@prismicio/migrate 0.0.1 → 0.0.2-canary.2da5f89

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 (77) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  2. package/dist/errors/PrismicRichTextError.cjs +5 -5
  3. package/dist/errors/PrismicRichTextError.cjs.map +1 -1
  4. package/dist/errors/PrismicRichTextError.d.cts +4 -0
  5. package/dist/errors/PrismicRichTextError.d.cts.map +1 -0
  6. package/dist/errors/PrismicRichTextError.d.ts +4 -2
  7. package/dist/errors/PrismicRichTextError.d.ts.map +1 -0
  8. package/dist/errors/PrismicRichTextError.js +6 -6
  9. package/dist/errors/PrismicRichTextError.js.map +1 -1
  10. package/dist/errors/PrismicRichTextSerializerError.cjs +6 -6
  11. package/dist/errors/PrismicRichTextSerializerError.cjs.map +1 -1
  12. package/dist/errors/PrismicRichTextSerializerError.d.cts +5 -0
  13. package/dist/errors/PrismicRichTextSerializerError.d.cts.map +1 -0
  14. package/dist/errors/PrismicRichTextSerializerError.d.ts +5 -3
  15. package/dist/errors/PrismicRichTextSerializerError.d.ts.map +1 -0
  16. package/dist/errors/PrismicRichTextSerializerError.js +6 -6
  17. package/dist/errors/PrismicRichTextSerializerError.js.map +1 -1
  18. package/dist/htmlAsRichText.cjs +24 -8
  19. package/dist/htmlAsRichText.cjs.map +1 -1
  20. package/dist/htmlAsRichText.d.cts +22 -0
  21. package/dist/htmlAsRichText.d.cts.map +1 -0
  22. package/dist/htmlAsRichText.d.ts +11 -67
  23. package/dist/htmlAsRichText.d.ts.map +1 -0
  24. package/dist/htmlAsRichText.js +21 -7
  25. package/dist/htmlAsRichText.js.map +1 -1
  26. package/dist/index.cjs +6 -8
  27. package/dist/index.d.cts +5 -0
  28. package/dist/index.d.ts +5 -4
  29. package/dist/index.js +2 -7
  30. package/dist/lib/RichTextFieldBuilder.cjs +82 -113
  31. package/dist/lib/RichTextFieldBuilder.cjs.map +1 -1
  32. package/dist/lib/RichTextFieldBuilder.d.cts +14 -0
  33. package/dist/lib/RichTextFieldBuilder.d.cts.map +1 -0
  34. package/dist/lib/RichTextFieldBuilder.d.ts +5 -26
  35. package/dist/lib/RichTextFieldBuilder.d.ts.map +1 -0
  36. package/dist/lib/RichTextFieldBuilder.js +82 -113
  37. package/dist/lib/RichTextFieldBuilder.js.map +1 -1
  38. package/dist/lib/filterRichTextField.cjs +81 -78
  39. package/dist/lib/filterRichTextField.cjs.map +1 -1
  40. package/dist/lib/filterRichTextField.js +82 -79
  41. package/dist/lib/filterRichTextField.js.map +1 -1
  42. package/dist/lib/hastSerializerHelpers.cjs +101 -86
  43. package/dist/lib/hastSerializerHelpers.cjs.map +1 -1
  44. package/dist/lib/hastSerializerHelpers.js +101 -88
  45. package/dist/lib/hastSerializerHelpers.js.map +1 -1
  46. package/dist/lib/hastToRichText.cjs +151 -157
  47. package/dist/lib/hastToRichText.cjs.map +1 -1
  48. package/dist/lib/hastToRichText.d.cts +21 -0
  49. package/dist/lib/hastToRichText.d.cts.map +1 -0
  50. package/dist/lib/hastToRichText.d.ts +19 -28
  51. package/dist/lib/hastToRichText.d.ts.map +1 -0
  52. package/dist/lib/hastToRichText.js +150 -156
  53. package/dist/lib/hastToRichText.js.map +1 -1
  54. package/dist/lib/rehypeRichText.cjs +57 -57
  55. package/dist/lib/rehypeRichText.cjs.map +1 -1
  56. package/dist/lib/rehypeRichText.d.cts +58 -0
  57. package/dist/lib/rehypeRichText.d.cts.map +1 -0
  58. package/dist/lib/rehypeRichText.d.ts +52 -59
  59. package/dist/lib/rehypeRichText.d.ts.map +1 -0
  60. package/dist/lib/rehypeRichText.js +53 -55
  61. package/dist/lib/rehypeRichText.js.map +1 -1
  62. package/dist/types.d.cts +47 -0
  63. package/dist/types.d.cts.map +1 -0
  64. package/dist/types.d.ts +29 -39
  65. package/dist/types.d.ts.map +1 -0
  66. package/package.json +40 -63
  67. package/src/htmlAsRichText.ts +22 -49
  68. package/src/lib/RichTextFieldBuilder.ts +26 -31
  69. package/src/lib/filterRichTextField.ts +6 -25
  70. package/src/lib/hastSerializerHelpers.ts +4 -17
  71. package/src/lib/hastToRichText.ts +17 -39
  72. package/src/lib/rehypeRichText.ts +88 -102
  73. package/src/types.ts +24 -33
  74. package/dist/index.cjs.map +0 -1
  75. package/dist/index.js.map +0 -1
  76. package/dist/lib/filterRichTextField.d.ts +0 -10
  77. package/dist/lib/hastSerializerHelpers.d.ts +0 -28
