@blocknote/core 0.28.0 → 0.29.1
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
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { TextSelection } from "prosemirror-state";
|
|
1
|
+
import { TextSelection, type Transaction } from "prosemirror-state";
|
|
2
2
|
import { TableMap } from "prosemirror-tables";
|
|
3
3
|
|
|
4
4
|
import { Block } from "../../../blocks/defaultBlocks.js";
|
|
5
|
-
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
|
|
6
5
|
import { Selection } from "../../../editor/selectionTypes.js";
|
|
7
6
|
import {
|
|
8
7
|
BlockIdentifier,
|
|
@@ -13,26 +12,24 @@ import {
|
|
|
13
12
|
import { getBlockInfo, getNearestBlockPos } from "../../getBlockInfoFromPos.js";
|
|
14
13
|
import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
|
|
15
14
|
import { getNodeById } from "../../nodeUtil.js";
|
|
15
|
+
import { getBlockNoteSchema, getPmSchema } from "../../pmUtil.js";
|
|
16
16
|
|
|
17
17
|
export function getSelection<
|
|
18
18
|
BSchema extends BlockSchema,
|
|
19
19
|
I extends InlineContentSchema,
|
|
20
20
|
S extends StyleSchema
|
|
21
|
-
>(
|
|
22
|
-
|
|
23
|
-
): Selection<BSchema, I, S> | undefined {
|
|
24
|
-
const state = editor._tiptapEditor.state;
|
|
25
|
-
|
|
21
|
+
>(tr: Transaction): Selection<BSchema, I, S> | undefined {
|
|
22
|
+
const pmSchema = getPmSchema(tr);
|
|
26
23
|
// Return undefined if the selection is collapsed or a node is selected.
|
|
27
|
-
if (
|
|
24
|
+
if (tr.selection.empty || "node" in tr.selection) {
|
|
28
25
|
return undefined;
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
const $startBlockBeforePos =
|
|
32
|
-
getNearestBlockPos(
|
|
28
|
+
const $startBlockBeforePos = tr.doc.resolve(
|
|
29
|
+
getNearestBlockPos(tr.doc, tr.selection.from).posBeforeNode
|
|
33
30
|
);
|
|
34
|
-
const $endBlockBeforePos =
|
|
35
|
-
getNearestBlockPos(
|
|
31
|
+
const $endBlockBeforePos = tr.doc.resolve(
|
|
32
|
+
getNearestBlockPos(tr.doc, tr.selection.to).posBeforeNode
|
|
36
33
|
);
|
|
37
34
|
|
|
38
35
|
// Converts the node at the given index and depth around `$startBlockBeforePos`
|
|
@@ -43,7 +40,7 @@ export function getSelection<
|
|
|
43
40
|
depth?: number
|
|
44
41
|
): Block<BSchema, I, S> => {
|
|
45
42
|
const pos = $startBlockBeforePos.posAtIndex(index, depth);
|
|
46
|
-
const node =
|
|
43
|
+
const node = tr.doc.resolve(pos).nodeAfter;
|
|
47
44
|
|
|
48
45
|
if (!node) {
|
|
49
46
|
throw new Error(
|
|
@@ -51,13 +48,7 @@ export function getSelection<
|
|
|
51
48
|
);
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
return nodeToBlock(
|
|
55
|
-
node,
|
|
56
|
-
editor.schema.blockSchema,
|
|
57
|
-
editor.schema.inlineContentSchema,
|
|
58
|
-
editor.schema.styleSchema,
|
|
59
|
-
editor.blockCache
|
|
60
|
-
);
|
|
51
|
+
return nodeToBlock(node, pmSchema);
|
|
61
52
|
};
|
|
62
53
|
|
|
63
54
|
const blocks: Block<BSchema, I, S>[] = [];
|
|
@@ -98,15 +89,7 @@ export function getSelection<
|
|
|
98
89
|
// [ id-2, id-3, id-4, id-6, id-7, id-8, id-9 ]
|
|
99
90
|
if ($startBlockBeforePos.depth > sharedDepth) {
|
|
100
91
|
// Adds the block that the selection starts in.
|
|
101
|
-
blocks.push(
|
|
102
|
-
nodeToBlock(
|
|
103
|
-
$startBlockBeforePos.nodeAfter!,
|
|
104
|
-
editor.schema.blockSchema,
|
|
105
|
-
editor.schema.inlineContentSchema,
|
|
106
|
-
editor.schema.styleSchema,
|
|
107
|
-
editor.blockCache
|
|
108
|
-
)
|
|
109
|
-
);
|
|
92
|
+
blocks.push(nodeToBlock($startBlockBeforePos.nodeAfter!, pmSchema));
|
|
110
93
|
|
|
111
94
|
// Traverses all depths from the depth of the block in which the selection
|
|
112
95
|
// starts, up to the shared depth.
|
|
@@ -137,7 +120,7 @@ export function getSelection<
|
|
|
137
120
|
|
|
138
121
|
if (blocks.length === 0) {
|
|
139
122
|
throw new Error(
|
|
140
|
-
`Error getting selection - selection doesn't span any blocks (${
|
|
123
|
+
`Error getting selection - selection doesn't span any blocks (${tr.selection})`
|
|
141
124
|
);
|
|
142
125
|
}
|
|
143
126
|
|
|
@@ -146,32 +129,27 @@ export function getSelection<
|
|
|
146
129
|
};
|
|
147
130
|
}
|
|
148
131
|
|
|
149
|
-
export function setSelection
|
|
150
|
-
|
|
151
|
-
I extends InlineContentSchema,
|
|
152
|
-
S extends StyleSchema
|
|
153
|
-
>(
|
|
154
|
-
editor: BlockNoteEditor<BSchema, I, S>,
|
|
132
|
+
export function setSelection(
|
|
133
|
+
tr: Transaction,
|
|
155
134
|
startBlock: BlockIdentifier,
|
|
156
135
|
endBlock: BlockIdentifier
|
|
157
136
|
) {
|
|
158
137
|
const startBlockId =
|
|
159
138
|
typeof startBlock === "string" ? startBlock : startBlock.id;
|
|
160
139
|
const endBlockId = typeof endBlock === "string" ? endBlock : endBlock.id;
|
|
140
|
+
const pmSchema = getPmSchema(tr);
|
|
141
|
+
const schema = getBlockNoteSchema(pmSchema);
|
|
161
142
|
|
|
162
143
|
if (startBlockId === endBlockId) {
|
|
163
144
|
throw new Error(
|
|
164
145
|
`Attempting to set selection with the same anchor and head blocks (id ${startBlockId})`
|
|
165
146
|
);
|
|
166
147
|
}
|
|
167
|
-
|
|
168
|
-
const doc = editor._tiptapEditor.state.doc;
|
|
169
|
-
|
|
170
|
-
const anchorPosInfo = getNodeById(startBlockId, doc);
|
|
148
|
+
const anchorPosInfo = getNodeById(startBlockId, tr.doc);
|
|
171
149
|
if (!anchorPosInfo) {
|
|
172
150
|
throw new Error(`Block with ID ${startBlockId} not found`);
|
|
173
151
|
}
|
|
174
|
-
const headPosInfo = getNodeById(endBlockId, doc);
|
|
152
|
+
const headPosInfo = getNodeById(endBlockId, tr.doc);
|
|
175
153
|
if (!headPosInfo) {
|
|
176
154
|
throw new Error(`Block with ID ${endBlockId} not found`);
|
|
177
155
|
}
|
|
@@ -180,12 +158,12 @@ export function setSelection<
|
|
|
180
158
|
const headBlockInfo = getBlockInfo(headPosInfo);
|
|
181
159
|
|
|
182
160
|
const anchorBlockConfig =
|
|
183
|
-
|
|
184
|
-
anchorBlockInfo.blockNoteType as keyof typeof
|
|
161
|
+
schema.blockSchema[
|
|
162
|
+
anchorBlockInfo.blockNoteType as keyof typeof schema.blockSchema
|
|
185
163
|
];
|
|
186
164
|
const headBlockConfig =
|
|
187
|
-
|
|
188
|
-
headBlockInfo.blockNoteType as keyof typeof
|
|
165
|
+
schema.blockSchema[
|
|
166
|
+
headBlockInfo.blockNoteType as keyof typeof schema.blockSchema
|
|
189
167
|
];
|
|
190
168
|
|
|
191
169
|
if (
|
|
@@ -226,7 +204,7 @@ export function setSelection<
|
|
|
226
204
|
headBlockInfo.blockContent.node
|
|
227
205
|
) +
|
|
228
206
|
1;
|
|
229
|
-
const lastCellNodeSize = doc.resolve(lastCellPos).nodeAfter!.nodeSize;
|
|
207
|
+
const lastCellNodeSize = tr.doc.resolve(lastCellPos).nodeAfter!.nodeSize;
|
|
230
208
|
endPos = lastCellPos + lastCellNodeSize - 2;
|
|
231
209
|
} else {
|
|
232
210
|
endPos = headBlockInfo.blockContent.afterPos - 1;
|
|
@@ -236,9 +214,5 @@ export function setSelection<
|
|
|
236
214
|
// Right now it's missing a few things like a jsonID and styling to show
|
|
237
215
|
// which nodes are selected. `TextSelection` is ok for now, but has the
|
|
238
216
|
// restriction that the start/end blocks must have content.
|
|
239
|
-
|
|
240
|
-
editor._tiptapEditor.state.tr.setSelection(
|
|
241
|
-
TextSelection.create(editor._tiptapEditor.state.doc, startPos, endPos)
|
|
242
|
-
)
|
|
243
|
-
);
|
|
217
|
+
tr.setSelection(TextSelection.create(tr.doc, startPos, endPos));
|
|
244
218
|
}
|
|
@@ -10,44 +10,65 @@ const getEditor = setupTestEnv();
|
|
|
10
10
|
|
|
11
11
|
describe("Test getTextCursorPosition & setTextCursorPosition", () => {
|
|
12
12
|
it("Basic", () => {
|
|
13
|
-
|
|
13
|
+
getEditor().transact((tr) => {
|
|
14
|
+
setTextCursorPosition(tr, "paragraph-1");
|
|
15
|
+
});
|
|
14
16
|
|
|
15
|
-
expect(
|
|
17
|
+
expect(
|
|
18
|
+
getEditor().transact((tr) => getTextCursorPosition(tr))
|
|
19
|
+
).toMatchSnapshot();
|
|
16
20
|
});
|
|
17
21
|
|
|
18
22
|
it("First block", () => {
|
|
19
|
-
|
|
23
|
+
getEditor().transact((tr) => {
|
|
24
|
+
setTextCursorPosition(tr, "paragraph-0");
|
|
25
|
+
});
|
|
20
26
|
|
|
21
|
-
expect(
|
|
27
|
+
expect(
|
|
28
|
+
getEditor().transact((tr) => getTextCursorPosition(tr))
|
|
29
|
+
).toMatchSnapshot();
|
|
22
30
|
});
|
|
23
31
|
|
|
24
32
|
it("Last block", () => {
|
|
25
|
-
|
|
33
|
+
getEditor().transact((tr) => {
|
|
34
|
+
setTextCursorPosition(tr, "trailing-paragraph");
|
|
35
|
+
});
|
|
26
36
|
|
|
27
|
-
expect(
|
|
37
|
+
expect(
|
|
38
|
+
getEditor().transact((tr) => getTextCursorPosition(tr))
|
|
39
|
+
).toMatchSnapshot();
|
|
28
40
|
});
|
|
29
41
|
|
|
30
42
|
it("Nested block", () => {
|
|
31
|
-
|
|
43
|
+
getEditor().transact((tr) => {
|
|
44
|
+
setTextCursorPosition(tr, "nested-paragraph-0");
|
|
45
|
+
});
|
|
32
46
|
|
|
33
|
-
expect(
|
|
47
|
+
expect(
|
|
48
|
+
getEditor().transact((tr) => getTextCursorPosition(tr))
|
|
49
|
+
).toMatchSnapshot();
|
|
34
50
|
});
|
|
35
51
|
|
|
36
52
|
it("Set to start", () => {
|
|
37
|
-
|
|
53
|
+
getEditor().transact((tr) => {
|
|
54
|
+
setTextCursorPosition(tr, "paragraph-1", "start");
|
|
55
|
+
});
|
|
38
56
|
|
|
39
57
|
expect(
|
|
40
|
-
getEditor().
|
|
58
|
+
getEditor().transact((tr) => tr.selection.$from.parentOffset) === 0
|
|
41
59
|
).toBeTruthy();
|
|
42
60
|
});
|
|
43
61
|
|
|
44
62
|
it("Set to end", () => {
|
|
45
|
-
|
|
63
|
+
getEditor().transact((tr) => {
|
|
64
|
+
setTextCursorPosition(tr, "paragraph-1", "end");
|
|
65
|
+
});
|
|
46
66
|
|
|
47
67
|
expect(
|
|
48
|
-
getEditor().
|
|
49
|
-
getEditor().
|
|
50
|
-
.nodeSize
|
|
68
|
+
getEditor().transact((tr) => tr.selection.$from.parentOffset) ===
|
|
69
|
+
getEditor().transact(
|
|
70
|
+
(tr) => tr.selection.$from.node().firstChild!.nodeSize
|
|
71
|
+
)
|
|
51
72
|
).toBeTruthy();
|
|
52
73
|
});
|
|
53
74
|
});
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { Node } from "prosemirror-model";
|
|
2
|
-
|
|
3
|
-
import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
|
|
4
|
-
import { TextCursorPosition } from "../../../../editor/cursorPositionTypes.js";
|
|
1
|
+
import type { Node } from "prosemirror-model";
|
|
5
2
|
import {
|
|
3
|
+
NodeSelection,
|
|
4
|
+
TextSelection,
|
|
5
|
+
type Transaction,
|
|
6
|
+
} from "prosemirror-state";
|
|
7
|
+
import type { TextCursorPosition } from "../../../../editor/cursorPositionTypes.js";
|
|
8
|
+
import type {
|
|
6
9
|
BlockIdentifier,
|
|
7
10
|
BlockSchema,
|
|
8
11
|
InlineContentSchema,
|
|
@@ -11,26 +14,26 @@ import {
|
|
|
11
14
|
import { UnreachableCaseError } from "../../../../util/typescript.js";
|
|
12
15
|
import {
|
|
13
16
|
getBlockInfo,
|
|
14
|
-
|
|
17
|
+
getBlockInfoFromTransaction,
|
|
15
18
|
} from "../../../getBlockInfoFromPos.js";
|
|
16
19
|
import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js";
|
|
17
20
|
import { getNodeById } from "../../../nodeUtil.js";
|
|
21
|
+
import { getBlockNoteSchema, getPmSchema } from "../../../pmUtil.js";
|
|
18
22
|
|
|
19
23
|
export function getTextCursorPosition<
|
|
20
24
|
BSchema extends BlockSchema,
|
|
21
25
|
I extends InlineContentSchema,
|
|
22
26
|
S extends StyleSchema
|
|
23
|
-
>(
|
|
24
|
-
const { bnBlock } =
|
|
27
|
+
>(tr: Transaction): TextCursorPosition<BSchema, I, S> {
|
|
28
|
+
const { bnBlock } = getBlockInfoFromTransaction(tr);
|
|
29
|
+
const pmSchema = getPmSchema(tr.doc);
|
|
25
30
|
|
|
26
|
-
const resolvedPos =
|
|
31
|
+
const resolvedPos = tr.doc.resolve(bnBlock.beforePos);
|
|
27
32
|
// Gets previous blockContainer node at the same nesting level, if the current node isn't the first child.
|
|
28
33
|
const prevNode = resolvedPos.nodeBefore;
|
|
29
34
|
|
|
30
35
|
// Gets next blockContainer node at the same nesting level, if the current node isn't the last child.
|
|
31
|
-
const nextNode =
|
|
32
|
-
bnBlock.afterPos
|
|
33
|
-
).nodeAfter;
|
|
36
|
+
const nextNode = tr.doc.resolve(bnBlock.afterPos).nodeAfter;
|
|
34
37
|
|
|
35
38
|
// Gets parent blockContainer node, if the current node is nested.
|
|
36
39
|
let parentNode: Node | undefined = undefined;
|
|
@@ -44,58 +47,24 @@ export function getTextCursorPosition<
|
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
return {
|
|
47
|
-
block: nodeToBlock(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
editor.schema.inlineContentSchema,
|
|
51
|
-
editor.schema.styleSchema,
|
|
52
|
-
editor.blockCache
|
|
53
|
-
),
|
|
54
|
-
prevBlock:
|
|
55
|
-
prevNode === null
|
|
56
|
-
? undefined
|
|
57
|
-
: nodeToBlock(
|
|
58
|
-
prevNode,
|
|
59
|
-
editor.schema.blockSchema,
|
|
60
|
-
editor.schema.inlineContentSchema,
|
|
61
|
-
editor.schema.styleSchema,
|
|
62
|
-
editor.blockCache
|
|
63
|
-
),
|
|
64
|
-
nextBlock:
|
|
65
|
-
nextNode === null
|
|
66
|
-
? undefined
|
|
67
|
-
: nodeToBlock(
|
|
68
|
-
nextNode,
|
|
69
|
-
editor.schema.blockSchema,
|
|
70
|
-
editor.schema.inlineContentSchema,
|
|
71
|
-
editor.schema.styleSchema,
|
|
72
|
-
editor.blockCache
|
|
73
|
-
),
|
|
50
|
+
block: nodeToBlock(bnBlock.node, pmSchema),
|
|
51
|
+
prevBlock: prevNode === null ? undefined : nodeToBlock(prevNode, pmSchema),
|
|
52
|
+
nextBlock: nextNode === null ? undefined : nodeToBlock(nextNode, pmSchema),
|
|
74
53
|
parentBlock:
|
|
75
|
-
parentNode === undefined
|
|
76
|
-
? undefined
|
|
77
|
-
: nodeToBlock(
|
|
78
|
-
parentNode,
|
|
79
|
-
editor.schema.blockSchema,
|
|
80
|
-
editor.schema.inlineContentSchema,
|
|
81
|
-
editor.schema.styleSchema,
|
|
82
|
-
editor.blockCache
|
|
83
|
-
),
|
|
54
|
+
parentNode === undefined ? undefined : nodeToBlock(parentNode, pmSchema),
|
|
84
55
|
};
|
|
85
56
|
}
|
|
86
57
|
|
|
87
|
-
export function setTextCursorPosition
|
|
88
|
-
|
|
89
|
-
I extends InlineContentSchema,
|
|
90
|
-
S extends StyleSchema
|
|
91
|
-
>(
|
|
92
|
-
editor: BlockNoteEditor<BSchema, I, S>,
|
|
58
|
+
export function setTextCursorPosition(
|
|
59
|
+
tr: Transaction,
|
|
93
60
|
targetBlock: BlockIdentifier,
|
|
94
61
|
placement: "start" | "end" = "start"
|
|
95
62
|
) {
|
|
96
63
|
const id = typeof targetBlock === "string" ? targetBlock : targetBlock.id;
|
|
64
|
+
const pmSchema = getPmSchema(tr.doc);
|
|
65
|
+
const schema = getBlockNoteSchema(pmSchema);
|
|
97
66
|
|
|
98
|
-
const posInfo = getNodeById(id,
|
|
67
|
+
const posInfo = getNodeById(id, tr.doc);
|
|
99
68
|
if (!posInfo) {
|
|
100
69
|
throw new Error(`Block with ID ${id} not found`);
|
|
101
70
|
}
|
|
@@ -103,23 +72,23 @@ export function setTextCursorPosition<
|
|
|
103
72
|
const info = getBlockInfo(posInfo);
|
|
104
73
|
|
|
105
74
|
const contentType: "none" | "inline" | "table" =
|
|
106
|
-
|
|
75
|
+
schema.blockSchema[info.blockNoteType]!.content;
|
|
107
76
|
|
|
108
77
|
if (info.isBlockContainer) {
|
|
109
78
|
const blockContent = info.blockContent;
|
|
110
79
|
if (contentType === "none") {
|
|
111
|
-
|
|
80
|
+
tr.setSelection(NodeSelection.create(tr.doc, blockContent.beforePos));
|
|
112
81
|
return;
|
|
113
82
|
}
|
|
114
83
|
|
|
115
84
|
if (contentType === "inline") {
|
|
116
85
|
if (placement === "start") {
|
|
117
|
-
|
|
118
|
-
blockContent.beforePos + 1
|
|
86
|
+
tr.setSelection(
|
|
87
|
+
TextSelection.create(tr.doc, blockContent.beforePos + 1)
|
|
119
88
|
);
|
|
120
89
|
} else {
|
|
121
|
-
|
|
122
|
-
blockContent.afterPos - 1
|
|
90
|
+
tr.setSelection(
|
|
91
|
+
TextSelection.create(tr.doc, blockContent.afterPos - 1)
|
|
123
92
|
);
|
|
124
93
|
}
|
|
125
94
|
} else if (contentType === "table") {
|
|
@@ -127,12 +96,12 @@ export function setTextCursorPosition<
|
|
|
127
96
|
// Need to offset the position as we have to get through the `tableRow`
|
|
128
97
|
// and `tableCell` nodes to get to the `tableParagraph` node we want to
|
|
129
98
|
// set the selection in.
|
|
130
|
-
|
|
131
|
-
blockContent.beforePos + 4
|
|
99
|
+
tr.setSelection(
|
|
100
|
+
TextSelection.create(tr.doc, blockContent.beforePos + 4)
|
|
132
101
|
);
|
|
133
102
|
} else {
|
|
134
|
-
|
|
135
|
-
blockContent.afterPos - 4
|
|
103
|
+
tr.setSelection(
|
|
104
|
+
TextSelection.create(tr.doc, blockContent.afterPos - 4)
|
|
136
105
|
);
|
|
137
106
|
}
|
|
138
107
|
} else {
|
|
@@ -144,6 +113,6 @@ export function setTextCursorPosition<
|
|
|
144
113
|
? info.childContainer.node.firstChild!
|
|
145
114
|
: info.childContainer.node.lastChild!;
|
|
146
115
|
|
|
147
|
-
setTextCursorPosition(
|
|
116
|
+
setTextCursorPosition(tr, child.attrs.id, placement);
|
|
148
117
|
}
|
|
149
118
|
}
|
|
@@ -160,16 +160,14 @@ export async function handleFileInsertion<
|
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
fileBlock
|
|
172
|
-
);
|
|
163
|
+
insertedBlockId = editor.transact((tr) => {
|
|
164
|
+
const posInfo = getNearestBlockPos(tr.doc, pos.pos);
|
|
165
|
+
return insertOrUpdateBlock(
|
|
166
|
+
editor,
|
|
167
|
+
editor.getBlock(posInfo.node.attrs.id)!,
|
|
168
|
+
fileBlock
|
|
169
|
+
);
|
|
170
|
+
});
|
|
173
171
|
} else {
|
|
174
172
|
return;
|
|
175
173
|
}
|
|
@@ -94,7 +94,7 @@ function fragmentToExternalHTML<
|
|
|
94
94
|
);
|
|
95
95
|
externalHTML = externalHTMLExporter.exportInlineContent(ic, {});
|
|
96
96
|
} else {
|
|
97
|
-
const blocks = fragmentToBlocks(selectedFragment
|
|
97
|
+
const blocks = fragmentToBlocks(selectedFragment);
|
|
98
98
|
externalHTML = externalHTMLExporter.exportBlocks(blocks, {});
|
|
99
99
|
}
|
|
100
100
|
return externalHTML;
|
|
@@ -120,9 +120,9 @@ export function selectedFragmentToHTML<
|
|
|
120
120
|
"node" in view.state.selection &&
|
|
121
121
|
(view.state.selection.node as Node).type.spec.group === "blockContent"
|
|
122
122
|
) {
|
|
123
|
-
editor.
|
|
124
|
-
|
|
125
|
-
new NodeSelection(
|
|
123
|
+
editor.transact((tr) =>
|
|
124
|
+
tr.setSelection(
|
|
125
|
+
new NodeSelection(tr.doc.resolve(view.state.selection.from - 1))
|
|
126
126
|
)
|
|
127
127
|
);
|
|
128
128
|
}
|
|
@@ -251,10 +251,10 @@ export const createCopyToClipboardExtension = <
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
// Expands the selection to the parent `blockContainer` node.
|
|
254
|
-
editor.
|
|
255
|
-
|
|
254
|
+
editor.transact((tr) =>
|
|
255
|
+
tr.setSelection(
|
|
256
256
|
new NodeSelection(
|
|
257
|
-
|
|
257
|
+
tr.doc.resolve(view.state.selection.from - 1)
|
|
258
258
|
)
|
|
259
259
|
)
|
|
260
260
|
);
|
|
@@ -43,23 +43,11 @@ export function serializeInlineContentExternalHTML<
|
|
|
43
43
|
if (!blockContent) {
|
|
44
44
|
throw new Error("blockContent is required");
|
|
45
45
|
} else if (typeof blockContent === "string") {
|
|
46
|
-
nodes = inlineContentToNodes(
|
|
47
|
-
[blockContent],
|
|
48
|
-
editor.pmSchema,
|
|
49
|
-
editor.schema.styleSchema
|
|
50
|
-
);
|
|
46
|
+
nodes = inlineContentToNodes([blockContent], editor.pmSchema);
|
|
51
47
|
} else if (Array.isArray(blockContent)) {
|
|
52
|
-
nodes = inlineContentToNodes(
|
|
53
|
-
blockContent,
|
|
54
|
-
editor.pmSchema,
|
|
55
|
-
editor.schema.styleSchema
|
|
56
|
-
);
|
|
48
|
+
nodes = inlineContentToNodes(blockContent, editor.pmSchema);
|
|
57
49
|
} else if (blockContent.type === "tableContent") {
|
|
58
|
-
nodes = tableContentToNodes(
|
|
59
|
-
blockContent,
|
|
60
|
-
editor.pmSchema,
|
|
61
|
-
editor.schema.styleSchema
|
|
62
|
-
);
|
|
50
|
+
nodes = tableContentToNodes(blockContent, editor.pmSchema);
|
|
63
51
|
} else {
|
|
64
52
|
throw new UnreachableCaseError(blockContent.type);
|
|
65
53
|
}
|
|
@@ -130,7 +118,10 @@ function serializeBlock<
|
|
|
130
118
|
|
|
131
119
|
const elementFragment = doc.createDocumentFragment();
|
|
132
120
|
if (ret.dom.classList.contains("bn-block-content")) {
|
|
133
|
-
const blockContentDataAttributes = [
|
|
121
|
+
const blockContentDataAttributes = [
|
|
122
|
+
...attrs,
|
|
123
|
+
...Array.from(ret.dom.attributes),
|
|
124
|
+
].filter(
|
|
134
125
|
(attr) =>
|
|
135
126
|
attr.name.startsWith("data") &&
|
|
136
127
|
attr.name !== "data-content-type" &&
|
|
@@ -30,25 +30,11 @@ export function serializeInlineContentInternalHTML<
|
|
|
30
30
|
if (!blockContent) {
|
|
31
31
|
throw new Error("blockContent is required");
|
|
32
32
|
} else if (typeof blockContent === "string") {
|
|
33
|
-
nodes = inlineContentToNodes(
|
|
34
|
-
[blockContent],
|
|
35
|
-
editor.pmSchema,
|
|
36
|
-
editor.schema.styleSchema,
|
|
37
|
-
blockType
|
|
38
|
-
);
|
|
33
|
+
nodes = inlineContentToNodes([blockContent], editor.pmSchema, blockType);
|
|
39
34
|
} else if (Array.isArray(blockContent)) {
|
|
40
|
-
nodes = inlineContentToNodes(
|
|
41
|
-
blockContent,
|
|
42
|
-
editor.pmSchema,
|
|
43
|
-
editor.schema.styleSchema,
|
|
44
|
-
blockType
|
|
45
|
-
);
|
|
35
|
+
nodes = inlineContentToNodes(blockContent, editor.pmSchema, blockType);
|
|
46
36
|
} else if (blockContent.type === "tableContent") {
|
|
47
|
-
nodes = tableContentToNodes(
|
|
48
|
-
blockContent,
|
|
49
|
-
editor.pmSchema,
|
|
50
|
-
editor.schema.styleSchema
|
|
51
|
-
);
|
|
37
|
+
nodes = tableContentToNodes(blockContent, editor.pmSchema);
|
|
52
38
|
} else {
|
|
53
39
|
throw new UnreachableCaseError(blockContent.type);
|
|
54
40
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Node, ResolvedPos } from "prosemirror-model";
|
|
2
|
-
import { EditorState } from "prosemirror-state";
|
|
2
|
+
import { EditorState, Transaction } from "prosemirror-state";
|
|
3
3
|
|
|
4
4
|
type SingleBlockInfo = {
|
|
5
5
|
node: Node;
|
|
@@ -239,3 +239,15 @@ export function getBlockInfoFromSelection(state: EditorState) {
|
|
|
239
239
|
|
|
240
240
|
return getBlockInfo(posInfo);
|
|
241
241
|
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Gets information regarding the ProseMirror nodes that make up a block. The
|
|
245
|
+
* block chosen is the one currently containing the current ProseMirror
|
|
246
|
+
* selection.
|
|
247
|
+
* @param tr The ProseMirror transaction.
|
|
248
|
+
*/
|
|
249
|
+
export function getBlockInfoFromTransaction(tr: Transaction) {
|
|
250
|
+
const posInfo = getNearestBlockPos(tr.doc, tr.selection.anchor);
|
|
251
|
+
|
|
252
|
+
return getBlockInfo(posInfo);
|
|
253
|
+
}
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import { getColspan, isPartialTableCell } from "../../util/table.js";
|
|
20
20
|
import { UnreachableCaseError } from "../../util/typescript.js";
|
|
21
21
|
import { getAbsoluteTableCells } from "../blockManipulation/tables/tables.js";
|
|
22
|
+
import { getStyleSchema } from "../pmUtil.js";
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Convert a StyledText inline element to a
|
|
@@ -139,8 +140,8 @@ export function inlineContentToNodes<
|
|
|
139
140
|
>(
|
|
140
141
|
blockContent: PartialInlineContent<I, S>,
|
|
141
142
|
schema: Schema,
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
blockType?: string,
|
|
144
|
+
styleSchema: S = getStyleSchema(schema)
|
|
144
145
|
): Node[] {
|
|
145
146
|
const nodes: Node[] = [];
|
|
146
147
|
|
|
@@ -173,7 +174,7 @@ export function tableContentToNodes<
|
|
|
173
174
|
>(
|
|
174
175
|
tableContent: PartialTableContent<I, S>,
|
|
175
176
|
schema: Schema,
|
|
176
|
-
styleSchema: StyleSchema
|
|
177
|
+
styleSchema: StyleSchema = getStyleSchema(schema)
|
|
177
178
|
): Node[] {
|
|
178
179
|
const rowNodes: Node[] = [];
|
|
179
180
|
// Header rows and columns are used to determine the type of the cell
|
|
@@ -222,7 +223,12 @@ export function tableContentToNodes<
|
|
|
222
223
|
content = schema.text(cell);
|
|
223
224
|
} else if (isPartialTableCell(cell)) {
|
|
224
225
|
if (cell.content) {
|
|
225
|
-
content = inlineContentToNodes(
|
|
226
|
+
content = inlineContentToNodes(
|
|
227
|
+
cell.content,
|
|
228
|
+
schema,
|
|
229
|
+
"tableParagraph",
|
|
230
|
+
styleSchema
|
|
231
|
+
);
|
|
226
232
|
}
|
|
227
233
|
const colspan = getColspan(cell);
|
|
228
234
|
|
|
@@ -234,7 +240,12 @@ export function tableContentToNodes<
|
|
|
234
240
|
});
|
|
235
241
|
}
|
|
236
242
|
} else {
|
|
237
|
-
content = inlineContentToNodes(
|
|
243
|
+
content = inlineContentToNodes(
|
|
244
|
+
cell,
|
|
245
|
+
schema,
|
|
246
|
+
"tableParagraph",
|
|
247
|
+
styleSchema
|
|
248
|
+
);
|
|
238
249
|
}
|
|
239
250
|
|
|
240
251
|
const cellNode = schema.nodes[
|
|
@@ -279,16 +290,16 @@ function blockOrInlineContentToContentNode(
|
|
|
279
290
|
const nodes = inlineContentToNodes(
|
|
280
291
|
[block.content],
|
|
281
292
|
schema,
|
|
282
|
-
|
|
283
|
-
|
|
293
|
+
type,
|
|
294
|
+
styleSchema
|
|
284
295
|
);
|
|
285
296
|
contentNode = schema.nodes[type].createChecked(block.props, nodes);
|
|
286
297
|
} else if (Array.isArray(block.content)) {
|
|
287
298
|
const nodes = inlineContentToNodes(
|
|
288
299
|
block.content,
|
|
289
300
|
schema,
|
|
290
|
-
|
|
291
|
-
|
|
301
|
+
type,
|
|
302
|
+
styleSchema
|
|
292
303
|
);
|
|
293
304
|
contentNode = schema.nodes[type].createChecked(block.props, nodes);
|
|
294
305
|
} else if (block.content.type === "tableContent") {
|
|
@@ -306,7 +317,7 @@ function blockOrInlineContentToContentNode(
|
|
|
306
317
|
export function blockToNode(
|
|
307
318
|
block: PartialBlock<any, any, any>,
|
|
308
319
|
schema: Schema,
|
|
309
|
-
styleSchema: StyleSchema
|
|
320
|
+
styleSchema: StyleSchema = getStyleSchema(schema)
|
|
310
321
|
) {
|
|
311
322
|
let id = block.id;
|
|
312
323
|
|