@atlaskit/media-card 73.1.0 → 73.3.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 (74) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/cjs/files/cardImageView/index.js +51 -41
  3. package/dist/cjs/root/card/cardAnalytics.js +4 -4
  4. package/dist/cjs/root/card/getCardPreview/index.js +7 -1
  5. package/dist/cjs/root/card/index.js +301 -155
  6. package/dist/cjs/root/cardView.js +128 -118
  7. package/dist/cjs/root/inlinePlayer.js +4 -2
  8. package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +17 -23
  9. package/dist/cjs/root/ui/styled.js +5 -5
  10. package/dist/cjs/types.js +10 -1
  11. package/dist/cjs/utils/analytics.js +32 -13
  12. package/dist/cjs/utils/dimensionComparer.js +7 -13
  13. package/dist/cjs/utils/getMediaCardCursor.js +29 -0
  14. package/dist/cjs/utils/globalScope/getSSRData.js +20 -0
  15. package/dist/cjs/utils/globalScope/globalScope.js +94 -0
  16. package/dist/cjs/utils/globalScope/index.js +39 -0
  17. package/dist/cjs/utils/globalScope/types.js +5 -0
  18. package/dist/cjs/utils/printScript.js +44 -0
  19. package/dist/cjs/version.json +1 -1
  20. package/dist/es2019/files/cardImageView/index.js +19 -5
  21. package/dist/es2019/root/card/cardAnalytics.js +4 -4
  22. package/dist/es2019/root/card/getCardPreview/index.js +1 -0
  23. package/dist/es2019/root/card/index.js +167 -40
  24. package/dist/es2019/root/cardView.js +41 -35
  25. package/dist/es2019/root/inlinePlayer.js +4 -2
  26. package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +17 -19
  27. package/dist/es2019/root/ui/styled.js +4 -4
  28. package/dist/es2019/types.js +7 -1
  29. package/dist/es2019/utils/analytics.js +17 -9
  30. package/dist/es2019/utils/dimensionComparer.js +6 -13
  31. package/dist/es2019/utils/getMediaCardCursor.js +19 -0
  32. package/dist/es2019/utils/globalScope/getSSRData.js +10 -0
  33. package/dist/es2019/utils/globalScope/globalScope.js +62 -0
  34. package/dist/es2019/utils/globalScope/index.js +2 -0
  35. package/dist/es2019/utils/globalScope/types.js +1 -0
  36. package/dist/es2019/utils/printScript.js +19 -0
  37. package/dist/es2019/version.json +1 -1
  38. package/dist/esm/files/cardImageView/index.js +53 -41
  39. package/dist/esm/root/card/cardAnalytics.js +4 -4
  40. package/dist/esm/root/card/getCardPreview/index.js +3 -0
  41. package/dist/esm/root/card/index.js +284 -138
  42. package/dist/esm/root/cardView.js +127 -118
  43. package/dist/esm/root/inlinePlayer.js +4 -2
  44. package/dist/esm/root/ui/imageRenderer/imageRenderer.js +17 -21
  45. package/dist/esm/root/ui/styled.js +5 -5
  46. package/dist/esm/types.js +7 -1
  47. package/dist/esm/utils/analytics.js +26 -12
  48. package/dist/esm/utils/dimensionComparer.js +8 -13
  49. package/dist/esm/utils/getMediaCardCursor.js +19 -0
  50. package/dist/esm/utils/globalScope/getSSRData.js +10 -0
  51. package/dist/esm/utils/globalScope/globalScope.js +69 -0
  52. package/dist/esm/utils/globalScope/index.js +2 -0
  53. package/dist/esm/utils/globalScope/types.js +1 -0
  54. package/dist/esm/utils/printScript.js +30 -0
  55. package/dist/esm/version.json +1 -1
  56. package/dist/types/__tests_external__/page-objects/MediaCard.d.ts +0 -1
  57. package/dist/types/errors.d.ts +1 -1
  58. package/dist/types/files/cardImageView/index.d.ts +6 -2
  59. package/dist/types/root/card/cardAnalytics.d.ts +2 -1
  60. package/dist/types/root/card/getCardPreview/index.d.ts +1 -0
  61. package/dist/types/root/card/index.d.ts +5 -1
  62. package/dist/types/root/cardView.d.ts +8 -6
  63. package/dist/types/root/inlinePlayer.d.ts +3 -1
  64. package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +5 -14
  65. package/dist/types/root/ui/styled.d.ts +2 -1
  66. package/dist/types/types.d.ts +6 -1
  67. package/dist/types/utils/analytics.d.ts +27 -5
  68. package/dist/types/utils/getMediaCardCursor.d.ts +2 -0
  69. package/dist/types/utils/globalScope/getSSRData.d.ts +3 -0
  70. package/dist/types/utils/globalScope/globalScope.d.ts +21 -0
  71. package/dist/types/utils/globalScope/index.d.ts +4 -0
  72. package/dist/types/utils/globalScope/types.d.ts +8 -0
  73. package/dist/types/utils/printScript.d.ts +2 -0
  74. package/package.json +12 -12
@@ -41,7 +41,7 @@ var _mediaCommon = require("@atlaskit/media-common");
41
41
 
42
42
  var _download = _interopRequireDefault(require("@atlaskit/icon/glyph/download"));
43
43
 
44
- var _mediaClient = require("@atlaskit/media-client");
44
+ var _mediaClient2 = require("@atlaskit/media-client");
45
45
 
46
46
  var _mediaViewer = require("@atlaskit/media-viewer");
47
47
 
@@ -67,8 +67,14 @@ var _cardAnalytics = require("./cardAnalytics");
67
67
 
68
68
  var _document = _interopRequireDefault(require("../../utils/document"));
69
69
 
