mirror of
https://github.com/docmost/docmost.git
synced 2026-07-25 20:04:46 +10:00
73ee6ee8c3
* feat: subpages list node * disable user-select * support subpages node list in public pages
69 lines
1.2 KiB
TypeScript
69 lines
1.2 KiB
TypeScript
import { mergeAttributes, Node } from "@tiptap/core";
|
|
import { ReactNodeViewRenderer } from "@tiptap/react";
|
|
|
|
export interface SubpagesOptions {
|
|
HTMLAttributes: Record<string, any>;
|
|
view: any;
|
|
}
|
|
|
|
export interface SubpagesAttributes {}
|
|
|
|
declare module "@tiptap/core" {
|
|
interface Commands<ReturnType> {
|
|
subpages: {
|
|
insertSubpages: (attributes?: SubpagesAttributes) => ReturnType;
|
|
};
|
|
}
|
|
}
|
|
|
|
export const Subpages = Node.create<SubpagesOptions>({
|
|
name: "subpages",
|
|
|
|
addOptions() {
|
|
return {
|
|
HTMLAttributes: {},
|
|
view: null,
|
|
};
|
|
},
|
|
|
|
group: "block",
|
|
atom: true,
|
|
draggable: false,
|
|
|
|
parseHTML() {
|
|
return [
|
|
{
|
|
tag: `div[data-type="${this.name}"]`,
|
|
},
|
|
];
|
|
},
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
return [
|
|
"div",
|
|
mergeAttributes(
|
|
{ "data-type": this.name },
|
|
this.options.HTMLAttributes,
|
|
HTMLAttributes,
|
|
),
|
|
];
|
|
},
|
|
|
|
addCommands() {
|
|
return {
|
|
insertSubpages:
|
|
(attributes) =>
|
|
({ commands }) => {
|
|
return commands.insertContent({
|
|
type: this.name,
|
|
attrs: attributes,
|
|
});
|
|
},
|
|
};
|
|
},
|
|
|
|
addNodeView() {
|
|
return ReactNodeViewRenderer(this.options.view);
|
|
},
|
|
});
|