@atlaskit/media-card 77.4.6 → 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 +16 -0
- package/dist/cjs/card/card.js +4 -7
- 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 +18 -17
- package/dist/cjs/card/v2/useFilePreview.js +48 -31
- package/dist/cjs/inline/loader.js +1 -1
- package/dist/cjs/utils/getDataURIDimension.js +38 -1
- package/dist/cjs/utils/globalScope/globalScope.js +4 -10
- package/dist/cjs/utils/globalScope/index.js +2 -2
- package/dist/cjs/utils/ufoExperiences.js +1 -1
- package/dist/es2019/card/card.js +5 -8
- 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 +21 -20
- package/dist/es2019/card/v2/useFilePreview.js +51 -32
- package/dist/es2019/inline/loader.js +1 -1
- package/dist/es2019/utils/getDataURIDimension.js +39 -0
- package/dist/es2019/utils/globalScope/globalScope.js +1 -7
- package/dist/es2019/utils/globalScope/index.js +1 -1
- package/dist/es2019/utils/ufoExperiences.js +1 -1
- package/dist/esm/card/card.js +5 -8
- 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 +21 -20
- package/dist/esm/card/v2/useFilePreview.js +50 -32
- package/dist/esm/inline/loader.js +1 -1
- package/dist/esm/utils/getDataURIDimension.js +38 -0
- package/dist/esm/utils/globalScope/globalScope.js +3 -8
- package/dist/esm/utils/globalScope/index.js +1 -1
- 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 +9 -14
- package/dist/types/utils/getDataURIDimension.d.ts +17 -0
- package/dist/types/utils/globalScope/globalScope.d.ts +2 -8
- package/dist/types/utils/globalScope/index.d.ts +1 -1
- 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 +9 -14
- package/dist/types-ts4.5/utils/getDataURIDimension.d.ts +17 -0
- package/dist/types-ts4.5/utils/globalScope/globalScope.d.ts +2 -8
- package/dist/types-ts4.5/utils/globalScope/index.d.ts +1 -1
- package/dist/types-ts4.5/utils/globalScope/types.d.ts +1 -1
- package/package.json +7 -3
package/dist/es2019/card/card.js
CHANGED
|
@@ -20,14 +20,14 @@ import { getFileAttributes, extractErrorInfo } from '../utils/analytics';
|
|
|
20
20
|
import { isLocalPreviewError, MediaCardError, ensureMediaCardError, ImageLoadError } from '../errors';
|
|
21
21
|
import { fireOperationalEvent, fireCommencedEvent, fireCopiedEvent, fireScreenEvent, fireNonCriticalErrorEvent } from './cardAnalytics';
|
|
22
22
|
import getDocument from '../utils/document';
|
|
23
|
-
import {
|
|
23
|
+
import { generateScriptProps, getSSRData } from '../utils/globalScope';
|
|
24
24
|
import { getCardStateFromFileState, createStateUpdater } from './cardState';
|
|
25
25
|
import { isBigger } from '../utils/dimensionComparer';
|
|
26
26
|
import { getMediaCardCursor } from '../utils/getMediaCardCursor';
|
|
27
27
|
import { completeUfoExperience, startUfoExperience, abortUfoExperience } from '../utils/ufoExperiences';
|
|
28
28
|
import { generateUniqueId } from '../utils/generateUniqueId';
|
|
29
29
|
const packageName = "@atlaskit/media-card";
|
|
30
|
-
const packageVersion = "77.4.
|
|
30
|
+
const packageVersion = "77.4.8";
|
|
31
31
|
export class CardBase extends Component {
|
|
32
32
|
constructor(props) {
|
|
33
33
|
super(props);
|
|
@@ -573,12 +573,9 @@ export class CardBase extends Component {
|
|
|
573
573
|
dataURI
|
|
574
574
|
} = {}
|
|
575
575
|
} = this.state;
|
|
576
|
-
return isFileIdentifier(identifier) &&
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
dimensions: this.requestedDimensions,
|
|
580
|
-
error: ((_this$ssrReliability$ = this.ssrReliability.server) === null || _this$ssrReliability$ === void 0 ? void 0 : _this$ssrReliability$.status) === 'fail' ? this.ssrReliability.server : undefined
|
|
581
|
-
});
|
|
576
|
+
return isFileIdentifier(identifier) &&
|
|
577
|
+
// Print the SSR result to be used during hydration
|
|
578
|
+
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));
|
|
582
579
|
});
|
|
583
580
|
_defineProperty(this, "onCardInViewport", () => {
|
|
584
581
|
this.setState({
|
|
@@ -26,6 +26,7 @@ import { PreviewUnavailable, CreatingPreview, FailedToUpload, PreviewCurrentlyUn
|
|
|
26
26
|
import { isUploadError, isRateLimitedError, isPollingError } from '../errors';
|
|
27
27
|
import { Wrapper } from './ui/wrapper';
|
|
28
28
|
import { fileCardImageViewSelector } from './classnames';
|
|
29
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
29
30
|
/**
|
|
30
31
|
* This is classic vanilla CardView class. To create an instance of class one would need to supply
|
|
31
32
|
* `createAnalyticsEvent` prop to satisfy it's Analytics Events needs.
|
|
@@ -320,10 +321,14 @@ export class CardViewBase extends React.Component {
|
|
|
320
321
|
nativeLazyLoad,
|
|
321
322
|
forceSyncDisplay
|
|
322
323
|
} = this.props;
|
|
324
|
+
const {
|
|
325
|
+
name
|
|
326
|
+
} = this.props.metadata || {};
|
|
327
|
+
const altText = getBooleanFF('platform.editor.a11y-media_er96o') ? alt || name : alt;
|
|
323
328
|
return !!cardPreview && jsx(ImageRenderer, {
|
|
324
329
|
cardPreview: cardPreview,
|
|
325
330
|
mediaType: mediaType,
|
|
326
|
-
alt:
|
|
331
|
+
alt: altText,
|
|
327
332
|
resizeMode: resizeMode,
|
|
328
333
|
onDisplayImage: onDisplayImage,
|
|
329
334
|
onImageLoad: this.onImageLoad,
|
|
@@ -66,7 +66,7 @@ class WrappedMediaCardAnalyticsErrorBoundary extends React.Component {
|
|
|
66
66
|
}
|
|
67
67
|
_defineProperty(WrappedMediaCardAnalyticsErrorBoundary, "displayName", 'MediaCardAnalyticsErrorBoundary');
|
|
68
68
|
const packageName = "@atlaskit/media-card";
|
|
69
|
-
const packageVersion = "77.4.
|
|
69
|
+
const packageVersion = "77.4.8";
|
|
70
70
|
const MediaCardAnalyticsErrorBoundary = withMediaAnalyticsContext({
|
|
71
71
|
packageVersion,
|
|
72
72
|
packageName,
|
|
@@ -7,7 +7,7 @@ import { IntlProvider, injectIntl } from 'react-intl-next';
|
|
|
7
7
|
import { ExternalImageCard } from './externalImageCard';
|
|
8
8
|
import { FileCard } from './fileCard';
|
|
9
9
|
const packageName = "@atlaskit/media-card";
|
|
10
|
-
const packageVersion = "77.4.
|
|
10
|
+
const packageVersion = "77.4.8";
|
|
11
11
|
export const CardV2Base = ({
|
|
12
12
|
identifier,
|
|
13
13
|
...otherProps
|
|
@@ -28,7 +28,6 @@ export const CardViewV2Base = ({
|
|
|
28
28
|
onImageLoad,
|
|
29
29
|
onImageError,
|
|
30
30
|
dimensions,
|
|
31
|
-
appearance = 'auto',
|
|
32
31
|
onClick,
|
|
33
32
|
onMouseEnter,
|
|
34
33
|
testId,
|
|
@@ -258,7 +257,6 @@ export const CardViewV2Base = ({
|
|
|
258
257
|
return jsx(Wrapper, {
|
|
259
258
|
testId: testId || 'media-card-view',
|
|
260
259
|
dimensions: dimensions,
|
|
261
|
-
appearance: appearance,
|
|
262
260
|
onClick: onClick,
|
|
263
261
|
onMouseEnter: onMouseEnter,
|
|
264
262
|
innerRef: divRef,
|
|
@@ -9,6 +9,7 @@ import { generateUniqueId } from '../../utils/generateUniqueId';
|
|
|
9
9
|
import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
|
|
10
10
|
import { abortUfoExperience, completeUfoExperience, startUfoExperience } from '../../utils/ufoExperiences';
|
|
11
11
|
import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
|
|
12
|
+
import { getDefaultCardDimensions } from '../../utils/cardDimensions';
|
|
12
13
|
import { usePrevious } from '../../utils/usePrevious';
|
|
13
14
|
import { fireCommencedEvent, fireCopiedEvent, fireOperationalEvent, fireScreenEvent } from '../cardAnalytics';
|
|
14
15
|
import { CardViewV2 } from './cardViewV2';
|
|
@@ -36,6 +37,7 @@ export const ExternalImageCard = ({
|
|
|
36
37
|
onMouseEnter,
|
|
37
38
|
createAnalyticsEvent
|
|
38
39
|
}) => {
|
|
40
|
+
const cardDimensions = dimensions || getDefaultCardDimensions(appearance);
|
|
39
41
|
const internalOccurrenceKey = useMemo(() => generateUniqueId(), []);
|
|
40
42
|
const timeElapsedTillCommenced = useMemo(() => performance.now(), []);
|
|
41
43
|
|
|
@@ -194,9 +196,8 @@ export const ExternalImageCard = ({
|
|
|
194
196
|
metadata: metadata,
|
|
195
197
|
cardPreview: cardPreview,
|
|
196
198
|
alt: alt,
|
|
197
|
-
appearance: appearance,
|
|
198
199
|
resizeMode: resizeMode,
|
|
199
|
-
dimensions:
|
|
200
|
+
dimensions: cardDimensions,
|
|
200
201
|
actions: actions,
|
|
201
202
|
selectable: selectable,
|
|
202
203
|
selected: selected,
|
|
@@ -235,7 +236,6 @@ export const ExternalImageCard = ({
|
|
|
235
236
|
},
|
|
236
237
|
innerRef: setCardElement,
|
|
237
238
|
testId: testId,
|
|
238
|
-
featureFlags: featureFlags,
|
|
239
239
|
titleBoxBgColor: titleBoxBgColor,
|
|
240
240
|
titleBoxIcon: titleBoxIcon,
|
|
241
241
|
onImageError: newCardPreview => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import DownloadIcon from '@atlaskit/icon/glyph/download';
|
|
2
|
-
import {
|
|
3
|
-
import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
|
|
2
|
+
import { globalMediaEventEmitter, isImageRepresentationReady, RECENTS_COLLECTION } from '@atlaskit/media-client';
|
|
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,
|
|
@@ -131,15 +136,13 @@ export const FileCard = ({
|
|
|
131
136
|
ssrReliabilityRef,
|
|
132
137
|
onImageError: onImageErrorBase,
|
|
133
138
|
onImageLoad: onImageLoadBase,
|
|
134
|
-
|
|
139
|
+
getScriptProps
|
|
135
140
|
} = useFilePreview({
|
|
136
141
|
mediaBlobUrlAttrs,
|
|
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,
|
|
@@ -551,5 +552,5 @@ export const FileCard = ({
|
|
|
551
552
|
},
|
|
552
553
|
contextId: contextId,
|
|
553
554
|
featureFlags: featureFlags
|
|
554
|
-
}), document.body) : null, ssr === 'server' && /*#__PURE__*/React.createElement(
|
|
555
|
+
}), document.body) : null, ssr === 'server' && /*#__PURE__*/React.createElement("script", getScriptProps()));
|
|
555
556
|
};
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { addFileAttrsToUrl, imageResizeModeToFileImageMode, isImageRepresentationReady } from '@atlaskit/media-client';
|
|
3
|
-
import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
|
|
2
|
+
import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
4
3
|
import { getMediaTypeFromMimeType, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
5
4
|
import { getOrientation } from '@atlaskit/media-ui';
|
|
6
5
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
7
|
-
import {
|
|
6
|
+
import { ensureMediaCardError, ImageLoadError, isLocalPreviewError, isUnsupportedLocalPreviewError, LocalPreviewError, MediaCardError } from '../../errors';
|
|
8
7
|
import { extractErrorInfo } from '../../utils/analytics';
|
|
9
8
|
import { isBigger } from '../../utils/dimensionComparer';
|
|
10
|
-
import {
|
|
9
|
+
import { isRetina } from '../../utils/isRetina';
|
|
10
|
+
import { generateScriptProps, getSSRData } from '../../utils/globalScope';
|
|
11
11
|
import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
|
|
12
12
|
import { usePrevious } from '../../utils/usePrevious';
|
|
13
13
|
import { takeSnapshot } from '../../utils/videoSnapshot';
|
|
14
14
|
import { fetchAndCacheRemotePreview, getCardPreviewFromCache, getSSRCardPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, removeCardPreviewFromCache, shouldResolvePreview } from '../getCardPreview';
|
|
15
15
|
import cardPreviewCache from '../getCardPreview/cache';
|
|
16
|
-
import { StoreSSRDataScript } from '../../utils/globalScope';
|
|
17
16
|
export const useFilePreview = ({
|
|
18
17
|
resizeMode = 'crop',
|
|
19
18
|
identifier,
|
|
20
19
|
ssr,
|
|
21
|
-
mediaClient,
|
|
22
20
|
dimensions,
|
|
23
|
-
requestedDimensions,
|
|
24
21
|
traceContext,
|
|
25
22
|
previewDidRender,
|
|
26
23
|
skipRemote,
|
|
27
24
|
mediaBlobUrlAttrs
|
|
28
25
|
}) => {
|
|
26
|
+
const mediaClient = useMediaClient();
|
|
29
27
|
const [error, setError] = useState();
|
|
30
28
|
const [nonCriticalError, setNonCriticalError] = useState();
|
|
29
|
+
const requestDimensions = useMemo(() => dimensions ? createRequestDimensions(dimensions) : undefined, [dimensions]);
|
|
30
|
+
|
|
31
31
|
//----------------------------------------------------------------//
|
|
32
32
|
//---------------- State Initializer Functions -------------------//
|
|
33
33
|
//----------------------------------------------------------------//
|
|
@@ -44,9 +44,9 @@ export const useFilePreview = ({
|
|
|
44
44
|
const imageURLParams = useMemo(() => ({
|
|
45
45
|
collection: identifier.collectionName,
|
|
46
46
|
mode: resizeMode === 'stretchy-fit' ? 'full-fit' : resizeMode,
|
|
47
|
-
...
|
|
47
|
+
...requestDimensions,
|
|
48
48
|
allowAnimated: true
|
|
49
|
-
}), [
|
|
49
|
+
}), [requestDimensions, identifier.collectionName, resizeMode]);
|
|
50
50
|
const getSSRPreview = (ssr, identifier, mediaClient) => {
|
|
51
51
|
var _ssrDataRef$current, _ssrDataRef$current2;
|
|
52
52
|
ssrDataRef.current = getSSRData(identifier);
|
|
@@ -66,8 +66,13 @@ export const useFilePreview = ({
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
} else {
|
|
69
|
+
const {
|
|
70
|
+
dimensions,
|
|
71
|
+
dataURI
|
|
72
|
+
} = ssrDataRef.current;
|
|
69
73
|
return {
|
|
70
|
-
dataURI
|
|
74
|
+
dataURI,
|
|
75
|
+
dimensions,
|
|
71
76
|
source: 'ssr-data'
|
|
72
77
|
};
|
|
73
78
|
}
|
|
@@ -109,7 +114,7 @@ export const useFilePreview = ({
|
|
|
109
114
|
//----------------------------------------------------------------//
|
|
110
115
|
|
|
111
116
|
const fetchRemotePreviewRef = useCurrentValueRef(identifier => {
|
|
112
|
-
return fetchAndCacheRemotePreview(mediaClient, identifier.id,
|
|
117
|
+
return fetchAndCacheRemotePreview(mediaClient, identifier.id, requestDimensions || {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
|
|
113
118
|
});
|
|
114
119
|
const resolvePreviewRef = useCurrentValueRef(async (identifier, fileState) => {
|
|
115
120
|
const filePreview = isBannedLocalPreview ? undefined : fileState.status !== 'error' && 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) ? fileState.preview : undefined;
|
|
@@ -117,7 +122,7 @@ export const useFilePreview = ({
|
|
|
117
122
|
try {
|
|
118
123
|
const mode = imageURLParams.mode;
|
|
119
124
|
const cachedPreview = cardPreviewCache.get(identifier.id, mode);
|
|
120
|
-
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);
|
|
121
126
|
if (cachedPreview && !dimensionsAreBigger) {
|
|
122
127
|
return cachedPreview;
|
|
123
128
|
}
|
|
@@ -176,7 +181,7 @@ export const useFilePreview = ({
|
|
|
176
181
|
}
|
|
177
182
|
const preview = {
|
|
178
183
|
...localPreview,
|
|
179
|
-
dimensions
|
|
184
|
+
dimensions: requestDimensions
|
|
180
185
|
};
|
|
181
186
|
let source;
|
|
182
187
|
switch (preview.source) {
|
|
@@ -241,7 +246,7 @@ export const useFilePreview = ({
|
|
|
241
246
|
*/
|
|
242
247
|
throw new MediaCardError('remote-preview-not-ready');
|
|
243
248
|
}
|
|
244
|
-
const remotePreview = await
|
|
249
|
+
const remotePreview = await fetchRemotePreviewRef.current(identifier);
|
|
245
250
|
setCardPreview(remotePreview);
|
|
246
251
|
return;
|
|
247
252
|
} catch (e) {
|
|
@@ -266,7 +271,7 @@ export const useFilePreview = ({
|
|
|
266
271
|
//------------ resolveUpfrontPreview useEffect -------------------//
|
|
267
272
|
//----------------------------------------------------------------//
|
|
268
273
|
const prevCardPreview = usePrevious(cardPreview);
|
|
269
|
-
const
|
|
274
|
+
const requestDimensionsRef = useCurrentValueRef(requestDimensions);
|
|
270
275
|
useEffect(() => {
|
|
271
276
|
const resolveUpfrontPreview = async identifier => {
|
|
272
277
|
// We block any possible future call to this method regardless of the outcome (success or fail)
|
|
@@ -274,10 +279,10 @@ export const useFilePreview = ({
|
|
|
274
279
|
wasResolvedUpfrontPreviewRef.current = true;
|
|
275
280
|
try {
|
|
276
281
|
const fetchedDimensions = {
|
|
277
|
-
...
|
|
282
|
+
...requestDimensions
|
|
278
283
|
};
|
|
279
284
|
const newCardPreview = await fetchRemotePreviewRef.current(identifier);
|
|
280
|
-
const areValidFetchedDimensions = !isBigger(fetchedDimensions,
|
|
285
|
+
const areValidFetchedDimensions = !isBigger(fetchedDimensions, requestDimensionsRef.current);
|
|
281
286
|
|
|
282
287
|
// If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
|
|
283
288
|
// the fetched preview is no longer valid, and thus, we dismiss it
|
|
@@ -294,16 +299,16 @@ export const useFilePreview = ({
|
|
|
294
299
|
if (!wasResolvedUpfrontPreviewRef.current && (!skipRemote || hadSSRCardPreview) && !cardPreview) {
|
|
295
300
|
resolveUpfrontPreview(identifier);
|
|
296
301
|
}
|
|
297
|
-
}, [cardPreview,
|
|
302
|
+
}, [cardPreview, requestDimensions, requestDimensionsRef, fetchRemotePreviewRef, identifier, skipRemote, prevCardPreview, ssr]);
|
|
298
303
|
|
|
299
304
|
//----------------------------------------------------------------//
|
|
300
305
|
//---------------- fetch and resolve card preview ----------------//
|
|
301
306
|
//----------------------------------------------------------------//
|
|
302
307
|
|
|
303
|
-
const
|
|
308
|
+
const prevRequestDimensions = usePrevious(requestDimensions);
|
|
304
309
|
useEffect(() => {
|
|
305
|
-
|
|
306
|
-
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)) {
|
|
307
312
|
// refetchSRRPreview: If dimensions from Server have changed and are bigger,
|
|
308
313
|
// we need to refetch
|
|
309
314
|
fetchRemotePreviewRef.current(identifier).then(setCardPreview).catch(e => {
|
|
@@ -318,8 +323,8 @@ export const useFilePreview = ({
|
|
|
318
323
|
if (fileState && shouldResolvePreview({
|
|
319
324
|
status,
|
|
320
325
|
fileState: fileState,
|
|
321
|
-
prevDimensions,
|
|
322
|
-
dimensions,
|
|
326
|
+
prevDimensions: prevRequestDimensions,
|
|
327
|
+
dimensions: requestDimensions,
|
|
323
328
|
hasCardPreview: !!cardPreview,
|
|
324
329
|
isBannedLocalPreview,
|
|
325
330
|
wasResolvedUpfrontPreview: wasResolvedUpfrontPreviewRef.current
|
|
@@ -336,7 +341,7 @@ export const useFilePreview = ({
|
|
|
336
341
|
// https://product-fabric.atlassian.net/browse/MEX-1071
|
|
337
342
|
});
|
|
338
343
|
}
|
|
339
|
-
}, [cardPreview,
|
|
344
|
+
}, [cardPreview, requestDimensions, fetchRemotePreviewRef, fileState, identifier, isBannedLocalPreview, prevRequestDimensions, resolvePreviewRef, skipRemote, ssr, status]);
|
|
340
345
|
|
|
341
346
|
//----------------------------------------------------------------//
|
|
342
347
|
//----------------- set complete status --------------------------//
|
|
@@ -475,14 +480,10 @@ export const useFilePreview = ({
|
|
|
475
480
|
// RETURN
|
|
476
481
|
//----------------------------------------------------------------//
|
|
477
482
|
|
|
478
|
-
|
|
483
|
+
// FOR SSR
|
|
484
|
+
const getScriptProps = () => {
|
|
479
485
|
var _ssrReliabilityRef$cu;
|
|
480
|
-
return
|
|
481
|
-
identifier: identifier,
|
|
482
|
-
dataURI: cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI,
|
|
483
|
-
dimensions: requestedDimensions,
|
|
484
|
-
error: ((_ssrReliabilityRef$cu = ssrReliabilityRef.current.server) === null || _ssrReliabilityRef$cu === void 0 ? void 0 : _ssrReliabilityRef$cu.status) === 'fail' ? ssrReliabilityRef.current.server : undefined
|
|
485
|
-
});
|
|
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);
|
|
486
487
|
};
|
|
487
488
|
|
|
488
489
|
// CXP-2723 TODO: should consider simplifying our analytics, and how
|
|
@@ -494,6 +495,24 @@ export const useFilePreview = ({
|
|
|
494
495
|
ssrReliabilityRef,
|
|
495
496
|
onImageError,
|
|
496
497
|
onImageLoad,
|
|
497
|
-
|
|
498
|
+
getScriptProps
|
|
498
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;
|
|
499
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
|
};
|
|
@@ -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
|
|
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 {
|
|
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.
|
|
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
|
@@ -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 {
|
|
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.
|
|
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);
|
|
@@ -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) &&
|
|
606
|
-
|
|
607
|
-
|
|
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({
|
|
@@ -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,
|