@atlaskit/media-card 70.10.0 → 72.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.
Files changed (150) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/dist/cjs/errors.js +76 -5
  3. package/dist/cjs/files/cardImageView/index.js +58 -89
  4. package/dist/cjs/files/index.js +0 -6
  5. package/dist/cjs/index.js +16 -6
  6. package/dist/cjs/root/card/cardAnalytics.js +33 -19
  7. package/dist/cjs/root/card/cardConstants.js +8 -0
  8. package/dist/cjs/root/card/cardLoader.js +66 -124
  9. package/dist/cjs/root/card/cardState.js +50 -0
  10. package/dist/cjs/root/card/getCardPreview/cache.js +5 -0
  11. package/dist/cjs/root/card/getCardPreview/filePreviewStatus.js +50 -0
  12. package/dist/cjs/root/card/getCardPreview/helpers.js +13 -21
  13. package/dist/cjs/root/card/getCardPreview/index.js +171 -100
  14. package/dist/cjs/root/card/getCardStatus.js +7 -1
  15. package/dist/cjs/root/card/index.js +407 -322
  16. package/dist/cjs/root/cardView.js +115 -76
  17. package/dist/cjs/root/index.js +9 -1
  18. package/dist/cjs/root/inline/loader.js +22 -21
  19. package/dist/cjs/root/inline/{inlineMediaCard.js → mediaInlineCard.js} +72 -25
  20. package/dist/cjs/root/inlinePlayer.js +5 -15
  21. package/dist/cjs/root/ui/iconMessage/index.js +17 -9
  22. package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +36 -115
  23. package/dist/cjs/root/ui/styled.js +1 -1
  24. package/dist/cjs/root/ui/titleBox/failedTitleBox.js +7 -3
  25. package/dist/cjs/utils/analytics.js +26 -43
  26. package/dist/cjs/utils/cardActions/cardActionsDropdownMenu.js +16 -9
  27. package/dist/cjs/utils/dimensionComparer.js +1 -1
  28. package/dist/cjs/utils/document.js +12 -0
  29. package/dist/cjs/utils/getDataURIDimension.js +13 -2
  30. package/dist/cjs/utils/metadata.js +11 -3
  31. package/dist/cjs/utils/objectURLCache.js +6 -0
  32. package/dist/cjs/utils/resizeModeToMediaImageProps.js +13 -0
  33. package/dist/cjs/utils/shouldDisplayImageThumbnail.js +1 -1
  34. package/dist/cjs/version.json +1 -1
  35. package/dist/es2019/errors.js +42 -2
  36. package/dist/es2019/files/cardImageView/index.js +12 -46
  37. package/dist/es2019/files/index.js +1 -1
  38. package/dist/es2019/index.js +3 -3
  39. package/dist/es2019/root/card/cardAnalytics.js +23 -17
  40. package/dist/es2019/root/card/cardConstants.js +1 -0
  41. package/dist/es2019/root/card/cardLoader.js +47 -53
  42. package/dist/es2019/root/card/cardState.js +26 -0
  43. package/dist/es2019/root/card/getCardPreview/cache.js +5 -0
  44. package/dist/es2019/root/card/getCardPreview/filePreviewStatus.js +35 -0
  45. package/dist/es2019/root/card/getCardPreview/helpers.js +2 -12
  46. package/dist/es2019/root/card/getCardPreview/index.js +112 -79
  47. package/dist/es2019/root/card/getCardStatus.js +1 -0
  48. package/dist/es2019/root/card/index.js +356 -254
  49. package/dist/es2019/root/cardView.js +98 -58
  50. package/dist/es2019/root/index.js +2 -1
  51. package/dist/es2019/root/inline/loader.js +16 -15
  52. package/dist/es2019/root/inline/mediaInlineCard.js +132 -0
  53. package/dist/es2019/root/inlinePlayer.js +5 -13
  54. package/dist/es2019/root/ui/iconMessage/index.js +10 -6
  55. package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +26 -74
  56. package/dist/es2019/root/ui/styled.js +1 -0
  57. package/dist/es2019/root/ui/titleBox/failedTitleBox.js +5 -3
  58. package/dist/es2019/utils/analytics.js +29 -40
  59. package/dist/es2019/utils/cardActions/cardActionsDropdownMenu.js +8 -4
  60. package/dist/es2019/utils/dimensionComparer.js +1 -1
  61. package/dist/es2019/utils/document.js +1 -0
  62. package/dist/es2019/utils/getDataURIDimension.js +8 -0
  63. package/dist/es2019/utils/metadata.js +12 -4
  64. package/dist/es2019/utils/objectURLCache.js +5 -0
  65. package/dist/es2019/utils/resizeModeToMediaImageProps.js +6 -0
  66. package/dist/es2019/utils/shouldDisplayImageThumbnail.js +1 -1
  67. package/dist/es2019/version.json +1 -1
  68. package/dist/esm/errors.js +60 -1
  69. package/dist/esm/files/cardImageView/index.js +55 -87
  70. package/dist/esm/files/index.js +1 -1
  71. package/dist/esm/index.js +3 -3
  72. package/dist/esm/root/card/cardAnalytics.js +23 -18
  73. package/dist/esm/root/card/cardConstants.js +1 -0
  74. package/dist/esm/root/card/cardLoader.js +66 -126
  75. package/dist/esm/root/card/cardState.js +32 -0
  76. package/dist/esm/root/card/getCardPreview/cache.js +6 -0
  77. package/dist/esm/root/card/getCardPreview/filePreviewStatus.js +35 -0
  78. package/dist/esm/root/card/getCardPreview/helpers.js +13 -21
  79. package/dist/esm/root/card/getCardPreview/index.js +142 -95
  80. package/dist/esm/root/card/getCardStatus.js +3 -0
  81. package/dist/esm/root/card/index.js +416 -325
  82. package/dist/esm/root/cardView.js +114 -73
  83. package/dist/esm/root/index.js +2 -1
  84. package/dist/esm/root/inline/loader.js +23 -22
  85. package/dist/esm/root/inline/mediaInlineCard.js +145 -0
  86. package/dist/esm/root/inlinePlayer.js +5 -13
  87. package/dist/esm/root/ui/iconMessage/index.js +12 -7
  88. package/dist/esm/root/ui/imageRenderer/imageRenderer.js +28 -106
  89. package/dist/esm/root/ui/styled.js +1 -1
  90. package/dist/esm/root/ui/titleBox/failedTitleBox.js +6 -3
  91. package/dist/esm/utils/analytics.js +22 -35
  92. package/dist/esm/utils/cardActions/cardActionsDropdownMenu.js +16 -9
  93. package/dist/esm/utils/dimensionComparer.js +1 -1
  94. package/dist/esm/utils/document.js +3 -0
  95. package/dist/esm/utils/getDataURIDimension.js +8 -0
  96. package/dist/esm/utils/metadata.js +12 -4
  97. package/dist/esm/utils/objectURLCache.js +6 -0
  98. package/dist/esm/utils/resizeModeToMediaImageProps.js +6 -0
  99. package/dist/esm/utils/shouldDisplayImageThumbnail.js +1 -1
  100. package/dist/esm/version.json +1 -1
  101. package/dist/types/errors.d.ts +15 -1
  102. package/dist/types/files/cardImageView/index.d.ts +5 -12
  103. package/dist/types/files/cardImageView/styled.d.ts +1 -1
  104. package/dist/types/files/index.d.ts +1 -1
  105. package/dist/types/index.d.ts +11 -13
  106. package/dist/types/root/card/cardAnalytics.d.ts +5 -7
  107. package/dist/types/root/card/cardConstants.d.ts +1 -0
  108. package/dist/types/root/card/cardLoader.d.ts +4 -18
  109. package/dist/types/root/card/cardState.d.ts +5 -0
  110. package/dist/types/root/card/getCardPreview/cache.d.ts +4 -2
  111. package/dist/types/root/card/getCardPreview/filePreviewStatus.d.ts +5 -0
  112. package/dist/types/root/card/getCardPreview/helpers.d.ts +4 -5
  113. package/dist/types/root/card/getCardPreview/index.d.ts +25 -14
  114. package/dist/types/root/card/getCardStatus.d.ts +1 -0
  115. package/dist/types/root/card/index.d.ts +18 -15
  116. package/dist/types/root/cardView.d.ts +14 -8
  117. package/dist/types/root/index.d.ts +1 -0
  118. package/dist/types/root/inline/loader.d.ts +8 -8
  119. package/dist/types/root/inline/{inlineMediaCard.d.ts → mediaInlineCard.d.ts} +4 -4
  120. package/dist/types/root/inlinePlayer.d.ts +1 -1
  121. package/dist/types/root/ui/iconMessage/index.d.ts +7 -2
  122. package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +5 -18
  123. package/dist/types/root/ui/titleBox/failedTitleBox.d.ts +2 -0
  124. package/dist/types/types.d.ts +9 -1
  125. package/dist/types/utils/analytics.d.ts +20 -21
  126. package/dist/types/utils/cardDimensions.d.ts +5 -1
  127. package/dist/types/utils/dimensionComparer.d.ts +1 -1
  128. package/dist/types/utils/document.d.ts +2 -0
  129. package/dist/types/utils/getDataURIDimension.d.ts +3 -1
  130. package/dist/types/utils/index.d.ts +1 -0
  131. package/dist/types/utils/lazyContent/styled.d.ts +1 -1
  132. package/dist/types/utils/lightCards/types.d.ts +1 -1
  133. package/dist/types/utils/metadata.d.ts +2 -2
  134. package/dist/types/utils/objectURLCache.d.ts +2 -1
  135. package/dist/types/utils/resizeModeToMediaImageProps.d.ts +5 -0
  136. package/dist/types/utils/shouldDisplayImageThumbnail.d.ts +1 -1
  137. package/example-helpers/developmentUseMessage.tsx +14 -0
  138. package/example-helpers/index.tsx +55 -4
  139. package/example-helpers/selectableCard.tsx +2 -1
  140. package/package.json +18 -14
  141. package/dist/cjs/root/card/getCardPreview/types.js +0 -5
  142. package/dist/cjs/utils/fileAttributesContext.js +0 -40
  143. package/dist/es2019/root/card/getCardPreview/types.js +0 -1
  144. package/dist/es2019/root/inline/inlineMediaCard.js +0 -92
  145. package/dist/es2019/utils/fileAttributesContext.js +0 -19
  146. package/dist/esm/root/card/getCardPreview/types.js +0 -1
  147. package/dist/esm/root/inline/inlineMediaCard.js +0 -100
  148. package/dist/esm/utils/fileAttributesContext.js +0 -18
  149. package/dist/types/root/card/getCardPreview/types.d.ts +0 -5
  150. package/dist/types/utils/fileAttributesContext.d.ts +0 -10
