@atlaskit/editor-plugin-media 12.8.2 → 12.9.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 (46) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/nodeviews/mediaGroupNext.js +12 -12
  3. package/dist/cjs/nodeviews/mediaInline.js +25 -25
  4. package/dist/cjs/nodeviews/mediaNodeUpdater.js +199 -198
  5. package/dist/cjs/nodeviews/mediaNodeView/media.js +29 -17
  6. package/dist/cjs/nodeviews/mediaSingleNext.js +24 -24
  7. package/dist/cjs/pm-plugins/ai-generating-decoration.js +59 -12
  8. package/dist/cjs/pm-plugins/commands.js +2 -2
  9. package/dist/cjs/pm-plugins/main.js +55 -46
  10. package/dist/cjs/pm-plugins/mediaTaskManager.js +6 -6
  11. package/dist/cjs/pm-plugins/picker-facade.js +4 -4
  12. package/dist/cjs/pm-plugins/utils/check-media-type.js +17 -17
  13. package/dist/cjs/ui/MediaPicker/PickerFacadeProvider.js +21 -21
  14. package/dist/cjs/ui/ResizableMediaSingle/index.js +18 -18
  15. package/dist/cjs/ui/toolbar/utils.js +11 -11
  16. package/dist/es2019/nodeviews/mediaNodeView/media.js +12 -0
  17. package/dist/es2019/pm-plugins/ai-generating-decoration.js +53 -12
  18. package/dist/es2019/pm-plugins/commands.js +2 -2
  19. package/dist/es2019/pm-plugins/main.js +11 -1
  20. package/dist/esm/nodeviews/mediaGroupNext.js +12 -12
  21. package/dist/esm/nodeviews/mediaInline.js +25 -25
  22. package/dist/esm/nodeviews/mediaNodeUpdater.js +199 -198
  23. package/dist/esm/nodeviews/mediaNodeView/media.js +28 -16
  24. package/dist/esm/nodeviews/mediaSingleNext.js +23 -23
  25. package/dist/esm/pm-plugins/ai-generating-decoration.js +59 -12
  26. package/dist/esm/pm-plugins/commands.js +2 -2
  27. package/dist/esm/pm-plugins/main.js +54 -45
  28. package/dist/esm/pm-plugins/mediaTaskManager.js +6 -6
  29. package/dist/esm/pm-plugins/picker-facade.js +4 -4
  30. package/dist/esm/pm-plugins/utils/check-media-type.js +17 -17
  31. package/dist/esm/ui/MediaPicker/PickerFacadeProvider.js +21 -21
  32. package/dist/esm/ui/ResizableMediaSingle/index.js +18 -18
  33. package/dist/esm/ui/toolbar/utils.js +11 -11
  34. package/dist/types/mediaPluginType.d.ts +2 -1
  35. package/dist/types/nodeviews/mediaNodeView/media.d.ts +1 -0
  36. package/dist/types/pm-plugins/ai-generating-decoration.d.ts +3 -1
  37. package/dist/types/pm-plugins/commands.d.ts +2 -1
  38. package/dist/types/pm-plugins/main.d.ts +1 -0
  39. package/dist/types/pm-plugins/types.d.ts +1 -0
  40. package/dist/types-ts4.5/mediaPluginType.d.ts +2 -1
  41. package/dist/types-ts4.5/nodeviews/mediaNodeView/media.d.ts +1 -0
  42. package/dist/types-ts4.5/pm-plugins/ai-generating-decoration.d.ts +3 -1
  43. package/dist/types-ts4.5/pm-plugins/commands.d.ts +2 -1
  44. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -0
  45. package/dist/types-ts4.5/pm-plugins/types.d.ts +1 -0
  46. package/package.json +10 -7
