@blocknote/core 0.55.0 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-DaEUT0O1.js → blocks-COYcDVg7.js} +1572 -1156
- 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.js +12 -12
- package/dist/{en-BAn9gxr-.js → en-Ch-vvt5e.js} +36 -2
- 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 +771 -23
- 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-D5w0XAHX.js → src-BmLsLZfE.js} +1390 -1278
- 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 +8 -8
- 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/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 +71 -9
- package/src/editor/BlockNoteExtension.ts +5 -5
- 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/ExtensionManager/ExtensionManager.browser.test.ts +45 -0
- package/src/editor/managers/ExtensionManager/ExtensionManager.node.test.ts +209 -0
- package/src/editor/managers/ExtensionManager/extensions.ts +10 -1
- package/src/editor/managers/ExtensionManager/index.ts +135 -68
- package/src/editor/managers/StateManager.ts +14 -4
- 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 +7 -1
- 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 -764
- 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.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 +32 -0
- package/src/i18n/locales/de.ts +32 -0
- package/src/i18n/locales/en.ts +32 -0
- package/src/i18n/locales/es.ts +32 -0
- package/src/i18n/locales/fa.ts +32 -0
- package/src/i18n/locales/fr.ts +32 -0
- package/src/i18n/locales/he.ts +32 -0
- package/src/i18n/locales/hr.ts +32 -0
- package/src/i18n/locales/is.ts +32 -0
- package/src/i18n/locales/it.ts +32 -0
- package/src/i18n/locales/ja.ts +32 -0
- package/src/i18n/locales/ko.ts +32 -0
- package/src/i18n/locales/nl.ts +32 -0
- package/src/i18n/locales/no.ts +32 -0
- package/src/i18n/locales/pl.ts +32 -0
- package/src/i18n/locales/pt.ts +32 -0
- package/src/i18n/locales/ru.ts +32 -0
- package/src/i18n/locales/sk.ts +32 -0
- package/src/i18n/locales/uk.ts +32 -0
- package/src/i18n/locales/uz.ts +32 -0
- package/src/i18n/locales/vi.ts +32 -0
- package/src/i18n/locales/zh-tw.ts +32 -0
- package/src/i18n/locales/zh.ts +32 -0
- package/src/index.ts +13 -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/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/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/editor/BlockNoteEditor.d.ts +36 -8
- package/types/src/editor/BlockNoteEditor.node.test.d.ts +1 -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/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/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/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 +32 -0
- package/types/src/i18n/locales/fa.d.ts +32 -0
- package/types/src/i18n/locales/sk.d.ts +32 -0
- package/types/src/index.d.ts +6 -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/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-DLgTreVu.cjs +0 -12
- package/dist/blocks-DLgTreVu.cjs.map +0 -1
- package/dist/blocks-DaEUT0O1.js.map +0 -1
- package/dist/en-BAn9gxr-.js.map +0 -1
- package/dist/en-CHnrV5l8.cjs +0 -2
- package/dist/en-CHnrV5l8.cjs.map +0 -1
- package/dist/extensions-B1JQURVF.js +0 -2138
- package/dist/extensions-B1JQURVF.js.map +0 -1
- package/dist/extensions-CZkqKzJO.cjs +0 -58
- package/dist/extensions-CZkqKzJO.cjs.map +0 -1
- package/dist/src-D5w0XAHX.js.map +0 -1
- package/dist/src-th5uZEvx.cjs +0 -23
- package/dist/src-th5uZEvx.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
|
@@ -8,7 +8,6 @@ import { fragmentToBlocks } from "../../api/nodeConversions/fragmentToBlocks.js"
|
|
|
8
8
|
import { getNodeById } from "../../api/nodeUtil.js";
|
|
9
9
|
import { Block } from "../../blocks/defaultBlocks.js";
|
|
10
10
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
11
|
-
import { UiElementPosition } from "../../extensions-shared/UiElementPosition.js";
|
|
12
11
|
import {
|
|
13
12
|
BlockSchema,
|
|
14
13
|
InlineContentSchema,
|
|
@@ -18,15 +17,6 @@ import { MultipleNodeSelection } from "./MultipleNodeSelection.js";
|
|
|
18
17
|
|
|
19
18
|
let dragImageElement: Element | undefined;
|
|
20
19
|
|
|
21
|
-
export type SideMenuState<
|
|
22
|
-
BSchema extends BlockSchema,
|
|
23
|
-
I extends InlineContentSchema,
|
|
24
|
-
S extends StyleSchema,
|
|
25
|
-
> = UiElementPosition & {
|
|
26
|
-
// The block that the side menu is attached to.
|
|
27
|
-
block: Block<BSchema, I, S>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
20
|
function blockPositionsFromSelection(selection: Selection, doc: Node) {
|
|
31
21
|
// Absolute positions just before the first block spanned by the selection, and just after the last block. Having the
|
|
32
22
|
// selection start and end just before and just after the target blocks ensures no whitespace/line breaks are left
|
|
@@ -71,33 +61,23 @@ function setDragImage(view: EditorView, from: number, to = from) {
|
|
|
71
61
|
to += view.state.doc.resolve(from + 1).node().nodeSize;
|
|
72
62
|
}
|
|
73
63
|
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
view.domAtPos(from + 1).node.parentElement!,
|
|
85
|
-
);
|
|
86
|
-
const lastSelectedBlockIndex = getElementIndex(
|
|
87
|
-
parent,
|
|
88
|
-
// Expects to position to be just after the last selected block.
|
|
89
|
-
view.domAtPos(to - 1).node.parentElement!,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
for (let i = parent.childElementCount - 1; i >= 0; i--) {
|
|
93
|
-
if (i > lastSelectedBlockIndex || i < firstSelectedBlockIndex) {
|
|
94
|
-
parentClone.removeChild(parentClone.children[i]);
|
|
64
|
+
// The preview is a copy of the element that holds the dragged blocks,
|
|
65
|
+
// without its other children: a copy of each dragged block's element. The
|
|
66
|
+
// holding element can have no box of its own (`display: contents`, e.g. the
|
|
67
|
+
// slot of a React layout block), but the preview needs one.
|
|
68
|
+
const preview = view.domAtPos(from).node.cloneNode(false) as HTMLElement;
|
|
69
|
+
preview.style.removeProperty("display");
|
|
70
|
+
for (let pos = from; pos < to; pos += view.state.doc.nodeAt(pos)!.nodeSize) {
|
|
71
|
+
const blockDOM = view.nodeDOM(pos);
|
|
72
|
+
if (!blockDOM) {
|
|
73
|
+
throw new Error(`The dragged block at ${pos} has no DOM.`);
|
|
95
74
|
}
|
|
75
|
+
preview.appendChild(blockDOM.cloneNode(true));
|
|
96
76
|
}
|
|
97
77
|
|
|
98
78
|
// dataTransfer.setDragImage(element) only works if element is attached to the DOM.
|
|
99
79
|
unsetDragImage(view.root);
|
|
100
|
-
dragImageElement =
|
|
80
|
+
dragImageElement = preview;
|
|
101
81
|
|
|
102
82
|
// Browsers may have CORS policies which prevents iframes from being
|
|
103
83
|
// manipulated, so better to stay on the safe side and remove them from the
|
|
@@ -205,6 +185,13 @@ export function dragStart<
|
|
|
205
185
|
|
|
206
186
|
e.dataTransfer.clearData();
|
|
207
187
|
e.dataTransfer.setData("blocknote/html", clipboardHTML);
|
|
188
|
+
// The type of the dragged blocks' parent. The editors parse the blocks
|
|
189
|
+
// into it (see `blockDropHandling.ts`), so that a block that only this
|
|
190
|
+
// parent can hold is not wrapped in a new copy of it.
|
|
191
|
+
e.dataTransfer.setData(
|
|
192
|
+
"blocknote/parent",
|
|
193
|
+
view.state.selection.$from.parent.type.name,
|
|
194
|
+
);
|
|
208
195
|
e.dataTransfer.setData("text/html", externalHTML);
|
|
209
196
|
e.dataTransfer.setData("text/plain", plainText);
|
|
210
197
|
e.dataTransfer.effectAllowed = "move";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
2
|
+
|
|
3
|
+
import { isHeadingToMenu } from "./sideMenuHover.js";
|
|
4
|
+
|
|
5
|
+
// A menu left of and above the exit point, as for a block's side menu when
|
|
6
|
+
// the pointer leaves the block at its bottom left.
|
|
7
|
+
const menu = { left: 0, top: 0, right: 40, bottom: 20 };
|
|
8
|
+
const exit = { x: 60, y: 60 };
|
|
9
|
+
|
|
10
|
+
describe("isHeadingToMenu", () => {
|
|
11
|
+
it("accepts points on the way from the exit point to the menu", () => {
|
|
12
|
+
expect(isHeadingToMenu({ x: 50, y: 40 }, exit, menu)).toBe(true);
|
|
13
|
+
expect(isHeadingToMenu({ x: 20, y: 10 }, exit, menu)).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("accepts a steep move just outside the hull's tip", () => {
|
|
17
|
+
// The hull's edge from the exit point to the menu's bottom left corner
|
|
18
|
+
// has y ≈ 54.7 at x = 52; (52, 56) is ~1.1px below it.
|
|
19
|
+
expect(isHeadingToMenu({ x: 52, y: 56 }, exit, menu)).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("rejects points further than the buffer from the hull", () => {
|
|
23
|
+
expect(isHeadingToMenu({ x: 40, y: 55 }, exit, menu)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("rejects moves away from the menu, even next to the exit point", () => {
|
|
27
|
+
expect(isHeadingToMenu({ x: 60, y: 61 }, exit, menu)).toBe(false);
|
|
28
|
+
expect(isHeadingToMenu({ x: 61, y: 60 }, exit, menu)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("rejects every point once the exit point is on the menu", () => {
|
|
32
|
+
expect(isHeadingToMenu({ x: 30, y: 24 }, { x: 30, y: 19 }, menu)).toBe(
|
|
33
|
+
false,
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { EditorView } from "@tiptap/pm/view";
|
|
2
|
+
|
|
3
|
+
import { getBlockElement, getDraggableBlockFromElement } from "../blockDOM.js";
|
|
4
|
+
import { getNestedBlockAtCursor } from "./blockGeometry.js";
|
|
5
|
+
|
|
6
|
+
export type Point = { x: number; y: number };
|
|
7
|
+
|
|
8
|
+
export type Rect = { left: number; top: number; right: number; bottom: number };
|
|
9
|
+
|
|
10
|
+
export type HoveredBlock = { node: HTMLElement; id: string };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* How far inside the edge of the blocks the probe point goes. A probe exactly
|
|
14
|
+
* on an edge can hit the element next to it.
|
|
15
|
+
*/
|
|
16
|
+
const PROBE_INSET = 10;
|
|
17
|
+
|
|
18
|
+
function clamp(value: number, min: number, max: number) {
|
|
19
|
+
return Math.min(Math.max(value, min), max);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Returns the block of this editor at a visible point, if there is one. */
|
|
23
|
+
function getBlockAtPoint(view: EditorView, point: Point) {
|
|
24
|
+
for (const element of view.root.elementsFromPoint(point.x, point.y)) {
|
|
25
|
+
// Skips UI painted over the blocks (e.g. a toolbar), and the blocks of an
|
|
26
|
+
// editor nested in one of ours: looks below them.
|
|
27
|
+
const block = getBlockElement(element, view);
|
|
28
|
+
if (block) {
|
|
29
|
+
return block;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Finds the block at the height of the pointer, when the pointer is not on
|
|
37
|
+
* the content of a block (it is in padding, in an indentation or in the
|
|
38
|
+
* gutter).
|
|
39
|
+
*
|
|
40
|
+
* The function probes once: it finds the element at a point on the same line
|
|
41
|
+
* as the pointer, just inside the edge of the blocks, with
|
|
42
|
+
* `elementsFromPoint`. This point is next to the pointer, so it is visible
|
|
43
|
+
* when the pointer is. The probe can find a parent instead of the block on
|
|
44
|
+
* the line (e.g. left of a nested block, the element is the parent). Thus the
|
|
45
|
+
* function then goes down into the children of the found block, by their
|
|
46
|
+
* boxes, to the deepest block at the pointer's height.
|
|
47
|
+
*/
|
|
48
|
+
function probeBlockAtHeight(
|
|
49
|
+
view: EditorView,
|
|
50
|
+
pointer: Point,
|
|
51
|
+
): Element | undefined {
|
|
52
|
+
const blocks = view.dom.firstElementChild?.getBoundingClientRect();
|
|
53
|
+
if (!blocks || pointer.y < blocks.top || pointer.y > blocks.bottom) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const inset = Math.min(PROBE_INSET, blocks.width / 2);
|
|
57
|
+
const reference = getBlockAtPoint(view, {
|
|
58
|
+
x: clamp(pointer.x, blocks.left + inset, blocks.right - inset),
|
|
59
|
+
y: pointer.y,
|
|
60
|
+
});
|
|
61
|
+
return reference ? getNestedBlockAtCursor(reference, pointer) : undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type HoverResolution =
|
|
65
|
+
/** The pointer is over this block (directly, or at its height). */
|
|
66
|
+
| { kind: "block"; block: HoveredBlock }
|
|
67
|
+
/** The pointer is over UI that belongs to this editor; keep the menu as is. */
|
|
68
|
+
| { kind: "editorUI" }
|
|
69
|
+
/** The pointer is not over this editor's blocks. */
|
|
70
|
+
| { kind: "none" };
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Which of this editor's blocks the pointer is about, from the topmost element
|
|
74
|
+
* under the pointer (the event target).
|
|
75
|
+
*/
|
|
76
|
+
export function resolveHoveredBlock(
|
|
77
|
+
view: EditorView,
|
|
78
|
+
target: Element | null,
|
|
79
|
+
pointer: Point,
|
|
80
|
+
/** Whether blocks of this type get a drag handle. */
|
|
81
|
+
isDraggable: (type: string) => boolean,
|
|
82
|
+
/** Whether the element is UI that belongs to this editor (a toolbar, a menu). */
|
|
83
|
+
isWithinEditorUI: (element: Element) => boolean,
|
|
84
|
+
/** How far left or right of the editor element the pointer still counts (px). */
|
|
85
|
+
hoverMargin: number,
|
|
86
|
+
): HoverResolution {
|
|
87
|
+
// Resolve layout before applying drag policy: columns have no handle, but
|
|
88
|
+
// their children do, and their gutter still needs to resolve those children.
|
|
89
|
+
function draggable(block: Element | undefined): HoverResolution {
|
|
90
|
+
const resolved = block
|
|
91
|
+
? getDraggableBlockFromElement(block, view, isDraggable)
|
|
92
|
+
: undefined;
|
|
93
|
+
return resolved ? { kind: "block", block: resolved } : { kind: "none" };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (target && view.dom.contains(target)) {
|
|
97
|
+
// Embedded editors own their blocks, even though their DOM is inside ours.
|
|
98
|
+
if (target.closest(".bn-editor") !== view.dom) {
|
|
99
|
+
return { kind: "none" };
|
|
100
|
+
}
|
|
101
|
+
// Over a block (its content, its indentation, a container's padding):
|
|
102
|
+
// the deepest block at the pointer's height. Over the editor's own
|
|
103
|
+
// padding: no block is known yet, so probe for the one on the line.
|
|
104
|
+
const block = getBlockElement(target, view);
|
|
105
|
+
return draggable(
|
|
106
|
+
block
|
|
107
|
+
? getNestedBlockAtCursor(block, pointer)
|
|
108
|
+
: probeBlockAtHeight(view, pointer),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (target && isWithinEditorUI(target)) {
|
|
113
|
+
// A toolbar, a menu, the side menu itself, or the editor's wrapper: the
|
|
114
|
+
// block under that UI is not what the pointer is about.
|
|
115
|
+
return { kind: "editorUI" };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const editorRect = view.dom.getBoundingClientRect();
|
|
119
|
+
|
|
120
|
+
// Something else is painted over the editor (e.g. another editor in an
|
|
121
|
+
// overlay).
|
|
122
|
+
if (
|
|
123
|
+
pointer.x >= editorRect.left &&
|
|
124
|
+
pointer.x <= editorRect.right &&
|
|
125
|
+
pointer.y >= editorRect.top &&
|
|
126
|
+
pointer.y <= editorRect.bottom
|
|
127
|
+
) {
|
|
128
|
+
return { kind: "none" };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Beside the editor element (left or right of it, level with its blocks):
|
|
132
|
+
// only within `hoverMargin`, and not over another editor. Above or below
|
|
133
|
+
// it, no block is at the pointer's height. The gutter where the menu sits
|
|
134
|
+
// is the editor's own padding, handled above.
|
|
135
|
+
const besideEditor =
|
|
136
|
+
pointer.y >= editorRect.top &&
|
|
137
|
+
pointer.y <= editorRect.bottom &&
|
|
138
|
+
Math.max(editorRect.left - pointer.x, pointer.x - editorRect.right) <=
|
|
139
|
+
hoverMargin;
|
|
140
|
+
if (besideEditor && !target?.closest(".bn-editor")) {
|
|
141
|
+
return draggable(probeBlockAtHeight(view, pointer));
|
|
142
|
+
}
|
|
143
|
+
return { kind: "none" };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* How far (in px) outside the intent hull the pointer may stray. A steep exit
|
|
148
|
+
* from a block's corner towards its menu otherwise starts just outside the
|
|
149
|
+
* hull's thin tip.
|
|
150
|
+
*/
|
|
151
|
+
const INTENT_BUFFER = 3;
|
|
152
|
+
|
|
153
|
+
/** The z component of (a - o) × (b - o): its sign says which side of o→a b is. */
|
|
154
|
+
function cross(o: Point, a: Point, b: Point) {
|
|
155
|
+
return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Whether a point is inside the convex polygon (vertices in either order). */
|
|
159
|
+
function isInConvexPolygon(point: Point, polygon: Point[]): boolean {
|
|
160
|
+
let sign = 0;
|
|
161
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
162
|
+
const side = Math.sign(
|
|
163
|
+
cross(polygon[i], polygon[(i + 1) % polygon.length], point),
|
|
164
|
+
);
|
|
165
|
+
if (side === 0) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (sign === 0) {
|
|
169
|
+
sign = side;
|
|
170
|
+
} else if (side !== sign) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function distanceToSegment(point: Point, a: Point, b: Point): number {
|
|
178
|
+
const dx = b.x - a.x;
|
|
179
|
+
const dy = b.y - a.y;
|
|
180
|
+
const lengthSquared = dx * dx + dy * dy;
|
|
181
|
+
const t =
|
|
182
|
+
lengthSquared === 0
|
|
183
|
+
? 0
|
|
184
|
+
: clamp(
|
|
185
|
+
((point.x - a.x) * dx + (point.y - a.y) * dy) / lengthSquared,
|
|
186
|
+
0,
|
|
187
|
+
1,
|
|
188
|
+
);
|
|
189
|
+
return Math.hypot(point.x - (a.x + t * dx), point.y - (a.y + t * dy));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The distance from the point to the rect (0 when it is inside). */
|
|
193
|
+
export function distanceToRect(point: Point, rect: Rect): number {
|
|
194
|
+
return Math.hypot(
|
|
195
|
+
point.x - clamp(point.x, rect.left, rect.right),
|
|
196
|
+
point.y - clamp(point.y, rect.top, rect.bottom),
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Convex hull of a small point set, with Andrew's monotone chain algorithm
|
|
202
|
+
* (https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).
|
|
203
|
+
*/
|
|
204
|
+
function convexHull(points: Point[]): Point[] {
|
|
205
|
+
const sorted = [...points].sort((a, b) => a.x - b.x || a.y - b.y);
|
|
206
|
+
const lower: Point[] = [];
|
|
207
|
+
for (const p of sorted) {
|
|
208
|
+
while (
|
|
209
|
+
lower.length >= 2 &&
|
|
210
|
+
cross(lower[lower.length - 2], lower[lower.length - 1], p) <= 0
|
|
211
|
+
) {
|
|
212
|
+
lower.pop();
|
|
213
|
+
}
|
|
214
|
+
lower.push(p);
|
|
215
|
+
}
|
|
216
|
+
const upper: Point[] = [];
|
|
217
|
+
for (const p of [...sorted].reverse()) {
|
|
218
|
+
while (
|
|
219
|
+
upper.length >= 2 &&
|
|
220
|
+
cross(upper[upper.length - 2], upper[upper.length - 1], p) <= 0
|
|
221
|
+
) {
|
|
222
|
+
upper.pop();
|
|
223
|
+
}
|
|
224
|
+
upper.push(p);
|
|
225
|
+
}
|
|
226
|
+
lower.pop();
|
|
227
|
+
upper.pop();
|
|
228
|
+
return lower.concat(upper);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Whether the pointer is on its way from the exit point to the menu: inside
|
|
233
|
+
* the "triangle" spanned by the exit point and the menu's rect (the convex
|
|
234
|
+
* hull of the point and the rect's corners), or within {@link INTENT_BUFFER}
|
|
235
|
+
* of it, and closer to the menu than the exit point. The latter keeps the
|
|
236
|
+
* buffer around the exit point from holding on to a block the pointer leaves
|
|
237
|
+
* in another direction, e.g. down onto the next block.
|
|
238
|
+
*
|
|
239
|
+
* Similar to Floating UI's `safePolygon`
|
|
240
|
+
* (https://floating-ui.com/docs/useHover#safepolygon), with two differences:
|
|
241
|
+
* the hull covers the way to the menu whatever side the menu is on, and the
|
|
242
|
+
* intent ends when the pointer rests (`INTENT_TIMEOUT` in `SideMenu.ts`)
|
|
243
|
+
* rather than when it slows down, as people slow down when aiming at the
|
|
244
|
+
* menu's small buttons.
|
|
245
|
+
*/
|
|
246
|
+
export function isHeadingToMenu(
|
|
247
|
+
pointer: Point,
|
|
248
|
+
exit: Point,
|
|
249
|
+
menu: Rect,
|
|
250
|
+
): boolean {
|
|
251
|
+
if (distanceToRect(pointer, menu) >= distanceToRect(exit, menu)) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
const hull = convexHull([
|
|
255
|
+
exit,
|
|
256
|
+
{ x: menu.left, y: menu.top },
|
|
257
|
+
{ x: menu.right, y: menu.top },
|
|
258
|
+
{ x: menu.right, y: menu.bottom },
|
|
259
|
+
{ x: menu.left, y: menu.bottom },
|
|
260
|
+
]);
|
|
261
|
+
if (hull.length >= 3 && isInConvexPolygon(pointer, hull)) {
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
// Also covers a degenerate hull (a zero-size menu).
|
|
265
|
+
return hull.some(
|
|
266
|
+
(vertex, i) =>
|
|
267
|
+
distanceToSegment(pointer, vertex, hull[(i + 1) % hull.length]) <=
|
|
268
|
+
INTENT_BUFFER,
|
|
269
|
+
);
|
|
270
|
+
}
|
|
@@ -30,7 +30,7 @@ export const SourceBlockWithPreviewExtension = createExtension(
|
|
|
30
30
|
// `meta.hasPreview` (read from the spec, like the syntax-highlighting
|
|
31
31
|
// extension reads `meta.highlight`).
|
|
32
32
|
const blockHasPreview = (block: Block<any, any, any>) =>
|
|
33
|
-
!!editor.schema.blockSpecs[block.type]?.implementation
|
|
33
|
+
!!editor.schema.blockSpecs[block.type]?.implementation.meta.hasPreview;
|
|
34
34
|
|
|
35
35
|
const handleArrow =
|
|
36
36
|
(direction: "prev" | "next") =>
|
|
@@ -57,7 +57,8 @@ export const SourceBlockWithPreviewExtension = createExtension(
|
|
|
57
57
|
key: "sourceBlockWithPreview",
|
|
58
58
|
store,
|
|
59
59
|
keyboardShortcuts: {
|
|
60
|
-
// Toggles the popup
|
|
60
|
+
// Toggles the popup, unless Enter inserts line breaks in the block
|
|
61
|
+
// (`keyboard.enter: "line-break"`).
|
|
61
62
|
Enter: ({ editor }) => {
|
|
62
63
|
const { block } = editor.getTextCursorPosition();
|
|
63
64
|
if (!blockHasPreview(block)) {
|
|
@@ -66,8 +67,8 @@ export const SourceBlockWithPreviewExtension = createExtension(
|
|
|
66
67
|
|
|
67
68
|
if (
|
|
68
69
|
store.state.popupOpen === block.id &&
|
|
69
|
-
editor.schema.blockSpecs[block.type]
|
|
70
|
-
|
|
70
|
+
editor.schema.blockSpecs[block.type].implementation.keyboard(block)
|
|
71
|
+
.enter === "line-break"
|
|
71
72
|
) {
|
|
72
73
|
const view = editor.prosemirrorView!;
|
|
73
74
|
view.dispatch(view.state.tr.insertText("\n"));
|
|
@@ -49,7 +49,7 @@ class SuggestionMenuView {
|
|
|
49
49
|
this.rootEl?.addEventListener("scroll", this.handleScroll, true);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
handleScroll = () => {
|
|
52
|
+
handleScroll = (event: Event) => {
|
|
53
53
|
if (this.state?.show) {
|
|
54
54
|
const decorationNode = this.rootEl?.querySelector(
|
|
55
55
|
`[data-decoration-id="${this.pluginState!.decorationId}"]`,
|
|
@@ -57,6 +57,15 @@ class SuggestionMenuView {
|
|
|
57
57
|
if (!decorationNode) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
+
// Only a scroll of an ancestor of the cursor can move the menu's
|
|
61
|
+
// reference. The menu's own scroll (it is in the editor's subtree, so
|
|
62
|
+
// this capture listener sees it) must not reposition it.
|
|
63
|
+
if (
|
|
64
|
+
event.target instanceof Node &&
|
|
65
|
+
!event.target.contains(decorationNode)
|
|
66
|
+
) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
60
69
|
this.state.referencePos = decorationNode
|
|
61
70
|
.getBoundingClientRect()
|
|
62
71
|
.toJSON() as DOMRect;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Block, PartialBlock } from "../../blocks/defaultBlocks.js";
|
|
2
2
|
import { editorHasBlockWithType } from "../../blocks/defaultBlockTypeGuards.js";
|
|
3
|
+
import {
|
|
4
|
+
type DefaultBlockTypeItem,
|
|
5
|
+
getDefaultBlockTypeItems,
|
|
6
|
+
} from "../../blocks/defaultBlockTypeItems.js";
|
|
3
7
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
4
8
|
import {
|
|
5
9
|
BlockSchema,
|
|
@@ -99,103 +103,39 @@ export function getDefaultSlashMenuItems<
|
|
|
99
103
|
>(editor: BlockNoteEditor<BSchema, I, S>) {
|
|
100
104
|
const items: DefaultSuggestionItem[] = [];
|
|
101
105
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
},
|
|
113
|
-
badge: formatKeyboardShortcut(`Mod-Alt-${level}`),
|
|
114
|
-
key:
|
|
115
|
-
level === 1 ? ("heading" as const) : (`heading_${level}` as const),
|
|
116
|
-
...editor.dictionary.slash_menu[
|
|
117
|
-
level === 1 ? ("heading" as const) : (`heading_${level}` as const)
|
|
118
|
-
],
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (editorHasBlockWithType(editor, "quote")) {
|
|
124
|
-
items.push({
|
|
125
|
-
onItemClick: () => {
|
|
126
|
-
insertOrUpdateBlockForSlashMenu(editor, {
|
|
127
|
-
type: "quote",
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
|
-
key: "quote",
|
|
131
|
-
...editor.dictionary.slash_menu.quote,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (editorHasBlockWithType(editor, "toggleListItem")) {
|
|
136
|
-
items.push({
|
|
137
|
-
onItemClick: () => {
|
|
138
|
-
insertOrUpdateBlockForSlashMenu(editor, {
|
|
139
|
-
type: "toggleListItem",
|
|
140
|
-
});
|
|
141
|
-
},
|
|
142
|
-
badge: formatKeyboardShortcut("Mod-Shift-6"),
|
|
143
|
-
key: "toggle_list",
|
|
144
|
-
...editor.dictionary.slash_menu.toggle_list,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (editorHasBlockWithType(editor, "numberedListItem")) {
|
|
149
|
-
items.push({
|
|
150
|
-
onItemClick: () => {
|
|
151
|
-
insertOrUpdateBlockForSlashMenu(editor, {
|
|
152
|
-
type: "numberedListItem",
|
|
153
|
-
});
|
|
154
|
-
},
|
|
155
|
-
badge: formatKeyboardShortcut("Mod-Shift-7"),
|
|
156
|
-
key: "numbered_list",
|
|
157
|
-
...editor.dictionary.slash_menu.numbered_list,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (editorHasBlockWithType(editor, "bulletListItem")) {
|
|
162
|
-
items.push({
|
|
163
|
-
onItemClick: () => {
|
|
164
|
-
insertOrUpdateBlockForSlashMenu(editor, {
|
|
165
|
-
type: "bulletListItem",
|
|
166
|
-
});
|
|
167
|
-
},
|
|
168
|
-
badge: formatKeyboardShortcut("Mod-Shift-8"),
|
|
169
|
-
key: "bullet_list",
|
|
170
|
-
...editor.dictionary.slash_menu.bullet_list,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (editorHasBlockWithType(editor, "checkListItem")) {
|
|
106
|
+
// The block types come from `getDefaultBlockTypeItems`, which the block
|
|
107
|
+
// type select also uses. The slash menu places them in its own order.
|
|
108
|
+
const blockTypes = new Map(
|
|
109
|
+
getDefaultBlockTypeItems(editor).map((item) => [item.key, item]),
|
|
110
|
+
);
|
|
111
|
+
function pushBlockType(key: DefaultBlockTypeItem["key"], badge?: string) {
|
|
112
|
+
const blockType = blockTypes.get(key);
|
|
113
|
+
if (!blockType) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
175
116
|
items.push({
|
|
176
117
|
onItemClick: () => {
|
|
118
|
+
// The schema supports the block type (see `getDefaultBlockTypeItems`).
|
|
177
119
|
insertOrUpdateBlockForSlashMenu(editor, {
|
|
178
|
-
type:
|
|
179
|
-
|
|
120
|
+
type: blockType.type,
|
|
121
|
+
props: blockType.props,
|
|
122
|
+
} as PartialBlock<BSchema, I, S>);
|
|
180
123
|
},
|
|
181
|
-
badge
|
|
182
|
-
key
|
|
183
|
-
...editor.dictionary.slash_menu
|
|
124
|
+
badge,
|
|
125
|
+
key,
|
|
126
|
+
...editor.dictionary.slash_menu[key],
|
|
184
127
|
});
|
|
185
128
|
}
|
|
186
129
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
...editor.dictionary.slash_menu.paragraph,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
130
|
+
pushBlockType("heading", formatKeyboardShortcut("Mod-Alt-1"));
|
|
131
|
+
pushBlockType("heading_2", formatKeyboardShortcut("Mod-Alt-2"));
|
|
132
|
+
pushBlockType("heading_3", formatKeyboardShortcut("Mod-Alt-3"));
|
|
133
|
+
pushBlockType("quote");
|
|
134
|
+
pushBlockType("toggle_list", formatKeyboardShortcut("Mod-Shift-6"));
|
|
135
|
+
pushBlockType("numbered_list", formatKeyboardShortcut("Mod-Shift-7"));
|
|
136
|
+
pushBlockType("bullet_list", formatKeyboardShortcut("Mod-Shift-8"));
|
|
137
|
+
pushBlockType("check_list", formatKeyboardShortcut("Mod-Shift-9"));
|
|
138
|
+
pushBlockType("paragraph", formatKeyboardShortcut("Mod-Alt-0"));
|
|
199
139
|
|
|
200
140
|
if (editorHasBlockWithType(editor, "codeBlock")) {
|
|
201
141
|
items.push({
|
|
@@ -324,52 +264,12 @@ export function getDefaultSlashMenuItems<
|
|
|
324
264
|
});
|
|
325
265
|
}
|
|
326
266
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
)
|
|
333
|
-
(editor.schema.blockSchema.heading.propSchema.level.values || [])
|
|
334
|
-
.filter((level): level is 1 | 2 | 3 => level <= 3)
|
|
335
|
-
.forEach((level) => {
|
|
336
|
-
items.push({
|
|
337
|
-
onItemClick: () => {
|
|
338
|
-
insertOrUpdateBlockForSlashMenu(editor, {
|
|
339
|
-
type: "heading",
|
|
340
|
-
props: { level: level, isToggleable: true },
|
|
341
|
-
});
|
|
342
|
-
},
|
|
343
|
-
key:
|
|
344
|
-
level === 1
|
|
345
|
-
? ("toggle_heading" as const)
|
|
346
|
-
: (`toggle_heading_${level}` as const),
|
|
347
|
-
...editor.dictionary.slash_menu[
|
|
348
|
-
level === 1
|
|
349
|
-
? ("toggle_heading" as const)
|
|
350
|
-
: (`toggle_heading_${level}` as const)
|
|
351
|
-
],
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
if (editorHasBlockWithType(editor, "heading", { level: "number" })) {
|
|
357
|
-
(editor.schema.blockSchema.heading.propSchema.level.values || [])
|
|
358
|
-
.filter((level): level is 4 | 5 | 6 => level > 3)
|
|
359
|
-
.forEach((level) => {
|
|
360
|
-
items.push({
|
|
361
|
-
onItemClick: () => {
|
|
362
|
-
insertOrUpdateBlockForSlashMenu(editor, {
|
|
363
|
-
type: "heading",
|
|
364
|
-
props: { level: level },
|
|
365
|
-
});
|
|
366
|
-
},
|
|
367
|
-
badge: formatKeyboardShortcut(`Mod-Alt-${level}`),
|
|
368
|
-
key: `heading_${level}`,
|
|
369
|
-
...editor.dictionary.slash_menu[`heading_${level}`],
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
}
|
|
267
|
+
pushBlockType("toggle_heading");
|
|
268
|
+
pushBlockType("toggle_heading_2");
|
|
269
|
+
pushBlockType("toggle_heading_3");
|
|
270
|
+
pushBlockType("heading_4", formatKeyboardShortcut("Mod-Alt-4"));
|
|
271
|
+
pushBlockType("heading_5", formatKeyboardShortcut("Mod-Alt-5"));
|
|
272
|
+
pushBlockType("heading_6", formatKeyboardShortcut("Mod-Alt-6"));
|
|
373
273
|
|
|
374
274
|
items.push({
|
|
375
275
|
onItemClick: () => {
|
|
@@ -10,14 +10,24 @@ import {
|
|
|
10
10
|
|
|
11
11
|
describe("SyntaxHighlightingExtension", () => {
|
|
12
12
|
// The extension only reads `editor.schema.blockSpecs` and
|
|
13
|
-
// `inlineContentSpecs`, so a minimal stub is enough.
|
|
13
|
+
// `inlineContentSpecs`, so a minimal stub is enough. A spec in a schema
|
|
14
|
+
// always carries its resolved `meta`.
|
|
14
15
|
const fakeEditor = () =>
|
|
15
16
|
({
|
|
16
17
|
schema: {
|
|
17
18
|
blockSpecs: {
|
|
18
|
-
paragraph: {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
paragraph: {
|
|
20
|
+
config: { type: "paragraph", content: "inline" },
|
|
21
|
+
implementation: { meta: {} },
|
|
22
|
+
},
|
|
23
|
+
codeBlock: {
|
|
24
|
+
config: { type: "codeBlock", content: "plain" },
|
|
25
|
+
implementation: { meta: {} },
|
|
26
|
+
},
|
|
27
|
+
image: {
|
|
28
|
+
config: { type: "image", content: "none" },
|
|
29
|
+
implementation: { meta: {} },
|
|
30
|
+
},
|
|
21
31
|
},
|
|
22
32
|
inlineContentSpecs: {},
|
|
23
33
|
},
|