@blocknote/core 0.27.2 → 0.29.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/blocknote.cjs +10 -10
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +3032 -3118
- package/dist/blocknote.js.map +1 -1
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +10 -10
- package/dist/locales.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +2 -2
- package/src/api/__snapshots__/blocks-deleted-nested-deep.json +26 -0
- package/src/api/__snapshots__/blocks-deleted-nested.json +68 -0
- package/src/api/__snapshots__/blocks-deleted.json +26 -0
- package/src/api/__snapshots__/blocks-inserted-nested.json +62 -0
- package/src/api/__snapshots__/blocks-inserted.json +20 -0
- package/src/api/__snapshots__/blocks-updated-content-inserted.json +42 -0
- package/src/api/__snapshots__/blocks-updated-multiple-insert.json +50 -0
- package/src/api/__snapshots__/blocks-updated-multiple.json +82 -0
- package/src/api/__snapshots__/blocks-updated-nested-deep.json +42 -0
- package/src/api/__snapshots__/blocks-updated-nested-multiple.json +118 -0
- package/src/api/__snapshots__/blocks-updated-nested.json +78 -0
- package/src/api/__snapshots__/blocks-updated-single.json +42 -0
- package/src/api/__snapshots__/blocks-updated.json +42 -0
- package/src/api/blockManipulation/__snapshots__/transactions.test.ts.snap +34 -0
- package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +312 -0
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +127 -94
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +19 -37
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +8 -6
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +25 -31
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +93 -91
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +16 -20
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +14 -1
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +18 -56
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +52 -46
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +1051 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +247 -154
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +109 -142
- package/src/api/blockManipulation/getBlock/getBlock.ts +23 -48
- package/src/api/blockManipulation/insertContentAt.ts +4 -17
- package/src/api/blockManipulation/selections/selection.test.ts +32 -16
- package/src/api/blockManipulation/selections/selection.ts +25 -51
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +35 -14
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +34 -65
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +8 -10
- package/src/api/clipboard/toClipboard/copyExtension.ts +7 -7
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +7 -16
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +3 -17
- package/src/api/getBlockInfoFromPos.ts +13 -1
- package/src/api/nodeConversions/blockToNode.ts +21 -10
- package/src/api/nodeConversions/fragmentToBlocks.ts +5 -18
- package/src/api/nodeConversions/nodeToBlock.ts +11 -8
- package/src/api/nodeUtil.test.ts +228 -0
- package/src/api/nodeUtil.ts +235 -2
- package/src/api/parsers/html/parseHTML.ts +2 -10
- package/src/api/parsers/markdown/parseMarkdown.ts +2 -8
- package/src/api/pmUtil.ts +54 -0
- package/src/api/positionMapping.test.ts +370 -0
- package/src/api/positionMapping.ts +114 -0
- package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +2 -2
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +9 -13
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +5 -9
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +19 -31
- package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +10 -8
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +9 -13
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +1 -1
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +5 -9
- package/src/blocks/defaultBlockHelpers.ts +1 -1
- package/src/editor/BlockNoteEditor.test.ts +1 -1
- package/src/editor/BlockNoteEditor.ts +259 -130
- package/src/editor/BlockNoteTipTapEditor.ts +91 -8
- package/src/extensions/Comments/CommentsPlugin.ts +32 -34
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +4 -8
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +12 -13
- package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +1 -3
- package/src/extensions/SideMenu/MultipleNodeSelection.ts +3 -1
- package/src/extensions/SideMenu/dragging.ts +1 -1
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +38 -25
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +8 -8
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +150 -136
- package/src/i18n/locales/de.ts +10 -10
- package/src/index.ts +4 -3
- package/src/schema/inlineContent/createSpec.ts +1 -5
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +2 -2
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +4 -8
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +9 -10
- package/types/src/api/blockManipulation/getBlock/getBlock.d.ts +7 -7
- package/types/src/api/blockManipulation/insertContentAt.d.ts +5 -3
- package/types/src/api/blockManipulation/selections/selection.d.ts +3 -3
- package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.d.ts +5 -5
- package/types/src/api/getBlockInfoFromPos.d.ts +8 -1
- package/types/src/api/nodeConversions/blockToNode.d.ts +3 -3
- package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +1 -2
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +2 -2
- package/types/src/api/nodeUtil.d.ts +67 -1
- package/types/src/api/parsers/html/parseHTML.d.ts +1 -1
- package/types/src/api/parsers/markdown/parseMarkdown.d.ts +1 -1
- package/types/src/api/pmUtil.d.ts +12 -0
- package/types/src/api/positionMapping.d.ts +25 -0
- package/types/src/editor/BlockNoteEditor.d.ts +72 -10
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +15 -2
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +1 -1
- package/types/src/index.d.ts +1 -2
- package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +0 -1859
- package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.ts +0 -40
- package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts +0 -20
- package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraph.html +0 -138
- package/src/api/clipboard/__snapshots__/external/pasteEndOfParagraphText.html +0 -138
- package/src/api/clipboard/__snapshots__/external/pasteImage.html +0 -153
- package/src/api/clipboard/__snapshots__/external/pasteParagraphInCustomBlock.html +0 -138
- package/src/api/clipboard/__snapshots__/external/pasteTable.html +0 -233
- package/src/api/clipboard/__snapshots__/external/pasteTableInExistingTable.html +0 -216
- package/src/api/clipboard/__snapshots__/internal/basicBlocks.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/basicBlocksWithProps.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/childToParent.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/childrenToNextParent.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/childrenToNextParentsChildren.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/image.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/multipleChildren.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/multipleStyledText.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/nestedImage.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/paragraphInCustomBlock.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/partialChildToParent.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/styledText.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/tableAllCells.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/tableCell.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/tableCellText.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/tableRow.html +0 -1
- package/src/api/clipboard/__snapshots__/internal/unstyledText.html +0 -1
- package/src/api/clipboard/clipboardExternal.test.ts +0 -161
- package/src/api/clipboard/clipboardInternal.test.ts +0 -435
- package/src/api/clipboard/testUtil.ts +0 -27
- package/src/api/exporters/html/__snapshots__/codeBlock/contains-newlines/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/contains-newlines/internal.html +0 -3
- package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/empty/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/empty/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/python/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/codeBlock/python/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/complex/misc/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/complex/misc/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/customBlock/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/customBlock/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/customParagraph/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/customParagraph/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/customParagraph/lineBreaks/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/customParagraph/lineBreaks/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/customParagraph/nested/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/customParagraph/nested/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/customParagraph/styled/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/customParagraph/styled/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/file/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/file/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/file/button/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/file/button/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/file/nested/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/file/nested/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/file/noCaption/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/file/noCaption/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/file/noName/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/file/noName/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/fontSize/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/fontSize/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/between-links/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/between-links/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/end/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/end/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/link/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/link/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/multiple/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/multiple/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/only/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/only/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/start/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/start/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/styles/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/hardbreak/styles/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/button/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/button/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/nested/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/nested/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/noCaption/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/noCaption/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/noName/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/noName/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/noPreview/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/image/noPreview/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/link/adjacent/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/link/adjacent/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/link/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/link/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/link/styled/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/link/styled/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/lists/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/lists/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/lists/nested/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/lists/nested/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/mention/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/mention/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/pageBreak/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/pageBreak/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/paragraph/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/paragraph/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/paragraph/empty/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/paragraph/empty/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/paragraph/lineBreaks/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/paragraph/lineBreaks/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/paragraph/nested/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/paragraph/nested/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/paragraph/styled/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/paragraph/styled/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/paste/parse-basic-block-types.json +0 -140
- package/src/api/exporters/html/__snapshots__/paste/parse-deep-nested-content.json +0 -240
- package/src/api/exporters/html/__snapshots__/paste/parse-div-with-inline-content.json +0 -91
- package/src/api/exporters/html/__snapshots__/paste/parse-divs.json +0 -19
- package/src/api/exporters/html/__snapshots__/paste/parse-fake-image-caption.json +0 -31
- package/src/api/exporters/html/__snapshots__/paste/parse-mixed-nested-lists.json +0 -70
- package/src/api/exporters/html/__snapshots__/paste/parse-nested-lists-with-paragraphs.json +0 -70
- package/src/api/exporters/html/__snapshots__/paste/parse-nested-lists.json +0 -70
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleFile/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleFile/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleFile/button/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleFile/button/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleFile/nested/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleFile/nested/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/button/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/button/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noName/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/small/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/small/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/allColWidths/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/allColWidths/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/basic/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/headerCols/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/headerCols/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/headerRows/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/headerRows/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/headersRows/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/headersRows/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/mixedCellColors/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/mixedCellColors/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/mixedColWidths/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/mixedColWidths/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/table/mixedRowspansAndColspans/internal.html +0 -1
- package/src/api/exporters/html/__snapshots__/tag/basic/external.html +0 -1
- package/src/api/exporters/html/__snapshots__/tag/basic/internal.html +0 -1
- package/src/api/exporters/html/htmlConversion.test.ts +0 -110
- package/src/api/exporters/markdown/__snapshots__/codeBlock/contains-newlines/markdown.md +0 -4
- package/src/api/exporters/markdown/__snapshots__/codeBlock/defaultLanguage/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/codeBlock/empty/markdown.md +0 -2
- package/src/api/exporters/markdown/__snapshots__/codeBlock/python/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/complex/misc/markdown.md +0 -5
- package/src/api/exporters/markdown/__snapshots__/customBlock/basic/markdown.md +0 -5
- package/src/api/exporters/markdown/__snapshots__/customParagraph/basic/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/customParagraph/lineBreaks/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/customParagraph/nested/markdown.md +0 -5
- package/src/api/exporters/markdown/__snapshots__/customParagraph/styled/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/file/basic/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/file/button/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/file/nested/markdown.md +0 -7
- package/src/api/exporters/markdown/__snapshots__/file/noCaption/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/file/noName/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/fontSize/basic/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/hardbreak/basic/markdown.md +0 -2
- package/src/api/exporters/markdown/__snapshots__/hardbreak/between-links/markdown.md +0 -2
- package/src/api/exporters/markdown/__snapshots__/hardbreak/end/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/hardbreak/link/markdown.md +0 -2
- package/src/api/exporters/markdown/__snapshots__/hardbreak/multiple/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/hardbreak/only/markdown.md +0 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/start/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/hardbreak/styles/markdown.md +0 -2
- package/src/api/exporters/markdown/__snapshots__/image/basic/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/image/button/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/image/nested/markdown.md +0 -7
- package/src/api/exporters/markdown/__snapshots__/image/noCaption/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/image/noName/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/image/noPreview/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/link/adjacent/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/link/basic/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/link/styled/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/lists/basic/markdown.md +0 -10
- package/src/api/exporters/markdown/__snapshots__/lists/nested/markdown.md +0 -10
- package/src/api/exporters/markdown/__snapshots__/mention/basic/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/pageBreak/basic/markdown.md +0 -0
- package/src/api/exporters/markdown/__snapshots__/paragraph/basic/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/paragraph/empty/markdown.md +0 -0
- package/src/api/exporters/markdown/__snapshots__/paragraph/lineBreaks/markdown.md +0 -2
- package/src/api/exporters/markdown/__snapshots__/paragraph/nested/markdown.md +0 -5
- package/src/api/exporters/markdown/__snapshots__/paragraph/styled/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/basic/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/nested/markdown.md +0 -5
- package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/styled/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/simpleFile/basic/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/simpleFile/button/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/simpleFile/nested/markdown.md +0 -7
- package/src/api/exporters/markdown/__snapshots__/simpleImage/basic/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/simpleImage/button/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/simpleImage/nested/markdown.md +0 -7
- package/src/api/exporters/markdown/__snapshots__/simpleImage/noCaption/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/simpleImage/noName/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/simpleImage/noPreview/markdown.md +0 -3
- package/src/api/exporters/markdown/__snapshots__/small/basic/markdown.md +0 -1
- package/src/api/exporters/markdown/__snapshots__/table/allColWidths/markdown.md +0 -5
- package/src/api/exporters/markdown/__snapshots__/table/basic/markdown.md +0 -5
- package/src/api/exporters/markdown/__snapshots__/table/headerCols/markdown.md +0 -4
- package/src/api/exporters/markdown/__snapshots__/table/headerRows/markdown.md +0 -4
- package/src/api/exporters/markdown/__snapshots__/table/mixedCellColors/markdown.md +0 -5
- package/src/api/exporters/markdown/__snapshots__/table/mixedColWidths/markdown.md +0 -5
- package/src/api/exporters/markdown/__snapshots__/table/mixedRowspansAndColspans/markdown.md +0 -5
- package/src/api/exporters/markdown/__snapshots__/tag/basic/markdown.md +0 -1
- package/src/api/exporters/markdown/markdownExporter.test.ts +0 -86
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +0 -3473
- package/src/api/nodeConversions/nodeConversions.test.ts +0 -83
- package/src/api/parsers/html/__snapshots__/list-test.json +0 -177
- package/src/api/parsers/html/__snapshots__/parse-2-tables.json +0 -129
- package/src/api/parsers/html/__snapshots__/parse-basic-block-types.json +0 -142
- package/src/api/parsers/html/__snapshots__/parse-codeblocks.json +0 -62
- package/src/api/parsers/html/__snapshots__/parse-div-with-inline-content.json +0 -91
- package/src/api/parsers/html/__snapshots__/parse-divs.json +0 -121
- package/src/api/parsers/html/__snapshots__/parse-fake-image-caption.json +0 -33
- package/src/api/parsers/html/__snapshots__/parse-image-in-paragraph.json +0 -16
- package/src/api/parsers/html/__snapshots__/parse-mixed-nested-lists.json +0 -265
- package/src/api/parsers/html/__snapshots__/parse-nested-lists-with-paragraphs.json +0 -265
- package/src/api/parsers/html/__snapshots__/parse-nested-lists.json +0 -265
- package/src/api/parsers/html/__snapshots__/parse-notion-html.json +0 -565
- package/src/api/parsers/html/__snapshots__/parse-two-divs.json +0 -36
- package/src/api/parsers/html/parseHTML.test.ts +0 -563
- package/src/api/parsers/markdown/__snapshots__/complex.json +0 -353
- package/src/api/parsers/markdown/__snapshots__/issue-226-1.json +0 -71
- package/src/api/parsers/markdown/__snapshots__/issue-226-2.json +0 -144
- package/src/api/parsers/markdown/__snapshots__/nested.json +0 -72
- package/src/api/parsers/markdown/__snapshots__/non-nested.json +0 -71
- package/src/api/parsers/markdown/__snapshots__/pasted/complex.json +0 -319
- package/src/api/parsers/markdown/__snapshots__/pasted/issue-226-1.json +0 -81
- package/src/api/parsers/markdown/__snapshots__/pasted/issue-226-2.json +0 -165
- package/src/api/parsers/markdown/__snapshots__/pasted/nested.json +0 -81
- package/src/api/parsers/markdown/__snapshots__/pasted/non-nested.json +0 -81
- package/src/api/parsers/markdown/__snapshots__/pasted/styled.json +0 -61
- package/src/api/parsers/markdown/__snapshots__/pasted/whitespace bold.json +0 -42
- package/src/api/parsers/markdown/__snapshots__/styled.json +0 -58
- package/src/api/parsers/markdown/__snapshots__/whitespace bold.json +0 -19
- package/src/api/parsers/markdown/parseMarkdown.test.ts +0 -135
- package/src/api/testUtil/cases/customBlocks.ts +0 -342
- package/src/api/testUtil/cases/customInlineContent.ts +0 -113
- package/src/api/testUtil/cases/customStyles.ts +0 -102
- package/src/api/testUtil/cases/defaultSchema.ts +0 -1493
- package/src/api/testUtil/index.ts +0 -19
- package/src/api/testUtil/partialBlockTestUtil.ts +0 -198
- package/src/api/testUtil/paste.ts +0 -46
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +0 -4
- package/types/src/api/clipboard/clipboardInternal.test.d.ts +0 -1
- package/types/src/api/clipboard/testUtil.d.ts +0 -541
- package/types/src/api/exporters/html/htmlConversion.test.d.ts +0 -1
- package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +0 -1
- package/types/src/api/nodeConversions/nodeConversions.test.d.ts +0 -1
- package/types/src/api/parsers/html/parseHTML.test.d.ts +0 -1
- package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +0 -1
- package/types/src/api/testUtil/cases/customBlocks.d.ts +0 -670
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +0 -558
- package/types/src/api/testUtil/cases/customStyles.d.ts +0 -552
- package/types/src/api/testUtil/cases/defaultSchema.d.ts +0 -4
- package/types/src/api/testUtil/index.d.ts +0 -14
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +0 -9
- package/types/src/api/testUtil/paste.d.ts +0 -2
- /package/types/src/api/{blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts → nodeUtil.test.d.ts} +0 -0
- /package/types/src/api/{clipboard/clipboardExternal.test.d.ts → positionMapping.test.d.ts} +0 -0
|
@@ -1,137 +1,170 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
|
|
3
3
|
import { setupTestEnv } from "../../setupTestEnv.js";
|
|
4
|
-
import { insertBlocks } from "./insertBlocks.js";
|
|
4
|
+
import { insertBlocks as insertBlocksTr } from "./insertBlocks.js";
|
|
5
|
+
import { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
|
|
6
|
+
import { PartialBlock } from "../../../../blocks/defaultBlocks.js";
|
|
7
|
+
import { BlockIdentifier } from "../../../../schema/index.js";
|
|
5
8
|
|
|
6
9
|
const getEditor = setupTestEnv();
|
|
7
10
|
|
|
11
|
+
function insertBlocks(
|
|
12
|
+
editor: BlockNoteEditor,
|
|
13
|
+
blocksToInsert: PartialBlock<any, any, any>[],
|
|
14
|
+
referenceBlock: BlockIdentifier,
|
|
15
|
+
placement: "before" | "after" = "before"
|
|
16
|
+
) {
|
|
17
|
+
return editor.transact((tr) =>
|
|
18
|
+
insertBlocksTr(tr, blocksToInsert, referenceBlock, placement)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
8
22
|
describe("Test insertBlocks", () => {
|
|
9
23
|
it("Insert single basic block before (without type)", () => {
|
|
10
|
-
|
|
24
|
+
expect(
|
|
25
|
+
insertBlocks(getEditor(), [{ content: "test" }], "paragraph-0", "before")
|
|
26
|
+
).toMatchSnapshot();
|
|
11
27
|
|
|
12
28
|
expect(getEditor().document).toMatchSnapshot();
|
|
13
29
|
});
|
|
14
30
|
|
|
15
31
|
it("Insert single basic block before", () => {
|
|
16
|
-
|
|
32
|
+
expect(
|
|
33
|
+
insertBlocks(
|
|
34
|
+
getEditor(),
|
|
35
|
+
[{ type: "paragraph" }],
|
|
36
|
+
"paragraph-0",
|
|
37
|
+
"before"
|
|
38
|
+
)
|
|
39
|
+
).toMatchSnapshot();
|
|
17
40
|
|
|
18
41
|
expect(getEditor().document).toMatchSnapshot();
|
|
19
42
|
});
|
|
20
43
|
|
|
21
44
|
it("Insert single basic block after", () => {
|
|
22
|
-
|
|
45
|
+
expect(
|
|
46
|
+
insertBlocks(getEditor(), [{ type: "paragraph" }], "paragraph-0", "after")
|
|
47
|
+
).toMatchSnapshot();
|
|
23
48
|
|
|
24
49
|
expect(getEditor().document).toMatchSnapshot();
|
|
25
50
|
});
|
|
26
51
|
|
|
27
52
|
it("Insert multiple blocks before", () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
53
|
+
expect(
|
|
54
|
+
insertBlocks(
|
|
55
|
+
getEditor(),
|
|
56
|
+
[
|
|
57
|
+
{ type: "paragraph", content: "Inserted paragraph 1" },
|
|
58
|
+
{ type: "paragraph", content: "Inserted paragraph 2" },
|
|
59
|
+
{ type: "paragraph", content: "Inserted paragraph 3" },
|
|
60
|
+
],
|
|
61
|
+
"paragraph-0",
|
|
62
|
+
"before"
|
|
63
|
+
)
|
|
64
|
+
).toMatchSnapshot();
|
|
38
65
|
|
|
39
66
|
expect(getEditor().document).toMatchSnapshot();
|
|
40
67
|
});
|
|
41
68
|
|
|
42
69
|
it("Insert multiple blocks after", () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
expect(
|
|
71
|
+
insertBlocks(
|
|
72
|
+
getEditor(),
|
|
73
|
+
[
|
|
74
|
+
{ type: "paragraph", content: "Inserted paragraph 1" },
|
|
75
|
+
{ type: "paragraph", content: "Inserted paragraph 2" },
|
|
76
|
+
{ type: "paragraph", content: "Inserted paragraph 3" },
|
|
77
|
+
],
|
|
78
|
+
"paragraph-0",
|
|
79
|
+
"after"
|
|
80
|
+
)
|
|
81
|
+
).toMatchSnapshot();
|
|
53
82
|
|
|
54
83
|
expect(getEditor().document).toMatchSnapshot();
|
|
55
84
|
});
|
|
56
85
|
|
|
57
86
|
it("Insert single complex block before", () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
content: [
|
|
71
|
-
{ type: "text", text: "Heading", styles: { bold: true } },
|
|
72
|
-
{ type: "text", text: " with styled ", styles: {} },
|
|
73
|
-
{ type: "text", text: "content", styles: { italic: true } },
|
|
74
|
-
],
|
|
75
|
-
children: [
|
|
76
|
-
{
|
|
77
|
-
id: "inserted-nested-paragraph-2",
|
|
78
|
-
type: "paragraph",
|
|
79
|
-
content: "Nested Paragraph 2",
|
|
80
|
-
children: [
|
|
81
|
-
{
|
|
82
|
-
id: "inserted-double-nested-paragraph-2",
|
|
83
|
-
type: "paragraph",
|
|
84
|
-
content: "Double Nested Paragraph 2",
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
+
expect(
|
|
88
|
+
insertBlocks(
|
|
89
|
+
getEditor(),
|
|
90
|
+
[
|
|
91
|
+
{
|
|
92
|
+
id: "inserted-heading-with-everything",
|
|
93
|
+
type: "heading",
|
|
94
|
+
props: {
|
|
95
|
+
backgroundColor: "red",
|
|
96
|
+
level: 2,
|
|
97
|
+
textAlignment: "center",
|
|
98
|
+
textColor: "red",
|
|
87
99
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
content: [
|
|
101
|
+
{ type: "text", text: "Heading", styles: { bold: true } },
|
|
102
|
+
{ type: "text", text: " with styled ", styles: {} },
|
|
103
|
+
{ type: "text", text: "content", styles: { italic: true } },
|
|
104
|
+
],
|
|
105
|
+
children: [
|
|
106
|
+
{
|
|
107
|
+
id: "inserted-nested-paragraph-2",
|
|
108
|
+
type: "paragraph",
|
|
109
|
+
content: "Nested Paragraph 2",
|
|
110
|
+
children: [
|
|
111
|
+
{
|
|
112
|
+
id: "inserted-double-nested-paragraph-2",
|
|
113
|
+
type: "paragraph",
|
|
114
|
+
content: "Double Nested Paragraph 2",
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
"paragraph-0",
|
|
122
|
+
"before"
|
|
123
|
+
)
|
|
124
|
+
).toMatchSnapshot();
|
|
94
125
|
|
|
95
126
|
expect(getEditor().document).toMatchSnapshot();
|
|
96
127
|
});
|
|
97
128
|
|
|
98
129
|
it("Insert single complex block after", () => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
content: [
|
|
112
|
-
{ type: "text", text: "Heading", styles: { bold: true } },
|
|
113
|
-
{ type: "text", text: " with styled ", styles: {} },
|
|
114
|
-
{ type: "text", text: "content", styles: { italic: true } },
|
|
115
|
-
],
|
|
116
|
-
children: [
|
|
117
|
-
{
|
|
118
|
-
id: "inserted-nested-paragraph-2",
|
|
119
|
-
type: "paragraph",
|
|
120
|
-
content: "Nested Paragraph 2",
|
|
121
|
-
children: [
|
|
122
|
-
{
|
|
123
|
-
id: "inserted-double-nested-paragraph-2",
|
|
124
|
-
type: "paragraph",
|
|
125
|
-
content: "Double Nested Paragraph 2",
|
|
126
|
-
},
|
|
127
|
-
],
|
|
130
|
+
expect(
|
|
131
|
+
insertBlocks(
|
|
132
|
+
getEditor(),
|
|
133
|
+
[
|
|
134
|
+
{
|
|
135
|
+
id: "inserted-heading-with-everything",
|
|
136
|
+
type: "heading",
|
|
137
|
+
props: {
|
|
138
|
+
backgroundColor: "red",
|
|
139
|
+
level: 2,
|
|
140
|
+
textAlignment: "center",
|
|
141
|
+
textColor: "red",
|
|
128
142
|
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
143
|
+
content: [
|
|
144
|
+
{ type: "text", text: "Heading", styles: { bold: true } },
|
|
145
|
+
{ type: "text", text: " with styled ", styles: {} },
|
|
146
|
+
{ type: "text", text: "content", styles: { italic: true } },
|
|
147
|
+
],
|
|
148
|
+
children: [
|
|
149
|
+
{
|
|
150
|
+
id: "inserted-nested-paragraph-2",
|
|
151
|
+
type: "paragraph",
|
|
152
|
+
content: "Nested Paragraph 2",
|
|
153
|
+
children: [
|
|
154
|
+
{
|
|
155
|
+
id: "inserted-double-nested-paragraph-2",
|
|
156
|
+
type: "paragraph",
|
|
157
|
+
content: "Double Nested Paragraph 2",
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
"paragraph-0",
|
|
165
|
+
"after"
|
|
166
|
+
)
|
|
167
|
+
).toMatchSnapshot();
|
|
135
168
|
|
|
136
169
|
expect(getEditor().document).toMatchSnapshot();
|
|
137
170
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment, Slice } from "prosemirror-model";
|
|
2
2
|
|
|
3
3
|
import { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js";
|
|
4
|
-
import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor";
|
|
5
4
|
import {
|
|
6
5
|
BlockIdentifier,
|
|
7
6
|
BlockSchema,
|
|
@@ -11,63 +10,46 @@ import {
|
|
|
11
10
|
import { blockToNode } from "../../../nodeConversions/blockToNode.js";
|
|
12
11
|
import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js";
|
|
13
12
|
import { getNodeById } from "../../../nodeUtil.js";
|
|
13
|
+
import { ReplaceStep } from "prosemirror-transform";
|
|
14
|
+
import type { Transaction } from "prosemirror-state";
|
|
15
|
+
import { getPmSchema } from "../../../pmUtil.js";
|
|
14
16
|
|
|
15
17
|
export function insertBlocks<
|
|
16
18
|
BSchema extends BlockSchema,
|
|
17
19
|
I extends InlineContentSchema,
|
|
18
20
|
S extends StyleSchema
|
|
19
21
|
>(
|
|
20
|
-
|
|
22
|
+
tr: Transaction,
|
|
21
23
|
blocksToInsert: PartialBlock<BSchema, I, S>[],
|
|
22
24
|
referenceBlock: BlockIdentifier,
|
|
23
25
|
placement: "before" | "after" = "before"
|
|
24
26
|
): Block<BSchema, I, S>[] {
|
|
25
27
|
const id =
|
|
26
28
|
typeof referenceBlock === "string" ? referenceBlock : referenceBlock.id;
|
|
29
|
+
const pmSchema = getPmSchema(tr);
|
|
30
|
+
const nodesToInsert = blocksToInsert.map((block) =>
|
|
31
|
+
blockToNode(block, pmSchema)
|
|
32
|
+
);
|
|
27
33
|
|
|
28
|
-
const
|
|
29
|
-
for (const blockSpec of blocksToInsert) {
|
|
30
|
-
nodesToInsert.push(
|
|
31
|
-
blockToNode(blockSpec, editor.pmSchema, editor.schema.styleSchema)
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const posInfo = getNodeById(id, editor._tiptapEditor.state.doc);
|
|
34
|
+
const posInfo = getNodeById(id, tr.doc);
|
|
36
35
|
if (!posInfo) {
|
|
37
36
|
throw new Error(`Block with ID ${id} not found`);
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
// because the fitting algorithm should not be necessary and might even cause unexpected behavior
|
|
42
|
-
if (placement === "before") {
|
|
43
|
-
editor.dispatch(
|
|
44
|
-
editor._tiptapEditor.state.tr.insert(posInfo.posBeforeNode, nodesToInsert)
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
39
|
+
let pos = posInfo.posBeforeNode;
|
|
48
40
|
if (placement === "after") {
|
|
49
|
-
|
|
50
|
-
editor._tiptapEditor.state.tr.insert(
|
|
51
|
-
posInfo.posBeforeNode + posInfo.node.nodeSize,
|
|
52
|
-
nodesToInsert
|
|
53
|
-
)
|
|
54
|
-
);
|
|
41
|
+
pos += posInfo.node.nodeSize;
|
|
55
42
|
}
|
|
56
43
|
|
|
44
|
+
tr.step(
|
|
45
|
+
new ReplaceStep(pos, pos, new Slice(Fragment.from(nodesToInsert), 0, 0))
|
|
46
|
+
);
|
|
47
|
+
|
|
57
48
|
// Now that the `PartialBlock`s have been converted to nodes, we can
|
|
58
49
|
// re-convert them into full `Block`s.
|
|
59
|
-
const insertedBlocks
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
nodeToBlock(
|
|
63
|
-
node,
|
|
64
|
-
editor.schema.blockSchema,
|
|
65
|
-
editor.schema.inlineContentSchema,
|
|
66
|
-
editor.schema.styleSchema,
|
|
67
|
-
editor.blockCache
|
|
68
|
-
)
|
|
69
|
-
);
|
|
70
|
-
}
|
|
50
|
+
const insertedBlocks = nodesToInsert.map((node) =>
|
|
51
|
+
nodeToBlock(node, pmSchema)
|
|
52
|
+
);
|
|
71
53
|
|
|
72
54
|
return insertedBlocks;
|
|
73
55
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getBlockInfoFromTransaction } from "../../../getBlockInfoFromPos.js";
|
|
4
4
|
import { setupTestEnv } from "../../setupTestEnv.js";
|
|
5
5
|
import { mergeBlocksCommand } from "./mergeBlocks.js";
|
|
6
6
|
|
|
@@ -13,8 +13,9 @@ function mergeBlocks(posBetweenBlocks: number) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function getPosBeforeSelectedBlock() {
|
|
16
|
-
return
|
|
17
|
-
.beforePos
|
|
16
|
+
return getEditor().transact(
|
|
17
|
+
(tr) => getBlockInfoFromTransaction(tr).bnBlock.beforePos
|
|
18
|
+
);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
describe("Test mergeBlocks", () => {
|
|
@@ -61,15 +62,16 @@ describe("Test mergeBlocks", () => {
|
|
|
61
62
|
it("Selection is updated", () => {
|
|
62
63
|
getEditor().setTextCursorPosition("paragraph-0", "end");
|
|
63
64
|
|
|
64
|
-
const firstBlockEndOffset =
|
|
65
|
-
|
|
65
|
+
const firstBlockEndOffset = getEditor().transact(
|
|
66
|
+
(tr) => tr.selection.$anchor.parentOffset
|
|
67
|
+
);
|
|
66
68
|
|
|
67
69
|
getEditor().setTextCursorPosition("paragraph-1");
|
|
68
70
|
|
|
69
71
|
mergeBlocks(getPosBeforeSelectedBlock());
|
|
70
72
|
|
|
71
73
|
const anchorIsAtOldFirstBlockEndPos =
|
|
72
|
-
getEditor().
|
|
74
|
+
getEditor().transact((tr) => tr.selection.$anchor.parentOffset) ===
|
|
73
75
|
firstBlockEndOffset;
|
|
74
76
|
|
|
75
77
|
expect(anchorIsAtOldFirstBlockEndPos).toBeTruthy();
|
|
@@ -2,7 +2,7 @@ import { NodeSelection, TextSelection } from "prosemirror-state";
|
|
|
2
2
|
import { CellSelection } from "prosemirror-tables";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { getBlockInfoFromTransaction } from "../../../getBlockInfoFromPos.js";
|
|
6
6
|
import { setupTestEnv } from "../../setupTestEnv.js";
|
|
7
7
|
import {
|
|
8
8
|
moveBlocksDown,
|
|
@@ -13,7 +13,9 @@ import {
|
|
|
13
13
|
const getEditor = setupTestEnv();
|
|
14
14
|
|
|
15
15
|
function makeSelectionSpanContent(selectionType: "text" | "node" | "cell") {
|
|
16
|
-
const blockInfo =
|
|
16
|
+
const blockInfo = getEditor().transact((tr) =>
|
|
17
|
+
getBlockInfoFromTransaction(tr)
|
|
18
|
+
);
|
|
17
19
|
if (!blockInfo.isBlockContainer) {
|
|
18
20
|
throw new Error(
|
|
19
21
|
`Selection points to a ${blockInfo.blockNoteType} node, not a blockContainer node`
|
|
@@ -21,34 +23,26 @@ function makeSelectionSpanContent(selectionType: "text" | "node" | "cell") {
|
|
|
21
23
|
}
|
|
22
24
|
const { blockContent } = blockInfo;
|
|
23
25
|
|
|
26
|
+
const editor = getEditor();
|
|
24
27
|
if (selectionType === "cell") {
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
editor.transact((tr) =>
|
|
29
|
+
tr.setSelection(
|
|
27
30
|
CellSelection.create(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.before(),
|
|
32
|
-
getEditor()
|
|
33
|
-
._tiptapEditor.state.doc.resolve(blockContent.afterPos - 3)
|
|
34
|
-
.before()
|
|
31
|
+
tr.doc,
|
|
32
|
+
tr.doc.resolve(blockContent.beforePos + 3).before(),
|
|
33
|
+
tr.doc.resolve(blockContent.afterPos - 3).before()
|
|
35
34
|
)
|
|
36
35
|
)
|
|
37
36
|
);
|
|
38
37
|
} else if (selectionType === "node") {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
NodeSelection.create(
|
|
42
|
-
getEditor()._tiptapEditor.state.doc,
|
|
43
|
-
blockContent.beforePos
|
|
44
|
-
)
|
|
45
|
-
)
|
|
38
|
+
editor.transact((tr) =>
|
|
39
|
+
tr.setSelection(NodeSelection.create(tr.doc, blockContent.beforePos))
|
|
46
40
|
);
|
|
47
41
|
} else {
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
editor.transact((tr) =>
|
|
43
|
+
tr.setSelection(
|
|
50
44
|
TextSelection.create(
|
|
51
|
-
|
|
45
|
+
tr.doc,
|
|
52
46
|
blockContent.beforePos + 1,
|
|
53
47
|
blockContent.afterPos - 1
|
|
54
48
|
)
|
|
@@ -64,12 +58,12 @@ describe("Test moveSelectedBlockAndSelection", () => {
|
|
|
64
58
|
|
|
65
59
|
moveSelectedBlocksAndSelection(getEditor(), "paragraph-0", "before");
|
|
66
60
|
|
|
67
|
-
const selection = getEditor().
|
|
61
|
+
const selection = getEditor().transact((tr) => tr.selection);
|
|
68
62
|
getEditor().setTextCursorPosition("paragraph-1");
|
|
69
63
|
makeSelectionSpanContent("text");
|
|
70
64
|
|
|
71
65
|
expect(
|
|
72
|
-
selection.eq(getEditor().
|
|
66
|
+
selection.eq(getEditor().transact((tr) => tr.selection))
|
|
73
67
|
).toBeTruthy();
|
|
74
68
|
});
|
|
75
69
|
|
|
@@ -79,12 +73,12 @@ describe("Test moveSelectedBlockAndSelection", () => {
|
|
|
79
73
|
|
|
80
74
|
moveSelectedBlocksAndSelection(getEditor(), "paragraph-0", "before");
|
|
81
75
|
|
|
82
|
-
const selection = getEditor().
|
|
76
|
+
const selection = getEditor().transact((tr) => tr.selection);
|
|
83
77
|
getEditor().setTextCursorPosition("image-0");
|
|
84
78
|
makeSelectionSpanContent("node");
|
|
85
79
|
|
|
86
80
|
expect(
|
|
87
|
-
selection.eq(getEditor().
|
|
81
|
+
selection.eq(getEditor().transact((tr) => tr.selection))
|
|
88
82
|
).toBeTruthy();
|
|
89
83
|
});
|
|
90
84
|
|
|
@@ -94,12 +88,12 @@ describe("Test moveSelectedBlockAndSelection", () => {
|
|
|
94
88
|
|
|
95
89
|
moveSelectedBlocksAndSelection(getEditor(), "paragraph-0", "before");
|
|
96
90
|
|
|
97
|
-
const selection = getEditor().
|
|
91
|
+
const selection = getEditor().transact((tr) => tr.selection);
|
|
98
92
|
getEditor().setTextCursorPosition("table-0");
|
|
99
93
|
makeSelectionSpanContent("cell");
|
|
100
94
|
|
|
101
95
|
expect(
|
|
102
|
-
selection.eq(getEditor().
|
|
96
|
+
selection.eq(getEditor().transact((tr) => tr.selection))
|
|
103
97
|
).toBeTruthy();
|
|
104
98
|
});
|
|
105
99
|
|
|
@@ -108,11 +102,11 @@ describe("Test moveSelectedBlockAndSelection", () => {
|
|
|
108
102
|
|
|
109
103
|
moveSelectedBlocksAndSelection(getEditor(), "paragraph-0", "before");
|
|
110
104
|
|
|
111
|
-
const selection = getEditor().
|
|
105
|
+
const selection = getEditor().transact((tr) => tr.selection);
|
|
112
106
|
getEditor().setSelection("paragraph-1", "paragraph-2");
|
|
113
107
|
|
|
114
108
|
expect(
|
|
115
|
-
selection.eq(getEditor().
|
|
109
|
+
selection.eq(getEditor().transact((tr) => tr.selection))
|
|
116
110
|
).toBeTruthy();
|
|
117
111
|
});
|
|
118
112
|
|
|
@@ -121,11 +115,11 @@ describe("Test moveSelectedBlockAndSelection", () => {
|
|
|
121
115
|
|
|
122
116
|
moveSelectedBlocksAndSelection(getEditor(), "paragraph-0", "before");
|
|
123
117
|
|
|
124
|
-
const selection = getEditor().
|
|
118
|
+
const selection = getEditor().transact((tr) => tr.selection);
|
|
125
119
|
getEditor().setSelection("paragraph-6", "table-0");
|
|
126
120
|
|
|
127
121
|
expect(
|
|
128
|
-
selection.eq(getEditor().
|
|
122
|
+
selection.eq(getEditor().transact((tr) => tr.selection))
|
|
129
123
|
).toBeTruthy();
|
|
130
124
|
});
|
|
131
125
|
});
|