@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,88 @@
|
|
|
1
|
+
import { Attrs, Fragment, Mark, Node, NodeType } from "prosemirror-model";
|
|
2
|
+
|
|
3
|
+
import { isPlainContentNodeType } from "../../api/pmUtil.js";
|
|
4
|
+
import { createExtension } from "../../editor/BlockNoteExtension.js";
|
|
5
|
+
|
|
6
|
+
// Collaboration-only patches to the live ProseMirror schema. Both are applied
|
|
7
|
+
// once on `create`, before y-prosemirror binds and reconstructs the document.
|
|
8
|
+
export const FixUpSchemaExtension = createExtension(({ editor }) => {
|
|
9
|
+
editor.on("create", () => {
|
|
10
|
+
const schema = editor.pmSchema;
|
|
11
|
+
|
|
12
|
+
// 1. Preserve the initial block id.
|
|
13
|
+
// When y-prosemirror creates an empty document, the `blockContainer` node is created with an `id` of `null`.
|
|
14
|
+
// This causes the unique id extension to generate a new id for the initial block, which is not what we want
|
|
15
|
+
// Since it will be randomly generated & cause there to be more updates to the ydoc
|
|
16
|
+
// This is a hack to make it so that anytime `schema.doc.createAndFill` is called, the initial block id is already set to "initialBlockId"
|
|
17
|
+
let cache: Node | undefined = undefined;
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method -- intentionally saving reference for monkey-patching
|
|
19
|
+
const oldCreateAndFill = schema.nodes.doc.createAndFill;
|
|
20
|
+
schema.nodes.doc.createAndFill = ((...args: any) => {
|
|
21
|
+
if (cache) {
|
|
22
|
+
return cache;
|
|
23
|
+
}
|
|
24
|
+
const ret = oldCreateAndFill.apply(schema.nodes.doc, args)!;
|
|
25
|
+
|
|
26
|
+
// create a copy that we can mutate (otherwise, assigning attrs is not safe and corrupts the pm state)
|
|
27
|
+
const jsonNode = JSON.parse(JSON.stringify(ret.toJSON()));
|
|
28
|
+
jsonNode.content[0].content[0].attrs.id = "initialBlockId";
|
|
29
|
+
|
|
30
|
+
cache = Node.fromJSON(schema, jsonNode);
|
|
31
|
+
return cache;
|
|
32
|
+
}) as unknown as typeof schema.nodes.doc.createAndFill;
|
|
33
|
+
|
|
34
|
+
// 2. Drop marks a plain block no longer allows, instead of deleting the block.
|
|
35
|
+
// When a block's content type changes across BlockNote versions — e.g. a
|
|
36
|
+
// `codeBlock` that was `"inline"` (formatting marks like bold allowed) and is
|
|
37
|
+
// now `"plain"` (only the `"annotation"` mark group: comments + suggestions) —
|
|
38
|
+
// old Yjs documents carry text with marks the new node type disallows.
|
|
39
|
+
//
|
|
40
|
+
// y-prosemirror rebuilds each block by calling `schema.node(nodeName, attrs,
|
|
41
|
+
// children)`, where `children` are text nodes that may still carry those
|
|
42
|
+
// disallowed marks. `createChecked` then throws, and y-prosemirror's error
|
|
43
|
+
// handler DELETES the whole block from the Yjs doc — a deletion that propagates
|
|
44
|
+
// to every peer (data loss).
|
|
45
|
+
//
|
|
46
|
+
// Rather than mutating the Yjs doc to strip those marks, we leave them in place
|
|
47
|
+
// (marks are just format attributes; they don't affect position counting, so
|
|
48
|
+
// editing text is unaffected) and simply never materialize the disallowed ones
|
|
49
|
+
// into ProseMirror. We do that by wrapping `schema.node` to filter each text
|
|
50
|
+
// child's marks through the parent node type's `allowedMarks` before the node
|
|
51
|
+
// is built. The wrapper is scoped to plain-content blocks (the only place this
|
|
52
|
+
// migration applies); all other node types pass through untouched.
|
|
53
|
+
//
|
|
54
|
+
// NOTE: this covers marks that EXIST in the schema but aren't allowed on the
|
|
55
|
+
// node. A mark whose type is entirely absent from the schema still hits
|
|
56
|
+
// y-prosemirror's earlier `schema.mark` throw (and delete) path — that's a
|
|
57
|
+
// different migration scenario and is out of scope here.
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method -- intentionally saving reference for monkey-patching
|
|
59
|
+
const originalNode = schema.node;
|
|
60
|
+
schema.node = function (
|
|
61
|
+
this: typeof schema,
|
|
62
|
+
type: string | NodeType,
|
|
63
|
+
attrs?: Attrs | null,
|
|
64
|
+
content?: Fragment | Node | readonly Node[],
|
|
65
|
+
marks?: readonly Mark[],
|
|
66
|
+
) {
|
|
67
|
+
const nodeType = typeof type === "string" ? this.nodes[type] : type;
|
|
68
|
+
// y-prosemirror always passes `content` as a plain array of nodes; only
|
|
69
|
+
// touch text children that carry marks.
|
|
70
|
+
if (
|
|
71
|
+
nodeType &&
|
|
72
|
+
isPlainContentNodeType(this, nodeType) &&
|
|
73
|
+
Array.isArray(content)
|
|
74
|
+
) {
|
|
75
|
+
content = (content as readonly Node[]).map((child) =>
|
|
76
|
+
child?.isText && child.marks.length
|
|
77
|
+
? child.mark(nodeType.allowedMarks(child.marks))
|
|
78
|
+
: child,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return originalNode.call(this, type, attrs, content, marks);
|
|
82
|
+
} as typeof schema.node;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
key: "fixUpSchema",
|
|
87
|
+
} as const;
|
|
88
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vite-plus/test";
|
|
2
|
+
import * as Y from "yjs";
|
|
3
|
+
import { Awareness } from "y-protocols/awareness";
|
|
4
|
+
import { BlockNoteEditor } from "../../index.js";
|
|
5
|
+
import { ForkYDocExtension } from "./ForkYDoc.js";
|
|
6
|
+
import { withCollaboration } from "./index.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @vitest-environment jsdom
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function createCollabEditor() {
|
|
13
|
+
const doc = new Y.Doc();
|
|
14
|
+
const fragment = doc.getXmlFragment("doc");
|
|
15
|
+
const editor = BlockNoteEditor.create(
|
|
16
|
+
withCollaboration({
|
|
17
|
+
collaboration: {
|
|
18
|
+
fragment,
|
|
19
|
+
user: { name: "Test User", color: "#FF0000" },
|
|
20
|
+
provider: { awareness: new Awareness(doc) },
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
const div = document.createElement("div");
|
|
25
|
+
editor.mount(div);
|
|
26
|
+
return { editor, doc, fragment };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getEditorText(editor: BlockNoteEditor) {
|
|
30
|
+
return editor.prosemirrorState.doc.textContent;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function setEditorText(editor: BlockNoteEditor, text: string) {
|
|
34
|
+
editor.replaceBlocks(editor.document, [
|
|
35
|
+
{
|
|
36
|
+
type: "paragraph",
|
|
37
|
+
content: [{ text, styles: {}, type: "text" }],
|
|
38
|
+
},
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let ctx: ReturnType<typeof createCollabEditor>;
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
ctx?.editor.unmount();
|
|
46
|
+
ctx?.doc.destroy();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("ForkYDocExtension", () => {
|
|
50
|
+
it("forks the document — edits do not affect the original fragment", () => {
|
|
51
|
+
ctx = createCollabEditor();
|
|
52
|
+
setEditorText(ctx.editor, "Original");
|
|
53
|
+
|
|
54
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
55
|
+
forkYDoc.fork();
|
|
56
|
+
|
|
57
|
+
// Edit while forked
|
|
58
|
+
setEditorText(ctx.editor, "Forked edit");
|
|
59
|
+
|
|
60
|
+
// The original fragment should still have the original content
|
|
61
|
+
expect(ctx.fragment.toJSON()).toContain("Original");
|
|
62
|
+
expect(getEditorText(ctx.editor)).toBe("Forked edit");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("merge({ keepChanges: false }) discards forked edits", () => {
|
|
66
|
+
ctx = createCollabEditor();
|
|
67
|
+
setEditorText(ctx.editor, "Original");
|
|
68
|
+
|
|
69
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
70
|
+
forkYDoc.fork();
|
|
71
|
+
setEditorText(ctx.editor, "Forked edit");
|
|
72
|
+
|
|
73
|
+
forkYDoc.merge({ keepChanges: false });
|
|
74
|
+
|
|
75
|
+
expect(getEditorText(ctx.editor)).toBe("Original");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("merge({ keepChanges: true }) applies forked edits to the original doc", () => {
|
|
79
|
+
ctx = createCollabEditor();
|
|
80
|
+
setEditorText(ctx.editor, "Original");
|
|
81
|
+
|
|
82
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
83
|
+
forkYDoc.fork();
|
|
84
|
+
setEditorText(ctx.editor, "Forked edit");
|
|
85
|
+
|
|
86
|
+
forkYDoc.merge({ keepChanges: true });
|
|
87
|
+
|
|
88
|
+
// The editor and original fragment should both reflect the forked edit
|
|
89
|
+
expect(getEditorText(ctx.editor)).toContain("Forked edit");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("fork({ initialUpdate }) uses the provided update instead of the live doc", () => {
|
|
93
|
+
ctx = createCollabEditor();
|
|
94
|
+
setEditorText(ctx.editor, "Current content");
|
|
95
|
+
|
|
96
|
+
// Create a snapshot of an earlier state
|
|
97
|
+
const snapshotDoc = new Y.Doc();
|
|
98
|
+
// Manually build content in the snapshot doc
|
|
99
|
+
Y.applyUpdate(snapshotDoc, Y.encodeStateAsUpdate(ctx.doc));
|
|
100
|
+
// Now modify the live editor
|
|
101
|
+
setEditorText(ctx.editor, "Modified after snapshot");
|
|
102
|
+
|
|
103
|
+
// Fork with the snapshot (which has "Current content", not "Modified after snapshot")
|
|
104
|
+
const snapshotUpdate = Y.encodeStateAsUpdate(snapshotDoc);
|
|
105
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
106
|
+
forkYDoc.fork({ initialUpdate: snapshotUpdate });
|
|
107
|
+
|
|
108
|
+
// The editor should show the snapshot content, not the current live content
|
|
109
|
+
expect(getEditorText(ctx.editor)).toBe("Current content");
|
|
110
|
+
|
|
111
|
+
// The original fragment should still have the modified content
|
|
112
|
+
expect(ctx.fragment.toJSON()).toContain("Modified after snapshot");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("fork({ initialUpdate }) + merge({ keepChanges: false }) restores live doc", () => {
|
|
116
|
+
ctx = createCollabEditor();
|
|
117
|
+
setEditorText(ctx.editor, "Live content");
|
|
118
|
+
|
|
119
|
+
// Create a snapshot update
|
|
120
|
+
const snapshotDoc = new Y.Doc();
|
|
121
|
+
Y.applyUpdate(snapshotDoc, Y.encodeStateAsUpdate(ctx.doc));
|
|
122
|
+
|
|
123
|
+
setEditorText(ctx.editor, "Updated live content");
|
|
124
|
+
|
|
125
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
126
|
+
forkYDoc.fork({ initialUpdate: Y.encodeStateAsUpdate(snapshotDoc) });
|
|
127
|
+
|
|
128
|
+
// Editor shows snapshot
|
|
129
|
+
expect(getEditorText(ctx.editor)).toBe("Live content");
|
|
130
|
+
|
|
131
|
+
// Merge without keeping changes
|
|
132
|
+
forkYDoc.merge({ keepChanges: false });
|
|
133
|
+
|
|
134
|
+
// Should be back to the live doc
|
|
135
|
+
expect(getEditorText(ctx.editor)).toBe("Updated live content");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("calling fork() while already forked is a no-op", () => {
|
|
139
|
+
ctx = createCollabEditor();
|
|
140
|
+
setEditorText(ctx.editor, "Original");
|
|
141
|
+
|
|
142
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
143
|
+
forkYDoc.fork();
|
|
144
|
+
setEditorText(ctx.editor, "Forked edit");
|
|
145
|
+
|
|
146
|
+
// Second fork should be a no-op
|
|
147
|
+
forkYDoc.fork();
|
|
148
|
+
expect(getEditorText(ctx.editor)).toBe("Forked edit");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("isForked store state reflects fork/merge lifecycle", () => {
|
|
152
|
+
ctx = createCollabEditor();
|
|
153
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
154
|
+
|
|
155
|
+
expect(forkYDoc.store.state.isForked).toBe(false);
|
|
156
|
+
|
|
157
|
+
forkYDoc.fork();
|
|
158
|
+
expect(forkYDoc.store.state.isForked).toBe(true);
|
|
159
|
+
|
|
160
|
+
forkYDoc.merge({ keepChanges: false });
|
|
161
|
+
expect(forkYDoc.store.state.isForked).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("merge() is a no-op when not forked", () => {
|
|
165
|
+
ctx = createCollabEditor();
|
|
166
|
+
setEditorText(ctx.editor, "Untouched");
|
|
167
|
+
|
|
168
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
169
|
+
|
|
170
|
+
// Should not throw or change anything.
|
|
171
|
+
forkYDoc.merge({ keepChanges: false });
|
|
172
|
+
forkYDoc.merge({ keepChanges: true });
|
|
173
|
+
|
|
174
|
+
expect(getEditorText(ctx.editor)).toBe("Untouched");
|
|
175
|
+
expect(forkYDoc.store.state.isForked).toBe(false);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("forked doc is isolated from the original Y.Doc", () => {
|
|
179
|
+
ctx = createCollabEditor();
|
|
180
|
+
setEditorText(ctx.editor, "Before fork");
|
|
181
|
+
|
|
182
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
183
|
+
forkYDoc.fork();
|
|
184
|
+
|
|
185
|
+
// Edit while forked
|
|
186
|
+
setEditorText(ctx.editor, "Forked edit");
|
|
187
|
+
|
|
188
|
+
// The original fragment should still have "Before fork"
|
|
189
|
+
expect(ctx.fragment.toJSON()).toContain("Before fork");
|
|
190
|
+
expect(ctx.fragment.toJSON()).not.toContain("Forked edit");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("fork({ initialUpdate }) + merge({ keepChanges: true }) applies forked edits to original", () => {
|
|
194
|
+
ctx = createCollabEditor();
|
|
195
|
+
setEditorText(ctx.editor, "Current content");
|
|
196
|
+
|
|
197
|
+
// Take a snapshot
|
|
198
|
+
const snapshotDoc = new Y.Doc();
|
|
199
|
+
Y.applyUpdate(snapshotDoc, Y.encodeStateAsUpdate(ctx.doc));
|
|
200
|
+
|
|
201
|
+
// Move the live doc forward
|
|
202
|
+
setEditorText(ctx.editor, "Live content");
|
|
203
|
+
|
|
204
|
+
// Fork from the snapshot
|
|
205
|
+
const forkYDoc = ctx.editor.getExtension(ForkYDocExtension)!;
|
|
206
|
+
forkYDoc.fork({ initialUpdate: Y.encodeStateAsUpdate(snapshotDoc) });
|
|
207
|
+
expect(getEditorText(ctx.editor)).toBe("Current content");
|
|
208
|
+
|
|
209
|
+
// Edit while forked
|
|
210
|
+
setEditorText(ctx.editor, "Forked modification");
|
|
211
|
+
|
|
212
|
+
// Merge and keep changes
|
|
213
|
+
forkYDoc.merge({ keepChanges: true });
|
|
214
|
+
expect(getEditorText(ctx.editor)).toContain("Forked modification");
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -5,43 +5,11 @@ import {
|
|
|
5
5
|
createStore,
|
|
6
6
|
ExtensionOptions,
|
|
7
7
|
} from "../../editor/BlockNoteExtension.js";
|
|
8
|
-
import { CollaborationOptions } from "./
|
|
8
|
+
import type { CollaborationOptions } from "./index.js";
|
|
9
9
|
import { YCursorExtension } from "./YCursorPlugin.js";
|
|
10
10
|
import { YSyncExtension } from "./YSync.js";
|
|
11
11
|
import { YUndoExtension } from "./YUndo.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* To find a fragment in another ydoc, we need to search for it.
|
|
15
|
-
*/
|
|
16
|
-
function findTypeInOtherYdoc<T extends Y.AbstractType<any>>(
|
|
17
|
-
ytype: T,
|
|
18
|
-
otherYdoc: Y.Doc,
|
|
19
|
-
): T {
|
|
20
|
-
const ydoc = ytype.doc!;
|
|
21
|
-
if (ytype._item === null) {
|
|
22
|
-
/**
|
|
23
|
-
* If is a root type, we need to find the root key in the original ydoc
|
|
24
|
-
* and use it to get the type in the other ydoc.
|
|
25
|
-
*/
|
|
26
|
-
const rootKey = Array.from(ydoc.share.keys()).find(
|
|
27
|
-
(key) => ydoc.share.get(key) === ytype,
|
|
28
|
-
);
|
|
29
|
-
if (rootKey == null) {
|
|
30
|
-
throw new Error("type does not exist in other ydoc");
|
|
31
|
-
}
|
|
32
|
-
return otherYdoc.get(rootKey, ytype.constructor as new () => T) as T;
|
|
33
|
-
} else {
|
|
34
|
-
/**
|
|
35
|
-
* If it is a sub type, we use the item id to find the history type.
|
|
36
|
-
*/
|
|
37
|
-
const ytypeItem = ytype._item;
|
|
38
|
-
const otherStructs = otherYdoc.store.clients.get(ytypeItem.id.client) ?? [];
|
|
39
|
-
const itemIndex = Y.findIndexSS(otherStructs, ytypeItem.id.clock);
|
|
40
|
-
const otherItem = otherStructs[itemIndex] as Y.Item;
|
|
41
|
-
const otherContent = otherItem.content as Y.ContentType;
|
|
42
|
-
return otherContent.type as T;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
12
|
+
import { findTypeInOtherYdoc } from "../utils.js";
|
|
45
13
|
|
|
46
14
|
export const ForkYDocExtension = createExtension(
|
|
47
15
|
({ editor, options }: ExtensionOptions<CollaborationOptions>) => {
|
|
@@ -63,7 +31,15 @@ export const ForkYDocExtension = createExtension(
|
|
|
63
31
|
* allowing modifications to the document without affecting the remote.
|
|
64
32
|
* These changes can later be rolled back or applied to the remote.
|
|
65
33
|
*/
|
|
66
|
-
fork(
|
|
34
|
+
fork({
|
|
35
|
+
/**
|
|
36
|
+
* The initial update to apply to the forked document.
|
|
37
|
+
* If not provided, the current document state is used.
|
|
38
|
+
*/
|
|
39
|
+
initialUpdate,
|
|
40
|
+
}: {
|
|
41
|
+
initialUpdate?: Uint8Array;
|
|
42
|
+
} = {}) {
|
|
67
43
|
if (forkedState) {
|
|
68
44
|
return;
|
|
69
45
|
}
|
|
@@ -75,8 +51,11 @@ export const ForkYDocExtension = createExtension(
|
|
|
75
51
|
}
|
|
76
52
|
|
|
77
53
|
const doc = new Y.Doc();
|
|
78
|
-
// Copy the original document to a new Yjs document
|
|
79
|
-
Y.applyUpdate(
|
|
54
|
+
// Copy the original document (or apply the provided update) to a new Yjs document
|
|
55
|
+
Y.applyUpdate(
|
|
56
|
+
doc,
|
|
57
|
+
initialUpdate ?? Y.encodeStateAsUpdate(originalFragment.doc!),
|
|
58
|
+
);
|
|
80
59
|
|
|
81
60
|
// Find the forked fragment in the new Yjs document
|
|
82
61
|
const forkedFragment = findTypeInOtherYdoc(originalFragment, doc);
|
|
@@ -88,22 +67,22 @@ export const ForkYDocExtension = createExtension(
|
|
|
88
67
|
forkedFragment,
|
|
89
68
|
};
|
|
90
69
|
|
|
91
|
-
// Need to reset all the yjs plugins
|
|
92
|
-
editor.unregisterExtension([
|
|
93
|
-
YUndoExtension,
|
|
94
|
-
YCursorExtension,
|
|
95
|
-
YSyncExtension,
|
|
96
|
-
]);
|
|
97
70
|
const newOptions = {
|
|
98
71
|
...options,
|
|
99
72
|
fragment: forkedFragment,
|
|
100
73
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
74
|
+
|
|
75
|
+
// Atomically swap the yjs plugins to avoid re-entrant dispatch issues
|
|
76
|
+
// where y-prosemirror's view hooks can dispatch a transaction between
|
|
77
|
+
// separate unregister/register calls, re-introducing stale plugins.
|
|
78
|
+
editor.replaceExtension(
|
|
79
|
+
["ySync", "yCursor", "yUndo"],
|
|
80
|
+
[
|
|
81
|
+
YSyncExtension(newOptions),
|
|
82
|
+
// No need to register the cursor plugin again, it's a local fork
|
|
83
|
+
YUndoExtension(),
|
|
84
|
+
],
|
|
85
|
+
);
|
|
107
86
|
|
|
108
87
|
// Tell the store that the editor is now forked
|
|
109
88
|
store.setState({ isForked: true });
|
|
@@ -118,16 +97,18 @@ export const ForkYDocExtension = createExtension(
|
|
|
118
97
|
if (!forkedState) {
|
|
119
98
|
return;
|
|
120
99
|
}
|
|
121
|
-
// Remove the forked fragment's plugins
|
|
122
|
-
editor.unregisterExtension(["ySync", "yCursor", "yUndo"]);
|
|
123
100
|
|
|
124
101
|
const { originalFragment, forkedFragment, undoStack } = forkedState;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
102
|
+
|
|
103
|
+
// Atomically swap the forked plugins back to the original ones
|
|
104
|
+
editor.replaceExtension(
|
|
105
|
+
["ySync", "yCursor", "yUndo"],
|
|
106
|
+
[
|
|
107
|
+
YSyncExtension(options),
|
|
108
|
+
YCursorExtension(options),
|
|
109
|
+
YUndoExtension(),
|
|
110
|
+
],
|
|
111
|
+
);
|
|
131
112
|
|
|
132
113
|
// Reset the undo stack to the original undo stack
|
|
133
114
|
yUndoPluginKey.getState(
|