@atlaskit/editor-plugin-media 20.0.4 → 20.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/editor-plugin-media
2
2
 
3
+ ## 20.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`2d026706450c6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2d026706450c6) -
8
+ Add the `allowAIGeneratedMediaMotion` media plugin option and the `hasLoadingMotion` card prop, so
9
+ media that arrives mid-flight opens the document out to make room for itself and then fades its
10
+ preview in, instead of drawing a loading indicator and snapping into place. Behind
11
+ `aifc_page_create_defer_generated_visuals`.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 20.0.4
4
18
 
5
19
  ### Patch Changes
@@ -28,10 +28,13 @@ var _mediaCard = require("@atlaskit/media-card");
28
28
  var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
29
29
  var _fg = require("@atlaskit/platform-feature-flags/fg");
30
30
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
31
+ var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
31
32
  var _editorExperiment = require("@atlaskit/tmp-editor-statsig/editor-experiment");
32
33
  var _pluginKey = require("../../pm-plugins/plugin-key");
34
+ var _GeneratedMediaReveal = require("../../ui/GeneratedMediaReveal");
35
+ var _mediaNodeUpdater = require("../mediaNodeUpdater");
33
36
  var _styles = require("../styles");
34
- 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); }
37
+ 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 _t4 in e) "default" !== _t4 && {}.hasOwnProperty.call(e, _t4) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t4)) && (i.get || i.set) ? o(f, _t4, i) : f[_t4] = e[_t4]); return f; })(e, t); }
35
38
  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; }
36
39
  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; }
37
40
  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)); }
@@ -138,15 +141,73 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
138
141
  canUpdateVideoCaptions: (0, _fg.fg)('platform_media_video_captions') ? !!viewAndUploadMediaClientConfig && !isViewOnly : false
139
142
  };
140
143
  }));
