mirror of
https://github.com/docmost/docmost.git
synced 2026-05-26 04:22:42 +08:00
53 lines
1.0 KiB
TypeScript
53 lines
1.0 KiB
TypeScript
import { Node } from "@tiptap/core";
|
|
import { ReactNodeViewRenderer } from "@tiptap/react";
|
|
|
|
export interface TableOfContentsNodeOptions {
|
|
HTMLAttributes: Record<string, any>;
|
|
view: any;
|
|
}
|
|
|
|
declare module "@tiptap/core" {
|
|
interface Commands<ReturnType> {
|
|
tableOfContentsNode: {
|
|
insertTableOfContents: () => ReturnType;
|
|
};
|
|
}
|
|
}
|
|
|
|
export const TableOfContentsNode = Node.create<TableOfContentsNodeOptions>({
|
|
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,
|
|
});
|
|
},
|
|
};
|
|
},
|
|
});
|