@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,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { describe, expect, expectTypeOf, it, vi } from "vite-plus/test";
|
|
5
|
+
|
|
6
|
+
import { createUserStore, User } from "./index.js";
|
|
7
|
+
|
|
8
|
+
function setup(resolveUsers: (userIds: string[]) => Promise<User[]>) {
|
|
9
|
+
return createUserStore(resolveUsers);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function makeUser(id: string): User {
|
|
13
|
+
return {
|
|
14
|
+
id,
|
|
15
|
+
username: `user-${id}`,
|
|
16
|
+
avatarUrl: `https://example.com/${id}.png`,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("createUserStore", () => {
|
|
21
|
+
it("loads users into the store and exposes them via getUser", async () => {
|
|
22
|
+
const resolveUsers = vi.fn(async (ids: string[]) => ids.map(makeUser));
|
|
23
|
+
const userStore = setup(resolveUsers);
|
|
24
|
+
|
|
25
|
+
await userStore.loadUsers(["1", "2"]);
|
|
26
|
+
|
|
27
|
+
expect(resolveUsers).toHaveBeenCalledTimes(1);
|
|
28
|
+
// The store itself is passed as the second argument, so resolvers can
|
|
29
|
+
// return synchronously and fill in more info via `setUser` later.
|
|
30
|
+
expect(resolveUsers).toHaveBeenCalledWith(["1", "2"], userStore);
|
|
31
|
+
expect(userStore.getUser("1")).toEqual(makeUser("1"));
|
|
32
|
+
expect(userStore.getUser("2")).toEqual(makeUser("2"));
|
|
33
|
+
expect(userStore.store.state.size).toBe(2);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("does not re-fetch users that are already cached", async () => {
|
|
37
|
+
const resolveUsers = vi.fn(async (ids: string[]) => ids.map(makeUser));
|
|
38
|
+
const userStore = setup(resolveUsers);
|
|
39
|
+
|
|
40
|
+
await userStore.loadUsers(["1", "2"]);
|
|
41
|
+
await userStore.loadUsers(["2", "3"]);
|
|
42
|
+
|
|
43
|
+
// Only the missing "3" should be requested the second time.
|
|
44
|
+
expect(resolveUsers).toHaveBeenCalledTimes(2);
|
|
45
|
+
expect(resolveUsers).toHaveBeenNthCalledWith(2, ["3"], userStore);
|
|
46
|
+
|
|
47
|
+
await userStore.loadUsers(["1", "2", "3"]);
|
|
48
|
+
// Everything cached now → no further requests.
|
|
49
|
+
expect(resolveUsers).toHaveBeenCalledTimes(2);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("de-duplicates concurrent in-flight requests for the same user", async () => {
|
|
53
|
+
const resolveUsers = vi.fn(
|
|
54
|
+
(ids: string[]) =>
|
|
55
|
+
new Promise<User[]>((resolve) =>
|
|
56
|
+
setTimeout(() => resolve(ids.map(makeUser)), 10),
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
const userStore = setup(resolveUsers);
|
|
60
|
+
|
|
61
|
+
await Promise.all([userStore.loadUsers(["1"]), userStore.loadUsers(["1"])]);
|
|
62
|
+
|
|
63
|
+
expect(resolveUsers).toHaveBeenCalledTimes(1);
|
|
64
|
+
expect(userStore.getUser("1")).toEqual(makeUser("1"));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("refetchUsers ignores the cache and re-resolves", async () => {
|
|
68
|
+
let counter = 0;
|
|
69
|
+
const resolveUsers = vi.fn(async (ids: string[]) =>
|
|
70
|
+
ids.map((id) => ({
|
|
71
|
+
...makeUser(id),
|
|
72
|
+
username: `user-${id}-${counter++}`,
|
|
73
|
+
})),
|
|
74
|
+
);
|
|
75
|
+
const userStore = setup(resolveUsers);
|
|
76
|
+
|
|
77
|
+
await userStore.loadUsers(["1"]);
|
|
78
|
+
expect(userStore.getUser("1")?.username).toBe("user-1-0");
|
|
79
|
+
|
|
80
|
+
await userStore.refetchUsers(["1"]);
|
|
81
|
+
expect(resolveUsers).toHaveBeenCalledTimes(2);
|
|
82
|
+
expect(userStore.getUser("1")?.username).toBe("user-1-1");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Regression test for https://github.com/TypeCellOS/BlockNote/issues/1548
|
|
86
|
+
it("does not emit a store update when a user cannot be resolved", async () => {
|
|
87
|
+
// Resolver that never returns the requested user (can't find it).
|
|
88
|
+
const resolveUsers = vi.fn(async () => [] as User[]);
|
|
89
|
+
const userStore = setup(resolveUsers);
|
|
90
|
+
|
|
91
|
+
const onUpdate = vi.fn();
|
|
92
|
+
const unsubscribe = userStore.store.subscribe(onUpdate);
|
|
93
|
+
|
|
94
|
+
await userStore.loadUsers(["missing"]);
|
|
95
|
+
|
|
96
|
+
// Nothing was resolved, so no update should be emitted (which previously
|
|
97
|
+
// could feed an infinite load loop in subscribers).
|
|
98
|
+
expect(onUpdate).not.toHaveBeenCalled();
|
|
99
|
+
expect(userStore.getUser("missing")).toBeUndefined();
|
|
100
|
+
|
|
101
|
+
unsubscribe();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("infers a custom user type from resolveUsers' return type", async () => {
|
|
105
|
+
type CustomUser = User & { role: "admin" | "member" };
|
|
106
|
+
|
|
107
|
+
const resolveUsers = async (ids: string[]): Promise<CustomUser[]> =>
|
|
108
|
+
ids.map((id) => ({ ...makeUser(id), role: "admin" as const }));
|
|
109
|
+
|
|
110
|
+
const userStore = createUserStore(resolveUsers);
|
|
111
|
+
|
|
112
|
+
await userStore.loadUsers(["1"]);
|
|
113
|
+
|
|
114
|
+
const user = userStore.getUser("1");
|
|
115
|
+
// Type-level: the custom property flows through.
|
|
116
|
+
expectTypeOf(userStore.getUser).returns.toEqualTypeOf<
|
|
117
|
+
CustomUser | undefined
|
|
118
|
+
>();
|
|
119
|
+
expectTypeOf(userStore.store.state).toEqualTypeOf<
|
|
120
|
+
Map<string, CustomUser>
|
|
121
|
+
>();
|
|
122
|
+
|
|
123
|
+
// Runtime: the resolved user carries the extra field.
|
|
124
|
+
expect(user?.role).toBe("admin");
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { digestString } from "lib0/hash/fnv1a";
|
|
2
|
+
import type { UserStore } from "./UserStore.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Deterministic hash of a string to an unsigned 32-bit integer.
|
|
6
|
+
*/
|
|
7
|
+
const hashStr = (s: string): number => {
|
|
8
|
+
let hash = 0;
|
|
9
|
+
for (let i = 0; i < s.length; i++) {
|
|
10
|
+
hash = Math.imul(31, hash) + s.charCodeAt(i);
|
|
11
|
+
}
|
|
12
|
+
return Math.abs(hash);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Fallback palette used when a user has no resolved color of their own. */
|
|
16
|
+
export const userColorPalette: Array<{ light: string; dark: string }> = [
|
|
17
|
+
{ light: "#fff0c2", dark: "#8a6d1a" },
|
|
18
|
+
{ light: "#fcc9c3", dark: "#8a2e24" },
|
|
19
|
+
{ light: "#d4e8eb", dark: "#4a7178" },
|
|
20
|
+
{ light: "#c2eeff", dark: "#1a6e8a" },
|
|
21
|
+
{ light: "#bef3ff", dark: "#0a7a8a" },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/** The deterministic {@link userColorPalette} entry for a single user id. */
|
|
25
|
+
export const fallbackColorForUserId = (
|
|
26
|
+
id: string,
|
|
27
|
+
): { light: string; dark: string } =>
|
|
28
|
+
userColorPalette[hashStr(id) % userColorPalette.length];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The (first) user's resolved color from the {@link UserStore}, or their
|
|
32
|
+
* {@link fallbackColorForUserId} palette entry. Used where a concrete color
|
|
33
|
+
* string is needed (the portaled hover tooltip); marks themselves use the
|
|
34
|
+
* cascaded {@link userColorVarNames} properties instead.
|
|
35
|
+
*/
|
|
36
|
+
export const colorsForUserIds = (
|
|
37
|
+
userStore: UserStore,
|
|
38
|
+
userIds: readonly string[] | undefined | null,
|
|
39
|
+
): { light: string; dark: string } => {
|
|
40
|
+
if (!userIds || userIds.length === 0) {
|
|
41
|
+
return userColorPalette[0];
|
|
42
|
+
}
|
|
43
|
+
const firstId = userIds[0];
|
|
44
|
+
const user = userStore.getUser(firstId);
|
|
45
|
+
if (user?.color && user.colorLight) {
|
|
46
|
+
return { light: user.colorLight, dark: user.color };
|
|
47
|
+
}
|
|
48
|
+
return fallbackColorForUserId(firstId);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Reduce a user id to a fixed-width `[0-9a-f]` token safe to embed in a CSS
|
|
53
|
+
* custom-property name. Uses the (non-cryptographic) FNV-1a 32-bit hash; a
|
|
54
|
+
* collision only means two authors share a highlight color.
|
|
55
|
+
*/
|
|
56
|
+
export const cssVarUserId = (id: string): string =>
|
|
57
|
+
digestString(id).toString(16).padStart(8, "0");
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The `--user-color-<key>-{light,dark}` custom-property names for a user. Set on
|
|
61
|
+
* the editor root by `AttributionExtension`, read by the mark wrapper via
|
|
62
|
+
* `var(..., <fallback>)`.
|
|
63
|
+
*/
|
|
64
|
+
export const userColorVarNames = (
|
|
65
|
+
id: string,
|
|
66
|
+
): { light: string; dark: string } => {
|
|
67
|
+
const key = cssVarUserId(id);
|
|
68
|
+
return {
|
|
69
|
+
light: `--user-color-${key}-light`,
|
|
70
|
+
dark: `--user-color-${key}-dark`,
|
|
71
|
+
};
|
|
72
|
+
};
|
package/src/util/string.ts
CHANGED
package/src/util/typescript.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export class UnreachableCaseError extends Error {
|
|
2
2
|
constructor(val: never) {
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
3
4
|
super(`Unreachable case: ${val}`);
|
|
4
5
|
}
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export function assertEmpty(obj: Record<string, never>, throwError = true) {
|
|
8
|
-
const { "data-test":
|
|
9
|
+
const { "data-test": _dataTest, ...rest } = obj; // exclude data-test
|
|
9
10
|
|
|
10
11
|
if (Object.keys(rest).length > 0 && throwError) {
|
|
11
12
|
throw new Error("Object must be empty " + JSON.stringify(obj));
|
package/src/vite-env.d.ts
CHANGED
package/src/y/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# @blocknote/core/y
|
|
2
|
+
|
|
3
|
+
This package contains integrations for Yjs (v14) with BlockNote (based on `@y/y` & `@y/prosemirror`). Given that we are going to support both Yjs v13 & v14, we need to have a way to support both versions independently.
|
|
4
|
+
|
|
5
|
+
If you want to use Yjs v13, you can use the `@blocknote/core/yjs` package instead which will use the `yjs` & `y-prosemirror` packages.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as Y from "
|
|
2
|
-
import { CommentBody } from "../../types.js";
|
|
3
|
-
import { ThreadStoreAuth } from "
|
|
1
|
+
import * as Y from "@y/y";
|
|
2
|
+
import type { CommentBody } from "../../comments/types.js";
|
|
3
|
+
import type { ThreadStoreAuth } from "../../comments/threadstore/ThreadStoreAuth.js";
|
|
4
4
|
import { YjsThreadStoreBase } from "./YjsThreadStoreBase.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* This is a REST-based implementation of the YjsThreadStoreBase.
|
|
7
|
+
* This is a REST-based implementation of the YjsThreadStoreBase for @y/y (v14).
|
|
8
8
|
* It Reads data directly from the underlying document (same as YjsThreadStore),
|
|
9
9
|
* but for Writes, it sends data to a REST API that should:
|
|
10
10
|
* - check the user has the correct permissions to make the desired changes
|
|
@@ -21,10 +21,10 @@ export class RESTYjsThreadStore extends YjsThreadStoreBase {
|
|
|
21
21
|
constructor(
|
|
22
22
|
private readonly BASE_URL: string,
|
|
23
23
|
private readonly headers: Record<string, string>,
|
|
24
|
-
|
|
24
|
+
threadsYType: Y.Type,
|
|
25
25
|
auth: ThreadStoreAuth,
|
|
26
26
|
) {
|
|
27
|
-
super(
|
|
27
|
+
super(threadsYType, auth);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
private doRequest = async (path: string, method: string, body?: any) => {
|
|
@@ -47,14 +47,8 @@ export class RESTYjsThreadStore extends YjsThreadStoreBase {
|
|
|
47
47
|
public addThreadToDocument = async (options: {
|
|
48
48
|
threadId: string;
|
|
49
49
|
selection: {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
anchor: number;
|
|
53
|
-
};
|
|
54
|
-
yjs: {
|
|
55
|
-
head: any;
|
|
56
|
-
anchor: any;
|
|
57
|
-
};
|
|
50
|
+
head: number;
|
|
51
|
+
anchor: number;
|
|
58
52
|
};
|
|
59
53
|
}) => {
|
|
60
54
|
const { threadId, ...rest } = options;
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
|
|
2
|
+
import * as Y from "@y/y";
|
|
3
|
+
import type { CommentBody } from "../../comments/types.js";
|
|
4
|
+
import { DefaultThreadStoreAuth } from "../../comments/threadstore/DefaultThreadStoreAuth.js";
|
|
5
|
+
import { YjsThreadStore } from "./YjsThreadStore.js";
|
|
6
|
+
|
|
7
|
+
// Mock UUID to generate sequential IDs
|
|
8
|
+
let mockUuidCounter = 0;
|
|
9
|
+
vi.mock("lib0/random", async (importOriginal) => ({
|
|
10
|
+
...(await importOriginal<typeof import("lib0/random")>()),
|
|
11
|
+
uuidv4: () => `mocked-uuid-${++mockUuidCounter}`,
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
describe("YjsThreadStore (@y/y v14)", () => {
|
|
15
|
+
let store: YjsThreadStore;
|
|
16
|
+
let doc: Y.Doc;
|
|
17
|
+
let threadsYType: Y.Type;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
// Reset mocks and create fresh instances
|
|
21
|
+
vi.clearAllMocks();
|
|
22
|
+
mockUuidCounter = 0;
|
|
23
|
+
doc = new Y.Doc();
|
|
24
|
+
threadsYType = doc.get("threads");
|
|
25
|
+
|
|
26
|
+
store = new YjsThreadStore(
|
|
27
|
+
"test-user",
|
|
28
|
+
threadsYType,
|
|
29
|
+
new DefaultThreadStoreAuth("test-user", "editor"),
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("createThread", () => {
|
|
34
|
+
it("creates a thread with initial comment", async () => {
|
|
35
|
+
const initialComment = {
|
|
36
|
+
body: "Test comment" as CommentBody,
|
|
37
|
+
metadata: { extra: "metadatacomment" },
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const thread = await store.createThread({
|
|
41
|
+
initialComment,
|
|
42
|
+
metadata: { extra: "metadatathread" },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
expect(thread).toMatchObject({
|
|
46
|
+
type: "thread",
|
|
47
|
+
id: "mocked-uuid-2",
|
|
48
|
+
resolved: false,
|
|
49
|
+
metadata: { extra: "metadatathread" },
|
|
50
|
+
comments: [
|
|
51
|
+
{
|
|
52
|
+
type: "comment",
|
|
53
|
+
id: "mocked-uuid-1",
|
|
54
|
+
userId: "test-user",
|
|
55
|
+
body: "Test comment",
|
|
56
|
+
metadata: { extra: "metadatacomment" },
|
|
57
|
+
reactions: [],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("addComment", () => {
|
|
65
|
+
it("adds a comment to existing thread", async () => {
|
|
66
|
+
// First create a thread
|
|
67
|
+
const thread = await store.createThread({
|
|
68
|
+
initialComment: {
|
|
69
|
+
body: "Initial comment" as CommentBody,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Add new comment
|
|
74
|
+
const comment = await store.addComment({
|
|
75
|
+
threadId: thread.id,
|
|
76
|
+
comment: {
|
|
77
|
+
body: "New comment" as CommentBody,
|
|
78
|
+
metadata: { test: "metadata" },
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(comment).toMatchObject({
|
|
83
|
+
type: "comment",
|
|
84
|
+
id: "mocked-uuid-3",
|
|
85
|
+
userId: "test-user",
|
|
86
|
+
body: "New comment",
|
|
87
|
+
metadata: { test: "metadata" },
|
|
88
|
+
reactions: [],
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Verify thread has both comments
|
|
92
|
+
const updatedThread = store.getThread(thread.id);
|
|
93
|
+
expect(updatedThread.comments).toHaveLength(2);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("throws error for non-existent thread", async () => {
|
|
97
|
+
await expect(
|
|
98
|
+
store.addComment({
|
|
99
|
+
threadId: "non-existent",
|
|
100
|
+
comment: {
|
|
101
|
+
body: "Test comment" as CommentBody,
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
).rejects.toThrow("Thread not found");
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("updateComment", () => {
|
|
109
|
+
it("updates existing comment", async () => {
|
|
110
|
+
const thread = await store.createThread({
|
|
111
|
+
initialComment: {
|
|
112
|
+
body: "Initial comment" as CommentBody,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await store.updateComment({
|
|
117
|
+
threadId: thread.id,
|
|
118
|
+
commentId: thread.comments[0].id,
|
|
119
|
+
comment: {
|
|
120
|
+
body: "Updated comment" as CommentBody,
|
|
121
|
+
metadata: { updatedMetadata: true },
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const updatedThread = store.getThread(thread.id);
|
|
126
|
+
expect(updatedThread.comments[0]).toMatchObject({
|
|
127
|
+
body: "Updated comment",
|
|
128
|
+
metadata: { updatedMetadata: true },
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("deleteComment", () => {
|
|
134
|
+
it("soft deletes a comment", async () => {
|
|
135
|
+
const thread = await store.createThread({
|
|
136
|
+
initialComment: {
|
|
137
|
+
body: "Test comment" as CommentBody,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
await store.deleteComment({
|
|
142
|
+
threadId: thread.id,
|
|
143
|
+
commentId: thread.comments[0].id,
|
|
144
|
+
softDelete: true,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const updatedThread = store.getThread(thread.id);
|
|
148
|
+
expect(updatedThread.comments[0].deletedAt).toBeDefined();
|
|
149
|
+
expect(updatedThread.comments[0].body).toBeUndefined();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("hard deletes a comment (deletes thread)", async () => {
|
|
153
|
+
const thread = await store.createThread({
|
|
154
|
+
initialComment: {
|
|
155
|
+
body: "Test comment" as CommentBody,
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
await store.deleteComment({
|
|
160
|
+
threadId: thread.id,
|
|
161
|
+
commentId: thread.comments[0].id,
|
|
162
|
+
softDelete: false,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Thread should be deleted since it was the only comment
|
|
166
|
+
expect(() => store.getThread(thread.id)).toThrow("Thread not found");
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe("resolveThread", () => {
|
|
171
|
+
it("resolves a thread", async () => {
|
|
172
|
+
const thread = await store.createThread({
|
|
173
|
+
initialComment: {
|
|
174
|
+
body: "Test comment" as CommentBody,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
await store.resolveThread({ threadId: thread.id });
|
|
179
|
+
|
|
180
|
+
const updatedThread = store.getThread(thread.id);
|
|
181
|
+
expect(updatedThread.resolved).toBe(true);
|
|
182
|
+
expect(updatedThread.resolvedUpdatedAt).toBeDefined();
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe("unresolveThread", () => {
|
|
187
|
+
it("unresolves a thread", async () => {
|
|
188
|
+
const thread = await store.createThread({
|
|
189
|
+
initialComment: {
|
|
190
|
+
body: "Test comment" as CommentBody,
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
await store.resolveThread({ threadId: thread.id });
|
|
195
|
+
await store.unresolveThread({ threadId: thread.id });
|
|
196
|
+
|
|
197
|
+
const updatedThread = store.getThread(thread.id);
|
|
198
|
+
expect(updatedThread.resolved).toBe(false);
|
|
199
|
+
expect(updatedThread.resolvedUpdatedAt).toBeDefined();
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe("getThreads", () => {
|
|
204
|
+
it("returns all threads", async () => {
|
|
205
|
+
await store.createThread({
|
|
206
|
+
initialComment: {
|
|
207
|
+
body: "Thread 1" as CommentBody,
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
await store.createThread({
|
|
212
|
+
initialComment: {
|
|
213
|
+
body: "Thread 2" as CommentBody,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const threads = store.getThreads();
|
|
218
|
+
expect(threads.size).toBe(2);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe("deleteThread", () => {
|
|
223
|
+
it("deletes an entire thread", async () => {
|
|
224
|
+
const thread = await store.createThread({
|
|
225
|
+
initialComment: {
|
|
226
|
+
body: "Test comment" as CommentBody,
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
await store.deleteThread({ threadId: thread.id });
|
|
231
|
+
|
|
232
|
+
// Verify thread is deleted
|
|
233
|
+
expect(() => store.getThread(thread.id)).toThrow("Thread not found");
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe("reactions", () => {
|
|
238
|
+
it("adds a reaction to a comment", async () => {
|
|
239
|
+
const thread = await store.createThread({
|
|
240
|
+
initialComment: {
|
|
241
|
+
body: "Test comment" as CommentBody,
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
await store.addReaction({
|
|
246
|
+
threadId: thread.id,
|
|
247
|
+
commentId: thread.comments[0].id,
|
|
248
|
+
emoji: "👍",
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
expect(store.getThread(thread.id).comments[0].reactions).toHaveLength(1);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("deletes a reaction from a comment", async () => {
|
|
255
|
+
const thread = await store.createThread({
|
|
256
|
+
initialComment: {
|
|
257
|
+
body: "Test comment" as CommentBody,
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
await store.addReaction({
|
|
262
|
+
threadId: thread.id,
|
|
263
|
+
commentId: thread.comments[0].id,
|
|
264
|
+
emoji: "👍",
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
expect(store.getThread(thread.id).comments[0].reactions).toHaveLength(1);
|
|
268
|
+
|
|
269
|
+
await store.deleteReaction({
|
|
270
|
+
threadId: thread.id,
|
|
271
|
+
commentId: thread.comments[0].id,
|
|
272
|
+
emoji: "👍",
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
expect(store.getThread(thread.id).comments[0].reactions).toHaveLength(0);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe("subscribe", () => {
|
|
280
|
+
it("calls callback when threads change", async () => {
|
|
281
|
+
const callback = vi.fn();
|
|
282
|
+
const unsubscribe = store.subscribe(callback);
|
|
283
|
+
|
|
284
|
+
await store.createThread({
|
|
285
|
+
initialComment: {
|
|
286
|
+
body: "Test comment" as CommentBody,
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
expect(callback).toHaveBeenCalled();
|
|
291
|
+
|
|
292
|
+
unsubscribe();
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
});
|