@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,538 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import { buildLayoutButtons } from '@atlaskit/editor-common/card';
|
|
4
|
+
import { calcMinWidth, DEFAULT_IMAGE_HEIGHT, DEFAULT_IMAGE_WIDTH } from '@atlaskit/editor-common/media-single';
|
|
5
|
+
import commonMessages, { cardMessages } from '@atlaskit/editor-common/messages';
|
|
6
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import { findParentNodeOfType, hasParentNodeOfType, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
|
|
8
|
+
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
9
|
+
import DownloadIcon from '@atlaskit/icon/glyph/download';
|
|
10
|
+
import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
|
|
11
|
+
import { mediaFilmstripItemDOMSelector } from '@atlaskit/media-filmstrip';
|
|
12
|
+
import { messages } from '@atlaskit/media-ui';
|
|
13
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
|
+
import { showLinkingToolbar } from '../commands/linking';
|
|
15
|
+
import { MediaInlineNodeSelector, MediaSingleNodeSelector } from '../nodeviews/styles';
|
|
16
|
+
import { getPluginState as getMediaAltTextPluginState } from '../pm-plugins/alt-text';
|
|
17
|
+
import { getMediaLinkingState } from '../pm-plugins/linking';
|
|
18
|
+
import { stateKey } from '../pm-plugins/plugin-key';
|
|
19
|
+
import ImageBorderItem from '../ui/ImageBorder';
|
|
20
|
+
import { FullWidthDisplay, PixelEntry } from '../ui/PixelEntry';
|
|
21
|
+
import { currentMediaNodeBorderMark } from '../utils/current-media-node';
|
|
22
|
+
import { isVideo } from '../utils/media-single';
|
|
23
|
+
import { altTextButton, getAltTextToolbar } from './alt-text';
|
|
24
|
+
import { changeInlineToMediaCard, changeMediaCardToInline, removeInlineCard, setBorderMark, toggleBorderMark, updateMediaSingleWidth } from './commands';
|
|
25
|
+
import { FilePreviewItem } from './filePreviewItem';
|
|
26
|
+
import { shouldShowImageBorder } from './imageBorder';
|
|
27
|
+
import { getLinkingToolbar, shouldShowMediaLinkToolbar } from './linking';
|
|
28
|
+
import { LinkToolbarAppearance } from './linking-toolbar-appearance';
|
|
29
|
+
import { calcNewLayout, downloadMedia, getMaxToolbarWidth, getPixelWidthOfElement, getSelectedMediaSingle, removeMediaGroupNode } from './utils';
|
|
30
|
+
const remove = (state, dispatch) => {
|
|
31
|
+
if (dispatch) {
|
|
32
|
+
dispatch(removeSelectedNode(state.tr));
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
};
|
|
36
|
+
const handleRemoveMediaGroup = (state, dispatch) => {
|
|
37
|
+
const tr = removeMediaGroupNode(state);
|
|
38
|
+
if (dispatch) {
|
|
39
|
+
dispatch(tr);
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
const generateMediaCardFloatingToolbar = (state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI) => {
|
|
44
|
+
const {
|
|
45
|
+
mediaGroup
|
|
46
|
+
} = state.schema.nodes;
|
|
47
|
+
const items = [{
|
|
48
|
+
id: 'editor.media.view.switcher',
|
|
49
|
+
type: 'dropdown',
|
|
50
|
+
title: intl.formatMessage(messages.changeView),
|
|
51
|
+
options: [{
|
|
52
|
+
id: 'editor.media.view.switcher.inline',
|
|
53
|
+
title: intl.formatMessage(cardMessages.inline),
|
|
54
|
+
selected: false,
|
|
55
|
+
disabled: false,
|
|
56
|
+
onClick: changeMediaCardToInline(editorAnalyticsAPI),
|
|
57
|
+
testId: 'inline-appearance'
|
|
58
|
+
}, {
|
|
59
|
+
id: 'editor.media.view.switcher.thumbnail',
|
|
60
|
+
title: intl.formatMessage(messages.displayThumbnail),
|
|
61
|
+
selected: true,
|
|
62
|
+
disabled: false,
|
|
63
|
+
onClick: () => {
|
|
64
|
+
return true;
|
|
65
|
+
},
|
|
66
|
+
testId: 'thumbnail-appearance'
|
|
67
|
+
}]
|
|
68
|
+
}, {
|
|
69
|
+
type: 'separator'
|
|
70
|
+
}, {
|
|
71
|
+
type: 'custom',
|
|
72
|
+
fallback: [],
|
|
73
|
+
render: () => {
|
|
74
|
+
return /*#__PURE__*/React.createElement(FilePreviewItem, {
|
|
75
|
+
key: "editor.media.card.preview",
|
|
76
|
+
mediaPluginState: mediaPluginState,
|
|
77
|
+
intl: intl
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
type: 'separator'
|
|
82
|
+
}, {
|
|
83
|
+
id: 'editor.media.card.download',
|
|
84
|
+
type: 'button',
|
|
85
|
+
icon: DownloadIcon,
|
|
86
|
+
onClick: () => {
|
|
87
|
+
downloadMedia(mediaPluginState);
|
|
88
|
+
return true;
|
|
89
|
+
},
|
|
90
|
+
title: intl.formatMessage(messages.download)
|
|
91
|
+
}, {
|
|
92
|
+
type: 'separator'
|
|
93
|
+
}, {
|
|
94
|
+
type: 'copy-button',
|
|
95
|
+
items: [{
|
|
96
|
+
state,
|
|
97
|
+
formatMessage: intl.formatMessage,
|
|
98
|
+
nodeType: mediaGroup
|
|
99
|
+
}, {
|
|
100
|
+
type: 'separator'
|
|
101
|
+
}]
|
|
102
|
+
}, {
|
|
103
|
+
id: 'editor.media.delete',
|
|
104
|
+
type: 'button',
|
|
105
|
+
appearance: 'danger',
|
|
106
|
+
focusEditoronEnter: true,
|
|
107
|
+
icon: RemoveIcon,
|
|
108
|
+
onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaGroup, true),
|
|
109
|
+
onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaGroup, false),
|
|
110
|
+
onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaGroup, true),
|
|
111
|
+
onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaGroup, false),
|
|
112
|
+
title: intl.formatMessage(commonMessages.remove),
|
|
113
|
+
onClick: handleRemoveMediaGroup,
|
|
114
|
+
testId: 'media-toolbar-remove-button'
|
|
115
|
+
}];
|
|
116
|
+
return items;
|
|
117
|
+
};
|
|
118
|
+
const generateMediaInlineFloatingToolbar = (state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI) => {
|
|
119
|
+
const {
|
|
120
|
+
mediaInline
|
|
121
|
+
} = state.schema.nodes;
|
|
122
|
+
const items = [{
|
|
123
|
+
id: 'editor.media.view.switcher',
|
|
124
|
+
type: 'dropdown',
|
|
125
|
+
title: intl.formatMessage(messages.changeView),
|
|
126
|
+
options: [{
|
|
127
|
+
id: 'editor.media.view.switcher.inline',
|
|
128
|
+
title: intl.formatMessage(cardMessages.inline),
|
|
129
|
+
selected: true,
|
|
130
|
+
disabled: false,
|
|
131
|
+
onClick: () => {
|
|
132
|
+
return true;
|
|
133
|
+
},
|
|
134
|
+
testId: 'inline-appearance'
|
|
135
|
+
}, {
|
|
136
|
+
id: 'editor.media.view.switcher.thumbnail',
|
|
137
|
+
title: intl.formatMessage(messages.displayThumbnail),
|
|
138
|
+
selected: false,
|
|
139
|
+
disabled: false,
|
|
140
|
+
onClick: changeInlineToMediaCard(editorAnalyticsAPI),
|
|
141
|
+
testId: 'thumbnail-appearance'
|
|
142
|
+
}]
|
|
143
|
+
}, {
|
|
144
|
+
type: 'separator'
|
|
145
|
+
}, {
|
|
146
|
+
type: 'custom',
|
|
147
|
+
fallback: [],
|
|
148
|
+
render: () => {
|
|
149
|
+
return /*#__PURE__*/React.createElement(FilePreviewItem, {
|
|
150
|
+
key: "editor.media.card.preview",
|
|
151
|
+
mediaPluginState: mediaPluginState,
|
|
152
|
+
intl: intl
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}, {
|
|
156
|
+
type: 'separator'
|
|
157
|
+
}, {
|
|
158
|
+
id: 'editor.media.card.download',
|
|
159
|
+
type: 'button',
|
|
160
|
+
icon: DownloadIcon,
|
|
161
|
+
onClick: () => {
|
|
162
|
+
downloadMedia(mediaPluginState);
|
|
163
|
+
return true;
|
|
164
|
+
},
|
|
165
|
+
title: intl.formatMessage(messages.download)
|
|
166
|
+
}, {
|
|
167
|
+
type: 'separator'
|
|
168
|
+
}, {
|
|
169
|
+
type: 'copy-button',
|
|
170
|
+
items: [{
|
|
171
|
+
state,
|
|
172
|
+
formatMessage: intl.formatMessage,
|
|
173
|
+
nodeType: mediaInline
|
|
174
|
+
}, {
|
|
175
|
+
type: 'separator'
|
|
176
|
+
}]
|
|
177
|
+
}, {
|
|
178
|
+
id: 'editor.media.delete',
|
|
179
|
+
type: 'button',
|
|
180
|
+
appearance: 'danger',
|
|
181
|
+
focusEditoronEnter: true,
|
|
182
|
+
icon: RemoveIcon,
|
|
183
|
+
onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaInline, true),
|
|
184
|
+
onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaInline, false),
|
|
185
|
+
onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaInline, true),
|
|
186
|
+
onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaInline, false),
|
|
187
|
+
title: intl.formatMessage(commonMessages.remove),
|
|
188
|
+
onClick: removeInlineCard,
|
|
189
|
+
testId: 'media-toolbar-remove-button'
|
|
190
|
+
}];
|
|
191
|
+
return items;
|
|
192
|
+
};
|
|
193
|
+
const generateMediaSingleFloatingToolbar = (state, intl, options, pluginState, mediaLinkingState, pluginInjectionApi, getEditorFeatureFlags) => {
|
|
194
|
+
var _pluginInjectionApi$d;
|
|
195
|
+
const {
|
|
196
|
+
mediaSingle
|
|
197
|
+
} = state.schema.nodes;
|
|
198
|
+
const {
|
|
199
|
+
allowResizing,
|
|
200
|
+
allowLinking,
|
|
201
|
+
allowAdvancedToolBarOptions,
|
|
202
|
+
allowResizingInTables,
|
|
203
|
+
allowAltTextOnImages
|
|
204
|
+
} = options;
|
|
205
|
+
let toolbarButtons = [];
|
|
206
|
+
const {
|
|
207
|
+
hoverDecoration
|
|
208
|
+
} = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.decorations.actions) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {};
|
|
209
|
+
if (shouldShowImageBorder(state)) {
|
|
210
|
+
toolbarButtons.push({
|
|
211
|
+
type: 'custom',
|
|
212
|
+
fallback: [],
|
|
213
|
+
render: editorView => {
|
|
214
|
+
if (!editorView) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
const {
|
|
218
|
+
dispatch,
|
|
219
|
+
state
|
|
220
|
+
} = editorView;
|
|
221
|
+
const borderMark = currentMediaNodeBorderMark(state);
|
|
222
|
+
return /*#__PURE__*/React.createElement(ImageBorderItem, {
|
|
223
|
+
toggleBorder: () => {
|
|
224
|
+
var _pluginInjectionApi$a;
|
|
225
|
+
toggleBorderMark(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions)(state, dispatch);
|
|
226
|
+
},
|
|
227
|
+
setBorder: attrs => {
|
|
228
|
+
var _pluginInjectionApi$a2;
|
|
229
|
+
setBorderMark(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions)(attrs)(state, dispatch);
|
|
230
|
+
},
|
|
231
|
+
borderMark: borderMark,
|
|
232
|
+
intl: intl
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
toolbarButtons.push({
|
|
237
|
+
type: 'separator'
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
if (allowAdvancedToolBarOptions) {
|
|
241
|
+
var _pluginInjectionApi$a3;
|
|
242
|
+
const widthPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.width;
|
|
243
|
+
let isChangingLayoutDisabled = false;
|
|
244
|
+
if (getBooleanFF('platform.editor.media.extended-resize-experience')) {
|
|
245
|
+
var _widthPlugin$sharedSt;
|
|
246
|
+
const contentWidth = widthPlugin === null || widthPlugin === void 0 ? void 0 : (_widthPlugin$sharedSt = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt === void 0 ? void 0 : _widthPlugin$sharedSt.lineLength;
|
|
247
|
+
const selectedNode = getSelectedMediaSingle(state);
|
|
248
|
+
const selectedNodeMaxWidth = pluginState.currentMaxWidth || contentWidth;
|
|
249
|
+
if (selectedNode && selectedNodeMaxWidth && selectedNode.node.attrs.width >= selectedNodeMaxWidth) {
|
|
250
|
+
isChangingLayoutDisabled = true;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const layoutButtons = buildLayoutButtons(state, intl, state.schema.nodes.mediaSingle, widthPlugin, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a3 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a3 === void 0 ? void 0 : _pluginInjectionApi$a3.actions, allowResizing, allowResizingInTables, true, true, isChangingLayoutDisabled);
|
|
254
|
+
toolbarButtons = [...toolbarButtons, ...layoutButtons];
|
|
255
|
+
if (layoutButtons.length) {
|
|
256
|
+
toolbarButtons.push({
|
|
257
|
+
type: 'separator'
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Pixel Entry Toolbar Support
|
|
262
|
+
const {
|
|
263
|
+
selection
|
|
264
|
+
} = state;
|
|
265
|
+
const isWithinTable = hasParentNodeOfType([state.schema.nodes.table])(selection);
|
|
266
|
+
if (getBooleanFF('platform.editor.media.extended-resize-experience') && allowResizing && (!isWithinTable || allowResizingInTables === true)) {
|
|
267
|
+
const selectedMediaSingleNode = getSelectedMediaSingle(state);
|
|
268
|
+
const sizeInput = {
|
|
269
|
+
type: 'custom',
|
|
270
|
+
fallback: [],
|
|
271
|
+
render: editorView => {
|
|
272
|
+
var _widthPlugin$sharedSt2, _pluginInjectionApi$m;
|
|
273
|
+
if (!editorView || !selectedMediaSingleNode) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
const {
|
|
277
|
+
state,
|
|
278
|
+
dispatch
|
|
279
|
+
} = editorView;
|
|
280
|
+
const contentWidth = (widthPlugin === null || widthPlugin === void 0 ? void 0 : (_widthPlugin$sharedSt2 = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt2 === void 0 ? void 0 : _widthPlugin$sharedSt2.lineLength) || akEditorDefaultLayoutWidth;
|
|
281
|
+
const selectedMediaNode = selectedMediaSingleNode.node.content.firstChild;
|
|
282
|
+
if (!selectedMediaNode) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
const {
|
|
286
|
+
width: mediaSingleWidth,
|
|
287
|
+
widthType,
|
|
288
|
+
layout
|
|
289
|
+
} = selectedMediaSingleNode.node.attrs;
|
|
290
|
+
const {
|
|
291
|
+
width: mediaWidth,
|
|
292
|
+
height: mediaHeight
|
|
293
|
+
} = selectedMediaNode.attrs;
|
|
294
|
+
const maxWidthForNestedNode = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$m = pluginInjectionApi.media.sharedState.currentState()) === null || _pluginInjectionApi$m === void 0 ? void 0 : _pluginInjectionApi$m.currentMaxWidth;
|
|
295
|
+
const maxWidth = maxWidthForNestedNode || akEditorFullWidthLayoutWidth;
|
|
296
|
+
const isVideoFile = isVideo(selectedMediaNode.attrs.__fileMimeType);
|
|
297
|
+
const minWidth = calcMinWidth(isVideoFile, maxWidthForNestedNode || contentWidth);
|
|
298
|
+
const isLegacy = widthType !== 'pixel';
|
|
299
|
+
const pixelWidthFromElement = getPixelWidthOfElement(editorView, selectedMediaSingleNode.pos + 1,
|
|
300
|
+
// get pos of media node
|
|
301
|
+
mediaWidth || DEFAULT_IMAGE_WIDTH);
|
|
302
|
+
const pixelWidth = isLegacy ? pixelWidthFromElement : mediaSingleWidth;
|
|
303
|
+
return /*#__PURE__*/React.createElement(PixelEntry, {
|
|
304
|
+
intl: intl,
|
|
305
|
+
width: pluginState.isResizing ? pluginState.resizingWidth : pixelWidth,
|
|
306
|
+
showMigration: !pluginState.isResizing && isLegacy,
|
|
307
|
+
mediaWidth: mediaWidth || DEFAULT_IMAGE_WIDTH,
|
|
308
|
+
mediaHeight: mediaHeight || DEFAULT_IMAGE_HEIGHT,
|
|
309
|
+
minWidth: minWidth,
|
|
310
|
+
maxWidth: maxWidth,
|
|
311
|
+
onChange: valid => {
|
|
312
|
+
if (valid) {
|
|
313
|
+
hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaSingle, true, 'warning')(editorView.state, dispatch, editorView);
|
|
314
|
+
} else {
|
|
315
|
+
hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaSingle, false)(editorView.state, dispatch, editorView);
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
onSubmit: ({
|
|
319
|
+
width,
|
|
320
|
+
validation
|
|
321
|
+
}) => {
|
|
322
|
+
var _pluginInjectionApi$a4;
|
|
323
|
+
const newLayout = calcNewLayout(width, layout, contentWidth, options.fullWidthEnabled);
|
|
324
|
+
updateMediaSingleWidth(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions)(width, validation, newLayout)(state, dispatch);
|
|
325
|
+
},
|
|
326
|
+
onMigrate: () => {
|
|
327
|
+
const tr = state.tr.setNodeMarkup(selectedMediaSingleNode.pos, undefined, {
|
|
328
|
+
...selectedMediaSingleNode.node.attrs,
|
|
329
|
+
width: pixelWidthFromElement,
|
|
330
|
+
widthType: 'pixel'
|
|
331
|
+
});
|
|
332
|
+
tr.setMeta('scrollIntoView', false);
|
|
333
|
+
tr.setSelection(NodeSelection.create(tr.doc, selectedMediaSingleNode.pos));
|
|
334
|
+
dispatch(tr);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
if (pluginState.isResizing) {
|
|
340
|
+
// If the image is resizing
|
|
341
|
+
// then return pixel entry component or full width label as the only toolbar item
|
|
342
|
+
if (!selectedMediaSingleNode) {
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
345
|
+
const {
|
|
346
|
+
layout
|
|
347
|
+
} = selectedMediaSingleNode.node.attrs;
|
|
348
|
+
if (layout === 'full-width') {
|
|
349
|
+
const fullWidthLabel = {
|
|
350
|
+
type: 'custom',
|
|
351
|
+
fallback: [],
|
|
352
|
+
render: () => {
|
|
353
|
+
return /*#__PURE__*/React.createElement(FullWidthDisplay, {
|
|
354
|
+
intl: intl
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
return [fullWidthLabel];
|
|
359
|
+
}
|
|
360
|
+
return [sizeInput];
|
|
361
|
+
}
|
|
362
|
+
toolbarButtons.push(sizeInput);
|
|
363
|
+
toolbarButtons.push({
|
|
364
|
+
type: 'separator'
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
if (allowLinking && shouldShowMediaLinkToolbar(state)) {
|
|
368
|
+
toolbarButtons.push({
|
|
369
|
+
type: 'custom',
|
|
370
|
+
fallback: [],
|
|
371
|
+
render: (editorView, idx) => {
|
|
372
|
+
if (editorView !== null && editorView !== void 0 && editorView.state) {
|
|
373
|
+
const editLink = () => {
|
|
374
|
+
if (editorView) {
|
|
375
|
+
const {
|
|
376
|
+
state,
|
|
377
|
+
dispatch
|
|
378
|
+
} = editorView;
|
|
379
|
+
showLinkingToolbar(state, dispatch);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
const openLink = () => {
|
|
383
|
+
if (editorView) {
|
|
384
|
+
var _pluginInjectionApi$a5;
|
|
385
|
+
const {
|
|
386
|
+
state: {
|
|
387
|
+
tr
|
|
388
|
+
},
|
|
389
|
+
dispatch
|
|
390
|
+
} = editorView;
|
|
391
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a5 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a5 === void 0 ? void 0 : _pluginInjectionApi$a5.actions.attachAnalyticsEvent({
|
|
392
|
+
eventType: EVENT_TYPE.TRACK,
|
|
393
|
+
action: ACTION.VISITED,
|
|
394
|
+
actionSubject: ACTION_SUBJECT.MEDIA,
|
|
395
|
+
actionSubjectId: ACTION_SUBJECT_ID.LINK
|
|
396
|
+
})(tr);
|
|
397
|
+
dispatch(tr);
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
return /*#__PURE__*/React.createElement(LinkToolbarAppearance, {
|
|
402
|
+
key: idx,
|
|
403
|
+
editorState: editorView.state,
|
|
404
|
+
intl: intl,
|
|
405
|
+
mediaLinkingState: mediaLinkingState,
|
|
406
|
+
onAddLink: editLink,
|
|
407
|
+
onEditLink: editLink,
|
|
408
|
+
onOpenLink: openLink
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (allowAltTextOnImages) {
|
|
417
|
+
var _pluginInjectionApi$a6;
|
|
418
|
+
toolbarButtons.push(altTextButton(intl, state, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a6 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a6 === void 0 ? void 0 : _pluginInjectionApi$a6.actions), {
|
|
419
|
+
type: 'separator'
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
const removeButton = {
|
|
423
|
+
id: 'editor.media.delete',
|
|
424
|
+
type: 'button',
|
|
425
|
+
appearance: 'danger',
|
|
426
|
+
focusEditoronEnter: true,
|
|
427
|
+
icon: RemoveIcon,
|
|
428
|
+
onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaSingle, true),
|
|
429
|
+
onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaSingle, false),
|
|
430
|
+
onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaSingle, true),
|
|
431
|
+
onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaSingle, false),
|
|
432
|
+
title: intl.formatMessage(commonMessages.remove),
|
|
433
|
+
onClick: remove,
|
|
434
|
+
testId: 'media-toolbar-remove-button'
|
|
435
|
+
};
|
|
436
|
+
const items = [...toolbarButtons, {
|
|
437
|
+
type: 'copy-button',
|
|
438
|
+
items: [{
|
|
439
|
+
state,
|
|
440
|
+
formatMessage: intl.formatMessage,
|
|
441
|
+
nodeType: mediaSingle
|
|
442
|
+
}, {
|
|
443
|
+
type: 'separator'
|
|
444
|
+
}]
|
|
445
|
+
}, removeButton];
|
|
446
|
+
return items;
|
|
447
|
+
};
|
|
448
|
+
export const floatingToolbar = (state, intl, options = {}, pluginInjectionApi) => {
|
|
449
|
+
var _pluginInjectionApi$d2;
|
|
450
|
+
const {
|
|
451
|
+
media,
|
|
452
|
+
mediaInline,
|
|
453
|
+
mediaSingle,
|
|
454
|
+
mediaGroup
|
|
455
|
+
} = state.schema.nodes;
|
|
456
|
+
const {
|
|
457
|
+
altTextValidator,
|
|
458
|
+
allowLinking,
|
|
459
|
+
allowAltTextOnImages,
|
|
460
|
+
providerFactory,
|
|
461
|
+
allowMediaInline,
|
|
462
|
+
allowResizing,
|
|
463
|
+
getEditorFeatureFlags
|
|
464
|
+
} = options;
|
|
465
|
+
const mediaPluginState = stateKey.getState(state);
|
|
466
|
+
const mediaLinkingState = getMediaLinkingState(state);
|
|
467
|
+
const {
|
|
468
|
+
hoverDecoration
|
|
469
|
+
} = (_pluginInjectionApi$d2 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.decorations.actions) !== null && _pluginInjectionApi$d2 !== void 0 ? _pluginInjectionApi$d2 : {};
|
|
470
|
+
if (!mediaPluginState) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const nodeType = allowMediaInline ? [mediaInline, mediaSingle, media] : [mediaSingle];
|
|
474
|
+
const baseToolbar = {
|
|
475
|
+
title: 'Media floating controls',
|
|
476
|
+
nodeType,
|
|
477
|
+
getDomRef: () => mediaPluginState.element
|
|
478
|
+
};
|
|
479
|
+
if (allowLinking && mediaLinkingState && mediaLinkingState.visible && shouldShowMediaLinkToolbar(state)) {
|
|
480
|
+
const linkingToolbar = getLinkingToolbar(baseToolbar, mediaLinkingState, state, intl, pluginInjectionApi, providerFactory);
|
|
481
|
+
if (linkingToolbar) {
|
|
482
|
+
return linkingToolbar;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (allowAltTextOnImages) {
|
|
486
|
+
const mediaAltTextPluginState = getMediaAltTextPluginState(state);
|
|
487
|
+
if (mediaAltTextPluginState.isAltTextEditorOpen) {
|
|
488
|
+
var _pluginInjectionApi$f;
|
|
489
|
+
return getAltTextToolbar(baseToolbar, {
|
|
490
|
+
altTextValidator,
|
|
491
|
+
forceFocusSelector: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$f = pluginInjectionApi.floatingToolbar.actions) === null || _pluginInjectionApi$f === void 0 ? void 0 : _pluginInjectionApi$f.forceFocusSelector
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
let items = [];
|
|
496
|
+
const parentMediaGroupNode = findParentNodeOfType(mediaGroup)(state.selection);
|
|
497
|
+
let selectedNodeType;
|
|
498
|
+
if (state.selection instanceof NodeSelection) {
|
|
499
|
+
selectedNodeType = state.selection.node.type;
|
|
500
|
+
}
|
|
501
|
+
if (allowMediaInline && (parentMediaGroupNode === null || parentMediaGroupNode === void 0 ? void 0 : parentMediaGroupNode.node.type) === mediaGroup) {
|
|
502
|
+
var _pluginInjectionApi$a7;
|
|
503
|
+
const mediaOffset = state.selection.$from.parentOffset + 1;
|
|
504
|
+
baseToolbar.getDomRef = () => {
|
|
505
|
+
var _mediaPluginState$ele;
|
|
506
|
+
const selector = mediaFilmstripItemDOMSelector(mediaOffset);
|
|
507
|
+
return (_mediaPluginState$ele = mediaPluginState.element) === null || _mediaPluginState$ele === void 0 ? void 0 : _mediaPluginState$ele.querySelector(selector);
|
|
508
|
+
};
|
|
509
|
+
items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a7 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a7 === void 0 ? void 0 : _pluginInjectionApi$a7.actions);
|
|
510
|
+
} else if (allowMediaInline && selectedNodeType && selectedNodeType === mediaInline) {
|
|
511
|
+
var _pluginInjectionApi$a8;
|
|
512
|
+
baseToolbar.getDomRef = () => {
|
|
513
|
+
var _mediaPluginState$ele2;
|
|
514
|
+
const element = (_mediaPluginState$ele2 = mediaPluginState.element) === null || _mediaPluginState$ele2 === void 0 ? void 0 : _mediaPluginState$ele2.querySelector(`.${MediaInlineNodeSelector}`);
|
|
515
|
+
return element || mediaPluginState.element;
|
|
516
|
+
};
|
|
517
|
+
items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a8 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a8 === void 0 ? void 0 : _pluginInjectionApi$a8.actions);
|
|
518
|
+
} else {
|
|
519
|
+
baseToolbar.getDomRef = () => {
|
|
520
|
+
var _mediaPluginState$ele3;
|
|
521
|
+
const element = (_mediaPluginState$ele3 = mediaPluginState.element) === null || _mediaPluginState$ele3 === void 0 ? void 0 : _mediaPluginState$ele3.querySelector(`.${MediaSingleNodeSelector}`);
|
|
522
|
+
return element || mediaPluginState.element;
|
|
523
|
+
};
|
|
524
|
+
items = generateMediaSingleFloatingToolbar(state, intl, options, mediaPluginState, mediaLinkingState, pluginInjectionApi, getEditorFeatureFlags);
|
|
525
|
+
}
|
|
526
|
+
const toolbarConfig = {
|
|
527
|
+
...baseToolbar,
|
|
528
|
+
items,
|
|
529
|
+
scrollable: true
|
|
530
|
+
};
|
|
531
|
+
if (getBooleanFF('platform.editor.media.extended-resize-experience') && allowResizing) {
|
|
532
|
+
return {
|
|
533
|
+
...toolbarConfig,
|
|
534
|
+
width: mediaPluginState.isResizing ? undefined : getMaxToolbarWidth()
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
return toolbarConfig;
|
|
538
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React, { Fragment, useEffect, useState } from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/react';
|
|
4
|
+
import { isSafeUrl } from '@atlaskit/adf-schema';
|
|
5
|
+
import { addLink, ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
6
|
+
import { linkMessages, linkToolbarMessages } from '@atlaskit/editor-common/messages';
|
|
7
|
+
import { FloatingToolbarButton as ToolbarButton } from '@atlaskit/editor-common/ui';
|
|
8
|
+
import { FloatingToolbarSeparator as Separator } from '@atlaskit/editor-common/ui';
|
|
9
|
+
import LinkIcon from '@atlaskit/icon/glyph/editor/link';
|
|
10
|
+
import OpenIcon from '@atlaskit/icon/glyph/shortcut';
|
|
11
|
+
import { stateKey } from '../pm-plugins/plugin-key';
|
|
12
|
+
import { checkMediaType } from '../utils/check-media-type';
|
|
13
|
+
import { currentMediaNode } from '../utils/current-media-node';
|
|
14
|
+
// need this wrapper, need to have 4px between items.
|
|
15
|
+
const wrapper = css`
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
margin-right: ${"var(--ds-space-050, 4px)"};
|
|
19
|
+
`;
|
|
20
|
+
export const LinkToolbarAppearance = ({
|
|
21
|
+
editorState,
|
|
22
|
+
mediaLinkingState,
|
|
23
|
+
intl,
|
|
24
|
+
onAddLink,
|
|
25
|
+
onEditLink,
|
|
26
|
+
onOpenLink
|
|
27
|
+
}) => {
|
|
28
|
+
const [showLinkingControls, setShowLinkingControls] = useState(true);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
var _stateKey$getState;
|
|
31
|
+
const mediaNode = currentMediaNode(editorState);
|
|
32
|
+
if (!mediaNode) {
|
|
33
|
+
setShowLinkingControls(false);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const mediaClientConfig = (_stateKey$getState = stateKey.getState(editorState)) === null || _stateKey$getState === void 0 ? void 0 : _stateKey$getState.mediaClientConfig;
|
|
37
|
+
if (!mediaClientConfig) {
|
|
38
|
+
setShowLinkingControls(false);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
checkMediaType(mediaNode, mediaClientConfig).then(mediaType => {
|
|
42
|
+
setShowLinkingControls(mediaType === 'external' || mediaType === 'image');
|
|
43
|
+
});
|
|
44
|
+
}, [editorState]);
|
|
45
|
+
if (!showLinkingControls) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (mediaLinkingState && mediaLinkingState.editable) {
|
|
49
|
+
const isValidUrl = isSafeUrl(mediaLinkingState.link);
|
|
50
|
+
const title = intl.formatMessage(linkToolbarMessages.editLink);
|
|
51
|
+
const linkTitle = intl.formatMessage(isValidUrl ? linkMessages.openLink : linkToolbarMessages.unableToOpenLink);
|
|
52
|
+
return jsx(Fragment, null, jsx("div", {
|
|
53
|
+
css: wrapper
|
|
54
|
+
}, jsx(ToolbarButton, {
|
|
55
|
+
onClick: onEditLink,
|
|
56
|
+
title: title,
|
|
57
|
+
tooltipContent: jsx(ToolTipContent, {
|
|
58
|
+
description: title,
|
|
59
|
+
keymap: addLink
|
|
60
|
+
}),
|
|
61
|
+
testId: "edit-link-button"
|
|
62
|
+
}, title)), jsx("div", {
|
|
63
|
+
css: wrapper
|
|
64
|
+
}, jsx(Separator, null)), jsx(ToolbarButton, {
|
|
65
|
+
target: "_blank",
|
|
66
|
+
href: isValidUrl ? mediaLinkingState.link : undefined,
|
|
67
|
+
disabled: !isValidUrl,
|
|
68
|
+
onClick: onOpenLink,
|
|
69
|
+
title: linkTitle,
|
|
70
|
+
icon: jsx(OpenIcon, {
|
|
71
|
+
label: linkTitle
|
|
72
|
+
}),
|
|
73
|
+
className: "hyperlink-open-link"
|
|
74
|
+
}), jsx(Separator, null));
|
|
75
|
+
} else {
|
|
76
|
+
const title = intl.formatMessage(linkToolbarMessages.addLink);
|
|
77
|
+
return jsx(Fragment, null, jsx(ToolbarButton, {
|
|
78
|
+
testId: "add-link-button",
|
|
79
|
+
onClick: onAddLink,
|
|
80
|
+
title: title,
|
|
81
|
+
tooltipContent: jsx(ToolTipContent, {
|
|
82
|
+
description: title,
|
|
83
|
+
keymap: addLink
|
|
84
|
+
}),
|
|
85
|
+
icon: jsx(LinkIcon, {
|
|
86
|
+
label: title
|
|
87
|
+
})
|
|
88
|
+
}), jsx(Separator, null));
|
|
89
|
+
}
|
|
90
|
+
};
|