Compare commits

...

1 Commits

Author SHA1 Message Date
Philipinho c354bc7be3 feat: page break command 2025-12-06 22:08:12 +00:00
9 changed files with 62 additions and 5 deletions
@@ -20,6 +20,7 @@ import {
IconCalendar, IconCalendar,
IconAppWindow, IconAppWindow,
IconSitemap, IconSitemap,
IconPageBreak,
} from "@tabler/icons-react"; } from "@tabler/icons-react";
import { import {
CommandProps, CommandProps,
@@ -153,6 +154,19 @@ const CommandGroups: SlashMenuGroupedItemsType = {
command: ({ editor, range }: CommandProps) => command: ({ editor, range }: CommandProps) =>
editor.chain().focus().deleteRange(range).setHorizontalRule().run(), editor.chain().focus().deleteRange(range).setHorizontalRule().run(),
}, },
{
title: "Page break",
description: "Insert page break",
searchTerms: ["page break", "hr"],
icon: IconPageBreak,
command: ({ editor, range }: CommandProps) =>
editor
.chain()
.focus()
.deleteRange(range)
.insertContent('<hr data-type="pagebreak" /><p></p>')
.run(),
},
{ {
title: "Image", title: "Image",
description: "Upload any image from your device.", description: "Upload any image from your device.",
@@ -46,6 +46,7 @@ import {
Heading, Heading,
Highlight, Highlight,
UniqueID, UniqueID,
HorizontalRule,
} from "@docmost/editor-ext"; } from "@docmost/editor-ext";
import { import {
randomElement, randomElement,
@@ -108,7 +109,9 @@ export const mainExtensions = [
spellcheck: false, spellcheck: false,
}, },
}, },
horizontalRule: false,
}), }),
HorizontalRule,
Heading, Heading,
UniqueID.configure({ UniqueID.configure({
types: ["heading", "paragraph"], types: ["heading", "paragraph"],
@@ -110,6 +110,14 @@
border-top: 1px solid #68cef8; border-top: 1px solid #68cef8;
} }
hr[data-type="pagebreak"] {
border-top: 1px dashed var(--mantine-color-dark-2) !important;
}
.ProseMirror[contenteditable="false"] hr[data-type="pagebreak"] {
display: none !important;
}
.ProseMirror-selectednode { .ProseMirror-selectednode {
outline: 2px solid #70cff8; outline: 2px solid #70cff8;
} }
@@ -186,7 +194,6 @@
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
} }
.ProseMirror > h1, .ProseMirror > h1,
@@ -195,13 +202,11 @@
.ProseMirror > h4, .ProseMirror > h4,
.ProseMirror > h5, .ProseMirror > h5,
.ProseMirror > h6 { .ProseMirror > h6 {
> .link-btn { > .link-btn {
cursor: pointer; cursor: pointer;
position: relative; position: relative;
} }
> .link-btn > .link-btn-content { > .link-btn > .link-btn-content {
opacity: 0; opacity: 0;
position: absolute; position: absolute;
@@ -213,7 +218,7 @@
justify-content: center; justify-content: center;
flex-direction: column; flex-direction: column;
} }
&:hover > .link-btn > .link-btn-content { &:hover > .link-btn > .link-btn-content {
opacity: 1; opacity: 1;
} }
@@ -20,4 +20,10 @@
.tableWrapper { .tableWrapper {
overflow: hidden !important; overflow: hidden !important;
} }
hr[data-type="pagebreak"] {
break-before: always;
page-break-before: always;
visibility: hidden;
}
} }
@@ -36,6 +36,7 @@ import {
Highlight, Highlight,
UniqueID, UniqueID,
addUniqueIdsToDoc, addUniqueIdsToDoc,
HorizontalRule,
} from '@docmost/editor-ext'; } from '@docmost/editor-ext';
import { generateText, getSchema, JSONContent } from '@tiptap/core'; import { generateText, getSchema, JSONContent } from '@tiptap/core';
import { generateHTML, generateJSON } from '../common/helpers/prosemirror/html'; import { generateHTML, generateJSON } from '../common/helpers/prosemirror/html';
@@ -48,7 +49,9 @@ export const tiptapExtensions = [
StarterKit.configure({ StarterKit.configure({
codeBlock: false, codeBlock: false,
heading: false, heading: false,
horizontalRule: false,
}), }),
HorizontalRule,
Heading, Heading,
UniqueID.configure({ UniqueID.configure({
types: ['heading', 'paragraph'], types: ['heading', 'paragraph'],
+1
View File
@@ -38,6 +38,7 @@
"@tiptap/extension-heading": "2.27.1", "@tiptap/extension-heading": "2.27.1",
"@tiptap/extension-highlight": "2.27.1", "@tiptap/extension-highlight": "2.27.1",
"@tiptap/extension-history": "2.27.1", "@tiptap/extension-history": "2.27.1",
"@tiptap/extension-horizontal-rule": "2.27.1",
"@tiptap/extension-image": "2.27.1", "@tiptap/extension-image": "2.27.1",
"@tiptap/extension-link": "2.27.1", "@tiptap/extension-link": "2.27.1",
"@tiptap/extension-list-item": "2.27.1", "@tiptap/extension-list-item": "2.27.1",
+1
View File
@@ -23,3 +23,4 @@ export * from "./lib/subpages";
export * from "./lib/highlight"; export * from "./lib/highlight";
export * from "./lib/heading/heading"; export * from "./lib/heading/heading";
export * from "./lib/unique-id"; export * from "./lib/unique-id";
export * from "./lib/hr";
+21
View File
@@ -0,0 +1,21 @@
import { HorizontalRule as TiptapHorizontalRule } from "@tiptap/extension-horizontal-rule";
export type HorizontalRuleType = "pageBreak";
export const HorizontalRule = TiptapHorizontalRule.extend({
addAttributes() {
return {
type: {
default: null,
parseHTML: (element) => element.getAttribute("data-type"),
renderHTML: (attributes) => {
if (attributes.type) {
return {
"data-type": attributes.type,
};
}
},
},
};
},
});
+3
View File
@@ -77,6 +77,9 @@ importers:
'@tiptap/extension-history': '@tiptap/extension-history':
specifier: 2.27.1 specifier: 2.27.1
version: 2.27.1(@tiptap/core@2.27.1(@tiptap/pm@2.27.1))(@tiptap/pm@2.27.1) version: 2.27.1(@tiptap/core@2.27.1(@tiptap/pm@2.27.1))(@tiptap/pm@2.27.1)
'@tiptap/extension-horizontal-rule':
specifier: 2.27.1
version: 2.27.1(@tiptap/core@2.27.1(@tiptap/pm@2.27.1))(@tiptap/pm@2.27.1)
'@tiptap/extension-image': '@tiptap/extension-image':
specifier: 2.27.1 specifier: 2.27.1
version: 2.27.1(@tiptap/core@2.27.1(@tiptap/pm@2.27.1)) version: 2.27.1(@tiptap/core@2.27.1(@tiptap/pm@2.27.1))