@@ -0,0 +1,23 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
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
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ exports.__toESM = __toESM;
@@ -1,6 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- class PrismicRichTextError extends Error {
4
- }
1
+ //#region src/errors/PrismicRichTextError.ts
2
+ var PrismicRichTextError = class extends Error {};
3
+ //#endregion
5
4
  exports.PrismicRichTextError = PrismicRichTextError;
6
- //# sourceMappingURL=PrismicRichTextError.cjs.map
5
+
6
+ //# sourceMappingURL=PrismicRichTextError.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextError.cjs","sources":["../../../src/errors/PrismicRichTextError.ts"],"sourcesContent":["export class PrismicRichTextError extends Error {}\n"],"names":[],"mappings":";;AAAM,MAAO,6BAA6B,MAAK;AAAG;;"}
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"}
@@ -0,0 +1,4 @@
1
+ //#region src/errors/PrismicRichTextError.d.ts
2
+ export declare class PrismicRichTextError extends Error {}
3
+ //#endregion
4
+ //# sourceMappingURL=PrismicRichTextError.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicRichTextError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":";qBAAa,6BAA6B"}
@@ -1,2 +1,4 @@
1
- export declare class PrismicRichTextError extends Error {
2
- }
1
+ //#region src/errors/PrismicRichTextError.d.ts
2
+ export declare class PrismicRichTextError extends Error {}
3
+ //#endregion
4
+ //# sourceMappingURL=PrismicRichTextError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicRichTextError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":";qBAAa,6BAA6B"}
@@ -1,6 +1,6 @@
1
- class PrismicRichTextError extends Error {
2
- }
3
- export {
4
- PrismicRichTextError
5
- };
6
- //# sourceMappingURL=PrismicRichTextError.js.map
1
+ //#region src/errors/PrismicRichTextError.ts
2
+ var PrismicRichTextError = class extends Error {};
3
+ //#endregion
4
+ export { PrismicRichTextError };
5
+
6
+ //# sourceMappingURL=PrismicRichTextError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextError.js","sources":["../../../src/errors/PrismicRichTextError.ts"],"sourcesContent":["export class PrismicRichTextError extends Error {}\n"],"names":[],"mappings":"AAAM,MAAO,6BAA6B,MAAK;AAAG;"}
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,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const PrismicRichTextError = require("./PrismicRichTextError.cjs");
4
- class PrismicRichTextSerializerError extends PrismicRichTextError.PrismicRichTextError {
5
- }
1
+ const require_PrismicRichTextError = require("./PrismicRichTextError.cjs");
2
+ //#region src/errors/PrismicRichTextSerializerError.ts
3
+ var PrismicRichTextSerializerError = class extends require_PrismicRichTextError.PrismicRichTextError {};
4
+ //#endregion
6
5
  exports.PrismicRichTextSerializerError = PrismicRichTextSerializerError;
