@atlaskit/media-file-preview 0.2.1 → 0.3.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/useFilePreview.js +9 -6
- package/dist/es2019/useFilePreview.js +11 -7
- package/dist/esm/useFilePreview.js +10 -7
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/useFilePreview.d.ts +1 -1
- package/dist/types-ts4.5/errors.d.ts +1 -1
- package/dist/types-ts4.5/useFilePreview.d.ts +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/media-file-preview
|
|
2
2
|
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#70361](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70361) [`6bcee8c57dac`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6bcee8c57dac) - Support for files failed to process
|
|
8
|
+
|
|
9
|
+
## 0.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#70034](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70034) [`0cf829b2ca1f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0cf829b2ca1f) - Breaking: renamed return value from getScriptProps to getSsrScriptProps
|
|
14
|
+
|
|
3
15
|
## 0.2.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -114,10 +114,13 @@ var useFilePreview = exports.useFilePreview = function useFilePreview(_ref) {
|
|
|
114
114
|
}, [identifier]);
|
|
115
115
|
(0, _react.useEffect)(function () {
|
|
116
116
|
if (status !== 'error') {
|
|
117
|
-
if (
|
|
118
|
-
setStatus('loading');
|
|
119
|
-
} else {
|
|
117
|
+
if (preview || fileState && fileState.status === 'processed' && !(0, _mediaClient.isImageRepresentationReady)(fileState)) {
|
|
120
118
|
setStatus('complete');
|
|
119
|
+
} else if (!preview && fileState && fileState.status === 'failed-processing' && !(0, _mediaClient.isImageRepresentationReady)(fileState)) {
|
|
120
|
+
setStatus('error');
|
|
121
|
+
setError(new _errors.MediaFilePreviewError('failed-processing'));
|
|
122
|
+
} else {
|
|
123
|
+
setStatus('loading');
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
126
|
}, [preview, status, fileState]);
|
|
@@ -264,10 +267,10 @@ var useFilePreview = exports.useFilePreview = function useFilePreview(_ref) {
|
|
|
264
267
|
}, [preview === null || preview === void 0 ? void 0 : preview.dataURI]);
|
|
265
268
|
|
|
266
269
|
// FOR SSR
|
|
267
|
-
var
|
|
270
|
+
var getSsrScriptProps = ssr === 'server' ? function () {
|
|
268
271
|
var _ssrReliabilityRef$cu;
|
|
269
272
|
return (0, _globalScope.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);
|
|
270
|
-
};
|
|
273
|
+
} : undefined;
|
|
271
274
|
|
|
272
275
|
// CXP-2723 TODO: should consider simplifying our analytics, and how
|
|
273
276
|
// we might get rid of ssrReliabiltyRef from our hook
|
|
@@ -279,7 +282,7 @@ var useFilePreview = exports.useFilePreview = function useFilePreview(_ref) {
|
|
|
279
282
|
ssrReliabilityRef: ssrReliabilityRef,
|
|
280
283
|
onImageError: onImageError,
|
|
281
284
|
onImageLoad: onImageLoad,
|
|
282
|
-
|
|
285
|
+
getSsrScriptProps: getSsrScriptProps
|
|
283
286
|
};
|
|
284
287
|
};
|
|
285
288
|
var initialSsrReliability = {
|
|
@@ -3,7 +3,7 @@ import { isImageRepresentationReady } from '@atlaskit/media-client';
|
|
|
3
3
|
import { useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
4
4
|
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
5
5
|
import { extractErrorInfo } from './analytics';
|
|
6
|
-
import { ensureMediaFilePreviewError, ImageLoadError } from './errors';
|
|
6
|
+
import { ensureMediaFilePreviewError, ImageLoadError, MediaFilePreviewError } from './errors';
|
|
7
7
|
import { getAndCacheLocalPreview, getAndCacheRemotePreview, getSSRPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, isSSRPreview, isSupportedLocalPreview, mediaFilePreviewCache } from './getPreview';
|
|
8
8
|
import { generateScriptProps, getSSRData } from './globalScope';
|
|
9
9
|
import { createRequestDimensions, isBigger, useCurrentValueRef } from './helpers';
|
|
@@ -15,6 +15,7 @@ export const useFilePreview = ({
|
|
|
15
15
|
traceContext,
|
|
16
16
|
skipRemote,
|
|
17
17
|
mediaBlobUrlAttrs,
|
|
18
|
+
// TODO: mediaBlobUrlAttrs can be missing several values contained in the file details. The preview hook is not updating the params in the preview after the file details are available.
|
|
18
19
|
allowAnimated = true,
|
|
19
20
|
upscale,
|
|
20
21
|
maxAge
|
|
@@ -90,10 +91,13 @@ export const useFilePreview = ({
|
|
|
90
91
|
}, [identifier]);
|
|
91
92
|
useEffect(() => {
|
|
92
93
|
if (status !== 'error') {
|
|
93
|
-
if (
|
|
94
|
-
setStatus('loading');
|
|
95
|
-
} else {
|
|
94
|
+
if (preview || fileState && fileState.status === 'processed' && !isImageRepresentationReady(fileState)) {
|
|
96
95
|
setStatus('complete');
|
|
96
|
+
} else if (!preview && fileState && fileState.status === 'failed-processing' && !isImageRepresentationReady(fileState)) {
|
|
97
|
+
setStatus('error');
|
|
98
|
+
setError(new MediaFilePreviewError('failed-processing'));
|
|
99
|
+
} else {
|
|
100
|
+
setStatus('loading');
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
}, [preview, status, fileState]);
|
|
@@ -243,10 +247,10 @@ export const useFilePreview = ({
|
|
|
243
247
|
}, [preview === null || preview === void 0 ? void 0 : preview.dataURI]);
|
|
244
248
|
|
|
245
249
|
// FOR SSR
|
|
246
|
-
const
|
|
250
|
+
const getSsrScriptProps = ssr === 'server' ? () => {
|
|
247
251
|
var _ssrReliabilityRef$cu;
|
|
248
252
|
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);
|
|
249
|
-
};
|
|
253
|
+
} : undefined;
|
|
250
254
|
|
|
251
255
|
// CXP-2723 TODO: should consider simplifying our analytics, and how
|
|
252
256
|
// we might get rid of ssrReliabiltyRef from our hook
|
|
@@ -258,7 +262,7 @@ export const useFilePreview = ({
|
|
|
258
262
|
ssrReliabilityRef,
|
|
259
263
|
onImageError,
|
|
260
264
|
onImageLoad,
|
|
261
|
-
|
|
265
|
+
getSsrScriptProps
|
|
262
266
|
};
|
|
263
267
|
};
|
|
264
268
|
const initialSsrReliability = {
|
|
@@ -7,7 +7,7 @@ import { isImageRepresentationReady } from '@atlaskit/media-client';
|
|
|
7
7
|
import { useFileState, useMediaClient } from '@atlaskit/media-client-react';
|
|
8
8
|
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
9
9
|
import { extractErrorInfo } from './analytics';
|
|
10
|
-
import { ensureMediaFilePreviewError, ImageLoadError } from './errors';
|
|
10
|
+
import { ensureMediaFilePreviewError, ImageLoadError, MediaFilePreviewError } from './errors';
|
|
11
11
|
import { getAndCacheLocalPreview, getAndCacheRemotePreview, getSSRPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, isSSRPreview, isSupportedLocalPreview, mediaFilePreviewCache } from './getPreview';
|
|
12
12
|
import { generateScriptProps, getSSRData } from './globalScope';
|
|
13
13
|
import { createRequestDimensions, isBigger, useCurrentValueRef } from './helpers';
|
|
@@ -107,10 +107,13 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
107
107
|
}, [identifier]);
|
|
108
108
|
useEffect(function () {
|
|
109
109
|
if (status !== 'error') {
|
|
110
|
-
if (
|
|
111
|
-
setStatus('loading');
|
|
112
|
-
} else {
|
|
110
|
+
if (preview || fileState && fileState.status === 'processed' && !isImageRepresentationReady(fileState)) {
|
|
113
111
|
setStatus('complete');
|
|
112
|
+
} else if (!preview && fileState && fileState.status === 'failed-processing' && !isImageRepresentationReady(fileState)) {
|
|
113
|
+
setStatus('error');
|
|
114
|
+
setError(new MediaFilePreviewError('failed-processing'));
|
|
115
|
+
} else {
|
|
116
|
+
setStatus('loading');
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
}, [preview, status, fileState]);
|
|
@@ -257,10 +260,10 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
257
260
|
}, [preview === null || preview === void 0 ? void 0 : preview.dataURI]);
|
|
258
261
|
|
|
259
262
|
// FOR SSR
|
|
260
|
-
var
|
|
263
|
+
var getSsrScriptProps = ssr === 'server' ? function () {
|
|
261
264
|
var _ssrReliabilityRef$cu;
|
|
262
265
|
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);
|
|
263
|
-
};
|
|
266
|
+
} : undefined;
|
|
264
267
|
|
|
265
268
|
// CXP-2723 TODO: should consider simplifying our analytics, and how
|
|
266
269
|
// we might get rid of ssrReliabiltyRef from our hook
|
|
@@ -272,7 +275,7 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
272
275
|
ssrReliabilityRef: ssrReliabilityRef,
|
|
273
276
|
onImageError: onImageError,
|
|
274
277
|
onImageLoad: onImageLoad,
|
|
275
|
-
|
|
278
|
+
getSsrScriptProps: getSsrScriptProps
|
|
276
279
|
};
|
|
277
280
|
};
|
|
278
281
|
var initialSsrReliability = {
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { MediaFilePreview } from './types';
|
|
|
5
5
|
* Primary reason is logged through Data Portal.
|
|
6
6
|
* Make sure all the values are whitelisted in Measure -> Event Regitry -> "mediaCardRender failed" event
|
|
7
7
|
*/
|
|
8
|
-
export type MediaFilePreviewErrorPrimaryReason = 'upload' | 'metadata-fetch' | 'error-file-state' | RemotePreviewPrimaryReason | LocalPreviewPrimaryReason | ImageLoadPrimaryReason | SsrPreviewPrimaryReason | 'missing-error-data' | 'preview-fetch';
|
|
8
|
+
export type MediaFilePreviewErrorPrimaryReason = 'upload' | 'metadata-fetch' | 'error-file-state' | 'failed-processing' | RemotePreviewPrimaryReason | LocalPreviewPrimaryReason | ImageLoadPrimaryReason | SsrPreviewPrimaryReason | 'missing-error-data' | 'preview-fetch';
|
|
9
9
|
export type ImageLoadPrimaryReason = 'cache-remote-uri' | 'cache-local-uri' | 'local-uri' | 'remote-uri' | 'external-uri' | 'unknown-uri';
|
|
10
10
|
export type RemotePreviewPrimaryReason = 'remote-preview-fetch' | 'remote-preview-not-ready' | 'remote-preview-fetch-ssr';
|
|
11
11
|
export type LocalPreviewPrimaryReason = 'local-preview-get' | 'local-preview-unsupported' | 'local-preview-rejected' | 'local-preview-image' | 'local-preview-video';
|
|
@@ -35,5 +35,5 @@ export declare const useFilePreview: ({ resizeMode, identifier, ssr, dimensions,
|
|
|
35
35
|
ssrReliabilityRef: import("react").MutableRefObject<SSRStatus>;
|
|
36
36
|
onImageError: (newPreview?: MediaFilePreview) => void;
|
|
37
37
|
onImageLoad: (newPreview?: MediaFilePreview) => void;
|
|
38
|
-
|
|
38
|
+
getSsrScriptProps: (() => import("react").ScriptHTMLAttributes<HTMLScriptElement>) | undefined;
|
|
39
39
|
};
|
|
@@ -5,7 +5,7 @@ import { MediaFilePreview } from './types';
|
|
|
5
5
|
* Primary reason is logged through Data Portal.
|
|
6
6
|
* Make sure all the values are whitelisted in Measure -> Event Regitry -> "mediaCardRender failed" event
|
|
7
7
|
*/
|
|
8
|
-
export type MediaFilePreviewErrorPrimaryReason = 'upload' | 'metadata-fetch' | 'error-file-state' | RemotePreviewPrimaryReason | LocalPreviewPrimaryReason | ImageLoadPrimaryReason | SsrPreviewPrimaryReason | 'missing-error-data' | 'preview-fetch';
|
|
8
|
+
export type MediaFilePreviewErrorPrimaryReason = 'upload' | 'metadata-fetch' | 'error-file-state' | 'failed-processing' | RemotePreviewPrimaryReason | LocalPreviewPrimaryReason | ImageLoadPrimaryReason | SsrPreviewPrimaryReason | 'missing-error-data' | 'preview-fetch';
|
|
9
9
|
export type ImageLoadPrimaryReason = 'cache-remote-uri' | 'cache-local-uri' | 'local-uri' | 'remote-uri' | 'external-uri' | 'unknown-uri';
|
|
10
10
|
export type RemotePreviewPrimaryReason = 'remote-preview-fetch' | 'remote-preview-not-ready' | 'remote-preview-fetch-ssr';
|
|
11
11
|
export type LocalPreviewPrimaryReason = 'local-preview-get' | 'local-preview-unsupported' | 'local-preview-rejected' | 'local-preview-image' | 'local-preview-video';
|
|
@@ -35,5 +35,5 @@ export declare const useFilePreview: ({ resizeMode, identifier, ssr, dimensions,
|
|
|
35
35
|
ssrReliabilityRef: import("react").MutableRefObject<SSRStatus>;
|
|
36
36
|
onImageError: (newPreview?: MediaFilePreview) => void;
|
|
37
37
|
onImageLoad: (newPreview?: MediaFilePreview) => void;
|
|
38
|
-
|
|
38
|
+
getSsrScriptProps: (() => import("react").ScriptHTMLAttributes<HTMLScriptElement>) | undefined;
|
|
39
39
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/media-file-preview",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A React Hook to fetch and render file previews. It's overloaded with fancy features like SSR, lazy loading, memory cache and local preview.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@af/integration-testing": "*",
|
|
51
51
|
"@af/visual-regression": "*",
|
|
52
52
|
"@atlaskit/media-state": "^1.0.3",
|
|
53
|
-
"@atlaskit/media-test-data": "^1.
|
|
53
|
+
"@atlaskit/media-test-data": "^1.2.0",
|
|
54
54
|
"@atlaskit/section-message": "^6.4.17",
|
|
55
55
|
"@atlaskit/ssr": "*",
|
|
56
56
|
"@atlaskit/visual-regression": "*",
|