@@ -23,26 +23,27 @@ import { version as packageVersion, name as packageName } from '../../version.js
23
23
  import { withAnalyticsEvents } from '@atlaskit/analytics-next';
24
24
  import { withMediaAnalyticsContext } from '@atlaskit/media-common';
25
25
  import DownloadIcon from '@atlaskit/icon/glyph/download';
26
- import { addFileAttrsToUrl, globalMediaEventEmitter, isDifferentIdentifier, isFileIdentifier, isErrorFileState, RECENTS_COLLECTION, isImageRepresentationReady } from '@atlaskit/media-client';
26
+ import { globalMediaEventEmitter, isDifferentIdentifier, isFileIdentifier, RECENTS_COLLECTION, isImageRepresentationReady, isExternalImageIdentifier, imageResizeModeToFileImageMode } from '@atlaskit/media-client';
27
27
  import { MediaViewer } from '@atlaskit/media-viewer';
28
28
  import { IntlProvider, intlShape } from 'react-intl';
29
29
  import { CardView } from '../cardView';
30
30
  import { ViewportDetector } from '../../utils/viewportDetector';
31
- import { getDataURIDimension } from '../../utils/getDataURIDimension';
32
- import { shouldGetCardPreview, extractFilePreviewStatus, getCardPreview, getCardPreviewFromCache, getFilePreviewFromFileState } from './getCardPreview';
31
+ import { getRequestedDimensions } from '../../utils/getDataURIDimension';
32
+ import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, fetchAndCacheRemotePreview } from './getCardPreview';
33
33
  import { getFileDetails } from '../../utils/metadata';
34
- import { isBigger } from '../../utils/dimensionComparer';
35
- import { getCardStatus } from './getCardStatus';
36
34
  import { InlinePlayer } from '../inlinePlayer';
