@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
package/dist/yjs.js
CHANGED
|
@@ -1,26 +1,547 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { On as e, jt as t, vn as n, vt as r } from "./blocks-CiuUGa1E.js";
|
|
2
|
+
import { n as i, t as a } from "./BlockNoteExtension-B_IEJHS8.js";
|
|
3
|
+
import { t as o } from "./ThreadStore-et9wB5Xt.js";
|
|
4
|
+
import { Node as s } from "prosemirror-model";
|
|
5
|
+
import { uuidv4 as c } from "lib0/random";
|
|
6
|
+
import { Plugin as l, PluginKey as u } from "@tiptap/pm/state";
|
|
7
|
+
import { absolutePositionToRelativePosition as d, defaultSelectionBuilder as f, prosemirrorToYDoc as p, prosemirrorToYXmlFragment as m, redoCommand as h, relativePositionToAbsolutePosition as g, undoCommand as _, yCursorPlugin as v, ySyncPlugin as y, ySyncPluginKey as b, yUndoPlugin as ee, yUndoPluginKey as x, yXmlFragmentToProseMirrorRootNode as S } from "y-prosemirror";
|
|
8
|
+
import * as C from "yjs";
|
|
3
9
|
//#region src/yjs/utils.ts
|
|
4
|
-
function
|
|
5
|
-
|
|
10
|
+
function w(e, t) {
|
|
11
|
+
let n = e.doc;
|
|
12
|
+
if (!n) throw Error("type does not have a ydoc");
|
|
13
|
+
if (e._item === null) {
|
|
14
|
+
let r = Array.from(n.share.keys()).find((t) => n.share.get(t) === e);
|
|
15
|
+
if (r == null) throw Error("type does not exist in other ydoc");
|
|
16
|
+
return t.get(r, e.constructor);
|
|
17
|
+
} else {
|
|
18
|
+
let n = e._item, r = t.store.clients.get(n.id.client) ?? [], i = r[C.findIndexSS(r, n.id.clock)];
|
|
19
|
+
if (!i) throw Error("type does not exist in other ydoc");
|
|
20
|
+
let a = i.content;
|
|
21
|
+
if (!a) throw Error("type does not exist in other ydoc");
|
|
22
|
+
return a.type;
|
|
23
|
+
}
|
|
6
24
|
}
|
|
7
|
-
function
|
|
25
|
+
function T(e, t) {
|
|
26
|
+
return n(e.pmSchema.nodeFromJSON(t));
|
|
27
|
+
}
|
|
28
|
+
function E(e, n) {
|
|
8
29
|
let r = n.map((n) => t(n, e.pmSchema));
|
|
9
30
|
return e.pmSchema.topNodeType.create(null, e.pmSchema.nodes.blockGroup.create(null, r));
|
|
10
31
|
}
|
|
11
|
-
function
|
|
12
|
-
return
|
|
32
|
+
function D(e, t) {
|
|
33
|
+
return n(S(t, e.pmSchema));
|
|
34
|
+
}
|
|
35
|
+
function O(e, t, n) {
|
|
36
|
+
return m(E(e, t), n);
|
|
37
|
+
}
|
|
38
|
+
function k(e, t, n = "prosemirror") {
|
|
39
|
+
return D(e, t.getXmlFragment(n));
|
|
40
|
+
}
|
|
41
|
+
function A(e, t, n = "prosemirror") {
|
|
42
|
+
return p(E(e, t), n);
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/yjs/extensions/FixUpSchema.ts
|
|
46
|
+
var j = a(({ editor: t }) => (t.on("create", () => {
|
|
47
|
+
let n = t.pmSchema, r, i = n.nodes.doc.createAndFill;
|
|
48
|
+
n.nodes.doc.createAndFill = ((...e) => {
|
|
49
|
+
if (r) return r;
|
|
50
|
+
let t = i.apply(n.nodes.doc, e), a = JSON.parse(JSON.stringify(t.toJSON()));
|
|
51
|
+
return a.content[0].content[0].attrs.id = "initialBlockId", r = s.fromJSON(n, a), r;
|
|
52
|
+
});
|
|
53
|
+
let a = n.node;
|
|
54
|
+
n.node = function(t, n, r, i) {
|
|
55
|
+
let o = typeof t == "string" ? this.nodes[t] : t;
|
|
56
|
+
return o && e(this, o) && Array.isArray(r) && (r = r.map((e) => e?.isText && e.marks.length ? e.mark(o.allowedMarks(e.marks)) : e)), a.call(this, t, n, r, i);
|
|
57
|
+
};
|
|
58
|
+
}), { key: "fixUpSchema" }));
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/yjs/extensions/YCursorPlugin.ts
|
|
61
|
+
function M(e) {
|
|
62
|
+
let t = e.charAt(0) === "#" ? e.substring(1, 7) : e, n = parseInt(t.substring(0, 2), 16), r = parseInt(t.substring(2, 4), 16), i = parseInt(t.substring(4, 6), 16), a = [
|
|
63
|
+
n / 255,
|
|
64
|
+
r / 255,
|
|
65
|
+
i / 255
|
|
66
|
+
].map((e) => e <= .03928 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4);
|
|
67
|
+
return .2126 * a[0] + .7152 * a[1] + .0722 * a[2] <= .179;
|
|
68
|
+
}
|
|
69
|
+
function N(e) {
|
|
70
|
+
let t = document.createElement("span");
|
|
71
|
+
t.classList.add("bn-collaboration-cursor__base");
|
|
72
|
+
let n = document.createElement("span");
|
|
73
|
+
n.setAttribute("contentedEditable", "false"), n.classList.add("bn-collaboration-cursor__caret"), n.setAttribute("style", `background-color: ${e.color}; color: ${M(e.color) ? "white" : "black"}`);
|
|
74
|
+
let r = document.createElement("span");
|
|
75
|
+
return r.classList.add("bn-collaboration-cursor__label"), r.setAttribute("style", `background-color: ${e.color}; color: ${M(e.color) ? "white" : "black"}`), r.insertBefore(document.createTextNode(e.name), null), n.insertBefore(r, null), t.insertBefore(document.createTextNode(""), null), t.insertBefore(n, null), t.insertBefore(document.createTextNode(""), null), t;
|
|
76
|
+
}
|
|
77
|
+
var P = a(({ options: e }) => {
|
|
78
|
+
let t = /* @__PURE__ */ new Map(), n = e.provider && "awareness" in e.provider && typeof e.provider.awareness == "object" ? e.provider.awareness : void 0;
|
|
79
|
+
n && "setLocalStateField" in n && typeof n.setLocalStateField == "function" && n.setLocalStateField("user", e.user);
|
|
80
|
+
let r = ({ updated: e }) => {
|
|
81
|
+
for (let n of e) {
|
|
82
|
+
let e = t.get(n);
|
|
83
|
+
e && (setTimeout(() => {
|
|
84
|
+
e.element.setAttribute("data-active", "");
|
|
85
|
+
}, 10), e.hideTimeout && clearTimeout(e.hideTimeout), t.set(n, {
|
|
86
|
+
element: e.element,
|
|
87
|
+
hideTimeout: setTimeout(() => {
|
|
88
|
+
e.element.removeAttribute("data-active");
|
|
89
|
+
}, 2e3)
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
key: "yCursor",
|
|
95
|
+
mount() {
|
|
96
|
+
if (n && e.showCursorLabels !== "always" && "on" in n && typeof n.on == "function") return n.on("change", r), () => {
|
|
97
|
+
"off" in n && typeof n.off == "function" && n.off("change", r);
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
prosemirrorPlugins: [n ? v(n, {
|
|
101
|
+
selectionBuilder: f,
|
|
102
|
+
cursorBuilder(n, r) {
|
|
103
|
+
let i = t.get(r);
|
|
104
|
+
if (!i) {
|
|
105
|
+
let a = (e.renderCursor ?? N)(n);
|
|
106
|
+
e.showCursorLabels !== "always" && (a.addEventListener("mouseenter", () => {
|
|
107
|
+
let e = t.get(r);
|
|
108
|
+
e.element.setAttribute("data-active", ""), e.hideTimeout && (clearTimeout(e.hideTimeout), t.set(r, {
|
|
109
|
+
element: e.element,
|
|
110
|
+
hideTimeout: void 0
|
|
111
|
+
}));
|
|
112
|
+
}), a.addEventListener("mouseleave", () => {
|
|
113
|
+
let e = t.get(r);
|
|
114
|
+
t.set(r, {
|
|
115
|
+
element: e.element,
|
|
116
|
+
hideTimeout: setTimeout(() => {
|
|
117
|
+
e.element.removeAttribute("data-active");
|
|
118
|
+
}, 2e3)
|
|
119
|
+
});
|
|
120
|
+
})), i = {
|
|
121
|
+
element: a,
|
|
122
|
+
hideTimeout: void 0
|
|
123
|
+
}, t.set(r, i);
|
|
124
|
+
}
|
|
125
|
+
return i.element;
|
|
126
|
+
}
|
|
127
|
+
}) : void 0].filter(Boolean),
|
|
128
|
+
dependsOn: ["ySync"],
|
|
129
|
+
updateUser(e) {
|
|
130
|
+
n?.setLocalStateField("user", e);
|
|
131
|
+
},
|
|
132
|
+
getUser() {
|
|
133
|
+
let e = n?.getLocalState();
|
|
134
|
+
if (e) return e.user;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}), F = a(({ options: e }) => ({
|
|
138
|
+
key: "ySync",
|
|
139
|
+
prosemirrorPlugins: [y(e.fragment)],
|
|
140
|
+
runsBefore: ["default"]
|
|
141
|
+
})), I = a(() => ({
|
|
142
|
+
key: "yUndo",
|
|
143
|
+
prosemirrorPlugins: [ee()],
|
|
144
|
+
dependsOn: ["yCursor", "ySync"],
|
|
145
|
+
undoCommand: _,
|
|
146
|
+
redoCommand: h
|
|
147
|
+
})), L = a(({ editor: e, options: t }) => {
|
|
148
|
+
let n, r = i({ isForked: !1 });
|
|
149
|
+
return {
|
|
150
|
+
key: "yForkDoc",
|
|
151
|
+
store: r,
|
|
152
|
+
fork({ initialUpdate: i } = {}) {
|
|
153
|
+
if (n) return;
|
|
154
|
+
let a = t.fragment;
|
|
155
|
+
if (!a) throw Error("No fragment to fork from");
|
|
156
|
+
let o = new C.Doc();
|
|
157
|
+
C.applyUpdate(o, i ?? C.encodeStateAsUpdate(a.doc));
|
|
158
|
+
let s = w(a, o);
|
|
159
|
+
n = {
|
|
160
|
+
undoStack: x.getState(e.prosemirrorState).undoManager.undoStack,
|
|
161
|
+
originalFragment: a,
|
|
162
|
+
forkedFragment: s
|
|
163
|
+
};
|
|
164
|
+
let c = {
|
|
165
|
+
...t,
|
|
166
|
+
fragment: s
|
|
167
|
+
};
|
|
168
|
+
e.replaceExtension([
|
|
169
|
+
"ySync",
|
|
170
|
+
"yCursor",
|
|
171
|
+
"yUndo"
|
|
172
|
+
], [F(c), I()]), r.setState({ isForked: !0 });
|
|
173
|
+
},
|
|
174
|
+
merge({ keepChanges: i }) {
|
|
175
|
+
if (!n) return;
|
|
176
|
+
let { originalFragment: a, forkedFragment: o, undoStack: s } = n;
|
|
177
|
+
if (e.replaceExtension([
|
|
178
|
+
"ySync",
|
|
179
|
+
"yCursor",
|
|
180
|
+
"yUndo"
|
|
181
|
+
], [
|
|
182
|
+
F(t),
|
|
183
|
+
P(t),
|
|
184
|
+
I()
|
|
185
|
+
]), x.getState(e.prosemirrorState).undoManager.undoStack = s, i) {
|
|
186
|
+
let t = C.encodeStateAsUpdate(o.doc, C.encodeStateVector(a.doc));
|
|
187
|
+
C.applyUpdate(a.doc, t, e);
|
|
188
|
+
}
|
|
189
|
+
n = void 0, r.setState({ isForked: !1 });
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}), R = a(({ editor: e }) => ({
|
|
193
|
+
key: "yPositionMapping",
|
|
194
|
+
mapPosition: (t, n = "left") => {
|
|
195
|
+
let r = b.getState(e.prosemirrorState);
|
|
196
|
+
if (!r) throw Error("YSync plugin state not found");
|
|
197
|
+
if (t === 0) return () => 0;
|
|
198
|
+
if (r.binding.type.length === 0) {
|
|
199
|
+
let r = e.getExtension("positionMapping");
|
|
200
|
+
if (!r) throw Error("positionMapping extension is not available; cannot map position before sync");
|
|
201
|
+
return r.mapPosition(t, n);
|
|
202
|
+
}
|
|
203
|
+
let i = d(t + (n === "right" ? 1 : -1), r.binding.type, r.binding.mapping);
|
|
204
|
+
return () => {
|
|
205
|
+
let t = b.getState(e.prosemirrorState), r = g(t.doc, t.binding.type, i, t.binding.mapping);
|
|
206
|
+
if (r === null) throw Error("Position not found, cannot track positions");
|
|
207
|
+
return r + (n === "right" ? -1 : 1);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
})), z = (e, t) => {
|
|
211
|
+
t(e), e.forEach((e) => {
|
|
212
|
+
e instanceof C.XmlElement && z(e, t);
|
|
213
|
+
});
|
|
214
|
+
}, B = [(e, t) => {
|
|
215
|
+
let n = /* @__PURE__ */ new Map();
|
|
216
|
+
return e.forEach((e) => {
|
|
217
|
+
e instanceof C.XmlElement && z(e, (e) => {
|
|
218
|
+
if (e.nodeName === "blockContainer" && e.hasAttribute("id")) {
|
|
219
|
+
let t = e.getAttribute("textColor"), i = e.getAttribute("backgroundColor"), a = {
|
|
220
|
+
textColor: t === r.textColor.default ? void 0 : t,
|
|
221
|
+
backgroundColor: i === r.backgroundColor.default ? void 0 : i
|
|
222
|
+
};
|
|
223
|
+
(a.textColor || a.backgroundColor) && n.set(e.getAttribute("id"), a);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}), n.size === 0 ? !1 : (t.doc.descendants((e, r) => {
|
|
227
|
+
if (e.type.name === "blockContainer" && n.has(e.attrs.id)) {
|
|
228
|
+
let i = t.doc.nodeAt(r + 1);
|
|
229
|
+
if (!i) throw Error("No element found");
|
|
230
|
+
t.setNodeMarkup(r + 1, void 0, {
|
|
231
|
+
...i.attrs,
|
|
232
|
+
...n.get(e.attrs.id)
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}), !0);
|
|
236
|
+
}], V = a(({ options: e }) => {
|
|
237
|
+
let t = !1;
|
|
238
|
+
return {
|
|
239
|
+
key: "schemaMigration",
|
|
240
|
+
prosemirrorPlugins: [new l({
|
|
241
|
+
key: new u("schemaMigration"),
|
|
242
|
+
appendTransaction: (n, r, i) => {
|
|
243
|
+
if (t || !n.some((e) => e.getMeta("y-sync$")) || n.every((e) => !e.docChanged) || !e.fragment.firstChild) return;
|
|
244
|
+
let a = i.tr;
|
|
245
|
+
for (let t of B) t(e.fragment, a);
|
|
246
|
+
if (t = !0, a.docChanged) return a;
|
|
247
|
+
}
|
|
248
|
+
})]
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/yjs/extensions/Versioning.ts
|
|
253
|
+
function H(e, t) {
|
|
254
|
+
let { fragment: n } = t;
|
|
255
|
+
function r() {
|
|
256
|
+
let t = e.getExtension(L);
|
|
257
|
+
if (!t) throw Error("ForkYDocExtension is required for the Yjs versioning adapter. Make sure it is registered before the VersioningExtension.");
|
|
258
|
+
return t;
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
getCurrentDocument: () => n,
|
|
262
|
+
serializeCurrentContent: () => C.encodeStateAsUpdateV2(n.doc),
|
|
263
|
+
preview: {
|
|
264
|
+
supportsComparison: !1,
|
|
265
|
+
enterPreview(e, t) {
|
|
266
|
+
let n = r();
|
|
267
|
+
n.store.state.isForked && n.merge({ keepChanges: !1 }), n.fork({ initialUpdate: e });
|
|
268
|
+
},
|
|
269
|
+
exitPreview() {
|
|
270
|
+
let e = r();
|
|
271
|
+
e.store.state.isForked && e.merge({ keepChanges: !1 });
|
|
272
|
+
},
|
|
273
|
+
applyRestore(e) {
|
|
274
|
+
throw Error("Restore is not yet implemented for Yjs v13 versioning adapter.");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/yjs/extensions/index.ts
|
|
281
|
+
var U = a(({ options: e }) => ({
|
|
282
|
+
key: "collaboration",
|
|
283
|
+
blockNoteExtensions: [
|
|
284
|
+
j(),
|
|
285
|
+
L(e),
|
|
286
|
+
R(),
|
|
287
|
+
V(e),
|
|
288
|
+
P(e),
|
|
289
|
+
F(e),
|
|
290
|
+
I()
|
|
291
|
+
]
|
|
292
|
+
}));
|
|
293
|
+
function W(e) {
|
|
294
|
+
return {
|
|
295
|
+
...e,
|
|
296
|
+
extensions: [...e.extensions ?? [], U(e.collaboration)],
|
|
297
|
+
disableExtensions: ["history", ...e.disableExtensions ?? []],
|
|
298
|
+
initialContent: [{
|
|
299
|
+
type: "paragraph",
|
|
300
|
+
id: "initialBlockId"
|
|
301
|
+
}]
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/yjs/comments/yjsHelpers.ts
|
|
306
|
+
function G(e) {
|
|
307
|
+
let t = new C.Map();
|
|
308
|
+
if (t.set("id", e.id), t.set("userId", e.userId), t.set("createdAt", e.createdAt.getTime()), t.set("updatedAt", e.updatedAt.getTime()), e.deletedAt ? (t.set("deletedAt", e.deletedAt.getTime()), t.set("body", void 0)) : t.set("body", e.body), e.reactions.length > 0) throw Error("Reactions should be empty in commentToYMap");
|
|
309
|
+
return t.set("reactionsByUser", new C.Map()), t.set("metadata", e.metadata), t;
|
|
13
310
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
311
|
+
function K(e) {
|
|
312
|
+
let t = new C.Map();
|
|
313
|
+
t.set("id", e.id), t.set("createdAt", e.createdAt.getTime()), t.set("updatedAt", e.updatedAt.getTime());
|
|
314
|
+
let n = new C.Array();
|
|
315
|
+
return n.push(e.comments.map((e) => G(e))), t.set("comments", n), t.set("resolved", e.resolved), t.set("resolvedUpdatedAt", e.resolvedUpdatedAt?.getTime()), t.set("resolvedBy", e.resolvedBy), t.set("metadata", e.metadata), t;
|
|
16
316
|
}
|
|
17
|
-
function
|
|
18
|
-
return
|
|
317
|
+
function q(e) {
|
|
318
|
+
return {
|
|
319
|
+
emoji: e.get("emoji"),
|
|
320
|
+
createdAt: new Date(e.get("createdAt")),
|
|
321
|
+
userId: e.get("userId")
|
|
322
|
+
};
|
|
19
323
|
}
|
|
20
|
-
function
|
|
21
|
-
return
|
|
324
|
+
function J(e) {
|
|
325
|
+
return [...e.values()].map((e) => q(e)).reduce((e, t) => {
|
|
326
|
+
let n = e.find((e) => e.emoji === t.emoji);
|
|
327
|
+
return n ? (n.userIds.push(t.userId), n.createdAt = new Date(Math.min(n.createdAt.getTime(), t.createdAt.getTime()))) : e.push({
|
|
328
|
+
emoji: t.emoji,
|
|
329
|
+
createdAt: t.createdAt,
|
|
330
|
+
userIds: [t.userId]
|
|
331
|
+
}), e;
|
|
332
|
+
}, []);
|
|
333
|
+
}
|
|
334
|
+
function Y(e) {
|
|
335
|
+
return {
|
|
336
|
+
type: "comment",
|
|
337
|
+
id: e.get("id"),
|
|
338
|
+
userId: e.get("userId"),
|
|
339
|
+
createdAt: new Date(e.get("createdAt")),
|
|
340
|
+
updatedAt: new Date(e.get("updatedAt")),
|
|
341
|
+
deletedAt: e.get("deletedAt") ? new Date(e.get("deletedAt")) : void 0,
|
|
342
|
+
reactions: J(e.get("reactionsByUser")),
|
|
343
|
+
metadata: e.get("metadata"),
|
|
344
|
+
body: e.get("body")
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function X(e) {
|
|
348
|
+
return {
|
|
349
|
+
type: "thread",
|
|
350
|
+
id: e.get("id"),
|
|
351
|
+
createdAt: new Date(e.get("createdAt")),
|
|
352
|
+
updatedAt: new Date(e.get("updatedAt")),
|
|
353
|
+
comments: (e.get("comments") || []).map((e) => Y(e)),
|
|
354
|
+
resolved: e.get("resolved"),
|
|
355
|
+
resolvedUpdatedAt: new Date(e.get("resolvedUpdatedAt")),
|
|
356
|
+
resolvedBy: e.get("resolvedBy"),
|
|
357
|
+
metadata: e.get("metadata")
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/yjs/comments/YjsThreadStoreBase.ts
|
|
362
|
+
var Z = class extends o {
|
|
363
|
+
threadsYMap;
|
|
364
|
+
constructor(e, t) {
|
|
365
|
+
super(t), this.threadsYMap = e;
|
|
366
|
+
}
|
|
367
|
+
getThread(e) {
|
|
368
|
+
let t = this.threadsYMap.get(e);
|
|
369
|
+
if (!t) throw Error("Thread not found");
|
|
370
|
+
return X(t);
|
|
371
|
+
}
|
|
372
|
+
getThreads() {
|
|
373
|
+
let e = /* @__PURE__ */ new Map();
|
|
374
|
+
return this.threadsYMap.forEach((t, n) => {
|
|
375
|
+
t instanceof C.Map && e.set(n, X(t));
|
|
376
|
+
}), e;
|
|
377
|
+
}
|
|
378
|
+
subscribe(e) {
|
|
379
|
+
let t = () => {
|
|
380
|
+
e(this.getThreads());
|
|
381
|
+
};
|
|
382
|
+
return this.threadsYMap.observeDeep(t), () => {
|
|
383
|
+
this.threadsYMap.unobserveDeep(t);
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
}, Q = class extends Z {
|
|
387
|
+
BASE_URL;
|
|
388
|
+
headers;
|
|
389
|
+
constructor(e, t, n, r) {
|
|
390
|
+
super(n, r), this.BASE_URL = e, this.headers = t;
|
|
391
|
+
}
|
|
392
|
+
doRequest = async (e, t, n) => {
|
|
393
|
+
let r = await fetch(`${this.BASE_URL}${e}`, {
|
|
394
|
+
method: t,
|
|
395
|
+
body: JSON.stringify(n),
|
|
396
|
+
headers: {
|
|
397
|
+
"Content-Type": "application/json",
|
|
398
|
+
...this.headers
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
if (!r.ok) throw Error(`Failed to ${t} ${e}: ${r.statusText}`);
|
|
402
|
+
return r.json();
|
|
403
|
+
};
|
|
404
|
+
addThreadToDocument = async (e) => {
|
|
405
|
+
let { threadId: t, selection: n } = e, r = b.getState(e.editor.prosemirrorState), i = r ? {
|
|
406
|
+
head: d(n.head, r.type, r.mapping),
|
|
407
|
+
anchor: d(n.anchor, r.type, r.mapping)
|
|
408
|
+
} : void 0;
|
|
409
|
+
return this.doRequest(`/${t}/addToDocument`, "POST", { selection: {
|
|
410
|
+
prosemirror: n,
|
|
411
|
+
yjs: i
|
|
412
|
+
} });
|
|
413
|
+
};
|
|
414
|
+
createThread = async (e) => this.doRequest("", "POST", e);
|
|
415
|
+
addComment = (e) => {
|
|
416
|
+
let { threadId: t, ...n } = e;
|
|
417
|
+
return this.doRequest(`/${t}/comments`, "POST", n);
|
|
418
|
+
};
|
|
419
|
+
updateComment = (e) => {
|
|
420
|
+
let { threadId: t, commentId: n, ...r } = e;
|
|
421
|
+
return this.doRequest(`/${t}/comments/${n}`, "PUT", r);
|
|
422
|
+
};
|
|
423
|
+
deleteComment = (e) => {
|
|
424
|
+
let { threadId: t, commentId: n, ...r } = e;
|
|
425
|
+
return this.doRequest(`/${t}/comments/${n}?soft=${!!r.softDelete}`, "DELETE");
|
|
426
|
+
};
|
|
427
|
+
deleteThread = (e) => this.doRequest(`/${e.threadId}`, "DELETE");
|
|
428
|
+
resolveThread = (e) => this.doRequest(`/${e.threadId}/resolve`, "POST");
|
|
429
|
+
unresolveThread = (e) => this.doRequest(`/${e.threadId}/unresolve`, "POST");
|
|
430
|
+
addReaction = (e) => {
|
|
431
|
+
let { threadId: t, commentId: n, ...r } = e;
|
|
432
|
+
return this.doRequest(`/${t}/comments/${n}/reactions`, "POST", r);
|
|
433
|
+
};
|
|
434
|
+
deleteReaction = (e) => this.doRequest(`/${e.threadId}/comments/${e.commentId}/reactions/${e.emoji}`, "DELETE");
|
|
435
|
+
}, te = class extends Z {
|
|
436
|
+
userId;
|
|
437
|
+
constructor(e, t, n) {
|
|
438
|
+
super(t, n), this.userId = e;
|
|
439
|
+
}
|
|
440
|
+
transact = (e) => async (t) => this.threadsYMap.doc.transact(() => e(t));
|
|
441
|
+
createThread = this.transact((e) => {
|
|
442
|
+
if (!this.auth.canCreateThread()) throw Error("Not authorized");
|
|
443
|
+
let t = /* @__PURE__ */ new Date(), n = {
|
|
444
|
+
type: "comment",
|
|
445
|
+
id: c(),
|
|
446
|
+
userId: this.userId,
|
|
447
|
+
createdAt: t,
|
|
448
|
+
updatedAt: t,
|
|
449
|
+
reactions: [],
|
|
450
|
+
metadata: e.initialComment.metadata,
|
|
451
|
+
body: e.initialComment.body
|
|
452
|
+
}, r = {
|
|
453
|
+
type: "thread",
|
|
454
|
+
id: c(),
|
|
455
|
+
createdAt: t,
|
|
456
|
+
updatedAt: t,
|
|
457
|
+
comments: [n],
|
|
458
|
+
resolved: !1,
|
|
459
|
+
metadata: e.metadata
|
|
460
|
+
};
|
|
461
|
+
return this.threadsYMap.set(r.id, K(r)), r;
|
|
462
|
+
});
|
|
463
|
+
addThreadToDocument = void 0;
|
|
464
|
+
addComment = this.transact((e) => {
|
|
465
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
466
|
+
if (!t) throw Error("Thread not found");
|
|
467
|
+
if (!this.auth.canAddComment(X(t))) throw Error("Not authorized");
|
|
468
|
+
let n = /* @__PURE__ */ new Date(), r = {
|
|
469
|
+
type: "comment",
|
|
470
|
+
id: c(),
|
|
471
|
+
userId: this.userId,
|
|
472
|
+
createdAt: n,
|
|
473
|
+
updatedAt: n,
|
|
474
|
+
deletedAt: void 0,
|
|
475
|
+
reactions: [],
|
|
476
|
+
metadata: e.comment.metadata,
|
|
477
|
+
body: e.comment.body
|
|
478
|
+
};
|
|
479
|
+
return t.get("comments").push([G(r)]), t.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), r;
|
|
480
|
+
});
|
|
481
|
+
updateComment = this.transact((e) => {
|
|
482
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
483
|
+
if (!t) throw Error("Thread not found");
|
|
484
|
+
let n = $(t.get("comments"), (t) => t.get("id") === e.commentId);
|
|
485
|
+
if (n === -1) throw Error("Comment not found");
|
|
486
|
+
let r = t.get("comments").get(n);
|
|
487
|
+
if (!this.auth.canUpdateComment(Y(r))) throw Error("Not authorized");
|
|
488
|
+
r.set("body", e.comment.body), r.set("updatedAt", (/* @__PURE__ */ new Date()).getTime()), r.set("metadata", e.comment.metadata);
|
|
489
|
+
});
|
|
490
|
+
deleteComment = this.transact((e) => {
|
|
491
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
492
|
+
if (!t) throw Error("Thread not found");
|
|
493
|
+
let n = $(t.get("comments"), (t) => t.get("id") === e.commentId);
|
|
494
|
+
if (n === -1) throw Error("Comment not found");
|
|
495
|
+
let r = t.get("comments").get(n);
|
|
496
|
+
if (!this.auth.canDeleteComment(Y(r))) throw Error("Not authorized");
|
|
497
|
+
if (r.get("deletedAt")) throw Error("Comment already deleted");
|
|
498
|
+
e.softDelete ? (r.set("deletedAt", (/* @__PURE__ */ new Date()).getTime()), r.set("body", void 0)) : t.get("comments").delete(n), t.get("comments").toArray().every((e) => e.get("deletedAt")) && (e.softDelete ? t.set("deletedAt", (/* @__PURE__ */ new Date()).getTime()) : this.threadsYMap.delete(e.threadId)), t.set("updatedAt", (/* @__PURE__ */ new Date()).getTime());
|
|
499
|
+
});
|
|
500
|
+
deleteThread = this.transact((e) => {
|
|
501
|
+
if (!this.auth.canDeleteThread(X(this.threadsYMap.get(e.threadId)))) throw Error("Not authorized");
|
|
502
|
+
this.threadsYMap.delete(e.threadId);
|
|
503
|
+
});
|
|
504
|
+
resolveThread = this.transact((e) => {
|
|
505
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
506
|
+
if (!t) throw Error("Thread not found");
|
|
507
|
+
if (!this.auth.canResolveThread(X(t))) throw Error("Not authorized");
|
|
508
|
+
t.set("resolved", !0), t.set("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime()), t.set("resolvedBy", this.userId);
|
|
509
|
+
});
|
|
510
|
+
unresolveThread = this.transact((e) => {
|
|
511
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
512
|
+
if (!t) throw Error("Thread not found");
|
|
513
|
+
if (!this.auth.canUnresolveThread(X(t))) throw Error("Not authorized");
|
|
514
|
+
t.set("resolved", !1), t.set("resolvedUpdatedAt", (/* @__PURE__ */ new Date()).getTime());
|
|
515
|
+
});
|
|
516
|
+
addReaction = this.transact((e) => {
|
|
517
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
518
|
+
if (!t) throw Error("Thread not found");
|
|
519
|
+
let n = $(t.get("comments"), (t) => t.get("id") === e.commentId);
|
|
520
|
+
if (n === -1) throw Error("Comment not found");
|
|
521
|
+
let r = t.get("comments").get(n);
|
|
522
|
+
if (!this.auth.canAddReaction(Y(r), e.emoji)) throw Error("Not authorized");
|
|
523
|
+
let i = /* @__PURE__ */ new Date(), a = `${this.userId}-${e.emoji}`, o = r.get("reactionsByUser");
|
|
524
|
+
if (!o.has(a)) {
|
|
525
|
+
let t = new C.Map();
|
|
526
|
+
t.set("emoji", e.emoji), t.set("createdAt", i.getTime()), t.set("userId", this.userId), o.set(a, t);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
deleteReaction = this.transact((e) => {
|
|
530
|
+
let t = this.threadsYMap.get(e.threadId);
|
|
531
|
+
if (!t) throw Error("Thread not found");
|
|
532
|
+
let n = $(t.get("comments"), (t) => t.get("id") === e.commentId);
|
|
533
|
+
if (n === -1) throw Error("Comment not found");
|
|
534
|
+
let r = t.get("comments").get(n);
|
|
535
|
+
if (!this.auth.canDeleteReaction(Y(r), e.emoji)) throw Error("Not authorized");
|
|
536
|
+
let i = `${this.userId}-${e.emoji}`;
|
|
537
|
+
r.get("reactionsByUser").delete(i);
|
|
538
|
+
});
|
|
539
|
+
};
|
|
540
|
+
function $(e, t) {
|
|
541
|
+
for (let n = 0; n < e.length; n++) if (t(e.get(n))) return n;
|
|
542
|
+
return -1;
|
|
22
543
|
}
|
|
23
544
|
//#endregion
|
|
24
|
-
export {
|
|
545
|
+
export { U as CollaborationExtension, L as ForkYDocExtension, Q as RESTYjsThreadStore, R as RelativePositionMappingExtension, V as SchemaMigration, P as YCursorExtension, F as YSyncExtension, I as YUndoExtension, te as YjsThreadStore, Z as YjsThreadStoreBase, E as _blocksToProsemirrorNode, T as _prosemirrorJSONToBlocks, A as blocksToYDoc, O as blocksToYXmlFragment, H as createYjsVersioningAdapter, w as findTypeInOtherYdoc, W as withCollaboration, k as yDocToBlocks, D as yXmlFragmentToBlocks };
|
|
25
546
|
|
|
26
547
|
//# sourceMappingURL=yjs.js.map
|