@atlaskit/editor-plugin-media 1.44.2 → 1.44.3

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,18 @@
1
1
  # @atlaskit/editor-plugin-media
2
2
 
3
+ ## 1.44.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#102478](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102478)
8
+ [`da114a3262eae`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/da114a3262eae) -
9
+ Fixed deep copying of media single and group when provided with "editor" in copy scope
10
+ - [#102671](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102671)
11
+ [`6bad93b42f720`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6bad93b42f720) -
12
+ File copy v2 endpoint will only be used when copyWithToken fails as the intents are not registered
13
+ using copy button
14
+ - Updated dependencies
15
+
3
16
  ## 1.44.2
4
17
 
5
18
  ### Patch Changes
@@ -126,7 +126,8 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref3) {
126
126
  },
127
127
  commands: {
128
128
  showMediaViewer: _commands.showMediaViewer,
129
- hideMediaViewer: _commands.hideMediaViewer
129
+ hideMediaViewer: _commands.hideMediaViewer,
130
+ trackMediaPaste: _commands.trackMediaPaste
130
131
  },
131
132
  nodes: function nodes() {
132
133
  var _ref5 = options || {},
@@ -366,12 +366,9 @@ var MediaNodeUpdater = exports.MediaNodeUpdater = /*#__PURE__*/function () {
366
366
  return _context8.abrupt("return", false);
367
367
  case 10:
368
368
  id = (0, _mediaCommon.getIdentifier)(attrs);
369
- _context8.next = 13;
370
- return _this.mediaPluginState.isIdentifierInEditorScope(id);
371
- case 13:
372
- isIdentifierOutsideEditorScope = !_context8.sent;
369
+ isIdentifierOutsideEditorScope = !_this.mediaPluginState.isIdentifierInEditorScope(id);
373
370
  return _context8.abrupt("return", isIdentifierOutsideEditorScope);
374
- case 15:
371
+ case 13:
375
372
  case "end":
376
373
  return _context8.stop();
377
374
  }
@@ -450,36 +447,41 @@ var MediaNodeUpdater = exports.MediaNodeUpdater = /*#__PURE__*/function () {
450
447
  })));
451
448
  (0, _defineProperty2.default)(this, "handleCopyFileSwitcher", /*#__PURE__*/function () {
452
449
  var _ref13 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(attrs) {
453
- var mediaClient, source, destination, traceContext, _sourceAP, copyV2Source, _destAP, copyV2Destination, _yield$mediaClient$fi, id, _yield$mediaClient$fi2, _id;
450
+ var mediaClient, source, destination, traceContext, _yield$mediaClient$fi, id, _sourceAP, copyV2Source, _destAP, copyV2Destination, _yield$mediaClient$fi2, _id;
454
451
  return _regenerator.default.wrap(function _callee11$(_context11) {
455
452
  while (1) switch (_context11.prev = _context11.next) {
456
453
  case 0:
457
454
  mediaClient = attrs.mediaClient, source = attrs.source, destination = attrs.destination, traceContext = attrs.traceContext;
455
+ _context11.prev = 1;
456
+ _context11.next = 4;
457
+ return mediaClient.file.copyFile(source, destination, undefined, traceContext);
458
+ case 4:
459
+ _yield$mediaClient$fi = _context11.sent;
460
+ id = _yield$mediaClient$fi.id;
461
+ return _context11.abrupt("return", id);
462
+ case 9:
463
+ _context11.prev = 9;
464
+ _context11.t0 = _context11["catch"](1);
458
465
  if (!(0, _platformFeatureFlags.fg)('platform_media_copy_and_paste_v2')) {
459
- _context11.next = 11;
466
+ _context11.next = 21;
460
467
  break;
461
468
  }
462
- // don't need authProviders for v2 copy
469
+ // calling /v2/file/copy by removing the auth tokens to make cross product copy and pastes
463
470
  _sourceAP = source.authProvider, copyV2Source = (0, _objectWithoutProperties2.default)(source, _excluded);
464
471
  _destAP = destination.authProvider, copyV2Destination = (0, _objectWithoutProperties2.default)(destination, _excluded2);
465
- _context11.next = 6;
472
+ _context11.next = 16;
466
473
  return mediaClient.file.copyFile(copyV2Source, copyV2Destination, undefined, traceContext);
467
- case 6:
468
- _yield$mediaClient$fi = _context11.sent;
469
- id = _yield$mediaClient$fi.id;
470
- return _context11.abrupt("return", id);
471
- case 11:
472
- _context11.next = 13;
473
- return mediaClient.file.copyFile(source, destination, undefined, traceContext);
474
- case 13:
474
+ case 16:
475
475
  _yield$mediaClient$fi2 = _context11.sent;
476
476
  _id = _yield$mediaClient$fi2.id;
477
477
  return _context11.abrupt("return", _id);
478
- case 16:
478
+ case 21:
479
+ throw _context11.t0;
480
+ case 22:
479
481
  case "end":
480
482
  return _context11.stop();
481
483
  }
482
- }, _callee11);
484
+ }, _callee11, null, [[1, 9]]);
483
485
  }));
