@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
@@ -20,38 +20,42 @@ it("can fork a document", async () => {
20
20
  },
21
21
  });
22
22
 
23
- const div = document.createElement("div");
24
- editor.mount(div);
25
-
26
- editor.replaceBlocks(editor.document, [
27
- {
28
- type: "paragraph",
29
- content: [{ text: "Hello", styles: {}, type: "text" }],
30
- },
31
- ]);
23
+ try {
24
+ const div = document.createElement("div");
25
+ editor.mount(div);
26
+
27
+ editor.replaceBlocks(editor.document, [
28
+ {
29
+ type: "paragraph",
30
+ content: [{ text: "Hello", styles: {}, type: "text" }],
31
+ },
32
+ ]);
32
33
 
33
- await expect(fragment.toJSON()).toMatchFileSnapshot(
34
- "__snapshots__/fork-yjs-snap.html",
35
- );
36
- await expect(editor.document).toMatchFileSnapshot(
37
- "__snapshots__/fork-yjs-snap-editor.json",
38
- );
34
+ await expect(fragment.toJSON()).toMatchFileSnapshot(
35
+ "__snapshots__/fork-yjs-snap.html",
36
+ );
37
+ await expect(editor.document).toMatchFileSnapshot(
38
+ "__snapshots__/fork-yjs-snap-editor.json",
39
+ );
39
40
 
40
- editor.getExtension(ForkYDocExtension)!.fork();
41
+ editor.getExtension(ForkYDocExtension)!.fork();
41
42
 
42
- editor.replaceBlocks(editor.document, [
43
- {
44
- type: "paragraph",
45
- content: [{ text: "Hello World", styles: {}, type: "text" }],
46
- },
47
- ]);
48
-
49
- await expect(fragment.toJSON()).toMatchFileSnapshot(
50
- "__snapshots__/fork-yjs-snap.html",
51
- );
52
- await expect(editor.document).toMatchFileSnapshot(
53
- "__snapshots__/fork-yjs-snap-editor-forked.json",
54
- );
43
+ editor.replaceBlocks(editor.document, [
44
+ {
45
+ type: "paragraph",
46
+ content: [{ text: "Hello World", styles: {}, type: "text" }],
47
+ },
48
+ ]);
49
+
50
+ await expect(fragment.toJSON()).toMatchFileSnapshot(
51
+ "__snapshots__/fork-yjs-snap.html",
52
+ );
53
+ await expect(editor.document).toMatchFileSnapshot(
54
+ "__snapshots__/fork-yjs-snap-editor-forked.json",
55
+ );
56
+ } finally {
57
+ editor.unmount();
58
+ }
55
59
  });
56
60
 
57
61
  it("can merge a document", async () => {
@@ -67,47 +71,51 @@ it("can merge a document", async () => {
67
71
  },
68
72
  });
69
73
 
70
- const div = document.createElement("div");
71
- editor.mount(div);
74
+ try {
75
+ const div = document.createElement("div");
76
+ editor.mount(div);
72
77
 
73
- editor.replaceBlocks(editor.document, [
74
- {
75
- type: "paragraph",
76
- content: [{ text: "Hello", styles: {}, type: "text" }],
77
- },
78
- ]);
78
+ editor.replaceBlocks(editor.document, [
79
+ {
80
+ type: "paragraph",
81
+ content: [{ text: "Hello", styles: {}, type: "text" }],
82
+ },
83
+ ]);
79
84
 
80
- await expect(fragment.toJSON()).toMatchFileSnapshot(
81
- "__snapshots__/fork-yjs-snap.html",
82
- );
83
- await expect(editor.document).toMatchFileSnapshot(
84
- "__snapshots__/fork-yjs-snap-editor.json",
85
- );
85
+ await expect(fragment.toJSON()).toMatchFileSnapshot(
86
+ "__snapshots__/fork-yjs-snap.html",
87
+ );
88
+ await expect(editor.document).toMatchFileSnapshot(
89
+ "__snapshots__/fork-yjs-snap-editor.json",
90
+ );
86
91
 
87
- editor.getExtension(ForkYDocExtension)!.fork();
92
+ editor.getExtension(ForkYDocExtension)!.fork();
88
93
 
89
- editor.replaceBlocks(editor.document, [
90
- {
91
- type: "paragraph",
92
- content: [{ text: "Hello World", styles: {}, type: "text" }],
93
- },
94
- ]);
95
-
96
- await expect(fragment.toJSON()).toMatchFileSnapshot(
97
- "__snapshots__/fork-yjs-snap.html",
98
- );
99
- await expect(editor.document).toMatchFileSnapshot(
100
- "__snapshots__/fork-yjs-snap-editor-forked.json",
101
- );
102
-
103
- editor.getExtension(ForkYDocExtension)!.merge({ keepChanges: false });
104
-
105
- await expect(fragment.toJSON()).toMatchFileSnapshot(
106
- "__snapshots__/fork-yjs-snap.html",
107
- );
108
- await expect(editor.document).toMatchFileSnapshot(
109
- "__snapshots__/fork-yjs-snap-editor.json",
110
- );
94
+ editor.replaceBlocks(editor.document, [
95
+ {
96
+ type: "paragraph",
97
+ content: [{ text: "Hello World", styles: {}, type: "text" }],
98
+ },
99
+ ]);
100
+
101
+ await expect(fragment.toJSON()).toMatchFileSnapshot(
102
+ "__snapshots__/fork-yjs-snap.html",
103
+ );
104
+ await expect(editor.document).toMatchFileSnapshot(
105
+ "__snapshots__/fork-yjs-snap-editor-forked.json",
106
+ );
107
+
108
+ editor.getExtension(ForkYDocExtension)!.merge({ keepChanges: false });
109
+
110
+ await expect(fragment.toJSON()).toMatchFileSnapshot(
111
+ "__snapshots__/fork-yjs-snap.html",
112
+ );
113
+ await expect(editor.document).toMatchFileSnapshot(
114
+ "__snapshots__/fork-yjs-snap-editor.json",
115
+ );
116
+ } finally {
117
+ editor.unmount();
118
+ }
111
119
  });