144
+ /**
145
+ * Media written straight into the document arrives without intrinsic dimensions, and the
146
+ * fetch that would supply them resolves `false` while the file is still processing. Only
147
+ * editor-driven uploads get a second attempt, from the plugin's media-state listener, so
148
+ * otherwise the card would keep its placeholder ratio forever. The preview rendering is the
149
+ * one moment the file is guaranteed ready, so the fetch is retried there.
150
+ */
151
+ (0, _defineProperty2.default)(_this, "fetchMissingDimensions", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
152
+ var _pluginInjectionApi$w;
153
+ var _this$props, node, view, mediaProvider, contextIdentifierProvider, mediaOptions, pluginInjectionApi, updater, dimensions, _t;
154
+ return _regenerator.default.wrap(function (_context2) {
155
+ while (1) switch (_context2.prev = _context2.next) {
156
+ case 0:
157
+ _this$props = _this.props, node = _this$props.node, view = _this$props.view, mediaProvider = _this$props.mediaProvider, contextIdentifierProvider = _this$props.contextIdentifierProvider, mediaOptions = _this$props.mediaOptions, pluginInjectionApi = _this$props.pluginInjectionApi;
158
+ if (!(node.attrs.type === 'external' || !node.attrs.id || node.attrs.width && node.attrs.height)) {
159
+ _context2.next = 1;
160
+ break;
161
+ }
162
+ return _context2.abrupt("return");
163
+ case 1:
164
+ updater = (0, _mediaNodeUpdater.createMediaNodeUpdater)({
165
+ view: view,
166
+ mediaProvider: mediaProvider,
167
+ contextIdentifierProvider: contextIdentifierProvider,
168
+ node: node,
169
+ // Carries `allowRemoteDimensionsFetch`, so surfaces that cannot reach the media
170
+ // APIs get the default dimensions back instead of a request.
171
+ mediaOptions: mediaOptions,
172
+ isMediaSingle: true,
173
+ lineLength: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$w = pluginInjectionApi.width) === null || _pluginInjectionApi$w === void 0 || (_pluginInjectionApi$w = _pluginInjectionApi$w.sharedState.currentState()) === null || _pluginInjectionApi$w === void 0 ? void 0 : _pluginInjectionApi$w.lineLength
174
+ });
175
+ _context2.prev = 2;
176
+ _context2.next = 3;
177
+ return updater.getRemoteDimensions();
178
+ case 3:
179
+ dimensions = _context2.sent;
180
+ if (dimensions) {
181
+ updater.updateDimensions(dimensions);
182
+ }
183
+ _context2.next = 5;
184
+ break;
185
+ case 4:
186
+ _context2.prev = 4;
187
+ _t = _context2["catch"](2);
188
+ case 5:
189
+ case "end":
190
+ return _context2.stop();
191
+ }
192
+ }, _callee2, null, [[2, 4]]);
193
+ })));
141
194
  (0, _defineProperty2.default)(_this, "onPreviewRender", function (fileId) {
142
195
  _this.emitMediaRenderEvent({
143
196
  renderedMediaId: fileId,
144
197
  type: 'preview-rendered'
145
198
  });
199
+ // Only tracked where the reveal uses it. Every media card in every editor calls this,
200
+ // and the extra render it would otherwise trigger is not free.
201
+ if (_this.hasGeneratedMediaMotion && _this.state.previewRenderedFileId !== fileId) {
202
+ _this.setState({
203
+ previewRenderedFileId: fileId
204
+ });
205
+ _this.fetchMissingDimensions();
206
+ }
146
207
  if ((0, _isExperimentEnabled.isExperimentEnabled)('aifc_page_create_with_rovo_include_infographics')) {
147
208
  var _this$props$pluginInj2;
148
- (_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) {
149
- var tr = _ref3.tr;
209
+ (_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 (_ref4) {
210
+ var tr = _ref4.tr;
150
211
  return tr.setMeta(_pluginKey.stateKey, {
151
212
  type: 'PREVIEW_RENDERED',
152
213
  fileId: fileId
@@ -156,10 +217,22 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
156
217
  });
157
218
  (0, _defineProperty2.default)(_this, "onError", function (reason) {
158
219
  var _this$props$api;
220
+ // The card is already showing its error treatment, so let the reveal open onto
221
+ // that instead of waiting out its timeout.
222
+ _this.setState({
223
+ failedFileId: _this.props.node.attrs.id
224
+ });
159
225
  _this.emitMediaRenderEvent({
160
226
  reason: reason,
161
227
  type: 'error'
162
228
  });
229
+
230
+ // `getMediaRenderErrorHandler` also wires this for surfaces the analytics
231
+ // experiment does not cover, so re-read without exposure — the render-time read
232
+ // owns that — to keep the dispatch inside the experiment's own cohort.
233
+ if (!(0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_media_error_analytics', 'isEnabled', true)) {
234
+ return;
235
+ }
163
236
  var nestedUnder = _this.getNestedUnder();
164
237
  (_this$props$api = _this.props.api) === null || _this$props$api === void 0 || _this$props$api.media.actions.handleMediaNodeRenderError(_this.props.node, reason, nestedUnder);
165
238
  });
@@ -174,6 +247,12 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
174
247
  if ((0, _expValEquals.expValEquals)('platform_editor_media_error_analytics', 'isEnabled', true)) {
175
248
  return _this.onError;
176
249
  }
250
+ // The reveal needs terminal errors too, so it can open onto the card's error treatment
251
+ // rather than waiting out its timeout. `onError` keeps the analytics dispatch itself
252
+ // inside the experiment's cohort.
253
+ if (_this.hasGeneratedMediaMotion) {
254
+ return _this.onError;
255
+ }
177
256
  return (_this$props$mediaOpti = _this.props.mediaOptions) !== null && _this$props$mediaOpti !== void 0 && _this$props$mediaOpti.onMediaRenderEvent ? _this.onRemixRenderError : undefined;
178
257
  });
179
258
  /**
@@ -212,10 +291,10 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
212
291
  return _this.props.getPos();
213
292
  });
214
293
  });
215
- var _this$props = _this.props,
216
- view = _this$props.view,
217
- syncProvider = _this$props.syncProvider;
218
- _this.mediaPluginState = _pluginKey.stateKey.getState(view.state);
294
+ var _this$props2 = _this.props,
295
+ _view = _this$props2.view,
296
+ syncProvider = _this$props2.syncProvider;
297
+ _this.mediaPluginState = _pluginKey.stateKey.getState(_view.state);
219
298
 
220
299
  // Initialize state from syncProvider (available on both server and client for SSR)
221
300
  if (syncProvider) {
@@ -233,7 +312,9 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
233
312
  var _this$props$mediaOpti2, _nextProps$mediaOptio;
234
313
  var hasNewViewMediaClientConfig = !this.state.viewMediaClientConfig && nextState.viewMediaClientConfig;
235
314
  var hasNewViewAndUploadMediaClientConfig = !this.state.viewAndUploadMediaClientConfig && nextState.viewAndUploadMediaClientConfig;
236
- if (this.props.selected !== nextProps.selected || this.props.node.attrs.id !== nextProps.node.attrs.id || this.props.node.attrs.collection !== nextProps.node.attrs.collection || this.props.isAIGenerating !== nextProps.isAIGenerating || this.props.isCwrAIGenerating !== nextProps.isCwrAIGenerating || this.props.maxDimensions.height !== nextProps.maxDimensions.height || this.props.maxDimensions.width !== nextProps.maxDimensions.width || this.props.contextIdentifierProvider !== nextProps.contextIdentifierProvider || this.props.isLoading !== nextProps.isLoading || this.props.isViewOnly !== nextProps.isViewOnly || this.props.mediaProvider !== nextProps.mediaProvider || this.props.syncProvider !== nextProps.syncProvider || this.getDataConsumerSource() !== this.getDataConsumerSource(nextProps) || ((_this$props$mediaOpti2 = this.props.mediaOptions) === null || _this$props$mediaOpti2 === void 0 ? void 0 : _this$props$mediaOpti2.onMediaRenderEvent) !== ((_nextProps$mediaOptio = nextProps.mediaOptions) === null || _nextProps$mediaOptio === void 0 ? void 0 : _nextProps$mediaOptio.onMediaRenderEvent) || hasNewViewMediaClientConfig || hasNewViewAndUploadMediaClientConfig) {
315
+ if (this.props.selected !== nextProps.selected || this.props.node.attrs.id !== nextProps.node.attrs.id || this.props.node.attrs.collection !== nextProps.node.attrs.collection ||
316
+ // Patched in asynchronously once media services report the real size.
317
+ this.props.node.attrs.width !== nextProps.node.attrs.width || this.props.node.attrs.height !== nextProps.node.attrs.height || this.props.isAIGenerating !== nextProps.isAIGenerating || this.props.isCwrAIGenerating !== nextProps.isCwrAIGenerating || this.props.maxDimensions.height !== nextProps.maxDimensions.height || this.props.maxDimensions.width !== nextProps.maxDimensions.width || this.props.contextIdentifierProvider !== nextProps.contextIdentifierProvider || this.props.isLoading !== nextProps.isLoading || this.props.isViewOnly !== nextProps.isViewOnly || this.props.mediaProvider !== nextProps.mediaProvider || this.props.syncProvider !== nextProps.syncProvider || this.getDataConsumerSource() !== this.getDataConsumerSource(nextProps) || ((_this$props$mediaOpti2 = this.props.mediaOptions) === null || _this$props$mediaOpti2 === void 0 ? void 0 : _this$props$mediaOpti2.onMediaRenderEvent) !== ((_nextProps$mediaOptio = nextProps.mediaOptions) === null || _nextProps$mediaOptio === void 0 ? void 0 : _nextProps$mediaOptio.onMediaRenderEvent) || this.state.previewRenderedFileId !== nextState.previewRenderedFileId || this.state.failedFileId !== nextState.failedFileId || hasNewViewMediaClientConfig || hasNewViewAndUploadMediaClientConfig) {
237
318
  return true;
238
319
  }
239
320
  return false;
@@ -241,17 +322,17 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
241
322
  }, {
242
323
  key: "componentDidMount",
243
324
  value: function () {
244
- var _componentDidMount = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
325
+ var _componentDidMount = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
245
326
  var _dataConsumerMark$att;
246
- var _this$props2, node, pluginInjectionApi, dataConsumerMark, infographicType, _pluginInjectionApi$a, contextIdentifierProvider, _t, _t2;
247
- return _regenerator.default.wrap(function (_context2) {
248
- while (1) switch (_context2.prev = _context2.next) {
327
+ var _this$props3, node, pluginInjectionApi, dataConsumerMark, infographicType, _pluginInjectionApi$a, contextIdentifierProvider, _t2, _t3;
328
+ return _regenerator.default.wrap(function (_context3) {
329
+ while (1) switch (_context3.prev = _context3.next) {
249
330
  case 0:
250
331
  this.handleNewNode(this.props);
251
332
  this.emitMediaRenderEvent({
252
333
  type: 'mounted'
253
334
  });
254
- _this$props2 = this.props, node = _this$props2.node, pluginInjectionApi = _this$props2.pluginInjectionApi;
335
+ _this$props3 = this.props, node = _this$props3.node, pluginInjectionApi = _this$props3.pluginInjectionApi;
255
336
  dataConsumerMark = this.getDataConsumerMark();
256
337
  infographicType = dataConsumerMark === null || dataConsumerMark === void 0 || (_dataConsumerMark$att = dataConsumerMark.attrs.sources) === null || _dataConsumerMark$att === void 0 ? void 0 : _dataConsumerMark$att[0];
257
338
  if (infographicType) {
@@ -268,21 +349,21 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
268
349
  });
269
350
  }
270
351
  contextIdentifierProvider = this.props.contextIdentifierProvider;
271
- _t = this;
272
- _context2.next = 1;
352
+ _t2 = this;
353
+ _context3.next = 1;
273
354
  return contextIdentifierProvider;
274
355
  case 1:
275
- _t2 = _context2.sent;
276
- _t.setState.call(_t, {
277
- contextIdentifierProvider: _t2
356
+ _t3 = _context3.sent;
357
+ _t2.setState.call(_t2, {
358
+ contextIdentifierProvider: _t3
278
359
  });
279
- _context2.next = 2;
360
+ _context3.next = 2;
280
361
  return this.setViewMediaClientConfig();
281
362
  case 2:
282
363
  case "end":
283
- return _context2.stop();
364
+ return _context3.stop();
284
365
  }
285
- }, _callee2, this);
366
+ }, _callee3, this);
286
367
  }));
287
368
  function componentDidMount() {
288
369
  return _componentDidMount.apply(this, arguments);
@@ -374,17 +455,32 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
374
455
  });
375
456
  }
376
457
  }
458
+ }, {
459
+ key: "hasGeneratedMediaMotion",
460
+ get:
461
+ /**
462
+ * Surface opt-in first, so surfaces that never ask for the motion are not exposed to the
463
+ * gate. The node type is checked after it, so every node on an opted-in surface counts
464
+ * towards the same exposure population.
465
+ */
466
+ function get() {
467
+ var _this$props$mediaOpti4;
468
+ return !!((_this$props$mediaOpti4 = this.props.mediaOptions) !== null && _this$props$mediaOpti4 !== void 0 && _this$props$mediaOpti4.allowAIGeneratedMediaMotion) && (0, _fg.fg)('aifc_page_create_defer_generated_visuals') &&
469
+ // File-backed only: `ExternalImageCard` reports neither its rendered preview nor its
470
+ // dimensions, so an external node could only ever open on the reveal's timeout.
471
+ this.props.node.attrs.type !== 'external';
472
+ }
377
473
  }, {
378
474
  key: "render",
379
475
  value: function render() {
380
476
  var _dataConsumerMark$att2;
381
- var _this$props3 = this.props,
382
- node = _this$props3.node,
383
- selected = _this$props3.selected,
384
- originalDimensions = _this$props3.originalDimensions,
385
- isLoading = _this$props3.isLoading,
386
- maxDimensions = _this$props3.maxDimensions,
387
- mediaOptions = _this$props3.mediaOptions;
477
+ var _this$props4 = this.props,
478
+ node = _this$props4.node,
479
+ selected = _this$props4.selected,
480
+ originalDimensions = _this$props4.originalDimensions,
481
+ isLoading = _this$props4.isLoading,
482
+ maxDimensions = _this$props4.maxDimensions,
483
+ mediaOptions = _this$props4.mediaOptions;
388
484
  var borderMark = node.marks.find(function (m) {
389
485
  return m.type.name === 'border';
390
486
  });
@@ -402,14 +498,26 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
402
498
 
403
499
  // Check if we have any media client config available (syncProvider, state, or upload config)
404
500
  var hasNoMediaClientConfig = !viewMediaClientConfig && ((0, _fg.fg)('platform_media_video_captions') ? !viewAndUploadMediaClientConfig : true);
501
+ var hasGeneratedMediaMotion = this.hasGeneratedMediaMotion;
502
+
503
+ // Opening before the real dimensions land would animate to the wrong height and snap
504
+ // when they correct. Nodes that never get them fall through to the reveal's timeout.
505
+ //
506
+ // A terminal error is readiness too: the card is already showing its error treatment,
507
+ // so the space opens onto that rather than hiding it until the timeout.
508
+ var isRevealReady = this.state.failedFileId === id || this.state.previewRenderedFileId === id && !!node.attrs.width && !!node.attrs.height;
405
509
  if (isLoading || type !== 'external' && hasNoMediaClientConfig) {
406
- return /*#__PURE__*/_react.default.createElement(_styles.MediaCardWrapper, {
510
+ return /*#__PURE__*/_react.default.createElement(_GeneratedMediaReveal.GeneratedMediaReveal, {
511
+ isEnabled: hasGeneratedMediaMotion,
512
+ isReady: isRevealReady,
513
+ mediaKey: id
514
+ }, /*#__PURE__*/_react.default.createElement(_styles.MediaCardWrapper, {
407
515
  dimensions: originalDimensions,
408
516
  borderWidth: borderMark === null || borderMark === void 0 ? void 0 : borderMark.attrs.size,
409
517
  selected: selected
410
518
  }, /*#__PURE__*/_react.default.createElement(_mediaCard.CardLoading, {
411
519
  interactionName: "editor-media-card-loading"
412
- }));
520
+ })));
413
521
  }
414
522
  var contextId = contextIdentifierProvider && contextIdentifierProvider.objectId;
415
523
  var identifier = type === 'external' ? {
@@ -442,7 +550,11 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
442
550
  // generic media type icon isn't shown while the image streams in. Gated on the
443
551
  // existing infographics experiment.
444
552
  var isCWR = !!this.props.isCwrAIGenerating && (0, _isExperimentEnabled.isExperimentEnabled)('aifc_page_create_with_rovo_include_infographics');
445
- return /*#__PURE__*/_react.default.createElement(_styles.MediaCardWrapper, {
553
+ return /*#__PURE__*/_react.default.createElement(_GeneratedMediaReveal.GeneratedMediaReveal, {
554
+ isEnabled: hasGeneratedMediaMotion,
555
+ isReady: isRevealReady,
556
+ mediaKey: id
557
+ }, /*#__PURE__*/_react.default.createElement(_styles.MediaCardWrapper, {
446
558
  dimensions: originalDimensions,
447
559
  onContextMenu: this.selectMediaSingle,
448
560
  borderWidth: borderMark === null || borderMark === void 0 ? void 0 : borderMark.attrs.size,
@@ -477,10 +589,11 @@ var MediaNode = exports.MediaNode = /*#__PURE__*/function (_Component) {
477
589
  mediaSettings: this.getMediaSettings(viewAndUploadMediaClientConfig, this.props.isViewOnly),
478
590
  isAIGenerating: !!this.props.isAIGenerating,
479
591
  isCWR: isCWR,
592
+ hasLoadingMotion: hasGeneratedMediaMotion,
480
593
  onPreviewRender: this.onPreviewRender,
481
594
  fallbackMediaNameFetcher: mediaOptions === null || mediaOptions === void 0 ? void 0 : mediaOptions.fallbackMediaNameFetcher,
482
595
  onError: this.getMediaRenderErrorHandler()
483
- })));
596
+ }))));
484
597
  }
485
598
  }]);
