@blocknote/core 0.51.3 → 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-D0lMxErU.js → blocks-CiuUGa1E.js} +1096 -998
- 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-D2mx2C9y.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-Dvmif2FY.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 +129 -0
- package/src/blocks/Table/TableExtension.ts +23 -20
- 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 +39 -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/ExtensionManager.test.d.ts +1 -0
- 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-D0lMxErU.js.map +0 -1
- package/dist/blocks-KyMOxPT3.cjs +0 -11
- package/dist/blocks-KyMOxPT3.cjs.map +0 -1
- package/dist/en-B9hMApn4.js.map +0 -1
- package/dist/en-Cj5r8sW_.cjs.map +0 -1
- package/dist/extensions-Cutrafjg.cjs +0 -52
- package/dist/extensions-Cutrafjg.cjs.map +0 -1
- package/dist/extensions-D2mx2C9y.js.map +0 -1
- package/dist/src-D5R5YzV7.cjs +0 -21
- package/dist/src-D5R5YzV7.cjs.map +0 -1
- package/dist/src-Dvmif2FY.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 → blocks/Table/TableExtension.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,469 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
afterEach,
|
|
6
|
+
beforeEach,
|
|
7
|
+
describe,
|
|
8
|
+
expect,
|
|
9
|
+
it,
|
|
10
|
+
vi,
|
|
11
|
+
} from "vite-plus/test";
|
|
12
|
+
|
|
13
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
14
|
+
import { DiffVersioningExtension } from "../../y/extensions/DiffVersioningExtension.js";
|
|
15
|
+
import { CURRENT_VERSION_ID, VersioningExtension } from "./Versioning.js";
|
|
16
|
+
import {
|
|
17
|
+
createInMemoryPreviewController,
|
|
18
|
+
createInMemoryVersioningAdapter,
|
|
19
|
+
createInMemoryVersioningEndpoints,
|
|
20
|
+
} from "./inMemoryVersioning.js";
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Helpers
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
function createEditor() {
|
|
27
|
+
const editor = BlockNoteEditor.create();
|
|
28
|
+
const div = document.createElement("div");
|
|
29
|
+
editor.mount(div);
|
|
30
|
+
return editor;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getEditorText(editor: BlockNoteEditor<any, any, any>): string {
|
|
34
|
+
return editor.prosemirrorState.doc.textContent;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function setEditorText(editor: BlockNoteEditor<any, any, any>, text: string) {
|
|
38
|
+
editor.replaceBlocks(editor.document, [{ type: "paragraph", content: text }]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// Tests — createInMemoryVersioningEndpoints
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
describe("createInMemoryVersioningEndpoints", () => {
|
|
46
|
+
it("creates and retrieves snapshots", async () => {
|
|
47
|
+
const endpoints = createInMemoryVersioningEndpoints();
|
|
48
|
+
const blocks = [
|
|
49
|
+
{
|
|
50
|
+
id: "1",
|
|
51
|
+
type: "paragraph" as const,
|
|
52
|
+
content: [] as any,
|
|
53
|
+
props: {} as any,
|
|
54
|
+
children: [],
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const snap = await endpoints.create!(blocks, { name: "v1" });
|
|
59
|
+
expect(snap.name).toBe("v1");
|
|
60
|
+
expect(snap.id).toBeDefined();
|
|
61
|
+
|
|
62
|
+
const content = await endpoints.getContent(snap);
|
|
63
|
+
expect(content).toEqual(blocks);
|
|
64
|
+
// Content is a deep clone, not a reference
|
|
65
|
+
expect(content).not.toBe(blocks);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("lists snapshots newest-first", async () => {
|
|
69
|
+
vi.useFakeTimers();
|
|
70
|
+
try {
|
|
71
|
+
const endpoints = createInMemoryVersioningEndpoints();
|
|
72
|
+
|
|
73
|
+
const s1 = await endpoints.create!([
|
|
74
|
+
{
|
|
75
|
+
id: "1",
|
|
76
|
+
type: "paragraph" as const,
|
|
77
|
+
content: "v1" as any,
|
|
78
|
+
props: {} as any,
|
|
79
|
+
children: [],
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
vi.advanceTimersByTime(1000);
|
|
83
|
+
const s2 = await endpoints.create!([
|
|
84
|
+
{
|
|
85
|
+
id: "2",
|
|
86
|
+
type: "paragraph" as const,
|
|
87
|
+
content: "v2" as any,
|
|
88
|
+
props: {} as any,
|
|
89
|
+
children: [],
|
|
90
|
+
},
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
const list = await endpoints.list();
|
|
94
|
+
expect(list[0].id).toBe(s2.id);
|
|
95
|
+
expect(list[1].id).toBe(s1.id);
|
|
96
|
+
} finally {
|
|
97
|
+
vi.useRealTimers();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("restore creates a backup and returns snapshot content", async () => {
|
|
102
|
+
const endpoints = createInMemoryVersioningEndpoints();
|
|
103
|
+
|
|
104
|
+
const original = [
|
|
105
|
+
{
|
|
106
|
+
id: "1",
|
|
107
|
+
type: "paragraph" as const,
|
|
108
|
+
content: "original" as any,
|
|
109
|
+
props: {} as any,
|
|
110
|
+
children: [],
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
const snap = await endpoints.create!(original);
|
|
114
|
+
|
|
115
|
+
const currentDoc = [
|
|
116
|
+
{
|
|
117
|
+
id: "2",
|
|
118
|
+
type: "paragraph" as const,
|
|
119
|
+
content: "modified" as any,
|
|
120
|
+
props: {} as any,
|
|
121
|
+
children: [],
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
const restored = await endpoints.restore!(currentDoc, snap);
|
|
125
|
+
|
|
126
|
+
expect(restored).toEqual(original);
|
|
127
|
+
|
|
128
|
+
// A backup snapshot was created
|
|
129
|
+
const list = await endpoints.list();
|
|
130
|
+
expect(list.length).toBe(2);
|
|
131
|
+
const backup = list.find((s) => s.restoredFromSnapshotId === snap.id);
|
|
132
|
+
expect(backup).toBeDefined();
|
|
133
|
+
|
|
134
|
+
// The backup contains the current (pre-restore) doc
|
|
135
|
+
const backupContent = await endpoints.getContent(backup!);
|
|
136
|
+
expect(backupContent).toEqual(currentDoc);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("updates snapshot name", async () => {
|
|
140
|
+
const endpoints = createInMemoryVersioningEndpoints();
|
|
141
|
+
const snap = await endpoints.create!(
|
|
142
|
+
[
|
|
143
|
+
{
|
|
144
|
+
id: "1",
|
|
145
|
+
type: "paragraph" as const,
|
|
146
|
+
content: "v1" as any,
|
|
147
|
+
props: {} as any,
|
|
148
|
+
children: [],
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
{ name: "old" },
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
await endpoints.rename!(snap, "new");
|
|
155
|
+
|
|
156
|
+
const list = await endpoints.list();
|
|
157
|
+
expect(list.find((s) => s.id === snap.id)!.name).toBe("new");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("deletes a snapshot and its content", async () => {
|
|
161
|
+
const endpoints = createInMemoryVersioningEndpoints();
|
|
162
|
+
const snap = await endpoints.create!([
|
|
163
|
+
{
|
|
164
|
+
id: "1",
|
|
165
|
+
type: "paragraph" as const,
|
|
166
|
+
content: "v1" as any,
|
|
167
|
+
props: {} as any,
|
|
168
|
+
children: [],
|
|
169
|
+
},
|
|
170
|
+
]);
|
|
171
|
+
|
|
172
|
+
await endpoints.remove!(snap);
|
|
173
|
+
|
|
174
|
+
// No longer listed
|
|
175
|
+
expect(await endpoints.list()).toHaveLength(0);
|
|
176
|
+
// Its content is gone too
|
|
177
|
+
await expect(endpoints.getContent(snap)).rejects.toThrow(/not found/i);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("throws for unknown snapshot ID", async () => {
|
|
181
|
+
const endpoints = createInMemoryVersioningEndpoints();
|
|
182
|
+
const missing = { id: "nope", createdAt: 0, updatedAt: 0 };
|
|
183
|
+
await expect(endpoints.getContent(missing)).rejects.toThrow(/not found/i);
|
|
184
|
+
await expect(endpoints.restore!([], missing)).rejects.toThrow(/not found/i);
|
|
185
|
+
await expect(endpoints.rename!(missing, "x")).rejects.toThrow(/not found/i);
|
|
186
|
+
await expect(endpoints.remove!(missing)).rejects.toThrow(/not found/i);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
// Tests — createInMemoryPreviewController
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
|
|
194
|
+
describe("createInMemoryPreviewController", () => {
|
|
195
|
+
let editor: BlockNoteEditor<any, any, any>;
|
|
196
|
+
|
|
197
|
+
beforeEach(() => {
|
|
198
|
+
editor = createEditor();
|
|
199
|
+
setEditorText(editor, "live content");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
afterEach(() => {
|
|
203
|
+
editor.unmount();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("enterPreview replaces doc and exitPreview restores it", () => {
|
|
207
|
+
const preview = createInMemoryPreviewController(editor);
|
|
208
|
+
|
|
209
|
+
// Grab the snapshot content we want to preview — a doc with different text.
|
|
210
|
+
const previewEditor = createEditor();
|
|
211
|
+
setEditorText(previewEditor, "snapshot content");
|
|
212
|
+
const snapshotBlocks = previewEditor.document;
|
|
213
|
+
previewEditor.unmount();
|
|
214
|
+
|
|
215
|
+
preview.enterPreview(snapshotBlocks);
|
|
216
|
+
expect(getEditorText(editor)).toBe("snapshot content");
|
|
217
|
+
|
|
218
|
+
preview.exitPreview();
|
|
219
|
+
expect(getEditorText(editor)).toBe("live content");
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("successive enterPreview calls preserve original doc", () => {
|
|
223
|
+
const preview = createInMemoryPreviewController(editor);
|
|
224
|
+
|
|
225
|
+
const mkSnap = (text: string) => {
|
|
226
|
+
const e = createEditor();
|
|
227
|
+
setEditorText(e, text);
|
|
228
|
+
const blocks = e.document;
|
|
229
|
+
e.unmount();
|
|
230
|
+
return blocks;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
preview.enterPreview(mkSnap("snap A"));
|
|
234
|
+
expect(getEditorText(editor)).toBe("snap A");
|
|
235
|
+
|
|
236
|
+
preview.enterPreview(mkSnap("snap B"));
|
|
237
|
+
expect(getEditorText(editor)).toBe("snap B");
|
|
238
|
+
|
|
239
|
+
// Exit restores the original live doc, not snap A.
|
|
240
|
+
preview.exitPreview();
|
|
241
|
+
expect(getEditorText(editor)).toBe("live content");
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("applyRestore replaces doc and clears saved state", () => {
|
|
245
|
+
const preview = createInMemoryPreviewController(editor);
|
|
246
|
+
|
|
247
|
+
const mkSnap = (text: string) => {
|
|
248
|
+
const e = createEditor();
|
|
249
|
+
setEditorText(e, text);
|
|
250
|
+
const blocks = e.document;
|
|
251
|
+
e.unmount();
|
|
252
|
+
return blocks;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// Enter preview first
|
|
256
|
+
preview.enterPreview(mkSnap("previewed"));
|
|
257
|
+
expect(getEditorText(editor)).toBe("previewed");
|
|
258
|
+
|
|
259
|
+
// Now restore — this is the "apply" step after endpoints.restore returns
|
|
260
|
+
preview.applyRestore(mkSnap("restored"));
|
|
261
|
+
expect(getEditorText(editor)).toBe("restored");
|
|
262
|
+
|
|
263
|
+
// exitPreview should be a no-op since savedDoc was cleared
|
|
264
|
+
preview.exitPreview();
|
|
265
|
+
expect(getEditorText(editor)).toBe("restored");
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// ---------------------------------------------------------------------------
|
|
270
|
+
// Tests — Full integration with VersioningExtension
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
|
|
273
|
+
describe("VersioningExtension + in-memory adapter", () => {
|
|
274
|
+
let editor: BlockNoteEditor<any, any, any>;
|
|
275
|
+
|
|
276
|
+
beforeEach(() => {
|
|
277
|
+
editor = createEditor();
|
|
278
|
+
setEditorText(editor, "initial doc");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
afterEach(() => {
|
|
282
|
+
editor.unmount();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("create, preview, exit, restore full workflow", async () => {
|
|
286
|
+
const adapter = createInMemoryVersioningAdapter(editor);
|
|
287
|
+
const ext = VersioningExtension(adapter)({ editor });
|
|
288
|
+
|
|
289
|
+
// 1. Create a snapshot of "initial doc"
|
|
290
|
+
const snap1 = await ext.create!({ name: "v1" });
|
|
291
|
+
expect(snap1.name).toBe("v1");
|
|
292
|
+
|
|
293
|
+
// 2. Modify the document
|
|
294
|
+
setEditorText(editor, "modified doc");
|
|
295
|
+
|
|
296
|
+
// 3. Create another snapshot
|
|
297
|
+
await ext.create!({ name: "v2" });
|
|
298
|
+
|
|
299
|
+
// 4. List — both present (the adapter also surfaces a "current version"
|
|
300
|
+
// entry, which isn't a stored snapshot).
|
|
301
|
+
const list = (await ext.list()).filter((s) => s.id !== CURRENT_VERSION_ID);
|
|
302
|
+
expect(list).toHaveLength(2);
|
|
303
|
+
expect(list.map((s) => s.name)).toContain("v1");
|
|
304
|
+
expect(list.map((s) => s.name)).toContain("v2");
|
|
305
|
+
|
|
306
|
+
// 5. Preview the first snapshot
|
|
307
|
+
await ext.previewSnapshot(snap1.id);
|
|
308
|
+
expect(getEditorText(editor)).toBe("initial doc");
|
|
309
|
+
expect(ext.store.state.previewedSnapshotId).toBe(snap1.id);
|
|
310
|
+
|
|
311
|
+
// 6. Exit preview — back to modified doc
|
|
312
|
+
ext.exitPreview();
|
|
313
|
+
expect(getEditorText(editor)).toBe("modified doc");
|
|
314
|
+
expect(ext.store.state.previewedSnapshotId).toBeUndefined();
|
|
315
|
+
|
|
316
|
+
// 7. Restore the first snapshot
|
|
317
|
+
const restored = await ext.restore!(snap1.id);
|
|
318
|
+
expect(restored).toBeDefined();
|
|
319
|
+
expect(getEditorText(editor)).toBe("initial doc");
|
|
320
|
+
|
|
321
|
+
// 8. A backup snapshot was created by the endpoints (plus the adapter's
|
|
322
|
+
// "current version" entry, which isn't a stored snapshot).
|
|
323
|
+
const afterRestore = (await ext.list()).filter(
|
|
324
|
+
(s) => s.id !== CURRENT_VERSION_ID,
|
|
325
|
+
);
|
|
326
|
+
expect(afterRestore.length).toBe(3);
|
|
327
|
+
const backup = afterRestore.find(
|
|
328
|
+
(s) => s.restoredFromSnapshotId === snap1.id,
|
|
329
|
+
);
|
|
330
|
+
expect(backup).toBeDefined();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it("preview with compareTo fetches both contents", async () => {
|
|
334
|
+
const adapter = createInMemoryVersioningAdapter(editor);
|
|
335
|
+
const ext = VersioningExtension(adapter)({ editor });
|
|
336
|
+
|
|
337
|
+
const snap1 = await ext.create!({ name: "baseline" });
|
|
338
|
+
setEditorText(editor, "changed doc");
|
|
339
|
+
const snap2 = await ext.create!({ name: "current" });
|
|
340
|
+
|
|
341
|
+
// Preview snap2 compared to snap1. Without the (opt-in) DiffVersioningExtension
|
|
342
|
+
// registered, the in-memory preview controller falls back to a static swap:
|
|
343
|
+
// it shows the snapshot content and renders no diff marks.
|
|
344
|
+
await ext.previewSnapshot(snap2.id, { compareTo: snap1.id });
|
|
345
|
+
expect(getEditorText(editor)).toBe("changed doc");
|
|
346
|
+
|
|
347
|
+
ext.exitPreview();
|
|
348
|
+
expect(getEditorText(editor)).toBe("changed doc");
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("delete removes the snapshot from the store and backend", async () => {
|
|
352
|
+
const adapter = createInMemoryVersioningAdapter(editor);
|
|
353
|
+
const ext = VersioningExtension(adapter)({ editor });
|
|
354
|
+
|
|
355
|
+
const snap1 = await ext.create!({ name: "keep" });
|
|
356
|
+
setEditorText(editor, "changed doc");
|
|
357
|
+
const snap2 = await ext.create!({ name: "remove" });
|
|
358
|
+
await ext.list();
|
|
359
|
+
|
|
360
|
+
expect(ext.canRemove).toBe(true);
|
|
361
|
+
await ext.remove!(snap2.id);
|
|
362
|
+
|
|
363
|
+
// Gone from the optimistic store...
|
|
364
|
+
expect(
|
|
365
|
+
ext.store.state.snapshots.find((s) => s.id === snap2.id),
|
|
366
|
+
).toBeUndefined();
|
|
367
|
+
// ...and gone from the backend's authoritative list.
|
|
368
|
+
const list = (await ext.list()).filter((s) => s.id !== CURRENT_VERSION_ID);
|
|
369
|
+
expect(list.map((s) => s.id)).toEqual([snap1.id]);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("deleting the previewed snapshot exits preview", async () => {
|
|
373
|
+
const adapter = createInMemoryVersioningAdapter(editor);
|
|
374
|
+
const ext = VersioningExtension(adapter)({ editor });
|
|
375
|
+
|
|
376
|
+
const snap = await ext.create!({ name: "v1" });
|
|
377
|
+
setEditorText(editor, "modified doc");
|
|
378
|
+
|
|
379
|
+
// Preview the snapshot, then delete the version being previewed.
|
|
380
|
+
await ext.previewSnapshot(snap.id);
|
|
381
|
+
expect(ext.store.state.previewedSnapshotId).toBe(snap.id);
|
|
382
|
+
|
|
383
|
+
await ext.remove!(snap.id);
|
|
384
|
+
|
|
385
|
+
// Preview was exited and the live document restored.
|
|
386
|
+
expect(ext.store.state.previewedSnapshotId).toBeUndefined();
|
|
387
|
+
expect(getEditorText(editor)).toBe("modified doc");
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it("rename persists through list refresh", async () => {
|
|
391
|
+
const adapter = createInMemoryVersioningAdapter(editor);
|
|
392
|
+
const ext = VersioningExtension(adapter)({ editor });
|
|
393
|
+
|
|
394
|
+
const snap = await ext.create!({ name: "draft" });
|
|
395
|
+
await ext.rename!(snap.id, "final");
|
|
396
|
+
|
|
397
|
+
// Store was updated optimistically
|
|
398
|
+
expect(ext.store.state.snapshots.find((s) => s.id === snap.id)!.name).toBe(
|
|
399
|
+
"final",
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
// Backend also updated (verified via list which calls endpoints.list)
|
|
403
|
+
const list = await ext.list();
|
|
404
|
+
expect(list.find((s) => s.id === snap.id)!.name).toBe("final");
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
// ---------------------------------------------------------------------------
|
|
409
|
+
// Tests — diff delegation to the opt-in DiffVersioningExtension
|
|
410
|
+
// ---------------------------------------------------------------------------
|
|
411
|
+
|
|
412
|
+
describe("in-memory versioning + DiffVersioningExtension", () => {
|
|
413
|
+
let editor: BlockNoteEditor<any, any, any>;
|
|
414
|
+
|
|
415
|
+
beforeEach(() => {
|
|
416
|
+
editor = BlockNoteEditor.create({
|
|
417
|
+
extensions: [DiffVersioningExtension()],
|
|
418
|
+
});
|
|
419
|
+
editor.mount(document.createElement("div"));
|
|
420
|
+
setEditorText(editor, "initial doc");
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
afterEach(() => {
|
|
424
|
+
editor.unmount();
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
const attributionMarkCount = () => {
|
|
428
|
+
let count = 0;
|
|
429
|
+
editor.prosemirrorState.doc.descendants((node) => {
|
|
430
|
+
count += node.marks.filter((m) =>
|
|
431
|
+
m.type.name.startsWith("y-attributed-"),
|
|
432
|
+
).length;
|
|
433
|
+
return true;
|
|
434
|
+
});
|
|
435
|
+
return count;
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
it("previewing with compareTo renders an attributed diff", async () => {
|
|
439
|
+
const adapter = createInMemoryVersioningAdapter(editor);
|
|
440
|
+
const ext = VersioningExtension(adapter)({ editor });
|
|
441
|
+
|
|
442
|
+
const snap1 = await ext.create!({ name: "baseline" });
|
|
443
|
+
setEditorText(editor, "changed doc");
|
|
444
|
+
const snap2 = await ext.create!({ name: "current" });
|
|
445
|
+
|
|
446
|
+
await ext.previewSnapshot(snap2.id, { compareTo: snap1.id });
|
|
447
|
+
|
|
448
|
+
// The diff extension rendered attribution marks (initial vs changed doc).
|
|
449
|
+
expect(attributionMarkCount()).toBeGreaterThan(0);
|
|
450
|
+
|
|
451
|
+
// Exiting the preview clears the marks and restores the live document.
|
|
452
|
+
ext.exitPreview();
|
|
453
|
+
expect(attributionMarkCount()).toBe(0);
|
|
454
|
+
expect(getEditorText(editor)).toBe("changed doc");
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it("previewing without compareTo shows content with no diff marks", async () => {
|
|
458
|
+
const adapter = createInMemoryVersioningAdapter(editor);
|
|
459
|
+
const ext = VersioningExtension(adapter)({ editor });
|
|
460
|
+
|
|
461
|
+
const snap1 = await ext.create!({ name: "baseline" });
|
|
462
|
+
setEditorText(editor, "changed doc");
|
|
463
|
+
|
|
464
|
+
await ext.previewSnapshot(snap1.id);
|
|
465
|
+
|
|
466
|
+
expect(getEditorText(editor)).toBe("initial doc");
|
|
467
|
+
expect(attributionMarkCount()).toBe(0);
|
|
468
|
+
});
|
|
469
|
+
});
|