@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,18 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Fragment,
|
|
3
|
+
type NodeType,
|
|
4
|
+
type Node as PMNode,
|
|
5
|
+
Slice,
|
|
6
|
+
} from "prosemirror-model";
|
|
7
|
+
import type { Transaction } from "prosemirror-state";
|
|
3
8
|
|
|
4
9
|
import { ReplaceStep } from "prosemirror-transform";
|
|
5
|
-
import { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
10
|
+
import type { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js";
|
|
11
|
+
import type {
|
|
8
12
|
BlockIdentifier,
|
|
9
13
|
BlockSchema,
|
|
10
14
|
} from "../../../../schema/blocks/types.js";
|
|
11
|
-
import { InlineContentSchema } from "../../../../schema/inlineContent/types.js";
|
|
12
|
-
import { StyleSchema } from "../../../../schema/styles/types.js";
|
|
15
|
+
import type { InlineContentSchema } from "../../../../schema/inlineContent/types.js";
|
|
16
|
+
import type { StyleSchema } from "../../../../schema/styles/types.js";
|
|
13
17
|
import { UnreachableCaseError } from "../../../../util/typescript.js";
|
|
14
18
|
import {
|
|
15
|
-
BlockInfo,
|
|
19
|
+
type BlockInfo,
|
|
16
20
|
getBlockInfoFromResolvedPos,
|
|
17
21
|
} from "../../../getBlockInfoFromPos.js";
|
|
18
22
|
import {
|
|
@@ -22,98 +26,90 @@ import {
|
|
|
22
26
|
} from "../../../nodeConversions/blockToNode.js";
|
|
23
27
|
import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js";
|
|
24
28
|
import { getNodeById } from "../../../nodeUtil.js";
|
|
29
|
+
import { getPmSchema } from "../../../pmUtil.js";
|
|
25
30
|
|
|
26
|
-
export const updateBlockCommand =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
({
|
|
37
|
-
state,
|
|
31
|
+
export const updateBlockCommand = <
|
|
32
|
+
BSchema extends BlockSchema,
|
|
33
|
+
I extends InlineContentSchema,
|
|
34
|
+
S extends StyleSchema
|
|
35
|
+
>(
|
|
36
|
+
posBeforeBlock: number,
|
|
37
|
+
block: PartialBlock<BSchema, I, S>
|
|
38
|
+
) => {
|
|
39
|
+
return ({
|
|
40
|
+
tr,
|
|
38
41
|
dispatch,
|
|
39
42
|
}: {
|
|
40
|
-
|
|
41
|
-
dispatch
|
|
42
|
-
}) => {
|
|
43
|
-
const blockInfo = getBlockInfoFromResolvedPos(
|
|
44
|
-
state.doc.resolve(posBeforeBlock)
|
|
45
|
-
);
|
|
46
|
-
|
|
43
|
+
tr: Transaction;
|
|
44
|
+
dispatch?: () => void;
|
|
45
|
+
}): boolean => {
|
|
47
46
|
if (dispatch) {
|
|
48
|
-
|
|
47
|
+
updateBlockTr(tr, posBeforeBlock, block);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const updateBlockTr = <
|
|
54
|
+
BSchema extends BlockSchema,
|
|
55
|
+
I extends InlineContentSchema,
|
|
56
|
+
S extends StyleSchema
|
|
57
|
+
>(
|
|
58
|
+
tr: Transaction,
|
|
59
|
+
posBeforeBlock: number,
|
|
60
|
+
block: PartialBlock<BSchema, I, S>
|
|
61
|
+
) => {
|
|
62
|
+
const blockInfo = getBlockInfoFromResolvedPos(tr.doc.resolve(posBeforeBlock));
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// The code below determines the new content of the block.
|
|
60
|
-
// or "keep" to keep as-is
|
|
61
|
-
updateBlockContentNode(
|
|
62
|
-
block,
|
|
63
|
-
state,
|
|
64
|
-
editor,
|
|
65
|
-
oldNodeType,
|
|
66
|
-
newNodeType,
|
|
67
|
-
blockInfo
|
|
68
|
-
);
|
|
69
|
-
} else if (
|
|
70
|
-
!blockInfo.isBlockContainer &&
|
|
71
|
-
newNodeType.isInGroup("bnBlock")
|
|
72
|
-
) {
|
|
73
|
-
updateChildren(block, state, editor, blockInfo);
|
|
74
|
-
// old node was a bnBlock type (like column or columnList) and new block as well
|
|
75
|
-
// No op, we just update the bnBlock below (at end of function) and have already updated the children
|
|
76
|
-
} else {
|
|
77
|
-
// switching from blockContainer to non-blockContainer or v.v.
|
|
78
|
-
// currently breaking for column slash menu items converting empty block
|
|
79
|
-
// to column.
|
|
64
|
+
const pmSchema = getPmSchema(tr);
|
|
65
|
+
// Adds blockGroup node with child blocks if necessary.
|
|
80
66
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
editor.schema.blockSchema,
|
|
87
|
-
editor.schema.inlineContentSchema,
|
|
88
|
-
editor.schema.styleSchema,
|
|
89
|
-
editor.blockCache
|
|
90
|
-
);
|
|
91
|
-
state.tr.replaceWith(
|
|
92
|
-
blockInfo.bnBlock.beforePos,
|
|
93
|
-
blockInfo.bnBlock.afterPos,
|
|
94
|
-
blockToNode(
|
|
95
|
-
{
|
|
96
|
-
children: existingBlock.children, // if no children are passed in, use existing children
|
|
97
|
-
...block,
|
|
98
|
-
},
|
|
99
|
-
state.schema,
|
|
100
|
-
editor.schema.styleSchema
|
|
101
|
-
)
|
|
102
|
-
);
|
|
67
|
+
const oldNodeType = pmSchema.nodes[blockInfo.blockNoteType];
|
|
68
|
+
const newNodeType = pmSchema.nodes[block.type || blockInfo.blockNoteType];
|
|
69
|
+
const newBnBlockNodeType = newNodeType.isInGroup("bnBlock")
|
|
70
|
+
? newNodeType
|
|
71
|
+
: pmSchema.nodes["blockContainer"];
|
|
103
72
|
|
|
104
|
-
|
|
105
|
-
|
|
73
|
+
if (blockInfo.isBlockContainer && newNodeType.isInGroup("blockContent")) {
|
|
74
|
+
updateChildren(block, tr, blockInfo);
|
|
75
|
+
// The code below determines the new content of the block.
|
|
76
|
+
// or "keep" to keep as-is
|
|
77
|
+
updateBlockContentNode(block, tr, oldNodeType, newNodeType, blockInfo);
|
|
78
|
+
} else if (!blockInfo.isBlockContainer && newNodeType.isInGroup("bnBlock")) {
|
|
79
|
+
updateChildren(block, tr, blockInfo);
|
|
80
|
+
// old node was a bnBlock type (like column or columnList) and new block as well
|
|
81
|
+
// No op, we just update the bnBlock below (at end of function) and have already updated the children
|
|
82
|
+
} else {
|
|
83
|
+
// switching from blockContainer to non-blockContainer or v.v.
|
|
84
|
+
// currently breaking for column slash menu items converting empty block
|
|
85
|
+
// to column.
|
|
106
86
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
87
|
+
// currently, we calculate the new node and replace the entire node with the desired new node.
|
|
88
|
+
// for this, we do a nodeToBlock on the existing block to get the children.
|
|
89
|
+
// it would be cleaner to use a ReplaceAroundStep, but this is a bit simpler and it's quite an edge case
|
|
90
|
+
const existingBlock = nodeToBlock(blockInfo.bnBlock.node, pmSchema);
|
|
91
|
+
tr.replaceWith(
|
|
92
|
+
blockInfo.bnBlock.beforePos,
|
|
93
|
+
blockInfo.bnBlock.afterPos,
|
|
94
|
+
blockToNode(
|
|
95
|
+
{
|
|
96
|
+
children: existingBlock.children, // if no children are passed in, use existing children
|
|
97
|
+
...block,
|
|
98
|
+
},
|
|
99
|
+
pmSchema
|
|
100
|
+
)
|
|
101
|
+
);
|
|
114
102
|
|
|
115
|
-
return
|
|
116
|
-
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Adds all provided props as attributes to the parent blockContainer node too, and also preserves existing
|
|
107
|
+
// attributes.
|
|
108
|
+
tr.setNodeMarkup(blockInfo.bnBlock.beforePos, newBnBlockNodeType, {
|
|
109
|
+
...blockInfo.bnBlock.node.attrs,
|
|
110
|
+
...block.props,
|
|
111
|
+
});
|
|
112
|
+
};
|
|
117
113
|
|
|
118
114
|
function updateBlockContentNode<
|
|
119
115
|
BSchema extends BlockSchema,
|
|
@@ -121,8 +117,7 @@ function updateBlockContentNode<
|
|
|
121
117
|
S extends StyleSchema
|
|
122
118
|
>(
|
|
123
119
|
block: PartialBlock<BSchema, I, S>,
|
|
124
|
-
|
|
125
|
-
editor: BlockNoteEditor<BSchema, I, S>,
|
|
120
|
+
tr: Transaction,
|
|
126
121
|
oldNodeType: NodeType,
|
|
127
122
|
newNodeType: NodeType,
|
|
128
123
|
blockInfo: {
|
|
@@ -132,6 +127,7 @@ function updateBlockContentNode<
|
|
|
132
127
|
blockContent: { node: PMNode; beforePos: number; afterPos: number };
|
|
133
128
|
}
|
|
134
129
|
) {
|
|
130
|
+
const pmSchema = getPmSchema(tr);
|
|
135
131
|
let content: PMNode[] | "keep" = "keep";
|
|
136
132
|
|
|
137
133
|
// Has there been any custom content provided?
|
|
@@ -140,25 +136,15 @@ function updateBlockContentNode<
|
|
|
140
136
|
// Adds a single text node with no marks to the content.
|
|
141
137
|
content = inlineContentToNodes(
|
|
142
138
|
[block.content],
|
|
143
|
-
|
|
144
|
-
editor.schema.styleSchema,
|
|
139
|
+
pmSchema,
|
|
145
140
|
newNodeType.name
|
|
146
141
|
);
|
|
147
142
|
} else if (Array.isArray(block.content)) {
|
|
148
143
|
// Adds a text node with the provided styles converted into marks to the content,
|
|
149
144
|
// for each InlineContent object.
|
|
150
|
-
content = inlineContentToNodes(
|
|
151
|
-
block.content,
|
|
152
|
-
state.schema,
|
|
153
|
-
editor.schema.styleSchema,
|
|
154
|
-
newNodeType.name
|
|
155
|
-
);
|
|
145
|
+
content = inlineContentToNodes(block.content, pmSchema, newNodeType.name);
|
|
156
146
|
} else if (block.content.type === "tableContent") {
|
|
157
|
-
content = tableContentToNodes(
|
|
158
|
-
block.content,
|
|
159
|
-
state.schema,
|
|
160
|
-
editor.schema.styleSchema
|
|
161
|
-
);
|
|
147
|
+
content = tableContentToNodes(block.content, pmSchema);
|
|
162
148
|
} else {
|
|
163
149
|
throw new UnreachableCaseError(block.content.type);
|
|
164
150
|
}
|
|
@@ -186,9 +172,9 @@ function updateBlockContentNode<
|
|
|
186
172
|
// content is being replaced or not.
|
|
187
173
|
if (content === "keep") {
|
|
188
174
|
// use setNodeMarkup to only update the type and attributes
|
|
189
|
-
|
|
175
|
+
tr.setNodeMarkup(
|
|
190
176
|
blockInfo.blockContent.beforePos,
|
|
191
|
-
block.type === undefined ? undefined :
|
|
177
|
+
block.type === undefined ? undefined : pmSchema.nodes[block.type],
|
|
192
178
|
{
|
|
193
179
|
...blockInfo.blockContent.node.attrs,
|
|
194
180
|
...block.props,
|
|
@@ -198,7 +184,7 @@ function updateBlockContentNode<
|
|
|
198
184
|
// use replaceWith to replace the content and the block itself
|
|
199
185
|
// also reset the selection since replacing the block content
|
|
200
186
|
// sets it to the next block.
|
|
201
|
-
|
|
187
|
+
tr.replaceWith(
|
|
202
188
|
blockInfo.blockContent.beforePos,
|
|
203
189
|
blockInfo.blockContent.afterPos,
|
|
204
190
|
newNodeType.createChecked(
|
|
@@ -216,15 +202,11 @@ function updateChildren<
|
|
|
216
202
|
BSchema extends BlockSchema,
|
|
217
203
|
I extends InlineContentSchema,
|
|
218
204
|
S extends StyleSchema
|
|
219
|
-
>(
|
|
220
|
-
|
|
221
|
-
state: EditorState,
|
|
222
|
-
editor: BlockNoteEditor<BSchema, I, S>,
|
|
223
|
-
blockInfo: BlockInfo
|
|
224
|
-
) {
|
|
205
|
+
>(block: PartialBlock<BSchema, I, S>, tr: Transaction, blockInfo: BlockInfo) {
|
|
206
|
+
const pmSchema = getPmSchema(tr);
|
|
225
207
|
if (block.children !== undefined && block.children.length > 0) {
|
|
226
208
|
const childNodes = block.children.map((child) => {
|
|
227
|
-
return blockToNode(child,
|
|
209
|
+
return blockToNode(child, pmSchema);
|
|
228
210
|
});
|
|
229
211
|
|
|
230
212
|
// Checks if a blockGroup node already exists.
|
|
@@ -232,7 +214,7 @@ function updateChildren<
|
|
|
232
214
|
// Replaces all child nodes in the existing blockGroup with the ones created earlier.
|
|
233
215
|
|
|
234
216
|
// use a replacestep to avoid the fitting algorithm
|
|
235
|
-
|
|
217
|
+
tr.step(
|
|
236
218
|
new ReplaceStep(
|
|
237
219
|
blockInfo.childContainer.beforePos + 1,
|
|
238
220
|
blockInfo.childContainer.afterPos - 1,
|
|
@@ -244,51 +226,36 @@ function updateChildren<
|
|
|
244
226
|
throw new Error("impossible");
|
|
245
227
|
}
|
|
246
228
|
// Inserts a new blockGroup containing the child nodes created earlier.
|
|
247
|
-
|
|
229
|
+
tr.insert(
|
|
248
230
|
blockInfo.blockContent.afterPos,
|
|
249
|
-
|
|
231
|
+
pmSchema.nodes["blockGroup"].createChecked({}, childNodes)
|
|
250
232
|
);
|
|
251
233
|
}
|
|
252
234
|
}
|
|
253
235
|
}
|
|
254
236
|
|
|
255
237
|
export function updateBlock<
|
|
256
|
-
BSchema extends BlockSchema,
|
|
257
|
-
I extends InlineContentSchema,
|
|
258
|
-
S extends StyleSchema
|
|
238
|
+
BSchema extends BlockSchema = any,
|
|
239
|
+
I extends InlineContentSchema = any,
|
|
240
|
+
S extends StyleSchema = any
|
|
259
241
|
>(
|
|
260
|
-
|
|
242
|
+
tr: Transaction,
|
|
261
243
|
blockToUpdate: BlockIdentifier,
|
|
262
244
|
update: PartialBlock<BSchema, I, S>
|
|
263
245
|
): Block<BSchema, I, S> {
|
|
264
|
-
const ttEditor = editor._tiptapEditor;
|
|
265
|
-
|
|
266
246
|
const id =
|
|
267
247
|
typeof blockToUpdate === "string" ? blockToUpdate : blockToUpdate.id;
|
|
268
|
-
|
|
269
|
-
const posInfo = getNodeById(id, ttEditor.state.doc);
|
|
248
|
+
const posInfo = getNodeById(id, tr.doc);
|
|
270
249
|
if (!posInfo) {
|
|
271
250
|
throw new Error(`Block with ID ${id} not found`);
|
|
272
251
|
}
|
|
273
252
|
|
|
274
|
-
|
|
275
|
-
updateBlockCommand(
|
|
276
|
-
editor,
|
|
277
|
-
posInfo.posBeforeNode,
|
|
278
|
-
update
|
|
279
|
-
)({ state, dispatch });
|
|
280
|
-
return true;
|
|
281
|
-
});
|
|
253
|
+
updateBlockTr(tr, posInfo.posBeforeNode, update);
|
|
282
254
|
|
|
283
|
-
const blockContainerNode =
|
|
255
|
+
const blockContainerNode = tr.doc
|
|
284
256
|
.resolve(posInfo.posBeforeNode + 1) // TODO: clean?
|
|
285
257
|
.node();
|
|
286
258
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
editor.schema.blockSchema,
|
|
290
|
-
editor.schema.inlineContentSchema,
|
|
291
|
-
editor.schema.styleSchema,
|
|
292
|
-
editor.blockCache
|
|
293
|
-
);
|
|
259
|
+
const pmSchema = getPmSchema(tr);
|
|
260
|
+
return nodeToBlock(blockContainerNode, pmSchema);
|
|
294
261
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
1
|
+
import type { Node } from "prosemirror-model";
|
|
2
|
+
import type { Block } from "../../../blocks/defaultBlocks.js";
|
|
3
|
+
import type {
|
|
4
4
|
BlockIdentifier,
|
|
5
5
|
BlockSchema,
|
|
6
6
|
InlineContentSchema,
|
|
@@ -8,30 +8,26 @@ import {
|
|
|
8
8
|
} from "../../../schema/index.js";
|
|
9
9
|
import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
|
|
10
10
|
import { getNodeById } from "../../nodeUtil.js";
|
|
11
|
+
import { getPmSchema } from "../../pmUtil.js";
|
|
11
12
|
|
|
12
13
|
export function getBlock<
|
|
13
14
|
BSchema extends BlockSchema,
|
|
14
15
|
I extends InlineContentSchema,
|
|
15
16
|
S extends StyleSchema
|
|
16
17
|
>(
|
|
17
|
-
|
|
18
|
+
doc: Node,
|
|
18
19
|
blockIdentifier: BlockIdentifier
|
|
19
20
|
): Block<BSchema, I, S> | undefined {
|
|
20
21
|
const id =
|
|
21
22
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
23
|
+
const pmSchema = getPmSchema(doc);
|
|
22
24
|
|
|
23
|
-
const posInfo = getNodeById(id,
|
|
25
|
+
const posInfo = getNodeById(id, doc);
|
|
24
26
|
if (!posInfo) {
|
|
25
27
|
return undefined;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
return nodeToBlock(
|
|
29
|
-
posInfo.node,
|
|
30
|
-
editor.schema.blockSchema,
|
|
31
|
-
editor.schema.inlineContentSchema,
|
|
32
|
-
editor.schema.styleSchema,
|
|
33
|
-
editor.blockCache
|
|
34
|
-
);
|
|
30
|
+
return nodeToBlock(posInfo.node, pmSchema);
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
export function getPrevBlock<
|
|
@@ -39,32 +35,25 @@ export function getPrevBlock<
|
|
|
39
35
|
I extends InlineContentSchema,
|
|
40
36
|
S extends StyleSchema
|
|
41
37
|
>(
|
|
42
|
-
|
|
38
|
+
doc: Node,
|
|
43
39
|
blockIdentifier: BlockIdentifier
|
|
44
40
|
): Block<BSchema, I, S> | undefined {
|
|
45
41
|
const id =
|
|
46
42
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
47
43
|
|
|
48
|
-
const posInfo = getNodeById(id,
|
|
44
|
+
const posInfo = getNodeById(id, doc);
|
|
45
|
+
const pmSchema = getPmSchema(doc);
|
|
49
46
|
if (!posInfo) {
|
|
50
47
|
return undefined;
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
const $posBeforeNode =
|
|
54
|
-
posInfo.posBeforeNode
|
|
55
|
-
);
|
|
50
|
+
const $posBeforeNode = doc.resolve(posInfo.posBeforeNode);
|
|
56
51
|
const nodeToConvert = $posBeforeNode.nodeBefore;
|
|
57
52
|
if (!nodeToConvert) {
|
|
58
53
|
return undefined;
|
|
59
54
|
}
|
|
60
55
|
|
|
61
|
-
return nodeToBlock(
|
|
62
|
-
nodeToConvert,
|
|
63
|
-
editor.schema.blockSchema,
|
|
64
|
-
editor.schema.inlineContentSchema,
|
|
65
|
-
editor.schema.styleSchema,
|
|
66
|
-
editor.blockCache
|
|
67
|
-
);
|
|
56
|
+
return nodeToBlock(nodeToConvert, pmSchema);
|
|
68
57
|
}
|
|
69
58
|
|
|
70
59
|
export function getNextBlock<
|
|
@@ -72,18 +61,18 @@ export function getNextBlock<
|
|
|
72
61
|
I extends InlineContentSchema,
|
|
73
62
|
S extends StyleSchema
|
|
74
63
|
>(
|
|
75
|
-
|
|
64
|
+
doc: Node,
|
|
76
65
|
blockIdentifier: BlockIdentifier
|
|
77
66
|
): Block<BSchema, I, S> | undefined {
|
|
78
67
|
const id =
|
|
79
68
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
80
|
-
|
|
81
|
-
const
|
|
69
|
+
const posInfo = getNodeById(id, doc);
|
|
70
|
+
const pmSchema = getPmSchema(doc);
|
|
82
71
|
if (!posInfo) {
|
|
83
72
|
return undefined;
|
|
84
73
|
}
|
|
85
74
|
|
|
86
|
-
const $posAfterNode =
|
|
75
|
+
const $posAfterNode = doc.resolve(
|
|
87
76
|
posInfo.posBeforeNode + posInfo.node.nodeSize
|
|
88
77
|
);
|
|
89
78
|
const nodeToConvert = $posAfterNode.nodeAfter;
|
|
@@ -91,13 +80,7 @@ export function getNextBlock<
|
|
|
91
80
|
return undefined;
|
|
92
81
|
}
|
|
93
82
|
|
|
94
|
-
return nodeToBlock(
|
|
95
|
-
nodeToConvert,
|
|
96
|
-
editor.schema.blockSchema,
|
|
97
|
-
editor.schema.inlineContentSchema,
|
|
98
|
-
editor.schema.styleSchema,
|
|
99
|
-
editor.blockCache
|
|
100
|
-
);
|
|
83
|
+
return nodeToBlock(nodeToConvert, pmSchema);
|
|
101
84
|
}
|
|
102
85
|
|
|
103
86
|
export function getParentBlock<
|
|
@@ -105,20 +88,18 @@ export function getParentBlock<
|
|
|
105
88
|
I extends InlineContentSchema,
|
|
106
89
|
S extends StyleSchema
|
|
107
90
|
>(
|
|
108
|
-
|
|
91
|
+
doc: Node,
|
|
109
92
|
blockIdentifier: BlockIdentifier
|
|
110
93
|
): Block<BSchema, I, S> | undefined {
|
|
111
94
|
const id =
|
|
112
95
|
typeof blockIdentifier === "string" ? blockIdentifier : blockIdentifier.id;
|
|
113
|
-
|
|
114
|
-
const posInfo = getNodeById(id,
|
|
96
|
+
const pmSchema = getPmSchema(doc);
|
|
97
|
+
const posInfo = getNodeById(id, doc);
|
|
115
98
|
if (!posInfo) {
|
|
116
99
|
return undefined;
|
|
117
100
|
}
|
|
118
101
|
|
|
119
|
-
const $posBeforeNode =
|
|
120
|
-
posInfo.posBeforeNode
|
|
121
|
-
);
|
|
102
|
+
const $posBeforeNode = doc.resolve(posInfo.posBeforeNode);
|
|
122
103
|
const parentNode = $posBeforeNode.node();
|
|
123
104
|
const grandparentNode = $posBeforeNode.node(-1);
|
|
124
105
|
const nodeToConvert =
|
|
@@ -131,11 +112,5 @@ export function getParentBlock<
|
|
|
131
112
|
return undefined;
|
|
132
113
|
}
|
|
133
114
|
|
|
134
|
-
return nodeToBlock(
|
|
135
|
-
nodeToConvert,
|
|
136
|
-
editor.schema.blockSchema,
|
|
137
|
-
editor.schema.inlineContentSchema,
|
|
138
|
-
editor.schema.styleSchema,
|
|
139
|
-
editor.blockCache
|
|
140
|
-
);
|
|
115
|
+
return nodeToBlock(nodeToConvert, pmSchema);
|
|
141
116
|
}
|
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
import { selectionToInsertionEnd } from "@tiptap/core";
|
|
2
2
|
import { Node } from "prosemirror-model";
|
|
3
3
|
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
6
|
-
BlockSchema,
|
|
7
|
-
InlineContentSchema,
|
|
8
|
-
StyleSchema,
|
|
9
|
-
} from "../../schema/index.js";
|
|
4
|
+
import type { Transaction } from "prosemirror-state";
|
|
10
5
|
|
|
11
6
|
// similar to tiptap insertContentAt
|
|
12
|
-
export function insertContentAt
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
S extends StyleSchema
|
|
16
|
-
>(
|
|
17
|
-
position: any,
|
|
7
|
+
export function insertContentAt(
|
|
8
|
+
tr: Transaction,
|
|
9
|
+
position: number | { from: number; to: number },
|
|
18
10
|
nodes: Node[],
|
|
19
|
-
editor: BlockNoteEditor<BSchema, I, S>,
|
|
20
11
|
options: {
|
|
21
12
|
updateSelection: boolean;
|
|
22
13
|
} = { updateSelection: true }
|
|
23
14
|
) {
|
|
24
|
-
const tr = editor._tiptapEditor.state.tr;
|
|
25
|
-
|
|
26
15
|
// don’t dispatch an empty fragment because this can lead to strange errors
|
|
27
16
|
// if (content.toString() === "<>") {
|
|
28
17
|
// return true;
|
|
@@ -90,7 +79,5 @@ export function insertContentAt<
|
|
|
90
79
|
selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
|
|
91
80
|
}
|
|
92
81
|
|
|
93
|
-
editor.dispatch(tr);
|
|
94
|
-
|
|
95
82
|
return true;
|
|
96
83
|
}
|
|
@@ -7,50 +7,66 @@ const getEditor = setupTestEnv();
|
|
|
7
7
|
|
|
8
8
|
describe("Test getSelection & setSelection", () => {
|
|
9
9
|
it("Basic", () => {
|
|
10
|
-
|
|
10
|
+
getEditor().transact((tr) => {
|
|
11
|
+
setSelection(tr, "paragraph-0", "paragraph-1");
|
|
12
|
+
});
|
|
11
13
|
|
|
12
|
-
expect(
|
|
14
|
+
expect(getEditor().transact((tr) => getSelection(tr))).toMatchSnapshot();
|
|
13
15
|
});
|
|
14
16
|
|
|
15
17
|
it("Starts in block with children", () => {
|
|
16
|
-
|
|
18
|
+
getEditor().transact((tr) => {
|
|
19
|
+
setSelection(tr, "paragraph-with-children", "paragraph-2");
|
|
20
|
+
});
|
|
17
21
|
|
|
18
|
-
expect(
|
|
22
|
+
expect(getEditor().transact((tr) => getSelection(tr))).toMatchSnapshot();
|
|
19
23
|
});
|
|
20
24
|
|
|
21
25
|
it("Starts in nested block", () => {
|
|
22
|
-
|
|
26
|
+
getEditor().transact((tr) => {
|
|
27
|
+
setSelection(tr, "nested-paragraph-0", "paragraph-2");
|
|
28
|
+
});
|
|
23
29
|
|
|
24
|
-
expect(
|
|
30
|
+
expect(getEditor().transact((tr) => getSelection(tr))).toMatchSnapshot();
|
|
25
31
|
});
|
|
26
32
|
|
|
27
33
|
it("Ends in block with children", () => {
|
|
28
|
-
|
|
34
|
+
getEditor().transact((tr) => {
|
|
35
|
+
setSelection(tr, "paragraph-1", "paragraph-with-children");
|
|
36
|
+
});
|
|
29
37
|
|
|
30
|
-
expect(
|
|
38
|
+
expect(getEditor().transact((tr) => getSelection(tr))).toMatchSnapshot();
|
|
31
39
|
});
|
|
32
40
|
|
|
33
41
|
it("Ends in nested block", () => {
|
|
34
|
-
|
|
42
|
+
getEditor().transact((tr) => {
|
|
43
|
+
setSelection(tr, "paragraph-1", "nested-paragraph-0");
|
|
44
|
+
});
|
|
35
45
|
|
|
36
|
-
expect(
|
|
46
|
+
expect(getEditor().transact((tr) => getSelection(tr))).toMatchSnapshot();
|
|
37
47
|
});
|
|
38
48
|
|
|
39
49
|
it("Contains block with children", () => {
|
|
40
|
-
|
|
50
|
+
getEditor().transact((tr) => {
|
|
51
|
+
setSelection(tr, "paragraph-1", "paragraph-2");
|
|
52
|
+
});
|
|
41
53
|
|
|
42
|
-
expect(
|
|
54
|
+
expect(getEditor().transact((tr) => getSelection(tr))).toMatchSnapshot();
|
|
43
55
|
});
|
|
44
56
|
|
|
45
57
|
it("Starts in table", () => {
|
|
46
|
-
|
|
58
|
+
getEditor().transact((tr) => {
|
|
59
|
+
setSelection(tr, "table-0", "paragraph-7");
|
|
60
|
+
});
|
|
47
61
|
|
|
48
|
-
expect(
|
|
62
|
+
expect(getEditor().transact((tr) => getSelection(tr))).toMatchSnapshot();
|
|
49
63
|
});
|
|
50
64
|
|
|
51
65
|
it("Ends in table", () => {
|
|
52
|
-
|
|
66
|
+
getEditor().transact((tr) => {
|
|
67
|
+
setSelection(tr, "paragraph-6", "table-0");
|
|
68
|
+
});
|
|
53
69
|
|
|
54
|
-
expect(
|
|
70
|
+
expect(getEditor().transact((tr) => getSelection(tr))).toMatchSnapshot();
|
|
55
71
|
});
|
|
56
72
|
});
|