import type * as React from 'react' import type { Node as ProseMirrorNode } from '@tiptap/pm/model' import type { NodeProps } from '@tiptap/static-renderer' import { getContentEditorExtensions } from '@admin/utils/editor/get-content-editor-extensions' import { prepareMarkdownForRichMode } from '@admin/utils/editor/prepare-markdown-for-rich-mode' import { MarkdownManager } from '@tiptap/markdown' import { renderToReactElement } from '@tiptap/static-renderer' // Renders a content value the way the rich editor would, as plain React elements (no HTML string, // so nothing in the markdown is injected). Tiptap can only build the live editor in the browser, // so this is the editor card's first paint on the server and before hydration; the live // ProseMirror view replaces it once it exists; `nodeMapping` swaps in React parts for nodes whose // live view is a node view (task items). Returns null when the value cannot be parsed. export function renderContentEditorStatic( markdown: string, nodeMapping?: Record< string, (props: NodeProps) => React.ReactNode > ): React.ReactNode { if (!markdown.trim()) return null try { const extensions = getContentEditorExtensions() const content = new MarkdownManager({ extensions }).parse(prepareMarkdownForRichMode(markdown)) return renderToReactElement({ content, extensions, options: { nodeMapping } }) } catch { return null } }