484
486
  return function (_x4) {
485
487
  return _ref13.apply(this, arguments);
@@ -6,5 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.ACTIONS = void 0;
7
7
  var ACTIONS = exports.ACTIONS = {
8
8
  SHOW_MEDIA_VIEWER: 'SHOW_MEDIA_VIEWER',
9
- HIDE_MEDIA_VIEWER: 'HIDE_MEDIA_VIEWER'
9
+ HIDE_MEDIA_VIEWER: 'HIDE_MEDIA_VIEWER',
10
+ TRACK_MEDIA_PASTE: 'TRACK_MEDIA_PASTE'
10
11
  };
@@ -3,9 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.showMediaViewer = exports.hideMediaViewer = void 0;
6
+ exports.trackMediaPaste = exports.showMediaViewer = exports.hideMediaViewer = void 0;
7
7
  var _actions = require("../pm-plugins/actions");
8
8
  var _pluginKey = require("../pm-plugins/plugin-key");
9
+ var _mediaCommon = require("../pm-plugins/utils/media-common");
9
10
  var showMediaViewer = exports.showMediaViewer = function showMediaViewer(media) {
10
11
  return function (_ref) {
11
12
  var tr = _ref.tr;
@@ -25,4 +26,15 @@ var hideMediaViewer = exports.hideMediaViewer = function hideMediaViewer(_ref2)
25
26
  isMediaViewerVisible: false
26
27
  });
27
28
  return tr;
29
+ };
30
+ var trackMediaPaste = exports.trackMediaPaste = function trackMediaPaste(attrs) {
31
+ return function (_ref3) {
32
+ var tr = _ref3.tr;
33
+ var identifier = (0, _mediaCommon.getIdentifier)(attrs);
34
+ tr.setMeta(_pluginKey.stateKey, {
35
+ type: _actions.ACTIONS.TRACK_MEDIA_PASTE,
36
+ identifier: identifier
37
+ });
38
+ return tr;
39
+ };
28
40
  };
@@ -26,6 +26,7 @@ var _transform = require("@atlaskit/editor-prosemirror/transform");
26
26
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
27
27
  var _view2 = require("@atlaskit/editor-prosemirror/view");
28
28
  var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
29
+ var _mediaClient = require("@atlaskit/media-client");
29
30
  var _mediaCommon = require("@atlaskit/media-common");
30
31
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
31
32
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
@@ -118,6 +119,9 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
118
119
  (0, _defineProperty2.default)(this, "removeOnCloseListener", function () {});
119
120
  (0, _defineProperty2.default)(this, "onPopupToggleCallback", function () {});
120
121
  (0, _defineProperty2.default)(this, "identifierCount", new Map());
122
+ // This is to enable mediaShallowCopySope to enable only shallow copying media referenced within the edtior
123
+ // see: trackOutOfScopeIdentifier
124
+ (0, _defineProperty2.default)(this, "outOfEditorScopeIdentifierMap", new Map());
121
125
  (0, _defineProperty2.default)(this, "taskManager", new _mediaTaskManager.MediaTaskManager());
122
126
  (0, _defineProperty2.default)(this, "pickers", []);
123
127
  (0, _defineProperty2.default)(this, "pickerPromises", []);
@@ -319,7 +323,18 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
319
323
 
320
324
  // rely on has instead of count > 0 because if the user cuts and pastes the same media
321
325
  // the count will temporarily be 0 but the media is still in the scope of editor.
322
- return _this.identifierCount.has(key);
326
+ return !_this.outOfEditorScopeIdentifierMap.has(key) && _this.identifierCount.has(key);
327
+ });
328
+ /**
329
+ * This is used in on Paste of media, this tracks which if the pasted media originated from a outside the editor
330
+ * i.e. the pasted media was not uplaoded to the current editor.
331
+ * This is to enable mediaShallowCopySope to enable only shallow copying media referenced within the edtior
332
+ */
333
+ (0, _defineProperty2.default)(this, "trackOutOfScopeIdentifier", function (identifier) {
334
+ var key = _this.getIdentifierKey(identifier);
335
+ _this.outOfEditorScopeIdentifierMap.set(key, {
336
+ identifier: identifier
337
+ });
323
338
  });
