@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.
- package/dist/BlockNoteExtension-B6RhuQ3V.js +27 -0
- package/dist/BlockNoteExtension-B6RhuQ3V.js.map +1 -0
- package/dist/BlockNoteExtension-ab0REuob.cjs +2 -0
- package/dist/BlockNoteExtension-ab0REuob.cjs.map +1 -0
- package/dist/EventEmitter-CuPnGDYt.js +22 -0
- package/dist/EventEmitter-CuPnGDYt.js.map +1 -0
- package/dist/EventEmitter-DHdSnYCD.cjs +2 -0
- package/dist/EventEmitter-DHdSnYCD.cjs.map +1 -0
- package/dist/ShowSelection-BsHFfdMi.js +29 -0
- package/dist/ShowSelection-BsHFfdMi.js.map +1 -0
- package/dist/ShowSelection-DhXglbt8.cjs +2 -0
- package/dist/ShowSelection-DhXglbt8.cjs.map +1 -0
- package/dist/blocknote.cjs +1 -5
- package/dist/blocknote.js +7 -4256
- package/dist/blocks-BEvIOzln.cjs +11 -0
- package/dist/blocks-BEvIOzln.cjs.map +1 -0
- package/dist/blocks-DYl7UTS4.js +3313 -0
- package/dist/blocks-DYl7UTS4.js.map +1 -0
- package/dist/blocks.cjs +1 -2
- package/dist/blocks.js +2 -74
- package/dist/comments.cjs +2 -2
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +604 -900
- package/dist/comments.js.map +1 -1
- package/dist/en-C4ykW581.cjs +2 -0
- package/dist/en-C4ykW581.cjs.map +1 -0
- package/dist/en-QsSI16s5.js +453 -0
- package/dist/en-QsSI16s5.js.map +1 -0
- package/dist/extensions-3nf9PPhA.js +1495 -0
- package/dist/extensions-3nf9PPhA.js.map +1 -0
- package/dist/extensions-D9y6evn6.cjs +2 -0
- package/dist/extensions-D9y6evn6.cjs.map +1 -0
- package/dist/extensions.cjs +1 -2
- package/dist/extensions.js +4 -36
- package/dist/locales.cjs +2 -2
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +10049 -9111
- package/dist/locales.js.map +1 -1
- package/dist/src-BKJH7Jla.cjs +5 -0
- package/dist/src-BKJH7Jla.cjs.map +1 -0
- package/dist/src-Hjv1f5lc.js +2386 -0
- package/dist/src-Hjv1f5lc.js.map +1 -0
- package/dist/style.css +2 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/yjs.cjs +2 -2
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +20 -38
- package/dist/yjs.js.map +1 -1
- package/package.json +8 -8
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +15 -1
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +5 -0
- package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +1095 -0
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +661 -0
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +128 -11
- package/src/blocks/File/helpers/render/createResizableFileBlockWrapper.ts +17 -23
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +346 -0
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +143 -71
- package/src/editor/Block.css +5 -8
- package/src/editor/BlockNoteEditor.ts +38 -1
- package/src/editor/editor.css +0 -20
- package/src/editor/managers/ExtensionManager/extensions.ts +12 -1
- package/src/editor/performance.test.ts +134 -0
- package/src/extensions/Collaboration/ForkYDoc.test.ts +115 -103
- package/src/extensions/Placeholder/Placeholder.ts +1 -1
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +86 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +33 -49
- package/src/extensions/SideMenu/SideMenu.ts +14 -8
- package/src/extensions/TableHandles/TableHandles.ts +14 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +57 -17
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +9 -8
- package/src/index.ts +1 -1
- package/src/schema/blocks/createSpec.ts +6 -2
- package/src/schema/inlineContent/types.ts +0 -1
- package/src/vite-env.d.ts +6 -0
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +14 -1
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.test.d.ts +1 -0
- package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.d.ts +1 -0
- package/types/src/editor/BlockNoteEditor.d.ts +13 -0
- package/types/src/editor/performance.test.d.ts +1 -0
- package/types/src/extensions/PreviousBlockType/PreviousBlockType.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/SideMenu.d.ts +6 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -0
- package/dist/BlockNoteExtension-BWw0r8Gy.cjs +0 -2
- package/dist/BlockNoteExtension-BWw0r8Gy.cjs.map +0 -1
- package/dist/BlockNoteExtension-C2X7LW-V.js +0 -25
- package/dist/BlockNoteExtension-C2X7LW-V.js.map +0 -1
- package/dist/BlockNoteSchema-CCs_V3lo.cjs +0 -2
- package/dist/BlockNoteSchema-CCs_V3lo.cjs.map +0 -1
- package/dist/BlockNoteSchema-ooiKsd5B.js +0 -270
- package/dist/BlockNoteSchema-ooiKsd5B.js.map +0 -1
- package/dist/EventEmitter-CLwfmbqG.cjs +0 -2
- package/dist/EventEmitter-CLwfmbqG.cjs.map +0 -1
- package/dist/EventEmitter-CjSwpTbz.js +0 -27
- package/dist/EventEmitter-CjSwpTbz.js.map +0 -1
- package/dist/ShowSelection-B0ch3unP.js +0 -51
- package/dist/ShowSelection-B0ch3unP.js.map +0 -1
- package/dist/ShowSelection-BxnbRvy4.cjs +0 -2
- package/dist/ShowSelection-BxnbRvy4.cjs.map +0 -1
- package/dist/TrailingNode-GzE59m_7.js +0 -2288
- package/dist/TrailingNode-GzE59m_7.js.map +0 -1
- package/dist/TrailingNode-n0WdMPUl.cjs +0 -2
- package/dist/TrailingNode-n0WdMPUl.cjs.map +0 -1
- package/dist/blockToNode-BNoNIXU7.js +0 -1140
- package/dist/blockToNode-BNoNIXU7.js.map +0 -1
- package/dist/blockToNode-CumVjgem.cjs +0 -7
- package/dist/blockToNode-CumVjgem.cjs.map +0 -1
- package/dist/blocknote.cjs.map +0 -1
- package/dist/blocknote.js.map +0 -1
- package/dist/blocks.cjs.map +0 -1
- package/dist/blocks.js.map +0 -1
- package/dist/defaultBlocks-Dg9kQWXm.cjs +0 -6
- package/dist/defaultBlocks-Dg9kQWXm.cjs.map +0 -1
- package/dist/defaultBlocks-ZzGbYgQn.js +0 -3284
- package/dist/defaultBlocks-ZzGbYgQn.js.map +0 -1
- package/dist/en-Cl87Uuyf.cjs +0 -2
- package/dist/en-Cl87Uuyf.cjs.map +0 -1
- package/dist/en-njEqD7AG.js +0 -408
- package/dist/en-njEqD7AG.js.map +0 -1
- package/dist/extensions.cjs.map +0 -1
- package/dist/extensions.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -20,38 +20,42 @@ it("can fork a document", async () => {
|
|
|
20
20
|
},
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
41
|
+
editor.getExtension(ForkYDocExtension)!.fork();
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
71
|
-
|
|
74
|
+
try {
|
|
75
|
+
const div = document.createElement("div");
|
|
76
|
+
editor.mount(div);
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
editor.replaceBlocks(editor.document, [
|
|
79
|
+
{
|
|
80
|
+
type: "paragraph",
|
|
81
|
+
content: [{ text: "Hello", styles: {}, type: "text" }],
|
|
82
|
+
},
|
|
83
|
+
]);
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
92
|
+
editor.getExtension(ForkYDocExtension)!.fork();
|
|
88
93
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
127
|
-
|
|
134
|
+
try {
|
|
135
|
+
const div = document.createElement("div");
|
|
136
|
+
editor.mount(div);
|
|
128
137
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
138
|
+
editor.replaceBlocks(editor.document, [
|
|
139
|
+
{
|
|
140
|
+
type: "paragraph",
|
|
141
|
+
content: [{ text: "Hello", styles: {}, type: "text" }],
|
|
142
|
+
},
|
|
143
|
+
]);
|
|
135
144
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
152
|
+
editor.getExtension(ForkYDocExtension)!.fork();
|
|
144
153
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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}
|
|
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 {
|
|
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
|
|
70
|
+
if (!transaction.docChanged) {
|
|
71
71
|
return prev;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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 =
|
|
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 =
|
|
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[
|
|
131
|
-
|
|
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
|
-
|
|
137
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
|
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"],
|