@atlaskit/media-card 70.10.0 → 72.1.0
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 +79 -0
- package/dist/cjs/errors.js +76 -5
- package/dist/cjs/files/cardImageView/index.js +58 -89
- package/dist/cjs/files/index.js +0 -6
- package/dist/cjs/index.js +16 -6
- package/dist/cjs/root/card/cardAnalytics.js +33 -19
- package/dist/cjs/root/card/cardConstants.js +8 -0
- package/dist/cjs/root/card/cardLoader.js +66 -124
- package/dist/cjs/root/card/cardState.js +50 -0
- package/dist/cjs/root/card/getCardPreview/cache.js +5 -0
- package/dist/cjs/root/card/getCardPreview/filePreviewStatus.js +50 -0
- package/dist/cjs/root/card/getCardPreview/helpers.js +13 -21
- package/dist/cjs/root/card/getCardPreview/index.js +171 -100
- package/dist/cjs/root/card/getCardStatus.js +7 -1
- package/dist/cjs/root/card/index.js +407 -322
- package/dist/cjs/root/cardView.js +115 -76
- package/dist/cjs/root/index.js +9 -1
- package/dist/cjs/root/inline/loader.js +22 -21
- package/dist/cjs/root/inline/{inlineMediaCard.js → mediaInlineCard.js} +72 -25
- package/dist/cjs/root/inlinePlayer.js +5 -15
- package/dist/cjs/root/ui/iconMessage/index.js +17 -9
- package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +36 -115
- package/dist/cjs/root/ui/styled.js +1 -1
- package/dist/cjs/root/ui/titleBox/failedTitleBox.js +7 -3
- package/dist/cjs/utils/analytics.js +26 -43
- package/dist/cjs/utils/cardActions/cardActionsDropdownMenu.js +16 -9
- package/dist/cjs/utils/dimensionComparer.js +1 -1
- package/dist/cjs/utils/document.js +12 -0
- package/dist/cjs/utils/getDataURIDimension.js +13 -2
- package/dist/cjs/utils/metadata.js +11 -3
- package/dist/cjs/utils/objectURLCache.js +6 -0
- package/dist/cjs/utils/resizeModeToMediaImageProps.js +13 -0
- package/dist/cjs/utils/shouldDisplayImageThumbnail.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/errors.js +42 -2
- package/dist/es2019/files/cardImageView/index.js +12 -46
- package/dist/es2019/files/index.js +1 -1
- package/dist/es2019/index.js +3 -3
- package/dist/es2019/root/card/cardAnalytics.js +23 -17
- package/dist/es2019/root/card/cardConstants.js +1 -0
- package/dist/es2019/root/card/cardLoader.js +47 -53
- package/dist/es2019/root/card/cardState.js +26 -0
- package/dist/es2019/root/card/getCardPreview/cache.js +5 -0
- package/dist/es2019/root/card/getCardPreview/filePreviewStatus.js +35 -0
- package/dist/es2019/root/card/getCardPreview/helpers.js +2 -12
- package/dist/es2019/root/card/getCardPreview/index.js +112 -79
- package/dist/es2019/root/card/getCardStatus.js +1 -0
- package/dist/es2019/root/card/index.js +356 -254
- package/dist/es2019/root/cardView.js +98 -58
- package/dist/es2019/root/index.js +2 -1
- package/dist/es2019/root/inline/loader.js +16 -15
- package/dist/es2019/root/inline/mediaInlineCard.js +132 -0
- package/dist/es2019/root/inlinePlayer.js +5 -13
- package/dist/es2019/root/ui/iconMessage/index.js +10 -6
- package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +26 -74
- package/dist/es2019/root/ui/styled.js +1 -0
- package/dist/es2019/root/ui/titleBox/failedTitleBox.js +5 -3
- package/dist/es2019/utils/analytics.js +29 -40
- package/dist/es2019/utils/cardActions/cardActionsDropdownMenu.js +8 -4
- package/dist/es2019/utils/dimensionComparer.js +1 -1
- package/dist/es2019/utils/document.js +1 -0
- package/dist/es2019/utils/getDataURIDimension.js +8 -0
- package/dist/es2019/utils/metadata.js +12 -4
- package/dist/es2019/utils/objectURLCache.js +5 -0
- package/dist/es2019/utils/resizeModeToMediaImageProps.js +6 -0
- package/dist/es2019/utils/shouldDisplayImageThumbnail.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/errors.js +60 -1
- package/dist/esm/files/cardImageView/index.js +55 -87
- package/dist/esm/files/index.js +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/root/card/cardAnalytics.js +23 -18
- package/dist/esm/root/card/cardConstants.js +1 -0
- package/dist/esm/root/card/cardLoader.js +66 -126
- package/dist/esm/root/card/cardState.js +32 -0
- package/dist/esm/root/card/getCardPreview/cache.js +6 -0
- package/dist/esm/root/card/getCardPreview/filePreviewStatus.js +35 -0
- package/dist/esm/root/card/getCardPreview/helpers.js +13 -21
- package/dist/esm/root/card/getCardPreview/index.js +142 -95
- package/dist/esm/root/card/getCardStatus.js +3 -0
- package/dist/esm/root/card/index.js +416 -325
- package/dist/esm/root/cardView.js +114 -73
- package/dist/esm/root/index.js +2 -1
- package/dist/esm/root/inline/loader.js +23 -22
- package/dist/esm/root/inline/mediaInlineCard.js +145 -0
- package/dist/esm/root/inlinePlayer.js +5 -13
- package/dist/esm/root/ui/iconMessage/index.js +12 -7
- package/dist/esm/root/ui/imageRenderer/imageRenderer.js +28 -106
- package/dist/esm/root/ui/styled.js +1 -1
- package/dist/esm/root/ui/titleBox/failedTitleBox.js +6 -3
- package/dist/esm/utils/analytics.js +22 -35
- package/dist/esm/utils/cardActions/cardActionsDropdownMenu.js +16 -9
- package/dist/esm/utils/dimensionComparer.js +1 -1
- package/dist/esm/utils/document.js +3 -0
- package/dist/esm/utils/getDataURIDimension.js +8 -0
- package/dist/esm/utils/metadata.js +12 -4
- package/dist/esm/utils/objectURLCache.js +6 -0
- package/dist/esm/utils/resizeModeToMediaImageProps.js +6 -0
- package/dist/esm/utils/shouldDisplayImageThumbnail.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/errors.d.ts +15 -1
- package/dist/types/files/cardImageView/index.d.ts +5 -12
- package/dist/types/files/cardImageView/styled.d.ts +1 -1
- package/dist/types/files/index.d.ts +1 -1
- package/dist/types/index.d.ts +11 -13
- package/dist/types/root/card/cardAnalytics.d.ts +5 -7
- package/dist/types/root/card/cardConstants.d.ts +1 -0
- package/dist/types/root/card/cardLoader.d.ts +4 -18
- package/dist/types/root/card/cardState.d.ts +5 -0
- package/dist/types/root/card/getCardPreview/cache.d.ts +4 -2
- package/dist/types/root/card/getCardPreview/filePreviewStatus.d.ts +5 -0
- package/dist/types/root/card/getCardPreview/helpers.d.ts +4 -5
- package/dist/types/root/card/getCardPreview/index.d.ts +25 -14
- package/dist/types/root/card/getCardStatus.d.ts +1 -0
- package/dist/types/root/card/index.d.ts +18 -15
- package/dist/types/root/cardView.d.ts +14 -8
- package/dist/types/root/index.d.ts +1 -0
- package/dist/types/root/inline/loader.d.ts +8 -8
- package/dist/types/root/inline/{inlineMediaCard.d.ts → mediaInlineCard.d.ts} +4 -4
- package/dist/types/root/inlinePlayer.d.ts +1 -1
- package/dist/types/root/ui/iconMessage/index.d.ts +7 -2
- package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +5 -18
- package/dist/types/root/ui/titleBox/failedTitleBox.d.ts +2 -0
- package/dist/types/types.d.ts +9 -1
- package/dist/types/utils/analytics.d.ts +20 -21
- package/dist/types/utils/cardDimensions.d.ts +5 -1
- package/dist/types/utils/dimensionComparer.d.ts +1 -1
- package/dist/types/utils/document.d.ts +2 -0
- package/dist/types/utils/getDataURIDimension.d.ts +3 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/lazyContent/styled.d.ts +1 -1
- package/dist/types/utils/lightCards/types.d.ts +1 -1
- package/dist/types/utils/metadata.d.ts +2 -2
- package/dist/types/utils/objectURLCache.d.ts +2 -1
- package/dist/types/utils/resizeModeToMediaImageProps.d.ts +5 -0
- package/dist/types/utils/shouldDisplayImageThumbnail.d.ts +1 -1
- package/example-helpers/developmentUseMessage.tsx +14 -0
- package/example-helpers/index.tsx +55 -4
- package/example-helpers/selectableCard.tsx +2 -1
- package/package.json +18 -14
- package/dist/cjs/root/card/getCardPreview/types.js +0 -5
- package/dist/cjs/utils/fileAttributesContext.js +0 -40
- package/dist/es2019/root/card/getCardPreview/types.js +0 -1
- package/dist/es2019/root/inline/inlineMediaCard.js +0 -92
- package/dist/es2019/utils/fileAttributesContext.js +0 -19
- package/dist/esm/root/card/getCardPreview/types.js +0 -1
- package/dist/esm/root/inline/inlineMediaCard.js +0 -100
- package/dist/esm/utils/fileAttributesContext.js +0 -18
- package/dist/types/root/card/getCardPreview/types.d.ts +0 -5
- package/dist/types/utils/fileAttributesContext.d.ts +0 -10
|
@@ -1,51 +1,14 @@
|
|
|
1
|
-
import { isPreviewableFileState,
|
|
1
|
+
import { isPreviewableFileState, addFileAttrsToUrl } from '@atlaskit/media-client';
|
|
2
2
|
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
3
3
|
import cardPreviewCache from './cache';
|
|
4
|
-
import { getCardPreviewFromFilePreview, getCardPreviewFromBackend
|
|
5
|
-
import { MediaCardError, isUnsupportedLocalPreviewError } from '../../../errors';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
const hasFilesize = 'size' in fileState && !!fileState.size;
|
|
11
|
-
const {
|
|
12
|
-
mediaType
|
|
13
|
-
} = 'mediaType' in fileState && fileState || {};
|
|
14
|
-
const {
|
|
15
|
-
mimeType
|
|
16
|
-
} = 'mimeType' in fileState && fileState || {};
|
|
17
|
-
const isPreviewable = !!mediaType && isPreviewableType(mediaType, featureFlags);
|
|
18
|
-
/**
|
|
19
|
-
* Local preview is available only if it's supported by browser and supported by Media Card (isSupportedLocalPreview)
|
|
20
|
-
* For example, SVGs are mime type NOT supported by browser but media type supported by Media Card (image)
|
|
21
|
-
* Then, local Preview NOT available
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
const hasLocalPreview = isPreviewableFileState(fileState) && isSupportedLocalPreview(mediaType) && !!mimeType && isMimeTypeSupportedByBrowser(mimeType);
|
|
25
|
-
const hasRemotePreview = isImageRepresentationReady(fileState);
|
|
26
|
-
const hasPreview = hasLocalPreview || hasRemotePreview;
|
|
27
|
-
const isSupportedByBrowser = !!mimeType && isMimeTypeSupportedByBrowser(mimeType);
|
|
28
|
-
return {
|
|
29
|
-
hasFilesize,
|
|
30
|
-
isPreviewable,
|
|
31
|
-
hasPreview,
|
|
32
|
-
isSupportedByBrowser
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export const shouldGetCardPreview = (cardStatus, {
|
|
36
|
-
isPreviewable,
|
|
37
|
-
hasPreview,
|
|
38
|
-
isSupportedByBrowser
|
|
39
|
-
}) => {
|
|
40
|
-
return cardStatus === 'loading-preview' || cardStatus === 'uploading' && hasPreview && isPreviewable ||
|
|
41
|
-
/**
|
|
42
|
-
* For Video, we can have local or remote preview while processing.
|
|
43
|
-
* Then, we only want to show the thumbnail if the file is supported by the browser,
|
|
44
|
-
* this way we prevent playing unsupported videos that are not procesed
|
|
45
|
-
*/
|
|
46
|
-
cardStatus === 'processing' && hasPreview && isPreviewable && isSupportedByBrowser;
|
|
47
|
-
};
|
|
4
|
+
import { getCardPreviewFromFilePreview, getCardPreviewFromBackend } from './helpers';
|
|
5
|
+
import { MediaCardError, SsrPreviewError, isUnsupportedLocalPreviewError } from '../../../errors';
|
|
6
|
+
import { isBigger } from '../../../utils/dimensionComparer';
|
|
7
|
+
import { extractFilePreviewStatus, isPreviewableStatus } from './filePreviewStatus';
|
|
8
|
+
export { getCardPreviewFromFilePreview, getCardPreviewFromBackend, isSupportedLocalPreview } from './helpers';
|
|
9
|
+
export { extractFilePreviewStatus } from './filePreviewStatus';
|
|
48
10
|
export const getCardPreviewFromCache = cardPreviewCache.get;
|
|
11
|
+
export const removeCardPreviewFromCache = cardPreviewCache.remove;
|
|
49
12
|
/**
|
|
50
13
|
* Will return the preview if available and supported by the browser
|
|
51
14
|
* See extractFilePreviewStatus "hasLocalPreview" logic
|
|
@@ -53,6 +16,41 @@ export const getCardPreviewFromCache = cardPreviewCache.get;
|
|
|
53
16
|
|
|
54
17
|
export const getFilePreviewFromFileState = fileState => 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) && isPreviewableFileState(fileState) ? fileState.preview : undefined;
|
|
55
18
|
|
|
19
|
+
const extendAndCachePreview = (id, dimensions, preview, mediaBlobUrlAttrs) => {
|
|
20
|
+
let source;
|
|
21
|
+
|
|
22
|
+
switch (preview.source) {
|
|
23
|
+
case 'local':
|
|
24
|
+
source = 'cache-local';
|
|
25
|
+
break;
|
|
26
|
+
|
|
27
|
+
case 'remote':
|
|
28
|
+
source = 'cache-remote';
|
|
29
|
+
break;
|
|
30
|
+
|
|
31
|
+
case 'ssr-server':
|
|
32
|
+
source = 'cache-ssr-server';
|
|
33
|
+
break;
|
|
34
|
+
|
|
35
|
+
case 'ssr-client':
|
|
36
|
+
source = 'cache-ssr-client';
|
|
37
|
+
break;
|
|
38
|
+
|
|
39
|
+
default:
|
|
40
|
+
source = preview.source;
|
|
41
|
+
} // We want to embed some meta context into dataURI for Copy/Paste to work.
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
const dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI; // We store new cardPreview into cache
|
|
45
|
+
|
|
46
|
+
cardPreviewCache.set(id, dimensions, { ...preview,
|
|
47
|
+
source,
|
|
48
|
+
dataURI
|
|
49
|
+
});
|
|
50
|
+
return { ...preview,
|
|
51
|
+
dataURI
|
|
52
|
+
};
|
|
53
|
+
};
|
|
56
54
|
/**
|
|
57
55
|
* This function will try to return a Card preview, either from cache, local preview or remote preview.
|
|
58
56
|
* It should only be called if there is a chance to get either a remote or a local preview, or both.
|
|
@@ -63,28 +61,29 @@ export const getFilePreviewFromFileState = fileState => 'mimeType' in fileState
|
|
|
63
61
|
* In that case, we still want to report the local preview error to the caller, for feature realiability track.
|
|
64
62
|
* hence the use of the optional callback onLocalPreviewError
|
|
65
63
|
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
66
|
export const getCardPreview = async ({
|
|
67
67
|
mediaClient,
|
|
68
68
|
id,
|
|
69
|
-
collectionName,
|
|
70
|
-
requestedDimensions,
|
|
71
|
-
isRemotePreviewReady,
|
|
72
|
-
addContextToDataURI,
|
|
73
|
-
filePreview,
|
|
74
69
|
dimensions = {},
|
|
75
|
-
|
|
76
|
-
onLocalPreviewError
|
|
70
|
+
filePreview,
|
|
71
|
+
onLocalPreviewError,
|
|
72
|
+
isRemotePreviewReady,
|
|
73
|
+
imageUrlParams,
|
|
74
|
+
mediaBlobUrlAttrs
|
|
77
75
|
}) => {
|
|
78
|
-
|
|
76
|
+
const cachedPreview = cardPreviewCache.get(id, dimensions);
|
|
79
77
|
|
|
80
|
-
if (
|
|
81
|
-
return
|
|
82
|
-
source: 'cache'
|
|
83
|
-
};
|
|
78
|
+
if (cachedPreview) {
|
|
79
|
+
return cachedPreview;
|
|
84
80
|
}
|
|
85
81
|
|
|
86
82
|
try {
|
|
87
|
-
|
|
83
|
+
if (filePreview) {
|
|
84
|
+
const localPreview = await getCardPreviewFromFilePreview(filePreview);
|
|
85
|
+
return extendAndCachePreview(id, dimensions, localPreview, mediaBlobUrlAttrs);
|
|
86
|
+
}
|
|
88
87
|
} catch (e) {
|
|
89
88
|
/**
|
|
90
89
|
* We report the error if:
|
|
@@ -110,29 +109,63 @@ export const getCardPreview = async ({
|
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
if (!
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
throw new MediaCardError('remote-preview-not-ready');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
cardPreview = await getCardPreviewFromBackend(mediaClient, id, requestedDimensions, collectionName, resizeMode);
|
|
112
|
+
if (!isRemotePreviewReady) {
|
|
113
|
+
/**
|
|
114
|
+
* We throw this in case this function has been called
|
|
115
|
+
* without checking isRemotePreviewReady first.
|
|
116
|
+
* If remote preview is not ready, the call to getCardPreviewFromBackend
|
|
117
|
+
* will generate a console error due to a 404 code
|
|
118
|
+
*/
|
|
119
|
+
throw new MediaCardError('remote-preview-not-ready');
|
|
125
120
|
}
|
|
126
|
-
/**
|
|
127
|
-
* In case we've retrieved cardPreview using one of the two methods above,
|
|
128
|
-
* we want to embed some meta context into dataURI for Copy/Paste to work.
|
|
129
|
-
*/
|
|
130
121
|
|
|
122
|
+
return fetchAndCacheRemotePreview(mediaClient, id, dimensions, imageUrlParams, mediaBlobUrlAttrs);
|
|
123
|
+
};
|
|
124
|
+
export const shouldResolvePreview = ({
|
|
125
|
+
status,
|
|
126
|
+
fileState,
|
|
127
|
+
dimensions,
|
|
128
|
+
prevDimensions,
|
|
129
|
+
hasCardPreview,
|
|
130
|
+
isBannedLocalPreview,
|
|
131
|
+
featureFlags
|
|
132
|
+
}) => {
|
|
133
|
+
const statusIsPreviewable = isPreviewableStatus(status, extractFilePreviewStatus(fileState, isBannedLocalPreview, featureFlags));
|
|
134
|
+
const dimensionsAreBigger = isBigger(prevDimensions, dimensions);
|
|
135
|
+
return statusIsPreviewable && (!hasCardPreview || dimensionsAreBigger);
|
|
136
|
+
};
|
|
137
|
+
export const getSSRCardPreview = (ssr, mediaClient, id, params, mediaBlobUrlAttrs) => {
|
|
138
|
+
let dataURI;
|
|
131
139
|
|
|
132
|
-
|
|
133
|
-
dataURI
|
|
134
|
-
}; // We store new cardPreview into cache
|
|
140
|
+
try {
|
|
141
|
+
const rawDataURI = mediaClient.getImageUrlSync(id, params); // We want to embed some meta context into dataURI for Copy/Paste to work.
|
|
135
142
|
|
|
136
|
-
|
|
137
|
-
|
|
143
|
+
dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(rawDataURI, mediaBlobUrlAttrs) : rawDataURI;
|
|
144
|
+
const source = ssr === 'client' ? 'ssr-client' : 'ssr-server';
|
|
145
|
+
return {
|
|
146
|
+
dataURI,
|
|
147
|
+
source,
|
|
148
|
+
orientation: 1
|
|
149
|
+
};
|
|
150
|
+
} catch (e) {
|
|
151
|
+
const reason = ssr === 'server' ? 'ssr-server-uri' : 'ssr-client-uri';
|
|
152
|
+
throw new SsrPreviewError(reason, e);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
export const isLocalPreview = preview => {
|
|
156
|
+
const localSources = ['local', 'cache-local'];
|
|
157
|
+
return localSources.includes(preview.source);
|
|
158
|
+
};
|
|
159
|
+
export const isSSRPreview = preview => isSSRClientPreview(preview) || isSSRServerPreview(preview);
|
|
160
|
+
export const isSSRServerPreview = preview => {
|
|
161
|
+
const ssrClientSources = ['ssr-server', 'cache-ssr-server'];
|
|
162
|
+
return ssrClientSources.includes(preview.source);
|
|
163
|
+
};
|
|
164
|
+
export const isSSRClientPreview = preview => {
|
|
165
|
+
const ssrClientSources = ['ssr-client', 'cache-ssr-client'];
|
|
166
|
+
return ssrClientSources.includes(preview.source);
|
|
167
|
+
};
|
|
168
|
+
export const fetchAndCacheRemotePreview = async (mediaClient, id, dimensions, params, mediaBlobUrlAttrs) => {
|
|
169
|
+
const remotePreview = await getCardPreviewFromBackend(mediaClient, id, params);
|
|
170
|
+
return extendAndCachePreview(id, dimensions, remotePreview, mediaBlobUrlAttrs);
|
|
138
171
|
};
|