@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
@@ -29,7 +29,7 @@ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
29
29
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
30
30
  var _pluginKey = require("../../pm-plugins/plugin-key");
31
31
  var _styles = require("../styles");
32
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
32
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t3 in e) "default" !== _t3 && {}.hasOwnProperty.call(e, _t3) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t3)) && (i.get || i.set) ? o(f, _t3, i) : f[_t3] = e[_t3]); return f; })(e, t); }
33
33
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
34
34
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
35
35
  // This is being used by DropPlaceholder now
@@ -46,12 +46,12 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
46
46
  (0, _defineProperty2.default)(_this, "unbindKeyDown", null);
47
47
  (0, _defineProperty2.default)(_this, "setViewMediaClientConfig", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
48
48
  var mediaProvider, viewMediaClientConfig, viewAndUploadMediaClientConfig;
49
- return _regenerator.default.wrap(function _callee$(_context) {
49
+ return _regenerator.default.wrap(function (_context) {
50
50
  while (1) switch (_context.prev = _context.next) {
51
51
  case 0:
52
- _context.next = 2;
52
+ _context.next = 1;
53
53
  return _this.props.mediaProvider;
54
- case 2:
54
+ case 1:
55
55
  mediaProvider = _context.sent;
56
56
  if (mediaProvider) {
57
57
  viewMediaClientConfig = mediaProvider.viewMediaClientConfig;
@@ -63,7 +63,7 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
63
63
  });
64
64
  }
65
65
  }
66
- case 4:
66
+ case 2:
67
67
  case "end":
68
68
  return _context.stop();
69
69
  }
@@ -112,6 +112,18 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
112
112
  canUpdateVideoCaptions: (0, _platformFeatureFlags.fg)('platform_media_video_captions') ? !!viewAndUploadMediaClientConfig : false
113
113
  };
114
114
  }));
