@atlaskit/media-card 77.4.5 → 77.4.7

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 (39) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/card/card.js +4 -7
  3. package/dist/cjs/card/getCardPreview/filePreviewStatus.js +2 -0
  4. package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
  5. package/dist/cjs/card/v2/cardV2.js +1 -1
  6. package/dist/cjs/card/v2/fileCard.js +117 -520
  7. package/dist/cjs/card/v2/useFilePreview.js +585 -0
  8. package/dist/cjs/inline/loader.js +1 -1
  9. package/dist/cjs/utils/globalScope/globalScope.js +4 -10
  10. package/dist/cjs/utils/globalScope/index.js +2 -2
  11. package/dist/cjs/utils/ufoExperiences.js +1 -1
  12. package/dist/es2019/card/card.js +5 -8
  13. package/dist/es2019/card/getCardPreview/filePreviewStatus.js +2 -0
  14. package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
  15. package/dist/es2019/card/v2/cardV2.js +1 -1
  16. package/dist/es2019/card/v2/fileCard.js +102 -435
  17. package/dist/es2019/card/v2/useFilePreview.js +493 -0
  18. package/dist/es2019/inline/loader.js +1 -1
  19. package/dist/es2019/utils/globalScope/globalScope.js +1 -7
  20. package/dist/es2019/utils/globalScope/index.js +1 -1
  21. package/dist/es2019/utils/ufoExperiences.js +1 -1
  22. package/dist/esm/card/card.js +5 -8
  23. package/dist/esm/card/getCardPreview/filePreviewStatus.js +2 -0
  24. package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
  25. package/dist/esm/card/v2/cardV2.js +1 -1
  26. package/dist/esm/card/v2/fileCard.js +122 -525
  27. package/dist/esm/card/v2/useFilePreview.js +578 -0
  28. package/dist/esm/inline/loader.js +1 -1
  29. package/dist/esm/utils/globalScope/globalScope.js +3 -8
  30. package/dist/esm/utils/globalScope/index.js +1 -1
  31. package/dist/esm/utils/ufoExperiences.js +1 -1
  32. package/dist/types/card/v2/useFilePreview.d.ts +37 -0
  33. package/dist/types/utils/globalScope/globalScope.d.ts +1 -7
  34. package/dist/types/utils/globalScope/index.d.ts +1 -1
  35. package/dist/types-ts4.5/card/v2/useFilePreview.d.ts +37 -0
  36. package/dist/types-ts4.5/utils/globalScope/globalScope.d.ts +1 -7
  37. package/dist/types-ts4.5/utils/globalScope/index.d.ts +1 -1
  38. package/package.json +5 -4
  39. package/tmp/api-report-tmp.d.ts +0 -345
