@atlaskit/media-card 72.0.0 → 73.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/dist/cjs/actions.js +2 -2
  3. package/dist/cjs/errors.js +35 -11
  4. package/dist/cjs/files/cardImageView/cardOverlay/styled.js +1 -1
  5. package/dist/cjs/files/cardImageView/index.js +1 -1
  6. package/dist/cjs/files/cardImageView/styled.js +1 -1
  7. package/dist/cjs/index.js +8 -8
  8. package/dist/cjs/root/card/cardAnalytics.js +2 -2
  9. package/dist/cjs/root/card/cardLoader.js +66 -124
  10. package/dist/cjs/root/card/cardState.js +2 -2
  11. package/dist/cjs/root/card/getCardPreview/cache.js +5 -5
  12. package/dist/cjs/root/card/getCardPreview/filePreviewStatus.js +4 -1
  13. package/dist/cjs/root/card/getCardPreview/helpers.js +1 -1
  14. package/dist/cjs/root/card/getCardPreview/index.js +101 -18
  15. package/dist/cjs/root/card/getCardStatus.js +1 -1
  16. package/dist/cjs/root/card/index.js +191 -97
  17. package/dist/cjs/root/cardView.js +44 -57
  18. package/dist/cjs/root/inline/loader.js +45 -14
  19. package/dist/cjs/root/inline/mediaInlineCard.js +31 -11
  20. package/dist/cjs/root/inlinePlayer.js +77 -24
  21. package/dist/cjs/root/styled.js +7 -3
  22. package/dist/cjs/root/ui/actionsBar/styled.js +1 -1
  23. package/dist/cjs/root/ui/blanket/styled.js +1 -1
  24. package/dist/cjs/root/ui/common.js +11 -5
  25. package/dist/cjs/root/ui/iconMessage/index.js +5 -3
  26. package/dist/cjs/root/ui/iconWrapper/styled.js +1 -1
  27. package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +6 -2
  28. package/dist/cjs/root/ui/loadingRateLimited/loadingRateLimited.js +6 -4
  29. package/dist/cjs/root/ui/loadingRateLimited/styled.js +2 -2
  30. package/dist/cjs/root/ui/playButton/styled.js +1 -1
  31. package/dist/cjs/root/ui/progressBar/progressBar.js +7 -4
  32. package/dist/cjs/root/ui/progressBar/styled.js +8 -9
  33. package/dist/cjs/root/ui/styled.js +80 -17
  34. package/dist/cjs/root/ui/tickBox/styled.js +1 -1
  35. package/dist/cjs/root/ui/titleBox/failedTitleBox.js +4 -2
  36. package/dist/cjs/root/ui/titleBox/styled.js +2 -4
  37. package/dist/cjs/root/ui/titleBox/titleBox.js +2 -2
  38. package/dist/cjs/styles/index.js +25 -23
  39. package/dist/cjs/styles/mixins.js +1 -1
  40. package/dist/cjs/utils/analytics.js +2 -1
  41. package/dist/cjs/utils/breakpoint.js +1 -1
  42. package/dist/cjs/utils/cardActions/cardActionsDropdownMenu.js +18 -9
  43. package/dist/cjs/utils/cardActions/index.js +10 -10
  44. package/dist/cjs/utils/cardActions/styled.js +1 -1
  45. package/dist/cjs/utils/cardDimensions.js +1 -1
  46. package/dist/cjs/utils/getErrorMessage.js +2 -2
  47. package/dist/cjs/utils/index.js +46 -46
  48. package/dist/cjs/utils/lightCards/styled.js +1 -1
  49. package/dist/cjs/utils/objectURLCache.js +1 -1
  50. package/dist/cjs/utils/viewportDetector.js +49 -22
  51. package/dist/cjs/version.json +1 -1
  52. package/dist/es2019/errors.js +9 -1
  53. package/dist/es2019/root/card/cardAnalytics.js +1 -1
  54. package/dist/es2019/root/card/cardLoader.js +47 -53
  55. package/dist/es2019/root/card/getCardPreview/filePreviewStatus.js +4 -1
  56. package/dist/es2019/root/card/getCardPreview/index.js +45 -3
  57. package/dist/es2019/root/card/index.js +131 -35
  58. package/dist/es2019/root/cardView.js +26 -40
  59. package/dist/es2019/root/inline/loader.js +15 -4
  60. package/dist/es2019/root/inline/mediaInlineCard.js +30 -10
  61. package/dist/es2019/root/inlinePlayer.js +56 -4
  62. package/dist/es2019/root/styled.js +2 -1
  63. package/dist/es2019/root/ui/common.js +7 -1
  64. package/dist/es2019/root/ui/iconMessage/index.js +3 -2
  65. package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +6 -2
  66. package/dist/es2019/root/ui/loadingRateLimited/loadingRateLimited.js +4 -3
  67. package/dist/es2019/root/ui/loadingRateLimited/styled.js +1 -1
  68. package/dist/es2019/root/ui/progressBar/progressBar.js +5 -3
  69. package/dist/es2019/root/ui/progressBar/styled.js +7 -6
  70. package/dist/es2019/root/ui/styled.js +65 -4
  71. package/dist/es2019/root/ui/titleBox/failedTitleBox.js +3 -2
  72. package/dist/es2019/root/ui/titleBox/styled.js +1 -2
  73. package/dist/es2019/root/ui/titleBox/titleBox.js +1 -1
  74. package/dist/es2019/utils/cardActions/cardActionsDropdownMenu.js +8 -4
  75. package/dist/es2019/utils/getErrorMessage.js +1 -1
  76. package/dist/es2019/utils/viewportDetector.js +48 -18
  77. package/dist/es2019/version.json +1 -1
  78. package/dist/esm/actions.js +2 -2
  79. package/dist/esm/errors.js +28 -9
  80. package/dist/esm/root/card/cardAnalytics.js +1 -1
  81. package/dist/esm/root/card/cardLoader.js +66 -126
  82. package/dist/esm/root/card/cardState.js +2 -2
  83. package/dist/esm/root/card/getCardPreview/cache.js +3 -2
  84. package/dist/esm/root/card/getCardPreview/filePreviewStatus.js +4 -1
  85. package/dist/esm/root/card/getCardPreview/index.js +74 -12
  86. package/dist/esm/root/card/index.js +198 -100
  87. package/dist/esm/root/cardView.js +42 -54
  88. package/dist/esm/root/inline/loader.js +46 -14
  89. package/dist/esm/root/inline/mediaInlineCard.js +30 -10
  90. package/dist/esm/root/inlinePlayer.js +74 -23
  91. package/dist/esm/root/styled.js +3 -2
  92. package/dist/esm/root/ui/common.js +7 -1
  93. package/dist/esm/root/ui/iconMessage/index.js +3 -2
  94. package/dist/esm/root/ui/imageRenderer/imageRenderer.js +6 -2
  95. package/dist/esm/root/ui/loadingRateLimited/loadingRateLimited.js +4 -3
  96. package/dist/esm/root/ui/loadingRateLimited/styled.js +1 -1
  97. package/dist/esm/root/ui/progressBar/progressBar.js +6 -3
  98. package/dist/esm/root/ui/progressBar/styled.js +7 -7
  99. package/dist/esm/root/ui/styled.js +61 -13
  100. package/dist/esm/root/ui/titleBox/failedTitleBox.js +3 -2
  101. package/dist/esm/root/ui/titleBox/styled.js +1 -2
  102. package/dist/esm/root/ui/titleBox/titleBox.js +1 -1
  103. package/dist/esm/utils/cardActions/cardActionsDropdownMenu.js +17 -9
  104. package/dist/esm/utils/getErrorMessage.js +1 -1
  105. package/dist/esm/utils/viewportDetector.js +48 -21
  106. package/dist/esm/version.json +1 -1
  107. package/dist/types/errors.d.ts +9 -3
  108. package/dist/types/index.d.ts +3 -1
  109. package/dist/types/root/card/cardLoader.d.ts +5 -19
  110. package/dist/types/root/card/getCardPreview/index.d.ts +7 -1
  111. package/dist/types/root/card/index.d.ts +9 -8
  112. package/dist/types/root/cardView.d.ts +5 -3
  113. package/dist/types/root/inline/loader.d.ts +2 -0
  114. package/dist/types/root/inline/mediaInlineCard.d.ts +3 -5
  115. package/dist/types/root/inlinePlayer.d.ts +8 -1
  116. package/dist/types/root/styled.d.ts +1 -0
  117. package/dist/types/root/ui/common.d.ts +4 -1
  118. package/dist/types/root/ui/iconMessage/index.d.ts +2 -2
  119. package/dist/types/root/ui/iconWrapper/styled.d.ts +1 -1
  120. package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +3 -2
  121. package/dist/types/root/ui/loadingRateLimited/loadingRateLimited.d.ts +2 -1
  122. package/dist/types/root/ui/loadingRateLimited/styled.d.ts +1 -1
  123. package/dist/types/root/ui/playButton/playButton.d.ts +1 -0
  124. package/dist/types/root/ui/progressBar/progressBar.d.ts +4 -2
  125. package/dist/types/root/ui/progressBar/styled.d.ts +3 -2
  126. package/dist/types/root/ui/styled.d.ts +10 -3
  127. package/dist/types/root/ui/tickBox/tickBox.d.ts +1 -0
  128. package/dist/types/root/ui/titleBox/failedTitleBox.d.ts +3 -3
  129. package/dist/types/root/ui/titleBox/styled.d.ts +1 -1
  130. package/dist/types/root/ui/titleBox/titleBox.d.ts +2 -10
  131. package/dist/types/types.d.ts +1 -1
  132. package/dist/types/utils/getErrorMessage.d.ts +1 -0
  133. package/dist/types/utils/viewportDetector.d.ts +13 -5
  134. package/example-helpers/developmentUseMessage.tsx +14 -0
  135. package/example-helpers/index.tsx +34 -4
  136. package/example-helpers/selectableCard.tsx +2 -1
  137. package/package.json +16 -15
  138. package/dist/cjs/root/card/cardSSRView.js +0 -114
  139. package/dist/cjs/root/ui/Breakpoint.js +0 -13
  140. package/dist/cjs/root/ui/styledSSR.js +0 -108
  141. package/dist/cjs/utils/lazyContent/index.js +0 -56
  142. package/dist/cjs/utils/lazyContent/styled.js +0 -23
  143. package/dist/es2019/root/card/cardSSRView.js +0 -93
  144. package/dist/es2019/root/ui/Breakpoint.js +0 -6
  145. package/dist/es2019/root/ui/styledSSR.js +0 -93
  146. package/dist/es2019/utils/lazyContent/index.js +0 -18
  147. package/dist/es2019/utils/lazyContent/styled.js +0 -12
  148. package/dist/esm/root/card/cardSSRView.js +0 -92
  149. package/dist/esm/root/ui/Breakpoint.js +0 -6
  150. package/dist/esm/root/ui/styledSSR.js +0 -76
  151. package/dist/esm/utils/lazyContent/index.js +0 -41
  152. package/dist/esm/utils/lazyContent/styled.js +0 -14
  153. package/dist/types/root/card/cardSSRView.d.ts +0 -13
  154. package/dist/types/root/ui/Breakpoint.d.ts +0 -4
  155. package/dist/types/root/ui/styledSSR.d.ts +0 -16
  156. package/dist/types/utils/lazyContent/index.d.ts +0 -11
  157. package/dist/types/utils/lazyContent/styled.d.ts +0 -5
