@atlaskit/media-card 71.0.0 → 72.0.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 +18 -0
- package/dist/cjs/errors.js +56 -5
- package/dist/cjs/files/cardImageView/index.js +53 -104
- package/dist/cjs/files/index.js +0 -6
- package/dist/cjs/root/card/cardAnalytics.js +3 -15
- package/dist/cjs/root/card/cardSSRView.js +4 -2
- 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 +91 -94
- package/dist/cjs/root/card/getCardStatus.js +7 -1
- package/dist/cjs/root/card/index.js +271 -266
- package/dist/cjs/root/cardView.js +96 -60
- package/dist/cjs/root/inline/loader.js +2 -1
- package/dist/cjs/root/inline/mediaInlineCard.js +4 -3
- package/dist/cjs/root/ui/iconMessage/index.js +12 -5
- package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +30 -124
- package/dist/cjs/root/ui/titleBox/failedTitleBox.js +7 -3
- package/dist/cjs/utils/analytics.js +6 -44
- package/dist/cjs/utils/dimensionComparer.js +1 -1
- package/dist/cjs/utils/metadata.js +11 -3
- package/dist/cjs/utils/objectURLCache.js +6 -0
- package/dist/cjs/utils/shouldDisplayImageThumbnail.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/errors.js +34 -2
- package/dist/es2019/files/cardImageView/index.js +8 -61
- package/dist/es2019/files/index.js +1 -1
- package/dist/es2019/root/card/cardAnalytics.js +3 -14
- package/dist/es2019/root/card/cardSSRView.js +3 -2
- 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 +71 -74
- package/dist/es2019/root/card/getCardStatus.js +1 -0
- package/dist/es2019/root/card/index.js +193 -171
- package/dist/es2019/root/cardView.js +100 -61
- package/dist/es2019/root/inline/loader.js +2 -1
- package/dist/es2019/root/inline/mediaInlineCard.js +4 -3
- package/dist/es2019/root/ui/iconMessage/index.js +5 -3
- package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +21 -88
- package/dist/es2019/root/ui/titleBox/failedTitleBox.js +5 -3
- package/dist/es2019/utils/analytics.js +5 -34
- package/dist/es2019/utils/dimensionComparer.js +1 -1
- package/dist/es2019/utils/metadata.js +12 -4
- package/dist/es2019/utils/objectURLCache.js +5 -0
- package/dist/es2019/utils/shouldDisplayImageThumbnail.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/errors.js +42 -1
- package/dist/esm/files/cardImageView/index.js +51 -102
- package/dist/esm/files/index.js +1 -1
- package/dist/esm/root/card/cardAnalytics.js +3 -15
- package/dist/esm/root/card/cardSSRView.js +3 -2
- 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 +79 -88
- package/dist/esm/root/card/getCardStatus.js +3 -0
- package/dist/esm/root/card/index.js +278 -268
- package/dist/esm/root/cardView.js +98 -61
- package/dist/esm/root/inline/loader.js +2 -1
- package/dist/esm/root/inline/mediaInlineCard.js +4 -3
- package/dist/esm/root/ui/iconMessage/index.js +7 -3
- package/dist/esm/root/ui/imageRenderer/imageRenderer.js +23 -118
- package/dist/esm/root/ui/titleBox/failedTitleBox.js +6 -3
- package/dist/esm/utils/analytics.js +5 -36
- package/dist/esm/utils/dimensionComparer.js +1 -1
- package/dist/esm/utils/metadata.js +12 -4
- package/dist/esm/utils/objectURLCache.js +6 -0
- package/dist/esm/utils/shouldDisplayImageThumbnail.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/errors.d.ts +9 -1
- package/dist/types/files/cardImageView/index.d.ts +4 -13
- 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 +4 -3
- package/dist/types/root/card/cardAnalytics.d.ts +1 -6
- package/dist/types/root/card/cardSSRView.d.ts +1 -1
- package/dist/types/root/card/cardState.d.ts +5 -0
- package/dist/types/root/card/getCardPreview/cache.d.ts +3 -1
- package/dist/types/root/card/getCardPreview/filePreviewStatus.d.ts +5 -0
- package/dist/types/root/card/getCardPreview/helpers.d.ts +3 -4
- package/dist/types/root/card/getCardPreview/index.d.ts +17 -13
- package/dist/types/root/card/getCardStatus.d.ts +1 -0
- package/dist/types/root/card/index.d.ts +11 -10
- package/dist/types/root/cardView.d.ts +11 -8
- package/dist/types/root/inlinePlayer.d.ts +1 -1
- package/dist/types/root/ui/iconMessage/index.d.ts +2 -1
- package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +2 -13
- package/dist/types/root/ui/styledSSR.d.ts +1 -1
- package/dist/types/root/ui/titleBox/failedTitleBox.d.ts +2 -0
- package/dist/types/styles/mixins.d.ts +1 -1
- package/dist/types/types.d.ts +7 -1
- package/dist/types/utils/analytics.d.ts +6 -15
- package/dist/types/utils/cardDimensions.d.ts +4 -4
- package/dist/types/utils/dimensionComparer.d.ts +1 -1
- package/dist/types/utils/metadata.d.ts +2 -2
- package/dist/types/utils/objectURLCache.d.ts +2 -1
- package/example-helpers/index.tsx +21 -0
- package/package.json +6 -5
- 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/utils/fileAttributesContext.js +0 -19
- package/dist/esm/root/card/getCardPreview/types.js +0 -1
- 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
|
@@ -20,8 +20,8 @@ var getProcessingStatusFromFileState = function getProcessingStatusFromFileState
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
var
|
|
24
|
-
return
|
|
23
|
+
var getFileDetailsFromFileState = function getFileDetailsFromFileState(state) {
|
|
24
|
+
return {
|
|
25
25
|
id: state.id,
|
|
26
26
|
name: state.name,
|
|
27
27
|
size: state.size,
|
|
@@ -29,8 +29,16 @@ var getFileDetails = function getFileDetails(state) {
|
|
|
29
29
|
createdAt: state.createdAt,
|
|
30
30
|
mediaType: state.mediaType,
|
|
31
31
|
processingStatus: getProcessingStatusFromFileState(state.status)
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var getFileDetails = function getFileDetails(identifier, fileState) {
|
|
36
|
+
return (0, _mediaClient.isFileIdentifier)(identifier) ? fileState && !(0, _mediaClient.isErrorFileState)(fileState) ? getFileDetailsFromFileState(fileState) : {
|
|
37
|
+
id: identifier.id
|
|
32
38
|
} : {
|
|
33
|
-
id:
|
|
39
|
+
id: identifier.mediaItemType,
|
|
40
|
+
name: identifier.name || identifier.dataURI,
|
|
41
|
+
mediaType: 'image'
|
|
34
42
|
};
|
|
35
43
|
};
|
|
36
44
|
|
|
@@ -86,6 +86,12 @@ var ObjectURLCache = /*#__PURE__*/function () {
|
|
|
86
86
|
value: function set(key, value) {
|
|
87
87
|
this.cache.set(key, value);
|
|
88
88
|
}
|
|
89
|
+
}, {
|
|
90
|
+
key: "remove",
|
|
91
|
+
value: function remove(key) {
|
|
92
|
+
var removed = this.cache.remove(key);
|
|
93
|
+
removed && URL.revokeObjectURL(removed.dataURI);
|
|
94
|
+
}
|
|
89
95
|
}]);
|
|
90
96
|
return ObjectURLCache;
|
|
91
97
|
}();
|
|
@@ -13,7 +13,7 @@ var shouldDisplayImageThumbnail = function shouldDisplayImageThumbnail(cardStatu
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if (dataURI) {
|
|
16
|
-
return mediaItemType === 'external-image' || mimeType && (0, _mediaClient.isMimeTypeSupportedByBrowser)(mimeType) || cardStatus === 'complete';
|
|
16
|
+
return mediaItemType === 'external-image' || mimeType && (0, _mediaClient.isMimeTypeSupportedByBrowser)(mimeType) || cardStatus === 'complete' || cardStatus === 'loading-preview';
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
return false;
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/errors.js
CHANGED
|
@@ -27,13 +27,45 @@ export class RemotePreviewError extends MediaCardError {
|
|
|
27
27
|
this.secondaryError = secondaryError;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
}
|
|
31
|
+
export const getImageLoadPrimaryReason = source => {
|
|
32
|
+
switch (source) {
|
|
33
|
+
case 'cache-remote':
|
|
34
|
+
return 'cache-remote-uri';
|
|
35
|
+
|
|
36
|
+
case 'cache-local':
|
|
37
|
+
return 'cache-local-uri';
|
|
38
|
+
|
|
39
|
+
case 'external':
|
|
40
|
+
return 'external-uri';
|
|
41
|
+
|
|
42
|
+
case 'local':
|
|
43
|
+
return 'local-uri';
|
|
44
|
+
|
|
45
|
+
case 'remote':
|
|
46
|
+
return 'remote-uri';
|
|
47
|
+
// This fail reason will come from a bug, most likely.
|
|
48
|
+
|
|
49
|
+
default:
|
|
50
|
+
return `unknown-uri`;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export class ImageLoadError extends MediaCardError {
|
|
54
|
+
constructor(source) {
|
|
55
|
+
super(getImageLoadPrimaryReason(source));
|
|
56
|
+
}
|
|
57
|
+
|
|
30
58
|
}
|
|
31
59
|
export function isMediaCardError(err) {
|
|
32
60
|
return err instanceof MediaCardError;
|
|
33
61
|
}
|
|
34
62
|
export const isLocalPreviewError = err => err instanceof LocalPreviewError;
|
|
35
63
|
export const isRemotePreviewError = err => err instanceof RemotePreviewError;
|
|
36
|
-
export const isUnsupportedLocalPreviewError = err => isMediaCardError(err) && err.primaryReason === 'local-preview-unsupported';
|
|
64
|
+
export const isUnsupportedLocalPreviewError = err => isMediaCardError(err) && err.primaryReason === 'local-preview-unsupported';
|
|
65
|
+
export function isImageLoadError(err) {
|
|
66
|
+
return err instanceof ImageLoadError;
|
|
67
|
+
} // In a try/catch statement, the error caught is the type of any.
|
|
37
68
|
// We can use this helper to ensure that the error handled is the type of MediaCardError if unsure
|
|
38
69
|
|
|
39
|
-
export const ensureMediaCardError = (primaryReason, error) => isMediaCardError(error) ? error : new MediaCardError(primaryReason, error);
|
|
70
|
+
export const ensureMediaCardError = (primaryReason, error) => isMediaCardError(error) ? error : new MediaCardError(primaryReason, error);
|
|
71
|
+
export const isUploadError = error => error.primaryReason === 'upload';
|
|
@@ -9,12 +9,9 @@ import { CardLoading } from '../../utils/lightCards/cardLoading';
|
|
|
9
9
|
import { shouldDisplayImageThumbnail } from '../../utils/shouldDisplayImageThumbnail';
|
|
10
10
|
import { ProgressBar } from '../../utils/progressBar';
|
|
11
11
|
import CardActions from '../../utils/cardActions';
|
|
12
|
-
import { withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
13
|
-
import { fireMediaCardEvent, RenderEventAction, getRenderSucceededEventPayload, getRenderFailedFileUriPayload, getRenderFailedExternalUriPayload } from '../../utils/analytics';
|
|
14
|
-
import { withFileAttributes } from '../../utils/fileAttributesContext';
|
|
15
12
|
export const fileCardImageViewSelector = 'media-file-card-view';
|
|
16
13
|
export const fileCardImageViewSelectedSelector = 'media-file-card-view-selected';
|
|
17
|
-
export class
|
|
14
|
+
export class FileCardImageView extends Component {
|
|
18
15
|
constructor(...args) {
|
|
19
16
|
super(...args);
|
|
20
17
|
|
|
@@ -141,54 +138,6 @@ export class FileCardImageViewBase extends Component {
|
|
|
141
138
|
})));
|
|
142
139
|
});
|
|
143
140
|
|
|
144
|
-
_defineProperty(this, "onImageLoad", () => {
|
|
145
|
-
const {
|
|
146
|
-
createAnalyticsEvent,
|
|
147
|
-
fileAttributes,
|
|
148
|
-
timeElapsedTillCommenced
|
|
149
|
-
} = this.props;
|
|
150
|
-
|
|
151
|
-
if (fileAttributes && this.shouldFireEvent(RenderEventAction.SUCCEEDED)) {
|
|
152
|
-
const timeElapsedTillSucceeded = performance.now();
|
|
153
|
-
const durationSinceCommenced = timeElapsedTillCommenced && timeElapsedTillSucceeded - timeElapsedTillCommenced;
|
|
154
|
-
const performanceAttributes = {
|
|
155
|
-
overall: {
|
|
156
|
-
durationSincePageStart: timeElapsedTillSucceeded,
|
|
157
|
-
durationSinceCommenced
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
fireMediaCardEvent(getRenderSucceededEventPayload(fileAttributes, performanceAttributes), createAnalyticsEvent);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
_defineProperty(this, "onImageError", () => {
|
|
165
|
-
const {
|
|
166
|
-
fileAttributes
|
|
167
|
-
} = this.props;
|
|
168
|
-
|
|
169
|
-
if (fileAttributes && this.shouldFireEvent(RenderEventAction.FAILED)) {
|
|
170
|
-
const {
|
|
171
|
-
createAnalyticsEvent,
|
|
172
|
-
mediaItemType,
|
|
173
|
-
timeElapsedTillCommenced
|
|
174
|
-
} = this.props;
|
|
175
|
-
const timeElapsedTillFailed = performance.now();
|
|
176
|
-
const durationSinceCommenced = timeElapsedTillCommenced && timeElapsedTillFailed - timeElapsedTillCommenced;
|
|
177
|
-
const performanceAttributes = {
|
|
178
|
-
overall: {
|
|
179
|
-
durationSincePageStart: timeElapsedTillFailed,
|
|
180
|
-
durationSinceCommenced
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
if (mediaItemType === 'file') {
|
|
185
|
-
fireMediaCardEvent(getRenderFailedFileUriPayload(fileAttributes, performanceAttributes), createAnalyticsEvent);
|
|
186
|
-
} else if (mediaItemType === 'external-image') {
|
|
187
|
-
fireMediaCardEvent(getRenderFailedExternalUriPayload(fileAttributes, performanceAttributes), createAnalyticsEvent);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
|
|
192
141
|
_defineProperty(this, "renderMediaImage", () => {
|
|
193
142
|
const {
|
|
194
143
|
status,
|
|
@@ -198,7 +147,9 @@ export class FileCardImageViewBase extends Component {
|
|
|
198
147
|
mimeType,
|
|
199
148
|
previewOrientation,
|
|
200
149
|
onDisplayImage,
|
|
201
|
-
alt
|
|
150
|
+
alt,
|
|
151
|
+
onImageLoad,
|
|
152
|
+
onImageError
|
|
202
153
|
} = this.props;
|
|
203
154
|
|
|
204
155
|
if (!shouldDisplayImageThumbnail(status, mediaItemType, dataURI, mediaType, mimeType)) {
|
|
@@ -216,13 +167,11 @@ export class FileCardImageViewBase extends Component {
|
|
|
216
167
|
crop: this.isCropped,
|
|
217
168
|
stretch: this.isStretched,
|
|
218
169
|
previewOrientation: previewOrientation,
|
|
219
|
-
onImageLoad:
|
|
220
|
-
onImageError:
|
|
170
|
+
onImageLoad: onImageLoad,
|
|
171
|
+
onImageError: onImageError
|
|
221
172
|
});
|
|
222
173
|
});
|
|
223
174
|
|
|
224
|
-
_defineProperty(this, "shouldFireEvent", action => !this.lastAnalyticsAction || this.lastAnalyticsAction !== action);
|
|
225
|
-
|
|
226
175
|
_defineProperty(this, "renderProgressBar", () => {
|
|
227
176
|
const {
|
|
228
177
|
mediaName,
|
|
@@ -345,9 +294,7 @@ export class FileCardImageViewBase extends Component {
|
|
|
345
294
|
|
|
346
295
|
}
|
|
347
296
|
|
|
348
|
-
_defineProperty(
|
|
297
|
+
_defineProperty(FileCardImageView, "defaultProps", {
|
|
349
298
|
resizeMode: 'crop',
|
|
350
299
|
disableOverlay: false
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
export const FileCardImageView = withAnalyticsEvents()(withFileAttributes(FileCardImageViewBase));
|
|
300
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { FileCardImageView
|
|
1
|
+
export { FileCardImageView } from './cardImageView';
|
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
import { fireMediaCardEvent, getRenderSucceededEventPayload, getRenderErrorEventPayload, getRenderFailedFileStatusPayload, getCopiedFilePayload, getRenderCommencedEventPayload, getRenderPreviewableCardPayload } from '../../utils/analytics';
|
|
2
|
-
export const relevantFeatureFlagNames = ['newCardExperience', '
|
|
3
|
-
export const fireOperationalEvent = (createAnalyticsEvent, status, fileAttributes, performanceAttributes, {
|
|
4
|
-
cardPreview,
|
|
5
|
-
error
|
|
6
|
-
} = {}) => {
|
|
2
|
+
export const relevantFeatureFlagNames = ['newCardExperience', 'captions'];
|
|
3
|
+
export const fireOperationalEvent = (createAnalyticsEvent, status, fileAttributes, performanceAttributes, error) => {
|
|
7
4
|
const fireEvent = payload => fireMediaCardEvent(payload, createAnalyticsEvent);
|
|
8
5
|
|
|
9
6
|
switch (status) {
|
|
10
7
|
case 'complete':
|
|
11
|
-
|
|
12
|
-
* A Card that is considered Complete and has no preview,
|
|
13
|
-
* reflects an expected behaviour, and thus a legitimate
|
|
14
|
-
* success case to be logged.
|
|
15
|
-
*/
|
|
16
|
-
if (!(cardPreview !== null && cardPreview !== void 0 && cardPreview.dataURI)) {
|
|
17
|
-
fireEvent(getRenderSucceededEventPayload(fileAttributes, performanceAttributes));
|
|
18
|
-
}
|
|
19
|
-
|
|
8
|
+
fireEvent(getRenderSucceededEventPayload(fileAttributes, performanceAttributes));
|
|
20
9
|
break;
|
|
21
10
|
|
|
22
11
|
case 'failed-processing':
|
|
@@ -7,6 +7,7 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
7
7
|
* imported file only contains and depends on only what is required for it to function.
|
|
8
8
|
*/
|
|
9
9
|
import React from 'react';
|
|
10
|
+
import { imageResizeModeToFileImageMode } from '@atlaskit/media-client';
|
|
10
11
|
import { MediaImage } from '@atlaskit/media-ui';
|
|
11
12
|
import SpinnerIcon from '@atlaskit/spinner';
|
|
12
13
|
import { getRequestedDimensions } from '../../utils/getDataURIDimension';
|
|
@@ -33,7 +34,7 @@ export const CardSSRView = ({
|
|
|
33
34
|
} = getRequestedDimensions({
|
|
34
35
|
dimensions
|
|
35
36
|
});
|
|
36
|
-
const mode = resizeMode
|
|
37
|
+
const mode = imageResizeModeToFileImageMode(resizeMode);
|
|
37
38
|
dataURI = mediaClient.getImageUrlSync(identifier.id, {
|
|
38
39
|
collection: identifier.collectionName,
|
|
39
40
|
mode,
|
|
@@ -53,7 +54,7 @@ export const CardSSRView = ({
|
|
|
53
54
|
breakpoint: calculateBreakpoint(dimensions),
|
|
54
55
|
shouldUsePointerCursor: Boolean(dataURI),
|
|
55
56
|
displayBackground: shouldDisplayBackground,
|
|
56
|
-
disableOverlay: disableOverlay,
|
|
57
|
+
disableOverlay: !!disableOverlay,
|
|
57
58
|
selected: false,
|
|
58
59
|
"data-testid": "media-card-view"
|
|
59
60
|
}, /*#__PURE__*/React.createElement(CardImageContainer, {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isErrorFileState } from '@atlaskit/media-client';
|
|
2
|
+
import { MediaCardError } from '../../errors';
|
|
3
|
+
import { getCardStatus, isFinalCardStatus } from './getCardStatus';
|
|
4
|
+
import { extractFilePreviewStatus } from './getCardPreview';
|
|
5
|
+
export const createStateUpdater = newState => prevState => {
|
|
6
|
+
// Only override if previous status is non-final
|
|
7
|
+
// or new status is 'complete'
|
|
8
|
+
if (isFinalCardStatus(prevState.status) && newState.status !== 'complete') {
|
|
9
|
+
return prevState;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return { ...prevState,
|
|
13
|
+
...newState
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export const getCardStateFromFileState = (fileState, isBannedLocalPreview, featureFlags) => {
|
|
17
|
+
const status = getCardStatus(fileState.status, extractFilePreviewStatus(fileState, isBannedLocalPreview, featureFlags));
|
|
18
|
+
const error = status === 'error' && isErrorFileState(fileState) ? new MediaCardError('error-file-state', new Error(fileState.message)) : undefined;
|
|
19
|
+
const progress = status === 'uploading' && fileState.status === 'uploading' ? fileState.progress : 1;
|
|
20
|
+
return {
|
|
21
|
+
fileState,
|
|
22
|
+
status,
|
|
23
|
+
progress,
|
|
24
|
+
error
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -17,6 +17,11 @@ export class CardPreviewCacheImpl {
|
|
|
17
17
|
this.previewCache.set(cacheKey, cardPreview);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
_defineProperty(this, "remove", (id, dimensions) => {
|
|
21
|
+
const cacheKey = getCacheKey(id, dimensions);
|
|
22
|
+
this.previewCache.remove(cacheKey);
|
|
23
|
+
});
|
|
24
|
+
|
|
20
25
|
this.previewCache = previewCache;
|
|
21
26
|
}
|
|
22
27
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
2
|
+
import { isPreviewableFileState, isPreviewableType, isImageRepresentationReady } from '@atlaskit/media-client';
|
|
3
|
+
import { isSupportedLocalPreview } from './helpers'; // TODO: align these checks with helpers from Media Client
|
|
4
|
+
// https://product-fabric.atlassian.net/browse/BMPT-1300
|
|
5
|
+
|
|
6
|
+
export const extractFilePreviewStatus = (fileState, isBannedLocalPreview, featureFlags) => {
|
|
7
|
+
const hasFilesize = 'size' in fileState && !!fileState.size;
|
|
8
|
+
const {
|
|
9
|
+
mediaType
|
|
10
|
+
} = 'mediaType' in fileState && fileState || {};
|
|
11
|
+
const {
|
|
12
|
+
mimeType
|
|
13
|
+
} = 'mimeType' in fileState && fileState || {};
|
|
14
|
+
const isPreviewable = !!mediaType && isPreviewableType(mediaType, featureFlags); // Local preview is available only if it's supported by browser and supported by Media Card (isSupportedLocalPreview)
|
|
15
|
+
// For example, SVGs are mime type NOT supported by browser but media type supported by Media Card (image)
|
|
16
|
+
// Then, local Preview NOT available
|
|
17
|
+
|
|
18
|
+
const hasLocalPreview = !isBannedLocalPreview && isPreviewableFileState(fileState) && isSupportedLocalPreview(mediaType) && !!mimeType && isMimeTypeSupportedByBrowser(mimeType);
|
|
19
|
+
const hasRemotePreview = isImageRepresentationReady(fileState);
|
|
20
|
+
const hasPreview = hasLocalPreview || hasRemotePreview;
|
|
21
|
+
const isSupportedByBrowser = !!mimeType && isMimeTypeSupportedByBrowser(mimeType);
|
|
22
|
+
return {
|
|
23
|
+
hasFilesize,
|
|
24
|
+
isPreviewable,
|
|
25
|
+
hasPreview,
|
|
26
|
+
isSupportedByBrowser
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export const isPreviewableStatus = (cardStatus, {
|
|
30
|
+
isPreviewable,
|
|
31
|
+
hasPreview,
|
|
32
|
+
isSupportedByBrowser
|
|
33
|
+
}) => {
|
|
34
|
+
return hasPreview && isPreviewable && (cardStatus === 'complete' || cardStatus === 'loading-preview' || cardStatus === 'uploading' || cardStatus === 'processing' && isSupportedByBrowser);
|
|
35
|
+
};
|
|
@@ -69,19 +69,9 @@ export const getCardPreviewFromFilePreview = async filePreview => {
|
|
|
69
69
|
|
|
70
70
|
throw new LocalPreviewError('local-preview-unsupported');
|
|
71
71
|
};
|
|
72
|
-
export const getCardPreviewFromBackend = async (mediaClient, id, {
|
|
73
|
-
width,
|
|
74
|
-
height
|
|
75
|
-
}, collectionName, resizeMode) => {
|
|
72
|
+
export const getCardPreviewFromBackend = async (mediaClient, id, params) => {
|
|
76
73
|
try {
|
|
77
|
-
const
|
|
78
|
-
const blob = await mediaClient.getImage(id, {
|
|
79
|
-
collection: collectionName,
|
|
80
|
-
mode,
|
|
81
|
-
width,
|
|
82
|
-
height,
|
|
83
|
-
allowAnimated: true
|
|
84
|
-
});
|
|
74
|
+
const blob = await mediaClient.getImage(id, params);
|
|
85
75
|
return {
|
|
86
76
|
dataURI: URL.createObjectURL(blob),
|
|
87
77
|
orientation: 1,
|
|
@@ -1,45 +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
|
|
4
|
+
import { getCardPreviewFromFilePreview, getCardPreviewFromBackend } from './helpers';
|
|
5
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 || cardStatus === 'processing' && hasPreview && isPreviewable && isSupportedByBrowser;
|
|
41
|
-
};
|
|
6
|
+
import { isBigger } from '../../../utils/dimensionComparer';
|
|
7
|
+
import { extractFilePreviewStatus, isPreviewableStatus } from './filePreviewStatus';
|
|
8
|
+
export { getCardPreviewFromFilePreview, getCardPreviewFromBackend, isSupportedLocalPreview } from './helpers';
|
|
9
|
+
export { extractFilePreviewStatus } from './filePreviewStatus';
|
|
42
10
|
export const getCardPreviewFromCache = cardPreviewCache.get;
|
|
11
|
+
export const removeCardPreviewFromCache = cardPreviewCache.remove;
|
|
43
12
|
/**
|
|
44
13
|
* Will return the preview if available and supported by the browser
|
|
45
14
|
* See extractFilePreviewStatus "hasLocalPreview" logic
|
|
@@ -47,6 +16,33 @@ export const getCardPreviewFromCache = cardPreviewCache.get;
|
|
|
47
16
|
|
|
48
17
|
export const getFilePreviewFromFileState = fileState => 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) && isPreviewableFileState(fileState) ? fileState.preview : undefined;
|
|
49
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
|
+
default:
|
|
32
|
+
source = preview.source;
|
|
33
|
+
} // We want to embed some meta context into dataURI for Copy/Paste to work.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
const dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI; // We store new cardPreview into cache
|
|
37
|
+
|
|
38
|
+
cardPreviewCache.set(id, dimensions, { ...preview,
|
|
39
|
+
source,
|
|
40
|
+
dataURI
|
|
41
|
+
});
|
|
42
|
+
return { ...preview,
|
|
43
|
+
dataURI
|
|
44
|
+
};
|
|
45
|
+
};
|
|
50
46
|
/**
|
|
51
47
|
* This function will try to return a Card preview, either from cache, local preview or remote preview.
|
|
52
48
|
* It should only be called if there is a chance to get either a remote or a local preview, or both.
|
|
@@ -57,28 +53,29 @@ export const getFilePreviewFromFileState = fileState => 'mimeType' in fileState
|
|
|
57
53
|
* In that case, we still want to report the local preview error to the caller, for feature realiability track.
|
|
58
54
|
* hence the use of the optional callback onLocalPreviewError
|
|
59
55
|
*/
|
|
56
|
+
|
|
57
|
+
|
|
60
58
|
export const getCardPreview = async ({
|
|
61
59
|
mediaClient,
|
|
62
60
|
id,
|
|
63
|
-
collectionName,
|
|
64
|
-
requestedDimensions,
|
|
65
|
-
isRemotePreviewReady,
|
|
66
|
-
addContextToDataURI,
|
|
67
|
-
filePreview,
|
|
68
61
|
dimensions = {},
|
|
69
|
-
|
|
70
|
-
onLocalPreviewError
|
|
62
|
+
filePreview,
|
|
63
|
+
onLocalPreviewError,
|
|
64
|
+
isRemotePreviewReady,
|
|
65
|
+
imageUrlParams,
|
|
66
|
+
mediaBlobUrlAttrs
|
|
71
67
|
}) => {
|
|
72
|
-
|
|
68
|
+
const cachedPreview = cardPreviewCache.get(id, dimensions);
|
|
73
69
|
|
|
74
|
-
if (
|
|
75
|
-
return
|
|
76
|
-
source: 'cache'
|
|
77
|
-
};
|
|
70
|
+
if (cachedPreview) {
|
|
71
|
+
return cachedPreview;
|
|
78
72
|
}
|
|
79
73
|
|
|
80
74
|
try {
|
|
81
|
-
|
|
75
|
+
if (filePreview) {
|
|
76
|
+
const localPreview = await getCardPreviewFromFilePreview(filePreview);
|
|
77
|
+
return extendAndCachePreview(id, dimensions, localPreview, mediaBlobUrlAttrs);
|
|
78
|
+
}
|
|
82
79
|
} catch (e) {
|
|
83
80
|
/**
|
|
84
81
|
* We report the error if:
|
|
@@ -104,29 +101,29 @@ export const getCardPreview = async ({
|
|
|
104
101
|
}
|
|
105
102
|
}
|
|
106
103
|
|
|
107
|
-
if (!
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
throw new MediaCardError('remote-preview-not-ready');
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
cardPreview = await getCardPreviewFromBackend(mediaClient, id, requestedDimensions, collectionName, resizeMode);
|
|
104
|
+
if (!isRemotePreviewReady) {
|
|
105
|
+
/**
|
|
106
|
+
* We throw this in case this function has been called
|
|
107
|
+
* without checking isRemotePreviewReady first.
|
|
108
|
+
* If remote preview is not ready, the call to getCardPreviewFromBackend
|
|
109
|
+
* will generate a console error due to a 404 code
|
|
110
|
+
*/
|
|
111
|
+
throw new MediaCardError('remote-preview-not-ready');
|
|
119
112
|
}
|
|
120
|
-
/**
|
|
121
|
-
* In case we've retrieved cardPreview using one of the two methods above,
|
|
122
|
-
* we want to embed some meta context into dataURI for Copy/Paste to work.
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
113
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
114
|
+
const remotePreview = await getCardPreviewFromBackend(mediaClient, id, imageUrlParams);
|
|
115
|
+
return extendAndCachePreview(id, dimensions, remotePreview, mediaBlobUrlAttrs);
|
|
116
|
+
};
|
|
117
|
+
export const shouldResolvePreview = ({
|
|
118
|
+
status,
|
|
119
|
+
fileState,
|
|
120
|
+
dimensions,
|
|
121
|
+
prevDimensions,
|
|
122
|
+
hasCardPreview,
|
|
123
|
+
isBannedLocalPreview,
|
|
124
|
+
featureFlags
|
|
125
|
+
}) => {
|
|
126
|
+
const statusIsPreviewable = isPreviewableStatus(status, extractFilePreviewStatus(fileState, isBannedLocalPreview, featureFlags));
|
|
127
|
+
const dimensionsAreBigger = isBigger(prevDimensions, dimensions);
|
|
128
|
+
return statusIsPreviewable && (!hasCardPreview || dimensionsAreBigger);
|
|
132
129
|
};
|