@blocknote/core 0.51.4 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BlockNoteExtension-B_IEJHS8.js +38 -0
- package/dist/BlockNoteExtension-B_IEJHS8.js.map +1 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs +2 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs.map +1 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs +2 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs.map +1 -0
- package/dist/ThreadStore-et9wB5Xt.js +11 -0
- package/dist/ThreadStore-et9wB5Xt.js.map +1 -0
- package/dist/UserStore-DCG6lsla.cjs +2 -0
- package/dist/UserStore-DCG6lsla.cjs.map +1 -0
- package/dist/UserStore-QbbPFj0z.js +73 -0
- package/dist/UserStore-QbbPFj0z.js.map +1 -0
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -7
- package/dist/blocks-BqHv0xhc.cjs +12 -0
- package/dist/blocks-BqHv0xhc.cjs.map +1 -0
- package/dist/{blocks-DGsP5WKr.js → blocks-CiuUGa1E.js} +1093 -994
- package/dist/blocks-CiuUGa1E.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +75 -340
- package/dist/comments.js.map +1 -1
- package/dist/{en-Cj5r8sW_.cjs → en-C5Z4Ag9_.cjs} +2 -2
- package/dist/en-C5Z4Ag9_.cjs.map +1 -0
- package/dist/{en-B9hMApn4.js → en-CGKXfWma.js} +9 -1
- package/dist/en-CGKXfWma.js.map +1 -0
- package/dist/{extensions-Co4y7P63.js → extensions-CrUGDOks.js} +655 -583
- package/dist/extensions-CrUGDOks.js.map +1 -0
- package/dist/extensions-Ghr9QqqR.cjs +52 -0
- package/dist/extensions-Ghr9QqqR.cjs.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +4 -4
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +177 -1
- package/dist/locales.js.map +1 -1
- package/dist/{src-Bcud0PIg.js → src-DTF83Cl9.js} +1243 -1297
- package/dist/src-DTF83Cl9.js.map +1 -0
- package/dist/src-OfbaVbMw.cjs +21 -0
- package/dist/src-OfbaVbMw.cjs.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +2 -0
- package/dist/y.cjs.map +1 -0
- package/dist/y.js +989 -0
- package/dist/y.js.map +1 -0
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +535 -14
- package/dist/yjs.js.map +1 -1
- package/package.json +46 -19
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +25 -20
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +39 -29
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +2 -2
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +4 -8
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +21 -9
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +6 -5
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +362 -4
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +240 -30
- package/src/api/blockManipulation/getBlock/getBlock.ts +4 -9
- package/src/api/blockManipulation/selections/selection.ts +3 -6
- package/src/api/blockManipulation/selections/textCursorPosition.ts +10 -10
- package/src/api/blockManipulation/setupTestEnv.ts +1 -1
- package/src/api/blockManipulation/tables/tables.test.ts +1 -1
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +1 -1
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +8 -4
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +2 -1
- package/src/api/exporters/markdown/htmlToMarkdown.ts +79 -43
- package/src/api/getBlockInfoFromPos.test.ts +256 -0
- package/src/api/getBlockInfoFromPos.ts +53 -15
- package/src/api/getBlocksChangedByTransaction.test.ts +2 -1
- package/src/api/getBlocksChangedByTransaction.ts +6 -6
- package/src/api/nodeConversions/blockToNode.test.ts +113 -0
- package/src/api/nodeConversions/blockToNode.ts +15 -3
- package/src/api/nodeConversions/fragmentToBlocks.ts +2 -4
- package/src/api/nodeConversions/nodeToBlock.ts +28 -58
- package/src/api/nodeUtil.ts +6 -2
- package/src/api/parsers/html/parseHTML.ts +1 -1
- package/src/api/parsers/html/util/nestedLists.test.ts +1 -1
- package/src/api/parsers/markdown/detectMarkdown.test.ts +1 -1
- package/src/api/parsers/markdown/markdownToHtml.ts +228 -82
- package/src/api/pmUtil.ts +18 -1
- package/src/api/positionMapping.test.ts +20 -345
- package/src/api/positionMapping.ts +13 -83
- package/src/blocks/Audio/block.ts +1 -1
- package/src/blocks/Code/block.test.ts +14 -7
- package/src/blocks/Code/block.ts +2 -2
- package/src/blocks/Image/block.ts +1 -1
- package/src/blocks/ListItem/CheckListItem/block.test.ts +1 -1
- package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +2 -2
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +4 -11
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +47 -50
- package/src/blocks/Table/TableExtension.test.ts +9 -6
- package/src/blocks/Table/TableExtension.ts +20 -6
- package/src/blocks/Table/block.ts +18 -5
- package/src/blocks/Video/block.ts +1 -1
- package/src/blocks/utils/listItemEnterHandler.ts +3 -2
- package/src/comments/extension.ts +30 -21
- package/src/comments/index.ts +0 -3
- package/src/comments/mark.ts +4 -0
- package/src/comments/threadstore/ThreadStore.ts +4 -8
- package/src/comments/types.ts +0 -8
- package/src/editor/Block.css +307 -3
- package/src/editor/BlockNoteEditor.test.ts +21 -18
- package/src/editor/BlockNoteEditor.ts +22 -57
- package/src/editor/BlockNoteExtension.test.ts +1 -1
- package/src/editor/managers/BlockManager.ts +1 -1
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +249 -0
- package/src/editor/managers/ExtensionManager/extensions.ts +7 -18
- package/src/editor/managers/ExtensionManager/index.ts +168 -68
- package/src/editor/managers/StateManager.ts +4 -3
- package/src/editor/performance.test.ts +14 -1
- package/src/editor/transformPasted.test.ts +1 -1
- package/src/extensions/Placeholder/Placeholder.ts +1 -0
- package/src/extensions/PositionMapping/PositionMapping.ts +68 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +14 -1
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +14 -11
- package/src/extensions/SideMenu/SideMenu.ts +9 -2
- package/src/extensions/SuggestionMenu/SuggestionMenu.test.ts +1 -1
- package/src/extensions/TableHandles/TableHandles.ts +18 -20
- package/src/extensions/TrailingNode/TrailingNode.ts +33 -1
- package/src/extensions/Versioning/Versioning.test.ts +435 -0
- package/src/extensions/Versioning/Versioning.ts +628 -0
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +469 -0
- package/src/extensions/Versioning/inMemoryVersioning.ts +263 -0
- package/src/extensions/Versioning/index.ts +2 -0
- package/src/extensions/index.ts +6 -9
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +155 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +6 -8
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +9 -9
- package/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts +8 -10
- package/src/extensions/tiptap-extensions/Link/helpers/whitespace.ts +2 -2
- package/src/extensions/tiptap-extensions/Link/link.test.ts +26 -22
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +187 -0
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +37 -24
- package/src/extensions/tiptap-extensions/index.ts +1 -25
- package/src/i18n/locales/ar.ts +9 -0
- package/src/i18n/locales/de.ts +9 -0
- package/src/i18n/locales/en.ts +10 -1
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fa.ts +11 -1
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/he.ts +10 -1
- package/src/i18n/locales/hr.ts +10 -0
- package/src/i18n/locales/is.ts +10 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/ja.ts +9 -0
- package/src/i18n/locales/ko.ts +9 -0
- package/src/i18n/locales/nl.ts +10 -0
- package/src/i18n/locales/no.ts +10 -0
- package/src/i18n/locales/pl.ts +9 -0
- package/src/i18n/locales/pt.ts +10 -0
- package/src/i18n/locales/ru.ts +10 -0
- package/src/i18n/locales/sk.ts +10 -1
- package/src/i18n/locales/uk.ts +9 -0
- package/src/i18n/locales/uz.ts +9 -0
- package/src/i18n/locales/vi.ts +9 -0
- package/src/i18n/locales/zh-tw.ts +9 -0
- package/src/i18n/locales/zh.ts +9 -0
- package/src/index.ts +2 -0
- package/src/pm-nodes/BlockContainer.ts +4 -1
- package/src/pm-nodes/BlockGroup.ts +4 -1
- package/src/pm-nodes/Doc.ts +4 -1
- package/src/pm-nodes/suggestionMarks.ts +43 -0
- package/src/schema/blocks/createSpec.test.ts +123 -0
- package/src/schema/blocks/createSpec.ts +82 -24
- package/src/schema/blocks/extendBlockSpec.test.ts +188 -0
- package/src/schema/blocks/internal.ts +13 -43
- package/src/schema/blocks/types.ts +69 -22
- package/src/schema/contentTypePropagation.test.ts +182 -0
- package/src/schema/index.ts +1 -0
- package/src/schema/inlineContent/internal.ts +1 -1
- package/src/schema/inlineContent/types.ts +3 -3
- package/src/schema/markGroups.ts +50 -0
- package/src/user/UserStore.ts +199 -0
- package/src/user/createUserStore.test.ts +126 -0
- package/src/user/index.ts +2 -0
- package/src/user/userColors.ts +72 -0
- package/src/util/string.ts +1 -1
- package/src/util/topo-sort.test.ts +1 -1
- package/src/util/typescript.ts +2 -1
- package/src/vite-env.d.ts +1 -1
- package/src/y/README.md +5 -0
- package/src/{comments/threadstore/yjs → y/comments}/RESTYjsThreadStore.ts +8 -14
- package/src/y/comments/YjsThreadStore.test.ts +295 -0
- package/src/y/comments/YjsThreadStore.ts +358 -0
- package/src/y/comments/YjsThreadStoreBase.ts +50 -0
- package/src/y/comments/index.ts +3 -0
- package/src/y/comments/yjsHelpers.ts +125 -0
- package/src/y/extensions/AttributionExtension.test.ts +86 -0
- package/src/y/extensions/AttributionExtension.ts +378 -0
- package/src/y/extensions/DiffVersioningExtension.test.ts +193 -0
- package/src/y/extensions/DiffVersioningExtension.ts +228 -0
- package/src/y/extensions/ForkYDoc.test.ts +253 -0
- package/src/y/extensions/ForkYDoc.ts +108 -0
- package/src/y/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/y/extensions/RelativePositionMapping.ts +49 -0
- package/src/y/extensions/Suggestions.ts +174 -0
- package/src/y/extensions/Versioning.test.ts +395 -0
- package/src/y/extensions/Versioning.ts +115 -0
- package/src/y/extensions/YAttributionMarks.ts +320 -0
- package/src/{extensions/Collaboration → y/extensions}/YCursorPlugin.ts +15 -7
- package/src/y/extensions/YSync.ts +125 -0
- package/src/y/extensions/blockMatchNodes.ts +182 -0
- package/src/y/extensions/index.ts +156 -0
- package/src/y/index.ts +4 -0
- package/src/y/utils.test.ts +1042 -0
- package/src/y/utils.ts +242 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.json +50 -0
- package/src/y/versioning/__test__/fixtures/activity-all.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all.json +20 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +32 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-before.json +1 -0
- package/src/y/versioning/__test__/fixtures/changeset.bin +0 -0
- package/src/y/versioning/__test__/fixtures/patch-response.json +4 -0
- package/src/y/versioning/__test__/yhub.test.ts +752 -0
- package/src/y/versioning/index.ts +1 -0
- package/src/y/versioning/yhub.ts +631 -0
- package/src/yjs/README.md +5 -0
- package/src/yjs/comments/RESTYjsThreadStore.ts +166 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.test.ts +3 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.ts +7 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.ts +3 -3
- package/src/yjs/comments/index.ts +3 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.ts +5 -1
- package/src/yjs/extensions/FixUpSchema.test.ts +421 -0
- package/src/yjs/extensions/FixUpSchema.ts +88 -0
- package/src/yjs/extensions/ForkYDoc.test.ts +216 -0
- package/src/{extensions/Collaboration → yjs/extensions}/ForkYDoc.ts +38 -57
- package/src/yjs/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/yjs/extensions/RelativePositionMapping.ts +71 -0
- package/src/yjs/extensions/Versioning.test.ts +549 -0
- package/src/yjs/extensions/Versioning.ts +83 -0
- package/src/yjs/extensions/YCursorPlugin.ts +201 -0
- package/src/{extensions/Collaboration → yjs/extensions}/YSync.ts +1 -1
- package/src/yjs/extensions/index.ts +89 -0
- package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.test.ts +1 -1
- package/src/yjs/index.ts +2 -0
- package/src/yjs/utils.test.ts +5 -15
- package/src/yjs/utils.ts +36 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +3 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
- package/types/src/api/getBlockInfoFromPos.d.ts +5 -9
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +4 -6
- package/types/src/api/pmUtil.d.ts +12 -1
- package/types/src/blocks/Audio/block.d.ts +2 -2
- package/types/src/blocks/Code/block.d.ts +2 -2
- package/types/src/blocks/File/block.d.ts +2 -2
- package/types/src/blocks/Heading/block.d.ts +21 -21
- package/types/src/blocks/Image/block.d.ts +3 -3
- package/types/src/blocks/ListItem/CheckListItem/block.d.ts +6 -6
- package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +6 -6
- package/types/src/blocks/Video/block.d.ts +3 -3
- package/types/src/blocks/defaultBlocks.d.ts +17 -17
- package/types/src/comments/extension.d.ts +18 -5
- package/types/src/comments/index.d.ts +0 -3
- package/types/src/comments/threadstore/ThreadStore.d.ts +4 -8
- package/types/src/comments/types.d.ts +0 -8
- package/types/src/editor/BlockNoteEditor.d.ts +8 -9
- package/types/src/editor/managers/BlockManager.d.ts +1 -1
- package/types/src/editor/managers/ExtensionManager/extensions.d.ts +2 -2
- package/types/src/editor/managers/ExtensionManager/index.d.ts +13 -0
- package/types/src/editor/managers/SelectionManager.d.ts +1 -1
- package/types/src/extensions/PositionMapping/PositionMapping.d.ts +4 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -6
- package/types/src/extensions/Versioning/Versioning.d.ts +352 -0
- package/types/src/extensions/Versioning/Versioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +37 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/index.d.ts +2 -0
- package/types/src/extensions/index.d.ts +6 -9
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +1 -0
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.d.ts +6 -1
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.d.ts +4 -0
- package/types/src/extensions/tiptap-extensions/index.d.ts +1 -5
- package/types/src/i18n/locales/en.d.ts +9 -1
- package/types/src/i18n/locales/fa.d.ts +9 -1
- package/types/src/i18n/locales/sk.d.ts +9 -1
- package/types/src/index.d.ts +2 -0
- package/types/src/pm-nodes/suggestionMarks.d.ts +26 -0
- package/types/src/schema/blocks/createSpec.d.ts +4 -4
- package/types/src/schema/blocks/createSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/extendBlockSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/internal.d.ts +5 -7
- package/types/src/schema/blocks/types.d.ts +22 -14
- package/types/src/schema/contentTypePropagation.test.d.ts +1 -0
- package/types/src/schema/index.d.ts +1 -0
- package/types/src/schema/inlineContent/types.d.ts +3 -3
- package/types/src/schema/markGroups.d.ts +33 -0
- package/types/src/user/UserStore.d.ts +105 -0
- package/types/src/user/createUserStore.test.d.ts +1 -0
- package/types/src/user/index.d.ts +2 -0
- package/types/src/user/userColors.d.ts +36 -0
- package/types/src/y/comments/RESTYjsThreadStore.d.ts +77 -0
- package/types/src/y/comments/YjsThreadStore.d.ts +79 -0
- package/types/src/y/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/y/comments/YjsThreadStoreBase.d.ts +15 -0
- package/types/src/y/comments/index.d.ts +3 -0
- package/types/src/y/comments/yjsHelpers.d.ts +13 -0
- package/types/src/y/extensions/AttributionExtension.d.ts +74 -0
- package/types/src/y/extensions/AttributionExtension.test.d.ts +1 -0
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +69 -0
- package/types/src/y/extensions/DiffVersioningExtension.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → y/extensions}/ForkYDoc.d.ts +4 -2
- package/types/src/y/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/y/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/y/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/y/extensions/Suggestions.d.ts +36 -0
- package/types/src/y/extensions/Versioning.d.ts +17 -0
- package/types/src/y/extensions/Versioning.test.d.ts +1 -0
- package/types/src/y/extensions/YAttributionMarks.d.ts +67 -0
- package/types/src/y/extensions/YCursorPlugin.d.ts +14 -0
- package/types/src/y/extensions/YSync.d.ts +32 -0
- package/types/src/y/extensions/blockMatchNodes.d.ts +25 -0
- package/types/src/y/extensions/index.d.ts +189 -0
- package/types/src/y/index.d.ts +4 -0
- package/types/src/y/utils.d.ts +82 -0
- package/types/src/y/utils.test.d.ts +1 -0
- package/types/src/y/versioning/__test__/yhub.test.d.ts +1 -0
- package/types/src/y/versioning/index.d.ts +1 -0
- package/types/src/y/versioning/yhub.d.ts +87 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/RESTYjsThreadStore.d.ts +6 -10
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.d.ts +3 -3
- package/types/src/yjs/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.d.ts +3 -3
- package/types/src/yjs/comments/index.d.ts +3 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.d.ts +1 -1
- package/types/src/yjs/extensions/FixUpSchema.d.ts +3 -0
- package/types/src/yjs/extensions/FixUpSchema.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +27 -0
- package/types/src/yjs/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/yjs/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/yjs/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/yjs/extensions/Versioning.d.ts +26 -0
- package/types/src/yjs/extensions/Versioning.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → yjs/extensions}/YCursorPlugin.d.ts +5 -2
- package/types/src/{extensions/Collaboration → yjs/extensions}/YSync.d.ts +1 -1
- package/types/src/{extensions/Collaboration/Collaboration.d.ts → yjs/extensions/index.d.ts} +36 -15
- package/types/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +1 -0
- package/types/src/yjs/index.d.ts +2 -0
- package/types/src/yjs/utils.d.ts +5 -0
- package/dist/BlockNoteExtension-B6RhuQ3V.js +0 -27
- package/dist/BlockNoteExtension-B6RhuQ3V.js.map +0 -1
- package/dist/BlockNoteExtension-ab0REuob.cjs +0 -2
- package/dist/BlockNoteExtension-ab0REuob.cjs.map +0 -1
- package/dist/EventEmitter-CuPnGDYt.js +0 -22
- package/dist/EventEmitter-CuPnGDYt.js.map +0 -1
- package/dist/EventEmitter-DHdSnYCD.cjs +0 -2
- package/dist/EventEmitter-DHdSnYCD.cjs.map +0 -1
- package/dist/ShowSelection-BsHFfdMi.js +0 -29
- package/dist/ShowSelection-BsHFfdMi.js.map +0 -1
- package/dist/ShowSelection-DhXglbt8.cjs +0 -2
- package/dist/ShowSelection-DhXglbt8.cjs.map +0 -1
- package/dist/blocks-Bm6IfL1R.cjs +0 -11
- package/dist/blocks-Bm6IfL1R.cjs.map +0 -1
- package/dist/blocks-DGsP5WKr.js.map +0 -1
- package/dist/en-B9hMApn4.js.map +0 -1
- package/dist/en-Cj5r8sW_.cjs.map +0 -1
- package/dist/extensions-Co4y7P63.js.map +0 -1
- package/dist/extensions-IJK3t0sz.cjs +0 -52
- package/dist/extensions-IJK3t0sz.cjs.map +0 -1
- package/dist/src-B6rlChSc.cjs +0 -21
- package/dist/src-B6rlChSc.cjs.map +0 -1
- package/dist/src-Bcud0PIg.js.map +0 -1
- package/src/comments/userstore/UserStore.ts +0 -72
- package/src/extensions/Collaboration/Collaboration.ts +0 -55
- package/src/extensions/Collaboration/ForkYDoc.test.ts +0 -179
- package/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.ts +0 -175
- package/types/src/comments/userstore/UserStore.d.ts +0 -31
- package/types/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.d.ts +0 -4
- /package/src/{extensions/Collaboration → yjs/extensions}/YUndo.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor-forked.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-forked.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.ts +0 -0
- /package/types/src/{comments/threadstore/yjs/YjsThreadStore.test.d.ts → api/getBlockInfoFromPos.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/ForkYDoc.test.d.ts → api/nodeConversions/blockToNode.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.d.ts → editor/managers/ExtensionManager/ExtensionManager.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/YUndo.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.d.ts +0 -0
|
@@ -1,38 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
3
5
|
import { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
4
6
|
import { trackPosition } from "./positionMapping.js";
|
|
5
7
|
|
|
6
8
|
describe("PositionStorage with local editor", () => {
|
|
7
9
|
describe("mount and unmount", () => {
|
|
8
|
-
it("should
|
|
10
|
+
it("should return a position getter on creation (mounted)", () => {
|
|
9
11
|
const editor = BlockNoteEditor.create();
|
|
10
12
|
editor.mount(document.createElement("div"));
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
trackPosition(editor, 0);
|
|
14
|
+
const getPos = trackPosition(editor, 0);
|
|
14
15
|
|
|
15
|
-
expect(
|
|
16
|
-
|
|
17
|
-
expect.any(Function),
|
|
18
|
-
);
|
|
16
|
+
expect(typeof getPos).toBe("function");
|
|
17
|
+
expect(getPos()).toBe(0);
|
|
19
18
|
|
|
20
|
-
editor.
|
|
19
|
+
editor.unmount();
|
|
21
20
|
});
|
|
22
21
|
|
|
23
|
-
it("should
|
|
22
|
+
it("should return a position getter on creation (unmounted)", () => {
|
|
24
23
|
const editor = BlockNoteEditor.create();
|
|
25
|
-
// editor.mount(document.createElement("div"));
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
trackPosition(editor, 0);
|
|
25
|
+
const getPos = trackPosition(editor, 0);
|
|
29
26
|
|
|
30
|
-
expect(
|
|
31
|
-
|
|
32
|
-
expect.any(Function),
|
|
33
|
-
);
|
|
27
|
+
expect(typeof getPos).toBe("function");
|
|
28
|
+
expect(getPos()).toBe(0);
|
|
34
29
|
|
|
35
|
-
editor.
|
|
30
|
+
editor.unmount();
|
|
36
31
|
});
|
|
37
32
|
});
|
|
38
33
|
|
|
@@ -45,7 +40,7 @@ describe("PositionStorage with local editor", () => {
|
|
|
45
40
|
|
|
46
41
|
expect(getPos()).toBe(10);
|
|
47
42
|
|
|
48
|
-
editor.
|
|
43
|
+
editor.unmount();
|
|
49
44
|
});
|
|
50
45
|
|
|
51
46
|
it("should handle right side positions", () => {
|
|
@@ -56,7 +51,7 @@ describe("PositionStorage with local editor", () => {
|
|
|
56
51
|
|
|
57
52
|
expect(getPos()).toBe(10);
|
|
58
53
|
|
|
59
|
-
editor.
|
|
54
|
+
editor.unmount();
|
|
60
55
|
});
|
|
61
56
|
});
|
|
62
57
|
|
|
@@ -101,50 +96,7 @@ describe("PositionStorage with local editor", () => {
|
|
|
101
96
|
// Position should be updated according to mapping
|
|
102
97
|
expect(getPos()).toBe(14);
|
|
103
98
|
|
|
104
|
-
editor.
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("should update mapping for local transactions before the position (unmounted)", () => {
|
|
108
|
-
const editor = BlockNoteEditor.create();
|
|
109
|
-
|
|
110
|
-
// Set initial content
|
|
111
|
-
editor.insertBlocks(
|
|
112
|
-
[
|
|
113
|
-
{
|
|
114
|
-
id: "1",
|
|
115
|
-
type: "paragraph",
|
|
116
|
-
content: [
|
|
117
|
-
{
|
|
118
|
-
type: "text",
|
|
119
|
-
text: "Hello World",
|
|
120
|
-
styles: {},
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
editor.document[0],
|
|
126
|
-
"before",
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
// Start tracking
|
|
130
|
-
const getPos = trackPosition(editor, 10);
|
|
131
|
-
|
|
132
|
-
// Move the cursor to the start of the document
|
|
133
|
-
editor.setTextCursorPosition(editor.document[0], "start");
|
|
134
|
-
|
|
135
|
-
// Insert text at the start of the document
|
|
136
|
-
editor.insertInlineContent([
|
|
137
|
-
{
|
|
138
|
-
type: "text",
|
|
139
|
-
text: "Test",
|
|
140
|
-
styles: {},
|
|
141
|
-
},
|
|
142
|
-
]);
|
|
143
|
-
|
|
144
|
-
// Position should be updated according to mapping
|
|
145
|
-
expect(getPos()).toBe(14);
|
|
146
|
-
|
|
147
|
-
editor._tiptapEditor.destroy();
|
|
99
|
+
editor.unmount();
|
|
148
100
|
});
|
|
149
101
|
|
|
150
102
|
it("should not update mapping for local transactions after the position", () => {
|
|
@@ -187,7 +139,7 @@ describe("PositionStorage with local editor", () => {
|
|
|
187
139
|
// Position should not be updated
|
|
188
140
|
expect(getPos()).toBe(10);
|
|
189
141
|
|
|
190
|
-
editor.
|
|
142
|
+
editor.unmount();
|
|
191
143
|
});
|
|
192
144
|
|
|
193
145
|
it("should track positions on each side", () => {
|
|
@@ -217,7 +169,7 @@ describe("PositionStorage with local editor", () => {
|
|
|
217
169
|
expect(getPosAfterPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
218
170
|
expect(getPosAfterRightPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
219
171
|
|
|
220
|
-
editor.
|
|
172
|
+
editor.unmount();
|
|
221
173
|
});
|
|
222
174
|
|
|
223
175
|
it("should handle multiple transactions", () => {
|
|
@@ -252,283 +204,6 @@ describe("PositionStorage with local editor", () => {
|
|
|
252
204
|
expect(getPosAfterPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
253
205
|
expect(getPosAfterRightPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
254
206
|
|
|
255
|
-
editor.
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
describe("PositionStorage with remote editor", () => {
|
|
260
|
-
// Function to sync two documents
|
|
261
|
-
function syncDocs(sourceDoc: Y.Doc, targetDoc: Y.Doc) {
|
|
262
|
-
// Create update message from source
|
|
263
|
-
const update = Y.encodeStateAsUpdate(sourceDoc);
|
|
264
|
-
|
|
265
|
-
// Apply update to target
|
|
266
|
-
Y.applyUpdate(targetDoc, update);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// Set up two-way sync
|
|
270
|
-
function setupTwoWaySync(doc1: Y.Doc, doc2: Y.Doc) {
|
|
271
|
-
// Sync initial states
|
|
272
|
-
syncDocs(doc1, doc2);
|
|
273
|
-
syncDocs(doc2, doc1);
|
|
274
|
-
|
|
275
|
-
// Set up observers for future changes
|
|
276
|
-
doc1.on("update", (update: Uint8Array) => {
|
|
277
|
-
Y.applyUpdate(doc2, update);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
doc2.on("update", (update: Uint8Array) => {
|
|
281
|
-
Y.applyUpdate(doc1, update);
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
describe("remote editor", () => {
|
|
286
|
-
it("should update the local position when collaborating", () => {
|
|
287
|
-
const ydoc = new Y.Doc();
|
|
288
|
-
const remoteYdoc = new Y.Doc();
|
|
289
|
-
|
|
290
|
-
// Create a mock editor
|
|
291
|
-
const localEditor = BlockNoteEditor.create({
|
|
292
|
-
collaboration: {
|
|
293
|
-
fragment: ydoc.getXmlFragment("doc"),
|
|
294
|
-
user: { color: "#ff0000", name: "Local User" },
|
|
295
|
-
provider: undefined,
|
|
296
|
-
},
|
|
297
|
-
});
|
|
298
|
-
const div = document.createElement("div");
|
|
299
|
-
localEditor.mount(div);
|
|
300
|
-
|
|
301
|
-
const remoteEditor = BlockNoteEditor.create({
|
|
302
|
-
collaboration: {
|
|
303
|
-
fragment: remoteYdoc.getXmlFragment("doc"),
|
|
304
|
-
user: { color: "#ff0000", name: "Remote User" },
|
|
305
|
-
provider: undefined,
|
|
306
|
-
},
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
const remoteDiv = document.createElement("div");
|
|
310
|
-
remoteEditor.mount(remoteDiv);
|
|
311
|
-
setupTwoWaySync(ydoc, remoteYdoc);
|
|
312
|
-
|
|
313
|
-
localEditor.replaceBlocks(localEditor.document, [
|
|
314
|
-
{
|
|
315
|
-
type: "paragraph",
|
|
316
|
-
content: "Hello World",
|
|
317
|
-
},
|
|
318
|
-
]);
|
|
319
|
-
|
|
320
|
-
// Store position at "Hello| World"
|
|
321
|
-
const getCursorPos = trackPosition(localEditor, 6);
|
|
322
|
-
// Store position at "|Hello World"
|
|
323
|
-
const getStartPos = trackPosition(localEditor, 3);
|
|
324
|
-
// Store position at "|Hello World" (but on the right side)
|
|
325
|
-
const getStartRightPos = trackPosition(localEditor, 3, "right");
|
|
326
|
-
// Store position at "H|ello World"
|
|
327
|
-
const getPosAfterPos = trackPosition(localEditor, 4);
|
|
328
|
-
// Store position at "H|ello World" (but on the right side)
|
|
329
|
-
const getPosAfterRightPos = trackPosition(localEditor, 4, "right");
|
|
330
|
-
|
|
331
|
-
// Insert text at the beginning
|
|
332
|
-
localEditor._tiptapEditor.commands.insertContentAt(3, "Test ");
|
|
333
|
-
|
|
334
|
-
// Position should be updated
|
|
335
|
-
expect(getCursorPos()).toBe(11); // 6 + 5 ("Test " length)
|
|
336
|
-
expect(getStartPos()).toBe(3); // 3
|
|
337
|
-
expect(getStartRightPos()).toBe(8); // 3 + 5 ("Test " length)
|
|
338
|
-
expect(getPosAfterPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
339
|
-
expect(getPosAfterRightPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
340
|
-
|
|
341
|
-
ydoc.destroy();
|
|
342
|
-
remoteYdoc.destroy();
|
|
343
|
-
localEditor._tiptapEditor.destroy();
|
|
344
|
-
remoteEditor._tiptapEditor.destroy();
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
it("should handle multiple transactions when collaborating", () => {
|
|
348
|
-
const ydoc = new Y.Doc();
|
|
349
|
-
const remoteYdoc = new Y.Doc();
|
|
350
|
-
|
|
351
|
-
// Create a mock editor
|
|
352
|
-
const localEditor = BlockNoteEditor.create({
|
|
353
|
-
collaboration: {
|
|
354
|
-
fragment: ydoc.getXmlFragment("doc"),
|
|
355
|
-
user: { color: "#ff0000", name: "Local User" },
|
|
356
|
-
provider: undefined,
|
|
357
|
-
},
|
|
358
|
-
});
|
|
359
|
-
const div = document.createElement("div");
|
|
360
|
-
localEditor.mount(div);
|
|
361
|
-
|
|
362
|
-
const remoteEditor = BlockNoteEditor.create({
|
|
363
|
-
collaboration: {
|
|
364
|
-
fragment: remoteYdoc.getXmlFragment("doc"),
|
|
365
|
-
user: { color: "#ff0000", name: "Remote User" },
|
|
366
|
-
provider: undefined,
|
|
367
|
-
},
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
const remoteDiv = document.createElement("div");
|
|
371
|
-
remoteEditor.mount(remoteDiv);
|
|
372
|
-
setupTwoWaySync(ydoc, remoteYdoc);
|
|
373
|
-
|
|
374
|
-
localEditor.replaceBlocks(localEditor.document, [
|
|
375
|
-
{
|
|
376
|
-
type: "paragraph",
|
|
377
|
-
content: "Hello World",
|
|
378
|
-
},
|
|
379
|
-
]);
|
|
380
|
-
|
|
381
|
-
// Store position at "Hello| World"
|
|
382
|
-
const getCursorPos = trackPosition(localEditor, 6);
|
|
383
|
-
// Store position at "|Hello World"
|
|
384
|
-
const getStartPos = trackPosition(localEditor, 3);
|
|
385
|
-
// Store position at "|Hello World" (but on the right side)
|
|
386
|
-
const getStartRightPos = trackPosition(localEditor, 3, "right");
|
|
387
|
-
// Store position at "H|ello World"
|
|
388
|
-
const getPosAfterPos = trackPosition(localEditor, 4);
|
|
389
|
-
// Store position at "H|ello World" (but on the right side)
|
|
390
|
-
const getPosAfterRightPos = trackPosition(localEditor, 4, "right");
|
|
391
|
-
|
|
392
|
-
// Insert text at the beginning
|
|
393
|
-
localEditor._tiptapEditor.commands.insertContentAt(3, "T");
|
|
394
|
-
localEditor._tiptapEditor.commands.insertContentAt(4, "e");
|
|
395
|
-
localEditor._tiptapEditor.commands.insertContentAt(5, "s");
|
|
396
|
-
localEditor._tiptapEditor.commands.insertContentAt(6, "t");
|
|
397
|
-
localEditor._tiptapEditor.commands.insertContentAt(7, " ");
|
|
398
|
-
|
|
399
|
-
// Position should be updated
|
|
400
|
-
expect(getCursorPos()).toBe(11); // 6 + 5 ("Test " length)
|
|
401
|
-
expect(getStartPos()).toBe(3); // 3
|
|
402
|
-
expect(getStartRightPos()).toBe(8); // 3 + 5 ("Test " length)
|
|
403
|
-
expect(getPosAfterPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
404
|
-
expect(getPosAfterRightPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
405
|
-
|
|
406
|
-
ydoc.destroy();
|
|
407
|
-
remoteYdoc.destroy();
|
|
408
|
-
localEditor._tiptapEditor.destroy();
|
|
409
|
-
remoteEditor._tiptapEditor.destroy();
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
it("should update the local position from a remote transaction", () => {
|
|
413
|
-
const ydoc = new Y.Doc();
|
|
414
|
-
const remoteYdoc = new Y.Doc();
|
|
415
|
-
|
|
416
|
-
// Create a mock editor
|
|
417
|
-
const localEditor = BlockNoteEditor.create({
|
|
418
|
-
collaboration: {
|
|
419
|
-
fragment: ydoc.getXmlFragment("doc"),
|
|
420
|
-
user: { color: "#ff0000", name: "Local User" },
|
|
421
|
-
provider: undefined,
|
|
422
|
-
},
|
|
423
|
-
});
|
|
424
|
-
const div = document.createElement("div");
|
|
425
|
-
localEditor.mount(div);
|
|
426
|
-
|
|
427
|
-
const remoteEditor = BlockNoteEditor.create({
|
|
428
|
-
collaboration: {
|
|
429
|
-
fragment: remoteYdoc.getXmlFragment("doc"),
|
|
430
|
-
user: { color: "#ff0000", name: "Remote User" },
|
|
431
|
-
provider: undefined,
|
|
432
|
-
},
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
const remoteDiv = document.createElement("div");
|
|
436
|
-
remoteEditor.mount(remoteDiv);
|
|
437
|
-
setupTwoWaySync(ydoc, remoteYdoc);
|
|
438
|
-
|
|
439
|
-
remoteEditor.replaceBlocks(remoteEditor.document, [
|
|
440
|
-
{
|
|
441
|
-
type: "paragraph",
|
|
442
|
-
content: "Hello World",
|
|
443
|
-
},
|
|
444
|
-
]);
|
|
445
|
-
|
|
446
|
-
// Store position at "Hello| World"
|
|
447
|
-
const getCursorPos = trackPosition(localEditor, 6);
|
|
448
|
-
// Store position at "|Hello World"
|
|
449
|
-
const getStartPos = trackPosition(localEditor, 3);
|
|
450
|
-
// Store position at "|Hello World" (but on the right side)
|
|
451
|
-
const getStartRightPos = trackPosition(localEditor, 3, "right");
|
|
452
|
-
// Store position at "H|ello World"
|
|
453
|
-
const getPosAfterPos = trackPosition(localEditor, 4);
|
|
454
|
-
// Store position at "H|ello World" (but on the right side)
|
|
455
|
-
const getPosAfterRightPos = trackPosition(localEditor, 4, "right");
|
|
456
|
-
|
|
457
|
-
// Insert text at the beginning
|
|
458
|
-
localEditor._tiptapEditor.commands.insertContentAt(3, "Test ");
|
|
459
|
-
|
|
460
|
-
// Position should be updated
|
|
461
|
-
expect(getCursorPos()).toBe(11); // 6 + 5 ("Test " length)
|
|
462
|
-
expect(getStartPos()).toBe(3); // 3
|
|
463
|
-
expect(getStartRightPos()).toBe(8); // 3 + 5 ("Test " length)
|
|
464
|
-
expect(getPosAfterPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
465
|
-
expect(getPosAfterRightPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
466
|
-
|
|
467
|
-
ydoc.destroy();
|
|
468
|
-
remoteYdoc.destroy();
|
|
469
|
-
localEditor._tiptapEditor.destroy();
|
|
470
|
-
remoteEditor._tiptapEditor.destroy();
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
it("should update the remote position from a remote transaction", () => {
|
|
474
|
-
const ydoc = new Y.Doc();
|
|
475
|
-
const remoteYdoc = new Y.Doc();
|
|
476
|
-
|
|
477
|
-
// Create a mock editor
|
|
478
|
-
const localEditor = BlockNoteEditor.create({
|
|
479
|
-
collaboration: {
|
|
480
|
-
fragment: ydoc.getXmlFragment("doc"),
|
|
481
|
-
user: { color: "#ff0000", name: "Local User" },
|
|
482
|
-
provider: undefined,
|
|
483
|
-
},
|
|
484
|
-
});
|
|
485
|
-
const div = document.createElement("div");
|
|
486
|
-
localEditor.mount(div);
|
|
487
|
-
|
|
488
|
-
const remoteEditor = BlockNoteEditor.create({
|
|
489
|
-
collaboration: {
|
|
490
|
-
fragment: remoteYdoc.getXmlFragment("doc"),
|
|
491
|
-
user: { color: "#ff0000", name: "Remote User" },
|
|
492
|
-
provider: undefined,
|
|
493
|
-
},
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
const remoteDiv = document.createElement("div");
|
|
497
|
-
remoteEditor.mount(remoteDiv);
|
|
498
|
-
setupTwoWaySync(ydoc, remoteYdoc);
|
|
499
|
-
|
|
500
|
-
remoteEditor.replaceBlocks(remoteEditor.document, [
|
|
501
|
-
{
|
|
502
|
-
type: "paragraph",
|
|
503
|
-
content: "Hello World",
|
|
504
|
-
},
|
|
505
|
-
]);
|
|
506
|
-
|
|
507
|
-
// Store position at "Hello| World"
|
|
508
|
-
const getCursorPos = trackPosition(remoteEditor, 6);
|
|
509
|
-
// Store position at "|Hello World"
|
|
510
|
-
const getStartPos = trackPosition(remoteEditor, 3);
|
|
511
|
-
// Store position at "|Hello World" (but on the right side)
|
|
512
|
-
const getStartRightPos = trackPosition(remoteEditor, 3, "right");
|
|
513
|
-
// Store position at "H|ello World"
|
|
514
|
-
const getPosAfterPos = trackPosition(remoteEditor, 4);
|
|
515
|
-
// Store position at "H|ello World" (but on the right side)
|
|
516
|
-
const getPosAfterRightPos = trackPosition(remoteEditor, 4, "right");
|
|
517
|
-
|
|
518
|
-
// Insert text at the beginning
|
|
519
|
-
localEditor._tiptapEditor.commands.insertContentAt(3, "Test ");
|
|
520
|
-
|
|
521
|
-
// Position should be updated
|
|
522
|
-
expect(getCursorPos()).toBe(11); // 6 + 5 ("Test " length)
|
|
523
|
-
expect(getStartPos()).toBe(3); // 3
|
|
524
|
-
expect(getStartRightPos()).toBe(8); // 3 + 5 ("Test " length)
|
|
525
|
-
expect(getPosAfterPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
526
|
-
expect(getPosAfterRightPos()).toBe(9); // 4 + 5 ("Test " length)
|
|
527
|
-
|
|
528
|
-
ydoc.destroy();
|
|
529
|
-
remoteYdoc.destroy();
|
|
530
|
-
localEditor._tiptapEditor.destroy();
|
|
531
|
-
remoteEditor._tiptapEditor.destroy();
|
|
532
|
-
});
|
|
207
|
+
editor.unmount();
|
|
533
208
|
});
|
|
534
209
|
});
|
|
@@ -1,40 +1,5 @@
|
|
|
1
|
-
import { Mapping } from "prosemirror-transform";
|
|
2
|
-
import {
|
|
3
|
-
absolutePositionToRelativePosition,
|
|
4
|
-
relativePositionToAbsolutePosition,
|
|
5
|
-
ySyncPluginKey,
|
|
6
|
-
} from "y-prosemirror";
|
|
7
1
|
import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
8
|
-
import
|
|
9
|
-
import type { ProsemirrorBinding } from "y-prosemirror";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* This is used to track a mapping for each editor. The mapping stores the mappings for each transaction since the first transaction that was tracked.
|
|
13
|
-
*/
|
|
14
|
-
const editorToMapping = new Map<BlockNoteEditor<any, any, any>, Mapping>();
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* This initializes a single mapping for an editor instance.
|
|
18
|
-
*/
|
|
19
|
-
function getMapping(editor: BlockNoteEditor<any, any, any>) {
|
|
20
|
-
if (editorToMapping.has(editor)) {
|
|
21
|
-
// Mapping already initialized, so we don't need to do anything
|
|
22
|
-
return editorToMapping.get(editor)!;
|
|
23
|
-
}
|
|
24
|
-
const mapping = new Mapping();
|
|
25
|
-
editor._tiptapEditor.on("transaction", ({ transaction }) => {
|
|
26
|
-
mapping.appendMapping(transaction.mapping);
|
|
27
|
-
});
|
|
28
|
-
editor._tiptapEditor.on("destroy", () => {
|
|
29
|
-
// Cleanup the mapping when the editor is destroyed
|
|
30
|
-
editorToMapping.delete(editor);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// There only is one mapping per editor, so we can just set it
|
|
34
|
-
editorToMapping.set(editor, mapping);
|
|
35
|
-
|
|
36
|
-
return mapping;
|
|
37
|
-
}
|
|
2
|
+
import type { PositionMappingExtension } from "../extensions/PositionMapping/PositionMapping.js";
|
|
38
3
|
|
|
39
4
|
/**
|
|
40
5
|
* This is used to keep track of positions of elements in the editor.
|
|
@@ -61,52 +26,17 @@ export function trackPosition(
|
|
|
61
26
|
*/
|
|
62
27
|
side: "left" | "right" = "left",
|
|
63
28
|
): () => number {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (!ySyncPluginState) {
|
|
70
|
-
// No y-prosemirror sync plugin, so we need to track the mapping manually
|
|
71
|
-
// This will initialize the mapping for this editor, if needed
|
|
72
|
-
const mapping = getMapping(editor);
|
|
73
|
-
|
|
74
|
-
// This is the start point of tracking the mapping
|
|
75
|
-
const trackedMapLength = mapping.maps.length;
|
|
76
|
-
|
|
77
|
-
return () => {
|
|
78
|
-
const pos = mapping
|
|
79
|
-
// Only read the history of the mapping that we care about
|
|
80
|
-
.slice(trackedMapLength)
|
|
81
|
-
.map(position, side === "left" ? -1 : 1);
|
|
82
|
-
|
|
83
|
-
return pos;
|
|
84
|
-
};
|
|
29
|
+
// Try to use the Yjs Relative Position Mapping Extension
|
|
30
|
+
const yPositionMappingExtension =
|
|
31
|
+
editor.getExtension<typeof PositionMappingExtension>("yPositionMapping");
|
|
32
|
+
if (yPositionMappingExtension) {
|
|
33
|
+
return yPositionMappingExtension.mapPosition(position, side);
|
|
85
34
|
}
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
return () => {
|
|
95
|
-
const curYSyncPluginState = ySyncPluginKey.getState(
|
|
96
|
-
editor.prosemirrorState,
|
|
97
|
-
) as typeof ySyncPluginState;
|
|
98
|
-
const pos = relativePositionToAbsolutePosition(
|
|
99
|
-
curYSyncPluginState.doc,
|
|
100
|
-
curYSyncPluginState.binding.type,
|
|
101
|
-
relativePosition,
|
|
102
|
-
curYSyncPluginState.binding.mapping,
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
// This can happen if the element is garbage collected
|
|
106
|
-
if (pos === null) {
|
|
107
|
-
throw new Error("Position not found, cannot track positions");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return pos + (side === "right" ? -1 : 1);
|
|
111
|
-
};
|
|
35
|
+
// Fallback to the Prosemirror Position Mapping Extension
|
|
36
|
+
const positionMappingExtension =
|
|
37
|
+
editor.getExtension<typeof PositionMappingExtension>("positionMapping");
|
|
38
|
+
if (positionMappingExtension) {
|
|
39
|
+
return positionMappingExtension.mapPosition(position, side);
|
|
40
|
+
}
|
|
41
|
+
throw new Error("No position mapping extension found");
|
|
112
42
|
}
|
|
@@ -100,7 +100,7 @@ export const audioRender =
|
|
|
100
100
|
const audio = document.createElement("audio");
|
|
101
101
|
audio.className = "bn-audio";
|
|
102
102
|
if (editor.resolveFileUrl) {
|
|
103
|
-
editor.resolveFileUrl(block.props.url).then((downloadUrl) => {
|
|
103
|
+
void editor.resolveFileUrl(block.props.url).then((downloadUrl) => {
|
|
104
104
|
audio.src = downloadUrl;
|
|
105
105
|
});
|
|
106
106
|
} else {
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
afterAll,
|
|
3
|
+
beforeAll,
|
|
4
|
+
beforeEach,
|
|
5
|
+
describe,
|
|
6
|
+
expect,
|
|
7
|
+
it,
|
|
8
|
+
} from "vite-plus/test";
|
|
2
9
|
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
3
10
|
import type { PartialBlock } from "../defaultBlocks.js";
|
|
4
11
|
import { getLanguageId, type CodeBlockOptions } from "./block.js";
|
|
@@ -179,9 +186,9 @@ describe("Code block input rule", () => {
|
|
|
179
186
|
const after = editor.document[0];
|
|
180
187
|
expect(after.type).toBe("codeBlock");
|
|
181
188
|
expect(after.id).toBe(block.id);
|
|
182
|
-
expect(
|
|
183
|
-
"hello",
|
|
184
|
-
);
|
|
189
|
+
expect(after.content).toEqual([
|
|
190
|
+
{ type: "text", text: "hello", styles: {} },
|
|
191
|
+
]);
|
|
185
192
|
});
|
|
186
193
|
|
|
187
194
|
it("places cursor inside the new code block after Enter conversion", () => {
|
|
@@ -198,9 +205,9 @@ describe("Code block input rule", () => {
|
|
|
198
205
|
const after = editor.document[0];
|
|
199
206
|
expect(after.type).toBe("codeBlock");
|
|
200
207
|
expect(after.id).toBe(block.id);
|
|
201
|
-
expect(
|
|
202
|
-
"world",
|
|
203
|
-
);
|
|
208
|
+
expect(after.content).toEqual([
|
|
209
|
+
{ type: "text", text: "world", styles: {} },
|
|
210
|
+
]);
|
|
204
211
|
});
|
|
205
212
|
|
|
206
213
|
it("Enter inside an existing code block does not retrigger conversion", () => {
|
package/src/blocks/Code/block.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { HighlighterGeneric } from "@shikijs/types";
|
|
2
|
+
import { DOMParser } from "@tiptap/pm/model";
|
|
2
3
|
import { createExtension } from "../../editor/BlockNoteExtension.js";
|
|
3
4
|
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
|
|
4
5
|
import { lazyShikiPlugin } from "./shiki.js";
|
|
5
|
-
import { DOMParser } from "@tiptap/pm/model";
|
|
6
6
|
|
|
7
7
|
export type CodeBlockOptions = {
|
|
8
8
|
/**
|
|
@@ -62,7 +62,7 @@ export const createCodeBlockConfig = createBlockConfig(
|
|
|
62
62
|
default: defaultLanguage,
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
|
-
content: "
|
|
65
|
+
content: "plain",
|
|
66
66
|
}) as const,
|
|
67
67
|
);
|
|
68
68
|
|
|
@@ -109,7 +109,7 @@ export const imageRender =
|
|
|
109
109
|
const image = document.createElement("img");
|
|
110
110
|
image.className = "bn-visual-media";
|
|
111
111
|
if (editor.resolveFileUrl) {
|
|
112
|
-
editor.resolveFileUrl(block.props.url).then((downloadUrl) => {
|
|
112
|
+
void editor.resolveFileUrl(block.props.url).then((downloadUrl) => {
|
|
113
113
|
image.src = downloadUrl;
|
|
114
114
|
});
|
|
115
115
|
} else {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { splitBlockCommand } from "../../api/blockManipulation/commands/splitBlock/splitBlock.js";
|
|
2
2
|
import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js";
|
|
4
4
|
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
5
5
|
|
|
6
6
|
export const handleEnter = (editor: BlockNoteEditor<any, any, any>) => {
|
|
7
7
|
const { blockInfo, selectionEmpty } = editor.transact((tr) => {
|
|
8
8
|
return {
|
|
9
|
-
blockInfo:
|
|
9
|
+
blockInfo: getBlockInfoFromSelection(tr),
|
|
10
10
|
selectionEmpty: tr.selection.anchor === tr.selection.head,
|
|
11
11
|
};
|
|
12
12
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Selection } from "prosemirror-state";
|
|
2
|
-
import { afterEach, describe, expect, it } from "
|
|
2
|
+
import { afterEach, describe, expect, it } from "vite-plus/test";
|
|
3
3
|
|
|
4
4
|
import { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
|
|
5
5
|
|
|
@@ -30,9 +30,7 @@ function createEditor() {
|
|
|
30
30
|
|
|
31
31
|
function getDecorationSet(editor: BlockNoteEditor<any, any, any>) {
|
|
32
32
|
const view = editor._tiptapEditor.view;
|
|
33
|
-
const plugin = view.state.plugins.find(
|
|
34
|
-
(p) => (p as any).key === PLUGIN_KEY,
|
|
35
|
-
);
|
|
33
|
+
const plugin = view.state.plugins.find((p) => (p as any).key === PLUGIN_KEY);
|
|
36
34
|
if (!plugin) {
|
|
37
35
|
throw new Error("IndexingPlugin not found");
|
|
38
36
|
}
|
|
@@ -54,8 +52,7 @@ function getDataIndices(editor: BlockNoteEditor<any, any, any>) {
|
|
|
54
52
|
const decos = decoSet.find(0, doc.nodeSize - 2);
|
|
55
53
|
return decos.map((d: any) => {
|
|
56
54
|
// Decoration attrs are stored on the decoration object
|
|
57
|
-
const attrs =
|
|
58
|
-
(d as any).type?.attrs ?? (d as any).attrs ?? (d as any).type;
|
|
55
|
+
const attrs = (d as any).type?.attrs ?? (d as any).attrs ?? (d as any).type;
|
|
59
56
|
return parseInt(attrs["data-index"], 10);
|
|
60
57
|
});
|
|
61
58
|
}
|
|
@@ -287,11 +284,7 @@ describe("IndexingPlugin: typing preserves indices (early exit)", () => {
|
|
|
287
284
|
const view = editor._tiptapEditor.view;
|
|
288
285
|
let targetPos = 0;
|
|
289
286
|
view.state.doc.descendants((node, pos) => {
|
|
290
|
-
if (
|
|
291
|
-
node.type.name === "numberedListItem" &&
|
|
292
|
-
targetPos === 0 &&
|
|
293
|
-
pos > 4
|
|
294
|
-
) {
|
|
287
|
+
if (node.type.name === "numberedListItem" && targetPos === 0 && pos > 4) {
|
|
295
288
|
targetPos = pos + 1; // inside the inline content
|
|
296
289
|
}
|
|
297
290
|
});
|