@@ -9,15 +9,15 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstruct
9
9
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
10
10
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
11
11
 
12
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
12
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
13
 
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
15
 
16
16
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
17
17
 
18
18
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
19
19
 
20
- import React, { Component } from 'react';
20
+ import React, { Component, createRef } from 'react';
21
21
  import ReactDOM from 'react-dom';
22
22
  import { version as packageVersion, name as packageName } from '../../version.json';
23
23
  import { withAnalyticsEvents } from '@atlaskit/analytics-next';
@@ -25,11 +25,11 @@ import { withMediaAnalyticsContext } from '@atlaskit/media-common';
25
25
  import DownloadIcon from '@atlaskit/icon/glyph/download';
26
26
  import { globalMediaEventEmitter, isDifferentIdentifier, isFileIdentifier, RECENTS_COLLECTION, isImageRepresentationReady, isExternalImageIdentifier, imageResizeModeToFileImageMode } from '@atlaskit/media-client';
27
27
  import { MediaViewer } from '@atlaskit/media-viewer';
28
- import { IntlProvider, intlShape } from 'react-intl';
28
+ import { injectIntl, IntlProvider } from 'react-intl-next';
29
29
  import { CardView } from '../cardView';
30
- import { ViewportDetector } from '../../utils/viewportDetector';
30
+ import { ABS_VIEWPORT_ANCHOR_OFFSET_TOP, ViewportDetector, ViewportAnchor } from '../../utils/viewportDetector';
31
31
  import { getRequestedDimensions } from '../../utils/getDataURIDimension';