@@ -0,0 +1,493 @@
1
+ import { addFileAttrsToUrl, imageResizeModeToFileImageMode, isImageRepresentationReady } from '@atlaskit/media-client';
2
+ import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
3
+ import { getMediaTypeFromMimeType, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
4
+ import { getOrientation } from '@atlaskit/media-ui';
5
+ import { useEffect, useMemo, useRef, useState } from 'react';
6
+ import { ensureMediaCardError, ImageLoadError, isLocalPreviewError, isUnsupportedLocalPreviewError, LocalPreviewError, MediaCardError } from '../../errors';
7
+ import { extractErrorInfo } from '../../utils/analytics';
8
+ import { isBigger } from '../../utils/dimensionComparer';
9
+ import { generateScriptProps, getSSRData } from '../../utils/globalScope';
10
+ import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
11
+ import { usePrevious } from '../../utils/usePrevious';
12
+ import { takeSnapshot } from '../../utils/videoSnapshot';
13
+ import { fetchAndCacheRemotePreview, getCardPreviewFromCache, getSSRCardPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, removeCardPreviewFromCache, shouldResolvePreview } from '../getCardPreview';
14
+ import cardPreviewCache from '../getCardPreview/cache';
15
+ export const useFilePreview = ({
16
+ resizeMode = 'crop',
17
+ identifier,
18
+ ssr,
19
+ mediaClient,
20
+ dimensions,
21
+ requestedDimensions,
22
+ traceContext,
23
+ previewDidRender,
24
+ skipRemote,
25
+ mediaBlobUrlAttrs
26
+ }) => {
27
+ const [error, setError] = useState();
28
+ const [nonCriticalError, setNonCriticalError] = useState();
29
+ //----------------------------------------------------------------//
30
+ //---------------- State Initializer Functions -------------------//
31
+ //----------------------------------------------------------------//
32
+
33
+ const ssrDataRef = useRef();
34
+ const ssrReliabilityRef = useRef({
35
+ server: {
36
+ status: 'unknown'
37
+ },
38
+ client: {
39
+ status: 'unknown'
40
+ }
41
+ });
42
+ const imageURLParams = useMemo(() => ({
43
+ collection: identifier.collectionName,
44
+ mode: resizeMode === 'stretchy-fit' ? 'full-fit' : resizeMode,
45
+ ...requestedDimensions,
46
+ allowAnimated: true
47
+ }), [requestedDimensions, identifier.collectionName, resizeMode]);
48
+ const getSSRPreview = (ssr, identifier, mediaClient) => {
49
+ var _ssrDataRef$current, _ssrDataRef$current2;
50
+ ssrDataRef.current = getSSRData(identifier);
51
+ if ((_ssrDataRef$current = ssrDataRef.current) !== null && _ssrDataRef$current !== void 0 && _ssrDataRef$current.error) {
52
+ ssrReliabilityRef.current.server = {
53
+ status: 'fail',
54
+ ...ssrDataRef.current.error
55
+ };
56
+ }
57
+ if (!((_ssrDataRef$current2 = ssrDataRef.current) !== null && _ssrDataRef$current2 !== void 0 && _ssrDataRef$current2.dataURI)) {
58
+ try {
59
+ return getSSRCardPreview(ssr, mediaClient, identifier.id, imageURLParams, mediaBlobUrlAttrs);
60
+ } catch (e) {
61
+ ssrReliabilityRef.current[ssr] = {
62
+ status: 'fail',
63
+ ...extractErrorInfo(e)
64
+ };
65
+ }
66
+ } else {
67
+ return {
68
+ dataURI: ssrDataRef.current.dataURI,
69
+ source: 'ssr-data'
70
+ };
71
+ }
72
+ };
73
+ const cardPreviewInitializer = () => {
74
+ let cardPreview;
75
+ const {
76
+ id
77
+ } = identifier;
78
+ const fileImageMode = imageResizeModeToFileImageMode(resizeMode);
79
+ cardPreview = getCardPreviewFromCache(id, fileImageMode);
80
+ if (!cardPreview && ssr) {
81
+ cardPreview = getSSRPreview(ssr, identifier, mediaClient);
82
+ }
83
+ return cardPreview;
84
+ };
85
+ const [cardPreview, setCardPreview] = useState(cardPreviewInitializer);
86
+ const {
87
+ fileState
88
+ } = useFileState(identifier.id, {
89
+ skipRemote,
90
+ collectionName: identifier.collectionName,
91
+ occurrenceKey: identifier.occurrenceKey
92
+ });
93
+
94
+ //----------------------------------------------------------------//
95
+ //------------ State, Refs & Initial Values ----------------------//
96
+ //----------------------------------------------------------------//
97
+
98
+ const [status, setStatus] = useState('loading');
99
+ useEffect(() => {
100
+ setStatus('loading');
101
+ }, [identifier]);
102
+ const [isBannedLocalPreview, setIsBannedLocalPreview] = useState(false);
103
+ const wasResolvedUpfrontPreviewRef = useRef(false);
104
+
105
+ //----------------------------------------------------------------//
106
+ //---------------------- Helper Functions -----------------------//
107
+ //----------------------------------------------------------------//
108
+
109
+ const fetchRemotePreviewRef = useCurrentValueRef(identifier => {
110
+ return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs);
111
+ });
112
+ const resolvePreviewRef = useCurrentValueRef(async (identifier, fileState) => {
113
+ const filePreview = isBannedLocalPreview ? undefined : fileState.status !== 'error' && 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) ? fileState.preview : undefined;
114
+ const isRemotePreviewReady = isImageRepresentationReady(fileState);
115
+ try {
116
+ const mode = imageURLParams.mode;
117
+ const cachedPreview = cardPreviewCache.get(identifier.id, mode);
118
+ const dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, dimensions);
119
+ if (cachedPreview && !dimensionsAreBigger) {
120
+ return cachedPreview;
121
+ }
122
+ let localPreview;
123
+ try {
124
+ if (filePreview) {
125
+ let value;
126
+ try {
127
+ const resolvedFilePreview = await filePreview;
128
+ value = resolvedFilePreview.value;
129
+ } catch (e) {
130
+ throw new LocalPreviewError('local-preview-rejected', e instanceof Error ? e : undefined);
131
+ }
132
+ if (typeof value === 'string') {
133
+ localPreview = {
134
+ dataURI: value,
135
+ orientation: 1,
136
+ source: 'local'
137
+ };
138
+ } else if (value instanceof Blob) {
139
+ const {
140
+ type
141
+ } = value;
142
+ const mediaType = getMediaTypeFromMimeType(type);
143
+ switch (mediaType) {
144
+ case 'image':
145
+ try {
146
+ const orientation = await getOrientation(value);
147
+ const dataURI = URL.createObjectURL(value);
148
+ localPreview = {
149
+ dataURI,
150
+ orientation,
151
+ source: 'local'
152
+ };
153
+ } catch (e) {
154
+ throw new LocalPreviewError('local-preview-image', e instanceof Error ? e : undefined);
155
+ }
156
+ break;
157
+ case 'video':
158
+ try {
159
+ const dataURI = await takeSnapshot(value);
160
+ localPreview = {
161
+ dataURI,
162
+ orientation: 1,
163
+ source: 'local'
164
+ };
165
+ } catch (e) {
166
+ throw new LocalPreviewError('local-preview-video', e instanceof Error ? e : undefined);
167
+ }
168
+ break;
169
+ default:
170
+ throw new LocalPreviewError('local-preview-unsupported');
171
+ }
172
+ } else {
173
+ throw new LocalPreviewError('local-preview-unsupported');
174
+ }
175
+ const preview = {
176
+ ...localPreview,
177
+ dimensions
178
+ };
179
+ let source;
180
+ switch (preview.source) {
181
+ case 'local':
182
+ source = 'cache-local';
183
+ break;
184
+ case 'remote':
185
+ source = 'cache-remote';
186
+ break;
187
+ case 'ssr-server':
188
+ source = 'cache-ssr-server';
189
+ break;
190
+ case 'ssr-client':
191
+ source = 'cache-ssr-client';
192
+ break;
193
+ default:
194
+ source = preview.source;
195
+ }
196
+ // We want to embed some meta context into dataURI for Copy/Paste to work.
197
+ const dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI;
198
+ // We store new cardPreview into cache
199
+ cardPreviewCache.set(identifier.id, mode, {
200
+ ...preview,
201
+ source,
202
+ dataURI
203
+ });
204
+ setCardPreview({
205
+ ...preview,
206
+ dataURI
207
+ });
208
+ return;
209
+ }
210
+ } catch (e) {
211
+ /**
212
+ * We report the error if:
213
+ * - local preview is supported and fails
214
+ * - local preview is unsupported and remote preview is NOT READY
215
+ * i.e. the function was called for "no reason".
216
+ * We DON'T report the error if:
217
+ * - local preview is unsupported and remote preview IS READY
218
+ * i.e. local preview is available and not supported,
219
+ * but we are after the remote preview instead.
220
+ */
221
+ if (!isUnsupportedLocalPreviewError(e) || isUnsupportedLocalPreviewError(e) && !isRemotePreviewReady) {
222
+ // CXP-2723 TODO: We might have to wrap this error in MediaCardError
223
+ setNonCriticalError(e);
224
+ }
225
+ /**
226
+ * No matter the reason why the local preview failed, we break the process
227
+ * if there is no remote preview available
228
+ */
229
+ if (!isRemotePreviewReady) {
230
+ throw e;
231
+ }
232
+ }
233
+ if (!isRemotePreviewReady) {
234
+ /**
235
+ * We throw this in case this function has been called
236
+ * without checking isRemotePreviewReady first.
237
+ * If remote preview is not ready, the call to getCardPreviewFromBackend
238
+ * will generate a console error due to a 404 code
239
+ */
240
+ throw new MediaCardError('remote-preview-not-ready');
241
+ }
242
+ const remotePreview = await fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
243
+ setCardPreview(remotePreview);
244
+ return;
245
+ } catch (e) {
246
+ const wrappedError = ensureMediaCardError('preview-fetch', e);
247
+ // If remote preview fails, we set status 'error'
248
+ // If local preview fails (i.e, no remote preview available),
249
+ // we can stay in the same status until there is a remote preview available
250
+ // If it's any other error we set status 'error'
251
+ if (isLocalPreviewError(wrappedError)) {
252
+ // This error should already been logged inside the getCardPreview. No need to log it here.
253
+ setIsBannedLocalPreview(true);
254
+ } else {
255
+ if (!['complete', 'error', 'failed-processing'].includes(status)) {
256
+ setStatus('error');
257
+ setError(wrappedError);
258
+ }
259
+ }
260
+ }
261
+ });
262
+
263
+ //----------------------------------------------------------------//
264
+ //------------ resolveUpfrontPreview useEffect -------------------//
265
+ //----------------------------------------------------------------//
266
+ const prevCardPreview = usePrevious(cardPreview);
267
+ const dimensionsRef = useCurrentValueRef(dimensions);
268
+ useEffect(() => {
269
+ const resolveUpfrontPreview = async identifier => {
270
+ // We block any possible future call to this method regardless of the outcome (success or fail)
271
+ // If it fails, the normal preview fetch should occur after the file state is fetched anyways
272
+ wasResolvedUpfrontPreviewRef.current = true;
273
+ try {
274
+ const fetchedDimensions = {
275
+ ...dimensions
276
+ };
277
+ const newCardPreview = await fetchRemotePreviewRef.current(identifier);
278
+ const areValidFetchedDimensions = !isBigger(fetchedDimensions, dimensionsRef.current);
279
+
280
+ // If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
281
+ // the fetched preview is no longer valid, and thus, we dismiss it
282
+ if (areValidFetchedDimensions) {
283
+ setCardPreview(newCardPreview);
284
+ }
285
+ } catch (e) {
286
+ // NO need to log error. If this call fails, a refetch will happen after
287
+ }
288
+ };
289
+ const hadSSRCardPreview = ssr === 'client' && !!prevCardPreview && isSSRClientPreview(prevCardPreview);
290
+
291
+ // CXP-2723 TODO: `hadSSRCardPreview` is most likely redundant
292
+ if (!wasResolvedUpfrontPreviewRef.current && (!skipRemote || hadSSRCardPreview) && !cardPreview) {
293
+ resolveUpfrontPreview(identifier);
294
+ }
295
+ }, [cardPreview, dimensions, dimensionsRef, fetchRemotePreviewRef, identifier, skipRemote, prevCardPreview, ssr]);
296
+
297
+ //----------------------------------------------------------------//
298
+ //---------------- fetch and resolve card preview ----------------//
299
+ //----------------------------------------------------------------//
300
+
301
+ const prevDimensions = usePrevious(dimensions);
302
+ useEffect(() => {
303
+ var _ssrDataRef$current3;
304
+ if (cardPreview && !skipRemote && isSSRDataPreview(cardPreview) && isBigger((_ssrDataRef$current3 = ssrDataRef.current) === null || _ssrDataRef$current3 === void 0 ? void 0 : _ssrDataRef$current3.dimensions, dimensions)) {
305
+ // refetchSRRPreview: If dimensions from Server have changed and are bigger,
306
+ // we need to refetch
307
+ fetchRemotePreviewRef.current(identifier).then(setCardPreview).catch(e => {
308
+ const wrappedError = ensureMediaCardError('remote-preview-fetch-ssr', e, true);
309
+ setNonCriticalError(wrappedError);
310
+ });
311
+ }
312
+ // CXP-2723 TODO: The above and below preview fetch logic seem very similar and could be revisted
313
+ // Both compare dimensions, but the above is only for SSR in order to refetchSRRPreview and
314
+ // will swallow any errors. Below logic only applies when there is no card preview or the dimensions
315
+ // are bigger.
316
+ if (fileState && shouldResolvePreview({
317
+ status,
318
+ fileState: fileState,
319
+ prevDimensions,
320
+ dimensions,
321
+ hasCardPreview: !!cardPreview,
322
+ isBannedLocalPreview,
323
+ wasResolvedUpfrontPreview: wasResolvedUpfrontPreviewRef.current
324
+ })) {
325
+ resolvePreviewRef.current(identifier, fileState);
326
+ }
327
+ if (!skipRemote && ssr && !!cardPreview && isSSRClientPreview(cardPreview)) {
328
+ // Since the SSR preview brings the token in the query params,
329
+ // We need to fetch the remote preview to be able to cache it,
330
+ fetchRemotePreviewRef.current(identifier).catch(() => {
331
+ // No need to log this error.
332
+ // If preview fails, it will be refetched later
333
+ //TODO: test this catch
334
+ // https://product-fabric.atlassian.net/browse/MEX-1071
335
+ });
336
+ }
337
+ }, [cardPreview, dimensions, fetchRemotePreviewRef, fileState, identifier, isBannedLocalPreview, prevDimensions, resolvePreviewRef, skipRemote, ssr, status]);
338
+
339
+ //----------------------------------------------------------------//
340
+ //----------------- set complete status --------------------------//
341
+ //----------------------------------------------------------------//
342
+
343
+ useEffect(() => {
344
+ if (previewDidRender &&
345
+ // We should't complete if status is uploading
346
+ ['loading-preview', 'processing'].includes(status)) {
347
+ setStatus('complete');
348
+ // TODO MEX-788: add test for "do not remove the card preview when unsubscribing".
349
+ setIsBannedLocalPreview(false); // CXP-2723 TODO: we might be able to remove this??
350
+ }
351
+ }, [previewDidRender, status]);
352
+
353
+ // CXP-2723 TODO: Create test cases for banning local preview after status is complete
354
+
355
+ //----------------------------------------------------------------//
356
+ //------------------ Subscribe to file state ---------------------//
357
+ //----------------------------------------------------------------//
358
+
359
+ const updateFileStateRef = useCurrentValueRef(() => {
360
+ if (fileState) {
361
+ // do not update the card status if the status is final
362
+ if (['complete', 'error', 'failed-processing'].includes(status)) {
363
+ return;
364
+ }
365
+ if (fileState.status !== 'error') {
366
+ const mediaType = 'mediaType' in fileState ? fileState.mediaType : undefined;
367
+ const isPreviewable = !!mediaType && ['audio', 'video', 'image', 'doc'].indexOf(mediaType) > -1;
368
+ const isPreviewableFileState = !!fileState.preview;
369
+ const isSupportedLocalPreview = mediaType === 'image' || mediaType === 'video';
370
+ const hasLocalPreview = !isBannedLocalPreview && isPreviewableFileState && isSupportedLocalPreview && !!fileState.mimeType && isMimeTypeSupportedByBrowser(fileState.mimeType);
371
+ const hasRemotePreview = isImageRepresentationReady(fileState);
372
+ const hasPreview = hasLocalPreview || hasRemotePreview;
373
+ let newStatus;
374
+ switch (fileState.status) {
375
+ case 'uploading':
376
+ case 'failed-processing':
377
+ case 'processing':
378
+ newStatus = fileState.status;
379
+ break;
380
+ case 'processed':
381
+ if (!isPreviewable || !hasPreview) {
382
+ newStatus = 'complete';
383
+ break;
384
+ }
385
+ newStatus = 'loading-preview';
386
+ break;
387
+ default:
388
+ newStatus = 'loading';
389
+ }
390
+ setStatus(newStatus);
391
+ } else {
392
+ const e = new MediaFileStateError(fileState.id, fileState.reason, fileState.message, fileState.details);
393
+ const errorReason = status === 'uploading' ? 'upload' : 'metadata-fetch';
394
+ setError(new MediaCardError(errorReason, e));
395
+ setStatus('error');
396
+ }
397
+ }
398
+ });
399
+ useEffect(() => {
400
+ updateFileStateRef.current();
401
+ }, [fileState, updateFileStateRef]);
402
+ const onImageError = newCardPreview => {
403
+ if (newCardPreview) {
404
+ const failedSSRObject = {
405
+ status: 'fail',
406
+ ...extractErrorInfo(new ImageLoadError(newCardPreview.source))
407
+ };
408
+ if (isSSRClientPreview(newCardPreview)) {
409
+ ssrReliabilityRef.current.client = failedSSRObject;
410
+ }
411
+
412
+ /*
413
+ 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.
414
+ */
415
+
416
+ if (isSSRDataPreview(newCardPreview)) {
417
+ ssrReliabilityRef.current.server = failedSSRObject;
418
+ ssrReliabilityRef.current.client = failedSSRObject;
419
+ }
420
+ }
421
+
422
+ // If the dataURI has been replaced, we can dismiss this error
423
+ if ((newCardPreview === null || newCardPreview === void 0 ? void 0 : newCardPreview.dataURI) !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
424
+ return;
425
+ }
426
+ const error = new ImageLoadError(newCardPreview === null || newCardPreview === void 0 ? void 0 : newCardPreview.source);
427
+ const isLocal = newCardPreview && isLocalPreview(newCardPreview);
428
+ const isSSR = newCardPreview && (isSSRClientPreview(newCardPreview) || isSSRDataPreview(newCardPreview));
429
+ if (isLocal || isSSR) {
430
+ if (isLocal) {
431
+ setIsBannedLocalPreview(true);
432
+ setNonCriticalError(error);
433
+ }
434
+ const fileImageMode = imageResizeModeToFileImageMode(resizeMode);
435
+ removeCardPreviewFromCache(identifier.id, fileImageMode);
436
+ setCardPreview(undefined);
437
+ } else {
438
+ if (!['complete', 'error', 'failed-processing'].includes(status)) {
439
+ setStatus('error');
440
+ setError(error);
441
+ }
442
+ }
443
+ };
444
+ const onImageLoad = newCardPreview => {
445
+ if (newCardPreview) {
446
+ if (isSSRClientPreview(newCardPreview) && ssrReliabilityRef.current.client.status === 'unknown') {
447
+ ssrReliabilityRef.current.client = {
448
+ status: 'success'
449
+ };
450
+ }
451
+
452
+ /*
453
+ 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.
454
+ */
455
+
456
+ if (isSSRDataPreview(newCardPreview) && ssrReliabilityRef.current.server.status === 'unknown') {
457
+ ssrReliabilityRef.current.server = {
458
+ status: 'success'
459
+ };
460
+ ssrReliabilityRef.current.client = {
461
+ status: 'success'
462
+ };
463
+ }
464
+ }
465
+
466
+ // If the dataURI has been replaced, we can dismiss this callback
467
+ if ((newCardPreview === null || newCardPreview === void 0 ? void 0 : newCardPreview.dataURI) !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
468
+ return;
469
+ }
470
+ };
471
+
472
+ //----------------------------------------------------------------//
473
+ // RETURN
474
+ //----------------------------------------------------------------//
475
+
476
+ // FOR SSR
477
+ const getScriptProps = () => {
478
+ var _ssrReliabilityRef$cu;
479
+ return generateScriptProps(identifier, cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI, requestedDimensions, ((_ssrReliabilityRef$cu = ssrReliabilityRef.current.server) === null || _ssrReliabilityRef$cu === void 0 ? void 0 : _ssrReliabilityRef$cu.status) === 'fail' ? ssrReliabilityRef.current.server : undefined);
480
+ };
481
+
482
+ // CXP-2723 TODO: should consider simplifying our analytics, and how
483
+ // we might get rid of ssrReliabiltyRef from our hook
484
+ return {
485
+ cardPreview,
486
+ error,
487
+ nonCriticalError,
488
+ ssrReliabilityRef,
489
+ onImageError,
490
+ onImageLoad,
491
+ getScriptProps
492
+ };
493
+ };
@@ -37,7 +37,7 @@ export default class MediaInlineCardLoader extends React.PureComponent {
37
37
  } = this.state;
