@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
|
@@ -7,12 +7,25 @@ import * as Y from "@y/y";
|
|
|
7
7
|
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
8
8
|
import { ForkYDocExtension } from "./ForkYDoc.js";
|
|
9
9
|
import { withCollaboration } from "./index.js";
|
|
10
|
+
import {
|
|
11
|
+
createExtension,
|
|
12
|
+
type ExtensionFactoryInstance,
|
|
13
|
+
} from "../../editor/BlockNoteExtension.js";
|
|
14
|
+
import {
|
|
15
|
+
createVersioningExtension,
|
|
16
|
+
type VersioningController,
|
|
17
|
+
} from "../../extensions/Versioning/Versioning.js";
|
|
18
|
+
import { createYVersionView } from "./Versioning.js";
|
|
19
|
+
import { yUndoPlugin, undo, redo } from "@y/prosemirror";
|
|
10
20
|
|
|
11
21
|
// ---------------------------------------------------------------------------
|
|
12
22
|
// Helpers
|
|
13
23
|
// ---------------------------------------------------------------------------
|
|
14
24
|
|
|
15
|
-
function createCollabEditor(
|
|
25
|
+
function createCollabEditor(
|
|
26
|
+
extensions: (fragment: Y.Node) => ExtensionFactoryInstance[] = () => [],
|
|
27
|
+
disableExtensions: string[] = [],
|
|
28
|
+
) {
|
|
16
29
|
const doc = new Y.Doc();
|
|
17
30
|
const fragment = doc.get("doc");
|
|
18
31
|
|
|
@@ -25,8 +38,9 @@ function createCollabEditor() {
|
|
|
25
38
|
const editor = BlockNoteEditor.create(
|
|
26
39
|
withCollaboration({
|
|
27
40
|
collaboration: collabOptions,
|
|
41
|
+
disableExtensions,
|
|
28
42
|
// Register ForkYDocExtension alongside the collaboration extensions
|
|
29
|
-
extensions: [ForkYDocExtension(collabOptions)],
|
|
43
|
+
extensions: [ForkYDocExtension(collabOptions), ...extensions(fragment)],
|
|
30
44
|
}),
|
|
31
45
|
);
|
|
32
46
|
const div = document.createElement("div");
|
|
@@ -60,6 +74,83 @@ afterEach(() => {
|
|
|
60
74
|
});
|
|
61
75
|
|
|
62
76
|
describe("ForkYDocExtension (v14)", () => {
|
|
77
|
+
it.each(["history", "yUndo"] as const)(
|
|
78
|
+
"detaches %s through version previews and resumes live undo",
|
|
79
|
+
async (historyType) => {
|
|
80
|
+
let snapshot: Uint8Array = new Uint8Array();
|
|
81
|
+
let manager: Y.UndoManager | undefined;
|
|
82
|
+
ctx = createCollabEditor(
|
|
83
|
+
(fragment) => {
|
|
84
|
+
const Versions = createVersioningExtension((editor) => ({
|
|
85
|
+
adapter: createYVersionView(editor, fragment),
|
|
86
|
+
storage: {
|
|
87
|
+
async list() {
|
|
88
|
+
return { ok: true, value: { snapshots: [] } };
|
|
89
|
+
},
|
|
90
|
+
async getContent() {
|
|
91
|
+
return { ok: true, value: snapshot };
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
}));
|
|
95
|
+
if (historyType === "history") {
|
|
96
|
+
return [Versions()];
|
|
97
|
+
}
|
|
98
|
+
manager = new Y.UndoManager(fragment);
|
|
99
|
+
const undoManager = manager;
|
|
100
|
+
const YUndo = createExtension(() => ({
|
|
101
|
+
key: "yUndo",
|
|
102
|
+
prosemirrorPlugins: [yUndoPlugin(undoManager)],
|
|
103
|
+
undoCommand: undo,
|
|
104
|
+
redoCommand: redo,
|
|
105
|
+
}));
|
|
106
|
+
return [Versions(), YUndo()];
|
|
107
|
+
},
|
|
108
|
+
historyType === "yUndo" ? ["history"] : [],
|
|
109
|
+
);
|
|
110
|
+
const versions =
|
|
111
|
+
ctx.editor.getExtension<VersioningController>("versioning")!;
|
|
112
|
+
try {
|
|
113
|
+
setEditorText(ctx.editor, "Snapshot");
|
|
114
|
+
snapshot = Y.encodeStateAsUpdateV2(ctx.doc);
|
|
115
|
+
setEditorText(ctx.editor, "Live");
|
|
116
|
+
const live = Y.encodeStateAsUpdateV2(ctx.doc);
|
|
117
|
+
const undoDepth = manager?.undoStack.length;
|
|
118
|
+
versions.open();
|
|
119
|
+
expect(ctx.editor.isEditable).toBe(false);
|
|
120
|
+
for (const target of [
|
|
121
|
+
{ type: "snapshot", id: "saved" },
|
|
122
|
+
{ type: "current" },
|
|
123
|
+
{ type: "snapshot", id: "saved" },
|
|
124
|
+
] as const) {
|
|
125
|
+
await versions.select(target);
|
|
126
|
+
expect(getEditorText(ctx.editor)).toBe(
|
|
127
|
+
target.type === "current" ? "Live" : "Snapshot",
|
|
128
|
+
);
|
|
129
|
+
expect(ctx.editor.getExtension(historyType)).toBeUndefined();
|
|
130
|
+
expect(Y.encodeStateAsUpdateV2(ctx.doc)).toEqual(live);
|
|
131
|
+
}
|
|
132
|
+
versions.close();
|
|
133
|
+
expect(getEditorText(ctx.editor)).toBe("Live");
|
|
134
|
+
expect(ctx.editor.isEditable).toBe(true);
|
|
135
|
+
if (manager) {
|
|
136
|
+
expect(manager.undoStack.length).toBe(undoDepth);
|
|
137
|
+
} else {
|
|
138
|
+
expect(ctx.editor.undo()).toBe(false);
|
|
139
|
+
expect(ctx.editor.redo()).toBe(false);
|
|
140
|
+
}
|
|
141
|
+
manager?.stopCapturing();
|
|
142
|
+
setEditorText(ctx.editor, "New edit");
|
|
143
|
+
expect(ctx.editor.undo()).toBe(true);
|
|
144
|
+
expect(getEditorText(ctx.editor)).toBe("Live");
|
|
145
|
+
expect(ctx.editor.redo()).toBe(true);
|
|
146
|
+
expect(getEditorText(ctx.editor)).toBe("New edit");
|
|
147
|
+
} finally {
|
|
148
|
+
versions.close();
|
|
149
|
+
manager?.destroy();
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
|
|
63
154
|
it("forks the document — edits do not affect the original fragment", () => {
|
|
64
155
|
ctx = createCollabEditor();
|
|
65
156
|
setEditorText(ctx.editor, "Original");
|
|
@@ -13,8 +13,9 @@ export const ForkYDocExtension = createExtension(
|
|
|
13
13
|
({ editor, options }: ExtensionOptions<CollaborationOptions>) => {
|
|
14
14
|
let forkedState:
|
|
15
15
|
| {
|
|
16
|
-
originalFragment: Y.
|
|
17
|
-
forkedFragment: Y.
|
|
16
|
+
originalFragment: Y.Node;
|
|
17
|
+
forkedFragment: Y.Node;
|
|
18
|
+
cursor: ReturnType<ReturnType<typeof YCursorExtension>> | undefined;
|
|
18
19
|
}
|
|
19
20
|
| undefined = undefined;
|
|
20
21
|
|
|
@@ -59,14 +60,12 @@ export const ForkYDocExtension = createExtension(
|
|
|
59
60
|
forkedState = {
|
|
60
61
|
originalFragment,
|
|
61
62
|
forkedFragment,
|
|
63
|
+
cursor: editor.unregisterExtension(YCursorExtension),
|
|
62
64
|
};
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
editor.unregisterExtension([YCursorExtension]);
|
|
66
|
-
editor.exec(configureYProsemirror({ ytype: forkedFragment }));
|
|
67
|
-
|
|
68
|
-
// Tell the store that the editor is now forked
|
|
66
|
+
options.provider?.awareness?.setLocalStateField("cursor", null);
|
|
69
67
|
store.setState({ isForked: true });
|
|
68
|
+
editor.exec(configureYProsemirror({ ytype: forkedFragment }));
|
|
70
69
|
},
|
|
71
70
|
|
|
72
71
|
/**
|
|
@@ -74,20 +73,28 @@ export const ForkYDocExtension = createExtension(
|
|
|
74
73
|
* If `keepChanges` is true, any changes that have been made to the forked document will be applied to the original document.
|
|
75
74
|
* Otherwise, the original document will be restored and the changes will be discarded.
|
|
76
75
|
*/
|
|
77
|
-
merge({
|
|
76
|
+
merge({
|
|
77
|
+
keepChanges,
|
|
78
|
+
renderer = options.renderer,
|
|
79
|
+
}: {
|
|
80
|
+
keepChanges: boolean;
|
|
81
|
+
renderer?: Y.DiffRenderer | null;
|
|
82
|
+
}) {
|
|
78
83
|
if (!forkedState) {
|
|
79
84
|
return;
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
const { originalFragment, forkedFragment } = forkedState;
|
|
83
|
-
//
|
|
84
|
-
editor.registerExtension([YCursorExtension(options)]);
|
|
87
|
+
const { originalFragment, forkedFragment, cursor } = forkedState;
|
|
88
|
+
// Restore the live binding before a cursor plugin view can use it.
|
|
85
89
|
editor.exec(
|
|
86
90
|
configureYProsemirror({
|
|
87
91
|
ytype: originalFragment,
|
|
88
|
-
renderer
|
|
92
|
+
renderer,
|
|
89
93
|
}),
|
|
90
94
|
);
|
|
95
|
+
if (cursor) {
|
|
96
|
+
editor.registerExtension(cursor);
|
|
97
|
+
}
|
|
91
98
|
|
|
92
99
|
if (keepChanges) {
|
|
93
100
|
// Apply any changes that have been made to the fork, onto the original doc
|
|
@@ -95,11 +102,13 @@ export const ForkYDocExtension = createExtension(
|
|
|
95
102
|
forkedFragment.doc!,
|
|
96
103
|
Y.encodeStateVector(originalFragment.doc!),
|
|
97
104
|
);
|
|
98
|
-
//
|
|
105
|
+
// This arrives through Yjs synchronization, so normal ProseMirror
|
|
106
|
+
// history does not record the merge as a local undoable transaction.
|
|
99
107
|
Y.applyUpdate(originalFragment.doc!, update, editor);
|
|
100
108
|
}
|
|
101
109
|
// Reset the forked state
|
|
102
110
|
forkedState = undefined;
|
|
111
|
+
forkedFragment.doc!.destroy();
|
|
103
112
|
// Tell the store that the editor is no longer forked
|
|
104
113
|
store.setState({ isForked: false });
|
|
105
114
|
},
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import * as Y from "@y/y";
|
|
3
|
+
import { afterEach, expect, it } from "vite-plus/test";
|
|
4
|
+
|
|
5
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
6
|
+
import { blocksToYType, yDocToBlocks } from "../utils.js";
|
|
7
|
+
import { withCollaboration } from "./index.js";
|
|
8
|
+
|
|
9
|
+
const cleanups: Array<() => void> = [];
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
for (const cleanup of cleanups.splice(0).reverse()) {
|
|
12
|
+
cleanup();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
function createCollaborativeEditor(doc = new Y.Doc()) {
|
|
17
|
+
cleanups.push(() => doc.destroy());
|
|
18
|
+
const fragment = doc.get("doc");
|
|
19
|
+
const editor = BlockNoteEditor.create(
|
|
20
|
+
withCollaboration({
|
|
21
|
+
collaboration: { fragment, user: { name: "Test", color: "red" } },
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
if (fragment.length === 0) {
|
|
25
|
+
editor.replaceBlocks(editor.document, [
|
|
26
|
+
{ id: "paragraph", type: "paragraph", content: "Initial document" },
|
|
27
|
+
{ id: "other", type: "paragraph", content: "Other paragraph" },
|
|
28
|
+
]);
|
|
29
|
+
blocksToYType(editor, editor.document, fragment);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const element = document.createElement("div");
|
|
33
|
+
document.body.appendChild(element);
|
|
34
|
+
cleanups.push(() => {
|
|
35
|
+
editor.unmount();
|
|
36
|
+
element.remove();
|
|
37
|
+
});
|
|
38
|
+
editor.mount(element);
|
|
39
|
+
return { editor, doc };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
it.each([
|
|
43
|
+
{
|
|
44
|
+
change: "insert",
|
|
45
|
+
apply(editor: BlockNoteEditor) {
|
|
46
|
+
editor.setTextCursorPosition("paragraph", "start");
|
|
47
|
+
editor.insertInlineContent("Local ");
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
change: "remove",
|
|
52
|
+
apply(editor: BlockNoteEditor) {
|
|
53
|
+
editor.removeBlocks(["paragraph"]);
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
change: "format",
|
|
58
|
+
apply(editor: BlockNoteEditor) {
|
|
59
|
+
editor.updateBlock("paragraph", {
|
|
60
|
+
content: [
|
|
61
|
+
{ type: "text", text: "Initial document", styles: { bold: true } },
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
])(
|
|
67
|
+
"undoes and redoes a local $change in a collaborative document",
|
|
68
|
+
(testCase) => {
|
|
69
|
+
const { editor, doc } = createCollaborativeEditor();
|
|
70
|
+
const initial = editor.document;
|
|
71
|
+
expect(initial[0].content).toEqual([
|
|
72
|
+
{ type: "text", text: "Initial document", styles: {} },
|
|
73
|
+
]);
|
|
74
|
+
expect(editor.undo()).toBe(false);
|
|
75
|
+
expect(editor.redo()).toBe(false);
|
|
76
|
+
|
|
77
|
+
testCase.apply(editor);
|
|
78
|
+
const changed = editor.document;
|
|
79
|
+
expect(changed).not.toEqual(initial);
|
|
80
|
+
expect(yDocToBlocks(editor, doc, "doc")).toEqual(changed);
|
|
81
|
+
|
|
82
|
+
expect(editor.undo()).toBe(true);
|
|
83
|
+
expect(editor.document).toEqual(initial);
|
|
84
|
+
expect(yDocToBlocks(editor, doc, "doc")).toEqual(initial);
|
|
85
|
+
expect(editor.undo()).toBe(false);
|
|
86
|
+
expect(editor.redo()).toBe(true);
|
|
87
|
+
expect(editor.document).toEqual(changed);
|
|
88
|
+
expect(yDocToBlocks(editor, doc, "doc")).toEqual(changed);
|
|
89
|
+
expect(editor.redo()).toBe(false);
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
it("maps local undo and redo across remote insertions without recording remote edits", () => {
|
|
94
|
+
const { editor, doc } = createCollaborativeEditor();
|
|
95
|
+
const remoteDoc = new Y.Doc();
|
|
96
|
+
Y.applyUpdateV2(remoteDoc, Y.encodeStateAsUpdateV2(doc));
|
|
97
|
+
const { editor: remote } = createCollaborativeEditor(remoteDoc);
|
|
98
|
+
|
|
99
|
+
editor.setTextCursorPosition("paragraph", "start");
|
|
100
|
+
editor.insertInlineContent("Local ");
|
|
101
|
+
Y.applyUpdateV2(remoteDoc, Y.encodeStateAsUpdateV2(doc));
|
|
102
|
+
expect(remote.undo()).toBe(false);
|
|
103
|
+
remote.setTextCursorPosition("paragraph", "start");
|
|
104
|
+
remote.insertInlineContent("Remote ");
|
|
105
|
+
Y.applyUpdateV2(doc, Y.encodeStateAsUpdateV2(remoteDoc));
|
|
106
|
+
expect(editor.document[0].content).toEqual([
|
|
107
|
+
{ type: "text", text: "Remote Local Initial document", styles: {} },
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
expect(editor.undo()).toBe(true);
|
|
111
|
+
expect(editor.document[0].content).toEqual([
|
|
112
|
+
{ type: "text", text: "Remote Initial document", styles: {} },
|
|
113
|
+
]);
|
|
114
|
+
expect(editor.undo()).toBe(false);
|
|
115
|
+
Y.applyUpdateV2(remoteDoc, Y.encodeStateAsUpdateV2(doc));
|
|
116
|
+
expect(remote.document).toEqual(editor.document);
|
|
117
|
+
|
|
118
|
+
expect(editor.redo()).toBe(true);
|
|
119
|
+
expect(editor.document[0].content).toEqual([
|
|
120
|
+
{ type: "text", text: "Remote Local Initial document", styles: {} },
|
|
121
|
+
]);
|
|
122
|
+
expect(editor.redo()).toBe(false);
|
|
123
|
+
Y.applyUpdateV2(remoteDoc, Y.encodeStateAsUpdateV2(doc));
|
|
124
|
+
expect(remote.document).toEqual(editor.document);
|
|
125
|
+
});
|
|
@@ -416,3 +416,38 @@ describe.skip("RelativePositionMapping (@y/y)", () => {
|
|
|
416
416
|
remoteEditor.unmount();
|
|
417
417
|
});
|
|
418
418
|
});
|
|
419
|
+
|
|
420
|
+
it("tracks a block boundary through the view-based Yjs mapping API", async () => {
|
|
421
|
+
const doc = new Y.Doc();
|
|
422
|
+
const editor = BlockNoteEditor.create(
|
|
423
|
+
withCollaboration({
|
|
424
|
+
collaboration: {
|
|
425
|
+
fragment: doc.get("doc"),
|
|
426
|
+
user: { name: "Test", color: "#ff0000" },
|
|
427
|
+
provider: undefined,
|
|
428
|
+
},
|
|
429
|
+
}),
|
|
430
|
+
);
|
|
431
|
+
editor.mount(document.createElement("div"));
|
|
432
|
+
try {
|
|
433
|
+
// Binding initialization and repairs finish asynchronously.
|
|
434
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
|
435
|
+
editor.replaceBlocks(editor.document, [
|
|
436
|
+
{ id: "first", type: "paragraph", content: "first" },
|
|
437
|
+
{ id: "second", type: "paragraph", content: "second" },
|
|
438
|
+
]);
|
|
439
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
|
440
|
+
const secondBlockPosition =
|
|
441
|
+
1 + editor.prosemirrorState.doc.firstChild!.firstChild!.nodeSize;
|
|
442
|
+
const restore = trackPosition(editor, secondBlockPosition);
|
|
443
|
+
expect(restore()).toBe(secondBlockPosition);
|
|
444
|
+
editor.updateBlock("first", { content: "a longer first paragraph" });
|
|
445
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
|
446
|
+
expect(restore()).toBe(
|
|
447
|
+
1 + editor.prosemirrorState.doc.firstChild!.firstChild!.nodeSize,
|
|
448
|
+
);
|
|
449
|
+
} finally {
|
|
450
|
+
editor.unmount();
|
|
451
|
+
doc.destroy();
|
|
452
|
+
}
|
|
453
|
+
});
|
|
@@ -19,29 +19,25 @@ export const RelativePositionMappingExtension = createExtension(
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const posStore = relativePositionStore(
|
|
22
|
+
editor.prosemirrorView,
|
|
22
23
|
editor.prosemirrorState.doc.resolve(
|
|
23
24
|
position + (side === "right" ? 1 : -1),
|
|
24
25
|
),
|
|
25
|
-
ySyncPluginState.ytype,
|
|
26
|
-
ySyncPluginState.renderer,
|
|
27
26
|
);
|
|
28
27
|
|
|
28
|
+
if (posStore === null) {
|
|
29
|
+
throw new Error("Position not found, cannot track positions");
|
|
30
|
+
}
|
|
31
|
+
|
|
29
32
|
return () => {
|
|
30
|
-
const
|
|
31
|
-
editor.prosemirrorState,
|
|
32
|
-
) as typeof ySyncPluginState;
|
|
33
|
-
const pos = posStore(
|
|
34
|
-
editor.prosemirrorState.doc,
|
|
35
|
-
curYSyncPluginState.ytype,
|
|
36
|
-
curYSyncPluginState.renderer,
|
|
37
|
-
);
|
|
33
|
+
const pos = posStore(editor.prosemirrorView);
|
|
38
34
|
|
|
39
35
|
// This can happen if the element is garbage collected
|
|
40
36
|
if (pos === null) {
|
|
41
37
|
throw new Error("Position not found, cannot track positions");
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
return pos + (side === "right" ? -1 : 1);
|
|
40
|
+
return pos.pos + (side === "right" ? -1 : 1);
|
|
45
41
|
};
|
|
46
42
|
},
|
|
47
43
|
} as const;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import * as Y from "@y/y";
|
|
3
|
+
import { configureYProsemirror } from "@y/prosemirror";
|
|
4
|
+
import { expect, it } from "vite-plus/test";
|
|
5
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
6
|
+
import {
|
|
7
|
+
type VersioningController,
|
|
8
|
+
createVersioningExtension,
|
|
9
|
+
} from "../../extensions/Versioning/Versioning.js";
|
|
10
|
+
import type { VersionStorage } from "../../extensions/Versioning/types.js";
|
|
11
|
+
import { CollaborationExtension, withCollaboration } from "./index.js";
|
|
12
|
+
import { createYVersionView } from "./Versioning.js";
|
|
13
|
+
import { YHubVersioningExtension } from "../versioning/yhub.js";
|
|
14
|
+
|
|
15
|
+
const options = { baseUrl: "https://yhub.test/api", org: "org", docId: "doc" };
|
|
16
|
+
|
|
17
|
+
it("does not install history when only collaboration is configured", () => {
|
|
18
|
+
const doc = new Y.Doc();
|
|
19
|
+
const editor = BlockNoteEditor.create(
|
|
20
|
+
withCollaboration({
|
|
21
|
+
collaboration: {
|
|
22
|
+
fragment: doc.get("doc"),
|
|
23
|
+
user: { name: "Test", color: "red" },
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
try {
|
|
28
|
+
expect(editor.getExtension("versioning")).toBeUndefined();
|
|
29
|
+
} finally {
|
|
30
|
+
editor._tiptapEditor.destroy();
|
|
31
|
+
doc.destroy();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it.each(["before", "after"] as const)(
|
|
36
|
+
"installs standalone YHub history %s collaboration per editor and shares its user store",
|
|
37
|
+
(order) => {
|
|
38
|
+
const docs = [new Y.Doc(), new Y.Doc()];
|
|
39
|
+
const editors: BlockNoteEditor[] = [];
|
|
40
|
+
const history = YHubVersioningExtension(options);
|
|
41
|
+
try {
|
|
42
|
+
for (const doc of docs) {
|
|
43
|
+
const fragment = doc.get("doc");
|
|
44
|
+
const collaboration = CollaborationExtension({
|
|
45
|
+
fragment,
|
|
46
|
+
user: { name: "Test", color: "red" },
|
|
47
|
+
});
|
|
48
|
+
const editor = BlockNoteEditor.create({
|
|
49
|
+
extensions:
|
|
50
|
+
order === "before"
|
|
51
|
+
? [history, collaboration]
|
|
52
|
+
: [collaboration, history],
|
|
53
|
+
disableExtensions: ["history"],
|
|
54
|
+
initialContent: [{ type: "paragraph", id: "initialBlockId" }],
|
|
55
|
+
});
|
|
56
|
+
editors.push(editor);
|
|
57
|
+
const versioning =
|
|
58
|
+
editor.getExtension<VersioningController>("versioning")!;
|
|
59
|
+
expect(versioning.userStore).toBe(
|
|
60
|
+
editor.getExtension(CollaborationExtension)!.userStore,
|
|
61
|
+
);
|
|
62
|
+
expect(versioning.canCreate).toBe(true);
|
|
63
|
+
// Tiptap installs plugins and YSync configures the live binding on mount.
|
|
64
|
+
// Initialize both explicitly to exercise the real headless view adapter.
|
|
65
|
+
editor.prosemirrorView.updateState(
|
|
66
|
+
editor.prosemirrorState.reconfigure({
|
|
67
|
+
plugins: editor._tiptapEditor.extensionManager.plugins,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
editor.exec(configureYProsemirror({ ytype: fragment }));
|
|
71
|
+
expect(editor.headless).toBe(true);
|
|
72
|
+
versioning.open();
|
|
73
|
+
expect(versioning.store.state.mode).toBe("versions");
|
|
74
|
+
versioning.close();
|
|
75
|
+
versioning.open();
|
|
76
|
+
versioning.close();
|
|
77
|
+
}
|
|
78
|
+
expect(editors[0].getExtension("versioning")).not.toBe(
|
|
79
|
+
editors[1].getExtension("versioning"),
|
|
80
|
+
);
|
|
81
|
+
} finally {
|
|
82
|
+
for (const editor of editors) {
|
|
83
|
+
editor.getExtension<VersioningController>("versioning")!.close();
|
|
84
|
+
editor._tiptapEditor.destroy();
|
|
85
|
+
}
|
|
86
|
+
for (const doc of docs) {
|
|
87
|
+
doc.destroy();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
it("keeps the first versioning integration using normal extension deduplication", () => {
|
|
94
|
+
const doc = new Y.Doc();
|
|
95
|
+
const fragment = doc.get("doc");
|
|
96
|
+
const storage: VersionStorage<Uint8Array, Y.ContentMap> = {
|
|
97
|
+
async list() {
|
|
98
|
+
return { ok: true, value: { snapshots: [] } };
|
|
99
|
+
},
|
|
100
|
+
async getContent() {
|
|
101
|
+
return { ok: true, value: new Uint8Array() };
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
const Versions = createVersioningExtension((editor) => ({
|
|
105
|
+
adapter: createYVersionView(editor, fragment),
|
|
106
|
+
storage,
|
|
107
|
+
}));
|
|
108
|
+
const editor = BlockNoteEditor.create(
|
|
109
|
+
withCollaboration({
|
|
110
|
+
extensions: [Versions(), YHubVersioningExtension(options)],
|
|
111
|
+
collaboration: {
|
|
112
|
+
fragment,
|
|
113
|
+
user: { name: "Test", color: "red" },
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
try {
|
|
118
|
+
expect(editor.getExtension("versioning")).toBe(
|
|
119
|
+
editor.getExtension(Versions),
|
|
120
|
+
);
|
|
121
|
+
expect(editor.getExtension(Versions)).toBeDefined();
|
|
122
|
+
} finally {
|
|
123
|
+
editor._tiptapEditor.destroy();
|
|
124
|
+
doc.destroy();
|
|
125
|
+
}
|
|
126
|
+
});
|