115
+ (0, _defineProperty2.default)(_this, "onPreviewRender", function (fileId) {
116
+ if ((0, _platformFeatureFlags.fg)('aifc_page_create_with_rovo_include_infographics')) {
117
+ var _this$props$pluginInj2;
118
+ (_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) {
119
+ var tr = _ref3.tr;
120
+ return tr.setMeta(_pluginKey.stateKey, {
121
+ type: 'PREVIEW_RENDERED',
122
+ fileId: fileId
123
+ });
124
+ });
125
+ }
126
+ });
115
127
  (0, _defineProperty2.default)(_this, "onError", function (reason) {
116
128
  var _this$props$api;
117
129
  var nestedUnder = _this.getNestedUnder();
@@ -182,24 +194,23 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
182
194
  key: "componentDidMount",
183
195
  value: function () {
184
196
  var _componentDidMount = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
185
- var contextIdentifierProvider;
186
- return _regenerator.default.wrap(function _callee2$(_context2) {
197
+ var contextIdentifierProvider, _t, _t2;
198
+ return _regenerator.default.wrap(function (_context2) {
187
199
  while (1) switch (_context2.prev = _context2.next) {
188
200
  case 0:
189
201
  this.handleNewNode(this.props);
190
202
  contextIdentifierProvider = this.props.contextIdentifierProvider;
191
- _context2.t0 = this;
192
- _context2.next = 5;
203
+ _t = this;
204
+ _context2.next = 1;
193
205
  return contextIdentifierProvider;
194
- case 5:
195
- _context2.t1 = _context2.sent;
196
- _context2.t2 = {
197
- contextIdentifierProvider: _context2.t1
198
- };
199
- _context2.t0.setState.call(_context2.t0, _context2.t2);
200
- _context2.next = 10;
206
+ case 1:
207
+ _t2 = _context2.sent;
208
+ _t.setState.call(_t, {
209
+ contextIdentifierProvider: _t2
210
+ });
211
+ _context2.next = 2;
201
212
  return this.setViewMediaClientConfig();
202
- case 10:
213
+ case 2:
203
214
  case "end":
204
215
  return _context2.stop();
205
216
  }
@@ -377,6 +388,7 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
377
388
  ssr: ssr,
378
389
  mediaSettings: this.getMediaSettings(viewAndUploadMediaClientConfig),
379
390
  isAIGenerating: !!this.props.isAIGenerating,
391
+ onPreviewRender: this.onPreviewRender,
380
392
  onError: (0, _expValEquals.expValEquals)('platform_editor_media_error_analytics', 'isEnabled', true) ? this.onError : undefined
381
393
  })));
382
394
  }
@@ -32,7 +32,7 @@ var _ResizableMediaSingleNext = _interopRequireDefault(require("../ui/ResizableM
32
32
  var _helpers = require("./helpers");
33
33
  var _mediaNodeUpdater = require("./mediaNodeUpdater");
34
34
  var _styles = require("./styles");
35
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
35
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
36
36
  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; }
37
37
  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) { (0, _defineProperty2.default)(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; } /**
38
38
  * @jsxRuntime classic
@@ -86,63 +86,63 @@ var useMediaNodeUpdater = function useMediaNodeUpdater(_ref) {
86
86
  };
87
87
  var mediaAsyncOperations = /*#__PURE__*/function () {
88
88
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(props) {
89
- var updatedDimensions, currentAttrs, updatingNode, contextId, shouldNodeBeDeepCopied, copyNode;
90
- return _regenerator.default.wrap(function _callee$(_context) {
89
+ var updatedDimensions, currentAttrs, updatingNode, contextId, shouldNodeBeDeepCopied, copyNode, _t;
90
+ return _regenerator.default.wrap(function (_context) {
91
91
  while (1) switch (_context.prev = _context.next) {
92
92
  case 0:
93
- _context.next = 2;
93
+ _context.next = 1;
94
94
  return props.updater.getRemoteDimensions();
95
- case 2:
95
+ case 1:
96
96
  updatedDimensions = _context.sent;
97
97
  currentAttrs = props.mediaChildNode.attrs;
98
98
  if (updatedDimensions && ((currentAttrs === null || currentAttrs === void 0 ? void 0 : currentAttrs.width) !== updatedDimensions.width || (currentAttrs === null || currentAttrs === void 0 ? void 0 : currentAttrs.height) !== updatedDimensions.height)) {
99
99
  props.updater.updateDimensions(updatedDimensions);
100
100
  }
101
101
  if (!(props.mediaChildNode.attrs.type === 'external' && props.mediaChildNode.attrs.__external)) {
102
- _context.next = 11;
102
+ _context.next = 3;
103
103
  break;
104
104
  }
105
105
  updatingNode = props.updater.handleExternalMedia(props.getPos);
106
106
  props.addPendingTask(updatingNode);
107
- _context.next = 10;
107
+ _context.next = 2;
108
108
  return updatingNode;
109
- case 10:
109
+ case 2:
110
110
  return _context.abrupt("return");
111
- case 11:
111
+ case 3:
112
112
  contextId = props.updater.getNodeContextId();
113
113
  if (contextId) {
114
- _context.next = 15;
114
+ _context.next = 4;
115
115
  break;
116
116
  }
117
- _context.next = 15;
117
+ _context.next = 4;
118
118
  return props.updater.updateContextId();
119
- case 15:
120
- _context.next = 17;
119
+ case 4:
120
+ _context.next = 5;
121
121
  return props.updater.shouldNodeBeDeepCopied();
122
- case 17:
122
+ case 5:
123
123
  shouldNodeBeDeepCopied = _context.sent;
124
124
  if (!shouldNodeBeDeepCopied) {
125
- _context.next = 28;
125
+ _context.next = 9;
126
126
  break;
127
127
  }
128
- _context.prev = 19;
128
+ _context.prev = 6;
129
129
  copyNode = props.updater.copyNode({
130
130
  traceId: props.mediaNode.attrs.__mediaTraceId
131
131
  });
132
132
  props.addPendingTask(copyNode);
133
- _context.next = 24;
133
+ _context.next = 7;
134
134
  return copyNode;
135
- case 24:
136
- _context.next = 28;
135
+ case 7:
136
+ _context.next = 9;
137
137
  break;
138
- case 26:
139
- _context.prev = 26;
140
- _context.t0 = _context["catch"](19);
141
- case 28:
138
+ case 8:
139
+ _context.prev = 8;
140
+ _t = _context["catch"](6);
141
+ case 9:
142
142
  case "end":
143
143
  return _context.stop();
144
144
  }
145
- }, _callee, null, [[19, 26]]);
145
+ }, _callee, null, [[6, 8]]);
146
146
  }));
147
147
  return function mediaAsyncOperations(_x) {
148
148
  return _ref2.apply(this, arguments);
@@ -10,6 +10,7 @@ exports.createAIGeneratingDecorationPlugin = createAIGeneratingDecorationPlugin;
10
10
  exports.hasAIGeneratingDecoration = hasAIGeneratingDecoration;
11
11
  exports.setAIGeneratingMeta = setAIGeneratingMeta;
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
14
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
14
15
  var _state = require("@atlaskit/editor-prosemirror/state");
15
16
  var _view = require("@atlaskit/editor-prosemirror/view");
@@ -82,10 +83,11 @@ function hasAIGeneratingDecoration(decorations) {
82
83
  * );
83
84
  * ```
84
85
  */
85
- function setAIGeneratingMeta(tr, mediaId) {
86
+ function setAIGeneratingMeta(tr, mediaId, source) {
86
87
  return tr.setMeta(aiGeneratingDecorationPluginKey, {
87
88
  type: 'SET_GENERATING',
88
- mediaId: mediaId
89
+ mediaId: mediaId,
90
+ source: source
89
91
  }).setMeta('addToHistory', false);
90
92
  }
91
93
 
@@ -109,7 +111,7 @@ function createAIGeneratingDecorationPlugin() {
109
111
  state: {
110
112
  init: function init() {
111
113
  return {
112
- generatingMediaIds: new Set(),
114
+ generatingMediaIds: new Map(),
113
115
  decorationSet: _view.DecorationSet.empty
114
116
  };
115
117
  },
@@ -118,7 +120,7 @@ function createAIGeneratingDecorationPlugin() {
118
120
  if (!(0, _platformFeatureFlags.fg)('cc-maui-phase-2') || !(0, _expValEquals.expValEquals)('cc-maui-experiment', 'isEnabled', true)) {
119
121
  if (pluginState.generatingMediaIds.size > 0) {
120
122
  return {
121
- generatingMediaIds: new Set(),
123
+ generatingMediaIds: new Map(),
122
124
  decorationSet: _view.DecorationSet.empty
123
125
  };
124
126
  }
@@ -129,30 +131,76 @@ function createAIGeneratingDecorationPlugin() {
129
131
  switch (meta.type) {
130
132
  case 'SET_GENERATING':
131
133
  {
132
- var ids = new Set(pluginState.generatingMediaIds);
133
- ids.add(meta.mediaId);
134
+ var _meta$source;
135
+ var ids = new Map(pluginState.generatingMediaIds);
136
+ ids.set(meta.mediaId, (_meta$source = meta.source) !== null && _meta$source !== void 0 ? _meta$source : 'maui');
137
+ var _hasCwrIds = (0, _platformFeatureFlags.fg)('aifc_page_create_with_rovo_include_infographics') && (0, _toConsumableArray2.default)(ids.values()).some(function (s) {
138
+ return s === 'cwr';
139
+ });
140
+ var newDecoSet = buildDecorationSet(newState.doc, ids);
141
+ if (_hasCwrIds && newDecoSet.find().length === 0 && ids.size > 0) {
142
+ // CWR fallback — keep existing decorations during transient doc absence
143
+ return {
144
+ generatingMediaIds: ids,
145
+ decorationSet: pluginState.decorationSet
146
+ };
147
+ }
134
148
  return {
135
149
  generatingMediaIds: ids,
136
- decorationSet: buildDecorationSet(newState.doc, ids)
150
+ decorationSet: newDecoSet
137
151
  };
138
152
  }
139
153
  case 'CLEAR_GENERATING':
140
154
  {
141
- var _ids = new Set(pluginState.generatingMediaIds);
155
+ var _ids = new Map(pluginState.generatingMediaIds);
142
156
  _ids.delete(meta.mediaId);
157
+ var _hasCwrIds2 = (0, _platformFeatureFlags.fg)('aifc_page_create_with_rovo_include_infographics') && (0, _toConsumableArray2.default)(_ids.values()).some(function (s) {
158
+ return s === 'cwr';
159
+ });
160
+ var _newDecoSet = buildDecorationSet(newState.doc, _ids);
161
+ if (_hasCwrIds2 && _newDecoSet.find().length === 0) {
162
+ // CWR fallback — keep existing decorations during transient doc absence
163
+ return {
164
+ generatingMediaIds: _ids,
165
+ decorationSet: pluginState.decorationSet
166
+ };
167
+ }
143
168
  return {
144
169
  generatingMediaIds: _ids,
145
- decorationSet: buildDecorationSet(newState.doc, _ids)
170
+ decorationSet: _newDecoSet
146
171
  };
147
172
  }
148
173
  case 'CLEAR_ALL':
149
174
  return {
150
- generatingMediaIds: new Set(),
175
+ generatingMediaIds: new Map(),
151
176
  decorationSet: _view.DecorationSet.empty
152
177
  };
153
178
  }
154
179
  }
155
180
 
181
+ // CWR path
182
+ // Rebuild decorations from scratch because CWR streaming replaces the
183
+ // entire document on every chunk and map() drops decorations whose
184
+ // positions can't be mapped.
185
+ var hasCwrIds = (0, _platformFeatureFlags.fg)('aifc_page_create_with_rovo_include_infographics') && (0, _toConsumableArray2.default)(pluginState.generatingMediaIds.values()).some(function (s) {
186
+ return s === 'cwr';
187
+ });
188
+ if (tr.docChanged && hasCwrIds) {
189
+ var rebuilt = buildDecorationSet(newState.doc, pluginState.generatingMediaIds);
190
+ var prevCount = pluginState.decorationSet.find().length;
191
+ var newCount = rebuilt.find().length;
192
+
193
+ // Prevents flickering that results from updating during transient
194
+ // doc replacements (when nodes are briefly absent)
195
+ if (newCount !== prevCount && newCount >= pluginState.generatingMediaIds.size) {
196
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
197
+ decorationSet: rebuilt
198
+ });
199
+ }
200
+ return pluginState;
201
+ }
202
+
203
+ // Remix path
156
204
  // Map decorations through document changes so positions stay in sync
157
205
  if (tr.docChanged && pluginState.decorationSet !== _view.DecorationSet.empty) {
158
206
  try {
@@ -160,9 +208,8 @@ function createAIGeneratingDecorationPlugin() {
160
208
  decorationSet: pluginState.decorationSet.map(tr.mapping, newState.doc)
161
209
  });
162
210
  } catch (_unused) {
163
- // Collaborative editing edge case — reset
164
211
  return {
165
- generatingMediaIds: new Set(),
212
+ generatingMediaIds: new Map(),
166
213
  decorationSet: _view.DecorationSet.empty
167
214
  };
168
215
  }
@@ -48,10 +48,10 @@ var trackMediaPaste = exports.trackMediaPaste = function trackMediaPaste(attrs)
48
48
  * Decorations live in the view layer only and never affect the document model
49
49
  * or undo/redo history.
50
50
  */
51
- var setAIGenerating = exports.setAIGenerating = function setAIGenerating(mediaId) {
51
+ var setAIGenerating = exports.setAIGenerating = function setAIGenerating(mediaId, source) {
52
52
  return function (_ref4) {
53
53
  var tr = _ref4.tr;
54
- return (0, _aiGeneratingDecoration.setAIGeneratingMeta)(tr, mediaId);
54
+ return (0, _aiGeneratingDecoration.setAIGeneratingMeta)(tr, mediaId, source);
55
55
  };
56
56
  };
57
57
 
@@ -42,7 +42,7 @@ var _actions = require("./actions");
42
42
  var _mediaTaskManager = require("./mediaTaskManager");
43
43
  var _pickerFacade = _interopRequireDefault(require("./picker-facade"));
44
44
  var _pluginKey = require("./plugin-key");
45
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
45
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t3 in e) "default" !== _t3 && {}.hasOwnProperty.call(e, _t3) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t3)) && (i.get || i.set) ? o(f, _t3, i) : f[_t3] = e[_t3]); return f; })(e, t); }
46
46
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
47
47
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
48
48
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
@@ -83,6 +83,7 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
83
83
  (0, _defineProperty2.default)(this, "ignoreLinks", false);
84
84
  (0, _defineProperty2.default)(this, "waitForMediaUpload", true);
85
85
  (0, _defineProperty2.default)(this, "allUploadsFinished", true);
86
+ (0, _defineProperty2.default)(this, "previewRenderedMediaIds", new Set());
86
87
  (0, _defineProperty2.default)(this, "showDropzone", false);
87
88
  (0, _defineProperty2.default)(this, "isFullscreen", false);
88
89
  (0, _defineProperty2.default)(this, "layout", 'center');
@@ -714,19 +715,19 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
714
715
  key: "setMediaProvider",
715
716
  value: function () {
716
717
  var _setMediaProvider = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(mediaProvider) {
717
- var viewMediaClientConfig, wrappedError, view, allowsUploads;
718
- return _regenerator.default.wrap(function _callee$(_context) {
718
+ var viewMediaClientConfig, wrappedError, view, allowsUploads, _t;
719
+ return _regenerator.default.wrap(function (_context) {
719
720
  while (1) switch (_context.prev = _context.next) {
720
721
  case 0:
721
722
  if (!(this.previousMediaProvider === mediaProvider)) {
722
- _context.next = 2;
723
+ _context.next = 1;
723
724
  break;
724
725
  }
725
726
  return _context.abrupt("return");
726
- case 2:
727
+ case 1:
727
728
  this.previousMediaProvider = mediaProvider;
728
729
  if (mediaProvider) {
729
- _context.next = 8;
730
+ _context.next = 2;
730
731
  break;
731
732
  }
732
733
  this.destroyPickers();
@@ -737,21 +738,21 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
737
738
  }));
738
739
  }
739
740
  return _context.abrupt("return");
740
- case 8:
741
- _context.prev = 8;
741
+ case 2:
742
+ _context.prev = 2;
742
743
  if (!(mediaProvider instanceof Promise)) {
743
- _context.next = 15;
744
+ _context.next = 4;
744
745
  break;
745
746
  }
746
- _context.next = 12;
747
+ _context.next = 3;
747
748
  return mediaProvider;
748
- case 12:
749
+ case 3:
749
750
  this.mediaProvider = _context.sent;
750
- _context.next = 16;
751
+ _context.next = 5;
751
752
  break;
752
- case 15:
753
+ case 4:
753
754
  this.mediaProvider = mediaProvider;
754
- case 16:
755
+ case 5:
755
756
  // Ignored via go/ees007
756
757
  // eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format
757
758
  // TODO [MS-2038]: remove once context api is removed
@@ -764,12 +765,12 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
764
765
  }
765
766
  }
766
767
  (0, _assert.default)(this.mediaProvider.viewMediaClientConfig, "MediaProvider promise did not resolve to a valid instance of MediaProvider - ".concat(this.mediaProvider));
767
- _context.next = 28;
768
+ _context.next = 7;
768
769
  break;
769
- case 20:
770
- _context.prev = 20;
771
- _context.t0 = _context["catch"](8);
772
- wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_context.t0 instanceof Error ? _context.t0.message : String(_context.t0)));
770
+ case 6:
771
+ _context.prev = 6;
772
+ _t = _context["catch"](2);
773
+ wrappedError = new Error("Media functionality disabled due to rejected provider: ".concat(_t instanceof Error ? _t.message : String(_t)));
773
774
  this.errorReporter.captureException(wrappedError);
774
775
  this.destroyPickers();
775
776
  this.allowsUploads = false;
@@ -779,7 +780,7 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
779
780
  }));
780
781
  }
781
782
  return _context.abrupt("return");
782
- case 28:
783
+ case 7:
783
784
  this.mediaClientConfig = this.mediaProvider.viewMediaClientConfig;
784
785
  this.allowsUploads = !!this.mediaProvider.uploadMediaClientConfig;
785
786
  view = this.view, allowsUploads = this.allowsUploads; // make sure editable DOM node is mounted
@@ -790,31 +791,31 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
790
791
  }));
791
792
  }
792
793
  if (!this.allowsUploads) {
793
- _context.next = 42;
794
+ _context.next = 11;
794
795
  break;
795
796
  }
796
797
  this.uploadMediaClientConfig = this.mediaProvider.uploadMediaClientConfig;
797
798
  if (!(this.mediaProvider.uploadParams && this.uploadMediaClientConfig)) {
798
- _context.next = 39;
799
+ _context.next = 9;
799
800
  break;
800
801
  }
801
- _context.next = 37;
802
+ _context.next = 8;
802
803
  return this.initPickers(this.mediaProvider.uploadParams, _pickerFacade.default);
803
- case 37:
804
- _context.next = 40;
804
+ case 8:
805
+ _context.next = 10;
805
806
  break;
806
- case 39:
807
+ case 9:
807
808
  this.destroyPickers();
808
- case 40:
809
- _context.next = 43;
809
+ case 10:
810
+ _context.next = 12;
810
811
  break;
811
- case 42:
812
+ case 11:
812
813
  this.destroyPickers();
813
- case 43:
814
+ case 12:
814
815
  case "end":
815
816
  return _context.stop();
816
817
  }
817
- }, _callee, this, [[8, 20]]);
818
+ }, _callee, this, [[2, 6]]);
818
819
  }));
819
820
  function setMediaProvider(_x) {
820
821
  return _setMediaProvider.apply(this, arguments);
@@ -932,19 +933,19 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
932
933
  value: function () {
933
934
  var _initPickers = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(uploadParams, Picker) {
934
935
  var _this3 = this;
935
- var errorReporter, pickers, pickerPromises, pickerFacadeConfig, customPicker;
936
- return _regenerator.default.wrap(function _callee2$(_context2) {
936
+ var errorReporter, pickers, pickerPromises, pickerFacadeConfig, customPicker, _t2;
937
+ return _regenerator.default.wrap(function (_context2) {
937
938
  while (1) switch (_context2.prev = _context2.next) {
938
939
  case 0:
939
940
  if (!(this.destroyed || !this.uploadMediaClientConfig)) {
940
- _context2.next = 2;
941
+ _context2.next = 1;
941
942
  break;
942
943
  }
943
944
  return _context2.abrupt("return");
944
- case 2:
945
+ case 1:
945
946
  errorReporter = this.errorReporter, pickers = this.pickers, pickerPromises = this.pickerPromises; // create pickers if they don't exist, re-use otherwise
946
947
  if (pickers.length) {
947
- _context2.next = 14;
948
+ _context2.next = 4;
948
949
  break;
949
950
  }
950
951
  pickerFacadeConfig = {
@@ -952,27 +953,26 @@ var MediaPluginStateImplementation = exports.MediaPluginStateImplementation = /*
952
953
  errorReporter: errorReporter
953
954
  };
954
955
  if (!this.options.customMediaPicker) {
955
- _context2.next = 13;
956
+ _context2.next = 3;
956
957
  break;
957
958
  }
958
959
  customPicker = new Picker('customMediaPicker', pickerFacadeConfig, this.options.customMediaPicker).init();
959
960
  pickerPromises.push(customPicker);
960
- _context2.t0 = pickers;
961
- _context2.next = 11;
961
+ _t2 = pickers;
962
+ _context2.next = 2;
962
963
  return customPicker;
963
- case 11:
964
- _context2.t1 = this.customPicker = _context2.sent;
965
- _context2.t0.push.call(_context2.t0, _context2.t1);
966
- case 13:
964
+ case 2:
965
+ _t2.push.call(_t2, this.customPicker = _context2.sent);
966
+ case 3:
967
967
  pickers.forEach(function (picker) {
968
968
  picker.onNewMedia(_this3.insertFile);
969
969
  });
970
- case 14:
970
+ case 4:
971
971
  // set new upload params for the pickers
972
972
  pickers.forEach(function (picker) {
973
973
  return picker.setUploadParams(uploadParams);
974
974
  });
975
- case 15:
975
+ case 5:
976
976
  case "end":
977
977
  return _context2.stop();
978
978
  }
@@ -1044,7 +1044,7 @@ var createPlugin = exports.createPlugin = function createPlugin(_schema, options
1044
1044
  nextPluginState = nextPluginState.clone();
1045
1045
  }
1046
1046
  var meta = tr.getMeta(_pluginKey.stateKey);
1047
- if (meta) {
1047
+ if (meta && meta.type !== 'PREVIEW_RENDERED') {
1048
1048
  var allowsUploads = meta.allowsUploads;
1049
1049
  pluginState.updateAndDispatch({
1050
1050
  allowsUploads: typeof allowsUploads === 'undefined' ? pluginState.allowsUploads : allowsUploads
@@ -1052,6 +1052,15 @@ var createPlugin = exports.createPlugin = function createPlugin(_schema, options
1052
1052
  nextPluginState = nextPluginState.clone();
1053
1053
  }
1054
1054
 
1055
+ // Handle preview render notifications — add the file ID to the
1056
+ // previewRenderedMediaIds Set so sharedState subscribers can react.
1057
+ if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'PREVIEW_RENDERED' && typeof meta.fileId === 'string') {
1058
+ var newSet = new Set(pluginState.previewRenderedMediaIds);
1059
+ newSet.add(meta.fileId);
1060
+ pluginState.previewRenderedMediaIds = newSet;
1061
+ nextPluginState = nextPluginState.clone();
1062
+ }
1063
+
1055
1064
  // ACTIONS
1056
1065
  switch (meta === null || meta === void 0 ? void 0 : meta.type) {
1057
1066
  case _actions.ACTIONS.SHOW_MEDIA_VIEWER:
@@ -26,15 +26,15 @@ var MediaTaskManager = exports.MediaTaskManager = /*#__PURE__*/(0, _createClass2
26
26
  (0, _defineProperty2.default)(this, "waitForPendingTasks", /*#__PURE__*/function () {
27
27
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(timeout, lastTask) {
28
28
  var chainedPromise, rejectTimeout, timeoutPromise;
29
- return _regenerator.default.wrap(function _callee$(_context) {
29
+ return _regenerator.default.wrap(function (_context) {
30
30
  while (1) switch (_context.prev = _context.next) {
31
31
  case 0:
32
32
  if (!(lastTask && _this.pendingTask === lastTask)) {
33
- _context.next = 2;
33
+ _context.next = 1;
34
34
  break;
35
35
  }
36
36
  return _context.abrupt("return", lastTask);
37
- case 2:
37
+ case 1:
38
38
  chainedPromise = _this.pendingTask.then(function () {
39
39
  return (
40
40
  // Call ourselves to make sure that no new pending tasks have been
@@ -43,11 +43,11 @@ var MediaTaskManager = exports.MediaTaskManager = /*#__PURE__*/(0, _createClass2
43
43
  );
44
44
  });
45
45
  if (timeout) {
46
- _context.next = 5;
46
+ _context.next = 2;
47
47
  break;
48
48
  }
49
49
  return _context.abrupt("return", chainedPromise);
50
- case 5:
50
+ case 2:
51
51
  timeoutPromise = new Promise(function (_resolve, reject) {
52
52
  rejectTimeout = window.setTimeout(function () {
53
53
  return reject(new Error("Media operations did not finish in ".concat(timeout, " ms")));
@@ -57,7 +57,7 @@ var MediaTaskManager = exports.MediaTaskManager = /*#__PURE__*/(0, _createClass2
57
57
  clearTimeout(rejectTimeout);
58
58
  return value;
59
59
  })]));
60
- case 7:
60
+ case 3:
61
61
  case "end":
62
62
  return _context.stop();
63
63
  }
@@ -122,24 +122,24 @@ var PickerFacade = exports.default = /*#__PURE__*/function () {
122
122
  value: function () {
123
123
  var _init = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
124
124
  var picker;
125
- return _regenerator.default.wrap(function _callee$(_context) {
125
+ return _regenerator.default.wrap(function (_context) {
126
126
  while (1) switch (_context.prev = _context.next) {
127
127
  case 0:
128
128
  if (this.pickerType === 'customMediaPicker') {
129
129
  picker = this.picker = this.pickerConfig;
130
130
  }
131
131
  if (picker) {
132
- _context.next = 3;
132
+ _context.next = 1;
133
133
  break;
134
134
  }
135
135
  return _context.abrupt("return", this);
136
- case 3:
136
+ case 1:
137
137
  picker.on('upload-preview-update', this.handleUploadPreviewUpdate);
138
138
  picker.on('upload-end', this.handleReady);
139
139
  picker.on('upload-error', this.handleUploadError);
140
140
  picker.on('mobile-upload-end', this.handleMobileUploadEnd);
141
141
  return _context.abrupt("return", this);
142
- case 8:
142
+ case 2:
143
143
  case "end":
144
144
  return _context.stop();
145
145
  }