70
+ var _globalScope = require("../../utils/globalScope");
71
+
70
72
  var _cardState = require("./cardState");
71
73
 
74
+ var _dimensionComparer = require("../../utils/dimensionComparer");
75
+
76
+ var _getMediaCardCursor = require("../../utils/getMediaCardCursor");
77
+
72
78
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
73
79
 
74
80
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -96,12 +102,20 @@ var CardBase = /*#__PURE__*/function (_Component) {
96
102
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hasBeenMounted", false);
97
103
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "viewportPreAnchorRef", /*#__PURE__*/(0, _react.createRef)());
98
104
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "viewportPostAnchorRef", /*#__PURE__*/(0, _react.createRef)());
105
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "ssrReliability", {
106
+ server: {
107
+ status: 'unknown'
108
+ },
109
+ client: {
110
+ status: 'unknown'
111
+ }
112
+ });
99
113
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "timeElapsedTillCommenced", performance.now());
100
114
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getImageURLParams", function (_ref) {
101
115
  var collection = _ref.collectionName;
102
116
  return _objectSpread(_objectSpread({
103
117
  collection: collection,
104
- mode: (0, _mediaClient.imageResizeModeToFileImageMode)(_this.props.resizeMode)
118
+ mode: (0, _mediaClient2.imageResizeModeToFileImageMode)(_this.props.resizeMode)
105
119
  }, _this.requestedDimensions), {}, {
106
120
  allowAnimated: true
107
121
  });
@@ -143,7 +157,7 @@ var CardBase = /*#__PURE__*/function (_Component) {
143
157
  dimensions: dimensions,
144
158
  onLocalPreviewError: _this.fireLocalPreviewErrorEvent,
145
159
  filePreview: isBannedLocalPreview ? undefined : (0, _getCardPreview.getFilePreviewFromFileState)(fileState),
146
- isRemotePreviewReady: (0, _mediaClient.isImageRepresentationReady)(fileState),
160
+ isRemotePreviewReady: (0, _mediaClient2.isImageRepresentationReady)(fileState),
147
161
  imageUrlParams: _this.getImageURLParams(identifier),
148
162
  mediaBlobUrlAttrs: _this.getMediaBlobUrlAttrs(identifier, fileState)
149
163
  };
@@ -159,26 +173,18 @@ var CardBase = /*#__PURE__*/function (_Component) {
159
173
  // https://product-fabric.atlassian.net/browse/MEX-1071
160
174
  });
161
175
  });
162
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "resolveSSRPreview", function (identifier, ssr) {
163
- var mediaClient = _this.props.mediaClient;
176
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "refetchSSRPreview", /*#__PURE__*/function () {
177
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(identifier) {
178
+ var _this$props4, mediaClient, _this$props4$dimensio, dimensions, cardPreview;
164
179
 
165
- try {
166
- return (0, _getCardPreview.getSSRCardPreview)(ssr, mediaClient, identifier.id, _this.getImageURLParams(identifier), _this.getMediaBlobUrlAttrs(identifier));
167
- } catch (e) {// TODO: log SSR reliability 'failed'
168
- // https://product-fabric.atlassian.net/browse/MEX-770
169
- }
170
- });
171
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "resolvePreview", /*#__PURE__*/function () {
172
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(identifier, fileState) {
173
- var params, cardPreview, wrappedError;
174
180
  return _regenerator.default.wrap(function _callee$(_context) {
175
181
  while (1) {
176
182
  switch (_context.prev = _context.next) {
177
183
  case 0:
178
- _context.prev = 0;
179
- params = _this.getCardPreviewParams(identifier, fileState);
184
+ _this$props4 = _this.props, mediaClient = _this$props4.mediaClient, _this$props4$dimensio = _this$props4.dimensions, dimensions = _this$props4$dimensio === void 0 ? {} : _this$props4$dimensio;
185
+ _context.prev = 1;
180
186
  _context.next = 4;
181
- return (0, _getCardPreview.getCardPreview)(params);
187
+ return (0, _getCardPreview.fetchAndCacheRemotePreview)(mediaClient, identifier.id, dimensions, _this.getImageURLParams(identifier), _this.getMediaBlobUrlAttrs(identifier));
182
188
 
183
189
  case 4:
184
190
  cardPreview = _context.sent;
@@ -187,13 +193,51 @@ var CardBase = /*#__PURE__*/function (_Component) {
187
193
  cardPreview: cardPreview
188
194
  });
189
195
 
190
- _context.next = 12;
196
+ _context.next = 10;
191
197
  break;
192
198
 
193
199
  case 8:
194
200
  _context.prev = 8;
195
- _context.t0 = _context["catch"](0);
196
- wrappedError = (0, _errors.ensureMediaCardError)('preview-fetch', _context.t0); // If remote preview fails, we set status 'error'
201
+ _context.t0 = _context["catch"](1);
202
+
203
+ case 10:
204
+ case "end":
205
+ return _context.stop();
206
+ }
207
+ }
208
+ }, _callee, null, [[1, 8]]);
209
+ }));
210
+
211
+ return function (_x) {
212
+ return _ref2.apply(this, arguments);
213
+ };
214
+ }());
215
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "resolvePreview", /*#__PURE__*/function () {
216
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(identifier, fileState) {
217
+ var params, cardPreview, wrappedError;
218
+ return _regenerator.default.wrap(function _callee2$(_context2) {
219
+ while (1) {
220
+ switch (_context2.prev = _context2.next) {
221
+ case 0:
222
+ _context2.prev = 0;
223
+ params = _this.getCardPreviewParams(identifier, fileState);
224
+ _context2.next = 4;
225
+ return (0, _getCardPreview.getCardPreview)(params);
226
+
227
+ case 4:
228
+ cardPreview = _context2.sent;
229
+
230
+ _this.safeSetState({
231
+ cardPreview: cardPreview
232
+ });
233
+
234
+ _context2.next = 12;
235
+ break;
236
+
237
+ case 8:
238
+ _context2.prev = 8;
239
+ _context2.t0 = _context2["catch"](0);
240
+ wrappedError = (0, _errors.ensureMediaCardError)('preview-fetch', _context2.t0); // If remote preview fails, we set status 'error'
197
241
  // If local preview fails (i.e, no remote preview available),
198
242
  // we can stay in the same status until there is a remote preview available
199
243
  // If it's any other error we set status 'error'
@@ -211,14 +255,14 @@ var CardBase = /*#__PURE__*/function (_Component) {
211
255
 
212
256
  case 12:
213
257
  case "end":
214
- return _context.stop();
258
+ return _context2.stop();
215
259
  }
216
260
  }
217
- }, _callee, null, [[0, 8]]);
261
+ }, _callee2, null, [[0, 8]]);
218
262
  }));
