@blocknote/core 0.51.4 → 0.52.1
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,166 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import {
|
|
3
|
+
absolutePositionToRelativePosition,
|
|
4
|
+
ySyncPluginKey,
|
|
5
|
+
} from "y-prosemirror";
|
|
6
|
+
import type { CommentBody } from "../../comments/types.js";
|
|
7
|
+
import type { ThreadStoreAuth } from "../../comments/threadstore/ThreadStoreAuth.js";
|
|
8
|
+
import { YjsThreadStoreBase } from "./YjsThreadStoreBase.js";
|
|
9
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This is a REST-based implementation of the YjsThreadStoreBase.
|
|
13
|
+
* It Reads data directly from the underlying document (same as YjsThreadStore),
|
|
14
|
+
* but for Writes, it sends data to a REST API that should:
|
|
15
|
+
* - check the user has the correct permissions to make the desired changes
|
|
16
|
+
* - apply the updates to the underlying Yjs document
|
|
17
|
+
*
|
|
18
|
+
* (see https://github.com/TypeCellOS/BlockNote-demo-nextjs-hocuspocus)
|
|
19
|
+
*
|
|
20
|
+
* The reason we still use the Yjs document as underlying storage is that it makes it easy to
|
|
21
|
+
* sync updates in real-time to other collaborators.
|
|
22
|
+
* (but technically, you could also implement a different storage altogether
|
|
23
|
+
* and not store the thread related data in the Yjs document)
|
|
24
|
+
*/
|
|
25
|
+
export class RESTYjsThreadStore extends YjsThreadStoreBase {
|
|
26
|
+
constructor(
|
|
27
|
+
private readonly BASE_URL: string,
|
|
28
|
+
private readonly headers: Record<string, string>,
|
|
29
|
+
threadsYMap: Y.Map<any>,
|
|
30
|
+
auth: ThreadStoreAuth,
|
|
31
|
+
) {
|
|
32
|
+
super(threadsYMap, auth);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private doRequest = async (path: string, method: string, body?: any) => {
|
|
36
|
+
const response = await fetch(`${this.BASE_URL}${path}`, {
|
|
37
|
+
method,
|
|
38
|
+
body: JSON.stringify(body),
|
|
39
|
+
headers: {
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
...this.headers,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new Error(`Failed to ${method} ${path}: ${response.statusText}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return response.json();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
public addThreadToDocument = async (options: {
|
|
53
|
+
threadId: string;
|
|
54
|
+
selection: {
|
|
55
|
+
head: number;
|
|
56
|
+
anchor: number;
|
|
57
|
+
};
|
|
58
|
+
editor: BlockNoteEditor<any, any, any>;
|
|
59
|
+
}) => {
|
|
60
|
+
const { threadId, selection } = options;
|
|
61
|
+
|
|
62
|
+
const binding = ySyncPluginKey.getState(options.editor.prosemirrorState);
|
|
63
|
+
const yjsSelection = binding
|
|
64
|
+
? {
|
|
65
|
+
head: absolutePositionToRelativePosition(
|
|
66
|
+
selection.head,
|
|
67
|
+
binding.type,
|
|
68
|
+
binding.mapping,
|
|
69
|
+
),
|
|
70
|
+
anchor: absolutePositionToRelativePosition(
|
|
71
|
+
selection.anchor,
|
|
72
|
+
binding.type,
|
|
73
|
+
binding.mapping,
|
|
74
|
+
),
|
|
75
|
+
}
|
|
76
|
+
: undefined;
|
|
77
|
+
|
|
78
|
+
return this.doRequest(`/${threadId}/addToDocument`, "POST", {
|
|
79
|
+
selection: {
|
|
80
|
+
prosemirror: selection,
|
|
81
|
+
yjs: yjsSelection,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
public createThread = async (options: {
|
|
87
|
+
initialComment: {
|
|
88
|
+
body: CommentBody;
|
|
89
|
+
metadata?: any;
|
|
90
|
+
};
|
|
91
|
+
metadata?: any;
|
|
92
|
+
}) => {
|
|
93
|
+
return this.doRequest("", "POST", options);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
public addComment = (options: {
|
|
97
|
+
comment: {
|
|
98
|
+
body: CommentBody;
|
|
99
|
+
metadata?: any;
|
|
100
|
+
};
|
|
101
|
+
threadId: string;
|
|
102
|
+
}) => {
|
|
103
|
+
const { threadId, ...rest } = options;
|
|
104
|
+
return this.doRequest(`/${threadId}/comments`, "POST", rest);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
public updateComment = (options: {
|
|
108
|
+
comment: {
|
|
109
|
+
body: CommentBody;
|
|
110
|
+
metadata?: any;
|
|
111
|
+
};
|
|
112
|
+
threadId: string;
|
|
113
|
+
commentId: string;
|
|
114
|
+
}) => {
|
|
115
|
+
const { threadId, commentId, ...rest } = options;
|
|
116
|
+
return this.doRequest(`/${threadId}/comments/${commentId}`, "PUT", rest);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
public deleteComment = (options: {
|
|
120
|
+
threadId: string;
|
|
121
|
+
commentId: string;
|
|
122
|
+
softDelete?: boolean;
|
|
123
|
+
}) => {
|
|
124
|
+
const { threadId, commentId, ...rest } = options;
|
|
125
|
+
return this.doRequest(
|
|
126
|
+
`/${threadId}/comments/${commentId}?soft=${!!rest.softDelete}`,
|
|
127
|
+
"DELETE",
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
public deleteThread = (options: { threadId: string }) => {
|
|
132
|
+
return this.doRequest(`/${options.threadId}`, "DELETE");
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
public resolveThread = (options: { threadId: string }) => {
|
|
136
|
+
return this.doRequest(`/${options.threadId}/resolve`, "POST");
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
public unresolveThread = (options: { threadId: string }) => {
|
|
140
|
+
return this.doRequest(`/${options.threadId}/unresolve`, "POST");
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
public addReaction = (options: {
|
|
144
|
+
threadId: string;
|
|
145
|
+
commentId: string;
|
|
146
|
+
emoji: string;
|
|
147
|
+
}) => {
|
|
148
|
+
const { threadId, commentId, ...rest } = options;
|
|
149
|
+
return this.doRequest(
|
|
150
|
+
`/${threadId}/comments/${commentId}/reactions`,
|
|
151
|
+
"POST",
|
|
152
|
+
rest,
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
public deleteReaction = (options: {
|
|
157
|
+
threadId: string;
|
|
158
|
+
commentId: string;
|
|
159
|
+
emoji: string;
|
|
160
|
+
}) => {
|
|
161
|
+
return this.doRequest(
|
|
162
|
+
`/${options.threadId}/comments/${options.commentId}/reactions/${options.emoji}`,
|
|
163
|
+
"DELETE",
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
|
|
2
2
|
import * as Y from "yjs";
|
|
3
|
-
import { CommentBody } from "../../types.js";
|
|
4
|
-
import { DefaultThreadStoreAuth } from "
|
|
3
|
+
import type { CommentBody } from "../../comments/types.js";
|
|
4
|
+
import { DefaultThreadStoreAuth } from "../../comments/threadstore/DefaultThreadStoreAuth.js";
|
|
5
5
|
import { YjsThreadStore } from "./YjsThreadStore.js";
|
|
6
6
|
|
|
7
7
|
// Mock UUID to generate sequential IDs
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { uuidv4 } from "lib0/random";
|
|
2
1
|
import * as Y from "yjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { uuidv4 } from "lib0/random";
|
|
3
|
+
import type {
|
|
4
|
+
CommentBody,
|
|
5
|
+
CommentData,
|
|
6
|
+
ThreadData,
|
|
7
|
+
} from "../../comments/types.js";
|
|
8
|
+
import type { ThreadStoreAuth } from "../../comments/threadstore/ThreadStoreAuth.js";
|
|
5
9
|
import { YjsThreadStoreBase } from "./YjsThreadStoreBase.js";
|
|
6
10
|
import {
|
|
7
11
|
commentToYMap,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Y from "yjs";
|
|
2
|
-
import { ThreadData } from "../../types.js";
|
|
3
|
-
import { ThreadStore } from "
|
|
4
|
-
import { ThreadStoreAuth } from "
|
|
2
|
+
import type { ThreadData } from "../../comments/types.js";
|
|
3
|
+
import { ThreadStore } from "../../comments/threadstore/ThreadStore.js";
|
|
4
|
+
import type { ThreadStoreAuth } from "../../comments/threadstore/ThreadStoreAuth.js";
|
|
5
5
|
import { yMapToThread } from "./yjsHelpers.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as Y from "yjs";
|
|
2
|
-
import {
|
|
2
|
+
import type {
|
|
3
|
+
CommentData,
|
|
4
|
+
CommentReactionData,
|
|
5
|
+
ThreadData,
|
|
6
|
+
} from "../../comments/types.js";
|
|
3
7
|
|
|
4
8
|
export function commentToYMap(comment: CommentData) {
|
|
5
9
|
const yMap = new Y.Map<any>();
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
2
|
+
import * as Y from "yjs";
|
|
3
|
+
|
|
4
|
+
import { BlockNoteSchema } from "../../blocks/BlockNoteSchema.js";
|
|
5
|
+
import { defaultBlockSpecs } from "../../blocks/defaultBlocks.js";
|
|
6
|
+
import { CommentsExtension } from "../../comments/extension.js";
|
|
7
|
+
import { DefaultThreadStoreAuth } from "../../comments/threadstore/DefaultThreadStoreAuth.js";
|
|
8
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
9
|
+
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
|
|
10
|
+
import { YAttributionMarksExtension } from "../../y/extensions/YAttributionMarks.js";
|
|
11
|
+
import { YjsThreadStore } from "../comments/YjsThreadStore.js";
|
|
12
|
+
import { withCollaboration } from "../index.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @vitest-environment jsdom
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// These tests cover the mark-dropping part of `FixUpSchemaExtension`, which lets
|
|
19
|
+
// a document survive a block whose content type changed from `"inline"` (marks allowed)
|
|
20
|
+
// to `"plain"` (only the `"annotation"` group allowed). The key behaviour: the
|
|
21
|
+
// disallowed marks REMAIN in the Yjs fragment (we never mutate the Yjs doc), but
|
|
22
|
+
// they are NOT materialized into ProseMirror — so the block is not deleted and
|
|
23
|
+
// its text is preserved. Everything is exercised end-to-end through a real
|
|
24
|
+
// collaborative editor, i.e. through y-prosemirror's actual reconstruction path
|
|
25
|
+
// (`schema.node` -> `createChecked`) that would otherwise delete the block.
|
|
26
|
+
|
|
27
|
+
// A "legacy" schema where the code block holds inline content — i.e. the schema
|
|
28
|
+
// from BEFORE the migration to "plain", where a code block could carry
|
|
29
|
+
// formatting marks. Used to produce fixtures via a real editor so that marks
|
|
30
|
+
// are encoded in Yjs exactly as y-prosemirror encodes them (rather than by
|
|
31
|
+
// hand, which could assume the wrong attribute names).
|
|
32
|
+
const legacySchema = BlockNoteSchema.create({
|
|
33
|
+
blockSpecs: {
|
|
34
|
+
...defaultBlockSpecs,
|
|
35
|
+
codeBlock: createBlockSpec(
|
|
36
|
+
createBlockConfig(() => ({
|
|
37
|
+
type: "codeBlock" as const,
|
|
38
|
+
propSchema: { language: { default: "" } },
|
|
39
|
+
content: "inline" as const,
|
|
40
|
+
})),
|
|
41
|
+
{
|
|
42
|
+
render: () => {
|
|
43
|
+
const dom = document.createElement("pre");
|
|
44
|
+
const code = document.createElement("code");
|
|
45
|
+
dom.append(code);
|
|
46
|
+
return { dom, contentDOM: code };
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
)(),
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const createThreadStore = (ydoc: Y.Doc) =>
|
|
54
|
+
new YjsThreadStore(
|
|
55
|
+
"test-user",
|
|
56
|
+
ydoc.getMap("threads"),
|
|
57
|
+
new DefaultThreadStoreAuth("test-user", "editor"),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// Mounts a real collaborative editor on the legacy schema (code block = inline,
|
|
61
|
+
// so it allows marks), seeded with a bold-formatted code block. Returns the
|
|
62
|
+
// editor (typed loosely, since it doesn't use the default schema) so callers can
|
|
63
|
+
// apply extra marks before destroying it. Marks therefore land in Yjs exactly
|
|
64
|
+
// the way y-prosemirror writes them.
|
|
65
|
+
const createLegacyEditor = (
|
|
66
|
+
fragment: Y.XmlFragment,
|
|
67
|
+
opts: { threadStore?: YjsThreadStore } = {},
|
|
68
|
+
) => {
|
|
69
|
+
const editor = BlockNoteEditor.create(
|
|
70
|
+
withCollaboration({
|
|
71
|
+
collaboration: {
|
|
72
|
+
fragment,
|
|
73
|
+
user: { color: "#0000ff", name: "Legacy User" },
|
|
74
|
+
provider: undefined,
|
|
75
|
+
},
|
|
76
|
+
schema: legacySchema,
|
|
77
|
+
// Register the Yjs attribution marks — they're the annotation mark
|
|
78
|
+
// reachable from core (the AI suggestion marks live in xl-ai), so they
|
|
79
|
+
// stand in for the `"annotation"` group here and let the plain code block
|
|
80
|
+
// keep them while dropping formatting.
|
|
81
|
+
extensions: [
|
|
82
|
+
YAttributionMarksExtension(),
|
|
83
|
+
...(opts.threadStore
|
|
84
|
+
? [
|
|
85
|
+
CommentsExtension({
|
|
86
|
+
threadStore: opts.threadStore,
|
|
87
|
+
resolveUsers: async () => [],
|
|
88
|
+
}),
|
|
89
|
+
]
|
|
90
|
+
: []),
|
|
91
|
+
],
|
|
92
|
+
}) as Parameters<typeof BlockNoteEditor.create>[0],
|
|
93
|
+
) as unknown as BlockNoteEditor<any, any, any>;
|
|
94
|
+
editor.mount(document.createElement("div"));
|
|
95
|
+
editor.replaceBlocks(editor.document, [
|
|
96
|
+
{
|
|
97
|
+
type: "codeBlock",
|
|
98
|
+
props: { language: "javascript" },
|
|
99
|
+
content: [{ type: "text", text: "const x = 1;", styles: { bold: true } }],
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
102
|
+
return editor;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Populates `fragment` with a bold-formatted code block (optionally also a
|
|
106
|
+
// suggestion / `y-attributed-insert` mark).
|
|
107
|
+
const buildLegacyFormattedCodeBlock = (
|
|
108
|
+
fragment: Y.XmlFragment,
|
|
109
|
+
opts: { withSuggestion?: boolean } = {},
|
|
110
|
+
) => {
|
|
111
|
+
const editor = createLegacyEditor(fragment);
|
|
112
|
+
if (opts.withSuggestion) {
|
|
113
|
+
editor.transact((tr) =>
|
|
114
|
+
tr.addMark(
|
|
115
|
+
0,
|
|
116
|
+
tr.doc.content.size,
|
|
117
|
+
editor.pmSchema.marks["y-attributed-insert"].create({
|
|
118
|
+
userIds: ["test-user"],
|
|
119
|
+
}),
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
editor._tiptapEditor.destroy();
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// Populates `ydoc` with a code block carrying a bold mark AND a real comment
|
|
127
|
+
// (created through the comment API, so the comment mark is encoded by
|
|
128
|
+
// y-prosemirror as `comment--<hash>`).
|
|
129
|
+
const buildLegacyCommentedCodeBlock = async (ydoc: Y.Doc) => {
|
|
130
|
+
const editor = createLegacyEditor(ydoc.getXmlFragment("doc"), {
|
|
131
|
+
threadStore: createThreadStore(ydoc),
|
|
132
|
+
});
|
|
133
|
+
(editor as any)._tiptapEditor.commands.selectAll();
|
|
134
|
+
await (editor.getExtension(CommentsExtension) as any).createThread({
|
|
135
|
+
initialComment: { body: "review this" },
|
|
136
|
+
});
|
|
137
|
+
editor._tiptapEditor.destroy();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const createCollabEditor = (
|
|
141
|
+
fragment: Y.XmlFragment,
|
|
142
|
+
opts: { threadStore?: YjsThreadStore } = {},
|
|
143
|
+
) => {
|
|
144
|
+
const editor = BlockNoteEditor.create(
|
|
145
|
+
withCollaboration({
|
|
146
|
+
collaboration: {
|
|
147
|
+
fragment,
|
|
148
|
+
user: { color: "#ff0000", name: "Test User" },
|
|
149
|
+
provider: undefined,
|
|
150
|
+
},
|
|
151
|
+
// Register the same annotation mark on the reconstructing editor, so it's
|
|
152
|
+
// allowed on the plain block and materialized rather than dropped.
|
|
153
|
+
extensions: [
|
|
154
|
+
YAttributionMarksExtension(),
|
|
155
|
+
...(opts.threadStore
|
|
156
|
+
? [
|
|
157
|
+
CommentsExtension({
|
|
158
|
+
threadStore: opts.threadStore,
|
|
159
|
+
resolveUsers: async () => [],
|
|
160
|
+
}),
|
|
161
|
+
]
|
|
162
|
+
: []),
|
|
163
|
+
],
|
|
164
|
+
}),
|
|
165
|
+
);
|
|
166
|
+
editor.mount(document.createElement("div"));
|
|
167
|
+
return editor;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// Collects every mark-attribute key present on a fragment's text.
|
|
171
|
+
const markKeysIn = (fragment: Y.XmlFragment) => {
|
|
172
|
+
const keys = new Set<string>();
|
|
173
|
+
const walk = (node: Y.AbstractType<any>) => {
|
|
174
|
+
if (node instanceof Y.XmlText) {
|
|
175
|
+
for (const op of node.toDelta() as { attributes?: object }[]) {
|
|
176
|
+
if (op.attributes) {
|
|
177
|
+
Object.keys(op.attributes).forEach((k) => keys.add(k));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
} else if (node instanceof Y.XmlElement || node instanceof Y.XmlFragment) {
|
|
181
|
+
node.toArray().forEach(walk);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
fragment.toArray().forEach(walk);
|
|
185
|
+
return keys;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// Collects the style keys present on a block's inline content (empty for plain
|
|
189
|
+
// text). A materialized formatting mark would show up here.
|
|
190
|
+
const styleKeysOf = (block: any) => {
|
|
191
|
+
const keys = new Set<string>();
|
|
192
|
+
if (Array.isArray(block.content)) {
|
|
193
|
+
for (const inline of block.content) {
|
|
194
|
+
if (inline.styles) {
|
|
195
|
+
Object.keys(inline.styles).forEach((k) => keys.add(k));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return keys;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
describe("FixUpSchema: formatted code block backwards compatibility", () => {
|
|
203
|
+
it("preserves a formatted code block present before mount, dropping only the formatting", () => {
|
|
204
|
+
const doc = new Y.Doc();
|
|
205
|
+
const fragment = doc.getXmlFragment("doc");
|
|
206
|
+
buildLegacyFormattedCodeBlock(fragment);
|
|
207
|
+
|
|
208
|
+
// The fixture really does carry a bold mark, encoded by y-prosemirror.
|
|
209
|
+
expect(markKeysIn(fragment).has("bold")).toBe(true);
|
|
210
|
+
|
|
211
|
+
const editor = createCollabEditor(fragment);
|
|
212
|
+
|
|
213
|
+
// The block survives reconstruction with its text intact...
|
|
214
|
+
expect(editor.document.map((b) => b.type)).toEqual(["codeBlock"]);
|
|
215
|
+
expect(editor.document[0].content).toEqual([
|
|
216
|
+
{
|
|
217
|
+
styles: {},
|
|
218
|
+
text: "const x = 1;",
|
|
219
|
+
type: "text",
|
|
220
|
+
},
|
|
221
|
+
]);
|
|
222
|
+
// ...bold is NOT materialized into ProseMirror...
|
|
223
|
+
expect(styleKeysOf(editor.document[0]).has("bold")).toBe(false);
|
|
224
|
+
// ...but the mark is STILL in the Yjs fragment (we never mutate the Yjs doc).
|
|
225
|
+
expect(markKeysIn(fragment).has("bold")).toBe(true);
|
|
226
|
+
|
|
227
|
+
editor._tiptapEditor.destroy();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("preserves a formatted code block that syncs in after mount", () => {
|
|
231
|
+
const remoteDoc = new Y.Doc();
|
|
232
|
+
buildLegacyFormattedCodeBlock(remoteDoc.getXmlFragment("doc"));
|
|
233
|
+
|
|
234
|
+
const localDoc = new Y.Doc();
|
|
235
|
+
const localFragment = localDoc.getXmlFragment("doc");
|
|
236
|
+
|
|
237
|
+
// Editor mounts on an empty fragment, before any content arrives.
|
|
238
|
+
const editor = createCollabEditor(localFragment);
|
|
239
|
+
expect(localFragment.toJSON()).toBe("");
|
|
240
|
+
|
|
241
|
+
// Provider delivers the initial state after mount.
|
|
242
|
+
Y.applyUpdate(localDoc, Y.encodeStateAsUpdate(remoteDoc));
|
|
243
|
+
|
|
244
|
+
// The code block survives in the editor...
|
|
245
|
+
expect(editor.document.map((b) => b.type)).toEqual(["codeBlock"]);
|
|
246
|
+
expect(editor.document[0].content).toEqual([
|
|
247
|
+
{
|
|
248
|
+
styles: {},
|
|
249
|
+
text: "const x = 1;",
|
|
250
|
+
type: "text",
|
|
251
|
+
},
|
|
252
|
+
]);
|
|
253
|
+
// ...and in the Yjs fragment — i.e. it was NOT deleted (which would
|
|
254
|
+
// otherwise propagate the deletion back to every peer)...
|
|
255
|
+
expect(localFragment.toJSON()).toContain("const x = 1;");
|
|
256
|
+
// ...with its formatting not materialized into ProseMirror...
|
|
257
|
+
expect(styleKeysOf(editor.document[0]).has("bold")).toBe(false);
|
|
258
|
+
// ...but the bold mark still present in the fragment (left in Yjs).
|
|
259
|
+
expect(markKeysIn(localFragment).has("bold")).toBe(true);
|
|
260
|
+
|
|
261
|
+
editor._tiptapEditor.destroy();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("keeps the reconstructed block editable (leftover marks don't break positions)", () => {
|
|
265
|
+
const doc = new Y.Doc();
|
|
266
|
+
const fragment = doc.getXmlFragment("doc");
|
|
267
|
+
buildLegacyFormattedCodeBlock(fragment);
|
|
268
|
+
|
|
269
|
+
const editor = createCollabEditor(fragment);
|
|
270
|
+
const block = editor.document[0];
|
|
271
|
+
expect(block.content).toEqual([
|
|
272
|
+
{
|
|
273
|
+
styles: {},
|
|
274
|
+
text: "const x = 1;",
|
|
275
|
+
type: "text",
|
|
276
|
+
},
|
|
277
|
+
]);
|
|
278
|
+
|
|
279
|
+
// Editing the reconstructed block applies cleanly despite the leftover bold
|
|
280
|
+
// mark still living in the Yjs fragment.
|
|
281
|
+
editor.updateBlock(block, { content: "const x = 2;" });
|
|
282
|
+
|
|
283
|
+
expect(editor.document.map((b) => b.type)).toEqual(["codeBlock"]);
|
|
284
|
+
expect(editor.document[0].content).toEqual([
|
|
285
|
+
{
|
|
286
|
+
styles: {},
|
|
287
|
+
text: "const x = 2;",
|
|
288
|
+
type: "text",
|
|
289
|
+
},
|
|
290
|
+
]);
|
|
291
|
+
// Still no materialized formatting after the edit.
|
|
292
|
+
expect(styleKeysOf(editor.document[0]).has("bold")).toBe(false);
|
|
293
|
+
|
|
294
|
+
editor._tiptapEditor.destroy();
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("keeps suggestion (y-attributed-insert) marks while dropping formatting", () => {
|
|
298
|
+
const doc = new Y.Doc();
|
|
299
|
+
const fragment = doc.getXmlFragment("doc");
|
|
300
|
+
buildLegacyFormattedCodeBlock(fragment, { withSuggestion: true });
|
|
301
|
+
|
|
302
|
+
const before = markKeysIn(fragment);
|
|
303
|
+
expect(before.has("bold")).toBe(true);
|
|
304
|
+
// y-prosemirror encodes a mark that carries attributes with a hash suffix
|
|
305
|
+
// (e.g. `y-attributed-insert--<hash>`).
|
|
306
|
+
expect([...before].some((k) => k.startsWith("y-attributed-insert"))).toBe(
|
|
307
|
+
true,
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
const editor = createCollabEditor(fragment);
|
|
311
|
+
|
|
312
|
+
// Block survives with text intact.
|
|
313
|
+
expect(editor.document.map((b) => b.type)).toEqual(["codeBlock"]);
|
|
314
|
+
expect(editor.document[0].content).toEqual([
|
|
315
|
+
{
|
|
316
|
+
styles: {},
|
|
317
|
+
text: "const x = 1;",
|
|
318
|
+
type: "text",
|
|
319
|
+
},
|
|
320
|
+
]);
|
|
321
|
+
|
|
322
|
+
const after = markKeysIn(fragment);
|
|
323
|
+
// Formatting left in Yjs but not materialized; suggestion (allowed) kept.
|
|
324
|
+
expect(after.has("bold")).toBe(true);
|
|
325
|
+
expect([...after].some((k) => k.startsWith("y-attributed-insert"))).toBe(
|
|
326
|
+
true,
|
|
327
|
+
);
|
|
328
|
+
expect(styleKeysOf(editor.document[0]).has("bold")).toBe(false);
|
|
329
|
+
|
|
330
|
+
editor._tiptapEditor.destroy();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it("keeps a real comment mark (encoded as comment--<hash>) while dropping formatting", async () => {
|
|
334
|
+
const ydoc = new Y.Doc();
|
|
335
|
+
await buildLegacyCommentedCodeBlock(ydoc);
|
|
336
|
+
const fragment = ydoc.getXmlFragment("doc");
|
|
337
|
+
|
|
338
|
+
// The comment mark is stored under a hashed key, not just "comment".
|
|
339
|
+
const before = markKeysIn(fragment);
|
|
340
|
+
expect(before.has("bold")).toBe(true);
|
|
341
|
+
expect([...before].some((k) => k.startsWith("comment--"))).toBe(true);
|
|
342
|
+
|
|
343
|
+
// Mount a comments-configured collab editor on the same doc, so the comment
|
|
344
|
+
// mark exists in the schema and is allowed on the (plain) code block.
|
|
345
|
+
const editor = createCollabEditor(fragment, {
|
|
346
|
+
threadStore: createThreadStore(ydoc),
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Block survives with text intact.
|
|
350
|
+
expect(editor.document.map((b) => b.type)).toEqual(["codeBlock"]);
|
|
351
|
+
expect(editor.document[0].content).toEqual([
|
|
352
|
+
{
|
|
353
|
+
styles: {},
|
|
354
|
+
text: "const x = 1;",
|
|
355
|
+
type: "text",
|
|
356
|
+
},
|
|
357
|
+
]);
|
|
358
|
+
|
|
359
|
+
const after = markKeysIn(fragment);
|
|
360
|
+
// The hashed comment mark is kept (allowed); bold left in Yjs but not
|
|
361
|
+
// materialized as formatting.
|
|
362
|
+
expect([...after].some((k) => k.startsWith("comment--"))).toBe(true);
|
|
363
|
+
expect(after.has("bold")).toBe(true);
|
|
364
|
+
expect(styleKeysOf(editor.document[0]).has("bold")).toBe(false);
|
|
365
|
+
|
|
366
|
+
editor._tiptapEditor.destroy();
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it("leaves an already-clean code block untouched (no-op for valid content)", () => {
|
|
370
|
+
const doc = new Y.Doc();
|
|
371
|
+
const fragment = doc.getXmlFragment("doc");
|
|
372
|
+
// A plain code block produced by the current schema (no disallowed marks).
|
|
373
|
+
const seedEditor = createCollabEditor(fragment);
|
|
374
|
+
seedEditor.replaceBlocks(seedEditor.document, [
|
|
375
|
+
{ type: "codeBlock", content: "const x = 1;" },
|
|
376
|
+
]);
|
|
377
|
+
const before = fragment.toJSON();
|
|
378
|
+
seedEditor._tiptapEditor.destroy();
|
|
379
|
+
|
|
380
|
+
// Reconstruct it in a fresh collab editor: the override is a no-op, so the
|
|
381
|
+
// fragment is byte-for-byte unchanged.
|
|
382
|
+
const editor = createCollabEditor(fragment);
|
|
383
|
+
expect(editor.document.map((b) => b.type)).toEqual(["codeBlock"]);
|
|
384
|
+
expect(editor.document[0].content).toEqual([
|
|
385
|
+
{
|
|
386
|
+
styles: {},
|
|
387
|
+
text: "const x = 1;",
|
|
388
|
+
type: "text",
|
|
389
|
+
},
|
|
390
|
+
]);
|
|
391
|
+
expect(fragment.toJSON()).toBe(before);
|
|
392
|
+
|
|
393
|
+
editor._tiptapEditor.destroy();
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("does not touch inline blocks: a bold paragraph keeps its formatting", () => {
|
|
397
|
+
const doc = new Y.Doc();
|
|
398
|
+
const fragment = doc.getXmlFragment("doc");
|
|
399
|
+
|
|
400
|
+
// A paragraph is "inline" content, so bold is allowed and should survive
|
|
401
|
+
// reconstruction untouched — the override is scoped to plain blocks.
|
|
402
|
+
const seedEditor = createCollabEditor(fragment);
|
|
403
|
+
seedEditor.replaceBlocks(seedEditor.document, [
|
|
404
|
+
{
|
|
405
|
+
type: "paragraph",
|
|
406
|
+
content: [{ type: "text", text: "hello", styles: { bold: true } }],
|
|
407
|
+
},
|
|
408
|
+
]);
|
|
409
|
+
const before = fragment.toJSON();
|
|
410
|
+
seedEditor._tiptapEditor.destroy();
|
|
411
|
+
|
|
412
|
+
const editor = createCollabEditor(fragment);
|
|
413
|
+
expect(editor.document.map((b) => b.type)).toEqual(["paragraph"]);
|
|
414
|
+
// Bold is materialized (kept) on the inline block.
|
|
415
|
+
expect(styleKeysOf(editor.document[0]).has("bold")).toBe(true);
|
|
416
|
+
// And the fragment is unchanged (override was a no-op for this node).
|
|
417
|
+
expect(fragment.toJSON()).toBe(before);
|
|
418
|
+
|
|
419
|
+
editor._tiptapEditor.destroy();
|
|
420
|
+
});
|
|
421
|
+
});
|