import { Node } from "@tiptap/core"; import { ReactNodeViewRenderer } from "@tiptap/react"; export interface TableOfContentsNodeOptions { HTMLAttributes: Record; view: any; } declare module "@tiptap/core" { interface Commands { tableOfContentsNode: { insertTableOfContents: () => ReturnType; }; } } export const TableOfContentsNode = Node.create({ name: "tableOfContentsNode", group: "block", atom: true, selectable: true, draggable: true, inline: false, parseHTML() { return [ { tag: 'div[data-type="table-of-content"]', }, ]; }, renderHTML({ HTMLAttributes }) { return ["div", { ...HTMLAttributes, "data-type": "table-of-content" }]; }, addNodeView() { return ReactNodeViewRenderer(this.options.view); }, addCommands() { return { insertTableOfContents: () => ({ commands }) => { return commands.insertContent({ type: this.name, }); }, }; }, });