@blocknote/core 0.55.0 → 0.56.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 (460) hide show
  1. package/dist/BlockNoteExtension-DjEkXkR5.cjs +2 -0
  2. package/dist/BlockNoteExtension-DjEkXkR5.cjs.map +1 -0
  3. package/dist/{BlockNoteExtension-CbvDA0F7.js → BlockNoteExtension-TsTGtIeX.js} +34 -27
  4. package/dist/BlockNoteExtension-TsTGtIeX.js.map +1 -0
  5. package/dist/{UserStore-mj3fXW4D.cjs → UserStore-CTVzVGh-.cjs} +2 -2
  6. package/dist/{UserStore-mj3fXW4D.cjs.map → UserStore-CTVzVGh-.cjs.map} +1 -1
  7. package/dist/{UserStore-C4TzkGEn.js → UserStore-OZJP3K8T.js} +2 -2
  8. package/dist/{UserStore-C4TzkGEn.js.map → UserStore-OZJP3K8T.js.map} +1 -1
  9. package/dist/blocknote.cjs +1 -1
  10. package/dist/blocknote.js +6 -6
  11. package/dist/blocks-COVwe5Cf.cjs +12 -0
  12. package/dist/blocks-COVwe5Cf.cjs.map +1 -0
  13. package/dist/{blocks-DaEUT0O1.js → blocks-COYcDVg7.js} +1572 -1156
  14. package/dist/blocks-COYcDVg7.js.map +1 -0
  15. package/dist/blocks.cjs +1 -1
  16. package/dist/blocks.js +2 -2
  17. package/dist/comments.cjs +1 -1
  18. package/dist/comments.js +12 -12
  19. package/dist/{en-BAn9gxr-.js → en-Ch-vvt5e.js} +36 -2
  20. package/dist/en-Ch-vvt5e.js.map +1 -0
  21. package/dist/en-N5lu0-j8.cjs +2 -0
  22. package/dist/en-N5lu0-j8.cjs.map +1 -0
  23. package/dist/extensions-BbM81hHa.js +3069 -0
  24. package/dist/extensions-BbM81hHa.js.map +1 -0
  25. package/dist/extensions-D_WkAfSt.cjs +58 -0
  26. package/dist/extensions-D_WkAfSt.cjs.map +1 -0
  27. package/dist/extensions.cjs +1 -1
  28. package/dist/extensions.js +4 -4
  29. package/dist/locales.cjs +1 -1
  30. package/dist/locales.cjs.map +1 -1
  31. package/dist/locales.js +771 -23
  32. package/dist/locales.js.map +1 -1
  33. package/dist/src-4OQT3z5S.cjs +23 -0
  34. package/dist/src-4OQT3z5S.cjs.map +1 -0
  35. package/dist/{src-D5w0XAHX.js → src-BmLsLZfE.js} +1390 -1278
  36. package/dist/src-BmLsLZfE.js.map +1 -0
  37. package/dist/style.css +1 -1
  38. package/dist/webpack-stats.json +1 -1
  39. package/dist/y.cjs +1 -1
  40. package/dist/y.cjs.map +1 -1
  41. package/dist/y.js +1284 -554
  42. package/dist/y.js.map +1 -1
  43. package/dist/yjs.cjs +1 -1
  44. package/dist/yjs.cjs.map +1 -1
  45. package/dist/yjs.js +189 -148
  46. package/dist/yjs.js.map +1 -1
  47. package/package.json +8 -8
  48. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +45 -6
  49. package/src/api/blockManipulation/commands/insertBlocks/insertPlacement.test.ts +217 -0
  50. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +113 -9
  51. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +151 -163
  52. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +47 -31
  53. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +122 -181
  54. package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +256 -0
  55. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +80 -40
  56. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +71 -0
  57. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +39 -31
  58. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +221 -8
  59. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +40 -8
  60. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +272 -40
  61. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +138 -117
  62. package/src/api/blockManipulation/getBlock/getBlock.ts +4 -11
  63. package/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.ts +173 -0
  64. package/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.ts +293 -0
  65. package/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.ts +145 -0
  66. package/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.ts +783 -0
  67. package/src/api/blockManipulation/layoutBlocks/plainBlocks.test.ts +180 -0
  68. package/src/api/blockManipulation/layoutBlocks/titledBlocks.test.ts +365 -0
  69. package/src/api/blockManipulation/selections/selection.ts +20 -53
  70. package/src/api/blockManipulation/selections/textCursorPosition.ts +17 -72
  71. package/src/api/blockManipulation/setupTestEnv.ts +38 -6
  72. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +4 -4
  73. package/src/api/clipboard/toClipboard/copyExtension.ts +3 -3
  74. package/src/api/combineTransactionSteps.ts +22 -0
  75. package/src/api/exporters/html/externalHTMLExporter.ts +1 -1
  76. package/src/api/exporters/html/internalHTMLSerializer.ts +4 -4
  77. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +111 -36
  78. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +51 -21
  79. package/src/api/exporters/markdown/htmlToMarkdown.ts +12 -1
  80. package/src/api/exporters/markdown/markdownExporter.ts +1 -1
  81. package/src/api/getBlockInfoFromPos.test.ts +428 -3
  82. package/src/api/getBlockInfoFromPos.ts +531 -129
  83. package/src/api/getBlocksChangedByTransaction.test.ts +7 -7
  84. package/src/api/getBlocksChangedByTransaction.ts +3 -3
  85. package/src/api/{getChangedRange.ts → getChangedRangeWithAttrs.ts} +2 -2
  86. package/src/api/getChangedRanges.test.ts +391 -0
  87. package/src/api/getChangedRanges.ts +368 -0
  88. package/src/api/nodeConversions/blockToNode.ts +44 -16
  89. package/src/api/nodeConversions/fragmentToBlocks.ts +29 -44
  90. package/src/api/nodeConversions/nodeToBlock.ts +120 -68
  91. package/src/api/nodeUtil.ts +1 -1
  92. package/src/api/parsers/markdown/autolink.ts +23 -0
  93. package/src/api/parsers/markdown/markdownToHtml.ts +115 -11
  94. package/src/blocks/Code/block.test.ts +4 -4
  95. package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +6 -1
  96. package/src/blocks/Heading/block.ts +54 -15
  97. package/src/blocks/ListItem/BulletListItem/block.ts +6 -4
  98. package/src/blocks/ListItem/CheckListItem/block.test.ts +2 -2
  99. package/src/blocks/ListItem/CheckListItem/block.ts +6 -4
  100. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +14 -17
  101. package/src/blocks/ListItem/NumberedListItem/block.ts +6 -4
  102. package/src/blocks/ListItem/ToggleListItem/block.ts +23 -12
  103. package/src/blocks/Table/block.ts +2 -10
  104. package/src/blocks/ToggleWrapper/createToggleFrame.ts +126 -0
  105. package/src/blocks/ToggleWrapper/toggleBlocks.browser.test.ts +1056 -0
  106. package/src/blocks/defaultBlockTypeItems.test.ts +70 -0
  107. package/src/blocks/defaultBlockTypeItems.ts +99 -0
  108. package/src/blocks/defaultBlocks.test.ts +67 -0
  109. package/src/blocks/defaultBlocks.ts +7 -1
  110. package/src/blocks/index.ts +2 -1
  111. package/src/editor/Block.css +286 -154
  112. package/src/editor/BlockNoteEditor.node.test.ts +35 -0
  113. package/src/editor/BlockNoteEditor.test.ts +2 -2
  114. package/src/editor/BlockNoteEditor.ts +71 -9
  115. package/src/editor/BlockNoteExtension.ts +5 -5
  116. package/src/editor/blockColors.browser.test.ts +127 -0
  117. package/src/editor/editor.css +60 -0
  118. package/src/editor/managers/BlockManager.ts +4 -3
  119. package/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.ts +45 -0
  120. package/src/editor/managers/ExtensionManager/ExtensionManager.node.test.ts +209 -0
  121. package/src/editor/managers/ExtensionManager/extensions.ts +10 -1
  122. package/src/editor/managers/ExtensionManager/index.ts +135 -68
  123. package/src/editor/managers/StateManager.ts +14 -4
  124. package/src/editor/transformPasted.ts +14 -13
  125. package/src/exporter/Exporter.test.ts +70 -1
  126. package/src/exporter/Exporter.ts +34 -4
  127. package/src/exporter/mapping.ts +41 -10
  128. package/src/extensions/DropCursor/DropCursor.ts +119 -6
  129. package/src/extensions/DropCursor/dropIntoChildren.ts +80 -0
  130. package/src/extensions/FormattingToolbar/FormattingToolbar.ts +7 -1
  131. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.ts +190 -0
  132. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +41 -4
  133. package/src/extensions/Placeholder/Placeholder.test.ts +23 -0
  134. package/src/extensions/Placeholder/Placeholder.ts +8 -7
  135. package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +36 -0
  136. package/src/extensions/PreviousBlockType/PreviousBlockType.ts +8 -4
  137. package/src/extensions/ReadOnly/ReadOnly.test.ts +181 -0
  138. package/src/extensions/ReadOnly/ReadOnly.ts +73 -0
  139. package/src/extensions/SideMenu/SideMenu.ts +401 -764
  140. package/src/extensions/SideMenu/blockDropHandling.ts +372 -0
  141. package/src/extensions/SideMenu/blockGeometry.browser.test.ts +148 -0
  142. package/src/extensions/SideMenu/blockGeometry.test.ts +46 -0
  143. package/src/extensions/SideMenu/blockGeometry.ts +53 -0
  144. package/src/extensions/SideMenu/dragging.ts +19 -32
  145. package/src/extensions/SideMenu/sideMenuHover.test.ts +36 -0
  146. package/src/extensions/SideMenu/sideMenuHover.ts +270 -0
  147. package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +5 -4
  148. package/src/extensions/SuggestionMenu/SuggestionMenu.ts +10 -1
  149. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +36 -136
  150. package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +14 -4
  151. package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +1 -1
  152. package/src/extensions/SyntaxHighlighting/shiki.ts +1 -1
  153. package/src/extensions/TableHandles/TableHandles.ts +4 -6
  154. package/src/extensions/Versioning/Versioning.browser.test.ts +151 -0
  155. package/src/extensions/Versioning/Versioning.node.test.ts +177 -0
  156. package/src/extensions/Versioning/Versioning.ts +145 -612
  157. package/src/extensions/Versioning/__test__/result.ts +12 -0
  158. package/src/extensions/Versioning/comparison.test.ts +40 -0
  159. package/src/extensions/Versioning/createVersioning.test.ts +867 -0
  160. package/src/extensions/Versioning/createVersioning.ts +499 -0
  161. package/src/extensions/Versioning/formatVersionDate.ts +24 -0
  162. package/src/extensions/Versioning/inMemoryVersioning.test.ts +533 -430
  163. package/src/extensions/Versioning/inMemoryVersioning.ts +246 -251
  164. package/src/extensions/Versioning/index.ts +4 -0
  165. package/src/extensions/Versioning/scrollScheduling.test.ts +51 -0
  166. package/src/extensions/Versioning/scrollToFirstChange.test.ts +320 -0
  167. package/src/extensions/Versioning/scrollToFirstChange.ts +139 -0
  168. package/src/extensions/Versioning/types.ts +219 -0
  169. package/src/extensions/Versioning/versioningState.ts +154 -0
  170. package/src/extensions/blockDOM.browser.test.ts +102 -0
  171. package/src/extensions/blockDOM.test.ts +178 -0
  172. package/src/extensions/blockDOM.ts +135 -0
  173. package/src/extensions/index.ts +2 -0
  174. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +1719 -53
  175. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +645 -531
  176. package/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.ts +152 -0
  177. package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +4 -9
  178. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +10 -24
  179. package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +22 -19
  180. package/src/fonts/inter.browser.test.ts +57 -0
  181. package/src/fonts/inter.css +111 -0
  182. package/src/i18n/locales/ar.ts +32 -0
  183. package/src/i18n/locales/de.ts +32 -0
  184. package/src/i18n/locales/en.ts +32 -0
  185. package/src/i18n/locales/es.ts +32 -0
  186. package/src/i18n/locales/fa.ts +32 -0
  187. package/src/i18n/locales/fr.ts +32 -0
  188. package/src/i18n/locales/he.ts +32 -0
  189. package/src/i18n/locales/hr.ts +32 -0
  190. package/src/i18n/locales/is.ts +32 -0
  191. package/src/i18n/locales/it.ts +32 -0
  192. package/src/i18n/locales/ja.ts +32 -0
  193. package/src/i18n/locales/ko.ts +32 -0
  194. package/src/i18n/locales/nl.ts +32 -0
  195. package/src/i18n/locales/no.ts +32 -0
  196. package/src/i18n/locales/pl.ts +32 -0
  197. package/src/i18n/locales/pt.ts +32 -0
  198. package/src/i18n/locales/ru.ts +32 -0
  199. package/src/i18n/locales/sk.ts +32 -0
  200. package/src/i18n/locales/uk.ts +32 -0
  201. package/src/i18n/locales/uz.ts +32 -0
  202. package/src/i18n/locales/vi.ts +32 -0
  203. package/src/i18n/locales/zh-tw.ts +32 -0
  204. package/src/i18n/locales/zh.ts +32 -0
  205. package/src/index.ts +13 -3
  206. package/src/pm-nodes/BlockContainer.test.ts +101 -0
  207. package/src/pm-nodes/BlockContainer.ts +110 -1
  208. package/src/pm-nodes/BlockGroup.ts +2 -1
  209. package/src/pm-nodes/README.md +2 -0
  210. package/src/schema/blocks/children.test.ts +288 -0
  211. package/src/schema/blocks/children.ts +136 -0
  212. package/src/schema/blocks/createSpec.browser.test.ts +176 -0
  213. package/src/schema/blocks/createSpec.test.ts +231 -0
  214. package/src/schema/blocks/createSpec.ts +493 -267
  215. package/src/schema/blocks/frame.test.ts +112 -0
  216. package/src/schema/blocks/frame.ts +337 -0
  217. package/src/schema/blocks/internal.ts +50 -17
  218. package/src/schema/blocks/keyboard.ts +154 -0
  219. package/src/schema/blocks/layoutBlockAttributes.ts +29 -0
  220. package/src/schema/blocks/meta.test.ts +53 -0
  221. package/src/schema/blocks/meta.ts +35 -0
  222. package/src/schema/blocks/renderFrame.test.ts +691 -0
  223. package/src/schema/blocks/types.ts +285 -21
  224. package/src/schema/blocks/validateChildren.ts +156 -0
  225. package/src/schema/dataAttributes.test.ts +72 -0
  226. package/src/schema/dataAttributes.ts +69 -0
  227. package/src/schema/index.ts +3 -0
  228. package/src/schema/inlineContent/internal.ts +7 -12
  229. package/src/schema/markGroups.ts +34 -2
  230. package/src/schema/schema.ts +8 -1
  231. package/src/user/userColors.test.ts +108 -0
  232. package/src/user/userColors.ts +42 -13
  233. package/src/y/comments/RESTYjsThreadStore.ts +1 -1
  234. package/src/y/comments/YjsThreadStore.test.ts +1 -1
  235. package/src/y/comments/YjsThreadStore.ts +27 -27
  236. package/src/y/comments/YjsThreadStoreBase.ts +2 -2
  237. package/src/y/comments/yjsHelpers.ts +11 -11
  238. package/src/y/extensions/AttributionExtension.test.ts +271 -2
  239. package/src/y/extensions/AttributionExtension.ts +146 -123
  240. package/src/y/extensions/DiffVersioningExtension.test.ts +67 -18
  241. package/src/y/extensions/DiffVersioningExtension.ts +95 -123
  242. package/src/y/extensions/EmptyDocBinding.test.ts +282 -0
  243. package/src/y/extensions/ForkYDoc.node.test.ts +77 -0
  244. package/src/y/extensions/ForkYDoc.test.ts +93 -2
  245. package/src/y/extensions/ForkYDoc.ts +22 -13
  246. package/src/y/extensions/History.test.ts +125 -0
  247. package/src/y/extensions/RelativePositionMapping.test.ts +35 -0
  248. package/src/y/extensions/RelativePositionMapping.ts +7 -11
  249. package/src/y/extensions/Versioning.node.test.ts +126 -0
  250. package/src/y/extensions/Versioning.test.ts +110 -401
  251. package/src/y/extensions/Versioning.ts +66 -107
  252. package/src/y/extensions/YAttributionMarks.ts +111 -9
  253. package/src/y/extensions/YCursorPlugin.ts +3 -0
  254. package/src/y/extensions/YSync.node.test.ts +75 -0
  255. package/src/y/extensions/YSync.ts +76 -4
  256. package/src/y/extensions/YSyncRemount.test.ts +99 -0
  257. package/src/y/extensions/blockMatchNodes.ts +20 -29
  258. package/src/y/extensions/index.ts +10 -26
  259. package/src/y/extensions/legacyYjsDocBinding.test.ts +652 -0
  260. package/src/y/extensions/nestingChanges.test.ts +326 -0
  261. package/src/y/extensions/persistentBlockGroups.test.ts +1709 -0
  262. package/src/y/extensions/persistentBlockGroups.ts +953 -0
  263. package/src/y/extensions/snapshotCodec.test.ts +105 -0
  264. package/src/y/extensions/snapshotCodec.ts +39 -0
  265. package/src/y/extensions/snapshotPreview.test.ts +201 -0
  266. package/src/y/extensions/snapshotPreview.ts +292 -0
  267. package/src/y/extensions/tableReshape.test.ts +121 -0
  268. package/src/y/extensions/v1BindingSnapshotDiff.test.ts +121 -0
  269. package/src/y/extensions/versionDiffAttribution.test.ts +944 -0
  270. package/src/y/extensions/versionDiffPerformance.test.ts +101 -0
  271. package/src/y/index.ts +1 -0
  272. package/src/y/utils.test.ts +289 -22
  273. package/src/y/utils.ts +167 -43
  274. package/src/y/versioning/__test__/fixtures/activity-all-after.json +5 -5
  275. package/src/y/versioning/__test__/fixtures/activity-all.json +3 -3
  276. package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +2 -2
  277. package/src/y/versioning/__test__/yhub.test.ts +902 -721
  278. package/src/y/versioning/index.ts +6 -1
  279. package/src/y/versioning/yhub.ts +316 -603
  280. package/src/y/versioning/yhubClient.ts +345 -0
  281. package/src/yjs/comments/RESTYjsThreadStore.test.ts +10 -0
  282. package/src/yjs/extensions/FixUpSchema.ts +11 -0
  283. package/src/yjs/extensions/ForkYDoc.browser.test.ts +84 -0
  284. package/src/yjs/extensions/ForkYDoc.node.test.ts +231 -0
  285. package/src/yjs/extensions/ForkYDoc.test.ts +68 -1
  286. package/src/yjs/extensions/ForkYDoc.ts +57 -39
  287. package/src/yjs/extensions/Versioning.test.ts +345 -530
  288. package/src/yjs/extensions/Versioning.ts +111 -68
  289. package/src/yjs/extensions/index.ts +1 -1
  290. package/src/yjs/index.ts +4 -0
  291. package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +2 -1
  292. package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +24 -24
  293. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +3 -2
  294. package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +1 -1
  295. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -2
  296. package/types/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.d.ts +34 -0
  297. package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.d.ts +1 -0
  298. package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.d.ts +460 -0
  299. package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.d.ts +1 -0
  300. package/types/src/api/blockManipulation/layoutBlocks/plainBlocks.test.d.ts +1 -0
  301. package/types/src/api/blockManipulation/layoutBlocks/titledBlocks.test.d.ts +1 -0
  302. package/types/src/api/blockManipulation/setupTestEnv.d.ts +15 -69
  303. package/types/src/api/combineTransactionSteps.d.ts +12 -0
  304. package/types/src/api/getBlockInfoFromPos.d.ts +218 -44
  305. package/types/src/api/{getChangedRange.d.ts → getChangedRangeWithAttrs.d.ts} +1 -1
  306. package/types/src/api/getChangedRanges.d.ts +23 -0
  307. package/types/src/api/getChangedRanges.test.d.ts +1 -0
  308. package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +0 -3
  309. package/types/src/api/parsers/markdown/autolink.d.ts +5 -0
  310. package/types/src/blocks/ToggleWrapper/createToggleFrame.d.ts +29 -0
  311. package/types/src/blocks/ToggleWrapper/toggleBlocks.browser.test.d.ts +1 -0
  312. package/types/src/blocks/defaultBlockTypeItems.d.ts +37 -0
  313. package/types/src/blocks/defaultBlockTypeItems.test.d.ts +1 -0
  314. package/types/src/blocks/defaultBlocks.test.d.ts +1 -0
  315. package/types/src/blocks/index.d.ts +2 -1
  316. package/types/src/editor/BlockNoteEditor.d.ts +36 -8
  317. package/types/src/editor/BlockNoteEditor.node.test.d.ts +1 -0
  318. package/types/src/editor/blockColors.browser.test.d.ts +1 -0
  319. package/types/src/editor/managers/BlockManager.d.ts +4 -3
  320. package/types/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.d.ts +1 -0
  321. package/types/src/editor/managers/ExtensionManager/ExtensionManager.node.test.d.ts +1 -0
  322. package/types/src/editor/managers/ExtensionManager/index.d.ts +15 -3
  323. package/types/src/editor/managers/StateManager.d.ts +1 -1
  324. package/types/src/editor/transformPasted.d.ts +1 -1
  325. package/types/src/exporter/Exporter.d.ts +11 -4
  326. package/types/src/exporter/mapping.d.ts +13 -1
  327. package/types/src/extensions/DropCursor/DropCursor.d.ts +1 -1
  328. package/types/src/extensions/DropCursor/dropIntoChildren.d.ts +38 -0
  329. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.d.ts +1 -1
  330. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.d.ts +1 -0
  331. package/types/src/extensions/Placeholder/Placeholder.test.d.ts +1 -0
  332. package/types/src/extensions/ReadOnly/ReadOnly.d.ts +21 -0
  333. package/types/src/extensions/ReadOnly/ReadOnly.test.d.ts +1 -0
  334. package/types/src/extensions/SideMenu/SideMenu.d.ts +49 -88
  335. package/types/src/extensions/SideMenu/blockDropHandling.d.ts +11 -0
  336. package/types/src/extensions/SideMenu/blockGeometry.browser.test.d.ts +1 -0
  337. package/types/src/extensions/SideMenu/blockGeometry.d.ts +22 -0
  338. package/types/src/extensions/SideMenu/blockGeometry.test.d.ts +1 -0
  339. package/types/src/extensions/SideMenu/dragging.d.ts +0 -4
  340. package/types/src/extensions/SideMenu/sideMenuHover.d.ts +58 -0
  341. package/types/src/extensions/SideMenu/sideMenuHover.test.d.ts +1 -0
  342. package/types/src/extensions/Versioning/Versioning.browser.test.d.ts +1 -0
  343. package/types/src/extensions/Versioning/Versioning.d.ts +34 -311
  344. package/types/src/extensions/Versioning/Versioning.node.test.d.ts +1 -0
  345. package/types/src/extensions/Versioning/__test__/result.d.ts +3 -0
  346. package/types/src/extensions/Versioning/comparison.test.d.ts +1 -0
  347. package/types/src/extensions/Versioning/createVersioning.d.ts +32 -0
  348. package/types/src/extensions/Versioning/createVersioning.test.d.ts +1 -0
  349. package/types/src/extensions/Versioning/formatVersionDate.d.ts +7 -0
  350. package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +64 -36
  351. package/types/src/extensions/Versioning/index.d.ts +4 -0
  352. package/types/src/extensions/Versioning/scrollScheduling.test.d.ts +1 -0
  353. package/types/src/extensions/Versioning/scrollToFirstChange.d.ts +18 -0
  354. package/types/src/extensions/Versioning/scrollToFirstChange.test.d.ts +1 -0
  355. package/types/src/extensions/Versioning/types.d.ts +239 -0
  356. package/types/src/extensions/Versioning/versioningState.d.ts +43 -0
  357. package/types/src/extensions/blockDOM.browser.test.d.ts +1 -0
  358. package/types/src/extensions/blockDOM.d.ts +37 -0
  359. package/types/src/extensions/blockDOM.test.d.ts +1 -0
  360. package/types/src/extensions/index.d.ts +2 -0
  361. package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +1 -0
  362. package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +3 -0
  363. package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.d.ts +1 -0
  364. package/types/src/fonts/inter.browser.test.d.ts +2 -0
  365. package/types/src/i18n/locales/en.d.ts +32 -0
  366. package/types/src/i18n/locales/fa.d.ts +32 -0
  367. package/types/src/i18n/locales/sk.d.ts +32 -0
  368. package/types/src/index.d.ts +6 -3
  369. package/types/src/pm-nodes/BlockContainer.d.ts +6 -0
  370. package/types/src/pm-nodes/BlockContainer.test.d.ts +1 -0
  371. package/types/src/schema/blocks/children.d.ts +39 -0
  372. package/types/src/schema/blocks/children.test.d.ts +1 -0
  373. package/types/src/schema/blocks/createSpec.browser.test.d.ts +1 -0
  374. package/types/src/schema/blocks/createSpec.d.ts +13 -0
  375. package/types/src/schema/blocks/frame.d.ts +109 -0
  376. package/types/src/schema/blocks/frame.test.d.ts +1 -0
  377. package/types/src/schema/blocks/internal.d.ts +6 -0
  378. package/types/src/schema/blocks/keyboard.d.ts +111 -0
  379. package/types/src/schema/blocks/layoutBlockAttributes.d.ts +9 -0
  380. package/types/src/schema/blocks/meta.d.ts +14 -0
  381. package/types/src/schema/blocks/meta.test.d.ts +1 -0
  382. package/types/src/schema/blocks/renderFrame.test.d.ts +1 -0
  383. package/types/src/schema/blocks/types.d.ts +228 -15
  384. package/types/src/schema/blocks/validateChildren.d.ts +5 -0
  385. package/types/src/schema/dataAttributes.d.ts +19 -0
  386. package/types/src/schema/dataAttributes.test.d.ts +1 -0
  387. package/types/src/schema/index.d.ts +3 -0
  388. package/types/src/schema/markGroups.d.ts +8 -0
  389. package/types/src/user/userColors.d.ts +24 -3
  390. package/types/src/user/userColors.test.d.ts +1 -0
  391. package/types/src/y/comments/RESTYjsThreadStore.d.ts +1 -1
  392. package/types/src/y/comments/YjsThreadStore.d.ts +1 -1
  393. package/types/src/y/comments/YjsThreadStoreBase.d.ts +2 -2
  394. package/types/src/y/comments/yjsHelpers.d.ts +5 -5
  395. package/types/src/y/extensions/AttributionExtension.d.ts +19 -21
  396. package/types/src/y/extensions/DiffVersioningExtension.d.ts +9 -4
  397. package/types/src/y/extensions/EmptyDocBinding.test.d.ts +1 -0
  398. package/types/src/y/extensions/ForkYDoc.d.ts +3 -1
  399. package/types/src/y/extensions/ForkYDoc.node.test.d.ts +1 -0
  400. package/types/src/y/extensions/History.test.d.ts +1 -0
  401. package/types/src/y/extensions/Versioning.d.ts +4 -15
  402. package/types/src/y/extensions/Versioning.node.test.d.ts +1 -0
  403. package/types/src/y/extensions/YAttributionMarks.d.ts +13 -2
  404. package/types/src/y/extensions/YCursorPlugin.d.ts +1 -0
  405. package/types/src/y/extensions/YSync.d.ts +4 -18
  406. package/types/src/y/extensions/YSync.node.test.d.ts +1 -0
  407. package/types/src/y/extensions/YSyncRemount.test.d.ts +1 -0
  408. package/types/src/y/extensions/blockMatchNodes.d.ts +0 -22
  409. package/types/src/y/extensions/index.d.ts +27 -44
  410. package/types/src/y/extensions/legacyYjsDocBinding.test.d.ts +1 -0
  411. package/types/src/y/extensions/nestingChanges.test.d.ts +1 -0
  412. package/types/src/y/extensions/persistentBlockGroups.d.ts +189 -0
  413. package/types/src/y/extensions/persistentBlockGroups.test.d.ts +1 -0
  414. package/types/src/y/extensions/snapshotCodec.d.ts +13 -0
  415. package/types/src/y/extensions/snapshotCodec.test.d.ts +1 -0
  416. package/types/src/y/extensions/snapshotPreview.d.ts +21 -0
  417. package/types/src/y/extensions/snapshotPreview.test.d.ts +1 -0
  418. package/types/src/y/extensions/tableReshape.test.d.ts +1 -0
  419. package/types/src/y/extensions/v1BindingSnapshotDiff.test.d.ts +1 -0
  420. package/types/src/y/extensions/versionDiffAttribution.test.d.ts +1 -0
  421. package/types/src/y/extensions/versionDiffPerformance.test.d.ts +1 -0
  422. package/types/src/y/index.d.ts +1 -0
  423. package/types/src/y/utils.d.ts +39 -19
  424. package/types/src/y/versioning/index.d.ts +1 -1
  425. package/types/src/y/versioning/yhub.d.ts +69 -86
  426. package/types/src/y/versioning/yhubClient.d.ts +67 -0
  427. package/types/src/yjs/extensions/ForkYDoc.browser.test.d.ts +1 -0
  428. package/types/src/yjs/extensions/ForkYDoc.d.ts +2 -0
  429. package/types/src/yjs/extensions/ForkYDoc.node.test.d.ts +1 -0
  430. package/types/src/yjs/extensions/Versioning.d.ts +36 -22
  431. package/types/src/yjs/extensions/index.d.ts +2 -1
  432. package/types/src/yjs/index.d.ts +1 -0
  433. package/dist/BlockNoteExtension-BJCLnwrE.cjs +0 -2
  434. package/dist/BlockNoteExtension-BJCLnwrE.cjs.map +0 -1
  435. package/dist/BlockNoteExtension-CbvDA0F7.js.map +0 -1
  436. package/dist/blocks-DLgTreVu.cjs +0 -12
  437. package/dist/blocks-DLgTreVu.cjs.map +0 -1
  438. package/dist/blocks-DaEUT0O1.js.map +0 -1
  439. package/dist/en-BAn9gxr-.js.map +0 -1
  440. package/dist/en-CHnrV5l8.cjs +0 -2
  441. package/dist/en-CHnrV5l8.cjs.map +0 -1
  442. package/dist/extensions-B1JQURVF.js +0 -2138
  443. package/dist/extensions-B1JQURVF.js.map +0 -1
  444. package/dist/extensions-CZkqKzJO.cjs +0 -58
  445. package/dist/extensions-CZkqKzJO.cjs.map +0 -1
  446. package/dist/src-D5w0XAHX.js.map +0 -1
  447. package/dist/src-th5uZEvx.cjs +0 -23
  448. package/dist/src-th5uZEvx.cjs.map +0 -1
  449. package/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.ts +0 -173
  450. package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +0 -63
  451. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +0 -197
  452. package/src/blocks/utils/listItemEnterHandler.ts +0 -43
  453. package/src/extensions/Versioning/Versioning.test.ts +0 -435
  454. package/src/extensions/getDraggableBlockFromElement.ts +0 -19
  455. package/types/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.d.ts +0 -32
  456. package/types/src/blocks/ListItem/ListItemKeyboardShortcuts.d.ts +0 -2
  457. package/types/src/blocks/ToggleWrapper/createToggleWrapper.d.ts +0 -15
  458. package/types/src/blocks/utils/listItemEnterHandler.d.ts +0 -2
  459. package/types/src/extensions/getDraggableBlockFromElement.d.ts +0 -5
  460. /package/types/src/{extensions/Versioning/Versioning.test.d.ts → api/blockManipulation/commands/insertBlocks/insertPlacement.test.d.ts} +0 -0
