@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,252 @@
|
|
|
1
|
+
/** Define the main block types **/
|
|
2
|
+
import { Extension, Node } from "@tiptap/core";
|
|
3
|
+
|
|
4
|
+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
5
|
+
import {
|
|
6
|
+
InlineContent,
|
|
7
|
+
InlineContentSchema,
|
|
8
|
+
PartialInlineContent,
|
|
9
|
+
} from "../inlineContent/types";
|
|
10
|
+
import { PropSchema, Props } from "../propTypes";
|
|
11
|
+
import { StyleSchema } from "../styles/types";
|
|
12
|
+
|
|
13
|
+
export type BlockNoteDOMElement =
|
|
14
|
+
| "editor"
|
|
15
|
+
| "blockContainer"
|
|
16
|
+
| "blockGroup"
|
|
17
|
+
| "blockContent"
|
|
18
|
+
| "inlineContent";
|
|
19
|
+
|
|
20
|
+
export type BlockNoteDOMAttributes = Partial<{
|
|
21
|
+
[DOMElement in BlockNoteDOMElement]: Record<string, string>;
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
// BlockConfig contains the "schema" info about a Block type
|
|
25
|
+
// i.e. what props it supports, what content it supports, etc.
|
|
26
|
+
export type BlockConfig = {
|
|
27
|
+
type: string;
|
|
28
|
+
readonly propSchema: PropSchema;
|
|
29
|
+
content: "inline" | "none" | "table";
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Block implementation contains the "implementation" info about a Block
|
|
33
|
+
// such as the functions / Nodes required to render and / or serialize it
|
|
34
|
+
export type TiptapBlockImplementation<
|
|
35
|
+
T extends BlockConfig,
|
|
36
|
+
B extends BlockSchema,
|
|
37
|
+
I extends InlineContentSchema,
|
|
38
|
+
S extends StyleSchema
|
|
39
|
+
> = {
|
|
40
|
+
requiredExtensions?: Array<Extension | Node>;
|
|
41
|
+
node: Node;
|
|
42
|
+
toInternalHTML: (
|
|
43
|
+
block: BlockFromConfigNoChildren<T, I, S> & {
|
|
44
|
+
children: Block<B, I, S>[];
|
|
45
|
+
},
|
|
46
|
+
editor: BlockNoteEditor<B, I, S>
|
|
47
|
+
) => {
|
|
48
|
+
dom: HTMLElement;
|
|
49
|
+
contentDOM?: HTMLElement;
|
|
50
|
+
};
|
|
51
|
+
toExternalHTML: (
|
|
52
|
+
block: BlockFromConfigNoChildren<T, I, S> & {
|
|
53
|
+
children: Block<B, I, S>[];
|
|
54
|
+
},
|
|
55
|
+
editor: BlockNoteEditor<B, I, S>
|
|
56
|
+
) => {
|
|
57
|
+
dom: HTMLElement;
|
|
58
|
+
contentDOM?: HTMLElement;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// A Spec contains both the Config and Implementation
|
|
63
|
+
export type BlockSpec<
|
|
64
|
+
T extends BlockConfig,
|
|
65
|
+
B extends BlockSchema,
|
|
66
|
+
I extends InlineContentSchema,
|
|
67
|
+
S extends StyleSchema
|
|
68
|
+
> = {
|
|
69
|
+
config: T;
|
|
70
|
+
implementation: TiptapBlockImplementation<T, B, I, S>;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Utility type. For a given object block schema, ensures that the key of each
|
|
74
|
+
// block spec matches the name of the TipTap node in it.
|
|
75
|
+
type NamesMatch<Blocks extends Record<string, BlockConfig>> = Blocks extends {
|
|
76
|
+
[Type in keyof Blocks]: Type extends string
|
|
77
|
+
? Blocks[Type] extends { type: Type }
|
|
78
|
+
? Blocks[Type]
|
|
79
|
+
: never
|
|
80
|
+
: never;
|
|
81
|
+
}
|
|
82
|
+
? Blocks
|
|
83
|
+
: never;
|
|
84
|
+
|
|
85
|
+
// A Schema contains all the types (Configs) supported in an editor
|
|
86
|
+
// The keys are the "type" of a block
|
|
87
|
+
export type BlockSchema = NamesMatch<Record<string, BlockConfig>>;
|
|
88
|
+
|
|
89
|
+
export type BlockSpecs = Record<
|
|
90
|
+
string,
|
|
91
|
+
BlockSpec<any, any, InlineContentSchema, StyleSchema>
|
|
92
|
+
>;
|
|
93
|
+
|
|
94
|
+
export type BlockImplementations = Record<
|
|
95
|
+
string,
|
|
96
|
+
TiptapBlockImplementation<any, any, any, any>
|
|
97
|
+
>;
|
|
98
|
+
|
|
99
|
+
export type BlockSchemaFromSpecs<T extends BlockSpecs> = {
|
|
100
|
+
[K in keyof T]: T[K]["config"];
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type BlockSchemaWithBlock<
|
|
104
|
+
BType extends string,
|
|
105
|
+
C extends BlockConfig
|
|
106
|
+
> = {
|
|
107
|
+
[k in BType]: C;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export type TableContent<
|
|
111
|
+
I extends InlineContentSchema,
|
|
112
|
+
S extends StyleSchema = StyleSchema
|
|
113
|
+
> = {
|
|
114
|
+
type: "tableContent";
|
|
115
|
+
rows: {
|
|
116
|
+
cells: InlineContent<I, S>[][];
|
|
117
|
+
}[];
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// A BlockConfig has all the information to get the type of a Block (which is a specific instance of the BlockConfig.
|
|
121
|
+
// i.e.: paragraphConfig: BlockConfig defines what a "paragraph" is / supports, and BlockFromConfigNoChildren<paragraphConfig> is the shape of a specific paragraph block.
|
|
122
|
+
// (for internal use)
|
|
123
|
+
export type BlockFromConfigNoChildren<
|
|
124
|
+
B extends BlockConfig,
|
|
125
|
+
I extends InlineContentSchema,
|
|
126
|
+
S extends StyleSchema
|
|
127
|
+
> = {
|
|
128
|
+
id: string;
|
|
129
|
+
type: B["type"];
|
|
130
|
+
props: Props<B["propSchema"]>;
|
|
131
|
+
content: B["content"] extends "inline"
|
|
132
|
+
? InlineContent<I, S>[]
|
|
133
|
+
: B["content"] extends "table"
|
|
134
|
+
? TableContent<I, S>
|
|
135
|
+
: B["content"] extends "none"
|
|
136
|
+
? undefined
|
|
137
|
+
: never;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export type BlockFromConfig<
|
|
141
|
+
B extends BlockConfig,
|
|
142
|
+
I extends InlineContentSchema,
|
|
143
|
+
S extends StyleSchema
|
|
144
|
+
> = BlockFromConfigNoChildren<B, I, S> & {
|
|
145
|
+
children: Block<BlockSchema, I, S>[];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// Converts each block spec into a Block object without children. We later merge
|
|
149
|
+
// them into a union type and add a children property to create the Block and
|
|
150
|
+
// PartialBlock objects we use in the external API.
|
|
151
|
+
type BlocksWithoutChildren<
|
|
152
|
+
BSchema extends BlockSchema,
|
|
153
|
+
I extends InlineContentSchema,
|
|
154
|
+
S extends StyleSchema
|
|
155
|
+
> = {
|
|
156
|
+
[BType in keyof BSchema]: BlockFromConfigNoChildren<BSchema[BType], I, S>;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// Converts each block spec into a Block object without children, merges them
|
|
160
|
+
// into a union type, and adds a children property
|
|
161
|
+
export type Block<
|
|
162
|
+
BSchema extends BlockSchema,
|
|
163
|
+
I extends InlineContentSchema,
|
|
164
|
+
S extends StyleSchema
|
|
165
|
+
> = BlocksWithoutChildren<BSchema, I, S>[keyof BSchema] & {
|
|
166
|
+
children: Block<BSchema, I, S>[];
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export type SpecificBlock<
|
|
170
|
+
BSchema extends BlockSchema,
|
|
171
|
+
BType extends keyof BSchema,
|
|
172
|
+
I extends InlineContentSchema,
|
|
173
|
+
S extends StyleSchema
|
|
174
|
+
> = BlocksWithoutChildren<BSchema, I, S>[BType] & {
|
|
175
|
+
children: Block<BSchema, I, S>[];
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/** CODE FOR PARTIAL BLOCKS, analogous to above
|
|
179
|
+
*
|
|
180
|
+
* Partial blocks are convenience-wrappers to make it easier to
|
|
181
|
+
*create/update blocks in the editor.
|
|
182
|
+
*
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
export type PartialTableContent<
|
|
186
|
+
I extends InlineContentSchema,
|
|
187
|
+
S extends StyleSchema = StyleSchema
|
|
188
|
+
> = {
|
|
189
|
+
type: "tableContent";
|
|
190
|
+
rows: {
|
|
191
|
+
cells: PartialInlineContent<I, S>[];
|
|
192
|
+
}[];
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
type PartialBlockFromConfigNoChildren<
|
|
196
|
+
B extends BlockConfig,
|
|
197
|
+
I extends InlineContentSchema,
|
|
198
|
+
S extends StyleSchema
|
|
199
|
+
> = {
|
|
200
|
+
id?: string;
|
|
201
|
+
type?: B["type"];
|
|
202
|
+
props?: Partial<Props<B["propSchema"]>>;
|
|
203
|
+
content?: B["content"] extends "inline"
|
|
204
|
+
? PartialInlineContent<I, S>
|
|
205
|
+
: B["content"] extends "table"
|
|
206
|
+
? PartialTableContent<I, S>
|
|
207
|
+
: undefined;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
type PartialBlocksWithoutChildren<
|
|
211
|
+
BSchema extends BlockSchema,
|
|
212
|
+
I extends InlineContentSchema,
|
|
213
|
+
S extends StyleSchema
|
|
214
|
+
> = {
|
|
215
|
+
[BType in keyof BSchema]: PartialBlockFromConfigNoChildren<
|
|
216
|
+
BSchema[BType],
|
|
217
|
+
I,
|
|
218
|
+
S
|
|
219
|
+
>;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export type PartialBlock<
|
|
223
|
+
BSchema extends BlockSchema,
|
|
224
|
+
I extends InlineContentSchema,
|
|
225
|
+
S extends StyleSchema
|
|
226
|
+
> = PartialBlocksWithoutChildren<
|
|
227
|
+
BSchema,
|
|
228
|
+
I,
|
|
229
|
+
S
|
|
230
|
+
>[keyof PartialBlocksWithoutChildren<BSchema, I, S>] &
|
|
231
|
+
Partial<{
|
|
232
|
+
children: PartialBlock<BSchema, I, S>[];
|
|
233
|
+
}>;
|
|
234
|
+
|
|
235
|
+
export type SpecificPartialBlock<
|
|
236
|
+
BSchema extends BlockSchema,
|
|
237
|
+
I extends InlineContentSchema,
|
|
238
|
+
BType extends keyof BSchema,
|
|
239
|
+
S extends StyleSchema
|
|
240
|
+
> = PartialBlocksWithoutChildren<BSchema, I, S>[BType] & {
|
|
241
|
+
children?: Block<BSchema, I, S>[];
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export type PartialBlockFromConfig<
|
|
245
|
+
B extends BlockConfig,
|
|
246
|
+
I extends InlineContentSchema,
|
|
247
|
+
S extends StyleSchema
|
|
248
|
+
> = PartialBlockFromConfigNoChildren<B, I, S> & {
|
|
249
|
+
children?: Block<BlockSchema, I, S>[];
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export type BlockIdentifier = { id: string } | string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./blocks/createSpec";
|
|
2
|
+
export * from "./blocks/internal";
|
|
3
|
+
export * from "./blocks/types";
|
|
4
|
+
export * from "./inlineContent/createSpec";
|
|
5
|
+
export * from "./inlineContent/internal";
|
|
6
|
+
export * from "./inlineContent/types";
|
|
7
|
+
export * from "./propTypes";
|
|
8
|
+
export * from "./styles/createSpec";
|
|
9
|
+
export * from "./styles/internal";
|
|
10
|
+
export * from "./styles/types";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Node } from "@tiptap/core";
|
|
2
|
+
import { ParseRule } from "@tiptap/pm/model";
|
|
3
|
+
import { nodeToCustomInlineContent } from "../../api/nodeConversions/nodeConversions";
|
|
4
|
+
import { propsToAttributes } from "../blocks/internal";
|
|
5
|
+
import { Props } from "../propTypes";
|
|
6
|
+
import { StyleSchema } from "../styles/types";
|
|
7
|
+
import {
|
|
8
|
+
addInlineContentAttributes,
|
|
9
|
+
addInlineContentKeyboardShortcuts,
|
|
10
|
+
createInlineContentSpecFromTipTapNode,
|
|
11
|
+
} from "./internal";
|
|
12
|
+
import {
|
|
13
|
+
CustomInlineContentConfig,
|
|
14
|
+
InlineContentConfig,
|
|
15
|
+
InlineContentFromConfig,
|
|
16
|
+
InlineContentSpec,
|
|
17
|
+
} from "./types";
|
|
18
|
+
|
|
19
|
+
// TODO: support serialization
|
|
20
|
+
|
|
21
|
+
export type CustomInlineContentImplementation<
|
|
22
|
+
T extends InlineContentConfig,
|
|
23
|
+
// B extends BlockSchema,
|
|
24
|
+
// I extends InlineContentSchema,
|
|
25
|
+
S extends StyleSchema
|
|
26
|
+
> = {
|
|
27
|
+
render: (
|
|
28
|
+
/**
|
|
29
|
+
* The custom inline content to render
|
|
30
|
+
*/
|
|
31
|
+
inlineContent: InlineContentFromConfig<T, S>
|
|
32
|
+
/**
|
|
33
|
+
* The BlockNote editor instance
|
|
34
|
+
* This is typed generically. If you want an editor with your custom schema, you need to
|
|
35
|
+
* cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
|
|
36
|
+
*/
|
|
37
|
+
// editor: BlockNoteEditor<B, I, S>
|
|
38
|
+
// (note) if we want to fix the manual cast, we need to prevent circular references and separate block definition and render implementations
|
|
39
|
+
// or allow manually passing <BSchema>, but that's not possible without passing the other generics because Typescript doesn't support partial inferred generics
|
|
40
|
+
) => {
|
|
41
|
+
dom: HTMLElement;
|
|
42
|
+
contentDOM?: HTMLElement;
|
|
43
|
+
// destroy?: () => void;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export function getInlineContentParseRules(
|
|
48
|
+
config: CustomInlineContentConfig
|
|
49
|
+
): ParseRule[] {
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
tag: `[data-inline-content-type="${config.type}"]`,
|
|
53
|
+
contentElement: (element) => {
|
|
54
|
+
const htmlElement = element as HTMLElement;
|
|
55
|
+
|
|
56
|
+
if (htmlElement.matches("[data-editable]")) {
|
|
57
|
+
return htmlElement;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return htmlElement.querySelector("[data-editable]") || htmlElement;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function createInlineContentSpec<
|
|
67
|
+
T extends CustomInlineContentConfig,
|
|
68
|
+
S extends StyleSchema
|
|
69
|
+
>(
|
|
70
|
+
inlineContentConfig: T,
|
|
71
|
+
inlineContentImplementation: CustomInlineContentImplementation<T, S>
|
|
72
|
+
): InlineContentSpec<T> {
|
|
73
|
+
const node = Node.create({
|
|
74
|
+
name: inlineContentConfig.type,
|
|
75
|
+
inline: true,
|
|
76
|
+
group: "inline",
|
|
77
|
+
selectable: inlineContentConfig.content === "styled",
|
|
78
|
+
atom: inlineContentConfig.content === "none",
|
|
79
|
+
content: (inlineContentConfig.content === "styled"
|
|
80
|
+
? "inline*"
|
|
81
|
+
: "") as T["content"] extends "styled" ? "inline*" : "",
|
|
82
|
+
|
|
83
|
+
addAttributes() {
|
|
84
|
+
return propsToAttributes(inlineContentConfig.propSchema);
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
addKeyboardShortcuts() {
|
|
88
|
+
return addInlineContentKeyboardShortcuts(inlineContentConfig);
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
parseHTML() {
|
|
92
|
+
return getInlineContentParseRules(inlineContentConfig);
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
renderHTML({ node }) {
|
|
96
|
+
const editor = this.options.editor;
|
|
97
|
+
|
|
98
|
+
const output = inlineContentImplementation.render(
|
|
99
|
+
nodeToCustomInlineContent(
|
|
100
|
+
node,
|
|
101
|
+
editor.inlineContentSchema,
|
|
102
|
+
editor.styleSchema
|
|
103
|
+
) as any as InlineContentFromConfig<T, S> // TODO: fix cast
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return addInlineContentAttributes(
|
|
107
|
+
output,
|
|
108
|
+
inlineContentConfig.type,
|
|
109
|
+
node.attrs as Props<T["propSchema"]>,
|
|
110
|
+
inlineContentConfig.propSchema
|
|
111
|
+
);
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return createInlineContentSpecFromTipTapNode(
|
|
116
|
+
node,
|
|
117
|
+
inlineContentConfig.propSchema
|
|
118
|
+
) as InlineContentSpec<T>; // TODO: fix cast
|
|
119
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { KeyboardShortcutCommand, Node } from "@tiptap/core";
|
|
2
|
+
|
|
3
|
+
import { camelToDataKebab } from "../../util/string";
|
|
4
|
+
import { PropSchema, Props } from "../propTypes";
|
|
5
|
+
import {
|
|
6
|
+
CustomInlineContentConfig,
|
|
7
|
+
InlineContentConfig,
|
|
8
|
+
InlineContentImplementation,
|
|
9
|
+
InlineContentSchemaFromSpecs,
|
|
10
|
+
InlineContentSpec,
|
|
11
|
+
InlineContentSpecs,
|
|
12
|
+
} from "./types";
|
|
13
|
+
|
|
14
|
+
// Function that adds necessary classes and attributes to the `dom` element
|
|
15
|
+
// returned from a custom inline content's 'render' function, to ensure no data
|
|
16
|
+
// is lost on internal copy & paste.
|
|
17
|
+
export function addInlineContentAttributes<
|
|
18
|
+
IType extends string,
|
|
19
|
+
PSchema extends PropSchema
|
|
20
|
+
>(
|
|
21
|
+
element: {
|
|
22
|
+
dom: HTMLElement;
|
|
23
|
+
contentDOM?: HTMLElement;
|
|
24
|
+
},
|
|
25
|
+
inlineContentType: IType,
|
|
26
|
+
inlineContentProps: Props<PSchema>,
|
|
27
|
+
propSchema: PSchema
|
|
28
|
+
): {
|
|
29
|
+
dom: HTMLElement;
|
|
30
|
+
contentDOM?: HTMLElement;
|
|
31
|
+
} {
|
|
32
|
+
// Sets content type attribute
|
|
33
|
+
element.dom.setAttribute("data-inline-content-type", inlineContentType);
|
|
34
|
+
// Adds props as HTML attributes in kebab-case with "data-" prefix. Skips props
|
|
35
|
+
// set to their default values.
|
|
36
|
+
Object.entries(inlineContentProps)
|
|
37
|
+
.filter(([prop, value]) => value !== propSchema[prop].default)
|
|
38
|
+
.map(([prop, value]) => {
|
|
39
|
+
return [camelToDataKebab(prop), value];
|
|
40
|
+
})
|
|
41
|
+
.forEach(([prop, value]) => element.dom.setAttribute(prop, value));
|
|
42
|
+
|
|
43
|
+
if (element.contentDOM !== undefined) {
|
|
44
|
+
element.contentDOM.setAttribute("data-editable", "");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return element;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// see https://github.com/TypeCellOS/BlockNote/pull/435
|
|
51
|
+
export function addInlineContentKeyboardShortcuts<
|
|
52
|
+
T extends CustomInlineContentConfig
|
|
53
|
+
>(
|
|
54
|
+
config: T
|
|
55
|
+
): {
|
|
56
|
+
[p: string]: KeyboardShortcutCommand;
|
|
57
|
+
} {
|
|
58
|
+
return {
|
|
59
|
+
Backspace: ({ editor }) => {
|
|
60
|
+
const resolvedPos = editor.state.selection.$from;
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
editor.state.selection.empty &&
|
|
64
|
+
resolvedPos.node().type.name === config.type &&
|
|
65
|
+
resolvedPos.parentOffset === 0
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// This helper function helps to instantiate a InlineContentSpec with a
|
|
72
|
+
// config and implementation that conform to the type of Config
|
|
73
|
+
export function createInternalInlineContentSpec<T extends InlineContentConfig>(
|
|
74
|
+
config: T,
|
|
75
|
+
implementation: InlineContentImplementation<T>
|
|
76
|
+
) {
|
|
77
|
+
return {
|
|
78
|
+
config,
|
|
79
|
+
implementation,
|
|
80
|
+
} satisfies InlineContentSpec<T>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function createInlineContentSpecFromTipTapNode<
|
|
84
|
+
T extends Node,
|
|
85
|
+
P extends PropSchema
|
|
86
|
+
>(node: T, propSchema: P) {
|
|
87
|
+
return createInternalInlineContentSpec(
|
|
88
|
+
{
|
|
89
|
+
type: node.name as T["name"],
|
|
90
|
+
propSchema,
|
|
91
|
+
content: node.config.content === "inline*" ? "styled" : "none",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
node,
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function getInlineContentSchemaFromSpecs<T extends InlineContentSpecs>(
|
|
100
|
+
specs: T
|
|
101
|
+
) {
|
|
102
|
+
return Object.fromEntries(
|
|
103
|
+
Object.entries(specs).map(([key, value]) => [key, value.config])
|
|
104
|
+
) as InlineContentSchemaFromSpecs<T>;
|
|
105
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Node } from "@tiptap/core";
|
|
2
|
+
import { PropSchema, Props } from "../propTypes";
|
|
3
|
+
import { StyleSchema, Styles } from "../styles/types";
|
|
4
|
+
|
|
5
|
+
export type CustomInlineContentConfig = {
|
|
6
|
+
type: string;
|
|
7
|
+
content: "styled" | "none"; // | "plain"
|
|
8
|
+
readonly propSchema: PropSchema;
|
|
9
|
+
// content: "inline" | "none" | "table";
|
|
10
|
+
};
|
|
11
|
+
// InlineContentConfig contains the "schema" info about an InlineContent type
|
|
12
|
+
// i.e. what props it supports, what content it supports, etc.
|
|
13
|
+
export type InlineContentConfig = CustomInlineContentConfig | "text" | "link";
|
|
14
|
+
|
|
15
|
+
// InlineContentImplementation contains the "implementation" info about an InlineContent element
|
|
16
|
+
// such as the functions / Nodes required to render and / or serialize it
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
export type InlineContentImplementation<T extends InlineContentConfig> =
|
|
19
|
+
T extends "link" | "text"
|
|
20
|
+
? undefined
|
|
21
|
+
: {
|
|
22
|
+
node: Node;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Container for both the config and implementation of InlineContent,
|
|
26
|
+
// and the type of `implementation` is based on that of the config
|
|
27
|
+
export type InlineContentSpec<T extends InlineContentConfig> = {
|
|
28
|
+
config: T;
|
|
29
|
+
implementation: InlineContentImplementation<T>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// A Schema contains all the types (Configs) supported in an editor
|
|
33
|
+
// The keys are the "type" of InlineContent elements
|
|
34
|
+
export type InlineContentSchema = Record<string, InlineContentConfig>;
|
|
35
|
+
|
|
36
|
+
export type InlineContentSpecs = {
|
|
37
|
+
text: { config: "text"; implementation: undefined };
|
|
38
|
+
link: { config: "link"; implementation: undefined };
|
|
39
|
+
} & Record<string, InlineContentSpec<InlineContentConfig>>;
|
|
40
|
+
|
|
41
|
+
export type InlineContentSchemaFromSpecs<T extends InlineContentSpecs> = {
|
|
42
|
+
[K in keyof T]: T[K]["config"];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type CustomInlineContentFromConfig<
|
|
46
|
+
I extends CustomInlineContentConfig,
|
|
47
|
+
S extends StyleSchema
|
|
48
|
+
> = {
|
|
49
|
+
type: I["type"];
|
|
50
|
+
props: Props<I["propSchema"]>;
|
|
51
|
+
content: I["content"] extends "styled"
|
|
52
|
+
? StyledText<S>[]
|
|
53
|
+
: I["content"] extends "plain"
|
|
54
|
+
? string
|
|
55
|
+
: I["content"] extends "none"
|
|
56
|
+
? undefined
|
|
57
|
+
: never;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type InlineContentFromConfig<
|
|
61
|
+
I extends InlineContentConfig,
|
|
62
|
+
S extends StyleSchema
|
|
63
|
+
> = I extends "text"
|
|
64
|
+
? StyledText<S>
|
|
65
|
+
: I extends "link"
|
|
66
|
+
? Link<S>
|
|
67
|
+
: I extends CustomInlineContentConfig
|
|
68
|
+
? CustomInlineContentFromConfig<I, S>
|
|
69
|
+
: never;
|
|
70
|
+
|
|
71
|
+
export type PartialCustomInlineContentFromConfig<
|
|
72
|
+
I extends CustomInlineContentConfig,
|
|
73
|
+
S extends StyleSchema
|
|
74
|
+
> = {
|
|
75
|
+
type: I["type"];
|
|
76
|
+
props?: Props<I["propSchema"]>;
|
|
77
|
+
content: I["content"] extends "styled"
|
|
78
|
+
? StyledText<S>[] | string
|
|
79
|
+
: I["content"] extends "plain"
|
|
80
|
+
? string
|
|
81
|
+
: I["content"] extends "none"
|
|
82
|
+
? undefined
|
|
83
|
+
: never;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type PartialInlineContentFromConfig<
|
|
87
|
+
I extends InlineContentConfig,
|
|
88
|
+
S extends StyleSchema
|
|
89
|
+
> = I extends "text"
|
|
90
|
+
? string | StyledText<S>
|
|
91
|
+
: I extends "link"
|
|
92
|
+
? PartialLink<S>
|
|
93
|
+
: I extends CustomInlineContentConfig
|
|
94
|
+
? PartialCustomInlineContentFromConfig<I, S>
|
|
95
|
+
: never;
|
|
96
|
+
|
|
97
|
+
export type StyledText<T extends StyleSchema> = {
|
|
98
|
+
type: "text";
|
|
99
|
+
text: string;
|
|
100
|
+
styles: Styles<T>;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type Link<T extends StyleSchema> = {
|
|
104
|
+
type: "link";
|
|
105
|
+
href: string;
|
|
106
|
+
content: StyledText<T>[];
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type PartialLink<T extends StyleSchema> = Omit<Link<T>, "content"> & {
|
|
110
|
+
content: string | Link<T>["content"];
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type InlineContent<
|
|
114
|
+
I extends InlineContentSchema,
|
|
115
|
+
T extends StyleSchema
|
|
116
|
+
> = InlineContentFromConfig<I[keyof I], T>;
|
|
117
|
+
|
|
118
|
+
type PartialInlineContentElement<
|
|
119
|
+
I extends InlineContentSchema,
|
|
120
|
+
T extends StyleSchema
|
|
121
|
+
> = PartialInlineContentFromConfig<I[keyof I], T>;
|
|
122
|
+
|
|
123
|
+
export type PartialInlineContent<
|
|
124
|
+
I extends InlineContentSchema,
|
|
125
|
+
T extends StyleSchema
|
|
126
|
+
> = PartialInlineContentElement<I, T>[] | string;
|
|
127
|
+
|
|
128
|
+
export function isLinkInlineContent<T extends StyleSchema>(
|
|
129
|
+
content: InlineContent<any, T>
|
|
130
|
+
): content is Link<T> {
|
|
131
|
+
return content.type === "link";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function isPartialLinkInlineContent<T extends StyleSchema>(
|
|
135
|
+
content: PartialInlineContentElement<any, T>
|
|
136
|
+
): content is PartialLink<T> {
|
|
137
|
+
return typeof content !== "string" && content.type === "link";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function isStyledTextInlineContent<T extends StyleSchema>(
|
|
141
|
+
content: PartialInlineContentElement<any, T>
|
|
142
|
+
): content is StyledText<T> {
|
|
143
|
+
return typeof content !== "string" && content.type === "text";
|
|
144
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Defines a single prop spec, which includes the default value the prop should
|
|
2
|
+
// take and possible values it can take.
|
|
3
|
+
export type PropSpec<PType extends boolean | number | string> = {
|
|
4
|
+
values?: readonly PType[];
|
|
5
|
+
default: PType;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// Defines multiple block prop specs. The key of each prop is the name of the
|
|
9
|
+
// prop, while the value is a corresponding prop spec. This should be included
|
|
10
|
+
// in a block config or schema. From a prop schema, we can derive both the props'
|
|
11
|
+
// internal implementation (as TipTap node attributes) and the type information
|
|
12
|
+
// for the external API.
|
|
13
|
+
export type PropSchema = Record<string, PropSpec<boolean | number | string>>;
|
|
14
|
+
|
|
15
|
+
// Defines Props objects for use in Block objects in the external API. Converts
|
|
16
|
+
// each prop spec into a union type of its possible values, or a string if no
|
|
17
|
+
// values are specified.
|
|
18
|
+
export type Props<PSchema extends PropSchema> = {
|
|
19
|
+
[PName in keyof PSchema]: PSchema[PName]["default"] extends boolean
|
|
20
|
+
? PSchema[PName]["values"] extends readonly boolean[]
|
|
21
|
+
? PSchema[PName]["values"][number]
|
|
22
|
+
: boolean
|
|
23
|
+
: PSchema[PName]["default"] extends number
|
|
24
|
+
? PSchema[PName]["values"] extends readonly number[]
|
|
25
|
+
? PSchema[PName]["values"][number]
|
|
26
|
+
: number
|
|
27
|
+
: PSchema[PName]["default"] extends string
|
|
28
|
+
? PSchema[PName]["values"] extends readonly string[]
|
|
29
|
+
? PSchema[PName]["values"][number]
|
|
30
|
+
: string
|
|
31
|
+
: never;
|
|
32
|
+
};
|