@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,133 +0,0 @@
|
|
|
1
|
-
import { DOMParser, DOMSerializer, Schema } from "prosemirror-model";
|
|
2
|
-
import rehypeParse from "rehype-parse";
|
|
3
|
-
import rehypeRemark from "rehype-remark";
|
|
4
|
-
import rehypeStringify from "rehype-stringify";
|
|
5
|
-
import remarkGfm from "remark-gfm";
|
|
6
|
-
import remarkParse from "remark-parse";
|
|
7
|
-
import remarkRehype, { defaultHandlers } from "remark-rehype";
|
|
8
|
-
import remarkStringify from "remark-stringify";
|
|
9
|
-
import { unified } from "unified";
|
|
10
|
-
import { Block, BlockSchema } from "../../extensions/Blocks/api/blockTypes";
|
|
11
|
-
|
|
12
|
-
import { blockToNode, nodeToBlock } from "../nodeConversions/nodeConversions";
|
|
13
|
-
import { removeUnderlines } from "./removeUnderlinesRehypePlugin";
|
|
14
|
-
import { simplifyBlocks } from "./simplifyBlocksRehypePlugin";
|
|
15
|
-
|
|
16
|
-
export async function blocksToHTML<BSchema extends BlockSchema>(
|
|
17
|
-
blocks: Block<BSchema>[],
|
|
18
|
-
schema: Schema
|
|
19
|
-
): Promise<string> {
|
|
20
|
-
const htmlParentElement = document.createElement("div");
|
|
21
|
-
const serializer = DOMSerializer.fromSchema(schema);
|
|
22
|
-
|
|
23
|
-
for (const block of blocks) {
|
|
24
|
-
const node = blockToNode(block, schema);
|
|
25
|
-
const htmlNode = serializer.serializeNode(node);
|
|
26
|
-
htmlParentElement.appendChild(htmlNode);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const htmlString = await unified()
|
|
30
|
-
.use(rehypeParse, { fragment: true })
|
|
31
|
-
.use(simplifyBlocks, {
|
|
32
|
-
orderedListItemBlockTypes: new Set<string>(["numberedListItem"]),
|
|
33
|
-
unorderedListItemBlockTypes: new Set<string>(["bulletListItem"]),
|
|
34
|
-
})
|
|
35
|
-
.use(rehypeStringify)
|
|
36
|
-
.process(htmlParentElement.innerHTML);
|
|
37
|
-
|
|
38
|
-
return htmlString.value as string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function HTMLToBlocks<BSchema extends BlockSchema>(
|
|
42
|
-
html: string,
|
|
43
|
-
blockSchema: BSchema,
|
|
44
|
-
schema: Schema
|
|
45
|
-
): Promise<Block<BSchema>[]> {
|
|
46
|
-
const htmlNode = document.createElement("div");
|
|
47
|
-
htmlNode.innerHTML = html.trim();
|
|
48
|
-
|
|
49
|
-
const parser = DOMParser.fromSchema(schema);
|
|
50
|
-
const parentNode = parser.parse(htmlNode); //, { preserveWhitespace: "full" });
|
|
51
|
-
|
|
52
|
-
const blocks: Block<BSchema>[] = [];
|
|
53
|
-
|
|
54
|
-
for (let i = 0; i < parentNode.firstChild!.childCount; i++) {
|
|
55
|
-
blocks.push(nodeToBlock(parentNode.firstChild!.child(i), blockSchema));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return blocks;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export async function blocksToMarkdown<BSchema extends BlockSchema>(
|
|
62
|
-
blocks: Block<BSchema>[],
|
|
63
|
-
schema: Schema
|
|
64
|
-
): Promise<string> {
|
|
65
|
-
const markdownString = await unified()
|
|
66
|
-
.use(rehypeParse, { fragment: true })
|
|
67
|
-
.use(removeUnderlines)
|
|
68
|
-
.use(rehypeRemark)
|
|
69
|
-
.use(remarkGfm)
|
|
70
|
-
.use(remarkStringify)
|
|
71
|
-
.process(await blocksToHTML(blocks, schema));
|
|
72
|
-
|
|
73
|
-
return markdownString.value as string;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// modefied version of https://github.com/syntax-tree/mdast-util-to-hast/blob/main/lib/handlers/code.js
|
|
77
|
-
// that outputs a data-language attribute instead of a CSS class (e.g.: language-typescript)
|
|
78
|
-
function code(state: any, node: any) {
|
|
79
|
-
const value = node.value ? node.value + "\n" : "";
|
|
80
|
-
/** @type {Properties} */
|
|
81
|
-
const properties: any = {};
|
|
82
|
-
|
|
83
|
-
if (node.lang) {
|
|
84
|
-
// changed line
|
|
85
|
-
properties["data-language"] = node.lang;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Create `<code>`.
|
|
89
|
-
/** @type {Element} */
|
|
90
|
-
let result: any = {
|
|
91
|
-
type: "element",
|
|
92
|
-
tagName: "code",
|
|
93
|
-
properties,
|
|
94
|
-
children: [{ type: "text", value }],
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
if (node.meta) {
|
|
98
|
-
result.data = { meta: node.meta };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
state.patch(node, result);
|
|
102
|
-
result = state.applyData(node, result);
|
|
103
|
-
|
|
104
|
-
// Create `<pre>`.
|
|
105
|
-
result = {
|
|
106
|
-
type: "element",
|
|
107
|
-
tagName: "pre",
|
|
108
|
-
properties: {},
|
|
109
|
-
children: [result],
|
|
110
|
-
};
|
|
111
|
-
state.patch(node, result);
|
|
112
|
-
return result;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export async function markdownToBlocks<BSchema extends BlockSchema>(
|
|
116
|
-
markdown: string,
|
|
117
|
-
blockSchema: BSchema,
|
|
118
|
-
schema: Schema
|
|
119
|
-
): Promise<Block<BSchema>[]> {
|
|
120
|
-
const htmlString = await unified()
|
|
121
|
-
.use(remarkParse)
|
|
122
|
-
.use(remarkGfm)
|
|
123
|
-
.use(remarkRehype, {
|
|
124
|
-
handlers: {
|
|
125
|
-
...(defaultHandlers as any),
|
|
126
|
-
code,
|
|
127
|
-
},
|
|
128
|
-
})
|
|
129
|
-
.use(rehypeStringify)
|
|
130
|
-
.process(markdown);
|
|
131
|
-
|
|
132
|
-
return HTMLToBlocks(htmlString.value as string, blockSchema, schema);
|
|
133
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Block,
|
|
3
|
-
BlockSchema,
|
|
4
|
-
PartialBlock,
|
|
5
|
-
} from "../../extensions/Blocks/api/blockTypes";
|
|
6
|
-
import {
|
|
7
|
-
InlineContent,
|
|
8
|
-
PartialInlineContent,
|
|
9
|
-
StyledText,
|
|
10
|
-
} from "../../extensions/Blocks/api/inlineContentTypes";
|
|
11
|
-
|
|
12
|
-
function textShorthandToStyledText(
|
|
13
|
-
content: string | StyledText[] = ""
|
|
14
|
-
): StyledText[] {
|
|
15
|
-
if (typeof content === "string") {
|
|
16
|
-
return [
|
|
17
|
-
{
|
|
18
|
-
type: "text",
|
|
19
|
-
text: content,
|
|
20
|
-
styles: {},
|
|
21
|
-
},
|
|
22
|
-
];
|
|
23
|
-
}
|
|
24
|
-
return content;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function partialContentToInlineContent(
|
|
28
|
-
content: string | PartialInlineContent[] = ""
|
|
29
|
-
): InlineContent[] {
|
|
30
|
-
if (typeof content === "string") {
|
|
31
|
-
return textShorthandToStyledText(content);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return content.map((partialContent) => {
|
|
35
|
-
if (partialContent.type === "link") {
|
|
36
|
-
return {
|
|
37
|
-
...partialContent,
|
|
38
|
-
content: textShorthandToStyledText(partialContent.content),
|
|
39
|
-
};
|
|
40
|
-
} else {
|
|
41
|
-
return partialContent;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function partialBlockToBlockForTesting<BSchema extends BlockSchema>(
|
|
47
|
-
partialBlock: PartialBlock<BSchema>
|
|
48
|
-
): Block<BSchema> {
|
|
49
|
-
const withDefaults = {
|
|
50
|
-
id: "",
|
|
51
|
-
type: "paragraph",
|
|
52
|
-
// because at this point we don't have an easy way to access default props at runtime,
|
|
53
|
-
// partialBlockToBlockForTesting will not set them.
|
|
54
|
-
props: {} as any,
|
|
55
|
-
content: [] as any,
|
|
56
|
-
children: [],
|
|
57
|
-
...partialBlock,
|
|
58
|
-
} satisfies PartialBlock<BSchema>;
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
...withDefaults,
|
|
62
|
-
content: partialContentToInlineContent(withDefaults.content),
|
|
63
|
-
children: withDefaults.children.map(partialBlockToBlockForTesting),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import { Attribute, Attributes, Node } from "@tiptap/core";
|
|
2
|
-
import { BlockNoteDOMAttributes, BlockNoteEditor } from "../../..";
|
|
3
|
-
import styles from "../nodes/Block.module.css";
|
|
4
|
-
import {
|
|
5
|
-
BlockConfig,
|
|
6
|
-
BlockSchema,
|
|
7
|
-
BlockSpec,
|
|
8
|
-
PropSchema,
|
|
9
|
-
TipTapNode,
|
|
10
|
-
TipTapNodeConfig,
|
|
11
|
-
} from "./blockTypes";
|
|
12
|
-
import { mergeCSSClasses } from "../../../shared/utils";
|
|
13
|
-
import { ParseRule } from "prosemirror-model";
|
|
14
|
-
|
|
15
|
-
export function camelToDataKebab(str: string): string {
|
|
16
|
-
return "data-" + str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Function that uses the 'propSchema' of a blockConfig to create a TipTap
|
|
20
|
-
// node's `addAttributes` property.
|
|
21
|
-
export function propsToAttributes<
|
|
22
|
-
BType extends string,
|
|
23
|
-
PSchema extends PropSchema,
|
|
24
|
-
ContainsInlineContent extends boolean,
|
|
25
|
-
BSchema extends BlockSchema
|
|
26
|
-
>(
|
|
27
|
-
blockConfig: Omit<
|
|
28
|
-
BlockConfig<BType, PSchema, ContainsInlineContent, BSchema>,
|
|
29
|
-
"render"
|
|
30
|
-
>
|
|
31
|
-
): Attributes {
|
|
32
|
-
const tiptapAttributes: Record<string, Attribute> = {};
|
|
33
|
-
|
|
34
|
-
Object.entries(blockConfig.propSchema).forEach(([name, spec]) => {
|
|
35
|
-
tiptapAttributes[name] = {
|
|
36
|
-
default: spec.default,
|
|
37
|
-
keepOnSplit: true,
|
|
38
|
-
// Props are displayed in kebab-case as HTML attributes. If a prop's
|
|
39
|
-
// value is the same as its default, we don't display an HTML
|
|
40
|
-
// attribute for it.
|
|
41
|
-
parseHTML: (element) => {
|
|
42
|
-
const value = element.getAttribute(camelToDataKebab(name));
|
|
43
|
-
|
|
44
|
-
if (value === null) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (typeof spec.default === "boolean") {
|
|
49
|
-
if (value === "true") {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (value === "false") {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (typeof spec.default === "number") {
|
|
61
|
-
const asNumber = parseFloat(value);
|
|
62
|
-
const isNumeric =
|
|
63
|
-
!Number.isNaN(asNumber) && Number.isFinite(asNumber);
|
|
64
|
-
|
|
65
|
-
if (isNumeric) {
|
|
66
|
-
return asNumber;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return value;
|
|
73
|
-
},
|
|
74
|
-
renderHTML: (attributes) =>
|
|
75
|
-
attributes[name] !== spec.default
|
|
76
|
-
? {
|
|
77
|
-
[camelToDataKebab(name)]: attributes[name],
|
|
78
|
-
}
|
|
79
|
-
: {},
|
|
80
|
-
};
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return tiptapAttributes;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Function that uses the 'parse' function of a blockConfig to create a
|
|
87
|
-
// TipTap node's `parseHTML` property. This is only used for parsing content
|
|
88
|
-
// from the clipboard.
|
|
89
|
-
export function parse<
|
|
90
|
-
BType extends string,
|
|
91
|
-
PSchema extends PropSchema,
|
|
92
|
-
ContainsInlineContent extends boolean,
|
|
93
|
-
BSchema extends BlockSchema
|
|
94
|
-
>(
|
|
95
|
-
blockConfig: Omit<
|
|
96
|
-
BlockConfig<BType, PSchema, ContainsInlineContent, BSchema>,
|
|
97
|
-
"render"
|
|
98
|
-
>
|
|
99
|
-
): ParseRule[] {
|
|
100
|
-
return [
|
|
101
|
-
{
|
|
102
|
-
tag: "div[data-content-type=" + blockConfig.type + "]",
|
|
103
|
-
},
|
|
104
|
-
];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Function that uses the 'render' function of a blockConfig to create a
|
|
108
|
-
// TipTap node's `renderHTML` property. Since custom blocks use node views,
|
|
109
|
-
// this is only used for serializing content to the clipboard.
|
|
110
|
-
export function render<
|
|
111
|
-
BType extends string,
|
|
112
|
-
PSchema extends PropSchema,
|
|
113
|
-
ContainsInlineContent extends boolean,
|
|
114
|
-
BSchema extends BlockSchema
|
|
115
|
-
>(
|
|
116
|
-
blockConfig: Omit<
|
|
117
|
-
BlockConfig<BType, PSchema, ContainsInlineContent, BSchema>,
|
|
118
|
-
"render"
|
|
119
|
-
>,
|
|
120
|
-
HTMLAttributes: Record<string, any>
|
|
121
|
-
) {
|
|
122
|
-
// Create blockContent element
|
|
123
|
-
const blockContent = document.createElement("div");
|
|
124
|
-
// Add blockContent HTML attribute
|
|
125
|
-
blockContent.setAttribute("data-content-type", blockConfig.type);
|
|
126
|
-
// Add props as HTML attributes in kebab-case with "data-" prefix
|
|
127
|
-
for (const [attribute, value] of Object.entries(HTMLAttributes)) {
|
|
128
|
-
blockContent.setAttribute(attribute, value);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// TODO: This only works for content copied within BlockNote.
|
|
132
|
-
// Creates contentDOM element to serialize inline content into.
|
|
133
|
-
let contentDOM: HTMLDivElement | undefined;
|
|
134
|
-
if (blockConfig.containsInlineContent) {
|
|
135
|
-
contentDOM = document.createElement("div");
|
|
136
|
-
blockContent.appendChild(contentDOM);
|
|
137
|
-
} else {
|
|
138
|
-
contentDOM = undefined;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return contentDOM !== undefined
|
|
142
|
-
? {
|
|
143
|
-
dom: blockContent,
|
|
144
|
-
contentDOM: contentDOM,
|
|
145
|
-
}
|
|
146
|
-
: {
|
|
147
|
-
dom: blockContent,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// A function to create custom block for API consumers
|
|
152
|
-
// we want to hide the tiptap node from API consumers and provide a simpler API surface instead
|
|
153
|
-
export function createBlockSpec<
|
|
154
|
-
BType extends string,
|
|
155
|
-
PSchema extends PropSchema,
|
|
156
|
-
ContainsInlineContent extends false,
|
|
157
|
-
BSchema extends BlockSchema
|
|
158
|
-
>(
|
|
159
|
-
blockConfig: BlockConfig<BType, PSchema, ContainsInlineContent, BSchema>
|
|
160
|
-
): BlockSpec<BType, PSchema, ContainsInlineContent> {
|
|
161
|
-
const node = createTipTapBlock<
|
|
162
|
-
BType,
|
|
163
|
-
ContainsInlineContent,
|
|
164
|
-
{
|
|
165
|
-
editor: BlockNoteEditor<BSchema>;
|
|
166
|
-
domAttributes?: BlockNoteDOMAttributes;
|
|
167
|
-
}
|
|
168
|
-
>({
|
|
169
|
-
name: blockConfig.type,
|
|
170
|
-
content: (blockConfig.containsInlineContent
|
|
171
|
-
? "inline*"
|
|
172
|
-
: "") as ContainsInlineContent extends true ? "inline*" : "",
|
|
173
|
-
selectable: true,
|
|
174
|
-
|
|
175
|
-
addAttributes() {
|
|
176
|
-
return propsToAttributes(blockConfig);
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
parseHTML() {
|
|
180
|
-
return parse(blockConfig);
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
renderHTML({ HTMLAttributes }) {
|
|
184
|
-
return render(blockConfig, HTMLAttributes);
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
addNodeView() {
|
|
188
|
-
return ({ HTMLAttributes, getPos }) => {
|
|
189
|
-
// Create blockContent element
|
|
190
|
-
const blockContent = document.createElement("div");
|
|
191
|
-
// Add custom HTML attributes
|
|
192
|
-
const blockContentDOMAttributes =
|
|
193
|
-
this.options.domAttributes?.blockContent || {};
|
|
194
|
-
for (const [attribute, value] of Object.entries(
|
|
195
|
-
blockContentDOMAttributes
|
|
196
|
-
)) {
|
|
197
|
-
if (attribute !== "class") {
|
|
198
|
-
blockContent.setAttribute(attribute, value);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
// Set blockContent & custom classes
|
|
202
|
-
blockContent.className = mergeCSSClasses(
|
|
203
|
-
styles.blockContent,
|
|
204
|
-
blockContentDOMAttributes.class
|
|
205
|
-
);
|
|
206
|
-
// Add blockContent HTML attribute
|
|
207
|
-
blockContent.setAttribute("data-content-type", blockConfig.type);
|
|
208
|
-
// Add props as HTML attributes in kebab-case with "data-" prefix
|
|
209
|
-
for (const [attribute, value] of Object.entries(HTMLAttributes)) {
|
|
210
|
-
blockContent.setAttribute(attribute, value);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Gets BlockNote editor instance
|
|
214
|
-
const editor = this.options.editor! as BlockNoteEditor<
|
|
215
|
-
BSchema & {
|
|
216
|
-
[k in BType]: BlockSpec<BType, PSchema, ContainsInlineContent>;
|
|
217
|
-
}
|
|
218
|
-
>;
|
|
219
|
-
// Gets position of the node
|
|
220
|
-
if (typeof getPos === "boolean") {
|
|
221
|
-
throw new Error(
|
|
222
|
-
"Cannot find node position as getPos is a boolean, not a function."
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
const pos = getPos();
|
|
226
|
-
// Gets TipTap editor instance
|
|
227
|
-
const tipTapEditor = editor._tiptapEditor;
|
|
228
|
-
// Gets parent blockContainer node
|
|
229
|
-
const blockContainer = tipTapEditor.state.doc.resolve(pos!).node();
|
|
230
|
-
// Gets block identifier
|
|
231
|
-
const blockIdentifier = blockContainer.attrs.id;
|
|
232
|
-
|
|
233
|
-
// Get the block
|
|
234
|
-
const block = editor.getBlock(blockIdentifier)!;
|
|
235
|
-
if (block.type !== blockConfig.type) {
|
|
236
|
-
throw new Error("Block type does not match");
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Render elements
|
|
240
|
-
const rendered = blockConfig.render(block as any, editor);
|
|
241
|
-
// Add HTML attributes to contentDOM
|
|
242
|
-
if (blockConfig.containsInlineContent) {
|
|
243
|
-
const contentDOM = (rendered as { contentDOM: HTMLElement })
|
|
244
|
-
.contentDOM;
|
|
245
|
-
|
|
246
|
-
const inlineContentDOMAttributes =
|
|
247
|
-
this.options.domAttributes?.inlineContent || {};
|
|
248
|
-
// Add custom HTML attributes
|
|
249
|
-
for (const [attribute, value] of Object.entries(
|
|
250
|
-
inlineContentDOMAttributes
|
|
251
|
-
)) {
|
|
252
|
-
if (attribute !== "class") {
|
|
253
|
-
contentDOM.setAttribute(attribute, value);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
// Merge existing classes with inlineContent & custom classes
|
|
257
|
-
contentDOM.className = mergeCSSClasses(
|
|
258
|
-
contentDOM.className,
|
|
259
|
-
styles.inlineContent,
|
|
260
|
-
inlineContentDOMAttributes.class
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
// Add elements to blockContent
|
|
264
|
-
blockContent.appendChild(rendered.dom);
|
|
265
|
-
|
|
266
|
-
return "contentDOM" in rendered
|
|
267
|
-
? {
|
|
268
|
-
dom: blockContent,
|
|
269
|
-
contentDOM: rendered.contentDOM,
|
|
270
|
-
destroy: rendered.destroy,
|
|
271
|
-
}
|
|
272
|
-
: {
|
|
273
|
-
dom: blockContent,
|
|
274
|
-
destroy: rendered.destroy,
|
|
275
|
-
};
|
|
276
|
-
};
|
|
277
|
-
},
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
return {
|
|
281
|
-
node: node as TipTapNode<BType, ContainsInlineContent>,
|
|
282
|
-
propSchema: blockConfig.propSchema,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export function createTipTapBlock<
|
|
287
|
-
Type extends string,
|
|
288
|
-
ContainsInlineContent extends boolean,
|
|
289
|
-
Options extends {
|
|
290
|
-
domAttributes?: BlockNoteDOMAttributes;
|
|
291
|
-
} = {
|
|
292
|
-
domAttributes?: BlockNoteDOMAttributes;
|
|
293
|
-
},
|
|
294
|
-
Storage = any
|
|
295
|
-
>(
|
|
296
|
-
config: TipTapNodeConfig<Type, ContainsInlineContent, Options, Storage>
|
|
297
|
-
): TipTapNode<Type, ContainsInlineContent, Options, Storage> {
|
|
298
|
-
// Type cast is needed as Node.name is mutable, though there is basically no
|
|
299
|
-
// reason to change it after creation. Alternative is to wrap Node in a new
|
|
300
|
-
// class, which I don't think is worth it since we'd only be changing 1
|
|
301
|
-
// attribute to be read only.
|
|
302
|
-
return Node.create<Options, Storage>({
|
|
303
|
-
...config,
|
|
304
|
-
group: "blockContent",
|
|
305
|
-
content: config.content,
|
|
306
|
-
}) as TipTapNode<Type, ContainsInlineContent, Options, Storage>;
|
|
307
|
-
}
|