@prismicio/migrate 0.0.2-canary.6b4d958 → 0.0.2-canary.701c2e5

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.
Files changed (67) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +2 -3
  2. package/dist/errors/PrismicRichTextError.cjs +1 -2
  3. package/dist/errors/PrismicRichTextError.cjs.map +1 -1
  4. package/dist/errors/PrismicRichTextError.d.cts +1 -4
  5. package/dist/errors/PrismicRichTextError.d.cts.map +1 -1
  6. package/dist/errors/PrismicRichTextError.d.ts +1 -4
  7. package/dist/errors/PrismicRichTextError.d.ts.map +1 -1
  8. package/dist/errors/PrismicRichTextError.js +1 -2
  9. package/dist/errors/PrismicRichTextError.js.map +1 -1
  10. package/dist/errors/PrismicRichTextSerializerError.cjs +1 -2
  11. package/dist/errors/PrismicRichTextSerializerError.cjs.map +1 -1
  12. package/dist/errors/PrismicRichTextSerializerError.d.cts +1 -5
  13. package/dist/errors/PrismicRichTextSerializerError.d.cts.map +1 -1
  14. package/dist/errors/PrismicRichTextSerializerError.d.ts +1 -5
  15. package/dist/errors/PrismicRichTextSerializerError.d.ts.map +1 -1
  16. package/dist/errors/PrismicRichTextSerializerError.js +1 -2
  17. package/dist/errors/PrismicRichTextSerializerError.js.map +1 -1
  18. package/dist/htmlAsRichText.cjs +1 -2
  19. package/dist/htmlAsRichText.cjs.map +1 -1
  20. package/dist/htmlAsRichText.d.cts +5 -8
  21. package/dist/htmlAsRichText.d.cts.map +1 -1
  22. package/dist/htmlAsRichText.d.ts +6 -8
  23. package/dist/htmlAsRichText.d.ts.map +1 -1
  24. package/dist/htmlAsRichText.js +1 -2
  25. package/dist/htmlAsRichText.js.map +1 -1
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.d.cts +1 -1
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/lib/RichTextFieldBuilder.cjs +1 -2
  31. package/dist/lib/RichTextFieldBuilder.cjs.map +1 -1
  32. package/dist/lib/RichTextFieldBuilder.d.cts +3 -6
  33. package/dist/lib/RichTextFieldBuilder.d.cts.map +1 -1
  34. package/dist/lib/RichTextFieldBuilder.d.ts +3 -6
  35. package/dist/lib/RichTextFieldBuilder.d.ts.map +1 -1
  36. package/dist/lib/RichTextFieldBuilder.js +1 -2
  37. package/dist/lib/RichTextFieldBuilder.js.map +1 -1
  38. package/dist/lib/filterRichTextField.cjs +20 -17
  39. package/dist/lib/filterRichTextField.cjs.map +1 -1
  40. package/dist/lib/filterRichTextField.js +20 -16
  41. package/dist/lib/filterRichTextField.js.map +1 -1
  42. package/dist/lib/hastSerializerHelpers.cjs +1 -3
  43. package/dist/lib/hastSerializerHelpers.cjs.map +1 -1
  44. package/dist/lib/hastSerializerHelpers.js +1 -2
  45. package/dist/lib/hastSerializerHelpers.js.map +1 -1
  46. package/dist/lib/hastToRichText.cjs +1 -3
  47. package/dist/lib/hastToRichText.cjs.map +1 -1
  48. package/dist/lib/hastToRichText.d.cts +1 -6
  49. package/dist/lib/hastToRichText.d.cts.map +1 -1
  50. package/dist/lib/hastToRichText.d.ts +4 -6
  51. package/dist/lib/hastToRichText.d.ts.map +1 -1
  52. package/dist/lib/hastToRichText.js +1 -2
  53. package/dist/lib/hastToRichText.js.map +1 -1
  54. package/dist/lib/rehypeRichText.cjs +3 -3
  55. package/dist/lib/rehypeRichText.cjs.map +1 -1
  56. package/dist/lib/rehypeRichText.d.cts +2 -5
  57. package/dist/lib/rehypeRichText.d.cts.map +1 -1
  58. package/dist/lib/rehypeRichText.d.ts +4 -5
  59. package/dist/lib/rehypeRichText.d.ts.map +1 -1
  60. package/dist/lib/rehypeRichText.js +3 -3
  61. package/dist/lib/rehypeRichText.js.map +1 -1
  62. package/dist/types.d.cts +9 -9
  63. package/dist/types.d.cts.map +1 -1
  64. package/dist/types.d.ts +9 -9
  65. package/dist/types.d.ts.map +1 -1
  66. package/package.json +17 -17
  67. package/src/lib/hastToRichText.ts +31 -31
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -15,9 +15,8 @@ var __copyProps = (to, from, except, desc) => {
15
15
  }
16
16
  return to;
17
17
  };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
19
  value: mod,
20
20
  enumerable: true
21
21
  }) : target, mod));
22
- //#endregion
23
22
  exports.__toESM = __toESM;
@@ -1,6 +1,5 @@
1
- //#region src/errors/PrismicRichTextError.ts
1
+ // src/errors/PrismicRichTextError.ts
2
2
  var PrismicRichTextError = class extends Error {};
3
- //#endregion
4
3
  exports.PrismicRichTextError = PrismicRichTextError;
5
4
 
6
5
  //# sourceMappingURL=PrismicRichTextError.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextError.cjs","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"sourcesContent":["export class PrismicRichTextError extends Error {}\n"],"mappings":";AAAA,IAAa,uBAAb,cAA0C,MAAM"}
