@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
|
@@ -3,8 +3,8 @@ import Code from "@tiptap/extension-code";
|
|
|
3
3
|
import Italic from "@tiptap/extension-italic";
|
|
4
4
|
import Strike from "@tiptap/extension-strike";
|
|
5
5
|
import Underline from "@tiptap/extension-underline";
|
|
6
|
-
import { BackgroundColor } from "../extensions/BackgroundColor/BackgroundColorMark";
|
|
7
|
-
import { TextColor } from "../extensions/TextColor/TextColorMark";
|
|
6
|
+
import { BackgroundColor } from "../extensions/BackgroundColor/BackgroundColorMark.js";
|
|
7
|
+
import { TextColor } from "../extensions/TextColor/TextColorMark.js";
|
|
8
8
|
import {
|
|
9
9
|
BlockNoDefaults,
|
|
10
10
|
BlockSchema,
|
|
@@ -18,18 +18,18 @@ import {
|
|
|
18
18
|
getBlockSchemaFromSpecs,
|
|
19
19
|
getInlineContentSchemaFromSpecs,
|
|
20
20
|
getStyleSchemaFromSpecs,
|
|
21
|
-
} from "../schema";
|
|
21
|
+
} from "../schema/index.js";
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
23
|
+
import { AudioBlock } from "./AudioBlockContent/AudioBlockContent.js";
|
|
24
|
+
import { FileBlock } from "./FileBlockContent/FileBlockContent.js";
|
|
25
|
+
import { Heading } from "./HeadingBlockContent/HeadingBlockContent.js";
|
|
26
|
+
import { ImageBlock } from "./ImageBlockContent/ImageBlockContent.js";
|
|
27
|
+
import { BulletListItem } from "./ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.js";
|
|
28
|
+
import { CheckListItem } from "./ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.js";
|
|
29
|
+
import { NumberedListItem } from "./ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.js";
|
|
30
|
+
import { Paragraph } from "./ParagraphBlockContent/ParagraphBlockContent.js";
|
|
31
|
+
import { Table } from "./TableBlockContent/TableBlockContent.js";
|
|
32
|
+
import { VideoBlock } from "./VideoBlockContent/VideoBlockContent.js";
|
|
33
33
|
|
|
34
34
|
export const defaultBlockSpecs = {
|
|
35
35
|
paragraph: Paragraph,
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
getBlockInfo,
|
|
4
|
+
getNearestBlockContainerPos,
|
|
5
|
+
} from "../api/getBlockInfoFromPos.js";
|
|
6
|
+
import { BlockNoteEditor } from "./BlockNoteEditor.js";
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* @vitest-environment jsdom
|
|
7
10
|
*/
|
|
8
11
|
it("creates an editor", () => {
|
|
9
12
|
const editor = BlockNoteEditor.create();
|
|
10
|
-
const
|
|
11
|
-
|
|
13
|
+
const posInfo = getNearestBlockContainerPos(
|
|
14
|
+
editor._tiptapEditor.state.doc,
|
|
15
|
+
2
|
|
16
|
+
);
|
|
17
|
+
const { blockContent } = getBlockInfo(posInfo);
|
|
18
|
+
expect(blockContent.node.type.name).toEqual("paragraph");
|
|
12
19
|
});
|
|
13
20
|
|
|
14
21
|
it("immediately replaces doc", async () => {
|
|
@@ -66,7 +73,7 @@ it("adds id attribute when requested", async () => {
|
|
|
66
73
|
"This is a normal text\n\n# And this is a large heading"
|
|
67
74
|
);
|
|
68
75
|
editor.replaceBlocks(editor.document, blocks);
|
|
69
|
-
expect(
|
|
70
|
-
|
|
71
|
-
)
|
|
76
|
+
expect(await editor.blocksToFullHTML(editor.document)).toMatchInlineSnapshot(
|
|
77
|
+
`"<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1" id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1" id="1"><div class="bn-block-content" data-content-type="paragraph"><p class="bn-inline-content">This is a normal text</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="2" id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2" id="2"><div class="bn-block-content" data-content-type="heading" data-level="1"><h1 class="bn-inline-content">And this is a large heading</h1></div></div></div></div>"`
|
|
78
|
+
);
|
|
72
79
|
});
|
|
@@ -2,37 +2,38 @@ import { EditorOptions, Extension, getSchema } from "@tiptap/core";
|
|
|
2
2
|
import { Node, Schema } from "prosemirror-model";
|
|
3
3
|
// import "./blocknote.css";
|
|
4
4
|
import * as Y from "yjs";
|
|
5
|
+
import { insertBlocks } from "../api/blockManipulation/commands/insertBlocks/insertBlocks.js";
|
|
5
6
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "../api/blockManipulation/
|
|
12
|
-
import {
|
|
13
|
-
import { blocksToMarkdown } from "../api/exporters/markdown/markdownExporter";
|
|
14
|
-
import { getBlockInfoFromPos } from "../api/getBlockInfoFromPos";
|
|
7
|
+
moveBlockDown,
|
|
8
|
+
moveBlockUp,
|
|
9
|
+
} from "../api/blockManipulation/commands/moveBlock/moveBlock.js";
|
|
10
|
+
import { removeBlocks } from "../api/blockManipulation/commands/removeBlocks/removeBlocks.js";
|
|
11
|
+
import { replaceBlocks } from "../api/blockManipulation/commands/replaceBlocks/replaceBlocks.js";
|
|
12
|
+
import { updateBlock } from "../api/blockManipulation/commands/updateBlock/updateBlock.js";
|
|
13
|
+
import { insertContentAt } from "../api/blockManipulation/insertContentAt.js";
|
|
15
14
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from "../api/
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
15
|
+
getTextCursorPosition,
|
|
16
|
+
setTextCursorPosition,
|
|
17
|
+
} from "../api/blockManipulation/selections/textCursorPosition/textCursorPosition.js";
|
|
18
|
+
import { createExternalHTMLExporter } from "../api/exporters/html/externalHTMLExporter.js";
|
|
19
|
+
import { blocksToMarkdown } from "../api/exporters/markdown/markdownExporter.js";
|
|
20
|
+
import { getBlockInfoFromSelection } from "../api/getBlockInfoFromPos.js";
|
|
21
|
+
import { HTMLToBlocks } from "../api/parsers/html/parseHTML.js";
|
|
22
|
+
import { markdownToBlocks } from "../api/parsers/markdown/parseMarkdown.js";
|
|
22
23
|
import {
|
|
23
24
|
Block,
|
|
24
25
|
DefaultBlockSchema,
|
|
25
26
|
DefaultInlineContentSchema,
|
|
26
27
|
DefaultStyleSchema,
|
|
27
28
|
PartialBlock,
|
|
28
|
-
} from "../blocks/defaultBlocks";
|
|
29
|
-
import { FilePanelProsemirrorPlugin } from "../extensions/FilePanel/FilePanelPlugin";
|
|
30
|
-
import { FormattingToolbarProsemirrorPlugin } from "../extensions/FormattingToolbar/FormattingToolbarPlugin";
|
|
31
|
-
import { LinkToolbarProsemirrorPlugin } from "../extensions/LinkToolbar/LinkToolbarPlugin";
|
|
32
|
-
import { SideMenuProsemirrorPlugin } from "../extensions/SideMenu/SideMenuPlugin";
|
|
33
|
-
import { SuggestionMenuProseMirrorPlugin } from "../extensions/SuggestionMenu/SuggestionPlugin";
|
|
34
|
-
import { TableHandlesProsemirrorPlugin } from "../extensions/TableHandles/TableHandlesPlugin";
|
|
35
|
-
import { UniqueID } from "../extensions/UniqueID/UniqueID";
|
|
29
|
+
} from "../blocks/defaultBlocks.js";
|
|
30
|
+
import { FilePanelProsemirrorPlugin } from "../extensions/FilePanel/FilePanelPlugin.js";
|
|
31
|
+
import { FormattingToolbarProsemirrorPlugin } from "../extensions/FormattingToolbar/FormattingToolbarPlugin.js";
|
|
32
|
+
import { LinkToolbarProsemirrorPlugin } from "../extensions/LinkToolbar/LinkToolbarPlugin.js";
|
|
33
|
+
import { SideMenuProsemirrorPlugin } from "../extensions/SideMenu/SideMenuPlugin.js";
|
|
34
|
+
import { SuggestionMenuProseMirrorPlugin } from "../extensions/SuggestionMenu/SuggestionPlugin.js";
|
|
35
|
+
import { TableHandlesProsemirrorPlugin } from "../extensions/TableHandles/TableHandlesPlugin.js";
|
|
36
|
+
import { UniqueID } from "../extensions/UniqueID/UniqueID.js";
|
|
36
37
|
import {
|
|
37
38
|
BlockIdentifier,
|
|
38
39
|
BlockNoteDOMAttributes,
|
|
@@ -44,32 +45,34 @@ import {
|
|
|
44
45
|
StyleSchema,
|
|
45
46
|
StyleSpecs,
|
|
46
47
|
Styles,
|
|
47
|
-
} from "../schema";
|
|
48
|
-
import { mergeCSSClasses } from "../util/browser";
|
|
49
|
-
import { NoInfer, UnreachableCaseError } from "../util/typescript";
|
|
48
|
+
} from "../schema/index.js";
|
|
49
|
+
import { mergeCSSClasses } from "../util/browser.js";
|
|
50
|
+
import { NoInfer, UnreachableCaseError } from "../util/typescript.js";
|
|
50
51
|
|
|
51
|
-
import { getBlockNoteExtensions } from "./BlockNoteExtensions";
|
|
52
|
-
import { TextCursorPosition } from "./cursorPositionTypes";
|
|
52
|
+
import { getBlockNoteExtensions } from "./BlockNoteExtensions.js";
|
|
53
|
+
import { TextCursorPosition } from "./cursorPositionTypes.js";
|
|
53
54
|
|
|
54
|
-
import { Selection } from "./selectionTypes";
|
|
55
|
-
import { transformPasted } from "./transformPasted";
|
|
55
|
+
import { Selection } from "./selectionTypes.js";
|
|
56
|
+
import { transformPasted } from "./transformPasted.js";
|
|
56
57
|
|
|
57
|
-
import { checkDefaultBlockTypeInSchema } from "../blocks/defaultBlockTypeGuards";
|
|
58
|
-
import { BlockNoteSchema } from "./BlockNoteSchema";
|
|
58
|
+
import { checkDefaultBlockTypeInSchema } from "../blocks/defaultBlockTypeGuards.js";
|
|
59
|
+
import { BlockNoteSchema } from "./BlockNoteSchema.js";
|
|
59
60
|
import {
|
|
60
61
|
BlockNoteTipTapEditor,
|
|
61
62
|
BlockNoteTipTapEditorOptions,
|
|
62
|
-
} from "./BlockNoteTipTapEditor";
|
|
63
|
+
} from "./BlockNoteTipTapEditor.js";
|
|
63
64
|
|
|
64
|
-
import { PlaceholderPlugin } from "../extensions/Placeholder/PlaceholderPlugin";
|
|
65
|
-
import { Dictionary } from "../i18n/dictionary";
|
|
66
|
-
import { en } from "../i18n/locales";
|
|
65
|
+
import { PlaceholderPlugin } from "../extensions/Placeholder/PlaceholderPlugin.js";
|
|
66
|
+
import { Dictionary } from "../i18n/dictionary.js";
|
|
67
|
+
import { en } from "../i18n/locales/index.js";
|
|
67
68
|
|
|
68
69
|
import { Transaction } from "@tiptap/pm/state";
|
|
69
|
-
import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer";
|
|
70
|
-
import {
|
|
70
|
+
import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer.js";
|
|
71
|
+
import { inlineContentToNodes } from "../api/nodeConversions/blockToNode.js";
|
|
72
|
+
import { nodeToBlock } from "../api/nodeConversions/nodeToBlock.js";
|
|
73
|
+
import { NodeSelectionKeyboardPlugin } from "../extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js";
|
|
74
|
+
import { PreviousBlockTypePlugin } from "../extensions/PreviousBlockType/PreviousBlockTypePlugin.js";
|
|
71
75
|
import "../style.css";
|
|
72
|
-
import { initializeESMDependencies } from "../util/esmDependencies";
|
|
73
76
|
|
|
74
77
|
export type BlockNoteEditorOptions<
|
|
75
78
|
BSchema extends BlockSchema,
|
|
@@ -378,6 +381,7 @@ export class BlockNoteEditor<
|
|
|
378
381
|
...(this.filePanel ? [this.filePanel.plugin] : []),
|
|
379
382
|
...(this.tableHandles ? [this.tableHandles.plugin] : []),
|
|
380
383
|
PlaceholderPlugin(this, newOptions.placeholders),
|
|
384
|
+
NodeSelectionKeyboardPlugin(),
|
|
381
385
|
...(this.options.animations ?? true
|
|
382
386
|
? [PreviousBlockTypePlugin()]
|
|
383
387
|
: []),
|
|
@@ -659,61 +663,7 @@ export class BlockNoteEditor<
|
|
|
659
663
|
ISchema,
|
|
660
664
|
SSchema
|
|
661
665
|
> {
|
|
662
|
-
|
|
663
|
-
this._tiptapEditor.state.doc,
|
|
664
|
-
this._tiptapEditor.state.selection.from
|
|
665
|
-
)!;
|
|
666
|
-
|
|
667
|
-
// Index of the current blockContainer node relative to its parent blockGroup.
|
|
668
|
-
const nodeIndex = this._tiptapEditor.state.doc
|
|
669
|
-
.resolve(endPos)
|
|
670
|
-
.index(depth - 1);
|
|
671
|
-
// Number of the parent blockGroup's child blockContainer nodes.
|
|
672
|
-
const numNodes = this._tiptapEditor.state.doc
|
|
673
|
-
.resolve(endPos + 1)
|
|
674
|
-
.node().childCount;
|
|
675
|
-
|
|
676
|
-
// Gets previous blockContainer node at the same nesting level, if the current node isn't the first child.
|
|
677
|
-
let prevNode: Node | undefined = undefined;
|
|
678
|
-
if (nodeIndex > 0) {
|
|
679
|
-
prevNode = this._tiptapEditor.state.doc.resolve(startPos - 2).node();
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
// Gets next blockContainer node at the same nesting level, if the current node isn't the last child.
|
|
683
|
-
let nextNode: Node | undefined = undefined;
|
|
684
|
-
if (nodeIndex < numNodes - 1) {
|
|
685
|
-
nextNode = this._tiptapEditor.state.doc.resolve(endPos + 2).node();
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
return {
|
|
689
|
-
block: nodeToBlock(
|
|
690
|
-
node,
|
|
691
|
-
this.schema.blockSchema,
|
|
692
|
-
this.schema.inlineContentSchema,
|
|
693
|
-
this.schema.styleSchema,
|
|
694
|
-
this.blockCache
|
|
695
|
-
),
|
|
696
|
-
prevBlock:
|
|
697
|
-
prevNode === undefined
|
|
698
|
-
? undefined
|
|
699
|
-
: nodeToBlock(
|
|
700
|
-
prevNode,
|
|
701
|
-
this.schema.blockSchema,
|
|
702
|
-
this.schema.inlineContentSchema,
|
|
703
|
-
this.schema.styleSchema,
|
|
704
|
-
this.blockCache
|
|
705
|
-
),
|
|
706
|
-
nextBlock:
|
|
707
|
-
nextNode === undefined
|
|
708
|
-
? undefined
|
|
709
|
-
: nodeToBlock(
|
|
710
|
-
nextNode,
|
|
711
|
-
this.schema.blockSchema,
|
|
712
|
-
this.schema.inlineContentSchema,
|
|
713
|
-
this.schema.styleSchema,
|
|
714
|
-
this.blockCache
|
|
715
|
-
),
|
|
716
|
-
};
|
|
666
|
+
return getTextCursorPosition(this);
|
|
717
667
|
}
|
|
718
668
|
|
|
719
669
|
/**
|
|
@@ -726,44 +676,7 @@ export class BlockNoteEditor<
|
|
|
726
676
|
targetBlock: BlockIdentifier,
|
|
727
677
|
placement: "start" | "end" = "start"
|
|
728
678
|
) {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
const { posBeforeNode } = getNodeById(id, this._tiptapEditor.state.doc);
|
|
732
|
-
const { startPos, contentNode } = getBlockInfoFromPos(
|
|
733
|
-
this._tiptapEditor.state.doc,
|
|
734
|
-
posBeforeNode + 2
|
|
735
|
-
)!;
|
|
736
|
-
|
|
737
|
-
const contentType: "none" | "inline" | "table" =
|
|
738
|
-
this.schema.blockSchema[contentNode.type.name]!.content;
|
|
739
|
-
|
|
740
|
-
if (contentType === "none") {
|
|
741
|
-
this._tiptapEditor.commands.setNodeSelection(startPos);
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
if (contentType === "inline") {
|
|
746
|
-
if (placement === "start") {
|
|
747
|
-
this._tiptapEditor.commands.setTextSelection(startPos + 1);
|
|
748
|
-
} else {
|
|
749
|
-
this._tiptapEditor.commands.setTextSelection(
|
|
750
|
-
startPos + contentNode.nodeSize - 1
|
|
751
|
-
);
|
|
752
|
-
}
|
|
753
|
-
} else if (contentType === "table") {
|
|
754
|
-
if (placement === "start") {
|
|
755
|
-
// Need to offset the position as we have to get through the `tableRow`
|
|
756
|
-
// and `tableCell` nodes to get to the `tableParagraph` node we want to
|
|
757
|
-
// set the selection in.
|
|
758
|
-
this._tiptapEditor.commands.setTextSelection(startPos + 4);
|
|
759
|
-
} else {
|
|
760
|
-
this._tiptapEditor.commands.setTextSelection(
|
|
761
|
-
startPos + contentNode.nodeSize - 4
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
} else {
|
|
765
|
-
throw new UnreachableCaseError(contentType);
|
|
766
|
-
}
|
|
679
|
+
setTextCursorPosition(this, targetBlock, placement);
|
|
767
680
|
}
|
|
768
681
|
|
|
769
682
|
/**
|
|
@@ -858,14 +771,14 @@ export class BlockNoteEditor<
|
|
|
858
771
|
* @param blocksToInsert An array of partial blocks that should be inserted.
|
|
859
772
|
* @param referenceBlock An identifier for an existing block, at which the new blocks should be inserted.
|
|
860
773
|
* @param placement Whether the blocks should be inserted just before, just after, or nested inside the
|
|
861
|
-
* `referenceBlock`.
|
|
774
|
+
* `referenceBlock`.
|
|
862
775
|
*/
|
|
863
776
|
public insertBlocks(
|
|
864
777
|
blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[],
|
|
865
778
|
referenceBlock: BlockIdentifier,
|
|
866
|
-
placement: "before" | "after"
|
|
779
|
+
placement: "before" | "after" = "before"
|
|
867
780
|
) {
|
|
868
|
-
return insertBlocks(blocksToInsert, referenceBlock, placement
|
|
781
|
+
return insertBlocks(this, blocksToInsert, referenceBlock, placement);
|
|
869
782
|
}
|
|
870
783
|
|
|
871
784
|
/**
|
|
@@ -879,7 +792,7 @@ export class BlockNoteEditor<
|
|
|
879
792
|
blockToUpdate: BlockIdentifier,
|
|
880
793
|
update: PartialBlock<BSchema, ISchema, SSchema>
|
|
881
794
|
) {
|
|
882
|
-
return updateBlock(blockToUpdate, update
|
|
795
|
+
return updateBlock(this, blockToUpdate, update);
|
|
883
796
|
}
|
|
884
797
|
|
|
885
798
|
/**
|
|
@@ -887,7 +800,7 @@ export class BlockNoteEditor<
|
|
|
887
800
|
* @param blocksToRemove An array of identifiers for existing blocks that should be removed.
|
|
888
801
|
*/
|
|
889
802
|
public removeBlocks(blocksToRemove: BlockIdentifier[]) {
|
|
890
|
-
return removeBlocks(
|
|
803
|
+
return removeBlocks(this, blocksToRemove);
|
|
891
804
|
}
|
|
892
805
|
|
|
893
806
|
/**
|
|
@@ -901,7 +814,7 @@ export class BlockNoteEditor<
|
|
|
901
814
|
blocksToRemove: BlockIdentifier[],
|
|
902
815
|
blocksToInsert: PartialBlock<BSchema, ISchema, SSchema>[]
|
|
903
816
|
) {
|
|
904
|
-
return replaceBlocks(blocksToRemove, blocksToInsert
|
|
817
|
+
return replaceBlocks(this, blocksToRemove, blocksToInsert);
|
|
905
818
|
}
|
|
906
819
|
|
|
907
820
|
/**
|
|
@@ -1049,12 +962,14 @@ export class BlockNoteEditor<
|
|
|
1049
962
|
* Checks if the block containing the text cursor can be nested.
|
|
1050
963
|
*/
|
|
1051
964
|
public canNestBlock() {
|
|
1052
|
-
const {
|
|
1053
|
-
this._tiptapEditor.state
|
|
1054
|
-
|
|
1055
|
-
)!;
|
|
965
|
+
const { blockContainer } = getBlockInfoFromSelection(
|
|
966
|
+
this._tiptapEditor.state
|
|
967
|
+
);
|
|
1056
968
|
|
|
1057
|
-
return
|
|
969
|
+
return (
|
|
970
|
+
this._tiptapEditor.state.doc.resolve(blockContainer.beforePos)
|
|
971
|
+
.nodeBefore !== null
|
|
972
|
+
);
|
|
1058
973
|
}
|
|
1059
974
|
|
|
1060
975
|
/**
|
|
@@ -1068,12 +983,13 @@ export class BlockNoteEditor<
|
|
|
1068
983
|
* Checks if the block containing the text cursor is nested.
|
|
1069
984
|
*/
|
|
1070
985
|
public canUnnestBlock() {
|
|
1071
|
-
const {
|
|
1072
|
-
this._tiptapEditor.state
|
|
1073
|
-
|
|
1074
|
-
)!;
|
|
986
|
+
const { blockContainer } = getBlockInfoFromSelection(
|
|
987
|
+
this._tiptapEditor.state
|
|
988
|
+
);
|
|
1075
989
|
|
|
1076
|
-
return
|
|
990
|
+
return (
|
|
991
|
+
this._tiptapEditor.state.doc.resolve(blockContainer.beforePos).depth > 1
|
|
992
|
+
);
|
|
1077
993
|
}
|
|
1078
994
|
|
|
1079
995
|
/**
|
|
@@ -1083,6 +999,24 @@ export class BlockNoteEditor<
|
|
|
1083
999
|
this._tiptapEditor.commands.liftListItem("blockContainer");
|
|
1084
1000
|
}
|
|
1085
1001
|
|
|
1002
|
+
/**
|
|
1003
|
+
* Moves the block containing the text cursor up. If the previous block has
|
|
1004
|
+
* children, moves it to the end of its children. If there is no previous
|
|
1005
|
+
* block, but the current block is nested, moves it out of & before its parent.
|
|
1006
|
+
*/
|
|
1007
|
+
public moveBlockUp() {
|
|
1008
|
+
moveBlockUp(this);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
/**
|
|
1012
|
+
* Moves the block containing the text cursor down. If the next block has
|
|
1013
|
+
* children, moves it to the start of its children. If there is no next block,
|
|
1014
|
+
* but the current block is nested, moves it out of & after its parent.
|
|
1015
|
+
*/
|
|
1016
|
+
public moveBlockDown() {
|
|
1017
|
+
moveBlockDown(this);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1086
1020
|
/**
|
|
1087
1021
|
* Exports blocks into a simplified HTML string. To better conform to HTML standards, children of blocks which aren't list
|
|
1088
1022
|
* items are un-nested in the output HTML.
|
|
@@ -1093,7 +1027,6 @@ export class BlockNoteEditor<
|
|
|
1093
1027
|
public async blocksToHTMLLossy(
|
|
1094
1028
|
blocks: PartialBlock<BSchema, ISchema, SSchema>[] = this.document
|
|
1095
1029
|
): Promise<string> {
|
|
1096
|
-
await initializeESMDependencies();
|
|
1097
1030
|
const exporter = createExternalHTMLExporter(this.pmSchema, this);
|
|
1098
1031
|
return exporter.exportBlocks(blocks, {});
|
|
1099
1032
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Extension, Extensions, extensions } from "@tiptap/core";
|
|
2
2
|
|
|
3
|
-
import type { BlockNoteEditor } from "./BlockNoteEditor";
|
|
3
|
+
import type { BlockNoteEditor } from "./BlockNoteEditor.js";
|
|
4
4
|
|
|
5
5
|
import Collaboration from "@tiptap/extension-collaboration";
|
|
6
6
|
import CollaborationCursor from "@tiptap/extension-collaboration-cursor";
|
|
@@ -11,15 +11,16 @@ import { History } from "@tiptap/extension-history";
|
|
|
11
11
|
import { Link } from "@tiptap/extension-link";
|
|
12
12
|
import { Text } from "@tiptap/extension-text";
|
|
13
13
|
import * as Y from "yjs";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { BackgroundColorExtension } from "../extensions/BackgroundColor/BackgroundColorExtension";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import
|
|
22
|
-
import
|
|
14
|
+
import { createDropFileExtension } from "../api/clipboard/fromClipboard/fileDropExtension.js";
|
|
15
|
+
import { createPasteFromClipboardExtension } from "../api/clipboard/fromClipboard/pasteExtension.js";
|
|
16
|
+
import { createCopyToClipboardExtension } from "../api/clipboard/toClipboard/copyExtension.js";
|
|
17
|
+
import { BackgroundColorExtension } from "../extensions/BackgroundColor/BackgroundColorExtension.js";
|
|
18
|
+
import { KeyboardShortcutsExtension } from "../extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js";
|
|
19
|
+
import { TextAlignmentExtension } from "../extensions/TextAlignment/TextAlignmentExtension.js";
|
|
20
|
+
import { TextColorExtension } from "../extensions/TextColor/TextColorExtension.js";
|
|
21
|
+
import { TrailingNode } from "../extensions/TrailingNode/TrailingNodeExtension.js";
|
|
22
|
+
import UniqueID from "../extensions/UniqueID/UniqueID.js";
|
|
23
|
+
import { BlockContainer, BlockGroup, Doc } from "../pm-nodes/index.js";
|
|
23
24
|
import {
|
|
24
25
|
BlockNoteDOMAttributes,
|
|
25
26
|
BlockSchema,
|
|
@@ -28,7 +29,7 @@ import {
|
|
|
28
29
|
InlineContentSpecs,
|
|
29
30
|
StyleSchema,
|
|
30
31
|
StyleSpecs,
|
|
31
|
-
} from "../schema";
|
|
32
|
+
} from "../schema/index.js";
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Get all the Tiptap extensions BlockNote is configured with by default
|
|
@@ -120,6 +121,9 @@ export const getBlockNoteExtensions = <
|
|
|
120
121
|
editor: opts.editor,
|
|
121
122
|
domAttributes: opts.domAttributes,
|
|
122
123
|
}),
|
|
124
|
+
KeyboardShortcutsExtension.configure({
|
|
125
|
+
editor: opts.editor,
|
|
126
|
+
}),
|
|
123
127
|
BlockGroup.configure({
|
|
124
128
|
domAttributes: opts.domAttributes,
|
|
125
129
|
}),
|
|
@@ -2,7 +2,11 @@ import {
|
|
|
2
2
|
defaultBlockSpecs,
|
|
3
3
|
defaultInlineContentSpecs,
|
|
4
4
|
defaultStyleSpecs,
|
|
5
|
-
} from "../blocks/defaultBlocks";
|
|
5
|
+
} from "../blocks/defaultBlocks.js";
|
|
6
|
+
import type {
|
|
7
|
+
BlockNoDefaults,
|
|
8
|
+
PartialBlockNoDefaults,
|
|
9
|
+
} from "../schema/blocks/types.js";
|
|
6
10
|
import {
|
|
7
11
|
BlockSchema,
|
|
8
12
|
BlockSchemaFromSpecs,
|
|
@@ -16,12 +20,8 @@ import {
|
|
|
16
20
|
getBlockSchemaFromSpecs,
|
|
17
21
|
getInlineContentSchemaFromSpecs,
|
|
18
22
|
getStyleSchemaFromSpecs,
|
|
19
|
-
} from "../schema";
|
|
20
|
-
import type {
|
|
21
|
-
BlockNoDefaults,
|
|
22
|
-
PartialBlockNoDefaults,
|
|
23
|
-
} from "../schema/blocks/types";
|
|
24
|
-
import type { BlockNoteEditor } from "./BlockNoteEditor";
|
|
23
|
+
} from "../schema/index.js";
|
|
24
|
+
import type { BlockNoteEditor } from "./BlockNoteEditor.js";
|
|
25
25
|
|
|
26
26
|
function removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {
|
|
27
27
|
if (!obj) {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { EditorOptions, createDocument } from "@tiptap/core";
|
|
2
2
|
// import "./blocknote.css";
|
|
3
3
|
import { Editor as TiptapEditor } from "@tiptap/core";
|
|
4
|
+
|
|
4
5
|
import { Node } from "@tiptap/pm/model";
|
|
6
|
+
|
|
5
7
|
import { EditorView } from "@tiptap/pm/view";
|
|
6
8
|
|
|
7
9
|
import { EditorState, Transaction } from "@tiptap/pm/state";
|
|
8
|
-
import { blockToNode } from "../api/nodeConversions/
|
|
9
|
-
import { PartialBlock } from "../blocks/defaultBlocks";
|
|
10
|
-
import { StyleSchema } from "../schema";
|
|
10
|
+
import { blockToNode } from "../api/nodeConversions/blockToNode.js";
|
|
11
|
+
import { PartialBlock } from "../blocks/defaultBlocks.js";
|
|
12
|
+
import { StyleSchema } from "../schema/index.js";
|
|
11
13
|
|
|
12
14
|
export type BlockNoteTipTapEditorOptions = Partial<
|
|
13
15
|
Omit<EditorOptions, "content">
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { Block } from "../blocks/defaultBlocks";
|
|
2
|
-
import {
|
|
1
|
+
import { Block } from "../blocks/defaultBlocks.js";
|
|
2
|
+
import {
|
|
3
|
+
BlockSchema,
|
|
4
|
+
InlineContentSchema,
|
|
5
|
+
StyleSchema,
|
|
6
|
+
} from "../schema/index.js";
|
|
3
7
|
|
|
4
8
|
export type TextCursorPosition<
|
|
5
9
|
BSchema extends BlockSchema,
|
|
@@ -9,4 +13,5 @@ export type TextCursorPosition<
|
|
|
9
13
|
block: Block<BSchema, I, S>;
|
|
10
14
|
prevBlock: Block<BSchema, I, S> | undefined;
|
|
11
15
|
nextBlock: Block<BSchema, I, S> | undefined;
|
|
16
|
+
parentBlock: Block<BSchema, I, S> | undefined;
|
|
12
17
|
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { Block } from "../blocks/defaultBlocks";
|
|
2
|
-
import {
|
|
1
|
+
import { Block } from "../blocks/defaultBlocks.js";
|
|
2
|
+
import {
|
|
3
|
+
BlockSchema,
|
|
4
|
+
InlineContentSchema,
|
|
5
|
+
StyleSchema,
|
|
6
|
+
} from "../schema/index.js";
|
|
3
7
|
|
|
4
8
|
export type Selection<
|
|
5
9
|
BSchema extends BlockSchema,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fragment, Slice } from "@tiptap/pm/model";
|
|
1
|
+
import { Fragment, Schema, Slice } from "@tiptap/pm/model";
|
|
2
2
|
import { EditorView } from "@tiptap/pm/view";
|
|
3
3
|
|
|
4
4
|
// helper function to remove a child from a fragment
|
|
@@ -12,6 +12,37 @@ function removeChild(node: Fragment, n: number) {
|
|
|
12
12
|
return Fragment.from(children);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Wrap adjacent tableRow items in a table.
|
|
17
|
+
*
|
|
18
|
+
* This makes sure the content that we paste is always a table (and not a tableRow)
|
|
19
|
+
* A table works better for the remaing paste handling logic, as it's actually a blockContent node
|
|
20
|
+
*/
|
|
21
|
+
export function wrapTableRows(f: Fragment, schema: Schema) {
|
|
22
|
+
const newItems: any[] = [];
|
|
23
|
+
for (let i = 0; i < f.childCount; i++) {
|
|
24
|
+
if (f.child(i).type.name === "tableRow") {
|
|
25
|
+
if (
|
|
26
|
+
newItems.length > 0 &&
|
|
27
|
+
newItems[newItems.length - 1].type.name === "table"
|
|
28
|
+
) {
|
|
29
|
+
// append to existing table
|
|
30
|
+
const prevTable = newItems[newItems.length - 1];
|
|
31
|
+
const newTable = prevTable.copy(prevTable.content.addToEnd(f.child(i)));
|
|
32
|
+
newItems[newItems.length - 1] = newTable;
|
|
33
|
+
} else {
|
|
34
|
+
// create new table to wrap tableRow with
|
|
35
|
+
const newTable = schema.nodes.table.create(undefined, f.child(i));
|
|
36
|
+
newItems.push(newTable);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
newItems.push(f.child(i));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
f = Fragment.from(newItems);
|
|
43
|
+
return f;
|
|
44
|
+
}
|
|
45
|
+
|
|
15
46
|
/**
|
|
16
47
|
* fix for https://github.com/ProseMirror/prosemirror/issues/1430#issuecomment-1822570821
|
|
17
48
|
*
|
|
@@ -23,6 +54,8 @@ function removeChild(node: Fragment, n: number) {
|
|
|
23
54
|
*/
|
|
24
55
|
export function transformPasted(slice: Slice, view: EditorView) {
|
|
25
56
|
let f = Fragment.from(slice.content);
|
|
57
|
+
f = wrapTableRows(f, view.state.schema);
|
|
58
|
+
|
|
26
59
|
for (let i = 0; i < f.childCount; i++) {
|
|
27
60
|
if (f.child(i).type.spec.group === "blockContent") {
|
|
28
61
|
const content = [f.child(i)];
|
|
@@ -54,6 +87,5 @@ export function transformPasted(slice: Slice, view: EditorView) {
|
|
|
54
87
|
f = f.replaceChild(i, container);
|
|
55
88
|
}
|
|
56
89
|
}
|
|
57
|
-
|
|
58
90
|
return new Slice(f, slice.openStart, slice.openEnd);
|
|
59
91
|
}
|