@blocknote/core 0.51.4 → 0.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BlockNoteExtension-B_IEJHS8.js +38 -0
- package/dist/BlockNoteExtension-B_IEJHS8.js.map +1 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs +2 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs.map +1 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs +2 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs.map +1 -0
- package/dist/ThreadStore-et9wB5Xt.js +11 -0
- package/dist/ThreadStore-et9wB5Xt.js.map +1 -0
- package/dist/UserStore-DCG6lsla.cjs +2 -0
- package/dist/UserStore-DCG6lsla.cjs.map +1 -0
- package/dist/UserStore-QbbPFj0z.js +73 -0
- package/dist/UserStore-QbbPFj0z.js.map +1 -0
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -7
- package/dist/blocks-BqHv0xhc.cjs +12 -0
- package/dist/blocks-BqHv0xhc.cjs.map +1 -0
- package/dist/{blocks-DGsP5WKr.js → blocks-CiuUGa1E.js} +1093 -994
- package/dist/blocks-CiuUGa1E.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +75 -340
- package/dist/comments.js.map +1 -1
- package/dist/{en-Cj5r8sW_.cjs → en-C5Z4Ag9_.cjs} +2 -2
- package/dist/en-C5Z4Ag9_.cjs.map +1 -0
- package/dist/{en-B9hMApn4.js → en-CGKXfWma.js} +9 -1
- package/dist/en-CGKXfWma.js.map +1 -0
- package/dist/{extensions-Co4y7P63.js → extensions-CrUGDOks.js} +655 -583
- package/dist/extensions-CrUGDOks.js.map +1 -0
- package/dist/extensions-Ghr9QqqR.cjs +52 -0
- package/dist/extensions-Ghr9QqqR.cjs.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +4 -4
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +177 -1
- package/dist/locales.js.map +1 -1
- package/dist/{src-Bcud0PIg.js → src-DTF83Cl9.js} +1243 -1297
- package/dist/src-DTF83Cl9.js.map +1 -0
- package/dist/src-OfbaVbMw.cjs +21 -0
- package/dist/src-OfbaVbMw.cjs.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +2 -0
- package/dist/y.cjs.map +1 -0
- package/dist/y.js +989 -0
- package/dist/y.js.map +1 -0
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +535 -14
- package/dist/yjs.js.map +1 -1
- package/package.json +46 -19
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +25 -20
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +39 -29
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +2 -2
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +4 -8
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +21 -9
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +6 -5
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +362 -4
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +240 -30
- package/src/api/blockManipulation/getBlock/getBlock.ts +4 -9
- package/src/api/blockManipulation/selections/selection.ts +3 -6
- package/src/api/blockManipulation/selections/textCursorPosition.ts +10 -10
- package/src/api/blockManipulation/setupTestEnv.ts +1 -1
- package/src/api/blockManipulation/tables/tables.test.ts +1 -1
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +1 -1
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +8 -4
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +2 -1
- package/src/api/exporters/markdown/htmlToMarkdown.ts +79 -43
- package/src/api/getBlockInfoFromPos.test.ts +256 -0
- package/src/api/getBlockInfoFromPos.ts +53 -15
- package/src/api/getBlocksChangedByTransaction.test.ts +2 -1
- package/src/api/getBlocksChangedByTransaction.ts +6 -6
- package/src/api/nodeConversions/blockToNode.test.ts +113 -0
- package/src/api/nodeConversions/blockToNode.ts +15 -3
- package/src/api/nodeConversions/fragmentToBlocks.ts +2 -4
- package/src/api/nodeConversions/nodeToBlock.ts +28 -58
- package/src/api/nodeUtil.ts +6 -2
- package/src/api/parsers/html/parseHTML.ts +1 -1
- package/src/api/parsers/html/util/nestedLists.test.ts +1 -1
- package/src/api/parsers/markdown/detectMarkdown.test.ts +1 -1
- package/src/api/parsers/markdown/markdownToHtml.ts +228 -82
- package/src/api/pmUtil.ts +18 -1
- package/src/api/positionMapping.test.ts +20 -345
- package/src/api/positionMapping.ts +13 -83
- package/src/blocks/Audio/block.ts +1 -1
- package/src/blocks/Code/block.test.ts +14 -7
- package/src/blocks/Code/block.ts +2 -2
- package/src/blocks/Image/block.ts +1 -1
- package/src/blocks/ListItem/CheckListItem/block.test.ts +1 -1
- package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +2 -2
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +4 -11
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +47 -50
- package/src/blocks/Table/TableExtension.test.ts +9 -6
- package/src/blocks/Table/TableExtension.ts +20 -6
- package/src/blocks/Table/block.ts +18 -5
- package/src/blocks/Video/block.ts +1 -1
- package/src/blocks/utils/listItemEnterHandler.ts +3 -2
- package/src/comments/extension.ts +30 -21
- package/src/comments/index.ts +0 -3
- package/src/comments/mark.ts +4 -0
- package/src/comments/threadstore/ThreadStore.ts +4 -8
- package/src/comments/types.ts +0 -8
- package/src/editor/Block.css +307 -3
- package/src/editor/BlockNoteEditor.test.ts +21 -18
- package/src/editor/BlockNoteEditor.ts +22 -57
- package/src/editor/BlockNoteExtension.test.ts +1 -1
- package/src/editor/managers/BlockManager.ts +1 -1
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +249 -0
- package/src/editor/managers/ExtensionManager/extensions.ts +7 -18
- package/src/editor/managers/ExtensionManager/index.ts +168 -68
- package/src/editor/managers/StateManager.ts +4 -3
- package/src/editor/performance.test.ts +14 -1
- package/src/editor/transformPasted.test.ts +1 -1
- package/src/extensions/Placeholder/Placeholder.ts +1 -0
- package/src/extensions/PositionMapping/PositionMapping.ts +68 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +14 -1
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +14 -11
- package/src/extensions/SideMenu/SideMenu.ts +9 -2
- package/src/extensions/SuggestionMenu/SuggestionMenu.test.ts +1 -1
- package/src/extensions/TableHandles/TableHandles.ts +18 -20
- package/src/extensions/TrailingNode/TrailingNode.ts +33 -1
- package/src/extensions/Versioning/Versioning.test.ts +435 -0
- package/src/extensions/Versioning/Versioning.ts +628 -0
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +469 -0
- package/src/extensions/Versioning/inMemoryVersioning.ts +263 -0
- package/src/extensions/Versioning/index.ts +2 -0
- package/src/extensions/index.ts +6 -9
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +155 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +6 -8
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +9 -9
- package/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts +8 -10
- package/src/extensions/tiptap-extensions/Link/helpers/whitespace.ts +2 -2
- package/src/extensions/tiptap-extensions/Link/link.test.ts +26 -22
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +187 -0
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +37 -24
- package/src/extensions/tiptap-extensions/index.ts +1 -25
- package/src/i18n/locales/ar.ts +9 -0
- package/src/i18n/locales/de.ts +9 -0
- package/src/i18n/locales/en.ts +10 -1
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fa.ts +11 -1
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/he.ts +10 -1
- package/src/i18n/locales/hr.ts +10 -0
- package/src/i18n/locales/is.ts +10 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/ja.ts +9 -0
- package/src/i18n/locales/ko.ts +9 -0
- package/src/i18n/locales/nl.ts +10 -0
- package/src/i18n/locales/no.ts +10 -0
- package/src/i18n/locales/pl.ts +9 -0
- package/src/i18n/locales/pt.ts +10 -0
- package/src/i18n/locales/ru.ts +10 -0
- package/src/i18n/locales/sk.ts +10 -1
- package/src/i18n/locales/uk.ts +9 -0
- package/src/i18n/locales/uz.ts +9 -0
- package/src/i18n/locales/vi.ts +9 -0
- package/src/i18n/locales/zh-tw.ts +9 -0
- package/src/i18n/locales/zh.ts +9 -0
- package/src/index.ts +2 -0
- package/src/pm-nodes/BlockContainer.ts +4 -1
- package/src/pm-nodes/BlockGroup.ts +4 -1
- package/src/pm-nodes/Doc.ts +4 -1
- package/src/pm-nodes/suggestionMarks.ts +43 -0
- package/src/schema/blocks/createSpec.test.ts +123 -0
- package/src/schema/blocks/createSpec.ts +82 -24
- package/src/schema/blocks/extendBlockSpec.test.ts +188 -0
- package/src/schema/blocks/internal.ts +13 -43
- package/src/schema/blocks/types.ts +69 -22
- package/src/schema/contentTypePropagation.test.ts +182 -0
- package/src/schema/index.ts +1 -0
- package/src/schema/inlineContent/internal.ts +1 -1
- package/src/schema/inlineContent/types.ts +3 -3
- package/src/schema/markGroups.ts +50 -0
- package/src/user/UserStore.ts +199 -0
- package/src/user/createUserStore.test.ts +126 -0
- package/src/user/index.ts +2 -0
- package/src/user/userColors.ts +72 -0
- package/src/util/string.ts +1 -1
- package/src/util/topo-sort.test.ts +1 -1
- package/src/util/typescript.ts +2 -1
- package/src/vite-env.d.ts +1 -1
- package/src/y/README.md +5 -0
- package/src/{comments/threadstore/yjs → y/comments}/RESTYjsThreadStore.ts +8 -14
- package/src/y/comments/YjsThreadStore.test.ts +295 -0
- package/src/y/comments/YjsThreadStore.ts +358 -0
- package/src/y/comments/YjsThreadStoreBase.ts +50 -0
- package/src/y/comments/index.ts +3 -0
- package/src/y/comments/yjsHelpers.ts +125 -0
- package/src/y/extensions/AttributionExtension.test.ts +86 -0
- package/src/y/extensions/AttributionExtension.ts +378 -0
- package/src/y/extensions/DiffVersioningExtension.test.ts +193 -0
- package/src/y/extensions/DiffVersioningExtension.ts +228 -0
- package/src/y/extensions/ForkYDoc.test.ts +253 -0
- package/src/y/extensions/ForkYDoc.ts +108 -0
- package/src/y/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/y/extensions/RelativePositionMapping.ts +49 -0
- package/src/y/extensions/Suggestions.ts +174 -0
- package/src/y/extensions/Versioning.test.ts +395 -0
- package/src/y/extensions/Versioning.ts +115 -0
- package/src/y/extensions/YAttributionMarks.ts +320 -0
- package/src/{extensions/Collaboration → y/extensions}/YCursorPlugin.ts +15 -7
- package/src/y/extensions/YSync.ts +125 -0
- package/src/y/extensions/blockMatchNodes.ts +182 -0
- package/src/y/extensions/index.ts +156 -0
- package/src/y/index.ts +4 -0
- package/src/y/utils.test.ts +1042 -0
- package/src/y/utils.ts +242 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.json +50 -0
- package/src/y/versioning/__test__/fixtures/activity-all.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all.json +20 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +32 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-before.json +1 -0
- package/src/y/versioning/__test__/fixtures/changeset.bin +0 -0
- package/src/y/versioning/__test__/fixtures/patch-response.json +4 -0
- package/src/y/versioning/__test__/yhub.test.ts +752 -0
- package/src/y/versioning/index.ts +1 -0
- package/src/y/versioning/yhub.ts +631 -0
- package/src/yjs/README.md +5 -0
- package/src/yjs/comments/RESTYjsThreadStore.ts +166 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.test.ts +3 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.ts +7 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.ts +3 -3
- package/src/yjs/comments/index.ts +3 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.ts +5 -1
- package/src/yjs/extensions/FixUpSchema.test.ts +421 -0
- package/src/yjs/extensions/FixUpSchema.ts +88 -0
- package/src/yjs/extensions/ForkYDoc.test.ts +216 -0
- package/src/{extensions/Collaboration → yjs/extensions}/ForkYDoc.ts +38 -57
- package/src/yjs/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/yjs/extensions/RelativePositionMapping.ts +71 -0
- package/src/yjs/extensions/Versioning.test.ts +549 -0
- package/src/yjs/extensions/Versioning.ts +83 -0
- package/src/yjs/extensions/YCursorPlugin.ts +201 -0
- package/src/{extensions/Collaboration → yjs/extensions}/YSync.ts +1 -1
- package/src/yjs/extensions/index.ts +89 -0
- package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.test.ts +1 -1
- package/src/yjs/index.ts +2 -0
- package/src/yjs/utils.test.ts +5 -15
- package/src/yjs/utils.ts +36 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +3 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
- package/types/src/api/getBlockInfoFromPos.d.ts +5 -9
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +4 -6
- package/types/src/api/pmUtil.d.ts +12 -1
- package/types/src/blocks/Audio/block.d.ts +2 -2
- package/types/src/blocks/Code/block.d.ts +2 -2
- package/types/src/blocks/File/block.d.ts +2 -2
- package/types/src/blocks/Heading/block.d.ts +21 -21
- package/types/src/blocks/Image/block.d.ts +3 -3
- package/types/src/blocks/ListItem/CheckListItem/block.d.ts +6 -6
- package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +6 -6
- package/types/src/blocks/Video/block.d.ts +3 -3
- package/types/src/blocks/defaultBlocks.d.ts +17 -17
- package/types/src/comments/extension.d.ts +18 -5
- package/types/src/comments/index.d.ts +0 -3
- package/types/src/comments/threadstore/ThreadStore.d.ts +4 -8
- package/types/src/comments/types.d.ts +0 -8
- package/types/src/editor/BlockNoteEditor.d.ts +8 -9
- package/types/src/editor/managers/BlockManager.d.ts +1 -1
- package/types/src/editor/managers/ExtensionManager/extensions.d.ts +2 -2
- package/types/src/editor/managers/ExtensionManager/index.d.ts +13 -0
- package/types/src/editor/managers/SelectionManager.d.ts +1 -1
- package/types/src/extensions/PositionMapping/PositionMapping.d.ts +4 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -6
- package/types/src/extensions/Versioning/Versioning.d.ts +352 -0
- package/types/src/extensions/Versioning/Versioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +37 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/index.d.ts +2 -0
- package/types/src/extensions/index.d.ts +6 -9
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +1 -0
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.d.ts +6 -1
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.d.ts +4 -0
- package/types/src/extensions/tiptap-extensions/index.d.ts +1 -5
- package/types/src/i18n/locales/en.d.ts +9 -1
- package/types/src/i18n/locales/fa.d.ts +9 -1
- package/types/src/i18n/locales/sk.d.ts +9 -1
- package/types/src/index.d.ts +2 -0
- package/types/src/pm-nodes/suggestionMarks.d.ts +26 -0
- package/types/src/schema/blocks/createSpec.d.ts +4 -4
- package/types/src/schema/blocks/createSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/extendBlockSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/internal.d.ts +5 -7
- package/types/src/schema/blocks/types.d.ts +22 -14
- package/types/src/schema/contentTypePropagation.test.d.ts +1 -0
- package/types/src/schema/index.d.ts +1 -0
- package/types/src/schema/inlineContent/types.d.ts +3 -3
- package/types/src/schema/markGroups.d.ts +33 -0
- package/types/src/user/UserStore.d.ts +105 -0
- package/types/src/user/createUserStore.test.d.ts +1 -0
- package/types/src/user/index.d.ts +2 -0
- package/types/src/user/userColors.d.ts +36 -0
- package/types/src/y/comments/RESTYjsThreadStore.d.ts +77 -0
- package/types/src/y/comments/YjsThreadStore.d.ts +79 -0
- package/types/src/y/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/y/comments/YjsThreadStoreBase.d.ts +15 -0
- package/types/src/y/comments/index.d.ts +3 -0
- package/types/src/y/comments/yjsHelpers.d.ts +13 -0
- package/types/src/y/extensions/AttributionExtension.d.ts +74 -0
- package/types/src/y/extensions/AttributionExtension.test.d.ts +1 -0
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +69 -0
- package/types/src/y/extensions/DiffVersioningExtension.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → y/extensions}/ForkYDoc.d.ts +4 -2
- package/types/src/y/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/y/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/y/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/y/extensions/Suggestions.d.ts +36 -0
- package/types/src/y/extensions/Versioning.d.ts +17 -0
- package/types/src/y/extensions/Versioning.test.d.ts +1 -0
- package/types/src/y/extensions/YAttributionMarks.d.ts +67 -0
- package/types/src/y/extensions/YCursorPlugin.d.ts +14 -0
- package/types/src/y/extensions/YSync.d.ts +32 -0
- package/types/src/y/extensions/blockMatchNodes.d.ts +25 -0
- package/types/src/y/extensions/index.d.ts +189 -0
- package/types/src/y/index.d.ts +4 -0
- package/types/src/y/utils.d.ts +82 -0
- package/types/src/y/utils.test.d.ts +1 -0
- package/types/src/y/versioning/__test__/yhub.test.d.ts +1 -0
- package/types/src/y/versioning/index.d.ts +1 -0
- package/types/src/y/versioning/yhub.d.ts +87 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/RESTYjsThreadStore.d.ts +6 -10
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.d.ts +3 -3
- package/types/src/yjs/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.d.ts +3 -3
- package/types/src/yjs/comments/index.d.ts +3 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.d.ts +1 -1
- package/types/src/yjs/extensions/FixUpSchema.d.ts +3 -0
- package/types/src/yjs/extensions/FixUpSchema.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +27 -0
- package/types/src/yjs/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/yjs/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/yjs/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/yjs/extensions/Versioning.d.ts +26 -0
- package/types/src/yjs/extensions/Versioning.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → yjs/extensions}/YCursorPlugin.d.ts +5 -2
- package/types/src/{extensions/Collaboration → yjs/extensions}/YSync.d.ts +1 -1
- package/types/src/{extensions/Collaboration/Collaboration.d.ts → yjs/extensions/index.d.ts} +36 -15
- package/types/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +1 -0
- package/types/src/yjs/index.d.ts +2 -0
- package/types/src/yjs/utils.d.ts +5 -0
- package/dist/BlockNoteExtension-B6RhuQ3V.js +0 -27
- package/dist/BlockNoteExtension-B6RhuQ3V.js.map +0 -1
- package/dist/BlockNoteExtension-ab0REuob.cjs +0 -2
- package/dist/BlockNoteExtension-ab0REuob.cjs.map +0 -1
- package/dist/EventEmitter-CuPnGDYt.js +0 -22
- package/dist/EventEmitter-CuPnGDYt.js.map +0 -1
- package/dist/EventEmitter-DHdSnYCD.cjs +0 -2
- package/dist/EventEmitter-DHdSnYCD.cjs.map +0 -1
- package/dist/ShowSelection-BsHFfdMi.js +0 -29
- package/dist/ShowSelection-BsHFfdMi.js.map +0 -1
- package/dist/ShowSelection-DhXglbt8.cjs +0 -2
- package/dist/ShowSelection-DhXglbt8.cjs.map +0 -1
- package/dist/blocks-Bm6IfL1R.cjs +0 -11
- package/dist/blocks-Bm6IfL1R.cjs.map +0 -1
- package/dist/blocks-DGsP5WKr.js.map +0 -1
- package/dist/en-B9hMApn4.js.map +0 -1
- package/dist/en-Cj5r8sW_.cjs.map +0 -1
- package/dist/extensions-Co4y7P63.js.map +0 -1
- package/dist/extensions-IJK3t0sz.cjs +0 -52
- package/dist/extensions-IJK3t0sz.cjs.map +0 -1
- package/dist/src-B6rlChSc.cjs +0 -21
- package/dist/src-B6rlChSc.cjs.map +0 -1
- package/dist/src-Bcud0PIg.js.map +0 -1
- package/src/comments/userstore/UserStore.ts +0 -72
- package/src/extensions/Collaboration/Collaboration.ts +0 -55
- package/src/extensions/Collaboration/ForkYDoc.test.ts +0 -179
- package/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.ts +0 -175
- package/types/src/comments/userstore/UserStore.d.ts +0 -31
- package/types/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.d.ts +0 -4
- /package/src/{extensions/Collaboration → yjs/extensions}/YUndo.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor-forked.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-forked.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.ts +0 -0
- /package/types/src/{comments/threadstore/yjs/YjsThreadStore.test.d.ts → api/getBlockInfoFromPos.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/ForkYDoc.test.d.ts → api/nodeConversions/blockToNode.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.d.ts → editor/managers/ExtensionManager/ExtensionManager.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/YUndo.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.d.ts +0 -0
|
@@ -127,7 +127,7 @@ export function updateBlockTr<
|
|
|
127
127
|
// currently, we calculate the new node and replace the entire node with the desired new node.
|
|
128
128
|
// for this, we do a nodeToBlock on the existing block to get the children.
|
|
129
129
|
// it would be cleaner to use a ReplaceAroundStep, but this is a bit simpler and it's quite an edge case
|
|
130
|
-
const existingBlock = nodeToBlock(blockInfo.bnBlock.node,
|
|
130
|
+
const existingBlock = nodeToBlock(blockInfo.bnBlock.node, tr.doc);
|
|
131
131
|
const replacementNode = blockToNode(
|
|
132
132
|
{
|
|
133
133
|
children: existingBlock.children, // if no children are passed in, use existing children
|
|
@@ -146,9 +146,10 @@ export function updateBlockTr<
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
// Adds all provided props as attributes to the parent blockContainer node too, and also preserves existing
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
|
|
150
|
+
// attributes. Uses minimal steps so that an unchanged container (e.g. when
|
|
151
|
+
// only children or content changed) doesn't emit a step at all.
|
|
152
|
+
setNodeMarkupMinimal(tr, blockInfo.bnBlock.beforePos, newBnBlockNodeType, {
|
|
152
153
|
...block.props,
|
|
153
154
|
});
|
|
154
155
|
|
|
@@ -219,29 +220,30 @@ function updateBlockContentNode<
|
|
|
219
220
|
// Use either setNodeMarkup or replaceWith depending on whether the
|
|
220
221
|
// content is being replaced or not.
|
|
221
222
|
if (content === "keep") {
|
|
222
|
-
//
|
|
223
|
-
tr
|
|
224
|
-
...blockInfo.blockContent.node.attrs,
|
|
223
|
+
// only update the type and attributes, keeping the content as-is
|
|
224
|
+
setNodeMarkupMinimal(tr, blockInfo.blockContent.beforePos, newNodeType, {
|
|
225
225
|
...block.props,
|
|
226
226
|
});
|
|
227
227
|
} else if (replaceFromOffset !== undefined || replaceToOffset !== undefined) {
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
228
|
+
// Update the markup of the containing node, then get its (possibly shifted)
|
|
229
|
+
// position back.
|
|
230
|
+
const contentBeforePos = setNodeMarkupMinimalAndRemap(
|
|
231
|
+
tr,
|
|
232
|
+
blockInfo.blockContent.beforePos,
|
|
233
|
+
newNodeType,
|
|
234
|
+
{ ...block.props },
|
|
235
|
+
);
|
|
233
236
|
|
|
234
|
-
const start =
|
|
235
|
-
blockInfo.blockContent.beforePos + 1 + (replaceFromOffset ?? 0);
|
|
237
|
+
const start = contentBeforePos + 1 + (replaceFromOffset ?? 0);
|
|
236
238
|
const end =
|
|
237
|
-
|
|
239
|
+
contentBeforePos +
|
|
238
240
|
1 +
|
|
239
241
|
(replaceToOffset ?? blockInfo.blockContent.node.content.size);
|
|
240
242
|
|
|
241
243
|
// for content like table cells (where the blockcontent has nested PM nodes),
|
|
242
244
|
// we need to figure out the correct openStart and openEnd for the slice when replacing
|
|
243
245
|
|
|
244
|
-
const contentDepth = tr.doc.resolve(
|
|
246
|
+
const contentDepth = tr.doc.resolve(contentBeforePos).depth;
|
|
245
247
|
const startDepth = tr.doc.resolve(start).depth;
|
|
246
248
|
const endDepth = tr.doc.resolve(end).depth;
|
|
247
249
|
|
|
@@ -254,10 +256,30 @@ function updateBlockContentNode<
|
|
|
254
256
|
endDepth - contentDepth - 1,
|
|
255
257
|
),
|
|
256
258
|
);
|
|
259
|
+
} else if (
|
|
260
|
+
newNodeType === oldNodeType ||
|
|
261
|
+
newNodeType.validContent(blockInfo.blockContent.node.content)
|
|
262
|
+
) {
|
|
263
|
+
// The new type can hold the existing content, so we can update the markup
|
|
264
|
+
// first and then diff the content. This keeps both steps minimal.
|
|
265
|
+
//
|
|
266
|
+
// First update the markup (type & attributes) of the content node using
|
|
267
|
+
// minimal steps (avoids replacing the whole node just to change attrs), then
|
|
268
|
+
// get its (possibly shifted) position back.
|
|
269
|
+
const contentBeforePos = setNodeMarkupMinimalAndRemap(
|
|
270
|
+
tr,
|
|
271
|
+
blockInfo.blockContent.beforePos,
|
|
272
|
+
newNodeType,
|
|
273
|
+
{ ...block.props },
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
// Then replace only the part of the content that actually changed, keeping
|
|
277
|
+
// any shared prefix/suffix untouched.
|
|
278
|
+
replaceContentMinimal(tr, contentBeforePos, Fragment.from(content));
|
|
257
279
|
} else {
|
|
258
|
-
//
|
|
259
|
-
//
|
|
260
|
-
//
|
|
280
|
+
// The content type is incompatible with the new node type (e.g. switching
|
|
281
|
+
// between inline content, table content, and no content). We can't update
|
|
282
|
+
// the markup in-place, so replace the whole content node atomically.
|
|
261
283
|
tr.replaceWith(
|
|
262
284
|
blockInfo.blockContent.beforePos,
|
|
263
285
|
blockInfo.blockContent.afterPos,
|
|
@@ -272,6 +294,197 @@ function updateBlockContentNode<
|
|
|
272
294
|
}
|
|
273
295
|
}
|
|
274
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Replaces the content of the node at `nodePos` with `newContent`, only
|
|
299
|
+
* touching the range that actually differs between the old and new content.
|
|
300
|
+
*
|
|
301
|
+
* - For textblocks (inline content), this diffs at the character level using
|
|
302
|
+
* `Fragment.findDiffStart`/`findDiffEnd`, so e.g. changing a single word only
|
|
303
|
+
* replaces that word rather than the entire paragraph.
|
|
304
|
+
* - For nested content (like tables or blockGroups), the diff is snapped to
|
|
305
|
+
* whole top-level children (rows / blocks), so only the changed children are
|
|
306
|
+
* replaced while unchanged leading/trailing children are left untouched.
|
|
307
|
+
*/
|
|
308
|
+
function replaceContentMinimal(
|
|
309
|
+
tr: Transform,
|
|
310
|
+
nodePos: number,
|
|
311
|
+
newContent: Fragment,
|
|
312
|
+
) {
|
|
313
|
+
const node = tr.doc.nodeAt(nodePos);
|
|
314
|
+
if (!node) {
|
|
315
|
+
throw new RangeError("No node at given position");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const oldContent = node.content;
|
|
319
|
+
// Position of the first child inside the node.
|
|
320
|
+
const contentStart = nodePos + 1;
|
|
321
|
+
|
|
322
|
+
if (node.isTextblock) {
|
|
323
|
+
// Inline content: diff at the character/token level. A flat slice (no open
|
|
324
|
+
// depth) is valid because the children are inline leaves.
|
|
325
|
+
const diffStart = oldContent.findDiffStart(newContent);
|
|
326
|
+
if (diffStart === null) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// `findDiffEnd` returns ends in TWO separate coordinate systems: `a` is an
|
|
331
|
+
// offset into the OLD content, `b` is an offset into the NEW content. They
|
|
332
|
+
// are NOT interchangeable when the two fragments differ in size.
|
|
333
|
+
const diffEnd = oldContent.findDiffEnd(newContent)!;
|
|
334
|
+
let { a: oldEnd, b: newEnd } = diffEnd;
|
|
335
|
+
|
|
336
|
+
// The shared prefix (`diffStart`) and shared suffix can overlap, e.g. when
|
|
337
|
+
// inserting/deleting a run of text at a boundary. When that happens an end
|
|
338
|
+
// can fall before `diffStart`. Push the ends forward so neither precedes the
|
|
339
|
+
// shared prefix, keeping the OLD and NEW ranges aligned by the same amount
|
|
340
|
+
// (each coordinate system is checked independently, then the larger shift is
|
|
341
|
+
// applied to both so the suffix stays in sync).
|
|
342
|
+
const shift = Math.max(0, diffStart - oldEnd, diffStart - newEnd);
|
|
343
|
+
if (shift > 0) {
|
|
344
|
+
oldEnd += shift;
|
|
345
|
+
newEnd += shift;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
tr.replace(
|
|
349
|
+
// OLD-doc range to remove: uses old-content offsets.
|
|
350
|
+
contentStart + diffStart,
|
|
351
|
+
contentStart + oldEnd,
|
|
352
|
+
// Replacement: cut the NEW content using new-content offsets. `diffStart`
|
|
353
|
+
// is valid here because it lies within the shared prefix (identical in
|
|
354
|
+
// both fragments), and `newEnd` is a new-content offset.
|
|
355
|
+
new Slice(newContent.cut(diffStart, newEnd), 0, 0),
|
|
356
|
+
);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Nested/block content (table rows, child blocks, ...): snap the diff to whole
|
|
361
|
+
// top-level children so the replacement slice is always a valid sequence of
|
|
362
|
+
// complete children (open depth 0).
|
|
363
|
+
const oldChildCount = oldContent.childCount;
|
|
364
|
+
const newChildCount = newContent.childCount;
|
|
365
|
+
|
|
366
|
+
// Number of identical leading children.
|
|
367
|
+
let startIndex = 0;
|
|
368
|
+
while (
|
|
369
|
+
startIndex < oldChildCount &&
|
|
370
|
+
startIndex < newChildCount &&
|
|
371
|
+
oldContent.child(startIndex).eq(newContent.child(startIndex))
|
|
372
|
+
) {
|
|
373
|
+
startIndex++;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Number of identical trailing children (not overlapping the shared prefix).
|
|
377
|
+
let oldEndIndex = oldChildCount;
|
|
378
|
+
let newEndIndex = newChildCount;
|
|
379
|
+
while (
|
|
380
|
+
oldEndIndex > startIndex &&
|
|
381
|
+
newEndIndex > startIndex &&
|
|
382
|
+
oldContent.child(oldEndIndex - 1).eq(newContent.child(newEndIndex - 1))
|
|
383
|
+
) {
|
|
384
|
+
oldEndIndex--;
|
|
385
|
+
newEndIndex--;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Nothing changed.
|
|
389
|
+
if (startIndex === oldEndIndex && startIndex === newEndIndex) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// Convert child indices to document positions.
|
|
394
|
+
let from = contentStart;
|
|
395
|
+
for (let i = 0; i < startIndex; i++) {
|
|
396
|
+
from += oldContent.child(i).nodeSize;
|
|
397
|
+
}
|
|
398
|
+
let to = from;
|
|
399
|
+
for (let i = startIndex; i < oldEndIndex; i++) {
|
|
400
|
+
to += oldContent.child(i).nodeSize;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// Collect the changed replacement children.
|
|
404
|
+
const replacement: PMNode[] = [];
|
|
405
|
+
for (let i = startIndex; i < newEndIndex; i++) {
|
|
406
|
+
replacement.push(newContent.child(i));
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Use a strict ReplaceStep (rather than the lenient `tr.replace`) so that
|
|
410
|
+
// invalid content for the parent node type (e.g. a columnList that would end
|
|
411
|
+
// up with non-column children) throws instead of being silently coerced.
|
|
412
|
+
tr.step(
|
|
413
|
+
new ReplaceStep(from, to, new Slice(Fragment.from(replacement), 0, 0)),
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Updates the type and/or attributes of the node at `pos` using the smallest
|
|
419
|
+
* possible set of steps.
|
|
420
|
+
*
|
|
421
|
+
* - If neither the type nor any attribute changes, no step is emitted.
|
|
422
|
+
* - If only attributes change (type stays the same), an `AttrStep` is emitted
|
|
423
|
+
* for each changed attribute. These are minimal steps that don't touch the
|
|
424
|
+
* node's content.
|
|
425
|
+
* - If the type changes, `setNodeMarkup` is used, which keeps the node's content
|
|
426
|
+
* via a `ReplaceAroundStep`.
|
|
427
|
+
*/
|
|
428
|
+
function setNodeMarkupMinimal(
|
|
429
|
+
tr: Transform,
|
|
430
|
+
pos: number,
|
|
431
|
+
newType: NodeType,
|
|
432
|
+
newAttrs: Record<string, unknown>,
|
|
433
|
+
) {
|
|
434
|
+
const node = tr.doc.nodeAt(pos);
|
|
435
|
+
if (!node) {
|
|
436
|
+
throw new RangeError("No node at given position");
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Only consider attributes that are actually valid for the target node type.
|
|
440
|
+
// `block.props` may contain props that belong to the content node but not the
|
|
441
|
+
// container (or vice versa), and these should be ignored here.
|
|
442
|
+
const validAttrs = newType.spec.attrs ?? {};
|
|
443
|
+
const filteredNewAttrs: Record<string, unknown> = {};
|
|
444
|
+
for (const attr of Object.keys(newAttrs)) {
|
|
445
|
+
if (attr in validAttrs) {
|
|
446
|
+
filteredNewAttrs[attr] = newAttrs[attr];
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const mergedAttrs = { ...node.attrs, ...filteredNewAttrs };
|
|
451
|
+
|
|
452
|
+
if (node.type === newType) {
|
|
453
|
+
// Only emit AttrSteps for attributes that actually changed.
|
|
454
|
+
for (const attr of Object.keys(mergedAttrs)) {
|
|
455
|
+
if (mergedAttrs[attr] !== node.attrs[attr]) {
|
|
456
|
+
tr.setNodeAttribute(pos, attr, mergedAttrs[attr]);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// Type changed - setNodeMarkup keeps the content via a ReplaceAroundStep.
|
|
463
|
+
tr.setNodeMarkup(pos, newType, mergedAttrs);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Applies a minimal markup update to the node at `pos`, then returns `pos`
|
|
468
|
+
* re-mapped through only the steps that update added.
|
|
469
|
+
*
|
|
470
|
+
* `setNodeMarkupMinimal` may add a step (e.g. a ReplaceAroundStep when the node
|
|
471
|
+
* type changes), which leaves the original `pos` stale. Because `tr` may already
|
|
472
|
+
* contain steps from earlier ops (other `updateBlock` calls sharing the same
|
|
473
|
+
* transaction), we map through only the steps added here — not the whole
|
|
474
|
+
* `tr.mapping` — using a -1 (before) bias so the position stays anchored before
|
|
475
|
+
* the node rather than being pushed past it.
|
|
476
|
+
*/
|
|
477
|
+
function setNodeMarkupMinimalAndRemap(
|
|
478
|
+
tr: Transform,
|
|
479
|
+
pos: number,
|
|
480
|
+
newType: NodeType,
|
|
481
|
+
newAttrs: Record<string, unknown>,
|
|
482
|
+
): number {
|
|
483
|
+
const baseMapLen = tr.mapping.maps.length;
|
|
484
|
+
setNodeMarkupMinimal(tr, pos, newType, newAttrs);
|
|
485
|
+
return tr.mapping.slice(baseMapLen).map(pos, -1);
|
|
486
|
+
}
|
|
487
|
+
|
|
275
488
|
function updateChildren<
|
|
276
489
|
BSchema extends BlockSchema,
|
|
277
490
|
I extends InlineContentSchema,
|
|
@@ -287,15 +500,13 @@ function updateChildren<
|
|
|
287
500
|
|
|
288
501
|
// Checks if a blockGroup node already exists.
|
|
289
502
|
if (blockInfo.childContainer) {
|
|
290
|
-
// Replaces
|
|
291
|
-
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
new Slice(Fragment.from(childNodes), 0, 0),
|
|
298
|
-
),
|
|
503
|
+
// Replaces the child nodes in the existing blockGroup, only touching the
|
|
504
|
+
// range that actually changed (keeping unchanged leading/trailing
|
|
505
|
+
// children untouched).
|
|
506
|
+
replaceContentMinimal(
|
|
507
|
+
tr,
|
|
508
|
+
blockInfo.childContainer.beforePos,
|
|
509
|
+
Fragment.from(childNodes),
|
|
299
510
|
);
|
|
300
511
|
} else {
|
|
301
512
|
if (!blockInfo.isBlockContainer) {
|
|
@@ -340,8 +551,7 @@ export function updateBlock<
|
|
|
340
551
|
.resolve(posInfo.posBeforeNode + 1) // TODO: clean?
|
|
341
552
|
.node();
|
|
342
553
|
|
|
343
|
-
|
|
344
|
-
return nodeToBlock(blockContainerNode, pmSchema);
|
|
554
|
+
return nodeToBlock(blockContainerNode, tr.doc);
|
|
345
555
|
}
|
|
346
556
|
|
|
347
557
|
type CellAnchor = { row: number; col: number; offset: number };
|
|
@@ -8,7 +8,6 @@ import type {
|
|
|
8
8
|
} from "../../../schema/index.js";
|
|
9
9
|
import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
|
|
10
10
|
import { getNodeById } from "../../nodeUtil.js";
|
|
11
|
-
import { getPmSchema } from "../../pmUtil.js";
|
|
12
11
|
|
|
13
12
|
export function getBlock<
|
|
14
13
|
BSchema extends BlockSchema,
|
|
@@ -20,14 +19,13 @@ export function getBlock<
|
|
|
20
19
|
): Block<BSchema, I, S> | undefined {
|
|
21
20
|
const id =
|
|
22
21
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
23
|
-
const pmSchema = getPmSchema(doc);
|
|
24
22
|
|
|
25
23
|
const posInfo = getNodeById(id, doc);
|
|
26
24
|
if (!posInfo) {
|
|
27
25
|
return undefined;
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
return nodeToBlock(posInfo.node,
|
|
28
|
+
return nodeToBlock(posInfo.node, doc);
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
export function getPrevBlock<
|
|
@@ -42,7 +40,6 @@ export function getPrevBlock<
|
|
|
42
40
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
43
41
|
|
|
44
42
|
const posInfo = getNodeById(id, doc);
|
|
45
|
-
const pmSchema = getPmSchema(doc);
|
|
46
43
|
if (!posInfo) {
|
|
47
44
|
return undefined;
|
|
48
45
|
}
|
|
@@ -53,7 +50,7 @@ export function getPrevBlock<
|
|
|
53
50
|
return undefined;
|
|
54
51
|
}
|
|
55
52
|
|
|
56
|
-
return nodeToBlock(nodeToConvert,
|
|
53
|
+
return nodeToBlock(nodeToConvert, doc);
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
export function getNextBlock<
|
|
@@ -67,7 +64,6 @@ export function getNextBlock<
|
|
|
67
64
|
const id =
|
|
68
65
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
69
66
|
const posInfo = getNodeById(id, doc);
|
|
70
|
-
const pmSchema = getPmSchema(doc);
|
|
71
67
|
if (!posInfo) {
|
|
72
68
|
return undefined;
|
|
73
69
|
}
|
|
@@ -80,7 +76,7 @@ export function getNextBlock<
|
|
|
80
76
|
return undefined;
|
|
81
77
|
}
|
|
82
78
|
|
|
83
|
-
return nodeToBlock(nodeToConvert,
|
|
79
|
+
return nodeToBlock(nodeToConvert, doc);
|
|
84
80
|
}
|
|
85
81
|
|
|
86
82
|
export function getParentBlock<
|
|
@@ -93,7 +89,6 @@ export function getParentBlock<
|
|
|
93
89
|
): Block<BSchema, I, S> | undefined {
|
|
94
90
|
const id =
|
|
95
91
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
96
|
-
const pmSchema = getPmSchema(doc);
|
|
97
92
|
const posInfo = getNodeById(id, doc);
|
|
98
93
|
if (!posInfo) {
|
|
99
94
|
return undefined;
|
|
@@ -112,5 +107,5 @@ export function getParentBlock<
|
|
|
112
107
|
return undefined;
|
|
113
108
|
}
|
|
114
109
|
|
|
115
|
-
return nodeToBlock(nodeToConvert,
|
|
110
|
+
return nodeToBlock(nodeToConvert, doc);
|
|
116
111
|
}
|
|
@@ -22,7 +22,6 @@ export function getSelection<
|
|
|
22
22
|
I extends InlineContentSchema,
|
|
23
23
|
S extends StyleSchema,
|
|
24
24
|
>(tr: Transaction): Selection<BSchema, I, S> | undefined {
|
|
25
|
-
const pmSchema = getPmSchema(tr);
|
|
26
25
|
// Return undefined if the selection is collapsed or a node is selected.
|
|
27
26
|
if (tr.selection.empty || "node" in tr.selection) {
|
|
28
27
|
return undefined;
|
|
@@ -51,7 +50,7 @@ export function getSelection<
|
|
|
51
50
|
);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
return nodeToBlock(node,
|
|
53
|
+
return nodeToBlock(node, tr.doc);
|
|
55
54
|
};
|
|
56
55
|
|
|
57
56
|
const blocks: Block<BSchema, I, S>[] = [];
|
|
@@ -92,7 +91,7 @@ export function getSelection<
|
|
|
92
91
|
// [ id-2, id-3, id-4, id-6, id-7, id-8, id-9 ]
|
|
93
92
|
if ($startBlockBeforePos.depth > sharedDepth) {
|
|
94
93
|
// Adds the block that the selection starts in.
|
|
95
|
-
blocks.push(nodeToBlock($startBlockBeforePos.nodeAfter!,
|
|
94
|
+
blocks.push(nodeToBlock($startBlockBeforePos.nodeAfter!, tr.doc));
|
|
96
95
|
|
|
97
96
|
// Traverses all depths from the depth of the block in which the selection
|
|
98
97
|
// starts, up to the shared depth.
|
|
@@ -123,6 +122,7 @@ export function getSelection<
|
|
|
123
122
|
|
|
124
123
|
if (blocks.length === 0) {
|
|
125
124
|
throw new Error(
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-base-to-string
|
|
126
126
|
`Error getting selection - selection doesn't span any blocks (${tr.selection})`,
|
|
127
127
|
);
|
|
128
128
|
}
|
|
@@ -223,8 +223,6 @@ export function setSelection(
|
|
|
223
223
|
export function getSelectionCutBlocks(tr: Transaction, expandToWords = false) {
|
|
224
224
|
// TODO: fix image node selection
|
|
225
225
|
|
|
226
|
-
const pmSchema = getPmSchema(tr);
|
|
227
|
-
|
|
228
226
|
const range = expandToWords
|
|
229
227
|
? expandPMRangeToWords(tr.doc, tr.selection)
|
|
230
228
|
: tr.selection;
|
|
@@ -257,7 +255,6 @@ export function getSelectionCutBlocks(tr: Transaction, expandToWords = false) {
|
|
|
257
255
|
|
|
258
256
|
const selectionInfo = prosemirrorSliceToSlicedBlocks(
|
|
259
257
|
tr.doc.slice(start.pos, end.pos, true),
|
|
260
|
-
pmSchema,
|
|
261
258
|
);
|
|
262
259
|
|
|
263
260
|
return {
|
|
@@ -14,7 +14,8 @@ import type {
|
|
|
14
14
|
import { UnreachableCaseError } from "../../../util/typescript.js";
|
|
15
15
|
import {
|
|
16
16
|
getBlockInfo,
|
|
17
|
-
|
|
17
|
+
getBlockInfoFromSelection,
|
|
18
|
+
getNodeId,
|
|
18
19
|
} from "../../getBlockInfoFromPos.js";
|
|
19
20
|
import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
|
|
20
21
|
import { getNodeById } from "../../nodeUtil.js";
|
|
@@ -25,8 +26,7 @@ export function getTextCursorPosition<
|
|
|
25
26
|
I extends InlineContentSchema,
|
|
26
27
|
S extends StyleSchema,
|
|
27
28
|
>(tr: Transaction): TextCursorPosition<BSchema, I, S> {
|
|
28
|
-
const { bnBlock } =
|
|
29
|
-
const pmSchema = getPmSchema(tr.doc);
|
|
29
|
+
const { bnBlock } = getBlockInfoFromSelection(tr);
|
|
30
30
|
|
|
31
31
|
const resolvedPos = tr.doc.resolve(bnBlock.beforePos);
|
|
32
32
|
// Gets previous blockContainer node at the same nesting level, if the current node isn't the first child.
|
|
@@ -47,11 +47,11 @@ export function getTextCursorPosition<
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
return {
|
|
50
|
-
block: nodeToBlock(bnBlock.node,
|
|
51
|
-
prevBlock: prevNode === null ? undefined : nodeToBlock(prevNode,
|
|
52
|
-
nextBlock: nextNode === null ? undefined : nodeToBlock(nextNode,
|
|
50
|
+
block: nodeToBlock(bnBlock.node, tr.doc),
|
|
51
|
+
prevBlock: prevNode === null ? undefined : nodeToBlock(prevNode, tr.doc),
|
|
52
|
+
nextBlock: nextNode === null ? undefined : nodeToBlock(nextNode, tr.doc),
|
|
53
53
|
parentBlock:
|
|
54
|
-
parentNode === undefined ? undefined : nodeToBlock(parentNode,
|
|
54
|
+
parentNode === undefined ? undefined : nodeToBlock(parentNode, tr.doc),
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -71,7 +71,7 @@ export function setTextCursorPosition(
|
|
|
71
71
|
|
|
72
72
|
const info = getBlockInfo(posInfo);
|
|
73
73
|
|
|
74
|
-
const contentType: "none" | "inline" | "table" =
|
|
74
|
+
const contentType: "none" | "inline" | "table" | "plain" =
|
|
75
75
|
schema.blockSchema[info.blockNoteType]!.content;
|
|
76
76
|
|
|
77
77
|
if (info.isBlockContainer) {
|
|
@@ -81,7 +81,7 @@ export function setTextCursorPosition(
|
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
if (contentType === "inline") {
|
|
84
|
+
if (contentType === "inline" || contentType === "plain") {
|
|
85
85
|
if (placement === "start") {
|
|
86
86
|
tr.setSelection(
|
|
87
87
|
TextSelection.create(tr.doc, blockContent.beforePos + 1),
|
|
@@ -113,6 +113,6 @@ export function setTextCursorPosition(
|
|
|
113
113
|
? info.childContainer.node.firstChild!
|
|
114
114
|
: info.childContainer.node.lastChild!;
|
|
115
115
|
|
|
116
|
-
setTextCursorPosition(tr, child.
|
|
116
|
+
setTextCursorPosition(tr, getNodeId(child, tr.doc), placement);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
InlineContentSchema,
|
|
6
6
|
StyleSchema,
|
|
7
7
|
} from "../../../schema/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { getBlockInfoAtNearest, getNodeId } from "../../getBlockInfoFromPos.js";
|
|
9
9
|
import { acceptedMIMETypes } from "./acceptedMIMETypes.js";
|
|
10
10
|
|
|
11
11
|
function checkFileExtensionsMatch(
|
|
@@ -159,16 +159,20 @@ export async function handleFileInsertion<
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
insertedBlockId = editor.transact((tr) => {
|
|
162
|
-
const
|
|
162
|
+
const blockInfo = getBlockInfoAtNearest(tr, pos.pos);
|
|
163
|
+
const id = getNodeId(blockInfo.bnBlock.node, tr.doc);
|
|
164
|
+
// TODO technically data-id will always be the non-rewritten id, so there might be multiple in the document.
|
|
165
|
+
// getNodeId might find the wrong one (aka point to a deleted node when it should be a non-deleted on)
|
|
166
|
+
// This is acceptable right now, given that we don't expect edits on the document content
|
|
163
167
|
const blockElement = editor.domElement?.querySelector(
|
|
164
|
-
`[data-id="${
|
|
168
|
+
`[data-id="${id}"]`,
|
|
165
169
|
);
|
|
166
170
|
|
|
167
171
|
const blockRect = blockElement?.getBoundingClientRect();
|
|
168
172
|
|
|
169
173
|
return insertOrUpdateBlock(
|
|
170
174
|
editor,
|
|
171
|
-
editor.getBlock(
|
|
175
|
+
editor.getBlock(id)!,
|
|
172
176
|
fileBlock,
|
|
173
177
|
blockRect && (blockRect.top + blockRect.bottom) / 2 > coords.top
|
|
174
178
|
? "before"
|
|
@@ -293,7 +293,8 @@ function serializeBlock<
|
|
|
293
293
|
props.start &&
|
|
294
294
|
props?.start !== 1
|
|
295
295
|
) {
|
|
296
|
-
|
|
296
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
297
|
+
list.setAttribute("start", String(props.start));
|
|
297
298
|
}
|
|
298
299
|
fragment.append(list);
|
|
299
300
|
}
|