@atlaskit/editor-plugin-media 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/commands/captions.js +59 -0
- package/dist/cjs/commands/helpers.js +127 -0
- package/dist/cjs/commands/index.js +24 -0
- package/dist/cjs/commands/linking.js +181 -0
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/media-plugin-options.js +5 -0
- package/dist/cjs/next-plugin-type.js +5 -0
- package/dist/cjs/nodeviews/mediaGroup.js +376 -0
- package/dist/cjs/nodeviews/mediaInline.js +288 -0
- package/dist/cjs/nodeviews/mediaNodeUpdater.js +739 -0
- package/dist/cjs/nodeviews/mediaNodeView/index.js +177 -0
- package/dist/cjs/nodeviews/mediaNodeView/media.js +242 -0
- package/dist/cjs/nodeviews/mediaSingle.js +629 -0
- package/dist/cjs/nodeviews/messages.js +14 -0
- package/dist/cjs/nodeviews/styles.js +46 -0
- package/dist/cjs/nodeviews/types.js +5 -0
- package/dist/cjs/picker-facade.js +192 -0
- package/dist/cjs/plugin.js +293 -0
- package/dist/cjs/pm-plugins/alt-text/actions.js +5 -0
- package/dist/cjs/pm-plugins/alt-text/commands.js +59 -0
- package/dist/cjs/pm-plugins/alt-text/index.js +36 -0
- package/dist/cjs/pm-plugins/alt-text/keymap.js +15 -0
- package/dist/cjs/pm-plugins/alt-text/messages.js +44 -0
- package/dist/cjs/pm-plugins/alt-text/reducer.js +32 -0
- package/dist/cjs/pm-plugins/alt-text/types.js +5 -0
- package/dist/cjs/pm-plugins/alt-text/ui/AltTextEdit.js +209 -0
- package/dist/cjs/pm-plugins/keymap-media-single.js +163 -0
- package/dist/cjs/pm-plugins/keymap.js +88 -0
- package/dist/cjs/pm-plugins/linking/actions.js +13 -0
- package/dist/cjs/pm-plugins/linking/index.js +65 -0
- package/dist/cjs/pm-plugins/linking/keymap.js +14 -0
- package/dist/cjs/pm-plugins/linking/reducer.js +43 -0
- package/dist/cjs/pm-plugins/linking/types.js +5 -0
- package/dist/cjs/pm-plugins/main.js +813 -0
- package/dist/cjs/pm-plugins/media-editor-plugin-factory.js +8 -0
- package/dist/cjs/pm-plugins/mediaTaskManager.js +101 -0
- package/dist/cjs/pm-plugins/plugin-key.js +8 -0
- package/dist/cjs/pm-plugins/types.js +5 -0
- package/dist/cjs/toolbar/alt-text.js +80 -0
- package/dist/cjs/toolbar/commands.js +236 -0
- package/dist/cjs/toolbar/filePreviewItem.js +66 -0
- package/dist/cjs/toolbar/imageBorder.js +20 -0
- package/dist/cjs/toolbar/index.js +523 -0
- package/dist/cjs/toolbar/linking-toolbar-appearance.js +100 -0
- package/dist/cjs/toolbar/linking.js +96 -0
- package/dist/cjs/toolbar/utils.js +110 -0
- package/dist/cjs/ui/CaptionPlaceholder/index.js +27 -0
- package/dist/cjs/ui/CaptionPlaceholder/messages.js +14 -0
- package/dist/cjs/ui/ImageBorder/index.js +226 -0
- package/dist/cjs/ui/ImageBorder/messages.js +49 -0
- package/dist/cjs/ui/ImageBorder/styles.js +52 -0
- package/dist/cjs/ui/Media/DropPlaceholder.js +38 -0
- package/dist/cjs/ui/Media/drop-placeholder-messages.js +14 -0
- package/dist/cjs/ui/MediaLinkingToolbar.js +196 -0
- package/dist/cjs/ui/MediaPicker/BrowserWrapper.js +40 -0
- package/dist/cjs/ui/MediaPicker/ClipboardWrapper.js +39 -0
- package/dist/cjs/ui/MediaPicker/DropzoneWrapper.js +51 -0
- package/dist/cjs/ui/MediaPicker/PickerFacadeProvider.js +151 -0
- package/dist/cjs/ui/MediaPicker/index.js +103 -0
- package/dist/cjs/ui/PixelEntry/constants.js +7 -0
- package/dist/cjs/ui/PixelEntry/index.js +185 -0
- package/dist/cjs/ui/PixelEntry/messages.js +54 -0
- package/dist/cjs/ui/PixelEntry/styles.js +19 -0
- package/dist/cjs/ui/PixelEntry/types.js +5 -0
- package/dist/cjs/ui/ResizableMediaSingle/ResizableMediaMigrationNotification.js +16 -0
- package/dist/cjs/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +541 -0
- package/dist/cjs/ui/ResizableMediaSingle/index.js +422 -0
- package/dist/cjs/ui/ResizableMediaSingle/styled.js +14 -0
- package/dist/cjs/ui/ResizableMediaSingle/styles.js +17 -0
- package/dist/cjs/ui/ResizableMediaSingle/types.js +5 -0
- package/dist/cjs/ui/ToolbarMedia/index.js +42 -0
- package/dist/cjs/ui/ToolbarMedia/toolbar-media-messages.js +14 -0
- package/dist/cjs/ui/media-linking-toolbar-messages.js +14 -0
- package/dist/cjs/utils/analytics.js +53 -0
- package/dist/cjs/utils/check-media-type.js +56 -0
- package/dist/cjs/utils/current-media-node.js +41 -0
- package/dist/cjs/utils/is-image.js +9 -0
- package/dist/cjs/utils/media-common.js +181 -0
- package/dist/cjs/utils/media-files.js +297 -0
- package/dist/cjs/utils/media-single.js +181 -0
- package/dist/es2019/commands/captions.js +47 -0
- package/dist/es2019/commands/helpers.js +113 -0
- package/dist/es2019/commands/index.js +1 -0
- package/dist/es2019/commands/linking.js +169 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/media-plugin-options.js +1 -0
- package/dist/es2019/next-plugin-type.js +1 -0
- package/dist/es2019/nodeviews/mediaGroup.js +314 -0
- package/dist/es2019/nodeviews/mediaInline.js +201 -0
- package/dist/es2019/nodeviews/mediaNodeUpdater.js +384 -0
- package/dist/es2019/nodeviews/mediaNodeView/index.js +149 -0
- package/dist/es2019/nodeviews/mediaNodeView/media.js +182 -0
- package/dist/es2019/nodeviews/mediaSingle.js +511 -0
- package/dist/es2019/nodeviews/messages.js +8 -0
- package/dist/es2019/nodeviews/styles.js +46 -0
- package/dist/es2019/nodeviews/types.js +1 -0
- package/dist/es2019/picker-facade.js +146 -0
- package/dist/es2019/plugin.js +284 -0
- package/dist/es2019/pm-plugins/alt-text/actions.js +1 -0
- package/dist/es2019/pm-plugins/alt-text/commands.js +42 -0
- package/dist/es2019/pm-plugins/alt-text/index.js +33 -0
- package/dist/es2019/pm-plugins/alt-text/keymap.js +9 -0
- package/dist/es2019/pm-plugins/alt-text/messages.js +38 -0
- package/dist/es2019/pm-plugins/alt-text/reducer.js +26 -0
- package/dist/es2019/pm-plugins/alt-text/types.js +1 -0
- package/dist/es2019/pm-plugins/alt-text/ui/AltTextEdit.js +228 -0
- package/dist/es2019/pm-plugins/keymap-media-single.js +172 -0
- package/dist/es2019/pm-plugins/keymap.js +84 -0
- package/dist/es2019/pm-plugins/linking/actions.js +7 -0
- package/dist/es2019/pm-plugins/linking/index.js +56 -0
- package/dist/es2019/pm-plugins/linking/keymap.js +8 -0
- package/dist/es2019/pm-plugins/linking/reducer.js +37 -0
- package/dist/es2019/pm-plugins/linking/types.js +1 -0
- package/dist/es2019/pm-plugins/main.js +695 -0
- package/dist/es2019/pm-plugins/media-editor-plugin-factory.js +2 -0
- package/dist/es2019/pm-plugins/mediaTaskManager.js +64 -0
- package/dist/es2019/pm-plugins/plugin-key.js +2 -0
- package/dist/es2019/pm-plugins/types.js +1 -0
- package/dist/es2019/toolbar/alt-text.js +72 -0
- package/dist/es2019/toolbar/commands.js +212 -0
- package/dist/es2019/toolbar/filePreviewItem.js +54 -0
- package/dist/es2019/toolbar/imageBorder.js +15 -0
- package/dist/es2019/toolbar/index.js +538 -0
- package/dist/es2019/toolbar/linking-toolbar-appearance.js +90 -0
- package/dist/es2019/toolbar/linking.js +98 -0
- package/dist/es2019/toolbar/utils.js +86 -0
- package/dist/es2019/ui/CaptionPlaceholder/index.js +25 -0
- package/dist/es2019/ui/CaptionPlaceholder/messages.js +8 -0
- package/dist/es2019/ui/ImageBorder/index.js +213 -0
- package/dist/es2019/ui/ImageBorder/messages.js +43 -0
- package/dist/es2019/ui/ImageBorder/styles.js +126 -0
- package/dist/es2019/ui/Media/DropPlaceholder.js +47 -0
- package/dist/es2019/ui/Media/drop-placeholder-messages.js +8 -0
- package/dist/es2019/ui/MediaLinkingToolbar.js +190 -0
- package/dist/es2019/ui/MediaPicker/BrowserWrapper.js +31 -0
- package/dist/es2019/ui/MediaPicker/ClipboardWrapper.js +32 -0
- package/dist/es2019/ui/MediaPicker/DropzoneWrapper.js +42 -0
- package/dist/es2019/ui/MediaPicker/PickerFacadeProvider.js +85 -0
- package/dist/es2019/ui/MediaPicker/index.js +82 -0
- package/dist/es2019/ui/PixelEntry/constants.js +1 -0
- package/dist/es2019/ui/PixelEntry/index.js +170 -0
- package/dist/es2019/ui/PixelEntry/messages.js +48 -0
- package/dist/es2019/ui/PixelEntry/styles.js +51 -0
- package/dist/es2019/ui/PixelEntry/types.js +1 -0
- package/dist/es2019/ui/ResizableMediaSingle/ResizableMediaMigrationNotification.js +9 -0
- package/dist/es2019/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +454 -0
- package/dist/es2019/ui/ResizableMediaSingle/index.js +344 -0
- package/dist/es2019/ui/ResizableMediaSingle/styled.js +9 -0
- package/dist/es2019/ui/ResizableMediaSingle/styles.js +14 -0
- package/dist/es2019/ui/ResizableMediaSingle/types.js +1 -0
- package/dist/es2019/ui/ToolbarMedia/index.js +37 -0
- package/dist/es2019/ui/ToolbarMedia/toolbar-media-messages.js +8 -0
- package/dist/es2019/ui/media-linking-toolbar-messages.js +8 -0
- package/dist/es2019/utils/analytics.js +51 -0
- package/dist/es2019/utils/check-media-type.js +19 -0
- package/dist/es2019/utils/current-media-node.js +35 -0
- package/dist/es2019/utils/is-image.js +3 -0
- package/dist/es2019/utils/media-common.js +189 -0
- package/dist/es2019/utils/media-files.js +321 -0
- package/dist/es2019/utils/media-single.js +176 -0
- package/dist/esm/commands/captions.js +53 -0
- package/dist/esm/commands/helpers.js +120 -0
- package/dist/esm/commands/index.js +1 -0
- package/dist/esm/commands/linking.js +174 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/media-plugin-options.js +1 -0
- package/dist/esm/next-plugin-type.js +1 -0
- package/dist/esm/nodeviews/mediaGroup.js +369 -0
- package/dist/esm/nodeviews/mediaInline.js +278 -0
- package/dist/esm/nodeviews/mediaNodeUpdater.js +732 -0
- package/dist/esm/nodeviews/mediaNodeView/index.js +170 -0
- package/dist/esm/nodeviews/mediaNodeView/media.js +233 -0
- package/dist/esm/nodeviews/mediaSingle.js +622 -0
- package/dist/esm/nodeviews/messages.js +8 -0
- package/dist/esm/nodeviews/styles.js +39 -0
- package/dist/esm/nodeviews/types.js +1 -0
- package/dist/esm/picker-facade.js +186 -0
- package/dist/esm/plugin.js +282 -0
- package/dist/esm/pm-plugins/alt-text/actions.js +1 -0
- package/dist/esm/pm-plugins/alt-text/commands.js +52 -0
- package/dist/esm/pm-plugins/alt-text/index.js +31 -0
- package/dist/esm/pm-plugins/alt-text/keymap.js +9 -0
- package/dist/esm/pm-plugins/alt-text/messages.js +38 -0
- package/dist/esm/pm-plugins/alt-text/reducer.js +25 -0
- package/dist/esm/pm-plugins/alt-text/types.js +1 -0
- package/dist/esm/pm-plugins/alt-text/ui/AltTextEdit.js +206 -0
- package/dist/esm/pm-plugins/keymap-media-single.js +158 -0
- package/dist/esm/pm-plugins/keymap.js +81 -0
- package/dist/esm/pm-plugins/linking/actions.js +7 -0
- package/dist/esm/pm-plugins/linking/index.js +59 -0
- package/dist/esm/pm-plugins/linking/keymap.js +8 -0
- package/dist/esm/pm-plugins/linking/reducer.js +36 -0
- package/dist/esm/pm-plugins/linking/types.js +1 -0
- package/dist/esm/pm-plugins/main.js +798 -0
- package/dist/esm/pm-plugins/media-editor-plugin-factory.js +2 -0
- package/dist/esm/pm-plugins/mediaTaskManager.js +94 -0
- package/dist/esm/pm-plugins/plugin-key.js +2 -0
- package/dist/esm/pm-plugins/types.js +1 -0
- package/dist/esm/toolbar/alt-text.js +70 -0
- package/dist/esm/toolbar/commands.js +229 -0
- package/dist/esm/toolbar/filePreviewItem.js +56 -0
- package/dist/esm/toolbar/imageBorder.js +14 -0
- package/dist/esm/toolbar/index.js +513 -0
- package/dist/esm/toolbar/linking-toolbar-appearance.js +91 -0
- package/dist/esm/toolbar/linking.js +88 -0
- package/dist/esm/toolbar/utils.js +103 -0
- package/dist/esm/ui/CaptionPlaceholder/index.js +20 -0
- package/dist/esm/ui/CaptionPlaceholder/messages.js +8 -0
- package/dist/esm/ui/ImageBorder/index.js +218 -0
- package/dist/esm/ui/ImageBorder/messages.js +43 -0
- package/dist/esm/ui/ImageBorder/styles.js +42 -0
- package/dist/esm/ui/Media/DropPlaceholder.js +31 -0
- package/dist/esm/ui/Media/drop-placeholder-messages.js +8 -0
- package/dist/esm/ui/MediaLinkingToolbar.js +188 -0
- package/dist/esm/ui/MediaPicker/BrowserWrapper.js +33 -0
- package/dist/esm/ui/MediaPicker/ClipboardWrapper.js +32 -0
- package/dist/esm/ui/MediaPicker/DropzoneWrapper.js +44 -0
- package/dist/esm/ui/MediaPicker/PickerFacadeProvider.js +145 -0
- package/dist/esm/ui/MediaPicker/index.js +96 -0
- package/dist/esm/ui/PixelEntry/constants.js +1 -0
- package/dist/esm/ui/PixelEntry/index.js +174 -0
- package/dist/esm/ui/PixelEntry/messages.js +48 -0
- package/dist/esm/ui/PixelEntry/styles.js +12 -0
- package/dist/esm/ui/PixelEntry/types.js +1 -0
- package/dist/esm/ui/ResizableMediaSingle/ResizableMediaMigrationNotification.js +9 -0
- package/dist/esm/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +535 -0
- package/dist/esm/ui/ResizableMediaSingle/index.js +417 -0
- package/dist/esm/ui/ResizableMediaSingle/styled.js +7 -0
- package/dist/esm/ui/ResizableMediaSingle/styles.js +7 -0
- package/dist/esm/ui/ResizableMediaSingle/types.js +1 -0
- package/dist/esm/ui/ToolbarMedia/index.js +35 -0
- package/dist/esm/ui/ToolbarMedia/toolbar-media-messages.js +8 -0
- package/dist/esm/ui/media-linking-toolbar-messages.js +8 -0
- package/dist/esm/utils/analytics.js +47 -0
- package/dist/esm/utils/check-media-type.js +49 -0
- package/dist/esm/utils/current-media-node.js +35 -0
- package/dist/esm/utils/is-image.js +3 -0
- package/dist/esm/utils/media-common.js +175 -0
- package/dist/esm/utils/media-files.js +291 -0
- package/dist/esm/utils/media-single.js +172 -0
- package/dist/types/commands/captions.d.ts +5 -0
- package/dist/types/commands/helpers.d.ts +15 -0
- package/dist/types/commands/index.d.ts +1 -0
- package/dist/types/commands/linking.d.ts +9 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/media-plugin-options.d.ts +17 -0
- package/dist/types/next-plugin-type.d.ts +33 -0
- package/dist/types/nodeviews/__mocks__/mediaNodeUpdater.d.ts +24 -0
- package/dist/types/nodeviews/mediaGroup.d.ts +33 -0
- package/dist/types/nodeviews/mediaInline.d.ts +50 -0
- package/dist/types/nodeviews/mediaNodeUpdater.d.ts +45 -0
- package/dist/types/nodeviews/mediaNodeView/index.d.ts +28 -0
- package/dist/types/nodeviews/mediaNodeView/media.d.ts +44 -0
- package/dist/types/nodeviews/mediaSingle.d.ts +62 -0
- package/dist/types/nodeviews/messages.d.ts +7 -0
- package/dist/types/nodeviews/styles.d.ts +16 -0
- package/dist/types/nodeviews/types.d.ts +42 -0
- package/dist/types/picker-facade.d.ts +44 -0
- package/dist/types/plugin.d.ts +7 -0
- package/dist/types/pm-plugins/alt-text/actions.d.ts +10 -0
- package/dist/types/pm-plugins/alt-text/commands.d.ts +4 -0
- package/dist/types/pm-plugins/alt-text/index.d.ts +7 -0
- package/dist/types/pm-plugins/alt-text/keymap.d.ts +4 -0
- package/dist/types/pm-plugins/alt-text/messages.d.ts +37 -0
- package/dist/types/pm-plugins/alt-text/reducer.d.ts +4 -0
- package/dist/types/pm-plugins/alt-text/types.d.ts +3 -0
- package/dist/types/pm-plugins/alt-text/ui/AltTextEdit.d.ts +41 -0
- package/dist/types/pm-plugins/keymap-media-single.d.ts +3 -0
- package/dist/types/pm-plugins/keymap.d.ts +6 -0
- package/dist/types/pm-plugins/linking/actions.d.ts +20 -0
- package/dist/types/pm-plugins/linking/index.d.ts +10 -0
- package/dist/types/pm-plugins/linking/keymap.d.ts +3 -0
- package/dist/types/pm-plugins/linking/reducer.d.ts +4 -0
- package/dist/types/pm-plugins/linking/types.d.ts +12 -0
- package/dist/types/pm-plugins/main.d.ts +120 -0
- package/dist/types/pm-plugins/media-editor-plugin-factory.d.ts +3 -0
- package/dist/types/pm-plugins/mediaTaskManager.d.ts +9 -0
- package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types/pm-plugins/types.d.ts +65 -0
- package/dist/types/toolbar/alt-text.d.ts +13 -0
- package/dist/types/toolbar/commands.d.ts +12 -0
- package/dist/types/toolbar/filePreviewItem.d.ts +9 -0
- package/dist/types/toolbar/imageBorder.d.ts +2 -0
- package/dist/types/toolbar/index.d.ts +6 -0
- package/dist/types/toolbar/linking-toolbar-appearance.d.ts +14 -0
- package/dist/types/toolbar/linking.d.ts +10 -0
- package/dist/types/toolbar/utils.d.ts +11 -0
- package/dist/types/types.d.ts +2 -1
- package/dist/types/ui/CaptionPlaceholder/index.d.ts +6 -0
- package/dist/types/ui/CaptionPlaceholder/messages.d.ts +7 -0
- package/dist/types/ui/ImageBorder/index.d.ts +11 -0
- package/dist/types/ui/ImageBorder/messages.d.ts +42 -0
- package/dist/types/ui/ImageBorder/styles.d.ts +15 -0
- package/dist/types/ui/Media/DropPlaceholder.d.ts +8 -0
- package/dist/types/ui/Media/drop-placeholder-messages.d.ts +7 -0
- package/dist/types/ui/MediaLinkingToolbar.d.ts +35 -0
- package/dist/types/ui/MediaPicker/BrowserWrapper.d.ts +11 -0
- package/dist/types/ui/MediaPicker/ClipboardWrapper.d.ts +10 -0
- package/dist/types/ui/MediaPicker/DropzoneWrapper.d.ts +13 -0
- package/dist/types/ui/MediaPicker/PickerFacadeProvider.d.ts +28 -0
- package/dist/types/ui/MediaPicker/index.d.ts +23 -0
- package/dist/types/ui/PixelEntry/constants.d.ts +1 -0
- package/dist/types/ui/PixelEntry/index.d.ts +8 -0
- package/dist/types/ui/PixelEntry/messages.d.ts +47 -0
- package/dist/types/ui/PixelEntry/styles.d.ts +8 -0
- package/dist/types/ui/PixelEntry/types.d.ts +58 -0
- package/dist/types/ui/ResizableMediaSingle/ResizableMediaMigrationNotification.d.ts +3 -0
- package/dist/types/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +59 -0
- package/dist/types/ui/ResizableMediaSingle/index.d.ts +45 -0
- package/dist/types/ui/ResizableMediaSingle/styled.d.ts +2 -0
- package/dist/types/ui/ResizableMediaSingle/styles.d.ts +1 -0
- package/dist/types/ui/ResizableMediaSingle/types.d.ts +27 -0
- package/dist/types/ui/ToolbarMedia/index.d.ts +13 -0
- package/dist/types/ui/ToolbarMedia/toolbar-media-messages.d.ts +7 -0
- package/dist/types/ui/media-linking-toolbar-messages.d.ts +7 -0
- package/dist/types/utils/analytics.d.ts +3 -0
- package/dist/types/utils/check-media-type.d.ts +4 -0
- package/dist/types/utils/current-media-node.d.ts +9 -0
- package/dist/types/utils/is-image.d.ts +1 -0
- package/dist/types/utils/media-common.d.ts +20 -0
- package/dist/types/utils/media-files.d.ts +30 -0
- package/dist/types/utils/media-single.d.ts +20 -0
- package/package.json +32 -20
- package/report.api.md +430 -0
- package/dist/types-ts4.5/index.d.ts +0 -1
- package/dist/types-ts4.5/types.d.ts +0 -118
- package/tmp/api-report-tmp.d.ts +0 -9
|
@@ -0,0 +1,813 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getMediaPluginState = exports.createPlugin = exports.MediaPluginStateImplementation = exports.MEDIA_PLUGIN_RESIZING_WIDTH_KEY = exports.MEDIA_PLUGIN_IS_RESIZING_KEY = exports.MEDIA_CONTENT_WRAP_CLASS_NAME = void 0;
|
|
9
|
+
Object.defineProperty(exports, "stateKey", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function get() {
|
|
12
|
+
return _pluginKey.stateKey;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
16
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
17
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
18
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
19
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
20
|
+
var _assert = _interopRequireDefault(require("assert"));
|
|
21
|
+
var _react = _interopRequireDefault(require("react"));
|
|
22
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
23
|
+
var _reactIntlNext = require("react-intl-next");
|
|
24
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
25
|
+
var _mediaSingle = require("@atlaskit/editor-common/media-single");
|
|
26
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
27
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
28
|
+
var _state2 = require("@atlaskit/editor-prosemirror/state");
|
|
29
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
30
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
31
|
+
var _view2 = require("@atlaskit/editor-prosemirror/view");
|
|
32
|
+
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
33
|
+
var _mediaCommon = require("@atlaskit/media-common");
|
|
34
|
+
var _helpers = _interopRequireWildcard(require("../commands/helpers"));
|
|
35
|
+
var helpers = _helpers;
|
|
36
|
+
var _pickerFacade = _interopRequireDefault(require("../picker-facade"));
|
|
37
|
+
var _DropPlaceholder = _interopRequireDefault(require("../ui/Media/DropPlaceholder"));
|
|
38
|
+
var _mediaCommon2 = require("../utils/media-common");
|
|
39
|
+
var _mediaFiles = require("../utils/media-files");
|
|
40
|
+
var _mediaSingle2 = require("../utils/media-single");
|
|
41
|
+
var _mediaTaskManager = require("./mediaTaskManager");
|
|
42
|
+
var _pluginKey = require("./plugin-key");
|
|
43
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
44
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
45
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
46
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
47
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
48
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
49
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
50
|
+
var MEDIA_CONTENT_WRAP_CLASS_NAME = exports.MEDIA_CONTENT_WRAP_CLASS_NAME = 'media-content-wrap';
|
|
51
|
+
var MEDIA_PLUGIN_IS_RESIZING_KEY = exports.MEDIA_PLUGIN_IS_RESIZING_KEY = 'mediaSinglePlugin.isResizing';
|
|
52
|
+
var MEDIA_PLUGIN_RESIZING_WIDTH_KEY = exports.MEDIA_PLUGIN_RESIZING_WIDTH_KEY = 'mediaSinglePlugin.resizing-width';
|
|
53
|
+
var createDropPlaceholder = function createDropPlaceholder(intl, allowDropLine) {
|
|
54
|
+
var dropPlaceholder = document.createElement('div');
|
|
55
|
+
var createElement = _react.default.createElement;
|
|
56
|
+
if (allowDropLine) {
|
|
57
|
+
_reactDom.default.render(createElement(_reactIntlNext.RawIntlProvider, {
|
|
58
|
+
value: intl
|
|
59
|
+
}, createElement(_DropPlaceholder.default, {
|
|
60
|
+
type: 'single'
|
|
61
|
+
})), dropPlaceholder);
|
|
62
|
+
} else {
|
|
63
|
+
_reactDom.default.render(createElement(_reactIntlNext.RawIntlProvider, {
|
|
64
|
+
value: intl
|
|
65
|
+
}, createElement(_DropPlaceholder.default)), dropPlaceholder);
|
|
66
|
+
}
|
|
67
|
+
return dropPlaceholder;
|
|
68
|
+
};
|
|
69
|
+
var MEDIA_RESOLVED_STATES = ['ready', 'error', 'cancelled'];
|
|
70
|
+
var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*#__PURE__*/function () {
|
|
71
|
+
function MediaPluginStateImplementation(_state, options, mediaOptions, newInsertionBehaviour, _dispatch, pluginInjectionApi) {
|
|
72
|
+
var _this = this;
|
|
73
|
+
(0, _classCallCheck2.default)(this, MediaPluginStateImplementation);
|
|
74
|
+
(0, _defineProperty2.default)(this, "allowsUploads", false);
|
|
75
|
+
(0, _defineProperty2.default)(this, "ignoreLinks", false);
|
|
76
|
+
(0, _defineProperty2.default)(this, "waitForMediaUpload", true);
|
|
77
|
+
(0, _defineProperty2.default)(this, "allUploadsFinished", true);
|
|
78
|
+
(0, _defineProperty2.default)(this, "showDropzone", false);
|
|
79
|
+
(0, _defineProperty2.default)(this, "isFullscreen", false);
|
|
80
|
+
(0, _defineProperty2.default)(this, "layout", 'center');
|
|
81
|
+
(0, _defineProperty2.default)(this, "mediaNodes", []);
|
|
82
|
+
(0, _defineProperty2.default)(this, "isResizing", false);
|
|
83
|
+
(0, _defineProperty2.default)(this, "resizingWidth", 0);
|
|
84
|
+
(0, _defineProperty2.default)(this, "destroyed", false);
|
|
85
|
+
(0, _defineProperty2.default)(this, "removeOnCloseListener", function () {});
|
|
86
|
+
(0, _defineProperty2.default)(this, "onPopupToggleCallback", function () {});
|
|
87
|
+
(0, _defineProperty2.default)(this, "nodeCount", new Map());
|
|
88
|
+
(0, _defineProperty2.default)(this, "taskManager", new _mediaTaskManager.MediaTaskManager());
|
|
89
|
+
(0, _defineProperty2.default)(this, "pickers", []);
|
|
90
|
+
(0, _defineProperty2.default)(this, "pickerPromises", []);
|
|
91
|
+
(0, _defineProperty2.default)(this, "onContextIdentifierProvider", /*#__PURE__*/function () {
|
|
92
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_name, provider) {
|
|
93
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
94
|
+
while (1) switch (_context.prev = _context.next) {
|
|
95
|
+
case 0:
|
|
96
|
+
if (!provider) {
|
|
97
|
+
_context.next = 4;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
_context.next = 3;
|
|
101
|
+
return provider;
|
|
102
|
+
case 3:
|
|
103
|
+
_this.contextIdentifierProvider = _context.sent;
|
|
104
|
+
case 4:
|
|
105
|
+
case "end":
|
|
106
|
+
return _context.stop();
|
|
107
|
+
}
|
|
108
|
+
}, _callee);
|
|
109
|
+
}));
|
|
110
|
+
return function (_x, _x2) {
|
|
111
|
+
return _ref.apply(this, arguments);
|
|
112
|
+
};
|
|
113
|
+
}());
|
|
114
|
+
(0, _defineProperty2.default)(this, "setMediaProvider", /*#__PURE__*/function () {
|
|
115
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(mediaProvider) {
|
|
116
|
+
var viewMediaClientConfig, wrappedError, view, allowsUploads;
|
|
117
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
118
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
119
|
+
case 0:
|
|
120
|
+
if (mediaProvider) {
|
|
121
|
+
_context2.next = 5;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
_this.destroyPickers();
|
|
125
|
+
_this.allowsUploads = false;
|
|
126
|
+
if (!_this.destroyed) {
|
|
127
|
+
_this.view.dispatch(_this.view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
128
|
+
allowsUploads: _this.allowsUploads
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
return _context2.abrupt("return");
|
|
132
|
+
case 5:
|
|
133
|
+
_context2.prev = 5;
|
|
134
|
+
_context2.next = 8;
|
|
135
|
+
return mediaProvider;
|
|
136
|
+
case 8:
|
|
137
|
+
_this.mediaProvider = _context2.sent;
|
|
138
|
+
// TODO [MS-2038]: remove once context api is removed
|
|
139
|
+
// We want to re assign the view and upload configs if they are missing for backwards compatibility
|
|
140
|
+
// as currently integrators can pass context || mediaClientConfig
|
|
141
|
+
if (!_this.mediaProvider.viewMediaClientConfig) {
|
|
142
|
+
viewMediaClientConfig = _this.mediaProvider.viewMediaClientConfig;
|
|
143
|
+
if (viewMediaClientConfig) {
|
|
144
|
+
_this.mediaProvider.viewMediaClientConfig = viewMediaClientConfig;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
(0, _assert.default)(_this.mediaProvider.viewMediaClientConfig, "MediaProvider promise did not resolve to a valid instance of MediaProvider - ".concat(_this.mediaProvider));
|
|
148
|
+
_context2.next = 21;
|
|
149
|
+
break;
|
|
150
|
+
case 13:
|
|
151
|
+
_context2.prev = 13;
|
|
152
|
+
_context2.t0 = _context2["catch"](5);
|
|
153
|
+
wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0)));
|
|
154
|
+
_this.errorReporter.captureException(wrappedError);
|
|
155
|
+
_this.destroyPickers();
|
|
156
|
+
_this.allowsUploads = false;
|
|
157
|
+
if (!_this.destroyed) {
|
|
158
|
+
_this.view.dispatch(_this.view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
159
|
+
allowsUploads: _this.allowsUploads
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
return _context2.abrupt("return");
|
|
163
|
+
case 21:
|
|
164
|
+
_this.mediaClientConfig = _this.mediaProvider.viewMediaClientConfig;
|
|
165
|
+
_this.allowsUploads = !!_this.mediaProvider.uploadMediaClientConfig;
|
|
166
|
+
view = _this.view, allowsUploads = _this.allowsUploads; // make sure editable DOM node is mounted
|
|
167
|
+
if (!_this.destroyed && view && view.dom.parentNode) {
|
|
168
|
+
// make PM plugin aware of the state change to update UI during 'apply' hook
|
|
169
|
+
view.dispatch(view.state.tr.setMeta(_pluginKey.stateKey, {
|
|
170
|
+
allowsUploads: allowsUploads
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
if (!_this.allowsUploads) {
|
|
174
|
+
_context2.next = 35;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
_this.uploadMediaClientConfig = _this.mediaProvider.uploadMediaClientConfig;
|
|
178
|
+
if (!(_this.mediaProvider.uploadParams && _this.uploadMediaClientConfig)) {
|
|
179
|
+
_context2.next = 32;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
_context2.next = 30;
|
|
183
|
+
return _this.initPickers(_this.mediaProvider.uploadParams, _pickerFacade.default);
|
|
184
|
+
case 30:
|
|
185
|
+
_context2.next = 33;
|
|
186
|
+
break;
|
|
187
|
+
case 32:
|
|
188
|
+
_this.destroyPickers();
|
|
189
|
+
case 33:
|
|
190
|
+
_context2.next = 36;
|
|
191
|
+
break;
|
|
192
|
+
case 35:
|
|
193
|
+
_this.destroyPickers();
|
|
194
|
+
case 36:
|
|
195
|
+
case "end":
|
|
196
|
+
return _context2.stop();
|
|
197
|
+
}
|
|
198
|
+
}, _callee2, null, [[5, 13]]);
|
|
199
|
+
}));
|
|
200
|
+
return function (_x3) {
|
|
201
|
+
return _ref2.apply(this, arguments);
|
|
202
|
+
};
|
|
203
|
+
}());
|
|
204
|
+
(0, _defineProperty2.default)(this, "getMediaOptions", function () {
|
|
205
|
+
return _this.options;
|
|
206
|
+
});
|
|
207
|
+
(0, _defineProperty2.default)(this, "isMediaSchemaNode", function (_ref3) {
|
|
208
|
+
var _this$mediaOptions;
|
|
209
|
+
var type = _ref3.type;
|
|
210
|
+
var _this$view$state$sche = _this.view.state.schema.nodes,
|
|
211
|
+
mediaInline = _this$view$state$sche.mediaInline,
|
|
212
|
+
mediaSingle = _this$view$state$sche.mediaSingle,
|
|
213
|
+
media = _this$view$state$sche.media;
|
|
214
|
+
if ((0, _mediaCommon.getMediaFeatureFlag)('mediaInline', (_this$mediaOptions = _this.mediaOptions) === null || _this$mediaOptions === void 0 ? void 0 : _this$mediaOptions.featureFlags)) {
|
|
215
|
+
return type === mediaSingle || type === media || type === mediaInline;
|
|
216
|
+
}
|
|
217
|
+
return type === mediaSingle;
|
|
218
|
+
});
|
|
219
|
+
/**
|
|
220
|
+
* we insert a new file by inserting a initial state for that file.
|
|
221
|
+
*
|
|
222
|
+
* called when we insert a new file via the picker (connected via pickerfacade)
|
|
223
|
+
*/
|
|
224
|
+
(0, _defineProperty2.default)(this, "insertFile", function (mediaState, onMediaStateChanged, pickerType) {
|
|
225
|
+
var _this$pluginInjection, _mediaState$collectio, _this$mediaOptions2;
|
|
226
|
+
var state = _this.view.state;
|
|
227
|
+
var editorAnalyticsAPI = (_this$pluginInjection = _this.pluginInjectionApi) === null || _this$pluginInjection === void 0 || (_this$pluginInjection = _this$pluginInjection.analytics) === null || _this$pluginInjection === void 0 ? void 0 : _this$pluginInjection.actions;
|
|
228
|
+
var mediaStateWithContext = _objectSpread(_objectSpread({}, mediaState), {}, {
|
|
229
|
+
contextId: _this.contextIdentifierProvider ? _this.contextIdentifierProvider.objectId : undefined
|
|
230
|
+
});
|
|
231
|
+
var collection = (_mediaState$collectio = mediaState.collection) !== null && _mediaState$collectio !== void 0 ? _mediaState$collectio : _this.collectionFromProvider();
|
|
232
|
+
if (collection === undefined) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// We need to dispatch the change to event dispatcher only for successful files
|
|
237
|
+
if (mediaState.status !== 'error') {
|
|
238
|
+
_this.updateAndDispatch({
|
|
239
|
+
allUploadsFinished: false
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if ((0, _mediaSingle2.isMediaSingle)(state.schema, mediaStateWithContext.fileMimeType)) {
|
|
243
|
+
var _this$pluginInjection2;
|
|
244
|
+
// read width state right before inserting to get up-to-date and define values
|
|
245
|
+
var widthPluginState = (_this$pluginInjection2 = _this.pluginInjectionApi) === null || _this$pluginInjection2 === void 0 ? void 0 : _this$pluginInjection2.width.sharedState.currentState();
|
|
246
|
+
(0, _mediaSingle2.insertMediaSingleNode)(_this.view, mediaStateWithContext, _this.getInputMethod(pickerType), collection, _this.mediaOptions && _this.mediaOptions.alignLeftOnInsert, _this.newInsertionBehaviour, widthPluginState, editorAnalyticsAPI);
|
|
247
|
+
} else if ((0, _mediaCommon.getMediaFeatureFlag)('mediaInline', (_this$mediaOptions2 = _this.mediaOptions) === null || _this$mediaOptions2 === void 0 ? void 0 : _this$mediaOptions2.featureFlags) && !(0, _utils.isInEmptyLine)(state) && (!(0, _mediaCommon2.isInsidePotentialEmptyParagraph)(state) || (0, _utils.isInListItem)(state)) && (0, _mediaFiles.canInsertMediaInline)(state)) {
|
|
248
|
+
(0, _mediaFiles.insertMediaInlineNode)(editorAnalyticsAPI)(_this.view, mediaStateWithContext, collection, _this.getInputMethod(pickerType));
|
|
249
|
+
} else {
|
|
250
|
+
(0, _mediaFiles.insertMediaGroupNode)(editorAnalyticsAPI)(_this.view, [mediaStateWithContext], collection, _this.getInputMethod(pickerType));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// do events when media state changes
|
|
254
|
+
onMediaStateChanged(_this.handleMediaState);
|
|
255
|
+
|
|
256
|
+
// handle waiting for upload complete
|
|
257
|
+
var isEndState = function isEndState(state) {
|
|
258
|
+
return state.status && MEDIA_RESOLVED_STATES.indexOf(state.status) !== -1;
|
|
259
|
+
};
|
|
260
|
+
if (!isEndState(mediaStateWithContext)) {
|
|
261
|
+
var uploadingPromise = new Promise(function (resolve) {
|
|
262
|
+
onMediaStateChanged(function (newState) {
|
|
263
|
+
// When media item reaches its final state, remove listener and resolve
|
|
264
|
+
if (isEndState(newState)) {
|
|
265
|
+
resolve(newState);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
_this.taskManager.addPendingTask(uploadingPromise, mediaStateWithContext.id).then(function () {
|
|
270
|
+
_this.updateAndDispatch({
|
|
271
|
+
allUploadsFinished: true
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// refocus the view
|
|
277
|
+
var view = _this.view;
|
|
278
|
+
if (!view.hasFocus()) {
|
|
279
|
+
view.focus();
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
(0, _defineProperty2.default)(this, "addPendingTask", function (task) {
|
|
283
|
+
_this.taskManager.addPendingTask(task);
|
|
284
|
+
});
|
|
285
|
+
(0, _defineProperty2.default)(this, "splitMediaGroup", function () {
|
|
286
|
+
return (0, _mediaCommon2.splitMediaGroup)(_this.view);
|
|
287
|
+
});
|
|
288
|
+
(0, _defineProperty2.default)(this, "onPopupPickerClose", function () {
|
|
289
|
+
_this.onPopupToggleCallback(false);
|
|
290
|
+
});
|
|
291
|
+
(0, _defineProperty2.default)(this, "showMediaPicker", function () {
|
|
292
|
+
if (_this.openMediaPickerBrowser) {
|
|
293
|
+
return _this.openMediaPickerBrowser();
|
|
294
|
+
}
|
|
295
|
+
_this.onPopupToggleCallback(true);
|
|
296
|
+
});
|
|
297
|
+
(0, _defineProperty2.default)(this, "setBrowseFn", function (browseFn) {
|
|
298
|
+
_this.openMediaPickerBrowser = browseFn;
|
|
299
|
+
});
|
|
300
|
+
(0, _defineProperty2.default)(this, "onPopupToggle", function (onPopupToggleCallback) {
|
|
301
|
+
_this.onPopupToggleCallback = onPopupToggleCallback;
|
|
302
|
+
});
|
|
303
|
+
/**
|
|
304
|
+
* Returns a promise that is resolved after all pending operations have been finished.
|
|
305
|
+
* An optional timeout will cause the promise to reject if the operation takes too long
|
|
306
|
+
*
|
|
307
|
+
* NOTE: The promise will resolve even if some of the media have failed to process.
|
|
308
|
+
*/
|
|
309
|
+
(0, _defineProperty2.default)(this, "waitForPendingTasks", this.taskManager.waitForPendingTasks);
|
|
310
|
+
/**
|
|
311
|
+
* Called from React UI Component when user clicks on "Delete" icon
|
|
312
|
+
* inside of it
|
|
313
|
+
*/
|
|
314
|
+
(0, _defineProperty2.default)(this, "handleMediaNodeRemoval", function (node, getPos) {
|
|
315
|
+
var getNode = node;
|
|
316
|
+
if (!getNode) {
|
|
317
|
+
var pos = getPos();
|
|
318
|
+
if (typeof pos !== 'number') {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
getNode = _this.view.state.doc.nodeAt(pos);
|
|
322
|
+
}
|
|
323
|
+
(0, _mediaCommon2.removeMediaNode)(_this.view, getNode, getPos);
|
|
324
|
+
});
|
|
325
|
+
(0, _defineProperty2.default)(this, "trackMediaNodeAddition", function (node) {
|
|
326
|
+
var _this$nodeCount$get;
|
|
327
|
+
var id = node.attrs.id;
|
|
328
|
+
var count = (_this$nodeCount$get = _this.nodeCount.get(id)) !== null && _this$nodeCount$get !== void 0 ? _this$nodeCount$get : 0;
|
|
329
|
+
if (count === 0) {
|
|
330
|
+
_this.taskManager.resumePendingTask(id);
|
|
331
|
+
}
|
|
332
|
+
_this.nodeCount.set(id, count + 1);
|
|
333
|
+
});
|
|
334
|
+
(0, _defineProperty2.default)(this, "trackMediaNodeRemoval", function (node) {
|
|
335
|
+
var _this$nodeCount$get2;
|
|
336
|
+
var id = node.attrs.id;
|
|
337
|
+
var count = (_this$nodeCount$get2 = _this.nodeCount.get(id)) !== null && _this$nodeCount$get2 !== void 0 ? _this$nodeCount$get2 : 0;
|
|
338
|
+
if (count === 1) {
|
|
339
|
+
_this.taskManager.cancelPendingTask(id);
|
|
340
|
+
}
|
|
341
|
+
_this.nodeCount.set(id, count - 1);
|
|
342
|
+
});
|
|
343
|
+
/**
|
|
344
|
+
* Called from React UI Component on componentDidMount
|
|
345
|
+
*/
|
|
346
|
+
(0, _defineProperty2.default)(this, "handleMediaNodeMount", function (node, getPos) {
|
|
347
|
+
_this.trackMediaNodeAddition(node);
|
|
348
|
+
_this.mediaNodes.unshift({
|
|
349
|
+
node: node,
|
|
350
|
+
getPos: getPos
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
/**
|
|
354
|
+
* Called from React UI Component on componentWillUnmount and UNSAFE_componentWillReceiveProps
|
|
355
|
+
* when React component's underlying node property is replaced with a new node
|
|
356
|
+
*/
|
|
357
|
+
(0, _defineProperty2.default)(this, "handleMediaNodeUnmount", function (oldNode) {
|
|
358
|
+
_this.trackMediaNodeRemoval(oldNode);
|
|
359
|
+
_this.mediaNodes = _this.mediaNodes.filter(function (_ref4) {
|
|
360
|
+
var node = _ref4.node;
|
|
361
|
+
return oldNode !== node;
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
(0, _defineProperty2.default)(this, "handleMediaGroupUpdate", function (oldNodes, newNodes) {
|
|
365
|
+
var addedNodes = newNodes.filter(function (node) {
|
|
366
|
+
return oldNodes.every(function (oldNode) {
|
|
367
|
+
return oldNode.attrs.id !== node.attrs.id;
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
var removedNodes = oldNodes.filter(function (node) {
|
|
371
|
+
return newNodes.every(function (newNode) {
|
|
372
|
+
return newNode.attrs.id !== node.attrs.id;
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
addedNodes.forEach(function (node) {
|
|
376
|
+
_this.trackMediaNodeAddition(node);
|
|
377
|
+
});
|
|
378
|
+
removedNodes.forEach(function (oldNode) {
|
|
379
|
+
_this.trackMediaNodeRemoval(oldNode);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
(0, _defineProperty2.default)(this, "findMediaNode", function (id) {
|
|
383
|
+
return helpers.findMediaSingleNode(_this, id);
|
|
384
|
+
});
|
|
385
|
+
(0, _defineProperty2.default)(this, "destroyAllPickers", function (pickers) {
|
|
386
|
+
pickers.forEach(function (picker) {
|
|
387
|
+
return picker.destroy();
|
|
388
|
+
});
|
|
389
|
+
_this.pickers.splice(0, _this.pickers.length);
|
|
390
|
+
});
|
|
391
|
+
(0, _defineProperty2.default)(this, "destroyPickers", function () {
|
|
392
|
+
var pickers = _this.pickers,
|
|
393
|
+
pickerPromises = _this.pickerPromises;
|
|
394
|
+
|
|
395
|
+
// If pickerPromises and pickers are the same length
|
|
396
|
+
// All pickers have resolved and we safely destroy them
|
|
397
|
+
// Otherwise wait for them to resolve then destroy.
|
|
398
|
+
if (pickerPromises.length === pickers.length) {
|
|
399
|
+
_this.destroyAllPickers(_this.pickers);
|
|
400
|
+
} else {
|
|
401
|
+
Promise.all(pickerPromises).then(function (resolvedPickers) {
|
|
402
|
+
return _this.destroyAllPickers(resolvedPickers);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
_this.customPicker = undefined;
|
|
406
|
+
});
|
|
407
|
+
(0, _defineProperty2.default)(this, "getInputMethod", function (pickerType) {
|
|
408
|
+
switch (pickerType) {
|
|
409
|
+
case 'clipboard':
|
|
410
|
+
return _analytics.INPUT_METHOD.CLIPBOARD;
|
|
411
|
+
case 'dropzone':
|
|
412
|
+
return _analytics.INPUT_METHOD.DRAG_AND_DROP;
|
|
413
|
+
}
|
|
414
|
+
return;
|
|
415
|
+
});
|
|
416
|
+
(0, _defineProperty2.default)(this, "updateMediaSingleNodeAttrs", function (id, attrs) {
|
|
417
|
+
var view = _this.view;
|
|
418
|
+
if (!view) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
return (0, _helpers.updateMediaSingleNodeAttrs)(id, attrs)(view.state, view.dispatch);
|
|
422
|
+
});
|
|
423
|
+
(0, _defineProperty2.default)(this, "handleMediaState", function (state) {
|
|
424
|
+
switch (state.status) {
|
|
425
|
+
case 'error':
|
|
426
|
+
var uploadErrorHandler = _this.options.uploadErrorHandler;
|
|
427
|
+
if (uploadErrorHandler) {
|
|
428
|
+
uploadErrorHandler(state);
|
|
429
|
+
}
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
(0, _defineProperty2.default)(this, "removeSelectedMediaContainer", function () {
|
|
434
|
+
var view = _this.view;
|
|
435
|
+
var selectedNode = _this.selectedMediaContainerNode();
|
|
436
|
+
if (!selectedNode) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
var from = view.state.selection.from;
|
|
440
|
+
(0, _mediaCommon2.removeMediaNode)(view, selectedNode.firstChild, function () {
|
|
441
|
+
return from + 1;
|
|
442
|
+
});
|
|
443
|
+
return true;
|
|
444
|
+
});
|
|
445
|
+
(0, _defineProperty2.default)(this, "selectedMediaContainerNode", function () {
|
|
446
|
+
var selection = _this.view.state.selection;
|
|
447
|
+
if (selection instanceof _state2.NodeSelection && _this.isMediaSchemaNode(selection.node)) {
|
|
448
|
+
return selection.node;
|
|
449
|
+
}
|
|
450
|
+
return;
|
|
451
|
+
});
|
|
452
|
+
(0, _defineProperty2.default)(this, "handleDrag", function (dragState) {
|
|
453
|
+
var isActive = dragState === 'enter';
|
|
454
|
+
if (_this.showDropzone === isActive) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
_this.showDropzone = isActive;
|
|
458
|
+
var _this$view = _this.view,
|
|
459
|
+
dispatch = _this$view.dispatch,
|
|
460
|
+
state = _this$view.state;
|
|
461
|
+
var tr = state.tr,
|
|
462
|
+
selection = state.selection,
|
|
463
|
+
doc = state.doc;
|
|
464
|
+
var _state$schema$nodes = state.schema.nodes,
|
|
465
|
+
media = _state$schema$nodes.media,
|
|
466
|
+
mediaGroup = _state$schema$nodes.mediaGroup;
|
|
467
|
+
|
|
468
|
+
// Workaround for wrong upload position
|
|
469
|
+
// @see https://product-fabric.atlassian.net/browse/MEX-2457
|
|
470
|
+
// If the media node is the last selectable item in the current cursor position and it is located within a mediaGroup,
|
|
471
|
+
// we relocate the cursor to the first child of the mediaGroup.
|
|
472
|
+
var sel = _state2.Selection.findFrom(doc.resolve(selection.$from.pos - 1), -1);
|
|
473
|
+
if (sel && (0, _utils2.findSelectedNodeOfType)(media)(sel)) {
|
|
474
|
+
var parent = (0, _utils2.findParentNodeOfType)(mediaGroup)(sel);
|
|
475
|
+
if (parent) {
|
|
476
|
+
tr.setSelection(_state2.NodeSelection.create(tr.doc, parent.start));
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Trigger state change to be able to pick it up in the decorations handler
|
|
481
|
+
dispatch(tr);
|
|
482
|
+
});
|
|
483
|
+
this.options = options;
|
|
484
|
+
this.mediaOptions = mediaOptions;
|
|
485
|
+
this.newInsertionBehaviour = newInsertionBehaviour;
|
|
486
|
+
this.dispatch = _dispatch;
|
|
487
|
+
this.pluginInjectionApi = pluginInjectionApi;
|
|
488
|
+
this.waitForMediaUpload = options.waitForMediaUpload === undefined ? true : options.waitForMediaUpload;
|
|
489
|
+
var nodes = _state.schema.nodes;
|
|
490
|
+
(0, _assert.default)(nodes.media && (nodes.mediaGroup || nodes.mediaSingle), 'Editor: unable to init media plugin - media or mediaGroup/mediaSingle node absent in schema');
|
|
491
|
+
options.providerFactory.subscribe('mediaProvider', function (_name, provider) {
|
|
492
|
+
return _this.setMediaProvider(provider);
|
|
493
|
+
});
|
|
494
|
+
options.providerFactory.subscribe('contextIdentifierProvider', this.onContextIdentifierProvider);
|
|
495
|
+
this.errorReporter = options.errorReporter || new _utils.ErrorReporter();
|
|
496
|
+
this.singletonCreatedAt = (performance || Date).now();
|
|
497
|
+
}
|
|
498
|
+
(0, _createClass2.default)(MediaPluginStateImplementation, [{
|
|
499
|
+
key: "clone",
|
|
500
|
+
value: function clone() {
|
|
501
|
+
var clonedAt = (performance || Date).now();
|
|
502
|
+
return new Proxy(this, {
|
|
503
|
+
get: function get(target, prop, receiver) {
|
|
504
|
+
if (prop === 'singletonCreatedAt') {
|
|
505
|
+
return clonedAt;
|
|
506
|
+
}
|
|
507
|
+
return Reflect.get(target, prop, receiver);
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
}, {
|
|
512
|
+
key: "setIsResizing",
|
|
513
|
+
value: function setIsResizing(isResizing) {
|
|
514
|
+
this.isResizing = isResizing;
|
|
515
|
+
}
|
|
516
|
+
}, {
|
|
517
|
+
key: "setResizingWidth",
|
|
518
|
+
value: function setResizingWidth(width) {
|
|
519
|
+
this.resizingWidth = width;
|
|
520
|
+
}
|
|
521
|
+
}, {
|
|
522
|
+
key: "updateElement",
|
|
523
|
+
value: function updateElement() {
|
|
524
|
+
var newElement;
|
|
525
|
+
var selectedContainer = this.selectedMediaContainerNode();
|
|
526
|
+
if (selectedContainer && this.isMediaSchemaNode(selectedContainer)) {
|
|
527
|
+
newElement = this.getDomElement(this.view.domAtPos.bind(this.view));
|
|
528
|
+
if (selectedContainer.type === this.view.state.schema.nodes.mediaSingle) {
|
|
529
|
+
this.currentMaxWidth = (0, _mediaSingle.getMaxWidthForNestedNodeNext)(this.view, this.view.state.selection.$anchor.pos) || undefined;
|
|
530
|
+
} else {
|
|
531
|
+
this.currentMaxWidth = undefined;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (this.element !== newElement) {
|
|
535
|
+
this.element = newElement;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}, {
|
|
539
|
+
key: "getDomElement",
|
|
540
|
+
value: function getDomElement(domAtPos) {
|
|
541
|
+
var selection = this.view.state.selection;
|
|
542
|
+
if (!(selection instanceof _state2.NodeSelection)) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (!this.isMediaSchemaNode(selection.node)) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
var node = (0, _utils2.findDomRefAtPos)(selection.from, domAtPos);
|
|
549
|
+
if (node) {
|
|
550
|
+
if (!node.childNodes.length) {
|
|
551
|
+
return node.parentNode;
|
|
552
|
+
}
|
|
553
|
+
return node;
|
|
554
|
+
}
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
}, {
|
|
558
|
+
key: "setView",
|
|
559
|
+
value: function setView(view) {
|
|
560
|
+
this.view = view;
|
|
561
|
+
}
|
|
562
|
+
}, {
|
|
563
|
+
key: "destroy",
|
|
564
|
+
value: function destroy() {
|
|
565
|
+
if (this.destroyed) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
this.destroyed = true;
|
|
569
|
+
var mediaNodes = this.mediaNodes;
|
|
570
|
+
mediaNodes.splice(0, mediaNodes.length);
|
|
571
|
+
this.removeOnCloseListener();
|
|
572
|
+
this.destroyPickers();
|
|
573
|
+
}
|
|
574
|
+
}, {
|
|
575
|
+
key: "initPickers",
|
|
576
|
+
value: function () {
|
|
577
|
+
var _initPickers = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(uploadParams, Picker) {
|
|
578
|
+
var _this2 = this;
|
|
579
|
+
var errorReporter, pickers, pickerPromises, pickerFacadeConfig, customPicker;
|
|
580
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
581
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
582
|
+
case 0:
|
|
583
|
+
if (!(this.destroyed || !this.uploadMediaClientConfig)) {
|
|
584
|
+
_context3.next = 2;
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
587
|
+
return _context3.abrupt("return");
|
|
588
|
+
case 2:
|
|
589
|
+
errorReporter = this.errorReporter, pickers = this.pickers, pickerPromises = this.pickerPromises; // create pickers if they don't exist, re-use otherwise
|
|
590
|
+
if (pickers.length) {
|
|
591
|
+
_context3.next = 14;
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
pickerFacadeConfig = {
|
|
595
|
+
mediaClientConfig: this.uploadMediaClientConfig,
|
|
596
|
+
errorReporter: errorReporter
|
|
597
|
+
};
|
|
598
|
+
if (!this.options.customMediaPicker) {
|
|
599
|
+
_context3.next = 13;
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
customPicker = new Picker('customMediaPicker', pickerFacadeConfig, this.options.customMediaPicker).init();
|
|
603
|
+
pickerPromises.push(customPicker);
|
|
604
|
+
_context3.t0 = pickers;
|
|
605
|
+
_context3.next = 11;
|
|
606
|
+
return customPicker;
|
|
607
|
+
case 11:
|
|
608
|
+
_context3.t1 = this.customPicker = _context3.sent;
|
|
609
|
+
_context3.t0.push.call(_context3.t0, _context3.t1);
|
|
610
|
+
case 13:
|
|
611
|
+
pickers.forEach(function (picker) {
|
|
612
|
+
picker.onNewMedia(_this2.insertFile);
|
|
613
|
+
});
|
|
614
|
+
case 14:
|
|
615
|
+
// set new upload params for the pickers
|
|
616
|
+
pickers.forEach(function (picker) {
|
|
617
|
+
return picker.setUploadParams(uploadParams);
|
|
618
|
+
});
|
|
619
|
+
case 15:
|
|
620
|
+
case "end":
|
|
621
|
+
return _context3.stop();
|
|
622
|
+
}
|
|
623
|
+
}, _callee3, this);
|
|
624
|
+
}));
|
|
625
|
+
function initPickers(_x4, _x5) {
|
|
626
|
+
return _initPickers.apply(this, arguments);
|
|
627
|
+
}
|
|
628
|
+
return initPickers;
|
|
629
|
+
}()
|
|
630
|
+
}, {
|
|
631
|
+
key: "collectionFromProvider",
|
|
632
|
+
value: function collectionFromProvider() {
|
|
633
|
+
return this.mediaProvider && this.mediaProvider.uploadParams && this.mediaProvider.uploadParams.collection;
|
|
634
|
+
}
|
|
635
|
+
}, {
|
|
636
|
+
key: "updateAndDispatch",
|
|
637
|
+
value: function updateAndDispatch(props) {
|
|
638
|
+
var _this3 = this;
|
|
639
|
+
// update plugin state
|
|
640
|
+
Object.keys(props).forEach(function (_key) {
|
|
641
|
+
var key = _key;
|
|
642
|
+
var value = props[key];
|
|
643
|
+
if (value !== undefined) {
|
|
644
|
+
_this3[key] = value;
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
if (this.dispatch) {
|
|
648
|
+
this.dispatch(_pluginKey.stateKey, _objectSpread({}, this));
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}]);
|
|
652
|
+
return MediaPluginStateImplementation;
|
|
653
|
+
}();
|
|
654
|
+
var getMediaPluginState = exports.getMediaPluginState = function getMediaPluginState(state) {
|
|
655
|
+
return _pluginKey.stateKey.getState(state);
|
|
656
|
+
};
|
|
657
|
+
var createPlugin = exports.createPlugin = function createPlugin(_schema, options, reactContext, getIntl, pluginInjectionApi, dispatch, mediaOptions, newInsertionBehaviour) {
|
|
658
|
+
var intl = getIntl();
|
|
659
|
+
var dropPlaceholder = createDropPlaceholder(intl, mediaOptions && mediaOptions.allowDropzoneDropLine);
|
|
660
|
+
return new _safePlugin.SafePlugin({
|
|
661
|
+
state: {
|
|
662
|
+
init: function init(_config, state) {
|
|
663
|
+
return new MediaPluginStateImplementation(state, options, mediaOptions, newInsertionBehaviour, dispatch, pluginInjectionApi);
|
|
664
|
+
},
|
|
665
|
+
apply: function apply(tr, pluginState) {
|
|
666
|
+
var isResizing = tr.getMeta(MEDIA_PLUGIN_IS_RESIZING_KEY);
|
|
667
|
+
var resizingWidth = tr.getMeta(MEDIA_PLUGIN_RESIZING_WIDTH_KEY);
|
|
668
|
+
// Yes, I agree with you; this approach, using the clone() fuction, below is horrifying.
|
|
669
|
+
// However, we needed to implement this workaround to solve the singleton Media PluginState.
|
|
670
|
+
// The entire PluginInjectionAPI relies on the following axiom: "A PluginState that reflects a new EditorState.". We can not have the mutable singleton instance for all EditorState.
|
|
671
|
+
// Unfortunately, we can't implement a proper fix for this media state situation. So, we are faking a new object using a Proxy instance.
|
|
672
|
+
var nextPluginState = pluginState;
|
|
673
|
+
if (isResizing !== undefined) {
|
|
674
|
+
pluginState.setIsResizing(isResizing);
|
|
675
|
+
nextPluginState = nextPluginState.clone();
|
|
676
|
+
}
|
|
677
|
+
if (resizingWidth) {
|
|
678
|
+
pluginState.setResizingWidth(resizingWidth);
|
|
679
|
+
nextPluginState = nextPluginState.clone();
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// remap editing media single position if we're in collab
|
|
683
|
+
if (typeof pluginState.editingMediaSinglePos === 'number') {
|
|
684
|
+
pluginState.editingMediaSinglePos = tr.mapping.map(pluginState.editingMediaSinglePos);
|
|
685
|
+
nextPluginState = nextPluginState.clone();
|
|
686
|
+
}
|
|
687
|
+
var meta = tr.getMeta(_pluginKey.stateKey);
|
|
688
|
+
if (meta) {
|
|
689
|
+
var allowsUploads = meta.allowsUploads;
|
|
690
|
+
pluginState.updateAndDispatch({
|
|
691
|
+
allowsUploads: typeof allowsUploads === 'undefined' ? pluginState.allowsUploads : allowsUploads
|
|
692
|
+
});
|
|
693
|
+
nextPluginState = nextPluginState.clone();
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// NOTE: We're not calling passing new state to the Editor, because we depend on the view.state reference
|
|
697
|
+
// throughout the lifetime of view. We injected the view into the plugin state, because we dispatch()
|
|
698
|
+
// transformations from within the plugin state (i.e. when adding a new file).
|
|
699
|
+
return nextPluginState;
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
703
|
+
var _iterator = _createForOfIteratorHelper(transactions),
|
|
704
|
+
_step;
|
|
705
|
+
try {
|
|
706
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
707
|
+
var transaction = _step.value;
|
|
708
|
+
var isSelectionOnMediaInsideMediaSingle = transaction.selectionSet && (0, _utils2.isNodeSelection)(transaction.selection) && transaction.selection.node.type === newState.schema.nodes.media && transaction.selection.$anchor.parent.type === newState.schema.nodes.mediaSingle;
|
|
709
|
+
|
|
710
|
+
// Note: this causes an additional transaction when selecting a media node
|
|
711
|
+
// through clicking on it with the cursor.
|
|
712
|
+
if (isSelectionOnMediaInsideMediaSingle) {
|
|
713
|
+
// If a selection has been placed on a media inside a media single,
|
|
714
|
+
// we shift it to the media single parent as other code is opinionated about
|
|
715
|
+
// the selection landing there. In particular the caption insertion and selection
|
|
716
|
+
// action.
|
|
717
|
+
return newState.tr.setSelection(_state2.NodeSelection.create(newState.doc, transaction.selection.$from.pos - 1));
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
} catch (err) {
|
|
721
|
+
_iterator.e(err);
|
|
722
|
+
} finally {
|
|
723
|
+
_iterator.f();
|
|
724
|
+
}
|
|
725
|
+
return;
|
|
726
|
+
},
|
|
727
|
+
key: _pluginKey.stateKey,
|
|
728
|
+
view: function view(_view) {
|
|
729
|
+
var pluginState = getMediaPluginState(_view.state);
|
|
730
|
+
pluginState.setView(_view);
|
|
731
|
+
pluginState.updateElement();
|
|
732
|
+
return {
|
|
733
|
+
update: function update() {
|
|
734
|
+
pluginState.updateElement();
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
},
|
|
738
|
+
props: {
|
|
739
|
+
decorations: function decorations(state) {
|
|
740
|
+
// Use this to indicate that the media node is selected
|
|
741
|
+
var mediaNodes = [];
|
|
742
|
+
var schema = state.schema,
|
|
743
|
+
$anchor = state.selection.$anchor,
|
|
744
|
+
doc = state.doc;
|
|
745
|
+
|
|
746
|
+
// Find any media nodes in the current selection
|
|
747
|
+
if (state.selection instanceof _state2.TextSelection || state.selection instanceof _state2.AllSelection || state.selection instanceof _state2.NodeSelection || state.selection instanceof _cellSelection.CellSelection) {
|
|
748
|
+
doc.nodesBetween(state.selection.from, state.selection.to, function (node, pos) {
|
|
749
|
+
if (node.type === schema.nodes.media) {
|
|
750
|
+
mediaNodes.push(_view2.Decoration.node(pos, pos + node.nodeSize, {}, {
|
|
751
|
+
type: 'media',
|
|
752
|
+
selected: true
|
|
753
|
+
}));
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
return true;
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
var pluginState = getMediaPluginState(state);
|
|
760
|
+
if (!pluginState.showDropzone) {
|
|
761
|
+
return _view2.DecorationSet.create(state.doc, mediaNodes);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// When a media is already selected
|
|
765
|
+
if (state.selection instanceof _state2.NodeSelection) {
|
|
766
|
+
var node = state.selection.node;
|
|
767
|
+
if (node.type === schema.nodes.mediaSingle) {
|
|
768
|
+
var deco = _view2.Decoration.node(state.selection.from, state.selection.to, {
|
|
769
|
+
class: 'richMedia-selected'
|
|
770
|
+
});
|
|
771
|
+
return _view2.DecorationSet.create(state.doc, [deco].concat(mediaNodes));
|
|
772
|
+
}
|
|
773
|
+
return _view2.DecorationSet.create(state.doc, mediaNodes);
|
|
774
|
+
}
|
|
775
|
+
var pos = $anchor.pos;
|
|
776
|
+
if ($anchor.parent.type !== schema.nodes.paragraph && $anchor.parent.type !== schema.nodes.codeBlock) {
|
|
777
|
+
pos = (0, _transform.insertPoint)(state.doc, pos, schema.nodes.mediaGroup);
|
|
778
|
+
}
|
|
779
|
+
if (pos === null || pos === undefined) {
|
|
780
|
+
return _view2.DecorationSet.create(state.doc, mediaNodes);
|
|
781
|
+
}
|
|
782
|
+
var dropPlaceholders = [_view2.Decoration.widget(pos, dropPlaceholder, {
|
|
783
|
+
key: 'drop-placeholder'
|
|
784
|
+
})].concat(mediaNodes);
|
|
785
|
+
return _view2.DecorationSet.create(state.doc, dropPlaceholders);
|
|
786
|
+
},
|
|
787
|
+
nodeViews: options.nodeViews,
|
|
788
|
+
handleTextInput: function handleTextInput(view) {
|
|
789
|
+
getMediaPluginState(view.state).splitMediaGroup();
|
|
790
|
+
return false;
|
|
791
|
+
},
|
|
792
|
+
handleClick: function handleClick(_editorView, _pos, event) {
|
|
793
|
+
var _event$target;
|
|
794
|
+
var clickedInsideCaptionPlaceholder = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.closest("[data-id=\"".concat(_mediaSingle.CAPTION_PLACEHOLDER_ID, "\"]"));
|
|
795
|
+
|
|
796
|
+
// Workaround for Chrome given a regression introduced in prosemirror-view@1.18.6
|
|
797
|
+
// Returning true prevents that updateSelection() is getting called in the commit below:
|
|
798
|
+
// @see https://github.com/ProseMirror/prosemirror-view/compare/1.18.5...1.18.6
|
|
799
|
+
if ((_utils.browser.chrome || _utils.browser.safari) && clickedInsideCaptionPlaceholder) {
|
|
800
|
+
return true;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// Workaound for iOS 16 Caption selection issue
|
|
804
|
+
// @see https://product-fabric.atlassian.net/browse/MEX-2012
|
|
805
|
+
if (_utils.browser.ios) {
|
|
806
|
+
var _event$target2;
|
|
807
|
+
return !!((_event$target2 = event.target) !== null && _event$target2 !== void 0 && _event$target2.closest("[class=\"".concat(MEDIA_CONTENT_WRAP_CLASS_NAME, "\"]")));
|
|
808
|
+
}
|
|
809
|
+
return false;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
};
|