7
- //# sourceMappingURL=PrismicRichTextSerializerError.cjs.map
6
+
7
+ //# sourceMappingURL=PrismicRichTextSerializerError.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextSerializerError.cjs","sources":["../../../src/errors/PrismicRichTextSerializerError.ts"],"sourcesContent":["import { PrismicRichTextError } from \"./PrismicRichTextError\"\n\nexport class PrismicRichTextSerializerError extends PrismicRichTextError {}\n"],"names":["PrismicRichTextError"],"mappings":";;;AAEM,MAAO,uCAAuCA,qBAAAA,qBAAoB;AAAG;;"}
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"}
@@ -0,0 +1,5 @@
1
+ import { PrismicRichTextError } from "./PrismicRichTextError.cjs";
2
+ //#region src/errors/PrismicRichTextSerializerError.d.ts
3
+ export declare class PrismicRichTextSerializerError extends PrismicRichTextError {}
4
+ //#endregion
5
+ //# sourceMappingURL=PrismicRichTextSerializerError.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicRichTextSerializerError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";;qBAEa,uCAAuC"}
@@ -1,3 +1,5 @@
1
- import { PrismicRichTextError } from "./PrismicRichTextError";
2
- export declare class PrismicRichTextSerializerError extends PrismicRichTextError {
3
- }
1
+ import { PrismicRichTextError } from "./PrismicRichTextError.js";
2
+ //#region src/errors/PrismicRichTextSerializerError.d.ts
3
+ export declare class PrismicRichTextSerializerError extends PrismicRichTextError {}
4
+ //#endregion
5
+ //# sourceMappingURL=PrismicRichTextSerializerError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicRichTextSerializerError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";;qBAEa,uCAAuC"}
@@ -1,7 +1,7 @@
1
1
  import { PrismicRichTextError } from "./PrismicRichTextError.js";
2
- class PrismicRichTextSerializerError extends PrismicRichTextError {
3
- }
4
- export {
5
- PrismicRichTextSerializerError
6
- };
7
- //# sourceMappingURL=PrismicRichTextSerializerError.js.map
2
+ //#region src/errors/PrismicRichTextSerializerError.ts
3
+ var PrismicRichTextSerializerError = class extends PrismicRichTextError {};
4
+ //#endregion
5
+ export { PrismicRichTextSerializerError };
6
+
7
+ //# sourceMappingURL=PrismicRichTextSerializerError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichTextSerializerError.js","sources":["../../../src/errors/PrismicRichTextSerializerError.ts"],"sourcesContent":["import { PrismicRichTextError } from \"./PrismicRichTextError\"\n\nexport class PrismicRichTextSerializerError extends PrismicRichTextError {}\n"],"names":[],"mappings":";AAEM,MAAO,uCAAuC,qBAAoB;AAAG;"}
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"}
@@ -1,11 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const rehypeParse = require("rehype-parse");
4
- const unified = require("unified");
5
- const rehypeRichText = require("./lib/rehypeRichText.cjs");
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_rehypeRichText = require("./lib/rehypeRichText.cjs");
3
+ let rehype_parse = require("rehype-parse");
4
+ rehype_parse = require_runtime.__toESM(rehype_parse, 1);
5
+ let unified = require("unified");
6
+ //#region src/htmlAsRichText.ts
7
+ /**
8
+ * Converts an HTML string to a rich text field.
9
+ *
10
+ * @param html - An HTML string.
11
+ * @param config - Configuration that determines the output the function.
12
+ * @returns `html` as rich text.
13
+ */
6
14
  const htmlAsRichText = (html, config) => {
7
- const { result, messages } = unified.unified().use(rehypeParse, { emitParseErrors: true, missingDoctype: 0 }).use(rehypeRichText.rehypeRichText, config).processSync(html);
8
- return { result, warnings: messages.map((message) => message.toString()) };
15
+ const { result, messages } = (0, unified.unified)().use(rehype_parse.default, {
16
+ emitParseErrors: true,
17
+ missingDoctype: 0
18
+ }).use(require_rehypeRichText.rehypeRichText, config).processSync(html);
19
+ return {
20
+ result,
21
+ warnings: messages.map((message) => message.toString())
22
+ };
9
23
  };
24
+ //#endregion
10
25
  exports.htmlAsRichText = htmlAsRichText;
