@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,190 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
/** @jsx jsx */
|
|
3
|
+
import React, { Fragment } from 'react';
|
|
4
|
+
import { css, jsx } from '@emotion/react';
|
|
5
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
6
|
+
import { container, containerWithProvider, inputWrapper, RecentSearch } from '@atlaskit/editor-common/link';
|
|
7
|
+
import { linkToolbarMessages } from '@atlaskit/editor-common/messages';
|
|
8
|
+
import { ErrorMessage } from '@atlaskit/editor-common/ui';
|
|
9
|
+
// Common Translations will live here
|
|
10
|
+
import { PanelTextInput } from '@atlaskit/editor-common/ui';
|
|
11
|
+
import { FloatingToolbarButton as Button, FloatingToolbarSeparator as Separator } from '@atlaskit/editor-common/ui';
|
|
12
|
+
import { normalizeUrl } from '@atlaskit/editor-common/utils';
|
|
13
|
+
import ChevronLeftLargeIcon from '@atlaskit/icon/glyph/chevron-left-large';
|
|
14
|
+
import EditorUnlinkIcon from '@atlaskit/icon/glyph/editor/unlink';
|
|
15
|
+
import { R400 } from '@atlaskit/theme/colors';
|
|
16
|
+
import { mediaLinkToolbarMessages } from './media-linking-toolbar-messages';
|
|
17
|
+
const validationWrapper = css`
|
|
18
|
+
line-height: 0;
|
|
19
|
+
padding: ${"var(--ds-space-150, 12px)"} ${"var(--ds-space-300, 24px)"}
|
|
20
|
+
${"var(--ds-space-150, 12px)"} 0;
|
|
21
|
+
margin: 0 ${"var(--ds-space-050, 4px)"} 0 ${"var(--ds-space-400, 32px)"};
|
|
22
|
+
border-top: 1px solid ${`var(--ds-border-danger, ${R400})`};
|
|
23
|
+
align-items: start;
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
`;
|
|
27
|
+
const buttonWrapper = css`
|
|
28
|
+
padding: ${"var(--ds-space-050, 4px)"} ${"var(--ds-space-100, 8px)"}
|
|
29
|
+
${"var(--ds-space-050, 4px)"} 0px;
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
33
|
+
export class LinkAddToolbar extends React.PureComponent {
|
|
34
|
+
constructor(...args) {
|
|
35
|
+
super(...args);
|
|
36
|
+
_defineProperty(this, "state", {
|
|
37
|
+
validationErrors: []
|
|
38
|
+
});
|
|
39
|
+
_defineProperty(this, "handleSubmit", ({
|
|
40
|
+
url,
|
|
41
|
+
inputMethod
|
|
42
|
+
}) => {
|
|
43
|
+
this.props.onSubmit(url, {
|
|
44
|
+
inputMethod
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
_defineProperty(this, "handleOnBack", ({
|
|
48
|
+
url,
|
|
49
|
+
inputMethod
|
|
50
|
+
}) => {
|
|
51
|
+
const {
|
|
52
|
+
onBack
|
|
53
|
+
} = this.props;
|
|
54
|
+
if (onBack) {
|
|
55
|
+
onBack(url, {
|
|
56
|
+
inputMethod
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
_defineProperty(this, "handleCancel", () => {
|
|
61
|
+
const {
|
|
62
|
+
onCancel
|
|
63
|
+
} = this.props;
|
|
64
|
+
if (onCancel) {
|
|
65
|
+
onCancel();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
_defineProperty(this, "handleUnlink", () => {
|
|
69
|
+
const {
|
|
70
|
+
onUnlink
|
|
71
|
+
} = this.props;
|
|
72
|
+
if (onUnlink) {
|
|
73
|
+
onUnlink();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
_defineProperty(this, "handleOnBlur", options => {
|
|
77
|
+
this.props.onBlur(options.url);
|
|
78
|
+
});
|
|
79
|
+
_defineProperty(this, "renderContainer", ({
|
|
80
|
+
activityProvider,
|
|
81
|
+
inputProps: {
|
|
82
|
+
onChange,
|
|
83
|
+
onKeyDown,
|
|
84
|
+
onSubmit,
|
|
85
|
+
value
|
|
86
|
+
},
|
|
87
|
+
currentInputMethod,
|
|
88
|
+
renderRecentList
|
|
89
|
+
}) => {
|
|
90
|
+
const {
|
|
91
|
+
intl: {
|
|
92
|
+
formatMessage
|
|
93
|
+
},
|
|
94
|
+
displayUrl
|
|
95
|
+
} = this.props;
|
|
96
|
+
const getPlaceholder = hasActivityProvider => formatMessage(hasActivityProvider ? linkToolbarMessages.placeholder : linkToolbarMessages.linkPlaceholder);
|
|
97
|
+
const formatLinkAddressText = formatMessage(mediaLinkToolbarMessages.backLink);
|
|
98
|
+
const formatUnlinkText = formatMessage(linkToolbarMessages.unlink);
|
|
99
|
+
const errorsList = this.state.validationErrors.map(function (error, index) {
|
|
100
|
+
return jsx(ErrorMessage, {
|
|
101
|
+
key: index
|
|
102
|
+
}, error);
|
|
103
|
+
});
|
|
104
|
+
return jsx("div", {
|
|
105
|
+
className: "recent-list"
|
|
106
|
+
}, jsx("div", {
|
|
107
|
+
css: [container, !!activityProvider && containerWithProvider]
|
|
108
|
+
}, jsx("div", {
|
|
109
|
+
css: inputWrapper
|
|
110
|
+
}, jsx("span", {
|
|
111
|
+
css: buttonWrapper
|
|
112
|
+
}, jsx(Button, {
|
|
113
|
+
title: formatLinkAddressText,
|
|
114
|
+
icon: jsx(ChevronLeftLargeIcon, {
|
|
115
|
+
label: formatLinkAddressText
|
|
116
|
+
}),
|
|
117
|
+
onClick: () => this.handleOnBack({
|
|
118
|
+
url: value,
|
|
119
|
+
inputMethod: currentInputMethod
|
|
120
|
+
})
|
|
121
|
+
})), jsx(PanelTextInput, {
|
|
122
|
+
testId: "media-link-input",
|
|
123
|
+
placeholder: getPlaceholder(!!activityProvider),
|
|
124
|
+
autoFocus: true,
|
|
125
|
+
onCancel: this.handleCancel,
|
|
126
|
+
defaultValue: value,
|
|
127
|
+
onSubmit: inputValue => {
|
|
128
|
+
const validationErrors = this.getValidationErrors(inputValue, currentInputMethod);
|
|
129
|
+
this.setState({
|
|
130
|
+
validationErrors
|
|
131
|
+
});
|
|
132
|
+
if (!validationErrors.length) {
|
|
133
|
+
onSubmit();
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
onChange: value => {
|
|
137
|
+
this.setState({
|
|
138
|
+
validationErrors: []
|
|
139
|
+
});
|
|
140
|
+
onChange(value);
|
|
141
|
+
},
|
|
142
|
+
onKeyDown: onKeyDown
|
|
143
|
+
}), normalizeUrl(displayUrl) && jsx(Fragment, null, jsx(Separator, null), jsx(Button, {
|
|
144
|
+
title: formatUnlinkText,
|
|
145
|
+
icon: jsx(EditorUnlinkIcon, {
|
|
146
|
+
label: formatUnlinkText
|
|
147
|
+
}),
|
|
148
|
+
onClick: this.handleUnlink
|
|
149
|
+
}))), !!errorsList.length && jsx("section", {
|
|
150
|
+
css: validationWrapper
|
|
151
|
+
}, errorsList), renderRecentList()));
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
getValidationErrors(value, inputMethod) {
|
|
155
|
+
const {
|
|
156
|
+
intl: {
|
|
157
|
+
formatMessage
|
|
158
|
+
}
|
|
159
|
+
} = this.props;
|
|
160
|
+
|
|
161
|
+
// dont show validation errors if input method is typeahed, which means user selects from search list
|
|
162
|
+
if (inputMethod === INPUT_METHOD.TYPEAHEAD) {
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
if (!value) {
|
|
166
|
+
return [formatMessage(linkToolbarMessages.emptyLink)];
|
|
167
|
+
}
|
|
168
|
+
// if url can be normalized - we consider it is a valid url
|
|
169
|
+
// also don't show validaition errors for empty values
|
|
170
|
+
if (normalizeUrl(value)) {
|
|
171
|
+
return [];
|
|
172
|
+
} else {
|
|
173
|
+
return [formatMessage(linkToolbarMessages.invalidLink)];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
render() {
|
|
177
|
+
const {
|
|
178
|
+
providerFactory,
|
|
179
|
+
displayUrl
|
|
180
|
+
} = this.props;
|
|
181
|
+
return jsx(RecentSearch, {
|
|
182
|
+
defaultUrl: normalizeUrl(displayUrl),
|
|
183
|
+
providerFactory: providerFactory,
|
|
184
|
+
onSubmit: this.handleSubmit,
|
|
185
|
+
onBlur: this.handleOnBlur,
|
|
186
|
+
render: this.renderContainer
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export default LinkAddToolbar;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Browser } from '@atlaskit/media-picker';
|
|
3
|
+
import PickerFacadeProvider from './PickerFacadeProvider';
|
|
4
|
+
export const BrowserWrapper = ({
|
|
5
|
+
mediaState,
|
|
6
|
+
isOpen,
|
|
7
|
+
onBrowseFn,
|
|
8
|
+
featureFlags
|
|
9
|
+
}) => /*#__PURE__*/React.createElement(PickerFacadeProvider, {
|
|
10
|
+
mediaState: mediaState,
|
|
11
|
+
analyticsName: "browser"
|
|
12
|
+
}, ({
|
|
13
|
+
mediaClientConfig,
|
|
14
|
+
config,
|
|
15
|
+
pickerFacadeInstance
|
|
16
|
+
}) => {
|
|
17
|
+
const browserConfig = {
|
|
18
|
+
...config,
|
|
19
|
+
multiple: true
|
|
20
|
+
};
|
|
21
|
+
return /*#__PURE__*/React.createElement(Browser, {
|
|
22
|
+
onBrowseFn: onBrowseFn,
|
|
23
|
+
isOpen: isOpen,
|
|
24
|
+
config: browserConfig,
|
|
25
|
+
mediaClientConfig: mediaClientConfig,
|
|
26
|
+
onEnd: pickerFacadeInstance.handleReady,
|
|
27
|
+
onError: pickerFacadeInstance.handleUploadError,
|
|
28
|
+
onPreviewUpdate: pickerFacadeInstance.handleUploadPreviewUpdate,
|
|
29
|
+
featureFlags: featureFlags
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Clipboard } from '@atlaskit/media-picker';
|
|
3
|
+
import PickerFacadeProvider from './PickerFacadeProvider';
|
|
4
|
+
export const ClipboardWrapper = ({
|
|
5
|
+
mediaState,
|
|
6
|
+
featureFlags,
|
|
7
|
+
container
|
|
8
|
+
}) => /*#__PURE__*/React.createElement(PickerFacadeProvider, {
|
|
9
|
+
mediaState: mediaState,
|
|
10
|
+
analyticsName: "clipboard"
|
|
11
|
+
}, ({
|
|
12
|
+
mediaClientConfig,
|
|
13
|
+
config,
|
|
14
|
+
pickerFacadeInstance
|
|
15
|
+
}) => {
|
|
16
|
+
const clipboardConfig = Object.assign({}, config);
|
|
17
|
+
if ((featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.securedClipboard) === true) {
|
|
18
|
+
clipboardConfig.container = container;
|
|
19
|
+
clipboardConfig.onPaste = event => {
|
|
20
|
+
event.stopPropagation();
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return /*#__PURE__*/React.createElement(Clipboard, {
|
|
25
|
+
mediaClientConfig: mediaClientConfig,
|
|
26
|
+
config: clipboardConfig,
|
|
27
|
+
onError: pickerFacadeInstance.handleUploadError,
|
|
28
|
+
onPreviewUpdate: pickerFacadeInstance.handleUploadPreviewUpdate,
|
|
29
|
+
onEnd: pickerFacadeInstance.handleReady,
|
|
30
|
+
featureFlags: featureFlags
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
|
|
3
|
+
import { Dropzone } from '@atlaskit/media-picker';
|
|
4
|
+
import PickerFacadeProvider from './PickerFacadeProvider';
|
|
5
|
+
export const DropzoneWrapper = ({
|
|
6
|
+
mediaState,
|
|
7
|
+
isActive,
|
|
8
|
+
featureFlags,
|
|
9
|
+
editorDomElement,
|
|
10
|
+
appearance
|
|
11
|
+
}) => /*#__PURE__*/React.createElement(PickerFacadeProvider, {
|
|
12
|
+
mediaState: mediaState,
|
|
13
|
+
analyticsName: "dropzone"
|
|
14
|
+
}, ({
|
|
15
|
+
mediaClientConfig,
|
|
16
|
+
config,
|
|
17
|
+
pickerFacadeInstance
|
|
18
|
+
}) => {
|
|
19
|
+
const {
|
|
20
|
+
options: {
|
|
21
|
+
customDropzoneContainer
|
|
22
|
+
},
|
|
23
|
+
handleDrag
|
|
24
|
+
} = mediaState;
|
|
25
|
+
const editorHtmlElement = editorDomElement;
|
|
26
|
+
const scrollParent = appearance === 'full-page' && findOverflowScrollParent(editorHtmlElement);
|
|
27
|
+
const container = customDropzoneContainer || (scrollParent ? scrollParent : editorHtmlElement);
|
|
28
|
+
const dropzoneConfig = {
|
|
29
|
+
...config,
|
|
30
|
+
container
|
|
31
|
+
};
|
|
32
|
+
return isActive ? /*#__PURE__*/React.createElement(Dropzone, {
|
|
33
|
+
mediaClientConfig: mediaClientConfig,
|
|
34
|
+
config: dropzoneConfig,
|
|
35
|
+
onError: pickerFacadeInstance.handleUploadError,
|
|
36
|
+
onPreviewUpdate: pickerFacadeInstance.handleUploadPreviewUpdate,
|
|
37
|
+
onEnd: pickerFacadeInstance.handleReady,
|
|
38
|
+
onDragEnter: () => handleDrag('enter'),
|
|
39
|
+
onDragLeave: () => handleDrag('leave'),
|
|
40
|
+
featureFlags: featureFlags
|
|
41
|
+
}) : null;
|
|
42
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ErrorReporter } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import PickerFacade from '../../picker-facade';
|
|
5
|
+
const dummyMediaPickerObject = {
|
|
6
|
+
on: () => {},
|
|
7
|
+
removeAllListeners: () => {},
|
|
8
|
+
emit: () => {},
|
|
9
|
+
destroy: () => {},
|
|
10
|
+
setUploadParams: () => {}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
14
|
+
export default class PickerFacadeProvider extends React.Component {
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
_defineProperty(this, "state", {});
|
|
18
|
+
_defineProperty(this, "handleMediaProvider", async (_name, provider) => {
|
|
19
|
+
const {
|
|
20
|
+
mediaState,
|
|
21
|
+
analyticsName
|
|
22
|
+
} = this.props;
|
|
23
|
+
const mediaProvider = await provider;
|
|
24
|
+
if (!mediaProvider || !mediaProvider.uploadParams) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const resolvedMediaClientConfig = (await mediaProvider.uploadMediaClientConfig) || (await mediaProvider.viewMediaClientConfig);
|
|
28
|
+
if (!resolvedMediaClientConfig) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const pickerFacadeConfig = {
|
|
32
|
+
mediaClientConfig: resolvedMediaClientConfig,
|
|
33
|
+
errorReporter: mediaState.options.errorReporter || new ErrorReporter(),
|
|
34
|
+
featureFlags: mediaState.mediaOptions && mediaState.mediaOptions.featureFlags
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* As the first MediaPicker component to be migrated to React, we want to scope the amount of changes logic changed/moved on Editor side.
|
|
39
|
+
* To achieve this we agreed on using `PickerFacade` 'customMediaPicker' type, since we only need this instance to reuse the logic when we subscribe
|
|
40
|
+
* for all the different events in MediaPicker (onPreviewUpdate, onError, onProcessing, etc).
|
|
41
|
+
* The `dummyMediaPickerObject` provided here serves as a workaround for the old picker api that `PickerFacade` will try to use.
|
|
42
|
+
* But we don't want this to do anything since it's all part of the new React component (`Clipboard` component in this case).
|
|
43
|
+
* Eventually PickerFacade will be removed and replaced with a new abstraction explained here https://product-fabric.atlassian.net/browse/MS-1937
|
|
44
|
+
*/
|
|
45
|
+
const pickerFacadeInstance = await new PickerFacade('customMediaPicker', pickerFacadeConfig, dummyMediaPickerObject, analyticsName).init();
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Based on the `initPickers` method in `MediaPluginState` we need these 2 `onNewMedia` subscriptions.
|
|
49
|
+
* First one in order to trigger the entire process of uploading a file for when `onPreviewUpdate` is called
|
|
50
|
+
* Second one in order to track all analytics as before.
|
|
51
|
+
*/
|
|
52
|
+
pickerFacadeInstance.onNewMedia(mediaState.insertFile);
|
|
53
|
+
pickerFacadeInstance.setUploadParams(mediaProvider.uploadParams);
|
|
54
|
+
const config = {
|
|
55
|
+
uploadParams: mediaProvider.uploadParams
|
|
56
|
+
};
|
|
57
|
+
this.setState({
|
|
58
|
+
pickerFacadeInstance,
|
|
59
|
+
config,
|
|
60
|
+
mediaClientConfig: resolvedMediaClientConfig
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
componentDidMount() {
|
|
65
|
+
this.props.mediaState.options.providerFactory.subscribe('mediaProvider', this.handleMediaProvider);
|
|
66
|
+
}
|
|
67
|
+
componentWillUnmount() {
|
|
68
|
+
this.props.mediaState.options.providerFactory.unsubscribe('mediaProvider', this.handleMediaProvider);
|
|
69
|
+
}
|
|
70
|
+
render() {
|
|
71
|
+
const {
|
|
72
|
+
mediaClientConfig,
|
|
73
|
+
config,
|
|
74
|
+
pickerFacadeInstance
|
|
75
|
+
} = this.state;
|
|
76
|
+
if (!mediaClientConfig || !config || !pickerFacadeInstance) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return this.props.children({
|
|
80
|
+
mediaClientConfig,
|
|
81
|
+
config,
|
|
82
|
+
pickerFacadeInstance
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
|
+
import { BrowserWrapper } from './BrowserWrapper';
|
|
5
|
+
import { ClipboardWrapper } from './ClipboardWrapper';
|
|
6
|
+
import { DropzoneWrapper } from './DropzoneWrapper';
|
|
7
|
+
const MediaPicker = ({
|
|
8
|
+
api,
|
|
9
|
+
isPopupOpened,
|
|
10
|
+
appearance,
|
|
11
|
+
mediaState,
|
|
12
|
+
onBrowseFn,
|
|
13
|
+
editorDomElement
|
|
14
|
+
}) => {
|
|
15
|
+
const {
|
|
16
|
+
focusState
|
|
17
|
+
} = useSharedPluginState(api, ['focus']);
|
|
18
|
+
const featureFlags = mediaState.mediaOptions && mediaState.mediaOptions.featureFlags;
|
|
19
|
+
const container = editorDomElement;
|
|
20
|
+
const clipboard = focusState !== null && focusState !== void 0 && focusState.hasFocus ? /*#__PURE__*/React.createElement(ClipboardWrapper, {
|
|
21
|
+
mediaState: mediaState,
|
|
22
|
+
featureFlags: featureFlags,
|
|
23
|
+
container: container
|
|
24
|
+
}) : null;
|
|
25
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, clipboard, /*#__PURE__*/React.createElement(DropzoneWrapper, {
|
|
26
|
+
mediaState: mediaState,
|
|
27
|
+
isActive: !isPopupOpened,
|
|
28
|
+
featureFlags: featureFlags,
|
|
29
|
+
editorDomElement: editorDomElement,
|
|
30
|
+
appearance: appearance
|
|
31
|
+
}), /*#__PURE__*/React.createElement(BrowserWrapper, {
|
|
32
|
+
onBrowseFn: onBrowseFn,
|
|
33
|
+
mediaState: mediaState,
|
|
34
|
+
featureFlags: featureFlags
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
39
|
+
export class MediaPickerComponents extends React.Component {
|
|
40
|
+
constructor(...args) {
|
|
41
|
+
super(...args);
|
|
42
|
+
_defineProperty(this, "state", {
|
|
43
|
+
isPopupOpened: false
|
|
44
|
+
});
|
|
45
|
+
_defineProperty(this, "onBrowseFn", nativeBrowseFn => {
|
|
46
|
+
const {
|
|
47
|
+
mediaState
|
|
48
|
+
} = this.props;
|
|
49
|
+
mediaState && mediaState.setBrowseFn(nativeBrowseFn);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
componentDidMount() {
|
|
53
|
+
const {
|
|
54
|
+
mediaState
|
|
55
|
+
} = this.props;
|
|
56
|
+
mediaState.onPopupToggle(isPopupOpened => {
|
|
57
|
+
this.setState({
|
|
58
|
+
isPopupOpened
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
render() {
|
|
63
|
+
const {
|
|
64
|
+
api,
|
|
65
|
+
mediaState,
|
|
66
|
+
editorDomElement,
|
|
67
|
+
appearance
|
|
68
|
+
} = this.props;
|
|
69
|
+
const {
|
|
70
|
+
isPopupOpened
|
|
71
|
+
} = this.state;
|
|
72
|
+
return /*#__PURE__*/React.createElement(MediaPicker, {
|
|
73
|
+
mediaState: mediaState,
|
|
74
|
+
editorDomElement: editorDomElement,
|
|
75
|
+
appearance: appearance,
|
|
76
|
+
isPopupOpened: isPopupOpened,
|
|
77
|
+
onBrowseFn: this.onBrowseFn,
|
|
78
|
+
api: api
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
_defineProperty(MediaPickerComponents, "displayName", 'MediaPickerComponents');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PIXELENTRY_MIGRATION_BUTTON_TESTID = 'pixel-entry-convert-pixels-btn';
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
/** @jsx jsx */
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
import { jsx } from '@emotion/react';
|
|
5
|
+
import Button from '@atlaskit/button';
|
|
6
|
+
import Form, { Field } from '@atlaskit/form';
|
|
7
|
+
import Textfield from '@atlaskit/textfield';
|
|
8
|
+
import Tooltip from '@atlaskit/tooltip';
|
|
9
|
+
import { PIXELENTRY_MIGRATION_BUTTON_TESTID } from './constants';
|
|
10
|
+
import { messages } from './messages';
|
|
11
|
+
import { pixelEntryForm, pixelEntryHiddenSubmit, pixelSizingFullWidthLabelStyles, pixelSizingHeightInput, pixelSizingInput, pixelSizingLabel, pixelSizingWidthInput, pixelSizingWrapper } from './styles';
|
|
12
|
+
export const PixelEntry = ({
|
|
13
|
+
width,
|
|
14
|
+
mediaWidth,
|
|
15
|
+
mediaHeight,
|
|
16
|
+
onSubmit,
|
|
17
|
+
minWidth,
|
|
18
|
+
maxWidth,
|
|
19
|
+
onChange,
|
|
20
|
+
intl: {
|
|
21
|
+
formatMessage
|
|
22
|
+
},
|
|
23
|
+
showMigration,
|
|
24
|
+
onMigrate
|
|
25
|
+
}) => {
|
|
26
|
+
const ratioWidth = useMemo(() => {
|
|
27
|
+
return mediaHeight / mediaWidth;
|
|
28
|
+
}, [mediaHeight, mediaWidth]);
|
|
29
|
+
const ratioHeight = useMemo(() => {
|
|
30
|
+
return mediaWidth / mediaHeight;
|
|
31
|
+
}, [mediaHeight, mediaWidth]);
|
|
32
|
+
const [computedWidth, setComputedWidth] = useState(width);
|
|
33
|
+
const [computedHeight, setComputedHeight] = useState(Math.round(ratioWidth * width));
|
|
34
|
+
|
|
35
|
+
// Handle update to width from outside component
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
setComputedWidth(width);
|
|
38
|
+
setComputedHeight(Math.round(ratioWidth * width));
|
|
39
|
+
}, [width, ratioWidth]);
|
|
40
|
+
|
|
41
|
+
// Handle submit when user presses enter in form
|
|
42
|
+
const handleOnSubmit = data => {
|
|
43
|
+
if (data.inputWidth === '' || data.inputHeight === '') {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (onSubmit) {
|
|
47
|
+
let widthToBeSumitted = data.inputWidth;
|
|
48
|
+
let validation = 'valid';
|
|
49
|
+
if (data.inputWidth < minWidth) {
|
|
50
|
+
widthToBeSumitted = minWidth;
|
|
51
|
+
validation = 'less-than-min';
|
|
52
|
+
}
|
|
53
|
+
if (data.inputWidth > maxWidth) {
|
|
54
|
+
widthToBeSumitted = maxWidth;
|
|
55
|
+
validation = 'greater-than-max';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// If user keeps submitting an invalid input, node width attribute will be updated with the same value
|
|
59
|
+
// and won't upadte the state in useEffect (since width is the same)
|
|
60
|
+
// Thus, we set the state here to always display the correct dimension
|
|
61
|
+
if (validation !== 'valid') {
|
|
62
|
+
setComputedWidth(widthToBeSumitted);
|
|
63
|
+
setComputedHeight(Math.round(ratioWidth * widthToBeSumitted));
|
|
64
|
+
}
|
|
65
|
+
onSubmit({
|
|
66
|
+
width: widthToBeSumitted,
|
|
67
|
+
validation
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Handle updating computed fields based on
|
|
73
|
+
const handleOnChange = useCallback(type => event => {
|
|
74
|
+
const value = parseInt(event.currentTarget.value);
|
|
75
|
+
const newInputValue = isNaN(value) ? '' : value;
|
|
76
|
+
let newWidth = '';
|
|
77
|
+
switch (type) {
|
|
78
|
+
case 'inputWidth':
|
|
79
|
+
{
|
|
80
|
+
newWidth = newInputValue;
|
|
81
|
+
setComputedWidth(newInputValue);
|
|
82
|
+
const newHeight = newInputValue !== '' ? Math.round(ratioWidth * newInputValue) : '';
|
|
83
|
+
setComputedHeight(newHeight);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case 'inputHeight':
|
|
87
|
+
{
|
|
88
|
+
setComputedHeight(newInputValue);
|
|
89
|
+
newWidth = newInputValue !== '' ? Math.round(ratioHeight * newInputValue) : '';
|
|
90
|
+
setComputedWidth(newWidth);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const isInvalidInputValid = newWidth !== '' && (newWidth < minWidth || newWidth > maxWidth);
|
|
95
|
+
onChange && onChange(isInvalidInputValid);
|
|
96
|
+
}, [minWidth, maxWidth, onChange, ratioWidth, ratioHeight]);
|
|
97
|
+
if (showMigration) {
|
|
98
|
+
return jsx(Tooltip, {
|
|
99
|
+
content: formatMessage(messages.migrationButtonTooltip)
|
|
100
|
+
}, jsx(Button, {
|
|
101
|
+
appearance: "warning",
|
|
102
|
+
spacing: "compact",
|
|
103
|
+
onClick: onMigrate,
|
|
104
|
+
testId: PIXELENTRY_MIGRATION_BUTTON_TESTID
|
|
105
|
+
}, formatMessage(messages.migrationButtonText)));
|
|
106
|
+
}
|
|
107
|
+
return jsx("div", {
|
|
108
|
+
css: pixelEntryForm
|
|
109
|
+
}, jsx(Form, {
|
|
110
|
+
onSubmit: handleOnSubmit
|
|
111
|
+
}, ({
|
|
112
|
+
formProps
|
|
113
|
+
}) => {
|
|
114
|
+
return jsx("form", formProps, jsx("div", {
|
|
115
|
+
css: pixelSizingWrapper
|
|
116
|
+
}, jsx(Field, {
|
|
117
|
+
key: "inputWidth",
|
|
118
|
+
name: "inputWidth",
|
|
119
|
+
defaultValue: computedWidth
|
|
120
|
+
}, ({
|
|
121
|
+
fieldProps
|
|
122
|
+
}) => jsx(Tooltip, {
|
|
123
|
+
hideTooltipOnMouseDown: true,
|
|
124
|
+
content: formatMessage(messages.inputWidthTooltip, {
|
|
125
|
+
maxWidth
|
|
126
|
+
}),
|
|
127
|
+
position: "top"
|
|
128
|
+
}, jsx(Textfield, _extends({}, fieldProps, {
|
|
129
|
+
css: [pixelSizingWidthInput, pixelSizingInput],
|
|
130
|
+
appearance: "none",
|
|
131
|
+
isCompact: true,
|
|
132
|
+
onChange: handleOnChange('inputWidth'),
|
|
133
|
+
pattern: "\\d*",
|
|
134
|
+
"aria-label": formatMessage(messages.inputWidthAriaLabel, {
|
|
135
|
+
maxWidth
|
|
136
|
+
})
|
|
137
|
+
})))), jsx("span", {
|
|
138
|
+
css: pixelSizingLabel
|
|
139
|
+
}, "x"), jsx(Field, {
|
|
140
|
+
key: "inputHeight",
|
|
141
|
+
name: "inputHeight",
|
|
142
|
+
defaultValue: computedHeight
|
|
143
|
+
}, ({
|
|
144
|
+
fieldProps
|
|
145
|
+
}) => jsx(Tooltip, {
|
|
146
|
+
hideTooltipOnMouseDown: true,
|
|
147
|
+
content: formatMessage(messages.inputHeightTooltip),
|
|
148
|
+
position: "top"
|
|
149
|
+
}, jsx(Textfield, _extends({}, fieldProps, {
|
|
150
|
+
css: [pixelSizingHeightInput, pixelSizingInput],
|
|
151
|
+
appearance: "none",
|
|
152
|
+
isCompact: true,
|
|
153
|
+
onChange: handleOnChange('inputHeight'),
|
|
154
|
+
pattern: "\\d*",
|
|
155
|
+
"aria-label": formatMessage(messages.inputHeightAriaLabel)
|
|
156
|
+
})))), jsx(Button, {
|
|
157
|
+
css: pixelEntryHiddenSubmit,
|
|
158
|
+
type: "submit"
|
|
159
|
+
}, formatMessage(messages.submitButtonText))));
|
|
160
|
+
}));
|
|
161
|
+
};
|
|
162
|
+
export const FullWidthDisplay = ({
|
|
163
|
+
intl: {
|
|
164
|
+
formatMessage
|
|
165
|
+
}
|
|
166
|
+
}) => {
|
|
167
|
+
return jsx("div", {
|
|
168
|
+
css: pixelSizingFullWidthLabelStyles
|
|
169
|
+
}, jsx("span", null, formatMessage(messages.fullWidthLabel)));
|
|
170
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl-next';
|
|
2
|
+
export const messages = defineMessages({
|
|
3
|
+
validationFailedMessage: {
|
|
4
|
+
id: 'fabric.editor.media.pixelEntry.validationFailedMessage',
|
|
5
|
+
defaultMessage: 'Validation for width failed',
|
|
6
|
+
description: 'The passed in validator function returned false'
|
|
7
|
+
},
|
|
8
|
+
inputWidthTooltip: {
|
|
9
|
+
id: 'fabric.editor.media.pixelEntry.inputWidthTooltip',
|
|
10
|
+
defaultMessage: 'Max width {maxWidth}px',
|
|
11
|
+
description: 'The tooltip displayed ontop of the width input'
|
|
12
|
+
},
|
|
13
|
+
inputWidthAriaLabel: {
|
|
14
|
+
id: 'fabric.editor.media.pixelEntry.inputWidthAriaLabel',
|
|
15
|
+
defaultMessage: 'Max width {maxWidth}px',
|
|
16
|
+
description: 'The width input aria label'
|
|
17
|
+
},
|
|
18
|
+
inputHeightTooltip: {
|
|
19
|
+
id: 'fabric.editor.media.pixelEntry.inputHeightTooltip',
|
|
20
|
+
defaultMessage: 'Height',
|
|
21
|
+
description: 'The tooltip displayed ontop of the height input'
|
|
22
|
+
},
|
|
23
|
+
inputHeightAriaLabel: {
|
|
24
|
+
id: 'fabric.editor.media.pixelEntry.inputHeightAriaLabel',
|
|
25
|
+
defaultMessage: 'height input',
|
|
26
|
+
description: 'The width input aria label'
|
|
27
|
+
},
|
|
28
|
+
submitButtonText: {
|
|
29
|
+
id: 'fabric.editor.media.pixelEntry.submitButtonText',
|
|
30
|
+
defaultMessage: 'Submit',
|
|
31
|
+
description: 'The text give to the hidden submit button'
|
|
32
|
+
},
|
|
33
|
+
fullWidthLabel: {
|
|
34
|
+
id: 'fabric.editor.image.fullWidthLabel',
|
|
35
|
+
defaultMessage: 'Full-width',
|
|
36
|
+
description: 'The media has reached its maximum width'
|
|
37
|
+
},
|
|
38
|
+
migrationButtonText: {
|
|
39
|
+
id: 'fabric.editor.media.pixelEntry.migrationButtonText',
|
|
40
|
+
defaultMessage: 'Convert to pixels',
|
|
41
|
+
description: 'The text give to the button used to covert to pixels for legacy experience'
|
|
42
|
+
},
|
|
43
|
+
migrationButtonTooltip: {
|
|
44
|
+
id: 'fabric.editor.media.pixelEntry.migrationButtonTooltip',
|
|
45
|
+
defaultMessage: 'Migrate from percentage to fixed pixel sizing',
|
|
46
|
+
description: 'The tooltip displayed on the migration button'
|
|
47
|
+
}
|
|
48
|
+
});
|