@prismicio/migrate 0.0.1 → 0.0.2-canary.3e6d6e6

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 +5 -0
  5. package/dist/errors/PrismicRichTextError.d.cts.map +1 -0
  6. package/dist/errors/PrismicRichTextError.d.ts +5 -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 +6 -0
  13. package/dist/errors/PrismicRichTextSerializerError.d.cts.map +1 -0
  14. package/dist/errors/PrismicRichTextSerializerError.d.ts +6 -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 +23 -0
  21. package/dist/htmlAsRichText.d.cts.map +1 -0
  22. package/dist/htmlAsRichText.d.ts +14 -69
  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 +15 -0
  33. package/dist/lib/RichTextFieldBuilder.d.cts.map +1 -0
  34. package/dist/lib/RichTextFieldBuilder.d.ts +7 -27
  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 +76 -78
  39. package/dist/lib/filterRichTextField.cjs.map +1 -1
  40. package/dist/lib/filterRichTextField.js +77 -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 +22 -0
  49. package/dist/lib/hastToRichText.d.cts.map +1 -0
  50. package/dist/lib/hastToRichText.d.ts +21 -29
  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 +59 -0
  57. package/dist/lib/rehypeRichText.d.cts.map +1 -0
  58. package/dist/lib/rehypeRichText.d.ts +54 -60
  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 +48 -0
  63. package/dist/types.d.cts.map +1 -0
  64. package/dist/types.d.ts +32 -41
  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
@@ -11,20 +11,14 @@ import { toString } from "hast-util-to-string"
11
11
  import { visit } from "unist-util-visit"
12
12
  import type { VFile } from "vfile"
13
13
 
14
+ import { PrismicRichTextSerializerError } from "../errors/PrismicRichTextSerializerError"
14
15
  import type {
15
16
  RichTextHTMLMapSerializer,
16
17
  RichTextHTMLMapSerializerFunction,
17
18
  RichTextHTMLMapSerializerShorthand,
18
19
  } from "../types"
19
-
20
- import { PrismicRichTextSerializerError } from "../errors/PrismicRichTextSerializerError"
21
-
20
+ import { serializeEmbed, serializeImage, serializeSpan } from "./hastSerializerHelpers"
22
21
  import { RichTextFieldBuilder } from "./RichTextFieldBuilder"
23
- import {
24
- serializeEmbed,
25
- serializeImage,
26
- serializeSpan,
27
- } from "./hastSerializerHelpers"
28
22
 
29
23
  /**
30
24
  * Pick keys from a type, distributing the operation over a union.
@@ -33,10 +27,9 @@ import {
33
27
  *
34
28
  * @see https://github.com/sindresorhus/type-fest/blob/8a45ba048767aaffcebc7d190172d814a739feb0/source/distributed-pick.d.ts
35
29
  */
36
- type DistributedPick<
37
- ObjectType,
38
- KeyType extends keyof ObjectType,
39
- > = ObjectType extends unknown ? Pick<ObjectType, KeyType> : never
30
+ type DistributedPick<ObjectType, KeyType extends keyof ObjectType> = ObjectType extends unknown
31
+ ? Pick<ObjectType, KeyType>
32
+ : never
40
33
 