324
339
  /**
325
340
  * Called from React UI Component on componentDidMount
@@ -850,6 +865,14 @@ var createPlugin = exports.createPlugin = function createPlugin(_schema, options
850
865
  pluginState.isMediaViewerVisible = meta.isMediaViewerVisible;
851
866
  nextPluginState = nextPluginState.clone();
852
867
  break;
868
+ case _actions.ACTIONS.TRACK_MEDIA_PASTE:
869
+ var identifier = meta.identifier;
870
+ var isIdentifierInEditorScope = pluginState.isIdentifierInEditorScope(identifier);
871
+ if (!isIdentifierInEditorScope && (0, _mediaClient.isFileIdentifier)(identifier)) {
872
+ pluginState.trackOutOfScopeIdentifier(identifier);
873
+ nextPluginState = pluginState.clone();
874
+ }
875
+ break;
853
876
  }
854
877
 
855
878
  // NOTE: We're not calling passing new state to the Editor, because we depend on the view.state reference
@@ -18,7 +18,7 @@ import { mediaInlineSpecWithFixedToDOM } from './nodeviews/toDOM-fixes/mediaInli
18
18
  import { mediaSingleSpecWithFixedToDOM } from './nodeviews/toDOM-fixes/mediaSingle';
19
19
  import { createPlugin as createMediaAltTextPlugin } from './pm-plugins/alt-text';
20
20
  import keymapMediaAltTextPlugin from './pm-plugins/alt-text/keymap';
21
- import { hideMediaViewer, showMediaViewer } from './pm-plugins/commands';
21
+ import { hideMediaViewer, showMediaViewer, trackMediaPaste } from './pm-plugins/commands';
22
22
  import keymapPlugin from './pm-plugins/keymap';
23
23
  import keymapMediaSinglePlugin from './pm-plugins/keymap-media';
24
24
  import linkingPlugin from './pm-plugins/linking';
@@ -119,7 +119,8 @@ export const mediaPlugin = ({
119
119
  },
120
120
  commands: {
121
121
  showMediaViewer,
122
- hideMediaViewer
122
+ hideMediaViewer,
123
+ trackMediaPaste
123
124
  },
124
125
  nodes() {
125
126
  const {
@@ -209,7 +209,7 @@ export class MediaNodeUpdater {
209
209
  return false;
210
210
  }
211
211
  const id = getIdentifier(attrs);
212
- const isIdentifierOutsideEditorScope = !(await this.mediaPluginState.isIdentifierInEditorScope(id));
212
+ const isIdentifierOutsideEditorScope = !this.mediaPluginState.isIdentifierInEditorScope(id);
213
213
  return isIdentifierOutsideEditorScope;
214
214
  }
215
215
  });
@@ -248,25 +248,30 @@ export class MediaNodeUpdater {
248
248
  destination,
249
249
  traceContext
250
250
  } = attrs;
251
- if (fg('platform_media_copy_and_paste_v2')) {
252
- // don't need authProviders for v2 copy
253
- const {
254
- authProvider: _sourceAP,
255
- ...copyV2Source
256
- } = source;
257
- const {
258
- authProvider: _destAP,
259
- ...copyV2Destination
260
- } = destination;
261
- const {
262
- id
263
- } = await mediaClient.file.copyFile(copyV2Source, copyV2Destination, undefined, traceContext);
264
- return id;
265
- } else {
251
+ try {
252
+ // calling copyWithToken by passing the auth providers
266
253
  const {
267
254
  id
268
255
  } = await mediaClient.file.copyFile(source, destination, undefined, traceContext);
269
256
  return id;
257
+ } catch (err) {
258
+ if (fg('platform_media_copy_and_paste_v2')) {
259
+ // calling /v2/file/copy by removing the auth tokens to make cross product copy and pastes
260
+ const {
261
+ authProvider: _sourceAP,
262
+ ...copyV2Source
263
+ } = source;
264
+ const {
265
+ authProvider: _destAP,
266
+ ...copyV2Destination
267
+ } = destination;
268
+ const {
269
+ id
270
+ } = await mediaClient.file.copyFile(copyV2Source, copyV2Destination, undefined, traceContext);
271
+ return id;
272
+ } else {
273
+ throw err;
274
+ }
270
275
  }
271
276
  });
272
277
  _defineProperty(this, "copyNodeFromBlobUrl", async getPos => {
@@ -1,4 +1,5 @@
1
1
  export const ACTIONS = {
2
2
  SHOW_MEDIA_VIEWER: 'SHOW_MEDIA_VIEWER',
3
- HIDE_MEDIA_VIEWER: 'HIDE_MEDIA_VIEWER'
3
+ HIDE_MEDIA_VIEWER: 'HIDE_MEDIA_VIEWER',
4
+ TRACK_MEDIA_PASTE: 'TRACK_MEDIA_PASTE'
4
5
  };
@@ -1,5 +1,6 @@
1
1
  import { ACTIONS } from '../pm-plugins/actions';
2
2
  import { stateKey } from '../pm-plugins/plugin-key';
3
+ import { getIdentifier } from '../pm-plugins/utils/media-common';
3
4
  export const showMediaViewer = media => ({
4
5
  tr
5
6
  }) => {
@@ -19,4 +20,14 @@ export const hideMediaViewer = ({
19
20
  isMediaViewerVisible: false
20
21
  });
21
22
  return tr;
23
+ };
24
+ export const trackMediaPaste = attrs => ({
25
+ tr
26
+ }) => {
27
+ const identifier = getIdentifier(attrs);
28
+ tr.setMeta(stateKey, {
29
+ type: ACTIONS.TRACK_MEDIA_PASTE,
30
+ identifier
31
+ });
32
+ return tr;
22
33
  };
@@ -14,6 +14,7 @@ import { insertPoint } from '@atlaskit/editor-prosemirror/transform';
14
14
  import { findDomRefAtPos, findParentNodeOfType, findSelectedNodeOfType, isNodeSelection } from '@atlaskit/editor-prosemirror/utils';
15
15
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
16
16
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
17
+ import { isFileIdentifier } from '@atlaskit/media-client';
17
18
  import { getMediaFeatureFlag } from '@atlaskit/media-common';
18
19
  import { fg } from '@atlaskit/platform-feature-flags';
19
20
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -93,6 +94,9 @@ export class MediaPluginStateImplementation {
93
94
  _defineProperty(this, "removeOnCloseListener", () => {});
94
95
  _defineProperty(this, "onPopupToggleCallback", () => {});
95
96
  _defineProperty(this, "identifierCount", new Map());
97
+ // This is to enable mediaShallowCopySope to enable only shallow copying media referenced within the edtior
98
+ // see: trackOutOfScopeIdentifier
99
+ _defineProperty(this, "outOfEditorScopeIdentifierMap", new Map());
96
100
  _defineProperty(this, "taskManager", new MediaTaskManager());
97
101
  _defineProperty(this, "pickers", []);
98
102
  _defineProperty(this, "pickerPromises", []);
@@ -293,7 +297,18 @@ export class MediaPluginStateImplementation {
293
297
 
294
298
  // rely on has instead of count > 0 because if the user cuts and pastes the same media
295
299
  // the count will temporarily be 0 but the media is still in the scope of editor.
296
- return this.identifierCount.has(key);
300
+ return !this.outOfEditorScopeIdentifierMap.has(key) && this.identifierCount.has(key);
301
+ });
302
+ /**
303
+ * This is used in on Paste of media, this tracks which if the pasted media originated from a outside the editor
304
+ * i.e. the pasted media was not uplaoded to the current editor.
305
+ * This is to enable mediaShallowCopySope to enable only shallow copying media referenced within the edtior
306
+ */
307
+ _defineProperty(this, "trackOutOfScopeIdentifier", identifier => {
308
+ const key = this.getIdentifierKey(identifier);
309
+ this.outOfEditorScopeIdentifierMap.set(key, {
310
+ identifier
311
+ });
297
312
  });
