@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,384 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import uuidV4 from 'uuid/v4';
|
|
3
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import { DEFAULT_IMAGE_HEIGHT, DEFAULT_IMAGE_WIDTH } from '@atlaskit/editor-common/media-single';
|
|
5
|
+
import { getAttrsFromUrl, getMediaClient, isImageRepresentationReady, isMediaBlobUrl } from '@atlaskit/media-client';
|
|
6
|
+
import { replaceExternalMedia, updateAllMediaSingleNodesAttrs, updateCurrentMediaNodeAttrs, updateMediaSingleNodeAttrs } from '../commands/helpers';
|
|
7
|
+
export class MediaNodeUpdater {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
// Updates the node with contextId if it doesn't have one already
|
|
10
|
+
// TODO [MS-2258]: remove updateContextId in order to only use updateMediaSingleFileAttrs
|
|
11
|
+
_defineProperty(this, "updateContextId", async () => {
|
|
12
|
+
const attrs = this.getAttrs();
|
|
13
|
+
if (!attrs || attrs.type !== 'file') {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const {
|
|
17
|
+
id
|
|
18
|
+
} = attrs;
|
|
19
|
+
const objectId = await this.getObjectId();
|
|
20
|
+
updateAllMediaSingleNodesAttrs(id, {
|
|
21
|
+
__contextId: objectId
|
|
22
|
+
})(this.props.view.state, this.props.view.dispatch);
|
|
23
|
+
});
|
|
24
|
+
_defineProperty(this, "updateNodeContextId", async getPos => {
|
|
25
|
+
const attrs = this.getAttrs();
|
|
26
|
+
if ((attrs === null || attrs === void 0 ? void 0 : attrs.type) !== 'file') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const objectId = await this.getObjectId();
|
|
30
|
+
updateCurrentMediaNodeAttrs({
|
|
31
|
+
__contextId: objectId
|
|
32
|
+
}, {
|
|
33
|
+
node: this.props.node,
|
|
34
|
+
getPos
|
|
35
|
+
})(this.props.view.state, this.props.view.dispatch);
|
|
36
|
+
});
|
|
37
|
+
_defineProperty(this, "hasFileAttributesDefined", attrs => {
|
|
38
|
+
return attrs && attrs.type === 'file' && attrs.__fileName && attrs.__fileMimeType && attrs.__fileSize && attrs.__contextId;
|
|
39
|
+
});
|
|
40
|
+
_defineProperty(this, "getNewFileAttrsForNode", async () => {
|
|
41
|
+
const attrs = this.getAttrs();
|
|
42
|
+
const mediaProvider = await this.props.mediaProvider;
|
|
43
|
+
if (!mediaProvider || !mediaProvider.uploadParams || !attrs || attrs.type !== 'file' || this.hasFileAttributesDefined(attrs)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const mediaClientConfig = mediaProvider.viewMediaClientConfig;
|
|
47
|
+
const mediaClient = getMediaClient(mediaClientConfig);
|
|
48
|
+
let fileState;
|
|
49
|
+
const {
|
|
50
|
+
id,
|
|
51
|
+
collection: collectionName
|
|
52
|
+
} = attrs;
|
|
53
|
+
try {
|
|
54
|
+
fileState = await mediaClient.file.getCurrentState(id, {
|
|
55
|
+
collectionName
|
|
56
|
+
});
|
|
57
|
+
if (fileState.status === 'error') {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const contextId = this.getNodeContextId() || (await this.getObjectId());
|
|
64
|
+
const {
|
|
65
|
+
name,
|
|
66
|
+
mimeType,
|
|
67
|
+
size
|
|
68
|
+
} = fileState;
|
|
69
|
+
const newAttrs = {
|
|
70
|
+
__fileName: name,
|
|
71
|
+
__fileMimeType: mimeType,
|
|
72
|
+
__fileSize: size,
|
|
73
|
+
__contextId: contextId
|
|
74
|
+
};
|
|
75
|
+
if (!hasPrivateAttrsChanged(attrs, newAttrs)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
return newAttrs;
|
|
79
|
+
});
|
|
80
|
+
_defineProperty(this, "updateMediaSingleFileAttrs", async () => {
|
|
81
|
+
const newAttrs = await this.getNewFileAttrsForNode();
|
|
82
|
+
const {
|
|
83
|
+
id
|
|
84
|
+
} = this.getAttrs();
|
|
85
|
+
if (id && newAttrs) {
|
|
86
|
+
updateAllMediaSingleNodesAttrs(id, newAttrs)(this.props.view.state, this.props.view.dispatch);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
_defineProperty(this, "updateNodeAttrs", async getPos => {
|
|
90
|
+
const newAttrs = await this.getNewFileAttrsForNode();
|
|
91
|
+
if (newAttrs) {
|
|
92
|
+
updateCurrentMediaNodeAttrs(newAttrs, {
|
|
93
|
+
node: this.props.node,
|
|
94
|
+
getPos
|
|
95
|
+
})(this.props.view.state, this.props.view.dispatch);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
_defineProperty(this, "getAttrs", () => {
|
|
99
|
+
const {
|
|
100
|
+
attrs
|
|
101
|
+
} = this.props.node;
|
|
102
|
+
if (attrs) {
|
|
103
|
+
return attrs;
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
});
|
|
107
|
+
_defineProperty(this, "getObjectId", async () => {
|
|
108
|
+
const contextIdentifierProvider = await this.props.contextIdentifierProvider;
|
|
109
|
+
return (contextIdentifierProvider === null || contextIdentifierProvider === void 0 ? void 0 : contextIdentifierProvider.objectId) || null;
|
|
110
|
+
});
|
|
111
|
+
_defineProperty(this, "uploadExternalMedia", async getPos => {
|
|
112
|
+
const {
|
|
113
|
+
node
|
|
114
|
+
} = this.props;
|
|
115
|
+
const mediaProvider = await this.props.mediaProvider;
|
|
116
|
+
if (node && mediaProvider) {
|
|
117
|
+
const uploadMediaClientConfig = mediaProvider.uploadMediaClientConfig;
|
|
118
|
+
if (!uploadMediaClientConfig || !node.attrs.url) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const mediaClient = getMediaClient(uploadMediaClientConfig);
|
|
122
|
+
const collection = mediaProvider.uploadParams && mediaProvider.uploadParams.collection;
|
|
123
|
+
try {
|
|
124
|
+
const uploader = await mediaClient.file.uploadExternal(node.attrs.url, collection);
|
|
125
|
+
const {
|
|
126
|
+
uploadableFileUpfrontIds,
|
|
127
|
+
dimensions
|
|
128
|
+
} = uploader;
|
|
129
|
+
const pos = getPos();
|
|
130
|
+
if (typeof pos !== 'number') {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
replaceExternalMedia(pos + 1, {
|
|
134
|
+
id: uploadableFileUpfrontIds.id,
|
|
135
|
+
collection,
|
|
136
|
+
height: dimensions.height,
|
|
137
|
+
width: dimensions.width,
|
|
138
|
+
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey
|
|
139
|
+
})(this.props.view.state, this.props.view.dispatch);
|
|
140
|
+
} catch (e) {
|
|
141
|
+
//keep it as external media
|
|
142
|
+
if (this.props.dispatchAnalyticsEvent) {
|
|
143
|
+
this.props.dispatchAnalyticsEvent({
|
|
144
|
+
action: ACTION.UPLOAD_EXTERNAL_FAIL,
|
|
145
|
+
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
146
|
+
eventType: EVENT_TYPE.OPERATIONAL
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
_defineProperty(this, "getNodeContextId", () => {
|
|
153
|
+
const attrs = this.getAttrs();
|
|
154
|
+
if (!attrs || attrs.type !== 'file') {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
return attrs.__contextId || null;
|
|
158
|
+
});
|
|
159
|
+
_defineProperty(this, "updateDimensions", dimensions => {
|
|
160
|
+
updateAllMediaSingleNodesAttrs(dimensions.id, {
|
|
161
|
+
height: dimensions.height,
|
|
162
|
+
width: dimensions.width
|
|
163
|
+
})(this.props.view.state, this.props.view.dispatch);
|
|
164
|
+
});
|
|
165
|
+
_defineProperty(this, "hasDifferentContextId", async () => {
|
|
166
|
+
const nodeContextId = this.getNodeContextId();
|
|
167
|
+
const currentContextId = await this.getObjectId();
|
|
168
|
+
if (nodeContextId && currentContextId && nodeContextId !== currentContextId) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
});
|
|
173
|
+
_defineProperty(this, "isNodeFromDifferentCollection", async () => {
|
|
174
|
+
const mediaProvider = await this.props.mediaProvider;
|
|
175
|
+
if (!mediaProvider || !mediaProvider.uploadParams) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
const currentCollectionName = mediaProvider.uploadParams.collection;
|
|
179
|
+
const attrs = this.getAttrs();
|
|
180
|
+
if (!attrs || attrs.type !== 'file') {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const {
|
|
184
|
+
collection: nodeCollection,
|
|
185
|
+
__contextId
|
|
186
|
+
} = attrs;
|
|
187
|
+
const contextId = __contextId || (await this.getObjectId());
|
|
188
|
+
if (contextId && currentCollectionName !== nodeCollection) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
return false;
|
|
192
|
+
});
|
|
193
|
+
_defineProperty(this, "copyNodeFromBlobUrl", async getPos => {
|
|
194
|
+
const attrs = this.getAttrs();
|
|
195
|
+
if (!attrs || attrs.type !== 'external') {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const {
|
|
199
|
+
url
|
|
200
|
+
} = attrs;
|
|
201
|
+
const mediaAttrs = getAttrsFromUrl(url);
|
|
202
|
+
if (!mediaAttrs) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const mediaProvider = await this.props.mediaProvider;
|
|
206
|
+
if (!mediaProvider || !mediaProvider.uploadParams) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const currentCollectionName = mediaProvider.uploadParams.collection;
|
|
210
|
+
const {
|
|
211
|
+
contextId,
|
|
212
|
+
id,
|
|
213
|
+
collection,
|
|
214
|
+
height,
|
|
215
|
+
width,
|
|
216
|
+
mimeType,
|
|
217
|
+
name,
|
|
218
|
+
size
|
|
219
|
+
} = mediaAttrs;
|
|
220
|
+
const uploadMediaClientConfig = mediaProvider.uploadMediaClientConfig;
|
|
221
|
+
if (!uploadMediaClientConfig || !uploadMediaClientConfig.getAuthFromContext) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const mediaClient = getMediaClient(uploadMediaClientConfig);
|
|
225
|
+
const auth = await uploadMediaClientConfig.getAuthFromContext(contextId);
|
|
226
|
+
const source = {
|
|
227
|
+
id,
|
|
228
|
+
collection,
|
|
229
|
+
authProvider: () => Promise.resolve(auth)
|
|
230
|
+
};
|
|
231
|
+
const destination = {
|
|
232
|
+
collection: currentCollectionName,
|
|
233
|
+
authProvider: uploadMediaClientConfig.authProvider,
|
|
234
|
+
occurrenceKey: uuidV4()
|
|
235
|
+
};
|
|
236
|
+
const mediaFile = await mediaClient.file.copyFile(source, destination);
|
|
237
|
+
const pos = getPos();
|
|
238
|
+
if (typeof pos !== 'number') {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
replaceExternalMedia(pos + 1, {
|
|
242
|
+
id: mediaFile.id,
|
|
243
|
+
collection: currentCollectionName,
|
|
244
|
+
height,
|
|
245
|
+
width,
|
|
246
|
+
__fileName: name,
|
|
247
|
+
__fileMimeType: mimeType,
|
|
248
|
+
__fileSize: size
|
|
249
|
+
})(this.props.view.state, this.props.view.dispatch);
|
|
250
|
+
});
|
|
251
|
+
// Copies the pasted node into the current collection using a getPos handler
|
|
252
|
+
_defineProperty(this, "copyNodeFromPos", async (getPos, traceContext) => {
|
|
253
|
+
const attrs = this.getAttrs();
|
|
254
|
+
if ((attrs === null || attrs === void 0 ? void 0 : attrs.type) !== 'file') {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const copiedAttrs = await this.copyFile(attrs.id, attrs.collection, traceContext);
|
|
258
|
+
if (!copiedAttrs) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
updateCurrentMediaNodeAttrs(copiedAttrs, {
|
|
262
|
+
node: this.props.node,
|
|
263
|
+
getPos
|
|
264
|
+
})(this.props.view.state, this.props.view.dispatch);
|
|
265
|
+
});
|
|
266
|
+
// Copies the pasted node into the current collection
|
|
267
|
+
_defineProperty(this, "copyNode", async traceContext => {
|
|
268
|
+
const attrs = this.getAttrs();
|
|
269
|
+
const {
|
|
270
|
+
view
|
|
271
|
+
} = this.props;
|
|
272
|
+
if ((attrs === null || attrs === void 0 ? void 0 : attrs.type) !== 'file') {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const copiedAttrs = await this.copyFile(attrs.id, attrs.collection, traceContext);
|
|
276
|
+
if (!copiedAttrs) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
updateMediaSingleNodeAttrs(attrs.id, copiedAttrs)(view.state, view.dispatch);
|
|
280
|
+
});
|
|
281
|
+
_defineProperty(this, "copyFile", async (id, collection, traceContext) => {
|
|
282
|
+
const mediaProvider = await this.props.mediaProvider;
|
|
283
|
+
if (!(mediaProvider !== null && mediaProvider !== void 0 && mediaProvider.uploadParams)) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const nodeContextId = this.getNodeContextId();
|
|
287
|
+
const uploadMediaClientConfig = mediaProvider.uploadMediaClientConfig;
|
|
288
|
+
if (!(uploadMediaClientConfig !== null && uploadMediaClientConfig !== void 0 && uploadMediaClientConfig.getAuthFromContext) || !nodeContextId) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const mediaClient = getMediaClient(uploadMediaClientConfig);
|
|
292
|
+
const auth = await uploadMediaClientConfig.getAuthFromContext(nodeContextId);
|
|
293
|
+
const objectId = await this.getObjectId();
|
|
294
|
+
const source = {
|
|
295
|
+
id,
|
|
296
|
+
collection,
|
|
297
|
+
authProvider: () => Promise.resolve(auth)
|
|
298
|
+
};
|
|
299
|
+
const currentCollectionName = mediaProvider.uploadParams.collection;
|
|
300
|
+
const destination = {
|
|
301
|
+
collection: currentCollectionName,
|
|
302
|
+
authProvider: uploadMediaClientConfig.authProvider,
|
|
303
|
+
occurrenceKey: uuidV4()
|
|
304
|
+
};
|
|
305
|
+
const mediaFile = await mediaClient.file.copyFile(source, destination, undefined, traceContext);
|
|
306
|
+
return {
|
|
307
|
+
id: mediaFile.id,
|
|
308
|
+
collection: currentCollectionName,
|
|
309
|
+
__contextId: objectId
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
this.props = props;
|
|
313
|
+
}
|
|
314
|
+
isMediaBlobUrl() {
|
|
315
|
+
const attrs = this.getAttrs();
|
|
316
|
+
return !!(attrs && attrs.type === 'external' && isMediaBlobUrl(attrs.url));
|
|
317
|
+
}
|
|
318
|
+
async getRemoteDimensions() {
|
|
319
|
+
const mediaProvider = await this.props.mediaProvider;
|
|
320
|
+
const {
|
|
321
|
+
mediaOptions
|
|
322
|
+
} = this.props;
|
|
323
|
+
const attrs = this.getAttrs();
|
|
324
|
+
if (!mediaProvider || !attrs) {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
const {
|
|
328
|
+
height,
|
|
329
|
+
width
|
|
330
|
+
} = attrs;
|
|
331
|
+
if (attrs.type === 'external' || !attrs.id) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
const {
|
|
335
|
+
id,
|
|
336
|
+
collection
|
|
337
|
+
} = attrs;
|
|
338
|
+
if (height && width) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// can't fetch remote dimensions on mobile, so we'll default them
|
|
343
|
+
if (mediaOptions && !mediaOptions.allowRemoteDimensionsFetch) {
|
|
344
|
+
return {
|
|
345
|
+
id,
|
|
346
|
+
height: DEFAULT_IMAGE_HEIGHT,
|
|
347
|
+
width: DEFAULT_IMAGE_WIDTH
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
const viewMediaClientConfig = mediaProvider.viewMediaClientConfig;
|
|
351
|
+
const mediaClient = getMediaClient(viewMediaClientConfig);
|
|
352
|
+
const currentState = await mediaClient.file.getCurrentState(id, {
|
|
353
|
+
collectionName: collection
|
|
354
|
+
});
|
|
355
|
+
if (!isImageRepresentationReady(currentState)) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
const imageMetadata = await mediaClient.getImageMetadata(id, {
|
|
359
|
+
collection
|
|
360
|
+
});
|
|
361
|
+
if (!imageMetadata || !imageMetadata.original) {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
id,
|
|
366
|
+
height: imageMetadata.original.height || DEFAULT_IMAGE_HEIGHT,
|
|
367
|
+
width: imageMetadata.original.width || DEFAULT_IMAGE_WIDTH
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
async handleExternalMedia(getPos) {
|
|
371
|
+
if (this.isMediaBlobUrl()) {
|
|
372
|
+
try {
|
|
373
|
+
await this.copyNodeFromBlobUrl(getPos);
|
|
374
|
+
} catch (e) {
|
|
375
|
+
await this.uploadExternalMedia(getPos);
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
await this.uploadExternalMedia(getPos);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const hasPrivateAttrsChanged = (currentAttrs, newAttrs) => {
|
|
383
|
+
return currentAttrs.__fileName !== newAttrs.__fileName || currentAttrs.__fileMimeType !== newAttrs.__fileMimeType || currentAttrs.__fileSize !== newAttrs.__fileSize || currentAttrs.__contextId !== newAttrs.__contextId;
|
|
384
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
|
+
import { DEFAULT_IMAGE_HEIGHT, DEFAULT_IMAGE_WIDTH } from '@atlaskit/editor-common/media-single';
|
|
5
|
+
import { WithProviders } from '@atlaskit/editor-common/provider-factory';
|
|
6
|
+
import { SelectionBasedNodeView } from '@atlaskit/editor-common/selection-based-node-view';
|
|
7
|
+
import { getAttrsFromUrl } from '@atlaskit/media-client';
|
|
8
|
+
import { isMediaBlobUrlFromAttrs } from '../../utils/media-common';
|
|
9
|
+
import MediaNode from './media';
|
|
10
|
+
const MediaNodeWithProviders = ({
|
|
11
|
+
pluginInjectionApi,
|
|
12
|
+
innerComponent
|
|
13
|
+
}) => {
|
|
14
|
+
const {
|
|
15
|
+
widthState
|
|
16
|
+
} = useSharedPluginState(pluginInjectionApi, ['width']);
|
|
17
|
+
return innerComponent({
|
|
18
|
+
width: widthState
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
function isMediaDecorationSpec(decoration) {
|
|
22
|
+
return decoration.spec.type !== undefined && decoration.spec.selected !== undefined;
|
|
23
|
+
}
|
|
24
|
+
class MediaNodeView extends SelectionBasedNodeView {
|
|
25
|
+
constructor(...args) {
|
|
26
|
+
super(...args);
|
|
27
|
+
_defineProperty(this, "isSelected", false);
|
|
28
|
+
_defineProperty(this, "renderMediaNodeWithState", (mediaProvider, contextIdentifierProvider) => {
|
|
29
|
+
return ({
|
|
30
|
+
width: editorWidth
|
|
31
|
+
}) => {
|
|
32
|
+
const getPos = this.getPos;
|
|
33
|
+
const {
|
|
34
|
+
mediaOptions
|
|
35
|
+
} = this.reactComponentProps;
|
|
36
|
+
const attrs = this.getAttrs();
|
|
37
|
+
const url = attrs.type === 'external' ? attrs.url : '';
|
|
38
|
+
let {
|
|
39
|
+
width,
|
|
40
|
+
height
|
|
41
|
+
} = attrs;
|
|
42
|
+
if (this.isMediaBlobUrl()) {
|
|
43
|
+
const urlAttrs = getAttrsFromUrl(url);
|
|
44
|
+
if (urlAttrs) {
|
|
45
|
+
const {
|
|
46
|
+
width: urlWidth,
|
|
47
|
+
height: urlHeight
|
|
48
|
+
} = urlAttrs;
|
|
49
|
+
width = width || urlWidth;
|
|
50
|
+
height = height || urlHeight;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
width = width || DEFAULT_IMAGE_WIDTH;
|
|
54
|
+
height = height || DEFAULT_IMAGE_HEIGHT;
|
|
55
|
+
const maxDimensions = {
|
|
56
|
+
width: `${editorWidth.width}px`,
|
|
57
|
+
height: `${height / width * editorWidth.width}px`
|
|
58
|
+
};
|
|
59
|
+
const originalDimensions = {
|
|
60
|
+
width,
|
|
61
|
+
height
|
|
62
|
+
};
|
|
63
|
+
return /*#__PURE__*/React.createElement(MediaNode, {
|
|
64
|
+
view: this.view,
|
|
65
|
+
node: this.node,
|
|
66
|
+
getPos: getPos,
|
|
67
|
+
selected: this.nodeInsideSelection(),
|
|
68
|
+
originalDimensions: originalDimensions,
|
|
69
|
+
maxDimensions: maxDimensions,
|
|
70
|
+
url: url,
|
|
71
|
+
mediaProvider: mediaProvider,
|
|
72
|
+
contextIdentifierProvider: contextIdentifierProvider,
|
|
73
|
+
mediaOptions: mediaOptions
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
_defineProperty(this, "renderMediaNodeWithProviders", ({
|
|
78
|
+
mediaProvider,
|
|
79
|
+
contextIdentifierProvider
|
|
80
|
+
}) => {
|
|
81
|
+
const {
|
|
82
|
+
pluginInjectionApi
|
|
83
|
+
} = this.reactComponentProps;
|
|
84
|
+
return /*#__PURE__*/React.createElement(MediaNodeWithProviders, {
|
|
85
|
+
pluginInjectionApi: pluginInjectionApi,
|
|
86
|
+
innerComponent: this.renderMediaNodeWithState(mediaProvider, contextIdentifierProvider)
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
createDomRef() {
|
|
91
|
+
const domRef = document.createElement('div');
|
|
92
|
+
if (this.reactComponentProps.mediaOptions && this.reactComponentProps.mediaOptions.allowMediaSingleEditable) {
|
|
93
|
+
// workaround Chrome bug in https://product-fabric.atlassian.net/browse/ED-5379
|
|
94
|
+
// see also: https://github.com/ProseMirror/prosemirror/issues/884
|
|
95
|
+
domRef.contentEditable = 'true';
|
|
96
|
+
}
|
|
97
|
+
return domRef;
|
|
98
|
+
}
|
|
99
|
+
viewShouldUpdate(nextNode, decorations) {
|
|
100
|
+
const hasMediaNodeSelectedDecoration = decorations.some(decoration => isMediaDecorationSpec(decoration) && decoration.spec.type === 'media' && decoration.spec.selected);
|
|
101
|
+
if (this.isSelected !== hasMediaNodeSelectedDecoration) {
|
|
102
|
+
this.isSelected = hasMediaNodeSelectedDecoration;
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (this.node.attrs !== nextNode.attrs) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return super.viewShouldUpdate(nextNode, decorations);
|
|
109
|
+
}
|
|
110
|
+
stopEvent(event) {
|
|
111
|
+
// Don't trap right click events on media node
|
|
112
|
+
if (['mousedown', 'contextmenu'].indexOf(event.type) !== -1) {
|
|
113
|
+
const mouseEvent = event;
|
|
114
|
+
if (mouseEvent.button === 2) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
getAttrs() {
|
|
121
|
+
const {
|
|
122
|
+
attrs
|
|
123
|
+
} = this.node;
|
|
124
|
+
return attrs;
|
|
125
|
+
}
|
|
126
|
+
isMediaBlobUrl() {
|
|
127
|
+
const attrs = this.getAttrs();
|
|
128
|
+
return isMediaBlobUrlFromAttrs(attrs);
|
|
129
|
+
}
|
|
130
|
+
render() {
|
|
131
|
+
const {
|
|
132
|
+
providerFactory
|
|
133
|
+
} = this.reactComponentProps;
|
|
134
|
+
return /*#__PURE__*/React.createElement(WithProviders, {
|
|
135
|
+
providers: ['mediaProvider', 'contextIdentifierProvider'],
|
|
136
|
+
providerFactory: providerFactory,
|
|
137
|
+
renderNode: this.renderMediaNodeWithProviders
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export const ReactMediaNode = (portalProviderAPI, eventDispatcher, providerFactory, mediaOptions = {}, pluginInjectionApi) => (node, view, getPos) => {
|
|
142
|
+
const hasIntlContext = true;
|
|
143
|
+
return new MediaNodeView(node, view, getPos, portalProviderAPI, eventDispatcher, {
|
|
144
|
+
eventDispatcher,
|
|
145
|
+
providerFactory,
|
|
146
|
+
mediaOptions,
|
|
147
|
+
pluginInjectionApi
|
|
148
|
+
}, undefined, undefined, undefined, hasIntlContext).init();
|
|
149
|
+
};
|