@atlaskit/media-card 77.4.7 → 77.4.8
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 +9 -0
- package/dist/cjs/card/card.js +1 -1
- package/dist/cjs/card/cardView.js +11 -7
- 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/cardViewV2.js +0 -3
- package/dist/cjs/card/v2/externalImageCard.js +3 -3
- package/dist/cjs/card/v2/fileCard.js +16 -15
- package/dist/cjs/card/v2/useFilePreview.js +44 -20
- package/dist/cjs/inline/loader.js +1 -1
- package/dist/cjs/utils/getDataURIDimension.js +38 -1
- package/dist/cjs/utils/ufoExperiences.js +1 -1
- package/dist/es2019/card/card.js +1 -1
- package/dist/es2019/card/cardView.js +6 -1
- 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/cardViewV2.js +0 -2
- package/dist/es2019/card/v2/externalImageCard.js +3 -3
- package/dist/es2019/card/v2/fileCard.js +18 -17
- package/dist/es2019/card/v2/useFilePreview.js +46 -21
- package/dist/es2019/inline/loader.js +1 -1
- package/dist/es2019/utils/getDataURIDimension.js +39 -0
- package/dist/es2019/utils/ufoExperiences.js +1 -1
- package/dist/esm/card/card.js +1 -1
- package/dist/esm/card/cardView.js +11 -7
- 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/cardViewV2.js +0 -3
- package/dist/esm/card/v2/externalImageCard.js +3 -3
- package/dist/esm/card/v2/fileCard.js +18 -17
- package/dist/esm/card/v2/useFilePreview.js +45 -21
- package/dist/esm/inline/loader.js +1 -1
- package/dist/esm/utils/getDataURIDimension.js +38 -0
- package/dist/esm/utils/ufoExperiences.js +1 -1
- package/dist/types/card/v2/cardViewV2.d.ts +17 -6
- package/dist/types/card/v2/fileCard.d.ts +40 -6
- package/dist/types/card/v2/useFilePreview.d.ts +5 -9
- package/dist/types/utils/getDataURIDimension.d.ts +17 -0
- package/dist/types/utils/globalScope/globalScope.d.ts +2 -2
- package/dist/types/utils/globalScope/types.d.ts +1 -1
- package/dist/types-ts4.5/card/v2/cardViewV2.d.ts +17 -6
- package/dist/types-ts4.5/card/v2/fileCard.d.ts +40 -6
- package/dist/types-ts4.5/card/v2/useFilePreview.d.ts +5 -9
- package/dist/types-ts4.5/utils/getDataURIDimension.d.ts +17 -0
- package/dist/types-ts4.5/utils/globalScope/globalScope.d.ts +2 -2
- package/dist/types-ts4.5/utils/globalScope/types.d.ts +1 -1
- package/package.json +5 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import DownloadIcon from '@atlaskit/icon/glyph/download';
|
|
2
2
|
import { globalMediaEventEmitter, isImageRepresentationReady, RECENTS_COLLECTION } from '@atlaskit/media-client';
|
|
3
|
-
import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
|
|
3
|
+
import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
4
4
|
import { getRandomHex, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
5
5
|
import { MediaViewer } from '@atlaskit/media-viewer';
|
|
6
6
|
import React, { Suspense, useEffect, useMemo, useRef, useState } from 'react';
|
|
@@ -8,7 +8,7 @@ import ReactDOM from 'react-dom';
|
|
|
8
8
|
import { MediaCardError } from '../../errors';
|
|
9
9
|
import getDocument from '../../utils/document';
|
|
10
10
|
import { generateUniqueId } from '../../utils/generateUniqueId';
|
|
11
|
-
import {
|
|
11
|
+
import { resolveCardPreviewDimensions } from '../../utils/getDataURIDimension';
|
|
12
12
|
import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
|
|
13
13
|
import { getFileDetails } from '../../utils/metadata';
|
|
14
14
|
import { abortUfoExperience, completeUfoExperience, startUfoExperience } from '../../utils/ufoExperiences';
|
|
@@ -16,6 +16,7 @@ import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
|
|
|
16
16
|
import { usePrevious } from '../../utils/usePrevious';
|
|
17
17
|
import { videoIsPlayable } from '../../utils/videoIsPlayable';
|
|
18
18
|
import { ViewportDetector } from '../../utils/viewportDetector';
|
|
19
|
+
import { getDefaultCardDimensions } from '../../utils/cardDimensions';
|
|
19
20
|
import { fireCommencedEvent, fireCopiedEvent, fireNonCriticalErrorEvent, fireOperationalEvent, fireScreenEvent } from '../cardAnalytics';
|
|
20
21
|
import { isSSRPreview } from '../getCardPreview';
|
|
21
22
|
import { CardViewV2 } from './cardViewV2';
|
|
@@ -30,7 +31,6 @@ export const FileCard = ({
|
|
|
30
31
|
featureFlags = {},
|
|
31
32
|
identifier,
|
|
32
33
|
ssr,
|
|
33
|
-
mediaClient,
|
|
34
34
|
dimensions,
|
|
35
35
|
originalDimensions,
|
|
36
36
|
contextId,
|
|
@@ -55,13 +55,18 @@ export const FileCard = ({
|
|
|
55
55
|
//------------ State, Refs & Initial Values ----------------------//
|
|
56
56
|
//----------------------------------------------------------------//
|
|
57
57
|
|
|
58
|
+
const mediaClient = useMediaClient();
|
|
58
59
|
const [cardElement, setCardElement] = useState(null);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const cardDimensions = dimensions || getDefaultCardDimensions(appearance);
|
|
61
|
+
|
|
62
|
+
// Calculate the preview dimensions if card dimensions are "percentage" based
|
|
63
|
+
const previewDimensions = useMemo(() =>
|
|
64
|
+
// resolving dimensions is eventually an expensive operation if the dimensions are a percentage
|
|
65
|
+
// thus needs to be memoized
|
|
66
|
+
resolveCardPreviewDimensions({
|
|
67
|
+
dimensions: cardDimensions,
|
|
63
68
|
element: cardElement
|
|
64
|
-
}), [
|
|
69
|
+
}), [cardDimensions, cardElement]);
|
|
65
70
|
const [isCardVisible, setIsCardVisible] = useState(!isLazy);
|
|
66
71
|
const {
|
|
67
72
|
fileState
|
|
@@ -120,10 +125,10 @@ export const FileCard = ({
|
|
|
120
125
|
mimeType,
|
|
121
126
|
name,
|
|
122
127
|
size,
|
|
123
|
-
...(originalDimensions ||
|
|
128
|
+
...(originalDimensions || previewDimensions),
|
|
124
129
|
alt
|
|
125
130
|
} : undefined;
|
|
126
|
-
}, [alt,
|
|
131
|
+
}, [alt, previewDimensions, contextId, fileStateValue, identifier, originalDimensions]);
|
|
127
132
|
const {
|
|
128
133
|
cardPreview,
|
|
129
134
|
error: previewError,
|
|
@@ -137,9 +142,7 @@ export const FileCard = ({
|
|
|
137
142
|
resizeMode,
|
|
138
143
|
identifier,
|
|
139
144
|
ssr,
|
|
140
|
-
|
|
141
|
-
dimensions,
|
|
142
|
-
requestedDimensions,
|
|
145
|
+
dimensions: previewDimensions,
|
|
143
146
|
traceContext,
|
|
144
147
|
previewDidRender,
|
|
145
148
|
skipRemote: !isCardVisible
|
|
@@ -472,9 +475,8 @@ export const FileCard = ({
|
|
|
472
475
|
metadata: metadata,
|
|
473
476
|
cardPreview: cardPreview,
|
|
474
477
|
alt: alt,
|
|
475
|
-
appearance: appearance,
|
|
476
478
|
resizeMode: resizeMode,
|
|
477
|
-
dimensions:
|
|
479
|
+
dimensions: cardDimensions,
|
|
478
480
|
actions: computedActions,
|
|
479
481
|
selectable: selectable,
|
|
480
482
|
selected: selected,
|
|
@@ -499,7 +501,6 @@ export const FileCard = ({
|
|
|
499
501
|
} : undefined,
|
|
500
502
|
innerRef: setCardElement,
|
|
501
503
|
testId: testId,
|
|
502
|
-
featureFlags: featureFlags,
|
|
503
504
|
titleBoxBgColor: titleBoxBgColor,
|
|
504
505
|
titleBoxIcon: titleBoxIcon,
|
|
505
506
|
onImageError: withCallbacks ? onImageError : undefined,
|
|
@@ -526,7 +527,7 @@ export const FileCard = ({
|
|
|
526
527
|
return /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? /*#__PURE__*/React.createElement(Suspense, {
|
|
527
528
|
fallback: inlinePlayerFallback
|
|
528
529
|
}, /*#__PURE__*/React.createElement(InlinePlayerLazyV2, {
|
|
529
|
-
dimensions:
|
|
530
|
+
dimensions: cardDimensions,
|
|
530
531
|
originalDimensions: originalDimensions,
|
|
531
532
|
identifier: identifier,
|
|
532
533
|
autoplay: !!shouldAutoplay,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { addFileAttrsToUrl, imageResizeModeToFileImageMode, isImageRepresentationReady } from '@atlaskit/media-client';
|
|
2
|
-
import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
|
|
2
|
+
import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
3
3
|
import { getMediaTypeFromMimeType, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
4
4
|
import { getOrientation } from '@atlaskit/media-ui';
|
|
5
5
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
6
6
|
import { ensureMediaCardError, ImageLoadError, isLocalPreviewError, isUnsupportedLocalPreviewError, LocalPreviewError, MediaCardError } from '../../errors';
|
|
7
7
|
import { extractErrorInfo } from '../../utils/analytics';
|
|
8
8
|
import { isBigger } from '../../utils/dimensionComparer';
|
|
9
|
+
import { isRetina } from '../../utils/isRetina';
|
|
9
10
|
import { generateScriptProps, getSSRData } from '../../utils/globalScope';
|
|
10
11
|
import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
|
|
11
12
|
import { usePrevious } from '../../utils/usePrevious';
|
|
@@ -16,16 +17,17 @@ export const useFilePreview = ({
|
|
|
16
17
|
resizeMode = 'crop',
|
|
17
18
|
identifier,
|
|
18
19
|
ssr,
|
|
19
|
-
mediaClient,
|
|
20
20
|
dimensions,
|
|
21
|
-
requestedDimensions,
|
|
22
21
|
traceContext,
|
|
23
22
|
previewDidRender,
|
|
24
23
|
skipRemote,
|
|
25
24
|
mediaBlobUrlAttrs
|
|
26
25
|
}) => {
|
|
26
|
+
const mediaClient = useMediaClient();
|
|
27
27
|
const [error, setError] = useState();
|
|
28
28
|
const [nonCriticalError, setNonCriticalError] = useState();
|
|
29
|
+
const requestDimensions = useMemo(() => dimensions ? createRequestDimensions(dimensions) : undefined, [dimensions]);
|
|
30
|
+
|
|
29
31
|
//----------------------------------------------------------------//
|
|
30
32
|
//---------------- State Initializer Functions -------------------//
|
|
31
33
|
//----------------------------------------------------------------//
|
|
@@ -42,9 +44,9 @@ export const useFilePreview = ({
|
|
|
42
44
|
const imageURLParams = useMemo(() => ({
|
|
43
45
|
collection: identifier.collectionName,
|
|
44
46
|
mode: resizeMode === 'stretchy-fit' ? 'full-fit' : resizeMode,
|
|
45
|
-
...
|
|
47
|
+
...requestDimensions,
|
|
46
48
|
allowAnimated: true
|
|
47
|
-
}), [
|
|
49
|
+
}), [requestDimensions, identifier.collectionName, resizeMode]);
|
|
48
50
|
const getSSRPreview = (ssr, identifier, mediaClient) => {
|
|
49
51
|
var _ssrDataRef$current, _ssrDataRef$current2;
|
|
50
52
|
ssrDataRef.current = getSSRData(identifier);
|
|
@@ -64,8 +66,13 @@ export const useFilePreview = ({
|
|
|
64
66
|
};
|
|
65
67
|
}
|
|
66
68
|
} else {
|
|
69
|
+
const {
|
|
70
|
+
dimensions,
|
|
71
|
+
dataURI
|
|
72
|
+
} = ssrDataRef.current;
|
|
67
73
|
return {
|
|
68
|
-
dataURI
|
|
74
|
+
dataURI,
|
|
75
|
+
dimensions,
|
|
69
76
|
source: 'ssr-data'
|
|
70
77
|
};
|
|
71
78
|
}
|
|
@@ -107,7 +114,7 @@ export const useFilePreview = ({
|
|
|
107
114
|
//----------------------------------------------------------------//
|
|
108
115
|
|
|
109
116
|
const fetchRemotePreviewRef = useCurrentValueRef(identifier => {
|
|
110
|
-
return fetchAndCacheRemotePreview(mediaClient, identifier.id,
|
|
117
|
+
return fetchAndCacheRemotePreview(mediaClient, identifier.id, requestDimensions || {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
|
|
111
118
|
});
|
|
112
119
|
const resolvePreviewRef = useCurrentValueRef(async (identifier, fileState) => {
|
|
113
120
|
const filePreview = isBannedLocalPreview ? undefined : fileState.status !== 'error' && 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) ? fileState.preview : undefined;
|
|
@@ -115,7 +122,7 @@ export const useFilePreview = ({
|
|
|
115
122
|
try {
|
|
116
123
|
const mode = imageURLParams.mode;
|
|
117
124
|
const cachedPreview = cardPreviewCache.get(identifier.id, mode);
|
|
118
|
-
const dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions,
|
|
125
|
+
const dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, requestDimensions);
|
|
119
126
|
if (cachedPreview && !dimensionsAreBigger) {
|
|
120
127
|
return cachedPreview;
|
|
121
128
|
}
|
|
@@ -174,7 +181,7 @@ export const useFilePreview = ({
|
|
|
174
181
|
}
|
|
175
182
|
const preview = {
|
|
176
183
|
...localPreview,
|
|
177
|
-
dimensions
|
|
184
|
+
dimensions: requestDimensions
|
|
178
185
|
};
|
|
179
186
|
let source;
|
|
180
187
|
switch (preview.source) {
|
|
@@ -239,7 +246,7 @@ export const useFilePreview = ({
|
|
|
239
246
|
*/
|
|
240
247
|
throw new MediaCardError('remote-preview-not-ready');
|
|
241
248
|
}
|
|
242
|
-
const remotePreview = await
|
|
249
|
+
const remotePreview = await fetchRemotePreviewRef.current(identifier);
|
|
243
250
|
setCardPreview(remotePreview);
|
|
244
251
|
return;
|
|
245
252
|
} catch (e) {
|
|
@@ -264,7 +271,7 @@ export const useFilePreview = ({
|
|
|
264
271
|
//------------ resolveUpfrontPreview useEffect -------------------//
|
|
265
272
|
//----------------------------------------------------------------//
|
|
266
273
|
const prevCardPreview = usePrevious(cardPreview);
|
|
267
|
-
const
|
|
274
|
+
const requestDimensionsRef = useCurrentValueRef(requestDimensions);
|
|
268
275
|
useEffect(() => {
|
|
269
276
|
const resolveUpfrontPreview = async identifier => {
|
|
270
277
|
// We block any possible future call to this method regardless of the outcome (success or fail)
|
|
@@ -272,10 +279,10 @@ export const useFilePreview = ({
|
|
|
272
279
|
wasResolvedUpfrontPreviewRef.current = true;
|
|
273
280
|
try {
|
|
274
281
|
const fetchedDimensions = {
|
|
275
|
-
...
|
|
282
|
+
...requestDimensions
|
|
276
283
|
};
|
|
277
284
|
const newCardPreview = await fetchRemotePreviewRef.current(identifier);
|
|
278
|
-
const areValidFetchedDimensions = !isBigger(fetchedDimensions,
|
|
285
|
+
const areValidFetchedDimensions = !isBigger(fetchedDimensions, requestDimensionsRef.current);
|
|
279
286
|
|
|
280
287
|
// If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
|
|
281
288
|
// the fetched preview is no longer valid, and thus, we dismiss it
|
|
@@ -292,16 +299,16 @@ export const useFilePreview = ({
|
|
|
292
299
|
if (!wasResolvedUpfrontPreviewRef.current && (!skipRemote || hadSSRCardPreview) && !cardPreview) {
|
|
293
300
|
resolveUpfrontPreview(identifier);
|
|
294
301
|
}
|
|
295
|
-
}, [cardPreview,
|
|
302
|
+
}, [cardPreview, requestDimensions, requestDimensionsRef, fetchRemotePreviewRef, identifier, skipRemote, prevCardPreview, ssr]);
|
|
296
303
|
|
|
297
304
|
//----------------------------------------------------------------//
|
|
298
305
|
//---------------- fetch and resolve card preview ----------------//
|
|
299
306
|
//----------------------------------------------------------------//
|
|
300
307
|
|
|
301
|
-
const
|
|
308
|
+
const prevRequestDimensions = usePrevious(requestDimensions);
|
|
302
309
|
useEffect(() => {
|
|
303
|
-
|
|
304
|
-
if (cardPreview && !skipRemote && isSSRDataPreview(cardPreview) && isBigger(
|
|
310
|
+
// CXP-2813 TODO: This is called too many times if the refetch failed. Should be called only once
|
|
311
|
+
if (cardPreview && !skipRemote && isSSRDataPreview(cardPreview) && isBigger(cardPreview.dimensions, requestDimensions)) {
|
|
305
312
|
// refetchSRRPreview: If dimensions from Server have changed and are bigger,
|
|
306
313
|
// we need to refetch
|
|
307
314
|
fetchRemotePreviewRef.current(identifier).then(setCardPreview).catch(e => {
|
|
@@ -316,8 +323,8 @@ export const useFilePreview = ({
|
|
|
316
323
|
if (fileState && shouldResolvePreview({
|
|
317
324
|
status,
|
|
318
325
|
fileState: fileState,
|
|
319
|
-
prevDimensions,
|
|
320
|
-
dimensions,
|
|
326
|
+
prevDimensions: prevRequestDimensions,
|
|
327
|
+
dimensions: requestDimensions,
|
|
321
328
|
hasCardPreview: !!cardPreview,
|
|
322
329
|
isBannedLocalPreview,
|
|
323
330
|
wasResolvedUpfrontPreview: wasResolvedUpfrontPreviewRef.current
|
|
@@ -334,7 +341,7 @@ export const useFilePreview = ({
|
|
|
334
341
|
// https://product-fabric.atlassian.net/browse/MEX-1071
|
|
335
342
|
});
|
|
336
343
|
}
|
|
337
|
-
}, [cardPreview,
|
|
344
|
+
}, [cardPreview, requestDimensions, fetchRemotePreviewRef, fileState, identifier, isBannedLocalPreview, prevRequestDimensions, resolvePreviewRef, skipRemote, ssr, status]);
|
|
338
345
|
|
|
339
346
|
//----------------------------------------------------------------//
|
|
340
347
|
//----------------- set complete status --------------------------//
|
|
@@ -476,7 +483,7 @@ export const useFilePreview = ({
|
|
|
476
483
|
// FOR SSR
|
|
477
484
|
const getScriptProps = () => {
|
|
478
485
|
var _ssrReliabilityRef$cu;
|
|
479
|
-
return generateScriptProps(identifier, cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI,
|
|
486
|
+
return generateScriptProps(identifier, cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI, requestDimensions, ((_ssrReliabilityRef$cu = ssrReliabilityRef.current.server) === null || _ssrReliabilityRef$cu === void 0 ? void 0 : _ssrReliabilityRef$cu.status) === 'fail' ? ssrReliabilityRef.current.server : undefined);
|
|
480
487
|
};
|
|
481
488
|
|
|
482
489
|
// CXP-2723 TODO: should consider simplifying our analytics, and how
|
|
@@ -490,4 +497,22 @@ export const useFilePreview = ({
|
|
|
490
497
|
onImageLoad,
|
|
491
498
|
getScriptProps
|
|
492
499
|
};
|
|
500
|
+
};
|
|
501
|
+
const createRequestDimensions = dimensions => {
|
|
502
|
+
if (!dimensions) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const retinaFactor = isRetina() ? 2 : 1;
|
|
506
|
+
const {
|
|
507
|
+
width,
|
|
508
|
+
height
|
|
509
|
+
} = dimensions;
|
|
510
|
+
const result = {};
|
|
511
|
+
if (width) {
|
|
512
|
+
result.width = width * retinaFactor;
|
|
513
|
+
}
|
|
514
|
+
if (height) {
|
|
515
|
+
result.height = height * retinaFactor;
|
|
516
|
+
}
|
|
517
|
+
return result;
|
|
493
518
|
};
|
|
@@ -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.
|
|
40
|
+
packageName: "77.4.8",
|
|
41
41
|
componentName: 'mediaInlineCard',
|
|
42
42
|
component: 'mediaInlineCard'
|
|
43
43
|
};
|
|
@@ -3,6 +3,13 @@ import { getElementDimension } from './getElementDimension';
|
|
|
3
3
|
import { defaultImageCardDimensions } from './cardDimensions';
|
|
4
4
|
import { isValidPercentageUnit } from './isValidPercentageUnit';
|
|
5
5
|
import { containsPixelUnit } from './containsPixelUnit';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ************************************************
|
|
9
|
+
* For Card v1
|
|
10
|
+
* ************************************************
|
|
11
|
+
*/
|
|
12
|
+
|
|
6
13
|
export const getDataURIDimension = (dimension, options) => {
|
|
7
14
|
const retinaFactor = isRetina() ? 2 : 1;
|
|
8
15
|
const dimensionValue = options.dimensions && options.dimensions[dimension] || '';
|
|
@@ -24,4 +31,36 @@ export const getRequestedDimensions = options => {
|
|
|
24
31
|
width,
|
|
25
32
|
height
|
|
26
33
|
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* ************************************************
|
|
38
|
+
* For Card v2
|
|
39
|
+
* ************************************************
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
// Same as getDataURIDimension but without Retina factor
|
|
43
|
+
export const resolveCardPreviewDimension = (dimensionName, {
|
|
44
|
+
dimensions,
|
|
45
|
+
element
|
|
46
|
+
}) => {
|
|
47
|
+
const dimensionValue = (dimensions === null || dimensions === void 0 ? void 0 : dimensions[dimensionName]) || '';
|
|
48
|
+
if (isValidPercentageUnit(dimensionValue) && element) {
|
|
49
|
+
return getElementDimension(element, dimensionName);
|
|
50
|
+
}
|
|
51
|
+
if (typeof dimensionValue === 'number') {
|
|
52
|
+
return dimensionValue;
|
|
53
|
+
}
|
|
54
|
+
if (containsPixelUnit(`${dimensionValue}`)) {
|
|
55
|
+
return parseInt(`${dimensionValue}`, 10);
|
|
56
|
+
}
|
|
57
|
+
return defaultImageCardDimensions[dimensionName];
|
|
58
|
+
};
|
|
59
|
+
export const resolveCardPreviewDimensions = options => {
|
|
60
|
+
const width = resolveCardPreviewDimension('width', options);
|
|
61
|
+
const height = resolveCardPreviewDimension('height', options);
|
|
62
|
+
return {
|
|
63
|
+
width,
|
|
64
|
+
height
|
|
65
|
+
};
|
|
27
66
|
};
|
|
@@ -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.
|
|
7
|
+
const packageVersion = "77.4.8";
|
|
8
8
|
let concurrentExperience;
|
|
9
9
|
const getExperience = id => {
|
|
10
10
|
if (!concurrentExperience) {
|
package/dist/esm/card/card.js
CHANGED
|
@@ -40,7 +40,7 @@ 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.
|
|
43
|
+
var packageVersion = "77.4.8";
|
|
44
44
|
export var CardBase = /*#__PURE__*/function (_Component) {
|
|
45
45
|
_inherits(CardBase, _Component);
|
|
46
46
|
var _super = _createSuper(CardBase);
|
|
@@ -36,6 +36,7 @@ import { PreviewUnavailable, CreatingPreview, FailedToUpload, PreviewCurrentlyUn
|
|
|
36
36
|
import { isUploadError, isRateLimitedError, isPollingError } from '../errors';
|
|
37
37
|
import { Wrapper } from './ui/wrapper';
|
|
38
38
|
import { fileCardImageViewSelector } from './classnames';
|
|
39
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
39
40
|
/**
|
|
40
41
|
* This is classic vanilla CardView class. To create an instance of class one would need to supply
|
|
41
42
|
* `createAnalyticsEvent` prop to satisfy it's Analytics Events needs.
|
|
@@ -328,10 +329,13 @@ export var CardViewBase = /*#__PURE__*/function (_React$Component) {
|
|
|
328
329
|
onDisplayImage = _this$props6.onDisplayImage,
|
|
329
330
|
nativeLazyLoad = _this$props6.nativeLazyLoad,
|
|
330
331
|
forceSyncDisplay = _this$props6.forceSyncDisplay;
|
|
332
|
+
var _ref7 = this.props.metadata || {},
|
|
333
|
+
name = _ref7.name;
|
|
334
|
+
var altText = getBooleanFF('platform.editor.a11y-media_er96o') ? alt || name : alt;
|
|
331
335
|
return !!cardPreview && jsx(ImageRenderer, {
|
|
332
336
|
cardPreview: cardPreview,
|
|
333
337
|
mediaType: mediaType,
|
|
334
|
-
alt:
|
|
338
|
+
alt: altText,
|
|
335
339
|
resizeMode: resizeMode,
|
|
336
340
|
onDisplayImage: onDisplayImage,
|
|
337
341
|
onImageLoad: this.onImageLoad,
|
|
@@ -352,10 +356,10 @@ export var CardViewBase = /*#__PURE__*/function (_React$Component) {
|
|
|
352
356
|
key: "renderMediaTypeIcon",
|
|
353
357
|
value: function renderMediaTypeIcon(hasTitleBox, iconMessage) {
|
|
354
358
|
var metadata = this.props.metadata;
|
|
355
|
-
var
|
|
356
|
-
mediaType =
|
|
357
|
-
mimeType =
|
|
358
|
-
name =
|
|
359
|
+
var _ref8 = metadata || {},
|
|
360
|
+
mediaType = _ref8.mediaType,
|
|
361
|
+
mimeType = _ref8.mimeType,
|
|
362
|
+
name = _ref8.name;
|
|
359
363
|
return jsx(IconWrapper, {
|
|
360
364
|
breakpoint: this.breakpoint,
|
|
361
365
|
hasTitleBox: hasTitleBox
|
|
@@ -398,8 +402,8 @@ export var CardViewBase = /*#__PURE__*/function (_React$Component) {
|
|
|
398
402
|
cardPreview = _this$props8.cardPreview,
|
|
399
403
|
mediaCardCursor = _this$props8.mediaCardCursor,
|
|
400
404
|
shouldHideTooltip = _this$props8.shouldHideTooltip;
|
|
401
|
-
var
|
|
402
|
-
name =
|
|
405
|
+
var _ref9 = metadata || {},
|
|
406
|
+
name = _ref9.name;
|
|
403
407
|
var shouldDisplayBackground = !cardPreview || !disableOverlay || status === 'error' || status === 'failed-processing';
|
|
404
408
|
var isPlayButtonClickable = !!(this.shouldRenderPlayButton() && disableOverlay);
|
|
405
409
|
var isTickBoxSelectable = !disableOverlay && !!selectable && !selected;
|
|
@@ -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.
|
|
86
|
+
var packageVersion = "77.4.8";
|
|
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.
|
|
12
|
+
var packageVersion = "77.4.8";
|
|
13
13
|
export var CardV2Base = function CardV2Base(_ref) {
|
|
14
14
|
var identifier = _ref.identifier,
|
|
15
15
|
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -32,8 +32,6 @@ export var CardViewV2Base = function CardViewV2Base(_ref) {
|
|
|
32
32
|
onImageLoad = _ref.onImageLoad,
|
|
33
33
|
onImageError = _ref.onImageError,
|
|
34
34
|
dimensions = _ref.dimensions,
|
|
35
|
-
_ref$appearance = _ref.appearance,
|
|
36
|
-
appearance = _ref$appearance === void 0 ? 'auto' : _ref$appearance,
|
|
37
35
|
onClick = _ref.onClick,
|
|
38
36
|
onMouseEnter = _ref.onMouseEnter,
|
|
39
37
|
testId = _ref.testId,
|
|
@@ -254,7 +252,6 @@ export var CardViewV2Base = function CardViewV2Base(_ref) {
|
|
|
254
252
|
return jsx(Wrapper, {
|
|
255
253
|
testId: testId || 'media-card-view',
|
|
256
254
|
dimensions: dimensions,
|
|
257
|
-
appearance: appearance,
|
|
258
255
|
onClick: onClick,
|
|
259
256
|
onMouseEnter: onMouseEnter,
|
|
260
257
|
innerRef: divRef,
|
|
@@ -13,6 +13,7 @@ import { generateUniqueId } from '../../utils/generateUniqueId';
|
|
|
13
13
|
import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
|
|
14
14
|
import { abortUfoExperience, completeUfoExperience, startUfoExperience } from '../../utils/ufoExperiences';
|
|
15
15
|
import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
|
|
16
|
+
import { getDefaultCardDimensions } from '../../utils/cardDimensions';
|
|
16
17
|
import { usePrevious } from '../../utils/usePrevious';
|
|
17
18
|
import { fireCommencedEvent, fireCopiedEvent, fireOperationalEvent, fireScreenEvent } from '../cardAnalytics';
|
|
18
19
|
import { CardViewV2 } from './cardViewV2';
|
|
@@ -42,6 +43,7 @@ export var ExternalImageCard = function ExternalImageCard(_ref) {
|
|
|
42
43
|
_onClick = _ref.onClick,
|
|
43
44
|
_onMouseEnter = _ref.onMouseEnter,
|
|
44
45
|
createAnalyticsEvent = _ref.createAnalyticsEvent;
|
|
46
|
+
var cardDimensions = dimensions || getDefaultCardDimensions(appearance);
|
|
45
47
|
var internalOccurrenceKey = useMemo(function () {
|
|
46
48
|
return generateUniqueId();
|
|
47
49
|
}, []);
|
|
@@ -223,9 +225,8 @@ export var ExternalImageCard = function ExternalImageCard(_ref) {
|
|
|
223
225
|
metadata: metadata,
|
|
224
226
|
cardPreview: cardPreview,
|
|
225
227
|
alt: alt,
|
|
226
|
-
appearance: appearance,
|
|
227
228
|
resizeMode: resizeMode,
|
|
228
|
-
dimensions:
|
|
229
|
+
dimensions: cardDimensions,
|
|
229
230
|
actions: actions,
|
|
230
231
|
selectable: selectable,
|
|
231
232
|
selected: selected,
|
|
@@ -263,7 +264,6 @@ export var ExternalImageCard = function ExternalImageCard(_ref) {
|
|
|
263
264
|
},
|
|
264
265
|
innerRef: setCardElement,
|
|
265
266
|
testId: testId,
|
|
266
|
-
featureFlags: featureFlags,
|
|
267
267
|
titleBoxBgColor: titleBoxBgColor,
|
|
268
268
|
titleBoxIcon: titleBoxIcon,
|
|
269
269
|
onImageError: function onImageError(newCardPreview) {
|
|
@@ -5,7 +5,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
5
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; }
|
|
6
6
|
import DownloadIcon from '@atlaskit/icon/glyph/download';
|
|
7
7
|
import { globalMediaEventEmitter, isImageRepresentationReady, RECENTS_COLLECTION } from '@atlaskit/media-client';
|
|
8
|
-
import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
|
|
8
|
+
import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
9
9
|
import { getRandomHex, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
10
10
|
import { MediaViewer } from '@atlaskit/media-viewer';
|
|
11
11
|
import React, { Suspense, useEffect, useMemo, useRef, useState } from 'react';
|
|
@@ -13,7 +13,7 @@ import ReactDOM from 'react-dom';
|
|
|
13
13
|
import { MediaCardError } from '../../errors';
|
|
14
14
|
import getDocument from '../../utils/document';
|
|
15
15
|
import { generateUniqueId } from '../../utils/generateUniqueId';
|
|
16
|
-
import {
|
|
16
|
+
import { resolveCardPreviewDimensions } from '../../utils/getDataURIDimension';
|
|
17
17
|
import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
|
|
18
18
|
import { getFileDetails } from '../../utils/metadata';
|
|
19
19
|
import { abortUfoExperience, completeUfoExperience, startUfoExperience } from '../../utils/ufoExperiences';
|
|
@@ -21,6 +21,7 @@ import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
|
|
|
21
21
|
import { usePrevious } from '../../utils/usePrevious';
|
|
22
22
|
import { videoIsPlayable } from '../../utils/videoIsPlayable';
|
|
23
23
|
import { ViewportDetector } from '../../utils/viewportDetector';
|
|
24
|
+
import { getDefaultCardDimensions } from '../../utils/cardDimensions';
|
|
24
25
|
import { fireCommencedEvent, fireCopiedEvent, fireNonCriticalErrorEvent, fireOperationalEvent, fireScreenEvent } from '../cardAnalytics';
|
|
25
26
|
import { isSSRPreview } from '../getCardPreview';
|
|
26
27
|
import { CardViewV2 } from './cardViewV2';
|
|
@@ -39,7 +40,6 @@ export var FileCard = function FileCard(_ref) {
|
|
|
39
40
|
featureFlags = _ref$featureFlags === void 0 ? {} : _ref$featureFlags,
|
|
40
41
|
identifier = _ref.identifier,
|
|
41
42
|
ssr = _ref.ssr,
|
|
42
|
-
mediaClient = _ref.mediaClient,
|
|
43
43
|
dimensions = _ref.dimensions,
|
|
44
44
|
originalDimensions = _ref.originalDimensions,
|
|
45
45
|
contextId = _ref.contextId,
|
|
@@ -63,19 +63,24 @@ export var FileCard = function FileCard(_ref) {
|
|
|
63
63
|
//------------ State, Refs & Initial Values ----------------------//
|
|
64
64
|
//----------------------------------------------------------------//
|
|
65
65
|
|
|
66
|
+
var mediaClient = useMediaClient();
|
|
66
67
|
var _useState = useState(null),
|
|
67
68
|
_useState2 = _slicedToArray(_useState, 2),
|
|
68
69
|
cardElement = _useState2[0],
|
|
69
70
|
setCardElement = _useState2[1];
|
|
70
|
-
var
|
|
71
|
+
var cardDimensions = dimensions || getDefaultCardDimensions(appearance);
|
|
72
|
+
|
|
73
|
+
// Calculate the preview dimensions if card dimensions are "percentage" based
|
|
74
|
+
var previewDimensions = useMemo(function () {
|
|
71
75
|
return (
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
// resolving dimensions is eventually an expensive operation if the dimensions are a percentage
|
|
77
|
+
// thus needs to be memoized
|
|
78
|
+
resolveCardPreviewDimensions({
|
|
79
|
+
dimensions: cardDimensions,
|
|
75
80
|
element: cardElement
|
|
76
81
|
})
|
|
77
82
|
);
|
|
78
|
-
}, [
|
|
83
|
+
}, [cardDimensions, cardElement]);
|
|
79
84
|
var _useState3 = useState(!isLazy),
|
|
80
85
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
81
86
|
isCardVisible = _useState4[0],
|
|
@@ -154,18 +159,16 @@ export var FileCard = function FileCard(_ref) {
|
|
|
154
159
|
mimeType: mimeType,
|
|
155
160
|
name: name,
|
|
156
161
|
size: size
|
|
157
|
-
}, originalDimensions ||
|
|
162
|
+
}, originalDimensions || previewDimensions), {}, {
|
|
158
163
|
alt: alt
|
|
159
164
|
}) : undefined;
|
|
160
|
-
}, [alt,
|
|
165
|
+
}, [alt, previewDimensions, contextId, fileStateValue, identifier, originalDimensions]);
|
|
161
166
|
var _useFilePreview = useFilePreview({
|
|
162
167
|
mediaBlobUrlAttrs: mediaBlobUrlAttrs,
|
|
163
168
|
resizeMode: resizeMode,
|
|
164
169
|
identifier: identifier,
|
|
165
170
|
ssr: ssr,
|
|
166
|
-
|
|
167
|
-
dimensions: dimensions,
|
|
168
|
-
requestedDimensions: requestedDimensions,
|
|
171
|
+
dimensions: previewDimensions,
|
|
169
172
|
traceContext: traceContext,
|
|
170
173
|
previewDidRender: previewDidRender,
|
|
171
174
|
skipRemote: !isCardVisible
|
|
@@ -513,9 +516,8 @@ export var FileCard = function FileCard(_ref) {
|
|
|
513
516
|
metadata: metadata,
|
|
514
517
|
cardPreview: cardPreview,
|
|
515
518
|
alt: alt,
|
|
516
|
-
appearance: appearance,
|
|
517
519
|
resizeMode: resizeMode,
|
|
518
|
-
dimensions:
|
|
520
|
+
dimensions: cardDimensions,
|
|
519
521
|
actions: computedActions,
|
|
520
522
|
selectable: selectable,
|
|
521
523
|
selected: selected,
|
|
@@ -539,7 +541,6 @@ export var FileCard = function FileCard(_ref) {
|
|
|
539
541
|
} : undefined,
|
|
540
542
|
innerRef: setCardElement,
|
|
541
543
|
testId: testId,
|
|
542
|
-
featureFlags: featureFlags,
|
|
543
544
|
titleBoxBgColor: titleBoxBgColor,
|
|
544
545
|
titleBoxIcon: titleBoxIcon,
|
|
545
546
|
onImageError: withCallbacks ? onImageError : undefined,
|
|
@@ -566,7 +567,7 @@ export var FileCard = function FileCard(_ref) {
|
|
|
566
567
|
return /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? /*#__PURE__*/React.createElement(Suspense, {
|
|
567
568
|
fallback: inlinePlayerFallback
|
|
568
569
|
}, /*#__PURE__*/React.createElement(InlinePlayerLazyV2, {
|
|
569
|
-
dimensions:
|
|
570
|
+
dimensions: cardDimensions,
|
|
570
571
|
originalDimensions: originalDimensions,
|
|
571
572
|
identifier: identifier,
|
|
572
573
|
autoplay: !!shouldAutoplay,
|