@tiptap/static-renderer 3.0.0-beta.0

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 (59) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +18 -0
  3. package/dist/index.cjs +629 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +327 -0
  6. package/dist/index.d.ts +327 -0
  7. package/dist/index.js +584 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/json/html-string/index.cjs +111 -0
  10. package/dist/json/html-string/index.cjs.map +1 -0
  11. package/dist/json/html-string/index.d.cts +201 -0
  12. package/dist/json/html-string/index.d.ts +201 -0
  13. package/dist/json/html-string/index.js +81 -0
  14. package/dist/json/html-string/index.js.map +1 -0
  15. package/dist/json/react/index.cjs +117 -0
  16. package/dist/json/react/index.cjs.map +1 -0
  17. package/dist/json/react/index.d.cts +190 -0
  18. package/dist/json/react/index.d.ts +190 -0
  19. package/dist/json/react/index.js +79 -0
  20. package/dist/json/react/index.js.map +1 -0
  21. package/dist/json/renderer.cjs +89 -0
  22. package/dist/json/renderer.cjs.map +1 -0
  23. package/dist/json/renderer.d.cts +166 -0
  24. package/dist/json/renderer.d.ts +166 -0
  25. package/dist/json/renderer.js +64 -0
  26. package/dist/json/renderer.js.map +1 -0
  27. package/dist/pm/html-string/index.cjs +344 -0
  28. package/dist/pm/html-string/index.cjs.map +1 -0
  29. package/dist/pm/html-string/index.d.cts +175 -0
  30. package/dist/pm/html-string/index.d.ts +175 -0
  31. package/dist/pm/html-string/index.js +317 -0
  32. package/dist/pm/html-string/index.js.map +1 -0
  33. package/dist/pm/markdown/index.cjs +473 -0
  34. package/dist/pm/markdown/index.cjs.map +1 -0
  35. package/dist/pm/markdown/index.d.cts +153 -0
  36. package/dist/pm/markdown/index.d.ts +153 -0
  37. package/dist/pm/markdown/index.js +449 -0
  38. package/dist/pm/markdown/index.js.map +1 -0
  39. package/dist/pm/react/index.cjs +399 -0
  40. package/dist/pm/react/index.cjs.map +1 -0
  41. package/dist/pm/react/index.d.cts +163 -0
  42. package/dist/pm/react/index.d.ts +163 -0
  43. package/dist/pm/react/index.js +364 -0
  44. package/dist/pm/react/index.js.map +1 -0
  45. package/package.json +101 -0
  46. package/src/helpers.ts +54 -0
  47. package/src/index.ts +6 -0
  48. package/src/json/html-string/index.ts +2 -0
  49. package/src/json/html-string/string.ts +49 -0
  50. package/src/json/react/index.ts +2 -0
  51. package/src/json/react/react.ts +33 -0
  52. package/src/json/renderer.ts +241 -0
  53. package/src/pm/extensionRenderer.ts +215 -0
  54. package/src/pm/html-string/html-string.ts +105 -0
  55. package/src/pm/html-string/index.ts +2 -0
  56. package/src/pm/markdown/index.ts +2 -0
  57. package/src/pm/markdown/markdown.ts +142 -0
  58. package/src/pm/react/index.ts +2 -0
  59. package/src/pm/react/react.ts +152 -0