486
599
  }(_react.Component);
@@ -0,0 +1,12 @@
1
+ ._18m915vq{overflow-y:hidden}
2
+ ._1e0c11p5{display:grid}
3
+ ._1o51eoah{animation-fill-mode:backwards}
4
+ ._1pglindk{animation-timing-function:var(--ds-easing-out-practical,cubic-bezier(.4,1,.6,1))}
5
+ ._1reo15vq{overflow-x:hidden}
6
+ ._1tkeidpf{min-height:0}
7
+ ._2z0563bf{grid-template-rows:0fr}
8
+ ._2z05hkll{grid-template-rows:1fr}
9
+ ._5sag15uc{animation-duration:var(--ds-duration-xlong,.4s)}
10
+ ._j7hq8gkt{animation-name:kaq7wke}
11
+ @keyframes kaq7wke{0%{grid-template-rows:0fr}to{grid-template-rows:1fr}}
12
+ @media (prefers-reduced-motion:reduce){._1bumglyw{animation:none}}
@@ -0,0 +1,124 @@
1
+ /* GeneratedMediaReveal.tsx generated by @compiled/babel-plugin v3.0.1 */
2
+ "use strict";
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.GeneratedMediaReveal = void 0;
10
+ require("./GeneratedMediaReveal.compiled.css");
11
+ var _runtime = require("@compiled/react/runtime");
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+ var _react = _interopRequireWildcard(require("react"));
14
+ 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); }
15
+ /**
16
+ * Only `collapsed` and `revealing` size and clip the content. `open` drops back to plain
17
+ * block layout, so the reveal leaves nothing behind for selection outlines, resize handles
18
+ * or badges to collide with.
19
+ */
20
+
21
+ /** Which path opened the node. Surfaced as a data attribute for debugging. */
22
+
23
+ // A `0fr -> 1fr` grid row opens out to the content's natural height without anyone having to
24
+ // measure it, which matters because the card's height comes from an aspect-ratio padding
25
+ // further down the tree.
26
+ var openRow = null;
27
+ var collapsedStyles = null;
28
+ var revealStyles = null;
29
+ var clippedStyles = null;
30
+
31
+ /**
32
+ * Fail-safe, not a normal path: opens the node even if the preview never reports itself
33
+ * rendered, so a failed or hanging image still ends up visible rather than staying collapsed.
34
+ * Also covers lazy loading, where a card collapsed to zero height may never satisfy the
35
+ * IntersectionObserver that triggers its fetch.
36
+ *
37
+ * Deliberately generous, because opening early is worse than opening late — the space then
38
+ * reveals the card's own loading treatment instead of the image, and an AI-generated image has
39
+ * to be generated, uploaded, processed and fetched first. `data-media-reveal-trigger` shows
40
+ * which path fired; `timeout` in normal use means the readiness signal is broken.
41
+ */
42
+ var READY_TIMEOUT_MS = 30000;
43
+
44
+ // Backstop for reduced motion and browsers that don't interpolate grid-template-rows, where no
45
+ // animationend fires. Must stay comfortably longer than the reveal, or it cuts it off part way.
46
+ var REVEAL_TIMEOUT_MS = 1000;
47
+ /**
48
+ * Opens the document out to make room for a media node once its preview is ready, rather than
49
+ * having the node snap into place at full height. For AI-generated media in the Create with
50
+ * Rovo preview, where images are inserted after the surrounding content has streamed in:
51
+ * holding the node closed until the preview has rendered means the space opens exactly once,
52
+ * with the image already fading in, so there is no placeholder to look at in between.
53
+ */
54
+ var GeneratedMediaReveal = exports.GeneratedMediaReveal = function GeneratedMediaReveal(_ref) {
55
+ var children = _ref.children,
56
+ isEnabled = _ref.isEnabled,
57
+ isReady = _ref.isReady,
58
+ mediaKey = _ref.mediaKey;
59
+ var _useState = (0, _react.useState)('collapsed'),
60
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
61
+ state = _useState2[0],
62
+ setState = _useState2[1];
63
+ var _useState3 = (0, _react.useState)(),
64
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
65
+ trigger = _useState4[0],
66
+ setTrigger = _useState4[1];
67
+
68
+ // Reset during render rather than remounting on a `key`, which would also remount the card
69
+ // below and restart its fetch. The reveal's effect only runs while `collapsed`, so without
70
+ // this a replacement would appear at once, having inherited the previous file's `open`.
71
+ var _useState5 = (0, _react.useState)(mediaKey),
72
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
73
+ renderedMediaKey = _useState6[0],
74
+ setRenderedMediaKey = _useState6[1];
75
+ if (mediaKey !== renderedMediaKey) {
76
+ setRenderedMediaKey(mediaKey);
77
+ setState('collapsed');
78
+ setTrigger(undefined);
79
+ }
80
+ (0, _react.useEffect)(function () {
81
+ if (!isEnabled || state !== 'collapsed') {
82
+ return;
83
+ }
84
+ if (isReady) {
85
+ setTrigger('ready');
86
+ setState('revealing');
87
+ return;
88
+ }
89
+ var timer = setTimeout(function () {
90
+ setTrigger('timeout');
91
+ setState('revealing');
92
+ }, READY_TIMEOUT_MS);
93
+ return function () {
94
+ return clearTimeout(timer);
95
+ };
96
+ }, [isEnabled, isReady, state]);
97
+ (0, _react.useEffect)(function () {
98
+ if (state !== 'revealing') {
99
+ return;
100
+ }
101
+ var timer = setTimeout(function () {
102
+ return setState('open');
103
+ }, REVEAL_TIMEOUT_MS);
104
+ return function () {
105
+ return clearTimeout(timer);
106
+ };
107
+ }, [state]);
108
+ if (!isEnabled) {
109
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
110
+ }
111
+ return /*#__PURE__*/_react.default.createElement("div", {
112
+ "data-media-reveal": state,
113
+ "data-media-reveal-trigger": trigger,
114
+ onAnimationEnd: function onAnimationEnd(event) {
115
+ // The media card runs animations of its own, which bubble through here.
116
+ if (event.target === event.currentTarget) {
117
+ setState('open');
118
+ }
119
+ },
120
+ className: (0, _runtime.ax)([state === 'collapsed' && "_1e0c11p5 _2z0563bf", state === 'revealing' && "", state === 'revealing' && "_1e0c11p5 _2z05hkll _j7hq8gkt _5sag15uc _1pglindk _1o51eoah _1bumglyw"])
121
+ }, /*#__PURE__*/_react.default.createElement("div", {
122
+ className: (0, _runtime.ax)([state !== 'open' && "_1reo15vq _18m915vq _1tkeidpf"])
123
+ }, children));
124
+ };