mirror of
https://github.com/docmost/docmost.git
synced 2026-05-20 00:14:10 +08:00
61 lines
1012 B
TypeScript
61 lines
1012 B
TypeScript
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(),
|
|
};
|
|
},
|
|
});
|