298
313
  /**
299
314
  * Called from React UI Component on componentDidMount
@@ -742,6 +757,16 @@ export const createPlugin = (_schema, options, getIntl, pluginInjectionApi, node
742
757
  pluginState.isMediaViewerVisible = meta.isMediaViewerVisible;
743
758
  nextPluginState = nextPluginState.clone();
744
759
  break;
760
+ case ACTIONS.TRACK_MEDIA_PASTE:
761
+ const {
762
+ identifier
763
+ } = meta;
764
+ const isIdentifierInEditorScope = pluginState.isIdentifierInEditorScope(identifier);
765
+ if (!isIdentifierInEditorScope && isFileIdentifier(identifier)) {
766
+ pluginState.trackOutOfScopeIdentifier(identifier);
767
+ nextPluginState = pluginState.clone();
768
+ }
769
+ break;
745
770
  }
746
771
 
747
772
  // NOTE: We're not calling passing new state to the Editor, because we depend on the view.state reference
@@ -18,7 +18,7 @@ import { mediaInlineSpecWithFixedToDOM } from './nodeviews/toDOM-fixes/mediaInli
18
18
  import { mediaSingleSpecWithFixedToDOM } from './nodeviews/toDOM-fixes/mediaSingle';
19
19
  import { createPlugin as createMediaAltTextPlugin } from './pm-plugins/alt-text';
20
20
  import keymapMediaAltTextPlugin from './pm-plugins/alt-text/keymap';
21
- import { hideMediaViewer, showMediaViewer } from './pm-plugins/commands';
21
+ import { hideMediaViewer, showMediaViewer, trackMediaPaste } from './pm-plugins/commands';
22
22
  import keymapPlugin from './pm-plugins/keymap';
23
23
  import keymapMediaSinglePlugin from './pm-plugins/keymap-media';
24
24
  import linkingPlugin from './pm-plugins/linking';
@@ -116,7 +116,8 @@ export var mediaPlugin = function mediaPlugin(_ref3) {
116
116
  },
117
117
  commands: {
118
118
  showMediaViewer: showMediaViewer,
119
- hideMediaViewer: hideMediaViewer
119
+ hideMediaViewer: hideMediaViewer,
120
+ trackMediaPaste: trackMediaPaste
120
121
  },
121
122
  nodes: function nodes() {
122
123
  var _ref5 = options || {},
@@ -359,12 +359,9 @@ export var MediaNodeUpdater = /*#__PURE__*/function () {
359
359
  return _context8.abrupt("return", false);
360
360
  case 10:
361
361
  id = getIdentifier(attrs);
362
- _context8.next = 13;
363
- return _this.mediaPluginState.isIdentifierInEditorScope(id);
364
- case 13:
365
- isIdentifierOutsideEditorScope = !_context8.sent;
362
+ isIdentifierOutsideEditorScope = !_this.mediaPluginState.isIdentifierInEditorScope(id);
366
363
  return _context8.abrupt("return", isIdentifierOutsideEditorScope);
367
- case 15:
364
+ case 13:
368
365
  case "end":
369
366
  return _context8.stop();
370
367
  }
@@ -443,36 +440,41 @@ export var MediaNodeUpdater = /*#__PURE__*/function () {
443
440
  })));
