@shelamkoff/rector 1.0.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/LICENSE +21 -0
- package/NOTICE +17 -0
- package/README.md +23 -0
- package/THIRD_PARTY_LICENSES.txt +298 -0
- package/dist/I18n.d.ts +1 -0
- package/dist/core/Block.d.ts +110 -0
- package/dist/core/Block.js +390 -0
- package/dist/core/BlockAnimator.d.ts +39 -0
- package/dist/core/BlockAnimator.js +106 -0
- package/dist/core/BlockManager.d.ts +163 -0
- package/dist/core/BlockManager.js +640 -0
- package/dist/core/BlockOperations.d.ts +67 -0
- package/dist/core/BlockOperations.js +238 -0
- package/dist/core/ChangeNotifier.d.ts +15 -0
- package/dist/core/ChangeNotifier.js +55 -0
- package/dist/core/CommandDispatcher.d.ts +52 -0
- package/dist/core/CommandDispatcher.js +208 -0
- package/dist/core/CrossBlockSelection.d.ts +30 -0
- package/dist/core/CrossBlockSelection.js +74 -0
- package/dist/core/Diagnostics.d.ts +23 -0
- package/dist/core/Diagnostics.js +62 -0
- package/dist/core/DocumentSchema.d.ts +29 -0
- package/dist/core/DocumentSchema.js +147 -0
- package/dist/core/DocumentSnapshotStore.d.ts +34 -0
- package/dist/core/DocumentSnapshotStore.js +153 -0
- package/dist/core/DragManager.d.ts +17 -0
- package/dist/core/DragManager.js +223 -0
- package/dist/core/EditorFacade.d.ts +154 -0
- package/dist/core/EditorFacade.js +361 -0
- package/dist/core/EditorHolderOwnership.d.ts +12 -0
- package/dist/core/EditorHolderOwnership.js +28 -0
- package/dist/core/I18n.d.ts +147 -0
- package/dist/core/I18n.js +296 -0
- package/dist/core/InlinePatternMatcher.d.ts +26 -0
- package/dist/core/InlinePatternMatcher.js +267 -0
- package/dist/core/InlinePluginRegistry.d.ts +55 -0
- package/dist/core/InlinePluginRegistry.js +128 -0
- package/dist/core/KeyboardManager.d.ts +17 -0
- package/dist/core/KeyboardManager.js +231 -0
- package/dist/core/LifecycleScope.d.ts +19 -0
- package/dist/core/LifecycleScope.js +41 -0
- package/dist/core/MouseSelectionManager.d.ts +30 -0
- package/dist/core/MouseSelectionManager.js +307 -0
- package/dist/core/PluginOwnership.d.ts +9 -0
- package/dist/core/PluginOwnership.js +40 -0
- package/dist/core/PopupManager.d.ts +50 -0
- package/dist/core/PopupManager.js +183 -0
- package/dist/core/PreservedBlockPlugin.d.ts +11 -0
- package/dist/core/PreservedBlockPlugin.js +42 -0
- package/dist/core/PublicEditorApi.d.ts +82 -0
- package/dist/core/PublicEditorApi.js +158 -0
- package/dist/core/SelectionManager.d.ts +50 -0
- package/dist/core/SelectionManager.js +205 -0
- package/dist/core/ShortcutRegistry.d.ts +29 -0
- package/dist/core/ShortcutRegistry.js +106 -0
- package/dist/core/SlashCommands.d.ts +34 -0
- package/dist/core/SlashCommands.js +483 -0
- package/dist/core/StyleInjector.d.ts +1 -0
- package/dist/core/StyleInjector.js +1 -0
- package/dist/core/Tooltip.d.ts +17 -0
- package/dist/core/Tooltip.js +60 -0
- package/dist/core/TriggerManager.d.ts +17 -0
- package/dist/core/TriggerManager.js +159 -0
- package/dist/core/TypeSelector.d.ts +31 -0
- package/dist/core/TypeSelector.js +464 -0
- package/dist/core/UndoManager.d.ts +72 -0
- package/dist/core/UndoManager.js +383 -0
- package/dist/core/block-settings-menu/BlockActions.d.ts +81 -0
- package/dist/core/block-settings-menu/BlockActions.js +233 -0
- package/dist/core/block-settings-menu/BlockSettingsMenu.d.ts +46 -0
- package/dist/core/block-settings-menu/BlockSettingsMenu.js +205 -0
- package/dist/core/block-settings-menu/MenuBuilder.d.ts +43 -0
- package/dist/core/block-settings-menu/MenuBuilder.js +203 -0
- package/dist/core/block-settings-menu/MenuPositioner.d.ts +22 -0
- package/dist/core/block-settings-menu/MenuPositioner.js +79 -0
- package/dist/core/clipboard/Clipboard.d.ts +47 -0
- package/dist/core/clipboard/Clipboard.js +653 -0
- package/dist/core/clipboard/CrossBlockEditor.d.ts +43 -0
- package/dist/core/clipboard/CrossBlockEditor.js +198 -0
- package/dist/core/clipboard/PasteRouter.d.ts +27 -0
- package/dist/core/clipboard/PasteRouter.js +86 -0
- package/dist/core/clipboard/pasteInsert.d.ts +35 -0
- package/dist/core/clipboard/pasteInsert.js +215 -0
- package/dist/core/clipboard/pasteUtils.d.ts +25 -0
- package/dist/core/clipboard/pasteUtils.js +98 -0
- package/dist/core/config.d.ts +77 -0
- package/dist/core/config.js +100 -0
- package/dist/core/constants.d.ts +23 -0
- package/dist/core/constants.js +30 -0
- package/dist/core/crossBlockConvert.d.ts +38 -0
- package/dist/core/crossBlockConvert.js +253 -0
- package/dist/core/dom.d.ts +35 -0
- package/dist/core/dom.js +65 -0
- package/dist/core/editorEvents.d.ts +89 -0
- package/dist/core/editorEvents.js +60 -0
- package/dist/core/hydrateInlinePlugins.d.ts +9 -0
- package/dist/core/hydrateInlinePlugins.js +36 -0
- package/dist/core/icons.d.ts +10 -0
- package/dist/core/icons.js +21 -0
- package/dist/core/index.d.ts +59 -0
- package/dist/core/index.js +703 -0
- package/dist/core/inline-toolbar/ActionsPanel.d.ts +61 -0
- package/dist/core/inline-toolbar/ActionsPanel.js +132 -0
- package/dist/core/inline-toolbar/InlinePositioner.d.ts +20 -0
- package/dist/core/inline-toolbar/InlinePositioner.js +63 -0
- package/dist/core/inline-toolbar/InlineToolbar.d.ts +45 -0
- package/dist/core/inline-toolbar/InlineToolbar.js +456 -0
- package/dist/core/inline-toolbar/PluginControlsSlot.d.ts +52 -0
- package/dist/core/inline-toolbar/PluginControlsSlot.js +118 -0
- package/dist/core/inline-toolbar/SelectionTracker.d.ts +63 -0
- package/dist/core/inline-toolbar/SelectionTracker.js +173 -0
- package/dist/core/inlinePluginInsert.d.ts +13 -0
- package/dist/core/inlinePluginInsert.js +56 -0
- package/dist/core/locale/en.d.ts +35 -0
- package/dist/core/locale/en.js +37 -0
- package/dist/core/locale/ru.d.ts +35 -0
- package/dist/core/locale/ru.js +37 -0
- package/dist/core/menuKeyboardNav.d.ts +15 -0
- package/dist/core/menuKeyboardNav.js +52 -0
- package/dist/core/sanitize.d.ts +2 -0
- package/dist/core/sanitize.js +6 -0
- package/dist/core/splitConvert.d.ts +46 -0
- package/dist/core/splitConvert.js +190 -0
- package/dist/core/textOffset.d.ts +46 -0
- package/dist/core/textOffset.js +180 -0
- package/dist/core/themes/dark.css +30 -0
- package/dist/core/themes/light.css +33 -0
- package/dist/core/themes/variables.css +1170 -0
- package/dist/core/toolbar/OffcanvasRoot.d.ts +37 -0
- package/dist/core/toolbar/OffcanvasRoot.js +127 -0
- package/dist/core/toolbar/Toolbar.d.ts +70 -0
- package/dist/core/toolbar/Toolbar.js +432 -0
- package/dist/core/toolbar/ToolbarPositioner.d.ts +60 -0
- package/dist/core/toolbar/ToolbarPositioner.js +188 -0
- package/dist/core/toolbar/ToolboxBuilder.d.ts +44 -0
- package/dist/core/toolbar/ToolboxBuilder.js +260 -0
- package/dist/core/types.d.ts +747 -0
- package/dist/core/uid.d.ts +6 -0
- package/dist/core/uid.js +29 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/inline-plugins/README.md +35 -0
- package/dist/inline-plugins/README.ru.md +35 -0
- package/dist/inline-plugins/color/README.md +61 -0
- package/dist/inline-plugins/color/README.ru.md +61 -0
- package/dist/inline-plugins/color.d.ts +8 -0
- package/dist/inline-plugins/color.js +184 -0
- package/dist/inline-plugins/locale/en.d.ts +7 -0
- package/dist/inline-plugins/locale/en.js +6 -0
- package/dist/inline-plugins/locale/ru.d.ts +7 -0
- package/dist/inline-plugins/locale/ru.js +6 -0
- package/dist/inline-plugins/mention/README.md +97 -0
- package/dist/inline-plugins/mention/README.ru.md +97 -0
- package/dist/inline-plugins/mention/index.d.ts +110 -0
- package/dist/inline-plugins/mention/index.js +1897 -0
- package/dist/inline-plugins/mention/styles.css +183 -0
- package/dist/inline-plugins/mention/widget.d.ts +16 -0
- package/dist/inline-plugins/mention/widget.js +75 -0
- package/dist/inline-tools/align.d.ts +14 -0
- package/dist/inline-tools/align.js +120 -0
- package/dist/inline-tools/bold.d.ts +8 -0
- package/dist/inline-tools/bold.js +12 -0
- package/dist/inline-tools/caseTransform.d.ts +8 -0
- package/dist/inline-tools/caseTransform.js +87 -0
- package/dist/inline-tools/clearFormatting.d.ts +8 -0
- package/dist/inline-tools/clearFormatting.js +74 -0
- package/dist/inline-tools/code.d.ts +8 -0
- package/dist/inline-tools/code.js +12 -0
- package/dist/inline-tools/colorPicker.d.ts +7 -0
- package/dist/inline-tools/colorPicker.js +271 -0
- package/dist/inline-tools/defaults.d.ts +10 -0
- package/dist/inline-tools/defaults.js +57 -0
- package/dist/inline-tools/fontSize.d.ts +7 -0
- package/dist/inline-tools/fontSize.js +524 -0
- package/dist/inline-tools/italic.d.ts +8 -0
- package/dist/inline-tools/italic.js +12 -0
- package/dist/inline-tools/link.d.ts +12 -0
- package/dist/inline-tools/link.js +251 -0
- package/dist/inline-tools/marker.d.ts +8 -0
- package/dist/inline-tools/marker.js +12 -0
- package/dist/inline-tools/scriptTool.d.ts +11 -0
- package/dist/inline-tools/scriptTool.js +149 -0
- package/dist/inline-tools/strikethrough.d.ts +8 -0
- package/dist/inline-tools/strikethrough.js +12 -0
- package/dist/inline-tools/utils.d.ts +220 -0
- package/dist/inline-tools/utils.js +992 -0
- package/dist/locale/en.d.ts +311 -0
- package/dist/locale/en.js +52 -0
- package/dist/locale/ru.d.ts +315 -0
- package/dist/locale/ru.js +52 -0
- package/dist/plugins/BlockPluginAbstract.d.ts +82 -0
- package/dist/plugins/BlockPluginAbstract.js +111 -0
- package/dist/plugins/README.md +44 -0
- package/dist/plugins/README.ru.md +40 -0
- package/dist/plugins/async.d.ts +35 -0
- package/dist/plugins/async.js +79 -0
- package/dist/plugins/attaches/README.md +86 -0
- package/dist/plugins/attaches/README.ru.md +87 -0
- package/dist/plugins/attaches/attaches.css +374 -0
- package/dist/plugins/attaches/index.d.ts +133 -0
- package/dist/plugins/attaches/index.js +921 -0
- package/dist/plugins/attaches/locale/en.d.ts +23 -0
- package/dist/plugins/attaches/locale/en.js +19 -0
- package/dist/plugins/attaches/locale/keys.d.ts +5 -0
- package/dist/plugins/attaches/locale/ru.d.ts +25 -0
- package/dist/plugins/attaches/locale/ru.js +19 -0
- package/dist/plugins/carousel/README.md +108 -0
- package/dist/plugins/carousel/README.ru.md +109 -0
- package/dist/plugins/carousel/carousel.css +198 -0
- package/dist/plugins/carousel/icons.d.ts +12 -0
- package/dist/plugins/carousel/icons.js +13 -0
- package/dist/plugins/carousel/index.d.ts +137 -0
- package/dist/plugins/carousel/index.js +859 -0
- package/dist/plugins/carousel/locale/en.d.ts +41 -0
- package/dist/plugins/carousel/locale/en.js +40 -0
- package/dist/plugins/carousel/locale/keys.d.ts +2 -0
- package/dist/plugins/carousel/locale/ru.d.ts +41 -0
- package/dist/plugins/carousel/locale/ru.js +40 -0
- package/dist/plugins/carousel/state.d.ts +29 -0
- package/dist/plugins/carousel/state.js +42 -0
- package/dist/plugins/checklist/README.md +54 -0
- package/dist/plugins/checklist/README.ru.md +55 -0
- package/dist/plugins/checklist/checklist.css +80 -0
- package/dist/plugins/checklist/index.d.ts +75 -0
- package/dist/plugins/checklist/index.js +407 -0
- package/dist/plugins/checklist/locale/en.d.ts +5 -0
- package/dist/plugins/checklist/locale/en.js +4 -0
- package/dist/plugins/checklist/locale/keys.d.ts +5 -0
- package/dist/plugins/checklist/locale/ru.d.ts +5 -0
- package/dist/plugins/checklist/locale/ru.js +4 -0
- package/dist/plugins/checklist/mapTextFields.d.ts +1 -0
- package/dist/plugins/checklist/mapTextFields.js +1 -0
- package/dist/plugins/code/README.md +59 -0
- package/dist/plugins/code/README.ru.md +60 -0
- package/dist/plugins/code/code.css +360 -0
- package/dist/plugins/code/index.d.ts +109 -0
- package/dist/plugins/code/index.js +1012 -0
- package/dist/plugins/code/locale/en.d.ts +11 -0
- package/dist/plugins/code/locale/en.js +10 -0
- package/dist/plugins/code/locale/keys.d.ts +5 -0
- package/dist/plugins/code/locale/ru.d.ts +11 -0
- package/dist/plugins/code/locale/ru.js +10 -0
- package/dist/plugins/columns/README.md +55 -0
- package/dist/plugins/columns/README.ru.md +56 -0
- package/dist/plugins/columns/columns.css +103 -0
- package/dist/plugins/columns/index.d.ts +58 -0
- package/dist/plugins/columns/index.js +236 -0
- package/dist/plugins/columns/locale/en.d.ts +6 -0
- package/dist/plugins/columns/locale/en.js +5 -0
- package/dist/plugins/columns/locale/keys.d.ts +5 -0
- package/dist/plugins/columns/locale/ru.d.ts +6 -0
- package/dist/plugins/columns/locale/ru.js +5 -0
- package/dist/plugins/delimiter/README.md +48 -0
- package/dist/plugins/delimiter/README.ru.md +49 -0
- package/dist/plugins/delimiter/delimiter.css +22 -0
- package/dist/plugins/delimiter/index.d.ts +38 -0
- package/dist/plugins/delimiter/index.js +69 -0
- package/dist/plugins/delimiter/locale/en.d.ts +4 -0
- package/dist/plugins/delimiter/locale/en.js +3 -0
- package/dist/plugins/delimiter/locale/keys.d.ts +5 -0
- package/dist/plugins/delimiter/locale/ru.d.ts +4 -0
- package/dist/plugins/delimiter/locale/ru.js +3 -0
- package/dist/plugins/embed/README.md +81 -0
- package/dist/plugins/embed/README.ru.md +82 -0
- package/dist/plugins/embed/embed.css +558 -0
- package/dist/plugins/embed/index.d.ts +271 -0
- package/dist/plugins/embed/index.js +967 -0
- package/dist/plugins/embed/locale/en.d.ts +20 -0
- package/dist/plugins/embed/locale/en.js +19 -0
- package/dist/plugins/embed/locale/keys.d.ts +5 -0
- package/dist/plugins/embed/locale/ru.d.ts +20 -0
- package/dist/plugins/embed/locale/ru.js +19 -0
- package/dist/plugins/embed/player.d.ts +1 -0
- package/dist/plugins/embed/player.js +1 -0
- package/dist/plugins/gallery/README.md +92 -0
- package/dist/plugins/gallery/README.ru.md +93 -0
- package/dist/plugins/gallery/css.d.ts +52 -0
- package/dist/plugins/gallery/css.js +67 -0
- package/dist/plugins/gallery/gallery.css +860 -0
- package/dist/plugins/gallery/icons.d.ts +13 -0
- package/dist/plugins/gallery/icons.js +45 -0
- package/dist/plugins/gallery/index.d.ts +126 -0
- package/dist/plugins/gallery/index.js +355 -0
- package/dist/plugins/gallery/layout.d.ts +35 -0
- package/dist/plugins/gallery/layout.js +79 -0
- package/dist/plugins/gallery/locale/en.d.ts +36 -0
- package/dist/plugins/gallery/locale/en.js +35 -0
- package/dist/plugins/gallery/locale/keys.d.ts +5 -0
- package/dist/plugins/gallery/locale/ru.d.ts +36 -0
- package/dist/plugins/gallery/locale/ru.js +35 -0
- package/dist/plugins/gallery/settings.d.ts +25 -0
- package/dist/plugins/gallery/settings.js +199 -0
- package/dist/plugins/gallery/slot.d.ts +73 -0
- package/dist/plugins/gallery/slot.js +260 -0
- package/dist/plugins/gallery/state.d.ts +67 -0
- package/dist/plugins/gallery/state.js +133 -0
- package/dist/plugins/gallery/styles.d.ts +10 -0
- package/dist/plugins/gallery/styles.js +24 -0
- package/dist/plugins/gallery/uploader.d.ts +31 -0
- package/dist/plugins/gallery/uploader.js +111 -0
- package/dist/plugins/gallery/view-empty.d.ts +41 -0
- package/dist/plugins/gallery/view-empty.js +56 -0
- package/dist/plugins/gallery/view-filled.d.ts +55 -0
- package/dist/plugins/gallery/view-filled.js +353 -0
- package/dist/plugins/heading/HeadingLevelSelect.d.ts +16 -0
- package/dist/plugins/heading/HeadingLevelSelect.js +183 -0
- package/dist/plugins/heading/README.md +58 -0
- package/dist/plugins/heading/README.ru.md +59 -0
- package/dist/plugins/heading/heading.css +76 -0
- package/dist/plugins/heading/index.d.ts +124 -0
- package/dist/plugins/heading/index.js +273 -0
- package/dist/plugins/heading/locale/en.d.ts +11 -0
- package/dist/plugins/heading/locale/en.js +10 -0
- package/dist/plugins/heading/locale/keys.d.ts +5 -0
- package/dist/plugins/heading/locale/ru.d.ts +11 -0
- package/dist/plugins/heading/locale/ru.js +10 -0
- package/dist/plugins/heading/mapTextFields.d.ts +1 -0
- package/dist/plugins/heading/mapTextFields.js +1 -0
- package/dist/plugins/image/README.md +93 -0
- package/dist/plugins/image/README.ru.md +94 -0
- package/dist/plugins/image/css.d.ts +47 -0
- package/dist/plugins/image/css.js +47 -0
- package/dist/plugins/image/icons.d.ts +13 -0
- package/dist/plugins/image/icons.js +26 -0
- package/dist/plugins/image/image.css +559 -0
- package/dist/plugins/image/index.d.ts +129 -0
- package/dist/plugins/image/index.js +346 -0
- package/dist/plugins/image/locale/en.d.ts +39 -0
- package/dist/plugins/image/locale/en.js +38 -0
- package/dist/plugins/image/locale/keys.d.ts +5 -0
- package/dist/plugins/image/locale/ru.d.ts +39 -0
- package/dist/plugins/image/locale/ru.js +38 -0
- package/dist/plugins/image/settings.d.ts +23 -0
- package/dist/plugins/image/settings.js +347 -0
- package/dist/plugins/image/state.d.ts +86 -0
- package/dist/plugins/image/state.js +151 -0
- package/dist/plugins/image/styles.d.ts +21 -0
- package/dist/plugins/image/styles.js +58 -0
- package/dist/plugins/image/uploader.d.ts +31 -0
- package/dist/plugins/image/uploader.js +92 -0
- package/dist/plugins/image/view-empty.d.ts +44 -0
- package/dist/plugins/image/view-empty.js +61 -0
- package/dist/plugins/image/view-filled.d.ts +49 -0
- package/dist/plugins/image/view-filled.js +282 -0
- package/dist/plugins/index.d.ts +21 -0
- package/dist/plugins/index.js +22 -0
- package/dist/plugins/link-preview/README.md +69 -0
- package/dist/plugins/link-preview/README.ru.md +70 -0
- package/dist/plugins/link-preview/index.d.ts +169 -0
- package/dist/plugins/link-preview/index.js +698 -0
- package/dist/plugins/link-preview/link-preview.css +254 -0
- package/dist/plugins/link-preview/locale/en.d.ts +14 -0
- package/dist/plugins/link-preview/locale/en.js +13 -0
- package/dist/plugins/link-preview/locale/keys.d.ts +5 -0
- package/dist/plugins/link-preview/locale/ru.d.ts +14 -0
- package/dist/plugins/link-preview/locale/ru.js +13 -0
- package/dist/plugins/list/README.md +59 -0
- package/dist/plugins/list/README.ru.md +60 -0
- package/dist/plugins/list/index.d.ts +134 -0
- package/dist/plugins/list/index.js +566 -0
- package/dist/plugins/list/list.css +57 -0
- package/dist/plugins/list/locale/en.d.ts +5 -0
- package/dist/plugins/list/locale/en.js +4 -0
- package/dist/plugins/list/locale/keys.d.ts +5 -0
- package/dist/plugins/list/locale/ru.d.ts +5 -0
- package/dist/plugins/list/locale/ru.js +4 -0
- package/dist/plugins/list/mapTextFields.d.ts +1 -0
- package/dist/plugins/list/mapTextFields.js +1 -0
- package/dist/plugins/paragraph/README.md +57 -0
- package/dist/plugins/paragraph/README.ru.md +58 -0
- package/dist/plugins/paragraph/index.d.ts +112 -0
- package/dist/plugins/paragraph/index.js +158 -0
- package/dist/plugins/paragraph/locale/en.d.ts +5 -0
- package/dist/plugins/paragraph/locale/en.js +4 -0
- package/dist/plugins/paragraph/locale/keys.d.ts +5 -0
- package/dist/plugins/paragraph/locale/ru.d.ts +5 -0
- package/dist/plugins/paragraph/locale/ru.js +4 -0
- package/dist/plugins/paragraph/mapTextFields.d.ts +1 -0
- package/dist/plugins/paragraph/mapTextFields.js +1 -0
- package/dist/plugins/paragraph/paragraph.css +56 -0
- package/dist/plugins/person/README.md +72 -0
- package/dist/plugins/person/README.ru.md +73 -0
- package/dist/plugins/person/index.d.ts +189 -0
- package/dist/plugins/person/index.js +777 -0
- package/dist/plugins/person/locale/en.d.ts +18 -0
- package/dist/plugins/person/locale/en.js +17 -0
- package/dist/plugins/person/locale/keys.d.ts +5 -0
- package/dist/plugins/person/locale/ru.d.ts +18 -0
- package/dist/plugins/person/locale/ru.js +17 -0
- package/dist/plugins/person/person.css +431 -0
- package/dist/plugins/person/socialResolver.d.ts +18 -0
- package/dist/plugins/person/socialResolver.js +69 -0
- package/dist/plugins/poll/README.md +96 -0
- package/dist/plugins/poll/README.ru.md +97 -0
- package/dist/plugins/poll/index.d.ts +134 -0
- package/dist/plugins/poll/index.js +825 -0
- package/dist/plugins/poll/locale/en.d.ts +23 -0
- package/dist/plugins/poll/locale/en.js +22 -0
- package/dist/plugins/poll/locale/keys.d.ts +5 -0
- package/dist/plugins/poll/locale/ru.d.ts +23 -0
- package/dist/plugins/poll/locale/ru.js +22 -0
- package/dist/plugins/poll/poll.css +400 -0
- package/dist/plugins/quote/README.md +55 -0
- package/dist/plugins/quote/README.ru.md +56 -0
- package/dist/plugins/quote/index.d.ts +81 -0
- package/dist/plugins/quote/index.js +165 -0
- package/dist/plugins/quote/locale/en.d.ts +6 -0
- package/dist/plugins/quote/locale/en.js +5 -0
- package/dist/plugins/quote/locale/keys.d.ts +5 -0
- package/dist/plugins/quote/locale/ru.d.ts +6 -0
- package/dist/plugins/quote/locale/ru.js +5 -0
- package/dist/plugins/quote/mapTextFields.d.ts +1 -0
- package/dist/plugins/quote/mapTextFields.js +1 -0
- package/dist/plugins/quote/quote.css +72 -0
- package/dist/plugins/raw/README.md +54 -0
- package/dist/plugins/raw/README.ru.md +55 -0
- package/dist/plugins/raw/index.d.ts +62 -0
- package/dist/plugins/raw/index.js +227 -0
- package/dist/plugins/raw/locale/en.d.ts +7 -0
- package/dist/plugins/raw/locale/en.js +6 -0
- package/dist/plugins/raw/locale/keys.d.ts +5 -0
- package/dist/plugins/raw/locale/ru.d.ts +7 -0
- package/dist/plugins/raw/locale/ru.js +6 -0
- package/dist/plugins/raw/raw.css +127 -0
- package/dist/plugins/shared/actionBar.d.ts +19 -0
- package/dist/plugins/shared/actionBar.js +35 -0
- package/dist/plugins/shared/dropzone.d.ts +106 -0
- package/dist/plugins/shared/dropzone.js +107 -0
- package/dist/plugins/shared/fileInput.d.ts +44 -0
- package/dist/plugins/shared/fileInput.js +62 -0
- package/dist/plugins/spoiler/README.md +55 -0
- package/dist/plugins/spoiler/README.ru.md +56 -0
- package/dist/plugins/spoiler/index.d.ts +61 -0
- package/dist/plugins/spoiler/index.js +169 -0
- package/dist/plugins/spoiler/locale/en.d.ts +7 -0
- package/dist/plugins/spoiler/locale/en.js +6 -0
- package/dist/plugins/spoiler/locale/keys.d.ts +5 -0
- package/dist/plugins/spoiler/locale/ru.d.ts +7 -0
- package/dist/plugins/spoiler/locale/ru.js +6 -0
- package/dist/plugins/spoiler/spoiler.css +101 -0
- package/dist/plugins/table/README.md +55 -0
- package/dist/plugins/table/README.ru.md +56 -0
- package/dist/plugins/table/index.d.ts +85 -0
- package/dist/plugins/table/index.js +399 -0
- package/dist/plugins/table/locale/en.d.ts +9 -0
- package/dist/plugins/table/locale/en.js +8 -0
- package/dist/plugins/table/locale/keys.d.ts +5 -0
- package/dist/plugins/table/locale/ru.d.ts +9 -0
- package/dist/plugins/table/locale/ru.js +8 -0
- package/dist/plugins/table/table.css +58 -0
- package/dist/plugins/toggle/README.md +56 -0
- package/dist/plugins/toggle/README.ru.md +57 -0
- package/dist/plugins/toggle/index.d.ts +69 -0
- package/dist/plugins/toggle/index.js +191 -0
- package/dist/plugins/toggle/locale/en.d.ts +7 -0
- package/dist/plugins/toggle/locale/en.js +6 -0
- package/dist/plugins/toggle/locale/keys.d.ts +5 -0
- package/dist/plugins/toggle/locale/ru.d.ts +7 -0
- package/dist/plugins/toggle/locale/ru.js +6 -0
- package/dist/plugins/toggle/toggle.css +101 -0
- package/dist/plugins/warning/README.md +55 -0
- package/dist/plugins/warning/README.ru.md +56 -0
- package/dist/plugins/warning/index.d.ts +66 -0
- package/dist/plugins/warning/index.js +167 -0
- package/dist/plugins/warning/locale/en.d.ts +6 -0
- package/dist/plugins/warning/locale/en.js +5 -0
- package/dist/plugins/warning/locale/keys.d.ts +5 -0
- package/dist/plugins/warning/locale/ru.d.ts +6 -0
- package/dist/plugins/warning/locale/ru.js +5 -0
- package/dist/plugins/warning/warning.css +63 -0
- package/dist/renderer/async.d.ts +1 -0
- package/dist/renderer/async.js +7 -0
- package/dist/renderer/errors.d.ts +27 -0
- package/dist/renderer/errors.js +48 -0
- package/dist/renderer/index.d.ts +82 -0
- package/dist/renderer/index.js +413 -0
- package/dist/renderer/inline.d.ts +5 -0
- package/dist/renderer/inline.js +61 -0
- package/dist/renderer/locale/en.d.ts +35 -0
- package/dist/renderer/locale/en.js +29 -0
- package/dist/renderer/locale/ru.d.ts +37 -0
- package/dist/renderer/locale/ru.js +29 -0
- package/dist/renderer/renderers/README.md +7 -0
- package/dist/renderer/renderers/README.ru.md +5 -0
- package/dist/renderer/renderers/async.d.ts +51 -0
- package/dist/renderer/renderers/async.js +99 -0
- package/dist/renderer/renderers/attaches/README.md +48 -0
- package/dist/renderer/renderers/attaches/README.ru.md +48 -0
- package/dist/renderer/renderers/attaches/index.d.ts +37 -0
- package/dist/renderer/renderers/attaches/index.js +451 -0
- package/dist/renderer/renderers/attaches/locale/en.d.ts +11 -0
- package/dist/renderer/renderers/attaches/locale/en.js +7 -0
- package/dist/renderer/renderers/attaches/locale/ru.d.ts +13 -0
- package/dist/renderer/renderers/attaches/locale/ru.js +7 -0
- package/dist/renderer/renderers/attaches/styles.css +196 -0
- package/dist/renderer/renderers/carousel/README.md +43 -0
- package/dist/renderer/renderers/carousel/README.ru.md +43 -0
- package/dist/renderer/renderers/carousel/index.d.ts +7 -0
- package/dist/renderer/renderers/carousel/index.js +110 -0
- package/dist/renderer/renderers/carousel/styles.css +7 -0
- package/dist/renderer/renderers/checklist/README.md +33 -0
- package/dist/renderer/renderers/checklist/README.ru.md +33 -0
- package/dist/renderer/renderers/checklist/index.d.ts +7 -0
- package/dist/renderer/renderers/checklist/index.js +55 -0
- package/dist/renderer/renderers/checklist/styles.css +54 -0
- package/dist/renderer/renderers/code/README.md +33 -0
- package/dist/renderer/renderers/code/README.ru.md +33 -0
- package/dist/renderer/renderers/code/index.d.ts +9 -0
- package/dist/renderer/renderers/code/index.js +137 -0
- package/dist/renderer/renderers/code/locale/en.d.ts +5 -0
- package/dist/renderer/renderers/code/locale/en.js +4 -0
- package/dist/renderer/renderers/code/locale/ru.d.ts +5 -0
- package/dist/renderer/renderers/code/locale/ru.js +4 -0
- package/dist/renderer/renderers/code/styles.css +330 -0
- package/dist/renderer/renderers/columns/README.md +33 -0
- package/dist/renderer/renderers/columns/README.ru.md +33 -0
- package/dist/renderer/renderers/columns/index.d.ts +7 -0
- package/dist/renderer/renderers/columns/index.js +53 -0
- package/dist/renderer/renderers/columns/styles.css +5 -0
- package/dist/renderer/renderers/delimiter/README.md +33 -0
- package/dist/renderer/renderers/delimiter/README.ru.md +33 -0
- package/dist/renderer/renderers/delimiter/index.d.ts +7 -0
- package/dist/renderer/renderers/delimiter/index.js +28 -0
- package/dist/renderer/renderers/delimiter/styles.css +12 -0
- package/dist/renderer/renderers/embed/README.md +35 -0
- package/dist/renderer/renderers/embed/README.ru.md +35 -0
- package/dist/renderer/renderers/embed/index.d.ts +8 -0
- package/dist/renderer/renderers/embed/index.js +66 -0
- package/dist/renderer/renderers/embed/styles.css +217 -0
- package/dist/renderer/renderers/gallery/README.md +41 -0
- package/dist/renderer/renderers/gallery/README.ru.md +41 -0
- package/dist/renderer/renderers/gallery/index.d.ts +8 -0
- package/dist/renderer/renderers/gallery/index.js +329 -0
- package/dist/renderer/renderers/gallery/styles.css +419 -0
- package/dist/renderer/renderers/heading/README.md +33 -0
- package/dist/renderer/renderers/heading/README.ru.md +33 -0
- package/dist/renderer/renderers/heading/index.d.ts +8 -0
- package/dist/renderer/renderers/heading/index.js +38 -0
- package/dist/renderer/renderers/heading/styles.css +26 -0
- package/dist/renderer/renderers/image/README.md +42 -0
- package/dist/renderer/renderers/image/README.ru.md +42 -0
- package/dist/renderer/renderers/image/index.d.ts +7 -0
- package/dist/renderer/renderers/image/index.js +93 -0
- package/dist/renderer/renderers/image/styles.css +40 -0
- package/dist/renderer/renderers/index.d.ts +47 -0
- package/dist/renderer/renderers/index.js +125 -0
- package/dist/renderer/renderers/link-preview/README.md +43 -0
- package/dist/renderer/renderers/link-preview/README.ru.md +43 -0
- package/dist/renderer/renderers/link-preview/index.d.ts +9 -0
- package/dist/renderer/renderers/link-preview/index.js +118 -0
- package/dist/renderer/renderers/link-preview/styles.css +246 -0
- package/dist/renderer/renderers/list/README.md +33 -0
- package/dist/renderer/renderers/list/README.ru.md +33 -0
- package/dist/renderer/renderers/list/index.d.ts +8 -0
- package/dist/renderer/renderers/list/index.js +42 -0
- package/dist/renderer/renderers/list/styles.css +20 -0
- package/dist/renderer/renderers/paragraph/README.md +33 -0
- package/dist/renderer/renderers/paragraph/README.ru.md +33 -0
- package/dist/renderer/renderers/paragraph/index.d.ts +7 -0
- package/dist/renderer/renderers/paragraph/index.js +35 -0
- package/dist/renderer/renderers/paragraph/styles.css +3 -0
- package/dist/renderer/renderers/person/README.md +44 -0
- package/dist/renderer/renderers/person/README.ru.md +44 -0
- package/dist/renderer/renderers/person/index.d.ts +7 -0
- package/dist/renderer/renderers/person/index.js +213 -0
- package/dist/renderer/renderers/person/locale/en.d.ts +6 -0
- package/dist/renderer/renderers/person/locale/en.js +5 -0
- package/dist/renderer/renderers/person/locale/ru.d.ts +6 -0
- package/dist/renderer/renderers/person/locale/ru.js +5 -0
- package/dist/renderer/renderers/person/styles.css +47 -0
- package/dist/renderer/renderers/poll/README.md +68 -0
- package/dist/renderer/renderers/poll/README.ru.md +68 -0
- package/dist/renderer/renderers/poll/index.d.ts +9 -0
- package/dist/renderer/renderers/poll/index.js +339 -0
- package/dist/renderer/renderers/poll/styles.css +148 -0
- package/dist/renderer/renderers/quote/README.md +33 -0
- package/dist/renderer/renderers/quote/README.ru.md +33 -0
- package/dist/renderer/renderers/quote/index.d.ts +7 -0
- package/dist/renderer/renderers/quote/index.js +59 -0
- package/dist/renderer/renderers/quote/styles.css +43 -0
- package/dist/renderer/renderers/raw/README.md +33 -0
- package/dist/renderer/renderers/raw/README.ru.md +33 -0
- package/dist/renderer/renderers/raw/index.d.ts +7 -0
- package/dist/renderer/renderers/raw/index.js +27 -0
- package/dist/renderer/renderers/spoiler/README.md +33 -0
- package/dist/renderer/renderers/spoiler/README.ru.md +33 -0
- package/dist/renderer/renderers/spoiler/index.d.ts +9 -0
- package/dist/renderer/renderers/spoiler/index.js +84 -0
- package/dist/renderer/renderers/spoiler/locale/en.d.ts +4 -0
- package/dist/renderer/renderers/spoiler/locale/en.js +3 -0
- package/dist/renderer/renderers/spoiler/locale/ru.d.ts +4 -0
- package/dist/renderer/renderers/spoiler/locale/ru.js +3 -0
- package/dist/renderer/renderers/spoiler/styles.css +61 -0
- package/dist/renderer/renderers/table/README.md +33 -0
- package/dist/renderer/renderers/table/README.ru.md +33 -0
- package/dist/renderer/renderers/table/index.d.ts +7 -0
- package/dist/renderer/renderers/table/index.js +83 -0
- package/dist/renderer/renderers/table/styles.css +34 -0
- package/dist/renderer/renderers/toggle/README.md +33 -0
- package/dist/renderer/renderers/toggle/README.ru.md +33 -0
- package/dist/renderer/renderers/toggle/index.d.ts +7 -0
- package/dist/renderer/renderers/toggle/index.js +59 -0
- package/dist/renderer/renderers/toggle/styles.css +49 -0
- package/dist/renderer/renderers/warning/README.md +33 -0
- package/dist/renderer/renderers/warning/README.ru.md +33 -0
- package/dist/renderer/renderers/warning/index.d.ts +7 -0
- package/dist/renderer/renderers/warning/index.js +62 -0
- package/dist/renderer/renderers/warning/styles.css +41 -0
- package/dist/renderer/styles/base.css +168 -0
- package/dist/renderer/types.d.ts +464 -0
- package/dist/shared/blockDataNormalizers.d.ts +14 -0
- package/dist/shared/blockDataNormalizers.js +235 -0
- package/dist/shared/blockDataValidators.d.ts +81 -0
- package/dist/shared/blockDataValidators.js +313 -0
- package/dist/shared/blockTypes.d.ts +2 -0
- package/dist/shared/blockTypes.js +26 -0
- package/dist/shared/carouselData.d.ts +34 -0
- package/dist/shared/carouselData.js +111 -0
- package/dist/shared/cloneEditorData.d.ts +11 -0
- package/dist/shared/cloneEditorData.js +20 -0
- package/dist/shared/documentTypes.d.ts +35 -0
- package/dist/shared/embedPlayer.d.ts +42 -0
- package/dist/shared/embedPlayer.js +141 -0
- package/dist/shared/fileUtils.d.ts +33 -0
- package/dist/shared/fileUtils.js +109 -0
- package/dist/shared/highlightRuntime.d.ts +38 -0
- package/dist/shared/highlightRuntime.js +75 -0
- package/dist/shared/inlineMarshal.d.ts +82 -0
- package/dist/shared/inlineMarshal.js +215 -0
- package/dist/shared/jsonData.d.ts +11 -0
- package/dist/shared/jsonData.js +53 -0
- package/dist/shared/localeTypes.d.ts +11 -0
- package/dist/shared/mapTextFields.d.ts +89 -0
- package/dist/shared/mapTextFields.js +119 -0
- package/dist/shared/pollData.d.ts +90 -0
- package/dist/shared/pollData.js +231 -0
- package/dist/shared/resolvePath.d.ts +8 -0
- package/dist/shared/resolvePath.js +10 -0
- package/dist/shared/runtime/dompurify.js +2424 -0
- package/dist/shared/runtime/highlightBundle.js +10 -0
- package/dist/shared/runtime/jszip.js +13 -0
- package/dist/shared/sanitize/allowlist.d.ts +21 -0
- package/dist/shared/sanitize/allowlist.js +40 -0
- package/dist/shared/sanitize/escapeHtml.d.ts +6 -0
- package/dist/shared/sanitize/escapeHtml.js +11 -0
- package/dist/shared/sanitize/index.d.ts +8 -0
- package/dist/shared/sanitize/index.js +8 -0
- package/dist/shared/sanitize/parseInline.d.ts +11 -0
- package/dist/shared/sanitize/parseInline.js +25 -0
- package/dist/shared/sanitize/sanitizeHtml.d.ts +8 -0
- package/dist/shared/sanitize/sanitizeHtml.js +19 -0
- package/dist/shared/sanitize/sanitizeRawHtml.d.ts +15 -0
- package/dist/shared/sanitize/sanitizeRawHtml.js +162 -0
- package/dist/shared/sanitize/sanitizeStyle.d.ts +9 -0
- package/dist/shared/sanitize/sanitizeStyle.js +39 -0
- package/dist/shared/sanitize/sanitizeUrl.d.ts +28 -0
- package/dist/shared/sanitize/sanitizeUrl.js +86 -0
- package/dist/shared/sanitize/walker.d.ts +15 -0
- package/dist/shared/sanitize/walker.js +98 -0
- package/dist/shared/styleRegistry.d.ts +4 -0
- package/dist/shared/styleRegistry.js +38 -0
- package/dist/shared/textFormat.d.ts +32 -0
- package/dist/shared/textFormat.js +48 -0
- package/dist/shared/zipRuntime.d.ts +19 -0
- package/dist/shared/zipRuntime.js +54 -0
- package/dist/styles/editor.css +3 -0
- package/dist/types.d.ts +1 -0
- package/package.json +149 -0
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
import { BLOCK_SELECTOR } from '../constants.js'
|
|
2
|
+
import { EditorEvent } from '../editorEvents.js'
|
|
3
|
+
import { CrossBlockEditor } from './CrossBlockEditor.js'
|
|
4
|
+
import { PasteRouter } from './PasteRouter.js'
|
|
5
|
+
import { pasteHtml, pastePlainText } from './pasteInsert.js'
|
|
6
|
+
import { hydrateInlinePlugins } from '../hydrateInlinePlugins.js'
|
|
7
|
+
import { cloneEditorData } from '../../shared/cloneEditorData.js'
|
|
8
|
+
|
|
9
|
+
const MIME_TYPE = 'application/x-rector-editor'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Extract plain text and HTML from a DOM Range.
|
|
13
|
+
* @param {Range} range
|
|
14
|
+
* @returns {{ text: string, html: string }}
|
|
15
|
+
*/
|
|
16
|
+
function extractRangeContent(range) {
|
|
17
|
+
const text = range.toString()
|
|
18
|
+
const frag = range.cloneContents()
|
|
19
|
+
const div = document.createElement('div')
|
|
20
|
+
div.appendChild(frag)
|
|
21
|
+
return { text, html: div.innerHTML }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Copy a cross-block range as both plain text and HTML via async Clipboard API.
|
|
26
|
+
* Used from keydown handler where ClipboardEvent.clipboardData is unavailable.
|
|
27
|
+
*
|
|
28
|
+
* @param {KeyboardEvent} e
|
|
29
|
+
* @param {Range} crossRange
|
|
30
|
+
* @returns {boolean} whether the async Clipboard API handled the operation
|
|
31
|
+
*/
|
|
32
|
+
function copyRange(e, crossRange) {
|
|
33
|
+
if (typeof ClipboardItem === 'undefined' || !navigator.clipboard?.write) return false
|
|
34
|
+
|
|
35
|
+
e.preventDefault()
|
|
36
|
+
const { text, html } = extractRangeContent(crossRange)
|
|
37
|
+
|
|
38
|
+
navigator.clipboard.write([
|
|
39
|
+
new ClipboardItem({
|
|
40
|
+
'text/plain': new Blob([text], { type: 'text/plain' }),
|
|
41
|
+
'text/html': new Blob([html], { type: 'text/html' }),
|
|
42
|
+
}),
|
|
43
|
+
]).catch((err) => {
|
|
44
|
+
console.warn('[Clipboard] Failed to write rich clipboard, falling back to plain text:', err)
|
|
45
|
+
navigator.clipboard?.writeText?.(text).catch(() => {})
|
|
46
|
+
})
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Editor clipboard surface — listens to copy/cut/paste/keydown on the editor
|
|
52
|
+
* root and dispatches to the right helper:
|
|
53
|
+
* - selected blocks (`block.selected`): handled inline (whole-block copy/cut)
|
|
54
|
+
* - cross-block range: delegated to `CrossBlockEditor`
|
|
55
|
+
* - paste: routed by MIME type → custom-data, files, html, plain text,
|
|
56
|
+
* each via `PasteRouter` lookup or `pasteInsert.js` helpers.
|
|
57
|
+
*/
|
|
58
|
+
export class Clipboard {
|
|
59
|
+
/** @type {HTMLElement} */
|
|
60
|
+
#rootEl
|
|
61
|
+
|
|
62
|
+
/** @type {import('../types').IBlockManager} */
|
|
63
|
+
#blocks
|
|
64
|
+
|
|
65
|
+
/** @type {import('../types').ISelectionManager} */
|
|
66
|
+
#selection
|
|
67
|
+
|
|
68
|
+
/** @type {Map<string, import('../types').BlockPlugin>} */
|
|
69
|
+
#plugins
|
|
70
|
+
|
|
71
|
+
/** @type {string} */
|
|
72
|
+
#defaultBlockType
|
|
73
|
+
|
|
74
|
+
/** @type {import('../types').ICrossBlockSelection} */
|
|
75
|
+
#crossBlockSelection
|
|
76
|
+
|
|
77
|
+
/** @type {import('../types').IEventBus} */
|
|
78
|
+
#events
|
|
79
|
+
|
|
80
|
+
/** @type {import('../CommandDispatcher').CommandDispatcher} */
|
|
81
|
+
#commands
|
|
82
|
+
|
|
83
|
+
/** @type {import('../Diagnostics').Diagnostics | null} */
|
|
84
|
+
#diagnostics
|
|
85
|
+
|
|
86
|
+
/** @type {PasteRouter} */
|
|
87
|
+
#router
|
|
88
|
+
|
|
89
|
+
/** @type {CrossBlockEditor} */
|
|
90
|
+
#crossEditor
|
|
91
|
+
|
|
92
|
+
/** @type {import('../BlockOperations').BlockOperations} */
|
|
93
|
+
#blockOps
|
|
94
|
+
|
|
95
|
+
/** @type {() => import('../types').EditorDocument} */
|
|
96
|
+
#captureSnapshot
|
|
97
|
+
|
|
98
|
+
/** @type {import('../InlinePluginRegistry').InlinePluginRegistry} */
|
|
99
|
+
#inlinePluginRegistry
|
|
100
|
+
|
|
101
|
+
/** @type {import('../types').InlinePluginContext} */
|
|
102
|
+
#inlinePluginCtx
|
|
103
|
+
|
|
104
|
+
/** @type {(e: Event) => void} */ #onCopy
|
|
105
|
+
/** @type {(e: Event) => void} */ #onCut
|
|
106
|
+
/** @type {(e: Event) => void} */ #onPaste
|
|
107
|
+
/** @type {(e: Event) => void} */ #onKeyDown
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Predicate: returns true when an interactive UI overlay is open.
|
|
111
|
+
* @type {(() => boolean) | null}
|
|
112
|
+
*/
|
|
113
|
+
#isUIActive = null
|
|
114
|
+
|
|
115
|
+
/** @type {Set<{ cancelled: boolean, cleanup(): void }>} */
|
|
116
|
+
#pendingPastes = new Set()
|
|
117
|
+
|
|
118
|
+
/** @type {boolean} */
|
|
119
|
+
#destroyed = false
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @typedef {Object} ClipboardConfig
|
|
123
|
+
* @property {import('../types').IBlockManager} blocks
|
|
124
|
+
* @property {import('../types').ISelectionManager} selection
|
|
125
|
+
* @property {Map<string, import('../types').BlockPlugin>} plugins
|
|
126
|
+
* @property {string} defaultBlockType
|
|
127
|
+
* @property {import('../types').ICrossBlockSelection} crossBlockSelection
|
|
128
|
+
* @property {import('../types').IEventBus} events
|
|
129
|
+
* @property {import('../CommandDispatcher').CommandDispatcher} commands
|
|
130
|
+
* @property {import('../BlockOperations').BlockOperations} blockOps
|
|
131
|
+
* @property {() => import('../types').EditorDocument} captureSnapshot
|
|
132
|
+
* @property {import('../InlinePluginRegistry').InlinePluginRegistry} inlinePluginRegistry
|
|
133
|
+
* @property {import('../types').InlinePluginContext} inlinePluginCtx
|
|
134
|
+
* @property {import('../Diagnostics').Diagnostics} [diagnostics]
|
|
135
|
+
* @property {(() => boolean)} [uiActivePredicate]
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {HTMLElement} rootEl
|
|
140
|
+
* @param {ClipboardConfig} config
|
|
141
|
+
*/
|
|
142
|
+
constructor(rootEl, config) {
|
|
143
|
+
const {
|
|
144
|
+
blocks, selection, plugins, defaultBlockType, crossBlockSelection,
|
|
145
|
+
events, commands, blockOps, captureSnapshot, inlinePluginRegistry,
|
|
146
|
+
inlinePluginCtx, diagnostics, uiActivePredicate,
|
|
147
|
+
} = config
|
|
148
|
+
this.#rootEl = rootEl
|
|
149
|
+
this.#blocks = blocks
|
|
150
|
+
this.#selection = selection
|
|
151
|
+
this.#plugins = plugins
|
|
152
|
+
this.#defaultBlockType = defaultBlockType
|
|
153
|
+
this.#crossBlockSelection = crossBlockSelection
|
|
154
|
+
this.#events = events
|
|
155
|
+
this.#commands = commands
|
|
156
|
+
this.#diagnostics = diagnostics ?? null
|
|
157
|
+
this.#captureSnapshot = captureSnapshot
|
|
158
|
+
this.#inlinePluginRegistry = inlinePluginRegistry
|
|
159
|
+
this.#inlinePluginCtx = inlinePluginCtx
|
|
160
|
+
this.#isUIActive = uiActivePredicate ?? null
|
|
161
|
+
|
|
162
|
+
this.#blockOps = blockOps
|
|
163
|
+
this.#router = new PasteRouter(plugins.values())
|
|
164
|
+
this.#crossEditor = new CrossBlockEditor(
|
|
165
|
+
rootEl, blocks, selection, crossBlockSelection, events, defaultBlockType,
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
this.#onCopy = (e) => this.#handleCopy(/** @type {ClipboardEvent} */ (e))
|
|
169
|
+
this.#onCut = (e) => this.#handleCut(/** @type {ClipboardEvent} */ (e))
|
|
170
|
+
this.#onPaste = (e) => {
|
|
171
|
+
void this.#observePaste(/** @type {ClipboardEvent} */ (e)).catch((err) => {
|
|
172
|
+
console.error('[Clipboard] Failed to paste:', err)
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
this.#onKeyDown = (e) => this.#handleKeyDown(/** @type {KeyboardEvent} */ (e))
|
|
176
|
+
|
|
177
|
+
rootEl.addEventListener('copy', this.#onCopy, true)
|
|
178
|
+
rootEl.addEventListener('cut', this.#onCut, true)
|
|
179
|
+
rootEl.addEventListener('paste', this.#onPaste, true)
|
|
180
|
+
rootEl.addEventListener('keydown', this.#onKeyDown, true)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
destroy() {
|
|
184
|
+
this.#destroyed = true
|
|
185
|
+
this.#rootEl.removeEventListener('copy', this.#onCopy, true)
|
|
186
|
+
this.#rootEl.removeEventListener('cut', this.#onCut, true)
|
|
187
|
+
this.#rootEl.removeEventListener('paste', this.#onPaste, true)
|
|
188
|
+
this.#rootEl.removeEventListener('keydown', this.#onKeyDown, true)
|
|
189
|
+
for (const pending of [...this.#pendingPastes]) {
|
|
190
|
+
pending.cancelled = true
|
|
191
|
+
pending.cleanup()
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ── Keyboard shortcuts (cross-block range) ──────────────────────────────────
|
|
196
|
+
|
|
197
|
+
/** @param {KeyboardEvent} e */
|
|
198
|
+
#handleKeyDown(e) {
|
|
199
|
+
// Skip when interactive UI overlay is open (dropdown, actions panel).
|
|
200
|
+
if (this.#isUIActive?.()) return
|
|
201
|
+
|
|
202
|
+
// Skip events from toolbar UI (inputs, dropdowns) — only handle block content keys.
|
|
203
|
+
const target = /** @type {HTMLElement} */ (e.target)
|
|
204
|
+
if (target !== this.#rootEl && !target.closest?.(BLOCK_SELECTOR)) return
|
|
205
|
+
|
|
206
|
+
const crossRange = this.#crossBlockSelection.range
|
|
207
|
+
if (!crossRange) return
|
|
208
|
+
|
|
209
|
+
if (e.key === 'Backspace' || e.key === 'Delete') {
|
|
210
|
+
e.preventDefault()
|
|
211
|
+
e.stopPropagation()
|
|
212
|
+
this.#crossEditor.setCaretToRangeEnd(crossRange)
|
|
213
|
+
this.#crossEditor.deleteContent(crossRange, (...blocks) => this.#notifyChanged(...blocks))
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!(e.ctrlKey || e.metaKey)) return
|
|
218
|
+
|
|
219
|
+
if (e.code === 'KeyX') {
|
|
220
|
+
if (!copyRange(e, crossRange)) return
|
|
221
|
+
e.stopPropagation()
|
|
222
|
+
this.#crossEditor.setCaretToRangeEnd(crossRange)
|
|
223
|
+
this.#crossEditor.deleteContent(crossRange, (...blocks) => this.#notifyChanged(...blocks))
|
|
224
|
+
} else if (e.code === 'KeyC') {
|
|
225
|
+
if (copyRange(e, crossRange)) e.stopPropagation()
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ── Copy ────────────────────────────────────────────────────────────────────
|
|
230
|
+
|
|
231
|
+
/** @param {ClipboardEvent} e */
|
|
232
|
+
#handleCopy(e) {
|
|
233
|
+
const crossRange = this.#crossBlockSelection.range
|
|
234
|
+
if (crossRange) {
|
|
235
|
+
e.preventDefault()
|
|
236
|
+
const { text, html } = extractRangeContent(crossRange)
|
|
237
|
+
e.clipboardData?.setData('text/plain', text)
|
|
238
|
+
e.clipboardData?.setData('text/html', html)
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const selectedBlocks = this.#blocks.getSelectedBlocks()
|
|
243
|
+
if (selectedBlocks.length > 0) {
|
|
244
|
+
e.preventDefault()
|
|
245
|
+
const canonical = new Map(
|
|
246
|
+
this.#captureSnapshot().blocks.map(block => [block.id, block]),
|
|
247
|
+
)
|
|
248
|
+
const blocksData = selectedBlocks.map(block => canonical.get(block.id) ?? block.save())
|
|
249
|
+
const html = selectedBlocks.map((b) => b.contentElement.innerHTML).join('\n')
|
|
250
|
+
const text = selectedBlocks.map((b) => b.contentElement.textContent).join('\n')
|
|
251
|
+
e.clipboardData?.setData('text/plain', text)
|
|
252
|
+
e.clipboardData?.setData('text/html', html)
|
|
253
|
+
e.clipboardData?.setData(MIME_TYPE, JSON.stringify(blocksData))
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ── Cut ─────────────────────────────────────────────────────────────────────
|
|
259
|
+
|
|
260
|
+
/** @param {ClipboardEvent} e */
|
|
261
|
+
#handleCut(e) {
|
|
262
|
+
this.#handleCopy(e)
|
|
263
|
+
|
|
264
|
+
const blocks = this.#blocks
|
|
265
|
+
const crossRange = this.#crossBlockSelection.range
|
|
266
|
+
if (crossRange) {
|
|
267
|
+
this.#crossEditor.deleteContent(crossRange, (...blocks) => this.#notifyChanged(...blocks))
|
|
268
|
+
return
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (this.#blocks.hasSelectedBlocks()) {
|
|
272
|
+
this.#events.emit(EditorEvent.UNDO_BATCH_START)
|
|
273
|
+
try {
|
|
274
|
+
const result = blocks.removeSelected(this.#defaultBlockType)
|
|
275
|
+
if (result) {
|
|
276
|
+
blocks.setCurrentIndex(result.focusIndex)
|
|
277
|
+
const focusBlock = blocks.getBlockByIndex(result.focusIndex)
|
|
278
|
+
if (focusBlock) {
|
|
279
|
+
focusBlock.focus()
|
|
280
|
+
this.#selection.setCaretToBlock(focusBlock.id, 'start')
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
} finally {
|
|
284
|
+
this.#events.emit(EditorEvent.UNDO_BATCH_END)
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ── Paste ───────────────────────────────────────────────────────────────────
|
|
291
|
+
|
|
292
|
+
/** @param {ClipboardEvent} event */
|
|
293
|
+
async #observePaste(event) {
|
|
294
|
+
const startedAt = this.#diagnostics?.enabled ? this.#diagnostics.now() : 0
|
|
295
|
+
try {
|
|
296
|
+
await this.#handlePaste(event)
|
|
297
|
+
} catch (error) {
|
|
298
|
+
this.#diagnostics?.emit('paste.failed', {
|
|
299
|
+
operation: 'clipboard.paste',
|
|
300
|
+
errorName: this.#diagnostics.errorName(error),
|
|
301
|
+
})
|
|
302
|
+
throw error
|
|
303
|
+
} finally {
|
|
304
|
+
if (startedAt && this.#diagnostics) {
|
|
305
|
+
const durationMs = this.#diagnostics.now() - startedAt
|
|
306
|
+
if (durationMs >= this.#diagnostics.threshold('pasteMs')) {
|
|
307
|
+
this.#diagnostics.emit('paste.slow', { operation: 'clipboard.paste', durationMs })
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** @param {ClipboardEvent} e */
|
|
314
|
+
async #handlePaste(e) {
|
|
315
|
+
const target = /** @type {HTMLElement | null} */ (e.target)
|
|
316
|
+
if (target) {
|
|
317
|
+
// Only handle paste inside content blocks.
|
|
318
|
+
if (!target.closest(BLOCK_SELECTOR)) return
|
|
319
|
+
const closestNonEditable = target.closest('[contenteditable="false"]')
|
|
320
|
+
if (closestNonEditable && closestNonEditable.closest(BLOCK_SELECTOR)) return
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const pasteStartBlock = target
|
|
324
|
+
? this.#blocks.getBlockByChildNode(target)
|
|
325
|
+
: this.#blocks.getCurrentBlock()
|
|
326
|
+
|
|
327
|
+
e.preventDefault()
|
|
328
|
+
|
|
329
|
+
// File uploads are prepared outside the live document. This keeps a slow
|
|
330
|
+
// plugin promise from holding the editor-wide undo batch open while the
|
|
331
|
+
// user continues editing. The completed blocks are committed once.
|
|
332
|
+
const customData = e.clipboardData?.getData(MIME_TYPE)
|
|
333
|
+
const files = Array.from(e.clipboardData?.files ?? [])
|
|
334
|
+
if (!customData && files.length > 0) {
|
|
335
|
+
const crossRange = this.#crossBlockSelection.range?.cloneRange() ?? null
|
|
336
|
+
const selectedIds = crossRange
|
|
337
|
+
? []
|
|
338
|
+
: this.#blocks.getSelectedBlocks().map(block => block.id)
|
|
339
|
+
await this.#pasteFiles(files, {
|
|
340
|
+
crossRange,
|
|
341
|
+
selectedIds,
|
|
342
|
+
anchorBlockId: pasteStartBlock?.id,
|
|
343
|
+
fallbackIndex: this.#blocks.getCurrentIndex() + 1,
|
|
344
|
+
})
|
|
345
|
+
return
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
this.#events.emit(EditorEvent.UNDO_BATCH_START)
|
|
349
|
+
|
|
350
|
+
try {
|
|
351
|
+
// A mouse cross-selection also paints whole blocks as selected for UI
|
|
352
|
+
// purposes, but paste must replace only its text range. Route that case
|
|
353
|
+
// through the range editor before considering whole-block selection.
|
|
354
|
+
const crossRange = this.#crossBlockSelection.range
|
|
355
|
+
let result = null
|
|
356
|
+
if (crossRange) {
|
|
357
|
+
this.#crossEditor.deleteContent(crossRange, (...blocks) => this.#notifyChanged(...blocks))
|
|
358
|
+
} else {
|
|
359
|
+
result = this.#blocks.removeSelected(this.#defaultBlockType)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Determine the insertion point after selection replacement.
|
|
363
|
+
const insertIndex = result ? result.focusIndex : this.#blocks.getCurrentIndex() + 1
|
|
364
|
+
const hadSelection = !!result
|
|
365
|
+
|
|
366
|
+
// ── 1. Internal MIME (block-level paste) ──
|
|
367
|
+
if (customData && this.#pasteCustomMime(customData, insertIndex)) return
|
|
368
|
+
|
|
369
|
+
// ── 3. Plain text URL/pattern matching (before HTML) ──
|
|
370
|
+
const html = e.clipboardData?.getData('text/html')
|
|
371
|
+
const plainText = e.clipboardData?.getData('text/plain') || ''
|
|
372
|
+
|
|
373
|
+
if (plainText && this.#handlePatternPaste(plainText)) return
|
|
374
|
+
|
|
375
|
+
if (hadSelection) {
|
|
376
|
+
this.#ensureCaretBlock(Math.min(insertIndex, this.#blocks.getBlockCount()))
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ── 4. HTML / plain text ──
|
|
380
|
+
this.#pasteContent(html, plainText)
|
|
381
|
+
const pasteEndBlock = this.#blocks.getCurrentBlock()
|
|
382
|
+
this.#events.emit(EditorEvent.PASTE_APPLIED, {
|
|
383
|
+
...(pasteStartBlock ? { startBlockId: pasteStartBlock.id } : {}),
|
|
384
|
+
...(pasteEndBlock ? { endBlockId: pasteEndBlock.id } : {}),
|
|
385
|
+
})
|
|
386
|
+
} finally {
|
|
387
|
+
// Async paste work (for example an image upload) remains one atomic
|
|
388
|
+
// history operation, and errors cannot leave UndoManager batching open.
|
|
389
|
+
this.#events.emit(EditorEvent.UNDO_BATCH_END)
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Paste HTML or plain text content at the current caret position.
|
|
395
|
+
* @param {string} [html]
|
|
396
|
+
* @param {string} [plainText]
|
|
397
|
+
*/
|
|
398
|
+
#pasteContent(html, plainText) {
|
|
399
|
+
const ctx = {
|
|
400
|
+
blocks: this.#blocks,
|
|
401
|
+
selection: this.#selection,
|
|
402
|
+
blockOps: this.#blockOps,
|
|
403
|
+
defaultBlockType: this.#defaultBlockType,
|
|
404
|
+
router: this.#router,
|
|
405
|
+
notifyChanged: (...blocks) => this.#notifyChanged(...blocks),
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (html) {
|
|
409
|
+
pasteHtml(html, ctx)
|
|
410
|
+
} else if (plainText) {
|
|
411
|
+
pastePlainText(plainText, ctx)
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* @param {string} customData
|
|
417
|
+
* @param {number} insertIndex
|
|
418
|
+
*/
|
|
419
|
+
#pasteCustomMime(customData, insertIndex) {
|
|
420
|
+
try {
|
|
421
|
+
/** @type {unknown} */
|
|
422
|
+
const parsed = JSON.parse(customData)
|
|
423
|
+
if (!Array.isArray(parsed) || parsed.length === 0) return false
|
|
424
|
+
|
|
425
|
+
const blocksData = parsed.filter(blockData => (
|
|
426
|
+
blockData
|
|
427
|
+
&& typeof blockData === 'object'
|
|
428
|
+
&& typeof blockData.type === 'string'
|
|
429
|
+
&& blockData.data
|
|
430
|
+
&& typeof blockData.data === 'object'
|
|
431
|
+
))
|
|
432
|
+
if (blocksData.length === 0) return false
|
|
433
|
+
|
|
434
|
+
for (const blockData of blocksData) {
|
|
435
|
+
const type = this.#plugins.has(blockData.type) ? blockData.type : this.#defaultBlockType
|
|
436
|
+
const inline = blockData.inline && typeof blockData.inline === 'object'
|
|
437
|
+
? blockData.inline
|
|
438
|
+
: undefined
|
|
439
|
+
const inserted = this.#blocks.insert(type, blockData.data, insertIndex, undefined, inline)
|
|
440
|
+
hydrateInlinePlugins(inserted.contentElement, this.#inlinePluginRegistry, this.#inlinePluginCtx)
|
|
441
|
+
insertIndex++
|
|
442
|
+
}
|
|
443
|
+
// Focus the last inserted block once (avoid intermediate focus shifts).
|
|
444
|
+
const lastInserted = this.#blocks.getBlockByIndex(insertIndex - 1)
|
|
445
|
+
if (lastInserted) {
|
|
446
|
+
this.#blocks.setCurrentIndex(insertIndex - 1)
|
|
447
|
+
this.#selection.setCaretToBlock(lastInserted.id, 'end')
|
|
448
|
+
lastInserted.focus()
|
|
449
|
+
}
|
|
450
|
+
return true
|
|
451
|
+
} catch (err) {
|
|
452
|
+
console.error('[Clipboard] Failed to parse custom data:', err)
|
|
453
|
+
return false
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Prepare uploads outside the model, then commit every successful file as
|
|
459
|
+
* one synchronous history operation.
|
|
460
|
+
* @param {File[]} files
|
|
461
|
+
* @param {{ crossRange: Range | null, selectedIds: string[], anchorBlockId?: string, fallbackIndex: number }} target
|
|
462
|
+
*/
|
|
463
|
+
async #pasteFiles(files, target) {
|
|
464
|
+
const pendingHost = document.createElement('div')
|
|
465
|
+
pendingHost.className = 'oe-pending-pastes'
|
|
466
|
+
pendingHost.setAttribute('aria-live', 'polite')
|
|
467
|
+
|
|
468
|
+
const anchor = target.anchorBlockId
|
|
469
|
+
? this.#blocks.getBlockById(target.anchorBlockId)
|
|
470
|
+
: this.#blocks.getCurrentBlock()
|
|
471
|
+
if (anchor?.element.parentNode) anchor.element.after(pendingHost)
|
|
472
|
+
|
|
473
|
+
const prepared = (await Promise.all(
|
|
474
|
+
files.map(file => this.#prepareFilePaste(file, pendingHost)),
|
|
475
|
+
)).filter(Boolean)
|
|
476
|
+
pendingHost.remove()
|
|
477
|
+
|
|
478
|
+
if (this.#destroyed || prepared.length === 0) return
|
|
479
|
+
|
|
480
|
+
this.#events.emit(EditorEvent.UNDO_BATCH_START)
|
|
481
|
+
try {
|
|
482
|
+
let result = null
|
|
483
|
+
if (target.crossRange
|
|
484
|
+
&& this.#rootEl.contains(target.crossRange.startContainer)
|
|
485
|
+
&& this.#rootEl.contains(target.crossRange.endContainer)) {
|
|
486
|
+
this.#crossEditor.deleteContent(target.crossRange, (...blocks) => this.#notifyChanged(...blocks))
|
|
487
|
+
} else if (target.selectedIds.length > 0) {
|
|
488
|
+
const selected = new Set(target.selectedIds)
|
|
489
|
+
this.#blocks.clearSelection()
|
|
490
|
+
for (const block of this.#blocks) block.selected = selected.has(block.id)
|
|
491
|
+
result = this.#blocks.removeSelected(this.#defaultBlockType)
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
let insertIndex
|
|
495
|
+
if (result) {
|
|
496
|
+
insertIndex = result.focusIndex
|
|
497
|
+
} else {
|
|
498
|
+
const liveAnchorIndex = target.anchorBlockId
|
|
499
|
+
? this.#blocks.getBlockIndex(target.anchorBlockId)
|
|
500
|
+
: -1
|
|
501
|
+
insertIndex = liveAnchorIndex >= 0
|
|
502
|
+
? liveAnchorIndex + 1
|
|
503
|
+
: Math.min(target.fallbackIndex, this.#blocks.getBlockCount())
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const current = target.anchorBlockId
|
|
507
|
+
? this.#blocks.getBlockById(target.anchorBlockId)
|
|
508
|
+
: null
|
|
509
|
+
let replaceEmpty = prepared.length === 1
|
|
510
|
+
&& current?.isEmpty()
|
|
511
|
+
&& current.type === this.#defaultBlockType
|
|
512
|
+
if (replaceEmpty) insertIndex = this.#blocks.getBlockIndex(current.id)
|
|
513
|
+
|
|
514
|
+
for (const entry of prepared) {
|
|
515
|
+
const inserted = this.#blocks.insert(entry.type, entry.data, insertIndex)
|
|
516
|
+
hydrateInlinePlugins(inserted.contentElement, this.#inlinePluginRegistry, this.#inlinePluginCtx)
|
|
517
|
+
if (replaceEmpty) {
|
|
518
|
+
this.#blocks.remove(insertIndex + 1)
|
|
519
|
+
replaceEmpty = false
|
|
520
|
+
}
|
|
521
|
+
insertIndex++
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const lastInserted = this.#blocks.getBlockByIndex(insertIndex - 1)
|
|
525
|
+
if (lastInserted) {
|
|
526
|
+
this.#blocks.setCurrentIndex(insertIndex - 1)
|
|
527
|
+
lastInserted.focus()
|
|
528
|
+
} else {
|
|
529
|
+
this.#rootEl.focus()
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
this.#events.emit(EditorEvent.PASTE_APPLIED, {
|
|
533
|
+
...(target.anchorBlockId ? { startBlockId: target.anchorBlockId } : {}),
|
|
534
|
+
...(lastInserted ? { endBlockId: lastInserted.id } : {}),
|
|
535
|
+
})
|
|
536
|
+
} finally {
|
|
537
|
+
this.#events.emit(EditorEvent.UNDO_BATCH_END)
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* @param {File} file
|
|
543
|
+
* @param {HTMLElement} pendingHost
|
|
544
|
+
* @returns {Promise<{ type: string, data: Record<string, unknown> } | null>}
|
|
545
|
+
*/
|
|
546
|
+
async #prepareFilePaste(file, pendingHost) {
|
|
547
|
+
const plugin = this.#router.findByFile(file.type)
|
|
548
|
+
if (!plugin?.onPaste) return null
|
|
549
|
+
|
|
550
|
+
let element
|
|
551
|
+
let shell
|
|
552
|
+
/** @type {{ cancelled: boolean, cleanup(): void } | null} */
|
|
553
|
+
let pending = null
|
|
554
|
+
try {
|
|
555
|
+
const initialData = plugin.onPaste({ type: 'file', file })
|
|
556
|
+
if (!initialData) return null
|
|
557
|
+
|
|
558
|
+
element = plugin.render(initialData, {
|
|
559
|
+
mutate: (operation) => operation(),
|
|
560
|
+
splitBlock: () => {},
|
|
561
|
+
exitEmptyBlock: () => false,
|
|
562
|
+
readOnly: false,
|
|
563
|
+
})
|
|
564
|
+
if (!(element instanceof HTMLElement)) {
|
|
565
|
+
console.error(`[Clipboard] File paste plugin "${plugin.type}" did not return an HTMLElement`)
|
|
566
|
+
return null
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
shell = document.createElement('div')
|
|
570
|
+
shell.className = 'oe-block oe-block--pending-paste'
|
|
571
|
+
shell.dataset.blockType = plugin.type
|
|
572
|
+
shell.appendChild(element)
|
|
573
|
+
pendingHost.appendChild(shell)
|
|
574
|
+
|
|
575
|
+
let cleaned = false
|
|
576
|
+
pending = {
|
|
577
|
+
cancelled: false,
|
|
578
|
+
cleanup: () => {
|
|
579
|
+
if (cleaned) return
|
|
580
|
+
cleaned = true
|
|
581
|
+
try { plugin.destroy?.(element) } catch (error) {
|
|
582
|
+
console.warn(`[Clipboard] Failed to destroy pending "${plugin.type}" paste:`, error)
|
|
583
|
+
}
|
|
584
|
+
shell?.remove()
|
|
585
|
+
this.#pendingPastes.delete(pending)
|
|
586
|
+
},
|
|
587
|
+
}
|
|
588
|
+
this.#pendingPastes.add(pending)
|
|
589
|
+
|
|
590
|
+
await plugin.waitForPaste?.(element)
|
|
591
|
+
if (this.#destroyed || pending.cancelled) return null
|
|
592
|
+
|
|
593
|
+
const saved = plugin.save(element)
|
|
594
|
+
if (!saved || typeof saved !== 'object' || Array.isArray(saved)) {
|
|
595
|
+
console.error(`[Clipboard] File paste plugin "${plugin.type}" returned invalid data`)
|
|
596
|
+
return null
|
|
597
|
+
}
|
|
598
|
+
if (plugin.validate && !plugin.validate(saved)) return null
|
|
599
|
+
return { type: plugin.type, data: cloneEditorData(saved) }
|
|
600
|
+
} catch (error) {
|
|
601
|
+
console.error(`[Clipboard] Failed to prepare file paste with "${plugin.type}":`, error)
|
|
602
|
+
return null
|
|
603
|
+
} finally {
|
|
604
|
+
pending?.cleanup()
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* @param {string} text
|
|
610
|
+
* @returns {boolean}
|
|
611
|
+
*/
|
|
612
|
+
#handlePatternPaste(text) {
|
|
613
|
+
const plugin = this.#router.findByPattern(text)
|
|
614
|
+
if (!plugin?.onPaste) return false
|
|
615
|
+
const data = plugin.onPaste({ type: 'pattern', data: text })
|
|
616
|
+
if (!data) return false
|
|
617
|
+
|
|
618
|
+
this.#blockOps.replaceEmptyOrInsert(plugin.type, data)
|
|
619
|
+
return true
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
623
|
+
|
|
624
|
+
/** @param {number} index */
|
|
625
|
+
#ensureCaretBlock(index) {
|
|
626
|
+
const newBlock = this.#blocks.insert(this.#defaultBlockType, undefined, index)
|
|
627
|
+
const newIdx = this.#blocks.getBlockIndex(newBlock.id)
|
|
628
|
+
this.#blocks.setCurrentIndex(newIdx)
|
|
629
|
+
|
|
630
|
+
newBlock.focus()
|
|
631
|
+
const sel = window.getSelection()
|
|
632
|
+
if (sel) {
|
|
633
|
+
const range = document.createRange()
|
|
634
|
+
range.setStart(newBlock.contentElement, 0)
|
|
635
|
+
range.collapse(true)
|
|
636
|
+
sel.removeAllRanges()
|
|
637
|
+
sel.addRange(range)
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Invalidate every existing block mutated directly by a paste operation.
|
|
643
|
+
* With no explicit targets, preserve the legacy current-block fallback for
|
|
644
|
+
* cross-block editor callbacks that already position current precisely.
|
|
645
|
+
* @param {...import('../types').IBlock} affected
|
|
646
|
+
*/
|
|
647
|
+
#notifyChanged(...affected) {
|
|
648
|
+
const targets = affected.length > 0
|
|
649
|
+
? affected
|
|
650
|
+
: [this.#blocks.getCurrentBlock()].filter(Boolean)
|
|
651
|
+
this.#commands.commitExternalMany(targets)
|
|
652
|
+
}
|
|
653
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operations on cross-block selections (text spanning multiple blocks).
|
|
3
|
+
*
|
|
4
|
+
* Cross-block selection is held in `ICrossBlockSelection` (a custom range
|
|
5
|
+
* since the native browser API can't span editing hosts). This class
|
|
6
|
+
* encapsulates the multi-step delete sequence:
|
|
7
|
+
*
|
|
8
|
+
* 1. Delete tail of last block (from rangeEnd → end of CE).
|
|
9
|
+
* 2. Remove all middle blocks.
|
|
10
|
+
* 3. Delete head of first block (from start of CE → rangeStart).
|
|
11
|
+
* 4. Merge first + last (first block keeps the merged content).
|
|
12
|
+
* 5. Restore caret at the merge boundary.
|
|
13
|
+
*
|
|
14
|
+
* Wrapped in an UNDO_BATCH so the whole operation is one undo step.
|
|
15
|
+
*/
|
|
16
|
+
export class CrossBlockEditor {
|
|
17
|
+
/**
|
|
18
|
+
* @param {HTMLElement} rootEl
|
|
19
|
+
* @param {import('../types.js').IBlockManager} blocks
|
|
20
|
+
* @param {import('../types.js').ISelectionManager} selection
|
|
21
|
+
* @param {import('../types.js').ICrossBlockSelection} crossBlockSelection
|
|
22
|
+
* @param {import('../types.js').IEventBus} events
|
|
23
|
+
* @param {string} defaultBlockType
|
|
24
|
+
*/
|
|
25
|
+
constructor(rootEl: HTMLElement, blocks: import("../types.js").IBlockManager, selection: import("../types.js").ISelectionManager, crossBlockSelection: import("../types.js").ICrossBlockSelection, events: import("../types.js").IEventBus, defaultBlockType: string);
|
|
26
|
+
/**
|
|
27
|
+
* Place the native caret at the end of a cross-block range.
|
|
28
|
+
* Required so UndoManager captures the correct caret position when
|
|
29
|
+
* the next snapshot is taken.
|
|
30
|
+
*
|
|
31
|
+
* @param {Range} range
|
|
32
|
+
*/
|
|
33
|
+
setCaretToRangeEnd(range: Range): void;
|
|
34
|
+
/**
|
|
35
|
+
* Delete the content covered by a cross-block range and merge the
|
|
36
|
+
* surviving head + tail into the first block.
|
|
37
|
+
*
|
|
38
|
+
* @param {Range} crossRange
|
|
39
|
+
* @param {(...blocks: import('../types.js').IBlock[]) => void} notifyChanged
|
|
40
|
+
*/
|
|
41
|
+
deleteContent(crossRange: Range, notifyChanged: (...blocks: import("../types.js").IBlock[]) => void): void;
|
|
42
|
+
#private;
|
|
43
|
+
}
|