@tiptap/static-renderer 3.20.1 → 3.20.3

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 (43) hide show
  1. package/package.json +5 -5
  2. package/dist/index.cjs +0 -647
  3. package/dist/index.cjs.map +0 -1
  4. package/dist/index.d.cts +0 -334
  5. package/dist/index.d.ts +0 -334
  6. package/dist/index.js +0 -601
  7. package/dist/index.js.map +0 -1
  8. package/dist/json/html-string/index.cjs +0 -111
  9. package/dist/json/html-string/index.cjs.map +0 -1
  10. package/dist/json/html-string/index.d.cts +0 -201
  11. package/dist/json/html-string/index.d.ts +0 -201
  12. package/dist/json/html-string/index.js +0 -81
  13. package/dist/json/html-string/index.js.map +0 -1
  14. package/dist/json/react/index.cjs +0 -117
  15. package/dist/json/react/index.cjs.map +0 -1
  16. package/dist/json/react/index.d.cts +0 -190
  17. package/dist/json/react/index.d.ts +0 -190
  18. package/dist/json/react/index.js +0 -79
  19. package/dist/json/react/index.js.map +0 -1
  20. package/dist/json/renderer.cjs +0 -89
  21. package/dist/json/renderer.cjs.map +0 -1
  22. package/dist/json/renderer.d.cts +0 -166
  23. package/dist/json/renderer.d.ts +0 -166
  24. package/dist/json/renderer.js +0 -64
  25. package/dist/json/renderer.js.map +0 -1
  26. package/dist/pm/html-string/index.cjs +0 -348
  27. package/dist/pm/html-string/index.cjs.map +0 -1
  28. package/dist/pm/html-string/index.d.cts +0 -175
  29. package/dist/pm/html-string/index.d.ts +0 -175
  30. package/dist/pm/html-string/index.js +0 -321
  31. package/dist/pm/html-string/index.js.map +0 -1
  32. package/dist/pm/markdown/index.cjs +0 -478
  33. package/dist/pm/markdown/index.cjs.map +0 -1
  34. package/dist/pm/markdown/index.d.cts +0 -153
  35. package/dist/pm/markdown/index.d.ts +0 -153
  36. package/dist/pm/markdown/index.js +0 -454
  37. package/dist/pm/markdown/index.js.map +0 -1
  38. package/dist/pm/react/index.cjs +0 -412
  39. package/dist/pm/react/index.cjs.map +0 -1
  40. package/dist/pm/react/index.d.cts +0 -170
  41. package/dist/pm/react/index.d.ts +0 -170
  42. package/dist/pm/react/index.js +0 -376
  43. package/dist/pm/react/index.js.map +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/static-renderer",
3
3
  "description": "statically render Tiptap JSON",
4
- "version": "3.20.1",
4
+ "version": "3.20.3",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -76,14 +76,14 @@
76
76
  "@types/react-dom": "^19.0.0",
77
77
  "react": "^19.0.0",
78
78
  "react-dom": "^19.0.0",
79
- "@tiptap/core": "^3.20.1",
80
- "@tiptap/pm": "^3.20.1"
79
+ "@tiptap/core": "^3.20.3",
80
+ "@tiptap/pm": "^3.20.3"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
84
84
  "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0",
85
- "@tiptap/core": "^3.20.1",
86
- "@tiptap/pm": "^3.20.1"
85
+ "@tiptap/core": "^3.20.3",
86
+ "@tiptap/pm": "^3.20.3"
87
87
  },
