@blocknote/core 0.51.4 → 0.52.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-B_IEJHS8.js +38 -0
- package/dist/BlockNoteExtension-B_IEJHS8.js.map +1 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs +2 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs.map +1 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs +2 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs.map +1 -0
- package/dist/ThreadStore-et9wB5Xt.js +11 -0
- package/dist/ThreadStore-et9wB5Xt.js.map +1 -0
- package/dist/UserStore-DCG6lsla.cjs +2 -0
- package/dist/UserStore-DCG6lsla.cjs.map +1 -0
- package/dist/UserStore-QbbPFj0z.js +73 -0
- package/dist/UserStore-QbbPFj0z.js.map +1 -0
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -7
- package/dist/blocks-BqHv0xhc.cjs +12 -0
- package/dist/blocks-BqHv0xhc.cjs.map +1 -0
- package/dist/{blocks-DGsP5WKr.js → blocks-CiuUGa1E.js} +1093 -994
- package/dist/blocks-CiuUGa1E.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +75 -340
- package/dist/comments.js.map +1 -1
- package/dist/{en-Cj5r8sW_.cjs → en-C5Z4Ag9_.cjs} +2 -2
- package/dist/en-C5Z4Ag9_.cjs.map +1 -0
- package/dist/{en-B9hMApn4.js → en-CGKXfWma.js} +9 -1
- package/dist/en-CGKXfWma.js.map +1 -0
- package/dist/{extensions-Co4y7P63.js → extensions-CrUGDOks.js} +655 -583
- package/dist/extensions-CrUGDOks.js.map +1 -0
- package/dist/extensions-Ghr9QqqR.cjs +52 -0
- package/dist/extensions-Ghr9QqqR.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 +177 -1
- package/dist/locales.js.map +1 -1
- package/dist/{src-Bcud0PIg.js → src-DTF83Cl9.js} +1243 -1297
- package/dist/src-DTF83Cl9.js.map +1 -0
- package/dist/src-OfbaVbMw.cjs +21 -0
- package/dist/src-OfbaVbMw.cjs.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +2 -0
- package/dist/y.cjs.map +1 -0
- package/dist/y.js +989 -0
- package/dist/y.js.map +1 -0
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +535 -14
- package/dist/yjs.js.map +1 -1
- package/package.json +46 -19
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +25 -20
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +39 -29
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +2 -2
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +4 -8
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +21 -9
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +6 -5
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +362 -4
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +240 -30
- package/src/api/blockManipulation/getBlock/getBlock.ts +4 -9
- package/src/api/blockManipulation/selections/selection.ts +3 -6
- package/src/api/blockManipulation/selections/textCursorPosition.ts +10 -10
- package/src/api/blockManipulation/setupTestEnv.ts +1 -1
- package/src/api/blockManipulation/tables/tables.test.ts +1 -1
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +1 -1
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +8 -4
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +2 -1
- package/src/api/exporters/markdown/htmlToMarkdown.ts +79 -43
- package/src/api/getBlockInfoFromPos.test.ts +256 -0
- package/src/api/getBlockInfoFromPos.ts +53 -15
- package/src/api/getBlocksChangedByTransaction.test.ts +2 -1
- package/src/api/getBlocksChangedByTransaction.ts +6 -6
- package/src/api/nodeConversions/blockToNode.test.ts +113 -0
- package/src/api/nodeConversions/blockToNode.ts +15 -3
- package/src/api/nodeConversions/fragmentToBlocks.ts +2 -4
- package/src/api/nodeConversions/nodeToBlock.ts +28 -58
- package/src/api/nodeUtil.ts +6 -2
- package/src/api/parsers/html/parseHTML.ts +1 -1
- package/src/api/parsers/html/util/nestedLists.test.ts +1 -1
- package/src/api/parsers/markdown/detectMarkdown.test.ts +1 -1
- package/src/api/parsers/markdown/markdownToHtml.ts +228 -82
- package/src/api/pmUtil.ts +18 -1
- package/src/api/positionMapping.test.ts +20 -345
- package/src/api/positionMapping.ts +13 -83
- package/src/blocks/Audio/block.ts +1 -1
- package/src/blocks/Code/block.test.ts +14 -7
- package/src/blocks/Code/block.ts +2 -2
- package/src/blocks/Image/block.ts +1 -1
- package/src/blocks/ListItem/CheckListItem/block.test.ts +1 -1
- package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +2 -2
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +4 -11
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +47 -50
- package/src/blocks/Table/TableExtension.test.ts +9 -6
- package/src/blocks/Table/TableExtension.ts +20 -6
- package/src/blocks/Table/block.ts +18 -5
- package/src/blocks/Video/block.ts +1 -1
- package/src/blocks/utils/listItemEnterHandler.ts +3 -2
- package/src/comments/extension.ts +30 -21
- package/src/comments/index.ts +0 -3
- package/src/comments/mark.ts +4 -0
- package/src/comments/threadstore/ThreadStore.ts +4 -8
- package/src/comments/types.ts +0 -8
- package/src/editor/Block.css +307 -3
- package/src/editor/BlockNoteEditor.test.ts +21 -18
- package/src/editor/BlockNoteEditor.ts +22 -57
- package/src/editor/BlockNoteExtension.test.ts +1 -1
- package/src/editor/managers/BlockManager.ts +1 -1
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +249 -0
- package/src/editor/managers/ExtensionManager/extensions.ts +7 -18
- package/src/editor/managers/ExtensionManager/index.ts +168 -68
- package/src/editor/managers/StateManager.ts +4 -3
- package/src/editor/performance.test.ts +14 -1
- package/src/editor/transformPasted.test.ts +1 -1
- package/src/extensions/Placeholder/Placeholder.ts +1 -0
- package/src/extensions/PositionMapping/PositionMapping.ts +68 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +14 -1
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +14 -11
- package/src/extensions/SideMenu/SideMenu.ts +9 -2
- package/src/extensions/SuggestionMenu/SuggestionMenu.test.ts +1 -1
- package/src/extensions/TableHandles/TableHandles.ts +18 -20
- package/src/extensions/TrailingNode/TrailingNode.ts +33 -1
- package/src/extensions/Versioning/Versioning.test.ts +435 -0
- package/src/extensions/Versioning/Versioning.ts +628 -0
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +469 -0
- package/src/extensions/Versioning/inMemoryVersioning.ts +263 -0
- package/src/extensions/Versioning/index.ts +2 -0
- package/src/extensions/index.ts +6 -9
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +155 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +6 -8
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +9 -9
- package/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts +8 -10
- package/src/extensions/tiptap-extensions/Link/helpers/whitespace.ts +2 -2
- package/src/extensions/tiptap-extensions/Link/link.test.ts +26 -22
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +187 -0
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +37 -24
- package/src/extensions/tiptap-extensions/index.ts +1 -25
- package/src/i18n/locales/ar.ts +9 -0
- package/src/i18n/locales/de.ts +9 -0
- package/src/i18n/locales/en.ts +10 -1
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fa.ts +11 -1
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/he.ts +10 -1
- package/src/i18n/locales/hr.ts +10 -0
- package/src/i18n/locales/is.ts +10 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/ja.ts +9 -0
- package/src/i18n/locales/ko.ts +9 -0
- package/src/i18n/locales/nl.ts +10 -0
- package/src/i18n/locales/no.ts +10 -0
- package/src/i18n/locales/pl.ts +9 -0
- package/src/i18n/locales/pt.ts +10 -0
- package/src/i18n/locales/ru.ts +10 -0
- package/src/i18n/locales/sk.ts +10 -1
- package/src/i18n/locales/uk.ts +9 -0
- package/src/i18n/locales/uz.ts +9 -0
- package/src/i18n/locales/vi.ts +9 -0
- package/src/i18n/locales/zh-tw.ts +9 -0
- package/src/i18n/locales/zh.ts +9 -0
- package/src/index.ts +2 -0
- package/src/pm-nodes/BlockContainer.ts +4 -1
- package/src/pm-nodes/BlockGroup.ts +4 -1
- package/src/pm-nodes/Doc.ts +4 -1
- package/src/pm-nodes/suggestionMarks.ts +43 -0
- package/src/schema/blocks/createSpec.test.ts +123 -0
- package/src/schema/blocks/createSpec.ts +82 -24
- package/src/schema/blocks/extendBlockSpec.test.ts +188 -0
- package/src/schema/blocks/internal.ts +13 -43
- package/src/schema/blocks/types.ts +69 -22
- package/src/schema/contentTypePropagation.test.ts +182 -0
- package/src/schema/index.ts +1 -0
- package/src/schema/inlineContent/internal.ts +1 -1
- package/src/schema/inlineContent/types.ts +3 -3
- package/src/schema/markGroups.ts +50 -0
- package/src/user/UserStore.ts +199 -0
- package/src/user/createUserStore.test.ts +126 -0
- package/src/user/index.ts +2 -0
- package/src/user/userColors.ts +72 -0
- package/src/util/string.ts +1 -1
- package/src/util/topo-sort.test.ts +1 -1
- package/src/util/typescript.ts +2 -1
- package/src/vite-env.d.ts +1 -1
- package/src/y/README.md +5 -0
- package/src/{comments/threadstore/yjs → y/comments}/RESTYjsThreadStore.ts +8 -14
- package/src/y/comments/YjsThreadStore.test.ts +295 -0
- package/src/y/comments/YjsThreadStore.ts +358 -0
- package/src/y/comments/YjsThreadStoreBase.ts +50 -0
- package/src/y/comments/index.ts +3 -0
- package/src/y/comments/yjsHelpers.ts +125 -0
- package/src/y/extensions/AttributionExtension.test.ts +86 -0
- package/src/y/extensions/AttributionExtension.ts +378 -0
- package/src/y/extensions/DiffVersioningExtension.test.ts +193 -0
- package/src/y/extensions/DiffVersioningExtension.ts +228 -0
- package/src/y/extensions/ForkYDoc.test.ts +253 -0
- package/src/y/extensions/ForkYDoc.ts +108 -0
- package/src/y/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/y/extensions/RelativePositionMapping.ts +49 -0
- package/src/y/extensions/Suggestions.ts +174 -0
- package/src/y/extensions/Versioning.test.ts +395 -0
- package/src/y/extensions/Versioning.ts +115 -0
- package/src/y/extensions/YAttributionMarks.ts +320 -0
- package/src/{extensions/Collaboration → y/extensions}/YCursorPlugin.ts +15 -7
- package/src/y/extensions/YSync.ts +125 -0
- package/src/y/extensions/blockMatchNodes.ts +182 -0
- package/src/y/extensions/index.ts +156 -0
- package/src/y/index.ts +4 -0
- package/src/y/utils.test.ts +1042 -0
- package/src/y/utils.ts +242 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.json +50 -0
- package/src/y/versioning/__test__/fixtures/activity-all.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all.json +20 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +32 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-before.json +1 -0
- package/src/y/versioning/__test__/fixtures/changeset.bin +0 -0
- package/src/y/versioning/__test__/fixtures/patch-response.json +4 -0
- package/src/y/versioning/__test__/yhub.test.ts +752 -0
- package/src/y/versioning/index.ts +1 -0
- package/src/y/versioning/yhub.ts +631 -0
- package/src/yjs/README.md +5 -0
- package/src/yjs/comments/RESTYjsThreadStore.ts +166 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.test.ts +3 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.ts +7 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.ts +3 -3
- package/src/yjs/comments/index.ts +3 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.ts +5 -1
- package/src/yjs/extensions/FixUpSchema.test.ts +421 -0
- package/src/yjs/extensions/FixUpSchema.ts +88 -0
- package/src/yjs/extensions/ForkYDoc.test.ts +216 -0
- package/src/{extensions/Collaboration → yjs/extensions}/ForkYDoc.ts +38 -57
- package/src/yjs/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/yjs/extensions/RelativePositionMapping.ts +71 -0
- package/src/yjs/extensions/Versioning.test.ts +549 -0
- package/src/yjs/extensions/Versioning.ts +83 -0
- package/src/yjs/extensions/YCursorPlugin.ts +201 -0
- package/src/{extensions/Collaboration → yjs/extensions}/YSync.ts +1 -1
- package/src/yjs/extensions/index.ts +89 -0
- package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.test.ts +1 -1
- package/src/yjs/index.ts +2 -0
- package/src/yjs/utils.test.ts +5 -15
- package/src/yjs/utils.ts +36 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +3 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
- package/types/src/api/getBlockInfoFromPos.d.ts +5 -9
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +4 -6
- package/types/src/api/pmUtil.d.ts +12 -1
- package/types/src/blocks/Audio/block.d.ts +2 -2
- package/types/src/blocks/Code/block.d.ts +2 -2
- package/types/src/blocks/File/block.d.ts +2 -2
- package/types/src/blocks/Heading/block.d.ts +21 -21
- package/types/src/blocks/Image/block.d.ts +3 -3
- package/types/src/blocks/ListItem/CheckListItem/block.d.ts +6 -6
- package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +6 -6
- package/types/src/blocks/Video/block.d.ts +3 -3
- package/types/src/blocks/defaultBlocks.d.ts +17 -17
- package/types/src/comments/extension.d.ts +18 -5
- package/types/src/comments/index.d.ts +0 -3
- package/types/src/comments/threadstore/ThreadStore.d.ts +4 -8
- package/types/src/comments/types.d.ts +0 -8
- package/types/src/editor/BlockNoteEditor.d.ts +8 -9
- package/types/src/editor/managers/BlockManager.d.ts +1 -1
- package/types/src/editor/managers/ExtensionManager/extensions.d.ts +2 -2
- package/types/src/editor/managers/ExtensionManager/index.d.ts +13 -0
- package/types/src/editor/managers/SelectionManager.d.ts +1 -1
- package/types/src/extensions/PositionMapping/PositionMapping.d.ts +4 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -6
- package/types/src/extensions/Versioning/Versioning.d.ts +352 -0
- package/types/src/extensions/Versioning/Versioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +37 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/index.d.ts +2 -0
- package/types/src/extensions/index.d.ts +6 -9
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +1 -0
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.d.ts +6 -1
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.d.ts +4 -0
- package/types/src/extensions/tiptap-extensions/index.d.ts +1 -5
- package/types/src/i18n/locales/en.d.ts +9 -1
- package/types/src/i18n/locales/fa.d.ts +9 -1
- package/types/src/i18n/locales/sk.d.ts +9 -1
- package/types/src/index.d.ts +2 -0
- package/types/src/pm-nodes/suggestionMarks.d.ts +26 -0
- package/types/src/schema/blocks/createSpec.d.ts +4 -4
- package/types/src/schema/blocks/createSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/extendBlockSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/internal.d.ts +5 -7
- package/types/src/schema/blocks/types.d.ts +22 -14
- package/types/src/schema/contentTypePropagation.test.d.ts +1 -0
- package/types/src/schema/index.d.ts +1 -0
- package/types/src/schema/inlineContent/types.d.ts +3 -3
- package/types/src/schema/markGroups.d.ts +33 -0
- package/types/src/user/UserStore.d.ts +105 -0
- package/types/src/user/createUserStore.test.d.ts +1 -0
- package/types/src/user/index.d.ts +2 -0
- package/types/src/user/userColors.d.ts +36 -0
- package/types/src/y/comments/RESTYjsThreadStore.d.ts +77 -0
- package/types/src/y/comments/YjsThreadStore.d.ts +79 -0
- package/types/src/y/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/y/comments/YjsThreadStoreBase.d.ts +15 -0
- package/types/src/y/comments/index.d.ts +3 -0
- package/types/src/y/comments/yjsHelpers.d.ts +13 -0
- package/types/src/y/extensions/AttributionExtension.d.ts +74 -0
- package/types/src/y/extensions/AttributionExtension.test.d.ts +1 -0
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +69 -0
- package/types/src/y/extensions/DiffVersioningExtension.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → y/extensions}/ForkYDoc.d.ts +4 -2
- package/types/src/y/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/y/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/y/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/y/extensions/Suggestions.d.ts +36 -0
- package/types/src/y/extensions/Versioning.d.ts +17 -0
- package/types/src/y/extensions/Versioning.test.d.ts +1 -0
- package/types/src/y/extensions/YAttributionMarks.d.ts +67 -0
- package/types/src/y/extensions/YCursorPlugin.d.ts +14 -0
- package/types/src/y/extensions/YSync.d.ts +32 -0
- package/types/src/y/extensions/blockMatchNodes.d.ts +25 -0
- package/types/src/y/extensions/index.d.ts +189 -0
- package/types/src/y/index.d.ts +4 -0
- package/types/src/y/utils.d.ts +82 -0
- package/types/src/y/utils.test.d.ts +1 -0
- package/types/src/y/versioning/__test__/yhub.test.d.ts +1 -0
- package/types/src/y/versioning/index.d.ts +1 -0
- package/types/src/y/versioning/yhub.d.ts +87 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/RESTYjsThreadStore.d.ts +6 -10
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.d.ts +3 -3
- package/types/src/yjs/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.d.ts +3 -3
- package/types/src/yjs/comments/index.d.ts +3 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.d.ts +1 -1
- package/types/src/yjs/extensions/FixUpSchema.d.ts +3 -0
- package/types/src/yjs/extensions/FixUpSchema.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +27 -0
- package/types/src/yjs/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/yjs/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/yjs/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/yjs/extensions/Versioning.d.ts +26 -0
- package/types/src/yjs/extensions/Versioning.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → yjs/extensions}/YCursorPlugin.d.ts +5 -2
- package/types/src/{extensions/Collaboration → yjs/extensions}/YSync.d.ts +1 -1
- package/types/src/{extensions/Collaboration/Collaboration.d.ts → yjs/extensions/index.d.ts} +36 -15
- package/types/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +1 -0
- package/types/src/yjs/index.d.ts +2 -0
- package/types/src/yjs/utils.d.ts +5 -0
- package/dist/BlockNoteExtension-B6RhuQ3V.js +0 -27
- package/dist/BlockNoteExtension-B6RhuQ3V.js.map +0 -1
- package/dist/BlockNoteExtension-ab0REuob.cjs +0 -2
- package/dist/BlockNoteExtension-ab0REuob.cjs.map +0 -1
- package/dist/EventEmitter-CuPnGDYt.js +0 -22
- package/dist/EventEmitter-CuPnGDYt.js.map +0 -1
- package/dist/EventEmitter-DHdSnYCD.cjs +0 -2
- package/dist/EventEmitter-DHdSnYCD.cjs.map +0 -1
- package/dist/ShowSelection-BsHFfdMi.js +0 -29
- package/dist/ShowSelection-BsHFfdMi.js.map +0 -1
- package/dist/ShowSelection-DhXglbt8.cjs +0 -2
- package/dist/ShowSelection-DhXglbt8.cjs.map +0 -1
- package/dist/blocks-Bm6IfL1R.cjs +0 -11
- package/dist/blocks-Bm6IfL1R.cjs.map +0 -1
- package/dist/blocks-DGsP5WKr.js.map +0 -1
- package/dist/en-B9hMApn4.js.map +0 -1
- package/dist/en-Cj5r8sW_.cjs.map +0 -1
- package/dist/extensions-Co4y7P63.js.map +0 -1
- package/dist/extensions-IJK3t0sz.cjs +0 -52
- package/dist/extensions-IJK3t0sz.cjs.map +0 -1
- package/dist/src-B6rlChSc.cjs +0 -21
- package/dist/src-B6rlChSc.cjs.map +0 -1
- package/dist/src-Bcud0PIg.js.map +0 -1
- package/src/comments/userstore/UserStore.ts +0 -72
- package/src/extensions/Collaboration/Collaboration.ts +0 -55
- package/src/extensions/Collaboration/ForkYDoc.test.ts +0 -179
- package/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.ts +0 -175
- package/types/src/comments/userstore/UserStore.d.ts +0 -31
- package/types/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.d.ts +0 -4
- /package/src/{extensions/Collaboration → yjs/extensions}/YUndo.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor-forked.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-forked.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.ts +0 -0
- /package/types/src/{comments/threadstore/yjs/YjsThreadStore.test.d.ts → api/getBlockInfoFromPos.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/ForkYDoc.test.d.ts → api/nodeConversions/blockToNode.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.d.ts → editor/managers/ExtensionManager/ExtensionManager.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/YUndo.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.d.ts +0 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { afterEach, describe, expect, it } from "vite-plus/test";
|
|
5
|
+
import * as Y from "yjs";
|
|
6
|
+
|
|
7
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
8
|
+
import { VersioningExtension } from "../../extensions/Versioning/index.js";
|
|
9
|
+
import type { VersioningEndpoints } from "../../extensions/Versioning/index.js";
|
|
10
|
+
import { withCollaboration } from "./index.js";
|
|
11
|
+
import { createYjsVersioningAdapter } from "./Versioning.js";
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Helpers
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
function createCollabEditor() {
|
|
18
|
+
const doc = new Y.Doc();
|
|
19
|
+
const fragment = doc.getXmlFragment("doc");
|
|
20
|
+
|
|
21
|
+
const collaborationOptions = {
|
|
22
|
+
fragment,
|
|
23
|
+
user: { color: "#ff0000", name: "Test User" },
|
|
24
|
+
provider: undefined,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const editor = BlockNoteEditor.create(
|
|
28
|
+
withCollaboration({
|
|
29
|
+
collaboration: collaborationOptions,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
const div = document.createElement("div");
|
|
33
|
+
editor.mount(div);
|
|
34
|
+
|
|
35
|
+
return { editor, doc, fragment, collaborationOptions };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getEditorText(editor: BlockNoteEditor<any, any, any>): string {
|
|
39
|
+
return editor.prosemirrorState.doc.textContent;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function setEditorText(editor: BlockNoteEditor<any, any, any>, text: string) {
|
|
43
|
+
editor.replaceBlocks(editor.document, [{ type: "paragraph", content: text }]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Tests
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
describe("createYjsVersioningAdapter (Yjs v13, delegates to ForkYDocExtension)", () => {
|
|
51
|
+
let ctx: ReturnType<typeof createCollabEditor>;
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
ctx.editor.unmount();
|
|
55
|
+
ctx.doc.destroy();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("getCurrentDocument returns the live fragment", () => {
|
|
59
|
+
ctx = createCollabEditor();
|
|
60
|
+
const adapter = createYjsVersioningAdapter(
|
|
61
|
+
ctx.editor,
|
|
62
|
+
ctx.collaborationOptions,
|
|
63
|
+
);
|
|
64
|
+
const state = adapter.getCurrentDocument();
|
|
65
|
+
expect(state.doc).toBe(ctx.doc);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("enterPreview shows snapshot content, not live doc", () => {
|
|
69
|
+
ctx = createCollabEditor();
|
|
70
|
+
setEditorText(ctx.editor, "Version A");
|
|
71
|
+
const snapshotUpdate = Y.encodeStateAsUpdate(ctx.doc);
|
|
72
|
+
|
|
73
|
+
setEditorText(ctx.editor, "Version B");
|
|
74
|
+
expect(getEditorText(ctx.editor)).toBe("Version B");
|
|
75
|
+
|
|
76
|
+
const adapter = createYjsVersioningAdapter(
|
|
77
|
+
ctx.editor,
|
|
78
|
+
ctx.collaborationOptions,
|
|
79
|
+
);
|
|
80
|
+
adapter.preview.enterPreview(snapshotUpdate);
|
|
81
|
+
expect(getEditorText(ctx.editor)).toBe("Version A");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("exitPreview restores the live document", () => {
|
|
85
|
+
ctx = createCollabEditor();
|
|
86
|
+
setEditorText(ctx.editor, "Version A");
|
|
87
|
+
const snapshotUpdate = Y.encodeStateAsUpdate(ctx.doc);
|
|
88
|
+
|
|
89
|
+
setEditorText(ctx.editor, "Version B");
|
|
90
|
+
|
|
91
|
+
const adapter = createYjsVersioningAdapter(
|
|
92
|
+
ctx.editor,
|
|
93
|
+
ctx.collaborationOptions,
|
|
94
|
+
);
|
|
95
|
+
adapter.preview.enterPreview(snapshotUpdate);
|
|
96
|
+
expect(getEditorText(ctx.editor)).toBe("Version A");
|
|
97
|
+
|
|
98
|
+
adapter.preview.exitPreview();
|
|
99
|
+
expect(getEditorText(ctx.editor)).toBe("Version B");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("successive enterPreview calls switch between snapshots", () => {
|
|
103
|
+
ctx = createCollabEditor();
|
|
104
|
+
|
|
105
|
+
// Create snapshot A
|
|
106
|
+
setEditorText(ctx.editor, "Snapshot A");
|
|
107
|
+
const snapshotA = Y.encodeStateAsUpdate(ctx.doc);
|
|
108
|
+
|
|
109
|
+
// Create snapshot B
|
|
110
|
+
setEditorText(ctx.editor, "Snapshot B");
|
|
111
|
+
const snapshotB = Y.encodeStateAsUpdate(ctx.doc);
|
|
112
|
+
|
|
113
|
+
// Move to different content
|
|
114
|
+
setEditorText(ctx.editor, "Current");
|
|
115
|
+
|
|
116
|
+
const adapter = createYjsVersioningAdapter(
|
|
117
|
+
ctx.editor,
|
|
118
|
+
ctx.collaborationOptions,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Preview A
|
|
122
|
+
adapter.preview.enterPreview(snapshotA);
|
|
123
|
+
expect(getEditorText(ctx.editor)).toBe("Snapshot A");
|
|
124
|
+
|
|
125
|
+
// Switch to preview B without explicitly exiting
|
|
126
|
+
adapter.preview.enterPreview(snapshotB);
|
|
127
|
+
expect(getEditorText(ctx.editor)).toBe("Snapshot B");
|
|
128
|
+
|
|
129
|
+
// Exit should restore live doc
|
|
130
|
+
adapter.preview.exitPreview();
|
|
131
|
+
expect(getEditorText(ctx.editor)).toBe("Current");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("switching previews does not introduce duplicate keyed plugins", () => {
|
|
135
|
+
ctx = createCollabEditor();
|
|
136
|
+
|
|
137
|
+
// Helper to find duplicate keyed plugins
|
|
138
|
+
function getDuplicateKeys() {
|
|
139
|
+
const plugins = ctx.editor.prosemirrorState.plugins;
|
|
140
|
+
const keys = plugins
|
|
141
|
+
.map((p: any) => p.spec?.key?.key)
|
|
142
|
+
.filter(Boolean) as string[];
|
|
143
|
+
return keys.filter((key, i) => keys.indexOf(key) !== i);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Create two snapshots
|
|
147
|
+
setEditorText(ctx.editor, "Snap A");
|
|
148
|
+
const snapA = Y.encodeStateAsUpdate(ctx.doc);
|
|
149
|
+
|
|
150
|
+
setEditorText(ctx.editor, "Snap B");
|
|
151
|
+
const snapB = Y.encodeStateAsUpdate(ctx.doc);
|
|
152
|
+
|
|
153
|
+
setEditorText(ctx.editor, "Live");
|
|
154
|
+
|
|
155
|
+
const adapter = createYjsVersioningAdapter(
|
|
156
|
+
ctx.editor,
|
|
157
|
+
ctx.collaborationOptions,
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Baseline: no duplicates before any preview
|
|
161
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
162
|
+
|
|
163
|
+
// First preview (fork)
|
|
164
|
+
adapter.preview.enterPreview(snapA);
|
|
165
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
166
|
+
expect(getEditorText(ctx.editor)).toBe("Snap A");
|
|
167
|
+
|
|
168
|
+
// Switch directly to second preview (merge + fork)
|
|
169
|
+
adapter.preview.enterPreview(snapB);
|
|
170
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
171
|
+
expect(getEditorText(ctx.editor)).toBe("Snap B");
|
|
172
|
+
|
|
173
|
+
// Third switch
|
|
174
|
+
adapter.preview.enterPreview(snapA);
|
|
175
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
176
|
+
expect(getEditorText(ctx.editor)).toBe("Snap A");
|
|
177
|
+
|
|
178
|
+
// Exit and verify no duplicates remain
|
|
179
|
+
adapter.preview.exitPreview();
|
|
180
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("preview → exit → preview again does not duplicate keyed plugins", () => {
|
|
184
|
+
ctx = createCollabEditor();
|
|
185
|
+
|
|
186
|
+
// Helper to find duplicate keyed plugins
|
|
187
|
+
function getDuplicateKeys() {
|
|
188
|
+
const plugins = ctx.editor.prosemirrorState.plugins;
|
|
189
|
+
const keys = plugins
|
|
190
|
+
.map((p: any) => p.spec?.key?.key)
|
|
191
|
+
.filter(Boolean) as string[];
|
|
192
|
+
return keys.filter((key, i) => keys.indexOf(key) !== i);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
setEditorText(ctx.editor, "Snap A");
|
|
196
|
+
const snapA = Y.encodeStateAsUpdate(ctx.doc);
|
|
197
|
+
|
|
198
|
+
setEditorText(ctx.editor, "Live");
|
|
199
|
+
|
|
200
|
+
const adapter = createYjsVersioningAdapter(
|
|
201
|
+
ctx.editor,
|
|
202
|
+
ctx.collaborationOptions,
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const pluginCountBefore = ctx.editor.prosemirrorState.plugins.length;
|
|
206
|
+
|
|
207
|
+
// Preview
|
|
208
|
+
adapter.preview.enterPreview(snapA);
|
|
209
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
210
|
+
|
|
211
|
+
// Exit back to live
|
|
212
|
+
adapter.preview.exitPreview();
|
|
213
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
214
|
+
// Plugin count should be back to original
|
|
215
|
+
expect(ctx.editor.prosemirrorState.plugins.length).toBe(pluginCountBefore);
|
|
216
|
+
|
|
217
|
+
// Preview again — this is the exact flow that triggers the browser bug
|
|
218
|
+
adapter.preview.enterPreview(snapA);
|
|
219
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
220
|
+
|
|
221
|
+
// Exit again
|
|
222
|
+
adapter.preview.exitPreview();
|
|
223
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
224
|
+
expect(ctx.editor.prosemirrorState.plugins.length).toBe(pluginCountBefore);
|
|
225
|
+
|
|
226
|
+
// One more round trip to be thorough
|
|
227
|
+
adapter.preview.enterPreview(snapA);
|
|
228
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
229
|
+
adapter.preview.exitPreview();
|
|
230
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
231
|
+
expect(ctx.editor.prosemirrorState.plugins.length).toBe(pluginCountBefore);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("applyRestore throws not-yet-implemented error", () => {
|
|
235
|
+
ctx = createCollabEditor();
|
|
236
|
+
const adapter = createYjsVersioningAdapter(
|
|
237
|
+
ctx.editor,
|
|
238
|
+
ctx.collaborationOptions,
|
|
239
|
+
);
|
|
240
|
+
expect(() => adapter.preview.applyRestore(new Uint8Array())).toThrow(
|
|
241
|
+
/not yet implemented/i,
|
|
242
|
+
);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("exitPreview is a no-op when not previewing", () => {
|
|
246
|
+
ctx = createCollabEditor();
|
|
247
|
+
setEditorText(ctx.editor, "Content");
|
|
248
|
+
|
|
249
|
+
const adapter = createYjsVersioningAdapter(
|
|
250
|
+
ctx.editor,
|
|
251
|
+
ctx.collaborationOptions,
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
// Should not throw
|
|
255
|
+
adapter.preview.exitPreview();
|
|
256
|
+
expect(getEditorText(ctx.editor)).toBe("Content");
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("throws when ForkYDocExtension is not registered", () => {
|
|
260
|
+
// Create an editor with collaboration but without ForkYDocExtension.
|
|
261
|
+
// We can't easily remove it from CollaborationExtension, but we can
|
|
262
|
+
// create a minimal editor and pass the adapter directly.
|
|
263
|
+
const doc = new Y.Doc();
|
|
264
|
+
const fragment = doc.getXmlFragment("doc");
|
|
265
|
+
const editor = BlockNoteEditor.create();
|
|
266
|
+
const div = document.createElement("div");
|
|
267
|
+
editor.mount(div);
|
|
268
|
+
|
|
269
|
+
const adapter = createYjsVersioningAdapter(editor, {
|
|
270
|
+
fragment,
|
|
271
|
+
user: { name: "Test", color: "#000" },
|
|
272
|
+
provider: undefined,
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
expect(() =>
|
|
276
|
+
adapter.preview.enterPreview(Y.encodeStateAsUpdate(doc)),
|
|
277
|
+
).toThrow(/ForkYDocExtension/);
|
|
278
|
+
|
|
279
|
+
editor.unmount();
|
|
280
|
+
doc.destroy();
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
// Helpers for integration tests
|
|
286
|
+
// ---------------------------------------------------------------------------
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Simple in-memory Yjs v13 versioning endpoints for tests.
|
|
290
|
+
*/
|
|
291
|
+
function createInMemoryYjsEndpoints(): VersioningEndpoints<
|
|
292
|
+
Y.XmlFragment,
|
|
293
|
+
Uint8Array
|
|
294
|
+
> {
|
|
295
|
+
const snapshots = new Map<
|
|
296
|
+
string,
|
|
297
|
+
{
|
|
298
|
+
id: string;
|
|
299
|
+
name?: string;
|
|
300
|
+
createdAt: number;
|
|
301
|
+
updatedAt: number;
|
|
302
|
+
restoredFromSnapshotId?: string;
|
|
303
|
+
}
|
|
304
|
+
>();
|
|
305
|
+
const contents = new Map<string, Uint8Array>();
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
list: async () =>
|
|
309
|
+
[...snapshots.values()].sort((a, b) => b.createdAt - a.createdAt),
|
|
310
|
+
create: async (fragment, options) => {
|
|
311
|
+
const snapshot = {
|
|
312
|
+
id: crypto.randomUUID(),
|
|
313
|
+
name: options?.name,
|
|
314
|
+
createdAt: Date.now(),
|
|
315
|
+
updatedAt: Date.now(),
|
|
316
|
+
restoredFromSnapshotId: options?.restoredFromSnapshot?.id
|
|
317
|
+
? String(options.restoredFromSnapshot.id)
|
|
318
|
+
: undefined,
|
|
319
|
+
};
|
|
320
|
+
contents.set(snapshot.id, Y.encodeStateAsUpdate(fragment.doc!));
|
|
321
|
+
snapshots.set(snapshot.id, snapshot);
|
|
322
|
+
return snapshot;
|
|
323
|
+
},
|
|
324
|
+
getContent: async (snapshot) => {
|
|
325
|
+
const data = contents.get(String(snapshot.id));
|
|
326
|
+
if (!data) {
|
|
327
|
+
throw new Error(`Snapshot ${String(snapshot.id)} not found`);
|
|
328
|
+
}
|
|
329
|
+
return data;
|
|
330
|
+
},
|
|
331
|
+
restore: async (fragment, snapshot) => {
|
|
332
|
+
const backup = {
|
|
333
|
+
id: crypto.randomUUID(),
|
|
334
|
+
name: "Backup",
|
|
335
|
+
createdAt: Date.now(),
|
|
336
|
+
updatedAt: Date.now(),
|
|
337
|
+
};
|
|
338
|
+
contents.set(backup.id, Y.encodeStateAsUpdate(fragment.doc!));
|
|
339
|
+
snapshots.set(backup.id, backup);
|
|
340
|
+
|
|
341
|
+
const snapshotContent = contents.get(String(snapshot.id))!;
|
|
342
|
+
return snapshotContent;
|
|
343
|
+
},
|
|
344
|
+
rename: async (snapshot, name) => {
|
|
345
|
+
const s = snapshots.get(String(snapshot.id));
|
|
346
|
+
if (!s) {
|
|
347
|
+
throw new Error(`Snapshot ${String(snapshot.id)} not found`);
|
|
348
|
+
}
|
|
349
|
+
s.name = name;
|
|
350
|
+
s.updatedAt = Date.now();
|
|
351
|
+
},
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ---------------------------------------------------------------------------
|
|
356
|
+
// Integration tests: VersioningExtension + Yjs v13 adapter
|
|
357
|
+
// ---------------------------------------------------------------------------
|
|
358
|
+
|
|
359
|
+
describe("Yjs v13 versioning integration (VersioningExtension + in-memory endpoints)", () => {
|
|
360
|
+
function createCollabEditorWithVersioning() {
|
|
361
|
+
const doc = new Y.Doc();
|
|
362
|
+
const fragment = doc.getXmlFragment("doc");
|
|
363
|
+
|
|
364
|
+
const endpoints = createInMemoryYjsEndpoints();
|
|
365
|
+
|
|
366
|
+
const collaborationOptions: import("./index.js").CollaborationOptions = {
|
|
367
|
+
fragment,
|
|
368
|
+
user: { name: "Test User", color: "#ff0000" },
|
|
369
|
+
provider: undefined,
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const editor = BlockNoteEditor.create(
|
|
373
|
+
withCollaboration({
|
|
374
|
+
collaboration: collaborationOptions,
|
|
375
|
+
extensions: [
|
|
376
|
+
VersioningExtension((ed) => ({
|
|
377
|
+
...createYjsVersioningAdapter(ed, collaborationOptions),
|
|
378
|
+
endpoints,
|
|
379
|
+
})),
|
|
380
|
+
],
|
|
381
|
+
}),
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
const div = document.createElement("div");
|
|
385
|
+
editor.mount(div);
|
|
386
|
+
|
|
387
|
+
return { editor, doc, fragment, endpoints };
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
let ctx2: ReturnType<typeof createCollabEditorWithVersioning>;
|
|
391
|
+
|
|
392
|
+
afterEach(() => {
|
|
393
|
+
ctx2.editor.unmount();
|
|
394
|
+
ctx2.doc.destroy();
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it("previews a snapshot, showing old content", async () => {
|
|
398
|
+
ctx2 = createCollabEditorWithVersioning();
|
|
399
|
+
const versioning = ctx2.editor.getExtension(VersioningExtension)!;
|
|
400
|
+
|
|
401
|
+
setEditorText(ctx2.editor, "Snapshot content");
|
|
402
|
+
const snap = await versioning.create!({ name: "v1" });
|
|
403
|
+
|
|
404
|
+
setEditorText(ctx2.editor, "Current content");
|
|
405
|
+
|
|
406
|
+
await versioning.previewSnapshot(snap.id);
|
|
407
|
+
expect(versioning.store.state.previewedSnapshotId).toBe(snap.id);
|
|
408
|
+
expect(getEditorText(ctx2.editor)).toBe("Snapshot content");
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("exits preview and returns to live document", async () => {
|
|
412
|
+
ctx2 = createCollabEditorWithVersioning();
|
|
413
|
+
const versioning = ctx2.editor.getExtension(VersioningExtension)!;
|
|
414
|
+
|
|
415
|
+
setEditorText(ctx2.editor, "Saved state");
|
|
416
|
+
const snap = await versioning.create!({ name: "v1" });
|
|
417
|
+
|
|
418
|
+
setEditorText(ctx2.editor, "Live state");
|
|
419
|
+
|
|
420
|
+
await versioning.previewSnapshot(snap.id);
|
|
421
|
+
versioning.exitPreview();
|
|
422
|
+
|
|
423
|
+
expect(getEditorText(ctx2.editor)).toBe("Live state");
|
|
424
|
+
expect(versioning.store.state.previewedSnapshotId).toBeUndefined();
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it("full workflow: create multiple versions, preview, switch, exit", async () => {
|
|
428
|
+
ctx2 = createCollabEditorWithVersioning();
|
|
429
|
+
const versioning = ctx2.editor.getExtension(VersioningExtension)!;
|
|
430
|
+
|
|
431
|
+
// Create two versions
|
|
432
|
+
setEditorText(ctx2.editor, "Version 1");
|
|
433
|
+
const v1 = await versioning.create!({ name: "v1" });
|
|
434
|
+
|
|
435
|
+
setEditorText(ctx2.editor, "Version 2");
|
|
436
|
+
const v2 = await versioning.create!({ name: "v2" });
|
|
437
|
+
|
|
438
|
+
setEditorText(ctx2.editor, "Current state");
|
|
439
|
+
|
|
440
|
+
// List
|
|
441
|
+
const list = await versioning.list();
|
|
442
|
+
expect(list).toHaveLength(2);
|
|
443
|
+
|
|
444
|
+
// Preview older, then switch to newer
|
|
445
|
+
await versioning.previewSnapshot(v1.id);
|
|
446
|
+
expect(getEditorText(ctx2.editor)).toBe("Version 1");
|
|
447
|
+
|
|
448
|
+
await versioning.previewSnapshot(v2.id);
|
|
449
|
+
expect(getEditorText(ctx2.editor)).toBe("Version 2");
|
|
450
|
+
|
|
451
|
+
// Exit back to live
|
|
452
|
+
versioning.exitPreview();
|
|
453
|
+
expect(getEditorText(ctx2.editor)).toBe("Current state");
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it("preview → preview → exit → preview does not crash (keyed plugin collision)", async () => {
|
|
457
|
+
ctx2 = createCollabEditorWithVersioning();
|
|
458
|
+
const versioning = ctx2.editor.getExtension(VersioningExtension)!;
|
|
459
|
+
|
|
460
|
+
// Helper to find duplicate keyed plugins
|
|
461
|
+
function getDuplicateKeys() {
|
|
462
|
+
const plugins = ctx2.editor.prosemirrorState.plugins;
|
|
463
|
+
const keys = plugins
|
|
464
|
+
.map((p: any) => p.spec?.key?.key)
|
|
465
|
+
.filter(Boolean) as string[];
|
|
466
|
+
return keys.filter((key, i) => keys.indexOf(key) !== i);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// Create two versions
|
|
470
|
+
setEditorText(ctx2.editor, "Version 1");
|
|
471
|
+
const v1 = await versioning.create!({ name: "v1" });
|
|
472
|
+
|
|
473
|
+
setEditorText(ctx2.editor, "Version 2");
|
|
474
|
+
const v2 = await versioning.create!({ name: "v2" });
|
|
475
|
+
|
|
476
|
+
setEditorText(ctx2.editor, "Current state");
|
|
477
|
+
|
|
478
|
+
const pluginCountBefore = ctx2.editor.prosemirrorState.plugins.length;
|
|
479
|
+
|
|
480
|
+
// preview
|
|
481
|
+
await versioning.previewSnapshot(v1.id);
|
|
482
|
+
expect(getEditorText(ctx2.editor)).toBe("Version 1");
|
|
483
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
484
|
+
|
|
485
|
+
// preview (switch)
|
|
486
|
+
await versioning.previewSnapshot(v2.id);
|
|
487
|
+
expect(getEditorText(ctx2.editor)).toBe("Version 2");
|
|
488
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
489
|
+
|
|
490
|
+
// exit
|
|
491
|
+
versioning.exitPreview();
|
|
492
|
+
expect(getEditorText(ctx2.editor)).toBe("Current state");
|
|
493
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
494
|
+
expect(ctx2.editor.prosemirrorState.plugins.length).toBe(pluginCountBefore);
|
|
495
|
+
|
|
496
|
+
// preview again — this is the sequence that triggers the browser crash
|
|
497
|
+
await versioning.previewSnapshot(v1.id);
|
|
498
|
+
expect(getEditorText(ctx2.editor)).toBe("Version 1");
|
|
499
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it("preview → exit → edit → snapshot → preview new snapshot (exact user-reported flow)", async () => {
|
|
503
|
+
ctx2 = createCollabEditorWithVersioning();
|
|
504
|
+
const versioning = ctx2.editor.getExtension(VersioningExtension)!;
|
|
505
|
+
|
|
506
|
+
// Helper to find duplicate keyed plugins
|
|
507
|
+
function getDuplicateKeys() {
|
|
508
|
+
const plugins = ctx2.editor.prosemirrorState.plugins;
|
|
509
|
+
const keys = plugins
|
|
510
|
+
.map((p: any) => p.spec?.key?.key)
|
|
511
|
+
.filter(Boolean) as string[];
|
|
512
|
+
return keys.filter((key, i) => keys.indexOf(key) !== i);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// Step 1: Create initial content and snapshot
|
|
516
|
+
setEditorText(ctx2.editor, "Version 1");
|
|
517
|
+
const v1 = await versioning.create!({ name: "v1" });
|
|
518
|
+
|
|
519
|
+
setEditorText(ctx2.editor, "Current state");
|
|
520
|
+
|
|
521
|
+
// Step 2: Preview the snapshot
|
|
522
|
+
await versioning.previewSnapshot(v1.id);
|
|
523
|
+
expect(getEditorText(ctx2.editor)).toBe("Version 1");
|
|
524
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
525
|
+
|
|
526
|
+
// Step 3: Exit back to live
|
|
527
|
+
versioning.exitPreview();
|
|
528
|
+
expect(getEditorText(ctx2.editor)).toBe("Current state");
|
|
529
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
530
|
+
|
|
531
|
+
// Step 4: EDIT the document (this is the key difference from previous tests)
|
|
532
|
+
setEditorText(ctx2.editor, "Edited after preview");
|
|
533
|
+
|
|
534
|
+
// Step 5: Create a NEW snapshot of the edited content
|
|
535
|
+
const v2 = await versioning.create!({ name: "v2" });
|
|
536
|
+
|
|
537
|
+
// Step 6: Preview the NEW snapshot — this is where the browser crash happened
|
|
538
|
+
// before the replaceExtension fix (y-prosemirror's view hooks would dispatch
|
|
539
|
+
// a transaction between separate unregister/register calls, re-introducing
|
|
540
|
+
// stale y-sync$ plugins).
|
|
541
|
+
await versioning.previewSnapshot(v2.id);
|
|
542
|
+
expect(getEditorText(ctx2.editor)).toBe("Edited after preview");
|
|
543
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
544
|
+
|
|
545
|
+
// Clean exit
|
|
546
|
+
versioning.exitPreview();
|
|
547
|
+
expect(getDuplicateKeys()).toEqual([]);
|
|
548
|
+
});
|
|
549
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
|
|
3
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
4
|
+
import type { PreviewController } from "../../extensions/Versioning/index.js";
|
|
5
|
+
import type { CollaborationOptions } from "./index.js";
|
|
6
|
+
import { ForkYDocExtension } from "./ForkYDoc.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Yjs v13 adapter that provides the {@link PreviewController}
|
|
10
|
+
* and `getCurrentDocument` callback required by the base
|
|
11
|
+
* {@link VersioningExtension}.
|
|
12
|
+
*
|
|
13
|
+
* Delegates to the {@link ForkYDocExtension} for entering/exiting preview:
|
|
14
|
+
* - **enterPreview**: calls `fork({ initialUpdate: snapshotContent })` to
|
|
15
|
+
* switch the editor to a temporary doc built from the snapshot.
|
|
16
|
+
* - **exitPreview**: calls `merge({ keepChanges: false })` to discard the
|
|
17
|
+
* preview and restore the live document.
|
|
18
|
+
* - **applyRestore**: calls `merge({ keepChanges: true })` to apply the
|
|
19
|
+
* snapshot content back to the live document.
|
|
20
|
+
*/
|
|
21
|
+
export function createYjsVersioningAdapter(
|
|
22
|
+
/** The BlockNote editor instance (must have ForkYDocExtension). */
|
|
23
|
+
editor: BlockNoteEditor<any, any, any>,
|
|
24
|
+
/** The full collaboration options (used for `fragment` access). */
|
|
25
|
+
options: CollaborationOptions,
|
|
26
|
+
): {
|
|
27
|
+
preview: PreviewController<Uint8Array>;
|
|
28
|
+
getCurrentDocument: () => Y.XmlFragment;
|
|
29
|
+
serializeCurrentContent: () => Uint8Array;
|
|
30
|
+
} {
|
|
31
|
+
const { fragment } = options;
|
|
32
|
+
|
|
33
|
+
function getForkYDoc() {
|
|
34
|
+
const ext = editor.getExtension(ForkYDocExtension);
|
|
35
|
+
if (!ext) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"ForkYDocExtension is required for the Yjs versioning adapter. " +
|
|
38
|
+
"Make sure it is registered before the VersioningExtension.",
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return ext;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
getCurrentDocument: () => fragment,
|
|
46
|
+
serializeCurrentContent: () => Y.encodeStateAsUpdateV2(fragment.doc!),
|
|
47
|
+
preview: {
|
|
48
|
+
// Yjs v13 can only fork the document to a single snapshot; it has no way
|
|
49
|
+
// to diff two versions, so comparison is unsupported.
|
|
50
|
+
supportsComparison: false,
|
|
51
|
+
enterPreview(
|
|
52
|
+
snapshotContent: Uint8Array,
|
|
53
|
+
_compareToContent?: Uint8Array,
|
|
54
|
+
) {
|
|
55
|
+
const forkYDoc = getForkYDoc();
|
|
56
|
+
|
|
57
|
+
// If already in a preview (forked state), exit first.
|
|
58
|
+
if (forkYDoc.store.state.isForked) {
|
|
59
|
+
forkYDoc.merge({ keepChanges: false });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
forkYDoc.fork({ initialUpdate: snapshotContent });
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
exitPreview() {
|
|
66
|
+
const forkYDoc = getForkYDoc();
|
|
67
|
+
if (forkYDoc.store.state.isForked) {
|
|
68
|
+
forkYDoc.merge({ keepChanges: false });
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
applyRestore(_snapshotContent: Uint8Array) {
|
|
73
|
+
// Restoring to an older Yjs state cannot be done by merging a fork
|
|
74
|
+
// because the original doc already contains all CRDT state vectors
|
|
75
|
+
// from the snapshot. Restore must be handled at the endpoint/server
|
|
76
|
+
// level (e.g., the server creates a new Y.Doc and syncs it).
|
|
77
|
+
throw new Error(
|
|
78
|
+
"Restore is not yet implemented for Yjs v13 versioning adapter.",
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|