@atlaskit/media-card 77.6.3 → 77.6.5
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 +12 -0
- package/dist/cjs/card/card.js +1 -1
- package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/cjs/card/v2/cardV2.js +1 -1
- package/dist/cjs/card/v2/fileCard.js +6 -2
- package/dist/cjs/card/v2/useFilePreview/getPreview/index.js +8 -14
- package/dist/cjs/card/v2/useFilePreview/helpers.js +0 -8
- package/dist/cjs/card/v2/useFilePreview/useFilePreview.js +45 -150
- package/dist/cjs/inline/loader.js +1 -1
- package/dist/cjs/inline/mediaInlineCard.js +7 -7
- package/dist/cjs/utils/ufoExperiences.js +1 -1
- package/dist/es2019/card/card.js +1 -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/fileCard.js +6 -2
- package/dist/es2019/card/v2/useFilePreview/getPreview/index.js +2 -2
- package/dist/es2019/card/v2/useFilePreview/helpers.js +1 -8
- package/dist/es2019/card/v2/useFilePreview/useFilePreview.js +39 -96
- package/dist/es2019/inline/loader.js +1 -1
- package/dist/es2019/inline/mediaInlineCard.js +8 -8
- package/dist/es2019/utils/ufoExperiences.js +1 -1
- package/dist/esm/card/card.js +1 -1
- package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
- package/dist/esm/card/v2/cardV2.js +1 -1
- package/dist/esm/card/v2/fileCard.js +6 -2
- package/dist/esm/card/v2/useFilePreview/getPreview/index.js +2 -2
- package/dist/esm/card/v2/useFilePreview/helpers.js +1 -8
- package/dist/esm/card/v2/useFilePreview/useFilePreview.js +48 -153
- package/dist/esm/inline/loader.js +1 -1
- package/dist/esm/inline/mediaInlineCard.js +8 -8
- package/dist/esm/utils/ufoExperiences.js +1 -1
- package/dist/types/card/v2/useFilePreview/getPreview/index.d.ts +1 -1
- package/dist/types/card/v2/useFilePreview/helpers.d.ts +0 -1
- package/dist/types/card/v2/useFilePreview/types.d.ts +0 -6
- package/dist/types/inline/mediaInlineCard.d.ts +1 -1
- package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/index.d.ts +1 -1
- package/dist/types-ts4.5/card/v2/useFilePreview/helpers.d.ts +0 -1
- package/dist/types-ts4.5/card/v2/useFilePreview/types.d.ts +0 -6
- package/dist/types-ts4.5/inline/mediaInlineCard.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/card/v2/useFilePreview/getPreview/filePreviewStatus.js +0 -45
- package/dist/es2019/card/v2/useFilePreview/getPreview/filePreviewStatus.js +0 -43
- package/dist/esm/card/v2/useFilePreview/getPreview/filePreviewStatus.js +0 -40
- package/dist/types/card/v2/useFilePreview/getPreview/filePreviewStatus.d.ts +0 -4
- package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/filePreviewStatus.d.ts +0 -4
|
@@ -2,11 +2,11 @@ import { imageResizeModeToFileImageMode, isImageRepresentationReady } from '@atl
|
|
|
2
2
|
import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
3
3
|
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
4
4
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
-
import { ensureMediaFilePreviewError, ImageLoadError,
|
|
5
|
+
import { ensureMediaFilePreviewError, ImageLoadError, MediaFilePreviewError } from './errors';
|
|
6
6
|
import { extractErrorInfo } from './analytics';
|
|
7
|
-
import { isBigger, createRequestDimensions, useCurrentValueRef
|
|
7
|
+
import { isBigger, createRequestDimensions, useCurrentValueRef } from './helpers';
|
|
8
8
|
import { generateScriptProps, getSSRData } from './globalScope';
|
|
9
|
-
import { getAndCacheRemotePreview, getSSRPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview,
|
|
9
|
+
import { getAndCacheRemotePreview, getSSRPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, mediaFilePreviewCache, getAndCacheLocalPreview, isSupportedLocalPreview } from './getPreview';
|
|
10
10
|
export const useFilePreview = ({
|
|
11
11
|
resizeMode = 'crop',
|
|
12
12
|
identifier,
|
|
@@ -26,7 +26,6 @@ export const useFilePreview = ({
|
|
|
26
26
|
const ssrReliabilityRef = useRef(initialSsrReliability);
|
|
27
27
|
const requestDimensions = useMemo(() => dimensions ? createRequestDimensions(dimensions) : undefined, [dimensions]);
|
|
28
28
|
const requestDimensionsRef = useCurrentValueRef(requestDimensions);
|
|
29
|
-
const prevRequestDimensions = usePrevious(requestDimensions);
|
|
30
29
|
const imageURLParams = useMemo(() => ({
|
|
31
30
|
collection: identifier.collectionName,
|
|
32
31
|
mode: resizeMode === 'stretchy-fit' ? 'full-fit' : resizeMode,
|
|
@@ -70,7 +69,6 @@ export const useFilePreview = ({
|
|
|
70
69
|
}
|
|
71
70
|
};
|
|
72
71
|
const [preview, setPreview] = useState(previewInitializer);
|
|
73
|
-
const prevPreview = usePrevious(preview);
|
|
74
72
|
const {
|
|
75
73
|
fileState
|
|
76
74
|
} = useFileState(identifier.id, {
|
|
@@ -163,7 +161,7 @@ export const useFilePreview = ({
|
|
|
163
161
|
// https://product-fabric.atlassian.net/browse/MEX-1071
|
|
164
162
|
});
|
|
165
163
|
}
|
|
166
|
-
}, [
|
|
164
|
+
}, [getAndCacheRemotePreviewRef, preview, skipRemote, ssr]);
|
|
167
165
|
|
|
168
166
|
//----------------------------------------------------------------
|
|
169
167
|
// Refetch SRR Preview if dimensions from Server have changed and are bigger,
|
|
@@ -176,117 +174,62 @@ export const useFilePreview = ({
|
|
|
176
174
|
setNonCriticalError(wrappedError);
|
|
177
175
|
});
|
|
178
176
|
}
|
|
179
|
-
}, [getAndCacheRemotePreviewRef,
|
|
177
|
+
}, [getAndCacheRemotePreviewRef, preview, requestDimensions, skipRemote]);
|
|
180
178
|
|
|
181
179
|
//----------------------------------------------------------------
|
|
182
180
|
// Upfront Preview
|
|
183
181
|
//----------------------------------------------------------------
|
|
184
182
|
useEffect(() => {
|
|
185
|
-
|
|
183
|
+
if (!preview && !wasResolvedUpfrontPreviewRef.current && !skipRemote) {
|
|
186
184
|
// We block any possible future call to this method regardless of the outcome (success or fail)
|
|
187
185
|
// If it fails, the normal preview fetch should occur after the file state is fetched anyways
|
|
188
186
|
wasResolvedUpfrontPreviewRef.current = true;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const newPreview = await getAndCacheRemotePreviewRef.current();
|
|
194
|
-
const areValidFetchedDimensions = !isBigger(fetchedDimensions, requestDimensionsRef.current);
|
|
195
|
-
|
|
187
|
+
const fetchedDimensions = {
|
|
188
|
+
...requestDimensions
|
|
189
|
+
};
|
|
190
|
+
getAndCacheRemotePreviewRef.current().then(newPreview => {
|
|
196
191
|
// If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
|
|
197
192
|
// the fetched preview is no longer valid, and thus, we dismiss it
|
|
198
|
-
if (
|
|
193
|
+
if (!isBigger(fetchedDimensions, requestDimensionsRef.current)) {
|
|
199
194
|
setPreview(newPreview);
|
|
200
195
|
}
|
|
201
|
-
}
|
|
196
|
+
}).catch(() => {
|
|
202
197
|
// NO need to log error. If this call fails, a refetch will happen after
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
// CXP-2723 TODO: `hadSSRPreview` is most likely redundant
|
|
207
|
-
const hadSSRPreview = ssr === 'client' && !!prevPreview && isSSRClientPreview(prevPreview);
|
|
208
|
-
if (!preview && !wasResolvedUpfrontPreviewRef.current && (!skipRemote || hadSSRPreview)) {
|
|
209
|
-
resolveUpfrontPreview();
|
|
198
|
+
});
|
|
210
199
|
}
|
|
211
|
-
}, [preview, requestDimensions, requestDimensionsRef,
|
|
200
|
+
}, [getAndCacheRemotePreviewRef, preview, requestDimensions, requestDimensionsRef, skipRemote]);
|
|
212
201
|
|
|
213
202
|
//----------------------------------------------------------------
|
|
214
|
-
//
|
|
203
|
+
// Cache, Local & Remote Preview
|
|
215
204
|
//----------------------------------------------------------------
|
|
216
205
|
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
} catch (e) {
|
|
234
|
-
/**
|
|
235
|
-
* We report the error if:
|
|
236
|
-
* - local preview is supported and fails
|
|
237
|
-
* - local preview is unsupported and remote preview is NOT READY
|
|
238
|
-
* i.e. the function was called for "no reason".
|
|
239
|
-
* We DON'T report the error if:
|
|
240
|
-
* - local preview is unsupported and remote preview IS READY
|
|
241
|
-
* i.e. local preview is available and not supported,
|
|
242
|
-
* but we are after the remote preview instead.
|
|
243
|
-
*/
|
|
244
|
-
if (!isUnsupportedLocalPreviewError(e) || isUnsupportedLocalPreviewError(e) && !isRemotePreviewReady) {
|
|
245
|
-
// CXP-2723 TODO: We might have to wrap this error in MediaCardError
|
|
246
|
-
setNonCriticalError(e);
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* No matter the reason why the local preview failed, we break the process
|
|
250
|
-
* if there is no remote preview available
|
|
251
|
-
*/
|
|
252
|
-
if (!isRemotePreviewReady) {
|
|
253
|
-
throw e;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
if (!isRemotePreviewReady) {
|
|
257
|
-
/**
|
|
258
|
-
* We throw this in case this function has been called
|
|
259
|
-
* without checking isRemotePreviewReady first.
|
|
260
|
-
* If remote preview is not ready, the call to getCardPreviewFromBackend
|
|
261
|
-
* will generate a console error due to a 404 code
|
|
262
|
-
*/
|
|
263
|
-
throw new MediaFilePreviewError('remote-preview-not-ready');
|
|
264
|
-
}
|
|
265
|
-
const remotePreview = await getAndCacheRemotePreviewRef.current();
|
|
266
|
-
setPreview(remotePreview);
|
|
267
|
-
return;
|
|
268
|
-
} catch (e) {
|
|
269
|
-
const wrappedError = ensureMediaFilePreviewError('preview-fetch', e);
|
|
270
|
-
// If remote preview fails, we set status 'error'
|
|
271
|
-
// If local preview fails (i.e, no remote preview available),
|
|
272
|
-
// we can stay in the same status until there is a remote preview available
|
|
273
|
-
// If it's any other error we set status 'error'
|
|
274
|
-
if (isLocalPreviewError(wrappedError)) {
|
|
275
|
-
// This error should already been logged inside the getCardPreview. No need to log it here.
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
const cachedPreview = mediaFilePreviewCache.get(identifier.id, imageURLParams.mode);
|
|
208
|
+
|
|
209
|
+
// Cached Preview ----------------------------------------------------------------
|
|
210
|
+
if (!preview && cachedPreview && !isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, requestDimensions)) {
|
|
211
|
+
setPreview(cachedPreview);
|
|
212
|
+
}
|
|
213
|
+
// Local Preview ----------------------------------------------------------------
|
|
214
|
+
else if (!preview && !isBannedLocalPreview && !!fileState && 'preview' in fileState && !!fileState.preview && isSupportedLocalPreview(fileState.mediaType) && isMimeTypeSupportedByBrowser(fileState.mimeType)) {
|
|
215
|
+
// Local preview is available only if it's supported by browser and supported by Media Card (isSupportedLocalPreview)
|
|
216
|
+
// For example, SVGs are mime type NOT supported by browser but media type supported by Media Card (image)
|
|
217
|
+
// Then, local Preview NOT available
|
|
218
|
+
|
|
219
|
+
getAndCacheLocalPreview(identifier.id, fileState.preview, requestDimensions || {}, imageURLParams.mode, mediaBlobUrlAttrs).then(setPreview).catch(e => {
|
|
276
220
|
setIsBannedLocalPreview(true);
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
setError(wrappedError);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
221
|
+
// CXP-2723 TODO: We might have to wrap this error in MediaCardError
|
|
222
|
+
setNonCriticalError(e);
|
|
223
|
+
});
|
|
283
224
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
225
|
+
// Remote Preview ----------------------------------------------------------------
|
|
226
|
+
else if ((!preview || isBigger(preview.dimensions, requestDimensions)) && !skipRemote && wasResolvedUpfrontPreviewRef.current && !!fileState && isImageRepresentationReady(fileState)) {
|
|
227
|
+
getAndCacheRemotePreviewRef.current().then(setPreview).catch(e => {
|
|
228
|
+
setStatus('error');
|
|
229
|
+
setError(ensureMediaFilePreviewError('preview-fetch', e));
|
|
230
|
+
});
|
|
288
231
|
}
|
|
289
|
-
}, [fileState, identifier, isBannedLocalPreview,
|
|
232
|
+
}, [fileState, getAndCacheRemotePreviewRef, identifier.id, imageURLParams.mode, isBannedLocalPreview, mediaBlobUrlAttrs, preview, requestDimensions, skipRemote]);
|
|
290
233
|
|
|
291
234
|
//----------------------------------------------------------------
|
|
292
235
|
// RETURN
|
|
@@ -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.6.
|
|
40
|
+
packageName: "77.6.5",
|
|
41
41
|
componentName: 'mediaInlineCard',
|
|
42
42
|
component: 'mediaInlineCard'
|
|
43
43
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
1
|
+
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
3
2
|
import { FileFetcherError } from '@atlaskit/media-client';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { MediaInlineCardErroredView, MediaInlineCardLoadedView, MediaInlineCardLoadingView, messages } from '@atlaskit/media-ui';
|
|
4
|
+
import { formatDate } from '@atlaskit/media-ui/formatDate';
|
|
6
5
|
import { MimeTypeIcon } from '@atlaskit/media-ui/mime-type-icon';
|
|
7
6
|
import { MediaViewer } from '@atlaskit/media-viewer';
|
|
8
7
|
import Tooltip from '@atlaskit/tooltip';
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
8
|
+
import React, { useEffect, useState } from 'react';
|
|
9
|
+
import ReactDOM from 'react-dom';
|
|
10
|
+
import { createIntl, injectIntl, IntlProvider } from 'react-intl-next';
|
|
12
11
|
import { MediaCardError } from '../errors';
|
|
12
|
+
import { fireMediaCardEvent } from '../utils/analytics';
|
|
13
13
|
import { getErrorStatusPayload, getFailedProcessingStatusPayload, getSucceededStatusPayload } from './mediaInlineCardAnalytics';
|
|
14
14
|
// UI component which renders an inline link in the appropiate state based on a media file
|
|
15
15
|
export const MediaInlineCardInternal = ({
|
|
@@ -86,7 +86,7 @@ export const MediaInlineCardInternal = ({
|
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
return () => {
|
|
89
|
-
subscription.unsubscribe();
|
|
89
|
+
subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe();
|
|
90
90
|
};
|
|
91
91
|
}, [identifier.collectionName, identifier.id, mediaClient.file]);
|
|
92
92
|
if (subscribeError) {
|
|
@@ -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.6.
|
|
7
|
+
const packageVersion = "77.6.5";
|
|
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.6.
|
|
43
|
+
var packageVersion = "77.6.5";
|
|
44
44
|
export var CardBase = /*#__PURE__*/function (_Component) {
|
|
45
45
|
_inherits(CardBase, _Component);
|
|
46
46
|
var _super = _createSuper(CardBase);
|
|
@@ -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.6.
|
|
86
|
+
var packageVersion = "77.6.5";
|
|
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.6.
|
|
12
|
+
var packageVersion = "77.6.5";
|
|
13
13
|
export var CardV2Base = function CardV2Base(_ref) {
|
|
14
14
|
var identifier = _ref.identifier,
|
|
15
15
|
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -318,8 +318,12 @@ export var FileCard = function FileCard(_ref) {
|
|
|
318
318
|
if (!metadata) {
|
|
319
319
|
return;
|
|
320
320
|
}
|
|
321
|
-
var isVideo = metadata
|
|
322
|
-
|
|
321
|
+
var isVideo = metadata.mediaType === 'video';
|
|
322
|
+
var isBrowserSupported = metadata.mimeType && isMimeTypeSupportedByBrowser(metadata.mimeType);
|
|
323
|
+
|
|
324
|
+
// TODO: this should be handled by Inline Player
|
|
325
|
+
var isPlayable = !!fileState && (fileState.status === 'processed' || isBrowserSupported && ['processing', 'uploading'].includes(fileState.status));
|
|
326
|
+
if (useInlinePlayer && isVideo && isPlayable && finalStatus !== 'error') {
|
|
323
327
|
setIsPlayingFile(true);
|
|
324
328
|
setShouldAutoplay(true);
|
|
325
329
|
} else if (shouldOpenMediaViewer) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { mediaFilePreviewCache } from './cache';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { getSSRPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, getAndCacheRemotePreview, getAndCacheLocalPreview } from './getPreview';
|
|
3
|
+
export { isSupportedLocalPreview } from './helpers';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef
|
|
1
|
+
import { useRef } from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Checks if at least one of next dimensions is bigger than current
|
|
@@ -47,11 +47,4 @@ export function useCurrentValueRef(value) {
|
|
|
47
47
|
var ref = useRef(value);
|
|
48
48
|
ref.current = value;
|
|
49
49
|
return ref;
|
|
50
|
-
}
|
|
51
|
-
export function usePrevious(value) {
|
|
52
|
-
var ref = useRef();
|
|
53
|
-
useEffect(function () {
|
|
54
|
-
ref.current = value;
|
|
55
|
-
}, [value]);
|
|
56
|
-
return ref.current;
|
|
57
50
|
}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
3
|
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
4
|
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
5
|
import { imageResizeModeToFileImageMode, isImageRepresentationReady } from '@atlaskit/media-client';
|
|
8
6
|
import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
9
7
|
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
10
8
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
11
|
-
import { ensureMediaFilePreviewError, ImageLoadError,
|
|
9
|
+
import { ensureMediaFilePreviewError, ImageLoadError, MediaFilePreviewError } from './errors';
|
|
12
10
|
import { extractErrorInfo } from './analytics';
|
|
13
|
-
import { isBigger, createRequestDimensions, useCurrentValueRef
|
|
11
|
+
import { isBigger, createRequestDimensions, useCurrentValueRef } from './helpers';
|
|
14
12
|
import { generateScriptProps, getSSRData } from './globalScope';
|
|
15
|
-
import { getAndCacheRemotePreview, getSSRPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview,
|
|
13
|
+
import { getAndCacheRemotePreview, getSSRPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, mediaFilePreviewCache, getAndCacheLocalPreview, isSupportedLocalPreview } from './getPreview';
|
|
16
14
|
export var useFilePreview = function useFilePreview(_ref) {
|
|
17
15
|
var _ref$resizeMode = _ref.resizeMode,
|
|
18
16
|
resizeMode = _ref$resizeMode === void 0 ? 'crop' : _ref$resizeMode,
|
|
@@ -46,7 +44,6 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
46
44
|
return dimensions ? createRequestDimensions(dimensions) : undefined;
|
|
47
45
|
}, [dimensions]);
|
|
48
46
|
var requestDimensionsRef = useCurrentValueRef(requestDimensions);
|
|
49
|
-
var prevRequestDimensions = usePrevious(requestDimensions);
|
|
50
47
|
var imageURLParams = useMemo(function () {
|
|
51
48
|
return _objectSpread(_objectSpread({
|
|
52
49
|
collection: identifier.collectionName,
|
|
@@ -91,7 +88,6 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
91
88
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
92
89
|
preview = _useState10[0],
|
|
93
90
|
setPreview = _useState10[1];
|
|
94
|
-
var prevPreview = usePrevious(preview);
|
|
95
91
|
var _useFileState = useFileState(identifier.id, {
|
|
96
92
|
skipRemote: skipRemote,
|
|
97
93
|
collectionName: identifier.collectionName,
|
|
@@ -117,8 +113,8 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
117
113
|
var mediaType = 'mediaType' in fileState ? fileState.mediaType : undefined;
|
|
118
114
|
var isPreviewable = !!mediaType && ['audio', 'video', 'image', 'doc'].indexOf(mediaType) > -1;
|
|
119
115
|
var isPreviewableFileState = !!fileState.preview;
|
|
120
|
-
var
|
|
121
|
-
var hasLocalPreview = !isBannedLocalPreview && isPreviewableFileState &&
|
|
116
|
+
var _isSupportedLocalPreview = mediaType === 'image' || mediaType === 'video';
|
|
117
|
+
var hasLocalPreview = !isBannedLocalPreview && isPreviewableFileState && _isSupportedLocalPreview && !!fileState.mimeType && isMimeTypeSupportedByBrowser(fileState.mimeType);
|
|
122
118
|
var hasRemotePreview = isImageRepresentationReady(fileState);
|
|
123
119
|
var hasPreview = hasLocalPreview || hasRemotePreview;
|
|
124
120
|
var newStatus;
|
|
@@ -183,7 +179,7 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
183
179
|
// https://product-fabric.atlassian.net/browse/MEX-1071
|
|
184
180
|
});
|
|
185
181
|
}
|
|
186
|
-
}, [
|
|
182
|
+
}, [getAndCacheRemotePreviewRef, preview, skipRemote, ssr]);
|
|
187
183
|
|
|
188
184
|
//----------------------------------------------------------------
|
|
189
185
|
// Refetch SRR Preview if dimensions from Server have changed and are bigger,
|
|
@@ -196,161 +192,60 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
196
192
|
setNonCriticalError(wrappedError);
|
|
197
193
|
});
|
|
198
194
|
}
|
|
199
|
-
}, [getAndCacheRemotePreviewRef,
|
|
195
|
+
}, [getAndCacheRemotePreviewRef, preview, requestDimensions, skipRemote]);
|
|
200
196
|
|
|
201
197
|
//----------------------------------------------------------------
|
|
202
198
|
// Upfront Preview
|
|
203
199
|
//----------------------------------------------------------------
|
|
204
200
|
useEffect(function () {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
newPreview = _context.sent;
|
|
220
|
-
areValidFetchedDimensions = !isBigger(fetchedDimensions, requestDimensionsRef.current); // If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
|
|
221
|
-
// the fetched preview is no longer valid, and thus, we dismiss it
|
|
222
|
-
if (areValidFetchedDimensions) {
|
|
223
|
-
setPreview(newPreview);
|
|
224
|
-
}
|
|
225
|
-
_context.next = 12;
|
|
226
|
-
break;
|
|
227
|
-
case 10:
|
|
228
|
-
_context.prev = 10;
|
|
229
|
-
_context.t0 = _context["catch"](1);
|
|
230
|
-
case 12:
|
|
231
|
-
case "end":
|
|
232
|
-
return _context.stop();
|
|
233
|
-
}
|
|
234
|
-
}, _callee, null, [[1, 10]]);
|
|
235
|
-
}));
|
|
236
|
-
return function resolveUpfrontPreview() {
|
|
237
|
-
return _ref2.apply(this, arguments);
|
|
238
|
-
};
|
|
239
|
-
}();
|
|
240
|
-
|
|
241
|
-
// CXP-2723 TODO: `hadSSRPreview` is most likely redundant
|
|
242
|
-
var hadSSRPreview = ssr === 'client' && !!prevPreview && isSSRClientPreview(prevPreview);
|
|
243
|
-
if (!preview && !wasResolvedUpfrontPreviewRef.current && (!skipRemote || hadSSRPreview)) {
|
|
244
|
-
resolveUpfrontPreview();
|
|
201
|
+
if (!preview && !wasResolvedUpfrontPreviewRef.current && !skipRemote) {
|
|
202
|
+
// We block any possible future call to this method regardless of the outcome (success or fail)
|
|
203
|
+
// If it fails, the normal preview fetch should occur after the file state is fetched anyways
|
|
204
|
+
wasResolvedUpfrontPreviewRef.current = true;
|
|
205
|
+
var fetchedDimensions = _objectSpread({}, requestDimensions);
|
|
206
|
+
getAndCacheRemotePreviewRef.current().then(function (newPreview) {
|
|
207
|
+
// If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
|
|
208
|
+
// the fetched preview is no longer valid, and thus, we dismiss it
|
|
209
|
+
if (!isBigger(fetchedDimensions, requestDimensionsRef.current)) {
|
|
210
|
+
setPreview(newPreview);
|
|
211
|
+
}
|
|
212
|
+
}).catch(function () {
|
|
213
|
+
// NO need to log error. If this call fails, a refetch will happen after
|
|
214
|
+
});
|
|
245
215
|
}
|
|
246
|
-
}, [preview, requestDimensions, requestDimensionsRef,
|
|
216
|
+
}, [getAndCacheRemotePreviewRef, preview, requestDimensions, requestDimensionsRef, skipRemote]);
|
|
247
217
|
|
|
248
218
|
//----------------------------------------------------------------
|
|
249
|
-
//
|
|
219
|
+
// Cache, Local & Remote Preview
|
|
250
220
|
//----------------------------------------------------------------
|
|
251
221
|
|
|
252
|
-
var resolvePreviewRef = useCurrentValueRef( /*#__PURE__*/function () {
|
|
253
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(identifier, fileState) {
|
|
254
|
-
var filePreview, isRemotePreviewReady, mode, cachedPreview, dimensionsAreBigger, localPreview, remotePreview, wrappedError;
|
|
255
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
256
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
257
|
-
case 0:
|
|
258
|
-
filePreview = isBannedLocalPreview ? undefined : fileState.status !== 'error' && 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) ? fileState.preview : undefined;
|
|
259
|
-
isRemotePreviewReady = isImageRepresentationReady(fileState);
|
|
260
|
-
_context2.prev = 2;
|
|
261
|
-
mode = imageURLParams.mode;
|
|
262
|
-
cachedPreview = mediaFilePreviewCache.get(identifier.id, mode);
|
|
263
|
-
dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, requestDimensions);
|
|
264
|
-
if (!(cachedPreview && !dimensionsAreBigger)) {
|
|
265
|
-
_context2.next = 8;
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
return _context2.abrupt("return", cachedPreview);
|
|
269
|
-
case 8:
|
|
270
|
-
_context2.prev = 8;
|
|
271
|
-
if (!filePreview) {
|
|
272
|
-
_context2.next = 15;
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
_context2.next = 12;
|
|
276
|
-
return getAndCacheLocalPreview(identifier.id, filePreview, requestDimensions || {}, mode, mediaBlobUrlAttrs);
|
|
277
|
-
case 12:
|
|
278
|
-
localPreview = _context2.sent;
|
|
279
|
-
setPreview(localPreview);
|
|
280
|
-
return _context2.abrupt("return");
|
|
281
|
-
case 15:
|
|
282
|
-
_context2.next = 22;
|
|
283
|
-
break;
|
|
284
|
-
case 17:
|
|
285
|
-
_context2.prev = 17;
|
|
286
|
-
_context2.t0 = _context2["catch"](8);
|
|
287
|
-
/**
|
|
288
|
-
* We report the error if:
|
|
289
|
-
* - local preview is supported and fails
|
|
290
|
-
* - local preview is unsupported and remote preview is NOT READY
|
|
291
|
-
* i.e. the function was called for "no reason".
|
|
292
|
-
* We DON'T report the error if:
|
|
293
|
-
* - local preview is unsupported and remote preview IS READY
|
|
294
|
-
* i.e. local preview is available and not supported,
|
|
295
|
-
* but we are after the remote preview instead.
|
|
296
|
-
*/
|
|
297
|
-
if (!isUnsupportedLocalPreviewError(_context2.t0) || isUnsupportedLocalPreviewError(_context2.t0) && !isRemotePreviewReady) {
|
|
298
|
-
// CXP-2723 TODO: We might have to wrap this error in MediaCardError
|
|
299
|
-
setNonCriticalError(_context2.t0);
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* No matter the reason why the local preview failed, we break the process
|
|
303
|
-
* if there is no remote preview available
|
|
304
|
-
*/
|
|
305
|
-
if (isRemotePreviewReady) {
|
|
306
|
-
_context2.next = 22;
|
|
307
|
-
break;
|
|
308
|
-
}
|
|
309
|
-
throw _context2.t0;
|
|
310
|
-
case 22:
|
|
311
|
-
if (isRemotePreviewReady) {
|
|
312
|
-
_context2.next = 24;
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
throw new MediaFilePreviewError('remote-preview-not-ready');
|
|
316
|
-
case 24:
|
|
317
|
-
_context2.next = 26;
|
|
318
|
-
return getAndCacheRemotePreviewRef.current();
|
|
319
|
-
case 26:
|
|
320
|
-
remotePreview = _context2.sent;
|
|
321
|
-
setPreview(remotePreview);
|
|
322
|
-
return _context2.abrupt("return");
|
|
323
|
-
case 31:
|
|
324
|
-
_context2.prev = 31;
|
|
325
|
-
_context2.t1 = _context2["catch"](2);
|
|
326
|
-
wrappedError = ensureMediaFilePreviewError('preview-fetch', _context2.t1); // If remote preview fails, we set status 'error'
|
|
327
|
-
// If local preview fails (i.e, no remote preview available),
|
|
328
|
-
// we can stay in the same status until there is a remote preview available
|
|
329
|
-
// If it's any other error we set status 'error'
|
|
330
|
-
if (isLocalPreviewError(wrappedError)) {
|
|
331
|
-
// This error should already been logged inside the getCardPreview. No need to log it here.
|
|
332
|
-
setIsBannedLocalPreview(true);
|
|
333
|
-
} else {
|
|
334
|
-
if (!['complete', 'error', 'failed-processing'].includes(status)) {
|
|
335
|
-
setStatus('error');
|
|
336
|
-
setError(wrappedError);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
case 35:
|
|
340
|
-
case "end":
|
|
341
|
-
return _context2.stop();
|
|
342
|
-
}
|
|
343
|
-
}, _callee2, null, [[2, 31], [8, 17]]);
|
|
344
|
-
}));
|
|
345
|
-
return function (_x, _x2) {
|
|
346
|
-
return _ref3.apply(this, arguments);
|
|
347
|
-
};
|
|
348
|
-
}());
|
|
349
222
|
useEffect(function () {
|
|
350
|
-
|
|
351
|
-
|
|
223
|
+
var cachedPreview = mediaFilePreviewCache.get(identifier.id, imageURLParams.mode);
|
|
224
|
+
|
|
225
|
+
// Cached Preview ----------------------------------------------------------------
|
|
226
|
+
if (!preview && cachedPreview && !isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, requestDimensions)) {
|
|
227
|
+
setPreview(cachedPreview);
|
|
228
|
+
}
|
|
229
|
+
// Local Preview ----------------------------------------------------------------
|
|
230
|
+
else if (!preview && !isBannedLocalPreview && !!fileState && 'preview' in fileState && !!fileState.preview && isSupportedLocalPreview(fileState.mediaType) && isMimeTypeSupportedByBrowser(fileState.mimeType)) {
|
|
231
|
+
// Local preview is available only if it's supported by browser and supported by Media Card (isSupportedLocalPreview)
|
|
232
|
+
// For example, SVGs are mime type NOT supported by browser but media type supported by Media Card (image)
|
|
233
|
+
// Then, local Preview NOT available
|
|
234
|
+
|
|
235
|
+
getAndCacheLocalPreview(identifier.id, fileState.preview, requestDimensions || {}, imageURLParams.mode, mediaBlobUrlAttrs).then(setPreview).catch(function (e) {
|
|
236
|
+
setIsBannedLocalPreview(true);
|
|
237
|
+
// CXP-2723 TODO: We might have to wrap this error in MediaCardError
|
|
238
|
+
setNonCriticalError(e);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
// Remote Preview ----------------------------------------------------------------
|
|
242
|
+
else if ((!preview || isBigger(preview.dimensions, requestDimensions)) && !skipRemote && wasResolvedUpfrontPreviewRef.current && !!fileState && isImageRepresentationReady(fileState)) {
|
|
243
|
+
getAndCacheRemotePreviewRef.current().then(setPreview).catch(function (e) {
|
|
244
|
+
setStatus('error');
|
|
245
|
+
setError(ensureMediaFilePreviewError('preview-fetch', e));
|
|
246
|
+
});
|
|
352
247
|
}
|
|
353
|
-
}, [fileState, identifier, isBannedLocalPreview,
|
|
248
|
+
}, [fileState, getAndCacheRemotePreviewRef, identifier.id, imageURLParams.mode, isBannedLocalPreview, mediaBlobUrlAttrs, preview, requestDimensions, skipRemote]);
|
|
354
249
|
|
|
355
250
|
//----------------------------------------------------------------
|
|
356
251
|
// RETURN
|
|
@@ -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.6.
|
|
106
|
+
packageName: "77.6.5",
|
|
107
107
|
componentName: 'mediaInlineCard',
|
|
108
108
|
component: 'mediaInlineCard'
|
|
109
109
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import
|
|
3
|
-
import ReactDOM from 'react-dom';
|
|
2
|
+
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
4
3
|
import { FileFetcherError } from '@atlaskit/media-client';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { MediaInlineCardErroredView, MediaInlineCardLoadedView, MediaInlineCardLoadingView, messages } from '@atlaskit/media-ui';
|
|
5
|
+
import { formatDate } from '@atlaskit/media-ui/formatDate';
|
|
7
6
|
import { MimeTypeIcon } from '@atlaskit/media-ui/mime-type-icon';
|
|
8
7
|
import { MediaViewer } from '@atlaskit/media-viewer';
|
|
9
8
|
import Tooltip from '@atlaskit/tooltip';
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
9
|
+
import React, { useEffect, useState } from 'react';
|
|
10
|
+
import ReactDOM from 'react-dom';
|
|
11
|
+
import { createIntl, injectIntl, IntlProvider } from 'react-intl-next';
|
|
13
12
|
import { MediaCardError } from '../errors';
|
|
13
|
+
import { fireMediaCardEvent } from '../utils/analytics';
|
|
14
14
|
import { getErrorStatusPayload, getFailedProcessingStatusPayload, getSucceededStatusPayload } from './mediaInlineCardAnalytics';
|
|
15
15
|
// UI component which renders an inline link in the appropiate state based on a media file
|
|
16
16
|
export var MediaInlineCardInternal = function MediaInlineCardInternal(_ref) {
|
|
@@ -104,7 +104,7 @@ export var MediaInlineCardInternal = function MediaInlineCardInternal(_ref) {
|
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
return function () {
|
|
107
|
-
subscription.unsubscribe();
|
|
107
|
+
subscription === null || subscription === void 0 || subscription.unsubscribe();
|
|
108
108
|
};
|
|
109
109
|
}, [identifier.collectionName, identifier.id, mediaClient.file]);
|
|
110
110
|
if (subscribeError) {
|
|
@@ -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.6.
|
|
10
|
+
var packageVersion = "77.6.5";
|
|
11
11
|
var concurrentExperience;
|
|
12
12
|
var getExperience = function getExperience(id) {
|
|
13
13
|
if (!concurrentExperience) {
|