feat: subpages (child pages) list node (#1462)

* feat: subpages list node

* disable user-select

* support subpages node list in public pages
This commit is contained in:
Philip Okugbe
2025-08-31 18:54:52 +01:00
committed by GitHub
parent 7d1e5bce0d
commit 73ee6ee8c3
20 changed files with 410 additions and 25 deletions

View File

@ -19,3 +19,4 @@ export * from "./lib/mention";
export * from "./lib/markdown";
export * from "./lib/search-and-replace";
export * from "./lib/embed-provider";
export * from "./lib/subpages";

View File

@ -0,0 +1,2 @@
export { Subpages } from "./subpages";
export type { SubpagesAttributes, SubpagesOptions } from "./subpages";

View File

@ -0,0 +1,68 @@
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);
},
});