@blocknote/core 0.54.2 → 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.
- package/dist/BlockNoteExtension-DjEkXkR5.cjs +2 -0
- package/dist/BlockNoteExtension-DjEkXkR5.cjs.map +1 -0
- package/dist/{BlockNoteExtension-CbvDA0F7.js → BlockNoteExtension-TsTGtIeX.js} +34 -27
- package/dist/BlockNoteExtension-TsTGtIeX.js.map +1 -0
- package/dist/{UserStore-mj3fXW4D.cjs → UserStore-CTVzVGh-.cjs} +2 -2
- package/dist/{UserStore-mj3fXW4D.cjs.map → UserStore-CTVzVGh-.cjs.map} +1 -1
- package/dist/{UserStore-C4TzkGEn.js → UserStore-OZJP3K8T.js} +2 -2
- package/dist/{UserStore-C4TzkGEn.js.map → UserStore-OZJP3K8T.js.map} +1 -1
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -6
- package/dist/blocks-COVwe5Cf.cjs +12 -0
- package/dist/blocks-COVwe5Cf.cjs.map +1 -0
- package/dist/{blocks-Dol85hpH.js → blocks-COYcDVg7.js} +1577 -1155
- package/dist/blocks-COYcDVg7.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +69 -43
- package/dist/comments.js.map +1 -1
- package/dist/{en-uzHzj6eH.js → en-Ch-vvt5e.js} +40 -3
- package/dist/en-Ch-vvt5e.js.map +1 -0
- package/dist/en-N5lu0-j8.cjs +2 -0
- package/dist/en-N5lu0-j8.cjs.map +1 -0
- package/dist/extensions-BbM81hHa.js +3069 -0
- package/dist/extensions-BbM81hHa.js.map +1 -0
- package/dist/extensions-D_WkAfSt.cjs +58 -0
- package/dist/extensions-D_WkAfSt.cjs.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +4 -4
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +859 -45
- package/dist/locales.js.map +1 -1
- package/dist/src-4OQT3z5S.cjs +23 -0
- package/dist/src-4OQT3z5S.cjs.map +1 -0
- package/dist/src-BmLsLZfE.js +3491 -0
- package/dist/src-BmLsLZfE.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +1 -1
- package/dist/y.cjs.map +1 -1
- package/dist/y.js +1284 -554
- package/dist/y.js.map +1 -1
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +189 -148
- package/dist/yjs.js.map +1 -1
- package/package.json +18 -18
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +45 -6
- package/src/api/blockManipulation/commands/insertBlocks/insertPlacement.test.ts +217 -0
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +113 -9
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +151 -163
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +47 -31
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +122 -181
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +256 -0
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +80 -40
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +71 -0
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +39 -31
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +221 -8
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +40 -8
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +272 -40
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +138 -117
- package/src/api/blockManipulation/getBlock/getBlock.ts +4 -11
- package/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.ts +173 -0
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.ts +293 -0
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.ts +145 -0
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.ts +783 -0
- package/src/api/blockManipulation/layoutBlocks/plainBlocks.test.ts +180 -0
- package/src/api/blockManipulation/layoutBlocks/titledBlocks.test.ts +365 -0
- package/src/api/blockManipulation/selections/selection.ts +20 -53
- package/src/api/blockManipulation/selections/textCursorPosition.ts +17 -72
- package/src/api/blockManipulation/setupTestEnv.ts +38 -6
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +4 -4
- package/src/api/clipboard/toClipboard/copyExtension.ts +3 -3
- package/src/api/combineTransactionSteps.ts +22 -0
- package/src/api/exporters/html/externalHTMLExporter.ts +1 -1
- package/src/api/exporters/html/internalHTMLSerializer.ts +4 -4
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +111 -36
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +51 -21
- package/src/api/exporters/markdown/htmlToMarkdown.ts +12 -1
- package/src/api/exporters/markdown/markdownExporter.ts +1 -1
- package/src/api/getBlockInfoFromPos.test.ts +428 -3
- package/src/api/getBlockInfoFromPos.ts +531 -129
- package/src/api/getBlocksChangedByTransaction.test.ts +7 -7
- package/src/api/getBlocksChangedByTransaction.ts +3 -3
- package/src/api/{getChangedRange.ts → getChangedRangeWithAttrs.ts} +2 -2
- package/src/api/getChangedRanges.test.ts +391 -0
- package/src/api/getChangedRanges.ts +368 -0
- package/src/api/nodeConversions/blockToNode.ts +44 -16
- package/src/api/nodeConversions/fragmentToBlocks.ts +29 -44
- package/src/api/nodeConversions/nodeToBlock.ts +120 -68
- package/src/api/nodeUtil.ts +1 -1
- package/src/api/parsers/markdown/autolink.ts +23 -0
- package/src/api/parsers/markdown/markdownToHtml.ts +115 -11
- package/src/blocks/Code/block.test.ts +4 -4
- package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +6 -1
- package/src/blocks/Heading/block.ts +54 -15
- package/src/blocks/ListItem/BulletListItem/block.ts +6 -4
- package/src/blocks/ListItem/CheckListItem/block.test.ts +2 -2
- package/src/blocks/ListItem/CheckListItem/block.ts +6 -4
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +14 -17
- package/src/blocks/ListItem/NumberedListItem/block.ts +6 -4
- package/src/blocks/ListItem/ToggleListItem/block.ts +23 -12
- package/src/blocks/Table/block.ts +2 -10
- package/src/blocks/ToggleWrapper/createToggleFrame.ts +126 -0
- package/src/blocks/ToggleWrapper/toggleBlocks.browser.test.ts +1056 -0
- package/src/blocks/defaultBlockTypeItems.test.ts +70 -0
- package/src/blocks/defaultBlockTypeItems.ts +99 -0
- package/src/blocks/defaultBlocks.test.ts +67 -0
- package/src/blocks/defaultBlocks.ts +7 -1
- package/src/blocks/index.ts +2 -1
- package/src/comments/CommentEditorSubmitExtension.test.ts +141 -0
- package/src/comments/CommentEditorSubmitExtension.ts +56 -0
- package/src/comments/extension.ts +8 -0
- package/src/comments/index.ts +1 -0
- package/src/editor/Block.css +286 -154
- package/src/editor/BlockNoteEditor.node.test.ts +35 -0
- package/src/editor/BlockNoteEditor.test.ts +2 -2
- package/src/editor/BlockNoteEditor.ts +165 -50
- package/src/editor/BlockNoteExtension.ts +11 -6
- package/src/editor/blockColors.browser.test.ts +127 -0
- package/src/editor/editor.css +60 -0
- package/src/editor/managers/BlockManager.ts +4 -3
- package/src/editor/managers/EventManager.browser.test.ts +334 -0
- package/src/editor/managers/EventManager.ts +128 -31
- package/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.ts +45 -0
- package/src/editor/managers/ExtensionManager/ExtensionManager.node.test.ts +209 -0
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +88 -1
- package/src/editor/managers/ExtensionManager/extensions.ts +10 -1
- package/src/editor/managers/ExtensionManager/index.ts +165 -75
- package/src/editor/managers/StateManager.ts +14 -4
- package/src/editor/managers/StyleManager.browser.test.ts +122 -0
- package/src/editor/managers/StyleManager.test.ts +98 -0
- package/src/editor/managers/StyleManager.ts +31 -15
- package/src/editor/managers/index.ts +1 -0
- package/src/editor/transformPasted.ts +14 -13
- package/src/exporter/Exporter.test.ts +70 -1
- package/src/exporter/Exporter.ts +34 -4
- package/src/exporter/mapping.ts +41 -10
- package/src/extensions/DropCursor/DropCursor.ts +119 -6
- package/src/extensions/DropCursor/dropIntoChildren.ts +80 -0
- package/src/extensions/FormattingToolbar/FormattingToolbar.ts +29 -0
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.ts +190 -0
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +41 -4
- package/src/extensions/Placeholder/Placeholder.test.ts +23 -0
- package/src/extensions/Placeholder/Placeholder.ts +8 -7
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +36 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +8 -4
- package/src/extensions/ReadOnly/ReadOnly.test.ts +181 -0
- package/src/extensions/ReadOnly/ReadOnly.ts +73 -0
- package/src/extensions/SideMenu/SideMenu.ts +401 -749
- package/src/extensions/SideMenu/blockDropHandling.ts +372 -0
- package/src/extensions/SideMenu/blockGeometry.browser.test.ts +148 -0
- package/src/extensions/SideMenu/blockGeometry.test.ts +46 -0
- package/src/extensions/SideMenu/blockGeometry.ts +53 -0
- package/src/extensions/SideMenu/dragging.ts +19 -32
- package/src/extensions/SideMenu/sideMenuHover.test.ts +36 -0
- package/src/extensions/SideMenu/sideMenuHover.ts +270 -0
- package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +5 -4
- package/src/extensions/SuggestionMenu/SuggestionMenu.ts +10 -1
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +36 -136
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +14 -4
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +1 -1
- package/src/extensions/SyntaxHighlighting/shiki.ts +1 -1
- package/src/extensions/TableHandles/TableHandles.browser.test.ts +3 -1
- package/src/extensions/TableHandles/TableHandles.ts +4 -6
- package/src/extensions/Versioning/Versioning.browser.test.ts +151 -0
- package/src/extensions/Versioning/Versioning.node.test.ts +177 -0
- package/src/extensions/Versioning/Versioning.ts +145 -612
- package/src/extensions/Versioning/__test__/result.ts +12 -0
- package/src/extensions/Versioning/comparison.test.ts +40 -0
- package/src/extensions/Versioning/createVersioning.test.ts +867 -0
- package/src/extensions/Versioning/createVersioning.ts +499 -0
- package/src/extensions/Versioning/formatVersionDate.ts +24 -0
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +533 -430
- package/src/extensions/Versioning/inMemoryVersioning.ts +246 -251
- package/src/extensions/Versioning/index.ts +4 -0
- package/src/extensions/Versioning/scrollScheduling.test.ts +51 -0
- package/src/extensions/Versioning/scrollToFirstChange.test.ts +320 -0
- package/src/extensions/Versioning/scrollToFirstChange.ts +139 -0
- package/src/extensions/Versioning/types.ts +219 -0
- package/src/extensions/Versioning/versioningState.ts +154 -0
- package/src/extensions/blockDOM.browser.test.ts +102 -0
- package/src/extensions/blockDOM.test.ts +178 -0
- package/src/extensions/blockDOM.ts +135 -0
- package/src/extensions/index.ts +2 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +1719 -53
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +645 -531
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.ts +152 -0
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +4 -9
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +10 -24
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +22 -19
- package/src/fonts/inter.browser.test.ts +57 -0
- package/src/fonts/inter.css +111 -0
- package/src/i18n/locales/ar.ts +33 -0
- package/src/i18n/locales/de.ts +33 -0
- package/src/i18n/locales/en.ts +33 -0
- package/src/i18n/locales/es.ts +33 -0
- package/src/i18n/locales/fa.ts +33 -0
- package/src/i18n/locales/fr.ts +33 -0
- package/src/i18n/locales/he.ts +33 -0
- package/src/i18n/locales/hr.ts +33 -0
- package/src/i18n/locales/is.ts +33 -0
- package/src/i18n/locales/it.ts +33 -0
- package/src/i18n/locales/ja.ts +33 -0
- package/src/i18n/locales/ko.ts +33 -0
- package/src/i18n/locales/nl.ts +33 -0
- package/src/i18n/locales/no.ts +33 -0
- package/src/i18n/locales/pl.ts +33 -0
- package/src/i18n/locales/pt.ts +33 -0
- package/src/i18n/locales/ru.ts +33 -0
- package/src/i18n/locales/sk.ts +33 -0
- package/src/i18n/locales/uk.ts +33 -0
- package/src/i18n/locales/uz.ts +33 -0
- package/src/i18n/locales/vi.ts +33 -0
- package/src/i18n/locales/zh-tw.ts +33 -0
- package/src/i18n/locales/zh.ts +33 -0
- package/src/index.ts +14 -3
- package/src/pm-nodes/BlockContainer.test.ts +101 -0
- package/src/pm-nodes/BlockContainer.ts +110 -1
- package/src/pm-nodes/BlockGroup.ts +2 -1
- package/src/pm-nodes/README.md +2 -0
- package/src/schema/blocks/children.test.ts +288 -0
- package/src/schema/blocks/children.ts +136 -0
- package/src/schema/blocks/createSpec.browser.test.ts +176 -0
- package/src/schema/blocks/createSpec.test.ts +231 -0
- package/src/schema/blocks/createSpec.ts +493 -267
- package/src/schema/blocks/frame.test.ts +112 -0
- package/src/schema/blocks/frame.ts +337 -0
- package/src/schema/blocks/internal.ts +50 -17
- package/src/schema/blocks/keyboard.ts +154 -0
- package/src/schema/blocks/layoutBlockAttributes.ts +29 -0
- package/src/schema/blocks/meta.test.ts +53 -0
- package/src/schema/blocks/meta.ts +35 -0
- package/src/schema/blocks/renderFrame.test.ts +691 -0
- package/src/schema/blocks/types.ts +285 -21
- package/src/schema/blocks/validateChildren.ts +156 -0
- package/src/schema/dataAttributes.test.ts +72 -0
- package/src/schema/dataAttributes.ts +69 -0
- package/src/schema/index.ts +3 -0
- package/src/schema/inlineContent/internal.ts +7 -12
- package/src/schema/markGroups.ts +34 -2
- package/src/schema/schema.ts +8 -1
- package/src/user/userColors.test.ts +108 -0
- package/src/user/userColors.ts +42 -13
- package/src/util/browser.ts +24 -0
- package/src/y/comments/RESTYjsThreadStore.ts +1 -1
- package/src/y/comments/YjsThreadStore.test.ts +1 -1
- package/src/y/comments/YjsThreadStore.ts +27 -27
- package/src/y/comments/YjsThreadStoreBase.ts +2 -2
- package/src/y/comments/yjsHelpers.ts +11 -11
- package/src/y/extensions/AttributionExtension.test.ts +271 -2
- package/src/y/extensions/AttributionExtension.ts +146 -123
- package/src/y/extensions/DiffVersioningExtension.test.ts +67 -18
- package/src/y/extensions/DiffVersioningExtension.ts +95 -123
- package/src/y/extensions/EmptyDocBinding.test.ts +282 -0
- package/src/y/extensions/ForkYDoc.node.test.ts +77 -0
- package/src/y/extensions/ForkYDoc.test.ts +93 -2
- package/src/y/extensions/ForkYDoc.ts +22 -13
- package/src/y/extensions/History.test.ts +125 -0
- package/src/y/extensions/RelativePositionMapping.test.ts +35 -0
- package/src/y/extensions/RelativePositionMapping.ts +7 -11
- package/src/y/extensions/Versioning.node.test.ts +126 -0
- package/src/y/extensions/Versioning.test.ts +110 -401
- package/src/y/extensions/Versioning.ts +66 -107
- package/src/y/extensions/YAttributionMarks.ts +111 -9
- package/src/y/extensions/YCursorPlugin.ts +3 -0
- package/src/y/extensions/YSync.node.test.ts +75 -0
- package/src/y/extensions/YSync.ts +76 -4
- package/src/y/extensions/YSyncRemount.test.ts +99 -0
- package/src/y/extensions/blockMatchNodes.ts +20 -29
- package/src/y/extensions/index.ts +10 -26
- package/src/y/extensions/legacyYjsDocBinding.test.ts +652 -0
- package/src/y/extensions/nestingChanges.test.ts +326 -0
- package/src/y/extensions/persistentBlockGroups.test.ts +1709 -0
- package/src/y/extensions/persistentBlockGroups.ts +953 -0
- package/src/y/extensions/snapshotCodec.test.ts +105 -0
- package/src/y/extensions/snapshotCodec.ts +39 -0
- package/src/y/extensions/snapshotPreview.test.ts +201 -0
- package/src/y/extensions/snapshotPreview.ts +292 -0
- package/src/y/extensions/tableReshape.test.ts +121 -0
- package/src/y/extensions/v1BindingSnapshotDiff.test.ts +121 -0
- package/src/y/extensions/versionDiffAttribution.test.ts +944 -0
- package/src/y/extensions/versionDiffPerformance.test.ts +101 -0
- package/src/y/index.ts +1 -0
- package/src/y/utils.test.ts +289 -22
- package/src/y/utils.ts +167 -43
- package/src/y/versioning/__test__/fixtures/activity-all-after.json +5 -5
- package/src/y/versioning/__test__/fixtures/activity-all.json +3 -3
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +2 -2
- package/src/y/versioning/__test__/yhub.test.ts +902 -721
- package/src/y/versioning/index.ts +6 -1
- package/src/y/versioning/yhub.ts +316 -603
- package/src/y/versioning/yhubClient.ts +345 -0
- package/src/yjs/comments/RESTYjsThreadStore.test.ts +10 -0
- package/src/yjs/extensions/FixUpSchema.ts +11 -0
- package/src/yjs/extensions/ForkYDoc.browser.test.ts +84 -0
- package/src/yjs/extensions/ForkYDoc.node.test.ts +231 -0
- package/src/yjs/extensions/ForkYDoc.test.ts +68 -1
- package/src/yjs/extensions/ForkYDoc.ts +57 -39
- package/src/yjs/extensions/Versioning.test.ts +345 -530
- package/src/yjs/extensions/Versioning.ts +111 -68
- package/src/yjs/extensions/index.ts +1 -1
- package/src/yjs/index.ts +4 -0
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +2 -1
- package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +24 -24
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +3 -2
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +1 -1
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -2
- package/types/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.d.ts +34 -0
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.d.ts +1 -0
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.d.ts +460 -0
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/layoutBlocks/plainBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/layoutBlocks/titledBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +15 -69
- package/types/src/api/combineTransactionSteps.d.ts +12 -0
- package/types/src/api/getBlockInfoFromPos.d.ts +218 -44
- package/types/src/api/{getChangedRange.d.ts → getChangedRangeWithAttrs.d.ts} +1 -1
- package/types/src/api/getChangedRanges.d.ts +23 -0
- package/types/src/api/getChangedRanges.test.d.ts +1 -0
- package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +0 -3
- package/types/src/api/parsers/markdown/autolink.d.ts +5 -0
- package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +4 -0
- package/types/src/blocks/ToggleWrapper/createToggleFrame.d.ts +29 -0
- package/types/src/blocks/ToggleWrapper/toggleBlocks.browser.test.d.ts +1 -0
- package/types/src/blocks/defaultBlockTypeItems.d.ts +37 -0
- package/types/src/blocks/defaultBlockTypeItems.test.d.ts +1 -0
- package/types/src/blocks/defaultBlocks.test.d.ts +1 -0
- package/types/src/blocks/index.d.ts +2 -1
- package/types/src/comments/CommentEditorSubmitExtension.d.ts +19 -0
- package/types/src/comments/CommentEditorSubmitExtension.test.d.ts +1 -0
- package/types/src/comments/extension.d.ts +7 -0
- package/types/src/comments/index.d.ts +1 -0
- package/types/src/editor/BlockNoteEditor.d.ts +88 -27
- package/types/src/editor/BlockNoteEditor.node.test.d.ts +1 -0
- package/types/src/editor/BlockNoteExtension.d.ts +3 -0
- package/types/src/editor/blockColors.browser.test.d.ts +1 -0
- package/types/src/editor/managers/BlockManager.d.ts +4 -3
- package/types/src/editor/managers/EventManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/EventManager.d.ts +55 -0
- package/types/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/ExtensionManager/ExtensionManager.node.test.d.ts +1 -0
- package/types/src/editor/managers/ExtensionManager/index.d.ts +15 -3
- package/types/src/editor/managers/StateManager.d.ts +1 -1
- package/types/src/editor/managers/StyleManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/StyleManager.d.ts +4 -2
- package/types/src/editor/managers/StyleManager.test.d.ts +1 -0
- package/types/src/editor/managers/index.d.ts +1 -0
- package/types/src/editor/transformPasted.d.ts +1 -1
- package/types/src/exporter/Exporter.d.ts +11 -4
- package/types/src/exporter/mapping.d.ts +13 -1
- package/types/src/extensions/DropCursor/DropCursor.d.ts +1 -1
- package/types/src/extensions/DropCursor/dropIntoChildren.d.ts +38 -0
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.d.ts +1 -1
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.d.ts +1 -0
- package/types/src/extensions/Placeholder/Placeholder.test.d.ts +1 -0
- package/types/src/extensions/ReadOnly/ReadOnly.d.ts +21 -0
- package/types/src/extensions/ReadOnly/ReadOnly.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/SideMenu.d.ts +49 -88
- package/types/src/extensions/SideMenu/blockDropHandling.d.ts +11 -0
- package/types/src/extensions/SideMenu/blockGeometry.browser.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/blockGeometry.d.ts +22 -0
- package/types/src/extensions/SideMenu/blockGeometry.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/dragging.d.ts +0 -4
- package/types/src/extensions/SideMenu/sideMenuHover.d.ts +58 -0
- package/types/src/extensions/SideMenu/sideMenuHover.test.d.ts +1 -0
- package/types/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.d.ts +3 -0
- package/types/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.d.ts +1 -0
- package/types/src/extensions/Versioning/Versioning.browser.test.d.ts +1 -0
- package/types/src/extensions/Versioning/Versioning.d.ts +34 -311
- package/types/src/extensions/Versioning/Versioning.node.test.d.ts +1 -0
- package/types/src/extensions/Versioning/__test__/result.d.ts +3 -0
- package/types/src/extensions/Versioning/comparison.test.d.ts +1 -0
- package/types/src/extensions/Versioning/createVersioning.d.ts +32 -0
- package/types/src/extensions/Versioning/createVersioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/formatVersionDate.d.ts +7 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +64 -36
- package/types/src/extensions/Versioning/index.d.ts +4 -0
- package/types/src/extensions/Versioning/scrollScheduling.test.d.ts +1 -0
- package/types/src/extensions/Versioning/scrollToFirstChange.d.ts +18 -0
- package/types/src/extensions/Versioning/scrollToFirstChange.test.d.ts +1 -0
- package/types/src/extensions/Versioning/types.d.ts +239 -0
- package/types/src/extensions/Versioning/versioningState.d.ts +43 -0
- package/types/src/extensions/blockDOM.browser.test.d.ts +1 -0
- package/types/src/extensions/blockDOM.d.ts +37 -0
- package/types/src/extensions/blockDOM.test.d.ts +1 -0
- package/types/src/extensions/index.d.ts +2 -0
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +1 -0
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +3 -0
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.d.ts +1 -0
- package/types/src/fonts/inter.browser.test.d.ts +2 -0
- package/types/src/i18n/locales/en.d.ts +33 -0
- package/types/src/i18n/locales/fa.d.ts +33 -0
- package/types/src/i18n/locales/sk.d.ts +33 -0
- package/types/src/index.d.ts +7 -3
- package/types/src/pm-nodes/BlockContainer.d.ts +6 -0
- package/types/src/pm-nodes/BlockContainer.test.d.ts +1 -0
- package/types/src/schema/blocks/children.d.ts +39 -0
- package/types/src/schema/blocks/children.test.d.ts +1 -0
- package/types/src/schema/blocks/createSpec.browser.test.d.ts +1 -0
- package/types/src/schema/blocks/createSpec.d.ts +13 -0
- package/types/src/schema/blocks/frame.d.ts +109 -0
- package/types/src/schema/blocks/frame.test.d.ts +1 -0
- package/types/src/schema/blocks/internal.d.ts +6 -0
- package/types/src/schema/blocks/keyboard.d.ts +111 -0
- package/types/src/schema/blocks/layoutBlockAttributes.d.ts +9 -0
- package/types/src/schema/blocks/meta.d.ts +14 -0
- package/types/src/schema/blocks/meta.test.d.ts +1 -0
- package/types/src/schema/blocks/renderFrame.test.d.ts +1 -0
- package/types/src/schema/blocks/types.d.ts +228 -15
- package/types/src/schema/blocks/validateChildren.d.ts +5 -0
- package/types/src/schema/dataAttributes.d.ts +19 -0
- package/types/src/schema/dataAttributes.test.d.ts +1 -0
- package/types/src/schema/index.d.ts +3 -0
- package/types/src/schema/markGroups.d.ts +8 -0
- package/types/src/user/userColors.d.ts +24 -3
- package/types/src/user/userColors.test.d.ts +1 -0
- package/types/src/util/browser.d.ts +2 -0
- package/types/src/y/comments/RESTYjsThreadStore.d.ts +1 -1
- package/types/src/y/comments/YjsThreadStore.d.ts +1 -1
- package/types/src/y/comments/YjsThreadStoreBase.d.ts +2 -2
- package/types/src/y/comments/yjsHelpers.d.ts +5 -5
- package/types/src/y/extensions/AttributionExtension.d.ts +19 -21
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +9 -4
- package/types/src/y/extensions/EmptyDocBinding.test.d.ts +1 -0
- package/types/src/y/extensions/ForkYDoc.d.ts +3 -1
- package/types/src/y/extensions/ForkYDoc.node.test.d.ts +1 -0
- package/types/src/y/extensions/History.test.d.ts +1 -0
- package/types/src/y/extensions/Versioning.d.ts +4 -15
- package/types/src/y/extensions/Versioning.node.test.d.ts +1 -0
- package/types/src/y/extensions/YAttributionMarks.d.ts +13 -2
- package/types/src/y/extensions/YCursorPlugin.d.ts +1 -0
- package/types/src/y/extensions/YSync.d.ts +4 -18
- package/types/src/y/extensions/YSync.node.test.d.ts +1 -0
- package/types/src/y/extensions/YSyncRemount.test.d.ts +1 -0
- package/types/src/y/extensions/blockMatchNodes.d.ts +0 -22
- package/types/src/y/extensions/index.d.ts +27 -44
- package/types/src/y/extensions/legacyYjsDocBinding.test.d.ts +1 -0
- package/types/src/y/extensions/nestingChanges.test.d.ts +1 -0
- package/types/src/y/extensions/persistentBlockGroups.d.ts +189 -0
- package/types/src/y/extensions/persistentBlockGroups.test.d.ts +1 -0
- package/types/src/y/extensions/snapshotCodec.d.ts +13 -0
- package/types/src/y/extensions/snapshotCodec.test.d.ts +1 -0
- package/types/src/y/extensions/snapshotPreview.d.ts +21 -0
- package/types/src/y/extensions/snapshotPreview.test.d.ts +1 -0
- package/types/src/y/extensions/tableReshape.test.d.ts +1 -0
- package/types/src/y/extensions/v1BindingSnapshotDiff.test.d.ts +1 -0
- package/types/src/y/extensions/versionDiffAttribution.test.d.ts +1 -0
- package/types/src/y/extensions/versionDiffPerformance.test.d.ts +1 -0
- package/types/src/y/index.d.ts +1 -0
- package/types/src/y/utils.d.ts +39 -19
- package/types/src/y/versioning/index.d.ts +1 -1
- package/types/src/y/versioning/yhub.d.ts +69 -86
- package/types/src/y/versioning/yhubClient.d.ts +67 -0
- package/types/src/yjs/extensions/ForkYDoc.browser.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +2 -0
- package/types/src/yjs/extensions/ForkYDoc.node.test.d.ts +1 -0
- package/types/src/yjs/extensions/Versioning.d.ts +36 -22
- package/types/src/yjs/extensions/index.d.ts +2 -1
- package/types/src/yjs/index.d.ts +1 -0
- package/dist/BlockNoteExtension-BJCLnwrE.cjs +0 -2
- package/dist/BlockNoteExtension-BJCLnwrE.cjs.map +0 -1
- package/dist/BlockNoteExtension-CbvDA0F7.js.map +0 -1
- package/dist/blocks-CTB_5Vyj.cjs +0 -12
- package/dist/blocks-CTB_5Vyj.cjs.map +0 -1
- package/dist/blocks-Dol85hpH.js.map +0 -1
- package/dist/en-BuzSuuTq.cjs +0 -2
- package/dist/en-BuzSuuTq.cjs.map +0 -1
- package/dist/en-uzHzj6eH.js.map +0 -1
- package/dist/extensions-B7Rsp_Ft.cjs +0 -58
- package/dist/extensions-B7Rsp_Ft.cjs.map +0 -1
- package/dist/extensions-D6JcJCwd.js +0 -2138
- package/dist/extensions-D6JcJCwd.js.map +0 -1
- package/dist/src-Buuo5l7X.js +0 -3317
- package/dist/src-Buuo5l7X.js.map +0 -1
- package/dist/src-C54Ok9E0.cjs +0 -23
- package/dist/src-C54Ok9E0.cjs.map +0 -1
- package/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.ts +0 -173
- package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +0 -63
- package/src/blocks/ToggleWrapper/createToggleWrapper.ts +0 -197
- package/src/blocks/utils/listItemEnterHandler.ts +0 -43
- package/src/extensions/Versioning/Versioning.test.ts +0 -435
- package/src/extensions/getDraggableBlockFromElement.ts +0 -19
- package/types/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.d.ts +0 -32
- package/types/src/blocks/ListItem/ListItemKeyboardShortcuts.d.ts +0 -2
- package/types/src/blocks/ToggleWrapper/createToggleWrapper.d.ts +0 -15
- package/types/src/blocks/utils/listItemEnterHandler.d.ts +0 -2
- package/types/src/extensions/getDraggableBlockFromElement.d.ts +0 -5
- /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 {
|
|
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 {
|
|
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
|
-
|
|
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
|
-
//
|
|
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.
|
|
117
|
+
if (!blockInfo.hasContent) {
|
|
49
118
|
return false;
|
|
50
119
|
}
|
|
51
120
|
|
|
52
121
|
const selectionAtBlockStart =
|
|
53
|
-
state.selection.from === blockInfo.
|
|
54
|
-
|
|
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
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
141
|
+
return commands.command(
|
|
142
|
+
updateBlockCommand(blockInfo.block.beforePos, resetsTo as any),
|
|
143
|
+
);
|
|
89
144
|
}),
|
|
90
|
-
// Merges
|
|
91
|
-
//
|
|
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.
|
|
150
|
+
if (!blockInfo.hasContent) {
|
|
96
151
|
return false;
|
|
97
152
|
}
|
|
98
|
-
const {
|
|
153
|
+
const { block: blockContainer } = blockInfo;
|
|
99
154
|
|
|
100
|
-
const
|
|
155
|
+
const prevSibling = getPrevBlockInfo(
|
|
101
156
|
state.doc,
|
|
102
|
-
blockInfo.
|
|
157
|
+
blockInfo.block.beforePos,
|
|
103
158
|
);
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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 ===
|
|
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
|
-
//
|
|
131
|
-
//
|
|
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 (
|
|
188
|
+
if (
|
|
189
|
+
!blockInfo.hasContent ||
|
|
190
|
+
state.selection.from !== blockInfo.contentStart
|
|
191
|
+
) {
|
|
136
192
|
return false;
|
|
137
193
|
}
|
|
138
194
|
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
172
|
-
//
|
|
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 (
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
195
|
-
|
|
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
|
-
|
|
272
|
-
|
|
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
|
-
|
|
288
|
-
bottomNestedPrevBlockInfo.blockContent.beforePos,
|
|
289
|
-
);
|
|
275
|
+
tr.delete(parent.children.beforePos, parent.children.afterPos);
|
|
290
276
|
} else {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
277
|
+
tr.replaceWith(
|
|
278
|
+
blockInfo.block.beforePos,
|
|
279
|
+
blockInfo.block.afterPos,
|
|
280
|
+
blockInfo.children?.node.content ?? Fragment.empty,
|
|
281
|
+
);
|
|
296
282
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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.
|
|
299
|
+
if (!blockInfo.hasContent) {
|
|
317
300
|
return false;
|
|
318
301
|
}
|
|
319
302
|
|
|
320
303
|
const selectionAtBlockStart =
|
|
321
|
-
state.selection.from === blockInfo.
|
|
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.
|
|
309
|
+
blockInfo.block.beforePos,
|
|
327
310
|
);
|
|
328
311
|
|
|
329
312
|
if (prevBlockInfo && selectionAtBlockStart && selectionEmpty) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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.
|
|
318
|
+
if (!bottomBlock.hasContent) {
|
|
336
319
|
return false;
|
|
337
320
|
}
|
|
338
321
|
|
|
339
322
|
const prevBlockNotTableAndNoContent =
|
|
340
|
-
bottomBlock.
|
|
341
|
-
(bottomBlock.
|
|
342
|
-
|
|
343
|
-
bottomBlock.blockContent.node.childCount === 0);
|
|
323
|
+
bottomBlock.contentKind === "none" ||
|
|
324
|
+
(bottomBlock.contentKind === "inline" &&
|
|
325
|
+
bottomBlock.isContentEmpty);
|
|
344
326
|
|
|
345
327
|
if (prevBlockNotTableAndNoContent) {
|
|
346
|
-
|
|
347
|
-
.
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
bottomBlock.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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.
|
|
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 ===
|
|
397
|
+
state.selection.from === blockInfo.contentEnd;
|
|
385
398
|
const selectionEmpty = state.selection.empty;
|
|
386
399
|
|
|
387
|
-
const firstChildBlockInfo =
|
|
388
|
-
state.doc
|
|
400
|
+
const firstChildBlockInfo = getBlockInfoAt(
|
|
401
|
+
state.doc,
|
|
402
|
+
children.childrenStart,
|
|
389
403
|
);
|
|
390
|
-
if (!firstChildBlockInfo.
|
|
404
|
+
if (!firstChildBlockInfo.hasContent) {
|
|
391
405
|
return false;
|
|
392
406
|
}
|
|
393
407
|
|
|
394
408
|
if (selectionAtBlockEnd && selectionEmpty) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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.
|
|
427
|
+
if (!blockInfo.hasContent) {
|
|
444
428
|
return false;
|
|
445
429
|
}
|
|
446
|
-
const {
|
|
430
|
+
const { block: blockContainer } = blockInfo;
|
|
447
431
|
|
|
448
432
|
const nextBlockInfo = getNextBlockInfo(
|
|
449
433
|
state.doc,
|
|
450
|
-
blockInfo.
|
|
434
|
+
blockInfo.block.beforePos,
|
|
451
435
|
);
|
|
452
|
-
if (!nextBlockInfo || !nextBlockInfo.
|
|
436
|
+
if (!nextBlockInfo || !nextBlockInfo.hasContent) {
|
|
453
437
|
return false;
|
|
454
438
|
}
|
|
455
439
|
|
|
456
440
|
const selectionAtBlockEnd =
|
|
457
|
-
state.selection.from ===
|
|
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
|
-
//
|
|
472
|
-
//
|
|
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 (
|
|
477
|
-
|
|
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
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
537
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
508
|
+
if (!blockInfo.hasContent) {
|
|
581
509
|
return false;
|
|
582
510
|
}
|
|
583
|
-
const { blockContent } = blockInfo;
|
|
584
511
|
|
|
585
512
|
const selectionAtBlockEnd =
|
|
586
|
-
state.selection.from ===
|
|
513
|
+
state.selection.from === blockInfo.contentEnd;
|
|
587
514
|
const selectionEmpty = state.selection.empty;
|
|
588
515
|
|
|
589
516
|
if (selectionAtBlockEnd && selectionEmpty) {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
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
|
-
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
const parentBlockInfo = getParentBlockInfo(doc, beforePos);
|
|
600
|
-
if (!parentBlockInfo) {
|
|
601
|
-
return undefined;
|
|
525
|
+
break;
|
|
602
526
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
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
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
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.
|
|
551
|
+
if (!blockInfo.hasContent) {
|
|
657
552
|
return false;
|
|
658
553
|
}
|
|
659
554
|
|
|
660
555
|
const blockEmpty =
|
|
661
|
-
blockInfo.
|
|
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.
|
|
561
|
+
blockInfo.block.beforePos,
|
|
668
562
|
);
|
|
669
|
-
if (!nextBlockInfo || !nextBlockInfo.
|
|
563
|
+
if (!nextBlockInfo || !nextBlockInfo.hasContent) {
|
|
670
564
|
return false;
|
|
671
565
|
}
|
|
672
566
|
|
|
673
|
-
|
|
567
|
+
const chainedCommands = chain();
|
|
674
568
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
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.
|
|
703
|
-
to: blockInfo.
|
|
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.
|
|
594
|
+
if (!blockInfo.hasContent) {
|
|
719
595
|
return false;
|
|
720
596
|
}
|
|
721
597
|
|
|
722
598
|
const selectionAtBlockEnd =
|
|
723
|
-
state.selection.from === blockInfo.
|
|
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.
|
|
604
|
+
blockInfo.block.beforePos,
|
|
729
605
|
);
|
|
730
606
|
if (!nextBlockInfo) {
|
|
731
607
|
return false;
|
|
732
608
|
}
|
|
733
|
-
if (!nextBlockInfo.
|
|
609
|
+
if (!nextBlockInfo.hasContent) {
|
|
734
610
|
return false;
|
|
735
611
|
}
|
|
736
612
|
|
|
737
613
|
if (nextBlockInfo && selectionAtBlockEnd && selectionEmpty) {
|
|
738
614
|
const nextBlockNotTableAndNoContent =
|
|
739
|
-
nextBlockInfo.
|
|
740
|
-
(nextBlockInfo.
|
|
741
|
-
|
|
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.
|
|
750
|
-
to: nextBlockInfo.
|
|
622
|
+
from: nextBlockInfo.block.beforePos,
|
|
623
|
+
to: nextBlockInfo.block.afterPos,
|
|
751
624
|
})
|
|
752
625
|
.insertContentAt(
|
|
753
|
-
blockInfo.
|
|
754
|
-
nextBlockInfo.
|
|
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.
|
|
668
|
+
if (!blockInfo.hasContent) {
|
|
774
669
|
return false;
|
|
775
670
|
}
|
|
776
|
-
const {
|
|
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 =
|
|
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
|
-
|
|
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
|
-
//
|
|
828
|
-
|
|
829
|
-
(
|
|
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.
|
|
825
|
+
if (!blockInfo.hasContent) {
|
|
868
826
|
return false;
|
|
869
827
|
}
|
|
870
|
-
const {
|
|
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 =
|
|
834
|
+
const blockEmpty = blockInfo.isContentEmpty;
|
|
877
835
|
|
|
878
|
-
if (
|
|
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.
|
|
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.
|
|
869
|
+
if (blockInfo.children) {
|
|
906
870
|
tr.delete(
|
|
907
|
-
blockInfo.
|
|
908
|
-
blockInfo.
|
|
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.
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
959
|
-
|
|
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
|
});
|