@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,18 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
EditorState,
|
|
4
|
-
Plugin,
|
|
5
|
-
PluginKey,
|
|
6
|
-
PluginView,
|
|
7
|
-
TextSelection,
|
|
8
|
-
} from "@tiptap/pm/state";
|
|
9
|
-
import { EditorView } from "@tiptap/pm/view";
|
|
1
|
+
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
10
2
|
|
|
11
3
|
import { Block } from "../../blocks/defaultBlocks.js";
|
|
12
|
-
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
13
4
|
import {
|
|
14
5
|
createExtension,
|
|
15
6
|
createStore,
|
|
7
|
+
ExtensionOptions,
|
|
16
8
|
} from "../../editor/BlockNoteExtension.js";
|
|
17
9
|
import { UiElementPosition } from "../../extensions-shared/UiElementPosition.js";
|
|
18
10
|
import {
|
|
@@ -20,799 +12,459 @@ import {
|
|
|
20
12
|
InlineContentSchema,
|
|
21
13
|
StyleSchema,
|
|
22
14
|
} from "../../schema/index.js";
|
|
23
|
-
import {
|
|
15
|
+
import { registerBlockDropHandlers } from "./blockDropHandling.js";
|
|
24
16
|
import { dragStart, unsetDragImage } from "./dragging.js";
|
|
17
|
+
import {
|
|
18
|
+
HoveredBlock,
|
|
19
|
+
isHeadingToMenu,
|
|
20
|
+
Point,
|
|
21
|
+
resolveHoveredBlock,
|
|
22
|
+
} from "./sideMenuHover.js";
|
|
25
23
|
|
|
26
24
|
export type SideMenuState<
|
|
27
25
|
BSchema extends BlockSchema,
|
|
28
26
|
I extends InlineContentSchema,
|
|
29
27
|
S extends StyleSchema,
|
|
30
28
|
> = UiElementPosition & {
|
|
31
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The block that the side menu is attached to. While the menu is hidden
|
|
31
|
+
* (`show` is `false`), the block it was last attached to, so it can animate
|
|
32
|
+
* out next to it. The store's state is `undefined` until the menu first
|
|
33
|
+
* shows.
|
|
34
|
+
*/
|
|
32
35
|
block: Block<BSchema, I, S>;
|
|
33
36
|
};
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
) {
|
|
42
|
-
const elements = view.root.elementsFromPoint(coords.left, coords.top);
|
|
43
|
-
|
|
44
|
-
for (const element of elements) {
|
|
45
|
-
if (!view.dom.contains(element)) {
|
|
46
|
-
// probably a ui overlay like formatting toolbar etc
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (adjustForColumns) {
|
|
50
|
-
const column = element.closest("[data-node-type=columnList]");
|
|
51
|
-
if (column) {
|
|
52
|
-
return getBlockFromCoords(
|
|
53
|
-
view,
|
|
54
|
-
{
|
|
55
|
-
// TODO can we do better than this?
|
|
56
|
-
left: coords.left + 50, // bit hacky, but if we're inside a column, offset x position to right to account for the width of sidemenu itself
|
|
57
|
-
top: coords.top,
|
|
58
|
-
},
|
|
59
|
-
false,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return getDraggableBlockFromElement(element, view);
|
|
64
|
-
}
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function getBlockFromMousePos(
|
|
69
|
-
mousePos: {
|
|
70
|
-
x: number;
|
|
71
|
-
y: number;
|
|
72
|
-
},
|
|
73
|
-
view: EditorView,
|
|
74
|
-
): { node: HTMLElement; id: string } | undefined {
|
|
75
|
-
// Editor itself may have padding or other styling which affects
|
|
76
|
-
// size/position, so we get the boundingRect of the first child (i.e. the
|
|
77
|
-
// blockGroup that wraps all blocks in the editor) for more accurate side
|
|
78
|
-
// menu placement.
|
|
79
|
-
if (!view.dom.firstChild) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const editorBoundingBox = (
|
|
84
|
-
view.dom.firstChild as HTMLElement
|
|
85
|
-
).getBoundingClientRect();
|
|
86
|
-
|
|
87
|
-
// Gets block at mouse cursor's position.
|
|
88
|
-
const coords = {
|
|
89
|
-
// Clamps the x position to the editor's bounding box.
|
|
90
|
-
left: Math.min(
|
|
91
|
-
Math.max(editorBoundingBox.left + 10, mousePos.x),
|
|
92
|
-
editorBoundingBox.right - 10,
|
|
93
|
-
),
|
|
94
|
-
top: mousePos.y,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const referenceBlock = getBlockFromCoords(view, coords);
|
|
98
|
-
|
|
99
|
-
if (!referenceBlock) {
|
|
100
|
-
// could not find the reference block
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
|
|
38
|
+
/**
|
|
39
|
+
* How far the areas around the editor where the side menu responds reach, in
|
|
40
|
+
* px from the editor element's box. The editor element itself (including its
|
|
41
|
+
* padding, where the menu sits) always counts.
|
|
42
|
+
*/
|
|
43
|
+
export type SideMenuOptions = {
|
|
104
44
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* ```
|
|
110
|
-
* Hovering at position x (left edge of BlockB) would return BlockA.
|
|
111
|
-
* Instead, we check at position y (right edge of BlockA) to correctly identify BlockB.
|
|
45
|
+
* How far left or right of the editor element the pointer still shows the
|
|
46
|
+
* side menu, for the block at the pointer's height. Above or below the
|
|
47
|
+
* editor, no block is at that height.
|
|
48
|
+
* @default 0
|
|
112
49
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
false,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
50
|
+
hoverMargin?: number;
|
|
51
|
+
/**
|
|
52
|
+
* How far outside the editor element, on any side, a dragged block can still
|
|
53
|
+
* be dropped into it (the drop goes to the nearest position in the editor).
|
|
54
|
+
* @default 250
|
|
55
|
+
*/
|
|
56
|
+
dropMargin?: number;
|
|
57
|
+
};
|
|
124
58
|
|
|
125
59
|
/**
|
|
126
|
-
*
|
|
60
|
+
* How long the pointer may rest on its way to the menu (inside the triangle
|
|
61
|
+
* from where it left the block to the menu) before the menu follows it to the
|
|
62
|
+
* block it is over.
|
|
127
63
|
*/
|
|
128
|
-
|
|
129
|
-
BSchema extends BlockSchema,
|
|
130
|
-
I extends InlineContentSchema,
|
|
131
|
-
S extends StyleSchema,
|
|
132
|
-
> implements PluginView {
|
|
133
|
-
public state?: SideMenuState<BSchema, I, S>;
|
|
134
|
-
public readonly emitUpdate: (state: SideMenuState<BSchema, I, S>) => void;
|
|
135
|
-
|
|
136
|
-
private mousePos: { x: number; y: number } | undefined;
|
|
137
|
-
|
|
138
|
-
private hoveredBlock: HTMLElement | undefined;
|
|
139
|
-
|
|
140
|
-
public menuFrozen = false;
|
|
141
|
-
|
|
142
|
-
public isDragOrigin = false;
|
|
143
|
-
|
|
144
|
-
constructor(
|
|
145
|
-
private readonly editor: BlockNoteEditor<BSchema, I, S>,
|
|
146
|
-
private readonly pmView: EditorView,
|
|
147
|
-
emitUpdate: (state: SideMenuState<BSchema, I, S>) => void,
|
|
148
|
-
) {
|
|
149
|
-
this.emitUpdate = () => {
|
|
150
|
-
if (!this.state) {
|
|
151
|
-
throw new Error("Attempting to update uninitialized side menu");
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
emitUpdate(this.state);
|
|
155
|
-
};
|
|
64
|
+
const INTENT_TIMEOUT = 350;
|
|
156
65
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this.onDrop as EventListener,
|
|
168
|
-
true,
|
|
169
|
-
);
|
|
170
|
-
this.pmView.root.addEventListener(
|
|
171
|
-
"dragend",
|
|
172
|
-
this.onDragEnd as EventListener,
|
|
173
|
-
true,
|
|
174
|
-
);
|
|
66
|
+
/** The event's target as an element (text nodes resolve to their parent). */
|
|
67
|
+
function targetElement(target: EventTarget | null): Element | null {
|
|
68
|
+
if (!target || !("nodeType" in target)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const node = target as Node;
|
|
72
|
+
return node.nodeType === Node.ELEMENT_NODE
|
|
73
|
+
? (node as Element)
|
|
74
|
+
: node.parentElement;
|
|
75
|
+
}
|
|
175
76
|
|
|
176
|
-
|
|
177
|
-
this.pmView.root.addEventListener(
|
|
178
|
-
"mousemove",
|
|
179
|
-
this.onMouseMove as EventListener,
|
|
180
|
-
true,
|
|
181
|
-
);
|
|
77
|
+
export const sideMenuPluginKey = new PluginKey("SideMenuPlugin");
|
|
182
78
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Shows a menu next to the block the pointer is about. This
|
|
81
|
+
* extension owns that decision: it listens to the pointer in `mount` and
|
|
82
|
+
* writes the store; the UI only reads the store, positions the menu, and
|
|
83
|
+
* registers the menu's element with `setMenuElement`.
|
|
84
|
+
*
|
|
85
|
+
* The block comes from the topmost element under the pointer (so an editor
|
|
86
|
+
* covered by another element or editor gets no menu), falling back to probing
|
|
87
|
+
* at the pointer's height when that element is padding or the gutter beside
|
|
88
|
+
* the blocks. When the pointer leaves the block towards the menu, the menu
|
|
89
|
+
* stays with the block while the pointer is inside the triangle from its exit
|
|
90
|
+
* point to the menu, until it rests there for {@link INTENT_TIMEOUT}. Once on
|
|
91
|
+
* the menu, leaving it anywhere but onto its block follows the pointer at
|
|
92
|
+
* once. The menu hides when the pointer leaves the window.
|
|
93
|
+
*/
|
|
94
|
+
export const SideMenuExtension = createExtension(
|
|
95
|
+
({
|
|
96
|
+
editor,
|
|
97
|
+
options,
|
|
98
|
+
}: ExtensionOptions<{ sideMenu?: SideMenuOptions } | undefined>) => {
|
|
99
|
+
const store = createStore<SideMenuState<any, any, any> | undefined>(
|
|
100
|
+
undefined,
|
|
188
101
|
);
|
|
189
|
-
}
|
|
190
102
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
103
|
+
const hoverMargin = options?.sideMenu?.hoverMargin ?? 0;
|
|
104
|
+
|
|
105
|
+
let menuFrozen = false;
|
|
106
|
+
let isDragOrigin = false;
|
|
107
|
+
// The side menu's DOM element, registered by the UI that renders it.
|
|
108
|
+
let menuElement: HTMLElement | undefined;
|
|
109
|
+
// The last pointer position over this document.
|
|
110
|
+
let pointer: Point | undefined;
|
|
111
|
+
// The last pointer position over the active block (or the menu).
|
|
112
|
+
let lastOnActive: Point | undefined;
|
|
113
|
+
// Set while the pointer is heading from the active block to the menu.
|
|
114
|
+
let intent:
|
|
115
|
+
| { exit: Point; timer: ReturnType<typeof setTimeout> }
|
|
116
|
+
| undefined;
|
|
117
|
+
|
|
118
|
+
function isDraggable(type: string) {
|
|
119
|
+
return editor.schema.blockSpecs[type].implementation.meta.draggable;
|
|
199
120
|
}
|
|
200
121
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
closestEditor?.element !== this.pmView.dom ||
|
|
208
|
-
closestEditor.distance > DISTANCE_TO_CONSIDER_EDITOR_BOUNDS
|
|
209
|
-
) {
|
|
210
|
-
if (this.state?.show) {
|
|
211
|
-
this.state.show = false;
|
|
212
|
-
this.updateState(this.state);
|
|
122
|
+
function clearIntent() {
|
|
123
|
+
if (intent) {
|
|
124
|
+
clearTimeout(intent.timer);
|
|
125
|
+
intent = undefined;
|
|
213
126
|
}
|
|
214
|
-
return;
|
|
215
127
|
}
|
|
216
128
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (this.state?.show) {
|
|
222
|
-
this.state.show = false;
|
|
223
|
-
this.updateState(this.state);
|
|
129
|
+
function hideMenu() {
|
|
130
|
+
const state = store.state;
|
|
131
|
+
if (state?.show) {
|
|
132
|
+
store.setState({ ...state, show: false });
|
|
224
133
|
}
|
|
225
|
-
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Doesn't update if the menu is already open and the mouse cursor is still hovering the same block.
|
|
230
|
-
if (
|
|
231
|
-
this.state?.show &&
|
|
232
|
-
this.hoveredBlock?.hasAttribute("data-id") &&
|
|
233
|
-
this.hoveredBlock?.getAttribute("data-id") === block.id
|
|
234
|
-
) {
|
|
235
|
-
return;
|
|
236
134
|
}
|
|
237
135
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const blockContentBoundingBox = block.node.getBoundingClientRect();
|
|
243
|
-
const column = block.node.closest("[data-node-type=column]");
|
|
244
|
-
const sideMenuBlock = this.editor.getBlock(
|
|
245
|
-
this.hoveredBlock!.getAttribute("data-id")!,
|
|
246
|
-
);
|
|
247
|
-
if (!sideMenuBlock) {
|
|
248
|
-
if (this.state?.show) {
|
|
249
|
-
this.state.show = false;
|
|
250
|
-
this.hoveredBlock = undefined;
|
|
251
|
-
this.emitUpdate(this.state);
|
|
252
|
-
}
|
|
136
|
+
function showMenu(hovered: HoveredBlock) {
|
|
137
|
+
const block = editor.getBlock(hovered.id);
|
|
138
|
+
if (!block) {
|
|
139
|
+
hideMenu();
|
|
253
140
|
return;
|
|
254
141
|
}
|
|
255
|
-
|
|
142
|
+
store.setState({
|
|
256
143
|
show: true,
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// only take the x coordinate, it's ok.
|
|
263
|
-
column.firstElementChild!.getBoundingClientRect().x
|
|
264
|
-
: (
|
|
265
|
-
this.pmView.dom.firstChild as HTMLElement
|
|
266
|
-
).getBoundingClientRect().x,
|
|
267
|
-
blockContentBoundingBox.y,
|
|
268
|
-
blockContentBoundingBox.width,
|
|
269
|
-
blockContentBoundingBox.height,
|
|
270
|
-
),
|
|
271
|
-
block: sideMenuBlock,
|
|
272
|
-
};
|
|
273
|
-
this.updateState(this.state);
|
|
144
|
+
// The hovered block's box: the menu goes next to the block itself, as
|
|
145
|
+
// the React UI anchors it to the block's element.
|
|
146
|
+
referencePos: hovered.node.getBoundingClientRect(),
|
|
147
|
+
block,
|
|
148
|
+
});
|
|
274
149
|
}
|
|
275
|
-
};
|
|
276
150
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
const element = document.createElement("div");
|
|
307
|
-
element.innerHTML = html;
|
|
308
|
-
|
|
309
|
-
const parser = DOMParser.fromSchema(this.pmView.state.schema);
|
|
310
|
-
const node = parser.parse(element, {
|
|
311
|
-
topNode: this.pmView.state.schema.nodes["blockGroup"].create(),
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
this.pmView.dragging = {
|
|
315
|
-
slice: new Slice(node.content, 0, 0),
|
|
316
|
-
move: true,
|
|
317
|
-
};
|
|
318
|
-
};
|
|
151
|
+
/**
|
|
152
|
+
* Updates the menu for the pointer at `point` over `target`. With
|
|
153
|
+
* `allowIntent`, a pointer heading to the menu keeps the active block.
|
|
154
|
+
*/
|
|
155
|
+
function update(
|
|
156
|
+
point: Point,
|
|
157
|
+
target: Element | null,
|
|
158
|
+
allowIntent: boolean,
|
|
159
|
+
) {
|
|
160
|
+
// While a block is dragged by its handle, the menu must stay as it is:
|
|
161
|
+
// the handle is the drag source, and if the menu hid or moved, React would
|
|
162
|
+
// remove it from the DOM, so its `dragend` (and `blockDragEnd`, which
|
|
163
|
+
// removes the drag image) would never fire. The drop's document change
|
|
164
|
+
// otherwise re-resolves the block at the pointer's pre-drag position.
|
|
165
|
+
if (menuFrozen || isDragOrigin) {
|
|
166
|
+
// Frozen or dragging: keep the menu as it is.
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (target && menuElement?.contains(target)) {
|
|
170
|
+
// On the menu: the pointer got where it was heading. Recording the
|
|
171
|
+
// point here makes it the exit point if the pointer leaves the menu,
|
|
172
|
+
// and as nothing is closer to the menu than the menu, leaving it
|
|
173
|
+
// anywhere but onto its block follows the pointer at once.
|
|
174
|
+
clearIntent();
|
|
175
|
+
lastOnActive = point;
|
|
176
|
+
// On the menu: keep the menu as it is.
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
319
179
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}) => {
|
|
327
|
-
// Get all editor elements in the document
|
|
328
|
-
const editors = Array.from(this.pmView.root.querySelectorAll(".bn-editor"));
|
|
329
|
-
|
|
330
|
-
if (editors.length === 0) {
|
|
331
|
-
return null;
|
|
332
|
-
}
|
|
180
|
+
if (!editor.isEditable) {
|
|
181
|
+
clearIntent();
|
|
182
|
+
hideMenu();
|
|
183
|
+
// Read-only editor: hide the menu.
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
333
186
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
.getBoundingClientRect();
|
|
342
|
-
|
|
343
|
-
const distanceX =
|
|
344
|
-
coords.clientX < rect.left
|
|
345
|
-
? rect.left - coords.clientX
|
|
346
|
-
: coords.clientX > rect.right
|
|
347
|
-
? coords.clientX - rect.right
|
|
348
|
-
: 0;
|
|
349
|
-
|
|
350
|
-
const distanceY =
|
|
351
|
-
coords.clientY < rect.top
|
|
352
|
-
? rect.top - coords.clientY
|
|
353
|
-
: coords.clientY > rect.bottom
|
|
354
|
-
? coords.clientY - rect.bottom
|
|
355
|
-
: 0;
|
|
356
|
-
|
|
357
|
-
const distance = Math.sqrt(
|
|
358
|
-
Math.pow(distanceX, 2) + Math.pow(distanceY, 2),
|
|
187
|
+
const resolution = resolveHoveredBlock(
|
|
188
|
+
editor.prosemirrorView,
|
|
189
|
+
target,
|
|
190
|
+
point,
|
|
191
|
+
isDraggable,
|
|
192
|
+
editor.isWithinEditor,
|
|
193
|
+
hoverMargin,
|
|
359
194
|
);
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
closestEditor = editor;
|
|
195
|
+
if (resolution.kind === "editorUI") {
|
|
196
|
+
// On other UI of the editor (e.g. a toolbar): keep the menu as it is.
|
|
197
|
+
return;
|
|
364
198
|
}
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
return {
|
|
368
|
-
element: closestEditor,
|
|
369
|
-
distance: minDistance,
|
|
370
|
-
};
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* This dragover event handler listens at the document level,
|
|
375
|
-
* and is trying to handle dragover events for all editors.
|
|
376
|
-
*
|
|
377
|
-
* It specifically is trying to handle the following cases:
|
|
378
|
-
* - If the dragover event is within the bounds of any editor, then it does nothing
|
|
379
|
-
* - If the dragover event is outside the bounds of any editor, but close enough (within DISTANCE_TO_CONSIDER_EDITOR_BOUNDS) to the closest editor,
|
|
380
|
-
* then it dispatches a synthetic dragover event to the closest editor (which will trigger the drop-cursor to be shown on that editor)
|
|
381
|
-
* - If the dragover event is outside the bounds of the current editor, then it will dispatch a synthetic dragleave event to the current editor
|
|
382
|
-
* (which will trigger the drop-cursor to be removed from the current editor)
|
|
383
|
-
*
|
|
384
|
-
* The synthetic event is a necessary evil because we do not control prosemirror-dropcursor to be able to show the drop-cursor within the range we want
|
|
385
|
-
*/
|
|
386
|
-
onDragOver = (event: DragEvent) => {
|
|
387
|
-
if ((event as any).synthetic) {
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
199
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
event.dataTransfer?.types.includes("blocknote/html") ||
|
|
398
|
-
(event.target instanceof Node && this.pmView.dom.contains(event.target));
|
|
399
|
-
|
|
400
|
-
if (!isBlockNoteDrag) {
|
|
401
|
-
// Not a BlockNote-related drag, return early without any processing
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
const dragEventContext = this.getDragEventContext(event);
|
|
406
|
-
|
|
407
|
-
if (!dragEventContext || !dragEventContext.isDropPoint) {
|
|
408
|
-
// This is not a drag event that we are interested in
|
|
409
|
-
// so, we close the drop-cursor
|
|
410
|
-
this.closeDropCursor();
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
if (
|
|
415
|
-
dragEventContext.isDropPoint &&
|
|
416
|
-
!dragEventContext.isDropWithinEditorBounds
|
|
417
|
-
) {
|
|
418
|
-
// we are the drop point, but the drag over event is not within the bounds of this editor instance
|
|
419
|
-
// so, we need to dispatch an event that is in the bounds of this editor instance
|
|
420
|
-
this.dispatchSyntheticEvent(event);
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* Closes the drop-cursor for the current editor
|
|
426
|
-
*/
|
|
427
|
-
private closeDropCursor = () => {
|
|
428
|
-
const evt = new Event("dragleave", { bubbles: false });
|
|
429
|
-
// It needs to be synthetic, so we don't accidentally think it is a real dragend event
|
|
430
|
-
(evt as any).synthetic = true;
|
|
431
|
-
// We dispatch the event to the current editor, so that the drop-cursor is removed for it
|
|
432
|
-
this.pmView.dom.dispatchEvent(evt);
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* It is surprisingly difficult to determine the information we need to know about a drag event
|
|
437
|
-
*
|
|
438
|
-
* This function is trying to determine the following:
|
|
439
|
-
* - Whether the current editor instance is the drop point
|
|
440
|
-
* - Whether the current editor instance is the drag origin
|
|
441
|
-
* - Whether the drop event is within the bounds of the current editor instance
|
|
442
|
-
*/
|
|
443
|
-
getDragEventContext = (event: DragEvent) => {
|
|
444
|
-
// Relevance gate: Only handle drags that belong to BlockNote
|
|
445
|
-
// Check if at least one of the following is true:
|
|
446
|
-
// 1. ProseMirror drag started in an editor
|
|
447
|
-
// 2. Side menu drag
|
|
448
|
-
// 3. BlockNote-specific data type in the drag
|
|
449
|
-
// 4. (optional stricter mode) Event target is inside this editor
|
|
450
|
-
const isBlockNoteDrag =
|
|
451
|
-
this.pmView.dragging !== null ||
|
|
452
|
-
this.isDragOrigin ||
|
|
453
|
-
event.dataTransfer?.types.includes("blocknote/html") ||
|
|
454
|
-
(event.target instanceof Node && this.pmView.dom.contains(event.target));
|
|
455
|
-
|
|
456
|
-
if (!isBlockNoteDrag) {
|
|
457
|
-
// Not a BlockNote-related drag, return early
|
|
458
|
-
return undefined;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// We need to check if there is text content that is being dragged (select some text & just drag it)
|
|
462
|
-
const textContentIsBeingDragged =
|
|
463
|
-
!event.dataTransfer?.types.includes("blocknote/html") &&
|
|
464
|
-
!!this.pmView.dragging;
|
|
465
|
-
// This is the side menu drag from this plugin
|
|
466
|
-
const sideMenuIsBeingDragged = !!this.isDragOrigin;
|
|
467
|
-
// Tells us that the current editor instance has a drag ongoing (either text or side menu)
|
|
468
|
-
const isDragOrigin = textContentIsBeingDragged || sideMenuIsBeingDragged;
|
|
469
|
-
|
|
470
|
-
// Tells us which editor instance is the closest to the drag event (whether or not it is actually reasonably close)
|
|
471
|
-
const closestEditor = this.findClosestEditorElement(event);
|
|
472
|
-
|
|
473
|
-
// We arbitrarily decide how far is "too far" from the closest editor to be considered a drop point
|
|
474
|
-
if (
|
|
475
|
-
!closestEditor ||
|
|
476
|
-
closestEditor.distance > DISTANCE_TO_CONSIDER_EDITOR_BOUNDS
|
|
477
|
-
) {
|
|
478
|
-
// we are too far from the closest editor, or no editor was found
|
|
479
|
-
return undefined;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
// We check if the closest editor is the same as the current editor instance (which is the drop point)
|
|
483
|
-
const isDropPoint = closestEditor.element === this.pmView.dom;
|
|
484
|
-
// We check if the current editor instance is the same as the editor instance that the drag event is happening within
|
|
485
|
-
const isDropWithinEditorBounds =
|
|
486
|
-
isDropPoint && closestEditor.distance === 0;
|
|
487
|
-
|
|
488
|
-
// We never want to handle drop events that are not related to us
|
|
489
|
-
if (!isDropPoint && !isDragOrigin) {
|
|
490
|
-
// we are not the drop point or drag origin, so not relevant to us
|
|
491
|
-
return undefined;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
return {
|
|
495
|
-
isDropPoint,
|
|
496
|
-
isDropWithinEditorBounds,
|
|
497
|
-
isDragOrigin,
|
|
498
|
-
};
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* The drop event handler listens at the document level,
|
|
503
|
-
* and handles drop events for all editors.
|
|
504
|
-
*
|
|
505
|
-
* It specifically handles the following cases:
|
|
506
|
-
* - If we are both the drag origin and drop point:
|
|
507
|
-
* - Let normal drop handling take over
|
|
508
|
-
* - If we are the drop point but not the drag origin:
|
|
509
|
-
* - Collapse selection to prevent PM from deleting unrelated content
|
|
510
|
-
* - If drop event is outside our editor bounds, dispatch synthetic drop event to our editor
|
|
511
|
-
* - If we are the drag origin but not the drop point:
|
|
512
|
-
* - Delete the dragged content from our editor after a delay
|
|
513
|
-
*/
|
|
514
|
-
onDrop = (event: DragEvent) => {
|
|
515
|
-
if ((event as any).synthetic) {
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
// Relevance gate: Only handle drags that belong to BlockNote
|
|
520
|
-
// This prevents interference with external drag-and-drop libraries
|
|
521
|
-
const isBlockNoteDrag =
|
|
522
|
-
this.pmView.dragging !== null ||
|
|
523
|
-
this.isDragOrigin ||
|
|
524
|
-
event.dataTransfer?.types.includes("blocknote/html") ||
|
|
525
|
-
(event.target instanceof Node && this.pmView.dom.contains(event.target));
|
|
526
|
-
|
|
527
|
-
if (!isBlockNoteDrag) {
|
|
528
|
-
// Not a BlockNote-related drag, return early without any processing
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
const context = this.getDragEventContext(event);
|
|
533
|
-
if (!context) {
|
|
534
|
-
this.closeDropCursor();
|
|
535
|
-
// This is not a drag event that we are interested in
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
const { isDropPoint, isDropWithinEditorBounds, isDragOrigin } = context;
|
|
539
|
-
|
|
540
|
-
if (!isDropWithinEditorBounds && isDropPoint) {
|
|
541
|
-
// Any time that the drop event is outside of the editor bounds (but still close to an editor instance)
|
|
542
|
-
// We dispatch a synthetic event that is in the bounds of the editor instance, to have the correct drop point
|
|
543
|
-
this.dispatchSyntheticEvent(event);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
if (isDropPoint) {
|
|
547
|
-
// The current instance is the drop point
|
|
548
|
-
|
|
549
|
-
if (this.pmView.dragging) {
|
|
550
|
-
// Do not collapse selection when text content is being dragged
|
|
200
|
+
const state = store.state;
|
|
201
|
+
const active = state?.show ? state.block.id : undefined;
|
|
202
|
+
if (resolution.kind === "block" && resolution.block.id === active) {
|
|
203
|
+
clearIntent();
|
|
204
|
+
lastOnActive = point;
|
|
205
|
+
// On the block of the menu: keep the menu as it is.
|
|
551
206
|
return;
|
|
552
207
|
}
|
|
553
|
-
// Because the editor selection is unrelated to the dragged content, we
|
|
554
|
-
// don't want PM to delete its content. Therefore, we collapse the
|
|
555
|
-
// selection.
|
|
556
|
-
this.pmView.dispatch(
|
|
557
|
-
this.pmView.state.tr.setSelection(
|
|
558
|
-
TextSelection.create(
|
|
559
|
-
this.pmView.state.tr.doc,
|
|
560
|
-
this.pmView.state.tr.selection.anchor,
|
|
561
|
-
),
|
|
562
|
-
),
|
|
563
|
-
);
|
|
564
|
-
return;
|
|
565
|
-
} else if (isDragOrigin) {
|
|
566
|
-
// The current instance is the drag origin, but not the drop point
|
|
567
|
-
// our content got dropped somewhere else
|
|
568
|
-
|
|
569
|
-
// Because the editor from which the block originates doesn't get a drop
|
|
570
|
-
// event on it, PM doesn't delete its selected content. Therefore, we
|
|
571
|
-
// need to do so manually.
|
|
572
|
-
//
|
|
573
|
-
// Note: Deleting the selected content from the editor from which the
|
|
574
|
-
// block originates, may change its height. This can cause the position of
|
|
575
|
-
// the editor in which the block is being dropping to shift, before it
|
|
576
|
-
// can handle the drop event. That in turn can cause the drop to happen
|
|
577
|
-
// somewhere other than the user intended. To get around this, we delay
|
|
578
|
-
// deleting the selected content until all editors have had the chance to
|
|
579
|
-
// handle the event.
|
|
580
|
-
setTimeout(
|
|
581
|
-
() => this.pmView.dispatch(this.pmView.state.tr.deleteSelection()),
|
|
582
|
-
0,
|
|
583
|
-
);
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
};
|
|
587
|
-
|
|
588
|
-
onDragEnd = (event: DragEvent) => {
|
|
589
|
-
if ((event as any).synthetic) {
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
// When the user starts dragging a block, `view.dragging` is set on all
|
|
593
|
-
// BlockNote editors. However, when the drag ends, only the editor that the
|
|
594
|
-
// drag originated in automatically clears `view.dragging`. Therefore, we
|
|
595
|
-
// have to manually clear it on all editors.
|
|
596
|
-
this.pmView.dragging = null;
|
|
597
|
-
};
|
|
598
|
-
|
|
599
|
-
onKeyDown = (_event: KeyboardEvent) => {
|
|
600
|
-
if (this.state?.show && this.editor.isFocused()) {
|
|
601
|
-
// Typing in editor should hide side menu
|
|
602
|
-
this.state.show = false;
|
|
603
|
-
this.emitUpdate(this.state);
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
208
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
if (!Number.isFinite(event.clientX) || !Number.isFinite(event.clientY)) {
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
this.mousePos = { x: event.clientX, y: event.clientY };
|
|
621
|
-
|
|
622
|
-
// We want the full area of the editor to check if the cursor is hovering
|
|
623
|
-
// above it though.
|
|
624
|
-
const editorOuterBoundingBox = this.pmView.dom.getBoundingClientRect();
|
|
625
|
-
const cursorWithinEditor =
|
|
626
|
-
this.mousePos.x > editorOuterBoundingBox.left &&
|
|
627
|
-
this.mousePos.x < editorOuterBoundingBox.right &&
|
|
628
|
-
this.mousePos.y > editorOuterBoundingBox.top &&
|
|
629
|
-
this.mousePos.y < editorOuterBoundingBox.bottom;
|
|
630
|
-
|
|
631
|
-
// Doesn't update if the mouse hovers an element that's over the editor but
|
|
632
|
-
// isn't a part of it or the side menu.
|
|
633
|
-
if (
|
|
634
|
-
// Cursor is within the editor area
|
|
635
|
-
cursorWithinEditor &&
|
|
636
|
-
// An element is hovered
|
|
637
|
-
event &&
|
|
638
|
-
event.target &&
|
|
639
|
-
// Element is outside this editor and its portaled UI
|
|
640
|
-
!this.editor.isWithinEditor(event.target as HTMLElement)
|
|
641
|
-
) {
|
|
642
|
-
if (this.state?.show) {
|
|
643
|
-
this.state.show = false;
|
|
644
|
-
this.emitUpdate(this.state);
|
|
209
|
+
if (allowIntent && active !== undefined && menuElement?.isConnected) {
|
|
210
|
+
const exit = intent?.exit ?? lastOnActive ?? point;
|
|
211
|
+
if (isHeadingToMenu(point, exit, menuElement.getBoundingClientRect())) {
|
|
212
|
+
// Restarts the timeout, so it measures how long the pointer rests.
|
|
213
|
+
clearIntent();
|
|
214
|
+
intent = { exit, timer: setTimeout(releaseIntent, INTENT_TIMEOUT) };
|
|
215
|
+
// On the way to the menu: keep the menu on its block for now.
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
645
218
|
}
|
|
646
219
|
|
|
647
|
-
|
|
220
|
+
// Not on the way to the menu: show the menu for the block under the
|
|
221
|
+
// pointer, or hide it if there is no block.
|
|
222
|
+
clearIntent();
|
|
223
|
+
if (resolution.kind === "block") {
|
|
224
|
+
lastOnActive = point;
|
|
225
|
+
showMenu(resolution.block);
|
|
226
|
+
} else {
|
|
227
|
+
hideMenu();
|
|
228
|
+
}
|
|
648
229
|
}
|
|
649
230
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
private dispatchSyntheticEvent(event: DragEvent) {
|
|
654
|
-
const evt = new Event(event.type as "dragover", event) as any;
|
|
655
|
-
const dropPointBoundingBox = (
|
|
656
|
-
this.pmView.dom.firstChild as HTMLElement
|
|
657
|
-
).getBoundingClientRect();
|
|
658
|
-
evt.clientX = event.clientX;
|
|
659
|
-
evt.clientY = event.clientY;
|
|
660
|
-
|
|
661
|
-
evt.clientX = Math.min(
|
|
662
|
-
Math.max(event.clientX, dropPointBoundingBox.left),
|
|
663
|
-
dropPointBoundingBox.left + dropPointBoundingBox.width,
|
|
664
|
-
);
|
|
665
|
-
evt.clientY = Math.min(
|
|
666
|
-
Math.max(event.clientY, dropPointBoundingBox.top),
|
|
667
|
-
dropPointBoundingBox.top + dropPointBoundingBox.height,
|
|
668
|
-
);
|
|
669
|
-
|
|
670
|
-
evt.dataTransfer = event.dataTransfer;
|
|
671
|
-
evt.preventDefault = () => event.preventDefault();
|
|
672
|
-
evt.synthetic = true; // prevent recursion
|
|
673
|
-
this.pmView.dom.dispatchEvent(evt);
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// Needed in cases where the editor state updates without the mouse cursor
|
|
677
|
-
// moving, as some state updates can require a side menu update. For example,
|
|
678
|
-
// adding a button to the side menu which removes the block can cause the
|
|
679
|
-
// block below to jump up into the place of the removed block when clicked,
|
|
680
|
-
// allowing the user to click the button again without moving the cursor. This
|
|
681
|
-
// would otherwise not update the side menu, and so clicking the button again
|
|
682
|
-
// would attempt to remove the same block again, causing an error.
|
|
683
|
-
update(_view: EditorView, prevState: EditorState) {
|
|
684
|
-
const docChanged = !prevState.doc.eq(this.pmView.state.doc);
|
|
685
|
-
if (docChanged && this.state?.show) {
|
|
686
|
-
this.updateStateFromMousePos();
|
|
231
|
+
function endBlockDrag() {
|
|
232
|
+
unsetDragImage(editor.prosemirrorView.root);
|
|
233
|
+
isDragOrigin = false;
|
|
687
234
|
}
|
|
688
|
-
}
|
|
689
235
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
236
|
+
/** The pointer rested on its way to the menu: follow it after all. */
|
|
237
|
+
function releaseIntent() {
|
|
238
|
+
intent = undefined;
|
|
239
|
+
refresh();
|
|
694
240
|
}
|
|
695
|
-
this.pmView.root.removeEventListener(
|
|
696
|
-
"mousemove",
|
|
697
|
-
this.onMouseMove as EventListener,
|
|
698
|
-
true,
|
|
699
|
-
);
|
|
700
|
-
this.pmView.root.removeEventListener(
|
|
701
|
-
"dragstart",
|
|
702
|
-
this.onDragStart as EventListener,
|
|
703
|
-
);
|
|
704
|
-
this.pmView.root.removeEventListener(
|
|
705
|
-
"dragover",
|
|
706
|
-
this.onDragOver as EventListener,
|
|
707
|
-
);
|
|
708
|
-
this.pmView.root.removeEventListener(
|
|
709
|
-
"drop",
|
|
710
|
-
this.onDrop as EventListener,
|
|
711
|
-
true,
|
|
712
|
-
);
|
|
713
|
-
this.pmView.root.removeEventListener(
|
|
714
|
-
"dragend",
|
|
715
|
-
this.onDragEnd as EventListener,
|
|
716
|
-
true,
|
|
717
|
-
);
|
|
718
|
-
this.pmView.root.removeEventListener(
|
|
719
|
-
"keydown",
|
|
720
|
-
this.onKeyDown as EventListener,
|
|
721
|
-
true,
|
|
722
|
-
);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
export const sideMenuPluginKey = new PluginKey("SideMenuPlugin");
|
|
727
|
-
|
|
728
|
-
export const SideMenuExtension = createExtension(({ editor }) => {
|
|
729
|
-
let view: SideMenuView<any, any, any> | undefined;
|
|
730
|
-
const store = createStore<SideMenuState<any, any, any> | undefined>(
|
|
731
|
-
undefined,
|
|
732
|
-
);
|
|
733
|
-
|
|
734
|
-
return {
|
|
735
|
-
key: "sideMenu",
|
|
736
|
-
store,
|
|
737
|
-
prosemirrorPlugins: [
|
|
738
|
-
new Plugin({
|
|
739
|
-
key: sideMenuPluginKey,
|
|
740
|
-
view: (editorView) => {
|
|
741
|
-
view = new SideMenuView(editor, editorView, (state) => {
|
|
742
|
-
// TODO: Without spreading the state, in some cases like toggling
|
|
743
|
-
// `show`, this doesn't trigger an update.
|
|
744
|
-
store.setState({ ...state });
|
|
745
|
-
});
|
|
746
|
-
return view;
|
|
747
|
-
},
|
|
748
|
-
}),
|
|
749
|
-
],
|
|
750
241
|
|
|
751
242
|
/**
|
|
752
|
-
*
|
|
243
|
+
* Re-resolves the block for the last pointer position, without intent,
|
|
244
|
+
* e.g. after a document change. If the pointer is on the menu (e.g. it
|
|
245
|
+
* clicked a menu button), this resolves just right of the menu instead:
|
|
246
|
+
* the menu is next to its block, so that point is on the line of the block,
|
|
247
|
+
* in its column. The pointer itself can be over another block, e.g. the
|
|
248
|
+
* "+" of a block in a column is over the column to its left. If the block
|
|
249
|
+
* was removed, the block that moved up into its place takes over.
|
|
753
250
|
*/
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
) {
|
|
758
|
-
if (view) {
|
|
759
|
-
view.isDragOrigin = true;
|
|
760
|
-
}
|
|
761
|
-
dragStart(event, block, editor);
|
|
762
|
-
},
|
|
763
|
-
|
|
764
|
-
/**
|
|
765
|
-
* Handles drag & drop events for blocks.
|
|
766
|
-
*/
|
|
767
|
-
blockDragEnd() {
|
|
768
|
-
unsetDragImage(editor.prosemirrorView.root);
|
|
769
|
-
if (view) {
|
|
770
|
-
view.isDragOrigin = false;
|
|
251
|
+
function refresh() {
|
|
252
|
+
if (!pointer) {
|
|
253
|
+
return;
|
|
771
254
|
}
|
|
255
|
+
const view = editor.prosemirrorView;
|
|
256
|
+
const menu = menuElement?.isConnected
|
|
257
|
+
? menuElement.getBoundingClientRect()
|
|
258
|
+
: undefined;
|
|
259
|
+
const onMenu =
|
|
260
|
+
menu !== undefined &&
|
|
261
|
+
pointer.x >= menu.left &&
|
|
262
|
+
pointer.x <= menu.right &&
|
|
263
|
+
pointer.y >= menu.top &&
|
|
264
|
+
pointer.y <= menu.bottom;
|
|
265
|
+
const point = onMenu ? { x: menu.right + 1, y: pointer.y } : pointer;
|
|
266
|
+
// Looks past other UI of the editor at what is underneath.
|
|
267
|
+
const target =
|
|
268
|
+
view.root
|
|
269
|
+
.elementsFromPoint(point.x, point.y)
|
|
270
|
+
.find(
|
|
271
|
+
(element) =>
|
|
272
|
+
view.dom.contains(element) || !editor.isWithinEditor(element),
|
|
273
|
+
) ?? null;
|
|
274
|
+
update(point, target, false);
|
|
275
|
+
}
|
|
772
276
|
|
|
773
|
-
|
|
774
|
-
|
|
277
|
+
return {
|
|
278
|
+
key: "sideMenu",
|
|
279
|
+
store,
|
|
280
|
+
prosemirrorPlugins: [
|
|
281
|
+
new Plugin({
|
|
282
|
+
key: sideMenuPluginKey,
|
|
283
|
+
appendTransaction: (transactions, _oldState, newState) => {
|
|
284
|
+
if (transactions.some((tr) => tr.getMeta("uiEvent") === "drop")) {
|
|
285
|
+
// Forces a `scrollIntoView` immediately after a drop. Fixes WebKit
|
|
286
|
+
// specific behavior where focusing scrolls the selection into
|
|
287
|
+
// view. This happens on drop before ProseMirror updates the
|
|
288
|
+
// document/selection, which is incorrect.
|
|
289
|
+
return newState.tr.scrollIntoView();
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
},
|
|
293
|
+
}),
|
|
294
|
+
],
|
|
295
|
+
mount({
|
|
296
|
+
root,
|
|
297
|
+
signal,
|
|
298
|
+
}: {
|
|
299
|
+
root: Document | ShadowRoot;
|
|
300
|
+
signal: AbortSignal;
|
|
301
|
+
}) {
|
|
302
|
+
registerBlockDropHandlers(
|
|
303
|
+
editor.prosemirrorView,
|
|
304
|
+
() => isDragOrigin,
|
|
305
|
+
options?.sideMenu?.dropMargin ?? 250,
|
|
306
|
+
signal,
|
|
307
|
+
);
|
|
775
308
|
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
309
|
+
// Shows or updates the menu whenever the pointer moves, unless frozen.
|
|
310
|
+
root.addEventListener(
|
|
311
|
+
// `mousemove`, not `pointermove`: iOS Safari delivers a tap as a hover
|
|
312
|
+
// (one compatibility `mousemove` to the tap point, then the click),
|
|
313
|
+
// which is how the side menu shows on phones.
|
|
314
|
+
"mousemove",
|
|
315
|
+
(event) => {
|
|
316
|
+
// Synthetic events created via `new Event("mousemove")` (e.g.
|
|
317
|
+
// dispatched by browser extensions) have no `clientX`/`clientY`,
|
|
318
|
+
// which would make `elementsFromPoint` throw on the resulting
|
|
319
|
+
// non-finite coordinates.
|
|
320
|
+
const { clientX, clientY, buttons } = event as Partial<MouseEvent>;
|
|
321
|
+
if (
|
|
322
|
+
menuFrozen ||
|
|
323
|
+
typeof clientX !== "number" ||
|
|
324
|
+
typeof clientY !== "number" ||
|
|
325
|
+
!Number.isFinite(clientX) ||
|
|
326
|
+
!Number.isFinite(clientY)
|
|
327
|
+
) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (isDragOrigin && buttons === 0) {
|
|
331
|
+
// The drag ended without `dragend` reaching the handle (e.g. the
|
|
332
|
+
// menu was unmounted by its controller): clean up now.
|
|
333
|
+
endBlockDrag();
|
|
334
|
+
}
|
|
335
|
+
const point = { x: clientX, y: clientY };
|
|
336
|
+
pointer = point;
|
|
337
|
+
update(point, targetElement(event.target), true);
|
|
338
|
+
},
|
|
339
|
+
{ signal, capture: true },
|
|
340
|
+
);
|
|
783
341
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
342
|
+
// The pointer left the window: no block is hovered any more. Only
|
|
343
|
+
// `mouseout` reports this (with no `relatedTarget`), as `mouseleave`
|
|
344
|
+
// doesn't reach a document or shadow root.
|
|
345
|
+
root.addEventListener(
|
|
346
|
+
"mouseout",
|
|
347
|
+
(event) => {
|
|
348
|
+
if (
|
|
349
|
+
(event as MouseEvent).relatedTarget === null &&
|
|
350
|
+
!menuFrozen &&
|
|
351
|
+
!isDragOrigin
|
|
352
|
+
) {
|
|
353
|
+
pointer = undefined;
|
|
354
|
+
clearIntent();
|
|
355
|
+
hideMenu();
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
{ signal, capture: true },
|
|
359
|
+
);
|
|
794
360
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
361
|
+
// Hides the menu whenever the user types.
|
|
362
|
+
root.addEventListener(
|
|
363
|
+
"keydown",
|
|
364
|
+
() => {
|
|
365
|
+
if (store.state?.show && editor.isFocused()) {
|
|
366
|
+
clearIntent();
|
|
367
|
+
hideMenu();
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
{ signal, capture: true },
|
|
371
|
+
);
|
|
805
372
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
}
|
|
373
|
+
// Needed in cases where the document changes without the pointer
|
|
374
|
+
// moving: blocks move under it when blocks above it change. For
|
|
375
|
+
// example, a side menu button which removes the block can cause the
|
|
376
|
+
// block below to jump up into the place of the removed block when
|
|
377
|
+
// clicked, allowing the user to click the button again without moving
|
|
378
|
+
// the pointer. This would otherwise not update the side menu, and so
|
|
379
|
+
// clicking the button again would attempt to remove the same block
|
|
380
|
+
// again, causing an error.
|
|
381
|
+
const unsubscribeOnChange = editor.onChange(() => {
|
|
382
|
+
if (store.state?.show) {
|
|
383
|
+
clearIntent();
|
|
384
|
+
refresh();
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
signal.addEventListener("abort", () => {
|
|
389
|
+
unsubscribeOnChange();
|
|
390
|
+
clearIntent();
|
|
391
|
+
hideMenu();
|
|
392
|
+
});
|
|
393
|
+
},
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Registers the element that renders the side menu. Moving the pointer
|
|
397
|
+
* from a block towards this element keeps the menu on that block, and
|
|
398
|
+
* hovering it never changes the block.
|
|
399
|
+
*/
|
|
400
|
+
setMenuElement(element: HTMLElement | undefined) {
|
|
401
|
+
menuElement = element;
|
|
402
|
+
},
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Handles drag & drop events for blocks.
|
|
406
|
+
*/
|
|
407
|
+
blockDragStart(
|
|
408
|
+
event: { dataTransfer: DataTransfer | null; clientY: number },
|
|
409
|
+
block: Block<any, any, any>,
|
|
410
|
+
) {
|
|
411
|
+
isDragOrigin = true;
|
|
412
|
+
dragStart(event, block, editor);
|
|
413
|
+
},
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Handles drag & drop events for blocks.
|
|
417
|
+
*/
|
|
418
|
+
blockDragEnd() {
|
|
419
|
+
endBlockDrag();
|
|
420
|
+
editor.blur();
|
|
421
|
+
},
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Whether the side menu is currently frozen (e.g. because the drag handle
|
|
425
|
+
* menu is open).
|
|
426
|
+
*/
|
|
427
|
+
get menuFrozen() {
|
|
428
|
+
return menuFrozen;
|
|
429
|
+
},
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Freezes the side menu. When frozen, the side menu will stay
|
|
433
|
+
* attached to the same block regardless of which block is hovered by the
|
|
434
|
+
* mouse cursor.
|
|
435
|
+
*/
|
|
436
|
+
freezeMenu() {
|
|
437
|
+
menuFrozen = true;
|
|
438
|
+
clearIntent();
|
|
439
|
+
const state = store.state;
|
|
440
|
+
if (state) {
|
|
441
|
+
store.setState({ ...state, show: true });
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Unfreezes the side menu. When frozen, the side menu will stay
|
|
447
|
+
* attached to the same block regardless of which block is hovered by the
|
|
448
|
+
* mouse cursor.
|
|
449
|
+
*/
|
|
450
|
+
unfreezeMenu() {
|
|
451
|
+
menuFrozen = false;
|
|
452
|
+
hideMenu();
|
|
453
|
+
},
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Hides the side menu unless it is currently frozen (e.g. the drag
|
|
457
|
+
* handle menu is open). Used to dismiss the menu on scroll without
|
|
458
|
+
* interfering with open submenus.
|
|
459
|
+
*/
|
|
460
|
+
hideMenuIfNotFrozen() {
|
|
461
|
+
// A drag can scroll the page, but hiding the menu would remove the drag
|
|
462
|
+
// source (see `update`).
|
|
463
|
+
if (!menuFrozen && !isDragOrigin) {
|
|
464
|
+
clearIntent();
|
|
465
|
+
hideMenu();
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
} as const;
|
|
469
|
+
},
|
|
470
|
+
);
|