// Convert the fixture's narrative shape to a ProseMirror document JSON. // Used as the initial content for the TipTap editor. import type { JSONContent } from "@tiptap/react"; import type { FixtureData, NarrativeNode } from "../../lib/fixtures/aristotle"; export function fixtureToDoc(data: FixtureData): JSONContent { const content: JSONContent[] = data.narrative.map(node => narrativeNodeToJSON(node)); return { type: "doc", content, }; } function narrativeNodeToJSON(node: NarrativeNode): JSONContent { if (node.type === "h1") { return { type: "heading", attrs: { level: 1 }, content: node.text ? [{ type: "text", text: node.text }] : [], }; } if (node.type === "h2") { return { type: "heading", attrs: { level: 2 }, content: node.text ? [{ type: "text", text: node.text }] : [], }; } // paragraph const inline: JSONContent[] = []; for (const child of node.children ?? []) { if (child.t === "text") { inline.push({ type: "text", text: child.v }); } else if (child.t === "chip") { inline.push({ type: "chip", attrs: { kind: child.kind, refId: child.id, label: child.label }, }); } } return { type: "paragraph", content: inline }; }