@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,6 +1,7 @@
|
|
|
1
1
|
import { type Node } from "prosemirror-model";
|
|
2
2
|
import { type Transaction } from "prosemirror-state";
|
|
3
3
|
import type { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js";
|
|
4
|
+
import { getNodeId } from "../../../getBlockInfoFromPos.js";
|
|
4
5
|
import type {
|
|
5
6
|
BlockIdentifier,
|
|
6
7
|
BlockSchema,
|
|
@@ -20,6 +21,9 @@ export function removeAndInsertBlocks<
|
|
|
20
21
|
tr: Transaction,
|
|
21
22
|
blocksToRemove: BlockIdentifier[],
|
|
22
23
|
blocksToInsert: PartialBlock<BSchema, I, S>[],
|
|
24
|
+
options: {
|
|
25
|
+
fixColumns?: boolean;
|
|
26
|
+
} = {},
|
|
23
27
|
): {
|
|
24
28
|
insertedBlocks: Block<BSchema, I, S>[];
|
|
25
29
|
removedBlocks: Block<BSchema, I, S>[];
|
|
@@ -54,18 +58,21 @@ export function removeAndInsertBlocks<
|
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
// Keeps traversing nodes if block with target ID has not been found.
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
if (!node.type.isInGroup("bnBlock")) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const nodeId = getNodeId(node, tr.doc);
|
|
66
|
+
|
|
67
|
+
if (!idsOfBlocksToRemove.has(nodeId)) {
|
|
61
68
|
return true;
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
// Saves the block that is being deleted.
|
|
65
|
-
removedBlocks.push(nodeToBlock(node,
|
|
66
|
-
idsOfBlocksToRemove.delete(
|
|
72
|
+
removedBlocks.push(nodeToBlock(node, tr.doc));
|
|
73
|
+
idsOfBlocksToRemove.delete(nodeId);
|
|
67
74
|
|
|
68
|
-
if (blocksToInsert.length > 0 &&
|
|
75
|
+
if (blocksToInsert.length > 0 && nodeId === idOfFirstBlock) {
|
|
69
76
|
const oldDocSize = tr.doc.nodeSize;
|
|
70
77
|
tr.insert(pos, nodesToInsert);
|
|
71
78
|
const newDocSize = tr.doc.nodeSize;
|
|
@@ -112,11 +119,16 @@ export function removeAndInsertBlocks<
|
|
|
112
119
|
);
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
|
|
122
|
+
// Collapses empty columns/columnLists. Callers where the removal isn't a
|
|
123
|
+
// deletion can opt out - e.g. `moveBlocks` re-inserts the blocks elsewhere
|
|
124
|
+
// and deliberately leaves emptied columns as-is.
|
|
125
|
+
if (options.fixColumns !== false) {
|
|
126
|
+
columnListPositions.forEach((pos) => fixColumnList(tr, pos));
|
|
127
|
+
}
|
|
116
128
|
|
|
117
129
|
// Converts the nodes created from `blocksToInsert` into full `Block`s.
|
|
118
130
|
const insertedBlocks = nodesToInsert.map((node) =>
|
|
119
|
-
nodeToBlock(node,
|
|
131
|
+
nodeToBlock(node, tr.doc),
|
|
120
132
|
) as Block<BSchema, I, S>[];
|
|
121
133
|
|
|
122
134
|
return { insertedBlocks, removedBlocks };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Node } from "prosemirror-model";
|
|
2
2
|
import { TextSelection } from "prosemirror-state";
|
|
3
|
-
import { describe, expect, it } from "
|
|
3
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
getBlockInfo,
|
|
7
|
-
|
|
7
|
+
getBlockInfoFromSelection,
|
|
8
|
+
getNodeId,
|
|
8
9
|
} from "../../../getBlockInfoFromPos.js";
|
|
9
10
|
import { getNodeById } from "../../../nodeUtil.js";
|
|
10
11
|
import { setupTestEnv } from "../../setupTestEnv.js";
|
|
@@ -137,12 +138,12 @@ describe("Test splitBlocks", () => {
|
|
|
137
138
|
|
|
138
139
|
splitBlock(getEditor().transact((tr) => tr.selection.anchor));
|
|
139
140
|
|
|
140
|
-
const
|
|
141
|
-
(
|
|
141
|
+
const blockId = getEditor().transact((tr) =>
|
|
142
|
+
getNodeId(getBlockInfoFromSelection(tr).bnBlock.node, tr.doc),
|
|
142
143
|
);
|
|
143
144
|
|
|
144
145
|
const anchorIsAtStartOfNewBlock =
|
|
145
|
-
|
|
146
|
+
blockId === "0" &&
|
|
146
147
|
getEditor().transact((tr) => tr.selection.$anchor.parentOffset) === 0;
|
|
147
148
|
|
|
148
149
|
expect(anchorIsAtStartOfNewBlock).toBeTruthy();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { describe, expect, it } from "
|
|
1
|
+
import { describe, expect, it } from "vite-plus/test";
|
|
2
2
|
|
|
3
|
+
import type { PartialBlock } from "../../../../blocks/defaultBlocks.js";
|
|
3
4
|
import { getBlockInfo } from "../../../getBlockInfoFromPos.js";
|
|
4
5
|
import { getNodeById } from "../../../nodeUtil.js";
|
|
5
6
|
import { setupTestEnv } from "../../setupTestEnv.js";
|
|
@@ -17,7 +18,7 @@ describe("Test updateBlock typing", () => {
|
|
|
17
18
|
type: "non-existing",
|
|
18
19
|
},
|
|
19
20
|
);
|
|
20
|
-
} catch
|
|
21
|
+
} catch {
|
|
21
22
|
// ID doesn't exist, which is fine - this is a compile-time check
|
|
22
23
|
}
|
|
23
24
|
});
|
|
@@ -34,7 +35,7 @@ describe("Test updateBlock typing", () => {
|
|
|
34
35
|
},
|
|
35
36
|
},
|
|
36
37
|
);
|
|
37
|
-
} catch
|
|
38
|
+
} catch {
|
|
38
39
|
// ID doesn't exist, which is fine - this is a compile-time check
|
|
39
40
|
}
|
|
40
41
|
try {
|
|
@@ -47,7 +48,7 @@ describe("Test updateBlock typing", () => {
|
|
|
47
48
|
},
|
|
48
49
|
},
|
|
49
50
|
);
|
|
50
|
-
} catch
|
|
51
|
+
} catch {
|
|
51
52
|
// ID doesn't exist, which is fine - this is a compile-time check
|
|
52
53
|
}
|
|
53
54
|
});
|
|
@@ -576,3 +577,360 @@ describe("Test updateBlock", () => {
|
|
|
576
577
|
expect(getEditor().document).toMatchSnapshot();
|
|
577
578
|
});
|
|
578
579
|
});
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* These tests assert that `updateBlock` produces the smallest possible set of
|
|
583
|
+
* ProseMirror steps, rather than replacing whole blocks/content/children when
|
|
584
|
+
* only a small part changed.
|
|
585
|
+
*/
|
|
586
|
+
describe("Test updateBlock minimal steps", () => {
|
|
587
|
+
// Runs `updateBlock` in a throwaway transaction and returns the resulting
|
|
588
|
+
// steps as JSON for inspection.
|
|
589
|
+
const getSteps = (blockId: string, update: PartialBlock<any, any, any>) => {
|
|
590
|
+
let steps: any[] = [];
|
|
591
|
+
getEditor().transact((tr) => {
|
|
592
|
+
updateBlock(tr, blockId, update);
|
|
593
|
+
steps = tr.steps.map((s) => s.toJSON());
|
|
594
|
+
});
|
|
595
|
+
return steps;
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
it("Changing a single prop emits only attr steps", () => {
|
|
599
|
+
const steps = getSteps("heading-with-everything", {
|
|
600
|
+
props: { level: 3 },
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
expect(steps).toEqual([
|
|
604
|
+
{
|
|
605
|
+
stepType: "attr",
|
|
606
|
+
pos: expect.any(Number),
|
|
607
|
+
attr: "level",
|
|
608
|
+
value: 3,
|
|
609
|
+
},
|
|
610
|
+
]);
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it("Changing only children does not touch content or container", () => {
|
|
614
|
+
const steps = getSteps("heading-with-everything", {
|
|
615
|
+
children: [
|
|
616
|
+
{
|
|
617
|
+
id: "new-nested-paragraph",
|
|
618
|
+
type: "paragraph",
|
|
619
|
+
content: "New nested Paragraph 2",
|
|
620
|
+
},
|
|
621
|
+
],
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
// A single replace step covering the children range only.
|
|
625
|
+
expect(steps).toHaveLength(1);
|
|
626
|
+
expect(steps[0].stepType).toBe("replace");
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
it("Appending a child is a pure insertion", () => {
|
|
630
|
+
const steps = getSteps("heading-with-everything", {
|
|
631
|
+
children: [
|
|
632
|
+
// Existing child, kept as-is.
|
|
633
|
+
{
|
|
634
|
+
id: "nested-paragraph-1",
|
|
635
|
+
type: "paragraph",
|
|
636
|
+
content: "Nested Paragraph 1",
|
|
637
|
+
children: [
|
|
638
|
+
{
|
|
639
|
+
id: "double-nested-paragraph-1",
|
|
640
|
+
type: "paragraph",
|
|
641
|
+
content: "Double Nested Paragraph 1",
|
|
642
|
+
},
|
|
643
|
+
],
|
|
644
|
+
},
|
|
645
|
+
// New sibling.
|
|
646
|
+
{
|
|
647
|
+
id: "appended-child",
|
|
648
|
+
type: "paragraph",
|
|
649
|
+
content: "Appended",
|
|
650
|
+
},
|
|
651
|
+
],
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
expect(steps).toHaveLength(1);
|
|
655
|
+
expect(steps[0].stepType).toBe("replace");
|
|
656
|
+
// Pure insertion: from === to (nothing deleted).
|
|
657
|
+
expect(steps[0].from).toBe(steps[0].to);
|
|
658
|
+
|
|
659
|
+
expect(
|
|
660
|
+
(getEditor().getBlock("heading-with-everything") as any).children.map(
|
|
661
|
+
(c: any) => c.id,
|
|
662
|
+
),
|
|
663
|
+
).toEqual(["nested-paragraph-1", "appended-child"]);
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
it("Changing part of the content only replaces the changed range", () => {
|
|
667
|
+
// Original content: "Heading" + " with styled " + "content".
|
|
668
|
+
// Only the middle text changes.
|
|
669
|
+
const steps = getSteps("heading-with-everything", {
|
|
670
|
+
content: [
|
|
671
|
+
{ type: "text", text: "Heading", styles: { bold: true } },
|
|
672
|
+
{ type: "text", text: " with NEW ", styles: {} },
|
|
673
|
+
{ type: "text", text: "content", styles: { italic: true } },
|
|
674
|
+
],
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
expect(steps).toHaveLength(1);
|
|
678
|
+
const [step] = steps;
|
|
679
|
+
expect(step.stepType).toBe("replace");
|
|
680
|
+
// The replaced range should be the diff ("styled" -> "NEW"), much smaller
|
|
681
|
+
// than the whole content node.
|
|
682
|
+
expect(step.to - step.from).toBeLessThan(
|
|
683
|
+
"Heading with styled content".length,
|
|
684
|
+
);
|
|
685
|
+
// Only the changed text is inserted.
|
|
686
|
+
expect(step.slice.content[0].text).toBe("NEW");
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
it("Changing one table cell only replaces that cell's text", () => {
|
|
690
|
+
const steps = getSteps("table-0", {
|
|
691
|
+
type: "table",
|
|
692
|
+
content: {
|
|
693
|
+
type: "tableContent",
|
|
694
|
+
rows: [
|
|
695
|
+
{ cells: ["Cell 1", "Cell 2", "Cell 3"] },
|
|
696
|
+
{ cells: ["Cell 4", "CHANGED", "Cell 6"] },
|
|
697
|
+
{ cells: ["Cell 7", "Cell 8", "Cell 9"] },
|
|
698
|
+
],
|
|
699
|
+
},
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
expect(steps).toHaveLength(1);
|
|
703
|
+
expect(steps[0].stepType).toBe("replace");
|
|
704
|
+
|
|
705
|
+
const block = getEditor().getBlock("table-0") as any;
|
|
706
|
+
expect(block.content.rows[1].cells[1].content[0].text).toBe("CHANGED");
|
|
707
|
+
// Surrounding cells are untouched.
|
|
708
|
+
expect(block.content.rows[0].cells[0].content[0].text).toBe("Cell 1");
|
|
709
|
+
expect(block.content.rows[2].cells[2].content[0].text).toBe("Cell 9");
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
it("Updating with identical content/props/children emits no steps", () => {
|
|
713
|
+
const steps = getSteps("heading-with-everything", {
|
|
714
|
+
type: "heading",
|
|
715
|
+
props: {
|
|
716
|
+
backgroundColor: "red",
|
|
717
|
+
level: 2,
|
|
718
|
+
textAlignment: "center",
|
|
719
|
+
textColor: "red",
|
|
720
|
+
},
|
|
721
|
+
content: [
|
|
722
|
+
{ type: "text", text: "Heading", styles: { bold: true } },
|
|
723
|
+
{ type: "text", text: " with styled ", styles: {} },
|
|
724
|
+
{ type: "text", text: "content", styles: { italic: true } },
|
|
725
|
+
],
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
expect(steps).toEqual([]);
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
it("Changing only a child's content replaces just that child's text", () => {
|
|
732
|
+
const steps = getSteps("paragraph-with-children", {
|
|
733
|
+
children: [
|
|
734
|
+
{
|
|
735
|
+
id: "nested-paragraph-0",
|
|
736
|
+
type: "paragraph",
|
|
737
|
+
content: "CHANGED nested",
|
|
738
|
+
children: [
|
|
739
|
+
{
|
|
740
|
+
id: "double-nested-paragraph-0",
|
|
741
|
+
type: "paragraph",
|
|
742
|
+
content: "Double Nested Paragraph 0",
|
|
743
|
+
},
|
|
744
|
+
],
|
|
745
|
+
},
|
|
746
|
+
],
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
// Diffed down to a single replace; the unchanged double-nested child and
|
|
750
|
+
// surrounding structure are left in place.
|
|
751
|
+
expect(steps).toHaveLength(1);
|
|
752
|
+
expect(steps[0].stepType).toBe("replace");
|
|
753
|
+
|
|
754
|
+
const block = getEditor().getBlock("paragraph-with-children") as any;
|
|
755
|
+
expect(block.children[0].content[0].text).toBe("CHANGED nested");
|
|
756
|
+
expect(block.children[0].children[0].id).toBe("double-nested-paragraph-0");
|
|
757
|
+
expect(block.children[0].children[0].content[0].text).toBe(
|
|
758
|
+
"Double Nested Paragraph 0",
|
|
759
|
+
);
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
it("Removing a table row only replaces the removed range", () => {
|
|
763
|
+
const steps = getSteps("table-0", {
|
|
764
|
+
type: "table",
|
|
765
|
+
content: {
|
|
766
|
+
type: "tableContent",
|
|
767
|
+
rows: [
|
|
768
|
+
{ cells: ["Cell 1", "Cell 2", "Cell 3"] },
|
|
769
|
+
{ cells: ["Cell 7", "Cell 8", "Cell 9"] },
|
|
770
|
+
],
|
|
771
|
+
},
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
// Snapped to the removed (middle) row: a single replace where content is
|
|
775
|
+
// deleted (slice is empty -> from < to).
|
|
776
|
+
expect(steps).toHaveLength(1);
|
|
777
|
+
expect(steps[0].stepType).toBe("replace");
|
|
778
|
+
expect(steps[0].to).toBeGreaterThan(steps[0].from);
|
|
779
|
+
|
|
780
|
+
const block = getEditor().getBlock("table-0") as any;
|
|
781
|
+
expect(block.content.rows).toHaveLength(2);
|
|
782
|
+
expect(block.content.rows[0].cells[0].content[0].text).toBe("Cell 1");
|
|
783
|
+
expect(block.content.rows[1].cells[2].content[0].text).toBe("Cell 9");
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
// Regression: when the content node's TYPE changes, setNodeMarkupMinimal
|
|
787
|
+
// emits a ReplaceAroundStep. Mapping the original beforePos through that step
|
|
788
|
+
// with the default (forward) bias pushes the position past the node, so the
|
|
789
|
+
// subsequent content diff resolved into the wrong place and corrupted the doc.
|
|
790
|
+
// The position must be mapped with a -1 (before) bias.
|
|
791
|
+
it("Type change + content change keeps the document valid", () => {
|
|
792
|
+
const steps = getSteps("paragraph-3", {
|
|
793
|
+
type: "heading",
|
|
794
|
+
props: { level: 1 },
|
|
795
|
+
content: "Now a heading",
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
// The type change requires a ReplaceAroundStep, but no error should be
|
|
799
|
+
// thrown and the resulting block must be correct.
|
|
800
|
+
expect(steps.length).toBeGreaterThan(0);
|
|
801
|
+
|
|
802
|
+
const block = getEditor().getBlock("paragraph-3") as any;
|
|
803
|
+
expect(block.type).toBe("heading");
|
|
804
|
+
expect(block.props.level).toBe(1);
|
|
805
|
+
expect(block.content[0].text).toBe("Now a heading");
|
|
806
|
+
|
|
807
|
+
// The editor document must still be internally consistent.
|
|
808
|
+
expect(() => getEditor()._tiptapEditor.state.doc.check()).not.toThrow();
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
it("Type change followed by another update resolves positions correctly", () => {
|
|
812
|
+
const editor = getEditor();
|
|
813
|
+
|
|
814
|
+
// First: change the content-node type (forces a ReplaceAroundStep), which
|
|
815
|
+
// is the operation that previously left later positions stale.
|
|
816
|
+
editor.transact((tr) => {
|
|
817
|
+
updateBlock(tr, "paragraph-4", {
|
|
818
|
+
type: "heading",
|
|
819
|
+
props: { level: 2 },
|
|
820
|
+
content: "Heading four",
|
|
821
|
+
});
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
// Then: a follow-up update on a *later* block, whose position would be wrong
|
|
825
|
+
// if the first transaction had corrupted the doc length.
|
|
826
|
+
expect(() => {
|
|
827
|
+
editor.transact((tr) => {
|
|
828
|
+
updateBlock(tr, "paragraph-9", {
|
|
829
|
+
content: "Paragraph nine updated",
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
}).not.toThrow();
|
|
833
|
+
|
|
834
|
+
expect((editor.getBlock("paragraph-4") as any).type).toBe("heading");
|
|
835
|
+
expect((editor.getBlock("paragraph-9") as any).content[0].text).toBe(
|
|
836
|
+
"Paragraph nine updated",
|
|
837
|
+
);
|
|
838
|
+
expect(() => editor._tiptapEditor.state.doc.check()).not.toThrow();
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
// Strongest regression: a children change (adds a step BEFORE the content
|
|
842
|
+
// node is updated) combined with a content-node type change (ReplaceAroundStep)
|
|
843
|
+
// and a content change. This is the exact mix that left the original beforePos
|
|
844
|
+
// stale; without the -1 mapping bias the content diff resolves into the wrong
|
|
845
|
+
// place and corrupts/throws.
|
|
846
|
+
it("Children change + type change + content change stays valid", () => {
|
|
847
|
+
const editor = getEditor();
|
|
848
|
+
|
|
849
|
+
expect(() => {
|
|
850
|
+
editor.transact((tr) => {
|
|
851
|
+
updateBlock(tr, "paragraph-with-children", {
|
|
852
|
+
type: "heading",
|
|
853
|
+
props: { level: 2 },
|
|
854
|
+
content: "Converted to heading",
|
|
855
|
+
children: [
|
|
856
|
+
{
|
|
857
|
+
id: "nested-paragraph-0",
|
|
858
|
+
type: "paragraph",
|
|
859
|
+
content: "Updated nested",
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
id: "brand-new-child",
|
|
863
|
+
type: "paragraph",
|
|
864
|
+
content: "Brand new child",
|
|
865
|
+
},
|
|
866
|
+
],
|
|
867
|
+
});
|
|
868
|
+
});
|
|
869
|
+
}).not.toThrow();
|
|
870
|
+
|
|
871
|
+
const block = editor.getBlock("paragraph-with-children") as any;
|
|
872
|
+
expect(block.type).toBe("heading");
|
|
873
|
+
expect(block.props.level).toBe(2);
|
|
874
|
+
expect(block.content[0].text).toBe("Converted to heading");
|
|
875
|
+
expect(block.children.map((c: any) => c.id)).toEqual([
|
|
876
|
+
"nested-paragraph-0",
|
|
877
|
+
"brand-new-child",
|
|
878
|
+
]);
|
|
879
|
+
expect(block.children[0].content[0].text).toBe("Updated nested");
|
|
880
|
+
expect(() => editor._tiptapEditor.state.doc.check()).not.toThrow();
|
|
881
|
+
|
|
882
|
+
// A follow-up update on a later block must still resolve correctly.
|
|
883
|
+
expect(() => {
|
|
884
|
+
editor.transact((tr) => {
|
|
885
|
+
updateBlock(tr, "paragraph-9", { content: "After conversion" });
|
|
886
|
+
});
|
|
887
|
+
}).not.toThrow();
|
|
888
|
+
expect((editor.getBlock("paragraph-9") as any).content[0].text).toBe(
|
|
889
|
+
"After conversion",
|
|
890
|
+
);
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
it("Type change with offset content replace stays minimal and valid", () => {
|
|
894
|
+
const editor = getEditor();
|
|
895
|
+
const info = getBlockInfo(
|
|
896
|
+
getNodeById(
|
|
897
|
+
"paragraph-with-styled-content",
|
|
898
|
+
editor.prosemirrorState.doc,
|
|
899
|
+
)!,
|
|
900
|
+
);
|
|
901
|
+
if (!info.isBlockContainer) {
|
|
902
|
+
throw new Error("paragraph-with-styled-content is not a block container");
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// paragraph-with-styled-content is "Paragraph"(bold) + " with styled " +
|
|
906
|
+
// "content"(italic). Replace only the unstyled middle node while converting
|
|
907
|
+
// the block to a heading. The type change forces a ReplaceAroundStep, after
|
|
908
|
+
// which the offset-replace branch must still resolve the (now shifted)
|
|
909
|
+
// content position correctly.
|
|
910
|
+
let steps: any[] = [];
|
|
911
|
+
editor.transact((tr) => {
|
|
912
|
+
updateBlock(
|
|
913
|
+
tr,
|
|
914
|
+
"paragraph-with-styled-content",
|
|
915
|
+
{
|
|
916
|
+
type: "heading",
|
|
917
|
+
props: { level: 3 },
|
|
918
|
+
content: [{ type: "text", text: " with NEW ", styles: {} }],
|
|
919
|
+
},
|
|
920
|
+
info.blockContent.beforePos + 1 + "Paragraph".length,
|
|
921
|
+
info.blockContent.beforePos + 1 + "Paragraph with styled ".length,
|
|
922
|
+
);
|
|
923
|
+
steps = tr.steps.map((s) => s.toJSON());
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
expect(steps.length).toBeGreaterThan(0);
|
|
927
|
+
|
|
928
|
+
const block = editor.getBlock("paragraph-with-styled-content") as any;
|
|
929
|
+
expect(block.type).toBe("heading");
|
|
930
|
+
expect(block.props.level).toBe(3);
|
|
931
|
+
// The styled text on either side of the replaced range is preserved.
|
|
932
|
+
expect(block.content[0].text).toBe("Paragraph");
|
|
933
|
+
expect(block.content[block.content.length - 1].text).toBe("content");
|
|
934
|
+
expect(() => editor._tiptapEditor.state.doc.check()).not.toThrow();
|
|
935
|
+
});
|
|
936
|
+
});
|