@blocknote/core 0.49.0 → 0.51.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.
Files changed (147) hide show
  1. package/dist/blocknote.cjs +1 -1
  2. package/dist/blocknote.js +4 -4
  3. package/dist/{blocks-CSfJen16.js → blocks-D0lMxErU.js} +612 -568
  4. package/dist/blocks-D0lMxErU.js.map +1 -0
  5. package/dist/blocks-KyMOxPT3.cjs +11 -0
  6. package/dist/blocks-KyMOxPT3.cjs.map +1 -0
  7. package/dist/blocks.cjs +1 -1
  8. package/dist/blocks.js +2 -2
  9. package/dist/comments.cjs +1 -1
  10. package/dist/comments.cjs.map +1 -1
  11. package/dist/comments.js +17 -14
  12. package/dist/comments.js.map +1 -1
  13. package/dist/{en-QsSI16s5.js → en-B9hMApn4.js} +4 -2
  14. package/dist/en-B9hMApn4.js.map +1 -0
  15. package/dist/{en-C4ykW581.cjs → en-Cj5r8sW_.cjs} +2 -2
  16. package/dist/en-Cj5r8sW_.cjs.map +1 -0
  17. package/dist/{extensions-C3nguvVr.js → extensions-CQFfm5f5.js} +621 -353
  18. package/dist/extensions-CQFfm5f5.js.map +1 -0
  19. package/dist/extensions-Cuw3zOdC.cjs +52 -0
  20. package/dist/extensions-Cuw3zOdC.cjs.map +1 -0
  21. package/dist/extensions.cjs +1 -1
  22. package/dist/extensions.js +3 -3
  23. package/dist/locales.cjs +1 -1
  24. package/dist/locales.cjs.map +1 -1
  25. package/dist/locales.js +68 -24
  26. package/dist/locales.js.map +1 -1
  27. package/dist/{src-DQfz4zLM.js → src-DK_8q1j5.js} +1135 -625
  28. package/dist/src-DK_8q1j5.js.map +1 -0
  29. package/dist/src-_83jmA7A.cjs +21 -0
  30. package/dist/src-_83jmA7A.cjs.map +1 -0
  31. package/dist/style.css +1 -1
  32. package/dist/webpack-stats.json +1 -1
  33. package/dist/yjs.cjs +1 -1
  34. package/dist/yjs.js +8 -8
  35. package/package.json +1 -13
  36. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +7 -7
  37. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +5 -3
  38. package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +5 -5
  39. package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +2550 -291
  40. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +83 -2
  41. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +103 -42
  42. package/src/api/blockManipulation/commands/nestBlock/__snapshots__/nestBlock.test.ts.snap +0 -143
  43. package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +12 -12
  44. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +5 -3
  45. package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +6 -6
  46. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +22 -22
  47. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +12 -8
  48. package/src/api/blockManipulation/setupTestEnv.ts +1 -1
  49. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +2 -6
  50. package/src/api/clipboard/fromClipboard/pasteExtension.ts +7 -2
  51. package/src/api/clipboard/toClipboard/copyExtension.ts +21 -16
  52. package/src/api/exporters/markdown/htmlToMarkdown.ts +813 -0
  53. package/src/api/exporters/markdown/markdownExporter.ts +2 -21
  54. package/src/api/nodeConversions/blockToNode.ts +3 -2
  55. package/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap +122 -107
  56. package/src/api/parsers/html/util/nestedLists.test.ts +1 -12
  57. package/src/api/parsers/markdown/markdownToHtml.ts +1194 -0
  58. package/src/api/parsers/markdown/parseMarkdown.ts +2 -101
  59. package/src/blocks/Audio/block.ts +1 -4
  60. package/src/blocks/Code/block.test.ts +258 -0
  61. package/src/blocks/File/block.ts +1 -4
  62. package/src/blocks/File/helpers/render/createFileBlockWrapper.ts +7 -2
  63. package/src/blocks/Image/block.ts +9 -6
  64. package/src/blocks/ListItem/BulletListItem/block.ts +7 -4
  65. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +3 -4
  66. package/src/blocks/Table/TableExtension.ts +38 -9
  67. package/src/blocks/Video/block.ts +4 -5
  68. package/src/blocks/Video/parseVideoElement.ts +2 -1
  69. package/src/blocks/defaultBlocks.ts +34 -1
  70. package/src/comments/extension.ts +30 -11
  71. package/src/editor/Block.css +22 -18
  72. package/src/editor/BlockNoteEditor.test.ts +10 -4
  73. package/src/editor/BlockNoteEditor.ts +30 -13
  74. package/src/editor/managers/BlockManager.ts +10 -6
  75. package/src/editor/managers/ExtensionManager/extensions.ts +8 -9
  76. package/src/editor/managers/ExtensionManager/index.ts +80 -25
  77. package/src/editor/performance.test.ts +2 -2
  78. package/src/editor/transformPasted.test.ts +295 -0
  79. package/src/editor/transformPasted.ts +77 -0
  80. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +1 -12
  81. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +0 -11
  82. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
  83. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
  84. package/src/extensions/SideMenu/SideMenu.ts +2 -2
  85. package/src/extensions/SideMenu/dragging.ts +7 -10
  86. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +21 -0
  87. package/src/extensions/TableHandles/TableHandles.ts +2 -0
  88. package/src/extensions/TrailingNode/TrailingNode.ts +124 -65
  89. package/src/extensions/tiptap-extensions/Link/index.ts +1 -1
  90. package/src/extensions/tiptap-extensions/Link/link.ts +49 -18
  91. package/src/i18n/locales/ar.ts +3 -1
  92. package/src/i18n/locales/de.ts +3 -1
  93. package/src/i18n/locales/en.ts +3 -1
  94. package/src/i18n/locales/es.ts +3 -1
  95. package/src/i18n/locales/fa.ts +3 -1
  96. package/src/i18n/locales/fr.ts +4 -2
  97. package/src/i18n/locales/he.ts +3 -1
  98. package/src/i18n/locales/hr.ts +3 -1
  99. package/src/i18n/locales/is.ts +3 -1
  100. package/src/i18n/locales/it.ts +3 -1
  101. package/src/i18n/locales/ja.ts +3 -1
  102. package/src/i18n/locales/ko.ts +3 -1
  103. package/src/i18n/locales/nl.ts +3 -1
  104. package/src/i18n/locales/no.ts +3 -1
  105. package/src/i18n/locales/pl.ts +3 -1
  106. package/src/i18n/locales/pt.ts +3 -1
  107. package/src/i18n/locales/ru.ts +3 -1
  108. package/src/i18n/locales/sk.ts +3 -1
  109. package/src/i18n/locales/uk.ts +3 -1
  110. package/src/i18n/locales/uz.ts +3 -1
  111. package/src/i18n/locales/vi.ts +3 -1
  112. package/src/i18n/locales/zh-tw.ts +3 -1
  113. package/src/i18n/locales/zh.ts +3 -1
  114. package/types/src/api/blockManipulation/commands/moveBlocks/moveBlocks.d.ts +13 -2
  115. package/types/src/api/clipboard/fromClipboard/handleVSCodePaste.d.ts +1 -1
  116. package/types/src/api/exporters/markdown/htmlToMarkdown.d.ts +11 -0
  117. package/types/src/api/parsers/markdown/markdownToHtml.d.ts +5 -0
  118. package/types/src/blocks/Code/block.test.d.ts +1 -0
  119. package/types/src/blocks/Video/block.d.ts +2 -0
  120. package/types/src/blocks/Video/parseVideoElement.d.ts +1 -0
  121. package/types/src/comments/extension.d.ts +2 -1
  122. package/types/src/editor/BlockNoteEditor.d.ts +20 -6
  123. package/types/src/editor/managers/BlockManager.d.ts +8 -4
  124. package/types/src/editor/transformPasted.test.d.ts +1 -0
  125. package/types/src/extensions/TrailingNode/TrailingNode.d.ts +8 -3
  126. package/types/src/extensions/tiptap-extensions/Link/index.d.ts +1 -1
  127. package/types/src/extensions/tiptap-extensions/Link/link.d.ts +12 -0
  128. package/types/src/i18n/locales/en.d.ts +2 -0
  129. package/types/src/i18n/locales/fa.d.ts +2 -0
  130. package/types/src/i18n/locales/sk.d.ts +2 -0
  131. package/dist/blocks-CSfJen16.js.map +0 -1
  132. package/dist/blocks-_lpGWKOa.cjs +0 -11
  133. package/dist/blocks-_lpGWKOa.cjs.map +0 -1
  134. package/dist/en-C4ykW581.cjs.map +0 -1
  135. package/dist/en-QsSI16s5.js.map +0 -1
  136. package/dist/extensions-BfYaEv6F.cjs +0 -2
  137. package/dist/extensions-BfYaEv6F.cjs.map +0 -1
  138. package/dist/extensions-C3nguvVr.js.map +0 -1
  139. package/dist/src-ChTwrMcE.cjs +0 -5
  140. package/dist/src-ChTwrMcE.cjs.map +0 -1
  141. package/dist/src-DQfz4zLM.js.map +0 -1
  142. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +0 -42
  143. package/src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.ts +0 -19
  144. package/src/api/exporters/markdown/util/removeUnderlinesRehypePlugin.ts +0 -39
  145. package/types/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.d.ts +0 -7
  146. package/types/src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.d.ts +0 -2
  147. package/types/src/api/exporters/markdown/util/removeUnderlinesRehypePlugin.d.ts +0 -6
