mirror of
https://github.com/docmost/docmost.git
synced 2025-11-23 14:51:09 +10:00
table of contents node - WIP
This commit is contained in:
@ -20,3 +20,4 @@ export * from "./lib/markdown";
|
||||
export * from "./lib/search-and-replace";
|
||||
export * from "./lib/embed-provider";
|
||||
export * from "./lib/subpages";
|
||||
export * from "./lib/table-of-contents-node";
|
||||
|
||||
@ -0,0 +1 @@
|
||||
export { TableOfContentsNode } from "./table-of-contents";
|
||||
@ -0,0 +1,52 @@
|
||||
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,
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user