219
263
 
220
- return function (_x, _x2) {
221
- return _ref2.apply(this, arguments);
264
+ return function (_x2, _x3) {
265
+ return _ref3.apply(this, arguments);
222
266
  };
223
267
  }());
224
268
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getPerformanceAttributes", function () {
@@ -234,11 +278,38 @@ var CardBase = /*#__PURE__*/function (_Component) {
234
278
  }
235
279
  };
236
280
  });
237
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onImageError", function () {
238
- var cardPreview = _this.state.cardPreview;
281
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "logSSRImageError", function (cardPreview) {
282
+ if (cardPreview) {
283
+ var failedSSRObject = _objectSpread({
284
+ status: 'fail'
285
+ }, (0, _analytics.extractErrorInfo)(new _errors.ImageLoadError(cardPreview.source)));
286
+
287
+ if ((0, _getCardPreview.isSSRClientPreview)(cardPreview)) {
288
+ _this.ssrReliability.client = failedSSRObject;
289
+ }
290
+ /*
291
+ If the cardPreview failed and it comes from server (global scope / ssrData), it means that we have reused it in client and the error counts for both: server & client.
292
+ */
293
+
294
+
295
+ if ((0, _getCardPreview.isSSRDataPreview)(cardPreview)) {
296
+ _this.ssrReliability.server = failedSSRObject;
297
+ _this.ssrReliability.client = failedSSRObject;
298
+ }
299
+ }
300
+ });
301
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onImageError", function (cardPreview) {
302
+ _this.logSSRImageError(cardPreview);
303
+
304
+ var currentPreview = _this.state.cardPreview; // If the dataURI has been replaced, we can dismiss this error
305
+
306
+ if ((cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI) !== (currentPreview === null || currentPreview === void 0 ? void 0 : currentPreview.dataURI)) {
307
+ return;
308
+ }
309
+
239
310
  var error = new _errors.ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
240
311
  var isLocal = cardPreview && (0, _getCardPreview.isLocalPreview)(cardPreview);
241
- var isSSR = cardPreview && (0, _getCardPreview.isSSRClientPreview)(cardPreview);
312
+ var isSSR = cardPreview && ((0, _getCardPreview.isSSRClientPreview)(cardPreview) || (0, _getCardPreview.isSSRDataPreview)(cardPreview));
242
313
 
243
314
  if (isLocal || isSSR) {
244
315
  var updateState = {
@@ -251,15 +322,11 @@ var CardBase = /*#__PURE__*/function (_Component) {
251
322
  _this.fireLocalPreviewErrorEvent(error);
252
323
  }
253
324
 
254
- if (isSSR) {// TODO: set SSR-client reliability 'failed'.
255
- // https://product-fabric.atlassian.net/browse/MEX-770
256
- }
257
-
258
- var _this$props4 = _this.props,
259
- identifier = _this$props4.identifier,
260
- _this$props4$dimensio = _this$props4.dimensions,
261
- dimensions = _this$props4$dimensio === void 0 ? {} : _this$props4$dimensio;
262
- (0, _mediaClient.isFileIdentifier)(identifier) && (0, _getCardPreview.removeCardPreviewFromCache)(identifier.id, dimensions);
325
+ var _this$props5 = _this.props,
326
+ identifier = _this$props5.identifier,
327
+ _this$props5$dimensio = _this$props5.dimensions,
328
+ dimensions = _this$props5$dimensio === void 0 ? {} : _this$props5$dimensio;
329
+ (0, _mediaClient2.isFileIdentifier)(identifier) && (0, _getCardPreview.removeCardPreviewFromCache)(identifier.id, dimensions);
263
330
 
264
331
  _this.safeSetState(updateState);
265
332
  } else {
@@ -269,7 +336,34 @@ var CardBase = /*#__PURE__*/function (_Component) {
269
336
  });
270
337
  }
271
338
  });
272
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onImageLoad", function () {
339
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onImageLoad", function (cardPreview) {
340
+ if (cardPreview) {
341
+ if ((0, _getCardPreview.isSSRClientPreview)(cardPreview) && _this.ssrReliability.client.status === 'unknown') {
342
+ _this.ssrReliability.client = {
343
+ status: 'success'
344
+ };
345
+ }
346
+ /*
347
+ If the image loads successfully and it comes from server (global scope / ssrData), it means that we have reused it in client and the success counts for both: server & client.
348
+ */
349
+
350
+
351
+ if ((0, _getCardPreview.isSSRDataPreview)(cardPreview) && _this.ssrReliability.server.status === 'unknown') {
352
+ _this.ssrReliability.server = {
353
+ status: 'success'
354
+ };
355
+ _this.ssrReliability.client = {
356
+ status: 'success'
357
+ };
358
+ }
359
+ }
360
+
361
+ var currentPreview = _this.state.cardPreview; // If the dataURI has been replaced, we can dismiss this callback
362
+
363
+ if ((cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI) !== (currentPreview === null || currentPreview === void 0 ? void 0 : currentPreview.dataURI)) {
364
+ return;
365
+ }
366
+
273
367
  _this.safeSetState({
274
368
  previewDidRender: true
275
369
  });