444
441
  _defineProperty(this, "handleCopyFileSwitcher", /*#__PURE__*/function () {
445
442
  var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(attrs) {
446
- var mediaClient, source, destination, traceContext, _sourceAP, copyV2Source, _destAP, copyV2Destination, _yield$mediaClient$fi, id, _yield$mediaClient$fi2, _id;
443
+ var mediaClient, source, destination, traceContext, _yield$mediaClient$fi, id, _sourceAP, copyV2Source, _destAP, copyV2Destination, _yield$mediaClient$fi2, _id;
447
444
  return _regeneratorRuntime.wrap(function _callee11$(_context11) {
448
445
  while (1) switch (_context11.prev = _context11.next) {
449
446
  case 0:
450
447
  mediaClient = attrs.mediaClient, source = attrs.source, destination = attrs.destination, traceContext = attrs.traceContext;
448
+ _context11.prev = 1;
449
+ _context11.next = 4;
450
+ return mediaClient.file.copyFile(source, destination, undefined, traceContext);
451
+ case 4:
452
+ _yield$mediaClient$fi = _context11.sent;
453
+ id = _yield$mediaClient$fi.id;
454
+ return _context11.abrupt("return", id);
455
+ case 9:
456
+ _context11.prev = 9;
457
+ _context11.t0 = _context11["catch"](1);
451
458
  if (!fg('platform_media_copy_and_paste_v2')) {
452
- _context11.next = 11;
459
+ _context11.next = 21;
453
460
  break;
454
461
  }
455
- // don't need authProviders for v2 copy
462
+ // calling /v2/file/copy by removing the auth tokens to make cross product copy and pastes
456
463
  _sourceAP = source.authProvider, copyV2Source = _objectWithoutProperties(source, _excluded);
457
464
  _destAP = destination.authProvider, copyV2Destination = _objectWithoutProperties(destination, _excluded2);
458
- _context11.next = 6;
465
+ _context11.next = 16;
459
466
  return mediaClient.file.copyFile(copyV2Source, copyV2Destination, undefined, traceContext);
460
- case 6:
461
- _yield$mediaClient$fi = _context11.sent;
462
- id = _yield$mediaClient$fi.id;
463
- return _context11.abrupt("return", id);
464
- case 11:
465
- _context11.next = 13;
466
- return mediaClient.file.copyFile(source, destination, undefined, traceContext);
467
- case 13:
467
+ case 16:
468
468
  _yield$mediaClient$fi2 = _context11.sent;
469
469
  _id = _yield$mediaClient$fi2.id;
470
470
  return _context11.abrupt("return", _id);
471
- case 16:
471
+ case 21:
472
+ throw _context11.t0;
473
+ case 22:
472
474
  case "end":
473
475
  return _context11.stop();
474
476
  }
475
- }, _callee11);
477
+ }, _callee11, null, [[1, 9]]);
476
478
  }));
477
479
  return function (_x4) {
478
480
  return _ref13.apply(this, arguments);
@@ -1,4 +1,5 @@
1
1
  export var ACTIONS = {
2
2
  SHOW_MEDIA_VIEWER: 'SHOW_MEDIA_VIEWER',
3
- HIDE_MEDIA_VIEWER: 'HIDE_MEDIA_VIEWER'
3
+ HIDE_MEDIA_VIEWER: 'HIDE_MEDIA_VIEWER',
4
+ TRACK_MEDIA_PASTE: 'TRACK_MEDIA_PASTE'
4
5
  };
@@ -1,5 +1,6 @@
1
1
  import { ACTIONS } from '../pm-plugins/actions';
2
2
  import { stateKey } from '../pm-plugins/plugin-key';
3
+ import { getIdentifier } from '../pm-plugins/utils/media-common';
3
4
  export var showMediaViewer = function showMediaViewer(media) {
4
5
  return function (_ref) {
5
6
  var tr = _ref.tr;
@@ -19,4 +20,15 @@ export var hideMediaViewer = function hideMediaViewer(_ref2) {
19
20
  isMediaViewerVisible: false
20
21
  });
21
22
  return tr;
23
+ };
24
+ export var trackMediaPaste = function trackMediaPaste(attrs) {
25
+ return function (_ref3) {
26
+ var tr = _ref3.tr;
27
+ var identifier = getIdentifier(attrs);
28
+ tr.setMeta(stateKey, {
29
+ type: ACTIONS.TRACK_MEDIA_PASTE,
30
+ identifier: identifier
31
+ });
32
+ return tr;
33
+ };
22
34
  };
@@ -23,6 +23,7 @@ import { insertPoint } from '@atlaskit/editor-prosemirror/transform';
23
23
  import { findDomRefAtPos, findParentNodeOfType, findSelectedNodeOfType, isNodeSelection } from '@atlaskit/editor-prosemirror/utils';
24
24
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
25
25
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
26
+ import { isFileIdentifier } from '@atlaskit/media-client';
26
27
  import { getMediaFeatureFlag } from '@atlaskit/media-common';
27
28
  import { fg } from '@atlaskit/platform-feature-flags';
28
29
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -109,6 +110,9 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
109
110
  _defineProperty(this, "removeOnCloseListener", function () {});
110
111
  _defineProperty(this, "onPopupToggleCallback", function () {});
111
112
  _defineProperty(this, "identifierCount", new Map());
113
+ // This is to enable mediaShallowCopySope to enable only shallow copying media referenced within the edtior
114
+ // see: trackOutOfScopeIdentifier
115
+ _defineProperty(this, "outOfEditorScopeIdentifierMap", new Map());
112
116
  _defineProperty(this, "taskManager", new MediaTaskManager());
113
117
  _defineProperty(this, "pickers", []);
114
118
  _defineProperty(this, "pickerPromises", []);
@@ -310,7 +314,18 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
310
314
 
311
315
  // rely on has instead of count > 0 because if the user cuts and pastes the same media
312
316
  // the count will temporarily be 0 but the media is still in the scope of editor.
313
- return _this.identifierCount.has(key);
317
+ return !_this.outOfEditorScopeIdentifierMap.has(key) && _this.identifierCount.has(key);
318
+ });
319
+ /**
320
+ * This is used in on Paste of media, this tracks which if the pasted media originated from a outside the editor
321
+ * i.e. the pasted media was not uplaoded to the current editor.
322
+ * This is to enable mediaShallowCopySope to enable only shallow copying media referenced within the edtior
323
+ */
324
+ _defineProperty(this, "trackOutOfScopeIdentifier", function (identifier) {
325
+ var key = _this.getIdentifierKey(identifier);
326
+ _this.outOfEditorScopeIdentifierMap.set(key, {
327
+ identifier: identifier
328
+ });
314
329
  });