38
38
  const analyticsContext = {
39
39
  packageVersion: "@atlaskit/media-card",
40
- packageName: "77.4.5",
40
+ packageName: "77.4.7",
41
41
  componentName: 'mediaInlineCard',
42
42
  component: 'mediaInlineCard'
43
43
  };
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { printFunctionCall, printScript } from '../printScript';
3
2
  // ----- WARNING -----
4
3
  // This is a very sensitive fraction of code.
@@ -42,12 +41,7 @@ const generateScript = (identifier, dataURI, dimensions, error) => {
42
41
  const functionCall = printFunctionCall(storeDataURI, getKey(identifier), dataURI, dimensions, error);
43
42
  return printScript([getMediaCardSSR.toString(), getMediaGlobalScope.toString(), functionCall]);
44
43
  };
45
- export const StoreSSRDataScript = ({
46
- dataURI,
47
- identifier,
48
- dimensions,
49
- error
50
- }) => /*#__PURE__*/React.createElement("script", {
44
+ export const generateScriptProps = (identifier, dataURI, dimensions, error) => ({
51
45
  dangerouslySetInnerHTML: {
52
46
  __html: generateScript(identifier, dataURI, dimensions, error)
53
47
  }
@@ -1,2 +1,2 @@
1
- export { StoreSSRDataScript, GLOBAL_MEDIA_NAMESPACE, GLOBAL_MEDIA_CARD_SSR, getKey } from './globalScope';
1
+ export { GLOBAL_MEDIA_NAMESPACE, GLOBAL_MEDIA_CARD_SSR, generateScriptProps, getKey } from './globalScope';
2
2
  export { getSSRData } from './getSSRData';
@@ -4,7 +4,7 @@ import { extractErrorInfo, getRenderErrorRequestMetadata } from './analytics';
4
4
  import { MediaCardError } from '../errors';
5
5
  import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
6
6
  const packageName = "@atlaskit/media-card";
7
- const packageVersion = "77.4.5";
7
+ const packageVersion = "77.4.7";
8
8
  let concurrentExperience;
9
9
  const getExperience = id => {
10
10
  if (!concurrentExperience) {
@@ -33,14 +33,14 @@ import { getFileAttributes, extractErrorInfo } from '../utils/analytics';
33
33
  import { isLocalPreviewError, MediaCardError, ensureMediaCardError, ImageLoadError } from '../errors';
34
34
  import { fireOperationalEvent as _fireOperationalEvent, fireCommencedEvent as _fireCommencedEvent, fireCopiedEvent, fireScreenEvent, fireNonCriticalErrorEvent } from './cardAnalytics';
35
35
  import getDocument from '../utils/document';
36
- import { StoreSSRDataScript, getSSRData } from '../utils/globalScope';
36
+ import { generateScriptProps, getSSRData } from '../utils/globalScope';
37
37
  import { getCardStateFromFileState, createStateUpdater } from './cardState';
38
38
  import { isBigger } from '../utils/dimensionComparer';
39
39
  import { getMediaCardCursor } from '../utils/getMediaCardCursor';
40
40
  import { completeUfoExperience, startUfoExperience, abortUfoExperience } from '../utils/ufoExperiences';
41
41
  import { generateUniqueId } from '../utils/generateUniqueId';
42
42
  var packageName = "@atlaskit/media-card";
43
- var packageVersion = "77.4.5";
43
+ var packageVersion = "77.4.7";
44
44
  export var CardBase = /*#__PURE__*/function (_Component) {
45
45
  _inherits(CardBase, _Component);
46
46
  var _super = _createSuper(CardBase);
@@ -602,12 +602,9 @@ export var CardBase = /*#__PURE__*/function (_Component) {
602
602
  var _this$state$cardPrevi = _this.state.cardPreview,
603
603
  _this$state$cardPrevi2 = _this$state$cardPrevi === void 0 ? {} : _this$state$cardPrevi,
604
604
  dataURI = _this$state$cardPrevi2.dataURI;
605
- return isFileIdentifier(identifier) && ssr === 'server' && /*#__PURE__*/React.createElement(StoreSSRDataScript, {
606
- identifier: identifier,
607
- dataURI: dataURI,
608
- dimensions: _this.requestedDimensions,
609
- error: ((_this$ssrReliability$ = _this.ssrReliability.server) === null || _this$ssrReliability$ === void 0 ? void 0 : _this$ssrReliability$.status) === 'fail' ? _this.ssrReliability.server : undefined
610
- });
605
+ return isFileIdentifier(identifier) &&
606
+ // Print the SSR result to be used during hydration
607
+ ssr === 'server' && /*#__PURE__*/React.createElement("script", generateScriptProps(identifier, dataURI, _this.requestedDimensions, ((_this$ssrReliability$ = _this.ssrReliability.server) === null || _this$ssrReliability$ === void 0 ? void 0 : _this$ssrReliability$.status) === 'fail' ? _this.ssrReliability.server : undefined));
611
608
  });
612
609
  _defineProperty(_assertThisInitialized(_this), "onCardInViewport", function () {
613
610
  _this.setState({
@@ -26,6 +26,8 @@ export var extractFilePreviewStatus = function extractFilePreviewStatus(fileStat
26
26
  isSupportedByBrowser: isSupportedByBrowser
27
27
  };
28
28
  };
29
+
30
+ // CXP-2723 TODO: Review this in relation to removing status from the hook
29
31
  export var isPreviewableStatus = function isPreviewableStatus(cardStatus, _ref3) {
30
32
  var isPreviewable = _ref3.isPreviewable,
31
33
  hasPreview = _ref3.hasPreview,
@@ -83,7 +83,7 @@ var WrappedMediaCardAnalyticsErrorBoundary = /*#__PURE__*/function (_React$Compo
83
83
  }(React.Component);
84
84
  _defineProperty(WrappedMediaCardAnalyticsErrorBoundary, "displayName", 'MediaCardAnalyticsErrorBoundary');
85
85
  var packageName = "@atlaskit/media-card";
86
- var packageVersion = "77.4.5";
86
+ var packageVersion = "77.4.7";
87
87
  var MediaCardAnalyticsErrorBoundary = withMediaAnalyticsContext({
88
88
  packageVersion: packageVersion,
89
89
  packageName: packageName,
@@ -9,7 +9,7 @@ import { IntlProvider, injectIntl } from 'react-intl-next';
9
9
  import { ExternalImageCard } from './externalImageCard';
10
10
  import { FileCard } from './fileCard';
11
11
  var packageName = "@atlaskit/media-card";
12
- var packageVersion = "77.4.5";
12
+ var packageVersion = "77.4.7";
13
13
  export var CardV2Base = function CardV2Base(_ref) {
14
14
  var identifier = _ref.identifier,
15
15
  otherProps = _objectWithoutProperties(_ref, _excluded);