@atlaskit/editor-plugin-media 1.43.14 → 1.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/nodeviews/mediaGroup.js +4 -4
  3. package/dist/cjs/nodeviews/mediaGroupNext.js +4 -4
  4. package/dist/cjs/nodeviews/mediaInline.js +8 -8
  5. package/dist/cjs/nodeviews/mediaNodeUpdater.js +179 -141
  6. package/dist/cjs/nodeviews/mediaSingle.js +4 -4
  7. package/dist/cjs/nodeviews/mediaSingleNext.js +4 -4
  8. package/dist/cjs/pm-plugins/main.js +41 -13
  9. package/dist/es2019/nodeviews/mediaGroup.js +2 -2
  10. package/dist/es2019/nodeviews/mediaGroupNext.js +2 -2
  11. package/dist/es2019/nodeviews/mediaInline.js +5 -5
  12. package/dist/es2019/nodeviews/mediaNodeUpdater.js +18 -0
  13. package/dist/es2019/nodeviews/mediaSingle.js +2 -2
  14. package/dist/es2019/nodeviews/mediaSingleNext.js +2 -2
  15. package/dist/es2019/pm-plugins/main.js +42 -12
  16. package/dist/esm/nodeviews/mediaGroup.js +4 -4
  17. package/dist/esm/nodeviews/mediaGroupNext.js +4 -4
  18. package/dist/esm/nodeviews/mediaInline.js +8 -8
  19. package/dist/esm/nodeviews/mediaNodeUpdater.js +179 -141
  20. package/dist/esm/nodeviews/mediaSingle.js +4 -4
  21. package/dist/esm/nodeviews/mediaSingleNext.js +4 -4
  22. package/dist/esm/pm-plugins/main.js +42 -14
  23. package/dist/types/nodeviews/__mocks__/mediaNodeUpdater.d.ts +1 -0
  24. package/dist/types/nodeviews/mediaNodeUpdater.d.ts +3 -1
  25. package/dist/types/pm-plugins/main.d.ts +4 -1
  26. package/dist/types/pm-plugins/types.d.ts +2 -0
  27. package/dist/types/types/index.d.ts +2 -0
  28. package/dist/types-ts4.5/nodeviews/__mocks__/mediaNodeUpdater.d.ts +1 -0
  29. package/dist/types-ts4.5/nodeviews/mediaNodeUpdater.d.ts +3 -1
  30. package/dist/types-ts4.5/pm-plugins/main.d.ts +4 -1
  31. package/dist/types-ts4.5/pm-plugins/types.d.ts +2 -0
  32. package/dist/types-ts4.5/types/index.d.ts +2 -0
  33. package/package.json +6 -6
@@ -78,7 +78,7 @@ var useMediaNodeUpdater = function useMediaNodeUpdater(_ref) {
78
78
  };
