@prismicio/client 7.2.0 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createClient.cjs +9 -1
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.js +9 -1
- package/dist/createClient.js.map +1 -1
- package/dist/errors/ForbiddenError.cjs.map +1 -1
- package/dist/errors/ForbiddenError.d.ts +1 -1
- package/dist/errors/ForbiddenError.js.map +1 -1
- package/dist/errors/NotFoundError.cjs.map +1 -1
- package/dist/errors/NotFoundError.d.ts +1 -1
- package/dist/errors/NotFoundError.js.map +1 -1
- package/dist/errors/ParsingError.cjs.map +1 -1
- package/dist/errors/ParsingError.d.ts +1 -1
- package/dist/errors/ParsingError.js.map +1 -1
- package/dist/errors/RefExpiredError.cjs +7 -0
- package/dist/errors/RefExpiredError.cjs.map +1 -0
- package/dist/errors/RefExpiredError.d.ts +8 -0
- package/dist/errors/RefExpiredError.js +7 -0
- package/dist/errors/RefExpiredError.js.map +1 -0
- package/dist/errors/RefNotFoundError.cjs +7 -0
- package/dist/errors/RefNotFoundError.cjs.map +1 -0
- package/dist/errors/RefNotFoundError.d.ts +8 -0
- package/dist/errors/RefNotFoundError.js +7 -0
- package/dist/errors/RefNotFoundError.js.map +1 -0
- package/dist/helpers/asHTML.cjs +43 -50
- package/dist/helpers/asHTML.cjs.map +1 -1
- package/dist/helpers/asHTML.d.ts +31 -6
- package/dist/helpers/asHTML.js +42 -49
- package/dist/helpers/asHTML.js.map +1 -1
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +1 -1
- package/dist/helpers/asImageSrc.d.ts +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs +1 -1
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
- package/dist/helpers/asImageWidthSrcSet.d.ts +1 -1
- package/dist/helpers/asImageWidthSrcSet.js +1 -1
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
- package/dist/helpers/asLinkAttrs.d.ts +1 -1
- package/dist/helpers/asText.cjs +2 -2
- package/dist/helpers/asText.cjs.map +1 -1
- package/dist/helpers/asText.js +1 -1
- package/dist/helpers/asText.js.map +1 -1
- package/dist/helpers/isFilled.d.ts +10 -13
- package/dist/index.cjs +8 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +28 -2
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/serializerHelpers.cjs +91 -35
- package/dist/lib/serializerHelpers.cjs.map +1 -1
- package/dist/lib/serializerHelpers.d.ts +8 -8
- package/dist/lib/serializerHelpers.js +91 -35
- package/dist/lib/serializerHelpers.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/richtext/asText.cjs +13 -0
- package/dist/richtext/asText.cjs.map +1 -0
- package/dist/richtext/asText.d.ts +12 -0
- package/dist/richtext/asText.js +13 -0
- package/dist/richtext/asText.js.map +1 -0
- package/dist/richtext/asTree.cjs +123 -0
- package/dist/richtext/asTree.cjs.map +1 -0
- package/dist/richtext/asTree.d.ts +14 -0
- package/dist/richtext/asTree.js +123 -0
- package/dist/richtext/asTree.js.map +1 -0
- package/dist/richtext/composeSerializers.cjs +17 -0
- package/dist/richtext/composeSerializers.cjs.map +1 -0
- package/dist/richtext/composeSerializers.d.ts +16 -0
- package/dist/richtext/composeSerializers.js +17 -0
- package/dist/richtext/composeSerializers.js.map +1 -0
- package/dist/richtext/index.d.ts +7 -0
- package/dist/richtext/serialize.cjs +19 -0
- package/dist/richtext/serialize.cjs.map +1 -0
- package/dist/richtext/serialize.d.ts +19 -0
- package/dist/richtext/serialize.js +19 -0
- package/dist/richtext/serialize.js.map +1 -0
- package/dist/richtext/types.cjs +11 -0
- package/dist/richtext/types.cjs.map +1 -0
- package/dist/richtext/types.d.ts +71 -0
- package/dist/richtext/types.js +11 -0
- package/dist/richtext/types.js.map +1 -0
- package/dist/richtext/wrapMapSerializer.cjs +24 -0
- package/dist/richtext/wrapMapSerializer.cjs.map +1 -0
- package/dist/richtext/wrapMapSerializer.d.ts +15 -0
- package/dist/richtext/wrapMapSerializer.js +24 -0
- package/dist/richtext/wrapMapSerializer.js.map +1 -0
- package/dist/richtext.cjs +15 -0
- package/dist/richtext.cjs.map +1 -0
- package/dist/richtext.js +15 -0
- package/dist/richtext.js.map +1 -0
- package/dist/types/value/image.d.ts +9 -0
- package/dist/types/value/linkToMedia.d.ts +1 -0
- package/dist/types/value/richText.cjs.map +1 -1
- package/dist/types/value/richText.d.ts +7 -0
- package/dist/types/value/richText.js.map +1 -1
- package/dist/types/value/sharedSlice.d.ts +1 -1
- package/dist/types/value/slice.d.ts +1 -1
- package/package.json +34 -15
- package/src/createClient.ts +17 -4
- package/src/errors/ForbiddenError.ts +5 -3
- package/src/errors/NotFoundError.ts +3 -1
- package/src/errors/ParsingError.ts +3 -1
- package/src/errors/RefExpiredError.ts +14 -0
- package/src/errors/RefNotFoundError.ts +14 -0
- package/src/helpers/asHTML.ts +166 -76
- package/src/helpers/asImageWidthSrcSet.ts +2 -0
- package/src/helpers/asText.ts +2 -2
- package/src/index.ts +9 -4
- package/src/lib/serializerHelpers.ts +140 -67
- package/src/richtext/asText.ts +27 -0
- package/src/richtext/asTree.ts +211 -0
- package/src/richtext/composeSerializers.ts +36 -0
- package/src/richtext/index.ts +14 -0
- package/src/richtext/serialize.ts +54 -0
- package/src/richtext/types.ts +153 -0
- package/src/richtext/wrapMapSerializer.ts +46 -0
- package/src/types/value/image.ts +9 -0
- package/src/types/value/linkToMedia.ts +1 -0
- package/src/types/value/richText.ts +7 -0
- package/src/types/value/sharedSlice.ts +1 -1
- package/src/types/value/slice.ts +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { asTree } from "./asTree";
|
|
2
|
+
export { asText } from "./asText";
|
|
3
|
+
export { serialize } from "./serialize";
|
|
4
|
+
export { wrapMapSerializer } from "./wrapMapSerializer";
|
|
5
|
+
export { composeSerializers } from "./composeSerializers";
|
|
6
|
+
export { RichTextNodeType as Element } from "../types/value/richText";
|
|
7
|
+
export type { RichTextFunctionSerializer, RichTextMapSerializer, RichTextMapSerializerFunction, } from "./types";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const asTree = require("./asTree.cjs");
|
|
4
|
+
const serialize = (richTextField, serializer) => {
|
|
5
|
+
return serializeTreeNodes(asTree.asTree(richTextField).children, serializer);
|
|
6
|
+
};
|
|
7
|
+
const serializeTreeNodes = (nodes, serializer) => {
|
|
8
|
+
const serializedTreeNodes = [];
|
|
9
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
10
|
+
const treeNode = nodes[i];
|
|
11
|
+
const serializedTreeNode = serializer(treeNode.type, treeNode.node, treeNode.text, serializeTreeNodes(treeNode.children, serializer), treeNode.key);
|
|
12
|
+
if (serializedTreeNode != null) {
|
|
13
|
+
serializedTreeNodes.push(serializedTreeNode);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return serializedTreeNodes;
|
|
17
|
+
};
|
|
18
|
+
exports.serialize = serialize;
|
|
19
|
+
//# sourceMappingURL=serialize.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.cjs","sources":["../../../src/richtext/serialize.ts"],"sourcesContent":["import type { RichTextField } from \"../types/value/richText\";\nimport { RichTextFunctionSerializer, TreeNode } from \"./types\";\n\nimport { asTree } from \"./asTree\";\n\n/**\n * Serializes a rich text or title field with a given serializer\n *\n * @remarks\n * This is a low level helper mainly intended to be used by higher level\n * packages Most users aren't expected to this function directly\n *\n * @typeParam SerializerReturnType - Return type of the serializer\n *\n * @param richTextField - A rich text or title field from Prismic\n * @param serializer - A function serializer to apply\n *\n * @returns An array of serialized nodes\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 const serialize = <SerializerReturnType>(\n\trichTextField: RichTextField,\n\tserializer: RichTextFunctionSerializer<SerializerReturnType>,\n): SerializerReturnType[] => {\n\treturn serializeTreeNodes<SerializerReturnType>(\n\t\tasTree(richTextField).children,\n\t\tserializer,\n\t);\n};\n\nconst serializeTreeNodes = <T>(\n\tnodes: TreeNode[],\n\tserializer: RichTextFunctionSerializer<T>,\n): T[] => {\n\tconst serializedTreeNodes: T[] = [];\n\n\tfor (let i = 0; i < nodes.length; i++) {\n\t\tconst treeNode = nodes[i];\n\t\tconst serializedTreeNode = serializer(\n\t\t\ttreeNode.type,\n\t\t\ttreeNode.node,\n\t\t\ttreeNode.text,\n\t\t\tserializeTreeNodes(treeNode.children, serializer),\n\t\t\ttreeNode.key,\n\t\t);\n\n\t\tif (serializedTreeNode != null) {\n\t\t\tserializedTreeNodes.push(serializedTreeNode);\n\t\t}\n\t}\n\n\treturn serializedTreeNodes;\n};\n"],"names":["asTree"],"mappings":";;;AAqBa,MAAA,YAAY,CACxB,eACA,eAC2B;AAC3B,SAAO,mBACNA,OAAAA,OAAO,aAAa,EAAE,UACtB,UAAU;AAEZ;AAEA,MAAM,qBAAqB,CAC1B,OACA,eACQ;AACR,QAAM,sBAA2B,CAAA;AAEjC,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AAChC,UAAA,WAAW,MAAM,CAAC;AACxB,UAAM,qBAAqB,WAC1B,SAAS,MACT,SAAS,MACT,SAAS,MACT,mBAAmB,SAAS,UAAU,UAAU,GAChD,SAAS,GAAG;AAGb,QAAI,sBAAsB,MAAM;AAC/B,0BAAoB,KAAK,kBAAkB;AAAA,IAC3C;AAAA,EACD;AAEM,SAAA;AACR;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RichTextField } from "../types/value/richText";
|
|
2
|
+
import { RichTextFunctionSerializer } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Serializes a rich text or title field with a given serializer
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* This is a low level helper mainly intended to be used by higher level
|
|
8
|
+
* packages Most users aren't expected to this function directly
|
|
9
|
+
*
|
|
10
|
+
* @typeParam SerializerReturnType - Return type of the serializer
|
|
11
|
+
*
|
|
12
|
+
* @param richTextField - A rich text or title field from Prismic
|
|
13
|
+
* @param serializer - A function serializer to apply
|
|
14
|
+
*
|
|
15
|
+
* @returns An array of serialized nodes
|
|
16
|
+
*
|
|
17
|
+
* @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
|
|
18
|
+
*/
|
|
19
|
+
export declare const serialize: <SerializerReturnType>(richTextField: RichTextField, serializer: RichTextFunctionSerializer<SerializerReturnType>) => SerializerReturnType[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { asTree } from "./asTree.js";
|
|
2
|
+
const serialize = (richTextField, serializer) => {
|
|
3
|
+
return serializeTreeNodes(asTree(richTextField).children, serializer);
|
|
4
|
+
};
|
|
5
|
+
const serializeTreeNodes = (nodes, serializer) => {
|
|
6
|
+
const serializedTreeNodes = [];
|
|
7
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
8
|
+
const treeNode = nodes[i];
|
|
9
|
+
const serializedTreeNode = serializer(treeNode.type, treeNode.node, treeNode.text, serializeTreeNodes(treeNode.children, serializer), treeNode.key);
|
|
10
|
+
if (serializedTreeNode != null) {
|
|
11
|
+
serializedTreeNodes.push(serializedTreeNode);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return serializedTreeNodes;
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
serialize
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.js","sources":["../../../src/richtext/serialize.ts"],"sourcesContent":["import type { RichTextField } from \"../types/value/richText\";\nimport { RichTextFunctionSerializer, TreeNode } from \"./types\";\n\nimport { asTree } from \"./asTree\";\n\n/**\n * Serializes a rich text or title field with a given serializer\n *\n * @remarks\n * This is a low level helper mainly intended to be used by higher level\n * packages Most users aren't expected to this function directly\n *\n * @typeParam SerializerReturnType - Return type of the serializer\n *\n * @param richTextField - A rich text or title field from Prismic\n * @param serializer - A function serializer to apply\n *\n * @returns An array of serialized nodes\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 const serialize = <SerializerReturnType>(\n\trichTextField: RichTextField,\n\tserializer: RichTextFunctionSerializer<SerializerReturnType>,\n): SerializerReturnType[] => {\n\treturn serializeTreeNodes<SerializerReturnType>(\n\t\tasTree(richTextField).children,\n\t\tserializer,\n\t);\n};\n\nconst serializeTreeNodes = <T>(\n\tnodes: TreeNode[],\n\tserializer: RichTextFunctionSerializer<T>,\n): T[] => {\n\tconst serializedTreeNodes: T[] = [];\n\n\tfor (let i = 0; i < nodes.length; i++) {\n\t\tconst treeNode = nodes[i];\n\t\tconst serializedTreeNode = serializer(\n\t\t\ttreeNode.type,\n\t\t\ttreeNode.node,\n\t\t\ttreeNode.text,\n\t\t\tserializeTreeNodes(treeNode.children, serializer),\n\t\t\ttreeNode.key,\n\t\t);\n\n\t\tif (serializedTreeNode != null) {\n\t\t\tserializedTreeNodes.push(serializedTreeNode);\n\t\t}\n\t}\n\n\treturn serializedTreeNodes;\n};\n"],"names":[],"mappings":";AAqBa,MAAA,YAAY,CACxB,eACA,eAC2B;AAC3B,SAAO,mBACN,OAAO,aAAa,EAAE,UACtB,UAAU;AAEZ;AAEA,MAAM,qBAAqB,CAC1B,OACA,eACQ;AACR,QAAM,sBAA2B,CAAA;AAEjC,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AAChC,UAAA,WAAW,MAAM,CAAC;AACxB,UAAM,qBAAqB,WAC1B,SAAS,MACT,SAAS,MACT,SAAS,MACT,mBAAmB,SAAS,UAAU,UAAU,GAChD,SAAS,GAAG;AAGb,QAAI,sBAAsB,MAAM;AAC/B,0BAAoB,KAAK,kBAAkB;AAAA,IAC3C;AAAA,EACD;AAEM,SAAA;AACR;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const richText = require("../types/value/richText.cjs");
|
|
4
|
+
const RichTextReversedNodeType = {
|
|
5
|
+
[richText.RichTextNodeType.listItem]: "listItem",
|
|
6
|
+
[richText.RichTextNodeType.oListItem]: "oListItem",
|
|
7
|
+
[richText.RichTextNodeType.list]: "list",
|
|
8
|
+
[richText.RichTextNodeType.oList]: "oList"
|
|
9
|
+
};
|
|
10
|
+
exports.RichTextReversedNodeType = RichTextReversedNodeType;
|
|
11
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sources":["../../../src/richtext/types.ts"],"sourcesContent":["import {\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\tRichTextNodeType,\n} 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: (typeof RichTextNodeType)[keyof typeof RichTextNodeType],\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: (typeof RichTextNodeType)[keyof typeof RichTextNodeType];\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":";;;AAmJO,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;;;"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { RTAnyNode, RTEmNode, RTEmbedNode, RTHeading1Node, RTHeading2Node, RTHeading3Node, RTHeading4Node, RTHeading5Node, RTHeading6Node, RTImageNode, RTLabelNode, RTLinkNode, RTListItemNode, RTListNode, RTOListItemNode, RTOListNode, RTParagraphNode, RTPreformattedNode, RTSpanNode, RTStrongNode, RichTextNodeType } from "../types/value/richText";
|
|
2
|
+
/**
|
|
3
|
+
* Serializes a node from a rich text or title field with a function
|
|
4
|
+
*
|
|
5
|
+
* @typeParam ReturnType - Return type of the function serializer
|
|
6
|
+
*
|
|
7
|
+
* @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
|
|
8
|
+
*/
|
|
9
|
+
export type RichTextFunctionSerializer<ReturnType> = (type: (typeof RichTextNodeType)[keyof typeof RichTextNodeType], node: RTAnyNode, text: string | undefined, children: ReturnType[], key: string) => ReturnType | null | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Map serializer's tag function serializer, can be helpful for typing those
|
|
12
|
+
* handlers
|
|
13
|
+
*
|
|
14
|
+
* @typeParam ReturnType - Return type of the tag serializer
|
|
15
|
+
*/
|
|
16
|
+
export type RichTextMapSerializerFunction<ReturnType, Node extends RTAnyNode = RTAnyNode, TextType = string | undefined> = (payload: {
|
|
17
|
+
type: Node["type"];
|
|
18
|
+
node: Node;
|
|
19
|
+
text: TextType;
|
|
20
|
+
children: ReturnType[];
|
|
21
|
+
key: string;
|
|
22
|
+
}) => ReturnType | null | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Serializes a node from a rich text or title field with a map
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* This type of serializer needs to be processed through
|
|
28
|
+
* {@link wrapMapSerializer} before being used with {@link serialize}
|
|
29
|
+
*
|
|
30
|
+
* @typeParam ReturnType - Return type of the map serializer
|
|
31
|
+
*
|
|
32
|
+
* @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
|
|
33
|
+
*/
|
|
34
|
+
export type RichTextMapSerializer<ReturnType> = {
|
|
35
|
+
heading1?: RichTextMapSerializerFunction<ReturnType, RTHeading1Node, undefined>;
|
|
36
|
+
heading2?: RichTextMapSerializerFunction<ReturnType, RTHeading2Node, undefined>;
|
|
37
|
+
heading3?: RichTextMapSerializerFunction<ReturnType, RTHeading3Node, undefined>;
|
|
38
|
+
heading4?: RichTextMapSerializerFunction<ReturnType, RTHeading4Node, undefined>;
|
|
39
|
+
heading5?: RichTextMapSerializerFunction<ReturnType, RTHeading5Node, undefined>;
|
|
40
|
+
heading6?: RichTextMapSerializerFunction<ReturnType, RTHeading6Node, undefined>;
|
|
41
|
+
paragraph?: RichTextMapSerializerFunction<ReturnType, RTParagraphNode, undefined>;
|
|
42
|
+
preformatted?: RichTextMapSerializerFunction<ReturnType, RTPreformattedNode, undefined>;
|
|
43
|
+
strong?: RichTextMapSerializerFunction<ReturnType, RTStrongNode, string>;
|
|
44
|
+
em?: RichTextMapSerializerFunction<ReturnType, RTEmNode, string>;
|
|
45
|
+
listItem?: RichTextMapSerializerFunction<ReturnType, RTListItemNode, undefined>;
|
|
46
|
+
oListItem?: RichTextMapSerializerFunction<ReturnType, RTOListItemNode, undefined>;
|
|
47
|
+
list?: RichTextMapSerializerFunction<ReturnType, RTListNode, undefined>;
|
|
48
|
+
oList?: RichTextMapSerializerFunction<ReturnType, RTOListNode, undefined>;
|
|
49
|
+
image?: RichTextMapSerializerFunction<ReturnType, RTImageNode, undefined>;
|
|
50
|
+
embed?: RichTextMapSerializerFunction<ReturnType, RTEmbedNode, undefined>;
|
|
51
|
+
hyperlink?: RichTextMapSerializerFunction<ReturnType, RTLinkNode, string>;
|
|
52
|
+
label?: RichTextMapSerializerFunction<ReturnType, RTLabelNode, string>;
|
|
53
|
+
span?: RichTextMapSerializerFunction<ReturnType, RTSpanNode, string>;
|
|
54
|
+
};
|
|
55
|
+
export interface Tree {
|
|
56
|
+
key: string;
|
|
57
|
+
children: TreeNode[];
|
|
58
|
+
}
|
|
59
|
+
export interface TreeNode {
|
|
60
|
+
key: string;
|
|
61
|
+
type: (typeof RichTextNodeType)[keyof typeof RichTextNodeType];
|
|
62
|
+
text?: string;
|
|
63
|
+
node: RTAnyNode;
|
|
64
|
+
children: TreeNode[];
|
|
65
|
+
}
|
|
66
|
+
export declare const RichTextReversedNodeType: {
|
|
67
|
+
readonly "list-item": "listItem";
|
|
68
|
+
readonly "o-list-item": "oListItem";
|
|
69
|
+
readonly "group-list-item": "list";
|
|
70
|
+
readonly "group-o-list-item": "oList";
|
|
71
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RichTextNodeType } from "../types/value/richText.js";
|
|
2
|
+
const RichTextReversedNodeType = {
|
|
3
|
+
[RichTextNodeType.listItem]: "listItem",
|
|
4
|
+
[RichTextNodeType.oListItem]: "oListItem",
|
|
5
|
+
[RichTextNodeType.list]: "list",
|
|
6
|
+
[RichTextNodeType.oList]: "oList"
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
RichTextReversedNodeType
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/richtext/types.ts"],"sourcesContent":["import {\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\tRichTextNodeType,\n} 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: (typeof RichTextNodeType)[keyof typeof RichTextNodeType],\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: (typeof RichTextNodeType)[keyof typeof RichTextNodeType];\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":[],"mappings":";AAmJO,MAAM,2BAA2B;AAAA,EACvC,CAAC,iBAAiB,QAAQ,GAAG;AAAA,EAC7B,CAAC,iBAAiB,SAAS,GAAG;AAAA,EAC9B,CAAC,iBAAiB,IAAI,GAAG;AAAA,EACzB,CAAC,iBAAiB,KAAK,GAAG;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const types = require("./types.cjs");
|
|
4
|
+
const wrapMapSerializer = (mapSerializer) => {
|
|
5
|
+
return (type, node, text, children, key) => {
|
|
6
|
+
const tagSerializer = mapSerializer[types.RichTextReversedNodeType[type] || type];
|
|
7
|
+
if (tagSerializer) {
|
|
8
|
+
return tagSerializer({
|
|
9
|
+
// @ts-expect-error cannot type check here
|
|
10
|
+
type,
|
|
11
|
+
// @ts-expect-error cannot type check here
|
|
12
|
+
node,
|
|
13
|
+
// @ts-expect-error cannot type check here
|
|
14
|
+
text,
|
|
15
|
+
// @ts-expect-error cannot type check here
|
|
16
|
+
children,
|
|
17
|
+
// @ts-expect-error cannot type check here
|
|
18
|
+
key
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.wrapMapSerializer = wrapMapSerializer;
|
|
24
|
+
//# sourceMappingURL=wrapMapSerializer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrapMapSerializer.cjs","sources":["../../../src/richtext/wrapMapSerializer.ts"],"sourcesContent":["import {\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextReversedNodeType,\n} from \"./types\";\n\n/**\n * Wraps a map serializer into a regular function serializer\n *\n * @remarks\n * This is a low level helper mainly intended to be used by higher level\n * packages Most users aren't expected to this function directly\n *\n * @typeParam SerializerReturnType - Return type of the map serializer\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nexport const wrapMapSerializer = <SerializerReturnType>(\n\tmapSerializer: RichTextMapSerializer<SerializerReturnType>,\n): RichTextFunctionSerializer<SerializerReturnType> => {\n\treturn (type, node, text, children, key) => {\n\t\tconst tagSerializer: RichTextMapSerializer<SerializerReturnType>[keyof RichTextMapSerializer<SerializerReturnType>] =\n\t\t\tmapSerializer[\n\t\t\t\t(RichTextReversedNodeType[\n\t\t\t\t\ttype as keyof typeof RichTextReversedNodeType\n\t\t\t\t] || type) as keyof RichTextMapSerializer<SerializerReturnType>\n\t\t\t];\n\n\t\tif (tagSerializer) {\n\t\t\treturn tagSerializer({\n\t\t\t\t// @ts-expect-error cannot type check here\n\t\t\t\ttype,\n\t\t\t\t// @ts-expect-error cannot type check here\n\t\t\t\tnode,\n\t\t\t\t// @ts-expect-error cannot type check here\n\t\t\t\ttext,\n\t\t\t\t// @ts-expect-error cannot type check here\n\t\t\t\tchildren,\n\t\t\t\t// @ts-expect-error cannot type check here\n\t\t\t\tkey,\n\t\t\t});\n\t\t}\n\t};\n};\n"],"names":["RichTextReversedNodeType"],"mappings":";;;AAmBa,MAAA,oBAAoB,CAChC,kBACqD;AACrD,SAAO,CAAC,MAAM,MAAM,MAAM,UAAU,QAAO;AAC1C,UAAM,gBACL,cACEA,MAAAA,yBACA,IAA6C,KACzC,IAA0D;AAGjE,QAAI,eAAe;AAClB,aAAO,cAAc;AAAA;AAAA,QAEpB;AAAA;AAAA,QAEA;AAAA;AAAA,QAEA;AAAA;AAAA,QAEA;AAAA;AAAA,QAEA;AAAA,MAAA,CACA;AAAA,IACD;AAAA,EAAA;AAEH;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RichTextFunctionSerializer, RichTextMapSerializer } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a map serializer into a regular function serializer
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This is a low level helper mainly intended to be used by higher level
|
|
7
|
+
* packages Most users aren't expected to this function directly
|
|
8
|
+
*
|
|
9
|
+
* @typeParam SerializerReturnType - Return type of the map serializer
|
|
10
|
+
*
|
|
11
|
+
* @param mapSerializer - Map serializer to wrap
|
|
12
|
+
*
|
|
13
|
+
* @returns A regular function serializer
|
|
14
|
+
*/
|
|
15
|
+
export declare const wrapMapSerializer: <SerializerReturnType>(mapSerializer: RichTextMapSerializer<SerializerReturnType>) => RichTextFunctionSerializer<SerializerReturnType>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RichTextReversedNodeType } from "./types.js";
|
|
2
|
+
const wrapMapSerializer = (mapSerializer) => {
|
|
3
|
+
return (type, node, text, children, key) => {
|
|
4
|
+
const tagSerializer = mapSerializer[RichTextReversedNodeType[type] || type];
|
|
5
|
+
if (tagSerializer) {
|
|
6
|
+
return tagSerializer({
|
|
7
|
+
// @ts-expect-error cannot type check here
|
|
8
|
+
type,
|
|
9
|
+
// @ts-expect-error cannot type check here
|
|
10
|
+
node,
|
|
11
|
+
// @ts-expect-error cannot type check here
|
|
12
|
+
text,
|
|
13
|
+
// @ts-expect-error cannot type check here
|
|
14
|
+
children,
|
|
15
|
+
// @ts-expect-error cannot type check here
|
|
16
|
+
key
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
wrapMapSerializer
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=wrapMapSerializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrapMapSerializer.js","sources":["../../../src/richtext/wrapMapSerializer.ts"],"sourcesContent":["import {\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n\tRichTextReversedNodeType,\n} from \"./types\";\n\n/**\n * Wraps a map serializer into a regular function serializer\n *\n * @remarks\n * This is a low level helper mainly intended to be used by higher level\n * packages Most users aren't expected to this function directly\n *\n * @typeParam SerializerReturnType - Return type of the map serializer\n *\n * @param mapSerializer - Map serializer to wrap\n *\n * @returns A regular function serializer\n */\nexport const wrapMapSerializer = <SerializerReturnType>(\n\tmapSerializer: RichTextMapSerializer<SerializerReturnType>,\n): RichTextFunctionSerializer<SerializerReturnType> => {\n\treturn (type, node, text, children, key) => {\n\t\tconst tagSerializer: RichTextMapSerializer<SerializerReturnType>[keyof RichTextMapSerializer<SerializerReturnType>] =\n\t\t\tmapSerializer[\n\t\t\t\t(RichTextReversedNodeType[\n\t\t\t\t\ttype as keyof typeof RichTextReversedNodeType\n\t\t\t\t] || type) as keyof RichTextMapSerializer<SerializerReturnType>\n\t\t\t];\n\n\t\tif (tagSerializer) {\n\t\t\treturn tagSerializer({\n\t\t\t\t// @ts-expect-error cannot type check here\n\t\t\t\ttype,\n\t\t\t\t// @ts-expect-error cannot type check here\n\t\t\t\tnode,\n\t\t\t\t// @ts-expect-error cannot type check here\n\t\t\t\ttext,\n\t\t\t\t// @ts-expect-error cannot type check here\n\t\t\t\tchildren,\n\t\t\t\t// @ts-expect-error cannot type check here\n\t\t\t\tkey,\n\t\t\t});\n\t\t}\n\t};\n};\n"],"names":[],"mappings":";AAmBa,MAAA,oBAAoB,CAChC,kBACqD;AACrD,SAAO,CAAC,MAAM,MAAM,MAAM,UAAU,QAAO;AAC1C,UAAM,gBACL,cACE,yBACA,IAA6C,KACzC,IAA0D;AAGjE,QAAI,eAAe;AAClB,aAAO,cAAc;AAAA;AAAA,QAEpB;AAAA;AAAA,QAEA;AAAA;AAAA,QAEA;AAAA;AAAA,QAEA;AAAA;AAAA,QAEA;AAAA,MAAA,CACA;AAAA,IACD;AAAA,EAAA;AAEH;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const asTree = require("./richtext/asTree.cjs");
|
|
4
|
+
const asText = require("./richtext/asText.cjs");
|
|
5
|
+
const serialize = require("./richtext/serialize.cjs");
|
|
6
|
+
const wrapMapSerializer = require("./richtext/wrapMapSerializer.cjs");
|
|
7
|
+
const composeSerializers = require("./richtext/composeSerializers.cjs");
|
|
8
|
+
const richText = require("./types/value/richText.cjs");
|
|
9
|
+
exports.asTree = asTree.asTree;
|
|
10
|
+
exports.asText = asText.asText;
|
|
11
|
+
exports.serialize = serialize.serialize;
|
|
12
|
+
exports.wrapMapSerializer = wrapMapSerializer.wrapMapSerializer;
|
|
13
|
+
exports.composeSerializers = composeSerializers.composeSerializers;
|
|
14
|
+
exports.Element = richText.RichTextNodeType;
|
|
15
|
+
//# sourceMappingURL=richtext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"richtext.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
package/dist/richtext.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { asTree } from "./richtext/asTree.js";
|
|
2
|
+
import { asText } from "./richtext/asText.js";
|
|
3
|
+
import { serialize } from "./richtext/serialize.js";
|
|
4
|
+
import { wrapMapSerializer } from "./richtext/wrapMapSerializer.js";
|
|
5
|
+
import { composeSerializers } from "./richtext/composeSerializers.js";
|
|
6
|
+
import { RichTextNodeType } from "./types/value/richText.js";
|
|
7
|
+
export {
|
|
8
|
+
RichTextNodeType as Element,
|
|
9
|
+
asText,
|
|
10
|
+
asTree,
|
|
11
|
+
composeSerializers,
|
|
12
|
+
serialize,
|
|
13
|
+
wrapMapSerializer
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=richtext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"richtext.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -9,17 +9,26 @@ import type { FieldState, Simplify } from "./types";
|
|
|
9
9
|
*/
|
|
10
10
|
export type ImageFieldImage<State extends FieldState = FieldState> = State extends "empty" ? EmptyImageFieldImage : FilledImageFieldImage;
|
|
11
11
|
export interface FilledImageFieldImage {
|
|
12
|
+
id: string;
|
|
12
13
|
url: string;
|
|
13
14
|
dimensions: {
|
|
14
15
|
width: number;
|
|
15
16
|
height: number;
|
|
16
17
|
};
|
|
18
|
+
edit: {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
zoom: number;
|
|
22
|
+
background: string;
|
|
23
|
+
};
|
|
17
24
|
alt: string | null;
|
|
18
25
|
copyright: string | null;
|
|
19
26
|
}
|
|
20
27
|
export interface EmptyImageFieldImage {
|
|
28
|
+
id?: null;
|
|
21
29
|
url?: null;
|
|
22
30
|
dimensions?: null;
|
|
31
|
+
edit?: null;
|
|
23
32
|
alt?: null;
|
|
24
33
|
copyright?: null;
|
|
25
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"richText.cjs","sources":["../../../../src/types/value/richText.ts"],"sourcesContent":["import type { FieldState } from \"./types\";\n\nimport type { FilledContentRelationshipField } from \"./contentRelationship\";\nimport type { EmbedField } from \"./embed\";\nimport type { FilledLinkToWebField } from \"./link\";\nimport type { FilledLinkToMediaField } from \"./linkToMedia\";\n\n/**\n * Types 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// 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}\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\turl: string;\n\talt: string | null;\n\tcopyright: string | null;\n\tdimensions: {\n\t\twidth: number;\n\t\theight: number;\n\t};\n\tlinkTo?:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField;\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:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField;\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":";;AAYO,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;;;"}
|
|
1
|
+
{"version":3,"file":"richText.cjs","sources":["../../../../src/types/value/richText.ts"],"sourcesContent":["import type { FieldState } from \"./types\";\n\nimport type { FilledContentRelationshipField } from \"./contentRelationship\";\nimport type { EmbedField } from \"./embed\";\nimport type { FilledLinkToWebField } from \"./link\";\nimport type { FilledLinkToMediaField } from \"./linkToMedia\";\n\n/**\n * Types 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// 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}\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?:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField;\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:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField;\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":";;AAYO,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;;;"}
|
|
@@ -130,6 +130,7 @@ export interface RTLabelNode extends RTSpanNodeBase {
|
|
|
130
130
|
*/
|
|
131
131
|
export type RTImageNode = {
|
|
132
132
|
type: typeof RichTextNodeType.image;
|
|
133
|
+
id: string;
|
|
133
134
|
url: string;
|
|
134
135
|
alt: string | null;
|
|
135
136
|
copyright: string | null;
|
|
@@ -137,6 +138,12 @@ export type RTImageNode = {
|
|
|
137
138
|
width: number;
|
|
138
139
|
height: number;
|
|
139
140
|
};
|
|
141
|
+
edit: {
|
|
142
|
+
x: number;
|
|
143
|
+
y: number;
|
|
144
|
+
zoom: number;
|
|
145
|
+
background: string;
|
|
146
|
+
};
|
|
140
147
|
linkTo?: FilledContentRelationshipField | FilledLinkToWebField | FilledLinkToMediaField;
|
|
141
148
|
};
|
|
142
149
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"richText.js","sources":["../../../../src/types/value/richText.ts"],"sourcesContent":["import type { FieldState } from \"./types\";\n\nimport type { FilledContentRelationshipField } from \"./contentRelationship\";\nimport type { EmbedField } from \"./embed\";\nimport type { FilledLinkToWebField } from \"./link\";\nimport type { FilledLinkToMediaField } from \"./linkToMedia\";\n\n/**\n * Types 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// 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}\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\turl: string;\n\talt: string | null;\n\tcopyright: string | null;\n\tdimensions: {\n\t\twidth: number;\n\t\theight: number;\n\t};\n\tlinkTo?:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField;\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:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField;\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":"AAYO,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;;"}
|
|
1
|
+
{"version":3,"file":"richText.js","sources":["../../../../src/types/value/richText.ts"],"sourcesContent":["import type { FieldState } from \"./types\";\n\nimport type { FilledContentRelationshipField } from \"./contentRelationship\";\nimport type { EmbedField } from \"./embed\";\nimport type { FilledLinkToWebField } from \"./link\";\nimport type { FilledLinkToMediaField } from \"./linkToMedia\";\n\n/**\n * Types 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// 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}\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?:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField;\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:\n\t\t| FilledContentRelationshipField\n\t\t| FilledLinkToWebField\n\t\t| FilledLinkToMediaField;\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":"AAYO,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;;"}
|
|
@@ -7,5 +7,5 @@ import type { SharedSliceVariation } from "./sharedSliceVariation";
|
|
|
7
7
|
export type SharedSlice<SliceType = string, Variations extends SharedSliceVariation = SharedSliceVariation> = {
|
|
8
8
|
slice_type: SliceType;
|
|
9
9
|
slice_label: null;
|
|
10
|
-
id
|
|
10
|
+
id: string;
|
|
11
11
|
} & Variations;
|
|
@@ -7,7 +7,7 @@ import type { AnyRegularField } from "./types";
|
|
|
7
7
|
export interface Slice<SliceType = string, PrimaryFields extends Record<string, AnyRegularField> = Record<string, AnyRegularField>, ItemsFields extends Record<string, AnyRegularField> = Record<string, AnyRegularField>> {
|
|
8
8
|
slice_type: SliceType;
|
|
9
9
|
slice_label: string | null;
|
|
10
|
-
id
|
|
10
|
+
id: string;
|
|
11
11
|
primary: PrimaryFields;
|
|
12
12
|
items: ItemsFields[];
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "The official JavaScript + TypeScript client library for Prismic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -32,12 +32,32 @@
|
|
|
32
32
|
"default": "./dist/index.js"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
|
+
"./richtext": {
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/richtext/index.d.ts",
|
|
38
|
+
"default": "./dist/richtext.cjs"
|
|
39
|
+
},
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/richtext/index.d.ts",
|
|
42
|
+
"default": "./dist/richtext.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
35
45
|
"./package.json": "./package.json"
|
|
36
46
|
},
|
|
37
47
|
"main": "./dist/index.cjs",
|
|
38
48
|
"module": "./dist/index.js",
|
|
39
49
|
"react-native": "./dist/index.js",
|
|
40
50
|
"types": "./dist/index.d.ts",
|
|
51
|
+
"typesVersions": {
|
|
52
|
+
"*": {
|
|
53
|
+
"*": [
|
|
54
|
+
"dist/index.d.ts"
|
|
55
|
+
],
|
|
56
|
+
"richtext": [
|
|
57
|
+
"dist/richtext/index.d.ts"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
},
|
|
41
61
|
"files": [
|
|
42
62
|
"dist",
|
|
43
63
|
"src"
|
|
@@ -59,33 +79,32 @@
|
|
|
59
79
|
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
|
|
60
80
|
},
|
|
61
81
|
"dependencies": {
|
|
62
|
-
"@prismicio/richtext": "^2.1.5",
|
|
63
82
|
"imgix-url-builder": "^0.0.4"
|
|
64
83
|
},
|
|
65
84
|
"devDependencies": {
|
|
66
85
|
"@prismicio/mock": "^0.3.1",
|
|
67
|
-
"@prismicio/types-internal": "2.
|
|
68
|
-
"@size-limit/preset-small-lib": "^
|
|
86
|
+
"@prismicio/types-internal": "2.3.0",
|
|
87
|
+
"@size-limit/preset-small-lib": "^9.0.0",
|
|
69
88
|
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
|
|
70
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
71
|
-
"@typescript-eslint/parser": "^6.
|
|
72
|
-
"@vitest/coverage-v8": "^0.34.
|
|
89
|
+
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
90
|
+
"@typescript-eslint/parser": "^6.7.4",
|
|
91
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
73
92
|
"abort-controller": "^3.0.0",
|
|
74
|
-
"eslint": "^8.
|
|
93
|
+
"eslint": "^8.50.0",
|
|
75
94
|
"eslint-config-prettier": "^9.0.0",
|
|
76
95
|
"eslint-plugin-prettier": "^5.0.0",
|
|
77
96
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
78
|
-
"msw": "^1.2
|
|
97
|
+
"msw": "^1.3.2",
|
|
79
98
|
"node-fetch": "^3.3.2",
|
|
80
|
-
"prettier": "^3.0.
|
|
81
|
-
"prettier-plugin-jsdoc": "
|
|
82
|
-
"size-limit": "^
|
|
99
|
+
"prettier": "^3.0.3",
|
|
100
|
+
"prettier-plugin-jsdoc": "1.0.2",
|
|
101
|
+
"size-limit": "^9.0.0",
|
|
83
102
|
"standard-version": "^9.5.0",
|
|
84
103
|
"ts-expect": "^1.3.0",
|
|
85
|
-
"typescript": "
|
|
86
|
-
"vite": "^4.4.
|
|
104
|
+
"typescript": "~5.0.4",
|
|
105
|
+
"vite": "^4.4.11",
|
|
87
106
|
"vite-plugin-sdk": "^0.1.1",
|
|
88
|
-
"vitest": "^0.34.
|
|
107
|
+
"vitest": "^0.34.6"
|
|
89
108
|
},
|
|
90
109
|
"engines": {
|
|
91
110
|
"node": ">=14.15.0"
|
package/src/createClient.ts
CHANGED
|
@@ -19,6 +19,8 @@ import { ForbiddenError } from "./errors/ForbiddenError";
|
|
|
19
19
|
import { NotFoundError } from "./errors/NotFoundError";
|
|
20
20
|
import { ParsingError } from "./errors/ParsingError";
|
|
21
21
|
import { PrismicError } from "./errors/PrismicError";
|
|
22
|
+
import { RefExpiredError } from "./errors/RefExpiredError";
|
|
23
|
+
import { RefNotFoundError } from "./errors/RefNotFoundError";
|
|
22
24
|
|
|
23
25
|
import { LinkResolverFunction, asLink } from "./helpers/asLink";
|
|
24
26
|
|
|
@@ -1900,22 +1902,33 @@ export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
|
1900
1902
|
// - Incorrect access token for query endpoint
|
|
1901
1903
|
case 403: {
|
|
1902
1904
|
throw new ForbiddenError(
|
|
1903
|
-
|
|
1905
|
+
res.json.error || res.json.message,
|
|
1904
1906
|
url,
|
|
1905
1907
|
res.json,
|
|
1906
1908
|
);
|
|
1907
1909
|
}
|
|
1908
1910
|
|
|
1909
|
-
// Not Found
|
|
1910
|
-
// - Incorrect repository name
|
|
1911
|
+
// Not Found
|
|
1912
|
+
// - Incorrect repository name (this response has an empty body)
|
|
1913
|
+
// - Ref does not exist
|
|
1911
1914
|
case 404: {
|
|
1915
|
+
if (res.json && res.json.type === "api_notfound_error") {
|
|
1916
|
+
throw new RefNotFoundError(res.json.message, url, res.json);
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1912
1919
|
throw new NotFoundError(
|
|
1913
1920
|
`Prismic repository not found. Check that "${this.endpoint}" is pointing to the correct repository.`,
|
|
1914
1921
|
url,
|
|
1915
|
-
undefined,
|
|
1922
|
+
undefined, // res.json is empty
|
|
1916
1923
|
);
|
|
1917
1924
|
}
|
|
1918
1925
|
|
|
1926
|
+
// Gone
|
|
1927
|
+
// - Ref is expired
|
|
1928
|
+
case 410: {
|
|
1929
|
+
throw new RefExpiredError(res.json.message, url, res.json);
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1919
1932
|
// Too Many Requests
|
|
1920
1933
|
// - Exceeded the maximum number of requests per second
|
|
1921
1934
|
case 429: {
|
|
@@ -9,6 +9,8 @@ type ForbiddenErrorQueryAPIResponse = {
|
|
|
9
9
|
error: string;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export class ForbiddenError
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export class ForbiddenError<
|
|
13
|
+
TResponse =
|
|
14
|
+
| ForbiddenErrorRepositoryAPIResponse
|
|
15
|
+
| ForbiddenErrorQueryAPIResponse,
|
|
16
|
+
> extends PrismicError<TResponse> {}
|