@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
package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/ImageBlockContent.ts
RENAMED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
2
|
+
import { imageToolbarPluginKey } from "../../extensions/ImageToolbar/ImageToolbarPlugin";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
BlockFromConfig,
|
|
6
|
+
BlockSchemaWithBlock,
|
|
7
|
+
CustomBlockConfig,
|
|
8
|
+
InlineContentSchema,
|
|
9
|
+
PropSchema,
|
|
10
|
+
StyleSchema,
|
|
11
|
+
createBlockSpec,
|
|
12
|
+
} from "../../schema";
|
|
13
|
+
import { defaultProps } from "../defaultProps";
|
|
7
14
|
|
|
8
15
|
export const imagePropSchema = {
|
|
9
16
|
textAlignment: defaultProps.textAlignment,
|
|
@@ -41,50 +48,51 @@ const textAlignmentToAlignItems = (
|
|
|
41
48
|
// Min image width in px.
|
|
42
49
|
const minWidth = 64;
|
|
43
50
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
const blockConfig = {
|
|
52
|
+
type: "image" as const,
|
|
53
|
+
propSchema: imagePropSchema,
|
|
54
|
+
content: "none",
|
|
55
|
+
} satisfies CustomBlockConfig;
|
|
56
|
+
|
|
57
|
+
export const renderImage = (
|
|
58
|
+
block: BlockFromConfig<typeof blockConfig, InlineContentSchema, StyleSchema>,
|
|
59
|
+
editor: BlockNoteEditor<BlockSchemaWithBlock<"image", typeof blockConfig>>
|
|
52
60
|
) => {
|
|
53
61
|
// Wrapper element to set the image alignment, contains both image/image
|
|
54
62
|
// upload dashboard and caption.
|
|
55
63
|
const wrapper = document.createElement("div");
|
|
56
|
-
wrapper.className =
|
|
64
|
+
wrapper.className = "bn-image-block-content-wrapper";
|
|
57
65
|
wrapper.style.alignItems = textAlignmentToAlignItems(
|
|
58
66
|
block.props.textAlignment
|
|
59
67
|
);
|
|
60
68
|
|
|
61
69
|
// Button element that acts as a placeholder for images with no src.
|
|
62
70
|
const addImageButton = document.createElement("div");
|
|
63
|
-
addImageButton.className =
|
|
71
|
+
addImageButton.className = "bn-add-image-button";
|
|
64
72
|
addImageButton.style.display = block.props.url === "" ? "" : "none";
|
|
65
73
|
|
|
66
74
|
// Icon for the add image button.
|
|
67
75
|
const addImageButtonIcon = document.createElement("div");
|
|
68
|
-
addImageButtonIcon.className =
|
|
76
|
+
addImageButtonIcon.className = "bn-add-image-button-icon";
|
|
69
77
|
|
|
70
78
|
// Text for the add image button.
|
|
71
79
|
const addImageButtonText = document.createElement("p");
|
|
72
|
-
addImageButtonText.className =
|
|
80
|
+
addImageButtonText.className = "bn-add-image-button-text";
|
|
73
81
|
addImageButtonText.innerText = "Add Image";
|
|
74
82
|
|
|
75
83
|
// Wrapper element for the image, resize handles and caption.
|
|
76
84
|
const imageAndCaptionWrapper = document.createElement("div");
|
|
77
|
-
imageAndCaptionWrapper.className =
|
|
85
|
+
imageAndCaptionWrapper.className = "bn-image-and-caption-wrapper";
|
|
78
86
|
imageAndCaptionWrapper.style.display = block.props.url !== "" ? "" : "none";
|
|
79
87
|
|
|
80
88
|
// Wrapper element for the image and resize handles.
|
|
81
89
|
const imageWrapper = document.createElement("div");
|
|
82
|
-
imageWrapper.className =
|
|
90
|
+
imageWrapper.className = "bn-image-wrapper";
|
|
83
91
|
imageWrapper.style.display = block.props.url !== "" ? "" : "none";
|
|
84
92
|
|
|
85
93
|
// Image element.
|
|
86
94
|
const image = document.createElement("img");
|
|
87
|
-
image.className =
|
|
95
|
+
image.className = "bn-image";
|
|
88
96
|
image.src = block.props.url;
|
|
89
97
|
image.alt = "placeholder";
|
|
90
98
|
image.contentEditable = "false";
|
|
@@ -96,15 +104,15 @@ const renderImage = (
|
|
|
96
104
|
|
|
97
105
|
// Resize handle elements.
|
|
98
106
|
const leftResizeHandle = document.createElement("div");
|
|
99
|
-
leftResizeHandle.className =
|
|
107
|
+
leftResizeHandle.className = "bn-image-resize-handle";
|
|
100
108
|
leftResizeHandle.style.left = "4px";
|
|
101
109
|
const rightResizeHandle = document.createElement("div");
|
|
102
|
-
rightResizeHandle.className =
|
|
110
|
+
rightResizeHandle.className = "bn-image-resize-handle";
|
|
103
111
|
rightResizeHandle.style.right = "4px";
|
|
104
112
|
|
|
105
113
|
// Caption element.
|
|
106
114
|
const caption = document.createElement("p");
|
|
107
|
-
caption.className =
|
|
115
|
+
caption.className = "bn-image-caption";
|
|
108
116
|
caption.innerText = block.props.caption;
|
|
109
117
|
caption.style.padding = block.props.caption ? "4px" : "";
|
|
110
118
|
|
|
@@ -207,7 +215,7 @@ const renderImage = (
|
|
|
207
215
|
type: "image",
|
|
208
216
|
props: {
|
|
209
217
|
// Removes "px" from the end of the width string and converts to float.
|
|
210
|
-
width: parseFloat(image.style.width.slice(0, -2)),
|
|
218
|
+
width: parseFloat(image.style.width.slice(0, -2)) as any,
|
|
211
219
|
},
|
|
212
220
|
});
|
|
213
221
|
};
|
|
@@ -327,9 +335,57 @@ const renderImage = (
|
|
|
327
335
|
};
|
|
328
336
|
};
|
|
329
337
|
|
|
330
|
-
export const Image = createBlockSpec(
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
338
|
+
export const Image = createBlockSpec(
|
|
339
|
+
{
|
|
340
|
+
type: "image" as const,
|
|
341
|
+
propSchema: imagePropSchema,
|
|
342
|
+
content: "none",
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
render: renderImage,
|
|
346
|
+
toExternalHTML: (block) => {
|
|
347
|
+
if (block.props.url === "") {
|
|
348
|
+
const div = document.createElement("p");
|
|
349
|
+
div.innerHTML = "Add Image";
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
dom: div,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const figure = document.createElement("figure");
|
|
357
|
+
|
|
358
|
+
const img = document.createElement("img");
|
|
359
|
+
img.src = block.props.url;
|
|
360
|
+
figure.appendChild(img);
|
|
361
|
+
|
|
362
|
+
if (block.props.caption !== "") {
|
|
363
|
+
const figcaption = document.createElement("figcaption");
|
|
364
|
+
figcaption.innerHTML = block.props.caption;
|
|
365
|
+
figure.appendChild(figcaption);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return {
|
|
369
|
+
dom: figure,
|
|
370
|
+
};
|
|
371
|
+
},
|
|
372
|
+
parse: (element: HTMLElement) => {
|
|
373
|
+
if (element.tagName === "FIGURE") {
|
|
374
|
+
const img = element.querySelector("img");
|
|
375
|
+
const caption = element.querySelector("figcaption");
|
|
376
|
+
return {
|
|
377
|
+
url: img?.getAttribute("src") || "",
|
|
378
|
+
caption:
|
|
379
|
+
caption?.textContent || img?.getAttribute("alt") || undefined,
|
|
380
|
+
};
|
|
381
|
+
} else if (element.tagName === "IMG") {
|
|
382
|
+
return {
|
|
383
|
+
url: element.getAttribute("src") || "",
|
|
384
|
+
caption: element.getAttribute("alt") || undefined,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return undefined;
|
|
389
|
+
},
|
|
390
|
+
}
|
|
391
|
+
);
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { InputRule
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { InputRule } from "@tiptap/core";
|
|
2
|
+
import {
|
|
3
|
+
PropSchema,
|
|
4
|
+
createBlockSpecFromStronglyTypedTiptapNode,
|
|
5
|
+
createStronglyTypedTiptapNode,
|
|
6
|
+
} from "../../../schema";
|
|
7
|
+
import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers";
|
|
8
|
+
import { defaultProps } from "../../defaultProps";
|
|
6
9
|
import { handleEnter } from "../ListItemKeyboardShortcuts";
|
|
7
|
-
import styles from "../../../Block.module.css";
|
|
8
10
|
|
|
9
11
|
export const bulletListItemPropSchema = {
|
|
10
12
|
...defaultProps,
|
|
11
13
|
} satisfies PropSchema;
|
|
12
14
|
|
|
13
|
-
const BulletListItemBlockContent =
|
|
15
|
+
const BulletListItemBlockContent = createStronglyTypedTiptapNode({
|
|
14
16
|
name: "bulletListItem",
|
|
15
17
|
content: "inline*",
|
|
16
|
-
|
|
18
|
+
group: "blockContent",
|
|
17
19
|
addInputRules() {
|
|
18
20
|
return [
|
|
19
21
|
// Creates an unordered list when starting with "-", "+", or "*".
|
|
@@ -36,13 +38,7 @@ const BulletListItemBlockContent = createTipTapBlock<"bulletListItem", true>({
|
|
|
36
38
|
return {
|
|
37
39
|
Enter: () => handleEnter(this.editor),
|
|
38
40
|
"Mod-Shift-7": () =>
|
|
39
|
-
this.editor.commands.BNUpdateBlock
|
|
40
|
-
bulletListItem: BlockSpec<
|
|
41
|
-
"bulletListItem",
|
|
42
|
-
typeof bulletListItemPropSchema,
|
|
43
|
-
true
|
|
44
|
-
>;
|
|
45
|
-
}>(this.editor.state.selection.anchor, {
|
|
41
|
+
this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor, {
|
|
46
42
|
type: "bulletListItem",
|
|
47
43
|
props: {},
|
|
48
44
|
}),
|
|
@@ -52,6 +48,9 @@ const BulletListItemBlockContent = createTipTapBlock<"bulletListItem", true>({
|
|
|
52
48
|
parseHTML() {
|
|
53
49
|
return [
|
|
54
50
|
// Case for regular HTML list structure.
|
|
51
|
+
{
|
|
52
|
+
tag: "div[data-content-type=" + this.name + "]", // TODO: remove if we can't come up with test case that needs this
|
|
53
|
+
},
|
|
55
54
|
{
|
|
56
55
|
tag: "li",
|
|
57
56
|
getAttrs: (element) => {
|
|
@@ -65,7 +64,10 @@ const BulletListItemBlockContent = createTipTapBlock<"bulletListItem", true>({
|
|
|
65
64
|
return false;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
if (
|
|
67
|
+
if (
|
|
68
|
+
parent.tagName === "UL" ||
|
|
69
|
+
(parent.tagName === "DIV" && parent.parentElement!.tagName === "UL")
|
|
70
|
+
) {
|
|
69
71
|
return {};
|
|
70
72
|
}
|
|
71
73
|
|
|
@@ -100,37 +102,22 @@ const BulletListItemBlockContent = createTipTapBlock<"bulletListItem", true>({
|
|
|
100
102
|
},
|
|
101
103
|
|
|
102
104
|
renderHTML({ HTMLAttributes }) {
|
|
103
|
-
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
...
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
),
|
|
116
|
-
"data-content-type": this.name,
|
|
117
|
-
}),
|
|
118
|
-
[
|
|
119
|
-
"p",
|
|
120
|
-
{
|
|
121
|
-
...inlineContentDOMAttributes,
|
|
122
|
-
class: mergeCSSClasses(
|
|
123
|
-
styles.inlineContent,
|
|
124
|
-
inlineContentDOMAttributes.class
|
|
125
|
-
),
|
|
126
|
-
},
|
|
127
|
-
0,
|
|
128
|
-
],
|
|
129
|
-
];
|
|
105
|
+
return createDefaultBlockDOMOutputSpec(
|
|
106
|
+
this.name,
|
|
107
|
+
// We use a <p> tag, because for <li> tags we'd need a <ul> element to put
|
|
108
|
+
// them in to be semantically correct, which we can't have due to the
|
|
109
|
+
// schema.
|
|
110
|
+
"p",
|
|
111
|
+
{
|
|
112
|
+
...(this.options.domAttributes?.blockContent || {}),
|
|
113
|
+
...HTMLAttributes,
|
|
114
|
+
},
|
|
115
|
+
this.options.domAttributes?.inlineContent || {}
|
|
116
|
+
);
|
|
130
117
|
},
|
|
131
118
|
});
|
|
132
119
|
|
|
133
|
-
export const BulletListItem =
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
120
|
+
export const BulletListItem = createBlockSpecFromStronglyTypedTiptapNode(
|
|
121
|
+
BulletListItemBlockContent,
|
|
122
|
+
bulletListItemPropSchema
|
|
123
|
+
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Editor } from "@tiptap/core";
|
|
2
|
-
import { getBlockInfoFromPos } from "
|
|
2
|
+
import { getBlockInfoFromPos } from "../../api/getBlockInfoFromPos";
|
|
3
3
|
|
|
4
4
|
export const handleEnter = (editor: Editor) => {
|
|
5
5
|
const { node, contentType } = getBlockInfoFromPos(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Plugin, PluginKey } from "prosemirror-state";
|
|
2
|
-
import { getBlockInfoFromPos } from "
|
|
2
|
+
import { getBlockInfoFromPos } from "../../../api/getBlockInfoFromPos";
|
|
3
3
|
|
|
4
4
|
// ProseMirror Plugin which automatically assigns indices to ordered list items per nesting level.
|
|
5
5
|
const PLUGIN_KEY = new PluginKey(`numbered-list-indexing`);
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { InputRule
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { InputRule } from "@tiptap/core";
|
|
2
|
+
import {
|
|
3
|
+
PropSchema,
|
|
4
|
+
createBlockSpecFromStronglyTypedTiptapNode,
|
|
5
|
+
createStronglyTypedTiptapNode,
|
|
6
|
+
} from "../../../schema";
|
|
7
|
+
import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers";
|
|
8
|
+
import { defaultProps } from "../../defaultProps";
|
|
6
9
|
import { handleEnter } from "../ListItemKeyboardShortcuts";
|
|
7
10
|
import { NumberedListIndexingPlugin } from "./NumberedListIndexingPlugin";
|
|
8
|
-
import styles from "../../../Block.module.css";
|
|
9
11
|
|
|
10
12
|
export const numberedListItemPropSchema = {
|
|
11
13
|
...defaultProps,
|
|
12
14
|
} satisfies PropSchema;
|
|
13
15
|
|
|
14
|
-
const NumberedListItemBlockContent =
|
|
15
|
-
"numberedListItem",
|
|
16
|
-
true
|
|
17
|
-
>({
|
|
16
|
+
const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
|
|
18
17
|
name: "numberedListItem",
|
|
19
18
|
content: "inline*",
|
|
20
|
-
|
|
19
|
+
group: "blockContent",
|
|
21
20
|
addAttributes() {
|
|
22
21
|
return {
|
|
23
22
|
index: {
|
|
@@ -54,13 +53,7 @@ const NumberedListItemBlockContent = createTipTapBlock<
|
|
|
54
53
|
return {
|
|
55
54
|
Enter: () => handleEnter(this.editor),
|
|
56
55
|
"Mod-Shift-8": () =>
|
|
57
|
-
this.editor.commands.BNUpdateBlock
|
|
58
|
-
numberedListItem: BlockSpec<
|
|
59
|
-
"numberedListItem",
|
|
60
|
-
typeof numberedListItemPropSchema,
|
|
61
|
-
true
|
|
62
|
-
>;
|
|
63
|
-
}>(this.editor.state.selection.anchor, {
|
|
56
|
+
this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor, {
|
|
64
57
|
type: "numberedListItem",
|
|
65
58
|
props: {},
|
|
66
59
|
}),
|
|
@@ -73,6 +66,9 @@ const NumberedListItemBlockContent = createTipTapBlock<
|
|
|
73
66
|
|
|
74
67
|
parseHTML() {
|
|
75
68
|
return [
|
|
69
|
+
{
|
|
70
|
+
tag: "div[data-content-type=" + this.name + "]", // TODO: remove if we can't come up with test case that needs this
|
|
71
|
+
},
|
|
76
72
|
// Case for regular HTML list structure.
|
|
77
73
|
// (e.g.: when pasting from other apps)
|
|
78
74
|
{
|
|
@@ -88,7 +84,10 @@ const NumberedListItemBlockContent = createTipTapBlock<
|
|
|
88
84
|
return false;
|
|
89
85
|
}
|
|
90
86
|
|
|
91
|
-
if (
|
|
87
|
+
if (
|
|
88
|
+
parent.tagName === "OL" ||
|
|
89
|
+
(parent.tagName === "DIV" && parent.parentElement!.tagName === "OL")
|
|
90
|
+
) {
|
|
92
91
|
return {};
|
|
93
92
|
}
|
|
94
93
|
|
|
@@ -124,43 +123,22 @@ const NumberedListItemBlockContent = createTipTapBlock<
|
|
|
124
123
|
},
|
|
125
124
|
|
|
126
125
|
renderHTML({ HTMLAttributes }) {
|
|
127
|
-
|
|
128
|
-
this.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
...
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
),
|
|
140
|
-
"data-content-type": this.name,
|
|
141
|
-
}),
|
|
142
|
-
// we use a <p> tag, because for <li> tags we'd need to add a <ul> parent for around siblings to be semantically correct,
|
|
143
|
-
// which would be quite cumbersome
|
|
144
|
-
[
|
|
145
|
-
"p",
|
|
146
|
-
{
|
|
147
|
-
...inlineContentDOMAttributes,
|
|
148
|
-
class: mergeCSSClasses(
|
|
149
|
-
styles.inlineContent,
|
|
150
|
-
inlineContentDOMAttributes.class
|
|
151
|
-
),
|
|
152
|
-
},
|
|
153
|
-
0,
|
|
154
|
-
],
|
|
155
|
-
];
|
|
126
|
+
return createDefaultBlockDOMOutputSpec(
|
|
127
|
+
this.name,
|
|
128
|
+
// We use a <p> tag, because for <li> tags we'd need an <ol> element to
|
|
129
|
+
// put them in to be semantically correct, which we can't have due to the
|
|
130
|
+
// schema.
|
|
131
|
+
"p",
|
|
132
|
+
{
|
|
133
|
+
...(this.options.domAttributes?.blockContent || {}),
|
|
134
|
+
...HTMLAttributes,
|
|
135
|
+
},
|
|
136
|
+
this.options.domAttributes?.inlineContent || {}
|
|
137
|
+
);
|
|
156
138
|
},
|
|
157
139
|
});
|
|
158
140
|
|
|
159
|
-
export const NumberedListItem =
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
"numberedListItem",
|
|
164
|
-
typeof numberedListItemPropSchema,
|
|
165
|
-
true
|
|
166
|
-
>;
|
|
141
|
+
export const NumberedListItem = createBlockSpecFromStronglyTypedTiptapNode(
|
|
142
|
+
NumberedListItemBlockContent,
|
|
143
|
+
numberedListItemPropSchema
|
|
144
|
+
);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBlockSpecFromStronglyTypedTiptapNode,
|
|
3
|
+
createStronglyTypedTiptapNode,
|
|
4
|
+
} from "../../schema";
|
|
5
|
+
import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers";
|
|
6
|
+
import { defaultProps } from "../defaultProps";
|
|
7
|
+
|
|
8
|
+
export const paragraphPropSchema = {
|
|
9
|
+
...defaultProps,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const ParagraphBlockContent = createStronglyTypedTiptapNode({
|
|
13
|
+
name: "paragraph",
|
|
14
|
+
content: "inline*",
|
|
15
|
+
group: "blockContent",
|
|
16
|
+
parseHTML() {
|
|
17
|
+
return [
|
|
18
|
+
{ tag: "div[data-content-type=" + this.name + "]" },
|
|
19
|
+
{
|
|
20
|
+
tag: "p",
|
|
21
|
+
priority: 200,
|
|
22
|
+
node: "paragraph",
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
renderHTML({ HTMLAttributes }) {
|
|
28
|
+
return createDefaultBlockDOMOutputSpec(
|
|
29
|
+
this.name,
|
|
30
|
+
"p",
|
|
31
|
+
{
|
|
32
|
+
...(this.options.domAttributes?.blockContent || {}),
|
|
33
|
+
...HTMLAttributes,
|
|
34
|
+
},
|
|
35
|
+
this.options.domAttributes?.inlineContent || {}
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const Paragraph = createBlockSpecFromStronglyTypedTiptapNode(
|
|
41
|
+
ParagraphBlockContent,
|
|
42
|
+
paragraphPropSchema
|
|
43
|
+
);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { mergeAttributes, Node } from "@tiptap/core";
|
|
2
|
+
import { TableCell } from "@tiptap/extension-table-cell";
|
|
3
|
+
import { TableHeader } from "@tiptap/extension-table-header";
|
|
4
|
+
import { TableRow } from "@tiptap/extension-table-row";
|
|
5
|
+
import {
|
|
6
|
+
createBlockSpecFromStronglyTypedTiptapNode,
|
|
7
|
+
createStronglyTypedTiptapNode,
|
|
8
|
+
} from "../../schema";
|
|
9
|
+
import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers";
|
|
10
|
+
import { defaultProps } from "../defaultProps";
|
|
11
|
+
import { TableExtension } from "./TableExtension";
|
|
12
|
+
|
|
13
|
+
export const tablePropSchema = {
|
|
14
|
+
...defaultProps,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const TableBlockContent = createStronglyTypedTiptapNode({
|
|
18
|
+
name: "table",
|
|
19
|
+
content: "tableRow+",
|
|
20
|
+
group: "blockContent",
|
|
21
|
+
tableRole: "table",
|
|
22
|
+
|
|
23
|
+
isolating: true,
|
|
24
|
+
|
|
25
|
+
parseHTML() {
|
|
26
|
+
return [{ tag: "table" }];
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
renderHTML({ HTMLAttributes }) {
|
|
30
|
+
return createDefaultBlockDOMOutputSpec(
|
|
31
|
+
this.name,
|
|
32
|
+
"table",
|
|
33
|
+
{
|
|
34
|
+
...(this.options.domAttributes?.blockContent || {}),
|
|
35
|
+
...HTMLAttributes,
|
|
36
|
+
},
|
|
37
|
+
this.options.domAttributes?.inlineContent || {}
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const TableParagraph = Node.create({
|
|
43
|
+
name: "tableParagraph",
|
|
44
|
+
group: "tableContent",
|
|
45
|
+
content: "inline*",
|
|
46
|
+
|
|
47
|
+
parseHTML() {
|
|
48
|
+
return [{ tag: "p" }];
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
renderHTML({ HTMLAttributes }) {
|
|
52
|
+
return [
|
|
53
|
+
"p",
|
|
54
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
55
|
+
0,
|
|
56
|
+
];
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const Table = createBlockSpecFromStronglyTypedTiptapNode(
|
|
61
|
+
TableBlockContent,
|
|
62
|
+
tablePropSchema,
|
|
63
|
+
[
|
|
64
|
+
TableExtension,
|
|
65
|
+
TableParagraph,
|
|
66
|
+
TableHeader.extend({
|
|
67
|
+
content: "tableContent",
|
|
68
|
+
}),
|
|
69
|
+
TableCell.extend({
|
|
70
|
+
content: "tableContent",
|
|
71
|
+
}),
|
|
72
|
+
TableRow,
|
|
73
|
+
]
|
|
74
|
+
);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { callOrReturn, Extension, getExtensionField } from "@tiptap/core";
|
|
2
|
+
import { columnResizing, tableEditing } from "prosemirror-tables";
|
|
3
|
+
|
|
4
|
+
export const TableExtension = Extension.create({
|
|
5
|
+
name: "BlockNoteTableExtension",
|
|
6
|
+
|
|
7
|
+
addProseMirrorPlugins: () => {
|
|
8
|
+
return [
|
|
9
|
+
columnResizing({
|
|
10
|
+
cellMinWidth: 100,
|
|
11
|
+
}),
|
|
12
|
+
tableEditing(),
|
|
13
|
+
];
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
addKeyboardShortcuts() {
|
|
17
|
+
return {
|
|
18
|
+
// Makes enter create a new line within the cell.
|
|
19
|
+
Enter: () => {
|
|
20
|
+
if (
|
|
21
|
+
this.editor.state.selection.empty &&
|
|
22
|
+
this.editor.state.selection.$head.parent.type.name ===
|
|
23
|
+
"tableParagraph"
|
|
24
|
+
) {
|
|
25
|
+
this.editor.commands.setHardBreak();
|
|
26
|
+
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
// Ensures that backspace won't delete the table if the text cursor is at
|
|
33
|
+
// the start of a cell and the selection is empty.
|
|
34
|
+
Backspace: () => {
|
|
35
|
+
const selection = this.editor.state.selection;
|
|
36
|
+
const selectionIsEmpty = selection.empty;
|
|
37
|
+
const selectionIsAtStartOfNode = selection.$head.parentOffset === 0;
|
|
38
|
+
const selectionIsInTableParagraphNode =
|
|
39
|
+
selection.$head.node().type.name === "tableParagraph";
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
selectionIsEmpty &&
|
|
43
|
+
selectionIsAtStartOfNode &&
|
|
44
|
+
selectionIsInTableParagraphNode
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
extendNodeSchema(extension) {
|
|
51
|
+
const context = {
|
|
52
|
+
name: extension.name,
|
|
53
|
+
options: extension.options,
|
|
54
|
+
storage: extension.storage,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
tableRole: callOrReturn(
|
|
59
|
+
getExtensionField(extension, "tableRole", context)
|
|
60
|
+
),
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
});
|