@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
@@ -158,6 +158,8 @@ export const CommentsExtension = createExtension(
158
158
  return {
159
159
  key: "comments",
160
160
  store,
161
+ runsBefore: ["link"],
162
+ tiptapExtensions: [CommentMark],
161
163
  prosemirrorPlugins: [
162
164
  new Plugin<CommentsPluginState>({
163
165
  key: PLUGIN_KEY,
@@ -224,7 +226,7 @@ export const CommentsExtension = createExtension(
224
226
  },
225
227
  handleClick: (view, pos, event) => {
226
228
  if (event.button !== 0) {
227
- return;
229
+ return false;
228
230
  }
229
231
 
230
232
  const node = view.state.doc.nodeAt(pos);
@@ -235,7 +237,7 @@ export const CommentsExtension = createExtension(
235
237
  ...prev,
236
238
  selectedThreadId: undefined,
237
239
  }));
238
- return;
240
+ return false;
239
241
  }
240
242
 
241
243
  const commentMark = node.marks.find(
@@ -243,15 +245,33 @@ export const CommentsExtension = createExtension(
243
245
  mark.type.name === markType && mark.attrs.orphan !== true,
244
246
  );
245
247
 
246
- const threadId = commentMark?.attrs.threadId as
247
- | string
248
- | undefined;
249
- if (threadId !== store.state.selectedThreadId) {
250
- store.setState((prev) => ({
251
- ...prev,
252
- selectedThreadId: threadId,
253
- }));
248
+ if (!commentMark) {
249
+ // Clicked outside any comment thread. Deselect if needed but
250
+ // don't consume the event so other handlers (e.g. link
251
+ // navigation) can process it.
252
+ if (store.state.selectedThreadId !== undefined) {
253
+ store.setState((prev) => ({
254
+ ...prev,
255
+ selectedThreadId: undefined,
256
+ }));
257
+ }
258
+ return false;
259
+ }
260
+
261
+ const threadId = commentMark.attrs.threadId as string;
262
+
263
+ // If the clicked thread is already selected, do nothing and let
264
+ // other handlers process the event (e.g. navigating a link).
265
+ if (threadId === store.state.selectedThreadId) {
266
+ return false;
254
267
  }
268
+
269
+ store.setState((prev) => ({
270
+ ...prev,
271
+ selectedThreadId: threadId,
272
+ }));
273
+
274
+ return true;
255
275
  },
256
276
  },
257
277
  }),
@@ -356,7 +376,6 @@ export const CommentsExtension = createExtension(
356
376
  },
357
377
  userStore,
358
378
  commentEditorSchema,
359
- tiptapExtensions: [CommentMark],
360
379
  } as const;
361
380
  },
362
381
  );
@@ -49,6 +49,11 @@ BASIC STYLES
49
49
  white-space: pre-wrap;
50
50
  }
51
51
 
52
+ .bn-trailing-block {
53
+ cursor: text;
54
+ height: 30px;
55
+ }
56
+
52
57
  /*
53
58
  NESTED BLOCKS
54
59
  */
@@ -127,6 +132,7 @@ NESTED BLOCKS
127
132
 
128
133
  /* HEADINGS*/
129
134
  [data-content-type="heading"] {
135
+ padding-top: 18px;
130
136
  --level: 3em;
131
137
  }
132
138
  [data-content-type="heading"][data-level="2"] {
@@ -467,6 +473,9 @@ NESTED BLOCKS
467
473
  cursor: pointer;
468
474
  display: flex;
469
475
  flex-direction: column;
476
+ /* Reset default <figure> browser margins (the wrapper becomes a <figure>
477
+ when the block has a caption). */
478
+ margin: 0;
470
479
  user-select: none;
471
480
  }
472
481
 
@@ -486,12 +495,25 @@ NESTED BLOCKS
486
495
  padding: 12px;
487
496
  }
488
497
 
498
+ [data-file-block] .bn-add-file-button:where(.dark, .dark *) {
499
+ background-color: rgb(70, 70, 70);
500
+ color: rgb(190, 190, 190);
501
+ }
502
+
489
503
  .bn-editor[contenteditable="true"] [data-file-block] .bn-add-file-button:hover,
