@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,378 @@
|
|
|
1
|
+
import { getChangedRanges } from "@tiptap/core";
|
|
2
|
+
import { Plugin, PluginKey, type Transaction } from "prosemirror-state";
|
|
3
|
+
import {
|
|
4
|
+
createExtension,
|
|
5
|
+
createStore,
|
|
6
|
+
type ExtensionOptions,
|
|
7
|
+
} from "../../editor/BlockNoteExtension.js";
|
|
8
|
+
import {
|
|
9
|
+
colorsForUserIds,
|
|
10
|
+
userColorVarNames,
|
|
11
|
+
normalizeToUserStore,
|
|
12
|
+
type UserStoreOrResolver,
|
|
13
|
+
} from "../../user/index.js";
|
|
14
|
+
import {
|
|
15
|
+
resolveAttributionMarkClassName,
|
|
16
|
+
YAttributionMarksExtension,
|
|
17
|
+
type GetAttributionMarkClassName,
|
|
18
|
+
} from "./YAttributionMarks.js";
|
|
19
|
+
|
|
20
|
+
/** The attribution marks, mapped to their `modificationType`. */
|
|
21
|
+
const ATTRIBUTION_MARK_TYPES = {
|
|
22
|
+
"y-attributed-insert": "insert",
|
|
23
|
+
"y-attributed-delete": "delete",
|
|
24
|
+
"y-attributed-format": "format",
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
const ATTRIBUTION_LOAD_PLUGIN_KEY = new PluginKey("attributionLoadUsers");
|
|
28
|
+
|
|
29
|
+
/** Wrapper of an attribution mark; carries its author(s) in `data-user-ids`. */
|
|
30
|
+
const ATTRIBUTION_MARK_SELECTOR = "[data-user-ids]";
|
|
31
|
+
|
|
32
|
+
/** Parse the JSON-encoded `data-user-ids` attribute; `[]` if missing/malformed. */
|
|
33
|
+
const parseUserIds = (userIdsJSON: string | undefined): string[] => {
|
|
34
|
+
if (!userIdsJSON) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
let userIds: unknown;
|
|
38
|
+
try {
|
|
39
|
+
userIds = JSON.parse(userIdsJSON);
|
|
40
|
+
} catch {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
return Array.isArray(userIds) ? userIds.map(String) : [];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The changed format keys from a modification mark's `data-format` (e.g.
|
|
48
|
+
* `["bold", "italic"]`); `[]` if missing/malformed or an empty change. This is
|
|
49
|
+
* the raw change context — turning it into a localized label (e.g.
|
|
50
|
+
* `"Bold, Italic"`) is a view concern owned by the React layer's
|
|
51
|
+
* `formatChangeLabel`, so core stays i18n-agnostic here.
|
|
52
|
+
*/
|
|
53
|
+
const parseFormatKeys = (formatJSON: string | undefined): string[] => {
|
|
54
|
+
if (!formatJSON) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
let format: unknown;
|
|
58
|
+
try {
|
|
59
|
+
format = JSON.parse(formatJSON);
|
|
60
|
+
} catch {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
if (typeof format !== "object" || format === null) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
return Object.keys(format);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The element with a real box to anchor the tooltip to. The wrapper is
|
|
71
|
+
* `display: contents` (no box of its own), so use its content span child,
|
|
72
|
+
* falling back further for block marks.
|
|
73
|
+
*/
|
|
74
|
+
const getReferenceElement = (wrapper: Element): Element => {
|
|
75
|
+
const content = wrapper.firstElementChild ?? wrapper;
|
|
76
|
+
const rect = content.getBoundingClientRect();
|
|
77
|
+
if (rect.width || rect.height) {
|
|
78
|
+
return content;
|
|
79
|
+
}
|
|
80
|
+
return content.firstElementChild ?? content;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The box the tooltip anchors to. The wrapper is `display: contents` (no box of
|
|
85
|
+
* its own), so use its content span child, falling back further for block marks.
|
|
86
|
+
* Exported for the React controller's floating-ui `getBoundingClientRect`.
|
|
87
|
+
*/
|
|
88
|
+
export const getReferenceRect = (wrapper: Element): DOMRect =>
|
|
89
|
+
getReferenceElement(wrapper).getBoundingClientRect();
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The per-line client rects of the reference element, for floating-ui's
|
|
93
|
+
* `inline()` middleware — it needs one rect per line to position off a
|
|
94
|
+
* multi-line mark, and virtual elements don't get a default `getClientRects`.
|
|
95
|
+
*/
|
|
96
|
+
export const getReferenceClientRects = (wrapper: Element): DOMRectList =>
|
|
97
|
+
getReferenceElement(wrapper).getClientRects();
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* State for the currently-hovered suggestion mark's tooltip (`undefined` when
|
|
101
|
+
* none). The extension computes it; a React controller renders + positions it
|
|
102
|
+
* (see `AttributionTooltipController`).
|
|
103
|
+
*/
|
|
104
|
+
export type AttributionTooltipState = {
|
|
105
|
+
/** The wrapper element the tooltip anchors to (floating-ui reference). */
|
|
106
|
+
anchor: HTMLElement;
|
|
107
|
+
/** Per-user background color, resolved from the user store (default path). */
|
|
108
|
+
color: string;
|
|
109
|
+
/** The kind of change — `format` is the modification mark. */
|
|
110
|
+
modificationType: "insert" | "delete" | "format";
|
|
111
|
+
/** Whether the mark wraps inline content or a whole block. */
|
|
112
|
+
contentType: "inline-content" | "block";
|
|
113
|
+
/** Resolved usernames (falls back to raw ids), for custom renderers. */
|
|
114
|
+
users: string[];
|
|
115
|
+
/**
|
|
116
|
+
* The changed format keys (e.g. `["bold", "italic"]`), present only for
|
|
117
|
+
* `format` marks. This is the raw change context — the view layer turns it
|
|
118
|
+
* into a localized label via its `formatChangeLabel`.
|
|
119
|
+
*/
|
|
120
|
+
format?: string[];
|
|
121
|
+
/**
|
|
122
|
+
* Class name from the `getAttributionMarkClassName` callback (override path).
|
|
123
|
+
* When present, the tooltip applies this and skips the inline `color`.
|
|
124
|
+
*/
|
|
125
|
+
className?: string;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Resolves the attribution tooltip state for suggestion marks on hover (exposed
|
|
130
|
+
* via a store for React), and loads each mark's author so its color/username
|
|
131
|
+
* resolves. Marks nest, so a single delegated `mouseover` listener picks the
|
|
132
|
+
* `closest` wrapper to the pointer — the innermost mark wins.
|
|
133
|
+
*/
|
|
134
|
+
export const AttributionExtension = createExtension(
|
|
135
|
+
({
|
|
136
|
+
options,
|
|
137
|
+
}: ExtensionOptions<
|
|
138
|
+
| {
|
|
139
|
+
/** Resolves authors to usernames. Optional; unresolved ids show raw. */
|
|
140
|
+
resolveUsers?: UserStoreOrResolver;
|
|
141
|
+
/** See {@link GetAttributionMarkClassName}. */
|
|
142
|
+
getAttributionMarkClassName?: GetAttributionMarkClassName;
|
|
143
|
+
}
|
|
144
|
+
| undefined
|
|
145
|
+
>) => {
|
|
146
|
+
const userStore = normalizeToUserStore(options?.resolveUsers);
|
|
147
|
+
const getAttributionMarkClassName = options?.getAttributionMarkClassName;
|
|
148
|
+
|
|
149
|
+
const store = createStore<AttributionTooltipState | undefined>(undefined);
|
|
150
|
+
|
|
151
|
+
// Load the authors of the attribution marks in `tr`'s changed ranges, so
|
|
152
|
+
// their colors/usernames resolve (colors then flow to marks via `syncRootVars`).
|
|
153
|
+
// `getChangedRanges` covers mark-only steps too — which suggestion mode adds
|
|
154
|
+
// over existing text and `tr.changedRange()` would miss.
|
|
155
|
+
const loadChangedUsers = (tr: Transaction) => {
|
|
156
|
+
const ranges = getChangedRanges(tr);
|
|
157
|
+
if (ranges.length === 0) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
// Most changes are local (often several steps in one small span), so scan a
|
|
161
|
+
// single range spanning all of them rather than each range individually.
|
|
162
|
+
let from = Infinity;
|
|
163
|
+
let to = -Infinity;
|
|
164
|
+
for (const { newRange } of ranges) {
|
|
165
|
+
from = Math.min(from, newRange.from);
|
|
166
|
+
to = Math.max(to, newRange.to);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const ids = new Set<string>();
|
|
170
|
+
tr.doc.nodesBetween(from, to, (node) => {
|
|
171
|
+
for (const mark of node.marks) {
|
|
172
|
+
if (
|
|
173
|
+
ATTRIBUTION_MARK_TYPES[
|
|
174
|
+
mark.type.name as keyof typeof ATTRIBUTION_MARK_TYPES
|
|
175
|
+
]
|
|
176
|
+
) {
|
|
177
|
+
const userIds = mark.attrs["userIds"] as string[] | null;
|
|
178
|
+
userIds?.forEach((id) => ids.add(id));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return true;
|
|
182
|
+
});
|
|
183
|
+
if (ids.size > 0) {
|
|
184
|
+
void userStore.loadUsers(Array.from(ids));
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
key: "attribution",
|
|
190
|
+
userStore,
|
|
191
|
+
store,
|
|
192
|
+
prosemirrorPlugins: [
|
|
193
|
+
// Marks arrive in a transaction (suggestion mode, viewing suggestions,
|
|
194
|
+
// version preview), so resolve their authors as the doc changes.
|
|
195
|
+
new Plugin({
|
|
196
|
+
key: ATTRIBUTION_LOAD_PLUGIN_KEY,
|
|
197
|
+
state: {
|
|
198
|
+
init: () => null,
|
|
199
|
+
apply: (tr) => {
|
|
200
|
+
if (tr.docChanged) {
|
|
201
|
+
loadChangedUsers(tr);
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
}),
|
|
207
|
+
],
|
|
208
|
+
mount({ dom, root, signal }) {
|
|
209
|
+
// Write each resolved author's color to the editor root as per-user CSS
|
|
210
|
+
// variables (`--user-color-<id>-{light,dark}`) that the mark wrappers read
|
|
211
|
+
// via `var(..., <fallback>)`, so the cascade recolors marks once a color
|
|
212
|
+
// resolves. Color-less users have theirs removed so the fallback applies.
|
|
213
|
+
const syncRootVars = () => {
|
|
214
|
+
for (const [id, user] of userStore.store.state) {
|
|
215
|
+
const { light, dark } = userColorVarNames(id);
|
|
216
|
+
if (user.color && user.colorLight) {
|
|
217
|
+
dom.style.setProperty(light, user.colorLight);
|
|
218
|
+
dom.style.setProperty(dark, user.color);
|
|
219
|
+
} else {
|
|
220
|
+
dom.style.removeProperty(light);
|
|
221
|
+
dom.style.removeProperty(dark);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// The wrapper currently showing a tooltip, so we don't re-emit on every
|
|
227
|
+
// `mouseover` over the same mark.
|
|
228
|
+
let activeAnchor: HTMLElement | undefined;
|
|
229
|
+
|
|
230
|
+
// The mark's authors as usernames, falling back to the raw id when not
|
|
231
|
+
// cached (`getUser` is cache-only; ids load on hover, see `onPointerOver`).
|
|
232
|
+
const usersLabelArray = (userIdsJSON: string | undefined): string[] =>
|
|
233
|
+
parseUserIds(userIdsJSON).map(
|
|
234
|
+
(id) => userStore.getUser(id)?.username ?? id,
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
// A stable identity string for a wrapper (empty if unattributed), used to
|
|
238
|
+
// (a) test whether a mark is attributed and (b) group adjacent marks with
|
|
239
|
+
// the *same* attribution under one tooltip. It's an internal grouping key,
|
|
240
|
+
// not the displayed text — that's composed in the view from `users` and
|
|
241
|
+
// the format label — so it's built from raw `data-*` (ids + format keys)
|
|
242
|
+
// and stays free of i18n/username resolution.
|
|
243
|
+
const attributionIdentity = (wrapper: HTMLElement) => {
|
|
244
|
+
const ids = parseUserIds(wrapper.dataset["userIds"]);
|
|
245
|
+
if (ids.length === 0) {
|
|
246
|
+
return "";
|
|
247
|
+
}
|
|
248
|
+
const format = parseFormatKeys(wrapper.dataset["format"]);
|
|
249
|
+
return `${format.join(",")}:${ids.join(",")}`;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// Build the tooltip state from a wrapper's `data-*` attributes.
|
|
253
|
+
const buildState = (anchor: HTMLElement): AttributionTooltipState => {
|
|
254
|
+
const isModification = anchor.dataset["format"] !== undefined;
|
|
255
|
+
const modificationType: AttributionTooltipState["modificationType"] =
|
|
256
|
+
isModification
|
|
257
|
+
? "format"
|
|
258
|
+
: anchor.tagName === "INS"
|
|
259
|
+
? "insert"
|
|
260
|
+
: "delete";
|
|
261
|
+
const contentType: AttributionTooltipState["contentType"] =
|
|
262
|
+
anchor.dataset["inline"] === "false" ? "block" : "inline-content";
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
anchor,
|
|
266
|
+
// The tooltip is portaled outside the editor root, so it can't read
|
|
267
|
+
// the cascaded per-user vars — resolve a concrete color from the store.
|
|
268
|
+
color: colorsForUserIds(
|
|
269
|
+
userStore,
|
|
270
|
+
parseUserIds(anchor.dataset["userIds"]),
|
|
271
|
+
).dark,
|
|
272
|
+
modificationType,
|
|
273
|
+
contentType,
|
|
274
|
+
users: usersLabelArray(anchor.dataset["userIds"]),
|
|
275
|
+
format: isModification
|
|
276
|
+
? parseFormatKeys(anchor.dataset["format"])
|
|
277
|
+
: undefined,
|
|
278
|
+
className: resolveAttributionMarkClassName(
|
|
279
|
+
getAttributionMarkClassName?.({ contentType, modificationType }),
|
|
280
|
+
"tooltip",
|
|
281
|
+
),
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const hideTooltip = () => {
|
|
286
|
+
if (!activeAnchor) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
activeAnchor = undefined;
|
|
290
|
+
store.setState(undefined);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// The innermost attributed mark at or above `el`, skipping unattributed
|
|
294
|
+
// wrappers so an attributed ancestor still wins.
|
|
295
|
+
const innermostAttributed = (
|
|
296
|
+
el: Element | null,
|
|
297
|
+
): HTMLElement | undefined => {
|
|
298
|
+
while (el) {
|
|
299
|
+
const wrapper = el.closest<HTMLElement>(ATTRIBUTION_MARK_SELECTOR);
|
|
300
|
+
if (!wrapper) {
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
if (attributionIdentity(wrapper)) {
|
|
304
|
+
return wrapper;
|
|
305
|
+
}
|
|
306
|
+
el = wrapper.parentElement;
|
|
307
|
+
}
|
|
308
|
+
return undefined;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const onPointerOver = (event: Event) => {
|
|
312
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
313
|
+
const innermost = innermostAttributed(target);
|
|
314
|
+
if (!innermost) {
|
|
315
|
+
// Not over an attributed mark — drop the current tooltip.
|
|
316
|
+
hideTooltip();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const identity = attributionIdentity(innermost);
|
|
321
|
+
// Anchor on the outermost ancestor with the *same* attribution so one
|
|
322
|
+
// tooltip covers the whole region; a differently-attributed ancestor
|
|
323
|
+
// breaks the chain, and unattributed ones are climbed past.
|
|
324
|
+
let anchor = innermost;
|
|
325
|
+
let el: Element | null = innermost.parentElement;
|
|
326
|
+
while (el) {
|
|
327
|
+
const ancestor = el.closest<HTMLElement>(ATTRIBUTION_MARK_SELECTOR);
|
|
328
|
+
if (!ancestor) {
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
const ancestorIdentity = attributionIdentity(ancestor);
|
|
332
|
+
if (ancestorIdentity === identity) {
|
|
333
|
+
anchor = ancestor;
|
|
334
|
+
} else if (ancestorIdentity) {
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
el = ancestor.parentElement;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (activeAnchor === anchor) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
activeAnchor = anchor;
|
|
345
|
+
store.setState(buildState(anchor));
|
|
346
|
+
|
|
347
|
+
// First hover renders raw ids (cache-only); load the authors and refresh
|
|
348
|
+
// the resolved usernames once loaded, if this mark is still active.
|
|
349
|
+
const ids = parseUserIds(anchor.dataset["userIds"]);
|
|
350
|
+
if (ids.length > 0) {
|
|
351
|
+
void userStore.loadUsers(ids).then(() => {
|
|
352
|
+
if (activeAnchor !== anchor) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
store.setState(buildState(anchor));
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
root.addEventListener("mouseover", onPointerOver, { signal });
|
|
361
|
+
signal.addEventListener("abort", hideTooltip);
|
|
362
|
+
|
|
363
|
+
// Seed from the cache, then keep the vars in sync as users resolve.
|
|
364
|
+
syncRootVars();
|
|
365
|
+
const unsubscribe = userStore.store.subscribe(syncRootVars);
|
|
366
|
+
signal.addEventListener("abort", unsubscribe);
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
// The `y-attributed-*` marks aren't in the default schema — register them
|
|
370
|
+
// here so the block specs can allow them (collaboration-only).
|
|
371
|
+
blockNoteExtensions: [
|
|
372
|
+
YAttributionMarksExtension({
|
|
373
|
+
getAttributionMarkClassName: options?.getAttributionMarkClassName,
|
|
374
|
+
}),
|
|
375
|
+
],
|
|
376
|
+
};
|
|
377
|
+
},
|
|
378
|
+
);
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from "vite-plus/test";
|
|
5
|
+
|
|
6
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
7
|
+
import type { Block } from "../../blocks/defaultBlocks.js";
|
|
8
|
+
import { AttributionExtension } from "./AttributionExtension.js";
|
|
9
|
+
import { DiffVersioningExtension } from "./DiffVersioningExtension.js";
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Helpers
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
function createDiffEditor() {
|
|
16
|
+
const editor = BlockNoteEditor.create({
|
|
17
|
+
extensions: [DiffVersioningExtension()],
|
|
18
|
+
});
|
|
19
|
+
editor.mount(document.createElement("div"));
|
|
20
|
+
return editor;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Build a `Block[]` fixture from a plain paragraph string using a throwaway
|
|
25
|
+
* editor, mirroring the `mkSnap` pattern in `inMemoryVersioning.test.ts`.
|
|
26
|
+
*/
|
|
27
|
+
function blocksFromText(text: string): Block<any, any, any>[] {
|
|
28
|
+
const e = BlockNoteEditor.create();
|
|
29
|
+
e.mount(document.createElement("div"));
|
|
30
|
+
e.replaceBlocks(e.document, [{ type: "paragraph", content: text }]);
|
|
31
|
+
const blocks = e.document;
|
|
32
|
+
e.unmount();
|
|
33
|
+
return blocks;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Walk the rendered doc and collect, per text node, its text and the attribution
|
|
38
|
+
* marks on it: `{ text, marks: [[markName, userIds], ...] }`. Only y-attributed-*
|
|
39
|
+
* marks are recorded, so ordinary formatting doesn't pollute the assertion.
|
|
40
|
+
*/
|
|
41
|
+
function collectAttributedText(editor: BlockNoteEditor<any, any, any>) {
|
|
42
|
+
const out: Array<{ text: string; marks: Array<[string, string[]]> }> = [];
|
|
43
|
+
editor.prosemirrorState.doc.descendants((node) => {
|
|
44
|
+
if (node.isText) {
|
|
45
|
+
const marks = node.marks
|
|
46
|
+
.filter((m) => m.type.name.startsWith("y-attributed-"))
|
|
47
|
+
.map(
|
|
48
|
+
(m) =>
|
|
49
|
+
[m.type.name, (m.attrs.userIds as string[]) ?? []] as [
|
|
50
|
+
string,
|
|
51
|
+
string[],
|
|
52
|
+
],
|
|
53
|
+
);
|
|
54
|
+
out.push({ text: node.text ?? "", marks });
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
});
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function attributionMarkNames(
|
|
62
|
+
editor: BlockNoteEditor<any, any, any>,
|
|
63
|
+
): Set<string> {
|
|
64
|
+
const names = new Set<string>();
|
|
65
|
+
editor.prosemirrorState.doc.descendants((node) => {
|
|
66
|
+
node.marks.forEach((m) => {
|
|
67
|
+
if (m.type.name.startsWith("y-attributed-")) {
|
|
68
|
+
names.add(m.type.name);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return true;
|
|
72
|
+
});
|
|
73
|
+
return names;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// Tests
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
describe("DiffVersioningExtension", () => {
|
|
81
|
+
let editor: BlockNoteEditor<any, any, any>;
|
|
82
|
+
|
|
83
|
+
beforeEach(() => {
|
|
84
|
+
editor = createDiffEditor();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
afterEach(() => {
|
|
88
|
+
editor.unmount();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("registers the y-attributed-* marks into the schema", () => {
|
|
92
|
+
expect(editor.pmSchema.marks["y-attributed-insert"]).toBeDefined();
|
|
93
|
+
expect(editor.pmSchema.marks["y-attributed-delete"]).toBeDefined();
|
|
94
|
+
expect(editor.pmSchema.marks["y-attributed-format"]).toBeDefined();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("renders insert/delete marks in the right positions for a known diff", () => {
|
|
98
|
+
const baseline = blocksFromText("the quick brown fox");
|
|
99
|
+
const target = blocksFromText("the slow brown fox jumps");
|
|
100
|
+
|
|
101
|
+
const diff = editor.getExtension(DiffVersioningExtension)!;
|
|
102
|
+
diff.renderDiff(target, baseline);
|
|
103
|
+
|
|
104
|
+
const attributed = collectAttributedText(editor);
|
|
105
|
+
|
|
106
|
+
// The rendered doc must contain both an insertion and a deletion.
|
|
107
|
+
const names = attributionMarkNames(editor);
|
|
108
|
+
expect(names.has("y-attributed-insert")).toBe(true);
|
|
109
|
+
expect(names.has("y-attributed-delete")).toBe(true);
|
|
110
|
+
|
|
111
|
+
// "quick" is only in the baseline -> deleted.
|
|
112
|
+
const deleted = attributed
|
|
113
|
+
.filter((t) => t.marks.some(([n]) => n === "y-attributed-delete"))
|
|
114
|
+
.map((t) => t.text)
|
|
115
|
+
.join("");
|
|
116
|
+
expect(deleted).toContain("quick");
|
|
117
|
+
|
|
118
|
+
// "slow" and "jumps" are only in the target -> inserted.
|
|
119
|
+
const inserted = attributed
|
|
120
|
+
.filter((t) => t.marks.some(([n]) => n === "y-attributed-insert"))
|
|
121
|
+
.map((t) => t.text)
|
|
122
|
+
.join("");
|
|
123
|
+
expect(inserted).toContain("slow");
|
|
124
|
+
expect(inserted).toContain("jumps");
|
|
125
|
+
|
|
126
|
+
// Unchanged text ("brown fox") carries no attribution marks.
|
|
127
|
+
const unchanged = attributed
|
|
128
|
+
.filter((t) => t.marks.length === 0)
|
|
129
|
+
.map((t) => t.text)
|
|
130
|
+
.join("");
|
|
131
|
+
expect(unchanged).toContain("brown fox");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("attributes the diff to the version author id (userIds on the marks)", () => {
|
|
135
|
+
const baseline = blocksFromText("hello world");
|
|
136
|
+
const target = blocksFromText("hello there world");
|
|
137
|
+
|
|
138
|
+
const diff = editor.getExtension(DiffVersioningExtension)!;
|
|
139
|
+
diff.renderDiff(target, baseline, "My version");
|
|
140
|
+
|
|
141
|
+
const attributed = collectAttributedText(editor);
|
|
142
|
+
const insertUserIds = attributed
|
|
143
|
+
.flatMap((t) => t.marks)
|
|
144
|
+
.filter(([n]) => n === "y-attributed-insert")
|
|
145
|
+
.flatMap(([, ids]) => ids);
|
|
146
|
+
|
|
147
|
+
// A version diff has one synthetic author (the version). Its id encodes the
|
|
148
|
+
// version label, so the tooltip resolves to that name.
|
|
149
|
+
expect(insertUserIds).toContain("version:My version");
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("resolves the diff author to the version's name (tooltip label)", async () => {
|
|
153
|
+
const baseline = blocksFromText("hello world");
|
|
154
|
+
const target = blocksFromText("hello brave new world");
|
|
155
|
+
|
|
156
|
+
const diff = editor.getExtension(DiffVersioningExtension)!;
|
|
157
|
+
diff.renderDiff(target, baseline, "Draft 3");
|
|
158
|
+
|
|
159
|
+
// The version name is surfaced by resolving the marks' author id through the
|
|
160
|
+
// composed AttributionExtension's user store — this is what the hover tooltip
|
|
161
|
+
// shows ("…by {name}").
|
|
162
|
+
const attribution = editor.getExtension(AttributionExtension)!;
|
|
163
|
+
const authorId = "version:Draft 3";
|
|
164
|
+
await attribution.userStore.loadUsers([authorId]);
|
|
165
|
+
expect(attribution.userStore.getUser(authorId)?.username).toBe("Draft 3");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("produces no attribution marks when the docs are identical", () => {
|
|
169
|
+
const same = blocksFromText("nothing changes here");
|
|
170
|
+
|
|
171
|
+
const diff = editor.getExtension(DiffVersioningExtension)!;
|
|
172
|
+
diff.renderDiff(same, same);
|
|
173
|
+
|
|
174
|
+
expect(attributionMarkNames(editor).size).toBe(0);
|
|
175
|
+
expect(editor.prosemirrorState.doc.textContent).toContain(
|
|
176
|
+
"nothing changes here",
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("clearDiff restores plain content with no attribution marks", () => {
|
|
181
|
+
const baseline = blocksFromText("first version");
|
|
182
|
+
const target = blocksFromText("second version");
|
|
183
|
+
const restore = blocksFromText("live document");
|
|
184
|
+
|
|
185
|
+
const diff = editor.getExtension(DiffVersioningExtension)!;
|
|
186
|
+
diff.renderDiff(target, baseline);
|
|
187
|
+
expect(attributionMarkNames(editor).size).toBeGreaterThan(0);
|
|
188
|
+
|
|
189
|
+
diff.clearDiff(restore);
|
|
190
|
+
expect(attributionMarkNames(editor).size).toBe(0);
|
|
191
|
+
expect(editor.prosemirrorState.doc.textContent).toBe("live document");
|
|
192
|
+
});
|
|
193
|
+
});
|