@blocknote/core 0.54.2 → 0.56.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/BlockNoteExtension-DjEkXkR5.cjs +2 -0
- package/dist/BlockNoteExtension-DjEkXkR5.cjs.map +1 -0
- package/dist/{BlockNoteExtension-CbvDA0F7.js → BlockNoteExtension-TsTGtIeX.js} +34 -27
- package/dist/BlockNoteExtension-TsTGtIeX.js.map +1 -0
- package/dist/{UserStore-mj3fXW4D.cjs → UserStore-CTVzVGh-.cjs} +2 -2
- package/dist/{UserStore-mj3fXW4D.cjs.map → UserStore-CTVzVGh-.cjs.map} +1 -1
- package/dist/{UserStore-C4TzkGEn.js → UserStore-OZJP3K8T.js} +2 -2
- package/dist/{UserStore-C4TzkGEn.js.map → UserStore-OZJP3K8T.js.map} +1 -1
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -6
- package/dist/blocks-COVwe5Cf.cjs +12 -0
- package/dist/blocks-COVwe5Cf.cjs.map +1 -0
- package/dist/{blocks-Dol85hpH.js → blocks-COYcDVg7.js} +1577 -1155
- package/dist/blocks-COYcDVg7.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +69 -43
- package/dist/comments.js.map +1 -1
- package/dist/{en-uzHzj6eH.js → en-Ch-vvt5e.js} +40 -3
- package/dist/en-Ch-vvt5e.js.map +1 -0
- package/dist/en-N5lu0-j8.cjs +2 -0
- package/dist/en-N5lu0-j8.cjs.map +1 -0
- package/dist/extensions-BbM81hHa.js +3069 -0
- package/dist/extensions-BbM81hHa.js.map +1 -0
- package/dist/extensions-D_WkAfSt.cjs +58 -0
- package/dist/extensions-D_WkAfSt.cjs.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +4 -4
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +859 -45
- package/dist/locales.js.map +1 -1
- package/dist/src-4OQT3z5S.cjs +23 -0
- package/dist/src-4OQT3z5S.cjs.map +1 -0
- package/dist/src-BmLsLZfE.js +3491 -0
- package/dist/src-BmLsLZfE.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +1 -1
- package/dist/y.cjs.map +1 -1
- package/dist/y.js +1284 -554
- package/dist/y.js.map +1 -1
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +189 -148
- package/dist/yjs.js.map +1 -1
- package/package.json +18 -18
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +45 -6
- package/src/api/blockManipulation/commands/insertBlocks/insertPlacement.test.ts +217 -0
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +113 -9
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +151 -163
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +47 -31
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +122 -181
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +256 -0
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +80 -40
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +71 -0
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +39 -31
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +221 -8
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +40 -8
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +272 -40
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +138 -117
- package/src/api/blockManipulation/getBlock/getBlock.ts +4 -11
- package/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.ts +173 -0
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.ts +293 -0
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.ts +145 -0
- package/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.ts +783 -0
- package/src/api/blockManipulation/layoutBlocks/plainBlocks.test.ts +180 -0
- package/src/api/blockManipulation/layoutBlocks/titledBlocks.test.ts +365 -0
- package/src/api/blockManipulation/selections/selection.ts +20 -53
- package/src/api/blockManipulation/selections/textCursorPosition.ts +17 -72
- package/src/api/blockManipulation/setupTestEnv.ts +38 -6
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +4 -4
- package/src/api/clipboard/toClipboard/copyExtension.ts +3 -3
- package/src/api/combineTransactionSteps.ts +22 -0
- package/src/api/exporters/html/externalHTMLExporter.ts +1 -1
- package/src/api/exporters/html/internalHTMLSerializer.ts +4 -4
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +111 -36
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +51 -21
- package/src/api/exporters/markdown/htmlToMarkdown.ts +12 -1
- package/src/api/exporters/markdown/markdownExporter.ts +1 -1
- package/src/api/getBlockInfoFromPos.test.ts +428 -3
- package/src/api/getBlockInfoFromPos.ts +531 -129
- package/src/api/getBlocksChangedByTransaction.test.ts +7 -7
- package/src/api/getBlocksChangedByTransaction.ts +3 -3
- package/src/api/{getChangedRange.ts → getChangedRangeWithAttrs.ts} +2 -2
- package/src/api/getChangedRanges.test.ts +391 -0
- package/src/api/getChangedRanges.ts +368 -0
- package/src/api/nodeConversions/blockToNode.ts +44 -16
- package/src/api/nodeConversions/fragmentToBlocks.ts +29 -44
- package/src/api/nodeConversions/nodeToBlock.ts +120 -68
- package/src/api/nodeUtil.ts +1 -1
- package/src/api/parsers/markdown/autolink.ts +23 -0
- package/src/api/parsers/markdown/markdownToHtml.ts +115 -11
- package/src/blocks/Code/block.test.ts +4 -4
- package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +6 -1
- package/src/blocks/Heading/block.ts +54 -15
- package/src/blocks/ListItem/BulletListItem/block.ts +6 -4
- package/src/blocks/ListItem/CheckListItem/block.test.ts +2 -2
- package/src/blocks/ListItem/CheckListItem/block.ts +6 -4
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +14 -17
- package/src/blocks/ListItem/NumberedListItem/block.ts +6 -4
- package/src/blocks/ListItem/ToggleListItem/block.ts +23 -12
- package/src/blocks/Table/block.ts +2 -10
- package/src/blocks/ToggleWrapper/createToggleFrame.ts +126 -0
- package/src/blocks/ToggleWrapper/toggleBlocks.browser.test.ts +1056 -0
- package/src/blocks/defaultBlockTypeItems.test.ts +70 -0
- package/src/blocks/defaultBlockTypeItems.ts +99 -0
- package/src/blocks/defaultBlocks.test.ts +67 -0
- package/src/blocks/defaultBlocks.ts +7 -1
- package/src/blocks/index.ts +2 -1
- package/src/comments/CommentEditorSubmitExtension.test.ts +141 -0
- package/src/comments/CommentEditorSubmitExtension.ts +56 -0
- package/src/comments/extension.ts +8 -0
- package/src/comments/index.ts +1 -0
- package/src/editor/Block.css +286 -154
- package/src/editor/BlockNoteEditor.node.test.ts +35 -0
- package/src/editor/BlockNoteEditor.test.ts +2 -2
- package/src/editor/BlockNoteEditor.ts +165 -50
- package/src/editor/BlockNoteExtension.ts +11 -6
- package/src/editor/blockColors.browser.test.ts +127 -0
- package/src/editor/editor.css +60 -0
- package/src/editor/managers/BlockManager.ts +4 -3
- package/src/editor/managers/EventManager.browser.test.ts +334 -0
- package/src/editor/managers/EventManager.ts +128 -31
- package/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.ts +45 -0
- package/src/editor/managers/ExtensionManager/ExtensionManager.node.test.ts +209 -0
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +88 -1
- package/src/editor/managers/ExtensionManager/extensions.ts +10 -1
- package/src/editor/managers/ExtensionManager/index.ts +165 -75
- package/src/editor/managers/StateManager.ts +14 -4
- package/src/editor/managers/StyleManager.browser.test.ts +122 -0
- package/src/editor/managers/StyleManager.test.ts +98 -0
- package/src/editor/managers/StyleManager.ts +31 -15
- package/src/editor/managers/index.ts +1 -0
- package/src/editor/transformPasted.ts +14 -13
- package/src/exporter/Exporter.test.ts +70 -1
- package/src/exporter/Exporter.ts +34 -4
- package/src/exporter/mapping.ts +41 -10
- package/src/extensions/DropCursor/DropCursor.ts +119 -6
- package/src/extensions/DropCursor/dropIntoChildren.ts +80 -0
- package/src/extensions/FormattingToolbar/FormattingToolbar.ts +29 -0
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.ts +190 -0
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +41 -4
- package/src/extensions/Placeholder/Placeholder.test.ts +23 -0
- package/src/extensions/Placeholder/Placeholder.ts +8 -7
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +36 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +8 -4
- package/src/extensions/ReadOnly/ReadOnly.test.ts +181 -0
- package/src/extensions/ReadOnly/ReadOnly.ts +73 -0
- package/src/extensions/SideMenu/SideMenu.ts +401 -749
- package/src/extensions/SideMenu/blockDropHandling.ts +372 -0
- package/src/extensions/SideMenu/blockGeometry.browser.test.ts +148 -0
- package/src/extensions/SideMenu/blockGeometry.test.ts +46 -0
- package/src/extensions/SideMenu/blockGeometry.ts +53 -0
- package/src/extensions/SideMenu/dragging.ts +19 -32
- package/src/extensions/SideMenu/sideMenuHover.test.ts +36 -0
- package/src/extensions/SideMenu/sideMenuHover.ts +270 -0
- package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +5 -4
- package/src/extensions/SuggestionMenu/SuggestionMenu.ts +10 -1
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +36 -136
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +14 -4
- package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +1 -1
- package/src/extensions/SyntaxHighlighting/shiki.ts +1 -1
- package/src/extensions/TableHandles/TableHandles.browser.test.ts +3 -1
- package/src/extensions/TableHandles/TableHandles.ts +4 -6
- package/src/extensions/Versioning/Versioning.browser.test.ts +151 -0
- package/src/extensions/Versioning/Versioning.node.test.ts +177 -0
- package/src/extensions/Versioning/Versioning.ts +145 -612
- package/src/extensions/Versioning/__test__/result.ts +12 -0
- package/src/extensions/Versioning/comparison.test.ts +40 -0
- package/src/extensions/Versioning/createVersioning.test.ts +867 -0
- package/src/extensions/Versioning/createVersioning.ts +499 -0
- package/src/extensions/Versioning/formatVersionDate.ts +24 -0
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +533 -430
- package/src/extensions/Versioning/inMemoryVersioning.ts +246 -251
- package/src/extensions/Versioning/index.ts +4 -0
- package/src/extensions/Versioning/scrollScheduling.test.ts +51 -0
- package/src/extensions/Versioning/scrollToFirstChange.test.ts +320 -0
- package/src/extensions/Versioning/scrollToFirstChange.ts +139 -0
- package/src/extensions/Versioning/types.ts +219 -0
- package/src/extensions/Versioning/versioningState.ts +154 -0
- package/src/extensions/blockDOM.browser.test.ts +102 -0
- package/src/extensions/blockDOM.test.ts +178 -0
- package/src/extensions/blockDOM.ts +135 -0
- package/src/extensions/index.ts +2 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +1719 -53
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +645 -531
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.ts +152 -0
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +4 -9
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +10 -24
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +22 -19
- package/src/fonts/inter.browser.test.ts +57 -0
- package/src/fonts/inter.css +111 -0
- package/src/i18n/locales/ar.ts +33 -0
- package/src/i18n/locales/de.ts +33 -0
- package/src/i18n/locales/en.ts +33 -0
- package/src/i18n/locales/es.ts +33 -0
- package/src/i18n/locales/fa.ts +33 -0
- package/src/i18n/locales/fr.ts +33 -0
- package/src/i18n/locales/he.ts +33 -0
- package/src/i18n/locales/hr.ts +33 -0
- package/src/i18n/locales/is.ts +33 -0
- package/src/i18n/locales/it.ts +33 -0
- package/src/i18n/locales/ja.ts +33 -0
- package/src/i18n/locales/ko.ts +33 -0
- package/src/i18n/locales/nl.ts +33 -0
- package/src/i18n/locales/no.ts +33 -0
- package/src/i18n/locales/pl.ts +33 -0
- package/src/i18n/locales/pt.ts +33 -0
- package/src/i18n/locales/ru.ts +33 -0
- package/src/i18n/locales/sk.ts +33 -0
- package/src/i18n/locales/uk.ts +33 -0
- package/src/i18n/locales/uz.ts +33 -0
- package/src/i18n/locales/vi.ts +33 -0
- package/src/i18n/locales/zh-tw.ts +33 -0
- package/src/i18n/locales/zh.ts +33 -0
- package/src/index.ts +14 -3
- package/src/pm-nodes/BlockContainer.test.ts +101 -0
- package/src/pm-nodes/BlockContainer.ts +110 -1
- package/src/pm-nodes/BlockGroup.ts +2 -1
- package/src/pm-nodes/README.md +2 -0
- package/src/schema/blocks/children.test.ts +288 -0
- package/src/schema/blocks/children.ts +136 -0
- package/src/schema/blocks/createSpec.browser.test.ts +176 -0
- package/src/schema/blocks/createSpec.test.ts +231 -0
- package/src/schema/blocks/createSpec.ts +493 -267
- package/src/schema/blocks/frame.test.ts +112 -0
- package/src/schema/blocks/frame.ts +337 -0
- package/src/schema/blocks/internal.ts +50 -17
- package/src/schema/blocks/keyboard.ts +154 -0
- package/src/schema/blocks/layoutBlockAttributes.ts +29 -0
- package/src/schema/blocks/meta.test.ts +53 -0
- package/src/schema/blocks/meta.ts +35 -0
- package/src/schema/blocks/renderFrame.test.ts +691 -0
- package/src/schema/blocks/types.ts +285 -21
- package/src/schema/blocks/validateChildren.ts +156 -0
- package/src/schema/dataAttributes.test.ts +72 -0
- package/src/schema/dataAttributes.ts +69 -0
- package/src/schema/index.ts +3 -0
- package/src/schema/inlineContent/internal.ts +7 -12
- package/src/schema/markGroups.ts +34 -2
- package/src/schema/schema.ts +8 -1
- package/src/user/userColors.test.ts +108 -0
- package/src/user/userColors.ts +42 -13
- package/src/util/browser.ts +24 -0
- package/src/y/comments/RESTYjsThreadStore.ts +1 -1
- package/src/y/comments/YjsThreadStore.test.ts +1 -1
- package/src/y/comments/YjsThreadStore.ts +27 -27
- package/src/y/comments/YjsThreadStoreBase.ts +2 -2
- package/src/y/comments/yjsHelpers.ts +11 -11
- package/src/y/extensions/AttributionExtension.test.ts +271 -2
- package/src/y/extensions/AttributionExtension.ts +146 -123
- package/src/y/extensions/DiffVersioningExtension.test.ts +67 -18
- package/src/y/extensions/DiffVersioningExtension.ts +95 -123
- package/src/y/extensions/EmptyDocBinding.test.ts +282 -0
- package/src/y/extensions/ForkYDoc.node.test.ts +77 -0
- package/src/y/extensions/ForkYDoc.test.ts +93 -2
- package/src/y/extensions/ForkYDoc.ts +22 -13
- package/src/y/extensions/History.test.ts +125 -0
- package/src/y/extensions/RelativePositionMapping.test.ts +35 -0
- package/src/y/extensions/RelativePositionMapping.ts +7 -11
- package/src/y/extensions/Versioning.node.test.ts +126 -0
- package/src/y/extensions/Versioning.test.ts +110 -401
- package/src/y/extensions/Versioning.ts +66 -107
- package/src/y/extensions/YAttributionMarks.ts +111 -9
- package/src/y/extensions/YCursorPlugin.ts +3 -0
- package/src/y/extensions/YSync.node.test.ts +75 -0
- package/src/y/extensions/YSync.ts +76 -4
- package/src/y/extensions/YSyncRemount.test.ts +99 -0
- package/src/y/extensions/blockMatchNodes.ts +20 -29
- package/src/y/extensions/index.ts +10 -26
- package/src/y/extensions/legacyYjsDocBinding.test.ts +652 -0
- package/src/y/extensions/nestingChanges.test.ts +326 -0
- package/src/y/extensions/persistentBlockGroups.test.ts +1709 -0
- package/src/y/extensions/persistentBlockGroups.ts +953 -0
- package/src/y/extensions/snapshotCodec.test.ts +105 -0
- package/src/y/extensions/snapshotCodec.ts +39 -0
- package/src/y/extensions/snapshotPreview.test.ts +201 -0
- package/src/y/extensions/snapshotPreview.ts +292 -0
- package/src/y/extensions/tableReshape.test.ts +121 -0
- package/src/y/extensions/v1BindingSnapshotDiff.test.ts +121 -0
- package/src/y/extensions/versionDiffAttribution.test.ts +944 -0
- package/src/y/extensions/versionDiffPerformance.test.ts +101 -0
- package/src/y/index.ts +1 -0
- package/src/y/utils.test.ts +289 -22
- package/src/y/utils.ts +167 -43
- package/src/y/versioning/__test__/fixtures/activity-all-after.json +5 -5
- package/src/y/versioning/__test__/fixtures/activity-all.json +3 -3
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +2 -2
- package/src/y/versioning/__test__/yhub.test.ts +902 -721
- package/src/y/versioning/index.ts +6 -1
- package/src/y/versioning/yhub.ts +316 -603
- package/src/y/versioning/yhubClient.ts +345 -0
- package/src/yjs/comments/RESTYjsThreadStore.test.ts +10 -0
- package/src/yjs/extensions/FixUpSchema.ts +11 -0
- package/src/yjs/extensions/ForkYDoc.browser.test.ts +84 -0
- package/src/yjs/extensions/ForkYDoc.node.test.ts +231 -0
- package/src/yjs/extensions/ForkYDoc.test.ts +68 -1
- package/src/yjs/extensions/ForkYDoc.ts +57 -39
- package/src/yjs/extensions/Versioning.test.ts +345 -530
- package/src/yjs/extensions/Versioning.ts +111 -68
- package/src/yjs/extensions/index.ts +1 -1
- package/src/yjs/index.ts +4 -0
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +2 -1
- package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +24 -24
- package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +3 -2
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +1 -1
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -2
- package/types/src/api/blockManipulation/layoutBlocks/fixLayoutBlock.d.ts +34 -0
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.browser.test.d.ts +1 -0
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.fixture.d.ts +460 -0
- package/types/src/api/blockManipulation/layoutBlocks/layoutBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/layoutBlocks/plainBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/layoutBlocks/titledBlocks.test.d.ts +1 -0
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +15 -69
- package/types/src/api/combineTransactionSteps.d.ts +12 -0
- package/types/src/api/getBlockInfoFromPos.d.ts +218 -44
- package/types/src/api/{getChangedRange.d.ts → getChangedRangeWithAttrs.d.ts} +1 -1
- package/types/src/api/getChangedRanges.d.ts +23 -0
- package/types/src/api/getChangedRanges.test.d.ts +1 -0
- package/types/src/api/nodeConversions/fragmentToBlocks.d.ts +0 -3
- package/types/src/api/parsers/markdown/autolink.d.ts +5 -0
- package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +4 -0
- package/types/src/blocks/ToggleWrapper/createToggleFrame.d.ts +29 -0
- package/types/src/blocks/ToggleWrapper/toggleBlocks.browser.test.d.ts +1 -0
- package/types/src/blocks/defaultBlockTypeItems.d.ts +37 -0
- package/types/src/blocks/defaultBlockTypeItems.test.d.ts +1 -0
- package/types/src/blocks/defaultBlocks.test.d.ts +1 -0
- package/types/src/blocks/index.d.ts +2 -1
- package/types/src/comments/CommentEditorSubmitExtension.d.ts +19 -0
- package/types/src/comments/CommentEditorSubmitExtension.test.d.ts +1 -0
- package/types/src/comments/extension.d.ts +7 -0
- package/types/src/comments/index.d.ts +1 -0
- package/types/src/editor/BlockNoteEditor.d.ts +88 -27
- package/types/src/editor/BlockNoteEditor.node.test.d.ts +1 -0
- package/types/src/editor/BlockNoteExtension.d.ts +3 -0
- package/types/src/editor/blockColors.browser.test.d.ts +1 -0
- package/types/src/editor/managers/BlockManager.d.ts +4 -3
- package/types/src/editor/managers/EventManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/EventManager.d.ts +55 -0
- package/types/src/editor/managers/ExtensionManager/ExtensionManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/ExtensionManager/ExtensionManager.node.test.d.ts +1 -0
- package/types/src/editor/managers/ExtensionManager/index.d.ts +15 -3
- package/types/src/editor/managers/StateManager.d.ts +1 -1
- package/types/src/editor/managers/StyleManager.browser.test.d.ts +1 -0
- package/types/src/editor/managers/StyleManager.d.ts +4 -2
- package/types/src/editor/managers/StyleManager.test.d.ts +1 -0
- package/types/src/editor/managers/index.d.ts +1 -0
- package/types/src/editor/transformPasted.d.ts +1 -1
- package/types/src/exporter/Exporter.d.ts +11 -4
- package/types/src/exporter/mapping.d.ts +13 -1
- package/types/src/extensions/DropCursor/DropCursor.d.ts +1 -1
- package/types/src/extensions/DropCursor/dropIntoChildren.d.ts +38 -0
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.d.ts +1 -1
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.test.d.ts +1 -0
- package/types/src/extensions/Placeholder/Placeholder.test.d.ts +1 -0
- package/types/src/extensions/ReadOnly/ReadOnly.d.ts +21 -0
- package/types/src/extensions/ReadOnly/ReadOnly.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/SideMenu.d.ts +49 -88
- package/types/src/extensions/SideMenu/blockDropHandling.d.ts +11 -0
- package/types/src/extensions/SideMenu/blockGeometry.browser.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/blockGeometry.d.ts +22 -0
- package/types/src/extensions/SideMenu/blockGeometry.test.d.ts +1 -0
- package/types/src/extensions/SideMenu/dragging.d.ts +0 -4
- package/types/src/extensions/SideMenu/sideMenuHover.d.ts +58 -0
- package/types/src/extensions/SideMenu/sideMenuHover.test.d.ts +1 -0
- package/types/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.d.ts +3 -0
- package/types/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.d.ts +1 -0
- package/types/src/extensions/Versioning/Versioning.browser.test.d.ts +1 -0
- package/types/src/extensions/Versioning/Versioning.d.ts +34 -311
- package/types/src/extensions/Versioning/Versioning.node.test.d.ts +1 -0
- package/types/src/extensions/Versioning/__test__/result.d.ts +3 -0
- package/types/src/extensions/Versioning/comparison.test.d.ts +1 -0
- package/types/src/extensions/Versioning/createVersioning.d.ts +32 -0
- package/types/src/extensions/Versioning/createVersioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/formatVersionDate.d.ts +7 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +64 -36
- package/types/src/extensions/Versioning/index.d.ts +4 -0
- package/types/src/extensions/Versioning/scrollScheduling.test.d.ts +1 -0
- package/types/src/extensions/Versioning/scrollToFirstChange.d.ts +18 -0
- package/types/src/extensions/Versioning/scrollToFirstChange.test.d.ts +1 -0
- package/types/src/extensions/Versioning/types.d.ts +239 -0
- package/types/src/extensions/Versioning/versioningState.d.ts +43 -0
- package/types/src/extensions/blockDOM.browser.test.d.ts +1 -0
- package/types/src/extensions/blockDOM.d.ts +37 -0
- package/types/src/extensions/blockDOM.test.d.ts +1 -0
- package/types/src/extensions/index.d.ts +2 -0
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.d.ts +1 -0
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +3 -0
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/blockIdentity.browser.test.d.ts +1 -0
- package/types/src/fonts/inter.browser.test.d.ts +2 -0
- package/types/src/i18n/locales/en.d.ts +33 -0
- package/types/src/i18n/locales/fa.d.ts +33 -0
- package/types/src/i18n/locales/sk.d.ts +33 -0
- package/types/src/index.d.ts +7 -3
- package/types/src/pm-nodes/BlockContainer.d.ts +6 -0
- package/types/src/pm-nodes/BlockContainer.test.d.ts +1 -0
- package/types/src/schema/blocks/children.d.ts +39 -0
- package/types/src/schema/blocks/children.test.d.ts +1 -0
- package/types/src/schema/blocks/createSpec.browser.test.d.ts +1 -0
- package/types/src/schema/blocks/createSpec.d.ts +13 -0
- package/types/src/schema/blocks/frame.d.ts +109 -0
- package/types/src/schema/blocks/frame.test.d.ts +1 -0
- package/types/src/schema/blocks/internal.d.ts +6 -0
- package/types/src/schema/blocks/keyboard.d.ts +111 -0
- package/types/src/schema/blocks/layoutBlockAttributes.d.ts +9 -0
- package/types/src/schema/blocks/meta.d.ts +14 -0
- package/types/src/schema/blocks/meta.test.d.ts +1 -0
- package/types/src/schema/blocks/renderFrame.test.d.ts +1 -0
- package/types/src/schema/blocks/types.d.ts +228 -15
- package/types/src/schema/blocks/validateChildren.d.ts +5 -0
- package/types/src/schema/dataAttributes.d.ts +19 -0
- package/types/src/schema/dataAttributes.test.d.ts +1 -0
- package/types/src/schema/index.d.ts +3 -0
- package/types/src/schema/markGroups.d.ts +8 -0
- package/types/src/user/userColors.d.ts +24 -3
- package/types/src/user/userColors.test.d.ts +1 -0
- package/types/src/util/browser.d.ts +2 -0
- package/types/src/y/comments/RESTYjsThreadStore.d.ts +1 -1
- package/types/src/y/comments/YjsThreadStore.d.ts +1 -1
- package/types/src/y/comments/YjsThreadStoreBase.d.ts +2 -2
- package/types/src/y/comments/yjsHelpers.d.ts +5 -5
- package/types/src/y/extensions/AttributionExtension.d.ts +19 -21
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +9 -4
- package/types/src/y/extensions/EmptyDocBinding.test.d.ts +1 -0
- package/types/src/y/extensions/ForkYDoc.d.ts +3 -1
- package/types/src/y/extensions/ForkYDoc.node.test.d.ts +1 -0
- package/types/src/y/extensions/History.test.d.ts +1 -0
- package/types/src/y/extensions/Versioning.d.ts +4 -15
- package/types/src/y/extensions/Versioning.node.test.d.ts +1 -0
- package/types/src/y/extensions/YAttributionMarks.d.ts +13 -2
- package/types/src/y/extensions/YCursorPlugin.d.ts +1 -0
- package/types/src/y/extensions/YSync.d.ts +4 -18
- package/types/src/y/extensions/YSync.node.test.d.ts +1 -0
- package/types/src/y/extensions/YSyncRemount.test.d.ts +1 -0
- package/types/src/y/extensions/blockMatchNodes.d.ts +0 -22
- package/types/src/y/extensions/index.d.ts +27 -44
- package/types/src/y/extensions/legacyYjsDocBinding.test.d.ts +1 -0
- package/types/src/y/extensions/nestingChanges.test.d.ts +1 -0
- package/types/src/y/extensions/persistentBlockGroups.d.ts +189 -0
- package/types/src/y/extensions/persistentBlockGroups.test.d.ts +1 -0
- package/types/src/y/extensions/snapshotCodec.d.ts +13 -0
- package/types/src/y/extensions/snapshotCodec.test.d.ts +1 -0
- package/types/src/y/extensions/snapshotPreview.d.ts +21 -0
- package/types/src/y/extensions/snapshotPreview.test.d.ts +1 -0
- package/types/src/y/extensions/tableReshape.test.d.ts +1 -0
- package/types/src/y/extensions/v1BindingSnapshotDiff.test.d.ts +1 -0
- package/types/src/y/extensions/versionDiffAttribution.test.d.ts +1 -0
- package/types/src/y/extensions/versionDiffPerformance.test.d.ts +1 -0
- package/types/src/y/index.d.ts +1 -0
- package/types/src/y/utils.d.ts +39 -19
- package/types/src/y/versioning/index.d.ts +1 -1
- package/types/src/y/versioning/yhub.d.ts +69 -86
- package/types/src/y/versioning/yhubClient.d.ts +67 -0
- package/types/src/yjs/extensions/ForkYDoc.browser.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +2 -0
- package/types/src/yjs/extensions/ForkYDoc.node.test.d.ts +1 -0
- package/types/src/yjs/extensions/Versioning.d.ts +36 -22
- package/types/src/yjs/extensions/index.d.ts +2 -1
- package/types/src/yjs/index.d.ts +1 -0
- package/dist/BlockNoteExtension-BJCLnwrE.cjs +0 -2
- package/dist/BlockNoteExtension-BJCLnwrE.cjs.map +0 -1
- package/dist/BlockNoteExtension-CbvDA0F7.js.map +0 -1
- package/dist/blocks-CTB_5Vyj.cjs +0 -12
- package/dist/blocks-CTB_5Vyj.cjs.map +0 -1
- package/dist/blocks-Dol85hpH.js.map +0 -1
- package/dist/en-BuzSuuTq.cjs +0 -2
- package/dist/en-BuzSuuTq.cjs.map +0 -1
- package/dist/en-uzHzj6eH.js.map +0 -1
- package/dist/extensions-B7Rsp_Ft.cjs +0 -58
- package/dist/extensions-B7Rsp_Ft.cjs.map +0 -1
- package/dist/extensions-D6JcJCwd.js +0 -2138
- package/dist/extensions-D6JcJCwd.js.map +0 -1
- package/dist/src-Buuo5l7X.js +0 -3317
- package/dist/src-Buuo5l7X.js.map +0 -1
- package/dist/src-C54Ok9E0.cjs +0 -23
- package/dist/src-C54Ok9E0.cjs.map +0 -1
- package/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.ts +0 -173
- package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +0 -63
- package/src/blocks/ToggleWrapper/createToggleWrapper.ts +0 -197
- package/src/blocks/utils/listItemEnterHandler.ts +0 -43
- package/src/extensions/Versioning/Versioning.test.ts +0 -435
- package/src/extensions/getDraggableBlockFromElement.ts +0 -19
- package/types/src/api/blockManipulation/commands/replaceBlocks/util/fixColumnList.d.ts +0 -32
- package/types/src/blocks/ListItem/ListItemKeyboardShortcuts.d.ts +0 -2
- package/types/src/blocks/ToggleWrapper/createToggleWrapper.d.ts +0 -15
- package/types/src/blocks/utils/listItemEnterHandler.d.ts +0 -2
- package/types/src/extensions/getDraggableBlockFromElement.d.ts +0 -5
- /package/types/src/{extensions/Versioning/Versioning.test.d.ts → api/blockManipulation/commands/insertBlocks/insertPlacement.test.d.ts} +0 -0
|
@@ -0,0 +1,3491 @@
|
|
|
1
|
+
import { At as e, Cr as t, Dn as n, Dr as r, En as i, Er as a, Fr as o, Gn as s, Hn as c, Ht as l, Ir as u, Mn as d, Mr as f, Nr as p, On as m, Or as h, Ot as g, Pn as _, Pr as v, Qt as ee, Sr as te, St as ne, Tn as re, Tr as y, Un as ie, Xt as ae, Zt as oe, _n as se, _r as ce, bn as le, br as b, dr as ue, er as de, f as fe, fn as pe, fr as me, gn as he, gr as ge, hn as _e, hr as ve, kn as ye, kr as x, kt as S, m as be, mr as xe, pr as Se, t as Ce, tr as C, vr as w, wn as we, wr as Te, wt as Ee, xn as De, xr as T, yr as E, yt as Oe } from "./blocks-COYcDVg7.js";
|
|
2
|
+
import { r as ke, s as Ae, t as je } from "./BlockNoteExtension-TsTGtIeX.js";
|
|
3
|
+
import { C as Me, D as Ne, E as Pe, I as Fe, L as Ie, M as Le, N as Re, O as ze, P as Be, R as Ve, S as He, T as Ue, U as D, V as We, _ as Ge, b as Ke, g as qe, k as Je, l as Ye, u as Xe, v as Ze, w as Qe, x as $e, z as et } from "./extensions-BbM81hHa.js";
|
|
4
|
+
import { r as tt } from "./UserStore-OZJP3K8T.js";
|
|
5
|
+
import { t as nt } from "./en-Ch-vvt5e.js";
|
|
6
|
+
import { DOMParser as rt, DOMSerializer as it, Fragment as O, NodeRange as at, Slice as k } from "prosemirror-model";
|
|
7
|
+
import { ReplaceAroundStep as ot, ReplaceStep as st, canJoin as ct, liftTarget as lt } from "prosemirror-transform";
|
|
8
|
+
import { NodeSelection as A, Plugin as j, Selection as M, TextSelection as N } from "prosemirror-state";
|
|
9
|
+
import { DOMParser as ut, Fragment as P, Slice as F } from "@tiptap/pm/model";
|
|
10
|
+
import { Editor as dt, Extension as I, Mark as ft, Node as L, createDocument as pt, extensions as R, findChildrenInRange as mt, findParentNodeClosestToPos as ht, getAttributes as gt, getMarkRange as _t, getMarksBetween as vt, getSchema as yt, isNodeSelection as bt, markPasteRule as xt, mergeAttributes as St, posToDOMRect as Ct, selectionToInsertionEnd as wt } from "@tiptap/core";
|
|
11
|
+
import { CellSelection as z, TableMap as Tt } from "prosemirror-tables";
|
|
12
|
+
import { Plugin as B, PluginKey as V } from "@tiptap/pm/state";
|
|
13
|
+
import { digestString as Et } from "lib0/hash/fnv1a";
|
|
14
|
+
import { InputRule as Dt, inputRules as Ot } from "@handlewithcare/prosemirror-inputrules";
|
|
15
|
+
import { keydownHandler as kt } from "@tiptap/pm/keymap";
|
|
16
|
+
import { Text as At } from "@tiptap/extension-text";
|
|
17
|
+
import { Gapcursor as jt } from "@tiptap/extensions/gap-cursor";
|
|
18
|
+
//#region src/schema/blocks/types.ts
|
|
19
|
+
function Mt(e) {
|
|
20
|
+
return typeof e == "string" ? e : e.map((e) => typeof e == "string" ? e : e.text).join("");
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/schema/inlineContent/createSpec.ts
|
|
24
|
+
function Nt(e) {
|
|
25
|
+
return e.matches("[data-editable]") ? e : e.querySelector("[data-editable]") || e;
|
|
26
|
+
}
|
|
27
|
+
function Pt(e, t) {
|
|
28
|
+
return ut.fromSchema(t).parse(e, {
|
|
29
|
+
topNode: t.nodes.paragraph.create(),
|
|
30
|
+
preserveWhitespace: !0
|
|
31
|
+
}).content;
|
|
32
|
+
}
|
|
33
|
+
function Ft(e, t) {
|
|
34
|
+
let n = [];
|
|
35
|
+
return e.forEach((e) => {
|
|
36
|
+
if (e.isText) n.push(e);
|
|
37
|
+
else {
|
|
38
|
+
let r = e.type === t.linebreakReplacement ? "\n" : e.textContent;
|
|
39
|
+
r && n.push(t.text(r, e.marks));
|
|
40
|
+
}
|
|
41
|
+
}), P.fromArray(n);
|
|
42
|
+
}
|
|
43
|
+
function It(e, t, n) {
|
|
44
|
+
let r = e.content === "plain" || n && e.content === "styled" ? (t) => (r, i) => {
|
|
45
|
+
let a = n?.({
|
|
46
|
+
el: r,
|
|
47
|
+
schema: i
|
|
48
|
+
});
|
|
49
|
+
if (a !== void 0) return e.content === "plain" ? Ft(a, i) : a;
|
|
50
|
+
let o = Pt(t(r), i);
|
|
51
|
+
return e.content === "plain" ? Ft(o, i) : o;
|
|
52
|
+
} : void 0, i = [{
|
|
53
|
+
tag: `[data-inline-content-type="${e.type}"]`,
|
|
54
|
+
contentElement: (e) => Nt(e),
|
|
55
|
+
getContent: r ? (e, t) => r(Nt)(e, t) : void 0
|
|
56
|
+
}];
|
|
57
|
+
return t && i.push({
|
|
58
|
+
tag: "*",
|
|
59
|
+
getAttrs(e) {
|
|
60
|
+
if (typeof e == "string") return !1;
|
|
61
|
+
let n = t?.(e);
|
|
62
|
+
return n !== void 0 && n;
|
|
63
|
+
},
|
|
64
|
+
preserveWhitespace: r ? !0 : void 0,
|
|
65
|
+
getContent: r ? (e, t) => r((e) => e)(e, t) : void 0
|
|
66
|
+
}), i;
|
|
67
|
+
}
|
|
68
|
+
function Lt(e, t) {
|
|
69
|
+
let n = L.create({
|
|
70
|
+
name: e.type,
|
|
71
|
+
inline: !0,
|
|
72
|
+
group: "inline",
|
|
73
|
+
draggable: t.meta?.draggable,
|
|
74
|
+
selectable: e.content !== "none",
|
|
75
|
+
atom: e.content === "none",
|
|
76
|
+
code: t.meta?.code,
|
|
77
|
+
content: e.content === "styled" ? "inline*" : e.content === "plain" ? "text*" : "",
|
|
78
|
+
marks() {
|
|
79
|
+
return e.content === "plain" ? Ae(this.editor) : void 0;
|
|
80
|
+
},
|
|
81
|
+
addAttributes() {
|
|
82
|
+
return pe(e.propSchema);
|
|
83
|
+
},
|
|
84
|
+
addKeyboardShortcuts() {
|
|
85
|
+
return oe(e);
|
|
86
|
+
},
|
|
87
|
+
parseHTML() {
|
|
88
|
+
return It(e, t.parse, t.parseContent);
|
|
89
|
+
},
|
|
90
|
+
renderHTML({ node: n }) {
|
|
91
|
+
let r = this.options.editor, i = t.render.call({
|
|
92
|
+
renderType: "dom",
|
|
93
|
+
props: void 0
|
|
94
|
+
}, m(n, r.schema.inlineContentSchema, r.schema.styleSchema), () => {}, r, n, () => void 0);
|
|
95
|
+
return ae(i, e.type, n.attrs, e.propSchema);
|
|
96
|
+
},
|
|
97
|
+
addNodeView() {
|
|
98
|
+
return (n) => {
|
|
99
|
+
let { node: r, getPos: i } = n, a = this.options.editor, o = t.render.call({
|
|
100
|
+
renderType: "nodeView",
|
|
101
|
+
props: n
|
|
102
|
+
}, m(r, a.schema.inlineContentSchema, a.schema.styleSchema), (e) => {
|
|
103
|
+
let t = S([e], a.pmSchema), n = i();
|
|
104
|
+
n && a.transact((e) => e.replaceWith(n, n + r.nodeSize, t));
|
|
105
|
+
}, a, r, i), s = ae(o, e.type, r.attrs, e.propSchema);
|
|
106
|
+
return ie(s), s;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return ee(n, e.propSchema, {
|
|
111
|
+
...t,
|
|
112
|
+
toExternalHTML: t.toExternalHTML,
|
|
113
|
+
render(n, r, i) {
|
|
114
|
+
let a = S([n], i.pmSchema)[0], o = t.render(n, r, i, a, () => void 0);
|
|
115
|
+
return ae(o, e.type, n.props, e.propSchema);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts
|
|
121
|
+
function H(e, r, i, a = "before") {
|
|
122
|
+
let o = typeof i == "string" ? i : i.id, s = _(e), c = r.map((e) => {
|
|
123
|
+
let t = g(e, s);
|
|
124
|
+
return t.check(), t;
|
|
125
|
+
}), l = D(o, e.doc);
|
|
126
|
+
if (!l) throw Error(`Block with ID ${o} not found`);
|
|
127
|
+
if (c.length === 0) return [];
|
|
128
|
+
let u = t(e.doc, w(e.doc, l.posBeforeNode), a, c[0].type);
|
|
129
|
+
if (!u) throw Error(`Cannot insert blocks at "${a}" of block "${o}": no valid position for them`);
|
|
130
|
+
if (u.wrapIn && !u.wrapIn.validContent(O.from(c))) throw Error(`Cannot insert blocks at "${a}" of block "${o}": a "${u.wrapIn.name}" doesn't accept them`);
|
|
131
|
+
let d = u.wrapIn ? O.from(u.wrapIn.create(null, c)) : O.from(c), f = e.doc.resolve(u.pos);
|
|
132
|
+
if (!f.parent.canReplace(f.index(), f.index(), d)) throw Error(`Cannot insert blocks at "${a}" of block "${o}": a "${f.parent.type.name}" doesn't accept them`);
|
|
133
|
+
return e.step(new st(u.pos, u.pos, new k(d, 0, 0))), c.map((t) => n(t, e.doc));
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/api/blockManipulation/layoutBlocks/fixLayoutBlock.ts
|
|
137
|
+
function U(e) {
|
|
138
|
+
if (e.type.name === "blockContainer") {
|
|
139
|
+
let t = e.firstChild;
|
|
140
|
+
return e.childCount === 1 && !!t && t.type.name === "paragraph" && t.childCount === 0;
|
|
141
|
+
}
|
|
142
|
+
return v(e.type) ? e.childCount === 1 ? U(e.firstChild) : e.childCount === 0 && u(e.type.spec.blockConfig?.children) >= 1 : !1;
|
|
143
|
+
}
|
|
144
|
+
function Rt(e, t) {
|
|
145
|
+
let n = e.doc.resolve(t).nodeAfter;
|
|
146
|
+
if (!n || !v(n.type)) throw Error("Invalid layoutBlockPos: does not point to a layout block node.");
|
|
147
|
+
if (o(n.type)) return;
|
|
148
|
+
let r = n.type.spec.blockConfig?.children;
|
|
149
|
+
if (r && "dissolve" in r && r.dissolve === !1) return;
|
|
150
|
+
let i = u(n.type.spec.blockConfig?.children), a = [], s = [];
|
|
151
|
+
if (n.forEach((e, n) => {
|
|
152
|
+
if (!U(e)) a.push({
|
|
153
|
+
node: e,
|
|
154
|
+
offset: n
|
|
155
|
+
});
|
|
156
|
+
else if (v(e.type)) {
|
|
157
|
+
let r = t + 1 + n;
|
|
158
|
+
s.push({
|
|
159
|
+
from: r,
|
|
160
|
+
to: r + e.nodeSize
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}), a.length >= i) {
|
|
164
|
+
for (let { from: t, to: n } of s.reverse()) e.delete(t, n);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (a.length === 1) {
|
|
168
|
+
let [{ node: r, offset: i }] = a, s = t + 1 + i, c = o(r.type) ? {
|
|
169
|
+
from: s + 1,
|
|
170
|
+
to: s + r.nodeSize - 1
|
|
171
|
+
} : {
|
|
172
|
+
from: s,
|
|
173
|
+
to: s + r.nodeSize
|
|
174
|
+
};
|
|
175
|
+
e.step(new ot(t, t + n.nodeSize, c.from, c.to, k.empty, 0, !1));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
let c = [];
|
|
179
|
+
for (let { node: e } of a) o(e.type) ? e.forEach((e) => c.push(e)) : c.push(e);
|
|
180
|
+
e.replaceWith(t, t + n.nodeSize, O.from(c));
|
|
181
|
+
}
|
|
182
|
+
function zt(e, t) {
|
|
183
|
+
[...t].sort((e, t) => t.depth - e.depth).forEach(({ id: t }) => {
|
|
184
|
+
let n = D(t, e.doc);
|
|
185
|
+
n && v(n.node.type) && Rt(e, n.posBeforeNode);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts
|
|
190
|
+
function W(e, t, i, a = {}) {
|
|
191
|
+
let o = _(e), s = i.map((e) => {
|
|
192
|
+
let t = g(e, o);
|
|
193
|
+
return t.check(), t;
|
|
194
|
+
}), c = new Set(t.map((e) => typeof e == "string" ? e : e.id)), l = [], u = [], d = typeof t[0] == "string" ? t[0] : t[0].id, f = e.steps.length, p = (t) => e.mapping.slice(f).map(t);
|
|
195
|
+
if (e.doc.descendants((t, a) => {
|
|
196
|
+
if (c.size === 0) return !1;
|
|
197
|
+
if (!t.type.isInGroup("bnBlock")) return !0;
|
|
198
|
+
let o = r(t, e.doc);
|
|
199
|
+
if (!c.has(o)) return !0;
|
|
200
|
+
l.push(n(t, e.doc)), c.delete(o), i.length > 0 && o === d && e.insert(p(a), s);
|
|
201
|
+
let f = e.doc.resolve(p(a));
|
|
202
|
+
for (let e of ce(f.doc, f.pos)) u.some((t) => t.id === e.id) || u.push(e);
|
|
203
|
+
let m = f.node();
|
|
204
|
+
return m.type.name === "blockGroup" && f.node(f.depth - 1).type.name !== "doc" && m.childCount === 1 ? e.delete(f.before(), f.after()) : e.delete(f.pos, f.pos + t.nodeSize), !1;
|
|
205
|
+
}), c.size > 0) {
|
|
206
|
+
let e = [...c].join("\n");
|
|
207
|
+
throw Error("Blocks with the following IDs could not be found in the editor: " + e);
|
|
208
|
+
}
|
|
209
|
+
return a.fixLayoutBlocks !== !1 && zt(e, u), {
|
|
210
|
+
insertedBlocks: s.map((t) => n(t, e.doc)),
|
|
211
|
+
removedBlocks: l
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/api/blockManipulation/commands/updateBlock/updateBlock.ts
|
|
216
|
+
var G = (e, t) => ({ tr: n, dispatch: r }) => (r && K(n, e, t), !0);
|
|
217
|
+
function K(e, t, r, i, a) {
|
|
218
|
+
let o = e.mapping.maps.length, s = w(e.doc, t), c = s.hasContent && s.blockNoteType === "table" ? Gt(e) : null, l = _(e);
|
|
219
|
+
if (i !== void 0 && a !== void 0 && i > a) throw Error("Invalid replaceFromPos or replaceToPos");
|
|
220
|
+
let u = r.type || s.blockNoteType, f = l.nodes[u], p = f.isInGroup("bnBlock") ? f : l.nodes.blockContainer, m = s.hasContent && i !== void 0 && i >= s.contentStart && i <= s.contentEnd ? i - s.contentStart : void 0, h = s.hasContent && a !== void 0 && a >= s.contentStart && a <= s.contentEnd ? a - s.contentStart : void 0;
|
|
221
|
+
if (s.hasContent !== f.isInGroup("blockContent") || !s.hasContent && !f.validContent(s.block.node.content)) {
|
|
222
|
+
let t = n(s.block.node, e.doc), i = d(l)[u], a, o = [...t.children];
|
|
223
|
+
Array.isArray(t.content) && t.content.length && (i.content === "inline" || i.content === "plain" ? a = t.content : v(f) && o.unshift({
|
|
224
|
+
type: "paragraph",
|
|
225
|
+
content: t.content
|
|
226
|
+
}));
|
|
227
|
+
let c = g({
|
|
228
|
+
id: t.id,
|
|
229
|
+
...a ? { content: a } : {},
|
|
230
|
+
...o.length > 0 ? { children: o } : {},
|
|
231
|
+
...r
|
|
232
|
+
}, l);
|
|
233
|
+
c.check();
|
|
234
|
+
let p = e.doc.resolve(s.block.beforePos);
|
|
235
|
+
if (!p.parent.canReplace(p.index(), p.index(), O.from(c))) throw Error(`Cannot update block to "${u}": a "${p.parent.type.name}" doesn't accept it`);
|
|
236
|
+
e.replaceWith(s.block.beforePos, s.block.afterPos, c);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
Ut(r, e, s), s.hasContent && Bt(r, e, l.nodes[s.blockNoteType], f, s, m, h), q(e, s.block.beforePos, p, { ...r.props }), c && s.hasContent && Kt(e, e.mapping.slice(o).map(s.content.beforePos), c);
|
|
240
|
+
}
|
|
241
|
+
function Bt(t, n, r, i, a, o, s) {
|
|
242
|
+
let c = _(n), l = "keep";
|
|
243
|
+
if (t.content) {
|
|
244
|
+
if (typeof t.content == "string") l = S([t.content], c, i.name);
|
|
245
|
+
else if (Array.isArray(t.content)) l = S(t.content, c, i.name);
|
|
246
|
+
else if (t.content.type === "tableContent") l = e(t.content, c);
|
|
247
|
+
else throw new C(t.content.type);
|
|
248
|
+
} else {
|
|
249
|
+
let e = a.content.node.content;
|
|
250
|
+
if (r.spec.content !== "" && i.spec.content !== r.spec.content && !i.validContent(e)) {
|
|
251
|
+
if (i.inlineContent && r.inlineContent) {
|
|
252
|
+
let e = a.content.node.textContent;
|
|
253
|
+
l = e.length > 0 ? [c.text(e)] : [];
|
|
254
|
+
} else l = [];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (l === "keep") q(n, a.content.beforePos, i, { ...t.props });
|
|
258
|
+
else if (o !== void 0 || s !== void 0) {
|
|
259
|
+
let e = Ht(n, a.content.beforePos, i, { ...t.props }), r = e + 1 + (o ?? 0), c = e + 1 + (s ?? a.content.node.content.size), u = n.doc.resolve(e).depth, d = n.doc.resolve(r).depth, f = n.doc.resolve(c).depth;
|
|
260
|
+
n.replace(r, c, new k(O.from(l), d - u - 1, f - u - 1));
|
|
261
|
+
} else i === r || i.validContent(a.content.node.content) ? Vt(n, Ht(n, a.content.beforePos, i, { ...t.props }), O.from(l)) : n.replaceWith(a.content.beforePos, a.content.afterPos, i.createChecked({
|
|
262
|
+
...a.content.node.attrs,
|
|
263
|
+
...t.props
|
|
264
|
+
}, l));
|
|
265
|
+
}
|
|
266
|
+
function Vt(e, t, n) {
|
|
267
|
+
let r = e.doc.nodeAt(t);
|
|
268
|
+
if (!r) throw RangeError("No node at given position");
|
|
269
|
+
let i = r.content, a = t + 1;
|
|
270
|
+
if (r.isTextblock) {
|
|
271
|
+
let t = i.findDiffStart(n);
|
|
272
|
+
if (t === null) return;
|
|
273
|
+
let { a: r, b: o } = i.findDiffEnd(n), s = Math.max(0, t - r, t - o);
|
|
274
|
+
s > 0 && (r += s, o += s), e.replace(a + t, a + r, new k(n.cut(t, o), 0, 0));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
let o = i.childCount, s = n.childCount, c = 0;
|
|
278
|
+
for (; c < o && c < s && i.child(c).eq(n.child(c));) c++;
|
|
279
|
+
let l = o, u = s;
|
|
280
|
+
for (; l > c && u > c && i.child(l - 1).eq(n.child(u - 1));) l--, u--;
|
|
281
|
+
if (c === l && c === u) return;
|
|
282
|
+
let d = a;
|
|
283
|
+
for (let e = 0; e < c; e++) d += i.child(e).nodeSize;
|
|
284
|
+
let f = d;
|
|
285
|
+
for (let e = c; e < l; e++) f += i.child(e).nodeSize;
|
|
286
|
+
let p = [];
|
|
287
|
+
for (let e = c; e < u; e++) p.push(n.child(e));
|
|
288
|
+
e.step(new st(d, f, new k(O.from(p), 0, 0)));
|
|
289
|
+
}
|
|
290
|
+
function q(e, t, n, r) {
|
|
291
|
+
let i = e.doc.nodeAt(t);
|
|
292
|
+
if (!i) throw RangeError("No node at given position");
|
|
293
|
+
let a = n.spec.attrs ?? {}, o = {};
|
|
294
|
+
for (let e of Object.keys(r)) e in a && (o[e] = r[e]);
|
|
295
|
+
let s = {
|
|
296
|
+
...i.attrs,
|
|
297
|
+
...o
|
|
298
|
+
};
|
|
299
|
+
if (i.type === n) {
|
|
300
|
+
for (let n of Object.keys(s)) s[n] !== i.attrs[n] && e.setNodeAttribute(t, n, s[n]);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
e.setNodeMarkup(t, n, s);
|
|
304
|
+
}
|
|
305
|
+
function Ht(e, t, n, r) {
|
|
306
|
+
let i = e.mapping.maps.length;
|
|
307
|
+
return q(e, t, n, r), e.mapping.slice(i).map(t, -1);
|
|
308
|
+
}
|
|
309
|
+
function Ut(e, t, n) {
|
|
310
|
+
let r = _(t);
|
|
311
|
+
if (e.children !== void 0 && e.children.length > 0) {
|
|
312
|
+
let i = e.children.map((e) => {
|
|
313
|
+
let t = g(e, r);
|
|
314
|
+
return t.check(), t;
|
|
315
|
+
});
|
|
316
|
+
n.children ? Vt(t, n.children.beforePos, O.from(i)) : n.hasContent && t.insert(n.content.afterPos, p(r, i));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function Wt(e, t, r, i, a) {
|
|
320
|
+
let o = typeof t == "string" ? t : t.id, s = D(o, e.doc);
|
|
321
|
+
if (!s) throw Error(`Block with ID ${o} not found`);
|
|
322
|
+
K(e, s.posBeforeNode, r, i, a);
|
|
323
|
+
let c = e.doc.resolve(s.posBeforeNode).nodeAfter;
|
|
324
|
+
if (!c) throw Error(`Block with ID ${o} not found after update`);
|
|
325
|
+
return n(c, e.doc);
|
|
326
|
+
}
|
|
327
|
+
function Gt(e) {
|
|
328
|
+
let t = "selection" in e ? e.selection : null;
|
|
329
|
+
if (!(t instanceof N)) return null;
|
|
330
|
+
let n = e.doc.resolve(t.head), r = -1, i = -1;
|
|
331
|
+
for (let e = n.depth; e >= 0; e--) {
|
|
332
|
+
let t = n.node(e).type.name;
|
|
333
|
+
if (r < 0 && (t === "tableCell" || t === "tableHeader") && (r = e), t === "table") {
|
|
334
|
+
i = e;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (r < 0 || i < 0) return null;
|
|
339
|
+
let a = n.before(r), o = n.before(i), s = e.doc.nodeAt(o);
|
|
340
|
+
if (!s || s.type.name !== "table") return null;
|
|
341
|
+
let c = Tt.get(s), l = a - (o + 1), u = c.map.indexOf(l);
|
|
342
|
+
if (u < 0) return null;
|
|
343
|
+
let d = Math.floor(u / c.width), f = u % c.width, p = a + 1 + 1;
|
|
344
|
+
return {
|
|
345
|
+
row: d,
|
|
346
|
+
col: f,
|
|
347
|
+
offset: Math.max(0, t.head - p)
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function Kt(e, t, n) {
|
|
351
|
+
let r = e.doc.nodeAt(t);
|
|
352
|
+
if (!r || r.type.name !== "table") return !1;
|
|
353
|
+
let i = Tt.get(r), a = Math.max(0, Math.min(n.row, i.height - 1)), o = Math.max(0, Math.min(n.col, i.width - 1)), s = a * i.width + o, c = i.map[s];
|
|
354
|
+
if (c == null) return !1;
|
|
355
|
+
let l = t + 1 + c + 1, u = e.doc.nodeAt(l), d = l + 1, f = u ? u.content.size : 0, p = d + Math.max(0, Math.min(n.offset, f));
|
|
356
|
+
return "selection" in e && e.setSelection(N.create(e.doc, p)), !0;
|
|
357
|
+
}
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/pm-nodes/BlockContainer.ts
|
|
360
|
+
var qt = [["textColor", "data-text-color"], ["backgroundColor", "data-background-color"]];
|
|
361
|
+
function Jt(e) {
|
|
362
|
+
return typeof e == "string" && e !== "default";
|
|
363
|
+
}
|
|
364
|
+
function Yt(e) {
|
|
365
|
+
return qt.some(([t]) => Jt(e[t]));
|
|
366
|
+
}
|
|
367
|
+
function J(e, t) {
|
|
368
|
+
for (let [n, r] of qt) {
|
|
369
|
+
let i = t?.[n];
|
|
370
|
+
Jt(i) ? e.setAttribute(r, i) : e.removeAttribute(r);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
var Xt = {
|
|
374
|
+
blockColor: "data-block-color",
|
|
375
|
+
blockStyle: "data-block-style",
|
|
376
|
+
id: "data-id",
|
|
377
|
+
depth: "data-depth",
|
|
378
|
+
depthChange: "data-depth-change"
|
|
379
|
+
}, Zt = L.create({
|
|
380
|
+
name: "blockContainer",
|
|
381
|
+
group: "blockGroupChild bnBlock",
|
|
382
|
+
content: "blockContent blockGroup?",
|
|
383
|
+
priority: 50,
|
|
384
|
+
defining: !0,
|
|
385
|
+
marks() {
|
|
386
|
+
return s(this.editor);
|
|
387
|
+
},
|
|
388
|
+
parseHTML() {
|
|
389
|
+
return [{
|
|
390
|
+
tag: "div[data-node-type=" + this.name + "]",
|
|
391
|
+
getAttrs: (e) => {
|
|
392
|
+
if (typeof e == "string") return !1;
|
|
393
|
+
let t = {};
|
|
394
|
+
for (let [n, r] of Object.entries(Xt)) e.getAttribute(r) && (t[n] = e.getAttribute(r));
|
|
395
|
+
return t;
|
|
396
|
+
},
|
|
397
|
+
contentElement: (e) => he(e) ?? e
|
|
398
|
+
}, {
|
|
399
|
+
tag: "div[data-node-type=\"blockOuter\"]",
|
|
400
|
+
skip: !0
|
|
401
|
+
}];
|
|
402
|
+
},
|
|
403
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
404
|
+
let t = document.createElement("div");
|
|
405
|
+
t.className = "bn-block-outer", t.setAttribute("data-node-type", "blockOuter");
|
|
406
|
+
for (let [n, r] of Object.entries(e)) n !== "class" && t.setAttribute(n, r);
|
|
407
|
+
let n = {
|
|
408
|
+
...this.options.domAttributes?.block || {},
|
|
409
|
+
...e
|
|
410
|
+
}, r = document.createElement("div");
|
|
411
|
+
r.className = de("bn-block", n.class), r.setAttribute("data-node-type", this.name);
|
|
412
|
+
for (let [e, t] of Object.entries(n)) e !== "class" && r.setAttribute(e, t);
|
|
413
|
+
return t.appendChild(r), {
|
|
414
|
+
dom: t,
|
|
415
|
+
contentDOM: r
|
|
416
|
+
};
|
|
417
|
+
},
|
|
418
|
+
addNodeView() {
|
|
419
|
+
return ((e) => {
|
|
420
|
+
let { dom: t, contentDOM: n } = this.type.spec.toDOM(e.node), r = this.options.editor, i = _e({
|
|
421
|
+
props: e,
|
|
422
|
+
editor: r,
|
|
423
|
+
blockNode: (e) => e.firstChild,
|
|
424
|
+
unframed: n
|
|
425
|
+
});
|
|
426
|
+
i.dom !== n && n.appendChild(i.dom);
|
|
427
|
+
let a = e.node.firstChild.attrs;
|
|
428
|
+
return Yt(a) && J(n, a), {
|
|
429
|
+
dom: t,
|
|
430
|
+
contentDOM: i.slot,
|
|
431
|
+
update(e, t, r) {
|
|
432
|
+
let a = i.node;
|
|
433
|
+
return !e.sameMarkup(a) || !i.update(e, t, r) ? !1 : (e.firstChild.sameMarkup(a.firstChild) || J(n, e.firstChild.attrs), !0);
|
|
434
|
+
},
|
|
435
|
+
...se(i)
|
|
436
|
+
};
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region src/api/exporters/html/util/serializeBlocksInternalHTML.ts
|
|
442
|
+
function Qt(t, n, r, i, a) {
|
|
443
|
+
let o;
|
|
444
|
+
if (!n) throw Error("blockContent is required");
|
|
445
|
+
if (typeof n == "string") o = S([n], t.pmSchema, i);
|
|
446
|
+
else if (Array.isArray(n)) o = S(n, t.pmSchema, i);
|
|
447
|
+
else if (n.type === "tableContent") o = e(n, t.pmSchema);
|
|
448
|
+
else throw new C(n.type);
|
|
449
|
+
let s = (a?.document ?? document).createDocumentFragment();
|
|
450
|
+
for (let e of o) if (e.type.name !== "text" && t.schema.inlineContentSchema[e.type.name]) {
|
|
451
|
+
let n = t.schema.inlineContentSpecs[e.type.name].implementation;
|
|
452
|
+
if (n) {
|
|
453
|
+
let i = m(e, t.schema.inlineContentSchema, t.schema.styleSchema), o = n.render.call({
|
|
454
|
+
renderType: "dom",
|
|
455
|
+
props: void 0
|
|
456
|
+
}, i, () => {}, t);
|
|
457
|
+
if (o) {
|
|
458
|
+
if (s.appendChild(o.dom), o.contentDOM) {
|
|
459
|
+
let t = r.serializeFragment(e.content, a);
|
|
460
|
+
o.contentDOM.dataset.editable = "", o.contentDOM.appendChild(t);
|
|
461
|
+
}
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
} else if (e.type.name === "text") {
|
|
466
|
+
let n = document.createTextNode(e.textContent);
|
|
467
|
+
for (let r of e.marks.toReversed()) if (r.type.name in t.schema.styleSpecs) {
|
|
468
|
+
let e = t.schema.styleSpecs[r.type.name].implementation.render(r.attrs.stringValue, t);
|
|
469
|
+
e.contentDOM.appendChild(n), n = e.dom;
|
|
470
|
+
} else {
|
|
471
|
+
let e = r.type.spec.toDOM(r, !0), t = it.renderSpec(document, e);
|
|
472
|
+
t.contentDOM.appendChild(n), n = t.dom;
|
|
473
|
+
}
|
|
474
|
+
s.appendChild(n);
|
|
475
|
+
} else {
|
|
476
|
+
let t = r.serializeFragment(O.from([e]), a);
|
|
477
|
+
s.appendChild(t);
|
|
478
|
+
}
|
|
479
|
+
return s;
|
|
480
|
+
}
|
|
481
|
+
function $t(e, t, n, r) {
|
|
482
|
+
let i = e.pmSchema.nodes.blockContainer, a = t.props || {};
|
|
483
|
+
for (let [n, r] of Object.entries(e.schema.blockSchema[t.type].propSchema)) !(n in a) && r.default !== void 0 && (a[n] = r.default);
|
|
484
|
+
let o = t.children || [], s = e.blockImplementations[t.type].implementation, c = {
|
|
485
|
+
...t,
|
|
486
|
+
props: a,
|
|
487
|
+
children: o
|
|
488
|
+
};
|
|
489
|
+
if (v(e.pmSchema.nodes[t.type])) {
|
|
490
|
+
let i = De(e, c);
|
|
491
|
+
if (!i) throw Error(`Layout block "${t.type}" drew no frame. This is a bug in BlockNote.`);
|
|
492
|
+
return o.length > 0 && i.slot.append(en(e, o, n, r)), i.dom;
|
|
493
|
+
}
|
|
494
|
+
if (!s.render) throw Error(`Block "${t.type}" has no \`render\`. This is a bug in BlockNote.`);
|
|
495
|
+
let l = s.render.call({
|
|
496
|
+
renderType: "dom",
|
|
497
|
+
props: void 0
|
|
498
|
+
}, c, e);
|
|
499
|
+
if (l.contentDOM && t.content) {
|
|
500
|
+
let i = Qt(e, t.content, n, t.type, r);
|
|
501
|
+
l.contentDOM.appendChild(i);
|
|
502
|
+
}
|
|
503
|
+
let u = i.spec?.toDOM?.(i.create({
|
|
504
|
+
id: t.id,
|
|
505
|
+
...a
|
|
506
|
+
}));
|
|
507
|
+
u.contentDOM && J(u.contentDOM, a);
|
|
508
|
+
let d = u.contentDOM, f = De(e, c);
|
|
509
|
+
return f && (le(f.slot), u.contentDOM?.appendChild(f.dom), d = f.slot), d?.appendChild(l.dom), o.length > 0 && d?.appendChild(tn(e, o, n, r)), u.dom;
|
|
510
|
+
}
|
|
511
|
+
function en(e, t, n, r) {
|
|
512
|
+
let i = (r?.document ?? document).createDocumentFragment();
|
|
513
|
+
for (let a of t) {
|
|
514
|
+
let t = $t(e, a, n, r);
|
|
515
|
+
i.appendChild(t);
|
|
516
|
+
}
|
|
517
|
+
return i;
|
|
518
|
+
}
|
|
519
|
+
var tn = (e, t, n, r) => {
|
|
520
|
+
let i = e.pmSchema.nodes.blockGroup, a = i.spec.toDOM(i.create({})), o = en(e, t, n, r);
|
|
521
|
+
return a.contentDOM?.appendChild(o), a.dom;
|
|
522
|
+
}, nn = (e) => (e.querySelectorAll("[data-content-type=\"numberedListItem\"]").forEach((e) => {
|
|
523
|
+
let t = e.closest(".bn-block-outer")?.previousElementSibling?.querySelector("[data-content-type=\"numberedListItem\"]");
|
|
524
|
+
if (!t) e.setAttribute("data-index", e.getAttribute("data-start") || "1");
|
|
525
|
+
else {
|
|
526
|
+
let n = t.getAttribute("data-index");
|
|
527
|
+
e.setAttribute("data-index", (parseInt(n || "0") + 1).toString());
|
|
528
|
+
}
|
|
529
|
+
}), e), rn = (e) => (e.querySelectorAll("[data-content-type=\"checkListItem\"] input").forEach((e) => {
|
|
530
|
+
e.disabled = !0;
|
|
531
|
+
}), e), an = (e) => (e.querySelectorAll(".bn-toggle-button[aria-expanded=\"false\"]").forEach((e) => {
|
|
532
|
+
e.setAttribute("aria-expanded", "true");
|
|
533
|
+
}), e), on = (e) => (e.querySelectorAll("[data-content-type=\"table\"] table").forEach((e) => {
|
|
534
|
+
e.setAttribute("style", "--default-cell-min-width: 120px;"), e.setAttribute("data-show-children", "true");
|
|
535
|
+
}), e), sn = (e) => (e.querySelectorAll("[data-content-type=\"table\"] table").forEach((e) => {
|
|
536
|
+
let t = document.createElement("div");
|
|
537
|
+
t.className = "tableWrapper";
|
|
538
|
+
let n = document.createElement("div");
|
|
539
|
+
n.className = "tableWrapper-inner", t.appendChild(n), e.parentElement?.appendChild(t), t.appendChild(e);
|
|
540
|
+
}), e), cn = (e) => (e.querySelectorAll(".bn-inline-content:empty").forEach((e) => {
|
|
541
|
+
let t = document.createElement("span");
|
|
542
|
+
t.className = "ProseMirror-trailingBreak", t.setAttribute("style", "display: inline-block;"), e.appendChild(t);
|
|
543
|
+
}), e), ln = (e, t) => {
|
|
544
|
+
let n = it.fromSchema(e), r = [
|
|
545
|
+
nn,
|
|
546
|
+
rn,
|
|
547
|
+
an,
|
|
548
|
+
on,
|
|
549
|
+
sn,
|
|
550
|
+
cn
|
|
551
|
+
];
|
|
552
|
+
return { serializeBlocks: (e, i) => {
|
|
553
|
+
let a = tn(t, e, n, i);
|
|
554
|
+
for (let e of r) a = e(a);
|
|
555
|
+
return a.outerHTML;
|
|
556
|
+
} };
|
|
557
|
+
}, un = (e) => {
|
|
558
|
+
let t = 0;
|
|
559
|
+
for (let n = 0; n < e.length; n++) t = Math.imul(31, t) + e.charCodeAt(n);
|
|
560
|
+
return Math.abs(t);
|
|
561
|
+
}, Y = [
|
|
562
|
+
{
|
|
563
|
+
light: "#fff0c2",
|
|
564
|
+
dark: "#8a6d1a"
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
light: "#cdeffd",
|
|
568
|
+
dark: "#0b6a8a"
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
light: "#d6defd",
|
|
572
|
+
dark: "#2948b3"
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
light: "#eadcfb",
|
|
576
|
+
dark: "#6b2fa3"
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
light: "#f1e2d3",
|
|
580
|
+
dark: "#7a4a1e"
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
light: "#dfe4ea",
|
|
584
|
+
dark: "#46525f"
|
|
585
|
+
}
|
|
586
|
+
], dn = (e) => Y[un(e) % Y.length], fn = (e) => {
|
|
587
|
+
if (e?.color) return {
|
|
588
|
+
light: e.colorLight ?? `color-mix(in srgb, ${e.color} 30%, white)`,
|
|
589
|
+
dark: e.color
|
|
590
|
+
};
|
|
591
|
+
}, pn = (e, t) => {
|
|
592
|
+
if (!t || t.length === 0) return Y[0];
|
|
593
|
+
let n = t[0];
|
|
594
|
+
return fn(e.getUser(n)) ?? dn(n);
|
|
595
|
+
}, mn = (e) => Et(e).toString(16).padStart(8, "0"), hn = (e) => {
|
|
596
|
+
let t = mn(e);
|
|
597
|
+
return {
|
|
598
|
+
light: `--user-color-${t}-light`,
|
|
599
|
+
dark: `--user-color-${t}-dark`
|
|
600
|
+
};
|
|
601
|
+
}, gn = class {
|
|
602
|
+
callbacks = {};
|
|
603
|
+
on(e, t) {
|
|
604
|
+
return this.callbacks[e] || (this.callbacks[e] = []), this.callbacks[e].push(t), () => this.off(e, t);
|
|
605
|
+
}
|
|
606
|
+
emit(e, ...t) {
|
|
607
|
+
let n = this.callbacks[e];
|
|
608
|
+
n && n.forEach((e) => e.apply(this, t));
|
|
609
|
+
}
|
|
610
|
+
off(e, t) {
|
|
611
|
+
let n = this.callbacks[e];
|
|
612
|
+
n && (t ? this.callbacks[e] = n.filter((e) => e !== t) : delete this.callbacks[e]);
|
|
613
|
+
}
|
|
614
|
+
removeAllListeners() {
|
|
615
|
+
this.callbacks = {};
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
//#endregion
|
|
619
|
+
//#region src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts
|
|
620
|
+
function _n(e, t) {
|
|
621
|
+
return e.flatMap((e) => o(t.nodes[e.type]) ? _n(e.children, t) : [e]);
|
|
622
|
+
}
|
|
623
|
+
function vn(e) {
|
|
624
|
+
return e.transact((e) => {
|
|
625
|
+
let t = T(e, e.selection.anchor), n = r(t.block.node, e.doc);
|
|
626
|
+
if (e.selection instanceof z) return {
|
|
627
|
+
type: "cell",
|
|
628
|
+
anchorBlockId: n,
|
|
629
|
+
anchorCellOffset: e.selection.$anchorCell.pos - t.block.beforePos,
|
|
630
|
+
headCellOffset: e.selection.$headCell.pos - t.block.beforePos
|
|
631
|
+
};
|
|
632
|
+
if (e.selection instanceof A) return {
|
|
633
|
+
type: "node",
|
|
634
|
+
anchorBlockId: n
|
|
635
|
+
};
|
|
636
|
+
{
|
|
637
|
+
let i = T(e, e.selection.head);
|
|
638
|
+
return {
|
|
639
|
+
type: "text",
|
|
640
|
+
anchorBlockId: n,
|
|
641
|
+
headBlockId: r(i.block.node, e.doc),
|
|
642
|
+
anchorOffset: e.selection.anchor - t.block.beforePos,
|
|
643
|
+
headOffset: e.selection.head - i.block.beforePos
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
function yn(e, t) {
|
|
649
|
+
let n = D(t.anchorBlockId, e.doc)?.posBeforeNode;
|
|
650
|
+
if (n === void 0) throw Error(`Could not find block with ID ${t.anchorBlockId} to update selection`);
|
|
651
|
+
let r;
|
|
652
|
+
if (t.type === "cell") r = z.create(e.doc, n + t.anchorCellOffset, n + t.headCellOffset);
|
|
653
|
+
else if (t.type === "node") {
|
|
654
|
+
let t = w(e.doc, n);
|
|
655
|
+
r = A.create(e.doc, t.hasContent ? t.content.beforePos : n);
|
|
656
|
+
} else {
|
|
657
|
+
let i = D(t.headBlockId, e.doc)?.posBeforeNode;
|
|
658
|
+
if (i === void 0) throw Error(`Could not find block with ID ${t.headBlockId} to update selection`);
|
|
659
|
+
r = N.create(e.doc, n + t.anchorOffset, i + t.headOffset);
|
|
660
|
+
}
|
|
661
|
+
e.setSelection(r);
|
|
662
|
+
}
|
|
663
|
+
function bn(e, t, n, r) {
|
|
664
|
+
e.transact((i) => {
|
|
665
|
+
W(i, t, [], { fixLayoutBlocks: !1 }), H(i, _n(t, e.pmSchema), n, r);
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
function xn(e, t, n) {
|
|
669
|
+
e.transact((r) => {
|
|
670
|
+
let i = e.getSelection()?.blocks || [e.getTextCursorPosition().block], a = vn(e);
|
|
671
|
+
bn(e, i, t, n), yn(r, a);
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
function Sn(e, t) {
|
|
675
|
+
let n = _n([t], e.pmSchema)[0], r = n && e.pmSchema.nodes[n.type];
|
|
676
|
+
return r && v(r) ? r : e.pmSchema.nodes.blockContainer;
|
|
677
|
+
}
|
|
678
|
+
function Cn(e, n, r, i, a) {
|
|
679
|
+
let o = r === "up" ? "before" : "after", s = r === "up" ? "after" : "before";
|
|
680
|
+
for (; i || a;) {
|
|
681
|
+
let c = i && i.children.length > 0, l = i ? c ? i.children[r === "up" ? i.children.length - 1 : 0] : i : a, u = c ? s : o;
|
|
682
|
+
if (e.transact((e) => {
|
|
683
|
+
let r = D(l.id, e.doc);
|
|
684
|
+
return r !== void 0 && t(e.doc, w(e.doc, r.posBeforeNode), u, n) !== null;
|
|
685
|
+
})) return {
|
|
686
|
+
referenceBlock: l,
|
|
687
|
+
placement: u
|
|
688
|
+
};
|
|
689
|
+
a = e.getParentBlock(l), i = u === s ? l : r === "up" ? e.getPrevBlock(l) : e.getNextBlock(l);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
function wn(e, t, n) {
|
|
693
|
+
e.transact(() => {
|
|
694
|
+
let r;
|
|
695
|
+
if (n) {
|
|
696
|
+
let t = e.getBlock(n);
|
|
697
|
+
if (!t) return;
|
|
698
|
+
r = [t];
|
|
699
|
+
} else r = e.getSelection()?.blocks || [e.getTextCursorPosition().block];
|
|
700
|
+
let i = r[t === "up" ? 0 : r.length - 1], a = Cn(e, Sn(e, r[0]), t, t === "up" ? e.getPrevBlock(i) : e.getNextBlock(i), e.getParentBlock(i));
|
|
701
|
+
a && (n ? bn(e, r, a.referenceBlock, a.placement) : xn(e, a.referenceBlock, a.placement));
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
function Tn(e, t) {
|
|
705
|
+
wn(e, "up", t);
|
|
706
|
+
}
|
|
707
|
+
function En(e, t) {
|
|
708
|
+
wn(e, "down", t);
|
|
709
|
+
}
|
|
710
|
+
//#endregion
|
|
711
|
+
//#region src/api/blockManipulation/commands/nestBlock/nestBlock.ts
|
|
712
|
+
function Dn(e, t) {
|
|
713
|
+
return e.childCount > 0 && e.type.isInGroup("childContainer") && e.type.contentMatch.matchType(t) !== null;
|
|
714
|
+
}
|
|
715
|
+
function On(e, t, n) {
|
|
716
|
+
let { $from: r, $to: i } = e.selection, a = r.blockRange(i, (e) => Dn(e, t));
|
|
717
|
+
if (!a) return !1;
|
|
718
|
+
let o = a.startIndex;
|
|
719
|
+
if (o === 0) return !1;
|
|
720
|
+
let s = a.parent.child(o - 1);
|
|
721
|
+
if (s.type !== t) return !1;
|
|
722
|
+
let c = s.lastChild && s.lastChild.type === n ? 2 : 1, l = new k(O.from(t.create(null, O.from(n.create()))), c, 0), u = a.start, d = a.end;
|
|
723
|
+
return e.step(new ot(u - c, d, u, d, l, 2 - c, !0)).scrollIntoView(), !0;
|
|
724
|
+
}
|
|
725
|
+
function kn(e) {
|
|
726
|
+
return (t) => On(t, e.pmSchema.nodes.blockContainer, e.pmSchema.nodes.blockGroup);
|
|
727
|
+
}
|
|
728
|
+
function An(e) {
|
|
729
|
+
return e.transact(kn(e));
|
|
730
|
+
}
|
|
731
|
+
function jn(e, t, n, r) {
|
|
732
|
+
let i = r.end, a = r.$to.end(r.depth);
|
|
733
|
+
if (i < a) {
|
|
734
|
+
let o = r.parent.child(r.endIndex - 1), s = o.lastChild && o.lastChild.type === n;
|
|
735
|
+
e.step(new ot(i - (s ? 2 : 1), a, i, a, new k(O.from(t.create(null, n.create())), s ? 2 : 1, 0), +!s, !0)), r = new at(e.doc.resolve(r.$from.pos), e.doc.resolve(a), r.depth);
|
|
736
|
+
}
|
|
737
|
+
let o = lt(r);
|
|
738
|
+
if (o == null) return !1;
|
|
739
|
+
e.lift(r, o);
|
|
740
|
+
let s = e.doc.resolve(e.mapping.map(i, -1) - 1);
|
|
741
|
+
return ct(e.doc, s.pos) && s.nodeBefore.type === s.nodeAfter.type && e.join(s.pos), e.scrollIntoView(), !0;
|
|
742
|
+
}
|
|
743
|
+
function Mn(e, t, n, r) {
|
|
744
|
+
let { $from: i, $to: a } = e.selection, o = i.blockRange(a, (e) => Dn(e, t));
|
|
745
|
+
if (!o) return !1;
|
|
746
|
+
let s = i.node(o.depth - 1);
|
|
747
|
+
return s.type === t && !r(s) ? !1 : s.type === t && jn(e, t, n, o);
|
|
748
|
+
}
|
|
749
|
+
function Nn(e) {
|
|
750
|
+
return (t) => Mn(t, e.pmSchema.nodes.blockContainer, e.pmSchema.nodes.blockGroup, (r) => {
|
|
751
|
+
let i = n(r, t.doc);
|
|
752
|
+
return e.schema.blockSpecs[i.type].implementation.keyboard(i).childrenCanOutdent;
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
function Pn(e) {
|
|
756
|
+
return e.transact(Nn(e));
|
|
757
|
+
}
|
|
758
|
+
function Fn(e) {
|
|
759
|
+
return e.canExec((t) => kn(e)(t.tr));
|
|
760
|
+
}
|
|
761
|
+
function In(e) {
|
|
762
|
+
return e.canExec((t) => Nn(e)(t.tr));
|
|
763
|
+
}
|
|
764
|
+
//#endregion
|
|
765
|
+
//#region src/api/blockManipulation/getBlock/getBlock.ts
|
|
766
|
+
function Ln(e, t) {
|
|
767
|
+
let r = typeof t == "string" ? t : t.id, i = D(r, e);
|
|
768
|
+
if (i) return n(i.node, e);
|
|
769
|
+
}
|
|
770
|
+
function Rn(e, t) {
|
|
771
|
+
let r = typeof t == "string" ? t : t.id, i = D(r, e);
|
|
772
|
+
if (!i) return;
|
|
773
|
+
let a = e.resolve(i.posBeforeNode).nodeBefore;
|
|
774
|
+
if (a) return n(a, e);
|
|
775
|
+
}
|
|
776
|
+
function zn(e, t) {
|
|
777
|
+
let r = typeof t == "string" ? t : t.id, i = D(r, e);
|
|
778
|
+
if (!i) return;
|
|
779
|
+
let a = e.resolve(i.posBeforeNode + i.node.nodeSize).nodeAfter;
|
|
780
|
+
if (a) return n(a, e);
|
|
781
|
+
}
|
|
782
|
+
function Bn(e, t) {
|
|
783
|
+
let r = typeof t == "string" ? t : t.id, i = D(r, e);
|
|
784
|
+
if (!i) return;
|
|
785
|
+
let a = h(e, i.posBeforeNode);
|
|
786
|
+
if (a) return n(a.block.node, e);
|
|
787
|
+
}
|
|
788
|
+
//#endregion
|
|
789
|
+
//#region src/editor/managers/BlockManager.ts
|
|
790
|
+
var Vn = class {
|
|
791
|
+
editor;
|
|
792
|
+
constructor(e) {
|
|
793
|
+
this.editor = e;
|
|
794
|
+
}
|
|
795
|
+
get document() {
|
|
796
|
+
return this.editor.transact((e) => i(e.doc));
|
|
797
|
+
}
|
|
798
|
+
getBlock(e) {
|
|
799
|
+
return this.editor.transact((t) => Ln(t.doc, e));
|
|
800
|
+
}
|
|
801
|
+
getPrevBlock(e) {
|
|
802
|
+
return this.editor.transact((t) => Rn(t.doc, e));
|
|
803
|
+
}
|
|
804
|
+
getNextBlock(e) {
|
|
805
|
+
return this.editor.transact((t) => zn(t.doc, e));
|
|
806
|
+
}
|
|
807
|
+
getParentBlock(e) {
|
|
808
|
+
return this.editor.transact((t) => Bn(t.doc, e));
|
|
809
|
+
}
|
|
810
|
+
forEachBlock(e, t = !1) {
|
|
811
|
+
let n = this.document.slice();
|
|
812
|
+
t && n.reverse();
|
|
813
|
+
function r(n) {
|
|
814
|
+
for (let i of n) if (e(i) === !1 || !r(t ? i.children.slice().reverse() : i.children)) return !1;
|
|
815
|
+
return !0;
|
|
816
|
+
}
|
|
817
|
+
r(n);
|
|
818
|
+
}
|
|
819
|
+
insertBlocks(e, t, n = "before") {
|
|
820
|
+
return this.editor.transact((r) => H(r, e, t, n));
|
|
821
|
+
}
|
|
822
|
+
updateBlock(e, t) {
|
|
823
|
+
return this.editor.transact((n) => Wt(n, e, t));
|
|
824
|
+
}
|
|
825
|
+
removeBlocks(e) {
|
|
826
|
+
return this.editor.transact((t) => W(t, e, []).removedBlocks);
|
|
827
|
+
}
|
|
828
|
+
replaceBlocks(e, t) {
|
|
829
|
+
return this.editor.transact((n) => W(n, e, t));
|
|
830
|
+
}
|
|
831
|
+
canNestBlock() {
|
|
832
|
+
return Fn(this.editor);
|
|
833
|
+
}
|
|
834
|
+
nestBlock() {
|
|
835
|
+
An(this.editor);
|
|
836
|
+
}
|
|
837
|
+
canUnnestBlock() {
|
|
838
|
+
return In(this.editor);
|
|
839
|
+
}
|
|
840
|
+
unnestBlock() {
|
|
841
|
+
Pn(this.editor);
|
|
842
|
+
}
|
|
843
|
+
moveBlocksUp(e) {
|
|
844
|
+
return Tn(this.editor, e);
|
|
845
|
+
}
|
|
846
|
+
moveBlocksDown(e) {
|
|
847
|
+
return En(this.editor, e);
|
|
848
|
+
}
|
|
849
|
+
}, Hn = class extends gn {
|
|
850
|
+
editor;
|
|
851
|
+
constructor(e) {
|
|
852
|
+
super(), this.editor = e, e.on("create", () => {
|
|
853
|
+
e._tiptapEditor.on("update", ({ transaction: t, appendedTransactions: n }) => {
|
|
854
|
+
this.emit("onChange", {
|
|
855
|
+
editor: e,
|
|
856
|
+
transaction: t,
|
|
857
|
+
appendedTransactions: n
|
|
858
|
+
});
|
|
859
|
+
}), e._tiptapEditor.on("selectionUpdate", ({ transaction: t }) => {
|
|
860
|
+
this.emit("onSelectionChange", {
|
|
861
|
+
editor: e,
|
|
862
|
+
transaction: t
|
|
863
|
+
});
|
|
864
|
+
}), e._tiptapEditor.on("focus", ({ event: t }) => {
|
|
865
|
+
this.emit("onFocusChange", {
|
|
866
|
+
editor: e,
|
|
867
|
+
focused: !0,
|
|
868
|
+
event: t
|
|
869
|
+
});
|
|
870
|
+
}), e._tiptapEditor.on("blur", ({ event: t }) => {
|
|
871
|
+
this.emit("onFocusChange", {
|
|
872
|
+
editor: e,
|
|
873
|
+
focused: !1,
|
|
874
|
+
event: t
|
|
875
|
+
});
|
|
876
|
+
}), e._tiptapEditor.on("mount", () => {
|
|
877
|
+
this.emit("onMount", { editor: e });
|
|
878
|
+
}), e._tiptapEditor.on("unmount", () => {
|
|
879
|
+
this.emit("onUnmount", { editor: e });
|
|
880
|
+
});
|
|
881
|
+
let t;
|
|
882
|
+
this.onMount(() => {
|
|
883
|
+
t = this.attachUIFocusTracker();
|
|
884
|
+
}), this.onUnmount(() => {
|
|
885
|
+
t && t();
|
|
886
|
+
});
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
attachUIFocusTracker() {
|
|
890
|
+
if (typeof document > "u") return () => {};
|
|
891
|
+
let e = this.editor.isFocused({ includeEditorUI: !0 }), t, n = (t) => {
|
|
892
|
+
let n = this.editor.isFocused({ includeEditorUI: !0 });
|
|
893
|
+
n !== e && (e = n, this.emit("onFocusChangeWithinUI", {
|
|
894
|
+
editor: this.editor,
|
|
895
|
+
focused: n,
|
|
896
|
+
event: t
|
|
897
|
+
}));
|
|
898
|
+
}, r = (e) => n(e), i = (e) => {
|
|
899
|
+
clearTimeout(t), t = setTimeout(() => n(e));
|
|
900
|
+
};
|
|
901
|
+
return document.addEventListener("focusin", r, !0), document.addEventListener("focusout", i, !0), () => {
|
|
902
|
+
clearTimeout(t), document.removeEventListener("focusin", r, !0), document.removeEventListener("focusout", i, !0);
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
onChange(e, t = !0) {
|
|
906
|
+
return this.on("onChange", ({ transaction: n, appendedTransactions: r }) => {
|
|
907
|
+
(t || !Un(n)) && e(this.editor, { getChanges() {
|
|
908
|
+
return et(n, r);
|
|
909
|
+
} });
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
onSelectionChange(e, t = !1) {
|
|
913
|
+
return this.on("onSelectionChange", ({ transaction: n }) => {
|
|
914
|
+
(t || !Un(n)) && e(this.editor);
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
onFocusChange(e, t) {
|
|
918
|
+
return this.on(t?.includeEditorUI ? "onFocusChangeWithinUI" : "onFocusChange", ({ focused: t, event: n }) => e(this.editor, {
|
|
919
|
+
focused: t,
|
|
920
|
+
event: n
|
|
921
|
+
}));
|
|
922
|
+
}
|
|
923
|
+
onMount(e) {
|
|
924
|
+
return this.on("onMount", e);
|
|
925
|
+
}
|
|
926
|
+
onUnmount(e) {
|
|
927
|
+
return this.on("onUnmount", e);
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
function Un(e) {
|
|
931
|
+
return !!e.getMeta("y-sync$");
|
|
932
|
+
}
|
|
933
|
+
//#endregion
|
|
934
|
+
//#region src/api/parsers/html/util/nestedLists.ts
|
|
935
|
+
function Wn(e) {
|
|
936
|
+
return Array.prototype.indexOf.call(e.parentElement.childNodes, e);
|
|
937
|
+
}
|
|
938
|
+
function Gn(e) {
|
|
939
|
+
return e.nodeType === 3 && !/\S/.test(e.nodeValue || "");
|
|
940
|
+
}
|
|
941
|
+
function Kn(e) {
|
|
942
|
+
e.querySelectorAll("li > ul, li > ol").forEach((e) => {
|
|
943
|
+
let t = Wn(e), n = e.parentElement, r = Array.from(n.childNodes).slice(t + 1);
|
|
944
|
+
e.remove(), r.forEach((e) => {
|
|
945
|
+
e.remove();
|
|
946
|
+
}), n.insertAdjacentElement("afterend", e), r.reverse().forEach((t) => {
|
|
947
|
+
if (Gn(t)) return;
|
|
948
|
+
let n = document.createElement("li");
|
|
949
|
+
n.append(t), e.insertAdjacentElement("afterend", n);
|
|
950
|
+
}), n.childNodes.length === 0 && n.remove();
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
function qn(e) {
|
|
954
|
+
e.querySelectorAll("li + ul, li + ol").forEach((e) => {
|
|
955
|
+
let t = e.previousElementSibling, n = document.createElement("div");
|
|
956
|
+
t.insertAdjacentElement("afterend", n), n.append(t);
|
|
957
|
+
let r = document.createElement("div");
|
|
958
|
+
for (r.setAttribute("data-node-type", "blockGroup"), n.append(r); n.nextElementSibling?.nodeName === "UL" || n.nextElementSibling?.nodeName === "OL";) r.append(n.nextElementSibling);
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
var Jn = null;
|
|
962
|
+
function Yn() {
|
|
963
|
+
return Jn ||= document.implementation.createHTMLDocument("title");
|
|
964
|
+
}
|
|
965
|
+
function Xn(e) {
|
|
966
|
+
if (typeof e == "string") {
|
|
967
|
+
let t = Yn().createElement("div");
|
|
968
|
+
t.innerHTML = e, e = t;
|
|
969
|
+
}
|
|
970
|
+
return Kn(e), qn(e), e;
|
|
971
|
+
}
|
|
972
|
+
//#endregion
|
|
973
|
+
//#region src/api/parsers/html/util/normalizeWhitespace.ts
|
|
974
|
+
function Zn(e) {
|
|
975
|
+
let t = e.ownerDocument.createTreeWalker(e, 128), n;
|
|
976
|
+
for (; n = t.nextNode();) if (/^\s*notionvc:/.test(n.nodeValue || "")) return !0;
|
|
977
|
+
return !1;
|
|
978
|
+
}
|
|
979
|
+
function Qn(e) {
|
|
980
|
+
let t = /* @__PURE__ */ new Set(["PRE", "CODE"]), n = e.ownerDocument.createTreeWalker(e, 4, { acceptNode(n) {
|
|
981
|
+
let r = n.parentElement;
|
|
982
|
+
for (; r && r !== e;) {
|
|
983
|
+
if (t.has(r.tagName)) return 2;
|
|
984
|
+
r = r.parentElement;
|
|
985
|
+
}
|
|
986
|
+
return 1;
|
|
987
|
+
} }), r = [], i;
|
|
988
|
+
for (; i = n.nextNode();) r.push(i);
|
|
989
|
+
for (let e of r) e.nodeValue && /[\r\n]/.test(e.nodeValue) && (e.nodeValue = e.nodeValue.replace(/[ \t\r\n\f]+/g, " "));
|
|
990
|
+
}
|
|
991
|
+
function $n(e) {
|
|
992
|
+
Zn(e) || Qn(e);
|
|
993
|
+
}
|
|
994
|
+
//#endregion
|
|
995
|
+
//#region src/api/parsers/html/parseHTML.ts
|
|
996
|
+
function er(e) {
|
|
997
|
+
let t = [];
|
|
998
|
+
for (let n of e) if (n.type === "text") {
|
|
999
|
+
let e = n.text.split("").join("");
|
|
1000
|
+
e.length > 0 && t.push({
|
|
1001
|
+
...n,
|
|
1002
|
+
text: e
|
|
1003
|
+
});
|
|
1004
|
+
} else Array.isArray(n.content) ? t.push({
|
|
1005
|
+
...n,
|
|
1006
|
+
content: er(n.content)
|
|
1007
|
+
}) : t.push(n);
|
|
1008
|
+
return t;
|
|
1009
|
+
}
|
|
1010
|
+
function tr(e) {
|
|
1011
|
+
for (let t of e) Array.isArray(t.content) && (t.content = er(t.content)), t.children.length > 0 && tr(t.children);
|
|
1012
|
+
}
|
|
1013
|
+
function nr(e, t) {
|
|
1014
|
+
let r = Xn(e);
|
|
1015
|
+
$n(r);
|
|
1016
|
+
let i = rt.fromSchema(t).parse(r, { topNode: t.nodes.blockGroup.create() }), a = [];
|
|
1017
|
+
for (let e = 0; e < i.childCount; e++) a.push(n(i.child(e), i));
|
|
1018
|
+
return tr(a), a;
|
|
1019
|
+
}
|
|
1020
|
+
//#endregion
|
|
1021
|
+
//#region src/api/parsers/markdown/markdownToHtml.ts
|
|
1022
|
+
function X(e) {
|
|
1023
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1024
|
+
}
|
|
1025
|
+
function rr(e) {
|
|
1026
|
+
return e ? /\w/.test(e) : !1;
|
|
1027
|
+
}
|
|
1028
|
+
function ir(e, t, n) {
|
|
1029
|
+
let r = t > 0 ? e[t - 1] : void 0, i = t + n < e.length ? e[t + n] : void 0;
|
|
1030
|
+
return rr(r) && rr(i);
|
|
1031
|
+
}
|
|
1032
|
+
function ar(e, t) {
|
|
1033
|
+
if (e[t] !== "\\" || t + 1 >= e.length) return null;
|
|
1034
|
+
let n = e[t + 1];
|
|
1035
|
+
return n === "\n" ? {
|
|
1036
|
+
html: "<br>\n",
|
|
1037
|
+
end: t + 2
|
|
1038
|
+
} : "\\`*_{}[]()#+-.!~|>".includes(n) ? {
|
|
1039
|
+
html: X(n),
|
|
1040
|
+
end: t + 2
|
|
1041
|
+
} : null;
|
|
1042
|
+
}
|
|
1043
|
+
function or(e, t) {
|
|
1044
|
+
return e[t] === "`" ? Tr(e, t) : null;
|
|
1045
|
+
}
|
|
1046
|
+
function sr(e, t) {
|
|
1047
|
+
return e[t] !== "!" || e[t + 1] !== "[" ? null : Er(e, t);
|
|
1048
|
+
}
|
|
1049
|
+
function cr(e, t) {
|
|
1050
|
+
return e[t] === "[" ? Dr(e, t) : null;
|
|
1051
|
+
}
|
|
1052
|
+
function lr(e, t) {
|
|
1053
|
+
let n = e.substring(t);
|
|
1054
|
+
if (e[t] === "<") {
|
|
1055
|
+
let e = n.match(/^<([a-zA-Z][a-zA-Z0-9+.-]{1,31}:[^\s<>]*)>/);
|
|
1056
|
+
if (e) {
|
|
1057
|
+
let n = e[1];
|
|
1058
|
+
return {
|
|
1059
|
+
html: `<a href="${X(n)}">${X(n)}</a>`,
|
|
1060
|
+
end: t + e[0].length
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
let r = n.match(/^<([^\s<>]+)>/), i = r?.[1], a = i ? Me(i).find((e) => e.type === "email" && e.start === 0 && e.end === i.length) : void 0;
|
|
1064
|
+
return r && i && a ? {
|
|
1065
|
+
html: `<a href="${X(a.href)}">${X(i)}</a>`,
|
|
1066
|
+
end: t + r[0].length
|
|
1067
|
+
} : null;
|
|
1068
|
+
}
|
|
1069
|
+
if (t > 0 && /[a-zA-Z0-9_]/.test(e[t - 1])) return null;
|
|
1070
|
+
let r = n.match(/^(https?:\/\/|www\.)[^\s<>]+/i);
|
|
1071
|
+
if (!r) return null;
|
|
1072
|
+
let i = He(r[0]);
|
|
1073
|
+
return i ? {
|
|
1074
|
+
html: `<a href="${X(i.href)}">${X(i.value)}</a>`,
|
|
1075
|
+
end: t + i.value.length
|
|
1076
|
+
} : null;
|
|
1077
|
+
}
|
|
1078
|
+
function ur(e, t, n) {
|
|
1079
|
+
return e[t] !== "~" || e[t + 1] !== "~" ? null : Q(e, t, "~~", "<del>", "</del>", n);
|
|
1080
|
+
}
|
|
1081
|
+
function dr(e, t, n) {
|
|
1082
|
+
return e[t] === "*" && e[t + 1] === "*" && e[t + 2] === "*" || e[t] === "_" && e[t + 1] === "_" && e[t + 2] === "_" && !ir(e, t, 3) ? Q(e, t, e.substring(t, t + 3), "<strong><em>", "</em></strong>", n) : null;
|
|
1083
|
+
}
|
|
1084
|
+
function fr(e, t, n) {
|
|
1085
|
+
return e[t] === "*" && e[t + 1] === "*" || e[t] === "_" && e[t + 1] === "_" && !ir(e, t, 2) ? Q(e, t, e.substring(t, t + 2), "<strong>", "</strong>", n) : null;
|
|
1086
|
+
}
|
|
1087
|
+
function pr(e, t, n) {
|
|
1088
|
+
return e[t] === "*" || e[t] === "_" && !ir(e, t, 1) ? Q(e, t, e[t], "<em>", "</em>", n) : null;
|
|
1089
|
+
}
|
|
1090
|
+
function mr(e, t) {
|
|
1091
|
+
return e[t] === "\n" ? {
|
|
1092
|
+
html: "<br>\n",
|
|
1093
|
+
end: t + 1
|
|
1094
|
+
} : null;
|
|
1095
|
+
}
|
|
1096
|
+
var hr = /^<\/?[a-zA-Z][a-zA-Z0-9-]*(?:\s+[a-zA-Z_:][a-zA-Z0-9_.:-]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*\s*\/?>/, gr = /^<!--[\s\S]*?-->/, _r = /^<!\[CDATA\[[\s\S]*?\]\]>/, vr = /^<\?[\s\S]*?\?>/, yr = /^<![A-Za-z][\s\S]*?>/;
|
|
1097
|
+
function br(e, t) {
|
|
1098
|
+
if (e[t] !== "<") return null;
|
|
1099
|
+
let n = e.substring(t);
|
|
1100
|
+
for (let e of [
|
|
1101
|
+
gr,
|
|
1102
|
+
_r,
|
|
1103
|
+
vr,
|
|
1104
|
+
yr,
|
|
1105
|
+
hr
|
|
1106
|
+
]) {
|
|
1107
|
+
let r = n.match(e);
|
|
1108
|
+
if (r) return {
|
|
1109
|
+
html: r[0],
|
|
1110
|
+
end: t + r[0].length
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
return null;
|
|
1114
|
+
}
|
|
1115
|
+
var xr = /* @__PURE__ */ new Set("\\`![~*_\n<");
|
|
1116
|
+
function Sr(e, t) {
|
|
1117
|
+
let n = e[t];
|
|
1118
|
+
return xr.has(n) ? !0 : n === "h" ? e.startsWith("http://", t) || e.startsWith("https://", t) : n === "w" && e.startsWith("www.", t);
|
|
1119
|
+
}
|
|
1120
|
+
var Cr = [
|
|
1121
|
+
ar,
|
|
1122
|
+
or,
|
|
1123
|
+
sr,
|
|
1124
|
+
cr,
|
|
1125
|
+
lr,
|
|
1126
|
+
ur,
|
|
1127
|
+
dr,
|
|
1128
|
+
fr,
|
|
1129
|
+
pr,
|
|
1130
|
+
br,
|
|
1131
|
+
mr
|
|
1132
|
+
], wr = Cr.filter((e) => e !== cr && e !== lr);
|
|
1133
|
+
function Z(e, t = !0) {
|
|
1134
|
+
let n = "", r = 0, i = t ? Cr : wr;
|
|
1135
|
+
for (; r < e.length;) {
|
|
1136
|
+
if (e[r] === "\n" && r >= 2 && e[r - 1] === " " && e[r - 2] === " ") {
|
|
1137
|
+
n = n.replace(/ +$/, ""), n += "<br>\n", r++;
|
|
1138
|
+
continue;
|
|
1139
|
+
}
|
|
1140
|
+
let a = !1;
|
|
1141
|
+
if (Sr(e, r)) for (let o of i) {
|
|
1142
|
+
let i = o(e, r, t);
|
|
1143
|
+
if (i) {
|
|
1144
|
+
n += i.html, r = i.end, a = !0;
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (!a) {
|
|
1149
|
+
let t = r;
|
|
1150
|
+
for (r++; r < e.length && !Sr(e, r);) r++;
|
|
1151
|
+
n += X(e.substring(t, r));
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return n;
|
|
1155
|
+
}
|
|
1156
|
+
function Tr(e, t) {
|
|
1157
|
+
let n = 0, r = t;
|
|
1158
|
+
for (; r < e.length && e[r] === "`";) n++, r++;
|
|
1159
|
+
let i = r;
|
|
1160
|
+
for (; i < e.length;) if (e[i] === "`") {
|
|
1161
|
+
let t = 0, a = i;
|
|
1162
|
+
for (; i < e.length && e[i] === "`";) t++, i++;
|
|
1163
|
+
if (t === n) {
|
|
1164
|
+
let t = e.substring(r, a);
|
|
1165
|
+
return t = t.replace(/\n/g, " "), t.length >= 2 && t[0] === " " && t[t.length - 1] === " " && /[^ ]/.test(t) && (t = t.substring(1, t.length - 1)), {
|
|
1166
|
+
html: `<code>${X(t)}</code>`,
|
|
1167
|
+
end: i
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
} else i++;
|
|
1171
|
+
return null;
|
|
1172
|
+
}
|
|
1173
|
+
function Er(e, t) {
|
|
1174
|
+
let n = Or(e, t + 1);
|
|
1175
|
+
if (n === -1) return null;
|
|
1176
|
+
let r = t + 2;
|
|
1177
|
+
if (e[n + 1] !== "(") return null;
|
|
1178
|
+
let i = n + 2, a = kr(e, i - 1);
|
|
1179
|
+
if (a === -1) return null;
|
|
1180
|
+
let o = e.substring(r, n), { url: s, title: l } = Ar(e.substring(i, a));
|
|
1181
|
+
if (c(s)) {
|
|
1182
|
+
let e = o || l;
|
|
1183
|
+
return {
|
|
1184
|
+
html: `<video src="${X(s)}"${e ? ` data-name="${X(e)}"` : ""} data-url="${X(s)}" controls></video>`,
|
|
1185
|
+
end: a + 1
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
let u = l === void 0 ? "" : ` title="${X(l)}"`;
|
|
1189
|
+
return {
|
|
1190
|
+
html: `<img src="${X(s)}" alt="${X(o)}"${u}>`,
|
|
1191
|
+
end: a + 1
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
function Dr(e, t) {
|
|
1195
|
+
let n = t + 1, r = Or(e, t);
|
|
1196
|
+
if (r === -1 || e[r + 1] !== "(") return null;
|
|
1197
|
+
let i = r + 2, a = kr(e, r + 1);
|
|
1198
|
+
if (a === -1) return null;
|
|
1199
|
+
let o = e.substring(n, r), { url: s, title: c } = Ar(e.substring(i, a)), l = c === void 0 ? "" : ` title="${X(c)}"`;
|
|
1200
|
+
return {
|
|
1201
|
+
html: `<a href="${X(s)}"${l}>${Z(o, !1)}</a>`,
|
|
1202
|
+
end: a + 1
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
function Or(e, t) {
|
|
1206
|
+
let n = 0;
|
|
1207
|
+
for (let r = t; r < e.length; r++) {
|
|
1208
|
+
if (e[r] === "\\" && r + 1 < e.length) {
|
|
1209
|
+
r++;
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
if (e[r] === "[" && n++, e[r] === "]" && (n--, n === 0)) return r;
|
|
1213
|
+
}
|
|
1214
|
+
return -1;
|
|
1215
|
+
}
|
|
1216
|
+
function kr(e, t) {
|
|
1217
|
+
let n = 0;
|
|
1218
|
+
for (let r = t; r < e.length; r++) {
|
|
1219
|
+
if (e[r] === "\\" && r + 1 < e.length) {
|
|
1220
|
+
r++;
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
if (e[r] === "(" && n++, e[r] === ")" && (n--, n === 0)) return r;
|
|
1224
|
+
}
|
|
1225
|
+
return -1;
|
|
1226
|
+
}
|
|
1227
|
+
function Ar(e) {
|
|
1228
|
+
e = e.trim();
|
|
1229
|
+
let t, n;
|
|
1230
|
+
if (e.startsWith("<")) {
|
|
1231
|
+
let r = e.indexOf(">");
|
|
1232
|
+
r === -1 ? (t = e.substring(1), n = "") : (t = e.substring(1, r), n = e.substring(r + 1).trim());
|
|
1233
|
+
} else {
|
|
1234
|
+
let r = e.length;
|
|
1235
|
+
for (let t = 0; t < e.length; t++) {
|
|
1236
|
+
if (e[t] === "\\" && t + 1 < e.length) {
|
|
1237
|
+
t++;
|
|
1238
|
+
continue;
|
|
1239
|
+
}
|
|
1240
|
+
if (e[t] === " " || e[t] === " " || e[t] === "\n") {
|
|
1241
|
+
r = t;
|
|
1242
|
+
break;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
t = e.substring(0, r), n = e.substring(r).trim();
|
|
1246
|
+
}
|
|
1247
|
+
let r;
|
|
1248
|
+
if (n.length > 0) {
|
|
1249
|
+
let e = n.match(/^"([^"]*)"$|^'([^']*)'$|^\(([^)]*)\)$/);
|
|
1250
|
+
e && (r = e[1] ?? e[2] ?? e[3]);
|
|
1251
|
+
}
|
|
1252
|
+
return {
|
|
1253
|
+
url: t,
|
|
1254
|
+
title: r
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
function Q(e, t, n, r, i, a) {
|
|
1258
|
+
let o = n.length, s = t + o;
|
|
1259
|
+
if (s >= e.length || e[s] === " " || e[s] === " ") return null;
|
|
1260
|
+
let c = s;
|
|
1261
|
+
for (; c < e.length;) {
|
|
1262
|
+
if (e[c] === "\\" && c + 1 < e.length) {
|
|
1263
|
+
c += 2;
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
if (e.substring(c, c + o) === n) {
|
|
1267
|
+
if (e[c - 1] === " " || e[c - 1] === " ") {
|
|
1268
|
+
c++;
|
|
1269
|
+
continue;
|
|
1270
|
+
}
|
|
1271
|
+
if (o === 1 && (c > 0 && e[c - 1] === n[0] && !(c >= 2 && e[c - 2] === "\\") || c + o < e.length && e[c + o] === n[0])) {
|
|
1272
|
+
c++;
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
1275
|
+
let t = e.substring(s, c);
|
|
1276
|
+
if (t.length === 0) {
|
|
1277
|
+
c++;
|
|
1278
|
+
continue;
|
|
1279
|
+
}
|
|
1280
|
+
return {
|
|
1281
|
+
html: r + Z(t, a) + i,
|
|
1282
|
+
end: c + o
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
c++;
|
|
1286
|
+
}
|
|
1287
|
+
return null;
|
|
1288
|
+
}
|
|
1289
|
+
var jr = /* @__PURE__ */ new Set(/* @__PURE__ */ "address.article.aside.audio.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.section.source.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul".split("."));
|
|
1290
|
+
function Mr(e) {
|
|
1291
|
+
if (/^ {0,3}<(!--|\?|![A-Za-z]|!\[CDATA\[)/.test(e)) return !0;
|
|
1292
|
+
let t = e.match(/^ {0,3}<\/?([a-zA-Z][a-zA-Z0-9-]*)(?:\s|\/?>|$)/);
|
|
1293
|
+
return t ? jr.has(t[1].toLowerCase()) : !1;
|
|
1294
|
+
}
|
|
1295
|
+
function Nr(e) {
|
|
1296
|
+
let t = e.split("\n"), n = [], r = 0, i = !0;
|
|
1297
|
+
for (; r < t.length;) {
|
|
1298
|
+
let e = t[r];
|
|
1299
|
+
if (e.trim() === "") {
|
|
1300
|
+
i = !0, r++;
|
|
1301
|
+
continue;
|
|
1302
|
+
}
|
|
1303
|
+
let a = e.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);
|
|
1304
|
+
if (a) {
|
|
1305
|
+
let e = a[1], o = e[0], s = e.length, c = a[2].trim(), l = [];
|
|
1306
|
+
for (r++; r < t.length;) {
|
|
1307
|
+
if (t[r].match(RegExp(`^ {0,3}${o}{${s},}\\s*$`))) {
|
|
1308
|
+
r++;
|
|
1309
|
+
break;
|
|
1310
|
+
}
|
|
1311
|
+
l.push(t[r]), r++;
|
|
1312
|
+
}
|
|
1313
|
+
n.push({
|
|
1314
|
+
type: "codeBlock",
|
|
1315
|
+
language: c || "",
|
|
1316
|
+
code: l.join("\n")
|
|
1317
|
+
}), i = !1;
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
let o = e.match(/^(#{1,6})\s+(.+?)(?:\s+#+\s*|\s*)$/);
|
|
1321
|
+
if (o) {
|
|
1322
|
+
n.push({
|
|
1323
|
+
type: "heading",
|
|
1324
|
+
level: o[1].length,
|
|
1325
|
+
content: o[2]
|
|
1326
|
+
}), i = !1, r++;
|
|
1327
|
+
continue;
|
|
1328
|
+
}
|
|
1329
|
+
if (/^(\s{0,3})([-*_])\s*(\2\s*){2,}$/.test(e)) {
|
|
1330
|
+
let t = n[n.length - 1];
|
|
1331
|
+
if (!i && e.trim().match(/^-+$/) && t && t.type === "paragraph") {
|
|
1332
|
+
let e = t;
|
|
1333
|
+
n[n.length - 1] = {
|
|
1334
|
+
type: "heading",
|
|
1335
|
+
level: 2,
|
|
1336
|
+
content: e.content
|
|
1337
|
+
}, i = !1, r++;
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
n.push({ type: "hr" }), i = !1, r++;
|
|
1341
|
+
continue;
|
|
1342
|
+
}
|
|
1343
|
+
if (r + 1 < t.length) {
|
|
1344
|
+
let a = t[r + 1];
|
|
1345
|
+
if (/^={1,}\s*$/.test(a) && e.trim().length > 0) {
|
|
1346
|
+
n.push({
|
|
1347
|
+
type: "heading",
|
|
1348
|
+
level: 1,
|
|
1349
|
+
content: e.trim()
|
|
1350
|
+
}), i = !1, r += 2;
|
|
1351
|
+
continue;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
let s = Pr(t, r);
|
|
1355
|
+
if (s) {
|
|
1356
|
+
n.push(s.token), r = s.nextLine, i = !1;
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (/^\s{0,3}>/.test(e)) {
|
|
1360
|
+
let e = [];
|
|
1361
|
+
for (; r < t.length && /^\s{0,3}>/.test(t[r]);) e.push(t[r].replace(/^\s{0,3}>\s?/, "")), r++;
|
|
1362
|
+
for (; r < t.length;) {
|
|
1363
|
+
let n = t[r];
|
|
1364
|
+
if (n.trim() === "" || /^\s{0,3}>/.test(n) || /^(#{1,6})\s/.test(n) || /^(`{3,}|~{3,})/.test(n) || /^(\s{0,3})([-*_])\s*(\2\s*){2,}$/.test(n) || /^\s*([-*+]|\d+[.)])\s+/.test(n) || /^\s*\|(.+\|)+\s*$/.test(n)) break;
|
|
1365
|
+
e.push(n), r++;
|
|
1366
|
+
}
|
|
1367
|
+
n.push({
|
|
1368
|
+
type: "blockquote",
|
|
1369
|
+
content: e.join("\n")
|
|
1370
|
+
}), i = !1;
|
|
1371
|
+
continue;
|
|
1372
|
+
}
|
|
1373
|
+
let c = e.match(/^(\s*)([-*+]|\d+[.)])(\s+)(\[[ xX]\] )?(.*)$/);
|
|
1374
|
+
if (c) {
|
|
1375
|
+
let e = c[1].length, a = c[2], o = c[3], s = c[4], l = c[5], u, d, f;
|
|
1376
|
+
s ? (u = "task", f = s.trim() !== "[ ]") : /^\d+[.)]$/.test(a) ? (u = "ordered", d = parseInt(a, 10)) : u = "bullet";
|
|
1377
|
+
let p = e + a.length + o.length + (s ? s.length : 0), m = e + 1, h = (e) => {
|
|
1378
|
+
if (e.trim() === "") return !0;
|
|
1379
|
+
let t = e.match(/^\s*/)[0].length;
|
|
1380
|
+
return !!(t >= p || t >= m && e.match(/^\s*([-*+]|\d+[.)])\s+/));
|
|
1381
|
+
};
|
|
1382
|
+
r++;
|
|
1383
|
+
let g = [];
|
|
1384
|
+
for (; r < t.length;) {
|
|
1385
|
+
let e = t[r];
|
|
1386
|
+
if (e.trim() === "") {
|
|
1387
|
+
let e = r + 1;
|
|
1388
|
+
for (; e < t.length && t[e].trim() === "";) e++;
|
|
1389
|
+
if (e < t.length && h(t[e])) {
|
|
1390
|
+
g.push(""), r++;
|
|
1391
|
+
continue;
|
|
1392
|
+
}
|
|
1393
|
+
break;
|
|
1394
|
+
}
|
|
1395
|
+
if (!h(e)) break;
|
|
1396
|
+
e.match(/^\s*/)[0].length >= p ? g.push(e.substring(p)) : g.push(e.substring(m)), r++;
|
|
1397
|
+
}
|
|
1398
|
+
let _ = g.join("\n").replace(/^\n+|\n+$/g, "");
|
|
1399
|
+
n.push({
|
|
1400
|
+
type: "listItem",
|
|
1401
|
+
listType: u,
|
|
1402
|
+
indent: e,
|
|
1403
|
+
content: l.trim(),
|
|
1404
|
+
start: d,
|
|
1405
|
+
checked: f,
|
|
1406
|
+
childContent: _ || void 0
|
|
1407
|
+
}), i = !1;
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
if (Mr(e)) {
|
|
1411
|
+
let e = [];
|
|
1412
|
+
for (; r < t.length && t[r].trim() !== "";) e.push(t[r]), r++;
|
|
1413
|
+
n.push({
|
|
1414
|
+
type: "rawHtml",
|
|
1415
|
+
content: e.join("\n")
|
|
1416
|
+
}), i = !1;
|
|
1417
|
+
continue;
|
|
1418
|
+
}
|
|
1419
|
+
let l = [e];
|
|
1420
|
+
for (r++; r < t.length;) {
|
|
1421
|
+
let e = t[r];
|
|
1422
|
+
if (e.trim() === "" || /^(#{1,6})\s/.test(e) || /^(`{3,}|~{3,})/.test(e) || /^\s{0,3}>/.test(e) || /^(\s{0,3})([-*_])\s*(\2\s*){2,}$/.test(e) || /^\s*([-*+]|\d+[.)])\s+/.test(e) || /^\s*\|(.+\|)+\s*$/.test(e) || Mr(e) || r + 1 < t.length && /^[=-]+\s*$/.test(t[r + 1]) && e.trim().length > 0) break;
|
|
1423
|
+
l.push(e), r++;
|
|
1424
|
+
}
|
|
1425
|
+
n.push({
|
|
1426
|
+
type: "paragraph",
|
|
1427
|
+
content: l.map((e) => e.replace(/^ {1,3}/, "")).join("\n").replace(/[ \t]+$/, "")
|
|
1428
|
+
}), i = !1;
|
|
1429
|
+
}
|
|
1430
|
+
return n;
|
|
1431
|
+
}
|
|
1432
|
+
function Pr(e, t) {
|
|
1433
|
+
if (t + 1 >= e.length) return null;
|
|
1434
|
+
let n = e[t], r = e[t + 1];
|
|
1435
|
+
if (!r.includes("|") || !/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/.test(r) || !n.includes("|")) return null;
|
|
1436
|
+
let i = Fr(n), a = Ir(r), o = [], s = t + 2;
|
|
1437
|
+
for (; s < e.length;) {
|
|
1438
|
+
let t = e[s];
|
|
1439
|
+
if (!t.includes("|")) break;
|
|
1440
|
+
o.push(Fr(t)), s++;
|
|
1441
|
+
}
|
|
1442
|
+
return {
|
|
1443
|
+
token: {
|
|
1444
|
+
type: "table",
|
|
1445
|
+
headers: i,
|
|
1446
|
+
rows: o,
|
|
1447
|
+
alignments: a
|
|
1448
|
+
},
|
|
1449
|
+
nextLine: s
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
function Fr(e) {
|
|
1453
|
+
let t = e.trim(), n = t.startsWith("|") ? t.substring(1) : t, r = n.endsWith("|") ? n.substring(0, n.length - 1) : n, i = [], a = "";
|
|
1454
|
+
for (let e = 0; e < r.length; e++) r[e] === "\\" && e + 1 < r.length && r[e + 1] === "|" ? (a += "|", e++) : r[e] === "|" ? (i.push(a.trim()), a = "") : a += r[e];
|
|
1455
|
+
return i.push(a.trim()), i;
|
|
1456
|
+
}
|
|
1457
|
+
function Ir(e) {
|
|
1458
|
+
return Fr(e).map((e) => {
|
|
1459
|
+
let t = e.trim(), n = t.startsWith(":"), r = t.endsWith(":");
|
|
1460
|
+
return n && r ? "center" : r ? "right" : n ? "left" : null;
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
function Lr(e) {
|
|
1464
|
+
let t = "", n = 0;
|
|
1465
|
+
for (; n < e.length;) {
|
|
1466
|
+
let r = e[n];
|
|
1467
|
+
switch (r.type) {
|
|
1468
|
+
case "heading": {
|
|
1469
|
+
let e = r;
|
|
1470
|
+
t += `<h${e.level}>${Z(e.content)}</h${e.level}>`, n++;
|
|
1471
|
+
break;
|
|
1472
|
+
}
|
|
1473
|
+
case "paragraph":
|
|
1474
|
+
t += `<p>${Z(r.content)}</p>`, n++;
|
|
1475
|
+
break;
|
|
1476
|
+
case "codeBlock": {
|
|
1477
|
+
let e = r, i = e.language ? ` data-language="${X(e.language)}"` : "";
|
|
1478
|
+
t += `<pre><code${i}>${X(e.code)}</code></pre>`, n++;
|
|
1479
|
+
break;
|
|
1480
|
+
}
|
|
1481
|
+
case "blockquote": {
|
|
1482
|
+
let e = Lr(Nr(r.content));
|
|
1483
|
+
t += `<blockquote>${e}</blockquote>`, n++;
|
|
1484
|
+
break;
|
|
1485
|
+
}
|
|
1486
|
+
case "hr":
|
|
1487
|
+
t += "<hr>", n++;
|
|
1488
|
+
break;
|
|
1489
|
+
case "listItem": {
|
|
1490
|
+
let r = Rr(e, n);
|
|
1491
|
+
t += r.html, n = r.nextIndex;
|
|
1492
|
+
break;
|
|
1493
|
+
}
|
|
1494
|
+
case "table":
|
|
1495
|
+
t += Br(r), n++;
|
|
1496
|
+
break;
|
|
1497
|
+
case "rawHtml":
|
|
1498
|
+
t += r.content, n++;
|
|
1499
|
+
break;
|
|
1500
|
+
default: n++;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
return t;
|
|
1504
|
+
}
|
|
1505
|
+
function Rr(e, t) {
|
|
1506
|
+
let n = "", r = t, i = null;
|
|
1507
|
+
for (; r < e.length && e[r].type === "listItem";) {
|
|
1508
|
+
let t = e[r], a = zr(t.listType);
|
|
1509
|
+
if (i !== null && i !== a && (n += `</${i === "ordered" ? "ol" : "ul"}>`, i = null), i === null) {
|
|
1510
|
+
if (a === "ordered") {
|
|
1511
|
+
let e = t.start !== void 0 && t.start !== 1 ? ` start="${t.start}"` : "";
|
|
1512
|
+
n += `<ol${e}>`;
|
|
1513
|
+
} else n += "<ul>";
|
|
1514
|
+
i = a;
|
|
1515
|
+
}
|
|
1516
|
+
if (t.listType === "task") {
|
|
1517
|
+
let e = t.checked ? " checked" : "";
|
|
1518
|
+
n += `<li><input type="checkbox" disabled${e}><p>${Z(t.content)}</p>`;
|
|
1519
|
+
} else n += `<li><p>${Z(t.content)}</p>`;
|
|
1520
|
+
if (t.childContent) {
|
|
1521
|
+
let e = Nr(t.childContent);
|
|
1522
|
+
n += Lr(e);
|
|
1523
|
+
}
|
|
1524
|
+
n += "</li>", r++;
|
|
1525
|
+
}
|
|
1526
|
+
return i !== null && (n += `</${i === "ordered" ? "ol" : "ul"}>`), {
|
|
1527
|
+
html: n,
|
|
1528
|
+
nextIndex: r
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
function zr(e) {
|
|
1532
|
+
return e === "ordered" ? "ordered" : "bullet";
|
|
1533
|
+
}
|
|
1534
|
+
function Br(e) {
|
|
1535
|
+
let t = "<table>", n = e.headers.every((e) => e.trim() === ""), r = e.headers.length;
|
|
1536
|
+
if (!n) {
|
|
1537
|
+
t += "<thead><tr>";
|
|
1538
|
+
for (let n = 0; n < r; n++) {
|
|
1539
|
+
let r = e.alignments[n], i = r ? ` align="${r}"` : "";
|
|
1540
|
+
t += `<th${i}>${Z(e.headers[n])}</th>`;
|
|
1541
|
+
}
|
|
1542
|
+
t += "</tr></thead>";
|
|
1543
|
+
}
|
|
1544
|
+
if (e.rows.length > 0) {
|
|
1545
|
+
t += "<tbody>";
|
|
1546
|
+
for (let n of e.rows) {
|
|
1547
|
+
t += "<tr>";
|
|
1548
|
+
for (let i = 0; i < r; i++) {
|
|
1549
|
+
let r = i < n.length ? n[i] : "", a = e.alignments[i], o = a ? ` align="${a}"` : "";
|
|
1550
|
+
t += `<td${o}>${Z(r)}</td>`;
|
|
1551
|
+
}
|
|
1552
|
+
t += "</tr>";
|
|
1553
|
+
}
|
|
1554
|
+
t += "</tbody>";
|
|
1555
|
+
}
|
|
1556
|
+
return t += "</table>", t;
|
|
1557
|
+
}
|
|
1558
|
+
function Vr(e) {
|
|
1559
|
+
return Lr(Nr(e));
|
|
1560
|
+
}
|
|
1561
|
+
//#endregion
|
|
1562
|
+
//#region src/api/parsers/markdown/parseMarkdown.ts
|
|
1563
|
+
function Hr(e) {
|
|
1564
|
+
return Vr(e);
|
|
1565
|
+
}
|
|
1566
|
+
function Ur(e, t) {
|
|
1567
|
+
return nr(Hr(e), t);
|
|
1568
|
+
}
|
|
1569
|
+
//#endregion
|
|
1570
|
+
//#region src/editor/managers/ExportManager.ts
|
|
1571
|
+
var Wr = class {
|
|
1572
|
+
editor;
|
|
1573
|
+
constructor(e) {
|
|
1574
|
+
this.editor = e;
|
|
1575
|
+
}
|
|
1576
|
+
blocksToHTMLLossy(e = this.editor.document) {
|
|
1577
|
+
return We(this.editor.pmSchema, this.editor).exportBlocks(e, {});
|
|
1578
|
+
}
|
|
1579
|
+
blocksToFullHTML(e = this.editor.document) {
|
|
1580
|
+
return ln(this.editor.pmSchema, this.editor).serializeBlocks(e, {});
|
|
1581
|
+
}
|
|
1582
|
+
tryParseHTMLToBlocks(e) {
|
|
1583
|
+
return nr(e, this.editor.pmSchema);
|
|
1584
|
+
}
|
|
1585
|
+
blocksToMarkdownLossy(e = this.editor.document) {
|
|
1586
|
+
return Ke(e, this.editor.pmSchema, this.editor, {});
|
|
1587
|
+
}
|
|
1588
|
+
tryParseMarkdownToBlocks(e) {
|
|
1589
|
+
return Ur(e, this.editor.pmSchema);
|
|
1590
|
+
}
|
|
1591
|
+
pasteHTML(e, t = !1) {
|
|
1592
|
+
let n = e;
|
|
1593
|
+
if (!t) {
|
|
1594
|
+
let t = this.tryParseHTMLToBlocks(e);
|
|
1595
|
+
n = this.blocksToFullHTML(t);
|
|
1596
|
+
}
|
|
1597
|
+
n && this.editor.prosemirrorView?.pasteHTML(n);
|
|
1598
|
+
}
|
|
1599
|
+
pasteText(e) {
|
|
1600
|
+
return this.editor.prosemirrorView?.pasteText(e);
|
|
1601
|
+
}
|
|
1602
|
+
pasteMarkdown(e) {
|
|
1603
|
+
let t = Hr(e);
|
|
1604
|
+
return this.pasteHTML(t);
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
//#endregion
|
|
1608
|
+
//#region src/api/blockManipulation/selections/textCursorPosition.ts
|
|
1609
|
+
function Gr(e) {
|
|
1610
|
+
let { block: t } = b(e), r = e.doc.resolve(t.beforePos).nodeBefore, i = e.doc.resolve(t.afterPos).nodeAfter, a = h(e.doc, t.beforePos)?.block.node;
|
|
1611
|
+
return {
|
|
1612
|
+
block: n(t.node, e.doc),
|
|
1613
|
+
prevBlock: r === null ? void 0 : n(r, e.doc),
|
|
1614
|
+
nextBlock: i === null ? void 0 : n(i, e.doc),
|
|
1615
|
+
parentBlock: a === void 0 ? void 0 : n(a, e.doc)
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
function Kr(e, t, n = "start") {
|
|
1619
|
+
let r = typeof t == "string" ? t : t.id, i = D(r, e.doc);
|
|
1620
|
+
if (!i) throw Error(`Block with ID ${r} not found`);
|
|
1621
|
+
e.setSelection(ge(e.doc, E(i.node, i.posBeforeNode), n));
|
|
1622
|
+
}
|
|
1623
|
+
//#endregion
|
|
1624
|
+
//#region src/api/clipboard/fromClipboard/acceptedMIMETypes.ts
|
|
1625
|
+
var qr = [
|
|
1626
|
+
"vscode-editor-data",
|
|
1627
|
+
"blocknote/html",
|
|
1628
|
+
"text/markdown",
|
|
1629
|
+
"text/html",
|
|
1630
|
+
"text/plain",
|
|
1631
|
+
"Files"
|
|
1632
|
+
];
|
|
1633
|
+
//#endregion
|
|
1634
|
+
//#region src/api/clipboard/fromClipboard/handleFileInsertion.ts
|
|
1635
|
+
function Jr(e, t) {
|
|
1636
|
+
if (!e.startsWith(".") || !t.startsWith(".")) throw Error("The strings provided are not valid file extensions.");
|
|
1637
|
+
return e === t;
|
|
1638
|
+
}
|
|
1639
|
+
function Yr(e, t) {
|
|
1640
|
+
let n = e.split("/"), r = t.split("/");
|
|
1641
|
+
if (n.length !== 2) throw Error(`The string ${e} is not a valid MIME type.`);
|
|
1642
|
+
if (r.length !== 2) throw Error(`The string ${t} is not a valid MIME type.`);
|
|
1643
|
+
return n[1] === "*" || r[1] === "*" ? n[0] === r[0] : (n[0] === "*" || r[0] === "*" || n[0] === r[0]) && n[1] === r[1];
|
|
1644
|
+
}
|
|
1645
|
+
function Xr(e, t, n, r = "after") {
|
|
1646
|
+
let i;
|
|
1647
|
+
return i = Array.isArray(t.content) && t.content.length === 0 ? e.updateBlock(t, n).id : e.insertBlocks([n], t, r)[0].id, i;
|
|
1648
|
+
}
|
|
1649
|
+
async function Zr(e, t) {
|
|
1650
|
+
if (!t.uploadFile) {
|
|
1651
|
+
console.warn("Attempted ot insert file, but uploadFile is not set in the BlockNote editor options");
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
let n = "dataTransfer" in e ? e.dataTransfer : e.clipboardData;
|
|
1655
|
+
if (n === null) return;
|
|
1656
|
+
let i = null;
|
|
1657
|
+
for (let e of qr) if (n.types.includes(e)) {
|
|
1658
|
+
i = e;
|
|
1659
|
+
break;
|
|
1660
|
+
}
|
|
1661
|
+
if (i !== "Files") return;
|
|
1662
|
+
let a = n.items;
|
|
1663
|
+
if (a) {
|
|
1664
|
+
e.preventDefault();
|
|
1665
|
+
for (let n = 0; n < a.length; n++) {
|
|
1666
|
+
let i = "file";
|
|
1667
|
+
for (let e of Object.values(t.schema.blockSpecs)) for (let t of e.implementation.meta.fileBlockAccept || []) {
|
|
1668
|
+
let r = t.startsWith("."), o = a[n].getAsFile();
|
|
1669
|
+
if (o && (!r && o.type && Yr(a[n].type, t) || r && Jr("." + o.name.split(".").pop(), t))) {
|
|
1670
|
+
i = e.config.type;
|
|
1671
|
+
break;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
let o = a[n].getAsFile();
|
|
1675
|
+
if (o) {
|
|
1676
|
+
let n = {
|
|
1677
|
+
type: i,
|
|
1678
|
+
props: { name: o.name }
|
|
1679
|
+
}, a;
|
|
1680
|
+
if (e.type === "paste") {
|
|
1681
|
+
let e = t.getTextCursorPosition().block;
|
|
1682
|
+
a = Xr(t, e, n);
|
|
1683
|
+
} else if (e.type === "drop") {
|
|
1684
|
+
let i = {
|
|
1685
|
+
left: e.clientX,
|
|
1686
|
+
top: e.clientY
|
|
1687
|
+
}, o = t.prosemirrorView.posAtCoords(i);
|
|
1688
|
+
if (!o) return;
|
|
1689
|
+
a = t.transact((e) => {
|
|
1690
|
+
let a = T(e, o.pos), s = r(a.block.node, e.doc), c = (t.domElement?.querySelector(`[data-id="${s}"]`))?.getBoundingClientRect(), l = t.getBlock(s);
|
|
1691
|
+
if (l) return Xr(t, l, n, c && (c.top + c.bottom) / 2 > i.top ? "before" : "after");
|
|
1692
|
+
});
|
|
1693
|
+
} else return;
|
|
1694
|
+
if (!a) return;
|
|
1695
|
+
let s = await t.uploadFile(o, a), c = typeof s == "string" ? { props: { url: s } } : { ...s };
|
|
1696
|
+
t.updateBlock(a, c);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
//#endregion
|
|
1702
|
+
//#region src/api/clipboard/fromClipboard/fileDropExtension.ts
|
|
1703
|
+
var Qr = (e) => I.create({
|
|
1704
|
+
name: "dropFile",
|
|
1705
|
+
addProseMirrorPlugins() {
|
|
1706
|
+
return [new j({ props: { handleDOMEvents: { drop(t, n) {
|
|
1707
|
+
if (!e.isEditable) return;
|
|
1708
|
+
let r = null;
|
|
1709
|
+
for (let e of qr) if (n.dataTransfer.types.includes(e)) {
|
|
1710
|
+
r = e;
|
|
1711
|
+
break;
|
|
1712
|
+
}
|
|
1713
|
+
return r === null || r === "Files" && (Zr(n, e), !0);
|
|
1714
|
+
} } } })];
|
|
1715
|
+
}
|
|
1716
|
+
}), $r = /(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/, ei = /(_|__|\*|\*\*|~~|==|\+\+)(?!\s)(?:[^\s](?:.{0,62}[^\s])?|\S)(?=\1)/, ti = /\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/, ni = /(?:\s|^)`(?!\s)(?:[^\s`](?:[^`]{0,46}[^\s`])?|[^\s`])`([^\w]|$)/, ri = /(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/, ii = /(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/, ai = /\n{2} {0,3}-{2,48}\n{2}/, oi = /(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/, si = /(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/, ci = /(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/, li = /^\s*\|(.+\|)+\s*$/m, ui = /^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m, di = /^\s*\|(.+\|)+\s*$/m, fi = (e) => $r.test(e) || ei.test(e) || ti.test(e) || ni.test(e) || ri.test(e) || ii.test(e) || ai.test(e) || oi.test(e) || si.test(e) || ci.test(e) || li.test(e) || ui.test(e) || di.test(e);
|
|
1717
|
+
//#endregion
|
|
1718
|
+
//#region src/api/clipboard/fromClipboard/handleVSCodePaste.ts
|
|
1719
|
+
function pi(e, t) {
|
|
1720
|
+
let { schema: n } = t.state;
|
|
1721
|
+
if (!e.clipboardData) return !1;
|
|
1722
|
+
let r = e.clipboardData.getData("text/plain");
|
|
1723
|
+
if (!r || !n.nodes.codeBlock) return !1;
|
|
1724
|
+
let i = e.clipboardData.getData("vscode-editor-data"), a = (i ? JSON.parse(i) : void 0)?.mode;
|
|
1725
|
+
return a ? (t.pasteHTML(`<pre><code class="language-${a}">${r.replace(/\r\n?/g, "\n")}</code></pre>`), !0) : !1;
|
|
1726
|
+
}
|
|
1727
|
+
//#endregion
|
|
1728
|
+
//#region src/api/clipboard/fromClipboard/pasteExtension.ts
|
|
1729
|
+
function mi({ event: e, editor: t, prioritizeMarkdownOverHTML: n, plainTextAsMarkdown: r }) {
|
|
1730
|
+
if (t.transact((e) => e.selection.$from.parent.type.spec.code && e.selection.$to.parent.type.spec.code)) {
|
|
1731
|
+
let n = e.clipboardData?.getData("text/plain");
|
|
1732
|
+
if (n) return t.pasteText(n), !0;
|
|
1733
|
+
}
|
|
1734
|
+
let i;
|
|
1735
|
+
for (let t of qr) if (e.clipboardData.types.includes(t)) {
|
|
1736
|
+
i = t;
|
|
1737
|
+
break;
|
|
1738
|
+
}
|
|
1739
|
+
if (!i) return !0;
|
|
1740
|
+
if (i === "vscode-editor-data") {
|
|
1741
|
+
if (pi(e, t.prosemirrorView)) return !0;
|
|
1742
|
+
i = "text/plain";
|
|
1743
|
+
}
|
|
1744
|
+
if (i === "Files") return Zr(e, t), !0;
|
|
1745
|
+
let a = e.clipboardData.getData(i);
|
|
1746
|
+
if (i === "blocknote/html") return t.pasteHTML(a, !0), !0;
|
|
1747
|
+
if (i === "text/markdown") return t.pasteMarkdown(a), !0;
|
|
1748
|
+
if (n) {
|
|
1749
|
+
let n = e.clipboardData.getData("text/plain");
|
|
1750
|
+
if (fi(n)) return t.pasteMarkdown(n), !0;
|
|
1751
|
+
}
|
|
1752
|
+
return i === "text/html" ? (t.pasteHTML(a), !0) : r ? (t.pasteMarkdown(a), !0) : (t.pasteText(a), !0);
|
|
1753
|
+
}
|
|
1754
|
+
var hi = (e, t) => I.create({
|
|
1755
|
+
name: "pasteFromClipboard",
|
|
1756
|
+
addProseMirrorPlugins() {
|
|
1757
|
+
return [new j({ props: { handleDOMEvents: { paste(n, r) {
|
|
1758
|
+
if (r.preventDefault(), e.isEditable) return t({
|
|
1759
|
+
event: r,
|
|
1760
|
+
editor: e,
|
|
1761
|
+
defaultPasteHandler: ({ prioritizeMarkdownOverHTML: t = !0, plainTextAsMarkdown: n = !0 } = {}) => mi({
|
|
1762
|
+
event: r,
|
|
1763
|
+
editor: e,
|
|
1764
|
+
prioritizeMarkdownOverHTML: t,
|
|
1765
|
+
plainTextAsMarkdown: n
|
|
1766
|
+
})
|
|
1767
|
+
});
|
|
1768
|
+
} } } })];
|
|
1769
|
+
}
|
|
1770
|
+
});
|
|
1771
|
+
//#endregion
|
|
1772
|
+
//#region src/api/clipboard/toClipboard/copyExtension.ts
|
|
1773
|
+
function gi(e, t, n) {
|
|
1774
|
+
let r = !1, i = e.state.selection instanceof z;
|
|
1775
|
+
if (!i) {
|
|
1776
|
+
let n = e.state.doc.slice(e.state.selection.from, e.state.selection.to, !1).content, i = [];
|
|
1777
|
+
for (let e = 0; e < n.childCount; e++) i.push(n.child(e));
|
|
1778
|
+
r = i.find((e) => e.type.isInGroup("bnBlock") || e.type.name === "blockGroup" || e.type.spec.group === "blockContent") === void 0, r && (t = n);
|
|
1779
|
+
}
|
|
1780
|
+
let a, o = We(e.state.schema, n);
|
|
1781
|
+
if (i) {
|
|
1782
|
+
t.firstChild?.type.name === "table" && (t = t.firstChild.content);
|
|
1783
|
+
let e = re(t, n.schema.inlineContentSchema, n.schema.styleSchema);
|
|
1784
|
+
a = `<table>${o.exportInlineContent(e, {})}</table>`;
|
|
1785
|
+
} else if (r) {
|
|
1786
|
+
let e = we(t, n.schema.inlineContentSchema, n.schema.styleSchema);
|
|
1787
|
+
a = o.exportInlineContent(e, {});
|
|
1788
|
+
} else {
|
|
1789
|
+
let e = Ie(t);
|
|
1790
|
+
a = o.exportBlocks(e, {});
|
|
1791
|
+
}
|
|
1792
|
+
return a;
|
|
1793
|
+
}
|
|
1794
|
+
function $(e, t) {
|
|
1795
|
+
"node" in e.state.selection && e.state.selection.node.type.spec.group === "blockContent" && t.transact((t) => t.setSelection(new A(t.doc.resolve(e.state.selection.from - 1))));
|
|
1796
|
+
let n = e.serializeForClipboard(e.state.selection.content()).dom.innerHTML, r = e.state.selection.content().content, i = gi(e, r, t), { $from: a, $to: o } = e.state.selection, s = a.parent.type.name, c = t.schema.blockSpecs[s];
|
|
1797
|
+
return {
|
|
1798
|
+
clipboardHTML: n,
|
|
1799
|
+
externalHTML: i,
|
|
1800
|
+
markdown: a.sameParent(o) && c?.implementation.meta.code === !0 ? e.state.doc.textBetween(a.pos, o.pos) : $e(i)
|
|
1801
|
+
};
|
|
1802
|
+
}
|
|
1803
|
+
var _i = (e) => {
|
|
1804
|
+
if (e.state.selection.empty) return !0;
|
|
1805
|
+
let t = window.getSelection();
|
|
1806
|
+
if (t && !t.isCollapsed) {
|
|
1807
|
+
let e = t.focusNode;
|
|
1808
|
+
for (; e;) {
|
|
1809
|
+
if (e instanceof HTMLElement && e.getAttribute("contenteditable") === "false") return !0;
|
|
1810
|
+
e = e.parentElement;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
return !1;
|
|
1814
|
+
}, vi = (e, t, n) => {
|
|
1815
|
+
n.preventDefault(), n.clipboardData.clearData();
|
|
1816
|
+
let { clipboardHTML: r, externalHTML: i, markdown: a } = $(t, e);
|
|
1817
|
+
n.clipboardData.setData("blocknote/html", r), n.clipboardData.setData("text/html", i), n.clipboardData.setData("text/plain", a);
|
|
1818
|
+
}, yi = (e) => I.create({
|
|
1819
|
+
name: "copyToClipboard",
|
|
1820
|
+
addProseMirrorPlugins() {
|
|
1821
|
+
return [new j({ props: { handleDOMEvents: {
|
|
1822
|
+
copy(t, n) {
|
|
1823
|
+
return _i(t) || vi(e, t, n), !0;
|
|
1824
|
+
},
|
|
1825
|
+
cut(t, n) {
|
|
1826
|
+
return _i(t) ? !0 : (vi(e, t, n), t.editable && t.dispatch(t.state.tr.deleteSelection()), !0);
|
|
1827
|
+
},
|
|
1828
|
+
dragstart(t, n) {
|
|
1829
|
+
if (!("node" in t.state.selection) || t.state.selection.node.type.spec.group !== "blockContent") return;
|
|
1830
|
+
e.transact((e) => e.setSelection(new A(e.doc.resolve(t.state.selection.from - 1)))), n.preventDefault(), n.dataTransfer.clearData();
|
|
1831
|
+
let { clipboardHTML: r, externalHTML: i, markdown: a } = $(t, e);
|
|
1832
|
+
return n.dataTransfer.setData("blocknote/html", r), n.dataTransfer.setData("text/html", i), n.dataTransfer.setData("text/plain", a), !0;
|
|
1833
|
+
}
|
|
1834
|
+
} } })];
|
|
1835
|
+
}
|
|
1836
|
+
}), bi = I.create({
|
|
1837
|
+
name: "blockBackgroundColor",
|
|
1838
|
+
addGlobalAttributes() {
|
|
1839
|
+
return [{
|
|
1840
|
+
types: ["tableCell", "tableHeader"],
|
|
1841
|
+
attributes: { backgroundColor: ne() }
|
|
1842
|
+
}];
|
|
1843
|
+
}
|
|
1844
|
+
}), xi = L.create({
|
|
1845
|
+
name: "hardBreak",
|
|
1846
|
+
inline: !0,
|
|
1847
|
+
group: "inline",
|
|
1848
|
+
selectable: !1,
|
|
1849
|
+
linebreakReplacement: !0,
|
|
1850
|
+
priority: 10,
|
|
1851
|
+
parseHTML() {
|
|
1852
|
+
return [{ tag: "br" }];
|
|
1853
|
+
},
|
|
1854
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
1855
|
+
return ["br", St(this.options.HTMLAttributes, e)];
|
|
1856
|
+
},
|
|
1857
|
+
renderText() {
|
|
1858
|
+
return "\n";
|
|
1859
|
+
}
|
|
1860
|
+
});
|
|
1861
|
+
//#endregion
|
|
1862
|
+
//#region src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts
|
|
1863
|
+
function Si(e, t) {
|
|
1864
|
+
return e.contentKind === "inline" && t.contentKind === "inline" ? t.content.node.content : void 0;
|
|
1865
|
+
}
|
|
1866
|
+
function Ci(e, t, n, r) {
|
|
1867
|
+
if (!n.children) return !1;
|
|
1868
|
+
let i = Si(n, r);
|
|
1869
|
+
if (i === void 0 || i.size > 0 && !n.content.node.type.validContent(n.content.node.content.append(i))) return !1;
|
|
1870
|
+
if (t) {
|
|
1871
|
+
let a = e.tr;
|
|
1872
|
+
n.children.node.childCount === 1 && !r.children ? a.delete(n.children.beforePos, n.children.afterPos) : a.replaceWith(r.block.beforePos, r.block.afterPos, r.children?.node.content ?? O.empty);
|
|
1873
|
+
let o = n.contentEnd;
|
|
1874
|
+
i.size > 0 && a.insert(o, i), a.setSelection(M.near(a.doc.resolve(o), -1)), t(a.scrollIntoView());
|
|
1875
|
+
}
|
|
1876
|
+
return !0;
|
|
1877
|
+
}
|
|
1878
|
+
var wi = (e) => ({ state: t, dispatch: n }) => {
|
|
1879
|
+
let r = w(t.doc, e);
|
|
1880
|
+
if (!r.hasContent) return !1;
|
|
1881
|
+
let i = x(t.doc, r.block.beforePos);
|
|
1882
|
+
if (!i) {
|
|
1883
|
+
let e = h(t.doc, r.block.beforePos);
|
|
1884
|
+
return e?.hasContent ? Ci(t, n, e, r) : !1;
|
|
1885
|
+
}
|
|
1886
|
+
let a = Te(i);
|
|
1887
|
+
if (!a.hasContent || Si(a, r) === void 0) return !1;
|
|
1888
|
+
if (a.isContentEmpty && a.content.node.sameMarkup(r.content.node)) {
|
|
1889
|
+
if (n) {
|
|
1890
|
+
let e = t.tr.delete(r.block.beforePos, r.block.afterPos).replaceWith(a.block.beforePos, a.block.afterPos, r.block.node);
|
|
1891
|
+
e.setSelection(N.create(e.doc, a.contentStart)), n(e.scrollIntoView());
|
|
1892
|
+
}
|
|
1893
|
+
return !0;
|
|
1894
|
+
}
|
|
1895
|
+
if (n && r.children) {
|
|
1896
|
+
let e = t.doc.resolve(r.children.childrenStart).blockRange(t.doc.resolve(r.children.childrenEnd));
|
|
1897
|
+
if (!e) throw Error("Children of a block are expected to form a block range");
|
|
1898
|
+
t.tr.lift(e, t.doc.resolve(r.block.beforePos).depth);
|
|
1899
|
+
}
|
|
1900
|
+
return n && n(t.tr.delete(a.contentEnd, r.contentStart)), !0;
|
|
1901
|
+
}, Ti = (e, t, n, r) => ({ state: i, dispatch: a }) => !a || Ei(i.tr, e, t, n, r), Ei = (e, t, n, r, i) => {
|
|
1902
|
+
let a = y(e.doc, t), o = E(a.node, a.posBeforeNode);
|
|
1903
|
+
if (!o.hasContent) return !1;
|
|
1904
|
+
let s = _(e), c = [{
|
|
1905
|
+
type: o.block.node.type,
|
|
1906
|
+
attrs: r ? {
|
|
1907
|
+
...o.block.node.attrs,
|
|
1908
|
+
id: void 0
|
|
1909
|
+
} : {}
|
|
1910
|
+
}, {
|
|
1911
|
+
type: n ? o.content.node.type : s.nodes.paragraph,
|
|
1912
|
+
attrs: r ? { ...o.content.node.attrs } : {}
|
|
1913
|
+
}], l = i && t !== o.contentStart ? o.children : void 0;
|
|
1914
|
+
if (l && e.delete(l.beforePos, l.afterPos), e.split(t, 2, c), l) {
|
|
1915
|
+
let t = e.doc.nodeAt(o.block.beforePos);
|
|
1916
|
+
if (!t?.firstChild) throw Error("Split lost its original block");
|
|
1917
|
+
e.insert(o.block.beforePos + 1 + t.firstChild.nodeSize, l.node);
|
|
1918
|
+
}
|
|
1919
|
+
return !0;
|
|
1920
|
+
};
|
|
1921
|
+
//#endregion
|
|
1922
|
+
//#region src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts
|
|
1923
|
+
function Di(e, t, n) {
|
|
1924
|
+
let r = ce(e.doc, t.beforePos);
|
|
1925
|
+
e.delete(t.beforePos, t.afterPos);
|
|
1926
|
+
let i = e.mapping.map(n);
|
|
1927
|
+
e.insert(i, t.node);
|
|
1928
|
+
let a = e.steps.length;
|
|
1929
|
+
zt(e, r), e.setSelection(N.near(e.doc.resolve(e.mapping.slice(a).map(i) + 1)));
|
|
1930
|
+
}
|
|
1931
|
+
function Oi(e, t, n, r = n.block) {
|
|
1932
|
+
return e.insertContentAt(n.block.afterPos, n.children?.node.content || O.empty).deleteRange({
|
|
1933
|
+
from: r.beforePos,
|
|
1934
|
+
to: r.afterPos
|
|
1935
|
+
}).insertContentAt(t.contentEnd, Si(t, n) ?? null).setTextSelection(t.contentEnd).scrollIntoView().run();
|
|
1936
|
+
}
|
|
1937
|
+
var ki = I.create({
|
|
1938
|
+
priority: 50,
|
|
1939
|
+
addKeyboardShortcuts() {
|
|
1940
|
+
let e = this.options.editor;
|
|
1941
|
+
function r(t, r) {
|
|
1942
|
+
let i = n(t, r);
|
|
1943
|
+
return e.schema.blockSpecs[i.type].implementation.keyboard(i);
|
|
1944
|
+
}
|
|
1945
|
+
function i(e) {
|
|
1946
|
+
return (t) => r(t, e).childrenCanOutdent;
|
|
1947
|
+
}
|
|
1948
|
+
let o = () => this.editor.commands.first(({ chain: e, commands: n }) => [
|
|
1949
|
+
() => n.deleteSelection(),
|
|
1950
|
+
() => n.undoInputRule(),
|
|
1951
|
+
() => n.command(({ state: e }) => {
|
|
1952
|
+
let t = b(e);
|
|
1953
|
+
if (!t.hasContent || e.selection.from !== t.contentStart) return !1;
|
|
1954
|
+
let i = r(t.block.node, e.doc).resetsTo, a = t.content.node;
|
|
1955
|
+
return a.type.name === i.type && Object.entries(i.props ?? {}).every(([e, t]) => a.attrs[e] === t) ? !1 : n.command(G(t.block.beforePos, i));
|
|
1956
|
+
}),
|
|
1957
|
+
() => n.command(({ state: t }) => {
|
|
1958
|
+
let n = b(t);
|
|
1959
|
+
if (!n.hasContent) return !1;
|
|
1960
|
+
let { block: r } = n, i = x(t.doc, n.block.beforePos);
|
|
1961
|
+
if (i && !i.hasContent) return !1;
|
|
1962
|
+
let a = t.selection.from === n.contentStart, o = t.selection.empty, s = r.beforePos;
|
|
1963
|
+
return a && o ? e().command(wi(s)).scrollIntoView().run() : !1;
|
|
1964
|
+
}),
|
|
1965
|
+
() => n.command(({ state: e, tr: n, dispatch: r }) => {
|
|
1966
|
+
let i = b(e);
|
|
1967
|
+
if (!i.hasContent || e.selection.from !== i.contentStart) return !1;
|
|
1968
|
+
let a = i.block.node.type, o = x(n.doc, i.block.beforePos), s;
|
|
1969
|
+
if (o) {
|
|
1970
|
+
if (o.hasContent) return !1;
|
|
1971
|
+
} else {
|
|
1972
|
+
let e = n.doc.resolve(i.block.beforePos);
|
|
1973
|
+
if (!v(e.parent.type)) return !1;
|
|
1974
|
+
let t = n.doc.resolve(e.before()), r = t.nodeBefore;
|
|
1975
|
+
v(t.parent.type) && r && v(r.type) ? o = E(r, t.pos - r.nodeSize) : s = xe(n.doc, t.pos, a);
|
|
1976
|
+
}
|
|
1977
|
+
return o && (s = t(n.doc, o, "last-child", a)?.pos), s !== void 0 && (r && Di(n, i.block, s), !0);
|
|
1978
|
+
}),
|
|
1979
|
+
() => n.command(({ state: e, tr: t, dispatch: n }) => {
|
|
1980
|
+
let r = b(e);
|
|
1981
|
+
if (!r.hasContent || !e.selection.empty || r.contentKind !== "inline" || !r.isContentEmpty) return !1;
|
|
1982
|
+
let i = x(e.doc, r.block.beforePos), a = i ? void 0 : h(e.doc, r.block.beforePos), o = i ? Te(i) : a;
|
|
1983
|
+
return o?.hasContent ? (n && (a?.children?.node.childCount === 1 && !r.children ? t.delete(a.children.beforePos, a.children.afterPos) : t.replaceWith(r.block.beforePos, r.block.afterPos, r.children?.node.content ?? O.empty), t.setSelection(o.contentKind === "none" ? A.create(t.doc, o.content.beforePos) : N.near(t.doc.resolve(o.contentEnd), -1)), t.scrollIntoView()), !0) : !1;
|
|
1984
|
+
}),
|
|
1985
|
+
() => n.command(({ state: e, tr: t, dispatch: n }) => {
|
|
1986
|
+
let r = b(e);
|
|
1987
|
+
if (!r.hasContent) return !1;
|
|
1988
|
+
let i = e.selection.from === r.contentStart, a = e.selection.empty, o = x(e.doc, r.block.beforePos);
|
|
1989
|
+
if (o && i && a) {
|
|
1990
|
+
let e = Te(o);
|
|
1991
|
+
if (!e.hasContent) return !1;
|
|
1992
|
+
if (e.contentKind === "none" || e.contentKind === "inline" && e.isContentEmpty) return n && (t.delete(r.block.beforePos, r.block.afterPos), t.replaceWith(e.block.beforePos, e.block.afterPos, r.block.node), t.setSelection(N.near(t.doc.resolve(e.block.beforePos + 2))), t.scrollIntoView()), !0;
|
|
1993
|
+
}
|
|
1994
|
+
return !1;
|
|
1995
|
+
}),
|
|
1996
|
+
() => n.command(({ state: e, tr: t }) => {
|
|
1997
|
+
let n = b(e);
|
|
1998
|
+
return !n.hasContent || !e.selection.empty || e.selection.from !== n.contentStart ? !1 : Mn(t, t.doc.type.schema.nodes.blockContainer, t.doc.type.schema.nodes.blockGroup, i(t.doc));
|
|
1999
|
+
})
|
|
2000
|
+
]), s = () => this.editor.commands.first(({ chain: e, commands: t }) => [
|
|
2001
|
+
() => t.deleteSelection(),
|
|
2002
|
+
() => t.command(({ state: t }) => {
|
|
2003
|
+
let n = b(t);
|
|
2004
|
+
if (!n.hasContent || !n.children) return !1;
|
|
2005
|
+
let { children: r } = n;
|
|
2006
|
+
if (r.node.childCount === 0) return !1;
|
|
2007
|
+
let i = t.selection.from === n.contentEnd, a = t.selection.empty, o = w(t.doc, r.childrenStart);
|
|
2008
|
+
return o.hasContent && i && a ? Oi(e(), n, o, r.node.childCount === 1 ? r : o.block) : !1;
|
|
2009
|
+
}),
|
|
2010
|
+
() => t.command(({ state: t }) => {
|
|
2011
|
+
let n = b(t);
|
|
2012
|
+
if (!n.hasContent) return !1;
|
|
2013
|
+
let { block: r } = n, i = a(t.doc, n.block.beforePos);
|
|
2014
|
+
if (!i || !i.hasContent) return !1;
|
|
2015
|
+
let o = t.selection.from === n.contentEnd, s = t.selection.empty, c = r.afterPos;
|
|
2016
|
+
return o && s ? e().command(wi(c)).scrollIntoView().run() : !1;
|
|
2017
|
+
}),
|
|
2018
|
+
() => t.command(({ state: e, tr: t, dispatch: n }) => {
|
|
2019
|
+
let r = b(e);
|
|
2020
|
+
if (!r.hasContent || e.selection.from !== r.contentEnd) return !1;
|
|
2021
|
+
let i = t.doc.resolve(r.block.afterPos);
|
|
2022
|
+
for (; !i.nodeAfter && i.depth > 0 && v(i.parent.type);) i = t.doc.resolve(i.after());
|
|
2023
|
+
let a = i.nodeAfter;
|
|
2024
|
+
if (!a || i.pos === r.block.afterPos && !v(a.type)) return !1;
|
|
2025
|
+
let o = te(E(a, i.pos));
|
|
2026
|
+
return o ? (n && Di(t, o.block, r.block.afterPos), !0) : !1;
|
|
2027
|
+
}),
|
|
2028
|
+
() => t.command(({ state: t }) => {
|
|
2029
|
+
let n = b(t);
|
|
2030
|
+
if (!n.hasContent) return !1;
|
|
2031
|
+
let r = t.selection.from === n.contentEnd, i = t.selection.empty;
|
|
2032
|
+
if (r && i) {
|
|
2033
|
+
let r, i = n;
|
|
2034
|
+
for (; i && (r = a(t.doc, i.block.beforePos), !r);) i = h(t.doc, i.block.beforePos);
|
|
2035
|
+
return !r || !r.hasContent ? !1 : Oi(e(), n, r, r.block);
|
|
2036
|
+
}
|
|
2037
|
+
return !1;
|
|
2038
|
+
}),
|
|
2039
|
+
() => t.command(({ state: t }) => {
|
|
2040
|
+
let n = b(t);
|
|
2041
|
+
if (!n.hasContent) return !1;
|
|
2042
|
+
if (n.isContentEmpty && n.contentKind === "inline") {
|
|
2043
|
+
let r = a(t.doc, n.block.beforePos);
|
|
2044
|
+
if (!r || !r.hasContent) return !1;
|
|
2045
|
+
let i = e();
|
|
2046
|
+
return i.command(({ tr: e }) => (e.setSelection(ge(e.doc, r, "start")), !0)), i.deleteRange({
|
|
2047
|
+
from: n.block.beforePos,
|
|
2048
|
+
to: n.block.afterPos
|
|
2049
|
+
}).scrollIntoView().run();
|
|
2050
|
+
}
|
|
2051
|
+
return !1;
|
|
2052
|
+
}),
|
|
2053
|
+
() => t.command(({ state: t }) => {
|
|
2054
|
+
let n = b(t);
|
|
2055
|
+
if (!n.hasContent) return !1;
|
|
2056
|
+
let r = t.selection.from === n.contentEnd, i = t.selection.empty, o = a(t.doc, n.block.beforePos);
|
|
2057
|
+
return !o || !o.hasContent ? !1 : o && r && i && (o.contentKind === "none" || o.contentKind === "inline" && o.isContentEmpty) ? e().deleteRange({
|
|
2058
|
+
from: o.block.beforePos,
|
|
2059
|
+
to: o.block.afterPos
|
|
2060
|
+
}).insertContentAt(n.block.afterPos, o.children?.node.content ?? null).run() : !1;
|
|
2061
|
+
})
|
|
2062
|
+
]), c = (e = !1) => this.editor.commands.first(({ commands: t, tr: n }) => [
|
|
2063
|
+
() => t.command(({ state: e }) => {
|
|
2064
|
+
let n = b(e);
|
|
2065
|
+
if (!n.hasContent || !e.selection.empty || !n.isContentEmpty) return !1;
|
|
2066
|
+
let i = r(n.block.node, e.doc);
|
|
2067
|
+
return i.emptyEnterResets ? t.command(G(n.block.beforePos, i.resetsTo)) : !1;
|
|
2068
|
+
}),
|
|
2069
|
+
() => t.command(({ state: e, tr: t }) => {
|
|
2070
|
+
let n = b(e);
|
|
2071
|
+
if (!n.hasContent) return !1;
|
|
2072
|
+
let { block: a } = n, { depth: o } = e.doc.resolve(a.beforePos), s = e.selection.$anchor.parentOffset === 0, c = e.selection.anchor === e.selection.head, l = n.isContentEmpty;
|
|
2073
|
+
if (s && c && l && o > 1) {
|
|
2074
|
+
let n = h(e.doc, a.beforePos);
|
|
2075
|
+
return n && r(n.block.node, e.doc).emptyChildEnter !== "outdent" ? !1 : Mn(t, t.doc.type.schema.nodes.blockContainer, t.doc.type.schema.nodes.blockGroup, i(t.doc));
|
|
2076
|
+
}
|
|
2077
|
+
return !1;
|
|
2078
|
+
}),
|
|
2079
|
+
() => t.command(({ state: t }) => {
|
|
2080
|
+
let i = b(t), a = this.options.editor.schema.blockSpecs[i.blockNoteType], o = r(i.block.node, t.doc);
|
|
2081
|
+
if (o.enter === "line-break" || e && o.shiftEnter === "line-break") {
|
|
2082
|
+
if (a?.config?.content === "plain") return n.insertText("\n", n.selection.head), !0;
|
|
2083
|
+
let e = n.storedMarks || n.selection.$head.marks().filter((e) => this.editor.extensionManager.splittableMarks.includes(e.type.name));
|
|
2084
|
+
return n.insert(n.selection.head, n.doc.type.schema.nodes.hardBreak.create()).ensureMarks(e), !0;
|
|
2085
|
+
}
|
|
2086
|
+
return !1;
|
|
2087
|
+
}),
|
|
2088
|
+
() => t.command(({ state: e, tr: t, dispatch: n }) => {
|
|
2089
|
+
let i = b(e);
|
|
2090
|
+
if (!i.hasContent) return !1;
|
|
2091
|
+
let a = e.selection.anchor === e.selection.head, o = i.isContentEmpty;
|
|
2092
|
+
if (!a || !o) return !1;
|
|
2093
|
+
let s = t.doc.resolve(i.block.beforePos);
|
|
2094
|
+
if (t.doc.resolve(i.block.afterPos).nodeAfter !== null) return !1;
|
|
2095
|
+
let c = h(t.doc, i.block.beforePos);
|
|
2096
|
+
if (!c || r(c.block.node, t.doc).emptyChildEnter !== "exit-at-end" || s.index() === 0 && c.hasContent) return !1;
|
|
2097
|
+
let l = xe(t.doc, c.block.afterPos, e.schema.nodes.blockContainer, "after");
|
|
2098
|
+
return l !== void 0 && (n && (Di(t, i.block, l), t.scrollIntoView()), !0);
|
|
2099
|
+
}),
|
|
2100
|
+
() => t.command(({ state: e, dispatch: t, tr: n }) => {
|
|
2101
|
+
let i = b(e);
|
|
2102
|
+
if (!i.hasContent) return !1;
|
|
2103
|
+
let { block: a } = i, o = e.selection.$anchor.parentOffset === 0, s = e.selection.anchor === e.selection.head, c = i.isContentEmpty;
|
|
2104
|
+
if (o && s && c && r(i.block.node, e.doc).enter !== "into-children") {
|
|
2105
|
+
let r = a.afterPos, o = r + 2;
|
|
2106
|
+
if (t) {
|
|
2107
|
+
let t = e.schema.nodes.blockContainer.createAndFill(void 0, [e.schema.nodes.paragraph.createAndFill() || void 0, i.children?.node].filter((e) => e !== void 0));
|
|
2108
|
+
n.insert(r, t).setSelection(new N(n.doc.resolve(o))).scrollIntoView(), i.children && n.delete(i.children.beforePos, i.children.afterPos);
|
|
2109
|
+
}
|
|
2110
|
+
return !0;
|
|
2111
|
+
}
|
|
2112
|
+
return !1;
|
|
2113
|
+
}),
|
|
2114
|
+
() => t.command(({ state: e, tr: t, dispatch: n }) => {
|
|
2115
|
+
let i = b(e);
|
|
2116
|
+
if (!i.hasContent || i.contentKind === "table" || !e.selection.empty || i.isContentEmpty || e.selection.from !== i.contentStart) return !1;
|
|
2117
|
+
if (n) {
|
|
2118
|
+
let n = r(i.block.node, e.doc).splitKeepsType ? i.content.node.type : e.schema.nodes.paragraph, a = e.schema.nodes.blockContainer.create(void 0, n.create());
|
|
2119
|
+
t.insert(i.block.beforePos, a).scrollIntoView();
|
|
2120
|
+
}
|
|
2121
|
+
return !0;
|
|
2122
|
+
}),
|
|
2123
|
+
() => t.command(({ state: e, tr: t, dispatch: n }) => {
|
|
2124
|
+
let i = b(e);
|
|
2125
|
+
if (!i.hasContent || r(i.block.node, e.doc).enter !== "into-children" || !e.selection.empty || e.selection.from < i.contentStart || e.selection.from > i.contentEnd) return !1;
|
|
2126
|
+
if (n) {
|
|
2127
|
+
let n = i.content.node.cut(e.selection.from - i.contentStart), r = e.schema.nodes.blockContainer.create(void 0, e.schema.nodes.paragraph.create(void 0, n.content));
|
|
2128
|
+
t.delete(e.selection.from, i.contentEnd);
|
|
2129
|
+
let a = w(t.doc, i.block.beforePos).children, o = a ? a.childrenStart : t.mapping.map(i.content.afterPos);
|
|
2130
|
+
t.insert(o, a ? r : e.schema.nodes.blockGroup.create(void 0, r)).setSelection(new N(t.doc.resolve(o + (a ? 2 : 3)))).scrollIntoView();
|
|
2131
|
+
}
|
|
2132
|
+
return !0;
|
|
2133
|
+
}),
|
|
2134
|
+
() => t.command(({ state: e, chain: t }) => {
|
|
2135
|
+
let n = b(e);
|
|
2136
|
+
if (!n.hasContent) return !1;
|
|
2137
|
+
let i = e.selection.$anchor.parentOffset === 0;
|
|
2138
|
+
if (!n.isContentEmpty) {
|
|
2139
|
+
let a = r(n.block.node, e.doc), o = i || a.splitKeepsType;
|
|
2140
|
+
return t().deleteSelection().command(Ti(e.selection.from, o, i, a.splitKeepsChildren)).scrollIntoView().run(), !0;
|
|
2141
|
+
}
|
|
2142
|
+
return !1;
|
|
2143
|
+
})
|
|
2144
|
+
]), l = this.options;
|
|
2145
|
+
function u(e) {
|
|
2146
|
+
let { editor: t, tabBehavior: n } = l;
|
|
2147
|
+
return n !== "prefer-indent" && (t.getExtension(be)?.store.state || t.getExtension(Oe)?.store.state !== void 0) ? !1 : e ? Pn(t) : An(t);
|
|
2148
|
+
}
|
|
2149
|
+
return {
|
|
2150
|
+
Backspace: o,
|
|
2151
|
+
Delete: s,
|
|
2152
|
+
Enter: () => c(),
|
|
2153
|
+
"Shift-Enter": () => c(!0),
|
|
2154
|
+
Tab: () => u(!1),
|
|
2155
|
+
"Shift-Tab": () => u(!0),
|
|
2156
|
+
"Shift-Mod-ArrowUp": () => (this.options.editor.moveBlocksUp(), !0),
|
|
2157
|
+
"Shift-Mod-ArrowDown": () => (this.options.editor.moveBlocksDown(), !0),
|
|
2158
|
+
"Mod-z": () => this.options.editor.undo(),
|
|
2159
|
+
"Mod-y": () => this.options.editor.redo(),
|
|
2160
|
+
"Shift-Mod-z": () => this.options.editor.redo(),
|
|
2161
|
+
"Mod-a": () => {
|
|
2162
|
+
let e = this.editor.view, { doc: t, selection: n, tr: r } = e.state, i = N.between(M.atStart(t).$from, M.atEnd(t).$to);
|
|
2163
|
+
if (this.options.selectAllBehavior === "document") return e.dispatch(r.setSelection(i)), !0;
|
|
2164
|
+
let a, o = b(e.state);
|
|
2165
|
+
if (o.hasContent) {
|
|
2166
|
+
let e = o.contentStart, n = o.contentEnd, r = N.between(t.resolve(e), t.resolve(n));
|
|
2167
|
+
!r.empty && r.from >= e && r.to <= n && (a = r);
|
|
2168
|
+
}
|
|
2169
|
+
let s = !a || n.from < a.from || n.to > a.to || n.from === a.from && n.to === a.to;
|
|
2170
|
+
return a && !s ? r.setSelection(a).scrollIntoView() : r.setSelection(i), e.dispatch(r), !0;
|
|
2171
|
+
}
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
}), Ai = I.create({
|
|
2175
|
+
name: "textAlignment",
|
|
2176
|
+
addGlobalAttributes() {
|
|
2177
|
+
return [{
|
|
2178
|
+
types: ["tableCell", "tableHeader"],
|
|
2179
|
+
attributes: { textAlignment: {
|
|
2180
|
+
default: "left",
|
|
2181
|
+
parseHTML: (e) => e.getAttribute("data-text-alignment"),
|
|
2182
|
+
renderHTML: (e) => e.textAlignment === "left" ? {} : { "data-text-alignment": e.textAlignment }
|
|
2183
|
+
} }
|
|
2184
|
+
}];
|
|
2185
|
+
}
|
|
2186
|
+
}), ji = I.create({
|
|
2187
|
+
name: "blockTextColor",
|
|
2188
|
+
addGlobalAttributes() {
|
|
2189
|
+
return [{
|
|
2190
|
+
types: [
|
|
2191
|
+
"table",
|
|
2192
|
+
"tableCell",
|
|
2193
|
+
"tableHeader"
|
|
2194
|
+
],
|
|
2195
|
+
attributes: { textColor: Ee() }
|
|
2196
|
+
}];
|
|
2197
|
+
}
|
|
2198
|
+
}), Mi = "[\0- \xA0 -\u2029 ]", Ni = new RegExp(Mi), Pi = RegExp(`${Mi}$`), Fi = new RegExp(Mi, "g");
|
|
2199
|
+
//#endregion
|
|
2200
|
+
//#region src/extensions/tiptap-extensions/Link/helpers/autolink.ts
|
|
2201
|
+
function Ii(e) {
|
|
2202
|
+
return e.length === 1 ? e[0].isLink : e.length === 3 && e[1].isLink ? ["()", "[]"].includes(e[0].value + e[2].value) : !1;
|
|
2203
|
+
}
|
|
2204
|
+
function Li(e) {
|
|
2205
|
+
return new B({
|
|
2206
|
+
key: new V("autolink"),
|
|
2207
|
+
appendTransaction: (t, n, r) => {
|
|
2208
|
+
let i = t.some((e) => e.docChanged) && !n.doc.eq(r.doc), a = t.some((e) => e.getMeta("preventAutolink"));
|
|
2209
|
+
if (!i || a) return;
|
|
2210
|
+
let { tr: o } = r, s = Se(n.doc, t);
|
|
2211
|
+
if (me(s).forEach(({ newRange: t }) => {
|
|
2212
|
+
let n = mt(r.doc, t, (e) => e.isTextblock), i, a;
|
|
2213
|
+
if (n.length > 1) i = n[0], a = r.doc.textBetween(i.pos, i.pos + i.node.nodeSize, void 0, " ");
|
|
2214
|
+
else if (n.length) {
|
|
2215
|
+
let e = r.doc.textBetween(t.from, t.to, " ", " ");
|
|
2216
|
+
if (!Pi.test(e)) return;
|
|
2217
|
+
i = n[0], a = r.doc.textBetween(i.pos, t.to, void 0, " ");
|
|
2218
|
+
}
|
|
2219
|
+
if (i && a) {
|
|
2220
|
+
let t = a.split(Ni).filter(Boolean);
|
|
2221
|
+
if (t.length <= 0) return;
|
|
2222
|
+
let n = t[t.length - 1], s = i.pos + a.lastIndexOf(n);
|
|
2223
|
+
if (!n) return;
|
|
2224
|
+
let c = Qe(n, e.defaultProtocol);
|
|
2225
|
+
if (!Ii(c)) return;
|
|
2226
|
+
c.filter((e) => e.isLink).map((e) => ({
|
|
2227
|
+
...e,
|
|
2228
|
+
from: s + e.start + 1,
|
|
2229
|
+
to: s + e.end + 1
|
|
2230
|
+
})).filter((e) => !r.schema.marks.code || !r.doc.rangeHasMark(e.from, e.to, r.schema.marks.code)).filter((t) => e.validate(t.value)).filter((t) => e.shouldAutoLink(t.value)).forEach((t) => {
|
|
2231
|
+
vt(t.from, t.to, r.doc).some((t) => t.mark.type === e.type) || o.addMark(t.from, t.to, e.type.create({ href: t.href }));
|
|
2232
|
+
});
|
|
2233
|
+
}
|
|
2234
|
+
}), o.steps.length) return o;
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
//#endregion
|
|
2239
|
+
//#region src/extensions/tiptap-extensions/Link/helpers/clickHandler.ts
|
|
2240
|
+
function Ri(e) {
|
|
2241
|
+
return new B({
|
|
2242
|
+
key: new V("handleClickLink"),
|
|
2243
|
+
props: { handleClick: (t, n, r) => {
|
|
2244
|
+
if (r.button !== 0 || !t.editable) return !1;
|
|
2245
|
+
let i = null;
|
|
2246
|
+
if (r.target instanceof HTMLAnchorElement && r.target.getAttribute("data-inline-content-type") === "link") i = r.target;
|
|
2247
|
+
else {
|
|
2248
|
+
let t = r.target;
|
|
2249
|
+
if (!t) return !1;
|
|
2250
|
+
let n = e.tiptapEditor.view.dom;
|
|
2251
|
+
i = t.closest("a[data-inline-content-type=\"link\"]"), i && !n.contains(i) && (i = null);
|
|
2252
|
+
}
|
|
2253
|
+
if (!i) return !1;
|
|
2254
|
+
if (e.onClick) {
|
|
2255
|
+
if (!e.editor) throw Error("BlockNoteEditor not found in Link click handler");
|
|
2256
|
+
return e.onClick(r, e.editor) ?? !0;
|
|
2257
|
+
}
|
|
2258
|
+
let a = gt(t.state, e.type.name), o = i.href ?? a.href, s = i.target ?? a.target;
|
|
2259
|
+
return o ? (window.open(o, s), !0) : !1;
|
|
2260
|
+
} }
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
//#endregion
|
|
2264
|
+
//#region src/extensions/tiptap-extensions/Link/helpers/pasteHandler.ts
|
|
2265
|
+
function zi(e) {
|
|
2266
|
+
return new B({
|
|
2267
|
+
key: new V("handlePasteLink"),
|
|
2268
|
+
props: { handlePaste: (t, n, r) => {
|
|
2269
|
+
let { shouldAutoLink: i, isValidLink: a } = e, { state: o } = t, { selection: s } = o, { empty: c } = s;
|
|
2270
|
+
if (c) return !1;
|
|
2271
|
+
let l = "";
|
|
2272
|
+
r.content.forEach((e) => {
|
|
2273
|
+
l += e.textContent;
|
|
2274
|
+
});
|
|
2275
|
+
let u = Me(l, { defaultProtocol: e.defaultProtocol }).find((e) => e.isLink && e.value === l);
|
|
2276
|
+
return !l || !u || !a(u.value) || i !== void 0 && !i(u.value) ? !1 : e.editor.commands.setMark(e.type, { href: u.href });
|
|
2277
|
+
} }
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
//#endregion
|
|
2281
|
+
//#region src/extensions/tiptap-extensions/Link/link.ts
|
|
2282
|
+
var Bi = "https", Vi = /^(?:(?:http|https|ftp|ftps|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z0-9+.\-]+(?:[^a-z+.\-:]|$))/i;
|
|
2283
|
+
function Hi(e) {
|
|
2284
|
+
if (!e) return !0;
|
|
2285
|
+
let t = e.replace(Fi, "");
|
|
2286
|
+
return Vi.test(t);
|
|
2287
|
+
}
|
|
2288
|
+
function Ui(e) {
|
|
2289
|
+
let t = /^[a-z][a-z0-9+.-]*:\/\//i.test(e), n = /^[a-z][a-z0-9+.-]*:/i.test(e);
|
|
2290
|
+
if (t || n && !e.includes("@")) return !0;
|
|
2291
|
+
let r = (e.includes("@") ? e.split("@").pop() : e).split(/[/?#:]/)[0];
|
|
2292
|
+
return !(/^\d{1,3}(\.\d{1,3}){3}$/.test(r) || !/\./.test(r));
|
|
2293
|
+
}
|
|
2294
|
+
var Wi = ft.create({
|
|
2295
|
+
name: "link",
|
|
2296
|
+
keepOnSplit: !1,
|
|
2297
|
+
exitable: !0,
|
|
2298
|
+
inclusive: !1,
|
|
2299
|
+
addOptions() {
|
|
2300
|
+
return {
|
|
2301
|
+
HTMLAttributes: {
|
|
2302
|
+
target: "_blank",
|
|
2303
|
+
rel: "noopener noreferrer nofollow",
|
|
2304
|
+
className: "bn-inline-content-section",
|
|
2305
|
+
"data-inline-content-type": "link"
|
|
2306
|
+
},
|
|
2307
|
+
editor: void 0,
|
|
2308
|
+
onClick: void 0,
|
|
2309
|
+
isValidLink: Hi
|
|
2310
|
+
};
|
|
2311
|
+
},
|
|
2312
|
+
addAttributes() {
|
|
2313
|
+
return { href: {
|
|
2314
|
+
default: null,
|
|
2315
|
+
parseHTML(e) {
|
|
2316
|
+
return e.getAttribute("href");
|
|
2317
|
+
}
|
|
2318
|
+
} };
|
|
2319
|
+
},
|
|
2320
|
+
parseHTML() {
|
|
2321
|
+
let e = this.options.isValidLink;
|
|
2322
|
+
return [{
|
|
2323
|
+
tag: "a[href]",
|
|
2324
|
+
getAttrs: (t) => {
|
|
2325
|
+
let n = t.getAttribute("href");
|
|
2326
|
+
return !n || !e(n) ? !1 : null;
|
|
2327
|
+
}
|
|
2328
|
+
}];
|
|
2329
|
+
},
|
|
2330
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
2331
|
+
return this.options.isValidLink(e.href) ? [
|
|
2332
|
+
"a",
|
|
2333
|
+
St(e, this.options.HTMLAttributes),
|
|
2334
|
+
0
|
|
2335
|
+
] : [
|
|
2336
|
+
"a",
|
|
2337
|
+
St({
|
|
2338
|
+
...e,
|
|
2339
|
+
href: ""
|
|
2340
|
+
}, this.options.HTMLAttributes),
|
|
2341
|
+
0
|
|
2342
|
+
];
|
|
2343
|
+
},
|
|
2344
|
+
addPasteRules() {
|
|
2345
|
+
let e = this.options.isValidLink;
|
|
2346
|
+
return [xt({
|
|
2347
|
+
find: (t) => {
|
|
2348
|
+
let n = [];
|
|
2349
|
+
if (t) {
|
|
2350
|
+
let r = Me(t, { defaultProtocol: Bi }).filter((t) => t.isLink && e(t.value));
|
|
2351
|
+
for (let e of r) Ui(e.value) && n.push({
|
|
2352
|
+
text: e.value,
|
|
2353
|
+
data: { href: e.href },
|
|
2354
|
+
index: e.start
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
return n;
|
|
2358
|
+
},
|
|
2359
|
+
type: this.type,
|
|
2360
|
+
getAttributes: (e) => ({ href: e.data?.href })
|
|
2361
|
+
})];
|
|
2362
|
+
},
|
|
2363
|
+
addProseMirrorPlugins() {
|
|
2364
|
+
let e = [];
|
|
2365
|
+
return e.push(Li({
|
|
2366
|
+
type: this.type,
|
|
2367
|
+
defaultProtocol: Bi,
|
|
2368
|
+
validate: this.options.isValidLink,
|
|
2369
|
+
shouldAutoLink: Ui
|
|
2370
|
+
})), e.push(Ri({
|
|
2371
|
+
type: this.type,
|
|
2372
|
+
tiptapEditor: this.editor,
|
|
2373
|
+
editor: this.options.editor,
|
|
2374
|
+
onClick: this.options.onClick
|
|
2375
|
+
})), e.push(zi({
|
|
2376
|
+
editor: this.editor,
|
|
2377
|
+
defaultProtocol: Bi,
|
|
2378
|
+
type: this.type,
|
|
2379
|
+
shouldAutoLink: Ui,
|
|
2380
|
+
isValidLink: this.options.isValidLink
|
|
2381
|
+
})), e;
|
|
2382
|
+
}
|
|
2383
|
+
}), Gi = je(({ editor: e, options: t }) => ({
|
|
2384
|
+
key: "link",
|
|
2385
|
+
tiptapExtensions: [Wi.configure({
|
|
2386
|
+
HTMLAttributes: t.HTMLAttributes ?? {},
|
|
2387
|
+
editor: e,
|
|
2388
|
+
onClick: t.onClick,
|
|
2389
|
+
...t.isValidLink ? { isValidLink: t.isValidLink } : {}
|
|
2390
|
+
})]
|
|
2391
|
+
})), Ki = L.create({
|
|
2392
|
+
name: "blockGroup",
|
|
2393
|
+
group: f,
|
|
2394
|
+
content: "blockGroupChild+",
|
|
2395
|
+
marks() {
|
|
2396
|
+
return s(this.editor);
|
|
2397
|
+
},
|
|
2398
|
+
parseHTML() {
|
|
2399
|
+
return [{
|
|
2400
|
+
tag: "div",
|
|
2401
|
+
getAttrs: (e) => typeof e != "string" && e.getAttribute("data-node-type") === "blockGroup" && null
|
|
2402
|
+
}];
|
|
2403
|
+
},
|
|
2404
|
+
renderHTML({ HTMLAttributes: e }) {
|
|
2405
|
+
let t = {
|
|
2406
|
+
...this.options.domAttributes?.blockGroup || {},
|
|
2407
|
+
...e
|
|
2408
|
+
}, n = document.createElement("div");
|
|
2409
|
+
n.className = de("bn-block-group", t.class), n.setAttribute("data-node-type", "blockGroup");
|
|
2410
|
+
for (let [e, r] of Object.entries(t)) e !== "class" && n.setAttribute(e, r);
|
|
2411
|
+
return {
|
|
2412
|
+
dom: n,
|
|
2413
|
+
contentDOM: n
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
}), qi = L.create({
|
|
2417
|
+
name: "doc",
|
|
2418
|
+
topNode: !0,
|
|
2419
|
+
content: "blockGroup",
|
|
2420
|
+
marks() {
|
|
2421
|
+
return s(this.editor);
|
|
2422
|
+
}
|
|
2423
|
+
});
|
|
2424
|
+
//#endregion
|
|
2425
|
+
//#region src/editor/managers/ExtensionManager/extensions.ts
|
|
2426
|
+
function Ji(e, t) {
|
|
2427
|
+
return [
|
|
2428
|
+
R.ClipboardTextSerializer,
|
|
2429
|
+
R.Commands,
|
|
2430
|
+
R.Editable,
|
|
2431
|
+
R.FocusEvents,
|
|
2432
|
+
R.Tabindex,
|
|
2433
|
+
jt,
|
|
2434
|
+
ue.configure({
|
|
2435
|
+
types: ["blockContainer", ...Object.values(e.schema.blockSpecs).filter((e) => e.config.layoutOnly === !0).map((e) => e.config.type)],
|
|
2436
|
+
setIdAttribute: t.setIdAttribute,
|
|
2437
|
+
isWithinEditor: e.isWithinEditor
|
|
2438
|
+
}),
|
|
2439
|
+
xi,
|
|
2440
|
+
At,
|
|
2441
|
+
...Object.values(e.schema.styleSpecs).map((t) => t.implementation.mark.configure({ editor: e })),
|
|
2442
|
+
ji,
|
|
2443
|
+
bi,
|
|
2444
|
+
Ai,
|
|
2445
|
+
I.create({
|
|
2446
|
+
name: "OverrideEscape",
|
|
2447
|
+
addKeyboardShortcuts: () => ({ Escape: () => !e.getExtension(fe)?.shown() && (e.blur(), !0) })
|
|
2448
|
+
}),
|
|
2449
|
+
qi,
|
|
2450
|
+
Zt.configure({
|
|
2451
|
+
editor: e,
|
|
2452
|
+
domAttributes: t.domAttributes
|
|
2453
|
+
}),
|
|
2454
|
+
ki.configure({
|
|
2455
|
+
editor: e,
|
|
2456
|
+
tabBehavior: t.tabBehavior,
|
|
2457
|
+
selectAllBehavior: t.selectAllBehavior ?? "block-first"
|
|
2458
|
+
}),
|
|
2459
|
+
Ki.configure({ domAttributes: t.domAttributes }),
|
|
2460
|
+
...Object.values(e.schema.inlineContentSpecs).filter((e) => e.config !== "link" && e.config !== "text").map((t) => t.implementation.node.configure({ editor: e })),
|
|
2461
|
+
...Object.values(e.schema.blockSpecs).flatMap((n) => [..."node" in n.implementation ? [n.implementation.node.configure({
|
|
2462
|
+
editor: e,
|
|
2463
|
+
domAttributes: t.domAttributes
|
|
2464
|
+
})] : []]),
|
|
2465
|
+
yi(e),
|
|
2466
|
+
hi(e, t.pasteHandler || ((e) => e.defaultPasteHandler())),
|
|
2467
|
+
Qr(e)
|
|
2468
|
+
];
|
|
2469
|
+
}
|
|
2470
|
+
function Yi(e, t) {
|
|
2471
|
+
let n = [
|
|
2472
|
+
Ve(),
|
|
2473
|
+
Fe(t),
|
|
2474
|
+
Oe(t),
|
|
2475
|
+
be(t),
|
|
2476
|
+
Gi({
|
|
2477
|
+
HTMLAttributes: t.links?.HTMLAttributes ?? {},
|
|
2478
|
+
onClick: t.links?.onClick,
|
|
2479
|
+
...t.links?.isValidLink ? { isValidLink: t.links.isValidLink } : {}
|
|
2480
|
+
}),
|
|
2481
|
+
Le(t),
|
|
2482
|
+
Je(),
|
|
2483
|
+
ze(t),
|
|
2484
|
+
Ue({ editable: t._tiptapOptions?.editable }),
|
|
2485
|
+
tt(t),
|
|
2486
|
+
Ze(t),
|
|
2487
|
+
Ge(),
|
|
2488
|
+
qe(),
|
|
2489
|
+
fe(t),
|
|
2490
|
+
Be(),
|
|
2491
|
+
Re(),
|
|
2492
|
+
Ne(),
|
|
2493
|
+
...t.trailingBlock === !1 ? [] : [Ye()]
|
|
2494
|
+
];
|
|
2495
|
+
return "table" in e.schema.blockSpecs && n.push(Xe(t)), t.animations !== !1 && n.push(Pe()), n;
|
|
2496
|
+
}
|
|
2497
|
+
//#endregion
|
|
2498
|
+
//#region src/editor/managers/ExtensionManager/index.ts
|
|
2499
|
+
var Xi = class {
|
|
2500
|
+
editor;
|
|
2501
|
+
options;
|
|
2502
|
+
disabledExtensions = /* @__PURE__ */ new Set();
|
|
2503
|
+
extensions = [];
|
|
2504
|
+
abortMap = /* @__PURE__ */ new Map();
|
|
2505
|
+
extensionFactories = /* @__PURE__ */ new Map();
|
|
2506
|
+
extensionPlugins = /* @__PURE__ */ new Map();
|
|
2507
|
+
runtimeExtensions = /* @__PURE__ */ new Set();
|
|
2508
|
+
blockNoteExtensionDependents = /* @__PURE__ */ new Map();
|
|
2509
|
+
constructor(e, t) {
|
|
2510
|
+
this.editor = e, this.options = t, e.onMount(() => {
|
|
2511
|
+
for (let e of this.extensions) this.mountExtension(e);
|
|
2512
|
+
}), e.onUnmount(() => {
|
|
2513
|
+
for (let [e, t] of this.abortMap.entries()) this.abortMap.delete(e), t.abort();
|
|
2514
|
+
}), this.disabledExtensions = new Set(t.disableExtensions || []);
|
|
2515
|
+
for (let e of Yi(this.editor, this.options)) this.addExtension(e);
|
|
2516
|
+
for (let e of this.options.extensions ?? []) this.addExtension(e);
|
|
2517
|
+
for (let e of Object.values(this.editor.schema.blockSpecs)) for (let t of e.extensions ?? []) this.addExtension(t);
|
|
2518
|
+
}
|
|
2519
|
+
mountExtension(e) {
|
|
2520
|
+
if (!e.mount || this.abortMap.has(e)) return;
|
|
2521
|
+
let t = new window.AbortController();
|
|
2522
|
+
this.abortMap.set(e, t);
|
|
2523
|
+
let n = e.mount({
|
|
2524
|
+
dom: this.editor.prosemirrorView.dom,
|
|
2525
|
+
root: this.editor.prosemirrorView.root,
|
|
2526
|
+
signal: t.signal
|
|
2527
|
+
});
|
|
2528
|
+
n && (t.signal.aborted ? n() : t.signal.addEventListener("abort", n, { once: !0 }));
|
|
2529
|
+
}
|
|
2530
|
+
registerExtension(e) {
|
|
2531
|
+
this.replaceExtension(void 0, e);
|
|
2532
|
+
}
|
|
2533
|
+
addExtension(e, t) {
|
|
2534
|
+
let n;
|
|
2535
|
+
if (n = typeof e == "function" ? e({ editor: this.editor }) : e, !n || this.disabledExtensions.has(n.key)) return;
|
|
2536
|
+
if (t) {
|
|
2537
|
+
let e = this.blockNoteExtensionDependents.get(n.key);
|
|
2538
|
+
e || (e = /* @__PURE__ */ new Set(), this.blockNoteExtensionDependents.set(n.key, e)), e.add(t);
|
|
2539
|
+
}
|
|
2540
|
+
if (this.extensions.some((e) => e.key === n.key)) return;
|
|
2541
|
+
let r = n[ke];
|
|
2542
|
+
if (typeof r == "function" && this.extensionFactories.set(r, n), this.extensions.push(n), n.blockNoteExtensions) for (let e of n.blockNoteExtensions) this.addExtension(e, n.key);
|
|
2543
|
+
return n;
|
|
2544
|
+
}
|
|
2545
|
+
resolveExtensions(e) {
|
|
2546
|
+
let t = [];
|
|
2547
|
+
if (typeof e == "function") {
|
|
2548
|
+
let n = this.extensionFactories.get(e);
|
|
2549
|
+
n && t.push(n);
|
|
2550
|
+
} else if (Array.isArray(e)) for (let n of e) t.push(...this.resolveExtensions(n));
|
|
2551
|
+
else if (typeof e == "object" && "key" in e) t.push(e);
|
|
2552
|
+
else if (typeof e == "string") {
|
|
2553
|
+
let n = this.extensions.find((t) => t.key === e);
|
|
2554
|
+
n && t.push(n);
|
|
2555
|
+
}
|
|
2556
|
+
return t;
|
|
2557
|
+
}
|
|
2558
|
+
unregisterExtension(e) {
|
|
2559
|
+
let t = [...new Set(this.resolveExtensions(e))].filter((e) => this.extensions.includes(e));
|
|
2560
|
+
return t.length && this.replaceExtension(t, []), Array.isArray(e) ? t : t[0];
|
|
2561
|
+
}
|
|
2562
|
+
replaceExtension(e, t, n) {
|
|
2563
|
+
let r = this.resolveExtensions(e);
|
|
2564
|
+
e && !r.length && console.warn("No extensions found to unregister", e);
|
|
2565
|
+
let i = !1, a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
|
|
2566
|
+
for (let t of r) this.extensions = this.extensions.filter((e) => e !== t), this.extensionFactories.forEach((e, n) => {
|
|
2567
|
+
e === t && this.extensionFactories.delete(n);
|
|
2568
|
+
}), this.abortMap.get(t)?.abort(), this.abortMap.delete(t), this.extensionPlugins.get(t)?.forEach((e) => {
|
|
2569
|
+
a.add(e);
|
|
2570
|
+
let t = e.spec?.key, n = typeof t == "object" && t ? t.key : t;
|
|
2571
|
+
typeof n == "string" && o.add(n);
|
|
2572
|
+
}), this.extensionPlugins.delete(t), this.runtimeExtensions.delete(t), t.tiptapExtensions && !i && (i = !0, console.warn(`Extension ${t.key} has tiptap extensions, but they will not be removed. Please separate the extension into multiple extensions if you want to remove them, or re-initialize the editor.`, e));
|
|
2573
|
+
let s = [].concat(t).filter(Boolean).map((e) => this.addExtension(e)).filter(Boolean), c = [];
|
|
2574
|
+
for (let e of s) this.runtimeExtensions.add(e), e?.tiptapExtensions && console.warn(`Extension ${e.key} has tiptap extensions, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`, e), e?.inputRules?.length && console.warn(`Extension ${e.key} has input rules, but these cannot be changed after initializing the editor. Please separate the extension into multiple extensions if you want to add them, or re-initialize the editor.`, e), this.getProsemirrorPluginsFromExtension(e).plugins.forEach((e) => {
|
|
2575
|
+
c.push(e);
|
|
2576
|
+
});
|
|
2577
|
+
if ((a.size || o.size || c.length || n?.resetPluginStateFor.length) && this.updatePlugins((e) => [...e.filter((e) => {
|
|
2578
|
+
if (a.has(e)) return !1;
|
|
2579
|
+
if (o.size) {
|
|
2580
|
+
let t = e.spec?.key, n = typeof t == "object" && t ? t.key : t;
|
|
2581
|
+
if (typeof n == "string" && o.has(n)) return !1;
|
|
2582
|
+
}
|
|
2583
|
+
return !0;
|
|
2584
|
+
}), ...c], n?.resetPluginStateFor), !this.editor.headless) for (let e of s) this.mountExtension(e);
|
|
2585
|
+
}
|
|
2586
|
+
updatePlugins(e, t) {
|
|
2587
|
+
let n = this.editor.prosemirrorState, r = new Set(t), i = (r.size ? n.reconfigure({ plugins: n.plugins.filter((e) => !e.spec.key || !r.has(e.spec.key)) }) : n).reconfigure({ plugins: e(n.plugins.slice()) });
|
|
2588
|
+
this.editor.prosemirrorView.updateState(i);
|
|
2589
|
+
}
|
|
2590
|
+
getTiptapExtensions() {
|
|
2591
|
+
let e = Ji(this.editor, this.options).filter((e) => !this.disabledExtensions.has(e.name)), t = l(this.extensions.map((e) => {
|
|
2592
|
+
let t = this.blockNoteExtensionDependents.get(e.key);
|
|
2593
|
+
return t?.size ? {
|
|
2594
|
+
key: e.key,
|
|
2595
|
+
runsBefore: [...e.runsBefore ?? [], ...t]
|
|
2596
|
+
} : e;
|
|
2597
|
+
})), n = /* @__PURE__ */ new Map();
|
|
2598
|
+
for (let r of this.extensions) {
|
|
2599
|
+
r.tiptapExtensions && e.push(...r.tiptapExtensions);
|
|
2600
|
+
let i = t(r.key), { plugins: a, inputRules: o } = this.getProsemirrorPluginsFromExtension(r);
|
|
2601
|
+
a.length && e.push(I.create({
|
|
2602
|
+
name: r.key,
|
|
2603
|
+
priority: i,
|
|
2604
|
+
addProseMirrorPlugins: () => this.runtimeExtensions.has(r) ? [] : this.extensionPlugins.get(r) ?? []
|
|
2605
|
+
})), o.length && (n.has(i) || n.set(i, []), n.get(i).push(...o));
|
|
2606
|
+
}
|
|
2607
|
+
e.push(I.create({
|
|
2608
|
+
name: "blocknote-runtime-extensions",
|
|
2609
|
+
priority: -Infinity,
|
|
2610
|
+
addProseMirrorPlugins: () => this.extensions.filter((e) => this.runtimeExtensions.has(e)).flatMap((e) => this.extensionPlugins.get(e) ?? [])
|
|
2611
|
+
})), e.push(I.create({
|
|
2612
|
+
name: "blocknote-input-rules",
|
|
2613
|
+
addProseMirrorPlugins() {
|
|
2614
|
+
let e = [];
|
|
2615
|
+
Array.from(n.keys()).sort((e, t) => e - t).reverse().forEach((t) => {
|
|
2616
|
+
e.push(...n.get(t));
|
|
2617
|
+
});
|
|
2618
|
+
let t = Ot({ rules: e });
|
|
2619
|
+
return [t, new j({ props: { handleKeyDown(e, n) {
|
|
2620
|
+
if (n.key !== "Enter" || n.shiftKey || n.ctrlKey || n.metaKey || n.altKey) return !1;
|
|
2621
|
+
let { $cursor: r } = e.state.selection;
|
|
2622
|
+
return r ? !!t.props.handleTextInput?.call(t, e, r.pos, r.pos, "\n", () => e.state.tr.insertText("\n", r.pos, r.pos)) : !1;
|
|
2623
|
+
} } })];
|
|
2624
|
+
}
|
|
2625
|
+
}));
|
|
2626
|
+
for (let t of this.options._tiptapOptions?.extensions ?? []) e.push(t);
|
|
2627
|
+
return e;
|
|
2628
|
+
}
|
|
2629
|
+
getProsemirrorPluginsFromExtension(e) {
|
|
2630
|
+
let t = [...e.prosemirrorPlugins ?? []], n = [];
|
|
2631
|
+
if (!e.prosemirrorPlugins?.length && !Object.keys(e.keyboardShortcuts || {}).length && !e.inputRules?.length) return {
|
|
2632
|
+
plugins: t,
|
|
2633
|
+
inputRules: n
|
|
2634
|
+
};
|
|
2635
|
+
if (this.extensionPlugins.set(e, t), e.inputRules?.length && n.push(...e.inputRules.map((e) => new Dt(e.find, (t, n, i, a) => {
|
|
2636
|
+
let o = e.replace({
|
|
2637
|
+
match: n,
|
|
2638
|
+
range: {
|
|
2639
|
+
from: i,
|
|
2640
|
+
to: a
|
|
2641
|
+
},
|
|
2642
|
+
editor: this.editor
|
|
2643
|
+
});
|
|
2644
|
+
if (o) {
|
|
2645
|
+
let e = t.tr, n = b(e);
|
|
2646
|
+
return !n.hasContent || this.editor.schema.blockSchema[n.blockNoteType]?.content !== "inline" ? null : (e.deleteRange(i, a), K(e, n.block.beforePos, o), Kr(e, r(n.block.node, e.doc), "start"), e);
|
|
2647
|
+
}
|
|
2648
|
+
return null;
|
|
2649
|
+
}, { undoable: !0 }))), Object.keys(e.keyboardShortcuts || {}).length) {
|
|
2650
|
+
let n, r = kt(Object.fromEntries(Object.entries(e.keyboardShortcuts).map(([e, t]) => [e, () => {
|
|
2651
|
+
if (!n) throw Error("Keyboard shortcut called outside handleKeyDown");
|
|
2652
|
+
return t({
|
|
2653
|
+
editor: this.editor,
|
|
2654
|
+
event: n
|
|
2655
|
+
});
|
|
2656
|
+
}])));
|
|
2657
|
+
t.push(new j({ props: { handleKeyDown: (e, t) => {
|
|
2658
|
+
let i = n;
|
|
2659
|
+
n = t;
|
|
2660
|
+
try {
|
|
2661
|
+
return r(e, t);
|
|
2662
|
+
} finally {
|
|
2663
|
+
n = i;
|
|
2664
|
+
}
|
|
2665
|
+
} } }));
|
|
2666
|
+
}
|
|
2667
|
+
return {
|
|
2668
|
+
plugins: t,
|
|
2669
|
+
inputRules: n
|
|
2670
|
+
};
|
|
2671
|
+
}
|
|
2672
|
+
getExtensions() {
|
|
2673
|
+
return new Map(this.extensions.map((e) => [e.key, e]));
|
|
2674
|
+
}
|
|
2675
|
+
getExtension(e) {
|
|
2676
|
+
if (typeof e == "string") return this.extensions.find((t) => t.key === e) || void 0;
|
|
2677
|
+
if (typeof e == "function") return this.extensionFactories.get(e) || void 0;
|
|
2678
|
+
throw Error(`Invalid extension type: ${typeof e}`);
|
|
2679
|
+
}
|
|
2680
|
+
hasExtension(e) {
|
|
2681
|
+
return typeof e == "string" ? this.extensions.some((t) => t.key === e) : typeof e == "object" && "key" in e ? this.extensions.some((t) => t.key === e.key) : typeof e == "function" && this.extensionFactories.has(e);
|
|
2682
|
+
}
|
|
2683
|
+
};
|
|
2684
|
+
//#endregion
|
|
2685
|
+
//#region src/util/expandToWords.ts
|
|
2686
|
+
function Zi(e, t) {
|
|
2687
|
+
let { $from: n, $to: r } = t;
|
|
2688
|
+
if (n.pos > n.start() && n.pos < e.content.size) {
|
|
2689
|
+
let t = e.textBetween(n.pos, n.pos + 1);
|
|
2690
|
+
if (/^[\w\p{P}]$/u.test(t)) {
|
|
2691
|
+
let t = e.textBetween(n.start(), n.pos).match(/[\w\p{P}]+$/u);
|
|
2692
|
+
t && (n = e.resolve(n.pos - t[0].length));
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
if (r.pos < r.end() && r.pos > 0) {
|
|
2696
|
+
let t = e.textBetween(r.pos - 1, r.pos);
|
|
2697
|
+
if (/^[\w\p{P}]$/u.test(t)) {
|
|
2698
|
+
let t = e.textBetween(r.pos, r.end()).match(/^[\w\p{P}]+/u);
|
|
2699
|
+
t && (r = e.resolve(r.pos + t[0].length));
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
return {
|
|
2703
|
+
$from: n,
|
|
2704
|
+
$to: r,
|
|
2705
|
+
from: n.pos,
|
|
2706
|
+
to: r.pos
|
|
2707
|
+
};
|
|
2708
|
+
}
|
|
2709
|
+
//#endregion
|
|
2710
|
+
//#region src/api/blockManipulation/selections/selection.ts
|
|
2711
|
+
function Qi(e) {
|
|
2712
|
+
if (e.selection.empty || "node" in e.selection) return;
|
|
2713
|
+
let t = e.doc.resolve(y(e.doc, e.selection.from).posBeforeNode), r = e.doc.resolve(y(e.doc, e.selection.to).posBeforeNode), i = (r, i) => {
|
|
2714
|
+
let a = t.posAtIndex(r, i), o = e.doc.resolve(a).nodeAfter;
|
|
2715
|
+
if (!o) throw Error(`Error getting selection - node not found at position ${a}`);
|
|
2716
|
+
return n(o, e.doc);
|
|
2717
|
+
}, a = [], o = t.sharedDepth(r.pos), s = t.index(o), c = r.index(o);
|
|
2718
|
+
if (t.depth > o) {
|
|
2719
|
+
a.push(n(t.nodeAfter, e.doc));
|
|
2720
|
+
for (let e = t.depth; e > o; e--) if (t.node(e).type.isInGroup("childContainer")) {
|
|
2721
|
+
let n = t.index(e) + 1, r = t.node(e).childCount;
|
|
2722
|
+
for (let t = n; t < r; t++) a.push(i(t, e));
|
|
2723
|
+
}
|
|
2724
|
+
} else a.push(i(s, o));
|
|
2725
|
+
for (let e = s + 1; e <= c; e++) a.push(i(e, o));
|
|
2726
|
+
if (a.length === 0) throw Error(`Error getting selection - selection doesn't span any blocks (${e.selection})`);
|
|
2727
|
+
return { blocks: a };
|
|
2728
|
+
}
|
|
2729
|
+
function $i(e, t, n) {
|
|
2730
|
+
let r = typeof t == "string" ? t : t.id, i = typeof n == "string" ? n : n.id;
|
|
2731
|
+
if (r === i) throw Error(`Attempting to set selection with the same anchor and head blocks (id ${r})`);
|
|
2732
|
+
let a = D(r, e.doc);
|
|
2733
|
+
if (!a) throw Error(`Block with ID ${r} not found`);
|
|
2734
|
+
let o = D(i, e.doc);
|
|
2735
|
+
if (!o) throw Error(`Block with ID ${i} not found`);
|
|
2736
|
+
let s = E(a.node, a.posBeforeNode), c = E(o.node, o.posBeforeNode), l = ve(s, "start");
|
|
2737
|
+
if (l === null) throw Error(`Attempting to set selection anchor in block without content (id ${r})`);
|
|
2738
|
+
let u = ve(c, "end");
|
|
2739
|
+
if (u === null) throw Error(`Attempting to set selection head in block without content (id ${i})`);
|
|
2740
|
+
e.setSelection(N.create(e.doc, l, u));
|
|
2741
|
+
}
|
|
2742
|
+
function ea(e, t = !1) {
|
|
2743
|
+
let n = t ? Zi(e.doc, e.selection) : e.selection, r = n.$from, i = n.$to;
|
|
2744
|
+
for (; i.parentOffset >= i.parent.nodeSize - 2 && i.depth > 0;) i = e.doc.resolve(i.pos + 1);
|
|
2745
|
+
for (; i.parentOffset === 0 && i.depth > 0;) i = e.doc.resolve(i.pos - 1);
|
|
2746
|
+
for (; r.parentOffset === 0 && r.depth > 0;) r = e.doc.resolve(r.pos - 1);
|
|
2747
|
+
for (; r.parentOffset >= r.parent.nodeSize - 2 && r.depth > 0;) r = e.doc.resolve(r.pos + 1);
|
|
2748
|
+
let a = ye(e.doc.slice(r.pos, i.pos, !0));
|
|
2749
|
+
return {
|
|
2750
|
+
_meta: {
|
|
2751
|
+
startPos: r.pos,
|
|
2752
|
+
endPos: i.pos
|
|
2753
|
+
},
|
|
2754
|
+
...a
|
|
2755
|
+
};
|
|
2756
|
+
}
|
|
2757
|
+
//#endregion
|
|
2758
|
+
//#region src/editor/managers/SelectionManager.ts
|
|
2759
|
+
var ta = class {
|
|
2760
|
+
editor;
|
|
2761
|
+
constructor(e) {
|
|
2762
|
+
this.editor = e;
|
|
2763
|
+
}
|
|
2764
|
+
getSelection() {
|
|
2765
|
+
return this.editor.transact((e) => Qi(e));
|
|
2766
|
+
}
|
|
2767
|
+
getSelectionCutBlocks(e = !1) {
|
|
2768
|
+
return this.editor.transact((t) => ea(t, e));
|
|
2769
|
+
}
|
|
2770
|
+
setSelection(e, t) {
|
|
2771
|
+
return this.editor.transact((n) => $i(n, e, t));
|
|
2772
|
+
}
|
|
2773
|
+
getTextCursorPosition() {
|
|
2774
|
+
return this.editor.transact((e) => Gr(e));
|
|
2775
|
+
}
|
|
2776
|
+
setTextCursorPosition(e, t = "start") {
|
|
2777
|
+
return this.editor.transact((n) => Kr(n, e, t));
|
|
2778
|
+
}
|
|
2779
|
+
getSelectionBoundingBox() {
|
|
2780
|
+
if (!this.editor.prosemirrorView) return;
|
|
2781
|
+
let { selection: e } = this.editor.prosemirrorState, { ranges: t } = e, n = Math.min(...t.map((e) => e.$from.pos)), r = Math.max(...t.map((e) => e.$to.pos));
|
|
2782
|
+
if (bt(e)) {
|
|
2783
|
+
let e = this.editor.prosemirrorView.nodeDOM(n);
|
|
2784
|
+
if (e) return e.getBoundingClientRect();
|
|
2785
|
+
}
|
|
2786
|
+
return Ct(this.editor.prosemirrorView, n, r).toJSON();
|
|
2787
|
+
}
|
|
2788
|
+
}, na = class {
|
|
2789
|
+
editor;
|
|
2790
|
+
constructor(e) {
|
|
2791
|
+
this.editor = e;
|
|
2792
|
+
}
|
|
2793
|
+
activeTransaction = null;
|
|
2794
|
+
can(e) {
|
|
2795
|
+
try {
|
|
2796
|
+
return this.isInCan = !0, e();
|
|
2797
|
+
} finally {
|
|
2798
|
+
this.isInCan = !1;
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
isInCan = !1;
|
|
2802
|
+
exec(e) {
|
|
2803
|
+
if (this.activeTransaction) throw Error("`exec` should not be called within a `transact` call, move the `exec` call outside of the `transact` call");
|
|
2804
|
+
if (this.isInCan) return this.canExec(e);
|
|
2805
|
+
let t = this.prosemirrorState, n = this.prosemirrorView;
|
|
2806
|
+
return e(t, (e) => this.prosemirrorView.dispatch(e), n);
|
|
2807
|
+
}
|
|
2808
|
+
canExec(e) {
|
|
2809
|
+
if (this.activeTransaction) throw Error("`canExec` should not be called within a `transact` call, move the `canExec` call outside of the `transact` call");
|
|
2810
|
+
let t = this.prosemirrorState, n = this.prosemirrorView;
|
|
2811
|
+
return e(t, void 0, n);
|
|
2812
|
+
}
|
|
2813
|
+
transact(e) {
|
|
2814
|
+
if (this.activeTransaction) return e(this.activeTransaction);
|
|
2815
|
+
try {
|
|
2816
|
+
this.activeTransaction = this.editor._tiptapEditor.state.tr;
|
|
2817
|
+
let t = e(this.activeTransaction), n = this.activeTransaction;
|
|
2818
|
+
return this.activeTransaction = null, n && (n.docChanged || n.selectionSet || n.scrolledIntoView || n.storedMarksSet || !n.isGeneric) && this.prosemirrorView.dispatch(n), t;
|
|
2819
|
+
} finally {
|
|
2820
|
+
this.activeTransaction = null;
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
get prosemirrorState() {
|
|
2824
|
+
if (this.activeTransaction) throw Error("`prosemirrorState` should not be called within a `transact` call, move the `prosemirrorState` call outside of the `transact` call or use `editor.transact` to read the current editor state");
|
|
2825
|
+
return this.editor._tiptapEditor.state;
|
|
2826
|
+
}
|
|
2827
|
+
get prosemirrorView() {
|
|
2828
|
+
return this.editor._tiptapEditor.view;
|
|
2829
|
+
}
|
|
2830
|
+
isFocused() {
|
|
2831
|
+
return this.prosemirrorView?.hasFocus() || !1;
|
|
2832
|
+
}
|
|
2833
|
+
focus() {
|
|
2834
|
+
this.prosemirrorView?.focus();
|
|
2835
|
+
}
|
|
2836
|
+
get isEditable() {
|
|
2837
|
+
if (!this.editor._tiptapEditor) {
|
|
2838
|
+
if (!this.editor.headless) throw Error("no editor, but also not headless?");
|
|
2839
|
+
return !1;
|
|
2840
|
+
}
|
|
2841
|
+
if (this.editor.headless) {
|
|
2842
|
+
let e = this.editor.getExtension(Ue)?.store.state;
|
|
2843
|
+
if (e) return e.isEditable && e.enabledSet.size === 0;
|
|
2844
|
+
}
|
|
2845
|
+
return this.editor._tiptapEditor.isEditable === void 0 || this.editor._tiptapEditor.isEditable;
|
|
2846
|
+
}
|
|
2847
|
+
set isEditable(e) {
|
|
2848
|
+
if (!this.editor._tiptapEditor) {
|
|
2849
|
+
if (!this.editor.headless) throw Error("no editor, but also not headless?");
|
|
2850
|
+
return;
|
|
2851
|
+
}
|
|
2852
|
+
this.editor.getExtension(Ue).setEditable(e);
|
|
2853
|
+
}
|
|
2854
|
+
undo() {
|
|
2855
|
+
let e = this.editor.getExtension("yUndo");
|
|
2856
|
+
if (e) return this.exec(e.undoCommand);
|
|
2857
|
+
let t = this.editor.getExtension("history");
|
|
2858
|
+
if (t) return this.exec(t.undoCommand);
|
|
2859
|
+
throw Error("No undo plugin found");
|
|
2860
|
+
}
|
|
2861
|
+
redo() {
|
|
2862
|
+
let e = this.editor.getExtension("yUndo");
|
|
2863
|
+
if (e) return this.exec(e.redoCommand);
|
|
2864
|
+
let t = this.editor.getExtension("history");
|
|
2865
|
+
if (t) return this.exec(t.redoCommand);
|
|
2866
|
+
throw Error("No redo plugin found");
|
|
2867
|
+
}
|
|
2868
|
+
};
|
|
2869
|
+
//#endregion
|
|
2870
|
+
//#region src/api/blockManipulation/insertContentAt.ts
|
|
2871
|
+
function ra(e, t, n, r = { updateSelection: !0 }) {
|
|
2872
|
+
let { from: i, to: a } = typeof t == "number" ? {
|
|
2873
|
+
from: t,
|
|
2874
|
+
to: t
|
|
2875
|
+
} : {
|
|
2876
|
+
from: t.from,
|
|
2877
|
+
to: t.to
|
|
2878
|
+
}, o = !0, s = !0, c = "";
|
|
2879
|
+
if (n.forEach((e) => {
|
|
2880
|
+
e.check(), o && e.isText && e.marks.length === 0 ? c += e.text : o = !1, s = s ? e.isBlock : !1;
|
|
2881
|
+
}), i === a && s) {
|
|
2882
|
+
let { parent: t } = e.doc.resolve(i);
|
|
2883
|
+
t.isTextblock && !t.type.spec.code && !t.childCount && (--i, a += 1);
|
|
2884
|
+
}
|
|
2885
|
+
return o ? e.insertText(c, i, a) : e.replaceWith(i, a, n), r.updateSelection && wt(e, e.steps.length - 1, -1), !0;
|
|
2886
|
+
}
|
|
2887
|
+
//#endregion
|
|
2888
|
+
//#region src/editor/managers/StyleManager.ts
|
|
2889
|
+
var ia = class {
|
|
2890
|
+
editor;
|
|
2891
|
+
constructor(e) {
|
|
2892
|
+
this.editor = e;
|
|
2893
|
+
}
|
|
2894
|
+
insertInlineContent(e, { updateSelection: t = !1 } = {}) {
|
|
2895
|
+
let n = S(e, this.editor.pmSchema);
|
|
2896
|
+
this.editor.transact((e) => {
|
|
2897
|
+
ra(e, {
|
|
2898
|
+
from: e.selection.from,
|
|
2899
|
+
to: e.selection.to
|
|
2900
|
+
}, n, { updateSelection: t });
|
|
2901
|
+
});
|
|
2902
|
+
}
|
|
2903
|
+
getActiveStyles() {
|
|
2904
|
+
return this.editor.transact((e) => {
|
|
2905
|
+
let t = {}, n = e.selection.empty && e.storedMarks || e.selection.$to.marks();
|
|
2906
|
+
for (let e of n) {
|
|
2907
|
+
let n = this.editor.schema.styleSchema[e.type.name];
|
|
2908
|
+
if (!n) {
|
|
2909
|
+
e.type.name !== "link" && !e.type.spec.blocknoteIgnore && console.warn("mark not found in styleschema", e.type.name);
|
|
2910
|
+
continue;
|
|
2911
|
+
}
|
|
2912
|
+
n.propSchema === "boolean" ? t[n.type] = !0 : t[n.type] = e.attrs.stringValue;
|
|
2913
|
+
}
|
|
2914
|
+
return t;
|
|
2915
|
+
});
|
|
2916
|
+
}
|
|
2917
|
+
addStyles(e) {
|
|
2918
|
+
for (let [t, n] of Object.entries(e)) {
|
|
2919
|
+
let e = this.editor.schema.styleSchema[t];
|
|
2920
|
+
if (!e) throw Error(`style ${t} not found in styleSchema`);
|
|
2921
|
+
if (e.propSchema === "boolean") this.editor._tiptapEditor.commands.setMark(t);
|
|
2922
|
+
else if (e.propSchema === "string") this.editor._tiptapEditor.commands.setMark(t, { stringValue: n });
|
|
2923
|
+
else throw new C(e.propSchema);
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
removeStyles(e) {
|
|
2927
|
+
for (let t of Object.keys(e)) this.editor._tiptapEditor.commands.unsetMark(t);
|
|
2928
|
+
}
|
|
2929
|
+
toggleStyles(e) {
|
|
2930
|
+
for (let [t, n] of Object.entries(e)) {
|
|
2931
|
+
let e = this.editor.schema.styleSchema[t];
|
|
2932
|
+
if (!e) throw Error(`style ${t} not found in styleSchema`);
|
|
2933
|
+
if (e.propSchema === "boolean") this.editor._tiptapEditor.commands.toggleMark(t);
|
|
2934
|
+
else if (e.propSchema === "string") this.editor._tiptapEditor.commands.toggleMark(t, { stringValue: n });
|
|
2935
|
+
else throw new C(e.propSchema);
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
getSelectedText() {
|
|
2939
|
+
return this.editor.transact((e) => e.doc.textBetween(e.selection.from, e.selection.to));
|
|
2940
|
+
}
|
|
2941
|
+
getLinkMarkAtPos(e) {
|
|
2942
|
+
return this.editor.transact((t) => {
|
|
2943
|
+
let n = this.editor.pmSchema.marks.link, r = _t(t.doc.resolve(e), n);
|
|
2944
|
+
if (!r) return;
|
|
2945
|
+
let i = t.doc.nodeAt(r.from)?.marks.find((e) => e.type === n);
|
|
2946
|
+
if (i) return {
|
|
2947
|
+
href: i.attrs.href,
|
|
2948
|
+
from: r.from,
|
|
2949
|
+
to: r.to,
|
|
2950
|
+
text: t.doc.textBetween(r.from, r.to)
|
|
2951
|
+
};
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
getSelectedLinkUrl() {
|
|
2955
|
+
return this.editor.transact((e) => (e.doc.nodeAt(e.selection.from)?.marks.find((e) => e.type.name === "link"))?.attrs.href);
|
|
2956
|
+
}
|
|
2957
|
+
createLink(e, t) {
|
|
2958
|
+
e !== "" && this.editor.transact((n) => {
|
|
2959
|
+
let { from: r, to: i } = n.selection, a = this.editor.pmSchema.mark("link", { href: e });
|
|
2960
|
+
t ? n.insertText(t, r, i).addMark(r, r + t.length, a) : n.addMark(r, i, a);
|
|
2961
|
+
});
|
|
2962
|
+
}
|
|
2963
|
+
editLink(e, t, n = this.editor.transact((e) => e.selection.anchor)) {
|
|
2964
|
+
this.editor.transact((r) => {
|
|
2965
|
+
let { from: i, to: a } = this.getLinkMarkAtPos(n) || {
|
|
2966
|
+
from: r.selection.from,
|
|
2967
|
+
to: r.selection.to
|
|
2968
|
+
}, o = this.editor.pmSchema.mark("link", { href: e });
|
|
2969
|
+
t !== r.doc.textBetween(i, a) && r.insertText(t, i, a), r.addMark(i, i + t.length, o);
|
|
2970
|
+
}), this.editor.prosemirrorView.focus();
|
|
2971
|
+
}
|
|
2972
|
+
deleteLink(e = this.editor.transact((e) => e.selection.anchor)) {
|
|
2973
|
+
this.editor.transact((t) => {
|
|
2974
|
+
let { from: n, to: r } = this.getLinkMarkAtPos(e) || {
|
|
2975
|
+
from: t.selection.from,
|
|
2976
|
+
to: t.selection.to
|
|
2977
|
+
};
|
|
2978
|
+
t.removeMark(n, r, this.editor.pmSchema.marks.link).setMeta("preventAutolink", !0);
|
|
2979
|
+
}), this.editor.prosemirrorView.focus();
|
|
2980
|
+
}
|
|
2981
|
+
};
|
|
2982
|
+
//#endregion
|
|
2983
|
+
//#region src/editor/transformPasted.ts
|
|
2984
|
+
function aa(e) {
|
|
2985
|
+
return ht(e.state.selection.$from, (e) => e.type.name === "tableCell" || e.type.name === "tableHeader") !== void 0;
|
|
2986
|
+
}
|
|
2987
|
+
function oa(e, t) {
|
|
2988
|
+
let n = t.nodes.hardBreak, r = P.empty;
|
|
2989
|
+
return e.forEach((e) => {
|
|
2990
|
+
e.isTextblock && e.childCount > 0 ? (r = r.append(e.content), r = r.addToEnd(n.create())) : e.isText ? r = r.addToEnd(e) : e.isBlock && e.childCount > 0 && (r = r.append(oa(e.content, t)), r = r.addToEnd(n.create()));
|
|
2991
|
+
}), r.lastChild?.type === n && (r = r.cut(0, r.size - 1)), r;
|
|
2992
|
+
}
|
|
2993
|
+
function sa(e, t) {
|
|
2994
|
+
let n = [];
|
|
2995
|
+
return e.forEach((e, r, i) => {
|
|
2996
|
+
i !== t && n.push(e);
|
|
2997
|
+
}), P.from(n);
|
|
2998
|
+
}
|
|
2999
|
+
function ca(e, t) {
|
|
3000
|
+
let n = [];
|
|
3001
|
+
for (let r = 0; r < e.childCount; r++) if (e.child(r).type.name === "tableRow") {
|
|
3002
|
+
if (n.length > 0 && n[n.length - 1].type.name === "table") {
|
|
3003
|
+
let t = n[n.length - 1], i = t.copy(t.content.addToEnd(e.child(r)));
|
|
3004
|
+
n[n.length - 1] = i;
|
|
3005
|
+
} else {
|
|
3006
|
+
let i = t.nodes.table.createChecked(void 0, e.child(r));
|
|
3007
|
+
n.push(i);
|
|
3008
|
+
}
|
|
3009
|
+
} else n.push(e.child(r));
|
|
3010
|
+
return e = P.from(n), e;
|
|
3011
|
+
}
|
|
3012
|
+
function la(e, t) {
|
|
3013
|
+
let n = P.from(e.content);
|
|
3014
|
+
n = ca(n, t.state.schema);
|
|
3015
|
+
let r = ua(n, t, e);
|
|
3016
|
+
if (r) return r;
|
|
3017
|
+
let i = t.state.schema.nodes.tableParagraph;
|
|
3018
|
+
if (i && aa(t)) {
|
|
3019
|
+
let e = !1;
|
|
3020
|
+
if (n.descendants((t) => {
|
|
3021
|
+
t.type.isInGroup("tableContent") && (e = !0);
|
|
3022
|
+
}), !e && !i.validContent(n)) return new F(oa(n, t.state.schema), 0, 0);
|
|
3023
|
+
}
|
|
3024
|
+
if (!da(n, t)) return new F(n, e.openStart, e.openEnd);
|
|
3025
|
+
for (let e = 0; e < n.childCount; e++) if (n.child(e).type.spec.group === "blockContent") {
|
|
3026
|
+
let r = [n.child(e)];
|
|
3027
|
+
if (e + 1 < n.childCount && n.child(e + 1).type.name === "blockGroup") {
|
|
3028
|
+
let t = n.child(e + 1).child(0).child(0);
|
|
3029
|
+
(t.type.name === "bulletListItem" || t.type.name === "numberedListItem" || t.type.name === "checkListItem") && (r.push(n.child(e + 1)), n = sa(n, e + 1));
|
|
3030
|
+
}
|
|
3031
|
+
let i = t.state.schema.nodes.blockContainer.createChecked(void 0, r);
|
|
3032
|
+
n = n.replaceChild(e, i);
|
|
3033
|
+
}
|
|
3034
|
+
return new F(n, e.openStart, e.openEnd);
|
|
3035
|
+
}
|
|
3036
|
+
function ua(e, t, n) {
|
|
3037
|
+
if (aa(t) || t.dragging) return null;
|
|
3038
|
+
let r = b(t.state);
|
|
3039
|
+
if (!r.hasContent || r.content.node.type.name === "paragraph" || r.contentKind !== "inline" || !r.isContentEmpty) return null;
|
|
3040
|
+
let i = r.content.node, a = e.firstChild, o = a?.firstChild, s = o?.firstChild;
|
|
3041
|
+
if (a?.type.name !== "blockGroup" || o?.type.name !== "blockContainer" || s?.type.name !== "paragraph") return null;
|
|
3042
|
+
let c = i.type.create(i.attrs, s.content), l = o.copy(o.content.replaceChild(0, c)), u = a.copy(a.content.replaceChild(0, l));
|
|
3043
|
+
return new F(e.replaceChild(0, u), n.openStart, n.openEnd);
|
|
3044
|
+
}
|
|
3045
|
+
function da(e, t) {
|
|
3046
|
+
let n = e.childCount === 1, r = e.firstChild?.type.spec.content === "inline*", i = e.firstChild?.type.spec.content === "tableRow+";
|
|
3047
|
+
if (n) {
|
|
3048
|
+
if (r) return !1;
|
|
3049
|
+
if (i) {
|
|
3050
|
+
let e = b(t.state);
|
|
3051
|
+
if (e.hasContent) return e.contentKind !== "table";
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
return !0;
|
|
3055
|
+
}
|
|
3056
|
+
//#endregion
|
|
3057
|
+
//#region src/editor/BlockNoteEditor.ts
|
|
3058
|
+
var fa = {
|
|
3059
|
+
enableInputRules: !0,
|
|
3060
|
+
enablePasteRules: !0,
|
|
3061
|
+
enableCoreExtensions: !1
|
|
3062
|
+
}, pa = class e extends gn {
|
|
3063
|
+
options;
|
|
3064
|
+
pmSchema;
|
|
3065
|
+
_tiptapEditor;
|
|
3066
|
+
elementRenderer = null;
|
|
3067
|
+
blockCache = /* @__PURE__ */ new WeakMap();
|
|
3068
|
+
dictionary;
|
|
3069
|
+
schema;
|
|
3070
|
+
blockImplementations;
|
|
3071
|
+
inlineContentImplementations;
|
|
3072
|
+
styleImplementations;
|
|
3073
|
+
uploadFile;
|
|
3074
|
+
onUploadStartCallbacks = [];
|
|
3075
|
+
onUploadEndCallbacks = [];
|
|
3076
|
+
resolveFileUrl;
|
|
3077
|
+
settings;
|
|
3078
|
+
static create(t) {
|
|
3079
|
+
return new e(t ?? {});
|
|
3080
|
+
}
|
|
3081
|
+
constructor(e) {
|
|
3082
|
+
super(), this.options = e, this.dictionary = e.dictionary || nt, this.settings = { tables: {
|
|
3083
|
+
splitCells: e?.tables?.splitCells ?? !1,
|
|
3084
|
+
cellBackgroundColor: e?.tables?.cellBackgroundColor ?? !1,
|
|
3085
|
+
cellTextColor: e?.tables?.cellTextColor ?? !1,
|
|
3086
|
+
headers: e?.tables?.headers ?? !1
|
|
3087
|
+
} };
|
|
3088
|
+
let t = {
|
|
3089
|
+
defaultStyles: !0,
|
|
3090
|
+
schema: e.schema || Ce.create(),
|
|
3091
|
+
...e,
|
|
3092
|
+
placeholders: {
|
|
3093
|
+
...this.dictionary.placeholders,
|
|
3094
|
+
...e.placeholders
|
|
3095
|
+
}
|
|
3096
|
+
};
|
|
3097
|
+
if (this.schema = t.schema, this.blockImplementations = t.schema.blockSpecs, this.inlineContentImplementations = t.schema.inlineContentSpecs, this.styleImplementations = t.schema.styleSpecs, t.uploadFile) {
|
|
3098
|
+
let e = t.uploadFile;
|
|
3099
|
+
this.uploadFile = async (t, n) => {
|
|
3100
|
+
this.onUploadStartCallbacks.forEach((e) => e.apply(this, [n]));
|
|
3101
|
+
try {
|
|
3102
|
+
return await e(t, n);
|
|
3103
|
+
} finally {
|
|
3104
|
+
this.onUploadEndCallbacks.forEach((e) => e.apply(this, [n]));
|
|
3105
|
+
}
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
this.resolveFileUrl = t.resolveFileUrl, this._eventManager = new Hn(this), this._extensionManager = new Xi(this, t);
|
|
3109
|
+
let n = this._extensionManager.getTiptapExtensions(), r = {
|
|
3110
|
+
...fa,
|
|
3111
|
+
...t._tiptapOptions,
|
|
3112
|
+
editable: !0,
|
|
3113
|
+
element: null,
|
|
3114
|
+
autofocus: t.autofocus ?? !1,
|
|
3115
|
+
extensions: n,
|
|
3116
|
+
editorProps: {
|
|
3117
|
+
scrollMargin: {
|
|
3118
|
+
top: 72,
|
|
3119
|
+
bottom: 72,
|
|
3120
|
+
left: 0,
|
|
3121
|
+
right: 0
|
|
3122
|
+
},
|
|
3123
|
+
...t._tiptapOptions?.editorProps,
|
|
3124
|
+
attributes: {
|
|
3125
|
+
tabIndex: "0",
|
|
3126
|
+
...t._tiptapOptions?.editorProps?.attributes,
|
|
3127
|
+
...t.domAttributes?.editor,
|
|
3128
|
+
class: de("bn-editor", t.defaultStyles ? "bn-default-styles" : "", t.domAttributes?.editor?.class || "")
|
|
3129
|
+
},
|
|
3130
|
+
transformPasted: la
|
|
3131
|
+
}
|
|
3132
|
+
};
|
|
3133
|
+
try {
|
|
3134
|
+
let e = t.initialContent || [{
|
|
3135
|
+
type: "paragraph",
|
|
3136
|
+
id: ue.options.generateID()
|
|
3137
|
+
}];
|
|
3138
|
+
if (!Array.isArray(e) || e.length === 0) throw Error("initialContent must be a non-empty array of blocks, received: " + JSON.stringify(e));
|
|
3139
|
+
let n = yt(r.extensions);
|
|
3140
|
+
n.cached.blockNoteEditor = this;
|
|
3141
|
+
let i = e.map((e) => g(e, n, this.schema.styleSchema).toJSON()), a = pt({
|
|
3142
|
+
type: "doc",
|
|
3143
|
+
content: [{
|
|
3144
|
+
type: "blockGroup",
|
|
3145
|
+
content: i
|
|
3146
|
+
}]
|
|
3147
|
+
}, n, r.parseOptions);
|
|
3148
|
+
a.check(), this._tiptapEditor = new dt({
|
|
3149
|
+
...r,
|
|
3150
|
+
content: a.toJSON()
|
|
3151
|
+
}), this.pmSchema = this._tiptapEditor.schema;
|
|
3152
|
+
} catch (e) {
|
|
3153
|
+
throw Error("Error creating document from blocks passed as `initialContent`", { cause: e });
|
|
3154
|
+
}
|
|
3155
|
+
this.pmSchema.cached.blockNoteEditor = this, this._tiptapEditor.on("mount", () => {
|
|
3156
|
+
this.headless = !1;
|
|
3157
|
+
}), this._tiptapEditor.on("unmount", () => {
|
|
3158
|
+
this.headless = !0;
|
|
3159
|
+
}), this._tiptapEditor.on("destroy", () => {
|
|
3160
|
+
this.emit("destroy");
|
|
3161
|
+
}), this._blockManager = new Vn(this), this._exportManager = new Wr(this), this._selectionManager = new ta(this), this._stateManager = new na(this), this._styleManager = new ia(this), this.emit("create");
|
|
3162
|
+
}
|
|
3163
|
+
_blockManager;
|
|
3164
|
+
_eventManager;
|
|
3165
|
+
_exportManager;
|
|
3166
|
+
_extensionManager;
|
|
3167
|
+
_selectionManager;
|
|
3168
|
+
_stateManager;
|
|
3169
|
+
_styleManager;
|
|
3170
|
+
get extensions() {
|
|
3171
|
+
return this._extensionManager.getExtensions();
|
|
3172
|
+
}
|
|
3173
|
+
exec(e) {
|
|
3174
|
+
return this._stateManager.exec(e);
|
|
3175
|
+
}
|
|
3176
|
+
canExec(e) {
|
|
3177
|
+
return this._stateManager.canExec(e);
|
|
3178
|
+
}
|
|
3179
|
+
transact(e) {
|
|
3180
|
+
return this._stateManager.transact(e);
|
|
3181
|
+
}
|
|
3182
|
+
unregisterExtension(e) {
|
|
3183
|
+
return this._extensionManager.unregisterExtension(e);
|
|
3184
|
+
}
|
|
3185
|
+
registerExtension = (...e) => this._extensionManager.registerExtension(...e);
|
|
3186
|
+
replaceExtension = (...e) => this._extensionManager.replaceExtension(...e);
|
|
3187
|
+
getExtension = ((e) => this._extensionManager.getExtension(e));
|
|
3188
|
+
mount = (e) => {
|
|
3189
|
+
this._tiptapEditor.mount({ mount: e }), this._tiptapEditor.isEditorContentInitialized = !0;
|
|
3190
|
+
};
|
|
3191
|
+
unmount = () => {
|
|
3192
|
+
this._tiptapEditor.isEditorContentInitialized = !1, this._tiptapEditor.unmount();
|
|
3193
|
+
};
|
|
3194
|
+
get prosemirrorState() {
|
|
3195
|
+
return this._stateManager.prosemirrorState;
|
|
3196
|
+
}
|
|
3197
|
+
get prosemirrorView() {
|
|
3198
|
+
return this._stateManager.prosemirrorView;
|
|
3199
|
+
}
|
|
3200
|
+
get domElement() {
|
|
3201
|
+
if (!this.headless) return this.prosemirrorView?.dom;
|
|
3202
|
+
}
|
|
3203
|
+
_portalElements = /* @__PURE__ */ new Map();
|
|
3204
|
+
registerPortalElement = (e) => {
|
|
3205
|
+
this._portalElements.set(e, (this._portalElements.get(e) ?? 0) + 1);
|
|
3206
|
+
};
|
|
3207
|
+
unregisterPortalElement = (e) => {
|
|
3208
|
+
let t = this._portalElements.get(e);
|
|
3209
|
+
t !== void 0 && (t <= 1 ? this._portalElements.delete(e) : this._portalElements.set(e, t - 1));
|
|
3210
|
+
};
|
|
3211
|
+
isWithinEditor = (e) => {
|
|
3212
|
+
if (this.domElement?.parentElement?.contains(e)) return !0;
|
|
3213
|
+
for (let t of this._portalElements.keys()) if (t.contains(e)) return !0;
|
|
3214
|
+
return !1;
|
|
3215
|
+
};
|
|
3216
|
+
isFocused(e) {
|
|
3217
|
+
if (this.headless) return !1;
|
|
3218
|
+
let t = this.prosemirrorView?.hasFocus() || !1;
|
|
3219
|
+
if (!e?.includeEditorUI) return t;
|
|
3220
|
+
let n = typeof document < "u" ? document.activeElement : null;
|
|
3221
|
+
return t || !!n && this.isWithinEditor(n);
|
|
3222
|
+
}
|
|
3223
|
+
headless = !0;
|
|
3224
|
+
focus() {
|
|
3225
|
+
this.headless || this.prosemirrorView.focus();
|
|
3226
|
+
}
|
|
3227
|
+
blur() {
|
|
3228
|
+
this.headless || this.domElement?.blur();
|
|
3229
|
+
}
|
|
3230
|
+
onUploadStart(e) {
|
|
3231
|
+
return this.onUploadStartCallbacks.push(e), () => {
|
|
3232
|
+
let t = this.onUploadStartCallbacks.indexOf(e);
|
|
3233
|
+
t > -1 && this.onUploadStartCallbacks.splice(t, 1);
|
|
3234
|
+
};
|
|
3235
|
+
}
|
|
3236
|
+
onUploadEnd(e) {
|
|
3237
|
+
return this.onUploadEndCallbacks.push(e), () => {
|
|
3238
|
+
let t = this.onUploadEndCallbacks.indexOf(e);
|
|
3239
|
+
t > -1 && this.onUploadEndCallbacks.splice(t, 1);
|
|
3240
|
+
};
|
|
3241
|
+
}
|
|
3242
|
+
get topLevelBlocks() {
|
|
3243
|
+
return this.document;
|
|
3244
|
+
}
|
|
3245
|
+
get document() {
|
|
3246
|
+
return this._blockManager.document;
|
|
3247
|
+
}
|
|
3248
|
+
getBlock(e) {
|
|
3249
|
+
return this._blockManager.getBlock(e);
|
|
3250
|
+
}
|
|
3251
|
+
getPrevBlock(e) {
|
|
3252
|
+
return this._blockManager.getPrevBlock(e);
|
|
3253
|
+
}
|
|
3254
|
+
getNextBlock(e) {
|
|
3255
|
+
return this._blockManager.getNextBlock(e);
|
|
3256
|
+
}
|
|
3257
|
+
getParentBlock(e) {
|
|
3258
|
+
return this._blockManager.getParentBlock(e);
|
|
3259
|
+
}
|
|
3260
|
+
forEachBlock(e, t = !1) {
|
|
3261
|
+
this._blockManager.forEachBlock(e, t);
|
|
3262
|
+
}
|
|
3263
|
+
onEditorContentChange(e) {
|
|
3264
|
+
this._tiptapEditor.on("update", e);
|
|
3265
|
+
}
|
|
3266
|
+
onEditorSelectionChange(e) {
|
|
3267
|
+
this._tiptapEditor.on("selectionUpdate", e);
|
|
3268
|
+
}
|
|
3269
|
+
onBeforeChange(e) {
|
|
3270
|
+
return this._extensionManager.getExtension(Ve).subscribe(e);
|
|
3271
|
+
}
|
|
3272
|
+
getTextCursorPosition() {
|
|
3273
|
+
return this._selectionManager.getTextCursorPosition();
|
|
3274
|
+
}
|
|
3275
|
+
setTextCursorPosition(e, t = "start") {
|
|
3276
|
+
return this._selectionManager.setTextCursorPosition(e, t);
|
|
3277
|
+
}
|
|
3278
|
+
getSelection() {
|
|
3279
|
+
return this._selectionManager.getSelection();
|
|
3280
|
+
}
|
|
3281
|
+
getSelectionCutBlocks(e = !1) {
|
|
3282
|
+
return this._selectionManager.getSelectionCutBlocks(e);
|
|
3283
|
+
}
|
|
3284
|
+
setSelection(e, t) {
|
|
3285
|
+
return this._selectionManager.setSelection(e, t);
|
|
3286
|
+
}
|
|
3287
|
+
get isEditable() {
|
|
3288
|
+
return this._stateManager.isEditable;
|
|
3289
|
+
}
|
|
3290
|
+
set isEditable(e) {
|
|
3291
|
+
this._stateManager.isEditable = e;
|
|
3292
|
+
}
|
|
3293
|
+
insertBlocks(e, t, n = "before") {
|
|
3294
|
+
return this._blockManager.insertBlocks(e, t, n);
|
|
3295
|
+
}
|
|
3296
|
+
updateBlock(e, t) {
|
|
3297
|
+
return this._blockManager.updateBlock(e, t);
|
|
3298
|
+
}
|
|
3299
|
+
removeBlocks(e) {
|
|
3300
|
+
return this._blockManager.removeBlocks(e);
|
|
3301
|
+
}
|
|
3302
|
+
replaceBlocks(e, t) {
|
|
3303
|
+
return this._blockManager.replaceBlocks(e, t);
|
|
3304
|
+
}
|
|
3305
|
+
undo() {
|
|
3306
|
+
return this._stateManager.undo();
|
|
3307
|
+
}
|
|
3308
|
+
redo() {
|
|
3309
|
+
return this._stateManager.redo();
|
|
3310
|
+
}
|
|
3311
|
+
insertInlineContent(e, { updateSelection: t = !1 } = {}) {
|
|
3312
|
+
this._styleManager.insertInlineContent(e, { updateSelection: t });
|
|
3313
|
+
}
|
|
3314
|
+
getActiveStyles() {
|
|
3315
|
+
return this._styleManager.getActiveStyles();
|
|
3316
|
+
}
|
|
3317
|
+
addStyles(e) {
|
|
3318
|
+
this._styleManager.addStyles(e);
|
|
3319
|
+
}
|
|
3320
|
+
removeStyles(e) {
|
|
3321
|
+
this._styleManager.removeStyles(e);
|
|
3322
|
+
}
|
|
3323
|
+
toggleStyles(e) {
|
|
3324
|
+
this._styleManager.toggleStyles(e);
|
|
3325
|
+
}
|
|
3326
|
+
getSelectedText() {
|
|
3327
|
+
return this._styleManager.getSelectedText();
|
|
3328
|
+
}
|
|
3329
|
+
getSelectedLinkUrl() {
|
|
3330
|
+
return this._styleManager.getSelectedLinkUrl();
|
|
3331
|
+
}
|
|
3332
|
+
createLink(e, t) {
|
|
3333
|
+
this._styleManager.createLink(e, t);
|
|
3334
|
+
}
|
|
3335
|
+
getLinkMarkAtPos(e) {
|
|
3336
|
+
return this._styleManager.getLinkMarkAtPos(e);
|
|
3337
|
+
}
|
|
3338
|
+
editLink(e, t, n) {
|
|
3339
|
+
this._styleManager.editLink(e, t, n);
|
|
3340
|
+
}
|
|
3341
|
+
deleteLink(e) {
|
|
3342
|
+
this._styleManager.deleteLink(e);
|
|
3343
|
+
}
|
|
3344
|
+
canNestBlock() {
|
|
3345
|
+
return this._blockManager.canNestBlock();
|
|
3346
|
+
}
|
|
3347
|
+
nestBlock() {
|
|
3348
|
+
this._blockManager.nestBlock();
|
|
3349
|
+
}
|
|
3350
|
+
canUnnestBlock() {
|
|
3351
|
+
return this._blockManager.canUnnestBlock();
|
|
3352
|
+
}
|
|
3353
|
+
unnestBlock() {
|
|
3354
|
+
this._blockManager.unnestBlock();
|
|
3355
|
+
}
|
|
3356
|
+
moveBlocksUp(e) {
|
|
3357
|
+
return this._blockManager.moveBlocksUp(e);
|
|
3358
|
+
}
|
|
3359
|
+
moveBlocksDown(e) {
|
|
3360
|
+
return this._blockManager.moveBlocksDown(e);
|
|
3361
|
+
}
|
|
3362
|
+
blocksToHTMLLossy(e = this.document) {
|
|
3363
|
+
return this._exportManager.blocksToHTMLLossy(e);
|
|
3364
|
+
}
|
|
3365
|
+
blocksToFullHTML(e = this.document) {
|
|
3366
|
+
return this._exportManager.blocksToFullHTML(e);
|
|
3367
|
+
}
|
|
3368
|
+
tryParseHTMLToBlocks(e) {
|
|
3369
|
+
return this._exportManager.tryParseHTMLToBlocks(e);
|
|
3370
|
+
}
|
|
3371
|
+
blocksToMarkdownLossy(e = this.document) {
|
|
3372
|
+
return this._exportManager.blocksToMarkdownLossy(e);
|
|
3373
|
+
}
|
|
3374
|
+
tryParseMarkdownToBlocks(e) {
|
|
3375
|
+
return this._exportManager.tryParseMarkdownToBlocks(e);
|
|
3376
|
+
}
|
|
3377
|
+
onChange(e, t) {
|
|
3378
|
+
return this._eventManager.onChange(e, t);
|
|
3379
|
+
}
|
|
3380
|
+
onSelectionChange(e, t) {
|
|
3381
|
+
return this._eventManager.onSelectionChange(e, t);
|
|
3382
|
+
}
|
|
3383
|
+
onFocusChange(e, t) {
|
|
3384
|
+
return this._eventManager.onFocusChange(e, t);
|
|
3385
|
+
}
|
|
3386
|
+
onMount(e) {
|
|
3387
|
+
return this._eventManager.onMount(e);
|
|
3388
|
+
}
|
|
3389
|
+
onUnmount(e) {
|
|
3390
|
+
return this._eventManager.onUnmount(e);
|
|
3391
|
+
}
|
|
3392
|
+
getSelectionBoundingBox() {
|
|
3393
|
+
return this._selectionManager.getSelectionBoundingBox();
|
|
3394
|
+
}
|
|
3395
|
+
get isEmpty() {
|
|
3396
|
+
let e = this.document;
|
|
3397
|
+
return e.length === 0 || e.length === 1 && e[0].type === "paragraph" && e[0].content.length === 0;
|
|
3398
|
+
}
|
|
3399
|
+
pasteHTML(e, t = !1) {
|
|
3400
|
+
this._exportManager.pasteHTML(e, t);
|
|
3401
|
+
}
|
|
3402
|
+
pasteText(e) {
|
|
3403
|
+
return this._exportManager.pasteText(e);
|
|
3404
|
+
}
|
|
3405
|
+
pasteMarkdown(e) {
|
|
3406
|
+
return this._exportManager.pasteMarkdown(e);
|
|
3407
|
+
}
|
|
3408
|
+
}, ma = class {
|
|
3409
|
+
schema;
|
|
3410
|
+
mappings;
|
|
3411
|
+
options;
|
|
3412
|
+
constructor(e, t, n) {
|
|
3413
|
+
this.schema = e, this.mappings = t, this.options = n;
|
|
3414
|
+
}
|
|
3415
|
+
placesChildren(e) {
|
|
3416
|
+
let t = this.mappings.blockMapping[e.type];
|
|
3417
|
+
return typeof t == "object" && !!t;
|
|
3418
|
+
}
|
|
3419
|
+
get dictionary() {
|
|
3420
|
+
return this.options.dictionary?.exporter ?? nt.exporter;
|
|
3421
|
+
}
|
|
3422
|
+
async resolveFile(e) {
|
|
3423
|
+
if (!this.options?.resolveFileUrl) return this.fetchBlob(e);
|
|
3424
|
+
let t = await this.options.resolveFileUrl(e);
|
|
3425
|
+
return t instanceof Blob ? t : this.fetchBlob(t);
|
|
3426
|
+
}
|
|
3427
|
+
async fetchBlob(e) {
|
|
3428
|
+
let t = await fetch(e);
|
|
3429
|
+
if (!t.ok) throw Error(`Failed to fetch file "${e}": ${t.status} ${t.statusText}`);
|
|
3430
|
+
return t.blob();
|
|
3431
|
+
}
|
|
3432
|
+
mapStyles(e) {
|
|
3433
|
+
return Object.entries(e).map(([e, t]) => {
|
|
3434
|
+
let n = this.mappings.styleMapping[e];
|
|
3435
|
+
if (!n) throw Error(`Exporter is missing a style mapping for style "${e}". If this style comes from a separate package, spread that package's exporter mappings into your styleMapping.`);
|
|
3436
|
+
return n(t, this);
|
|
3437
|
+
});
|
|
3438
|
+
}
|
|
3439
|
+
mapInlineContent(e) {
|
|
3440
|
+
let t = this.mappings.inlineContentMapping[e.type];
|
|
3441
|
+
if (!t) throw Error(`Exporter is missing an inline content mapping for inline content type "${e.type}". If this inline content comes from a separate package, spread that package's exporter mappings into your inlineContentMapping.`);
|
|
3442
|
+
return t(e, this);
|
|
3443
|
+
}
|
|
3444
|
+
transformInlineContent(e) {
|
|
3445
|
+
return e.map((e) => this.mapInlineContent(e));
|
|
3446
|
+
}
|
|
3447
|
+
async mapBlock(e, t, n, r) {
|
|
3448
|
+
let i = this.mappings.blockMapping[e.type];
|
|
3449
|
+
if (!i) throw Error(`Exporter is missing a block mapping for block type "${e.type}". If this block comes from a separate package, spread that package's exporter mappings into your blockMapping.`);
|
|
3450
|
+
if (typeof i == "function") {
|
|
3451
|
+
let r = this.schema.blockSpecs[e.type];
|
|
3452
|
+
if (r !== void 0 && r.config.layoutOnly === !0) throw Error(`The mapping for layout block type "${e.type}" must be a \`{ withChildren }\` mapping, which places the block's children.`);
|
|
3453
|
+
return i(e, this, t, n);
|
|
3454
|
+
}
|
|
3455
|
+
return i.withChildren(e, this, t, n, r ?? []);
|
|
3456
|
+
}
|
|
3457
|
+
};
|
|
3458
|
+
//#endregion
|
|
3459
|
+
//#region src/exporter/ExportImage.ts
|
|
3460
|
+
function ha(e) {
|
|
3461
|
+
if ("toBase64" in e && typeof e.toBase64 == "function") return e.toBase64();
|
|
3462
|
+
let t = "";
|
|
3463
|
+
for (let n of e) t += String.fromCharCode(n);
|
|
3464
|
+
return btoa(t);
|
|
3465
|
+
}
|
|
3466
|
+
function ga(e) {
|
|
3467
|
+
return `data:${e.mimeType};base64,${ha(e.data)}`;
|
|
3468
|
+
}
|
|
3469
|
+
//#endregion
|
|
3470
|
+
//#region src/exporter/mapping.ts
|
|
3471
|
+
function _a(e) {
|
|
3472
|
+
return {
|
|
3473
|
+
createBlockMapping: (e) => e,
|
|
3474
|
+
createInlineContentMapping: (e) => e,
|
|
3475
|
+
createStyleMapping: (e) => e
|
|
3476
|
+
};
|
|
3477
|
+
}
|
|
3478
|
+
//#endregion
|
|
3479
|
+
//#region src/util/combineByGroup.ts
|
|
3480
|
+
function va(e, ...t) {
|
|
3481
|
+
let n = [...e];
|
|
3482
|
+
for (let e of t) for (let t of e) {
|
|
3483
|
+
let e = n.findLastIndex((e) => e.group === t.group);
|
|
3484
|
+
e === -1 ? n.push(t) : n.splice(e + 1, 0, t);
|
|
3485
|
+
}
|
|
3486
|
+
return n;
|
|
3487
|
+
}
|
|
3488
|
+
//#endregion
|
|
3489
|
+
export { U as A, ln as C, K as D, G as E, Lt as M, It as N, W as O, Mt as P, fn as S, Wt as T, pn as _, ma as a, Y as b, $ as c, nr as d, Ln as f, gn as g, Rn as h, ga as i, H as j, Rt as k, Ur as l, Bn as m, _a as n, pa as o, zn as p, ha as r, Zi as s, va as t, Hr as u, mn as v, Gt as w, hn as x, dn as y };
|
|
3490
|
+
|
|
3491
|
+
//# sourceMappingURL=src-BmLsLZfE.js.map
|