@atlaskit/editor-plugin-media 1.10.1 → 1.12.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 (39) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/nodeviews/mediaInline.js +27 -15
  3. package/dist/cjs/nodeviews/mediaSingle.js +21 -8
  4. package/dist/cjs/toolbar/comments.js +7 -4
  5. package/dist/cjs/toolbar/filePreviewItem.js +5 -26
  6. package/dist/cjs/toolbar/utils.js +4 -2
  7. package/dist/cjs/ui/MediaViewer/MediaViewerContainer.js +66 -0
  8. package/dist/cjs/ui/MediaViewer/PortalWrapper.js +30 -0
  9. package/dist/es2019/nodeviews/mediaInline.js +27 -11
  10. package/dist/es2019/nodeviews/mediaSingle.js +21 -8
  11. package/dist/es2019/toolbar/comments.js +7 -4
  12. package/dist/es2019/toolbar/filePreviewItem.js +1 -24
  13. package/dist/es2019/toolbar/utils.js +4 -2
  14. package/dist/es2019/ui/MediaViewer/MediaViewerContainer.js +49 -0
  15. package/dist/es2019/ui/MediaViewer/PortalWrapper.js +25 -0
  16. package/dist/esm/nodeviews/mediaInline.js +27 -11
  17. package/dist/esm/nodeviews/mediaSingle.js +21 -8
  18. package/dist/esm/toolbar/comments.js +7 -4
  19. package/dist/esm/toolbar/filePreviewItem.js +4 -25
  20. package/dist/esm/toolbar/utils.js +4 -2
  21. package/dist/esm/ui/MediaViewer/MediaViewerContainer.js +55 -0
  22. package/dist/esm/ui/MediaViewer/PortalWrapper.js +23 -0
  23. package/dist/types/next-plugin-type.d.ts +2 -0
  24. package/dist/types/nodeviews/mediaInline.d.ts +4 -3
  25. package/dist/types/nodeviews/mediaSingle.d.ts +1 -2
  26. package/dist/types/nodeviews/types.d.ts +2 -0
  27. package/dist/types/toolbar/comments.d.ts +1 -1
  28. package/dist/types/ui/MediaViewer/MediaViewerContainer.d.ts +16 -0
  29. package/dist/types/ui/MediaViewer/PortalWrapper.d.ts +10 -0
  30. package/dist/types/ui/ResizableMediaSingle/types.d.ts +1 -0
  31. package/dist/types-ts4.5/next-plugin-type.d.ts +2 -0
  32. package/dist/types-ts4.5/nodeviews/mediaInline.d.ts +4 -3
  33. package/dist/types-ts4.5/nodeviews/mediaSingle.d.ts +1 -2
  34. package/dist/types-ts4.5/nodeviews/types.d.ts +2 -0
  35. package/dist/types-ts4.5/toolbar/comments.d.ts +1 -1
  36. package/dist/types-ts4.5/ui/MediaViewer/MediaViewerContainer.d.ts +16 -0
  37. package/dist/types-ts4.5/ui/MediaViewer/PortalWrapper.d.ts +10 -0
  38. package/dist/types-ts4.5/ui/ResizableMediaSingle/types.d.ts +1 -0
  39. package/package.json +7 -4
@@ -1,32 +1,9 @@
1
1
  import React, { useState } from 'react';
2
- import ReactDOM from 'react-dom';
3
2
  import { FloatingToolbarButton as ToolbarButton } from '@atlaskit/editor-common/ui';
4
3
  import FilePreviewIcon from '@atlaskit/icon/glyph/editor/file-preview';
5
4
  import { messages } from '@atlaskit/media-ui';
6
- import { MediaViewer } from '@atlaskit/media-viewer';
5
+ import { RenderMediaViewer } from '../ui/MediaViewer/PortalWrapper';
7
6
  import { getSelectedNearestMediaContainerNodeAttrs } from './utils';