@@ -1,39 +1,106 @@
1
- import { Extension } from "@tiptap/core";
2
- import { Fragment, Node } from "prosemirror-model";
3
- import { TextSelection } from "prosemirror-state";
1
+ import { type ChainedCommands, Extension } from "@tiptap/core";
2
+ import { Fragment, type Node } from "prosemirror-model";
3
+ import {
4
+ NodeSelection,
5
+ Selection,
6
+ TextSelection,
7
+ Transaction,
8
+ } from "prosemirror-state";
4
9
 
5
10
  import {
6
- getBottomNestedBlockInfo,
7
- getNextBlockInfo,
8
- getParentBlockInfo,
9
- getPrevBlockInfo,
10
11
  mergeBlocksCommand,
12
+ getMergeContent,
11
13
  } from "../../../api/blockManipulation/commands/mergeBlocks/mergeBlocks.js";
12
14
  import {
13
15
  liftItem,
14
16
  nestBlock,
15
17
  unnestBlock,
16
18
  } from "../../../api/blockManipulation/commands/nestBlock/nestBlock.js";
17
- import { fixColumnList } from "../../../api/blockManipulation/commands/replaceBlocks/util/fixColumnList.js";
19
+ import { fixLayoutBlocksById } from "../../../api/blockManipulation/layoutBlocks/fixLayoutBlock.js";
20
+ import { nodeToBlock } from "../../../api/nodeConversions/nodeToBlock.js";
21
+ import { isLayoutNode } from "../../../schema/blocks/children.js";
18
22
  import { splitBlockCommand } from "../../../api/blockManipulation/commands/splitBlock/splitBlock.js";
