@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,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NodeSelection,
|
|
3
|
+
Selection,
|
|
4
|
+
TextSelection,
|
|
5
|
+
Transaction,
|
|
6
|
+
} from "prosemirror-state";
|
|
2
7
|
import { CellSelection } from "prosemirror-tables";
|
|
3
8
|
|
|
4
9
|
import { Block } from "../../../../blocks/defaultBlocks.js";
|
|
@@ -38,36 +43,35 @@ type BlockSelectionData = (
|
|
|
38
43
|
function getBlockSelectionData(
|
|
39
44
|
editor: BlockNoteEditor<any, any, any>
|
|
40
45
|
): BlockSelectionData {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
46
|
+
return editor.transact((tr) => {
|
|
47
|
+
const anchorBlockPosInfo = getNearestBlockPos(tr.doc, tr.selection.anchor);
|
|
48
|
+
|
|
49
|
+
if (tr.selection instanceof CellSelection) {
|
|
50
|
+
return {
|
|
51
|
+
type: "cell" as const,
|
|
52
|
+
anchorBlockId: anchorBlockPosInfo.node.attrs.id,
|
|
53
|
+
anchorCellOffset:
|
|
54
|
+
tr.selection.$anchorCell.pos - anchorBlockPosInfo.posBeforeNode,
|
|
55
|
+
headCellOffset:
|
|
56
|
+
tr.selection.$headCell.pos - anchorBlockPosInfo.posBeforeNode,
|
|
57
|
+
};
|
|
58
|
+
} else if (tr.selection instanceof NodeSelection) {
|
|
59
|
+
return {
|
|
60
|
+
type: "node" as const,
|
|
61
|
+
anchorBlockId: anchorBlockPosInfo.node.attrs.id,
|
|
62
|
+
};
|
|
63
|
+
} else {
|
|
64
|
+
const headBlockPosInfo = getNearestBlockPos(tr.doc, tr.selection.head);
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
type: "text" as const,
|
|
68
|
+
anchorBlockId: anchorBlockPosInfo.node.attrs.id,
|
|
69
|
+
headBlockId: headBlockPosInfo.node.attrs.id,
|
|
70
|
+
anchorOffset: tr.selection.anchor - anchorBlockPosInfo.posBeforeNode,
|
|
71
|
+
headOffset: tr.selection.head - headBlockPosInfo.posBeforeNode,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
});
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
/**
|
|
@@ -77,18 +81,15 @@ function getBlockSelectionData(
|
|
|
77
81
|
* positions of their surrounding blocks, as well as the IDs of those blocks. We
|
|
78
82
|
* can then recreate the selection by finding the blocks with those IDs, getting
|
|
79
83
|
* their before positions, and adding the offsets to those positions.
|
|
80
|
-
* @param
|
|
84
|
+
* @param tr The transaction to update the selection in.
|
|
81
85
|
* @param data The selection data to update the selection with (generated by
|
|
82
86
|
* `getBlockSelectionData`).
|
|
83
87
|
*/
|
|
84
88
|
function updateBlockSelectionFromData(
|
|
85
|
-
|
|
89
|
+
tr: Transaction,
|
|
86
90
|
data: BlockSelectionData
|
|
87
91
|
) {
|
|
88
|
-
const anchorBlockPos = getNodeById(
|
|
89
|
-
data.anchorBlockId,
|
|
90
|
-
editor._tiptapEditor.state.doc
|
|
91
|
-
)?.posBeforeNode;
|
|
92
|
+
const anchorBlockPos = getNodeById(data.anchorBlockId, tr.doc)?.posBeforeNode;
|
|
92
93
|
if (anchorBlockPos === undefined) {
|
|
93
94
|
throw new Error(
|
|
94
95
|
`Could not find block with ID ${data.anchorBlockId} to update selection`
|
|
@@ -98,20 +99,14 @@ function updateBlockSelectionFromData(
|
|
|
98
99
|
let selection: Selection;
|
|
99
100
|
if (data.type === "cell") {
|
|
100
101
|
selection = CellSelection.create(
|
|
101
|
-
|
|
102
|
+
tr.doc,
|
|
102
103
|
anchorBlockPos + data.anchorCellOffset,
|
|
103
104
|
anchorBlockPos + data.headCellOffset
|
|
104
105
|
);
|
|
105
106
|
} else if (data.type === "node") {
|
|
106
|
-
selection = NodeSelection.create(
|
|
107
|
-
editor._tiptapEditor.state.doc,
|
|
108
|
-
anchorBlockPos + 1
|
|
109
|
-
);
|
|
107
|
+
selection = NodeSelection.create(tr.doc, anchorBlockPos + 1);
|
|
110
108
|
} else {
|
|
111
|
-
const headBlockPos = getNodeById(
|
|
112
|
-
data.headBlockId,
|
|
113
|
-
editor._tiptapEditor.state.doc
|
|
114
|
-
)?.posBeforeNode;
|
|
109
|
+
const headBlockPos = getNodeById(data.headBlockId, tr.doc)?.posBeforeNode;
|
|
115
110
|
if (headBlockPos === undefined) {
|
|
116
111
|
throw new Error(
|
|
117
112
|
`Could not find block with ID ${data.headBlockId} to update selection`
|
|
@@ -119,13 +114,13 @@ function updateBlockSelectionFromData(
|
|
|
119
114
|
}
|
|
120
115
|
|
|
121
116
|
selection = TextSelection.create(
|
|
122
|
-
|
|
117
|
+
tr.doc,
|
|
123
118
|
anchorBlockPos + data.anchorOffset,
|
|
124
119
|
headBlockPos + data.headOffset
|
|
125
120
|
);
|
|
126
121
|
}
|
|
127
122
|
|
|
128
|
-
|
|
123
|
+
tr.setSelection(selection);
|
|
129
124
|
}
|
|
130
125
|
|
|
131
126
|
/**
|
|
@@ -168,15 +163,18 @@ export function moveSelectedBlocksAndSelection(
|
|
|
168
163
|
referenceBlock: BlockIdentifier,
|
|
169
164
|
placement: "before" | "after"
|
|
170
165
|
) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
166
|
+
// We want this to be a single step in the undo history
|
|
167
|
+
editor.transact((tr) => {
|
|
168
|
+
const blocks = editor.getSelection()?.blocks || [
|
|
169
|
+
editor.getTextCursorPosition().block,
|
|
170
|
+
];
|
|
171
|
+
const selectionData = getBlockSelectionData(editor);
|
|
172
|
+
|
|
173
|
+
editor.removeBlocks(blocks);
|
|
174
|
+
editor.insertBlocks(flattenColumns(blocks), referenceBlock, placement);
|
|
175
|
+
|
|
176
|
+
updateBlockSelectionFromData(tr, selectionData);
|
|
177
|
+
});
|
|
180
178
|
}
|
|
181
179
|
|
|
182
180
|
// Checks if a block is in a valid place after being moved. This check is
|
|
@@ -292,45 +290,49 @@ function getMoveDownPlacement(
|
|
|
292
290
|
}
|
|
293
291
|
|
|
294
292
|
export function moveBlocksUp(editor: BlockNoteEditor<any, any, any>) {
|
|
295
|
-
|
|
296
|
-
|
|
293
|
+
editor.transact(() => {
|
|
294
|
+
const selection = editor.getSelection();
|
|
295
|
+
const block = selection?.blocks[0] || editor.getTextCursorPosition().block;
|
|
297
296
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
297
|
+
const moveUpPlacement = getMoveUpPlacement(
|
|
298
|
+
editor,
|
|
299
|
+
editor.getPrevBlock(block),
|
|
300
|
+
editor.getParentBlock(block)
|
|
301
|
+
);
|
|
303
302
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
303
|
+
if (!moveUpPlacement) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
307
306
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
307
|
+
moveSelectedBlocksAndSelection(
|
|
308
|
+
editor,
|
|
309
|
+
moveUpPlacement.referenceBlock,
|
|
310
|
+
moveUpPlacement.placement
|
|
311
|
+
);
|
|
312
|
+
});
|
|
313
313
|
}
|
|
314
314
|
|
|
315
315
|
export function moveBlocksDown(editor: BlockNoteEditor<any, any, any>) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const moveDownPlacement = getMoveDownPlacement(
|
|
322
|
-
editor,
|
|
323
|
-
editor.getNextBlock(block),
|
|
324
|
-
editor.getParentBlock(block)
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
if (!moveDownPlacement) {
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
316
|
+
editor.transact(() => {
|
|
317
|
+
const selection = editor.getSelection();
|
|
318
|
+
const block =
|
|
319
|
+
selection?.blocks[selection?.blocks.length - 1] ||
|
|
320
|
+
editor.getTextCursorPosition().block;
|
|
330
321
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
322
|
+
const moveDownPlacement = getMoveDownPlacement(
|
|
323
|
+
editor,
|
|
324
|
+
editor.getNextBlock(block),
|
|
325
|
+
editor.getParentBlock(block)
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
if (!moveDownPlacement) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
moveSelectedBlocksAndSelection(
|
|
333
|
+
editor,
|
|
334
|
+
moveDownPlacement.referenceBlock,
|
|
335
|
+
moveDownPlacement.placement
|
|
336
|
+
);
|
|
337
|
+
});
|
|
336
338
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Fragment, NodeType, Slice } from "prosemirror-model";
|
|
2
|
-
import { EditorState } from "prosemirror-state";
|
|
2
|
+
import { EditorState, Transaction } from "prosemirror-state";
|
|
3
3
|
import { ReplaceAroundStep } from "prosemirror-transform";
|
|
4
4
|
|
|
5
5
|
import { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
|
|
6
|
-
import {
|
|
6
|
+
import { getBlockInfoFromTransaction } from "../../../getBlockInfoFromPos.js";
|
|
7
7
|
|
|
8
8
|
// TODO: Unit tests
|
|
9
9
|
/**
|
|
@@ -12,7 +12,7 @@ import { getBlockInfoFromSelection } from "../../../getBlockInfoFromPos.js";
|
|
|
12
12
|
* The original function derives too many information from the parentnode and itemtype
|
|
13
13
|
*/
|
|
14
14
|
function sinkListItem(itemType: NodeType, groupType: NodeType) {
|
|
15
|
-
return function (
|
|
15
|
+
return function (state: EditorState, dispatch?: (tr: Transaction) => void) {
|
|
16
16
|
const { $from, $to } = state.selection;
|
|
17
17
|
const range = $from.blockRange(
|
|
18
18
|
$to,
|
|
@@ -67,11 +67,11 @@ function sinkListItem(itemType: NodeType, groupType: NodeType) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export function nestBlock(editor: BlockNoteEditor<any, any, any>) {
|
|
70
|
-
return editor.
|
|
70
|
+
return editor.exec((state, dispatch) =>
|
|
71
71
|
sinkListItem(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
)
|
|
72
|
+
state.schema.nodes["blockContainer"],
|
|
73
|
+
state.schema.nodes["blockGroup"]
|
|
74
|
+
)(state, dispatch)
|
|
75
75
|
);
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -80,21 +80,17 @@ export function unnestBlock(editor: BlockNoteEditor<any, any, any>) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
export function canNestBlock(editor: BlockNoteEditor<any, any, any>) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
83
|
+
return editor.transact((tr) => {
|
|
84
|
+
const { bnBlock: blockContainer } = getBlockInfoFromTransaction(tr);
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
.nodeBefore !== null
|
|
90
|
-
);
|
|
86
|
+
return tr.doc.resolve(blockContainer.beforePos).nodeBefore !== null;
|
|
87
|
+
});
|
|
91
88
|
}
|
|
89
|
+
|
|
92
90
|
export function canUnnestBlock(editor: BlockNoteEditor<any, any, any>) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
);
|
|
91
|
+
return editor.transact((tr) => {
|
|
92
|
+
const { bnBlock: blockContainer } = getBlockInfoFromTransaction(tr);
|
|
96
93
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
);
|
|
94
|
+
return tr.doc.resolve(blockContainer.beforePos).depth > 1;
|
|
95
|
+
});
|
|
100
96
|
}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
|
|
3
3
|
import { setupTestEnv } from "../../setupTestEnv.js";
|
|
4
|
-
import {
|
|
4
|
+
import { removeAndInsertBlocks } from "./replaceBlocks.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 replaceBlocks(
|
|
12
|
+
editor: BlockNoteEditor,
|
|
13
|
+
blocksToRemove: BlockIdentifier[],
|
|
14
|
+
blocksToInsert: PartialBlock<any, any, any>[]
|
|
15
|
+
) {
|
|
16
|
+
return editor.transact((tr) =>
|
|
17
|
+
removeAndInsertBlocks(tr, blocksToRemove, blocksToInsert)
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
8
21
|
describe("Test replaceBlocks", () => {
|
|
9
22
|
it("Remove single block", () => {
|
|
10
23
|
replaceBlocks(getEditor(), ["paragraph-0"], []);
|
|
@@ -1,38 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
1
|
+
import type { Node } from "prosemirror-model";
|
|
2
|
+
import type { Transaction } from "prosemirror-state";
|
|
3
|
+
import type { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js";
|
|
4
|
+
import type {
|
|
4
5
|
BlockIdentifier,
|
|
5
6
|
BlockSchema,
|
|
6
7
|
InlineContentSchema,
|
|
7
8
|
StyleSchema,
|
|
8
9
|
} from "../../../../schema/index.js";
|
|
9
|
-
import { Node } from "prosemirror-model";
|
|
10
10
|
import { blockToNode } from "../../../nodeConversions/blockToNode.js";
|
|
11
11
|
import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js";
|
|
12
|
+
import { getPmSchema } from "../../../pmUtil.js";
|
|
12
13
|
|
|
13
14
|
export function removeAndInsertBlocks<
|
|
14
15
|
BSchema extends BlockSchema,
|
|
15
16
|
I extends InlineContentSchema,
|
|
16
17
|
S extends StyleSchema
|
|
17
18
|
>(
|
|
18
|
-
|
|
19
|
+
tr: Transaction,
|
|
19
20
|
blocksToRemove: BlockIdentifier[],
|
|
20
21
|
blocksToInsert: PartialBlock<BSchema, I, S>[]
|
|
21
22
|
): {
|
|
22
23
|
insertedBlocks: Block<BSchema, I, S>[];
|
|
23
24
|
removedBlocks: Block<BSchema, I, S>[];
|
|
24
25
|
} {
|
|
25
|
-
const
|
|
26
|
-
let tr = ttEditor.state.tr;
|
|
27
|
-
|
|
26
|
+
const pmSchema = getPmSchema(tr);
|
|
28
27
|
// Converts the `PartialBlock`s to ProseMirror nodes to insert them into the
|
|
29
28
|
// document.
|
|
30
|
-
const nodesToInsert: Node[] =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
blockToNode(block, editor.pmSchema, editor.schema.styleSchema)
|
|
34
|
-
);
|
|
35
|
-
}
|
|
29
|
+
const nodesToInsert: Node[] = blocksToInsert.map((block) =>
|
|
30
|
+
blockToNode(block, pmSchema)
|
|
31
|
+
);
|
|
36
32
|
|
|
37
33
|
const idsOfBlocksToRemove = new Set<string>(
|
|
38
34
|
blocksToRemove.map((block) =>
|
|
@@ -47,7 +43,7 @@ export function removeAndInsertBlocks<
|
|
|
47
43
|
: blocksToRemove[0].id;
|
|
48
44
|
let removedSize = 0;
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
tr.doc.descendants((node, pos) => {
|
|
51
47
|
// Skips traversing nodes after all target blocks have been removed.
|
|
52
48
|
if (idsOfBlocksToRemove.size === 0) {
|
|
53
49
|
return false;
|
|
@@ -62,20 +58,12 @@ export function removeAndInsertBlocks<
|
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
// Saves the block that is being deleted.
|
|
65
|
-
removedBlocks.push(
|
|
66
|
-
nodeToBlock(
|
|
67
|
-
node,
|
|
68
|
-
editor.schema.blockSchema,
|
|
69
|
-
editor.schema.inlineContentSchema,
|
|
70
|
-
editor.schema.styleSchema,
|
|
71
|
-
editor.blockCache
|
|
72
|
-
)
|
|
73
|
-
);
|
|
61
|
+
removedBlocks.push(nodeToBlock(node, pmSchema));
|
|
74
62
|
idsOfBlocksToRemove.delete(node.attrs.id);
|
|
75
63
|
|
|
76
64
|
if (blocksToInsert.length > 0 && node.attrs.id === idOfFirstBlock) {
|
|
77
65
|
const oldDocSize = tr.doc.nodeSize;
|
|
78
|
-
tr
|
|
66
|
+
tr.insert(pos, nodesToInsert);
|
|
79
67
|
const newDocSize = tr.doc.nodeSize;
|
|
80
68
|
|
|
81
69
|
removedSize += oldDocSize - newDocSize;
|
|
@@ -91,9 +79,9 @@ export function removeAndInsertBlocks<
|
|
|
91
79
|
$pos.node($pos.depth - 1).type.name !== "doc" &&
|
|
92
80
|
$pos.node().childCount === 1
|
|
93
81
|
) {
|
|
94
|
-
tr
|
|
82
|
+
tr.delete($pos.before(), $pos.after());
|
|
95
83
|
} else {
|
|
96
|
-
tr
|
|
84
|
+
tr.delete(pos - removedSize, pos - removedSize + node.nodeSize);
|
|
97
85
|
}
|
|
98
86
|
const newDocSize = tr.doc.nodeSize;
|
|
99
87
|
removedSize += oldDocSize - newDocSize;
|
|
@@ -111,36 +99,10 @@ export function removeAndInsertBlocks<
|
|
|
111
99
|
);
|
|
112
100
|
}
|
|
113
101
|
|
|
114
|
-
editor.dispatch(tr);
|
|
115
|
-
|
|
116
102
|
// Converts the nodes created from `blocksToInsert` into full `Block`s.
|
|
117
|
-
const insertedBlocks
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
nodeToBlock(
|
|
121
|
-
node,
|
|
122
|
-
editor.schema.blockSchema,
|
|
123
|
-
editor.schema.inlineContentSchema,
|
|
124
|
-
editor.schema.styleSchema,
|
|
125
|
-
editor.blockCache
|
|
126
|
-
)
|
|
127
|
-
);
|
|
128
|
-
}
|
|
103
|
+
const insertedBlocks = nodesToInsert.map((node) =>
|
|
104
|
+
nodeToBlock(node, pmSchema)
|
|
105
|
+
);
|
|
129
106
|
|
|
130
107
|
return { insertedBlocks, removedBlocks };
|
|
131
108
|
}
|
|
132
|
-
|
|
133
|
-
export function replaceBlocks<
|
|
134
|
-
BSchema extends BlockSchema,
|
|
135
|
-
I extends InlineContentSchema,
|
|
136
|
-
S extends StyleSchema
|
|
137
|
-
>(
|
|
138
|
-
editor: BlockNoteEditor<BSchema, I, S>,
|
|
139
|
-
blocksToRemove: BlockIdentifier[],
|
|
140
|
-
blocksToInsert: PartialBlock<BSchema, I, S>[]
|
|
141
|
-
): {
|
|
142
|
-
insertedBlocks: Block<BSchema, I, S>[];
|
|
143
|
-
removedBlocks: Block<BSchema, I, S>[];
|
|
144
|
-
} {
|
|
145
|
-
return removeAndInsertBlocks(editor, blocksToRemove, blocksToInsert);
|
|
146
|
-
}
|
|
@@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest";
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
getBlockInfo,
|
|
7
|
-
|
|
7
|
+
getBlockInfoFromTransaction,
|
|
8
8
|
} from "../../../getBlockInfoFromPos.js";
|
|
9
9
|
import { getNodeById } from "../../../nodeUtil.js";
|
|
10
10
|
import { setupTestEnv } from "../../setupTestEnv.js";
|
|
@@ -38,8 +38,8 @@ function setSelectionWithOffset(
|
|
|
38
38
|
throw new Error("Target block is not a block container");
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
getEditor().
|
|
42
|
-
|
|
41
|
+
getEditor().transact((tr) =>
|
|
42
|
+
tr.setSelection(
|
|
43
43
|
TextSelection.create(doc, info.blockContent.beforePos + offset + 1)
|
|
44
44
|
)
|
|
45
45
|
);
|
|
@@ -47,97 +47,103 @@ function setSelectionWithOffset(
|
|
|
47
47
|
|
|
48
48
|
describe("Test splitBlocks", () => {
|
|
49
49
|
it("Basic", () => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
4
|
|
54
|
-
);
|
|
50
|
+
getEditor().transact((tr) => {
|
|
51
|
+
setSelectionWithOffset(tr.doc, "paragraph-0", 4);
|
|
52
|
+
});
|
|
55
53
|
|
|
56
|
-
splitBlock(getEditor().
|
|
54
|
+
splitBlock(getEditor().transact((tr) => tr.selection.anchor));
|
|
57
55
|
|
|
58
56
|
expect(getEditor().document).toMatchSnapshot();
|
|
59
57
|
});
|
|
60
58
|
|
|
61
59
|
it("End of content", () => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
11
|
|
66
|
-
);
|
|
60
|
+
getEditor().transact((tr) => {
|
|
61
|
+
setSelectionWithOffset(tr.doc, "paragraph-0", 11);
|
|
62
|
+
});
|
|
67
63
|
|
|
68
|
-
splitBlock(getEditor().
|
|
64
|
+
splitBlock(getEditor().transact((tr) => tr.selection.anchor));
|
|
69
65
|
|
|
70
66
|
expect(getEditor().document).toMatchSnapshot();
|
|
71
67
|
});
|
|
72
68
|
|
|
73
69
|
it("Block has children", () => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
4
|
|
78
|
-
);
|
|
70
|
+
getEditor().transact((tr) => {
|
|
71
|
+
setSelectionWithOffset(tr.doc, "paragraph-with-children", 4);
|
|
72
|
+
});
|
|
79
73
|
|
|
80
|
-
splitBlock(getEditor().
|
|
74
|
+
splitBlock(getEditor().transact((tr) => tr.selection.anchor));
|
|
81
75
|
|
|
82
76
|
expect(getEditor().document).toMatchSnapshot();
|
|
83
77
|
});
|
|
84
78
|
|
|
85
79
|
it("Keep type", () => {
|
|
86
|
-
|
|
80
|
+
getEditor().transact((tr) => {
|
|
81
|
+
setSelectionWithOffset(tr.doc, "heading-0", 4);
|
|
82
|
+
});
|
|
87
83
|
|
|
88
|
-
splitBlock(
|
|
84
|
+
splitBlock(
|
|
85
|
+
getEditor().transact((tr) => tr.selection.anchor),
|
|
86
|
+
true
|
|
87
|
+
);
|
|
89
88
|
|
|
90
89
|
expect(getEditor().document).toMatchSnapshot();
|
|
91
90
|
});
|
|
92
91
|
|
|
93
92
|
it("Don't keep type", () => {
|
|
94
|
-
|
|
93
|
+
getEditor().transact((tr) => {
|
|
94
|
+
setSelectionWithOffset(tr.doc, "heading-0", 4);
|
|
95
|
+
});
|
|
95
96
|
|
|
96
|
-
splitBlock(
|
|
97
|
+
splitBlock(
|
|
98
|
+
getEditor().transact((tr) => tr.selection.anchor),
|
|
99
|
+
false
|
|
100
|
+
);
|
|
97
101
|
|
|
98
102
|
expect(getEditor().document).toMatchSnapshot();
|
|
99
103
|
});
|
|
100
104
|
|
|
101
105
|
it.skip("Keep props", () => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
getEditor().transact((tr) => {
|
|
107
|
+
setSelectionWithOffset(tr.doc, "paragraph-with-props", 4);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
splitBlock(
|
|
111
|
+
getEditor().transact((tr) => tr.selection.anchor),
|
|
112
|
+
false,
|
|
113
|
+
true
|
|
106
114
|
);
|
|
107
115
|
|
|
108
|
-
splitBlock(getEditor()._tiptapEditor.state.selection.anchor, false, true);
|
|
109
|
-
|
|
110
116
|
expect(getEditor().document).toMatchSnapshot();
|
|
111
117
|
});
|
|
112
118
|
|
|
113
119
|
it("Don't keep props", () => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
getEditor().transact((tr) => {
|
|
121
|
+
setSelectionWithOffset(tr.doc, "paragraph-with-props", 4);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
splitBlock(
|
|
125
|
+
getEditor().transact((tr) => tr.selection.anchor),
|
|
126
|
+
false,
|
|
127
|
+
false
|
|
118
128
|
);
|
|
119
129
|
|
|
120
|
-
splitBlock(getEditor()._tiptapEditor.state.selection.anchor, false, false);
|
|
121
|
-
|
|
122
130
|
expect(getEditor().document).toMatchSnapshot();
|
|
123
131
|
});
|
|
124
132
|
|
|
125
133
|
it("Selection is set", () => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
4
|
|
130
|
-
);
|
|
134
|
+
getEditor().transact((tr) => {
|
|
135
|
+
setSelectionWithOffset(tr.doc, "paragraph-0", 4);
|
|
136
|
+
});
|
|
131
137
|
|
|
132
|
-
splitBlock(getEditor().
|
|
138
|
+
splitBlock(getEditor().transact((tr) => tr.selection.anchor));
|
|
133
139
|
|
|
134
|
-
const
|
|
135
|
-
|
|
140
|
+
const bnBlock = getEditor().transact(
|
|
141
|
+
(tr) => getBlockInfoFromTransaction(tr).bnBlock
|
|
136
142
|
);
|
|
137
143
|
|
|
138
144
|
const anchorIsAtStartOfNewBlock =
|
|
139
145
|
bnBlock.node.attrs.id === "0" &&
|
|
140
|
-
getEditor().
|
|
146
|
+
getEditor().transact((tr) => tr.selection.$anchor.parentOffset) === 0;
|
|
141
147
|
|
|
142
148
|
expect(anchorIsAtStartOfNewBlock).toBeTruthy();
|
|
143
149
|
});
|