@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
|
@@ -1,44 +1,56 @@
|
|
|
1
|
-
import { Mark } from "@tiptap/pm/model";
|
|
2
|
-
|
|
3
|
-
import
|
|
1
|
+
import { Mark, Node, Schema } from "@tiptap/pm/model";
|
|
2
|
+
|
|
3
|
+
import UniqueID from "../../extensions/UniqueID/UniqueID";
|
|
4
|
+
import type {
|
|
4
5
|
Block,
|
|
5
6
|
BlockSchema,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
ColorStyle,
|
|
7
|
+
CustomInlineContentConfig,
|
|
8
|
+
CustomInlineContentFromConfig,
|
|
10
9
|
InlineContent,
|
|
10
|
+
InlineContentFromConfig,
|
|
11
|
+
InlineContentSchema,
|
|
12
|
+
PartialBlock,
|
|
13
|
+
PartialCustomInlineContentFromConfig,
|
|
11
14
|
PartialInlineContent,
|
|
12
15
|
PartialLink,
|
|
16
|
+
PartialTableContent,
|
|
17
|
+
StyleSchema,
|
|
13
18
|
StyledText,
|
|
14
19
|
Styles,
|
|
15
|
-
|
|
16
|
-
} from "../../
|
|
17
|
-
import { getBlockInfo } from "
|
|
18
|
-
import UniqueID from "../../extensions/UniqueID/UniqueID";
|
|
19
|
-
import { UnreachableCaseError } from "../../shared/utils";
|
|
20
|
+
TableContent,
|
|
21
|
+
} from "../../schema";
|
|
22
|
+
import { getBlockInfo } from "../getBlockInfoFromPos";
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
]);
|
|
28
|
-
const colorStyles = new Set<ColorStyle>(["textColor", "backgroundColor"]);
|
|
24
|
+
import {
|
|
25
|
+
isLinkInlineContent,
|
|
26
|
+
isPartialLinkInlineContent,
|
|
27
|
+
isStyledTextInlineContent,
|
|
28
|
+
} from "../../schema/inlineContent/types";
|
|
29
|
+
import { UnreachableCaseError } from "../../util/typescript";
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* Convert a StyledText inline element to a
|
|
32
33
|
* prosemirror text node with the appropriate marks
|
|
33
34
|
*/
|
|
34
|
-
function styledTextToNodes
|
|
35
|
+
function styledTextToNodes<T extends StyleSchema>(
|
|
36
|
+
styledText: StyledText<T>,
|
|
37
|
+
schema: Schema,
|
|
38
|
+
styleSchema: T
|
|
39
|
+
): Node[] {
|
|
35
40
|
const marks: Mark[] = [];
|
|
36
41
|
|
|
37
42
|
for (const [style, value] of Object.entries(styledText.styles)) {
|
|
38
|
-
|
|
43
|
+
const config = styleSchema[style];
|
|
44
|
+
if (!config) {
|
|
45
|
+
throw new Error(`style ${style} not found in styleSchema`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (config.propSchema === "boolean") {
|
|
39
49
|
marks.push(schema.mark(style));
|
|
40
|
-
} else if (
|
|
41
|
-
marks.push(schema.mark(style, {
|
|
50
|
+
} else if (config.propSchema === "string") {
|
|
51
|
+
marks.push(schema.mark(style, { stringValue: value }));
|
|
52
|
+
} else {
|
|
53
|
+
throw new UnreachableCaseError(config.propSchema);
|
|
42
54
|
}
|
|
43
55
|
}
|
|
44
56
|
|
|
@@ -64,42 +76,53 @@ function styledTextToNodes(styledText: StyledText, schema: Schema): Node[] {
|
|
|
64
76
|
* Converts a Link inline content element to
|
|
65
77
|
* prosemirror text nodes with the appropriate marks
|
|
66
78
|
*/
|
|
67
|
-
function linkToNodes(
|
|
79
|
+
function linkToNodes(
|
|
80
|
+
link: PartialLink<StyleSchema>,
|
|
81
|
+
schema: Schema,
|
|
82
|
+
styleSchema: StyleSchema
|
|
83
|
+
): Node[] {
|
|
68
84
|
const linkMark = schema.marks.link.create({
|
|
69
85
|
href: link.href,
|
|
70
86
|
});
|
|
71
87
|
|
|
72
|
-
return styledTextArrayToNodes(link.content, schema).map(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
return styledTextArrayToNodes(link.content, schema, styleSchema).map(
|
|
89
|
+
(node) => {
|
|
90
|
+
if (node.type.name === "text") {
|
|
91
|
+
return node.mark([...node.marks, linkMark]);
|
|
92
|
+
}
|
|
76
93
|
|
|
77
|
-
|
|
78
|
-
|
|
94
|
+
if (node.type.name === "hardBreak") {
|
|
95
|
+
return node;
|
|
96
|
+
}
|
|
97
|
+
throw new Error("unexpected node type");
|
|
79
98
|
}
|
|
80
|
-
|
|
81
|
-
});
|
|
99
|
+
);
|
|
82
100
|
}
|
|
83
101
|
|
|
84
102
|
/**
|
|
85
103
|
* Converts an array of StyledText inline content elements to
|
|
86
104
|
* prosemirror text nodes with the appropriate marks
|
|
87
105
|
*/
|
|
88
|
-
function styledTextArrayToNodes(
|
|
89
|
-
content: string | StyledText[],
|
|
90
|
-
schema: Schema
|
|
106
|
+
function styledTextArrayToNodes<S extends StyleSchema>(
|
|
107
|
+
content: string | StyledText<S>[],
|
|
108
|
+
schema: Schema,
|
|
109
|
+
styleSchema: S
|
|
91
110
|
): Node[] {
|
|
92
111
|
const nodes: Node[] = [];
|
|
93
112
|
|
|
94
113
|
if (typeof content === "string") {
|
|
95
114
|
nodes.push(
|
|
96
|
-
...styledTextToNodes(
|
|
115
|
+
...styledTextToNodes(
|
|
116
|
+
{ type: "text", text: content, styles: {} },
|
|
117
|
+
schema,
|
|
118
|
+
styleSchema
|
|
119
|
+
)
|
|
97
120
|
);
|
|
98
121
|
return nodes;
|
|
99
122
|
}
|
|
100
123
|
|
|
101
124
|
for (const styledText of content) {
|
|
102
|
-
nodes.push(...styledTextToNodes(styledText, schema));
|
|
125
|
+
nodes.push(...styledTextToNodes(styledText, schema, styleSchema));
|
|
103
126
|
}
|
|
104
127
|
return nodes;
|
|
105
128
|
}
|
|
@@ -107,44 +130,85 @@ function styledTextArrayToNodes(
|
|
|
107
130
|
/**
|
|
108
131
|
* converts an array of inline content elements to prosemirror nodes
|
|
109
132
|
*/
|
|
110
|
-
export function inlineContentToNodes
|
|
111
|
-
|
|
112
|
-
|
|
133
|
+
export function inlineContentToNodes<
|
|
134
|
+
I extends InlineContentSchema,
|
|
135
|
+
S extends StyleSchema
|
|
136
|
+
>(
|
|
137
|
+
blockContent: PartialInlineContent<I, S>,
|
|
138
|
+
schema: Schema,
|
|
139
|
+
styleSchema: S
|
|
113
140
|
): Node[] {
|
|
114
141
|
const nodes: Node[] = [];
|
|
115
142
|
|
|
116
143
|
for (const content of blockContent) {
|
|
117
|
-
if (content
|
|
118
|
-
nodes.push(...
|
|
119
|
-
} else if (content
|
|
120
|
-
nodes.push(...
|
|
144
|
+
if (typeof content === "string") {
|
|
145
|
+
nodes.push(...styledTextArrayToNodes(content, schema, styleSchema));
|
|
146
|
+
} else if (isPartialLinkInlineContent(content)) {
|
|
147
|
+
nodes.push(...linkToNodes(content, schema, styleSchema));
|
|
148
|
+
} else if (isStyledTextInlineContent(content)) {
|
|
149
|
+
nodes.push(...styledTextArrayToNodes([content], schema, styleSchema));
|
|
121
150
|
} else {
|
|
122
|
-
|
|
151
|
+
nodes.push(
|
|
152
|
+
blockOrInlineContentToContentNode(content, schema, styleSchema)
|
|
153
|
+
);
|
|
123
154
|
}
|
|
124
155
|
}
|
|
125
156
|
return nodes;
|
|
126
157
|
}
|
|
127
158
|
|
|
128
159
|
/**
|
|
129
|
-
*
|
|
160
|
+
* converts an array of inline content elements to prosemirror nodes
|
|
130
161
|
*/
|
|
131
|
-
export function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
162
|
+
export function tableContentToNodes<
|
|
163
|
+
I extends InlineContentSchema,
|
|
164
|
+
S extends StyleSchema
|
|
165
|
+
>(
|
|
166
|
+
tableContent: PartialTableContent<I, S>,
|
|
167
|
+
schema: Schema,
|
|
168
|
+
styleSchema: StyleSchema
|
|
169
|
+
): Node[] {
|
|
170
|
+
const rowNodes: Node[] = [];
|
|
171
|
+
|
|
172
|
+
for (const row of tableContent.rows) {
|
|
173
|
+
const columnNodes: Node[] = [];
|
|
174
|
+
for (const cell of row.cells) {
|
|
175
|
+
let pNode: Node;
|
|
176
|
+
if (!cell) {
|
|
177
|
+
pNode = schema.nodes["tableParagraph"].create({});
|
|
178
|
+
} else if (typeof cell === "string") {
|
|
179
|
+
pNode = schema.nodes["tableParagraph"].create({}, schema.text(cell));
|
|
180
|
+
} else {
|
|
181
|
+
const textNodes = inlineContentToNodes(cell, schema, styleSchema);
|
|
182
|
+
pNode = schema.nodes["tableParagraph"].create({}, textNodes);
|
|
183
|
+
}
|
|
136
184
|
|
|
137
|
-
|
|
138
|
-
|
|
185
|
+
const cellNode = schema.nodes["tableCell"].create({}, pNode);
|
|
186
|
+
columnNodes.push(cellNode);
|
|
187
|
+
}
|
|
188
|
+
const rowNode = schema.nodes["tableRow"].create({}, columnNodes);
|
|
189
|
+
rowNodes.push(rowNode);
|
|
139
190
|
}
|
|
191
|
+
return rowNodes;
|
|
192
|
+
}
|
|
140
193
|
|
|
194
|
+
function blockOrInlineContentToContentNode(
|
|
195
|
+
block:
|
|
196
|
+
| PartialBlock<any, any, any>
|
|
197
|
+
| PartialCustomInlineContentFromConfig<any, any>,
|
|
198
|
+
schema: Schema,
|
|
199
|
+
styleSchema: StyleSchema
|
|
200
|
+
) {
|
|
201
|
+
let contentNode: Node;
|
|
141
202
|
let type = block.type;
|
|
142
203
|
|
|
204
|
+
// TODO: needed? came from previous code
|
|
143
205
|
if (type === undefined) {
|
|
144
206
|
type = "paragraph";
|
|
145
207
|
}
|
|
146
208
|
|
|
147
|
-
|
|
209
|
+
if (!schema.nodes[type]) {
|
|
210
|
+
throw new Error(`node type ${type} not found in schema`);
|
|
211
|
+
}
|
|
148
212
|
|
|
149
213
|
if (!block.content) {
|
|
150
214
|
contentNode = schema.nodes[type].create(block.props);
|
|
@@ -153,16 +217,42 @@ export function blockToNode<BSchema extends BlockSchema>(
|
|
|
153
217
|
block.props,
|
|
154
218
|
schema.text(block.content)
|
|
155
219
|
);
|
|
156
|
-
} else {
|
|
157
|
-
const nodes = inlineContentToNodes(block.content, schema);
|
|
220
|
+
} else if (Array.isArray(block.content)) {
|
|
221
|
+
const nodes = inlineContentToNodes(block.content, schema, styleSchema);
|
|
158
222
|
contentNode = schema.nodes[type].create(block.props, nodes);
|
|
223
|
+
} else if (block.content.type === "tableContent") {
|
|
224
|
+
const nodes = tableContentToNodes(block.content, schema, styleSchema);
|
|
225
|
+
contentNode = schema.nodes[type].create(block.props, nodes);
|
|
226
|
+
} else {
|
|
227
|
+
throw new UnreachableCaseError(block.content.type);
|
|
228
|
+
}
|
|
229
|
+
return contentNode;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Converts a BlockNote block to a TipTap node.
|
|
233
|
+
*/
|
|
234
|
+
export function blockToNode(
|
|
235
|
+
block: PartialBlock<any, any, any>,
|
|
236
|
+
schema: Schema,
|
|
237
|
+
styleSchema: StyleSchema
|
|
238
|
+
) {
|
|
239
|
+
let id = block.id;
|
|
240
|
+
|
|
241
|
+
if (id === undefined) {
|
|
242
|
+
id = UniqueID.options.generateID();
|
|
159
243
|
}
|
|
160
244
|
|
|
245
|
+
const contentNode = blockOrInlineContentToContentNode(
|
|
246
|
+
block,
|
|
247
|
+
schema,
|
|
248
|
+
styleSchema
|
|
249
|
+
);
|
|
250
|
+
|
|
161
251
|
const children: Node[] = [];
|
|
162
252
|
|
|
163
253
|
if (block.children) {
|
|
164
254
|
for (const child of block.children) {
|
|
165
|
-
children.push(blockToNode(child, schema));
|
|
255
|
+
children.push(blockToNode(child, schema, styleSchema));
|
|
166
256
|
}
|
|
167
257
|
}
|
|
168
258
|
|
|
@@ -177,12 +267,48 @@ export function blockToNode<BSchema extends BlockSchema>(
|
|
|
177
267
|
);
|
|
178
268
|
}
|
|
179
269
|
|
|
270
|
+
/**
|
|
271
|
+
* Converts an internal (prosemirror) table node contentto a BlockNote Tablecontent
|
|
272
|
+
*/
|
|
273
|
+
function contentNodeToTableContent<
|
|
274
|
+
I extends InlineContentSchema,
|
|
275
|
+
S extends StyleSchema
|
|
276
|
+
>(contentNode: Node, inlineContentSchema: I, styleSchema: S) {
|
|
277
|
+
const ret: TableContent<I, S> = {
|
|
278
|
+
type: "tableContent",
|
|
279
|
+
rows: [],
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
contentNode.content.forEach((rowNode) => {
|
|
283
|
+
const row: TableContent<I, S>["rows"][0] = {
|
|
284
|
+
cells: [],
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
rowNode.content.forEach((cellNode) => {
|
|
288
|
+
row.cells.push(
|
|
289
|
+
contentNodeToInlineContent(
|
|
290
|
+
cellNode.firstChild!,
|
|
291
|
+
inlineContentSchema,
|
|
292
|
+
styleSchema
|
|
293
|
+
)
|
|
294
|
+
);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
ret.rows.push(row);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
return ret;
|
|
301
|
+
}
|
|
302
|
+
|
|
180
303
|
/**
|
|
181
304
|
* Converts an internal (prosemirror) content node to a BlockNote InlineContent array.
|
|
182
305
|
*/
|
|
183
|
-
function contentNodeToInlineContent
|
|
184
|
-
|
|
185
|
-
|
|
306
|
+
export function contentNodeToInlineContent<
|
|
307
|
+
I extends InlineContentSchema,
|
|
308
|
+
S extends StyleSchema
|
|
309
|
+
>(contentNode: Node, inlineContentSchema: I, styleSchema: S) {
|
|
310
|
+
const content: InlineContent<any, S>[] = [];
|
|
311
|
+
let currentContent: InlineContent<any, S> | undefined = undefined;
|
|
186
312
|
|
|
187
313
|
// Most of the logic below is for handling links because in ProseMirror links are marks
|
|
188
314
|
// while in BlockNote links are a type of inline content
|
|
@@ -192,13 +318,15 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
192
318
|
if (node.type.name === "hardBreak") {
|
|
193
319
|
if (currentContent) {
|
|
194
320
|
// Current content exists.
|
|
195
|
-
if (currentContent
|
|
321
|
+
if (isStyledTextInlineContent(currentContent)) {
|
|
196
322
|
// Current content is text.
|
|
197
323
|
currentContent.text += "\n";
|
|
198
|
-
} else if (currentContent
|
|
324
|
+
} else if (isLinkInlineContent(currentContent)) {
|
|
199
325
|
// Current content is a link.
|
|
200
326
|
currentContent.content[currentContent.content.length - 1].text +=
|
|
201
327
|
"\n";
|
|
328
|
+
} else {
|
|
329
|
+
throw new Error("unexpected");
|
|
202
330
|
}
|
|
203
331
|
} else {
|
|
204
332
|
// Current content does not exist.
|
|
@@ -212,18 +340,41 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
212
340
|
return;
|
|
213
341
|
}
|
|
214
342
|
|
|
215
|
-
|
|
343
|
+
if (
|
|
344
|
+
node.type.name !== "link" &&
|
|
345
|
+
node.type.name !== "text" &&
|
|
346
|
+
inlineContentSchema[node.type.name]
|
|
347
|
+
) {
|
|
348
|
+
if (currentContent) {
|
|
349
|
+
content.push(currentContent);
|
|
350
|
+
currentContent = undefined;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
content.push(
|
|
354
|
+
nodeToCustomInlineContent(node, inlineContentSchema, styleSchema)
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const styles: Styles<S> = {};
|
|
216
361
|
let linkMark: Mark | undefined;
|
|
217
362
|
|
|
218
363
|
for (const mark of node.marks) {
|
|
219
364
|
if (mark.type.name === "link") {
|
|
220
365
|
linkMark = mark;
|
|
221
|
-
} else if (toggleStyles.has(mark.type.name as ToggledStyle)) {
|
|
222
|
-
styles[mark.type.name as ToggledStyle] = true;
|
|
223
|
-
} else if (colorStyles.has(mark.type.name as ColorStyle)) {
|
|
224
|
-
styles[mark.type.name as ColorStyle] = mark.attrs.color;
|
|
225
366
|
} else {
|
|
226
|
-
|
|
367
|
+
const config = styleSchema[mark.type.name];
|
|
368
|
+
if (!config) {
|
|
369
|
+
throw new Error(`style ${mark.type.name} not found in styleSchema`);
|
|
370
|
+
}
|
|
371
|
+
if (config.propSchema === "boolean") {
|
|
372
|
+
(styles as any)[config.type] = true;
|
|
373
|
+
} else if (config.propSchema === "string") {
|
|
374
|
+
(styles as any)[config.type] = mark.attrs.stringValue;
|
|
375
|
+
} else {
|
|
376
|
+
throw new UnreachableCaseError(config.propSchema);
|
|
377
|
+
}
|
|
227
378
|
}
|
|
228
379
|
}
|
|
229
380
|
|
|
@@ -231,7 +382,7 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
231
382
|
// Current content exists.
|
|
232
383
|
if (currentContent) {
|
|
233
384
|
// Current content is text.
|
|
234
|
-
if (currentContent
|
|
385
|
+
if (isStyledTextInlineContent(currentContent)) {
|
|
235
386
|
if (!linkMark) {
|
|
236
387
|
// Node is text (same type as current content).
|
|
237
388
|
if (
|
|
@@ -263,7 +414,7 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
263
414
|
],
|
|
264
415
|
};
|
|
265
416
|
}
|
|
266
|
-
} else if (currentContent
|
|
417
|
+
} else if (isLinkInlineContent(currentContent)) {
|
|
267
418
|
// Current content is a link.
|
|
268
419
|
if (linkMark) {
|
|
269
420
|
// Node is a link (same type as current content).
|
|
@@ -309,6 +460,8 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
309
460
|
styles,
|
|
310
461
|
};
|
|
311
462
|
}
|
|
463
|
+
} else {
|
|
464
|
+
// TODO
|
|
312
465
|
}
|
|
313
466
|
}
|
|
314
467
|
// Current content does not exist.
|
|
@@ -342,17 +495,66 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
342
495
|
content.push(currentContent);
|
|
343
496
|
}
|
|
344
497
|
|
|
345
|
-
return content;
|
|
498
|
+
return content as InlineContent<I, S>[];
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export function nodeToCustomInlineContent<
|
|
502
|
+
I extends InlineContentSchema,
|
|
503
|
+
S extends StyleSchema
|
|
504
|
+
>(node: Node, inlineContentSchema: I, styleSchema: S): InlineContent<I, S> {
|
|
505
|
+
if (node.type.name === "text" || node.type.name === "link") {
|
|
506
|
+
throw new Error("unexpected");
|
|
507
|
+
}
|
|
508
|
+
const props: any = {};
|
|
509
|
+
const icConfig = inlineContentSchema[
|
|
510
|
+
node.type.name
|
|
511
|
+
] as CustomInlineContentConfig;
|
|
512
|
+
for (const [attr, value] of Object.entries(node.attrs)) {
|
|
513
|
+
if (!icConfig) {
|
|
514
|
+
throw Error("ic node is of an unrecognized type: " + node.type.name);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const propSchema = icConfig.propSchema;
|
|
518
|
+
|
|
519
|
+
if (attr in propSchema) {
|
|
520
|
+
props[attr] = value;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
let content: CustomInlineContentFromConfig<any, any>["content"];
|
|
525
|
+
|
|
526
|
+
if (icConfig.content === "styled") {
|
|
527
|
+
content = contentNodeToInlineContent(
|
|
528
|
+
node,
|
|
529
|
+
inlineContentSchema,
|
|
530
|
+
styleSchema
|
|
531
|
+
) as any; // TODO: is this safe? could we have Links here that are undesired?
|
|
532
|
+
} else {
|
|
533
|
+
content = undefined;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const ic = {
|
|
537
|
+
type: node.type.name,
|
|
538
|
+
props,
|
|
539
|
+
content,
|
|
540
|
+
} as InlineContentFromConfig<I[keyof I], S>;
|
|
541
|
+
return ic;
|
|
346
542
|
}
|
|
347
543
|
|
|
348
544
|
/**
|
|
349
545
|
* Convert a TipTap node to a BlockNote block.
|
|
350
546
|
*/
|
|
351
|
-
export function nodeToBlock<
|
|
547
|
+
export function nodeToBlock<
|
|
548
|
+
BSchema extends BlockSchema,
|
|
549
|
+
I extends InlineContentSchema,
|
|
550
|
+
S extends StyleSchema
|
|
551
|
+
>(
|
|
352
552
|
node: Node,
|
|
353
553
|
blockSchema: BSchema,
|
|
354
|
-
|
|
355
|
-
|
|
554
|
+
inlineContentSchema: I,
|
|
555
|
+
styleSchema: S,
|
|
556
|
+
blockCache?: WeakMap<Node, Block<BSchema, I, S>>
|
|
557
|
+
): Block<BSchema, I, S> {
|
|
356
558
|
if (node.type.name !== "blockContainer") {
|
|
357
559
|
throw Error(
|
|
358
560
|
"Node must be of type blockContainer, but is of type" +
|
|
@@ -382,6 +584,7 @@ export function nodeToBlock<BSchema extends BlockSchema>(
|
|
|
382
584
|
...blockInfo.contentNode.attrs,
|
|
383
585
|
})) {
|
|
384
586
|
const blockSpec = blockSchema[blockInfo.contentType.name];
|
|
587
|
+
|
|
385
588
|
if (!blockSpec) {
|
|
386
589
|
throw Error(
|
|
387
590
|
"Block is of an unrecognized type: " + blockInfo.contentType.name
|
|
@@ -395,25 +598,48 @@ export function nodeToBlock<BSchema extends BlockSchema>(
|
|
|
395
598
|
}
|
|
396
599
|
}
|
|
397
600
|
|
|
398
|
-
const
|
|
601
|
+
const blockConfig = blockSchema[blockInfo.contentType.name];
|
|
399
602
|
|
|
400
|
-
const children: Block<BSchema>[] = [];
|
|
603
|
+
const children: Block<BSchema, I, S>[] = [];
|
|
401
604
|
for (let i = 0; i < blockInfo.numChildBlocks; i++) {
|
|
402
605
|
children.push(
|
|
403
|
-
nodeToBlock(
|
|
606
|
+
nodeToBlock(
|
|
607
|
+
node.lastChild!.child(i),
|
|
608
|
+
blockSchema,
|
|
609
|
+
inlineContentSchema,
|
|
610
|
+
styleSchema,
|
|
611
|
+
blockCache
|
|
612
|
+
)
|
|
404
613
|
);
|
|
405
614
|
}
|
|
406
615
|
|
|
407
|
-
|
|
616
|
+
let content: Block<any, any, any>["content"];
|
|
617
|
+
|
|
618
|
+
if (blockConfig.content === "inline") {
|
|
619
|
+
content = contentNodeToInlineContent(
|
|
620
|
+
blockInfo.contentNode,
|
|
621
|
+
inlineContentSchema,
|
|
622
|
+
styleSchema
|
|
623
|
+
);
|
|
624
|
+
} else if (blockConfig.content === "table") {
|
|
625
|
+
content = contentNodeToTableContent(
|
|
626
|
+
blockInfo.contentNode,
|
|
627
|
+
inlineContentSchema,
|
|
628
|
+
styleSchema
|
|
629
|
+
);
|
|
630
|
+
} else if (blockConfig.content === "none") {
|
|
631
|
+
content = undefined;
|
|
632
|
+
} else {
|
|
633
|
+
throw new UnreachableCaseError(blockConfig.content);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
const block = {
|
|
408
637
|
id,
|
|
409
|
-
type:
|
|
638
|
+
type: blockConfig.type,
|
|
410
639
|
props,
|
|
411
|
-
content
|
|
412
|
-
blockSpec.node.config.content === "inline*"
|
|
413
|
-
? contentNodeToInlineContent(blockInfo.contentNode)
|
|
414
|
-
: undefined,
|
|
640
|
+
content,
|
|
415
641
|
children,
|
|
416
|
-
} as Block<BSchema>;
|
|
642
|
+
} as Block<BSchema, I, S>;
|
|
417
643
|
|
|
418
644
|
blockCache?.set(node, block);
|
|
419
645
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "1",
|
|
4
|
+
"type": "bulletListItem",
|
|
5
|
+
"props": {
|
|
6
|
+
"textColor": "default",
|
|
7
|
+
"backgroundColor": "default",
|
|
8
|
+
"textAlignment": "left"
|
|
9
|
+
},
|
|
10
|
+
"content": [
|
|
11
|
+
{
|
|
12
|
+
"type": "text",
|
|
13
|
+
"text": "First",
|
|
14
|
+
"styles": {}
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"children": []
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": "2",
|
|
21
|
+
"type": "bulletListItem",
|
|
22
|
+
"props": {
|
|
23
|
+
"textColor": "default",
|
|
24
|
+
"backgroundColor": "default",
|
|
25
|
+
"textAlignment": "left"
|
|
26
|
+
},
|
|
27
|
+
"content": [
|
|
28
|
+
{
|
|
29
|
+
"type": "text",
|
|
30
|
+
"text": "Second",
|
|
31
|
+
"styles": {}
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"children": []
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "3",
|
|
38
|
+
"type": "bulletListItem",
|
|
39
|
+
"props": {
|
|
40
|
+
"textColor": "default",
|
|
41
|
+
"backgroundColor": "default",
|
|
42
|
+
"textAlignment": "left"
|
|
43
|
+
},
|
|
44
|
+
"content": [
|
|
45
|
+
{
|
|
46
|
+
"type": "text",
|
|
47
|
+
"text": "Third",
|
|
48
|
+
"styles": {}
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"children": []
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "4",
|
|
55
|
+
"type": "bulletListItem",
|
|
56
|
+
"props": {
|
|
57
|
+
"textColor": "default",
|
|
58
|
+
"backgroundColor": "default",
|
|
59
|
+
"textAlignment": "left"
|
|
60
|
+
},
|
|
61
|
+
"content": [
|
|
62
|
+
{
|
|
63
|
+
"type": "text",
|
|
64
|
+
"text": "Five Parent",
|
|
65
|
+
"styles": {}
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"children": [
|
|
69
|
+
{
|
|
70
|
+
"id": "5",
|
|
71
|
+
"type": "bulletListItem",
|
|
72
|
+
"props": {
|
|
73
|
+
"textColor": "default",
|
|
74
|
+
"backgroundColor": "default",
|
|
75
|
+
"textAlignment": "left"
|
|
76
|
+
},
|
|
77
|
+
"content": [
|
|
78
|
+
{
|
|
79
|
+
"type": "text",
|
|
80
|
+
"text": "Child 1",
|
|
81
|
+
"styles": {}
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"children": []
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"id": "6",
|
|
88
|
+
"type": "bulletListItem",
|
|
89
|
+
"props": {
|
|
90
|
+
"textColor": "default",
|
|
91
|
+
"backgroundColor": "default",
|
|
92
|
+
"textAlignment": "left"
|
|
93
|
+
},
|
|
94
|
+
"content": [
|
|
95
|
+
{
|
|
96
|
+
"type": "text",
|
|
97
|
+
"text": "Child 2",
|
|
98
|
+
"styles": {}
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
"children": []
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
]
|