1
+ {"version":3,"file":"PrismicRichTextError.cjs","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"sourcesContent":["export class PrismicRichTextError extends Error {}\n"],"mappings":";AAAA,IAAa,uBAAb,cAA0C,MAAM,CAAC"}
@@ -1,5 +1,2 @@
1
- //#region src/errors/PrismicRichTextError.d.ts
2
- declare class PrismicRichTextError extends Error {}
3
- //#endregion
4
- export { PrismicRichTextError };
1
+ export declare class PrismicRichTextError extends Error {}
5
2
  //# sourceMappingURL=PrismicRichTextError.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":";cAAa,oBAAA,SAA6B,KAAA"}
1
+ {"version":3,"file":"PrismicRichTextError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":"A,qBAAa,6BAA6B"}
@@ -1,5 +1,2 @@
1
- //#region src/errors/PrismicRichTextError.d.ts
2
- declare class PrismicRichTextError extends Error {}
3
- //#endregion
4
- export { PrismicRichTextError };
1
+ export declare class PrismicRichTextError extends Error {}
5
2
  //# sourceMappingURL=PrismicRichTextError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":";cAAa,oBAAA,SAA6B,KAAA"}
1
+ {"version":3,"file":"PrismicRichTextError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":"A,qBAAa,6BAA6B"}
@@ -1,6 +1,5 @@
1
- //#region src/errors/PrismicRichTextError.ts
1
+ // src/errors/PrismicRichTextError.ts
2
2
  var PrismicRichTextError = class extends Error {};
3
- //#endregion
4
3
  export { PrismicRichTextError };
5
4
 
6
5
  //# sourceMappingURL=PrismicRichTextError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextError.js","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"sourcesContent":["export class PrismicRichTextError extends Error {}\n"],"mappings":";AAAA,IAAa,uBAAb,cAA0C,MAAM"}
1
+ {"version":3,"file":"PrismicRichTextError.js","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"sourcesContent":["export class PrismicRichTextError extends Error {}\n"],"mappings":";AAAA,IAAa,uBAAb,cAA0C,MAAM,CAAC"}
@@ -1,7 +1,6 @@
1
1
  const require_PrismicRichTextError = require("./PrismicRichTextError.cjs");
2
- //#region src/errors/PrismicRichTextSerializerError.ts
2
+ // src/errors/PrismicRichTextSerializerError.ts
3
3
  var PrismicRichTextSerializerError = class extends require_PrismicRichTextError.PrismicRichTextError {};
4
- //#endregion
5
4
  exports.PrismicRichTextSerializerError = PrismicRichTextSerializerError;
6
5
 
7
6
  //# sourceMappingURL=PrismicRichTextSerializerError.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextSerializerError.cjs","names":["PrismicRichTextError"],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"sourcesContent":["import { PrismicRichTextError } from \"./PrismicRichTextError\"\n\nexport class PrismicRichTextSerializerError extends PrismicRichTextError {}\n"],"mappings":";;AAEA,IAAa,iCAAb,cAAoDA,6BAAAA,qBAAqB"}
1
+ {"version":3,"file":"PrismicRichTextSerializerError.cjs","names":["PrismicRichTextError"],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"sourcesContent":["import { PrismicRichTextError } from \"./PrismicRichTextError\"\n\nexport class PrismicRichTextSerializerError extends PrismicRichTextError {}\n"],"mappings":";;AAEA,IAAa,iCAAb,cAAoDA,6BAAAA,qBAAqB,CAAC"}
@@ -1,7 +1,3 @@
1
1
  import { PrismicRichTextError } from "./PrismicRichTextError.cjs";
2
-
3
- //#region src/errors/PrismicRichTextSerializerError.d.ts
4
- declare class PrismicRichTextSerializerError extends PrismicRichTextError {}
5
- //#endregion
6
- export { PrismicRichTextSerializerError };
2
+ export declare class PrismicRichTextSerializerError extends PrismicRichTextError {}
7
3
  //# sourceMappingURL=PrismicRichTextSerializerError.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextSerializerError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";;;cAEa,8BAAA,SAAuC,oBAAA"}
1
+ {"version":3,"file":"PrismicRichTextSerializerError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";qBAEa,uCAAuC"}
@@ -1,7 +1,3 @@
1
1
  import { PrismicRichTextError } from "./PrismicRichTextError.js";
2
-
3
- //#region src/errors/PrismicRichTextSerializerError.d.ts
4
- declare class PrismicRichTextSerializerError extends PrismicRichTextError {}
5
- //#endregion
6
- export { PrismicRichTextSerializerError };
2
+ export declare class PrismicRichTextSerializerError extends PrismicRichTextError {}
7
3
  //# sourceMappingURL=PrismicRichTextSerializerError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextSerializerError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";;;cAEa,8BAAA,SAAuC,oBAAA"}
1
+ {"version":3,"file":"PrismicRichTextSerializerError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";qBAEa,uCAAuC"}
@@ -1,7 +1,6 @@
1
1
  import { PrismicRichTextError } from "./PrismicRichTextError.js";
2
- //#region src/errors/PrismicRichTextSerializerError.ts
2
+ // src/errors/PrismicRichTextSerializerError.ts
3
3
  var PrismicRichTextSerializerError = class extends PrismicRichTextError {};
4
- //#endregion
5
4
  export { PrismicRichTextSerializerError };
6
5
 
7
6
  //# sourceMappingURL=PrismicRichTextSerializerError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextSerializerError.js","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"sourcesContent":["import { PrismicRichTextError } from \"./PrismicRichTextError\"\n\nexport class PrismicRichTextSerializerError extends PrismicRichTextError {}\n"],"mappings":";;AAEA,IAAa,iCAAb,cAAoD,qBAAqB"}
1
+ {"version":3,"file":"PrismicRichTextSerializerError.js","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"sourcesContent":["import { PrismicRichTextError } from \"./PrismicRichTextError\"\n\nexport class PrismicRichTextSerializerError extends PrismicRichTextError {}\n"],"mappings":";;AAEA,IAAa,iCAAb,cAAoD,qBAAqB,CAAC"}
@@ -3,7 +3,7 @@ const require_rehypeRichText = require("./lib/rehypeRichText.cjs");
3
3
  let rehype_parse = require("rehype-parse");
4
4
  rehype_parse = require_runtime.__toESM(rehype_parse, 1);
5
5
  let unified = require("unified");
6
- //#region src/htmlAsRichText.ts
6
+ // src/htmlAsRichText.ts
7
7
  /**
8
8
  * Converts an HTML string to a rich text field.
9
9
  *
@@ -21,7 +21,6 @@ const htmlAsRichText = (html, config) => {
21
21
  warnings: messages.map((message) => message.toString())
22
22
  };
23
23
  };
24
- //#endregion
25
24
  exports.htmlAsRichText = htmlAsRichText;
26
25
 
27
26
  //# sourceMappingURL=htmlAsRichText.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"htmlAsRichText.cjs","names":["rehypeParse","rehypeRichText"],"sources":["../src/htmlAsRichText.ts"],"sourcesContent":["// Used for TSDocs only.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { HTMLRichTextMapSerializer, asHTML } from \"@prismicio/client\"\nimport type { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from \"@prismicio/client\"\nimport type { Element } from \"hast\"\nimport rehypeParse from \"rehype-parse\"\nimport { unified } from \"unified\"\n\nimport type { RehypeRichTextConfig } from \"./lib/rehypeRichText\"\nimport { rehypeRichText } from \"./lib/rehypeRichText\"\nimport type { RTPartialInlineNode } from \"./lib/RichTextFieldBuilder\"\n\n/**\n * A shorthand definition for {@link RichTextHTMLMapSerializer} rich text node types.\n *\n * @remarks\n * The `label` rich text node type is not available as is. Use an object containing your label\n * name to convert to label nodes instead. For example: `u: { label: \"underline\" }`\n * @remarks\n * The `span` rich text node type is not available as it is not relevant in the context of going\n * from HTML to Prismic rich text.\n */\nexport type RichTextHTMLMapSerializerShorthand =\n\t| Exclude<RichTextNodeTypes, \"label\" | \"span\">\n\t| { label: string }\n\n/** The payload provided to a {@link RichTextHTMLMapSerializerFunction}. */\ntype RichTextHTMLMapSerializerFunctionPayload = {\n\t/** The hast {@link Element} node to serialize. */\n\tnode: Element\n\n\t/** Additional context information to help with the serialization. */\n\tcontext: {\n\t\t/** The list type of the last list node encountered if any. */\n\t\tlistType?: \"group-list-item\" | \"group-o-list-item\"\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RichTextHTMLMapSerializerShorthand} or a rich\n * text node.\n *\n * @remarks\n * Serializing to a rich text node directly is not recommended and is only available as an escape\n * hatch. Prefer returning a {@link RichTextHTMLMapSerializerShorthand} instead.\n */\nexport type RichTextHTMLMapSerializerFunction = (\n\tpayload: RichTextHTMLMapSerializerFunctionPayload,\n) => RichTextHTMLMapSerializerShorthand | RTNode | RTInlineNode | RTPartialInlineNode | undefined\n\n/**\n * Serializes a hast {@link Element} node matching the given HTML tag name or CSS selector to a\n * Prismic rich text node.\n *\n * @remarks\n * This serializer is used to serialize HTML to Prismic rich text. When serializing Prismic rich\n * text to HTML with {@link asHTML}, use the {@link HTMLRichTextMapSerializer} type instead.\n */\nexport type RichTextHTMLMapSerializer = Record<\n\tstring,\n\tRichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction\n>\n\n/** Configuration that determines the output of {@link htmlAsRichText}. */\nexport type HTMLAsRichTextConfig = RehypeRichTextConfig\n\n/** The return type of {@link htmlAsRichText}. */\ntype HTMLAsRichTextReturnType = {\n\tresult: RichTextField\n\twarnings: string[]\n}\n\n/**\n * Converts an HTML string to a rich text field.\n *\n * @param html - An HTML string.\n * @param config - Configuration that determines the output the function.\n * @returns `html` as rich text.\n */\nexport const htmlAsRichText = (\n\thtml: string,\n\tconfig?: HTMLAsRichTextConfig,\n): HTMLAsRichTextReturnType => {\n\tconst { result, messages } = unified()\n\t\t.use(rehypeParse, { emitParseErrors: true, missingDoctype: 0 })\n\t\t.use(rehypeRichText, config)\n\t\t.processSync(html)\n\n\treturn { result, warnings: messages.map((message) => message.toString()) }\n}\n"],"mappings":";;;;;;;;;;;;;AA+EA,MAAa,kBACZ,MACA,WAC8B;CAC9B,MAAM,EAAE,QAAQ,cAAA,GAAA,QAAA,UAAsB,CACpC,IAAIA,aAAAA,SAAa;EAAE,iBAAiB;EAAM,gBAAgB;EAAG,CAAC,CAC9D,IAAIC,uBAAAA,gBAAgB,OAAO,CAC3B,YAAY,KAAK;AAEnB,QAAO;EAAE;EAAQ,UAAU,SAAS,KAAK,YAAY,QAAQ,UAAU,CAAC;EAAE"}
1
+ {"version":3,"file":"htmlAsRichText.cjs","names":["rehypeParse","rehypeRichText"],"sources":["../src/htmlAsRichText.ts"],"sourcesContent":["// Used for TSDocs only.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { HTMLRichTextMapSerializer, asHTML } from \"@prismicio/client\"\nimport type { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from \"@prismicio/client\"\nimport type { Element } from \"hast\"\nimport rehypeParse from \"rehype-parse\"\nimport { unified } from \"unified\"\n\nimport type { RehypeRichTextConfig } from \"./lib/rehypeRichText\"\nimport { rehypeRichText } from \"./lib/rehypeRichText\"\nimport type { RTPartialInlineNode } from \"./lib/RichTextFieldBuilder\"\n\n/**\n * A shorthand definition for {@link RichTextHTMLMapSerializer} rich text node types.\n *\n * @remarks\n * The `label` rich text node type is not available as is. Use an object containing your label\n * name to convert to label nodes instead. For example: `u: { label: \"underline\" }`\n * @remarks\n * The `span` rich text node type is not available as it is not relevant in the context of going\n * from HTML to Prismic rich text.\n */\nexport type RichTextHTMLMapSerializerShorthand =\n\t| Exclude<RichTextNodeTypes, \"label\" | \"span\">\n\t| { label: string }\n\n/** The payload provided to a {@link RichTextHTMLMapSerializerFunction}. */\ntype RichTextHTMLMapSerializerFunctionPayload = {\n\t/** The hast {@link Element} node to serialize. */\n\tnode: Element\n\n\t/** Additional context information to help with the serialization. */\n\tcontext: {\n\t\t/** The list type of the last list node encountered if any. */\n\t\tlistType?: \"group-list-item\" | \"group-o-list-item\"\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RichTextHTMLMapSerializerShorthand} or a rich\n * text node.\n *\n * @remarks\n * Serializing to a rich text node directly is not recommended and is only available as an escape\n * hatch. Prefer returning a {@link RichTextHTMLMapSerializerShorthand} instead.\n */\nexport type RichTextHTMLMapSerializerFunction = (\n\tpayload: RichTextHTMLMapSerializerFunctionPayload,\n) => RichTextHTMLMapSerializerShorthand | RTNode | RTInlineNode | RTPartialInlineNode | undefined\n\n/**\n * Serializes a hast {@link Element} node matching the given HTML tag name or CSS selector to a\n * Prismic rich text node.\n *\n * @remarks\n * This serializer is used to serialize HTML to Prismic rich text. When serializing Prismic rich\n * text to HTML with {@link asHTML}, use the {@link HTMLRichTextMapSerializer} type instead.\n */\nexport type RichTextHTMLMapSerializer = Record<\n\tstring,\n\tRichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction\n>\n\n/** Configuration that determines the output of {@link htmlAsRichText}. */\nexport type HTMLAsRichTextConfig = RehypeRichTextConfig\n\n/** The return type of {@link htmlAsRichText}. */\ntype HTMLAsRichTextReturnType = {\n\tresult: RichTextField\n\twarnings: string[]\n}\n\n/**\n * Converts an HTML string to a rich text field.\n *\n * @param html - An HTML string.\n * @param config - Configuration that determines the output the function.\n * @returns `html` as rich text.\n */\nexport const htmlAsRichText = (\n\thtml: string,\n\tconfig?: HTMLAsRichTextConfig,\n): HTMLAsRichTextReturnType => {\n\tconst { result, messages } = unified()\n\t\t.use(rehypeParse, { emitParseErrors: true, missingDoctype: 0 })\n\t\t.use(rehypeRichText, config)\n\t\t.processSync(html)\n\n\treturn { result, warnings: messages.map((message) => message.toString()) }\n}\n"],"mappings":";;;;;;;;;;;;;AA+EA,MAAa,kBACZ,MACA,WAC8B;CAC9B,MAAM,EAAE,QAAQ,cAAA,GAAa,QAAA,QAAA,CAAQ,CAAC,CACpC,IAAIA,aAAAA,SAAa;EAAE,iBAAiB;EAAM,gBAAgB;CAAE,CAAC,CAAC,CAC9D,IAAIC,uBAAAA,gBAAgB,MAAM,CAAC,CAC3B,YAAY,IAAI;CAElB,OAAO;EAAE;EAAQ,UAAU,SAAS,KAAK,YAAY,QAAQ,SAAS,CAAC;CAAE;AAC1E"}
@@ -1,10 +1,8 @@
1
1
  import { RehypeRichTextConfig } from "./lib/rehypeRichText.cjs";
2
- import { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from "@prismicio/client";
3
- import { Element } from "hast";
4
-
5
- //#region src/htmlAsRichText.d.ts
2
+ import "./lib/RichTextFieldBuilder.cjs";
3
+ import { RichTextField } from "@prismicio/client";
6
4
  /** Configuration that determines the output of {@link htmlAsRichText}. */
7
- type HTMLAsRichTextConfig = RehypeRichTextConfig;
5
+ export type HTMLAsRichTextConfig = RehypeRichTextConfig;
8
6
  /** The return type of {@link htmlAsRichText}. */
9
7
  type HTMLAsRichTextReturnType = {
10
8
  result: RichTextField;
@@ -17,7 +15,6 @@ type HTMLAsRichTextReturnType = {
17
15
  * @param config - Configuration that determines the output the function.
18
16
  * @returns `html` as rich text.
19
17
  */
20
- declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
21
- //#endregion
22
- export { htmlAsRichText };
18
+ export declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
19
+ export {};
23
20
  //# sourceMappingURL=htmlAsRichText.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"htmlAsRichText.d.cts","names":[],"sources":["../src/htmlAsRichText.ts"],"mappings":";;;;;;KAgEY,oBAAA,GAAuB,oBAAA;;KAG9B,wBAAA;EACJ,MAAA,EAAQ,aAAA;EACR,QAAA;AAAA;;;;;;;;cAUY,cAAA,GACZ,IAAA,UACA,MAAA,GAAS,oBAAA,KACP,wBAAA"}
1
+ {"version":3,"file":"htmlAsRichText.d.cts","names":[],"sources":["../src/htmlAsRichText.ts"],"mappings":";;;;YAgEY,uBAAuB;;KAG9B;EACJ,QAAQ;EACR;;;;;;;;;qBAUY,iBAAc,cACd,SACH,yBACP"}
@@ -1,10 +1,9 @@
1
1
  import { RehypeRichTextConfig } from "./lib/rehypeRichText.js";
2
- import { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from "@prismicio/client";
3
- import { Element } from "hast";
4
-
5
- //#region src/htmlAsRichText.d.ts
2
+ import "./lib/RichTextFieldBuilder.js";
3
+ import { RichTextField } from "@prismicio/client";
4
+ import "hast";
6
5
  /** Configuration that determines the output of {@link htmlAsRichText}. */
7
- type HTMLAsRichTextConfig = RehypeRichTextConfig;
6
+ export type HTMLAsRichTextConfig = RehypeRichTextConfig;
8
7
  /** The return type of {@link htmlAsRichText}. */
9
8
  type HTMLAsRichTextReturnType = {
10
9
  result: RichTextField;
@@ -17,7 +16,6 @@ type HTMLAsRichTextReturnType = {
17
16
  * @param config - Configuration that determines the output the function.
18
17
  * @returns `html` as rich text.
19
18
  */
20
- declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
21
- //#endregion
22
- export { htmlAsRichText };
19
+ export declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
20
+ export {};
23
21
  //# sourceMappingURL=htmlAsRichText.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"htmlAsRichText.d.ts","names":[],"sources":["../src/htmlAsRichText.ts"],"mappings":";;;;;;KAgEY,oBAAA,GAAuB,oBAAA;;KAG9B,wBAAA;EACJ,MAAA,EAAQ,aAAA;EACR,QAAA;AAAA;;;;;;;;cAUY,cAAA,GACZ,IAAA,UACA,MAAA,GAAS,oBAAA,KACP,wBAAA"}
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,7 +1,7 @@
1
1
  import { rehypeRichText } from "./lib/rehypeRichText.js";
2
2
  import rehypeParse from "rehype-parse";
3
3
  import { unified } from "unified";
4
- //#region src/htmlAsRichText.ts
4
+ // src/htmlAsRichText.ts
5
5
  /**
6
6
  * Converts an HTML string to a rich text field.
7
7
  *
@@ -19,7 +19,6 @@ const htmlAsRichText = (html, config) => {
19
19
  warnings: messages.map((message) => message.toString())
20
20
  };
21
21
  };
22
- //#endregion
23
22
  export { htmlAsRichText };
24
23
 
25
24
  //# sourceMappingURL=htmlAsRichText.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"htmlAsRichText.js","names":[],"sources":["../src/htmlAsRichText.ts"],"sourcesContent":["// Used for TSDocs only.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { HTMLRichTextMapSerializer, asHTML } from \"@prismicio/client\"\nimport type { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from \"@prismicio/client\"\nimport type { Element } from \"hast\"\nimport rehypeParse from \"rehype-parse\"\nimport { unified } from \"unified\"\n\nimport type { RehypeRichTextConfig } from \"./lib/rehypeRichText\"\nimport { rehypeRichText } from \"./lib/rehypeRichText\"\nimport type { RTPartialInlineNode } from \"./lib/RichTextFieldBuilder\"\n\n/**\n * A shorthand definition for {@link RichTextHTMLMapSerializer} rich text node types.\n *\n * @remarks\n * The `label` rich text node type is not available as is. Use an object containing your label\n * name to convert to label nodes instead. For example: `u: { label: \"underline\" }`\n * @remarks\n * The `span` rich text node type is not available as it is not relevant in the context of going\n * from HTML to Prismic rich text.\n */\nexport type RichTextHTMLMapSerializerShorthand =\n\t| Exclude<RichTextNodeTypes, \"label\" | \"span\">\n\t| { label: string }\n\n/** The payload provided to a {@link RichTextHTMLMapSerializerFunction}. */\ntype RichTextHTMLMapSerializerFunctionPayload = {\n\t/** The hast {@link Element} node to serialize. */\n\tnode: Element\n\n\t/** Additional context information to help with the serialization. */\n\tcontext: {\n\t\t/** The list type of the last list node encountered if any. */\n\t\tlistType?: \"group-list-item\" | \"group-o-list-item\"\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RichTextHTMLMapSerializerShorthand} or a rich\n * text node.\n *\n * @remarks\n * Serializing to a rich text node directly is not recommended and is only available as an escape\n * hatch. Prefer returning a {@link RichTextHTMLMapSerializerShorthand} instead.\n */\nexport type RichTextHTMLMapSerializerFunction = (\n\tpayload: RichTextHTMLMapSerializerFunctionPayload,\n) => RichTextHTMLMapSerializerShorthand | RTNode | RTInlineNode | RTPartialInlineNode | undefined\n\n/**\n * Serializes a hast {@link Element} node matching the given HTML tag name or CSS selector to a\n * Prismic rich text node.\n *\n * @remarks\n * This serializer is used to serialize HTML to Prismic rich text. When serializing Prismic rich\n * text to HTML with {@link asHTML}, use the {@link HTMLRichTextMapSerializer} type instead.\n */\nexport type RichTextHTMLMapSerializer = Record<\n\tstring,\n\tRichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction\n>\n\n/** Configuration that determines the output of {@link htmlAsRichText}. */\nexport type HTMLAsRichTextConfig = RehypeRichTextConfig\n\n/** The return type of {@link htmlAsRichText}. */\ntype HTMLAsRichTextReturnType = {\n\tresult: RichTextField\n\twarnings: string[]\n}\n\n/**\n * Converts an HTML string to a rich text field.\n *\n * @param html - An HTML string.\n * @param config - Configuration that determines the output the function.\n * @returns `html` as rich text.\n */\nexport const htmlAsRichText = (\n\thtml: string,\n\tconfig?: HTMLAsRichTextConfig,\n): HTMLAsRichTextReturnType => {\n\tconst { result, messages } = unified()\n\t\t.use(rehypeParse, { emitParseErrors: true, missingDoctype: 0 })\n\t\t.use(rehypeRichText, config)\n\t\t.processSync(html)\n\n\treturn { result, warnings: messages.map((message) => message.toString()) }\n}\n"],"mappings":";;;;;;;;;;;AA+EA,MAAa,kBACZ,MACA,WAC8B;CAC9B,MAAM,EAAE,QAAQ,aAAa,SAAS,CACpC,IAAI,aAAa;EAAE,iBAAiB;EAAM,gBAAgB;EAAG,CAAC,CAC9D,IAAI,gBAAgB,OAAO,CAC3B,YAAY,KAAK;AAEnB,QAAO;EAAE;EAAQ,UAAU,SAAS,KAAK,YAAY,QAAQ,UAAU,CAAC;EAAE"}
1
+ {"version":3,"file":"htmlAsRichText.js","names":[],"sources":["../src/htmlAsRichText.ts"],"sourcesContent":["// Used for TSDocs only.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { HTMLRichTextMapSerializer, asHTML } from \"@prismicio/client\"\nimport type { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from \"@prismicio/client\"\nimport type { Element } from \"hast\"\nimport rehypeParse from \"rehype-parse\"\nimport { unified } from \"unified\"\n\nimport type { RehypeRichTextConfig } from \"./lib/rehypeRichText\"\nimport { rehypeRichText } from \"./lib/rehypeRichText\"\nimport type { RTPartialInlineNode } from \"./lib/RichTextFieldBuilder\"\n\n/**\n * A shorthand definition for {@link RichTextHTMLMapSerializer} rich text node types.\n *\n * @remarks\n * The `label` rich text node type is not available as is. Use an object containing your label\n * name to convert to label nodes instead. For example: `u: { label: \"underline\" }`\n * @remarks\n * The `span` rich text node type is not available as it is not relevant in the context of going\n * from HTML to Prismic rich text.\n */\nexport type RichTextHTMLMapSerializerShorthand =\n\t| Exclude<RichTextNodeTypes, \"label\" | \"span\">\n\t| { label: string }\n\n/** The payload provided to a {@link RichTextHTMLMapSerializerFunction}. */\ntype RichTextHTMLMapSerializerFunctionPayload = {\n\t/** The hast {@link Element} node to serialize. */\n\tnode: Element\n\n\t/** Additional context information to help with the serialization. */\n\tcontext: {\n\t\t/** The list type of the last list node encountered if any. */\n\t\tlistType?: \"group-list-item\" | \"group-o-list-item\"\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RichTextHTMLMapSerializerShorthand} or a rich\n * text node.\n *\n * @remarks\n * Serializing to a rich text node directly is not recommended and is only available as an escape\n * hatch. Prefer returning a {@link RichTextHTMLMapSerializerShorthand} instead.\n */\nexport type RichTextHTMLMapSerializerFunction = (\n\tpayload: RichTextHTMLMapSerializerFunctionPayload,\n) => RichTextHTMLMapSerializerShorthand | RTNode | RTInlineNode | RTPartialInlineNode | undefined\n\n/**\n * Serializes a hast {@link Element} node matching the given HTML tag name or CSS selector to a\n * Prismic rich text node.\n *\n * @remarks\n * This serializer is used to serialize HTML to Prismic rich text. When serializing Prismic rich\n * text to HTML with {@link asHTML}, use the {@link HTMLRichTextMapSerializer} type instead.\n */\nexport type RichTextHTMLMapSerializer = Record<\n\tstring,\n\tRichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction\n>\n\n/** Configuration that determines the output of {@link htmlAsRichText}. */\nexport type HTMLAsRichTextConfig = RehypeRichTextConfig\n\n/** The return type of {@link htmlAsRichText}. */\ntype HTMLAsRichTextReturnType = {\n\tresult: RichTextField\n\twarnings: string[]\n}\n\n/**\n * Converts an HTML string to a rich text field.\n *\n * @param html - An HTML string.\n * @param config - Configuration that determines the output the function.\n * @returns `html` as rich text.\n */\nexport const htmlAsRichText = (\n\thtml: string,\n\tconfig?: HTMLAsRichTextConfig,\n): HTMLAsRichTextReturnType => {\n\tconst { result, messages } = unified()\n\t\t.use(rehypeParse, { emitParseErrors: true, missingDoctype: 0 })\n\t\t.use(rehypeRichText, config)\n\t\t.processSync(html)\n\n\treturn { result, warnings: messages.map((message) => message.toString()) }\n}\n"],"mappings":";;;;;;;;;;;AA+EA,MAAa,kBACZ,MACA,WAC8B;CAC9B,MAAM,EAAE,QAAQ,aAAa,QAAQ,CAAC,CACpC,IAAI,aAAa;EAAE,iBAAiB;EAAM,gBAAgB;CAAE,CAAC,CAAC,CAC9D,IAAI,gBAAgB,MAAM,CAAC,CAC3B,YAAY,IAAI;CAElB,OAAO;EAAE;EAAQ,UAAU,SAAS,KAAK,YAAY,QAAQ,SAAS,CAAC;CAAE;AAC1E"}
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_htmlAsRichText = require("./htmlAsRichText.cjs");
2
3
  const require_PrismicRichTextError = require("./errors/PrismicRichTextError.cjs");
3
4
  const require_PrismicRichTextSerializerError = require("./errors/PrismicRichTextSerializerError.cjs");
4
- const require_htmlAsRichText = require("./htmlAsRichText.cjs");
5
5
  exports.PrismicRichTextError = require_PrismicRichTextError.PrismicRichTextError;
6
6
  exports.PrismicRichTextSerializerError = require_PrismicRichTextSerializerError.PrismicRichTextSerializerError;
7
7
  exports.htmlAsRichText = require_htmlAsRichText.htmlAsRichText;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { RichTextHTMLMapSerializer } from "./types.cjs";
2
1
  import { htmlAsRichText } from "./htmlAsRichText.cjs";
2
+ import { RichTextHTMLMapSerializer } from "./types.cjs";
3
3
  import { PrismicRichTextError } from "./errors/PrismicRichTextError.cjs";
4
4
  import { PrismicRichTextSerializerError } from "./errors/PrismicRichTextSerializerError.cjs";
5
5
  export { PrismicRichTextError, PrismicRichTextSerializerError, type RichTextHTMLMapSerializer, htmlAsRichText };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { RichTextHTMLMapSerializer } from "./types.js";
2
1
  import { htmlAsRichText } from "./htmlAsRichText.js";
2
+ import { RichTextHTMLMapSerializer } from "./types.js";
3
3
  import { PrismicRichTextError } from "./errors/PrismicRichTextError.js";
4
4
  import { PrismicRichTextSerializerError } from "./errors/PrismicRichTextSerializerError.js";
5
5
  export { PrismicRichTextError, PrismicRichTextSerializerError, type RichTextHTMLMapSerializer, htmlAsRichText };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
+ import { htmlAsRichText } from "./htmlAsRichText.js";
1
2
  import { PrismicRichTextError } from "./errors/PrismicRichTextError.js";
2
3
  import { PrismicRichTextSerializerError } from "./errors/PrismicRichTextSerializerError.js";
3
- import { htmlAsRichText } from "./htmlAsRichText.js";
4
4
  export { PrismicRichTextError, PrismicRichTextSerializerError, htmlAsRichText };
@@ -1,5 +1,5 @@
1
1
  const require_PrismicRichTextError = require("../errors/PrismicRichTextError.cjs");
2
- //#region src/lib/RichTextFieldBuilder.ts
2
+ // src/lib/RichTextFieldBuilder.ts
3
3
  var RichTextFieldBuilder = class {
4
4
  #nodes = [];
5
5
  get #last() {
@@ -78,7 +78,6 @@ var RichTextFieldBuilder = class {
78
78
  return !!node && node.type !== "image" && node.type !== "embed";
79
79
  }
80
80
  };
81
- //#endregion
82
81
  exports.RichTextFieldBuilder = RichTextFieldBuilder;
83
82
 
84
83
  //# sourceMappingURL=RichTextFieldBuilder.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextFieldBuilder.cjs","names":["#last","#nodes","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,EAAE;CAEnD,KAAA,OAA8D;AAC7D,SAAO,MAAA,MAAY,MAAA,MAAY,SAAS;;CAGzC,WAAW,MAAkD;AAC5D,OAAK,aAAa;AAElB,QAAA,MAAY,KAAK,KAAK;;CAGvB,eAAe,MAA0B,YAA2B,OAAa;AAChF,OAAK,WAAW;GACf;GACA,MAAM;GACN,OAAO,EAAE;GACT;GACA,CAAC;;CAKH,WACC,mBACA,QACO;AACP,MAAI,CAAC,KAAK,WAAW,MAAA,KAAW,CAC/B,OAAM,IAAIE,6BAAAA,qBAAqB,wCAAwC;EAGxE,IAAI;AACJ,MAAI,WAAW,qBAAqB,SAAS,kBAC5C,QAAO;OACD;GACN,MAAM,aAAa,MAAA,KAAW,KAAK;AAEnC,UAAO;IACN,GAAG;IACH,OAAO;IACP,KAAK,aAAa;IAClB;;EAGF,IAAI,yBAAyB;AAC7B,OAAK,IAAI,IAAI,MAAA,KAAW,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;GACtD,MAAM,WAAW,MAAA,KAAW,MAAM;AAElC,OAAI,KAAK,SAAS,YAAY,KAAK,SAAS;QACvC,SAAS,SAAS,KAAK,MAAM;AAChC,8BAAyB;AACzB;;cAES,KAAK,SAAS;QACpB,SAAS,SAAS,WAAW,SAAS,KAAK,UAAU,KAAK,KAAK,OAAO;AACzE,8BAAyB;AACzB;;cAES,KAAK,SAAS;QACpB,SAAS,SAAS;SAKpB,OAAO,KAAK,SAAS,YAAY,OAAO,SAAS,SAAS,WACtD,OAAO,QAAQ,KAAK,KAAK,CAA2C,OACpE,CAAC,KAAK,WACN,SAAS,OAAO,SAA4C,MAC7D,GACA,KAAK,SAAS,SAAS,MAEX;AACf,+BAAyB;AACzB;;;;;AAOJ,MAAI,KAAK,UAAU,KAAK,IACvB;AAKD,MAAI,MAAA,KAAW,MAAM,yBAAyB,QAAQ,KAAK,MAC1D,OAAA,KAAW,MAAM,wBAAwB,MAAM,KAAK;MAEpD,OAAA,KAAW,MAAM,KAAK,KAAK;;CAI7B,WAAW,MAAoB;AAC9B,MAAI,CAAC,KAAK,WAAW,MAAA,KAAW,CAC/B,OAAM,IAAIA,6BAAAA,qBAAqB,2CAA2C;AAG3E,MAAI,MAAA,KAAW,KACd,OAAA,KAAW,QAAQ;MAEnB,OAAA,KAAW,OAAO,KAAK,WAAW;;CAIpC,QAAuB;AAEtB,OAAK,aAAa;AAIlB,SAAO,MAAA;;;CAIR,cAA4B;AAC3B,MAAI,KAAK,WAAW,MAAA,KAAW,CAC9B,OAAA,KAAW,OAAO,MAAA,KAAW,KAAK,SAAS;;;;;;;;CAU7C,WACC,MACmD;AACnD,SAAO,CAAC,CAAC,QAAQ,KAAK,SAAS,WAAW,KAAK,SAAS"}
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;;CAGQ,cAAoB;EAC3B,IAAI,KAAK,WAAW,KAAK,KAAK,GAC7B,KAAK,MAAM,OAAO,KAAK,MAAM,KAAK,QAAQ;CAE5C;;;;;;;CAQQ,WACP,MACmD;EACnD,OAAO,CAAC,CAAC,QAAQ,KAAK,SAAS,WAAW,KAAK,SAAS;CACzD;AACD"}
@@ -1,6 +1,4 @@
1
- import { InjectMigrationSpecificTypes, RTInlineNode, RTNode, RichTextField } from "@prismicio/client";
2
-
3
- //#region src/lib/RichTextFieldBuilder.d.ts
1
+ import { RTInlineNode } from "@prismicio/client";
4
2
  /**
5
3
  * Omits keys from a type, distributing the operation over a union.
6
4
  *
@@ -10,7 +8,6 @@ import { InjectMigrationSpecificTypes, RTInlineNode, RTNode, RichTextField } fro
10
8
  */
11
9
  type DistributedOmit<ObjectType, KeyType extends keyof ObjectType> = ObjectType extends unknown ? Omit<ObjectType, KeyType> : never;
12
10
  /** An inline node without its `start` and `end` properties. */
13
- type RTPartialInlineNode = DistributedOmit<RTInlineNode, "start" | "end">;
14
- //#endregion
15
- export { RTPartialInlineNode };
11
+ export type RTPartialInlineNode = DistributedOmit<RTInlineNode, "start" | "end">;
12
+ export {};
16
13
  //# sourceMappingURL=RichTextFieldBuilder.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextFieldBuilder.d.cts","names":[],"sources":["../../src/lib/RichTextFieldBuilder.ts"],"mappings":";;;;;AAO0B;;;;;KAWrB,eAAA,mCAAkD,UAAA,IAAc,UAAA,mBAClE,IAAA,CAAK,UAAA,EAAY,OAAA;;KAIR,mBAAA,GAAsB,eAAA,CAAgB,YAAA"}
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"}
@@ -1,6 +1,4 @@
1
- import { InjectMigrationSpecificTypes, RTInlineNode, RTNode, RichTextField } from "@prismicio/client";
2
-
3
- //#region src/lib/RichTextFieldBuilder.d.ts
1
+ import { RTInlineNode } from "@prismicio/client";
4
2
  /**
5
3
  * Omits keys from a type, distributing the operation over a union.
6
4
  *
@@ -10,7 +8,6 @@ import { InjectMigrationSpecificTypes, RTInlineNode, RTNode, RichTextField } fro
10
8
  */
11
9
  type DistributedOmit<ObjectType, KeyType extends keyof ObjectType> = ObjectType extends unknown ? Omit<ObjectType, KeyType> : never;
12
10
  /** An inline node without its `start` and `end` properties. */
13
- type RTPartialInlineNode = DistributedOmit<RTInlineNode, "start" | "end">;
14
- //#endregion
15
- export { RTPartialInlineNode };
11
+ export type RTPartialInlineNode = DistributedOmit<RTInlineNode, "start" | "end">;
12
+ export {};
16
13
  //# sourceMappingURL=RichTextFieldBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextFieldBuilder.d.ts","names":[],"sources":["../../src/lib/RichTextFieldBuilder.ts"],"mappings":";;;;;AAO0B;;;;;KAWrB,eAAA,mCAAkD,UAAA,IAAc,UAAA,mBAClE,IAAA,CAAK,UAAA,EAAY,OAAA;;KAIR,mBAAA,GAAsB,eAAA,CAAgB,YAAA"}
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,5 +1,5 @@
1
1
  import { PrismicRichTextError } from "../errors/PrismicRichTextError.js";
2
- //#region src/lib/RichTextFieldBuilder.ts
2
+ // src/lib/RichTextFieldBuilder.ts
3
3
  var RichTextFieldBuilder = class {
4
4
  #nodes = [];
5
5
  get #last() {
@@ -78,7 +78,6 @@ var RichTextFieldBuilder = class {
78
78
  return !!node && node.type !== "image" && node.type !== "embed";
79
79
  }
80
80
  };
81
- //#endregion
82
81
  export { RichTextFieldBuilder };
83
82
 
84
83
  //# sourceMappingURL=RichTextFieldBuilder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextFieldBuilder.js","names":["#last","#nodes"],"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,EAAE;CAEnD,KAAA,OAA8D;AAC7D,SAAO,MAAA,MAAY,MAAA,MAAY,SAAS;;CAGzC,WAAW,MAAkD;AAC5D,OAAK,aAAa;AAElB,QAAA,MAAY,KAAK,KAAK;;CAGvB,eAAe,MAA0B,YAA2B,OAAa;AAChF,OAAK,WAAW;GACf;GACA,MAAM;GACN,OAAO,EAAE;GACT;GACA,CAAC;;CAKH,WACC,mBACA,QACO;AACP,MAAI,CAAC,KAAK,WAAW,MAAA,KAAW,CAC/B,OAAM,IAAI,qBAAqB,wCAAwC;EAGxE,IAAI;AACJ,MAAI,WAAW,qBAAqB,SAAS,kBAC5C,QAAO;OACD;GACN,MAAM,aAAa,MAAA,KAAW,KAAK;AAEnC,UAAO;IACN,GAAG;IACH,OAAO;IACP,KAAK,aAAa;IAClB;;EAGF,IAAI,yBAAyB;AAC7B,OAAK,IAAI,IAAI,MAAA,KAAW,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;GACtD,MAAM,WAAW,MAAA,KAAW,MAAM;AAElC,OAAI,KAAK,SAAS,YAAY,KAAK,SAAS;QACvC,SAAS,SAAS,KAAK,MAAM;AAChC,8BAAyB;AACzB;;cAES,KAAK,SAAS;QACpB,SAAS,SAAS,WAAW,SAAS,KAAK,UAAU,KAAK,KAAK,OAAO;AACzE,8BAAyB;AACzB;;cAES,KAAK,SAAS;QACpB,SAAS,SAAS;SAKpB,OAAO,KAAK,SAAS,YAAY,OAAO,SAAS,SAAS,WACtD,OAAO,QAAQ,KAAK,KAAK,CAA2C,OACpE,CAAC,KAAK,WACN,SAAS,OAAO,SAA4C,MAC7D,GACA,KAAK,SAAS,SAAS,MAEX;AACf,+BAAyB;AACzB;;;;;AAOJ,MAAI,KAAK,UAAU,KAAK,IACvB;AAKD,MAAI,MAAA,KAAW,MAAM,yBAAyB,QAAQ,KAAK,MAC1D,OAAA,KAAW,MAAM,wBAAwB,MAAM,KAAK;MAEpD,OAAA,KAAW,MAAM,KAAK,KAAK;;CAI7B,WAAW,MAAoB;AAC9B,MAAI,CAAC,KAAK,WAAW,MAAA,KAAW,CAC/B,OAAM,IAAI,qBAAqB,2CAA2C;AAG3E,MAAI,MAAA,KAAW,KACd,OAAA,KAAW,QAAQ;MAEnB,OAAA,KAAW,OAAO,KAAK,WAAW;;CAIpC,QAAuB;AAEtB,OAAK,aAAa;AAIlB,SAAO,MAAA;;;CAIR,cAA4B;AAC3B,MAAI,KAAK,WAAW,MAAA,KAAW,CAC9B,OAAA,KAAW,OAAO,MAAA,KAAW,KAAK,SAAS;;;;;;;;CAU7C,WACC,MACmD;AACnD,SAAO,CAAC,CAAC,QAAQ,KAAK,SAAS,WAAW,KAAK,SAAS"}
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;;CAGQ,cAAoB;EAC3B,IAAI,KAAK,WAAW,KAAK,KAAK,GAC7B,KAAK,MAAM,OAAO,KAAK,MAAM,KAAK,QAAQ;CAE5C;;;;;;;CAQQ,WACP,MACmD;EACnD,OAAO,CAAC,CAAC,QAAQ,KAAK,SAAS,WAAW,KAAK,SAAS;CACzD;AACD"}
@@ -1,6 +1,5 @@
1
- require("../_virtual/_rolldown/runtime.cjs");
2
1
  let _prismicio_client = require("@prismicio/client");
3
- //#region src/lib/filterRichTextField.ts
2
+ // src/lib/filterRichTextField.ts
4
3
  /**
5
4
  * Get allowed nodes types from a rich text or title field custom type model.
6
5
  *
@@ -48,17 +47,20 @@ const filterTextNode = (node, model, allowedNodeTypes) => {
48
47
  };
49
48
  for (let i = 0; i < node.spans.length; i++) {
50
49
  const span = node.spans[i];
51
- if (allowedNodeTypes.includes(span.type)) if (span.type === _prismicio_client.RichTextNodeType.hyperlink) if (!model.config?.allowTargetBlank && span.data.link_type === _prismicio_client.LinkType.Web) filteredNode.spans.push({
52
- ...span,
53
- data: {
54
- ...span.data,
55
- target: void 0
56
- }
57
- });
58
- else filteredNode.spans.push(span);
59
- else if (span.type === _prismicio_client.RichTextNodeType.label) {
60
- if (model.config?.labels?.includes(span.data.label)) filteredNode.spans.push(span);
61
- } else filteredNode.spans.push(span);
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
+ }
62
64
  }
63
65
  return filteredNode;
64
66
  };
@@ -74,13 +76,14 @@ const filterRichTextField = (richTextField, model) => {
74
76
  const allowedNodeTypes = getAllowedNodeTypes(model);
75
77
  for (let i = 0; i < (model.config && "multi" in model.config ? richTextField.length : 1); i++) {
76
78
  const node = richTextField[i];
77
- if (allowedNodeTypes.includes(node.type)) if (node.type === _prismicio_client.RichTextNodeType.image) nodes.push(filterImageNode(node, model));
78
- else if (node.type === _prismicio_client.RichTextNodeType.embed) nodes.push(node);
79
- else nodes.push(filterTextNode(node, model, allowedNodeTypes));
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
+ }
80
84
  }
81
85
  return nodes;
82
86
  };
83
- //#endregion
84
87
  exports.filterRichTextField = filterRichTextField;
85
88
 
86
89
  //# sourceMappingURL=filterRichTextField.cjs.map
@@ -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,EAAE;AAEhD,KAAI,MAAM,QAAQ;AACjB,MAAI,WAAW,MAAM,UAAU,MAAM,OAAO,MAC3C,kBAAiB,KAAK,GAAI,MAAM,OAAO,MAAM,MAAM,IAAI,CAAyB;WACtE,YAAY,MAAM,UAAU,MAAM,OAAO,OACnD,kBAAiB,KAAK,GAAI,MAAM,OAAO,OAAO,MAAM,IAAI,CAAyB;AAGlF,MAAI,MAAM,OAAO,QAAQ,OACxB,kBAAiB,KAAK,QAAQ;;AAIhC,QAAO;;;;;;;;;AAUR,MAAM,mBAAmB,MAAmB,UAAqD;AAChG,KAAI,CAAC,MAAM,QAAQ,oBAAoB,KAAK,QAAQ,cAAcA,kBAAAA,SAAS,IAC1E,QAAO;EACN,GAAG;EACH,QAAQ;GACP,GAAG,KAAK;GACR,QAAQ,KAAA;GACR;EACD;AAGF,QAAO;;;;;;;;;;AAWR,MAAM,kBACL,MACA,OACA,qBACgB;CAChB,MAAM,eAA2B;EAChC,GAAG;EACH,OAAO,EAAE;EACT;AAED,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,MAAM,QAAQ,KAAK;EAC3C,MAAM,OAAO,KAAK,MAAM;AAExB,MAAI,iBAAiB,SAAS,KAAK,KAAK,CACvC,KAAI,KAAK,SAASC,kBAAAA,iBAAiB,UAClC,KAAI,CAAC,MAAM,QAAQ,oBAAoB,KAAK,KAAK,cAAcD,kBAAAA,SAAS,IACvE,cAAa,MAAM,KAAK;GACvB,GAAG;GACH,MAAM;IACL,GAAG,KAAK;IACR,QAAQ,KAAA;IACR;GACD,CAAC;MAEF,cAAa,MAAM,KAAK,KAAK;WAEpB,KAAK,SAASC,kBAAAA,iBAAiB;OACrC,MAAM,QAAQ,QAAQ,SAAS,KAAK,KAAK,MAAM,CAClD,cAAa,MAAM,KAAK,KAAK;QAG9B,cAAa,MAAM,KAAK,KAAK;;AAKhC,QAAO;;;;;;;;;AAUR,MAAa,uBACZ,eACA,UACW;CACX,MAAM,QAAkB,EAAE;CAE1B,MAAM,mBAAmB,oBAAoB,MAAM;AAEnD,MACC,IAAI,IAAI,GAER,KAAK,MAAM,UAAU,WAAW,MAAM,SAAS,cAAc,SAAS,IACtE,KACC;EACD,MAAM,OAAO,cAAc;AAE3B,MAAI,iBAAiB,SAAS,KAAK,KAAK,CACvC,KAAI,KAAK,SAASA,kBAAAA,iBAAiB,MAClC,OAAM,KAAK,gBAAgB,MAAM,MAAM,CAAC;WAC9B,KAAK,SAASA,kBAAAA,iBAAiB,MACzC,OAAM,KAAK,KAAK;MAEhB,OAAM,KAAK,eAAe,MAAM,OAAO,iBAAiB,CAAC;;AAK5D,QAAO"}
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"}