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

simple latex block #818

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
Merge branch 'main' into feature/latex
# Conflicts:
#	packages/core/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap
#	packages/core/src/api/blockManipulation/blockManipulation.test.ts
#	packages/core/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap
  • Loading branch information
jkcs committed Jun 7, 2024
commit 9a8871b603bfb5a0fb7c6f58cbf0a13ac07ce60b
Original file line number Diff line number Diff line change
Expand Up @@ -615,4 +615,100 @@ exports[`Inserting Blocks with Different Placements > Insert nested inside exist
]
`;

exports[`Update Custom Block content > update Custom Block with line break 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=\\"customBlock\\"><div class=\\"bn-inline-content custom-block\\" data-editable=\\"\\">Updated Custom Block with <br>line <br>break</div></div><div class=\\"bn-block-group\\" data-node-type=\\"blockGroup\\"><div class=\\"bn-block-outer\\" data-node-type=\\"blockOuter\\" data-id=\\"2\\"><div class=\\"bn-block\\" data-node-type=\\"blockContainer\\" data-id=\\"2\\"><div class=\\"bn-block-content\\" data-content-type=\\"customBlock\\"><div class=\\"bn-inline-content custom-block\\" data-editable=\\"\\">Custom Block</div></div></div></div></div></div></div><div class=\\"bn-block-outer\\" data-node-type=\\"blockOuter\\" data-id=\\"0\\"><div class=\\"bn-block\\" data-node-type=\\"blockContainer\\" data-id=\\"0\\"><div class=\\"bn-block-content\\" data-content-type=\\"paragraph\\"><p class=\\"bn-inline-content\\"></p></div></div></div></div>"`;
exports[`Update Line Breaks > Update custom block with line break 1`] = `
[
{
"children": [],
"content": [
{
"styles": {},
"text": "Line1
Line2",
"type": "text",
},
],
"id": "1",
"props": {
"backgroundColor": "default",
"textAlignment": "left",
"textColor": "default",
},
"type": "paragraph",
},
{
"children": [],
"content": [
{
"styles": {},
"text": "Updated Custom Block with
line
break",
"type": "text",
},
],
"id": "2",
"props": {},
"type": "customBlock",
},
{
"children": [],
"content": [],
"id": "0",
"props": {
"backgroundColor": "default",
"textAlignment": "left",
"textColor": "default",
},
"type": "paragraph",
},
]
`;

exports[`Update Line Breaks > Update paragraph with line break 1`] = `
[
{
"children": [],
"content": [
{
"styles": {},
"text": "Updated Custom Block with
line
break",
"type": "text",
},
],
"id": "1",
"props": {
"backgroundColor": "default",
"textAlignment": "left",
"textColor": "default",
},
"type": "paragraph",
},
{
"children": [],
"content": [
{
"styles": {},
"text": "Line1
Line2",
"type": "text",
},
],
"id": "2",
"props": {},
"type": "customBlock",
},
{
"children": [],
"content": [],
"id": "0",
"props": {
"backgroundColor": "default",
"textAlignment": "left",
"textColor": "default",
},
"type": "paragraph",
},
]
`;
59 changes: 32 additions & 27 deletions packages/core/src/api/blockManipulation/blockManipulation.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import {
Block,
DefaultBlockSchema,
defaultBlockSpecs,
DefaultInlineContentSchema,
DefaultStyleSchema,
Expand All @@ -10,14 +9,13 @@ import {
import { BlockNoteEditor } from "../../editor/BlockNoteEditor";
import { createBlockSpec } from "../../schema";
import { BlockNoteSchema } from "../../editor/BlockNoteSchema";
import { createInternalHTMLSerializer } from "../exporters/html/internalHTMLSerializer";

const CustomBlock = createBlockSpec(
{
type: "customBlock",
propSchema: {},
content: "inline",
},
} as const,
{
render: () => {
const dom = document.createElement("div");
Expand All @@ -34,7 +32,7 @@ const CustomBlock = createBlockSpec(
const schema = BlockNoteSchema.create({
blockSpecs: {
...defaultBlockSpecs,
customBlock: CustomBlock
customBlock: CustomBlock,
},
});

Expand Down Expand Up @@ -70,12 +68,6 @@ let blocksWithLineBreaks: PartialBlock<
DefaultStyleSchema
>[];

let customBlock: PartialBlock<
typeof schema.blockSchema,
DefaultInlineContentSchema,
DefaultStyleSchema
>;

let insert: (
placement: "before" | "nested" | "after"
) => Block<
Expand All @@ -86,7 +78,7 @@ let insert: (

beforeEach(() => {
editor = BlockNoteEditor.create<typeof schema.blockSchema>({
schema: schema
schema: schema,
});

editor.mount(div);
Expand Down Expand Up @@ -131,10 +123,16 @@ beforeEach(() => {
},
];

customBlock = {
type: 'customBlock',
content: 'Custom Block',
}
blocksWithLineBreaks = [
{
type: "paragraph",
content: "Line1\nLine2",
},
{
type: "customBlock",
content: "Line1\nLine2",
},
];

insert = (placement) => {
const existingBlock = editor.document[0];
Expand Down Expand Up @@ -287,26 +285,33 @@ describe("Insert, Update, & Delete Blocks", () => {
});
});

describe("Update Custom Block content", () => {
it("update Custom Block with line break", async () => {
describe("Update Line Breaks", () => {
it("Update paragraph with line break", async () => {
await waitForEditor();

const existingBlock = editor.document[0];
editor.insertBlocks([customBlock], existingBlock);
editor.insertBlocks(blocksWithLineBreaks, existingBlock);

const newBlock = editor.document[0];
editor.updateBlock(newBlock, {
type: "paragraph",
content: "Updated Custom Block with \nline \nbreak",
});

expect(editor.document).toMatchSnapshot();
});
it("Update custom block with line break", async () => {
await waitForEditor();

const existingBlock = editor.document[0];
editor.insertBlocks(blocksWithLineBreaks, existingBlock);

const newBlock = editor.document[1];
editor.updateBlock(newBlock, {
type: "customBlock",
content: "Updated Custom Block with \nline \nbreak",
children: [customBlock],
});

const serializer = createInternalHTMLSerializer(
editor._tiptapEditor.schema,
editor
);
const internalHTML = serializer.serializeBlocks(editor.document);

expect(internalHTML).toMatchSnapshot();
expect(editor.document).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Test BlockNote-Prosemirror conversion > Case: custom blocks schema > Convert customBlock/basic to/from prosemirror 1`] = `
exports[`Test BlockNote-Prosemirror conversion > Case: custom blocks schema > Convert customParagraph/basic to/from prosemirror 1`] = `
{
"attrs": {
"backgroundColor": "default",
Expand All @@ -9,20 +9,23 @@ exports[`Test BlockNote-Prosemirror conversion > Case: custom blocks schema > Co
},
"content": [
{
"attrs": {
"textAlignment": "left",
},
"content": [
{
"text": "Custom customBlock",
"text": "Custom Paragraph",
"type": "text",
},
],
"type": "customBlock",
"type": "customParagraph",
},
],
"type": "blockContainer",
}
`;

exports[`Test BlockNote-Prosemirror conversion > Case: custom blocks schema > Convert customParagraph/basic to/from prosemirror 1`] = `
exports[`Test BlockNote-Prosemirror conversion > Case: custom blocks schema > Convert customParagraph/lineBreaks to/from prosemirror 1`] = `
{
"attrs": {
"backgroundColor": "default",
Expand All @@ -36,7 +39,14 @@ exports[`Test BlockNote-Prosemirror conversion > Case: custom blocks schema > Co
},
"content": [
{
"text": "Custom Paragraph",
"text": "Line 1",
"type": "text",
},
{
"type": "hardBreak",
},
{
"text": "Line 2",
"type": "text",
},
],
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.