88
88
  "repository": {
89
89
  "type": "git",
package/dist/index.cjs DELETED
@@ -1,647 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
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
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- TiptapStaticRenderer: () => TiptapStaticRenderer,
34
- domOutputSpecToHTMLString: () => domOutputSpecToHTMLString,
35
- domOutputSpecToReactElement: () => domOutputSpecToReactElement,
36
- getAttributes: () => getAttributes,
37
- getHTMLAttributes: () => getHTMLAttributes,
38
- mapAttrsToHTMLAttributes: () => mapAttrsToHTMLAttributes,
39
- mapMarkExtensionToReactNode: () => mapMarkExtensionToReactNode,
40
- mapNodeExtensionToReactNode: () => mapNodeExtensionToReactNode,
41
- renderJSONContentToReactElement: () => renderJSONContentToReactElement,
42
- renderJSONContentToString: () => renderJSONContentToString,
43
- renderToElement: () => renderToElement,
44
- renderToHTMLString: () => renderToHTMLString,
45
- renderToMarkdown: () => renderToMarkdown,
46
- renderToReactElement: () => renderToReactElement,
47
- serializeAttrsToHTMLString: () => serializeAttrsToHTMLString,
48
- serializeChildrenToHTMLString: () => serializeChildrenToHTMLString
49
- });
50
- module.exports = __toCommonJS(index_exports);
51
-
52
- // src/helpers.ts
53
- var import_core = require("@tiptap/core");
54
- function getAttributes(nodeOrMark, extensionAttributes, onlyRenderedAttributes) {
55
- const nodeOrMarkAttributes = nodeOrMark.attrs;
56
- if (!nodeOrMarkAttributes) {
57
- return {};
58
- }
59
- return extensionAttributes.filter((item) => {
60
- if (item.type !== (typeof nodeOrMark.type === "string" ? nodeOrMark.type : nodeOrMark.type.name)) {
61
- return false;
62
- }
63
- if (onlyRenderedAttributes) {
64
- return item.attribute.rendered;
65
- }
66
- return true;
67
- }).map((item) => {
68
- if (!item.attribute.renderHTML) {
69
- return {
70
- [item.name]: item.name in nodeOrMarkAttributes ? nodeOrMarkAttributes[item.name] : item.attribute.default
71
- };
72
- }
73
- return item.attribute.renderHTML(nodeOrMarkAttributes) || {
74
- [item.name]: item.name in nodeOrMarkAttributes ? nodeOrMarkAttributes[item.name] : item.attribute.default
75
- };
76
- }).reduce((attributes, attribute) => (0, import_core.mergeAttributes)(attributes, attribute), {});
77
- }
78
- function getHTMLAttributes(nodeOrMark, extensionAttributes) {
79
- return getAttributes(nodeOrMark, extensionAttributes, true);
80
- }
81
-
82
- // src/json/renderer.ts
83
- function TiptapStaticRenderer(renderComponent, {
84
- nodeMapping,
85
- markMapping,
86
- unhandledNode,
87
- unhandledMark
88
- }) {
89
- return function renderContent({
90
- content,
91
- parent
92
- }) {
93
- var _a;
94
- const nodeType = typeof content.type === "string" ? content.type : content.type.name;
95
- const NodeHandler = (_a = nodeMapping[nodeType]) != null ? _a : unhandledNode;
96
- if (!NodeHandler) {
97
- throw new Error(`missing handler for node type ${nodeType}`);
98
- }
99
- const nodeContent = renderComponent({
100
- component: NodeHandler,
101
- props: {
102
- node: content,
103
- parent,
104
- renderElement: renderContent,
105
- // Lazily compute the children to avoid unnecessary recursion
106
- get children() {
107
- const children = [];
108
- if (content.content) {
109
- content.content.forEach((child) => {
110
- children.push(
111
- renderContent({
112
- content: child,
113
- parent: content
114
- })
115
- );
116
- });
117
- }
118
- return children;
119
- }
120
- }
121
- });
122
- const markedContent = content.marks ? content.marks.reduce((acc, mark) => {
123
- var _a2;
124
- const markType = typeof mark.type === "string" ? mark.type : mark.type.name;
125
- const MarkHandler = (_a2 = markMapping[markType]) != null ? _a2 : unhandledMark;
126
- if (!MarkHandler) {
127
- throw new Error(`missing handler for mark type ${markType}`);
128
- }
129
- return renderComponent({
130
- component: MarkHandler,
131
- props: {
132
- mark,
133
- parent,
134
- node: content,
135
- children: acc
136
- }
137
- });
138
- }, nodeContent) : nodeContent;
139
- return markedContent;
140
- };
141
- }
142
-
143
- // src/json/html-string/string.ts
144
- function renderJSONContentToString(options) {
145
- return TiptapStaticRenderer((ctx) => {
146
- return ctx.component(ctx.props);
147
- }, options);
148
- }
149
- function serializeAttrsToHTMLString(attrs) {
150
- const output = Object.entries(attrs || {}).map(([key, value]) => `${key.split(" ").at(-1)}=${JSON.stringify(value)}`).join(" ");
151
- return output ? ` ${output}` : "";
152
- }
153
- function serializeChildrenToHTMLString(children) {
154
- return [].concat(children || "").filter(Boolean).join("");
155
- }
156
-
157
- // src/json/react/react.ts
158
- var import_react = __toESM(require("react"), 1);
159
- function renderJSONContentToReactElement(options) {
160
- let key = 0;
161
- return TiptapStaticRenderer(({ component, props: { children, ...props } }) => {
162
- return import_react.default.createElement(
163
- component,
164
- // eslint-disable-next-line no-plusplus
165
- Object.assign(props, { key: key++ }),
166
- [].concat(children)
167
- );
168
- }, options);
169
- }
170
-
171
- // src/pm/extensionRenderer.ts
172
- var import_core2 = require("@tiptap/core");
173
- var import_model = require("@tiptap/pm/model");
174
- function mapNodeExtensionToReactNode(domOutputSpecToElement, extension, extensionAttributes, options) {
175
- const context = {
176
- name: extension.name,
177
- options: extension.options,
178
- storage: extension.storage,
179
- parent: extension.parent
180
- };
181
- const renderToHTML = (0, import_core2.getExtensionField)(extension, "renderHTML", context);
182
- if (!renderToHTML) {
183
- if (options == null ? void 0 : options.unhandledNode) {
184
- return [extension.name, options.unhandledNode];
185
- }
186
- return [
187
- extension.name,
188
- () => {
189
- throw new Error(
190
- `[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`
191
- );
192
- }
193
- ];
194
- }
195
- return [
196
- extension.name,
197
- ({ node, children }) => {
198
- try {
199
- return domOutputSpecToElement(
200
- renderToHTML({
201
- node,
202
- HTMLAttributes: getHTMLAttributes(node, extensionAttributes)
203
- })
204
- )(children);
205
- } catch (e) {
206
- throw new Error(
207
- `[tiptap error]: Node ${extension.name} cannot be rendered, it's "renderToHTML" method threw an error: ${e.message}`,
208
- { cause: e }
209
- );
210
- }
211
- }
212
- ];
213
- }
214
- function mapMarkExtensionToReactNode(domOutputSpecToElement, extension, extensionAttributes, options) {
215
- const context = {
216
- name: extension.name,
217
- options: extension.options,
218
- storage: extension.storage,
219
- parent: extension.parent
220
- };
221
- const renderToHTML = (0, import_core2.getExtensionField)(extension, "renderHTML", context);
222
- if (!renderToHTML) {
223
- if (options == null ? void 0 : options.unhandledMark) {
224
- return [extension.name, options.unhandledMark];
225
- }
226
- return [
227
- extension.name,
228
- () => {
229
- throw new Error(`Node ${extension.name} cannot be rendered, it is missing a "renderToHTML" method`);
230
- }
231
- ];
232
- }
233
- return [
234
- extension.name,
235
- ({ mark, children }) => {
236
- try {
237
- return domOutputSpecToElement(
238
- renderToHTML({
239
- mark,
240
- HTMLAttributes: getHTMLAttributes(mark, extensionAttributes)
241
- })
242
- )(children);
243
- } catch (e) {
244
- throw new Error(
245
- `[tiptap error]: Mark ${extension.name} cannot be rendered, it's "renderToHTML" method threw an error: ${e.message}`,
246
- { cause: e }
247
- );
248
- }
249
- }
250
- ];
251
- }
252
- function renderToElement({
253
- renderer,
254
- domOutputSpecToElement,
255
- mapDefinedTypes,
256
- content,
257
- extensions,
258
- options
259
- }) {
260
- extensions = (0, import_core2.resolveExtensions)(extensions);
261
- const extensionAttributes = (0, import_core2.getAttributesFromExtensions)(extensions);
262
- const { nodeExtensions, markExtensions } = (0, import_core2.splitExtensions)(extensions);
263
- if (!(content instanceof import_model.Node)) {
264
- content = import_model.Node.fromJSON((0, import_core2.getSchemaByResolvedExtensions)(extensions), content);
265
- }
266
- return renderer({
267
- ...options,
268
- nodeMapping: {
269
- ...Object.fromEntries(
270
- nodeExtensions.filter((e) => {
271
- if (e.name in mapDefinedTypes) {
272
- return false;
273
- }
274
- if (options == null ? void 0 : options.nodeMapping) {
275
- return !(e.name in options.nodeMapping);
276
- }
277
- return true;
278
- }).map(
279
- (nodeExtension) => mapNodeExtensionToReactNode(domOutputSpecToElement, nodeExtension, extensionAttributes, options)
280
- )
281
- ),
282
- ...mapDefinedTypes,
283
- ...options == null ? void 0 : options.nodeMapping
284
- },
285
- markMapping: {
286
- ...Object.fromEntries(
287
- markExtensions.filter((e) => {
288
- if (options == null ? void 0 : options.markMapping) {
289
- return !(e.name in options.markMapping);
290
- }
291
- return true;
292
- }).map((mark) => mapMarkExtensionToReactNode(domOutputSpecToElement, mark, extensionAttributes, options))
293
- ),
294
- ...options == null ? void 0 : options.markMapping
295
- }
296
- })({ content });
297
- }
298
-
299
- // src/pm/html-string/html-string.ts
300
- var NON_SELF_CLOSING_TAGS = /* @__PURE__ */ new Set(["iframe", "script", "style", "title", "textarea", "div", "span", "a", "button"]);
301
- function domOutputSpecToHTMLString(content) {
302
- if (typeof content === "string") {
303
- return () => content;
304
- }
305
- if (typeof content === "object" && "length" in content) {
306
- const [_tag, attrs, children, ...rest] = content;
307
- let tag = _tag;
308
- const parts = tag.split(" ");
309
- if (parts.length > 1) {
310
- tag = `${parts[1]} xmlns="${parts[0]}"`;
311
- }
312
- if (attrs === void 0) {
313
- return () => `<${tag}/>`;
314
- }
315
- if (attrs === 0) {
316
- return (child) => `<${tag}>${serializeChildrenToHTMLString(child)}</${tag}>`;
317
- }
318
- if (typeof attrs === "object") {
319
- if (Array.isArray(attrs)) {
320
- if (children === void 0) {
321
- return (child) => `<${tag}>${domOutputSpecToHTMLString(attrs)(child)}</${tag}>`;
322
- }
323
- if (children === 0) {
324
- return (child) => `<${tag}>${domOutputSpecToHTMLString(attrs)(child)}</${tag}>`;
325
- }
326
- return (child) => `<${tag}>${domOutputSpecToHTMLString(attrs)(child)}${[children].concat(rest).map((a) => domOutputSpecToHTMLString(a)(child))}</${tag}>`;
327
- }
328
- if (children === void 0) {
329
- if (NON_SELF_CLOSING_TAGS.has(tag)) {
330
- return () => `<${tag}${serializeAttrsToHTMLString(attrs)}></${tag}>`;
331
- }
332
- return () => `<${tag}${serializeAttrsToHTMLString(attrs)}/>`;
333
- }
334
- if (children === 0) {
335
- return (child) => `<${tag}${serializeAttrsToHTMLString(attrs)}>${serializeChildrenToHTMLString(child)}</${tag}>`;
336
- }
337
- return (child) => `<${tag}${serializeAttrsToHTMLString(attrs)}>${[children].concat(rest).map((a) => domOutputSpecToHTMLString(a)(child)).join("")}</${tag}>`;
338
- }
339
- }
340
- throw new Error(
341
- "[tiptap error]: Unsupported DomOutputSpec type, check the `renderHTML` method output or implement a node mapping",
342
- {
343
- cause: content
344
- }
345
- );
346
- }
347
- function renderToHTMLString({
348
- content,
349
- extensions,
350
- options
351
- }) {
352
- return renderToElement({
353
- renderer: renderJSONContentToString,
354
- domOutputSpecToElement: domOutputSpecToHTMLString,
355
- mapDefinedTypes: {
356
- // Map a doc node to concatenated children
357
- doc: ({ children }) => serializeChildrenToHTMLString(children),
358
- // Map a text node to its text content
359
- text: ({ node }) => {
360
- var _a;
361
- return (_a = node.text) != null ? _a : "";
362
- }
363
- },
364
- content,
365
- extensions,
366
- options
367
- });
368
- }
369
-
370
- // src/pm/markdown/markdown.ts
371
- function renderToMarkdown({
372
- content,
373
- extensions,
374
- options
375
- }) {
376
- return renderToHTMLString({
377
- content,
378
- extensions,
379
- options: {
380
- ...options,
381
- nodeMapping: {
382
- bulletList({ children }) {
383
- return `
384
- ${serializeChildrenToHTMLString(children)}`;
385
- },
386
- orderedList({ children }) {
387
- return `
388
- ${serializeChildrenToHTMLString(children)}`;
389
- },
390
- listItem({ node, children, parent }) {
391
- if ((parent == null ? void 0 : parent.type.name) === "bulletList") {
392
- return `- ${serializeChildrenToHTMLString(children).trim()}
393
- `;
394
- }
395
- if ((parent == null ? void 0 : parent.type.name) === "orderedList") {
396
- let number = parent.attrs.start || 1;
397
- parent.forEach((parentChild, _offset, index) => {
398
- if (node === parentChild) {
399
- number = index + 1;
400
- }
401
- });
402
- return `${number}. ${serializeChildrenToHTMLString(children).trim()}
403
- `;
404
- }
405
- return serializeChildrenToHTMLString(children);
406
- },
407
- paragraph({ children }) {
408
- return `
409
- ${serializeChildrenToHTMLString(children)}
410
- `;
411
- },
412
- heading({ node, children }) {
413
- const level = node.attrs.level;
414
- return `${new Array(level).fill("#").join("")} ${children}
415
- `;
416
- },
417
- codeBlock({ node, children }) {
418
- return `
419
- \`\`\`${node.attrs.language}
420
- ${serializeChildrenToHTMLString(children)}
421
- \`\`\`
422
- `;
423
- },
424
- blockquote({ children }) {
425
- return `
426
- ${serializeChildrenToHTMLString(children).trim().split("\n").map((a) => `> ${a}`).join("\n")}`;
427
- },
428
- image({ node }) {
429
- return `![${node.attrs.alt}](${node.attrs.src})`;
430
- },
431
- hardBreak() {
432
- return "\n";
433
- },
434
- horizontalRule() {
435
- return "\n---\n";
436
- },
437
- table({ children, node }) {
438
- if (!Array.isArray(children)) {
439
- return `
440
- ${serializeChildrenToHTMLString(children)}
441
- `;
442
- }
443
- const columnCount = node.children[0].childCount;
444
- return `
445
- ${serializeChildrenToHTMLString(children[0])}| ${new Array(columnCount).fill("---").join(" | ")} |
446
- ${serializeChildrenToHTMLString(children.slice(1))}
447
- `;
448
- },
449
- tableRow({ children }) {
450
- if (Array.isArray(children)) {
451
- return `| ${children.join(" | ")} |
452
- `;
453
- }
454
- return `${serializeChildrenToHTMLString(children)}
455
- `;
456
- },
457
- tableHeader({ children }) {
458
- return serializeChildrenToHTMLString(children).trim();
459
- },
460
- tableCell({ children }) {
461
- return serializeChildrenToHTMLString(children).trim();
462
- },
463
- ...options == null ? void 0 : options.nodeMapping
464
- },
465
- markMapping: {
466
- bold({ children }) {
467
- return `**${serializeChildrenToHTMLString(children)}**`;
468
- },
469
- italic({ children, node }) {
470
- let isBoldToo = false;
471
- if (node == null ? void 0 : node.marks.some((m) => m.type.name === "bold")) {
472
- isBoldToo = true;
473
- }
474
- if (isBoldToo) {
475
- return `*${serializeChildrenToHTMLString(children)}*`;
476
- }
477
- return `_${serializeChildrenToHTMLString(children)}_`;
478
- },
479
- code({ children }) {
480
- return `\`${serializeChildrenToHTMLString(children)}\``;
481
- },
482
- strike({ children }) {
483
- return `~~${serializeChildrenToHTMLString(children)}~~`;
484
- },
485
- underline({ children }) {
486
- return `<u>${serializeChildrenToHTMLString(children)}</u>`;
487
- },
488
- subscript({ children }) {
489
- return `<sub>${serializeChildrenToHTMLString(children)}</sub>`;
490
- },
491
- superscript({ children }) {
492
- return `<sup>${serializeChildrenToHTMLString(children)}</sup>`;
493
- },
494
- link({ mark, children }) {
495
- return `[${serializeChildrenToHTMLString(children)}](${mark.attrs.href})`;
496
- },
497
- highlight({ children }) {
498
- return `==${serializeChildrenToHTMLString(children)}==`;
499
- },
500
- ...options == null ? void 0 : options.markMapping
501
- }
502
- }
503
- });
504
- }
505
-
506
- // src/pm/react/react.ts
507
- var import_react2 = __toESM(require("react"), 1);
508
- function mapAttrsToHTMLAttributes(attrs, key) {
509
- if (!attrs) {
510
- return { key };
511
- }
512
- return Object.entries(attrs).reduce(
513
- (acc, [name, value]) => {
514
- if (name === "class") {
515
- return Object.assign(acc, { className: value });
516
- }
517
- if (name === "style" && typeof value === "string") {
518
- const styleObject = {};
519
- value.split(";").forEach((style) => {
520
- const [styleKey, val] = style.split(":");
521
- if (styleKey && val) {
522
- const camelCaseKey = styleKey.trim().replace(/-([a-z])/g, (g) => g[1].toUpperCase());
523
- styleObject[camelCaseKey] = val.trim();
524
- }
525
- });
526
- return Object.assign(acc, { style: styleObject });
527
- }
528
- return Object.assign(acc, { [name]: value });
529
- },
530
- { key }
531
- );
532
- }
533
- function domOutputSpecToReactElement(content, key = 0) {
534
- if (typeof content === "string") {
535
- return () => content;
536
- }
537
- if (typeof content === "object" && "length" in content) {
538
- let [tag, attrs, children, ...rest] = content;
539
- const parts = tag.split(" ");
540
- if (parts.length > 1) {
541
- tag = parts[1];
542
- if (attrs === void 0) {
543
- attrs = {
544
- xmlns: parts[0]
545
- };
546
- }
547
- if (attrs === 0) {
548
- attrs = {
549
- xmlns: parts[0]
550
- };
551
- children = 0;
552
- }
553
- if (typeof attrs === "object") {
554
- attrs = Object.assign(attrs, { xmlns: parts[0] });
555
- }
556
- }
557
- if (attrs === void 0) {
558
- return () => import_react2.default.createElement(tag, mapAttrsToHTMLAttributes(void 0, key.toString()));
559
- }
560
- if (attrs === 0) {
561
- return (child) => import_react2.default.createElement(tag, mapAttrsToHTMLAttributes(void 0, key.toString()), child);
562
- }
563
- if (typeof attrs === "object") {
564
- if (Array.isArray(attrs)) {
565
- if (children === void 0) {
566
- return (child) => import_react2.default.createElement(
567
- tag,
568
- mapAttrsToHTMLAttributes(void 0, key.toString()),
569
- domOutputSpecToReactElement(attrs, key++)(child)
570
- );
571
- }
572
- if (children === 0) {
573
- return (child) => import_react2.default.createElement(
574
- tag,
575
- mapAttrsToHTMLAttributes(void 0, key.toString()),
576
- domOutputSpecToReactElement(attrs, key++)(child)
577
- );
578
- }
579
- return (child) => import_react2.default.createElement(
580
- tag,
581
- mapAttrsToHTMLAttributes(void 0, key.toString()),
582
- domOutputSpecToReactElement(attrs)(child),
583
- [children].concat(rest).map((outputSpec) => domOutputSpecToReactElement(outputSpec, key++)(child))
584
- );
585
- }
586
- if (children === void 0) {
587
- return () => import_react2.default.createElement(tag, mapAttrsToHTMLAttributes(attrs, key.toString()));
588
- }
589
- if (children === 0) {
590
- return (child) => import_react2.default.createElement(tag, mapAttrsToHTMLAttributes(attrs, key.toString()), child);
591
- }
592
- return (child) => import_react2.default.createElement(
593
- tag,
594
- mapAttrsToHTMLAttributes(attrs, key.toString()),
595
- [children].concat(rest).map((outputSpec) => domOutputSpecToReactElement(outputSpec, key++)(child))
596
- );
597
- }
598
- }
599
- throw new Error(
600
- "[tiptap error]: Unsupported DomOutputSpec type, check the `renderHTML` method output or implement a node mapping",
601
- {
602
- cause: content
603
- }
604
- );
605
- }
606
- function renderToReactElement({
607
- content,
608
- extensions,
609
- options
610
- }) {
611
- return renderToElement({
612
- renderer: renderJSONContentToReactElement,
613
- domOutputSpecToElement: domOutputSpecToReactElement,
614
- mapDefinedTypes: {
615
- // Map a doc node to concatenated children
616
- doc: ({ children }) => import_react2.default.createElement(import_react2.default.Fragment, {}, children),
617
- // Map a text node to its text content
618
- text: ({ node }) => {
619
- var _a;
620
- return (_a = node.text) != null ? _a : "";
621
- }
622
- },
623
- content,
624
- extensions,
625
- options
626
- });
627
- }
628
- // Annotate the CommonJS export names for ESM import in node:
629
- 0 && (module.exports = {
630
- TiptapStaticRenderer,
631
- domOutputSpecToHTMLString,
632
- domOutputSpecToReactElement,
633
- getAttributes,
634
- getHTMLAttributes,
635
- mapAttrsToHTMLAttributes,
636
- mapMarkExtensionToReactNode,
637
- mapNodeExtensionToReactNode,
638
- renderJSONContentToReactElement,
639
- renderJSONContentToString,
640
- renderToElement,
641
- renderToHTMLString,
642
- renderToMarkdown,
643
- renderToReactElement,
644
- serializeAttrsToHTMLString,
645
- serializeChildrenToHTMLString
646
- });
647
- //# sourceMappingURL=index.cjs.map