@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,11 +1,11 @@
|
|
|
1
1
|
import { Fragment } from "@tiptap/pm/model";
|
|
2
|
-
import { BlockNoteSchema } from "../../editor/BlockNoteSchema.js";
|
|
3
2
|
import {
|
|
4
3
|
BlockNoDefaults,
|
|
5
4
|
BlockSchema,
|
|
6
5
|
InlineContentSchema,
|
|
7
6
|
StyleSchema,
|
|
8
7
|
} from "../../schema/index.js";
|
|
8
|
+
import { getPmSchema } from "../pmUtil.js";
|
|
9
9
|
import { nodeToBlock } from "./nodeToBlock.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -15,11 +15,12 @@ export function fragmentToBlocks<
|
|
|
15
15
|
B extends BlockSchema,
|
|
16
16
|
I extends InlineContentSchema,
|
|
17
17
|
S extends StyleSchema
|
|
18
|
-
>(fragment: Fragment
|
|
18
|
+
>(fragment: Fragment) {
|
|
19
19
|
// first convert selection to blocknote-style blocks, and then
|
|
20
20
|
// pass these to the exporter
|
|
21
21
|
const blocks: BlockNoDefaults<B, I, S>[] = [];
|
|
22
22
|
fragment.descendants((node) => {
|
|
23
|
+
const pmSchema = getPmSchema(node);
|
|
23
24
|
if (node.type.name === "blockContainer") {
|
|
24
25
|
if (node.firstChild?.type.name === "blockGroup") {
|
|
25
26
|
// selection started within a block group
|
|
@@ -48,27 +49,13 @@ export function fragmentToBlocks<
|
|
|
48
49
|
if (node.type.name === "columnList" && node.childCount === 1) {
|
|
49
50
|
// column lists with a single column should be flattened (not the entire column list has been selected)
|
|
50
51
|
node.firstChild?.forEach((child) => {
|
|
51
|
-
blocks.push(
|
|
52
|
-
nodeToBlock(
|
|
53
|
-
child,
|
|
54
|
-
schema.blockSchema,
|
|
55
|
-
schema.inlineContentSchema,
|
|
56
|
-
schema.styleSchema
|
|
57
|
-
)
|
|
58
|
-
);
|
|
52
|
+
blocks.push(nodeToBlock(child, pmSchema));
|
|
59
53
|
});
|
|
60
54
|
return false;
|
|
61
55
|
}
|
|
62
56
|
|
|
63
57
|
if (node.type.isInGroup("bnBlock")) {
|
|
64
|
-
blocks.push(
|
|
65
|
-
nodeToBlock(
|
|
66
|
-
node,
|
|
67
|
-
schema.blockSchema,
|
|
68
|
-
schema.inlineContentSchema,
|
|
69
|
-
schema.styleSchema
|
|
70
|
-
)
|
|
71
|
-
);
|
|
58
|
+
blocks.push(nodeToBlock(node, pmSchema));
|
|
72
59
|
// don't descend into children, as they're already included in the block returned by nodeToBlock
|
|
73
60
|
return false;
|
|
74
61
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Mark, Node } from "@tiptap/pm/model";
|
|
1
|
+
import { Mark, Node, Schema } from "@tiptap/pm/model";
|
|
2
2
|
|
|
3
3
|
import UniqueID from "../../extensions/UniqueID/UniqueID.js";
|
|
4
4
|
import type {
|
|
@@ -21,6 +21,9 @@ import {
|
|
|
21
21
|
isStyledTextInlineContent,
|
|
22
22
|
} from "../../schema/inlineContent/types.js";
|
|
23
23
|
import { UnreachableCaseError } from "../../util/typescript.js";
|
|
24
|
+
import { getBlockCache, getStyleSchema } from "../pmUtil.js";
|
|
25
|
+
import { getInlineContentSchema } from "../pmUtil.js";
|
|
26
|
+
import { getBlockSchema } from "../pmUtil.js";
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* Converts an internal (prosemirror) table node contentto a BlockNote Tablecontent
|
|
@@ -385,15 +388,14 @@ export function nodeToBlock<
|
|
|
385
388
|
S extends StyleSchema
|
|
386
389
|
>(
|
|
387
390
|
node: Node,
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
391
|
+
schema: Schema,
|
|
392
|
+
blockSchema: BSchema = getBlockSchema(schema) as BSchema,
|
|
393
|
+
inlineContentSchema: I = getInlineContentSchema(schema) as I,
|
|
394
|
+
styleSchema: S = getStyleSchema(schema) as S,
|
|
395
|
+
blockCache = getBlockCache(schema)
|
|
392
396
|
): Block<BSchema, I, S> {
|
|
393
397
|
if (!node.type.isInGroup("bnBlock")) {
|
|
394
|
-
throw Error(
|
|
395
|
-
"Node must be in bnBlock group, but is of type" + node.type.name
|
|
396
|
-
);
|
|
398
|
+
throw Error("Node should be a bnBlock, but is instead: " + node.type.name);
|
|
397
399
|
}
|
|
398
400
|
|
|
399
401
|
const cachedBlock = blockCache?.get(node);
|
|
@@ -439,6 +441,7 @@ export function nodeToBlock<
|
|
|
439
441
|
children.push(
|
|
440
442
|
nodeToBlock(
|
|
441
443
|
child,
|
|
444
|
+
schema,
|
|
442
445
|
blockSchema,
|
|
443
446
|
inlineContentSchema,
|
|
444
447
|
styleSchema,
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { describe, expect, it, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { setupTestEnv } from "./blockManipulation/setupTestEnv.js";
|
|
4
|
+
import { getBlocksChangedByTransaction } from "./nodeUtil.js";
|
|
5
|
+
import { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
6
|
+
|
|
7
|
+
const getEditor = setupTestEnv();
|
|
8
|
+
|
|
9
|
+
describe("Test getBlocksChangedByTransaction", () => {
|
|
10
|
+
let editor: BlockNoteEditor;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
editor = getEditor();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should return the correct blocks changed by a transaction", () => {
|
|
17
|
+
const blocksChanged = editor.transact((tr) => {
|
|
18
|
+
return getBlocksChangedByTransaction(tr);
|
|
19
|
+
});
|
|
20
|
+
expect(blocksChanged).toEqual([]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should return blocks inserted by a transaction", async () => {
|
|
24
|
+
const blocksChanged = editor.transact((tr) => {
|
|
25
|
+
editor.insertBlocks([{ type: "paragraph" }], "paragraph-0", "after");
|
|
26
|
+
return getBlocksChangedByTransaction(tr);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
30
|
+
"__snapshots__/blocks-inserted.json"
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should return nested blocks inserted by a transaction", async () => {
|
|
35
|
+
const blocksChanged = editor.transact((tr) => {
|
|
36
|
+
editor.insertBlocks(
|
|
37
|
+
[
|
|
38
|
+
{
|
|
39
|
+
type: "paragraph",
|
|
40
|
+
children: [{ type: "paragraph", content: "Nested" }],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
"paragraph-0",
|
|
44
|
+
"after"
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return getBlocksChangedByTransaction(tr);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
51
|
+
"__snapshots__/blocks-inserted-nested.json"
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should return blocks deleted by a transaction", async () => {
|
|
56
|
+
const blocksChanged = editor.transact((tr) => {
|
|
57
|
+
editor.removeBlocks(["paragraph-0"]);
|
|
58
|
+
return getBlocksChangedByTransaction(tr);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
62
|
+
"__snapshots__/blocks-deleted.json"
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should return deeply nested blocks deleted by a transaction", async () => {
|
|
67
|
+
const blocksChanged = editor.transact((tr) => {
|
|
68
|
+
editor.removeBlocks(["double-nested-paragraph-0"]);
|
|
69
|
+
return getBlocksChangedByTransaction(tr);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
73
|
+
"__snapshots__/blocks-deleted-nested-deep.json"
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should return nested blocks deleted by a transaction", async () => {
|
|
78
|
+
const blocksChanged = editor.transact((tr) => {
|
|
79
|
+
editor.removeBlocks(["nested-paragraph-0"]);
|
|
80
|
+
return getBlocksChangedByTransaction(tr);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
84
|
+
"__snapshots__/blocks-deleted-nested.json"
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should return blocks updated by a transaction", async () => {
|
|
89
|
+
const blocksChanged = editor.transact((tr) => {
|
|
90
|
+
editor.updateBlock("paragraph-0", {
|
|
91
|
+
props: {
|
|
92
|
+
backgroundColor: "red",
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return getBlocksChangedByTransaction(tr);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
100
|
+
"__snapshots__/blocks-updated.json"
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should return nested blocks updated by a transaction", async () => {
|
|
105
|
+
const blocksChanged = editor.transact((tr) => {
|
|
106
|
+
editor.updateBlock("nested-paragraph-0", {
|
|
107
|
+
props: {
|
|
108
|
+
backgroundColor: "red",
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return getBlocksChangedByTransaction(tr);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
116
|
+
"__snapshots__/blocks-updated-nested.json"
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should return deeply nested blocks updated by a transaction", async () => {
|
|
121
|
+
const blocksChanged = editor.transact((tr) => {
|
|
122
|
+
editor.updateBlock("double-nested-paragraph-0", {
|
|
123
|
+
content: "Example Text",
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return getBlocksChangedByTransaction(tr);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
130
|
+
"__snapshots__/blocks-updated-nested-deep.json"
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should return multiple nested blocks updated by a transaction", async () => {
|
|
135
|
+
const blocksChanged = editor.transact((tr) => {
|
|
136
|
+
editor.updateBlock("nested-paragraph-0", {
|
|
137
|
+
props: {
|
|
138
|
+
backgroundColor: "red",
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
editor.updateBlock("double-nested-paragraph-0", {
|
|
142
|
+
content: "Example Text",
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return getBlocksChangedByTransaction(tr);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
149
|
+
"__snapshots__/blocks-updated-nested-multiple.json"
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("should only return a single block, if multiple updates change a single block in a transaction", async () => {
|
|
154
|
+
const blocksChanged = editor.transact((tr) => {
|
|
155
|
+
editor.updateBlock("paragraph-0", {
|
|
156
|
+
props: {
|
|
157
|
+
backgroundColor: "red",
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
editor.updateBlock("paragraph-0", {
|
|
161
|
+
props: {
|
|
162
|
+
backgroundColor: "blue",
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return getBlocksChangedByTransaction(tr);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
170
|
+
"__snapshots__/blocks-updated-single.json"
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("should return multiple blocks, if multiple updates change multiple blocks in a transaction", async () => {
|
|
175
|
+
const blocksChanged = editor.transact((tr) => {
|
|
176
|
+
editor.updateBlock("paragraph-0", {
|
|
177
|
+
props: {
|
|
178
|
+
backgroundColor: "red",
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
editor.updateBlock("paragraph-1", {
|
|
182
|
+
props: {
|
|
183
|
+
backgroundColor: "blue",
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
return getBlocksChangedByTransaction(tr);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
191
|
+
"__snapshots__/blocks-updated-multiple.json"
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("should return multiple blocks, if multiple inserts add new blocks in a transaction", async () => {
|
|
196
|
+
const blocksChanged = editor.transact((tr) => {
|
|
197
|
+
editor.insertBlocks(
|
|
198
|
+
[{ type: "paragraph", content: "ABC" }],
|
|
199
|
+
"paragraph-0",
|
|
200
|
+
"after"
|
|
201
|
+
);
|
|
202
|
+
editor.insertBlocks(
|
|
203
|
+
[{ type: "paragraph", content: "DEF" }],
|
|
204
|
+
"paragraph-1",
|
|
205
|
+
"after"
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
return getBlocksChangedByTransaction(tr);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
212
|
+
"__snapshots__/blocks-updated-multiple-insert.json"
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("should return blocks which have had content inserted into them", async () => {
|
|
217
|
+
const blocksChanged = editor.transact((tr) => {
|
|
218
|
+
editor.setTextCursorPosition("paragraph-2", "start");
|
|
219
|
+
editor.insertInlineContent("Hello");
|
|
220
|
+
|
|
221
|
+
return getBlocksChangedByTransaction(tr);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
await expect(blocksChanged).toMatchFileSnapshot(
|
|
225
|
+
"__snapshots__/blocks-updated-content-inserted.json"
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
});
|
package/src/api/nodeUtil.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
combineTransactionSteps,
|
|
3
|
+
findChildrenInRange,
|
|
4
|
+
getChangedRanges,
|
|
5
|
+
} from "@tiptap/core";
|
|
6
|
+
import type { Node } from "prosemirror-model";
|
|
7
|
+
import type { Transaction } from "prosemirror-state";
|
|
8
|
+
import {
|
|
9
|
+
Block,
|
|
10
|
+
DefaultBlockSchema,
|
|
11
|
+
DefaultInlineContentSchema,
|
|
12
|
+
DefaultStyleSchema,
|
|
13
|
+
} from "../blocks/defaultBlocks.js";
|
|
14
|
+
import type { BlockSchema } from "../schema/index.js";
|
|
15
|
+
import type { InlineContentSchema } from "../schema/inlineContent/types.js";
|
|
16
|
+
import type { StyleSchema } from "../schema/styles/types.js";
|
|
17
|
+
import { nodeToBlock } from "./nodeConversions/nodeToBlock.js";
|
|
18
|
+
import { getPmSchema } from "./pmUtil.js";
|
|
2
19
|
|
|
3
20
|
/**
|
|
4
21
|
* Get a TipTap node by id
|
|
@@ -17,7 +34,7 @@ export function getNodeById(
|
|
|
17
34
|
}
|
|
18
35
|
|
|
19
36
|
// Keeps traversing nodes if block with target ID has not been found.
|
|
20
|
-
if (!node
|
|
37
|
+
if (!isNodeBlock(node) || node.attrs.id !== id) {
|
|
21
38
|
return true;
|
|
22
39
|
}
|
|
23
40
|
|
|
@@ -36,3 +53,219 @@ export function getNodeById(
|
|
|
36
53
|
posBeforeNode: posBeforeNode,
|
|
37
54
|
};
|
|
38
55
|
}
|
|
56
|
+
|
|
57
|
+
export function isNodeBlock(node: Node): boolean {
|
|
58
|
+
return node.type.isInGroup("bnBlock");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* This attributes the changes to a specific source.
|
|
63
|
+
*/
|
|
64
|
+
export type BlockChangeSource =
|
|
65
|
+
| {
|
|
66
|
+
/**
|
|
67
|
+
* When an event is triggered by the local user, the source is "local".
|
|
68
|
+
* This is the default source.
|
|
69
|
+
*/
|
|
70
|
+
type: "local";
|
|
71
|
+
}
|
|
72
|
+
| {
|
|
73
|
+
/**
|
|
74
|
+
* When an event is triggered by a paste operation, the source is "paste".
|
|
75
|
+
*/
|
|
76
|
+
type: "paste";
|
|
77
|
+
}
|
|
78
|
+
| {
|
|
79
|
+
/**
|
|
80
|
+
* When an event is triggered by a drop operation, the source is "drop".
|
|
81
|
+
*/
|
|
82
|
+
type: "drop";
|
|
83
|
+
}
|
|
84
|
+
| {
|
|
85
|
+
/**
|
|
86
|
+
* When an event is triggered by an undo or redo operation, the source is "undo" or "redo".
|
|
87
|
+
* @note Y.js undo/redo are not differentiated.
|
|
88
|
+
*/
|
|
89
|
+
type: "undo" | "redo" | "undo-redo";
|
|
90
|
+
}
|
|
91
|
+
| {
|
|
92
|
+
/**
|
|
93
|
+
* When an event is triggered by a remote user, the source is "remote".
|
|
94
|
+
*/
|
|
95
|
+
type: "yjs-remote";
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type BlocksChanged<
|
|
99
|
+
BSchema extends BlockSchema = DefaultBlockSchema,
|
|
100
|
+
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
|
|
101
|
+
SSchema extends StyleSchema = DefaultStyleSchema
|
|
102
|
+
> = Array<
|
|
103
|
+
{
|
|
104
|
+
/**
|
|
105
|
+
* The affected block.
|
|
106
|
+
*/
|
|
107
|
+
block: Block<BSchema, ISchema, SSchema>;
|
|
108
|
+
/**
|
|
109
|
+
* The source of the change.
|
|
110
|
+
*/
|
|
111
|
+
source: BlockChangeSource;
|
|
112
|
+
} & (
|
|
113
|
+
| {
|
|
114
|
+
type: "insert" | "delete";
|
|
115
|
+
/**
|
|
116
|
+
* Insert and delete changes don't have a previous block.
|
|
117
|
+
*/
|
|
118
|
+
prevBlock: undefined;
|
|
119
|
+
}
|
|
120
|
+
| {
|
|
121
|
+
type: "update";
|
|
122
|
+
/**
|
|
123
|
+
* The block before the update.
|
|
124
|
+
*/
|
|
125
|
+
prevBlock: Block<BSchema, ISchema, SSchema>;
|
|
126
|
+
}
|
|
127
|
+
)
|
|
128
|
+
>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Compares two blocks, ignoring their children.
|
|
132
|
+
* Returns true if the blocks are different (excluding children).
|
|
133
|
+
*/
|
|
134
|
+
function areBlocksDifferentExcludingChildren<
|
|
135
|
+
BSchema extends BlockSchema,
|
|
136
|
+
ISchema extends InlineContentSchema,
|
|
137
|
+
SSchema extends StyleSchema
|
|
138
|
+
>(
|
|
139
|
+
block1: Block<BSchema, ISchema, SSchema>,
|
|
140
|
+
block2: Block<BSchema, ISchema, SSchema>
|
|
141
|
+
): boolean {
|
|
142
|
+
// TODO use an actual diff algorithm
|
|
143
|
+
// Compare all properties except children
|
|
144
|
+
return (
|
|
145
|
+
block1.id !== block2.id ||
|
|
146
|
+
block1.type !== block2.type ||
|
|
147
|
+
JSON.stringify(block1.props) !== JSON.stringify(block2.props) ||
|
|
148
|
+
JSON.stringify(block1.content) !== JSON.stringify(block2.content)
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get the blocks that were changed by a transaction.
|
|
154
|
+
* @param transaction The transaction to get the changes from.
|
|
155
|
+
* @param editor The editor to get the changes from.
|
|
156
|
+
* @returns The blocks that were changed by the transaction.
|
|
157
|
+
*/
|
|
158
|
+
export function getBlocksChangedByTransaction<
|
|
159
|
+
BSchema extends BlockSchema = DefaultBlockSchema,
|
|
160
|
+
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
|
|
161
|
+
SSchema extends StyleSchema = DefaultStyleSchema
|
|
162
|
+
>(
|
|
163
|
+
transaction: Transaction,
|
|
164
|
+
appendedTransactions: Transaction[] = []
|
|
165
|
+
): BlocksChanged<BSchema, ISchema, SSchema> {
|
|
166
|
+
let source: BlockChangeSource = { type: "local" };
|
|
167
|
+
|
|
168
|
+
if (transaction.getMeta("paste")) {
|
|
169
|
+
source = { type: "paste" };
|
|
170
|
+
} else if (transaction.getMeta("uiEvent") === "drop") {
|
|
171
|
+
source = { type: "drop" };
|
|
172
|
+
} else if (transaction.getMeta("history$")) {
|
|
173
|
+
source = {
|
|
174
|
+
type: transaction.getMeta("history$").redo ? "redo" : "undo",
|
|
175
|
+
};
|
|
176
|
+
} else if (transaction.getMeta("y-sync$")) {
|
|
177
|
+
if (transaction.getMeta("y-sync$").isUndoRedoOperation) {
|
|
178
|
+
source = {
|
|
179
|
+
type: "undo-redo",
|
|
180
|
+
};
|
|
181
|
+
} else {
|
|
182
|
+
source = {
|
|
183
|
+
type: "yjs-remote",
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Get affected blocks before and after the change
|
|
189
|
+
const pmSchema = getPmSchema(transaction);
|
|
190
|
+
const combinedTransaction = combineTransactionSteps(transaction.before, [
|
|
191
|
+
transaction,
|
|
192
|
+
...appendedTransactions,
|
|
193
|
+
]);
|
|
194
|
+
|
|
195
|
+
const changedRanges = getChangedRanges(combinedTransaction);
|
|
196
|
+
const prevAffectedBlocks = changedRanges
|
|
197
|
+
.flatMap((range) => {
|
|
198
|
+
return findChildrenInRange(
|
|
199
|
+
combinedTransaction.before,
|
|
200
|
+
range.oldRange,
|
|
201
|
+
isNodeBlock
|
|
202
|
+
);
|
|
203
|
+
})
|
|
204
|
+
.map(({ node }) => nodeToBlock(node, pmSchema));
|
|
205
|
+
|
|
206
|
+
const nextAffectedBlocks = changedRanges
|
|
207
|
+
.flatMap((range) => {
|
|
208
|
+
return findChildrenInRange(
|
|
209
|
+
combinedTransaction.doc,
|
|
210
|
+
range.newRange,
|
|
211
|
+
isNodeBlock
|
|
212
|
+
);
|
|
213
|
+
})
|
|
214
|
+
.map(({ node }) => nodeToBlock(node, pmSchema));
|
|
215
|
+
|
|
216
|
+
const nextBlocks = new Map(
|
|
217
|
+
nextAffectedBlocks.map((block) => {
|
|
218
|
+
return [block.id, block];
|
|
219
|
+
})
|
|
220
|
+
);
|
|
221
|
+
const prevBlocks = new Map(
|
|
222
|
+
prevAffectedBlocks.map((block) => {
|
|
223
|
+
return [block.id, block];
|
|
224
|
+
})
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const changes: BlocksChanged<BSchema, ISchema, SSchema> = [];
|
|
228
|
+
|
|
229
|
+
// Inserted blocks are blocks that were not in the previous state and are in the next state
|
|
230
|
+
for (const [id, block] of nextBlocks) {
|
|
231
|
+
if (!prevBlocks.has(id)) {
|
|
232
|
+
changes.push({
|
|
233
|
+
type: "insert",
|
|
234
|
+
block,
|
|
235
|
+
source,
|
|
236
|
+
prevBlock: undefined,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Deleted blocks are blocks that were in the previous state but not in the next state
|
|
242
|
+
for (const [id, block] of prevBlocks) {
|
|
243
|
+
if (!nextBlocks.has(id)) {
|
|
244
|
+
changes.push({
|
|
245
|
+
type: "delete",
|
|
246
|
+
block,
|
|
247
|
+
source,
|
|
248
|
+
prevBlock: undefined,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Updated blocks are blocks that were in the previous state and are in the next state
|
|
254
|
+
for (const [id, block] of nextBlocks) {
|
|
255
|
+
if (prevBlocks.has(id)) {
|
|
256
|
+
const prevBlock = prevBlocks.get(id)!;
|
|
257
|
+
|
|
258
|
+
// Only include the update if the block itself changed (excluding children)
|
|
259
|
+
if (areBlocksDifferentExcludingChildren(prevBlock, block)) {
|
|
260
|
+
changes.push({
|
|
261
|
+
type: "update",
|
|
262
|
+
block,
|
|
263
|
+
prevBlock,
|
|
264
|
+
source,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return changes;
|
|
271
|
+
}
|
|
@@ -12,13 +12,7 @@ export async function HTMLToBlocks<
|
|
|
12
12
|
BSchema extends BlockSchema,
|
|
13
13
|
I extends InlineContentSchema,
|
|
14
14
|
S extends StyleSchema
|
|
15
|
-
>(
|
|
16
|
-
html: string,
|
|
17
|
-
blockSchema: BSchema,
|
|
18
|
-
icSchema: I,
|
|
19
|
-
styleSchema: S,
|
|
20
|
-
pmSchema: Schema
|
|
21
|
-
): Promise<Block<BSchema, I, S>[]> {
|
|
15
|
+
>(html: string, pmSchema: Schema): Promise<Block<BSchema, I, S>[]> {
|
|
22
16
|
const htmlNode = nestedListsToBlockNoteStructure(html);
|
|
23
17
|
const parser = DOMParser.fromSchema(pmSchema);
|
|
24
18
|
|
|
@@ -33,9 +27,7 @@ export async function HTMLToBlocks<
|
|
|
33
27
|
const blocks: Block<BSchema, I, S>[] = [];
|
|
34
28
|
|
|
35
29
|
for (let i = 0; i < parentNode.childCount; i++) {
|
|
36
|
-
blocks.push(
|
|
37
|
-
nodeToBlock(parentNode.child(i), blockSchema, icSchema, styleSchema)
|
|
38
|
-
);
|
|
30
|
+
blocks.push(nodeToBlock(parentNode.child(i), pmSchema));
|
|
39
31
|
}
|
|
40
32
|
|
|
41
33
|
return blocks;
|
|
@@ -71,14 +71,8 @@ export async function markdownToBlocks<
|
|
|
71
71
|
BSchema extends BlockSchema,
|
|
72
72
|
I extends InlineContentSchema,
|
|
73
73
|
S extends StyleSchema
|
|
74
|
-
>(
|
|
75
|
-
markdown: string,
|
|
76
|
-
blockSchema: BSchema,
|
|
77
|
-
icSchema: I,
|
|
78
|
-
styleSchema: S,
|
|
79
|
-
pmSchema: Schema
|
|
80
|
-
): Promise<Block<BSchema, I, S>[]> {
|
|
74
|
+
>(markdown: string, pmSchema: Schema): Promise<Block<BSchema, I, S>[]> {
|
|
81
75
|
const htmlString = await markdownToHTML(markdown);
|
|
82
76
|
|
|
83
|
-
return HTMLToBlocks(htmlString,
|
|
77
|
+
return HTMLToBlocks(htmlString, pmSchema);
|
|
84
78
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Node, Schema } from "prosemirror-model";
|
|
2
|
+
import type { Transaction } from "prosemirror-state";
|
|
3
|
+
import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
4
|
+
import type { BlockSchema } from "../schema/blocks/types.js";
|
|
5
|
+
import type { InlineContentSchema } from "../schema/inlineContent/types.js";
|
|
6
|
+
import type { StyleSchema } from "../schema/styles/types.js";
|
|
7
|
+
import { BlockNoteSchema } from "../editor/BlockNoteSchema.js";
|
|
8
|
+
|
|
9
|
+
export function getPmSchema(trOrNode: Transaction | Node) {
|
|
10
|
+
if ("doc" in trOrNode) {
|
|
11
|
+
return trOrNode.doc.type.schema;
|
|
12
|
+
}
|
|
13
|
+
return trOrNode.type.schema;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getBlockNoteEditor<
|
|
17
|
+
BSchema extends BlockSchema,
|
|
18
|
+
I extends InlineContentSchema,
|
|
19
|
+
S extends StyleSchema
|
|
20
|
+
>(schema: Schema): BlockNoteEditor<BSchema, I, S> {
|
|
21
|
+
return schema.cached.blockNoteEditor as BlockNoteEditor<BSchema, I, S>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getBlockNoteSchema<
|
|
25
|
+
BSchema extends BlockSchema,
|
|
26
|
+
I extends InlineContentSchema,
|
|
27
|
+
S extends StyleSchema
|
|
28
|
+
>(schema: Schema): BlockNoteSchema<BSchema, I, S> {
|
|
29
|
+
return getBlockNoteEditor(schema).schema as unknown as BlockNoteSchema<
|
|
30
|
+
BSchema,
|
|
31
|
+
I,
|
|
32
|
+
S
|
|
33
|
+
>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getBlockSchema<BSchema extends BlockSchema>(
|
|
37
|
+
schema: Schema
|
|
38
|
+
): BSchema {
|
|
39
|
+
return getBlockNoteSchema(schema).blockSchema as BSchema;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getInlineContentSchema<I extends InlineContentSchema>(
|
|
43
|
+
schema: Schema
|
|
44
|
+
): I {
|
|
45
|
+
return getBlockNoteSchema(schema).inlineContentSchema as I;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getStyleSchema<S extends StyleSchema>(schema: Schema): S {
|
|
49
|
+
return getBlockNoteSchema(schema).styleSchema as S;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function getBlockCache(schema: Schema) {
|
|
53
|
+
return getBlockNoteEditor(schema).blockCache;
|
|
54
|
+
}
|