@tiptap/static-renderer 3.0.0-next.4 → 3.0.0-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024, Tiptap GmbH
3
+ Copyright (c) 2025, Tiptap GmbH
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.cjs CHANGED
@@ -153,7 +153,7 @@ function serializeChildrenToHTMLString(children) {
153
153
  return [].concat(children || "").filter(Boolean).join("");
154
154
  }
155
155
 
156
- // src/json/react/react.tsx
156
+ // src/json/react/react.ts
157
157
  var import_react = __toESM(require("react"), 1);
158
158
  function renderJSONContentToReactElement(options) {
159
159
  let key = 0;
@@ -497,7 +497,7 @@ ${serializeChildrenToHTMLString(children.slice(1))}
497
497
  });
498
498
  }
499
499
 
500
- // src/pm/react/react.tsx
500
+ // src/pm/react/react.ts
501
501
  var import_react2 = __toESM(require("react"), 1);
502
502
  function mapAttrsToHTMLAttributes(attrs, key) {
503
503
  if (!attrs) {
@@ -596,7 +596,7 @@ function renderToReactElement({
596
596
  domOutputSpecToElement: domOutputSpecToReactElement,
597
597
  mapDefinedTypes: {
598
598
  // Map a doc node to concatenated children
599
- doc: ({ children }) => /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, children),
599
+ doc: ({ children }) => import_react2.default.createElement(import_react2.default.Fragment, {}, children),
600
600
  // Map a text node to its text content
601
601
  text: ({ node }) => {
602
602
  var _a;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/helpers.ts","../src/json/renderer.ts","../src/json/html-string/string.ts","../src/json/react/react.tsx","../src/pm/extensionRenderer.ts","../src/pm/html-string/html-string.ts","../src/pm/markdown/markdown.ts","../src/pm/react/react.tsx"],"sourcesContent":["export * from './helpers.js'\nexport * from './json/html-string/index.js'\nexport * from './json/react/index.js'\nexport * from './pm/html-string/index.js'\nexport * from './pm/markdown/index.js'\nexport * from './pm/react/index.js'\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 @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","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { MarkType, NodeType } from '@tiptap/core'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } from '../renderer.js'\n\nexport function renderJSONContentToString<\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<string, TMarkType, TNodeType>) {\n return TiptapStaticRenderer(ctx => {\n return ctx.component(ctx.props as any)\n }, options)\n}\n\n/**\n * Serialize the attributes of a node or mark to a string\n * @param attrs The attributes to serialize\n * @returns The serialized attributes as a string\n */\nexport function serializeAttrsToHTMLString(attrs: Record<string, any> | undefined | null): string {\n const output = Object.entries(attrs || {})\n .map(([key, value]) => `${key.split(' ').at(-1)}=${JSON.stringify(value)}`)\n .join(' ')\n\n return output ? ` ${output}` : ''\n}\n\n/**\n * Serialize the children of a node or mark to a string\n * @param children The children to serialize\n * @returns The serialized children as a string\n */\nexport function serializeChildrenToHTMLString(children?: string | string[]): string {\n return ([] as string[])\n .concat(children || '')\n .filter(Boolean)\n .join('')\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { MarkType, NodeType } from '@tiptap/core'\nimport React from 'react'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } 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 no-plusplus */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n ExtensionAttribute,\n Extensions,\n getAttributesFromExtensions,\n getExtensionField,\n getSchemaByResolvedExtensions,\n JSONContent,\n Mark as MarkExtension,\n MarkConfig,\n Node as NodeExtension,\n NodeConfig,\n resolveExtensions,\n splitExtensions,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport { getHTMLAttributes } from '../helpers.js'\nimport { 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 { DOMOutputSpecArray, Extensions, JSONContent } from '@tiptap/core'\nimport type { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport {\n renderJSONContentToString,\n serializeAttrsToHTMLString,\n serializeChildrenToHTMLString,\n} from '../../json/html-string/string.js'\nimport { TiptapStaticRendererOptions } from '../../json/renderer.js'\nimport { renderToElement } from '../extensionRenderer.js'\n\nexport { serializeAttrsToHTMLString, serializeChildrenToHTMLString } from '../../json/html-string/string.js'\n\n/**\n * Take a DOMOutputSpec and return a function that can render it to a string\n * @param content The DOMOutputSpec to convert to a string\n * @returns A function that can render the DOMOutputSpec to a string\n */\nexport function domOutputSpecToHTMLString(content: DOMOutputSpec): (children?: string | string[]) => string {\n if (typeof content === 'string') {\n return () => content\n }\n if (typeof content === 'object' && 'length' in content) {\n const [_tag, attrs, children, ...rest] = content as DOMOutputSpecArray\n let tag = _tag\n const parts = tag.split(' ')\n\n if (parts.length > 1) {\n tag = `${parts[1]} xmlns=\"${parts[0]}\"`\n }\n\n if (attrs === undefined) {\n return () => `<${tag}/>`\n }\n if (attrs === 0) {\n return child => `<${tag}>${serializeChildrenToHTMLString(child)}</${tag}>`\n }\n if (typeof attrs === 'object') {\n if (Array.isArray(attrs)) {\n if (children === undefined) {\n return child => `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}</${tag}>`\n }\n if (children === 0) {\n return child => `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}</${tag}>`\n }\n return child =>\n `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}${[children]\n .concat(rest)\n .map(a => domOutputSpecToHTMLString(a)(child))}</${tag}>`\n }\n if (children === undefined) {\n return () => `<${tag}${serializeAttrsToHTMLString(attrs)}/>`\n }\n if (children === 0) {\n return child => `<${tag}${serializeAttrsToHTMLString(attrs)}>${serializeChildrenToHTMLString(child)}</${tag}>`\n }\n\n return child =>\n `<${tag}${serializeAttrsToHTMLString(attrs)}>${[children]\n .concat(rest)\n .map(a => domOutputSpecToHTMLString(a)(child))\n .join('')}</${tag}>`\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 HTML using the provided extensions and options\n * @param content The content to render to HTML\n * @param extensions The extensions to use for rendering\n * @param options The options to use for rendering\n * @returns The rendered HTML string\n */\nexport function renderToHTMLString({\n content,\n extensions,\n options,\n}: {\n content: Node | JSONContent\n extensions: Extensions\n options?: Partial<TiptapStaticRendererOptions<string, Mark, Node>>\n}): string {\n return renderToElement<string>({\n renderer: renderJSONContentToString,\n domOutputSpecToElement: domOutputSpecToHTMLString,\n mapDefinedTypes: {\n // Map a doc node to concatenated children\n doc: ({ children }) => serializeChildrenToHTMLString(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","import { Extensions, JSONContent } from '@tiptap/core'\nimport type { Mark, Node } from '@tiptap/pm/model'\n\nimport { TiptapStaticRendererOptions } from '../../json/renderer.js'\nimport { renderToHTMLString, serializeChildrenToHTMLString } from '../html-string/html-string.js'\n\n/**\n * This code is just to show the flexibility of this renderer. We can potentially render content to any format we want.\n * This is a simple example of how we can render content to markdown. This is not a full implementation of a markdown renderer.\n */\nexport function renderToMarkdown({\n content,\n extensions,\n options,\n}: {\n content: Node | JSONContent\n extensions: Extensions\n options?: Partial<TiptapStaticRendererOptions<string, Mark, Node>>\n}) {\n return renderToHTMLString({\n content,\n extensions,\n options: {\n nodeMapping: {\n bulletList({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}`\n },\n orderedList({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}`\n },\n listItem({ node, children, parent }) {\n if (parent?.type.name === 'bulletList') {\n return `- ${serializeChildrenToHTMLString(children).trim()}\\n`\n }\n if (parent?.type.name === 'orderedList') {\n let number = parent.attrs.start || 1\n\n parent.forEach((parentChild, _offset, index) => {\n if (node === parentChild) {\n number = index + 1\n }\n })\n\n return `${number}. ${serializeChildrenToHTMLString(children).trim()}\\n`\n }\n\n return serializeChildrenToHTMLString(children)\n },\n paragraph({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}\\n`\n },\n heading({ node, children }) {\n const level = node.attrs.level as number\n\n return `${new Array(level).fill('#').join('')} ${children}\\n`\n },\n codeBlock({ node, children }) {\n return `\\n\\`\\`\\`${node.attrs.language}\\n${serializeChildrenToHTMLString(children)}\\n\\`\\`\\`\\n`\n },\n blockquote({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)\n .trim()\n .split('\\n')\n .map(a => `> ${a}`)\n .join('\\n')}`\n },\n image({ node }) {\n return `![${node.attrs.alt}](${node.attrs.src})`\n },\n hardBreak() {\n return '\\n'\n },\n horizontalRule() {\n return '\\n---\\n'\n },\n table({ children, node }) {\n if (!Array.isArray(children)) {\n return `\\n${serializeChildrenToHTMLString(children)}\\n`\n }\n\n return `\\n${serializeChildrenToHTMLString(children[0])}| ${new Array(node.childCount - 2).fill('---').join(' | ')} |\\n${serializeChildrenToHTMLString(children.slice(1))}\\n`\n },\n tableRow({ children }) {\n if (Array.isArray(children)) {\n return `| ${children.join(' | ')} |\\n`\n }\n return `${serializeChildrenToHTMLString(children)}\\n`\n },\n tableHeader({ children }) {\n return serializeChildrenToHTMLString(children).trim()\n },\n tableCell({ children }) {\n return serializeChildrenToHTMLString(children).trim()\n },\n ...options?.nodeMapping,\n },\n markMapping: {\n bold({ children }) {\n return `**${serializeChildrenToHTMLString(children)}**`\n },\n italic({ children, node }) {\n let isBoldToo = false\n\n // Check if the node being wrapped also has a bold mark, if so, we need to use the bold markdown syntax\n if (node?.marks.some(m => m.type.name === 'bold')) {\n isBoldToo = true\n }\n\n if (isBoldToo) {\n // If the content is bold, just wrap the bold content in italic markdown syntax with another set of asterisks\n return `*${serializeChildrenToHTMLString(children)}*`\n }\n\n return `_${serializeChildrenToHTMLString(children)}_`\n },\n code({ children }) {\n return `\\`${serializeChildrenToHTMLString(children)}\\``\n },\n strike({ children }) {\n return `~~${serializeChildrenToHTMLString(children)}~~`\n },\n underline({ children }) {\n return `<u>${serializeChildrenToHTMLString(children)}</u>`\n },\n subscript({ children }) {\n return `<sub>${serializeChildrenToHTMLString(children)}</sub>`\n },\n superscript({ children }) {\n return `<sup>${serializeChildrenToHTMLString(children)}</sup>`\n },\n link({ node, children }) {\n return `[${serializeChildrenToHTMLString(children)}](${node.attrs.href})`\n },\n highlight({ children }) {\n return `==${serializeChildrenToHTMLString(children)}==`\n },\n ...options?.markMapping,\n },\n ...options,\n },\n })\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 { 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 }) => <>{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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAuF;AAQhF,SAAS,cACd,YACA,qBACA,wBACqB;AACrB,QAAM,uBAAuB,WAAW;AAExC,MAAI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AAiB;AAAA;AAAA,MAEf,KAAK,CAAC,EAAE,SAAS,MAAM,8BAAAA,QAAA,4BAAAA,QAAA,gBAAG,QAAS;AAAA;AAAA,MAEnC,MAAM,CAAC,EAAE,KAAK,MAAG;AAjJvB;AAiJ0B,0BAAK,SAAL,YAAa;AAAA;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["_a","React","import_core","import_react","React"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/helpers.ts","../src/json/renderer.ts","../src/json/html-string/string.ts","../src/json/react/react.ts","../src/pm/extensionRenderer.ts","../src/pm/html-string/html-string.ts","../src/pm/markdown/markdown.ts","../src/pm/react/react.ts"],"sourcesContent":["export * from './helpers.js'\nexport * from './json/html-string/index.js'\nexport * from './json/react/index.js'\nexport * from './pm/html-string/index.js'\nexport * from './pm/markdown/index.js'\nexport * from './pm/react/index.js'\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 @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","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { MarkType, NodeType } from '@tiptap/core'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } from '../renderer.js'\n\nexport function renderJSONContentToString<\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<string, TMarkType, TNodeType>) {\n return TiptapStaticRenderer(ctx => {\n return ctx.component(ctx.props as any)\n }, options)\n}\n\n/**\n * Serialize the attributes of a node or mark to a string\n * @param attrs The attributes to serialize\n * @returns The serialized attributes as a string\n */\nexport function serializeAttrsToHTMLString(attrs: Record<string, any> | undefined | null): string {\n const output = Object.entries(attrs || {})\n .map(([key, value]) => `${key.split(' ').at(-1)}=${JSON.stringify(value)}`)\n .join(' ')\n\n return output ? ` ${output}` : ''\n}\n\n/**\n * Serialize the children of a node or mark to a string\n * @param children The children to serialize\n * @returns The serialized children as a string\n */\nexport function serializeChildrenToHTMLString(children?: string | string[]): string {\n return ([] as string[])\n .concat(children || '')\n .filter(Boolean)\n .join('')\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { MarkType, NodeType } from '@tiptap/core'\nimport React from 'react'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } 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 no-plusplus */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n ExtensionAttribute,\n Extensions,\n getAttributesFromExtensions,\n getExtensionField,\n getSchemaByResolvedExtensions,\n JSONContent,\n Mark as MarkExtension,\n MarkConfig,\n Node as NodeExtension,\n NodeConfig,\n resolveExtensions,\n splitExtensions,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport { getHTMLAttributes } from '../helpers.js'\nimport { 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 { DOMOutputSpecArray, Extensions, JSONContent } from '@tiptap/core'\nimport type { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport {\n renderJSONContentToString,\n serializeAttrsToHTMLString,\n serializeChildrenToHTMLString,\n} from '../../json/html-string/string.js'\nimport { TiptapStaticRendererOptions } from '../../json/renderer.js'\nimport { renderToElement } from '../extensionRenderer.js'\n\nexport { serializeAttrsToHTMLString, serializeChildrenToHTMLString } from '../../json/html-string/string.js'\n\n/**\n * Take a DOMOutputSpec and return a function that can render it to a string\n * @param content The DOMOutputSpec to convert to a string\n * @returns A function that can render the DOMOutputSpec to a string\n */\nexport function domOutputSpecToHTMLString(content: DOMOutputSpec): (children?: string | string[]) => string {\n if (typeof content === 'string') {\n return () => content\n }\n if (typeof content === 'object' && 'length' in content) {\n const [_tag, attrs, children, ...rest] = content as DOMOutputSpecArray\n let tag = _tag\n const parts = tag.split(' ')\n\n if (parts.length > 1) {\n tag = `${parts[1]} xmlns=\"${parts[0]}\"`\n }\n\n if (attrs === undefined) {\n return () => `<${tag}/>`\n }\n if (attrs === 0) {\n return child => `<${tag}>${serializeChildrenToHTMLString(child)}</${tag}>`\n }\n if (typeof attrs === 'object') {\n if (Array.isArray(attrs)) {\n if (children === undefined) {\n return child => `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}</${tag}>`\n }\n if (children === 0) {\n return child => `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}</${tag}>`\n }\n return child =>\n `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}${[children]\n .concat(rest)\n .map(a => domOutputSpecToHTMLString(a)(child))}</${tag}>`\n }\n if (children === undefined) {\n return () => `<${tag}${serializeAttrsToHTMLString(attrs)}/>`\n }\n if (children === 0) {\n return child => `<${tag}${serializeAttrsToHTMLString(attrs)}>${serializeChildrenToHTMLString(child)}</${tag}>`\n }\n\n return child =>\n `<${tag}${serializeAttrsToHTMLString(attrs)}>${[children]\n .concat(rest)\n .map(a => domOutputSpecToHTMLString(a)(child))\n .join('')}</${tag}>`\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 HTML using the provided extensions and options\n * @param content The content to render to HTML\n * @param extensions The extensions to use for rendering\n * @param options The options to use for rendering\n * @returns The rendered HTML string\n */\nexport function renderToHTMLString({\n content,\n extensions,\n options,\n}: {\n content: Node | JSONContent\n extensions: Extensions\n options?: Partial<TiptapStaticRendererOptions<string, Mark, Node>>\n}): string {\n return renderToElement<string>({\n renderer: renderJSONContentToString,\n domOutputSpecToElement: domOutputSpecToHTMLString,\n mapDefinedTypes: {\n // Map a doc node to concatenated children\n doc: ({ children }) => serializeChildrenToHTMLString(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","import { Extensions, JSONContent } from '@tiptap/core'\nimport type { Mark, Node } from '@tiptap/pm/model'\n\nimport { TiptapStaticRendererOptions } from '../../json/renderer.js'\nimport { renderToHTMLString, serializeChildrenToHTMLString } from '../html-string/html-string.js'\n\n/**\n * This code is just to show the flexibility of this renderer. We can potentially render content to any format we want.\n * This is a simple example of how we can render content to markdown. This is not a full implementation of a markdown renderer.\n */\nexport function renderToMarkdown({\n content,\n extensions,\n options,\n}: {\n content: Node | JSONContent\n extensions: Extensions\n options?: Partial<TiptapStaticRendererOptions<string, Mark, Node>>\n}) {\n return renderToHTMLString({\n content,\n extensions,\n options: {\n nodeMapping: {\n bulletList({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}`\n },\n orderedList({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}`\n },\n listItem({ node, children, parent }) {\n if (parent?.type.name === 'bulletList') {\n return `- ${serializeChildrenToHTMLString(children).trim()}\\n`\n }\n if (parent?.type.name === 'orderedList') {\n let number = parent.attrs.start || 1\n\n parent.forEach((parentChild, _offset, index) => {\n if (node === parentChild) {\n number = index + 1\n }\n })\n\n return `${number}. ${serializeChildrenToHTMLString(children).trim()}\\n`\n }\n\n return serializeChildrenToHTMLString(children)\n },\n paragraph({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}\\n`\n },\n heading({ node, children }) {\n const level = node.attrs.level as number\n\n return `${new Array(level).fill('#').join('')} ${children}\\n`\n },\n codeBlock({ node, children }) {\n return `\\n\\`\\`\\`${node.attrs.language}\\n${serializeChildrenToHTMLString(children)}\\n\\`\\`\\`\\n`\n },\n blockquote({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)\n .trim()\n .split('\\n')\n .map(a => `> ${a}`)\n .join('\\n')}`\n },\n image({ node }) {\n return `![${node.attrs.alt}](${node.attrs.src})`\n },\n hardBreak() {\n return '\\n'\n },\n horizontalRule() {\n return '\\n---\\n'\n },\n table({ children, node }) {\n if (!Array.isArray(children)) {\n return `\\n${serializeChildrenToHTMLString(children)}\\n`\n }\n\n return `\\n${serializeChildrenToHTMLString(children[0])}| ${new Array(node.childCount - 2).fill('---').join(' | ')} |\\n${serializeChildrenToHTMLString(children.slice(1))}\\n`\n },\n tableRow({ children }) {\n if (Array.isArray(children)) {\n return `| ${children.join(' | ')} |\\n`\n }\n return `${serializeChildrenToHTMLString(children)}\\n`\n },\n tableHeader({ children }) {\n return serializeChildrenToHTMLString(children).trim()\n },\n tableCell({ children }) {\n return serializeChildrenToHTMLString(children).trim()\n },\n ...options?.nodeMapping,\n },\n markMapping: {\n bold({ children }) {\n return `**${serializeChildrenToHTMLString(children)}**`\n },\n italic({ children, node }) {\n let isBoldToo = false\n\n // Check if the node being wrapped also has a bold mark, if so, we need to use the bold markdown syntax\n if (node?.marks.some(m => m.type.name === 'bold')) {\n isBoldToo = true\n }\n\n if (isBoldToo) {\n // If the content is bold, just wrap the bold content in italic markdown syntax with another set of asterisks\n return `*${serializeChildrenToHTMLString(children)}*`\n }\n\n return `_${serializeChildrenToHTMLString(children)}_`\n },\n code({ children }) {\n return `\\`${serializeChildrenToHTMLString(children)}\\``\n },\n strike({ children }) {\n return `~~${serializeChildrenToHTMLString(children)}~~`\n },\n underline({ children }) {\n return `<u>${serializeChildrenToHTMLString(children)}</u>`\n },\n subscript({ children }) {\n return `<sub>${serializeChildrenToHTMLString(children)}</sub>`\n },\n superscript({ children }) {\n return `<sup>${serializeChildrenToHTMLString(children)}</sup>`\n },\n link({ node, children }) {\n return `[${serializeChildrenToHTMLString(children)}](${node.attrs.href})`\n },\n highlight({ children }) {\n return `==${serializeChildrenToHTMLString(children)}==`\n },\n ...options?.markMapping,\n },\n ...options,\n },\n })\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 { 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAAuF;AAQhF,SAAS,cACd,YACA,qBACA,wBACqB;AACrB,QAAM,uBAAuB,WAAW;AAExC,MAAI,CAAC,sBAAsB;AACzB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,oBACJ,OAAO,UAAQ;AACd,QAAI,KAAK,UAAU,OAAO,WAAW,SAAS,WAAW,WAAW,OAAO,WAAW,KAAK,OAAO;AAChG,aAAO;AAAA,IACT;AACA,QAAI,wBAAwB;AAC1B,aAAO,KAAK,UAAU;AAAA,IACxB;AACA,WAAO;AAAA,EACT,CAAC,EACA,IAAI,UAAQ;AACX,QAAI,CAAC,KAAK,UAAU,YAAY;AAC9B,aAAO;AAAA,QACL,CAAC,KAAK,IAAI,GAAG,KAAK,QAAQ,uBAAuB,qBAAqB,KAAK,IAAI,IAAI,KAAK,UAAU;AAAA,MACpG;AAAA,IACF;AAEA,WACE,KAAK,UAAU,WAAW,oBAAoB,KAAK;AAAA,MACjD,CAAC,KAAK,IAAI,GAAG,KAAK,QAAQ,uBAAuB,qBAAqB,KAAK,IAAI,IAAI,KAAK,UAAU;AAAA,IACpG;AAAA,EAEJ,CAAC,EACA,OAAO,CAAC,YAAY,kBAAc,6BAAgB,YAAY,SAAS,GAAG,CAAC,CAAC;AACjF;AAOO,SAAS,kBAAkB,YAAiC,qBAA2C;AAC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K,yBAAyB,OAAO,IAAI,SAAS,CAAC,GAAG,KAAK;AAAA,MACjG;AAEA,aAAO,WACL,cAAAA,QAAM;AAAA,QACJ;AAAA,QACA,yBAAyB,OAAO,IAAI,SAAS,CAAC;AAAA,QAC9C,CAAC,QAAQ,EAAE,OAAO,IAAI,EAAE,IAAI,gBAAc,4BAA4B,YAAY,KAAK,EAAE,KAAK,CAAC;AAAA,MACjG;AAAA,IACJ;AAAA,EACF;AAGA,QAAM,IAAI;AAAA,IACR;AAAA,IACA;AAAA,MACE,OAAO;AAAA,IACT;AAAA,EACF;AACF;AASO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAIoB;AAClB,SAAO,gBAAiC;AAAA,IACtC,UAAU;AAAA,IACV,wBAAwB;AAAA,IACxB,iBAAiB;AAAA;AAAA,MAEf,KAAK,CAAC,EAAE,SAAS,MAAM,cAAAA,QAAM,cAAc,cAAAA,QAAM,UAAU,CAAC,GAAG,QAAQ;AAAA;AAAA,MAEvE,MAAM,CAAC,EAAE,KAAK,MAAG;AAjJvB;AAiJ0B,0BAAK,SAAL,YAAa;AAAA;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["_a","React","import_core","import_react","React"]}
package/dist/index.js CHANGED
@@ -103,7 +103,7 @@ function serializeChildrenToHTMLString(children) {
103
103
  return [].concat(children || "").filter(Boolean).join("");
104
104
  }
105
105
 
106
- // src/json/react/react.tsx
106
+ // src/json/react/react.ts
107
107
  import React from "react";
108
108
  function renderJSONContentToReactElement(options) {
109
109
  let key = 0;
@@ -453,7 +453,7 @@ ${serializeChildrenToHTMLString(children.slice(1))}
453
453
  });
454
454
  }
455
455
 
456
- // src/pm/react/react.tsx
456
+ // src/pm/react/react.ts
457
457
  import React2 from "react";
458
458
  function mapAttrsToHTMLAttributes(attrs, key) {
459
459
  if (!attrs) {
@@ -552,7 +552,7 @@ function renderToReactElement({
552
552
  domOutputSpecToElement: domOutputSpecToReactElement,
553
553
  mapDefinedTypes: {
554
554
  // Map a doc node to concatenated children
555
- doc: ({ children }) => /* @__PURE__ */ React2.createElement(React2.Fragment, null, children),
555
+ doc: ({ children }) => React2.createElement(React2.Fragment, {}, children),
556
556
  // Map a text node to its text content
557
557
  text: ({ node }) => {
558
558
  var _a;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/helpers.ts","../src/json/renderer.ts","../src/json/html-string/string.ts","../src/json/react/react.tsx","../src/pm/extensionRenderer.ts","../src/pm/html-string/html-string.ts","../src/pm/markdown/markdown.ts","../src/pm/react/react.tsx"],"sourcesContent":["/* 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 @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","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { MarkType, NodeType } from '@tiptap/core'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } from '../renderer.js'\n\nexport function renderJSONContentToString<\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<string, TMarkType, TNodeType>) {\n return TiptapStaticRenderer(ctx => {\n return ctx.component(ctx.props as any)\n }, options)\n}\n\n/**\n * Serialize the attributes of a node or mark to a string\n * @param attrs The attributes to serialize\n * @returns The serialized attributes as a string\n */\nexport function serializeAttrsToHTMLString(attrs: Record<string, any> | undefined | null): string {\n const output = Object.entries(attrs || {})\n .map(([key, value]) => `${key.split(' ').at(-1)}=${JSON.stringify(value)}`)\n .join(' ')\n\n return output ? ` ${output}` : ''\n}\n\n/**\n * Serialize the children of a node or mark to a string\n * @param children The children to serialize\n * @returns The serialized children as a string\n */\nexport function serializeChildrenToHTMLString(children?: string | string[]): string {\n return ([] as string[])\n .concat(children || '')\n .filter(Boolean)\n .join('')\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { MarkType, NodeType } from '@tiptap/core'\nimport React from 'react'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } 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 no-plusplus */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n ExtensionAttribute,\n Extensions,\n getAttributesFromExtensions,\n getExtensionField,\n getSchemaByResolvedExtensions,\n JSONContent,\n Mark as MarkExtension,\n MarkConfig,\n Node as NodeExtension,\n NodeConfig,\n resolveExtensions,\n splitExtensions,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport { getHTMLAttributes } from '../helpers.js'\nimport { 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 { DOMOutputSpecArray, Extensions, JSONContent } from '@tiptap/core'\nimport type { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport {\n renderJSONContentToString,\n serializeAttrsToHTMLString,\n serializeChildrenToHTMLString,\n} from '../../json/html-string/string.js'\nimport { TiptapStaticRendererOptions } from '../../json/renderer.js'\nimport { renderToElement } from '../extensionRenderer.js'\n\nexport { serializeAttrsToHTMLString, serializeChildrenToHTMLString } from '../../json/html-string/string.js'\n\n/**\n * Take a DOMOutputSpec and return a function that can render it to a string\n * @param content The DOMOutputSpec to convert to a string\n * @returns A function that can render the DOMOutputSpec to a string\n */\nexport function domOutputSpecToHTMLString(content: DOMOutputSpec): (children?: string | string[]) => string {\n if (typeof content === 'string') {\n return () => content\n }\n if (typeof content === 'object' && 'length' in content) {\n const [_tag, attrs, children, ...rest] = content as DOMOutputSpecArray\n let tag = _tag\n const parts = tag.split(' ')\n\n if (parts.length > 1) {\n tag = `${parts[1]} xmlns=\"${parts[0]}\"`\n }\n\n if (attrs === undefined) {\n return () => `<${tag}/>`\n }\n if (attrs === 0) {\n return child => `<${tag}>${serializeChildrenToHTMLString(child)}</${tag}>`\n }\n if (typeof attrs === 'object') {\n if (Array.isArray(attrs)) {\n if (children === undefined) {\n return child => `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}</${tag}>`\n }\n if (children === 0) {\n return child => `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}</${tag}>`\n }\n return child =>\n `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}${[children]\n .concat(rest)\n .map(a => domOutputSpecToHTMLString(a)(child))}</${tag}>`\n }\n if (children === undefined) {\n return () => `<${tag}${serializeAttrsToHTMLString(attrs)}/>`\n }\n if (children === 0) {\n return child => `<${tag}${serializeAttrsToHTMLString(attrs)}>${serializeChildrenToHTMLString(child)}</${tag}>`\n }\n\n return child =>\n `<${tag}${serializeAttrsToHTMLString(attrs)}>${[children]\n .concat(rest)\n .map(a => domOutputSpecToHTMLString(a)(child))\n .join('')}</${tag}>`\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 HTML using the provided extensions and options\n * @param content The content to render to HTML\n * @param extensions The extensions to use for rendering\n * @param options The options to use for rendering\n * @returns The rendered HTML string\n */\nexport function renderToHTMLString({\n content,\n extensions,\n options,\n}: {\n content: Node | JSONContent\n extensions: Extensions\n options?: Partial<TiptapStaticRendererOptions<string, Mark, Node>>\n}): string {\n return renderToElement<string>({\n renderer: renderJSONContentToString,\n domOutputSpecToElement: domOutputSpecToHTMLString,\n mapDefinedTypes: {\n // Map a doc node to concatenated children\n doc: ({ children }) => serializeChildrenToHTMLString(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","import { Extensions, JSONContent } from '@tiptap/core'\nimport type { Mark, Node } from '@tiptap/pm/model'\n\nimport { TiptapStaticRendererOptions } from '../../json/renderer.js'\nimport { renderToHTMLString, serializeChildrenToHTMLString } from '../html-string/html-string.js'\n\n/**\n * This code is just to show the flexibility of this renderer. We can potentially render content to any format we want.\n * This is a simple example of how we can render content to markdown. This is not a full implementation of a markdown renderer.\n */\nexport function renderToMarkdown({\n content,\n extensions,\n options,\n}: {\n content: Node | JSONContent\n extensions: Extensions\n options?: Partial<TiptapStaticRendererOptions<string, Mark, Node>>\n}) {\n return renderToHTMLString({\n content,\n extensions,\n options: {\n nodeMapping: {\n bulletList({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}`\n },\n orderedList({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}`\n },\n listItem({ node, children, parent }) {\n if (parent?.type.name === 'bulletList') {\n return `- ${serializeChildrenToHTMLString(children).trim()}\\n`\n }\n if (parent?.type.name === 'orderedList') {\n let number = parent.attrs.start || 1\n\n parent.forEach((parentChild, _offset, index) => {\n if (node === parentChild) {\n number = index + 1\n }\n })\n\n return `${number}. ${serializeChildrenToHTMLString(children).trim()}\\n`\n }\n\n return serializeChildrenToHTMLString(children)\n },\n paragraph({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}\\n`\n },\n heading({ node, children }) {\n const level = node.attrs.level as number\n\n return `${new Array(level).fill('#').join('')} ${children}\\n`\n },\n codeBlock({ node, children }) {\n return `\\n\\`\\`\\`${node.attrs.language}\\n${serializeChildrenToHTMLString(children)}\\n\\`\\`\\`\\n`\n },\n blockquote({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)\n .trim()\n .split('\\n')\n .map(a => `> ${a}`)\n .join('\\n')}`\n },\n image({ node }) {\n return `![${node.attrs.alt}](${node.attrs.src})`\n },\n hardBreak() {\n return '\\n'\n },\n horizontalRule() {\n return '\\n---\\n'\n },\n table({ children, node }) {\n if (!Array.isArray(children)) {\n return `\\n${serializeChildrenToHTMLString(children)}\\n`\n }\n\n return `\\n${serializeChildrenToHTMLString(children[0])}| ${new Array(node.childCount - 2).fill('---').join(' | ')} |\\n${serializeChildrenToHTMLString(children.slice(1))}\\n`\n },\n tableRow({ children }) {\n if (Array.isArray(children)) {\n return `| ${children.join(' | ')} |\\n`\n }\n return `${serializeChildrenToHTMLString(children)}\\n`\n },\n tableHeader({ children }) {\n return serializeChildrenToHTMLString(children).trim()\n },\n tableCell({ children }) {\n return serializeChildrenToHTMLString(children).trim()\n },\n ...options?.nodeMapping,\n },\n markMapping: {\n bold({ children }) {\n return `**${serializeChildrenToHTMLString(children)}**`\n },\n italic({ children, node }) {\n let isBoldToo = false\n\n // Check if the node being wrapped also has a bold mark, if so, we need to use the bold markdown syntax\n if (node?.marks.some(m => m.type.name === 'bold')) {\n isBoldToo = true\n }\n\n if (isBoldToo) {\n // If the content is bold, just wrap the bold content in italic markdown syntax with another set of asterisks\n return `*${serializeChildrenToHTMLString(children)}*`\n }\n\n return `_${serializeChildrenToHTMLString(children)}_`\n },\n code({ children }) {\n return `\\`${serializeChildrenToHTMLString(children)}\\``\n },\n strike({ children }) {\n return `~~${serializeChildrenToHTMLString(children)}~~`\n },\n underline({ children }) {\n return `<u>${serializeChildrenToHTMLString(children)}</u>`\n },\n subscript({ children }) {\n return `<sub>${serializeChildrenToHTMLString(children)}</sub>`\n },\n superscript({ children }) {\n return `<sup>${serializeChildrenToHTMLString(children)}</sup>`\n },\n link({ node, children }) {\n return `[${serializeChildrenToHTMLString(children)}](${node.attrs.href})`\n },\n highlight({ children }) {\n return `==${serializeChildrenToHTMLString(children)}==`\n },\n ...options?.markMapping,\n },\n ...options,\n },\n })\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 { 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 }) => <>{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"],"mappings":";AACA,SAAgE,uBAAuB;AAQhF,SAAS,cACd,YACA,qBACA,wBACqB;AACrB,QAAM,uBAAuB,WAAW;AAExC,MAAI,CAAC,sBAAsB;AACzB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,oBACJ,OAAO,UAAQ;AACd,QAAI,KAAK,UAAU,OAAO,WAAW,SAAS,WAAW,WAAW,OAAO,WAAW,KAAK,OAAO;AAChG,aAAO;AAAA,IACT;AACA,QAAI,wBAAwB;AAC1B,aAAO,KAAK,UAAU;AAAA,IACxB;AACA,WAAO;AAAA,EACT,CAAC,EACA,IAAI,UAAQ;AACX,QAAI,CAAC,KAAK,UAAU,YAAY;AAC9B,aAAO;AAAA,QACL,CAAC,KAAK,IAAI,GAAG,KAAK,QAAQ,uBAAuB,qBAAqB,KAAK,IAAI,IAAI,KAAK,UAAU;AAAA,MACpG;AAAA,IACF;AAEA,WACE,KAAK,UAAU,WAAW,oBAAoB,KAAK;AAAA,MACjD,CAAC,KAAK,IAAI,GAAG,KAAK,QAAQ,uBAAuB,qBAAqB,KAAK,IAAI,IAAI,KAAK,UAAU;AAAA,IACpG;AAAA,EAEJ,CAAC,EACA,OAAO,CAAC,YAAY,cAAc,gBAAgB,YAAY,SAAS,GAAG,CAAC,CAAC;AACjF;AAOO,SAAS,kBAAkB,YAAiC,qBAA2C;AAC5G,SAAO,cAAc,YAAY,qBAAqB,IAAI;AAC5D;;;AC8DO,SAAS,qBAiCd,iBAWA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GACA;AAIA,SAAO,SAAS,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,EACF,GASgB;AArLlB;AAsLI,UAAM,WAAW,OAAO,QAAQ,SAAS,WAAW,QAAQ,OAAO,QAAQ,KAAK;AAChF,UAAM,eAAc,iBAAY,QAAQ,MAApB,YAAyB;AAE7C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,MACE,OAAO;AAAA,IACT;AAAA,EACF;AACF;AASO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAIoB;AAClB,SAAO,gBAAiC;AAAA,IACtC,UAAU;AAAA,IACV,wBAAwB;AAAA,IACxB,iBAAiB;AAAA;AAAA,MAEf,KAAK,CAAC,EAAE,SAAS,MAAM,gBAAAA,OAAA,cAAAA,OAAA,gBAAG,QAAS;AAAA;AAAA,MAEnC,MAAM,CAAC,EAAE,KAAK,MAAG;AAjJvB;AAiJ0B,0BAAK,SAAL,YAAa;AAAA;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["_a","React","React"]}
1
+ {"version":3,"sources":["../src/helpers.ts","../src/json/renderer.ts","../src/json/html-string/string.ts","../src/json/react/react.ts","../src/pm/extensionRenderer.ts","../src/pm/html-string/html-string.ts","../src/pm/markdown/markdown.ts","../src/pm/react/react.ts"],"sourcesContent":["/* 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 @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","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { MarkType, NodeType } from '@tiptap/core'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } from '../renderer.js'\n\nexport function renderJSONContentToString<\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<string, TMarkType, TNodeType>) {\n return TiptapStaticRenderer(ctx => {\n return ctx.component(ctx.props as any)\n }, options)\n}\n\n/**\n * Serialize the attributes of a node or mark to a string\n * @param attrs The attributes to serialize\n * @returns The serialized attributes as a string\n */\nexport function serializeAttrsToHTMLString(attrs: Record<string, any> | undefined | null): string {\n const output = Object.entries(attrs || {})\n .map(([key, value]) => `${key.split(' ').at(-1)}=${JSON.stringify(value)}`)\n .join(' ')\n\n return output ? ` ${output}` : ''\n}\n\n/**\n * Serialize the children of a node or mark to a string\n * @param children The children to serialize\n * @returns The serialized children as a string\n */\nexport function serializeChildrenToHTMLString(children?: string | string[]): string {\n return ([] as string[])\n .concat(children || '')\n .filter(Boolean)\n .join('')\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { MarkType, NodeType } from '@tiptap/core'\nimport React from 'react'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } 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 no-plusplus */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n ExtensionAttribute,\n Extensions,\n getAttributesFromExtensions,\n getExtensionField,\n getSchemaByResolvedExtensions,\n JSONContent,\n Mark as MarkExtension,\n MarkConfig,\n Node as NodeExtension,\n NodeConfig,\n resolveExtensions,\n splitExtensions,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport { getHTMLAttributes } from '../helpers.js'\nimport { 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 { DOMOutputSpecArray, Extensions, JSONContent } from '@tiptap/core'\nimport type { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport {\n renderJSONContentToString,\n serializeAttrsToHTMLString,\n serializeChildrenToHTMLString,\n} from '../../json/html-string/string.js'\nimport { TiptapStaticRendererOptions } from '../../json/renderer.js'\nimport { renderToElement } from '../extensionRenderer.js'\n\nexport { serializeAttrsToHTMLString, serializeChildrenToHTMLString } from '../../json/html-string/string.js'\n\n/**\n * Take a DOMOutputSpec and return a function that can render it to a string\n * @param content The DOMOutputSpec to convert to a string\n * @returns A function that can render the DOMOutputSpec to a string\n */\nexport function domOutputSpecToHTMLString(content: DOMOutputSpec): (children?: string | string[]) => string {\n if (typeof content === 'string') {\n return () => content\n }\n if (typeof content === 'object' && 'length' in content) {\n const [_tag, attrs, children, ...rest] = content as DOMOutputSpecArray\n let tag = _tag\n const parts = tag.split(' ')\n\n if (parts.length > 1) {\n tag = `${parts[1]} xmlns=\"${parts[0]}\"`\n }\n\n if (attrs === undefined) {\n return () => `<${tag}/>`\n }\n if (attrs === 0) {\n return child => `<${tag}>${serializeChildrenToHTMLString(child)}</${tag}>`\n }\n if (typeof attrs === 'object') {\n if (Array.isArray(attrs)) {\n if (children === undefined) {\n return child => `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}</${tag}>`\n }\n if (children === 0) {\n return child => `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}</${tag}>`\n }\n return child =>\n `<${tag}>${domOutputSpecToHTMLString(attrs as DOMOutputSpecArray)(child)}${[children]\n .concat(rest)\n .map(a => domOutputSpecToHTMLString(a)(child))}</${tag}>`\n }\n if (children === undefined) {\n return () => `<${tag}${serializeAttrsToHTMLString(attrs)}/>`\n }\n if (children === 0) {\n return child => `<${tag}${serializeAttrsToHTMLString(attrs)}>${serializeChildrenToHTMLString(child)}</${tag}>`\n }\n\n return child =>\n `<${tag}${serializeAttrsToHTMLString(attrs)}>${[children]\n .concat(rest)\n .map(a => domOutputSpecToHTMLString(a)(child))\n .join('')}</${tag}>`\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 HTML using the provided extensions and options\n * @param content The content to render to HTML\n * @param extensions The extensions to use for rendering\n * @param options The options to use for rendering\n * @returns The rendered HTML string\n */\nexport function renderToHTMLString({\n content,\n extensions,\n options,\n}: {\n content: Node | JSONContent\n extensions: Extensions\n options?: Partial<TiptapStaticRendererOptions<string, Mark, Node>>\n}): string {\n return renderToElement<string>({\n renderer: renderJSONContentToString,\n domOutputSpecToElement: domOutputSpecToHTMLString,\n mapDefinedTypes: {\n // Map a doc node to concatenated children\n doc: ({ children }) => serializeChildrenToHTMLString(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","import { Extensions, JSONContent } from '@tiptap/core'\nimport type { Mark, Node } from '@tiptap/pm/model'\n\nimport { TiptapStaticRendererOptions } from '../../json/renderer.js'\nimport { renderToHTMLString, serializeChildrenToHTMLString } from '../html-string/html-string.js'\n\n/**\n * This code is just to show the flexibility of this renderer. We can potentially render content to any format we want.\n * This is a simple example of how we can render content to markdown. This is not a full implementation of a markdown renderer.\n */\nexport function renderToMarkdown({\n content,\n extensions,\n options,\n}: {\n content: Node | JSONContent\n extensions: Extensions\n options?: Partial<TiptapStaticRendererOptions<string, Mark, Node>>\n}) {\n return renderToHTMLString({\n content,\n extensions,\n options: {\n nodeMapping: {\n bulletList({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}`\n },\n orderedList({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}`\n },\n listItem({ node, children, parent }) {\n if (parent?.type.name === 'bulletList') {\n return `- ${serializeChildrenToHTMLString(children).trim()}\\n`\n }\n if (parent?.type.name === 'orderedList') {\n let number = parent.attrs.start || 1\n\n parent.forEach((parentChild, _offset, index) => {\n if (node === parentChild) {\n number = index + 1\n }\n })\n\n return `${number}. ${serializeChildrenToHTMLString(children).trim()}\\n`\n }\n\n return serializeChildrenToHTMLString(children)\n },\n paragraph({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)}\\n`\n },\n heading({ node, children }) {\n const level = node.attrs.level as number\n\n return `${new Array(level).fill('#').join('')} ${children}\\n`\n },\n codeBlock({ node, children }) {\n return `\\n\\`\\`\\`${node.attrs.language}\\n${serializeChildrenToHTMLString(children)}\\n\\`\\`\\`\\n`\n },\n blockquote({ children }) {\n return `\\n${serializeChildrenToHTMLString(children)\n .trim()\n .split('\\n')\n .map(a => `> ${a}`)\n .join('\\n')}`\n },\n image({ node }) {\n return `![${node.attrs.alt}](${node.attrs.src})`\n },\n hardBreak() {\n return '\\n'\n },\n horizontalRule() {\n return '\\n---\\n'\n },\n table({ children, node }) {\n if (!Array.isArray(children)) {\n return `\\n${serializeChildrenToHTMLString(children)}\\n`\n }\n\n return `\\n${serializeChildrenToHTMLString(children[0])}| ${new Array(node.childCount - 2).fill('---').join(' | ')} |\\n${serializeChildrenToHTMLString(children.slice(1))}\\n`\n },\n tableRow({ children }) {\n if (Array.isArray(children)) {\n return `| ${children.join(' | ')} |\\n`\n }\n return `${serializeChildrenToHTMLString(children)}\\n`\n },\n tableHeader({ children }) {\n return serializeChildrenToHTMLString(children).trim()\n },\n tableCell({ children }) {\n return serializeChildrenToHTMLString(children).trim()\n },\n ...options?.nodeMapping,\n },\n markMapping: {\n bold({ children }) {\n return `**${serializeChildrenToHTMLString(children)}**`\n },\n italic({ children, node }) {\n let isBoldToo = false\n\n // Check if the node being wrapped also has a bold mark, if so, we need to use the bold markdown syntax\n if (node?.marks.some(m => m.type.name === 'bold')) {\n isBoldToo = true\n }\n\n if (isBoldToo) {\n // If the content is bold, just wrap the bold content in italic markdown syntax with another set of asterisks\n return `*${serializeChildrenToHTMLString(children)}*`\n }\n\n return `_${serializeChildrenToHTMLString(children)}_`\n },\n code({ children }) {\n return `\\`${serializeChildrenToHTMLString(children)}\\``\n },\n strike({ children }) {\n return `~~${serializeChildrenToHTMLString(children)}~~`\n },\n underline({ children }) {\n return `<u>${serializeChildrenToHTMLString(children)}</u>`\n },\n subscript({ children }) {\n return `<sub>${serializeChildrenToHTMLString(children)}</sub>`\n },\n superscript({ children }) {\n return `<sup>${serializeChildrenToHTMLString(children)}</sup>`\n },\n link({ node, children }) {\n return `[${serializeChildrenToHTMLString(children)}](${node.attrs.href})`\n },\n highlight({ children }) {\n return `==${serializeChildrenToHTMLString(children)}==`\n },\n ...options?.markMapping,\n },\n ...options,\n },\n })\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 { 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"],"mappings":";AACA,SAAgE,uBAAuB;AAQhF,SAAS,cACd,YACA,qBACA,wBACqB;AACrB,QAAM,uBAAuB,WAAW;AAExC,MAAI,CAAC,sBAAsB;AACzB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,oBACJ,OAAO,UAAQ;AACd,QAAI,KAAK,UAAU,OAAO,WAAW,SAAS,WAAW,WAAW,OAAO,WAAW,KAAK,OAAO;AAChG,aAAO;AAAA,IACT;AACA,QAAI,wBAAwB;AAC1B,aAAO,KAAK,UAAU;AAAA,IACxB;AACA,WAAO;AAAA,EACT,CAAC,EACA,IAAI,UAAQ;AACX,QAAI,CAAC,KAAK,UAAU,YAAY;AAC9B,aAAO;AAAA,QACL,CAAC,KAAK,IAAI,GAAG,KAAK,QAAQ,uBAAuB,qBAAqB,KAAK,IAAI,IAAI,KAAK,UAAU;AAAA,MACpG;AAAA,IACF;AAEA,WACE,KAAK,UAAU,WAAW,oBAAoB,KAAK;AAAA,MACjD,CAAC,KAAK,IAAI,GAAG,KAAK,QAAQ,uBAAuB,qBAAqB,KAAK,IAAI,IAAI,KAAK,UAAU;AAAA,IACpG;AAAA,EAEJ,CAAC,EACA,OAAO,CAAC,YAAY,cAAc,gBAAgB,YAAY,SAAS,GAAG,CAAC,CAAC;AACjF;AAOO,SAAS,kBAAkB,YAAiC,qBAA2C;AAC5G,SAAO,cAAc,YAAY,qBAAqB,IAAI;AAC5D;;;AC8DO,SAAS,qBAiCd,iBAWA;AAAA,EACE;AAAA,EACA;AAAA,EACA;A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yBAAyB,OAAO,IAAI,SAAS,CAAC;AAAA,QAC9C,CAAC,QAAQ,EAAE,OAAO,IAAI,EAAE,IAAI,gBAAc,4BAA4B,YAAY,KAAK,EAAE,KAAK,CAAC;AAAA,MACjG;AAAA,IACJ;AAAA,EACF;AAGA,QAAM,IAAI;AAAA,IACR;AAAA,IACA;AAAA,MACE,OAAO;AAAA,IACT;AAAA,EACF;AACF;AASO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAIoB;AAClB,SAAO,gBAAiC;AAAA,IACtC,UAAU;AAAA,IACV,wBAAwB;AAAA,IACxB,iBAAiB;AAAA;AAAA,MAEf,KAAK,CAAC,EAAE,SAAS,MAAMA,OAAM,cAAcA,OAAM,UAAU,CAAC,GAAG,QAAQ;AAAA;AAAA,MAEvE,MAAM,CAAC,EAAE,KAAK,MAAG;AAjJvB;AAiJ0B,0BAAK,SAAL,YAAa;AAAA;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["_a","React","React"]}
@@ -96,7 +96,7 @@ function TiptapStaticRenderer(renderComponent, {
96
96
  };
97
97
  }
98
98
 
99
- // src/json/react/react.tsx
99
+ // src/json/react/react.ts
100
100
  var import_react = __toESM(require("react"), 1);
101
101
  function renderJSONContentToReactElement(options) {
102
102
  let key = 0;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/json/react/index.ts","../../../src/json/renderer.ts","../../../src/json/react/react.tsx"],"sourcesContent":["export * from '../renderer.js'\nexport * from './react.js'\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","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { MarkType, NodeType } from '@tiptap/core'\nimport React from 'react'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC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O;AAAA,EACT;AACF;;;AC7OA,mBAAkB;AAIX,SAAS,gCAad,SAA6E;AAC7E,MAAI,MAAM;AAEV,SAAO,qBAA4D,CAAC,EAAE,WAAW,OAAO,EAAE,UAAU,GAAG,MAAM,EAAE,MAAM;AACnH,WAAO,aAAAC,QAAM;AAAA,MACX;AAAA;AAAA,MAEA,OAAO,OAAO,OAAO,EAAE,KAAK,MAAM,CAAC;AAAA,MAClC,CAAC,EAAwB,OAAO,QAAQ;AAAA,IAC3C;AAAA,EACF,GAAG,OAAO;AACZ;","names":["_a","React"]}
1
+ {"version":3,"sources":["../../../src/json/react/index.ts","../../../src/json/renderer.ts","../../../src/json/react/react.ts"],"sourcesContent":["export * from '../renderer.js'\nexport * from './react.js'\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","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { MarkType, NodeType } from '@tiptap/core'\nimport React from 'react'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmHO,SAAS,qBAiCd,iBAWA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GACA;AAIA,SAAO,SAAS,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,EACF,GASgB;AArLlB;AAsLI,UAAM,WAAW,OAAO,QAAQ,SAAS,WAAW,QAAQ,OAAO,QAAQ,KAAK;AAChF,UAAM,eAAc,iBAAY,QAAQ,MAApB,YAAyB;AAE7C,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,iCAAiC,QAAQ,EAAE;AAAA,IAC7D;AAEA,UAAM,cAAc,gBAAgB;AAAA,MAClC,WAAW;AAAA,MACX,OAAO;AAAA,QACL,MAAM;AAAA,QACN;AAAA,QACA,eAAe;AAAA;AAAA,QAEf,IAAI,WAAW;AAEb,gBAAM,WAA0B,CAAC;AAEjC,cAAI,QAAQ,SAAS;AACnB,oBAAQ,QAAQ,QAAQ,WAAS;AAC/B,uBAAS;AAAA,gBACP,cAAc;AAAA,kBACZ,SAAS;AAAA,kBACT,QAAQ;AAAA,gBACV,CAAC;AAAA,cACH;AAAA,YACF,CAAC;AAAA,UACH;AAEA,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAGD,UAAM,gBAAgB,QAAQ,QAC1B,QAAQ,MAAM,OAAO,CAAC,KAAK,SAAS;AA1N5C,UAAAA;AA2NU,YAAM,WAAW,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO,KAAK,KAAK;AACvE,YAAM,eAAcA,MAAA,YAAY,QAAQ,MAApB,OAAAA,MAAyB;AAE7C,UAAI,CAAC,aAAa;AAChB,cAAM,IAAI,MAAM,iCAAiC,QAAQ,EAAE;AAAA,MAC7D;AAEA,aAAO,gBAAgB;AAAA,QACrB,WAAW;AAAA,QACX,OAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA,MAAM;AAAA,UACN,UAAU;AAAA,QACZ;AAAA,MACF,CAAC;AAAA,IACH,GAAG,WAAW,IACd;AAEJ,WAAO;AAAA,EACT;AACF;;;AC7OA,mBAAkB;AAIX,SAAS,gCAad,SAA6E;AAC7E,MAAI,MAAM;AAEV,SAAO,qBAA4D,CAAC,EAAE,WAAW,OAAO,EAAE,UAAU,GAAG,MAAM,EAAE,MAAM;AACnH,WAAO,aAAAC,QAAM;AAAA,MACX;AAAA;AAAA,MAEA,OAAO,OAAO,OAAO,EAAE,KAAK,MAAM,CAAC;AAAA,MAClC,CAAC,EAAwB,OAAO,QAAQ;AAAA,IAC3C;AAAA,EACF,GAAG,OAAO;AACZ;","names":["_a","React"]}
@@ -59,7 +59,7 @@ function TiptapStaticRenderer(renderComponent, {
59
59
  };
60
60
  }
61
61
 
62
- // src/json/react/react.tsx
62
+ // src/json/react/react.ts
63
63
  import React from "react";
64
64
  function renderJSONContentToReactElement(options) {
65
65
  let key = 0;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/json/renderer.ts","../../../src/json/react/react.tsx"],"sourcesContent":["/* 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","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { MarkType, NodeType } from '@tiptap/core'\nimport React from 'react'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } 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"],"mappings":";AAmHO,SAAS,qBAiCd,iBAWA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GACA;AAIA,SAAO,SAAS,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,EACF,GASgB;AArLlB;AAsLI,UAAM,WAAW,OAAO,QAAQ,SAAS,WAAW,QAAQ,OAAO,QAAQ,KAAK;AAChF,UAAM,eAAc,iBAAY,QAAQ,MAApB,YAAyB;AAE7C,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,iCAAiC,QAAQ,EAAE;AAAA,IAC7D;AAEA,UAAM,cAAc,gBAAgB;AAAA,MAClC,WAAW;AAAA,MACX,OAAO;AAAA,QACL,MAAM;AAAA,QACN;AAAA,QACA,eAAe;AAAA;AAAA,QAEf,IAAI,WAAW;AAEb,gBAAM,WAA0B,CAAC;AAEjC,cAAI,QAAQ,SAAS;AACnB,oBAAQ,QAAQ,QAAQ,WAAS;AAC/B,uBAAS;AAAA,gBACP,cAAc;AAAA,kBACZ,SAAS;AAAA,kBACT,QAAQ;AAAA,gBACV,CAAC;AAAA,cACH;AAAA,YACF,CAAC;AAAA,UACH;AAEA,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAGD,UAAM,gBAAgB,QAAQ,QAC1B,QAAQ,MAAM,OAAO,CAAC,KAAK,SAAS;AA1N5C,UAAAA;AA2NU,YAAM,WAAW,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO,KAAK,KAAK;AACvE,YAAM,eAAcA,MAAA,YAAY,QAAQ,MAApB,OAAAA,MAAyB;AAE7C,UAAI,CAAC,aAAa;AAChB,cAAM,IAAI,MAAM,iCAAiC,QAAQ,EAAE;AAAA,MAC7D;AAEA,aAAO,gBAAgB;AAAA,QACrB,WAAW;AAAA,QACX,OAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA,MAAM;AAAA,UACN,UAAU;AAAA,QACZ;AAAA,MACF,CAAC;AAAA,IACH,GAAG,WAAW,IACd;AAEJ,WAAO;AAAA,EACT;AACF;;;AC7OA,OAAO,WAAW;AAIX,SAAS,gCAad,SAA6E;AAC7E,MAAI,MAAM;AAEV,SAAO,qBAA4D,CAAC,EAAE,WAAW,OAAO,EAAE,UAAU,GAAG,MAAM,EAAE,MAAM;AACnH,WAAO,MAAM;AAAA,MACX;AAAA;AAAA,MAEA,OAAO,OAAO,OAAO,EAAE,KAAK,MAAM,CAAC;AAAA,MAClC,CAAC,EAAwB,OAAO,QAAQ;AAAA,IAC3C;AAAA,EACF,GAAG,OAAO;AACZ;","names":["_a"]}
1
+ {"version":3,"sources":["../../../src/json/renderer.ts","../../../src/json/react/react.ts"],"sourcesContent":["/* 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","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { MarkType, NodeType } from '@tiptap/core'\nimport React from 'react'\n\nimport { TiptapStaticRenderer, TiptapStaticRendererOptions } 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"],"mappings":";AAmHO,SAAS,qBAiCd,iBAWA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GACA;AAIA,SAAO,SAAS,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,EACF,GASgB;AArLlB;AAsLI,UAAM,WAAW,OAAO,QAAQ,SAAS,WAAW,QAAQ,OAAO,QAAQ,KAAK;AAChF,UAAM,eAAc,iBAAY,QAAQ,MAApB,YAAyB;AAE7C,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,iCAAiC,QAAQ,EAAE;AAAA,IAC7D;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,10 +198,10 @@ function renderToElement({
198
198
  })({ content });
199
199
  }
200
200
 
201
- // src/pm/react/react.tsx
201
+ // src/pm/react/react.ts
202
202
  var import_react2 = __toESM(require("react"), 1);
203
203
 
204
- // src/json/react/react.tsx
204
+ // src/json/react/react.ts
205
205
  var import_react = __toESM(require("react"), 1);
206
206
 
207
207
  // src/json/renderer.ts
@@ -265,7 +265,7 @@ function TiptapStaticRenderer(renderComponent, {
265
265
  };
266
266
  }
267
267
 
268
- // src/json/react/react.tsx
268
+ // src/json/react/react.ts
269
269
  function renderJSONContentToReactElement(options) {
270
270
  let key = 0;
271
271
  return TiptapStaticRenderer(({ component, props: { children, ...props } }) => {
@@ -278,7 +278,7 @@ function renderJSONContentToReactElement(options) {
278
278
  }, options);
279
279
  }
280
280
 
281
- // src/pm/react/react.tsx
281
+ // src/pm/react/react.ts
282
282
  function mapAttrsToHTMLAttributes(attrs, key) {
283
283
  if (!attrs) {
284
284
  return { key };
@@ -376,7 +376,7 @@ function renderToReactElement({
376
376
  domOutputSpecToElement: domOutputSpecToReactElement,
377
377
  mapDefinedTypes: {
378
378
  // Map a doc node to concatenated children
379
- doc: ({ children }) => /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, children),
379
+ doc: ({ children }) => import_react2.default.createElement(import_react2.default.Fragment, {}, children),
380
380
  // Map a text node to its text content
381
381
  text: ({ node }) => {
382
382
  var _a;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/pm/react/index.ts","../../../src/pm/extensionRenderer.ts","../../../src/helpers.ts","../../../src/pm/react/react.tsx","../../../src/json/react/react.tsx","../../../src/json/renderer.ts"],"sourcesContent":["export * from '../extensionRenderer.js'\nexport * from './react.js'\n","/* eslint-disable no-plusplus */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n ExtensionAttribute,\n Extensions,\n getAttributesFromExtensions,\n getExtensionField,\n getSchemaByResolvedExtensions,\n JSONContent,\n Mark as MarkExtension,\n MarkConfig,\n Node as NodeExtension,\n NodeConfig,\n resolveExtensions,\n splitExtensions,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport { getHTMLAttributes } from '../helpers.js'\nimport { 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 { 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 }) => <>{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 { TiptapStaticRenderer, TiptapStaticRendererOptions } 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,IAAAA,eAaO;AACP,mBAA0C;;;AChB1C,kBAAuF;AAQhF,SAAS,cACd,YACA,qBACA,wBACqB;AACrB,QAAM,uBAAuB,WAAW;AAExC,MAAI,CAAC,sBAAsB;AACzB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,oBACJ,OAAO,UAAQ;AACd,QAAI,KAAK,UAAU,OAAO,WAAW,SAAS,WAAW,WAAW,OAAO,WAAW,KAAK,OAAO;AAChG,aAAO;AAAA,IACT;AACA,QAAI,wBAAwB;AAC1B,aAAO,KAAK,UAAU;AAAA,IACxB;AACA,WAAO;AAAA,EACT,CAAC,EACA,IAAI,UAAQ;AACX,QAAI,CAAC,KAAK,UAAU,YAAY;AAC9B,aA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E,SAAS,MAAM,8BAAAA,QAAA,4BAAAA,QAAA,gBAAG,QAAS;AAAA;AAAA,MAEnC,MAAM,CAAC,EAAE,KAAK,MAAG;AAjJvB;AAiJ0B,0BAAK,SAAL,YAAa;AAAA;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["import_core","import_react","_a","React","React"]}
1
+ {"version":3,"sources":["../../../src/pm/react/index.ts","../../../src/pm/extensionRenderer.ts","../../../src/helpers.ts","../../../src/pm/react/react.ts","../../../src/json/react/react.ts","../../../src/json/renderer.ts"],"sourcesContent":["export * from '../extensionRenderer.js'\nexport * from './react.js'\n","/* eslint-disable no-plusplus */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n ExtensionAttribute,\n Extensions,\n getAttributesFromExtensions,\n getExtensionField,\n getSchemaByResolvedExtensions,\n JSONContent,\n Mark as MarkExtension,\n MarkConfig,\n Node as NodeExtension,\n NodeConfig,\n resolveExtensions,\n splitExtensions,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport { getHTMLAttributes } from '../helpers.js'\nimport { 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 { 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 { TiptapStaticRenderer, TiptapStaticRendererOptions } 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: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,UAAI,aAAa,GAAG;AAClB,eAAO,WAAS,cAAAA,QAAM,cAAc,KAAK,yBAAyB,OAAO,IAAI,SAAS,CAAC,GAAG,KAAK;AAAA,MACjG;AAEA,aAAO,WACL,cAAAA,QAAM;AAAA,QACJ;AAAA,QACA,yBAAyB,OAAO,IAAI,SAAS,CAAC;AAAA,QAC9C,CAAC,QAAQ,EAAE,OAAO,IAAI,EAAE,IAAI,gBAAc,4BAA4B,YAAY,KAAK,EAAE,KAAK,CAAC;AAAA,MACjG;AAAA,IACJ;AAAA,EACF;AAGA,QAAM,IAAI;AAAA,IACR;AAAA,IACA;AAAA,MACE,OAAO;AAAA,IACT;AAAA,EACF;AACF;AASO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAIoB;AAClB,SAAO,gBAAiC;AAAA,IACtC,UAAU;AAAA,IACV,wBAAwB;AAAA,IACxB,iBAAiB;AAAA;AAAA,MAEf,KAAK,CAAC,EAAE,SAAS,MAAM,cAAAA,QAAM,cAAc,cAAAA,QAAM,UAAU,CAAC,GAAG,QAAQ;AAAA;AAAA,MAEvE,MAAM,CAAC,EAAE,KAAK,MAAG;AAjJvB;AAiJ0B,0BAAK,SAAL,YAAa;AAAA;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["import_core","import_react","_a","React","React"]}
@@ -164,10 +164,10 @@ function renderToElement({
164
164
  })({ content });
165
165
  }
166
166
 
167
- // src/pm/react/react.tsx
167
+ // src/pm/react/react.ts
168
168
  import React2 from "react";
169
169
 
170
- // src/json/react/react.tsx
170
+ // src/json/react/react.ts
171
171
  import React from "react";
172
172
 
173
173
  // src/json/renderer.ts
@@ -231,7 +231,7 @@ function TiptapStaticRenderer(renderComponent, {
231
231
  };
232
232
  }
233
233
 
234
- // src/json/react/react.tsx
234
+ // src/json/react/react.ts
235
235
  function renderJSONContentToReactElement(options) {
236
236
  let key = 0;
237
237
  return TiptapStaticRenderer(({ component, props: { children, ...props } }) => {
@@ -244,7 +244,7 @@ function renderJSONContentToReactElement(options) {
244
244
  }, options);
245
245
  }
246
246
 
247
- // src/pm/react/react.tsx
247
+ // src/pm/react/react.ts
248
248
  function mapAttrsToHTMLAttributes(attrs, key) {
249
249
  if (!attrs) {
250
250
  return { key };
@@ -342,7 +342,7 @@ function renderToReactElement({
342
342
  domOutputSpecToElement: domOutputSpecToReactElement,
343
343
  mapDefinedTypes: {
344
344
  // Map a doc node to concatenated children
345
- doc: ({ children }) => /* @__PURE__ */ React2.createElement(React2.Fragment, null, children),
345
+ doc: ({ children }) => React2.createElement(React2.Fragment, {}, children),
346
346
  // Map a text node to its text content
347
347
  text: ({ node }) => {
348
348
  var _a;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/pm/extensionRenderer.ts","../../../src/helpers.ts","../../../src/pm/react/react.tsx","../../../src/json/react/react.tsx","../../../src/json/renderer.ts"],"sourcesContent":["/* eslint-disable no-plusplus */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n ExtensionAttribute,\n Extensions,\n getAttributesFromExtensions,\n getExtensionField,\n getSchemaByResolvedExtensions,\n JSONContent,\n Mark as MarkExtension,\n MarkConfig,\n Node as NodeExtension,\n NodeConfig,\n resolveExtensions,\n splitExtensions,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport { getHTMLAttributes } from '../helpers.js'\nimport { 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 { 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 }) => <>{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 { TiptapStaticRenderer, TiptapStaticRendererOptions } 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":";AAGA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EAMA;AAAA,EACA;AAAA,OACK;AACP,SAA8B,YAAY;;;AChB1C,SAAgE,uBAAuB;AAQhF,SAAS,cACd,YACA,qBACA,wBACqB;AACrB,QAAM,uBAAuB,WAAW;AAExC,MAAI,CAAC,sBAAsB;AACzB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,oBACJ,OAAO,UAAQ;AACd,QAAI,KAAK,UAAU,OAAO,WAAW,SAAS,WAAW,WAAW,OAAO,WAAW,KAAK,OAAO;AAChG,aAAO;AAAA,IACT;AACA,QAAI,wBAAwB;AAC1B,aAAO,KAAK,UAAU;AAAA,IACxB;AACA,WAAO;AAAA,EACT,CAAC,EACA,IAAI,UAAQ;AACX,QAAI,CAAC,KAAK,UAAU,YAAY;AAC9B,aAAO;AAAA,QACL,CAAC,KAAK,IAAI,GAAG,KAAK,QAAQ,uBAAuB,qBAAqB,KAAK,IAAI,IAAI,KAAK,UAAU;AAAA,MACpG;AAAA,IACF;AAEA,WACE,KAAK,UAAU,WAAW,oBAAoB,KAAK;AAAA,MACjD,CAAC,KAAK,IAAI,GAAG,KAAK,QAAQ,uBAAuB,qBAAqB,KAAK,IAAI,IAAI,KAAK,UAAU;AAAA,IACpG;AAAA,EAEJ,CAAC,EACA,OAAO,CAAC,YAAY,cAAc,gBAAgB,YAAY,SAAS,GAAG,CAAC,CAAC;AACjF;AAOO,SAAS,kBAAkB,YAAiC,qBAA2C;AAC5G,SAAO,cAAc,YAAY,qBAAqB,IAAI;AAC5D;;;ADvBO,SAAS,4BACd,wBACA,WACA,qBACA,SACkD;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,eAAO,MAAMA,OAAM,cAAc,KAAK,yBAAyB,OAAO,IAAI,SAAS,CAAC,CAAC;AAAA,MACvF;AACA,UAAI,aAAa,GAAG;AAClB,eAAO,WAASA,OAAM,cAAc,KAAK,yBAAyB,OAAO,IAAI,SAAS,CAAC,GAAG,KAAK;AAAA,MACjG;AAEA,aAAO,WACLA,OAAM;AAAA,QACJ;AAAA,QACA,yBAAyB,OAAO,IAAI,SAAS,CAAC;AAAA,QAC9C,CAAC,QAAQ,EAAE,OAAO,IAAI,EAAE,IAAI,gBAAc,4BAA4B,YAAY,KAAK,EAAE,KAAK,CAAC;AAAA,MACjG;AAAA,IACJ;AAAA,EACF;AAGA,QAAM,IAAI;AAAA,IACR;AAAA,IACA;AAAA,MACE,OAAO;AAAA,IACT;AAAA,EACF;AACF;AASO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAIoB;AAClB,SAAO,gBAAiC;AAAA,IACtC,UAAU;AAAA,IACV,wBAAwB;AAAA,IACxB,iBAAiB;AAAA;AAAA,MAEf,KAAK,CAAC,EAAE,SAAS,MAAM,gBAAAA,OAAA,cAAAA,OAAA,gBAAG,QAAS;AAAA;AAAA,MAEnC,MAAM,CAAC,EAAE,KAAK,MAAG;AAjJvB;AAiJ0B,0BAAK,SAAL,YAAa;AAAA;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["React","_a","React"]}
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 {\n ExtensionAttribute,\n Extensions,\n getAttributesFromExtensions,\n getExtensionField,\n getSchemaByResolvedExtensions,\n JSONContent,\n Mark as MarkExtension,\n MarkConfig,\n Node as NodeExtension,\n NodeConfig,\n resolveExtensions,\n splitExtensions,\n} from '@tiptap/core'\nimport { DOMOutputSpec, Mark, Node } from '@tiptap/pm/model'\n\nimport { getHTMLAttributes } from '../helpers.js'\nimport { 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 { 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 { TiptapStaticRenderer, TiptapStaticRendererOptions } 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":";AAGA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EAMA;AAAA,EACA;AAAA,OACK;AACP,SAA8B,YAAY;;;AChB1C,SAAgE,uBAAuB;AAQhF,SAAS,cACd,YACA,qBACA,wBACqB;AACrB,QAAM,uBAAuB,WAAW;AAExC,MAAI,CAAC,sBAAsB;AACzB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,oBACJ,OAAO,UAAQ;AACd,QAAI,KAAK,UAAU,OAAO,WAAW,SAAS,WAAW,WAAW,OAAO,WAAW,KAAK,OAAO;AAChG,aAAO;AAAA,IACT;AACA,QAAI,wBAAwB;AAC1B,aAAO,KAAK,UAAU;AAAA,IACxB;AACA,WAAO;AAAA,EACT,CAAC,EACA,IAAI,UAAQ;AACX,QAAI,CAAC,KAAK,UAAU,YAAY;AAC9B,aAAO;AAAA,QACL,CAAC,KAAK,IAAI,GAAG,KAAK,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;AAjJvB;AAiJ0B,0BAAK,SAAL,YAAa;AAAA;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["React","_a","React"]}
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.0.0-next.4",
4
+ "version": "3.0.0-next.6",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -72,8 +72,8 @@
72
72
  "dist"
73
73
  ],
74
74
  "devDependencies": {
75
- "@tiptap/core": "^3.0.0-next.4",
76
- "@tiptap/pm": "^3.0.0-next.4",
75
+ "@tiptap/core": "^3.0.0-next.6",
76
+ "@tiptap/pm": "^3.0.0-next.6",
77
77
  "@types/react": "^18.2.14",
78
78
  "@types/react-dom": "^18.2.6",
79
79
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
@@ -141,7 +141,7 @@ export function renderToReactElement({
141
141
  domOutputSpecToElement: domOutputSpecToReactElement,
142
142
  mapDefinedTypes: {
143
143
  // Map a doc node to concatenated children
144
- doc: ({ children }) => <>{children}</>,
144
+ doc: ({ children }) => React.createElement(React.Fragment, {}, children),
145
145
  // Map a text node to its text content
146
146
  text: ({ node }) => node.text ?? '',
147
147
  },
File without changes