@blocknote/core 0.28.0 → 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 +9 -9
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +3221 -3351
- package/dist/blocknote.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.ts +4 -2
- 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 -131
- 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 +22 -19
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +8 -8
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +150 -136
- 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/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/clipboardExternal.test.d.ts +0 -1
- 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
|
@@ -22,8 +22,7 @@ import {
|
|
|
22
22
|
nestBlock,
|
|
23
23
|
unnestBlock,
|
|
24
24
|
} from "../api/blockManipulation/commands/nestBlock/nestBlock.js";
|
|
25
|
-
import {
|
|
26
|
-
import { replaceBlocks } from "../api/blockManipulation/commands/replaceBlocks/replaceBlocks.js";
|
|
25
|
+
import { removeAndInsertBlocks } from "../api/blockManipulation/commands/replaceBlocks/replaceBlocks.js";
|
|
27
26
|
import { updateBlock } from "../api/blockManipulation/commands/updateBlock/updateBlock.js";
|
|
28
27
|
import {
|
|
29
28
|
getBlock,
|
|
@@ -94,18 +93,27 @@ import {
|
|
|
94
93
|
import { Dictionary } from "../i18n/dictionary.js";
|
|
95
94
|
import { en } from "../i18n/locales/index.js";
|
|
96
95
|
|
|
97
|
-
import {
|
|
96
|
+
import {
|
|
97
|
+
TextSelection,
|
|
98
|
+
type Command,
|
|
99
|
+
type Plugin,
|
|
100
|
+
type Transaction,
|
|
101
|
+
} from "@tiptap/pm/state";
|
|
98
102
|
import { dropCursor } from "prosemirror-dropcursor";
|
|
99
103
|
import { EditorView } from "prosemirror-view";
|
|
100
104
|
import { ySyncPluginKey } from "y-prosemirror";
|
|
101
105
|
import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer.js";
|
|
102
106
|
import { inlineContentToNodes } from "../api/nodeConversions/blockToNode.js";
|
|
103
107
|
import { nodeToBlock } from "../api/nodeConversions/nodeToBlock.js";
|
|
108
|
+
import {
|
|
109
|
+
BlocksChanged,
|
|
110
|
+
getBlocksChangedByTransaction,
|
|
111
|
+
} from "../api/nodeUtil.js";
|
|
112
|
+
import { nestedListsToBlockNoteStructure } from "../api/parsers/html/util/nestedLists.js";
|
|
113
|
+
import { CodeBlockOptions } from "../blocks/CodeBlockContent/CodeBlockContent.js";
|
|
104
114
|
import type { ThreadStore, User } from "../comments/index.js";
|
|
105
115
|
import "../style.css";
|
|
106
116
|
import { EventEmitter } from "../util/EventEmitter.js";
|
|
107
|
-
import { CodeBlockOptions } from "../blocks/CodeBlockContent/CodeBlockContent.js";
|
|
108
|
-
import { nestedListsToBlockNoteStructure } from "../api/parsers/html/util/nestedLists.js";
|
|
109
117
|
|
|
110
118
|
export type BlockNoteExtensionFactory = (
|
|
111
119
|
editor: BlockNoteEditor<any, any, any>
|
|
@@ -117,6 +125,12 @@ export type BlockNoteExtension =
|
|
|
117
125
|
plugin: Plugin;
|
|
118
126
|
};
|
|
119
127
|
|
|
128
|
+
export type BlockCache<
|
|
129
|
+
BSchema extends BlockSchema = any,
|
|
130
|
+
ISchema extends InlineContentSchema = any,
|
|
131
|
+
SSchema extends StyleSchema = any
|
|
132
|
+
> = WeakMap<Node, Block<BSchema, ISchema, SSchema>>;
|
|
133
|
+
|
|
120
134
|
export type BlockNoteEditorOptions<
|
|
121
135
|
BSchema extends BlockSchema,
|
|
122
136
|
ISchema extends InlineContentSchema,
|
|
@@ -416,7 +430,7 @@ export class BlockNoteEditor<
|
|
|
416
430
|
* This is especially useful when we want to keep track of the same block across multiple operations,
|
|
417
431
|
* with this cache, blocks stay the same object reference (referential equality with ===).
|
|
418
432
|
*/
|
|
419
|
-
public blockCache = new WeakMap
|
|
433
|
+
public blockCache: BlockCache = new WeakMap();
|
|
420
434
|
|
|
421
435
|
/**
|
|
422
436
|
* The dictionary contains translations for the editor.
|
|
@@ -723,13 +737,127 @@ export class BlockNoteEditor<
|
|
|
723
737
|
// but we still need the schema
|
|
724
738
|
this.pmSchema = getSchema(tiptapOptions.extensions!);
|
|
725
739
|
}
|
|
726
|
-
|
|
740
|
+
this.pmSchema.cached.blockNoteEditor = this;
|
|
727
741
|
this.emit("create");
|
|
728
742
|
}
|
|
729
743
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
744
|
+
/**
|
|
745
|
+
* Stores the currently active transaction, which is the accumulated transaction from all {@link dispatch} calls during a {@link transact} calls
|
|
746
|
+
*/
|
|
747
|
+
private activeTransaction: Transaction | null = null;
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Execute a prosemirror command. This is mostly for backwards compatibility with older code.
|
|
751
|
+
*
|
|
752
|
+
* @note You should prefer the {@link transact} method when possible, as it will automatically handle the dispatching of the transaction and work across blocknote transactions.
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* ```ts
|
|
756
|
+
* editor.exec((state, dispatch, view) => {
|
|
757
|
+
* dispatch(state.tr.insertText("Hello, world!"));
|
|
758
|
+
* });
|
|
759
|
+
* ```
|
|
760
|
+
*/
|
|
761
|
+
public exec(command: Command) {
|
|
762
|
+
if (this.activeTransaction) {
|
|
763
|
+
throw new Error(
|
|
764
|
+
"`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call"
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
const state = this._tiptapEditor.state;
|
|
768
|
+
const view = this._tiptapEditor.view;
|
|
769
|
+
const dispatch = (tr: Transaction) => this._tiptapEditor.dispatch(tr);
|
|
770
|
+
|
|
771
|
+
return command(state, dispatch, view);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Check if a command can be executed. A command should return `false` if it is not valid in the current state.
|
|
776
|
+
*
|
|
777
|
+
* @example
|
|
778
|
+
* ```ts
|
|
779
|
+
* if (editor.canExec(command)) {
|
|
780
|
+
* // show button
|
|
781
|
+
* } else {
|
|
782
|
+
* // hide button
|
|
783
|
+
* }
|
|
784
|
+
* ```
|
|
785
|
+
*/
|
|
786
|
+
public canExec(command: Command): boolean {
|
|
787
|
+
if (this.activeTransaction) {
|
|
788
|
+
throw new Error(
|
|
789
|
+
"`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call"
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
const state = this._tiptapEditor.state;
|
|
793
|
+
const view = this._tiptapEditor.view;
|
|
794
|
+
|
|
795
|
+
return command(state, undefined, view);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Execute a function within a "blocknote transaction".
|
|
800
|
+
* All changes to the editor within the transaction will be grouped together, so that
|
|
801
|
+
* we can dispatch them as a single operation (thus creating only a single undo step)
|
|
802
|
+
*
|
|
803
|
+
* @note There is no need to dispatch the transaction, as it will be automatically dispatched when the callback is complete.
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* ```ts
|
|
807
|
+
* // All changes to the editor will be grouped together
|
|
808
|
+
* editor.transact((tr) => {
|
|
809
|
+
* tr.insertText("Hello, world!");
|
|
810
|
+
* // These two operations will be grouped together in a single undo step
|
|
811
|
+
* editor.transact((tr) => {
|
|
812
|
+
* tr.insertText("Hello, world!");
|
|
813
|
+
* });
|
|
814
|
+
* });
|
|
815
|
+
* ```
|
|
816
|
+
*/
|
|
817
|
+
public transact<T>(
|
|
818
|
+
callback: (
|
|
819
|
+
/**
|
|
820
|
+
* The current active transaction, this will automatically be dispatched to the editor when the callback is complete
|
|
821
|
+
* If another `transact` call is made within the callback, it will be passed the same transaction as the parent call.
|
|
822
|
+
*/
|
|
823
|
+
tr: Transaction
|
|
824
|
+
) => T
|
|
825
|
+
): T {
|
|
826
|
+
if (this.activeTransaction) {
|
|
827
|
+
// Already in a transaction, so we can just callback immediately
|
|
828
|
+
return callback(this.activeTransaction);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
try {
|
|
832
|
+
// Enter transaction mode, by setting a starting transaction
|
|
833
|
+
this.activeTransaction = this._tiptapEditor.state.tr;
|
|
834
|
+
|
|
835
|
+
// Capture all dispatch'd transactions
|
|
836
|
+
const result = callback(this.activeTransaction);
|
|
837
|
+
|
|
838
|
+
// Any transactions captured by the `dispatch` call will be stored in `this.activeTransaction`
|
|
839
|
+
const activeTr = this.activeTransaction;
|
|
840
|
+
|
|
841
|
+
this.activeTransaction = null;
|
|
842
|
+
if (
|
|
843
|
+
activeTr &&
|
|
844
|
+
// Only dispatch if the transaction was actually modified in some way
|
|
845
|
+
(activeTr.docChanged ||
|
|
846
|
+
activeTr.selectionSet ||
|
|
847
|
+
activeTr.scrolledIntoView ||
|
|
848
|
+
activeTr.storedMarksSet ||
|
|
849
|
+
!activeTr.isGeneric)
|
|
850
|
+
) {
|
|
851
|
+
// Dispatch the transaction if it was modified
|
|
852
|
+
this._tiptapEditor.dispatch(activeTr);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
return result;
|
|
856
|
+
} finally {
|
|
857
|
+
// We wrap this in a finally block to ensure we don't disable future transactions just because of an error in the callback
|
|
858
|
+
this.activeTransaction = null;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
733
861
|
|
|
734
862
|
/**
|
|
735
863
|
* Mount the editor to a parent DOM element. Call mount(undefined) to clean up
|
|
@@ -750,13 +878,6 @@ export class BlockNoteEditor<
|
|
|
750
878
|
return this._tiptapEditor.view;
|
|
751
879
|
}
|
|
752
880
|
|
|
753
|
-
/**
|
|
754
|
-
* Get the underlying prosemirror state
|
|
755
|
-
*/
|
|
756
|
-
public get prosemirrorState() {
|
|
757
|
-
return this._tiptapEditor.state;
|
|
758
|
-
}
|
|
759
|
-
|
|
760
881
|
public get domElement() {
|
|
761
882
|
return this.prosemirrorView?.dom as HTMLDivElement | undefined;
|
|
762
883
|
}
|
|
@@ -803,23 +924,17 @@ export class BlockNoteEditor<
|
|
|
803
924
|
* @returns A snapshot of all top-level (non-nested) blocks in the editor.
|
|
804
925
|
*/
|
|
805
926
|
public get document(): Block<BSchema, ISchema, SSchema>[] {
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
this.prosemirrorState.doc.firstChild!.descendants((node) => {
|
|
809
|
-
blocks.push(
|
|
810
|
-
nodeToBlock(
|
|
811
|
-
node,
|
|
812
|
-
this.schema.blockSchema,
|
|
813
|
-
this.schema.inlineContentSchema,
|
|
814
|
-
this.schema.styleSchema,
|
|
815
|
-
this.blockCache
|
|
816
|
-
)
|
|
817
|
-
);
|
|
927
|
+
return this.transact((tr) => {
|
|
928
|
+
const blocks: Block<BSchema, ISchema, SSchema>[] = [];
|
|
818
929
|
|
|
819
|
-
|
|
820
|
-
|
|
930
|
+
tr.doc.firstChild!.descendants((node) => {
|
|
931
|
+
blocks.push(nodeToBlock(node, this.pmSchema));
|
|
821
932
|
|
|
822
|
-
|
|
933
|
+
return false;
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
return blocks;
|
|
937
|
+
});
|
|
823
938
|
}
|
|
824
939
|
|
|
825
940
|
/**
|
|
@@ -832,7 +947,7 @@ export class BlockNoteEditor<
|
|
|
832
947
|
public getBlock(
|
|
833
948
|
blockIdentifier: BlockIdentifier
|
|
834
949
|
): Block<BSchema, ISchema, SSchema> | undefined {
|
|
835
|
-
return getBlock(
|
|
950
|
+
return this.transact((tr) => getBlock(tr.doc, blockIdentifier));
|
|
836
951
|
}
|
|
837
952
|
|
|
838
953
|
/**
|
|
@@ -847,7 +962,7 @@ export class BlockNoteEditor<
|
|
|
847
962
|
public getPrevBlock(
|
|
848
963
|
blockIdentifier: BlockIdentifier
|
|
849
964
|
): Block<BSchema, ISchema, SSchema> | undefined {
|
|
850
|
-
return getPrevBlock(
|
|
965
|
+
return this.transact((tr) => getPrevBlock(tr.doc, blockIdentifier));
|
|
851
966
|
}
|
|
852
967
|
|
|
853
968
|
/**
|
|
@@ -861,7 +976,7 @@ export class BlockNoteEditor<
|
|
|
861
976
|
public getNextBlock(
|
|
862
977
|
blockIdentifier: BlockIdentifier
|
|
863
978
|
): Block<BSchema, ISchema, SSchema> | undefined {
|
|
864
|
-
return getNextBlock(
|
|
979
|
+
return this.transact((tr) => getNextBlock(tr.doc, blockIdentifier));
|
|
865
980
|
}
|
|
866
981
|
|
|
867
982
|
/**
|
|
@@ -874,7 +989,7 @@ export class BlockNoteEditor<
|
|
|
874
989
|
public getParentBlock(
|
|
875
990
|
blockIdentifier: BlockIdentifier
|
|
876
991
|
): Block<BSchema, ISchema, SSchema> | undefined {
|
|
877
|
-
return getParentBlock(
|
|
992
|
+
return this.transact((tr) => getParentBlock(tr.doc, blockIdentifier));
|
|
878
993
|
}
|
|
879
994
|
|
|
880
995
|
/**
|
|
@@ -944,7 +1059,7 @@ export class BlockNoteEditor<
|
|
|
944
1059
|
ISchema,
|
|
945
1060
|
SSchema
|
|
946
1061
|
> {
|
|
947
|
-
return getTextCursorPosition(
|
|
1062
|
+
return this.transact((tr) => getTextCursorPosition(tr));
|
|
948
1063
|
}
|
|
949
1064
|
|
|
950
1065
|
/**
|
|
@@ -957,18 +1072,25 @@ export class BlockNoteEditor<
|
|
|
957
1072
|
targetBlock: BlockIdentifier,
|
|
958
1073
|
placement: "start" | "end" = "start"
|
|
959
1074
|
) {
|
|
960
|
-
|
|
1075
|
+
return this.transact((tr) =>
|
|
1076
|
+
setTextCursorPosition(tr, targetBlock, placement)
|
|
1077
|
+
);
|
|
961
1078
|
}
|
|
962
1079
|
|
|
963
1080
|
/**
|
|
964
1081
|
* Gets a snapshot of the current selection.
|
|
965
1082
|
*/
|
|
966
1083
|
public getSelection(): Selection<BSchema, ISchema, SSchema> | undefined {
|
|
967
|
-
return getSelection(
|
|
1084
|
+
return this.transact((tr) => getSelection(tr));
|
|
968
1085
|
}
|
|
969
1086
|
|
|
1087
|
+
/**
|
|
1088
|
+
* Sets the selection to a range of blocks.
|
|
1089
|
+
* @param startBlock The identifier of the block that should be the start of the selection.
|
|
1090
|
+
* @param endBlock The identifier of the block that should be the end of the selection.
|
|
1091
|
+
*/
|
|
970
1092
|
public setSelection(startBlock: BlockIdentifier, endBlock: BlockIdentifier) {
|
|
971
|
-
setSelection(
|
|
1093
|
+
return this.transact((tr) => setSelection(tr, startBlock, endBlock));
|
|
972
1094
|
}
|
|
973
1095
|
|
|
974
1096
|
/**
|
|
@@ -1017,7 +1139,9 @@ export class BlockNoteEditor<
|
|
|
1017
1139
|
referenceBlock: BlockIdentifier,
|
|
1018
1140
|
placement: "before" | "after" = "before"
|
|
1019
1141
|
) {
|
|
1020
|
-
return
|
|
1142
|
+
return this.transact((tr) =>
|
|
1143
|
+
insertBlocks(tr, blocksToInsert, referenceBlock, placement)
|
|
1144
|
+
);
|
|
1021
1145
|
}
|
|
1022
1146
|
|
|
1023
1147
|
/**
|
|
@@ -1031,7 +1155,7 @@ export class BlockNoteEditor<
|
|
|
1031
1155
|
blockToUpdate: BlockIdentifier,
|
|
1032
1156
|
update: PartialBlock<BSchema, ISchema, SSchema>
|
|
1033
1157
|
) {
|
|
1034
|
-
return updateBlock(
|
|
1158
|
+
return this.transact((tr) => updateBlock(tr, blockToUpdate, update));
|
|
1035
1159
|
}
|
|
1036
1160
|
|
|
1037
1161
|
/**
|
|
@@ -1039,7 +1163,9 @@ export class BlockNoteEditor<
|
|
|
1039
1163
|
* @param blocksToRemove An array of identifiers for existing blocks that should be removed.
|
|
1040
1164
|
*/
|
|
1041
1165
|
public removeBlocks(blocksToRemove: BlockIdentifier[]) {
|
|
1042
|
-
return
|
|
1166
|
+
return this.transact(
|
|
1167
|
+
(tr) => removeAndInsertBlocks(tr, blocksToRemove, []).removedBlocks
|
|
1168
|
+
);
|
|
1043
1169
|
}
|
|
1044
1170
|
|
|
1045
1171
|
/**
|
|
@@ -1053,7 +1179,9 @@ export class BlockNoteEditor<
|
|
|
1053
1179
|
blocksToRemove: BlockIdentifier[],
|
|
1054
1180
|
blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[]
|
|
1055
1181
|
) {
|
|
1056
|
-
return
|
|
1182
|
+
return this.transact((tr) =>
|
|
1183
|
+
removeAndInsertBlocks(tr, blocksToRemove, blocksToInsert)
|
|
1184
|
+
);
|
|
1057
1185
|
}
|
|
1058
1186
|
|
|
1059
1187
|
/**
|
|
@@ -1062,52 +1190,52 @@ export class BlockNoteEditor<
|
|
|
1062
1190
|
* @param content can be a string, or array of partial inline content elements
|
|
1063
1191
|
*/
|
|
1064
1192
|
public insertInlineContent(content: PartialInlineContent<ISchema, SSchema>) {
|
|
1065
|
-
const nodes = inlineContentToNodes(
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
this
|
|
1078
|
-
);
|
|
1193
|
+
const nodes = inlineContentToNodes(content, this.pmSchema);
|
|
1194
|
+
|
|
1195
|
+
this.transact((tr) => {
|
|
1196
|
+
insertContentAt(
|
|
1197
|
+
tr,
|
|
1198
|
+
{
|
|
1199
|
+
from: tr.selection.from,
|
|
1200
|
+
to: tr.selection.to,
|
|
1201
|
+
},
|
|
1202
|
+
nodes
|
|
1203
|
+
);
|
|
1204
|
+
});
|
|
1079
1205
|
}
|
|
1080
1206
|
|
|
1081
1207
|
/**
|
|
1082
1208
|
* Gets the active text styles at the text cursor position or at the end of the current selection if it's active.
|
|
1083
1209
|
*/
|
|
1084
1210
|
public getActiveStyles() {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1091
|
-
if (
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1211
|
+
return this.transact((tr) => {
|
|
1212
|
+
const styles: Styles<SSchema> = {};
|
|
1213
|
+
const marks = tr.selection.$to.marks();
|
|
1214
|
+
|
|
1215
|
+
for (const mark of marks) {
|
|
1216
|
+
const config = this.schema.styleSchema[mark.type.name];
|
|
1217
|
+
if (!config) {
|
|
1218
|
+
if (
|
|
1219
|
+
// Links are not considered styles in blocknote
|
|
1220
|
+
mark.type.name !== "link" &&
|
|
1221
|
+
// "blocknoteIgnore" tagged marks (such as comments) are also not considered BlockNote "styles"
|
|
1222
|
+
!mark.type.spec.blocknoteIgnore
|
|
1223
|
+
) {
|
|
1224
|
+
// eslint-disable-next-line no-console
|
|
1225
|
+
console.warn("mark not found in styleschema", mark.type.name);
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
1230
|
+
if (config.propSchema === "boolean") {
|
|
1231
|
+
(styles as any)[config.type] = true;
|
|
1232
|
+
} else {
|
|
1233
|
+
(styles as any)[config.type] = mark.attrs.stringValue;
|
|
1099
1234
|
}
|
|
1100
|
-
|
|
1101
|
-
continue;
|
|
1102
|
-
}
|
|
1103
|
-
if (config.propSchema === "boolean") {
|
|
1104
|
-
(styles as any)[config.type] = true;
|
|
1105
|
-
} else {
|
|
1106
|
-
(styles as any)[config.type] = mark.attrs.stringValue;
|
|
1107
1235
|
}
|
|
1108
|
-
}
|
|
1109
1236
|
|
|
1110
|
-
|
|
1237
|
+
return styles;
|
|
1238
|
+
});
|
|
1111
1239
|
}
|
|
1112
1240
|
|
|
1113
1241
|
/**
|
|
@@ -1164,10 +1292,9 @@ export class BlockNoteEditor<
|
|
|
1164
1292
|
* Gets the currently selected text.
|
|
1165
1293
|
*/
|
|
1166
1294
|
public getSelectedText() {
|
|
1167
|
-
return this.
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
);
|
|
1295
|
+
return this.transact((tr) => {
|
|
1296
|
+
return tr.doc.textBetween(tr.selection.from, tr.selection.to);
|
|
1297
|
+
});
|
|
1171
1298
|
}
|
|
1172
1299
|
|
|
1173
1300
|
/**
|
|
@@ -1186,21 +1313,20 @@ export class BlockNoteEditor<
|
|
|
1186
1313
|
if (url === "") {
|
|
1187
1314
|
return;
|
|
1188
1315
|
}
|
|
1189
|
-
|
|
1190
|
-
const { from, to } = this._tiptapEditor.state.selection;
|
|
1191
1316
|
const mark = this.pmSchema.mark("link", { href: url });
|
|
1317
|
+
this.transact((tr) => {
|
|
1318
|
+
const { from, to } = tr.selection;
|
|
1192
1319
|
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
);
|
|
1320
|
+
if (text) {
|
|
1321
|
+
tr.insertText(text, from, to).addMark(from, from + text.length, mark);
|
|
1322
|
+
} else {
|
|
1323
|
+
tr.setSelection(TextSelection.create(tr.doc, to)).addMark(
|
|
1324
|
+
from,
|
|
1325
|
+
to,
|
|
1326
|
+
mark
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1204
1330
|
}
|
|
1205
1331
|
|
|
1206
1332
|
/**
|
|
@@ -1237,7 +1363,7 @@ export class BlockNoteEditor<
|
|
|
1237
1363
|
* current blocks share a common parent, moves them out of & before it.
|
|
1238
1364
|
*/
|
|
1239
1365
|
public moveBlocksUp() {
|
|
1240
|
-
moveBlocksUp(this);
|
|
1366
|
+
return moveBlocksUp(this);
|
|
1241
1367
|
}
|
|
1242
1368
|
|
|
1243
1369
|
/**
|
|
@@ -1246,7 +1372,7 @@ export class BlockNoteEditor<
|
|
|
1246
1372
|
* current blocks share a common parent, moves them out of & after it.
|
|
1247
1373
|
*/
|
|
1248
1374
|
public moveBlocksDown() {
|
|
1249
|
-
moveBlocksDown(this);
|
|
1375
|
+
return moveBlocksDown(this);
|
|
1250
1376
|
}
|
|
1251
1377
|
|
|
1252
1378
|
/**
|
|
@@ -1288,13 +1414,7 @@ export class BlockNoteEditor<
|
|
|
1288
1414
|
public async tryParseHTMLToBlocks(
|
|
1289
1415
|
html: string
|
|
1290
1416
|
): Promise<Block<BSchema, ISchema, SSchema>[]> {
|
|
1291
|
-
return HTMLToBlocks(
|
|
1292
|
-
html,
|
|
1293
|
-
this.schema.blockSchema,
|
|
1294
|
-
this.schema.inlineContentSchema,
|
|
1295
|
-
this.schema.styleSchema,
|
|
1296
|
-
this.pmSchema
|
|
1297
|
-
);
|
|
1417
|
+
return HTMLToBlocks(html, this.pmSchema);
|
|
1298
1418
|
}
|
|
1299
1419
|
|
|
1300
1420
|
/**
|
|
@@ -1319,13 +1439,7 @@ export class BlockNoteEditor<
|
|
|
1319
1439
|
public async tryParseMarkdownToBlocks(
|
|
1320
1440
|
markdown: string
|
|
1321
1441
|
): Promise<Block<BSchema, ISchema, SSchema>[]> {
|
|
1322
|
-
return markdownToBlocks(
|
|
1323
|
-
markdown,
|
|
1324
|
-
this.schema.blockSchema,
|
|
1325
|
-
this.schema.inlineContentSchema,
|
|
1326
|
-
this.schema.styleSchema,
|
|
1327
|
-
this.pmSchema
|
|
1328
|
-
);
|
|
1442
|
+
return markdownToBlocks(markdown, this.pmSchema);
|
|
1329
1443
|
}
|
|
1330
1444
|
|
|
1331
1445
|
/**
|
|
@@ -1347,21 +1461,38 @@ export class BlockNoteEditor<
|
|
|
1347
1461
|
* @returns A function to remove the callback.
|
|
1348
1462
|
*/
|
|
1349
1463
|
public onChange(
|
|
1350
|
-
callback: (
|
|
1464
|
+
callback: (
|
|
1465
|
+
editor: BlockNoteEditor<BSchema, ISchema, SSchema>,
|
|
1466
|
+
context: {
|
|
1467
|
+
/**
|
|
1468
|
+
* Returns the blocks that were inserted, updated, or deleted by the change that occurred.
|
|
1469
|
+
*/
|
|
1470
|
+
getChanges(): BlocksChanged<BSchema, ISchema, SSchema>;
|
|
1471
|
+
}
|
|
1472
|
+
) => void
|
|
1351
1473
|
) {
|
|
1352
1474
|
if (this.headless) {
|
|
1353
1475
|
// Note: would be nice if this is possible in headless mode as well
|
|
1354
1476
|
return;
|
|
1355
1477
|
}
|
|
1356
1478
|
|
|
1357
|
-
const cb = (
|
|
1358
|
-
|
|
1479
|
+
const cb = ({
|
|
1480
|
+
transaction,
|
|
1481
|
+
appendedTransactions,
|
|
1482
|
+
}: {
|
|
1483
|
+
transaction: Transaction;
|
|
1484
|
+
appendedTransactions: Transaction[];
|
|
1485
|
+
}) => {
|
|
1486
|
+
callback(this, {
|
|
1487
|
+
getChanges: () =>
|
|
1488
|
+
getBlocksChangedByTransaction(transaction, appendedTransactions),
|
|
1489
|
+
});
|
|
1359
1490
|
};
|
|
1360
1491
|
|
|
1361
|
-
this._tiptapEditor.on("update", cb);
|
|
1492
|
+
this._tiptapEditor.on("v3-update", cb);
|
|
1362
1493
|
|
|
1363
1494
|
return () => {
|
|
1364
|
-
this._tiptapEditor.off("update", cb);
|
|
1495
|
+
this._tiptapEditor.off("v3-update", cb);
|
|
1365
1496
|
};
|
|
1366
1497
|
}
|
|
1367
1498
|
|
|
@@ -1452,24 +1583,21 @@ export class BlockNoteEditor<
|
|
|
1452
1583
|
ignoreQueryLength?: boolean;
|
|
1453
1584
|
}
|
|
1454
1585
|
) {
|
|
1455
|
-
|
|
1456
|
-
if (!tr) {
|
|
1586
|
+
if (!this.prosemirrorView) {
|
|
1457
1587
|
return;
|
|
1458
1588
|
}
|
|
1459
1589
|
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
this.prosemirrorView.dispatch(
|
|
1467
|
-
transaction.scrollIntoView().setMeta(this.suggestionMenus.plugin, {
|
|
1590
|
+
this.focus();
|
|
1591
|
+
this.transact((tr) => {
|
|
1592
|
+
if (pluginState?.deleteTriggerCharacter) {
|
|
1593
|
+
tr.insertText(triggerCharacter);
|
|
1594
|
+
}
|
|
1595
|
+
tr.scrollIntoView().setMeta(this.suggestionMenus.plugin, {
|
|
1468
1596
|
triggerCharacter: triggerCharacter,
|
|
1469
1597
|
deleteTriggerCharacter: pluginState?.deleteTriggerCharacter || false,
|
|
1470
1598
|
ignoreQueryLength: pluginState?.ignoreQueryLength || false,
|
|
1471
|
-
})
|
|
1472
|
-
);
|
|
1599
|
+
});
|
|
1600
|
+
});
|
|
1473
1601
|
}
|
|
1474
1602
|
|
|
1475
1603
|
// `forceSelectionVisible` determines whether the editor selection is shows
|