@blocknote/core 0.47.3 → 0.48.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.
Files changed (121) hide show
  1. package/dist/BlockNoteExtension-B6RhuQ3V.js +27 -0
  2. package/dist/BlockNoteExtension-B6RhuQ3V.js.map +1 -0
  3. package/dist/BlockNoteExtension-ab0REuob.cjs +2 -0
  4. package/dist/BlockNoteExtension-ab0REuob.cjs.map +1 -0
  5. package/dist/EventEmitter-CuPnGDYt.js +22 -0
  6. package/dist/EventEmitter-CuPnGDYt.js.map +1 -0
  7. package/dist/EventEmitter-DHdSnYCD.cjs +2 -0
  8. package/dist/EventEmitter-DHdSnYCD.cjs.map +1 -0
  9. package/dist/ShowSelection-BsHFfdMi.js +29 -0
  10. package/dist/ShowSelection-BsHFfdMi.js.map +1 -0
  11. package/dist/ShowSelection-DhXglbt8.cjs +2 -0
  12. package/dist/ShowSelection-DhXglbt8.cjs.map +1 -0
  13. package/dist/blocknote.cjs +1 -5
  14. package/dist/blocknote.js +7 -4256
  15. package/dist/blocks-BEvIOzln.cjs +11 -0
  16. package/dist/blocks-BEvIOzln.cjs.map +1 -0
  17. package/dist/blocks-DYl7UTS4.js +3313 -0
  18. package/dist/blocks-DYl7UTS4.js.map +1 -0
  19. package/dist/blocks.cjs +1 -2
  20. package/dist/blocks.js +2 -74
  21. package/dist/comments.cjs +2 -2
  22. package/dist/comments.cjs.map +1 -1
  23. package/dist/comments.js +604 -900
  24. package/dist/comments.js.map +1 -1
  25. package/dist/en-C4ykW581.cjs +2 -0
  26. package/dist/en-C4ykW581.cjs.map +1 -0
  27. package/dist/en-QsSI16s5.js +453 -0
  28. package/dist/en-QsSI16s5.js.map +1 -0
  29. package/dist/extensions-3nf9PPhA.js +1495 -0
  30. package/dist/extensions-3nf9PPhA.js.map +1 -0
  31. package/dist/extensions-D9y6evn6.cjs +2 -0
  32. package/dist/extensions-D9y6evn6.cjs.map +1 -0
  33. package/dist/extensions.cjs +1 -2
  34. package/dist/extensions.js +4 -36
  35. package/dist/locales.cjs +2 -2
  36. package/dist/locales.cjs.map +1 -1
  37. package/dist/locales.js +10049 -9111
  38. package/dist/locales.js.map +1 -1
  39. package/dist/src-BKJH7Jla.cjs +5 -0
  40. package/dist/src-BKJH7Jla.cjs.map +1 -0
  41. package/dist/src-Hjv1f5lc.js +2386 -0
  42. package/dist/src-Hjv1f5lc.js.map +1 -0
  43. package/dist/style.css +2 -1
  44. package/dist/webpack-stats.json +1 -1
  45. package/dist/yjs.cjs +2 -2
  46. package/dist/yjs.cjs.map +1 -1
  47. package/dist/yjs.js +20 -38
  48. package/dist/yjs.js.map +1 -1
  49. package/package.json +8 -8
  50. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +15 -1
  51. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +5 -0
  52. package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +1095 -0
  53. package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +661 -0
  54. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +128 -11
  55. package/src/blocks/File/helpers/render/createResizableFileBlockWrapper.ts +17 -23
  56. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +346 -0
  57. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +143 -71
  58. package/src/editor/Block.css +5 -8
  59. package/src/editor/BlockNoteEditor.ts +38 -1
  60. package/src/editor/editor.css +0 -20
  61. package/src/editor/managers/ExtensionManager/extensions.ts +12 -1
  62. package/src/editor/performance.test.ts +134 -0
  63. package/src/extensions/Collaboration/ForkYDoc.test.ts +115 -103
  64. package/src/extensions/Placeholder/Placeholder.ts +1 -1
  65. package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +86 -0
  66. package/src/extensions/PreviousBlockType/PreviousBlockType.ts +33 -49
  67. package/src/extensions/SideMenu/SideMenu.ts +14 -8
  68. package/src/extensions/TableHandles/TableHandles.ts +14 -0
  69. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +57 -17
  70. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +9 -8
  71. package/src/index.ts +1 -1
  72. package/src/schema/blocks/createSpec.ts +6 -2
  73. package/src/schema/inlineContent/types.ts +0 -1
  74. package/src/vite-env.d.ts +6 -0
  75. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +14 -1
  76. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.test.d.ts +1 -0
  77. package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.d.ts +1 -0
  78. package/types/src/editor/BlockNoteEditor.d.ts +13 -0
  79. package/types/src/editor/performance.test.d.ts +1 -0
  80. package/types/src/extensions/PreviousBlockType/PreviousBlockType.test.d.ts +1 -0
  81. package/types/src/extensions/SideMenu/SideMenu.d.ts +6 -0
  82. package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -0
  83. package/dist/BlockNoteExtension-BWw0r8Gy.cjs +0 -2
  84. package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +0 -1
  85. package/dist/BlockNoteExtension-C2X7LW-V.js +0 -25
  86. package/dist/BlockNoteExtension-C2X7LW-V.js.map +0 -1
  87. package/dist/BlockNoteSchema-CCs_V3lo.cjs +0 -2
  88. package/dist/BlockNoteSchema-CCs_V3lo.cjs.map +0 -1
  89. package/dist/BlockNoteSchema-ooiKsd5B.js +0 -270
  90. package/dist/BlockNoteSchema-ooiKsd5B.js.map +0 -1
  91. package/dist/EventEmitter-CLwfmbqG.cjs +0 -2
  92. package/dist/EventEmitter-CLwfmbqG.cjs.map +0 -1
  93. package/dist/EventEmitter-CjSwpTbz.js +0 -27
  94. package/dist/EventEmitter-CjSwpTbz.js.map +0 -1
  95. package/dist/ShowSelection-B0ch3unP.js +0 -51
  96. package/dist/ShowSelection-B0ch3unP.js.map +0 -1
  97. package/dist/ShowSelection-BxnbRvy4.cjs +0 -2
  98. package/dist/ShowSelection-BxnbRvy4.cjs.map +0 -1
  99. package/dist/TrailingNode-GzE59m_7.js +0 -2288
  100. package/dist/TrailingNode-GzE59m_7.js.map +0 -1
  101. package/dist/TrailingNode-n0WdMPUl.cjs +0 -2
  102. package/dist/TrailingNode-n0WdMPUl.cjs.map +0 -1
  103. package/dist/blockToNode-BNoNIXU7.js +0 -1140
  104. package/dist/blockToNode-BNoNIXU7.js.map +0 -1
  105. package/dist/blockToNode-CumVjgem.cjs +0 -7
  106. package/dist/blockToNode-CumVjgem.cjs.map +0 -1
  107. package/dist/blocknote.cjs.map +0 -1
  108. package/dist/blocknote.js.map +0 -1
  109. package/dist/blocks.cjs.map +0 -1
  110. package/dist/blocks.js.map +0 -1
  111. package/dist/defaultBlocks-Dg9kQWXm.cjs +0 -6
  112. package/dist/defaultBlocks-Dg9kQWXm.cjs.map +0 -1
  113. package/dist/defaultBlocks-ZzGbYgQn.js +0 -3284
  114. package/dist/defaultBlocks-ZzGbYgQn.js.map +0 -1
  115. package/dist/en-Cl87Uuyf.cjs +0 -2
  116. package/dist/en-Cl87Uuyf.cjs.map +0 -1
  117. package/dist/en-njEqD7AG.js +0 -408
  118. package/dist/en-njEqD7AG.js.map +0 -1
  119. package/dist/extensions.cjs.map +0 -1
  120. package/dist/extensions.js.map +0 -1
  121. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,661 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { afterAll, beforeAll } from "vitest";
