@atlaskit/media-card 77.2.3 → 77.3.0

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