@atlaskit/media-file-preview 0.0.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 +1 -0
- package/LICENSE.md +13 -0
- package/README.md +9 -0
- package/dist/cjs/analytics.js +50 -0
- package/dist/cjs/errors.js +143 -0
- package/dist/cjs/getPreview/cache.js +39 -0
- package/dist/cjs/getPreview/getPreview.js +119 -0
- package/dist/cjs/getPreview/helpers.js +167 -0
- package/dist/cjs/getPreview/index.js +56 -0
- package/dist/cjs/getPreview/objectURLCache.js +85 -0
- package/dist/cjs/getPreview/videoSnapshot.js +63 -0
- package/dist/cjs/globalScope/getSSRData.js +14 -0
- package/dist/cjs/globalScope/globalScope.js +66 -0
- package/dist/cjs/globalScope/index.js +37 -0
- package/dist/cjs/globalScope/printScript.js +32 -0
- package/dist/cjs/globalScope/types.js +5 -0
- package/dist/cjs/helpers.js +56 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/useFilePreview.js +355 -0
- package/dist/es2019/analytics.js +44 -0
- package/dist/es2019/errors.js +90 -0
- package/dist/es2019/getPreview/cache.js +30 -0
- package/dist/es2019/getPreview/getPreview.js +75 -0
- package/dist/es2019/getPreview/helpers.js +77 -0
- package/dist/es2019/getPreview/index.js +3 -0
- package/dist/es2019/getPreview/objectURLCache.js +44 -0
- package/dist/es2019/getPreview/videoSnapshot.js +41 -0
- package/dist/es2019/globalScope/getSSRData.js +8 -0
- package/dist/es2019/globalScope/globalScope.js +48 -0
- package/dist/es2019/globalScope/index.js +2 -0
- package/dist/es2019/globalScope/printScript.js +16 -0
- package/dist/es2019/globalScope/types.js +1 -0
- package/dist/es2019/helpers.js +53 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/useFilePreview.js +333 -0
- package/dist/esm/analytics.js +44 -0
- package/dist/esm/errors.js +133 -0
- package/dist/esm/getPreview/cache.js +32 -0
- package/dist/esm/getPreview/getPreview.js +112 -0
- package/dist/esm/getPreview/helpers.js +161 -0
- package/dist/esm/getPreview/index.js +3 -0
- package/dist/esm/getPreview/objectURLCache.js +78 -0
- package/dist/esm/getPreview/videoSnapshot.js +56 -0
- package/dist/esm/globalScope/getSSRData.js +8 -0
- package/dist/esm/globalScope/globalScope.js +56 -0
- package/dist/esm/globalScope/index.js +2 -0
- package/dist/esm/globalScope/printScript.js +25 -0
- package/dist/esm/globalScope/types.js +1 -0
- package/dist/esm/helpers.js +49 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/useFilePreview.js +348 -0
- package/dist/types/analytics.d.ts +28 -0
- package/dist/types/errors.d.ts +42 -0
- package/dist/types/getPreview/cache.d.ts +21 -0
- package/dist/types/getPreview/getPreview.d.ts +9 -0
- package/dist/types/getPreview/helpers.d.ts +10 -0
- package/dist/types/getPreview/index.d.ts +3 -0
- package/dist/types/getPreview/objectURLCache.d.ts +12 -0
- package/dist/types/getPreview/videoSnapshot.d.ts +1 -0
- package/dist/types/globalScope/getSSRData.d.ts +3 -0
- package/dist/types/globalScope/globalScope.d.ts +15 -0
- package/dist/types/globalScope/index.d.ts +4 -0
- package/dist/types/globalScope/printScript.d.ts +2 -0
- package/dist/types/globalScope/types.d.ts +8 -0
- package/dist/types/helpers.d.ts +10 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/types.d.ts +12 -0
- package/dist/types/useFilePreview.d.ts +33 -0
- package/dist/types-ts4.5/analytics.d.ts +28 -0
- package/dist/types-ts4.5/errors.d.ts +42 -0
- package/dist/types-ts4.5/getPreview/cache.d.ts +21 -0
- package/dist/types-ts4.5/getPreview/getPreview.d.ts +9 -0
- package/dist/types-ts4.5/getPreview/helpers.d.ts +10 -0
- package/dist/types-ts4.5/getPreview/index.d.ts +3 -0
- package/dist/types-ts4.5/getPreview/objectURLCache.d.ts +12 -0
- package/dist/types-ts4.5/getPreview/videoSnapshot.d.ts +1 -0
- package/dist/types-ts4.5/globalScope/getSSRData.d.ts +3 -0
- package/dist/types-ts4.5/globalScope/globalScope.d.ts +15 -0
- package/dist/types-ts4.5/globalScope/index.d.ts +4 -0
- package/dist/types-ts4.5/globalScope/printScript.d.ts +2 -0
- package/dist/types-ts4.5/globalScope/types.d.ts +8 -0
- package/dist/types-ts4.5/helpers.d.ts +10 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/types.d.ts +12 -0
- package/dist/types-ts4.5/useFilePreview.d.ts +33 -0
- package/package.json +98 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if at least one of next dimensions is bigger than current
|
|
4
|
+
* If a single dimension is undefined, returns false
|
|
5
|
+
*/
|
|
6
|
+
export var isBigger = function isBigger(current, next) {
|
|
7
|
+
var _ref = current || {},
|
|
8
|
+
currentWidth = _ref.width,
|
|
9
|
+
currentHeight = _ref.height;
|
|
10
|
+
var _ref2 = next || {},
|
|
11
|
+
nextWidth = _ref2.width,
|
|
12
|
+
nextHeight = _ref2.height;
|
|
13
|
+
if (!!currentWidth && !!currentHeight && !!nextWidth && !!nextHeight) {
|
|
14
|
+
var nextIsWider = currentWidth < nextWidth;
|
|
15
|
+
var nextIsHigher = currentHeight < nextHeight;
|
|
16
|
+
return nextIsHigher || nextIsWider;
|
|
17
|
+
} else {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Verifies if the current screen is retina display */
|
|
23
|
+
function isRetina() {
|
|
24
|
+
var mediaQuery = '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)';
|
|
25
|
+
return window.devicePixelRatio > 1 || window.matchMedia && window.matchMedia(mediaQuery).matches;
|
|
26
|
+
}
|
|
27
|
+
export var createRequestDimensions = function createRequestDimensions(dimensions) {
|
|
28
|
+
if (!dimensions) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
var retinaFactor = isRetina() ? 2 : 1;
|
|
32
|
+
var width = dimensions.width,
|
|
33
|
+
height = dimensions.height;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (width) {
|
|
36
|
+
result.width = width * retinaFactor;
|
|
37
|
+
}
|
|
38
|
+
if (height) {
|
|
39
|
+
result.height = height * retinaFactor;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Stores the provided value in a ref object to avoid "component rerenders" when the value is used as a hook dependency */
|
|
45
|
+
export function useCurrentValueRef(value) {
|
|
46
|
+
var ref = useRef(value);
|
|
47
|
+
ref.current = value;
|
|
48
|
+
return ref;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useFilePreview } from './useFilePreview';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
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 { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { imageResizeModeToFileImageMode, isImageRepresentationReady } from '@atlaskit/media-client';
|
|
7
|
+
import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
8
|
+
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
9
|
+
import { extractErrorInfo } from './analytics';
|
|
10
|
+
import { ensureMediaFilePreviewError, ImageLoadError, MediaFilePreviewError } from './errors';
|
|
11
|
+
import { getAndCacheLocalPreview, getAndCacheRemotePreview, getSSRPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, isSupportedLocalPreview, mediaFilePreviewCache } from './getPreview';
|
|
12
|
+
import { generateScriptProps, getSSRData } from './globalScope';
|
|
13
|
+
import { createRequestDimensions, isBigger, useCurrentValueRef } from './helpers';
|
|
14
|
+
export var useFilePreview = function useFilePreview(_ref) {
|
|
15
|
+
var _ref$resizeMode = _ref.resizeMode,
|
|
16
|
+
resizeMode = _ref$resizeMode === void 0 ? 'crop' : _ref$resizeMode,
|
|
17
|
+
identifier = _ref.identifier,
|
|
18
|
+
ssr = _ref.ssr,
|
|
19
|
+
dimensions = _ref.dimensions,
|
|
20
|
+
traceContext = _ref.traceContext,
|
|
21
|
+
previewDidRender = _ref.previewDidRender,
|
|
22
|
+
skipRemote = _ref.skipRemote,
|
|
23
|
+
mediaBlobUrlAttrs = _ref.mediaBlobUrlAttrs;
|
|
24
|
+
var mediaClient = useMediaClient();
|
|
25
|
+
var _useState = useState('loading'),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
status = _useState2[0],
|
|
28
|
+
setStatus = _useState2[1];
|
|
29
|
+
var _useState3 = useState(),
|
|
30
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
31
|
+
error = _useState4[0],
|
|
32
|
+
setError = _useState4[1];
|
|
33
|
+
var _useState5 = useState(),
|
|
34
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
35
|
+
nonCriticalError = _useState6[0],
|
|
36
|
+
setNonCriticalError = _useState6[1];
|
|
37
|
+
var _useState7 = useState(false),
|
|
38
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
39
|
+
isBannedLocalPreview = _useState8[0],
|
|
40
|
+
setIsBannedLocalPreview = _useState8[1];
|
|
41
|
+
var wasResolvedUpfrontPreviewRef = useRef(false);
|
|
42
|
+
var ssrReliabilityRef = useRef(initialSsrReliability);
|
|
43
|
+
var requestDimensions = useMemo(function () {
|
|
44
|
+
return dimensions ? createRequestDimensions(dimensions) : undefined;
|
|
45
|
+
}, [dimensions]);
|
|
46
|
+
var requestDimensionsRef = useCurrentValueRef(requestDimensions);
|
|
47
|
+
var imageURLParams = useMemo(function () {
|
|
48
|
+
return _objectSpread(_objectSpread({
|
|
49
|
+
collection: identifier.collectionName,
|
|
50
|
+
mode: resizeMode === 'stretchy-fit' ? 'full-fit' : resizeMode
|
|
51
|
+
}, requestDimensions), {}, {
|
|
52
|
+
allowAnimated: true
|
|
53
|
+
});
|
|
54
|
+
}, [requestDimensions, identifier.collectionName, resizeMode]);
|
|
55
|
+
var previewInitializer = function previewInitializer() {
|
|
56
|
+
var fileImageMode = imageResizeModeToFileImageMode(resizeMode);
|
|
57
|
+
var preview = mediaFilePreviewCache.get(identifier.id, fileImageMode);
|
|
58
|
+
if (preview) {
|
|
59
|
+
return preview;
|
|
60
|
+
}
|
|
61
|
+
if (ssr) {
|
|
62
|
+
var ssrData = getSSRData(identifier);
|
|
63
|
+
if (ssrData !== null && ssrData !== void 0 && ssrData.error) {
|
|
64
|
+
ssrReliabilityRef.current.server = _objectSpread({
|
|
65
|
+
status: 'fail'
|
|
66
|
+
}, ssrData.error);
|
|
67
|
+
}
|
|
68
|
+
if (!(ssrData !== null && ssrData !== void 0 && ssrData.dataURI)) {
|
|
69
|
+
try {
|
|
70
|
+
return getSSRPreview(ssr, mediaClient, identifier.id, imageURLParams, mediaBlobUrlAttrs);
|
|
71
|
+
} catch (e) {
|
|
72
|
+
ssrReliabilityRef.current[ssr] = _objectSpread({
|
|
73
|
+
status: 'fail'
|
|
74
|
+
}, extractErrorInfo(e));
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
var _dimensions = ssrData.dimensions,
|
|
78
|
+
dataURI = ssrData.dataURI;
|
|
79
|
+
return {
|
|
80
|
+
dataURI: dataURI,
|
|
81
|
+
dimensions: _dimensions,
|
|
82
|
+
source: 'ssr-data'
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var _useState9 = useState(previewInitializer),
|
|
88
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
89
|
+
preview = _useState10[0],
|
|
90
|
+
setPreview = _useState10[1];
|
|
91
|
+
var _useFileState = useFileState(identifier.id, {
|
|
92
|
+
skipRemote: skipRemote,
|
|
93
|
+
collectionName: identifier.collectionName,
|
|
94
|
+
occurrenceKey: identifier.occurrenceKey
|
|
95
|
+
}),
|
|
96
|
+
fileState = _useFileState.fileState;
|
|
97
|
+
|
|
98
|
+
//----------------------------------------------------------------
|
|
99
|
+
// Update status
|
|
100
|
+
//----------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
// TOOD: make a full hook reset (remount) on New identifier or client
|
|
103
|
+
useEffect(function () {
|
|
104
|
+
setStatus('loading');
|
|
105
|
+
}, [identifier]);
|
|
106
|
+
var updateFileStateRef = useCurrentValueRef(function () {
|
|
107
|
+
if (fileState) {
|
|
108
|
+
// do not update the status if the status is final
|
|
109
|
+
if (['complete', 'error', 'failed-processing'].includes(status)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (fileState.status !== 'error') {
|
|
113
|
+
var mediaType = 'mediaType' in fileState ? fileState.mediaType : undefined;
|
|
114
|
+
var isPreviewable = !!mediaType && ['audio', 'video', 'image', 'doc'].indexOf(mediaType) > -1;
|
|
115
|
+
var isPreviewableFileState = !!fileState.preview;
|
|
116
|
+
var _isSupportedLocalPreview = mediaType === 'image' || mediaType === 'video';
|
|
117
|
+
var hasLocalPreview = !isBannedLocalPreview && isPreviewableFileState && _isSupportedLocalPreview && !!fileState.mimeType && isMimeTypeSupportedByBrowser(fileState.mimeType);
|
|
118
|
+
var hasRemotePreview = isImageRepresentationReady(fileState);
|
|
119
|
+
var hasPreview = hasLocalPreview || hasRemotePreview;
|
|
120
|
+
var newStatus;
|
|
121
|
+
switch (fileState.status) {
|
|
122
|
+
case 'uploading':
|
|
123
|
+
case 'failed-processing':
|
|
124
|
+
case 'processing':
|
|
125
|
+
newStatus = fileState.status;
|
|
126
|
+
break;
|
|
127
|
+
case 'processed':
|
|
128
|
+
if (!isPreviewable || !hasPreview) {
|
|
129
|
+
newStatus = 'complete';
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
newStatus = 'loading-preview';
|
|
133
|
+
break;
|
|
134
|
+
default:
|
|
135
|
+
newStatus = 'loading';
|
|
136
|
+
}
|
|
137
|
+
setStatus(newStatus);
|
|
138
|
+
} else {
|
|
139
|
+
var e = new MediaFileStateError(fileState.id, fileState.reason, fileState.message, fileState.details);
|
|
140
|
+
var errorReason = status === 'uploading' ? 'upload' : 'metadata-fetch';
|
|
141
|
+
setError(new MediaFilePreviewError(errorReason, e));
|
|
142
|
+
setStatus('error');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
useEffect(function () {
|
|
147
|
+
updateFileStateRef.current();
|
|
148
|
+
}, [fileState, updateFileStateRef]);
|
|
149
|
+
useEffect(function () {
|
|
150
|
+
if (previewDidRender &&
|
|
151
|
+
// We should't complete if status is uploading
|
|
152
|
+
['loading-preview', 'processing'].includes(status)) {
|
|
153
|
+
setStatus('complete');
|
|
154
|
+
// TODO MEX-788: add test for "do not remove the preview when unsubscribing".
|
|
155
|
+
setIsBannedLocalPreview(false); // CXP-2723 TODO: we might be able to remove this??
|
|
156
|
+
}
|
|
157
|
+
}, [previewDidRender, status]);
|
|
158
|
+
|
|
159
|
+
// CXP-2723 TODO: Create test cases for banning local preview after status is complete
|
|
160
|
+
|
|
161
|
+
//----------------------------------------------------------------
|
|
162
|
+
// Preview Fetch Helper
|
|
163
|
+
//----------------------------------------------------------------
|
|
164
|
+
var getAndCacheRemotePreviewRef = useCurrentValueRef(function () {
|
|
165
|
+
return getAndCacheRemotePreview(mediaClient, identifier.id, requestDimensions || {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
//----------------------------------------------------------------
|
|
169
|
+
// Cache SSR Preview
|
|
170
|
+
//----------------------------------------------------------------
|
|
171
|
+
useEffect(function () {
|
|
172
|
+
if (!skipRemote && ssr && !!preview && isSSRClientPreview(preview)) {
|
|
173
|
+
// Since the SSR preview brings the token in the query params,
|
|
174
|
+
// We need to fetch the remote preview to be able to cache it,
|
|
175
|
+
getAndCacheRemotePreviewRef.current().catch(function () {
|
|
176
|
+
// No need to log this error.
|
|
177
|
+
// If preview fails, it will be refetched later
|
|
178
|
+
//TODO: test this catch
|
|
179
|
+
// https://product-fabric.atlassian.net/browse/MEX-1071
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}, [getAndCacheRemotePreviewRef, preview, skipRemote, ssr]);
|
|
183
|
+
|
|
184
|
+
//----------------------------------------------------------------
|
|
185
|
+
// Refetch SRR Preview if dimensions from Server have changed and are bigger,
|
|
186
|
+
//----------------------------------------------------------------
|
|
187
|
+
useEffect(function () {
|
|
188
|
+
// CXP-2813 TODO: This is called too many times if the refetch failed. Should be called only once
|
|
189
|
+
if (preview && !skipRemote && isSSRDataPreview(preview) && isBigger(preview.dimensions, requestDimensions)) {
|
|
190
|
+
getAndCacheRemotePreviewRef.current().then(setPreview).catch(function (e) {
|
|
191
|
+
var wrappedError = ensureMediaFilePreviewError('remote-preview-fetch-ssr', e, true);
|
|
192
|
+
setNonCriticalError(wrappedError);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}, [getAndCacheRemotePreviewRef, preview, requestDimensions, skipRemote]);
|
|
196
|
+
|
|
197
|
+
//----------------------------------------------------------------
|
|
198
|
+
// Upfront Preview
|
|
199
|
+
//----------------------------------------------------------------
|
|
200
|
+
useEffect(function () {
|
|
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
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}, [getAndCacheRemotePreviewRef, preview, requestDimensions, requestDimensionsRef, skipRemote]);
|
|
217
|
+
|
|
218
|
+
//----------------------------------------------------------------
|
|
219
|
+
// Cache, Local & Remote Preview
|
|
220
|
+
//----------------------------------------------------------------
|
|
221
|
+
|
|
222
|
+
useEffect(function () {
|
|
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
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}, [fileState, getAndCacheRemotePreviewRef, identifier.id, imageURLParams.mode, isBannedLocalPreview, mediaBlobUrlAttrs, preview, requestDimensions, skipRemote]);
|
|
249
|
+
|
|
250
|
+
//----------------------------------------------------------------
|
|
251
|
+
// RETURN
|
|
252
|
+
//----------------------------------------------------------------
|
|
253
|
+
|
|
254
|
+
var onImageError = useCallback(function (newPreview) {
|
|
255
|
+
if (newPreview) {
|
|
256
|
+
var failedSSRObject = _objectSpread({
|
|
257
|
+
status: 'fail'
|
|
258
|
+
}, extractErrorInfo(new ImageLoadError(newPreview.source)));
|
|
259
|
+
if (isSSRClientPreview(newPreview)) {
|
|
260
|
+
ssrReliabilityRef.current.client = failedSSRObject;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/*
|
|
264
|
+
If the preview failed and it comes from server (global scope / ssrData), it means that we have reused it in client and the error counts for both: server & client.
|
|
265
|
+
*/
|
|
266
|
+
|
|
267
|
+
if (isSSRDataPreview(newPreview)) {
|
|
268
|
+
ssrReliabilityRef.current.server = failedSSRObject;
|
|
269
|
+
ssrReliabilityRef.current.client = failedSSRObject;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// If the dataURI has been replaced, we can dismiss this error
|
|
274
|
+
if ((newPreview === null || newPreview === void 0 ? void 0 : newPreview.dataURI) !== (preview === null || preview === void 0 ? void 0 : preview.dataURI)) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
var error = new ImageLoadError(newPreview === null || newPreview === void 0 ? void 0 : newPreview.source);
|
|
278
|
+
var isLocal = newPreview && isLocalPreview(newPreview);
|
|
279
|
+
var isSSR = newPreview && (isSSRClientPreview(newPreview) || isSSRDataPreview(newPreview));
|
|
280
|
+
if (isLocal || isSSR) {
|
|
281
|
+
if (isLocal) {
|
|
282
|
+
setIsBannedLocalPreview(true);
|
|
283
|
+
setNonCriticalError(error);
|
|
284
|
+
}
|
|
285
|
+
var fileImageMode = imageResizeModeToFileImageMode(resizeMode);
|
|
286
|
+
mediaFilePreviewCache.remove(identifier.id, fileImageMode);
|
|
287
|
+
setPreview(undefined);
|
|
288
|
+
} else {
|
|
289
|
+
if (!['complete', 'error', 'failed-processing'].includes(status)) {
|
|
290
|
+
setStatus('error');
|
|
291
|
+
setError(error);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}, [identifier.id, preview === null || preview === void 0 ? void 0 : preview.dataURI, resizeMode, status]);
|
|
295
|
+
var onImageLoad = useCallback(function (newPreview) {
|
|
296
|
+
if (newPreview) {
|
|
297
|
+
if (isSSRClientPreview(newPreview) && ssrReliabilityRef.current.client.status === 'unknown') {
|
|
298
|
+
ssrReliabilityRef.current.client = {
|
|
299
|
+
status: 'success'
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/*
|
|
304
|
+
If the image loads successfully and it comes from server (global scope / ssrData), it means that we have reused it in client and the success counts for both: server & client.
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
if (isSSRDataPreview(newPreview) && ssrReliabilityRef.current.server.status === 'unknown') {
|
|
308
|
+
ssrReliabilityRef.current.server = {
|
|
309
|
+
status: 'success'
|
|
310
|
+
};
|
|
311
|
+
ssrReliabilityRef.current.client = {
|
|
312
|
+
status: 'success'
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// If the dataURI has been replaced, we can dismiss this callback
|
|
318
|
+
if ((newPreview === null || newPreview === void 0 ? void 0 : newPreview.dataURI) !== (preview === null || preview === void 0 ? void 0 : preview.dataURI)) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
}, [preview === null || preview === void 0 ? void 0 : preview.dataURI]);
|
|
322
|
+
|
|
323
|
+
// FOR SSR
|
|
324
|
+
var getScriptProps = function getScriptProps() {
|
|
325
|
+
var _ssrReliabilityRef$cu;
|
|
326
|
+
return generateScriptProps(identifier, preview === null || preview === void 0 ? void 0 : preview.dataURI, requestDimensions, ((_ssrReliabilityRef$cu = ssrReliabilityRef.current.server) === null || _ssrReliabilityRef$cu === void 0 ? void 0 : _ssrReliabilityRef$cu.status) === 'fail' ? ssrReliabilityRef.current.server : undefined);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// CXP-2723 TODO: should consider simplifying our analytics, and how
|
|
330
|
+
// we might get rid of ssrReliabiltyRef from our hook
|
|
331
|
+
return {
|
|
332
|
+
preview: preview,
|
|
333
|
+
error: error,
|
|
334
|
+
nonCriticalError: nonCriticalError,
|
|
335
|
+
ssrReliabilityRef: ssrReliabilityRef,
|
|
336
|
+
onImageError: onImageError,
|
|
337
|
+
onImageLoad: onImageLoad,
|
|
338
|
+
getScriptProps: getScriptProps
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
var initialSsrReliability = {
|
|
342
|
+
server: {
|
|
343
|
+
status: 'unknown'
|
|
344
|
+
},
|
|
345
|
+
client: {
|
|
346
|
+
status: 'unknown'
|
|
347
|
+
}
|
|
348
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MediaClientErrorReason } from '@atlaskit/media-client';
|
|
2
|
+
import { MediaTraceContext, SuccessAttributes } from '@atlaskit/media-common';
|
|
3
|
+
import { MediaFilePreviewError, MediaFilePreviewErrorPrimaryReason } from './errors';
|
|
4
|
+
export type FailedErrorFailReason = MediaFilePreviewErrorPrimaryReason | 'nativeError';
|
|
5
|
+
export type MediaFilePreviewErrorInfo = {
|
|
6
|
+
failReason: FailedErrorFailReason;
|
|
7
|
+
error: MediaClientErrorReason | 'nativeError';
|
|
8
|
+
errorDetail: string;
|
|
9
|
+
metadataTraceContext?: MediaTraceContext;
|
|
10
|
+
};
|
|
11
|
+
export type SSRStatusFail = MediaFilePreviewErrorInfo & {
|
|
12
|
+
status: 'fail';
|
|
13
|
+
};
|
|
14
|
+
type SSRStatusSuccess = SuccessAttributes;
|
|
15
|
+
type SSRStatusUnknown = {
|
|
16
|
+
status: 'unknown';
|
|
17
|
+
};
|
|
18
|
+
type SSRStatusAttributes = SSRStatusSuccess | SSRStatusFail | SSRStatusUnknown;
|
|
19
|
+
export type SSRStatus = {
|
|
20
|
+
server: SSRStatusAttributes;
|
|
21
|
+
client: SSRStatusAttributes;
|
|
22
|
+
};
|
|
23
|
+
export declare const getErrorTraceContext: (error: MediaFilePreviewError) => MediaTraceContext | undefined;
|
|
24
|
+
export declare const getRenderErrorFailReason: (error: MediaFilePreviewError) => FailedErrorFailReason;
|
|
25
|
+
export declare const getRenderErrorErrorReason: (error: MediaFilePreviewError) => MediaClientErrorReason | 'nativeError';
|
|
26
|
+
export declare const getRenderErrorErrorDetail: (error: MediaFilePreviewError) => string;
|
|
27
|
+
export declare const extractErrorInfo: (error: MediaFilePreviewError, metadataTraceContext?: MediaTraceContext) => MediaFilePreviewErrorInfo;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MediaClientErrorReason } from '@atlaskit/media-client';
|
|
2
|
+
import { MediaFileStateError } from '@atlaskit/media-client-react';
|
|
3
|
+
import { MediaFilePreview } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Primary reason is logged through Data Portal.
|
|
6
|
+
* Make sure all the values are whitelisted in Measure -> Event Regitry -> "mediaCardRender failed" event
|
|
7
|
+
*/
|
|
8
|
+
export type MediaFilePreviewErrorPrimaryReason = 'upload' | 'metadata-fetch' | 'error-file-state' | RemotePreviewPrimaryReason | LocalPreviewPrimaryReason | ImageLoadPrimaryReason | SsrPreviewPrimaryReason | 'missing-error-data' | 'preview-fetch';
|
|
9
|
+
export type ImageLoadPrimaryReason = 'cache-remote-uri' | 'cache-local-uri' | 'local-uri' | 'remote-uri' | 'external-uri' | 'unknown-uri';
|
|
10
|
+
export type RemotePreviewPrimaryReason = 'remote-preview-fetch' | 'remote-preview-not-ready' | 'remote-preview-fetch-ssr';
|
|
11
|
+
export type LocalPreviewPrimaryReason = 'local-preview-get' | 'local-preview-unsupported' | 'local-preview-rejected' | 'local-preview-image' | 'local-preview-video';
|
|
12
|
+
export type SsrPreviewPrimaryReason = 'ssr-client-uri' | 'ssr-client-load' | 'ssr-server-uri' | 'ssr-server-load';
|
|
13
|
+
export declare class MediaFilePreviewError extends Error {
|
|
14
|
+
readonly primaryReason: MediaFilePreviewErrorPrimaryReason;
|
|
15
|
+
readonly secondaryError?: Error | undefined;
|
|
16
|
+
constructor(primaryReason: MediaFilePreviewErrorPrimaryReason, secondaryError?: Error | undefined);
|
|
17
|
+
}
|
|
18
|
+
export declare class LocalPreviewError extends MediaFilePreviewError {
|
|
19
|
+
readonly primaryReason: LocalPreviewPrimaryReason;
|
|
20
|
+
readonly secondaryError?: Error | undefined;
|
|
21
|
+
constructor(primaryReason: LocalPreviewPrimaryReason, secondaryError?: Error | undefined);
|
|
22
|
+
}
|
|
23
|
+
export declare class RemotePreviewError extends MediaFilePreviewError {
|
|
24
|
+
readonly primaryReason: RemotePreviewPrimaryReason;
|
|
25
|
+
readonly secondaryError?: Error | undefined;
|
|
26
|
+
constructor(primaryReason: RemotePreviewPrimaryReason, secondaryError?: Error | undefined);
|
|
27
|
+
}
|
|
28
|
+
export declare class SsrPreviewError extends MediaFilePreviewError {
|
|
29
|
+
readonly primaryReason: SsrPreviewPrimaryReason;
|
|
30
|
+
readonly secondaryError?: Error | undefined;
|
|
31
|
+
constructor(primaryReason: SsrPreviewPrimaryReason, secondaryError?: Error | undefined);
|
|
32
|
+
}
|
|
33
|
+
export declare class ImageLoadError extends MediaFilePreviewError {
|
|
34
|
+
constructor(source?: MediaFilePreview['source']);
|
|
35
|
+
}
|
|
36
|
+
export declare function isMediaFilePreviewError(err: Error): err is MediaFilePreviewError;
|
|
37
|
+
export declare const isLocalPreviewError: (err: Error) => err is LocalPreviewError;
|
|
38
|
+
export declare const isRemotePreviewError: (err: Error) => err is RemotePreviewError;
|
|
39
|
+
export declare const isUnsupportedLocalPreviewError: (err: Error) => boolean;
|
|
40
|
+
export declare const ensureMediaFilePreviewError: (primaryReason: MediaFilePreviewErrorPrimaryReason, error: Error, updatePrimaryReason?: boolean) => MediaFilePreviewError;
|
|
41
|
+
export declare function isMediaFileStateError(err: Error): err is MediaFileStateError;
|
|
42
|
+
export declare function getFileStateErrorReason(err: MediaFileStateError): MediaClientErrorReason | 'unknown';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ImageResizeMode } from '@atlaskit/media-client';
|
|
2
|
+
import { MediaFilePreview } from '../types';
|
|
3
|
+
import { ObjectURLCache } from './objectURLCache';
|
|
4
|
+
type Mode = ImageResizeMode | undefined;
|
|
5
|
+
export declare const getCacheKey: (id: string, mode: Mode) => string;
|
|
6
|
+
export interface MediaFilePreviewCache {
|
|
7
|
+
get(id: string, mode: Mode): MediaFilePreview | undefined;
|
|
8
|
+
set(id: string, mode: Mode, cardPreview: MediaFilePreview): void;
|
|
9
|
+
remove(id: string, mode: Mode): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class CardPreviewCacheImpl implements MediaFilePreviewCache {
|
|
13
|
+
private previewCache;
|
|
14
|
+
constructor(previewCache: ObjectURLCache);
|
|
15
|
+
get: (id: string, mode: Mode) => MediaFilePreview | undefined;
|
|
16
|
+
set: (id: string, mode: Mode, cardPreview: MediaFilePreview) => void;
|
|
17
|
+
remove: (id: string, mode: Mode) => void;
|
|
18
|
+
clear: () => void;
|
|
19
|
+
}
|
|
20
|
+
export declare const mediaFilePreviewCache: CardPreviewCacheImpl;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FilePreview, MediaBlobUrlAttrs, MediaClient, MediaStoreGetFileImageParams } from '@atlaskit/media-client';
|
|
2
|
+
import { MediaTraceContext, SSR } from '@atlaskit/media-common';
|
|
3
|
+
import { MediaFilePreview, MediaFilePreviewDimensions } from '../types';
|
|
4
|
+
export declare const getSSRPreview: (ssr: SSR, mediaClient: MediaClient, id: string, params: MediaStoreGetFileImageParams, mediaBlobUrlAttrs?: MediaBlobUrlAttrs) => MediaFilePreview;
|
|
5
|
+
export declare const isLocalPreview: (preview: MediaFilePreview) => boolean;
|
|
6
|
+
export declare const isSSRClientPreview: (preview: MediaFilePreview) => boolean;
|
|
7
|
+
export declare const isSSRDataPreview: (preview: MediaFilePreview) => boolean;
|
|
8
|
+
export declare const getAndCacheRemotePreview: (mediaClient: MediaClient, id: string, dimensions: MediaFilePreviewDimensions, params: MediaStoreGetFileImageParams, mediaBlobUrlAttrs?: MediaBlobUrlAttrs, traceContext?: MediaTraceContext) => Promise<MediaFilePreview>;
|
|
9
|
+
export declare const getAndCacheLocalPreview: (id: string, filePreview: FilePreview | Promise<FilePreview>, dimensions: MediaFilePreviewDimensions, mode: MediaStoreGetFileImageParams['mode'], mediaBlobUrlAttrs?: MediaBlobUrlAttrs) => Promise<MediaFilePreview>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FilePreview, MediaClient, MediaStoreGetFileImageParams, MediaType } from '@atlaskit/media-client';
|
|
2
|
+
import { MediaTraceContext } from '@atlaskit/media-common';
|
|
3
|
+
import { MediaFilePreview } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* This method tells the support for the media
|
|
6
|
+
* types covered in getCardPreviewFromFilePreview
|
|
7
|
+
*/
|
|
8
|
+
export declare const isSupportedLocalPreview: (mediaType?: MediaType) => boolean;
|
|
9
|
+
export declare const getLocalPreview: (filePreview: FilePreview | Promise<FilePreview>) => Promise<MediaFilePreview>;
|
|
10
|
+
export declare const getRemotePreview: (mediaClient: MediaClient, id: string, params: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext) => Promise<MediaFilePreview>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MediaFilePreview } from '../types';
|
|
2
|
+
export declare const PREVIEW_CACHE_LRU_SIZE = 50;
|
|
3
|
+
export declare class ObjectURLCache {
|
|
4
|
+
private readonly cache;
|
|
5
|
+
constructor(size: number);
|
|
6
|
+
has(key: string): boolean;
|
|
7
|
+
get(key: string): MediaFilePreview | undefined;
|
|
8
|
+
set(key: string, value: MediaFilePreview): void;
|
|
9
|
+
remove(key: string): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
}
|
|
12
|
+
export declare const createObjectURLCache: () => ObjectURLCache;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const takeSnapshot: (blob: Blob) => Promise<string>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FileIdentifier } from '@atlaskit/media-client';
|
|
3
|
+
import { NumericalCardDimensions } from '@atlaskit/media-common';
|
|
4
|
+
import { MediaFilePreviewErrorInfo } from '../analytics';
|
|
5
|
+
import { MediaCardSsr } from './types';
|
|
6
|
+
export declare const GLOBAL_MEDIA_CARD_SSR = "mediaCardSsr";
|
|
7
|
+
export declare const GLOBAL_MEDIA_NAMESPACE = "__MEDIA_INTERNAL";
|
|
8
|
+
export type MediaGlobalScope = {
|
|
9
|
+
[GLOBAL_MEDIA_CARD_SSR]?: MediaCardSsr;
|
|
10
|
+
};
|
|
11
|
+
export declare function getMediaGlobalScope(globalScope?: any): MediaGlobalScope;
|
|
12
|
+
export declare function getMediaCardSSR(globalScope?: any): MediaCardSsr;
|
|
13
|
+
export declare const getKey: ({ id, collectionName, occurrenceKey }: FileIdentifier) => string;
|
|
14
|
+
export declare const storeDataURI: (key: string, dataURI?: string, dimensions?: Partial<NumericalCardDimensions>, error?: MediaFilePreviewErrorInfo, globalScope?: any) => void;
|
|
15
|
+
export declare const generateScriptProps: (identifier: FileIdentifier, dataURI?: string, dimensions?: Partial<NumericalCardDimensions>, error?: MediaFilePreviewErrorInfo) => React.ScriptHTMLAttributes<HTMLScriptElement>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { GLOBAL_MEDIA_NAMESPACE, GLOBAL_MEDIA_CARD_SSR, generateScriptProps, getKey, } from './globalScope';
|
|
2
|
+
export { getSSRData } from './getSSRData';
|
|
3
|
+
export type { MediaCardSsrData, MediaCardSsr } from './types';
|
|
4
|
+
export type { MediaGlobalScope } from './globalScope';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NumericalCardDimensions } from '@atlaskit/media-common';
|
|
2
|
+
import { MediaFilePreviewErrorInfo } from '../analytics';
|
|
3
|
+
export type MediaCardSsrData = {
|
|
4
|
+
dataURI?: string;
|
|
5
|
+
dimensions?: Partial<NumericalCardDimensions>;
|
|
6
|
+
error?: MediaFilePreviewErrorInfo;
|
|
7
|
+
};
|
|
8
|
+
export type MediaCardSsr = Record<string, MediaCardSsrData>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
import { MediaFilePreviewDimensions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Checks if at least one of next dimensions is bigger than current
|
|
5
|
+
* If a single dimension is undefined, returns false
|
|
6
|
+
*/
|
|
7
|
+
export declare const isBigger: (current?: MediaFilePreviewDimensions, next?: MediaFilePreviewDimensions) => boolean;
|
|
8
|
+
export declare const createRequestDimensions: (dimensions: Partial<MediaFilePreviewDimensions>) => Partial<MediaFilePreviewDimensions> | undefined;
|
|
9
|
+
/** Stores the provided value in a ref object to avoid "component rerenders" when the value is used as a hook dependency */
|
|
10
|
+
export declare function useCurrentValueRef<T>(value: T): MutableRefObject<T>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type MediaFilePreviewSource = 'local' | 'remote' | 'ssr-server' | 'ssr-client' | 'ssr-data' | 'cache-local' | 'cache-remote' | 'cache-ssr-client' | 'cache-ssr-server' | 'external';
|
|
2
|
+
export type MediaFilePreviewDimensions = {
|
|
3
|
+
width?: number;
|
|
4
|
+
height?: number;
|
|
5
|
+
};
|
|
6
|
+
export interface MediaFilePreview {
|
|
7
|
+
dataURI: string;
|
|
8
|
+
orientation?: number;
|
|
9
|
+
dimensions?: MediaFilePreviewDimensions;
|
|
10
|
+
source: MediaFilePreviewSource;
|
|
11
|
+
}
|
|
12
|
+
export type MediaFilePreviewStatus = 'uploading' | 'loading' | 'processing' | 'loading-preview' | 'complete' | 'error' | 'failed-processing';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FileIdentifier, ImageResizeMode, MediaBlobUrlAttrs } from '@atlaskit/media-client';
|
|
3
|
+
import { MediaTraceContext, SSR } from '@atlaskit/media-common';
|
|
4
|
+
import { SSRStatus } from './analytics';
|
|
5
|
+
import { MediaFilePreviewError } from './errors';
|
|
6
|
+
import { MediaFilePreview, MediaFilePreviewDimensions } from './types';
|
|
7
|
+
export interface UseFilePreviewParams {
|
|
8
|
+
/** Instance of file identifier. */
|
|
9
|
+
readonly identifier: FileIdentifier;
|
|
10
|
+
/** Resize the media to 'crop' | 'fit' | 'full-fit' | 'stretchy-fit' */
|
|
11
|
+
readonly resizeMode?: ImageResizeMode;
|
|
12
|
+
/** Dimensions to be requested to the server. Will be scaled x2 in Retina Displays */
|
|
13
|
+
readonly dimensions?: MediaFilePreviewDimensions;
|
|
14
|
+
/** Server-Side-Rendering modes are "server" and "client" */
|
|
15
|
+
readonly ssr?: SSR;
|
|
16
|
+
/** Attributes to attach to the created Blob Url */
|
|
17
|
+
readonly mediaBlobUrlAttrs?: MediaBlobUrlAttrs;
|
|
18
|
+
/** Trace context to be passed to the backend requests */
|
|
19
|
+
readonly traceContext?: MediaTraceContext;
|
|
20
|
+
/** Notify the hook that the preview successfully rendered */
|
|
21
|
+
readonly previewDidRender?: boolean;
|
|
22
|
+
/** Do not fetch a remote preview. Helpful for lazy loading */
|
|
23
|
+
readonly skipRemote?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare const useFilePreview: ({ resizeMode, identifier, ssr, dimensions, traceContext, previewDidRender, skipRemote, mediaBlobUrlAttrs, }: UseFilePreviewParams) => {
|
|
26
|
+
preview: MediaFilePreview | undefined;
|
|
27
|
+
error: MediaFilePreviewError | undefined;
|
|
28
|
+
nonCriticalError: MediaFilePreviewError | undefined;
|
|
29
|
+
ssrReliabilityRef: import("react").MutableRefObject<SSRStatus>;
|
|
30
|
+
onImageError: (newPreview?: MediaFilePreview) => void;
|
|
31
|
+
onImageLoad: (newPreview?: MediaFilePreview) => void;
|
|
32
|
+
getScriptProps: () => import("react").ScriptHTMLAttributes<HTMLScriptElement>;
|
|
33
|
+
};
|