@blocknote/core 0.9.5 → 0.10.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 +3699 -2600
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +7 -7
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -0
- package/package.json +8 -4
- package/src/api/README.md +8 -0
- package/src/api/blockManipulation/blockManipulation.test.ts +72 -10
- package/src/api/blockManipulation/blockManipulation.ts +38 -18
- package/src/api/exporters/copyExtension.ts +68 -0
- package/src/api/exporters/html/__snapshots__/complex/misc/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/complex/misc/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/nested/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/nested/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/styled/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/styled/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/fontSize/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/fontSize/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/between-links/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/between-links/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/end/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/end/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/link/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/link/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/multiple/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/multiple/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/only/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/only/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/start/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/start/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/styles/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/styles/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/button/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/button/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/nested/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/adjacent/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/adjacent/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/styled/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/styled/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/mention/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/mention/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/empty/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/empty/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/nested/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/nested/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/styled/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/styled/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-basic-block-types.json +140 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-deep-nested-content.json +240 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-div-with-inline-content.json +91 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-divs.json +19 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-fake-image-caption.json +31 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-mixed-nested-lists.json +70 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-nested-lists-with-paragraphs.json +70 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-nested-lists.json +70 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/button/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/button/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/small/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/small/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/tag/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/tag/basic/internal.html +1 -0
- package/src/api/exporters/html/externalHTMLExporter.ts +98 -0
- package/src/api/exporters/html/htmlConversion.test.ts +100 -0
- package/src/api/exporters/html/internalHTMLSerializer.ts +80 -0
- package/src/api/exporters/html/util/sharedHTMLConversion.ts +128 -0
- package/src/api/{formatConversions → exporters/html/util}/simplifyBlocksRehypePlugin.ts +13 -0
- package/src/api/exporters/markdown/__snapshots__/complex/misc/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/customParagraph/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/customParagraph/nested/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/customParagraph/styled/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/fontSize/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/basic/markdown.md +2 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/between-links/markdown.md +2 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/end/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/link/markdown.md +2 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/multiple/markdown.md +3 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/start/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/styles/markdown.md +2 -0
- package/src/api/exporters/markdown/__snapshots__/image/basic/markdown.md +3 -0
- package/src/api/exporters/markdown/__snapshots__/image/button/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/image/nested/markdown.md +7 -0
- package/src/api/exporters/markdown/__snapshots__/link/adjacent/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/link/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/link/styled/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/mention/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/paragraph/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/paragraph/empty/markdown.md +0 -0
- package/src/api/exporters/markdown/__snapshots__/paragraph/nested/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/paragraph/styled/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/nested/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/styled/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleImage/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleImage/button/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleImage/nested/markdown.md +3 -0
- package/src/api/exporters/markdown/__snapshots__/small/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/tag/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/markdownExporter.test.ts +85 -0
- package/src/api/exporters/markdown/markdownExporter.ts +42 -0
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +486 -125
- package/src/api/nodeConversions/nodeConversions.test.ts +67 -498
- package/src/api/nodeConversions/nodeConversions.ts +311 -98
- package/src/api/parsers/html/__snapshots__/paste/list-test.json +105 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-basic-block-types.json +140 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-deep-nested-content.json +240 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-div-with-inline-content.json +91 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-divs.json +121 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-fake-image-caption.json +31 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-google-docs-html.json +476 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-mixed-nested-lists.json +140 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-nested-lists-with-paragraphs.json +140 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-nested-lists.json +157 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-notion-html.json +470 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-two-divs.json +36 -0
- package/src/api/parsers/html/parseHTML.test.ts +440 -0
- package/src/api/parsers/html/parseHTML.ts +42 -0
- package/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap +129 -0
- package/src/api/parsers/html/util/nestedLists.test.ts +176 -0
- package/src/api/parsers/html/util/nestedLists.ts +113 -0
- package/src/api/parsers/markdown/__snapshots__/complex.json +353 -0
- package/src/api/parsers/markdown/__snapshots__/issue-226-1.json +71 -0
- package/src/api/parsers/markdown/__snapshots__/issue-226-2.json +144 -0
- package/src/api/parsers/markdown/__snapshots__/nested.json +72 -0
- package/src/api/parsers/markdown/__snapshots__/non-nested.json +71 -0
- package/src/api/parsers/markdown/__snapshots__/styled.json +58 -0
- package/src/api/parsers/markdown/parseMarkdown.test.ts +114 -0
- package/src/api/parsers/markdown/parseMarkdown.ts +84 -0
- package/src/api/parsers/pasteExtension.ts +59 -0
- package/src/api/testUtil/cases/customBlocks.ts +282 -0
- package/src/api/testUtil/cases/customInlineContent.ts +114 -0
- package/src/api/testUtil/cases/customStyles.ts +100 -0
- package/src/api/testUtil/cases/defaultSchema.ts +399 -0
- package/src/api/testUtil/index.ts +17 -0
- package/src/api/testUtil/partialBlockTestUtil.ts +127 -0
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +136 -0
- package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/ImageBlockContent.ts +117 -31
- package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +34 -47
- package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
- package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
- package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +34 -56
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +43 -0
- package/src/blocks/README.md +3 -0
- package/src/blocks/TableBlockContent/TableBlockContent.ts +74 -0
- package/src/blocks/TableBlockContent/TableExtension.ts +63 -0
- package/src/blocks/defaultBlockHelpers.ts +95 -0
- package/src/blocks/defaultBlocks.ts +60 -0
- package/src/blocks/defaultProps.ts +24 -0
- package/src/{extensions/Blocks/nodes/Block.module.css → editor/Block.css} +70 -66
- package/src/{BlockNoteEditor.test.ts → editor/BlockNoteEditor.test.ts} +2 -2
- package/src/{BlockNoteEditor.ts → editor/BlockNoteEditor.ts} +382 -159
- package/src/{BlockNoteExtensions.ts → editor/BlockNoteExtensions.ts} +59 -40
- package/src/editor/README.md +3 -0
- package/src/editor/cursorPositionTypes.ts +16 -0
- package/src/{editor.module.css → editor/editor.css} +42 -15
- package/src/editor/selectionTypes.ts +14 -0
- package/src/editor/transformPasted.ts +58 -0
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -36
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +12 -27
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +16 -24
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +12 -10
- package/src/extensions/ImageToolbar/ImageToolbarPlugin.ts +35 -73
- package/src/extensions/Placeholder/PlaceholderExtension.ts +4 -4
- package/src/extensions/README.md +3 -0
- package/src/extensions/SideMenu/SideMenuPlugin.ts +77 -37
- package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +7 -6
- package/src/extensions/SlashMenu/SlashMenuPlugin.ts +9 -7
- package/src/extensions/SlashMenu/defaultSlashMenuItems.ts +98 -35
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +617 -0
- package/src/extensions/TextAlignment/TextAlignmentExtension.ts +3 -51
- package/src/extensions/TextColor/TextColorExtension.ts +1 -29
- package/src/extensions/TextColor/TextColorMark.ts +7 -27
- package/src/extensions/UniqueID/UniqueID.ts +28 -2
- package/src/extensions-shared/README.md +3 -0
- package/src/{shared/plugins → extensions-shared}/suggestion/SuggestionPlugin.ts +19 -13
- package/src/index.ts +21 -15
- package/src/{extensions/Blocks/nodes → pm-nodes}/BlockContainer.ts +161 -96
- package/src/pm-nodes/BlockGroup.ts +54 -0
- package/src/pm-nodes/Doc.ts +7 -0
- package/src/pm-nodes/README.md +42 -0
- package/src/pm-nodes/index.ts +3 -0
- package/src/schema/README.md +3 -0
- package/src/schema/blocks/createSpec.ts +220 -0
- package/src/schema/blocks/internal.ts +253 -0
- package/src/schema/blocks/types.ts +252 -0
- package/src/schema/index.ts +10 -0
- package/src/schema/inlineContent/createSpec.ts +119 -0
- package/src/schema/inlineContent/internal.ts +105 -0
- package/src/schema/inlineContent/types.ts +144 -0
- package/src/schema/propTypes.ts +32 -0
- package/src/schema/styles/createSpec.ts +85 -0
- package/src/schema/styles/internal.ts +96 -0
- package/src/schema/styles/types.ts +42 -0
- package/src/util/README.md +3 -0
- package/src/{shared/utils.ts → util/browser.ts} +4 -8
- package/src/util/string.ts +3 -0
- package/src/util/typescript.ts +5 -0
- package/types/src/BlockNoteEditor.d.ts +51 -37
- package/types/src/BlockNoteExtensions.d.ts +8 -3
- package/types/src/api/blockManipulation/blockManipulation.d.ts +5 -4
- package/types/src/api/exporters/copyExtension.d.ts +6 -0
- package/types/src/api/exporters/html/externalHTMLExporter.d.ts +8 -0
- package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +8 -0
- package/types/src/api/exporters/html/util/sharedHTMLConversion.d.ts +7 -0
- package/types/src/api/exporters/markdown/markdownExporter.d.ts +5 -0
- package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +1 -0
- package/types/src/api/getBlockInfoFromPos.d.ts +27 -0
- package/types/src/api/nodeConversions/nodeConversions.d.ts +14 -6
- package/types/src/api/nodeConversions/testUtil.d.ts +7 -2
- package/types/src/api/nodeUtil.d.ts +8 -0
- package/types/src/api/parsers/html/parseHTML.d.ts +3 -0
- package/types/src/api/parsers/html/parseHTML.test.d.ts +1 -0
- package/types/src/api/parsers/html/util/nestedLists.d.ts +1 -0
- package/types/src/api/parsers/html/util/nestedLists.test.d.ts +1 -0
- package/types/src/api/parsers/markdown/parseMarkdown.d.ts +3 -0
- package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +1 -0
- package/types/src/api/parsers/pasteExtension.d.ts +6 -0
- package/types/src/api/testCases/cases/customBlocks.d.ts +345 -0
- package/types/src/api/testCases/cases/customInlineContent.d.ts +29 -0
- package/types/src/api/testCases/cases/customStyles.d.ts +64 -0
- package/types/src/api/testCases/cases/defaultSchema.d.ts +3 -0
- package/types/src/api/testCases/index.d.ts +12 -0
- package/types/src/api/testUtil/cases/customBlocks.d.ts +345 -0
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +29 -0
- package/types/src/api/testUtil/cases/customStyles.d.ts +64 -0
- package/types/src/api/testUtil/cases/defaultSchema.d.ts +3 -0
- package/types/src/api/testUtil/index.d.ts +12 -0
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +7 -0
- package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +58 -0
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +93 -0
- package/types/src/blocks/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +1 -0
- package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +46 -0
- package/types/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +2 -0
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +2 -0
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +46 -0
- package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +52 -0
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +53 -0
- package/types/src/blocks/TableBlockContent/TableExtension.d.ts +2 -0
- package/types/src/blocks/defaultBlockHelpers.d.ts +10 -0
- package/types/src/blocks/defaultBlocks.d.ts +577 -0
- package/types/src/blocks/defaultProps.d.ts +15 -0
- package/types/src/editor/BlockNoteEditor.d.ts +299 -0
- package/types/src/editor/BlockNoteEditor.test.d.ts +1 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +24 -0
- package/types/src/editor/cursorPositionTypes.d.ts +6 -0
- package/types/src/editor/selectionTypes.d.ts +4 -0
- package/types/src/editor/transformPasted.d.ts +12 -0
- package/types/src/extensions/BackgroundColor/BackgroundColorExtension.d.ts +0 -7
- package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +7 -9
- package/types/src/extensions/Blocks/api/blocks/createSpec.d.ts +35 -0
- package/types/src/extensions/Blocks/api/blocks/internal.d.ts +45 -0
- package/types/src/extensions/Blocks/api/blocks/types.d.ts +114 -0
- package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +7 -5
- package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +573 -113
- package/types/src/extensions/Blocks/api/defaultProps.d.ts +2 -1
- package/types/src/extensions/Blocks/api/inlineContent/createSpec.d.ts +21 -0
- package/types/src/extensions/Blocks/api/inlineContent/internal.d.ts +25 -0
- package/types/src/extensions/Blocks/api/inlineContent/types.d.ts +62 -0
- package/types/src/extensions/Blocks/api/selectionTypes.d.ts +5 -3
- package/types/src/extensions/Blocks/api/styles/createSpec.d.ts +13 -0
- package/types/src/extensions/Blocks/api/styles/internal.d.ts +22 -0
- package/types/src/extensions/Blocks/api/styles/types.d.ts +21 -0
- package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +8 -4
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +38 -23
- package/types/src/extensions/Blocks/nodes/BlockContent/ImageBlockContent/ImageBlockContent.d.ts +75 -17
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +30 -19
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +30 -19
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +36 -28
- package/types/src/extensions/Blocks/nodes/BlockContent/TableBlockContent/TableBlockContent.d.ts +53 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/TableBlockContent/TableExtension.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/defaultBlockHelpers.d.ts +12 -0
- package/types/src/extensions/Blocks/nodes/BlockGroup.d.ts +1 -1
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +8 -6
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +6 -6
- package/types/src/extensions/ImageToolbar/ImageToolbarPlugin.d.ts +11 -16
- package/types/src/extensions/NonEditableBlocks/NonEditableBlockPlugin.d.ts +2 -0
- package/types/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.d.ts +14 -0
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +19 -11
- package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +5 -6
- package/types/src/extensions/SlashMenu/SlashMenuPlugin.d.ts +6 -6
- package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +2 -1
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +74 -0
- package/types/src/extensions/TextAlignment/TextAlignmentExtension.d.ts +0 -7
- package/types/src/extensions/TextColor/TextColorExtension.d.ts +0 -7
- package/types/src/extensions/TextColor/TextColorMark.d.ts +7 -9
- package/types/src/extensions/UniqueID/UniqueID.d.ts +1 -1
- package/types/src/extensions-shared/BaseUiElementTypes.d.ts +7 -0
- package/types/src/extensions-shared/suggestion/SuggestionItem.d.ts +3 -0
- package/types/src/extensions-shared/suggestion/SuggestionPlugin.d.ts +36 -0
- package/types/src/index.d.ts +20 -15
- package/types/src/pm-nodes/BlockContainer.d.ts +28 -0
- package/types/src/pm-nodes/BlockGroup.d.ts +10 -0
- package/types/src/pm-nodes/Doc.d.ts +2 -0
- package/types/src/pm-nodes/index.d.ts +3 -0
- package/types/src/schema/blocks/createSpec.d.ts +35 -0
- package/types/src/schema/blocks/internal.d.ts +45 -0
- package/types/src/schema/blocks/types.d.ts +107 -0
- package/types/src/schema/index.d.ts +10 -0
- package/types/src/schema/inlineContent/createSpec.d.ts +21 -0
- package/types/src/schema/inlineContent/internal.d.ts +28 -0
- package/types/src/schema/inlineContent/types.d.ts +62 -0
- package/types/src/schema/propTypes.d.ts +8 -0
- package/types/src/schema/styles/createSpec.d.ts +13 -0
- package/types/src/schema/styles/internal.d.ts +22 -0
- package/types/src/schema/styles/types.d.ts +21 -0
- package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +4 -2
- package/types/src/util/EventEmitter.d.ts +11 -0
- package/types/src/util/browser.d.ts +3 -0
- package/types/src/util/string.d.ts +1 -0
- package/types/src/util/typescript.d.ts +3 -0
- package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +0 -346
- package/src/api/formatConversions/formatConversions.test.ts +0 -753
- package/src/api/formatConversions/formatConversions.ts +0 -133
- package/src/api/nodeConversions/testUtil.ts +0 -65
- package/src/extensions/Blocks/api/block.ts +0 -307
- package/src/extensions/Blocks/api/blockTypes.ts +0 -249
- package/src/extensions/Blocks/api/cursorPositionTypes.ts +0 -7
- package/src/extensions/Blocks/api/defaultBlocks.ts +0 -16
- package/src/extensions/Blocks/api/defaultProps.ts +0 -16
- package/src/extensions/Blocks/api/inlineContentTypes.ts +0 -36
- package/src/extensions/Blocks/api/selectionTypes.ts +0 -5
- package/src/extensions/Blocks/api/serialization.ts +0 -29
- package/src/extensions/Blocks/helpers/findBlock.ts +0 -5
- package/src/extensions/Blocks/index.ts +0 -8
- package/src/extensions/Blocks/nodes/BlockAttributes.ts +0 -10
- package/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.ts +0 -142
- package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +0 -62
- package/src/extensions/Blocks/nodes/BlockGroup.ts +0 -53
- package/types/src/api/formatConversions/formatConversions.d.ts +0 -6
- package/types/src/extensions/Blocks/api/block.d.ts +0 -20
- package/types/src/extensions/Blocks/api/blockTypes.d.ts +0 -103
- package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +0 -30
- package/types/src/extensions/Blocks/api/serialization.d.ts +0 -2
- /package/src/{shared/EditorElement.ts → api/exporters/markdown/__snapshots__/hardbreak/only/markdown.md} +0 -0
- /package/src/api/{formatConversions → exporters/markdown}/removeUnderlinesRehypePlugin.ts +0 -0
- /package/src/{extensions/Blocks/helpers → api}/getBlockInfoFromPos.ts +0 -0
- /package/src/api/{util/nodeUtil.ts → nodeUtil.ts} +0 -0
- /package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
- /package/src/extensions/{Blocks → NonEditableBlocks}/NonEditableBlockPlugin.ts +0 -0
- /package/src/extensions/{Blocks → PreviousBlockType}/PreviousBlockTypePlugin.ts +0 -0
- /package/src/{shared → extensions-shared}/BaseUiElementTypes.ts +0 -0
- /package/src/{shared/plugins → extensions-shared}/suggestion/SuggestionItem.ts +0 -0
- /package/src/{shared → util}/EventEmitter.ts +0 -0
- /package/types/src/api/{formatConversions/formatConversions.test.d.ts → exporters/html/htmlConversion.test.d.ts} +0 -0
- /package/types/src/api/{formatConversions → exporters/html/util}/simplifyBlocksRehypePlugin.d.ts +0 -0
- /package/types/src/api/{formatConversions → exporters/markdown}/removeUnderlinesRehypePlugin.d.ts +0 -0
|
@@ -1,48 +1,44 @@
|
|
|
1
|
-
import { Node as PMNode } from "prosemirror-model";
|
|
2
1
|
import { EditorState, Plugin, PluginKey } from "prosemirror-state";
|
|
3
2
|
import { EditorView } from "prosemirror-view";
|
|
3
|
+
|
|
4
|
+
import { EventEmitter } from "../../util/EventEmitter";
|
|
5
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
4
6
|
import {
|
|
5
|
-
BaseUiElementCallbacks,
|
|
6
|
-
BaseUiElementState,
|
|
7
|
-
BlockNoteEditor,
|
|
8
7
|
BlockSchema,
|
|
9
|
-
|
|
8
|
+
InlineContentSchema,
|
|
10
9
|
SpecificBlock,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
StyleSchema,
|
|
11
|
+
} from "../../schema";
|
|
12
|
+
import {
|
|
13
|
+
BaseUiElementCallbacks,
|
|
14
|
+
BaseUiElementState,
|
|
15
|
+
} from "../../extensions-shared/BaseUiElementTypes";
|
|
14
16
|
export type ImageToolbarCallbacks = BaseUiElementCallbacks;
|
|
15
17
|
|
|
16
|
-
export type ImageToolbarState
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
src: { default: string };
|
|
23
|
-
},
|
|
24
|
-
false
|
|
25
|
-
>;
|
|
26
|
-
},
|
|
27
|
-
"image"
|
|
28
|
-
>;
|
|
18
|
+
export type ImageToolbarState<
|
|
19
|
+
B extends BlockSchema,
|
|
20
|
+
I extends InlineContentSchema,
|
|
21
|
+
S extends StyleSchema = StyleSchema
|
|
22
|
+
> = BaseUiElementState & {
|
|
23
|
+
block: SpecificBlock<B, "image", I, S>;
|
|
29
24
|
};
|
|
30
25
|
|
|
31
|
-
export class ImageToolbarView
|
|
32
|
-
|
|
26
|
+
export class ImageToolbarView<
|
|
27
|
+
BSchema extends BlockSchema,
|
|
28
|
+
I extends InlineContentSchema,
|
|
29
|
+
S extends StyleSchema
|
|
30
|
+
> {
|
|
31
|
+
private imageToolbarState?: ImageToolbarState<BSchema, I, S>;
|
|
33
32
|
public updateImageToolbar: () => void;
|
|
34
33
|
|
|
35
34
|
public prevWasEditable: boolean | null = null;
|
|
36
35
|
|
|
37
|
-
public shouldShow: (state: EditorState) => boolean = (state) =>
|
|
38
|
-
"node" in state.selection &&
|
|
39
|
-
(state.selection.node as PMNode).type.name === "image" &&
|
|
40
|
-
(state.selection.node as PMNode).attrs.src === "";
|
|
41
|
-
|
|
42
36
|
constructor(
|
|
43
37
|
private readonly pluginKey: PluginKey,
|
|
44
38
|
private readonly pmView: EditorView,
|
|
45
|
-
updateImageToolbar: (
|
|
39
|
+
updateImageToolbar: (
|
|
40
|
+
imageToolbarState: ImageToolbarState<BSchema, I, S>
|
|
41
|
+
) => void
|
|
46
42
|
) {
|
|
47
43
|
this.updateImageToolbar = () => {
|
|
48
44
|
if (!this.imageToolbarState) {
|
|
@@ -112,18 +108,7 @@ export class ImageToolbarView {
|
|
|
112
108
|
|
|
113
109
|
update(view: EditorView, prevState: EditorState) {
|
|
114
110
|
const pluginState: {
|
|
115
|
-
block: SpecificBlock<
|
|
116
|
-
BlockSchema & {
|
|
117
|
-
image: BlockSpec<
|
|
118
|
-
"image",
|
|
119
|
-
{
|
|
120
|
-
src: { default: string };
|
|
121
|
-
},
|
|
122
|
-
false
|
|
123
|
-
>;
|
|
124
|
-
},
|
|
125
|
-
"image"
|
|
126
|
-
>;
|
|
111
|
+
block: SpecificBlock<BSchema, "image", I, S>;
|
|
127
112
|
} = this.pluginKey.getState(view.state);
|
|
128
113
|
|
|
129
114
|
if (!this.imageToolbarState?.show && pluginState.block) {
|
|
@@ -168,28 +153,17 @@ export class ImageToolbarView {
|
|
|
168
153
|
export const imageToolbarPluginKey = new PluginKey("ImageToolbarPlugin");
|
|
169
154
|
|
|
170
155
|
export class ImageToolbarProsemirrorPlugin<
|
|
171
|
-
BSchema extends BlockSchema
|
|
156
|
+
BSchema extends BlockSchema,
|
|
157
|
+
I extends InlineContentSchema,
|
|
158
|
+
S extends StyleSchema
|
|
172
159
|
> extends EventEmitter<any> {
|
|
173
|
-
private view: ImageToolbarView | undefined;
|
|
160
|
+
private view: ImageToolbarView<BSchema, I, S> | undefined;
|
|
174
161
|
public readonly plugin: Plugin;
|
|
175
162
|
|
|
176
|
-
constructor(_editor: BlockNoteEditor<BSchema>) {
|
|
163
|
+
constructor(_editor: BlockNoteEditor<BSchema, I, S>) {
|
|
177
164
|
super();
|
|
178
165
|
this.plugin = new Plugin<{
|
|
179
|
-
block:
|
|
180
|
-
| SpecificBlock<
|
|
181
|
-
BlockSchema & {
|
|
182
|
-
image: BlockSpec<
|
|
183
|
-
"image",
|
|
184
|
-
{
|
|
185
|
-
src: { default: string };
|
|
186
|
-
},
|
|
187
|
-
false
|
|
188
|
-
>;
|
|
189
|
-
},
|
|
190
|
-
"image"
|
|
191
|
-
>
|
|
192
|
-
| undefined;
|
|
166
|
+
block: SpecificBlock<BSchema, "image", I, S> | undefined;
|
|
193
167
|
}>({
|
|
194
168
|
key: imageToolbarPluginKey,
|
|
195
169
|
view: (editorView) => {
|
|
@@ -210,20 +184,8 @@ export class ImageToolbarProsemirrorPlugin<
|
|
|
210
184
|
};
|
|
211
185
|
},
|
|
212
186
|
apply: (transaction) => {
|
|
213
|
-
const block:
|
|
214
|
-
|
|
215
|
-
BlockSchema & {
|
|
216
|
-
image: BlockSpec<
|
|
217
|
-
"image",
|
|
218
|
-
{
|
|
219
|
-
src: { default: string };
|
|
220
|
-
},
|
|
221
|
-
false
|
|
222
|
-
>;
|
|
223
|
-
},
|
|
224
|
-
"image"
|
|
225
|
-
>
|
|
226
|
-
| undefined = transaction.getMeta(imageToolbarPluginKey)?.block;
|
|
187
|
+
const block: SpecificBlock<BSchema, "image", I, S> | undefined =
|
|
188
|
+
transaction.getMeta(imageToolbarPluginKey)?.block;
|
|
227
189
|
|
|
228
190
|
return {
|
|
229
191
|
block,
|
|
@@ -233,7 +195,7 @@ export class ImageToolbarProsemirrorPlugin<
|
|
|
233
195
|
});
|
|
234
196
|
}
|
|
235
197
|
|
|
236
|
-
public onUpdate(callback: (state: ImageToolbarState) => void) {
|
|
198
|
+
public onUpdate(callback: (state: ImageToolbarState<BSchema, I, S>) => void) {
|
|
237
199
|
return this.on("update", callback);
|
|
238
200
|
}
|
|
239
201
|
}
|
|
@@ -36,10 +36,10 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
|
36
36
|
|
|
37
37
|
addOptions() {
|
|
38
38
|
return {
|
|
39
|
-
emptyEditorClass: "is-editor-empty",
|
|
40
|
-
emptyNodeClass: "is-empty",
|
|
41
|
-
isFilterClass: "is-filter",
|
|
42
|
-
hasAnchorClass: "has-anchor",
|
|
39
|
+
emptyEditorClass: "bn-is-editor-empty",
|
|
40
|
+
emptyNodeClass: "bn-is-empty",
|
|
41
|
+
isFilterClass: "bn-is-filter",
|
|
42
|
+
hasAnchorClass: "bn-has-anchor",
|
|
43
43
|
placeholder: "Write something …",
|
|
44
44
|
showOnlyWhenEditable: true,
|
|
45
45
|
showOnlyCurrent: true,
|
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
import { PluginView } from "@tiptap/pm/state";
|
|
2
2
|
import { Node } from "prosemirror-model";
|
|
3
3
|
import { NodeSelection, Plugin, PluginKey, Selection } from "prosemirror-state";
|
|
4
|
-
import * as pv from "prosemirror-view";
|
|
5
4
|
import { EditorView } from "prosemirror-view";
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
5
|
+
import { createExternalHTMLExporter } from "../../api/exporters/html/externalHTMLExporter";
|
|
6
|
+
import { createInternalHTMLSerializer } from "../../api/exporters/html/internalHTMLSerializer";
|
|
7
|
+
import { cleanHTMLToMarkdown } from "../../api/exporters/markdown/markdownExporter";
|
|
8
|
+
import { getBlockInfoFromPos } from "../../api/getBlockInfoFromPos";
|
|
9
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
10
|
+
import { BaseUiElementState } from "../../extensions-shared/BaseUiElementTypes";
|
|
11
|
+
import {
|
|
12
|
+
Block,
|
|
13
|
+
BlockSchema,
|
|
14
|
+
InlineContentSchema,
|
|
15
|
+
StyleSchema,
|
|
16
|
+
} from "../../schema";
|
|
17
|
+
import { EventEmitter } from "../../util/EventEmitter";
|
|
12
18
|
import { slashMenuPluginKey } from "../SlashMenu/SlashMenuPlugin";
|
|
13
19
|
import { MultipleNodeSelection } from "./MultipleNodeSelection";
|
|
14
20
|
|
|
15
|
-
const serializeForClipboard = (pv as any).__serializeForClipboard;
|
|
16
|
-
// code based on https://github.com/ueberdosis/tiptap/issues/323#issuecomment-506637799
|
|
17
|
-
|
|
18
21
|
let dragImageElement: Element | undefined;
|
|
19
22
|
|
|
20
|
-
export type SideMenuState<
|
|
23
|
+
export type SideMenuState<
|
|
24
|
+
BSchema extends BlockSchema,
|
|
25
|
+
I extends InlineContentSchema,
|
|
26
|
+
S extends StyleSchema
|
|
27
|
+
> = BaseUiElementState & {
|
|
21
28
|
// The block that the side menu is attached to.
|
|
22
|
-
block: Block<BSchema>;
|
|
29
|
+
block: Block<BSchema, I, S>;
|
|
23
30
|
};
|
|
24
31
|
|
|
25
|
-
function getDraggableBlockFromCoords(
|
|
32
|
+
export function getDraggableBlockFromCoords(
|
|
26
33
|
coords: { left: number; top: number },
|
|
27
34
|
view: EditorView
|
|
28
35
|
) {
|
|
@@ -153,18 +160,14 @@ function setDragImage(view: EditorView, from: number, to = from) {
|
|
|
153
160
|
const inheritedClasses = classes
|
|
154
161
|
.filter(
|
|
155
162
|
(className) =>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
className !== "ProseMirror" &&
|
|
164
|
+
className !== "bn-root" &&
|
|
165
|
+
className !== "bn-editor"
|
|
159
166
|
)
|
|
160
167
|
.join(" ");
|
|
161
168
|
|
|
162
169
|
dragImageElement.className =
|
|
163
|
-
dragImageElement.className +
|
|
164
|
-
" " +
|
|
165
|
-
styles.dragPreview +
|
|
166
|
-
" " +
|
|
167
|
-
inheritedClasses;
|
|
170
|
+
dragImageElement.className + " bn-drag-preview " + inheritedClasses;
|
|
168
171
|
|
|
169
172
|
document.body.appendChild(dragImageElement);
|
|
170
173
|
}
|
|
@@ -176,14 +179,20 @@ function unsetDragImage() {
|
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
181
|
|
|
179
|
-
function dragStart
|
|
182
|
+
function dragStart<
|
|
183
|
+
BSchema extends BlockSchema,
|
|
184
|
+
I extends InlineContentSchema,
|
|
185
|
+
S extends StyleSchema
|
|
186
|
+
>(
|
|
180
187
|
e: { dataTransfer: DataTransfer | null; clientY: number },
|
|
181
|
-
|
|
188
|
+
editor: BlockNoteEditor<BSchema, I, S>
|
|
182
189
|
) {
|
|
183
190
|
if (!e.dataTransfer) {
|
|
184
191
|
return;
|
|
185
192
|
}
|
|
186
193
|
|
|
194
|
+
const view = editor.prosemirrorView;
|
|
195
|
+
|
|
187
196
|
const editorBoundingBox = view.dom.getBoundingClientRect();
|
|
188
197
|
|
|
189
198
|
const coords = {
|
|
@@ -215,20 +224,38 @@ function dragStart(
|
|
|
215
224
|
setDragImage(view, pos);
|
|
216
225
|
}
|
|
217
226
|
|
|
218
|
-
const
|
|
219
|
-
const
|
|
227
|
+
const selectedSlice = view.state.selection.content();
|
|
228
|
+
const schema = editor._tiptapEditor.schema;
|
|
229
|
+
|
|
230
|
+
const internalHTMLSerializer = createInternalHTMLSerializer(schema, editor);
|
|
231
|
+
const internalHTML = internalHTMLSerializer.serializeProseMirrorFragment(
|
|
232
|
+
selectedSlice.content
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
const externalHTMLExporter = createExternalHTMLExporter(schema, editor);
|
|
236
|
+
const externalHTML = externalHTMLExporter.exportProseMirrorFragment(
|
|
237
|
+
selectedSlice.content
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const plainText = cleanHTMLToMarkdown(externalHTML);
|
|
220
241
|
|
|
221
242
|
e.dataTransfer.clearData();
|
|
222
|
-
e.dataTransfer.setData("
|
|
223
|
-
e.dataTransfer.setData("text/
|
|
243
|
+
e.dataTransfer.setData("blocknote/html", internalHTML);
|
|
244
|
+
e.dataTransfer.setData("text/html", externalHTML);
|
|
245
|
+
e.dataTransfer.setData("text/plain", plainText);
|
|
224
246
|
e.dataTransfer.effectAllowed = "move";
|
|
225
247
|
e.dataTransfer.setDragImage(dragImageElement!, 0, 0);
|
|
226
|
-
view.dragging = { slice, move: true };
|
|
248
|
+
view.dragging = { slice: selectedSlice, move: true };
|
|
227
249
|
}
|
|
228
250
|
}
|
|
229
251
|
|
|
230
|
-
export class SideMenuView<
|
|
231
|
-
|
|
252
|
+
export class SideMenuView<
|
|
253
|
+
BSchema extends BlockSchema,
|
|
254
|
+
I extends InlineContentSchema,
|
|
255
|
+
S extends StyleSchema
|
|
256
|
+
> implements PluginView
|
|
257
|
+
{
|
|
258
|
+
private sideMenuState?: SideMenuState<BSchema, I, S>;
|
|
232
259
|
|
|
233
260
|
// When true, the drag handle with be anchored at the same level as root elements
|
|
234
261
|
// When false, the drag handle with be just to the left of the element
|
|
@@ -244,10 +271,10 @@ export class SideMenuView<BSchema extends BlockSchema> implements PluginView {
|
|
|
244
271
|
public menuFrozen = false;
|
|
245
272
|
|
|
246
273
|
constructor(
|
|
247
|
-
private readonly editor: BlockNoteEditor<BSchema>,
|
|
274
|
+
private readonly editor: BlockNoteEditor<BSchema, I, S>,
|
|
248
275
|
private readonly pmView: EditorView,
|
|
249
276
|
private readonly updateSideMenu: (
|
|
250
|
-
sideMenuState: SideMenuState<BSchema>
|
|
277
|
+
sideMenuState: SideMenuState<BSchema, I, S>
|
|
251
278
|
) => void
|
|
252
279
|
) {
|
|
253
280
|
this.horizontalPosAnchoredAtRoot = true;
|
|
@@ -265,6 +292,8 @@ export class SideMenuView<BSchema extends BlockSchema> implements PluginView {
|
|
|
265
292
|
// Makes menu scroll with the page.
|
|
266
293
|
document.addEventListener("scroll", this.onScroll);
|
|
267
294
|
|
|
295
|
+
// Unfreezes the menu whenever the user clicks anywhere.
|
|
296
|
+
document.body.addEventListener("mousedown", this.onMouseDown, true);
|
|
268
297
|
// Hides and unfreezes the menu whenever the user presses a key.
|
|
269
298
|
document.body.addEventListener("keydown", this.onKeyDown, true);
|
|
270
299
|
}
|
|
@@ -347,6 +376,14 @@ export class SideMenuView<BSchema extends BlockSchema> implements PluginView {
|
|
|
347
376
|
this.menuFrozen = false;
|
|
348
377
|
};
|
|
349
378
|
|
|
379
|
+
onMouseDown = (_event: MouseEvent) => {
|
|
380
|
+
if (this.sideMenuState && !this.sideMenuState.show) {
|
|
381
|
+
this.sideMenuState.show = true;
|
|
382
|
+
this.updateSideMenu(this.sideMenuState);
|
|
383
|
+
}
|
|
384
|
+
this.menuFrozen = false;
|
|
385
|
+
};
|
|
386
|
+
|
|
350
387
|
onMouseMove = (event: MouseEvent) => {
|
|
351
388
|
if (this.menuFrozen) {
|
|
352
389
|
return;
|
|
@@ -479,6 +516,7 @@ export class SideMenuView<BSchema extends BlockSchema> implements PluginView {
|
|
|
479
516
|
this.pmView.dom.removeEventListener("dragstart", this.onDragStart);
|
|
480
517
|
document.body.removeEventListener("drop", this.onDrop, true);
|
|
481
518
|
document.removeEventListener("scroll", this.onScroll);
|
|
519
|
+
document.body.removeEventListener("mousedown", this.onMouseDown, true);
|
|
482
520
|
document.body.removeEventListener("keydown", this.onKeyDown, true);
|
|
483
521
|
}
|
|
484
522
|
|
|
@@ -541,12 +579,14 @@ export class SideMenuView<BSchema extends BlockSchema> implements PluginView {
|
|
|
541
579
|
export const sideMenuPluginKey = new PluginKey("SideMenuPlugin");
|
|
542
580
|
|
|
543
581
|
export class SideMenuProsemirrorPlugin<
|
|
544
|
-
BSchema extends BlockSchema
|
|
582
|
+
BSchema extends BlockSchema,
|
|
583
|
+
I extends InlineContentSchema,
|
|
584
|
+
S extends StyleSchema
|
|
545
585
|
> extends EventEmitter<any> {
|
|
546
|
-
private sideMenuView: SideMenuView<BSchema> | undefined;
|
|
586
|
+
private sideMenuView: SideMenuView<BSchema, I, S> | undefined;
|
|
547
587
|
public readonly plugin: Plugin;
|
|
548
588
|
|
|
549
|
-
constructor(private readonly editor: BlockNoteEditor<BSchema>) {
|
|
589
|
+
constructor(private readonly editor: BlockNoteEditor<BSchema, I, S>) {
|
|
550
590
|
super();
|
|
551
591
|
this.plugin = new Plugin({
|
|
552
592
|
key: sideMenuPluginKey,
|
|
@@ -563,7 +603,7 @@ export class SideMenuProsemirrorPlugin<
|
|
|
563
603
|
});
|
|
564
604
|
}
|
|
565
605
|
|
|
566
|
-
public onUpdate(callback: (state: SideMenuState<BSchema>) => void) {
|
|
606
|
+
public onUpdate(callback: (state: SideMenuState<BSchema, I, S>) => void) {
|
|
567
607
|
return this.on("update", callback);
|
|
568
608
|
}
|
|
569
609
|
|
|
@@ -581,7 +621,7 @@ export class SideMenuProsemirrorPlugin<
|
|
|
581
621
|
clientY: number;
|
|
582
622
|
}) => {
|
|
583
623
|
this.sideMenuView!.isDragging = true;
|
|
584
|
-
dragStart(event, this.editor
|
|
624
|
+
dragStart(event, this.editor);
|
|
585
625
|
};
|
|
586
626
|
|
|
587
627
|
/**
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { BlockSchema } from "
|
|
4
|
-
import { DefaultBlockSchema } from "../Blocks/api/defaultBlocks";
|
|
1
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
2
|
+
import { SuggestionItem } from "../../extensions-shared/suggestion/SuggestionItem";
|
|
3
|
+
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema";
|
|
5
4
|
|
|
6
5
|
export type BaseSlashMenuItem<
|
|
7
|
-
BSchema extends BlockSchema
|
|
6
|
+
BSchema extends BlockSchema,
|
|
7
|
+
I extends InlineContentSchema,
|
|
8
|
+
S extends StyleSchema
|
|
8
9
|
> = SuggestionItem & {
|
|
9
|
-
execute: (editor: BlockNoteEditor<BSchema>) => void;
|
|
10
|
+
execute: (editor: BlockNoteEditor<BSchema, I, S>) => void;
|
|
10
11
|
aliases?: string[];
|
|
11
12
|
};
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { Plugin, PluginKey } from "prosemirror-state";
|
|
2
2
|
|
|
3
|
-
import { BlockNoteEditor } from "../../BlockNoteEditor";
|
|
4
|
-
import { EventEmitter } from "../../shared/EventEmitter";
|
|
3
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
5
4
|
import {
|
|
6
5
|
SuggestionsMenuState,
|
|
7
6
|
setupSuggestionsMenu,
|
|
8
|
-
} from "../../shared/
|
|
9
|
-
import { BlockSchema } from "
|
|
7
|
+
} from "../../extensions-shared/suggestion/SuggestionPlugin";
|
|
8
|
+
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema";
|
|
9
|
+
import { EventEmitter } from "../../util/EventEmitter";
|
|
10
10
|
import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
|
|
11
11
|
|
|
12
12
|
export const slashMenuPluginKey = new PluginKey("SlashMenuPlugin");
|
|
13
13
|
|
|
14
14
|
export class SlashMenuProsemirrorPlugin<
|
|
15
15
|
BSchema extends BlockSchema,
|
|
16
|
-
|
|
16
|
+
I extends InlineContentSchema,
|
|
17
|
+
S extends StyleSchema,
|
|
18
|
+
SlashMenuItem extends BaseSlashMenuItem<BSchema, I, S>
|
|
17
19
|
> extends EventEmitter<any> {
|
|
18
20
|
public readonly plugin: Plugin;
|
|
19
21
|
public readonly itemCallback: (item: SlashMenuItem) => void;
|
|
20
22
|
|
|
21
|
-
constructor(editor: BlockNoteEditor<BSchema>, items: SlashMenuItem[]) {
|
|
23
|
+
constructor(editor: BlockNoteEditor<BSchema, I, S>, items: SlashMenuItem[]) {
|
|
22
24
|
super();
|
|
23
|
-
const suggestions = setupSuggestionsMenu<SlashMenuItem, BSchema>(
|
|
25
|
+
const suggestions = setupSuggestionsMenu<SlashMenuItem, BSchema, I, S>(
|
|
24
26
|
editor,
|
|
25
27
|
(state) => {
|
|
26
28
|
this.emit("update", state);
|
|
@@ -1,42 +1,87 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { defaultBlockSchema } from "../../blocks/defaultBlocks";
|
|
2
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
3
|
+
import {
|
|
4
|
+
Block,
|
|
5
|
+
BlockSchema,
|
|
6
|
+
InlineContentSchema,
|
|
7
|
+
PartialBlock,
|
|
8
|
+
StyleSchema,
|
|
9
|
+
isStyledTextInlineContent,
|
|
10
|
+
} from "../../schema";
|
|
5
11
|
import { imageToolbarPluginKey } from "../ImageToolbar/ImageToolbarPlugin";
|
|
12
|
+
import { BaseSlashMenuItem } from "./BaseSlashMenuItem";
|
|
13
|
+
|
|
14
|
+
// Sets the editor's text cursor position to the next content editable block,
|
|
15
|
+
// so either a block with inline content or a table. The last block is always a
|
|
16
|
+
// paragraph, so this function won't try to set the cursor position past the
|
|
17
|
+
// last block.
|
|
18
|
+
function setSelectionToNextContentEditableBlock<
|
|
19
|
+
BSchema extends BlockSchema,
|
|
20
|
+
I extends InlineContentSchema,
|
|
21
|
+
S extends StyleSchema
|
|
22
|
+
>(editor: BlockNoteEditor<BSchema, I, S>) {
|
|
23
|
+
let block = editor.getTextCursorPosition().block;
|
|
24
|
+
let contentType = editor.blockSchema[block.type].content;
|
|
25
|
+
|
|
26
|
+
while (contentType === "none") {
|
|
27
|
+
block = editor.getTextCursorPosition().nextBlock!;
|
|
28
|
+
contentType = editor.blockSchema[block.type].content as
|
|
29
|
+
| "inline"
|
|
30
|
+
| "table"
|
|
31
|
+
| "none";
|
|
32
|
+
editor.setTextCursorPosition(block, "end");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
6
35
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
36
|
+
// Checks if the current block is empty or only contains a slash, and if so,
|
|
37
|
+
// updates the current block instead of inserting a new one below. If the new
|
|
38
|
+
// block doesn't contain editable content, the cursor is moved to the next block
|
|
39
|
+
// that does.
|
|
40
|
+
function insertOrUpdateBlock<
|
|
41
|
+
BSchema extends BlockSchema,
|
|
42
|
+
I extends InlineContentSchema,
|
|
43
|
+
S extends StyleSchema
|
|
44
|
+
>(
|
|
45
|
+
editor: BlockNoteEditor<BSchema, I, S>,
|
|
46
|
+
block: PartialBlock<BSchema, I, S>
|
|
47
|
+
): Block<BSchema, I, S> {
|
|
11
48
|
const currentBlock = editor.getTextCursorPosition().block;
|
|
12
49
|
|
|
13
50
|
if (currentBlock.content === undefined) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"Slash Menu open in a block that doesn't contain inline content."
|
|
16
|
-
);
|
|
51
|
+
throw new Error("Slash Menu open in a block that doesn't contain content.");
|
|
17
52
|
}
|
|
18
53
|
|
|
19
54
|
if (
|
|
20
|
-
(currentBlock.content
|
|
55
|
+
Array.isArray(currentBlock.content) &&
|
|
56
|
+
((currentBlock.content.length === 1 &&
|
|
57
|
+
isStyledTextInlineContent(currentBlock.content[0]) &&
|
|
21
58
|
currentBlock.content[0].type === "text" &&
|
|
22
59
|
currentBlock.content[0].text === "/") ||
|
|
23
|
-
|
|
60
|
+
currentBlock.content.length === 0)
|
|
24
61
|
) {
|
|
25
62
|
editor.updateBlock(currentBlock, block);
|
|
26
63
|
} else {
|
|
27
64
|
editor.insertBlocks([block], currentBlock, "after");
|
|
28
|
-
editor.setTextCursorPosition(
|
|
65
|
+
editor.setTextCursorPosition(
|
|
66
|
+
editor.getTextCursorPosition().nextBlock!,
|
|
67
|
+
"end"
|
|
68
|
+
);
|
|
29
69
|
}
|
|
70
|
+
|
|
71
|
+
const insertedBlock = editor.getTextCursorPosition().block;
|
|
72
|
+
setSelectionToNextContentEditableBlock(editor);
|
|
73
|
+
|
|
74
|
+
return insertedBlock;
|
|
30
75
|
}
|
|
31
76
|
|
|
32
|
-
export const getDefaultSlashMenuItems = <
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
77
|
+
export const getDefaultSlashMenuItems = <
|
|
78
|
+
BSchema extends BlockSchema,
|
|
79
|
+
I extends InlineContentSchema,
|
|
80
|
+
S extends StyleSchema
|
|
81
|
+
>(
|
|
37
82
|
schema: BSchema = defaultBlockSchema as unknown as BSchema
|
|
38
83
|
) => {
|
|
39
|
-
const slashMenuItems: BaseSlashMenuItem<BSchema>[] = [];
|
|
84
|
+
const slashMenuItems: BaseSlashMenuItem<BSchema, I, S>[] = [];
|
|
40
85
|
|
|
41
86
|
if ("heading" in schema && "level" in schema.heading.propSchema) {
|
|
42
87
|
// Command for creating a level 1 heading
|
|
@@ -48,7 +93,7 @@ export const getDefaultSlashMenuItems = <BSchema extends BlockSchema>(
|
|
|
48
93
|
insertOrUpdateBlock(editor, {
|
|
49
94
|
type: "heading",
|
|
50
95
|
props: { level: 1 },
|
|
51
|
-
} as PartialBlock<BSchema>),
|
|
96
|
+
} as PartialBlock<BSchema, I, S>),
|
|
52
97
|
});
|
|
53
98
|
}
|
|
54
99
|
|
|
@@ -61,7 +106,7 @@ export const getDefaultSlashMenuItems = <BSchema extends BlockSchema>(
|
|
|
61
106
|
insertOrUpdateBlock(editor, {
|
|
62
107
|
type: "heading",
|
|
63
108
|
props: { level: 2 },
|
|
64
|
-
} as PartialBlock<BSchema>),
|
|
109
|
+
} as PartialBlock<BSchema, I, S>),
|
|
65
110
|
});
|
|
66
111
|
}
|
|
67
112
|
|
|
@@ -74,7 +119,7 @@ export const getDefaultSlashMenuItems = <BSchema extends BlockSchema>(
|
|
|
74
119
|
insertOrUpdateBlock(editor, {
|
|
75
120
|
type: "heading",
|
|
76
121
|
props: { level: 3 },
|
|
77
|
-
} as PartialBlock<BSchema>),
|
|
122
|
+
} as PartialBlock<BSchema, I, S>),
|
|
78
123
|
});
|
|
79
124
|
}
|
|
80
125
|
}
|
|
@@ -86,7 +131,7 @@ export const getDefaultSlashMenuItems = <BSchema extends BlockSchema>(
|
|
|
86
131
|
execute: (editor) =>
|
|
87
132
|
insertOrUpdateBlock(editor, {
|
|
88
133
|
type: "bulletListItem",
|
|
89
|
-
}
|
|
134
|
+
}),
|
|
90
135
|
});
|
|
91
136
|
}
|
|
92
137
|
|
|
@@ -97,7 +142,7 @@ export const getDefaultSlashMenuItems = <BSchema extends BlockSchema>(
|
|
|
97
142
|
execute: (editor) =>
|
|
98
143
|
insertOrUpdateBlock(editor, {
|
|
99
144
|
type: "numberedListItem",
|
|
100
|
-
}
|
|
145
|
+
}),
|
|
101
146
|
});
|
|
102
147
|
}
|
|
103
148
|
|
|
@@ -108,7 +153,30 @@ export const getDefaultSlashMenuItems = <BSchema extends BlockSchema>(
|
|
|
108
153
|
execute: (editor) =>
|
|
109
154
|
insertOrUpdateBlock(editor, {
|
|
110
155
|
type: "paragraph",
|
|
111
|
-
}
|
|
156
|
+
}),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if ("table" in schema) {
|
|
161
|
+
slashMenuItems.push({
|
|
162
|
+
name: "Table",
|
|
163
|
+
aliases: ["table"],
|
|
164
|
+
execute: (editor) => {
|
|
165
|
+
insertOrUpdateBlock(editor, {
|
|
166
|
+
type: "table",
|
|
167
|
+
content: {
|
|
168
|
+
type: "tableContent",
|
|
169
|
+
rows: [
|
|
170
|
+
{
|
|
171
|
+
cells: ["", "", ""],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
cells: ["", "", ""],
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
} as PartialBlock<BSchema, I, S>);
|
|
179
|
+
},
|
|
112
180
|
});
|
|
113
181
|
}
|
|
114
182
|
|
|
@@ -127,19 +195,14 @@ export const getDefaultSlashMenuItems = <BSchema extends BlockSchema>(
|
|
|
127
195
|
"dropbox",
|
|
128
196
|
],
|
|
129
197
|
execute: (editor) => {
|
|
130
|
-
insertOrUpdateBlock(editor, {
|
|
198
|
+
const insertedBlock = insertOrUpdateBlock(editor, {
|
|
131
199
|
type: "image",
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// below it
|
|
135
|
-
editor.setTextCursorPosition(
|
|
136
|
-
editor.getTextCursorPosition().nextBlock!,
|
|
137
|
-
"start"
|
|
138
|
-
);
|
|
200
|
+
});
|
|
201
|
+
|
|
139
202
|
// Immediately open the image toolbar
|
|
140
203
|
editor._tiptapEditor.view.dispatch(
|
|
141
204
|
editor._tiptapEditor.state.tr.setMeta(imageToolbarPluginKey, {
|
|
142
|
-
block:
|
|
205
|
+
block: insertedBlock,
|
|
143
206
|
})
|
|
144
207
|
);
|
|
145
208
|
},
|