@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
221 lines (219 loc) • 5.99 kB
TypeScript
import { EmbedField } from "./embed.js";
import { FilledLinkField } from "./link.js";
import { FieldState } from "./types.js";
//#region src/types/value/richText.d.ts
/**
* Types enum for RichTextNodes
*
* @see More details: {@link https://prismic.io/docs/rich-text-title}
*/
declare const RichTextNodeType: {
readonly heading1: "heading1";
readonly heading2: "heading2";
readonly heading3: "heading3";
readonly heading4: "heading4";
readonly heading5: "heading5";
readonly heading6: "heading6";
readonly paragraph: "paragraph";
readonly preformatted: "preformatted";
readonly strong: "strong";
readonly em: "em";
readonly listItem: "list-item";
readonly oListItem: "o-list-item";
readonly list: "group-list-item";
readonly oList: "group-o-list-item";
readonly image: "image";
readonly embed: "embed";
readonly hyperlink: "hyperlink";
readonly label: "label";
readonly span: "span";
};
/**
* Types for RichTextNodes
*
* @see More details: {@link https://prismic.io/docs/rich-text-title}
*/
type RichTextNodeTypes = (typeof RichTextNodeType)[keyof typeof RichTextNodeType];
/**
* Base to be extended by other rich text nodes.
*/
interface RTTextNodeBase {
text: string;
spans: RTInlineNode[];
direction?: "ltr" | "rtl";
}
/**
* Rich text `heading1` node
*/
interface RTHeading1Node extends RTTextNodeBase {
type: typeof RichTextNodeType.heading1;
}
/**
* Rich text `heading2` node
*/
interface RTHeading2Node extends RTTextNodeBase {
type: typeof RichTextNodeType.heading2;
}
/**
* Rich text `heading3` node
*/
interface RTHeading3Node extends RTTextNodeBase {
type: typeof RichTextNodeType.heading3;
}
/**
* Rich text `heading4` node
*/
interface RTHeading4Node extends RTTextNodeBase {
type: typeof RichTextNodeType.heading4;
}
/**
* Rich text `heading5` node
*/
interface RTHeading5Node extends RTTextNodeBase {
type: typeof RichTextNodeType.heading5;
}
/**
* Rich text `heading6` node
*/
interface RTHeading6Node extends RTTextNodeBase {
type: typeof RichTextNodeType.heading6;
}
/**
* Rich text `paragraph` node
*/
interface RTParagraphNode extends RTTextNodeBase {
type: typeof RichTextNodeType.paragraph;
}
/**
* Rich text `preformatted` node
*/
interface RTPreformattedNode extends RTTextNodeBase {
type: typeof RichTextNodeType.preformatted;
}
/**
* Rich text `list-item` node
*/
interface RTListItemNode extends RTTextNodeBase {
type: typeof RichTextNodeType.listItem;
}
/**
* Rich text `o-list-item` node for ordered lists
*/
interface RTOListItemNode extends RTTextNodeBase {
type: typeof RichTextNodeType.oListItem;
}
/**
* @internal Span Node base to be extended for other Span nodes
*/
interface RTSpanNodeBase {
start: number;
end: number;
}
/**
* Rich text `strong` node
*/
interface RTStrongNode extends RTSpanNodeBase {
type: typeof RichTextNodeType.strong;
}
/**
* Rich text `embed` node
*/
interface RTEmNode extends RTSpanNodeBase {
type: typeof RichTextNodeType.em;
}
/**
* Rich text `label` node
*/
interface RTLabelNode extends RTSpanNodeBase {
type: typeof RichTextNodeType.label;
data: {
label: string;
};
}
/**
* Rich text `image` nodes. They could link to other documents, external web
* links and media fields
*/
type RTImageNode = {
type: typeof RichTextNodeType.image;
id: string;
url: string;
alt: string | null;
copyright: string | null;
dimensions: {
width: number;
height: number;
};
edit: {
x: number;
y: number;
zoom: number;
background: string;
};
linkTo?: FilledLinkField;
};
/**
* Rich text `embed` node
*/
type RTEmbedNode = {
type: typeof RichTextNodeType.embed;
oembed: EmbedField;
};
/**
* Rich text `a` node
*
* @see More details: {@link https://prismic.io/docs/rich-text-title#elements-and-styles}
*/
interface RTLinkNode extends RTSpanNodeBase {
type: typeof RichTextNodeType.hyperlink;
data: FilledLinkField;
}
/**
* Rich text `list` node
*/
interface RTListNode {
type: typeof RichTextNodeType.list;
items: RTListItemNode[];
}
/**
* Rich text o-lost node
*/
interface RTOListNode {
type: typeof RichTextNodeType.oList;
items: RTOListItemNode[];
}
/**
* Rich text `span` node
*/
interface RTSpanNode extends RTTextNodeBase {
type: typeof RichTextNodeType.span;
}
/**
* Nodes from a rich text field
*/
type RTNode = RTHeading1Node | RTHeading2Node | RTHeading3Node | RTHeading4Node | RTHeading5Node | RTHeading6Node | RTParagraphNode | RTPreformattedNode | RTListItemNode | RTOListItemNode | RTImageNode | RTEmbedNode;
/**
* Rich text nodes with text
*/
type RTTextNode = RTHeading1Node | RTHeading2Node | RTHeading3Node | RTHeading4Node | RTHeading5Node | RTHeading6Node | RTParagraphNode | RTPreformattedNode | RTListItemNode | RTOListItemNode;
/**
* Rich text block nodes
*/
type RTBlockNode = RTHeading1Node | RTHeading2Node | RTHeading3Node | RTHeading4Node | RTHeading5Node | RTHeading6Node | RTParagraphNode | RTPreformattedNode | RTListItemNode | RTOListItemNode | RTListNode | RTOListNode | RTImageNode | RTEmbedNode;
/**
* Inline rich text nodes
*/
type RTInlineNode = RTStrongNode | RTEmNode | RTLabelNode | RTLinkNode;
/**
* All rich text nodes
*/
type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode;
/**
* A rich text field.
*
* @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}
*/
type RichTextField<State extends FieldState = FieldState> = State extends "empty" ? [] : [RTNode, ...RTNode[]];
//#endregion
export { RTAnyNode, RTBlockNode, RTEmNode, RTEmbedNode, RTHeading1Node, RTHeading2Node, RTHeading3Node, RTHeading4Node, RTHeading5Node, RTHeading6Node, RTImageNode, RTInlineNode, RTLabelNode, RTLinkNode, RTListItemNode, RTListNode, RTNode, RTOListItemNode, RTOListNode, RTParagraphNode, RTPreformattedNode, RTSpanNode, RTSpanNodeBase, RTStrongNode, RTTextNode, RTTextNodeBase, RichTextField, RichTextNodeType, RichTextNodeTypes };
//# sourceMappingURL=richText.d.ts.map