@blocknote/core 0.9.6 → 0.10.1
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 +3696 -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 +11 -5
- 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/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} +363 -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} +43 -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/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/nodeConversions/nodeConversions.d.ts +14 -6
- 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/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/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +46 -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/{extensions/Blocks/api → blocks}/defaultProps.d.ts +2 -1
- package/types/src/{BlockNoteEditor.d.ts → editor/BlockNoteEditor.d.ts} +54 -43
- package/types/src/editor/BlockNoteEditor.test.d.ts +1 -0
- package/types/src/{BlockNoteExtensions.d.ts → editor/BlockNoteExtensions.d.ts} +7 -4
- 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/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/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/{shared/plugins → extensions-shared}/suggestion/SuggestionPlugin.d.ts +5 -4
- package/types/src/index.d.ts +20 -15
- package/types/src/{extensions/Blocks/nodes → pm-nodes}/BlockContainer.d.ts +5 -3
- 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/utils.d.ts → util/browser.d.ts} +0 -3
- 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/api/nodeConversions/testUtil.d.ts +0 -2
- 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/cursorPositionTypes.d.ts +0 -6
- package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +0 -117
- package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +0 -30
- package/types/src/extensions/Blocks/api/selectionTypes.d.ts +0 -4
- package/types/src/extensions/Blocks/api/serialization.d.ts +0 -2
- package/types/src/extensions/Blocks/helpers/findBlock.d.ts +0 -6
- package/types/src/extensions/Blocks/index.d.ts +0 -4
- package/types/src/extensions/Blocks/nodes/BlockAttributes.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +0 -43
- package/types/src/extensions/Blocks/nodes/BlockContent/ImageBlockContent/ImageBlockContent.d.ts +0 -37
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -35
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -35
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -44
- /package/src/{shared/EditorElement.ts → api/exporters/markdown/__snapshots__/hardbreak/only/markdown.md} +0 -0
- /package/{types/src/shared/EditorElement.d.ts → src/api/exporters/markdown/__snapshots__/paragraph/empty/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/{BlockNoteEditor.test.d.ts → api/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/formatConversions.test.d.ts → exporters/markdown/markdownExporter.test.d.ts} +0 -0
- /package/types/src/api/{formatConversions → exporters/markdown}/removeUnderlinesRehypePlugin.d.ts +0 -0
- /package/types/src/{extensions/Blocks/helpers → api}/getBlockInfoFromPos.d.ts +0 -0
- /package/types/src/api/{util/nodeUtil.d.ts → nodeUtil.d.ts} +0 -0
- /package/types/src/{extensions/Blocks/nodes/BlockContent → blocks}/ImageBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
- /package/types/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/ListItemKeyboardShortcuts.d.ts +0 -0
- /package/types/src/{extensions/Blocks/nodes/BlockContent → blocks}/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -0
- /package/types/src/extensions/{Blocks → NonEditableBlocks}/NonEditableBlockPlugin.d.ts +0 -0
- /package/types/src/extensions/{Blocks → PreviousBlockType}/PreviousBlockTypePlugin.d.ts +0 -0
- /package/types/src/{shared → extensions-shared}/BaseUiElementTypes.d.ts +0 -0
- /package/types/src/{shared/plugins → extensions-shared}/suggestion/SuggestionItem.d.ts +0 -0
- /package/types/src/{extensions/Blocks/nodes → pm-nodes}/BlockGroup.d.ts +0 -0
- /package/types/src/{shared → util}/EventEmitter.d.ts +0 -0
|
@@ -1,501 +1,70 @@
|
|
|
1
|
-
import { Editor } from "@tiptap/core";
|
|
2
1
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
|
-
import { BlockNoteEditor, PartialBlock } from "../..";
|
|
4
|
-
import {
|
|
5
|
-
DefaultBlockSchema,
|
|
6
|
-
defaultBlockSchema,
|
|
7
|
-
} from "../../extensions/Blocks/api/defaultBlocks";
|
|
8
|
-
import UniqueID from "../../extensions/UniqueID/UniqueID";
|
|
9
|
-
import { blockToNode, nodeToBlock } from "./nodeConversions";
|
|
10
|
-
import { partialBlockToBlockForTesting } from "./testUtil";
|
|
11
|
-
|
|
12
|
-
let editor: BlockNoteEditor;
|
|
13
|
-
let tt: Editor;
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
(window as Window & { __TEST_OPTIONS?: any }).__TEST_OPTIONS = {};
|
|
17
|
-
|
|
18
|
-
editor = new BlockNoteEditor();
|
|
19
|
-
tt = editor._tiptapEditor;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterEach(() => {
|
|
23
|
-
tt.destroy();
|
|
24
|
-
editor = undefined as any;
|
|
25
|
-
tt = undefined as any;
|
|
26
|
-
|
|
27
|
-
delete (window as Window & { __TEST_OPTIONS?: any }).__TEST_OPTIONS;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe("Simple ProseMirror Node Conversions", () => {
|
|
31
|
-
it("Convert simple block to node", async () => {
|
|
32
|
-
const block: PartialBlock = {
|
|
33
|
-
type: "paragraph",
|
|
34
|
-
};
|
|
35
|
-
const firstNodeConversion = blockToNode(block, tt.schema);
|
|
36
|
-
|
|
37
|
-
expect(firstNodeConversion).toMatchSnapshot();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("Convert simple node to block", async () => {
|
|
41
|
-
const node = tt.schema.nodes["blockContainer"].create(
|
|
42
|
-
{ id: UniqueID.options.generateID() },
|
|
43
|
-
tt.schema.nodes["paragraph"].create()
|
|
44
|
-
);
|
|
45
|
-
const firstBlockConversion = nodeToBlock<DefaultBlockSchema>(
|
|
46
|
-
node,
|
|
47
|
-
defaultBlockSchema
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
expect(firstBlockConversion).toMatchSnapshot();
|
|
51
|
-
|
|
52
|
-
const firstNodeConversion = blockToNode<DefaultBlockSchema>(
|
|
53
|
-
firstBlockConversion,
|
|
54
|
-
tt.schema
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
expect(firstNodeConversion).toStrictEqual(node);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe("Complex ProseMirror Node Conversions", () => {
|
|
62
|
-
it("Convert complex block to node", async () => {
|
|
63
|
-
const block: PartialBlock = {
|
|
64
|
-
type: "heading",
|
|
65
|
-
props: {
|
|
66
|
-
backgroundColor: "blue",
|
|
67
|
-
textColor: "yellow",
|
|
68
|
-
textAlignment: "right",
|
|
69
|
-
level: 2,
|
|
70
|
-
},
|
|
71
|
-
content: [
|
|
72
|
-
{
|
|
73
|
-
type: "text",
|
|
74
|
-
text: "Heading ",
|
|
75
|
-
styles: {
|
|
76
|
-
bold: true,
|
|
77
|
-
underline: true,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
type: "text",
|
|
82
|
-
text: "2",
|
|
83
|
-
styles: {
|
|
84
|
-
italic: true,
|
|
85
|
-
strike: true,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
children: [
|
|
90
|
-
{
|
|
91
|
-
type: "paragraph",
|
|
92
|
-
props: {
|
|
93
|
-
backgroundColor: "red",
|
|
94
|
-
},
|
|
95
|
-
content: "Paragraph",
|
|
96
|
-
children: [],
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
type: "bulletListItem",
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
};
|
|
103
|
-
const firstNodeConversion = blockToNode(block, tt.schema);
|
|
104
|
-
|
|
105
|
-
expect(firstNodeConversion).toMatchSnapshot();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("Convert complex node to block", async () => {
|
|
109
|
-
const node = tt.schema.nodes["blockContainer"].create(
|
|
110
|
-
{
|
|
111
|
-
id: UniqueID.options.generateID(),
|
|
112
|
-
backgroundColor: "blue",
|
|
113
|
-
textColor: "yellow",
|
|
114
|
-
},
|
|
115
|
-
[
|
|
116
|
-
tt.schema.nodes["heading"].create(
|
|
117
|
-
{ textAlignment: "right", level: 2 },
|
|
118
|
-
[
|
|
119
|
-
tt.schema.text("Heading ", [
|
|
120
|
-
tt.schema.mark("bold"),
|
|
121
|
-
tt.schema.mark("underline"),
|
|
122
|
-
]),
|
|
123
|
-
tt.schema.text("2", [
|
|
124
|
-
tt.schema.mark("italic"),
|
|
125
|
-
tt.schema.mark("strike"),
|
|
126
|
-
]),
|
|
127
|
-
]
|
|
128
|
-
),
|
|
129
|
-
tt.schema.nodes["blockGroup"].create({}, [
|
|
130
|
-
tt.schema.nodes["blockContainer"].create(
|
|
131
|
-
{ id: UniqueID.options.generateID(), backgroundColor: "red" },
|
|
132
|
-
[
|
|
133
|
-
tt.schema.nodes["paragraph"].create(
|
|
134
|
-
{},
|
|
135
|
-
tt.schema.text("Paragraph")
|
|
136
|
-
),
|
|
137
|
-
]
|
|
138
|
-
),
|
|
139
|
-
tt.schema.nodes["blockContainer"].create(
|
|
140
|
-
{ id: UniqueID.options.generateID() },
|
|
141
|
-
[tt.schema.nodes["bulletListItem"].create()]
|
|
142
|
-
),
|
|
143
|
-
]),
|
|
144
|
-
]
|
|
145
|
-
);
|
|
146
|
-
const firstBlockConversion = nodeToBlock<DefaultBlockSchema>(
|
|
147
|
-
node,
|
|
148
|
-
defaultBlockSchema
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
expect(firstBlockConversion).toMatchSnapshot();
|
|
152
|
-
|
|
153
|
-
const firstNodeConversion = blockToNode<DefaultBlockSchema>(
|
|
154
|
-
firstBlockConversion,
|
|
155
|
-
tt.schema
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
expect(firstNodeConversion).toStrictEqual(node);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
describe("links", () => {
|
|
163
|
-
it("Convert a block with link", async () => {
|
|
164
|
-
const block: PartialBlock<DefaultBlockSchema> = {
|
|
165
|
-
id: UniqueID.options.generateID(),
|
|
166
|
-
type: "paragraph",
|
|
167
|
-
content: [
|
|
168
|
-
{
|
|
169
|
-
type: "link",
|
|
170
|
-
href: "https://www.website.com",
|
|
171
|
-
content: "Website",
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
};
|
|
175
|
-
const node = blockToNode(block, tt.schema);
|
|
176
|
-
expect(node).toMatchSnapshot();
|
|
177
|
-
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
178
|
-
node,
|
|
179
|
-
defaultBlockSchema
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
// Temporary fix to set props to {}, because at this point
|
|
183
|
-
// we don't have an easy way to access default props at runtime,
|
|
184
|
-
// so partialBlockToBlockForTesting will not set them.
|
|
185
|
-
(outputBlock as any).props = {};
|
|
186
|
-
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
187
|
-
|
|
188
|
-
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("Convert link block with marks", async () => {
|
|
192
|
-
const block: PartialBlock<DefaultBlockSchema> = {
|
|
193
|
-
id: UniqueID.options.generateID(),
|
|
194
|
-
type: "paragraph",
|
|
195
|
-
content: [
|
|
196
|
-
{
|
|
197
|
-
type: "link",
|
|
198
|
-
href: "https://www.website.com",
|
|
199
|
-
content: [
|
|
200
|
-
{
|
|
201
|
-
type: "text",
|
|
202
|
-
text: "Web",
|
|
203
|
-
styles: {
|
|
204
|
-
bold: true,
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
type: "text",
|
|
209
|
-
text: "site",
|
|
210
|
-
styles: {},
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
},
|
|
214
|
-
],
|
|
215
|
-
};
|
|
216
|
-
const node = blockToNode(block, tt.schema);
|
|
217
|
-
// expect(node).toMatchSnapshot();
|
|
218
|
-
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
219
|
-
node,
|
|
220
|
-
defaultBlockSchema
|
|
221
|
-
);
|
|
222
|
-
|
|
223
|
-
// Temporary fix to set props to {}, because at this point
|
|
224
|
-
// we don't have an easy way to access default props at runtime,
|
|
225
|
-
// so partialBlockToBlockForTesting will not set them.
|
|
226
|
-
(outputBlock as any).props = {};
|
|
227
|
-
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
228
|
-
|
|
229
|
-
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("Convert two adjacent links in a block", async () => {
|
|
233
|
-
const block: PartialBlock<DefaultBlockSchema> = {
|
|
234
|
-
id: UniqueID.options.generateID(),
|
|
235
|
-
type: "paragraph",
|
|
236
|
-
content: [
|
|
237
|
-
{
|
|
238
|
-
type: "link",
|
|
239
|
-
href: "https://www.website.com",
|
|
240
|
-
content: "Website",
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
type: "link",
|
|
244
|
-
href: "https://www.website2.com",
|
|
245
|
-
content: "Website2",
|
|
246
|
-
},
|
|
247
|
-
],
|
|
248
|
-
};
|
|
249
2
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
// so partialBlockToBlockForTesting will not set them.
|
|
318
|
-
(outputBlock as any).props = {};
|
|
319
|
-
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
320
|
-
|
|
321
|
-
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
it("Convert a block with a hard break at the start", async () => {
|
|
325
|
-
const block: PartialBlock<DefaultBlockSchema> = {
|
|
326
|
-
id: UniqueID.options.generateID(),
|
|
327
|
-
type: "paragraph",
|
|
328
|
-
content: [
|
|
329
|
-
{
|
|
330
|
-
type: "text",
|
|
331
|
-
text: "\nText1",
|
|
332
|
-
styles: {},
|
|
333
|
-
},
|
|
334
|
-
],
|
|
335
|
-
};
|
|
336
|
-
const node = blockToNode(block, tt.schema);
|
|
337
|
-
expect(node).toMatchSnapshot();
|
|
338
|
-
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
339
|
-
node,
|
|
340
|
-
defaultBlockSchema
|
|
341
|
-
);
|
|
342
|
-
|
|
343
|
-
// Temporary fix to set props to {}, because at this point
|
|
344
|
-
// we don't have an easy way to access default props at runtime,
|
|
345
|
-
// so partialBlockToBlockForTesting will not set them.
|
|
346
|
-
(outputBlock as any).props = {};
|
|
347
|
-
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
348
|
-
|
|
349
|
-
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
it("Convert a block with a hard break at the end", async () => {
|
|
353
|
-
const block: PartialBlock<DefaultBlockSchema> = {
|
|
354
|
-
id: UniqueID.options.generateID(),
|
|
355
|
-
type: "paragraph",
|
|
356
|
-
content: [
|
|
357
|
-
{
|
|
358
|
-
type: "text",
|
|
359
|
-
text: "Text1\n",
|
|
360
|
-
styles: {},
|
|
361
|
-
},
|
|
362
|
-
],
|
|
363
|
-
};
|
|
364
|
-
const node = blockToNode(block, tt.schema);
|
|
365
|
-
expect(node).toMatchSnapshot();
|
|
366
|
-
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
367
|
-
node,
|
|
368
|
-
defaultBlockSchema
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
// Temporary fix to set props to {}, because at this point
|
|
372
|
-
// we don't have an easy way to access default props at runtime,
|
|
373
|
-
// so partialBlockToBlockForTesting will not set them.
|
|
374
|
-
(outputBlock as any).props = {};
|
|
375
|
-
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
376
|
-
|
|
377
|
-
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
it("Convert a block with only a hard break", async () => {
|
|
381
|
-
const block: PartialBlock<DefaultBlockSchema> = {
|
|
382
|
-
id: UniqueID.options.generateID(),
|
|
383
|
-
type: "paragraph",
|
|
384
|
-
content: [
|
|
385
|
-
{
|
|
386
|
-
type: "text",
|
|
387
|
-
text: "\n",
|
|
388
|
-
styles: {},
|
|
389
|
-
},
|
|
390
|
-
],
|
|
391
|
-
};
|
|
392
|
-
const node = blockToNode(block, tt.schema);
|
|
393
|
-
expect(node).toMatchSnapshot();
|
|
394
|
-
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
395
|
-
node,
|
|
396
|
-
defaultBlockSchema
|
|
397
|
-
);
|
|
398
|
-
|
|
399
|
-
// Temporary fix to set props to {}, because at this point
|
|
400
|
-
// we don't have an easy way to access default props at runtime,
|
|
401
|
-
// so partialBlockToBlockForTesting will not set them.
|
|
402
|
-
(outputBlock as any).props = {};
|
|
403
|
-
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
404
|
-
|
|
405
|
-
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
it("Convert a block with a hard break and different styles", async () => {
|
|
409
|
-
const block: PartialBlock<DefaultBlockSchema> = {
|
|
410
|
-
id: UniqueID.options.generateID(),
|
|
411
|
-
type: "paragraph",
|
|
412
|
-
content: [
|
|
413
|
-
{
|
|
414
|
-
type: "text",
|
|
415
|
-
text: "Text1\n",
|
|
416
|
-
styles: {},
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
type: "text",
|
|
420
|
-
text: "Text2",
|
|
421
|
-
styles: { bold: true },
|
|
422
|
-
},
|
|
423
|
-
],
|
|
424
|
-
};
|
|
425
|
-
const node = blockToNode(block, tt.schema);
|
|
426
|
-
expect(node).toMatchSnapshot();
|
|
427
|
-
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
428
|
-
node,
|
|
429
|
-
defaultBlockSchema
|
|
430
|
-
);
|
|
431
|
-
|
|
432
|
-
// Temporary fix to set props to {}, because at this point
|
|
433
|
-
// we don't have an easy way to access default props at runtime,
|
|
434
|
-
// so partialBlockToBlockForTesting will not set them.
|
|
435
|
-
(outputBlock as any).props = {};
|
|
436
|
-
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
437
|
-
|
|
438
|
-
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it("Convert a block with a hard break in a link", async () => {
|
|
442
|
-
const block: PartialBlock<DefaultBlockSchema> = {
|
|
443
|
-
id: UniqueID.options.generateID(),
|
|
444
|
-
type: "paragraph",
|
|
445
|
-
content: [
|
|
446
|
-
{
|
|
447
|
-
type: "link",
|
|
448
|
-
href: "https://www.website.com",
|
|
449
|
-
content: "Link1\nLink1",
|
|
450
|
-
},
|
|
451
|
-
],
|
|
452
|
-
};
|
|
453
|
-
const node = blockToNode(block, tt.schema);
|
|
454
|
-
expect(node).toMatchSnapshot();
|
|
455
|
-
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
456
|
-
node,
|
|
457
|
-
defaultBlockSchema
|
|
458
|
-
);
|
|
459
|
-
|
|
460
|
-
// Temporary fix to set props to {}, because at this point
|
|
461
|
-
// we don't have an easy way to access default props at runtime,
|
|
462
|
-
// so partialBlockToBlockForTesting will not set them.
|
|
463
|
-
(outputBlock as any).props = {};
|
|
464
|
-
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
465
|
-
|
|
466
|
-
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
it("Convert a block with a hard break between links", async () => {
|
|
470
|
-
const block: PartialBlock<DefaultBlockSchema> = {
|
|
471
|
-
id: UniqueID.options.generateID(),
|
|
472
|
-
type: "paragraph",
|
|
473
|
-
content: [
|
|
474
|
-
{
|
|
475
|
-
type: "link",
|
|
476
|
-
href: "https://www.website.com",
|
|
477
|
-
content: "Link1\n",
|
|
478
|
-
},
|
|
479
|
-
{
|
|
480
|
-
type: "link",
|
|
481
|
-
href: "https://www.website2.com",
|
|
482
|
-
content: "Link2",
|
|
483
|
-
},
|
|
484
|
-
],
|
|
485
|
-
};
|
|
486
|
-
const node = blockToNode(block, tt.schema);
|
|
487
|
-
expect(node).toMatchSnapshot();
|
|
488
|
-
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
489
|
-
node,
|
|
490
|
-
defaultBlockSchema
|
|
491
|
-
);
|
|
492
|
-
|
|
493
|
-
// Temporary fix to set props to {}, because at this point
|
|
494
|
-
// we don't have an easy way to access default props at runtime,
|
|
495
|
-
// so partialBlockToBlockForTesting will not set them.
|
|
496
|
-
(outputBlock as any).props = {};
|
|
497
|
-
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
498
|
-
|
|
499
|
-
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
500
|
-
});
|
|
3
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor";
|
|
4
|
+
import { PartialBlock } from "../../schema/blocks/types";
|
|
5
|
+
import { customInlineContentTestCases } from "../testUtil/cases/customInlineContent";
|
|
6
|
+
import { customStylesTestCases } from "../testUtil/cases/customStyles";
|
|
7
|
+
import { defaultSchemaTestCases } from "../testUtil/cases/defaultSchema";
|
|
8
|
+
import { blockToNode, nodeToBlock } from "./nodeConversions";
|
|
9
|
+
import { addIdsToBlock, partialBlockToBlockForTesting } from "../testUtil/partialBlockTestUtil";
|
|
10
|
+
|
|
11
|
+
function validateConversion(
|
|
12
|
+
block: PartialBlock<any, any, any>,
|
|
13
|
+
editor: BlockNoteEditor<any, any, any>
|
|
14
|
+
) {
|
|
15
|
+
addIdsToBlock(block);
|
|
16
|
+
const node = blockToNode(
|
|
17
|
+
block,
|
|
18
|
+
editor._tiptapEditor.schema,
|
|
19
|
+
editor.styleSchema
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
expect(node).toMatchSnapshot();
|
|
23
|
+
|
|
24
|
+
const outputBlock = nodeToBlock(
|
|
25
|
+
node,
|
|
26
|
+
editor.blockSchema,
|
|
27
|
+
editor.inlineContentSchema,
|
|
28
|
+
editor.styleSchema
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(
|
|
32
|
+
editor.blockSchema,
|
|
33
|
+
block
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const testCases = [
|
|
40
|
+
defaultSchemaTestCases,
|
|
41
|
+
customStylesTestCases,
|
|
42
|
+
customInlineContentTestCases,
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
describe("Test BlockNote-Prosemirror conversion", () => {
|
|
46
|
+
for (const testCase of testCases) {
|
|
47
|
+
describe("Case: " + testCase.name, () => {
|
|
48
|
+
let editor: BlockNoteEditor<any, any, any>;
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
editor = testCase.createEditor();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
afterEach(() => {
|
|
55
|
+
editor._tiptapEditor.destroy();
|
|
56
|
+
editor = undefined as any;
|
|
57
|
+
|
|
58
|
+
delete (window as Window & { __TEST_OPTIONS?: any }).__TEST_OPTIONS;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
for (const document of testCase.documents) {
|
|
62
|
+
// eslint-disable-next-line no-loop-func
|
|
63
|
+
it("Convert " + document.name + " to/from prosemirror", () => {
|
|
64
|
+
// NOTE: only converts first block
|
|
65
|
+
validateConversion(document.blocks[0], editor);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
501
70
|
});
|