@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
|
@@ -18,7 +18,7 @@ import type { StyleSchema } from "../../../../schema/styles/types.js";
|
|
|
18
18
|
import { UnreachableCaseError } from "../../../../util/typescript.js";
|
|
19
19
|
import {
|
|
20
20
|
type BlockInfo,
|
|
21
|
-
|
|
21
|
+
getBlockInfoAt,
|
|
22
22
|
} from "../../../getBlockInfoFromPos.js";
|
|
23
23
|
import {
|
|
24
24
|
blockToNode,
|
|
@@ -27,7 +27,11 @@ import {
|
|
|
27
27
|
} from "../../../nodeConversions/blockToNode.js";
|
|
28
28
|
import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js";
|
|
29
29
|
import { getNodeById } from "../../../nodeUtil.js";
|
|
30
|
-
import { getPmSchema } from "../../../pmUtil.js";
|
|
30
|
+
import { getBlockSchema, getPmSchema } from "../../../pmUtil.js";
|
|
31
|
+
import {
|
|
32
|
+
createBlockGroup,
|
|
33
|
+
isLayoutNode,
|
|
34
|
+
} from "../../../../schema/blocks/children.js";
|
|
31
35
|
|
|
32
36
|
// for compatibility with tiptap. TODO: remove as we want to remove dependency on tiptap command interface
|
|
33
37
|
export const updateBlockCommand = <
|
|
@@ -63,12 +67,17 @@ export function updateBlockTr<
|
|
|
63
67
|
replaceFromPos?: number,
|
|
64
68
|
replaceToPos?: number,
|
|
65
69
|
) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
// Positions in `blockInfo` are valid in the doc as it stands now, i.e.
|
|
71
|
+
// after any steps the caller already added to `tr`. Remapping them through
|
|
72
|
+
// the whole `tr.mapping` would apply those caller steps twice, so
|
|
73
|
+
// `restoreCellAnchor` maps through only the steps added below.
|
|
74
|
+
const stepsBefore = tr.mapping.maps.length;
|
|
75
|
+
const blockInfo = getBlockInfoAt(tr.doc, posBeforeBlock);
|
|
76
|
+
|
|
77
|
+
const cellAnchor =
|
|
78
|
+
blockInfo.hasContent && blockInfo.blockNoteType === "table"
|
|
79
|
+
? captureCellAnchor(tr)
|
|
80
|
+
: null;
|
|
72
81
|
|
|
73
82
|
const pmSchema = getPmSchema(tr);
|
|
74
83
|
|
|
@@ -80,81 +89,119 @@ export function updateBlockTr<
|
|
|
80
89
|
throw new Error("Invalid replaceFromPos or replaceToPos");
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const oldNodeType = pmSchema.nodes[blockInfo.blockNoteType];
|
|
86
|
-
const newNodeType = pmSchema.nodes[block.type || blockInfo.blockNoteType];
|
|
92
|
+
const newBlockType = block.type || blockInfo.blockNoteType;
|
|
93
|
+
const newNodeType = pmSchema.nodes[newBlockType];
|
|
87
94
|
const newBnBlockNodeType = newNodeType.isInGroup("bnBlock")
|
|
88
95
|
? newNodeType
|
|
89
96
|
: pmSchema.nodes["blockContainer"];
|
|
90
97
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
98
|
+
const replaceFromOffset =
|
|
99
|
+
blockInfo.hasContent &&
|
|
100
|
+
replaceFromPos !== undefined &&
|
|
101
|
+
replaceFromPos >= blockInfo.contentStart &&
|
|
102
|
+
replaceFromPos <= blockInfo.contentEnd
|
|
103
|
+
? replaceFromPos - blockInfo.contentStart
|
|
104
|
+
: undefined;
|
|
105
|
+
|
|
106
|
+
const replaceToOffset =
|
|
107
|
+
blockInfo.hasContent &&
|
|
108
|
+
replaceToPos !== undefined &&
|
|
109
|
+
replaceToPos >= blockInfo.contentStart &&
|
|
110
|
+
replaceToPos <= blockInfo.contentEnd
|
|
111
|
+
? replaceToPos - blockInfo.contentStart
|
|
112
|
+
: undefined;
|
|
113
|
+
|
|
114
|
+
// Rebuild when the block's shape changes or a layout block's existing children
|
|
115
|
+
// cannot satisfy the new type (e.g. changing to a pair requiring two children).
|
|
116
|
+
if (
|
|
117
|
+
blockInfo.hasContent !== newNodeType.isInGroup("blockContent") ||
|
|
118
|
+
(!blockInfo.hasContent &&
|
|
119
|
+
!newNodeType.validContent(blockInfo.block.node.content))
|
|
120
|
+
) {
|
|
121
|
+
const existingBlock: Block<any, any, any> = nodeToBlock(
|
|
122
|
+
blockInfo.block.node,
|
|
123
|
+
tr.doc,
|
|
117
124
|
);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
const targetConfig = getBlockSchema(pmSchema)[newBlockType];
|
|
126
|
+
let content: PartialBlock<any, any, any>["content"];
|
|
127
|
+
const children: PartialBlock<any, any, any>[] = [...existingBlock.children];
|
|
128
|
+
if (Array.isArray(existingBlock.content) && existingBlock.content.length) {
|
|
129
|
+
if (
|
|
130
|
+
targetConfig.content === "inline" ||
|
|
131
|
+
targetConfig.content === "plain"
|
|
132
|
+
) {
|
|
133
|
+
content = existingBlock.content;
|
|
134
|
+
} else if (isLayoutNode(newNodeType)) {
|
|
135
|
+
children.unshift({ type: "paragraph", content: existingBlock.content });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
131
139
|
const replacementNode = blockToNode(
|
|
132
140
|
{
|
|
133
|
-
|
|
141
|
+
// The rebuilt block keeps its id, so references to it stay valid.
|
|
142
|
+
id: existingBlock.id,
|
|
143
|
+
...(content ? { content } : {}),
|
|
144
|
+
// Omit empty children so a new layout block can seed its required children.
|
|
145
|
+
...(children.length > 0 ? { children } : {}),
|
|
134
146
|
...block,
|
|
135
147
|
},
|
|
136
148
|
pmSchema,
|
|
137
149
|
);
|
|
138
150
|
replacementNode.check(); // `blockToNode` is lenient; validate before mutating the doc
|
|
151
|
+
|
|
152
|
+
// Validate the parent too: a valid column still cannot replace a root block.
|
|
153
|
+
const $oldPos = tr.doc.resolve(blockInfo.block.beforePos);
|
|
154
|
+
if (
|
|
155
|
+
!$oldPos.parent.canReplace(
|
|
156
|
+
$oldPos.index(),
|
|
157
|
+
$oldPos.index(),
|
|
158
|
+
Fragment.from(replacementNode),
|
|
159
|
+
)
|
|
160
|
+
) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`Cannot update block to "${newBlockType}": a "${$oldPos.parent.type.name}" doesn't accept it`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
139
166
|
tr.replaceWith(
|
|
140
|
-
blockInfo.
|
|
141
|
-
blockInfo.
|
|
167
|
+
blockInfo.block.beforePos,
|
|
168
|
+
blockInfo.block.afterPos,
|
|
142
169
|
replacementNode,
|
|
143
170
|
);
|
|
144
171
|
|
|
145
172
|
return;
|
|
146
173
|
}
|
|
147
174
|
|
|
175
|
+
updateChildren(block, tr, blockInfo);
|
|
176
|
+
|
|
177
|
+
if (blockInfo.hasContent) {
|
|
178
|
+
// The code below determines the new content of the block.
|
|
179
|
+
// or "keep" to keep as-is
|
|
180
|
+
updateBlockContentNode(
|
|
181
|
+
block,
|
|
182
|
+
tr,
|
|
183
|
+
pmSchema.nodes[blockInfo.blockNoteType],
|
|
184
|
+
newNodeType,
|
|
185
|
+
blockInfo,
|
|
186
|
+
replaceFromOffset,
|
|
187
|
+
replaceToOffset,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
148
191
|
// Adds all provided props as attributes to the parent blockContainer node too, and also preserves existing
|
|
149
192
|
|
|
150
193
|
// attributes. Uses minimal steps so that an unchanged container (e.g. when
|
|
151
194
|
// only children or content changed) doesn't emit a step at all.
|
|
152
|
-
setNodeMarkupMinimal(tr, blockInfo.
|
|
195
|
+
setNodeMarkupMinimal(tr, blockInfo.block.beforePos, newBnBlockNodeType, {
|
|
153
196
|
...block.props,
|
|
154
197
|
});
|
|
155
198
|
|
|
156
|
-
if (cellAnchor) {
|
|
157
|
-
restoreCellAnchor(
|
|
199
|
+
if (cellAnchor && blockInfo.hasContent) {
|
|
200
|
+
restoreCellAnchor(
|
|
201
|
+
tr,
|
|
202
|
+
tr.mapping.slice(stepsBefore).map(blockInfo.content.beforePos),
|
|
203
|
+
cellAnchor,
|
|
204
|
+
);
|
|
158
205
|
}
|
|
159
206
|
}
|
|
160
207
|
|
|
@@ -167,12 +214,7 @@ function updateBlockContentNode<
|
|
|
167
214
|
tr: Transform,
|
|
168
215
|
oldNodeType: NodeType,
|
|
169
216
|
newNodeType: NodeType,
|
|
170
|
-
blockInfo: {
|
|
171
|
-
childContainer?:
|
|
172
|
-
| { node: PMNode; beforePos: number; afterPos: number }
|
|
173
|
-
| undefined;
|
|
174
|
-
blockContent: { node: PMNode; beforePos: number; afterPos: number };
|
|
175
|
-
},
|
|
217
|
+
blockInfo: Extract<BlockInfo, { hasContent: true }>,
|
|
176
218
|
replaceFromOffset?: number,
|
|
177
219
|
replaceToOffset?: number,
|
|
178
220
|
) {
|
|
@@ -201,8 +243,8 @@ function updateBlockContentNode<
|
|
|
201
243
|
// no custom content has been provided, use existing content IF possible
|
|
202
244
|
// Since some block types contain inline content and others don't,
|
|
203
245
|
// we either need to call setNodeMarkup to just update type &
|
|
204
|
-
// attributes, or replaceWith to replace the whole
|
|
205
|
-
const oldContent = blockInfo.
|
|
246
|
+
// attributes, or replaceWith to replace the whole content.
|
|
247
|
+
const oldContent = blockInfo.content.node.content;
|
|
206
248
|
if (oldNodeType.spec.content === "") {
|
|
207
249
|
// keep old content, because it's empty anyway and should be compatible with
|
|
208
250
|
// any newContentType
|
|
@@ -217,7 +259,7 @@ function updateBlockContentNode<
|
|
|
217
259
|
// for the new type (e.g. converting styled/complex inline content into a
|
|
218
260
|
// plain block that disallows formatting marks and inline nodes). Preserve
|
|
219
261
|
// the text, dropping the styling the new type can't represent.
|
|
220
|
-
const text = blockInfo.
|
|
262
|
+
const text = blockInfo.content.node.textContent;
|
|
221
263
|
content = text.length > 0 ? [pmSchema.text(text)] : [];
|
|
222
264
|
} else {
|
|
223
265
|
// the content type changed and is incompatible, replace the previous content
|
|
@@ -225,7 +267,7 @@ function updateBlockContentNode<
|
|
|
225
267
|
}
|
|
226
268
|
}
|
|
227
269
|
|
|
228
|
-
// Now, changes the
|
|
270
|
+
// Now, changes the content node type and adds the provided props
|
|
229
271
|
// as attributes. Also preserves all existing attributes that are
|
|
230
272
|
// compatible with the new type.
|
|
231
273
|
//
|
|
@@ -233,7 +275,7 @@ function updateBlockContentNode<
|
|
|
233
275
|
// content is being replaced or not.
|
|
234
276
|
if (content === "keep") {
|
|
235
277
|
// only update the type and attributes, keeping the content as-is
|
|
236
|
-
setNodeMarkupMinimal(tr, blockInfo.
|
|
278
|
+
setNodeMarkupMinimal(tr, blockInfo.content.beforePos, newNodeType, {
|
|
237
279
|
...block.props,
|
|
238
280
|
});
|
|
239
281
|
} else if (replaceFromOffset !== undefined || replaceToOffset !== undefined) {
|
|
@@ -241,7 +283,7 @@ function updateBlockContentNode<
|
|
|
241
283
|
// position back.
|
|
242
284
|
const contentBeforePos = setNodeMarkupMinimalAndRemap(
|
|
243
285
|
tr,
|
|
244
|
-
blockInfo.
|
|
286
|
+
blockInfo.content.beforePos,
|
|
245
287
|
newNodeType,
|
|
246
288
|
{ ...block.props },
|
|
247
289
|
);
|
|
@@ -250,7 +292,7 @@ function updateBlockContentNode<
|
|
|
250
292
|
const end =
|
|
251
293
|
contentBeforePos +
|
|
252
294
|
1 +
|
|
253
|
-
(replaceToOffset ?? blockInfo.
|
|
295
|
+
(replaceToOffset ?? blockInfo.content.node.content.size);
|
|
254
296
|
|
|
255
297
|
// for content like table cells (where the blockcontent has nested PM nodes),
|
|
256
298
|
// we need to figure out the correct openStart and openEnd for the slice when replacing
|
|
@@ -270,7 +312,7 @@ function updateBlockContentNode<
|
|
|
270
312
|
);
|
|
271
313
|
} else if (
|
|
272
314
|
newNodeType === oldNodeType ||
|
|
273
|
-
newNodeType.validContent(blockInfo.
|
|
315
|
+
newNodeType.validContent(blockInfo.content.node.content)
|
|
274
316
|
) {
|
|
275
317
|
// The new type can hold the existing content, so we can update the markup
|
|
276
318
|
// first and then diff the content. This keeps both steps minimal.
|
|
@@ -280,7 +322,7 @@ function updateBlockContentNode<
|
|
|
280
322
|
// get its (possibly shifted) position back.
|
|
281
323
|
const contentBeforePos = setNodeMarkupMinimalAndRemap(
|
|
282
324
|
tr,
|
|
283
|
-
blockInfo.
|
|
325
|
+
blockInfo.content.beforePos,
|
|
284
326
|
newNodeType,
|
|
285
327
|
{ ...block.props },
|
|
286
328
|
);
|
|
@@ -293,11 +335,11 @@ function updateBlockContentNode<
|
|
|
293
335
|
// between inline content, table content, and no content). We can't update
|
|
294
336
|
// the markup in-place, so replace the whole content node atomically.
|
|
295
337
|
tr.replaceWith(
|
|
296
|
-
blockInfo.
|
|
297
|
-
blockInfo.
|
|
338
|
+
blockInfo.content.beforePos,
|
|
339
|
+
blockInfo.content.afterPos,
|
|
298
340
|
newNodeType.createChecked(
|
|
299
341
|
{
|
|
300
|
-
...blockInfo.
|
|
342
|
+
...blockInfo.content.node.attrs,
|
|
301
343
|
...block.props,
|
|
302
344
|
},
|
|
303
345
|
content,
|
|
@@ -510,24 +552,23 @@ function updateChildren<
|
|
|
510
552
|
return node;
|
|
511
553
|
});
|
|
512
554
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
//
|
|
516
|
-
//
|
|
517
|
-
// children untouched).
|
|
555
|
+
if (blockInfo.children) {
|
|
556
|
+
// Replaces the child nodes in the existing children holder, only
|
|
557
|
+
// touching the range that actually changed (keeping unchanged
|
|
558
|
+
// leading/trailing children untouched).
|
|
518
559
|
replaceContentMinimal(
|
|
519
560
|
tr,
|
|
520
|
-
blockInfo.
|
|
561
|
+
blockInfo.children.beforePos,
|
|
521
562
|
Fragment.from(childNodes),
|
|
522
563
|
);
|
|
523
|
-
} else {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
//
|
|
564
|
+
} else if (blockInfo.hasContent) {
|
|
565
|
+
// A `blockContainer` with no children yet: its `blockGroup` is lazy
|
|
566
|
+
// (`blockContent blockGroup?`), so create it around the child nodes and
|
|
567
|
+
// insert it after the content node. (Layout blocks always have a children
|
|
568
|
+
// holder, so no holder implies a `blockContainer`.)
|
|
528
569
|
tr.insert(
|
|
529
|
-
blockInfo.
|
|
530
|
-
pmSchema
|
|
570
|
+
blockInfo.content.afterPos,
|
|
571
|
+
createBlockGroup(pmSchema, childNodes),
|
|
531
572
|
);
|
|
532
573
|
}
|
|
533
574
|
}
|
|
@@ -559,11 +600,14 @@ export function updateBlock<
|
|
|
559
600
|
replaceToPos,
|
|
560
601
|
);
|
|
561
602
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
603
|
+
// `updateBlockTr` may have replaced the node, so re-resolve it at the same
|
|
604
|
+
// position (an update never moves the block).
|
|
605
|
+
const updatedNode = tr.doc.resolve(posInfo.posBeforeNode).nodeAfter;
|
|
606
|
+
if (!updatedNode) {
|
|
607
|
+
throw new Error(`Block with ID ${id} not found after update`);
|
|
608
|
+
}
|
|
565
609
|
|
|
566
|
-
return nodeToBlock(
|
|
610
|
+
return nodeToBlock(updatedNode, tr.doc);
|
|
567
611
|
}
|
|
568
612
|
|
|
569
613
|
type CellAnchor = { row: number; col: number; offset: number };
|
|
@@ -627,33 +671,10 @@ export function captureCellAnchor(tr: Transform): CellAnchor | null {
|
|
|
627
671
|
|
|
628
672
|
function restoreCellAnchor(
|
|
629
673
|
tr: Transform | Transaction,
|
|
630
|
-
|
|
674
|
+
tablePos: number,
|
|
631
675
|
a: CellAnchor,
|
|
632
676
|
): boolean {
|
|
633
|
-
|
|
634
|
-
return false;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
// 1) Resolve the table node in the current document
|
|
638
|
-
let tablePos = -1;
|
|
639
|
-
|
|
640
|
-
if (blockInfo.isBlockContainer) {
|
|
641
|
-
// Prefer the blockContent position when available (points directly at the PM table node)
|
|
642
|
-
tablePos = tr.mapping.map(blockInfo.blockContent.beforePos);
|
|
643
|
-
} else {
|
|
644
|
-
// Fallback: scan within the mapped bnBlock range to find the inner table node
|
|
645
|
-
const start = tr.mapping.map(blockInfo.bnBlock.beforePos);
|
|
646
|
-
const end = start + (tr.doc.nodeAt(start)?.nodeSize || 0);
|
|
647
|
-
tr.doc.nodesBetween(start, end, (node, pos) => {
|
|
648
|
-
if (node.type.name === "table") {
|
|
649
|
-
tablePos = pos;
|
|
650
|
-
return false;
|
|
651
|
-
}
|
|
652
|
-
return true;
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
const table = tablePos >= 0 ? tr.doc.nodeAt(tablePos) : null;
|
|
677
|
+
const table = tr.doc.nodeAt(tablePos);
|
|
657
678
|
if (!table || table.type.name !== "table") {
|
|
658
679
|
return false;
|
|
659
680
|
}
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
InlineContentSchema,
|
|
7
7
|
StyleSchema,
|
|
8
8
|
} from "../../../schema/index.js";
|
|
9
|
+
import { getParentBlockInfo } from "../../getBlockInfoFromPos.js";
|
|
9
10
|
import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
|
|
10
11
|
import { getNodeById } from "../../nodeUtil.js";
|
|
11
12
|
|
|
@@ -94,18 +95,10 @@ export function getParentBlock<
|
|
|
94
95
|
return undefined;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const grandparentNode = $posBeforeNode.node(-1);
|
|
100
|
-
const nodeToConvert =
|
|
101
|
-
grandparentNode.type.name !== "doc"
|
|
102
|
-
? parentNode.type.name === "blockGroup"
|
|
103
|
-
? grandparentNode
|
|
104
|
-
: parentNode
|
|
105
|
-
: undefined;
|
|
106
|
-
if (!nodeToConvert) {
|
|
98
|
+
const parentInfo = getParentBlockInfo(doc, posInfo.posBeforeNode);
|
|
99
|
+
if (!parentInfo) {
|
|
107
100
|
return undefined;
|
|
108
101
|
}
|
|
109
102
|
|
|
110
|
-
return nodeToBlock(
|
|
103
|
+
return nodeToBlock(parentInfo.block.node, doc);
|
|
111
104
|
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Fragment, type Node, Slice } from "prosemirror-model";
|
|
2
|
+
import { type Transaction } from "prosemirror-state";
|
|
3
|
+
import { ReplaceAroundStep } from "prosemirror-transform";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
isLayoutNode,
|
|
7
|
+
isNamedOnly,
|
|
8
|
+
minChildren,
|
|
9
|
+
} from "../../../schema/blocks/children.js";
|
|
10
|
+
import { getNodeById } from "../../nodeUtil.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Whether `node` is a layout block child the user has emptied out: a layout block
|
|
14
|
+
* (a column, a cell) holding nothing but one empty paragraph, or one holding
|
|
15
|
+
* nothing at all that its content expression requires children.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export function isEmptyLayoutChild(node: Node): boolean {
|
|
19
|
+
if (node.type.name === "blockContainer") {
|
|
20
|
+
const content = node.firstChild;
|
|
21
|
+
return (
|
|
22
|
+
node.childCount === 1 &&
|
|
23
|
+
!!content &&
|
|
24
|
+
content.type.name === "paragraph" &&
|
|
25
|
+
content.childCount === 0
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (isLayoutNode(node.type)) {
|
|
29
|
+
if (node.childCount === 1) {
|
|
30
|
+
return isEmptyLayoutChild(node.firstChild!);
|
|
31
|
+
}
|
|
32
|
+
// A layout block left with no children at all: its last child was removed
|
|
33
|
+
// and no fill happened on the way. A `min: 0` layout block in this state is
|
|
34
|
+
// valid and stays; any other is broken structure.
|
|
35
|
+
if (node.childCount === 0) {
|
|
36
|
+
return minChildren(node.type.spec.blockConfig?.children) >= 1;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Repairs the layout block at `layoutBlockPos` after children were (re)moved from
|
|
45
|
+
* it: drops the ones the user emptied, and dissolves the layout block when too
|
|
46
|
+
* few are left for it to mean anything (a column list with one column is just
|
|
47
|
+
* that column's blocks).
|
|
48
|
+
*
|
|
49
|
+
* A layout block that only exists inside another layout block (a column) is left to
|
|
50
|
+
* its parent, which is the thing that decides whether it still belongs.
|
|
51
|
+
*
|
|
52
|
+
* @param layoutBlockPos The position just before the layout block node.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export function fixLayoutBlock(tr: Transaction, layoutBlockPos: number) {
|
|
56
|
+
const layoutBlock = tr.doc.resolve(layoutBlockPos).nodeAfter;
|
|
57
|
+
if (!layoutBlock || !isLayoutNode(layoutBlock.type)) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
"Invalid layoutBlockPos: does not point to a layout block node.",
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// A `namedOnly` layout block (a column) keeps existing: it is its parent's
|
|
64
|
+
// decision whether the layout block still belongs, and ProseMirror pads it
|
|
65
|
+
// back up to its minimum when children are removed.
|
|
66
|
+
if (isNamedOnly(layoutBlock.type)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// A layout block that does not dissolve keeps its empty children, and stays
|
|
71
|
+
// when too few are left: ProseMirror fills it back up to its minimum with
|
|
72
|
+
// empty children (`children.dissolve`).
|
|
73
|
+
const children = layoutBlock.type.spec.blockConfig?.children;
|
|
74
|
+
if (children && "dissolve" in children && children.dissolve === false) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const min = minChildren(layoutBlock.type.spec.blockConfig?.children);
|
|
79
|
+
const survivors: { node: Node; offset: number }[] = [];
|
|
80
|
+
const emptied: { from: number; to: number }[] = [];
|
|
81
|
+
layoutBlock.forEach((child, offset) => {
|
|
82
|
+
if (!isEmptyLayoutChild(child)) {
|
|
83
|
+
survivors.push({ node: child, offset });
|
|
84
|
+
} else if (isLayoutNode(child.type)) {
|
|
85
|
+
const from = layoutBlockPos + 1 + offset;
|
|
86
|
+
emptied.push({ from, to: from + child.nodeSize });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (survivors.length >= min) {
|
|
91
|
+
// Keep intentional empty paragraphs. Only remove empty structural children,
|
|
92
|
+
// back to front so positions (and selections in surviving children) stay valid.
|
|
93
|
+
for (const { from, to } of emptied.reverse()) {
|
|
94
|
+
tr.delete(from, to);
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Too few children left for the layout block to mean anything, so it is
|
|
100
|
+
// replaced by its surviving children.
|
|
101
|
+
|
|
102
|
+
// A single survivor supplying the whole replacement is an unwrap, and doing
|
|
103
|
+
// it as a `ReplaceAroundStep` leaves that content in place in the document:
|
|
104
|
+
// positions inside it - a caret, a collaborator's concurrent edit - map
|
|
105
|
+
// through it, where deleting and reinserting the same content would collapse
|
|
106
|
+
// them onto the edge of the replaced range.
|
|
107
|
+
if (survivors.length === 1) {
|
|
108
|
+
const [{ node: survivor, offset }] = survivors;
|
|
109
|
+
const survivorPos = layoutBlockPos + 1 + offset;
|
|
110
|
+
// A `namedOnly` survivor is lifted out of two wrappers at once - the column
|
|
111
|
+
// and the layout block - and any other survivor out of just the layout block.
|
|
112
|
+
const gap = isNamedOnly(survivor.type)
|
|
113
|
+
? { from: survivorPos + 1, to: survivorPos + survivor.nodeSize - 1 }
|
|
114
|
+
: { from: survivorPos, to: survivorPos + survivor.nodeSize };
|
|
115
|
+
|
|
116
|
+
tr.step(
|
|
117
|
+
new ReplaceAroundStep(
|
|
118
|
+
layoutBlockPos,
|
|
119
|
+
layoutBlockPos + layoutBlock.nodeSize,
|
|
120
|
+
gap.from,
|
|
121
|
+
gap.to,
|
|
122
|
+
Slice.empty,
|
|
123
|
+
0,
|
|
124
|
+
// Not a pure unwrap: emptied siblings sit outside the gap and go with
|
|
125
|
+
// the layout block, which the `structure` check would refuse.
|
|
126
|
+
false,
|
|
127
|
+
),
|
|
128
|
+
);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Several survivors are not one contiguous range once an emptied child sits
|
|
133
|
+
// between them, so this path rebuilds them and positions inside them
|
|
134
|
+
// collapse. It takes a layout block with a `min` of 3 or more to reach.
|
|
135
|
+
const replacement: Node[] = [];
|
|
136
|
+
for (const { node: survivor } of survivors) {
|
|
137
|
+
if (isNamedOnly(survivor.type)) {
|
|
138
|
+
// The survivor can't stand on its own either (a column only exists
|
|
139
|
+
// inside a column list), so what it holds is what's left.
|
|
140
|
+
survivor.forEach((grandChild) => replacement.push(grandChild));
|
|
141
|
+
} else {
|
|
142
|
+
replacement.push(survivor);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
tr.replaceWith(
|
|
147
|
+
layoutBlockPos,
|
|
148
|
+
layoutBlockPos + layoutBlock.nodeSize,
|
|
149
|
+
Fragment.from(replacement),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Runs {@link fixLayoutBlock} on each of the given layout blocks, looked up by ID
|
|
155
|
+
* in `tr`'s current doc. Layout blocks are repaired deepest-first so that an
|
|
156
|
+
* inner repair (e.g. a column emptying out) is observed by the outer
|
|
157
|
+
* layout block's repair (e.g. its columnList unwrapping) in the same pass.
|
|
158
|
+
* Layout blocks that no longer exist by the time their turn comes are skipped —
|
|
159
|
+
* an earlier repair may have removed them.
|
|
160
|
+
*/
|
|
161
|
+
export function fixLayoutBlocksById(
|
|
162
|
+
tr: Transaction,
|
|
163
|
+
layoutBlocks: { id: string; depth: number }[],
|
|
164
|
+
) {
|
|
165
|
+
[...layoutBlocks]
|
|
166
|
+
.sort((a, b) => b.depth - a.depth)
|
|
167
|
+
.forEach(({ id }) => {
|
|
168
|
+
const target = getNodeById(id, tr.doc);
|
|
169
|
+
if (target && isLayoutNode(target.node.type)) {
|
|
170
|
+
fixLayoutBlock(tr, target.posBeforeNode);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|