@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,5 +1,6 @@
|
|
|
1
1
|
import { Mark, Node, Slice } from "@tiptap/pm/model";
|
|
2
2
|
import type { Block } from "../../blocks/defaultBlocks.js";
|
|
3
|
+
import { isLayoutNode } from "../../schema/blocks/children.js";
|
|
3
4
|
import UniqueID from "../../extensions/tiptap-extensions/UniqueID/UniqueID.js";
|
|
4
5
|
import type {
|
|
5
6
|
BlockSchema,
|
|
@@ -19,8 +20,9 @@ import {
|
|
|
19
20
|
} from "../../schema/inlineContent/types.js";
|
|
20
21
|
import { UnreachableCaseError } from "../../util/typescript.js";
|
|
21
22
|
import {
|
|
22
|
-
|
|
23
|
+
getBlockInfoFromNode,
|
|
23
24
|
getNodeId,
|
|
25
|
+
isSuggestedDeletionNode,
|
|
24
26
|
} from "../getBlockInfoFromPos.js";
|
|
25
27
|
import {
|
|
26
28
|
getBlockCache,
|
|
@@ -29,6 +31,32 @@ import {
|
|
|
29
31
|
getStyleSchema,
|
|
30
32
|
} from "../pmUtil.js";
|
|
31
33
|
|
|
34
|
+
/**
|
|
35
|
+
* The text of a plain content node. Plain content can't carry marks, so text
|
|
36
|
+
* marked as deleted (in a version diff or a suggestion) would merge with its
|
|
37
|
+
* replacement (e.g. `x^2` → `y^3` reads `xy^23`) - keep only the result.
|
|
38
|
+
*
|
|
39
|
+
* Styled text (`contentNodeToInlineContent`) still includes deleted text; see
|
|
40
|
+
* the note there.
|
|
41
|
+
*
|
|
42
|
+
* TODO(suggestion mode): Do NOT keep this behavior when we implement suggestion
|
|
43
|
+
* mode. Converting nodes to blocks must preserve pending suggestions, not
|
|
44
|
+
* silently read deletions as accepted in `editor.document`, `onChange` or exports.
|
|
45
|
+
* We only accept filtering here because plain text content has no good
|
|
46
|
+
* representation of inline formatting, including insertion/deletion marks, and
|
|
47
|
+
* merging both versions produces invalid preview source. Suggestion mode needs
|
|
48
|
+
* to preserve that information and resolve the preview source separately.
|
|
49
|
+
*/
|
|
50
|
+
function plainContentText(node: Node): string {
|
|
51
|
+
let text = "";
|
|
52
|
+
node.forEach((child) => {
|
|
53
|
+
if (!isSuggestedDeletionNode(child)) {
|
|
54
|
+
text += child.textContent;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return text;
|
|
58
|
+
}
|
|
59
|
+
|
|
32
60
|
/**
|
|
33
61
|
* Converts an internal (prosemirror) table node contentto a BlockNote Tablecontent
|
|
34
62
|
*/
|
|
@@ -147,6 +175,12 @@ export function contentNodeToInlineContent<
|
|
|
147
175
|
const content: InlineContent<any, S>[] = [];
|
|
148
176
|
let currentContent: InlineContent<any, S> | undefined = undefined;
|
|
149
177
|
|
|
178
|
+
// NOTE: unlike plain content (`plainContentText`), text marked as deleted in
|
|
179
|
+
// a version diff or suggestion is kept here, merged with its replacement. We
|
|
180
|
+
// might want to filter it too, but that changes what `editor.document`,
|
|
181
|
+
// `onChange` and exports report while suggestions show, and makes a block
|
|
182
|
+
// whose text is all deleted read as empty.
|
|
183
|
+
|
|
150
184
|
// Most of the logic below is for handling links because in ProseMirror links are marks
|
|
151
185
|
// while in BlockNote links are a type of inline content
|
|
152
186
|
contentNode.content.forEach((node) => {
|
|
@@ -375,7 +409,7 @@ export function nodeToCustomInlineContent<
|
|
|
375
409
|
) as any; // TODO: is this safe? could we have Links here that are undesired?
|
|
376
410
|
} else if (icConfig.content === "plain") {
|
|
377
411
|
// Plain inline content is a single unstyled string.
|
|
378
|
-
content = node
|
|
412
|
+
content = plainContentText(node) as any;
|
|
379
413
|
} else {
|
|
380
414
|
content = undefined;
|
|
381
415
|
}
|
|
@@ -402,7 +436,7 @@ export function nodeToBlock<
|
|
|
402
436
|
const styleSchema = getStyleSchema(schema) as S;
|
|
403
437
|
const blockCache = getBlockCache(schema);
|
|
404
438
|
if (!node.type.isInGroup("bnBlock")) {
|
|
405
|
-
throw Error("Node should be a
|
|
439
|
+
throw Error("Node should be a block, but is instead: " + node.type.name);
|
|
406
440
|
}
|
|
407
441
|
|
|
408
442
|
const cachedBlock = blockCache?.get(node);
|
|
@@ -411,28 +445,28 @@ export function nodeToBlock<
|
|
|
411
445
|
return cachedBlock;
|
|
412
446
|
}
|
|
413
447
|
|
|
414
|
-
const blockInfo =
|
|
448
|
+
const blockInfo = getBlockInfoFromNode(node, 0);
|
|
415
449
|
|
|
416
450
|
let id: string;
|
|
417
451
|
try {
|
|
418
|
-
id = getNodeId(blockInfo.
|
|
452
|
+
id = getNodeId(blockInfo.block.node, doc);
|
|
419
453
|
} catch {
|
|
420
454
|
// Only used for blocks converted from other formats.
|
|
421
455
|
id = UniqueID.options.generateID();
|
|
422
456
|
}
|
|
423
457
|
|
|
424
|
-
const
|
|
458
|
+
const blockConfig = blockSchema[blockInfo.blockNoteType];
|
|
425
459
|
|
|
426
|
-
if (!
|
|
460
|
+
if (!blockConfig) {
|
|
427
461
|
throw Error("Block is of an unrecognized type: " + blockInfo.blockNoteType);
|
|
428
462
|
}
|
|
429
463
|
|
|
430
464
|
const props: any = {};
|
|
431
465
|
for (const [attr, value] of Object.entries({
|
|
432
466
|
...node.attrs,
|
|
433
|
-
...(blockInfo.
|
|
467
|
+
...(blockInfo.hasContent ? blockInfo.content.node.attrs : {}),
|
|
434
468
|
})) {
|
|
435
|
-
const propSchema =
|
|
469
|
+
const propSchema = blockConfig.propSchema;
|
|
436
470
|
|
|
437
471
|
if (
|
|
438
472
|
attr in propSchema &&
|
|
@@ -442,45 +476,43 @@ export function nodeToBlock<
|
|
|
442
476
|
}
|
|
443
477
|
}
|
|
444
478
|
|
|
445
|
-
const blockConfig = blockSchema[blockInfo.blockNoteType];
|
|
446
|
-
|
|
447
479
|
const children: Block<BSchema, I, S>[] = [];
|
|
448
|
-
blockInfo.
|
|
480
|
+
blockInfo.children?.node.forEach((child) => {
|
|
449
481
|
children.push(nodeToBlock(child, doc));
|
|
450
482
|
});
|
|
451
483
|
|
|
452
484
|
let content: Block<any, any, any>["content"];
|
|
453
485
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
486
|
+
// BlockInfo has already established whether content exists and its kind.
|
|
487
|
+
// Conversion only interprets that content; it does not resolve shape again.
|
|
488
|
+
switch (blockInfo.contentKind) {
|
|
489
|
+
case "inline":
|
|
490
|
+
content = contentNodeToInlineContent(
|
|
491
|
+
blockInfo.content.node,
|
|
492
|
+
inlineContentSchema,
|
|
493
|
+
styleSchema,
|
|
494
|
+
);
|
|
495
|
+
break;
|
|
496
|
+
case "table":
|
|
497
|
+
content = contentNodeToTableContent(
|
|
498
|
+
blockInfo.content.node,
|
|
499
|
+
inlineContentSchema,
|
|
500
|
+
styleSchema,
|
|
501
|
+
);
|
|
502
|
+
break;
|
|
503
|
+
case "plain": {
|
|
504
|
+
// Plain content is a single unstyled text item; an empty block is an
|
|
505
|
+
// empty array, matching inline content.
|
|
506
|
+
const text = plainContentText(blockInfo.content.node);
|
|
507
|
+
content = text.length > 0 ? [{ type: "text", text, styles: {} }] : [];
|
|
508
|
+
break;
|
|
475
509
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
} else {
|
|
483
|
-
throw new UnreachableCaseError(blockConfig.content);
|
|
510
|
+
case "none":
|
|
511
|
+
case undefined:
|
|
512
|
+
content = undefined;
|
|
513
|
+
break;
|
|
514
|
+
default:
|
|
515
|
+
throw new UnreachableCaseError(blockInfo);
|
|
484
516
|
}
|
|
485
517
|
|
|
486
518
|
const block = {
|
|
@@ -563,45 +595,58 @@ export function prosemirrorSliceToSlicedBlocks<
|
|
|
563
595
|
blockCutAtStart: string | undefined;
|
|
564
596
|
blockCutAtEnd: string | undefined;
|
|
565
597
|
} {
|
|
566
|
-
|
|
598
|
+
// Both `blockGroup` and layout block nodes (columnList, column, callout,
|
|
599
|
+
// ...) hold block children directly, so both can be processed here.
|
|
600
|
+
if (node.type.name !== "blockGroup" && !isLayoutNode(node.type)) {
|
|
567
601
|
throw new Error("unexpected");
|
|
568
602
|
}
|
|
569
603
|
const blocks: Block<BSchema, I, S>[] = [];
|
|
570
604
|
let blockCutAtStart: string | undefined;
|
|
571
605
|
let blockCutAtEnd: string | undefined;
|
|
572
606
|
|
|
573
|
-
node
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
if (blockContainer.childCount === 0) {
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
if (blockContainer.childCount === 0 || blockContainer.childCount > 2) {
|
|
581
|
-
throw new Error(
|
|
582
|
-
"unexpected, blockContainer.childCount: " + blockContainer.childCount,
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
|
|
607
|
+
// Each child is a block's node: a `blockContainer` for a regular block,
|
|
608
|
+
// or a layout block node (columnList, column, callout, ...) for a layout block
|
|
609
|
+
// block.
|
|
610
|
+
node.forEach((blockNode, _offset, index) => {
|
|
586
611
|
const isFirstBlock = index === 0;
|
|
587
612
|
const isLastBlock = index === node.childCount - 1;
|
|
588
613
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
// A
|
|
593
|
-
// ├── B
|
|
594
|
-
// selection starts within B, then this blockContainer is A, but we don't care about A
|
|
595
|
-
// so let's descend into B and continue processing
|
|
596
|
-
if (!isFirstBlock) {
|
|
614
|
+
const isLayoutBlock = isLayoutNode(blockNode.type);
|
|
615
|
+
if (!isLayoutBlock) {
|
|
616
|
+
if (blockNode.type.name !== "blockContainer") {
|
|
597
617
|
throw new Error("unexpected");
|
|
598
618
|
}
|
|
619
|
+
if (blockNode.childCount === 0) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (blockNode.childCount > 2) {
|
|
623
|
+
throw new Error(
|
|
624
|
+
"unexpected, blockContainer.childCount: " + blockNode.childCount,
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const omittedParent =
|
|
630
|
+
!isLayoutBlock && blockNode.firstChild!.type.name === "blockGroup";
|
|
631
|
+
if (omittedParent && !isFirstBlock) {
|
|
632
|
+
throw new Error("unexpected");
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// Open layout blocks and regular parents whose content was cut away both
|
|
636
|
+
// contribute their selected children, without their own wrapper.
|
|
637
|
+
if (
|
|
638
|
+
omittedParent ||
|
|
639
|
+
(isLayoutBlock &&
|
|
640
|
+
((isFirstBlock && openStart > 0) || (isLastBlock && openEnd > 0)))
|
|
641
|
+
) {
|
|
599
642
|
const ret = processNode(
|
|
600
|
-
|
|
601
|
-
Math.max(0, openStart - 1),
|
|
643
|
+
isLayoutBlock ? blockNode : blockNode.firstChild!,
|
|
644
|
+
isFirstBlock ? Math.max(0, openStart - 1) : 0,
|
|
602
645
|
isLastBlock ? Math.max(0, openEnd - 1) : 0,
|
|
603
646
|
);
|
|
604
|
-
|
|
647
|
+
if (isFirstBlock) {
|
|
648
|
+
blockCutAtStart = ret.blockCutAtStart;
|
|
649
|
+
}
|
|
605
650
|
if (isLastBlock) {
|
|
606
651
|
blockCutAtEnd = ret.blockCutAtEnd;
|
|
607
652
|
}
|
|
@@ -609,9 +654,16 @@ export function prosemirrorSliceToSlicedBlocks<
|
|
|
609
654
|
return;
|
|
610
655
|
}
|
|
611
656
|
|
|
612
|
-
|
|
657
|
+
if (isLayoutBlock) {
|
|
658
|
+
blocks.push(
|
|
659
|
+
nodeToBlock<BSchema, I, S>(blockNode, slice.content.firstChild!),
|
|
660
|
+
);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
const block = nodeToBlock(blockNode, slice.content.firstChild!);
|
|
613
665
|
const childGroup =
|
|
614
|
-
|
|
666
|
+
blockNode.childCount > 1 ? blockNode.child(1) : undefined;
|
|
615
667
|
|
|
616
668
|
let childBlocks: Block<BSchema, I, S>[] = [];
|
|
617
669
|
if (childGroup) {
|
package/src/api/nodeUtil.ts
CHANGED
|
@@ -18,7 +18,7 @@ export function getNodeById(
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// Keeps traversing nodes if block with target ID has not been found. Some
|
|
21
|
-
//
|
|
21
|
+
// block nodes we merely pass over (e.g. `column`/`columnList`) may not
|
|
22
22
|
// carry an id — skip them without calling the throwing `getNodeId`, which
|
|
23
23
|
// errors on id-less nodes. Only nodes that actually have an id are compared.
|
|
24
24
|
if (!isNodeBlock(node) || !node.attrs.id || getNodeId(node, doc) !== id) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { findLinks } from "../../../extensions/tiptap-extensions/Link/helpers/linkDetector.js";
|
|
2
|
+
|
|
3
|
+
export type AutolinkLiteral = {
|
|
4
|
+
value: string;
|
|
5
|
+
href: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function parseAutolinkLiteral(
|
|
9
|
+
candidate: string,
|
|
10
|
+
): AutolinkLiteral | undefined {
|
|
11
|
+
if (!/^(https?:\/\/|www\.)/i.test(candidate)) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Markdown leaves entity-like suffixes outside an autolink.
|
|
16
|
+
const value = candidate.replace(/&[a-zA-Z0-9]+;$/, "");
|
|
17
|
+
const match = findLinks(value, { defaultProtocol: "http" })[0];
|
|
18
|
+
if (!match || match.start !== 0) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return { value: match.value, href: match.href };
|
|
23
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { isVideoUrl } from "../../../util/string.js";
|
|
2
|
+
import { findLinks } from "../../../extensions/tiptap-extensions/Link/helpers/linkDetector.js";
|
|
3
|
+
import { parseAutolinkLiteral } from "./autolink.js";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Custom markdown-to-HTML converter for BlockNote.
|
|
@@ -41,6 +43,7 @@ function isIntraword(text: string, i: number, delimLen: number): boolean {
|
|
|
41
43
|
type InlineTokenizer = (
|
|
42
44
|
text: string,
|
|
43
45
|
i: number,
|
|
46
|
+
allowLinks: boolean,
|
|
44
47
|
) => { html: string; end: number } | null;
|
|
45
48
|
|
|
46
49
|
function tryBackslashEscape(
|
|
@@ -92,19 +95,80 @@ function tryLink(
|
|
|
92
95
|
return parseLink(text, i);
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
function tryAutolink(
|
|
99
|
+
text: string,
|
|
100
|
+
i: number,
|
|
101
|
+
): { html: string; end: number } | null {
|
|
102
|
+
const rest = text.substring(i);
|
|
103
|
+
|
|
104
|
+
// CommonMark autolinks: <scheme:destination> and <email@example.com>.
|
|
105
|
+
if (text[i] === "<") {
|
|
106
|
+
const urlMatch = rest.match(/^<([a-zA-Z][a-zA-Z0-9+.-]{1,31}:[^\s<>]*)>/);
|
|
107
|
+
if (urlMatch) {
|
|
108
|
+
const url = urlMatch[1];
|
|
109
|
+
return {
|
|
110
|
+
html: `<a href="${escapeHtml(url)}">${escapeHtml(url)}</a>`,
|
|
111
|
+
end: i + urlMatch[0].length,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const emailMatch = rest.match(/^<([^\s<>]+)>/);
|
|
116
|
+
const email = emailMatch?.[1];
|
|
117
|
+
const detectedEmail = email
|
|
118
|
+
? findLinks(email).find(
|
|
119
|
+
(match) =>
|
|
120
|
+
match.type === "email" &&
|
|
121
|
+
match.start === 0 &&
|
|
122
|
+
match.end === email.length,
|
|
123
|
+
)
|
|
124
|
+
: undefined;
|
|
125
|
+
if (emailMatch && email && detectedEmail) {
|
|
126
|
+
return {
|
|
127
|
+
html: `<a href="${escapeHtml(detectedEmail.href)}">${escapeHtml(email)}</a>`,
|
|
128
|
+
end: i + emailMatch[0].length,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// GFM autolink literals. Only start at a word boundary, so URL-like text
|
|
136
|
+
// embedded in a larger word remains plain text.
|
|
137
|
+
if (i > 0 && /[a-zA-Z0-9_]/.test(text[i - 1])) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const literalMatch = rest.match(/^(https?:\/\/|www\.)[^\s<>]+/i);
|
|
142
|
+
if (!literalMatch) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const autolink = parseAutolinkLiteral(literalMatch[0]);
|
|
147
|
+
if (!autolink) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
html: `<a href="${escapeHtml(autolink.href)}">${escapeHtml(autolink.value)}</a>`,
|
|
153
|
+
end: i + autolink.value.length,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
95
157
|
function tryStrikethrough(
|
|
96
158
|
text: string,
|
|
97
159
|
i: number,
|
|
160
|
+
allowLinks: boolean,
|
|
98
161
|
): { html: string; end: number } | null {
|
|
99
162
|
if (text[i] !== "~" || text[i + 1] !== "~") {
|
|
100
163
|
return null;
|
|
101
164
|
}
|
|
102
|
-
return parseDelimited(text, i, "~~", "<del>", "</del>");
|
|
165
|
+
return parseDelimited(text, i, "~~", "<del>", "</del>", allowLinks);
|
|
103
166
|
}
|
|
104
167
|
|
|
105
168
|
function tryBoldItalic(
|
|
106
169
|
text: string,
|
|
107
170
|
i: number,
|
|
171
|
+
allowLinks: boolean,
|
|
108
172
|
): { html: string; end: number } | null {
|
|
109
173
|
if (
|
|
110
174
|
(text[i] === "*" && text[i + 1] === "*" && text[i + 2] === "*") ||
|
|
@@ -114,7 +178,14 @@ function tryBoldItalic(
|
|
|
114
178
|
!isIntraword(text, i, 3))
|
|
115
179
|
) {
|
|
116
180
|
const delimiter = text.substring(i, i + 3);
|
|
117
|
-
return parseDelimited(
|
|
181
|
+
return parseDelimited(
|
|
182
|
+
text,
|
|
183
|
+
i,
|
|
184
|
+
delimiter,
|
|
185
|
+
"<strong><em>",
|
|
186
|
+
"</em></strong>",
|
|
187
|
+
allowLinks,
|
|
188
|
+
);
|
|
118
189
|
}
|
|
119
190
|
return null;
|
|
120
191
|
}
|
|
@@ -122,13 +193,21 @@ function tryBoldItalic(
|
|
|
122
193
|
function tryBold(
|
|
123
194
|
text: string,
|
|
124
195
|
i: number,
|
|
196
|
+
allowLinks: boolean,
|
|
125
197
|
): { html: string; end: number } | null {
|
|
126
198
|
if (
|
|
127
199
|
(text[i] === "*" && text[i + 1] === "*") ||
|
|
128
200
|
(text[i] === "_" && text[i + 1] === "_" && !isIntraword(text, i, 2))
|
|
129
201
|
) {
|
|
130
202
|
const delimiter = text.substring(i, i + 2);
|
|
131
|
-
return parseDelimited(
|
|
203
|
+
return parseDelimited(
|
|
204
|
+
text,
|
|
205
|
+
i,
|
|
206
|
+
delimiter,
|
|
207
|
+
"<strong>",
|
|
208
|
+
"</strong>",
|
|
209
|
+
allowLinks,
|
|
210
|
+
);
|
|
132
211
|
}
|
|
133
212
|
return null;
|
|
134
213
|
}
|
|
@@ -136,9 +215,10 @@ function tryBold(
|
|
|
136
215
|
function tryItalic(
|
|
137
216
|
text: string,
|
|
138
217
|
i: number,
|
|
218
|
+
allowLinks: boolean,
|
|
139
219
|
): { html: string; end: number } | null {
|
|
140
220
|
if (text[i] === "*" || (text[i] === "_" && !isIntraword(text, i, 1))) {
|
|
141
|
-
return parseDelimited(text, i, text[i], "<em>", "</em>");
|
|
221
|
+
return parseDelimited(text, i, text[i], "<em>", "</em>", allowLinks);
|
|
142
222
|
}
|
|
143
223
|
return null;
|
|
144
224
|
}
|
|
@@ -190,6 +270,23 @@ function tryInlineHtml(
|
|
|
190
270
|
/** Characters that can start an inline syntax token. */
|
|
191
271
|
const SPECIAL_CHARS = new Set("\\`![~*_\n<");
|
|
192
272
|
|
|
273
|
+
function canStartInlineToken(text: string, position: number): boolean {
|
|
274
|
+
const char = text[position];
|
|
275
|
+
if (SPECIAL_CHARS.has(char)) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
if (char === "h") {
|
|
279
|
+
return (
|
|
280
|
+
text.startsWith("http://", position) ||
|
|
281
|
+
text.startsWith("https://", position)
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
if (char === "w") {
|
|
285
|
+
return text.startsWith("www.", position);
|
|
286
|
+
}
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
|
|
193
290
|
/**
|
|
194
291
|
* Ordered array of inline tokenizers, tried in priority order.
|
|
195
292
|
* The first match wins.
|
|
@@ -199,6 +296,7 @@ const inlineTokenizers: InlineTokenizer[] = [
|
|
|
199
296
|
tryInlineCode,
|
|
200
297
|
tryImage,
|
|
201
298
|
tryLink,
|
|
299
|
+
tryAutolink,
|
|
202
300
|
tryStrikethrough,
|
|
203
301
|
tryBoldItalic, // *** / ___
|
|
204
302
|
tryBold, // ** / __
|
|
@@ -207,14 +305,19 @@ const inlineTokenizers: InlineTokenizer[] = [
|
|
|
207
305
|
trySoftBreak,
|
|
208
306
|
];
|
|
209
307
|
|
|
308
|
+
const linkTextTokenizers = inlineTokenizers.filter(
|
|
309
|
+
(tokenizer) => tokenizer !== tryLink && tokenizer !== tryAutolink,
|
|
310
|
+
);
|
|
311
|
+
|
|
210
312
|
/**
|
|
211
313
|
* Parse inline markdown syntax and return HTML.
|
|
212
314
|
* Handles: bold, italic, bold+italic, strikethrough, inline code,
|
|
213
315
|
* links, images (with video detection), hard line breaks, backslash escapes.
|
|
214
316
|
*/
|
|
215
|
-
function parseInline(text: string): string {
|
|
317
|
+
function parseInline(text: string, allowLinks = true): string {
|
|
216
318
|
let result = "";
|
|
217
319
|
let i = 0;
|
|
320
|
+
const tokenizers = allowLinks ? inlineTokenizers : linkTextTokenizers;
|
|
218
321
|
|
|
219
322
|
while (i < text.length) {
|
|
220
323
|
// Hard line break: 2+ trailing spaces immediately before a newline.
|
|
@@ -235,9 +338,9 @@ function parseInline(text: string): string {
|
|
|
235
338
|
|
|
236
339
|
// Try each tokenizer in priority order
|
|
237
340
|
let matched = false;
|
|
238
|
-
if (
|
|
239
|
-
for (const tokenizer of
|
|
240
|
-
const r = tokenizer(text, i);
|
|
341
|
+
if (canStartInlineToken(text, i)) {
|
|
342
|
+
for (const tokenizer of tokenizers) {
|
|
343
|
+
const r = tokenizer(text, i, allowLinks);
|
|
241
344
|
if (r) {
|
|
242
345
|
result += r.html;
|
|
243
346
|
i = r.end;
|
|
@@ -251,7 +354,7 @@ function parseInline(text: string): string {
|
|
|
251
354
|
// Batch consecutive plain-text characters and escape once
|
|
252
355
|
const runStart = i;
|
|
253
356
|
i++;
|
|
254
|
-
while (i < text.length && !
|
|
357
|
+
while (i < text.length && !canStartInlineToken(text, i)) {
|
|
255
358
|
i++;
|
|
256
359
|
}
|
|
257
360
|
result += escapeHtml(text.substring(runStart, i));
|
|
@@ -384,7 +487,7 @@ function parseLink(
|
|
|
384
487
|
|
|
385
488
|
const titleAttr = title !== undefined ? ` title="${escapeHtml(title)}"` : "";
|
|
386
489
|
return {
|
|
387
|
-
html: `<a href="${escapeHtml(url)}"${titleAttr}>${parseInline(linkText)}</a>`,
|
|
490
|
+
html: `<a href="${escapeHtml(url)}"${titleAttr}>${parseInline(linkText, false)}</a>`,
|
|
388
491
|
end: parenEnd + 1,
|
|
389
492
|
};
|
|
390
493
|
}
|
|
@@ -488,6 +591,7 @@ function parseDelimited(
|
|
|
488
591
|
delimiter: string,
|
|
489
592
|
openTag: string,
|
|
490
593
|
closeTag: string,
|
|
594
|
+
allowLinks: boolean,
|
|
491
595
|
): { html: string; end: number } | null {
|
|
492
596
|
const len = delimiter.length;
|
|
493
597
|
const afterOpen = start + len;
|
|
@@ -537,7 +641,7 @@ function parseDelimited(
|
|
|
537
641
|
}
|
|
538
642
|
|
|
539
643
|
return {
|
|
540
|
-
html: openTag + parseInline(inner) + closeTag,
|
|
644
|
+
html: openTag + parseInline(inner, allowLinks) + closeTag,
|
|
541
645
|
end: j + len,
|
|
542
646
|
};
|
|
543
647
|
}
|
|
@@ -82,12 +82,12 @@ describe("Code block input rule", () => {
|
|
|
82
82
|
expect((block.props as any).language).toBe("ts");
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
it("converts ``` + space into a codeBlock with
|
|
85
|
+
it("converts ``` + space into a codeBlock with the default language", () => {
|
|
86
86
|
typeString(editor, "``` ");
|
|
87
87
|
|
|
88
88
|
const block = editor.document[0];
|
|
89
89
|
expect(block.type).toBe("codeBlock");
|
|
90
|
-
expect((block.props as any).language).toBe("");
|
|
90
|
+
expect((block.props as any).language).toBe("text");
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
it("converts ```javascript + space into a codeBlock", () => {
|
|
@@ -138,13 +138,13 @@ describe("Code block input rule", () => {
|
|
|
138
138
|
expect(block.content).toEqual([]);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
it("converts ``` + Enter into a codeBlock with
|
|
141
|
+
it("converts ``` + Enter into a codeBlock with the default language", () => {
|
|
142
142
|
typeString(editor, "```");
|
|
143
143
|
pressKey(editor, "Enter");
|
|
144
144
|
|
|
145
145
|
const block = editor.document[0];
|
|
146
146
|
expect(block.type).toBe("codeBlock");
|
|
147
|
-
expect((block.props as any).language).toBe("");
|
|
147
|
+
expect((block.props as any).language).toBe("text");
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
it("converts ```javascript + Enter into a codeBlock", () => {
|
|
@@ -103,8 +103,13 @@ export const CodeKeyboardShortcutsExtension =
|
|
|
103
103
|
find: /^```(.*?)\s$/,
|
|
104
104
|
replace: ({ match }) => {
|
|
105
105
|
const languageName = match[1].trim();
|
|
106
|
+
// Without a language suffix there is nothing to resolve, so fall
|
|
107
|
+
// back to the default rather than storing an empty language that
|
|
108
|
+
// no highlighter can render.
|
|
106
109
|
const attributes = {
|
|
107
|
-
language:
|
|
110
|
+
language:
|
|
111
|
+
getLanguageId(options, languageName) ??
|
|
112
|
+
(languageName || options.defaultLanguage || "text"),
|
|
108
113
|
};
|
|
109
114
|
|
|
110
115
|
return {
|