@blocknote/core 0.15.11 → 0.17.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.js +3349 -2773
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +6 -6
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +5 -2
- package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +3087 -0
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +132 -0
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +71 -0
- package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +2276 -0
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +131 -0
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +103 -0
- package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +3767 -0
- package/src/api/blockManipulation/commands/moveBlock/moveBlock.test.ts +192 -0
- package/src/api/blockManipulation/commands/moveBlock/moveBlock.ts +178 -0
- package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +1136 -0
- package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.ts +34 -0
- package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts +100 -0
- package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +4931 -0
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +222 -0
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +70 -0
- package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +2924 -0
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +136 -0
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +48 -0
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +8376 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +300 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +199 -0
- package/src/api/blockManipulation/insertContentAt.ts +96 -0
- package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +316 -0
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +53 -0
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +130 -0
- package/src/api/blockManipulation/setupTestEnv.ts +179 -0
- package/src/api/clipboard/__snapshots__/childToParent.html +1 -0
- package/src/api/clipboard/__snapshots__/childrenToNextParent.html +1 -0
- package/src/api/clipboard/__snapshots__/childrenToNextParentsChildren.html +1 -0
- package/src/api/clipboard/__snapshots__/image.html +1 -0
- package/src/api/clipboard/__snapshots__/multipleStyledText.html +1 -0
- package/src/api/clipboard/__snapshots__/nestedImage.html +1 -0
- package/src/api/clipboard/__snapshots__/partialChildToParent.html +1 -0
- package/src/api/clipboard/__snapshots__/styledText.html +1 -0
- package/src/api/clipboard/__snapshots__/tableAllCells.html +1 -0
- package/src/api/clipboard/__snapshots__/tableCell.html +1 -0
- package/src/api/clipboard/__snapshots__/tableCellText.html +1 -0
- package/src/api/clipboard/__snapshots__/tableRow.html +1 -0
- package/src/api/clipboard/__snapshots__/unstyledText.html +1 -0
- package/src/api/clipboard/clipboard.test.ts +283 -0
- package/src/api/{parsers → clipboard/fromClipboard}/fileDropExtension.ts +8 -4
- package/src/api/{parsers → clipboard/fromClipboard}/handleFileInsertion.ts +12 -7
- package/src/api/{parsers → clipboard/fromClipboard}/pasteExtension.ts +19 -8
- package/src/api/clipboard/toClipboard/copyExtension.ts +243 -0
- package/src/api/exporters/html/__snapshots__/complex/misc/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/lists/basic/external.html +1 -1
- package/src/api/exporters/html/__snapshots__/lists/nested/external.html +1 -1
- package/src/api/exporters/html/externalHTMLExporter.ts +42 -87
- package/src/api/exporters/html/htmlConversion.test.ts +19 -156
- package/src/api/exporters/html/internalHTMLSerializer.ts +21 -69
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +263 -0
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +158 -0
- package/src/api/exporters/markdown/markdownExporter.test.ts +10 -10
- package/src/api/exporters/markdown/markdownExporter.ts +11 -7
- package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +2 -2
- package/src/api/getBlockInfoFromPos.ts +172 -90
- package/src/api/nodeConversions/blockToNode.ts +257 -0
- package/src/api/nodeConversions/fragmentToBlocks.ts +60 -0
- package/src/api/nodeConversions/nodeConversions.test.ts +9 -8
- package/src/api/nodeConversions/{nodeConversions.ts → nodeToBlock.ts} +20 -262
- package/src/api/parsers/html/parseHTML.test.ts +5 -8
- package/src/api/parsers/html/parseHTML.ts +8 -4
- package/src/api/parsers/html/util/nestedLists.test.ts +2 -2
- package/src/api/parsers/markdown/__snapshots__/pasted/complex.json +319 -0
- package/src/api/parsers/markdown/__snapshots__/pasted/issue-226-1.json +81 -0
- package/src/api/parsers/{html/__snapshots__/paste/parse-deep-nested-content.json → markdown/__snapshots__/pasted/issue-226-2.json} +35 -110
- package/src/api/parsers/markdown/__snapshots__/pasted/nested.json +81 -0
- package/src/api/parsers/markdown/__snapshots__/pasted/non-nested.json +81 -0
- package/src/api/parsers/markdown/__snapshots__/pasted/styled.json +61 -0
- package/src/api/parsers/markdown/parseMarkdown.test.ts +16 -1
- package/src/api/parsers/markdown/parseMarkdown.ts +8 -4
- package/src/api/testUtil/cases/customBlocks.ts +11 -11
- package/src/api/testUtil/cases/customInlineContent.ts +6 -6
- package/src/api/testUtil/cases/customStyles.ts +6 -6
- package/src/api/testUtil/cases/defaultSchema.ts +4 -4
- package/src/api/testUtil/index.ts +6 -6
- package/src/api/testUtil/partialBlockTestUtil.ts +5 -5
- package/src/api/testUtil/paste.ts +46 -0
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +5 -5
- package/src/blocks/FileBlockContent/FileBlockContent.ts +4 -4
- package/src/blocks/FileBlockContent/fileBlockHelpers.ts +2 -2
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +61 -39
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +5 -5
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +30 -18
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +67 -33
- package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +23 -19
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +22 -24
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +31 -19
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +16 -11
- package/src/blocks/TableBlockContent/TableBlockContent.ts +4 -5
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +5 -5
- package/src/blocks/defaultBlockHelpers.ts +4 -4
- package/src/blocks/defaultBlockTypeGuards.ts +5 -5
- package/src/blocks/defaultBlocks.ts +13 -13
- package/src/blocks/defaultProps.ts +1 -1
- package/src/editor/BlockNoteEditor.test.ts +14 -7
- package/src/editor/BlockNoteEditor.ts +82 -149
- package/src/editor/BlockNoteExtensions.ts +15 -11
- package/src/editor/BlockNoteSchema.ts +7 -7
- package/src/editor/BlockNoteTipTapEditor.ts +5 -3
- package/src/editor/cursorPositionTypes.ts +7 -2
- package/src/editor/selectionTypes.ts +6 -2
- package/src/editor/transformPasted.ts +34 -2
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -1
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
- package/src/extensions/FilePanel/FilePanelPlugin.ts +4 -4
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +8 -4
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +333 -0
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +9 -4
- package/src/extensions/{NonEditableBlocks/NonEditableBlockPlugin.ts → NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts} +2 -2
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +1 -1
- package/src/extensions/SideMenu/SideMenuPlugin.ts +72 -402
- package/src/extensions/SideMenu/dragging.ts +251 -0
- package/src/extensions/SuggestionMenu/DefaultSuggestionItem.ts +1 -1
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +8 -4
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +8 -4
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +19 -15
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +11 -7
- package/src/extensions/TextColor/TextColorExtension.ts +1 -1
- package/src/extensions/TextColor/TextColorMark.ts +1 -1
- package/src/i18n/dictionary.ts +1 -1
- package/src/i18n/locales/ar.ts +1 -1
- package/src/i18n/locales/fr.ts +1 -1
- package/src/i18n/locales/hr.ts +308 -0
- package/src/i18n/locales/index.ts +15 -14
- package/src/i18n/locales/is.ts +1 -1
- package/src/i18n/locales/ja.ts +1 -1
- package/src/i18n/locales/ko.ts +1 -1
- package/src/i18n/locales/nl.ts +1 -1
- package/src/i18n/locales/pl.ts +1 -1
- package/src/i18n/locales/pt.ts +1 -1
- package/src/i18n/locales/ru.ts +1 -1
- package/src/i18n/locales/vi.ts +1 -1
- package/src/i18n/locales/zh.ts +1 -1
- package/src/index.ts +45 -44
- package/src/pm-nodes/BlockContainer.ts +3 -647
- package/src/pm-nodes/BlockGroup.ts +2 -2
- package/src/pm-nodes/index.ts +3 -3
- package/src/schema/blocks/createSpec.ts +24 -14
- package/src/schema/blocks/internal.ts +9 -9
- package/src/schema/blocks/types.ts +4 -4
- package/src/schema/index.ts +10 -10
- package/src/schema/inlineContent/createSpec.ts +9 -10
- package/src/schema/inlineContent/internal.ts +3 -3
- package/src/schema/inlineContent/types.ts +2 -2
- package/src/schema/styles/createSpec.ts +4 -3
- package/src/schema/styles/internal.ts +1 -1
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +4 -0
- package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +7 -0
- package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.d.ts +5 -0
- package/types/src/api/blockManipulation/commands/moveBlock/moveBlock.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +7 -0
- package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +7 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +5 -0
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.test.d.ts +1 -0
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +11 -0
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.test.d.ts +1 -0
- package/types/src/api/blockManipulation/insertContentAt.d.ts +6 -0
- package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.d.ts +5 -0
- package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.d.ts +1 -0
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +492 -0
- package/types/src/api/clipboard/clipboard.test.d.ts +1 -0
- package/types/src/api/clipboard/fromClipboard/fileDropExtension.d.ts +6 -0
- package/types/src/api/{parsers → clipboard/fromClipboard}/handleFileInsertion.d.ts +2 -2
- package/types/src/api/clipboard/fromClipboard/pasteExtension.d.ts +6 -0
- package/types/src/api/clipboard/toClipboard/copyExtension.d.ts +12 -0
- package/types/src/api/exporters/html/externalHTMLExporter.d.ts +7 -8
- package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +6 -10
- package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +10 -0
- package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +11 -0
- package/types/src/api/exporters/markdown/markdownExporter.d.ts +3 -3
- package/types/src/api/getBlockInfoFromPos.d.ts +63 -20
- package/types/src/api/nodeConversions/blockToNode.d.ts +15 -0
- package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +7 -0
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +16 -0
- package/types/src/api/parsers/html/parseHTML.d.ts +2 -2
- package/types/src/api/parsers/markdown/parseMarkdown.d.ts +2 -2
- package/types/src/api/testUtil/cases/customBlocks.d.ts +39 -39
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +35 -35
- package/types/src/api/testUtil/cases/customStyles.d.ts +35 -35
- package/types/src/api/testUtil/cases/defaultSchema.d.ts +2 -2
- package/types/src/api/testUtil/index.d.ts +6 -6
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +4 -4
- package/types/src/api/testUtil/paste.d.ts +2 -0
- package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +4 -4
- package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +4 -4
- package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +2 -2
- package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +2 -2
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +4 -4
- package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +2 -2
- package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +2 -2
- package/types/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +2 -2
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +2 -2
- package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +2 -2
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +2 -2
- package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +4 -4
- package/types/src/blocks/defaultBlockHelpers.d.ts +3 -3
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +4 -4
- package/types/src/blocks/defaultBlocks.d.ts +38 -38
- package/types/src/blocks/defaultProps.d.ts +1 -1
- package/types/src/editor/BlockNoteEditor.d.ts +28 -16
- package/types/src/editor/BlockNoteExtensions.d.ts +3 -3
- package/types/src/editor/BlockNoteSchema.d.ts +4 -4
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
- package/types/src/editor/cursorPositionTypes.d.ts +3 -2
- package/types/src/editor/selectionTypes.d.ts +2 -2
- package/types/src/editor/transformPasted.d.ts +8 -1
- package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +1 -1
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +4 -4
- package/types/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +5 -0
- package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +4 -4
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -0
- package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +1 -1
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +12 -28
- package/types/src/extensions/SideMenu/dragging.d.ts +17 -0
- package/types/src/extensions/SuggestionMenu/DefaultSuggestionItem.d.ts +1 -1
- package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +4 -4
- package/types/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.d.ts +3 -3
- package/types/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.d.ts +4 -4
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +4 -4
- package/types/src/extensions/TextColor/TextColorMark.d.ts +1 -1
- package/types/src/i18n/dictionary.d.ts +1 -1
- package/types/src/i18n/locales/ar.d.ts +1 -1
- package/types/src/i18n/locales/fr.d.ts +1 -1
- package/types/src/i18n/locales/hr.d.ts +239 -0
- package/types/src/i18n/locales/index.d.ts +15 -14
- package/types/src/i18n/locales/is.d.ts +1 -1
- package/types/src/i18n/locales/ja.d.ts +1 -1
- package/types/src/i18n/locales/ko.d.ts +1 -1
- package/types/src/i18n/locales/nl.d.ts +1 -1
- package/types/src/i18n/locales/pl.d.ts +1 -1
- package/types/src/i18n/locales/pt.d.ts +1 -1
- package/types/src/i18n/locales/ru.d.ts +1 -1
- package/types/src/i18n/locales/vi.d.ts +1 -1
- package/types/src/i18n/locales/zh.d.ts +1 -1
- package/types/src/index.d.ts +45 -44
- package/types/src/pm-nodes/BlockContainer.d.ts +2 -16
- package/types/src/pm-nodes/BlockGroup.d.ts +1 -1
- package/types/src/pm-nodes/index.d.ts +3 -3
- package/types/src/schema/blocks/createSpec.d.ts +5 -5
- package/types/src/schema/blocks/internal.d.ts +5 -5
- package/types/src/schema/blocks/types.d.ts +4 -4
- package/types/src/schema/index.d.ts +10 -10
- package/types/src/schema/inlineContent/createSpec.d.ts +3 -3
- package/types/src/schema/inlineContent/internal.d.ts +2 -2
- package/types/src/schema/inlineContent/types.d.ts +2 -2
- package/types/src/schema/styles/createSpec.d.ts +1 -1
- package/types/src/schema/styles/internal.d.ts +1 -1
- package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +0 -714
- package/src/api/blockManipulation/blockManipulation.test.ts +0 -292
- package/src/api/blockManipulation/blockManipulation.ts +0 -350
- package/src/api/exporters/copyExtension.ts +0 -164
- package/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionLeavesBlockChildren.html +0 -1
- package/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionSpansBlocksChildren.html +0 -1
- package/src/api/exporters/html/util/sharedHTMLConversion.ts +0 -130
- package/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts +0 -218
- package/src/api/getCurrentBlockContentType.ts +0 -14
- package/src/api/parsers/html/__snapshots__/paste/parse-google-docs-html.json +0 -476
- package/types/src/api/blockManipulation/blockManipulation.d.ts +0 -14
- package/types/src/api/exporters/copyExtension.d.ts +0 -6
- package/types/src/api/exporters/html/util/sharedHTMLConversion.d.ts +0 -9
- package/types/src/api/exporters/html/util/simplifyBlocksRehypePlugin.d.ts +0 -16
- package/types/src/api/getCurrentBlockContentType.d.ts +0 -2
- package/types/src/api/nodeConversions/nodeConversions.d.ts +0 -24
- package/types/src/api/parsers/fileDropExtension.d.ts +0 -6
- package/types/src/api/parsers/pasteExtension.d.ts +0 -6
- package/types/src/extensions/NonEditableBlocks/NonEditableBlockPlugin.d.ts +0 -2
- /package/src/api/{exporters/html/__snapshots_fragment_edge_cases__/selectionWithinBlockChildren.html → clipboard/__snapshots__/multipleChildren.html} +0 -0
- /package/src/api/{parsers → clipboard/fromClipboard}/acceptedMIMETypes.ts +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/list-test.json → list-test.json} +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/parse-basic-block-types.json → parse-basic-block-types.json} +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/parse-div-with-inline-content.json → parse-div-with-inline-content.json} +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/parse-divs.json → parse-divs.json} +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/parse-fake-image-caption.json → parse-fake-image-caption.json} +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/parse-image-in-paragraph.json → parse-image-in-paragraph.json} +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/parse-mixed-nested-lists.json → parse-mixed-nested-lists.json} +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/parse-nested-lists-with-paragraphs.json → parse-nested-lists-with-paragraphs.json} +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/parse-nested-lists.json → parse-nested-lists.json} +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/parse-notion-html.json → parse-notion-html.json} +0 -0
- /package/src/api/parsers/html/__snapshots__/{paste/parse-two-divs.json → parse-two-divs.json} +0 -0
- /package/types/src/api/blockManipulation/{blockManipulation.test.d.ts → commands/insertBlocks/insertBlocks.test.d.ts} +0 -0
- /package/types/src/api/{parsers → clipboard/fromClipboard}/acceptedMIMETypes.d.ts +0 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
import { NodeSelection, Selection } from "prosemirror-state";
|
|
3
|
+
import * as pmView from "prosemirror-view";
|
|
4
|
+
import { EditorView } from "prosemirror-view";
|
|
5
|
+
|
|
6
|
+
import { createExternalHTMLExporter } from "../../api/exporters/html/externalHTMLExporter.js";
|
|
7
|
+
import { cleanHTMLToMarkdown } from "../../api/exporters/markdown/markdownExporter.js";
|
|
8
|
+
import { fragmentToBlocks } from "../../api/nodeConversions/fragmentToBlocks.js";
|
|
9
|
+
import { Block } from "../../blocks/defaultBlocks.js";
|
|
10
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
11
|
+
import { UiElementPosition } from "../../extensions-shared/UiElementPosition.js";
|
|
12
|
+
import {
|
|
13
|
+
BlockSchema,
|
|
14
|
+
InlineContentSchema,
|
|
15
|
+
StyleSchema,
|
|
16
|
+
} from "../../schema/index.js";
|
|
17
|
+
import { MultipleNodeSelection } from "./MultipleNodeSelection.js";
|
|
18
|
+
|
|
19
|
+
let dragImageElement: Element | undefined;
|
|
20
|
+
|
|
21
|
+
export type SideMenuState<
|
|
22
|
+
BSchema extends BlockSchema,
|
|
23
|
+
I extends InlineContentSchema,
|
|
24
|
+
S extends StyleSchema
|
|
25
|
+
> = UiElementPosition & {
|
|
26
|
+
// The block that the side menu is attached to.
|
|
27
|
+
block: Block<BSchema, I, S>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function getDraggableBlockFromElement(
|
|
31
|
+
element: Element,
|
|
32
|
+
view: EditorView
|
|
33
|
+
) {
|
|
34
|
+
while (
|
|
35
|
+
element &&
|
|
36
|
+
element.parentElement &&
|
|
37
|
+
element.parentElement !== view.dom &&
|
|
38
|
+
element.getAttribute?.("data-node-type") !== "blockContainer"
|
|
39
|
+
) {
|
|
40
|
+
element = element.parentElement;
|
|
41
|
+
}
|
|
42
|
+
if (element.getAttribute?.("data-node-type") !== "blockContainer") {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return { node: element as HTMLElement, id: element.getAttribute("data-id")! };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function blockPositionFromElement(element: Element, view: EditorView) {
|
|
49
|
+
const block = getDraggableBlockFromElement(element, view);
|
|
50
|
+
|
|
51
|
+
if (block && block.node.nodeType === 1) {
|
|
52
|
+
// TODO: this uses undocumented PM APIs? do we need this / let's add docs?
|
|
53
|
+
const docView = (view as any).docView;
|
|
54
|
+
const desc = docView.nearestDesc(block.node, true);
|
|
55
|
+
if (!desc || desc === docView) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return desc.posBefore;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function blockPositionsFromSelection(selection: Selection, doc: Node) {
|
|
64
|
+
// Absolute positions just before the first block spanned by the selection, and just after the last block. Having the
|
|
65
|
+
// selection start and end just before and just after the target blocks ensures no whitespace/line breaks are left
|
|
66
|
+
// behind after dragging & dropping them.
|
|
67
|
+
let beforeFirstBlockPos: number;
|
|
68
|
+
let afterLastBlockPos: number;
|
|
69
|
+
|
|
70
|
+
// Even the user starts dragging blocks but drops them in the same place, the selection will still be moved just
|
|
71
|
+
// before & just after the blocks spanned by the selection, and therefore doesn't need to change if they try to drag
|
|
72
|
+
// the same blocks again. If this happens, the anchor & head move out of the block content node they were originally
|
|
73
|
+
// in. If the anchor should update but the head shouldn't and vice versa, it means the user selection is outside a
|
|
74
|
+
// block content node, which should never happen.
|
|
75
|
+
const selectionStartInBlockContent =
|
|
76
|
+
doc.resolve(selection.from).node().type.spec.group === "blockContent";
|
|
77
|
+
const selectionEndInBlockContent =
|
|
78
|
+
doc.resolve(selection.to).node().type.spec.group === "blockContent";
|
|
79
|
+
|
|
80
|
+
// Ensures that entire outermost nodes are selected if the selection spans multiple nesting levels.
|
|
81
|
+
const minDepth = Math.min(selection.$anchor.depth, selection.$head.depth);
|
|
82
|
+
|
|
83
|
+
if (selectionStartInBlockContent && selectionEndInBlockContent) {
|
|
84
|
+
// Absolute positions at the start of the first block in the selection and at the end of the last block. User
|
|
85
|
+
// selections will always start and end in block content nodes, but we want the start and end positions of their
|
|
86
|
+
// parent block nodes, which is why minDepth - 1 is used.
|
|
87
|
+
const startFirstBlockPos = selection.$from.start(minDepth - 1);
|
|
88
|
+
const endLastBlockPos = selection.$to.end(minDepth - 1);
|
|
89
|
+
|
|
90
|
+
// Shifting start and end positions by one moves them just outside the first and last selected blocks.
|
|
91
|
+
beforeFirstBlockPos = doc.resolve(startFirstBlockPos - 1).pos;
|
|
92
|
+
afterLastBlockPos = doc.resolve(endLastBlockPos + 1).pos;
|
|
93
|
+
} else {
|
|
94
|
+
beforeFirstBlockPos = selection.from;
|
|
95
|
+
afterLastBlockPos = selection.to;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return { from: beforeFirstBlockPos, to: afterLastBlockPos };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function setDragImage(view: EditorView, from: number, to = from) {
|
|
102
|
+
if (from === to) {
|
|
103
|
+
// Moves to position to be just after the first (and only) selected block.
|
|
104
|
+
to += view.state.doc.resolve(from + 1).node().nodeSize;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Parent element is cloned to remove all unselected children without affecting the editor content.
|
|
108
|
+
const parentClone = view.domAtPos(from).node.cloneNode(true) as Element;
|
|
109
|
+
const parent = view.domAtPos(from).node as Element;
|
|
110
|
+
|
|
111
|
+
const getElementIndex = (parentElement: Element, targetElement: Element) =>
|
|
112
|
+
Array.prototype.indexOf.call(parentElement.children, targetElement);
|
|
113
|
+
|
|
114
|
+
const firstSelectedBlockIndex = getElementIndex(
|
|
115
|
+
parent,
|
|
116
|
+
// Expects from position to be just before the first selected block.
|
|
117
|
+
view.domAtPos(from + 1).node.parentElement!
|
|
118
|
+
);
|
|
119
|
+
const lastSelectedBlockIndex = getElementIndex(
|
|
120
|
+
parent,
|
|
121
|
+
// Expects to position to be just after the last selected block.
|
|
122
|
+
view.domAtPos(to - 1).node.parentElement!
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
for (let i = parent.childElementCount - 1; i >= 0; i--) {
|
|
126
|
+
if (i > lastSelectedBlockIndex || i < firstSelectedBlockIndex) {
|
|
127
|
+
parentClone.removeChild(parentClone.children[i]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// dataTransfer.setDragImage(element) only works if element is attached to the DOM.
|
|
132
|
+
unsetDragImage(view.root);
|
|
133
|
+
dragImageElement = parentClone;
|
|
134
|
+
|
|
135
|
+
// TODO: This is hacky, need a better way of assigning classes to the editor so that they can also be applied to the
|
|
136
|
+
// drag preview.
|
|
137
|
+
const classes = view.dom.className.split(" ");
|
|
138
|
+
const inheritedClasses = classes
|
|
139
|
+
.filter(
|
|
140
|
+
(className) =>
|
|
141
|
+
className !== "ProseMirror" &&
|
|
142
|
+
className !== "bn-root" &&
|
|
143
|
+
className !== "bn-editor"
|
|
144
|
+
)
|
|
145
|
+
.join(" ");
|
|
146
|
+
|
|
147
|
+
dragImageElement.className =
|
|
148
|
+
dragImageElement.className + " bn-drag-preview " + inheritedClasses;
|
|
149
|
+
|
|
150
|
+
if (view.root instanceof ShadowRoot) {
|
|
151
|
+
view.root.appendChild(dragImageElement);
|
|
152
|
+
} else {
|
|
153
|
+
view.root.body.appendChild(dragImageElement);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function unsetDragImage(rootEl: Document | ShadowRoot) {
|
|
158
|
+
if (dragImageElement !== undefined) {
|
|
159
|
+
if (rootEl instanceof ShadowRoot) {
|
|
160
|
+
rootEl.removeChild(dragImageElement);
|
|
161
|
+
} else {
|
|
162
|
+
rootEl.body.removeChild(dragImageElement);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
dragImageElement = undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function dragStart<
|
|
170
|
+
BSchema extends BlockSchema,
|
|
171
|
+
I extends InlineContentSchema,
|
|
172
|
+
S extends StyleSchema
|
|
173
|
+
>(
|
|
174
|
+
e: { dataTransfer: DataTransfer | null; clientY: number },
|
|
175
|
+
editor: BlockNoteEditor<BSchema, I, S>
|
|
176
|
+
) {
|
|
177
|
+
if (!e.dataTransfer) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const view = editor.prosemirrorView;
|
|
182
|
+
|
|
183
|
+
const editorBoundingBox = view.dom.getBoundingClientRect();
|
|
184
|
+
|
|
185
|
+
const coords = {
|
|
186
|
+
left: editorBoundingBox.left + editorBoundingBox.width / 2, // take middle of editor
|
|
187
|
+
top: e.clientY,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const elements = view.root.elementsFromPoint(coords.left, coords.top);
|
|
191
|
+
let blockEl = undefined;
|
|
192
|
+
|
|
193
|
+
for (const element of elements) {
|
|
194
|
+
if (view.dom.contains(element)) {
|
|
195
|
+
blockEl = getDraggableBlockFromElement(element, view);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (!blockEl) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const pos = blockPositionFromElement(blockEl.node, view);
|
|
205
|
+
if (pos != null) {
|
|
206
|
+
const selection = view.state.selection;
|
|
207
|
+
const doc = view.state.doc;
|
|
208
|
+
|
|
209
|
+
const { from, to } = blockPositionsFromSelection(selection, doc);
|
|
210
|
+
|
|
211
|
+
const draggedBlockInSelection = from <= pos && pos < to;
|
|
212
|
+
const multipleBlocksSelected =
|
|
213
|
+
selection.$anchor.node() !== selection.$head.node() ||
|
|
214
|
+
selection instanceof MultipleNodeSelection;
|
|
215
|
+
|
|
216
|
+
if (draggedBlockInSelection && multipleBlocksSelected) {
|
|
217
|
+
view.dispatch(
|
|
218
|
+
view.state.tr.setSelection(MultipleNodeSelection.create(doc, from, to))
|
|
219
|
+
);
|
|
220
|
+
setDragImage(view, from, to);
|
|
221
|
+
} else {
|
|
222
|
+
view.dispatch(
|
|
223
|
+
view.state.tr.setSelection(NodeSelection.create(view.state.doc, pos))
|
|
224
|
+
);
|
|
225
|
+
setDragImage(view, pos);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const selectedSlice = view.state.selection.content();
|
|
229
|
+
const schema = editor.pmSchema;
|
|
230
|
+
|
|
231
|
+
const clipboardHTML = (pmView as any).__serializeForClipboard(
|
|
232
|
+
view,
|
|
233
|
+
selectedSlice
|
|
234
|
+
).dom.innerHTML;
|
|
235
|
+
|
|
236
|
+
const externalHTMLExporter = createExternalHTMLExporter(schema, editor);
|
|
237
|
+
|
|
238
|
+
const blocks = fragmentToBlocks(selectedSlice.content, editor.schema);
|
|
239
|
+
const externalHTML = externalHTMLExporter.exportBlocks(blocks, {});
|
|
240
|
+
|
|
241
|
+
const plainText = cleanHTMLToMarkdown(externalHTML);
|
|
242
|
+
|
|
243
|
+
e.dataTransfer.clearData();
|
|
244
|
+
e.dataTransfer.setData("blocknote/html", clipboardHTML);
|
|
245
|
+
e.dataTransfer.setData("text/html", externalHTML);
|
|
246
|
+
e.dataTransfer.setData("text/plain", plainText);
|
|
247
|
+
e.dataTransfer.effectAllowed = "move";
|
|
248
|
+
e.dataTransfer.setDragImage(dragImageElement!, 0, 0);
|
|
249
|
+
view.dragging = { slice: selectedSlice, move: true };
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -2,10 +2,14 @@ import { findParentNode } from "@tiptap/core";
|
|
|
2
2
|
import { EditorState, Plugin, PluginKey } from "prosemirror-state";
|
|
3
3
|
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
|
|
4
4
|
|
|
5
|
-
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
6
|
-
import { UiElementPosition } from "../../extensions-shared/UiElementPosition";
|
|
7
|
-
import {
|
|
8
|
-
|
|
5
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
6
|
+
import { UiElementPosition } from "../../extensions-shared/UiElementPosition.js";
|
|
7
|
+
import {
|
|
8
|
+
BlockSchema,
|
|
9
|
+
InlineContentSchema,
|
|
10
|
+
StyleSchema,
|
|
11
|
+
} from "../../schema/index.js";
|
|
12
|
+
import { EventEmitter } from "../../util/EventEmitter.js";
|
|
9
13
|
|
|
10
14
|
const findBlock = findParentNode((node) => node.type.name === "blockContainer");
|
|
11
15
|
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { Emoji, EmojiMartData } from "@emoji-mart/data";
|
|
2
2
|
|
|
3
|
-
import { checkDefaultInlineContentTypeInSchema } from "../../blocks/defaultBlockTypeGuards";
|
|
4
|
-
import { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import { checkDefaultInlineContentTypeInSchema } from "../../blocks/defaultBlockTypeGuards.js";
|
|
4
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
5
|
+
import {
|
|
6
|
+
BlockSchema,
|
|
7
|
+
InlineContentSchema,
|
|
8
|
+
StyleSchema,
|
|
9
|
+
} from "../../schema/index.js";
|
|
10
|
+
import { DefaultGridSuggestionItem } from "./DefaultGridSuggestionItem.js";
|
|
7
11
|
|
|
8
12
|
let data:
|
|
9
13
|
| Promise<{
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Block, PartialBlock } from "../../blocks/defaultBlocks";
|
|
2
|
-
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
1
|
+
import { Block, PartialBlock } from "../../blocks/defaultBlocks.js";
|
|
2
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
3
3
|
|
|
4
|
-
import { checkDefaultBlockTypeInSchema } from "../../blocks/defaultBlockTypeGuards";
|
|
4
|
+
import { checkDefaultBlockTypeInSchema } from "../../blocks/defaultBlockTypeGuards.js";
|
|
5
5
|
import {
|
|
6
6
|
BlockSchema,
|
|
7
7
|
InlineContentSchema,
|
|
8
8
|
StyleSchema,
|
|
9
9
|
isStyledTextInlineContent,
|
|
10
|
-
} from "../../schema";
|
|
11
|
-
import { formatKeyboardShortcut } from "../../util/browser";
|
|
12
|
-
import { DefaultSuggestionItem } from "./DefaultSuggestionItem";
|
|
10
|
+
} from "../../schema/index.js";
|
|
11
|
+
import { formatKeyboardShortcut } from "../../util/browser.js";
|
|
12
|
+
import { DefaultSuggestionItem } from "./DefaultSuggestionItem.js";
|
|
13
13
|
|
|
14
14
|
// Sets the editor's text cursor position to the next content editable block,
|
|
15
15
|
// so either a block with inline content or a table. The last block is always a
|
|
@@ -51,6 +51,8 @@ export function insertOrUpdateBlock<
|
|
|
51
51
|
throw new Error("Slash Menu open in a block that doesn't contain content.");
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
let newBlock: Block<BSchema, I, S>;
|
|
55
|
+
|
|
54
56
|
if (
|
|
55
57
|
Array.isArray(currentBlock.content) &&
|
|
56
58
|
((currentBlock.content.length === 1 &&
|
|
@@ -59,19 +61,21 @@ export function insertOrUpdateBlock<
|
|
|
59
61
|
currentBlock.content[0].text === "/") ||
|
|
60
62
|
currentBlock.content.length === 0)
|
|
61
63
|
) {
|
|
62
|
-
editor.updateBlock(currentBlock, block);
|
|
64
|
+
newBlock = editor.updateBlock(currentBlock, block);
|
|
65
|
+
|
|
66
|
+
// Edge case for updating block content as `updateBlock` causes the
|
|
67
|
+
// selection to move into the next block, so we have to set it back.
|
|
68
|
+
if (block.content) {
|
|
69
|
+
editor.setTextCursorPosition(newBlock);
|
|
70
|
+
}
|
|
63
71
|
} else {
|
|
64
|
-
editor.insertBlocks([block], currentBlock, "after");
|
|
65
|
-
editor.setTextCursorPosition(
|
|
66
|
-
editor.getTextCursorPosition().nextBlock!,
|
|
67
|
-
"end"
|
|
68
|
-
);
|
|
72
|
+
newBlock = editor.insertBlocks([block], currentBlock, "after")[0];
|
|
73
|
+
editor.setTextCursorPosition(editor.getTextCursorPosition().nextBlock!);
|
|
69
74
|
}
|
|
70
75
|
|
|
71
|
-
const insertedBlock = editor.getTextCursorPosition().block;
|
|
72
76
|
setSelectionToNextContentEditableBlock(editor);
|
|
73
77
|
|
|
74
|
-
return
|
|
78
|
+
return newBlock;
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
export function getDefaultSlashMenuItems<
|
|
@@ -266,7 +270,7 @@ export function getDefaultSlashMenuItems<
|
|
|
266
270
|
})
|
|
267
271
|
);
|
|
268
272
|
},
|
|
269
|
-
key: "
|
|
273
|
+
key: "file",
|
|
270
274
|
...editor.dictionary.slash_menu.file,
|
|
271
275
|
});
|
|
272
276
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Plugin, PluginKey, PluginView } from "prosemirror-state";
|
|
2
2
|
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
|
|
3
|
-
import { nodeToBlock } from "../../api/nodeConversions/
|
|
4
|
-
import { checkBlockIsDefaultType } from "../../blocks/defaultBlockTypeGuards";
|
|
5
|
-
import { Block, DefaultBlockSchema } from "../../blocks/defaultBlocks";
|
|
6
|
-
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
3
|
+
import { nodeToBlock } from "../../api/nodeConversions/nodeToBlock.js";
|
|
4
|
+
import { checkBlockIsDefaultType } from "../../blocks/defaultBlockTypeGuards.js";
|
|
5
|
+
import { Block, DefaultBlockSchema } from "../../blocks/defaultBlocks.js";
|
|
6
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
7
7
|
import {
|
|
8
8
|
BlockFromConfigNoChildren,
|
|
9
9
|
BlockSchemaWithBlock,
|
|
10
10
|
InlineContentSchema,
|
|
11
11
|
StyleSchema,
|
|
12
|
-
} from "../../schema";
|
|
13
|
-
import { EventEmitter } from "../../util/EventEmitter";
|
|
14
|
-
import { getDraggableBlockFromElement } from "../SideMenu/
|
|
12
|
+
} from "../../schema/index.js";
|
|
13
|
+
import { EventEmitter } from "../../util/EventEmitter.js";
|
|
14
|
+
import { getDraggableBlockFromElement } from "../SideMenu/dragging.js";
|
|
15
15
|
|
|
16
16
|
let dragImageElement: HTMLElement | undefined;
|
|
17
17
|
|
|
@@ -387,6 +387,10 @@ export class TableHandlesView<
|
|
|
387
387
|
rows: rows,
|
|
388
388
|
},
|
|
389
389
|
});
|
|
390
|
+
|
|
391
|
+
// Have to reset text cursor position to the block as `updateBlock` moves
|
|
392
|
+
// the existing selection out of the block.
|
|
393
|
+
this.editor.setTextCursorPosition(this.state.block.id);
|
|
390
394
|
};
|
|
391
395
|
|
|
392
396
|
scrollHandler = () => {
|
package/src/i18n/dictionary.ts
CHANGED
package/src/i18n/locales/ar.ts
CHANGED
package/src/i18n/locales/fr.ts
CHANGED