@tiptap/static-renderer 3.0.0-next.1 → 3.0.0-next.5

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 (60) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +1 -1
  3. package/dist/index.cjs +573 -6
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +307 -32
  6. package/dist/index.d.ts +307 -32
  7. package/dist/index.js +552 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/json/html-string/index.cjs +16 -5
  10. package/dist/json/html-string/index.cjs.map +1 -1
  11. package/dist/json/html-string/index.d.cts +18 -22
  12. package/dist/json/html-string/index.d.ts +18 -22
  13. package/dist/json/html-string/index.js +10 -1
  14. package/dist/json/html-string/index.js.map +1 -1
  15. package/dist/json/react/index.cjs +13 -2202
  16. package/dist/json/react/index.cjs.map +1 -1
  17. package/dist/json/react/index.d.cts +5 -22
  18. package/dist/json/react/index.d.ts +5 -22
  19. package/dist/json/react/index.js +10 -2222
  20. package/dist/json/react/index.js.map +1 -1
  21. package/dist/json/renderer.cjs.map +1 -1
  22. package/dist/json/renderer.d.cts +5 -21
  23. package/dist/json/renderer.d.ts +5 -21
  24. package/dist/json/renderer.js.map +1 -1
  25. package/dist/pm/html-string/index.cjs +22 -37
  26. package/dist/pm/html-string/index.cjs.map +1 -1
  27. package/dist/pm/html-string/index.d.cts +7 -24
  28. package/dist/pm/html-string/index.d.ts +7 -24
  29. package/dist/pm/html-string/index.js +19 -34
  30. package/dist/pm/html-string/index.js.map +1 -1
  31. package/dist/pm/markdown/index.cjs +473 -0
  32. package/dist/pm/markdown/index.cjs.map +1 -0
  33. package/dist/pm/markdown/index.d.cts +153 -0
  34. package/dist/pm/markdown/index.d.ts +153 -0
  35. package/dist/pm/markdown/index.js +449 -0
  36. package/dist/pm/markdown/index.js.map +1 -0
  37. package/dist/pm/react/index.cjs +46 -2235
  38. package/dist/pm/react/index.cjs.map +1 -1
  39. package/dist/pm/react/index.d.cts +5 -23
  40. package/dist/pm/react/index.d.ts +5 -23
  41. package/dist/pm/react/index.js +51 -2263
  42. package/dist/pm/react/index.js.map +1 -1
  43. package/package.json +27 -8
  44. package/src/helpers.ts +5 -16
  45. package/src/index.ts +5 -1
  46. package/src/json/html-string/string.ts +39 -13
  47. package/src/json/react/{react.tsx → react.ts} +12 -15
  48. package/src/json/renderer.ts +50 -51
  49. package/src/pm/extensionRenderer.ts +16 -34
  50. package/src/pm/html-string/html-string.ts +29 -45
  51. package/src/pm/markdown/index.ts +2 -0
  52. package/src/pm/markdown/markdown.ts +142 -0
  53. package/src/pm/react/{react.tsx → react.ts} +50 -31
  54. package/src/helpers.example.ts +0 -35
  55. package/src/json/html-string/string.example.ts +0 -46
  56. package/src/json/react/react.example.ts +0 -45
  57. package/src/pm/html-string/html-string.example.ts +0 -225
  58. package/src/pm/markdown/markdown.example.ts +0 -296
  59. package/src/pm/react/react.example.tsx +0 -306
  60. package/src/types.ts +0 -57
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Tiptap GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Introduction
9
9
 
10
- Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
10
+ Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as _New York Times_, _The Guardian_ or _Atlassian_.
11
11
 
12
12
  ## Official Documentation
13
13
 
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,15 +17,36 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ TiptapStaticRenderer: () => TiptapStaticRenderer,
34
+ domOutputSpecToHTMLString: () => domOutputSpecToHTMLString,
35
+ domOutputSpecToReactElement: () => domOutputSpecToReactElement,
23
36
  getAttributes: () => getAttributes,