19
23
  import { updateBlockCommand } from "../../../api/blockManipulation/commands/updateBlock/updateBlock.js";
20
24
  import {
21
- getBlockInfoFromResolvedPos,
25
+ type BlockInfo,
26
+ ascendToInsertablePos,
27
+ getInsertionPos,
28
+ getAncestorLayoutBlocks,
29
+ getFirstLeafBlock,
30
+ getBlockInfoAt,
31
+ getBlockInfoFromNode,
22
32
  getBlockInfoFromSelection,
33
+ getLastDescendantBlockInfo,
34
+ getNextBlockInfo,
35
+ getParentBlockInfo,
36
+ getPrevBlockInfo,
37
+ blockEdgeSelection,
23
38
  } from "../../../api/getBlockInfoFromPos.js";
24
39
  import { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
25
40
  import { FilePanelExtension } from "../../FilePanel/FilePanel.js";
26
41
  import { FormattingToolbarExtension } from "../../FormattingToolbar/FormattingToolbar.js";
27
42
 
43
+ // Move a block across a layout block boundary, repair its former ancestors, and
44
+ // map the caret through any repairs that change the insertion position.
45
+ function moveBlockOutAndPlaceCaret(
46
+ tr: Transaction,
47
+ block: BlockInfo["block"],
48
+ insertAt: number,
49
+ ) {
50
+ const layoutBlocksToFix = getAncestorLayoutBlocks(tr.doc, block.beforePos);
51
+ tr.delete(block.beforePos, block.afterPos);
52
+ const insertionPos = tr.mapping.map(insertAt);
53
+ tr.insert(insertionPos, block.node);
54
+ const stepsBeforeFix = tr.steps.length;
55
+ fixLayoutBlocksById(tr, layoutBlocksToFix);
56
+ tr.setSelection(
57
+ TextSelection.near(
58
+ tr.doc.resolve(tr.mapping.slice(stepsBeforeFix).map(insertionPos) + 1),
59
+ ),
60
+ );
61
+ }
62
+
63
+ // Delete a following block, retaining its children and any compatible text.
64
+ // A sole child also removes its child group instead of leaving an empty body.
65
+ function deleteBlockAndAppendContent(
66
+ chain: ChainedCommands,
67
+ current: Extract<BlockInfo, { hasContent: true }>,
68
+ next: Extract<BlockInfo, { hasContent: true }>,
69
+ remove: Pick<BlockInfo["block"], "beforePos" | "afterPos"> = next.block,
70
+ ) {
71
+ return chain
72
+ .insertContentAt(
73
+ next.block.afterPos,
74
+ next.children?.node.content || Fragment.empty,
75
+ )
76
+ .deleteRange({ from: remove.beforePos, to: remove.afterPos })
77
+ .insertContentAt(current.contentEnd, getMergeContent(current, next) ?? null)
78
+ .setTextSelection(current.contentEnd)
79
+ .scrollIntoView()
80
+ .run();
81
+ }
82
+
28
83
  export const KeyboardShortcutsExtension = Extension.create<{
29
84
  editor: BlockNoteEditor<any, any, any>;
30
85
  tabBehavior: "prefer-navigate-ui" | "prefer-indent";
86
+ selectAllBehavior: "block-first" | "document";
31
87
  }>({
32
88
  priority: 50,
33
89
 
34
90
  // TODO: The shortcuts need a refactor. Do we want to use a command priority
35
91
  // design as there is now, or clump the logic into a single function?
36
92
  addKeyboardShortcuts() {
93
+ const bnEditor = this.options.editor;
94
+ // The `keyboard` settings of the block that `node` holds, in `doc`.
95
+ function keyboardOf(node: Node, doc: Node) {
96
+ const block = nodeToBlock(node, doc);
97
+ return bnEditor.schema.blockSpecs[block.type].implementation.keyboard(
98
+ block,
99
+ );
100
+ }
101
+ function canOutdentFrom(doc: Node) {
102
+ return (parent: Node) => keyboardOf(parent, doc).childrenCanOutdent;
103
+ }
37
104
  // handleBackspace is partially adapted from https://github.com/ueberdosis/tiptap/blob/ed56337470efb4fd277128ab7ef792b37cfae992/packages/core/src/extensions/keymap.ts
38
105
  const handleBackspace = () =>
39
106
  this.editor.commands.first(({ chain, commands }) => [
@@ -41,79 +108,65 @@ export const KeyboardShortcutsExtension = Extension.create<{
41
108
  () => commands.deleteSelection(),
42
109
  // Undoes an input rule if one was triggered in the last editor state change.
43
110
  () => commands.undoInputRule(),
44
- // Reverts block content type to a paragraph if the selection is at the start of the block.
111
+ // Resets the block (`keyboard.resetsTo`, a paragraph by default) if the
112
+ // selection is at the start of the block and the block isn't already
113
+ // in that form.
45
114
  () =>
46
115
  commands.command(({ state }) => {
47
116
  const blockInfo = getBlockInfoFromSelection(state);
48
- if (!blockInfo.isBlockContainer) {
117
+ if (!blockInfo.hasContent) {
49
118
  return false;
50
119
  }
51
120
 
52
121
  const selectionAtBlockStart =
53
- state.selection.from === blockInfo.blockContent.beforePos + 1;
54
- const isParagraph =
55
- blockInfo.blockContent.node.type.name === "paragraph";
56
-
57
- if (selectionAtBlockStart && !isParagraph) {
58
- return commands.command(
59
- updateBlockCommand(blockInfo.bnBlock.beforePos, {
60
- type: "paragraph",
61
- props: {},
62
- }),
63
- );
64
- }
65
-
66
- return false;
67
- }),
68
- // Removes a level of nesting if the block is indented if the selection is at the start of the block.
69
- () =>
70
- commands.command(({ state, tr }) => {
71
- const blockInfo = getBlockInfoFromSelection(state);
72
- if (!blockInfo.isBlockContainer) {
122
+ state.selection.from === blockInfo.contentStart;
123
+ if (!selectionAtBlockStart) {
73
124
  return false;
74
125
  }
75
- const { blockContent } = blockInfo;
76
126
 
77
- const selectionAtBlockStart =
78
- state.selection.from === blockContent.beforePos + 1;
79
-
80
- if (selectionAtBlockStart) {
81
- return liftItem(
82
- tr,
83
- tr.doc.type.schema.nodes["blockContainer"],
84
- tr.doc.type.schema.nodes["blockGroup"],
127
+ const resetsTo = keyboardOf(
128
+ blockInfo.block.node,
129
+ state.doc,
130
+ ).resetsTo;
131
+ const content = blockInfo.content.node;
132
+ const alreadyReset =
133
+ content.type.name === resetsTo.type &&
134
+ Object.entries(resetsTo.props ?? {}).every(
135
+ ([prop, value]) => content.attrs[prop] === value,
85
136
  );
137
+ if (alreadyReset) {
138
+ return false;
86
139
  }
87
140
 
88
- return false;
141
+ return commands.command(
142
+ updateBlockCommand(blockInfo.block.beforePos, resetsTo as any),
143
+ );
89
144
  }),
90
- // Merges block with the previous one if it isn't indented, and the selection is at the start of the
91
- // block. The target block for merging must contain inline content.
145
+ // Merges at the start of the block, into the preceding sibling
146
+ // (or its deepest descendant) or parent. Both must have inline content.
92
147
  () =>
93
148
  commands.command(({ state }) => {
94
149
  const blockInfo = getBlockInfoFromSelection(state);
95
- if (!blockInfo.isBlockContainer) {
150
+ if (!blockInfo.hasContent) {
96
151
  return false;
97
152
  }
98
- const { bnBlock: blockContainer, blockContent } = blockInfo;
153
+ const { block: blockContainer } = blockInfo;
99
154
 
100
- const prevBlockInfo = getPrevBlockInfo(
155
+ const prevSibling = getPrevBlockInfo(
101
156
  state.doc,
102
- blockInfo.bnBlock.beforePos,
157
+ blockInfo.block.beforePos,
103
158
  );
104
- // If the previous block has no inline content, it can't be merged.
105
- // It's instead deleted, which is done later in the chan, so we
106
- // return early here.
107
- if (
108
- !prevBlockInfo ||
109
- !prevBlockInfo.isBlockContainer ||
110
- prevBlockInfo.blockContent.node.type.spec.content !== "inline*"
111
- ) {
159
+ // A preceding layout block takes the move branch below. Otherwise
160
+ // the block merges into the block above (its last descendant), or
161
+ // into its parent when it has no previous sibling;
162
+ // mergeBlocksCommand decides whether their contents are
163
+ // compatible.
164
+ if (prevSibling && !prevSibling.hasContent) {
112
165
  return false;
113
166
  }
114
167
 
115
168
  const selectionAtBlockStart =
116
- state.selection.from === blockContent.beforePos + 1;
169
+ state.selection.from === blockInfo.contentStart;
117
170
  const selectionEmpty = state.selection.empty;
118
171
 
119
172
  const posBetweenBlocks = blockContainer.beforePos;
@@ -127,240 +180,193 @@ export const KeyboardShortcutsExtension = Extension.create<{
127
180
 
128
181
  return false;
129
182
  }),
130
- // If the previous block is a columnList, moves the current block to
131
- // the end of the last column in it.
183
+ // Move into the preceding layout block's trailing slot, or out of the
184
+ // current layout block when this is its first block.
132
185
  () =>
133
186
  commands.command(({ state, tr, dispatch }) => {
134
187
  const blockInfo = getBlockInfoFromSelection(state);
135
- if (!blockInfo.isBlockContainer) {
188
+ if (
189
+ !blockInfo.hasContent ||
190
+ state.selection.from !== blockInfo.contentStart
191
+ ) {
136
192
  return false;
137
193
  }
138
194
 
139
- const selectionAtBlockStart =
140
- state.selection.from === blockInfo.blockContent.beforePos + 1;
141
- if (!selectionAtBlockStart) {
142
- return false;
195
+ const blockType = blockInfo.block.node.type;
196
+ let target = getPrevBlockInfo(tr.doc, blockInfo.block.beforePos);
197
+ let insertionPos: number | undefined;
198
+ if (target) {
199
+ if (target.hasContent) {
200
+ return false;
201
+ }
202
+ } else {
203
+ const $pos = tr.doc.resolve(blockInfo.block.beforePos);
204
+ if (!isLayoutNode($pos.parent.type)) {
205
+ return false;
206
+ }
207
+ const $layoutBlockPos = tr.doc.resolve($pos.before());
208
+ // Between columns, move into the previous column. Outside a
209
+ // layout block, move above the closest boundary that accepts us.
210
+ const prevSibling = $layoutBlockPos.nodeBefore;
211
+ if (
212
+ isLayoutNode($layoutBlockPos.parent.type) &&
213
+ prevSibling &&
214
+ isLayoutNode(prevSibling.type)
215
+ ) {
216
+ target = getBlockInfoFromNode(
217
+ prevSibling,
218
+ $layoutBlockPos.pos - prevSibling.nodeSize,
219
+ );
220
+ } else {
221
+ insertionPos = ascendToInsertablePos(
222
+ tr.doc,
223
+ $layoutBlockPos.pos,
224
+ blockType,
225
+ );
226
+ }
143
227
  }
144
-
145
- const prevBlockInfo = getPrevBlockInfo(
146
- state.doc,
147
- blockInfo.bnBlock.beforePos,
148
- );
149
- if (!prevBlockInfo || prevBlockInfo.isBlockContainer) {
228
+ if (target) {
229
+ insertionPos = getInsertionPos(
230
+ tr.doc,
231
+ target,
232
+ "last-child",
233
+ blockType,
234
+ )?.pos;
235
+ }
236
+ if (insertionPos === undefined) {
150
237
  return false;
151
238
  }
152
-
153
239
  if (dispatch) {
154
- const columnAfterPos = prevBlockInfo.bnBlock.afterPos - 1;
155
- const $blockAfterPos = tr.doc.resolve(columnAfterPos - 1);
156
-
157
- tr.delete(
158
- blockInfo.bnBlock.beforePos,
159
- blockInfo.bnBlock.afterPos,
160
- );
161
- tr.insert($blockAfterPos.pos, blockInfo.bnBlock.node);
162
- tr.setSelection(
163
- TextSelection.near(tr.doc.resolve($blockAfterPos.pos + 1)),
164
- );
165
-
166
- return true;
240
+ moveBlockOutAndPlaceCaret(tr, blockInfo.block, insertionPos);
167
241
  }
168
-
169
- return false;
242
+ return true;
170
243
  }),
171
- // If the block is the first in a column, moves it to the end of the
172
- // previous column. If there is no previous column, moves it above the
173
- // columnList.
244
+ // Removes an empty inline block when merging is impossible. Its
245
+ // children take its place; the cursor moves to the preceding block.
174
246
  () =>
175
247
  commands.command(({ state, tr, dispatch }) => {
176
248
  const blockInfo = getBlockInfoFromSelection(state);
177
- if (!blockInfo.isBlockContainer) {
178
- return false;
179
- }
180
-
181
- const selectionAtBlockStart =
182
- tr.selection.from === blockInfo.blockContent.beforePos + 1;
183
- if (!selectionAtBlockStart) {
184
- return false;
185
- }
186
-
187
- const $pos = tr.doc.resolve(blockInfo.bnBlock.beforePos);
188
-
189
- const prevBlock = $pos.nodeBefore;
190
- if (prevBlock) {
249
+ if (
250
+ !blockInfo.hasContent ||
251
+ !state.selection.empty ||
252
+ blockInfo.contentKind !== "inline" ||
253
+ !blockInfo.isContentEmpty
254
+ ) {
191
255
  return false;
192
256
  }
193
-
194
- const parentBlock = $pos.node();
195
- if (parentBlock.type.name !== "column") {
257
+ const prevBlockInfo = getPrevBlockInfo(
258
+ state.doc,
259
+ blockInfo.block.beforePos,
260
+ );
261
+ const parent = !prevBlockInfo
262
+ ? getParentBlockInfo(state.doc, blockInfo.block.beforePos)
263
+ : undefined;
264
+ const target = prevBlockInfo
265
+ ? getLastDescendantBlockInfo(prevBlockInfo)
266
+ : parent;
267
+ if (!target?.hasContent) {
196
268
  return false;
197
269
  }
198
-
199
- const $blockPos = tr.doc.resolve(blockInfo.bnBlock.beforePos);
200
- const $columnPos = tr.doc.resolve($blockPos.before());
201
- const columnListPos = $columnPos.before();
202
-
203
270
  if (dispatch) {
204
- tr.delete(
205
- blockInfo.bnBlock.beforePos,
206
- blockInfo.bnBlock.afterPos,
207
- );
208
- fixColumnList(tr, columnListPos);
209
-
210
- if ($columnPos.pos === columnListPos + 1) {
211
- tr.insert(columnListPos, blockInfo.bnBlock.node);
212
- tr.setSelection(
213
- TextSelection.near(tr.doc.resolve(columnListPos)),
214
- );
215
- } else {
216
- tr.insert($columnPos.pos - 1, blockInfo.bnBlock.node);
217
- tr.setSelection(
218
- TextSelection.near(tr.doc.resolve($columnPos.pos)),
219
- );
220
- }
221
- }
222
-
223
- return true;
224
- }),
225
- // Deletes the current block if it's an empty block with inline content,
226
- // and moves the selection to the previous block.
227
- () =>
228
- commands.command(({ state }) => {
229
- const blockInfo = getBlockInfoFromSelection(state);
230
- if (!blockInfo.isBlockContainer) {
231
- return false;
232
- }
233
-
234
- const blockEmpty =
235
- blockInfo.blockContent.node.childCount === 0 &&
236
- blockInfo.blockContent.node.type.spec.content === "inline*";
237
-
238
- if (blockEmpty) {
239
- const prevBlockInfo = getPrevBlockInfo(
240
- state.doc,
241
- blockInfo.bnBlock.beforePos,
242
- );
243
- if (!prevBlockInfo) {
244
- return false;
245
- }
246
- const bottomNestedPrevBlockInfo = getBottomNestedBlockInfo(
247
- state.doc,
248
- prevBlockInfo,
249
- );
250
- if (!bottomNestedPrevBlockInfo.isBlockContainer) {
251
- return false;
252
- }
253
- if (
254
- !bottomNestedPrevBlockInfo ||
255
- !bottomNestedPrevBlockInfo.isBlockContainer
256
- ) {
257
- return false;
258
- }
259
-
260
- let chainedCommands = chain();
261
-
262
- // Moves the children the current block.
263
- if (blockInfo.childContainer) {
264
- chainedCommands.insertContentAt(
265
- blockInfo.bnBlock.afterPos,
266
- blockInfo.childContainer?.node.content,
267
- );
268
- }
269
-
270
271
  if (
271
- bottomNestedPrevBlockInfo.blockContent.node.type.spec
272
- .content === "tableRow+"
273
- ) {
274
- const tableBlockEndPos = blockInfo.bnBlock.beforePos - 1;
275
- const tableBlockContentEndPos = tableBlockEndPos - 1;
276
- const lastRowEndPos = tableBlockContentEndPos - 1;
277
- const lastCellEndPos = lastRowEndPos - 1;
278
- const lastCellParagraphEndPos = lastCellEndPos - 1;
279
-
280
- chainedCommands = chainedCommands.setTextSelection(
281
- lastCellParagraphEndPos,
282
- );
283
- } else if (
284
- bottomNestedPrevBlockInfo.blockContent.node.type.spec
285
- .content === ""
272
+ parent?.children?.node.childCount === 1 &&
273
+ !blockInfo.children
286
274
  ) {
287
- chainedCommands = chainedCommands.setNodeSelection(
288
- bottomNestedPrevBlockInfo.blockContent.beforePos,
289
- );
275
+ tr.delete(parent.children.beforePos, parent.children.afterPos);
290
276
  } else {
291
- const blockContentEndPos =
292
- bottomNestedPrevBlockInfo.blockContent.afterPos - 1;
293
-
294
- chainedCommands =
295
- chainedCommands.setTextSelection(blockContentEndPos);
277
+ tr.replaceWith(
278
+ blockInfo.block.beforePos,
279
+ blockInfo.block.afterPos,
280
+ blockInfo.children?.node.content ?? Fragment.empty,
281
+ );
296
282
  }
297
-
298
- return chainedCommands
299
- .deleteRange({
300
- from: blockInfo.bnBlock.beforePos,
301
- to: blockInfo.bnBlock.afterPos,
302
- })
303
- .scrollIntoView()
304
- .run();
283
+ tr.setSelection(
284
+ target.contentKind === "none"
285
+ ? NodeSelection.create(tr.doc, target.content.beforePos)
286
+ : TextSelection.near(tr.doc.resolve(target.contentEnd), -1),
287
+ );
288
+ tr.scrollIntoView();
305
289
  }
306
-
307
- return false;
290
+ return true;
308
291
  }),
309
292
  // Deletes previous block if it contains no content and isn't a table,
310
293
  // when the selection is empty and at the start of the block. Moves the
311
294
  // current block into the deleted block's place.
312
295
  () =>
313
- commands.command(({ state }) => {
296
+ commands.command(({ state, tr, dispatch }) => {
314
297
  const blockInfo = getBlockInfoFromSelection(state);
315
298
 
316
- if (!blockInfo.isBlockContainer) {
299
+ if (!blockInfo.hasContent) {
317
300
  return false;
318
301
  }
319
302
 
320
303
  const selectionAtBlockStart =
321
- state.selection.from === blockInfo.blockContent.beforePos + 1;
304
+ state.selection.from === blockInfo.contentStart;
322
305
  const selectionEmpty = state.selection.empty;
323
306
 
324
307
  const prevBlockInfo = getPrevBlockInfo(
325
308
  state.doc,
326
- blockInfo.bnBlock.beforePos,
309
+ blockInfo.block.beforePos,
327
310
  );
328
311
 
329
312
  if (prevBlockInfo && selectionAtBlockStart && selectionEmpty) {
330
- const bottomBlock = getBottomNestedBlockInfo(
331
- state.doc,
332
- prevBlockInfo,
333
- );
313
+ // An emptied layout block has no content to merge with, so the
314
+ // guard below rejects it — the merge branch above only fires
315
+ // for a previous block with content of its own.
316
+ const bottomBlock = getLastDescendantBlockInfo(prevBlockInfo);
334
317
 
335
- if (!bottomBlock.isBlockContainer) {
318
+ if (!bottomBlock.hasContent) {
336
319
  return false;
337
320
  }
338
321
 
339
322
  const prevBlockNotTableAndNoContent =
340
- bottomBlock.blockContent.node.type.spec.content === "" ||
341
- (bottomBlock.blockContent.node.type.spec.content ===
342
- "inline*" &&
343
- bottomBlock.blockContent.node.childCount === 0);
323
+ bottomBlock.contentKind === "none" ||
324
+ (bottomBlock.contentKind === "inline" &&
325
+ bottomBlock.isContentEmpty);
344
326
 
345
327
  if (prevBlockNotTableAndNoContent) {
346
- return chain()
347
- .cut(
348
- {
349
- from: blockInfo.bnBlock.beforePos,
350
- to: blockInfo.bnBlock.afterPos,
351
- },
352
- bottomBlock.bnBlock.afterPos,
353
- )
354
- .deleteRange({
355
- from: bottomBlock.bnBlock.beforePos,
356
- to: bottomBlock.bnBlock.afterPos,
357
- })
358
- .run();
328
+ if (dispatch) {
329
+ tr.delete(
330
+ blockInfo.block.beforePos,
331
+ blockInfo.block.afterPos,
332
+ );
333
+ tr.replaceWith(
334
+ bottomBlock.block.beforePos,
335
+ bottomBlock.block.afterPos,
336
+ blockInfo.block.node,
337
+ );
338
+ tr.setSelection(
339
+ TextSelection.near(
340
+ tr.doc.resolve(bottomBlock.block.beforePos + 2),
341
+ ),
342
+ );
343
+ tr.scrollIntoView();
344
+ }
345
+ return true;
359
346
  }
360
347
  }
361
348
 
362
349
  return false;
363
350
  }),
351
+ // If no merge/deletion is possible (for example beside a table or
352
+ // under an image), unindent instead of trapping the cursor or losing text.
353
+ () =>
354
+ commands.command(({ state, tr }) => {
355
+ const blockInfo = getBlockInfoFromSelection(state);
356
+ if (
357
+ !blockInfo.hasContent ||
358
+ !state.selection.empty ||
359
+ state.selection.from !== blockInfo.contentStart
360
+ ) {
361
+ return false;
362
+ }
363
+ return liftItem(
364
+ tr,
365
+ tr.doc.type.schema.nodes["blockContainer"],
366
+ tr.doc.type.schema.nodes["blockGroup"],
367
+ canOutdentFrom(tr.doc),
368
+ );
369
+ }),
364
370
  ]);
365
371
 
366
372
  const handleDelete = () =>
@@ -375,60 +381,38 @@ export const KeyboardShortcutsExtension = Extension.create<{
375
381
  () =>
376
382
  commands.command(({ state }) => {
377
383
  const blockInfo = getBlockInfoFromSelection(state);
378
- if (!blockInfo.isBlockContainer || !blockInfo.childContainer) {
384
+ if (!blockInfo.hasContent || !blockInfo.children) {
385
+ return false;
386
+ }
387
+ const { children } = blockInfo;
388
+
389
+ // A block can have an empty children node (the `childContainer`
390
+ // group), but then there is no first child to pull anything out
391
+ // of.
392
+ if (children.node.childCount === 0) {
379
393
  return false;
380
394
  }
381
- const { blockContent, childContainer } = blockInfo;
382
395
 
383
396
  const selectionAtBlockEnd =
384
- state.selection.from === blockContent.afterPos - 1;
397
+ state.selection.from === blockInfo.contentEnd;
385
398
  const selectionEmpty = state.selection.empty;
386
399
 
387
- const firstChildBlockInfo = getBlockInfoFromResolvedPos(
388
- state.doc.resolve(childContainer.beforePos + 1),
400
+ const firstChildBlockInfo = getBlockInfoAt(
401
+ state.doc,
402
+ children.childrenStart,
389
403
  );
390
- if (!firstChildBlockInfo.isBlockContainer) {
404
+ if (!firstChildBlockInfo.hasContent) {
391
405
  return false;
392
406
  }
393
407
 
394
408
  if (selectionAtBlockEnd && selectionEmpty) {
395
- const firstChildBlockContent =
396
- firstChildBlockInfo.blockContent.node;
397
- const firstChildBlockHasInlineContent =
398
- firstChildBlockContent.type.spec.content === "inline*";
399
- const blockHasInlineContent =
400
- blockContent.node.type.spec.content === "inline*";
401
-
402
- return (
403
- chain()
404
- // Un-nests child block's children if necessary.
405
- .insertContentAt(
406
- firstChildBlockInfo.bnBlock.afterPos,
407
- firstChildBlockInfo.childContainer?.node.content ||
408
- Fragment.empty,
409
- )
410
- .deleteRange(
411
- // Deletes whole child container if there's only one child.
412
- childContainer.node.childCount === 1
413
- ? {
414
- from: childContainer.beforePos,
415
- to: childContainer.afterPos,
416
- }
417
- : {
418
- from: firstChildBlockInfo.bnBlock.beforePos,
419
- to: firstChildBlockInfo.bnBlock.afterPos,
420
- },
421
- )
422
- // Appends inline content from child block if possible.
423
- .insertContentAt(
424
- state.selection.from,
425
- firstChildBlockHasInlineContent && blockHasInlineContent
426
- ? firstChildBlockContent.content
427
- : null,
428
- )
429
- .setTextSelection(state.selection.from)
430
- .scrollIntoView()
431
- .run()
409
+ return deleteBlockAndAppendContent(
410
+ chain(),
411
+ blockInfo,
412
+ firstChildBlockInfo,
413
+ children.node.childCount === 1
414
+ ? children
415
+ : firstChildBlockInfo.block,
432
416
  );
433
417
  }
434
418
 
@@ -440,21 +424,21 @@ export const KeyboardShortcutsExtension = Extension.create<{
440
424
  () =>
441
425
  commands.command(({ state }) => {
442
426
  const blockInfo = getBlockInfoFromSelection(state);
443
- if (!blockInfo.isBlockContainer) {
427
+ if (!blockInfo.hasContent) {
444
428
  return false;
445
429
  }
446
- const { bnBlock: blockContainer, blockContent } = blockInfo;
430
+ const { block: blockContainer } = blockInfo;
447
431
 
448
432
  const nextBlockInfo = getNextBlockInfo(
449
433
  state.doc,
450
- blockInfo.bnBlock.beforePos,
434
+ blockInfo.block.beforePos,
451
435
  );
452
- if (!nextBlockInfo || !nextBlockInfo.isBlockContainer) {
436
+ if (!nextBlockInfo || !nextBlockInfo.hasContent) {
453
437
  return false;
454
438
  }
455
439
 
456
440
  const selectionAtBlockEnd =
457
- state.selection.from === blockContent.afterPos - 1;
441
+ state.selection.from === blockInfo.contentEnd;
458
442
  const selectionEmpty = state.selection.empty;
459
443
 
460
444
  const posBetweenBlocks = blockContainer.afterPos;
@@ -468,105 +452,49 @@ export const KeyboardShortcutsExtension = Extension.create<{
468
452
 
469
453
  return false;
470
454
  }),
471
- // If the next block is a columnList, moves the first block from its
472
- // first column to after the current block.
455
+ // Pull the next leaf across a layout block boundary. It may be inside
456
+ // the next sibling layout block, or follow the layout blocks we're leaving.
473
457
  () =>
474
458
  commands.command(({ state, tr, dispatch }) => {
475
459
  const blockInfo = getBlockInfoFromSelection(state);
476
- if (!blockInfo.isBlockContainer) {
477
- return false;
478
- }
479
-
480
- const selectionAtBlockEnd =
481
- state.selection.from === blockInfo.blockContent.afterPos - 1;
482
- if (!selectionAtBlockEnd) {
483
- return false;
484
- }
485
-
486
- const nextBlockInfo = getNextBlockInfo(
487
- state.doc,
488
- blockInfo.bnBlock.beforePos,
489
- );
490
- if (!nextBlockInfo || nextBlockInfo.isBlockContainer) {
460
+ if (
461
+ !blockInfo.hasContent ||
462
+ state.selection.from !== blockInfo.contentEnd
463
+ ) {
491
464
  return false;
492
465
  }
493
466
 
494
- if (dispatch) {
495
- const columnBeforePos = nextBlockInfo.bnBlock.beforePos + 1;
496
- const $blockBeforePos = tr.doc.resolve(columnBeforePos + 1);
497
-
498
- tr.delete(
499
- $blockBeforePos.pos,
500
- $blockBeforePos.pos + $blockBeforePos.nodeAfter!.nodeSize,
501
- );
502
- fixColumnList(tr, nextBlockInfo.bnBlock.beforePos);
503
- tr.insert(blockInfo.bnBlock.afterPos, $blockBeforePos.nodeAfter!);
504
- tr.setSelection(
505
- TextSelection.near(tr.doc.resolve($blockBeforePos.pos)),
506
- );
507
-
508
- return true;
509
- }
510
-
511
- return false;
512
- }),
513
- // If the block is the last in a column, moves it to the start of the
514
- // next column. If there is no next column, moves it below the
515
- // columnList.
516
- () =>
517
- commands.command(({ state, tr, dispatch }) => {
518
- const blockInfo = getBlockInfoFromSelection(state);
519
- if (!blockInfo.isBlockContainer) {
520
- return false;
467
+ let $boundary = tr.doc.resolve(blockInfo.block.afterPos);
468
+ while (
469
+ !$boundary.nodeAfter &&
470
+ $boundary.depth > 0 &&
471
+ isLayoutNode($boundary.parent.type)
472
+ ) {
473
+ $boundary = tr.doc.resolve($boundary.after());
521
474
  }
522
-
523
- const selectionAtBlockEnd =
524
- tr.selection.from === blockInfo.blockContent.afterPos - 1;
525
- if (!selectionAtBlockEnd) {
475
+ const nextNode = $boundary.nodeAfter;
476
+ if (!nextNode) {
526
477
  return false;
527
478
  }
528
479
 
529
- const $pos = tr.doc.resolve(blockInfo.bnBlock.afterPos);
530
-
531
- const nextBlock = $pos.nodeAfter;
532
- if (nextBlock) {
480
+ const crossedBoundary = $boundary.pos !== blockInfo.block.afterPos;
481
+ if (!crossedBoundary && !isLayoutNode(nextNode.type)) {
533
482
  return false;
534
483
  }
535
-
536
- const parentBlock = $pos.node();
537
- if (parentBlock.type.name !== "column") {
484
+ const target = getFirstLeafBlock(
485
+ getBlockInfoFromNode(nextNode, $boundary.pos),
486
+ );
487
+ if (!target) {
538
488
  return false;
539
489
  }
540
490
 
541
- const $blockEndPos = tr.doc.resolve(blockInfo.bnBlock.afterPos);
542
- const $columnEndPos = tr.doc.resolve($blockEndPos.after());
543
- const columnListEndPos = $columnEndPos.after();
544
-
545
491
  if (dispatch) {
546
- // Position before first block in next column, or first block
547
- // after columnList if there is no next column.
548
- const nextBlockBeforePos =
549
- $columnEndPos.pos === columnListEndPos - 1
550
- ? columnListEndPos
551
- : $columnEndPos.pos + 1;
552
- const nextBlockInfo = getBlockInfoFromResolvedPos(
553
- tr.doc.resolve(nextBlockBeforePos),
554
- );
555
-
556
- tr.delete(
557
- nextBlockInfo.bnBlock.beforePos,
558
- nextBlockInfo.bnBlock.afterPos,
559
- );
560
- fixColumnList(
492
+ moveBlockOutAndPlaceCaret(
561
493
  tr,
562
- columnListEndPos - $columnEndPos.node().nodeSize,
563
- );
564
- tr.insert($blockEndPos.pos, nextBlockInfo.bnBlock.node);
565
- tr.setSelection(
566
- TextSelection.near(tr.doc.resolve(nextBlockBeforePos)),
494
+ target.block,
495
+ blockInfo.block.afterPos,
567
496
  );
568
497
  }
569
-
570
498
  return true;
571
499
  }),
572
500
  // Deletes the next block at either the same or lower nesting level, if
@@ -577,72 +505,39 @@ export const KeyboardShortcutsExtension = Extension.create<{
577
505
  () =>
578
506
  commands.command(({ state }) => {
579
507
  const blockInfo = getBlockInfoFromSelection(state);
580
- if (!blockInfo.isBlockContainer) {
508
+ if (!blockInfo.hasContent) {
581
509
  return false;
582
510
  }
583
- const { blockContent } = blockInfo;
584
511
 
585
512
  const selectionAtBlockEnd =
586
- state.selection.from === blockContent.afterPos - 1;
513
+ state.selection.from === blockInfo.contentEnd;
587
514
  const selectionEmpty = state.selection.empty;
588
515
 
589
516
  if (selectionAtBlockEnd && selectionEmpty) {
590
- const getNextBlockInfoAtAnyLevel = (
591
- doc: Node,
592
- beforePos: number,
593
- ) => {
594
- const nextBlockInfo = getNextBlockInfo(doc, beforePos);
517
+ let nextBlockInfo: BlockInfo | undefined;
518
+ let ancestor: BlockInfo | undefined = blockInfo;
519
+ while (ancestor) {
520
+ nextBlockInfo = getNextBlockInfo(
521
+ state.doc,
522
+ ancestor.block.beforePos,
523
+ );
595
524
  if (nextBlockInfo) {
596
- return nextBlockInfo;
597
- }
598
-
599
- const parentBlockInfo = getParentBlockInfo(doc, beforePos);
600
- if (!parentBlockInfo) {
601
- return undefined;
525
+ break;
602
526
  }
603
-
604
- return getNextBlockInfoAtAnyLevel(
605
- doc,
606
- parentBlockInfo.bnBlock.beforePos,
527
+ ancestor = getParentBlockInfo(
528
+ state.doc,
529
+ ancestor.block.beforePos,
607
530
  );
608
- };
609
-
610
- const nextBlockInfo = getNextBlockInfoAtAnyLevel(
611
- state.doc,
612
- blockInfo.bnBlock.beforePos,
613
- );
614
- if (!nextBlockInfo || !nextBlockInfo.isBlockContainer) {
531
+ }
532
+ if (!nextBlockInfo || !nextBlockInfo.hasContent) {
615
533
  return false;
616
534
  }
617
535
 
618
- const nextBlockContent = nextBlockInfo.blockContent.node;
619
- const nextBlockHasInlineContent =
620
- nextBlockContent.type.spec.content === "inline*";
621
- const blockHasInlineContent =
622
- blockContent.node.type.spec.content === "inline*";
623
-
624
- return (
625
- chain()
626
- // Un-nests next block's children if necessary.
627
- .insertContentAt(
628
- nextBlockInfo.bnBlock.afterPos,
629
- nextBlockInfo.childContainer?.node.content ||
630
- Fragment.empty,
631
- )
632
- .deleteRange({
633
- from: nextBlockInfo.bnBlock.beforePos,
634
- to: nextBlockInfo.bnBlock.afterPos,
635
- })
636
- // Appends inline content from child block if possible.
637
- .insertContentAt(
638
- state.selection.from,
639
- nextBlockHasInlineContent && blockHasInlineContent
640
- ? nextBlockContent.content
641
- : null,
642
- )
643
- .setTextSelection(state.selection.from)
644
- .scrollIntoView()
645
- .run()
536
+ return deleteBlockAndAppendContent(
537
+ chain(),
538
+ blockInfo,
539
+ nextBlockInfo,
540
+ nextBlockInfo.block,
646
541
  );
647
542
  }
648
543
 
@@ -653,54 +548,35 @@ export const KeyboardShortcutsExtension = Extension.create<{
653
548
  () =>
654
549
  commands.command(({ state }) => {
655
550
  const blockInfo = getBlockInfoFromSelection(state);
656
- if (!blockInfo.isBlockContainer) {
551
+ if (!blockInfo.hasContent) {
657
552
  return false;
658
553
  }
659
554
 
660
555
  const blockEmpty =
661
- blockInfo.blockContent.node.childCount === 0 &&
662
- blockInfo.blockContent.node.type.spec.content === "inline*";
556
+ blockInfo.isContentEmpty && blockInfo.contentKind === "inline";
663
557
 
664
558
  if (blockEmpty) {
665
559
  const nextBlockInfo = getNextBlockInfo(
666
560
  state.doc,
667
- blockInfo.bnBlock.beforePos,
561
+ blockInfo.block.beforePos,
668
562
  );
669
- if (!nextBlockInfo || !nextBlockInfo.isBlockContainer) {
563
+ if (!nextBlockInfo || !nextBlockInfo.hasContent) {
670
564
  return false;
671
565
  }
672
566
 
673
- let chainedCommands = chain();
567
+ const chainedCommands = chain();
674
568
 
675
- if (
676
- nextBlockInfo.blockContent.node.type.spec.content ===
677
- "tableRow+"
678
- ) {
679
- const tableBlockStartPos = blockInfo.bnBlock.afterPos + 1;
680
- const tableBlockContentStartPos = tableBlockStartPos + 1;
681
- const firstRowStartPos = tableBlockContentStartPos + 1;
682
- const firstCellStartPos = firstRowStartPos + 1;
683
- const firstCellParagraphStartPos = firstCellStartPos + 1;
684
-
685
- chainedCommands = chainedCommands.setTextSelection(
686
- firstCellParagraphStartPos,
687
- );
688
- } else if (
689
- nextBlockInfo.blockContent.node.type.spec.content === ""
690
- ) {
691
- chainedCommands = chainedCommands.setNodeSelection(
692
- nextBlockInfo.blockContent.beforePos,
693
- );
694
- } else {
695
- chainedCommands = chainedCommands.setTextSelection(
696
- nextBlockInfo.blockContent.beforePos + 1,
569
+ chainedCommands.command(({ tr }) => {
570
+ tr.setSelection(
571
+ blockEdgeSelection(tr.doc, nextBlockInfo, "start"),
697
572
  );
698
- }
573
+ return true;
574
+ });
699
575
 
700
576
  return chainedCommands
701
577
  .deleteRange({
702
- from: blockInfo.bnBlock.beforePos,
703
- to: blockInfo.bnBlock.afterPos,
578
+ from: blockInfo.block.beforePos,
579
+ to: blockInfo.block.afterPos,
704
580
  })
705
581
  .scrollIntoView()
706
582
  .run();
@@ -715,45 +591,40 @@ export const KeyboardShortcutsExtension = Extension.create<{
715
591
  commands.command(({ state }) => {
716
592
  const blockInfo = getBlockInfoFromSelection(state);
717
593
 
718
- if (!blockInfo.isBlockContainer) {
594
+ if (!blockInfo.hasContent) {
719
595
  return false;
720
596
  }
721
597
 
722
598
  const selectionAtBlockEnd =
723
- state.selection.from === blockInfo.blockContent.afterPos - 1;
599
+ state.selection.from === blockInfo.contentEnd;
724
600
  const selectionEmpty = state.selection.empty;
725
601
 
726
602
  const nextBlockInfo = getNextBlockInfo(
727
603
  state.doc,
728
- blockInfo.bnBlock.beforePos,
604
+ blockInfo.block.beforePos,
729
605
  );
730
606
  if (!nextBlockInfo) {
731
607
  return false;
732
608
  }
733
- if (!nextBlockInfo.isBlockContainer) {
609
+ if (!nextBlockInfo.hasContent) {
734
610
  return false;
735
611
  }
736
612
 
737
613
  if (nextBlockInfo && selectionAtBlockEnd && selectionEmpty) {
738
614
  const nextBlockNotTableAndNoContent =
739
- nextBlockInfo.blockContent.node.type.spec.content === "" ||
740
- (nextBlockInfo.blockContent.node.type.spec.content ===
741
- "inline*" &&
742
- nextBlockInfo.blockContent.node.childCount === 0);
615
+ nextBlockInfo.contentKind === "none" ||
616
+ (nextBlockInfo.contentKind === "inline" &&
617
+ nextBlockInfo.isContentEmpty);
743
618
 
744
619
  if (nextBlockNotTableAndNoContent) {
745
- const childBlocks =
746
- nextBlockInfo.bnBlock.node.lastChild!.content;
747
620
  return chain()
748
621
  .deleteRange({
749
- from: nextBlockInfo.bnBlock.beforePos,
750
- to: nextBlockInfo.bnBlock.afterPos,
622
+ from: nextBlockInfo.block.beforePos,
623
+ to: nextBlockInfo.block.afterPos,
751
624
  })
752
625
  .insertContentAt(
753
- blockInfo.bnBlock.afterPos,
754
- nextBlockInfo.bnBlock.node.childCount === 2
755
- ? childBlocks
756
- : null,
626
+ blockInfo.block.afterPos,
627
+ nextBlockInfo.children?.node.content ?? null,
757
628
  )
758
629
  .run();
759
630
  }
@@ -765,15 +636,39 @@ export const KeyboardShortcutsExtension = Extension.create<{
765
636
 
766
637
  const handleEnter = (withShift = false) => {
767
638
  return this.editor.commands.first(({ commands, tr }) => [
639
+ // Resets an empty block (`keyboard.resetsTo`) if it resets on Enter
640
+ // (`keyboard.emptyEnterResets`), e.g. an empty list item turns into a
641
+ // paragraph. Its children stay.
642
+ () =>
643
+ commands.command(({ state }) => {
644
+ const blockInfo = getBlockInfoFromSelection(state);
645
+ if (
646
+ !blockInfo.hasContent ||
647
+ !state.selection.empty ||
648
+ !blockInfo.isContentEmpty
649
+ ) {
650
+ return false;
651
+ }
652
+ const keyboard = keyboardOf(blockInfo.block.node, state.doc);
653
+ if (!keyboard.emptyEnterResets) {
654
+ return false;
655
+ }
656
+ return commands.command(
657
+ updateBlockCommand(
658
+ blockInfo.block.beforePos,
659
+ keyboard.resetsTo as any,
660
+ ),
661
+ );
662
+ }),
768
663
  // Removes a level of nesting if the block is empty & indented, while the selection is also empty & at the start
769
664
  // of the block.
770
665
  () =>
771
666
  commands.command(({ state, tr }) => {
772
667
  const blockInfo = getBlockInfoFromSelection(state);
773
- if (!blockInfo.isBlockContainer) {
668
+ if (!blockInfo.hasContent) {
774
669
  return false;
775
670
  }
776
- const { bnBlock: blockContainer, blockContent } = blockInfo;
671
+ const { block: blockContainer } = blockInfo;
777
672
 
778
673
  const { depth } = state.doc.resolve(blockContainer.beforePos);
779
674
 
@@ -781,7 +676,7 @@ export const KeyboardShortcutsExtension = Extension.create<{
781
676
  state.selection.$anchor.parentOffset === 0;
782
677
  const selectionEmpty =
783
678
  state.selection.anchor === state.selection.head;
784
- const blockEmpty = blockContent.node.childCount === 0;
679
+ const blockEmpty = blockInfo.isContentEmpty;
785
680
  const blockIndented = depth > 1;
786
681
 
787
682
  if (
@@ -790,16 +685,32 @@ export const KeyboardShortcutsExtension = Extension.create<{
790
685
  blockEmpty &&
791
686
  blockIndented
792
687
  ) {
688
+ // Only outdents where the parent says so
689
+ // (`keyboard.emptyChildEnter: "outdent"`); otherwise the block
690
+ // leaves at the end, or a new child is added, further down.
691
+ const parent = getParentBlockInfo(
692
+ state.doc,
693
+ blockContainer.beforePos,
694
+ );
695
+ if (
696
+ parent &&
697
+ keyboardOf(parent.block.node, state.doc).emptyChildEnter !==
698
+ "outdent"
699
+ ) {
700
+ return false;
701
+ }
793
702
  return liftItem(
794
703
  tr,
795
704
  tr.doc.type.schema.nodes["blockContainer"],
796
705
  tr.doc.type.schema.nodes["blockGroup"],
706
+ canOutdentFrom(tr.doc),
797
707
  );
798
708
  }
799
709
 
800
710
  return false;
801
711
  }),
802
- // Creates a hard break if block is configured to do so.
712
+ // Creates a hard break if the block is configured to do so
713
+ // (`keyboard.enter` / `keyboard.shiftEnter`).
803
714
  () =>
804
715
  commands.command(({ state }) => {
805
716
  const blockInfo = getBlockInfoFromSelection(state);
@@ -807,29 +718,12 @@ export const KeyboardShortcutsExtension = Extension.create<{
807
718
  const blockSpec =
808
719
  this.options.editor.schema.blockSpecs[blockInfo.blockNoteType];
809
720
 
810
- // NOTE: This likely doesn't work as intended - `blockSchema[type]`
811
- // holds the block *config* (type/propSchema/content), which carries
812
- // no `meta`, so `meta?.hardBreakShortcut` is always `undefined` and
813
- // this falls back to the default. It should read from the block
814
- // spec's implementation instead (i.e.
815
- // `editor.schema.blockSpecs[type].implementation.meta`), the way the
816
- // syntax-highlighting extension reads `meta.highlight`. Left as-is
817
- // for a follow-up pass.
818
- const blockHardBreakShortcut =
819
- blockSpec?.implementation?.meta?.hardBreakShortcut ??
820
- "shift+enter";
821
-
822
- if (blockHardBreakShortcut === "none") {
823
- return false;
824
- }
721
+ const keyboard = keyboardOf(blockInfo.block.node, state.doc);
825
722
 
826
723
  if (
827
- // If shortcut is not configured, or is configured as "shift+enter",
828
- // create a hard break for shift+enter, but not for enter.
829
- (blockHardBreakShortcut === "shift+enter" && withShift) ||
830
- // If shortcut is configured as "enter", create a hard break for
831
- // both enter and shift+enter.
832
- blockHardBreakShortcut === "enter"
724
+ // Enter as a line break makes Shift-Enter one too.
725
+ keyboard.enter === "line-break" ||
726
+ (withShift && keyboard.shiftEnter === "line-break")
833
727
  ) {
834
728
  // "plain" blocks (e.g. code/math/diagram source) hold text only
835
729
  // (their content is `text*`), which can't contain a `hardBreak`
@@ -859,23 +753,93 @@ export const KeyboardShortcutsExtension = Extension.create<{
859
753
 
860
754
  return false;
861
755
  }),
756
+ // If the block is empty and the last child of a block whose empty
757
+ // children exit at the end (`keyboard.emptyChildEnter:
758
+ // "exit-at-end"`, the default for layout blocks), moves the block out
759
+ // (double Enter exits the layout block). The block lands at the nearest enclosing position that
760
+ // accepts it. E.g. out of a column it skips the columnList, which
761
+ // holds only columns, and lands below it. Without this, Enter only
762
+ // ever creates new blocks within the layout block, so the cursor could
763
+ // never leave a trailing layout block. Shift+Enter still adds spacing
764
+ // inside a layout block. The first block of a body stays put: it is
765
+ // where the body begins, not a way out of it.
766
+ () =>
767
+ commands.command(({ state, tr, dispatch }) => {
768
+ const blockInfo = getBlockInfoFromSelection(state);
769
+ if (!blockInfo.hasContent) {
770
+ return false;
771
+ }
772
+
773
+ const selectionEmpty =
774
+ state.selection.anchor === state.selection.head;
775
+ const blockEmpty = blockInfo.isContentEmpty;
776
+ if (!selectionEmpty || !blockEmpty) {
777
+ return false;
778
+ }
779
+
780
+ const $pos = tr.doc.resolve(blockInfo.block.beforePos);
781
+ // Only fires on the layout block's last child.
782
+ if (tr.doc.resolve(blockInfo.block.afterPos).nodeAfter !== null) {
783
+ return false;
784
+ }
785
+
786
+ const owner = getParentBlockInfo(tr.doc, blockInfo.block.beforePos);
787
+ if (!owner) {
788
+ return false;
789
+ }
790
+ if (
791
+ keyboardOf(owner.block.node, tr.doc).emptyChildEnter !==
792
+ "exit-at-end"
793
+ ) {
794
+ return false;
795
+ }
796
+ // The first block of a body stays put: it is where the body
797
+ // begins, not a way out of it. (A layout block's own first child has
798
+ // no such role, so it may still leave.)
799
+ if ($pos.index() === 0 && owner.hasContent) {
800
+ return false;
801
+ }
802
+
803
+ const ownerAfterPos = ascendToInsertablePos(
804
+ tr.doc,
805
+ owner.block.afterPos,
806
+ state.schema.nodes["blockContainer"],
807
+ "after",
808
+ );
809
+ if (ownerAfterPos === undefined) {
810
+ return false;
811
+ }
812
+
813
+ if (dispatch) {
814
+ moveBlockOutAndPlaceCaret(tr, blockInfo.block, ownerAfterPos);
815
+ tr.scrollIntoView();
816
+ }
817
+
818
+ return true;
819
+ }),
862
820
  // Creates a new block and moves the selection to it if the current one is empty, while the selection is also
863
821
  // empty & at the start of the block.
864
822
  () =>
865
823
  commands.command(({ state, dispatch, tr }) => {
866
824
  const blockInfo = getBlockInfoFromSelection(state);
867
- if (!blockInfo.isBlockContainer) {
825
+ if (!blockInfo.hasContent) {
868
826
  return false;
869
827
  }
870
- const { bnBlock: blockContainer, blockContent } = blockInfo;
828
+ const { block: blockContainer } = blockInfo;
871
829
 
872
830
  const selectionAtBlockStart =
873
831
  state.selection.$anchor.parentOffset === 0;
874
832
  const selectionEmpty =
875
833
  state.selection.anchor === state.selection.head;
876
- const blockEmpty = blockContent.node.childCount === 0;
834
+ const blockEmpty = blockInfo.isContentEmpty;
877
835
 
878
- if (selectionAtBlockStart && selectionEmpty && blockEmpty) {
836
+ if (
837
+ selectionAtBlockStart &&
838
+ selectionEmpty &&
839
+ blockEmpty &&
840
+ keyboardOf(blockInfo.block.node, state.doc).enter !==
841
+ "into-children"
842
+ ) {
879
843
  const newBlockInsertionPos = blockContainer.afterPos;
880
844
  const newBlockContentPos = newBlockInsertionPos + 2;
881
845
 
@@ -889,7 +853,7 @@ export const KeyboardShortcutsExtension = Extension.create<{
889
853
  [
890
854
  state.schema.nodes["paragraph"].createAndFill() ||
891
855
  undefined,
892
- blockInfo.childContainer?.node,
856
+ blockInfo.children?.node,
893
857
  ].filter((node) => node !== undefined),
894
858
  )!;
895
859
 
@@ -902,10 +866,10 @@ export const KeyboardShortcutsExtension = Extension.create<{
902
866
 
903
867
  // Deletes old block's children, as they have been moved to
904
868
  // the new one.
905
- if (blockInfo.childContainer) {
869
+ if (blockInfo.children) {
906
870
  tr.delete(
907
- blockInfo.childContainer.beforePos,
908
- blockInfo.childContainer.afterPos,
871
+ blockInfo.children.beforePos,
872
+ blockInfo.children.afterPos,
909
873
  );
910
874
  }
911
875
  }
@@ -915,28 +879,129 @@ export const KeyboardShortcutsExtension = Extension.create<{
915
879
 
916
880
  return false;
917
881
  }),
882
+ // Enter at the start of non-empty content inserts an empty block above
883
+ // it: the same type when the block's splits keep their type (lists),
884
+ // a paragraph otherwise, with default props. The block itself, with
885
+ // its id, props (e.g. a checklist item's checked state) and children,
886
+ // stays where it is (#550).
887
+ () =>
888
+ commands.command(({ state, tr, dispatch }) => {
889
+ const blockInfo = getBlockInfoFromSelection(state);
890
+ if (
891
+ !blockInfo.hasContent ||
892
+ blockInfo.contentKind === "table" ||
893
+ !state.selection.empty ||
894
+ blockInfo.isContentEmpty ||
895
+ state.selection.from !== blockInfo.contentStart
896
+ ) {
897
+ return false;
898
+ }
899
+
900
+ if (dispatch) {
901
+ const contentType = keyboardOf(blockInfo.block.node, state.doc)
902
+ .splitKeepsType
903
+ ? blockInfo.content.node.type
904
+ : state.schema.nodes["paragraph"];
905
+ const newBlock = state.schema.nodes["blockContainer"].create(
906
+ undefined,
907
+ contentType.create(),
908
+ );
909
+ tr.insert(blockInfo.block.beforePos, newBlock).scrollIntoView();
910
+ }
911
+
912
+ return true;
913
+ }),
914
+ // Enter in the content of a block whose Enter goes into its children
915
+ // (`keyboard.enter: "into-children"`, e.g. an open toggle) starts its
916
+ // children rather than splitting the block in two: whatever follows
917
+ // the cursor becomes the first child, and the existing children stay
918
+ // where they are.
919
+ () =>
920
+ commands.command(({ state, tr, dispatch }) => {
921
+ const blockInfo = getBlockInfoFromSelection(state);
922
+ if (!blockInfo.hasContent) {
923
+ return false;
924
+ }
925
+
926
+ if (
927
+ keyboardOf(blockInfo.block.node, state.doc).enter !==
928
+ "into-children"
929
+ ) {
930
+ return false;
931
+ }
932
+ if (!state.selection.empty) {
933
+ return false;
934
+ }
935
+ if (
936
+ state.selection.from < blockInfo.contentStart ||
937
+ state.selection.from > blockInfo.contentEnd
938
+ ) {
939
+ return false;
940
+ }
941
+
942
+ if (dispatch) {
943
+ // Everything after the cursor moves into the new block, so
944
+ // splitting the title mid-way puts its tail at the top of the
945
+ // body instead of handing the body to a new sibling.
946
+ const tail = blockInfo.content.node.cut(
947
+ state.selection.from - blockInfo.contentStart,
948
+ );
949
+ const newBlock = state.schema.nodes["blockContainer"].create(
950
+ undefined,
951
+ state.schema.nodes["paragraph"].create(undefined, tail.content),
952
+ );
953
+
954
+ tr.delete(state.selection.from, blockInfo.contentEnd);
955
+
956
+ const body = getBlockInfoAt(
957
+ tr.doc,
958
+ blockInfo.block.beforePos,
959
+ ).children;
960
+ // Without a body yet, one is created around the new block.
961
+ const insertPos = body
962
+ ? body.childrenStart
963
+ : tr.mapping.map(blockInfo.content.afterPos);
964
+ tr.insert(
965
+ insertPos,
966
+ body
967
+ ? newBlock
968
+ : state.schema.nodes["blockGroup"].create(
969
+ undefined,
970
+ newBlock,
971
+ ),
972
+ )
973
+ .setSelection(
974
+ new TextSelection(tr.doc.resolve(insertPos + (body ? 2 : 3))),
975
+ )
976
+ .scrollIntoView();
977
+ }
978
+
979
+ return true;
980
+ }),
918
981
  // Splits the current block, moving content inside that's after the cursor to a new text block below. Also
919
982
  // deletes the selection beforehand, if it's not empty.
920
983
  () =>
921
984
  commands.command(({ state, chain }) => {
922
985
  const blockInfo = getBlockInfoFromSelection(state);
923
- if (!blockInfo.isBlockContainer) {
986
+ if (!blockInfo.hasContent) {
924
987
  return false;
925
988
  }
926
- const { blockContent } = blockInfo;
927
989
 
928
990
  const selectionAtBlockStart =
929
991
  state.selection.$anchor.parentOffset === 0;
930
- const blockEmpty = blockContent.node.childCount === 0;
992
+ const blockEmpty = blockInfo.isContentEmpty;
931
993
 
932
994
  if (!blockEmpty) {
995
+ const keyboard = keyboardOf(blockInfo.block.node, state.doc);
996
+ const keepType = selectionAtBlockStart || keyboard.splitKeepsType;
933
997
  chain()
934
998
  .deleteSelection()
935
999
  .command(
936
1000
  splitBlockCommand(
937
1001
  state.selection.from,
1002
+ keepType,
938
1003
  selectionAtBlockStart,
939
- selectionAtBlockStart,
1004
+ keyboard.splitKeepsChildren,
940
1005
  ),
941
1006
  )
942
1007
  .scrollIntoView()
@@ -950,42 +1015,27 @@ export const KeyboardShortcutsExtension = Extension.create<{
950
1015
  ]);
951
1016
  };
952
1017
 
1018
+ const options = this.options;
1019
+ function handleTab(shift: boolean) {
1020
+ const { editor, tabBehavior } = options;
1021
+ if (
1022
+ tabBehavior !== "prefer-indent" &&
1023
+ (editor.getExtension(FormattingToolbarExtension)?.store.state ||
1024
+ editor.getExtension(FilePanelExtension)?.store.state !== undefined)
1025
+ ) {
1026
+ // Let the browser navigate into and out of an open toolbar.
1027
+ return false;
1028
+ }
1029
+ return shift ? unnestBlock(editor) : nestBlock(editor);
1030
+ }
1031
+
953
1032
  return {
954
1033
  Backspace: handleBackspace,
955
1034
  Delete: handleDelete,
956
1035
  Enter: () => handleEnter(),
957
1036
  "Shift-Enter": () => handleEnter(true),
958
- // Always returning true for tab key presses ensures they're not captured by the browser. Otherwise, they blur the
959
- // editor since the browser will try to use tab for keyboard navigation.
960
- Tab: () => {
961
- if (
962
- this.options.tabBehavior !== "prefer-indent" &&
963
- (this.options.editor.getExtension(FormattingToolbarExtension)?.store
964
- .state ||
965
- this.options.editor.getExtension(FilePanelExtension)?.store
966
- .state !== undefined)
967
- // TODO need to check if the link toolbar is open or another alternative entirely
968
- ) {
969
- // don't handle tabs if a toolbar is shown, so we can tab into / out of it
970
- return false;
971
- }
972
- return nestBlock(this.options.editor);
973
- },
974
- "Shift-Tab": () => {
975
- if (
976
- this.options.tabBehavior !== "prefer-indent" &&
977
- (this.options.editor.getExtension(FormattingToolbarExtension)?.store
978
- .state ||
979
- this.options.editor.getExtension(FilePanelExtension)?.store
980
- .state !== undefined)
981
- // TODO need to check if the link toolbar is open or another alternative entirely
982
- // other menu types?
983
- ) {
984
- // don't handle tabs if a toolbar is shown, so we can tab into / out of it
985
- return false;
986
- }
987
- return unnestBlock(this.options.editor);
988
- },
1037
+ Tab: () => handleTab(false),
1038
+ "Shift-Tab": () => handleTab(true),
989
1039
  "Shift-Mod-ArrowUp": () => {
990
1040
  this.options.editor.moveBlocksUp();
991
1041
  return true;
@@ -997,6 +1047,70 @@ export const KeyboardShortcutsExtension = Extension.create<{
997
1047
  "Mod-z": () => this.options.editor.undo(),
998
1048
  "Mod-y": () => this.options.editor.redo(),
999
1049
  "Shift-Mod-z": () => this.options.editor.redo(),
1050
+ "Mod-a": () => {
1051
+ const view = this.editor.view;
1052
+ const { doc, selection, tr } = view.state;
1053
+
1054
+ // By default, the first `Mod-a` selects the current block's content,
1055
+ // and any subsequent `Mod-a` expands the selection to the whole
1056
+ // document. We use `TextSelection`s rather than an `AllSelection` for the
1057
+ // whole-document case as the latter creates from/to positions outside a
1058
+ // block, causing errors when calling e.g. `getBlock`.
1059
+ const wholeDocSelection = TextSelection.between(
1060
+ Selection.atStart(doc).$from,
1061
+ Selection.atEnd(doc).$to,
1062
+ );
1063
+
1064
+ if (this.options.selectAllBehavior === "document") {
1065
+ view.dispatch(tr.setSelection(wholeDocSelection));
1066
+ return true;
1067
+ }
1068
+
1069
+ // Selection covering just the current block's content. `between` snaps
1070
+ // to the nearest inline positions inside the block, so it also handles
1071
+ // blocks whose content isn't directly inline - e.g. table blocks, where
1072
+ // it spans from the first cell to the last. Blocks without any inline
1073
+ // content (e.g. images) are ignored, as `between` would then spill
1074
+ // outside the block, and select-all falls through to the whole document.
1075
+ let blockSelection: Selection | undefined;
1076
+ const blockInfo = getBlockInfoFromSelection(view.state);
1077
+ if (blockInfo.hasContent) {
1078
+ const contentFrom = blockInfo.contentStart;
1079
+ const contentTo = blockInfo.contentEnd;
1080
+ const candidate = TextSelection.between(
1081
+ doc.resolve(contentFrom),
1082
+ doc.resolve(contentTo),
1083
+ );
1084
+
1085
+ if (
1086
+ !candidate.empty &&
1087
+ candidate.from >= contentFrom &&
1088
+ candidate.to <= contentTo
1089
+ ) {
1090
+ blockSelection = candidate;
1091
+ }
1092
+ }
1093
+
1094
+ // Expands to the whole document when there's no selectable block content
1095
+ // to select first, when the selection already extends beyond the current
1096
+ // block, or when the current block's content is already fully selected.
1097
+ const selectWholeDoc =
1098
+ !blockSelection ||
1099
+ selection.from < blockSelection.from ||
1100
+ selection.to > blockSelection.to ||
1101
+ (selection.from === blockSelection.from &&
1102
+ selection.to === blockSelection.to);
1103
+
1104
+ if (blockSelection && !selectWholeDoc) {
1105
+ tr.setSelection(blockSelection).scrollIntoView();
1106
+ } else {
1107
+ tr.setSelection(wholeDocSelection);
1108
+ }
1109
+
1110
+ view.dispatch(tr);
1111
+
1112
+ return true;
1113
+ },
1000
1114
  };
1001
1115
  },
1002
1116
  });