UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

1 lines 4.47 kB
{"version":3,"file":"types.cjs","sources":["../../../src/richtext/types.ts"],"sourcesContent":["import type {\n\tRTAnyNode,\n\tRTEmNode,\n\tRTEmbedNode,\n\tRTHeading1Node,\n\tRTHeading2Node,\n\tRTHeading3Node,\n\tRTHeading4Node,\n\tRTHeading5Node,\n\tRTHeading6Node,\n\tRTImageNode,\n\tRTLabelNode,\n\tRTLinkNode,\n\tRTListItemNode,\n\tRTListNode,\n\tRTOListItemNode,\n\tRTOListNode,\n\tRTParagraphNode,\n\tRTPreformattedNode,\n\tRTSpanNode,\n\tRTStrongNode,\n\tRichTextNodeTypes,\n} from \"../types/value/richText\"\nimport { RichTextNodeType } from \"../types/value/richText\"\n\n// Serializers\n\n/**\n * Serializes a node from a rich text or title field with a function\n *\n * @typeParam ReturnType - Return type of the function serializer\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}\n */\nexport type RichTextFunctionSerializer<ReturnType> = (\n\ttype: RichTextNodeTypes,\n\tnode: RTAnyNode,\n\ttext: string | undefined,\n\tchildren: ReturnType[],\n\tkey: string,\n) => ReturnType | null | undefined\n\n/**\n * Map serializer's tag function serializer, can be helpful for typing those\n * handlers\n *\n * @typeParam ReturnType - Return type of the tag serializer\n */\nexport type RichTextMapSerializerFunction<\n\tReturnType,\n\tNode extends RTAnyNode = RTAnyNode,\n\tTextType = string | undefined,\n> = (payload: {\n\ttype: Node[\"type\"]\n\tnode: Node\n\ttext: TextType\n\tchildren: ReturnType[]\n\tkey: string\n}) => ReturnType | null | undefined\n\n/**\n * Serializes a node from a rich text or title field with a map\n *\n * @remarks\n * This type of serializer needs to be processed through\n * {@link wrapMapSerializer} before being used with {@link serialize}\n *\n * @typeParam ReturnType - Return type of the map serializer\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}\n */\nexport type RichTextMapSerializer<ReturnType> = {\n\theading1?: RichTextMapSerializerFunction<\n\t\tReturnType,\n\t\tRTHeading1Node,\n\t\tundefined\n\t>\n\theading2?: RichTextMapSerializerFunction<\n\t\tReturnType,\n\t\tRTHeading2Node,\n\t\tundefined\n\t>\n\theading3?: RichTextMapSerializerFunction<\n\t\tReturnType,\n\t\tRTHeading3Node,\n\t\tundefined\n\t>\n\theading4?: RichTextMapSerializerFunction<\n\t\tReturnType,\n\t\tRTHeading4Node,\n\t\tundefined\n\t>\n\theading5?: RichTextMapSerializerFunction<\n\t\tReturnType,\n\t\tRTHeading5Node,\n\t\tundefined\n\t>\n\theading6?: RichTextMapSerializerFunction<\n\t\tReturnType,\n\t\tRTHeading6Node,\n\t\tundefined\n\t>\n\tparagraph?: RichTextMapSerializerFunction<\n\t\tReturnType,\n\t\tRTParagraphNode,\n\t\tundefined\n\t>\n\tpreformatted?: RichTextMapSerializerFunction<\n\t\tReturnType,\n\t\tRTPreformattedNode,\n\t\tundefined\n\t>\n\tstrong?: RichTextMapSerializerFunction<ReturnType, RTStrongNode, string>\n\tem?: RichTextMapSerializerFunction<ReturnType, RTEmNode, string>\n\tlistItem?: RichTextMapSerializerFunction<\n\t\tReturnType,\n\t\tRTListItemNode,\n\t\tundefined\n\t>\n\toListItem?: RichTextMapSerializerFunction<\n\t\tReturnType,\n\t\tRTOListItemNode,\n\t\tundefined\n\t>\n\tlist?: RichTextMapSerializerFunction<ReturnType, RTListNode, undefined>\n\toList?: RichTextMapSerializerFunction<ReturnType, RTOListNode, undefined>\n\timage?: RichTextMapSerializerFunction<ReturnType, RTImageNode, undefined>\n\tembed?: RichTextMapSerializerFunction<ReturnType, RTEmbedNode, undefined>\n\thyperlink?: RichTextMapSerializerFunction<ReturnType, RTLinkNode, string>\n\tlabel?: RichTextMapSerializerFunction<ReturnType, RTLabelNode, string>\n\tspan?: RichTextMapSerializerFunction<ReturnType, RTSpanNode, string>\n}\n\n// Tree\nexport interface Tree {\n\tkey: string\n\tchildren: TreeNode[]\n}\n\nexport interface TreeNode {\n\tkey: string\n\ttype: RichTextNodeTypes\n\ttext?: string\n\tnode: RTAnyNode\n\tchildren: TreeNode[]\n}\n\n// Helpers\nexport const RichTextReversedNodeType = {\n\t[RichTextNodeType.listItem]: \"listItem\",\n\t[RichTextNodeType.oListItem]: \"oListItem\",\n\t[RichTextNodeType.list]: \"list\",\n\t[RichTextNodeType.oList]: \"oList\",\n} as const\n"],"names":["RichTextNodeType"],"mappings":";;;AAoJO,MAAM,2BAA2B;AAAA,EACvC,CAACA,SAAAA,iBAAiB,QAAQ,GAAG;AAAA,EAC7B,CAACA,SAAAA,iBAAiB,SAAS,GAAG;AAAA,EAC9B,CAACA,SAAAA,iBAAiB,IAAI,GAAG;AAAA,EACzB,CAACA,SAAAA,iBAAiB,KAAK,GAAG;;;"}