@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
71 lines (69 loc) • 3.51 kB
TypeScript
import { RTAnyNode, RTEmNode, RTEmbedNode, RTHeading1Node, RTHeading2Node, RTHeading3Node, RTHeading4Node, RTHeading5Node, RTHeading6Node, RTImageNode, RTLabelNode, RTLinkNode, RTListItemNode, RTListNode, RTOListItemNode, RTOListNode, RTParagraphNode, RTPreformattedNode, RTSpanNode, RTStrongNode, RichTextNodeTypes } from "../types/value/richText.js";
//#region src/richtext/types.d.ts
/**
* Serializes a node from a rich text or title field with a function
*
* @typeParam ReturnType - Return type of the function serializer.
*
* @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}
*/
type RichTextFunctionSerializer<ReturnType> = (type: RichTextNodeTypes, node: RTAnyNode, text: string | undefined, children: ReturnType[], key: string) => ReturnType | null | undefined;
/**
* Map serializer's tag function serializer, can be helpful for typing those
* handlers
*
* @typeParam ReturnType - Return type of the tag serializer
*/
type RichTextMapSerializerFunction<ReturnType, Node extends RTAnyNode = RTAnyNode, TextType = string | undefined> = (payload: {
type: Node["type"];
node: Node;
text: TextType;
children: ReturnType[];
key: string;
}) => ReturnType | null | undefined;
/**
* Serializes a node from a rich text field with a map.
*
* @remarks
* This type of serializer needs to be processed through
* {@link wrapMapSerializer} before being used with {@link serialize}.
*
* @typeParam ReturnType - Return type of the map serializer.
*
* @see Learn how to work with rich text fields: {@link https://prismic.io/docs/fields/rich-text}
*/
type RichTextMapSerializer<ReturnType> = {
heading1?: RichTextMapSerializerFunction<ReturnType, RTHeading1Node, undefined>;
heading2?: RichTextMapSerializerFunction<ReturnType, RTHeading2Node, undefined>;
heading3?: RichTextMapSerializerFunction<ReturnType, RTHeading3Node, undefined>;
heading4?: RichTextMapSerializerFunction<ReturnType, RTHeading4Node, undefined>;
heading5?: RichTextMapSerializerFunction<ReturnType, RTHeading5Node, undefined>;
heading6?: RichTextMapSerializerFunction<ReturnType, RTHeading6Node, undefined>;
paragraph?: RichTextMapSerializerFunction<ReturnType, RTParagraphNode, undefined>;
preformatted?: RichTextMapSerializerFunction<ReturnType, RTPreformattedNode, undefined>;
strong?: RichTextMapSerializerFunction<ReturnType, RTStrongNode, string>;
em?: RichTextMapSerializerFunction<ReturnType, RTEmNode, string>;
listItem?: RichTextMapSerializerFunction<ReturnType, RTListItemNode, undefined>;
oListItem?: RichTextMapSerializerFunction<ReturnType, RTOListItemNode, undefined>;
list?: RichTextMapSerializerFunction<ReturnType, RTListNode, undefined>;
oList?: RichTextMapSerializerFunction<ReturnType, RTOListNode, undefined>;
image?: RichTextMapSerializerFunction<ReturnType, RTImageNode, undefined>;
embed?: RichTextMapSerializerFunction<ReturnType, RTEmbedNode, undefined>;
hyperlink?: RichTextMapSerializerFunction<ReturnType, RTLinkNode, string>;
label?: RichTextMapSerializerFunction<ReturnType, RTLabelNode, string>;
span?: RichTextMapSerializerFunction<ReturnType, RTSpanNode, string>;
};
interface Tree {
key: string;
children: TreeNode[];
}
interface TreeNode {
key: string;
type: RichTextNodeTypes;
text?: string;
node: RTAnyNode;
children: TreeNode[];
}
//#endregion
export { RichTextFunctionSerializer, RichTextMapSerializer, RichTextMapSerializerFunction, Tree };
//# sourceMappingURL=types.d.ts.map