37
- import { fireMediaCardEvent, getFileAttributes, getRenderCommencedEventPayload, getCopiedFilePayload } from '../../utils/analytics';
38
- import { FileAttributesProvider } from '../../utils/fileAttributesContext';
39
- import { isRemotePreviewError, MediaCardError, ensureMediaCardError } from '../../errors';
40
- import { fireOperationalEvent, relevantFeatureFlagNames } from './cardAnalytics';
35
+ import { getFileAttributes } from '../../utils/analytics';
36
+ import { isLocalPreviewError, MediaCardError, ensureMediaCardError, ImageLoadError } from '../../errors';
37
+ import { fireOperationalEvent as _fireOperationalEvent, fireCommencedEvent as _fireCommencedEvent, relevantFeatureFlagNames, fireCopiedEvent, fireScreenEvent } from './cardAnalytics';
38
+ import getDocument from '../../utils/document';
39
+ import { getCardStateFromFileState, createStateUpdater } from './cardState';
41
40
  export var CardBase = /*#__PURE__*/function (_Component) {
42
41
  _inherits(CardBase, _Component);
43
42
 
44
43
  var _super = _createSuper(CardBase);
45
44
 
45
+ // We initialise timeElapsedTillCommenced
46
+ // to avoid extra branching on a possibly undefined value.
46
47
  function CardBase(props) {
47
48
  var _this;
48
49
 
@@ -52,93 +53,217 @@ export var CardBase = /*#__PURE__*/function (_Component) {
52
53
 
53
54
  _defineProperty(_assertThisInitialized(_this), "hasBeenMounted", false);
54
55
 
55
- _defineProperty(_assertThisInitialized(_this), "onCopyListener", function () {
56
- if (typeof window.getSelection === 'function') {
57
- var selection = window.getSelection();
58
- var cardRef = _this.state.cardRef;
56
+ _defineProperty(_assertThisInitialized(_this), "timeElapsedTillCommenced", performance.now());
59
57
 
60
- if (cardRef && selection && selection.containsNode && selection.containsNode(cardRef, true)) {
61
- _this.fireFileCopiedEvent();
62
- }
63
- }
58
+ _defineProperty(_assertThisInitialized(_this), "getImageURLParams", function (_ref) {
59
+ var collection = _ref.collectionName;
60
+ return _objectSpread(_objectSpread({
61
+ collection: collection,
62
+ mode: imageResizeModeToFileImageMode(_this.props.resizeMode)
63
+ }, _this.requestedDimensions), {}, {
64
+ allowAnimated: true
65
+ });
64
66
  });
65
67
 
66
- _defineProperty(_assertThisInitialized(_this), "shouldRefetchImage", function (current, next) {
67
- if (!current || !next) {
68
- return false;
69
- }
68
+ _defineProperty(_assertThisInitialized(_this), "getMediaBlobUrlAttrs", function (identifier, fileState) {
69
+ var id = identifier.id,
70
+ collection = identifier.collectionName;
71
+ var _this$props = _this.props,
72
+ originalDimensions = _this$props.originalDimensions,
73
+ contextId = _this$props.contextId,
74
+ alt = _this$props.alt;
75
+
76
+ var _getFileDetails = getFileDetails(identifier, fileState),
77
+ mimeType = _getFileDetails.mimeType,
78
+ name = _getFileDetails.name,
79
+ size = _getFileDetails.size;
80
+
81
+ return contextId ? _objectSpread(_objectSpread({
82
+ id: id,
83
+ collection: collection,
84
+ contextId: contextId,
85
+ mimeType: mimeType,
86
+ name: name,
87
+ size: size
88
+ }, originalDimensions || _this.requestedDimensions), {}, {
89
+ alt: alt
90
+ }) : undefined;
91
+ });
70
92
 
71
- return isBigger(current, next);
93
+ _defineProperty(_assertThisInitialized(_this), "getCardPreviewParams", function (identifier, fileState) {
94
+ var isBannedLocalPreview = _this.state.isBannedLocalPreview;
95
+ var id = identifier.id;
96
+ var _this$props2 = _this.props,
97
+ _this$props2$dimensio = _this$props2.dimensions,
98
+ dimensions = _this$props2$dimensio === void 0 ? {} : _this$props2$dimensio,
99
+ mediaClient = _this$props2.mediaClient;
100
+ return {
101
+ mediaClient: mediaClient,
102
+ id: id,
103
+ dimensions: dimensions,
104
+ onLocalPreviewError: _this.fireLocalPreviewErrorEvent,
105
+ filePreview: isBannedLocalPreview ? undefined : getFilePreviewFromFileState(fileState),
106
+ isRemotePreviewReady: isImageRepresentationReady(fileState),
107
+ imageUrlParams: _this.getImageURLParams(identifier),
108
+ mediaBlobUrlAttrs: _this.getMediaBlobUrlAttrs(identifier, fileState)
109
+ };
72
110
  });
73
111
 
74
- _defineProperty(_assertThisInitialized(_this), "isLatestCardStatusUpdate", function (cardStatusUpdateTimestamp) {
75
- return !_this.lastCardStatusUpdateTimestamp || _this.lastCardStatusUpdateTimestamp <= cardStatusUpdateTimestamp;
112
+ _defineProperty(_assertThisInitialized(_this), "setCacheSSRPreview", function (identifier) {
113
+ var _this$props3 = _this.props,
114
+ mediaClient = _this$props3.mediaClient,
115
+ _this$props3$dimensio = _this$props3.dimensions,
116
+ dimensions = _this$props3$dimensio === void 0 ? {} : _this$props3$dimensio;
117
+ fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions, _this.getImageURLParams(identifier), _this.getMediaBlobUrlAttrs(identifier)).catch(function () {// No need to log this error.
118
+ // If preview fails, it will be refetched later
119
+ //TODO: test this catch
120
+ // https://product-fabric.atlassian.net/browse/MEX-1071
121
+ });
76
122
  });
77
123
 
78
- _defineProperty(_assertThisInitialized(_this), "onLocalPreviewError", function (error) {// TODO: track local preview success rate
79
- // https://product-fabric.atlassian.net/browse/MEX-774
124
+ _defineProperty(_assertThisInitialized(_this), "resolveSSRPreview", function (identifier, ssr) {
125
+ var mediaClient = _this.props.mediaClient;
126
+
127
+ try {
128
+ return getSSRCardPreview(ssr, mediaClient, identifier.id, _this.getImageURLParams(identifier), _this.getMediaBlobUrlAttrs(identifier));
129
+ } catch (e) {// TODO: log SSR reliability 'failed'
130
+ // https://product-fabric.atlassian.net/browse/MEX-770
131
+ }
80
132
  });
81
133
 
82
- _defineProperty(_assertThisInitialized(_this), "createAddContextToDataURI", function (fileId, fileState, _ref, collectionName) {
83
- var width = _ref.width,
84
- height = _ref.height;
85
- return function (dataURI) {
86
- var _this$props = _this.props,
87
- contextId = _this$props.contextId,
88
- alt = _this$props.alt;
134
+ _defineProperty(_assertThisInitialized(_this), "resolvePreview", /*#__PURE__*/function () {
135
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(identifier, fileState) {
136
+ var params, cardPreview, wrappedError;
137
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
138
+ while (1) {
139
+ switch (_context.prev = _context.next) {
140
+ case 0:
141
+ _context.prev = 0;
142
+ params = _this.getCardPreviewParams(identifier, fileState);
143
+ _context.next = 4;
144
+ return getCardPreview(params);
145
+
146
+ case 4:
147
+ cardPreview = _context.sent;
148
+
149
+ _this.safeSetState({
150
+ cardPreview: cardPreview
151
+ });
152
+
153
+ _context.next = 12;
154
+ break;
155
+
156
+ case 8:
157
+ _context.prev = 8;
158
+ _context.t0 = _context["catch"](0);
159
+ wrappedError = ensureMediaCardError('preview-fetch', _context.t0); // If remote preview fails, we set status 'error'
160
+ // If local preview fails (i.e, no remote preview available),
161
+ // we can stay in the same status until there is a remote preview available
162
+ // If it's any other error we set status 'error'
163
+
164
+ if (isLocalPreviewError(wrappedError)) {
165
+ _this.safeSetState({
166
+ isBannedLocalPreview: true
167
+ });
168
+ } else {
169
+ _this.safeSetState({
170
+ status: 'error',
171
+ error: wrappedError
172
+ });
173
+ }
89
174
 
90
- if (!contextId) {
91
- return dataURI;
92
- }
175
+ case 12:
176
+ case "end":
177
+ return _context.stop();
178
+ }
179
+ }
180
+ }, _callee, null, [[0, 8]]);
181
+ }));
93
182
 
94
- var metadata = getFileDetails(fileState);
95
- return addFileAttrsToUrl(dataURI, {
96
- id: fileId,
97
- collection: collectionName,
98
- contextId: contextId,
99
- mimeType: metadata.mimeType,
100
- name: metadata.name,
101
- size: metadata.size,
102
- width: width,
103
- height: height,
104
- alt: alt
105
- });
183
+ return function (_x, _x2) {
184
+ return _ref2.apply(this, arguments);
106
185
  };
107
- });
186
+ }());
108
187
 
109
- _defineProperty(_assertThisInitialized(_this), "getCardPreviewParams", function (id, collectionName, fileState) {
188
+ _defineProperty(_assertThisInitialized(_this), "getPerformanceAttributes", function () {
110
189
  var _assertThisInitialize = _assertThisInitialized(_this),
111
- requestedDimensions = _assertThisInitialize.requestedDimensions,
112
- onLocalPreviewError = _assertThisInitialize.onLocalPreviewError;
190
+ timeElapsedTillCommenced = _assertThisInitialize.timeElapsedTillCommenced;
113
191
 
114
- var _this$props2 = _this.props,
115
- _this$props2$dimensio = _this$props2.dimensions,
116
- dimensions = _this$props2$dimensio === void 0 ? {} : _this$props2$dimensio,
117
- originalDimensions = _this$props2.originalDimensions,
118
- resizeMode = _this$props2.resizeMode,
119
- mediaClient = _this$props2.mediaClient;
192
+ var timeElapsedTillEvent = performance.now();
193
+ var durationSinceCommenced = timeElapsedTillCommenced && timeElapsedTillEvent - timeElapsedTillCommenced;
120
194
  return {
121
- mediaClient: mediaClient,
122
- id: id,
123
- collectionName: collectionName,
124
- dimensions: dimensions,
125
- resizeMode: resizeMode,
126
- requestedDimensions: requestedDimensions,
127
- onLocalPreviewError: onLocalPreviewError,
128
- filePreview: getFilePreviewFromFileState(fileState),
129
- isRemotePreviewReady: isImageRepresentationReady(fileState),
130
- addContextToDataURI: _this.createAddContextToDataURI(id, fileState, originalDimensions || _this.requestedDimensions, collectionName)
195
+ overall: {
196
+ durationSincePageStart: timeElapsedTillEvent,
197
+ durationSinceCommenced: durationSinceCommenced
198
+ }
131
199
  };
132
200
  });
133
201
 
134
- _defineProperty(_assertThisInitialized(_this), "fireFileCopiedEvent", function () {
202
+ _defineProperty(_assertThisInitialized(_this), "onImageError", function () {
203
+ var cardPreview = _this.state.cardPreview;
204
+ var error = new ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
205
+ var isLocal = cardPreview && isLocalPreview(cardPreview);
206
+ var isSSR = cardPreview && isSSRClientPreview(cardPreview);
207
+
208
+ if (isLocal || isSSR) {
209
+ var updateState = {
210
+ cardPreview: undefined
211
+ };
212
+
213
+ if (isLocal) {
214
+ updateState.isBannedLocalPreview = true;
215
+
216
+ _this.fireLocalPreviewErrorEvent(error);
217
+ }
218
+
219
+ if (isSSR) {// TODO: set SSR-client reliability 'failed'.
220
+ // https://product-fabric.atlassian.net/browse/MEX-770
221
+ }
222
+
223
+ var _this$props4 = _this.props,
224
+ identifier = _this$props4.identifier,
225
+ _this$props4$dimensio = _this$props4.dimensions,
226
+ dimensions = _this$props4$dimensio === void 0 ? {} : _this$props4$dimensio;
227
+ isFileIdentifier(identifier) && removeCardPreviewFromCache(identifier.id, dimensions);
228
+
229
+ _this.safeSetState(updateState);
230
+ } else {
231
+ _this.safeSetState({
232
+ status: 'error',
233
+ error: error
234
+ });
235
+ }
236
+ });
237
+
238
+ _defineProperty(_assertThisInitialized(_this), "onImageLoad", function () {
239
+ _this.safeSetState({
240
+ previewDidRender: true
241
+ });
242
+ });
243
+
244
+ _defineProperty(_assertThisInitialized(_this), "fireCopiedEvent", function () {
245
+ var createAnalyticsEvent = _this.props.createAnalyticsEvent;
246
+ var cardRef = _this.state.cardRef;
247
+ cardRef && createAnalyticsEvent && fireCopiedEvent(createAnalyticsEvent, _this.metadata.id, cardRef);
248
+ });
249
+
250
+ _defineProperty(_assertThisInitialized(_this), "fireScreenEvent", function () {
135
251
  var createAnalyticsEvent = _this.props.createAnalyticsEvent;
136
- fireMediaCardEvent(getCopiedFilePayload(_this.metadata.id), createAnalyticsEvent);
252
+ createAnalyticsEvent && fireScreenEvent(createAnalyticsEvent, _this.fileAttributes);
253
+ });
254
+
255
+ _defineProperty(_assertThisInitialized(_this), "fireLocalPreviewErrorEvent", function (error) {// TODO: track local preview success rate
256
+ // https://product-fabric.atlassian.net/browse/MEX-774
137
257
  });
138
258
 
139
259
  _defineProperty(_assertThisInitialized(_this), "safeSetState", function (state) {
140
260
  if (_this.hasBeenMounted) {
141
- _this.setState(state);
261
+ // If it's setting the status, we need to use a state updater function,
262
+ // which ensures that no non-final status overrides a final status.
263
+ // If no status is set, we don't need a sate updater
264
+ var updater = !!state.status ? createStateUpdater(state) : state;
265
+
266
+ _this.setState(updater);
142
267
  }
143
268
  });
144
269
 
@@ -148,17 +273,18 @@ export var CardBase = /*#__PURE__*/function (_Component) {
148
273
  }
149
274
 
150
275
  if (_this.hasBeenMounted) {
276
+ // TODO MEX-788: add test for "do not remove the card preview when unsubscribing".
151
277
  _this.setState({
152
- cardPreview: undefined
278
+ isBannedLocalPreview: false
153
279
  });
154
280
  }
155
281
  });
156
282
 
157
283
  _defineProperty(_assertThisInitialized(_this), "onCardViewClick", function (event, analyticsEvent) {
158
- var _this$props3 = _this.props,
159
- identifier = _this$props3.identifier,
160
- useInlinePlayer = _this$props3.useInlinePlayer,
161
- shouldOpenMediaViewer = _this$props3.shouldOpenMediaViewer;
284
+ var _this$props5 = _this.props,
285
+ identifier = _this$props5.identifier,
286
+ useInlinePlayer = _this$props5.useInlinePlayer,
287
+ shouldOpenMediaViewer = _this$props5.shouldOpenMediaViewer;
162
288
  var cardPreview = _this.state.cardPreview;
163
289
 
164
290
  var _assertThisInitialize2 = _assertThisInitialized(_this),
@@ -213,13 +339,13 @@ export var CardBase = /*#__PURE__*/function (_Component) {
213
339
  });
214
340
 
215
341
  _defineProperty(_assertThisInitialized(_this), "renderInlinePlayer", function () {
216
- var _this$props4 = _this.props,
217
- identifier = _this$props4.identifier,
218
- mediaClient = _this$props4.mediaClient,
219
- dimensions = _this$props4.dimensions,
220
- selected = _this$props4.selected,
221
- testId = _this$props4.testId,
222
- originalDimensions = _this$props4.originalDimensions;
342
+ var _this$props6 = _this.props,
343
+ identifier = _this$props6.identifier,
344
+ mediaClient = _this$props6.mediaClient,
345
+ dimensions = _this$props6.dimensions,
346
+ selected = _this$props6.selected,
347
+ testId = _this$props6.testId,
348
+ originalDimensions = _this$props6.originalDimensions;
223
349
  return /*#__PURE__*/React.createElement(InlinePlayer, {
224
350
  mediaClient: mediaClient,
225
351
  dimensions: dimensions,
@@ -262,12 +388,12 @@ export var CardBase = /*#__PURE__*/function (_Component) {
262
388
 
263
389
  _defineProperty(_assertThisInitialized(_this), "renderMediaViewer", function () {
264
390
  var mediaViewerSelectedItem = _this.state.mediaViewerSelectedItem;
265
- var _this$props5 = _this.props,
266
- mediaClient = _this$props5.mediaClient,
267
- identifier = _this$props5.identifier,
268
- mediaViewerDataSource = _this$props5.mediaViewerDataSource,
269
- contextId = _this$props5.contextId,
270
- featureFlags = _this$props5.featureFlags;
391
+ var _this$props7 = _this.props,
392
+ mediaClient = _this$props7.mediaClient,
393
+ identifier = _this$props7.identifier,
394
+ mediaViewerDataSource = _this$props7.mediaViewerDataSource,
395
+ contextId = _this$props7.contextId,
396
+ featureFlags = _this$props7.featureFlags;
271
397
 
272
398
  if (!mediaViewerSelectedItem) {
273
399
  return;
@@ -289,20 +415,21 @@ export var CardBase = /*#__PURE__*/function (_Component) {
289
415
  });
290
416
 
291
417
  _defineProperty(_assertThisInitialized(_this), "renderCard", function () {
292
- var _this$props6 = _this.props,
293
- identifier = _this$props6.identifier,
294
- isLazy = _this$props6.isLazy,
295
- appearance = _this$props6.appearance,
296
- resizeMode = _this$props6.resizeMode,
297
- dimensions = _this$props6.dimensions,
298
- selectable = _this$props6.selectable,
299
- selected = _this$props6.selected,
300
- disableOverlay = _this$props6.disableOverlay,
301
- alt = _this$props6.alt,
302
- testId = _this$props6.testId,
303
- featureFlags = _this$props6.featureFlags,
304
- titleBoxBgColor = _this$props6.titleBoxBgColor,
305
- titleBoxIcon = _this$props6.titleBoxIcon;
418
+ var _this$props8 = _this.props,
419
+ identifier = _this$props8.identifier,
420
+ isLazy = _this$props8.isLazy,
421
+ appearance = _this$props8.appearance,
422
+ resizeMode = _this$props8.resizeMode,
423
+ dimensions = _this$props8.dimensions,
424
+ selectable = _this$props8.selectable,
425
+ selected = _this$props8.selected,
426
+ disableOverlay = _this$props8.disableOverlay,
427
+ alt = _this$props8.alt,
428
+ testId = _this$props8.testId,
429
+ featureFlags = _this$props8.featureFlags,
430
+ titleBoxBgColor = _this$props8.titleBoxBgColor,
431
+ titleBoxIcon = _this$props8.titleBoxIcon,
432
+ ssr = _this$props8.ssr;
306
433
  var mediaItemType = identifier.mediaItemType;
307
434
  var _this$state = _this.state,
308
435
  status = _this$state.status,
@@ -315,7 +442,8 @@ export var CardBase = /*#__PURE__*/function (_Component) {
315
442
  var dataURI = _this$state$cardPrevi.dataURI,
316
443
  orientation = _this$state$cardPrevi.orientation,
317
444
  error = _this$state.error,
318
- cardRef = _this$state.cardRef;
445
+ cardRef = _this$state.cardRef,
446
+ isCardVisible = _this$state.isCardVisible;
319
447
 
320
448
  var _assertThisInitialize3 = _assertThisInitialized(_this),
321
449
  metadata = _assertThisInitialize3.metadata;
@@ -324,11 +452,16 @@ export var CardBase = /*#__PURE__*/function (_Component) {
324
452
  onCardViewClick = _assertThisInitialize4.onCardViewClick,
325
453
  onDisplayImage = _assertThisInitialize4.onDisplayImage,
326
454
  actions = _assertThisInitialize4.actions,
327
- onMouseEnter = _assertThisInitialize4.onMouseEnter;
455
+ onMouseEnter = _assertThisInitialize4.onMouseEnter; // Card can be artificially turned visible before entering the viewport
456
+ // For example, when we have the image in cache
457
+
458
+
459
+ var nativeLazyLoad = isLazy && !isCardVisible; // Force Media Image to always display img for SSR
328
460
 
461
+ var forceSyncDisplay = !!ssr;
329
462
  var card = /*#__PURE__*/React.createElement(CardView, {
330
463
  status: status,
331
- error: error && error.secondaryError,
464
+ error: error,
332
465
  mediaItemType: mediaItemType,
333
466
  metadata: metadata,
334
467
  dataURI: dataURI,
@@ -349,7 +482,11 @@ export var CardBase = /*#__PURE__*/function (_Component) {
349
482
  testId: testId,
350
483
  featureFlags: featureFlags,
351
484
  titleBoxBgColor: titleBoxBgColor,
352
- titleBoxIcon: titleBoxIcon
485
+ titleBoxIcon: titleBoxIcon,
486
+ onImageError: _this.onImageError,
487
+ onImageLoad: _this.onImageLoad,
488
+ nativeLazyLoad: nativeLazyLoad,
489
+ forceSyncDisplay: forceSyncDisplay
353
490
  });
354
491
  return isLazy ? /*#__PURE__*/React.createElement(ViewportDetector, {
355
492
  targetRef: cardRef,
@@ -393,44 +530,81 @@ export var CardBase = /*#__PURE__*/function (_Component) {
393
530
  }
394
531
  });
395
532
 
533
+ var _status = 'loading';
534
+
396
535
  var _cardPreview;
397
536
 
398
- var _this$props7 = _this.props,
399
- _identifier = _this$props7.identifier,
400
- _this$props7$dimensio = _this$props7.dimensions,
401
- _dimensions = _this$props7$dimensio === void 0 ? {} : _this$props7$dimensio;
537
+ var _this$props9 = _this.props,
538
+ _identifier = _this$props9.identifier,
539
+ _this$props9$dimensio = _this$props9.dimensions,
540
+ _dimensions = _this$props9$dimensio === void 0 ? {} : _this$props9$dimensio,
541
+ _ssr = _this$props9.ssr;
402
542
 
403
543
  if (isFileIdentifier(_identifier)) {
404
544
  var id = _identifier.id;
405
545
  _cardPreview = getCardPreviewFromCache(id, _dimensions);
406
- }
407
- /**
408
- * If cardPreview is available from local cache, `isCardVisible`
409
- * should be true to avoid flickers during re-mount of the component
410
- */
411
546
 
547
+ if (!_cardPreview && _ssr) {
548
+ _this.fireCommencedEvent();
549
+
550
+ _cardPreview = _this.resolveSSRPreview(_identifier, _ssr);
551
+ }
552
+ } else if (isExternalImageIdentifier(_identifier)) {
553
+ _this.fireCommencedEvent();
554
+
555
+ _status = 'loading-preview';
556
+ var dataURI = _identifier.dataURI;
557
+ _cardPreview = {
558
+ dataURI: dataURI,
559
+ orientation: 1,
560
+ source: 'external'
561
+ };
562
+ } // If cardPreview is available from local cache or external, `isCardVisible`
563
+ // should be true to avoid flickers during re-mount of the component
564
+ // should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
565
+ // outside the viewport
566
+
567
+
568
+ var _isCardVisible = !_this.props.isLazy || !!_cardPreview && !isSSRPreview(_cardPreview);
412
569
 
413
570
  _this.state = {
414
- status: 'loading',
415
- isCardVisible: _cardPreview ? true : !_this.props.isLazy,
571
+ status: _status,
572
+ isCardVisible: _isCardVisible,
416
573
  isPlayingFile: false,
417
574
  cardPreview: _cardPreview,
418
- cardRef: null
575
+ cardRef: null,
576
+ isBannedLocalPreview: false,
577
+ previewDidRender: false
419
578
  };
420
579
  return _this;
421
- } // we add a listener for each of the cards on the page
422
- // and then check if the triggered listener is from the card
423
- // that contains a div in current window.getSelection()
424
- // won't work in IE11
425
-
580
+ }
426
581
 
427
582
  _createClass(CardBase, [{
428
583
  key: "componentDidMount",
429
584
  value: function componentDidMount() {
430
585
  this.hasBeenMounted = true;
431
- this.fireCommencedEvent();
432
- this.updateStateForIdentifier();
433
- document.addEventListener('copy', this.onCopyListener);
586
+ var _this$state2 = this.state,
587
+ isCardVisible = _this$state2.isCardVisible,
588
+ cardPreview = _this$state2.cardPreview;
589
+ var _this$props10 = this.props,
590
+ identifier = _this$props10.identifier,
591
+ ssr = _this$props10.ssr;
592
+
593
+ if (isCardVisible && isFileIdentifier(identifier)) {
594
+ this.updateStateForIdentifier(identifier);
595
+ }
596
+
597
+ if (isCardVisible && !!ssr && !!cardPreview && isSSRClientPreview(cardPreview) && isFileIdentifier(identifier)) {
598
+ // Since the SSR preview brings the token in the query params,
599
+ // We need to fetch the remote preview to be able to cache it,
600
+ this.setCacheSSRPreview(identifier);
601
+ } // we add a listener for each of the cards on the page
602
+ // and then check if the triggered listener is from the card
603
+ // that contains a div in current window.getSelection()
604
+ // won't work in IE11
605
+
606
+
607
+ getDocument().addEventListener('copy', this.fireCopiedEvent);
434
608
  }
435
609
  }, {
436
610
  key: "componentDidUpdate",
@@ -439,28 +613,72 @@ export var CardBase = /*#__PURE__*/function (_Component) {
439
613
  prevIdentifier = prevProps.identifier,
440
614
  prevDimensions = prevProps.dimensions;
441
615
  var prevIsCardVisible = prevState.isCardVisible;
442
- var _this$props8 = this.props,
443
- mediaClient = _this$props8.mediaClient,
444
- identifier = _this$props8.identifier,
445
- dimensions = _this$props8.dimensions;
446
- var isCardVisible = this.state.isCardVisible;
616
+ var _this$props11 = this.props,
617
+ mediaClient = _this$props11.mediaClient,
618
+ identifier = _this$props11.identifier,
619
+ dimensions = _this$props11.dimensions,
620
+ featureFlags = _this$props11.featureFlags;
621
+ var _this$state3 = this.state,
622
+ isCardVisible = _this$state3.isCardVisible,
623
+ cardPreview = _this$state3.cardPreview,
624
+ status = _this$state3.status,
625
+ fileState = _this$state3.fileState,
626
+ isBannedLocalPreview = _this$state3.isBannedLocalPreview,
627
+ previewDidRender = _this$state3.previewDidRender;
447
628
  var isDifferent = isDifferentIdentifier(prevIdentifier, identifier);
629
+ var turnedVisible = !prevIsCardVisible && isCardVisible;
630
+ var isNewMediaClient = prevMediaClient !== mediaClient;
448
631
 
449
- if (prevIsCardVisible !== isCardVisible && isCardVisible || prevMediaClient !== mediaClient || isDifferent || this.shouldRefetchImage(prevDimensions, dimensions)) {
632
+ if (isExternalImageIdentifier(identifier) && isDifferent) {
450
633
  this.fireCommencedEvent();
451
- this.updateStateForIdentifier();
634
+ var dataURI = identifier.dataURI;
635
+ this.setState({
636
+ status: 'loading-preview',
637
+ cardPreview: {
638
+ dataURI: dataURI,
639
+ orientation: 1,
640
+ source: 'external'
641
+ },
642
+ isCardVisible: true
643
+ });
644
+ }
645
+
646
+ if (isFileIdentifier(identifier) && (turnedVisible || !!this.subscription && (isNewMediaClient || isDifferent))) {
647
+ this.updateStateForIdentifier(identifier);
452
648
  }
453
649
 
454
650
  if (this.state.status !== prevState.status) {
455
- var _this$state2 = this.state,
456
- status = _this$state2.status,
457
- cardPreview = _this$state2.cardPreview,
458
- error = _this$state2.error;
459
- var createAnalyticsEvent = this.props.createAnalyticsEvent;
460
- createAnalyticsEvent && fireOperationalEvent(createAnalyticsEvent, status, this.fileAttributes, {
461
- cardPreview: cardPreview,
462
- error: error
651
+ this.fireOperationalEvent();
652
+
653
+ if (this.state.status === 'complete' || this.fileAttributes.fileMediatype === 'video' && !!cardPreview && this.state.status === 'processing') {
654
+ this.fireScreenEvent();
655
+ }
656
+ }
657
+
658
+ if (isFileIdentifier(identifier) && fileState && shouldResolvePreview({
659
+ status: status,
660
+ fileState: fileState,
661
+ dimensions: dimensions,
662
+ prevDimensions: prevDimensions,
663
+ featureFlags: featureFlags,
664
+ hasCardPreview: !!cardPreview,
665
+ isBannedLocalPreview: isBannedLocalPreview
666
+ })) {
667
+ this.resolvePreview(identifier, fileState);
668
+ }
669
+
670
+ if (turnedVisible && this.props.ssr && !!cardPreview && isSSRClientPreview(cardPreview) && isFileIdentifier(identifier)) {
671
+ // Since the SSR preview brings the token in the query params,
672
+ // We need to fetch the remote preview to be able to cache it,
673
+ this.setCacheSSRPreview(identifier);
674
+ }
675
+
676
+ if (previewDidRender && // We should't complete if status is uploading
677
+ ['loading-preview', 'processing'].includes(status)) {
678
+ this.safeSetState({
679
+ status: 'complete'
463
680
  });
681
+ this.unsubscribe();
464
682
  }
465
683
  }
466
684
  }, {
@@ -468,207 +686,103 @@ export var CardBase = /*#__PURE__*/function (_Component) {
468
686
  value: function componentWillUnmount() {
469
687
  this.hasBeenMounted = false;
470
688
  this.unsubscribe();
471
- document.removeEventListener('copy', this.onCopyListener);
689
+ getDocument().removeEventListener('copy', this.fireCopiedEvent);
472
690
  }
473
691
  }, {
474
692
  key: "updateStateForIdentifier",
475
- value: function updateStateForIdentifier() {
476
- var _this$props9 = this.props,
477
- mediaClient = _this$props9.mediaClient,
478
- identifier = _this$props9.identifier;
479
- var isCardVisible = this.state.isCardVisible;
480
-
481
- if (!isCardVisible) {
482
- return;
483
- }
484
-
485
- if (identifier.mediaItemType === 'file') {
486
- this.unsubscribe();
487
- this.subscribeInternalFile(identifier, mediaClient);
488
- }
489
- }
490
- }, {
491
- key: "requestedDimensions",
492
- get: function get() {
493
- var dimensions = this.props.dimensions;
494
- var cardRef = this.state.cardRef;
495
- var options = {
496
- dimensions: dimensions,
497
- element: cardRef
498
- };
499
- var width = getDataURIDimension('width', options);
500
- var height = getDataURIDimension('height', options);
501
- return {
502
- width: width,
503
- height: height
504
- };
693
+ value: function updateStateForIdentifier(identifier) {
694
+ this.fireCommencedEvent();
695
+ this.subscribeInternalFile(identifier);
505
696
  }
506
697
  }, {
507
698
  key: "subscribeInternalFile",
508
- value: function subscribeInternalFile(identifier, mediaClient) {
699
+ value: function subscribeInternalFile(identifier) {
509
700
  var _this2 = this;
510
701
 
702
+ var mediaClient = this.props.mediaClient;
703
+ var isBannedLocalPreview = this.state.isBannedLocalPreview;
511
704
  var id = identifier.id,
512
705
  collectionName = identifier.collectionName,
513
706
  occurrenceKey = identifier.occurrenceKey;
707
+ this.unsubscribe();
514
708
  this.subscription = mediaClient.file.getFileState(id, {
515
709
  collectionName: collectionName,
516
710
  occurrenceKey: occurrenceKey
517
711
  }).subscribe({
518
- next: function () {
519
- var _next = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(fileState) {
520
- var thisCardStatusUpdateTimestamp, filePreviewStatus, status, cardPreview, error, wrappedError;
521
- return _regeneratorRuntime.wrap(function _callee$(_context) {
522
- while (1) {
523
- switch (_context.prev = _context.next) {
524
- case 0:
525
- _this2.lastFileState = fileState;
526
- thisCardStatusUpdateTimestamp = (performance || Date).now();
527
- filePreviewStatus = extractFilePreviewStatus(fileState, _this2.props.featureFlags);
528
- status = getCardStatus(fileState.status, filePreviewStatus);
529
-
530
- _this2.safeSetState({
531
- fileState: fileState
532
- });
533
-
534
- if (!shouldGetCardPreview(status, filePreviewStatus)) {
535
- _context.next = 17;
536
- break;
537
- }
538
-
539
- _context.prev = 6;
540
- _context.next = 9;
541
- return getCardPreview(_this2.getCardPreviewParams(id, collectionName, fileState));
542
-
543
- case 9:
544
- cardPreview = _context.sent;
545
-
546
- if (['loading-preview', 'processing'].includes(status)) {
547
- status = 'complete';
548
- }
549
-
550
- _context.next = 17;
551
- break;
552
-
553
- case 13:
554
- _context.prev = 13;
555
- _context.t0 = _context["catch"](6);
556
- wrappedError = ensureMediaCardError('preview-fetch', _context.t0);
557
- /**
558
- * If remote preview fails, we set status 'error'
559
- * If the local preview fails (i.e, no remote preview available),
560
- * we can stay in the same status until there is a remote preview available
561
- * */
562
-
563
- if (isRemotePreviewError(wrappedError)) {
564
- status = 'error';
565
- error = wrappedError;
566
- }
567
-
568
- case 17:
569
- if (_this2.isLatestCardStatusUpdate(thisCardStatusUpdateTimestamp)) {
570
- // These status and progress must not override values representing more recent FileState
571
-
572
- /* next() start some await() delay in next() status & progress update
573
- * ------- ------------------ ------------------------
574
- * |----[1]FileState:uploading------>| |
575
- * | | |
576
- * |----[2]FileState:uploading------>| |
577
- * | | |
578
- * | |----[2]FileState:uploading------>| Update status to `uploading`
579
- * |----[3]FileState:processing----->| |
580
- * | |----[3]FileState:processing----->| Update status to `complete`
581
- * | | |
582
- * | |----[1]FileState:uploading------>| We do not want to update status to `uploading` again!
583
- *
584
- */
585
- if (status === 'error' && isErrorFileState(fileState) && !error) {
586
- error = new MediaCardError('error-file-state', new Error(fileState.message));
587
- }
588
-
589
- _this2.safeSetState({
590
- status: status,
591
- cardPreview: cardPreview,
592
- progress: status === 'uploading' && fileState.status === 'uploading' ? fileState.progress : 1,
593
- error: status === 'error' && error ? error : undefined
594
- });
595
-
596
- _this2.lastCardStatusUpdateTimestamp = thisCardStatusUpdateTimestamp;
597
- }
598
-
599
- case 18:
600
- case "end":
601
- return _context.stop();
602
- }
603
- }
604
- }, _callee, null, [[6, 13]]);
605
- }));
606
-
607
- function next(_x) {
608
- return _next.apply(this, arguments);
609
- }
712
+ next: function next(fileState) {
713
+ var featureFlags = _this2.props.featureFlags;
714
+ var newState = getCardStateFromFileState(fileState, isBannedLocalPreview, featureFlags);
610
715
 
611
- return next;
612
- }(),
716
+ _this2.safeSetState(newState);
717
+ },
613
718
  error: function error(e) {
614
- // If file state subscription decides that the card is complete
615
- // and later there is an error, we won't change the card's status.
616
- if (_this2.state.status === 'complete') {
617
- return;
618
- }
619
-
620
- var errorReason = _this2.fileAttributes.fileStatus === 'uploading' ? 'upload' : 'metadata-fetch';
719
+ var errorReason = _this2.state.status === 'uploading' ? 'upload' : 'metadata-fetch';
621
720
  var error = new MediaCardError(errorReason, e);
622
721
 
623
722
  _this2.safeSetState({
624
723
  error: error,
625
724
  status: 'error'
626
725
  });
627
-
628
- _this2.lastCardStatusUpdateTimestamp = (performance || Date).now();
629
726
  }
630
727
  });
631
728
  }
729
+ }, {
730
+ key: "requestedDimensions",
731
+ get: function get() {
732
+ var dimensions = this.props.dimensions;
733
+
734
+ var _ref3 = this.state || {},
735
+ element = _ref3.cardRef;
736
+
737
+ return getRequestedDimensions({
738
+ dimensions: dimensions,
739
+ element: element
740
+ });
741
+ }
632
742
  }, {
633
743
  key: "metadata",
634
744
  get: function get() {
635
- var identifier = this.props.identifier;
636
- return isFileIdentifier(identifier) ? this.state.fileState ? getFileDetails(this.state.fileState) : {
637
- id: identifier.id
638
- } : {
639
- id: identifier.mediaItemType,
640
- name: identifier.name || identifier.dataURI,
641
- mediaType: 'image'
642
- };
745
+ var _this$state4;
746
+
747
+ return getFileDetails(this.props.identifier, (_this$state4 = this.state) === null || _this$state4 === void 0 ? void 0 : _this$state4.fileState);
643
748
  }
644
749
  }, {
645
750
  key: "fileAttributes",
646
751
  get: function get() {
647
- var _this$lastFileState;
752
+ var _this$state5, _this$state5$fileStat;
648
753
 
649
- return getFileAttributes(this.metadata, (_this$lastFileState = this.lastFileState) === null || _this$lastFileState === void 0 ? void 0 : _this$lastFileState.status);
754
+ 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);
755
+ }
756
+ }, {
757
+ key: "fireOperationalEvent",
758
+ value: function fireOperationalEvent() {
759
+ var _this$state6 = this.state,
760
+ status = _this$state6.status,
761
+ error = _this$state6.error;
762
+ var createAnalyticsEvent = this.props.createAnalyticsEvent;
763
+ createAnalyticsEvent && _fireOperationalEvent(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), error);
650
764
  }
651
765
  }, {
652
766
  key: "fireCommencedEvent",
653
767
  value: function fireCommencedEvent() {
654
- if (!this.state.isCardVisible) {
655
- return;
656
- }
657
-
768
+ this.timeElapsedTillCommenced = performance.now();
658
769
  var createAnalyticsEvent = this.props.createAnalyticsEvent;
659
- var payload = getRenderCommencedEventPayload(this.fileAttributes);
660
- fireMediaCardEvent(payload, createAnalyticsEvent);
770
+ createAnalyticsEvent && _fireCommencedEvent(createAnalyticsEvent, this.fileAttributes, {
771
+ overall: {
772
+ durationSincePageStart: this.timeElapsedTillCommenced
773
+ }
774
+ });
661
775
  }
662
776
  }, {
663
777
  key: "actions",
664
778
  get: function get() {
665
779
  var _this3 = this;
666
780
 
667
- var _this$props10 = this.props,
668
- _this$props10$actions = _this$props10.actions,
669
- actions = _this$props10$actions === void 0 ? [] : _this$props10$actions,
670
- identifier = _this$props10.identifier,
671
- shouldEnableDownloadButton = _this$props10.shouldEnableDownloadButton;
781
+ var _this$props12 = this.props,
782
+ _this$props12$actions = _this$props12.actions,
783
+ actions = _this$props12$actions === void 0 ? [] : _this$props12$actions,
784
+ identifier = _this$props12.identifier,
785
+ shouldEnableDownloadButton = _this$props12.shouldEnableDownloadButton;
672
786
  var status = this.state.status;
673
787
  var metadata = this.metadata;
674
788
 
@@ -690,18 +804,13 @@ export var CardBase = /*#__PURE__*/function (_Component) {
690
804
  }, {
691
805
  key: "render",
692
806
  value: function render() {
693
- var _this$lastFileState2;
694
-
695
- var _this$state3 = this.state,
696
- isPlayingFile = _this$state3.isPlayingFile,
697
- mediaViewerSelectedItem = _this$state3.mediaViewerSelectedItem;
807
+ var _this$state7 = this.state,
808
+ isPlayingFile = _this$state7.isPlayingFile,
809
+ mediaViewerSelectedItem = _this$state7.mediaViewerSelectedItem;
698
810
  var innerContent = /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null);
699
- var content = this.context.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
811
+ return this.context.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
700
812
  locale: "en"
701
813
  }, innerContent);
702
- return /*#__PURE__*/React.createElement(FileAttributesProvider, {
703
- data: getFileAttributes(this.metadata, (_this$lastFileState2 = this.lastFileState) === null || _this$lastFileState2 === void 0 ? void 0 : _this$lastFileState2.status)
704
- }, content);
705
814
  }
706
815
  }]);
707
816
 
@@ -722,24 +831,6 @@ _defineProperty(CardBase, "contextTypes", {
722
831
  intl: intlShape
723
832
  });
724
833
 
725
- _defineProperty(CardBase, "getDerivedStateFromProps", function (props) {
726
- var identifier = props.identifier;
727
-
728
- if (identifier.mediaItemType === 'external-image') {
729
- var dataURI = identifier.dataURI;
730
- return {
731
- status: 'complete',
732
- cardPreview: {
733
- dataURI: dataURI,
734
- orientation: 1,
735
- source: 'external'
736
- }
737
- };
738
- }
739
-
740
- return null;
741
- });
742
-
743
834
  export var Card = withMediaAnalyticsContext({
744
835
  packageVersion: packageVersion,
745
836
  packageName: packageName,