@prismicio/migrate 0.0.1 → 0.0.2-canary.6b4d958
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/errors/PrismicRichTextError.cjs +5 -5
- package/dist/errors/PrismicRichTextError.cjs.map +1 -1
- package/dist/errors/PrismicRichTextError.d.cts +5 -0
- package/dist/errors/PrismicRichTextError.d.cts.map +1 -0
- package/dist/errors/PrismicRichTextError.d.ts +5 -2
- package/dist/errors/PrismicRichTextError.d.ts.map +1 -0
- package/dist/errors/PrismicRichTextError.js +6 -6
- package/dist/errors/PrismicRichTextError.js.map +1 -1
- package/dist/errors/PrismicRichTextSerializerError.cjs +6 -6
- package/dist/errors/PrismicRichTextSerializerError.cjs.map +1 -1
- package/dist/errors/PrismicRichTextSerializerError.d.cts +7 -0
- package/dist/errors/PrismicRichTextSerializerError.d.cts.map +1 -0
- package/dist/errors/PrismicRichTextSerializerError.d.ts +7 -3
- package/dist/errors/PrismicRichTextSerializerError.d.ts.map +1 -0
- package/dist/errors/PrismicRichTextSerializerError.js +6 -6
- package/dist/errors/PrismicRichTextSerializerError.js.map +1 -1
- package/dist/htmlAsRichText.cjs +24 -8
- package/dist/htmlAsRichText.cjs.map +1 -1
- package/dist/htmlAsRichText.d.cts +23 -0
- package/dist/htmlAsRichText.d.cts.map +1 -0
- package/dist/htmlAsRichText.d.ts +14 -69
- package/dist/htmlAsRichText.d.ts.map +1 -0
- package/dist/htmlAsRichText.js +21 -7
- package/dist/htmlAsRichText.js.map +1 -1
- package/dist/index.cjs +6 -8
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -7
- package/dist/lib/RichTextFieldBuilder.cjs +82 -113
- package/dist/lib/RichTextFieldBuilder.cjs.map +1 -1
- package/dist/lib/RichTextFieldBuilder.d.cts +16 -0
- package/dist/lib/RichTextFieldBuilder.d.cts.map +1 -0
- package/dist/lib/RichTextFieldBuilder.d.ts +8 -27
- package/dist/lib/RichTextFieldBuilder.d.ts.map +1 -0
- package/dist/lib/RichTextFieldBuilder.js +82 -113
- package/dist/lib/RichTextFieldBuilder.js.map +1 -1
- package/dist/lib/filterRichTextField.cjs +77 -78
- package/dist/lib/filterRichTextField.cjs.map +1 -1
- package/dist/lib/filterRichTextField.js +77 -79
- package/dist/lib/filterRichTextField.js.map +1 -1
- package/dist/lib/hastSerializerHelpers.cjs +102 -86
- package/dist/lib/hastSerializerHelpers.cjs.map +1 -1
- package/dist/lib/hastSerializerHelpers.js +101 -88
- package/dist/lib/hastSerializerHelpers.js.map +1 -1
- package/dist/lib/hastToRichText.cjs +152 -157
- package/dist/lib/hastToRichText.cjs.map +1 -1
- package/dist/lib/hastToRichText.d.cts +21 -0
- package/dist/lib/hastToRichText.d.cts.map +1 -0
- package/dist/lib/hastToRichText.d.ts +20 -29
- package/dist/lib/hastToRichText.d.ts.map +1 -0
- package/dist/lib/hastToRichText.js +150 -156
- package/dist/lib/hastToRichText.js.map +1 -1
- package/dist/lib/rehypeRichText.cjs +56 -57
- package/dist/lib/rehypeRichText.cjs.map +1 -1
- package/dist/lib/rehypeRichText.d.cts +57 -0
- package/dist/lib/rehypeRichText.d.cts.map +1 -0
- package/dist/lib/rehypeRichText.d.ts +53 -61
- package/dist/lib/rehypeRichText.d.ts.map +1 -0
- package/dist/lib/rehypeRichText.js +52 -55
- package/dist/lib/rehypeRichText.js.map +1 -1
- package/dist/types.d.cts +46 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +30 -41
- package/dist/types.d.ts.map +1 -0
- package/package.json +35 -58
- package/src/htmlAsRichText.ts +22 -49
- package/src/lib/RichTextFieldBuilder.ts +26 -31
- package/src/lib/filterRichTextField.ts +6 -25
- package/src/lib/hastSerializerHelpers.ts +4 -17
- package/src/lib/hastToRichText.ts +44 -66
- package/src/lib/rehypeRichText.ts +88 -102
- package/src/types.ts +24 -33
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/filterRichTextField.d.ts +0 -10
- 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 ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.__toESM = __toESM;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
//#region src/errors/PrismicRichTextError.ts
|
|
2
|
+
var PrismicRichTextError = class extends Error {};
|
|
3
|
+
//#endregion
|
|
5
4
|
exports.PrismicRichTextError = PrismicRichTextError;
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=PrismicRichTextError.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichTextError.cjs","sources":["
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicRichTextError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":";cAAa,oBAAA,SAA6B,KAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicRichTextError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextError.ts"],"mappings":";cAAa,oBAAA,SAA6B,KAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
}
|
|
3
|
-
|
|
4
|
-
|
|
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":["
|
|
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,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=PrismicRichTextSerializerError.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichTextSerializerError.cjs","sources":["
|
|
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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
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 };
|
|
7
|
+
//# sourceMappingURL=PrismicRichTextSerializerError.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicRichTextSerializerError.d.cts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";;;cAEa,8BAAA,SAAuC,oBAAA"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import { PrismicRichTextError } from "./PrismicRichTextError";
|
|
2
|
-
|
|
3
|
-
|
|
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 };
|
|
7
|
+
//# sourceMappingURL=PrismicRichTextSerializerError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicRichTextSerializerError.d.ts","names":[],"sources":["../../src/errors/PrismicRichTextSerializerError.ts"],"mappings":";;;cAEa,8BAAA,SAAuC,oBAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PrismicRichTextError } from "./PrismicRichTextError.js";
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
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":["
|
|
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"}
|
package/dist/htmlAsRichText.cjs
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=htmlAsRichText.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlAsRichText.cjs","sources":["
|
|
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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
6
|
+
/** Configuration that determines the output of {@link htmlAsRichText}. */
|
|
7
|
+
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
|
+
declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { htmlAsRichText };
|
|
23
|
+
//# sourceMappingURL=htmlAsRichText.d.cts.map
|
|
@@ -0,0 +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"}
|
package/dist/htmlAsRichText.d.ts
CHANGED
|
@@ -1,78 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
*/
|
|
61
|
-
export type HTMLAsRichTextConfig = RehypeRichTextConfig;
|
|
62
|
-
/**
|
|
63
|
-
* The return type of {@link htmlAsRichText}.
|
|
64
|
-
*/
|
|
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
|
|
6
|
+
/** Configuration that determines the output of {@link htmlAsRichText}. */
|
|
7
|
+
type HTMLAsRichTextConfig = RehypeRichTextConfig;
|
|
8
|
+
/** The return type of {@link htmlAsRichText}. */
|
|
65
9
|
type HTMLAsRichTextReturnType = {
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
78
|
-
|
|
20
|
+
declare const htmlAsRichText: (html: string, config?: HTMLAsRichTextConfig) => HTMLAsRichTextReturnType;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { htmlAsRichText };
|
|
23
|
+
//# sourceMappingURL=htmlAsRichText.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/htmlAsRichText.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
//#
|
|
22
|
+
//#endregion
|
|
23
|
+
export { htmlAsRichText };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=htmlAsRichText.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlAsRichText.js","sources":["
|
|
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"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
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;
|
package/dist/index.d.cts
ADDED
|
@@ -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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
PrismicRichTextSerializerError,
|
|
7
|
-
htmlAsRichText
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
3
|
+
import { htmlAsRichText } from "./htmlAsRichText.js";
|
|
4
|
+
export { PrismicRichTextError, PrismicRichTextSerializerError, htmlAsRichText };
|