@atlaskit/editor-plugin-media 1.35.1 → 1.36.0

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugin.js +70 -43
  3. package/dist/cjs/pm-plugins/actions.js +10 -0
  4. package/dist/cjs/pm-plugins/commands.js +28 -0
  5. package/dist/cjs/pm-plugins/main.js +14 -0
  6. package/dist/cjs/toolbar/filePreviewItem.js +3 -2
  7. package/dist/cjs/toolbar/index.js +46 -12
  8. package/dist/cjs/toolbar/mediaInline.js +14 -1
  9. package/dist/es2019/plugin.js +31 -2
  10. package/dist/es2019/pm-plugins/actions.js +4 -0
  11. package/dist/es2019/pm-plugins/commands.js +22 -0
  12. package/dist/es2019/pm-plugins/main.js +14 -0
  13. package/dist/es2019/toolbar/filePreviewItem.js +3 -2
  14. package/dist/es2019/toolbar/index.js +40 -5
  15. package/dist/es2019/toolbar/mediaInline.js +15 -2
  16. package/dist/esm/plugin.js +70 -43
  17. package/dist/esm/pm-plugins/actions.js +4 -0
  18. package/dist/esm/pm-plugins/commands.js +22 -0
  19. package/dist/esm/pm-plugins/main.js +14 -0
  20. package/dist/esm/toolbar/filePreviewItem.js +3 -2
  21. package/dist/esm/toolbar/index.js +46 -12
  22. package/dist/esm/toolbar/mediaInline.js +15 -2
  23. package/dist/types/next-plugin-type.d.ts +6 -1
  24. package/dist/types/pm-plugins/actions.d.ts +4 -0
  25. package/dist/types/pm-plugins/commands.d.ts +4 -0
  26. package/dist/types/pm-plugins/types.d.ts +3 -1
  27. package/dist/types/toolbar/index.d.ts +4 -0
  28. package/dist/types-ts4.5/next-plugin-type.d.ts +6 -1
  29. package/dist/types-ts4.5/pm-plugins/actions.d.ts +4 -0
  30. package/dist/types-ts4.5/pm-plugins/commands.d.ts +4 -0
  31. package/dist/types-ts4.5/pm-plugins/types.d.ts +3 -1
  32. package/dist/types-ts4.5/toolbar/index.d.ts +4 -0
  33. package/package.json +9 -6
