@atlaskit/editor-plugin-media 1.32.2 → 1.33.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-media
2
2
 
3
+ ## 1.33.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#145463](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/145463)
8
+ [`d63935e60e04b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d63935e60e04b) -
9
+ [ux] ED-24924 Fix media preview broken for external images
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 1.32.2
4
16
 
5
17
  ### Patch Changes
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.removeMediaGroupNode = exports.getSelectedNearestMediaContainerNodeAttrs = exports.getSelectedMediaSingle = exports.getSelectedLayoutIcon = exports.getPixelWidthOfElement = exports.getMaxToolbarWidth = exports.downloadMedia = exports.canShowSwitchButtons = exports.calcNewLayout = void 0;
7
+ exports.removeMediaGroupNode = exports.isExternalMedia = exports.getSelectedNearestMediaContainerNodeAttrs = exports.getSelectedMediaSingle = exports.getSelectedLayoutIcon = exports.getPixelWidthOfElement = exports.getMaxToolbarWidth = exports.downloadMedia = exports.canShowSwitchButtons = exports.calcNewLayout = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
@@ -14,6 +14,9 @@ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
14
14
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
15
15
  var _mediaClientReact = require("@atlaskit/media-client-react");
16
16
  var _mediaSingle2 = require("../utils/media-single");
17
+ var isExternalMedia = exports.isExternalMedia = function isExternalMedia(attrs) {
18
+ return attrs.type === 'external';
19
+ };
17
20
  var getSelectedMediaContainerNodeAttrs = function getSelectedMediaContainerNodeAttrs(mediaPluginState) {
18
21
  var _mediaPluginState$sel;
19
22
  var selectedNode = (_mediaPluginState$sel = mediaPluginState.selectedMediaContainerNode) === null || _mediaPluginState$sel === void 0 ? void 0 : _mediaPluginState$sel.call(mediaPluginState);
@@ -46,7 +49,7 @@ var downloadMedia = exports.downloadMedia = /*#__PURE__*/function () {
46
49
  case 0:
47
50
  _context.prev = 0;
48
51
  selectedNodeAttrs = isViewMode ? getSelectedNearestMediaContainerNodeAttrs(mediaPluginState) : getSelectedMediaContainerNodeAttrs(mediaPluginState);
49
- if (!(selectedNodeAttrs && mediaPluginState.mediaClientConfig)) {
52
+ if (!(selectedNodeAttrs && mediaPluginState.mediaClientConfig && !isExternalMedia(selectedNodeAttrs))) {
50
53
  _context.next = 10;
51
54
  break;
52
55
  }
@@ -8,13 +8,44 @@ exports.RenderMediaViewer = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _reactDom = _interopRequireDefault(require("react-dom"));
10
10
  var _mediaViewer = require("@atlaskit/media-viewer");
11
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
+ var _utils = require("../../toolbar/utils");
13
+ var getIdentifier = function getIdentifier(attrs) {
14
+ if ((0, _utils.isExternalMedia)(attrs)) {
15
+ return {
16
+ mediaItemType: 'external-image',
17
+ dataURI: attrs.url
18
+ };
19
+ } else {
20
+ var id = attrs.id,
21
+ _attrs$collection = attrs.collection,
22
+ collection = _attrs$collection === void 0 ? '' : _attrs$collection;
23
+ return {
24
+ id: id,
25
+ mediaItemType: 'file',
26
+ collectionName: collection
27
+ };
28
+ }
29
+ };
11
30
  var RenderMediaViewer = exports.RenderMediaViewer = function RenderMediaViewer(_ref) {
12
31
  var mediaClientConfig = _ref.mediaClientConfig,
13
32
  onClose = _ref.onClose,
14
33
  selectedNodeAttrs = _ref.selectedNodeAttrs;
15
- var id = selectedNodeAttrs.id,
16
- _selectedNodeAttrs$co = selectedNodeAttrs.collection,
17
- collection = _selectedNodeAttrs$co === void 0 ? '' : _selectedNodeAttrs$co;
34
+ if ((0, _experiments.editorExperiment)('add-media-from-url', true)) {
35
+ var _identifier = getIdentifier(selectedNodeAttrs);
36
+ var collectionName = (0, _utils.isExternalMedia)(selectedNodeAttrs) ? '' : selectedNodeAttrs.collection;
37
+ return /*#__PURE__*/_reactDom.default.createPortal( /*#__PURE__*/_react.default.createElement(_mediaViewer.MediaViewer, {
38
+ collectionName: collectionName,
39
+ items: [],
40
+ mediaClientConfig: mediaClientConfig,
41
+ selectedItem: _identifier,
42
+ onClose: onClose
43
+ }), document.body);
44
+ }
45
+ var _ref2 = selectedNodeAttrs,
46
+ id = _ref2.id,
47
+ _ref2$collection = _ref2.collection,
48
+ collection = _ref2$collection === void 0 ? '' : _ref2$collection;
18
49
  var identifier = {
19
50
  id: id,
20
51
  mediaItemType: 'file',
@@ -5,6 +5,9 @@ import { findParentNodeOfType, findSelectedNodeOfType, removeParentNodeOfType, r
5
5
  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
+ export const isExternalMedia = attrs => {
9
+ return attrs.type === 'external';
10
+ };
8
11
  const getSelectedMediaContainerNodeAttrs = mediaPluginState => {
9
12
  var _mediaPluginState$sel;
10
13
  const selectedNode = (_mediaPluginState$sel = mediaPluginState.selectedMediaContainerNode) === null || _mediaPluginState$sel === void 0 ? void 0 : _mediaPluginState$sel.call(mediaPluginState);
@@ -32,7 +35,7 @@ export const getSelectedNearestMediaContainerNodeAttrs = mediaPluginState => {
32
35
  export const downloadMedia = async (mediaPluginState, isViewMode) => {
33
36
  try {
34
37
  const selectedNodeAttrs = isViewMode ? getSelectedNearestMediaContainerNodeAttrs(mediaPluginState) : getSelectedMediaContainerNodeAttrs(mediaPluginState);
35
- if (selectedNodeAttrs && mediaPluginState.mediaClientConfig) {
38
+ if (selectedNodeAttrs && mediaPluginState.mediaClientConfig && !isExternalMedia(selectedNodeAttrs)) {
36
39
  const {
37
40
  id,
38
41
  collection = ''
@@ -1,11 +1,42 @@
1
1
  import React from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import { MediaViewer } from '@atlaskit/media-viewer';
4
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
+ import { isExternalMedia } from '../../toolbar/utils';
6
+ const getIdentifier = attrs => {
7
+ if (isExternalMedia(attrs)) {
8
+ return {
9
+ mediaItemType: 'external-image',
10
+ dataURI: attrs.url
11
+ };
12
+ } else {
13
+ const {
14
+ id,
15
+ collection = ''
16
+ } = attrs;
17
+ return {
18
+ id,
19
+ mediaItemType: 'file',
20
+ collectionName: collection
21
+ };
22
+ }
23
+ };
4
24
  export const RenderMediaViewer = ({
5
25
  mediaClientConfig,
6
26
  onClose,
7
27
  selectedNodeAttrs
8
28
  }) => {
29
+ if (editorExperiment('add-media-from-url', true)) {
30
+ const identifier = getIdentifier(selectedNodeAttrs);
31
+ const collectionName = isExternalMedia(selectedNodeAttrs) ? '' : selectedNodeAttrs.collection;
32
+ return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(MediaViewer, {
33
+ collectionName: collectionName,
34
+ items: [],
35
+ mediaClientConfig: mediaClientConfig,
36
+ selectedItem: identifier,
37
+ onClose: onClose
38
+ }), document.body);
39
+ }
9
40
  const {
10
41
  id,
11
42
  collection = ''
@@ -7,6 +7,9 @@ import { findParentNodeOfType, findSelectedNodeOfType, removeParentNodeOfType, r
7
7
  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
+ export var isExternalMedia = function isExternalMedia(attrs) {
11
+ return attrs.type === 'external';
12
+ };
10
13
  var getSelectedMediaContainerNodeAttrs = function getSelectedMediaContainerNodeAttrs(mediaPluginState) {
11
14
  var _mediaPluginState$sel;
12
15
  var selectedNode = (_mediaPluginState$sel = mediaPluginState.selectedMediaContainerNode) === null || _mediaPluginState$sel === void 0 ? void 0 : _mediaPluginState$sel.call(mediaPluginState);
@@ -39,7 +42,7 @@ export var downloadMedia = /*#__PURE__*/function () {
39
42
  case 0:
40
43
  _context.prev = 0;
41
44
  selectedNodeAttrs = isViewMode ? getSelectedNearestMediaContainerNodeAttrs(mediaPluginState) : getSelectedMediaContainerNodeAttrs(mediaPluginState);
42
- if (!(selectedNodeAttrs && mediaPluginState.mediaClientConfig)) {
45
+ if (!(selectedNodeAttrs && mediaPluginState.mediaClientConfig && !isExternalMedia(selectedNodeAttrs))) {
43
46
  _context.next = 10;
44
47
  break;
45
48
  }
@@ -1,13 +1,44 @@
1
1
  import React from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import { MediaViewer } from '@atlaskit/media-viewer';
4
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
+ import { isExternalMedia } from '../../toolbar/utils';
6
+ var getIdentifier = function getIdentifier(attrs) {
7
+ if (isExternalMedia(attrs)) {
8
+ return {
9
+ mediaItemType: 'external-image',
10
+ dataURI: attrs.url
11
+ };
12
+ } else {
13
+ var id = attrs.id,
14
+ _attrs$collection = attrs.collection,
15
+ collection = _attrs$collection === void 0 ? '' : _attrs$collection;
16
+ return {
17
+ id: id,
18
+ mediaItemType: 'file',
19
+ collectionName: collection
20
+ };
21
+ }
22
+ };
4
23
  export var RenderMediaViewer = function RenderMediaViewer(_ref) {
5
24
  var mediaClientConfig = _ref.mediaClientConfig,
6
25
  onClose = _ref.onClose,
7
26
  selectedNodeAttrs = _ref.selectedNodeAttrs;
8
- var id = selectedNodeAttrs.id,
9
- _selectedNodeAttrs$co = selectedNodeAttrs.collection,
10
- collection = _selectedNodeAttrs$co === void 0 ? '' : _selectedNodeAttrs$co;
27
+ if (editorExperiment('add-media-from-url', true)) {
28
+ var _identifier = getIdentifier(selectedNodeAttrs);
29
+ var collectionName = isExternalMedia(selectedNodeAttrs) ? '' : selectedNodeAttrs.collection;
30
+ return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(MediaViewer, {
31
+ collectionName: collectionName,
32
+ items: [],
33
+ mediaClientConfig: mediaClientConfig,
34
+ selectedItem: _identifier,
35
+ onClose: onClose
36
+ }), document.body);
37
+ }
38
+ var _ref2 = selectedNodeAttrs,
39
+ id = _ref2.id,
40
+ _ref2$collection = _ref2.collection,
41
+ collection = _ref2$collection === void 0 ? '' : _ref2$collection;
11
42
  var identifier = {
12
43
  id: id,
13
44
  mediaItemType: 'file',
@@ -1,11 +1,12 @@
1
- import type { MediaBaseAttributes, RichMediaLayout } from '@atlaskit/adf-schema';
1
+ import type { ExternalMediaAttributes, MediaADFAttrs, RichMediaLayout } from '@atlaskit/adf-schema';
2
2
  import type { LayoutIcon } from '@atlaskit/editor-common/card';
3
3
  import type { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
5
  import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import type { MediaPluginState } from '../pm-plugins/types';
8
- export declare const getSelectedNearestMediaContainerNodeAttrs: (mediaPluginState: MediaPluginState) => MediaBaseAttributes | null;
8
+ export declare const isExternalMedia: (attrs: MediaADFAttrs) => attrs is ExternalMediaAttributes;
9
+ export declare const getSelectedNearestMediaContainerNodeAttrs: (mediaPluginState: MediaPluginState) => MediaADFAttrs | null;
9
10
  export declare const downloadMedia: (mediaPluginState: MediaPluginState, isViewMode?: boolean) => Promise<boolean>;
10
11
  export declare const removeMediaGroupNode: (state: EditorState) => import("prosemirror-state").Transaction;
11
12
  export declare const getSelectedMediaSingle: (state: EditorState) => ReturnType<ReturnType<typeof findSelectedNodeOfType>> | ReturnType<ReturnType<typeof findParentNodeOfType>>;
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
- import { type MediaBaseAttributes } from '@atlaskit/adf-schema';
2
+ import type { MediaADFAttrs } from '@atlaskit/adf-schema';
3
3
  import type { MediaClientConfig } from '@atlaskit/media-client';
4
4
  interface RenderMediaViewerProps {
5
5
  mediaClientConfig: MediaClientConfig;
6
6
  onClose: () => void;
7
- selectedNodeAttrs: MediaBaseAttributes;
7
+ selectedNodeAttrs: MediaADFAttrs;
8
8
  }
9
9
  export declare const RenderMediaViewer: ({ mediaClientConfig, onClose, selectedNodeAttrs, }: RenderMediaViewerProps) => React.ReactPortal;
10
10
  export {};
@@ -1,11 +1,12 @@
1
- import type { MediaBaseAttributes, RichMediaLayout } from '@atlaskit/adf-schema';
1
+ import type { ExternalMediaAttributes, MediaADFAttrs, RichMediaLayout } from '@atlaskit/adf-schema';
2
2
  import type { LayoutIcon } from '@atlaskit/editor-common/card';
3
3
  import type { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
5
  import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
7
  import type { MediaPluginState } from '../pm-plugins/types';
8
- export declare const getSelectedNearestMediaContainerNodeAttrs: (mediaPluginState: MediaPluginState) => MediaBaseAttributes | null;
8
+ export declare const isExternalMedia: (attrs: MediaADFAttrs) => attrs is ExternalMediaAttributes;
9
+ export declare const getSelectedNearestMediaContainerNodeAttrs: (mediaPluginState: MediaPluginState) => MediaADFAttrs | null;
9
10
  export declare const downloadMedia: (mediaPluginState: MediaPluginState, isViewMode?: boolean) => Promise<boolean>;
10
11
  export declare const removeMediaGroupNode: (state: EditorState) => import("prosemirror-state").Transaction;
11
12
  export declare const getSelectedMediaSingle: (state: EditorState) => ReturnType<ReturnType<typeof findSelectedNodeOfType>> | ReturnType<ReturnType<typeof findParentNodeOfType>>;
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
- import { type MediaBaseAttributes } from '@atlaskit/adf-schema';
2
+ import type { MediaADFAttrs } from '@atlaskit/adf-schema';
3
3
  import type { MediaClientConfig } from '@atlaskit/media-client';
4
4
  interface RenderMediaViewerProps {
5
5
  mediaClientConfig: MediaClientConfig;
6
6
  onClose: () => void;
7
- selectedNodeAttrs: MediaBaseAttributes;
7
+ selectedNodeAttrs: MediaADFAttrs;
8
8
  }
9
9
  export declare const RenderMediaViewer: ({ mediaClientConfig, onClose, selectedNodeAttrs, }: RenderMediaViewerProps) => React.ReactPortal;
10
10
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-media",
3
- "version": "1.32.2",
3
+ "version": "1.33.0",
4
4
  "description": "Media plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,8 +35,8 @@
35
35
  "@atlaskit/adf-schema": "^40.9.0",
36
36
  "@atlaskit/analytics-namespaced-context": "^6.12.0",
37
37
  "@atlaskit/analytics-next": "^10.1.0",
38
- "@atlaskit/button": "^20.1.0",
39
- "@atlaskit/editor-common": "^91.0.0",
38
+ "@atlaskit/button": "^20.2.0",
39
+ "@atlaskit/editor-common": "^91.1.0",
40
40
  "@atlaskit/editor-palette": "1.6.0",
41
41
  "@atlaskit/editor-plugin-analytics": "^1.8.0",
42
42
  "@atlaskit/editor-plugin-annotation": "1.19.8",
@@ -50,15 +50,15 @@
50
50
  "@atlaskit/editor-plugin-selection": "^1.4.0",
51
51
  "@atlaskit/editor-plugin-width": "^1.3.0",
52
52
  "@atlaskit/editor-prosemirror": "6.0.0",
53
- "@atlaskit/editor-shared-styles": "^2.13.0",
53
+ "@atlaskit/editor-shared-styles": "^3.0.0",
54
54
  "@atlaskit/editor-tables": "^2.8.0",
55
55
  "@atlaskit/form": "^10.5.0",
56
56
  "@atlaskit/icon": "^22.18.0",
57
57
  "@atlaskit/media-card": "^78.5.0",
58
58
  "@atlaskit/media-client": "^28.0.0",
59
59
  "@atlaskit/media-client-react": "^2.2.0",
60
- "@atlaskit/media-common": "^11.4.0",
61
- "@atlaskit/media-filmstrip": "^47.3.0",
60
+ "@atlaskit/media-common": "^11.5.0",
61
+ "@atlaskit/media-filmstrip": "^47.4.0",
62
62
  "@atlaskit/media-picker": "^66.7.0",
63
63
  "@atlaskit/media-ui": "^25.15.0",
64
64
  "@atlaskit/media-viewer": "^48.10.0",