@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,228 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
/** @jsx jsx */
|
|
3
|
+
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { css, jsx } from '@emotion/react';
|
|
6
|
+
import { injectIntl } from 'react-intl-next';
|
|
7
|
+
import { withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
8
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, fireAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
9
|
+
import { escape, ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
10
|
+
import { PanelTextInput } from '@atlaskit/editor-common/ui';
|
|
11
|
+
import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
|
|
12
|
+
import { RECENT_SEARCH_WIDTH_IN_PX } from '@atlaskit/editor-common/ui';
|
|
13
|
+
import { ErrorMessage } from '@atlaskit/editor-common/ui';
|
|
14
|
+
import { relativeFontSizeToBase16 } from '@atlaskit/editor-shared-styles';
|
|
15
|
+
import ChevronLeftLargeIcon from '@atlaskit/icon/glyph/chevron-left-large';
|
|
16
|
+
import CrossCircleIcon from '@atlaskit/icon/glyph/cross-circle';
|
|
17
|
+
import { N100, N30, N80, R400 } from '@atlaskit/theme/colors';
|
|
18
|
+
import { closeMediaAltTextMenu, updateAltText } from '../commands';
|
|
19
|
+
import { messages } from '../messages';
|
|
20
|
+
export const CONTAINER_WIDTH_IN_PX = RECENT_SEARCH_WIDTH_IN_PX;
|
|
21
|
+
export const MAX_ALT_TEXT_LENGTH = 510; // double tweet length
|
|
22
|
+
|
|
23
|
+
const supportText = css`
|
|
24
|
+
color: ${`var(--ds-text-subtlest, ${N100})`};
|
|
25
|
+
font-size: ${relativeFontSizeToBase16(12)};
|
|
26
|
+
padding: ${"var(--ds-space-150, 12px)"} ${"var(--ds-space-500, 40px)"};
|
|
27
|
+
line-height: 20px;
|
|
28
|
+
border-top: 1px solid ${`var(--ds-border, ${N30})`};
|
|
29
|
+
margin: 0;
|
|
30
|
+
`;
|
|
31
|
+
const container = css`
|
|
32
|
+
width: ${CONTAINER_WIDTH_IN_PX}px;
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
overflow: auto;
|
|
36
|
+
line-height: 2;
|
|
37
|
+
`;
|
|
38
|
+
const inputWrapper = css`
|
|
39
|
+
display: flex;
|
|
40
|
+
line-height: 0;
|
|
41
|
+
padding: 5px 0;
|
|
42
|
+
align-items: center;
|
|
43
|
+
`;
|
|
44
|
+
const validationWrapper = css`
|
|
45
|
+
display: flex;
|
|
46
|
+
line-height: 0;
|
|
47
|
+
padding: ${"var(--ds-space-150, 12px)"} ${"var(--ds-space-300, 24px)"}
|
|
48
|
+
${"var(--ds-space-150, 12px)"} 0;
|
|
49
|
+
margin: 0 ${"var(--ds-space-150, 12px)"} 0 ${"var(--ds-space-500, 40px)"};
|
|
50
|
+
border-top: 1px solid ${`var(--ds-border-danger, ${R400})`};
|
|
51
|
+
align-items: start;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
`;
|
|
54
|
+
const buttonWrapper = css`
|
|
55
|
+
display: flex;
|
|
56
|
+
padding: ${"var(--ds-space-050, 4px)"} ${"var(--ds-space-100, 8px)"};
|
|
57
|
+
`;
|
|
58
|
+
const clearText = css`
|
|
59
|
+
color: ${`var(--ds-icon-subtle, ${N80})`};
|
|
60
|
+
`;
|
|
61
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
62
|
+
export class AltTextEditComponent extends React.Component {
|
|
63
|
+
constructor(props) {
|
|
64
|
+
super(props);
|
|
65
|
+
_defineProperty(this, "state", {
|
|
66
|
+
showClearTextButton: Boolean(this.props.value),
|
|
67
|
+
validationErrors: this.props.value ? this.getValidationErrors(this.props.value) : [],
|
|
68
|
+
lastValue: this.props.value
|
|
69
|
+
});
|
|
70
|
+
_defineProperty(this, "closeMediaAltTextMenu", () => {
|
|
71
|
+
const {
|
|
72
|
+
view
|
|
73
|
+
} = this.props;
|
|
74
|
+
closeMediaAltTextMenu(view.state, view.dispatch);
|
|
75
|
+
});
|
|
76
|
+
_defineProperty(this, "dispatchCancelEvent", event => {
|
|
77
|
+
const {
|
|
78
|
+
view,
|
|
79
|
+
onEscape
|
|
80
|
+
} = this.props;
|
|
81
|
+
|
|
82
|
+
// We need to pass down the ESCAPE keymap
|
|
83
|
+
// because when we focus on the Toolbar, Prosemirror blur,
|
|
84
|
+
// making all keyboard shortcuts not working
|
|
85
|
+
view.someProp('handleKeyDown', fn => fn(view, event));
|
|
86
|
+
onEscape === null || onEscape === void 0 ? void 0 : onEscape();
|
|
87
|
+
});
|
|
88
|
+
_defineProperty(this, "updateAltText", newAltText => {
|
|
89
|
+
const {
|
|
90
|
+
view
|
|
91
|
+
} = this.props;
|
|
92
|
+
const newValue = newAltText.length === 0 ? '' : newAltText;
|
|
93
|
+
updateAltText(newValue)(view.state, view.dispatch);
|
|
94
|
+
});
|
|
95
|
+
_defineProperty(this, "handleOnChange", newAltText => {
|
|
96
|
+
const validationErrors = this.getValidationErrors(newAltText);
|
|
97
|
+
this.setState({
|
|
98
|
+
showClearTextButton: Boolean(newAltText),
|
|
99
|
+
validationErrors,
|
|
100
|
+
lastValue: newAltText
|
|
101
|
+
}, () => {
|
|
102
|
+
if (!validationErrors || !validationErrors.length) {
|
|
103
|
+
this.updateAltText(newAltText);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
_defineProperty(this, "handleOnBlur", () => {
|
|
108
|
+
// Handling the trimming onBlur() because PanelTextInput doesn't sync
|
|
109
|
+
// defaultValue properly during unmount
|
|
110
|
+
const {
|
|
111
|
+
value
|
|
112
|
+
} = this.props;
|
|
113
|
+
const newValue = (this.state.lastValue || value || '').trim();
|
|
114
|
+
this.handleOnChange(newValue);
|
|
115
|
+
});
|
|
116
|
+
_defineProperty(this, "handleClearText", () => {
|
|
117
|
+
this.handleOnChange('');
|
|
118
|
+
});
|
|
119
|
+
const {
|
|
120
|
+
createAnalyticsEvent
|
|
121
|
+
} = props;
|
|
122
|
+
this.fireCustomAnalytics = fireAnalyticsEvent(createAnalyticsEvent);
|
|
123
|
+
}
|
|
124
|
+
componentDidMount() {
|
|
125
|
+
this.prevValue = this.props.value;
|
|
126
|
+
}
|
|
127
|
+
componentWillUnmount() {
|
|
128
|
+
this.fireAnalytics(ACTION.CLOSED);
|
|
129
|
+
if (!this.prevValue && this.props.value) {
|
|
130
|
+
this.fireAnalytics(ACTION.ADDED);
|
|
131
|
+
}
|
|
132
|
+
if (this.prevValue && !this.props.value) {
|
|
133
|
+
this.fireAnalytics(ACTION.CLEARED);
|
|
134
|
+
}
|
|
135
|
+
if (this.prevValue && this.prevValue !== this.props.value) {
|
|
136
|
+
this.fireAnalytics(ACTION.EDITED);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
getValidationErrors(value) {
|
|
140
|
+
const {
|
|
141
|
+
altTextValidator
|
|
142
|
+
} = this.props;
|
|
143
|
+
if (value && typeof altTextValidator === 'function') {
|
|
144
|
+
return altTextValidator(value) || [];
|
|
145
|
+
}
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
render() {
|
|
149
|
+
const {
|
|
150
|
+
intl: {
|
|
151
|
+
formatMessage
|
|
152
|
+
}
|
|
153
|
+
} = this.props;
|
|
154
|
+
const {
|
|
155
|
+
showClearTextButton
|
|
156
|
+
} = this.state;
|
|
157
|
+
const backButtonMessage = formatMessage(messages.back);
|
|
158
|
+
const backButtonMessageComponent = jsx(ToolTipContent, {
|
|
159
|
+
description: backButtonMessage,
|
|
160
|
+
keymap: escape,
|
|
161
|
+
shortcutOverride: "Esc"
|
|
162
|
+
});
|
|
163
|
+
const errorsList = (this.state.validationErrors || []).map(function (error, index) {
|
|
164
|
+
return jsx(ErrorMessage, {
|
|
165
|
+
key: index
|
|
166
|
+
}, error);
|
|
167
|
+
});
|
|
168
|
+
return jsx("div", {
|
|
169
|
+
css: container
|
|
170
|
+
}, jsx("section", {
|
|
171
|
+
css: inputWrapper
|
|
172
|
+
}, jsx("div", {
|
|
173
|
+
css: buttonWrapper
|
|
174
|
+
}, jsx(Button, {
|
|
175
|
+
title: formatMessage(messages.back),
|
|
176
|
+
icon: jsx(ChevronLeftLargeIcon, {
|
|
177
|
+
label: formatMessage(messages.back)
|
|
178
|
+
}),
|
|
179
|
+
tooltipContent: backButtonMessageComponent,
|
|
180
|
+
onClick: this.closeMediaAltTextMenu
|
|
181
|
+
})), jsx(PanelTextInput, {
|
|
182
|
+
testId: "alt-text-input",
|
|
183
|
+
ariaLabel: formatMessage(messages.placeholder),
|
|
184
|
+
describedById: "support-text",
|
|
185
|
+
placeholder: formatMessage(messages.placeholder),
|
|
186
|
+
defaultValue: this.state.lastValue,
|
|
187
|
+
onCancel: this.dispatchCancelEvent,
|
|
188
|
+
onChange: this.handleOnChange,
|
|
189
|
+
onBlur: this.handleOnBlur,
|
|
190
|
+
onSubmit: this.closeMediaAltTextMenu,
|
|
191
|
+
maxLength: MAX_ALT_TEXT_LENGTH,
|
|
192
|
+
autoFocus: true
|
|
193
|
+
}), showClearTextButton && jsx("div", {
|
|
194
|
+
css: buttonWrapper
|
|
195
|
+
}, jsx(Button, {
|
|
196
|
+
testId: "alt-text-clear-button",
|
|
197
|
+
title: formatMessage(messages.clear),
|
|
198
|
+
icon: jsx("span", {
|
|
199
|
+
css: clearText
|
|
200
|
+
}, jsx(CrossCircleIcon, {
|
|
201
|
+
label: formatMessage(messages.clear)
|
|
202
|
+
})),
|
|
203
|
+
tooltipContent: formatMessage(messages.clear),
|
|
204
|
+
onClick: this.handleClearText
|
|
205
|
+
}))), !!errorsList.length && jsx("section", {
|
|
206
|
+
css: validationWrapper
|
|
207
|
+
}, errorsList), jsx("p", {
|
|
208
|
+
css: supportText,
|
|
209
|
+
id: "support-text"
|
|
210
|
+
}, formatMessage(messages.supportText)));
|
|
211
|
+
}
|
|
212
|
+
fireAnalytics(actionType) {
|
|
213
|
+
const {
|
|
214
|
+
createAnalyticsEvent
|
|
215
|
+
} = this.props;
|
|
216
|
+
if (createAnalyticsEvent && this.fireCustomAnalytics) {
|
|
217
|
+
this.fireCustomAnalytics({
|
|
218
|
+
payload: {
|
|
219
|
+
action: actionType,
|
|
220
|
+
actionSubject: ACTION_SUBJECT.MEDIA,
|
|
221
|
+
actionSubjectId: ACTION_SUBJECT_ID.ALT_TEXT,
|
|
222
|
+
eventType: EVENT_TYPE.TRACK
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
export default withAnalyticsEvents()(injectIntl(AltTextEditComponent));
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { backspace, bindKeymapWithCommand } from '@atlaskit/editor-common/keymaps';
|
|
2
|
+
import { atTheEndOfDoc } from '@atlaskit/editor-common/selection';
|
|
3
|
+
import { isEmptyNode, isSelectionInsideLastNodeInDocument } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { selectNodeBackward } from '@atlaskit/editor-prosemirror/commands';
|
|
5
|
+
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
6
|
+
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if is an empty selection at the start of the node
|
|
10
|
+
*/
|
|
11
|
+
function isEmptySelectionAtStart(selection) {
|
|
12
|
+
if (!selection.empty) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const {
|
|
16
|
+
$from
|
|
17
|
+
} = selection;
|
|
18
|
+
return $from.parentOffset <= 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Check if the current selection is inside a node type
|
|
23
|
+
*/
|
|
24
|
+
function isSelectionInsideOf(selection, nodeType) {
|
|
25
|
+
const {
|
|
26
|
+
$from
|
|
27
|
+
} = selection;
|
|
28
|
+
const parent = $from.parent;
|
|
29
|
+
return parent.type === nodeType;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Return the sibling of the current selection
|
|
34
|
+
*/
|
|
35
|
+
function getSibling(selection, sibling) {
|
|
36
|
+
const {
|
|
37
|
+
$from
|
|
38
|
+
} = selection;
|
|
39
|
+
const index = $from.index($from.depth - 1);
|
|
40
|
+
const grandParent = $from.node($from.depth - 1); // Get GrandParent
|
|
41
|
+
|
|
42
|
+
return grandParent ? grandParent.maybeChild(index + sibling) : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check if respective sibling (negative number previous, positive number next)
|
|
47
|
+
* is from the specified node
|
|
48
|
+
*/
|
|
49
|
+
function isSiblingOfType(selection, node, sibling) {
|
|
50
|
+
const maybeSiblingNode = getSibling(selection, sibling);
|
|
51
|
+
return !!maybeSiblingNode && maybeSiblingNode.type === node;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* When there's any empty block before another paragraph with wrap-right
|
|
55
|
+
* mediaSingle. Pressing backspace at the start of the paragraph will select
|
|
56
|
+
* the media but visually it makes more sense to remove the empty paragraph.
|
|
57
|
+
*
|
|
58
|
+
* Structure of the document: doc(block(), mediaSingle(media()), paragraph('{<>}hello!'))
|
|
59
|
+
* But, visually it looks like the following:
|
|
60
|
+
*
|
|
61
|
+
* [empty block] <- Remove this block
|
|
62
|
+
* or [paragraph block] <- Move text inside this paragraph
|
|
63
|
+
* or [any other block] <- Move paragraph node after this node
|
|
64
|
+
* [Cursor] x x x x x x x x +---------------+
|
|
65
|
+
* x x x x x x x x x x | mediaSingle |
|
|
66
|
+
* x x x x x. +---------------+
|
|
67
|
+
*/
|
|
68
|
+
function handleSelectionAfterWrapRight(isEmptyNode) {
|
|
69
|
+
function isEmptyWithoutThrow(node) {
|
|
70
|
+
let isEmpty = false;
|
|
71
|
+
try {
|
|
72
|
+
// We dont have isEmptyNode definition for table for example.
|
|
73
|
+
// In this case it will throw we need to catch it
|
|
74
|
+
isEmpty = isEmptyNode(node);
|
|
75
|
+
} catch (e) {}
|
|
76
|
+
return isEmpty;
|
|
77
|
+
}
|
|
78
|
+
return (state, dispatch) => {
|
|
79
|
+
const {
|
|
80
|
+
$from
|
|
81
|
+
} = state.selection;
|
|
82
|
+
const {
|
|
83
|
+
paragraph
|
|
84
|
+
} = state.schema.nodes;
|
|
85
|
+
const previousMediaSingleSibling = -2;
|
|
86
|
+
const maybeSibling = getSibling(state.selection, previousMediaSingleSibling);
|
|
87
|
+
if (!maybeSibling) {
|
|
88
|
+
// the last is the image so should let the default behaviour delete the image
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const mediaSingle = getSibling(state.selection, -1); // Sibling is a media single already checked in main code
|
|
92
|
+
const mediaSinglePos = $from.pos - mediaSingle.nodeSize;
|
|
93
|
+
|
|
94
|
+
// Should find the position
|
|
95
|
+
// Should move the current paragraph to the last line
|
|
96
|
+
const maybeAnyBlockPos = mediaSinglePos - maybeSibling.nodeSize;
|
|
97
|
+
let tr = state.tr;
|
|
98
|
+
if (isEmptyWithoutThrow(maybeSibling)) {
|
|
99
|
+
// Should remove the empty sibling
|
|
100
|
+
tr = tr.replace(maybeAnyBlockPos - 1, maybeAnyBlockPos + maybeSibling.nodeSize);
|
|
101
|
+
} else {
|
|
102
|
+
// We move the current node, to the new position
|
|
103
|
+
// 1. Remove current node, only if I am not removing the last node.
|
|
104
|
+
if (!isSelectionInsideLastNodeInDocument(state.selection)) {
|
|
105
|
+
tr.replace($from.pos - 1, $from.pos + $from.parent.nodeSize - 1); // Remove node
|
|
106
|
+
} else {
|
|
107
|
+
// Remove node content, if is the last node, let a empty paragraph
|
|
108
|
+
tr.replace($from.pos, $from.pos + $from.parent.nodeSize - 1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// 2. Add it in the new position
|
|
112
|
+
// If the sibling is a paragraph lets copy the text inside the paragraph
|
|
113
|
+
// Like a normal backspace from paragraph to paragraph
|
|
114
|
+
if (maybeSibling.type === paragraph) {
|
|
115
|
+
const insideParagraphPos = maybeAnyBlockPos + maybeSibling.nodeSize - 2;
|
|
116
|
+
safeInsert($from.parent.content, insideParagraphPos)(tr);
|
|
117
|
+
} else {
|
|
118
|
+
// If is any other kind of block just add the paragraph after it
|
|
119
|
+
const endOfBlockPos = maybeAnyBlockPos + maybeSibling.nodeSize - 1;
|
|
120
|
+
safeInsert($from.parent.copy($from.parent.content), endOfBlockPos)(tr);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (dispatch) {
|
|
124
|
+
dispatch(tr);
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const maybeRemoveMediaSingleNode = schema => {
|
|
130
|
+
const isEmptyNodeInSchema = isEmptyNode(schema);
|
|
131
|
+
return (state, dispatch) => {
|
|
132
|
+
const {
|
|
133
|
+
selection,
|
|
134
|
+
schema
|
|
135
|
+
} = state;
|
|
136
|
+
const {
|
|
137
|
+
$from
|
|
138
|
+
} = selection;
|
|
139
|
+
if (!isEmptySelectionAtStart(state.selection)) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
if (!isSelectionInsideOf(state.selection, schema.nodes.paragraph)) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
const previousSibling = -1;
|
|
146
|
+
if (!isSiblingOfType(state.selection, schema.nodes.mediaSingle, previousSibling)) {
|
|
147
|
+
// no media single
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const mediaSingle = getSibling(state.selection, previousSibling);
|
|
151
|
+
if (mediaSingle.attrs.layout === 'wrap-right') {
|
|
152
|
+
return handleSelectionAfterWrapRight(isEmptyNodeInSchema)(state, dispatch);
|
|
153
|
+
}
|
|
154
|
+
if (dispatch) {
|
|
155
|
+
// Select media single, and remove paragraph if it's empty.
|
|
156
|
+
selectNodeBackward(state, tr => {
|
|
157
|
+
if (isEmptyNodeInSchema($from.parent) && !atTheEndOfDoc(state)) {
|
|
158
|
+
tr.replace($from.pos - 1, $from.pos + $from.parent.nodeSize - 1); // Remove node
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
dispatch(tr);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
export default function keymapPlugin(schema) {
|
|
168
|
+
const list = {};
|
|
169
|
+
const removeMediaSingleCommand = maybeRemoveMediaSingleNode(schema);
|
|
170
|
+
bindKeymapWithCommand(backspace.common, removeMediaSingleCommand, list);
|
|
171
|
+
return keymap(list);
|
|
172
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { bindKeymapWithCommand, enter, insertNewLine, moveDown, moveLeft, moveRight, tab, undo } from '@atlaskit/editor-common/keymaps';
|
|
2
|
+
import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
|
|
3
|
+
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
4
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { getMediaFeatureFlag } from '@atlaskit/media-common';
|
|
6
|
+
import { insertAndSelectCaptionFromMediaSinglePos, selectCaptionFromMediaSinglePos } from '../commands/captions';
|
|
7
|
+
import { stateKey } from '../pm-plugins/plugin-key';
|
|
8
|
+
export function keymapPlugin(options, editorAnalyticsAPI, editorSelectionAPI) {
|
|
9
|
+
const list = {};
|
|
10
|
+
const {
|
|
11
|
+
featureFlags
|
|
12
|
+
} = options || {};
|
|
13
|
+
bindKeymapWithCommand(undo.common, ignoreLinksInSteps, list);
|
|
14
|
+
bindKeymapWithCommand(enter.common, splitMediaGroup, list);
|
|
15
|
+
if (options !== null && options !== void 0 && options.allowCaptions || getMediaFeatureFlag('captions', featureFlags)) {
|
|
16
|
+
bindKeymapWithCommand(moveDown.common, insertAndSelectCaption(editorAnalyticsAPI), list);
|
|
17
|
+
bindKeymapWithCommand(tab.common, insertAndSelectCaption(editorAnalyticsAPI), list);
|
|
18
|
+
bindKeymapWithCommand(moveLeft.common, arrowLeftFromMediaSingle(editorSelectionAPI), list);
|
|
19
|
+
bindKeymapWithCommand(moveRight.common, arrowRightFromMediaSingle(editorSelectionAPI), list);
|
|
20
|
+
}
|
|
21
|
+
bindKeymapWithCommand(insertNewLine.common, splitMediaGroup, list);
|
|
22
|
+
return keymap(list);
|
|
23
|
+
}
|
|
24
|
+
const ignoreLinksInSteps = state => {
|
|
25
|
+
const mediaPluginState = stateKey.getState(state);
|
|
26
|
+
mediaPluginState.ignoreLinks = true;
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
29
|
+
const splitMediaGroup = state => {
|
|
30
|
+
const mediaPluginState = stateKey.getState(state);
|
|
31
|
+
return mediaPluginState.splitMediaGroup();
|
|
32
|
+
};
|
|
33
|
+
const insertAndSelectCaption = editorAnalyticsAPI => (state, dispatch) => {
|
|
34
|
+
const {
|
|
35
|
+
selection,
|
|
36
|
+
schema
|
|
37
|
+
} = state;
|
|
38
|
+
if (selection instanceof NodeSelection && selection.node.type === schema.nodes.mediaSingle && schema.nodes.caption) {
|
|
39
|
+
if (dispatch) {
|
|
40
|
+
const {
|
|
41
|
+
from,
|
|
42
|
+
node
|
|
43
|
+
} = selection;
|
|
44
|
+
if (!insertAndSelectCaptionFromMediaSinglePos(editorAnalyticsAPI)(from, node)(state, dispatch)) {
|
|
45
|
+
selectCaptionFromMediaSinglePos(from, node)(state, dispatch);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
const arrowLeftFromMediaSingle = editorSelectionAPI => (state, dispatch) => {
|
|
53
|
+
const {
|
|
54
|
+
selection
|
|
55
|
+
} = state;
|
|
56
|
+
if (editorSelectionAPI && selection instanceof NodeSelection && selection.node.type.name === 'mediaSingle') {
|
|
57
|
+
const tr = editorSelectionAPI.selectNearNode({
|
|
58
|
+
selectionRelativeToNode: undefined,
|
|
59
|
+
selection: new GapCursorSelection(state.doc.resolve(selection.from), Side.LEFT)
|
|
60
|
+
})(state);
|
|
61
|
+
if (dispatch) {
|
|
62
|
+
dispatch(tr);
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
68
|
+
const arrowRightFromMediaSingle = editorSelectionAPI => (state, dispatch) => {
|
|
69
|
+
const {
|
|
70
|
+
selection
|
|
71
|
+
} = state;
|
|
72
|
+
if (editorSelectionAPI && selection instanceof NodeSelection && selection.node.type.name === 'mediaSingle') {
|
|
73
|
+
const tr = editorSelectionAPI.selectNearNode({
|
|
74
|
+
selectionRelativeToNode: undefined,
|
|
75
|
+
selection: new GapCursorSelection(state.doc.resolve(selection.to), Side.RIGHT)
|
|
76
|
+
})(state);
|
|
77
|
+
if (dispatch) {
|
|
78
|
+
dispatch(tr);
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
};
|
|
84
|
+
export default keymapPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export let MediaLinkingActionsTypes = /*#__PURE__*/function (MediaLinkingActionsTypes) {
|
|
2
|
+
MediaLinkingActionsTypes["showToolbar"] = "MEDIA_SHOW_TOOLBAR";
|
|
3
|
+
MediaLinkingActionsTypes["hideToolbar"] = "MEDIA_HIDE_TOOLBAR";
|
|
4
|
+
MediaLinkingActionsTypes["setUrl"] = "MEDIA_SET_LINK_TO";
|
|
5
|
+
MediaLinkingActionsTypes["unlink"] = "MEDIA_LINKING_UNLINK";
|
|
6
|
+
return MediaLinkingActionsTypes;
|
|
7
|
+
}({});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { NodeSelection, PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import reducer from './reducer';
|
|
5
|
+
export const mediaLinkingPluginKey = new PluginKey('mediaLinking');
|
|
6
|
+
const initialState = {
|
|
7
|
+
visible: false,
|
|
8
|
+
editable: false,
|
|
9
|
+
mediaPos: null,
|
|
10
|
+
link: ''
|
|
11
|
+
};
|
|
12
|
+
function mapping(tr, pluginState) {
|
|
13
|
+
if (pluginState && pluginState.mediaPos !== null) {
|
|
14
|
+
return {
|
|
15
|
+
...pluginState,
|
|
16
|
+
mediaPos: tr.mapping.map(pluginState.mediaPos)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return pluginState;
|
|
20
|
+
}
|
|
21
|
+
function onSelectionChanged(tr) {
|
|
22
|
+
const isNodeSelection = tr.selection instanceof NodeSelection;
|
|
23
|
+
if (!isNodeSelection) {
|
|
24
|
+
return initialState;
|
|
25
|
+
}
|
|
26
|
+
const mediaPos = tr.selection.$from.pos + 1;
|
|
27
|
+
const node = tr.doc.nodeAt(mediaPos);
|
|
28
|
+
if (!node || node.type.name !== 'media') {
|
|
29
|
+
return initialState;
|
|
30
|
+
}
|
|
31
|
+
const mark = node.marks.find(mark => mark.type.name === 'link');
|
|
32
|
+
if (mark) {
|
|
33
|
+
return {
|
|
34
|
+
...initialState,
|
|
35
|
+
mediaPos,
|
|
36
|
+
editable: true,
|
|
37
|
+
link: mark.attrs.href
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
...initialState,
|
|
42
|
+
mediaPos
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const mediaLinkingPluginFactory = pluginFactory(mediaLinkingPluginKey, reducer, {
|
|
46
|
+
mapping,
|
|
47
|
+
onSelectionChanged
|
|
48
|
+
});
|
|
49
|
+
export const {
|
|
50
|
+
createCommand: createMediaLinkingCommand,
|
|
51
|
+
getPluginState: getMediaLinkingState
|
|
52
|
+
} = mediaLinkingPluginFactory;
|
|
53
|
+
export default (dispatch => new SafePlugin({
|
|
54
|
+
key: mediaLinkingPluginKey,
|
|
55
|
+
state: mediaLinkingPluginFactory.createPluginState(dispatch, initialState)
|
|
56
|
+
}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { addLink, bindKeymapWithCommand } from '@atlaskit/editor-common/keymaps';
|
|
2
|
+
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
|
+
import { showLinkingToolbarWithMediaTypeCheck } from '../../commands/linking';
|
|
4
|
+
export default function keymapPlugin(schema) {
|
|
5
|
+
const list = {};
|
|
6
|
+
bindKeymapWithCommand(addLink.common, showLinkingToolbarWithMediaTypeCheck, list);
|
|
7
|
+
return keymap(list);
|
|
8
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MediaLinkingActionsTypes } from './actions';
|
|
2
|
+
export default ((state, action) => {
|
|
3
|
+
switch (action.type) {
|
|
4
|
+
case MediaLinkingActionsTypes.showToolbar:
|
|
5
|
+
{
|
|
6
|
+
return {
|
|
7
|
+
...state,
|
|
8
|
+
visible: true
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
case MediaLinkingActionsTypes.setUrl:
|
|
12
|
+
{
|
|
13
|
+
return {
|
|
14
|
+
...state,
|
|
15
|
+
editable: true,
|
|
16
|
+
link: action.payload
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
case MediaLinkingActionsTypes.hideToolbar:
|
|
20
|
+
{
|
|
21
|
+
return {
|
|
22
|
+
...state,
|
|
23
|
+
visible: false
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
case MediaLinkingActionsTypes.unlink:
|
|
27
|
+
{
|
|
28
|
+
return {
|
|
29
|
+
...state,
|
|
30
|
+
link: '',
|
|
31
|
+
visible: false,
|
|
32
|
+
editable: false
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return state;
|
|
37
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|