@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
package/dist/blocknote.umd.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`?t.nodes.hardBreak.create():t.text(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
`,styles:{}};return}const i={};let r;for(const s of n.marks)if(s.type.name==="link")r=s;else if(rt.has(s.type.name))i[s.type.name]=!0;else if(st.has(s.type.name))i[s.type.name]=s.attrs.color;else throw Error("Mark is of an unrecognized type: "+s.type.name);e?e.type==="text"?r?(t.push(e),e={type:"link",href:r.attrs.href,content:[{type:"text",text:n.textContent,styles:i}]}):JSON.stringify(e.styles)===JSON.stringify(i)?e.text+=n.textContent:(t.push(e),e={type:"text",text:n.textContent,styles:i}):e.type==="link"&&(r?e.href===r.attrs.href?JSON.stringify(e.content[e.content.length-1].styles)===JSON.stringify(i)?e.content[e.content.length-1].text+=n.textContent:e.content.push({type:"text",text:n.textContent,styles:i}):(t.push(e),e={type:"link",href:r.attrs.href,content:[{type:"text",text:n.textContent,styles:i}]}):(t.push(e),e={type:"text",text:n.textContent,styles:i})):r?e={type:"link",href:r.attrs.href,content:[{type:"text",text:n.textContent,styles:i}]}:e={type:"text",text:n.textContent,styles:i}}),e&&t.push(e),t}function P(o,t,e){if(o.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+o.type.name+".");const n=e==null?void 0:e.get(o);if(n)return n;const i=nt(o);let r=i.id;r===null&&(r=q.options.generateID());const s={};for(const[c,m]of Object.entries({...o.attrs,...i.contentNode.attrs})){const h=t[i.contentType.name];if(!h)throw Error("Block is of an unrecognized type: "+i.contentType.name);const p=h.propSchema;c in p?s[c]=m:c!=="id"&&!(c in T)&&console.warn("Block has an unrecognized attribute: "+c)}const l=t[i.contentType.name],a=[];for(let c=0;c<i.numChildBlocks;c++)a.push(P(o.lastChild.child(c),t,e));const d={id:r,type:l.node.name,props:s,content:l.node.config.content==="inline*"?Re(i.contentNode):void 0,children:a};return e==null||e.set(o,d),d}const ct=new b.PluginKey("previous-blocks"),ze={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Ve=()=>{let o;return new b.Plugin({key:ct,view(t){return{update:async(e,n)=>{var i;((i=this.key)==null?void 0:i.getState(e.state).updatedBlocks.size)>0&&(o=setTimeout(()=>{e.dispatch(e.state.tr.setMeta(ct,{clearUpdate:!0}))},0))},destroy:()=>{o&&clearTimeout(o)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,e,n,i){if(e.currentTransactionOldBlockAttrs={},e.updatedBlocks.clear(),!t.docChanged||n.doc.eq(i.doc))return e;const r={},s=g.findChildren(n.doc,d=>d.attrs.id),l=new Map(s.map(d=>[d.node.attrs.id,d])),a=g.findChildren(i.doc,d=>d.attrs.id);for(const d of a){const c=l.get(d.node.attrs.id),m=c==null?void 0:c.node.firstChild,h=d.node.firstChild;if(c&&m&&h){const p={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:i.doc.resolve(d.pos).depth};let k={index:m.attrs.index,level:m.attrs.level,type:m.type.name,depth:n.doc.resolve(c.pos).depth};r[d.node.attrs.id]=k,t.getMeta("numberedListIndexing")&&(d.node.attrs.id in e.prevTransactionOldBlockAttrs&&(k=e.prevTransactionOldBlockAttrs[d.node.attrs.id]),p.type==="numberedListItem"&&(k.index=p.index)),e.currentTransactionOldBlockAttrs[d.node.attrs.id]=k,JSON.stringify(k)!==JSON.stringify(p)&&(k["depth-change"]=k.depth-p.depth,e.updatedBlocks.add(d.node.attrs.id))}}return e.prevTransactionOldBlockAttrs=r,e}},props:{decorations(t){const e=this.getState(t);if(e.updatedBlocks.size===0)return;const n=[];return t.doc.descendants((i,r)=>{if(!i.attrs.id||!e.updatedBlocks.has(i.attrs.id))return;const s=e.currentTransactionOldBlockAttrs[i.attrs.id],l={};for(const[d,c]of Object.entries(s))l["data-prev-"+ze[d]]=c||"none";const a=I.Decoration.node(r,r+i.nodeSize,{...l});n.push(a)}),I.DecorationSet.create(t.doc,n)}}})},ut="_blockOuter_xo7pf_5",pt="_block_xo7pf_5",ht="_reactNodeViewRenderer_xo7pf_17",mt="_blockContent_xo7pf_22",ft="_blockGroup_xo7pf_42",gt="_wrapper_xo7pf_226",kt="_addImageButton_xo7pf_234",bt="_addImageButtonIcon_xo7pf_250",yt="_addImageButtonText_xo7pf_256",vt="_imageAndCaptionWrapper_xo7pf_260",wt="_imageWrapper_xo7pf_266",Ct="_image_xo7pf_260",Et="_resizeHandle_xo7pf_279",St="_caption_xo7pf_294",Tt="_isEmpty_xo7pf_300",Bt="_inlineContent_xo7pf_300",xt="_isFilter_xo7pf_301",Mt="_hasAnchor_xo7pf_313",y={blockOuter:ut,block:pt,reactNodeViewRenderer:ht,blockContent:mt,blockGroup:ft,wrapper:gt,addImageButton:kt,addImageButtonIcon:bt,addImageButtonText:yt,imageAndCaptionWrapper:vt,imageWrapper:wt,image:Ct,resizeHandle:Et,caption:St,isEmpty:Tt,inlineContent:Bt,isFilter:xt,hasAnchor:Mt},Fe=Object.freeze(Object.defineProperty({__proto__:null,addImageButton:kt,addImageButtonIcon:bt,addImageButtonText:yt,block:pt,blockContent:mt,blockGroup:ft,blockOuter:ut,caption:St,default:y,hasAnchor:Mt,image:Ct,imageAndCaptionWrapper:vt,imageWrapper:wt,inlineContent:Bt,isEmpty:Tt,isFilter:xt,reactNodeViewRenderer:ht,resizeHandle:Et,wrapper:gt},Symbol.toStringTag,{value:"Module"})),Ue={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},qe=new b.PluginKey("non-editable-block"),$e=()=>new b.Plugin({key:qe,props:{handleKeyDown:(o,t)=>{"node"in o.state.selection&&t.preventDefault()}}}),We=g.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:o=>{if(typeof o=="string")return!1;const t={};for(const[e,n]of Object.entries(Ue))o.getAttribute(n)&&(t[e]=o.getAttribute(n));return o.getAttribute("data-node-type")==="blockContainer"?t:!1}}]},renderHTML({HTMLAttributes:o}){var e;const t=((e=this.options.domAttributes)==null?void 0:e.blockContainer)||{};return["div",g.mergeAttributes(o,{class:y.blockOuter,"data-node-type":"block-outer"}),["div",g.mergeAttributes({...t,class:x(y.block,t.class),"data-node-type":this.name},o),0]]},addCommands(){return{BNCreateBlock:o=>({state:t,dispatch:e})=>{const n=t.schema.nodes.blockContainer.createAndFill();return e&&t.tr.insert(o,n),!0},BNDeleteBlock:o=>({state:t,dispatch:e})=>{const n=v(t.doc,o);if(n===void 0)return!1;const{startPos:i,endPos:r}=n;return e&&t.tr.deleteRange(i,r),!0},BNUpdateBlock:(o,t)=>({state:e,dispatch:n})=>{const i=v(e.doc,o);if(i===void 0)return!1;const{startPos:r,endPos:s,node:l,contentNode:a}=i;if(n){if(t.children!==void 0){const p=[];for(const k of t.children)p.push(F(k,e.schema));l.childCount===2?e.tr.replace(r+a.nodeSize+1,s-1,new S.Slice(S.Fragment.from(p),0,0)):e.tr.insert(r+a.nodeSize,e.schema.nodes.blockGroup.create({},p))}if(t.content!==void 0){let p=[];typeof t.content=="string"?p.push(e.schema.text(t.content)):p=dt(t.content,e.schema),e.tr.replace(r+1,r+a.nodeSize-1,new S.Slice(S.Fragment.from(p),0,0))}const d=a.type.name,c=t.type||d,m=e.schema.nodes[d].spec.content,h=e.schema.nodes[c].spec.content;m==="inline*"&&h===""?e.tr.replaceWith(r,s,e.schema.nodes[c].create({...a.attrs,...t.props})).setSelection(new b.NodeSelection(e.tr.doc.resolve(r))):e.tr.setNodeMarkup(r,t.type===void 0?void 0:e.schema.nodes[t.type],{...a.attrs,...t.props}),e.tr.setNodeMarkup(r-1,void 0,{...l.attrs,...t.props})}return!0},BNMergeBlocks:o=>({state:t,dispatch:e})=>{const n=t.doc.resolve(o+1).node().type.name==="blockContainer",i=t.doc.resolve(o-1).node().type.name==="blockContainer";if(!n||!i)return!1;const r=v(t.doc,o+1),{node:s,contentNode:l,startPos:a,endPos:d,depth:c}=r;if(s.childCount===2){const p=t.doc.resolve(a+l.nodeSize+1),k=t.doc.resolve(d-1),w=p.blockRange(k);e&&t.tr.lift(w,c-1)}let m=o-1,h=v(t.doc,m);for(;h.numChildBlocks>0;)if(m--,h=v(t.doc,m),h===void 0)return!1;return e&&(e(t.tr.deleteRange(a,a+l.nodeSize).replace(m-1,a,new S.Slice(l.content,0,0)).scrollIntoView()),t.tr.setSelection(new b.TextSelection(t.doc.resolve(m-1)))),!0},BNSplitBlock:(o,t)=>({state:e,dispatch:n})=>{const i=v(e.doc,o);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:l,endPos:a,depth:d}=i,c=e.doc.cut(l+1,o),m=e.doc.cut(o,a-1),h=e.schema.nodes.blockContainer.createAndFill(),p=a+1,k=p+2;return n&&(e.tr.insert(p,h),e.tr.replace(k,k+1,m.content.size>0?new S.Slice(S.Fragment.from(m),d+2,d+2):void 0),t&&e.tr.setBlockType(k,k,e.schema.node(s).type,r.attrs),e.tr.setSelection(new b.TextSelection(e.doc.resolve(k))),e.tr.replace(l+1,a-1,c.content.size>0?new S.Slice(S.Fragment.from(c),d+2,d+2):void 0)),!0}}},addProseMirrorPlugins(){return[Ve(),$e()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:n})=>[()=>n.deleteSelection(),()=>n.undoInputRule(),()=>n.command(({state:i})=>{const{contentType:r}=v(i.doc,i.selection.from),s=i.selection.$anchor.parentOffset===0,l=r.name==="paragraph";return s&&!l?n.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1}),()=>n.command(({state:i})=>i.selection.$anchor.parentOffset===0?n.liftListItem("blockContainer"):!1),()=>n.command(({state:i})=>{const{depth:r,startPos:s}=v(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,a=i.selection.anchor===i.selection.head,d=s===2,c=s-1;return!d&&l&&a&&r===2?n.BNMergeBlocks(c):!1})]),Delete:()=>this.editor.commands.first(({commands:n})=>[()=>n.deleteSelection(),()=>n.command(({state:i})=>{const{node:r,contentNode:s,depth:l,endPos:a}=v(i.doc,i.selection.from),d=i.selection.$anchor.parentOffset===s.firstChild.nodeSize,c=i.selection.anchor===i.selection.head,m=r.childCount===2;if(d&&c&&!m){let h=l,p=a+2,k=i.doc.resolve(p).depth;for(;k<h;)h=k,p+=2,k=i.doc.resolve(p).depth;return n.BNMergeBlocks(p-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:n})=>[()=>n.command(({state:i})=>{const{node:r,depth:s}=v(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,a=i.selection.anchor===i.selection.head,d=r.textContent.length===0,c=s>2;return l&&a&&d&&c?n.liftListItem("blockContainer"):!1}),()=>n.command(({state:i,chain:r})=>{const{node:s,endPos:l}=v(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0,d=i.selection.anchor===i.selection.head,c=s.textContent.length===0;if(a&&d&&c){const m=l+1,h=m+2;return r().BNCreateBlock(m).setTextSelection(h).run(),!0}return!1}),()=>n.command(({state:i,chain:r})=>{const{node:s}=v(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0;return s.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(i.selection.from,l).run(),!0)})]),Tab:()=>(this.editor.commands.sinkListItem("blockContainer"),!0),"Shift-Tab":()=>(this.editor.commands.liftListItem("blockContainer"),!0),"Mod-Alt-0":()=>this.editor.commands.BNCreateBlock(this.editor.state.selection.anchor+2)}}}),Ge=g.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:o=>typeof o=="string"?!1:o.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:o}){var e;const t=((e=this.options.domAttributes)==null?void 0:e.blockGroup)||{};return["div",g.mergeAttributes({...t,class:x(y.blockGroup,t.class),"data-node-type":"blockGroup"},o),0]}}),je=g.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Ke=o=>{const t=S.DOMSerializer.fromSchema(o);return new S.DOMSerializer({...t.nodes},t.marks)},_t=g.Extension.create({addProseMirrorPlugins(){return[new b.Plugin({props:{clipboardSerializer:Ke(this.editor.schema)}})]}});class U{constructor(){u(this,"callbacks",{})}on(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),()=>this.off(t,e)}emit(t,...e){const n=this.callbacks[t];n&&n.forEach(i=>i.apply(this,e))}off(t,e){const n=this.callbacks[t];n&&(e?this.callbacks[t]=n.filter(i=>i!==e):delete this.callbacks[t])}removeAllListeners(){this.callbacks={}}}const Xe=g.findParentNode(o=>o.type.name==="blockContainer");class Ye{constructor(t,e,n=()=>{}){u(this,"suggestionsMenuState");u(this,"updateSuggestionsMenu");u(this,"pluginState");u(this,"handleScroll",()=>{var t;if((t=this.suggestionsMenuState)!=null&&t.show){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.suggestionsMenuState.referencePos=e.getBoundingClientRect(),this.updateSuggestionsMenu()}});this.editor=t,this.pluginKey=e,this.pluginState=G(),this.updateSuggestionsMenu=()=>{if(!this.suggestionsMenuState)throw new Error("Attempting to update uninitialized suggestions menu");n(this.suggestionsMenuState)},document.addEventListener("scroll",this.handleScroll)}update(t,e){const n=this.pluginKey.getState(e),i=this.pluginKey.getState(t.state),r=!n.active&&i.active,s=n.active&&!i.active,l=n.active&&i.active;if(!r&&!l&&!s)return;if(this.pluginState=s?n:i,s||!this.editor.isEditable){this.suggestionsMenuState.show=!1,this.updateSuggestionsMenu();return}const a=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.suggestionsMenuState={show:!0,referencePos:a.getBoundingClientRect(),filteredItems:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex},this.updateSuggestionsMenu())}destroy(){document.removeEventListener("scroll",this.handleScroll)}}function G(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}const It=(o,t,e,n,i=()=>[],r=()=>{})=>{if(n.length!==1)throw new Error("'char' should be a single character");let s;const l=a=>{a.dispatch(a.state.tr.setMeta(e,{deactivate:!0}))};return{plugin:new b.Plugin({key:e,view:()=>(s=new Ye(o,e,t),s),state:{init(){return G()},apply(a,d,c,m){var p,k,w,E;if(a.getMeta("orderedListIndexing")!==void 0)return d;if((p=a.getMeta(e))!=null&&p.activate)return{active:!0,triggerCharacter:((k=a.getMeta(e))==null?void 0:k.triggerCharacter)||"",queryStartPos:m.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!d.active)return d;const h={...d};if(h.items=i(m.doc.textBetween(d.queryStartPos,m.selection.from)),h.notFoundCount=0,h.items.length===0&&(h.notFoundCount=Math.max(0,d.notFoundCount+(m.selection.from-c.selection.from))),m.selection.from!==m.selection.to||(w=a.getMeta(e))!=null&&w.deactivate||a.getMeta("focus")||a.getMeta("blur")||a.getMeta("pointer")||d.active&&m.selection.from<d.queryStartPos||h.notFoundCount>3)return G();if(((E=a.getMeta(e))==null?void 0:E.selectedItemIndexChanged)!==void 0){let B=a.getMeta(e).selectedItemIndexChanged;B<0?B=d.items.length-1:B>=d.items.length&&(B=0),h.keyboardHoveredItemIndex=B}else c.selection.from!==m.selection.from&&(h.keyboardHoveredItemIndex=0);return h}},props:{handleKeyDown(a,d){const c=this.getState(a.state).active;if(d.key===n&&!c)return a.dispatch(a.state.tr.insertText(n).scrollIntoView().setMeta(e,{activate:!0,triggerCharacter:n})),!0;if(!c)return!1;const{triggerCharacter:m,queryStartPos:h,items:p,keyboardHoveredItemIndex:k}=e.getState(a.state);return d.key==="ArrowUp"?(a.dispatch(a.state.tr.setMeta(e,{selectedItemIndexChanged:k-1})),!0):d.key==="ArrowDown"?(a.dispatch(a.state.tr.setMeta(e,{selectedItemIndexChanged:k+1})),!0):d.key==="Enter"?(p.length===0||(l(a),o._tiptapEditor.chain().focus().deleteRange({from:h-m.length,to:o._tiptapEditor.state.selection.from}).run(),r({item:p[k],editor:o})),!0):d.key==="Escape"?(l(a),!0):!1},decorations(a){const{active:d,decorationId:c,queryStartPos:m,triggerCharacter:h}=this.getState(a);if(!d)return null;if(h===""){const p=Xe(a.selection);if(p)return I.DecorationSet.create(a.doc,[I.Decoration.node(p.pos,p.pos+p.node.nodeSize,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":c})])}return I.DecorationSet.create(a.doc,[I.Decoration.inline(m-h.length,m,{nodeName:"span",class:"suggestion-decorator","data-decoration-id":c})])}}}),itemCallback:a=>{l(o._tiptapEditor.view),o._tiptapEditor.chain().focus().deleteRange({from:s.pluginState.queryStartPos-s.pluginState.triggerCharacter.length,to:o._tiptapEditor.state.selection.from}).run(),r({item:a,editor:o})}}},$=new b.PluginKey("SlashMenuPlugin");class At extends U{constructor(e,n){super();u(this,"plugin");u(this,"itemCallback");const i=It(e,r=>{this.emit("update",r)},$,"/",r=>n.filter(({name:s,aliases:l})=>s.toLowerCase().startsWith(r.toLowerCase())||l&&l.filter(a=>a.toLowerCase().startsWith(r.toLowerCase())).length!==0),({item:r,editor:s})=>r.execute(s));this.plugin=i.plugin,this.itemCallback=i.itemCallback}onUpdate(e){return this.on("update",e)}}const Je=new b.PluginKey("blocknote-placeholder"),Ze=g.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",isFilterClass:"is-filter",hasAnchorClass:"has-anchor",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new b.Plugin({key:Je,props:{decorations:o=>{const{doc:t,selection:e}=o,n=$.getState(o),i=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=e,s=[];if(i)return t.descendants((l,a)=>{const d=r>=a&&r<=a+l.nodeSize,c=!l.isLeaf&&!l.childCount;if((d||!this.options.showOnlyCurrent)&&c){const m=[this.options.emptyNodeClass];this.editor.isEmpty&&m.push(this.options.emptyEditorClass),d&&m.push(this.options.hasAnchorClass),(n==null?void 0:n.triggerCharacter)===""&&(n!=null&&n.active)&&m.push(this.options.isFilterClass);const h=I.Decoration.node(a,a+l.nodeSize,{class:m.join(" ")});s.push(h)}return this.options.includeChildren}),I.DecorationSet.create(t,s)}}})]}}),Qe=g.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:o=>o.getAttribute("data-text-alignment"),renderHTML:o=>o.textAlignment!=="left"&&{"data-text-alignment":o.textAlignment}}}}]},addCommands(){return{setTextAlignment:o=>({state:t})=>{const e=[],n=v(t.doc,t.selection.from);if(n===void 0)return!1;let i=n.startPos;for(;i<t.selection.to;)t.doc.resolve(i).node().type.spec.group==="blockContent"?(e.push(i-1),i+=t.doc.resolve(i).node().nodeSize-1):i+=1;for(const r of e)t.tr.setNodeAttribute(r,"textAlignment",o);return!0}}}}),tn=g.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:T.textColor.default,parseHTML:o=>o.hasAttribute("data-text-color")?o.getAttribute("data-text-color"):T.textColor.default,renderHTML:o=>o.textColor!==T.textColor.default&&{"data-text-color":o.textColor}}}}]},addCommands(){return{setBlockTextColor:(o,t)=>({state:e,view:n})=>{const i=v(e.doc,o);return i===void 0?!1:(e.tr.setNodeAttribute(i.startPos-1,"textColor",t),n.focus(),!0)}}}}),en=g.Mark.create({name:"textColor",addAttributes(){return{color:{default:void 0,parseHTML:o=>o.getAttribute("data-text-color"),renderHTML:o=>({"data-text-color":o.color})}}},parseHTML(){return[{tag:"span",getAttrs:o=>typeof o=="string"?!1:o.hasAttribute("data-text-color")?{color:o.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:o}){return["span",o,0]},addCommands(){return{setTextColor:o=>({commands:t})=>o!==T.textColor.default?t.setMark(this.name,{color:o}):t.unsetMark(this.name)}}}),nn=g.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const o=new b.PluginKey(this.name);return[new b.Plugin({key:o,appendTransaction:(t,e,n)=>{const{doc:i,tr:r,schema:s}=n,l=o.getState(n),a=i.content.size-2,d=s.nodes.blockContainer,c=s.nodes.paragraph;if(l)return r.insert(a,d.create(void 0,c.create()))},state:{init:(t,e)=>{},apply:(t,e)=>{if(!t.docChanged)return e;let n=t.doc.lastChild;if(!n||n.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(n=n.lastChild,!n||n.type.name!=="blockContainer")throw new Error("Expected blockContainer");const i=n.firstChild;if(!i)throw new Error("Expected blockContent");return n.nodeSize>4||i.type.spec.content!=="inline*"}}})]}}),Pt=o=>{var e;const t=[g.extensions.ClipboardTextSerializer,g.extensions.Commands,g.extensions.Editable,g.extensions.FocusEvents,g.extensions.Tabindex,de.Gapcursor,Ze.configure({emptyNodeClass:y.isEmpty,hasAnchorClass:y.hasAnchor,isFilterClass:y.isFilter,includeChildren:!0,showOnlyCurrent:!1}),q.configure({types:["blockContainer"]}),ce.HardBreak,fe.Text,H.Bold,re.Code,pe.Italic,me.Strike,ge.Underline,he.Link,en,tn,Ne,Pe,Qe,je,We.configure({domAttributes:o.domAttributes}),Ge.configure({domAttributes:o.domAttributes}),...Object.values(o.blockSchema).map(n=>n.node.configure({editor:o.editor,domAttributes:o.domAttributes})),_t,le.Dropcursor.configure({width:5,color:"#ddeeff"}),nn];if(o.collaboration){if(t.push(Te.default.configure({fragment:o.collaboration.fragment})),(e=o.collaboration.provider)!=null&&e.awareness){const n=i=>{const r=document.createElement("span");r.classList.add(O["collaboration-cursor__caret"]),r.setAttribute("style",`border-color: ${i.color}`);const s=document.createElement("span");s.classList.add(O["collaboration-cursor__label"]),s.setAttribute("style",`background-color: ${i.color}`),s.insertBefore(document.createTextNode(i.name),null);const l=document.createTextNode(""),a=document.createTextNode("");return r.insertBefore(l,null),r.insertBefore(s,null),r.insertBefore(a,null),r};t.push(Be.default.configure({user:o.collaboration.user,render:o.collaboration.renderCursor||n,provider:o.collaboration.provider}))}}else t.push(ue.History);return t};function j(o,t){let e,n;if(t.firstChild.descendants((i,r)=>e?!1:i.type.name!=="blockContainer"||i.attrs.id!==o?!0:(e=i,n=r+1,!1)),e===void 0||n===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:e,posBeforeNode:n}}function Nt(o,t,e="before",n){const i=typeof t=="string"?t:t.id,r=[];for(const d of o)r.push(F(d,n.schema));let s=-1;const{node:l,posBeforeNode:a}=j(i,n.state.doc);if(e==="before"&&(s=a),e==="after"&&(s=a+l.nodeSize),e==="nested"){if(l.childCount<2){s=a+l.firstChild.nodeSize+1;const d=n.state.schema.nodes.blockGroup.create({},r);n.view.dispatch(n.state.tr.insert(s,d));return}s=a+l.firstChild.nodeSize+2}n.view.dispatch(n.state.tr.insert(s,r))}function on(o,t,e){const n=typeof o=="string"?o:o.id,{posBeforeNode:i}=j(n,e.state.doc);e.commands.BNUpdateBlock(i+1,t)}function Ht(o,t){const e=new Set(o.map(i=>typeof i=="string"?i:i.id));let n=0;if(t.state.doc.descendants((i,r)=>{if(e.size===0)return!1;if(i.type.name!=="blockContainer"||!e.has(i.attrs.id))return!0;e.delete(i.attrs.id);const s=t.state.doc.nodeSize;t.commands.BNDeleteBlock(r-n+1);const l=t.state.doc.nodeSize;return n+=s-l,!1}),e.size>0){const i=[...e].join(`
|
|
6
|
-
`);throw Error("Blocks with the following IDs could not be found in the editor: "+i)}}function
|
|
7
|
-
`:"",n={};t.lang&&(n["data-language"]=t.lang);let i={type:"element",tagName:"code",properties:n,children:[{type:"text",value:e}]};return t.meta&&(i.data={meta:t.meta}),o.patch(t,i),i=o.applyData(t,i),i={type:"element",tagName:"pre",properties:{},children:[i]},o.patch(t,i),i}async function cn(o,t,e){const n=await W.unified().use(_e.default).use(et.default).use(Ie.default,{handlers:{...J.defaultHandlers,code:dn}}).use(tt.default).process(o);return Dt(n.value,t,e)}function K(o){return"data-"+o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function Ot(o){const t={};return Object.entries(o.propSchema).forEach(([e,n])=>{t[e]={default:n.default,keepOnSplit:!0,parseHTML:i=>{const r=i.getAttribute(K(e));if(r===null)return null;if(typeof n.default=="boolean")return r==="true"?!0:r==="false"?!1:null;if(typeof n.default=="number"){const s=parseFloat(r);return!Number.isNaN(s)&&Number.isFinite(s)?s:null}return r},renderHTML:i=>i[e]!==n.default?{[K(e)]:i[e]}:{}}}),t}function Rt(o){return[{tag:"div[data-content-type="+o.type+"]"}]}function zt(o,t){const e=document.createElement("div");e.setAttribute("data-content-type",o.type);for(const[i,r]of Object.entries(t))e.setAttribute(i,r);let n;return o.containsInlineContent?(n=document.createElement("div"),e.appendChild(n)):n=void 0,n!==void 0?{dom:e,contentDOM:n}:{dom:e}}function Vt(o){return{node:R({name:o.type,content:o.containsInlineContent?"inline*":"",selectable:!0,addAttributes(){return Ot(o)},parseHTML(){return Rt(o)},renderHTML({HTMLAttributes:e}){return zt(o,e)},addNodeView(){return({HTMLAttributes:e,getPos:n})=>{var p,k;const i=document.createElement("div"),r=((p=this.options.domAttributes)==null?void 0:p.blockContent)||{};for(const[w,E]of Object.entries(r))w!=="class"&&i.setAttribute(w,E);i.className=x(y.blockContent,r.class),i.setAttribute("data-content-type",o.type);for(const[w,E]of Object.entries(e))i.setAttribute(w,E);const s=this.options.editor;if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const l=n(),c=s._tiptapEditor.state.doc.resolve(l).node().attrs.id,m=s.getBlock(c);if(m.type!==o.type)throw new Error("Block type does not match");const h=o.render(m,s);if(o.containsInlineContent){const w=h.contentDOM,E=((k=this.options.domAttributes)==null?void 0:k.inlineContent)||{};for(const[B,M]of Object.entries(E))B!=="class"&&w.setAttribute(B,M);w.className=x(w.className,y.inlineContent,E.class)}return i.appendChild(h.dom),"contentDOM"in h?{dom:i,contentDOM:h.contentDOM,destroy:h.destroy}:{dom:i,destroy:h.destroy}}}}),propSchema:o.propSchema}}function R(o){return g.Node.create({...o,group:"blockContent",content:o.content})}const un={...T,level:{default:1,values:[1,2,3]}},pn={node:R({name:"heading",content:"inline*",addAttributes(){return{level:{default:1,parseHTML:o=>o.getAttribute("data-level"),renderHTML:o=>({"data-level":o.level.toString()})}}},addInputRules(){return[...[1,2,3].map(o=>new g.InputRule({find:new RegExp(`^(#{${o}})\\s$`),handler:({state:t,chain:e,range:n})=>{e().BNUpdateBlock(t.selection.from,{type:"heading",props:{level:o}}).deleteRange({from:n.from,to:n.to})}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:1}}),"Mod-Alt-2":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:2}}),"Mod-Alt-3":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:3}})}},parseHTML(){return[{tag:"h1",attrs:{level:1},node:"heading"},{tag:"h2",attrs:{level:2},node:"heading"},{tag:"h3",attrs:{level:3},node:"heading"}]},renderHTML({node:o,HTMLAttributes:t}){var i,r;const e=((i=this.options.domAttributes)==null?void 0:i.blockContent)||{},n=((r=this.options.domAttributes)==null?void 0:r.inlineContent)||{};return["div",g.mergeAttributes(t,{...e,class:x(y.blockContent,e.class),"data-content-type":this.name}),[`h${o.attrs.level}`,{...n,class:x(y.inlineContent,n.class)},0]]}}),propSchema:un},Ft=o=>{const{node:t,contentType:e}=v(o.state.doc,o.state.selection.from),n=o.state.selection.anchor===o.state.selection.head;return!e.name.endsWith("ListItem")||!n?!1:o.commands.first(({state:i,chain:r,commands:s})=>[()=>s.command(()=>t.textContent.length===0?s.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>t.textContent.length>0?(r().deleteSelection().BNSplitBlock(i.selection.from,!0).run(),!0):!1)])},hn={...T},mn={node:R({name:"bulletListItem",content:"inline*",addInputRules(){return[new g.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:o,chain:t,range:e})=>{t().BNUpdateBlock(o.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Ft(this.editor),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}})}},parseHTML(){return[{tag:"li",getAttrs:o=>{if(typeof o=="string")return!1;const t=o.parentElement;return t===null?!1:t.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:o=>{if(typeof o=="string")return!1;const t=o.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:o}){var n,i;const t=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},e=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",g.mergeAttributes(o,{...t,class:x(y.blockContent,t.class),"data-content-type":this.name}),["p",{...e,class:x(y.inlineContent,e.class)},0]]}}),propSchema:hn},fn=new b.PluginKey("numbered-list-indexing"),gn=()=>new b.Plugin({key:fn,appendTransaction:(o,t,e)=>{const n=e.tr;n.setMeta("numberedListIndexing",!0);let i=!1;return e.doc.descendants((r,s)=>{if(r.type.name==="blockContainer"&&r.firstChild.type.name==="numberedListItem"){let l="1";const a=s===1,d=v(n.doc,s+1);if(d===void 0)return;if(!a){const h=v(n.doc,s-2);if(h===void 0)return;if(!(d.depth!==h.depth)){const k=h.contentNode;if(h.contentType.name==="numberedListItem"){const B=k.attrs.index;l=(parseInt(B)+1).toString()}}}d.contentNode.attrs.index!==l&&(i=!0,n.setNodeMarkup(s+1,void 0,{index:l}))}}),i?n:null}}),kn={...T},bn={node:R({name:"numberedListItem",content:"inline*",addAttributes(){return{index:{default:null,parseHTML:o=>o.getAttribute("data-index"),renderHTML:o=>({"data-index":o.index})}}},addInputRules(){return[new g.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:o,chain:t,range:e})=>{t().BNUpdateBlock(o.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>Ft(this.editor),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[gn()]},parseHTML(){return[{tag:"li",getAttrs:o=>{if(typeof o=="string")return!1;const t=o.parentElement;return t===null?!1:t.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:o=>{if(typeof o=="string")return!1;const t=o.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:o}){var n,i;const t=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},e=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",g.mergeAttributes(o,{...t,class:x(y.blockContent,t.class),"data-content-type":this.name}),["p",{...e,class:x(y.inlineContent,e.class)},0]]}}),propSchema:kn},yn={...T},vn={node:R({name:"paragraph",content:"inline*",parseHTML(){return[{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:o}){var n,i;const t=((n=this.options.domAttributes)==null?void 0:n.blockContent)||{},e=((i=this.options.domAttributes)==null?void 0:i.inlineContent)||{};return["div",g.mergeAttributes({...t,class:x(y.blockContent,t.class),"data-content-type":this.name},o),["p",{...e,class:x(y.inlineContent,e.class)},0]]}}),propSchema:yn};class Ut{constructor(t,e,n){u(this,"imageToolbarState");u(this,"updateImageToolbar");u(this,"prevWasEditable",null);u(this,"shouldShow",t=>"node"in t.selection&&t.selection.node.type.name==="image"&&t.selection.node.attrs.src==="");u(this,"mouseDownHandler",()=>{var t;(t=this.imageToolbarState)!=null&&t.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});u(this,"dragstartHandler",()=>{var t;(t=this.imageToolbarState)!=null&&t.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});u(this,"blurHandler",t=>{var n;const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(n=this.imageToolbarState)!=null&&n.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});u(this,"scrollHandler",()=>{var t;if((t=this.imageToolbarState)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.imageToolbarState.block.id}"]`);this.imageToolbarState.referencePos=e.getBoundingClientRect(),this.updateImageToolbar()}});this.pluginKey=t,this.pmView=e,this.updateImageToolbar=()=>{if(!this.imageToolbarState)throw new Error("Attempting to update uninitialized image toolbar");n(this.imageToolbarState)},e.dom.addEventListener("mousedown",this.mouseDownHandler),e.dom.addEventListener("dragstart",this.dragstartHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var i,r;const n=this.pluginKey.getState(t.state);if(!((i=this.imageToolbarState)!=null&&i.show)&&n.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${n.block.id}"]`);this.imageToolbarState={show:!0,referencePos:s.getBoundingClientRect(),block:n.block},this.updateImageToolbar();return}(!t.state.selection.eq(e.selection)||!t.state.doc.eq(e.doc))&&(r=this.imageToolbarState)!=null&&r.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}}const z=new b.PluginKey("ImageToolbarPlugin");class qt extends U{constructor(e){super();u(this,"view");u(this,"plugin");this.plugin=new b.Plugin({key:z,view:n=>(this.view=new Ut(z,n,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:n=>{var r;return{block:(r=n.getMeta(z))==null?void 0:r.block}}}})}onUpdate(e){return this.on("update",e)}}const wn={textAlignment:T.textAlignment,backgroundColor:T.backgroundColor,url:{default:""},caption:{default:""},width:{default:512}},$t=o=>{switch(o){case"left":return"flex-start";case"center":return"center";case"right":return"flex-end";default:return"flex-start"}},Wt=64,Cn=Vt({type:"image",propSchema:wn,containsInlineContent:!1,render:(o,t)=>{const e=document.createElement("div");e.className=y.wrapper,e.style.alignItems=$t(o.props.textAlignment);const n=document.createElement("div");n.className=y.addImageButton,n.style.display=o.props.url===""?"":"none";const i=document.createElement("div");i.className=y.addImageButtonIcon;const r=document.createElement("p");r.className=y.addImageButtonText,r.innerText="Add Image";const s=document.createElement("div");s.className=y.imageAndCaptionWrapper,s.style.display=o.props.url!==""?"":"none";const l=document.createElement("div");l.className=y.imageWrapper,l.style.display=o.props.url!==""?"":"none";const a=document.createElement("img");a.className=y.image,a.src=o.props.url,a.alt="placeholder",a.contentEditable="false",a.draggable=!1,a.style.width=`${Math.min(o.props.width,t.domElement.firstElementChild.clientWidth)}px`;const d=document.createElement("div");d.className=y.resizeHandle,d.style.left="4px";const c=document.createElement("div");c.className=y.resizeHandle,c.style.right="4px";const m=document.createElement("p");m.className=y.caption,m.innerText=o.props.caption,m.style.padding=o.props.caption?"4px":"";const h=()=>{var Y;const C=((Y=t.getSelection())==null?void 0:Y.blocks)||[];[t.getTextCursorPosition().block,...C].find(An=>An.id===o.id)!==void 0?(n.style.outline="4px solid rgb(100, 160, 255)",s.style.outline="4px solid rgb(100, 160, 255)"):(n.style.outline="",s.style.outline="")};t.onEditorContentChange(h),t.onEditorSelectionChange(h);let p;const k=C=>{if(!p)return;let _;$t(o.props.textAlignment)==="center"?p.handleUsed==="left"?_=p.initialWidth+(p.initialClientX-C.clientX)*2:_=p.initialWidth+(C.clientX-p.initialClientX)*2:p.handleUsed==="left"?_=p.initialWidth+p.initialClientX-C.clientX:_=p.initialWidth+C.clientX-p.initialClientX,_<Wt?a.style.width=`${Wt}px`:_>t.domElement.firstElementChild.clientWidth?a.style.width=`${t.domElement.firstElementChild.clientWidth}px`:a.style.width=`${_}px`},w=C=>{p&&((!C.target||!l.contains(C.target))&&l.contains(d)&&l.contains(c)&&(d.style.display="none",c.style.display="none"),p=void 0,t.updateBlock(o,{type:"image",props:{width:parseFloat(a.style.width.slice(0,-2))}}))},E=C=>{C.preventDefault()},B=()=>{t._tiptapEditor.view.dispatch(t._tiptapEditor.state.tr.setMeta(z,{block:o}))},M=C=>{C.preventDefault(),d.style.display="block",c.style.display="block",p={handleUsed:"left",initialWidth:o.props.width,initialClientX:C.clientX}},D=C=>{C.preventDefault(),d.style.display="block",c.style.display="block",p={handleUsed:"right",initialWidth:o.props.width,initialClientX:C.clientX}};return e.appendChild(n),n.appendChild(i),n.appendChild(r),e.appendChild(s),s.appendChild(l),l.appendChild(a),l.appendChild(d),l.appendChild(c),s.appendChild(m),window.addEventListener("mousemove",k),window.addEventListener("mouseup",w),n.addEventListener("mousedown",E),n.addEventListener("click",B),d.addEventListener("mousedown",M),c.addEventListener("mousedown",D),{dom:e,destroy:()=>{window.removeEventListener("mousemove",k),window.removeEventListener("mouseup",w),n.removeEventListener("mousedown",E),n.removeEventListener("click",B),d.removeEventListener("mousedown",M),c.removeEventListener("mousedown",D)}}}}),X={paragraph:vn,heading:pn,bulletListItem:mn,numberedListItem:bn,image:Cn};class Gt{constructor(t,e,n){u(this,"formattingToolbarState");u(this,"updateFormattingToolbar");u(this,"preventHide",!1);u(this,"preventShow",!1);u(this,"prevWasEditable",null);u(this,"shouldShow",({view:t,state:e,from:n,to:i})=>{const{doc:r,selection:s}=e,{empty:l}=s,a=!r.textBetween(n,i).length&&g.isTextSelection(e.selection);return!(!t.hasFocus()||l||a)});u(this,"viewMousedownHandler",()=>{this.preventShow=!0});u(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});u(this,"dragstartHandler",()=>{var t;(t=this.formattingToolbarState)!=null&&t.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});u(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});u(this,"blurHandler",t=>{var n;if(this.preventHide){this.preventHide=!1;return}const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(n=this.formattingToolbarState)!=null&&n.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});u(this,"scrollHandler",()=>{var t;(t=this.formattingToolbarState)!=null&&t.show&&(this.formattingToolbarState.referencePos=this.getSelectionBoundingBox(),this.updateFormattingToolbar())});this.editor=t,this.pmView=e,this.updateFormattingToolbar=()=>{if(!this.formattingToolbarState)throw new Error("Attempting to update uninitialized formatting toolbar");n(this.formattingToolbarState)},e.dom.addEventListener("mousedown",this.viewMousedownHandler),e.dom.addEventListener("mouseup",this.viewMouseupHandler),e.dom.addEventListener("dragstart",this.dragstartHandler),e.dom.addEventListener("focus",this.focusHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var h,p;const{state:n,composing:i}=t,{doc:r,selection:s}=n,l=e&&e.doc.eq(r)&&e.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(i||l))return;this.prevWasEditable=this.editor.isEditable;const{ranges:a}=s,d=Math.min(...a.map(k=>k.$from.pos)),c=Math.max(...a.map(k=>k.$to.pos)),m=(h=this.shouldShow)==null?void 0:h.call(this,{view:t,state:n,from:d,to:c});if(this.editor.isEditable&&!this.preventShow&&(m||this.preventHide)){this.formattingToolbarState={show:!0,referencePos:this.getSelectionBoundingBox()},this.updateFormattingToolbar();return}if((p=this.formattingToolbarState)!=null&&p.show&&!this.preventHide&&(!m||this.preventShow||!this.editor.isEditable)){this.formattingToolbarState.show=!1,this.updateFormattingToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("focus",this.focusHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}getSelectionBoundingBox(){const{state:t}=this.pmView,{selection:e}=t,{ranges:n}=e,i=Math.min(...n.map(s=>s.$from.pos)),r=Math.max(...n.map(s=>s.$to.pos));if(g.isNodeSelection(e)){const s=this.pmView.nodeDOM(i);if(s)return s.getBoundingClientRect()}return g.posToDOMRect(this.pmView,i,r)}}const jt=new b.PluginKey("FormattingToolbarPlugin");class Kt extends U{constructor(e){super();u(this,"view");u(this,"plugin");this.plugin=new b.Plugin({key:jt,view:n=>(this.view=new Gt(e,n,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class En{constructor(t,e,n){u(this,"hyperlinkToolbarState");u(this,"updateHyperlinkToolbar");u(this,"menuUpdateTimer");u(this,"startMenuUpdateTimer");u(this,"stopMenuUpdateTimer");u(this,"mouseHoveredHyperlinkMark");u(this,"mouseHoveredHyperlinkMarkRange");u(this,"keyboardHoveredHyperlinkMark");u(this,"keyboardHoveredHyperlinkMarkRange");u(this,"hyperlinkMark");u(this,"hyperlinkMarkRange");u(this,"mouseOverHandler",t=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),t.target instanceof HTMLAnchorElement&&t.target.nodeName==="A"){const e=t.target,n=this.pmView.posAtDOM(e,0)+1,i=this.pmView.state.doc.resolve(n),r=i.marks();for(const s of r)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=g.getMarkRange(i,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});u(this,"clickHandler",t=>{var n;const e=this.pmView.dom.parentElement;this.hyperlinkMark&&t&&t.target&&!(e===t.target||e.contains(t.target))&&(n=this.hyperlinkToolbarState)!=null&&n.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())});u(this,"scrollHandler",()=>{var t;this.hyperlinkMark!==void 0&&(t=this.hyperlinkToolbarState)!=null&&t.show&&(this.hyperlinkToolbarState.referencePos=g.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),this.updateHyperlinkToolbar())});this.editor=t,this.pmView=e,this.updateHyperlinkToolbar=()=>{if(!this.hyperlinkToolbarState)throw new Error("Attempting to update uninitialized hyperlink toolbar");n(this.hyperlinkToolbarState)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),document.addEventListener("click",this.clickHandler,!0),document.addEventListener("scroll",this.scrollHandler)}editHyperlink(t,e){var i;const n=this.pmView.state.tr.insertText(e,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);n.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+e.length,this.pmView.state.schema.mark("link",{href:t})),this.pmView.dispatch(n),this.pmView.focus(),(i=this.hyperlinkToolbarState)!=null&&i.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}deleteHyperlink(){var t;this.pmView.dispatch(this.pmView.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(t=this.hyperlinkToolbarState)!=null&&t.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}update(){var e;if(!this.pmView.hasFocus())return;const t=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.pmView.state.selection.empty){const n=this.pmView.state.selection.$from.marks();for(const i of n)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=i,this.keyboardHoveredHyperlinkMarkRange=g.getMarkRange(this.pmView.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark&&this.editor.isEditable){this.hyperlinkToolbarState={show:!0,referencePos:g.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),url:this.hyperlinkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)},this.updateHyperlinkToolbar();return}if((e=this.hyperlinkToolbarState)!=null&&e.show&&t&&(!this.hyperlinkMark||!this.editor.isEditable)){this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const Xt=new b.PluginKey("HyperlinkToolbarPlugin");class Yt extends U{constructor(e){super();u(this,"view");u(this,"plugin");u(this,"editHyperlink",(e,n)=>{this.view.editHyperlink(e,n)});u(this,"deleteHyperlink",()=>{this.view.deleteHyperlink()});u(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});u(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new b.Plugin({key:Xt,view:n=>(this.view=new En(e,n,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class V extends b.Selection{constructor(e,n){super(e,n);u(this,"nodes");const i=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,n.pos,(r,s,l)=>{if(l!==null&&l.eq(i))return this.nodes.push(r),!1})}static create(e,n,i=n){return new V(e.resolve(n),e.resolve(i))}content(){return new S.Slice(S.Fragment.from(this.nodes),0,0)}eq(e){if(!(e instanceof V)||this.nodes.length!==e.nodes.length||this.from!==e.from||this.to!==e.to)return!1;for(let n=0;n<this.nodes.length;n++)if(!this.nodes[n].eq(e.nodes[n]))return!1;return!0}map(e,n){const i=n.mapResult(this.from),r=n.mapResult(this.to);return r.deleted?b.Selection.near(e.resolve(i.pos)):i.deleted?b.Selection.near(e.resolve(r.pos)):new V(e.resolve(i.pos),e.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}const Sn=xe.__serializeForClipboard;let N;function Jt(o,t){var i;if(!t.dom.isConnected)return;const e=t.posAtCoords(o);if(!e)return;let n=t.domAtPos(e.pos).node;if(n!==t.dom){for(;n&&n.parentNode&&n.parentNode!==t.dom&&!((i=n.hasAttribute)!=null&&i.call(n,"data-id"));)n=n.parentNode;if(n)return{node:n,id:n.getAttribute("data-id")}}}function Tn(o,t){const e=Jt(o,t);if(e&&e.node.nodeType===1){const n=t.docView,i=n.nearestDesc(e.node,!0);return!i||i===n?null:i.posBefore}return null}function Bn(o,t){let e,n;const i=t.resolve(o.from).node().type.spec.group==="blockContent",r=t.resolve(o.to).node().type.spec.group==="blockContent",s=Math.min(o.$anchor.depth,o.$head.depth);if(i&&r){const l=o.$from.start(s-1),a=o.$to.end(s-1);e=t.resolve(l-1).pos,n=t.resolve(a+1).pos}else e=o.from,n=o.to;return{from:e,to:n}}function Zt(o,t,e=t){t===e&&(e+=o.state.doc.resolve(t+1).node().nodeSize);const n=o.domAtPos(t).node.cloneNode(!0),i=o.domAtPos(t).node,r=(c,m)=>Array.prototype.indexOf.call(c.children,m),s=r(i,o.domAtPos(t+1).node.parentElement),l=r(i,o.domAtPos(e-1).node.parentElement);for(let c=i.childElementCount-1;c>=0;c--)(c>l||c<s)&&n.removeChild(n.children[c]);Qt(),N=n;const d=o.dom.className.split(" ").filter(c=>!c.includes("bn")&&!c.includes("ProseMirror")&&!c.includes("editor")).join(" ");N.className=N.className+" "+O.dragPreview+" "+d,document.body.appendChild(N)}function Qt(){N!==void 0&&(document.body.removeChild(N),N=void 0)}function xn(o,t){if(!o.dataTransfer)return;const e=t.dom.getBoundingClientRect(),n={left:e.left+e.width/2,top:o.clientY},i=Tn(n,t);if(i!=null){const r=t.state.selection,s=t.state.doc,{from:l,to:a}=Bn(r,s),d=l<=i&&i<a,c=r.$anchor.node()!==r.$head.node()||r instanceof V;d&&c?(t.dispatch(t.state.tr.setSelection(V.create(s,l,a))),Zt(t,l,a)):(t.dispatch(t.state.tr.setSelection(b.NodeSelection.create(t.state.doc,i))),Zt(t,i));const m=t.state.selection.content(),{dom:h,text:p}=Sn(t,m);o.dataTransfer.clearData(),o.dataTransfer.setData("text/html",h.innerHTML),o.dataTransfer.setData("text/plain",p),o.dataTransfer.effectAllowed="move",o.dataTransfer.setDragImage(N,0,0),t.dragging={slice:m,move:!0}}}class te{constructor(t,e,n){u(this,"sideMenuState");u(this,"horizontalPosAnchoredAtRoot");u(this,"horizontalPosAnchor");u(this,"hoveredBlock");u(this,"isDragging",!1);u(this,"menuFrozen",!1);u(this,"onDragStart",()=>{this.isDragging=!0});u(this,"onDrop",t=>{if(this.editor._tiptapEditor.commands.blur(),t.synthetic||!this.isDragging)return;const e=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(this.isDragging=!1,!e||e.inside===-1){const n=new Event("drop",t),i=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=i.left+i.width/2,n.clientY=t.clientY,n.dataTransfer=t.dataTransfer,n.preventDefault=()=>t.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}});u(this,"onDragOver",t=>{if(t.synthetic||!this.isDragging)return;const e=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(!e||e.inside===-1){const n=new Event("dragover",t),i=this.pmView.dom.firstChild.getBoundingClientRect();n.clientX=i.left+i.width/2,n.clientY=t.clientY,n.dataTransfer=t.dataTransfer,n.preventDefault=()=>t.preventDefault(),n.synthetic=!0,this.pmView.dom.dispatchEvent(n)}});u(this,"onKeyDown",t=>{var e;(e=this.sideMenuState)!=null&&e.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});u(this,"onMouseMove",t=>{var d,c,m,h,p;if(this.menuFrozen)return;const e=this.pmView.dom.firstChild.getBoundingClientRect(),n=this.pmView.dom.getBoundingClientRect(),i=t.clientX>=n.left&&t.clientX<=n.right&&t.clientY>=n.top&&t.clientY<=n.bottom,r=this.pmView.dom.parentElement;if(i&&t&&t.target&&!(r===t.target||r.contains(t.target))){(d=this.sideMenuState)!=null&&d.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}this.horizontalPosAnchor=e.x;const s={left:e.left+e.width/2,top:t.clientY},l=Jt(s,this.pmView);if(!l||!this.editor.isEditable){(c=this.sideMenuState)!=null&&c.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}if((m=this.sideMenuState)!=null&&m.show&&((h=this.hoveredBlock)!=null&&h.hasAttribute("data-id"))&&((p=this.hoveredBlock)==null?void 0:p.getAttribute("data-id"))===l.id)return;this.hoveredBlock=l.node;const a=l.node.firstChild;if(a&&this.editor.isEditable){const k=a.getBoundingClientRect();this.sideMenuState={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:k.x,k.y,k.width,k.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateSideMenu(this.sideMenuState)}});u(this,"onScroll",()=>{var t;if((t=this.sideMenuState)!=null&&t.show){const n=this.hoveredBlock.firstChild.getBoundingClientRect();this.sideMenuState.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:n.x,n.y,n.width,n.height),this.updateSideMenu(this.sideMenuState)}});this.editor=t,this.pmView=e,this.updateSideMenu=n,this.horizontalPosAnchoredAtRoot=!0,this.horizontalPosAnchor=this.pmView.dom.firstChild.getBoundingClientRect().x,document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),this.pmView.dom.addEventListener("dragstart",this.onDragStart),document.body.addEventListener("mousemove",this.onMouseMove,!0),document.addEventListener("scroll",this.onScroll),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){var t;(t=this.sideMenuState)!=null&&t.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),document.body.removeEventListener("mousemove",this.onMouseMove),document.body.removeEventListener("dragover",this.onDragOver),this.pmView.dom.removeEventListener("dragstart",this.onDragStart),document.body.removeEventListener("drop",this.onDrop,!0),document.removeEventListener("scroll",this.onScroll),document.body.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var l;(l=this.sideMenuState)!=null&&l.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!0;const e=this.hoveredBlock.firstChild.getBoundingClientRect(),n=this.pmView.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});if(!n)return;const i=v(this.editor._tiptapEditor.state.doc,n.pos);if(i===void 0)return;const{contentNode:r,endPos:s}=i;if(r.textContent.length!==0){const a=s+1,d=a+2;this.editor._tiptapEditor.chain().BNCreateBlock(a).BNUpdateBlock(d,{type:"paragraph",props:{}}).setTextSelection(d).run()}else this.editor._tiptapEditor.commands.setTextSelection(s);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta($,{activate:!0,type:"drag"}))}}const ee=new b.PluginKey("SideMenuPlugin");class ne extends U{constructor(e){super();u(this,"sideMenuView");u(this,"plugin");u(this,"addBlock",()=>this.sideMenuView.addBlock());u(this,"blockDragStart",e=>{this.sideMenuView.isDragging=!0,xn(e,this.editor.prosemirrorView)});u(this,"blockDragEnd",()=>Qt());u(this,"freezeMenu",()=>this.sideMenuView.menuFrozen=!0);u(this,"unfreezeMenu",()=>this.sideMenuView.menuFrozen=!1);this.editor=e,this.plugin=new b.Plugin({key:ee,view:n=>(this.sideMenuView=new te(e,n,i=>{this.emit("update",i)}),this.sideMenuView)})}onUpdate(e){return this.on("update",e)}}function L(o,t){const e=o.getTextCursorPosition().block;if(e.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain inline content.");e.content.length===1&&e.content[0].type==="text"&&e.content[0].text==="/"||e.content.length===0?o.updateBlock(e,t):(o.insertBlocks([t],e,"after"),o.setTextCursorPosition(o.getTextCursorPosition().nextBlock))}const oe=(o=X)=>{var e,n,i;const t=[];return"heading"in o&&"level"in o.heading.propSchema&&((e=o.heading.propSchema.level.values)!=null&&e.includes(1)&&t.push({name:"Heading",aliases:["h","heading1","h1"],execute:r=>L(r,{type:"heading",props:{level:1}})}),(n=o.heading.propSchema.level.values)!=null&&n.includes(2)&&t.push({name:"Heading 2",aliases:["h2","heading2","subheading"],execute:r=>L(r,{type:"heading",props:{level:2}})}),(i=o.heading.propSchema.level.values)!=null&&i.includes(3)&&t.push({name:"Heading 3",aliases:["h3","heading3","subheading"],execute:r=>L(r,{type:"heading",props:{level:3}})})),"bulletListItem"in o&&t.push({name:"Bullet List",aliases:["ul","list","bulletlist","bullet list"],execute:r=>L(r,{type:"bulletListItem"})}),"numberedListItem"in o&&t.push({name:"Numbered List",aliases:["li","list","numberedlist","numbered list"],execute:r=>L(r,{type:"numberedListItem"})}),"paragraph"in o&&t.push({name:"Paragraph",aliases:["p"],execute:r=>L(r,{type:"paragraph"})}),"image"in o&&t.push({name:"Image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],execute:r=>{L(r,{type:"image"}),r.setTextCursorPosition(r.getTextCursorPosition().nextBlock,"start"),r._tiptapEditor.view.dispatch(r._tiptapEditor.state.tr.setMeta(z,{block:r.getTextCursorPosition().prevBlock}))}}),t},Mn={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class _n{constructor(t={}){u(this,"_tiptapEditor");u(this,"blockCache",new WeakMap);u(this,"schema");u(this,"ready",!1);u(this,"sideMenu");u(this,"formattingToolbar");u(this,"slashMenu");u(this,"hyperlinkToolbar");u(this,"imageToolbar");u(this,"uploadFile");var l,a,d,c,m;this.options=t;const e={defaultStyles:!0,blockSchema:t.blockSchema||X,...t};this.sideMenu=new ne(this),this.formattingToolbar=new Kt(this),this.slashMenu=new At(this,e.slashMenuItems||oe(e.blockSchema)),this.hyperlinkToolbar=new Yt(this),this.imageToolbar=new qt(this);const n=Pt({editor:this,domAttributes:e.domAttributes||{},blockSchema:e.blockSchema,collaboration:e.collaboration}),i=g.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.sideMenu.plugin,this.formattingToolbar.plugin,this.slashMenu.plugin,this.hyperlinkToolbar.plugin,this.imageToolbar.plugin]});n.push(i),this.schema=e.blockSchema,this.uploadFile=e.uploadFile;const r=e.initialContent||(t.collaboration?void 0:[{type:"paragraph",id:q.options.generateID()}]),s={...Mn,...e._tiptapOptions,onBeforeCreate(h){if(!r)return;const p=h.editor.schema,k=p.node("doc",void 0,p.node("blockGroup",void 0,[F({id:"initialBlock",type:"paragraph"},p)]));h.editor.options.content=k.toJSON()},onCreate:()=>{var h;r!==void 0&&this.replaceBlocks(this.topLevelBlocks,r),(h=e.onEditorReady)==null||h.call(e,this),this.ready=!0},onUpdate:()=>{var h;this.ready&&((h=e.onEditorContentChange)==null||h.call(e,this))},onSelectionUpdate:()=>{var h;this.ready&&((h=e.onTextCursorPositionChange)==null||h.call(e,this))},editable:t.editable===void 0?!0:t.editable,extensions:e.enableBlockNoteExtensions===!1?(l=e._tiptapOptions)==null?void 0:l.extensions:[...((a=e._tiptapOptions)==null?void 0:a.extensions)||[],...n],editorProps:{attributes:{...(d=e.domAttributes)==null?void 0:d.editor,class:x(O.bnEditor,O.bnRoot,e.defaultStyles?O.defaultStyles:"",((m=(c=e.domAttributes)==null?void 0:c.editor)==null?void 0:m.class)||"")}}};e.parentElement&&(s.element=e.parentElement),this._tiptapEditor=new g.Editor(s)}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){return this._tiptapEditor.view.dom}isFocused(){return this._tiptapEditor.view.hasFocus()}focus(){this._tiptapEditor.view.focus()}get topLevelBlocks(){const t=[];return this._tiptapEditor.state.doc.firstChild.descendants(e=>(t.push(P(e,this.schema,this.blockCache)),!1)),t}getBlock(t){const e=typeof t=="string"?t:t.id;let n;return this._tiptapEditor.state.doc.firstChild.descendants(i=>typeof n<"u"?!1:i.type.name!=="blockContainer"||i.attrs.id!==e?!0:(n=P(i,this.schema,this.blockCache),!1)),n}forEachBlock(t,e=!1){const n=this.topLevelBlocks.slice();e&&n.reverse();function i(r){for(const s of r){if(!t(s))return!1;const l=e?s.children.slice().reverse():s.children;if(!i(l))return!1}return!0}i(n)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){const{node:t,depth:e,startPos:n,endPos:i}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),r=this._tiptapEditor.state.doc.resolve(i).index(e-1),s=this._tiptapEditor.state.doc.resolve(i+1).node().childCount;let l;r>0&&(l=this._tiptapEditor.state.doc.resolve(n-2).node());let a;return r<s-1&&(a=this._tiptapEditor.state.doc.resolve(i+2).node()),{block:P(t,this.schema,this.blockCache),prevBlock:l===void 0?void 0:P(l,this.schema,this.blockCache),nextBlock:a===void 0?void 0:P(a,this.schema,this.blockCache)}}setTextCursorPosition(t,e="start"){const n=typeof t=="string"?t:t.id,{posBeforeNode:i}=j(n,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=v(this._tiptapEditor.state.doc,i+2);if(s.type.spec.content===""){this._tiptapEditor.commands.setNodeSelection(r);return}e==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-1)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to||"node"in this._tiptapEditor.state.selection)return;const t=[];return this._tiptapEditor.state.doc.descendants((e,n)=>e.type.spec.group!=="blockContent"||n+e.nodeSize<this._tiptapEditor.state.selection.from||n>this._tiptapEditor.state.selection.to?!0:(t.push(P(this._tiptapEditor.state.doc.resolve(n).node(),this.schema,this.blockCache)),!1)),{blocks:t}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(t){this._tiptapEditor.setEditable(t)}insertBlocks(t,e,n="before"){Nt(t,e,n,this._tiptapEditor)}updateBlock(t,e){on(t,e,this._tiptapEditor)}removeBlocks(t){Ht(t,this._tiptapEditor)}replaceBlocks(t,e){rn(t,e,this._tiptapEditor)}getActiveStyles(){const t={},e=this._tiptapEditor.state.selection.$to.marks(),n=new Set(["bold","italic","underline","strike","code"]),i=new Set(["textColor","backgroundColor"]);for(const r of e)n.has(r.type.name)?t[r.type.name]=!0:i.has(r.type.name)&&(t[r.type.name]=r.attrs.color);return t}addStyles(t){const e=new Set(["bold","italic","underline","strike","code"]),n=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[i,r]of Object.entries(t))e.has(i)?this._tiptapEditor.commands.setMark(i):n.has(i)&&this._tiptapEditor.commands.setMark(i,{color:r})}removeStyles(t){this._tiptapEditor.view.focus();for(const e of Object.keys(t))this._tiptapEditor.commands.unsetMark(e)}toggleStyles(t){const e=new Set(["bold","italic","underline","strike","code"]),n=new Set(["textColor","backgroundColor"]);this._tiptapEditor.view.focus();for(const[i,r]of Object.entries(t))e.has(i)?this._tiptapEditor.commands.toggleMark(i):n.has(i)&&this._tiptapEditor.commands.toggleMark(i,{color:r})}getSelectedText(){return this._tiptapEditor.state.doc.textBetween(this._tiptapEditor.state.selection.from,this._tiptapEditor.state.selection.to)}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,e){if(t==="")return;const{from:n,to:i}=this._tiptapEditor.state.selection;e||(e=this._tiptapEditor.state.doc.textBetween(n,i));const r=this._tiptapEditor.schema.mark("link",{href:t});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(e,n,i).addMark(n,n+e.length,r))}canNestBlock(){const{startPos:t,depth:e}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(t).index(e-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:t}=v(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return t>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTML(t){return Lt(t,this._tiptapEditor.schema)}async HTMLToBlocks(t){return Dt(t,this.schema,this._tiptapEditor.schema)}async blocksToMarkdown(t){return ln(t,this._tiptapEditor.schema)}async markdownToBlocks(t){return cn(t,this.schema,this._tiptapEditor.schema)}updateCollaborationUserInfo(t){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(t)}}const In=async o=>{const t=new FormData;return t.append("file",o),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:t})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")};f.BlockNoteEditor=_n,f.CustomBlockSerializerExtension=_t,f.FormattingToolbarProsemirrorPlugin=Kt,f.FormattingToolbarView=Gt,f.HyperlinkToolbarProsemirrorPlugin=Yt,f.ImageToolbarProsemirrorPlugin=qt,f.ImageToolbarView=Ut,f.SideMenuProsemirrorPlugin=ne,f.SideMenuView=te,f.SlashMenuProsemirrorPlugin=At,f.UnreachableCaseError=it,f.blockStyles=Fe,f.camelToDataKebab=K,f.createBlockSpec=Vt,f.createTipTapBlock=R,f.defaultBlockSchema=X,f.defaultProps=T,f.formatKeyboardShortcut=De,f.formattingToolbarPluginKey=jt,f.getBlockNoteExtensions=Pt,f.getDefaultSlashMenuItems=oe,f.hyperlinkToolbarPluginKey=Xt,f.imageToolbarPluginKey=z,f.isAppleOS=ot,f.mergeCSSClasses=x,f.parse=Rt,f.propsToAttributes=Ot,f.render=zt,f.setupSuggestionsMenu=It,f.sideMenuPluginKey=ee,f.slashMenuPluginKey=$,f.uploadToTmpFilesDotOrg_DEV_ONLY=In,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(c,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("prosemirror-model"),require("rehype-parse"),require("rehype-stringify"),require("unified"),require("@tiptap/core"),require("prosemirror-state"),require("uuid"),require("hast-util-from-dom"),require("@tiptap/extension-bold"),require("@tiptap/extension-code"),require("@tiptap/extension-italic"),require("@tiptap/extension-strike"),require("@tiptap/extension-underline"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("prosemirror-tables"),require("rehype-remark"),require("remark-gfm"),require("remark-stringify"),require("remark-parse"),require("remark-rehype"),require("prosemirror-view"),require("@tiptap/extension-collaboration"),require("@tiptap/extension-collaboration-cursor"),require("@tiptap/extension-dropcursor"),require("@tiptap/extension-gapcursor"),require("@tiptap/extension-hard-break"),require("@tiptap/extension-history"),require("@tiptap/extension-link"),require("@tiptap/extension-text"),require("prosemirror-tables/style/tables.css")):typeof define=="function"&&define.amd?define(["exports","prosemirror-model","rehype-parse","rehype-stringify","unified","@tiptap/core","prosemirror-state","uuid","hast-util-from-dom","@tiptap/extension-bold","@tiptap/extension-code","@tiptap/extension-italic","@tiptap/extension-strike","@tiptap/extension-underline","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","prosemirror-tables","rehype-remark","remark-gfm","remark-stringify","remark-parse","remark-rehype","prosemirror-view","@tiptap/extension-collaboration","@tiptap/extension-collaboration-cursor","@tiptap/extension-dropcursor","@tiptap/extension-gapcursor","@tiptap/extension-hard-break","@tiptap/extension-history","@tiptap/extension-link","@tiptap/extension-text","prosemirror-tables/style/tables.css"],k):(c=typeof globalThis<"u"?globalThis:c||self,k(c.blocknote={},c.prosemirrorModel,c.rehypeParse,c.rehypeStringify,c.unified,c.core,c.prosemirrorState,c.uuid,c.hastUtilFromDom,c.Bold,c.Code,c.Italic,c.Strike,c.Underline,c.extensionTableCell,c.extensionTableHeader,c.extensionTableRow,c.prosemirrorTables,c.rehypeRemark,c.remarkGfm,c.remarkStringify,c.remarkParse,c.remarkRehype,c.prosemirrorView,c.Collaboration,c.CollaborationCursor,c.extensionDropcursor,c.extensionGapcursor,c.extensionHardBreak,c.extensionHistory,c.extensionLink,c.extensionText))})(this,function(c,k,V,Lt,le,b,y,At,Ne,Dt,_t,Ot,Rt,Ft,zt,Vt,Ut,Le,qt,$t,Gt,jt,Ae,N,Kt,Wt,Xt,Jt,Yt,Zt,Qt,en){"use strict";var Ro=Object.defineProperty;var Fo=(c,k,V)=>k in c?Ro(c,k,{enumerable:!0,configurable:!0,writable:!0,value:V}):c[k]=V;var p=(c,k,V)=>(Fo(c,typeof k!="symbol"?k+"":k,V),V);const I=n=>n&&typeof n=="object"&&"default"in n?n:{default:n},De=I(V),_e=I(Lt),tn=I(Dt),nn=I(_t),on=I(Ot),rn=I(Rt),sn=I(Ft),an=I(qt),Oe=I($t),ln=I(Gt),dn=I(jt),cn=I(Ae),un=I(Kt),pn=I(Wt);function hn(n,t=JSON.stringify){const e={};return n.filter(o=>{const i=t(o);return Object.prototype.hasOwnProperty.call(e,i)?!1:e[i]=!0})}function mn(n){const t=n.filter((o,i)=>n.indexOf(o)!==i);return hn(t)}const $=b.Extension.create({name:"uniqueID",priority:1e4,addOptions(){return{attributeName:"id",types:[],generateID:()=>{if(typeof window<"u"&&window.__TEST_OPTIONS){const n=window.__TEST_OPTIONS;return n.mockID===void 0?n.mockID=0:n.mockID++,n.mockID.toString()}return At.v4()},filterTransaction:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{[this.options.attributeName]:{default:null,parseHTML:n=>n.getAttribute(`data-${this.options.attributeName}`),renderHTML:n=>({[`data-${this.options.attributeName}`]:n[this.options.attributeName]})}}}]},addProseMirrorPlugins(){let n=null,t=!1;return[new y.Plugin({key:new y.PluginKey("uniqueID"),appendTransaction:(e,o,i)=>{const r=e.some(g=>g.docChanged)&&!o.doc.eq(i.doc),s=this.options.filterTransaction&&e.some(g=>{let E,M;return!(!((M=(E=this.options).filterTransaction)===null||M===void 0)&&M.call(E,g))});if(!r||s)return;const{tr:a}=i,{types:l,attributeName:d,generateID:u}=this.options,h=b.combineTransactionSteps(o.doc,e),{mapping:f}=h;if(b.getChangedRanges(h).forEach(({newRange:g})=>{const E=b.findChildrenInRange(i.doc,g,S=>l.includes(S.type.name)),M=E.map(({node:S})=>S.attrs[d]).filter(S=>S!==null),x=mn(M);E.forEach(({node:S,pos:w})=>{let C;const B=(C=a.doc.nodeAt(w))===null||C===void 0?void 0:C.attrs[d];if(B===null){const Y=o.doc.type.createAndFill().content;if(o.doc.content.findDiffStart(Y)===null){const q=JSON.parse(JSON.stringify(i.doc.toJSON()));if(q.content[0].content[0].attrs.id="initialBlockId",JSON.stringify(q.content)===JSON.stringify(Y.toJSON())){a.setNodeMarkup(w,void 0,{...S.attrs,[d]:"initialBlockId"});return}}a.setNodeMarkup(w,void 0,{...S.attrs,[d]:u()});return}const{deleted:v}=f.invert().mapResult(w);v&&x.includes(B)&&a.setNodeMarkup(w,void 0,{...S.attrs,[d]:u()})})}),!!a.steps.length)return a},view(e){const o=i=>{let r;n=!((r=e.dom.parentElement)===null||r===void 0)&&r.contains(i.target)?e.dom.parentElement:null};return window.addEventListener("dragstart",o),{destroy(){window.removeEventListener("dragstart",o)}}},props:{handleDOMEvents:{drop:(e,o)=>{let i;return(n!==e.dom.parentElement||((i=o.dataTransfer)===null||i===void 0?void 0:i.effectAllowed)==="copy")&&(n=null,t=!0),!1},paste:()=>(t=!0,!1)},transformPasted:e=>{if(!t)return e;const{types:o,attributeName:i}=this.options,r=s=>{const a=[];return s.forEach(l=>{if(l.isText){a.push(l);return}if(!o.includes(l.type.name)){a.push(l.copy(r(l.content)));return}const d=l.type.create({...l.attrs,[i]:null},r(l.content),l.marks);a.push(d)}),k.Fragment.from(a)};return t=!1,new k.Slice(r(e.content),e.openStart,e.openEnd)}}})]}});function Re(n){const t=n.attrs.id,e=n.firstChild,o=e.type,i=n.childCount===2?n.lastChild.childCount:0;return{id:t,node:n,contentNode:e,contentType:o,numChildBlocks:i}}function T(n,t){const o=n.nodeSize-2;if(t<=1)for(t=1+1;n.resolve(t).parent.type.name!=="blockContainer"&&t<o;)t++;else if(t>=o)for(t=o-1;n.resolve(t).parent.type.name!=="blockContainer"&&t>1;)t--;n.resolve(t).parent.type.name==="blockGroup"&&t++;const i=n.resolve(t),r=i.depth;let s=i.node(r),a=r;for(;;){if(a<0)throw new Error("Could not find blockContainer node. This can only happen if the underlying BlockNote schema has been edited.");if(s.type.name==="blockContainer")break;a-=1,s=i.node(a)}const{id:l,contentNode:d,contentType:u,numChildBlocks:h}=Re(s),f=i.start(a),m=i.end(a);return{id:l,node:s,contentNode:d,contentType:u,numChildBlocks:h,startPos:f,endPos:m,depth:a}}function de(n){return n.type==="link"}function ce(n){return typeof n!="string"&&n.type==="link"}function G(n){return typeof n!="string"&&n.type==="text"}class A extends Error{constructor(t){super(`Unreachable case: ${t}`)}}function Fe(n,t,e){const o=[];for(const[i,r]of Object.entries(n.styles)){const s=e[i];if(!s)throw new Error(`style ${i} not found in styleSchema`);if(s.propSchema==="boolean")o.push(t.mark(i));else if(s.propSchema==="string")o.push(t.mark(i,{stringValue:r}));else throw new A(s.propSchema)}return n.text.split(/(\n)/g).filter(i=>i.length>0).map(i=>i===`
|
|
2
|
+
`?t.nodes.hardBreak.create():t.text(i,o))}function fn(n,t,e){const o=t.marks.link.create({href:n.href});return ue(n.content,t,e).map(i=>{if(i.type.name==="text")return i.mark([...i.marks,o]);if(i.type.name==="hardBreak")return i;throw new Error("unexpected node type")})}function ue(n,t,e){const o=[];if(typeof n=="string")return o.push(...Fe({type:"text",text:n,styles:{}},t,e)),o;for(const i of n)o.push(...Fe(i,t,e));return o}function ne(n,t,e){const o=[];for(const i of n)typeof i=="string"?o.push(...ue(i,t,e)):ce(i)?o.push(...fn(i,t,e)):G(i)?o.push(...ue([i],t,e)):o.push(ze(i,t,e));return o}function pe(n,t,e){const o=[];for(const i of n.rows){const r=[];for(const a of i.cells){let l;if(!a)l=t.nodes.tableParagraph.create({});else if(typeof a=="string")l=t.nodes.tableParagraph.create({},t.text(a));else{const u=ne(a,t,e);l=t.nodes.tableParagraph.create({},u)}const d=t.nodes.tableCell.create({},l);r.push(d)}const s=t.nodes.tableRow.create({},r);o.push(s)}return o}function ze(n,t,e){let o,i=n.type;if(i===void 0&&(i="paragraph"),!t.nodes[i])throw new Error(`node type ${i} not found in schema`);if(!n.content)o=t.nodes[i].create(n.props);else if(typeof n.content=="string")o=t.nodes[i].create(n.props,t.text(n.content));else if(Array.isArray(n.content)){const r=ne(n.content,t,e);o=t.nodes[i].create(n.props,r)}else if(n.content.type==="tableContent"){const r=pe(n.content,t,e);o=t.nodes[i].create(n.props,r)}else throw new A(n.content.type);return o}function _(n,t,e){let o=n.id;o===void 0&&(o=$.options.generateID());const i=ze(n,t,e),r=[];if(n.children)for(const a of n.children)r.push(_(a,t,e));const s=t.nodes.blockGroup.create({},r);return t.nodes.blockContainer.create({id:o,...n.props},r.length>0?[i,s]:i)}function gn(n,t,e){const o={type:"tableContent",rows:[]};return n.content.forEach(i=>{const r={cells:[]};i.content.forEach(s=>{r.cells.push(oe(s.firstChild,t,e))}),o.rows.push(r)}),o}function oe(n,t,e){const o=[];let i;return n.content.forEach(r=>{if(r.type.name==="hardBreak"){if(i)if(G(i))i.text+=`
|
|
3
|
+
`;else if(de(i))i.content[i.content.length-1].text+=`
|
|
4
|
+
`;else throw new Error("unexpected");else i={type:"text",text:`
|
|
5
|
+
`,styles:{}};return}if(r.type.name!=="link"&&r.type.name!=="text"&&t[r.type.name]){i&&(o.push(i),i=void 0),o.push(he(r,t,e));return}const s={};let a;for(const l of r.marks)if(l.type.name==="link")a=l;else{const d=e[l.type.name];if(!d)throw new Error(`style ${l.type.name} not found in styleSchema`);if(d.propSchema==="boolean")s[d.type]=!0;else if(d.propSchema==="string")s[d.type]=l.attrs.stringValue;else throw new A(d.propSchema)}i?G(i)?a?(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):JSON.stringify(i.styles)===JSON.stringify(s)?i.text+=r.textContent:(o.push(i),i={type:"text",text:r.textContent,styles:s}):de(i)&&(a?i.href===a.attrs.href?JSON.stringify(i.content[i.content.length-1].styles)===JSON.stringify(s)?i.content[i.content.length-1].text+=r.textContent:i.content.push({type:"text",text:r.textContent,styles:s}):(o.push(i),i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}):(o.push(i),i={type:"text",text:r.textContent,styles:s})):a?i={type:"link",href:a.attrs.href,content:[{type:"text",text:r.textContent,styles:s}]}:i={type:"text",text:r.textContent,styles:s}}),i&&o.push(i),o}function he(n,t,e){if(n.type.name==="text"||n.type.name==="link")throw new Error("unexpected");const o={},i=t[n.type.name];for(const[a,l]of Object.entries(n.attrs)){if(!i)throw Error("ic node is of an unrecognized type: "+n.type.name);const d=i.propSchema;a in d&&(o[a]=l)}let r;return i.content==="styled"?r=oe(n,t,e):r=void 0,{type:n.type.name,props:o,content:r}}function L(n,t,e,o,i){if(n.type.name!=="blockContainer")throw Error("Node must be of type blockContainer, but is of type"+n.type.name+".");const r=i==null?void 0:i.get(n);if(r)return r;const s=Re(n);let a=s.id;a===null&&(a=$.options.generateID());const l={};for(const[m,g]of Object.entries({...n.attrs,...s.contentNode.attrs})){const E=t[s.contentType.name];if(!E)throw Error("Block is of an unrecognized type: "+s.contentType.name);const M=E.propSchema;m in M&&(l[m]=g)}const d=t[s.contentType.name],u=[];for(let m=0;m<s.numChildBlocks;m++)u.push(L(n.lastChild.child(m),t,e,o,i));let h;if(d.content==="inline")h=oe(s.contentNode,e,o);else if(d.content==="table")h=gn(s.contentNode,e,o);else if(d.content==="none")h=void 0;else throw new A(d.content);const f={id:a,type:d.type,props:l,content:h,children:u};return i==null||i.set(n,f),f}function bn(n){return n.document||window.document}const Ve=(n,t,e,o,i)=>{if(!e.nodes[n.type.name])throw new Error("Serializer is missing a node type: "+n.type.name);const{dom:r,contentDOM:s}=k.DOMSerializer.renderSpec(bn(t),e.nodes[n.type.name](n));if(s){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");if(n.type.name==="blockContainer"){const a=n.childCount>0&&n.firstChild.type.spec.group==="blockContent"?n.firstChild:void 0,l=n.childCount>0&&n.lastChild.type.spec.group==="blockGroup"?n.lastChild:void 0;if(a!==void 0){const d=o.blockImplementations[a.type.name].implementation,h=(i?d.toExternalHTML:d.toInternalHTML)(L(n,o.blockSchema,o.inlineContentSchema,o.styleSchema,o.blockCache),o);if(h.contentDOM!==void 0){if(n.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");h.contentDOM.appendChild(e.serializeFragment(a.content,t))}s.appendChild(h.dom)}l!==void 0&&e.serializeFragment(k.Fragment.from(l),t,s)}else e.serializeFragment(n.content,t,s)}return r},Ue=(n,t)=>{const e=t.serializeFragment(n),o=document.createElement("div");return o.appendChild(e),o.innerHTML};function yn(n){const t=new Set([...n.orderedListItemBlockTypes,...n.unorderedListItemBlockTypes]),e=o=>{var s;if(o.children.length===1&&((s=o.children[0].properties)==null?void 0:s.dataNodeType)==="blockGroup"){const a=o.children[0];o.children.pop(),o.children.push(...a.children)}let i=o.children.length,r;for(let a=0;a<i;a++){const d=o.children[a].children[0],u=d.children[0],h=d.children.length===2?d.children[1]:null,f=t.has(u.properties.dataContentType),m=f?n.orderedListItemBlockTypes.has(u.properties.dataContentType)?"ol":"ul":null;if(h!==null&&e(h),r&&r.tagName!==m){o.children.splice(a-r.children.length,r.children.length,r);const g=r.children.length-1;a-=g,i-=g,r=void 0}if(f){r||(r=Ne.fromDom(document.createElement(m)));const g=Ne.fromDom(document.createElement("li"));g.children.push(u.children[0]),h!==null&&g.children.push(...h.children),r.children.push(g)}else if(h!==null){o.children.splice(a+1,0,...h.children),o.children[a]=u.children[0];const g=h.children.length;a+=g,i+=g}else o.children[a]=u.children[0]}r&&o.children.splice(i-r.children.length,r.children.length,r)};return e}const Z=(n,t)=>{const e=k.DOMSerializer.fromSchema(n);return e.serializeNodeInner=(o,i)=>Ve(o,i,e,t,!0),e.exportProseMirrorFragment=o=>le.unified().use(De.default,{fragment:!0}).use(yn,{orderedListItemBlockTypes:new Set(["numberedListItem"]),unorderedListItemBlockTypes:new Set(["bulletListItem"])}).use(_e.default).processSync(Ue(o,e)).value,e.exportBlocks=o=>{const i=o.map(s=>_(s,n,t.styleSchema)),r=n.nodes.blockGroup.create(null,i);return e.exportProseMirrorFragment(k.Fragment.from(r))},e},me=(n,t)=>{const e=k.DOMSerializer.fromSchema(n);return e.serializeNodeInner=(o,i)=>Ve(o,i,e,t,!1),e.serializeProseMirrorFragment=o=>Ue(o,e),e.serializeBlocks=o=>{const i=o.map(s=>_(s,n,t.styleSchema)),r=n.nodes.blockGroup.create(null,i);return e.serializeProseMirrorFragment(k.Fragment.from(r))},e},kn=async n=>{const t=new FormData;return t.append("file",n),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:t})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")},qe=()=>typeof navigator<"u"&&(/Mac/.test(navigator.platform)||/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent));function wn(n){return qe()?n.replace("Mod","⌘"):n.replace("Mod","Ctrl")}function O(...n){return n.filter(t=>t).join(" ")}function Q(n,t,e,o){const i=document.createElement("div");i.className=O("bn-block-content",e.class),i.setAttribute("data-content-type",n);for(const[s,a]of Object.entries(e))s!=="class"&&i.setAttribute(s,a);const r=document.createElement(t);r.className=O("bn-inline-content",o.class);for(const[s,a]of Object.entries(o))s!=="class"&&r.setAttribute(s,a);return i.appendChild(r),{dom:i,contentDOM:r}}const $e=(n,t)=>{const e=_(n,t._tiptapEditor.schema,t.styleSchema).firstChild,o=t._tiptapEditor.schema.nodes[e.type.name].spec.toDOM;if(o===void 0)throw new Error("This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`.");const i=o(e);if(typeof i!="object"||!("dom"in i))throw new Error("Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property.");return i},P={backgroundColor:{default:"default"},textColor:{default:"default"},textAlignment:{default:"left",values:["left","center","right","justify"]}},fe=["backgroundColor","textColor"];function ee(n){return"data-"+n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function ge(n){const t={};return Object.entries(n).filter(([e,o])=>!fe.includes(e)).forEach(([e,o])=>{t[e]={default:o.default,keepOnSplit:!0,parseHTML:i=>{const r=i.getAttribute(ee(e));if(r===null)return null;if(typeof o.default=="boolean")return r==="true"?!0:r==="false"?!1:null;if(typeof o.default=="number"){const s=parseFloat(r);return!Number.isNaN(s)&&Number.isFinite(s)?s:null}return r},renderHTML:i=>i[e]!==o.default?{[ee(e)]:i[e]}:{}}}),t}function Ge(n,t,e,o){if(typeof n=="boolean")throw new Error("Cannot find node position as getPos is a boolean, not a function.");const i=n(),s=e.state.doc.resolve(i).node().attrs.id,a=t.getBlock(s);if(a.type!==o)throw new Error("Block type does not match");return a}function ie(n,t,e,o,i){const r=document.createElement("div");if(i!==void 0)for(const[s,a]of Object.entries(i))s!=="class"&&r.setAttribute(s,a);r.className=O("bn-block-content",(i==null?void 0:i.class)||""),r.setAttribute("data-content-type",t);for(const[s,a]of Object.entries(e))!fe.includes(s)&&a!==o[s].default&&r.setAttribute(ee(s),a);return r.appendChild(n.dom),n.contentDOM!==void 0&&(n.contentDOM.className=O("bn-inline-content",n.contentDOM.className),n.contentDOM.setAttribute("data-editable","")),{...n,dom:r}}function U(n){return b.Node.create(n)}function be(n,t){return{config:n,implementation:t}}function j(n,t,e){return be({type:n.name,content:n.config.content==="inline*"?"inline":n.config.content==="tableRow+"?"table":"none",propSchema:t},{node:n,requiredExtensions:e,toInternalHTML:$e,toExternalHTML:$e})}function ye(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function je(n,t){const e=[{tag:"[data-content-type="+n.type+"]",contentElement:"[data-editable]"}];return t&&e.push({tag:"*",getAttrs(o){if(typeof o=="string")return!1;const i=t==null?void 0:t(o);return i===void 0?!1:i}}),e}function Ke(n,t){const e=U({name:n.type,content:n.content==="inline"?"inline*":"",group:"blockContent",selectable:!0,addAttributes(){return ge(n.propSchema)},parseHTML(){return je(n,t.parse)},renderHTML(){const o=document.createElement("div");return o.setAttribute("data-tmp-placeholder","true"),{dom:o}},addNodeView(){return({getPos:o})=>{var l;const i=this.options.editor,r=Ge(o,i,this.editor,n.type),s=((l=this.options.domAttributes)==null?void 0:l.blockContent)||{},a=t.render(r,i);return ie(a,r.type,r.props,n.propSchema,s)}}});if(e.name!==n.type)throw new Error("Node name does not match block type. This is a bug in BlockNote.");return be(n,{node:e,toInternalHTML:(o,i)=>{var a;const r=((a=e.options.domAttributes)==null?void 0:a.blockContent)||{},s=t.render(o,i);return ie(s,o.type,o.props,n.propSchema,r)},toExternalHTML:(o,i)=>{var a,l;const r=((a=e.options.domAttributes)==null?void 0:a.blockContent)||{};let s=(l=t.toExternalHTML)==null?void 0:l.call(t,o,i);return s===void 0&&(s=t.render(o,i)),ie(s,o.type,o.props,n.propSchema,r)}})}function We(n,t,e,o){return n.dom.setAttribute("data-inline-content-type",t),Object.entries(e).filter(([i,r])=>r!==o[i].default).map(([i,r])=>[ee(i),r]).forEach(([i,r])=>n.dom.setAttribute(i,r)),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function Xe(n){return{Backspace:({editor:t})=>{const e=t.state.selection.$from;return t.state.selection.empty&&e.node().type.name===n.type&&e.parentOffset===0}}}function Je(n,t){return{config:n,implementation:t}}function Ye(n,t){return Je({type:n.name,propSchema:t,content:n.config.content==="inline*"?"styled":"none"},{node:n})}function ke(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function Ze(n){return[{tag:`[data-inline-content-type="${n.type}"]`,contentElement:t=>{const e=t;return e.matches("[data-editable]")?e:e.querySelector("[data-editable]")||e}}]}function vn(n,t){const e=b.Node.create({name:n.type,inline:!0,group:"inline",selectable:n.content==="styled",atom:n.content==="none",content:n.content==="styled"?"inline*":"",addAttributes(){return ge(n.propSchema)},addKeyboardShortcuts(){return Xe(n)},parseHTML(){return Ze(n)},renderHTML({node:o}){const i=this.options.editor,r=t.render(he(o,i.inlineContentSchema,i.styleSchema));return We(r,n.type,o.attrs,n.propSchema)}});return Ye(e,n.propSchema)}function Qe(n){return n==="boolean"?{}:{stringValue:{default:void 0,keepOnSplit:!0,parseHTML:t=>t.getAttribute("data-value"),renderHTML:t=>t.stringValue!==void 0?{"data-value":t.stringValue}:{}}}}function et(n,t,e,o){return n.dom.setAttribute("data-style-type",t),o==="string"&&n.dom.setAttribute("data-value",e),n.contentDOM!==void 0&&n.contentDOM.setAttribute("data-editable",""),n}function we(n,t){return{config:n,implementation:t}}function R(n,t){return we({type:n.name,propSchema:t},{mark:n})}function ve(n){return Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.config]))}function tt(n){return[{tag:`[data-style-type="${n.type}"]`,contentElement:t=>{const e=t;return e.matches("[data-editable]")?e:e.querySelector("[data-editable]")||e}}]}function Sn(n,t){const e=b.Mark.create({name:n.type,addAttributes(){return Qe(n.propSchema)},parseHTML(){return tt(n)},renderHTML({mark:o}){let i;if(n.propSchema==="boolean")i=t.render();else if(n.propSchema==="string")i=t.render(o.attrs.stringValue);else throw new A(n.propSchema);return et(i,n.type,o.attrs.stringValue,n.propSchema)}});return we(n,{mark:e})}const En=b.Mark.create({name:"backgroundColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-background-color"),renderHTML:n=>({"data-background-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-background-color")?{stringValue:n.getAttribute("data-background-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),Tn=R(En,"string"),Cn=b.Mark.create({name:"textColor",addAttributes(){return{stringValue:{default:void 0,parseHTML:n=>n.getAttribute("data-text-color"),renderHTML:n=>({"data-text-color":n.stringValue})}}},parseHTML(){return[{tag:"span",getAttrs:n=>typeof n=="string"?!1:n.hasAttribute("data-text-color")?{stringValue:n.getAttribute("data-text-color")}:!1}]},renderHTML({HTMLAttributes:n}){return["span",n,0]}}),Mn=R(Cn,"string"),xn={...P,level:{default:1,values:[1,2,3]}},Bn=U({name:"heading",content:"inline*",group:"blockContent",addAttributes(){return{level:{default:1,parseHTML:n=>{const t=n.getAttribute("data-level"),e=parseInt(t);if(isFinite(e))return e},renderHTML:n=>({"data-level":n.level.toString()})}}},addInputRules(){return[...[1,2,3].map(n=>new b.InputRule({find:new RegExp(`^(#{${n}})\\s$`),handler:({state:t,chain:e,range:o})=>{e().BNUpdateBlock(t.selection.from,{type:"heading",props:{level:n}}).deleteRange({from:o.from,to:o.to})}}))]},addKeyboardShortcuts(){return{"Mod-Alt-1":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:1}}),"Mod-Alt-2":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:2}}),"Mod-Alt-3":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"heading",props:{level:3}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]",getAttrs:n=>typeof n=="string"?!1:{level:n.getAttribute("data-level")}},{tag:"h1",attrs:{level:1},node:"heading"},{tag:"h2",attrs:{level:2},node:"heading"},{tag:"h3",attrs:{level:3},node:"heading"}]},renderHTML({node:n,HTMLAttributes:t}){var e,o;return Q(this.name,`h${n.attrs.level}`,{...((e=this.options.domAttributes)==null?void 0:e.blockContent)||{},...t},((o=this.options.domAttributes)==null?void 0:o.inlineContent)||{})}}),In=j(Bn,xn);class K{constructor(){p(this,"callbacks",{})}on(t,e){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(e),()=>this.off(t,e)}emit(t,...e){const o=this.callbacks[t];o&&o.forEach(i=>i.apply(this,e))}off(t,e){const o=this.callbacks[t];o&&(e?this.callbacks[t]=o.filter(i=>i!==e):delete this.callbacks[t])}removeAllListeners(){this.callbacks={}}}class nt{constructor(t,e,o){p(this,"imageToolbarState");p(this,"updateImageToolbar");p(this,"prevWasEditable",null);p(this,"mouseDownHandler",()=>{var t;(t=this.imageToolbarState)!=null&&t.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"dragstartHandler",()=>{var t;(t=this.imageToolbarState)!=null&&t.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"blurHandler",t=>{var o;const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(o=this.imageToolbarState)!=null&&o.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())});p(this,"scrollHandler",()=>{var t;if((t=this.imageToolbarState)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.imageToolbarState.block.id}"]`);this.imageToolbarState.referencePos=e.getBoundingClientRect(),this.updateImageToolbar()}});this.pluginKey=t,this.pmView=e,this.updateImageToolbar=()=>{if(!this.imageToolbarState)throw new Error("Attempting to update uninitialized image toolbar");o(this.imageToolbarState)},e.dom.addEventListener("mousedown",this.mouseDownHandler),e.dom.addEventListener("dragstart",this.dragstartHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var i,r;const o=this.pluginKey.getState(t.state);if(!((i=this.imageToolbarState)!=null&&i.show)&&o.block){const s=document.querySelector(`[data-node-type="blockContainer"][data-id="${o.block.id}"]`);this.imageToolbarState={show:!0,referencePos:s.getBoundingClientRect(),block:o.block},this.updateImageToolbar();return}(!t.state.selection.eq(e.selection)||!t.state.doc.eq(e.doc))&&(r=this.imageToolbarState)!=null&&r.show&&(this.imageToolbarState.show=!1,this.updateImageToolbar())}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseDownHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}}const W=new y.PluginKey("ImageToolbarPlugin");class ot extends K{constructor(e){super();p(this,"view");p(this,"plugin");this.plugin=new y.Plugin({key:W,view:o=>(this.view=new nt(W,o,i=>{this.emit("update",i)}),this.view),state:{init:()=>({block:void 0}),apply:o=>{var r;return{block:(r=o.getMeta(W))==null?void 0:r.block}}}})}onUpdate(e){return this.on("update",e)}}const Pn={textAlignment:P.textAlignment,backgroundColor:P.backgroundColor,url:{default:""},caption:{default:""},width:{default:512}},it=n=>{switch(n){case"left":return"flex-start";case"center":return"center";case"right":return"flex-end";default:return"flex-start"}},rt=64,Hn=Ke({type:"image",propSchema:Pn,content:"none"},{render:(n,t)=>{const e=document.createElement("div");e.className="bn-image-block-content-wrapper",e.style.alignItems=it(n.props.textAlignment);const o=document.createElement("div");o.className="bn-add-image-button",o.style.display=n.props.url===""?"":"none";const i=document.createElement("div");i.className="bn-add-image-button-icon";const r=document.createElement("p");r.className="bn-add-image-button-text",r.innerText="Add Image";const s=document.createElement("div");s.className="bn-image-and-caption-wrapper",s.style.display=n.props.url!==""?"":"none";const a=document.createElement("div");a.className="bn-image-wrapper",a.style.display=n.props.url!==""?"":"none";const l=document.createElement("img");l.className="bn-image",l.src=n.props.url,l.alt="placeholder",l.contentEditable="false",l.draggable=!1,l.style.width=`${Math.min(n.props.width,t.domElement.firstElementChild.clientWidth)}px`;const d=document.createElement("div");d.className="bn-image-resize-handle",d.style.left="4px";const u=document.createElement("div");u.className="bn-image-resize-handle",u.style.right="4px";const h=document.createElement("p");h.className="bn-image-caption",h.innerText=n.props.caption,h.style.padding=n.props.caption?"4px":"";const f=()=>{var te;const v=((te=t.getSelection())==null?void 0:te.blocks)||[];[t.getTextCursorPosition().block,...v].find(q=>q.id===n.id)!==void 0?(o.style.outline="4px solid rgb(100, 160, 255)",s.style.outline="4px solid rgb(100, 160, 255)"):(o.style.outline="",s.style.outline="")};t.onEditorContentChange(f),t.onEditorSelectionChange(f);let m;const g=v=>{if(!m)return;let H;it(n.props.textAlignment)==="center"?m.handleUsed==="left"?H=m.initialWidth+(m.initialClientX-v.clientX)*2:H=m.initialWidth+(v.clientX-m.initialClientX)*2:m.handleUsed==="left"?H=m.initialWidth+m.initialClientX-v.clientX:H=m.initialWidth+v.clientX-m.initialClientX,H<rt?l.style.width=`${rt}px`:H>t.domElement.firstElementChild.clientWidth?l.style.width=`${t.domElement.firstElementChild.clientWidth}px`:l.style.width=`${H}px`},E=v=>{m&&((!v.target||!a.contains(v.target))&&a.contains(d)&&a.contains(u)&&(d.style.display="none",u.style.display="none"),m=void 0,t.updateBlock(n,{type:"image",props:{width:parseFloat(l.style.width.slice(0,-2))}}))},M=v=>{v.preventDefault()},x=()=>{t._tiptapEditor.view.dispatch(t._tiptapEditor.state.tr.setMeta(W,{block:n}))},S=()=>{t.isEditable?(d.style.display="block",u.style.display="block"):(d.style.display="none",u.style.display="none")},w=v=>{v.relatedTarget===d||v.relatedTarget===u||m||(d.style.display="none",u.style.display="none")},C=v=>{v.preventDefault(),d.style.display="block",u.style.display="block",m={handleUsed:"left",initialWidth:n.props.width,initialClientX:v.clientX}},B=v=>{v.preventDefault(),d.style.display="block",u.style.display="block",m={handleUsed:"right",initialWidth:n.props.width,initialClientX:v.clientX}};return e.appendChild(o),o.appendChild(i),o.appendChild(r),e.appendChild(s),s.appendChild(a),a.appendChild(l),a.appendChild(d),a.appendChild(u),s.appendChild(h),window.addEventListener("mousemove",g),window.addEventListener("mouseup",E),o.addEventListener("mousedown",M),o.addEventListener("click",x),l.addEventListener("mouseenter",S),l.addEventListener("mouseleave",w),d.addEventListener("mousedown",C),u.addEventListener("mousedown",B),{dom:e,destroy:()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",E),o.removeEventListener("mousedown",M),o.removeEventListener("click",x),d.removeEventListener("mousedown",C),u.removeEventListener("mousedown",B)}}},toExternalHTML:n=>{if(n.props.url===""){const o=document.createElement("p");return o.innerHTML="Add Image",{dom:o}}const t=document.createElement("figure"),e=document.createElement("img");if(e.src=n.props.url,t.appendChild(e),n.props.caption!==""){const o=document.createElement("figcaption");o.innerHTML=n.props.caption,t.appendChild(o)}return{dom:t}},parse:n=>{if(n.tagName==="FIGURE"){const t=n.querySelector("img"),e=n.querySelector("figcaption");return{url:(t==null?void 0:t.getAttribute("src"))||"",caption:(e==null?void 0:e.textContent)||(t==null?void 0:t.getAttribute("alt"))||void 0}}else if(n.tagName==="IMG")return{url:n.getAttribute("src")||"",caption:n.getAttribute("alt")||void 0}}}),st=n=>{const{node:t,contentType:e}=T(n.state.doc,n.state.selection.from),o=n.state.selection.anchor===n.state.selection.head;return!e.name.endsWith("ListItem")||!o?!1:n.commands.first(({state:i,chain:r,commands:s})=>[()=>s.command(()=>t.textContent.length===0?s.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1),()=>s.command(()=>t.textContent.length>0?(r().deleteSelection().BNSplitBlock(i.selection.from,!0).run(),!0):!1)])},Nn={...P},Ln=U({name:"bulletListItem",content:"inline*",group:"blockContent",addInputRules(){return[new b.InputRule({find:new RegExp("^[-+*]\\s$"),handler:({state:n,chain:t,range:e})=>{t().BNUpdateBlock(n.selection.from,{type:"bulletListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>st(this.editor),"Mod-Shift-7":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"bulletListItem",props:{}})}},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.tagName==="UL"||t.tagName==="DIV"&&t.parentElement.tagName==="UL"?{}:!1},node:"bulletListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="bulletListItem"?{}:!1},priority:300,node:"bulletListItem"}]},renderHTML({HTMLAttributes:n}){var t,e;return Q(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),An=j(Ln,Nn),Dn=new y.PluginKey("numbered-list-indexing"),_n=()=>new y.Plugin({key:Dn,appendTransaction:(n,t,e)=>{const o=e.tr;o.setMeta("numberedListIndexing",!0);let i=!1;return e.doc.descendants((r,s)=>{if(r.type.name==="blockContainer"&&r.firstChild.type.name==="numberedListItem"){let a="1";const l=s===1,d=T(o.doc,s+1);if(d===void 0)return;if(!l){const f=T(o.doc,s-2);if(f===void 0)return;if(!(d.depth!==f.depth)){const g=f.contentNode;if(f.contentType.name==="numberedListItem"){const x=g.attrs.index;a=(parseInt(x)+1).toString()}}}d.contentNode.attrs.index!==a&&(i=!0,o.setNodeMarkup(s+1,void 0,{index:a}))}}),i?o:null}}),On={...P},Rn=U({name:"numberedListItem",content:"inline*",group:"blockContent",addAttributes(){return{index:{default:null,parseHTML:n=>n.getAttribute("data-index"),renderHTML:n=>({"data-index":n.index})}}},addInputRules(){return[new b.InputRule({find:new RegExp("^1\\.\\s$"),handler:({state:n,chain:t,range:e})=>{t().BNUpdateBlock(n.selection.from,{type:"numberedListItem",props:{}}).deleteRange({from:e.from,to:e.to})}})]},addKeyboardShortcuts(){return{Enter:()=>st(this.editor),"Mod-Shift-8":()=>this.editor.commands.BNUpdateBlock(this.editor.state.selection.anchor,{type:"numberedListItem",props:{}})}},addProseMirrorPlugins(){return[_n()]},parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"li",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.tagName==="OL"||t.tagName==="DIV"&&t.parentElement.tagName==="OL"?{}:!1},node:"numberedListItem"},{tag:"p",getAttrs:n=>{if(typeof n=="string")return!1;const t=n.parentElement;return t===null?!1:t.getAttribute("data-content-type")==="numberedListItem"?{}:!1},priority:300,node:"numberedListItem"}]},renderHTML({HTMLAttributes:n}){var t,e;return Q(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),Fn=j(Rn,On),zn={...P},Vn=U({name:"paragraph",content:"inline*",group:"blockContent",parseHTML(){return[{tag:"div[data-content-type="+this.name+"]"},{tag:"p",priority:200,node:"paragraph"}]},renderHTML({HTMLAttributes:n}){var t,e;return Q(this.name,"p",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),Un=j(Vn,zn),qn=b.Extension.create({name:"BlockNoteTableExtension",addProseMirrorPlugins:()=>[Le.columnResizing({cellMinWidth:100}),Le.tableEditing()],addKeyboardShortcuts(){return{Enter:()=>this.editor.state.selection.empty&&this.editor.state.selection.$head.parent.type.name==="tableParagraph"?(this.editor.commands.setHardBreak(),!0):!1,Backspace:()=>{const n=this.editor.state.selection,t=n.empty,e=n.$head.parentOffset===0,o=n.$head.node().type.name==="tableParagraph";return t&&e&&o}}},extendNodeSchema(n){const t={name:n.name,options:n.options,storage:n.storage};return{tableRole:b.callOrReturn(b.getExtensionField(n,"tableRole",t))}}}),$n={...P},Gn=U({name:"table",content:"tableRow+",group:"blockContent",tableRole:"table",isolating:!0,parseHTML(){return[{tag:"table"}]},renderHTML({HTMLAttributes:n}){var t,e;return Q(this.name,"table",{...((t=this.options.domAttributes)==null?void 0:t.blockContent)||{},...n},((e=this.options.domAttributes)==null?void 0:e.inlineContent)||{})}}),jn=b.Node.create({name:"tableParagraph",group:"tableContent",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",b.mergeAttributes(this.options.HTMLAttributes,n),0]}}),Kn=j(Gn,$n,[qn,jn,Vt.TableHeader.extend({content:"tableContent"}),zt.TableCell.extend({content:"tableContent"}),Ut.TableRow]),Se={paragraph:Un,heading:In,bulletListItem:An,numberedListItem:Fn,image:Hn,table:Kn},Ee=ye(Se),Te={bold:R(tn.default,"boolean"),italic:R(on.default,"boolean"),underline:R(sn.default,"boolean"),strike:R(rn.default,"boolean"),code:R(nn.default,"boolean"),textColor:Mn,backgroundColor:Tn},Wn=ve(Te),Ce={text:{config:"text",implementation:{}},link:{config:"link",implementation:{}}},Xn=ke(Ce);function Me(n,t){let e,o;if(t.firstChild.descendants((i,r)=>e?!1:i.type.name!=="blockContainer"||i.attrs.id!==n?!0:(e=i,o=r+1,!1)),e===void 0||o===void 0)throw Error("Could not find block in the editor with matching ID.");return{node:e,posBeforeNode:o}}function at(n,t,e="before",o){const i=o._tiptapEditor,r=typeof t=="string"?t:t.id,s=[];for(const u of n)s.push(_(u,i.schema,o.styleSchema));let a=-1;const{node:l,posBeforeNode:d}=Me(r,i.state.doc);if(e==="before"&&(a=d),e==="after"&&(a=d+l.nodeSize),e==="nested"){if(l.childCount<2){a=d+l.firstChild.nodeSize+1;const u=i.state.schema.nodes.blockGroup.create({},s);i.view.dispatch(i.state.tr.insert(a,u));return}a=d+l.firstChild.nodeSize+2}i.view.dispatch(i.state.tr.insert(a,s))}function Jn(n,t,e){const o=typeof n=="string"?n:n.id,{posBeforeNode:i}=Me(o,e.state.doc);e.commands.BNUpdateBlock(i+1,t)}function lt(n,t){const e=new Set(n.map(i=>typeof i=="string"?i:i.id));let o=0;if(t.state.doc.descendants((i,r)=>{if(e.size===0)return!1;if(i.type.name!=="blockContainer"||!e.has(i.attrs.id))return!0;e.delete(i.attrs.id);const s=t.state.doc.nodeSize;t.commands.BNDeleteBlock(r-o+1);const a=t.state.doc.nodeSize;return o+=s-a,!1}),e.size>0){const i=[...e].join(`
|
|
6
|
+
`);throw Error("Blocks with the following IDs could not be found in the editor: "+i)}}function Yn(n,t,e){at(t,n[0],"before",e),lt(n,e._tiptapEditor)}function Zn(){const n=t=>{let e=t.children.length;for(let o=0;o<e;o++){const i=t.children[o];if(i.type==="element"&&(n(i),i.tagName==="u"))if(i.children.length>0){t.children.splice(o,1,...i.children);const r=i.children.length-1;e+=r,o+=r}else t.children.splice(o,1),e--,o--}};return n}function xe(n){return le.unified().use(De.default,{fragment:!0}).use(Zn).use(an.default).use(Oe.default).use(ln.default).processSync(n).value}function Qn(n,t,e){const i=Z(t,e).exportBlocks(n);return xe(i)}function eo(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function to(n){return n.nodeType===3&&!/\S/.test(n.nodeValue||"")}function no(n){n.querySelectorAll("li > ul, li > ol").forEach(t=>{const e=eo(t),o=t.parentElement,i=Array.from(o.childNodes).slice(e+1);t.remove(),i.forEach(r=>{r.remove()}),o.insertAdjacentElement("afterend",t),i.reverse().forEach(r=>{if(to(r))return;const s=document.createElement("li");s.append(r),t.insertAdjacentElement("afterend",s)}),o.childNodes.length===0&&o.remove()})}function oo(n){n.querySelectorAll("li + ul, li + ol").forEach(t=>{var r,s;const e=t.previousElementSibling,o=document.createElement("div");e.insertAdjacentElement("afterend",o),o.append(e);const i=document.createElement("div");for(i.setAttribute("data-node-type","blockGroup"),o.append(i);((r=o.nextElementSibling)==null?void 0:r.nodeName)==="UL"||((s=o.nextElementSibling)==null?void 0:s.nodeName)==="OL";)i.append(o.nextElementSibling)})}function dt(n){if(typeof n=="string"){const t=document.createElement("div");t.innerHTML=n,n=t}return no(n),oo(n),n}async function ct(n,t,e,o,i){const r=dt(n),a=k.DOMParser.fromSchema(i).parse(r,{topNode:i.nodes.blockGroup.create()}),l=[];for(let d=0;d<a.childCount;d++)l.push(L(a.child(d),t,e,o));return l}function io(n,t){const e=t.value?t.value+`
|
|
7
|
+
`:"",o={};t.lang&&(o["data-language"]=t.lang);let i={type:"element",tagName:"code",properties:o,children:[{type:"text",value:e}]};return t.meta&&(i.data={meta:t.meta}),n.patch(t,i),i=n.applyData(t,i),i={type:"element",tagName:"pre",properties:{},children:[i]},n.patch(t,i),i}function ro(n,t,e,o,i){const r=le.unified().use(dn.default).use(Oe.default).use(cn.default,{handlers:{...Ae.defaultHandlers,code:io}}).use(_e.default).processSync(n);return ct(r.value,t,e,o,i)}class ut{constructor(t,e,o){p(this,"formattingToolbarState");p(this,"updateFormattingToolbar");p(this,"preventHide",!1);p(this,"preventShow",!1);p(this,"prevWasEditable",null);p(this,"shouldShow",({state:t})=>!t.selection.empty);p(this,"viewMousedownHandler",()=>{this.preventShow=!0});p(this,"viewMouseupHandler",()=>{this.preventShow=!1,setTimeout(()=>this.update(this.pmView))});p(this,"dragstartHandler",()=>{var t;(t=this.formattingToolbarState)!=null&&t.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});p(this,"focusHandler",()=>{setTimeout(()=>this.update(this.pmView))});p(this,"blurHandler",t=>{var o;if(this.preventHide){this.preventHide=!1;return}const e=this.pmView.dom.parentElement;t&&t.relatedTarget&&(e===t.relatedTarget||e.contains(t.relatedTarget))||(o=this.formattingToolbarState)!=null&&o.show&&(this.formattingToolbarState.show=!1,this.updateFormattingToolbar())});p(this,"scrollHandler",()=>{var t;(t=this.formattingToolbarState)!=null&&t.show&&(this.formattingToolbarState.referencePos=this.getSelectionBoundingBox(),this.updateFormattingToolbar())});this.editor=t,this.pmView=e,this.updateFormattingToolbar=()=>{if(!this.formattingToolbarState)throw new Error("Attempting to update uninitialized formatting toolbar");o(this.formattingToolbarState)},e.dom.addEventListener("mousedown",this.viewMousedownHandler),e.dom.addEventListener("mouseup",this.viewMouseupHandler),e.dom.addEventListener("dragstart",this.dragstartHandler),e.dom.addEventListener("focus",this.focusHandler),e.dom.addEventListener("blur",this.blurHandler),document.addEventListener("scroll",this.scrollHandler)}update(t,e){var f,m;const{state:o,composing:i}=t,{doc:r,selection:s}=o,a=e&&e.doc.eq(r)&&e.selection.eq(s);if((this.prevWasEditable===null||this.prevWasEditable===this.editor.isEditable)&&(i||a))return;this.prevWasEditable=this.editor.isEditable;const{ranges:l}=s,d=Math.min(...l.map(g=>g.$from.pos)),u=Math.max(...l.map(g=>g.$to.pos)),h=(f=this.shouldShow)==null?void 0:f.call(this,{view:t,state:o,from:d,to:u});if(this.editor.isEditable&&!this.preventShow&&(h||this.preventHide)){this.formattingToolbarState={show:!0,referencePos:this.getSelectionBoundingBox()},this.updateFormattingToolbar();return}if((m=this.formattingToolbarState)!=null&&m.show&&!this.preventHide&&(!h||this.preventShow||!this.editor.isEditable)){this.formattingToolbarState.show=!1,this.updateFormattingToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mousedown",this.viewMousedownHandler),this.pmView.dom.removeEventListener("mouseup",this.viewMouseupHandler),this.pmView.dom.removeEventListener("dragstart",this.dragstartHandler),this.pmView.dom.removeEventListener("focus",this.focusHandler),this.pmView.dom.removeEventListener("blur",this.blurHandler),document.removeEventListener("scroll",this.scrollHandler)}getSelectionBoundingBox(){const{state:t}=this.pmView,{selection:e}=t,{ranges:o}=e,i=Math.min(...o.map(s=>s.$from.pos)),r=Math.max(...o.map(s=>s.$to.pos));if(b.isNodeSelection(e)){const s=this.pmView.nodeDOM(i);if(s)return s.getBoundingClientRect()}return b.posToDOMRect(this.pmView,i,r)}}const pt=new y.PluginKey("FormattingToolbarPlugin");class ht extends K{constructor(e){super();p(this,"view");p(this,"plugin");this.plugin=new y.Plugin({key:pt,view:o=>(this.view=new ut(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}class so{constructor(t,e,o){p(this,"hyperlinkToolbarState");p(this,"updateHyperlinkToolbar");p(this,"menuUpdateTimer");p(this,"startMenuUpdateTimer");p(this,"stopMenuUpdateTimer");p(this,"mouseHoveredHyperlinkMark");p(this,"mouseHoveredHyperlinkMarkRange");p(this,"keyboardHoveredHyperlinkMark");p(this,"keyboardHoveredHyperlinkMarkRange");p(this,"hyperlinkMark");p(this,"hyperlinkMarkRange");p(this,"mouseOverHandler",t=>{if(this.mouseHoveredHyperlinkMark=void 0,this.mouseHoveredHyperlinkMarkRange=void 0,this.stopMenuUpdateTimer(),t.target instanceof HTMLAnchorElement&&t.target.nodeName==="A"){const e=t.target,o=this.pmView.posAtDOM(e,0)+1,i=this.pmView.state.doc.resolve(o),r=i.marks();for(const s of r)if(s.type.name===this.pmView.state.schema.mark("link").type.name){this.mouseHoveredHyperlinkMark=s,this.mouseHoveredHyperlinkMarkRange=b.getMarkRange(i,s.type,s.attrs)||void 0;break}}return this.startMenuUpdateTimer(),!1});p(this,"clickHandler",t=>{var o;const e=this.pmView.dom.parentElement;this.hyperlinkMark&&t&&t.target&&!(e===t.target||e.contains(t.target))&&(o=this.hyperlinkToolbarState)!=null&&o.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())});p(this,"scrollHandler",()=>{var t;this.hyperlinkMark!==void 0&&(t=this.hyperlinkToolbarState)!=null&&t.show&&(this.hyperlinkToolbarState.referencePos=b.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),this.updateHyperlinkToolbar())});this.editor=t,this.pmView=e,this.updateHyperlinkToolbar=()=>{if(!this.hyperlinkToolbarState)throw new Error("Attempting to update uninitialized hyperlink toolbar");o(this.hyperlinkToolbarState)},this.startMenuUpdateTimer=()=>{this.menuUpdateTimer=setTimeout(()=>{this.update()},250)},this.stopMenuUpdateTimer=()=>(this.menuUpdateTimer&&(clearTimeout(this.menuUpdateTimer),this.menuUpdateTimer=void 0),!1),this.pmView.dom.addEventListener("mouseover",this.mouseOverHandler),document.addEventListener("click",this.clickHandler,!0),document.addEventListener("scroll",this.scrollHandler)}editHyperlink(t,e){var i;const o=this.pmView.state.tr.insertText(e,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to);o.addMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.from+e.length,this.pmView.state.schema.mark("link",{href:t})),this.pmView.dispatch(o),this.pmView.focus(),(i=this.hyperlinkToolbarState)!=null&&i.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}deleteHyperlink(){var t;this.pmView.dispatch(this.pmView.state.tr.removeMark(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to,this.hyperlinkMark.type).setMeta("preventAutolink",!0)),this.pmView.focus(),(t=this.hyperlinkToolbarState)!=null&&t.show&&(this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar())}update(){var e;if(!this.pmView.hasFocus())return;const t=this.hyperlinkMark;if(this.hyperlinkMark=void 0,this.hyperlinkMarkRange=void 0,this.keyboardHoveredHyperlinkMark=void 0,this.keyboardHoveredHyperlinkMarkRange=void 0,this.pmView.state.selection.empty){const o=this.pmView.state.selection.$from.marks();for(const i of o)if(i.type.name===this.pmView.state.schema.mark("link").type.name){this.keyboardHoveredHyperlinkMark=i,this.keyboardHoveredHyperlinkMarkRange=b.getMarkRange(this.pmView.state.selection.$from,i.type,i.attrs)||void 0;break}}if(this.mouseHoveredHyperlinkMark&&(this.hyperlinkMark=this.mouseHoveredHyperlinkMark,this.hyperlinkMarkRange=this.mouseHoveredHyperlinkMarkRange),this.keyboardHoveredHyperlinkMark&&(this.hyperlinkMark=this.keyboardHoveredHyperlinkMark,this.hyperlinkMarkRange=this.keyboardHoveredHyperlinkMarkRange),this.hyperlinkMark&&this.editor.isEditable){this.hyperlinkToolbarState={show:!0,referencePos:b.posToDOMRect(this.pmView,this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to),url:this.hyperlinkMark.attrs.href,text:this.pmView.state.doc.textBetween(this.hyperlinkMarkRange.from,this.hyperlinkMarkRange.to)},this.updateHyperlinkToolbar();return}if((e=this.hyperlinkToolbarState)!=null&&e.show&&t&&(!this.hyperlinkMark||!this.editor.isEditable)){this.hyperlinkToolbarState.show=!1,this.updateHyperlinkToolbar();return}}destroy(){this.pmView.dom.removeEventListener("mouseover",this.mouseOverHandler),document.removeEventListener("scroll",this.scrollHandler),document.removeEventListener("click",this.clickHandler,!0)}}const mt=new y.PluginKey("HyperlinkToolbarPlugin");class ft extends K{constructor(e){super();p(this,"view");p(this,"plugin");p(this,"editHyperlink",(e,o)=>{this.view.editHyperlink(e,o)});p(this,"deleteHyperlink",()=>{this.view.deleteHyperlink()});p(this,"startHideTimer",()=>{this.view.startMenuUpdateTimer()});p(this,"stopHideTimer",()=>{this.view.stopMenuUpdateTimer()});this.plugin=new y.Plugin({key:mt,view:o=>(this.view=new so(e,o,i=>{this.emit("update",i)}),this.view)})}onUpdate(e){return this.on("update",e)}}const ao=b.findParentNode(n=>n.type.name==="blockContainer");class lo{constructor(t,e,o=()=>{}){p(this,"suggestionsMenuState");p(this,"updateSuggestionsMenu");p(this,"pluginState");p(this,"handleScroll",()=>{var t;if((t=this.suggestionsMenuState)!=null&&t.show){const e=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.suggestionsMenuState.referencePos=e.getBoundingClientRect(),this.updateSuggestionsMenu()}});this.editor=t,this.pluginKey=e,this.pluginState=Be(),this.updateSuggestionsMenu=()=>{if(!this.suggestionsMenuState)throw new Error("Attempting to update uninitialized suggestions menu");o(this.suggestionsMenuState)},document.addEventListener("scroll",this.handleScroll)}update(t,e){const o=this.pluginKey.getState(e),i=this.pluginKey.getState(t.state),r=!o.active&&i.active,s=o.active&&!i.active,a=o.active&&i.active;if(!r&&!a&&!s)return;if(this.pluginState=s?o:i,s||!this.editor.isEditable){this.suggestionsMenuState.show=!1,this.updateSuggestionsMenu();return}const l=document.querySelector(`[data-decoration-id="${this.pluginState.decorationId}"]`);this.editor.isEditable&&(this.suggestionsMenuState={show:!0,referencePos:l.getBoundingClientRect(),filteredItems:this.pluginState.items,keyboardHoveredItemIndex:this.pluginState.keyboardHoveredItemIndex},this.updateSuggestionsMenu())}destroy(){document.removeEventListener("scroll",this.handleScroll)}}function Be(){return{active:!1,triggerCharacter:void 0,queryStartPos:void 0,items:[],keyboardHoveredItemIndex:void 0,notFoundCount:0,decorationId:void 0}}const gt=(n,t,e,o,i=()=>[],r=()=>{})=>{if(o.length!==1)throw new Error("'char' should be a single character");let s;const a=l=>{l.dispatch(l.state.tr.setMeta(e,{deactivate:!0}))};return{plugin:new y.Plugin({key:e,view:()=>(s=new lo(n,e,t),s),state:{init(){return Be()},apply(l,d,u,h){var m,g,E,M;if(l.getMeta("orderedListIndexing")!==void 0)return d;if((m=l.getMeta(e))!=null&&m.activate)return{active:!0,triggerCharacter:((g=l.getMeta(e))==null?void 0:g.triggerCharacter)||"",queryStartPos:h.selection.from,items:i(""),keyboardHoveredItemIndex:0,notFoundCount:0,decorationId:`id_${Math.floor(Math.random()*4294967295)}`};if(!d.active)return d;const f={...d};if(f.items=i(h.doc.textBetween(d.queryStartPos,h.selection.from)),f.notFoundCount=0,f.items.length===0&&(f.notFoundCount=Math.max(0,d.notFoundCount+(h.selection.from-u.selection.from))),h.selection.from!==h.selection.to||(E=l.getMeta(e))!=null&&E.deactivate||l.getMeta("focus")||l.getMeta("blur")||l.getMeta("pointer")||d.active&&h.selection.from<d.queryStartPos||f.notFoundCount>3)return Be();if(((M=l.getMeta(e))==null?void 0:M.selectedItemIndexChanged)!==void 0){let x=l.getMeta(e).selectedItemIndexChanged;x<0?x=d.items.length-1:x>=d.items.length&&(x=0),f.keyboardHoveredItemIndex=x}else u.selection.from!==h.selection.from&&(f.keyboardHoveredItemIndex=0);return f}},props:{handleKeyDown(l,d){const u=this.getState(l.state).active;if(d.key===o&&!u)return l.dispatch(l.state.tr.insertText(o).scrollIntoView().setMeta(e,{activate:!0,triggerCharacter:o})),!0;if(!u)return!1;const{triggerCharacter:h,queryStartPos:f,items:m,keyboardHoveredItemIndex:g}=e.getState(l.state);return d.key==="ArrowUp"?(l.dispatch(l.state.tr.setMeta(e,{selectedItemIndexChanged:g-1})),!0):d.key==="ArrowDown"?(l.dispatch(l.state.tr.setMeta(e,{selectedItemIndexChanged:g+1})),!0):d.key==="Enter"?(m.length===0||(a(l),n._tiptapEditor.chain().focus().deleteRange({from:f-h.length,to:n._tiptapEditor.state.selection.from}).run(),r({item:m[g],editor:n})),!0):d.key==="Escape"?(a(l),!0):!1},decorations(l){const{active:d,decorationId:u,queryStartPos:h,triggerCharacter:f}=this.getState(l);if(!d)return null;if(f===""){const m=ao(l.selection);if(m)return N.DecorationSet.create(l.doc,[N.Decoration.node(m.pos,m.pos+m.node.nodeSize,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":u})])}return N.DecorationSet.create(l.doc,[N.Decoration.inline(h-f.length,h,{nodeName:"span",class:"bn-suggestion-decorator","data-decoration-id":u})])}}}),itemCallback:l=>{a(n._tiptapEditor.view),n._tiptapEditor.chain().focus().deleteRange({from:s.pluginState.queryStartPos-s.pluginState.triggerCharacter.length,to:n._tiptapEditor.state.selection.from}).run(),r({item:l,editor:n})}}},re=new y.PluginKey("SlashMenuPlugin");class bt extends K{constructor(e,o){super();p(this,"plugin");p(this,"itemCallback");const i=gt(e,r=>{this.emit("update",r)},re,"/",r=>o.filter(({name:s,aliases:a})=>s.toLowerCase().startsWith(r.toLowerCase())||a&&a.filter(l=>l.toLowerCase().startsWith(r.toLowerCase())).length!==0),({item:r,editor:s})=>r.execute(s));this.plugin=i.plugin,this.itemCallback=i.itemCallback}onUpdate(e){return this.on("update",e)}}class X extends y.Selection{constructor(e,o){super(e,o);p(this,"nodes");const i=e.node();this.nodes=[],e.doc.nodesBetween(e.pos,o.pos,(r,s,a)=>{if(a!==null&&a.eq(i))return this.nodes.push(r),!1})}static create(e,o,i=o){return new X(e.resolve(o),e.resolve(i))}content(){return new k.Slice(k.Fragment.from(this.nodes),0,0)}eq(e){if(!(e instanceof X)||this.nodes.length!==e.nodes.length||this.from!==e.from||this.to!==e.to)return!1;for(let o=0;o<this.nodes.length;o++)if(!this.nodes[o].eq(e.nodes[o]))return!1;return!0}map(e,o){const i=o.mapResult(this.from),r=o.mapResult(this.to);return r.deleted?y.Selection.near(e.resolve(i.pos)):i.deleted?y.Selection.near(e.resolve(r.pos)):new X(e.resolve(i.pos),e.resolve(r.pos))}toJSON(){return{type:"node",anchor:this.anchor,head:this.head}}}let F;function se(n,t){var i;if(!t.dom.isConnected)return;const e=t.posAtCoords(n);if(!e)return;let o=t.domAtPos(e.pos).node;if(o!==t.dom){for(;o&&o.parentNode&&o.parentNode!==t.dom&&!((i=o.hasAttribute)!=null&&i.call(o,"data-id"));)o=o.parentNode;if(o)return{node:o,id:o.getAttribute("data-id")}}}function co(n,t){const e=se(n,t);if(e&&e.node.nodeType===1){const o=t.docView,i=o.nearestDesc(e.node,!0);return!i||i===o?null:i.posBefore}return null}function uo(n,t){let e,o;const i=t.resolve(n.from).node().type.spec.group==="blockContent",r=t.resolve(n.to).node().type.spec.group==="blockContent",s=Math.min(n.$anchor.depth,n.$head.depth);if(i&&r){const a=n.$from.start(s-1),l=n.$to.end(s-1);e=t.resolve(a-1).pos,o=t.resolve(l+1).pos}else e=n.from,o=n.to;return{from:e,to:o}}function yt(n,t,e=t){t===e&&(e+=n.state.doc.resolve(t+1).node().nodeSize);const o=n.domAtPos(t).node.cloneNode(!0),i=n.domAtPos(t).node,r=(u,h)=>Array.prototype.indexOf.call(u.children,h),s=r(i,n.domAtPos(t+1).node.parentElement),a=r(i,n.domAtPos(e-1).node.parentElement);for(let u=i.childElementCount-1;u>=0;u--)(u>a||u<s)&&o.removeChild(o.children[u]);kt(),F=o;const d=n.dom.className.split(" ").filter(u=>u!=="ProseMirror"&&u!=="bn-root"&&u!=="bn-editor").join(" ");F.className=F.className+" bn-drag-preview "+d,document.body.appendChild(F)}function kt(){F!==void 0&&(document.body.removeChild(F),F=void 0)}function po(n,t){if(!n.dataTransfer)return;const e=t.prosemirrorView,o=e.dom.getBoundingClientRect(),i={left:o.left+o.width/2,top:n.clientY},r=co(i,e);if(r!=null){const s=e.state.selection,a=e.state.doc,{from:l,to:d}=uo(s,a),u=l<=r&&r<d,h=s.$anchor.node()!==s.$head.node()||s instanceof X;u&&h?(e.dispatch(e.state.tr.setSelection(X.create(a,l,d))),yt(e,l,d)):(e.dispatch(e.state.tr.setSelection(y.NodeSelection.create(e.state.doc,r))),yt(e,r));const f=e.state.selection.content(),m=t._tiptapEditor.schema,E=me(m,t).serializeProseMirrorFragment(f.content),x=Z(m,t).exportProseMirrorFragment(f.content),S=xe(x);n.dataTransfer.clearData(),n.dataTransfer.setData("blocknote/html",E),n.dataTransfer.setData("text/html",x),n.dataTransfer.setData("text/plain",S),n.dataTransfer.effectAllowed="move",n.dataTransfer.setDragImage(F,0,0),e.dragging={slice:f,move:!0}}}class wt{constructor(t,e,o){p(this,"sideMenuState");p(this,"horizontalPosAnchoredAtRoot");p(this,"horizontalPosAnchor");p(this,"hoveredBlock");p(this,"isDragging",!1);p(this,"menuFrozen",!1);p(this,"onDragStart",()=>{this.isDragging=!0});p(this,"onDrop",t=>{if(this.editor._tiptapEditor.commands.blur(),t.synthetic||!this.isDragging)return;const e=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(this.isDragging=!1,!e||e.inside===-1){const o=new Event("drop",t),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});p(this,"onDragOver",t=>{if(t.synthetic||!this.isDragging)return;const e=this.pmView.posAtCoords({left:t.clientX,top:t.clientY});if(!e||e.inside===-1){const o=new Event("dragover",t),i=this.pmView.dom.firstChild.getBoundingClientRect();o.clientX=i.left+i.width/2,o.clientY=t.clientY,o.dataTransfer=t.dataTransfer,o.preventDefault=()=>t.preventDefault(),o.synthetic=!0,this.pmView.dom.dispatchEvent(o)}});p(this,"onKeyDown",t=>{var e;(e=this.sideMenuState)!=null&&e.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});p(this,"onMouseDown",t=>{this.sideMenuState&&!this.sideMenuState.show&&(this.sideMenuState.show=!0,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!1});p(this,"onMouseMove",t=>{var d,u,h,f,m;if(this.menuFrozen)return;const e=this.pmView.dom.firstChild.getBoundingClientRect(),o=this.pmView.dom.getBoundingClientRect(),i=t.clientX>=o.left&&t.clientX<=o.right&&t.clientY>=o.top&&t.clientY<=o.bottom,r=this.pmView.dom.parentElement;if(i&&t&&t.target&&!(r===t.target||r.contains(t.target))){(d=this.sideMenuState)!=null&&d.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}this.horizontalPosAnchor=e.x;const s={left:e.left+e.width/2,top:t.clientY},a=se(s,this.pmView);if(!a||!this.editor.isEditable){(u=this.sideMenuState)!=null&&u.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState));return}if((h=this.sideMenuState)!=null&&h.show&&((f=this.hoveredBlock)!=null&&f.hasAttribute("data-id"))&&((m=this.hoveredBlock)==null?void 0:m.getAttribute("data-id"))===a.id)return;this.hoveredBlock=a.node;const l=a.node.firstChild;if(l&&this.editor.isEditable){const g=l.getBoundingClientRect();this.sideMenuState={show:!0,referencePos:new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:g.x,g.y,g.width,g.height),block:this.editor.getBlock(this.hoveredBlock.getAttribute("data-id"))},this.updateSideMenu(this.sideMenuState)}});p(this,"onScroll",()=>{var t;if((t=this.sideMenuState)!=null&&t.show){const o=this.hoveredBlock.firstChild.getBoundingClientRect();this.sideMenuState.referencePos=new DOMRect(this.horizontalPosAnchoredAtRoot?this.horizontalPosAnchor:o.x,o.y,o.width,o.height),this.updateSideMenu(this.sideMenuState)}});this.editor=t,this.pmView=e,this.updateSideMenu=o,this.horizontalPosAnchoredAtRoot=!0,this.horizontalPosAnchor=this.pmView.dom.firstChild.getBoundingClientRect().x,document.body.addEventListener("drop",this.onDrop,!0),document.body.addEventListener("dragover",this.onDragOver),this.pmView.dom.addEventListener("dragstart",this.onDragStart),document.body.addEventListener("mousemove",this.onMouseMove,!0),document.addEventListener("scroll",this.onScroll),document.body.addEventListener("mousedown",this.onMouseDown,!0),document.body.addEventListener("keydown",this.onKeyDown,!0)}destroy(){var t;(t=this.sideMenuState)!=null&&t.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),document.body.removeEventListener("mousemove",this.onMouseMove),document.body.removeEventListener("dragover",this.onDragOver),this.pmView.dom.removeEventListener("dragstart",this.onDragStart),document.body.removeEventListener("drop",this.onDrop,!0),document.removeEventListener("scroll",this.onScroll),document.body.removeEventListener("mousedown",this.onMouseDown,!0),document.body.removeEventListener("keydown",this.onKeyDown,!0)}addBlock(){var a;(a=this.sideMenuState)!=null&&a.show&&(this.sideMenuState.show=!1,this.updateSideMenu(this.sideMenuState)),this.menuFrozen=!0;const e=this.hoveredBlock.firstChild.getBoundingClientRect(),o=this.pmView.posAtCoords({left:e.left+e.width/2,top:e.top+e.height/2});if(!o)return;const i=T(this.editor._tiptapEditor.state.doc,o.pos);if(i===void 0)return;const{contentNode:r,endPos:s}=i;if(r.textContent.length!==0){const l=s+1,d=l+2;this.editor._tiptapEditor.chain().BNCreateBlock(l).BNUpdateBlock(d,{type:"paragraph",props:{}}).setTextSelection(d).run()}else this.editor._tiptapEditor.commands.setTextSelection(s);this.pmView.focus(),this.pmView.dispatch(this.pmView.state.tr.scrollIntoView().setMeta(re,{activate:!0,type:"drag"}))}}const vt=new y.PluginKey("SideMenuPlugin");class St extends K{constructor(e){super();p(this,"sideMenuView");p(this,"plugin");p(this,"addBlock",()=>this.sideMenuView.addBlock());p(this,"blockDragStart",e=>{this.sideMenuView.isDragging=!0,po(e,this.editor)});p(this,"blockDragEnd",()=>kt());p(this,"freezeMenu",()=>this.sideMenuView.menuFrozen=!0);p(this,"unfreezeMenu",()=>this.sideMenuView.menuFrozen=!1);this.editor=e,this.plugin=new y.Plugin({key:vt,view:o=>(this.sideMenuView=new wt(e,o,i=>{this.emit("update",i)}),this.sideMenuView)})}onUpdate(e){return this.on("update",e)}}function ho(n){let t=n.getTextCursorPosition().block,e=n.blockSchema[t.type].content;for(;e==="none";)t=n.getTextCursorPosition().nextBlock,e=n.blockSchema[t.type].content,n.setTextCursorPosition(t,"end")}function z(n,t){const e=n.getTextCursorPosition().block;if(e.content===void 0)throw new Error("Slash Menu open in a block that doesn't contain content.");Array.isArray(e.content)&&(e.content.length===1&&G(e.content[0])&&e.content[0].type==="text"&&e.content[0].text==="/"||e.content.length===0)?n.updateBlock(e,t):(n.insertBlocks([t],e,"after"),n.setTextCursorPosition(n.getTextCursorPosition().nextBlock,"end"));const o=n.getTextCursorPosition().block;return ho(n),o}const Et=(n=Ee)=>{var e,o,i;const t=[];return"heading"in n&&"level"in n.heading.propSchema&&((e=n.heading.propSchema.level.values)!=null&&e.includes(1)&&t.push({name:"Heading",aliases:["h","heading1","h1"],execute:r=>z(r,{type:"heading",props:{level:1}})}),(o=n.heading.propSchema.level.values)!=null&&o.includes(2)&&t.push({name:"Heading 2",aliases:["h2","heading2","subheading"],execute:r=>z(r,{type:"heading",props:{level:2}})}),(i=n.heading.propSchema.level.values)!=null&&i.includes(3)&&t.push({name:"Heading 3",aliases:["h3","heading3","subheading"],execute:r=>z(r,{type:"heading",props:{level:3}})})),"bulletListItem"in n&&t.push({name:"Bullet List",aliases:["ul","list","bulletlist","bullet list"],execute:r=>z(r,{type:"bulletListItem"})}),"numberedListItem"in n&&t.push({name:"Numbered List",aliases:["li","list","numberedlist","numbered list"],execute:r=>z(r,{type:"numberedListItem"})}),"paragraph"in n&&t.push({name:"Paragraph",aliases:["p"],execute:r=>z(r,{type:"paragraph"})}),"table"in n&&t.push({name:"Table",aliases:["table"],execute:r=>{z(r,{type:"table",content:{type:"tableContent",rows:[{cells:["","",""]},{cells:["","",""]}]}})}}),"image"in n&&t.push({name:"Image",aliases:["image","imageUpload","upload","img","picture","media","url","drive","dropbox"],execute:r=>{const s=z(r,{type:"image"});r._tiptapEditor.view.dispatch(r._tiptapEditor.state.tr.setMeta(W,{block:s}))}}),t};let D;function Tt(){D||(D=document.createElement("div"),D.innerHTML="_",D.style.visibility="hidden",document.body.appendChild(D))}function mo(){D&&(document.body.removeChild(D),D=void 0)}function ae(n){return Array.prototype.indexOf.call(n.parentElement.childNodes,n)}function fo(n){for(;n&&n.nodeName!=="TD"&&n.nodeName!=="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function go(n){n.forEach(t=>{const e=document.getElementsByClassName(t);for(let o=0;o<e.length;o++)e[o].style.visibility="hidden"})}class Ct{constructor(t,e,o){p(this,"state");p(this,"updateState");p(this,"tableId");p(this,"tablePos");p(this,"menuFrozen",!1);p(this,"prevWasEditable",null);p(this,"mouseMoveHandler",t=>{var d;if(this.menuFrozen)return;const e=fo(t.target);if(!e||!this.editor.isEditable){(d=this.state)!=null&&d.show&&(this.state.show=!1,this.updateState());return}const o=ae(e),i=ae(e.parentElement),r=e.getBoundingClientRect(),s=e.parentElement.parentElement.getBoundingClientRect(),a=se(r,this.pmView);if(!a)throw new Error("Found table cell element, but could not find surrounding blockContent element.");if(this.tableId=a.id,this.state!==void 0&&this.state.show&&this.tableId===a.id&&this.state.rowIndex===i&&this.state.colIndex===o)return;let l;return this.editor._tiptapEditor.state.doc.descendants((u,h)=>typeof l<"u"?!1:u.type.name!=="blockContainer"||u.attrs.id!==a.id?!0:(l=L(u,this.editor.blockSchema,this.editor.inlineContentSchema,this.editor.styleSchema,this.editor.blockCache),this.tablePos=h+1,!1)),this.state={show:!0,referencePosCell:r,referencePosTable:s,block:l,colIndex:o,rowIndex:i,draggingState:void 0},this.updateState(),!1});p(this,"dragOverHandler",t=>{var f;if(((f=this.state)==null?void 0:f.draggingState)===void 0)return;t.preventDefault(),t.dataTransfer.dropEffect="move",go(["column-resize-handle","prosemirror-dropcursor-block","prosemirror-dropcursor-inline"]);const e={left:Math.min(Math.max(t.clientX,this.state.referencePosTable.left+1),this.state.referencePosTable.right-1),top:Math.min(Math.max(t.clientY,this.state.referencePosTable.top+1),this.state.referencePosTable.bottom-1)},o=document.elementsFromPoint(e.left,e.top).filter(m=>m.tagName==="TD"||m.tagName==="TH");if(o.length===0)throw new Error("Could not find table cell element that the mouse cursor is hovering over.");const i=o[0];let r=!1;const s=ae(i.parentElement),a=ae(i),l=this.state.draggingState.draggedCellOrientation==="row"?this.state.rowIndex:this.state.colIndex,u=(this.state.draggingState.draggedCellOrientation==="row"?s:a)!==l;(this.state.rowIndex!==s||this.state.colIndex!==a)&&(this.state.rowIndex=s,this.state.colIndex=a,this.state.referencePosCell=i.getBoundingClientRect(),r=!0);const h=this.state.draggingState.draggedCellOrientation==="row"?e.top:e.left;this.state.draggingState.mousePos!==h&&(this.state.draggingState.mousePos=h,r=!0),r&&this.updateState(),u&&this.pmView.dispatch(this.pmView.state.tr.setMeta(J,!0))});p(this,"dropHandler",t=>{if(this.state===void 0||this.state.draggingState===void 0)return;t.preventDefault();const e=this.state.block.content.rows;if(this.state.draggingState.draggedCellOrientation==="row"){const o=e[this.state.draggingState.originalIndex];e.splice(this.state.draggingState.originalIndex,1),e.splice(this.state.rowIndex,0,o)}else{const o=e.map(i=>i.cells[this.state.draggingState.originalIndex]);e.forEach((i,r)=>{i.cells.splice(this.state.draggingState.originalIndex,1),i.cells.splice(this.state.colIndex,0,o[r])})}this.editor.updateBlock(this.state.block,{type:"table",content:{type:"tableContent",rows:e}})});p(this,"scrollHandler",()=>{var t;if((t=this.state)!=null&&t.show){const e=document.querySelector(`[data-node-type="blockContainer"][data-id="${this.tableId}"] table`),o=e.querySelector(`tr:nth-child(${this.state.rowIndex+1}) > td:nth-child(${this.state.colIndex+1})`);this.state.referencePosTable=e.getBoundingClientRect(),this.state.referencePosCell=o.getBoundingClientRect(),this.updateState()}});this.editor=t,this.pmView=e,this.updateState=()=>{if(!this.state)throw new Error("Attempting to update uninitialized image toolbar");o(this.state)},e.dom.addEventListener("mousemove",this.mouseMoveHandler),document.addEventListener("dragover",this.dragOverHandler),document.addEventListener("drop",this.dropHandler),document.addEventListener("scroll",this.scrollHandler)}destroy(){this.pmView.dom.removeEventListener("mousedown",this.mouseMoveHandler),document.removeEventListener("dragover",this.dragOverHandler),document.removeEventListener("drop",this.dropHandler),document.removeEventListener("scroll",this.scrollHandler)}}const J=new y.PluginKey("TableHandlesPlugin");class Mt extends K{constructor(e){super();p(this,"view");p(this,"plugin");p(this,"colDragStart",e=>{if(this.view.state===void 0)throw new Error("Attempted to drag table column, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"col",originalIndex:this.view.state.colIndex,mousePos:e.clientX},this.view.updateState(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.colIndex,newIndex:this.view.state.colIndex,tablePos:this.view.tablePos})),Tt(),e.dataTransfer.setDragImage(D,0,0),e.dataTransfer.effectAllowed="move"});p(this,"rowDragStart",e=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState={draggedCellOrientation:"row",originalIndex:this.view.state.rowIndex,mousePos:e.clientY},this.view.updateState(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,{draggedCellOrientation:this.view.state.draggingState.draggedCellOrientation,originalIndex:this.view.state.rowIndex,newIndex:this.view.state.rowIndex,tablePos:this.view.tablePos})),Tt(),e.dataTransfer.setDragImage(D,0,0),e.dataTransfer.effectAllowed="copyMove"});p(this,"dragEnd",()=>{if(this.view.state===void 0)throw new Error("Attempted to drag table row, but no table block was hovered prior.");this.view.state.draggingState=void 0,this.view.updateState(),this.editor._tiptapEditor.view.dispatch(this.editor._tiptapEditor.state.tr.setMeta(J,null)),mo()});p(this,"freezeHandles",()=>this.view.menuFrozen=!0);p(this,"unfreezeHandles",()=>this.view.menuFrozen=!1);this.editor=e,this.plugin=new y.Plugin({key:J,view:o=>(this.view=new Ct(e,o,i=>{this.emit("update",i)}),this.view),props:{decorations:o=>{if(this.view===void 0||this.view.state===void 0||this.view.state.draggingState===void 0||this.view.tablePos===void 0)return;const i=this.view.state.draggingState.draggedCellOrientation==="row"?this.view.state.rowIndex:this.view.state.colIndex,r=[];if(i===this.view.state.draggingState.originalIndex)return N.DecorationSet.create(o.doc,r);const s=o.doc.resolve(this.view.tablePos+1),a=s.node();if(this.view.state.draggingState.draggedCellOrientation==="row"){const l=o.doc.resolve(s.posAtIndex(i)+1),d=l.node();for(let u=0;u<d.childCount;u++){const h=o.doc.resolve(l.posAtIndex(u)+1),f=h.node(),m=h.pos+(i>this.view.state.draggingState.originalIndex?f.nodeSize-2:0);r.push(N.Decoration.widget(m,()=>{const g=document.createElement("div");return g.className="bn-table-drop-cursor",g.style.left="0",g.style.right="0",i>this.view.state.draggingState.originalIndex?g.style.bottom="-2px":g.style.top="-3px",g.style.height="4px",g}))}}else for(let l=0;l<a.childCount;l++){const d=o.doc.resolve(s.posAtIndex(l)+1),u=o.doc.resolve(d.posAtIndex(i)+1),h=u.node(),f=u.pos+(i>this.view.state.draggingState.originalIndex?h.nodeSize-2:0);r.push(N.Decoration.widget(f,()=>{const m=document.createElement("div");return m.className="bn-table-drop-cursor",m.style.top="0",m.style.bottom="0",i>this.view.state.draggingState.originalIndex?m.style.right="-2px":m.style.left="-3px",m.style.width="4px",m}))}return N.DecorationSet.create(o.doc,r)}}})}onUpdate(e){return this.on("update",e)}}const bo=n=>b.Extension.create({name:"copyToClipboard",addProseMirrorPlugins(){const t=this.editor,e=this.editor.schema;return[new y.Plugin({props:{handleDOMEvents:{copy(o,i){i.preventDefault(),i.clipboardData.clearData();const r=t.state.selection.content().content,a=me(e,n).serializeProseMirrorFragment(r),d=Z(e,n).exportProseMirrorFragment(r),u=xe(d);return i.clipboardData.setData("blocknote/html",a),i.clipboardData.setData("text/html",d),i.clipboardData.setData("text/plain",u),!0}}}})]}}),yo=["blocknote/html","text/html","text/plain"],ko=n=>b.Extension.create({name:"pasteFromClipboard",addProseMirrorPlugins(){return[new y.Plugin({props:{handleDOMEvents:{paste(t,e){e.preventDefault();let o=null;for(const i of yo)if(e.clipboardData.types.includes(i)){o=i;break}if(o!==null){let i=e.clipboardData.getData(o);o==="text/html"&&(i=dt(i.trim()).innerHTML,console.log(i)),n._tiptapEditor.view.pasteHTML(i)}return!0}}}})]}}),wo=b.Extension.create({name:"blockBackgroundColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{backgroundColor:{default:P.backgroundColor.default,parseHTML:n=>n.hasAttribute("data-background-color")?n.getAttribute("data-background-color"):P.backgroundColor.default,renderHTML:n=>n.backgroundColor!==P.backgroundColor.default&&{"data-background-color":n.backgroundColor}}}}]}}),vo=new y.PluginKey("blocknote-placeholder"),So=b.Extension.create({name:"placeholder",addOptions(){return{emptyEditorClass:"bn-is-editor-empty",emptyNodeClass:"bn-is-empty",isFilterClass:"bn-is-filter",hasAnchorClass:"bn-has-anchor",placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[new y.Plugin({key:vo,props:{decorations:n=>{const{doc:t,selection:e}=n,o=re.getState(n),i=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=e,s=[];if(i)return t.descendants((a,l)=>{const d=r>=l&&r<=l+a.nodeSize,u=!a.isLeaf&&!a.childCount;if((d||!this.options.showOnlyCurrent)&&u){const h=[this.options.emptyNodeClass];this.editor.isEmpty&&h.push(this.options.emptyEditorClass),d&&h.push(this.options.hasAnchorClass),(o==null?void 0:o.triggerCharacter)===""&&(o!=null&&o.active)&&h.push(this.options.isFilterClass);const f=N.Decoration.node(l,l+a.nodeSize,{class:h.join(" ")});s.push(f)}return this.options.includeChildren}),N.DecorationSet.create(t,s)}}})]}}),Eo=b.Extension.create({name:"textAlignment",addGlobalAttributes(){return[{types:["paragraph","heading","bulletListItem","numberedListItem"],attributes:{textAlignment:{default:"left",parseHTML:n=>n.getAttribute("data-text-alignment"),renderHTML:n=>n.textAlignment!=="left"&&{"data-text-alignment":n.textAlignment}}}}]}}),To=b.Extension.create({name:"blockTextColor",addGlobalAttributes(){return[{types:["blockContainer"],attributes:{textColor:{default:P.textColor.default,parseHTML:n=>n.hasAttribute("data-text-color")?n.getAttribute("data-text-color"):P.textColor.default,renderHTML:n=>n.textColor!==P.textColor.default&&{"data-text-color":n.textColor}}}}]}}),Co=b.Extension.create({name:"trailingNode",addProseMirrorPlugins(){const n=new y.PluginKey(this.name);return[new y.Plugin({key:n,appendTransaction:(t,e,o)=>{const{doc:i,tr:r,schema:s}=o,a=n.getState(o),l=i.content.size-2,d=s.nodes.blockContainer,u=s.nodes.paragraph;if(a)return r.insert(l,d.create(void 0,u.create()))},state:{init:(t,e)=>{},apply:(t,e)=>{if(!t.docChanged)return e;let o=t.doc.lastChild;if(!o||o.type.name!=="blockGroup")throw new Error("Expected blockGroup");if(o=o.lastChild,!o||o.type.name!=="blockContainer")throw new Error("Expected blockContainer");const i=o.firstChild;if(!i)throw new Error("Expected blockContent");return o.nodeSize>4||i.type.spec.content!=="inline*"}}})]}}),Mo=new y.PluginKey("non-editable-block"),xo=()=>new y.Plugin({key:Mo,props:{handleKeyDown:(n,t)=>{"node"in n.state.selection&&t.preventDefault()}}}),xt=new y.PluginKey("previous-blocks"),Bo={index:"index",level:"level",type:"type",depth:"depth","depth-change":"depth-change"},Io=()=>{let n;return new y.Plugin({key:xt,view(t){return{update:async(e,o)=>{var i;((i=this.key)==null?void 0:i.getState(e.state).updatedBlocks.size)>0&&(n=setTimeout(()=>{e.dispatch(e.state.tr.setMeta(xt,{clearUpdate:!0}))},0))},destroy:()=>{n&&clearTimeout(n)}}},state:{init(){return{prevTransactionOldBlockAttrs:{},currentTransactionOldBlockAttrs:{},updatedBlocks:new Set}},apply(t,e,o,i){if(e.currentTransactionOldBlockAttrs={},e.updatedBlocks.clear(),!t.docChanged||o.doc.eq(i.doc))return e;const r={},s=b.findChildren(o.doc,d=>d.attrs.id),a=new Map(s.map(d=>[d.node.attrs.id,d])),l=b.findChildren(i.doc,d=>d.attrs.id);for(const d of l){const u=a.get(d.node.attrs.id),h=u==null?void 0:u.node.firstChild,f=d.node.firstChild;if(u&&h&&f){const m={index:f.attrs.index,level:f.attrs.level,type:f.type.name,depth:i.doc.resolve(d.pos).depth};let g={index:h.attrs.index,level:h.attrs.level,type:h.type.name,depth:o.doc.resolve(u.pos).depth};r[d.node.attrs.id]=g,t.getMeta("numberedListIndexing")&&(d.node.attrs.id in e.prevTransactionOldBlockAttrs&&(g=e.prevTransactionOldBlockAttrs[d.node.attrs.id]),m.type==="numberedListItem"&&(g.index=m.index)),e.currentTransactionOldBlockAttrs[d.node.attrs.id]=g,JSON.stringify(g)!==JSON.stringify(m)&&(g["depth-change"]=g.depth-m.depth,e.updatedBlocks.add(d.node.attrs.id))}}return e.prevTransactionOldBlockAttrs=r,e}},props:{decorations(t){const e=this.getState(t);if(e.updatedBlocks.size===0)return;const o=[];return t.doc.descendants((i,r)=>{if(!i.attrs.id||!e.updatedBlocks.has(i.attrs.id))return;const s=e.currentTransactionOldBlockAttrs[i.attrs.id],a={};for(const[d,u]of Object.entries(s))a["data-prev-"+Bo[d]]=u||"none";const l=N.Decoration.node(r,r+i.nodeSize,{...a});o.push(l)}),N.DecorationSet.create(t.doc,o)}}})},Po={blockColor:"data-block-color",blockStyle:"data-block-style",id:"data-id",depth:"data-depth",depthChange:"data-depth-change"},Ho=b.Node.create({name:"blockContainer",group:"blockContainer",content:"blockContent blockGroup?",priority:50,defining:!0,parseHTML(){return[{tag:"div",getAttrs:n=>{if(typeof n=="string")return!1;const t={};for(const[e,o]of Object.entries(Po))n.getAttribute(o)&&(t[e]=n.getAttribute(o));return n.getAttribute("data-node-type")==="blockContainer"?t:!1}}]},renderHTML({HTMLAttributes:n}){var i;const t=document.createElement("div");t.className="bn-block-outer",t.setAttribute("data-node-type","blockOuter");for(const[r,s]of Object.entries(n))r!=="class"&&t.setAttribute(r,s);const e={...((i=this.options.domAttributes)==null?void 0:i.blockContainer)||{},...n},o=document.createElement("div");o.className=O("bn-block",e.class),o.setAttribute("data-node-type",this.name);for(const[r,s]of Object.entries(e))r!=="class"&&o.setAttribute(r,s);return t.appendChild(o),{dom:t,contentDOM:o}},addCommands(){return{BNCreateBlock:n=>({state:t,dispatch:e})=>{const o=t.schema.nodes.blockContainer.createAndFill();return e&&t.tr.insert(n,o),!0},BNDeleteBlock:n=>({state:t,dispatch:e})=>{const o=T(t.doc,n);if(o===void 0)return!1;const{startPos:i,endPos:r}=o;return e&&t.tr.deleteRange(i,r),!0},BNUpdateBlock:(n,t)=>({state:e,dispatch:o})=>{const i=T(e.doc,n);if(i===void 0)return!1;const{startPos:r,endPos:s,node:a,contentNode:l}=i;if(o){if(t.children!==void 0){const f=[];for(const m of t.children)f.push(_(m,e.schema,this.options.editor.styleSchema));a.childCount===2?e.tr.replace(r+l.nodeSize+1,s-1,new k.Slice(k.Fragment.from(f),0,0)):e.tr.insert(r+l.nodeSize,e.schema.nodes.blockGroup.create({},f))}const d=l.type.name,u=t.type||d;let h="keep";if(t.content)if(typeof t.content=="string")h=[e.schema.text(t.content)];else if(Array.isArray(t.content))h=ne(t.content,e.schema,this.options.editor.styleSchema);else if(t.content.type==="tableContent")h=pe(t.content,e.schema,this.options.editor.styleSchema);else throw new A(t.content.type);else{const f=e.schema.nodes[d].spec.content,m=e.schema.nodes[u].spec.content;f===""||m!==f&&(h=[])}h==="keep"?e.tr.setNodeMarkup(r,t.type===void 0?void 0:e.schema.nodes[t.type],{...l.attrs,...t.props}):e.tr.replaceWith(r,s,e.schema.nodes[u].create({...l.attrs,...t.props},h)).setSelection(e.schema.nodes[u].spec.content===""?new y.NodeSelection(e.tr.doc.resolve(r)):e.schema.nodes[u].spec.content==="inline*"?new y.TextSelection(e.tr.doc.resolve(r)):new y.TextSelection(e.tr.doc.resolve(r+4))),e.tr.setNodeMarkup(r-1,void 0,{...a.attrs,...t.props})}return!0},BNMergeBlocks:n=>({state:t,dispatch:e})=>{const o=t.doc.resolve(n+1).node().type.name==="blockContainer",i=t.doc.resolve(n-1).node().type.name==="blockContainer";if(!o||!i)return!1;const r=T(t.doc,n+1),{node:s,contentNode:a,startPos:l,endPos:d,depth:u}=r;if(s.childCount===2){const m=t.doc.resolve(l+a.nodeSize+1),g=t.doc.resolve(d-1),E=m.blockRange(g);e&&t.tr.lift(E,u-1)}let h=n-1,f=T(t.doc,h);for(;f.numChildBlocks>0;)if(h--,f=T(t.doc,h),f===void 0)return!1;return e&&(e(t.tr.deleteRange(l,l+a.nodeSize).replace(h-1,l,new k.Slice(a.content,0,0)).scrollIntoView()),t.tr.setSelection(new y.TextSelection(t.doc.resolve(h-1)))),!0},BNSplitBlock:(n,t)=>({state:e,dispatch:o})=>{const i=T(e.doc,n);if(i===void 0)return!1;const{contentNode:r,contentType:s,startPos:a,endPos:l,depth:d}=i,u=e.doc.cut(a+1,n),h=e.doc.cut(n,l-1),f=e.schema.nodes.blockContainer.createAndFill(),m=l+1,g=m+2;return o&&(e.tr.insert(m,f),e.tr.replace(g,g+1,h.content.size>0?new k.Slice(k.Fragment.from(h),d+2,d+2):void 0),t&&e.tr.setBlockType(g,g,e.schema.node(s).type,r.attrs),e.tr.setSelection(new y.TextSelection(e.doc.resolve(g))),e.tr.replace(a+1,l-1,u.content.size>0?new k.Slice(k.Fragment.from(u),d+2,d+2):void 0)),!0}}},addProseMirrorPlugins(){return[Io(),xo()]},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.undoInputRule(),()=>o.command(({state:i})=>{const{contentType:r,startPos:s}=T(i.doc,i.selection.from),a=i.selection.from===s+1,l=r.name==="paragraph";return a&&!l?o.BNUpdateBlock(i.selection.from,{type:"paragraph",props:{}}):!1}),()=>o.command(({state:i})=>{const{startPos:r}=T(i.doc,i.selection.from);return i.selection.from===r+1?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i})=>{const{depth:r,startPos:s}=T(i.doc,i.selection.from),a=i.selection.from===s+1,l=i.selection.empty,d=s===2,u=s-1;return!d&&a&&l&&r===2?o.BNMergeBlocks(u):!1})]),Delete:()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.command(({state:i})=>{const{node:r,depth:s,endPos:a}=T(i.doc,i.selection.from),l=i.selection.from===a-1,d=i.selection.empty,u=r.childCount===2;if(l&&d&&!u){let h=s,f=a+2,m=i.doc.resolve(f).depth;for(;m<h;)h=m,f+=2,m=i.doc.resolve(f).depth;return o.BNMergeBlocks(f-1)}return!1})]),Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.command(({state:i})=>{const{node:r,depth:s}=T(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0,l=i.selection.anchor===i.selection.head,d=r.textContent.length===0,u=s>2;return a&&l&&d&&u?o.liftListItem("blockContainer"):!1}),()=>o.command(({state:i,chain:r})=>{const{node:s,endPos:a}=T(i.doc,i.selection.from),l=i.selection.$anchor.parentOffset===0,d=i.selection.anchor===i.selection.head,u=s.textContent.length===0;if(l&&d&&u){const h=a+1,f=h+2;return r().BNCreateBlock(h).setTextSelection(f).run(),!0}return!1}),()=>o.command(({state:i,chain:r})=>{const{node:s}=T(i.doc,i.selection.from),a=i.selection.$anchor.parentOffset===0;return s.textContent.length===0?!1:(r().deleteSelection().BNSplitBlock(i.selection.from,a).run(),!0)})]),Tab:()=>(this.editor.commands.sinkListItem("blockContainer"),!0),"Shift-Tab":()=>(this.editor.commands.liftListItem("blockContainer"),!0),"Mod-Alt-0":()=>this.editor.commands.BNCreateBlock(this.editor.state.selection.anchor+2)}}}),No=b.Node.create({name:"blockGroup",group:"blockGroup",content:"blockContainer+",parseHTML(){return[{tag:"div",getAttrs:n=>typeof n=="string"?!1:n.getAttribute("data-node-type")==="blockGroup"?null:!1}]},renderHTML({HTMLAttributes:n}){var o;const t={...((o=this.options.domAttributes)==null?void 0:o.blockGroup)||{},...n},e=document.createElement("div");e.className=O("bn-block-group",t.class),e.setAttribute("data-node-type","blockGroup");for(const[i,r]of Object.entries(t))i!=="class"&&e.setAttribute(i,r);return{dom:e,contentDOM:e}}}),Lo=b.Node.create({name:"doc",topNode:!0,content:"blockGroup"}),Bt=n=>{var e;const t=[b.extensions.ClipboardTextSerializer,b.extensions.Commands,b.extensions.Editable,b.extensions.FocusEvents,b.extensions.Tabindex,Jt.Gapcursor,So.configure({includeChildren:!0,showOnlyCurrent:!1}),$.configure({types:["blockContainer"]}),Yt.HardBreak,en.Text,Qt.Link,...Object.values(n.styleSpecs).map(o=>o.implementation.mark),To,wo,Eo,Lo,Ho.configure({editor:n.editor,domAttributes:n.domAttributes}),No.configure({domAttributes:n.domAttributes}),...Object.values(n.inlineContentSpecs).filter(o=>o.config!=="link"&&o.config!=="text").map(o=>o.implementation.node.configure({editor:n.editor})),...Object.values(n.blockSpecs).flatMap(o=>[...(o.implementation.requiredExtensions||[]).map(i=>i.configure({editor:n.editor,domAttributes:n.domAttributes})),o.implementation.node.configure({editor:n.editor,domAttributes:n.domAttributes})]),bo(n.editor),ko(n.editor),Xt.Dropcursor.configure({width:5,color:"#ddeeff"}),Co];if(n.collaboration){if(t.push(un.default.configure({fragment:n.collaboration.fragment})),(e=n.collaboration.provider)!=null&&e.awareness){const o=i=>{const r=document.createElement("span");r.classList.add("collaboration-cursor__caret"),r.setAttribute("style",`border-color: ${i.color}`);const s=document.createElement("span");s.classList.add("collaboration-cursor__label"),s.setAttribute("style",`background-color: ${i.color}`),s.insertBefore(document.createTextNode(i.name),null);const a=document.createTextNode(""),l=document.createTextNode("");return r.insertBefore(a,null),r.insertBefore(s,null),r.insertBefore(l,null),r};t.push(pn.default.configure({user:n.collaboration.user,render:n.collaboration.renderCursor||o,provider:n.collaboration.provider}))}}else t.push(Zt.History);return t};function Ao(n,t){const e=[];return n.forEach((o,i,r)=>{r!==t&&e.push(o)}),k.Fragment.from(e)}function Do(n,t){let e=k.Fragment.from(n.content);for(let o=0;o<e.childCount;o++)if(e.child(o).type.spec.group==="blockContent"){const i=[e.child(o)];if(o+1<e.childCount&&e.child(o+1).type.spec.group==="blockGroup"){const s=e.child(o+1).child(0).child(0);(s.type.name==="bulletListItem"||s.type.name==="numberedListItem")&&(i.push(e.child(o+1)),e=Ao(e,o+1))}const r=t.state.schema.nodes.blockContainer.create(void 0,i);e=e.replaceChild(o,r)}return new k.Slice(e,n.openStart,n.openEnd)}const Vo="",Uo="",_o={enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!1};class Ie{constructor(t){p(this,"_tiptapEditor");p(this,"blockCache",new WeakMap);p(this,"blockSchema");p(this,"inlineContentSchema");p(this,"styleSchema");p(this,"blockImplementations");p(this,"inlineContentImplementations");p(this,"styleImplementations");p(this,"ready",!1);p(this,"sideMenu");p(this,"formattingToolbar");p(this,"slashMenu");p(this,"hyperlinkToolbar");p(this,"imageToolbar");p(this,"tableHandles");p(this,"uploadFile");var l,d,u,h,f,m,g,E,M,x;this.options=t;const e={defaultStyles:!0,blockSpecs:t.blockSpecs||Se,styleSpecs:t.styleSpecs||Te,inlineContentSpecs:t.inlineContentSpecs||Ce,...t};this.blockSchema=ye(e.blockSpecs),this.inlineContentSchema=ke(e.inlineContentSpecs),this.styleSchema=ve(e.styleSpecs),this.blockImplementations=e.blockSpecs,this.inlineContentImplementations=e.inlineContentSpecs,this.styleImplementations=e.styleSpecs,this.sideMenu=new St(this),this.formattingToolbar=new ht(this),this.slashMenu=new bt(this,e.slashMenuItems||Et(this.blockSchema)),this.hyperlinkToolbar=new ft(this),this.imageToolbar=new ot(this),this.blockSchema.table===Ee.table&&(this.tableHandles=new Mt(this));const o=Bt({editor:this,domAttributes:e.domAttributes||{},blockSchema:this.blockSchema,blockSpecs:e.blockSpecs,styleSpecs:e.styleSpecs,inlineContentSpecs:e.inlineContentSpecs,collaboration:e.collaboration}),i=b.Extension.create({name:"BlockNoteUIExtension",addProseMirrorPlugins:()=>[this.sideMenu.plugin,this.formattingToolbar.plugin,this.slashMenu.plugin,this.hyperlinkToolbar.plugin,this.imageToolbar.plugin,...this.tableHandles?[this.tableHandles.plugin]:[]]});o.push(i),this.uploadFile=e.uploadFile,e.collaboration&&e.initialContent&&console.warn("When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider");const r=e.initialContent||(t.collaboration?void 0:[{type:"paragraph",id:$.options.generateID()}]),s=this.styleSchema,a={..._o,...e._tiptapOptions,onBeforeCreate(S){var H,Y;(Y=(H=e._tiptapOptions)==null?void 0:H.onBeforeCreate)==null||Y.call(H,S);const w=S.editor.schema;let C;const B=w.nodes.doc.createAndFill;w.nodes.doc.createAndFill=(...te)=>{if(C)return C;const q=B.apply(w.nodes.doc,te),Nt=JSON.parse(JSON.stringify(q.toJSON()));return Nt.content[0].content[0].attrs.id="initialBlockId",C=k.Node.fromJSON(w,Nt),q};const v=w.node("doc",void 0,w.node("blockGroup",void 0,[_({id:"initialBlockId",type:"paragraph"},w,s)]));S.editor.options.content=v.toJSON()},onCreate:S=>{var w,C,B;(C=(w=e._tiptapOptions)==null?void 0:w.onCreate)==null||C.call(w,S),r!==void 0&&this.replaceBlocks(this.topLevelBlocks,r),(B=e.onEditorReady)==null||B.call(e,this),this.ready=!0},onUpdate:S=>{var w,C,B;(C=(w=e._tiptapOptions)==null?void 0:w.onUpdate)==null||C.call(w,S),this.ready&&((B=e.onEditorContentChange)==null||B.call(e,this))},onSelectionUpdate:S=>{var w,C,B;(C=(w=e._tiptapOptions)==null?void 0:w.onSelectionUpdate)==null||C.call(w,S),this.ready&&((B=e.onTextCursorPositionChange)==null||B.call(e,this))},editable:t.editable!==void 0?t.editable:((l=e._tiptapOptions)==null?void 0:l.editable)!==void 0?(d=e._tiptapOptions)==null?void 0:d.editable:!0,extensions:e.enableBlockNoteExtensions===!1?((u=e._tiptapOptions)==null?void 0:u.extensions)||[]:[...((h=e._tiptapOptions)==null?void 0:h.extensions)||[],...o],editorProps:{...(f=e._tiptapOptions)==null?void 0:f.editorProps,attributes:{...(g=(m=e._tiptapOptions)==null?void 0:m.editorProps)==null?void 0:g.attributes,...(E=e.domAttributes)==null?void 0:E.editor,class:O("bn-root","bn-editor",e.defaultStyles?"bn-default-styles":"",((x=(M=e.domAttributes)==null?void 0:M.editor)==null?void 0:x.class)||"")},transformPasted:Do}};e.parentElement&&(a.element=e.parentElement),this._tiptapEditor=new b.Editor(a)}static create(t={}){return new Ie(t)}get prosemirrorView(){return this._tiptapEditor.view}get domElement(){return this._tiptapEditor.view.dom}isFocused(){return this._tiptapEditor.view.hasFocus()}focus(){this._tiptapEditor.view.focus()}get topLevelBlocks(){const t=[];return this._tiptapEditor.state.doc.firstChild.descendants(e=>(t.push(L(e,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache)),!1)),t}getBlock(t){const e=typeof t=="string"?t:t.id;let o;return this._tiptapEditor.state.doc.firstChild.descendants(i=>typeof o<"u"?!1:i.type.name!=="blockContainer"||i.attrs.id!==e?!0:(o=L(i,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),!1)),o}forEachBlock(t,e=!1){const o=this.topLevelBlocks.slice();e&&o.reverse();function i(r){for(const s of r){if(!t(s))return!1;const a=e?s.children.slice().reverse():s.children;if(!i(a))return!1}return!0}i(o)}onEditorContentChange(t){this._tiptapEditor.on("update",t)}onEditorSelectionChange(t){this._tiptapEditor.on("selectionUpdate",t)}getTextCursorPosition(){const{node:t,depth:e,startPos:o,endPos:i}=T(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from),r=this._tiptapEditor.state.doc.resolve(i).index(e-1),s=this._tiptapEditor.state.doc.resolve(i+1).node().childCount;let a;r>0&&(a=this._tiptapEditor.state.doc.resolve(o-2).node());let l;return r<s-1&&(l=this._tiptapEditor.state.doc.resolve(i+2).node()),{block:L(t,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),prevBlock:a===void 0?void 0:L(a,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache),nextBlock:l===void 0?void 0:L(l,this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache)}}setTextCursorPosition(t,e="start"){const o=typeof t=="string"?t:t.id,{posBeforeNode:i}=Me(o,this._tiptapEditor.state.doc),{startPos:r,contentNode:s}=T(this._tiptapEditor.state.doc,i+2),a=this.blockSchema[s.type.name].content;if(a==="none"){this._tiptapEditor.commands.setNodeSelection(r);return}if(a==="inline")e==="start"?this._tiptapEditor.commands.setTextSelection(r+1):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-1);else if(a==="table")e==="start"?this._tiptapEditor.commands.setTextSelection(r+4):this._tiptapEditor.commands.setTextSelection(r+s.nodeSize-4);else throw new A(a)}getSelection(){if(this._tiptapEditor.state.selection.from===this._tiptapEditor.state.selection.to||"node"in this._tiptapEditor.state.selection)return;const t=[];return this._tiptapEditor.state.doc.descendants((e,o)=>e.type.spec.group!=="blockContent"||o+e.nodeSize<this._tiptapEditor.state.selection.from||o>this._tiptapEditor.state.selection.to?!0:(t.push(L(this._tiptapEditor.state.doc.resolve(o).node(),this.blockSchema,this.inlineContentSchema,this.styleSchema,this.blockCache)),!1)),{blocks:t}}get isEditable(){return this._tiptapEditor.isEditable}set isEditable(t){this._tiptapEditor.setEditable(t)}insertBlocks(t,e,o="before"){at(t,e,o,this)}updateBlock(t,e){Jn(t,e,this._tiptapEditor)}removeBlocks(t){lt(t,this._tiptapEditor)}replaceBlocks(t,e){Yn(t,e,this)}getActiveStyles(){const t={},e=this._tiptapEditor.state.selection.$to.marks();for(const o of e){const i=this.styleSchema[o.type.name];if(!i){console.warn("mark not found in styleschema",o.type.name);continue}i.propSchema==="boolean"?t[i.type]=!0:t[i.type]=o.attrs.stringValue}return t}addStyles(t){this._tiptapEditor.view.focus();for(const[e,o]of Object.entries(t)){const i=this.styleSchema[e];if(!i)throw new Error(`style ${e} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.setMark(e);else if(i.propSchema==="string")this._tiptapEditor.commands.setMark(e,{stringValue:o});else throw new A(i.propSchema)}}removeStyles(t){this._tiptapEditor.view.focus();for(const e of Object.keys(t))this._tiptapEditor.commands.unsetMark(e)}toggleStyles(t){this._tiptapEditor.view.focus();for(const[e,o]of Object.entries(t)){const i=this.styleSchema[e];if(!i)throw new Error(`style ${e} not found in styleSchema`);if(i.propSchema==="boolean")this._tiptapEditor.commands.toggleMark(e);else if(i.propSchema==="string")this._tiptapEditor.commands.toggleMark(e,{stringValue:o});else throw new A(i.propSchema)}}getSelectedText(){return this._tiptapEditor.state.doc.textBetween(this._tiptapEditor.state.selection.from,this._tiptapEditor.state.selection.to)}getSelectedLinkUrl(){return this._tiptapEditor.getAttributes("link").href}createLink(t,e){if(t==="")return;const{from:o,to:i}=this._tiptapEditor.state.selection;e||(e=this._tiptapEditor.state.doc.textBetween(o,i));const r=this._tiptapEditor.schema.mark("link",{href:t});this._tiptapEditor.view.dispatch(this._tiptapEditor.view.state.tr.insertText(e,o,i).addMark(o,o+e.length,r))}canNestBlock(){const{startPos:t,depth:e}=T(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return this._tiptapEditor.state.doc.resolve(t).index(e-1)>0}nestBlock(){this._tiptapEditor.commands.sinkListItem("blockContainer")}canUnnestBlock(){const{depth:t}=T(this._tiptapEditor.state.doc,this._tiptapEditor.state.selection.from);return t>2}unnestBlock(){this._tiptapEditor.commands.liftListItem("blockContainer")}async blocksToHTMLLossy(t=this.topLevelBlocks){return Z(this._tiptapEditor.schema,this).exportBlocks(t)}async tryParseHTMLToBlocks(t){return ct(t,this.blockSchema,this.inlineContentSchema,this.styleSchema,this._tiptapEditor.schema)}async blocksToMarkdownLossy(t=this.topLevelBlocks){return Qn(t,this._tiptapEditor.schema,this)}async tryParseMarkdownToBlocks(t){return ro(t,this.blockSchema,this.inlineContentSchema,this.styleSchema,this._tiptapEditor.schema)}updateCollaborationUserInfo(t){if(!this.options.collaboration)throw new Error("Cannot update collaboration user info when collaboration is disabled.");this._tiptapEditor.commands.updateUser(t)}}function Pe(n=""){return typeof n=="string"?[{type:"text",text:n,styles:{}}]:n}function It(n){return typeof n=="string"?Pe(n):Array.isArray(n)?n.flatMap(t=>typeof t=="string"?Pe(t):ce(t)?{...t,content:Pe(t.content)}:G(t)?t:{props:{},...t,content:It(t.content)}):n}function Oo(n,t){return t.map(e=>He(n,e))}function He(n,t){const e={id:"",type:t.type,props:{},content:n[t.type].content==="inline"?[]:void 0,children:[],...t};return Object.entries(n[t.type].propSchema).forEach(([o,i])=>{e.props[o]===void 0&&(e.props[o]=i.default)}),{...e,content:It(e.content),children:e.children.map(o=>He(n,o))}}function Pt(n){n.id||(n.id=$.options.generateID()),n.children&&Ht(n.children)}function Ht(n){for(const t of n)Pt(t)}c.BlockNoteEditor=Ie,c.FormattingToolbarProsemirrorPlugin=ht,c.FormattingToolbarView=ut,c.HyperlinkToolbarProsemirrorPlugin=ft,c.ImageToolbarProsemirrorPlugin=ot,c.ImageToolbarView=nt,c.SideMenuProsemirrorPlugin=St,c.SideMenuView=wt,c.SlashMenuProsemirrorPlugin=bt,c.TableHandlesProsemirrorPlugin=Mt,c.TableHandlesView=Ct,c.UniqueID=$,c.UnreachableCaseError=A,c.addIdsToBlock=Pt,c.addIdsToBlocks=Ht,c.addInlineContentAttributes=We,c.addInlineContentKeyboardShortcuts=Xe,c.addStyleAttributes=et,c.blockToNode=_,c.camelToDataKebab=ee,c.contentNodeToInlineContent=oe,c.createBlockSpec=Ke,c.createBlockSpecFromStronglyTypedTiptapNode=j,c.createExternalHTMLExporter=Z,c.createInlineContentSpec=vn,c.createInlineContentSpecFromTipTapNode=Ye,c.createInternalBlockSpec=be,c.createInternalHTMLSerializer=me,c.createInternalInlineContentSpec=Je,c.createInternalStyleSpec=we,c.createStronglyTypedTiptapNode=U,c.createStyleSpec=Sn,c.createStyleSpecFromTipTapMark=R,c.defaultBlockSchema=Ee,c.defaultBlockSpecs=Se,c.defaultInlineContentSchema=Xn,c.defaultInlineContentSpecs=Ce,c.defaultProps=P,c.defaultStyleSchema=Wn,c.defaultStyleSpecs=Te,c.formatKeyboardShortcut=wn,c.formattingToolbarPluginKey=pt,c.getBlockFromPos=Ge,c.getBlockNoteExtensions=Bt,c.getBlockSchemaFromSpecs=ye,c.getDefaultSlashMenuItems=Et,c.getDraggableBlockFromCoords=se,c.getInlineContentParseRules=Ze,c.getInlineContentSchemaFromSpecs=ke,c.getParseRules=je,c.getStyleParseRules=tt,c.getStyleSchemaFromSpecs=ve,c.hyperlinkToolbarPluginKey=mt,c.imageToolbarPluginKey=W,c.inheritedProps=fe,c.inlineContentToNodes=ne,c.isAppleOS=qe,c.isLinkInlineContent=de,c.isPartialLinkInlineContent=ce,c.isStyledTextInlineContent=G,c.mergeCSSClasses=O,c.nodeToBlock=L,c.nodeToCustomInlineContent=he,c.partialBlockToBlockForTesting=He,c.partialBlocksToBlocksForTesting=Oo,c.propsToAttributes=ge,c.setupSuggestionsMenu=gt,c.sideMenuPluginKey=vt,c.slashMenuPluginKey=re,c.stylePropsToAttributes=Qe,c.tableContentToNodes=pe,c.tableHandlesPluginKey=J,c.uploadToTmpFilesDotOrg_DEV_ONLY=kn,c.wrapInBlockStructure=ie,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
8
8
|
//# sourceMappingURL=blocknote.umd.cjs.map
|