@@ -309,10 +403,10 @@ var CardBase = /*#__PURE__*/function (_Component) {
309
403
  }
310
404
  });
311
405
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCardViewClick", function (event, analyticsEvent) {
312
- var _this$props5 = _this.props,
313
- identifier = _this$props5.identifier,
314
- useInlinePlayer = _this$props5.useInlinePlayer,
315
- shouldOpenMediaViewer = _this$props5.shouldOpenMediaViewer;
406
+ var _this$props6 = _this.props,
407
+ identifier = _this$props6.identifier,
408
+ useInlinePlayer = _this$props6.useInlinePlayer,
409
+ shouldOpenMediaViewer = _this$props6.shouldOpenMediaViewer;
316
410
  var cardPreview = _this.state.cardPreview;
317
411
 
318
412
  var _assertThisInitialize2 = (0, _assertThisInitialized2.default)(_this),
@@ -334,7 +428,7 @@ var CardBase = /*#__PURE__*/function (_Component) {
334
428
  } else if (shouldOpenMediaViewer) {
335
429
  var mediaViewerSelectedItem;
336
430
 
337
- if ((0, _mediaClient.isFileIdentifier)(identifier)) {
431
+ if ((0, _mediaClient2.isFileIdentifier)(identifier)) {
338
432
  mediaViewerSelectedItem = {
339
433
  id: identifier.id,
340
434
  mediaItemType: 'file',
@@ -365,14 +459,16 @@ var CardBase = /*#__PURE__*/function (_Component) {
365
459
  });
366
460
  });
367
461
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderInlinePlayer", function () {
368
- var _this$props6 = _this.props,
369
- identifier = _this$props6.identifier,
370
- mediaClient = _this$props6.mediaClient,
371
- dimensions = _this$props6.dimensions,
372
- selected = _this$props6.selected,
373
- testId = _this$props6.testId,
374
- originalDimensions = _this$props6.originalDimensions;
375
- var shouldAutoplay = _this.state.shouldAutoplay;
462
+ var _this$props7 = _this.props,
463
+ identifier = _this$props7.identifier,
464
+ mediaClient = _this$props7.mediaClient,
465
+ dimensions = _this$props7.dimensions,
466
+ selected = _this$props7.selected,
467
+ testId = _this$props7.testId,
468
+ originalDimensions = _this$props7.originalDimensions;
469
+ var _this$state = _this.state,
470
+ shouldAutoplay = _this$state.shouldAutoplay,
471
+ cardPreview = _this$state.cardPreview;
376
472
  return /*#__PURE__*/_react.default.createElement(_inlinePlayer.InlinePlayer, {
377
473
  mediaClient: mediaClient,
378
474
  dimensions: dimensions,
@@ -383,7 +479,8 @@ var CardBase = /*#__PURE__*/function (_Component) {
383
479
  onClick: _this.onClick,
384
480
  selected: selected,
385
481
  ref: _this.setRef,
386
- testId: testId
482
+ testId: testId,
483
+ cardPreview: cardPreview
387
484
  });
388
485
  });
389
486
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMediaViewerClose", function () {
@@ -395,10 +492,10 @@ var CardBase = /*#__PURE__*/function (_Component) {
395
492
  var identifier = _this.props.identifier;
396
493
  var payloadPart;
397
494
 
398
- if ((0, _mediaClient.isFileIdentifier)(identifier)) {
495
+ if ((0, _mediaClient2.isFileIdentifier)(identifier)) {
399
496
  payloadPart = {
400
497
  fileId: identifier.id,
401
- isUserCollection: identifier.collectionName === _mediaClient.RECENTS_COLLECTION
498
+ isUserCollection: identifier.collectionName === _mediaClient2.RECENTS_COLLECTION
402
499
  };
403
500
  } else {
404
501
  payloadPart = {
@@ -407,24 +504,24 @@ var CardBase = /*#__PURE__*/function (_Component) {
407
504
  };
408
505
  }
409
506
 
410
- _mediaClient.globalMediaEventEmitter.emit('media-viewed', _objectSpread({
507
+ _mediaClient2.globalMediaEventEmitter.emit('media-viewed', _objectSpread({
411
508
  viewingLevel: 'minimal'
412
509
  }, payloadPart));
413
510
  });
414
511
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderMediaViewer", function () {
415
512
  var mediaViewerSelectedItem = _this.state.mediaViewerSelectedItem;
416
- var _this$props7 = _this.props,
417
- mediaClient = _this$props7.mediaClient,
418
- identifier = _this$props7.identifier,
419
- mediaViewerDataSource = _this$props7.mediaViewerDataSource,
420
- contextId = _this$props7.contextId,
421
- featureFlags = _this$props7.featureFlags;
513
+ var _this$props8 = _this.props,
514
+ mediaClient = _this$props8.mediaClient,
515
+ identifier = _this$props8.identifier,
516
+ mediaViewerDataSource = _this$props8.mediaViewerDataSource,
517
+ contextId = _this$props8.contextId,
518
+ featureFlags = _this$props8.featureFlags;
422
519
 
423
520
  if (!mediaViewerSelectedItem) {
424
521
  return;
425
522
  }
426
523
 
427
- var collectionName = (0, _mediaClient.isFileIdentifier)(identifier) ? identifier.collectionName || '' : '';
524
+ var collectionName = (0, _mediaClient2.isFileIdentifier)(identifier) ? identifier.collectionName || '' : '';
428
525
  var dataSource = mediaViewerDataSource || {
429
526
  list: []
430
527
  };
@@ -439,35 +536,31 @@ var CardBase = /*#__PURE__*/function (_Component) {
439
536
  }), document.body);
440
537
  });