41
34
  const DEFAULT_SERIALIZER: RichTextHTMLMapSerializer = {
42
35
  h1: "heading1",
@@ -49,8 +42,7 @@ const DEFAULT_SERIALIZER: RichTextHTMLMapSerializer = {
49
42
  pre: "preformatted",
50
43
  strong: "strong",
51
44
  em: "em",
52
- li: ({ context }) =>
53
- context.listType === "group-o-list-item" ? "o-list-item" : "list-item",
45
+ li: ({ context }) => (context.listType === "group-o-list-item" ? "o-list-item" : "list-item"),
54
46
  ul: "group-list-item",
55
47
  ol: "group-o-list-item",
56
48
  img: "image",
@@ -61,13 +53,11 @@ const DEFAULT_SERIALIZER: RichTextHTMLMapSerializer = {
61
53
  const VFILE_RULE = "failed-to-serialize-node"
62
54
  const VFILE_SOURCE = "prismic"
63
55
 
64
- /**
65
- * Configuration that determines the output of `toRichText`.
66
- */
56
+ /** Configuration that determines the output of `toRichText`. */
67
57
  export type HASTToRichTextConfig = {
68
58
  /**
69
- * An optional HTML to rich text serializer. Will be merged with the default
70
- * HTML to rich text serializer.
59
+ * An optional HTML to rich text serializer. Will be merged with the default HTML to rich text
60
+ * serializer.
71
61
  */
72
62
  serializer?: RichTextHTMLMapSerializer
73
63
 
@@ -85,7 +75,6 @@ export type HASTToRichTextConfig = {
85
75
  * @param tree - The hast tree to transform.
86
76
  * @param file - The vfile to attach warnings to.
87
77
  * @param config - Configuration that determines the output of the function.
88
- *
89
78
  * @returns The rich text field equivalent of the provided hast tree.
90
79
  */
91
80
  export const hastToRichText = (
@@ -107,8 +96,7 @@ export const hastToRichText = (
107
96
 
108
97
  // Keep track of the last list type to know whether we need to append
109
98
  // `list-item` or `o-list-item` nodes.
110
- let lastListType: "group-list-item" | "group-o-list-item" | undefined =
111
- undefined
99
+ let lastListType: "group-list-item" | "group-o-list-item" | undefined = undefined
112
100
 
113
101
  visit(tree, (node) => {
114
102
  if (node.type === "element") {
@@ -116,7 +104,7 @@ export const hastToRichText = (
116
104
  if (node.tagName === "br") {
117
105
  try {
118
106
  builder.appendText("\n")
119
- } catch (error) {
107
+ } catch {
120
108
  // noop
121
109
  }
122
110
  }
@@ -145,10 +133,7 @@ export const hastToRichText = (
145
133
  if (!shorthandOrNode) {
146
134
  // Exit on unhandled node.
147
135
  return
148
- } else if (
149
- typeof shorthandOrNode === "object" &&
150
- "type" in shorthandOrNode
151
- ) {
136
+ } else if (typeof shorthandOrNode === "object" && "type" in shorthandOrNode) {
152
137
  // When the serializer returns a rich text node, we append it and return.
153
138
  switch (shorthandOrNode.type) {
154
139
  case RichTextNodeType.strong:
@@ -159,7 +144,7 @@ export const hastToRichText = (
159
144
 
160
145
  try {
161
146
  builder.appendSpan(shorthandOrNode, length)
162
- } catch (error) {
147
+ } catch {
163
148
  // Happens when we extract an image/embed node inside an RTTextNode and that
164
149
  // the next children is a span. The last RT node type is then an image/embed
165
150
  // node, so we need to resume a new RT text node.
@@ -191,10 +176,7 @@ export const hastToRichText = (
191
176
  }
192
177
 
193
178
  let match:
194
- | DistributedPick<
195
- RTBlockNode | Exclude<RTInlineNode, RTLabelNode>,
196
- "type"
197
- >
179
+ | DistributedPick<RTBlockNode | Exclude<RTInlineNode, RTLabelNode>, "type">
198
180
  | { type: "label"; data: { label: string } }
199
181
  if (typeof shorthand === "string") {
200
182
  match = { type: shorthand }
@@ -240,7 +222,7 @@ export const hastToRichText = (
240
222
 
241
223
  try {
242
224
  builder.appendSpan(span, length)
243
- } catch (error) {
225
+ } catch {
244
226
  // Happens when we extract an image/embed node inside an RTTextNode and that
245
227
  // the next children is a span. The last RT node type is then an image/embed
246
228
  // node, so we need to resume a new RT text node.
@@ -251,11 +233,7 @@ export const hastToRichText = (
251
233
  }
252
234
 
253
235
  default:
254
- throw new Error(
255
- `Unknown rich text node type: \`${
256
- (match as { type: string }).type
257
- }\``,
258
- )
236
+ throw new Error(`Unknown rich text node type: \`${(match as { type: string }).type}\``)
259
237
  }
260
238
  } catch (error) {
261
239
  if (error instanceof PrismicRichTextSerializerError) {
@@ -277,7 +255,7 @@ export const hastToRichText = (
277
255
  if (!(node.value.replace(/[ \t\n\f\r]/g, "") === "")) {
278
256
  try {
279
257
  builder.appendText(node.value)
280
- } catch (error) {
258
+ } catch {
281
259
  // Happens when we extract an image/embed node inside an RTTextNode. The last RT
282
260
  // node type is then an image/embed node, so we need to resume a new RT text node.
283
261
  builder.appendTextNode(lastRTTextNodeType, config?.direction)
@@ -1,7 +1,4 @@
1
- import type {
2
- CustomTypeModelRichTextField,
3
- RichTextField,
4
- } from "@prismicio/client"
1
+ import type { CustomTypeModelRichTextField, RichTextField } from "@prismicio/client"
5
2
  import type { Element, Root } from "hast"
6
3
  import { select, selectAll } from "hast-util-select"
7
4
  import rehypeMinifyWhitespace from "rehype-minify-whitespace"
@@ -14,43 +11,41 @@ import { filterRichTextField } from "./filterRichTextField"
14
11
  import type { HASTToRichTextConfig } from "./hastToRichText"
15
12
  import { hastToRichText } from "./hastToRichText"
16
13
 
17
- /**
18
- * Configuration options for {@link rehypeRichText}.
19
- */
14
+ /** Configuration options for {@link rehypeRichText}. */
20
15
  export type RehypeRichTextConfig = {
21
16
  /**
22
- * A CSS selector that targets the section of the document to convert to rich
23
- * text.
17
+ * A CSS selector that targets the section of the document to convert to rich text.
24
18
  *
25
- * @example `div.post`
19
+ * @example
20
+ * ;`div.post`
26
21
  *
27
22
  * @defaultValue `":root"` - The top-level element of the document.
28
23
  */
29
24
  container?: string
30
25
 
31
26
  /**
32
- * A list of CSS selectors to exclude matching nodes from the document to
33
- * process.
27
+ * A list of CSS selectors to exclude matching nodes from the document to process.
34
28
  *
35
- * @example `[".hidden", "aside"]`
29
+ * @example
30
+ * ;`[".hidden", "aside"]`
36
31
  *
37
32
  * @defaultValue `[]` - No nodes are excluded.
38
33
  */
39
34
  exclude?: string[]
40
35
 
41
36
  /**
42
- * A list of CSS selectors to include only matching nodes from the document to
43
- * process.
37
+ * A list of CSS selectors to include only matching nodes from the document to process.
44
38
  *
45
- * @example `["p", "img"]`
39
+ * @example
40
+ * ;`["p", "img"]`
46
41
  *
47
42
  * @defaultValue `[]` - All nodes are included.
48
43
  */
49
44
  include?: string[]
50
45
 
51
46
  /**
52
- * A rich text or title field model definition. When provided the serializer
53
- * will filter out any node types not allowed by the model.
47
+ * A rich text or title field model definition. When provided the serializer will filter out any
48
+ * node types not allowed by the model.
54
49
  *
55
50
  * @defaultValue `undefined` - No filtering is applied.
56
51
  */
@@ -64,107 +59,98 @@ export type RehypeRichTextConfig = {
64
59
  */
65
60
  // unified requires the function to be typed directly with the
66
61
  // `Plugin` type to properly infer return types on processors.
67
- export const rehypeRichText: Plugin<
68
- [config?: RehypeRichTextConfig],
69
- Root,
70
- RichTextField
71
- > = function rehypeRichText(config) {
72
- // This is a bit dirty, but it seems like that's how rehype intends
73
- // it to be due to JSDocs limitations(?), see:
74
- // https://github.com/rehypejs/rehype/blob/f6912ac680704f1ef4b558ac57cbf0dd62ed0892/packages/rehype-stringify/lib/index.js#L18-L20
75
- // eslint-disable-next-line @typescript-eslint/no-this-alias
76
- const self = this as unknown as Processor<
77
- undefined,
78
- undefined,
79
- undefined,
80
- Root,
81
- RichTextField
82
- >
83
-
84
- // We need to exclude nodes _before_ we minify the tree as excluding
85
- // nodes could end up in more whitespaces to trim.
86
- self.use(() => {
87
- return (tree: Root) => {
88
- // Extract container node if any is specified.
89
- if (config?.container) {
90
- const element = select(config.container, tree)
91
-
92
- if (!element) {
93
- throw new Error(
94
- `No container matching \`${config?.container}\` could be found in the input AST.`,
95
- )
96
- }
62
+ export const rehypeRichText: Plugin<[config?: RehypeRichTextConfig], Root, RichTextField> =
63
+ function rehypeRichText(config) {
64
+ // This is a bit dirty, but it seems like that's how rehype intends
65
+ // it to be due to JSDocs limitations(?), see:
66
+ // https://github.com/rehypejs/rehype/blob/f6912ac680704f1ef4b558ac57cbf0dd62ed0892/packages/rehype-stringify/lib/index.js#L18-L20
67
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
68
+ const self = this as unknown as Processor<undefined, undefined, undefined, Root, RichTextField>
69
+
70
+ // We need to exclude nodes _before_ we minify the tree as excluding
71
+ // nodes could end up in more whitespaces to trim.
72
+ self.use(() => {
73
+ return (tree: Root) => {
74
+ // Extract container node if any is specified.
75
+ if (config?.container) {
76
+ const element = select(config.container, tree)
77
+
78
+ if (!element) {
79
+ throw new Error(
80
+ `No container matching \`${config?.container}\` could be found in the input AST.`,
81
+ )
82
+ }
97
83
 
98
- // We cannot reassign the tree itself, so we instead replace
99
- // its children with the found element.
100
- tree.children = [element]
101
- }
84
+ // We cannot reassign the tree itself, so we instead replace
85
+ // its children with the found element.
86
+ tree.children = [element]
87
+ }
102
88
 
103
- // Remove excluded nodes if any are specified
104
- if (config?.exclude) {
105
- // We join selector to only run one query
106
- const nodesToExclude = selectAll(config.exclude.join(", "), tree)
89
+ // Remove excluded nodes if any are specified
90
+ if (config?.exclude) {
91
+ // We join selector to only run one query
92
+ const nodesToExclude = selectAll(config.exclude.join(", "), tree)
107
93
 
108
- remove(tree, (node) => nodesToExclude.includes(node as Element))
109
- }
94
+ remove(tree, (node) => nodesToExclude.includes(node as Element))
95
+ }
110
96
 
111
- // Include only nodes to include
112
- if (config?.include) {
113
- const nodesToInclude: Element[] = []
97
+ // Include only nodes to include
98
+ if (config?.include) {
99
+ const nodesToInclude: Element[] = []
114
100
 
115
- // We join selector to only run one query
116
- const selector = config.include.join(", ")
117
- const rawNodesToInclude = selectAll(selector, tree)
101
+ // We join selector to only run one query
102
+ const selector = config.include.join(", ")
103
+ const rawNodesToInclude = selectAll(selector, tree)
118
104
 
119
- // We walk the tree to exclude matching nodes that are children of other matching nodes.
120
- visit(tree, (node) => {
121
- if (rawNodesToInclude.includes(node as Element)) {
122
- nodesToInclude.push(node as Element)
105
+ // We walk the tree to exclude matching nodes that are children of other matching nodes.
106
+ visit(tree, (node) => {
107
+ if (rawNodesToInclude.includes(node as Element)) {
108
+ nodesToInclude.push(node as Element)
123
109
 
124
- // Stop traversing this part of the tree since we found its matching parent node.
125
- return SKIP
126
- }
127
- })
110
+ // Stop traversing this part of the tree since we found its matching parent node.
111
+ return SKIP
112
+ }
113
+ })
128
114
 
129
- // We cannot reassign the tree itself, so we instead replace
130
- // its children with the found element.
131
- tree.children = nodesToInclude
132
- }
115
+ // We cannot reassign the tree itself, so we instead replace
116
+ // its children with the found element.
117
+ tree.children = nodesToInclude
118
+ }
133
119
 
134
- // Mark nodes matching CSS selectors
135
- if (config?.serializer) {
136
- for (const key in config.serializer) {
137
- // HTML tag names are single word, lowercase strings, a-z and 1-6 (headings).
138
- // Here we want to match anything that's not a valid HTML tag name and treat
139
- // it as a CSS selector. See: https://regex101.com/r/LILLWH/1
140
- if (!/^[a-z]+[1-6]?$/.test(key)) {
141
- const matches = selectAll(key, tree)
142
-
143
- for (let i = 0; i < matches.length; i++) {
144
- matches[i].matchesSerializer = key
120
+ // Mark nodes matching CSS selectors
121
+ if (config?.serializer) {
122
+ for (const key in config.serializer) {
123
+ // HTML tag names are single word, lowercase strings, a-z and 1-6 (headings).
124
+ // Here we want to match anything that's not a valid HTML tag name and treat
125
+ // it as a CSS selector. See: https://regex101.com/r/LILLWH/1
126
+ if (!/^[a-z]+[1-6]?$/.test(key)) {
127
+ const matches = selectAll(key, tree)
128
+
129
+ for (let i = 0; i < matches.length; i++) {
130
+ matches[i].matchesSerializer = key
131
+ }
145
132
  }
146
133
  }
147
134
  }
148
135
  }
149
- }
150
- })
136
+ })
151
137
 
152
- // `rehypeRichText` _depends_ on `rehypeMinifyWhitespace`, that's why it's
153
- // registered within the plugin rather than on the processor directly.
154
- self.use(rehypeMinifyWhitespace)
138
+ // `rehypeRichText` _depends_ on `rehypeMinifyWhitespace`, that's why it's
139
+ // registered within the plugin rather than on the processor directly.
140
+ self.use(rehypeMinifyWhitespace)
155
141
 
156
- self.compiler = compiler
142
+ self.compiler = compiler
157
143
 
158
- function compiler(tree: Root, file: VFile): RichTextField {
159
- const richTextField = hastToRichText(tree, file, config)
144
+ function compiler(tree: Root, file: VFile): RichTextField {
145
+ const richTextField = hastToRichText(tree, file, config)
160
146
 
161
- if (config?.model) {
162
- return filterRichTextField(richTextField, config.model)
163
- }
147
+ if (config?.model) {
148
+ return filterRichTextField(richTextField, config.model)
149
+ }
164
150
 
165
- return richTextField
151
+ return richTextField
152
+ }
166
153
  }
167
- }
168
154
 
169
155
  declare module "unified" {
170
156
  // Register unified processor the result type.
@@ -177,8 +163,8 @@ declare module "hast" {
177
163
  // Extend hast node with a rich text value.
178
164
  interface Element {
179
165
  /**
180
- * A serializer this node matches to. Nodes are marked with this property
181
- * when they match a CSS selector from the serializer map.
166
+ * A serializer this node matches to. Nodes are marked with this property when they match a CSS
167
+ * selector from the serializer map.
182
168
  */
183
169
  matchesSerializer?: string
184
170
  }
package/src/types.ts CHANGED
@@ -1,70 +1,61 @@
1
- import type { RTInlineNode, RTNode, RichTextNodeTypes } from "@prismicio/client"
1
+ import type {
2
+ InjectMigrationSpecificTypes,
3
+ RTInlineNode,
4
+ RTNode,
5
+ RichTextNodeTypes,
6
+ } from "@prismicio/client"
2
7
  import type { Element } from "hast"
3
8
 
4
9
  import type { RTPartialInlineNode } from "./lib/RichTextFieldBuilder"
5
10
 
6
11
  /**
7
- * A shorthand definition for {@link RichTextHTMLMapSerializer} rich text node
8
- * types.
12
+ * A shorthand definition for {@link RichTextHTMLMapSerializer} rich text node types.
9
13
  *
10
14
  * @remarks
11
- * The `label` rich text node type is not available as is. Use an object
12
- * containing your label name to convert to label nodes instead. For example:
13
- * `u: { label: "underline" }`
15
+ * The `label` rich text node type is not available as is. Use an object containing your label
16
+ * name to convert to label nodes instead. For example: `u: { label: "underline" }`
14
17
  * @remarks
15
- * The `span` rich text node type is not available as it is not relevant in the
16
- * context of going from HTML to Prismic rich text.
18
+ * The `span` rich text node type is not available as it is not relevant in the context of going
19
+ * from HTML to Prismic rich text.
17
20
  */
18
21
  export type RichTextHTMLMapSerializerShorthand =
19
22
  | Exclude<RichTextNodeTypes, "label" | "span">
20
23
  | { label: string }
21
24
 
22
- /**
23
- * The payload provided to a {@link RichTextHTMLMapSerializerFunction}.
24
- */
25
+ /** The payload provided to a {@link RichTextHTMLMapSerializerFunction}. */
25
26
  type RichTextHTMLMapSerializerFunctionPayload = {
26
- /**
27
- * The hast {@link Element} node to serialize.
28
- */
27
+ /** The hast {@link Element} node to serialize. */
29
28
  node: Element
30
29
 
31
- /**
32
- * Additional context information to help with the serialization.
33
- */
30
+ /** Additional context information to help with the serialization. */
34
31
  context: {
35
- /**
36
- * The list type of the last list node encountered if any.
37
- */
32
+ /** The list type of the last list node encountered if any. */
38
33
  listType?: "group-list-item" | "group-o-list-item"
39
34
  }
40
35
  }
41
36
 
42
37
  /**
43
- * Serializes a hast {@link Element} node to a
44
- * {@link RichTextHTMLMapSerializerShorthand} or a rich text node.
38
+ * Serializes a hast {@link Element} node to a {@link RichTextHTMLMapSerializerShorthand} or a rich
39
+ * text node.
45
40
  *
46
41
  * @remarks
47
- * Serializing to a rich text node directly is not recommended and is only
48
- * available as an escape hatch. Prefer returning a
49
- * {@link RichTextHTMLMapSerializerShorthand} instead.
42
+ * Serializing to a rich text node directly is not recommended and is only available as an escape
43
+ * hatch. Prefer returning a {@link RichTextHTMLMapSerializerShorthand} instead.
50
44
  */
51
45
  export type RichTextHTMLMapSerializerFunction = (
52
46
  payload: RichTextHTMLMapSerializerFunctionPayload,
53
47
  ) =>
54
48
  | RichTextHTMLMapSerializerShorthand
55
- | RTNode
56
- | RTInlineNode
57
- | RTPartialInlineNode
49
+ | InjectMigrationSpecificTypes<RTNode | RTInlineNode | RTPartialInlineNode>
58
50
  | undefined
59
51
 
60
52
  /**
61
- * Serializes a hast {@link Element} node matching the given HTML tag name or CSS
62
- * selector to a Prismic rich text node.
53
+ * Serializes a hast {@link Element} node matching the given HTML tag name or CSS selector to a
54
+ * Prismic rich text node.
63
55
  *
64
56
  * @remarks
65
- * This serializer is used to serialize HTML to Prismic rich text. When
66
- * serializing Prismic rich text to HTML with {@link asHTML}, use the
67
- * {@link HTMLRichTextMapSerializer} type instead.
57
+ * This serializer is used to serialize HTML to Prismic rich text. When serializing Prismic rich
58
+ * text to HTML with {@link asHTML}, use the {@link HTMLRichTextMapSerializer} type instead.
68
59
  */
69
60
  export type RichTextHTMLMapSerializer = Record<
70
61
  string,
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -1,10 +0,0 @@
1
- import type { CustomTypeModelRichTextField, RichTextField, TitleField } from "@prismicio/client";
2
- /**
3
- * Filter a rich text field based on given model.
4
- *
5
- * @param richTextField - A rich text or title field from Prismic.
6
- * @param model - A rich text or title field custom type model.
7
- *
8
- * @returns A rich text or title field filtered based on the given model.
9
- */
10
- export declare const filterRichTextField: <Field extends RichTextField | TitleField>(richTextField: Field, model: CustomTypeModelRichTextField) => Field;
@@ -1,28 +0,0 @@
1
- import type { RTEmbedNode, RTImageNode, RTLinkNode } from "@prismicio/client";
2
- import type { Element } from "hast";
3
- import type { RTPartialInlineNode } from "./RichTextFieldBuilder";
4
- /**
5
- * Serializes a hast {@link Element} node to a {@link RTImageNode}.
6
- *
7
- * @param node - A hast node to serialize.
8
- *
9
- * @returns Equivalent {@link RTImageNode}.
10
- */
11
- export declare const serializeImage: (node: Element) => RTImageNode;
12
- /**
13
- * Serializes a hast {@link Element} node to a {@link RTEmbedNode}.
14
- *
15
- * @param node - A hast node to serialize.
16
- *
17
- * @returns Equivalent {@link RTEmbedNode}.
18
- */
19
- export declare const serializeEmbed: (node: Element) => RTEmbedNode;
20
- /**
21
- * Serializes a hast {@link Element} node to a {@link RTPartialInlineNode}.
22
- *
23
- * @param node - A hast node to serialize.
24
- * @param rtPartialInlineNode - A partial rich text node.
25
- *
26
- * @returns Equivalent {@link RTPartialInlineNode}.
27
- */
28
- export declare const serializeSpan: (node: Element, rtPartialInlineNode: RTPartialInlineNode | Omit<RTLinkNode, "start" | "end" | "data">) => RTPartialInlineNode;