@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
1 lines • 6.52 kB
Source Map (JSON)
{"version":3,"file":"richText.cjs","sources":["../../../../src/types/value/richText.ts"],"sourcesContent":["import type { FieldState } from \"./types\"\n\nimport type { EmbedField } from \"./embed\"\nimport type { FilledLinkField } from \"./link\"\n\n/**\n * Types enum for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport const RichTextNodeType = {\n\theading1: \"heading1\",\n\theading2: \"heading2\",\n\theading3: \"heading3\",\n\theading4: \"heading4\",\n\theading5: \"heading5\",\n\theading6: \"heading6\",\n\tparagraph: \"paragraph\",\n\tpreformatted: \"preformatted\",\n\tstrong: \"strong\",\n\tem: \"em\",\n\tlistItem: \"list-item\",\n\toListItem: \"o-list-item\",\n\tlist: \"group-list-item\",\n\toList: \"group-o-list-item\",\n\timage: \"image\",\n\tembed: \"embed\",\n\thyperlink: \"hyperlink\",\n\tlabel: \"label\",\n\tspan: \"span\",\n} as const\n\n/**\n * Types for RichTextNodes\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextNodeTypes =\n\t(typeof RichTextNodeType)[keyof typeof RichTextNodeType]\n\n// Text nodes\n\n/**\n * Base to be extended by other rich text nodes.\n */\nexport interface RTTextNodeBase {\n\ttext: string\n\tspans: RTInlineNode[]\n\tdirection?: \"ltr\" | \"rtl\"\n}\n\n/**\n * Rich text `heading1` node\n */\nexport interface RTHeading1Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading1\n}\n\n/**\n * Rich text `heading2` node\n */\nexport interface RTHeading2Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading2\n}\n\n/**\n * Rich text `heading3` node\n */\nexport interface RTHeading3Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading3\n}\n\n/**\n * Rich text `heading4` node\n */\nexport interface RTHeading4Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading4\n}\n\n/**\n * Rich text `heading5` node\n */\nexport interface RTHeading5Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading5\n}\n\n/**\n * Rich text `heading6` node\n */\nexport interface RTHeading6Node extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.heading6\n}\n\n/**\n * Rich text `paragraph` node\n */\nexport interface RTParagraphNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.paragraph\n}\n\n/**\n * Rich text `preformatted` node\n */\nexport interface RTPreformattedNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.preformatted\n}\n\n/**\n * Rich text `list-item` node\n */\nexport interface RTListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.listItem\n}\n\n/**\n * Rich text `o-list-item` node for ordered lists\n */\nexport interface RTOListItemNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.oListItem\n}\n\n// Span nodes\n\n/**\n * @internal Span Node base to be extended for other Span nodes\n */\nexport interface RTSpanNodeBase {\n\tstart: number\n\tend: number\n}\n/**\n * Rich text `strong` node\n */\nexport interface RTStrongNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.strong\n}\n\n/**\n * Rich text `embed` node\n */\nexport interface RTEmNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.em\n}\n\n/**\n * Rich text `label` node\n */\nexport interface RTLabelNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.label\n\tdata: {\n\t\tlabel: string\n\t}\n}\n\n// Media nodes\n\n/**\n * Rich text `image` nodes. They could link to other documents, external web\n * links and media fields\n */\nexport type RTImageNode = {\n\ttype: typeof RichTextNodeType.image\n\tid: string\n\turl: string\n\talt: string | null\n\tcopyright: string | null\n\tdimensions: {\n\t\twidth: number\n\t\theight: number\n\t}\n\tedit: {\n\t\tx: number\n\t\ty: number\n\t\tzoom: number\n\t\tbackground: string\n\t}\n\tlinkTo?: FilledLinkField\n}\n\n/**\n * Rich text `embed` node\n */\nexport type RTEmbedNode = {\n\ttype: typeof RichTextNodeType.embed\n\toembed: EmbedField\n}\n\n// Link nodes\n\n/**\n * Rich text `a` node\n *\n * @see More details: {@link https://prismic.io/docs/rich-text-title#elements-and-styles}\n */\nexport interface RTLinkNode extends RTSpanNodeBase {\n\ttype: typeof RichTextNodeType.hyperlink\n\tdata: FilledLinkField\n}\n\n// Serialization related nodes\n\n/**\n * Rich text `list` node\n */\nexport interface RTListNode {\n\ttype: typeof RichTextNodeType.list\n\titems: RTListItemNode[]\n}\n\n/**\n * Rich text o-lost node\n */\nexport interface RTOListNode {\n\ttype: typeof RichTextNodeType.oList\n\titems: RTOListItemNode[]\n}\n\n// This one is confusing but it's actually the inner content of a block\n/**\n * Rich text `span` node\n */\nexport interface RTSpanNode extends RTTextNodeBase {\n\ttype: typeof RichTextNodeType.span\n}\n\n// Helpers\n\n/**\n * Nodes from a rich text field\n */\nexport type RTNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/**\n * Rich text nodes with text\n */\nexport type RTTextNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\n/**\n * Rich text block nodes\n */\nexport type RTBlockNode =\n\t| RTHeading1Node\n\t| RTHeading2Node\n\t| RTHeading3Node\n\t| RTHeading4Node\n\t| RTHeading5Node\n\t| RTHeading6Node\n\t| RTParagraphNode\n\t| RTPreformattedNode\n\t| RTListItemNode\n\t| RTOListItemNode\n\t| RTListNode\n\t| RTOListNode\n\t| RTImageNode\n\t| RTEmbedNode\n\n/**\n * Inline rich text nodes\n */\nexport type RTInlineNode = RTStrongNode | RTEmNode | RTLabelNode | RTLinkNode\n\n/**\n * All rich text nodes\n */\nexport type RTAnyNode = RTBlockNode | RTInlineNode | RTSpanNode\n\n/**\n * A rich text field.\n *\n * @see Rich text field documentation: {@link https://prismic.io/docs/rich-text-title}\n */\nexport type RichTextField<State extends FieldState = FieldState> =\n\tState extends \"empty\" ? [] : [RTNode, ...RTNode[]]\n"],"names":[],"mappings":";;AAUO,MAAM,mBAAmB;AAAA,EAC/B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,WAAW;AAAA,EACX,OAAO;AAAA,EACP,MAAM;;;"}