32
- import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview } from './getCardPreview';
32
+ import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, fetchAndCacheRemotePreview } from './getCardPreview';
33
33
  import { getFileDetails } from '../../utils/metadata';
34
34
  import { InlinePlayer } from '../inlinePlayer';
35
35
  import { getFileAttributes } from '../../utils/analytics';
@@ -37,6 +37,8 @@ import { isLocalPreviewError, MediaCardError, ensureMediaCardError, ImageLoadErr
37
37
  import { fireOperationalEvent as _fireOperationalEvent, fireCommencedEvent as _fireCommencedEvent, relevantFeatureFlagNames, fireCopiedEvent, fireScreenEvent } from './cardAnalytics';
38
38
  import getDocument from '../../utils/document';
39
39
  import { getCardStateFromFileState, createStateUpdater } from './cardState';
40
+ import { isProcessedFileState } from '@atlaskit/media-client';
41
+ import { getMediaFeatureFlag } from '@atlaskit/media-common';
40
42
  export var CardBase = /*#__PURE__*/function (_Component) {
41
43
  _inherits(CardBase, _Component);
42
44
 
@@ -53,6 +55,10 @@ export var CardBase = /*#__PURE__*/function (_Component) {
53
55
 
54
56
  _defineProperty(_assertThisInitialized(_this), "hasBeenMounted", false);
55
57
 
58
+ _defineProperty(_assertThisInitialized(_this), "viewportPreAnchorRef", /*#__PURE__*/createRef());
59
+
60
+ _defineProperty(_assertThisInitialized(_this), "viewportPostAnchorRef", /*#__PURE__*/createRef());
61
+
56
62
  _defineProperty(_assertThisInitialized(_this), "timeElapsedTillCommenced", performance.now());
57
63
 
58
64
  _defineProperty(_assertThisInitialized(_this), "getImageURLParams", function (_ref) {
@@ -109,6 +115,28 @@ export var CardBase = /*#__PURE__*/function (_Component) {
109
115
  };
110
116
  });
111
117
 
118
+ _defineProperty(_assertThisInitialized(_this), "setCacheSSRPreview", function (identifier) {
119
+ var _this$props3 = _this.props,
120
+ mediaClient = _this$props3.mediaClient,
121
+ _this$props3$dimensio = _this$props3.dimensions,
122
+ dimensions = _this$props3$dimensio === void 0 ? {} : _this$props3$dimensio;
123
+ fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions, _this.getImageURLParams(identifier), _this.getMediaBlobUrlAttrs(identifier)).catch(function () {// No need to log this error.
124
+ // If preview fails, it will be refetched later
125
+ //TODO: test this catch
126
+ // https://product-fabric.atlassian.net/browse/MEX-1071
127
+ });
128
+ });
129
+
130
+ _defineProperty(_assertThisInitialized(_this), "resolveSSRPreview", function (identifier, ssr) {
131
+ var mediaClient = _this.props.mediaClient;
132
+
133
+ try {
134
+ return getSSRCardPreview(ssr, mediaClient, identifier.id, _this.getImageURLParams(identifier), _this.getMediaBlobUrlAttrs(identifier));
135
+ } catch (e) {// TODO: log SSR reliability 'failed'
136
+ // https://product-fabric.atlassian.net/browse/MEX-770
137
+ }
138
+ });
139
+
112
140
  _defineProperty(_assertThisInitialized(_this), "resolvePreview", /*#__PURE__*/function () {
113
141
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(identifier, fileState) {
114
142
  var params, cardPreview, wrappedError;
@@ -180,20 +208,31 @@ export var CardBase = /*#__PURE__*/function (_Component) {
180
208
  _defineProperty(_assertThisInitialized(_this), "onImageError", function () {
181
209
  var cardPreview = _this.state.cardPreview;
182
210
  var error = new ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
211
+ var isLocal = cardPreview && isLocalPreview(cardPreview);
212
+ var isSSR = cardPreview && isSSRClientPreview(cardPreview);
183
213
 
184
- if (cardPreview !== null && cardPreview !== void 0 && cardPreview.source && ['local', 'cache-local'].includes(cardPreview.source)) {
185
- var _this$props3 = _this.props,
186
- identifier = _this$props3.identifier,
187
- _this$props3$dimensio = _this$props3.dimensions,
188
- dimensions = _this$props3$dimensio === void 0 ? {} : _this$props3$dimensio;
189
- isFileIdentifier(identifier) && removeCardPreviewFromCache(identifier.id, dimensions);
214
+ if (isLocal || isSSR) {
215
+ var updateState = {
216
+ cardPreview: undefined
217
+ };
190
218
 
191
- _this.safeSetState({
192
- cardPreview: undefined,
193
- isBannedLocalPreview: true
194
- });
219
+ if (isLocal) {
220
+ updateState.isBannedLocalPreview = true;
221
+
222
+ _this.fireLocalPreviewErrorEvent(error);
223
+ }
224
+
225
+ if (isSSR) {// TODO: set SSR-client reliability 'failed'.
226
+ // https://product-fabric.atlassian.net/browse/MEX-770
227
+ }
228
+
229
+ var _this$props4 = _this.props,
230
+ identifier = _this$props4.identifier,
231
+ _this$props4$dimensio = _this$props4.dimensions,
232
+ dimensions = _this$props4$dimensio === void 0 ? {} : _this$props4$dimensio;
233
+ isFileIdentifier(identifier) && removeCardPreviewFromCache(identifier.id, dimensions);
195
234
 
196
- _this.fireLocalPreviewErrorEvent(error);
235
+ _this.safeSetState(updateState);
197
236
  } else {
198
237
  _this.safeSetState({
199
238
  status: 'error',
@@ -248,10 +287,10 @@ export var CardBase = /*#__PURE__*/function (_Component) {
248
287
  });
249
288
 
250
289
  _defineProperty(_assertThisInitialized(_this), "onCardViewClick", function (event, analyticsEvent) {
251
- var _this$props4 = _this.props,
252
- identifier = _this$props4.identifier,
253
- useInlinePlayer = _this$props4.useInlinePlayer,
254
- shouldOpenMediaViewer = _this$props4.shouldOpenMediaViewer;
290
+ var _this$props5 = _this.props,
291
+ identifier = _this$props5.identifier,
292
+ useInlinePlayer = _this$props5.useInlinePlayer,
293
+ shouldOpenMediaViewer = _this$props5.shouldOpenMediaViewer;
255
294
  var cardPreview = _this.state.cardPreview;
256
295
 
257
296
  var _assertThisInitialize2 = _assertThisInitialized(_this),
@@ -267,7 +306,8 @@ export var CardBase = /*#__PURE__*/function (_Component) {
267
306
 
268
307
  if (useInlinePlayer && isVideo && !!cardPreview) {
269
308
  _this.setState({
270
- isPlayingFile: true
309
+ isPlayingFile: true,
310
+ shouldAutoplay: true
271
311
  });
272
312
  } else if (shouldOpenMediaViewer) {
273
313
  var mediaViewerSelectedItem;
@@ -306,18 +346,20 @@ export var CardBase = /*#__PURE__*/function (_Component) {
306
346
  });
307
347
 
308
348
  _defineProperty(_assertThisInitialized(_this), "renderInlinePlayer", function () {
309
- var _this$props5 = _this.props,
310
- identifier = _this$props5.identifier,
311
- mediaClient = _this$props5.mediaClient,
312
- dimensions = _this$props5.dimensions,
313
- selected = _this$props5.selected,
314
- testId = _this$props5.testId,
315
- originalDimensions = _this$props5.originalDimensions;
349
+ var _this$props6 = _this.props,
350
+ identifier = _this$props6.identifier,
351
+ mediaClient = _this$props6.mediaClient,
352
+ dimensions = _this$props6.dimensions,
353
+ selected = _this$props6.selected,
354
+ testId = _this$props6.testId,
355
+ originalDimensions = _this$props6.originalDimensions;
356
+ var shouldAutoplay = _this.state.shouldAutoplay;
316
357
  return /*#__PURE__*/React.createElement(InlinePlayer, {
317
358
  mediaClient: mediaClient,
318
359
  dimensions: dimensions,
319
360
  originalDimensions: originalDimensions,
320
361
  identifier: identifier,
362
+ autoplay: !!shouldAutoplay,
321
363
  onError: _this.onInlinePlayerError,
322
364
  onClick: _this.onClick,
323
365
  selected: selected,
@@ -355,12 +397,12 @@ export var CardBase = /*#__PURE__*/function (_Component) {
355
397
 
356
398
  _defineProperty(_assertThisInitialized(_this), "renderMediaViewer", function () {
357
399
  var mediaViewerSelectedItem = _this.state.mediaViewerSelectedItem;
358
- var _this$props6 = _this.props,
359
- mediaClient = _this$props6.mediaClient,
360
- identifier = _this$props6.identifier,
361
- mediaViewerDataSource = _this$props6.mediaViewerDataSource,
362
- contextId = _this$props6.contextId,
363
- featureFlags = _this$props6.featureFlags;
400
+ var _this$props7 = _this.props,
401
+ mediaClient = _this$props7.mediaClient,
402
+ identifier = _this$props7.identifier,
403
+ mediaViewerDataSource = _this$props7.mediaViewerDataSource,
404
+ contextId = _this$props7.contextId,
405
+ featureFlags = _this$props7.featureFlags;
364
406
 
365
407
  if (!mediaViewerSelectedItem) {
366
408
  return;
@@ -382,20 +424,21 @@ export var CardBase = /*#__PURE__*/function (_Component) {
382
424
  });
383
425
 
384
426
  _defineProperty(_assertThisInitialized(_this), "renderCard", function () {
385
- var _this$props7 = _this.props,
386
- identifier = _this$props7.identifier,
387
- isLazy = _this$props7.isLazy,
388
- appearance = _this$props7.appearance,
389
- resizeMode = _this$props7.resizeMode,
390
- dimensions = _this$props7.dimensions,
391
- selectable = _this$props7.selectable,
392
- selected = _this$props7.selected,
393
- disableOverlay = _this$props7.disableOverlay,
394
- alt = _this$props7.alt,
395
- testId = _this$props7.testId,
396
- featureFlags = _this$props7.featureFlags,
397
- titleBoxBgColor = _this$props7.titleBoxBgColor,
398
- titleBoxIcon = _this$props7.titleBoxIcon;
427
+ var _this$props8 = _this.props,
428
+ identifier = _this$props8.identifier,
429
+ isLazy = _this$props8.isLazy,
430
+ appearance = _this$props8.appearance,
431
+ resizeMode = _this$props8.resizeMode,
432
+ dimensions = _this$props8.dimensions,
433
+ selectable = _this$props8.selectable,
434
+ selected = _this$props8.selected,
435
+ disableOverlay = _this$props8.disableOverlay,
436
+ alt = _this$props8.alt,
437
+ testId = _this$props8.testId,
438
+ featureFlags = _this$props8.featureFlags,
439
+ titleBoxBgColor = _this$props8.titleBoxBgColor,
440
+ titleBoxIcon = _this$props8.titleBoxIcon,
441
+ ssr = _this$props8.ssr;
399
442
  var mediaItemType = identifier.mediaItemType;
400
443
  var _this$state = _this.state,
401
444
  status = _this$state.status,
@@ -408,7 +451,8 @@ export var CardBase = /*#__PURE__*/function (_Component) {
408
451
  var dataURI = _this$state$cardPrevi.dataURI,
409
452
  orientation = _this$state$cardPrevi.orientation,
410
453
  error = _this$state.error,
411
- cardRef = _this$state.cardRef;
454
+ cardRef = _this$state.cardRef,
455
+ isCardVisible = _this$state.isCardVisible;
412
456
 
413
457
  var _assertThisInitialize3 = _assertThisInitialized(_this),
414
458
  metadata = _assertThisInitialize3.metadata;
@@ -417,8 +461,13 @@ export var CardBase = /*#__PURE__*/function (_Component) {
417
461
  onCardViewClick = _assertThisInitialize4.onCardViewClick,
418
462
  onDisplayImage = _assertThisInitialize4.onDisplayImage,
419
463
  actions = _assertThisInitialize4.actions,
420
- onMouseEnter = _assertThisInitialize4.onMouseEnter;
464
+ onMouseEnter = _assertThisInitialize4.onMouseEnter; // Card can be artificially turned visible before entering the viewport
465
+ // For example, when we have the image in cache
466
+
467
+
468
+ var nativeLazyLoad = isLazy && !isCardVisible; // Force Media Image to always display img for SSR
421
469
 
470
+ var forceSyncDisplay = !!ssr;
422
471
  var card = /*#__PURE__*/React.createElement(CardView, {
423
472
  status: status,
424
473
  error: error,
@@ -444,12 +493,22 @@ export var CardBase = /*#__PURE__*/function (_Component) {
444
493
  titleBoxBgColor: titleBoxBgColor,
445
494
  titleBoxIcon: titleBoxIcon,
446
495
  onImageError: _this.onImageError,
447
- onImageLoad: _this.onImageLoad
496
+ onImageLoad: _this.onImageLoad,
497
+ nativeLazyLoad: nativeLazyLoad,
498
+ forceSyncDisplay: forceSyncDisplay
448
499
  });
449
500
  return isLazy ? /*#__PURE__*/React.createElement(ViewportDetector, {
450
- targetRef: cardRef,
501
+ cardEl: cardRef,
502
+ preAnchorRef: _this.viewportPreAnchorRef,
503
+ postAnchorRef: _this.viewportPostAnchorRef,
451
504
  onVisible: _this.onCardInViewport
452
- }, card) : card;
505
+ }, /*#__PURE__*/React.createElement(ViewportAnchor, {
506
+ ref: _this.viewportPreAnchorRef,
507
+ offsetTop: -ABS_VIEWPORT_ANCHOR_OFFSET_TOP
508
+ }), card, /*#__PURE__*/React.createElement(ViewportAnchor, {
509
+ ref: _this.viewportPostAnchorRef,
510
+ offsetTop: ABS_VIEWPORT_ANCHOR_OFFSET_TOP
511
+ })) : card;
453
512
  });
454
513
 
455
514
  _defineProperty(_assertThisInitialized(_this), "onCardInViewport", function () {
@@ -492,14 +551,21 @@ export var CardBase = /*#__PURE__*/function (_Component) {
492
551
 
493
552
  var _cardPreview;
494
553
 
495
- var _this$props8 = _this.props,
496
- _identifier = _this$props8.identifier,
497
- _this$props8$dimensio = _this$props8.dimensions,
498
- _dimensions = _this$props8$dimensio === void 0 ? {} : _this$props8$dimensio;
554
+ var _this$props9 = _this.props,
555
+ _identifier = _this$props9.identifier,
556
+ _this$props9$dimensio = _this$props9.dimensions,
557
+ _dimensions = _this$props9$dimensio === void 0 ? {} : _this$props9$dimensio,
558
+ _ssr = _this$props9.ssr;
499
559
 
500
560
  if (isFileIdentifier(_identifier)) {
501
561
  var id = _identifier.id;
502
562
  _cardPreview = getCardPreviewFromCache(id, _dimensions);
563
+
564
+ if (!_cardPreview && _ssr) {
565
+ _this.fireCommencedEvent();
566
+
567
+ _cardPreview = _this.resolveSSRPreview(_identifier, _ssr);
568
+ }
503
569
  } else if (isExternalImageIdentifier(_identifier)) {
504
570
  _this.fireCommencedEvent();
505
571
 
@@ -510,15 +576,19 @@ export var CardBase = /*#__PURE__*/function (_Component) {
510
576
  orientation: 1,
511
577
  source: 'external'
512
578
  };
513
- } // If cardPreview is available from local cache, `isCardVisible`
514
- // should be true to avoid flickers during re-mount of the component
579
+ } // If cardPreview is available from local cache or external, `isCardVisible`
580
+ // should be true to avoid flickers during re-mount of the component
581
+ // should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
582
+ // outside the viewport
583
+
515
584
 
585
+ var _isCardVisible = !_this.props.isLazy || !!_cardPreview && !isSSRPreview(_cardPreview);
516
586
 
517
- var isCardVisible = _cardPreview ? true : !_this.props.isLazy;
518
587
  _this.state = {
519
588
  status: _status,
520
- isCardVisible: isCardVisible,
589
+ isCardVisible: _isCardVisible,
521
590
  isPlayingFile: false,
591
+ shouldAutoplay: false,
522
592
  cardPreview: _cardPreview,
523
593
  cardRef: null,
524
594
  isBannedLocalPreview: false,
@@ -531,11 +601,21 @@ export var CardBase = /*#__PURE__*/function (_Component) {
531
601
  key: "componentDidMount",
532
602
  value: function componentDidMount() {
533
603
  this.hasBeenMounted = true;
534
- var isCardVisible = this.state.isCardVisible;
535
- var identifier = this.props.identifier;
604
+ var _this$state2 = this.state,
605
+ isCardVisible = _this$state2.isCardVisible,
606
+ cardPreview = _this$state2.cardPreview;
607
+ var _this$props10 = this.props,
608
+ identifier = _this$props10.identifier,
609
+ ssr = _this$props10.ssr;
536
610
 
537
611
  if (isCardVisible && isFileIdentifier(identifier)) {
538
612
  this.updateStateForIdentifier(identifier);
613
+ }
614
+
615
+ if (isCardVisible && !!ssr && !!cardPreview && isSSRClientPreview(cardPreview) && isFileIdentifier(identifier)) {
616
+ // Since the SSR preview brings the token in the query params,
617
+ // We need to fetch the remote preview to be able to cache it,
618
+ this.setCacheSSRPreview(identifier);
539
619
  } // we add a listener for each of the cards on the page
540
620
  // and then check if the triggered listener is from the card
541
621
  // that contains a div in current window.getSelection()
@@ -551,18 +631,21 @@ export var CardBase = /*#__PURE__*/function (_Component) {
551
631
  prevIdentifier = prevProps.identifier,
552
632
  prevDimensions = prevProps.dimensions;
553
633
  var prevIsCardVisible = prevState.isCardVisible;
554
- var _this$props9 = this.props,
555
- mediaClient = _this$props9.mediaClient,
556
- identifier = _this$props9.identifier,
557
- dimensions = _this$props9.dimensions,
558
- featureFlags = _this$props9.featureFlags;
559
- var _this$state2 = this.state,
560
- isCardVisible = _this$state2.isCardVisible,
561
- cardPreview = _this$state2.cardPreview,
562
- status = _this$state2.status,
563
- fileState = _this$state2.fileState,
564
- isBannedLocalPreview = _this$state2.isBannedLocalPreview,
565
- previewDidRender = _this$state2.previewDidRender;
634
+ var _this$props11 = this.props,
635
+ mediaClient = _this$props11.mediaClient,
636
+ identifier = _this$props11.identifier,
637
+ dimensions = _this$props11.dimensions,
638
+ featureFlags = _this$props11.featureFlags,
639
+ useInlinePlayer = _this$props11.useInlinePlayer,
640
+ disableOverlay = _this$props11.disableOverlay;
641
+ var _this$state3 = this.state,
642
+ isCardVisible = _this$state3.isCardVisible,
643
+ cardPreview = _this$state3.cardPreview,
644
+ status = _this$state3.status,
645
+ fileState = _this$state3.fileState,
646
+ isBannedLocalPreview = _this$state3.isBannedLocalPreview,
647
+ previewDidRender = _this$state3.previewDidRender,
648
+ isPlayingFile = _this$state3.isPlayingFile;
566
649
  var isDifferent = isDifferentIdentifier(prevIdentifier, identifier);
567
650
  var turnedVisible = !prevIsCardVisible && isCardVisible;
568
651
  var isNewMediaClient = prevMediaClient !== mediaClient;
@@ -605,13 +688,28 @@ export var CardBase = /*#__PURE__*/function (_Component) {
605
688
  this.resolvePreview(identifier, fileState);
606
689
  }
607
690
 
691
+ if (turnedVisible && this.props.ssr && !!cardPreview && isSSRClientPreview(cardPreview) && isFileIdentifier(identifier)) {
692
+ // Since the SSR preview brings the token in the query params,
693
+ // We need to fetch the remote preview to be able to cache it,
694
+ this.setCacheSSRPreview(identifier);
695
+ }
696
+
608
697
  if (previewDidRender && // We should't complete if status is uploading
609
- ['loading', 'loading-preview', 'processing'].includes(status)) {
698
+ ['loading-preview', 'processing'].includes(status)) {
610
699
  this.safeSetState({
611
700
  status: 'complete'
612
701
  });
613
702
  this.unsubscribe();
614
703
  }
704
+
705
+ var isVideo = this.fileAttributes.fileMediatype === 'video';
706
+ var videoAvailableToPlay = fileState && isProcessedFileState(fileState);
707
+
708
+ if (isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && videoAvailableToPlay && getMediaFeatureFlag('timestampOnVideo', this.props.featureFlags)) {
709
+ this.setState({
710
+ isPlayingFile: true
711
+ });
712
+ }
615
713
  }
616
714
  }, {
617
715
  key: "componentWillUnmount",
@@ -662,7 +760,10 @@ export var CardBase = /*#__PURE__*/function (_Component) {
662
760
  key: "requestedDimensions",
663
761
  get: function get() {
664
762
  var dimensions = this.props.dimensions;
665
- var element = this.state.cardRef;
763
+
764
+ var _ref3 = this.state || {},
765
+ element = _ref3.cardRef;
766
+
666
767
  return getRequestedDimensions({
667
768
  dimensions: dimensions,
668
769
  element: element
@@ -671,23 +772,23 @@ export var CardBase = /*#__PURE__*/function (_Component) {
671
772
  }, {
672
773
  key: "metadata",
673
774
  get: function get() {
674
- var _this$state3;
775
+ var _this$state4;
675
776
 
676
- return getFileDetails(this.props.identifier, (_this$state3 = this.state) === null || _this$state3 === void 0 ? void 0 : _this$state3.fileState);
777
+ return getFileDetails(this.props.identifier, (_this$state4 = this.state) === null || _this$state4 === void 0 ? void 0 : _this$state4.fileState);
677
778
  }
678
779
  }, {
679
780
  key: "fileAttributes",
680
781
  get: function get() {
681
- var _this$state4, _this$state4$fileStat;
782
+ var _this$state5, _this$state5$fileStat;
682
783
 
683
- return getFileAttributes(this.metadata, (_this$state4 = this.state) === null || _this$state4 === void 0 ? void 0 : (_this$state4$fileStat = _this$state4.fileState) === null || _this$state4$fileStat === void 0 ? void 0 : _this$state4$fileStat.status);
784
+ return 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);
684
785
  }
685
786
  }, {
686
787
  key: "fireOperationalEvent",
687
788
  value: function fireOperationalEvent() {
688
- var _this$state5 = this.state,
689
- status = _this$state5.status,
690
- error = _this$state5.error;
789
+ var _this$state6 = this.state,
790
+ status = _this$state6.status,
791
+ error = _this$state6.error;
691
792
  var createAnalyticsEvent = this.props.createAnalyticsEvent;
692
793
  createAnalyticsEvent && _fireOperationalEvent(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), error);
693
794
  }
@@ -707,11 +808,11 @@ export var CardBase = /*#__PURE__*/function (_Component) {
707
808
  get: function get() {
708
809
  var _this3 = this;
709
810
 
710
- var _this$props10 = this.props,
711
- _this$props10$actions = _this$props10.actions,
712
- actions = _this$props10$actions === void 0 ? [] : _this$props10$actions,
713
- identifier = _this$props10.identifier,
714
- shouldEnableDownloadButton = _this$props10.shouldEnableDownloadButton;
811
+ var _this$props12 = this.props,
812
+ _this$props12$actions = _this$props12.actions,
813
+ actions = _this$props12$actions === void 0 ? [] : _this$props12$actions,
814
+ identifier = _this$props12.identifier,
815
+ shouldEnableDownloadButton = _this$props12.shouldEnableDownloadButton;
715
816
  var status = this.state.status;
716
817
  var metadata = this.metadata;
717
818
 
@@ -733,11 +834,11 @@ export var CardBase = /*#__PURE__*/function (_Component) {
733
834
  }, {
734
835
  key: "render",
735
836
  value: function render() {
736
- var _this$state6 = this.state,
737
- isPlayingFile = _this$state6.isPlayingFile,
738
- mediaViewerSelectedItem = _this$state6.mediaViewerSelectedItem;
837
+ var _this$state7 = this.state,
838
+ isPlayingFile = _this$state7.isPlayingFile,
839
+ mediaViewerSelectedItem = _this$state7.mediaViewerSelectedItem;
739
840
  var innerContent = /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null);
740
- return this.context.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
841
+ return this.props.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
741
842
  locale: "en"
742
843
  }, innerContent);
743
844
  }
@@ -755,11 +856,6 @@ _defineProperty(CardBase, "defaultProps", {
755
856
  featureFlags: {}
756
857
  });
757
858
 
758
- _defineProperty(CardBase, "contextTypes", {
759
- // Required to detect a parent IntlProvider
760
- intl: intlShape
761
- });
762
-
763
859
  export var Card = withMediaAnalyticsContext({
764
860
  packageVersion: packageVersion,
765
861
  packageName: packageName,
@@ -767,4 +863,6 @@ export var Card = withMediaAnalyticsContext({
767
863
  component: 'mediaCard'
768
864
  }, {
769
865
  filterFeatureFlags: relevantFeatureFlagNames
770
- })(withAnalyticsEvents()(CardBase));
866
+ })(withAnalyticsEvents()(injectIntl(CardBase, {
867
+ enforceContext: false
868
+ })));