@atlaskit/media-card 77.4.10 → 77.5.1
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/cardLoader.js +3 -47
- package/dist/cjs/card/cardWithMediaClient.js +26 -0
- 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/cardV2Loader.js +3 -54
- package/dist/cjs/card/v2/cardViewV2.js +7 -6
- package/dist/cjs/card/v2/cardWithMediaClientV2.js +34 -0
- package/dist/cjs/card/v2/useFilePreview/errors.js +132 -0
- package/dist/cjs/card/v2/useFilePreview/getPreview/cache.js +39 -0
- package/dist/cjs/card/v2/useFilePreview/getPreview/filePreviewStatus.js +45 -0
- package/dist/cjs/card/v2/useFilePreview/getPreview/getPreview.js +119 -0
- package/dist/cjs/card/v2/useFilePreview/getPreview/helpers.js +167 -0
- package/dist/cjs/card/v2/useFilePreview/getPreview/index.js +62 -0
- package/dist/cjs/card/v2/useFilePreview/getPreview/objectURLCache.js +85 -0
- package/dist/cjs/card/v2/useFilePreview/getPreview/videoSnapshot.js +58 -0
- package/dist/cjs/card/v2/useFilePreview/globalScope/getSSRData.js +14 -0
- package/dist/cjs/card/v2/useFilePreview/globalScope/globalScope.js +66 -0
- package/dist/cjs/card/v2/useFilePreview/globalScope/index.js +37 -0
- package/dist/cjs/card/v2/useFilePreview/globalScope/printScript.js +32 -0
- package/dist/cjs/card/v2/useFilePreview/globalScope/types.js +5 -0
- package/dist/cjs/card/v2/useFilePreview/helpers.js +64 -0
- package/dist/cjs/card/v2/useFilePreview/index.js +12 -0
- package/dist/cjs/card/v2/useFilePreview/types.js +5 -0
- package/dist/cjs/card/v2/{useFilePreview.js → useFilePreview/useFilePreview.js} +58 -194
- package/dist/cjs/inline/loader.js +1 -1
- package/dist/cjs/utils/ufoExperiences.js +1 -1
- package/dist/es2019/card/card.js +1 -1
- package/dist/es2019/card/cardLoader.js +2 -32
- package/dist/es2019/card/cardWithMediaClient.js +21 -0
- 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/cardV2Loader.js +2 -35
- package/dist/es2019/card/v2/cardViewV2.js +7 -6
- package/dist/es2019/card/v2/cardWithMediaClientV2.js +25 -0
- package/dist/es2019/card/v2/useFilePreview/errors.js +81 -0
- package/dist/es2019/card/v2/useFilePreview/getPreview/cache.js +30 -0
- package/dist/es2019/card/v2/useFilePreview/getPreview/filePreviewStatus.js +43 -0
- package/dist/es2019/card/v2/useFilePreview/getPreview/getPreview.js +75 -0
- package/dist/es2019/card/v2/useFilePreview/getPreview/helpers.js +76 -0
- package/dist/es2019/card/v2/useFilePreview/getPreview/index.js +3 -0
- package/dist/es2019/card/v2/useFilePreview/getPreview/objectURLCache.js +44 -0
- package/dist/es2019/card/v2/useFilePreview/getPreview/videoSnapshot.js +36 -0
- package/dist/es2019/card/v2/useFilePreview/globalScope/getSSRData.js +8 -0
- package/dist/es2019/card/v2/useFilePreview/globalScope/globalScope.js +48 -0
- package/dist/es2019/card/v2/useFilePreview/globalScope/index.js +2 -0
- package/dist/es2019/card/v2/useFilePreview/globalScope/printScript.js +16 -0
- package/dist/es2019/card/v2/useFilePreview/globalScope/types.js +1 -0
- package/dist/es2019/card/v2/useFilePreview/helpers.js +61 -0
- package/dist/es2019/card/v2/useFilePreview/index.js +1 -0
- package/dist/es2019/card/v2/useFilePreview/types.js +1 -0
- package/dist/es2019/card/v2/{useFilePreview.js → useFilePreview/useFilePreview.js} +18 -132
- package/dist/es2019/inline/loader.js +1 -1
- package/dist/es2019/utils/ufoExperiences.js +1 -1
- package/dist/esm/card/card.js +1 -1
- package/dist/esm/card/cardLoader.js +3 -43
- package/dist/esm/card/cardWithMediaClient.js +19 -0
- 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/cardV2Loader.js +3 -50
- package/dist/esm/card/v2/cardViewV2.js +7 -6
- package/dist/esm/card/v2/cardWithMediaClientV2.js +27 -0
- package/dist/esm/card/v2/useFilePreview/errors.js +124 -0
- package/dist/esm/card/v2/useFilePreview/getPreview/cache.js +32 -0
- package/dist/esm/card/v2/useFilePreview/getPreview/filePreviewStatus.js +40 -0
- package/dist/esm/card/v2/useFilePreview/getPreview/getPreview.js +112 -0
- package/dist/esm/card/v2/useFilePreview/getPreview/helpers.js +160 -0
- package/dist/esm/card/v2/useFilePreview/getPreview/index.js +3 -0
- package/dist/esm/card/v2/useFilePreview/getPreview/objectURLCache.js +78 -0
- package/dist/esm/card/v2/useFilePreview/getPreview/videoSnapshot.js +51 -0
- package/dist/esm/card/v2/useFilePreview/globalScope/getSSRData.js +8 -0
- package/dist/esm/card/v2/useFilePreview/globalScope/globalScope.js +56 -0
- package/dist/esm/card/v2/useFilePreview/globalScope/index.js +2 -0
- package/dist/esm/card/v2/useFilePreview/globalScope/printScript.js +25 -0
- package/dist/esm/card/v2/useFilePreview/globalScope/types.js +1 -0
- package/dist/esm/card/v2/useFilePreview/helpers.js +57 -0
- package/dist/esm/card/v2/useFilePreview/index.js +1 -0
- package/dist/esm/card/v2/useFilePreview/types.js +1 -0
- package/dist/esm/card/v2/{useFilePreview.js → useFilePreview/useFilePreview.js} +41 -177
- package/dist/esm/inline/loader.js +1 -1
- package/dist/esm/utils/ufoExperiences.js +1 -1
- package/dist/types/card/cardLoader.d.ts +1 -3
- package/dist/types/card/cardSwitcher.d.ts +1 -1
- package/dist/types/card/cardWithMediaClient.d.ts +3 -0
- package/dist/types/card/types.d.ts +3 -0
- package/dist/types/card/v2/cardV2Loader.d.ts +1 -1
- package/dist/types/card/v2/cardViewV2.d.ts +5 -4
- package/dist/types/card/v2/cardWithMediaClientV2.d.ts +3 -0
- package/dist/types/card/v2/useFilePreview/errors.d.ts +38 -0
- package/dist/types/card/v2/useFilePreview/getPreview/cache.d.ts +21 -0
- package/dist/types/card/v2/useFilePreview/getPreview/filePreviewStatus.d.ts +4 -0
- package/dist/types/card/v2/useFilePreview/getPreview/getPreview.d.ts +9 -0
- package/dist/types/card/v2/useFilePreview/getPreview/helpers.d.ts +10 -0
- package/dist/types/card/v2/useFilePreview/getPreview/index.d.ts +3 -0
- package/dist/types/card/v2/useFilePreview/getPreview/objectURLCache.d.ts +12 -0
- package/dist/types/card/v2/useFilePreview/getPreview/videoSnapshot.d.ts +1 -0
- package/dist/types/card/v2/useFilePreview/globalScope/getSSRData.d.ts +3 -0
- package/dist/types/card/v2/useFilePreview/globalScope/globalScope.d.ts +15 -0
- package/dist/types/card/v2/useFilePreview/globalScope/index.d.ts +4 -0
- package/dist/types/card/v2/useFilePreview/globalScope/printScript.d.ts +2 -0
- package/dist/types/card/v2/useFilePreview/globalScope/types.d.ts +8 -0
- package/dist/types/card/v2/useFilePreview/helpers.d.ts +11 -0
- package/dist/types/card/v2/useFilePreview/index.d.ts +2 -0
- package/dist/types/card/v2/useFilePreview/types.d.ts +18 -0
- package/dist/{types-ts4.5/card/v2 → types/card/v2/useFilePreview}/useFilePreview.d.ts +8 -8
- package/dist/types-ts4.5/card/cardLoader.d.ts +1 -3
- package/dist/types-ts4.5/card/cardSwitcher.d.ts +1 -1
- package/dist/types-ts4.5/card/cardWithMediaClient.d.ts +3 -0
- package/dist/types-ts4.5/card/types.d.ts +3 -0
- package/dist/types-ts4.5/card/v2/cardV2Loader.d.ts +1 -1
- package/dist/types-ts4.5/card/v2/cardViewV2.d.ts +5 -4
- package/dist/types-ts4.5/card/v2/cardWithMediaClientV2.d.ts +3 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/errors.d.ts +38 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/cache.d.ts +21 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/filePreviewStatus.d.ts +4 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/getPreview.d.ts +9 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/helpers.d.ts +10 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/index.d.ts +3 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/objectURLCache.d.ts +12 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/getPreview/videoSnapshot.d.ts +1 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/globalScope/getSSRData.d.ts +3 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/globalScope/globalScope.d.ts +15 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/globalScope/index.d.ts +4 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/globalScope/printScript.d.ts +2 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/globalScope/types.d.ts +8 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/helpers.d.ts +11 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/index.d.ts +2 -0
- package/dist/types-ts4.5/card/v2/useFilePreview/types.d.ts +18 -0
- package/dist/{types/card/v2 → types-ts4.5/card/v2/useFilePreview}/useFilePreview.d.ts +8 -8
- package/package.json +1 -1
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { imageResizeModeToFileImageMode, isImageRepresentationReady } from '@atlaskit/media-client';
|
|
2
2
|
import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
3
|
-
import {
|
|
4
|
-
import { getOrientation } from '@atlaskit/media-ui';
|
|
3
|
+
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
5
4
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
-
import {
|
|
7
|
-
import { extractErrorInfo } from '
|
|
8
|
-
import { isBigger } from '
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
|
|
12
|
-
import { usePrevious } from '../../utils/usePrevious';
|
|
13
|
-
import { takeSnapshot } from '../../utils/videoSnapshot';
|
|
14
|
-
import { fetchAndCacheRemotePreview, getCardPreviewFromCache, getSSRCardPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, removeCardPreviewFromCache, shouldResolvePreview } from '../getCardPreview';
|
|
15
|
-
import cardPreviewCache from '../getCardPreview/cache';
|
|
5
|
+
import { ensureMediaFilePreviewError, ImageLoadError, isLocalPreviewError, isUnsupportedLocalPreviewError, MediaFilePreviewError } from './errors';
|
|
6
|
+
import { extractErrorInfo } from '../../../utils/analytics';
|
|
7
|
+
import { isBigger, createRequestDimensions, useCurrentValueRef, usePrevious } from './helpers';
|
|
8
|
+
import { generateScriptProps, getSSRData } from './globalScope';
|
|
9
|
+
import { getAndCacheRemotePreview, getSSRCardPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, isPreviewableStatus, extractFilePreviewStatus, mediaFilePreviewCache, getAndCacheLocalPreview } from './getPreview';
|
|
16
10
|
export const useFilePreview = ({
|
|
17
11
|
resizeMode = 'crop',
|
|
18
12
|
identifier,
|
|
@@ -72,7 +66,7 @@ export const useFilePreview = ({
|
|
|
72
66
|
id
|
|
73
67
|
} = identifier;
|
|
74
68
|
const fileImageMode = imageResizeModeToFileImageMode(resizeMode);
|
|
75
|
-
cardPreview =
|
|
69
|
+
cardPreview = mediaFilePreviewCache.get(id, fileImageMode);
|
|
76
70
|
if (!cardPreview && ssr) {
|
|
77
71
|
cardPreview = getSSRPreview(ssr, identifier, mediaClient);
|
|
78
72
|
}
|
|
@@ -95,104 +89,22 @@ export const useFilePreview = ({
|
|
|
95
89
|
//----------------------------------------------------------------//
|
|
96
90
|
|
|
97
91
|
const fetchRemotePreviewRef = useCurrentValueRef(identifier => {
|
|
98
|
-
return
|
|
92
|
+
return getAndCacheRemotePreview(mediaClient, identifier.id, requestDimensions || {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
|
|
99
93
|
});
|
|
100
94
|
const resolvePreviewRef = useCurrentValueRef(async (identifier, fileState) => {
|
|
101
95
|
const filePreview = isBannedLocalPreview ? undefined : fileState.status !== 'error' && 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) ? fileState.preview : undefined;
|
|
102
96
|
const isRemotePreviewReady = isImageRepresentationReady(fileState);
|
|
103
97
|
try {
|
|
104
98
|
const mode = imageURLParams.mode;
|
|
105
|
-
const cachedPreview =
|
|
99
|
+
const cachedPreview = mediaFilePreviewCache.get(identifier.id, mode);
|
|
106
100
|
const dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, requestDimensions);
|
|
107
101
|
if (cachedPreview && !dimensionsAreBigger) {
|
|
108
102
|
return cachedPreview;
|
|
109
103
|
}
|
|
110
|
-
let localPreview;
|
|
111
104
|
try {
|
|
112
105
|
if (filePreview) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const resolvedFilePreview = await filePreview;
|
|
116
|
-
value = resolvedFilePreview.value;
|
|
117
|
-
} catch (e) {
|
|
118
|
-
throw new LocalPreviewError('local-preview-rejected', e instanceof Error ? e : undefined);
|
|
119
|
-
}
|
|
120
|
-
if (typeof value === 'string') {
|
|
121
|
-
localPreview = {
|
|
122
|
-
dataURI: value,
|
|
123
|
-
orientation: 1,
|
|
124
|
-
source: 'local'
|
|
125
|
-
};
|
|
126
|
-
} else if (value instanceof Blob) {
|
|
127
|
-
const {
|
|
128
|
-
type
|
|
129
|
-
} = value;
|
|
130
|
-
const mediaType = getMediaTypeFromMimeType(type);
|
|
131
|
-
switch (mediaType) {
|
|
132
|
-
case 'image':
|
|
133
|
-
try {
|
|
134
|
-
const orientation = await getOrientation(value);
|
|
135
|
-
const dataURI = URL.createObjectURL(value);
|
|
136
|
-
localPreview = {
|
|
137
|
-
dataURI,
|
|
138
|
-
orientation,
|
|
139
|
-
source: 'local'
|
|
140
|
-
};
|
|
141
|
-
} catch (e) {
|
|
142
|
-
throw new LocalPreviewError('local-preview-image', e instanceof Error ? e : undefined);
|
|
143
|
-
}
|
|
144
|
-
break;
|
|
145
|
-
case 'video':
|
|
146
|
-
try {
|
|
147
|
-
const dataURI = await takeSnapshot(value);
|
|
148
|
-
localPreview = {
|
|
149
|
-
dataURI,
|
|
150
|
-
orientation: 1,
|
|
151
|
-
source: 'local'
|
|
152
|
-
};
|
|
153
|
-
} catch (e) {
|
|
154
|
-
throw new LocalPreviewError('local-preview-video', e instanceof Error ? e : undefined);
|
|
155
|
-
}
|
|
156
|
-
break;
|
|
157
|
-
default:
|
|
158
|
-
throw new LocalPreviewError('local-preview-unsupported');
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
throw new LocalPreviewError('local-preview-unsupported');
|
|
162
|
-
}
|
|
163
|
-
const preview = {
|
|
164
|
-
...localPreview,
|
|
165
|
-
dimensions: requestDimensions
|
|
166
|
-
};
|
|
167
|
-
let source;
|
|
168
|
-
switch (preview.source) {
|
|
169
|
-
case 'local':
|
|
170
|
-
source = 'cache-local';
|
|
171
|
-
break;
|
|
172
|
-
case 'remote':
|
|
173
|
-
source = 'cache-remote';
|
|
174
|
-
break;
|
|
175
|
-
case 'ssr-server':
|
|
176
|
-
source = 'cache-ssr-server';
|
|
177
|
-
break;
|
|
178
|
-
case 'ssr-client':
|
|
179
|
-
source = 'cache-ssr-client';
|
|
180
|
-
break;
|
|
181
|
-
default:
|
|
182
|
-
source = preview.source;
|
|
183
|
-
}
|
|
184
|
-
// We want to embed some meta context into dataURI for Copy/Paste to work.
|
|
185
|
-
const dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI;
|
|
186
|
-
// We store new cardPreview into cache
|
|
187
|
-
cardPreviewCache.set(identifier.id, mode, {
|
|
188
|
-
...preview,
|
|
189
|
-
source,
|
|
190
|
-
dataURI
|
|
191
|
-
});
|
|
192
|
-
setCardPreview({
|
|
193
|
-
...preview,
|
|
194
|
-
dataURI
|
|
195
|
-
});
|
|
106
|
+
const localPreview = await getAndCacheLocalPreview(identifier.id, filePreview, requestDimensions || {}, mode, mediaBlobUrlAttrs);
|
|
107
|
+
setCardPreview(localPreview);
|
|
196
108
|
return;
|
|
197
109
|
}
|
|
198
110
|
} catch (e) {
|
|
@@ -225,13 +137,13 @@ export const useFilePreview = ({
|
|
|
225
137
|
* If remote preview is not ready, the call to getCardPreviewFromBackend
|
|
226
138
|
* will generate a console error due to a 404 code
|
|
227
139
|
*/
|
|
228
|
-
throw new
|
|
140
|
+
throw new MediaFilePreviewError('remote-preview-not-ready');
|
|
229
141
|
}
|
|
230
142
|
const remotePreview = await fetchRemotePreviewRef.current(identifier);
|
|
231
143
|
setCardPreview(remotePreview);
|
|
232
144
|
return;
|
|
233
145
|
} catch (e) {
|
|
234
|
-
const wrappedError =
|
|
146
|
+
const wrappedError = ensureMediaFilePreviewError('preview-fetch', e);
|
|
235
147
|
// If remote preview fails, we set status 'error'
|
|
236
148
|
// If local preview fails (i.e, no remote preview available),
|
|
237
149
|
// we can stay in the same status until there is a remote preview available
|
|
@@ -293,7 +205,7 @@ export const useFilePreview = ({
|
|
|
293
205
|
// refetchSRRPreview: If dimensions from Server have changed and are bigger,
|
|
294
206
|
// we need to refetch
|
|
295
207
|
fetchRemotePreviewRef.current(identifier).then(setCardPreview).catch(e => {
|
|
296
|
-
const wrappedError =
|
|
208
|
+
const wrappedError = ensureMediaFilePreviewError('remote-preview-fetch-ssr', e, true);
|
|
297
209
|
setNonCriticalError(wrappedError);
|
|
298
210
|
});
|
|
299
211
|
}
|
|
@@ -301,15 +213,7 @@ export const useFilePreview = ({
|
|
|
301
213
|
// Both compare dimensions, but the above is only for SSR in order to refetchSRRPreview and
|
|
302
214
|
// will swallow any errors. Below logic only applies when there is no card preview or the dimensions
|
|
303
215
|
// are bigger.
|
|
304
|
-
if (fileState &&
|
|
305
|
-
status,
|
|
306
|
-
fileState: fileState,
|
|
307
|
-
prevDimensions: prevRequestDimensions,
|
|
308
|
-
dimensions: requestDimensions,
|
|
309
|
-
hasCardPreview: !!cardPreview,
|
|
310
|
-
isBannedLocalPreview,
|
|
311
|
-
wasResolvedUpfrontPreview: wasResolvedUpfrontPreviewRef.current
|
|
312
|
-
})) {
|
|
216
|
+
if (fileState && wasResolvedUpfrontPreviewRef.current && isPreviewableStatus(status, extractFilePreviewStatus(fileState, isBannedLocalPreview)) && (!cardPreview || isBigger(prevRequestDimensions, requestDimensions))) {
|
|
313
217
|
resolvePreviewRef.current(identifier, fileState);
|
|
314
218
|
}
|
|
315
219
|
if (!skipRemote && ssr && !!cardPreview && isSSRClientPreview(cardPreview)) {
|
|
@@ -379,7 +283,7 @@ export const useFilePreview = ({
|
|
|
379
283
|
} else {
|
|
380
284
|
const e = new MediaFileStateError(fileState.id, fileState.reason, fileState.message, fileState.details);
|
|
381
285
|
const errorReason = status === 'uploading' ? 'upload' : 'metadata-fetch';
|
|
382
|
-
setError(new
|
|
286
|
+
setError(new MediaFilePreviewError(errorReason, e));
|
|
383
287
|
setStatus('error');
|
|
384
288
|
}
|
|
385
289
|
}
|
|
@@ -420,7 +324,7 @@ export const useFilePreview = ({
|
|
|
420
324
|
setNonCriticalError(error);
|
|
421
325
|
}
|
|
422
326
|
const fileImageMode = imageResizeModeToFileImageMode(resizeMode);
|
|
423
|
-
|
|
327
|
+
mediaFilePreviewCache.remove(identifier.id, fileImageMode);
|
|
424
328
|
setCardPreview(undefined);
|
|
425
329
|
} else {
|
|
426
330
|
if (!['complete', 'error', 'failed-processing'].includes(status)) {
|
|
@@ -479,24 +383,6 @@ export const useFilePreview = ({
|
|
|
479
383
|
getScriptProps
|
|
480
384
|
};
|
|
481
385
|
};
|
|
482
|
-
const createRequestDimensions = dimensions => {
|
|
483
|
-
if (!dimensions) {
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
const retinaFactor = isRetina() ? 2 : 1;
|
|
487
|
-
const {
|
|
488
|
-
width,
|
|
489
|
-
height
|
|
490
|
-
} = dimensions;
|
|
491
|
-
const result = {};
|
|
492
|
-
if (width) {
|
|
493
|
-
result.width = width * retinaFactor;
|
|
494
|
-
}
|
|
495
|
-
if (height) {
|
|
496
|
-
result.height = height * retinaFactor;
|
|
497
|
-
}
|
|
498
|
-
return result;
|
|
499
|
-
};
|
|
500
386
|
const initialSsrReliability = {
|
|
501
387
|
server: {
|
|
502
388
|
status: 'unknown'
|
|
@@ -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.
|
|
40
|
+
packageName: "77.5.1",
|
|
41
41
|
componentName: 'mediaInlineCard',
|
|
42
42
|
component: 'mediaInlineCard'
|
|
43
43
|
};
|
|
@@ -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.
|
|
7
|
+
const packageVersion = "77.5.1";
|
|
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.
|
|
43
|
+
var packageVersion = "77.5.1";
|
|
44
44
|
export var CardBase = /*#__PURE__*/function (_Component) {
|
|
45
45
|
_inherits(CardBase, _Component);
|
|
46
46
|
var _super = _createSuper(CardBase);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import React, { useContext } from 'react';
|
|
3
2
|
import Loadable from 'react-loadable';
|
|
4
3
|
import { CardLoading } from '../utils/lightCards/cardLoading';
|
|
@@ -7,55 +6,16 @@ var CardLoadingWithContext = function CardLoadingWithContext() {
|
|
|
7
6
|
var props = useContext(MediaCardContext);
|
|
8
7
|
return /*#__PURE__*/React.createElement(CardLoading, props);
|
|
9
8
|
};
|
|
10
|
-
var MediaCard = Loadable({
|
|
11
|
-
loader: function loader() {
|
|
12
|
-
return import( /* webpackChunkName: "@atlaskit-internal_media-card" */'./card').then(function (mod) {
|
|
13
|
-
return mod.Card;
|
|
14
|
-
});
|
|
15
|
-
},
|
|
16
|
-
loading: function loading() {
|
|
17
|
-
return /*#__PURE__*/React.createElement(CardLoadingWithContext, null);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
var MediaCardErrorBoundary = Loadable({
|
|
21
|
-
loader: function loader() {
|
|
22
|
-
return import( /* webpackChunkName: "@atlaskit-internal_media-card-error-boundary" */'./media-card-analytics-error-boundary').then(function (mod) {
|
|
23
|
-
return mod.default;
|
|
24
|
-
});
|
|
25
|
-
},
|
|
26
|
-
loading: function loading() {
|
|
27
|
-
return /*#__PURE__*/React.createElement(CardLoadingWithContext, null);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
9
|
var MediaCardWithMediaClient = Loadable({
|
|
31
10
|
loader: function loader() {
|
|
32
|
-
return import( /* webpackChunkName: "@atlaskit-internal_media-client
|
|
11
|
+
return import( /* webpackChunkName: "@atlaskit-internal_media-card-with-media-client" */'./cardWithMediaClient').then(function (mod) {
|
|
12
|
+
return mod.CardWithMediaClient;
|
|
13
|
+
});
|
|
33
14
|
},
|
|
34
15
|
loading: function loading() {
|
|
35
16
|
return /*#__PURE__*/React.createElement(CardLoadingWithContext, null);
|
|
36
|
-
},
|
|
37
|
-
render: function render(loaded, props) {
|
|
38
|
-
return /*#__PURE__*/React.createElement(CardWithMediaClient, _extends({}, props, {
|
|
39
|
-
withMediaClient: loaded.withMediaClient
|
|
40
|
-
}));
|
|
41
17
|
}
|
|
42
18
|
});
|
|
43
|
-
var CardWithMediaClient = function CardWithMediaClient(props) {
|
|
44
|
-
var withMediaClient = props.withMediaClient,
|
|
45
|
-
dimensions = props.dimensions,
|
|
46
|
-
onClick = props.onClick;
|
|
47
|
-
var Card = React.useMemo(function () {
|
|
48
|
-
return withMediaClient(MediaCard);
|
|
49
|
-
}, [withMediaClient]);
|
|
50
|
-
return (
|
|
51
|
-
/*#__PURE__*/
|
|
52
|
-
// onClick is passed into MediaCardErrorBoundary so MediaGroup items can get the toolbar menu in Editor
|
|
53
|
-
React.createElement(MediaCardErrorBoundary, {
|
|
54
|
-
dimensions: dimensions,
|
|
55
|
-
onClick: onClick
|
|
56
|
-
}, /*#__PURE__*/React.createElement(Card, props))
|
|
57
|
-
);
|
|
58
|
-
};
|
|
59
19
|
var CardLoader = function CardLoader(props) {
|
|
60
20
|
return /*#__PURE__*/React.createElement(MediaCardContext.Provider, {
|
|
61
21
|
value: props
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { withMediaClient } from '@atlaskit/media-client-react';
|
|
3
|
+
import { Card as MediaCard } from './card';
|
|
4
|
+
import MediaCardAnalyticsErrorBoundary from './media-card-analytics-error-boundary';
|
|
5
|
+
export var CardWithMediaClient = function CardWithMediaClient(props) {
|
|
6
|
+
var dimensions = props.dimensions,
|
|
7
|
+
onClick = props.onClick;
|
|
8
|
+
var Card = React.useMemo(function () {
|
|
9
|
+
return withMediaClient(MediaCard);
|
|
10
|
+
}, []);
|
|
11
|
+
return (
|
|
12
|
+
/*#__PURE__*/
|
|
13
|
+
// onClick is passed into MediaCardErrorBoundary so MediaGroup items can get the toolbar menu in Editor
|
|
14
|
+
React.createElement(MediaCardAnalyticsErrorBoundary, {
|
|
15
|
+
dimensions: dimensions,
|
|
16
|
+
onClick: onClick
|
|
17
|
+
}, /*#__PURE__*/React.createElement(Card, props))
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -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.
|
|
86
|
+
var packageVersion = "77.5.1";
|
|
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.
|
|
12
|
+
var packageVersion = "77.5.1";
|
|
13
13
|
export var CardV2Base = function CardV2Base(_ref) {
|
|
14
14
|
var identifier = _ref.identifier,
|
|
15
15
|
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
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; }
|
|
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; }
|
|
5
1
|
import React, { useContext } from 'react';
|
|
6
2
|
import Loadable from 'react-loadable';
|
|
7
3
|
import { CardLoading } from '../../utils/lightCards/cardLoading';
|
|
@@ -10,57 +6,14 @@ var CardLoadingWithContext = function CardLoadingWithContext() {
|
|
|
10
6
|
var props = useContext(MediaCardContext);
|
|
11
7
|
return /*#__PURE__*/React.createElement(CardLoading, props);
|
|
12
8
|
};
|
|
13
|
-
var MediaV2Card = Loadable({
|
|
14
|
-
loader: function loader() {
|
|
15
|
-
return import( /* webpackChunkName: "@atlaskit-internal_media-card-v2" */'./cardV2').then(function (mod) {
|
|
16
|
-
return mod.CardV2;
|
|
17
|
-
});
|
|
18
|
-
},
|
|
19
|
-
loading: function loading() {
|
|
20
|
-
return /*#__PURE__*/React.createElement(CardLoadingWithContext, null);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
var MediaCardErrorBoundary = Loadable({
|
|
24
|
-
loader: function loader() {
|
|
25
|
-
return import( /* webpackChunkName: "@atlaskit-internal_media-card-error-boundary" */'../media-card-analytics-error-boundary').then(function (mod) {
|
|
26
|
-
return mod.default;
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
loading: function loading() {
|
|
30
|
-
return /*#__PURE__*/React.createElement(CardLoadingWithContext, null);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
var CardWithMediaClient = function CardWithMediaClient(props) {
|
|
34
|
-
var dimensions = props.dimensions,
|
|
35
|
-
onClick = props.onClick,
|
|
36
|
-
withMediaClient = props.withMediaClient,
|
|
37
|
-
featureFlags = props.featureFlags;
|
|
38
|
-
var Card = React.useMemo(function () {
|
|
39
|
-
return withMediaClient(MediaV2Card);
|
|
40
|
-
}, [withMediaClient]);
|
|
41
|
-
var featureFlagsWithMediaCardV2 = React.useMemo(function () {
|
|
42
|
-
return _objectSpread(_objectSpread({}, featureFlags), {}, {
|
|
43
|
-
mediaCardV2: true //used for analytics - internal use only
|
|
44
|
-
});
|
|
45
|
-
}, [featureFlags]);
|
|
46
|
-
return /*#__PURE__*/React.createElement(MediaCardErrorBoundary, {
|
|
47
|
-
dimensions: dimensions,
|
|
48
|
-
onClick: onClick
|
|
49
|
-
}, /*#__PURE__*/React.createElement(Card, _extends({}, props, {
|
|
50
|
-
featureFlags: featureFlagsWithMediaCardV2
|
|
51
|
-
})));
|
|
52
|
-
};
|
|
53
9
|
var MediaCardWithMediaClientProvider = Loadable({
|
|
54
10
|
loader: function loader() {
|
|
55
|
-
return import( /* webpackChunkName: "@atlaskit-internal_media-client-
|
|
11
|
+
return import( /* webpackChunkName: "@atlaskit-internal_media-card-with-media-client-v2" */'./cardWithMediaClientV2').then(function (mod) {
|
|
12
|
+
return mod.CardWithMediaClientV2;
|
|
13
|
+
});
|
|
56
14
|
},
|
|
57
15
|
loading: function loading() {
|
|
58
16
|
return /*#__PURE__*/React.createElement(CardLoadingWithContext, null);
|
|
59
|
-
},
|
|
60
|
-
render: function render(loaded, props) {
|
|
61
|
-
return /*#__PURE__*/React.createElement(CardWithMediaClient, _extends({}, props, {
|
|
62
|
-
withMediaClient: loaded.withMediaClient
|
|
63
|
-
}));
|
|
64
17
|
}
|
|
65
18
|
});
|
|
66
19
|
var CardLoader = function CardLoader(props) {
|
|
@@ -75,18 +75,19 @@ export var CardViewV2Base = function CardViewV2Base(_ref) {
|
|
|
75
75
|
if (prevCardPreview.dataURI !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
|
-
|
|
79
78
|
/*
|
|
80
79
|
We render the icon & icon message always, even if there is cardPreview available.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
If the image fails to load/render, the icon will remain, i.e. the user won't see a change until the root card decides to chage status to error.
|
|
81
|
+
If the image renders successfully, we switch this variable to hide the icon & icon message behind the thumbnail in case the image has transparency.
|
|
82
|
+
It is less likely that root component replaces a suceeded cardPreview for a failed one than the opposite case. Therefore we prefer to hide the icon instead show when the image fails, for a smoother transition
|
|
84
83
|
*/
|
|
85
|
-
|
|
86
84
|
setDidImageRender(true);
|
|
87
85
|
onImageLoad === null || onImageLoad === void 0 || onImageLoad(cardPreview);
|
|
88
86
|
};
|
|
89
|
-
var handleOnImageError = function handleOnImageError(
|
|
87
|
+
var handleOnImageError = function handleOnImageError(prevCardPreview) {
|
|
88
|
+
if (prevCardPreview.dataURI !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
90
91
|
setDidImageRender(false);
|
|
91
92
|
onImageError === null || onImageError === void 0 || onImageError(cardPreview);
|
|
92
93
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
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; }
|
|
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; }
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { withMediaClient } from '@atlaskit/media-client-react';
|
|
7
|
+
import MediaCardAnalyticsErrorBoundary from '../media-card-analytics-error-boundary';
|
|
8
|
+
import { CardV2 } from './cardV2';
|
|
9
|
+
export var CardWithMediaClientV2 = function CardWithMediaClientV2(props) {
|
|
10
|
+
var dimensions = props.dimensions,
|
|
11
|
+
onClick = props.onClick,
|
|
12
|
+
featureFlags = props.featureFlags;
|
|
13
|
+
var Card = React.useMemo(function () {
|
|
14
|
+
return withMediaClient(CardV2);
|
|
15
|
+
}, []);
|
|
16
|
+
var featureFlagsWithMediaCardV2 = React.useMemo(function () {
|
|
17
|
+
return _objectSpread(_objectSpread({}, featureFlags), {}, {
|
|
18
|
+
mediaCardV2: true //used for analytics - internal use only
|
|
19
|
+
});
|
|
20
|
+
}, [featureFlags]);
|
|
21
|
+
return /*#__PURE__*/React.createElement(MediaCardAnalyticsErrorBoundary, {
|
|
22
|
+
dimensions: dimensions,
|
|
23
|
+
onClick: onClick
|
|
24
|
+
}, /*#__PURE__*/React.createElement(Card, _extends({}, props, {
|
|
25
|
+
featureFlags: featureFlagsWithMediaCardV2
|
|
26
|
+
})));
|
|
27
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
|
|
8
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
|
+
/**
|
|
11
|
+
* Primary reason is logged through Data Portal.
|
|
12
|
+
* Make sure all the values are whitelisted in Measure -> Event Regitry -> "mediaCardRender failed" event
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export var MediaFilePreviewError = /*#__PURE__*/function (_Error) {
|
|
16
|
+
_inherits(MediaFilePreviewError, _Error);
|
|
17
|
+
var _super = _createSuper(MediaFilePreviewError);
|
|
18
|
+
function MediaFilePreviewError(primaryReason, secondaryError) {
|
|
19
|
+
var _this;
|
|
20
|
+
_classCallCheck(this, MediaFilePreviewError);
|
|
21
|
+
_this = _super.call(this, primaryReason);
|
|
22
|
+
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
|
|
23
|
+
_this.primaryReason = primaryReason;
|
|
24
|
+
_this.secondaryError = secondaryError;
|
|
25
|
+
Object.setPrototypeOf(_assertThisInitialized(_this), (this instanceof MediaFilePreviewError ? this.constructor : void 0).prototype);
|
|
26
|
+
|
|
27
|
+
// https://v8.dev/docs/stack-trace-api
|
|
28
|
+
if ('captureStackTrace' in Error) {
|
|
29
|
+
Error.captureStackTrace(_assertThisInitialized(_this), this instanceof MediaFilePreviewError ? this.constructor : void 0);
|
|
30
|
+
}
|
|
31
|
+
return _this;
|
|
32
|
+
}
|
|
33
|
+
return _createClass(MediaFilePreviewError);
|
|
34
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
35
|
+
export var LocalPreviewError = /*#__PURE__*/function (_MediaFilePreviewErro) {
|
|
36
|
+
_inherits(LocalPreviewError, _MediaFilePreviewErro);
|
|
37
|
+
var _super2 = _createSuper(LocalPreviewError);
|
|
38
|
+
function LocalPreviewError(primaryReason, secondaryError) {
|
|
39
|
+
var _this2;
|
|
40
|
+
_classCallCheck(this, LocalPreviewError);
|
|
41
|
+
_this2 = _super2.call(this, primaryReason, secondaryError);
|
|
42
|
+
_this2.primaryReason = primaryReason;
|
|
43
|
+
_this2.secondaryError = secondaryError;
|
|
44
|
+
return _this2;
|
|
45
|
+
}
|
|
46
|
+
return _createClass(LocalPreviewError);
|
|
47
|
+
}(MediaFilePreviewError);
|
|
48
|
+
export var RemotePreviewError = /*#__PURE__*/function (_MediaFilePreviewErro2) {
|
|
49
|
+
_inherits(RemotePreviewError, _MediaFilePreviewErro2);
|
|
50
|
+
var _super3 = _createSuper(RemotePreviewError);
|
|
51
|
+
function RemotePreviewError(primaryReason, secondaryError) {
|
|
52
|
+
var _this3;
|
|
53
|
+
_classCallCheck(this, RemotePreviewError);
|
|
54
|
+
_this3 = _super3.call(this, primaryReason, secondaryError);
|
|
55
|
+
_this3.primaryReason = primaryReason;
|
|
56
|
+
_this3.secondaryError = secondaryError;
|
|
57
|
+
return _this3;
|
|
58
|
+
}
|
|
59
|
+
return _createClass(RemotePreviewError);
|
|
60
|
+
}(MediaFilePreviewError);
|
|
61
|
+
export var SsrPreviewError = /*#__PURE__*/function (_MediaFilePreviewErro3) {
|
|
62
|
+
_inherits(SsrPreviewError, _MediaFilePreviewErro3);
|
|
63
|
+
var _super4 = _createSuper(SsrPreviewError);
|
|
64
|
+
function SsrPreviewError(primaryReason, secondaryError) {
|
|
65
|
+
var _this4;
|
|
66
|
+
_classCallCheck(this, SsrPreviewError);
|
|
67
|
+
_this4 = _super4.call(this, primaryReason, secondaryError);
|
|
68
|
+
_this4.primaryReason = primaryReason;
|
|
69
|
+
_this4.secondaryError = secondaryError;
|
|
70
|
+
return _this4;
|
|
71
|
+
}
|
|
72
|
+
return _createClass(SsrPreviewError);
|
|
73
|
+
}(MediaFilePreviewError);
|
|
74
|
+
var getImageLoadPrimaryReason = function getImageLoadPrimaryReason(source) {
|
|
75
|
+
switch (source) {
|
|
76
|
+
case 'cache-remote':
|
|
77
|
+
return 'cache-remote-uri';
|
|
78
|
+
case 'cache-local':
|
|
79
|
+
return 'cache-local-uri';
|
|
80
|
+
case 'external':
|
|
81
|
+
return 'external-uri';
|
|
82
|
+
case 'local':
|
|
83
|
+
return 'local-uri';
|
|
84
|
+
case 'remote':
|
|
85
|
+
return 'remote-uri';
|
|
86
|
+
// This fail reason will come from a bug, most likely.
|
|
87
|
+
default:
|
|
88
|
+
return "unknown-uri";
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
export var ImageLoadError = /*#__PURE__*/function (_MediaFilePreviewErro4) {
|
|
92
|
+
_inherits(ImageLoadError, _MediaFilePreviewErro4);
|
|
93
|
+
var _super5 = _createSuper(ImageLoadError);
|
|
94
|
+
function ImageLoadError(source) {
|
|
95
|
+
_classCallCheck(this, ImageLoadError);
|
|
96
|
+
return _super5.call(this, getImageLoadPrimaryReason(source));
|
|
97
|
+
}
|
|
98
|
+
return _createClass(ImageLoadError);
|
|
99
|
+
}(MediaFilePreviewError);
|
|
100
|
+
export function isMediaFilePreviewError(err) {
|
|
101
|
+
return err instanceof MediaFilePreviewError;
|
|
102
|
+
}
|
|
103
|
+
export var isLocalPreviewError = function isLocalPreviewError(err) {
|
|
104
|
+
return err instanceof LocalPreviewError;
|
|
105
|
+
};
|
|
106
|
+
export var isRemotePreviewError = function isRemotePreviewError(err) {
|
|
107
|
+
return err instanceof RemotePreviewError;
|
|
108
|
+
};
|
|
109
|
+
export var isUnsupportedLocalPreviewError = function isUnsupportedLocalPreviewError(err) {
|
|
110
|
+
return isMediaFilePreviewError(err) && err.primaryReason === 'local-preview-unsupported';
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// In a try/catch statement, the error caught is the type of unknown.
|
|
114
|
+
// We can use this helper to ensure that the error handled is the type of MediaFilePreviewError if unsure
|
|
115
|
+
// If updatePrimaryReason is true, if it's a MediaFilePreviewError already, it will update it's primary reason
|
|
116
|
+
export var ensureMediaFilePreviewError = function ensureMediaFilePreviewError(primaryReason, error, updatePrimaryReason) {
|
|
117
|
+
if (isMediaFilePreviewError(error)) {
|
|
118
|
+
if (updatePrimaryReason && error.primaryReason !== primaryReason) {
|
|
119
|
+
return new MediaFilePreviewError(primaryReason, error.secondaryError);
|
|
120
|
+
}
|
|
121
|
+
return error;
|
|
122
|
+
}
|
|
123
|
+
return new MediaFilePreviewError(primaryReason, error);
|
|
124
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import { createObjectURLCache } from './objectURLCache';
|
|
5
|
+
|
|
6
|
+
// Dimensions are used to create a key.
|
|
7
|
+
// Cache is invalidated when different dimensions are provided.
|
|
8
|
+
export var getCacheKey = function getCacheKey(id, mode) {
|
|
9
|
+
var resizeMode = mode || 'crop';
|
|
10
|
+
return [id, resizeMode].join('-');
|
|
11
|
+
};
|
|
12
|
+
export var CardPreviewCacheImpl = /*#__PURE__*/_createClass(function CardPreviewCacheImpl(previewCache) {
|
|
13
|
+
var _this = this;
|
|
14
|
+
_classCallCheck(this, CardPreviewCacheImpl);
|
|
15
|
+
_defineProperty(this, "get", function (id, mode) {
|
|
16
|
+
var cacheKey = getCacheKey(id, mode);
|
|
17
|
+
return _this.previewCache.get(cacheKey);
|
|
18
|
+
});
|
|
19
|
+
_defineProperty(this, "set", function (id, mode, cardPreview) {
|
|
20
|
+
var cacheKey = getCacheKey(id, mode);
|
|
21
|
+
_this.previewCache.set(cacheKey, cardPreview);
|
|
22
|
+
});
|
|
23
|
+
_defineProperty(this, "remove", function (id, mode) {
|
|
24
|
+
var cacheKey = getCacheKey(id, mode);
|
|
25
|
+
_this.previewCache.remove(cacheKey);
|
|
26
|
+
});
|
|
27
|
+
_defineProperty(this, "clear", function () {
|
|
28
|
+
_this.previewCache.clear();
|
|
29
|
+
});
|
|
30
|
+
this.previewCache = previewCache;
|
|
31
|
+
});
|
|
32
|
+
export var mediaFilePreviewCache = new CardPreviewCacheImpl(createObjectURLCache());
|