@prismicio/migrate 0.0.2-canary.3e6d6e6 → 0.0.2-canary.9aa3ce7
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/errors/PrismicRichTextError.d.cts +1 -2
- package/dist/errors/PrismicRichTextError.d.cts.map +1 -1
- package/dist/errors/PrismicRichTextError.d.ts +1 -2
- package/dist/errors/PrismicRichTextError.d.ts.map +1 -1
- package/dist/errors/PrismicRichTextSerializerError.d.cts +1 -2
- package/dist/errors/PrismicRichTextSerializerError.d.cts.map +1 -1
- package/dist/errors/PrismicRichTextSerializerError.d.ts +1 -2
- package/dist/errors/PrismicRichTextSerializerError.d.ts.map +1 -1
- package/dist/htmlAsRichText.d.cts +2 -3
- package/dist/htmlAsRichText.d.cts.map +1 -1
- package/dist/htmlAsRichText.d.ts +2 -3
- package/dist/htmlAsRichText.d.ts.map +1 -1
- package/dist/lib/RichTextFieldBuilder.cjs.map +1 -1
- package/dist/lib/RichTextFieldBuilder.d.cts +1 -2
- package/dist/lib/RichTextFieldBuilder.d.cts.map +1 -1
- package/dist/lib/RichTextFieldBuilder.d.ts +1 -2
- package/dist/lib/RichTextFieldBuilder.d.ts.map +1 -1
- package/dist/lib/RichTextFieldBuilder.js.map +1 -1
- package/dist/lib/filterRichTextField.cjs +19 -14
- package/dist/lib/filterRichTextField.cjs.map +1 -1
- package/dist/lib/filterRichTextField.js +19 -14
- package/dist/lib/filterRichTextField.js.map +1 -1
- package/dist/lib/hastToRichText.d.cts +1 -2
- package/dist/lib/hastToRichText.d.cts.map +1 -1
- package/dist/lib/hastToRichText.d.ts +1 -2
- package/dist/lib/hastToRichText.d.ts.map +1 -1
- package/dist/lib/rehypeRichText.d.cts +1 -2
- package/dist/lib/rehypeRichText.d.cts.map +1 -1
- package/dist/lib/rehypeRichText.d.ts +1 -2
- package/dist/lib/rehypeRichText.d.ts.map +1 -1
- package/dist/types.d.cts +3 -4
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +3 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichTextError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"PrismicRichTextError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":";qBAAa,6BAA6B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichTextError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"PrismicRichTextError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":";qBAAa,6BAA6B"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { PrismicRichTextError } from "./PrismicRichTextError.cjs";
|
|
2
2
|
//#region src/errors/PrismicRichTextSerializerError.d.ts
|
|
3
|
-
declare class PrismicRichTextSerializerError extends PrismicRichTextError {}
|
|
3
|
+
export declare class PrismicRichTextSerializerError extends PrismicRichTextError {}
|
|
4
4
|
//#endregion
|
|
5
|
-
export { PrismicRichTextSerializerError };
|
|
6
5
|
//# sourceMappingURL=PrismicRichTextSerializerError.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichTextSerializerError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"PrismicRichTextSerializerError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";;qBAEa,uCAAuC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { PrismicRichTextError } from "./PrismicRichTextError.js";
|
|
2
2
|
//#region src/errors/PrismicRichTextSerializerError.d.ts
|
|
3
|
-
declare class PrismicRichTextSerializerError extends PrismicRichTextError {}
|
|
3
|
+
export declare class PrismicRichTextSerializerError extends PrismicRichTextError {}
|
|
4
4
|
//#endregion
|
|
5
|
-
export { PrismicRichTextSerializerError };
|
|
6
5
|
//# sourceMappingURL=PrismicRichTextSerializerError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichTextSerializerError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"PrismicRichTextSerializerError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";;qBAEa,uCAAuC"}
|
|
@@ -4,7 +4,7 @@ import { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from "@prismic
|
|
|
4
4
|
import { Element } from "hast";
|
|
5
5
|
//#region src/htmlAsRichText.d.ts
|
|
6
6
|
/** Configuration that determines the output of {@link htmlAsRichText}. */
|
|
7
|
-
type HTMLAsRichTextConfig = RehypeRichTextConfig;
|
|
7
|
+
export type HTMLAsRichTextConfig = RehypeRichTextConfig;
|
|
8
8
|
/** The return type of {@link htmlAsRichText}. */
|
|
9
9
|
type HTMLAsRichTextReturnType = {
|
|
10
10
|
result: RichTextField;
|
|
@@ -17,7 +17,6 @@ type HTMLAsRichTextReturnType = {
|
|
|
17
17
|
* @param config - Configuration that determines the output the function.
|
|
18
18
|
* @returns `html` as rich text.
|
|
19
19
|
*/
|
|
20
|
-
declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
|
|
20
|
+
export declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
|
|
21
21
|
//#endregion
|
|
22
|
-
export { HTMLAsRichTextConfig, htmlAsRichText };
|
|
23
22
|
//# sourceMappingURL=htmlAsRichText.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlAsRichText.d.cts","names":[],"sources":["../src/htmlAsRichText.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"htmlAsRichText.d.cts","names":[],"sources":["../src/htmlAsRichText.ts"],"mappings":";;;;;;YAgEY,uBAAuB;;KAG9B;EACJ,QAAQ;EACR;;;;;;;;;qBAUY,iBAAc,cACd,SACH,yBACP"}
|
package/dist/htmlAsRichText.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from "@prismic
|
|
|
4
4
|
import { Element } from "hast";
|
|
5
5
|
//#region src/htmlAsRichText.d.ts
|
|
6
6
|
/** Configuration that determines the output of {@link htmlAsRichText}. */
|
|
7
|
-
type HTMLAsRichTextConfig = RehypeRichTextConfig;
|
|
7
|
+
export type HTMLAsRichTextConfig = RehypeRichTextConfig;
|
|
8
8
|
/** The return type of {@link htmlAsRichText}. */
|
|
9
9
|
type HTMLAsRichTextReturnType = {
|
|
10
10
|
result: RichTextField;
|
|
@@ -17,7 +17,6 @@ type HTMLAsRichTextReturnType = {
|
|
|
17
17
|
* @param config - Configuration that determines the output the function.
|
|
18
18
|
* @returns `html` as rich text.
|
|
19
19
|
*/
|
|
20
|
-
declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
|
|
20
|
+
export declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
|
|
21
21
|
//#endregion
|
|
22
|
-
export { HTMLAsRichTextConfig, htmlAsRichText };
|
|
23
22
|
//# sourceMappingURL=htmlAsRichText.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlAsRichText.d.ts","names":[],"sources":["../src/htmlAsRichText.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"htmlAsRichText.d.ts","names":[],"sources":["../src/htmlAsRichText.ts"],"mappings":";;;;;;YAgEY,uBAAuB;;KAG9B;EACJ,QAAQ;EACR;;;;;;;;;qBAUY,iBAAc,cACd,SACH,yBACP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextFieldBuilder.cjs","names":["
|
|
1
|
+
{"version":3,"file":"RichTextFieldBuilder.cjs","names":["PrismicRichTextError"],"sources":["../../src/lib/RichTextFieldBuilder.ts"],"sourcesContent":["import type {\n\tInjectMigrationSpecificTypes,\n\tRTInlineNode,\n\tRTLinkNode,\n\tRTNode,\n\tRTTextNode,\n\tRichTextField,\n} from \"@prismicio/client\"\n\nimport { PrismicRichTextError } from \"../errors/PrismicRichTextError\"\n\n/**\n * Omits keys from a type, distributing the operation over a union.\n *\n * Taken from the `type-fest` package.\n *\n * @see https://github.com/sindresorhus/type-fest/blob/8a45ba048767aaffcebc7d190172d814a739feb0/source/distributed-omit.d.ts\n */\ntype DistributedOmit<ObjectType, KeyType extends keyof ObjectType> = ObjectType extends unknown\n\t? Omit<ObjectType, KeyType>\n\t: never\n\n/** An inline node without its `start` and `end` properties. */\nexport type RTPartialInlineNode = DistributedOmit<RTInlineNode, \"start\" | \"end\">\n\nexport class RichTextFieldBuilder {\n\t#nodes: InjectMigrationSpecificTypes<RTNode>[] = []\n\n\tget #last(): InjectMigrationSpecificTypes<RTNode> | undefined {\n\t\treturn this.#nodes[this.#nodes.length - 1]\n\t}\n\n\tappendNode(node: InjectMigrationSpecificTypes<RTNode>): void {\n\t\tthis.cleanupLast()\n\n\t\tthis.#nodes.push(node)\n\t}\n\n\tappendTextNode(type: RTTextNode[\"type\"], direction: \"ltr\" | \"rtl\" = \"ltr\"): void {\n\t\tthis.appendNode({\n\t\t\ttype,\n\t\t\ttext: \"\",\n\t\t\tspans: [],\n\t\t\tdirection,\n\t\t})\n\t}\n\n\tappendSpan(span: InjectMigrationSpecificTypes<RTInlineNode>): void\n\tappendSpan(partialSpan: InjectMigrationSpecificTypes<RTPartialInlineNode>, length: number): void\n\tappendSpan(\n\t\tspanOrPartialSpan: InjectMigrationSpecificTypes<RTInlineNode | RTPartialInlineNode>,\n\t\tlength?: number,\n\t): void {\n\t\tif (!this.isTextNode(this.#last)) {\n\t\t\tthrow new PrismicRichTextError(\"Cannot add span to non-text last node\")\n\t\t}\n\n\t\tlet span: InjectMigrationSpecificTypes<RTInlineNode>\n\t\tif (\"start\" in spanOrPartialSpan && \"end\" in spanOrPartialSpan) {\n\t\t\tspan = spanOrPartialSpan\n\t\t} else {\n\t\t\tconst lastLength = this.#last.text.length\n\n\t\t\tspan = {\n\t\t\t\t...spanOrPartialSpan,\n\t\t\t\tstart: lastLength,\n\t\t\t\tend: lastLength + length!,\n\t\t\t}\n\t\t}\n\n\t\tlet lastIdenticalSpanIndex = -1\n\t\tfor (let i = this.#last.spans.length - 1; i >= 0; i--) {\n\t\t\tconst lastSpan = this.#last.spans[i]\n\n\t\t\tif (span.type === \"strong\" || span.type === \"em\") {\n\t\t\t\tif (lastSpan.type === span.type) {\n\t\t\t\t\tlastIdenticalSpanIndex = i\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (span.type === \"label\") {\n\t\t\t\tif (lastSpan.type === \"label\" && lastSpan.data.label === span.data.label) {\n\t\t\t\t\tlastIdenticalSpanIndex = i\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (span.type === \"hyperlink\") {\n\t\t\t\tif (lastSpan.type === \"hyperlink\") {\n\t\t\t\t\t// Check that all data fields are the same. Since it's not a\n\t\t\t\t\t// deep equal operation, this doesn't guarantee a perfect\n\t\t\t\t\t// match with content relationship.\n\t\t\t\t\tconst isSameLink =\n\t\t\t\t\t\ttypeof span.data === \"object\" && typeof lastSpan.data === \"object\"\n\t\t\t\t\t\t\t? (Object.entries(span.data) as [keyof RTLinkNode[\"data\"], unknown][]).every(\n\t\t\t\t\t\t\t\t\t([key, value]) =>\n\t\t\t\t\t\t\t\t\t\tlastSpan.data?.[key as keyof (typeof lastSpan)[\"data\"]] === value,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: span.data === lastSpan.data\n\n\t\t\t\t\tif (isSameLink) {\n\t\t\t\t\t\tlastIdenticalSpanIndex = i\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Ignore empty spans.\n\t\tif (span.start === span.end) {\n\t\t\treturn\n\t\t}\n\n\t\t// Prefer to extend the last span of the same type end\n\t\t// position if it ends at the start of the new span.\n\t\tif (this.#last.spans[lastIdenticalSpanIndex]?.end === span.start) {\n\t\t\tthis.#last.spans[lastIdenticalSpanIndex].end = span.end\n\t\t} else {\n\t\t\tthis.#last.spans.push(span)\n\t\t}\n\t}\n\n\tappendText(text: string): void {\n\t\tif (!this.isTextNode(this.#last)) {\n\t\t\tthrow new PrismicRichTextError(\"Cannot append text to non-text last node\")\n\t\t}\n\n\t\tif (this.#last.text) {\n\t\t\tthis.#last.text += text\n\t\t} else {\n\t\t\tthis.#last.text = text.trimStart()\n\t\t}\n\t}\n\n\tbuild(): RichTextField {\n\t\t// Ensure that the last text node is trimmed.\n\t\tthis.cleanupLast()\n\n\t\t// Because `RichTextField` is defined as a non-empty\n\t\t// array, we have to cast `RTNode[]` to `RichTextField`.\n\t\treturn this.#nodes as RichTextField\n\t}\n\n\t/** Cleans up the current last node. */\n\tprivate cleanupLast(): void {\n\t\tif (this.isTextNode(this.#last)) {\n\t\t\tthis.#last.text = this.#last.text.trimEnd()\n\t\t}\n\t}\n\n\t/**\n\t * Determines if a node is a text node.\n\t *\n\t * @param node - Rich text node to check.\n\t * @returns `true` if `node` is a text node, `false` otherwise.\n\t */\n\tprivate isTextNode(\n\t\tnode?: InjectMigrationSpecificTypes<RTNode>,\n\t): node is InjectMigrationSpecificTypes<RTTextNode> {\n\t\treturn !!node && node.type !== \"image\" && node.type !== \"embed\"\n\t}\n}\n"],"mappings":";;AAyBA,IAAa,uBAAb,MAAkC;CACjC,SAAiD,CAAC;CAElD,IAAI,QAA0D;EAC7D,OAAO,KAAK,OAAO,KAAK,OAAO,SAAS;CACzC;CAEA,WAAW,MAAkD;EAC5D,KAAK,YAAY;EAEjB,KAAK,OAAO,KAAK,IAAI;CACtB;CAEA,eAAe,MAA0B,YAA2B,OAAa;EAChF,KAAK,WAAW;GACf;GACA,MAAM;GACN,OAAO,CAAC;GACR;EACD,CAAC;CACF;CAIA,WACC,mBACA,QACO;EACP,IAAI,CAAC,KAAK,WAAW,KAAK,KAAK,GAC9B,MAAM,IAAIA,6BAAAA,qBAAqB,uCAAuC;EAGvE,IAAI;EACJ,IAAI,WAAW,qBAAqB,SAAS,mBAC5C,OAAO;OACD;GACN,MAAM,aAAa,KAAK,MAAM,KAAK;GAEnC,OAAO;IACN,GAAG;IACH,OAAO;IACP,KAAK,aAAa;GACnB;EACD;EAEA,IAAI,yBAAyB;EAC7B,KAAK,IAAI,IAAI,KAAK,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;GACtD,MAAM,WAAW,KAAK,MAAM,MAAM;GAElC,IAAI,KAAK,SAAS,YAAY,KAAK,SAAS,MACvC;QAAA,SAAS,SAAS,KAAK,MAAM;KAChC,yBAAyB;KACzB;IACD;UACM,IAAI,KAAK,SAAS,SACpB;QAAA,SAAS,SAAS,WAAW,SAAS,KAAK,UAAU,KAAK,KAAK,OAAO;KACzE,yBAAyB;KACzB;IACD;UACM,IAAI,KAAK,SAAS,aACpB;QAAA,SAAS,SAAS,aAKpB;SAAA,OAAO,KAAK,SAAS,YAAY,OAAO,SAAS,SAAS,WACtD,OAAO,QAAQ,KAAK,IAAI,CAAC,CAA2C,OACpE,CAAC,KAAK,WACN,SAAS,OAAO,SAA4C,KAC9D,IACC,KAAK,SAAS,SAAS,MAEX;MACf,yBAAyB;MACzB;KACD;;;EAGH;EAGA,IAAI,KAAK,UAAU,KAAK,KACvB;EAKD,IAAI,KAAK,MAAM,MAAM,uBAAuB,EAAE,QAAQ,KAAK,OAC1D,KAAK,MAAM,MAAM,uBAAuB,CAAC,MAAM,KAAK;OAEpD,KAAK,MAAM,MAAM,KAAK,IAAI;CAE5B;CAEA,WAAW,MAAoB;EAC9B,IAAI,CAAC,KAAK,WAAW,KAAK,KAAK,GAC9B,MAAM,IAAIA,6BAAAA,qBAAqB,0CAA0C;EAG1E,IAAI,KAAK,MAAM,MACd,KAAK,MAAM,QAAQ;OAEnB,KAAK,MAAM,OAAO,KAAK,UAAU;CAEnC;CAEA,QAAuB;EAEtB,KAAK,YAAY;EAIjB,OAAO,KAAK;CACb;;CAGA,cAA4B;EAC3B,IAAI,KAAK,WAAW,KAAK,KAAK,GAC7B,KAAK,MAAM,OAAO,KAAK,MAAM,KAAK,QAAQ;CAE5C;;;;;;;CAQA,WACC,MACmD;EACnD,OAAO,CAAC,CAAC,QAAQ,KAAK,SAAS,WAAW,KAAK,SAAS;CACzD;AACD"}
|
|
@@ -9,7 +9,6 @@ import { InjectMigrationSpecificTypes, RTInlineNode, RTNode, RichTextField } fro
|
|
|
9
9
|
*/
|
|
10
10
|
type DistributedOmit<ObjectType, KeyType extends keyof ObjectType> = ObjectType extends unknown ? Omit<ObjectType, KeyType> : never;
|
|
11
11
|
/** An inline node without its `start` and `end` properties. */
|
|
12
|
-
type RTPartialInlineNode = DistributedOmit<RTInlineNode, "start" | "end">;
|
|
12
|
+
export type RTPartialInlineNode = DistributedOmit<RTInlineNode, "start" | "end">;
|
|
13
13
|
//#endregion
|
|
14
|
-
export { RTPartialInlineNode };
|
|
15
14
|
//# sourceMappingURL=RichTextFieldBuilder.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextFieldBuilder.d.cts","names":[],"sources":["../../src/lib/RichTextFieldBuilder.ts"],"mappings":";;;;;;;;;KAkBK,gBAAgB,YAAY,sBAAsB,cAAc,6BAClE,KAAK,YAAY;;
|
|
1
|
+
{"version":3,"file":"RichTextFieldBuilder.d.cts","names":[],"sources":["../../src/lib/RichTextFieldBuilder.ts"],"mappings":";;;;;;;;;KAkBK,gBAAgB,YAAY,sBAAsB,cAAc,6BAClE,KAAK,YAAY;;YAIR,sBAAsB,gBAAgB"}
|
|
@@ -9,7 +9,6 @@ import { InjectMigrationSpecificTypes, RTInlineNode, RTNode, RichTextField } fro
|
|
|
9
9
|
*/
|
|
10
10
|
type DistributedOmit<ObjectType, KeyType extends keyof ObjectType> = ObjectType extends unknown ? Omit<ObjectType, KeyType> : never;
|
|
11
11
|
/** An inline node without its `start` and `end` properties. */
|
|
12
|
-
type RTPartialInlineNode = DistributedOmit<RTInlineNode, "start" | "end">;
|
|
12
|
+
export type RTPartialInlineNode = DistributedOmit<RTInlineNode, "start" | "end">;
|
|
13
13
|
//#endregion
|
|
14
|
-
export { RTPartialInlineNode };
|
|
15
14
|
//# sourceMappingURL=RichTextFieldBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextFieldBuilder.d.ts","names":[],"sources":["../../src/lib/RichTextFieldBuilder.ts"],"mappings":";;;;;;;;;KAkBK,gBAAgB,YAAY,sBAAsB,cAAc,6BAClE,KAAK,YAAY;;
|
|
1
|
+
{"version":3,"file":"RichTextFieldBuilder.d.ts","names":[],"sources":["../../src/lib/RichTextFieldBuilder.ts"],"mappings":";;;;;;;;;KAkBK,gBAAgB,YAAY,sBAAsB,cAAc,6BAClE,KAAK,YAAY;;YAIR,sBAAsB,gBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextFieldBuilder.js","names":[
|
|
1
|
+
{"version":3,"file":"RichTextFieldBuilder.js","names":[],"sources":["../../src/lib/RichTextFieldBuilder.ts"],"sourcesContent":["import type {\n\tInjectMigrationSpecificTypes,\n\tRTInlineNode,\n\tRTLinkNode,\n\tRTNode,\n\tRTTextNode,\n\tRichTextField,\n} from \"@prismicio/client\"\n\nimport { PrismicRichTextError } from \"../errors/PrismicRichTextError\"\n\n/**\n * Omits keys from a type, distributing the operation over a union.\n *\n * Taken from the `type-fest` package.\n *\n * @see https://github.com/sindresorhus/type-fest/blob/8a45ba048767aaffcebc7d190172d814a739feb0/source/distributed-omit.d.ts\n */\ntype DistributedOmit<ObjectType, KeyType extends keyof ObjectType> = ObjectType extends unknown\n\t? Omit<ObjectType, KeyType>\n\t: never\n\n/** An inline node without its `start` and `end` properties. */\nexport type RTPartialInlineNode = DistributedOmit<RTInlineNode, \"start\" | \"end\">\n\nexport class RichTextFieldBuilder {\n\t#nodes: InjectMigrationSpecificTypes<RTNode>[] = []\n\n\tget #last(): InjectMigrationSpecificTypes<RTNode> | undefined {\n\t\treturn this.#nodes[this.#nodes.length - 1]\n\t}\n\n\tappendNode(node: InjectMigrationSpecificTypes<RTNode>): void {\n\t\tthis.cleanupLast()\n\n\t\tthis.#nodes.push(node)\n\t}\n\n\tappendTextNode(type: RTTextNode[\"type\"], direction: \"ltr\" | \"rtl\" = \"ltr\"): void {\n\t\tthis.appendNode({\n\t\t\ttype,\n\t\t\ttext: \"\",\n\t\t\tspans: [],\n\t\t\tdirection,\n\t\t})\n\t}\n\n\tappendSpan(span: InjectMigrationSpecificTypes<RTInlineNode>): void\n\tappendSpan(partialSpan: InjectMigrationSpecificTypes<RTPartialInlineNode>, length: number): void\n\tappendSpan(\n\t\tspanOrPartialSpan: InjectMigrationSpecificTypes<RTInlineNode | RTPartialInlineNode>,\n\t\tlength?: number,\n\t): void {\n\t\tif (!this.isTextNode(this.#last)) {\n\t\t\tthrow new PrismicRichTextError(\"Cannot add span to non-text last node\")\n\t\t}\n\n\t\tlet span: InjectMigrationSpecificTypes<RTInlineNode>\n\t\tif (\"start\" in spanOrPartialSpan && \"end\" in spanOrPartialSpan) {\n\t\t\tspan = spanOrPartialSpan\n\t\t} else {\n\t\t\tconst lastLength = this.#last.text.length\n\n\t\t\tspan = {\n\t\t\t\t...spanOrPartialSpan,\n\t\t\t\tstart: lastLength,\n\t\t\t\tend: lastLength + length!,\n\t\t\t}\n\t\t}\n\n\t\tlet lastIdenticalSpanIndex = -1\n\t\tfor (let i = this.#last.spans.length - 1; i >= 0; i--) {\n\t\t\tconst lastSpan = this.#last.spans[i]\n\n\t\t\tif (span.type === \"strong\" || span.type === \"em\") {\n\t\t\t\tif (lastSpan.type === span.type) {\n\t\t\t\t\tlastIdenticalSpanIndex = i\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (span.type === \"label\") {\n\t\t\t\tif (lastSpan.type === \"label\" && lastSpan.data.label === span.data.label) {\n\t\t\t\t\tlastIdenticalSpanIndex = i\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (span.type === \"hyperlink\") {\n\t\t\t\tif (lastSpan.type === \"hyperlink\") {\n\t\t\t\t\t// Check that all data fields are the same. Since it's not a\n\t\t\t\t\t// deep equal operation, this doesn't guarantee a perfect\n\t\t\t\t\t// match with content relationship.\n\t\t\t\t\tconst isSameLink =\n\t\t\t\t\t\ttypeof span.data === \"object\" && typeof lastSpan.data === \"object\"\n\t\t\t\t\t\t\t? (Object.entries(span.data) as [keyof RTLinkNode[\"data\"], unknown][]).every(\n\t\t\t\t\t\t\t\t\t([key, value]) =>\n\t\t\t\t\t\t\t\t\t\tlastSpan.data?.[key as keyof (typeof lastSpan)[\"data\"]] === value,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: span.data === lastSpan.data\n\n\t\t\t\t\tif (isSameLink) {\n\t\t\t\t\t\tlastIdenticalSpanIndex = i\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Ignore empty spans.\n\t\tif (span.start === span.end) {\n\t\t\treturn\n\t\t}\n\n\t\t// Prefer to extend the last span of the same type end\n\t\t// position if it ends at the start of the new span.\n\t\tif (this.#last.spans[lastIdenticalSpanIndex]?.end === span.start) {\n\t\t\tthis.#last.spans[lastIdenticalSpanIndex].end = span.end\n\t\t} else {\n\t\t\tthis.#last.spans.push(span)\n\t\t}\n\t}\n\n\tappendText(text: string): void {\n\t\tif (!this.isTextNode(this.#last)) {\n\t\t\tthrow new PrismicRichTextError(\"Cannot append text to non-text last node\")\n\t\t}\n\n\t\tif (this.#last.text) {\n\t\t\tthis.#last.text += text\n\t\t} else {\n\t\t\tthis.#last.text = text.trimStart()\n\t\t}\n\t}\n\n\tbuild(): RichTextField {\n\t\t// Ensure that the last text node is trimmed.\n\t\tthis.cleanupLast()\n\n\t\t// Because `RichTextField` is defined as a non-empty\n\t\t// array, we have to cast `RTNode[]` to `RichTextField`.\n\t\treturn this.#nodes as RichTextField\n\t}\n\n\t/** Cleans up the current last node. */\n\tprivate cleanupLast(): void {\n\t\tif (this.isTextNode(this.#last)) {\n\t\t\tthis.#last.text = this.#last.text.trimEnd()\n\t\t}\n\t}\n\n\t/**\n\t * Determines if a node is a text node.\n\t *\n\t * @param node - Rich text node to check.\n\t * @returns `true` if `node` is a text node, `false` otherwise.\n\t */\n\tprivate isTextNode(\n\t\tnode?: InjectMigrationSpecificTypes<RTNode>,\n\t): node is InjectMigrationSpecificTypes<RTTextNode> {\n\t\treturn !!node && node.type !== \"image\" && node.type !== \"embed\"\n\t}\n}\n"],"mappings":";;AAyBA,IAAa,uBAAb,MAAkC;CACjC,SAAiD,CAAC;CAElD,IAAI,QAA0D;EAC7D,OAAO,KAAK,OAAO,KAAK,OAAO,SAAS;CACzC;CAEA,WAAW,MAAkD;EAC5D,KAAK,YAAY;EAEjB,KAAK,OAAO,KAAK,IAAI;CACtB;CAEA,eAAe,MAA0B,YAA2B,OAAa;EAChF,KAAK,WAAW;GACf;GACA,MAAM;GACN,OAAO,CAAC;GACR;EACD,CAAC;CACF;CAIA,WACC,mBACA,QACO;EACP,IAAI,CAAC,KAAK,WAAW,KAAK,KAAK,GAC9B,MAAM,IAAI,qBAAqB,uCAAuC;EAGvE,IAAI;EACJ,IAAI,WAAW,qBAAqB,SAAS,mBAC5C,OAAO;OACD;GACN,MAAM,aAAa,KAAK,MAAM,KAAK;GAEnC,OAAO;IACN,GAAG;IACH,OAAO;IACP,KAAK,aAAa;GACnB;EACD;EAEA,IAAI,yBAAyB;EAC7B,KAAK,IAAI,IAAI,KAAK,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;GACtD,MAAM,WAAW,KAAK,MAAM,MAAM;GAElC,IAAI,KAAK,SAAS,YAAY,KAAK,SAAS,MACvC;QAAA,SAAS,SAAS,KAAK,MAAM;KAChC,yBAAyB;KACzB;IACD;UACM,IAAI,KAAK,SAAS,SACpB;QAAA,SAAS,SAAS,WAAW,SAAS,KAAK,UAAU,KAAK,KAAK,OAAO;KACzE,yBAAyB;KACzB;IACD;UACM,IAAI,KAAK,SAAS,aACpB;QAAA,SAAS,SAAS,aAKpB;SAAA,OAAO,KAAK,SAAS,YAAY,OAAO,SAAS,SAAS,WACtD,OAAO,QAAQ,KAAK,IAAI,CAAC,CAA2C,OACpE,CAAC,KAAK,WACN,SAAS,OAAO,SAA4C,KAC9D,IACC,KAAK,SAAS,SAAS,MAEX;MACf,yBAAyB;MACzB;KACD;;;EAGH;EAGA,IAAI,KAAK,UAAU,KAAK,KACvB;EAKD,IAAI,KAAK,MAAM,MAAM,uBAAuB,EAAE,QAAQ,KAAK,OAC1D,KAAK,MAAM,MAAM,uBAAuB,CAAC,MAAM,KAAK;OAEpD,KAAK,MAAM,MAAM,KAAK,IAAI;CAE5B;CAEA,WAAW,MAAoB;EAC9B,IAAI,CAAC,KAAK,WAAW,KAAK,KAAK,GAC9B,MAAM,IAAI,qBAAqB,0CAA0C;EAG1E,IAAI,KAAK,MAAM,MACd,KAAK,MAAM,QAAQ;OAEnB,KAAK,MAAM,OAAO,KAAK,UAAU;CAEnC;CAEA,QAAuB;EAEtB,KAAK,YAAY;EAIjB,OAAO,KAAK;CACb;;CAGA,cAA4B;EAC3B,IAAI,KAAK,WAAW,KAAK,KAAK,GAC7B,KAAK,MAAM,OAAO,KAAK,MAAM,KAAK,QAAQ;CAE5C;;;;;;;CAQA,WACC,MACmD;EACnD,OAAO,CAAC,CAAC,QAAQ,KAAK,SAAS,WAAW,KAAK,SAAS;CACzD;AACD"}
|
|
@@ -47,17 +47,20 @@ const filterTextNode = (node, model, allowedNodeTypes) => {
|
|
|
47
47
|
};
|
|
48
48
|
for (let i = 0; i < node.spans.length; i++) {
|
|
49
49
|
const span = node.spans[i];
|
|
50
|
-
if (allowedNodeTypes.includes(span.type))
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
if (allowedNodeTypes.includes(span.type)) {
|
|
51
|
+
if (span.type === _prismicio_client.RichTextNodeType.hyperlink) {
|
|
52
|
+
if (!model.config?.allowTargetBlank && span.data.link_type === _prismicio_client.LinkType.Web) filteredNode.spans.push({
|
|
53
|
+
...span,
|
|
54
|
+
data: {
|
|
55
|
+
...span.data,
|
|
56
|
+
target: void 0
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
else filteredNode.spans.push(span);
|
|
60
|
+
} else if (span.type === _prismicio_client.RichTextNodeType.label) {
|
|
61
|
+
if (model.config?.labels?.includes(span.data.label)) filteredNode.spans.push(span);
|
|
62
|
+
} else filteredNode.spans.push(span);
|
|
63
|
+
}
|
|
61
64
|
}
|
|
62
65
|
return filteredNode;
|
|
63
66
|
};
|
|
@@ -73,9 +76,11 @@ const filterRichTextField = (richTextField, model) => {
|
|
|
73
76
|
const allowedNodeTypes = getAllowedNodeTypes(model);
|
|
74
77
|
for (let i = 0; i < (model.config && "multi" in model.config ? richTextField.length : 1); i++) {
|
|
75
78
|
const node = richTextField[i];
|
|
76
|
-
if (allowedNodeTypes.includes(node.type))
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
if (allowedNodeTypes.includes(node.type)) {
|
|
80
|
+
if (node.type === _prismicio_client.RichTextNodeType.image) nodes.push(filterImageNode(node, model));
|
|
81
|
+
else if (node.type === _prismicio_client.RichTextNodeType.embed) nodes.push(node);
|
|
82
|
+
else nodes.push(filterTextNode(node, model, allowedNodeTypes));
|
|
83
|
+
}
|
|
79
84
|
}
|
|
80
85
|
return nodes;
|
|
81
86
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterRichTextField.cjs","names":["LinkType","RichTextNodeType"],"sources":["../../src/lib/filterRichTextField.ts"],"sourcesContent":["import type {\n\tCustomTypeModelRichTextField,\n\tRTImageNode,\n\tRTNode,\n\tRTTextNode,\n\tRichTextField,\n\tRichTextNodeTypes,\n\tTitleField,\n} from \"@prismicio/client\"\nimport { LinkType, RichTextNodeType } from \"@prismicio/client\"\n\n/**\n * Get allowed nodes types from a rich text or title field custom type model.\n *\n * @param model - A rich text or title field custom type model.\n * @returns An array of allowed nodes types.\n */\nconst getAllowedNodeTypes = (model: CustomTypeModelRichTextField): RichTextNodeTypes[] => {\n\tconst allowedNodeTypes: RichTextNodeTypes[] = [] // An empty array means no nodes are allowed by default.\n\n\tif (model.config) {\n\t\tif (\"multi\" in model.config && model.config.multi) {\n\t\t\tallowedNodeTypes.push(...(model.config.multi.split(\",\") as RichTextNodeTypes[]))\n\t\t} else if (\"single\" in model.config && model.config.single) {\n\t\t\tallowedNodeTypes.push(...(model.config.single.split(\",\") as RichTextNodeTypes[]))\n\t\t}\n\n\t\tif (model.config.labels?.length) {\n\t\t\tallowedNodeTypes.push(\"label\")\n\t\t}\n\t}\n\n\treturn allowedNodeTypes\n}\n\n/**\n * Filter an image node based on given model.\n *\n * @param node - An image node to filter.\n * @param model - A rich text or title field custom type model.\n * @returns A filtered image node based on the given model.\n */\nconst filterImageNode = (node: RTImageNode, model: CustomTypeModelRichTextField): RTImageNode => {\n\tif (!model.config?.allowTargetBlank && node.linkTo?.link_type === LinkType.Web) {\n\t\treturn {\n\t\t\t...node,\n\t\t\tlinkTo: {\n\t\t\t\t...node.linkTo,\n\t\t\t\ttarget: undefined,\n\t\t\t},\n\t\t}\n\t}\n\n\treturn node\n}\n\n/**\n * Filter a text node based on given model.\n *\n * @param node - A text node to filter.\n * @param model - A rich text or title field custom type model.\n * @param allowedNodeTypes - An array of allowed nodes types.\n * @returns A filtered text node based on the given model.\n */\nconst filterTextNode = (\n\tnode: RTTextNode,\n\tmodel: CustomTypeModelRichTextField,\n\tallowedNodeTypes: RichTextNodeTypes[],\n): RTTextNode => {\n\tconst filteredNode: RTTextNode = {\n\t\t...node,\n\t\tspans: [],\n\t}\n\n\tfor (let i = 0; i < node.spans.length; i++) {\n\t\tconst span = node.spans[i]\n\n\t\tif (allowedNodeTypes.includes(span.type)) {\n\t\t\tif (span.type === RichTextNodeType.hyperlink) {\n\t\t\t\tif (!model.config?.allowTargetBlank && span.data.link_type === LinkType.Web) {\n\t\t\t\t\tfilteredNode.spans.push({\n\t\t\t\t\t\t...span,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t...span.data,\n\t\t\t\t\t\t\ttarget: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else if (span.type === RichTextNodeType.label) {\n\t\t\t\tif (model.config?.labels?.includes(span.data.label)) {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn filteredNode\n}\n\n/**\n * Filter a rich text field based on given model.\n *\n * @param richTextField - A rich text or title field from Prismic.\n * @param model - A rich text or title field custom type model.\n * @returns A rich text or title field filtered based on the given model.\n */\nexport const filterRichTextField = <Field extends RichTextField | TitleField>(\n\trichTextField: Field,\n\tmodel: CustomTypeModelRichTextField,\n): Field => {\n\tconst nodes: RTNode[] = []\n\n\tconst allowedNodeTypes = getAllowedNodeTypes(model)\n\n\tfor (\n\t\tlet i = 0;\n\t\t// Only process the first node if it's a \"single\" node rich text type\n\t\ti < (model.config && \"multi\" in model.config ? richTextField.length : 1);\n\t\ti++\n\t) {\n\t\tconst node = richTextField[i]\n\n\t\tif (allowedNodeTypes.includes(node.type)) {\n\t\t\tif (node.type === RichTextNodeType.image) {\n\t\t\t\tnodes.push(filterImageNode(node, model))\n\t\t\t} else if (node.type === RichTextNodeType.embed) {\n\t\t\t\tnodes.push(node)\n\t\t\t} else {\n\t\t\t\tnodes.push(filterTextNode(node, model, allowedNodeTypes))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nodes as Field\n}\n"],"mappings":";;;;;;;;AAiBA,MAAM,uBAAuB,UAA6D;CACzF,MAAM,mBAAwC,CAAC;CAE/C,IAAI,MAAM,QAAQ;EACjB,IAAI,WAAW,MAAM,UAAU,MAAM,OAAO,OAC3C,iBAAiB,KAAK,GAAI,MAAM,OAAO,MAAM,MAAM,GAAG,CAAyB;OACzE,IAAI,YAAY,MAAM,UAAU,MAAM,OAAO,QACnD,iBAAiB,KAAK,GAAI,MAAM,OAAO,OAAO,MAAM,GAAG,CAAyB;EAGjF,IAAI,MAAM,OAAO,QAAQ,QACxB,iBAAiB,KAAK,OAAO;CAE/B;CAEA,OAAO;AACR;;;;;;;;AASA,MAAM,mBAAmB,MAAmB,UAAqD;CAChG,IAAI,CAAC,MAAM,QAAQ,oBAAoB,KAAK,QAAQ,cAAcA,kBAAAA,SAAS,KAC1E,OAAO;EACN,GAAG;EACH,QAAQ;GACP,GAAG,KAAK;GACR,QAAQ,KAAA;EACT;CACD;CAGD,OAAO;AACR;;;;;;;;;AAUA,MAAM,kBACL,MACA,OACA,qBACgB;CAChB,MAAM,eAA2B;EAChC,GAAG;EACH,OAAO,CAAC;CACT;CAEA,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,MAAM,QAAQ,KAAK;EAC3C,MAAM,OAAO,KAAK,MAAM;EAExB,IAAI,iBAAiB,SAAS,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"filterRichTextField.cjs","names":["LinkType","RichTextNodeType"],"sources":["../../src/lib/filterRichTextField.ts"],"sourcesContent":["import type {\n\tCustomTypeModelRichTextField,\n\tRTImageNode,\n\tRTNode,\n\tRTTextNode,\n\tRichTextField,\n\tRichTextNodeTypes,\n\tTitleField,\n} from \"@prismicio/client\"\nimport { LinkType, RichTextNodeType } from \"@prismicio/client\"\n\n/**\n * Get allowed nodes types from a rich text or title field custom type model.\n *\n * @param model - A rich text or title field custom type model.\n * @returns An array of allowed nodes types.\n */\nconst getAllowedNodeTypes = (model: CustomTypeModelRichTextField): RichTextNodeTypes[] => {\n\tconst allowedNodeTypes: RichTextNodeTypes[] = [] // An empty array means no nodes are allowed by default.\n\n\tif (model.config) {\n\t\tif (\"multi\" in model.config && model.config.multi) {\n\t\t\tallowedNodeTypes.push(...(model.config.multi.split(\",\") as RichTextNodeTypes[]))\n\t\t} else if (\"single\" in model.config && model.config.single) {\n\t\t\tallowedNodeTypes.push(...(model.config.single.split(\",\") as RichTextNodeTypes[]))\n\t\t}\n\n\t\tif (model.config.labels?.length) {\n\t\t\tallowedNodeTypes.push(\"label\")\n\t\t}\n\t}\n\n\treturn allowedNodeTypes\n}\n\n/**\n * Filter an image node based on given model.\n *\n * @param node - An image node to filter.\n * @param model - A rich text or title field custom type model.\n * @returns A filtered image node based on the given model.\n */\nconst filterImageNode = (node: RTImageNode, model: CustomTypeModelRichTextField): RTImageNode => {\n\tif (!model.config?.allowTargetBlank && node.linkTo?.link_type === LinkType.Web) {\n\t\treturn {\n\t\t\t...node,\n\t\t\tlinkTo: {\n\t\t\t\t...node.linkTo,\n\t\t\t\ttarget: undefined,\n\t\t\t},\n\t\t}\n\t}\n\n\treturn node\n}\n\n/**\n * Filter a text node based on given model.\n *\n * @param node - A text node to filter.\n * @param model - A rich text or title field custom type model.\n * @param allowedNodeTypes - An array of allowed nodes types.\n * @returns A filtered text node based on the given model.\n */\nconst filterTextNode = (\n\tnode: RTTextNode,\n\tmodel: CustomTypeModelRichTextField,\n\tallowedNodeTypes: RichTextNodeTypes[],\n): RTTextNode => {\n\tconst filteredNode: RTTextNode = {\n\t\t...node,\n\t\tspans: [],\n\t}\n\n\tfor (let i = 0; i < node.spans.length; i++) {\n\t\tconst span = node.spans[i]\n\n\t\tif (allowedNodeTypes.includes(span.type)) {\n\t\t\tif (span.type === RichTextNodeType.hyperlink) {\n\t\t\t\tif (!model.config?.allowTargetBlank && span.data.link_type === LinkType.Web) {\n\t\t\t\t\tfilteredNode.spans.push({\n\t\t\t\t\t\t...span,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t...span.data,\n\t\t\t\t\t\t\ttarget: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else if (span.type === RichTextNodeType.label) {\n\t\t\t\tif (model.config?.labels?.includes(span.data.label)) {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn filteredNode\n}\n\n/**\n * Filter a rich text field based on given model.\n *\n * @param richTextField - A rich text or title field from Prismic.\n * @param model - A rich text or title field custom type model.\n * @returns A rich text or title field filtered based on the given model.\n */\nexport const filterRichTextField = <Field extends RichTextField | TitleField>(\n\trichTextField: Field,\n\tmodel: CustomTypeModelRichTextField,\n): Field => {\n\tconst nodes: RTNode[] = []\n\n\tconst allowedNodeTypes = getAllowedNodeTypes(model)\n\n\tfor (\n\t\tlet i = 0;\n\t\t// Only process the first node if it's a \"single\" node rich text type\n\t\ti < (model.config && \"multi\" in model.config ? richTextField.length : 1);\n\t\ti++\n\t) {\n\t\tconst node = richTextField[i]\n\n\t\tif (allowedNodeTypes.includes(node.type)) {\n\t\t\tif (node.type === RichTextNodeType.image) {\n\t\t\t\tnodes.push(filterImageNode(node, model))\n\t\t\t} else if (node.type === RichTextNodeType.embed) {\n\t\t\t\tnodes.push(node)\n\t\t\t} else {\n\t\t\t\tnodes.push(filterTextNode(node, model, allowedNodeTypes))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nodes as Field\n}\n"],"mappings":";;;;;;;;AAiBA,MAAM,uBAAuB,UAA6D;CACzF,MAAM,mBAAwC,CAAC;CAE/C,IAAI,MAAM,QAAQ;EACjB,IAAI,WAAW,MAAM,UAAU,MAAM,OAAO,OAC3C,iBAAiB,KAAK,GAAI,MAAM,OAAO,MAAM,MAAM,GAAG,CAAyB;OACzE,IAAI,YAAY,MAAM,UAAU,MAAM,OAAO,QACnD,iBAAiB,KAAK,GAAI,MAAM,OAAO,OAAO,MAAM,GAAG,CAAyB;EAGjF,IAAI,MAAM,OAAO,QAAQ,QACxB,iBAAiB,KAAK,OAAO;CAE/B;CAEA,OAAO;AACR;;;;;;;;AASA,MAAM,mBAAmB,MAAmB,UAAqD;CAChG,IAAI,CAAC,MAAM,QAAQ,oBAAoB,KAAK,QAAQ,cAAcA,kBAAAA,SAAS,KAC1E,OAAO;EACN,GAAG;EACH,QAAQ;GACP,GAAG,KAAK;GACR,QAAQ,KAAA;EACT;CACD;CAGD,OAAO;AACR;;;;;;;;;AAUA,MAAM,kBACL,MACA,OACA,qBACgB;CAChB,MAAM,eAA2B;EAChC,GAAG;EACH,OAAO,CAAC;CACT;CAEA,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,MAAM,QAAQ,KAAK;EAC3C,MAAM,OAAO,KAAK,MAAM;EAExB,IAAI,iBAAiB,SAAS,KAAK,IAAI,GAAG;GACzC,IAAI,KAAK,SAASC,kBAAAA,iBAAiB,WAAW;IAC7C,IAAI,CAAC,MAAM,QAAQ,oBAAoB,KAAK,KAAK,cAAcD,kBAAAA,SAAS,KACvE,aAAa,MAAM,KAAK;KACvB,GAAG;KACH,MAAM;MACL,GAAG,KAAK;MACR,QAAQ,KAAA;KACT;IACD,CAAC;SAED,aAAa,MAAM,KAAK,IAAI;GAE9B,OAAO,IAAI,KAAK,SAASC,kBAAAA,iBAAiB,OACrC;QAAA,MAAM,QAAQ,QAAQ,SAAS,KAAK,KAAK,KAAK,GACjD,aAAa,MAAM,KAAK,IAAI;GAAA,OAG7B,aAAa,MAAM,KAAK,IAAI;EAE9B;CACD;CAEA,OAAO;AACR;;;;;;;;AASA,MAAa,uBACZ,eACA,UACW;CACX,MAAM,QAAkB,CAAC;CAEzB,MAAM,mBAAmB,oBAAoB,KAAK;CAElD,KACC,IAAI,IAAI,GAER,KAAK,MAAM,UAAU,WAAW,MAAM,SAAS,cAAc,SAAS,IACtE,KACC;EACD,MAAM,OAAO,cAAc;EAE3B,IAAI,iBAAiB,SAAS,KAAK,IAAI,GAAG;GACzC,IAAI,KAAK,SAASA,kBAAAA,iBAAiB,OAClC,MAAM,KAAK,gBAAgB,MAAM,KAAK,CAAC;QACjC,IAAI,KAAK,SAASA,kBAAAA,iBAAiB,OACzC,MAAM,KAAK,IAAI;QAEf,MAAM,KAAK,eAAe,MAAM,OAAO,gBAAgB,CAAC;EAE1D;CACD;CAEA,OAAO;AACR"}
|
|
@@ -47,17 +47,20 @@ const filterTextNode = (node, model, allowedNodeTypes) => {
|
|
|
47
47
|
};
|
|
48
48
|
for (let i = 0; i < node.spans.length; i++) {
|
|
49
49
|
const span = node.spans[i];
|
|
50
|
-
if (allowedNodeTypes.includes(span.type))
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
if (allowedNodeTypes.includes(span.type)) {
|
|
51
|
+
if (span.type === RichTextNodeType.hyperlink) {
|
|
52
|
+
if (!model.config?.allowTargetBlank && span.data.link_type === LinkType.Web) filteredNode.spans.push({
|
|
53
|
+
...span,
|
|
54
|
+
data: {
|
|
55
|
+
...span.data,
|
|
56
|
+
target: void 0
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
else filteredNode.spans.push(span);
|
|
60
|
+
} else if (span.type === RichTextNodeType.label) {
|
|
61
|
+
if (model.config?.labels?.includes(span.data.label)) filteredNode.spans.push(span);
|
|
62
|
+
} else filteredNode.spans.push(span);
|
|
63
|
+
}
|
|
61
64
|
}
|
|
62
65
|
return filteredNode;
|
|
63
66
|
};
|
|
@@ -73,9 +76,11 @@ const filterRichTextField = (richTextField, model) => {
|
|
|
73
76
|
const allowedNodeTypes = getAllowedNodeTypes(model);
|
|
74
77
|
for (let i = 0; i < (model.config && "multi" in model.config ? richTextField.length : 1); i++) {
|
|
75
78
|
const node = richTextField[i];
|
|
76
|
-
if (allowedNodeTypes.includes(node.type))
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
if (allowedNodeTypes.includes(node.type)) {
|
|
80
|
+
if (node.type === RichTextNodeType.image) nodes.push(filterImageNode(node, model));
|
|
81
|
+
else if (node.type === RichTextNodeType.embed) nodes.push(node);
|
|
82
|
+
else nodes.push(filterTextNode(node, model, allowedNodeTypes));
|
|
83
|
+
}
|
|
79
84
|
}
|
|
80
85
|
return nodes;
|
|
81
86
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterRichTextField.js","names":[],"sources":["../../src/lib/filterRichTextField.ts"],"sourcesContent":["import type {\n\tCustomTypeModelRichTextField,\n\tRTImageNode,\n\tRTNode,\n\tRTTextNode,\n\tRichTextField,\n\tRichTextNodeTypes,\n\tTitleField,\n} from \"@prismicio/client\"\nimport { LinkType, RichTextNodeType } from \"@prismicio/client\"\n\n/**\n * Get allowed nodes types from a rich text or title field custom type model.\n *\n * @param model - A rich text or title field custom type model.\n * @returns An array of allowed nodes types.\n */\nconst getAllowedNodeTypes = (model: CustomTypeModelRichTextField): RichTextNodeTypes[] => {\n\tconst allowedNodeTypes: RichTextNodeTypes[] = [] // An empty array means no nodes are allowed by default.\n\n\tif (model.config) {\n\t\tif (\"multi\" in model.config && model.config.multi) {\n\t\t\tallowedNodeTypes.push(...(model.config.multi.split(\",\") as RichTextNodeTypes[]))\n\t\t} else if (\"single\" in model.config && model.config.single) {\n\t\t\tallowedNodeTypes.push(...(model.config.single.split(\",\") as RichTextNodeTypes[]))\n\t\t}\n\n\t\tif (model.config.labels?.length) {\n\t\t\tallowedNodeTypes.push(\"label\")\n\t\t}\n\t}\n\n\treturn allowedNodeTypes\n}\n\n/**\n * Filter an image node based on given model.\n *\n * @param node - An image node to filter.\n * @param model - A rich text or title field custom type model.\n * @returns A filtered image node based on the given model.\n */\nconst filterImageNode = (node: RTImageNode, model: CustomTypeModelRichTextField): RTImageNode => {\n\tif (!model.config?.allowTargetBlank && node.linkTo?.link_type === LinkType.Web) {\n\t\treturn {\n\t\t\t...node,\n\t\t\tlinkTo: {\n\t\t\t\t...node.linkTo,\n\t\t\t\ttarget: undefined,\n\t\t\t},\n\t\t}\n\t}\n\n\treturn node\n}\n\n/**\n * Filter a text node based on given model.\n *\n * @param node - A text node to filter.\n * @param model - A rich text or title field custom type model.\n * @param allowedNodeTypes - An array of allowed nodes types.\n * @returns A filtered text node based on the given model.\n */\nconst filterTextNode = (\n\tnode: RTTextNode,\n\tmodel: CustomTypeModelRichTextField,\n\tallowedNodeTypes: RichTextNodeTypes[],\n): RTTextNode => {\n\tconst filteredNode: RTTextNode = {\n\t\t...node,\n\t\tspans: [],\n\t}\n\n\tfor (let i = 0; i < node.spans.length; i++) {\n\t\tconst span = node.spans[i]\n\n\t\tif (allowedNodeTypes.includes(span.type)) {\n\t\t\tif (span.type === RichTextNodeType.hyperlink) {\n\t\t\t\tif (!model.config?.allowTargetBlank && span.data.link_type === LinkType.Web) {\n\t\t\t\t\tfilteredNode.spans.push({\n\t\t\t\t\t\t...span,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t...span.data,\n\t\t\t\t\t\t\ttarget: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else if (span.type === RichTextNodeType.label) {\n\t\t\t\tif (model.config?.labels?.includes(span.data.label)) {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn filteredNode\n}\n\n/**\n * Filter a rich text field based on given model.\n *\n * @param richTextField - A rich text or title field from Prismic.\n * @param model - A rich text or title field custom type model.\n * @returns A rich text or title field filtered based on the given model.\n */\nexport const filterRichTextField = <Field extends RichTextField | TitleField>(\n\trichTextField: Field,\n\tmodel: CustomTypeModelRichTextField,\n): Field => {\n\tconst nodes: RTNode[] = []\n\n\tconst allowedNodeTypes = getAllowedNodeTypes(model)\n\n\tfor (\n\t\tlet i = 0;\n\t\t// Only process the first node if it's a \"single\" node rich text type\n\t\ti < (model.config && \"multi\" in model.config ? richTextField.length : 1);\n\t\ti++\n\t) {\n\t\tconst node = richTextField[i]\n\n\t\tif (allowedNodeTypes.includes(node.type)) {\n\t\t\tif (node.type === RichTextNodeType.image) {\n\t\t\t\tnodes.push(filterImageNode(node, model))\n\t\t\t} else if (node.type === RichTextNodeType.embed) {\n\t\t\t\tnodes.push(node)\n\t\t\t} else {\n\t\t\t\tnodes.push(filterTextNode(node, model, allowedNodeTypes))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nodes as Field\n}\n"],"mappings":";;;;;;;;AAiBA,MAAM,uBAAuB,UAA6D;CACzF,MAAM,mBAAwC,CAAC;CAE/C,IAAI,MAAM,QAAQ;EACjB,IAAI,WAAW,MAAM,UAAU,MAAM,OAAO,OAC3C,iBAAiB,KAAK,GAAI,MAAM,OAAO,MAAM,MAAM,GAAG,CAAyB;OACzE,IAAI,YAAY,MAAM,UAAU,MAAM,OAAO,QACnD,iBAAiB,KAAK,GAAI,MAAM,OAAO,OAAO,MAAM,GAAG,CAAyB;EAGjF,IAAI,MAAM,OAAO,QAAQ,QACxB,iBAAiB,KAAK,OAAO;CAE/B;CAEA,OAAO;AACR;;;;;;;;AASA,MAAM,mBAAmB,MAAmB,UAAqD;CAChG,IAAI,CAAC,MAAM,QAAQ,oBAAoB,KAAK,QAAQ,cAAc,SAAS,KAC1E,OAAO;EACN,GAAG;EACH,QAAQ;GACP,GAAG,KAAK;GACR,QAAQ,KAAA;EACT;CACD;CAGD,OAAO;AACR;;;;;;;;;AAUA,MAAM,kBACL,MACA,OACA,qBACgB;CAChB,MAAM,eAA2B;EAChC,GAAG;EACH,OAAO,CAAC;CACT;CAEA,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,MAAM,QAAQ,KAAK;EAC3C,MAAM,OAAO,KAAK,MAAM;EAExB,IAAI,iBAAiB,SAAS,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"filterRichTextField.js","names":[],"sources":["../../src/lib/filterRichTextField.ts"],"sourcesContent":["import type {\n\tCustomTypeModelRichTextField,\n\tRTImageNode,\n\tRTNode,\n\tRTTextNode,\n\tRichTextField,\n\tRichTextNodeTypes,\n\tTitleField,\n} from \"@prismicio/client\"\nimport { LinkType, RichTextNodeType } from \"@prismicio/client\"\n\n/**\n * Get allowed nodes types from a rich text or title field custom type model.\n *\n * @param model - A rich text or title field custom type model.\n * @returns An array of allowed nodes types.\n */\nconst getAllowedNodeTypes = (model: CustomTypeModelRichTextField): RichTextNodeTypes[] => {\n\tconst allowedNodeTypes: RichTextNodeTypes[] = [] // An empty array means no nodes are allowed by default.\n\n\tif (model.config) {\n\t\tif (\"multi\" in model.config && model.config.multi) {\n\t\t\tallowedNodeTypes.push(...(model.config.multi.split(\",\") as RichTextNodeTypes[]))\n\t\t} else if (\"single\" in model.config && model.config.single) {\n\t\t\tallowedNodeTypes.push(...(model.config.single.split(\",\") as RichTextNodeTypes[]))\n\t\t}\n\n\t\tif (model.config.labels?.length) {\n\t\t\tallowedNodeTypes.push(\"label\")\n\t\t}\n\t}\n\n\treturn allowedNodeTypes\n}\n\n/**\n * Filter an image node based on given model.\n *\n * @param node - An image node to filter.\n * @param model - A rich text or title field custom type model.\n * @returns A filtered image node based on the given model.\n */\nconst filterImageNode = (node: RTImageNode, model: CustomTypeModelRichTextField): RTImageNode => {\n\tif (!model.config?.allowTargetBlank && node.linkTo?.link_type === LinkType.Web) {\n\t\treturn {\n\t\t\t...node,\n\t\t\tlinkTo: {\n\t\t\t\t...node.linkTo,\n\t\t\t\ttarget: undefined,\n\t\t\t},\n\t\t}\n\t}\n\n\treturn node\n}\n\n/**\n * Filter a text node based on given model.\n *\n * @param node - A text node to filter.\n * @param model - A rich text or title field custom type model.\n * @param allowedNodeTypes - An array of allowed nodes types.\n * @returns A filtered text node based on the given model.\n */\nconst filterTextNode = (\n\tnode: RTTextNode,\n\tmodel: CustomTypeModelRichTextField,\n\tallowedNodeTypes: RichTextNodeTypes[],\n): RTTextNode => {\n\tconst filteredNode: RTTextNode = {\n\t\t...node,\n\t\tspans: [],\n\t}\n\n\tfor (let i = 0; i < node.spans.length; i++) {\n\t\tconst span = node.spans[i]\n\n\t\tif (allowedNodeTypes.includes(span.type)) {\n\t\t\tif (span.type === RichTextNodeType.hyperlink) {\n\t\t\t\tif (!model.config?.allowTargetBlank && span.data.link_type === LinkType.Web) {\n\t\t\t\t\tfilteredNode.spans.push({\n\t\t\t\t\t\t...span,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t...span.data,\n\t\t\t\t\t\t\ttarget: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else if (span.type === RichTextNodeType.label) {\n\t\t\t\tif (model.config?.labels?.includes(span.data.label)) {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn filteredNode\n}\n\n/**\n * Filter a rich text field based on given model.\n *\n * @param richTextField - A rich text or title field from Prismic.\n * @param model - A rich text or title field custom type model.\n * @returns A rich text or title field filtered based on the given model.\n */\nexport const filterRichTextField = <Field extends RichTextField | TitleField>(\n\trichTextField: Field,\n\tmodel: CustomTypeModelRichTextField,\n): Field => {\n\tconst nodes: RTNode[] = []\n\n\tconst allowedNodeTypes = getAllowedNodeTypes(model)\n\n\tfor (\n\t\tlet i = 0;\n\t\t// Only process the first node if it's a \"single\" node rich text type\n\t\ti < (model.config && \"multi\" in model.config ? richTextField.length : 1);\n\t\ti++\n\t) {\n\t\tconst node = richTextField[i]\n\n\t\tif (allowedNodeTypes.includes(node.type)) {\n\t\t\tif (node.type === RichTextNodeType.image) {\n\t\t\t\tnodes.push(filterImageNode(node, model))\n\t\t\t} else if (node.type === RichTextNodeType.embed) {\n\t\t\t\tnodes.push(node)\n\t\t\t} else {\n\t\t\t\tnodes.push(filterTextNode(node, model, allowedNodeTypes))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nodes as Field\n}\n"],"mappings":";;;;;;;;AAiBA,MAAM,uBAAuB,UAA6D;CACzF,MAAM,mBAAwC,CAAC;CAE/C,IAAI,MAAM,QAAQ;EACjB,IAAI,WAAW,MAAM,UAAU,MAAM,OAAO,OAC3C,iBAAiB,KAAK,GAAI,MAAM,OAAO,MAAM,MAAM,GAAG,CAAyB;OACzE,IAAI,YAAY,MAAM,UAAU,MAAM,OAAO,QACnD,iBAAiB,KAAK,GAAI,MAAM,OAAO,OAAO,MAAM,GAAG,CAAyB;EAGjF,IAAI,MAAM,OAAO,QAAQ,QACxB,iBAAiB,KAAK,OAAO;CAE/B;CAEA,OAAO;AACR;;;;;;;;AASA,MAAM,mBAAmB,MAAmB,UAAqD;CAChG,IAAI,CAAC,MAAM,QAAQ,oBAAoB,KAAK,QAAQ,cAAc,SAAS,KAC1E,OAAO;EACN,GAAG;EACH,QAAQ;GACP,GAAG,KAAK;GACR,QAAQ,KAAA;EACT;CACD;CAGD,OAAO;AACR;;;;;;;;;AAUA,MAAM,kBACL,MACA,OACA,qBACgB;CAChB,MAAM,eAA2B;EAChC,GAAG;EACH,OAAO,CAAC;CACT;CAEA,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,MAAM,QAAQ,KAAK;EAC3C,MAAM,OAAO,KAAK,MAAM;EAExB,IAAI,iBAAiB,SAAS,KAAK,IAAI,GAAG;GACzC,IAAI,KAAK,SAAS,iBAAiB,WAAW;IAC7C,IAAI,CAAC,MAAM,QAAQ,oBAAoB,KAAK,KAAK,cAAc,SAAS,KACvE,aAAa,MAAM,KAAK;KACvB,GAAG;KACH,MAAM;MACL,GAAG,KAAK;MACR,QAAQ,KAAA;KACT;IACD,CAAC;SAED,aAAa,MAAM,KAAK,IAAI;GAE9B,OAAO,IAAI,KAAK,SAAS,iBAAiB,OACrC;QAAA,MAAM,QAAQ,QAAQ,SAAS,KAAK,KAAK,KAAK,GACjD,aAAa,MAAM,KAAK,IAAI;GAAA,OAG7B,aAAa,MAAM,KAAK,IAAI;EAE9B;CACD;CAEA,OAAO;AACR;;;;;;;;AASA,MAAa,uBACZ,eACA,UACW;CACX,MAAM,QAAkB,CAAC;CAEzB,MAAM,mBAAmB,oBAAoB,KAAK;CAElD,KACC,IAAI,IAAI,GAER,KAAK,MAAM,UAAU,WAAW,MAAM,SAAS,cAAc,SAAS,IACtE,KACC;EACD,MAAM,OAAO,cAAc;EAE3B,IAAI,iBAAiB,SAAS,KAAK,IAAI,GAAG;GACzC,IAAI,KAAK,SAAS,iBAAiB,OAClC,MAAM,KAAK,gBAAgB,MAAM,KAAK,CAAC;QACjC,IAAI,KAAK,SAAS,iBAAiB,OACzC,MAAM,KAAK,IAAI;QAEf,MAAM,KAAK,eAAe,MAAM,OAAO,gBAAgB,CAAC;EAE1D;CACD;CAEA,OAAO;AACR"}
|
|
@@ -4,7 +4,7 @@ import { Element } from "hast";
|
|
|
4
4
|
import "vfile";
|
|
5
5
|
//#region src/lib/hastToRichText.d.ts
|
|
6
6
|
/** Configuration that determines the output of `toRichText`. */
|
|
7
|
-
type HASTToRichTextConfig = {
|
|
7
|
+
export type HASTToRichTextConfig = {
|
|
8
8
|
/**
|
|
9
9
|
* An optional HTML to rich text serializer. Will be merged with the default HTML to rich text
|
|
10
10
|
* serializer.
|
|
@@ -18,5 +18,4 @@ type HASTToRichTextConfig = {
|
|
|
18
18
|
direction?: "ltr" | "rtl";
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
|
-
export { HASTToRichTextConfig };
|
|
22
21
|
//# sourceMappingURL=hastToRichText.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hastToRichText.d.cts","names":[],"sources":["../../src/lib/hastToRichText.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"hastToRichText.d.cts","names":[],"sources":["../../src/lib/hastToRichText.ts"],"mappings":";;;;;;YAwDY;;;;;EAKX,aAAa;;;;;;EAOb"}
|
|
@@ -4,7 +4,7 @@ import { Element } from "hast";
|
|
|
4
4
|
import "vfile";
|
|
5
5
|
//#region src/lib/hastToRichText.d.ts
|
|
6
6
|
/** Configuration that determines the output of `toRichText`. */
|
|
7
|
-
type HASTToRichTextConfig = {
|
|
7
|
+
export type HASTToRichTextConfig = {
|
|
8
8
|
/**
|
|
9
9
|
* An optional HTML to rich text serializer. Will be merged with the default HTML to rich text
|
|
10
10
|
* serializer.
|
|
@@ -18,5 +18,4 @@ type HASTToRichTextConfig = {
|
|
|
18
18
|
direction?: "ltr" | "rtl";
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
|
-
export { HASTToRichTextConfig };
|
|
22
21
|
//# sourceMappingURL=hastToRichText.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hastToRichText.d.ts","names":[],"sources":["../../src/lib/hastToRichText.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"hastToRichText.d.ts","names":[],"sources":["../../src/lib/hastToRichText.ts"],"mappings":";;;;;;YAwDY;;;;;EAKX,aAAa;;;;;;EAOb"}
|
|
@@ -4,7 +4,7 @@ import "hast";
|
|
|
4
4
|
import "unified";
|
|
5
5
|
//#region src/lib/rehypeRichText.d.ts
|
|
6
6
|
/** Configuration options for {@link rehypeRichText}. */
|
|
7
|
-
type RehypeRichTextConfig = {
|
|
7
|
+
export type RehypeRichTextConfig = {
|
|
8
8
|
/**
|
|
9
9
|
* A CSS selector that targets the section of the document to convert to rich text.
|
|
10
10
|
*
|
|
@@ -55,5 +55,4 @@ declare module "hast" {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
|
-
export { RehypeRichTextConfig };
|
|
59
58
|
//# sourceMappingURL=rehypeRichText.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehypeRichText.d.cts","names":[],"sources":["../../src/lib/rehypeRichText.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"rehypeRichText.d.cts","names":[],"sources":["../../src/lib/rehypeRichText.ts"],"mappings":";;;;;;YAcY;;;;;;;;;EASX;;;;;;;;;EAUA;;;;;;;;;EAUA;;;;;;;EAQA,QAAQ;IACL;;YAwGO;IACT,eAAe;;;;YAMN;;;;;IAKT"}
|
|
@@ -4,7 +4,7 @@ import { CustomTypeModelRichTextField, RichTextField } from "@prismicio/client";
|
|
|
4
4
|
import "hast";
|
|
5
5
|
//#region src/lib/rehypeRichText.d.ts
|
|
6
6
|
/** Configuration options for {@link rehypeRichText}. */
|
|
7
|
-
type RehypeRichTextConfig = {
|
|
7
|
+
export type RehypeRichTextConfig = {
|
|
8
8
|
/**
|
|
9
9
|
* A CSS selector that targets the section of the document to convert to rich text.
|
|
10
10
|
*
|
|
@@ -55,5 +55,4 @@ declare module "hast" {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
|
-
export { RehypeRichTextConfig };
|
|
59
58
|
//# sourceMappingURL=rehypeRichText.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehypeRichText.d.ts","names":[],"sources":["../../src/lib/rehypeRichText.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"rehypeRichText.d.ts","names":[],"sources":["../../src/lib/rehypeRichText.ts"],"mappings":";;;;;;YAcY;;;;;;;;;EASX;;;;;;;;;EAUA;;;;;;;;;EAUA;;;;;;;EAQA,QAAQ;IACL;;YAwGO;IACT,eAAe;;;;YAMN;;;;;IAKT"}
|
package/dist/types.d.cts
CHANGED
|
@@ -12,7 +12,7 @@ import { Element } from "hast";
|
|
|
12
12
|
* The `span` rich text node type is not available as it is not relevant in the context of going
|
|
13
13
|
* from HTML to Prismic rich text.
|
|
14
14
|
*/
|
|
15
|
-
type RichTextHTMLMapSerializerShorthand = Exclude<RichTextNodeTypes, "label" | "span"> | {
|
|
15
|
+
export type RichTextHTMLMapSerializerShorthand = Exclude<RichTextNodeTypes, "label" | "span"> | {
|
|
16
16
|
label: string;
|
|
17
17
|
};
|
|
18
18
|
/** The payload provided to a {@link RichTextHTMLMapSerializerFunction}. */
|
|
@@ -33,7 +33,7 @@ type RichTextHTMLMapSerializerFunctionPayload = {
|
|
|
33
33
|
* Serializing to a rich text node directly is not recommended and is only available as an escape
|
|
34
34
|
* hatch. Prefer returning a {@link RichTextHTMLMapSerializerShorthand} instead.
|
|
35
35
|
*/
|
|
36
|
-
type RichTextHTMLMapSerializerFunction = (payload: RichTextHTMLMapSerializerFunctionPayload) => RichTextHTMLMapSerializerShorthand | InjectMigrationSpecificTypes<RTNode | RTInlineNode | RTPartialInlineNode> | undefined;
|
|
36
|
+
export type RichTextHTMLMapSerializerFunction = (payload: RichTextHTMLMapSerializerFunctionPayload) => RichTextHTMLMapSerializerShorthand | InjectMigrationSpecificTypes<RTNode | RTInlineNode | RTPartialInlineNode> | undefined;
|
|
37
37
|
/**
|
|
38
38
|
* Serializes a hast {@link Element} node matching the given HTML tag name or CSS selector to a
|
|
39
39
|
* Prismic rich text node.
|
|
@@ -42,7 +42,6 @@ type RichTextHTMLMapSerializerFunction = (payload: RichTextHTMLMapSerializerFunc
|
|
|
42
42
|
* This serializer is used to serialize HTML to Prismic rich text. When serializing Prismic rich
|
|
43
43
|
* text to HTML with {@link asHTML}, use the {@link HTMLRichTextMapSerializer} type instead.
|
|
44
44
|
*/
|
|
45
|
-
type RichTextHTMLMapSerializer = Record<string, RichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction>;
|
|
45
|
+
export type RichTextHTMLMapSerializer = Record<string, RichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction>;
|
|
46
46
|
//#endregion
|
|
47
|
-
export { RichTextHTMLMapSerializer, RichTextHTMLMapSerializerFunction, RichTextHTMLMapSerializerShorthand };
|
|
48
47
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;;;;;YAoBY,qCACT,QAAQ;EACN;;;KAGA;;EAEJ,MAAM;;EAGN;;IAEC;;;;;;;;;;;YAYU,qCACX,SAAS,6CAEP,qCACA,6BAA6B,SAAS,eAAe;;;;;;;;;YAW5C,4BAA4B,eAEvC,qCAAqC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { Element } from "hast";
|
|
|
12
12
|
* The `span` rich text node type is not available as it is not relevant in the context of going
|
|
13
13
|
* from HTML to Prismic rich text.
|
|
14
14
|
*/
|
|
15
|
-
type RichTextHTMLMapSerializerShorthand = Exclude<RichTextNodeTypes, "label" | "span"> | {
|
|
15
|
+
export type RichTextHTMLMapSerializerShorthand = Exclude<RichTextNodeTypes, "label" | "span"> | {
|
|
16
16
|
label: string;
|
|
17
17
|
};
|
|
18
18
|
/** The payload provided to a {@link RichTextHTMLMapSerializerFunction}. */
|
|
@@ -33,7 +33,7 @@ type RichTextHTMLMapSerializerFunctionPayload = {
|
|
|
33
33
|
* Serializing to a rich text node directly is not recommended and is only available as an escape
|
|
34
34
|
* hatch. Prefer returning a {@link RichTextHTMLMapSerializerShorthand} instead.
|
|
35
35
|
*/
|
|
36
|
-
type RichTextHTMLMapSerializerFunction = (payload: RichTextHTMLMapSerializerFunctionPayload) => RichTextHTMLMapSerializerShorthand | InjectMigrationSpecificTypes<RTNode | RTInlineNode | RTPartialInlineNode> | undefined;
|
|
36
|
+
export type RichTextHTMLMapSerializerFunction = (payload: RichTextHTMLMapSerializerFunctionPayload) => RichTextHTMLMapSerializerShorthand | InjectMigrationSpecificTypes<RTNode | RTInlineNode | RTPartialInlineNode> | undefined;
|
|
37
37
|
/**
|
|
38
38
|
* Serializes a hast {@link Element} node matching the given HTML tag name or CSS selector to a
|
|
39
39
|
* Prismic rich text node.
|
|
@@ -42,7 +42,6 @@ type RichTextHTMLMapSerializerFunction = (payload: RichTextHTMLMapSerializerFunc
|
|
|
42
42
|
* This serializer is used to serialize HTML to Prismic rich text. When serializing Prismic rich
|
|
43
43
|
* text to HTML with {@link asHTML}, use the {@link HTMLRichTextMapSerializer} type instead.
|
|
44
44
|
*/
|
|
45
|
-
type RichTextHTMLMapSerializer = Record<string, RichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction>;
|
|
45
|
+
export type RichTextHTMLMapSerializer = Record<string, RichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction>;
|
|
46
46
|
//#endregion
|
|
47
|
-
export { RichTextHTMLMapSerializer, RichTextHTMLMapSerializerFunction, RichTextHTMLMapSerializerShorthand };
|
|
48
47
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;;;;;YAoBY,qCACT,QAAQ;EACN;;;KAGA;;EAEJ,MAAM;;EAGN;;IAEC;;;;;;;;;;;YAYU,qCACX,SAAS,6CAEP,qCACA,6BAA6B,SAAS,eAAe;;;;;;;;;YAW5C,4BAA4B,eAEvC,qCAAqC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/migrate",
|
|
3
|
-
"version": "0.0.2-canary.
|
|
3
|
+
"version": "0.0.2-canary.9aa3ce7",
|
|
4
4
|
"description": "Set of helpers to migrate your data to Prismic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"prismic",
|
|
@@ -54,19 +54,19 @@
|
|
|
54
54
|
"vfile": "^6.0.3"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@prismicio/client": "^7.
|
|
58
|
-
"@types/node": "^26.
|
|
59
|
-
"@vitest/coverage-v8": "^
|
|
60
|
-
"oxfmt": "^0.
|
|
61
|
-
"oxlint": "^1.
|
|
62
|
-
"tsdown": "^0.
|
|
57
|
+
"@prismicio/client": "^7.22.3",
|
|
58
|
+
"@types/node": "^26.6.5",
|
|
59
|
+
"@vitest/coverage-v8": "^5.0.3",
|
|
60
|
+
"oxfmt": "^0.72.0",
|
|
61
|
+
"oxlint": "^1.87.0",
|
|
62
|
+
"tsdown": "^0.23.0",
|
|
63
63
|
"typescript": "^7.0.2",
|
|
64
|
-
"vitest": "^
|
|
64
|
+
"vitest": "^5.0.3"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"@prismicio/client": "^7.21.8"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
|
-
"node": ">=
|
|
70
|
+
"node": ">=22"
|
|
71
71
|
}
|
|
72
72
|
}
|