@@ -0,0 +1,295 @@
1
+ import { TextSelection } from "@tiptap/pm/state";
2
+ import { afterEach, describe, expect, it } from "vitest";
3
+
4
+ import { BlockNoteEditor } from "./BlockNoteEditor.js";
5
+
6
+ /**
7
+ * @vitest-environment jsdom
8
+ */
9
+
10
+ const editorsToCleanup: BlockNoteEditor<any, any, any>[] = [];
11
+
12
+ afterEach(() => {
13
+ for (const editor of editorsToCleanup) {
14
+ editor.unmount();
15
+ }
16
+ editorsToCleanup.length = 0;
17
+ });
18
+
19
+ function mountEditor(editor: BlockNoteEditor<any, any, any>) {
20
+ editorsToCleanup.push(editor);
21
+ editor.mount(document.createElement("div"));
22
+ }
23
+
24
+ function selectStartOfFirstBlock(editor: BlockNoteEditor) {
25
+ editor.transact((tr) => {
26
+ let pos: number | undefined;
27
+ tr.doc.descendants((node, nodePos) => {
28
+ if (node.type.spec.group === "blockContent") {
29
+ pos = nodePos + 1;
30
+ return false;
31
+ }
32
+ return pos === undefined;
33
+ });
34
+ tr.setSelection(TextSelection.create(tr.doc, pos!));
35
+ });
36
+ }
37
+
38
+ describe("paste into empty inline-content block", () => {
39
+ it.each(["bulletListItem", "numberedListItem", "checkListItem"] as const)(
40
+ "pastes a paragraph into an empty %s without replacing it",
41
+ (type) => {
42
+ const editor = BlockNoteEditor.create({
43
+ initialContent: [{ type, content: "" }],
44
+ });
45
+ mountEditor(editor);
46
+ selectStartOfFirstBlock(editor);
47
+
48
+ editor.pasteHTML(`<p>Pasted</p>`);
49
+
50
+ const blocks = editor.document;
51
+ expect(blocks[0].type).toBe(type);
52
+ expect(blocks[0].content).toEqual([
53
+ { type: "text", text: "Pasted", styles: {} },
54
+ ]);
55
+ },
56
+ );
57
+
58
+ it("inserts paragraph content into an empty list item without dropping marks", () => {
59
+ const editor = BlockNoteEditor.create({
60
+ initialContent: [{ type: "bulletListItem", content: "" }],
61
+ });
62
+ mountEditor(editor);
63
+ selectStartOfFirstBlock(editor);
64
+
65
+ editor.pasteHTML(`<p>Hello <strong>world</strong></p>`);
66
+
67
+ const blocks = editor.document;
68
+ expect(blocks[0].type).toBe("bulletListItem");
69
+ expect(blocks[0].content).toEqual([
70
+ { type: "text", text: "Hello ", styles: {} },
71
+ { type: "text", text: "world", styles: { bold: true } },
72
+ ]);
73
+ });
74
+
75
+ it("merges leading paragraph into empty list item and inserts rest as siblings", () => {
76
+ const editor = BlockNoteEditor.create({
77
+ initialContent: [{ type: "bulletListItem", content: "" }],
78
+ });
79
+ mountEditor(editor);
80
+ selectStartOfFirstBlock(editor);
81
+
82
+ editor.pasteHTML(`<p>First</p><p>Second</p>`);
83
+
84
+ const blocks = editor.document;
85
+ expect(blocks[0].type).toBe("bulletListItem");
86
+ expect(blocks[0].content).toEqual([
87
+ { type: "text", text: "First", styles: {} },
88
+ ]);
89
+ expect(blocks[1].type).toBe("paragraph");
90
+ expect(blocks[1].content).toEqual([
91
+ { type: "text", text: "Second", styles: {} },
92
+ ]);
93
+ });
94
+
95
+ it("replaces an empty list item with a heading when pasting a heading", () => {
96
+ const editor = BlockNoteEditor.create({
97
+ initialContent: [{ type: "bulletListItem", content: "" }],
98
+ });
99
+ mountEditor(editor);
100
+ selectStartOfFirstBlock(editor);
101
+
102
+ editor.pasteHTML(`<h1>Heading</h1>`);
103
+
104
+ // The empty list item is replaced by the heading rather than absorbing
105
+ // its inline content. Headings carry semantic meaning the user explicitly
106
+ // chose, so we keep them as-is.
107
+ const blocks = editor.document;
108
+ expect(blocks[0].type).toBe("heading");
109
+ expect(blocks[0].content).toEqual([
110
+ { type: "text", text: "Heading", styles: {} },
111
+ ]);
112
+ });
113
+
114
+ it("keeps the list item but discards the heading wrapper when a paragraph follows the heading", () => {
115
+ const editor = BlockNoteEditor.create({
116
+ initialContent: [{ type: "bulletListItem", content: "" }],
117
+ });
118
+ mountEditor(editor);
119
+ selectStartOfFirstBlock(editor);
120
+
121
+ // Heading first means the leading block is not a paragraph, so the
122
+ // unwrap/retype rule doesn't apply: the empty list item gets replaced
123
+ // by the pasted heading and the trailing paragraph follows as a sibling.
124
+ editor.pasteHTML(`<h1>Heading</h1><p>Body</p>`);
125
+
126
+ const blocks = editor.document;
127
+ expect(blocks[0].type).toBe("heading");
128
+ expect(blocks[0].content).toEqual([
129
+ { type: "text", text: "Heading", styles: {} },
130
+ ]);
131
+ expect(blocks[1].type).toBe("paragraph");
132
+ expect(blocks[1].content).toEqual([
133
+ { type: "text", text: "Body", styles: {} },
134
+ ]);
135
+ });
136
+
137
+ it("still replaces the empty list item when pasting another list item", () => {
138
+ const editor = BlockNoteEditor.create({
139
+ initialContent: [{ type: "bulletListItem", content: "" }],
140
+ });
141
+ mountEditor(editor);
142
+ selectStartOfFirstBlock(editor);
143
+
144
+ editor.pasteHTML(`<ul><li>Pasted item</li></ul>`);
145
+
146
+ const blocks = editor.document;
147
+ expect(blocks[0].type).toBe("bulletListItem");
148
+ // The empty list item should be replaced (not have inline content
149
+ // appended in-place), which matches the existing behavior.
150
+ expect(blocks[0].content).toEqual([
151
+ { type: "text", text: "Pasted item", styles: {} },
152
+ ]);
153
+ });
154
+
155
+ it("pastes a paragraph into a non-empty list item without replacing it", () => {
156
+ const editor = BlockNoteEditor.create({
157
+ initialContent: [{ type: "bulletListItem", content: "abc" }],
158
+ });
159
+ mountEditor(editor);
160
+ editor.setTextCursorPosition(editor.document[0].id, "end");
161
+
162
+ editor.pasteHTML(`<p>hello</p>`);
163
+
164
+ const blocks = editor.document;
165
+ expect(blocks[0].type).toBe("bulletListItem");
166
+ expect(blocks[0].content).toEqual([
167
+ { type: "text", text: "abchello", styles: {} },
168
+ ]);
169
+ });
170
+
171
+ it("pastes bare <li>a</li><li>b</li> into an empty list item as two list items", () => {
172
+ const editor = BlockNoteEditor.create({
173
+ initialContent: [{ type: "bulletListItem", content: "" }],
174
+ });
175
+ mountEditor(editor);
176
+ selectStartOfFirstBlock(editor);
177
+
178
+ editor.pasteHTML(`<li>a</li><li>b</li>`);
179
+
180
+ const blocks = editor.document;
181
+ expect(blocks[0].type).toBe("bulletListItem");
182
+ expect(blocks[0].content).toEqual([
183
+ { type: "text", text: "a", styles: {} },
184
+ ]);
185
+ expect(blocks[1].type).toBe("bulletListItem");
186
+ expect(blocks[1].content).toEqual([
187
+ { type: "text", text: "b", styles: {} },
188
+ ]);
189
+ });
190
+
191
+ it("pastes bare <li>a</li><li>b</li> into a non-empty list item, splicing the first into the cursor", () => {
192
+ const editor = BlockNoteEditor.create({
193
+ initialContent: [{ type: "bulletListItem", content: "X" }],
194
+ });
195
+ mountEditor(editor);
196
+ editor.setTextCursorPosition(editor.document[0].id, "end");
197
+
198
+ editor.pasteHTML(`<li>a</li><li>b</li>`);
199
+
200
+ const blocks = editor.document;
201
+ expect(blocks[0].type).toBe("bulletListItem");
202
+ expect(blocks[0].content).toEqual([
203
+ { type: "text", text: "Xa", styles: {} },
204
+ ]);
205
+ expect(blocks[1].type).toBe("bulletListItem");
206
+ expect(blocks[1].content).toEqual([
207
+ { type: "text", text: "b", styles: {} },
208
+ ]);
209
+ });
210
+
211
+ it("pastes two list items into an empty list item as two siblings", () => {
212
+ const editor = BlockNoteEditor.create({
213
+ initialContent: [{ type: "bulletListItem", content: "" }],
214
+ });
215
+ mountEditor(editor);
216
+ selectStartOfFirstBlock(editor);
217
+
218
+ editor.pasteHTML(`<ul><li>a</li><li>b</li></ul>`);
219
+
220
+ // The empty list item is replaced by the two pasted list items.
221
+ const blocks = editor.document;
222
+ expect(blocks[0].type).toBe("bulletListItem");
223
+ expect(blocks[0].content).toEqual([
224
+ { type: "text", text: "a", styles: {} },
225
+ ]);
226
+ expect(blocks[1].type).toBe("bulletListItem");
227
+ expect(blocks[1].content).toEqual([
228
+ { type: "text", text: "b", styles: {} },
229
+ ]);
230
+ });
231
+
232
+ it("pastes two list items into a non-empty list item, splicing the first into the cursor", () => {
233
+ const editor = BlockNoteEditor.create({
234
+ initialContent: [{ type: "bulletListItem", content: "X" }],
235
+ });
236
+ mountEditor(editor);
237
+ editor.setTextCursorPosition(editor.document[0].id, "end");
238
+
239
+ editor.pasteHTML(`<ul><li>a</li><li>b</li></ul>`);
240
+
241
+ // The first list item's inline content is spliced at the cursor (the
242
+ // existing list item becomes "Xa") and the second list item becomes a
243
+ // new sibling.
244
+ const blocks = editor.document;
245
+ expect(blocks[0].type).toBe("bulletListItem");
246
+ expect(blocks[0].content).toEqual([
247
+ { type: "text", text: "Xa", styles: {} },
248
+ ]);
249
+ expect(blocks[1].type).toBe("bulletListItem");
250
+ expect(blocks[1].content).toEqual([
251
+ { type: "text", text: "b", styles: {} },
252
+ ]);
253
+ });
254
+
255
+ it("preserves nested list structure when pasting a nested list into an empty list item", () => {
256
+ const editor = BlockNoteEditor.create({
257
+ initialContent: [{ type: "bulletListItem", content: "" }],
258
+ });
259
+ mountEditor(editor);
260
+ selectStartOfFirstBlock(editor);
261
+
262
+ // Pasting a list with nested children: the leading block is a list item,
263
+ // so the unwrap/retype rule does not apply and the existing slice-level
264
+ // list-nesting fix in `transformPasted` keeps the nested structure
265
+ // intact.
266
+ editor.pasteHTML(`<ul><li>Outer<ul><li>Inner</li></ul></li></ul>`);
267
+
268
+ const blocks = editor.document;
269
+ expect(blocks[0].type).toBe("bulletListItem");
270
+ expect(blocks[0].content).toEqual([
271
+ { type: "text", text: "Outer", styles: {} },
272
+ ]);
273
+ expect(blocks[0].children).toHaveLength(1);
274
+ expect(blocks[0].children[0].type).toBe("bulletListItem");
275
+ expect(blocks[0].children[0].content).toEqual([
276
+ { type: "text", text: "Inner", styles: {} },
277
+ ]);
278
+ });
279
+
280
+ it("preserves the existing paragraph behavior when pasting into a non-empty paragraph", () => {
281
+ const editor = BlockNoteEditor.create({
282
+ initialContent: [{ type: "paragraph", content: "Existing " }],
283
+ });
284
+ mountEditor(editor);
285
+ editor.setTextCursorPosition(editor.document[0].id, "end");
286
+
287
+ editor.pasteHTML(`<p>added</p>`);
288
+
289
+ const blocks = editor.document;
290
+ expect(blocks[0].type).toBe("paragraph");
291
+ expect(blocks[0].content).toEqual([
292
+ { type: "text", text: "Existing added", styles: {} },
293
+ ]);
294
+ });
295
+ });
@@ -113,6 +113,11 @@ export function transformPasted(slice: Slice, view: EditorView) {
113
113
  let f = Fragment.from(slice.content);
114
114
  f = wrapTableRows(f, view.state.schema);
115
115
 
116
+ const retyped = retypeLeadingParagraphForEmptyTarget(f, view, slice);
117
+ if (retyped) {
118
+ return retyped;
119
+ }
120
+
116
121
  if (isInTableCell(view)) {
117
122
  let hasTableContent = false;
118
123
  f.descendants((node) => {
@@ -173,6 +178,78 @@ export function transformPasted(slice: Slice, view: EditorView) {
173
178
  return new Slice(f, slice.openStart, slice.openEnd);
174
179
  }
175
180
 
181
+ /**
182
+ * Pasting plain text into an empty inline-content block (e.g. an empty
183
+ * bullet list item) would normally replace that block with a paragraph:
184
+ * BlockNote's serializer always wraps content in
185
+ * `blockGroup > blockContainer > <block>`, producing a closed slice that
186
+ * ProseMirror inserts as a new block rather than splicing inline.
187
+ *
188
+ * To preserve the empty block's type, retype the leading paragraph in the
189
+ * slice to match the target block. Subsequent blocks in the slice are left
190
+ * alone and end up as siblings.
191
+ *
192
+ * Scoped to: empty, non-paragraph, inline-content target + paragraph leading
193
+ * the slice. A non-empty target already gives ProseMirror a valid inline
194
+ * insertion point so it splices correctly on its own; non-paragraph leading
195
+ * blocks (heading, list item, …) carry semantic meaning the user picked, so
196
+ * we keep the existing replace behavior.
197
+ */
198
+ function retypeLeadingParagraphForEmptyTarget(
199
+ fragment: Fragment,
200
+ view: EditorView,
201
+ slice: Slice,
202
+ ): Slice | null {
203
+ if (isInTableCell(view)) {
204
+ return null;
205
+ }
206
+
207
+ // `transformPasted` is also called for drop events, where the slice will be
208
+ // inserted at the drop position rather than the current selection. In that
209
+ // case the selection-derived target is wrong, so bail out and let the
210
+ // default behavior handle drops.
211
+ if (view.dragging) {
212
+ return null;
213
+ }
214
+
215
+ const blockInfo = getBlockInfoFromSelection(view.state);
216
+ const target = blockInfo.isBlockContainer
217
+ ? blockInfo.blockContent.node
218
+ : null;
219
+ if (
220
+ !target ||
221
+ target.type.name === "paragraph" ||
222
+ target.type.spec.content !== "inline*" ||
223
+ target.childCount > 0
224
+ ) {
225
+ return null;
226
+ }
227
+
228
+ const blockGroup = fragment.firstChild;
229
+ const blockContainer = blockGroup?.firstChild;
230
+ const leading = blockContainer?.firstChild;
231
+ if (
232
+ blockGroup?.type.name !== "blockGroup" ||
233
+ blockContainer?.type.name !== "blockContainer" ||
234
+ leading?.type.name !== "paragraph"
235
+ ) {
236
+ return null;
237
+ }
238
+
239
+ const retyped = target.type.create(target.attrs, leading.content);
240
+ const newBlockContainer = blockContainer.copy(
241
+ blockContainer.content.replaceChild(0, retyped),
242
+ );
243
+ const newBlockGroup = blockGroup.copy(
244
+ blockGroup.content.replaceChild(0, newBlockContainer),
245
+ );
246
+ return new Slice(
247
+ fragment.replaceChild(0, newBlockGroup),
248
+ slice.openStart,
249
+ slice.openEnd,
250
+ );
251
+ }
252
+
176
253
  /**
177
254
  * Used in `transformPasted` to check if the fix there should be applied, i.e.
178
255
  * if the pasted fragment should be wrapped in a `blockContainer` node. This
@@ -8,18 +8,7 @@
8
8
  "type": "text",
9
9
  },
10
10
  ],
11
- "id": "2",
12
- "props": {
13
- "backgroundColor": "default",
14
- "textAlignment": "left",
15
- "textColor": "default",
16
- },
17
- "type": "paragraph",
18
- },
19
- {
20
- "children": [],
21
- "content": [],
22
- "id": "3",
11
+ "id": "1",
23
12
  "props": {
24
13
  "backgroundColor": "default",
25
14
  "textAlignment": "left",
@@ -16,15 +16,4 @@
16
16
  },
17
17
  "type": "paragraph",
18
18
  },
19
- {
20
- "children": [],
21
- "content": [],
22
- "id": "1",
23
- "props": {
24
- "backgroundColor": "default",
25
- "textAlignment": "left",
26
- "textColor": "default",
27
- },
28
- "type": "paragraph",
29
- },
30
19
  ]
@@ -1 +1 @@
1
- <blockgroup><blockcontainer id="2"><paragraph backgroundColor="default" textAlignment="left" textColor="default">Hello World</paragraph></blockcontainer><blockcontainer id="3"><paragraph backgroundColor="default" textAlignment="left" textColor="default"></paragraph></blockcontainer></blockgroup>
1
+ <blockgroup><blockcontainer id="1"><paragraph backgroundColor="default" textAlignment="left" textColor="default">Hello World</paragraph></blockcontainer></blockgroup>
@@ -1 +1 @@
1
- <blockgroup><blockcontainer id="0"><paragraph backgroundColor="default" textAlignment="left" textColor="default">Hello</paragraph></blockcontainer><blockcontainer id="1"><paragraph backgroundColor="default" textAlignment="left" textColor="default"></paragraph></blockcontainer></blockgroup>
1
+ <blockgroup><blockcontainer id="0"><paragraph backgroundColor="default" textAlignment="left" textColor="default">Hello</paragraph></blockcontainer></blockgroup>
@@ -785,8 +785,8 @@ export const SideMenuExtension = createExtension(({ editor }) => {
785
785
  * interfering with open submenus.
786
786
  */
787
787
  hideMenuIfNotFrozen() {
788
- if (!view!.menuFrozen && view!.state!.show) {
789
- view!.state!.show = false;
788
+ if (!view!.menuFrozen && view!.state?.show) {
789
+ view!.state.show = false;
790
790
  view!.emitUpdate(view!.state!);
791
791
  }
792
792
  },
@@ -101,16 +101,13 @@ function setDragImage(view: EditorView, from: number, to = from) {
101
101
 
102
102
  // Browsers may have CORS policies which prevents iframes from being
103
103
  // manipulated, so better to stay on the safe side and remove them from the
104
- // drag preview. The drag preview doesn't work with iframes anyway.
105
- const iframes = dragImageElement.getElementsByTagName("iframe");
106
- for (let i = 0; i < iframes.length; i++) {
107
- const iframe = iframes[i];
108
- const parent = iframe.parentElement;
109
-
110
- if (parent) {
111
- parent.removeChild(iframe);
112
- }
113
- }
104
+ // drag preview. The drag preview doesn't work with embedded documents
105
+ // (iframe/embed/object) anyway, and including an <embed> (e.g. a PDF)
106
+ // can prevent the drag from initiating at all.
107
+ const embeddedDocs = dragImageElement.querySelectorAll(
108
+ "iframe, embed, object",
109
+ );
110
+ embeddedDocs.forEach((el) => el.parentElement?.removeChild(el));
114
111
 
115
112
  // TODO: This is hacky, need a better way of assigning classes to the editor so that they can also be applied to the
116
113
  // drag preview.
@@ -9,6 +9,7 @@ import {
9
9
  } from "../../schema/index.js";
10
10
  import { formatKeyboardShortcut } from "../../util/browser.js";
11
11
  import { FilePanelExtension } from "../FilePanel/FilePanel.js";
12
+ import { FormattingToolbarExtension } from "../FormattingToolbar/FormattingToolbar.js";
12
13
  import { DefaultSuggestionItem } from "./DefaultSuggestionItem.js";
13
14
  import { SuggestionMenu } from "./SuggestionMenu.js";
14
15
 
@@ -242,6 +243,11 @@ export function getDefaultSlashMenuItems<
242
243
 
243
244
  // Immediately open the file toolbar
244
245
  editor.getExtension(FilePanelExtension)?.showMenu(insertedBlock.id);
246
+ // Immediately hide the formatting toolbar. This is only necessary for
247
+ // when the `trailingBlock` editor option is set to `false` and the
248
+ // inserted block is at the end of the document. Otherwise, the
249
+ // selection moves to the next block with inline content.
250
+ editor.getExtension(FormattingToolbarExtension)?.store.setState(false);
245
251
  },
246
252
  key: "image",
247
253
  ...editor.dictionary.slash_menu.image,
@@ -257,6 +263,11 @@ export function getDefaultSlashMenuItems<
257
263
 
258
264
  // Immediately open the file toolbar
259
265
  editor.getExtension(FilePanelExtension)?.showMenu(insertedBlock.id);
266
+ // Immediately hide the formatting toolbar. This is only necessary for
267
+ // when the `trailingBlock` editor option is set to `false` and the
268
+ // inserted block is at the end of the document. Otherwise, the
269
+ // selection moves to the next block with inline content.
270
+ editor.getExtension(FormattingToolbarExtension)?.store.setState(false);
260
271
  },
261
272
  key: "video",
262
273
  ...editor.dictionary.slash_menu.video,
@@ -272,6 +283,11 @@ export function getDefaultSlashMenuItems<
272
283
 
273
284
  // Immediately open the file toolbar
274
285
  editor.getExtension(FilePanelExtension)?.showMenu(insertedBlock.id);
286
+ // Immediately hide the formatting toolbar. This is only necessary for
287
+ // when the `trailingBlock` editor option is set to `false` and the
288
+ // inserted block is at the end of the document. Otherwise, the
289
+ // selection moves to the next block with inline content.
290
+ editor.getExtension(FormattingToolbarExtension)?.store.setState(false);
275
291
  },
276
292
  key: "audio",
277
293
  ...editor.dictionary.slash_menu.audio,
@@ -287,6 +303,11 @@ export function getDefaultSlashMenuItems<
287
303
 
288
304
  // Immediately open the file toolbar
289
305
  editor.getExtension(FilePanelExtension)?.showMenu(insertedBlock.id);
306
+ // Immediately hide the formatting toolbar. This is only necessary for
307
+ // when the `trailingBlock` editor option is set to `false` and the
308
+ // inserted block is at the end of the document. Otherwise, the
309
+ // selection moves to the next block with inline content.
310
+ editor.getExtension(FormattingToolbarExtension)?.store.setState(false);
290
311
  },
291
312
  key: "file",
292
313
  ...editor.dictionary.slash_menu.file,
@@ -466,6 +466,8 @@ export class TableHandlesView implements PluginView {
466
466
  event.preventDefault();
467
467
 
468
468
  const { draggingState, colIndex, rowIndex } = this.state;
469
+ // Clear so a re-dispatched drop short-circuits above (issue #2691).
470
+ this.state.draggingState = undefined;
469
471
 
470
472
  const columnWidths = this.state.block.content.columnWidths;
471
473