112
120
 
113
121
  it("can fork an keep the changes to the original document", async () => {
@@ -123,45 +131,49 @@ it("can fork an keep the changes to the original document", async () => {
123
131
  },
124
132
  });
125
133
 
126
- const div = document.createElement("div");
127
- editor.mount(div);
134
+ try {
135
+ const div = document.createElement("div");
136
+ editor.mount(div);
128
137
 
129
- editor.replaceBlocks(editor.document, [
130
- {
131
- type: "paragraph",
132
- content: [{ text: "Hello", styles: {}, type: "text" }],
133
- },
134
- ]);
138
+ editor.replaceBlocks(editor.document, [
139
+ {
140
+ type: "paragraph",
141
+ content: [{ text: "Hello", styles: {}, type: "text" }],
142
+ },
143
+ ]);
135
144
 
136
- await expect(fragment.toJSON()).toMatchFileSnapshot(
137
- "__snapshots__/fork-yjs-snap.html",
138
- );
139
- await expect(editor.document).toMatchFileSnapshot(
140
- "__snapshots__/fork-yjs-snap-editor.json",
141
- );
145
+ await expect(fragment.toJSON()).toMatchFileSnapshot(
146
+ "__snapshots__/fork-yjs-snap.html",
147
+ );
148
+ await expect(editor.document).toMatchFileSnapshot(
149
+ "__snapshots__/fork-yjs-snap-editor.json",
150
+ );
142
151
 
143
- editor.getExtension(ForkYDocExtension)!.fork();
152
+ editor.getExtension(ForkYDocExtension)!.fork();
144
153
 
145
- editor.replaceBlocks(editor.document, [
146
- {
147
- type: "paragraph",
148
- content: [{ text: "Hello World", styles: {}, type: "text" }],
149
- },
150
- ]);
151
-
152
- await expect(fragment.toJSON()).toMatchFileSnapshot(
153
- "__snapshots__/fork-yjs-snap.html",
154
- );
155
- await expect(editor.document).toMatchFileSnapshot(
156
- "__snapshots__/fork-yjs-snap-editor-forked.json",
157
- );
158
-
159
- editor.getExtension(ForkYDocExtension)!.merge({ keepChanges: true });
160
-
161
- await expect(fragment.toJSON()).toMatchFileSnapshot(
162
- "__snapshots__/fork-yjs-snap-forked.html",
163
- );
164
- await expect(editor.document).toMatchFileSnapshot(
165
- "__snapshots__/fork-yjs-snap-editor-forked.json",
166
- );
154
+ editor.replaceBlocks(editor.document, [
155
+ {
156
+ type: "paragraph",
157
+ content: [{ text: "Hello World", styles: {}, type: "text" }],
158
+ },
159
+ ]);
160
+
161
+ await expect(fragment.toJSON()).toMatchFileSnapshot(
162
+ "__snapshots__/fork-yjs-snap.html",
163
+ );
164
+ await expect(editor.document).toMatchFileSnapshot(
165
+ "__snapshots__/fork-yjs-snap-editor-forked.json",
166
+ );
167
+
168
+ editor.getExtension(ForkYDocExtension)!.merge({ keepChanges: true });
169
+
170
+ await expect(fragment.toJSON()).toMatchFileSnapshot(
171
+ "__snapshots__/fork-yjs-snap-forked.html",
172
+ );
173
+ await expect(editor.document).toMatchFileSnapshot(
174
+ "__snapshots__/fork-yjs-snap-editor-forked.json",
175
+ );
176
+ } finally {
177
+ editor.unmount();
178
+ }
167
179
  });
