feat(editor): add page break node

This commit is contained in:
Philipinho
2026-05-14 03:47:27 +01:00
parent 3b983a27f6
commit 425924cb4d
10 changed files with 135 additions and 0 deletions
+1
View File
@@ -31,5 +31,6 @@ export * from "./lib/recreate-transform";
export * from "./lib/columns";
export * from "./lib/status";
export * from "./lib/pdf";
export * from "./lib/page-break";
export * from "./lib/resizable-nodeview";
@@ -0,0 +1 @@
export * from "./page-break";
@@ -0,0 +1,60 @@
import { mergeAttributes, Node } from "@tiptap/core";
export interface PageBreakOptions {
HTMLAttributes: Record<string, any>;
}
declare module "@tiptap/core" {
interface Commands<ReturnType> {
pageBreak: {
setPageBreak: () => ReturnType;
};
}
}
export const PageBreak = Node.create<PageBreakOptions>({
name: "pageBreak",
group: "block",
atom: true,
selectable: true,
addOptions() {
return {
HTMLAttributes: {},
};
},
parseHTML() {
return [
{
tag: `div[data-type="${this.name}"]`,
},
];
},
renderHTML({ HTMLAttributes }) {
return [
"div",
mergeAttributes(
{ "data-type": this.name, class: "page-break" },
this.options.HTMLAttributes,
HTMLAttributes,
),
];
},
addCommands() {
return {
setPageBreak:
() =>
({ chain }) =>
chain()
.insertContent({ type: this.name })
.focus()
.run(),
};
},
});