@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,320 @@
|
|
|
1
|
+
import { Mark } from "@tiptap/core";
|
|
2
|
+
import { Mark as PMMark, MarkSpec } from "prosemirror-model";
|
|
3
|
+
import {
|
|
4
|
+
createExtension,
|
|
5
|
+
type ExtensionOptions,
|
|
6
|
+
} from "../../editor/BlockNoteExtension.js";
|
|
7
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
8
|
+
import { BLOCK_LEVEL_SUGGESTION_GROUP } from "../../pm-nodes/suggestionMarks.js";
|
|
9
|
+
import { NON_FORMATTING_MARK_GROUP } from "../../schema/markGroups.js";
|
|
10
|
+
import {
|
|
11
|
+
fallbackColorForUserId,
|
|
12
|
+
userColorPalette,
|
|
13
|
+
userColorVarNames,
|
|
14
|
+
} from "../../user/index.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Describes a suggestion mark to {@link GetAttributionMarkClassName}: whether it
|
|
18
|
+
* wraps inline content or a whole block, and which kind of change it represents.
|
|
19
|
+
* `modificationType: "format"` corresponds to the `y-attributed-format`
|
|
20
|
+
* (modification) mark.
|
|
21
|
+
*/
|
|
22
|
+
export type AttributionMarkStyleInfo = {
|
|
23
|
+
contentType: "inline-content" | "block";
|
|
24
|
+
modificationType: "insert" | "delete" | "format";
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The class name(s) an app returns to style a suggestion mark. Either:
|
|
29
|
+
* - a single string applied to *both* the mark content and its hover tooltip, or
|
|
30
|
+
* - `{ content, tooltip }` to style the mark content and the tooltip
|
|
31
|
+
* independently.
|
|
32
|
+
*/
|
|
33
|
+
export type AttributionMarkClassNames =
|
|
34
|
+
| string
|
|
35
|
+
| { content: string; tooltip: string };
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Optional callback to override suggestion-mark styling. Given a mark's
|
|
39
|
+
* {@link AttributionMarkStyleInfo}, it returns the class name(s) to apply (see
|
|
40
|
+
* {@link AttributionMarkClassNames}). When a class is returned, the default
|
|
41
|
+
* per-user color (the `--user-color-*` custom properties and the built-in
|
|
42
|
+
* `.bn-suggestion-mark` / `.bn-suggestion-node` styling) is *not* applied to the
|
|
43
|
+
* mark content, so the class fully controls its appearance — letting an app
|
|
44
|
+
* color suggestions by change type (e.g. green insertions, red deletions)
|
|
45
|
+
* instead of by author.
|
|
46
|
+
*/
|
|
47
|
+
export type GetAttributionMarkClassName = (
|
|
48
|
+
info: AttributionMarkStyleInfo,
|
|
49
|
+
) => AttributionMarkClassNames;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the {@link AttributionMarkClassNames} returned by a
|
|
53
|
+
* {@link GetAttributionMarkClassName} callback to the class name for a single
|
|
54
|
+
* target (the mark `content` or its `tooltip`).
|
|
55
|
+
*/
|
|
56
|
+
export const resolveAttributionMarkClassName = (
|
|
57
|
+
result: AttributionMarkClassNames | undefined,
|
|
58
|
+
target: "content" | "tooltip",
|
|
59
|
+
): string | undefined =>
|
|
60
|
+
result === undefined
|
|
61
|
+
? undefined
|
|
62
|
+
: typeof result === "string"
|
|
63
|
+
? result
|
|
64
|
+
: result[target];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Shared mark view for the attribution marks (insert / delete / modification).
|
|
68
|
+
* It renders the marked content and tags the wrapper with the author(s) via
|
|
69
|
+
* `data-*` attributes. The attribution tooltip shown on hover is handled
|
|
70
|
+
* separately by the `AttributionExtension`, which reads those attributes
|
|
71
|
+
* straight from the DOM — keeping this mark view purely presentational and the
|
|
72
|
+
* tooltip state off of module scope.
|
|
73
|
+
*
|
|
74
|
+
* Author colors are *not* baked into the (deterministic) mark attrs. Instead the
|
|
75
|
+
* wrapper sets the generic `--user-color-*` custom properties the Block.css rules
|
|
76
|
+
* read, sourcing them from the author's *per-user* CSS variable via
|
|
77
|
+
* `var(--user-color-<id>-*, <fallback>)`. Those per-user variables are populated
|
|
78
|
+
* on the editor root by `AttributionExtension` once the user resolves, so a mark
|
|
79
|
+
* shows the deterministic palette fallback immediately and recolors to the
|
|
80
|
+
* author's own color purely through the CSS cascade — no decoration, no doc
|
|
81
|
+
* transaction. See `userColors.ts`.
|
|
82
|
+
*/
|
|
83
|
+
const createAttributionMarkView =
|
|
84
|
+
(
|
|
85
|
+
type: "insert" | "delete" | "modification",
|
|
86
|
+
options?: {
|
|
87
|
+
editor?: BlockNoteEditor<any, any, any>;
|
|
88
|
+
getAttributionMarkClassName?: GetAttributionMarkClassName;
|
|
89
|
+
},
|
|
90
|
+
) =>
|
|
91
|
+
({ mark, inline }: { mark: PMMark; inline: boolean }) => {
|
|
92
|
+
const editor = options?.editor;
|
|
93
|
+
// `<ins>`/`<del>` are semantic elements. The modification mark has no
|
|
94
|
+
// dedicated element, so it renders as a `<span>` inline or a `<div>` over a
|
|
95
|
+
// block, matching its `parseDOM` rules.
|
|
96
|
+
const tag =
|
|
97
|
+
type === "insert"
|
|
98
|
+
? "ins"
|
|
99
|
+
: type === "delete"
|
|
100
|
+
? "del"
|
|
101
|
+
: inline
|
|
102
|
+
? "span"
|
|
103
|
+
: "div";
|
|
104
|
+
const dom = document.createElement(tag);
|
|
105
|
+
|
|
106
|
+
Object.assign(dom.dataset, {
|
|
107
|
+
userIds: JSON.stringify(mark.attrs["userIds"]),
|
|
108
|
+
inline: String(inline),
|
|
109
|
+
});
|
|
110
|
+
if (type === "modification") {
|
|
111
|
+
dom.dataset["type"] = "modification";
|
|
112
|
+
dom.dataset["format"] = JSON.stringify(mark.attrs["format"]);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Optional app-provided override: `y-attributed-format` is exposed as
|
|
116
|
+
// `"format"`. When a class is returned it's applied to the content element
|
|
117
|
+
// *instead of* the built-in `.bn-suggestion-mark` / `.bn-suggestion-node`
|
|
118
|
+
// classes, and the per-user `--user-color-*` properties are omitted, so the
|
|
119
|
+
// class fully controls the appearance (background, text color, etc.) with no
|
|
120
|
+
// per-user color leaking through (see the type doc).
|
|
121
|
+
const contentClassName = resolveAttributionMarkClassName(
|
|
122
|
+
options?.getAttributionMarkClassName?.({
|
|
123
|
+
contentType: inline ? "inline-content" : "block",
|
|
124
|
+
modificationType: type === "modification" ? "format" : type,
|
|
125
|
+
}),
|
|
126
|
+
"content",
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// The wrapper is always `display: contents` so it never generates a box of
|
|
130
|
+
// its own — an inline `<ins>`/`<del>` around block/table content (e.g. a
|
|
131
|
+
// suggestion spanning table cells) would otherwise break the normal layout.
|
|
132
|
+
// Because a `display: contents` element paints nothing, the highlight is
|
|
133
|
+
// applied to the inner content span (see `.bn-suggestion-mark` in Block.css)
|
|
134
|
+
// using the `--user-color-*` custom properties, which cascade down from here.
|
|
135
|
+
// They're sourced from the author's per-user variable (populated on the
|
|
136
|
+
// editor root by `AttributionExtension`) with the deterministic palette as a
|
|
137
|
+
// fallback, so a mark is colored before the user resolves and recolors via
|
|
138
|
+
// the cascade afterward. When an override class owns the styling, no per-user
|
|
139
|
+
// color is applied at all.
|
|
140
|
+
const userIds = (mark.attrs["userIds"] as string[] | null) ?? [];
|
|
141
|
+
const firstId = userIds[0];
|
|
142
|
+
const fallback = firstId
|
|
143
|
+
? fallbackColorForUserId(firstId)
|
|
144
|
+
: userColorPalette[0];
|
|
145
|
+
if (contentClassName) {
|
|
146
|
+
dom.style.cssText = "display: contents";
|
|
147
|
+
} else {
|
|
148
|
+
const light = firstId
|
|
149
|
+
? `var(${userColorVarNames(firstId).light}, ${fallback.light})`
|
|
150
|
+
: fallback.light;
|
|
151
|
+
const dark = firstId
|
|
152
|
+
? `var(${userColorVarNames(firstId).dark}, ${fallback.dark})`
|
|
153
|
+
: fallback.dark;
|
|
154
|
+
dom.style.cssText =
|
|
155
|
+
"display: contents" +
|
|
156
|
+
`; --user-color-light: ${light}; --user-color-dark: ${dark}`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const contentDOM = document.createElement("span");
|
|
160
|
+
if (inline) {
|
|
161
|
+
// Inline content: the span is a real inline box that carries the highlight
|
|
162
|
+
// (default path) or the app-provided override class.
|
|
163
|
+
contentDOM.className =
|
|
164
|
+
contentClassName ??
|
|
165
|
+
(type === "delete"
|
|
166
|
+
? "bn-suggestion-mark bn-suggestion-mark--delete"
|
|
167
|
+
: "bn-suggestion-mark");
|
|
168
|
+
} else {
|
|
169
|
+
// Block-level marks wrap block/table structure (e.g. <tr>/<td>/<p>). The
|
|
170
|
+
// span must be `display: contents` so it doesn't inject an inline box into
|
|
171
|
+
// the table layout (which triggers the browser's anonymous-table fixup and
|
|
172
|
+
// breaks the table). Such a span has no box to paint a background on, so
|
|
173
|
+
// the `.bn-suggestion-node` rule highlights its children (the wrapped
|
|
174
|
+
// nodes) instead. An override class is applied to the same span, so it
|
|
175
|
+
// should likewise target its children (e.g. `.my-class > *`).
|
|
176
|
+
contentDOM.style.display = "contents";
|
|
177
|
+
contentDOM.className =
|
|
178
|
+
contentClassName ??
|
|
179
|
+
(type === "delete"
|
|
180
|
+
? "bn-suggestion-node bn-suggestion-node--delete"
|
|
181
|
+
: "bn-suggestion-node");
|
|
182
|
+
if (type === "delete") {
|
|
183
|
+
// A deleted block shows a localized "Deleted" badge via a `::before`
|
|
184
|
+
// (see Block.css). The badge text is passed down as a CSS string token
|
|
185
|
+
// in `--deleted-label` so the stylesheet stays locale-agnostic; the
|
|
186
|
+
// wrapper is `display: contents` and can't paint a pseudo-element of its
|
|
187
|
+
// own, so the rule renders the badge on the wrapped node instead, which
|
|
188
|
+
// inherits this custom property.
|
|
189
|
+
const label = editor?.dictionary.suggestion_changes.deleted;
|
|
190
|
+
if (label) {
|
|
191
|
+
contentDOM.style.setProperty(
|
|
192
|
+
"--deleted-label",
|
|
193
|
+
JSON.stringify(label),
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
dom.appendChild(contentDOM);
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
dom,
|
|
202
|
+
contentDOM,
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export const YAttributedInsertion = Mark.create<{
|
|
207
|
+
getAttributionMarkClassName?: GetAttributionMarkClassName;
|
|
208
|
+
}>({
|
|
209
|
+
name: "y-attributed-insert",
|
|
210
|
+
inclusive: false,
|
|
211
|
+
excludes: "",
|
|
212
|
+
// Two groups: `BLOCK_LEVEL_SUGGESTION_GROUP` lets the mark sit on block nodes
|
|
213
|
+
// (see `suggestionMarks`), so a whole block can be marked as inserted in
|
|
214
|
+
// suggestion mode; `NON_FORMATTING_MARK_GROUP` lets it annotate text inside
|
|
215
|
+
// `"plain"` blocks (e.g. code blocks) — see `nonFormattingMarks`.
|
|
216
|
+
group: `${BLOCK_LEVEL_SUGGESTION_GROUP} ${NON_FORMATTING_MARK_GROUP}`,
|
|
217
|
+
addAttributes() {
|
|
218
|
+
return {
|
|
219
|
+
userIds: { default: null },
|
|
220
|
+
};
|
|
221
|
+
},
|
|
222
|
+
addMarkView() {
|
|
223
|
+
return createAttributionMarkView("insert", {
|
|
224
|
+
getAttributionMarkClassName: this.options.getAttributionMarkClassName,
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
extendMarkSchema(extension) {
|
|
228
|
+
if (extension.name !== this.name) {
|
|
229
|
+
return {};
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
blocknoteIgnore: true,
|
|
233
|
+
} satisfies MarkSpec;
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
export const YAttributedDeletion = Mark.create<{
|
|
238
|
+
editor?: BlockNoteEditor<any, any, any>;
|
|
239
|
+
getAttributionMarkClassName?: GetAttributionMarkClassName;
|
|
240
|
+
}>({
|
|
241
|
+
name: "y-attributed-delete",
|
|
242
|
+
inclusive: false,
|
|
243
|
+
excludes: "",
|
|
244
|
+
group: `${BLOCK_LEVEL_SUGGESTION_GROUP} ${NON_FORMATTING_MARK_GROUP}`,
|
|
245
|
+
addAttributes() {
|
|
246
|
+
return {
|
|
247
|
+
userIds: { default: null },
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
addMarkView() {
|
|
251
|
+
return createAttributionMarkView("delete", {
|
|
252
|
+
editor: this.options.editor,
|
|
253
|
+
getAttributionMarkClassName: this.options.getAttributionMarkClassName,
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
extendMarkSchema(extension) {
|
|
257
|
+
if (extension.name !== this.name) {
|
|
258
|
+
return {};
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
blocknoteIgnore: true,
|
|
262
|
+
} satisfies MarkSpec;
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
export const YAttributedFormat = Mark.create<{
|
|
267
|
+
getAttributionMarkClassName?: GetAttributionMarkClassName;
|
|
268
|
+
}>({
|
|
269
|
+
name: "y-attributed-format",
|
|
270
|
+
inclusive: false,
|
|
271
|
+
excludes: "",
|
|
272
|
+
group: `${BLOCK_LEVEL_SUGGESTION_GROUP} ${NON_FORMATTING_MARK_GROUP}`,
|
|
273
|
+
addAttributes() {
|
|
274
|
+
return {
|
|
275
|
+
userIds: { default: null },
|
|
276
|
+
format: { default: null },
|
|
277
|
+
};
|
|
278
|
+
},
|
|
279
|
+
addMarkView() {
|
|
280
|
+
return createAttributionMarkView("modification", {
|
|
281
|
+
getAttributionMarkClassName: this.options.getAttributionMarkClassName,
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
extendMarkSchema(extension) {
|
|
285
|
+
if (extension.name !== this.name) {
|
|
286
|
+
return {};
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
blocknoteIgnore: true,
|
|
290
|
+
} satisfies MarkSpec;
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Bundles the three `y-attributed-*` suggestion marks into a single BlockNote
|
|
296
|
+
* extension, so they can be registered wherever they're actually needed (the
|
|
297
|
+
* Yjs collaboration extension, or a test that exercises suggestions) instead of
|
|
298
|
+
* living in the default schema. The marks opt into being allowed on block nodes
|
|
299
|
+
* via their `blockLevelSuggestion` option — see `suggestionMarks`.
|
|
300
|
+
*/
|
|
301
|
+
export const YAttributionMarksExtension = createExtension(
|
|
302
|
+
({
|
|
303
|
+
options,
|
|
304
|
+
}: ExtensionOptions<
|
|
305
|
+
{ getAttributionMarkClassName?: GetAttributionMarkClassName } | undefined
|
|
306
|
+
>) => ({
|
|
307
|
+
key: "yAttributionMarks",
|
|
308
|
+
tiptapExtensions: [
|
|
309
|
+
YAttributedInsertion.configure({
|
|
310
|
+
getAttributionMarkClassName: options?.getAttributionMarkClassName,
|
|
311
|
+
}),
|
|
312
|
+
YAttributedDeletion.configure({
|
|
313
|
+
getAttributionMarkClassName: options?.getAttributionMarkClassName,
|
|
314
|
+
}),
|
|
315
|
+
YAttributedFormat.configure({
|
|
316
|
+
getAttributionMarkClassName: options?.getAttributionMarkClassName,
|
|
317
|
+
}),
|
|
318
|
+
],
|
|
319
|
+
}),
|
|
320
|
+
);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { defaultSelectionBuilder, yCursorPlugin } from "y
|
|
1
|
+
import { defaultSelectionBuilder, yCursorPlugin } from "@y/prosemirror";
|
|
2
2
|
import {
|
|
3
3
|
createExtension,
|
|
4
4
|
ExtensionOptions,
|
|
5
5
|
} from "../../editor/BlockNoteExtension.js";
|
|
6
|
-
import { CollaborationOptions } from "./
|
|
6
|
+
import { CollaborationOptions } from "./index.js";
|
|
7
7
|
|
|
8
8
|
export type CollaborationUser = {
|
|
9
|
+
id?: string;
|
|
9
10
|
name: string;
|
|
10
11
|
color: string;
|
|
11
|
-
[key: string]:
|
|
12
|
+
[key: string]: unknown;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -125,13 +126,13 @@ export const YCursorExtension = createExtension(
|
|
|
125
126
|
awareness
|
|
126
127
|
? yCursorPlugin(awareness, {
|
|
127
128
|
selectionBuilder: defaultSelectionBuilder,
|
|
128
|
-
cursorBuilder(user
|
|
129
|
+
cursorBuilder(user, clientID) {
|
|
129
130
|
let cursorData = recentlyUpdatedCursors.get(clientID);
|
|
130
131
|
|
|
131
132
|
if (!cursorData) {
|
|
132
133
|
const cursorElement = (
|
|
133
134
|
options.renderCursor ?? defaultCursorRender
|
|
134
|
-
)(user);
|
|
135
|
+
)(user as CollaborationUser);
|
|
135
136
|
|
|
136
137
|
if (options.showCursorLabels !== "always") {
|
|
137
138
|
cursorElement.addEventListener("mouseenter", () => {
|
|
@@ -171,11 +172,18 @@ export const YCursorExtension = createExtension(
|
|
|
171
172
|
},
|
|
172
173
|
})
|
|
173
174
|
: undefined,
|
|
174
|
-
].filter(
|
|
175
|
+
].filter((a) => a !== undefined),
|
|
175
176
|
dependsOn: ["ySync"],
|
|
176
|
-
updateUser(user:
|
|
177
|
+
updateUser(user: CollaborationUser) {
|
|
177
178
|
awareness?.setLocalStateField("user", user);
|
|
178
179
|
},
|
|
180
|
+
getUser(): CollaborationUser | undefined {
|
|
181
|
+
const state = awareness?.getLocalState();
|
|
182
|
+
if (!state) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
return state["user"];
|
|
186
|
+
},
|
|
179
187
|
} as const;
|
|
180
188
|
},
|
|
181
189
|
);
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { configureYProsemirror, syncPlugin } from "@y/prosemirror";
|
|
2
|
+
import {
|
|
3
|
+
type ExtensionOptions,
|
|
4
|
+
createExtension,
|
|
5
|
+
} from "../../editor/BlockNoteExtension.js";
|
|
6
|
+
import { blockMatchNodes } from "./blockMatchNodes.js";
|
|
7
|
+
import { CollaborationOptions } from "./index.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Maps a Y attribution to BlockNote's `y-attributed-*` mark attrs.
|
|
11
|
+
*
|
|
12
|
+
* The mapper must be deterministic in `(format, attribution)` and emit attrs
|
|
13
|
+
* that exactly match the declared mark schema in YAttributionMarks.ts. Any
|
|
14
|
+
* mismatch causes the sync plugin to fire phantom reconcile dispatches in a
|
|
15
|
+
* loop. See ATTRIBUTION.md in @y/prosemirror.
|
|
16
|
+
*
|
|
17
|
+
* Crucially the marks carry only stable identity (`userIds`, plus `format` for
|
|
18
|
+
* the modification mark) — *not* user colors. Colors resolve asynchronously
|
|
19
|
+
* from the {@link UserStore}, so baking them in here would make the mapper's
|
|
20
|
+
* output change under a fixed `(format, attribution)` once a user loads, which
|
|
21
|
+
* is exactly the non-determinism that triggers the reconcile loop. Instead the
|
|
22
|
+
* `AttributionExtension` applies colors as a decoration layer that can
|
|
23
|
+
* update independently of the mark representation.
|
|
24
|
+
*/
|
|
25
|
+
export const mapAttributionToMark = (
|
|
26
|
+
format: Record<string, unknown> | null,
|
|
27
|
+
attribution: {
|
|
28
|
+
insert?: readonly string[];
|
|
29
|
+
delete?: readonly string[];
|
|
30
|
+
format?: Record<string, readonly string[]>;
|
|
31
|
+
insertAt?: number;
|
|
32
|
+
deleteAt?: number;
|
|
33
|
+
formatAt?: number;
|
|
34
|
+
},
|
|
35
|
+
): Record<string, unknown> => {
|
|
36
|
+
const out: Record<string, unknown> = { ...format };
|
|
37
|
+
|
|
38
|
+
if (attribution.insert) {
|
|
39
|
+
out["y-attributed-insert"] = { userIds: attribution.insert };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (attribution.delete) {
|
|
43
|
+
out["y-attributed-delete"] = { userIds: attribution.delete };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (attribution.format) {
|
|
47
|
+
const userIds = [...new Set(Object.values(attribution.format).flat())];
|
|
48
|
+
out["y-attributed-format"] = { userIds, format: attribution.format };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return out;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const YSyncExtension = createExtension(
|
|
55
|
+
({
|
|
56
|
+
options,
|
|
57
|
+
editor,
|
|
58
|
+
}: ExtensionOptions<
|
|
59
|
+
Pick<
|
|
60
|
+
CollaborationOptions,
|
|
61
|
+
| "fragment"
|
|
62
|
+
| "renderer"
|
|
63
|
+
| "suggestionDoc"
|
|
64
|
+
| "provider"
|
|
65
|
+
| "getAttributionMarkClassName"
|
|
66
|
+
>
|
|
67
|
+
>) => {
|
|
68
|
+
return {
|
|
69
|
+
key: "ySync",
|
|
70
|
+
fragment: options.fragment,
|
|
71
|
+
mount: () => {
|
|
72
|
+
const configure = () => {
|
|
73
|
+
editor.exec(
|
|
74
|
+
configureYProsemirror({
|
|
75
|
+
ytype: options.fragment,
|
|
76
|
+
// purposefully not passing `renderer` here, this is only for syncing the main doc, not switching to suggestion mode
|
|
77
|
+
// In the future, we may want view suggestion mode to be the default, and then we can decide how to indicate that through the options.
|
|
78
|
+
// For now though, we are leaving suggestion mode as experimental and must be explicitly enabled through the SuggestionsExtension.
|
|
79
|
+
}),
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (
|
|
84
|
+
options.provider &&
|
|
85
|
+
"synced" in options.provider &&
|
|
86
|
+
typeof options.provider.synced === "boolean"
|
|
87
|
+
) {
|
|
88
|
+
if (options.provider["synced"]) {
|
|
89
|
+
configure();
|
|
90
|
+
} else if (
|
|
91
|
+
"on" in options.provider &&
|
|
92
|
+
typeof options.provider.on === "function"
|
|
93
|
+
) {
|
|
94
|
+
options.provider.on("synced", (synced: boolean) => {
|
|
95
|
+
if (synced) {
|
|
96
|
+
configure();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
throw new Error(
|
|
101
|
+
"YSyncExtension: provider must have a 'synced' boolean or an 'on' method to listen for 'sync'",
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
configure();
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
prosemirrorPlugins: [
|
|
109
|
+
syncPlugin({
|
|
110
|
+
suggestionDoc: options.suggestionDoc,
|
|
111
|
+
mapAttributionToMark,
|
|
112
|
+
// Node-pairing policy for the PM->Y diff: a `blockContainer` whose
|
|
113
|
+
// block-content type changes is treated as a *different* node, so the
|
|
114
|
+
// diff replaces the whole container (deleted + inserted siblings in
|
|
115
|
+
// the blockGroup) instead of producing two block-contents in one
|
|
116
|
+
// container => schema-invalid. No schema change / storage transform
|
|
117
|
+
// needed; `blockContainer` already whitelists the `y-attributed-*`
|
|
118
|
+
// marks. See blockMatchNodes.ts.
|
|
119
|
+
customCompare: blockMatchNodes,
|
|
120
|
+
}),
|
|
121
|
+
],
|
|
122
|
+
runsBefore: ["default"],
|
|
123
|
+
} as const;
|
|
124
|
+
},
|
|
125
|
+
);
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { $prosemirrorDelta } from "@y/prosemirror";
|
|
2
|
+
import * as delta from "lib0/delta";
|
|
3
|
+
import * as schema from "lib0/schema";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Canonical name of a content delta's first block child (the child carried by an
|
|
7
|
+
* insert op), or `null`. For a BlockNote `blockContainer` (content
|
|
8
|
+
* `blockContent blockGroup?`) this is its block-content type (paragraph,
|
|
9
|
+
* heading, image, ...).
|
|
10
|
+
*/
|
|
11
|
+
const firstChild = (
|
|
12
|
+
d: schema.Unwrap<typeof $prosemirrorDelta>,
|
|
13
|
+
): schema.Unwrap<typeof $prosemirrorDelta> | null => {
|
|
14
|
+
for (const op of (d as any).children) {
|
|
15
|
+
if (delta.$insertOp.check(op)) {
|
|
16
|
+
for (const it of op.insert) {
|
|
17
|
+
if (delta.$deltaAny.check(it)) {
|
|
18
|
+
return it;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Whether a `blockContainer` delta carries a child `blockGroup` — i.e. the block
|
|
28
|
+
* has nested children. A container's content is `blockContent blockGroup?`, so
|
|
29
|
+
* this is what tells a leaf block apart from a parent.
|
|
30
|
+
*/
|
|
31
|
+
const hasBlockGroup = (d: schema.Unwrap<typeof $prosemirrorDelta>): boolean => {
|
|
32
|
+
for (const op of (d as any).children) {
|
|
33
|
+
if (delta.$insertOp.check(op)) {
|
|
34
|
+
for (const it of op.insert) {
|
|
35
|
+
if (delta.$deltaAny.check(it) && it.name === "blockGroup") {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function getTableDimensions(
|
|
45
|
+
d: schema.Unwrap<typeof $prosemirrorDelta>,
|
|
46
|
+
): { rows: number; cols: number } | null {
|
|
47
|
+
if (d.name !== "table") {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Collect all rows with their cells' colspan/rowspan values.
|
|
52
|
+
const rows: Array<Array<{ colspan: number; rowspan: number }>> = [];
|
|
53
|
+
for (const op of (d as any).children) {
|
|
54
|
+
if (delta.$insertOp.check(op)) {
|
|
55
|
+
for (const tr of op.insert as Array<
|
|
56
|
+
schema.Unwrap<typeof $prosemirrorDelta>
|
|
57
|
+
>) {
|
|
58
|
+
if (tr.name !== "tableRow") {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const cells: Array<{ colspan: number; rowspan: number }> = [];
|
|
62
|
+
for (const trOp of (tr as any).children) {
|
|
63
|
+
if (delta.$insertOp.check(trOp)) {
|
|
64
|
+
for (const td of trOp.insert as Array<
|
|
65
|
+
schema.Unwrap<typeof $prosemirrorDelta>
|
|
66
|
+
>) {
|
|
67
|
+
if (td.name !== "tableCell" && td.name !== "tableHeader") {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
cells.push({
|
|
71
|
+
colspan: Number(td.attrs.colspan) || 1,
|
|
72
|
+
rowspan: Number(td.attrs.rowspan) || 1,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
rows.push(cells);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (rows.length === 0) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Build an occupancy grid to determine the true column count.
|
|
87
|
+
// Each entry in `grid[r]` tracks which columns are already occupied
|
|
88
|
+
// (by a cell from a previous row with rowspan > 1).
|
|
89
|
+
const grid: boolean[][] = [];
|
|
90
|
+
for (let r = 0; r < rows.length; r++) {
|
|
91
|
+
if (!grid[r]) {
|
|
92
|
+
grid[r] = [];
|
|
93
|
+
}
|
|
94
|
+
let col = 0;
|
|
95
|
+
for (const cell of rows[r]) {
|
|
96
|
+
// Skip columns already occupied by a rowspan from above.
|
|
97
|
+
while (grid[r][col]) {
|
|
98
|
+
col++;
|
|
99
|
+
}
|
|
100
|
+
// Mark all slots this cell occupies.
|
|
101
|
+
for (let dr = 0; dr < cell.rowspan; dr++) {
|
|
102
|
+
if (!grid[r + dr]) {
|
|
103
|
+
grid[r + dr] = [];
|
|
104
|
+
}
|
|
105
|
+
for (let dc = 0; dc < cell.colspan; dc++) {
|
|
106
|
+
grid[r + dr][col + dc] = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
col += cell.colspan;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const numCols = Math.max(...grid.map((row) => row.length));
|
|
114
|
+
return { rows: rows.length, cols: numCols };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* BlockNote's node-pairing policy for y-prosemirror's `matchNodes` option
|
|
119
|
+
* (forwarded to `lib0/delta.diff`). This is the schema-specific bit that lives
|
|
120
|
+
* in userland - the binding itself stays schema-agnostic.
|
|
121
|
+
*
|
|
122
|
+
* A `blockContainer` holds exactly one block content (`blockContent
|
|
123
|
+
* blockGroup?`). Diffing a *type change* of that content as an in-place child
|
|
124
|
+
* delete+insert would, under a suggestion, tombstone the old content next to the
|
|
125
|
+
* new one => two block-contents in one container => schema-invalid. So we
|
|
126
|
+
* declare a container's identity to be its first block-content child's type:
|
|
127
|
+
* when that changes, the two containers are reported as *different*, the PM->Y
|
|
128
|
+
* diff replaces the whole container, and the deleted + inserted containers sit
|
|
129
|
+
* as siblings in the blockGroup (`blockGroupChild+` allows that). Each carries
|
|
130
|
+
* the `y-attributed-*` node mark - which `blockContainer` already whitelists -
|
|
131
|
+
* so no schema change and no storage transform are needed. A plain text edit
|
|
132
|
+
* keeps the same first-child type => same identity => the diff descends and
|
|
133
|
+
* merges as usual.
|
|
134
|
+
*
|
|
135
|
+
* @param a removed (old) node
|
|
136
|
+
* @param b inserted (new) node
|
|
137
|
+
* @returns whether `a` and `b` are the same node (diff in place) vs different (replace)
|
|
138
|
+
*/
|
|
139
|
+
export const blockMatchNodes = (
|
|
140
|
+
a: schema.Unwrap<typeof $prosemirrorDelta>,
|
|
141
|
+
b: schema.Unwrap<typeof $prosemirrorDelta>,
|
|
142
|
+
): boolean => {
|
|
143
|
+
if (a.name !== b.name) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (a.name !== "blockContainer") {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const childA = firstChild(a);
|
|
152
|
+
const childB = firstChild(b);
|
|
153
|
+
|
|
154
|
+
if (childA?.name !== childB?.name) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// A change in nesting is structural too: if one container gains or loses a
|
|
159
|
+
// child `blockGroup`, diffing it in place would insert/delete the blockGroup as
|
|
160
|
+
// a sibling of the block content inside a single container — schema-invalid.
|
|
161
|
+
// Treat it as different so the whole container is replaced instead, same as a
|
|
162
|
+
// content-type change. Keeps concurrent nesting merges (e.g. two users nesting
|
|
163
|
+
// a block under the same parent) from producing a lopsided in-place result.
|
|
164
|
+
if (hasBlockGroup(a) !== hasBlockGroup(b)) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (childA?.name === "table" && childB?.name === "table") {
|
|
169
|
+
const dimA = getTableDimensions(childA);
|
|
170
|
+
const dimB = getTableDimensions(childB);
|
|
171
|
+
if (
|
|
172
|
+
dimA !== null &&
|
|
173
|
+
dimB !== null &&
|
|
174
|
+
dimA.rows !== dimB.rows &&
|
|
175
|
+
dimA.cols !== dimB.cols
|
|
176
|
+
) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return true;
|
|
182
|
+
};
|