490
504
  [data-file-block] .bn-file-name-with-icon:hover,
491
505
  .ProseMirror-selectednode .bn-file-name-with-icon {
492
506
  background-color: rgb(225, 225, 225);
493
507
  }
494
508
 
509
+ .bn-editor[contenteditable="true"]
510
+ [data-file-block]
511
+ .bn-add-file-button:hover:where(.dark, .dark *),
512
+ [data-file-block] .bn-file-name-with-icon:hover:where(.dark, .dark *),
513
+ .ProseMirror-selectednode .bn-file-name-with-icon:where(.dark, .dark *) {
514
+ background-color: rgb(90, 90, 90);
515
+ }
516
+
495
517
  [data-file-block] .bn-add-file-button-icon,
496
518
  [data-file-block] .bn-file-icon {
497
519
  width: 24px;
@@ -561,110 +583,92 @@ NESTED BLOCKS
561
583
 
562
584
  /* TEXT COLORS */
563
585
  [data-style-type="textColor"][data-value="gray"],
564
- [data-text-color="gray"],
565
586
  .bn-block:has(> .bn-block-content[data-text-color="gray"]) {
566
587
  color: #9b9a97;
567
588
  }
568
589
 
569
590
  [data-style-type="textColor"][data-value="brown"],
570
- [data-text-color="brown"],
571
591
  .bn-block:has(> .bn-block-content[data-text-color="brown"]) {
572
592
  color: #64473a;
573
593
  }
574
594
 
575
595
  [data-style-type="textColor"][data-value="red"],
576
- [data-text-color="red"],
577
596
  .bn-block:has(> .bn-block-content[data-text-color="red"]) {
578
597
  color: #e03e3e;
579
598
  }
580
599
 
581
600
  [data-style-type="textColor"][data-value="orange"],
582
- [data-text-color="orange"],
583
601
  .bn-block:has(> .bn-block-content[data-text-color="orange"]) {
584
602
  color: #d9730d;
585
603
  }
586
604
 
587
605
  [data-style-type="textColor"][data-value="yellow"],
588
- [data-text-color="yellow"],
589
606
  .bn-block:has(> .bn-block-content[data-text-color="yellow"]) {
590
607
  color: #dfab01;
591
608
  }
592
609
 
593
610
  [data-style-type="textColor"][data-value="green"],
594
- [data-text-color="green"],
595
611
  .bn-block:has(> .bn-block-content[data-text-color="green"]) {
596
612
  color: #4d6461;
597
613
  }
598
614
 
599
615
  [data-style-type="textColor"][data-value="blue"],
600
- [data-text-color="blue"],
601
616
  .bn-block:has(> .bn-block-content[data-text-color="blue"]) {
602
617
  color: #0b6e99;
603
618
  }
604
619
 
605
620
  [data-style-type="textColor"][data-value="purple"],
606
- [data-text-color="purple"],
607
621
  .bn-block:has(> .bn-block-content[data-text-color="purple"]) {
608
622
  color: #6940a5;
609
623
  }
610
624
 
611
625
  [data-style-type="textColor"][data-value="pink"],
612
- [data-text-color="pink"],
613
626
  .bn-block:has(> .bn-block-content[data-text-color="pink"]) {
614
627
  color: #ad1a72;
615
628
  }
616
629
 
617
630
  /* BACKGROUND COLORS */
618
631
  [data-style-type="backgroundColor"][data-value="gray"],
619
- [data-background-color="gray"],
620
632
  .bn-block:has(> .bn-block-content[data-background-color="gray"]) {
621
633
  background-color: #ebeced;
622
634
  }
623
635
 
624
636
  [data-style-type="backgroundColor"][data-value="brown"],
625
- [data-background-color="brown"],
626
637
  .bn-block:has(> .bn-block-content[data-background-color="brown"]) {
627
638
  background-color: #e9e5e3;
628
639
  }
629
640
 
630
641
  [data-style-type="backgroundColor"][data-value="red"],
631
- [data-background-color="red"],
632
642
  .bn-block:has(> .bn-block-content[data-background-color="red"]) {
633
643
  background-color: #fbe4e4;
634
644
  }
635
645
 
636
646
  [data-style-type="backgroundColor"][data-value="orange"],
637
- [data-background-color="orange"],
638
647
  .bn-block:has(> .bn-block-content[data-background-color="orange"]) {
639
648
  background-color: #f6e9d9;
640
649
  }
641
650
 
642
651
  [data-style-type="backgroundColor"][data-value="yellow"],
643
- [data-background-color="yellow"],
644
652
  .bn-block:has(> .bn-block-content[data-background-color="yellow"]) {
645
653
  background-color: #fbf3db;
646
654
  }
647
655
 
648
656
  [data-style-type="backgroundColor"][data-value="green"],
649
- [data-background-color="green"],
650
657
  .bn-block:has(> .bn-block-content[data-background-color="green"]) {
651
658
  background-color: #ddedea;
652
659
  }
653
660
 
654
661
  [data-style-type="backgroundColor"][data-value="blue"],
655
- [data-background-color="blue"],
656
662
  .bn-block:has(> .bn-block-content[data-background-color="blue"]) {
657
663
  background-color: #ddebf1;
658
664
  }
659
665
 
660
666
  [data-style-type="backgroundColor"][data-value="purple"],
661
- [data-background-color="purple"],
662
667
  .bn-block:has(> .bn-block-content[data-background-color="purple"]) {
663
668
  background-color: #eae4f2;
664
669
  }
665
670
 
666
671
  [data-style-type="backgroundColor"][data-value="pink"],
667
- [data-background-color="pink"],
668
672
  .bn-block:has(> .bn-block-content[data-background-color="pink"]) {
669
673
  background-color: #f4dfeb;
670
674
  }
@@ -187,7 +187,7 @@ it("sets an initial block id when using Y.js", async () => {
187
187
  expect(transactionCount).toBe(2);
188
188
  // Only after a real modification is made, will the fragment be updated
189
189
  expect(fragment.toJSON()).toMatchInlineSnapshot(
190
- `"<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>"`,
190
+ `"<blockgroup><blockcontainer id="0"><paragraph backgroundColor="default" textAlignment="left" textColor="default">Hello</paragraph></blockcontainer></blockgroup>"`,
191
191
  );
192
192
  });
193
193
 
@@ -213,8 +213,14 @@ it("onBeforeChange", () => {
213
213
  {
214
214
  "block": {
215
215
  "children": [],
216
- "content": [],
217
- "id": "3",
216
+ "content": [
217
+ {
218
+ "styles": {},
219
+ "text": "Hello",
220
+ "type": "text",
221
+ },
222
+ ],
223
+ "id": "1",
218
224
  "props": {
219
225
  "backgroundColor": "default",
220
226
  "textAlignment": "left",
@@ -232,7 +238,7 @@ it("onBeforeChange", () => {
232
238
  "block": {
233
239
  "children": [],
234
240
  "content": [],
235
- "id": "2",
241
+ "id": "0",
236
242
  "props": {
237
243
  "backgroundColor": "default",
238
244
  "textAlignment": "left",
@@ -306,7 +306,8 @@ export interface BlockNoteEditorOptions<
306
306
  };
307
307
 
308
308
  /**
309
- * An option which user can pass with `false` value to disable the automatic creation of a trailing new block on the next line when the user types or edits any block.
309
+ * When the editor document doesn't end in an empty paragraph block, this option causes the editor to render an element simulating one.
310
+ * When clicked by the user, it gets turned into an actual block at the end of the document. This element is not shown when the option is `false`.
310
311
  *
311
312
  * @default true
312
313
  */
@@ -731,15 +732,27 @@ export class BlockNoteEditor<
731
732
  /**
732
733
  * Mount the editor to a DOM element.
733
734
  *
735
+ * @param element The DOM element to mount the editor's contenteditable into.
736
+ * @param options.portalTarget Where to mount `editor.portalElement` — the
737
+ * container that floating UI (toolbars, menus, etc) portals into. When
738
+ * omitted, defaults to `element.parentElement` (which is the editor's
739
+ * `bn-container` in typical React usage), or to `document.body` /
740
+ * the surrounding shadow root when no parent is available.
741
+ *
734
742
  * @warning Not needed to call manually when using React, use BlockNoteView to take care of mounting
735
743
  */
736
- public mount = (element: HTMLElement) => {
744
+ public mount = (
745
+ element: HTMLElement,
746
+ options?: { portalTarget?: HTMLElement | null },
747
+ ) => {
737
748
  const root = element.getRootNode();
738
- if (typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot) {
739
- root.appendChild(this.portalElement);
740
- } else {
741
- document.body.appendChild(this.portalElement);
742
- }
749
+ const isInShadowRoot =
750
+ typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot;
751
+ const target =
752
+ options?.portalTarget ??
753
+ element.parentElement ??
754
+ (isInShadowRoot ? (root as ShadowRoot) : document.body);
755
+ target.appendChild(this.portalElement);
743
756
  this._tiptapEditor.mount({ mount: element });
744
757
  };
745
758
 
@@ -1240,19 +1253,23 @@ export class BlockNoteEditor<
1240
1253
  /**
1241
1254
  * Moves the selected blocks up. If the previous block has children, moves
1242
1255
  * them to the end of its children. If there is no previous block, but the
1243
- * current blocks share a common parent, moves them out of & before it.
1256
+ * current blocks share a common parent, moves them out of & before it. If a
1257
+ * `blockIdentifier` is provided, that block is moved instead of the
1258
+ * selection, and the selection is left unchanged.
1244
1259
  */
1245
- public moveBlocksUp() {
1246
- return this._blockManager.moveBlocksUp();
1260
+ public moveBlocksUp(blockIdentifier?: BlockIdentifier) {
1261
+ return this._blockManager.moveBlocksUp(blockIdentifier);
1247
1262
  }
1248
1263
 
1249
1264
  /**
1250
1265
  * Moves the selected blocks down. If the next block has children, moves
1251
1266
  * them to the start of its children. If there is no next block, but the
1252
- * current blocks share a common parent, moves them out of & after it.
1267
+ * current blocks share a common parent, moves them out of & after it. If a
1268
+ * `blockIdentifier` is provided, that block is moved instead of the
1269
+ * selection, and the selection is left unchanged.
1253
1270
  */
1254
- public moveBlocksDown() {
1255
- return this._blockManager.moveBlocksDown();
1271
+ public moveBlocksDown(blockIdentifier?: BlockIdentifier) {
1272
+ return this._blockManager.moveBlocksDown(blockIdentifier);
1256
1273
  }
1257
1274
 
1258
1275
  /**
@@ -234,18 +234,22 @@ export class BlockManager<
234
234
  /**
235
235
  * Moves the selected blocks up. If the previous block has children, moves
236
236
  * them to the end of its children. If there is no previous block, but the
237
- * current blocks share a common parent, moves them out of & before it.
237
+ * current blocks share a common parent, moves them out of & before it. If a
238
+ * `blockIdentifier` is provided, that block is moved instead of the
239
+ * selection, and the selection is left unchanged.
238
240
  */
239
- public moveBlocksUp() {
240
- return moveBlocksUp(this.editor);
241
+ public moveBlocksUp(blockIdentifier?: BlockIdentifier) {
242
+ return moveBlocksUp(this.editor, blockIdentifier);
241
243
  }
242
244
 
243
245
  /**
244
246
  * Moves the selected blocks down. If the next block has children, moves
245
247
  * them to the start of its children. If there is no next block, but the
246
- * current blocks share a common parent, moves them out of & after it.
248
+ * current blocks share a common parent, moves them out of & after it. If a
249
+ * `blockIdentifier` is provided, that block is moved instead of the
250
+ * selection, and the selection is left unchanged.
247
251
  */
248
- public moveBlocksDown() {
249
- return moveBlocksDown(this.editor);
252
+ public moveBlocksDown(blockIdentifier?: BlockIdentifier) {
253
+ return moveBlocksDown(this.editor, blockIdentifier);
250
254
  }
251
255
  }
@@ -5,7 +5,7 @@ import {
5
5
  Extension as TiptapExtension,
6
6
  } from "@tiptap/core";
7
7
  import { Gapcursor } from "@tiptap/extensions/gap-cursor";
8
- import { Link } from "../../../extensions/tiptap-extensions/Link/link.js";
8
+ import { LinkExtension } from "../../../extensions/tiptap-extensions/Link/link.js";
9
9
  import { Text } from "@tiptap/extension-text";
10
10
  import { createDropFileExtension } from "../../../api/clipboard/fromClipboard/fileDropExtension.js";
11
11
  import { createPasteFromClipboardExtension } from "../../../api/clipboard/fromClipboard/pasteExtension.js";
@@ -73,14 +73,6 @@ export function getDefaultTiptapExtensions(
73
73
  SuggestionAddMark,
74
74
  SuggestionDeleteMark,
75
75
  SuggestionModificationMark,
76
- Link.configure({
77
- HTMLAttributes: options.links?.HTMLAttributes ?? {},
78
- editor,
79
- onClick: options.links?.onClick,
80
- ...(options.links?.isValidLink
81
- ? { isValidLink: options.links.isValidLink }
82
- : {}),
83
- }),
84
76
  ...(Object.values(editor.schema.styleSpecs).map((styleSpec) => {
85
77
  return styleSpec.implementation.mark.configure({
86
78
  editor: editor,
@@ -169,6 +161,13 @@ export function getDefaultExtensions(
169
161
  DropCursorExtension(options),
170
162
  FilePanelExtension(options),
171
163
  FormattingToolbarExtension(options),
164
+ LinkExtension({
165
+ HTMLAttributes: options.links?.HTMLAttributes ?? {},
166
+ onClick: options.links?.onClick,
167
+ ...(options.links?.isValidLink
168
+ ? { isValidLink: options.links.isValidLink }
169
+ : {}),
170
+ }),
172
171
  LinkToolbarExtension(options),
173
172
  NodeSelectionKeyboardExtension(),
174
173
  PlaceholderExtension(options),
@@ -7,8 +7,9 @@ import {
7
7
  Extension as TiptapExtension,
8
8
  } from "@tiptap/core";
9
9
  import { keymap } from "@tiptap/pm/keymap";
10
- import { Plugin } from "prosemirror-state";
10
+ import { Plugin, TextSelection } from "prosemirror-state";
11
11
  import { updateBlockTr } from "../../../api/blockManipulation/commands/updateBlock/updateBlock.js";
12
+ import { setTextCursorPosition } from "../../../api/blockManipulation/selections/textCursorPosition.js";
12
13
  import { getBlockInfoFromTransaction } from "../../../api/getBlockInfoFromPos.js";
13
14
  import { sortByDependencies } from "../../../util/topo-sort.js";
14
15
  import type {
@@ -369,7 +370,49 @@ export class ExtensionManager {
369
370
  // Append in reverse priority order
370
371
  rules.push(...inputRulesByPriority.get(priority)!);
371
372
  });
372
- return [inputRulesPlugin({ rules })];
373
+ const inputRules = inputRulesPlugin({ rules });
374
+ // Sidecar plugin: triggers the same input rules on Enter by
375
+ // delegating to the inputRules plugin's handleTextInput with a
376
+ // synthetic "\n" insertion. The handlewithcare regex `\s$` already
377
+ // matches `\n`, so any rule that fires on space fires on Enter too.
378
+ // We call its handleTextInput directly (rather than via
379
+ // view.someProp) so other plugins don't observe the synthetic input,
380
+ // and so the rule's undo metadata is keyed to the same plugin
381
+ // instance that Tiptap's `commands.undoInputRule` reads from.
382
+ const inputRulesEnter = new Plugin({
383
+ props: {
384
+ handleKeyDown(view, event) {
385
+ if (event.key !== "Enter") {
386
+ return false;
387
+ }
388
+ // Only trigger on plain Enter — modifier combos like
389
+ // Shift/Cmd/Ctrl/Alt+Enter are reserved for other handlers
390
+ // (e.g. soft-break, submit) and should fall through.
391
+ if (
392
+ event.shiftKey ||
393
+ event.ctrlKey ||
394
+ event.metaKey ||
395
+ event.altKey
396
+ ) {
397
+ return false;
398
+ }
399
+ const { $cursor } = view.state.selection as TextSelection;
400
+ if (!$cursor) {
401
+ return false;
402
+ }
403
+ return !!inputRules.props.handleTextInput?.call(
404
+ inputRules,
405
+ view,
406
+ $cursor.pos,
407
+ $cursor.pos,
408
+ "\n",
409
+ () =>
410
+ view.state.tr.insertText("\n", $cursor.pos, $cursor.pos),
411
+ );
412
+ },
413
+ },
414
+ });
415
+ return [inputRules, inputRulesEnter];
373
416
  },
374
417
  }),
375
418
  );
@@ -408,30 +451,42 @@ export class ExtensionManager {
408
451
  if (extension.inputRules?.length) {
409
452
  inputRules.push(
410
453
  ...extension.inputRules.map((inputRule) => {
411
- return new InputRule(inputRule.find, (state, match, start, end) => {
412
- const replaceWith = inputRule.replace({
413
- match,
414
- range: { from: start, to: end },
415
- editor: this.editor,
416
- });
417
- if (replaceWith) {
418
- const cursorPosition = this.editor.getTextCursorPosition();
419
-
420
- if (
421
- this.editor.schema.blockSchema[cursorPosition.block.type]
422
- .content !== "inline"
423
- ) {
424
- return null;
454
+ return new InputRule(
455
+ inputRule.find,
456
+ (state, match, start, end) => {
457
+ const replaceWith = inputRule.replace({
458
+ match,
459
+ range: { from: start, to: end },
460
+ editor: this.editor,
461
+ });
462
+ if (replaceWith) {
463
+ const tr = state.tr;
464
+ const blockInfo = getBlockInfoFromTransaction(tr);
465
+
466
+ if (
467
+ !blockInfo.isBlockContainer ||
468
+ this.editor.schema.blockSchema[blockInfo.blockNoteType]
469
+ ?.content !== "inline"
470
+ ) {
471
+ return null;
472
+ }
473
+
474
+ tr.deleteRange(start, end);
475
+ updateBlockTr(tr, blockInfo.bnBlock.beforePos, replaceWith);
476
+ // updateBlockTr's replaceWith path leaves the selection after
477
+ // the new block when the content is replaced wholesale (e.g.
478
+ // when the rule returns content: []). Move the cursor back
479
+ // inside the new block so the user can keep typing.
480
+ const blockId = blockInfo.bnBlock.node.attrs.id;
481
+ if (blockId) {
482
+ setTextCursorPosition(tr, blockId, "start");
483
+ }
484
+ return tr;
425
485
  }
426
-
427
- const blockInfo = getBlockInfoFromTransaction(state.tr);
428
- const tr = state.tr.deleteRange(start, end);
429
-
430
- updateBlockTr(tr, blockInfo.bnBlock.beforePos, replaceWith);
431
- return tr;
432
- }
433
- return null;
434
- });
486
+ return null;
487
+ },
488
+ { undoable: true },
489
+ );
435
490
  }),
436
491
  );
437
492
  }
@@ -114,11 +114,11 @@ describe("Performance: transaction processing scales sub-linearly (#2595)", () =
114
114
 
115
115
  const smallAvg = measureAvgInsertTime(
116
116
  smallEditor,
117
- smallEditor._tiptapEditor.view.state.doc.content.size - 4,
117
+ smallEditor._tiptapEditor.view.state.doc.content.size - 2,
118
118
  );
119
119
  const largeAvg = measureAvgInsertTime(
120
120
  largeEditor,
121
- largeEditor._tiptapEditor.view.state.doc.content.size - 4,
121
+ largeEditor._tiptapEditor.view.state.doc.content.size - 2,
122
122
  );
123
123
  const ratio = largeAvg / smallAvg;
124
124