315
330
  /**
316
331
  * Called from React UI Component on componentDidMount
@@ -841,6 +856,14 @@ export var createPlugin = function createPlugin(_schema, options, getIntl, plugi
841
856
  pluginState.isMediaViewerVisible = meta.isMediaViewerVisible;
842
857
  nextPluginState = nextPluginState.clone();
843
858
  break;
859
+ case ACTIONS.TRACK_MEDIA_PASTE:
860
+ var identifier = meta.identifier;
861
+ var isIdentifierInEditorScope = pluginState.isIdentifierInEditorScope(identifier);
862
+ if (!isIdentifierInEditorScope && isFileIdentifier(identifier)) {
863
+ pluginState.trackOutOfScopeIdentifier(identifier);
864
+ nextPluginState = pluginState.clone();
865
+ }
866
+ break;
844
867
  }
845
868
 
846
869
  // NOTE: We're not calling passing new state to the Editor, because we depend on the view.state reference
@@ -18,24 +18,25 @@ import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
18
18
  import type { MediaPluginState } from './pm-plugins/types';
19
19
  import type { InsertMediaAsMediaSingle } from './pm-plugins/utils/media-single';
20
20
  import type { MediaOptions } from './types';
21
+ export type MediaPluginDependencies = [
22
+ OptionalPlugin<AnalyticsPlugin>,
23
+ OptionalPlugin<ContextIdentifierPlugin>,
24
+ OptionalPlugin<EditorViewModePlugin>,
25
+ OptionalPlugin<GuidelinePlugin>,
26
+ GridPlugin,
27
+ WidthPlugin,
28
+ DecorationsPlugin,
29
+ FloatingToolbarPlugin,
30
+ EditorDisabledPlugin,
31
+ FocusPlugin,
32
+ SelectionPlugin,
33
+ OptionalPlugin<AnnotationPlugin>,
34
+ OptionalPlugin<FeatureFlagsPlugin>,
35
+ OptionalPlugin<ConnectivityPlugin>
36
+ ];
21
37
  export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
22
38
  pluginConfiguration: MediaOptions | undefined;
23
- dependencies: [
24
- OptionalPlugin<AnalyticsPlugin>,
25
- OptionalPlugin<ContextIdentifierPlugin>,
26
- OptionalPlugin<EditorViewModePlugin>,
27
- OptionalPlugin<GuidelinePlugin>,
28
- GridPlugin,
29
- WidthPlugin,
30
- DecorationsPlugin,
31
- FloatingToolbarPlugin,
32
- EditorDisabledPlugin,
33
- FocusPlugin,
34
- SelectionPlugin,
35
- OptionalPlugin<AnnotationPlugin>,
36
- OptionalPlugin<FeatureFlagsPlugin>,
37
- OptionalPlugin<ConnectivityPlugin>
38
- ];
39
+ dependencies: MediaPluginDependencies;
39
40
  sharedState: MediaPluginState | null;
40
41
  actions: {
41
42
  insertMediaAsMediaSingle: InsertMediaAsMediaSingle;
@@ -53,5 +54,6 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
53
54
  commands: {
54
55
  showMediaViewer: (media: MediaADFAttrs) => EditorCommand;
55
56
  hideMediaViewer: EditorCommand;
57
+ trackMediaPaste: (attrs: MediaADFAttrs) => EditorCommand;
56
58
  };
57
59
  }>;
@@ -1,4 +1,5 @@
1
1
  export declare const ACTIONS: {
2
2
  SHOW_MEDIA_VIEWER: string;
3
3
  HIDE_MEDIA_VIEWER: string;
4
+ TRACK_MEDIA_PASTE: string;
4
5
  };
@@ -2,3 +2,4 @@ import type { MediaADFAttrs } from '@atlaskit/adf-schema';
2
2
  import type { EditorCommand } from '@atlaskit/editor-common/types';
3
3
  export declare const showMediaViewer: (media: MediaADFAttrs) => EditorCommand;
4
4
  export declare const hideMediaViewer: EditorCommand;
5
+ export declare const trackMediaPaste: (attrs: MediaADFAttrs) => EditorCommand;
@@ -9,7 +9,7 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
9
9
  import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
10
10
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
11
11
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
12
- import type { Identifier } from '@atlaskit/media-client';
12
+ import { type Identifier } from '@atlaskit/media-client';
13
13
  import type { MediaClientConfig } from '@atlaskit/media-core';
14
14
  import type { MediaNextEditorPluginType } from '../mediaPluginType';
15
15
  import type { MediaOptions, MediaState, MediaStateEventSubscriber, getPosHandlerNode as ProsemirrorGetPosHandler } from '../types';
@@ -53,6 +53,7 @@ export declare class MediaPluginStateImplementation implements MediaPluginState
53
53
  private openMediaPickerBrowser?;
54
54
  private onPopupToggleCallback;
55
55
  private identifierCount;
56
+ private outOfEditorScopeIdentifierMap;
56
57
  private taskManager;
57
58
  pickers: PickerFacade[];
58
59
  pickerPromises: Array<Promise<PickerFacade>>;
@@ -106,6 +107,12 @@ export declare class MediaPluginStateImplementation implements MediaPluginState
106
107
  trackMediaNodeAddition: (node: PMNode) => void;
107
108
  trackMediaNodeRemoval: (node: PMNode) => void;
108
109
  isIdentifierInEditorScope: (identifier: Identifier) => boolean;
110
+ /**
111
+ * This is used in on Paste of media, this tracks which if the pasted media originated from a outside the editor
112
+ * i.e. the pasted media was not uplaoded to the current editor.
113
+ * This is to enable mediaShallowCopySope to enable only shallow copying media referenced within the edtior
114
+ */
115
+ trackOutOfScopeIdentifier: (identifier: Identifier) => void;
109
116
  /**
110
117
  * Called from React UI Component on componentDidMount
111
118
  */
