@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 @@
|
|
|
1
|
+
<tr><td colspan="1" rowspan="1"><p>Table Cell</p></td><td colspan="1" rowspan="1"><p>Table Cell</p></td></tr><tr><td colspan="1" rowspan="1"><p>Table Cell</p></td><td colspan="1" rowspan="1"><p>Table Cell</p></td></tr>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<tr><td colspan="1" rowspan="1"><p>Table Cell</p></td></tr>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Table Cell
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<tr><td colspan="1" rowspan="1"><p>Table Cell</p></td><td colspan="1" rowspan="1"><p>Table Cell</p></td></tr>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Regular
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
import { NodeSelection, Selection, TextSelection } from "prosemirror-state";
|
|
3
|
+
import { CellSelection } from "prosemirror-tables";
|
|
4
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { PartialBlock } from "../../blocks/defaultBlocks.js";
|
|
7
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
8
|
+
import { initializeESMDependencies } from "../../util/esmDependencies.js";
|
|
9
|
+
import { doPaste } from "../testUtil/paste.js";
|
|
10
|
+
import { selectedFragmentToHTML } from "./toClipboard/copyExtension.js";
|
|
11
|
+
|
|
12
|
+
type SelectionTestCase = {
|
|
13
|
+
testName: string;
|
|
14
|
+
createSelection: (doc: Node) => Selection;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// These tests are meant to test the copying of user selections in the editor.
|
|
18
|
+
// The test cases used for the other HTML conversion tests are not suitable here
|
|
19
|
+
// as they are represented in the BlockNote API, whereas here we want to test
|
|
20
|
+
// ProseMirror/TipTap selections directly.
|
|
21
|
+
describe("Test ProseMirror selection clipboard HTML", () => {
|
|
22
|
+
const initialContent: PartialBlock[] = [
|
|
23
|
+
{
|
|
24
|
+
type: "heading",
|
|
25
|
+
props: {
|
|
26
|
+
level: 2,
|
|
27
|
+
textColor: "red",
|
|
28
|
+
},
|
|
29
|
+
content: "Heading 1",
|
|
30
|
+
children: [
|
|
31
|
+
{
|
|
32
|
+
type: "paragraph",
|
|
33
|
+
content: "Nested Paragraph 1",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: "paragraph",
|
|
37
|
+
content: "Nested Paragraph 2",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "paragraph",
|
|
41
|
+
content: "Nested Paragraph 3",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "heading",
|
|
47
|
+
props: {
|
|
48
|
+
level: 2,
|
|
49
|
+
textColor: "red",
|
|
50
|
+
},
|
|
51
|
+
content: "Heading 2",
|
|
52
|
+
children: [
|
|
53
|
+
{
|
|
54
|
+
type: "paragraph",
|
|
55
|
+
content: "Nested Paragraph 1",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: "paragraph",
|
|
59
|
+
content: "Nested Paragraph 2",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: "paragraph",
|
|
63
|
+
content: "Nested Paragraph 3",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: "heading",
|
|
69
|
+
props: {
|
|
70
|
+
level: 2,
|
|
71
|
+
textColor: "red",
|
|
72
|
+
},
|
|
73
|
+
content: [
|
|
74
|
+
{
|
|
75
|
+
type: "text",
|
|
76
|
+
text: "Bold",
|
|
77
|
+
styles: {
|
|
78
|
+
bold: true,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: "text",
|
|
83
|
+
text: "Italic",
|
|
84
|
+
styles: {
|
|
85
|
+
italic: true,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
type: "text",
|
|
90
|
+
text: "Regular",
|
|
91
|
+
styles: {},
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
children: [
|
|
95
|
+
{
|
|
96
|
+
type: "image",
|
|
97
|
+
props: {
|
|
98
|
+
url: "https://ralfvanveen.com/wp-content/uploads/2021/06/Placeholder-_-Glossary.svg",
|
|
99
|
+
},
|
|
100
|
+
children: [
|
|
101
|
+
{
|
|
102
|
+
type: "paragraph",
|
|
103
|
+
content: "Nested Paragraph",
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
type: "table",
|
|
111
|
+
content: {
|
|
112
|
+
type: "tableContent",
|
|
113
|
+
rows: [
|
|
114
|
+
{
|
|
115
|
+
cells: ["Table Cell", "Table Cell"],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
cells: ["Table Cell", "Table Cell"],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
// Not needed as selections starting in table cells will get snapped to
|
|
123
|
+
// the table boundaries.
|
|
124
|
+
// children: [
|
|
125
|
+
// {
|
|
126
|
+
// type: "table",
|
|
127
|
+
// content: {
|
|
128
|
+
// type: "tableContent",
|
|
129
|
+
// rows: [
|
|
130
|
+
// {
|
|
131
|
+
// cells: ["Table Cell", "Table Cell"],
|
|
132
|
+
// },
|
|
133
|
+
// {
|
|
134
|
+
// cells: ["Table Cell", "Table Cell"],
|
|
135
|
+
// },
|
|
136
|
+
// ],
|
|
137
|
+
// },
|
|
138
|
+
// },
|
|
139
|
+
// ],
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
let editor: BlockNoteEditor;
|
|
144
|
+
const div = document.createElement("div");
|
|
145
|
+
|
|
146
|
+
beforeEach(() => {
|
|
147
|
+
editor.replaceBlocks(editor.document, initialContent);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
beforeAll(async () => {
|
|
151
|
+
(window as any).__TEST_OPTIONS = (window as any).__TEST_OPTIONS || {};
|
|
152
|
+
|
|
153
|
+
editor = BlockNoteEditor.create();
|
|
154
|
+
editor.mount(div);
|
|
155
|
+
|
|
156
|
+
await initializeESMDependencies();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
afterAll(() => {
|
|
160
|
+
editor.mount(undefined);
|
|
161
|
+
editor._tiptapEditor.destroy();
|
|
162
|
+
editor = undefined as any;
|
|
163
|
+
|
|
164
|
+
delete (window as Window & { __TEST_OPTIONS?: any }).__TEST_OPTIONS;
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Sets the editor selection to the given start and end positions, then
|
|
168
|
+
// exports the selected content to HTML and compares it to a snapshot.
|
|
169
|
+
async function testSelection(testCase: SelectionTestCase) {
|
|
170
|
+
editor.dispatch(
|
|
171
|
+
editor._tiptapEditor.state.tr.setSelection(
|
|
172
|
+
testCase.createSelection(editor._tiptapEditor.view.state.doc)
|
|
173
|
+
)
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const { clipboardHTML, externalHTML } = await selectedFragmentToHTML(
|
|
177
|
+
editor._tiptapEditor.view,
|
|
178
|
+
editor
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
expect(externalHTML).toMatchFileSnapshot(
|
|
182
|
+
`./__snapshots__/${testCase.testName}.html`
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const originalDocument = editor.document;
|
|
186
|
+
doPaste(
|
|
187
|
+
editor._tiptapEditor.view,
|
|
188
|
+
"text",
|
|
189
|
+
clipboardHTML,
|
|
190
|
+
false,
|
|
191
|
+
new ClipboardEvent("paste")
|
|
192
|
+
);
|
|
193
|
+
const newDocument = editor.document;
|
|
194
|
+
|
|
195
|
+
expect(newDocument).toStrictEqual(originalDocument);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const testCases: SelectionTestCase[] = [
|
|
199
|
+
// TODO: Consider adding test cases for nested blocks & double nested blocks.
|
|
200
|
+
// Selection spans all of first heading's children.
|
|
201
|
+
{
|
|
202
|
+
testName: "multipleChildren",
|
|
203
|
+
createSelection: (doc) => TextSelection.create(doc, 16, 78),
|
|
204
|
+
},
|
|
205
|
+
// Selection spans from start of first heading to end of its first child.
|
|
206
|
+
{
|
|
207
|
+
testName: "childToParent",
|
|
208
|
+
createSelection: (doc) => TextSelection.create(doc, 3, 34),
|
|
209
|
+
},
|
|
210
|
+
// Selection spans from middle of first heading to the middle of its first
|
|
211
|
+
// child.
|
|
212
|
+
{
|
|
213
|
+
testName: "partialChildToParent",
|
|
214
|
+
createSelection: (doc) => TextSelection.create(doc, 6, 23),
|
|
215
|
+
},
|
|
216
|
+
// Selection spans from start of first heading's first child to end of
|
|
217
|
+
// second heading's content (does not include second heading's children).
|
|
218
|
+
{
|
|
219
|
+
testName: "childrenToNextParent",
|
|
220
|
+
createSelection: (doc) => TextSelection.create(doc, 16, 93),
|
|
221
|
+
},
|
|
222
|
+
// Selection spans from start of first heading's first child to end of
|
|
223
|
+
// second heading's last child.
|
|
224
|
+
{
|
|
225
|
+
testName: "childrenToNextParentsChildren",
|
|
226
|
+
createSelection: (doc) => TextSelection.create(doc, 16, 159),
|
|
227
|
+
},
|
|
228
|
+
// Selection spans "Regular" text inside third heading.
|
|
229
|
+
{
|
|
230
|
+
testName: "unstyledText",
|
|
231
|
+
createSelection: (doc) => TextSelection.create(doc, 175, 182),
|
|
232
|
+
},
|
|
233
|
+
// Selection spans "Italic" text inside third heading.
|
|
234
|
+
{
|
|
235
|
+
testName: "styledText",
|
|
236
|
+
createSelection: (doc) => TextSelection.create(doc, 169, 175),
|
|
237
|
+
},
|
|
238
|
+
// Selection spans third heading's content (does not include third heading's
|
|
239
|
+
// children).
|
|
240
|
+
{
|
|
241
|
+
testName: "multipleStyledText",
|
|
242
|
+
createSelection: (doc) => TextSelection.create(doc, 165, 182),
|
|
243
|
+
},
|
|
244
|
+
// Selection spans the image block content.
|
|
245
|
+
{
|
|
246
|
+
testName: "image",
|
|
247
|
+
createSelection: (doc) => NodeSelection.create(doc, 185),
|
|
248
|
+
},
|
|
249
|
+
// Selection spans from start of third heading to end of it's last
|
|
250
|
+
// descendant.
|
|
251
|
+
{
|
|
252
|
+
testName: "nestedImage",
|
|
253
|
+
createSelection: (doc) => TextSelection.create(doc, 165, 205),
|
|
254
|
+
},
|
|
255
|
+
// Selection spans text in first cell of the table.
|
|
256
|
+
{
|
|
257
|
+
testName: "tableCellText",
|
|
258
|
+
createSelection: (doc) => TextSelection.create(doc, 216, 226),
|
|
259
|
+
},
|
|
260
|
+
// Selection spans first cell of the table.
|
|
261
|
+
// TODO: External HTML is wrapped in unnecessary `tr` element.
|
|
262
|
+
{
|
|
263
|
+
testName: "tableCell",
|
|
264
|
+
createSelection: (doc) => CellSelection.create(doc, 214),
|
|
265
|
+
},
|
|
266
|
+
// Selection spans first row of the table.
|
|
267
|
+
{
|
|
268
|
+
testName: "tableRow",
|
|
269
|
+
createSelection: (doc) => CellSelection.create(doc, 214, 228),
|
|
270
|
+
},
|
|
271
|
+
// Selection spans all cells of the table.
|
|
272
|
+
{
|
|
273
|
+
testName: "tableAllCells",
|
|
274
|
+
createSelection: (doc) => CellSelection.create(doc, 214, 258),
|
|
275
|
+
},
|
|
276
|
+
];
|
|
277
|
+
|
|
278
|
+
for (const testCase of testCases) {
|
|
279
|
+
it(`${testCase.testName}`, async () => {
|
|
280
|
+
await testSelection(testCase);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
});
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Extension } from "@tiptap/core";
|
|
2
2
|
import { Plugin } from "prosemirror-state";
|
|
3
3
|
|
|
4
|
-
import type { BlockNoteEditor } from "
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
|
|
5
|
+
import {
|
|
6
|
+
BlockSchema,
|
|
7
|
+
InlineContentSchema,
|
|
8
|
+
StyleSchema,
|
|
9
|
+
} from "../../../schema/index.js";
|
|
10
|
+
import { acceptedMIMETypes } from "./acceptedMIMETypes.js";
|
|
11
|
+
import { handleFileInsertion } from "./handleFileInsertion.js";
|
|
8
12
|
|
|
9
13
|
export const createDropFileExtension = <
|
|
10
14
|
BSchema extends BlockSchema,
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { PartialBlock } from "../../../blocks/defaultBlocks.js";
|
|
2
|
+
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
|
|
3
3
|
import {
|
|
4
4
|
BlockSchema,
|
|
5
5
|
FileBlockConfig,
|
|
6
6
|
InlineContentSchema,
|
|
7
7
|
StyleSchema,
|
|
8
|
-
} from "
|
|
9
|
-
import {
|
|
10
|
-
|
|
8
|
+
} from "../../../schema/index.js";
|
|
9
|
+
import {
|
|
10
|
+
getBlockInfo,
|
|
11
|
+
getNearestBlockContainerPos,
|
|
12
|
+
} from "../../getBlockInfoFromPos.js";
|
|
13
|
+
import { acceptedMIMETypes } from "./acceptedMIMETypes.js";
|
|
11
14
|
|
|
12
15
|
function checkFileExtensionsMatch(
|
|
13
16
|
fileExtension1: string,
|
|
@@ -132,14 +135,16 @@ export async function handleFileInsertion<
|
|
|
132
135
|
return;
|
|
133
136
|
}
|
|
134
137
|
|
|
135
|
-
const
|
|
138
|
+
const posInfo = getNearestBlockContainerPos(
|
|
136
139
|
editor._tiptapEditor.state.doc,
|
|
137
140
|
pos.pos
|
|
138
141
|
);
|
|
139
142
|
|
|
143
|
+
const blockInfo = getBlockInfo(posInfo);
|
|
144
|
+
|
|
140
145
|
insertedBlockId = editor.insertBlocks(
|
|
141
146
|
[fileBlock],
|
|
142
|
-
blockInfo.id,
|
|
147
|
+
blockInfo.blockContainer.node.attrs.id,
|
|
143
148
|
"after"
|
|
144
149
|
)[0].id;
|
|
145
150
|
} else {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Extension } from "@tiptap/core";
|
|
2
2
|
import { Plugin } from "prosemirror-state";
|
|
3
3
|
|
|
4
|
-
import type { BlockNoteEditor } from "
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
|
|
5
|
+
import {
|
|
6
|
+
BlockSchema,
|
|
7
|
+
InlineContentSchema,
|
|
8
|
+
StyleSchema,
|
|
9
|
+
} from "../../../schema/index.js";
|
|
10
|
+
import { nestedListsToBlockNoteStructure } from "../../parsers/html/util/nestedLists.js";
|
|
11
|
+
import { acceptedMIMETypes } from "./acceptedMIMETypes.js";
|
|
12
|
+
import { handleFileInsertion } from "./handleFileInsertion.js";
|
|
9
13
|
|
|
10
14
|
export const createPasteFromClipboardExtension = <
|
|
11
15
|
BSchema extends BlockSchema,
|
|
@@ -28,14 +32,14 @@ export const createPasteFromClipboardExtension = <
|
|
|
28
32
|
return;
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
let format: (typeof acceptedMIMETypes)[number] |
|
|
35
|
+
let format: (typeof acceptedMIMETypes)[number] | undefined;
|
|
32
36
|
for (const mimeType of acceptedMIMETypes) {
|
|
33
37
|
if (event.clipboardData!.types.includes(mimeType)) {
|
|
34
38
|
format = mimeType;
|
|
35
39
|
break;
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
|
-
if (format
|
|
42
|
+
if (!format) {
|
|
39
43
|
return true;
|
|
40
44
|
}
|
|
41
45
|
|
|
@@ -46,12 +50,19 @@ export const createPasteFromClipboardExtension = <
|
|
|
46
50
|
|
|
47
51
|
let data = event.clipboardData!.getData(format);
|
|
48
52
|
|
|
53
|
+
if (format === "blocknote/html") {
|
|
54
|
+
editor._tiptapEditor.view.pasteHTML(data);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
49
58
|
if (format === "text/html") {
|
|
50
59
|
const htmlNode = nestedListsToBlockNoteStructure(data.trim());
|
|
51
60
|
data = htmlNode.innerHTML;
|
|
61
|
+
editor._tiptapEditor.view.pasteHTML(data);
|
|
62
|
+
return true;
|
|
52
63
|
}
|
|
53
64
|
|
|
54
|
-
editor._tiptapEditor.view.
|
|
65
|
+
editor._tiptapEditor.view.pasteText(data);
|
|
55
66
|
|
|
56
67
|
return true;
|
|
57
68
|
},
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
import { Fragment, Node } from "prosemirror-model";
|
|
3
|
+
import { NodeSelection, Plugin } from "prosemirror-state";
|
|
4
|
+
import { CellSelection } from "prosemirror-tables";
|
|
5
|
+
import * as pmView from "prosemirror-view";
|
|
6
|
+
|
|
7
|
+
import { EditorView } from "prosemirror-view";
|
|
8
|
+
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
|
|
9
|
+
import {
|
|
10
|
+
BlockSchema,
|
|
11
|
+
InlineContentSchema,
|
|
12
|
+
StyleSchema,
|
|
13
|
+
} from "../../../schema/index.js";
|
|
14
|
+
import { createExternalHTMLExporter } from "../../exporters/html/externalHTMLExporter.js";
|
|
15
|
+
import { cleanHTMLToMarkdown } from "../../exporters/markdown/markdownExporter.js";
|
|
16
|
+
import { fragmentToBlocks } from "../../nodeConversions/fragmentToBlocks.js";
|
|
17
|
+
import {
|
|
18
|
+
contentNodeToInlineContent,
|
|
19
|
+
contentNodeToTableContent,
|
|
20
|
+
} from "../../nodeConversions/nodeToBlock.js";
|
|
21
|
+
|
|
22
|
+
function fragmentToExternalHTML<
|
|
23
|
+
BSchema extends BlockSchema,
|
|
24
|
+
I extends InlineContentSchema,
|
|
25
|
+
S extends StyleSchema
|
|
26
|
+
>(
|
|
27
|
+
view: pmView.EditorView,
|
|
28
|
+
selectedFragment: Fragment,
|
|
29
|
+
editor: BlockNoteEditor<BSchema, I, S>
|
|
30
|
+
) {
|
|
31
|
+
let isWithinBlockContent = false;
|
|
32
|
+
const isWithinTable = view.state.selection instanceof CellSelection;
|
|
33
|
+
|
|
34
|
+
if (!isWithinTable) {
|
|
35
|
+
// Checks whether block ancestry should be included when creating external
|
|
36
|
+
// HTML. If the selection is within a block content node, the block ancestry
|
|
37
|
+
// is excluded as we only care about the inline content.
|
|
38
|
+
const fragmentWithoutParents = view.state.doc.slice(
|
|
39
|
+
view.state.selection.from,
|
|
40
|
+
view.state.selection.to,
|
|
41
|
+
false
|
|
42
|
+
).content;
|
|
43
|
+
|
|
44
|
+
const children = [];
|
|
45
|
+
for (let i = 0; i < fragmentWithoutParents.childCount; i++) {
|
|
46
|
+
children.push(fragmentWithoutParents.child(i));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
isWithinBlockContent =
|
|
50
|
+
children.find(
|
|
51
|
+
(child) =>
|
|
52
|
+
child.type.name === "blockContainer" ||
|
|
53
|
+
child.type.name === "blockGroup" ||
|
|
54
|
+
child.type.spec.group === "blockContent"
|
|
55
|
+
) === undefined;
|
|
56
|
+
if (isWithinBlockContent) {
|
|
57
|
+
selectedFragment = fragmentWithoutParents;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let externalHTML: string;
|
|
62
|
+
|
|
63
|
+
const externalHTMLExporter = createExternalHTMLExporter(
|
|
64
|
+
view.state.schema,
|
|
65
|
+
editor
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (isWithinTable) {
|
|
69
|
+
if (selectedFragment.firstChild?.type.name === "table") {
|
|
70
|
+
// contentNodeToTableContent expects the fragment of the content of a table, not the table node itself
|
|
71
|
+
// but cellselection.content() returns the table node itself if all cells and columns are selected
|
|
72
|
+
selectedFragment = selectedFragment.firstChild.content;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// first convert selection to blocknote-style table content, and then
|
|
76
|
+
// pass this to the exporter
|
|
77
|
+
const ic = contentNodeToTableContent(
|
|
78
|
+
selectedFragment as any,
|
|
79
|
+
editor.schema.inlineContentSchema,
|
|
80
|
+
editor.schema.styleSchema
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
externalHTML = externalHTMLExporter.exportInlineContent(ic as any, {});
|
|
84
|
+
} else if (isWithinBlockContent) {
|
|
85
|
+
// first convert selection to blocknote-style inline content, and then
|
|
86
|
+
// pass this to the exporter
|
|
87
|
+
const ic = contentNodeToInlineContent(
|
|
88
|
+
selectedFragment as any,
|
|
89
|
+
editor.schema.inlineContentSchema,
|
|
90
|
+
editor.schema.styleSchema
|
|
91
|
+
);
|
|
92
|
+
externalHTML = externalHTMLExporter.exportInlineContent(ic, {});
|
|
93
|
+
} else {
|
|
94
|
+
const blocks = fragmentToBlocks(selectedFragment, editor.schema);
|
|
95
|
+
externalHTML = externalHTMLExporter.exportBlocks(blocks, {});
|
|
96
|
+
}
|
|
97
|
+
return externalHTML;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function selectedFragmentToHTML<
|
|
101
|
+
BSchema extends BlockSchema,
|
|
102
|
+
I extends InlineContentSchema,
|
|
103
|
+
S extends StyleSchema
|
|
104
|
+
>(
|
|
105
|
+
view: EditorView,
|
|
106
|
+
editor: BlockNoteEditor<BSchema, I, S>
|
|
107
|
+
): {
|
|
108
|
+
clipboardHTML: string;
|
|
109
|
+
externalHTML: string;
|
|
110
|
+
markdown: string;
|
|
111
|
+
} {
|
|
112
|
+
// Checks if a `blockContent` node is being copied and expands
|
|
113
|
+
// the selection to the parent `blockContainer` node. This is
|
|
114
|
+
// for the use-case in which only a block without content is
|
|
115
|
+
// selected, e.g. an image block.
|
|
116
|
+
if (
|
|
117
|
+
"node" in view.state.selection &&
|
|
118
|
+
(view.state.selection.node as Node).type.spec.group === "blockContent"
|
|
119
|
+
) {
|
|
120
|
+
editor.dispatch(
|
|
121
|
+
editor._tiptapEditor.state.tr.setSelection(
|
|
122
|
+
new NodeSelection(view.state.doc.resolve(view.state.selection.from - 1))
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Uses default ProseMirror clipboard serialization.
|
|
128
|
+
const clipboardHTML: string = (pmView as any).__serializeForClipboard(
|
|
129
|
+
view,
|
|
130
|
+
view.state.selection.content()
|
|
131
|
+
).dom.innerHTML;
|
|
132
|
+
|
|
133
|
+
const selectedFragment = view.state.selection.content().content;
|
|
134
|
+
|
|
135
|
+
const externalHTML = fragmentToExternalHTML<BSchema, I, S>(
|
|
136
|
+
view,
|
|
137
|
+
selectedFragment,
|
|
138
|
+
editor
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const markdown = cleanHTMLToMarkdown(externalHTML);
|
|
142
|
+
|
|
143
|
+
return { clipboardHTML, externalHTML, markdown };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const copyToClipboard = <
|
|
147
|
+
BSchema extends BlockSchema,
|
|
148
|
+
I extends InlineContentSchema,
|
|
149
|
+
S extends StyleSchema
|
|
150
|
+
>(
|
|
151
|
+
editor: BlockNoteEditor<BSchema, I, S>,
|
|
152
|
+
view: EditorView,
|
|
153
|
+
event: ClipboardEvent
|
|
154
|
+
) => {
|
|
155
|
+
// Stops the default browser copy behaviour.
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
event.clipboardData!.clearData();
|
|
158
|
+
|
|
159
|
+
const { clipboardHTML, externalHTML, markdown } = selectedFragmentToHTML(
|
|
160
|
+
view,
|
|
161
|
+
editor
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// TODO: Writing to other MIME types not working in Safari for
|
|
165
|
+
// some reason.
|
|
166
|
+
event.clipboardData!.setData("blocknote/html", clipboardHTML);
|
|
167
|
+
event.clipboardData!.setData("text/html", externalHTML);
|
|
168
|
+
event.clipboardData!.setData("text/plain", markdown);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export const createCopyToClipboardExtension = <
|
|
172
|
+
BSchema extends BlockSchema,
|
|
173
|
+
I extends InlineContentSchema,
|
|
174
|
+
S extends StyleSchema
|
|
175
|
+
>(
|
|
176
|
+
editor: BlockNoteEditor<BSchema, I, S>
|
|
177
|
+
) =>
|
|
178
|
+
Extension.create<{ editor: BlockNoteEditor<BSchema, I, S> }, undefined>({
|
|
179
|
+
name: "copyToClipboard",
|
|
180
|
+
addProseMirrorPlugins() {
|
|
181
|
+
return [
|
|
182
|
+
new Plugin({
|
|
183
|
+
props: {
|
|
184
|
+
handleDOMEvents: {
|
|
185
|
+
copy(view, event) {
|
|
186
|
+
copyToClipboard(editor, view, event);
|
|
187
|
+
// Prevent default PM handler to be called
|
|
188
|
+
return true;
|
|
189
|
+
},
|
|
190
|
+
cut(view, event) {
|
|
191
|
+
copyToClipboard(editor, view, event);
|
|
192
|
+
view.dispatch(view.state.tr.deleteSelection());
|
|
193
|
+
// Prevent default PM handler to be called
|
|
194
|
+
return true;
|
|
195
|
+
},
|
|
196
|
+
// This is for the use-case in which only a block without content
|
|
197
|
+
// is selected, e.g. an image block, and dragged (not using the
|
|
198
|
+
// drag handle).
|
|
199
|
+
dragstart(view, event) {
|
|
200
|
+
// Checks if a `NodeSelection` is active.
|
|
201
|
+
if (!("node" in view.state.selection)) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Checks if a `blockContent` node is being dragged.
|
|
206
|
+
if (
|
|
207
|
+
(view.state.selection.node as Node).type.spec.group !==
|
|
208
|
+
"blockContent"
|
|
209
|
+
) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Expands the selection to the parent `blockContainer` node.
|
|
214
|
+
editor.dispatch(
|
|
215
|
+
editor._tiptapEditor.state.tr.setSelection(
|
|
216
|
+
new NodeSelection(
|
|
217
|
+
view.state.doc.resolve(view.state.selection.from - 1)
|
|
218
|
+
)
|
|
219
|
+
)
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
// Stops the default browser drag start behaviour.
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
event.dataTransfer!.clearData();
|
|
225
|
+
|
|
226
|
+
const { clipboardHTML, externalHTML, markdown } =
|
|
227
|
+
selectedFragmentToHTML(view, editor);
|
|
228
|
+
|
|
229
|
+
// TODO: Writing to other MIME types not working in Safari for
|
|
230
|
+
// some reason.
|
|
231
|
+
event.dataTransfer!.setData("blocknote/html", clipboardHTML);
|
|
232
|
+
event.dataTransfer!.setData("text/html", externalHTML);
|
|
233
|
+
event.dataTransfer!.setData("text/plain", markdown);
|
|
234
|
+
|
|
235
|
+
// Prevent default PM handler to be called
|
|
236
|
+
return true;
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
}),
|
|
241
|
+
];
|
|
242
|
+
},
|
|
243
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<h2 data-text-color="yellow" data-background-color="blue" data-text-alignment="right" data-level="2"><strong><u>Heading </u></strong><em><s>2</s></em></h2><p data-background-color="red">Paragraph</p><ul><li><p
|
|
1
|
+
<h2 data-text-color="yellow" data-background-color="blue" data-text-alignment="right" data-level="2"><strong><u>Heading </u></strong><em><s>2</s></em></h2><p data-background-color="red">Paragraph</p><ul><li><p></p></li></ul>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<ul><li><p
|
|
1
|
+
<ul><li><p>Bullet List Item 1</p></li><li><p>Bullet List Item 2</p></li></ul><ol><li><p>Numbered List Item 1</p></li><li><p>Numbered List Item 2</p></li></ol><ul><li><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></li><li><input type="checkbox" checked="" data-checked="true"><p class="bn-inline-content">Check List Item 2</p></li></ul>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<ul><li><p
|
|
1
|
+
<ul><li><p>Bullet List Item 1</p></li><li><p>Bullet List Item 2</p><ol><li><p>Numbered List Item 1</p></li><li><p>Numbered List Item 2</p><ul><li><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></li><li><input type="checkbox" checked="" data-checked="true"><p class="bn-inline-content">Check List Item 2</p></li></ul></li></ol></li></ul>
|