441
538
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderCard", function () {
442
- var _this$props8 = _this.props,
443
- identifier = _this$props8.identifier,
444
- isLazy = _this$props8.isLazy,
445
- appearance = _this$props8.appearance,
446
- resizeMode = _this$props8.resizeMode,
447
- dimensions = _this$props8.dimensions,
448
- selectable = _this$props8.selectable,
449
- selected = _this$props8.selected,
450
- disableOverlay = _this$props8.disableOverlay,
451
- alt = _this$props8.alt,
452
- testId = _this$props8.testId,
453
- featureFlags = _this$props8.featureFlags,
454
- titleBoxBgColor = _this$props8.titleBoxBgColor,
455
- titleBoxIcon = _this$props8.titleBoxIcon,
456
- ssr = _this$props8.ssr;
539
+ var _this$props9 = _this.props,
540
+ identifier = _this$props9.identifier,
541
+ isLazy = _this$props9.isLazy,
542
+ appearance = _this$props9.appearance,
543
+ resizeMode = _this$props9.resizeMode,
544
+ dimensions = _this$props9.dimensions,
545
+ selectable = _this$props9.selectable,
546
+ selected = _this$props9.selected,
547
+ disableOverlay = _this$props9.disableOverlay,
548
+ alt = _this$props9.alt,
549
+ testId = _this$props9.testId,
550
+ featureFlags = _this$props9.featureFlags,
551
+ titleBoxBgColor = _this$props9.titleBoxBgColor,
552
+ titleBoxIcon = _this$props9.titleBoxIcon,
553
+ ssr = _this$props9.ssr,
554
+ useInlinePlayer = _this$props9.useInlinePlayer,
555
+ shouldOpenMediaViewer = _this$props9.shouldOpenMediaViewer;
457
556
  var mediaItemType = identifier.mediaItemType;
458
- var _this$state = _this.state,
459
- status = _this$state.status,
460
- progress = _this$state.progress,
461
- _this$state$cardPrevi = _this$state.cardPreview;
462
- _this$state$cardPrevi = _this$state$cardPrevi === void 0 ? {
463
- dataURI: undefined,
464
- orientation: 1
465
- } : _this$state$cardPrevi;
466
- var dataURI = _this$state$cardPrevi.dataURI,
467
- orientation = _this$state$cardPrevi.orientation,
468
- error = _this$state.error,
469
- cardRef = _this$state.cardRef,
470
- isCardVisible = _this$state.isCardVisible;
557
+ var _this$state2 = _this.state,
558
+ status = _this$state2.status,
559
+ progress = _this$state2.progress,
560
+ cardPreview = _this$state2.cardPreview,
561
+ error = _this$state2.error,
562
+ cardRef = _this$state2.cardRef,
563
+ isCardVisible = _this$state2.isCardVisible;
471
564
 
472
565
  var _assertThisInitialize3 = (0, _assertThisInitialized2.default)(_this),
473
566
  metadata = _assertThisInitialize3.metadata;