@@ -62,6 +62,7 @@ export interface MediaPluginState {
62
62
  selectedMediaContainerNode: () => PMNode | undefined;
63
63
  handleDrag: (dragState: 'enter' | 'leave') => void;
64
64
  isIdentifierInEditorScope: (identifier: Identifier) => boolean;
65
+ trackOutOfScopeIdentifier: (identifier: Identifier) => void;
65
66
  updateElement(): void;
66
67
  setIsResizing(isResizing: boolean): void;
67
68
  setResizingWidth(width: number): void;
@@ -18,24 +18,25 @@ import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
18
18
  import type { MediaPluginState } from './pm-plugins/types';
19
19
  import type { InsertMediaAsMediaSingle } from './pm-plugins/utils/media-single';
20
20
  import type { MediaOptions } from './types';
21
+ export type MediaPluginDependencies = [
22
+ OptionalPlugin<AnalyticsPlugin>,
23
+ OptionalPlugin<ContextIdentifierPlugin>,
24
+ OptionalPlugin<EditorViewModePlugin>,
25
+ OptionalPlugin<GuidelinePlugin>,
26
+ GridPlugin,
27
+ WidthPlugin,
28
+ DecorationsPlugin,
29
+ FloatingToolbarPlugin,
30
+ EditorDisabledPlugin,
31
+ FocusPlugin,
32
+ SelectionPlugin,
33
+ OptionalPlugin<AnnotationPlugin>,
34
+ OptionalPlugin<FeatureFlagsPlugin>,
35
+ OptionalPlugin<ConnectivityPlugin>
36
+ ];
21
37
  export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
22
38
  pluginConfiguration: MediaOptions | undefined;
23
- dependencies: [
24
- OptionalPlugin<AnalyticsPlugin>,
25
- OptionalPlugin<ContextIdentifierPlugin>,
26
- OptionalPlugin<EditorViewModePlugin>,
27
- OptionalPlugin<GuidelinePlugin>,
28
- GridPlugin,
29
- WidthPlugin,
30
- DecorationsPlugin,
31
- FloatingToolbarPlugin,
32
- EditorDisabledPlugin,
33
- FocusPlugin,
34
- SelectionPlugin,
35
- OptionalPlugin<AnnotationPlugin>,
36
- OptionalPlugin<FeatureFlagsPlugin>,
37
- OptionalPlugin<ConnectivityPlugin>
38
- ];
39
+ dependencies: MediaPluginDependencies;
39
40
  sharedState: MediaPluginState | null;
40
41
  actions: {
41
42
  insertMediaAsMediaSingle: InsertMediaAsMediaSingle;
@@ -53,5 +54,6 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
53
54
  commands: {
54
55
  showMediaViewer: (media: MediaADFAttrs) => EditorCommand;
55
56
  hideMediaViewer: EditorCommand;
57
+ trackMediaPaste: (attrs: MediaADFAttrs) => EditorCommand;
56
58
  };
57
59
  }>;
@@ -1,4 +1,5 @@
1
1
  export declare const ACTIONS: {
2
2
  SHOW_MEDIA_VIEWER: string;
3
3
  HIDE_MEDIA_VIEWER: string;
4
+ TRACK_MEDIA_PASTE: string;
4
5
  };
@@ -2,3 +2,4 @@ import type { MediaADFAttrs } from '@atlaskit/adf-schema';
2
2
  import type { EditorCommand } from '@atlaskit/editor-common/types';
3
3
  export declare const showMediaViewer: (media: MediaADFAttrs) => EditorCommand;
4
4
  export declare const hideMediaViewer: EditorCommand;
5
+ export declare const trackMediaPaste: (attrs: MediaADFAttrs) => EditorCommand;
@@ -9,7 +9,7 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
9
9
  import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
10
10
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
11
11
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
12
- import type { Identifier } from '@atlaskit/media-client';
12
+ import { type Identifier } from '@atlaskit/media-client';
13
13
  import type { MediaClientConfig } from '@atlaskit/media-core';
14
14
  import type { MediaNextEditorPluginType } from '../mediaPluginType';
15
15
  import type { MediaOptions, MediaState, MediaStateEventSubscriber, getPosHandlerNode as ProsemirrorGetPosHandler } from '../types';
@@ -53,6 +53,7 @@ export declare class MediaPluginStateImplementation implements MediaPluginState
53
53
  private openMediaPickerBrowser?;
54
54
  private onPopupToggleCallback;
55
55
  private identifierCount;
56
+ private outOfEditorScopeIdentifierMap;
56
57
  private taskManager;
57
58
  pickers: PickerFacade[];
58
59
  pickerPromises: Array<Promise<PickerFacade>>;
@@ -106,6 +107,12 @@ export declare class MediaPluginStateImplementation implements MediaPluginState
106
107
  trackMediaNodeAddition: (node: PMNode) => void;
107
108
  trackMediaNodeRemoval: (node: PMNode) => void;
108
109
  isIdentifierInEditorScope: (identifier: Identifier) => boolean;
110
+ /**
111
+ * This is used in on Paste of media, this tracks which if the pasted media originated from a outside the editor
112
+ * i.e. the pasted media was not uplaoded to the current editor.
113
+ * This is to enable mediaShallowCopySope to enable only shallow copying media referenced within the edtior
114
+ */
115
+ trackOutOfScopeIdentifier: (identifier: Identifier) => void;
109
116
  /**
110
117
  * Called from React UI Component on componentDidMount
111
118
  */
@@ -62,6 +62,7 @@ export interface MediaPluginState {
62
62
  selectedMediaContainerNode: () => PMNode | undefined;
63
63
  handleDrag: (dragState: 'enter' | 'leave') => void;
64
64
  isIdentifierInEditorScope: (identifier: Identifier) => boolean;
65
+ trackOutOfScopeIdentifier: (identifier: Identifier) => void;
65
66
  updateElement(): void;
66
67
  setIsResizing(isResizing: boolean): void;
67
68
  setResizingWidth(width: number): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-media",
3
- "version": "1.44.2",
3
+ "version": "1.44.3",
4
4
  "description": "Media plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,7 +36,7 @@
36
36
  "@atlaskit/analytics-namespaced-context": "^6.12.0",
37
37
  "@atlaskit/analytics-next": "^10.2.0",
38
38
  "@atlaskit/button": "^20.3.0",
39
- "@atlaskit/editor-common": "^99.0.0",
39
+ "@atlaskit/editor-common": "^99.2.0",
40
40
  "@atlaskit/editor-palette": "1.6.4",
41
41
  "@atlaskit/editor-plugin-analytics": "^1.10.0",
42
42
  "@atlaskit/editor-plugin-annotation": "1.26.11",
@@ -54,7 +54,7 @@
54
54
  "@atlaskit/editor-shared-styles": "^3.2.0",
55
55
  "@atlaskit/editor-tables": "^2.8.0",
56
56
  "@atlaskit/form": "^11.0.0",
57
- "@atlaskit/icon": "^23.3.0",
57
+ "@atlaskit/icon": "^23.4.0",
58
58
  "@atlaskit/media-card": "^78.18.0",
59
59
  "@atlaskit/media-client": "^29.0.0",
60
60
  "@atlaskit/media-client-react": "^2.5.0",
@@ -67,7 +67,7 @@
67
67
  "@atlaskit/primitives": "^13.3.0",
68
68
  "@atlaskit/textfield": "^6.7.0",
69
69
  "@atlaskit/theme": "^14.0.0",
70
- "@atlaskit/tmp-editor-statsig": "^2.33.0",
70
+ "@atlaskit/tmp-editor-statsig": "^2.35.0",
71
71
  "@atlaskit/tokens": "^3.0.0",
72
72
  "@atlaskit/tooltip": "^19.0.0",
73
73
  "@babel/runtime": "^7.0.0",