79
79
  var mediaAsyncOperations = /*#__PURE__*/function () {
80
80
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(props) {
81
- var updatedDimensions, currentAttrs, updatingNode, contextId, hasDifferentContextId, copyNode;
81
+ var updatedDimensions, currentAttrs, updatingNode, contextId, shouldNodeBeDeepCopied, copyNode;
82
82
  return _regeneratorRuntime.wrap(function _callee$(_context) {
83
83
  while (1) switch (_context.prev = _context.next) {
84
84
  case 0:
@@ -110,10 +110,10 @@ var mediaAsyncOperations = /*#__PURE__*/function () {
110
110
  return props.updater.updateContextId();
111
111
  case 15:
112
112
  _context.next = 17;
113
- return props.updater.hasDifferentContextId();
113
+ return props.updater.shouldNodeBeDeepCopied();
114
114
  case 17:
115
- hasDifferentContextId = _context.sent;
116
- if (!hasDifferentContextId) {
115
+ shouldNodeBeDeepCopied = _context.sent;
116
+ if (!shouldNodeBeDeepCopied) {
117
117
  _context.next = 28;
118
118
  break;
119
119
  }
@@ -30,7 +30,7 @@ import { updateMediaNodeAttrs } from '../pm-plugins/commands/helpers';
30
30
  // Ignored via go/ees005
31
31
  // eslint-disable-next-line import/no-namespace
32
32
  import * as helpers from '../pm-plugins/commands/helpers';
33
- import { getMediaFromSupportedMediaNodesFromSelection, isNodeDoubleClickSupportedInLivePagesViewMode, removeMediaNode, splitMediaGroup } from '../pm-plugins/utils/media-common';
33
+ import { getIdentifier, getMediaFromSupportedMediaNodesFromSelection, isNodeDoubleClickSupportedInLivePagesViewMode, removeMediaNode, splitMediaGroup } from '../pm-plugins/utils/media-common';
34
34
  import { insertMediaGroupNode, insertMediaInlineNode } from '../pm-plugins/utils/media-files';
35
35
  import { getMediaNodeInsertionType } from '../pm-plugins/utils/media-inline';
36
36
  import { insertMediaSingleNode } from '../pm-plugins/utils/media-single';
@@ -108,7 +108,7 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
108
108
  _defineProperty(this, "destroyed", false);
109
109
  _defineProperty(this, "removeOnCloseListener", function () {});
110
110
  _defineProperty(this, "onPopupToggleCallback", function () {});
111
- _defineProperty(this, "nodeCount", new Map());
111
+ _defineProperty(this, "identifierCount", new Map());
112
112
  _defineProperty(this, "taskManager", new MediaTaskManager());
113
113
  _defineProperty(this, "pickers", []);
114
114
  _defineProperty(this, "pickerPromises", []);
@@ -266,23 +266,51 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
266
266
  }
267
267
  removeMediaNode(_this.view, getNode, getPos);
268
268
  });
269
+ _defineProperty(this, "getIdentifierKey", function (identifier) {
270
+ if (identifier.mediaItemType === 'file') {
271
+ return identifier.id;
272
+ } else {
273
+ return identifier.dataURI;
274
+ }
275
+ });
269
276
  _defineProperty(this, "trackMediaNodeAddition", function (node) {
270
- var _this$nodeCount$get;
271
- var id = node.attrs.id;
272
- var count = (_this$nodeCount$get = _this.nodeCount.get(id)) !== null && _this$nodeCount$get !== void 0 ? _this$nodeCount$get : 0;
277
+ var _this$identifierCount;
278
+ var identifier = getIdentifier(node.attrs);
279
+ var key = _this.getIdentifierKey(identifier);
280
+ var _ref2 = (_this$identifierCount = _this.identifierCount.get(key)) !== null && _this$identifierCount !== void 0 ? _this$identifierCount : {
281
+ count: 0
282
+ },
283
+ count = _ref2.count;
273
284
  if (count === 0) {
274
- _this.taskManager.resumePendingTask(id);
285
+ _this.taskManager.resumePendingTask(key);
275
286
  }
276
- _this.nodeCount.set(id, count + 1);
287
+ _this.identifierCount.set(key, {
288
+ identifier: identifier,
289
+ count: count + 1
290
+ });
277
291
  });
278
292
  _defineProperty(this, "trackMediaNodeRemoval", function (node) {
279
- var _this$nodeCount$get2;
280
- var id = node.attrs.id;
281
- var count = (_this$nodeCount$get2 = _this.nodeCount.get(id)) !== null && _this$nodeCount$get2 !== void 0 ? _this$nodeCount$get2 : 0;
293
+ var _this$identifierCount2;
294
+ var identifier = getIdentifier(node.attrs);
295
+ var key = _this.getIdentifierKey(identifier);
296
+ var _ref3 = (_this$identifierCount2 = _this.identifierCount.get(key)) !== null && _this$identifierCount2 !== void 0 ? _this$identifierCount2 : {
297
+ count: 0
298
+ },
299
+ count = _ref3.count;
282
300
  if (count === 1) {
283
- _this.taskManager.cancelPendingTask(id);
301
+ _this.taskManager.cancelPendingTask(key);
284
302
  }
285
- _this.nodeCount.set(id, count - 1);
303
+ _this.identifierCount.set(key, {
304
+ identifier: identifier,
305
+ count: count - 1
306
+ });
307
+ });
308
+ _defineProperty(this, "isIdentifierInEditorScope", function (identifier) {
309
+ var key = _this.getIdentifierKey(identifier);
310
+
311
+ // rely on has instead of count > 0 because if the user cuts and pastes the same media
312
+ // the count will temporarily be 0 but the media is still in the scope of editor.
313
+ return _this.identifierCount.has(key);
286
314
  });
287
315
  /**
288
316
  * Called from React UI Component on componentDidMount
@@ -300,8 +328,8 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
300
328
  */
301
329
  _defineProperty(this, "handleMediaNodeUnmount", function (oldNode) {
302
330
  _this.trackMediaNodeRemoval(oldNode);
303
- _this.mediaNodes = _this.mediaNodes.filter(function (_ref2) {
304
- var node = _ref2.node;
331
+ _this.mediaNodes = _this.mediaNodes.filter(function (_ref4) {
332
+ var node = _ref4.node;
305
333
  return oldNode !== node;
306
334
  });
307
335
  });
@@ -14,6 +14,7 @@ export declare class MediaNodeUpdater {
14
14
  getRemoteDimensions(): Promise<void>;
15
15
  isNodeFromDifferentCollection(): Promise<void>;
16
16
  hasDifferentContextId(): Promise<void>;
17
+ shouldNodeBeDeepCopied(): Promise<void>;
17
18
  copyNode(): Promise<void>;
18
19
  copyNodeFromPos(): Promise<void>;
19
20
  updateMediaSingleFileAttrs(): Promise<void>;
@@ -3,7 +3,7 @@ import type { ContextIdentifierProvider, MediaProvider } from '@atlaskit/editor-
3
3
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { MediaTraceContext } from '@atlaskit/media-common';
6
- import type { MediaOptions, getPosHandler as ProsemirrorGetPosHandler, SupportedMediaAttributes } from '../types';
6
+ import type { MediaOptions, MediaPluginState, getPosHandler as ProsemirrorGetPosHandler, SupportedMediaAttributes } from '../types';
7
7
  type RemoteDimensions = {
8
8
  id: string;
9
9
  height: number;
@@ -20,6 +20,7 @@ export interface MediaNodeUpdaterProps {
20
20
  }
21
21
  export declare class MediaNodeUpdater {
22
22
  props: MediaNodeUpdaterProps;
23
+ mediaPluginState: MediaPluginState | undefined;
23
24
  constructor(props: MediaNodeUpdaterProps);
24
25
  setProps(newComponentProps: Partial<MediaNodeUpdaterProps>): void;
25
26
  isMediaBlobUrl(): boolean;
@@ -35,6 +36,7 @@ export declare class MediaNodeUpdater {
35
36
  getNodeContextId: () => string | null;
36
37
  updateDimensions: (dimensions: RemoteDimensions) => void;
37
38
  getRemoteDimensions(): Promise<false | RemoteDimensions>;
39
+ shouldNodeBeDeepCopied: () => Promise<boolean>;
38
40
  hasDifferentContextId: () => Promise<boolean>;
39
41
  isNodeFromDifferentCollection: () => Promise<boolean>;
40
42
  handleExternalMedia(getPos: ProsemirrorGetPosHandler): Promise<void>;
@@ -9,6 +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
13
  import type { MediaClientConfig } from '@atlaskit/media-core';
13
14
  import type { MediaNextEditorPluginType } from '../mediaPluginType';
14
15
  import type { MediaOptions, MediaState, MediaStateEventSubscriber, getPosHandlerNode as ProsemirrorGetPosHandler } from '../types';
@@ -51,7 +52,7 @@ export declare class MediaPluginStateImplementation implements MediaPluginState
51
52
  private removeOnCloseListener;
52
53
  private openMediaPickerBrowser?;
53
54
  private onPopupToggleCallback;
54
- private nodeCount;
55
+ private identifierCount;
55
56
  private taskManager;
56
57
  pickers: PickerFacade[];
57
58
  pickerPromises: Array<Promise<PickerFacade>>;
@@ -101,8 +102,10 @@ export declare class MediaPluginStateImplementation implements MediaPluginState
101
102
  * inside of it
102
103
  */
103
104
  handleMediaNodeRemoval: (node: PMNode | undefined, getPos: ProsemirrorGetPosHandler) => void;
105
+ private getIdentifierKey;
104
106
  trackMediaNodeAddition: (node: PMNode) => void;
105
107
  trackMediaNodeRemoval: (node: PMNode) => void;
108
+ isIdentifierInEditorScope: (identifier: Identifier) => boolean;
106
109
  /**
107
110
  * Called from React UI Component on componentDidMount
108
111
  */
@@ -4,6 +4,7 @@ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
4
4
  import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
5
5
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
+ import type { Identifier } from '@atlaskit/media-client';
7
8
  import type { MediaClientConfig } from '@atlaskit/media-core';
8
9
  import type { MediaOptions, MediaState, MediaStateEventSubscriber, ProsemirrorGetPosHandler } from '../types';
9
10
  import type { MediaPluginOptions } from '../types/media-plugin-options';
@@ -60,6 +61,7 @@ export interface MediaPluginState {
60
61
  removeSelectedMediaContainer: () => boolean;
61
62
  selectedMediaContainerNode: () => PMNode | undefined;
62
63
  handleDrag: (dragState: 'enter' | 'leave') => void;
64
+ isIdentifierInEditorScope: (identifier: Identifier) => boolean;
63
65
  updateElement(): void;
64
66
  setIsResizing(isResizing: boolean): void;
65
67
  setResizingWidth(width: number): void;
@@ -14,6 +14,7 @@ interface PlaceholderTextOptions {
14
14
  }
15
15
  export type MediaStateStatus = 'unknown' | 'ready' | 'cancelled' | 'preview' | 'error' | 'mobile-upload-end';
16
16
  export type MediaSingleWithType = 'pixel' | 'percentage';
17
+ export type MediaCopyScope = 'editor' | 'context';
17
18
  export interface MediaOptions {
18
19
  provider?: Providers['mediaProvider'];
19
20
  /**
@@ -53,6 +54,7 @@ export interface MediaOptions {
53
54
  allowCommentsOnMedia?: boolean;
54
55
  editorAppearance?: EditorAppearance;
55
56
  forceHandlePositioning?: HandlePositioning;
57
+ mediaShallowCopyScope?: MediaCopyScope;
56
58
  }
57
59
  export interface MediaSingleOptions {
58
60
  disableLayout?: boolean;
@@ -14,6 +14,7 @@ export declare class MediaNodeUpdater {
14
14
  getRemoteDimensions(): Promise<void>;
15
15
  isNodeFromDifferentCollection(): Promise<void>;
16
16
  hasDifferentContextId(): Promise<void>;
17
+ shouldNodeBeDeepCopied(): Promise<void>;
17
18
  copyNode(): Promise<void>;
18
19
  copyNodeFromPos(): Promise<void>;
19
20
  updateMediaSingleFileAttrs(): Promise<void>;
@@ -3,7 +3,7 @@ import type { ContextIdentifierProvider, MediaProvider } from '@atlaskit/editor-
3
3
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { MediaTraceContext } from '@atlaskit/media-common';
6
- import type { MediaOptions, getPosHandler as ProsemirrorGetPosHandler, SupportedMediaAttributes } from '../types';
6
+ import type { MediaOptions, MediaPluginState, getPosHandler as ProsemirrorGetPosHandler, SupportedMediaAttributes } from '../types';
7
7
  type RemoteDimensions = {
8
8
  id: string;
9
9
  height: number;
@@ -20,6 +20,7 @@ export interface MediaNodeUpdaterProps {
20
20
  }
21
21
  export declare class MediaNodeUpdater {
22
22
  props: MediaNodeUpdaterProps;
23
+ mediaPluginState: MediaPluginState | undefined;
23
24
  constructor(props: MediaNodeUpdaterProps);
24
25
  setProps(newComponentProps: Partial<MediaNodeUpdaterProps>): void;
25
26
  isMediaBlobUrl(): boolean;
@@ -35,6 +36,7 @@ export declare class MediaNodeUpdater {
35
36
  getNodeContextId: () => string | null;
36
37
  updateDimensions: (dimensions: RemoteDimensions) => void;
37
38
  getRemoteDimensions(): Promise<false | RemoteDimensions>;
39
+ shouldNodeBeDeepCopied: () => Promise<boolean>;
38
40
  hasDifferentContextId: () => Promise<boolean>;
39
41
  isNodeFromDifferentCollection: () => Promise<boolean>;
40
42
  handleExternalMedia(getPos: ProsemirrorGetPosHandler): Promise<void>;
@@ -9,6 +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
13
  import type { MediaClientConfig } from '@atlaskit/media-core';
13
14
  import type { MediaNextEditorPluginType } from '../mediaPluginType';
14
15
  import type { MediaOptions, MediaState, MediaStateEventSubscriber, getPosHandlerNode as ProsemirrorGetPosHandler } from '../types';
@@ -51,7 +52,7 @@ export declare class MediaPluginStateImplementation implements MediaPluginState
51
52
  private removeOnCloseListener;
52
53
  private openMediaPickerBrowser?;
53
54
  private onPopupToggleCallback;
54
- private nodeCount;
55
+ private identifierCount;
55
56
  private taskManager;
56
57
  pickers: PickerFacade[];
57
58
  pickerPromises: Array<Promise<PickerFacade>>;
@@ -101,8 +102,10 @@ export declare class MediaPluginStateImplementation implements MediaPluginState
101
102
  * inside of it
102
103
  */
103
104
  handleMediaNodeRemoval: (node: PMNode | undefined, getPos: ProsemirrorGetPosHandler) => void;
105
+ private getIdentifierKey;
104
106
  trackMediaNodeAddition: (node: PMNode) => void;
105
107
  trackMediaNodeRemoval: (node: PMNode) => void;
108
+ isIdentifierInEditorScope: (identifier: Identifier) => boolean;
106
109
  /**
107
110
  * Called from React UI Component on componentDidMount
108
111
  */
@@ -4,6 +4,7 @@ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
4
4
  import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
5
5
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
6
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
+ import type { Identifier } from '@atlaskit/media-client';
7
8
  import type { MediaClientConfig } from '@atlaskit/media-core';
8
9
  import type { MediaOptions, MediaState, MediaStateEventSubscriber, ProsemirrorGetPosHandler } from '../types';
9
10
  import type { MediaPluginOptions } from '../types/media-plugin-options';
@@ -60,6 +61,7 @@ export interface MediaPluginState {
60
61
  removeSelectedMediaContainer: () => boolean;
61
62
  selectedMediaContainerNode: () => PMNode | undefined;
62
63
  handleDrag: (dragState: 'enter' | 'leave') => void;
64
+ isIdentifierInEditorScope: (identifier: Identifier) => boolean;
63
65
  updateElement(): void;
64
66
  setIsResizing(isResizing: boolean): void;
65
67
  setResizingWidth(width: number): void;
@@ -14,6 +14,7 @@ interface PlaceholderTextOptions {
14
14
  }
15
15
  export type MediaStateStatus = 'unknown' | 'ready' | 'cancelled' | 'preview' | 'error' | 'mobile-upload-end';
16
16
  export type MediaSingleWithType = 'pixel' | 'percentage';
17
+ export type MediaCopyScope = 'editor' | 'context';
17
18
  export interface MediaOptions {
18
19
  provider?: Providers['mediaProvider'];
19
20
  /**
@@ -53,6 +54,7 @@ export interface MediaOptions {
53
54
  allowCommentsOnMedia?: boolean;
54
55
  editorAppearance?: EditorAppearance;
55
56
  forceHandlePositioning?: HandlePositioning;
57
+ mediaShallowCopyScope?: MediaCopyScope;
56
58
  }
57
59
  export interface MediaSingleOptions {
58
60
  disableLayout?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-media",
3
- "version": "1.43.14",
3
+ "version": "1.44.1",
4
4
  "description": "Media plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,10 +36,10 @@
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": "^98.2.0",
40
- "@atlaskit/editor-palette": "1.6.3",
39
+ "@atlaskit/editor-common": "^99.0.0",
40
+ "@atlaskit/editor-palette": "1.6.4",
41
41
  "@atlaskit/editor-plugin-analytics": "^1.10.0",
42
- "@atlaskit/editor-plugin-annotation": "1.26.10",
42
+ "@atlaskit/editor-plugin-annotation": "1.26.11",
43
43
  "@atlaskit/editor-plugin-connectivity": "^1.1.0",
44
44
  "@atlaskit/editor-plugin-decorations": "^1.3.0",
45
45
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
@@ -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.2.0",
57
+ "@atlaskit/icon": "^23.3.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",
@@ -68,7 +68,7 @@
68
68
  "@atlaskit/textfield": "^6.7.0",
69
69
  "@atlaskit/theme": "^14.0.0",
70
70
  "@atlaskit/tmp-editor-statsig": "^2.33.0",
71
- "@atlaskit/tokens": "^2.5.0",
71
+ "@atlaskit/tokens": "^3.0.0",
72
72
  "@atlaskit/tooltip": "^19.0.0",
73
73
  "@babel/runtime": "^7.0.0",
74
74
  "@emotion/react": "^11.7.1",