@atlaskit/media-card 76.1.1 → 76.2.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 (79) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/card/actions.js +2 -2
  3. package/dist/cjs/card/card.js +3 -3
  4. package/dist/cjs/card/cardLoader.js +2 -5
  5. package/dist/cjs/card/cardSwitcher.js +12 -0
  6. package/dist/cjs/card/cardView.js +3 -4
  7. package/dist/cjs/card/getCardPreview/cache.js +3 -0
  8. package/dist/cjs/card/getCardPreview/index.js +2 -2
  9. package/dist/cjs/card/index.js +2 -2
  10. package/dist/cjs/card/media-card-analytics-error-boundary.js +3 -3
  11. package/dist/cjs/card/ui/progressBar/styledBar.js +1 -0
  12. package/dist/cjs/card/ui/titleBox/titleBoxComponents.js +1 -0
  13. package/dist/cjs/card/v2/cardV2.js +1054 -0
  14. package/dist/cjs/card/v2/cardV2Loader.js +95 -0
  15. package/dist/cjs/errors.js +89 -31
  16. package/dist/cjs/inline/loader.js +1 -1
  17. package/dist/cjs/inline/mediaInlineAnalyticsErrorBoundary.js +2 -2
  18. package/dist/cjs/inline/mediaInlineCardAnalytics.js +2 -2
  19. package/dist/cjs/utils/analytics.js +18 -8
  20. package/dist/cjs/utils/objectURLCache.js +5 -0
  21. package/dist/cjs/utils/ufoExperiences.js +3 -3
  22. package/dist/es2019/card/card.js +1 -1
  23. package/dist/es2019/card/cardLoader.js +2 -5
  24. package/dist/es2019/card/cardSwitcher.js +4 -0
  25. package/dist/es2019/card/cardView.js +1 -2
  26. package/dist/es2019/card/getCardPreview/cache.js +3 -0
  27. package/dist/es2019/card/index.js +1 -1
  28. package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
  29. package/dist/es2019/card/ui/progressBar/styledBar.js +1 -0
  30. package/dist/es2019/card/ui/titleBox/titleBoxComponents.js +1 -0
  31. package/dist/es2019/card/v2/cardV2.js +1031 -0
  32. package/dist/es2019/card/v2/cardV2Loader.js +58 -0
  33. package/dist/es2019/errors.js +45 -0
  34. package/dist/es2019/inline/loader.js +1 -1
  35. package/dist/es2019/utils/analytics.js +17 -7
  36. package/dist/es2019/utils/objectURLCache.js +3 -0
  37. package/dist/es2019/utils/ufoExperiences.js +1 -1
  38. package/dist/esm/card/actions.js +2 -2
  39. package/dist/esm/card/card.js +3 -3
  40. package/dist/esm/card/cardLoader.js +2 -5
  41. package/dist/esm/card/cardSwitcher.js +4 -0
  42. package/dist/esm/card/cardView.js +3 -4
  43. package/dist/esm/card/getCardPreview/cache.js +3 -0
  44. package/dist/esm/card/getCardPreview/index.js +2 -2
  45. package/dist/esm/card/index.js +1 -1
  46. package/dist/esm/card/media-card-analytics-error-boundary.js +3 -3
  47. package/dist/esm/card/ui/progressBar/styledBar.js +1 -0
  48. package/dist/esm/card/ui/titleBox/titleBoxComponents.js +1 -0
  49. package/dist/esm/card/v2/cardV2.js +1043 -0
  50. package/dist/esm/card/v2/cardV2Loader.js +78 -0
  51. package/dist/esm/errors.js +83 -30
  52. package/dist/esm/inline/loader.js +1 -1
  53. package/dist/esm/inline/mediaInlineAnalyticsErrorBoundary.js +2 -2
  54. package/dist/esm/inline/mediaInlineCardAnalytics.js +2 -2
  55. package/dist/esm/utils/analytics.js +19 -9
  56. package/dist/esm/utils/objectURLCache.js +5 -0
  57. package/dist/esm/utils/ufoExperiences.js +3 -3
  58. package/dist/types/card/cardSwitcher.d.ts +3 -0
  59. package/dist/types/card/getCardPreview/cache.d.ts +2 -0
  60. package/dist/types/card/index.d.ts +1 -1
  61. package/dist/types/card/v2/cardV2.d.ts +62 -0
  62. package/dist/types/card/v2/cardV2Loader.d.ts +4 -0
  63. package/dist/types/errors.d.ts +12 -0
  64. package/dist/types/types.d.ts +1 -0
  65. package/dist/types/utils/objectURLCache.d.ts +1 -0
  66. package/dist/types-ts4.5/card/cardSwitcher.d.ts +3 -0
  67. package/dist/types-ts4.5/card/getCardPreview/cache.d.ts +2 -0
  68. package/dist/types-ts4.5/card/index.d.ts +1 -1
  69. package/dist/types-ts4.5/card/v2/cardV2.d.ts +62 -0
  70. package/dist/types-ts4.5/card/v2/cardV2Loader.d.ts +4 -0
  71. package/dist/types-ts4.5/errors.d.ts +12 -0
  72. package/dist/types-ts4.5/types.d.ts +1 -0
  73. package/dist/types-ts4.5/utils/objectURLCache.d.ts +1 -0
  74. package/package.json +18 -9
  75. package/report.api.md +4 -1
  76. package/tmp/api-report-tmp.d.ts +4 -1
  77. package/dist/cjs/version.json +0 -5
  78. package/dist/es2019/version.json +0 -5
  79. package/dist/esm/version.json +0 -5
