@atlaskit/media-card 77.4.4 → 77.4.6
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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/card/card.js +42 -38
- package/dist/cjs/card/getCardPreview/filePreviewStatus.js +2 -0
- package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/cjs/card/v2/cardV2.js +1 -1
- package/dist/cjs/card/v2/fileCard.js +120 -521
- package/dist/cjs/card/v2/useFilePreview.js +592 -0
- package/dist/cjs/inline/loader.js +1 -1
- package/dist/cjs/utils/ufoExperiences.js +1 -1
- package/dist/es2019/card/card.js +7 -4
- package/dist/es2019/card/getCardPreview/filePreviewStatus.js +2 -0
- package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/es2019/card/v2/cardV2.js +1 -1
- package/dist/es2019/card/v2/fileCard.js +105 -436
- package/dist/es2019/card/v2/useFilePreview.js +499 -0
- package/dist/es2019/inline/loader.js +1 -1
- package/dist/es2019/utils/ufoExperiences.js +1 -1
- package/dist/esm/card/card.js +42 -38
- package/dist/esm/card/getCardPreview/filePreviewStatus.js +2 -0
- package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/esm/card/v2/cardV2.js +1 -1
- package/dist/esm/card/v2/fileCard.js +125 -526
- package/dist/esm/card/v2/useFilePreview.js +584 -0
- package/dist/esm/inline/loader.js +1 -1
- package/dist/esm/utils/ufoExperiences.js +1 -1
- package/dist/types/card/card.d.ts +1 -1
- package/dist/types/card/v2/useFilePreview.d.ts +38 -0
- package/dist/types-ts4.5/card/card.d.ts +1 -1
- package/dist/types-ts4.5/card/v2/useFilePreview.d.ts +38 -0
- package/package.json +4 -4
- package/tmp/api-report-tmp.d.ts +0 -345
|
@@ -1,40 +1,32 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
5
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
4
|
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; }
|
|
7
5
|
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; }
|
|
8
6
|
import DownloadIcon from '@atlaskit/icon/glyph/download';
|
|
9
|
-
import { RECENTS_COLLECTION,
|
|
7
|
+
import { RECENTS_COLLECTION, globalMediaEventEmitter, isImageRepresentationReady } from '@atlaskit/media-client';
|
|
10
8
|
import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
|
|
11
|
-
import {
|
|
12
|
-
import { getOrientation } from '@atlaskit/media-ui';
|
|
9
|
+
import { getRandomHex, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
13
10
|
import { MediaViewer } from '@atlaskit/media-viewer';
|
|
14
|
-
import React, { Suspense,
|
|
11
|
+
import React, { Suspense, useEffect, useMemo, useRef, useState } from 'react';
|
|
15
12
|
import ReactDOM from 'react-dom';
|
|
16
|
-
import {
|
|
17
|
-
import { extractErrorInfo } from '../../utils/analytics';
|
|
18
|
-
import { isBigger } from '../../utils/dimensionComparer';
|
|
13
|
+
import { MediaCardError } from '../../errors';
|
|
19
14
|
import getDocument from '../../utils/document';
|
|
20
15
|
import { generateUniqueId } from '../../utils/generateUniqueId';
|
|
21
16
|
import { getRequestedDimensions } from '../../utils/getDataURIDimension';
|
|
22
17
|
import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
|
|
23
|
-
import { getSSRData, StoreSSRDataScript } from '../../utils/globalScope';
|
|
24
18
|
import { getFileDetails } from '../../utils/metadata';
|
|
25
19
|
import { abortUfoExperience, completeUfoExperience, startUfoExperience } from '../../utils/ufoExperiences';
|
|
26
20
|
import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
|
|
27
21
|
import { usePrevious } from '../../utils/usePrevious';
|
|
28
22
|
import { videoIsPlayable } from '../../utils/videoIsPlayable';
|
|
29
|
-
import { takeSnapshot } from '../../utils/videoSnapshot';
|
|
30
23
|
import { ViewportDetector } from '../../utils/viewportDetector';
|
|
31
24
|
import { fireCommencedEvent, fireCopiedEvent, fireNonCriticalErrorEvent, fireOperationalEvent, fireScreenEvent } from '../cardAnalytics';
|
|
32
|
-
import {
|
|
33
|
-
import cardPreviewCache from '../getCardPreview/cache';
|
|
25
|
+
import { isSSRPreview } from '../getCardPreview';
|
|
34
26
|
import { CardViewV2 } from './cardViewV2';
|
|
35
27
|
import { InlinePlayerLazyV2 } from './inlinePlayerLazyV2';
|
|
28
|
+
import { useFilePreview } from './useFilePreview';
|
|
36
29
|
export var FileCard = function FileCard(_ref) {
|
|
37
|
-
var _ssrReliabilityRef$cu;
|
|
38
30
|
var _ref$appearance = _ref.appearance,
|
|
39
31
|
appearance = _ref$appearance === void 0 ? 'auto' : _ref$appearance,
|
|
40
32
|
_ref$resizeMode = _ref.resizeMode,
|
|
@@ -68,102 +60,26 @@ export var FileCard = function FileCard(_ref) {
|
|
|
68
60
|
onMouseEnter = _ref.onMouseEnter,
|
|
69
61
|
createAnalyticsEvent = _ref.createAnalyticsEvent;
|
|
70
62
|
//----------------------------------------------------------------//
|
|
71
|
-
|
|
63
|
+
//------------ State, Refs & Initial Values ----------------------//
|
|
72
64
|
//----------------------------------------------------------------//
|
|
73
65
|
|
|
74
|
-
var ssrDataRef = useRef();
|
|
75
|
-
var ssrReliabilityRef = useRef({
|
|
76
|
-
server: {
|
|
77
|
-
status: 'unknown'
|
|
78
|
-
},
|
|
79
|
-
client: {
|
|
80
|
-
status: 'unknown'
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
66
|
var _useState = useState(null),
|
|
84
67
|
_useState2 = _slicedToArray(_useState, 2),
|
|
85
68
|
cardElement = _useState2[0],
|
|
86
69
|
setCardElement = _useState2[1];
|
|
87
|
-
var
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}, [cardElement, dimensions, identifier.collectionName, resizeMode]);
|
|
98
|
-
var getMediaBlobUrlAttrs = useCallback(function (fileState) {
|
|
99
|
-
var id = identifier.id,
|
|
100
|
-
collection = identifier.collectionName;
|
|
101
|
-
var _getFileDetails = getFileDetails(identifier, fileState),
|
|
102
|
-
mimeType = _getFileDetails.mimeType,
|
|
103
|
-
name = _getFileDetails.name,
|
|
104
|
-
size = _getFileDetails.size;
|
|
105
|
-
return contextId ? _objectSpread(_objectSpread({
|
|
106
|
-
id: id,
|
|
107
|
-
collection: collection,
|
|
108
|
-
contextId: contextId,
|
|
109
|
-
mimeType: mimeType,
|
|
110
|
-
name: name,
|
|
111
|
-
size: size
|
|
112
|
-
}, originalDimensions || getRequestedDimensions({
|
|
113
|
-
dimensions: dimensions,
|
|
114
|
-
element: cardElement
|
|
115
|
-
})), {}, {
|
|
116
|
-
alt: alt
|
|
117
|
-
}) : undefined;
|
|
118
|
-
}, [alt, cardElement, contextId, dimensions, identifier, originalDimensions]);
|
|
119
|
-
var getSSRPreview = function getSSRPreview(ssr, identifier, mediaClient) {
|
|
120
|
-
var _ssrDataRef$current, _ssrDataRef$current2;
|
|
121
|
-
ssrDataRef.current = getSSRData(identifier);
|
|
122
|
-
if ((_ssrDataRef$current = ssrDataRef.current) !== null && _ssrDataRef$current !== void 0 && _ssrDataRef$current.error) {
|
|
123
|
-
ssrReliabilityRef.current.server = _objectSpread({
|
|
124
|
-
status: 'fail'
|
|
125
|
-
}, ssrDataRef.current.error);
|
|
126
|
-
}
|
|
127
|
-
if (!((_ssrDataRef$current2 = ssrDataRef.current) !== null && _ssrDataRef$current2 !== void 0 && _ssrDataRef$current2.dataURI)) {
|
|
128
|
-
try {
|
|
129
|
-
return getSSRCardPreview(ssr, mediaClient, identifier.id, imageURLParams, getMediaBlobUrlAttrs(fileStateValue));
|
|
130
|
-
} catch (e) {
|
|
131
|
-
ssrReliabilityRef.current[ssr] = _objectSpread({
|
|
132
|
-
status: 'fail'
|
|
133
|
-
}, extractErrorInfo(e));
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
return {
|
|
137
|
-
dataURI: ssrDataRef.current.dataURI,
|
|
138
|
-
source: 'ssr-data'
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
var cardPreviewInitializer = function cardPreviewInitializer() {
|
|
143
|
-
var cardPreview;
|
|
144
|
-
var id = identifier.id;
|
|
145
|
-
var fileImageMode = imageResizeModeToFileImageMode(resizeMode);
|
|
146
|
-
cardPreview = getCardPreviewFromCache(id, fileImageMode);
|
|
147
|
-
if (!cardPreview && ssr) {
|
|
148
|
-
cardPreview = getSSRPreview(ssr, identifier, mediaClient);
|
|
149
|
-
}
|
|
150
|
-
return cardPreview;
|
|
151
|
-
};
|
|
152
|
-
var _useState3 = useState(cardPreviewInitializer),
|
|
70
|
+
var requestedDimensions = useMemo(function () {
|
|
71
|
+
return (
|
|
72
|
+
// requested dimensions is eventually an expensive operation if the dimensions are a percentage
|
|
73
|
+
getRequestedDimensions({
|
|
74
|
+
dimensions: dimensions,
|
|
75
|
+
element: cardElement
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
}, [dimensions, cardElement]);
|
|
79
|
+
var _useState3 = useState(!isLazy),
|
|
153
80
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
// If cardPreview is available from local cache or external, `isCardVisible`
|
|
158
|
-
// should be true to avoid flickers during re-mount of the component
|
|
159
|
-
// should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
|
|
160
|
-
// outside the viewport
|
|
161
|
-
var _useState5 = useState(function () {
|
|
162
|
-
return !isLazy || cardPreview && !isSSRPreview(cardPreview);
|
|
163
|
-
}),
|
|
164
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
165
|
-
isCardVisible = _useState6[0],
|
|
166
|
-
setIsCardVisible = _useState6[1];
|
|
81
|
+
isCardVisible = _useState4[0],
|
|
82
|
+
setIsCardVisible = _useState4[1];
|
|
167
83
|
var _useFileState = useFileState(identifier.id, {
|
|
168
84
|
skipRemote: !isCardVisible,
|
|
169
85
|
collectionName: identifier.collectionName,
|
|
@@ -200,35 +116,79 @@ export var FileCard = function FileCard(_ref) {
|
|
|
200
116
|
traceId: getRandomHex(8)
|
|
201
117
|
};
|
|
202
118
|
}, []);
|
|
203
|
-
var
|
|
119
|
+
var _useState5 = useState('loading'),
|
|
120
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
121
|
+
status = _useState6[0],
|
|
122
|
+
setStatus = _useState6[1];
|
|
123
|
+
var _useState7 = useState(false),
|
|
204
124
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
205
|
-
|
|
206
|
-
|
|
125
|
+
isPlayingFile = _useState8[0],
|
|
126
|
+
setIsPlayingFile = _useState8[1];
|
|
207
127
|
var _useState9 = useState(false),
|
|
208
128
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
209
|
-
|
|
210
|
-
|
|
129
|
+
shouldAutoplay = _useState10[0],
|
|
130
|
+
setShouldAutoplay = _useState10[1];
|
|
131
|
+
|
|
132
|
+
// CXP-2723 TODO: remove isBannedLocalPreview
|
|
211
133
|
var _useState11 = useState(false),
|
|
212
134
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
213
|
-
|
|
214
|
-
|
|
135
|
+
isBannedLocalPreview = _useState12[0],
|
|
136
|
+
setIsBannedLocalPreview = _useState12[1];
|
|
215
137
|
var _useState13 = useState(false),
|
|
216
138
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
139
|
+
previewDidRender = _useState14[0],
|
|
140
|
+
setPreviewDidRender = _useState14[1];
|
|
141
|
+
|
|
142
|
+
// CXP-2723 TODO: Do we have tests to validate the use of the below attributes
|
|
143
|
+
var mediaBlobUrlAttrs = useMemo(function () {
|
|
144
|
+
var id = identifier.id,
|
|
145
|
+
collection = identifier.collectionName;
|
|
146
|
+
var _getFileDetails = getFileDetails(identifier, fileStateValue),
|
|
147
|
+
mimeType = _getFileDetails.mimeType,
|
|
148
|
+
name = _getFileDetails.name,
|
|
149
|
+
size = _getFileDetails.size;
|
|
150
|
+
return contextId ? _objectSpread(_objectSpread({
|
|
151
|
+
id: id,
|
|
152
|
+
collection: collection,
|
|
153
|
+
contextId: contextId,
|
|
154
|
+
mimeType: mimeType,
|
|
155
|
+
name: name,
|
|
156
|
+
size: size
|
|
157
|
+
}, originalDimensions || requestedDimensions), {}, {
|
|
158
|
+
alt: alt
|
|
159
|
+
}) : undefined;
|
|
160
|
+
}, [alt, requestedDimensions, contextId, fileStateValue, identifier, originalDimensions]);
|
|
161
|
+
var _useFilePreview = useFilePreview({
|
|
162
|
+
mediaBlobUrlAttrs: mediaBlobUrlAttrs,
|
|
163
|
+
resizeMode: resizeMode,
|
|
164
|
+
identifier: identifier,
|
|
165
|
+
ssr: ssr,
|
|
166
|
+
mediaClient: mediaClient,
|
|
167
|
+
dimensions: dimensions,
|
|
168
|
+
requestedDimensions: requestedDimensions,
|
|
169
|
+
traceContext: traceContext,
|
|
170
|
+
previewDidRender: previewDidRender,
|
|
171
|
+
skipRemote: !isCardVisible
|
|
172
|
+
}),
|
|
173
|
+
cardPreview = _useFilePreview.cardPreview,
|
|
174
|
+
previewError = _useFilePreview.error,
|
|
175
|
+
nonCriticalError = _useFilePreview.nonCriticalError,
|
|
176
|
+
ssrReliabilityRef = _useFilePreview.ssrReliabilityRef,
|
|
177
|
+
onImageErrorBase = _useFilePreview.onImageError,
|
|
178
|
+
onImageLoadBase = _useFilePreview.onImageLoad,
|
|
179
|
+
StoreSSRDataScript = _useFilePreview.StoreSSRDataScript;
|
|
180
|
+
var _useState15 = useState(),
|
|
220
181
|
_useState16 = _slicedToArray(_useState15, 2),
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
182
|
+
error = _useState16[0],
|
|
183
|
+
setError = _useState16[1];
|
|
184
|
+
|
|
185
|
+
// CXP-2723 TODO: TEMPORARY VARIABLES
|
|
186
|
+
var finalError = error || previewError;
|
|
187
|
+
var finalStatus = finalError ? 'error' : status;
|
|
188
|
+
var _useState17 = useState(null),
|
|
224
189
|
_useState18 = _slicedToArray(_useState17, 2),
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
var wasResolvedUpfrontPreviewRef = useRef(false);
|
|
228
|
-
var _useState19 = useState(null),
|
|
229
|
-
_useState20 = _slicedToArray(_useState19, 2),
|
|
230
|
-
mediaViewerSelectedItem = _useState20[0],
|
|
231
|
-
setMediaViewerSelectedItem = _useState20[1];
|
|
190
|
+
mediaViewerSelectedItem = _useState18[0],
|
|
191
|
+
setMediaViewerSelectedItem = _useState18[1];
|
|
232
192
|
var uploadProgressRef = useRef();
|
|
233
193
|
var metadata = useMemo(function () {
|
|
234
194
|
var getProcessingStatusFromFileState = function getProcessingStatusFromFileState(status) {
|
|
@@ -267,7 +227,7 @@ export var FileCard = function FileCard(_ref) {
|
|
|
267
227
|
};
|
|
268
228
|
}, [fileStateValue === null || fileStateValue === void 0 ? void 0 : fileStateValue.status, metadata.id, metadata.mediaType, metadata.mimeType, metadata.size]);
|
|
269
229
|
var computedActions = useMemo(function () {
|
|
270
|
-
if (
|
|
230
|
+
if (finalStatus === 'failed-processing' || shouldEnableDownloadButton) {
|
|
271
231
|
var downloadAction = {
|
|
272
232
|
label: 'Download',
|
|
273
233
|
icon: /*#__PURE__*/React.createElement(DownloadIcon, {
|
|
@@ -281,7 +241,7 @@ export var FileCard = function FileCard(_ref) {
|
|
|
281
241
|
} else {
|
|
282
242
|
return actions;
|
|
283
243
|
}
|
|
284
|
-
}, [actions, identifier.collectionName, identifier.id, mediaClient.file, metadata.name, shouldEnableDownloadButton,
|
|
244
|
+
}, [actions, identifier.collectionName, identifier.id, mediaClient.file, metadata.name, shouldEnableDownloadButton, finalStatus]);
|
|
285
245
|
|
|
286
246
|
//----------------------------------------------------------------//
|
|
287
247
|
//---------------------- Analytics ------------------------------//
|
|
@@ -296,12 +256,17 @@ export var FileCard = function FileCard(_ref) {
|
|
|
296
256
|
durationSinceCommenced: durationSinceCommenced
|
|
297
257
|
}
|
|
298
258
|
};
|
|
299
|
-
createAnalyticsEvent && fireOperationalEvent(createAnalyticsEvent,
|
|
300
|
-
completeUfoExperience(internalOccurrenceKey,
|
|
259
|
+
createAnalyticsEvent && fireOperationalEvent(createAnalyticsEvent, finalStatus, fileAttributes, performanceAttributes, ssrReliabilityRef.current, finalError, traceContext, fileStateValue === null || fileStateValue === void 0 ? void 0 : fileStateValue.metadataTraceContext);
|
|
260
|
+
completeUfoExperience(internalOccurrenceKey, finalStatus, fileAttributes, fileStateFlagsRef.current, ssrReliabilityRef.current, finalError);
|
|
301
261
|
});
|
|
302
262
|
var fireNonCriticalErrorEventRef = useCurrentValueRef(function (error) {
|
|
303
|
-
createAnalyticsEvent && fireNonCriticalErrorEvent(createAnalyticsEvent,
|
|
263
|
+
createAnalyticsEvent && fireNonCriticalErrorEvent(createAnalyticsEvent, finalStatus, fileAttributes, ssrReliabilityRef.current, error, traceContext, fileStateValue === null || fileStateValue === void 0 ? void 0 : fileStateValue.metadataTraceContext);
|
|
304
264
|
});
|
|
265
|
+
useEffect(function () {
|
|
266
|
+
if (nonCriticalError) {
|
|
267
|
+
fireNonCriticalErrorEventRef.current(nonCriticalError);
|
|
268
|
+
}
|
|
269
|
+
}, [nonCriticalError, fireNonCriticalErrorEventRef]);
|
|
305
270
|
var fireScreenEventRef = useCurrentValueRef(function () {
|
|
306
271
|
createAnalyticsEvent && fireScreenEvent(createAnalyticsEvent, fileAttributes);
|
|
307
272
|
});
|
|
@@ -327,72 +292,10 @@ export var FileCard = function FileCard(_ref) {
|
|
|
327
292
|
//----------------------------------------------------------------//
|
|
328
293
|
|
|
329
294
|
var onImageError = function onImageError(newCardPreview) {
|
|
330
|
-
|
|
331
|
-
var failedSSRObject = _objectSpread({
|
|
332
|
-
status: 'fail'
|
|
333
|
-
}, extractErrorInfo(new ImageLoadError(newCardPreview.source)));
|
|
334
|
-
if (isSSRClientPreview(newCardPreview)) {
|
|
335
|
-
ssrReliabilityRef.current.client = failedSSRObject;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/*
|
|
339
|
-
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.
|
|
340
|
-
*/
|
|
341
|
-
|
|
342
|
-
if (isSSRDataPreview(newCardPreview)) {
|
|
343
|
-
ssrReliabilityRef.current.server = failedSSRObject;
|
|
344
|
-
ssrReliabilityRef.current.client = failedSSRObject;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// If the dataURI has been replaced, we can dismiss this error
|
|
349
|
-
if ((newCardPreview === null || newCardPreview === void 0 ? void 0 : newCardPreview.dataURI) !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
var error = new ImageLoadError(newCardPreview === null || newCardPreview === void 0 ? void 0 : newCardPreview.source);
|
|
353
|
-
var isLocal = newCardPreview && isLocalPreview(newCardPreview);
|
|
354
|
-
var isSSR = newCardPreview && (isSSRClientPreview(newCardPreview) || isSSRDataPreview(newCardPreview));
|
|
355
|
-
if (isLocal || isSSR) {
|
|
356
|
-
if (isLocal) {
|
|
357
|
-
setIsBannedLocalPreview(true);
|
|
358
|
-
fireNonCriticalErrorEventRef.current && fireNonCriticalErrorEventRef.current(error);
|
|
359
|
-
}
|
|
360
|
-
var fileImageMode = imageResizeModeToFileImageMode(resizeMode);
|
|
361
|
-
isFileIdentifier(identifier) && removeCardPreviewFromCache(identifier.id, fileImageMode);
|
|
362
|
-
setCardPreview(undefined);
|
|
363
|
-
} else {
|
|
364
|
-
if (!['complete', 'error', 'failed-processing'].includes(status)) {
|
|
365
|
-
setStatus('error');
|
|
366
|
-
setError(error);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
295
|
+
onImageErrorBase(newCardPreview);
|
|
369
296
|
};
|
|
370
297
|
var onImageLoad = function onImageLoad(newCardPreview) {
|
|
371
|
-
|
|
372
|
-
if (isSSRClientPreview(newCardPreview) && ssrReliabilityRef.current.client.status === 'unknown') {
|
|
373
|
-
ssrReliabilityRef.current.client = {
|
|
374
|
-
status: 'success'
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/*
|
|
379
|
-
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.
|
|
380
|
-
*/
|
|
381
|
-
|
|
382
|
-
if (isSSRDataPreview(newCardPreview) && ssrReliabilityRef.current.server.status === 'unknown') {
|
|
383
|
-
ssrReliabilityRef.current.server = {
|
|
384
|
-
status: 'success'
|
|
385
|
-
};
|
|
386
|
-
ssrReliabilityRef.current.client = {
|
|
387
|
-
status: 'success'
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// If the dataURI has been replaced, we can dismiss this callback
|
|
393
|
-
if ((newCardPreview === null || newCardPreview === void 0 ? void 0 : newCardPreview.dataURI) !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
298
|
+
onImageLoadBase(newCardPreview);
|
|
396
299
|
setPreviewDidRender(true);
|
|
397
300
|
};
|
|
398
301
|
var onCardClick = function onCardClick(event, analyticsEvent) {
|
|
@@ -410,7 +313,7 @@ export var FileCard = function FileCard(_ref) {
|
|
|
410
313
|
return;
|
|
411
314
|
}
|
|
412
315
|
var isVideo = metadata && metadata.mediaType === 'video';
|
|
413
|
-
if (useInlinePlayer && isVideo && !!cardPreview) {
|
|
316
|
+
if (useInlinePlayer && isVideo && !!cardPreview && finalStatus !== 'error') {
|
|
414
317
|
setIsPlayingFile(true);
|
|
415
318
|
setShouldAutoplay(true);
|
|
416
319
|
} else if (shouldOpenMediaViewer) {
|
|
@@ -423,264 +326,6 @@ export var FileCard = function FileCard(_ref) {
|
|
|
423
326
|
}
|
|
424
327
|
};
|
|
425
328
|
|
|
426
|
-
//----------------------------------------------------------------//
|
|
427
|
-
//---------------------- Helper Functions -----------------------//
|
|
428
|
-
//----------------------------------------------------------------//
|
|
429
|
-
|
|
430
|
-
var fetchRemotePreviewRef = useCurrentValueRef(function (identifier) {
|
|
431
|
-
return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, getMediaBlobUrlAttrs(fileStateValue));
|
|
432
|
-
});
|
|
433
|
-
var resolvePreviewRef = useCurrentValueRef( /*#__PURE__*/function () {
|
|
434
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(identifier, fileState) {
|
|
435
|
-
var filePreview, isRemotePreviewReady, mode, cachedPreview, dimensionsAreBigger, localPreview, value, resolvedFilePreview, _value, type, mediaType, orientation, _dataURI, _dataURI2, preview, source, mediaBlobUrlAttrs, dataURI, remotePreview, wrappedError;
|
|
436
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
437
|
-
while (1) switch (_context.prev = _context.next) {
|
|
438
|
-
case 0:
|
|
439
|
-
filePreview = isBannedLocalPreview ? undefined : fileState.status !== 'error' && 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) ? fileState.preview : undefined;
|
|
440
|
-
isRemotePreviewReady = isImageRepresentationReady(fileState);
|
|
441
|
-
_context.prev = 2;
|
|
442
|
-
mode = imageURLParams.mode;
|
|
443
|
-
cachedPreview = cardPreviewCache.get(identifier.id, mode);
|
|
444
|
-
dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, dimensions);
|
|
445
|
-
if (!(cachedPreview && !dimensionsAreBigger)) {
|
|
446
|
-
_context.next = 8;
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
return _context.abrupt("return", cachedPreview);
|
|
450
|
-
case 8:
|
|
451
|
-
_context.prev = 8;
|
|
452
|
-
if (!filePreview) {
|
|
453
|
-
_context.next = 75;
|
|
454
|
-
break;
|
|
455
|
-
}
|
|
456
|
-
_context.prev = 10;
|
|
457
|
-
_context.next = 13;
|
|
458
|
-
return filePreview;
|
|
459
|
-
case 13:
|
|
460
|
-
resolvedFilePreview = _context.sent;
|
|
461
|
-
value = resolvedFilePreview.value;
|
|
462
|
-
_context.next = 20;
|
|
463
|
-
break;
|
|
464
|
-
case 17:
|
|
465
|
-
_context.prev = 17;
|
|
466
|
-
_context.t0 = _context["catch"](10);
|
|
467
|
-
throw new LocalPreviewError('local-preview-rejected', _context.t0 instanceof Error ? _context.t0 : undefined);
|
|
468
|
-
case 20:
|
|
469
|
-
if (!(typeof value === 'string')) {
|
|
470
|
-
_context.next = 24;
|
|
471
|
-
break;
|
|
472
|
-
}
|
|
473
|
-
localPreview = {
|
|
474
|
-
dataURI: value,
|
|
475
|
-
orientation: 1,
|
|
476
|
-
source: 'local'
|
|
477
|
-
};
|
|
478
|
-
_context.next = 57;
|
|
479
|
-
break;
|
|
480
|
-
case 24:
|
|
481
|
-
if (!(value instanceof Blob)) {
|
|
482
|
-
_context.next = 56;
|
|
483
|
-
break;
|
|
484
|
-
}
|
|
485
|
-
_value = value, type = _value.type;
|
|
486
|
-
mediaType = getMediaTypeFromMimeType(type);
|
|
487
|
-
_context.t1 = mediaType;
|
|
488
|
-
_context.next = _context.t1 === 'image' ? 30 : _context.t1 === 'video' ? 42 : 53;
|
|
489
|
-
break;
|
|
490
|
-
case 30:
|
|
491
|
-
_context.prev = 30;
|
|
492
|
-
_context.next = 33;
|
|
493
|
-
return getOrientation(value);
|
|
494
|
-
case 33:
|
|
495
|
-
orientation = _context.sent;
|
|
496
|
-
_dataURI = URL.createObjectURL(value);
|
|
497
|
-
localPreview = {
|
|
498
|
-
dataURI: _dataURI,
|
|
499
|
-
orientation: orientation,
|
|
500
|
-
source: 'local'
|
|
501
|
-
};
|
|
502
|
-
_context.next = 41;
|
|
503
|
-
break;
|
|
504
|
-
case 38:
|
|
505
|
-
_context.prev = 38;
|
|
506
|
-
_context.t2 = _context["catch"](30);
|
|
507
|
-
throw new LocalPreviewError('local-preview-image', _context.t2 instanceof Error ? _context.t2 : undefined);
|
|
508
|
-
case 41:
|
|
509
|
-
return _context.abrupt("break", 54);
|
|
510
|
-
case 42:
|
|
511
|
-
_context.prev = 42;
|
|
512
|
-
_context.next = 45;
|
|
513
|
-
return takeSnapshot(value);
|
|
514
|
-
case 45:
|
|
515
|
-
_dataURI2 = _context.sent;
|
|
516
|
-
localPreview = {
|
|
517
|
-
dataURI: _dataURI2,
|
|
518
|
-
orientation: 1,
|
|
519
|
-
source: 'local'
|
|
520
|
-
};
|
|
521
|
-
_context.next = 52;
|
|
522
|
-
break;
|
|
523
|
-
case 49:
|
|
524
|
-
_context.prev = 49;
|
|
525
|
-
_context.t3 = _context["catch"](42);
|
|
526
|
-
throw new LocalPreviewError('local-preview-video', _context.t3 instanceof Error ? _context.t3 : undefined);
|
|
527
|
-
case 52:
|
|
528
|
-
return _context.abrupt("break", 54);
|
|
529
|
-
case 53:
|
|
530
|
-
throw new LocalPreviewError('local-preview-unsupported');
|
|
531
|
-
case 54:
|
|
532
|
-
_context.next = 57;
|
|
533
|
-
break;
|
|
534
|
-
case 56:
|
|
535
|
-
throw new LocalPreviewError('local-preview-unsupported');
|
|
536
|
-
case 57:
|
|
537
|
-
preview = _objectSpread(_objectSpread({}, localPreview), {}, {
|
|
538
|
-
dimensions: dimensions
|
|
539
|
-
});
|
|
540
|
-
_context.t4 = preview.source;
|
|
541
|
-
_context.next = _context.t4 === 'local' ? 61 : _context.t4 === 'remote' ? 63 : _context.t4 === 'ssr-server' ? 65 : _context.t4 === 'ssr-client' ? 67 : 69;
|
|
542
|
-
break;
|
|
543
|
-
case 61:
|
|
544
|
-
source = 'cache-local';
|
|
545
|
-
return _context.abrupt("break", 70);
|
|
546
|
-
case 63:
|
|
547
|
-
source = 'cache-remote';
|
|
548
|
-
return _context.abrupt("break", 70);
|
|
549
|
-
case 65:
|
|
550
|
-
source = 'cache-ssr-server';
|
|
551
|
-
return _context.abrupt("break", 70);
|
|
552
|
-
case 67:
|
|
553
|
-
source = 'cache-ssr-client';
|
|
554
|
-
return _context.abrupt("break", 70);
|
|
555
|
-
case 69:
|
|
556
|
-
source = preview.source;
|
|
557
|
-
case 70:
|
|
558
|
-
// We want to embed some meta context into dataURI for Copy/Paste to work.
|
|
559
|
-
mediaBlobUrlAttrs = getMediaBlobUrlAttrs(fileStateValue);
|
|
560
|
-
dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI; // We store new cardPreview into cache
|
|
561
|
-
cardPreviewCache.set(identifier.id, mode, _objectSpread(_objectSpread({}, preview), {}, {
|
|
562
|
-
source: source,
|
|
563
|
-
dataURI: dataURI
|
|
564
|
-
}));
|
|
565
|
-
setCardPreview(_objectSpread(_objectSpread({}, preview), {}, {
|
|
566
|
-
dataURI: dataURI
|
|
567
|
-
}));
|
|
568
|
-
return _context.abrupt("return");
|
|
569
|
-
case 75:
|
|
570
|
-
_context.next = 82;
|
|
571
|
-
break;
|
|
572
|
-
case 77:
|
|
573
|
-
_context.prev = 77;
|
|
574
|
-
_context.t5 = _context["catch"](8);
|
|
575
|
-
/**
|
|
576
|
-
* We report the error if:
|
|
577
|
-
* - local preview is supported and fails
|
|
578
|
-
* - local preview is unsupported and remote preview is NOT READY
|
|
579
|
-
* i.e. the function was called for "no reason".
|
|
580
|
-
* We DON'T report the error if:
|
|
581
|
-
* - local preview is unsupported and remote preview IS READY
|
|
582
|
-
* i.e. local preview is available and not supported,
|
|
583
|
-
* but we are after the remote preview instead.
|
|
584
|
-
*/
|
|
585
|
-
if (!isUnsupportedLocalPreviewError(_context.t5) || isUnsupportedLocalPreviewError(_context.t5) && !isRemotePreviewReady) {
|
|
586
|
-
fireNonCriticalErrorEventRef.current && fireNonCriticalErrorEventRef.current(_context.t5);
|
|
587
|
-
}
|
|
588
|
-
/**
|
|
589
|
-
* No matter the reason why the local preview failed, we break the process
|
|
590
|
-
* if there is no remote preview available
|
|
591
|
-
*/
|
|
592
|
-
if (isRemotePreviewReady) {
|
|
593
|
-
_context.next = 82;
|
|
594
|
-
break;
|
|
595
|
-
}
|
|
596
|
-
throw _context.t5;
|
|
597
|
-
case 82:
|
|
598
|
-
if (isRemotePreviewReady) {
|
|
599
|
-
_context.next = 84;
|
|
600
|
-
break;
|
|
601
|
-
}
|
|
602
|
-
throw new MediaCardError('remote-preview-not-ready');
|
|
603
|
-
case 84:
|
|
604
|
-
_context.next = 86;
|
|
605
|
-
return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, getMediaBlobUrlAttrs(fileStateValue), traceContext);
|
|
606
|
-
case 86:
|
|
607
|
-
remotePreview = _context.sent;
|
|
608
|
-
setCardPreview(remotePreview);
|
|
609
|
-
return _context.abrupt("return");
|
|
610
|
-
case 91:
|
|
611
|
-
_context.prev = 91;
|
|
612
|
-
_context.t6 = _context["catch"](2);
|
|
613
|
-
wrappedError = ensureMediaCardError('preview-fetch', _context.t6); // If remote preview fails, we set status 'error'
|
|
614
|
-
// If local preview fails (i.e, no remote preview available),
|
|
615
|
-
// we can stay in the same status until there is a remote preview available
|
|
616
|
-
// If it's any other error we set status 'error'
|
|
617
|
-
if (isLocalPreviewError(wrappedError)) {
|
|
618
|
-
// This error should already been logged inside the getCardPreview. No need to log it here.
|
|
619
|
-
setIsBannedLocalPreview(true);
|
|
620
|
-
} else {
|
|
621
|
-
if (!['complete', 'error', 'failed-processing'].includes(status)) {
|
|
622
|
-
setStatus('error');
|
|
623
|
-
setError(wrappedError);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
case 95:
|
|
627
|
-
case "end":
|
|
628
|
-
return _context.stop();
|
|
629
|
-
}
|
|
630
|
-
}, _callee, null, [[2, 91], [8, 77], [10, 17], [30, 38], [42, 49]]);
|
|
631
|
-
}));
|
|
632
|
-
return function (_x, _x2) {
|
|
633
|
-
return _ref2.apply(this, arguments);
|
|
634
|
-
};
|
|
635
|
-
}());
|
|
636
|
-
|
|
637
|
-
//----------------------------------------------------------------//
|
|
638
|
-
//------------ resolveUpfrontPreview useEffect -------------------//
|
|
639
|
-
//----------------------------------------------------------------//
|
|
640
|
-
var prevCardPreview = usePrevious(cardPreview);
|
|
641
|
-
var dimensionsRef = useCurrentValueRef(dimensions);
|
|
642
|
-
useEffect(function () {
|
|
643
|
-
var resolveUpfrontPreview = /*#__PURE__*/function () {
|
|
644
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(identifier) {
|
|
645
|
-
var requestedDimensions, newCardPreview, areValidRequestedDimensions;
|
|
646
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
647
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
648
|
-
case 0:
|
|
649
|
-
// We block any possible future call to this method regardless of the outcome (success or fail)
|
|
650
|
-
// If it fails, the normal preview fetch should occur after the file state is fetched anyways
|
|
651
|
-
wasResolvedUpfrontPreviewRef.current = true;
|
|
652
|
-
_context2.prev = 1;
|
|
653
|
-
requestedDimensions = _objectSpread({}, dimensions);
|
|
654
|
-
_context2.next = 5;
|
|
655
|
-
return fetchRemotePreviewRef.current(identifier);
|
|
656
|
-
case 5:
|
|
657
|
-
newCardPreview = _context2.sent;
|
|
658
|
-
areValidRequestedDimensions = !isBigger(requestedDimensions, dimensionsRef.current); // If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
|
|
659
|
-
// the fetched preview is no longer valid, and thus, we dismiss it
|
|
660
|
-
if (areValidRequestedDimensions) {
|
|
661
|
-
setCardPreview(newCardPreview);
|
|
662
|
-
}
|
|
663
|
-
_context2.next = 12;
|
|
664
|
-
break;
|
|
665
|
-
case 10:
|
|
666
|
-
_context2.prev = 10;
|
|
667
|
-
_context2.t0 = _context2["catch"](1);
|
|
668
|
-
case 12:
|
|
669
|
-
case "end":
|
|
670
|
-
return _context2.stop();
|
|
671
|
-
}
|
|
672
|
-
}, _callee2, null, [[1, 10]]);
|
|
673
|
-
}));
|
|
674
|
-
return function resolveUpfrontPreview(_x3) {
|
|
675
|
-
return _ref3.apply(this, arguments);
|
|
676
|
-
};
|
|
677
|
-
}();
|
|
678
|
-
var hadSSRCardPreview = ssr === 'client' && !!prevCardPreview && isSSRClientPreview(prevCardPreview);
|
|
679
|
-
if ((isCardVisible || hadSSRCardPreview) && !cardPreview && !wasResolvedUpfrontPreviewRef.current) {
|
|
680
|
-
resolveUpfrontPreview(identifier);
|
|
681
|
-
}
|
|
682
|
-
}, [cardPreview, dimensions, dimensionsRef, fetchRemotePreviewRef, identifier, isCardVisible, prevCardPreview, ssr]);
|
|
683
|
-
|
|
684
329
|
//----------------------------------------------------------------//
|
|
685
330
|
//------------------------ handle fireCopiedEvent --------------//
|
|
686
331
|
//----------------------------------------------------------------//
|
|
@@ -718,64 +363,19 @@ export var FileCard = function FileCard(_ref) {
|
|
|
718
363
|
//---------------- fetch and resolve card preview ----------------//
|
|
719
364
|
//----------------------------------------------------------------//
|
|
720
365
|
|
|
721
|
-
var
|
|
366
|
+
var prevStatus = usePrevious(finalStatus);
|
|
722
367
|
var prevIsCardVisible = usePrevious(isCardVisible);
|
|
723
|
-
var prevStatus = usePrevious(status);
|
|
724
368
|
useEffect(function () {
|
|
725
|
-
if (prevStatus !== undefined &&
|
|
369
|
+
if (prevStatus !== undefined && finalStatus !== prevStatus) {
|
|
726
370
|
fireOperationalEventRef.current();
|
|
727
371
|
}
|
|
728
|
-
}, [fireOperationalEventRef, prevStatus,
|
|
372
|
+
}, [fireOperationalEventRef, prevStatus, finalStatus]);
|
|
729
373
|
useEffect(function () {
|
|
730
|
-
var _ssrDataRef$current3;
|
|
731
|
-
/**
|
|
732
|
-
* Variable turnedVisible should only be true when media card
|
|
733
|
-
* was invisible in the previous state and is visible in the current one
|
|
734
|
-
*
|
|
735
|
-
* prevIsCardVisible | isCardVisible | turnedVisible
|
|
736
|
-
* ----------------------------------------------------
|
|
737
|
-
* false | false | false
|
|
738
|
-
* false | true | true
|
|
739
|
-
* true | true | false
|
|
740
|
-
* true | false | false (unreachable case)
|
|
741
|
-
* ----------------------------------------------------
|
|
742
|
-
*/
|
|
743
|
-
|
|
744
374
|
var turnedVisible = !prevIsCardVisible && isCardVisible;
|
|
745
375
|
if (turnedVisible) {
|
|
746
376
|
fireCommencedEventRef.current();
|
|
747
377
|
}
|
|
748
|
-
|
|
749
|
-
// If dimensions from Server have changed and are bigger,
|
|
750
|
-
// we need to refetch
|
|
751
|
-
// refetchSRRPreview
|
|
752
|
-
fetchRemotePreviewRef.current(identifier).then(setCardPreview).catch(function (e) {
|
|
753
|
-
var wrappedError = ensureMediaCardError('remote-preview-fetch-ssr', e, true);
|
|
754
|
-
fireNonCriticalErrorEventRef.current(wrappedError);
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
if (fileStateValue && shouldResolvePreview({
|
|
758
|
-
status: status,
|
|
759
|
-
fileState: fileStateValue,
|
|
760
|
-
prevDimensions: prevDimensions,
|
|
761
|
-
dimensions: dimensions,
|
|
762
|
-
hasCardPreview: !!cardPreview,
|
|
763
|
-
isBannedLocalPreview: isBannedLocalPreview,
|
|
764
|
-
wasResolvedUpfrontPreview: wasResolvedUpfrontPreviewRef.current
|
|
765
|
-
})) {
|
|
766
|
-
resolvePreviewRef.current(identifier, fileStateValue);
|
|
767
|
-
}
|
|
768
|
-
if (turnedVisible && ssr && !!cardPreview && isSSRClientPreview(cardPreview)) {
|
|
769
|
-
// Since the SSR preview brings the token in the query params,
|
|
770
|
-
// We need to fetch the remote preview to be able to cache it,
|
|
771
|
-
fetchRemotePreviewRef.current(identifier).catch(function () {
|
|
772
|
-
// No need to log this error.
|
|
773
|
-
// If preview fails, it will be refetched later
|
|
774
|
-
//TODO: test this catch
|
|
775
|
-
// https://product-fabric.atlassian.net/browse/MEX-1071
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
}, [cardPreview, dimensions, fetchRemotePreviewRef, fileStateValue, fireCommencedEventRef, fireNonCriticalErrorEventRef, identifier, isBannedLocalPreview, isCardVisible, prevDimensions, prevIsCardVisible, resolvePreviewRef, ssr, status]);
|
|
378
|
+
}, [fireCommencedEventRef, isCardVisible, prevIsCardVisible]);
|
|
779
379
|
|
|
780
380
|
//----------------------------------------------------------------//
|
|
781
381
|
//----------------- set complete status --------------------------//
|
|
@@ -784,12 +384,12 @@ export var FileCard = function FileCard(_ref) {
|
|
|
784
384
|
useEffect(function () {
|
|
785
385
|
if (previewDidRender &&
|
|
786
386
|
// We should't complete if status is uploading
|
|
787
|
-
['loading-preview', 'processing'].includes(
|
|
387
|
+
['loading-preview', 'processing'].includes(finalStatus)) {
|
|
788
388
|
setStatus('complete');
|
|
789
389
|
// TODO MEX-788: add test for "do not remove the card preview when unsubscribing".
|
|
790
390
|
setIsBannedLocalPreview(false);
|
|
791
391
|
}
|
|
792
|
-
}, [previewDidRender,
|
|
392
|
+
}, [previewDidRender, finalStatus]);
|
|
793
393
|
|
|
794
394
|
//----------------------------------------------------------------//
|
|
795
395
|
//----------------- set isPlayingFile state ----------------------//
|
|
@@ -806,22 +406,22 @@ export var FileCard = function FileCard(_ref) {
|
|
|
806
406
|
* in order to avoid race conditions of the ViewportDector being unmounted before
|
|
807
407
|
* it is able to set isCardVisible to true.
|
|
808
408
|
*/
|
|
809
|
-
isCardVisible && isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && isVideoPlayable) {
|
|
409
|
+
isCardVisible && isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && isVideoPlayable && finalStatus !== 'error') {
|
|
810
410
|
setIsPlayingFile(true);
|
|
811
411
|
}
|
|
812
|
-
}, [isCardVisible, disableOverlay, fileAttributes.fileMediatype, fileStateValue, identifier, isBannedLocalPreview, isPlayingFile, useInlinePlayer]);
|
|
412
|
+
}, [isCardVisible, disableOverlay, fileAttributes.fileMediatype, fileStateValue, identifier, isBannedLocalPreview, isPlayingFile, finalStatus, useInlinePlayer]);
|
|
813
413
|
|
|
814
414
|
//----------------------------------------------------------------//
|
|
815
415
|
//----------------- fireScreenEvent ------------------------------//
|
|
816
416
|
//----------------------------------------------------------------//
|
|
817
417
|
|
|
818
418
|
useEffect(function () {
|
|
819
|
-
if (prevStatus !== undefined &&
|
|
820
|
-
if (
|
|
419
|
+
if (prevStatus !== undefined && finalStatus !== prevStatus) {
|
|
420
|
+
if (finalStatus === 'complete' || fileAttributes.fileMediatype === 'video' && !!cardPreview && finalStatus === 'processing') {
|
|
821
421
|
fireScreenEventRef.current();
|
|
822
422
|
}
|
|
823
423
|
}
|
|
824
|
-
}, [
|
|
424
|
+
}, [finalStatus, prevStatus, fileAttributes, cardPreview, fireScreenEventRef]);
|
|
825
425
|
|
|
826
426
|
//----------------------------------------------------------------//
|
|
827
427
|
//----------------- abort UFO experience -------------------------//
|
|
@@ -841,7 +441,7 @@ export var FileCard = function FileCard(_ref) {
|
|
|
841
441
|
var updateFileStateRef = useCurrentValueRef(function () {
|
|
842
442
|
if (fileState) {
|
|
843
443
|
// do not update the card status if the status is final
|
|
844
|
-
if (['complete', 'error', 'failed-processing'].includes(
|
|
444
|
+
if (['complete', 'error', 'failed-processing'].includes(finalStatus)) {
|
|
845
445
|
return;
|
|
846
446
|
}
|
|
847
447
|
if (fileState.status !== 'error') {
|
|
@@ -849,7 +449,9 @@ export var FileCard = function FileCard(_ref) {
|
|
|
849
449
|
var isPreviewable = !!mediaType && ['audio', 'video', 'image', 'doc'].indexOf(mediaType) > -1;
|
|
850
450
|
var isPreviewableFileState = !!fileState.preview;
|
|
851
451
|
var isSupportedLocalPreview = mediaType === 'image' || mediaType === 'video';
|
|
852
|
-
var hasLocalPreview = !isBannedLocalPreview && isPreviewableFileState &&
|
|
452
|
+
var hasLocalPreview = !isBannedLocalPreview && isPreviewableFileState &&
|
|
453
|
+
// CXP-2723 TODO: isPreviewableFileState is most likely redundant
|
|
454
|
+
isSupportedLocalPreview && !!fileState.mimeType && isMimeTypeSupportedByBrowser(fileState.mimeType);
|
|
853
455
|
var hasRemotePreview = isImageRepresentationReady(fileState);
|
|
854
456
|
var hasPreview = hasLocalPreview || hasRemotePreview;
|
|
855
457
|
var newStatus;
|
|
@@ -874,7 +476,7 @@ export var FileCard = function FileCard(_ref) {
|
|
|
874
476
|
uploadProgressRef.current = newProgress;
|
|
875
477
|
} else {
|
|
876
478
|
var e = new MediaFileStateError(fileState.id, fileState.reason, fileState.message, fileState.details);
|
|
877
|
-
var errorReason =
|
|
479
|
+
var errorReason = finalStatus === 'uploading' ? 'upload' : 'metadata-fetch';
|
|
878
480
|
setError(new MediaCardError(errorReason, e));
|
|
879
481
|
setStatus('error');
|
|
880
482
|
}
|
|
@@ -895,15 +497,18 @@ export var FileCard = function FileCard(_ref) {
|
|
|
895
497
|
var mediaItemType = identifier.mediaItemType;
|
|
896
498
|
var isLazyWithOverride = izLazyOverride === undefined ? isLazy : izLazyOverride;
|
|
897
499
|
|
|
898
|
-
//
|
|
899
|
-
//
|
|
900
|
-
|
|
500
|
+
// We should natively lazy load an SSR preview when card is not visible,
|
|
501
|
+
// otherwise we'll fire the metadata fetch from outside the viewport
|
|
502
|
+
// Side note: We should not lazy load if the cardPreview is available from local cache,
|
|
503
|
+
// in order to avoid flickers during re-mount of the component
|
|
504
|
+
// CXP-2723 TODO: Create test cases for the above scenarios
|
|
505
|
+
var nativeLazyLoad = isLazyWithOverride && !isCardVisible && cardPreview && isSSRPreview(cardPreview);
|
|
901
506
|
// Force Media Image to always display img for SSR
|
|
902
507
|
var forceSyncDisplay = !!ssr;
|
|
903
|
-
var mediaCardCursor = getMediaCardCursor(!!useInlinePlayer, !!shouldOpenMediaViewer,
|
|
508
|
+
var mediaCardCursor = getMediaCardCursor(!!useInlinePlayer, !!shouldOpenMediaViewer, finalStatus === 'error' || finalStatus === 'failed-processing', !!cardPreview, metadata.mediaType);
|
|
904
509
|
var card = /*#__PURE__*/React.createElement(CardViewV2, {
|
|
905
|
-
status: cardStatusOverride ||
|
|
906
|
-
error:
|
|
510
|
+
status: cardStatusOverride || finalStatus,
|
|
511
|
+
error: finalError,
|
|
907
512
|
mediaItemType: mediaItemType,
|
|
908
513
|
metadata: metadata,
|
|
909
514
|
cardPreview: cardPreview,
|
|
@@ -966,7 +571,9 @@ export var FileCard = function FileCard(_ref) {
|
|
|
966
571
|
identifier: identifier,
|
|
967
572
|
autoplay: !!shouldAutoplay,
|
|
968
573
|
onFullscreenChange: onFullscreenChange,
|
|
969
|
-
onError: function onError() {
|
|
574
|
+
onError: function onError(e) {
|
|
575
|
+
setError(new MediaCardError('error-file-state', e));
|
|
576
|
+
setStatus('error');
|
|
970
577
|
setIsPlayingFile(false);
|
|
971
578
|
},
|
|
972
579
|
onClick: onCardClick,
|
|
@@ -984,13 +591,5 @@ export var FileCard = function FileCard(_ref) {
|
|
|
984
591
|
},
|
|
985
592
|
contextId: contextId,
|
|
986
593
|
featureFlags: featureFlags
|
|
987
|
-
}), document.body) : null, ssr === 'server' && /*#__PURE__*/React.createElement(StoreSSRDataScript,
|
|
988
|
-
identifier: identifier,
|
|
989
|
-
dataURI: cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI,
|
|
990
|
-
dimensions: getRequestedDimensions({
|
|
991
|
-
dimensions: dimensions,
|
|
992
|
-
element: cardElement
|
|
993
|
-
}),
|
|
994
|
-
error: ((_ssrReliabilityRef$cu = ssrReliabilityRef.current.server) === null || _ssrReliabilityRef$cu === void 0 ? void 0 : _ssrReliabilityRef$cu.status) === 'fail' ? ssrReliabilityRef.current.server : undefined
|
|
995
|
-
}));
|
|
594
|
+
}), document.body) : null, ssr === 'server' && /*#__PURE__*/React.createElement(StoreSSRDataScript, null));
|
|
996
595
|
};
|