@blocknote/xl-multi-column 0.47.2 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { setupTestEnv } from "../setupTestEnv.js";
4
+ import { BlockNoteEditor } from "@blocknote/core";
5
+
6
+ const getEditor = setupTestEnv();
7
+
8
+ function pressBackspace(editor: BlockNoteEditor<any, any, any>) {
9
+ const view = editor._tiptapEditor.view;
10
+ const event = new KeyboardEvent("keydown", {
11
+ key: "Backspace",
12
+ code: "Backspace",
13
+ keyCode: 8,
14
+ bubbles: true,
15
+ });
16
+ view.someProp("handleKeyDown", (f: any) => f(view, event));
17
+ }
18
+
19
+ function pressDelete(editor: BlockNoteEditor<any, any, any>) {
20
+ const view = editor._tiptapEditor.view;
21
+ const event = new KeyboardEvent("keydown", {
22
+ key: "Delete",
23
+ code: "Delete",
24
+ keyCode: 46,
25
+ bubbles: true,
26
+ });
27
+ view.someProp("handleKeyDown", (f: any) => f(view, event));
28
+ }
29
+
30
+ const threeColumnsWithParagraphBelow = [
31
+ {
32
+ type: "columnList" as const,
33
+ children: [
34
+ {
35
+ type: "column" as const,
36
+ children: [
37
+ { id: "col1-para", type: "paragraph" as const, content: "col1" },
38
+ ],
39
+ },
40
+ {
41
+ type: "column" as const,
42
+ children: [
43
+ { id: "col2-para", type: "paragraph" as const, content: "col2" },
44
+ ],
45
+ },
46
+ {
47
+ type: "column" as const,
48
+ children: [
49
+ { id: "col3-para", type: "paragraph" as const, content: "hello" },
50
+ ],
51
+ },
52
+ ],
53
+ },
54
+ ];
55
+
56
+ const threeColumnsWithParagraphAbove = [
57
+ {
58
+ type: "columnList" as const,
59
+ children: [
60
+ {
61
+ type: "column" as const,
62
+ children: [
63
+ { id: "col1-para", type: "paragraph" as const, content: "world" },
64
+ ],
65
+ },
66
+ {
67
+ type: "column" as const,
68
+ children: [
69
+ {
70
+ id: "col2-para",
71
+ type: "paragraph" as const,
72
+ content: "universe",
73
+ },
74
+ ],
75
+ },
76
+ {
77
+ type: "column" as const,
78
+ children: [
79
+ { id: "col3-para", type: "paragraph" as const, content: "planet" },
80
+ ],
81
+ },
82
+ ],
83
+ },
84
+ ];
85
+
86
+ describe("Backspace with multi-column", () => {
87
+ // TODO: When migrating to vitest browser mode, replace this test with
88
+ // a version that presses Backspace 5 times from offset 5 in "hello world"
89
+ // and asserts " world" remains. Character deletion relies on contentEditable
90
+ // which is not available in jsdom.
91
+ it("mid-text backspace next to columnList should not move block", () => {
92
+ const editor = getEditor();
93
+ editor.replaceBlocks(editor.document, [
94
+ ...threeColumnsWithParagraphBelow,
95
+ {
96
+ id: "below-para",
97
+ type: "paragraph" as const,
98
+ content: "hello world",
99
+ },
100
+ ]);
101
+
102
+ // Place cursor at offset 5 (after "hello", mid-text).
103
+ editor.setTextCursorPosition("below-para", "start");
104
+ const view = editor._tiptapEditor.view;
105
+ const startPos = editor.transact((tr) => tr.selection.$from.pos);
106
+ view.dispatch(
107
+ view.state.tr.setSelection(
108
+ (view.state.selection.constructor as any).create(
109
+ view.state.doc,
110
+ startPos + 5,
111
+ ),
112
+ ),
113
+ );
114
+
115
+ pressBackspace(editor);
116
+ expect(editor.document).toMatchSnapshot();
117
+ });
118
+
119
+ it("backspace at block start should move block into last column", () => {
120
+ const editor = getEditor();
121
+ editor.replaceBlocks(editor.document, [
122
+ ...threeColumnsWithParagraphBelow,
123
+ { id: "below-para", type: "paragraph" as const, content: " world" },
124
+ ]);
125
+
126
+ editor.setTextCursorPosition("below-para", "start");
127
+ pressBackspace(editor);
128
+ expect(editor.document).toMatchSnapshot();
129
+ });
130
+
131
+ it("second backspace should merge into previous block in column", () => {
132
+ const editor = getEditor();
133
+ editor.replaceBlocks(editor.document, [
134
+ ...threeColumnsWithParagraphBelow,
135
+ { id: "below-para", type: "paragraph" as const, content: " world" },
136
+ ]);
137
+
138
+ editor.setTextCursorPosition("below-para", "start");
139
+ pressBackspace(editor);
140
+ pressBackspace(editor);
141
+ expect(editor.document).toMatchSnapshot();
142
+ });
143
+ });
144
+
145
+ describe("Delete with multi-column", () => {
146
+ // TODO: When migrating to vitest browser mode, replace this test with
147
+ // a version that presses Delete 5 times from offset 6 in "hello world"
148
+ // and asserts "hello " remains. Character deletion relies on contentEditable
149
+ // which is not available in jsdom.
150
+ it("mid-text delete next to columnList should not move block", () => {
151
+ const editor = getEditor();
152
+ editor.replaceBlocks(editor.document, [
153
+ {
154
+ id: "above-para",
155
+ type: "paragraph" as const,
156
+ content: "hello world",
157
+ },
158
+ ...threeColumnsWithParagraphAbove,
159
+ ]);
160
+
161
+ // Place cursor at offset 6 (after "hello ", mid-text).
162
+ editor.setTextCursorPosition("above-para", "start");
163
+ const view = editor._tiptapEditor.view;
164
+ const startPos = editor.transact((tr) => tr.selection.$from.pos);
165
+ view.dispatch(
166
+ view.state.tr.setSelection(
167
+ (view.state.selection.constructor as any).create(
168
+ view.state.doc,
169
+ startPos + 6,
170
+ ),
171
+ ),
172
+ );
173
+
174
+ pressDelete(editor);
175
+ expect(editor.document).toMatchSnapshot();
176
+ });
177
+
178
+ it("delete at block end should move first column block out", () => {
179
+ const editor = getEditor();
180
+ editor.replaceBlocks(editor.document, [
181
+ { id: "above-para", type: "paragraph" as const, content: "hello " },
182
+ ...threeColumnsWithParagraphAbove,
183
+ ]);
184
+
185
+ editor.setTextCursorPosition("above-para", "end");
186
+ pressDelete(editor);
187
+ expect(editor.document).toMatchSnapshot();
188
+ });
189
+
190
+ it("second delete should merge first column block into paragraph", () => {
191
+ const editor = getEditor();
192
+ editor.replaceBlocks(editor.document, [
193
+ { id: "above-para", type: "paragraph" as const, content: "hello " },
194
+ ...threeColumnsWithParagraphAbove,
195
+ ]);
196
+
197
+ editor.setTextCursorPosition("above-para", "end");
198
+ pressDelete(editor);
199
+ pressDelete(editor);
200
+ expect(editor.document).toMatchSnapshot();
201
+ });
202
+ });
@@ -0,0 +1 @@
1
+ export {};