@@ -38,12 +38,12 @@ export var MediaNode = /*#__PURE__*/function (_Component) {
38
38
  _defineProperty(_this, "unbindKeyDown", null);
39
39
  _defineProperty(_this, "setViewMediaClientConfig", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
40
40
  var mediaProvider, viewMediaClientConfig, viewAndUploadMediaClientConfig;
41
- return _regeneratorRuntime.wrap(function _callee$(_context) {
41
+ return _regeneratorRuntime.wrap(function (_context) {
42
42
  while (1) switch (_context.prev = _context.next) {
43
43
  case 0:
44
- _context.next = 2;
44
+ _context.next = 1;
45
45
  return _this.props.mediaProvider;
46
- case 2:
46
+ case 1:
47
47
  mediaProvider = _context.sent;
48
48
  if (mediaProvider) {
49
49
  viewMediaClientConfig = mediaProvider.viewMediaClientConfig;
@@ -55,7 +55,7 @@ export var MediaNode = /*#__PURE__*/function (_Component) {
55
55
  });
56
56
  }
57
57
  }
58
- case 4:
58
+ case 2:
59
59
  case "end":
60
60
  return _context.stop();
61
61
  }
@@ -104,6 +104,18 @@ export var MediaNode = /*#__PURE__*/function (_Component) {
104
104
  canUpdateVideoCaptions: fg('platform_media_video_captions') ? !!viewAndUploadMediaClientConfig : false
105
105
  };
106
106
  }));
107
+ _defineProperty(_this, "onPreviewRender", function (fileId) {
108
+ if (fg('aifc_page_create_with_rovo_include_infographics')) {
109
+ var _this$props$pluginInj2;
110
+ (_this$props$pluginInj2 = _this.props.pluginInjectionApi) === null || _this$props$pluginInj2 === void 0 || (_this$props$pluginInj2 = _this$props$pluginInj2.core) === null || _this$props$pluginInj2 === void 0 || _this$props$pluginInj2.actions.execute(function (_ref3) {
111
+ var tr = _ref3.tr;
112
+ return tr.setMeta(mediaStateKey, {
113
+ type: 'PREVIEW_RENDERED',
114
+ fileId: fileId
115
+ });
116
+ });
117
+ }
118
+ });
107
119
  _defineProperty(_this, "onError", function (reason) {
108
120
  var _this$props$api;
109
121
  var nestedUnder = _this.getNestedUnder();
@@ -174,24 +186,23 @@ export var MediaNode = /*#__PURE__*/function (_Component) {
174
186
  key: "componentDidMount",
175
187
  value: function () {
176
188
  var _componentDidMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
177
- var contextIdentifierProvider;
178
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
189
+ var contextIdentifierProvider, _t, _t2;
190
+ return _regeneratorRuntime.wrap(function (_context2) {
179
191
  while (1) switch (_context2.prev = _context2.next) {
180
192
  case 0:
181
193
  this.handleNewNode(this.props);
182
194
  contextIdentifierProvider = this.props.contextIdentifierProvider;
183
- _context2.t0 = this;
184
- _context2.next = 5;
195
+ _t = this;
196
+ _context2.next = 1;
185
197
  return contextIdentifierProvider;
186
- case 5:
187
- _context2.t1 = _context2.sent;
188
- _context2.t2 = {
189
- contextIdentifierProvider: _context2.t1
190
- };
191
- _context2.t0.setState.call(_context2.t0, _context2.t2);
192
- _context2.next = 10;
198
+ case 1:
199
+ _t2 = _context2.sent;
200
+ _t.setState.call(_t, {
201
+ contextIdentifierProvider: _t2
202
+ });
203
+ _context2.next = 2;
193
204
  return this.setViewMediaClientConfig();
194
- case 10:
205
+ case 2:
195
206
  case "end":
196
207
  return _context2.stop();
197
208
  }
@@ -369,6 +380,7 @@ export var MediaNode = /*#__PURE__*/function (_Component) {
369
380
  ssr: ssr,
370
381
  mediaSettings: this.getMediaSettings(viewAndUploadMediaClientConfig),
371
382
  isAIGenerating: !!this.props.isAIGenerating,
383
+ onPreviewRender: this.onPreviewRender,
372
384
  onError: expValEquals('platform_editor_media_error_analytics', 'isEnabled', true) ? this.onError : undefined
373
385
  })));
374
386
  }
@@ -80,63 +80,63 @@ var useMediaNodeUpdater = function useMediaNodeUpdater(_ref) {
80
80
  };
81
81
  var mediaAsyncOperations = /*#__PURE__*/function () {
82
82
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(props) {
83
- var updatedDimensions, currentAttrs, updatingNode, contextId, shouldNodeBeDeepCopied, copyNode;
84
- return _regeneratorRuntime.wrap(function _callee$(_context) {
83
+ var updatedDimensions, currentAttrs, updatingNode, contextId, shouldNodeBeDeepCopied, copyNode, _t;
84
+ return _regeneratorRuntime.wrap(function (_context) {
85
85
  while (1) switch (_context.prev = _context.next) {
86
86
  case 0:
87
- _context.next = 2;
87
+ _context.next = 1;
88
88
  return props.updater.getRemoteDimensions();
89
- case 2:
89
+ case 1:
90
90
  updatedDimensions = _context.sent;
91
91
  currentAttrs = props.mediaChildNode.attrs;
92
92
  if (updatedDimensions && ((currentAttrs === null || currentAttrs === void 0 ? void 0 : currentAttrs.width) !== updatedDimensions.width || (currentAttrs === null || currentAttrs === void 0 ? void 0 : currentAttrs.height) !== updatedDimensions.height)) {
93
93
  props.updater.updateDimensions(updatedDimensions);
94
94
  }
95
95
  if (!(props.mediaChildNode.attrs.type === 'external' && props.mediaChildNode.attrs.__external)) {
96
- _context.next = 11;
96
+ _context.next = 3;
97
97
  break;
98
98
  }
99
99
  updatingNode = props.updater.handleExternalMedia(props.getPos);
100
100
  props.addPendingTask(updatingNode);
101
- _context.next = 10;
101
+ _context.next = 2;
102
102
  return updatingNode;
103
- case 10:
103
+ case 2:
104
104
  return _context.abrupt("return");
105
- case 11:
105
+ case 3:
106
106
  contextId = props.updater.getNodeContextId();
107
107
  if (contextId) {
108
- _context.next = 15;
108
+ _context.next = 4;
109
109
  break;
110
110
  }
111
- _context.next = 15;
111
+ _context.next = 4;
112
112
  return props.updater.updateContextId();
113
- case 15:
114
- _context.next = 17;
113
+ case 4:
114
+ _context.next = 5;
115
115
  return props.updater.shouldNodeBeDeepCopied();
116
- case 17:
116
+ case 5:
117
117
  shouldNodeBeDeepCopied = _context.sent;
118
118
  if (!shouldNodeBeDeepCopied) {
119
- _context.next = 28;
119
+ _context.next = 9;
120
120
  break;
121
121
  }
122
- _context.prev = 19;
122
+ _context.prev = 6;
123
123
  copyNode = props.updater.copyNode({
124
124
  traceId: props.mediaNode.attrs.__mediaTraceId
125
125
  });
126
126
  props.addPendingTask(copyNode);
127
- _context.next = 24;
127
+ _context.next = 7;
128
128
  return copyNode;
129
- case 24:
130
- _context.next = 28;
129
+ case 7:
130
+ _context.next = 9;
131
131
  break;
132
- case 26:
133
- _context.prev = 26;
134
- _context.t0 = _context["catch"](19);
135
- case 28:
132
+ case 8:
133
+ _context.prev = 8;
134
+ _t = _context["catch"](6);
135
+ case 9:
136
136
  case "end":
137
137
  return _context.stop();
138
138
  }
139
- }, _callee, null, [[19, 26]]);
139
+ }, _callee, null, [[6, 8]]);
140
140
  }));
141
141
  return function mediaAsyncOperations(_x) {
142
142
  return _ref2.apply(this, arguments);
@@ -1,4 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
3
  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; }
3
4
  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; }
4
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
@@ -72,10 +73,11 @@ export function hasAIGeneratingDecoration(decorations) {
72
73
  * );
73
74
  * ```
74
75
  */
75
- export function setAIGeneratingMeta(tr, mediaId) {
76
+ export function setAIGeneratingMeta(tr, mediaId, source) {
76
77
  return tr.setMeta(aiGeneratingDecorationPluginKey, {
77
78
  type: 'SET_GENERATING',
78
- mediaId: mediaId
79
+ mediaId: mediaId,
80
+ source: source
79
81
  }).setMeta('addToHistory', false);
80
82
  }
81
83
 
@@ -99,7 +101,7 @@ export function createAIGeneratingDecorationPlugin() {
99
101
  state: {
100
102
  init: function init() {
101
103
  return {
102
- generatingMediaIds: new Set(),
104
+ generatingMediaIds: new Map(),
103
105
  decorationSet: DecorationSet.empty
104
106
  };
105
107
  },
@@ -108,7 +110,7 @@ export function createAIGeneratingDecorationPlugin() {
108
110
  if (!fg('cc-maui-phase-2') || !expValEquals('cc-maui-experiment', 'isEnabled', true)) {
109
111
  if (pluginState.generatingMediaIds.size > 0) {
110
112
  return {
111
- generatingMediaIds: new Set(),
113
+ generatingMediaIds: new Map(),
112
114
  decorationSet: DecorationSet.empty
113
115
  };
114
116
  }
@@ -119,30 +121,76 @@ export function createAIGeneratingDecorationPlugin() {
119
121
  switch (meta.type) {
120
122
  case 'SET_GENERATING':
121
123
  {
122
- var ids = new Set(pluginState.generatingMediaIds);
123
- ids.add(meta.mediaId);
124
+ var _meta$source;
125
+ var ids = new Map(pluginState.generatingMediaIds);
126
+ ids.set(meta.mediaId, (_meta$source = meta.source) !== null && _meta$source !== void 0 ? _meta$source : 'maui');
127
+ var _hasCwrIds = fg('aifc_page_create_with_rovo_include_infographics') && _toConsumableArray(ids.values()).some(function (s) {
128
+ return s === 'cwr';
129
+ });
130
+ var newDecoSet = buildDecorationSet(newState.doc, ids);
131
+ if (_hasCwrIds && newDecoSet.find().length === 0 && ids.size > 0) {
132
+ // CWR fallback — keep existing decorations during transient doc absence
133
+ return {
134
+ generatingMediaIds: ids,
135
+ decorationSet: pluginState.decorationSet
136
+ };
137
+ }
124
138
  return {
125
139
  generatingMediaIds: ids,
126
- decorationSet: buildDecorationSet(newState.doc, ids)
140
+ decorationSet: newDecoSet
127
141
  };
128
142
  }
129
143
  case 'CLEAR_GENERATING':
130
144
  {
131
- var _ids = new Set(pluginState.generatingMediaIds);
145
+ var _ids = new Map(pluginState.generatingMediaIds);
132
146
  _ids.delete(meta.mediaId);
147
+ var _hasCwrIds2 = fg('aifc_page_create_with_rovo_include_infographics') && _toConsumableArray(_ids.values()).some(function (s) {
148
+ return s === 'cwr';
149
+ });
150
+ var _newDecoSet = buildDecorationSet(newState.doc, _ids);
151
+ if (_hasCwrIds2 && _newDecoSet.find().length === 0) {
152
+ // CWR fallback — keep existing decorations during transient doc absence
153
+ return {
154
+ generatingMediaIds: _ids,
155
+ decorationSet: pluginState.decorationSet
156
+ };
157
+ }
133
158
  return {
134
159
  generatingMediaIds: _ids,
135
- decorationSet: buildDecorationSet(newState.doc, _ids)
160
+ decorationSet: _newDecoSet
136
161
  };
137
162
  }
138
163
  case 'CLEAR_ALL':
139
164
  return {
140
- generatingMediaIds: new Set(),
165
+ generatingMediaIds: new Map(),
141
166
  decorationSet: DecorationSet.empty
142
167
  };
143
168
  }
144
169
  }
145
170
 
171
+ // CWR path
172
+ // Rebuild decorations from scratch because CWR streaming replaces the
173
+ // entire document on every chunk and map() drops decorations whose
174
+ // positions can't be mapped.
175
+ var hasCwrIds = fg('aifc_page_create_with_rovo_include_infographics') && _toConsumableArray(pluginState.generatingMediaIds.values()).some(function (s) {
176
+ return s === 'cwr';
177
+ });
178
+ if (tr.docChanged && hasCwrIds) {
179
+ var rebuilt = buildDecorationSet(newState.doc, pluginState.generatingMediaIds);
180
+ var prevCount = pluginState.decorationSet.find().length;
181
+ var newCount = rebuilt.find().length;
182
+
183
+ // Prevents flickering that results from updating during transient
184
+ // doc replacements (when nodes are briefly absent)
185
+ if (newCount !== prevCount && newCount >= pluginState.generatingMediaIds.size) {
186
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
187
+ decorationSet: rebuilt
188
+ });
189
+ }
190
+ return pluginState;
191
+ }
192
+
193
+ // Remix path
146
194
  // Map decorations through document changes so positions stay in sync
147
195
  if (tr.docChanged && pluginState.decorationSet !== DecorationSet.empty) {
148
196
  try {
@@ -150,9 +198,8 @@ export function createAIGeneratingDecorationPlugin() {
150
198
  decorationSet: pluginState.decorationSet.map(tr.mapping, newState.doc)
151
199
  });
152
200
  } catch (_unused) {
153
- // Collaborative editing edge case — reset
154
201
  return {
155
- generatingMediaIds: new Set(),
202
+ generatingMediaIds: new Map(),
156
203
  decorationSet: DecorationSet.empty
157
204
  };
158
205
  }
@@ -42,10 +42,10 @@ export var trackMediaPaste = function trackMediaPaste(attrs) {
42
42
  * Decorations live in the view layer only and never affect the document model
43
43
  * or undo/redo history.
44
44
  */
45
- export var setAIGenerating = function setAIGenerating(mediaId) {
45
+ export var setAIGenerating = function setAIGenerating(mediaId, source) {
46
46
  return function (_ref4) {
47
47
  var tr = _ref4.tr;
48
- return setAIGeneratingMeta(tr, mediaId);
48
+ return setAIGeneratingMeta(tr, mediaId, source);
49
49
  };
50
50
  };
51
51
 
@@ -75,6 +75,7 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
75
75
  _defineProperty(this, "ignoreLinks", false);
76
76
  _defineProperty(this, "waitForMediaUpload", true);
77
77
  _defineProperty(this, "allUploadsFinished", true);
78
+ _defineProperty(this, "previewRenderedMediaIds", new Set());
78
79
  _defineProperty(this, "showDropzone", false);
79
80
  _defineProperty(this, "isFullscreen", false);
80
81
  _defineProperty(this, "layout", 'center');
@@ -706,19 +707,19 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
706
707
  key: "setMediaProvider",
707
708
  value: function () {
708
709
  var _setMediaProvider = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(mediaProvider) {
709
- var viewMediaClientConfig, wrappedError, view, allowsUploads;
710
- return _regeneratorRuntime.wrap(function _callee$(_context) {
710
+ var viewMediaClientConfig, wrappedError, view, allowsUploads, _t;
711
+ return _regeneratorRuntime.wrap(function (_context) {
711
712
  while (1) switch (_context.prev = _context.next) {
712
713
  case 0:
713
714
  if (!(this.previousMediaProvider === mediaProvider)) {
714
- _context.next = 2;
715
+ _context.next = 1;
715
716
  break;
716
717
  }
717
718
  return _context.abrupt("return");
718
- case 2:
719
+ case 1:
719
720
  this.previousMediaProvider = mediaProvider;
720
721
  if (mediaProvider) {
721
- _context.next = 8;
722
+ _context.next = 2;
722
723
  break;
723
724
  }
724
725
  this.destroyPickers();
@@ -729,21 +730,21 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
729
730
  }));
730
731
  }
731
732
  return _context.abrupt("return");
732
- case 8:
733
- _context.prev = 8;
733
+ case 2:
734
+ _context.prev = 2;
734
735
  if (!(mediaProvider instanceof Promise)) {
735
- _context.next = 15;
736
+ _context.next = 4;
736
737
  break;
737
738
  }
738
- _context.next = 12;
739
+ _context.next = 3;
739
740
  return mediaProvider;
740
- case 12:
741
+ case 3:
741
742
  this.mediaProvider = _context.sent;
742
- _context.next = 16;
743
+ _context.next = 5;
743
744
  break;
744
- case 15:
745
+ case 4:
745
746
  this.mediaProvider = mediaProvider;
746
- case 16:
747
+ case 5:
747
748
  // Ignored via go/ees007
748
749
  // eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format
749
750
  // TODO [MS-2038]: remove once context api is removed
@@ -756,12 +757,12 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
756
757
  }
757
758
  }
758
759
  assert(this.mediaProvider.viewMediaClientConfig, "MediaProvider promise did not resolve to a valid instance of MediaProvider - ".concat(this.mediaProvider));
759
- _context.next = 28;
760
+ _context.next = 7;
760
761
  break;
761
- case 20:
762
- _context.prev = 20;
763
- _context.t0 = _context["catch"](8);
764
- wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_context.t0 instanceof Error ? _context.t0.message : String(_context.t0)));
762
+ case 6:
763
+ _context.prev = 6;
764
+ _t = _context["catch"](2);
765
+ wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_t instanceof Error ? _t.message : String(_t)));
765
766
  this.errorReporter.captureException(wrappedError);
766
767
  this.destroyPickers();
767
768
  this.allowsUploads = false;
@@ -771,7 +772,7 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
771
772
  }));
772
773
  }
773
774
  return _context.abrupt("return");
774
- case 28:
775
+ case 7:
775
776
  this.mediaClientConfig = this.mediaProvider.viewMediaClientConfig;
776
777
  this.allowsUploads = !!this.mediaProvider.uploadMediaClientConfig;
777
778
  view = this.view, allowsUploads = this.allowsUploads; // make sure editable DOM node is mounted
@@ -782,31 +783,31 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
782
783
  }));
783
784
  }
784
785
  if (!this.allowsUploads) {
785
- _context.next = 42;
786
+ _context.next = 11;
786
787
  break;
787
788
  }
788
789
  this.uploadMediaClientConfig = this.mediaProvider.uploadMediaClientConfig;
789
790
  if (!(this.mediaProvider.uploadParams && this.uploadMediaClientConfig)) {
790
- _context.next = 39;
791
+ _context.next = 9;
791
792
  break;
792
793
  }
793
- _context.next = 37;
794
+ _context.next = 8;
794
795
  return this.initPickers(this.mediaProvider.uploadParams, PickerFacade);
795
- case 37:
796
- _context.next = 40;
796
+ case 8:
797
+ _context.next = 10;
797
798
  break;
798
- case 39:
799
+ case 9:
799
800
  this.destroyPickers();
800
- case 40:
801
- _context.next = 43;
801
+ case 10:
802
+ _context.next = 12;
802
803
  break;
803
- case 42:
804
+ case 11:
804
805
  this.destroyPickers();
805
- case 43:
806
+ case 12:
806
807
  case "end":
807
808
  return _context.stop();
808
809
  }
809
- }, _callee, this, [[8, 20]]);
810
+ }, _callee, this, [[2, 6]]);
810
811
  }));
811
812
  function setMediaProvider(_x) {
812
813
  return _setMediaProvider.apply(this, arguments);
@@ -924,19 +925,19 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
924
925
  value: function () {
925
926
  var _initPickers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(uploadParams, Picker) {
926
927
  var _this3 = this;
927
- var errorReporter, pickers, pickerPromises, pickerFacadeConfig, customPicker;
928
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
928
+ var errorReporter, pickers, pickerPromises, pickerFacadeConfig, customPicker, _t2;
929
+ return _regeneratorRuntime.wrap(function (_context2) {
929
930
  while (1) switch (_context2.prev = _context2.next) {
930
931
  case 0:
931
932
  if (!(this.destroyed || !this.uploadMediaClientConfig)) {
932
- _context2.next = 2;
933
+ _context2.next = 1;
933
934
  break;
934
935
  }
935
936
  return _context2.abrupt("return");
936
- case 2:
937
+ case 1:
937
938
  errorReporter = this.errorReporter, pickers = this.pickers, pickerPromises = this.pickerPromises; // create pickers if they don't exist, re-use otherwise
938
939
  if (pickers.length) {
939
- _context2.next = 14;
940
+ _context2.next = 4;
940
941
  break;
941
942
  }
942
943
  pickerFacadeConfig = {
@@ -944,27 +945,26 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
944
945
  errorReporter: errorReporter
945
946
  };
946
947
  if (!this.options.customMediaPicker) {
947
- _context2.next = 13;
948
+ _context2.next = 3;
948
949
  break;
949
950
  }
950
951
  customPicker = new Picker('customMediaPicker', pickerFacadeConfig, this.options.customMediaPicker).init();
951
952
  pickerPromises.push(customPicker);
952
- _context2.t0 = pickers;
953
- _context2.next = 11;
953
+ _t2 = pickers;
954
+ _context2.next = 2;
954
955
  return customPicker;
955
- case 11:
956
- _context2.t1 = this.customPicker = _context2.sent;
957
- _context2.t0.push.call(_context2.t0, _context2.t1);
958
- case 13:
956
+ case 2:
957
+ _t2.push.call(_t2, this.customPicker = _context2.sent);
958
+ case 3:
959
959
  pickers.forEach(function (picker) {
960
960
  picker.onNewMedia(_this3.insertFile);
961
961
  });
962
- case 14:
962
+ case 4:
963
963
  // set new upload params for the pickers
964
964
  pickers.forEach(function (picker) {
965
965
  return picker.setUploadParams(uploadParams);
966
966
  });
967
- case 15:
967
+ case 5:
968
968
  case "end":
969
969
  return _context2.stop();
970
970
  }
@@ -1036,7 +1036,7 @@ export var createPlugin = function createPlugin(_schema, options, getIntl, plugi
1036
1036
  nextPluginState = nextPluginState.clone();
1037
1037
  }
1038
1038
  var meta = tr.getMeta(stateKey);
1039
- if (meta) {
1039
+ if (meta && meta.type !== 'PREVIEW_RENDERED') {
1040
1040
  var allowsUploads = meta.allowsUploads;
1041
1041
  pluginState.updateAndDispatch({
1042
1042
  allowsUploads: typeof allowsUploads === 'undefined' ? pluginState.allowsUploads : allowsUploads
@@ -1044,6 +1044,15 @@ export var createPlugin = function createPlugin(_schema, options, getIntl, plugi
1044
1044
  nextPluginState = nextPluginState.clone();
1045
1045
  }
1046
1046
 
1047
+ // Handle preview render notifications — add the file ID to the
1048
+ // previewRenderedMediaIds Set so sharedState subscribers can react.
1049
+ if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'PREVIEW_RENDERED' && typeof meta.fileId === 'string') {
1050
+ var newSet = new Set(pluginState.previewRenderedMediaIds);
1051
+ newSet.add(meta.fileId);
1052
+ pluginState.previewRenderedMediaIds = newSet;
1053
+ nextPluginState = nextPluginState.clone();
1054
+ }
1055
+
1047
1056
  // ACTIONS
1048
1057
  switch (meta === null || meta === void 0 ? void 0 : meta.type) {
1049
1058
  case ACTIONS.SHOW_MEDIA_VIEWER:
@@ -19,15 +19,15 @@ export var MediaTaskManager = /*#__PURE__*/_createClass(function MediaTaskManage
19
19
  _defineProperty(this, "waitForPendingTasks", /*#__PURE__*/function () {
20
20
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(timeout, lastTask) {
21
21
  var chainedPromise, rejectTimeout, timeoutPromise;
22
- return _regeneratorRuntime.wrap(function _callee$(_context) {
22
+ return _regeneratorRuntime.wrap(function (_context) {
23
23
  while (1) switch (_context.prev = _context.next) {
24
24
  case 0:
25
25
  if (!(lastTask && _this.pendingTask === lastTask)) {
26
- _context.next = 2;
26
+ _context.next = 1;
27
27
  break;
28
28
  }
29
29
  return _context.abrupt("return", lastTask);
30
- case 2:
30
+ case 1:
31
31
  chainedPromise = _this.pendingTask.then(function () {
32
32
  return (
33
33
  // Call ourselves to make sure that no new pending tasks have been
@@ -36,11 +36,11 @@ export var MediaTaskManager = /*#__PURE__*/_createClass(function MediaTaskManage
36
36
  );
37
37
  });
38
38
  if (timeout) {
39
- _context.next = 5;
39
+ _context.next = 2;
40
40
  break;
41
41
  }
42
42
  return _context.abrupt("return", chainedPromise);
43
- case 5:
43
+ case 2:
44
44
  timeoutPromise = new Promise(function (_resolve, reject) {
45
45
  rejectTimeout = window.setTimeout(function () {
46
46
  return reject(new Error("Media operations did not finish in ".concat(timeout, " ms")));
@@ -50,7 +50,7 @@ export var MediaTaskManager = /*#__PURE__*/_createClass(function MediaTaskManage
50
50
  clearTimeout(rejectTimeout);
51
51
  return value;
52
52
  })]));
53
- case 7:
53
+ case 3:
54
54
  case "end":
55
55
  return _context.stop();
56
56
  }
@@ -115,24 +115,24 @@ var PickerFacade = /*#__PURE__*/function () {
115
115
  value: function () {
116
116
  var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
117
117
  var picker;
118
- return _regeneratorRuntime.wrap(function _callee$(_context) {
118
+ return _regeneratorRuntime.wrap(function (_context) {
119
119
  while (1) switch (_context.prev = _context.next) {
120
120
  case 0:
121
121
  if (this.pickerType === 'customMediaPicker') {
122
122
  picker = this.picker = this.pickerConfig;
123
123
  }
124
124
  if (picker) {
125
- _context.next = 3;
125
+ _context.next = 1;
126
126
  break;
127
127
  }
128
128
  return _context.abrupt("return", this);
129
- case 3:
129
+ case 1:
130
130
  picker.on('upload-preview-update', this.handleUploadPreviewUpdate);
131
131
  picker.on('upload-end', this.handleReady);
132
132
  picker.on('upload-error', this.handleUploadError);
133
133
  picker.on('mobile-upload-end', this.handleMobileUploadEnd);
134
134
  return _context.abrupt("return", this);
135
- case 8:
135
+ case 2:
136
136
  case "end":
137
137
  return _context.stop();
138
138
  }