Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Page break #1372

Merged
merged 9 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/01-basic/04-all-blocks/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export default function App() {
],
},
},
{ type: "pageBreak" },
{
type: "file",
},
Expand Down
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div data-page-break=""></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1"><div class="bn-block-content" data-content-type="pageBreak"><div class="bn-page-break" data-page-break=""></div></div></div></div></div>
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,22 @@ exports[`Test BlockNote-Prosemirror conversion > Case: default schema > Convert
}
`;

exports[`Test BlockNote-Prosemirror conversion > Case: default schema > Convert pageBreak/basic to/from prosemirror 1`] = `
{
"attrs": {
"backgroundColor": "default",
"id": "1",
"textColor": "default",
},
"content": [
{
"type": "pageBreak",
},
],
"type": "blockContainer",
}
`;

exports[`Test BlockNote-Prosemirror conversion > Case: default schema > Convert paragraph/basic to/from prosemirror 1`] = `
{
"attrs": {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/api/testUtil/cases/defaultSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ export const defaultSchemaTestCases: EditorTestCases<
},
],
},
{
name: "pageBreak/basic",
blocks: [
{
type: "pageBreak",
},
],
},
{
name: "file/button",
blocks: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
createBlockSpec,
CustomBlockConfig,
Props,
} from "../../schema/index.js";

export const pageBreakConfig = {
type: "pageBreak" as const,
propSchema: {},
content: "none",
isFileBlock: false,
} satisfies CustomBlockConfig;
export const pageBreakRender = () => {
const pageBreak = document.createElement("div");

pageBreak.className = "bn-page-break";
pageBreak.setAttribute("data-page-break", "");

return {
dom: pageBreak,
};
};
export const pageBreakParse = (
element: HTMLElement
): Partial<Props<typeof pageBreakConfig.propSchema>> | undefined => {
if (element.tagName === "DIV" && element.hasAttribute("data-page-break")) {
return {
type: "pageBreak",
};
}

return undefined;
};
export const pageBreakToExternalHTML = () => {
const pageBreak = document.createElement("div");

pageBreak.setAttribute("data-page-break", "");

return {
dom: pageBreak,
};
};

export const PageBreak = createBlockSpec(pageBreakConfig, {
render: pageBreakRender,
parse: pageBreakParse,
toExternalHTML: pageBreakToExternalHTML,
});
2 changes: 2 additions & 0 deletions packages/core/src/blocks/defaultBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {

import { AudioBlock } from "./AudioBlockContent/AudioBlockContent.js";
import { CodeBlock } from "./CodeBlockContent/CodeBlockContent.js";
import { PageBreak } from "./PageBreakBlockContent/PageBreakBlockContent.js";
import { FileBlock } from "./FileBlockContent/FileBlockContent.js";
import { Heading } from "./HeadingBlockContent/HeadingBlockContent.js";
import { ImageBlock } from "./ImageBlockContent/ImageBlockContent.js";
Expand All @@ -38,6 +39,7 @@ export const defaultBlockSpecs = {
paragraph: Paragraph,
heading: Heading,
codeBlock: CodeBlock,
pageBreak: PageBreak,
bulletListItem: BulletListItem,
numberedListItem: NumberedListItem,
checkListItem: CheckListItem,
Expand Down
16 changes: 15 additions & 1 deletion packages/core/src/editor/Block.css
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,20 @@ NESTED BLOCKS
transition-delay: 0.1s;
}

/* PAGE BREAK */
.bn-block-content[data-content-type="pageBreak"] > div {
width: 100%;
height: 8px;
background: linear-gradient(
to right,
rgb(22 22 22) 50%,
rgb(255, 255, 255, 0) 0%
);
background-position: center;
background-size: 16px 1.5px;
background-repeat: repeat-x;
}

/* FILES */

/* Element that wraps content for all file blocks */
Expand Down Expand Up @@ -336,7 +350,7 @@ NESTED BLOCKS

.bn-editor[contenteditable="true"] [data-file-block] .bn-add-file-button:hover,
[data-file-block] .bn-file-name-with-icon:hover,
.ProseMirror-selectednode .bn-file-name-with-icon{
.ProseMirror-selectednode .bn-file-name-with-icon {
background-color: rgb(225, 225, 225);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ export function getDefaultSlashMenuItems<
});
}

if (checkDefaultBlockTypeInSchema("pageBreak", editor)) {
items.push({
onItemClick: () => {
insertOrUpdateBlock(editor, {
type: "pageBreak",
});
},
key: "page_break",
...editor.dictionary.slash_menu.page_break,
});
}

if (checkDefaultBlockTypeInSchema("table", editor)) {
items.push({
onItemClick: () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/i18n/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export const ar: Dictionary = {
aliases: ["كود", "مسبق"],
group: "الكتل الأساسية",
},
page_break: {
title: "فاصل الصفحة",
subtext: "فاصل الصفحة",
aliases: ["page", "break", "separator", "فاصل", "الصفحة"],
group: "الكتل الأساسية",
},
table: {
title: "جدول",
subtext: "يستخدم للجداول",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/i18n/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export const de = {
aliases: ["code", "pre"],
group: "Grundlegende blöcke",
},
page_break: {
title: "Seitenumbruch",
subtext: "Seitentrenner",
aliases: ["page", "break", "separator", "seitenumbruch", "trenner"],
group: "Grundlegende Blöcke",
},
table: {
title: "Tabelle",
subtext: "Tabelle mit editierbaren Zellen",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export const en = {
aliases: ["code", "pre"],
group: "Basic blocks",
},
page_break: {
title: "Page Break",
subtext: "Page separator",
aliases: ["page", "break", "separator"],
group: "Basic blocks",
},
table: {
title: "Table",
subtext: "Table with editable cells",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/i18n/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export const es = {
aliases: ["code", "pre"],
group: "Bloques básicos",
},
page_break: {
title: "Salto de página",
subtext: "Separador de página",
aliases: ["page", "break", "separator", "salto", "separador"],
group: "Bloques básicos",
},
table: {
title: "Tabla",
subtext: "Tabla con celdas editables",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/i18n/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export const fr: Dictionary = {
aliases: ["code", "pre"],
group: "Blocs de base",
},
page_break: {
title: "Saut de page",
subtext: "Séparateur de page",
aliases: ["page", "break", "separator", "saut", "séparateur"],
group: "Blocs de base",
},
table: {
title: "Tableau",
subtext: "Utilisé pour les tableaux",
Expand Down
Loading
Loading