4
+ import { PartialBlock } from "../../../../blocks/defaultBlocks.js";
5
+ import { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
6
+
7
+ /**
8
+ * Custom test setup with a document designed to reproduce nesting/unnesting bugs.
9
+ *
10
+ * BLO-835 / BLO-899: liftListItem produces invalid content when a nested block
11
+ * has siblings after it in the same blockGroup.
12
+ * BLO-953: Backspace at start of indented block with multi-level children
13
+ * causes deeply nested content to be lost.
14
+ * BLO-844 / BLO-847: Deleting parent block then operating on children causes
15
+ * RangeError.
16
+ */
17
+
18
+ function setupNestTestEnv() {
19
+ let editor: BlockNoteEditor;
20
+ const div = document.createElement("div");
21
+
22
+ beforeAll(() => {
23
+ editor = BlockNoteEditor.create();
24
+ editor.mount(div);
25
+ });
26
+
27
+ afterAll(() => {
28
+ editor._tiptapEditor.destroy();
29
+ editor = undefined as any;
30
+ });
31
+
32
+ return (doc: PartialBlock[]) => {
33
+ editor.replaceBlocks(editor.document, doc);
34
+ return editor;
35
+ };
36
+ }
37
+
38
+ const withEditor = setupNestTestEnv();
39
+
40
+ describe("unnestBlock / liftListItem", () => {
41
+ // BLO-835: liftListItem error with siblings after nested children
42
+ // Structure:
43
+ // block1
44
+ // block2 ← unnest this
45
+ // block3
46
+ // block4
47
+ // block5
48
+ //
49
+ // Expected: block2 lifts out, block5 becomes child of block2
50
+ describe("BLO-835: unnest block with siblings after and nested children", () => {
51
+ it("should not throw when unnesting a block that has siblings after it", () => {
52
+ const editor = withEditor([
53
+ {
54
+ id: "block1",
55
+ type: "paragraph",
56
+ content: "Block 1",
57
+ children: [
58
+ {
59
+ id: "block2",
60
+ type: "paragraph",
61
+ content: "Block 2",
62
+ children: [
63
+ {
64
+ id: "block3",
65
+ type: "paragraph",
66
+ content: "Block 3",
67
+ },
68
+ {
69
+ id: "block4",
70
+ type: "paragraph",
71
+ content: "Block 4",
72
+ },
73
+ ],
74
+ },
75
+ {
76
+ id: "block5",
77
+ type: "paragraph",
78
+ content: "Block 5",
79
+ },
80
+ ],
81
+ },
82
+ ]);
83
+
84
+ editor.setTextCursorPosition("block2", "start");
85
+
86
+ expect(() => {
87
+ editor.unnestBlock();
88
+ }).not.toThrow();
89
+
90
+ expect(editor.document).toMatchSnapshot();
91
+ });
92
+
93
+ it("should move siblings after into lifted block's children", () => {
94
+ const editor = withEditor([
95
+ {
96
+ id: "block1",
97
+ type: "paragraph",
98
+ content: "Block 1",
99
+ children: [
100
+ {
101
+ id: "block2",
102
+ type: "paragraph",
103
+ content: "Block 2",
104
+ },
105
+ {
106
+ id: "block5",
107
+ type: "paragraph",
108
+ content: "Block 5",
109
+ },
110
+ ],
111
+ },
112
+ ]);
113
+
114
+ editor.setTextCursorPosition("block2", "start");
115
+
116
+ expect(() => {
117
+ editor.unnestBlock();
118
+ }).not.toThrow();
119
+
120
+ // block2 should now be at root level after block1
121
+ // block5 should be a child of block2
122
+ expect(editor.document).toMatchSnapshot();
123
+ });
124
+
125
+ it("should handle unnesting the first of many siblings", () => {
126
+ const editor = withEditor([
127
+ {
128
+ id: "block1",
129
+ type: "paragraph",
130
+ content: "Block 1",
131
+ children: [
132
+ {
133
+ id: "block2",
134
+ type: "paragraph",
135
+ content: "Block 2",
136
+ },
137
+ {
138
+ id: "block3",
139
+ type: "paragraph",
140
+ content: "Block 3",
141
+ },
142
+ {
143
+ id: "block4",
144
+ type: "paragraph",
145
+ content: "Block 4",
146
+ },
147
+ ],
148
+ },
149
+ ]);
150
+
151
+ editor.setTextCursorPosition("block2", "start");
152
+
153
+ expect(() => {
154
+ editor.unnestBlock();
155
+ }).not.toThrow();
156
+
157
+ // block2 at root, block3 and block4 become children of block2
158
+ expect(editor.document).toMatchSnapshot();
159
+ });
160
+ });
161
+
162
+ // BLO-899: Shift-Tab on second-level nested child (not last) causes error
163
+ // Structure:
164
+ // parent
165
+ // child1
166
+ // grandchild1 ← unnest this
167
+ // grandchild2
168
+ // child2
169
+ // grandchild3
170
+ // grandchild4
171
+ //
172
+ describe("BLO-899: Shift-Tab on second-level nested block", () => {
173
+ it("should not throw when unnesting a deeply nested block with siblings", () => {
174
+ const editor = withEditor([
175
+ {
176
+ id: "parent",
177
+ type: "paragraph",
178
+ content: "Parent",
179
+ children: [
180
+ {
181
+ id: "child1",
182
+ type: "paragraph",
183
+ content: "Child 1",
184
+ children: [
185
+ {
186
+ id: "grandchild1",
187
+ type: "paragraph",
188
+ content: "Grandchild 1",
189
+ },
190
+ {
191
+ id: "grandchild2",
192
+ type: "paragraph",
193
+ content: "Grandchild 2",
194
+ },
195
+ ],
196
+ },
197
+ {
198
+ id: "child2",
199
+ type: "paragraph",
200
+ content: "Child 2",
201
+ children: [
202
+ {
203
+ id: "grandchild3",
204
+ type: "paragraph",
205
+ content: "Grandchild 3",
206
+ },
207
+ {
208
+ id: "grandchild4",
209
+ type: "paragraph",
210
+ content: "Grandchild 4",
211
+ },
212
+ ],
213
+ },
214
+ ],
215
+ },
216
+ ]);
217
+
218
+ editor.setTextCursorPosition("grandchild1", "start");
219
+
220
+ expect(() => {
221
+ editor.unnestBlock();
222
+ }).not.toThrow();
223
+
224
+ // grandchild1 should become a sibling of child1 (at same level)
225
+ // grandchild2 should become a child of grandchild1
226
+ expect(editor.document).toMatchSnapshot();
227
+ });
228
+
229
+ it("should not throw when unnesting the last deeply nested block", () => {
230
+ const editor = withEditor([
231
+ {
232
+ id: "parent",
233
+ type: "paragraph",
234
+ content: "Parent",
235
+ children: [
236
+ {
237
+ id: "child1",
238
+ type: "paragraph",
239
+ content: "Child 1",
240
+ children: [
241
+ {
242
+ id: "grandchild1",
243
+ type: "paragraph",
244
+ content: "Grandchild 1",
245
+ },
246
+ {
247
+ id: "grandchild2",
248
+ type: "paragraph",
249
+ content: "Grandchild 2",
250
+ },
251
+ ],
252
+ },
253
+ ],
254
+ },
255
+ ]);
256
+
257
+ // Unnesting the LAST child should always work (no siblings after)
258
+ editor.setTextCursorPosition("grandchild2", "start");
259
+
260
+ expect(() => {
261
+ editor.unnestBlock();
262
+ }).not.toThrow();
263
+
264
+ expect(editor.document).toMatchSnapshot();
265
+ });
266
+ });
267
+
268
+ // BLO-953: Backspace at start of indented block loses deeply nested content
269
+ // Structure:
270
+ // block1
271
+ // blockA "text A" ← Backspace at start (unnest via keyboard)
272
+ // block3
273
+ // block4
274
+ // block5
275
+ //
276
+ // Expected: blockA moves to root, all children preserved
277
+ describe("BLO-953: unnest block with multi-level nested children", () => {
278
+ it("should preserve all deeply nested content when unnesting", () => {
279
+ const editor = withEditor([
280
+ {
281
+ id: "block1",
282
+ type: "paragraph",
283
+ content: "Block 1",
284
+ children: [
285
+ {
286
+ id: "blockA",
287
+ type: "paragraph",
288
+ content: "Block A",
289
+ children: [
290
+ {
291
+ id: "block3",
292
+ type: "paragraph",
293
+ content: "Block 3",
294
+ children: [
295
+ {
296
+ id: "block4",
297
+ type: "paragraph",
298
+ content: "Block 4",
299
+ },
300
+ ],
301
+ },
302
+ {
303
+ id: "block5",
304
+ type: "paragraph",
305
+ content: "Block 5",
306
+ },
307
+ ],
308
+ },
309
+ ],
310
+ },
311
+ ]);
312
+
313
+ editor.setTextCursorPosition("blockA", "start");
314
+
315
+ expect(() => {
316
+ editor.unnestBlock();
317
+ }).not.toThrow();
318
+
319
+ const doc = editor.document;
320
+
321
+ // All blocks should still exist in the document
322
+ const allBlockIds = flattenBlockIds(doc);
323
+ expect(allBlockIds).toContain("block1");
324
+ expect(allBlockIds).toContain("blockA");
325
+ expect(allBlockIds).toContain("block3");
326
+ expect(allBlockIds).toContain("block4");
327
+ expect(allBlockIds).toContain("block5");
328
+
329
+ expect(doc).toMatchSnapshot();
330
+ });
331
+
332
+ it("should preserve content when unnesting only child", () => {
333
+ const editor = withEditor([
334
+ {
335
+ id: "block1",
336
+ type: "paragraph",
337
+ content: "Block 1",
338
+ children: [
339
+ {
340
+ id: "blockA",
341
+ type: "paragraph",
342
+ content: "Block A",
343
+ children: [
344
+ {
345
+ id: "block3",
346
+ type: "paragraph",
347
+ content: "Block 3",
348
+ children: [
349
+ {
350
+ id: "block4",
351
+ type: "paragraph",
352
+ content: "Block 4",
353
+ },
354
+ ],
355
+ },
356
+ ],
357
+ },
358
+ ],
359
+ },
360
+ ]);
361
+
362
+ editor.setTextCursorPosition("blockA", "start");
363
+
364
+ expect(() => {
365
+ editor.unnestBlock();
366
+ }).not.toThrow();
367
+
368
+ const doc = editor.document;
369
+ const allBlockIds = flattenBlockIds(doc);
370
+ expect(allBlockIds).toContain("block1");
371
+ expect(allBlockIds).toContain("blockA");
372
+ expect(allBlockIds).toContain("block3");
373
+ expect(allBlockIds).toContain("block4");
374
+
375
+ expect(doc).toMatchSnapshot();
376
+ });
377
+ });
378
+
379
+ // BLO-844 / BLO-847: Operations after deleting parent cause RangeError
380
+ // These bugs manifest when backspace merges/deletes a parent block and
381
+ // then further operations on the (now re-parented) children fail.
382
+ //
383
+ // The core issue is liftListItem failing when the children need to be
384
+ // reorganized. Testing the unnest operation directly.
385
+ describe("BLO-844/847: unnest with complex nesting after parent operations", () => {
386
+ it("should handle unnesting when block is only child", () => {
387
+ const editor = withEditor([
388
+ {
389
+ id: "parent",
390
+ type: "paragraph",
391
+ content: "Parent",
392
+ children: [
393
+ {
394
+ id: "child",
395
+ type: "paragraph",
396
+ content: "Child",
397
+ },
398
+ ],
399
+ },
400
+ ]);
401
+
402
+ editor.setTextCursorPosition("child", "start");
403
+
404
+ expect(() => {
405
+ editor.unnestBlock();
406
+ }).not.toThrow();
407
+
408
+ expect(editor.document).toMatchSnapshot();
409
+ });
410
+
411
+ it("should handle sequential unnest operations", () => {
412
+ const editor = withEditor([
413
+ {
414
+ id: "block1",
415
+ type: "paragraph",
416
+ content: "Block 1",
417
+ children: [
418
+ {
419
+ id: "block2",
420
+ type: "paragraph",
421
+ content: "Block 2",
422
+ children: [
423
+ {
424
+ id: "block3",
425
+ type: "paragraph",
426
+ content: "Block 3",
427
+ },
428
+ ],
429
+ },
430
+ {
431
+ id: "block4",
432
+ type: "paragraph",
433
+ content: "Block 4",
434
+ },
435
+ ],
436
+ },
437
+ ]);
438
+
439
+ // First unnest block2
440
+ editor.setTextCursorPosition("block2", "start");
441
+ expect(() => {
442
+ editor.unnestBlock();
443
+ }).not.toThrow();
444
+
445
+ // Then unnest block3 (which should now be child of block2)
446
+ editor.setTextCursorPosition("block3", "start");
447
+ expect(() => {
448
+ editor.unnestBlock();
449
+ }).not.toThrow();
450
+
451
+ expect(editor.document).toMatchSnapshot();
452
+ });
453
+ });
454
+
455
+ // Additional edge cases
456
+ describe("Edge cases", () => {
457
+ it("should not unnest a root-level block", () => {
458
+ const editor = withEditor([
459
+ {
460
+ id: "root-block",
461
+ type: "paragraph",
462
+ content: "Root Block",
463
+ },
464
+ ]);
465
+
466
+ editor.setTextCursorPosition("root-block", "start");
467
+
468
+ // Should be a no-op (can't unnest root level)
469
+ const canUnnest = editor.canUnnestBlock();
470
+ expect(canUnnest).toBe(false);
471
+ });
472
+
473
+ it("should handle unnesting block with both existing children and siblings after", () => {
474
+ const editor = withEditor([
475
+ {
476
+ id: "parent",
477
+ type: "paragraph",
478
+ content: "Parent",
479
+ children: [
480
+ {
481
+ id: "child1",
482
+ type: "paragraph",
483
+ content: "Child 1",
484
+ children: [
485
+ {
486
+ id: "existing-grandchild",
487
+ type: "paragraph",
488
+ content: "Existing Grandchild",
489
+ },
490
+ ],
491
+ },
492
+ {
493
+ id: "child2",
494
+ type: "paragraph",
495
+ content: "Child 2",
496
+ },
497
+ {
498
+ id: "child3",
499
+ type: "paragraph",
500
+ content: "Child 3",
501
+ },
502
+ ],
503
+ },
504
+ ]);
505
+
506
+ editor.setTextCursorPosition("child1", "start");
507
+
508
+ expect(() => {
509
+ editor.unnestBlock();
510
+ }).not.toThrow();
511
+
512
+ // child1 should be at root level
513
+ // existing-grandchild should still be a child of child1
514
+ // child2 and child3 should also become children of child1
515
+ const doc = editor.document;
516
+ const allBlockIds = flattenBlockIds(doc);
517
+ expect(allBlockIds).toContain("parent");
518
+ expect(allBlockIds).toContain("child1");
519
+ expect(allBlockIds).toContain("existing-grandchild");
520
+ expect(allBlockIds).toContain("child2");
521
+ expect(allBlockIds).toContain("child3");
522
+
523
+ expect(doc).toMatchSnapshot();
524
+ });
525
+
526
+ it("should handle unnesting with different block types", () => {
527
+ const editor = withEditor([
528
+ {
529
+ id: "parent",
530
+ type: "paragraph",
531
+ content: "Parent",
532
+ children: [
533
+ {
534
+ id: "heading-child",
535
+ type: "heading",
536
+ content: "Heading Child",
537
+ },
538
+ {
539
+ id: "para-sibling",
540
+ type: "paragraph",
541
+ content: "Paragraph Sibling",
542
+ },
543
+ ],
544
+ },
545
+ ]);
546
+
547
+ editor.setTextCursorPosition("heading-child", "start");
548
+
549
+ expect(() => {
550
+ editor.unnestBlock();
551
+ }).not.toThrow();
552
+
553
+ expect(editor.document).toMatchSnapshot();
554
+ });
555
+ });
556
+
557
+ // nestBlock tests (sinkListItem) - ensuring nesting works correctly
558
+ describe("nestBlock", () => {
559
+ it("should nest a block under its previous sibling", () => {
560
+ const editor = withEditor([
561
+ {
562
+ id: "block1",
563
+ type: "paragraph",
564
+ content: "Block 1",
565
+ },
566
+ {
567
+ id: "block2",
568
+ type: "paragraph",
569
+ content: "Block 2",
570
+ },
571
+ ]);
572
+
573
+ editor.setTextCursorPosition("block2", "start");
574
+ editor.nestBlock();
575
+
576
+ expect(editor.document).toMatchSnapshot();
577
+ });
578
+
579
+ it("should not nest the first block (no previous sibling)", () => {
580
+ const editor = withEditor([
581
+ {
582
+ id: "block1",
583
+ type: "paragraph",
584
+ content: "Block 1",
585
+ },
586
+ ]);
587
+
588
+ editor.setTextCursorPosition("block1", "start");
589
+
590
+ const canNest = editor.canNestBlock();
591
+ expect(canNest).toBe(false);
592
+ });
593
+
594
+ it("should nest into a sibling that already has children (nestedBefore)", () => {
595
+ const editor = withEditor([
596
+ {
597
+ id: "block1",
598
+ type: "paragraph",
599
+ content: "Block 1",
600
+ children: [
601
+ {
602
+ id: "child1",
603
+ type: "paragraph",
604
+ content: "Child 1",
605
+ },
606
+ ],
607
+ },
608
+ {
609
+ id: "block2",
610
+ type: "paragraph",
611
+ content: "Block 2",
612
+ },
613
+ ]);
614
+
615
+ editor.setTextCursorPosition("block2", "start");
616
+ editor.nestBlock();
617
+
618
+ expect(editor.document).toMatchSnapshot();
619
+ });
620
+
621
+ it("nest then unnest should be a round trip", () => {
622
+ const editor = withEditor([
623
+ {
624
+ id: "block1",
625
+ type: "paragraph",
626
+ content: "Block 1",
627
+ },
628
+ {
629
+ id: "block2",
630
+ type: "paragraph",
631
+ content: "Block 2",
632
+ },
633
+ ]);
634
+
635
+ const originalDoc = JSON.parse(JSON.stringify(editor.document));
636
+
637
+ editor.setTextCursorPosition("block2", "start");
638
+ editor.nestBlock();
639
+ editor.unnestBlock();
640
+
641
+ // Content should be preserved (IDs may differ but structure/content same)
642
+ expect(editor.document.length).toBe(originalDoc.length);
643
+ expect(editor.document[0].content).toEqual(originalDoc[0].content);
644
+ expect(editor.document[1].content).toEqual(originalDoc[1].content);
645
+ });
646
+ });
647
+ });
648
+
649
+ /** Recursively collects all block IDs from a document */
650
+ function flattenBlockIds(blocks: any[]): string[] {
651
+ const ids: string[] = [];
652
+ for (const block of blocks) {
653
+ if (block.id) {
654
+ ids.push(block.id);
655
+ }
656
+ if (block.children) {
657
+ ids.push(...flattenBlockIds(block.children));
658
+ }
659
+ }
660
+ return ids;
661
+ }