@@ -0,0 +1,1043 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5
+ import _createClass from "@babel/runtime/helpers/createClass";
6
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
7
+ import _inherits from "@babel/runtime/helpers/inherits";
8
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
9
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
10
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
11
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ 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); }; }
15
+ 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; } }
16
+ import React, { Component, Suspense, useEffect } from 'react';
17
+ import ReactDOM from 'react-dom';
18
+ import { withAnalyticsEvents } from '@atlaskit/analytics-next';
19
+ import { withMediaAnalyticsContext } from '@atlaskit/media-common';
20
+ import DownloadIcon from '@atlaskit/icon/glyph/download';
21
+ import { getRandomHex } from '@atlaskit/media-common';
22
+ import { globalMediaEventEmitter, isDifferentIdentifier, isFileIdentifier, RECENTS_COLLECTION, isImageRepresentationReady, isExternalImageIdentifier, imageResizeModeToFileImageMode } from '@atlaskit/media-client';
23
+ import { MediaViewer } from '@atlaskit/media-viewer';
24
+ import { injectIntl, IntlProvider } from 'react-intl-next';
25
+ import { CardView } from '../cardView';
26
+ import { ViewportDetector } from '../../utils/viewportDetector';
27
+ import { videoIsPlayable } from '../../utils/videoIsPlayable';
28
+ import { getRequestedDimensions } from '../../utils/getDataURIDimension';
29
+ import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, isSSRDataPreview, fetchAndCacheRemotePreview } from '../getCardPreview';
30
+ import { getFileDetails } from '../../utils/metadata';
31
+ import { InlinePlayerLazy } from '../inlinePlayerLazy';
32
+ import { getFileAttributes, extractErrorInfo } from '../../utils/analytics';
33
+ import { isLocalPreviewError, MediaCardError, MediaFileStateError, ensureMediaCardError, ImageLoadError } from '../../errors';
34
+ import { fireOperationalEvent as _fireOperationalEvent, fireCommencedEvent as _fireCommencedEvent, fireCopiedEvent, fireScreenEvent, fireNonCriticalErrorEvent } from '../cardAnalytics';
35
+ import getDocument from '../../utils/document';
36
+ import { StoreSSRDataScript, getSSRData } from '../../utils/globalScope';
37
+ import { getCardStateFromFileState, createStateUpdater } from '../cardState';
38
+ import { isBigger } from '../../utils/dimensionComparer';
39
+ import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
40
+ import { completeUfoExperience, startUfoExperience } from '../../utils/ufoExperiences';
41
+ import { generateUniqueId } from '../../utils/generateUniqueId';
42
+ import { useFileState } from '@atlaskit/media-client-react';
43
+ var packageName = "@atlaskit/media-card";
44
+ var packageVersion = "76.2.0";
45
+ export var CardV2Base = /*#__PURE__*/function (_Component) {
46
+ _inherits(CardV2Base, _Component);
47
+ var _super = _createSuper(CardV2Base);
48
+ function CardV2Base(props) {
49
+ var _this;
50
+ _classCallCheck(this, CardV2Base);
51
+ _this = _super.call(this, props);
52
+ // An internalOccurrenceKey is a randomly generated value to differentiate various instances
53
+ // of Cards regardless of whether it shares the same file (either internal or external)
54
+ _defineProperty(_assertThisInitialized(_this), "internalOccurrenceKey", generateUniqueId());
55
+ _defineProperty(_assertThisInitialized(_this), "hasBeenMounted", false);
56
+ _defineProperty(_assertThisInitialized(_this), "fileStateFlags", {
57
+ wasStatusUploading: false,
58
+ wasStatusProcessing: false
59
+ });
60
+ _defineProperty(_assertThisInitialized(_this), "ssrReliability", {
61
+ server: {
62
+ status: 'unknown'
63
+ },
64
+ client: {
65
+ status: 'unknown'
66
+ }
67
+ });
68
+ // We initialise timeElapsedTillCommenced
69
+ // to avoid extra branching on a possibly undefined value.
70
+ _defineProperty(_assertThisInitialized(_this), "timeElapsedTillCommenced", performance.now());
71
+ // Generate unique traceId for file
72
+ _defineProperty(_assertThisInitialized(_this), "traceContext", {
73
+ traceId: getRandomHex(8)
74
+ });
75
+ _defineProperty(_assertThisInitialized(_this), "getImageURLParams", function (_ref) {
76
+ var collection = _ref.collectionName;
77
+ return _objectSpread(_objectSpread({
78
+ collection: collection,
79
+ mode: imageResizeModeToFileImageMode(_this.props.resizeMode)
80
+ }, _this.requestedDimensions), {}, {
81
+ allowAnimated: true
82
+ });
83
+ });
84
+ _defineProperty(_assertThisInitialized(_this), "getMediaBlobUrlAttrs", function (identifier, fileState) {
85
+ var id = identifier.id,
86
+ collection = identifier.collectionName;
87
+ var _this$props = _this.props,
88
+ originalDimensions = _this$props.originalDimensions,
89
+ contextId = _this$props.contextId,
90
+ alt = _this$props.alt;
91
+ var _getFileDetails = getFileDetails(identifier, fileState),
92
+ mimeType = _getFileDetails.mimeType,
93
+ name = _getFileDetails.name,
94
+ size = _getFileDetails.size;
95
+ return contextId ? _objectSpread(_objectSpread({
96
+ id: id,
97
+ collection: collection,
98
+ contextId: contextId,
99
+ mimeType: mimeType,
100
+ name: name,
101
+ size: size
102
+ }, originalDimensions || _this.requestedDimensions), {}, {
103
+ alt: alt
104
+ }) : undefined;
105
+ });
106
+ _defineProperty(_assertThisInitialized(_this), "getCardPreviewParams", function (identifier, fileState) {
107
+ var isBannedLocalPreview = _this.state.isBannedLocalPreview;
108
+ var id = identifier.id;
109
+ var _this$props2 = _this.props,
110
+ _this$props2$dimensio = _this$props2.dimensions,
111
+ dimensions = _this$props2$dimensio === void 0 ? {} : _this$props2$dimensio,
112
+ mediaClient = _this$props2.mediaClient,
113
+ createAnalyticsEvent = _this$props2.createAnalyticsEvent;
114
+ return {
115
+ mediaClient: mediaClient,
116
+ id: id,
117
+ dimensions: dimensions,
118
+ onLocalPreviewError: _this.fireNonCriticalErrorEvent,
119
+ filePreview: isBannedLocalPreview ? undefined : getFilePreviewFromFileState(fileState),
120
+ isRemotePreviewReady: isImageRepresentationReady(fileState),
121
+ imageUrlParams: _this.getImageURLParams(identifier),
122
+ mediaBlobUrlAttrs: _this.getMediaBlobUrlAttrs(identifier, fileState),
123
+ createAnalyticsEvent: createAnalyticsEvent,
124
+ featureFlags: _this.props.featureFlags,
125
+ traceContext: _this.traceContext
126
+ };
127
+ });
128
+ _defineProperty(_assertThisInitialized(_this), "setCacheSSRPreview", function (identifier) {
129
+ _this.fetchAndCacheRemotePreview(identifier).catch(function () {
130
+ // No need to log this error.
131
+ // If preview fails, it will be refetched later
132
+ //TODO: test this catch
133
+ // https://product-fabric.atlassian.net/browse/MEX-1071
134
+ });
135
+ });
136
+ _defineProperty(_assertThisInitialized(_this), "refetchSSRPreview", /*#__PURE__*/function () {
137
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(identifier) {
138
+ var cardPreview, wrappedError;
139
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
140
+ while (1) switch (_context.prev = _context.next) {
141
+ case 0:
142
+ _context.prev = 0;
143
+ _context.next = 3;
144
+ return _this.fetchAndCacheRemotePreview(identifier);
145
+ case 3:
146
+ cardPreview = _context.sent;
147
+ _this.safeSetState({
148
+ cardPreview: cardPreview
149
+ });
150
+ _context.next = 11;
151
+ break;
152
+ case 7:
153
+ _context.prev = 7;
154
+ _context.t0 = _context["catch"](0);
155
+ wrappedError = ensureMediaCardError('remote-preview-fetch-ssr', _context.t0, true);
156
+ _this.fireNonCriticalErrorEvent(wrappedError);
157
+ case 11:
158
+ case "end":
159
+ return _context.stop();
160
+ }
161
+ }, _callee, null, [[0, 7]]);
162
+ }));
163
+ return function (_x) {
164
+ return _ref2.apply(this, arguments);
165
+ };
166
+ }());
167
+ _defineProperty(_assertThisInitialized(_this), "resolveUpfrontPreview", /*#__PURE__*/function () {
168
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(identifier) {
169
+ var requestedDimensions, cardPreview, currentDimensions, areValidRequestedDimensions;
170
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
171
+ while (1) switch (_context2.prev = _context2.next) {
172
+ case 0:
173
+ requestedDimensions = _objectSpread({}, _this.props.dimensions);
174
+ _context2.prev = 1;
175
+ _context2.next = 4;
176
+ return _this.fetchAndCacheRemotePreview(identifier);
177
+ case 4:
178
+ cardPreview = _context2.sent;
179
+ currentDimensions = _this.props.dimensions;
180
+ areValidRequestedDimensions = !isBigger(requestedDimensions, currentDimensions); // If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
181
+ // the fetched preview is no longer valid, and thus, we dismiss it and set the flag wasResolvedUpfrontPreview = true
182
+ // to trigger a normal preview fetch.
183
+ if (areValidRequestedDimensions) {
184
+ _this.safeSetState({
185
+ cardPreview: cardPreview,
186
+ wasResolvedUpfrontPreview: true
187
+ });
188
+ } else {
189
+ _this.safeSetState({
190
+ wasResolvedUpfrontPreview: true
191
+ });
192
+ }
193
+ _context2.next = 13;
194
+ break;
195
+ case 10:
196
+ _context2.prev = 10;
197
+ _context2.t0 = _context2["catch"](1);
198
+ _this.safeSetState({
199
+ wasResolvedUpfrontPreview: true
200
+ });
201
+ // NO need to log error. If this call fails, a refetch will happen after
202
+ case 13:
203
+ case "end":
204
+ return _context2.stop();
205
+ }
206
+ }, _callee2, null, [[1, 10]]);
207
+ }));
208
+ return function (_x2) {
209
+ return _ref3.apply(this, arguments);
210
+ };
211
+ }());
212
+ _defineProperty(_assertThisInitialized(_this), "fetchAndCacheRemotePreview", function (identifier) {
213
+ var _this$props3 = _this.props,
214
+ mediaClient = _this$props3.mediaClient,
215
+ _this$props3$dimensio = _this$props3.dimensions,
216
+ dimensions = _this$props3$dimensio === void 0 ? {} : _this$props3$dimensio;
217
+ return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions, _this.getImageURLParams(identifier), _this.getMediaBlobUrlAttrs(identifier));
218
+ });
219
+ _defineProperty(_assertThisInitialized(_this), "resolvePreview", /*#__PURE__*/function () {
220
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(identifier, fileState) {
221
+ var params, cardPreview, wrappedError;
222
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
223
+ while (1) switch (_context3.prev = _context3.next) {
224
+ case 0:
225
+ _context3.prev = 0;
226
+ params = _this.getCardPreviewParams(identifier, fileState);
227
+ _context3.next = 4;
228
+ return getCardPreview(params);
229
+ case 4:
230
+ cardPreview = _context3.sent;
231
+ _this.safeSetState({
232
+ cardPreview: cardPreview
233
+ });
234
+ _context3.next = 12;
235
+ break;
236
+ case 8:
237
+ _context3.prev = 8;
238
+ _context3.t0 = _context3["catch"](0);
239
+ wrappedError = ensureMediaCardError('preview-fetch', _context3.t0); // If remote preview fails, we set status 'error'
240
+ // If local preview fails (i.e, no remote preview available),
241
+ // we can stay in the same status until there is a remote preview available
242
+ // If it's any other error we set status 'error'
243
+ if (isLocalPreviewError(wrappedError)) {
244
+ // This error should already been logged inside the getCardPreview. No need to log it here.
245
+ _this.safeSetState({
246
+ isBannedLocalPreview: true
247
+ });
248
+ } else {
249
+ _this.safeSetState({
250
+ status: 'error',
251
+ error: wrappedError
252
+ });
253
+ }
254
+ case 12:
255
+ case "end":
256
+ return _context3.stop();
257
+ }
258
+ }, _callee3, null, [[0, 8]]);
259
+ }));
260
+ return function (_x3, _x4) {
261
+ return _ref4.apply(this, arguments);
262
+ };
263
+ }());
264
+ _defineProperty(_assertThisInitialized(_this), "subscribeFileState", function (fileState) {
265
+ var isBannedLocalPreview = _this.state.isBannedLocalPreview;
266
+ if (fileState.status !== 'error') {
267
+ var featureFlags = _this.props.featureFlags;
268
+ var newState = getCardStateFromFileState(fileState, isBannedLocalPreview, featureFlags);
269
+ _this.safeSetState(newState);
270
+ } else {
271
+ var e = new MediaFileStateError(fileState.id, fileState.reason, fileState.message, fileState.details);
272
+ var errorReason = _this.state.status === 'uploading' ? 'upload' : 'metadata-fetch';
273
+ var error = new MediaCardError(errorReason, e);
274
+ _this.safeSetState({
275
+ error: error,
276
+ status: 'error'
277
+ });
278
+ }
279
+ });
280
+ _defineProperty(_assertThisInitialized(_this), "getPerformanceAttributes", function () {
281
+ var _assertThisInitialize = _assertThisInitialized(_this),
282
+ timeElapsedTillCommenced = _assertThisInitialize.timeElapsedTillCommenced;
283
+ var timeElapsedTillEvent = performance.now();
284
+ var durationSinceCommenced = timeElapsedTillCommenced && timeElapsedTillEvent - timeElapsedTillCommenced;
285
+ return {
286
+ overall: {
287
+ durationSincePageStart: timeElapsedTillEvent,
288
+ durationSinceCommenced: durationSinceCommenced
289
+ }
290
+ };
291
+ });
292
+ _defineProperty(_assertThisInitialized(_this), "logSSRImageError", function (cardPreview) {
293
+ if (cardPreview) {
294
+ var failedSSRObject = _objectSpread({
295
+ status: 'fail'
296
+ }, extractErrorInfo(new ImageLoadError(cardPreview.source)));
297
+ if (isSSRClientPreview(cardPreview)) {
298
+ _this.ssrReliability.client = failedSSRObject;
299
+ }
300
+
301
+ /*
302
+ 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.
303
+ */
304
+
305
+ if (isSSRDataPreview(cardPreview)) {
306
+ _this.ssrReliability.server = failedSSRObject;
307
+ _this.ssrReliability.client = failedSSRObject;
308
+ }
309
+ }
310
+ });
311
+ _defineProperty(_assertThisInitialized(_this), "onImageError", function (cardPreview) {
312
+ _this.logSSRImageError(cardPreview);
313
+ var currentPreview = _this.state.cardPreview;
314
+ // If the dataURI has been replaced, we can dismiss this error
315
+ if ((cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI) !== (currentPreview === null || currentPreview === void 0 ? void 0 : currentPreview.dataURI)) {
316
+ return;
317
+ }
318
+ var error = new ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
319
+ var isLocal = cardPreview && isLocalPreview(cardPreview);
320
+ var isSSR = cardPreview && (isSSRClientPreview(cardPreview) || isSSRDataPreview(cardPreview));
321
+ if (isLocal || isSSR) {
322
+ var updateState = {
323
+ cardPreview: undefined
324
+ };
325
+ if (isLocal) {
326
+ updateState.isBannedLocalPreview = true;
327
+ _this.fireNonCriticalErrorEvent(error);
328
+ }
329
+ var _this$props4 = _this.props,
330
+ identifier = _this$props4.identifier,
331
+ resizeMode = _this$props4.resizeMode;
332
+ var fileImageMode = imageResizeModeToFileImageMode(resizeMode);
333
+ isFileIdentifier(identifier) && removeCardPreviewFromCache(identifier.id, fileImageMode);
334
+ _this.safeSetState(updateState);
335
+ } else {
336
+ _this.safeSetState({
337
+ status: 'error',
338
+ error: error
339
+ });
340
+ }
341
+ });
342
+ _defineProperty(_assertThisInitialized(_this), "onImageLoad", function (cardPreview) {
343
+ if (cardPreview) {
344
+ if (isSSRClientPreview(cardPreview) && _this.ssrReliability.client.status === 'unknown') {
345
+ _this.ssrReliability.client = {
346
+ status: 'success'
347
+ };
348
+ }
349
+
350
+ /*
351
+ 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.
352
+ */
353
+
354
+ if (isSSRDataPreview(cardPreview) && _this.ssrReliability.server.status === 'unknown') {
355
+ _this.ssrReliability.server = {
356
+ status: 'success'
357
+ };
358
+ _this.ssrReliability.client = {
359
+ status: 'success'
360
+ };
361
+ }
362
+ }
363
+ var currentPreview = _this.state.cardPreview;
364
+ // If the dataURI has been replaced, we can dismiss this callback
365
+ if ((cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI) !== (currentPreview === null || currentPreview === void 0 ? void 0 : currentPreview.dataURI)) {
366
+ return;
367
+ }
368
+ _this.safeSetState({
369
+ previewDidRender: true
370
+ });
371
+ });
372
+ _defineProperty(_assertThisInitialized(_this), "fireCopiedEvent", function () {
373
+ var createAnalyticsEvent = _this.props.createAnalyticsEvent;
374
+ var cardRef = _this.state.cardRef;
375
+ cardRef && createAnalyticsEvent && fireCopiedEvent(createAnalyticsEvent, _this.metadata.id, cardRef);
376
+ });
377
+ _defineProperty(_assertThisInitialized(_this), "fireScreenEvent", function () {
378
+ var createAnalyticsEvent = _this.props.createAnalyticsEvent;
379
+ createAnalyticsEvent && fireScreenEvent(createAnalyticsEvent, _this.fileAttributes);
380
+ });
381
+ _defineProperty(_assertThisInitialized(_this), "fireNonCriticalErrorEvent", function (error) {
382
+ var createAnalyticsEvent = _this.props.createAnalyticsEvent;
383
+ var fileState = _this.state.fileState;
384
+ createAnalyticsEvent && fireNonCriticalErrorEvent(createAnalyticsEvent, _this.state.status, _this.fileAttributes, _this.ssrReliability, error, _this.traceContext, fileState === null || fileState === void 0 ? void 0 : fileState.metadataTraceContext);
385
+ });
386
+ _defineProperty(_assertThisInitialized(_this), "safeSetState", function (newState) {
387
+ if (_this.hasBeenMounted) {
388
+ /**
389
+ * createStateUpdater helper returns a callback to be passed to setState.
390
+ * It decides wether to update the 'status' depending on the current state vs the input state.
391
+ * From docs: "Both state and props received by the updater function are guaranteed to be up-to-date."
392
+ * If the input state brings an error and it won't be updating the state, the error will be logged as non-critical inside the helper.
393
+ * If the error persists int the state, it means it is a critical error and should be logged as a failed event for Card
394
+ */
395
+ _this.setState(createStateUpdater(newState, _this.fireNonCriticalErrorEvent));
396
+ }
397
+ });
398
+ _defineProperty(_assertThisInitialized(_this), "onCardViewClick", function (event, analyticsEvent) {
399
+ var _this$props5 = _this.props,
400
+ identifier = _this$props5.identifier,
401
+ useInlinePlayer = _this$props5.useInlinePlayer,
402
+ shouldOpenMediaViewer = _this$props5.shouldOpenMediaViewer;
403
+ var cardPreview = _this.state.cardPreview;
404
+ var _assertThisInitialize2 = _assertThisInitialized(_this),
405
+ metadata = _assertThisInitialize2.metadata;
406
+ _this.onClick(event, analyticsEvent);
407
+ if (!metadata) {
408
+ return;
409
+ }
410
+ var isVideo = metadata && metadata.mediaType === 'video';
411
+ if (useInlinePlayer && isVideo && !!cardPreview) {
412
+ _this.setState({
413
+ isPlayingFile: true,
414
+ shouldAutoplay: true
415
+ });
416
+ } else if (shouldOpenMediaViewer) {
417
+ var mediaViewerSelectedItem;
418
+ if (isFileIdentifier(identifier)) {
419
+ mediaViewerSelectedItem = {
420
+ id: identifier.id,
421
+ mediaItemType: 'file',
422
+ collectionName: identifier.collectionName,
423
+ occurrenceKey: identifier.occurrenceKey
424
+ };
425
+ } else {
426
+ mediaViewerSelectedItem = {
427
+ mediaItemType: 'external-image',
428
+ dataURI: identifier.dataURI,
429
+ name: identifier.name
430
+ };
431
+ }
432
+ _this.setState({
433
+ mediaViewerSelectedItem: mediaViewerSelectedItem
434
+ });
435
+ }
436
+ });
437
+ _defineProperty(_assertThisInitialized(_this), "onInlinePlayerError", function () {
438
+ _this.setState({
439
+ isPlayingFile: false
440
+ });
441
+ });
442
+ _defineProperty(_assertThisInitialized(_this), "setRef", function (cardRef) {
443
+ !!cardRef && _this.setState({
444
+ cardRef: cardRef
445
+ });
446
+ });
447
+ _defineProperty(_assertThisInitialized(_this), "renderInlinePlayer", function () {
448
+ var _this$props6 = _this.props,
449
+ identifier = _this$props6.identifier,
450
+ mediaClient = _this$props6.mediaClient,
451
+ dimensions = _this$props6.dimensions,
452
+ selected = _this$props6.selected,
453
+ testId = _this$props6.testId,
454
+ originalDimensions = _this$props6.originalDimensions,
455
+ onFullscreenChange = _this$props6.onFullscreenChange;
456
+ var _this$state = _this.state,
457
+ shouldAutoplay = _this$state.shouldAutoplay,
458
+ cardPreview = _this$state.cardPreview;
459
+ var card = _this.renderCard(false, 'loading', false);
460
+ return /*#__PURE__*/React.createElement(Suspense, {
461
+ fallback: card
462
+ }, /*#__PURE__*/React.createElement(InlinePlayerLazy, {
463
+ mediaClient: mediaClient,
464
+ dimensions: dimensions,
465
+ originalDimensions: originalDimensions,
466
+ identifier: identifier,
467
+ autoplay: !!shouldAutoplay,
468
+ onFullscreenChange: onFullscreenChange,
469
+ onError: _this.onInlinePlayerError,
470
+ onClick: _this.onClick,
471
+ selected: selected,
472
+ ref: _this.setRef,
473
+ testId: testId,
474
+ cardPreview: cardPreview
475
+ }));
476
+ });
477
+ _defineProperty(_assertThisInitialized(_this), "onMediaViewerClose", function () {
478
+ _this.setState({
479
+ mediaViewerSelectedItem: undefined
480
+ });
481
+ });
482
+ _defineProperty(_assertThisInitialized(_this), "onDisplayImage", function () {
483
+ var identifier = _this.props.identifier;
484
+ var payloadPart;
485
+ if (isFileIdentifier(identifier)) {
486
+ payloadPart = {
487
+ fileId: identifier.id,
488
+ isUserCollection: identifier.collectionName === RECENTS_COLLECTION
489
+ };
490
+ } else {
491
+ payloadPart = {
492
+ fileId: identifier.dataURI,
493
+ isUserCollection: false
494
+ };
495
+ }
496
+ globalMediaEventEmitter.emit('media-viewed', _objectSpread({
497
+ viewingLevel: 'minimal'
498
+ }, payloadPart));
499
+ });
500
+ _defineProperty(_assertThisInitialized(_this), "renderMediaViewer", function () {
501
+ var mediaViewerSelectedItem = _this.state.mediaViewerSelectedItem;
502
+ var _this$props7 = _this.props,
503
+ mediaClient = _this$props7.mediaClient,
504
+ identifier = _this$props7.identifier,
505
+ mediaViewerItems = _this$props7.mediaViewerItems,
506
+ contextId = _this$props7.contextId,
507
+ featureFlags = _this$props7.featureFlags;
508
+ if (!mediaViewerSelectedItem) {
509
+ return;
510
+ }
511
+ var collectionName = isFileIdentifier(identifier) ? identifier.collectionName || '' : '';
512
+ return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(MediaViewer, {
513
+ collectionName: collectionName,
514
+ items: mediaViewerItems || [],
515
+ mediaClientConfig: mediaClient.config,
516
+ selectedItem: mediaViewerSelectedItem,
517
+ onClose: _this.onMediaViewerClose,
518
+ contextId: contextId,
519
+ featureFlags: featureFlags
520
+ }), document.body);
521
+ });
522
+ _defineProperty(_assertThisInitialized(_this), "renderCard", function () {
523
+ var withCallbacks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
524
+ var cardStatusOverride = arguments.length > 1 ? arguments[1] : undefined;
525
+ var izLazyOverride = arguments.length > 2 ? arguments[2] : undefined;
526
+ var _this$props8 = _this.props,
527
+ identifier = _this$props8.identifier,
528
+ isLazy = _this$props8.isLazy,
529
+ appearance = _this$props8.appearance,
530
+ resizeMode = _this$props8.resizeMode,
531
+ dimensions = _this$props8.dimensions,
532
+ selectable = _this$props8.selectable,
533
+ selected = _this$props8.selected,
534
+ disableOverlay = _this$props8.disableOverlay,
535
+ alt = _this$props8.alt,
536
+ testId = _this$props8.testId,
537
+ featureFlags = _this$props8.featureFlags,
538
+ titleBoxBgColor = _this$props8.titleBoxBgColor,
539
+ titleBoxIcon = _this$props8.titleBoxIcon,
540
+ ssr = _this$props8.ssr,
541
+ useInlinePlayer = _this$props8.useInlinePlayer,
542
+ shouldOpenMediaViewer = _this$props8.shouldOpenMediaViewer,
543
+ shouldHideTooltip = _this$props8.shouldHideTooltip,
544
+ expandByPixel = _this$props8.expandByPixel;
545
+ var mediaItemType = identifier.mediaItemType;
546
+ var _this$state2 = _this.state,
547
+ status = _this$state2.status,
548
+ progress = _this$state2.progress,
549
+ cardPreview = _this$state2.cardPreview,
550
+ error = _this$state2.error,
551
+ cardRef = _this$state2.cardRef,
552
+ isCardVisible = _this$state2.isCardVisible;
553
+ var _assertThisInitialize3 = _assertThisInitialized(_this),
554
+ metadata = _assertThisInitialize3.metadata;
555
+ var _assertThisInitialize4 = _assertThisInitialized(_this),
556
+ onCardViewClick = _assertThisInitialize4.onCardViewClick,
557
+ onDisplayImage = _assertThisInitialize4.onDisplayImage,
558
+ actions = _assertThisInitialize4.actions,
559
+ onMouseEnter = _assertThisInitialize4.onMouseEnter;
560
+ var isLazyWithOverride = izLazyOverride === undefined ? isLazy : izLazyOverride;
561
+
562
+ // Card can be artificially turned visible before entering the viewport
563
+ // For example, when we have the image in cache
564
+ var nativeLazyLoad = isLazyWithOverride && !isCardVisible;
565
+ // Force Media Image to always display img for SSR
566
+ var forceSyncDisplay = !!ssr;
567
+ var mediaCardCursor = getMediaCardCursor(!!useInlinePlayer, !!shouldOpenMediaViewer, status === 'error' || status === 'failed-processing', !!_this.state.cardPreview, metadata.mediaType);
568
+ var card = /*#__PURE__*/React.createElement(CardView, {
569
+ expandByPixel: expandByPixel,
570
+ status: cardStatusOverride || status,
571
+ error: error,
572
+ mediaItemType: mediaItemType,
573
+ metadata: metadata,
574
+ cardPreview: cardPreview,
575
+ alt: alt,
576
+ appearance: appearance,
577
+ resizeMode: resizeMode,
578
+ dimensions: dimensions,
579
+ actions: actions,
580
+ selectable: selectable,
581
+ selected: selected,
582
+ onClick: withCallbacks ? onCardViewClick : undefined,
583
+ onMouseEnter: withCallbacks ? onMouseEnter : undefined,
584
+ disableOverlay: disableOverlay,
585
+ progress: progress,
586
+ onDisplayImage: withCallbacks ? onDisplayImage : undefined,
587
+ innerRef: _this.setRef,
588
+ testId: testId,
589
+ featureFlags: featureFlags,
590
+ titleBoxBgColor: titleBoxBgColor,
591
+ titleBoxIcon: titleBoxIcon,
592
+ onImageError: withCallbacks ? _this.onImageError : undefined,
593
+ onImageLoad: withCallbacks ? _this.onImageLoad : undefined,
594
+ nativeLazyLoad: nativeLazyLoad,
595
+ forceSyncDisplay: forceSyncDisplay,
596
+ mediaCardCursor: mediaCardCursor,
597
+ shouldHideTooltip: shouldHideTooltip
598
+ });
599
+ return isLazyWithOverride ? /*#__PURE__*/React.createElement(ViewportDetector, {
600
+ cardEl: cardRef,
601
+ onVisible: _this.onCardInViewport
602
+ }, card) : card;
603
+ });
604
+ _defineProperty(_assertThisInitialized(_this), "storeSSRData", function () {
605
+ var _this$ssrReliability$;
606
+ var _this$props9 = _this.props,
607
+ ssr = _this$props9.ssr,
608
+ identifier = _this$props9.identifier;
609
+ var _this$state$cardPrevi = _this.state.cardPreview,
610
+ _this$state$cardPrevi2 = _this$state$cardPrevi === void 0 ? {} : _this$state$cardPrevi,
611
+ dataURI = _this$state$cardPrevi2.dataURI;
612
+ return isFileIdentifier(identifier) && ssr === 'server' && /*#__PURE__*/React.createElement(StoreSSRDataScript, {
613
+ identifier: identifier,
614
+ dataURI: dataURI,
615
+ dimensions: _this.requestedDimensions,
616
+ error: ((_this$ssrReliability$ = _this.ssrReliability.server) === null || _this$ssrReliability$ === void 0 ? void 0 : _this$ssrReliability$.status) === 'fail' ? _this.ssrReliability.server : undefined
617
+ });
618
+ });
619
+ _defineProperty(_assertThisInitialized(_this), "onCardInViewport", function () {
620
+ _this.setState({
621
+ isCardVisible: true
622
+ });
623
+ });
624
+ _defineProperty(_assertThisInitialized(_this), "onClick", function (event, analyticsEvent) {
625
+ var onClick = _this.props.onClick;
626
+ var _assertThisInitialize5 = _assertThisInitialized(_this),
627
+ metadata = _assertThisInitialize5.metadata;
628
+ if (onClick) {
629
+ var cardEvent = {
630
+ event: event,
631
+ mediaItemDetails: metadata
632
+ };
633
+ onClick(cardEvent, analyticsEvent);
634
+ }
635
+ });
636
+ _defineProperty(_assertThisInitialized(_this), "onMouseEnter", function (event) {
637
+ var onMouseEnter = _this.props.onMouseEnter;
638
+ var _assertThisInitialize6 = _assertThisInitialized(_this),
639
+ metadata = _assertThisInitialize6.metadata;
640
+ if (onMouseEnter) {
641
+ var cardEvent = {
642
+ event: event,
643
+ mediaItemDetails: metadata
644
+ };
645
+ onMouseEnter(cardEvent);
646
+ }
647
+ });
648
+ var _status = 'loading';
649
+ var _cardPreview;
650
+ var _error;
651
+ var _this$props10 = _this.props,
652
+ _identifier = _this$props10.identifier,
653
+ _resizeMode = _this$props10.resizeMode,
654
+ _ssr = _this$props10.ssr,
655
+ _mediaClient = _this$props10.mediaClient;
656
+ if (isFileIdentifier(_identifier)) {
657
+ var id = _identifier.id;
658
+ var fileImageMode = imageResizeModeToFileImageMode(_resizeMode);
659
+ _cardPreview = getCardPreviewFromCache(id, fileImageMode);
660
+ if (!_cardPreview && _ssr) {
661
+ _cardPreview = _this.getSSRPreview(_ssr, _identifier, _mediaClient);
662
+ }
663
+ } else if (isExternalImageIdentifier(_identifier)) {
664
+ _this.fireCommencedEvent();
665
+ _status = 'loading-preview';
666
+ var dataURI = _identifier.dataURI;
667
+ _cardPreview = {
668
+ dataURI: dataURI,
669
+ orientation: 1,
670
+ source: 'external'
671
+ };
672
+ }
673
+
674
+ // If cardPreview is available from local cache or external, `isCardVisible`
675
+ // should be true to avoid flickers during re-mount of the component
676
+ // should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
677
+ // outside the viewport
678
+ var _isCardVisible = !_this.props.isLazy || !!_cardPreview && !isSSRPreview(_cardPreview);
679
+ _this.state = {
680
+ status: _status,
681
+ isCardVisible: _isCardVisible,
682
+ isPlayingFile: false,
683
+ shouldAutoplay: false,
684
+ cardPreview: _cardPreview,
685
+ cardRef: null,
686
+ isBannedLocalPreview: false,
687
+ previewDidRender: false,
688
+ error: _error,
689
+ wasResolvedUpfrontPreview: false,
690
+ shouldUpdateStateForIdentifier: false
691
+ };
692
+ return _this;
693
+ }
694
+ _createClass(CardV2Base, [{
695
+ key: "getSSRPreview",
696
+ value: function getSSRPreview(ssr, identifier, mediaClient) {
697
+ var _this$ssrData, _this$ssrData2;
698
+ this.ssrData = getSSRData(identifier);
699
+ if ((_this$ssrData = this.ssrData) !== null && _this$ssrData !== void 0 && _this$ssrData.error) {
700
+ this.ssrReliability.server = _objectSpread({
701
+ status: 'fail'
702
+ }, this.ssrData.error);
703
+ }
704
+ if (!((_this$ssrData2 = this.ssrData) !== null && _this$ssrData2 !== void 0 && _this$ssrData2.dataURI)) {
705
+ try {
706
+ return getSSRCardPreview(ssr, mediaClient, identifier.id, this.getImageURLParams(identifier), this.getMediaBlobUrlAttrs(identifier));
707
+ } catch (e) {
708
+ this.ssrReliability[ssr] = _objectSpread({
709
+ status: 'fail'
710
+ }, extractErrorInfo(e));
711
+ }
712
+ } else {
713
+ return {
714
+ dataURI: this.ssrData.dataURI,
715
+ source: 'ssr-data'
716
+ };
717
+ }
718
+ }
719
+ }, {
720
+ key: "componentDidMount",
721
+ value: function componentDidMount() {
722
+ var _getDocument;
723
+ this.hasBeenMounted = true;
724
+ var _this$state3 = this.state,
725
+ isCardVisible = _this$state3.isCardVisible,
726
+ cardPreview = _this$state3.cardPreview;
727
+ var _this$props11 = this.props,
728
+ identifier = _this$props11.identifier,
729
+ ssr = _this$props11.ssr,
730
+ dimensions = _this$props11.dimensions;
731
+ if (isCardVisible && isFileIdentifier(identifier)) {
732
+ this.updateStateForIdentifier(identifier);
733
+ if (!cardPreview) {
734
+ this.resolveUpfrontPreview(identifier);
735
+ }
736
+ }
737
+ if (isCardVisible && !!ssr && !!cardPreview && isFileIdentifier(identifier)) {
738
+ var _this$ssrData3;
739
+ if (isSSRClientPreview(cardPreview)) {
740
+ // Since the SSR preview brings the token in the query params,
741
+ // We need to fetch the remote preview to be able to cache it,
742
+ this.setCacheSSRPreview(identifier);
743
+ }
744
+ if (isSSRDataPreview(cardPreview) && isBigger((_this$ssrData3 = this.ssrData) === null || _this$ssrData3 === void 0 ? void 0 : _this$ssrData3.dimensions, dimensions)) {
745
+ // If dimensions from Server have changed and are bigger,
746
+ // we need to refetch
747
+ this.refetchSSRPreview(identifier);
748
+ }
749
+ }
750
+ // we add a listener for each of the cards on the page
751
+ // and then check if the triggered listener is from the card
752
+ // that contains a div in current window.getSelection()
753
+ // won't work in IE11
754
+ (_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.addEventListener('copy', this.fireCopiedEvent);
755
+ }
756
+ }, {
757
+ key: "componentDidUpdate",
758
+ value: function componentDidUpdate(prevProps, prevState) {
759
+ var prevMediaClient = prevProps.mediaClient,
760
+ prevIdentifier = prevProps.identifier,
761
+ prevDimensions = prevProps.dimensions;
762
+ var prevIsCardVisible = prevState.isCardVisible,
763
+ prevCardPreview = prevState.cardPreview;
764
+ var _this$props12 = this.props,
765
+ mediaClient = _this$props12.mediaClient,
766
+ identifier = _this$props12.identifier,
767
+ dimensions = _this$props12.dimensions,
768
+ featureFlags = _this$props12.featureFlags,
769
+ useInlinePlayer = _this$props12.useInlinePlayer,
770
+ disableOverlay = _this$props12.disableOverlay,
771
+ resizeMode = _this$props12.resizeMode,
772
+ ssr = _this$props12.ssr;
773
+ var _this$state4 = this.state,
774
+ isCardVisible = _this$state4.isCardVisible,
775
+ cardPreview = _this$state4.cardPreview,
776
+ status = _this$state4.status,
777
+ fileState = _this$state4.fileState,
778
+ isBannedLocalPreview = _this$state4.isBannedLocalPreview,
779
+ previewDidRender = _this$state4.previewDidRender,
780
+ isPlayingFile = _this$state4.isPlayingFile,
781
+ wasResolvedUpfrontPreview = _this$state4.wasResolvedUpfrontPreview;
782
+ var isDiffIdentifier = isDifferentIdentifier(prevIdentifier, identifier);
783
+ /**
784
+ * Variable turnedVisible should only be true when media card
785
+ * was invisible in the previous state and is visible in the current one
786
+ *
787
+ * prevIsCardVisible | isCardVisible | turnedVisible
788
+ * ----------------------------------------------------
789
+ * false | false | false
790
+ * false | true | true
791
+ * true | true | false
792
+ * true | false | false (unreachable case)
793
+ * ----------------------------------------------------
794
+ */
795
+ var turnedVisible = !prevIsCardVisible && isCardVisible;
796
+ var hadSSRCardPreview = !!prevCardPreview && isSSRClientPreview(prevCardPreview) && !cardPreview;
797
+ var isNewMediaClient = prevMediaClient !== mediaClient;
798
+ var fileImageMode = imageResizeModeToFileImageMode(resizeMode);
799
+ this.updateFileStateFlag(fileState);
800
+ if (isExternalImageIdentifier(identifier) && isDiffIdentifier) {
801
+ this.fireCommencedEvent();
802
+ var dataURI = identifier.dataURI;
803
+ this.setState({
804
+ status: 'loading-preview',
805
+ cardPreview: {
806
+ dataURI: dataURI,
807
+ orientation: 1,
808
+ source: 'external'
809
+ },
810
+ isCardVisible: true
811
+ });
812
+ }
813
+ if (isFileIdentifier(identifier) && (turnedVisible || !!this.subscription && (isNewMediaClient || isDiffIdentifier))) {
814
+ this.updateStateForIdentifier(identifier);
815
+ }
816
+ if (this.state.status !== prevState.status) {
817
+ this.fireOperationalEvent();
818
+ if (this.state.status === 'complete' || this.fileAttributes.fileMediatype === 'video' && !!cardPreview && this.state.status === 'processing') {
819
+ this.fireScreenEvent();
820
+ }
821
+ }
822
+ if (isFileIdentifier(identifier) && (turnedVisible || ssr === 'client' && hadSSRCardPreview) && !cardPreview && !wasResolvedUpfrontPreview) {
823
+ // This is a one-off call, only meant to happen once in the component's lifecycle. Mainly when either:
824
+ // - turnedVisible = true
825
+ // - ssr = client and has no preview (the dataURI failed to load in the previous state, most likely because of an initial auth issue)
826
+ this.resolveUpfrontPreview(identifier);
827
+ } else if (isFileIdentifier(identifier) && fileState && shouldResolvePreview({
828
+ status: status,
829
+ fileState: fileState,
830
+ prevDimensions: prevDimensions,
831
+ dimensions: dimensions,
832
+ identifier: identifier,
833
+ fileImageMode: fileImageMode,
834
+ featureFlags: featureFlags,
835
+ hasCardPreview: !!cardPreview,
836
+ isBannedLocalPreview: isBannedLocalPreview,
837
+ wasResolvedUpfrontPreview: wasResolvedUpfrontPreview
838
+ })) {
839
+ this.resolvePreview(identifier, fileState);
840
+ }
841
+ if (turnedVisible && this.props.ssr && !!cardPreview && isSSRClientPreview(cardPreview) && isFileIdentifier(identifier)) {
842
+ // Since the SSR preview brings the token in the query params,
843
+ // We need to fetch the remote preview to be able to cache it,
844
+ this.setCacheSSRPreview(identifier);
845
+ }
846
+ if (previewDidRender &&
847
+ // We should't complete if status is uploading
848
+ ['loading-preview', 'processing'].includes(status)) {
849
+ this.safeSetState({
850
+ status: 'complete',
851
+ shouldUpdateStateForIdentifier: false
852
+ });
853
+ if (this.hasBeenMounted) {
854
+ // TODO MEX-788: add test for "do not remove the card preview when unsubscribing".
855
+ this.setState({
856
+ isBannedLocalPreview: false
857
+ });
858
+ }
859
+ }
860
+ var isVideo = this.fileAttributes.fileMediatype === 'video';
861
+ var _getFileDetails2 = getFileDetails(identifier, fileState),
862
+ mimeType = _getFileDetails2.mimeType;
863
+ var isVideoPlayable = videoIsPlayable(isBannedLocalPreview, fileState, mimeType);
864
+ if (isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && isVideoPlayable) {
865
+ this.setState({
866
+ isPlayingFile: true
867
+ });
868
+ }
869
+ }
870
+ }, {
871
+ key: "componentWillUnmount",
872
+ value: function componentWillUnmount() {
873
+ var _getDocument2;
874
+ this.hasBeenMounted = false;
875
+ (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.removeEventListener('copy', this.fireCopiedEvent);
876
+ }
877
+ }, {
878
+ key: "updateStateForIdentifier",
879
+ value: function updateStateForIdentifier(identifier) {
880
+ this.fireCommencedEvent();
881
+ this.setState({
882
+ shouldUpdateStateForIdentifier: true
883
+ });
884
+ }
885
+ }, {
886
+ key: "updateFileStateFlag",
887
+ value: function updateFileStateFlag(fileState) {
888
+ if (!fileState) {
889
+ return;
890
+ }
891
+ var status = fileState.status;
892
+ if (status === 'processing') {
893
+ this.fileStateFlags.wasStatusProcessing = true;
894
+ } else if (status === 'uploading') {
895
+ this.fileStateFlags.wasStatusUploading = true;
896
+ }
897
+ }
898
+ }, {
899
+ key: "requestedDimensions",
900
+ get: function get() {
901
+ var dimensions = this.props.dimensions;
902
+ var _ref5 = this.state || {},
903
+ element = _ref5.cardRef;
904
+ return getRequestedDimensions({
905
+ dimensions: dimensions,
906
+ element: element
907
+ });
908
+ }
909
+ }, {
910
+ key: "metadata",
911
+ get: function get() {
912
+ var _this$state5;
913
+ return getFileDetails(this.props.identifier, (_this$state5 = this.state) === null || _this$state5 === void 0 ? void 0 : _this$state5.fileState);
914
+ }
915
+ }, {
916
+ key: "fileAttributes",
917
+ get: function get() {
918
+ var _this$state6, _this$state6$fileStat;
919
+ return 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);
920
+ }
921
+ }, {
922
+ key: "fireOperationalEvent",
923
+ value: function fireOperationalEvent() {
924
+ var _this$state7 = this.state,
925
+ status = _this$state7.status,
926
+ error = _this$state7.error,
927
+ fileState = _this$state7.fileState;
928
+ var createAnalyticsEvent = this.props.createAnalyticsEvent;
929
+ createAnalyticsEvent && _fireOperationalEvent(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), this.ssrReliability, error, this.traceContext, fileState === null || fileState === void 0 ? void 0 : fileState.metadataTraceContext);
930
+ completeUfoExperience(this.internalOccurrenceKey, status, this.fileAttributes, this.fileStateFlags, this.ssrReliability, error);
931
+ }
932
+ }, {
933
+ key: "fireCommencedEvent",
934
+ value: function fireCommencedEvent() {
935
+ this.timeElapsedTillCommenced = performance.now();
936
+ var createAnalyticsEvent = this.props.createAnalyticsEvent;
937
+ createAnalyticsEvent && _fireCommencedEvent(createAnalyticsEvent, this.fileAttributes, {
938
+ overall: {
939
+ durationSincePageStart: this.timeElapsedTillCommenced
940
+ }
941
+ }, this.traceContext);
942
+ startUfoExperience(this.internalOccurrenceKey);
943
+ }
944
+ }, {
945
+ key: "actions",
946
+ get: function get() {
947
+ var _this2 = this;
948
+ var _this$props13 = this.props,
949
+ _this$props13$actions = _this$props13.actions,
950
+ actions = _this$props13$actions === void 0 ? [] : _this$props13$actions,
951
+ identifier = _this$props13.identifier,
952
+ shouldEnableDownloadButton = _this$props13.shouldEnableDownloadButton;
953
+ var status = this.state.status;
954
+ var metadata = this.metadata;
955
+ if (isFileIdentifier(identifier) && (status === 'failed-processing' || shouldEnableDownloadButton)) {
956
+ var downloadAction = {
957
+ label: 'Download',
958
+ icon: /*#__PURE__*/React.createElement(DownloadIcon, {
959
+ label: "Download"
960
+ }),
961
+ handler: function handler() {
962
+ return _this2.props.mediaClient.file.downloadBinary(identifier.id, metadata.name, identifier.collectionName);
963
+ }
964
+ };
965
+ return [downloadAction].concat(_toConsumableArray(actions));
966
+ } else {
967
+ return actions;
968
+ }
969
+ }
970
+ }, {
971
+ key: "render",
972
+ value: function render() {
973
+ var _this$state8 = this.state,
974
+ isPlayingFile = _this$state8.isPlayingFile,
975
+ mediaViewerSelectedItem = _this$state8.mediaViewerSelectedItem,
976
+ shouldUpdateStateForIdentifier = _this$state8.shouldUpdateStateForIdentifier;
977
+ var innerContent = /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null, this.storeSSRData());
978
+ var wrappedContent = innerContent;
979
+ if (shouldUpdateStateForIdentifier) {
980
+ var _ref6 = this.props.identifier,
981
+ id = _ref6.id,
982
+ collectionName = _ref6.collectionName,
983
+ occurrenceKey = _ref6.occurrenceKey;
984
+ wrappedContent = /*#__PURE__*/React.createElement(FileStateListener, {
985
+ id: id,
986
+ onChange: this.subscribeFileState,
987
+ collectionName: collectionName,
988
+ occurrenceKey: occurrenceKey
989
+ }, innerContent);
990
+ }
991
+ return this.props.intl ? wrappedContent : /*#__PURE__*/React.createElement(IntlProvider, {
992
+ locale: "en"
993
+ }, wrappedContent);
994
+ }
995
+ }]);
996
+ return CardV2Base;
997
+ }(Component);
998
+ _defineProperty(CardV2Base, "defaultProps", {
999
+ appearance: 'auto',
1000
+ resizeMode: 'crop',
1001
+ isLazy: true,
1002
+ disableOverlay: false,
1003
+ // Media Feature Flag defaults are defined in @atlaskit/media-common
1004
+ featureFlags: {}
1005
+ });
1006
+ var FileStateListener = function FileStateListener(_ref7) {
1007
+ var children = _ref7.children,
1008
+ onChange = _ref7.onChange,
1009
+ id = _ref7.id,
1010
+ collectionName = _ref7.collectionName,
1011
+ occurrenceKey = _ref7.occurrenceKey;
1012
+ var _useFileState = useFileState(id, {
1013
+ collectionName: collectionName,
1014
+ occurrenceKey: occurrenceKey
1015
+ }),
1016
+ fileState = _useFileState.fileState;
1017
+ useEffect(function () {
1018
+ if (fileState) {
1019
+ onChange(fileState);
1020
+ }
1021
+ }, [fileState, onChange]);
1022
+ return children;
1023
+ };
1024
+
1025
+ /**
1026
+ * We require this wrapper in order to refresh media card state when the identifier is updated (via a key)
1027
+ * TODO: remove the key when the cardV2 is no longer required
1028
+ */
1029
+ var CardWithKey = function CardWithKey(props) {
1030
+ var identifier = props.identifier;
1031
+ var key = isFileIdentifier(identifier) ? identifier.id : identifier.dataURI;
1032
+ return /*#__PURE__*/React.createElement(CardV2Base, _extends({}, props, {
1033
+ key: key
1034
+ }));
1035
+ };
1036
+ export var CardV2 = withMediaAnalyticsContext({
1037
+ packageVersion: packageVersion,
1038
+ packageName: packageName,
1039
+ componentName: 'mediaCard',
1040
+ component: 'mediaCard'
1041
+ })(withAnalyticsEvents()(injectIntl(CardWithKey, {
1042
+ enforceContext: false
1043
+ })));