@blocknote/core 0.9.6 → 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 +3697 -2609
- 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 -85
- 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 +87 -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} +69 -62
- package/src/{BlockNoteEditor.test.ts → editor/BlockNoteEditor.test.ts} +2 -2
- package/src/{BlockNoteEditor.ts → editor/BlockNoteEditor.ts} +364 -153
- 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 +66 -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 +49 -36
- 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 +18 -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
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
import { Plugin, PluginKey, PluginView } from "prosemirror-state";
|
|
2
|
+
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
|
|
3
|
+
import { EventEmitter } from "../../util/EventEmitter";
|
|
4
|
+
import { nodeToBlock } from "../../api/nodeConversions/nodeConversions";
|
|
5
|
+
import { DefaultBlockSchema } from "../../blocks/defaultBlocks";
|
|
6
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
7
|
+
import {
|
|
8
|
+
Block,
|
|
9
|
+
BlockFromConfigNoChildren,
|
|
10
|
+
BlockSchemaWithBlock,
|
|
11
|
+
InlineContentSchema,
|
|
12
|
+
PartialBlock,
|
|
13
|
+
SpecificBlock,
|
|
14
|
+
StyleSchema,
|
|
15
|
+
} from "../../schema";
|
|
16
|
+
import { getDraggableBlockFromCoords } from "../SideMenu/SideMenuPlugin";
|
|
17
|
+
|
|
18
|
+
let dragImageElement: HTMLElement | undefined;
|
|
19
|
+
|
|
20
|
+
function setHiddenDragImage() {
|
|
21
|
+
if (dragImageElement) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
dragImageElement = document.createElement("div");
|
|
26
|
+
dragImageElement.innerHTML = "_";
|
|
27
|
+
dragImageElement.style.visibility = "hidden";
|
|
28
|
+
document.body.appendChild(dragImageElement);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function unsetHiddenDragImage() {
|
|
32
|
+
if (dragImageElement) {
|
|
33
|
+
document.body.removeChild(dragImageElement);
|
|
34
|
+
dragImageElement = undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type TableHandlesState<
|
|
39
|
+
I extends InlineContentSchema,
|
|
40
|
+
S extends StyleSchema
|
|
41
|
+
> = {
|
|
42
|
+
show: boolean;
|
|
43
|
+
referencePosCell: DOMRect;
|
|
44
|
+
referencePosTable: DOMRect;
|
|
45
|
+
|
|
46
|
+
block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], I, S>;
|
|
47
|
+
colIndex: number;
|
|
48
|
+
rowIndex: number;
|
|
49
|
+
|
|
50
|
+
draggingState:
|
|
51
|
+
| {
|
|
52
|
+
draggedCellOrientation: "row" | "col";
|
|
53
|
+
originalIndex: number;
|
|
54
|
+
mousePos: number;
|
|
55
|
+
}
|
|
56
|
+
| undefined;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function getChildIndex(node: Element) {
|
|
60
|
+
return Array.prototype.indexOf.call(node.parentElement!.childNodes, node);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Finds the DOM element corresponding to the table cell that the target element
|
|
64
|
+
// is currently in. If the target element is not in a table cell, returns null.
|
|
65
|
+
function domCellAround(target: Element | null): Element | null {
|
|
66
|
+
while (target && target.nodeName !== "TD" && target.nodeName !== "TH") {
|
|
67
|
+
target =
|
|
68
|
+
target.classList && target.classList.contains("ProseMirror")
|
|
69
|
+
? null
|
|
70
|
+
: (target.parentNode as Element);
|
|
71
|
+
}
|
|
72
|
+
return target;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Hides elements in the DOMwith the provided class names.
|
|
76
|
+
function hideElementsWithClassNames(classNames: string[]) {
|
|
77
|
+
classNames.forEach((className) => {
|
|
78
|
+
const elementsToHide = document.getElementsByClassName(className);
|
|
79
|
+
for (let i = 0; i < elementsToHide.length; i++) {
|
|
80
|
+
(elementsToHide[i] as HTMLElement).style.visibility = "hidden";
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class TableHandlesView<
|
|
86
|
+
BSchema extends BlockSchemaWithBlock<"table", DefaultBlockSchema["table"]>,
|
|
87
|
+
I extends InlineContentSchema,
|
|
88
|
+
S extends StyleSchema
|
|
89
|
+
> implements PluginView
|
|
90
|
+
{
|
|
91
|
+
public state?: TableHandlesState<I, S>;
|
|
92
|
+
public updateState: () => void;
|
|
93
|
+
|
|
94
|
+
public tableId: string | undefined;
|
|
95
|
+
public tablePos: number | undefined;
|
|
96
|
+
|
|
97
|
+
public menuFrozen = false;
|
|
98
|
+
|
|
99
|
+
public prevWasEditable: boolean | null = null;
|
|
100
|
+
|
|
101
|
+
constructor(
|
|
102
|
+
private readonly editor: BlockNoteEditor<BSchema, I, S>,
|
|
103
|
+
private readonly pmView: EditorView,
|
|
104
|
+
updateState: (state: TableHandlesState<I, S>) => void
|
|
105
|
+
) {
|
|
106
|
+
this.updateState = () => {
|
|
107
|
+
if (!this.state) {
|
|
108
|
+
throw new Error("Attempting to update uninitialized image toolbar");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
updateState(this.state);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
pmView.dom.addEventListener("mousemove", this.mouseMoveHandler);
|
|
115
|
+
|
|
116
|
+
document.addEventListener("dragover", this.dragOverHandler);
|
|
117
|
+
document.addEventListener("drop", this.dropHandler);
|
|
118
|
+
|
|
119
|
+
document.addEventListener("scroll", this.scrollHandler);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
mouseMoveHandler = (event: MouseEvent) => {
|
|
123
|
+
if (this.menuFrozen) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const target = domCellAround(event.target as HTMLElement);
|
|
128
|
+
|
|
129
|
+
if (!target || !this.editor.isEditable) {
|
|
130
|
+
if (this.state?.show) {
|
|
131
|
+
this.state.show = false;
|
|
132
|
+
this.updateState();
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const colIndex = getChildIndex(target);
|
|
138
|
+
const rowIndex = getChildIndex(target.parentElement!);
|
|
139
|
+
const cellRect = target.getBoundingClientRect();
|
|
140
|
+
const tableRect =
|
|
141
|
+
target.parentElement!.parentElement!.getBoundingClientRect();
|
|
142
|
+
|
|
143
|
+
const blockEl = getDraggableBlockFromCoords(cellRect, this.pmView);
|
|
144
|
+
if (!blockEl) {
|
|
145
|
+
throw new Error(
|
|
146
|
+
"Found table cell element, but could not find surrounding blockContent element."
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
this.tableId = blockEl.id;
|
|
150
|
+
|
|
151
|
+
if (
|
|
152
|
+
this.state !== undefined &&
|
|
153
|
+
this.state.show &&
|
|
154
|
+
this.tableId === blockEl.id &&
|
|
155
|
+
this.state.rowIndex === rowIndex &&
|
|
156
|
+
this.state.colIndex === colIndex
|
|
157
|
+
) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let block: Block<any, any, any> | undefined = undefined;
|
|
162
|
+
|
|
163
|
+
// Copied from `getBlock`. We don't use `getBlock` since we also need the PM
|
|
164
|
+
// node for the table, so we would effectively be doing the same work twice.
|
|
165
|
+
this.editor._tiptapEditor.state.doc.descendants((node, pos) => {
|
|
166
|
+
if (typeof block !== "undefined") {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (node.type.name !== "blockContainer" || node.attrs.id !== blockEl.id) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
block = nodeToBlock(
|
|
175
|
+
node,
|
|
176
|
+
this.editor.blockSchema,
|
|
177
|
+
this.editor.inlineContentSchema,
|
|
178
|
+
this.editor.styleSchema,
|
|
179
|
+
this.editor.blockCache
|
|
180
|
+
);
|
|
181
|
+
this.tablePos = pos + 1;
|
|
182
|
+
|
|
183
|
+
return false;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
this.state = {
|
|
187
|
+
show: true,
|
|
188
|
+
referencePosCell: cellRect,
|
|
189
|
+
referencePosTable: tableRect,
|
|
190
|
+
|
|
191
|
+
block: block! as SpecificBlock<BSchema, "table", I, S>,
|
|
192
|
+
colIndex: colIndex,
|
|
193
|
+
rowIndex: rowIndex,
|
|
194
|
+
|
|
195
|
+
draggingState: undefined,
|
|
196
|
+
};
|
|
197
|
+
this.updateState();
|
|
198
|
+
|
|
199
|
+
return false;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
dragOverHandler = (event: DragEvent) => {
|
|
203
|
+
if (this.state?.draggingState === undefined) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
event.dataTransfer!.dropEffect = "move";
|
|
209
|
+
|
|
210
|
+
hideElementsWithClassNames([
|
|
211
|
+
"column-resize-handle",
|
|
212
|
+
"prosemirror-dropcursor-block",
|
|
213
|
+
"prosemirror-dropcursor-inline",
|
|
214
|
+
]);
|
|
215
|
+
|
|
216
|
+
// The mouse cursor coordinates, bounded to the table's bounding box. The
|
|
217
|
+
// bounding box is shrunk by 1px on each side to ensure that the bounded
|
|
218
|
+
// coordinates are always inside a table cell.
|
|
219
|
+
const boundedMouseCoords = {
|
|
220
|
+
left: Math.min(
|
|
221
|
+
Math.max(event.clientX, this.state.referencePosTable.left + 1),
|
|
222
|
+
this.state.referencePosTable.right - 1
|
|
223
|
+
),
|
|
224
|
+
top: Math.min(
|
|
225
|
+
Math.max(event.clientY, this.state.referencePosTable.top + 1),
|
|
226
|
+
this.state.referencePosTable.bottom - 1
|
|
227
|
+
),
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// Gets the table cell element that the bounded mouse cursor coordinates lie
|
|
231
|
+
// in.
|
|
232
|
+
const tableCellElements = document
|
|
233
|
+
.elementsFromPoint(boundedMouseCoords.left, boundedMouseCoords.top)
|
|
234
|
+
.filter(
|
|
235
|
+
(element) => element.tagName === "TD" || element.tagName === "TH"
|
|
236
|
+
);
|
|
237
|
+
if (tableCellElements.length === 0) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
"Could not find table cell element that the mouse cursor is hovering over."
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
const tableCellElement = tableCellElements[0];
|
|
243
|
+
|
|
244
|
+
let emitStateUpdate = false;
|
|
245
|
+
|
|
246
|
+
// Gets current row and column index.
|
|
247
|
+
const rowIndex = getChildIndex(tableCellElement.parentElement!);
|
|
248
|
+
const colIndex = getChildIndex(tableCellElement);
|
|
249
|
+
|
|
250
|
+
// Checks if the drop cursor needs to be updated. This affects decorations
|
|
251
|
+
// only so it doesn't trigger a state update.
|
|
252
|
+
const oldIndex =
|
|
253
|
+
this.state.draggingState.draggedCellOrientation === "row"
|
|
254
|
+
? this.state.rowIndex
|
|
255
|
+
: this.state.colIndex;
|
|
256
|
+
const newIndex =
|
|
257
|
+
this.state.draggingState.draggedCellOrientation === "row"
|
|
258
|
+
? rowIndex
|
|
259
|
+
: colIndex;
|
|
260
|
+
const dispatchDecorationsTransaction = newIndex !== oldIndex;
|
|
261
|
+
|
|
262
|
+
// Checks if either the hovered cell has changed and updates the row and
|
|
263
|
+
// column index. Also updates the reference DOMRect.
|
|
264
|
+
if (this.state.rowIndex !== rowIndex || this.state.colIndex !== colIndex) {
|
|
265
|
+
this.state.rowIndex = rowIndex;
|
|
266
|
+
this.state.colIndex = colIndex;
|
|
267
|
+
|
|
268
|
+
this.state.referencePosCell = tableCellElement.getBoundingClientRect();
|
|
269
|
+
|
|
270
|
+
emitStateUpdate = true;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Checks if the mouse cursor position along the axis that the user is
|
|
274
|
+
// dragging on has changed and updates it.
|
|
275
|
+
const mousePos =
|
|
276
|
+
this.state.draggingState.draggedCellOrientation === "row"
|
|
277
|
+
? boundedMouseCoords.top
|
|
278
|
+
: boundedMouseCoords.left;
|
|
279
|
+
if (this.state.draggingState.mousePos !== mousePos) {
|
|
280
|
+
this.state.draggingState.mousePos = mousePos;
|
|
281
|
+
|
|
282
|
+
emitStateUpdate = true;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Emits a state update if any of the fields have changed.
|
|
286
|
+
if (emitStateUpdate) {
|
|
287
|
+
this.updateState();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Dispatches a dummy transaction to force a decorations update if
|
|
291
|
+
// necessary.
|
|
292
|
+
if (dispatchDecorationsTransaction) {
|
|
293
|
+
this.pmView.dispatch(
|
|
294
|
+
this.pmView.state.tr.setMeta(tableHandlesPluginKey, true)
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
dropHandler = (event: DragEvent) => {
|
|
300
|
+
if (this.state === undefined || this.state.draggingState === undefined) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
event.preventDefault();
|
|
305
|
+
|
|
306
|
+
const rows = this.state.block.content.rows;
|
|
307
|
+
|
|
308
|
+
if (this.state.draggingState.draggedCellOrientation === "row") {
|
|
309
|
+
const rowToMove = rows[this.state.draggingState.originalIndex];
|
|
310
|
+
rows.splice(this.state.draggingState.originalIndex, 1);
|
|
311
|
+
rows.splice(this.state.rowIndex, 0, rowToMove);
|
|
312
|
+
} else {
|
|
313
|
+
const cellsToMove = rows.map(
|
|
314
|
+
(row) => row.cells[this.state!.draggingState!.originalIndex]
|
|
315
|
+
);
|
|
316
|
+
rows.forEach((row, rowIndex) => {
|
|
317
|
+
row.cells.splice(this.state!.draggingState!.originalIndex, 1);
|
|
318
|
+
row.cells.splice(this.state!.colIndex, 0, cellsToMove[rowIndex]);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
this.editor.updateBlock(this.state.block, {
|
|
323
|
+
type: "table",
|
|
324
|
+
content: {
|
|
325
|
+
type: "tableContent",
|
|
326
|
+
rows: rows,
|
|
327
|
+
},
|
|
328
|
+
} as PartialBlock<BSchema, I, S>);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
scrollHandler = () => {
|
|
332
|
+
if (this.state?.show) {
|
|
333
|
+
const tableElement = document.querySelector(
|
|
334
|
+
`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`
|
|
335
|
+
)!;
|
|
336
|
+
const cellElement = tableElement.querySelector(
|
|
337
|
+
`tr:nth-child(${this.state.rowIndex + 1}) > td:nth-child(${
|
|
338
|
+
this.state.colIndex + 1
|
|
339
|
+
})`
|
|
340
|
+
)!;
|
|
341
|
+
|
|
342
|
+
this.state.referencePosTable = tableElement.getBoundingClientRect();
|
|
343
|
+
this.state.referencePosCell = cellElement.getBoundingClientRect();
|
|
344
|
+
this.updateState();
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
destroy() {
|
|
349
|
+
this.pmView.dom.removeEventListener("mousedown", this.mouseMoveHandler);
|
|
350
|
+
|
|
351
|
+
document.removeEventListener("dragover", this.dragOverHandler);
|
|
352
|
+
document.removeEventListener("drop", this.dropHandler);
|
|
353
|
+
|
|
354
|
+
document.removeEventListener("scroll", this.scrollHandler);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export const tableHandlesPluginKey = new PluginKey("TableHandlesPlugin");
|
|
359
|
+
|
|
360
|
+
export class TableHandlesProsemirrorPlugin<
|
|
361
|
+
BSchema extends BlockSchemaWithBlock<"table", DefaultBlockSchema["table"]>,
|
|
362
|
+
I extends InlineContentSchema,
|
|
363
|
+
S extends StyleSchema
|
|
364
|
+
> extends EventEmitter<any> {
|
|
365
|
+
private view: TableHandlesView<BSchema, I, S> | undefined;
|
|
366
|
+
public readonly plugin: Plugin;
|
|
367
|
+
|
|
368
|
+
constructor(private readonly editor: BlockNoteEditor<BSchema, I, S>) {
|
|
369
|
+
super();
|
|
370
|
+
this.plugin = new Plugin({
|
|
371
|
+
key: tableHandlesPluginKey,
|
|
372
|
+
view: (editorView) => {
|
|
373
|
+
this.view = new TableHandlesView(editor, editorView, (state) => {
|
|
374
|
+
this.emit("update", state);
|
|
375
|
+
});
|
|
376
|
+
return this.view;
|
|
377
|
+
},
|
|
378
|
+
// We use decorations to render the drop cursor when dragging a table row
|
|
379
|
+
// or column. The decorations are updated in the `dragOverHandler` method.
|
|
380
|
+
props: {
|
|
381
|
+
decorations: (state) => {
|
|
382
|
+
if (
|
|
383
|
+
this.view === undefined ||
|
|
384
|
+
this.view.state === undefined ||
|
|
385
|
+
this.view.state.draggingState === undefined ||
|
|
386
|
+
this.view.tablePos === undefined
|
|
387
|
+
) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const newIndex =
|
|
392
|
+
this.view.state.draggingState.draggedCellOrientation === "row"
|
|
393
|
+
? this.view.state.rowIndex
|
|
394
|
+
: this.view.state.colIndex;
|
|
395
|
+
|
|
396
|
+
const decorations: Decoration[] = [];
|
|
397
|
+
|
|
398
|
+
if (newIndex === this.view.state.draggingState.originalIndex) {
|
|
399
|
+
return DecorationSet.create(state.doc, decorations);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// Gets the table to show the drop cursor in.
|
|
403
|
+
const tableResolvedPos = state.doc.resolve(this.view.tablePos + 1);
|
|
404
|
+
const tableNode = tableResolvedPos.node();
|
|
405
|
+
|
|
406
|
+
if (this.view.state.draggingState.draggedCellOrientation === "row") {
|
|
407
|
+
// Gets the row at the new index.
|
|
408
|
+
const rowResolvedPos = state.doc.resolve(
|
|
409
|
+
tableResolvedPos.posAtIndex(newIndex) + 1
|
|
410
|
+
);
|
|
411
|
+
const rowNode = rowResolvedPos.node();
|
|
412
|
+
|
|
413
|
+
// Iterates over all cells in the row.
|
|
414
|
+
for (let i = 0; i < rowNode.childCount; i++) {
|
|
415
|
+
// Gets each cell in the row.
|
|
416
|
+
const cellResolvedPos = state.doc.resolve(
|
|
417
|
+
rowResolvedPos.posAtIndex(i) + 1
|
|
418
|
+
);
|
|
419
|
+
const cellNode = cellResolvedPos.node();
|
|
420
|
+
|
|
421
|
+
// Creates a decoration at the start or end of each cell,
|
|
422
|
+
// depending on whether the new index is before or after the
|
|
423
|
+
// original index.
|
|
424
|
+
const decorationPos =
|
|
425
|
+
cellResolvedPos.pos +
|
|
426
|
+
(newIndex > this.view.state.draggingState.originalIndex
|
|
427
|
+
? cellNode.nodeSize - 2
|
|
428
|
+
: 0);
|
|
429
|
+
decorations.push(
|
|
430
|
+
// The widget is a small bar which spans the width of the cell.
|
|
431
|
+
Decoration.widget(decorationPos, () => {
|
|
432
|
+
const widget = document.createElement("div");
|
|
433
|
+
widget.className = "bn-table-drop-cursor";
|
|
434
|
+
widget.style.left = "0";
|
|
435
|
+
widget.style.right = "0";
|
|
436
|
+
// This is only necessary because the drop indicator's height
|
|
437
|
+
// is an even number of pixels, whereas the border between
|
|
438
|
+
// table cells is an odd number of pixels. So this makes the
|
|
439
|
+
// positioning slightly more consistent regardless of where
|
|
440
|
+
// the row is being dropped.
|
|
441
|
+
if (
|
|
442
|
+
newIndex > this.view!.state!.draggingState!.originalIndex
|
|
443
|
+
) {
|
|
444
|
+
widget.style.bottom = "-2px";
|
|
445
|
+
} else {
|
|
446
|
+
widget.style.top = "-3px";
|
|
447
|
+
}
|
|
448
|
+
widget.style.height = "4px";
|
|
449
|
+
|
|
450
|
+
return widget;
|
|
451
|
+
})
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
} else {
|
|
455
|
+
// Iterates over all rows in the table.
|
|
456
|
+
for (let i = 0; i < tableNode.childCount; i++) {
|
|
457
|
+
// Gets each row in the table.
|
|
458
|
+
const rowResolvedPos = state.doc.resolve(
|
|
459
|
+
tableResolvedPos.posAtIndex(i) + 1
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
// Gets the cell at the new index in the row.
|
|
463
|
+
const cellResolvedPos = state.doc.resolve(
|
|
464
|
+
rowResolvedPos.posAtIndex(newIndex) + 1
|
|
465
|
+
);
|
|
466
|
+
const cellNode = cellResolvedPos.node();
|
|
467
|
+
|
|
468
|
+
// Creates a decoration at the start or end of each cell,
|
|
469
|
+
// depending on whether the new index is before or after the
|
|
470
|
+
// original index.
|
|
471
|
+
const decorationPos =
|
|
472
|
+
cellResolvedPos.pos +
|
|
473
|
+
(newIndex > this.view.state.draggingState.originalIndex
|
|
474
|
+
? cellNode.nodeSize - 2
|
|
475
|
+
: 0);
|
|
476
|
+
decorations.push(
|
|
477
|
+
// The widget is a small bar which spans the height of the cell.
|
|
478
|
+
Decoration.widget(decorationPos, () => {
|
|
479
|
+
const widget = document.createElement("div");
|
|
480
|
+
widget.className = "bn-table-drop-cursor";
|
|
481
|
+
widget.style.top = "0";
|
|
482
|
+
widget.style.bottom = "0";
|
|
483
|
+
// This is only necessary because the drop indicator's width
|
|
484
|
+
// is an even number of pixels, whereas the border between
|
|
485
|
+
// table cells is an odd number of pixels. So this makes the
|
|
486
|
+
// positioning slightly more consistent regardless of where
|
|
487
|
+
// the column is being dropped.
|
|
488
|
+
if (
|
|
489
|
+
newIndex > this.view!.state!.draggingState!.originalIndex
|
|
490
|
+
) {
|
|
491
|
+
widget.style.right = "-2px";
|
|
492
|
+
} else {
|
|
493
|
+
widget.style.left = "-3px";
|
|
494
|
+
}
|
|
495
|
+
widget.style.width = "4px";
|
|
496
|
+
|
|
497
|
+
return widget;
|
|
498
|
+
})
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
return DecorationSet.create(state.doc, decorations);
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
public onUpdate(callback: (state: TableHandlesState<I, S>) => void) {
|
|
510
|
+
return this.on("update", callback);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Callback that should be set on the `dragStart` event for whichever element
|
|
515
|
+
* is used as the column drag handle.
|
|
516
|
+
*/
|
|
517
|
+
colDragStart = (event: {
|
|
518
|
+
dataTransfer: DataTransfer | null;
|
|
519
|
+
clientX: number;
|
|
520
|
+
}) => {
|
|
521
|
+
if (this.view!.state === undefined) {
|
|
522
|
+
throw new Error(
|
|
523
|
+
"Attempted to drag table column, but no table block was hovered prior."
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
this.view!.state.draggingState = {
|
|
528
|
+
draggedCellOrientation: "col",
|
|
529
|
+
originalIndex: this.view!.state.colIndex,
|
|
530
|
+
mousePos: event.clientX,
|
|
531
|
+
};
|
|
532
|
+
this.view!.updateState();
|
|
533
|
+
|
|
534
|
+
this.editor._tiptapEditor.view.dispatch(
|
|
535
|
+
this.editor._tiptapEditor.state.tr.setMeta(tableHandlesPluginKey, {
|
|
536
|
+
draggedCellOrientation:
|
|
537
|
+
this.view!.state.draggingState.draggedCellOrientation,
|
|
538
|
+
originalIndex: this.view!.state.colIndex,
|
|
539
|
+
newIndex: this.view!.state.colIndex,
|
|
540
|
+
tablePos: this.view!.tablePos,
|
|
541
|
+
})
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
setHiddenDragImage();
|
|
545
|
+
event.dataTransfer!.setDragImage(dragImageElement!, 0, 0);
|
|
546
|
+
event.dataTransfer!.effectAllowed = "move";
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Callback that should be set on the `dragStart` event for whichever element
|
|
551
|
+
* is used as the row drag handle.
|
|
552
|
+
*/
|
|
553
|
+
rowDragStart = (event: {
|
|
554
|
+
dataTransfer: DataTransfer | null;
|
|
555
|
+
clientY: number;
|
|
556
|
+
}) => {
|
|
557
|
+
if (this.view!.state === undefined) {
|
|
558
|
+
throw new Error(
|
|
559
|
+
"Attempted to drag table row, but no table block was hovered prior."
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
this.view!.state.draggingState = {
|
|
564
|
+
draggedCellOrientation: "row",
|
|
565
|
+
originalIndex: this.view!.state.rowIndex,
|
|
566
|
+
mousePos: event.clientY,
|
|
567
|
+
};
|
|
568
|
+
this.view!.updateState();
|
|
569
|
+
|
|
570
|
+
this.editor._tiptapEditor.view.dispatch(
|
|
571
|
+
this.editor._tiptapEditor.state.tr.setMeta(tableHandlesPluginKey, {
|
|
572
|
+
draggedCellOrientation:
|
|
573
|
+
this.view!.state.draggingState.draggedCellOrientation,
|
|
574
|
+
originalIndex: this.view!.state.rowIndex,
|
|
575
|
+
newIndex: this.view!.state.rowIndex,
|
|
576
|
+
tablePos: this.view!.tablePos,
|
|
577
|
+
})
|
|
578
|
+
);
|
|
579
|
+
|
|
580
|
+
setHiddenDragImage();
|
|
581
|
+
event.dataTransfer!.setDragImage(dragImageElement!, 0, 0);
|
|
582
|
+
event.dataTransfer!.effectAllowed = "copyMove";
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Callback that should be set on the `dragEnd` event for both the element
|
|
587
|
+
* used as the row drag handle, and the one used as the column drag handle.
|
|
588
|
+
*/
|
|
589
|
+
dragEnd = () => {
|
|
590
|
+
if (this.view!.state === undefined) {
|
|
591
|
+
throw new Error(
|
|
592
|
+
"Attempted to drag table row, but no table block was hovered prior."
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
this.view!.state.draggingState = undefined;
|
|
597
|
+
this.view!.updateState();
|
|
598
|
+
|
|
599
|
+
this.editor._tiptapEditor.view.dispatch(
|
|
600
|
+
this.editor._tiptapEditor.state.tr.setMeta(tableHandlesPluginKey, null)
|
|
601
|
+
);
|
|
602
|
+
|
|
603
|
+
unsetHiddenDragImage();
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Freezes the drag handles. When frozen, they will stay attached to the same
|
|
608
|
+
* cell regardless of which cell is hovered by the mouse cursor.
|
|
609
|
+
*/
|
|
610
|
+
freezeHandles = () => (this.view!.menuFrozen = true);
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Unfreezes the drag handles. When frozen, they will stay attached to the
|
|
614
|
+
* same cell regardless of which cell is hovered by the mouse cursor.
|
|
615
|
+
*/
|
|
616
|
+
unfreezeHandles = () => (this.view!.menuFrozen = false);
|
|
617
|
+
}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
import { Extension } from "@tiptap/core";
|
|
2
|
-
import { getBlockInfoFromPos } from "../Blocks/helpers/getBlockInfoFromPos";
|
|
3
|
-
|
|
4
|
-
declare module "@tiptap/core" {
|
|
5
|
-
interface Commands<ReturnType> {
|
|
6
|
-
textAlignment: {
|
|
7
|
-
setTextAlignment: (
|
|
8
|
-
textAlignment: "left" | "center" | "right" | "justify"
|
|
9
|
-
) => ReturnType;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
2
|
|
|
14
3
|
export const TextAlignmentExtension = Extension.create({
|
|
15
4
|
name: "textAlignment",
|
|
@@ -23,7 +12,9 @@ export const TextAlignmentExtension = Extension.create({
|
|
|
23
12
|
attributes: {
|
|
24
13
|
textAlignment: {
|
|
25
14
|
default: "left",
|
|
26
|
-
parseHTML: (element) =>
|
|
15
|
+
parseHTML: (element) => {
|
|
16
|
+
return element.getAttribute("data-text-alignment");
|
|
17
|
+
},
|
|
27
18
|
renderHTML: (attributes) =>
|
|
28
19
|
attributes.textAlignment !== "left" && {
|
|
29
20
|
"data-text-alignment": attributes.textAlignment,
|
|
@@ -33,43 +24,4 @@ export const TextAlignmentExtension = Extension.create({
|
|
|
33
24
|
},
|
|
34
25
|
];
|
|
35
26
|
},
|
|
36
|
-
|
|
37
|
-
addCommands() {
|
|
38
|
-
return {
|
|
39
|
-
setTextAlignment:
|
|
40
|
-
(textAlignment) =>
|
|
41
|
-
({ state }) => {
|
|
42
|
-
const positionsBeforeSelectedContent = [];
|
|
43
|
-
|
|
44
|
-
const blockInfo = getBlockInfoFromPos(
|
|
45
|
-
state.doc,
|
|
46
|
-
state.selection.from
|
|
47
|
-
);
|
|
48
|
-
if (blockInfo === undefined) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Finds all blockContent nodes that the current selection is in.
|
|
53
|
-
let pos = blockInfo.startPos;
|
|
54
|
-
while (pos < state.selection.to) {
|
|
55
|
-
if (
|
|
56
|
-
state.doc.resolve(pos).node().type.spec.group === "blockContent"
|
|
57
|
-
) {
|
|
58
|
-
positionsBeforeSelectedContent.push(pos - 1);
|
|
59
|
-
|
|
60
|
-
pos += state.doc.resolve(pos).node().nodeSize - 1;
|
|
61
|
-
} else {
|
|
62
|
-
pos += 1;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Sets text alignment for all blockContent nodes that the current selection is in.
|
|
67
|
-
for (const pos of positionsBeforeSelectedContent) {
|
|
68
|
-
state.tr.setNodeAttribute(pos, "textAlignment", textAlignment);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return true;
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
27
|
});
|