2024-07-13 08:55:10 +00:00
|
|
|
import {
|
2024-07-13 11:05:20 +00:00
|
|
|
type GenericBlock,
|
|
|
|
type SectionBlock,
|
|
|
|
type TranscriptBlock,
|
|
|
|
type BreakBlock,
|
2024-07-13 08:55:10 +00:00
|
|
|
isBlockTranscriptBlock,
|
|
|
|
isBlockBreakBlock,
|
|
|
|
} from "./blocks";
|
2024-07-13 11:05:20 +00:00
|
|
|
import { Collections } from "./constants";
|
|
|
|
import type {
|
|
|
|
EndpointImagePreview,
|
|
|
|
EndpointVideoPreview,
|
|
|
|
EndpointAudioPreview,
|
|
|
|
} from "./endpoint-types";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
|
|
|
export type RichTextContent = {
|
|
|
|
root: {
|
|
|
|
children: RichTextNode[];
|
|
|
|
direction: ("ltr" | "rtl") | null;
|
|
|
|
format: "left" | "start" | "center" | "right" | "end" | "justify" | "";
|
|
|
|
indent: number;
|
|
|
|
type: string;
|
|
|
|
version: number;
|
|
|
|
};
|
|
|
|
[k: string]: unknown;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type RichTextNode = {
|
|
|
|
type: string;
|
|
|
|
version: number;
|
|
|
|
[k: string]: unknown;
|
|
|
|
};
|
|
|
|
|
|
|
|
export interface RichTextNodeWithChildren extends RichTextNode {
|
|
|
|
children: RichTextNode[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextParagraphNode extends RichTextNodeWithChildren {
|
|
|
|
type: "paragraph";
|
|
|
|
format: "left" | "start" | "center" | "right" | "end" | "justify" | "";
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextListNode extends RichTextNode {
|
|
|
|
type: "list";
|
|
|
|
children: RichTextNodeWithChildren[];
|
|
|
|
listType: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextListNumberNode extends RichTextListNode {
|
|
|
|
listType: "number";
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextListBulletNode extends RichTextListNode {
|
|
|
|
listType: "bullet";
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextListCheckNode extends RichTextListNode {
|
|
|
|
listType: "check";
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextLinebreakNode extends RichTextNode {
|
|
|
|
type: "linebreak";
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextUploadNode extends RichTextNode {
|
|
|
|
type: "upload";
|
|
|
|
relationTo: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextUploadImageNode extends RichTextUploadNode {
|
|
|
|
relationTo: Collections.Images;
|
|
|
|
value: EndpointImagePreview;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextUploadVideoNode extends RichTextUploadNode {
|
|
|
|
relationTo: Collections.Videos;
|
|
|
|
value: EndpointVideoPreview;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextUploadAudioNode extends RichTextUploadNode {
|
|
|
|
relationTo: Collections.Audios;
|
|
|
|
value: EndpointAudioPreview;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextTextNode extends RichTextNode {
|
|
|
|
type: "text";
|
|
|
|
format: number;
|
|
|
|
text: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextTabNode extends RichTextNode {
|
|
|
|
type: "tab";
|
|
|
|
format: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextLinkNode extends RichTextNodeWithChildren {
|
|
|
|
type: "link";
|
|
|
|
fields: {
|
|
|
|
linkType: "internal" | "custom";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextLinkInternalNode extends RichTextLinkNode {
|
|
|
|
fields: {
|
|
|
|
linkType: "internal";
|
|
|
|
newTab: boolean;
|
|
|
|
doc: {
|
|
|
|
relationTo: string;
|
|
|
|
value: any;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextLinkCustomNode extends RichTextLinkNode {
|
|
|
|
fields: {
|
|
|
|
linkType: "custom";
|
|
|
|
newTab: boolean;
|
|
|
|
url: string;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextBlockNode extends RichTextNode {
|
|
|
|
type: "block";
|
|
|
|
fields: GenericBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextSectionBlock extends RichTextBlockNode {
|
|
|
|
fields: SectionBlock;
|
|
|
|
anchorHash: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextTranscriptBlock extends RichTextBlockNode {
|
|
|
|
fields: TranscriptBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RichTextBreakBlock extends RichTextBlockNode {
|
|
|
|
fields: BreakBlock;
|
|
|
|
anchorHash: string;
|
|
|
|
}
|
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isNodeParagraphNode = (node: RichTextNode): node is RichTextParagraphNode =>
|
|
|
|
node.type === "paragraph";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isNodeUploadNode = (node: RichTextNode): node is RichTextUploadNode =>
|
|
|
|
node.type === "upload";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isUploadNodeImageNode = (node: RichTextUploadNode): node is RichTextUploadImageNode =>
|
|
|
|
node.relationTo === Collections.Images;
|
2024-07-13 08:55:10 +00:00
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isUploadNodeVideoNode = (node: RichTextUploadNode): node is RichTextUploadVideoNode =>
|
|
|
|
node.relationTo === Collections.Videos;
|
2024-07-13 08:55:10 +00:00
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isUploadNodeAudioNode = (node: RichTextUploadNode): node is RichTextUploadAudioNode =>
|
|
|
|
node.relationTo === Collections.Audios;
|
2024-07-13 08:55:10 +00:00
|
|
|
|
|
|
|
export const isNodeListNode = (node: RichTextNode): node is RichTextListNode =>
|
|
|
|
node.type === "list";
|
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isListNodeNumberListNode = (node: RichTextListNode): node is RichTextListNumberNode =>
|
|
|
|
node.listType === "number";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isListNodeBulletListNode = (node: RichTextListNode): node is RichTextListBulletNode =>
|
|
|
|
node.listType === "bullet";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isListNodeCheckListNode = (node: RichTextListNode): node is RichTextListCheckNode =>
|
|
|
|
node.listType === "check";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isNodeLinebreakNode = (node: RichTextNode): node is RichTextLinebreakNode =>
|
|
|
|
node.type === "linebreak";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
|
|
|
export const isNodeTextNode = (node: RichTextNode): node is RichTextTextNode =>
|
|
|
|
node.type === "text";
|
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isNodeTabNode = (node: RichTextNode): node is RichTextTabNode => node.type === "tab";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
|
|
|
export const isNodeLinkNode = (node: RichTextNode): node is RichTextLinkNode =>
|
|
|
|
node.type === "link";
|
|
|
|
|
|
|
|
export const isLinkNodeInternalLinkNode = (
|
|
|
|
node: RichTextLinkNode
|
|
|
|
): node is RichTextLinkInternalNode => node.fields.linkType === "internal";
|
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isLinkNodeCustomLinkNode = (node: RichTextLinkNode): node is RichTextLinkCustomNode =>
|
|
|
|
node.fields.linkType === "custom";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isNodeBlockNode = (node: RichTextNode): node is RichTextBlockNode =>
|
|
|
|
node.type === "block";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isBlockNodeSectionBlock = (node: RichTextBlockNode): node is RichTextSectionBlock =>
|
|
|
|
node.fields.blockType === "sectionBlock";
|
2024-07-13 08:55:10 +00:00
|
|
|
|
|
|
|
export const isBlockNodeTranscriptBlock = (
|
|
|
|
node: RichTextBlockNode
|
|
|
|
): node is RichTextTranscriptBlock => isBlockTranscriptBlock(node.fields);
|
|
|
|
|
2024-07-21 08:00:36 +00:00
|
|
|
export const isBlockNodeBreakBlock = (node: RichTextBlockNode): node is RichTextBreakBlock =>
|
|
|
|
isBlockBreakBlock(node.fields);
|