@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
|
@@ -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) {
|
|
@@ -4,8 +4,8 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
4
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
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
|
-
import {
|
|
8
|
-
import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
|
|
7
|
+
import { globalMediaEventEmitter, isImageRepresentationReady, RECENTS_COLLECTION } from '@atlaskit/media-client';
|
|
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
|
|
@@ -176,7 +179,7 @@ export var FileCard = function FileCard(_ref) {
|
|
|
176
179
|
ssrReliabilityRef = _useFilePreview.ssrReliabilityRef,
|
|
177
180
|
onImageErrorBase = _useFilePreview.onImageError,
|
|
178
181
|
onImageLoadBase = _useFilePreview.onImageLoad,
|
|
179
|
-
|
|
182
|
+
getScriptProps = _useFilePreview.getScriptProps;
|
|
180
183
|
var _useState15 = useState(),
|
|
181
184
|
_useState16 = _slicedToArray(_useState15, 2),
|
|
182
185
|
error = _useState16[0],
|
|
@@ -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,
|
|
@@ -591,5 +592,5 @@ export var FileCard = function FileCard(_ref) {
|
|
|
591
592
|
},
|
|
592
593
|
contextId: contextId,
|
|
593
594
|
featureFlags: featureFlags
|
|
594
|
-
}), document.body) : null, ssr === 'server' && /*#__PURE__*/React.createElement(
|
|
595
|
+
}), document.body) : null, ssr === 'server' && /*#__PURE__*/React.createElement("script", getScriptProps()));
|
|
595
596
|
};
|
|
@@ -4,34 +4,32 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
6
|
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; }
|
|
7
|
-
import React from 'react';
|
|
8
7
|
import { addFileAttrsToUrl, imageResizeModeToFileImageMode, isImageRepresentationReady } from '@atlaskit/media-client';
|
|
9
|
-
import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
|
|
8
|
+
import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
10
9
|
import { getMediaTypeFromMimeType, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
11
10
|
import { getOrientation } from '@atlaskit/media-ui';
|
|
12
11
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
13
|
-
import {
|
|
12
|
+
import { ensureMediaCardError, ImageLoadError, isLocalPreviewError, isUnsupportedLocalPreviewError, LocalPreviewError, MediaCardError } from '../../errors';
|
|
14
13
|
import { extractErrorInfo } from '../../utils/analytics';
|
|
15
14
|
import { isBigger } from '../../utils/dimensionComparer';
|
|
16
|
-
import {
|
|
15
|
+
import { isRetina } from '../../utils/isRetina';
|
|
16
|
+
import { generateScriptProps, getSSRData } from '../../utils/globalScope';
|
|
17
17
|
import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
|
|
18
18
|
import { usePrevious } from '../../utils/usePrevious';
|
|
19
19
|
import { takeSnapshot } from '../../utils/videoSnapshot';
|
|
20
20
|
import { fetchAndCacheRemotePreview, getCardPreviewFromCache, getSSRCardPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, removeCardPreviewFromCache, shouldResolvePreview } from '../getCardPreview';
|
|
21
21
|
import cardPreviewCache from '../getCardPreview/cache';
|
|
22
|
-
import { StoreSSRDataScript } from '../../utils/globalScope';
|
|
23
22
|
export var useFilePreview = function useFilePreview(_ref) {
|
|
24
23
|
var _ref$resizeMode = _ref.resizeMode,
|
|
25
24
|
resizeMode = _ref$resizeMode === void 0 ? 'crop' : _ref$resizeMode,
|
|
26
25
|
identifier = _ref.identifier,
|
|
27
26
|
ssr = _ref.ssr,
|
|
28
|
-
mediaClient = _ref.mediaClient,
|
|
29
27
|
dimensions = _ref.dimensions,
|
|
30
|
-
requestedDimensions = _ref.requestedDimensions,
|
|
31
28
|
traceContext = _ref.traceContext,
|
|
32
29
|
previewDidRender = _ref.previewDidRender,
|
|
33
30
|
skipRemote = _ref.skipRemote,
|
|
34
31
|
mediaBlobUrlAttrs = _ref.mediaBlobUrlAttrs;
|
|
32
|
+
var mediaClient = useMediaClient();
|
|
35
33
|
var _useState = useState(),
|
|
36
34
|
_useState2 = _slicedToArray(_useState, 2),
|
|
37
35
|
error = _useState2[0],
|
|
@@ -40,6 +38,10 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
40
38
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
41
39
|
nonCriticalError = _useState4[0],
|
|
42
40
|
setNonCriticalError = _useState4[1];
|
|
41
|
+
var requestDimensions = useMemo(function () {
|
|
42
|
+
return dimensions ? createRequestDimensions(dimensions) : undefined;
|
|
43
|
+
}, [dimensions]);
|
|
44
|
+
|
|
43
45
|
//----------------------------------------------------------------//
|
|
44
46
|
//---------------- State Initializer Functions -------------------//
|
|
45
47
|
//----------------------------------------------------------------//
|
|
@@ -57,10 +59,10 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
57
59
|
return _objectSpread(_objectSpread({
|
|
58
60
|
collection: identifier.collectionName,
|
|
59
61
|
mode: resizeMode === 'stretchy-fit' ? 'full-fit' : resizeMode
|
|
60
|
-
},
|
|
62
|
+
}, requestDimensions), {}, {
|
|
61
63
|
allowAnimated: true
|
|
62
64
|
});
|
|
63
|
-
}, [
|
|
65
|
+
}, [requestDimensions, identifier.collectionName, resizeMode]);
|
|
64
66
|
var getSSRPreview = function getSSRPreview(ssr, identifier, mediaClient) {
|
|
65
67
|
var _ssrDataRef$current, _ssrDataRef$current2;
|
|
66
68
|
ssrDataRef.current = getSSRData(identifier);
|
|
@@ -78,8 +80,12 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
78
80
|
}, extractErrorInfo(e));
|
|
79
81
|
}
|
|
80
82
|
} else {
|
|
83
|
+
var _ssrDataRef$current3 = ssrDataRef.current,
|
|
84
|
+
_dimensions = _ssrDataRef$current3.dimensions,
|
|
85
|
+
dataURI = _ssrDataRef$current3.dataURI;
|
|
81
86
|
return {
|
|
82
|
-
dataURI:
|
|
87
|
+
dataURI: dataURI,
|
|
88
|
+
dimensions: _dimensions,
|
|
83
89
|
source: 'ssr-data'
|
|
84
90
|
};
|
|
85
91
|
}
|
|
@@ -127,7 +133,7 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
127
133
|
//----------------------------------------------------------------//
|
|
128
134
|
|
|
129
135
|
var fetchRemotePreviewRef = useCurrentValueRef(function (identifier) {
|
|
130
|
-
return fetchAndCacheRemotePreview(mediaClient, identifier.id,
|
|
136
|
+
return fetchAndCacheRemotePreview(mediaClient, identifier.id, requestDimensions || {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
|
|
131
137
|
});
|
|
132
138
|
var resolvePreviewRef = useCurrentValueRef( /*#__PURE__*/function () {
|
|
133
139
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(identifier, fileState) {
|
|
@@ -140,7 +146,7 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
140
146
|
_context.prev = 2;
|
|
141
147
|
mode = imageURLParams.mode;
|
|
142
148
|
cachedPreview = cardPreviewCache.get(identifier.id, mode);
|
|
143
|
-
dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions,
|
|
149
|
+
dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, requestDimensions);
|
|
144
150
|
if (!(cachedPreview && !dimensionsAreBigger)) {
|
|
145
151
|
_context.next = 8;
|
|
146
152
|
break;
|
|
@@ -234,7 +240,7 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
234
240
|
throw new LocalPreviewError('local-preview-unsupported');
|
|
235
241
|
case 57:
|
|
236
242
|
preview = _objectSpread(_objectSpread({}, localPreview), {}, {
|
|
237
|
-
dimensions:
|
|
243
|
+
dimensions: requestDimensions
|
|
238
244
|
});
|
|
239
245
|
_context.t4 = preview.source;
|
|
240
246
|
_context.next = _context.t4 === 'local' ? 61 : _context.t4 === 'remote' ? 63 : _context.t4 === 'ssr-server' ? 65 : _context.t4 === 'ssr-client' ? 67 : 69;
|
|
@@ -301,7 +307,7 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
301
307
|
throw new MediaCardError('remote-preview-not-ready');
|
|
302
308
|
case 83:
|
|
303
309
|
_context.next = 85;
|
|
304
|
-
return
|
|
310
|
+
return fetchRemotePreviewRef.current(identifier);
|
|
305
311
|
case 85:
|
|
306
312
|
remotePreview = _context.sent;
|
|
307
313
|
setCardPreview(remotePreview);
|
|
@@ -337,7 +343,7 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
337
343
|
//------------ resolveUpfrontPreview useEffect -------------------//
|
|
338
344
|
//----------------------------------------------------------------//
|
|
339
345
|
var prevCardPreview = usePrevious(cardPreview);
|
|
340
|
-
var
|
|
346
|
+
var requestDimensionsRef = useCurrentValueRef(requestDimensions);
|
|
341
347
|
useEffect(function () {
|
|
342
348
|
var resolveUpfrontPreview = /*#__PURE__*/function () {
|
|
343
349
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(identifier) {
|
|
@@ -349,12 +355,12 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
349
355
|
// If it fails, the normal preview fetch should occur after the file state is fetched anyways
|
|
350
356
|
wasResolvedUpfrontPreviewRef.current = true;
|
|
351
357
|
_context2.prev = 1;
|
|
352
|
-
fetchedDimensions = _objectSpread({},
|
|
358
|
+
fetchedDimensions = _objectSpread({}, requestDimensions);
|
|
353
359
|
_context2.next = 5;
|
|
354
360
|
return fetchRemotePreviewRef.current(identifier);
|
|
355
361
|
case 5:
|
|
356
362
|
newCardPreview = _context2.sent;
|
|
357
|
-
areValidFetchedDimensions = !isBigger(fetchedDimensions,
|
|
363
|
+
areValidFetchedDimensions = !isBigger(fetchedDimensions, requestDimensionsRef.current); // If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
|
|
358
364
|
// the fetched preview is no longer valid, and thus, we dismiss it
|
|
359
365
|
if (areValidFetchedDimensions) {
|
|
360
366
|
setCardPreview(newCardPreview);
|
|
@@ -380,16 +386,16 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
380
386
|
if (!wasResolvedUpfrontPreviewRef.current && (!skipRemote || hadSSRCardPreview) && !cardPreview) {
|
|
381
387
|
resolveUpfrontPreview(identifier);
|
|
382
388
|
}
|
|
383
|
-
}, [cardPreview,
|
|
389
|
+
}, [cardPreview, requestDimensions, requestDimensionsRef, fetchRemotePreviewRef, identifier, skipRemote, prevCardPreview, ssr]);
|
|
384
390
|
|
|
385
391
|
//----------------------------------------------------------------//
|
|
386
392
|
//---------------- fetch and resolve card preview ----------------//
|
|
387
393
|
//----------------------------------------------------------------//
|
|
388
394
|
|
|
389
|
-
var
|
|
395
|
+
var prevRequestDimensions = usePrevious(requestDimensions);
|
|
390
396
|
useEffect(function () {
|
|
391
|
-
|
|
392
|
-
if (cardPreview && !skipRemote && isSSRDataPreview(cardPreview) && isBigger(
|
|
397
|
+
// CXP-2813 TODO: This is called too many times if the refetch failed. Should be called only once
|
|
398
|
+
if (cardPreview && !skipRemote && isSSRDataPreview(cardPreview) && isBigger(cardPreview.dimensions, requestDimensions)) {
|
|
393
399
|
// refetchSRRPreview: If dimensions from Server have changed and are bigger,
|
|
394
400
|
// we need to refetch
|
|
395
401
|
fetchRemotePreviewRef.current(identifier).then(setCardPreview).catch(function (e) {
|
|
@@ -404,8 +410,8 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
404
410
|
if (fileState && shouldResolvePreview({
|
|
405
411
|
status: status,
|
|
406
412
|
fileState: fileState,
|
|
407
|
-
prevDimensions:
|
|
408
|
-
dimensions:
|
|
413
|
+
prevDimensions: prevRequestDimensions,
|
|
414
|
+
dimensions: requestDimensions,
|
|
409
415
|
hasCardPreview: !!cardPreview,
|
|
410
416
|
isBannedLocalPreview: isBannedLocalPreview,
|
|
411
417
|
wasResolvedUpfrontPreview: wasResolvedUpfrontPreviewRef.current
|
|
@@ -422,7 +428,7 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
422
428
|
// https://product-fabric.atlassian.net/browse/MEX-1071
|
|
423
429
|
});
|
|
424
430
|
}
|
|
425
|
-
}, [cardPreview,
|
|
431
|
+
}, [cardPreview, requestDimensions, fetchRemotePreviewRef, fileState, identifier, isBannedLocalPreview, prevRequestDimensions, resolvePreviewRef, skipRemote, ssr, status]);
|
|
426
432
|
|
|
427
433
|
//----------------------------------------------------------------//
|
|
428
434
|
//----------------- set complete status --------------------------//
|
|
@@ -560,14 +566,10 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
560
566
|
// RETURN
|
|
561
567
|
//----------------------------------------------------------------//
|
|
562
568
|
|
|
563
|
-
|
|
569
|
+
// FOR SSR
|
|
570
|
+
var getScriptProps = function getScriptProps() {
|
|
564
571
|
var _ssrReliabilityRef$cu;
|
|
565
|
-
return
|
|
566
|
-
identifier: identifier,
|
|
567
|
-
dataURI: cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI,
|
|
568
|
-
dimensions: requestedDimensions,
|
|
569
|
-
error: ((_ssrReliabilityRef$cu = ssrReliabilityRef.current.server) === null || _ssrReliabilityRef$cu === void 0 ? void 0 : _ssrReliabilityRef$cu.status) === 'fail' ? ssrReliabilityRef.current.server : undefined
|
|
570
|
-
});
|
|
572
|
+
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);
|
|
571
573
|
};
|
|
572
574
|
|
|
573
575
|
// CXP-2723 TODO: should consider simplifying our analytics, and how
|
|
@@ -579,6 +581,22 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
579
581
|
ssrReliabilityRef: ssrReliabilityRef,
|
|
580
582
|
onImageError: onImageError,
|
|
581
583
|
onImageLoad: onImageLoad,
|
|
582
|
-
|
|
584
|
+
getScriptProps: getScriptProps
|
|
583
585
|
};
|
|
586
|
+
};
|
|
587
|
+
var createRequestDimensions = function createRequestDimensions(dimensions) {
|
|
588
|
+
if (!dimensions) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
var retinaFactor = isRetina() ? 2 : 1;
|
|
592
|
+
var width = dimensions.width,
|
|
593
|
+
height = dimensions.height;
|
|
594
|
+
var result = {};
|
|
595
|
+
if (width) {
|
|
596
|
+
result.width = width * retinaFactor;
|
|
597
|
+
}
|
|
598
|
+
if (height) {
|
|
599
|
+
result.height = height * retinaFactor;
|
|
600
|
+
}
|
|
601
|
+
return result;
|
|
584
602
|
};
|
|
@@ -103,7 +103,7 @@ var MediaInlineCardLoader = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
103
103
|
ErrorBoundary = _this$state.ErrorBoundary;
|
|
104
104
|
var analyticsContext = {
|
|
105
105
|
packageVersion: "@atlaskit/media-card",
|
|
106
|
-
packageName: "77.4.
|
|
106
|
+
packageName: "77.4.8",
|
|
107
107
|
componentName: 'mediaInlineCard',
|
|
108
108
|
component: 'mediaInlineCard'
|
|
109
109
|
};
|
|
@@ -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 var getDataURIDimension = function getDataURIDimension(dimension, options) {
|
|
7
14
|
var retinaFactor = isRetina() ? 2 : 1;
|
|
8
15
|
var dimensionValue = options.dimensions && options.dimensions[dimension] || '';
|
|
@@ -24,4 +31,35 @@ export var getRequestedDimensions = function getRequestedDimensions(options) {
|
|
|
24
31
|
width: width,
|
|
25
32
|
height: height
|
|
26
33
|
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* ************************************************
|
|
38
|
+
* For Card v2
|
|
39
|
+
* ************************************************
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
// Same as getDataURIDimension but without Retina factor
|
|
43
|
+
export var resolveCardPreviewDimension = function resolveCardPreviewDimension(dimensionName, _ref) {
|
|
44
|
+
var dimensions = _ref.dimensions,
|
|
45
|
+
element = _ref.element;
|
|
46
|
+
var dimensionValue = (dimensions === null || dimensions === void 0 ? void 0 : dimensions[dimensionName]) || '';
|
|
47
|
+
if (isValidPercentageUnit(dimensionValue) && element) {
|
|
48
|
+
return getElementDimension(element, dimensionName);
|
|
49
|
+
}
|
|
50
|
+
if (typeof dimensionValue === 'number') {
|
|
51
|
+
return dimensionValue;
|
|
52
|
+
}
|
|
53
|
+
if (containsPixelUnit("".concat(dimensionValue))) {
|
|
54
|
+
return parseInt("".concat(dimensionValue), 10);
|
|
55
|
+
}
|
|
56
|
+
return defaultImageCardDimensions[dimensionName];
|
|
57
|
+
};
|
|
58
|
+
export var resolveCardPreviewDimensions = function resolveCardPreviewDimensions(options) {
|
|
59
|
+
var width = resolveCardPreviewDimension('width', options);
|
|
60
|
+
var height = resolveCardPreviewDimension('height', options);
|
|
61
|
+
return {
|
|
62
|
+
width: width,
|
|
63
|
+
height: height
|
|
64
|
+
};
|
|
27
65
|
};
|
|
@@ -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.
|
|
@@ -48,14 +47,10 @@ var generateScript = function generateScript(identifier, dataURI, dimensions, er
|
|
|
48
47
|
var functionCall = printFunctionCall(storeDataURI, getKey(identifier), dataURI, dimensions, error);
|
|
49
48
|
return printScript([getMediaCardSSR.toString(), getMediaGlobalScope.toString(), functionCall]);
|
|
50
49
|
};
|
|
51
|
-
export var
|
|
52
|
-
|
|
53
|
-
identifier = _ref2.identifier,
|
|
54
|
-
dimensions = _ref2.dimensions,
|
|
55
|
-
error = _ref2.error;
|
|
56
|
-
return /*#__PURE__*/React.createElement("script", {
|
|
50
|
+
export var generateScriptProps = function generateScriptProps(identifier, dataURI, dimensions, error) {
|
|
51
|
+
return {
|
|
57
52
|
dangerouslySetInnerHTML: {
|
|
58
53
|
__html: generateScript(identifier, dataURI, dimensions, error)
|
|
59
54
|
}
|
|
60
|
-
}
|
|
55
|
+
};
|
|
61
56
|
};
|
|
@@ -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';
|
|
@@ -7,7 +7,7 @@ import { extractErrorInfo, getRenderErrorRequestMetadata } from './analytics';
|
|
|
7
7
|
import { MediaCardError } from '../errors';
|
|
8
8
|
import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
|
|
9
9
|
var packageName = "@atlaskit/media-card";
|
|
10
|
-
var packageVersion = "77.4.
|
|
10
|
+
var packageVersion = "77.4.8";
|
|
11
11
|
var concurrentExperience;
|
|
12
12
|
var getExperience = function getExperience(id) {
|
|
13
13
|
if (!concurrentExperience) {
|
|
@@ -2,11 +2,22 @@
|
|
|
2
2
|
import { jsx } from '@emotion/react';
|
|
3
3
|
import React, { MouseEvent } from 'react';
|
|
4
4
|
import { MessageDescriptor } from 'react-intl-next';
|
|
5
|
-
import { MediaItemType, FileDetails } from '@atlaskit/media-client';
|
|
5
|
+
import { MediaItemType, FileDetails, ImageResizeMode } from '@atlaskit/media-client';
|
|
6
6
|
import { WithAnalyticsEventsProps, UIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
7
|
-
import {
|
|
7
|
+
import { CardStatus, CardPreview, MediaCardCursor, CardDimensions, TitleBoxIcon } from '../../types';
|
|
8
|
+
import { CardAction } from '../actions';
|
|
8
9
|
import { MediaCardError } from '../../errors';
|
|
9
|
-
export interface
|
|
10
|
+
export interface CardViewV2Props {
|
|
11
|
+
readonly disableOverlay?: boolean;
|
|
12
|
+
readonly resizeMode?: ImageResizeMode;
|
|
13
|
+
readonly dimensions: CardDimensions;
|
|
14
|
+
readonly actions?: Array<CardAction>;
|
|
15
|
+
readonly selectable?: boolean;
|
|
16
|
+
readonly selected?: boolean;
|
|
17
|
+
readonly alt?: string;
|
|
18
|
+
readonly testId?: string;
|
|
19
|
+
readonly titleBoxBgColor?: string;
|
|
20
|
+
readonly titleBoxIcon?: TitleBoxIcon;
|
|
10
21
|
readonly status: CardStatus;
|
|
11
22
|
readonly mediaItemType: MediaItemType;
|
|
12
23
|
readonly mediaCardCursor?: MediaCardCursor;
|
|
@@ -25,7 +36,7 @@ export interface CardViewV2OwnProps extends SharedCardProps {
|
|
|
25
36
|
disableAnimation?: boolean;
|
|
26
37
|
shouldHideTooltip?: boolean;
|
|
27
38
|
}
|
|
28
|
-
export type
|
|
39
|
+
export type CardViewV2BaseProps = CardViewV2Props & WithAnalyticsEventsProps;
|
|
29
40
|
export interface RenderConfigByStatusV2 {
|
|
30
41
|
renderTypeIcon?: boolean;
|
|
31
42
|
iconMessage?: JSX.Element;
|
|
@@ -40,5 +51,5 @@ export interface RenderConfigByStatusV2 {
|
|
|
40
51
|
renderTickBox?: boolean;
|
|
41
52
|
customTitleMessage?: MessageDescriptor;
|
|
42
53
|
}
|
|
43
|
-
export declare const CardViewV2Base: ({ innerRef, onImageLoad, onImageError, dimensions,
|
|
44
|
-
export declare const CardViewV2: React.ForwardRefExoticComponent<Omit<
|
|
54
|
+
export declare const CardViewV2Base: ({ innerRef, onImageLoad, onImageError, dimensions, onClick, onMouseEnter, testId, metadata, status, selected, selectable, cardPreview, mediaCardCursor, shouldHideTooltip, progress, alt, resizeMode, onDisplayImage, nativeLazyLoad, forceSyncDisplay, actions, disableOverlay, titleBoxBgColor, titleBoxIcon, error, disableAnimation, }: CardViewV2BaseProps) => jsx.JSX.Element;
|
|
55
|
+
export declare const CardViewV2: React.ForwardRefExoticComponent<Omit<CardViewV2BaseProps, keyof WithAnalyticsEventsProps> & React.RefAttributes<any>>;
|
|
@@ -1,19 +1,53 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
|
|
3
|
-
import { FileIdentifier, Identifier,
|
|
4
|
-
import { SSR } from '@atlaskit/media-common';
|
|
5
|
-
import { CardEventProps,
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { FileIdentifier, Identifier, ImageResizeMode } from '@atlaskit/media-client';
|
|
4
|
+
import { MediaFeatureFlags, NumericalCardDimensions, SSR } from '@atlaskit/media-common';
|
|
5
|
+
import { CardAppearance, CardDimensions, CardEventProps, TitleBoxIcon } from '../../types';
|
|
6
|
+
import { CardAction } from '../actions';
|
|
7
|
+
export interface FileCardProps extends CardEventProps {
|
|
8
|
+
/** Overlay the media file. */
|
|
9
|
+
readonly disableOverlay?: boolean;
|
|
10
|
+
/** Resize the media to 'crop' | 'fit' | 'full-fit' | 'stretchy-fit'. */
|
|
11
|
+
readonly resizeMode?: ImageResizeMode;
|
|
12
|
+
readonly featureFlags?: MediaFeatureFlags;
|
|
13
|
+
/** Sets meida card appearance */
|
|
14
|
+
readonly appearance?: CardAppearance;
|
|
15
|
+
/** Custom media card dimension like width and height. */
|
|
16
|
+
readonly dimensions?: CardDimensions;
|
|
17
|
+
/** Original media card dimension like width and height. */
|
|
18
|
+
readonly originalDimensions?: NumericalCardDimensions;
|
|
19
|
+
/** Array of additional media card actions. */
|
|
20
|
+
readonly actions?: Array<CardAction>;
|
|
21
|
+
/** Enable media card selectable. */
|
|
22
|
+
readonly selectable?: boolean;
|
|
23
|
+
/** Renders media card as selected, if selected is true. */
|
|
24
|
+
readonly selected?: boolean;
|
|
25
|
+
/** Alternate text for an media card. */
|
|
26
|
+
readonly alt?: string;
|
|
27
|
+
/** ID for testing the media card. */
|
|
28
|
+
readonly testId?: string;
|
|
29
|
+
/** Sets the title box background color. */
|
|
30
|
+
readonly titleBoxBgColor?: string;
|
|
31
|
+
/** Sets the title box icon. */
|
|
32
|
+
readonly titleBoxIcon?: TitleBoxIcon;
|
|
33
|
+
/** Instance of file identifier. */
|
|
8
34
|
readonly identifier: FileIdentifier;
|
|
35
|
+
/** Lazy loads the media file. */
|
|
9
36
|
readonly isLazy?: boolean;
|
|
37
|
+
/** Uses the inline player for media file. */
|
|
10
38
|
readonly useInlinePlayer?: boolean;
|
|
39
|
+
/** Uses media MediaViewer to preview the media file. */
|
|
11
40
|
readonly shouldOpenMediaViewer?: boolean;
|
|
41
|
+
/** Media file list to display in Media Viewer. */
|
|
12
42
|
readonly mediaViewerItems?: Identifier[];
|
|
43
|
+
/** Retrieve auth based on a given context. */
|
|
13
44
|
readonly contextId?: string;
|
|
45
|
+
/** Enables the download button for media file. */
|
|
14
46
|
readonly shouldEnableDownloadButton?: boolean;
|
|
47
|
+
/** Server-Side-Rendering modes are "server" and "client" */
|
|
15
48
|
readonly ssr?: SSR;
|
|
49
|
+
/** Disable tooltip for the card */
|
|
16
50
|
readonly shouldHideTooltip?: boolean;
|
|
17
51
|
}
|
|
18
52
|
export type FileCardBaseProps = FileCardProps & WithAnalyticsEventsProps;
|
|
19
|
-
export declare const FileCard: ({ appearance, resizeMode, isLazy, disableOverlay, featureFlags, identifier, ssr,
|
|
53
|
+
export declare const FileCard: ({ appearance, resizeMode, isLazy, disableOverlay, featureFlags, identifier, ssr, dimensions, originalDimensions, contextId, alt, actions, shouldEnableDownloadButton, useInlinePlayer, shouldOpenMediaViewer, onFullscreenChange, selectable, selected, testId, titleBoxBgColor, titleBoxIcon, shouldHideTooltip, mediaViewerItems, onClick, onMouseEnter, createAnalyticsEvent, }: FileCardBaseProps) => JSX.Element;
|