@blocknote/core 0.9.5 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocknote.js +3699 -2600
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +7 -7
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -0
- package/package.json +8 -4
- package/src/api/README.md +8 -0
- package/src/api/blockManipulation/blockManipulation.test.ts +72 -10
- package/src/api/blockManipulation/blockManipulation.ts +38 -18
- package/src/api/exporters/copyExtension.ts +68 -0
- package/src/api/exporters/html/__snapshots__/complex/misc/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/complex/misc/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/nested/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/nested/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/styled/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/customParagraph/styled/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/fontSize/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/fontSize/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/between-links/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/between-links/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/end/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/end/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/link/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/link/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/multiple/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/multiple/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/only/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/only/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/start/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/start/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/styles/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/hardbreak/styles/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/button/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/button/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/nested/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/adjacent/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/adjacent/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/styled/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/link/styled/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/mention/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/mention/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/empty/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/empty/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/nested/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/nested/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/styled/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/paragraph/styled/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-basic-block-types.json +140 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-deep-nested-content.json +240 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-div-with-inline-content.json +91 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-divs.json +19 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-fake-image-caption.json +31 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-mixed-nested-lists.json +70 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-nested-lists-with-paragraphs.json +70 -0
- package/src/api/exporters/html/__snapshots__/paste/parse-nested-lists.json +70 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/button/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/button/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/small/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/small/basic/internal.html +1 -0
- package/src/api/exporters/html/__snapshots__/tag/basic/external.html +1 -0
- package/src/api/exporters/html/__snapshots__/tag/basic/internal.html +1 -0
- package/src/api/exporters/html/externalHTMLExporter.ts +98 -0
- package/src/api/exporters/html/htmlConversion.test.ts +100 -0
- package/src/api/exporters/html/internalHTMLSerializer.ts +80 -0
- package/src/api/exporters/html/util/sharedHTMLConversion.ts +128 -0
- package/src/api/{formatConversions → exporters/html/util}/simplifyBlocksRehypePlugin.ts +13 -0
- package/src/api/exporters/markdown/__snapshots__/complex/misc/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/customParagraph/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/customParagraph/nested/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/customParagraph/styled/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/fontSize/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/basic/markdown.md +2 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/between-links/markdown.md +2 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/end/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/link/markdown.md +2 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/multiple/markdown.md +3 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/start/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/hardbreak/styles/markdown.md +2 -0
- package/src/api/exporters/markdown/__snapshots__/image/basic/markdown.md +3 -0
- package/src/api/exporters/markdown/__snapshots__/image/button/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/image/nested/markdown.md +7 -0
- package/src/api/exporters/markdown/__snapshots__/link/adjacent/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/link/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/link/styled/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/mention/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/paragraph/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/paragraph/empty/markdown.md +0 -0
- package/src/api/exporters/markdown/__snapshots__/paragraph/nested/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/paragraph/styled/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/nested/markdown.md +5 -0
- package/src/api/exporters/markdown/__snapshots__/simpleCustomParagraph/styled/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleImage/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleImage/button/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/simpleImage/nested/markdown.md +3 -0
- package/src/api/exporters/markdown/__snapshots__/small/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/__snapshots__/tag/basic/markdown.md +1 -0
- package/src/api/exporters/markdown/markdownExporter.test.ts +85 -0
- package/src/api/exporters/markdown/markdownExporter.ts +42 -0
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +486 -125
- package/src/api/nodeConversions/nodeConversions.test.ts +67 -498
- package/src/api/nodeConversions/nodeConversions.ts +311 -98
- package/src/api/parsers/html/__snapshots__/paste/list-test.json +105 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-basic-block-types.json +140 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-deep-nested-content.json +240 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-div-with-inline-content.json +91 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-divs.json +121 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-fake-image-caption.json +31 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-google-docs-html.json +476 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-mixed-nested-lists.json +140 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-nested-lists-with-paragraphs.json +140 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-nested-lists.json +157 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-notion-html.json +470 -0
- package/src/api/parsers/html/__snapshots__/paste/parse-two-divs.json +36 -0
- package/src/api/parsers/html/parseHTML.test.ts +440 -0
- package/src/api/parsers/html/parseHTML.ts +42 -0
- package/src/api/parsers/html/util/__snapshots__/nestedLists.test.ts.snap +129 -0
- package/src/api/parsers/html/util/nestedLists.test.ts +176 -0
- package/src/api/parsers/html/util/nestedLists.ts +113 -0
- package/src/api/parsers/markdown/__snapshots__/complex.json +353 -0
- package/src/api/parsers/markdown/__snapshots__/issue-226-1.json +71 -0
- package/src/api/parsers/markdown/__snapshots__/issue-226-2.json +144 -0
- package/src/api/parsers/markdown/__snapshots__/nested.json +72 -0
- package/src/api/parsers/markdown/__snapshots__/non-nested.json +71 -0
- package/src/api/parsers/markdown/__snapshots__/styled.json +58 -0
- package/src/api/parsers/markdown/parseMarkdown.test.ts +114 -0
- package/src/api/parsers/markdown/parseMarkdown.ts +84 -0
- package/src/api/parsers/pasteExtension.ts +59 -0
- package/src/api/testUtil/cases/customBlocks.ts +282 -0
- package/src/api/testUtil/cases/customInlineContent.ts +114 -0
- package/src/api/testUtil/cases/customStyles.ts +100 -0
- package/src/api/testUtil/cases/defaultSchema.ts +399 -0
- package/src/api/testUtil/index.ts +17 -0
- package/src/api/testUtil/partialBlockTestUtil.ts +127 -0
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +136 -0
- package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/ImageBlockContent.ts +117 -31
- package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +34 -47
- package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
- package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
- package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +34 -56
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +43 -0
- package/src/blocks/README.md +3 -0
- package/src/blocks/TableBlockContent/TableBlockContent.ts +74 -0
- package/src/blocks/TableBlockContent/TableExtension.ts +63 -0
- package/src/blocks/defaultBlockHelpers.ts +95 -0
- package/src/blocks/defaultBlocks.ts +60 -0
- package/src/blocks/defaultProps.ts +24 -0
- package/src/{extensions/Blocks/nodes/Block.module.css → editor/Block.css} +70 -66
- package/src/{BlockNoteEditor.test.ts → editor/BlockNoteEditor.test.ts} +2 -2
- package/src/{BlockNoteEditor.ts → editor/BlockNoteEditor.ts} +382 -159
- package/src/{BlockNoteExtensions.ts → editor/BlockNoteExtensions.ts} +59 -40
- package/src/editor/README.md +3 -0
- package/src/editor/cursorPositionTypes.ts +16 -0
- package/src/{editor.module.css → editor/editor.css} +42 -15
- package/src/editor/selectionTypes.ts +14 -0
- package/src/editor/transformPasted.ts +58 -0
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +1 -36
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +12 -27
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +16 -24
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +12 -10
- package/src/extensions/ImageToolbar/ImageToolbarPlugin.ts +35 -73
- package/src/extensions/Placeholder/PlaceholderExtension.ts +4 -4
- package/src/extensions/README.md +3 -0
- package/src/extensions/SideMenu/SideMenuPlugin.ts +77 -37
- package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +7 -6
- package/src/extensions/SlashMenu/SlashMenuPlugin.ts +9 -7
- package/src/extensions/SlashMenu/defaultSlashMenuItems.ts +98 -35
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +617 -0
- package/src/extensions/TextAlignment/TextAlignmentExtension.ts +3 -51
- package/src/extensions/TextColor/TextColorExtension.ts +1 -29
- package/src/extensions/TextColor/TextColorMark.ts +7 -27
- package/src/extensions/UniqueID/UniqueID.ts +28 -2
- package/src/extensions-shared/README.md +3 -0
- package/src/{shared/plugins → extensions-shared}/suggestion/SuggestionPlugin.ts +19 -13
- package/src/index.ts +21 -15
- package/src/{extensions/Blocks/nodes → pm-nodes}/BlockContainer.ts +161 -96
- package/src/pm-nodes/BlockGroup.ts +54 -0
- package/src/pm-nodes/Doc.ts +7 -0
- package/src/pm-nodes/README.md +42 -0
- package/src/pm-nodes/index.ts +3 -0
- package/src/schema/README.md +3 -0
- package/src/schema/blocks/createSpec.ts +220 -0
- package/src/schema/blocks/internal.ts +253 -0
- package/src/schema/blocks/types.ts +252 -0
- package/src/schema/index.ts +10 -0
- package/src/schema/inlineContent/createSpec.ts +119 -0
- package/src/schema/inlineContent/internal.ts +105 -0
- package/src/schema/inlineContent/types.ts +144 -0
- package/src/schema/propTypes.ts +32 -0
- package/src/schema/styles/createSpec.ts +85 -0
- package/src/schema/styles/internal.ts +96 -0
- package/src/schema/styles/types.ts +42 -0
- package/src/util/README.md +3 -0
- package/src/{shared/utils.ts → util/browser.ts} +4 -8
- package/src/util/string.ts +3 -0
- package/src/util/typescript.ts +5 -0
- package/types/src/BlockNoteEditor.d.ts +51 -37
- package/types/src/BlockNoteExtensions.d.ts +8 -3
- package/types/src/api/blockManipulation/blockManipulation.d.ts +5 -4
- package/types/src/api/exporters/copyExtension.d.ts +6 -0
- package/types/src/api/exporters/html/externalHTMLExporter.d.ts +8 -0
- package/types/src/api/exporters/html/internalHTMLSerializer.d.ts +8 -0
- package/types/src/api/exporters/html/util/sharedHTMLConversion.d.ts +7 -0
- package/types/src/api/exporters/markdown/markdownExporter.d.ts +5 -0
- package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +1 -0
- package/types/src/api/getBlockInfoFromPos.d.ts +27 -0
- package/types/src/api/nodeConversions/nodeConversions.d.ts +14 -6
- package/types/src/api/nodeConversions/testUtil.d.ts +7 -2
- package/types/src/api/nodeUtil.d.ts +8 -0
- package/types/src/api/parsers/html/parseHTML.d.ts +3 -0
- package/types/src/api/parsers/html/parseHTML.test.d.ts +1 -0
- package/types/src/api/parsers/html/util/nestedLists.d.ts +1 -0
- package/types/src/api/parsers/html/util/nestedLists.test.d.ts +1 -0
- package/types/src/api/parsers/markdown/parseMarkdown.d.ts +3 -0
- package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +1 -0
- package/types/src/api/parsers/pasteExtension.d.ts +6 -0
- package/types/src/api/testCases/cases/customBlocks.d.ts +345 -0
- package/types/src/api/testCases/cases/customInlineContent.d.ts +29 -0
- package/types/src/api/testCases/cases/customStyles.d.ts +64 -0
- package/types/src/api/testCases/cases/defaultSchema.d.ts +3 -0
- package/types/src/api/testCases/index.d.ts +12 -0
- package/types/src/api/testUtil/cases/customBlocks.d.ts +345 -0
- package/types/src/api/testUtil/cases/customInlineContent.d.ts +29 -0
- package/types/src/api/testUtil/cases/customStyles.d.ts +64 -0
- package/types/src/api/testUtil/cases/defaultSchema.d.ts +3 -0
- package/types/src/api/testUtil/index.d.ts +12 -0
- package/types/src/api/testUtil/partialBlockTestUtil.d.ts +7 -0
- package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +58 -0
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +93 -0
- package/types/src/blocks/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +1 -0
- package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +46 -0
- package/types/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +2 -0
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +2 -0
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +46 -0
- package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +52 -0
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +53 -0
- package/types/src/blocks/TableBlockContent/TableExtension.d.ts +2 -0
- package/types/src/blocks/defaultBlockHelpers.d.ts +10 -0
- package/types/src/blocks/defaultBlocks.d.ts +577 -0
- package/types/src/blocks/defaultProps.d.ts +15 -0
- package/types/src/editor/BlockNoteEditor.d.ts +299 -0
- package/types/src/editor/BlockNoteEditor.test.d.ts +1 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +24 -0
- package/types/src/editor/cursorPositionTypes.d.ts +6 -0
- package/types/src/editor/selectionTypes.d.ts +4 -0
- package/types/src/editor/transformPasted.d.ts +12 -0
- package/types/src/extensions/BackgroundColor/BackgroundColorExtension.d.ts +0 -7
- package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +7 -9
- package/types/src/extensions/Blocks/api/blocks/createSpec.d.ts +35 -0
- package/types/src/extensions/Blocks/api/blocks/internal.d.ts +45 -0
- package/types/src/extensions/Blocks/api/blocks/types.d.ts +114 -0
- package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +7 -5
- package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +573 -113
- package/types/src/extensions/Blocks/api/defaultProps.d.ts +2 -1
- package/types/src/extensions/Blocks/api/inlineContent/createSpec.d.ts +21 -0
- package/types/src/extensions/Blocks/api/inlineContent/internal.d.ts +25 -0
- package/types/src/extensions/Blocks/api/inlineContent/types.d.ts +62 -0
- package/types/src/extensions/Blocks/api/selectionTypes.d.ts +5 -3
- package/types/src/extensions/Blocks/api/styles/createSpec.d.ts +13 -0
- package/types/src/extensions/Blocks/api/styles/internal.d.ts +22 -0
- package/types/src/extensions/Blocks/api/styles/types.d.ts +21 -0
- package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +8 -4
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +38 -23
- package/types/src/extensions/Blocks/nodes/BlockContent/ImageBlockContent/ImageBlockContent.d.ts +75 -17
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +30 -19
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +30 -19
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +36 -28
- package/types/src/extensions/Blocks/nodes/BlockContent/TableBlockContent/TableBlockContent.d.ts +53 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/TableBlockContent/TableExtension.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContent/defaultBlockHelpers.d.ts +12 -0
- package/types/src/extensions/Blocks/nodes/BlockGroup.d.ts +1 -1
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +8 -6
- package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +6 -6
- package/types/src/extensions/ImageToolbar/ImageToolbarPlugin.d.ts +11 -16
- package/types/src/extensions/NonEditableBlocks/NonEditableBlockPlugin.d.ts +2 -0
- package/types/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.d.ts +14 -0
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +19 -11
- package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +5 -6
- package/types/src/extensions/SlashMenu/SlashMenuPlugin.d.ts +6 -6
- package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +2 -1
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +74 -0
- package/types/src/extensions/TextAlignment/TextAlignmentExtension.d.ts +0 -7
- package/types/src/extensions/TextColor/TextColorExtension.d.ts +0 -7
- package/types/src/extensions/TextColor/TextColorMark.d.ts +7 -9
- package/types/src/extensions/UniqueID/UniqueID.d.ts +1 -1
- package/types/src/extensions-shared/BaseUiElementTypes.d.ts +7 -0
- package/types/src/extensions-shared/suggestion/SuggestionItem.d.ts +3 -0
- package/types/src/extensions-shared/suggestion/SuggestionPlugin.d.ts +36 -0
- package/types/src/index.d.ts +20 -15
- package/types/src/pm-nodes/BlockContainer.d.ts +28 -0
- package/types/src/pm-nodes/BlockGroup.d.ts +10 -0
- package/types/src/pm-nodes/Doc.d.ts +2 -0
- package/types/src/pm-nodes/index.d.ts +3 -0
- package/types/src/schema/blocks/createSpec.d.ts +35 -0
- package/types/src/schema/blocks/internal.d.ts +45 -0
- package/types/src/schema/blocks/types.d.ts +107 -0
- package/types/src/schema/index.d.ts +10 -0
- package/types/src/schema/inlineContent/createSpec.d.ts +21 -0
- package/types/src/schema/inlineContent/internal.d.ts +28 -0
- package/types/src/schema/inlineContent/types.d.ts +62 -0
- package/types/src/schema/propTypes.d.ts +8 -0
- package/types/src/schema/styles/createSpec.d.ts +13 -0
- package/types/src/schema/styles/internal.d.ts +22 -0
- package/types/src/schema/styles/types.d.ts +21 -0
- package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +4 -2
- package/types/src/util/EventEmitter.d.ts +11 -0
- package/types/src/util/browser.d.ts +3 -0
- package/types/src/util/string.d.ts +1 -0
- package/types/src/util/typescript.d.ts +3 -0
- package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +0 -346
- package/src/api/formatConversions/formatConversions.test.ts +0 -753
- package/src/api/formatConversions/formatConversions.ts +0 -133
- package/src/api/nodeConversions/testUtil.ts +0 -65
- package/src/extensions/Blocks/api/block.ts +0 -307
- package/src/extensions/Blocks/api/blockTypes.ts +0 -249
- package/src/extensions/Blocks/api/cursorPositionTypes.ts +0 -7
- package/src/extensions/Blocks/api/defaultBlocks.ts +0 -16
- package/src/extensions/Blocks/api/defaultProps.ts +0 -16
- package/src/extensions/Blocks/api/inlineContentTypes.ts +0 -36
- package/src/extensions/Blocks/api/selectionTypes.ts +0 -5
- package/src/extensions/Blocks/api/serialization.ts +0 -29
- package/src/extensions/Blocks/helpers/findBlock.ts +0 -5
- package/src/extensions/Blocks/index.ts +0 -8
- package/src/extensions/Blocks/nodes/BlockAttributes.ts +0 -10
- package/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.ts +0 -142
- package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +0 -62
- package/src/extensions/Blocks/nodes/BlockGroup.ts +0 -53
- package/types/src/api/formatConversions/formatConversions.d.ts +0 -6
- package/types/src/extensions/Blocks/api/block.d.ts +0 -20
- package/types/src/extensions/Blocks/api/blockTypes.d.ts +0 -103
- package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +0 -30
- package/types/src/extensions/Blocks/api/serialization.d.ts +0 -2
- /package/src/{shared/EditorElement.ts → api/exporters/markdown/__snapshots__/hardbreak/only/markdown.md} +0 -0
- /package/src/api/{formatConversions → exporters/markdown}/removeUnderlinesRehypePlugin.ts +0 -0
- /package/src/{extensions/Blocks/helpers → api}/getBlockInfoFromPos.ts +0 -0
- /package/src/api/{util/nodeUtil.ts → nodeUtil.ts} +0 -0
- /package/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
- /package/src/extensions/{Blocks → NonEditableBlocks}/NonEditableBlockPlugin.ts +0 -0
- /package/src/extensions/{Blocks → PreviousBlockType}/PreviousBlockTypePlugin.ts +0 -0
- /package/src/{shared → extensions-shared}/BaseUiElementTypes.ts +0 -0
- /package/src/{shared/plugins → extensions-shared}/suggestion/SuggestionItem.ts +0 -0
- /package/src/{shared → util}/EventEmitter.ts +0 -0
- /package/types/src/api/{formatConversions/formatConversions.test.d.ts → exporters/html/htmlConversion.test.d.ts} +0 -0
- /package/types/src/api/{formatConversions → exporters/html/util}/simplifyBlocksRehypePlugin.d.ts +0 -0
- /package/types/src/api/{formatConversions → exporters/markdown}/removeUnderlinesRehypePlugin.d.ts +0 -0
|
@@ -1,45 +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 { defaultProps } from "../../extensions/Blocks/api/defaultProps";
|
|
9
|
-
import {
|
|
10
|
-
ColorStyle,
|
|
7
|
+
CustomInlineContentConfig,
|
|
8
|
+
CustomInlineContentFromConfig,
|
|
11
9
|
InlineContent,
|
|
10
|
+
InlineContentFromConfig,
|
|
11
|
+
InlineContentSchema,
|
|
12
|
+
PartialBlock,
|
|
13
|
+
PartialCustomInlineContentFromConfig,
|
|
12
14
|
PartialInlineContent,
|
|
13
15
|
PartialLink,
|
|
16
|
+
PartialTableContent,
|
|
17
|
+
StyleSchema,
|
|
14
18
|
StyledText,
|
|
15
19
|
Styles,
|
|
16
|
-
|
|
17
|
-
} from "../../
|
|
18
|
-
import { getBlockInfo } from "
|
|
19
|
-
import UniqueID from "../../extensions/UniqueID/UniqueID";
|
|
20
|
-
import { UnreachableCaseError } from "../../shared/utils";
|
|
20
|
+
TableContent,
|
|
21
|
+
} from "../../schema";
|
|
22
|
+
import { getBlockInfo } from "../getBlockInfoFromPos";
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]);
|
|
29
|
-
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";
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Convert a StyledText inline element to a
|
|
33
33
|
* prosemirror text node with the appropriate marks
|
|
34
34
|
*/
|
|
35
|
-
function styledTextToNodes
|
|
35
|
+
function styledTextToNodes<T extends StyleSchema>(
|
|
36
|
+
styledText: StyledText<T>,
|
|
37
|
+
schema: Schema,
|
|
38
|
+
styleSchema: T
|
|
39
|
+
): Node[] {
|
|
36
40
|
const marks: Mark[] = [];
|
|
37
41
|
|
|
38
42
|
for (const [style, value] of Object.entries(styledText.styles)) {
|
|
39
|
-
|
|
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") {
|
|
40
49
|
marks.push(schema.mark(style));
|
|
41
|
-
} else if (
|
|
42
|
-
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);
|
|
43
54
|
}
|
|
44
55
|
}
|
|
45
56
|
|
|
@@ -65,42 +76,53 @@ function styledTextToNodes(styledText: StyledText, schema: Schema): Node[] {
|
|
|
65
76
|
* Converts a Link inline content element to
|
|
66
77
|
* prosemirror text nodes with the appropriate marks
|
|
67
78
|
*/
|
|
68
|
-
function linkToNodes(
|
|
79
|
+
function linkToNodes(
|
|
80
|
+
link: PartialLink<StyleSchema>,
|
|
81
|
+
schema: Schema,
|
|
82
|
+
styleSchema: StyleSchema
|
|
83
|
+
): Node[] {
|
|
69
84
|
const linkMark = schema.marks.link.create({
|
|
70
85
|
href: link.href,
|
|
71
86
|
});
|
|
72
87
|
|
|
73
|
-
return styledTextArrayToNodes(link.content, schema).map(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
88
|
+
return styledTextArrayToNodes(link.content, schema, styleSchema).map(
|
|
89
|
+
(node) => {
|
|
90
|
+
if (node.type.name === "text") {
|
|
91
|
+
return node.mark([...node.marks, linkMark]);
|
|
92
|
+
}
|
|
77
93
|
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
if (node.type.name === "hardBreak") {
|
|
95
|
+
return node;
|
|
96
|
+
}
|
|
97
|
+
throw new Error("unexpected node type");
|
|
80
98
|
}
|
|
81
|
-
|
|
82
|
-
});
|
|
99
|
+
);
|
|
83
100
|
}
|
|
84
101
|
|
|
85
102
|
/**
|
|
86
103
|
* Converts an array of StyledText inline content elements to
|
|
87
104
|
* prosemirror text nodes with the appropriate marks
|
|
88
105
|
*/
|
|
89
|
-
function styledTextArrayToNodes(
|
|
90
|
-
content: string | StyledText[],
|
|
91
|
-
schema: Schema
|
|
106
|
+
function styledTextArrayToNodes<S extends StyleSchema>(
|
|
107
|
+
content: string | StyledText<S>[],
|
|
108
|
+
schema: Schema,
|
|
109
|
+
styleSchema: S
|
|
92
110
|
): Node[] {
|
|
93
111
|
const nodes: Node[] = [];
|
|
94
112
|
|
|
95
113
|
if (typeof content === "string") {
|
|
96
114
|
nodes.push(
|
|
97
|
-
...styledTextToNodes(
|
|
115
|
+
...styledTextToNodes(
|
|
116
|
+
{ type: "text", text: content, styles: {} },
|
|
117
|
+
schema,
|
|
118
|
+
styleSchema
|
|
119
|
+
)
|
|
98
120
|
);
|
|
99
121
|
return nodes;
|
|
100
122
|
}
|
|
101
123
|
|
|
102
124
|
for (const styledText of content) {
|
|
103
|
-
nodes.push(...styledTextToNodes(styledText, schema));
|
|
125
|
+
nodes.push(...styledTextToNodes(styledText, schema, styleSchema));
|
|
104
126
|
}
|
|
105
127
|
return nodes;
|
|
106
128
|
}
|
|
@@ -108,44 +130,85 @@ function styledTextArrayToNodes(
|
|
|
108
130
|
/**
|
|
109
131
|
* converts an array of inline content elements to prosemirror nodes
|
|
110
132
|
*/
|
|
111
|
-
export function inlineContentToNodes
|
|
112
|
-
|
|
113
|
-
|
|
133
|
+
export function inlineContentToNodes<
|
|
134
|
+
I extends InlineContentSchema,
|
|
135
|
+
S extends StyleSchema
|
|
136
|
+
>(
|
|
137
|
+
blockContent: PartialInlineContent<I, S>,
|
|
138
|
+
schema: Schema,
|
|
139
|
+
styleSchema: S
|
|
114
140
|
): Node[] {
|
|
115
141
|
const nodes: Node[] = [];
|
|
116
142
|
|
|
117
143
|
for (const content of blockContent) {
|
|
118
|
-
if (content
|
|
119
|
-
nodes.push(...
|
|
120
|
-
} else if (content
|
|
121
|
-
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));
|
|
122
150
|
} else {
|
|
123
|
-
|
|
151
|
+
nodes.push(
|
|
152
|
+
blockOrInlineContentToContentNode(content, schema, styleSchema)
|
|
153
|
+
);
|
|
124
154
|
}
|
|
125
155
|
}
|
|
126
156
|
return nodes;
|
|
127
157
|
}
|
|
128
158
|
|
|
129
159
|
/**
|
|
130
|
-
*
|
|
160
|
+
* converts an array of inline content elements to prosemirror nodes
|
|
131
161
|
*/
|
|
132
|
-
export function
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
+
}
|
|
137
184
|
|
|
138
|
-
|
|
139
|
-
|
|
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);
|
|
140
190
|
}
|
|
191
|
+
return rowNodes;
|
|
192
|
+
}
|
|
141
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;
|
|
142
202
|
let type = block.type;
|
|
143
203
|
|
|
204
|
+
// TODO: needed? came from previous code
|
|
144
205
|
if (type === undefined) {
|
|
145
206
|
type = "paragraph";
|
|
146
207
|
}
|
|
147
208
|
|
|
148
|
-
|
|
209
|
+
if (!schema.nodes[type]) {
|
|
210
|
+
throw new Error(`node type ${type} not found in schema`);
|
|
211
|
+
}
|
|
149
212
|
|
|
150
213
|
if (!block.content) {
|
|
151
214
|
contentNode = schema.nodes[type].create(block.props);
|
|
@@ -154,16 +217,42 @@ export function blockToNode<BSchema extends BlockSchema>(
|
|
|
154
217
|
block.props,
|
|
155
218
|
schema.text(block.content)
|
|
156
219
|
);
|
|
157
|
-
} else {
|
|
158
|
-
const nodes = inlineContentToNodes(block.content, schema);
|
|
220
|
+
} else if (Array.isArray(block.content)) {
|
|
221
|
+
const nodes = inlineContentToNodes(block.content, schema, styleSchema);
|
|
159
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();
|
|
160
243
|
}
|
|
161
244
|
|
|
245
|
+
const contentNode = blockOrInlineContentToContentNode(
|
|
246
|
+
block,
|
|
247
|
+
schema,
|
|
248
|
+
styleSchema
|
|
249
|
+
);
|
|
250
|
+
|
|
162
251
|
const children: Node[] = [];
|
|
163
252
|
|
|
164
253
|
if (block.children) {
|
|
165
254
|
for (const child of block.children) {
|
|
166
|
-
children.push(blockToNode(child, schema));
|
|
255
|
+
children.push(blockToNode(child, schema, styleSchema));
|
|
167
256
|
}
|
|
168
257
|
}
|
|
169
258
|
|
|
@@ -178,12 +267,48 @@ export function blockToNode<BSchema extends BlockSchema>(
|
|
|
178
267
|
);
|
|
179
268
|
}
|
|
180
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
|
+
|
|
181
303
|
/**
|
|
182
304
|
* Converts an internal (prosemirror) content node to a BlockNote InlineContent array.
|
|
183
305
|
*/
|
|
184
|
-
function contentNodeToInlineContent
|
|
185
|
-
|
|
186
|
-
|
|
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;
|
|
187
312
|
|
|
188
313
|
// Most of the logic below is for handling links because in ProseMirror links are marks
|
|
189
314
|
// while in BlockNote links are a type of inline content
|
|
@@ -193,13 +318,15 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
193
318
|
if (node.type.name === "hardBreak") {
|
|
194
319
|
if (currentContent) {
|
|
195
320
|
// Current content exists.
|
|
196
|
-
if (currentContent
|
|
321
|
+
if (isStyledTextInlineContent(currentContent)) {
|
|
197
322
|
// Current content is text.
|
|
198
323
|
currentContent.text += "\n";
|
|
199
|
-
} else if (currentContent
|
|
324
|
+
} else if (isLinkInlineContent(currentContent)) {
|
|
200
325
|
// Current content is a link.
|
|
201
326
|
currentContent.content[currentContent.content.length - 1].text +=
|
|
202
327
|
"\n";
|
|
328
|
+
} else {
|
|
329
|
+
throw new Error("unexpected");
|
|
203
330
|
}
|
|
204
331
|
} else {
|
|
205
332
|
// Current content does not exist.
|
|
@@ -213,18 +340,41 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
213
340
|
return;
|
|
214
341
|
}
|
|
215
342
|
|
|
216
|
-
|
|
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> = {};
|
|
217
361
|
let linkMark: Mark | undefined;
|
|
218
362
|
|
|
219
363
|
for (const mark of node.marks) {
|
|
220
364
|
if (mark.type.name === "link") {
|
|
221
365
|
linkMark = mark;
|
|
222
|
-
} else if (toggleStyles.has(mark.type.name as ToggledStyle)) {
|
|
223
|
-
styles[mark.type.name as ToggledStyle] = true;
|
|
224
|
-
} else if (colorStyles.has(mark.type.name as ColorStyle)) {
|
|
225
|
-
styles[mark.type.name as ColorStyle] = mark.attrs.color;
|
|
226
366
|
} else {
|
|
227
|
-
|
|
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
|
+
}
|
|
228
378
|
}
|
|
229
379
|
}
|
|
230
380
|
|
|
@@ -232,7 +382,7 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
232
382
|
// Current content exists.
|
|
233
383
|
if (currentContent) {
|
|
234
384
|
// Current content is text.
|
|
235
|
-
if (currentContent
|
|
385
|
+
if (isStyledTextInlineContent(currentContent)) {
|
|
236
386
|
if (!linkMark) {
|
|
237
387
|
// Node is text (same type as current content).
|
|
238
388
|
if (
|
|
@@ -264,7 +414,7 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
264
414
|
],
|
|
265
415
|
};
|
|
266
416
|
}
|
|
267
|
-
} else if (currentContent
|
|
417
|
+
} else if (isLinkInlineContent(currentContent)) {
|
|
268
418
|
// Current content is a link.
|
|
269
419
|
if (linkMark) {
|
|
270
420
|
// Node is a link (same type as current content).
|
|
@@ -310,6 +460,8 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
310
460
|
styles,
|
|
311
461
|
};
|
|
312
462
|
}
|
|
463
|
+
} else {
|
|
464
|
+
// TODO
|
|
313
465
|
}
|
|
314
466
|
}
|
|
315
467
|
// Current content does not exist.
|
|
@@ -343,17 +495,66 @@ function contentNodeToInlineContent(contentNode: Node) {
|
|
|
343
495
|
content.push(currentContent);
|
|
344
496
|
}
|
|
345
497
|
|
|
346
|
-
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;
|
|
347
542
|
}
|
|
348
543
|
|
|
349
544
|
/**
|
|
350
545
|
* Convert a TipTap node to a BlockNote block.
|
|
351
546
|
*/
|
|
352
|
-
export function nodeToBlock<
|
|
547
|
+
export function nodeToBlock<
|
|
548
|
+
BSchema extends BlockSchema,
|
|
549
|
+
I extends InlineContentSchema,
|
|
550
|
+
S extends StyleSchema
|
|
551
|
+
>(
|
|
353
552
|
node: Node,
|
|
354
553
|
blockSchema: BSchema,
|
|
355
|
-
|
|
356
|
-
|
|
554
|
+
inlineContentSchema: I,
|
|
555
|
+
styleSchema: S,
|
|
556
|
+
blockCache?: WeakMap<Node, Block<BSchema, I, S>>
|
|
557
|
+
): Block<BSchema, I, S> {
|
|
357
558
|
if (node.type.name !== "blockContainer") {
|
|
358
559
|
throw Error(
|
|
359
560
|
"Node must be of type blockContainer, but is of type" +
|
|
@@ -383,6 +584,7 @@ export function nodeToBlock<BSchema extends BlockSchema>(
|
|
|
383
584
|
...blockInfo.contentNode.attrs,
|
|
384
585
|
})) {
|
|
385
586
|
const blockSpec = blockSchema[blockInfo.contentType.name];
|
|
587
|
+
|
|
386
588
|
if (!blockSpec) {
|
|
387
589
|
throw Error(
|
|
388
590
|
"Block is of an unrecognized type: " + blockInfo.contentType.name
|
|
@@ -394,39 +596,50 @@ export function nodeToBlock<BSchema extends BlockSchema>(
|
|
|
394
596
|
if (attr in propSchema) {
|
|
395
597
|
props[attr] = value;
|
|
396
598
|
}
|
|
397
|
-
// Block ids are stored as node attributes the same way props are, so we
|
|
398
|
-
// need to ensure we don't attempt to read block ids as props.
|
|
399
|
-
|
|
400
|
-
// the second check is for the backgroundColor & textColor props.
|
|
401
|
-
// Since we want them to be inherited by child blocks, we can't put them on the blockContent node,
|
|
402
|
-
// and instead have to put them on the blockContainer node.
|
|
403
|
-
// The blockContainer node is the same for all block types, but some custom blocks might not use backgroundColor & textColor,
|
|
404
|
-
// so these 2 props are technically unexpected but we shouldn't log a warning.
|
|
405
|
-
// (this is a bit hacky)
|
|
406
|
-
else if (attr !== "id" && !(attr in defaultProps)) {
|
|
407
|
-
console.warn("Block has an unrecognized attribute: " + attr);
|
|
408
|
-
}
|
|
409
599
|
}
|
|
410
600
|
|
|
411
|
-
const
|
|
601
|
+
const blockConfig = blockSchema[blockInfo.contentType.name];
|
|
412
602
|
|
|
413
|
-
const children: Block<BSchema>[] = [];
|
|
603
|
+
const children: Block<BSchema, I, S>[] = [];
|
|
414
604
|
for (let i = 0; i < blockInfo.numChildBlocks; i++) {
|
|
415
605
|
children.push(
|
|
416
|
-
nodeToBlock(
|
|
606
|
+
nodeToBlock(
|
|
607
|
+
node.lastChild!.child(i),
|
|
608
|
+
blockSchema,
|
|
609
|
+
inlineContentSchema,
|
|
610
|
+
styleSchema,
|
|
611
|
+
blockCache
|
|
612
|
+
)
|
|
417
613
|
);
|
|
418
614
|
}
|
|
419
615
|
|
|
420
|
-
|
|
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 = {
|
|
421
637
|
id,
|
|
422
|
-
type:
|
|
638
|
+
type: blockConfig.type,
|
|
423
639
|
props,
|
|
424
|
-
content
|
|
425
|
-
blockSpec.node.config.content === "inline*"
|
|
426
|
-
? contentNodeToInlineContent(blockInfo.contentNode)
|
|
427
|
-
: undefined,
|
|
640
|
+
content,
|
|
428
641
|
children,
|
|
429
|
-
} as Block<BSchema>;
|
|
642
|
+
} as Block<BSchema, I, S>;
|
|
430
643
|
|
|
431
644
|
blockCache?.set(node, block);
|
|
432
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
|
+
]
|