@@ -9,6 +9,7 @@ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
9
9
  import { contains, findParentNodeOfType, hasParentNode, hasParentNodeOfType, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
10
10
  import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
11
11
  import DownloadIcon from '@atlaskit/icon/glyph/download';
12
+ import FilePreviewIcon from '@atlaskit/icon/glyph/editor/file-preview';
12
13
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
13
14
  import { mediaFilmstripItemDOMSelector } from '@atlaskit/media-filmstrip';
14
15
  import { messages } from '@atlaskit/media-ui';
@@ -31,7 +32,7 @@ import { LayoutGroup } from './layout-group';
31
32
  import { getLinkingToolbar, shouldShowMediaLinkToolbar } from './linking';
32
33
  import { LinkToolbarAppearance } from './linking-toolbar-appearance';
33
34
  import { generateMediaInlineFloatingToolbar } from './mediaInline';
34
- import { calcNewLayout, canShowSwitchButtons, downloadMedia, getMaxToolbarWidth, getPixelWidthOfElement, getSelectedLayoutIcon, getSelectedMediaSingle, removeMediaGroupNode } from './utils';
35
+ import { calcNewLayout, canShowSwitchButtons, downloadMedia, getMaxToolbarWidth, getPixelWidthOfElement, getSelectedLayoutIcon, getSelectedMediaSingle, getSelectedNearestMediaContainerNodeAttrs, removeMediaGroupNode } from './utils';
35
36
  const mediaTypeMessages = {
36
37
  image: messages.file_image_is_selected,
37
38
  video: messages.file_video_is_selected,
@@ -67,7 +68,17 @@ export const generateFilePreviewItem = (mediaPluginState, intl) => {
67
68
  supportsViewMode: true
68
69
  };
69
70
  };
70
- const generateMediaCardFloatingToolbar = (state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, forceFocusSelector, isViewOnly) => {
71
+ export const handleShowMediaViewer = ({
72
+ api,
73
+ mediaPluginState
74
+ }) => {
75
+ const selectedNodeAttrs = getSelectedNearestMediaContainerNodeAttrs(mediaPluginState);
76
+ if (!selectedNodeAttrs) {
77
+ return false;
78
+ }
79
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.media.commands.showMediaViewer(selectedNodeAttrs));
80
+ };
81
+ const generateMediaCardFloatingToolbar = (state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, editorAnalyticsAPI, forceFocusSelector, isViewOnly) => {
71
82
  if (isViewOnly) {
72
83
  return [];
73
84
  }
@@ -98,7 +109,19 @@ const generateMediaCardFloatingToolbar = (state, intl, mediaPluginState, hoverDe
98
109
  className: 'thumbnail-appearance' // a11y. uses to force focus on item
99
110
  }, {
100
111
  type: 'separator'
101
- }, generateFilePreviewItem(mediaPluginState, intl), {
112
+ }, fg('platform_editor_media_previewer_bugfix') ? {
113
+ id: 'editor.media.viewer',
114
+ type: 'button',
115
+ icon: FilePreviewIcon,
116
+ title: intl.formatMessage(messages.preview),
117
+ onClick: () => {
118
+ var _handleShowMediaViewe;
119
+ return (_handleShowMediaViewe = handleShowMediaViewer({
120
+ mediaPluginState,
121
+ api: pluginInjectionApi
122
+ })) !== null && _handleShowMediaViewe !== void 0 ? _handleShowMediaViewe : false;
123
+ }
124
+ } : generateFilePreviewItem(mediaPluginState, intl), {
102
125
  type: 'separator'
103
126
  }, {
104
127
  id: 'editor.media.card.download',
@@ -447,7 +470,19 @@ const generateMediaSingleFloatingToolbar = (state, intl, options, pluginState, m
447
470
  const selectedMediaSingleNode = getSelectedMediaSingle(state);
448
471
  const mediaNode = selectedMediaSingleNode === null || selectedMediaSingleNode === void 0 ? void 0 : selectedMediaSingleNode.node.content.firstChild;
449
472
  if (!isVideo(mediaNode === null || mediaNode === void 0 ? void 0 : (_mediaNode$attrs = mediaNode.attrs) === null || _mediaNode$attrs === void 0 ? void 0 : _mediaNode$attrs.__fileMimeType)) {
450
- toolbarButtons.push(generateFilePreviewItem(pluginState, intl), {
473
+ toolbarButtons.push(fg('platform_editor_media_previewer_bugfix') ? {
474
+ id: 'editor.media.viewer',
475
+ type: 'button',
476
+ icon: FilePreviewIcon,
477
+ title: intl.formatMessage(messages.preview),
478
+ onClick: () => {
479
+ var _handleShowMediaViewe2;
480
+ return (_handleShowMediaViewe2 = handleShowMediaViewer({
481
+ api: pluginInjectionApi,
482
+ mediaPluginState: pluginState
483
+ })) !== null && _handleShowMediaViewe2 !== void 0 ? _handleShowMediaViewe2 : false;
484
+ }
485
+ } : generateFilePreviewItem(pluginState, intl), {
451
486
  type: 'separator',
452
487
  supportsViewMode: true
453
488
  });
@@ -572,7 +607,7 @@ export const floatingToolbar = (state, intl, options = {}, pluginInjectionApi) =
572
607
  const selector = mediaFilmstripItemDOMSelector(mediaOffset);
573
608
  return (_mediaPluginState$ele = mediaPluginState.element) === null || _mediaPluginState$ele === void 0 ? void 0 : _mediaPluginState$ele.querySelector(selector);
574
609
  };
575
- items = generateMediaCardFloatingToolbar(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, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$f3 = pluginInjectionApi.floatingToolbar) === null || _pluginInjectionApi$f3 === void 0 ? void 0 : (_pluginInjectionApi$f4 = _pluginInjectionApi$f3.actions) === null || _pluginInjectionApi$f4 === void 0 ? void 0 : _pluginInjectionApi$f4.forceFocusSelector, isViewOnly);
610
+ items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a8 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a8 === void 0 ? void 0 : _pluginInjectionApi$a8.actions, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$f3 = pluginInjectionApi.floatingToolbar) === null || _pluginInjectionApi$f3 === void 0 ? void 0 : (_pluginInjectionApi$f4 = _pluginInjectionApi$f3.actions) === null || _pluginInjectionApi$f4 === void 0 ? void 0 : _pluginInjectionApi$f4.forceFocusSelector, isViewOnly);
576
611
  } else if (allowMediaInline && selectedNodeType && selectedNodeType === mediaInline) {
577
612
  items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, options);
578
613
  } else {
@@ -4,6 +4,7 @@ import { IconCard, IconEmbed, IconInline } from '@atlaskit/editor-common/card';
4
4
  import commonMessages, { cardMessages, mediaAndEmbedToolbarMessages } from '@atlaskit/editor-common/messages';
5
5
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
6
  import DownloadIcon from '@atlaskit/icon/glyph/download';
7
+ import FilePreviewIcon from '@atlaskit/icon/glyph/editor/file-preview';
7
8
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
8
9
  import { messages } from '@atlaskit/media-ui';
9
10
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -18,7 +19,7 @@ import { FilePreviewItem } from './filePreviewItem';
18
19
  import { shouldShowImageBorder } from './imageBorder';
19
20
  import { LinkToolbarAppearance } from './linking-toolbar-appearance';
20
21
  import { downloadMedia } from './utils';
21
- import { generateFilePreviewItem } from './index';
22
+ import { generateFilePreviewItem, handleShowMediaViewer } from './index';
22
23
  export const generateMediaInlineFloatingToolbar = (state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, options = {}) => {
23
24
  var _pluginInjectionApi$a, _pluginInjectionApi$f, _pluginInjectionApi$f2;
24
25
  const editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
@@ -221,7 +222,19 @@ const getMediaInlineImageToolbar = (state, intl, mediaPluginState, hoverDecorati
221
222
 
222
223
  //Image Preview
223
224
  if (options.allowImagePreview) {
224
- inlineImageItems.push(generateFilePreviewItem(mediaPluginState, intl), {
225
+ inlineImageItems.push(fg('platform_editor_media_previewer_bugfix') ? {
226
+ id: 'editor.media.viewer',
227
+ type: 'button',
228
+ icon: FilePreviewIcon,
229
+ title: intl.formatMessage(messages.preview),
230
+ onClick: () => {
231
+ var _handleShowMediaViewe;
232
+ return (_handleShowMediaViewe = handleShowMediaViewer({
233
+ mediaPluginState,
234
+ api: pluginInjectionApi
235
+ })) !== null && _handleShowMediaViewe !== void 0 ? _handleShowMediaViewe : false;
236
+ }
237
+ } : generateFilePreviewItem(mediaPluginState, intl), {
225
238
  type: 'separator',
226
239
  supportsViewMode: true
227
240
  });
@@ -14,6 +14,7 @@ import { lazyMediaInlineView } from './nodeviews/lazy-media-inline';
14
14
  import { lazyMediaSingleView } from './nodeviews/lazy-media-single';
15
15
  import { createPlugin as createMediaAltTextPlugin } from './pm-plugins/alt-text';
16
16
  import keymapMediaAltTextPlugin from './pm-plugins/alt-text/keymap';
17
+ import { hideMediaViewer, showMediaViewer } from './pm-plugins/commands';
17
18
  import keymapPlugin from './pm-plugins/keymap';
18
19
  import keymapMediaSinglePlugin from './pm-plugins/keymap-media';
19
20
  import linkingPlugin from './pm-plugins/linking';
@@ -25,6 +26,7 @@ import { mediaInlineSpecWithFixedToDOM } from './toDOM-fixes/mediaInline';
25
26
  import { mediaSingleSpecWithFixedToDOM } from './toDOM-fixes/mediaSingle';
26
27
  import { floatingToolbar as _floatingToolbar } from './toolbar';
27
28
  import { MediaPickerComponents } from './ui/MediaPicker';
29
+ import { RenderMediaViewer } from './ui/MediaViewer/PortalWrapper';
28
30
  import ToolbarMedia from './ui/ToolbarMedia';
29
31
  import { insertMediaAsMediaSingle as _insertMediaAsMediaSingle } from './utils/media-single';
30
32
  var MediaPickerFunctionalComponent = function MediaPickerFunctionalComponent(_ref) {
@@ -43,10 +45,29 @@ var MediaPickerFunctionalComponent = function MediaPickerFunctionalComponent(_re
43
45
  api: api
44
46
  });
45
47
  };
46
- export var mediaPlugin = function mediaPlugin(_ref2) {
47
- var _ref2$config = _ref2.config,
48
- options = _ref2$config === void 0 ? {} : _ref2$config,
49
- api = _ref2.api;
48
+ var MediaViewerFunctionalComponent = function MediaViewerFunctionalComponent(_ref2) {
49
+ var api = _ref2.api;
50
+ var _useSharedPluginState2 = useSharedPluginState(api, ['media']),
51
+ mediaState = _useSharedPluginState2.mediaState;
52
+
53
+ // Viewer does not have required attributes to render the media viewer
54
+ if (!(mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaViewerSelectedMedia) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaClientConfig)) {
55
+ return null;
56
+ }
57
+ var handleOnClose = function handleOnClose() {
58
+ // Run Command to hide the media viewer
59
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.media.commands.hideMediaViewer);
60
+ };
61
+ return /*#__PURE__*/React.createElement(RenderMediaViewer, {
62
+ mediaClientConfig: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig,
63
+ onClose: handleOnClose,
64
+ selectedNodeAttrs: mediaState.mediaViewerSelectedMedia
65
+ });
66
+ };
67
+ export var mediaPlugin = function mediaPlugin(_ref3) {
68
+ var _ref3$config = _ref3.config,
69
+ options = _ref3$config === void 0 ? {} : _ref3$config,
70
+ api = _ref3.api;
50
71
  var previousMediaProvider;
51
72
  return {
52
73
  name: 'media',
@@ -68,22 +89,26 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
68
89
  return false;
69
90
  }
70
91
  previousMediaProvider = provider;
71
- return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(function (_ref3) {
72
- var tr = _ref3.tr;
92
+ return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(function (_ref4) {
93
+ var tr = _ref4.tr;
73
94
  return tr.setMeta(stateKey, {
74
95
  mediaProvider: provider
75
96
  });
76
97
  })) !== null && _api$core$actions$exe !== void 0 ? _api$core$actions$exe : false;
77
98
  }
78
99
  },
100
+ commands: {
101
+ showMediaViewer: showMediaViewer,
102
+ hideMediaViewer: hideMediaViewer
103
+ },
79
104
  nodes: function nodes() {
80
- var _ref4 = options || {},
81
- _ref4$allowMediaGroup = _ref4.allowMediaGroup,
82
- allowMediaGroup = _ref4$allowMediaGroup === void 0 ? true : _ref4$allowMediaGroup,
83
- _ref4$allowMediaSingl = _ref4.allowMediaSingle,
84
- allowMediaSingle = _ref4$allowMediaSingl === void 0 ? false : _ref4$allowMediaSingl,
85
- allowCaptions = _ref4.allowCaptions,
86
- mediaFeatureFlags = _ref4.featureFlags;
105
+ var _ref5 = options || {},
106
+ _ref5$allowMediaGroup = _ref5.allowMediaGroup,
107
+ allowMediaGroup = _ref5$allowMediaGroup === void 0 ? true : _ref5$allowMediaGroup,
108
+ _ref5$allowMediaSingl = _ref5.allowMediaSingle,
109
+ allowMediaSingle = _ref5$allowMediaSingl === void 0 ? false : _ref5$allowMediaSingl,
110
+ allowCaptions = _ref5.allowCaptions,
111
+ mediaFeatureFlags = _ref5.featureFlags;
87
112
  var allowMediaInline = getMediaFeatureFlag('mediaInline', mediaFeatureFlags);
88
113
  var mediaSingleOption = fg('platform.editor.media.extended-resize-experience') ? {
89
114
  withCaption: allowCaptions,
@@ -120,15 +145,15 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
120
145
  pmPlugins: function pmPlugins() {
121
146
  var pmPlugins = [{
122
147
  name: 'media',
123
- plugin: function plugin(_ref5) {
124
- var schema = _ref5.schema,
125
- dispatch = _ref5.dispatch,
126
- getIntl = _ref5.getIntl,
127
- eventDispatcher = _ref5.eventDispatcher,
128
- providerFactory = _ref5.providerFactory,
129
- errorReporter = _ref5.errorReporter,
130
- portalProviderAPI = _ref5.portalProviderAPI,
131
- dispatchAnalyticsEvent = _ref5.dispatchAnalyticsEvent;
148
+ plugin: function plugin(_ref6) {
149
+ var schema = _ref6.schema,
150
+ dispatch = _ref6.dispatch,
151
+ getIntl = _ref6.getIntl,
152
+ eventDispatcher = _ref6.eventDispatcher,
153
+ providerFactory = _ref6.providerFactory,
154
+ errorReporter = _ref6.errorReporter,
155
+ portalProviderAPI = _ref6.portalProviderAPI,
156
+ dispatchAnalyticsEvent = _ref6.dispatchAnalyticsEvent;
132
157
  return createPlugin(schema, {
133
158
  providerFactory: providerFactory,
134
159
  nodeViews: {
@@ -147,17 +172,17 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
147
172
  }
148
173
  }, {
149
174
  name: 'mediaKeymap',
150
- plugin: function plugin(_ref6) {
175
+ plugin: function plugin(_ref7) {
151
176
  var _api$analytics2, _api$selection;
152
- var getIntl = _ref6.getIntl;
177
+ var getIntl = _ref7.getIntl;
153
178
  return keymapPlugin(options, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.actions, api === null || api === void 0 ? void 0 : api.width, getIntl);
154
179
  }
155
180
  }];
156
181
  if (options && options.allowMediaSingle) {
157
182
  pmPlugins.push({
158
183
  name: 'mediaSingleKeymap',
159
- plugin: function plugin(_ref7) {
160
- var schema = _ref7.schema;
184
+ plugin: function plugin(_ref8) {
185
+ var schema = _ref8.schema;
161
186
  return keymapMediaSinglePlugin(schema);
162
187
  }
163
188
  });
@@ -169,9 +194,9 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
169
194
  });
170
195
  pmPlugins.push({
171
196
  name: 'mediaAltTextKeymap',
172
- plugin: function plugin(_ref8) {
197
+ plugin: function plugin(_ref9) {
173
198
  var _api$analytics3;
174
- var schema = _ref8.schema;
199
+ var schema = _ref9.schema;
175
200
  return keymapMediaAltTextPlugin(schema, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
176
201
  }
177
202
  });
@@ -179,15 +204,15 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
179
204
  if (options && options.allowLinking) {
180
205
  pmPlugins.push({
181
206
  name: 'mediaLinking',
182
- plugin: function plugin(_ref9) {
183
- var dispatch = _ref9.dispatch;
207
+ plugin: function plugin(_ref10) {
208
+ var dispatch = _ref10.dispatch;
184
209
  return linkingPlugin(dispatch);
185
210
  }
186
211
  });
187
212
  pmPlugins.push({
188
213
  name: 'mediaLinkingKeymap',
189
- plugin: function plugin(_ref10) {
190
- var schema = _ref10.schema;
214
+ plugin: function plugin(_ref11) {
215
+ var schema = _ref11.schema;
191
216
  return keymapLinkingPlugin(schema);
192
217
  }
193
218
  });
@@ -223,19 +248,21 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
223
248
  });
224
249
  return pmPlugins;
225
250
  },
226
- contentComponent: function contentComponent(_ref11) {
227
- var editorView = _ref11.editorView,
228
- appearance = _ref11.appearance;
229
- return /*#__PURE__*/React.createElement(MediaPickerFunctionalComponent, {
251
+ contentComponent: function contentComponent(_ref12) {
252
+ var editorView = _ref12.editorView,
253
+ appearance = _ref12.appearance;
254
+ return /*#__PURE__*/React.createElement(React.Fragment, null, fg('platform_editor_media_previewer_bugfix') && /*#__PURE__*/React.createElement(MediaViewerFunctionalComponent, {
255
+ api: api
256
+ }), /*#__PURE__*/React.createElement(MediaPickerFunctionalComponent, {
230
257
  editorDomElement: editorView.dom,
231
258
  appearance: appearance,
232
259
  api: api
233
- });
260
+ }));
234
261
  },
235
- secondaryToolbarComponent: function secondaryToolbarComponent(_ref12) {
236
- var editorView = _ref12.editorView,
237
- eventDispatcher = _ref12.eventDispatcher,
238
- disabled = _ref12.disabled;
262
+ secondaryToolbarComponent: function secondaryToolbarComponent(_ref13) {
263
+ var editorView = _ref13.editorView,
264
+ eventDispatcher = _ref13.eventDispatcher,
265
+ disabled = _ref13.disabled;
239
266
  return /*#__PURE__*/React.createElement(ToolbarMedia, {
240
267
  isDisabled: disabled,
241
268
  isReducedSpacing: true,
@@ -243,8 +270,8 @@ export var mediaPlugin = function mediaPlugin(_ref2) {
243
270
  });
244
271
  },
245
272
  pluginsOptions: {
246
- quickInsert: function quickInsert(_ref13) {
247
- var formatMessage = _ref13.formatMessage;
273
+ quickInsert: function quickInsert(_ref14) {
274
+ var formatMessage = _ref14.formatMessage;
248
275
  return editorExperiment('add-media-from-url', true) ? [] : [{
249
276
  id: 'media',
250
277
  title: formatMessage(messages.mediaFiles),
@@ -0,0 +1,4 @@
1
+ export var ACTIONS = {
2
+ SHOW_MEDIA_VIEWER: 'SHOW_MEDIA_VIEWER',
3
+ HIDE_MEDIA_VIEWER: 'HIDE_MEDIA_VIEWER'
4
+ };
@@ -0,0 +1,22 @@
1
+ import { ACTIONS } from '../pm-plugins/actions';
2
+ import { stateKey } from '../pm-plugins/plugin-key';
3
+ export var showMediaViewer = function showMediaViewer(media) {
4
+ return function (_ref) {
5
+ var tr = _ref.tr;
6
+ tr.setMeta(stateKey, {
7
+ type: ACTIONS.SHOW_MEDIA_VIEWER,
8
+ mediaViewerSelectedMedia: media,
9
+ isMediaViewerVisible: true
10
+ });
11
+ return tr;
12
+ };
13
+ };
14
+ export var hideMediaViewer = function hideMediaViewer(_ref2) {
15
+ var tr = _ref2.tr;
16
+ tr.setMeta(stateKey, {
17
+ type: ACTIONS.HIDE_MEDIA_VIEWER,
18
+ mediaViewerSelectedMedia: null,
19
+ isMediaViewerVisible: false
20
+ });
21
+ return tr;
22
+ };
@@ -33,6 +33,7 @@ import { removeMediaNode, splitMediaGroup } from '../utils/media-common';
33
33
  import { insertMediaGroupNode, insertMediaInlineNode } from '../utils/media-files';
34
34
  import { getMediaNodeInsertionType } from '../utils/media-inline';
35
35
  import { insertMediaSingleNode } from '../utils/media-single';
36
+ import { ACTIONS } from './actions';
36
37
  import { MediaTaskManager } from './mediaTaskManager';
37
38
  import { stateKey } from './plugin-key';
38
39
  export { stateKey } from './plugin-key';
@@ -766,6 +767,19 @@ export var createPlugin = function createPlugin(_schema, options, getIntl, plugi
766
767
  nextPluginState = nextPluginState.clone();
767
768
  }
768
769
 
770
+ // ACTIONS
771
+ switch (meta === null || meta === void 0 ? void 0 : meta.type) {
772
+ case ACTIONS.SHOW_MEDIA_VIEWER:
773
+ pluginState.mediaViewerSelectedMedia = meta.mediaViewerSelectedMedia;
774
+ pluginState.isMediaViewerVisible = true;
775
+ nextPluginState = nextPluginState.clone();
776
+ break;
777
+ case ACTIONS.HIDE_MEDIA_VIEWER:
778
+ pluginState.mediaViewerSelectedMedia = undefined;
779
+ nextPluginState = nextPluginState.clone();
780
+ break;
781
+ }
782
+
769
783
  // NOTE: We're not calling passing new state to the Editor, because we depend on the view.state reference
770
784
  // throughout the lifetime of view. We injected the view into the plugin state, because we dispatch()
771
785
  // transformations from within the plugin state (i.e. when adding a new file).
@@ -5,6 +5,7 @@ import FilePreviewIcon from '@atlaskit/icon/glyph/editor/file-preview';
5
5
  import { messages } from '@atlaskit/media-ui';
6
6
  import { RenderMediaViewer } from '../ui/MediaViewer/PortalWrapper';
7
7
  import { getSelectedNearestMediaContainerNodeAttrs } from './utils';
8
+ // This function will eventially be removed when platform_editor_media_previewer_bugfix is cleaned up
8
9
  export var FilePreviewItem = function FilePreviewItem(_ref) {
9
10
  var mediaPluginState = _ref.mediaPluginState,
10
11
  intl = _ref.intl;
@@ -12,7 +13,7 @@ export var FilePreviewItem = function FilePreviewItem(_ref) {
12
13
  _useState2 = _slicedToArray(_useState, 2),
13
14
  isMediaViewerVisible = _useState2[0],
14
15
  setMediaViewerVisible = _useState2[1];
15
- var openMediaViewer = function openMediaViewer() {
16
+ var showMediaViewer = function showMediaViewer() {
16
17
  setMediaViewerVisible(true);
17
18
  };
18
19
  var onMediaViewerClose = function onMediaViewerClose() {
@@ -24,7 +25,7 @@ export var FilePreviewItem = function FilePreviewItem(_ref) {
24
25
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ToolbarButton, {
25
26
  testId: "file-preview-toolbar-button",
26
27
  key: "editor.media.card.preview",
27
- onClick: openMediaViewer,
28
+ onClick: showMediaViewer,
28
29
  icon: /*#__PURE__*/React.createElement(FilePreviewIcon, {
29
30
  label: "file preview"
30
31
  }),
@@ -13,6 +13,7 @@ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
13
13
  import { contains, findParentNodeOfType, hasParentNode, hasParentNodeOfType, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
14
14
  import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
15
15
  import DownloadIcon from '@atlaskit/icon/glyph/download';
16
+ import FilePreviewIcon from '@atlaskit/icon/glyph/editor/file-preview';
16
17
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
17
18
  import { mediaFilmstripItemDOMSelector } from '@atlaskit/media-filmstrip';
18
19
  import { messages } from '@atlaskit/media-ui';
@@ -35,7 +36,7 @@ import { LayoutGroup } from './layout-group';
35
36
  import { getLinkingToolbar, shouldShowMediaLinkToolbar } from './linking';
36
37
  import { LinkToolbarAppearance } from './linking-toolbar-appearance';
37
38
  import { generateMediaInlineFloatingToolbar } from './mediaInline';
38
- import { calcNewLayout, canShowSwitchButtons, downloadMedia, getMaxToolbarWidth, getPixelWidthOfElement, getSelectedLayoutIcon, getSelectedMediaSingle, removeMediaGroupNode } from './utils';
39
+ import { calcNewLayout, canShowSwitchButtons, downloadMedia, getMaxToolbarWidth, getPixelWidthOfElement, getSelectedLayoutIcon, getSelectedMediaSingle, getSelectedNearestMediaContainerNodeAttrs, removeMediaGroupNode } from './utils';
39
40
  var mediaTypeMessages = {
40
41
  image: messages.file_image_is_selected,
41
42
  video: messages.file_video_is_selected,
@@ -71,7 +72,16 @@ export var generateFilePreviewItem = function generateFilePreviewItem(mediaPlugi
71
72
  supportsViewMode: true
72
73
  };
73
74
  };
74
- var generateMediaCardFloatingToolbar = function generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, forceFocusSelector, isViewOnly) {
75
+ export var handleShowMediaViewer = function handleShowMediaViewer(_ref) {
76
+ var api = _ref.api,
77
+ mediaPluginState = _ref.mediaPluginState;
78
+ var selectedNodeAttrs = getSelectedNearestMediaContainerNodeAttrs(mediaPluginState);
79
+ if (!selectedNodeAttrs) {
80
+ return false;
81
+ }
82
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.media.commands.showMediaViewer(selectedNodeAttrs));
83
+ };
84
+ var generateMediaCardFloatingToolbar = function generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, editorAnalyticsAPI, forceFocusSelector, isViewOnly) {
75
85
  if (isViewOnly) {
76
86
  return [];
77
87
  }
@@ -102,7 +112,19 @@ var generateMediaCardFloatingToolbar = function generateMediaCardFloatingToolbar
102
112
  className: 'thumbnail-appearance' // a11y. uses to force focus on item
103
113
  }, {
104
114
  type: 'separator'
105
- }, generateFilePreviewItem(mediaPluginState, intl), {
115
+ }, fg('platform_editor_media_previewer_bugfix') ? {
116
+ id: 'editor.media.viewer',
117
+ type: 'button',
118
+ icon: FilePreviewIcon,
119
+ title: intl.formatMessage(messages.preview),
120
+ onClick: function onClick() {
121
+ var _handleShowMediaViewe;
122
+ return (_handleShowMediaViewe = handleShowMediaViewer({
123
+ mediaPluginState: mediaPluginState,
124
+ api: pluginInjectionApi
125
+ })) !== null && _handleShowMediaViewe !== void 0 ? _handleShowMediaViewe : false;
126
+ }
127
+ } : generateFilePreviewItem(mediaPluginState, intl), {
106
128
  type: 'separator'
107
129
  }, {
108
130
  id: 'editor.media.card.download',
@@ -157,8 +179,8 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
157
179
  isViewOnly = options.isViewOnly;
158
180
  var editorFeatureFlags = getEditorFeatureFlags ? getEditorFeatureFlags() : undefined;
159
181
  var toolbarButtons = [];
160
- var _ref = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d2 = pluginInjectionApi.decorations) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {},
161
- hoverDecoration = _ref.hoverDecoration;
182
+ var _ref2 = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d2 = pluginInjectionApi.decorations) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {},
183
+ hoverDecoration = _ref2.hoverDecoration;
162
184
  if (shouldShowImageBorder(state)) {
163
185
  toolbarButtons.push({
164
186
  type: 'custom',
@@ -333,10 +355,10 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
333
355
  hoverDecoration === null || hoverDecoration === void 0 || hoverDecoration(mediaSingle, false)(editorView.state, dispatch, editorView);
334
356
  }
335
357
  },
336
- onSubmit: function onSubmit(_ref2) {
358
+ onSubmit: function onSubmit(_ref3) {
337
359
  var _pluginInjectionApi$a5;
338
- var width = _ref2.width,
339
- validation = _ref2.validation;
360
+ var width = _ref3.width,
361
+ validation = _ref3.validation;
340
362
  var newLayout = calcNewLayout(width, layout, contentWidth, options.fullWidthEnabled, isNested);
341
363
  updateMediaSingleWidth(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a5 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a5 === void 0 ? void 0 : _pluginInjectionApi$a5.actions)(width, validation, 'floatingToolBar', newLayout)(state, dispatch);
342
364
  },
@@ -434,7 +456,19 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
434
456
  var _selectedMediaSingleNode = getSelectedMediaSingle(state);
435
457
  var mediaNode = _selectedMediaSingleNode === null || _selectedMediaSingleNode === void 0 ? void 0 : _selectedMediaSingleNode.node.content.firstChild;
436
458
  if (!isVideo(mediaNode === null || mediaNode === void 0 || (_mediaNode$attrs = mediaNode.attrs) === null || _mediaNode$attrs === void 0 ? void 0 : _mediaNode$attrs.__fileMimeType)) {
437
- toolbarButtons.push(generateFilePreviewItem(pluginState, intl), {
459
+ toolbarButtons.push(fg('platform_editor_media_previewer_bugfix') ? {
460
+ id: 'editor.media.viewer',
461
+ type: 'button',
462
+ icon: FilePreviewIcon,
463
+ title: intl.formatMessage(messages.preview),
464
+ onClick: function onClick() {
465
+ var _handleShowMediaViewe2;
466
+ return (_handleShowMediaViewe2 = handleShowMediaViewer({
467
+ api: pluginInjectionApi,
468
+ mediaPluginState: pluginState
469
+ })) !== null && _handleShowMediaViewe2 !== void 0 ? _handleShowMediaViewe2 : false;
470
+ }
471
+ } : generateFilePreviewItem(pluginState, intl), {
438
472
  type: 'separator',
439
473
  supportsViewMode: true
440
474
  });
@@ -518,8 +552,8 @@ export var floatingToolbar = function floatingToolbar(state, intl) {
518
552
  isViewOnly = options.isViewOnly;
519
553
  var mediaPluginState = stateKey.getState(state);
520
554
  var mediaLinkingState = getMediaLinkingState(state);
521
- var _ref3 = (_pluginInjectionApi$d3 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d4 = pluginInjectionApi.decorations) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.actions) !== null && _pluginInjectionApi$d3 !== void 0 ? _pluginInjectionApi$d3 : {},
522
- hoverDecoration = _ref3.hoverDecoration;
555
+ var _ref4 = (_pluginInjectionApi$d3 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d4 = pluginInjectionApi.decorations) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.actions) !== null && _pluginInjectionApi$d3 !== void 0 ? _pluginInjectionApi$d3 : {},
556
+ hoverDecoration = _ref4.hoverDecoration;
523
557
  if (!mediaPluginState) {
524
558
  return;
525
559
  }
@@ -561,7 +595,7 @@ export var floatingToolbar = function floatingToolbar(state, intl) {
561
595
  var selector = mediaFilmstripItemDOMSelector(mediaOffset);
562
596
  return (_mediaPluginState$ele = mediaPluginState.element) === null || _mediaPluginState$ele === void 0 ? void 0 : _mediaPluginState$ele.querySelector(selector);
563
597
  };
564
- items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a8 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a8 === void 0 ? void 0 : _pluginInjectionApi$a8.actions, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$f2 = pluginInjectionApi.floatingToolbar) === null || _pluginInjectionApi$f2 === void 0 || (_pluginInjectionApi$f2 = _pluginInjectionApi$f2.actions) === null || _pluginInjectionApi$f2 === void 0 ? void 0 : _pluginInjectionApi$f2.forceFocusSelector, isViewOnly);
598
+ items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a8 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a8 === void 0 ? void 0 : _pluginInjectionApi$a8.actions, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$f2 = pluginInjectionApi.floatingToolbar) === null || _pluginInjectionApi$f2 === void 0 || (_pluginInjectionApi$f2 = _pluginInjectionApi$f2.actions) === null || _pluginInjectionApi$f2 === void 0 ? void 0 : _pluginInjectionApi$f2.forceFocusSelector, isViewOnly);
565
599
  } else if (allowMediaInline && selectedNodeType && selectedNodeType === mediaInline) {
566
600
  items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, options);
567
601
  } else {
@@ -4,6 +4,7 @@ import { IconCard, IconEmbed, IconInline } from '@atlaskit/editor-common/card';
4
4
  import commonMessages, { cardMessages, mediaAndEmbedToolbarMessages } from '@atlaskit/editor-common/messages';
5
5
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
6
  import DownloadIcon from '@atlaskit/icon/glyph/download';
7
+ import FilePreviewIcon from '@atlaskit/icon/glyph/editor/file-preview';
7
8
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
8
9
  import { messages } from '@atlaskit/media-ui';
9
10
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -18,7 +19,7 @@ import { FilePreviewItem } from './filePreviewItem';
18
19
  import { shouldShowImageBorder } from './imageBorder';
19
20
  import { LinkToolbarAppearance } from './linking-toolbar-appearance';
20
21
  import { downloadMedia } from './utils';
21
- import { generateFilePreviewItem } from './index';
22
+ import { generateFilePreviewItem, handleShowMediaViewer } from './index';
22
23
  export var generateMediaInlineFloatingToolbar = function generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi) {
23
24
  var _pluginInjectionApi$a, _pluginInjectionApi$f;
24
25
  var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
@@ -217,7 +218,19 @@ var getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl
217
218
 
218
219
  //Image Preview
219
220
  if (options.allowImagePreview) {
220
- inlineImageItems.push(generateFilePreviewItem(mediaPluginState, intl), {
221
+ inlineImageItems.push(fg('platform_editor_media_previewer_bugfix') ? {
222
+ id: 'editor.media.viewer',
223
+ type: 'button',
224
+ icon: FilePreviewIcon,
225
+ title: intl.formatMessage(messages.preview),
226
+ onClick: function onClick() {
227
+ var _handleShowMediaViewe;
228
+ return (_handleShowMediaViewe = handleShowMediaViewer({
229
+ mediaPluginState: mediaPluginState,
230
+ api: pluginInjectionApi
231
+ })) !== null && _handleShowMediaViewe !== void 0 ? _handleShowMediaViewe : false;
232
+ }
233
+ } : generateFilePreviewItem(mediaPluginState, intl), {
221
234
  type: 'separator',
222
235
  supportsViewMode: true
223
236
  });
@@ -1,5 +1,6 @@
1
+ import type { MediaADFAttrs } from '@atlaskit/adf-schema';
1
2
  import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
2
- import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
+ import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
4
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
5
  import type { AnnotationPlugin } from '@atlaskit/editor-plugin-annotation';
5
6
  import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
@@ -47,4 +48,8 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
47
48
  */
48
49
  setProvider: (provider: Promise<MediaProvider>) => boolean;
49
50
  };
51
+ commands: {
52
+ showMediaViewer: (media: MediaADFAttrs) => EditorCommand;
53
+ hideMediaViewer: EditorCommand;
54
+ };
50
55
  }>;
@@ -0,0 +1,4 @@
1
+ export declare const ACTIONS: {
2
+ SHOW_MEDIA_VIEWER: string;
3
+ HIDE_MEDIA_VIEWER: string;
4
+ };
@@ -0,0 +1,4 @@
1
+ import type { MediaADFAttrs } from '@atlaskit/adf-schema';
2
+ import type { EditorCommand } from '@atlaskit/editor-common/types';
3
+ export declare const showMediaViewer: (media: MediaADFAttrs) => EditorCommand;
4
+ export declare const hideMediaViewer: EditorCommand;
@@ -1,4 +1,4 @@
1
- import type { RichMediaLayout as MediaSingleLayout } from '@atlaskit/adf-schema';
1
+ import type { MediaADFAttrs, RichMediaLayout as MediaSingleLayout } from '@atlaskit/adf-schema';
2
2
  import { type InsertMediaVia } from '@atlaskit/editor-common/analytics';
3
3
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
4
4
  import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
@@ -69,5 +69,7 @@ export interface MediaPluginState {
69
69
  clone(): MediaPluginState;
70
70
  subscribeToUploadInProgressState(fn: (isUploading: boolean) => void): void;
71
71
  unsubscribeFromUploadInProgressState(fn: (isUploading: boolean) => void): void;
72
+ isMediaViewerVisible?: boolean;
73
+ mediaViewerSelectedMedia?: MediaADFAttrs;
72
74
  }
73
75
  export type EventInput = 'keyboard' | 'mouse' | 'floatingToolBar';
@@ -5,4 +5,8 @@ import type { MediaNextEditorPluginType } from '../next-plugin-type';
5
5
  import type { MediaPluginState } from '../pm-plugins/types';
6
6
  import type { MediaFloatingToolbarOptions } from '../types';
7
7
  export declare const generateFilePreviewItem: (mediaPluginState: MediaPluginState, intl: IntlShape) => FloatingToolbarItem<Command>;
8
+ export declare const handleShowMediaViewer: ({ api, mediaPluginState, }: {
9
+ api: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined;
10
+ mediaPluginState: MediaPluginState;
11
+ }) => false | undefined;
8
12
  export declare const floatingToolbar: (state: EditorState, intl: IntlShape, options: MediaFloatingToolbarOptions | undefined, pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined) => FloatingToolbarConfig | undefined;