@blocknote/xl-multi-column 0.41.1 → 0.42.1

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,408 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`Test fixColumnList > First of two columns empty 1`] = `
4
+ {
5
+ "content": [
6
+ {
7
+ "content": [
8
+ {
9
+ "attrs": {
10
+ "id": null,
11
+ },
12
+ "content": [
13
+ {
14
+ "attrs": {
15
+ "backgroundColor": "default",
16
+ "textAlignment": "left",
17
+ "textColor": "default",
18
+ },
19
+ "content": [
20
+ {
21
+ "text": "Paragraph 1",
22
+ "type": "text",
23
+ },
24
+ ],
25
+ "type": "paragraph",
26
+ },
27
+ ],
28
+ "type": "blockContainer",
29
+ },
30
+ ],
31
+ "type": "blockGroup",
32
+ },
33
+ ],
34
+ "type": "doc",
35
+ }
36
+ `;
37
+
38
+ exports[`Test fixColumnList > Last of two columns empty 1`] = `
39
+ {
40
+ "content": [
41
+ {
42
+ "content": [
43
+ {
44
+ "attrs": {
45
+ "id": null,
46
+ },
47
+ "content": [
48
+ {
49
+ "attrs": {
50
+ "backgroundColor": "default",
51
+ "textAlignment": "left",
52
+ "textColor": "default",
53
+ },
54
+ "content": [
55
+ {
56
+ "text": "Paragraph 1",
57
+ "type": "text",
58
+ },
59
+ ],
60
+ "type": "paragraph",
61
+ },
62
+ ],
63
+ "type": "blockContainer",
64
+ },
65
+ ],
66
+ "type": "blockGroup",
67
+ },
68
+ ],
69
+ "type": "doc",
70
+ }
71
+ `;
72
+
73
+ exports[`Test fixColumnList > Two empty columns 1`] = `
74
+ {
75
+ "content": [
76
+ {
77
+ "content": [
78
+ {
79
+ "attrs": {
80
+ "id": null,
81
+ },
82
+ "content": [
83
+ {
84
+ "attrs": {
85
+ "backgroundColor": "default",
86
+ "textAlignment": "left",
87
+ "textColor": "default",
88
+ },
89
+ "type": "paragraph",
90
+ },
91
+ ],
92
+ "type": "blockContainer",
93
+ },
94
+ ],
95
+ "type": "blockGroup",
96
+ },
97
+ ],
98
+ "type": "doc",
99
+ }
100
+ `;
101
+
102
+ exports[`Test removeEmptyColumns > First of two columns empty 1`] = `
103
+ {
104
+ "content": [
105
+ {
106
+ "content": [
107
+ {
108
+ "attrs": {
109
+ "id": null,
110
+ },
111
+ "content": [
112
+ {
113
+ "attrs": {
114
+ "id": null,
115
+ "width": 1,
116
+ },
117
+ "content": [
118
+ {
119
+ "attrs": {
120
+ "id": null,
121
+ },
122
+ "content": [
123
+ {
124
+ "attrs": {
125
+ "backgroundColor": "default",
126
+ "textAlignment": "left",
127
+ "textColor": "default",
128
+ },
129
+ "type": "paragraph",
130
+ },
131
+ ],
132
+ "type": "blockContainer",
133
+ },
134
+ ],
135
+ "type": "column",
136
+ },
137
+ {
138
+ "attrs": {
139
+ "id": null,
140
+ "width": 1,
141
+ },
142
+ "content": [
143
+ {
144
+ "attrs": {
145
+ "id": null,
146
+ },
147
+ "content": [
148
+ {
149
+ "attrs": {
150
+ "backgroundColor": "default",
151
+ "textAlignment": "left",
152
+ "textColor": "default",
153
+ },
154
+ "content": [
155
+ {
156
+ "text": "Paragraph 1",
157
+ "type": "text",
158
+ },
159
+ ],
160
+ "type": "paragraph",
161
+ },
162
+ ],
163
+ "type": "blockContainer",
164
+ },
165
+ ],
166
+ "type": "column",
167
+ },
168
+ ],
169
+ "type": "columnList",
170
+ },
171
+ ],
172
+ "type": "blockGroup",
173
+ },
174
+ ],
175
+ "type": "doc",
176
+ }
177
+ `;
178
+
179
+ exports[`Test removeEmptyColumns > Last of two columns empty 1`] = `
180
+ {
181
+ "content": [
182
+ {
183
+ "content": [
184
+ {
185
+ "attrs": {
186
+ "id": null,
187
+ },
188
+ "content": [
189
+ {
190
+ "attrs": {
191
+ "id": null,
192
+ "width": 1,
193
+ },
194
+ "content": [
195
+ {
196
+ "attrs": {
197
+ "id": null,
198
+ },
199
+ "content": [
200
+ {
201
+ "attrs": {
202
+ "backgroundColor": "default",
203
+ "textAlignment": "left",
204
+ "textColor": "default",
205
+ },
206
+ "content": [
207
+ {
208
+ "text": "Paragraph 1",
209
+ "type": "text",
210
+ },
211
+ ],
212
+ "type": "paragraph",
213
+ },
214
+ ],
215
+ "type": "blockContainer",
216
+ },
217
+ ],
218
+ "type": "column",
219
+ },
220
+ {
221
+ "attrs": {
222
+ "id": null,
223
+ "width": 1,
224
+ },
225
+ "content": [
226
+ {
227
+ "attrs": {
228
+ "id": null,
229
+ },
230
+ "content": [
231
+ {
232
+ "attrs": {
233
+ "backgroundColor": "default",
234
+ "textAlignment": "left",
235
+ "textColor": "default",
236
+ },
237
+ "type": "paragraph",
238
+ },
239
+ ],
240
+ "type": "blockContainer",
241
+ },
242
+ ],
243
+ "type": "column",
244
+ },
245
+ ],
246
+ "type": "columnList",
247
+ },
248
+ ],
249
+ "type": "blockGroup",
250
+ },
251
+ ],
252
+ "type": "doc",
253
+ }
254
+ `;
255
+
256
+ exports[`Test removeEmptyColumns > Start and end columns empty 1`] = `
257
+ {
258
+ "content": [
259
+ {
260
+ "content": [
261
+ {
262
+ "attrs": {
263
+ "id": null,
264
+ },
265
+ "content": [
266
+ {
267
+ "attrs": {
268
+ "id": null,
269
+ "width": 1,
270
+ },
271
+ "content": [
272
+ {
273
+ "attrs": {
274
+ "id": null,
275
+ },
276
+ "content": [
277
+ {
278
+ "attrs": {
279
+ "backgroundColor": "default",
280
+ "textAlignment": "left",
281
+ "textColor": "default",
282
+ },
283
+ "content": [
284
+ {
285
+ "text": "Paragraph 1",
286
+ "type": "text",
287
+ },
288
+ ],
289
+ "type": "paragraph",
290
+ },
291
+ ],
292
+ "type": "blockContainer",
293
+ },
294
+ ],
295
+ "type": "column",
296
+ },
297
+ {
298
+ "attrs": {
299
+ "id": null,
300
+ "width": 1,
301
+ },
302
+ "content": [
303
+ {
304
+ "attrs": {
305
+ "id": null,
306
+ },
307
+ "content": [
308
+ {
309
+ "attrs": {
310
+ "backgroundColor": "default",
311
+ "textAlignment": "left",
312
+ "textColor": "default",
313
+ },
314
+ "content": [
315
+ {
316
+ "text": "Paragraph 2",
317
+ "type": "text",
318
+ },
319
+ ],
320
+ "type": "paragraph",
321
+ },
322
+ ],
323
+ "type": "blockContainer",
324
+ },
325
+ ],
326
+ "type": "column",
327
+ },
328
+ ],
329
+ "type": "columnList",
330
+ },
331
+ ],
332
+ "type": "blockGroup",
333
+ },
334
+ ],
335
+ "type": "doc",
336
+ }
337
+ `;
338
+
339
+ exports[`Test removeEmptyColumns > Two empty columns 1`] = `
340
+ {
341
+ "content": [
342
+ {
343
+ "content": [
344
+ {
345
+ "attrs": {
346
+ "id": null,
347
+ },
348
+ "content": [
349
+ {
350
+ "attrs": {
351
+ "id": null,
352
+ "width": 1,
353
+ },
354
+ "content": [
355
+ {
356
+ "attrs": {
357
+ "id": null,
358
+ },
359
+ "content": [
360
+ {
361
+ "attrs": {
362
+ "backgroundColor": "default",
363
+ "textAlignment": "left",
364
+ "textColor": "default",
365
+ },
366
+ "type": "paragraph",
367
+ },
368
+ ],
369
+ "type": "blockContainer",
370
+ },
371
+ ],
372
+ "type": "column",
373
+ },
374
+ {
375
+ "attrs": {
376
+ "id": null,
377
+ "width": 1,
378
+ },
379
+ "content": [
380
+ {
381
+ "attrs": {
382
+ "id": null,
383
+ },
384
+ "content": [
385
+ {
386
+ "attrs": {
387
+ "backgroundColor": "default",
388
+ "textAlignment": "left",
389
+ "textColor": "default",
390
+ },
391
+ "type": "paragraph",
392
+ },
393
+ ],
394
+ "type": "blockContainer",
395
+ },
396
+ ],
397
+ "type": "column",
398
+ },
399
+ ],
400
+ "type": "columnList",
401
+ },
402
+ ],
403
+ "type": "blockGroup",
404
+ },
405
+ ],
406
+ "type": "doc",
407
+ }
408
+ `;
@@ -0,0 +1,283 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { setupTestEnv } from "../../setupTestEnv.js";
4
+ import {
5
+ fixColumnList,
6
+ isEmptyColumn,
7
+ removeEmptyColumns,
8
+ } from "@blocknote/core";
9
+
10
+ const getEditor = setupTestEnv();
11
+
12
+ describe("Test isEmptyColumn", () => {
13
+ it("Empty blocks", () => {
14
+ const schema = getEditor()._tiptapEditor.schema;
15
+
16
+ const column = schema.nodes["column"].create(undefined, [
17
+ schema.nodes["blockContainer"].create(undefined, [
18
+ schema.nodes["paragraph"].create(),
19
+ ]),
20
+ ]);
21
+
22
+ expect(isEmptyColumn(column)).toBeTruthy();
23
+ });
24
+
25
+ it("Multiple blocks", () => {
26
+ const schema = getEditor()._tiptapEditor.schema;
27
+
28
+ const column = schema.nodes["column"].create(undefined, [
29
+ schema.nodes["blockContainer"].create(undefined, [
30
+ schema.nodes["paragraph"].create(undefined),
31
+ ]),
32
+ schema.nodes["blockContainer"].create(undefined, [
33
+ schema.nodes["paragraph"].create(),
34
+ ]),
35
+ ]);
36
+
37
+ expect(isEmptyColumn(column)).toBeFalsy();
38
+ });
39
+
40
+ it("Block with children", () => {
41
+ const schema = getEditor()._tiptapEditor.schema;
42
+
43
+ const column = schema.nodes["column"].create(undefined, [
44
+ schema.nodes["blockContainer"].create(undefined, [
45
+ schema.nodes["paragraph"].create(undefined),
46
+ schema.nodes["blockGroup"].create(undefined, [
47
+ schema.nodes["blockContainer"].create(undefined, [
48
+ schema.nodes["paragraph"].create(),
49
+ ]),
50
+ ]),
51
+ ]),
52
+ ]);
53
+
54
+ expect(isEmptyColumn(column)).toBeFalsy();
55
+ });
56
+
57
+ it("Block with text", () => {
58
+ const schema = getEditor()._tiptapEditor.schema;
59
+
60
+ const column = schema.nodes["column"].create(undefined, [
61
+ schema.nodes["blockContainer"].create(undefined, [
62
+ schema.nodes["paragraph"].create(undefined, [
63
+ schema.text("Paragraph 1"),
64
+ ]),
65
+ ]),
66
+ ]);
67
+
68
+ expect(isEmptyColumn(column)).toBeFalsy();
69
+ });
70
+
71
+ it("Non-text block", () => {
72
+ const schema = getEditor()._tiptapEditor.schema;
73
+
74
+ const column = schema.nodes["column"].create(undefined, [
75
+ schema.nodes["blockContainer"].create(undefined, [
76
+ schema.nodes["image"].create(),
77
+ ]),
78
+ ]);
79
+
80
+ expect(isEmptyColumn(column)).toBeFalsy();
81
+ });
82
+ });
83
+
84
+ describe("Test removeEmptyColumns", () => {
85
+ it("Start and end columns empty", () => {
86
+ const editor = getEditor();
87
+ const schema = editor._tiptapEditor.schema;
88
+
89
+ const columnList = schema.nodes["columnList"].create(undefined, [
90
+ schema.nodes["column"].create(undefined, [
91
+ schema.nodes["blockContainer"].create(undefined, [
92
+ schema.nodes["paragraph"].create(),
93
+ ]),
94
+ ]),
95
+ schema.nodes["column"].create(undefined, [
96
+ schema.nodes["blockContainer"].create(undefined, [
97
+ schema.nodes["paragraph"].create(undefined, [
98
+ schema.text("Paragraph 1"),
99
+ ]),
100
+ ]),
101
+ ]),
102
+ schema.nodes["column"].create(undefined, [
103
+ schema.nodes["blockContainer"].create(undefined, [
104
+ schema.nodes["paragraph"].create(undefined, [
105
+ schema.text("Paragraph 2"),
106
+ ]),
107
+ ]),
108
+ ]),
109
+ schema.nodes["column"].create(undefined, [
110
+ schema.nodes["blockContainer"].create(undefined, [
111
+ schema.nodes["paragraph"].create(),
112
+ ]),
113
+ ]),
114
+ ]);
115
+
116
+ const tr = editor.prosemirrorState.tr;
117
+
118
+ tr.replaceRangeWith(1, tr.doc.firstChild!.content.size, columnList);
119
+ removeEmptyColumns(tr, 1);
120
+
121
+ expect(tr.doc).toMatchSnapshot();
122
+ });
123
+
124
+ it("First of two columns empty", () => {
125
+ const editor = getEditor();
126
+ const schema = editor._tiptapEditor.schema;
127
+
128
+ const columnList = schema.nodes["columnList"].create(undefined, [
129
+ schema.nodes["column"].create(undefined, [
130
+ schema.nodes["blockContainer"].create(undefined, [
131
+ schema.nodes["paragraph"].create(),
132
+ ]),
133
+ ]),
134
+ schema.nodes["column"].create(undefined, [
135
+ schema.nodes["blockContainer"].create(undefined, [
136
+ schema.nodes["paragraph"].create(undefined, [
137
+ schema.text("Paragraph 1"),
138
+ ]),
139
+ ]),
140
+ ]),
141
+ ]);
142
+
143
+ const tr = editor.prosemirrorState.tr;
144
+
145
+ tr.replaceRangeWith(1, tr.doc.firstChild!.content.size, columnList);
146
+ removeEmptyColumns(tr, 1);
147
+
148
+ expect(tr.doc).toMatchSnapshot();
149
+ });
150
+
151
+ it("Last of two columns empty", () => {
152
+ const editor = getEditor();
153
+ const schema = editor._tiptapEditor.schema;
154
+
155
+ const columnList = schema.nodes["columnList"].create(undefined, [
156
+ schema.nodes["column"].create(undefined, [
157
+ schema.nodes["blockContainer"].create(undefined, [
158
+ schema.nodes["paragraph"].create(undefined, [
159
+ schema.text("Paragraph 1"),
160
+ ]),
161
+ ]),
162
+ ]),
163
+ schema.nodes["column"].create(undefined, [
164
+ schema.nodes["blockContainer"].create(undefined, [
165
+ schema.nodes["paragraph"].create(),
166
+ ]),
167
+ ]),
168
+ ]);
169
+
170
+ const tr = editor.prosemirrorState.tr;
171
+
172
+ tr.replaceRangeWith(1, tr.doc.firstChild!.content.size, columnList);
173
+ removeEmptyColumns(tr, 1);
174
+
175
+ expect(tr.doc).toMatchSnapshot();
176
+ });
177
+
178
+ it("Two empty columns", () => {
179
+ const editor = getEditor();
180
+ const schema = editor._tiptapEditor.schema;
181
+
182
+ const columnList = schema.nodes["columnList"].create(undefined, [
183
+ schema.nodes["column"].create(undefined, [
184
+ schema.nodes["blockContainer"].create(undefined, [
185
+ schema.nodes["paragraph"].create(),
186
+ ]),
187
+ ]),
188
+ schema.nodes["column"].create(undefined, [
189
+ schema.nodes["blockContainer"].create(undefined, [
190
+ schema.nodes["paragraph"].create(),
191
+ ]),
192
+ ]),
193
+ ]);
194
+
195
+ const tr = editor.prosemirrorState.tr;
196
+
197
+ tr.replaceRangeWith(1, tr.doc.firstChild!.content.size, columnList);
198
+ removeEmptyColumns(tr, 1);
199
+
200
+ expect(tr.doc).toMatchSnapshot();
201
+ });
202
+ });
203
+
204
+ describe("Test fixColumnList", () => {
205
+ it("First of two columns empty", () => {
206
+ const editor = getEditor();
207
+ const schema = editor._tiptapEditor.schema;
208
+
209
+ const columnList = schema.nodes["columnList"].create(undefined, [
210
+ schema.nodes["column"].create(undefined, [
211
+ schema.nodes["blockContainer"].create(undefined, [
212
+ schema.nodes["paragraph"].create(),
213
+ ]),
214
+ ]),
215
+ schema.nodes["column"].create(undefined, [
216
+ schema.nodes["blockContainer"].create(undefined, [
217
+ schema.nodes["paragraph"].create(undefined, [
218
+ schema.text("Paragraph 1"),
219
+ ]),
220
+ ]),
221
+ ]),
222
+ ]);
223
+
224
+ const tr = editor.prosemirrorState.tr;
225
+
226
+ tr.replaceRangeWith(1, tr.doc.firstChild!.content.size, columnList);
227
+ fixColumnList(tr, 1);
228
+
229
+ expect(tr.doc).toMatchSnapshot();
230
+ });
231
+
232
+ it("Last of two columns empty", () => {
233
+ const editor = getEditor();
234
+ const schema = editor._tiptapEditor.schema;
235
+
236
+ const columnList = schema.nodes["columnList"].create(undefined, [
237
+ schema.nodes["column"].create(undefined, [
238
+ schema.nodes["blockContainer"].create(undefined, [
239
+ schema.nodes["paragraph"].create(undefined, [
240
+ schema.text("Paragraph 1"),
241
+ ]),
242
+ ]),
243
+ ]),
244
+ schema.nodes["column"].create(undefined, [
245
+ schema.nodes["blockContainer"].create(undefined, [
246
+ schema.nodes["paragraph"].create(),
247
+ ]),
248
+ ]),
249
+ ]);
250
+
251
+ const tr = editor.prosemirrorState.tr;
252
+
253
+ tr.replaceRangeWith(1, tr.doc.firstChild!.content.size, columnList);
254
+ fixColumnList(tr, 1);
255
+
256
+ expect(tr.doc).toMatchSnapshot();
257
+ });
258
+
259
+ it("Two empty columns", () => {
260
+ const editor = getEditor();
261
+ const schema = editor._tiptapEditor.schema;
262
+
263
+ const columnList = schema.nodes["columnList"].create(undefined, [
264
+ schema.nodes["column"].create(undefined, [
265
+ schema.nodes["blockContainer"].create(undefined, [
266
+ schema.nodes["paragraph"].create(),
267
+ ]),
268
+ ]),
269
+ schema.nodes["column"].create(undefined, [
270
+ schema.nodes["blockContainer"].create(undefined, [
271
+ schema.nodes["paragraph"].create(),
272
+ ]),
273
+ ]),
274
+ ]);
275
+
276
+ const tr = editor.prosemirrorState.tr;
277
+
278
+ tr.replaceRangeWith(1, tr.doc.firstChild!.content.size, columnList);
279
+ fixColumnList(tr, 1);
280
+
281
+ expect(tr.doc).toMatchSnapshot();
282
+ });
283
+ });