@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,80 +1,32 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import
|
|
3
|
-
import React from 'react';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
4
3
|
import { MediaImage } from '@atlaskit/media-ui';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
fileAttributes
|
|
20
|
-
} = this.props;
|
|
21
|
-
|
|
22
|
-
if (fileAttributes && this.shouldFireEvent(RenderEventAction.SUCCEEDED)) {
|
|
23
|
-
fireMediaCardEvent(getRenderSucceededEventPayload(fileAttributes), createAnalyticsEvent);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
_defineProperty(this, "onImageError", () => {
|
|
28
|
-
const {
|
|
29
|
-
onImageError,
|
|
30
|
-
fileAttributes
|
|
31
|
-
} = this.props;
|
|
32
|
-
onImageError && onImageError();
|
|
33
|
-
|
|
34
|
-
if (fileAttributes && this.shouldFireEvent(RenderEventAction.FAILED)) {
|
|
35
|
-
const {
|
|
36
|
-
createAnalyticsEvent,
|
|
37
|
-
mediaItemType
|
|
38
|
-
} = this.props;
|
|
39
|
-
|
|
40
|
-
if (mediaItemType === 'file') {
|
|
41
|
-
fireMediaCardEvent(getRenderFailedFileUriPayload(fileAttributes), createAnalyticsEvent);
|
|
42
|
-
} else if (mediaItemType === 'external-image') {
|
|
43
|
-
fireMediaCardEvent(getRenderFailedExternalUriPayload(fileAttributes), createAnalyticsEvent);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
_defineProperty(this, "shouldFireEvent", action => !this.lastAnalyticsAction || this.lastAnalyticsAction !== action);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
componentDidMount() {
|
|
4
|
+
import { resizeModeToMediaImageProps } from '../../../utils/resizeModeToMediaImageProps';
|
|
5
|
+
export const ImageRenderer = ({
|
|
6
|
+
dataURI,
|
|
7
|
+
previewOrientation,
|
|
8
|
+
alt,
|
|
9
|
+
resizeMode,
|
|
10
|
+
onImageLoad,
|
|
11
|
+
onImageError,
|
|
12
|
+
onDisplayImage,
|
|
13
|
+
mediaType,
|
|
14
|
+
nativeLazyLoad,
|
|
15
|
+
forceSyncDisplay
|
|
16
|
+
}) => {
|
|
17
|
+
useEffect(() => {
|
|
52
18
|
// TODO: trigger accordingly with the succeeded event. This could be a breaking change
|
|
53
|
-
const {
|
|
54
|
-
onDisplayImage,
|
|
55
|
-
mediaType
|
|
56
|
-
} = this.props;
|
|
57
|
-
|
|
58
19
|
if (mediaType === 'image' && onDisplayImage) {
|
|
59
20
|
onDisplayImage();
|
|
60
21
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
alt: alt,
|
|
73
|
-
previewOrientation: previewOrientation,
|
|
74
|
-
onImageLoad: this.onImageLoad,
|
|
75
|
-
onImageError: this.onImageError
|
|
76
|
-
}, resizeModeToMediaImageProps(resizeMode)));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
export const ImageRenderer = withAnalyticsEvents()(withFileAttributes(ImageRendererBase));
|
|
22
|
+
}, [mediaType, onDisplayImage]);
|
|
23
|
+
return /*#__PURE__*/React.createElement(MediaImage, _extends({
|
|
24
|
+
dataURI: dataURI,
|
|
25
|
+
alt: alt,
|
|
26
|
+
previewOrientation: previewOrientation,
|
|
27
|
+
onImageLoad: onImageLoad,
|
|
28
|
+
onImageError: onImageError,
|
|
29
|
+
loading: nativeLazyLoad ? 'lazy' : undefined,
|
|
30
|
+
forceSyncDisplay: forceSyncDisplay
|
|
31
|
+
}, resizeModeToMediaImageProps(resizeMode)));
|
|
32
|
+
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TitleBoxWrapper, ErrorMessageWrapper } from './styled';
|
|
3
3
|
import EditorWarningIcon from '@atlaskit/icon/glyph/editor/warning';
|
|
4
|
+
import { messages } from '@atlaskit/media-ui';
|
|
4
5
|
import { R300 } from '@atlaskit/theme/colors';
|
|
5
|
-
import {
|
|
6
|
+
import { FormattedMessage } from 'react-intl';
|
|
6
7
|
export const FailedTitleBox = ({
|
|
7
|
-
breakpoint
|
|
8
|
+
breakpoint,
|
|
9
|
+
customMessage = messages.failed_to_load
|
|
8
10
|
}) => {
|
|
9
11
|
return /*#__PURE__*/React.createElement(TitleBoxWrapper, {
|
|
10
12
|
breakpoint: breakpoint
|
|
@@ -12,5 +14,5 @@ export const FailedTitleBox = ({
|
|
|
12
14
|
label: 'Warning',
|
|
13
15
|
size: 'small',
|
|
14
16
|
primaryColor: R300
|
|
15
|
-
}),
|
|
17
|
+
}), /*#__PURE__*/React.createElement(FormattedMessage, customMessage)));
|
|
16
18
|
};
|
|
@@ -2,14 +2,6 @@ import { getMediaClientErrorReason, isRequestError } from '@atlaskit/media-clien
|
|
|
2
2
|
import { ANALYTICS_MEDIA_CHANNEL } from '@atlaskit/media-common';
|
|
3
3
|
import { createAndFireEvent } from '@atlaskit/analytics-next';
|
|
4
4
|
import { isMediaCardError } from '../errors';
|
|
5
|
-
export let RenderEventAction;
|
|
6
|
-
|
|
7
|
-
(function (RenderEventAction) {
|
|
8
|
-
RenderEventAction["COMMENCED"] = "commenced";
|
|
9
|
-
RenderEventAction["SUCCEEDED"] = "succeeded";
|
|
10
|
-
RenderEventAction["FAILED"] = "failed";
|
|
11
|
-
})(RenderEventAction || (RenderEventAction = {}));
|
|
12
|
-
|
|
13
5
|
export const getFileAttributes = (metadata, fileStatus) => ({
|
|
14
6
|
fileMediatype: metadata.mediaType,
|
|
15
7
|
fileMimetype: metadata.mimeType,
|
|
@@ -17,49 +9,44 @@ export const getFileAttributes = (metadata, fileStatus) => ({
|
|
|
17
9
|
fileSize: metadata.size,
|
|
18
10
|
fileStatus
|
|
19
11
|
});
|
|
20
|
-
export const
|
|
21
|
-
eventType: '
|
|
22
|
-
action:
|
|
23
|
-
actionSubject: '
|
|
12
|
+
export const getRenderPreviewableCardPayload = fileAttributes => ({
|
|
13
|
+
eventType: 'screen',
|
|
14
|
+
action: 'viewed',
|
|
15
|
+
actionSubject: 'mediaCardRenderScreen',
|
|
16
|
+
name: 'mediaCardRenderScreen',
|
|
24
17
|
attributes: {
|
|
18
|
+
type: fileAttributes.fileMediatype,
|
|
25
19
|
fileAttributes
|
|
26
20
|
}
|
|
27
21
|
});
|
|
28
|
-
export const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!fileStatus) {
|
|
39
|
-
// This fail reason will come from a bug, most likely.
|
|
40
|
-
return `unknown-uri`;
|
|
41
|
-
} else if (fileStatus === 'uploading') {
|
|
42
|
-
return 'local-uri';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return 'remote-uri';
|
|
22
|
+
export const getRenderCommencedEventPayload = (fileAttributes, performanceAttributes) => {
|
|
23
|
+
return {
|
|
24
|
+
eventType: 'operational',
|
|
25
|
+
action: 'commenced',
|
|
26
|
+
actionSubject: 'mediaCardRender',
|
|
27
|
+
attributes: {
|
|
28
|
+
fileAttributes,
|
|
29
|
+
performanceAttributes
|
|
30
|
+
}
|
|
31
|
+
};
|
|
46
32
|
};
|
|
47
|
-
export const
|
|
33
|
+
export const getRenderSucceededEventPayload = (fileAttributes, performanceAttributes) => ({
|
|
48
34
|
eventType: 'operational',
|
|
49
|
-
action:
|
|
35
|
+
action: 'succeeded',
|
|
50
36
|
actionSubject: 'mediaCardRender',
|
|
51
37
|
attributes: {
|
|
52
38
|
fileAttributes,
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
performanceAttributes,
|
|
40
|
+
status: 'success'
|
|
55
41
|
}
|
|
56
42
|
});
|
|
57
|
-
export const getRenderFailedExternalUriPayload = fileAttributes => ({
|
|
43
|
+
export const getRenderFailedExternalUriPayload = (fileAttributes, performanceAttributes) => ({
|
|
58
44
|
eventType: 'operational',
|
|
59
|
-
action:
|
|
45
|
+
action: 'failed',
|
|
60
46
|
actionSubject: 'mediaCardRender',
|
|
61
47
|
attributes: {
|
|
62
48
|
fileAttributes,
|
|
49
|
+
performanceAttributes,
|
|
63
50
|
status: 'fail',
|
|
64
51
|
failReason: 'external-uri'
|
|
65
52
|
}
|
|
@@ -94,12 +81,13 @@ export const getRenderErrorRequestMetadata = error => {
|
|
|
94
81
|
return error.secondaryError.metadata;
|
|
95
82
|
}
|
|
96
83
|
};
|
|
97
|
-
export const getRenderErrorEventPayload = (fileAttributes, error) => ({
|
|
84
|
+
export const getRenderErrorEventPayload = (fileAttributes, performanceAttributes, error) => ({
|
|
98
85
|
eventType: 'operational',
|
|
99
|
-
action:
|
|
86
|
+
action: 'failed',
|
|
100
87
|
actionSubject: 'mediaCardRender',
|
|
101
88
|
attributes: {
|
|
102
89
|
fileAttributes,
|
|
90
|
+
performanceAttributes,
|
|
103
91
|
status: 'fail',
|
|
104
92
|
failReason: getRenderErrorFailReason(error),
|
|
105
93
|
error: getRenderErrorErrorReason(error),
|
|
@@ -107,12 +95,13 @@ export const getRenderErrorEventPayload = (fileAttributes, error) => ({
|
|
|
107
95
|
request: getRenderErrorRequestMetadata(error)
|
|
108
96
|
}
|
|
109
97
|
});
|
|
110
|
-
export const getRenderFailedFileStatusPayload = fileAttributes => ({
|
|
98
|
+
export const getRenderFailedFileStatusPayload = (fileAttributes, performanceAttributes) => ({
|
|
111
99
|
eventType: 'operational',
|
|
112
|
-
action:
|
|
100
|
+
action: 'failed',
|
|
113
101
|
actionSubject: 'mediaCardRender',
|
|
114
102
|
attributes: {
|
|
115
103
|
fileAttributes,
|
|
104
|
+
performanceAttributes,
|
|
116
105
|
status: 'fail',
|
|
117
106
|
failReason: 'failed-processing'
|
|
118
107
|
}
|
|
@@ -57,14 +57,18 @@ export class CardActionsDropdownMenu extends Component {
|
|
|
57
57
|
|
|
58
58
|
if (actions.length > 0) {
|
|
59
59
|
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
60
|
-
|
|
60
|
+
testId: "media-card-actions-menu",
|
|
61
61
|
onOpenChange: onOpenChange,
|
|
62
|
-
trigger:
|
|
62
|
+
trigger: ({
|
|
63
|
+
triggerRef,
|
|
64
|
+
...providedProps
|
|
65
|
+
}) => /*#__PURE__*/React.createElement(CardActionButtonWithAnalytics, _extends({
|
|
63
66
|
variant: triggerVariant,
|
|
64
67
|
style: {
|
|
65
68
|
color: triggerColor
|
|
66
|
-
}
|
|
67
|
-
|
|
69
|
+
},
|
|
70
|
+
ref: triggerRef
|
|
71
|
+
}, providedProps), /*#__PURE__*/React.createElement(MoreIcon, {
|
|
68
72
|
label: "more"
|
|
69
73
|
}))
|
|
70
74
|
}, /*#__PURE__*/React.createElement(DropdownItemGroup, null, actions.map(createDropdownItemWithAnalytics)));
|
|
@@ -20,7 +20,7 @@ export const canCompareDimension = (current, next) => {
|
|
|
20
20
|
return false;
|
|
21
21
|
};
|
|
22
22
|
export const isBigger = (current, next) => {
|
|
23
|
-
if (canCompareDimension(current.width, next.width) && canCompareDimension(current.height, next.height)) {
|
|
23
|
+
if (!!current && !!next && canCompareDimension(current.width, next.width) && canCompareDimension(current.height, next.height)) {
|
|
24
24
|
const nextIsHigher = parseInt(`${current.width}`, 10) < parseInt(`${next.width}`, 10);
|
|
25
25
|
const nextIsWider = parseInt(`${current.height}`, 10) < parseInt(`${next.height}`, 10);
|
|
26
26
|
return nextIsHigher || nextIsWider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default (() => document);
|
|
@@ -20,4 +20,12 @@ export const getDataURIDimension = (dimension, options) => {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
return defaultImageCardDimensions[dimension] * retinaFactor;
|
|
23
|
+
};
|
|
24
|
+
export const getRequestedDimensions = options => {
|
|
25
|
+
const width = getDataURIDimension('width', options);
|
|
26
|
+
const height = getDataURIDimension('height', options);
|
|
27
|
+
return {
|
|
28
|
+
width,
|
|
29
|
+
height
|
|
30
|
+
};
|
|
23
31
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isErrorFileState } from '@atlaskit/media-client';
|
|
1
|
+
import { isErrorFileState, isFileIdentifier } from '@atlaskit/media-client';
|
|
2
2
|
|
|
3
3
|
const getProcessingStatusFromFileState = status => {
|
|
4
4
|
switch (status) {
|
|
@@ -13,7 +13,7 @@ const getProcessingStatusFromFileState = status => {
|
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const getFileDetailsFromFileState = state => ({
|
|
17
17
|
id: state.id,
|
|
18
18
|
name: state.name,
|
|
19
19
|
size: state.size,
|
|
@@ -21,6 +21,14 @@ export const getFileDetails = state => !isErrorFileState(state) ? {
|
|
|
21
21
|
createdAt: state.createdAt,
|
|
22
22
|
mediaType: state.mediaType,
|
|
23
23
|
processingStatus: getProcessingStatusFromFileState(state.status)
|
|
24
|
-
}
|
|
25
|
-
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const getFileDetails = (identifier, fileState) => {
|
|
27
|
+
return isFileIdentifier(identifier) ? fileState && !isErrorFileState(fileState) ? getFileDetailsFromFileState(fileState) : {
|
|
28
|
+
id: identifier.id
|
|
29
|
+
} : {
|
|
30
|
+
id: identifier.mediaItemType,
|
|
31
|
+
name: identifier.name || identifier.dataURI,
|
|
32
|
+
mediaType: 'image'
|
|
33
|
+
};
|
|
26
34
|
};
|
|
@@ -42,5 +42,10 @@ export class ObjectURLCache {
|
|
|
42
42
|
this.cache.set(key, value);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
remove(key) {
|
|
46
|
+
const removed = this.cache.remove(key);
|
|
47
|
+
removed && URL.revokeObjectURL(removed.dataURI);
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
}
|
|
46
51
|
export const createObjectURLCache = () => new ObjectURLCache(PREVIEW_CACHE_LRU_SIZE);
|
|
@@ -5,7 +5,7 @@ export const shouldDisplayImageThumbnail = (cardStatus, mediaItemType, dataURI,
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
if (dataURI) {
|
|
8
|
-
return mediaItemType === 'external-image' || mimeType && isMimeTypeSupportedByBrowser(mimeType) || cardStatus === 'complete';
|
|
8
|
+
return mediaItemType === 'external-image' || mimeType && isMimeTypeSupportedByBrowser(mimeType) || cardStatus === 'complete' || cardStatus === 'loading-preview';
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
return false;
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/errors.js
CHANGED
|
@@ -70,6 +70,59 @@ export var RemotePreviewError = /*#__PURE__*/function (_MediaCardError2) {
|
|
|
70
70
|
|
|
71
71
|
return RemotePreviewError;
|
|
72
72
|
}(MediaCardError);
|
|
73
|
+
export var SsrPreviewError = /*#__PURE__*/function (_MediaCardError3) {
|
|
74
|
+
_inherits(SsrPreviewError, _MediaCardError3);
|
|
75
|
+
|
|
76
|
+
var _super4 = _createSuper(SsrPreviewError);
|
|
77
|
+
|
|
78
|
+
function SsrPreviewError(primaryReason, secondaryError) {
|
|
79
|
+
var _this4;
|
|
80
|
+
|
|
81
|
+
_classCallCheck(this, SsrPreviewError);
|
|
82
|
+
|
|
83
|
+
_this4 = _super4.call(this, primaryReason, secondaryError);
|
|
84
|
+
_this4.primaryReason = primaryReason;
|
|
85
|
+
_this4.secondaryError = secondaryError;
|
|
86
|
+
return _this4;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return SsrPreviewError;
|
|
90
|
+
}(MediaCardError);
|
|
91
|
+
export var getImageLoadPrimaryReason = function getImageLoadPrimaryReason(source) {
|
|
92
|
+
switch (source) {
|
|
93
|
+
case 'cache-remote':
|
|
94
|
+
return 'cache-remote-uri';
|
|
95
|
+
|
|
96
|
+
case 'cache-local':
|
|
97
|
+
return 'cache-local-uri';
|
|
98
|
+
|
|
99
|
+
case 'external':
|
|
100
|
+
return 'external-uri';
|
|
101
|
+
|
|
102
|
+
case 'local':
|
|
103
|
+
return 'local-uri';
|
|
104
|
+
|
|
105
|
+
case 'remote':
|
|
106
|
+
return 'remote-uri';
|
|
107
|
+
// This fail reason will come from a bug, most likely.
|
|
108
|
+
|
|
109
|
+
default:
|
|
110
|
+
return "unknown-uri";
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
export var ImageLoadError = /*#__PURE__*/function (_MediaCardError4) {
|
|
114
|
+
_inherits(ImageLoadError, _MediaCardError4);
|
|
115
|
+
|
|
116
|
+
var _super5 = _createSuper(ImageLoadError);
|
|
117
|
+
|
|
118
|
+
function ImageLoadError(source) {
|
|
119
|
+
_classCallCheck(this, ImageLoadError);
|
|
120
|
+
|
|
121
|
+
return _super5.call(this, getImageLoadPrimaryReason(source));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return ImageLoadError;
|
|
125
|
+
}(MediaCardError);
|
|
73
126
|
export function isMediaCardError(err) {
|
|
74
127
|
return err instanceof MediaCardError;
|
|
75
128
|
}
|
|
@@ -81,9 +134,15 @@ export var isRemotePreviewError = function isRemotePreviewError(err) {
|
|
|
81
134
|
};
|
|
82
135
|
export var isUnsupportedLocalPreviewError = function isUnsupportedLocalPreviewError(err) {
|
|
83
136
|
return isMediaCardError(err) && err.primaryReason === 'local-preview-unsupported';
|
|
84
|
-
};
|
|
137
|
+
};
|
|
138
|
+
export function isImageLoadError(err) {
|
|
139
|
+
return err instanceof ImageLoadError;
|
|
140
|
+
} // In a try/catch statement, the error caught is the type of any.
|
|
85
141
|
// We can use this helper to ensure that the error handled is the type of MediaCardError if unsure
|
|
86
142
|
|
|
87
143
|
export var ensureMediaCardError = function ensureMediaCardError(primaryReason, error) {
|
|
88
144
|
return isMediaCardError(error) ? error : new MediaCardError(primaryReason, error);
|
|
145
|
+
};
|
|
146
|
+
export var isUploadError = function isUploadError(error) {
|
|
147
|
+
return error && error.primaryReason === 'upload';
|
|
89
148
|
};
|