24
- getHTMLAttributes: () => getHTMLAttributes
37
+ getHTMLAttributes: () => getHTMLAttributes,
38
+ mapMarkExtensionToReactNode: () => mapMarkExtensionToReactNode,
39
+ mapNodeExtensionToReactNode: () => mapNodeExtensionToReactNode,
40
+ renderJSONContentToReactElement: () => renderJSONContentToReactElement,
41
+ renderJSONContentToString: () => renderJSONContentToString,
42
+ renderToElement: () => renderToElement,
43
+ renderToHTMLString: () => renderToHTMLString,
44
+ renderToMarkdown: () => renderToMarkdown,
45
+ renderToReactElement: () => renderToReactElement,
46
+ serializeAttrsToHTMLString: () => serializeAttrsToHTMLString,
47
+ serializeChildrenToHTMLString: () => serializeChildrenToHTMLString
25
48
  });
26
- module.exports = __toCommonJS(src_exports);
49
+ module.exports = __toCommonJS(index_exports);
27
50
 
28
51
  // src/helpers.ts
29
52
  var import_core = require("@tiptap/core");
@@ -33,7 +56,7 @@ function getAttributes(nodeOrMark, extensionAttributes, onlyRenderedAttributes)
33
56
  return {};
34
57
  }
35
58
  return extensionAttributes.filter((item) => {
36
- if (item.type !== nodeOrMark.type) {
59
+ if (item.type !== (typeof nodeOrMark.type === "string" ? nodeOrMark.type : nodeOrMark.type.name)) {
37
60
  return false;
38
61
  }
39
62
  if (onlyRenderedAttributes) {
@@ -54,9 +77,553 @@ function getAttributes(nodeOrMark, extensionAttributes, onlyRenderedAttributes)
54
77
  function getHTMLAttributes(nodeOrMark, extensionAttributes) {
55
78
  return getAttributes(nodeOrMark, extensionAttributes, true);
56
79
  }
80
+
81
+ // src/json/renderer.ts
82
+ function TiptapStaticRenderer(renderComponent, {
83
+ nodeMapping,
84
+ markMapping,
85
+ unhandledNode,
86
+ unhandledMark
87
+ }) {
88
+ return function renderContent({
89
+ content,
90
+ parent
91
+ }) {
92
+ var _a;
93
+ const nodeType = typeof content.type === "string" ? content.type : content.type.name;
94
+ const NodeHandler = (_a = nodeMapping[nodeType]) != null ? _a : unhandledNode;
95
+ if (!NodeHandler) {
96
+ throw new Error(`missing handler for node type ${nodeType}`);
97
+ }
98
+ const nodeContent = renderComponent({
99
+ component: NodeHandler,
100
+ props: {
101
+ node: content,
102
+ parent,
103
+ renderElement: renderContent,
104
+ // Lazily compute the children to avoid unnecessary recursion
105
+ get children() {
106
+ const children = [];
107
+ if (content.content) {
108
+ content.content.forEach((child) => {
109
+ children.push(
110
+ renderContent({
111
+ content: child,
112
+ parent: content
113
+ })
114
+ );
115
+ });
116
+ }
117
+ return children;
118
+ }
119
+ }
120
+ });
121
+ const markedContent = content.marks ? content.marks.reduce((acc, mark) => {
122
+ var _a2;
123
+ const markType = typeof mark.type === "string" ? mark.type : mark.type.name;
124
+ const MarkHandler = (_a2 = markMapping[markType]) != null ? _a2 : unhandledMark;
125
+ if (!MarkHandler) {
126
+ throw new Error(`missing handler for mark type ${markType}`);
127
+ }
128
+ return renderComponent({
129
+ component: MarkHandler,
130
+ props: {
131
+ mark,
132
+ parent,
133
+ node: content,
134
+ children: acc
135
+ }
136
+ });
137
+ }, nodeContent) : nodeContent;
138
+ return markedContent;
139
+ };
140
+ }
141
+
142
+ // src/json/html-string/string.ts
143
+ function renderJSONContentToString(options) {
144
+ return TiptapStaticRenderer((ctx) => {
145
+ return ctx.component(ctx.props);
146
+ }, options);
147
+ }
148
+ function serializeAttrsToHTMLString(attrs) {
149
+ const output = Object.entries(attrs || {}).map(([key, value]) => `${key.split(" ").at(-1)}=${JSON.stringify(value)}`).join(" ");
150
+ return output ? ` ${output}` : "";
151
+ }
152
+ function serializeChildrenToHTMLString(children) {
153
+ return [].concat(children || "").filter(Boolean).join("");
154
+ }
155
+
156
+ // src/json/react/react.ts
157
+ var import_react = __toESM(require("react"), 1);
158
+ function renderJSONContentToReactElement(options) {
159
+ let key = 0;
160
+ return TiptapStaticRenderer(({ component, props: { children, ...props } }) => {
161
+ return import_react.default.createElement(
162
+ component,
163
+ // eslint-disable-next-line no-plusplus
164
+ Object.assign(props, { key: key++ }),
165
+ [].concat(children)
166
+ );
167
+ }, options);
168
+ }
169
+
170
+ // src/pm/extensionRenderer.ts
171
+ var import_core2 = require("@tiptap/core");
172
+ var import_model = require("@tiptap/pm/model");
173
+ function mapNodeExtensionToReactNode(domOutputSpecToElement, extension, extensionAttributes, options) {
174
+ const context = {
175
+ name: extension.name,
176
+ options: extension.options,
177
+ storage: extension.storage,
178
+ parent: extension.parent
179
+ };
180
+ const renderToHTML = (0, import_core2.getExtensionField)(extension, "renderHTML", context);
181
+ if (!renderToHTML) {
182
+ if (options == null ? void 0 : options.unhandledNode) {
183
+ return [extension.name, options.unhandledNode];
184
+ }
185
+ return [
186
+ extension.name,
187
+ () => {
188
+ throw new Error(
189
+ `[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`
190
+ );
191
+ }
192
+ ];
193
+ }
194
+ return [
195
+ extension.name,
196
+ ({ node, children }) => {
197
+ try {
198
+ return domOutputSpecToElement(
199
+ renderToHTML({
200
+ node,
201
+ HTMLAttributes: getHTMLAttributes(node, extensionAttributes)
202
+ })
203
+ )(children);
204
+ } catch (e) {
205
+ throw new Error(
206
+ `[tiptap error]: Node ${extension.name} cannot be rendered, it's "renderToHTML" method threw an error: ${e.message}`,
207
+ { cause: e }
208
+ );
209
+ }
210
+ }
211
+ ];
212
+ }
213
+ function mapMarkExtensionToReactNode(domOutputSpecToElement, extension, extensionAttributes, options) {
214
+ const context = {
215
+ name: extension.name,
216
+ options: extension.options,
217
+ storage: extension.storage,
218
+ parent: extension.parent
219
+ };
220
+ const renderToHTML = (0, import_core2.getExtensionField)(extension, "renderHTML", context);
221
+ if (!renderToHTML) {
222
+ if (options == null ? void 0 : options.unhandledMark) {
223
+ return [extension.name, options.unhandledMark];
224
+ }
225
+ return [
226
+ extension.name,
227
+ () => {
228
+ throw new Error(`Node ${extension.name} cannot be rendered, it is missing a "renderToHTML" method`);
229
+ }
230
+ ];
231
+ }
232
+ return [
233
+ extension.name,
234
+ ({ mark, children }) => {
235
+ try {
236
+ return domOutputSpecToElement(
237
+ renderToHTML({
238
+ mark,
239
+ HTMLAttributes: getHTMLAttributes(mark, extensionAttributes)
240
+ })
241
+ )(children);
242
+ } catch (e) {
243
+ throw new Error(
244
+ `[tiptap error]: Mark ${extension.name} cannot be rendered, it's "renderToHTML" method threw an error: ${e.message}`,
245
+ { cause: e }
246
+ );
247
+ }
248
+ }
249
+ ];
250
+ }
251
+ function renderToElement({
252
+ renderer,
253
+ domOutputSpecToElement,
254
+ mapDefinedTypes,
255
+ content,
256
+ extensions,
257
+ options
258
+ }) {
259
+ extensions = (0, import_core2.resolveExtensions)(extensions);
260
+ const extensionAttributes = (0, import_core2.getAttributesFromExtensions)(extensions);
261
+ const { nodeExtensions, markExtensions } = (0, import_core2.splitExtensions)(extensions);
262
+ if (!(content instanceof import_model.Node)) {
263
+ content = import_model.Node.fromJSON((0, import_core2.getSchemaByResolvedExtensions)(extensions), content);
264
+ }
265
+ return renderer({
266
+ ...options,
267
+ nodeMapping: {
268
+ ...Object.fromEntries(
269
+ nodeExtensions.filter((e) => {
270
+ if (e.name in mapDefinedTypes) {
271
+ return false;
272
+ }
273
+ if (options == null ? void 0 : options.nodeMapping) {
274
+ return !(e.name in options.nodeMapping);
275
+ }
276
+ return true;
277
+ }).map(
278
+ (nodeExtension) => mapNodeExtensionToReactNode(domOutputSpecToElement, nodeExtension, extensionAttributes, options)
279
+ )
280
+ ),
281
+ ...mapDefinedTypes,
282
+ ...options == null ? void 0 : options.nodeMapping
283
+ },
284
+ markMapping: {
285
+ ...Object.fromEntries(
286
+ markExtensions.filter((e) => {
287
+ if (options == null ? void 0 : options.markMapping) {
288
+ return !(e.name in options.markMapping);
289
+ }
290
+ return true;
291
+ }).map((mark) => mapMarkExtensionToReactNode(domOutputSpecToElement, mark, extensionAttributes, options))
292
+ ),
293
+ ...options == null ? void 0 : options.markMapping
294
+ }
295
+ })({ content });
296
+ }
297
+
298
+ // src/pm/html-string/html-string.ts
299
+ function domOutputSpecToHTMLString(content) {
300
+ if (typeof content === "string") {
301
+ return () => content;
302
+ }
303
+ if (typeof content === "object" && "length" in content) {
304
+ const [_tag, attrs, children, ...rest] = content;
305
+ let tag = _tag;
306
+ const parts = tag.split(" ");
307
+ if (parts.length > 1) {
308
+ tag = `${parts[1]} xmlns="${parts[0]}"`;
309
+ }
310
+ if (attrs === void 0) {
311
+ return () => `<${tag}/>`;
312
+ }
313
+ if (attrs === 0) {
314
+ return (child) => `<${tag}>${serializeChildrenToHTMLString(child)}</${tag}>`;
315
+ }
316
+ if (typeof attrs === "object") {
317
+ if (Array.isArray(attrs)) {
318
+ if (children === void 0) {
319
+ return (child) => `<${tag}>${domOutputSpecToHTMLString(attrs)(child)}</${tag}>`;
320
+ }
321
+ if (children === 0) {
322
+ return (child) => `<${tag}>${domOutputSpecToHTMLString(attrs)(child)}</${tag}>`;
323
+ }
324
+ return (child) => `<${tag}>${domOutputSpecToHTMLString(attrs)(child)}${[children].concat(rest).map((a) => domOutputSpecToHTMLString(a)(child))}</${tag}>`;
325
+ }
326
+ if (children === void 0) {
327
+ return () => `<${tag}${serializeAttrsToHTMLString(attrs)}/>`;
328
+ }
329
+ if (children === 0) {
330
+ return (child) => `<${tag}${serializeAttrsToHTMLString(attrs)}>${serializeChildrenToHTMLString(child)}</${tag}>`;
331
+ }
332
+ return (child) => `<${tag}${serializeAttrsToHTMLString(attrs)}>${[children].concat(rest).map((a) => domOutputSpecToHTMLString(a)(child)).join("")}</${tag}>`;
333
+ }
334
+ }
335
+ throw new Error(
336
+ "[tiptap error]: Unsupported DomOutputSpec type, check the `renderHTML` method output or implement a node mapping",
337
+ {
338
+ cause: content
339
+ }
340
+ );
341
+ }
342
+ function renderToHTMLString({
343
+ content,
344
+ extensions,
345
+ options
346
+ }) {
347
+ return renderToElement({
348
+ renderer: renderJSONContentToString,
349
+ domOutputSpecToElement: domOutputSpecToHTMLString,
350
+ mapDefinedTypes: {
351
+ // Map a doc node to concatenated children
352
+ doc: ({ children }) => serializeChildrenToHTMLString(children),
353
+ // Map a text node to its text content
354
+ text: ({ node }) => {
355
+ var _a;
356
+ return (_a = node.text) != null ? _a : "";
357
+ }
358
+ },
359
+ content,
360
+ extensions,
361
+ options
362
+ });
363
+ }
364
+
365
+ // src/pm/markdown/markdown.ts
366
+ function renderToMarkdown({
367
+ content,
368
+ extensions,
369
+ options
370
+ }) {
371
+ return renderToHTMLString({
372
+ content,
373
+ extensions,
374
+ options: {
375
+ nodeMapping: {
376
+ bulletList({ children }) {
377
+ return `
378
+ ${serializeChildrenToHTMLString(children)}`;
379
+ },
380
+ orderedList({ children }) {
381
+ return `
382
+ ${serializeChildrenToHTMLString(children)}`;
383
+ },
384
+ listItem({ node, children, parent }) {
385
+ if ((parent == null ? void 0 : parent.type.name) === "bulletList") {
386
+ return `- ${serializeChildrenToHTMLString(children).trim()}
387
+ `;
388
+ }
389
+ if ((parent == null ? void 0 : parent.type.name) === "orderedList") {
390
+ let number = parent.attrs.start || 1;
391
+ parent.forEach((parentChild, _offset, index) => {
392
+ if (node === parentChild) {
393
+ number = index + 1;
394
+ }
395
+ });
396
+ return `${number}. ${serializeChildrenToHTMLString(children).trim()}
397
+ `;
398
+ }
399
+ return serializeChildrenToHTMLString(children);
400
+ },
401
+ paragraph({ children }) {
402
+ return `
403
+ ${serializeChildrenToHTMLString(children)}
404
+ `;
405
+ },
406
+ heading({ node, children }) {
407
+ const level = node.attrs.level;
408
+ return `${new Array(level).fill("#").join("")} ${children}
409
+ `;
410
+ },
411
+ codeBlock({ node, children }) {
412
+ return `
413
+ \`\`\`${node.attrs.language}
414
+ ${serializeChildrenToHTMLString(children)}
415
+ \`\`\`
416
+ `;
417
+ },
418
+ blockquote({ children }) {
419
+ return `
420
+ ${serializeChildrenToHTMLString(children).trim().split("\n").map((a) => `> ${a}`).join("\n")}`;
421
+ },
422
+ image({ node }) {
423
+ return `![${node.attrs.alt}](${node.attrs.src})`;
424
+ },
425
+ hardBreak() {
426
+ return "\n";
427
+ },
428
+ horizontalRule() {
429
+ return "\n---\n";
430
+ },
431
+ table({ children, node }) {
432
+ if (!Array.isArray(children)) {
433
+ return `
434
+ ${serializeChildrenToHTMLString(children)}
435
+ `;
436
+ }
437
+ return `
438
+ ${serializeChildrenToHTMLString(children[0])}| ${new Array(node.childCount - 2).fill("---").join(" | ")} |
439
+ ${serializeChildrenToHTMLString(children.slice(1))}
440
+ `;
441
+ },
442
+ tableRow({ children }) {
443
+ if (Array.isArray(children)) {
444
+ return `| ${children.join(" | ")} |
445
+ `;
446
+ }
447
+ return `${serializeChildrenToHTMLString(children)}
448
+ `;
449
+ },
450
+ tableHeader({ children }) {
451
+ return serializeChildrenToHTMLString(children).trim();
452
+ },
453
+ tableCell({ children }) {
454
+ return serializeChildrenToHTMLString(children).trim();
455
+ },
456
+ ...options == null ? void 0 : options.nodeMapping
457
+ },
458
+ markMapping: {
459
+ bold({ children }) {
460
+ return `**${serializeChildrenToHTMLString(children)}**`;
461
+ },
462
+ italic({ children, node }) {
463
+ let isBoldToo = false;
464
+ if (node == null ? void 0 : node.marks.some((m) => m.type.name === "bold")) {
465
+ isBoldToo = true;
466
+ }
467
+ if (isBoldToo) {
468
+ return `*${serializeChildrenToHTMLString(children)}*`;
469
+ }
470
+ return `_${serializeChildrenToHTMLString(children)}_`;
471
+ },
472
+ code({ children }) {
473
+ return `\`${serializeChildrenToHTMLString(children)}\``;
474
+ },
475
+ strike({ children }) {
476
+ return `~~${serializeChildrenToHTMLString(children)}~~`;
477
+ },
478
+ underline({ children }) {
479
+ return `<u>${serializeChildrenToHTMLString(children)}</u>`;
480
+ },
481
+ subscript({ children }) {
482
+ return `<sub>${serializeChildrenToHTMLString(children)}</sub>`;
483
+ },
484
+ superscript({ children }) {
485
+ return `<sup>${serializeChildrenToHTMLString(children)}</sup>`;
486
+ },
487
+ link({ node, children }) {
488
+ return `[${serializeChildrenToHTMLString(children)}](${node.attrs.href})`;
489
+ },
490
+ highlight({ children }) {
491
+ return `==${serializeChildrenToHTMLString(children)}==`;
492
+ },
493
+ ...options == null ? void 0 : options.markMapping
494
+ },
495
+ ...options
496
+ }
497
+ });
498
+ }
499
+
500
+ // src/pm/react/react.ts
501
+ var import_react2 = __toESM(require("react"), 1);
502
+ function mapAttrsToHTMLAttributes(attrs, key) {
503
+ if (!attrs) {
504
+ return { key };
505
+ }
506
+ return Object.entries(attrs).reduce(
507
+ (acc, [name, value]) => {
508
+ if (name === "class") {
509
+ return Object.assign(acc, { className: value });
510
+ }
511
+ return Object.assign(acc, { [name]: value });
512
+ },
513
+ { key }
514
+ );
515
+ }
516
+ function domOutputSpecToReactElement(content, key = 0) {
517
+ if (typeof content === "string") {
518
+ return () => content;
519
+ }
520
+ if (typeof content === "object" && "length" in content) {
521
+ let [tag, attrs, children, ...rest] = content;
522
+ const parts = tag.split(" ");
523
+ if (parts.length > 1) {
524
+ tag = parts[1];
525
+ if (attrs === void 0) {
526
+ attrs = {
527
+ xmlns: parts[0]
528
+ };
529
+ }
530
+ if (attrs === 0) {
531
+ attrs = {
532
+ xmlns: parts[0]
533
+ };
534
+ children = 0;
535
+ }
536
+ if (typeof attrs === "object") {
537
+ attrs = Object.assign(attrs, { xmlns: parts[0] });
538
+ }
539
+ }
540
+ if (attrs === void 0) {
541
+ return () => import_react2.default.createElement(tag, mapAttrsToHTMLAttributes(void 0, key.toString()));
542
+ }
543
+ if (attrs === 0) {
544
+ return (child) => import_react2.default.createElement(tag, mapAttrsToHTMLAttributes(void 0, key.toString()), child);
545
+ }
546
+ if (typeof attrs === "object") {
547
+ if (Array.isArray(attrs)) {
548
+ if (children === void 0) {
549
+ return (child) => import_react2.default.createElement(
550
+ tag,
551
+ mapAttrsToHTMLAttributes(void 0, key.toString()),
552
+ domOutputSpecToReactElement(attrs, key++)(child)
553
+ );
554
+ }
555
+ if (children === 0) {
556
+ return (child) => import_react2.default.createElement(
557
+ tag,
558
+ mapAttrsToHTMLAttributes(void 0, key.toString()),
559
+ domOutputSpecToReactElement(attrs, key++)(child)
560
+ );
561
+ }
562
+ return (child) => import_react2.default.createElement(
563
+ tag,
564
+ mapAttrsToHTMLAttributes(void 0, key.toString()),
565
+ domOutputSpecToReactElement(attrs)(child),
566
+ [children].concat(rest).map((outputSpec) => domOutputSpecToReactElement(outputSpec, key++)(child))
567
+ );
568
+ }
569
+ if (children === void 0) {
570
+ return () => import_react2.default.createElement(tag, mapAttrsToHTMLAttributes(attrs, key.toString()));
571
+ }
572
+ if (children === 0) {
573
+ return (child) => import_react2.default.createElement(tag, mapAttrsToHTMLAttributes(attrs, key.toString()), child);
574
+ }
575
+ return (child) => import_react2.default.createElement(
576
+ tag,
577
+ mapAttrsToHTMLAttributes(attrs, key.toString()),
578
+ [children].concat(rest).map((outputSpec) => domOutputSpecToReactElement(outputSpec, key++)(child))
579
+ );
580
+ }
581
+ }
582
+ throw new Error(
583
+ "[tiptap error]: Unsupported DomOutputSpec type, check the `renderHTML` method output or implement a node mapping",
584
+ {
585
+ cause: content
586
+ }
587
+ );
588
+ }
589
+ function renderToReactElement({
590
+ content,
591
+ extensions,
592
+ options
593
+ }) {
594
+ return renderToElement({
595
+ renderer: renderJSONContentToReactElement,
596
+ domOutputSpecToElement: domOutputSpecToReactElement,
597
+ mapDefinedTypes: {
598
+ // Map a doc node to concatenated children
599
+ doc: ({ children }) => import_react2.default.createElement(import_react2.default.Fragment, {}, children),
600
+ // Map a text node to its text content
601
+ text: ({ node }) => {
602
+ var _a;
603
+ return (_a = node.text) != null ? _a : "";
604
+ }
605
+ },
606
+ content,
607
+ extensions,
608
+ options
609
+ });
610
+ }
57
611
  // Annotate the CommonJS export names for ESM import in node:
58
612
  0 && (module.exports = {
613
+ TiptapStaticRenderer,
614
+ domOutputSpecToHTMLString,
615
+ domOutputSpecToReactElement,
59
616
  getAttributes,
60
- getHTMLAttributes
617
+ getHTMLAttributes,
618
+ mapMarkExtensionToReactNode,
619
+ mapNodeExtensionToReactNode,
620
+ renderJSONContentToReactElement,
621
+ renderJSONContentToString,
622
+ renderToElement,
623
+ renderToHTMLString,
624
+ renderToMarkdown,
625
+ renderToReactElement,
626
+ serializeAttrsToHTMLString,
627
+ serializeChildrenToHTMLString
61
628
  });
62
629
  //# sourceMappingURL=index.cjs.map