8
- const RenderMediaViewer = ({
9
- mediaClientConfig,
10
- onClose,
11
- selectedNodeAttrs
12
- }) => {
13
- const {
14
- id,
15
- collection = ''
16
- } = selectedNodeAttrs;
17
- const identifier = {
18
- id,
19
- mediaItemType: 'file',
20
- collectionName: collection
21
- };
22
- return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(MediaViewer, {
23
- collectionName: collection,
24
- items: [],
25
- mediaClientConfig: mediaClientConfig,
26
- selectedItem: identifier,
27
- onClose: onClose
28
- }), document.body);
29
- };
30
7
  export const FilePreviewItem = ({
31
8
  mediaPluginState,
32
9
  intl
@@ -6,14 +6,16 @@ import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
6
6
  import { getMediaClient } from '@atlaskit/media-client-react';
7
7
  import { isVideo } from '../utils/media-single';
8
8
  export const getSelectedMediaContainerNodeAttrs = mediaPluginState => {
9
- const selectedNode = mediaPluginState.selectedMediaContainerNode();
9
+ var _mediaPluginState$sel;
10
+ const selectedNode = (_mediaPluginState$sel = mediaPluginState.selectedMediaContainerNode) === null || _mediaPluginState$sel === void 0 ? void 0 : _mediaPluginState$sel.call(mediaPluginState);
10
11
  if (selectedNode && selectedNode.attrs) {
11
12
  return selectedNode.attrs;
12
13
  }
13
14
  return null;
14
15
  };
15
16
  export const getSelectedNearestMediaContainerNodeAttrs = mediaPluginState => {
16
- const selectedNode = mediaPluginState.selectedMediaContainerNode();
17
+ var _mediaPluginState$sel2;
18
+ const selectedNode = (_mediaPluginState$sel2 = mediaPluginState.selectedMediaContainerNode) === null || _mediaPluginState$sel2 === void 0 ? void 0 : _mediaPluginState$sel2.call(mediaPluginState);
17
19
  if (selectedNode) {
18
20
  switch (selectedNode.type.name) {
19
21
  case 'mediaSingle':
@@ -0,0 +1,49 @@
1
+ /** @jsx jsx */
2
+ import React, { Fragment, useEffect, useState } from 'react';
3
+ import { css, jsx } from '@emotion/react';
4
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
+ import { getSelectedNearestMediaContainerNodeAttrs } from '../../toolbar/utils';
6
+ import { isVideo } from '../../utils/is-type';
7
+ import { RenderMediaViewer } from './PortalWrapper';
8
+ const interactiveStyles = css({
9
+ cursor: 'pointer'
10
+ });
11
+ export const mediaViewerContainerTestID = 'media-viewer-container-test';
12
+ export const MediaViewerContainer = ({
13
+ mediaNode,
14
+ mediaPluginState,
15
+ isEditorViewMode = false,
16
+ isSelected = true,
17
+ isInline = false,
18
+ children
19
+ }) => {
20
+ var _mediaNode$firstChild;
21
+ const [showViewer, setShowMediaViewer] = useState(false);
22
+ useEffect(() => {
23
+ setShowMediaViewer(isSelected);
24
+ }, [isSelected]);
25
+ const selectedNodeAttrs = getSelectedNearestMediaContainerNodeAttrs(mediaPluginState);
26
+ const mediaClientConfig = mediaPluginState.mediaClientConfig;
27
+ const showMediaViewer = () => {
28
+ setShowMediaViewer(true);
29
+ };
30
+ const closeMediaViewer = () => {
31
+ setShowMediaViewer(false);
32
+ };
33
+ const isVideoMedia = isVideo((_mediaNode$firstChild = mediaNode.firstChild) === null || _mediaNode$firstChild === void 0 ? void 0 : _mediaNode$firstChild.attrs.__fileMimeType);
34
+ const enableMediaViewer = getBooleanFF('platform.editor.media.preview-in-full-page') && isEditorViewMode;
35
+ const shouldShowViewer = enableMediaViewer && showViewer && selectedNodeAttrs && mediaClientConfig && !isVideoMedia;
36
+ return jsx(Fragment, null, enableMediaViewer ? jsx(Fragment, null, isInline ? jsx("span", {
37
+ onClick: showMediaViewer,
38
+ css: interactiveStyles,
39
+ "data-testid": mediaViewerContainerTestID
40
+ }, children) : jsx("div", {
41
+ onClick: showMediaViewer,
42
+ css: interactiveStyles,
43
+ "data-testid": mediaViewerContainerTestID
44
+ }, children), shouldShowViewer && jsx(RenderMediaViewer, {
45
+ selectedNodeAttrs: selectedNodeAttrs,
46
+ mediaClientConfig: mediaClientConfig,
47
+ onClose: closeMediaViewer
48
+ })) : children);
49
+ };
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import { MediaViewer } from '@atlaskit/media-viewer';
4
+ export const RenderMediaViewer = ({
5
+ mediaClientConfig,
6
+ onClose,
7
+ selectedNodeAttrs
8
+ }) => {
9
+ const {
10
+ id,
11
+ collection = ''
12
+ } = selectedNodeAttrs;
13
+ const identifier = {
14
+ id,
15
+ mediaItemType: 'file',
16
+ collectionName: collection
17
+ };
18
+ return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(MediaViewer, {
19
+ collectionName: collection,
20
+ items: [],
21
+ mediaClientConfig: mediaClientConfig,
22
+ selectedItem: identifier,
23
+ onClose: onClose
24
+ }), document.body);
25
+ };
@@ -12,7 +12,9 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
12
12
  import _regeneratorRuntime from "@babel/runtime/regenerator";
13
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
- import React, { useEffect, useState } from 'react';
15
+ /** @jsx jsx */
16
+ import { useEffect, useState } from 'react';
17
+ import { jsx } from '@emotion/react';
16
18
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
17
19
  import { MediaInlineImageCard } from '@atlaskit/editor-common/media-inline';
18
20
  import { WithProviders } from '@atlaskit/editor-common/provider-factory';
@@ -20,6 +22,7 @@ import { SelectionBasedNodeView } from '@atlaskit/editor-common/selection-based-
20
22
  import { MediaInlineCard } from '@atlaskit/media-card';
21
23
  import { getMediaClient } from '@atlaskit/media-client-react';
22
24
  import { MediaInlineCardLoadingView } from '@atlaskit/media-ui';
25
+ import { MediaViewerContainer } from '../ui/MediaViewer/MediaViewerContainer';
23
26
  import { isImage } from '../utils/is-type';
24
27
  import { MediaNodeUpdater } from './mediaNodeUpdater';
25
28
  import { MediaInlineNodeSelector } from './styles';
@@ -170,7 +173,7 @@ export var MediaInline = function MediaInline(props) {
170
173
  * before the prerequisites meet
171
174
  */
172
175
  if (!viewMediaClientConfig || isContextIdUnsync) {
173
- return /*#__PURE__*/React.createElement(MediaInlineCardLoadingView, {
176
+ return jsx(MediaInlineCardLoadingView, {
174
177
  message: "",
175
178
  isSelected: false
176
179
  });
@@ -180,7 +183,13 @@ export var MediaInline = function MediaInline(props) {
180
183
  return mark.type.name === 'border';
181
184
  });
182
185
  if (allowInlineImages && isImage(type)) {
183
- return /*#__PURE__*/React.createElement(MediaInlineImageCard, {
186
+ return jsx(MediaViewerContainer, {
187
+ mediaNode: props.node,
188
+ mediaPluginState: props.mediaPluginState,
189
+ isEditorViewMode: props.editorViewMode,
190
+ isSelected: props.isSelected,
191
+ isInline: true
192
+ }, jsx(MediaInlineImageCard, {
184
193
  mediaClient: getMediaClient(viewMediaClientConfig),
185
194
  identifier: identifier,
186
195
  isSelected: props.isSelected,
@@ -191,13 +200,18 @@ export var MediaInline = function MediaInline(props) {
191
200
  borderSize: borderMark === null || borderMark === void 0 ? void 0 : borderMark.attrs.size,
192
201
  borderColor: borderMark === null || borderMark === void 0 ? void 0 : borderMark.attrs.color
193
202
  }
194
- });
203
+ }));
195
204
  }
196
- return /*#__PURE__*/React.createElement(MediaInlineCard, {
205
+ return jsx(MediaViewerContainer, {
206
+ mediaNode: props.node,
207
+ mediaPluginState: props.mediaPluginState,
208
+ isEditorViewMode: props.editorViewMode,
209
+ isSelected: props.isSelected
210
+ }, jsx(MediaInlineCard, {
197
211
  isSelected: props.isSelected,
198
212
  identifier: identifier,
199
213
  mediaClientConfig: viewMediaClientConfig
200
- });
214
+ }));
201
215
  };
202
216
  var MediaInlineSharedState = function MediaInlineSharedState(_ref3) {
203
217
  var identifier = _ref3.identifier,
@@ -208,12 +222,13 @@ var MediaInlineSharedState = function MediaInlineSharedState(_ref3) {
208
222
  contextIdentifierProvider = _ref3.contextIdentifierProvider,
209
223
  api = _ref3.api,
210
224
  view = _ref3.view;
211
- var _useSharedPluginState = useSharedPluginState(api, ['media']),
225
+ var _useSharedPluginState = useSharedPluginState(api, ['editorViewMode', 'media']),
226
+ editorViewModeState = _useSharedPluginState.editorViewModeState,
212
227
  mediaState = _useSharedPluginState.mediaState;
213
228
  if (!mediaState) {
214
229
  return null;
215
230
  }
216
- return /*#__PURE__*/React.createElement(MediaInline, {
231
+ return jsx(MediaInline, {
217
232
  identifier: identifier,
218
233
  mediaProvider: mediaProvider,
219
234
  mediaPluginState: mediaState,
@@ -221,7 +236,8 @@ var MediaInlineSharedState = function MediaInlineSharedState(_ref3) {
221
236
  isSelected: isSelected,
222
237
  view: view,
223
238
  getPos: getPos,
224
- contextIdentifierProvider: contextIdentifierProvider
239
+ contextIdentifierProvider: contextIdentifierProvider,
240
+ editorViewMode: (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view'
225
241
  });
226
242
  };
227
243
  export var MediaInlineNodeView = /*#__PURE__*/function (_SelectionBasedNodeVi) {
@@ -268,7 +284,7 @@ export var MediaInlineNodeView = /*#__PURE__*/function (_SelectionBasedNodeVi) {
268
284
  api = props.api;
269
285
  var view = this.view;
270
286
  var getPos = this.getPos;
271
- return /*#__PURE__*/React.createElement(WithProviders, {
287
+ return jsx(WithProviders, {
272
288
  providers: ['mediaProvider', 'contextIdentifierProvider'],
273
289
  providerFactory: providerFactory,
274
290
  renderNode: function renderNode(_ref4) {
@@ -277,7 +293,7 @@ export var MediaInlineNodeView = /*#__PURE__*/function (_SelectionBasedNodeVi) {
277
293
  if (!mediaProvider) {
278
294
  return null;
279
295
  }
280
- return /*#__PURE__*/React.createElement(MediaInlineSharedState, {
296
+ return jsx(MediaInlineSharedState, {
281
297
  identifier: _this.node.attrs.id,
282
298
  mediaProvider: mediaProvider,
283
299
  node: _this.node,
@@ -31,6 +31,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
31
31
  import { insertAndSelectCaptionFromMediaSinglePos } from '../commands/captions';
32
32
  import { MEDIA_CONTENT_WRAP_CLASS_NAME } from '../pm-plugins/main';
33
33
  import CaptionPlaceholder from '../ui/CaptionPlaceholder';
34
+ import { MediaViewerContainer } from '../ui/MediaViewer/MediaViewerContainer';
34
35
  import ResizableMediaSingle from '../ui/ResizableMediaSingle';
35
36
  import ResizableMediaSingleNext from '../ui/ResizableMediaSingle/ResizableMediaSingleNext';
36
37
  import { isMediaBlobUrlFromAttrs } from '../utils/media-common';
@@ -229,10 +230,10 @@ var MediaSingleNode = /*#__PURE__*/function (_Component) {
229
230
  tr.setSelection(NodeSelection.create(tr.doc, pos));
230
231
  return dispatch(tr);
231
232
  });
232
- // Workaround for iOS 16 Caption selection issue
233
- // @see https://product-fabric.atlassian.net/browse/MEX-2012
234
233
  _defineProperty(_assertThisInitialized(_this), "onMediaSingleClicked", function (event) {
235
234
  var _this$captionPlaceHol;
235
+ // Workaround for iOS 16 Caption selection issue
236
+ // @see https://product-fabric.atlassian.net/browse/MEX-2012
236
237
  if (!browser.ios) {
237
238
  return;
238
239
  }
@@ -331,7 +332,9 @@ var MediaSingleNode = /*#__PURE__*/function (_Component) {
331
332
  pluginInjectionApi = _this$props2.pluginInjectionApi,
332
333
  containerWidth = _this$props2.width,
333
334
  lineLength = _this$props2.lineLength,
334
- dispatchAnalyticsEvent = _this$props2.dispatchAnalyticsEvent;
335
+ dispatchAnalyticsEvent = _this$props2.dispatchAnalyticsEvent,
336
+ editorViewMode = _this$props2.editorViewMode,
337
+ mediaPluginState = _this$props2.mediaPluginState;
335
338
  var _ref4 = node.attrs,
336
339
  layout = _ref4.layout,
337
340
  widthType = _ref4.widthType,
@@ -425,14 +428,20 @@ var MediaSingleNode = /*#__PURE__*/function (_Component) {
425
428
  ref: this.captionPlaceHolderRef,
426
429
  onClick: this.clickPlaceholder
427
430
  }));
428
- return canResize ? getBooleanFF('platform.editor.media.extended-resize-experience') ? jsx(ResizableMediaSingleNext, _extends({}, resizableMediaSingleProps, {
431
+ return jsx(MediaViewerContainer, {
432
+ mediaPluginState: mediaPluginState,
433
+ isEditorViewMode: editorViewMode,
434
+ mediaNode: node,
435
+ isSelected: isSelected,
436
+ isInline: false
437
+ }, canResize ? getBooleanFF('platform.editor.media.extended-resize-experience') ? jsx(ResizableMediaSingleNext, _extends({}, resizableMediaSingleProps, {
429
438
  showLegacyNotification: widthType !== 'pixel'
430
439
  }), MediaChildren) : jsx(ResizableMediaSingle, _extends({}, resizableMediaSingleProps, {
431
440
  lineLength: contentWidthForLegacyExperience,
432
441
  pctWidth: mediaSingleWidthAttribute
433
442
  }), MediaChildren) : jsx(MediaSingle, _extends({}, mediaSingleProps, {
434
443
  pctWidth: mediaSingleWidthAttribute
435
- }), MediaChildren);
444
+ }), MediaChildren));
436
445
  }
437
446
  }]);
438
447
  return MediaSingleNode;
@@ -455,10 +464,12 @@ var MediaSingleNodeWrapper = function MediaSingleNodeWrapper(_ref5) {
455
464
  eventDispatcher = _ref5.eventDispatcher,
456
465
  dispatchAnalyticsEvent = _ref5.dispatchAnalyticsEvent,
457
466
  forwardRef = _ref5.forwardRef;
458
- var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['width', 'media', 'annotation']),
467
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['width', 'media', 'annotation', 'editorDisabled', 'editorViewMode']),
459
468
  widthState = _useSharedPluginState.widthState,
460
469
  mediaState = _useSharedPluginState.mediaState,
461
- annotationState = _useSharedPluginState.annotationState;
470
+ annotationState = _useSharedPluginState.annotationState,
471
+ editorDisabledState = _useSharedPluginState.editorDisabledState,
472
+ editorViewModeState = _useSharedPluginState.editorViewModeState;
462
473
  return jsx(MediaSingleNode, {
463
474
  width: widthState.width,
464
475
  lineLength: widthState.lineLength,
@@ -475,7 +486,9 @@ var MediaSingleNodeWrapper = function MediaSingleNodeWrapper(_ref5) {
475
486
  annotationPluginState: annotationState !== null && annotationState !== void 0 ? annotationState : undefined,
476
487
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
477
488
  forwardRef: forwardRef,
478
- pluginInjectionApi: pluginInjectionApi
489
+ pluginInjectionApi: pluginInjectionApi,
490
+ editorDisabled: editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled,
491
+ editorViewMode: (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view'
479
492
  });
480
493
  };
481
494
  var MediaSingleNodeView = /*#__PURE__*/function (_ReactNodeView) {
@@ -2,14 +2,17 @@ import React from 'react';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
3
  import { ToolTipContent } from '@atlaskit/editor-common/keymaps';
4
4
  import { commentMessages as messages } from '@atlaskit/editor-common/media';
5
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
6
  import CommentIcon from '@atlaskit/icon/glyph/comment';
6
- export var commentButton = function commentButton(intl, state, api) {
7
+ export var commentButton = function commentButton(intl, _state, api) {
7
8
  var title = intl.formatMessage(messages.addCommentOnMedia);
8
9
  var onClickHandler = function onClickHandler(state, dispatch) {
9
- if (api && api.annotation) {
10
- api.annotation.actions.setInlineCommentDraftState(true,
10
+ if (api !== null && api !== void 0 && api.annotation && state.selection instanceof NodeSelection) {
11
+ var mediaNode = state.selection.node.firstChild;
12
+ var command = api.annotation.actions.showCommentForBlockNode(mediaNode) || api.annotation.actions.setInlineCommentDraftState(true,
11
13
  // TODO: might need to update to reflect it's from media floating toolbar
12
- INPUT_METHOD.FLOATING_TB, 'block', true)(state, dispatch);
14
+ INPUT_METHOD.FLOATING_TB, 'block', true);
15
+ command(state, dispatch);
13
16
  }
14
17
  return true;
15
18
  };
@@ -1,34 +1,13 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import React, { useState } from 'react';
3
- import ReactDOM from 'react-dom';
4
3
  import { FloatingToolbarButton as ToolbarButton } from '@atlaskit/editor-common/ui';
5
4
  import FilePreviewIcon from '@atlaskit/icon/glyph/editor/file-preview';
6
5
  import { messages } from '@atlaskit/media-ui';
7
- import { MediaViewer } from '@atlaskit/media-viewer';
6
+ import { RenderMediaViewer } from '../ui/MediaViewer/PortalWrapper';
8
7
  import { getSelectedNearestMediaContainerNodeAttrs } from './utils';
9
- var RenderMediaViewer = function RenderMediaViewer(_ref) {
10
- var mediaClientConfig = _ref.mediaClientConfig,
11
- onClose = _ref.onClose,
12
- selectedNodeAttrs = _ref.selectedNodeAttrs;
13
- var id = selectedNodeAttrs.id,
14
- _selectedNodeAttrs$co = selectedNodeAttrs.collection,
15
- collection = _selectedNodeAttrs$co === void 0 ? '' : _selectedNodeAttrs$co;
16
- var identifier = {
17
- id: id,
18
- mediaItemType: 'file',
19
- collectionName: collection
20
- };
21
- return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(MediaViewer, {
22
- collectionName: collection,
23
- items: [],
24
- mediaClientConfig: mediaClientConfig,
25
- selectedItem: identifier,
26
- onClose: onClose
27
- }), document.body);
28
- };
29
- export var FilePreviewItem = function FilePreviewItem(_ref2) {
30
- var mediaPluginState = _ref2.mediaPluginState,
31
- intl = _ref2.intl;
8
+ export var FilePreviewItem = function FilePreviewItem(_ref) {
9
+ var mediaPluginState = _ref.mediaPluginState,
10
+ intl = _ref.intl;
32
11
  var _useState = useState(false),
33
12
  _useState2 = _slicedToArray(_useState, 2),
34
13
  isMediaViewerVisible = _useState2[0],
@@ -8,14 +8,16 @@ import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
8
8
  import { getMediaClient } from '@atlaskit/media-client-react';
9
9
  import { isVideo } from '../utils/media-single';
10
10
  export var getSelectedMediaContainerNodeAttrs = function getSelectedMediaContainerNodeAttrs(mediaPluginState) {
11
- var selectedNode = mediaPluginState.selectedMediaContainerNode();
11
+ var _mediaPluginState$sel;
12
+ var selectedNode = (_mediaPluginState$sel = mediaPluginState.selectedMediaContainerNode) === null || _mediaPluginState$sel === void 0 ? void 0 : _mediaPluginState$sel.call(mediaPluginState);
12
13
  if (selectedNode && selectedNode.attrs) {
13
14
  return selectedNode.attrs;
14
15
  }
15
16
  return null;
16
17
  };
17
18
  export var getSelectedNearestMediaContainerNodeAttrs = function getSelectedNearestMediaContainerNodeAttrs(mediaPluginState) {
18
- var selectedNode = mediaPluginState.selectedMediaContainerNode();
19
+ var _mediaPluginState$sel2;
20
+ var selectedNode = (_mediaPluginState$sel2 = mediaPluginState.selectedMediaContainerNode) === null || _mediaPluginState$sel2 === void 0 ? void 0 : _mediaPluginState$sel2.call(mediaPluginState);
19
21
  if (selectedNode) {
20
22
  switch (selectedNode.type.name) {
21
23
  case 'mediaSingle':
@@ -0,0 +1,55 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /** @jsx jsx */
3
+ import React, { Fragment, useEffect, useState } from 'react';
4
+ import { css, jsx } from '@emotion/react';
5
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
+ import { getSelectedNearestMediaContainerNodeAttrs } from '../../toolbar/utils';
7
+ import { isVideo } from '../../utils/is-type';
8
+ import { RenderMediaViewer } from './PortalWrapper';
9
+ var interactiveStyles = css({
10
+ cursor: 'pointer'
11
+ });
12
+ export var mediaViewerContainerTestID = 'media-viewer-container-test';
13
+ export var MediaViewerContainer = function MediaViewerContainer(_ref) {
14
+ var _mediaNode$firstChild;
15
+ var mediaNode = _ref.mediaNode,
16
+ mediaPluginState = _ref.mediaPluginState,
17
+ _ref$isEditorViewMode = _ref.isEditorViewMode,
18
+ isEditorViewMode = _ref$isEditorViewMode === void 0 ? false : _ref$isEditorViewMode,
19
+ _ref$isSelected = _ref.isSelected,
20
+ isSelected = _ref$isSelected === void 0 ? true : _ref$isSelected,
21
+ _ref$isInline = _ref.isInline,
22
+ isInline = _ref$isInline === void 0 ? false : _ref$isInline,
23
+ children = _ref.children;
24
+ var _useState = useState(false),
25
+ _useState2 = _slicedToArray(_useState, 2),
26
+ showViewer = _useState2[0],
27
+ setShowMediaViewer = _useState2[1];
28
+ useEffect(function () {
29
+ setShowMediaViewer(isSelected);
30
+ }, [isSelected]);
31
+ var selectedNodeAttrs = getSelectedNearestMediaContainerNodeAttrs(mediaPluginState);
32
+ var mediaClientConfig = mediaPluginState.mediaClientConfig;
33
+ var showMediaViewer = function showMediaViewer() {
34
+ setShowMediaViewer(true);
35
+ };
36
+ var closeMediaViewer = function closeMediaViewer() {
37
+ setShowMediaViewer(false);
38
+ };
39
+ var isVideoMedia = isVideo((_mediaNode$firstChild = mediaNode.firstChild) === null || _mediaNode$firstChild === void 0 ? void 0 : _mediaNode$firstChild.attrs.__fileMimeType);
40
+ var enableMediaViewer = getBooleanFF('platform.editor.media.preview-in-full-page') && isEditorViewMode;
41
+ var shouldShowViewer = enableMediaViewer && showViewer && selectedNodeAttrs && mediaClientConfig && !isVideoMedia;
42
+ return jsx(Fragment, null, enableMediaViewer ? jsx(Fragment, null, isInline ? jsx("span", {
43
+ onClick: showMediaViewer,
44
+ css: interactiveStyles,
45
+ "data-testid": mediaViewerContainerTestID
46
+ }, children) : jsx("div", {
47
+ onClick: showMediaViewer,
48
+ css: interactiveStyles,
49
+ "data-testid": mediaViewerContainerTestID
50
+ }, children), shouldShowViewer && jsx(RenderMediaViewer, {
51
+ selectedNodeAttrs: selectedNodeAttrs,
52
+ mediaClientConfig: mediaClientConfig,
53
+ onClose: closeMediaViewer
54
+ })) : children);
55
+ };
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import { MediaViewer } from '@atlaskit/media-viewer';
4
+ export var RenderMediaViewer = function RenderMediaViewer(_ref) {
5
+ var mediaClientConfig = _ref.mediaClientConfig,
6
+ onClose = _ref.onClose,
7
+ selectedNodeAttrs = _ref.selectedNodeAttrs;
8
+ var id = selectedNodeAttrs.id,
9
+ _selectedNodeAttrs$co = selectedNodeAttrs.collection,
10
+ collection = _selectedNodeAttrs$co === void 0 ? '' : _selectedNodeAttrs$co;
11
+ var identifier = {
12
+ id: id,
13
+ mediaItemType: 'file',
14
+ collectionName: collection
15
+ };
16
+ return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(MediaViewer, {
17
+ collectionName: collection,
18
+ items: [],
19
+ mediaClientConfig: mediaClientConfig,
20
+ selectedItem: identifier,
21
+ onClose: onClose
22
+ }), document.body);
23
+ };
@@ -4,6 +4,7 @@ import type { AnnotationPlugin } from '@atlaskit/editor-plugin-annotation';
4
4
  import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
5
5
  import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
6
6
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
7
+ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
7
8
  import type { FloatingToolbarPlugin } from '@atlaskit/editor-plugin-floating-toolbar';
8
9
  import type { FocusPlugin } from '@atlaskit/editor-plugin-focus';
9
10
  import type { GridPlugin } from '@atlaskit/editor-plugin-grid';
@@ -18,6 +19,7 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
18
19
  dependencies: [
19
20
  OptionalPlugin<AnalyticsPlugin>,
20
21
  OptionalPlugin<ContextIdentifierPlugin>,
22
+ OptionalPlugin<EditorViewModePlugin>,
21
23
  GuidelinePlugin,
22
24
  GridPlugin,
23
25
  WidthPlugin,
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import { jsx } from '@emotion/react';
2
2
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
3
3
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
4
4
  import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
@@ -22,6 +22,7 @@ export interface MediaInlineProps {
22
22
  dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
23
23
  contextIdentifierProvider?: Promise<ContextIdentifierProvider>;
24
24
  mediaPluginState: MediaPluginState;
25
+ editorViewMode?: boolean;
25
26
  }
26
27
  export declare const createMediaNodeUpdater: (props: MediaInlineProps) => MediaNodeUpdater;
27
28
  /**
@@ -32,7 +33,7 @@ export declare const createMediaNodeUpdater: (props: MediaInlineProps) => MediaN
32
33
  */
33
34
  export declare const updateMediaNodeAttributes: (props: MediaInlineProps, mediaNodeUpdater: MediaNodeUpdater) => Promise<void>;
34
35
  export declare const handleNewNode: (props: MediaInlineProps) => void;
35
- export declare const MediaInline: (props: MediaInlineProps) => JSX.Element;
36
+ export declare const MediaInline: (props: MediaInlineProps) => jsx.JSX.Element;
36
37
  export interface MediaInlineNodeViewProps {
37
38
  providerFactory: ProviderFactory;
38
39
  api: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined;
@@ -45,6 +46,6 @@ export declare class MediaInlineNodeView extends SelectionBasedNodeView<MediaInl
45
46
  };
46
47
  ignoreMutation(): boolean;
47
48
  viewShouldUpdate(nextNode: PMNode): boolean;
48
- render(props: MediaInlineNodeViewProps): JSX.Element;
49
+ render(props: MediaInlineNodeViewProps): jsx.JSX.Element;
49
50
  }
50
51
  export declare const ReactMediaInlineNode: (portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, providerFactory: ProviderFactory, api: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined, dispatchAnalyticsEvent?: DispatchAnalyticsEvent) => (node: PMNode, view: EditorView, getPos: getPosHandler) => NodeView;
@@ -14,8 +14,7 @@ import type { Decoration, DecorationSource, EditorView } from '@atlaskit/editor-
14
14
  import type { CardEvent } from '@atlaskit/media-card';
15
15
  import type { MediaClientConfig } from '@atlaskit/media-core';
16
16
  import type { MediaNextEditorPluginType } from '../next-plugin-type';
17
- import type { ForwardRef, getPosHandler } from '../types';
18
- import type { MediaOptions } from '../types';
17
+ import type { ForwardRef, getPosHandler, MediaOptions } from '../types';
19
18
  import { MediaNodeUpdater } from './mediaNodeUpdater';
20
19
  import type { MediaSingleNodeProps, MediaSingleNodeViewProps } from './types';
21
20
  export interface MediaSingleNodeState {
@@ -26,6 +26,8 @@ export interface MediaSingleNodeProps {
26
26
  isCopyPasteEnabled?: boolean;
27
27
  forwardRef: ForwardRef;
28
28
  pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined;
29
+ editorViewMode?: boolean;
30
+ editorDisabled?: boolean;
29
31
  }
30
32
  export interface MediaSingleNodeViewProps {
31
33
  eventDispatcher: EventDispatcher;
@@ -2,4 +2,4 @@ import type { IntlShape } from 'react-intl-next';
2
2
  import type { Command, ExtractInjectionAPI, FloatingToolbarButton } from '@atlaskit/editor-common/types';
3
3
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { MediaNextEditorPluginType } from '../next-plugin-type';
5
- export declare const commentButton: (intl: IntlShape, state: EditorState, api: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined) => FloatingToolbarButton<Command>;
5
+ export declare const commentButton: (intl: IntlShape, _state: EditorState, api: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined) => FloatingToolbarButton<Command>;
@@ -0,0 +1,16 @@
1
+ /** @jsx jsx */
2
+ import React from 'react';
3
+ import { jsx } from '@emotion/react';
4
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
+ import { type MediaPluginState } from '../../types';
6
+ type MediaViewerContainerProps = {
7
+ mediaNode: PMNode;
8
+ mediaPluginState: MediaPluginState;
9
+ isEditorViewMode?: boolean;
10
+ isSelected?: boolean;
11
+ isInline?: boolean;
12
+ children?: React.ReactNode;
13
+ };
14
+ export declare const mediaViewerContainerTestID = "media-viewer-container-test";
15
+ export declare const MediaViewerContainer: ({ mediaNode, mediaPluginState, isEditorViewMode, isSelected, isInline, children, }: MediaViewerContainerProps) => jsx.JSX.Element;
16
+ export {};
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { type MediaBaseAttributes } from '@atlaskit/adf-schema';
3
+ import type { MediaClientConfig } from '@atlaskit/media-client';
4
+ interface RenderMediaViewerProps {
5
+ mediaClientConfig: MediaClientConfig;
6
+ onClose: () => void;
7
+ selectedNodeAttrs: MediaBaseAttributes;
8
+ }
9
+ export declare const RenderMediaViewer: ({ mediaClientConfig, onClose, selectedNodeAttrs, }: RenderMediaViewerProps) => React.ReactPortal;
10
+ export {};
@@ -24,4 +24,5 @@ export type Props = MediaSingleProps & {
24
24
  dispatchAnalyticsEvent: DispatchAnalyticsEvent;
25
25
  mediaSingleWidth?: number;
26
26
  pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined;
27
+ disableHandles?: boolean;
27
28
  };
@@ -4,6 +4,7 @@ import type { AnnotationPlugin } from '@atlaskit/editor-plugin-annotation';
4
4
  import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
5
5
  import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
6
6
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
7
+ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
7
8
  import type { FloatingToolbarPlugin } from '@atlaskit/editor-plugin-floating-toolbar';
8
9
  import type { FocusPlugin } from '@atlaskit/editor-plugin-focus';
9
10
  import type { GridPlugin } from '@atlaskit/editor-plugin-grid';
@@ -18,6 +19,7 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
18
19
  dependencies: [
19
20
  OptionalPlugin<AnalyticsPlugin>,
20
21
  OptionalPlugin<ContextIdentifierPlugin>,
22
+ OptionalPlugin<EditorViewModePlugin>,
21
23
  GuidelinePlugin,
22
24
  GridPlugin,
23
25
  WidthPlugin,
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import { jsx } from '@emotion/react';
2
2
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
3
3
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
4
4
  import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
@@ -22,6 +22,7 @@ export interface MediaInlineProps {
22
22
  dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
23
23
  contextIdentifierProvider?: Promise<ContextIdentifierProvider>;
24
24
  mediaPluginState: MediaPluginState;
25
+ editorViewMode?: boolean;
25
26
  }
26
27
  export declare const createMediaNodeUpdater: (props: MediaInlineProps) => MediaNodeUpdater;
27
28
  /**
@@ -32,7 +33,7 @@ export declare const createMediaNodeUpdater: (props: MediaInlineProps) => MediaN
32
33
  */
33
34
  export declare const updateMediaNodeAttributes: (props: MediaInlineProps, mediaNodeUpdater: MediaNodeUpdater) => Promise<void>;
34
35
  export declare const handleNewNode: (props: MediaInlineProps) => void;
35
- export declare const MediaInline: (props: MediaInlineProps) => JSX.Element;
36
+ export declare const MediaInline: (props: MediaInlineProps) => jsx.JSX.Element;
36
37
  export interface MediaInlineNodeViewProps {
37
38
  providerFactory: ProviderFactory;
38
39
  api: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined;
@@ -45,6 +46,6 @@ export declare class MediaInlineNodeView extends SelectionBasedNodeView<MediaInl
45
46
  };
46
47
  ignoreMutation(): boolean;
47
48
  viewShouldUpdate(nextNode: PMNode): boolean;
48
- render(props: MediaInlineNodeViewProps): JSX.Element;
49
+ render(props: MediaInlineNodeViewProps): jsx.JSX.Element;
49
50
  }
50
51
  export declare const ReactMediaInlineNode: (portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, providerFactory: ProviderFactory, api: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined, dispatchAnalyticsEvent?: DispatchAnalyticsEvent) => (node: PMNode, view: EditorView, getPos: getPosHandler) => NodeView;