@@ -41,7 +41,7 @@ export const PlaceholderExtension = createExtension(
41
41
  const styleSheet = styleEl.sheet!;
42
42
 
43
43
  const getSelector = (additionalSelectors = "") =>
44
- `.${uniqueEditorSelector} .bn-block-content${additionalSelectors} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before`;
44
+ `.${uniqueEditorSelector} .bn-block-content${additionalSelectors}:has(.ProseMirror-trailingBreak:only-child):after`;
45
45
 
46
46
  try {
47
47
  // FIXME: the names "default" and "emptyDocument" are hardcoded
@@ -0,0 +1,86 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
4
+
5
+ /**
6
+ * @vitest-environment jsdom
7
+ */
8
+
9
+ function createEditorWithBlocks(
10
+ blockCount: number,
11
+ blockType: "heading" | "paragraph" = "heading",
12
+ ) {
13
+ const editor = BlockNoteEditor.create();
14
+ editor.mount(document.createElement("div"));
15
+ const blocks = [];
16
+ for (let i = 0; i < blockCount; i++) {
17
+ blocks.push({
18
+ type: blockType as any,
19
+ content: `Block number ${i} with some text to simulate a real document`,
20
+ ...(blockType === "heading" ? { props: { level: 1 } } : {}),
21
+ });
22
+ }
23
+ editor.replaceBlocks(editor.document, blocks as any);
24
+ return editor;
25
+ }
26
+
27
+ function getPreviousBlockTypePluginState(
28
+ editor: BlockNoteEditor<any, any, any>,
29
+ ) {
30
+ const view = editor._tiptapEditor.view;
31
+ const plugin = view.state.plugins.find((p) => {
32
+ const key = (p.spec as any)?.key;
33
+ return key && typeof key === "object" && key.key === "previous-blocks$";
34
+ });
35
+ if (!plugin) {
36
+ throw new Error("PreviousBlockType plugin not found");
37
+ }
38
+ return plugin.getState(view.state) as {
39
+ updatedBlocks: Set<string>;
40
+ currentTransactionOldBlockAttrs: Record<string, any>;
41
+ prevTransactionOldBlockAttrs: Record<string, any>;
42
+ };
43
+ }
44
+
45
+ describe("PreviousBlockType: scoped traversal", () => {
46
+ it("only tracks blocks in the changed range, not the entire document", () => {
47
+ const editor = createEditorWithBlocks(500, "heading");
48
+ const view = editor._tiptapEditor.view;
49
+
50
+ // Insert a character — block attributes (type, level, depth) don't change
51
+ const pos = view.state.doc.content.size - 4;
52
+ view.dispatch(view.state.tr.insertText("x", pos));
53
+
54
+ const state = getPreviousBlockTypePluginState(editor);
55
+
56
+ // No blocks should be marked as updated since typing doesn't change attrs
57
+ expect(state.updatedBlocks.size).toBe(0);
58
+
59
+ // The plugin should only have tracked the block(s) in the changed range,
60
+ // not all 500 blocks. Before the fix this was 500; after, typically 1-3.
61
+ const trackedBlockCount = Object.keys(
62
+ state.currentTransactionOldBlockAttrs,
63
+ ).length;
64
+ expect(trackedBlockCount).toBeLessThan(10);
65
+ });
66
+
67
+ it("correctly detects attribute changes only for affected blocks", () => {
68
+ const editor = createEditorWithBlocks(100, "heading");
69
+
70
+ // Change the first block's type from heading to paragraph
71
+ const firstBlock = editor.document[0];
72
+ editor.updateBlock(firstBlock, { type: "paragraph" });
73
+
74
+ const state = getPreviousBlockTypePluginState(editor);
75
+
76
+ // Only the first block should be marked as updated
77
+ expect(state.updatedBlocks.size).toBe(1);
78
+ expect(state.updatedBlocks.has(firstBlock.id)).toBe(true);
79
+
80
+ // Only a small number of blocks tracked (the changed range)
81
+ const trackedBlockCount = Object.keys(
82
+ state.currentTransactionOldBlockAttrs,
83
+ ).length;
84
+ expect(trackedBlockCount).toBeLessThan(10);
85
+ });
86
+ });
@@ -1,4 +1,4 @@
1
- import { findChildren } from "@tiptap/core";
1
+ import { findChildrenInRange } from "@tiptap/core";
2
2
  import { Plugin, PluginKey } from "prosemirror-state";
3
3
  import { Decoration, DecorationSet } from "prosemirror-view";
4
4
  import { createExtension } from "../../editor/BlockNoteExtension.js";
@@ -67,45 +67,40 @@ export const PreviousBlockTypeExtension = createExtension(() => {
67
67
  prev.currentTransactionOldBlockAttrs = {};
68
68
  prev.updatedBlocks.clear();
69
69
 
70
- if (!transaction.docChanged || oldState.doc.eq(newState.doc)) {
70
+ if (!transaction.docChanged) {
71
71
  return prev;
72
72
  }
73
73
 
74
- // TODO: Instead of iterating through the entire document, only check nodes affected by the transactions. Will
75
- // also probably require checking nodes affected by the previous transaction too.
76
- // We didn't get this to work yet:
77
- // const transform = combineTransactionSteps(oldState.doc, [transaction]);
78
- // // const { mapping } = transform;
79
- // const changes = getChangedRanges(transform);
80
- //
81
- // changes.forEach(({ oldRange, newRange }) => {
82
- // const oldNodes = findChildrenInRange(
83
- // oldState.doc,
84
- // oldRange,
85
- // (node) => node.attrs.id
86
- // );
87
- //
88
- // const newNodes = findChildrenInRange(
89
- // newState.doc,
90
- // newRange,
91
- // (node) => node.attrs.id
92
- // );
74
+ // Only check nodes affected by the transaction, not the entire document.
75
+ // changedRange() is O(steps) unlike tiptap's getChangedRanges which is O(steps²).
76
+ const newRange = transaction.changedRange();
77
+ if (!newRange) {
78
+ return prev;
79
+ }
80
+
81
+ // Map the new-doc range back to old-doc coordinates
82
+ const invertedMapping = transaction.mapping.invert();
83
+ const oldRange = {
84
+ from: invertedMapping.map(newRange.from, -1),
85
+ to: invertedMapping.map(newRange.to, 1),
86
+ };
93
87
 
94
88
  const currentTransactionOriginalOldBlockAttrs = {} as any;
95
89
 
96
- const oldNodes = findChildren(
90
+ const oldNodes = findChildrenInRange(
97
91
  oldState.doc,
92
+ oldRange,
98
93
  (node) => node.attrs.id,
99
94
  );
100
95
  const oldNodesById = new Map(
101
96
  oldNodes.map((node) => [node.node.attrs.id, node]),
102
97
  );
103
- const newNodes = findChildren(
98
+ const newNodes = findChildrenInRange(
104
99
  newState.doc,
100
+ newRange,
105
101
  (node) => node.attrs.id,
106
102
  );
107
103
 
108
- // Traverses all block containers in the new editor state.
109
104
  for (const node of newNodes) {
110
105
  const oldNode = oldNodesById.get(node.node.attrs.id);
111
106
 
@@ -127,27 +122,22 @@ export const PreviousBlockTypeExtension = createExtension(() => {
127
122
  depth: oldState.doc.resolve(oldNode.pos).depth,
128
123
  };
129
124
 
130
- currentTransactionOriginalOldBlockAttrs[node.node.attrs.id] =
131
- oldAttrs;
125
+ currentTransactionOriginalOldBlockAttrs[
126
+ node.node.attrs.id
127
+ ] = oldAttrs;
132
128
 
133
129
  prev.currentTransactionOldBlockAttrs[node.node.attrs.id] =
134
130
  oldAttrs;
135
131
 
136
- // TODO: faster deep equal?
137
- if (JSON.stringify(oldAttrs) !== JSON.stringify(newAttrs)) {
132
+ if (
133
+ oldAttrs.index !== newAttrs.index ||
134
+ oldAttrs.level !== newAttrs.level ||
135
+ oldAttrs.type !== newAttrs.type ||
136
+ oldAttrs.depth !== newAttrs.depth
137
+ ) {
138
138
  (oldAttrs as any)["depth-change"] =
139
139
  oldAttrs.depth - newAttrs.depth;
140
140
 
141
- // for debugging:
142
- // console.log(
143
- // "id:",
144
- // node.node.attrs.id,
145
- // "previousBlockTypePlugin changes detected, oldAttrs",
146
- // oldAttrs,
147
- // "new",
148
- // newAttrs
149
- // );
150
-
151
141
  prev.updatedBlocks.add(node.node.attrs.id);
152
142
  }
153
143
  }
@@ -186,17 +176,11 @@ export const PreviousBlockTypeExtension = createExtension(() => {
186
176
  val || "none";
187
177
  }
188
178
 
189
- // for debugging:
190
- // console.log(
191
- // "previousBlockTypePlugin committing decorations",
192
- // decorationAttrs
193
- // );
194
-
195
- const decoration = Decoration.node(pos, pos + node.nodeSize, {
196
- ...decorationAttrs,
197
- });
198
-
199
- decorations.push(decoration);
179
+ decorations.push(
180
+ Decoration.node(pos, pos + node.nodeSize, {
181
+ ...decorationAttrs,
182
+ }),
183
+ );
200
184
  });
201
185
 
202
186
  return DecorationSet.create(state.doc, decorations);
@@ -612,9 +612,6 @@ export class SideMenuView<
612
612
  this.mousePos.y > editorOuterBoundingBox.top &&
613
613
  this.mousePos.y < editorOuterBoundingBox.bottom;
614
614
 
615
- // TODO: remove parentElement, but then we need to remove padding from boundingbox or find a different solution
616
- const editorWrapper = this.pmView.dom!.parentElement!;
617
-
618
615
  // Doesn't update if the mouse hovers an element that's over the editor but
619
616
  // isn't a part of it or the side menu.
620
617
  if (
@@ -623,11 +620,8 @@ export class SideMenuView<
623
620
  // An element is hovered
624
621
  event &&
625
622
  event.target &&
626
- // Element is outside the editor
627
- !(
628
- editorWrapper === event.target ||
629
- editorWrapper.contains(event.target as HTMLElement)
630
- )
623
+ // Element is outside this editor and its portaled UI
624
+ !this.editor.isWithinEditor(event.target as HTMLElement)
631
625
  ) {
632
626
  if (this.state?.show) {
633
627
  this.state.show = false;
@@ -784,5 +778,17 @@ export const SideMenuExtension = createExtension(({ editor }) => {
784
778
  view!.state!.show = false;
785
779
  view!.emitUpdate(view!.state!);
786
780
  },
781
+
782
+ /**
783
+ * Hides the side menu unless it is currently frozen (e.g. the drag
784
+ * handle menu is open). Used to dismiss the menu on scroll without
785
+ * interfering with open submenus.
786
+ */
787
+ hideMenuIfNotFrozen() {
788
+ if (!view!.menuFrozen && view!.state!.show) {
789
+ view!.state!.show = false;
790
+ view!.emitUpdate(view!.state!);
791
+ }
792
+ },
787
793
  } as const;
788
794
  });
@@ -908,6 +908,20 @@ export const TableHandlesExtension = createExtension(({ editor }) => {
908
908
  view!.menuFrozen = false;
909
909
  },
910
910
 
911
+ /**
912
+ * Hides the table handles unless they are currently frozen (e.g. a
913
+ * handle menu is open). Used to dismiss the handles on scroll without
914
+ * interfering with open submenus.
915
+ */
916
+ hideHandlesIfNotFrozen() {
917
+ if (!view!.menuFrozen && view!.state?.show) {
918
+ view!.state.show = false;
919
+ view!.state.showAddOrRemoveRowsButton = false;
920
+ view!.state.showAddOrRemoveColumnsButton = false;
921
+ view!.emitUpdate();
922
+ }
923
+ },
924
+
911
925
  getCellsAtRowHandle(
912
926
  block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], any, any>,
913
927
  relativeRowIndex: RelativeCellIndices["row"],