@@ -0,0 +1,163 @@
1
+ import { MarkType, NodeType, Node, ExtensionAttribute, Mark as Mark$1, JSONContent, Extensions } from '@tiptap/core';
2
+ import { DOMOutputSpec, Mark, Node as Node$1 } from '@tiptap/pm/model';
3
+ import React from 'react';
4
+
5
+ /**
6
+ * Props for a node renderer
7
+ */
8
+ type NodeProps<TNodeType = any, TChildren = any> = {
9
+ /**
10
+ * The current node to render
11
+ */
12
+ node: TNodeType;
13
+ /**
14
+ * Unless the node is the root node, this will always be defined
15
+ */
16
+ parent?: TNodeType;
17
+ /**
18
+ * The children of the current node
19
+ */
20
+ children?: TChildren;
21
+ /**
22
+ * Render a child element
23
+ */
24
+ renderElement: (props: {
25
+ /**
26
+ * Tiptap JSON content to render
27
+ */
28
+ content: TNodeType;
29
+ /**
30
+ * The parent node of the current node
31
+ */
32
+ parent?: TNodeType;
33
+ }) => TChildren;
34
+ };
35
+ /**
36
+ * Props for a mark renderer
37
+ */
38
+ type MarkProps<TMarkType = any, TChildren = any, TNodeType = any> = {
39
+ /**
40
+ * The current mark to render
41
+ */
42
+ mark: TMarkType;
43
+ /**
44
+ * The children of the current mark
45
+ */
46
+ children?: TChildren;
47
+ /**
48
+ * The node the current mark is applied to
49
+ */
50
+ node: TNodeType;
51
+ /**
52
+ * The node the current mark is applied to
53
+ */
54
+ parent?: TNodeType;
55
+ };
56
+ type TiptapStaticRendererOptions<
57
+ /**
58
+ * The return type of the render function (e.g. React.ReactNode, string)
59
+ */
60
+ TReturnType,
61
+ /**
62
+ * A mark type is either a JSON representation of a mark or a Prosemirror mark instance
63
+ */
64
+ TMarkType extends {
65
+ type: any;
66
+ } = MarkType,
67
+ /**
68
+ * A node type is either a JSON representation of a node or a Prosemirror node instance
69
+ */
70
+ TNodeType extends {
71
+ content?: {
72
+ forEach: (cb: (node: TNodeType) => void) => void;
73
+ };
74
+ marks?: readonly TMarkType[];
75
+ type: string | {
76
+ name: string;
77
+ };
78
+ } = NodeType,
79
+ /**
80
+ * A node renderer is a function that takes a node and its children and returns the rendered output
81
+ */
82
+ TNodeRender extends (ctx: NodeProps<TNodeType, TReturnType | TReturnType[]>) => TReturnType = (ctx: NodeProps<TNodeType, TReturnType | TReturnType[]>) => TReturnType,
83
+ /**
84
+ * A mark renderer is a function that takes a mark and its children and returns the rendered output
85
+ */
86
+ TMarkRender extends (ctx: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>) => TReturnType = (ctx: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>) => TReturnType> = {
87
+ /**
88
+ * Mapping of node types to react components
89
+ */
90
+ nodeMapping: Record<string, NoInfer<TNodeRender>>;
91
+ /**
92
+ * Mapping of mark types to react components
93
+ */
94
+ markMapping: Record<string, NoInfer<TMarkRender>>;
95
+ /**
96
+ * Component to render if a node type is not handled
97
+ */
98
+ unhandledNode?: NoInfer<TNodeRender>;
99
+ /**
100
+ * Component to render if a mark type is not handled
101
+ */
102
+ unhandledMark?: NoInfer<TMarkRender>;
103
+ };
104
+
105
+ type DomOutputSpecToElement<T> = (content: DOMOutputSpec) => (children?: T | T[]) => T;
106
+ /**
107
+ * This takes a NodeExtension and maps it to a React component
108
+ * @param extension The node extension to map to a React component
109
+ * @param extensionAttributes All available extension attributes
110
+ * @returns A tuple with the name of the extension and a React component that renders the extension
111
+ */
112
+ declare function mapNodeExtensionToReactNode<T>(domOutputSpecToElement: DomOutputSpecToElement<T>, extension: Node, extensionAttributes: ExtensionAttribute[], options?: Partial<Pick<TiptapStaticRendererOptions<T, Mark, Node$1>, 'unhandledNode'>>): [string, (props: NodeProps<Node$1, T | T[]>) => T];
113
+ /**
114
+ * This takes a MarkExtension and maps it to a React component
115
+ * @param extension The mark extension to map to a React component
116
+ * @param extensionAttributes All available extension attributes
117
+ * @returns A tuple with the name of the extension and a React component that renders the extension
118
+ */
119
+ declare function mapMarkExtensionToReactNode<T>(domOutputSpecToElement: DomOutputSpecToElement<T>, extension: Mark$1, extensionAttributes: ExtensionAttribute[], options?: Partial<Pick<TiptapStaticRendererOptions<T, Mark, Node$1>, 'unhandledMark'>>): [string, (props: MarkProps<Mark, T | T[]>) => T];
120
+ /**
121
+ * This function will statically render a Prosemirror Node to a target element type using the given extensions
122
+ * @param renderer The renderer to use to render the Prosemirror Node to the target element type
123
+ * @param domOutputSpecToElement A function that takes a Prosemirror DOMOutputSpec and returns a function that takes children and returns the target element type
124
+ * @param mapDefinedTypes An object with functions to map the doc and text types to the target element type
125
+ * @param content The Prosemirror Node to render
126
+ * @param extensions The extensions to use to render the Prosemirror Node
127
+ * @param options Additional options to pass to the renderer that can override the default behavior
128
+ * @returns The rendered target element type
129
+ */
130
+ declare function renderToElement<T>({ renderer, domOutputSpecToElement, mapDefinedTypes, content, extensions, options, }: {
131
+ renderer: (options: TiptapStaticRendererOptions<T, Mark, Node$1>) => (ctx: {
132
+ content: Node$1;
133
+ }) => T;
134
+ domOutputSpecToElement: DomOutputSpecToElement<T>;
135
+ mapDefinedTypes: {
136
+ doc: (props: NodeProps<Node$1, T | T[]>) => T;
137
+ text: (props: NodeProps<Node$1, T | T[]>) => T;
138
+ };
139
+ content: Node$1 | JSONContent;
140
+ extensions: Extensions;
141
+ options?: Partial<TiptapStaticRendererOptions<T, Mark, Node$1>>;
142
+ }): T;
143
+
144
+ /**
145
+ * Take a DOMOutputSpec and return a function that can render it to a React element
146
+ * @param content The DOMOutputSpec to convert to a React element
147
+ * @returns A function that can render the DOMOutputSpec to a React element
148
+ */
149
+ declare function domOutputSpecToReactElement(content: DOMOutputSpec, key?: number): (children?: React.ReactNode) => React.ReactNode;
150
+ /**
151
+ * This function will statically render a Prosemirror Node to a React component using the given extensions
152
+ * @param content The content to render to a React component
153
+ * @param extensions The extensions to use for rendering
154
+ * @param options The options to use for rendering
155
+ * @returns The React element that represents the rendered content
156
+ */
157
+ declare function renderToReactElement({ content, extensions, options, }: {
158
+ content: Node$1 | JSONContent;
159
+ extensions: Extensions;
160
+ options?: Partial<TiptapStaticRendererOptions<React.ReactNode, Mark, Node$1>>;
161
+ }): React.ReactNode;
162
+
163
+ export { type DomOutputSpecToElement, domOutputSpecToReactElement, mapMarkExtensionToReactNode, mapNodeExtensionToReactNode, renderToElement, renderToReactElement };
@@ -0,0 +1,364 @@
1
+ // src/pm/extensionRenderer.ts
2
+ import {
3
+ getAttributesFromExtensions,
4
+ getExtensionField,
5
+ getSchemaByResolvedExtensions,
6
+ resolveExtensions,
7
+ splitExtensions
8
+ } from "@tiptap/core";
9
+ import { Node } from "@tiptap/pm/model";
10
+
11
+ // src/helpers.ts
12
+ import { mergeAttributes } from "@tiptap/core";
13
+ function getAttributes(nodeOrMark, extensionAttributes, onlyRenderedAttributes) {
14
+ const nodeOrMarkAttributes = nodeOrMark.attrs;
15
+ if (!nodeOrMarkAttributes) {
16
+ return {};
17
+ }
18
+ return extensionAttributes.filter((item) => {
19
+ if (item.type !== (typeof nodeOrMark.type === "string" ? nodeOrMark.type : nodeOrMark.type.name)) {
20
+ return false;
21
+ }
22
+ if (onlyRenderedAttributes) {
23
+ return item.attribute.rendered;
24
+ }
25
+ return true;
26
+ }).map((item) => {
27
+ if (!item.attribute.renderHTML) {
28
+ return {
29
+ [item.name]: item.name in nodeOrMarkAttributes ? nodeOrMarkAttributes[item.name] : item.attribute.default
30
+ };
31
+ }
32
+ return item.attribute.renderHTML(nodeOrMarkAttributes) || {
33
+ [item.name]: item.name in nodeOrMarkAttributes ? nodeOrMarkAttributes[item.name] : item.attribute.default
34
+ };
35
+ }).reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {});
36
+ }
37
+ function getHTMLAttributes(nodeOrMark, extensionAttributes) {
38
+ return getAttributes(nodeOrMark, extensionAttributes, true);
39
+ }
40
+
41
+ // src/pm/extensionRenderer.ts
42
+ function mapNodeExtensionToReactNode(domOutputSpecToElement, extension, extensionAttributes, options) {
43
+ const context = {
44
+ name: extension.name,
45
+ options: extension.options,
46
+ storage: extension.storage,
47
+ parent: extension.parent
48
+ };
49
+ const renderToHTML = getExtensionField(extension, "renderHTML", context);
50
+ if (!renderToHTML) {
51
+ if (options == null ? void 0 : options.unhandledNode) {
52
+ return [extension.name, options.unhandledNode];
53
+ }
54
+ return [
55
+ extension.name,
56
+ () => {
57
+ throw new Error(
58
+ `[tiptap error]: Node ${extension.name} cannot be rendered, it is missing a "renderToHTML" method, please implement it or override the corresponding "nodeMapping" method to have a custom rendering`
59
+ );
60
+ }
61
+ ];
62
+ }
63
+ return [
64
+ extension.name,
65
+ ({ node, children }) => {
66
+ try {
67
+ return domOutputSpecToElement(
68
+ renderToHTML({
69
+ node,
70
+ HTMLAttributes: getHTMLAttributes(node, extensionAttributes)
71
+ })
72
+ )(children);
73
+ } catch (e) {
74
+ throw new Error(
75
+ `[tiptap error]: Node ${extension.name} cannot be rendered, it's "renderToHTML" method threw an error: ${e.message}`,
76
+ { cause: e }
77
+ );
78
+ }
79
+ }
80
+ ];
81
+ }
82
+ function mapMarkExtensionToReactNode(domOutputSpecToElement, extension, extensionAttributes, options) {
83
+ const context = {
84
+ name: extension.name,
85
+ options: extension.options,
86
+ storage: extension.storage,
87
+ parent: extension.parent
88
+ };
89
+ const renderToHTML = getExtensionField(extension, "renderHTML", context);
90
+ if (!renderToHTML) {
91
+ if (options == null ? void 0 : options.unhandledMark) {
92
+ return [extension.name, options.unhandledMark];
93
+ }
94
+ return [
95
+ extension.name,
96
+ () => {
97
+ throw new Error(`Node ${extension.name} cannot be rendered, it is missing a "renderToHTML" method`);
98
+ }
99
+ ];
100
+ }
101
+ return [
102
+ extension.name,
103
+ ({ mark, children }) => {
104
+ try {
105
+ return domOutputSpecToElement(
106
+ renderToHTML({
107
+ mark,
108
+ HTMLAttributes: getHTMLAttributes(mark, extensionAttributes)
109
+ })
110
+ )(children);
111
+ } catch (e) {
112
+ throw new Error(
113
+ `[tiptap error]: Mark ${extension.name} cannot be rendered, it's "renderToHTML" method threw an error: ${e.message}`,
114
+ { cause: e }
115
+ );
116
+ }
117
+ }
118
+ ];
119
+ }
120
+ function renderToElement({
121
+ renderer,
122
+ domOutputSpecToElement,
123
+ mapDefinedTypes,
124
+ content,
125
+ extensions,
126
+ options
127
+ }) {
128
+ extensions = resolveExtensions(extensions);
129
+ const extensionAttributes = getAttributesFromExtensions(extensions);
130
+ const { nodeExtensions, markExtensions } = splitExtensions(extensions);
131
+ if (!(content instanceof Node)) {
132
+ content = Node.fromJSON(getSchemaByResolvedExtensions(extensions), content);
133
+ }
134
+ return renderer({
135
+ ...options,
136
+ nodeMapping: {
137
+ ...Object.fromEntries(
138
+ nodeExtensions.filter((e) => {
139
+ if (e.name in mapDefinedTypes) {
140
+ return false;
141
+ }
142
+ if (options == null ? void 0 : options.nodeMapping) {
143
+ return !(e.name in options.nodeMapping);
144
+ }
145
+ return true;
146
+ }).map(
147
+ (nodeExtension) => mapNodeExtensionToReactNode(domOutputSpecToElement, nodeExtension, extensionAttributes, options)
148
+ )
149
+ ),
150
+ ...mapDefinedTypes,
151
+ ...options == null ? void 0 : options.nodeMapping
152
+ },
153
+ markMapping: {
154
+ ...Object.fromEntries(
155
+ markExtensions.filter((e) => {
156
+ if (options == null ? void 0 : options.markMapping) {
157
+ return !(e.name in options.markMapping);
158
+ }
159
+ return true;
160
+ }).map((mark) => mapMarkExtensionToReactNode(domOutputSpecToElement, mark, extensionAttributes, options))
161
+ ),
162
+ ...options == null ? void 0 : options.markMapping
163
+ }
164
+ })({ content });
165
+ }
166
+
167
+ // src/pm/react/react.ts
168
+ import React2 from "react";
169
+
170
+ // src/json/react/react.ts
171
+ import React from "react";
172
+
173
+ // src/json/renderer.ts
174
+ function TiptapStaticRenderer(renderComponent, {
175
+ nodeMapping,
176
+ markMapping,
177
+ unhandledNode,
178
+ unhandledMark
179
+ }) {
180
+ return function renderContent({
181
+ content,
182
+ parent
183
+ }) {
184
+ var _a;
185
+ const nodeType = typeof content.type === "string" ? content.type : content.type.name;
186
+ const NodeHandler = (_a = nodeMapping[nodeType]) != null ? _a : unhandledNode;
187
+ if (!NodeHandler) {
188
+ throw new Error(`missing handler for node type ${nodeType}`);
189
+ }
190
+ const nodeContent = renderComponent({
191
+ component: NodeHandler,
192
+ props: {
193
+ node: content,
194
+ parent,
195
+ renderElement: renderContent,
196
+ // Lazily compute the children to avoid unnecessary recursion
197
+ get children() {
198
+ const children = [];
199
+ if (content.content) {
200
+ content.content.forEach((child) => {
201
+ children.push(
202
+ renderContent({
203
+ content: child,
204
+ parent: content
205
+ })
206
+ );
207
+ });
208
+ }
209
+ return children;
210
+ }
211
+ }
212
+ });
213
+ const markedContent = content.marks ? content.marks.reduce((acc, mark) => {
214
+ var _a2;
215
+ const markType = typeof mark.type === "string" ? mark.type : mark.type.name;
216
+ const MarkHandler = (_a2 = markMapping[markType]) != null ? _a2 : unhandledMark;
217
+ if (!MarkHandler) {
218
+ throw new Error(`missing handler for mark type ${markType}`);
219
+ }
220
+ return renderComponent({
221
+ component: MarkHandler,
222
+ props: {
223
+ mark,
224
+ parent,
225
+ node: content,
226
+ children: acc
227
+ }
228
+ });
229
+ }, nodeContent) : nodeContent;
230
+ return markedContent;
231
+ };
232
+ }
233
+
234
+ // src/json/react/react.ts
235
+ function renderJSONContentToReactElement(options) {
236
+ let key = 0;
237
+ return TiptapStaticRenderer(({ component, props: { children, ...props } }) => {
238
+ return React.createElement(
239
+ component,
240
+ // eslint-disable-next-line no-plusplus
241
+ Object.assign(props, { key: key++ }),
242
+ [].concat(children)
243
+ );
244
+ }, options);
245
+ }
246
+
247
+ // src/pm/react/react.ts
248
+ function mapAttrsToHTMLAttributes(attrs, key) {
249
+ if (!attrs) {
250
+ return { key };
251
+ }
252
+ return Object.entries(attrs).reduce(
253
+ (acc, [name, value]) => {
254
+ if (name === "class") {
255
+ return Object.assign(acc, { className: value });
256
+ }
257
+ return Object.assign(acc, { [name]: value });
258
+ },
259
+ { key }
260
+ );
261
+ }
262
+ function domOutputSpecToReactElement(content, key = 0) {
263
+ if (typeof content === "string") {
264
+ return () => content;
265
+ }
266
+ if (typeof content === "object" && "length" in content) {
267
+ let [tag, attrs, children, ...rest] = content;
268
+ const parts = tag.split(" ");
269
+ if (parts.length > 1) {
270
+ tag = parts[1];
271
+ if (attrs === void 0) {
272
+ attrs = {
273
+ xmlns: parts[0]
274
+ };
275
+ }
276
+ if (attrs === 0) {
277
+ attrs = {
278
+ xmlns: parts[0]
279
+ };
280
+ children = 0;
281
+ }
282
+ if (typeof attrs === "object") {
283
+ attrs = Object.assign(attrs, { xmlns: parts[0] });
284
+ }
285
+ }
286
+ if (attrs === void 0) {
287
+ return () => React2.createElement(tag, mapAttrsToHTMLAttributes(void 0, key.toString()));
288
+ }
289
+ if (attrs === 0) {
290
+ return (child) => React2.createElement(tag, mapAttrsToHTMLAttributes(void 0, key.toString()), child);
291
+ }
292
+ if (typeof attrs === "object") {
293
+ if (Array.isArray(attrs)) {
294
+ if (children === void 0) {
295
+ return (child) => React2.createElement(
296
+ tag,
297
+ mapAttrsToHTMLAttributes(void 0, key.toString()),
298
+ domOutputSpecToReactElement(attrs, key++)(child)
299
+ );
300
+ }
301
+ if (children === 0) {
302
+ return (child) => React2.createElement(
303
+ tag,
304
+ mapAttrsToHTMLAttributes(void 0, key.toString()),
305
+ domOutputSpecToReactElement(attrs, key++)(child)
306
+ );
307
+ }
308
+ return (child) => React2.createElement(
309
+ tag,
310
+ mapAttrsToHTMLAttributes(void 0, key.toString()),
311
+ domOutputSpecToReactElement(attrs)(child),
312
+ [children].concat(rest).map((outputSpec) => domOutputSpecToReactElement(outputSpec, key++)(child))
313
+ );
314
+ }
315
+ if (children === void 0) {
316
+ return () => React2.createElement(tag, mapAttrsToHTMLAttributes(attrs, key.toString()));
317
+ }
318
+ if (children === 0) {
319
+ return (child) => React2.createElement(tag, mapAttrsToHTMLAttributes(attrs, key.toString()), child);
320
+ }
321
+ return (child) => React2.createElement(
322
+ tag,
323
+ mapAttrsToHTMLAttributes(attrs, key.toString()),
324
+ [children].concat(rest).map((outputSpec) => domOutputSpecToReactElement(outputSpec, key++)(child))
325
+ );
326
+ }
327
+ }
328
+ throw new Error(
329
+ "[tiptap error]: Unsupported DomOutputSpec type, check the `renderHTML` method output or implement a node mapping",
330
+ {
331
+ cause: content
332
+ }
333
+ );
334
+ }
335
+ function renderToReactElement({
336
+ content,
337
+ extensions,
338
+ options
339
+ }) {
340
+ return renderToElement({
341
+ renderer: renderJSONContentToReactElement,
342
+ domOutputSpecToElement: domOutputSpecToReactElement,
343
+ mapDefinedTypes: {
344
+ // Map a doc node to concatenated children
345
+ doc: ({ children }) => React2.createElement(React2.Fragment, {}, children),
346
+ // Map a text node to its text content
347
+ text: ({ node }) => {
348
+ var _a;
349
+ return (_a = node.text) != null ? _a : "";
350
+ }
351
+ },
352
+ content,
353
+ extensions,
354
+ options
355
+ });
356
+ }
357
+ export {
358
+ domOutputSpecToReactElement,
359
+ mapMarkExtensionToReactNode,
360
+ mapNodeExtensionToReactNode,
361
+ renderToElement,
362
+ renderToReactElement
363
+ };
364
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/pm/extensionRenderer.ts","../../../src/helpers.ts","../../../src/pm/react/react.ts","../../../src/json/react/react.ts","../../../src/json/renderer.ts"],"sourcesContent":["/* eslint-disable no-plusplus */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type {\n ExtensionAttribute,\n Extensions,\n JSONContent,\n Mark as MarkExtension,\n MarkConfig,\n Node as NodeExtension,\n NodeConfig,\n} from '@tiptap/core'\nimport {\n getAttributesFromExtensions,\n getExtensionField,\n getSchemaByResolvedExtensions,\n resolveExtensions,\n splitExtensions,\n} from '@tiptap/core'\nimport type { DOMOutputSpec, Mark } from '@tiptap/pm/model'\nimport { Node } from '@tiptap/pm/model'\n\nimport { getHTMLAttributes } from '../helpers.js'\nimport type { MarkProps, NodeProps, TiptapStaticRendererOptions } from '../json/renderer.js'\n\nexport type DomOutputSpecToElement<T> = (content: DOMOutputSpec) => (children?: T | T[]) => T\n\n/**\n * This takes a NodeExtension and maps it to a React component\n * @param extension The node extension to map to a React component\n * @param extensionAttributes All available extension attributes\n * @returns A tuple with the name of the extension and a React component that renders the extension\n */\nexport function mapNodeExtensionToReactNode<T>(\n domOutputSpecToElement: DomOutputSpecToElement<T>,\n extension: NodeExtension,\n extensionAttributes: ExtensionAttribute[],\n options?: Partial<Pick<TiptapStaticRendererOptions<T, Mark, Node>, 'unhandledNode'>>,\n): [string, (props: NodeProps<Node, T | T[]>) => T] {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n parent: extension.parent,\n }\n\n const renderToHTML = getExtensionField<NodeConfig['renderHTML']>(extension, 'renderHTML', context)\n\n if (!renderToHTML) {\n if (options?.unhandledNode) {\n return [extension.name, options.unhandledNode]\n }\n return [\n extension.name,\n () => {\n throw new Error(\n `[tiptap error]: Node ${extension.name} cannot be rendered, it is missing a \"renderToHTML\" method, please implement it or override the corresponding \"nodeMapping\" method to have a custom rendering`,\n )\n },\n ]\n }\n\n return [\n extension.name,\n ({ node, children }) => {\n try {\n return domOutputSpecToElement(\n renderToHTML({\n node,\n HTMLAttributes: getHTMLAttributes(node, extensionAttributes),\n }),\n )(children)\n } catch (e) {\n throw new Error(\n `[tiptap error]: Node ${\n extension.name\n } cannot be rendered, it's \"renderToHTML\" method threw an error: ${(e as Error).message}`,\n { cause: e },\n )\n }\n },\n ]\n}\n\n/**\n * This takes a MarkExtension and maps it to a React component\n * @param extension The mark extension to map to a React component\n * @param extensionAttributes All available extension attributes\n * @returns A tuple with the name of the extension and a React component that renders the extension\n */\nexport function mapMarkExtensionToReactNode<T>(\n domOutputSpecToElement: DomOutputSpecToElement<T>,\n extension: MarkExtension,\n extensionAttributes: ExtensionAttribute[],\n options?: Partial<Pick<TiptapStaticRendererOptions<T, Mark, Node>, 'unhandledMark'>>,\n): [string, (props: MarkProps<Mark, T | T[]>) => T] {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n parent: extension.parent,\n }\n\n const renderToHTML = getExtensionField<MarkConfig['renderHTML']>(extension, 'renderHTML', context)\n\n if (!renderToHTML) {\n if (options?.unhandledMark) {\n return [extension.name, options.unhandledMark]\n }\n return [\n extension.name,\n () => {\n throw new Error(`Node ${extension.name} cannot be rendered, it is missing a \"renderToHTML\" method`)\n },\n ]\n }\n\n return [\n extension.name,\n ({ mark, children }) => {\n try {\n return domOutputSpecToElement(\n renderToHTML({\n mark,\n HTMLAttributes: getHTMLAttributes(mark, extensionAttributes),\n }),\n )(children)\n } catch (e) {\n throw new Error(\n `[tiptap error]: Mark ${\n extension.name\n } cannot be rendered, it's \"renderToHTML\" method threw an error: ${(e as Error).message}`,\n { cause: e },\n )\n }\n },\n ]\n}\n\n/**\n * This function will statically render a Prosemirror Node to a target element type using the given extensions\n * @param renderer The renderer to use to render the Prosemirror Node to the target element type\n * @param domOutputSpecToElement A function that takes a Prosemirror DOMOutputSpec and returns a function that takes children and returns the target element type\n * @param mapDefinedTypes An object with functions to map the doc and text types to the target element type\n * @param content The Prosemirror Node to render\n * @param extensions The extensions to use to render the Prosemirror Node\n * @param options Additional options to pass to the renderer that can override the default behavior\n * @returns The rendered target element type\n */\nexport function renderToElement<T>({\n renderer,\n domOutputSpecToElement,\n mapDefinedTypes,\n content,\n extensions,\n options,\n}: {\n renderer: (options: TiptapStaticRendererOptions<T, Mark, Node>) => (ctx: { content: Node }) => T\n domOutputSpecToElement: DomOutputSpecToElement<T>\n mapDefinedTypes: {\n doc: (props: NodeProps<Node, T | T[]>) => T\n text: (props: NodeProps<Node, T | T[]>) => T\n }\n content: Node | JSONContent\n extensions: Extensions\n options?: Partial<TiptapStaticRendererOptions<T, Mark, Node>>\n}): T {\n // get all extensions in order & split them into nodes and marks\n extensions = resolveExtensions(extensions)\n const extensionAttributes = getAttributesFromExtensions(extensions)\n const { nodeExtensions, markExtensions } = splitExtensions(extensions)\n\n if (!(content instanceof Node)) {\n content = Node.fromJSON(getSchemaByResolvedExtensions(extensions), content)\n }\n\n return renderer({\n ...options,\n nodeMapping: {\n ...Object.fromEntries(\n nodeExtensions\n .filter(e => {\n if (e.name in mapDefinedTypes) {\n // These are predefined types that we don't need to map\n return false\n }\n // No need to generate mappings for nodes that are already mapped\n if (options?.nodeMapping) {\n return !(e.name in options.nodeMapping)\n }\n return true\n })\n .map(nodeExtension =>\n mapNodeExtensionToReactNode<T>(domOutputSpecToElement, nodeExtension, extensionAttributes, options),\n ),\n ),\n ...mapDefinedTypes,\n ...options?.nodeMapping,\n },\n markMapping: {\n ...Object.fromEntries(\n markExtensions\n .filter(e => {\n // No need to generate mappings for marks that are already mapped\n if (options?.markMapping) {\n return !(e.name in options.markMapping)\n }\n return true\n })\n .map(mark => mapMarkExtensionToReactNode<T>(domOutputSpecToElement, mark, extensionAttributes, options)),\n ),\n ...options?.markMapping,\n },\n })({ content })\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type ExtensionAttribute, type MarkType, type NodeType, mergeAttributes } from '@tiptap/core'\n\n/**\n * This function returns the attributes of a node or mark that are defined by the given extension attributes.\n * @param nodeOrMark The node or mark to get the attributes from\n * @param extensionAttributes The extension attributes to use\n * @param onlyRenderedAttributes If true, only attributes that are rendered in the HTML are returned\n */\nexport function getAttributes(\n nodeOrMark: NodeType | MarkType,\n extensionAttributes: ExtensionAttribute[],\n onlyRenderedAttributes?: boolean,\n): Record<string, any> {\n const nodeOrMarkAttributes = nodeOrMark.attrs\n\n if (!nodeOrMarkAttributes) {\n return {}\n }\n\n return extensionAttributes\n .filter(item => {\n if (item.type !== (typeof nodeOrMark.type === 'string' ? nodeOrMark.type : nodeOrMark.type.name)) {\n return false\n }\n if (onlyRenderedAttributes) {\n return item.attribute.rendered\n }\n return true\n })\n .map(item => {\n if (!item.attribute.renderHTML) {\n return {\n [item.name]: item.name in nodeOrMarkAttributes ? nodeOrMarkAttributes[item.name] : item.attribute.default,\n }\n }\n\n return (\n item.attribute.renderHTML(nodeOrMarkAttributes) || {\n [item.name]: item.name in nodeOrMarkAttributes ? nodeOrMarkAttributes[item.name] : item.attribute.default,\n }\n )\n })\n .reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {})\n}\n\n/**\n * This function returns the HTML attributes of a node or mark that are defined by the given extension attributes.\n * @param nodeOrMark The node or mark to get the attributes from\n * @param extensionAttributes The extension attributes to use\n */\nexport function getHTMLAttributes(nodeOrMark: NodeType | MarkType, extensionAttributes: ExtensionAttribute[]) {\n return getAttributes(nodeOrMark, extensionAttributes, true)\n}\n","/* eslint-disable no-plusplus, @typescript-eslint/no-explicit-any */\nimport type { DOMOutputSpecArray, Extensions, JSONContent } from '@tiptap/core'\nimport type { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\nimport React from 'react'\n\nimport { renderJSONContentToReactElement } from '../../json/react/react.js'\nimport type { TiptapStaticRendererOptions } from '../../json/renderer.js'\nimport { renderToElement } from '../extensionRenderer.js'\n\n/**\n * This function maps the attributes of a node or mark to HTML attributes\n * @param attrs The attributes to map\n * @param key The key to use for the React element\n * @returns The mapped HTML attributes as an object\n */\nfunction mapAttrsToHTMLAttributes(attrs?: Record<string, any>, key?: string): Record<string, any> {\n if (!attrs) {\n return { key }\n }\n return Object.entries(attrs).reduce(\n (acc, [name, value]) => {\n if (name === 'class') {\n return Object.assign(acc, { className: value })\n }\n return Object.assign(acc, { [name]: value })\n },\n { key },\n )\n}\n\n/**\n * Take a DOMOutputSpec and return a function that can render it to a React element\n * @param content The DOMOutputSpec to convert to a React element\n * @returns A function that can render the DOMOutputSpec to a React element\n */\nexport function domOutputSpecToReactElement(\n content: DOMOutputSpec,\n key = 0,\n): (children?: React.ReactNode) => React.ReactNode {\n if (typeof content === 'string') {\n return () => content\n }\n if (typeof content === 'object' && 'length' in content) {\n // eslint-disable-next-line prefer-const\n let [tag, attrs, children, ...rest] = content as DOMOutputSpecArray\n const parts = tag.split(' ')\n\n if (parts.length > 1) {\n tag = parts[1]\n if (attrs === undefined) {\n attrs = {\n xmlns: parts[0],\n }\n }\n if (attrs === 0) {\n attrs = {\n xmlns: parts[0],\n }\n children = 0\n }\n if (typeof attrs === 'object') {\n attrs = Object.assign(attrs, { xmlns: parts[0] })\n }\n }\n\n if (attrs === undefined) {\n return () => React.createElement(tag, mapAttrsToHTMLAttributes(undefined, key.toString()))\n }\n if (attrs === 0) {\n return child => React.createElement(tag, mapAttrsToHTMLAttributes(undefined, key.toString()), child)\n }\n if (typeof attrs === 'object') {\n if (Array.isArray(attrs)) {\n if (children === undefined) {\n return child =>\n React.createElement(\n tag,\n mapAttrsToHTMLAttributes(undefined, key.toString()),\n domOutputSpecToReactElement(attrs as DOMOutputSpecArray, key++)(child),\n )\n }\n if (children === 0) {\n return child =>\n React.createElement(\n tag,\n mapAttrsToHTMLAttributes(undefined, key.toString()),\n domOutputSpecToReactElement(attrs as DOMOutputSpecArray, key++)(child),\n )\n }\n return child =>\n React.createElement(\n tag,\n mapAttrsToHTMLAttributes(undefined, key.toString()),\n domOutputSpecToReactElement(attrs as DOMOutputSpecArray)(child),\n [children].concat(rest).map(outputSpec => domOutputSpecToReactElement(outputSpec, key++)(child)),\n )\n }\n if (children === undefined) {\n return () => React.createElement(tag, mapAttrsToHTMLAttributes(attrs, key.toString()))\n }\n if (children === 0) {\n return child => React.createElement(tag, mapAttrsToHTMLAttributes(attrs, key.toString()), child)\n }\n\n return child =>\n React.createElement(\n tag,\n mapAttrsToHTMLAttributes(attrs, key.toString()),\n [children].concat(rest).map(outputSpec => domOutputSpecToReactElement(outputSpec, key++)(child)),\n )\n }\n }\n\n // TODO support DOM elements? How to handle them?\n throw new Error(\n '[tiptap error]: Unsupported DomOutputSpec type, check the `renderHTML` method output or implement a node mapping',\n {\n cause: content,\n },\n )\n}\n\n/**\n * This function will statically render a Prosemirror Node to a React component using the given extensions\n * @param content The content to render to a React component\n * @param extensions The extensions to use for rendering\n * @param options The options to use for rendering\n * @returns The React element that represents the rendered content\n */\nexport function renderToReactElement({\n content,\n extensions,\n options,\n}: {\n content: Node | JSONContent\n extensions: Extensions\n options?: Partial<TiptapStaticRendererOptions<React.ReactNode, Mark, Node>>\n}): React.ReactNode {\n return renderToElement<React.ReactNode>({\n renderer: renderJSONContentToReactElement,\n domOutputSpecToElement: domOutputSpecToReactElement,\n mapDefinedTypes: {\n // Map a doc node to concatenated children\n doc: ({ children }) => React.createElement(React.Fragment, {}, children),\n // Map a text node to its text content\n text: ({ node }) => node.text ?? '',\n },\n content,\n extensions,\n options,\n })\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { MarkType, NodeType } from '@tiptap/core'\nimport React from 'react'\n\nimport type { TiptapStaticRendererOptions } from '../renderer.js'\nimport { TiptapStaticRenderer } from '../renderer.js'\n\nexport function renderJSONContentToReactElement<\n /**\n * A mark type is either a JSON representation of a mark or a Prosemirror mark instance\n */\n TMarkType extends { type: any } = MarkType,\n /**\n * A node type is either a JSON representation of a node or a Prosemirror node instance\n */\n TNodeType extends {\n content?: { forEach: (cb: (node: TNodeType) => void) => void }\n marks?: readonly TMarkType[]\n type: string | { name: string }\n } = NodeType,\n>(options: TiptapStaticRendererOptions<React.ReactNode, TMarkType, TNodeType>) {\n let key = 0\n\n return TiptapStaticRenderer<React.ReactNode, TMarkType, TNodeType>(({ component, props: { children, ...props } }) => {\n return React.createElement(\n component as React.FC<typeof props>,\n // eslint-disable-next-line no-plusplus\n Object.assign(props, { key: key++ }),\n ([] as React.ReactNode[]).concat(children),\n )\n }, options)\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { MarkType, NodeType } from '@tiptap/core'\n\n/**\n * Props for a node renderer\n */\nexport type NodeProps<TNodeType = any, TChildren = any> = {\n /**\n * The current node to render\n */\n node: TNodeType\n /**\n * Unless the node is the root node, this will always be defined\n */\n parent?: TNodeType\n /**\n * The children of the current node\n */\n children?: TChildren\n /**\n * Render a child element\n */\n renderElement: (props: {\n /**\n * Tiptap JSON content to render\n */\n content: TNodeType\n /**\n * The parent node of the current node\n */\n parent?: TNodeType\n }) => TChildren\n}\n\n/**\n * Props for a mark renderer\n */\nexport type MarkProps<TMarkType = any, TChildren = any, TNodeType = any> = {\n /**\n * The current mark to render\n */\n mark: TMarkType\n /**\n * The children of the current mark\n */\n children?: TChildren\n /**\n * The node the current mark is applied to\n */\n node: TNodeType\n /**\n * The node the current mark is applied to\n */\n parent?: TNodeType\n}\n\nexport type TiptapStaticRendererOptions<\n /**\n * The return type of the render function (e.g. React.ReactNode, string)\n */\n TReturnType,\n /**\n * A mark type is either a JSON representation of a mark or a Prosemirror mark instance\n */\n TMarkType extends { type: any } = MarkType,\n /**\n * A node type is either a JSON representation of a node or a Prosemirror node instance\n */\n TNodeType extends {\n content?: { forEach: (cb: (node: TNodeType) => void) => void }\n marks?: readonly TMarkType[]\n type: string | { name: string }\n } = NodeType,\n /**\n * A node renderer is a function that takes a node and its children and returns the rendered output\n */\n TNodeRender extends (ctx: NodeProps<TNodeType, TReturnType | TReturnType[]>) => TReturnType = (\n ctx: NodeProps<TNodeType, TReturnType | TReturnType[]>,\n ) => TReturnType,\n /**\n * A mark renderer is a function that takes a mark and its children and returns the rendered output\n */\n TMarkRender extends (ctx: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>) => TReturnType = (\n ctx: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>,\n ) => TReturnType,\n> = {\n /**\n * Mapping of node types to react components\n */\n nodeMapping: Record<string, NoInfer<TNodeRender>>\n /**\n * Mapping of mark types to react components\n */\n markMapping: Record<string, NoInfer<TMarkRender>>\n /**\n * Component to render if a node type is not handled\n */\n unhandledNode?: NoInfer<TNodeRender>\n /**\n * Component to render if a mark type is not handled\n */\n unhandledMark?: NoInfer<TMarkRender>\n}\n\n/**\n * Tiptap Static Renderer\n * ----------------------\n *\n * This function is a basis to allow for different renderers to be created.\n * Generic enough to be able to statically render Prosemirror JSON or Prosemirror Nodes.\n *\n * Using this function, you can create a renderer that takes a JSON representation of a Prosemirror document\n * and renders it using a mapping of node types to React components or even to a string.\n * This function is used as the basis to create the `reactRenderer` and `stringRenderer` functions.\n */\nexport function TiptapStaticRenderer<\n /**\n * The return type of the render function (e.g. React.ReactNode, string)\n */\n TReturnType,\n /**\n * A mark type is either a JSON representation of a mark or a Prosemirror mark instance\n */\n TMarkType extends { type: string | { name: string } } = MarkType,\n /**\n * A node type is either a JSON representation of a node or a Prosemirror node instance\n */\n TNodeType extends {\n content?: { forEach: (cb: (node: TNodeType) => void) => void }\n marks?: readonly TMarkType[]\n type: string | { name: string }\n } = NodeType,\n /**\n * A node renderer is a function that takes a node and its children and returns the rendered output\n */\n TNodeRender extends (ctx: NodeProps<TNodeType, TReturnType | TReturnType[]>) => TReturnType = (\n ctx: NodeProps<TNodeType, TReturnType | TReturnType[]>,\n ) => TReturnType,\n /**\n * A mark renderer is a function that takes a mark and its children and returns the rendered output\n */\n TMarkRender extends (ctx: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>) => TReturnType = (\n ctx: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>,\n ) => TReturnType,\n>(\n /**\n * The function that actually renders the component\n */\n renderComponent: (\n ctx:\n | {\n component: TNodeRender\n props: NodeProps<TNodeType, TReturnType | TReturnType[]>\n }\n | {\n component: TMarkRender\n props: MarkProps<TMarkType, TReturnType | TReturnType[], TNodeType>\n },\n ) => TReturnType,\n {\n nodeMapping,\n markMapping,\n unhandledNode,\n unhandledMark,\n }: TiptapStaticRendererOptions<TReturnType, TMarkType, TNodeType, TNodeRender, TMarkRender>,\n) {\n /**\n * Render Tiptap JSON and all its children using the provided node and mark mappings.\n */\n return function renderContent({\n content,\n parent,\n }: {\n /**\n * Tiptap JSON content to render\n */\n content: TNodeType\n /**\n * The parent node of the current node\n */\n parent?: TNodeType\n }): TReturnType {\n const nodeType = typeof content.type === 'string' ? content.type : content.type.name\n const NodeHandler = nodeMapping[nodeType] ?? unhandledNode\n\n if (!NodeHandler) {\n throw new Error(`missing handler for node type ${nodeType}`)\n }\n\n const nodeContent = renderComponent({\n component: NodeHandler,\n props: {\n node: content,\n parent,\n renderElement: renderContent,\n // Lazily compute the children to avoid unnecessary recursion\n get children() {\n // recursively render child content nodes\n const children: TReturnType[] = []\n\n if (content.content) {\n content.content.forEach(child => {\n children.push(\n renderContent({\n content: child,\n parent: content,\n }),\n )\n })\n }\n\n return children\n },\n },\n })\n\n // apply marks to the content\n const markedContent = content.marks\n ? content.marks.reduce((acc, mark) => {\n const markType = typeof mark.type === 'string' ? mark.type : mark.type.name\n const MarkHandler = markMapping[markType] ?? unhandledMark\n\n if (!MarkHandler) {\n throw new Error(`missing handler for mark type ${markType}`)\n }\n\n return renderComponent({\n component: MarkHandler,\n props: {\n mark,\n parent,\n node: content,\n children: acc,\n },\n })\n }, nodeContent)\n : nodeContent\n\n return markedContent\n }\n}\n"],"mappings":";AAYA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,YAAY;;;ACnBrB,SAAgE,uBAAuB;AAQhF,SAAS,cACd,YACA,qBACA,wBACqB;AACrB,QAAM,uBAAuB,WAAW;AAExC,MAAI,CAAC,sBAAsB;AACzB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,oBACJ,OAA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