@@ -483,13 +576,14 @@ var CardBase = /*#__PURE__*/function (_Component) {
483
576
  var nativeLazyLoad = isLazy && !isCardVisible; // Force Media Image to always display img for SSR
484
577
 
485
578
  var forceSyncDisplay = !!ssr;
579
+ var mediaCardCursor = (0, _getMediaCardCursor.getMediaCardCursor)(!!useInlinePlayer, !!shouldOpenMediaViewer, status === 'error' || status === 'failed-processing', !!_this.state.cardPreview, metadata.mediaType);
486
580
 
487
581
  var card = /*#__PURE__*/_react.default.createElement(_cardView.CardView, {
488
582
  status: status,
489
583
  error: error,
490
584
  mediaItemType: mediaItemType,
491
585
  metadata: metadata,
492
- dataURI: dataURI,
586
+ cardPreview: cardPreview,
493
587
  alt: alt,
494
588
  appearance: appearance,
495
589
  resizeMode: resizeMode,
@@ -502,7 +596,6 @@ var CardBase = /*#__PURE__*/function (_Component) {
502
596
  disableOverlay: disableOverlay,
503
597
  progress: progress,
504
598
  onDisplayImage: onDisplayImage,
505
- previewOrientation: orientation,
506
599
  innerRef: _this.setRef,
507
600
  testId: testId,
508
601
  featureFlags: featureFlags,
@@ -511,7 +604,8 @@ var CardBase = /*#__PURE__*/function (_Component) {
511
604
  onImageError: _this.onImageError,
512
605
  onImageLoad: _this.onImageLoad,
513
606
  nativeLazyLoad: nativeLazyLoad,
514
- forceSyncDisplay: forceSyncDisplay
607
+ forceSyncDisplay: forceSyncDisplay,
608
+ mediaCardCursor: mediaCardCursor
515
609
  });
516
610
 
517
611
  return isLazy ? /*#__PURE__*/_react.default.createElement(_viewportDetector.ViewportDetector, {
@@ -527,6 +621,22 @@ var CardBase = /*#__PURE__*/function (_Component) {
527
621
  offsetTop: _viewportDetector.ABS_VIEWPORT_ANCHOR_OFFSET_TOP
528
622
  })) : card;
529
623
  });
624
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "storeSSRData", function () {
625
+ var _this$ssrReliability$;
626
+
627
+ var _this$props10 = _this.props,
628
+ ssr = _this$props10.ssr,
629
+ identifier = _this$props10.identifier;
630
+ var _this$state$cardPrevi = _this.state.cardPreview;
631
+ _this$state$cardPrevi = _this$state$cardPrevi === void 0 ? {} : _this$state$cardPrevi;
632
+ var dataURI = _this$state$cardPrevi.dataURI;
633
+ return (0, _mediaClient2.isFileIdentifier)(identifier) && ssr === 'server' && /*#__PURE__*/_react.default.createElement(_globalScope.StoreSSRDataScript, {
634
+ identifier: identifier,
635
+ dataURI: dataURI,
636
+ dimensions: _this.requestedDimensions,
637
+ error: ((_this$ssrReliability$ = _this.ssrReliability.server) === null || _this$ssrReliability$ === void 0 ? void 0 : _this$ssrReliability$.status) === 'fail' ? _this.ssrReliability.server : undefined
638
+ });
639
+ });
530
640
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCardInViewport", function () {
531
641
  _this.setState({
532
642
  isCardVisible: true
@@ -564,22 +674,46 @@ var CardBase = /*#__PURE__*/function (_Component) {
564
674
 
565
675
  var _cardPreview;
566
676
 
567
- var _this$props9 = _this.props,
568
- _identifier = _this$props9.identifier,
569
- _this$props9$dimensio = _this$props9.dimensions,
570
- _dimensions = _this$props9$dimensio === void 0 ? {} : _this$props9$dimensio,
571
- _ssr = _this$props9.ssr;
677
+ var _error;
572
678
 
573
- if ((0, _mediaClient.isFileIdentifier)(_identifier)) {
679
+ var _this$props11 = _this.props,
680
+ _identifier = _this$props11.identifier,
681
+ _this$props11$dimensi = _this$props11.dimensions,
682
+ _dimensions = _this$props11$dimensi === void 0 ? {} : _this$props11$dimensi,
683
+ _ssr = _this$props11.ssr,
684
+ _mediaClient = _this$props11.mediaClient;
685
+
686
+ if ((0, _mediaClient2.isFileIdentifier)(_identifier)) {
574
687
  var id = _identifier.id;
575
688
  _cardPreview = (0, _getCardPreview.getCardPreviewFromCache)(id, _dimensions);
576
689
 
577
690
  if (!_cardPreview && _ssr) {
578
- _this.fireCommencedEvent();
691
+ var _this$ssrData, _this$ssrData2;
692
+
693
+ _this.ssrData = (0, _globalScope.getSSRData)(_identifier);
579
694
 
580
- _cardPreview = _this.resolveSSRPreview(_identifier, _ssr);
695
+ if ((_this$ssrData = _this.ssrData) !== null && _this$ssrData !== void 0 && _this$ssrData.error) {
696
+ _this.ssrReliability.server = _objectSpread({
697
+ status: 'fail'
698
+ }, _this.ssrData.error);
699
+ }
700
+
701
+ if (!((_this$ssrData2 = _this.ssrData) !== null && _this$ssrData2 !== void 0 && _this$ssrData2.dataURI)) {
702
+ try {
703
+ _cardPreview = (0, _getCardPreview.getSSRCardPreview)(_ssr, _mediaClient, _identifier.id, _this.getImageURLParams(_identifier), _this.getMediaBlobUrlAttrs(_identifier));
704
+ } catch (e) {
705
+ _this.ssrReliability[_ssr] = _objectSpread({
706
+ status: 'fail'
707
+ }, (0, _analytics.extractErrorInfo)(e));
708
+ }
709
+ } else {
710
+ _cardPreview = {
711
+ dataURI: _this.ssrData.dataURI,
712
+ source: 'ssr-data'
713
+ };
714
+ }
581
715
  }
582
- } else if ((0, _mediaClient.isExternalImageIdentifier)(_identifier)) {
716
+ } else if ((0, _mediaClient2.isExternalImageIdentifier)(_identifier)) {
583
717
  _this.fireCommencedEvent();
584
718
 
585
719
  _status = 'loading-preview';
@@ -605,7 +739,8 @@ var CardBase = /*#__PURE__*/function (_Component) {
605
739
  cardPreview: _cardPreview,
606
740
  cardRef: null,
607
741
  isBannedLocalPreview: false,
608
- previewDidRender: false
742
+ previewDidRender: false,
743
+ error: _error
609
744
  };
610
745
  return _this;
611
746
  }
@@ -614,21 +749,32 @@ var CardBase = /*#__PURE__*/function (_Component) {
614
749
  key: "componentDidMount",
615
750
  value: function componentDidMount() {
616
751
  this.hasBeenMounted = true;
617
- var _this$state2 = this.state,
618
- isCardVisible = _this$state2.isCardVisible,
619
- cardPreview = _this$state2.cardPreview;
620
- var _this$props10 = this.props,
621
- identifier = _this$props10.identifier,
622
- ssr = _this$props10.ssr;
623
-
624
- if (isCardVisible && (0, _mediaClient.isFileIdentifier)(identifier)) {
752
+ var _this$state3 = this.state,
753
+ isCardVisible = _this$state3.isCardVisible,
754
+ cardPreview = _this$state3.cardPreview;
755
+ var _this$props12 = this.props,
756
+ identifier = _this$props12.identifier,
757
+ ssr = _this$props12.ssr,
758
+ dimensions = _this$props12.dimensions;
759
+
760
+ if (isCardVisible && (0, _mediaClient2.isFileIdentifier)(identifier)) {
625
761
  this.updateStateForIdentifier(identifier);
626
762
  }
627
763
 
628
- if (isCardVisible && !!ssr && !!cardPreview && (0, _getCardPreview.isSSRClientPreview)(cardPreview) && (0, _mediaClient.isFileIdentifier)(identifier)) {
629
- // Since the SSR preview brings the token in the query params,
630
- // We need to fetch the remote preview to be able to cache it,
631
- this.setCacheSSRPreview(identifier);
764
+ if (isCardVisible && !!ssr && !!cardPreview && (0, _mediaClient2.isFileIdentifier)(identifier)) {
765
+ var _this$ssrData3;
766
+
767
+ if ((0, _getCardPreview.isSSRClientPreview)(cardPreview)) {
768
+ // Since the SSR preview brings the token in the query params,
769
+ // We need to fetch the remote preview to be able to cache it,
770
+ this.setCacheSSRPreview(identifier);
771
+ }
772
+
773
+ if ((0, _getCardPreview.isSSRDataPreview)(cardPreview) && (0, _dimensionComparer.isBigger)((_this$ssrData3 = this.ssrData) === null || _this$ssrData3 === void 0 ? void 0 : _this$ssrData3.dimensions, dimensions)) {
774
+ // If dimensions from Server have changed and are bigger,
775
+ // we need to refetch
776
+ this.refetchSSRPreview(identifier);
777
+ }
632
778
  } // we add a listener for each of the cards on the page
633
779
  // and then check if the triggered listener is from the card
634
780
  // that contains a div in current window.getSelection()
@@ -644,26 +790,26 @@ var CardBase = /*#__PURE__*/function (_Component) {
644
790
  prevIdentifier = prevProps.identifier,
645
791
  prevDimensions = prevProps.dimensions;
646
792
  var prevIsCardVisible = prevState.isCardVisible;
647
- var _this$props11 = this.props,
648
- mediaClient = _this$props11.mediaClient,
649
- identifier = _this$props11.identifier,
650
- dimensions = _this$props11.dimensions,
651
- featureFlags = _this$props11.featureFlags,
652
- useInlinePlayer = _this$props11.useInlinePlayer,
653
- disableOverlay = _this$props11.disableOverlay;
654
- var _this$state3 = this.state,
655
- isCardVisible = _this$state3.isCardVisible,
656
- cardPreview = _this$state3.cardPreview,
657
- status = _this$state3.status,
658
- fileState = _this$state3.fileState,
659
- isBannedLocalPreview = _this$state3.isBannedLocalPreview,
660
- previewDidRender = _this$state3.previewDidRender,
661
- isPlayingFile = _this$state3.isPlayingFile;
662
- var isDifferent = (0, _mediaClient.isDifferentIdentifier)(prevIdentifier, identifier);
793
+ var _this$props13 = this.props,
794
+ mediaClient = _this$props13.mediaClient,
795
+ identifier = _this$props13.identifier,
796
+ dimensions = _this$props13.dimensions,
797
+ featureFlags = _this$props13.featureFlags,
798
+ useInlinePlayer = _this$props13.useInlinePlayer,
799
+ disableOverlay = _this$props13.disableOverlay;
800
+ var _this$state4 = this.state,
801
+ isCardVisible = _this$state4.isCardVisible,
802
+ cardPreview = _this$state4.cardPreview,
803
+ status = _this$state4.status,
804
+ fileState = _this$state4.fileState,
805
+ isBannedLocalPreview = _this$state4.isBannedLocalPreview,
806
+ previewDidRender = _this$state4.previewDidRender,
807
+ isPlayingFile = _this$state4.isPlayingFile;
808
+ var isDifferent = (0, _mediaClient2.isDifferentIdentifier)(prevIdentifier, identifier);
663
809
  var turnedVisible = !prevIsCardVisible && isCardVisible;
664
810
  var isNewMediaClient = prevMediaClient !== mediaClient;
665
811
 
666
- if ((0, _mediaClient.isExternalImageIdentifier)(identifier) && isDifferent) {
812
+ if ((0, _mediaClient2.isExternalImageIdentifier)(identifier) && isDifferent) {
667
813
  this.fireCommencedEvent();
668
814
  var dataURI = identifier.dataURI;
669
815
  this.setState({
@@ -677,7 +823,7 @@ var CardBase = /*#__PURE__*/function (_Component) {
677
823
  });
678
824
  }
679
825
 
680
- if ((0, _mediaClient.isFileIdentifier)(identifier) && (turnedVisible || !!this.subscription && (isNewMediaClient || isDifferent))) {
826
+ if ((0, _mediaClient2.isFileIdentifier)(identifier) && (turnedVisible || !!this.subscription && (isNewMediaClient || isDifferent))) {
681
827
  this.updateStateForIdentifier(identifier);
682
828
  }
683
829
 
@@ -689,7 +835,7 @@ var CardBase = /*#__PURE__*/function (_Component) {
689
835
  }
690
836
  }
691
837
 
692
- if ((0, _mediaClient.isFileIdentifier)(identifier) && fileState && (0, _getCardPreview.shouldResolvePreview)({
838
+ if ((0, _mediaClient2.isFileIdentifier)(identifier) && fileState && (0, _getCardPreview.shouldResolvePreview)({
693
839
  status: status,
694
840
  fileState: fileState,
695
841
  dimensions: dimensions,
@@ -701,7 +847,7 @@ var CardBase = /*#__PURE__*/function (_Component) {
701
847
  this.resolvePreview(identifier, fileState);
702
848
  }
703
849
 
704
- if (turnedVisible && this.props.ssr && !!cardPreview && (0, _getCardPreview.isSSRClientPreview)(cardPreview) && (0, _mediaClient.isFileIdentifier)(identifier)) {
850
+ if (turnedVisible && this.props.ssr && !!cardPreview && (0, _getCardPreview.isSSRClientPreview)(cardPreview) && (0, _mediaClient2.isFileIdentifier)(identifier)) {
705
851
  // Since the SSR preview brings the token in the query params,
706
852
  // We need to fetch the remote preview to be able to cache it,
707
853
  this.setCacheSSRPreview(identifier);
@@ -716,7 +862,7 @@ var CardBase = /*#__PURE__*/function (_Component) {
716
862
  }
717
863
 
718
864
  var isVideo = this.fileAttributes.fileMediatype === 'video';
719
- var videoAvailableToPlay = fileState && (0, _mediaClient.isProcessedFileState)(fileState);
865
+ var videoAvailableToPlay = fileState && (0, _mediaClient2.isProcessedFileState)(fileState);
720
866
 
721
867
  if (isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && videoAvailableToPlay && (0, _mediaCommon.getMediaFeatureFlag)('timestampOnVideo', this.props.featureFlags)) {
722
868
  this.setState({
@@ -774,8 +920,8 @@ var CardBase = /*#__PURE__*/function (_Component) {
774
920
  get: function get() {
775
921
  var dimensions = this.props.dimensions;
776
922
 
777
- var _ref3 = this.state || {},
778
- element = _ref3.cardRef;
923
+ var _ref4 = this.state || {},
924
+ element = _ref4.cardRef;
779
925
 
780
926
  return (0, _getDataURIDimension.getRequestedDimensions)({
781
927
  dimensions: dimensions,
@@ -785,25 +931,25 @@ var CardBase = /*#__PURE__*/function (_Component) {
785
931
  }, {
786
932
  key: "metadata",
787
933
  get: function get() {
788
- var _this$state4;
934
+ var _this$state5;
789
935
 
790
- return (0, _metadata.getFileDetails)(this.props.identifier, (_this$state4 = this.state) === null || _this$state4 === void 0 ? void 0 : _this$state4.fileState);
936
+ return (0, _metadata.getFileDetails)(this.props.identifier, (_this$state5 = this.state) === null || _this$state5 === void 0 ? void 0 : _this$state5.fileState);
791
937
  }
792
938
  }, {
793
939
  key: "fileAttributes",
794
940
  get: function get() {
795
- var _this$state5, _this$state5$fileStat;
941
+ var _this$state6, _this$state6$fileStat;
796
942
 
797
- return (0, _analytics.getFileAttributes)(this.metadata, (_this$state5 = this.state) === null || _this$state5 === void 0 ? void 0 : (_this$state5$fileStat = _this$state5.fileState) === null || _this$state5$fileStat === void 0 ? void 0 : _this$state5$fileStat.status);
943
+ return (0, _analytics.getFileAttributes)(this.metadata, (_this$state6 = this.state) === null || _this$state6 === void 0 ? void 0 : (_this$state6$fileStat = _this$state6.fileState) === null || _this$state6$fileStat === void 0 ? void 0 : _this$state6$fileStat.status);
798
944
  }
799
945
  }, {
800
946
  key: "fireOperationalEvent",
801
947
  value: function fireOperationalEvent() {
802
- var _this$state6 = this.state,
803
- status = _this$state6.status,
804
- error = _this$state6.error;
948
+ var _this$state7 = this.state,
949
+ status = _this$state7.status,
950
+ error = _this$state7.error;
805
951
  var createAnalyticsEvent = this.props.createAnalyticsEvent;
806
- createAnalyticsEvent && (0, _cardAnalytics.fireOperationalEvent)(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), error);
952
+ createAnalyticsEvent && (0, _cardAnalytics.fireOperationalEvent)(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), this.ssrReliability, error);
807
953
  }
808
954
  }, {
809
955
  key: "fireCommencedEvent",
@@ -821,15 +967,15 @@ var CardBase = /*#__PURE__*/function (_Component) {
821
967
  get: function get() {
822
968
  var _this3 = this;
823
969
 
824
- var _this$props12 = this.props,
825
- _this$props12$actions = _this$props12.actions,
826
- actions = _this$props12$actions === void 0 ? [] : _this$props12$actions,
827
- identifier = _this$props12.identifier,
828
- shouldEnableDownloadButton = _this$props12.shouldEnableDownloadButton;
970
+ var _this$props14 = this.props,
971
+ _this$props14$actions = _this$props14.actions,
972
+ actions = _this$props14$actions === void 0 ? [] : _this$props14$actions,
973
+ identifier = _this$props14.identifier,
974
+ shouldEnableDownloadButton = _this$props14.shouldEnableDownloadButton;
829
975
  var status = this.state.status;
830
976
  var metadata = this.metadata;
831
977
 
832
- if ((0, _mediaClient.isFileIdentifier)(identifier) && (status === 'failed-processing' || shouldEnableDownloadButton)) {
978
+ if ((0, _mediaClient2.isFileIdentifier)(identifier) && (status === 'failed-processing' || shouldEnableDownloadButton)) {
833
979
  var downloadAction = {
834
980
  label: 'Download',
835
981
  icon: /*#__PURE__*/_react.default.createElement(_download.default, {
@@ -847,11 +993,11 @@ var CardBase = /*#__PURE__*/function (_Component) {
847
993
  }, {
848
994
  key: "render",
849
995
  value: function render() {
850
- var _this$state7 = this.state,
851
- isPlayingFile = _this$state7.isPlayingFile,
852
- mediaViewerSelectedItem = _this$state7.mediaViewerSelectedItem;
996
+ var _this$state8 = this.state,
997
+ isPlayingFile = _this$state8.isPlayingFile,
998
+ mediaViewerSelectedItem = _this$state8.mediaViewerSelectedItem;
853
999
 
854
- var innerContent = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null);
1000
+ var innerContent = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null, this.storeSSRData());
855
1001
 
856
1002
  return this.props.intl ? innerContent : /*#__PURE__*/_react.default.createElement(_reactIntlNext.IntlProvider, {
857
1003
  locale: "en"