@blocknote/core 0.51.3 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BlockNoteExtension-B_IEJHS8.js +38 -0
- package/dist/BlockNoteExtension-B_IEJHS8.js.map +1 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs +2 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs.map +1 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs +2 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs.map +1 -0
- package/dist/ThreadStore-et9wB5Xt.js +11 -0
- package/dist/ThreadStore-et9wB5Xt.js.map +1 -0
- package/dist/UserStore-DCG6lsla.cjs +2 -0
- package/dist/UserStore-DCG6lsla.cjs.map +1 -0
- package/dist/UserStore-QbbPFj0z.js +73 -0
- package/dist/UserStore-QbbPFj0z.js.map +1 -0
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -7
- package/dist/blocks-BqHv0xhc.cjs +12 -0
- package/dist/blocks-BqHv0xhc.cjs.map +1 -0
- package/dist/{blocks-D0lMxErU.js → blocks-CiuUGa1E.js} +1096 -998
- package/dist/blocks-CiuUGa1E.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +75 -340
- package/dist/comments.js.map +1 -1
- package/dist/{en-Cj5r8sW_.cjs → en-C5Z4Ag9_.cjs} +2 -2
- package/dist/en-C5Z4Ag9_.cjs.map +1 -0
- package/dist/{en-B9hMApn4.js → en-CGKXfWma.js} +9 -1
- package/dist/en-CGKXfWma.js.map +1 -0
- package/dist/{extensions-D2mx2C9y.js → extensions-CrUGDOks.js} +655 -583
- package/dist/extensions-CrUGDOks.js.map +1 -0
- package/dist/extensions-Ghr9QqqR.cjs +52 -0
- package/dist/extensions-Ghr9QqqR.cjs.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +4 -4
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +177 -1
- package/dist/locales.js.map +1 -1
- package/dist/{src-Dvmif2FY.js → src-DTF83Cl9.js} +1243 -1297
- package/dist/src-DTF83Cl9.js.map +1 -0
- package/dist/src-OfbaVbMw.cjs +21 -0
- package/dist/src-OfbaVbMw.cjs.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +2 -0
- package/dist/y.cjs.map +1 -0
- package/dist/y.js +989 -0
- package/dist/y.js.map +1 -0
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +535 -14
- package/dist/yjs.js.map +1 -1
- package/package.json +46 -19
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +25 -20
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +39 -29
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +2 -2
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +4 -8
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +21 -9
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +6 -5
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +362 -4
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +240 -30
- package/src/api/blockManipulation/getBlock/getBlock.ts +4 -9
- package/src/api/blockManipulation/selections/selection.ts +3 -6
- package/src/api/blockManipulation/selections/textCursorPosition.ts +10 -10
- package/src/api/blockManipulation/setupTestEnv.ts +1 -1
- package/src/api/blockManipulation/tables/tables.test.ts +1 -1
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +1 -1
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +8 -4
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +2 -1
- package/src/api/exporters/markdown/htmlToMarkdown.ts +79 -43
- package/src/api/getBlockInfoFromPos.test.ts +256 -0
- package/src/api/getBlockInfoFromPos.ts +53 -15
- package/src/api/getBlocksChangedByTransaction.test.ts +2 -1
- package/src/api/getBlocksChangedByTransaction.ts +6 -6
- package/src/api/nodeConversions/blockToNode.test.ts +113 -0
- package/src/api/nodeConversions/blockToNode.ts +15 -3
- package/src/api/nodeConversions/fragmentToBlocks.ts +2 -4
- package/src/api/nodeConversions/nodeToBlock.ts +28 -58
- package/src/api/nodeUtil.ts +6 -2
- package/src/api/parsers/html/parseHTML.ts +1 -1
- package/src/api/parsers/html/util/nestedLists.test.ts +1 -1
- package/src/api/parsers/markdown/detectMarkdown.test.ts +1 -1
- package/src/api/parsers/markdown/markdownToHtml.ts +228 -82
- package/src/api/pmUtil.ts +18 -1
- package/src/api/positionMapping.test.ts +20 -345
- package/src/api/positionMapping.ts +13 -83
- package/src/blocks/Audio/block.ts +1 -1
- package/src/blocks/Code/block.test.ts +14 -7
- package/src/blocks/Code/block.ts +2 -2
- package/src/blocks/Image/block.ts +1 -1
- package/src/blocks/ListItem/CheckListItem/block.test.ts +1 -1
- package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +2 -2
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +4 -11
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +47 -50
- package/src/blocks/Table/TableExtension.test.ts +129 -0
- package/src/blocks/Table/TableExtension.ts +23 -20
- package/src/blocks/Table/block.ts +18 -5
- package/src/blocks/Video/block.ts +1 -1
- package/src/blocks/utils/listItemEnterHandler.ts +3 -2
- package/src/comments/extension.ts +30 -21
- package/src/comments/index.ts +0 -3
- package/src/comments/mark.ts +4 -0
- package/src/comments/threadstore/ThreadStore.ts +4 -8
- package/src/comments/types.ts +0 -8
- package/src/editor/Block.css +307 -3
- package/src/editor/BlockNoteEditor.test.ts +39 -18
- package/src/editor/BlockNoteEditor.ts +22 -57
- package/src/editor/BlockNoteExtension.test.ts +1 -1
- package/src/editor/managers/BlockManager.ts +1 -1
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +249 -0
- package/src/editor/managers/ExtensionManager/extensions.ts +7 -18
- package/src/editor/managers/ExtensionManager/index.ts +168 -68
- package/src/editor/managers/StateManager.ts +4 -3
- package/src/editor/performance.test.ts +14 -1
- package/src/editor/transformPasted.test.ts +1 -1
- package/src/extensions/Placeholder/Placeholder.ts +1 -0
- package/src/extensions/PositionMapping/PositionMapping.ts +68 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +14 -1
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +14 -11
- package/src/extensions/SideMenu/SideMenu.ts +9 -2
- package/src/extensions/SuggestionMenu/SuggestionMenu.test.ts +1 -1
- package/src/extensions/TableHandles/TableHandles.ts +18 -20
- package/src/extensions/TrailingNode/TrailingNode.ts +33 -1
- package/src/extensions/Versioning/Versioning.test.ts +435 -0
- package/src/extensions/Versioning/Versioning.ts +628 -0
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +469 -0
- package/src/extensions/Versioning/inMemoryVersioning.ts +263 -0
- package/src/extensions/Versioning/index.ts +2 -0
- package/src/extensions/index.ts +6 -9
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +155 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +6 -8
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +9 -9
- package/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts +8 -10
- package/src/extensions/tiptap-extensions/Link/helpers/whitespace.ts +2 -2
- package/src/extensions/tiptap-extensions/Link/link.test.ts +26 -22
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +187 -0
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +37 -24
- package/src/extensions/tiptap-extensions/index.ts +1 -25
- package/src/i18n/locales/ar.ts +9 -0
- package/src/i18n/locales/de.ts +9 -0
- package/src/i18n/locales/en.ts +10 -1
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fa.ts +11 -1
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/he.ts +10 -1
- package/src/i18n/locales/hr.ts +10 -0
- package/src/i18n/locales/is.ts +10 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/ja.ts +9 -0
- package/src/i18n/locales/ko.ts +9 -0
- package/src/i18n/locales/nl.ts +10 -0
- package/src/i18n/locales/no.ts +10 -0
- package/src/i18n/locales/pl.ts +9 -0
- package/src/i18n/locales/pt.ts +10 -0
- package/src/i18n/locales/ru.ts +10 -0
- package/src/i18n/locales/sk.ts +10 -1
- package/src/i18n/locales/uk.ts +9 -0
- package/src/i18n/locales/uz.ts +9 -0
- package/src/i18n/locales/vi.ts +9 -0
- package/src/i18n/locales/zh-tw.ts +9 -0
- package/src/i18n/locales/zh.ts +9 -0
- package/src/index.ts +2 -0
- package/src/pm-nodes/BlockContainer.ts +4 -1
- package/src/pm-nodes/BlockGroup.ts +4 -1
- package/src/pm-nodes/Doc.ts +4 -1
- package/src/pm-nodes/suggestionMarks.ts +43 -0
- package/src/schema/blocks/createSpec.test.ts +123 -0
- package/src/schema/blocks/createSpec.ts +82 -24
- package/src/schema/blocks/extendBlockSpec.test.ts +188 -0
- package/src/schema/blocks/internal.ts +13 -43
- package/src/schema/blocks/types.ts +69 -22
- package/src/schema/contentTypePropagation.test.ts +182 -0
- package/src/schema/index.ts +1 -0
- package/src/schema/inlineContent/internal.ts +1 -1
- package/src/schema/inlineContent/types.ts +3 -3
- package/src/schema/markGroups.ts +50 -0
- package/src/user/UserStore.ts +199 -0
- package/src/user/createUserStore.test.ts +126 -0
- package/src/user/index.ts +2 -0
- package/src/user/userColors.ts +72 -0
- package/src/util/string.ts +1 -1
- package/src/util/topo-sort.test.ts +1 -1
- package/src/util/typescript.ts +2 -1
- package/src/vite-env.d.ts +1 -1
- package/src/y/README.md +5 -0
- package/src/{comments/threadstore/yjs → y/comments}/RESTYjsThreadStore.ts +8 -14
- package/src/y/comments/YjsThreadStore.test.ts +295 -0
- package/src/y/comments/YjsThreadStore.ts +358 -0
- package/src/y/comments/YjsThreadStoreBase.ts +50 -0
- package/src/y/comments/index.ts +3 -0
- package/src/y/comments/yjsHelpers.ts +125 -0
- package/src/y/extensions/AttributionExtension.test.ts +86 -0
- package/src/y/extensions/AttributionExtension.ts +378 -0
- package/src/y/extensions/DiffVersioningExtension.test.ts +193 -0
- package/src/y/extensions/DiffVersioningExtension.ts +228 -0
- package/src/y/extensions/ForkYDoc.test.ts +253 -0
- package/src/y/extensions/ForkYDoc.ts +108 -0
- package/src/y/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/y/extensions/RelativePositionMapping.ts +49 -0
- package/src/y/extensions/Suggestions.ts +174 -0
- package/src/y/extensions/Versioning.test.ts +395 -0
- package/src/y/extensions/Versioning.ts +115 -0
- package/src/y/extensions/YAttributionMarks.ts +320 -0
- package/src/{extensions/Collaboration → y/extensions}/YCursorPlugin.ts +15 -7
- package/src/y/extensions/YSync.ts +125 -0
- package/src/y/extensions/blockMatchNodes.ts +182 -0
- package/src/y/extensions/index.ts +156 -0
- package/src/y/index.ts +4 -0
- package/src/y/utils.test.ts +1042 -0
- package/src/y/utils.ts +242 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.json +50 -0
- package/src/y/versioning/__test__/fixtures/activity-all.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all.json +20 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +32 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-before.json +1 -0
- package/src/y/versioning/__test__/fixtures/changeset.bin +0 -0
- package/src/y/versioning/__test__/fixtures/patch-response.json +4 -0
- package/src/y/versioning/__test__/yhub.test.ts +752 -0
- package/src/y/versioning/index.ts +1 -0
- package/src/y/versioning/yhub.ts +631 -0
- package/src/yjs/README.md +5 -0
- package/src/yjs/comments/RESTYjsThreadStore.ts +166 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.test.ts +3 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.ts +7 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.ts +3 -3
- package/src/yjs/comments/index.ts +3 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.ts +5 -1
- package/src/yjs/extensions/FixUpSchema.test.ts +421 -0
- package/src/yjs/extensions/FixUpSchema.ts +88 -0
- package/src/yjs/extensions/ForkYDoc.test.ts +216 -0
- package/src/{extensions/Collaboration → yjs/extensions}/ForkYDoc.ts +38 -57
- package/src/yjs/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/yjs/extensions/RelativePositionMapping.ts +71 -0
- package/src/yjs/extensions/Versioning.test.ts +549 -0
- package/src/yjs/extensions/Versioning.ts +83 -0
- package/src/yjs/extensions/YCursorPlugin.ts +201 -0
- package/src/{extensions/Collaboration → yjs/extensions}/YSync.ts +1 -1
- package/src/yjs/extensions/index.ts +89 -0
- package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.test.ts +1 -1
- package/src/yjs/index.ts +2 -0
- package/src/yjs/utils.test.ts +5 -15
- package/src/yjs/utils.ts +36 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +3 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
- package/types/src/api/getBlockInfoFromPos.d.ts +5 -9
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +4 -6
- package/types/src/api/pmUtil.d.ts +12 -1
- package/types/src/blocks/Audio/block.d.ts +2 -2
- package/types/src/blocks/Code/block.d.ts +2 -2
- package/types/src/blocks/File/block.d.ts +2 -2
- package/types/src/blocks/Heading/block.d.ts +21 -21
- package/types/src/blocks/Image/block.d.ts +3 -3
- package/types/src/blocks/ListItem/CheckListItem/block.d.ts +6 -6
- package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +6 -6
- package/types/src/blocks/Video/block.d.ts +3 -3
- package/types/src/blocks/defaultBlocks.d.ts +17 -17
- package/types/src/comments/extension.d.ts +18 -5
- package/types/src/comments/index.d.ts +0 -3
- package/types/src/comments/threadstore/ThreadStore.d.ts +4 -8
- package/types/src/comments/types.d.ts +0 -8
- package/types/src/editor/BlockNoteEditor.d.ts +8 -9
- package/types/src/editor/managers/BlockManager.d.ts +1 -1
- package/types/src/editor/managers/ExtensionManager/ExtensionManager.test.d.ts +1 -0
- package/types/src/editor/managers/ExtensionManager/extensions.d.ts +2 -2
- package/types/src/editor/managers/ExtensionManager/index.d.ts +13 -0
- package/types/src/editor/managers/SelectionManager.d.ts +1 -1
- package/types/src/extensions/PositionMapping/PositionMapping.d.ts +4 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -6
- package/types/src/extensions/Versioning/Versioning.d.ts +352 -0
- package/types/src/extensions/Versioning/Versioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +37 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/index.d.ts +2 -0
- package/types/src/extensions/index.d.ts +6 -9
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +1 -0
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.d.ts +6 -1
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.d.ts +4 -0
- package/types/src/extensions/tiptap-extensions/index.d.ts +1 -5
- package/types/src/i18n/locales/en.d.ts +9 -1
- package/types/src/i18n/locales/fa.d.ts +9 -1
- package/types/src/i18n/locales/sk.d.ts +9 -1
- package/types/src/index.d.ts +2 -0
- package/types/src/pm-nodes/suggestionMarks.d.ts +26 -0
- package/types/src/schema/blocks/createSpec.d.ts +4 -4
- package/types/src/schema/blocks/createSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/extendBlockSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/internal.d.ts +5 -7
- package/types/src/schema/blocks/types.d.ts +22 -14
- package/types/src/schema/contentTypePropagation.test.d.ts +1 -0
- package/types/src/schema/index.d.ts +1 -0
- package/types/src/schema/inlineContent/types.d.ts +3 -3
- package/types/src/schema/markGroups.d.ts +33 -0
- package/types/src/user/UserStore.d.ts +105 -0
- package/types/src/user/createUserStore.test.d.ts +1 -0
- package/types/src/user/index.d.ts +2 -0
- package/types/src/user/userColors.d.ts +36 -0
- package/types/src/y/comments/RESTYjsThreadStore.d.ts +77 -0
- package/types/src/y/comments/YjsThreadStore.d.ts +79 -0
- package/types/src/y/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/y/comments/YjsThreadStoreBase.d.ts +15 -0
- package/types/src/y/comments/index.d.ts +3 -0
- package/types/src/y/comments/yjsHelpers.d.ts +13 -0
- package/types/src/y/extensions/AttributionExtension.d.ts +74 -0
- package/types/src/y/extensions/AttributionExtension.test.d.ts +1 -0
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +69 -0
- package/types/src/y/extensions/DiffVersioningExtension.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → y/extensions}/ForkYDoc.d.ts +4 -2
- package/types/src/y/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/y/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/y/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/y/extensions/Suggestions.d.ts +36 -0
- package/types/src/y/extensions/Versioning.d.ts +17 -0
- package/types/src/y/extensions/Versioning.test.d.ts +1 -0
- package/types/src/y/extensions/YAttributionMarks.d.ts +67 -0
- package/types/src/y/extensions/YCursorPlugin.d.ts +14 -0
- package/types/src/y/extensions/YSync.d.ts +32 -0
- package/types/src/y/extensions/blockMatchNodes.d.ts +25 -0
- package/types/src/y/extensions/index.d.ts +189 -0
- package/types/src/y/index.d.ts +4 -0
- package/types/src/y/utils.d.ts +82 -0
- package/types/src/y/utils.test.d.ts +1 -0
- package/types/src/y/versioning/__test__/yhub.test.d.ts +1 -0
- package/types/src/y/versioning/index.d.ts +1 -0
- package/types/src/y/versioning/yhub.d.ts +87 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/RESTYjsThreadStore.d.ts +6 -10
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.d.ts +3 -3
- package/types/src/yjs/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.d.ts +3 -3
- package/types/src/yjs/comments/index.d.ts +3 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.d.ts +1 -1
- package/types/src/yjs/extensions/FixUpSchema.d.ts +3 -0
- package/types/src/yjs/extensions/FixUpSchema.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +27 -0
- package/types/src/yjs/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/yjs/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/yjs/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/yjs/extensions/Versioning.d.ts +26 -0
- package/types/src/yjs/extensions/Versioning.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → yjs/extensions}/YCursorPlugin.d.ts +5 -2
- package/types/src/{extensions/Collaboration → yjs/extensions}/YSync.d.ts +1 -1
- package/types/src/{extensions/Collaboration/Collaboration.d.ts → yjs/extensions/index.d.ts} +36 -15
- package/types/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +1 -0
- package/types/src/yjs/index.d.ts +2 -0
- package/types/src/yjs/utils.d.ts +5 -0
- package/dist/BlockNoteExtension-B6RhuQ3V.js +0 -27
- package/dist/BlockNoteExtension-B6RhuQ3V.js.map +0 -1
- package/dist/BlockNoteExtension-ab0REuob.cjs +0 -2
- package/dist/BlockNoteExtension-ab0REuob.cjs.map +0 -1
- package/dist/EventEmitter-CuPnGDYt.js +0 -22
- package/dist/EventEmitter-CuPnGDYt.js.map +0 -1
- package/dist/EventEmitter-DHdSnYCD.cjs +0 -2
- package/dist/EventEmitter-DHdSnYCD.cjs.map +0 -1
- package/dist/ShowSelection-BsHFfdMi.js +0 -29
- package/dist/ShowSelection-BsHFfdMi.js.map +0 -1
- package/dist/ShowSelection-DhXglbt8.cjs +0 -2
- package/dist/ShowSelection-DhXglbt8.cjs.map +0 -1
- package/dist/blocks-D0lMxErU.js.map +0 -1
- package/dist/blocks-KyMOxPT3.cjs +0 -11
- package/dist/blocks-KyMOxPT3.cjs.map +0 -1
- package/dist/en-B9hMApn4.js.map +0 -1
- package/dist/en-Cj5r8sW_.cjs.map +0 -1
- package/dist/extensions-Cutrafjg.cjs +0 -52
- package/dist/extensions-Cutrafjg.cjs.map +0 -1
- package/dist/extensions-D2mx2C9y.js.map +0 -1
- package/dist/src-D5R5YzV7.cjs +0 -21
- package/dist/src-D5R5YzV7.cjs.map +0 -1
- package/dist/src-Dvmif2FY.js.map +0 -1
- package/src/comments/userstore/UserStore.ts +0 -72
- package/src/extensions/Collaboration/Collaboration.ts +0 -55
- package/src/extensions/Collaboration/ForkYDoc.test.ts +0 -179
- package/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.ts +0 -175
- package/types/src/comments/userstore/UserStore.d.ts +0 -31
- package/types/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.d.ts +0 -4
- /package/src/{extensions/Collaboration → yjs/extensions}/YUndo.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor-forked.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-forked.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.ts +0 -0
- /package/types/src/{comments/threadstore/yjs/YjsThreadStore.test.d.ts → api/getBlockInfoFromPos.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/ForkYDoc.test.d.ts → api/nodeConversions/blockToNode.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.d.ts → blocks/Table/TableExtension.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/YUndo.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.d.ts +0 -0
|
@@ -154,7 +154,9 @@ function serializeBlockquote(el: HTMLElement, ctx: SerializeContext): string {
|
|
|
154
154
|
|
|
155
155
|
function serializeCodeBlock(el: HTMLElement, ctx: SerializeContext): string {
|
|
156
156
|
const codeEl = el.querySelector("code");
|
|
157
|
-
if (!codeEl) {
|
|
157
|
+
if (!codeEl) {
|
|
158
|
+
return "";
|
|
159
|
+
}
|
|
158
160
|
|
|
159
161
|
const language =
|
|
160
162
|
codeEl.getAttribute("data-language") ||
|
|
@@ -167,7 +169,7 @@ function serializeCodeBlock(el: HTMLElement, ctx: SerializeContext): string {
|
|
|
167
169
|
// Use a fence longer than the longest backtick run in the code
|
|
168
170
|
const longestRun = Math.max(
|
|
169
171
|
0,
|
|
170
|
-
...(
|
|
172
|
+
...(code.match(/`+/g) ?? []).map((run) => run.length),
|
|
171
173
|
);
|
|
172
174
|
const fence = "`".repeat(Math.max(3, longestRun + 1));
|
|
173
175
|
|
|
@@ -212,11 +214,11 @@ function extractLanguageFromClass(className: string): string {
|
|
|
212
214
|
|
|
213
215
|
function serializeUnorderedList(
|
|
214
216
|
el: HTMLElement,
|
|
215
|
-
ctx: SerializeContext
|
|
217
|
+
ctx: SerializeContext,
|
|
216
218
|
): string {
|
|
217
219
|
let result = "";
|
|
218
220
|
const items = Array.from(el.children).filter(
|
|
219
|
-
(child) => child.tagName.toLowerCase() === "li"
|
|
221
|
+
(child) => child.tagName.toLowerCase() === "li",
|
|
220
222
|
);
|
|
221
223
|
|
|
222
224
|
for (const item of items) {
|
|
@@ -235,7 +237,7 @@ function serializeUnorderedList(
|
|
|
235
237
|
function serializeOrderedList(el: HTMLElement, ctx: SerializeContext): string {
|
|
236
238
|
let result = "";
|
|
237
239
|
const items = Array.from(el.children).filter(
|
|
238
|
-
(child) => child.tagName.toLowerCase() === "li"
|
|
240
|
+
(child) => child.tagName.toLowerCase() === "li",
|
|
239
241
|
);
|
|
240
242
|
const startNum = parseInt(el.getAttribute("start") || "1", 10);
|
|
241
243
|
|
|
@@ -254,7 +256,7 @@ function serializeListItem(
|
|
|
254
256
|
el: HTMLElement,
|
|
255
257
|
listType: "bullet" | "ordered",
|
|
256
258
|
ctx: SerializeContext,
|
|
257
|
-
num?: number
|
|
259
|
+
num?: number,
|
|
258
260
|
): string {
|
|
259
261
|
// Check for checkbox (task list) - direct children only
|
|
260
262
|
let checkbox: HTMLInputElement | null = null;
|
|
@@ -298,7 +300,9 @@ function serializeListItem(
|
|
|
298
300
|
inlineContent = summaryP ? serializeInlineContent(summaryP) : "";
|
|
299
301
|
} else {
|
|
300
302
|
firstContentEl = getFirstContentElement(el, checkbox);
|
|
301
|
-
inlineContent = firstContentEl
|
|
303
|
+
inlineContent = firstContentEl
|
|
304
|
+
? serializeInlineContent(firstContentEl)
|
|
305
|
+
: "";
|
|
302
306
|
}
|
|
303
307
|
|
|
304
308
|
// The marker line ends with a single `\n` so that consecutive list items
|
|
@@ -315,7 +319,9 @@ function serializeListItem(
|
|
|
315
319
|
if (details) {
|
|
316
320
|
const summary = details.querySelector("summary");
|
|
317
321
|
for (const child of Array.from(details.children)) {
|
|
318
|
-
if (child === summary) {
|
|
322
|
+
if (child === summary) {
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
319
325
|
const childTag = child.tagName.toLowerCase();
|
|
320
326
|
if (childTag === "p") {
|
|
321
327
|
const content = serializeInlineContent(child as HTMLElement);
|
|
@@ -334,8 +340,12 @@ function serializeListItem(
|
|
|
334
340
|
const childTag = child.tagName.toLowerCase();
|
|
335
341
|
|
|
336
342
|
// Skip the first content element and checkbox
|
|
337
|
-
if (child === firstContentEl || (child as HTMLElement) === checkbox) {
|
|
338
|
-
|
|
343
|
+
if (child === firstContentEl || (child as HTMLElement) === checkbox) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (childTag === "input") {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
339
349
|
|
|
340
350
|
// Nested lists and other block content
|
|
341
351
|
if (childTag === "ul" || childTag === "ol") {
|
|
@@ -359,13 +369,19 @@ function serializeListItem(
|
|
|
359
369
|
|
|
360
370
|
function getFirstContentElement(
|
|
361
371
|
li: HTMLElement,
|
|
362
|
-
checkbox: HTMLInputElement | null
|
|
372
|
+
checkbox: HTMLInputElement | null,
|
|
363
373
|
): HTMLElement | null {
|
|
364
374
|
for (const child of Array.from(li.children)) {
|
|
365
|
-
if (child === checkbox) {
|
|
366
|
-
|
|
375
|
+
if (child === checkbox) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (child.tagName.toLowerCase() === "input") {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
367
381
|
const tag = child.tagName.toLowerCase();
|
|
368
|
-
if (tag === "p" || tag === "span") {
|
|
382
|
+
if (tag === "p" || tag === "span") {
|
|
383
|
+
return child as HTMLElement;
|
|
384
|
+
}
|
|
369
385
|
}
|
|
370
386
|
return null;
|
|
371
387
|
}
|
|
@@ -390,20 +406,24 @@ function serializeTable(el: HTMLElement, ctx: SerializeContext): string {
|
|
|
390
406
|
const grid: (string | null)[][] = [];
|
|
391
407
|
|
|
392
408
|
trElements.forEach((tr, rowIdx) => {
|
|
393
|
-
if (!grid[rowIdx]) {
|
|
409
|
+
if (!grid[rowIdx]) {
|
|
410
|
+
grid[rowIdx] = [];
|
|
411
|
+
}
|
|
394
412
|
const cellElements = tr.querySelectorAll("th, td");
|
|
395
413
|
let gridCol = 0;
|
|
396
414
|
|
|
397
415
|
cellElements.forEach((cell) => {
|
|
398
416
|
// Find next empty column in this row
|
|
399
|
-
while (grid[rowIdx][gridCol] !== undefined) {
|
|
417
|
+
while (grid[rowIdx][gridCol] !== undefined) {
|
|
418
|
+
gridCol++;
|
|
419
|
+
}
|
|
400
420
|
|
|
401
421
|
if (rowIdx === 0 && cell.tagName.toLowerCase() === "th") {
|
|
402
422
|
hasHeader = true;
|
|
403
423
|
}
|
|
404
424
|
|
|
405
425
|
const content = escapeTableCell(
|
|
406
|
-
serializeInlineContent(cell as HTMLElement).trim()
|
|
426
|
+
serializeInlineContent(cell as HTMLElement).trim(),
|
|
407
427
|
);
|
|
408
428
|
const colspan = parseInt(cell.getAttribute("colspan") || "1", 10);
|
|
409
429
|
const rowspan = parseInt(cell.getAttribute("rowspan") || "1", 10);
|
|
@@ -412,7 +432,9 @@ function serializeTable(el: HTMLElement, ctx: SerializeContext): string {
|
|
|
412
432
|
for (let r = 0; r < rowspan; r++) {
|
|
413
433
|
for (let c = 0; c < colspan; c++) {
|
|
414
434
|
const ri = rowIdx + r;
|
|
415
|
-
if (!grid[ri]) {
|
|
435
|
+
if (!grid[ri]) {
|
|
436
|
+
grid[ri] = [];
|
|
437
|
+
}
|
|
416
438
|
grid[ri][gridCol + c] = r === 0 && c === 0 ? content : "";
|
|
417
439
|
}
|
|
418
440
|
}
|
|
@@ -435,7 +457,9 @@ function serializeTable(el: HTMLElement, ctx: SerializeContext): string {
|
|
|
435
457
|
rows.push(row);
|
|
436
458
|
}
|
|
437
459
|
|
|
438
|
-
if (rows.length === 0) {
|
|
460
|
+
if (rows.length === 0) {
|
|
461
|
+
return "";
|
|
462
|
+
}
|
|
439
463
|
|
|
440
464
|
// Determine column widths
|
|
441
465
|
const colWidths: number[] = [];
|
|
@@ -464,8 +488,7 @@ function serializeTable(el: HTMLElement, ctx: SerializeContext): string {
|
|
|
464
488
|
result += ctx.indent + formatTableRow(emptyRow, colWidths, colCount) + "\n";
|
|
465
489
|
result += ctx.indent + formatSeparatorRow(colWidths, colCount) + "\n";
|
|
466
490
|
for (const row of rows) {
|
|
467
|
-
result +=
|
|
468
|
-
ctx.indent + formatTableRow(row, colWidths, colCount) + "\n";
|
|
491
|
+
result += ctx.indent + formatTableRow(row, colWidths, colCount) + "\n";
|
|
469
492
|
}
|
|
470
493
|
}
|
|
471
494
|
|
|
@@ -480,7 +503,7 @@ function escapeTableCell(text: string): string {
|
|
|
480
503
|
function formatTableRow(
|
|
481
504
|
cells: string[],
|
|
482
505
|
colWidths: number[],
|
|
483
|
-
colCount: number
|
|
506
|
+
colCount: number,
|
|
484
507
|
): string {
|
|
485
508
|
const parts: string[] = [];
|
|
486
509
|
for (let c = 0; c < colCount; c++) {
|
|
@@ -505,30 +528,39 @@ function serializeImage(el: HTMLElement, ctx: SerializeContext): string {
|
|
|
505
528
|
const alt = el.getAttribute("alt") || "";
|
|
506
529
|
// Empty placeholder — preserve the block-level break, matching how
|
|
507
530
|
// serializeParagraph/serializeHeading emit `\n\n` for empty content.
|
|
508
|
-
if (!src) {
|
|
531
|
+
if (!src) {
|
|
532
|
+
return "\n\n";
|
|
533
|
+
}
|
|
509
534
|
return ctx.indent + `\n\n`;
|
|
510
535
|
}
|
|
511
536
|
|
|
512
537
|
function serializeVideo(el: HTMLElement, ctx: SerializeContext): string {
|
|
513
|
-
const src =
|
|
514
|
-
el.getAttribute("src") || el.getAttribute("data-url") || "";
|
|
538
|
+
const src = el.getAttribute("src") || el.getAttribute("data-url") || "";
|
|
515
539
|
const name = el.getAttribute("data-name") || el.getAttribute("title") || "";
|
|
516
|
-
if (!src) {
|
|
540
|
+
if (!src) {
|
|
541
|
+
return "\n\n";
|
|
542
|
+
}
|
|
517
543
|
return ctx.indent + `\n\n`;
|
|
518
544
|
}
|
|
519
545
|
|
|
520
546
|
function serializeAudio(el: HTMLElement, ctx: SerializeContext): string {
|
|
521
547
|
const src = el.getAttribute("src") || "";
|
|
522
|
-
if (!src) {
|
|
548
|
+
if (!src) {
|
|
549
|
+
return "\n\n";
|
|
550
|
+
}
|
|
523
551
|
// Audio has no markdown syntax, so emit raw HTML. The markdown parser
|
|
524
552
|
// passes <audio> blocks through verbatim and BlockNote's audio block parser
|
|
525
553
|
// recognizes them, giving a clean round-trip.
|
|
526
|
-
return
|
|
554
|
+
return (
|
|
555
|
+
ctx.indent + `<audio src="${escapeHtmlAttr(src)}" controls></audio>\n\n`
|
|
556
|
+
);
|
|
527
557
|
}
|
|
528
558
|
|
|
529
559
|
function serializeEmbed(el: HTMLElement, ctx: SerializeContext): string {
|
|
530
560
|
const src = el.getAttribute("src") || "";
|
|
531
|
-
if (!src) {
|
|
561
|
+
if (!src) {
|
|
562
|
+
return "\n\n";
|
|
563
|
+
}
|
|
532
564
|
return ctx.indent + `[](${src})\n\n`;
|
|
533
565
|
}
|
|
534
566
|
|
|
@@ -579,7 +611,9 @@ function serializeMediaFigure(
|
|
|
579
611
|
captionText: string,
|
|
580
612
|
ctx: SerializeContext,
|
|
581
613
|
): string {
|
|
582
|
-
if (!src) {
|
|
614
|
+
if (!src) {
|
|
615
|
+
return "";
|
|
616
|
+
}
|
|
583
617
|
|
|
584
618
|
// No caption + has a markdown shorthand → use it.
|
|
585
619
|
if (!captionText && kind !== "audio") {
|
|
@@ -591,14 +625,13 @@ function serializeMediaFigure(
|
|
|
591
625
|
// get set to the same string (BlockNote's HTML exporter writes alt =
|
|
592
626
|
// name || caption, so a caption-only image has alt === figcaption text).
|
|
593
627
|
const showDescriptor = descriptor && descriptor !== captionText;
|
|
594
|
-
const descAttr =
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
: "";
|
|
628
|
+
const descAttr = !showDescriptor
|
|
629
|
+
? ""
|
|
630
|
+
: kind === "img"
|
|
631
|
+
? ` alt="${escapeHtmlAttr(descriptor)}"`
|
|
632
|
+
: kind === "video"
|
|
633
|
+
? ` data-name="${escapeHtmlAttr(descriptor)}"`
|
|
634
|
+
: "";
|
|
602
635
|
|
|
603
636
|
const tag =
|
|
604
637
|
kind === "img"
|
|
@@ -629,7 +662,9 @@ function escapeHtmlText(value: string): string {
|
|
|
629
662
|
function serializeBlockLink(el: HTMLElement, ctx: SerializeContext): string {
|
|
630
663
|
const href = el.getAttribute("href") || "";
|
|
631
664
|
const text = el.textContent?.trim() || "";
|
|
632
|
-
if (!href) {
|
|
665
|
+
if (!href) {
|
|
666
|
+
return ctx.indent + text + "\n\n";
|
|
667
|
+
}
|
|
633
668
|
return ctx.indent + formatLink(text, href) + "\n\n";
|
|
634
669
|
}
|
|
635
670
|
|
|
@@ -655,7 +690,9 @@ function escapeLinkDestination(url: string): string {
|
|
|
655
690
|
function serializeDetails(el: HTMLElement, ctx: SerializeContext): string {
|
|
656
691
|
// Toggle heading or toggle list item
|
|
657
692
|
const summary = el.querySelector("summary");
|
|
658
|
-
if (!summary) {
|
|
693
|
+
if (!summary) {
|
|
694
|
+
return serializeChildren(el, ctx);
|
|
695
|
+
}
|
|
659
696
|
|
|
660
697
|
// Check if summary contains a heading
|
|
661
698
|
const heading = summary.querySelector("h1, h2, h3, h4, h5, h6");
|
|
@@ -718,11 +755,10 @@ function serializeInlineContent(el: Element): string {
|
|
|
718
755
|
const text = childEl.textContent || "";
|
|
719
756
|
const longestRun = Math.max(
|
|
720
757
|
0,
|
|
721
|
-
...(
|
|
758
|
+
...(text.match(/`+/g) ?? []).map((run) => run.length),
|
|
722
759
|
);
|
|
723
760
|
const fence = "`".repeat(longestRun + 1);
|
|
724
|
-
const needsPadding =
|
|
725
|
-
text.startsWith("`") || text.endsWith("`");
|
|
761
|
+
const needsPadding = text.startsWith("`") || text.endsWith("`");
|
|
726
762
|
result += fence + (needsPadding ? ` ${text} ` : text) + fence;
|
|
727
763
|
break;
|
|
728
764
|
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { Schema } from "prosemirror-model";
|
|
2
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
3
|
+
|
|
4
|
+
import { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
5
|
+
import { docToBlocks } from "./nodeConversions/nodeToBlock.js";
|
|
6
|
+
import { getNodeId } from "./getBlockInfoFromPos.js";
|
|
7
|
+
import { YAttributionMarksExtension } from "../y/extensions/YAttributionMarks.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Builds a `blockContainer` node holding a single paragraph with the given
|
|
11
|
+
* block `id`. When `suggestedDelete` is true, the container carries a
|
|
12
|
+
* `y-attributed-delete` mark, simulating a node that Yjs keeps in the document
|
|
13
|
+
* (in suggestion mode) after it has been deleted.
|
|
14
|
+
*/
|
|
15
|
+
function makeBlockContainer(
|
|
16
|
+
schema: Schema,
|
|
17
|
+
id: string,
|
|
18
|
+
text: string,
|
|
19
|
+
suggestedDelete: boolean,
|
|
20
|
+
) {
|
|
21
|
+
const paragraph = schema.nodes["paragraph"].createChecked(
|
|
22
|
+
{},
|
|
23
|
+
text ? schema.text(text) : null,
|
|
24
|
+
);
|
|
25
|
+
const marks = suggestedDelete
|
|
26
|
+
? [schema.marks["y-attributed-delete"].create({ id: 1 })]
|
|
27
|
+
: undefined;
|
|
28
|
+
|
|
29
|
+
return schema.nodes["blockContainer"].createChecked({ id }, paragraph, marks);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("getNodeId", () => {
|
|
33
|
+
let editor: BlockNoteEditor;
|
|
34
|
+
|
|
35
|
+
// We only need the editor's ProseMirror schema to construct nodes, so a
|
|
36
|
+
// single non-mounted editor instance is enough for all cases here.
|
|
37
|
+
function getSchema() {
|
|
38
|
+
if (!editor) {
|
|
39
|
+
editor = BlockNoteEditor.create({
|
|
40
|
+
extensions: [YAttributionMarksExtension()],
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return editor.pmSchema;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
it("returns the plain id for a normal block", () => {
|
|
47
|
+
const schema = getSchema();
|
|
48
|
+
const block = makeBlockContainer(schema, "0", "Hello", false);
|
|
49
|
+
const doc = schema.nodes["doc"].createChecked(
|
|
50
|
+
{},
|
|
51
|
+
schema.nodes["blockGroup"].createChecked({}, block),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// The only descendant blockContainer with id "0" is the one we built.
|
|
55
|
+
const blockContainer = doc.firstChild!.firstChild!;
|
|
56
|
+
|
|
57
|
+
expect(getNodeId(blockContainer, doc)).toBe("0");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("throws when a node has no id", () => {
|
|
61
|
+
const schema = getSchema();
|
|
62
|
+
// `create` (not `createChecked`) so we can omit the id attr default lying.
|
|
63
|
+
const block = schema.nodes["blockContainer"].create(
|
|
64
|
+
{ id: null },
|
|
65
|
+
schema.nodes["paragraph"].createChecked({}, schema.text("No id")),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(() => getNodeId(block, block)).toThrow(/does not have an ID/);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("lies about the id of a suggested-deletion block to disambiguate duplicates", () => {
|
|
72
|
+
const schema = getSchema();
|
|
73
|
+
|
|
74
|
+
// First block: a "real" block with id "0".
|
|
75
|
+
const liveBlock = makeBlockContainer(schema, "0", "Live", false);
|
|
76
|
+
// Second block: a suggested deletion that, in suggestion mode, shares the
|
|
77
|
+
// SAME id "0" as the live block but carries a y-attributed-delete mark.
|
|
78
|
+
const deletedBlock = makeBlockContainer(schema, "0", "Deleted", true);
|
|
79
|
+
|
|
80
|
+
const doc = schema.nodes["doc"].createChecked(
|
|
81
|
+
{},
|
|
82
|
+
schema.nodes["blockGroup"].createChecked({}, [liveBlock, deletedBlock]),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const blockGroup = doc.firstChild!;
|
|
86
|
+
const liveNode = blockGroup.child(0);
|
|
87
|
+
const deletedNode = blockGroup.child(1);
|
|
88
|
+
|
|
89
|
+
// The live block keeps its plain id.
|
|
90
|
+
expect(getNodeId(liveNode, doc)).toBe("0");
|
|
91
|
+
// The suggested-deletion block is disambiguated: it is preceded by one
|
|
92
|
+
// node with the same id, so its index is 1 -> "0-1".
|
|
93
|
+
expect(getNodeId(deletedNode, doc)).toBe("0-1");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("disambiguates multiple suggested-deletion blocks with the same id", () => {
|
|
97
|
+
const schema = getSchema();
|
|
98
|
+
|
|
99
|
+
// Three blocks all sharing id "0": one live block followed by two
|
|
100
|
+
// suggested deletions (e.g. the user deleted the same logical block twice
|
|
101
|
+
// across forks, all kept in the doc with the y-attributed-delete mark).
|
|
102
|
+
const liveBlock = makeBlockContainer(schema, "0", "Live", false);
|
|
103
|
+
const deletedBlock1 = makeBlockContainer(schema, "0", "Deleted 1", true);
|
|
104
|
+
const deletedBlock2 = makeBlockContainer(schema, "0", "Deleted 2", true);
|
|
105
|
+
|
|
106
|
+
const doc = schema.nodes["doc"].createChecked(
|
|
107
|
+
{},
|
|
108
|
+
schema.nodes["blockGroup"].createChecked({}, [
|
|
109
|
+
liveBlock,
|
|
110
|
+
deletedBlock1,
|
|
111
|
+
deletedBlock2,
|
|
112
|
+
]),
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const blockGroup = doc.firstChild!;
|
|
116
|
+
|
|
117
|
+
expect(getNodeId(blockGroup.child(0), doc)).toBe("0");
|
|
118
|
+
// Preceded by 1 node with the same id.
|
|
119
|
+
expect(getNodeId(blockGroup.child(1), doc)).toBe("0-1");
|
|
120
|
+
// Preceded by 2 nodes with the same id.
|
|
121
|
+
expect(getNodeId(blockGroup.child(2), doc)).toBe("0-2");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("counts only preceding same-id nodes, not unrelated blocks", () => {
|
|
125
|
+
const schema = getSchema();
|
|
126
|
+
|
|
127
|
+
// A block with a different id sits between the live and deleted blocks.
|
|
128
|
+
// It must NOT contribute to the suggested-deletion block's index.
|
|
129
|
+
const liveBlock = makeBlockContainer(schema, "0", "Live", false);
|
|
130
|
+
const otherBlock = makeBlockContainer(schema, "1", "Other", false);
|
|
131
|
+
const deletedBlock = makeBlockContainer(schema, "0", "Deleted", true);
|
|
132
|
+
|
|
133
|
+
const doc = schema.nodes["doc"].createChecked(
|
|
134
|
+
{},
|
|
135
|
+
schema.nodes["blockGroup"].createChecked({}, [
|
|
136
|
+
liveBlock,
|
|
137
|
+
otherBlock,
|
|
138
|
+
deletedBlock,
|
|
139
|
+
]),
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const blockGroup = doc.firstChild!;
|
|
143
|
+
|
|
144
|
+
expect(getNodeId(blockGroup.child(0), doc)).toBe("0");
|
|
145
|
+
expect(getNodeId(blockGroup.child(1), doc)).toBe("1");
|
|
146
|
+
// Only the single live block with id "0" precedes it -> index 1.
|
|
147
|
+
expect(getNodeId(blockGroup.child(2), doc)).toBe("0-1");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("throws when a suggested-deletion node is not found in the provided doc", () => {
|
|
151
|
+
const schema = getSchema();
|
|
152
|
+
|
|
153
|
+
// A suggested-deletion block that is NOT part of `doc` -> the walk never
|
|
154
|
+
// finds it, so getNodeId throws.
|
|
155
|
+
const orphanDeleted = makeBlockContainer(schema, "0", "Orphan", true);
|
|
156
|
+
|
|
157
|
+
const doc = schema.nodes["doc"].createChecked(
|
|
158
|
+
{},
|
|
159
|
+
schema.nodes["blockGroup"].createChecked(
|
|
160
|
+
{},
|
|
161
|
+
makeBlockContainer(schema, "0", "Live", false),
|
|
162
|
+
),
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
expect(() => getNodeId(orphanDeleted, doc)).toThrow(
|
|
166
|
+
/not found in document/,
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe("docToBlocks round trip with suggested deletions", () => {
|
|
172
|
+
let editor: BlockNoteEditor;
|
|
173
|
+
|
|
174
|
+
function getSchema() {
|
|
175
|
+
if (!editor) {
|
|
176
|
+
editor = BlockNoteEditor.create({
|
|
177
|
+
extensions: [YAttributionMarksExtension()],
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return editor.pmSchema;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
it("reports distinct block ids even though two ProseMirror nodes share the same id", () => {
|
|
184
|
+
const schema = getSchema();
|
|
185
|
+
|
|
186
|
+
// A live block and a suggested-deletion block that, in suggestion mode,
|
|
187
|
+
// share the SAME ProseMirror id "0".
|
|
188
|
+
const liveBlock = makeBlockContainer(schema, "0", "Live", false);
|
|
189
|
+
const deletedBlock = makeBlockContainer(schema, "0", "Deleted", true);
|
|
190
|
+
|
|
191
|
+
const doc = schema.nodes["doc"].createChecked(
|
|
192
|
+
{},
|
|
193
|
+
schema.nodes["blockGroup"].createChecked({}, [liveBlock, deletedBlock]),
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
// At the ProseMirror level, both nodes share id "0".
|
|
197
|
+
const blockGroup = doc.firstChild!;
|
|
198
|
+
expect(blockGroup.child(0).attrs.id).toBe("0");
|
|
199
|
+
expect(blockGroup.child(1).attrs.id).toBe("0");
|
|
200
|
+
|
|
201
|
+
// docToBlocks disambiguates them via getNodeId: the live block keeps "0",
|
|
202
|
+
// the suggested-deletion block becomes "0-1".
|
|
203
|
+
const blocks = docToBlocks(doc);
|
|
204
|
+
const ids = blocks.map((block) => block.id);
|
|
205
|
+
|
|
206
|
+
expect(ids).toEqual(["0", "0-1"]);
|
|
207
|
+
// All block ids are distinct.
|
|
208
|
+
expect(new Set(ids).size).toBe(ids.length);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("disambiguates multiple suggested-deletion blocks sharing an id in docToBlocks", () => {
|
|
212
|
+
const schema = getSchema();
|
|
213
|
+
|
|
214
|
+
const liveBlock = makeBlockContainer(schema, "0", "Live", false);
|
|
215
|
+
const deletedBlock1 = makeBlockContainer(schema, "0", "Deleted 1", true);
|
|
216
|
+
const deletedBlock2 = makeBlockContainer(schema, "0", "Deleted 2", true);
|
|
217
|
+
|
|
218
|
+
const doc = schema.nodes["doc"].createChecked(
|
|
219
|
+
{},
|
|
220
|
+
schema.nodes["blockGroup"].createChecked({}, [
|
|
221
|
+
liveBlock,
|
|
222
|
+
deletedBlock1,
|
|
223
|
+
deletedBlock2,
|
|
224
|
+
]),
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const blocks = docToBlocks(doc);
|
|
228
|
+
const ids = blocks.map((block) => block.id);
|
|
229
|
+
|
|
230
|
+
expect(ids).toEqual(["0", "0-1", "0-2"]);
|
|
231
|
+
expect(new Set(ids).size).toBe(ids.length);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("only disambiguates the suggested-deletion block, leaving unrelated ids intact", () => {
|
|
235
|
+
const schema = getSchema();
|
|
236
|
+
|
|
237
|
+
const liveBlock = makeBlockContainer(schema, "0", "Live", false);
|
|
238
|
+
const otherBlock = makeBlockContainer(schema, "1", "Other", false);
|
|
239
|
+
const deletedBlock = makeBlockContainer(schema, "0", "Deleted", true);
|
|
240
|
+
|
|
241
|
+
const doc = schema.nodes["doc"].createChecked(
|
|
242
|
+
{},
|
|
243
|
+
schema.nodes["blockGroup"].createChecked({}, [
|
|
244
|
+
liveBlock,
|
|
245
|
+
otherBlock,
|
|
246
|
+
deletedBlock,
|
|
247
|
+
]),
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const blocks = docToBlocks(doc);
|
|
251
|
+
const ids = blocks.map((block) => block.id);
|
|
252
|
+
|
|
253
|
+
expect(ids).toEqual(["0", "1", "0-1"]);
|
|
254
|
+
expect(new Set(ids).size).toBe(ids.length);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -44,6 +44,49 @@ export type BlockInfo = {
|
|
|
44
44
|
}
|
|
45
45
|
);
|
|
46
46
|
|
|
47
|
+
export function isSuggestedDeletionNode(node: Node): boolean {
|
|
48
|
+
return node.marks.some((m) => ["y-attributed-delete"].includes(m.type.name));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getNodeId(node: Node, doc: Node): string {
|
|
52
|
+
const id = node.attrs.id;
|
|
53
|
+
if (!id) {
|
|
54
|
+
throw new Error(`Node ${node.type.name} does not have an ID`);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* In suggestion mode, yjs will insert nodes which have actually been deleted but are kept in the document with a "y-attributed-delete" mark,
|
|
58
|
+
* and nodes which have been inserted but are not yet accepted by the user, with a "y-attributed-insert" mark.
|
|
59
|
+
* Both of these nodes will have the same ID as the original node,
|
|
60
|
+
* so we need to differentiate them by counting how many nodes with the same ID come before them in the document, and adding that count to the ID.
|
|
61
|
+
*/
|
|
62
|
+
if (isSuggestedDeletionNode(node)) {
|
|
63
|
+
// walk the doc to find the node and count it's index if others have the same ID, to differentiate them
|
|
64
|
+
let index = 0;
|
|
65
|
+
let found = false;
|
|
66
|
+
doc.descendants((descNode: Node) => {
|
|
67
|
+
if (found) {
|
|
68
|
+
return false; // stop the walk
|
|
69
|
+
}
|
|
70
|
+
if (descNode.attrs.id === id) {
|
|
71
|
+
if (descNode === node) {
|
|
72
|
+
found = true;
|
|
73
|
+
return false; // stop the walk
|
|
74
|
+
}
|
|
75
|
+
index++;
|
|
76
|
+
}
|
|
77
|
+
return true; // continue the walk
|
|
78
|
+
});
|
|
79
|
+
if (!found) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Node ${node.type.name} with ID ${id} not found in document`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return `${id}-${index}`;
|
|
85
|
+
}
|
|
86
|
+
// TODO handle deleted nodes
|
|
87
|
+
return id;
|
|
88
|
+
}
|
|
89
|
+
|
|
47
90
|
/**
|
|
48
91
|
* Retrieves the position just before the nearest block node in a ProseMirror
|
|
49
92
|
* doc, relative to a position. If the position is within a block node or its
|
|
@@ -171,6 +214,7 @@ export function getBlockInfoWithManualOffset(
|
|
|
171
214
|
|
|
172
215
|
if (!blockContent) {
|
|
173
216
|
throw new Error(
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
174
218
|
`blockContainer node does not contain a blockContent node in its children: ${bnBlockNode}`,
|
|
175
219
|
);
|
|
176
220
|
}
|
|
@@ -185,6 +229,7 @@ export function getBlockInfoWithManualOffset(
|
|
|
185
229
|
} else {
|
|
186
230
|
if (!bnBlock.node.type.isInGroup("childContainer")) {
|
|
187
231
|
throw new Error(
|
|
232
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
188
233
|
`bnBlock node is not in the childContainer group: ${bnBlock.node}`,
|
|
189
234
|
);
|
|
190
235
|
}
|
|
@@ -232,22 +277,15 @@ export function getBlockInfoFromResolvedPos(resolvedPos: ResolvedPos) {
|
|
|
232
277
|
* Gets information regarding the ProseMirror nodes that make up a block. The
|
|
233
278
|
* block chosen is the one currently containing the current ProseMirror
|
|
234
279
|
* selection.
|
|
235
|
-
* @param
|
|
280
|
+
* @param source The ProseMirror editor state.
|
|
236
281
|
*/
|
|
237
|
-
export function getBlockInfoFromSelection(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return getBlockInfo(posInfo);
|
|
282
|
+
export function getBlockInfoFromSelection(source: EditorState | Transaction) {
|
|
283
|
+
return getBlockInfoAtNearest(source, source.selection.anchor);
|
|
241
284
|
}
|
|
242
285
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
*/
|
|
249
|
-
export function getBlockInfoFromTransaction(tr: Transaction) {
|
|
250
|
-
const posInfo = getNearestBlockPos(tr.doc, tr.selection.anchor);
|
|
251
|
-
|
|
252
|
-
return getBlockInfo(posInfo);
|
|
286
|
+
export function getBlockInfoAtNearest(
|
|
287
|
+
source: EditorState | Transaction,
|
|
288
|
+
pos: number,
|
|
289
|
+
) {
|
|
290
|
+
return getBlockInfo(getNearestBlockPos(source.doc, pos));
|
|
253
291
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it, beforeEach } from "
|
|
1
|
+
import { describe, expect, it, beforeEach } from "vite-plus/test";
|
|
2
2
|
|
|
3
3
|
import { setupTestEnv } from "./blockManipulation/setupTestEnv.js";
|
|
4
4
|
import { getBlocksChangedByTransaction } from "./getBlocksChangedByTransaction.js";
|
|
@@ -285,6 +285,7 @@ describe("getBlocksChangedByTransaction", () => {
|
|
|
285
285
|
// This test is different from the other tests because it uses the onChange hook to get the blocks changed
|
|
286
286
|
// This is because unnesting a block is not allowed within a transaction
|
|
287
287
|
let blocksChanged: any = null;
|
|
288
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method -- getChanges is destructured from callback parameter, not a class
|
|
288
289
|
const unsubscribe = editor.onChange((_e, { getChanges }) => {
|
|
289
290
|
blocksChanged = getChanges();
|
|
290
291
|
});
|