11
- //# sourceMappingURL=htmlAsRichText.cjs.map
26
+
27
+ //# sourceMappingURL=htmlAsRichText.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"htmlAsRichText.cjs","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 {\n\tRTInlineNode,\n\tRTNode,\n\tRichTextField,\n\tRichTextNodeTypes,\n} from \"@prismicio/client\"\nimport type { Element } from \"hast\"\nimport rehypeParse from \"rehype-parse\"\nimport { unified } from \"unified\"\n\nimport type { RTPartialInlineNode } from \"./lib/RichTextFieldBuilder\"\nimport type { RehypeRichTextConfig } from \"./lib/rehypeRichText\"\nimport { rehypeRichText } from \"./lib/rehypeRichText\"\n\n/**\n * A shorthand definition for {@link RichTextHTMLMapSerializer} rich text node\n * types.\n *\n * @remarks\n * The `label` rich text node type is not available as is. Use an object\n * containing your label name to convert to label nodes instead. For example:\n * `u: { label: \"underline\" }`\n * @remarks\n * The `span` rich text node type is not available as it is not relevant in the\n * context of going from HTML to Prismic rich text.\n */\nexport type RichTextHTMLMapSerializerShorthand =\n\t| Exclude<RichTextNodeTypes, \"label\" | \"span\">\n\t| { label: string }\n\n/**\n * The payload provided to a {@link RichTextHTMLMapSerializerFunction}.\n */\ntype RichTextHTMLMapSerializerFunctionPayload = {\n\t/**\n\t * The hast {@link Element} node to serialize.\n\t */\n\tnode: Element\n\n\t/**\n\t * Additional context information to help with the serialization.\n\t */\n\tcontext: {\n\t\t/**\n\t\t * The list type of the last list node encountered if any.\n\t\t */\n\t\tlistType?: \"group-list-item\" | \"group-o-list-item\"\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a\n * {@link RichTextHTMLMapSerializerShorthand} or a rich text node.\n *\n * @remarks\n * Serializing to a rich text node directly is not recommended and is only\n * available as an escape hatch. Prefer returning a\n * {@link RichTextHTMLMapSerializerShorthand} instead.\n */\nexport type RichTextHTMLMapSerializerFunction = (\n\tpayload: RichTextHTMLMapSerializerFunctionPayload,\n) =>\n\t| RichTextHTMLMapSerializerShorthand\n\t| RTNode\n\t| RTInlineNode\n\t| RTPartialInlineNode\n\t| undefined\n\n/**\n * Serializes a hast {@link Element} node matching the given HTML tag name or CSS\n * selector to a Prismic rich text node.\n *\n * @remarks\n * This serializer is used to serialize HTML to Prismic rich text. When\n * serializing Prismic rich text to HTML with {@link asHTML}, use the\n * {@link HTMLRichTextMapSerializer} type instead.\n */\nexport type RichTextHTMLMapSerializer = Record<\n\tstring,\n\tRichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction\n>\n\n/**\n * Configuration that determines the output of {@link htmlAsRichText}.\n */\nexport type HTMLAsRichTextConfig = RehypeRichTextConfig\n\n/**\n * The return type of {@link htmlAsRichText}.\n */\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 *\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"],"names":["unified","rehypeRichText"],"mappings":";;;;;AA0Ga,MAAA,iBAAiB,CAC7B,MACA,WAC6B;AACvB,QAAA,EAAE,QAAQ,aAAaA,QAAAA,QAC3B,EAAA,IAAI,aAAa,EAAE,iBAAiB,MAAM,gBAAgB,EAAA,CAAG,EAC7D,IAAIC,eAAAA,gBAAgB,MAAM,EAC1B,YAAY,IAAI;AAEX,SAAA,EAAE,QAAQ,UAAU,SAAS,IAAI,CAAC,YAAY,QAAQ,SAAU,CAAA;AACxE;;"}
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"}
@@ -0,0 +1,22 @@
1
+ import "./lib/RichTextFieldBuilder.cjs";
2
+ import { RehypeRichTextConfig } from "./lib/rehypeRichText.cjs";
3
+ import { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from "@prismicio/client";
4
+ import { Element } from "hast";
5
+ //#region src/htmlAsRichText.d.ts
6
+ /** Configuration that determines the output of {@link htmlAsRichText}. */
7
+ export type HTMLAsRichTextConfig = RehypeRichTextConfig;
8
+ /** The return type of {@link htmlAsRichText}. */
9
+ type HTMLAsRichTextReturnType = {
10
+ result: RichTextField;
11
+ warnings: string[];
12
+ };
13
+ /**
14
+ * Converts an HTML string to a rich text field.
15
+ *
16
+ * @param html - An HTML string.
17
+ * @param config - Configuration that determines the output the function.
18
+ * @returns `html` as rich text.
19
+ */
20
+ export declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
21
+ //#endregion
22
+ //# sourceMappingURL=htmlAsRichText.d.cts.map
@@ -0,0 +1 @@
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,78 +1,22 @@
1
- import type { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from "@prismicio/client";
2
- import type { Element } from "hast";
3
- import type { RTPartialInlineNode } from "./lib/RichTextFieldBuilder";
4
- import type { RehypeRichTextConfig } from "./lib/rehypeRichText";
5
- /**
6
- * A shorthand definition for {@link RichTextHTMLMapSerializer} rich text node
7
- * types.
8
- *
9
- * @remarks
10
- * The `label` rich text node type is not available as is. Use an object
11
- * containing your label name to convert to label nodes instead. For example:
12
- * `u: { label: "underline" }`
13
- * @remarks
14
- * The `span` rich text node type is not available as it is not relevant in the
15
- * context of going from HTML to Prismic rich text.
16
- */
17
- export type RichTextHTMLMapSerializerShorthand = Exclude<RichTextNodeTypes, "label" | "span"> | {
18
- label: string;
19
- };
20
- /**
21
- * The payload provided to a {@link RichTextHTMLMapSerializerFunction}.
22
- */
23
- type RichTextHTMLMapSerializerFunctionPayload = {
24
- /**
25
- * The hast {@link Element} node to serialize.
26
- */
27
- node: Element;
28
- /**
29
- * Additional context information to help with the serialization.
30
- */
31
- context: {
32
- /**
33
- * The list type of the last list node encountered if any.
34
- */
35
- listType?: "group-list-item" | "group-o-list-item";
36
- };
37
- };
38
- /**
39
- * Serializes a hast {@link Element} node to a
40
- * {@link RichTextHTMLMapSerializerShorthand} or a rich text node.
41
- *
42
- * @remarks
43
- * Serializing to a rich text node directly is not recommended and is only
44
- * available as an escape hatch. Prefer returning a
45
- * {@link RichTextHTMLMapSerializerShorthand} instead.
46
- */
47
- export type RichTextHTMLMapSerializerFunction = (payload: RichTextHTMLMapSerializerFunctionPayload) => RichTextHTMLMapSerializerShorthand | RTNode | RTInlineNode | RTPartialInlineNode | undefined;
48
- /**
49
- * Serializes a hast {@link Element} node matching the given HTML tag name or CSS
50
- * selector to a Prismic rich text node.
51
- *
52
- * @remarks
53
- * This serializer is used to serialize HTML to Prismic rich text. When
54
- * serializing Prismic rich text to HTML with {@link asHTML}, use the
55
- * {@link HTMLRichTextMapSerializer} type instead.
56
- */
57
- export type RichTextHTMLMapSerializer = Record<string, RichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction>;
58
- /**
59
- * Configuration that determines the output of {@link htmlAsRichText}.
60
- */
1
+ import "./lib/RichTextFieldBuilder.js";
2
+ import { RehypeRichTextConfig } from "./lib/rehypeRichText.js";
3
+ import { RTInlineNode, RTNode, RichTextField, RichTextNodeTypes } from "@prismicio/client";
4
+ import { Element } from "hast";
5
+ //#region src/htmlAsRichText.d.ts
6
+ /** Configuration that determines the output of {@link htmlAsRichText}. */
61
7
  export type HTMLAsRichTextConfig = RehypeRichTextConfig;
62
- /**
63
- * The return type of {@link htmlAsRichText}.
64
- */
8
+ /** The return type of {@link htmlAsRichText}. */
65
9
  type HTMLAsRichTextReturnType = {
66
- result: RichTextField;
67
- warnings: string[];
10
+ result: RichTextField;
11
+ warnings: string[];
68
12
  };
69
13
  /**
70
14
  * Converts an HTML string to a rich text field.
71
15
  *
72
16
  * @param html - An HTML string.
73
17
  * @param config - Configuration that determines the output the function.
74
- *
75
18
  * @returns `html` as rich text.
76
19
  */
77
20
  export declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
78
- export {};
21
+ //#endregion
22
+ //# sourceMappingURL=htmlAsRichText.d.ts.map
@@ -0,0 +1 @@
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,11 +1,25 @@
1
+ import { rehypeRichText } from "./lib/rehypeRichText.js";
1
2
  import rehypeParse from "rehype-parse";
2
3
  import { unified } from "unified";
3
- import { rehypeRichText } from "./lib/rehypeRichText.js";
4
+ //#region src/htmlAsRichText.ts
5
+ /**
6
+ * Converts an HTML string to a rich text field.
7
+ *
8
+ * @param html - An HTML string.
9
+ * @param config - Configuration that determines the output the function.
10
+ * @returns `html` as rich text.
11
+ */
4
12
  const htmlAsRichText = (html, config) => {
5
- const { result, messages } = unified().use(rehypeParse, { emitParseErrors: true, missingDoctype: 0 }).use(rehypeRichText, config).processSync(html);
6
- return { result, warnings: messages.map((message) => message.toString()) };
7
- };
8
- export {
9
- htmlAsRichText
13
+ const { result, messages } = unified().use(rehypeParse, {
14
+ emitParseErrors: true,
15
+ missingDoctype: 0
16
+ }).use(rehypeRichText, config).processSync(html);
17
+ return {
18
+ result,
19
+ warnings: messages.map((message) => message.toString())
20
+ };
10
21
  };
11
- //# sourceMappingURL=htmlAsRichText.js.map
22
+ //#endregion
23
+ export { htmlAsRichText };
24
+
25
+ //# sourceMappingURL=htmlAsRichText.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"htmlAsRichText.js","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 {\n\tRTInlineNode,\n\tRTNode,\n\tRichTextField,\n\tRichTextNodeTypes,\n} from \"@prismicio/client\"\nimport type { Element } from \"hast\"\nimport rehypeParse from \"rehype-parse\"\nimport { unified } from \"unified\"\n\nimport type { RTPartialInlineNode } from \"./lib/RichTextFieldBuilder\"\nimport type { RehypeRichTextConfig } from \"./lib/rehypeRichText\"\nimport { rehypeRichText } from \"./lib/rehypeRichText\"\n\n/**\n * A shorthand definition for {@link RichTextHTMLMapSerializer} rich text node\n * types.\n *\n * @remarks\n * The `label` rich text node type is not available as is. Use an object\n * containing your label name to convert to label nodes instead. For example:\n * `u: { label: \"underline\" }`\n * @remarks\n * The `span` rich text node type is not available as it is not relevant in the\n * context of going from HTML to Prismic rich text.\n */\nexport type RichTextHTMLMapSerializerShorthand =\n\t| Exclude<RichTextNodeTypes, \"label\" | \"span\">\n\t| { label: string }\n\n/**\n * The payload provided to a {@link RichTextHTMLMapSerializerFunction}.\n */\ntype RichTextHTMLMapSerializerFunctionPayload = {\n\t/**\n\t * The hast {@link Element} node to serialize.\n\t */\n\tnode: Element\n\n\t/**\n\t * Additional context information to help with the serialization.\n\t */\n\tcontext: {\n\t\t/**\n\t\t * The list type of the last list node encountered if any.\n\t\t */\n\t\tlistType?: \"group-list-item\" | \"group-o-list-item\"\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a\n * {@link RichTextHTMLMapSerializerShorthand} or a rich text node.\n *\n * @remarks\n * Serializing to a rich text node directly is not recommended and is only\n * available as an escape hatch. Prefer returning a\n * {@link RichTextHTMLMapSerializerShorthand} instead.\n */\nexport type RichTextHTMLMapSerializerFunction = (\n\tpayload: RichTextHTMLMapSerializerFunctionPayload,\n) =>\n\t| RichTextHTMLMapSerializerShorthand\n\t| RTNode\n\t| RTInlineNode\n\t| RTPartialInlineNode\n\t| undefined\n\n/**\n * Serializes a hast {@link Element} node matching the given HTML tag name or CSS\n * selector to a Prismic rich text node.\n *\n * @remarks\n * This serializer is used to serialize HTML to Prismic rich text. When\n * serializing Prismic rich text to HTML with {@link asHTML}, use the\n * {@link HTMLRichTextMapSerializer} type instead.\n */\nexport type RichTextHTMLMapSerializer = Record<\n\tstring,\n\tRichTextHTMLMapSerializerShorthand | RichTextHTMLMapSerializerFunction\n>\n\n/**\n * Configuration that determines the output of {@link htmlAsRichText}.\n */\nexport type HTMLAsRichTextConfig = RehypeRichTextConfig\n\n/**\n * The return type of {@link htmlAsRichText}.\n */\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 *\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"],"names":[],"mappings":";;;AA0Ga,MAAA,iBAAiB,CAC7B,MACA,WAC6B;AACvB,QAAA,EAAE,QAAQ,aAAa,QAC3B,EAAA,IAAI,aAAa,EAAE,iBAAiB,MAAM,gBAAgB,EAAA,CAAG,EAC7D,IAAI,gBAAgB,MAAM,EAC1B,YAAY,IAAI;AAEX,SAAA,EAAE,QAAQ,UAAU,SAAS,IAAI,CAAC,YAAY,QAAQ,SAAU,CAAA;AACxE;"}
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,9 +1,7 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const htmlAsRichText = require("./htmlAsRichText.cjs");
4
- const PrismicRichTextError = require("./errors/PrismicRichTextError.cjs");
5
- const PrismicRichTextSerializerError = require("./errors/PrismicRichTextSerializerError.cjs");
6
- exports.htmlAsRichText = htmlAsRichText.htmlAsRichText;
7
- exports.PrismicRichTextError = PrismicRichTextError.PrismicRichTextError;
8
- exports.PrismicRichTextSerializerError = PrismicRichTextSerializerError.PrismicRichTextSerializerError;
9
- //# sourceMappingURL=index.cjs.map
2
+ const require_PrismicRichTextError = require("./errors/PrismicRichTextError.cjs");
3
+ const require_PrismicRichTextSerializerError = require("./errors/PrismicRichTextSerializerError.cjs");
4
+ const require_htmlAsRichText = require("./htmlAsRichText.cjs");
5
+ exports.PrismicRichTextError = require_PrismicRichTextError.PrismicRichTextError;
6
+ exports.PrismicRichTextSerializerError = require_PrismicRichTextSerializerError.PrismicRichTextSerializerError;
7
+ exports.htmlAsRichText = require_htmlAsRichText.htmlAsRichText;
@@ -0,0 +1,5 @@
1
+ import { RichTextHTMLMapSerializer } from "./types.cjs";
2
+ import { htmlAsRichText } from "./htmlAsRichText.cjs";
3
+ import { PrismicRichTextError } from "./errors/PrismicRichTextError.cjs";
4
+ import { PrismicRichTextSerializerError } from "./errors/PrismicRichTextSerializerError.cjs";
5
+ export { PrismicRichTextError, PrismicRichTextSerializerError, type RichTextHTMLMapSerializer, htmlAsRichText };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { htmlAsRichText } from "./htmlAsRichText";
2
- export type { RichTextHTMLMapSerializer } from "./types";
3
- export { PrismicRichTextError } from "./errors/PrismicRichTextError";
4
- export { PrismicRichTextSerializerError } from "./errors/PrismicRichTextSerializerError";
1
+ import { RichTextHTMLMapSerializer } from "./types.js";
2
+ import { htmlAsRichText } from "./htmlAsRichText.js";
3
+ import { PrismicRichTextError } from "./errors/PrismicRichTextError.js";
4
+ import { PrismicRichTextSerializerError } from "./errors/PrismicRichTextSerializerError.js";
5
+ export { PrismicRichTextError, PrismicRichTextSerializerError, type RichTextHTMLMapSerializer, htmlAsRichText };
package/dist/index.js CHANGED
@@ -1,9 +1,4 @@
1
- import { htmlAsRichText } from "./htmlAsRichText.js";
2
1
  import { PrismicRichTextError } from "./errors/PrismicRichTextError.js";
3
2
  import { PrismicRichTextSerializerError } from "./errors/PrismicRichTextSerializerError.js";
4
- export {
5
- PrismicRichTextError,
6
- PrismicRichTextSerializerError,
7
- htmlAsRichText
8
- };
9
- //# sourceMappingURL=index.js.map
3
+ import { htmlAsRichText } from "./htmlAsRichText.js";
4
+ export { PrismicRichTextError, PrismicRichTextSerializerError, htmlAsRichText };