@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.
Files changed (150) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/dist/cjs/errors.js +76 -5
  3. package/dist/cjs/files/cardImageView/index.js +58 -89
  4. package/dist/cjs/files/index.js +0 -6
  5. package/dist/cjs/index.js +16 -6
  6. package/dist/cjs/root/card/cardAnalytics.js +33 -19
  7. package/dist/cjs/root/card/cardConstants.js +8 -0
  8. package/dist/cjs/root/card/cardLoader.js +66 -124
  9. package/dist/cjs/root/card/cardState.js +50 -0
  10. package/dist/cjs/root/card/getCardPreview/cache.js +5 -0
  11. package/dist/cjs/root/card/getCardPreview/filePreviewStatus.js +50 -0
  12. package/dist/cjs/root/card/getCardPreview/helpers.js +13 -21
  13. package/dist/cjs/root/card/getCardPreview/index.js +171 -100
  14. package/dist/cjs/root/card/getCardStatus.js +7 -1
  15. package/dist/cjs/root/card/index.js +407 -322
  16. package/dist/cjs/root/cardView.js +115 -76
  17. package/dist/cjs/root/index.js +9 -1
  18. package/dist/cjs/root/inline/loader.js +22 -21
  19. package/dist/cjs/root/inline/{inlineMediaCard.js → mediaInlineCard.js} +72 -25
  20. package/dist/cjs/root/inlinePlayer.js +5 -15
  21. package/dist/cjs/root/ui/iconMessage/index.js +17 -9
  22. package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +36 -115
  23. package/dist/cjs/root/ui/styled.js +1 -1
  24. package/dist/cjs/root/ui/titleBox/failedTitleBox.js +7 -3
  25. package/dist/cjs/utils/analytics.js +26 -43
  26. package/dist/cjs/utils/cardActions/cardActionsDropdownMenu.js +16 -9
  27. package/dist/cjs/utils/dimensionComparer.js +1 -1
  28. package/dist/cjs/utils/document.js +12 -0
  29. package/dist/cjs/utils/getDataURIDimension.js +13 -2
  30. package/dist/cjs/utils/metadata.js +11 -3
  31. package/dist/cjs/utils/objectURLCache.js +6 -0
  32. package/dist/cjs/utils/resizeModeToMediaImageProps.js +13 -0
  33. package/dist/cjs/utils/shouldDisplayImageThumbnail.js +1 -1
  34. package/dist/cjs/version.json +1 -1
  35. package/dist/es2019/errors.js +42 -2
  36. package/dist/es2019/files/cardImageView/index.js +12 -46
  37. package/dist/es2019/files/index.js +1 -1
  38. package/dist/es2019/index.js +3 -3
  39. package/dist/es2019/root/card/cardAnalytics.js +23 -17
  40. package/dist/es2019/root/card/cardConstants.js +1 -0
  41. package/dist/es2019/root/card/cardLoader.js +47 -53
  42. package/dist/es2019/root/card/cardState.js +26 -0
  43. package/dist/es2019/root/card/getCardPreview/cache.js +5 -0
  44. package/dist/es2019/root/card/getCardPreview/filePreviewStatus.js +35 -0
  45. package/dist/es2019/root/card/getCardPreview/helpers.js +2 -12
  46. package/dist/es2019/root/card/getCardPreview/index.js +112 -79
  47. package/dist/es2019/root/card/getCardStatus.js +1 -0
  48. package/dist/es2019/root/card/index.js +356 -254
  49. package/dist/es2019/root/cardView.js +98 -58
  50. package/dist/es2019/root/index.js +2 -1
  51. package/dist/es2019/root/inline/loader.js +16 -15
  52. package/dist/es2019/root/inline/mediaInlineCard.js +132 -0
  53. package/dist/es2019/root/inlinePlayer.js +5 -13
  54. package/dist/es2019/root/ui/iconMessage/index.js +10 -6
  55. package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +26 -74
  56. package/dist/es2019/root/ui/styled.js +1 -0
  57. package/dist/es2019/root/ui/titleBox/failedTitleBox.js +5 -3
  58. package/dist/es2019/utils/analytics.js +29 -40
  59. package/dist/es2019/utils/cardActions/cardActionsDropdownMenu.js +8 -4
  60. package/dist/es2019/utils/dimensionComparer.js +1 -1
  61. package/dist/es2019/utils/document.js +1 -0
  62. package/dist/es2019/utils/getDataURIDimension.js +8 -0
  63. package/dist/es2019/utils/metadata.js +12 -4
  64. package/dist/es2019/utils/objectURLCache.js +5 -0
  65. package/dist/es2019/utils/resizeModeToMediaImageProps.js +6 -0
  66. package/dist/es2019/utils/shouldDisplayImageThumbnail.js +1 -1
  67. package/dist/es2019/version.json +1 -1
  68. package/dist/esm/errors.js +60 -1
  69. package/dist/esm/files/cardImageView/index.js +55 -87
  70. package/dist/esm/files/index.js +1 -1
  71. package/dist/esm/index.js +3 -3
  72. package/dist/esm/root/card/cardAnalytics.js +23 -18
  73. package/dist/esm/root/card/cardConstants.js +1 -0
  74. package/dist/esm/root/card/cardLoader.js +66 -126
  75. package/dist/esm/root/card/cardState.js +32 -0
  76. package/dist/esm/root/card/getCardPreview/cache.js +6 -0
  77. package/dist/esm/root/card/getCardPreview/filePreviewStatus.js +35 -0
  78. package/dist/esm/root/card/getCardPreview/helpers.js +13 -21
  79. package/dist/esm/root/card/getCardPreview/index.js +142 -95
  80. package/dist/esm/root/card/getCardStatus.js +3 -0
  81. package/dist/esm/root/card/index.js +416 -325
  82. package/dist/esm/root/cardView.js +114 -73
  83. package/dist/esm/root/index.js +2 -1
  84. package/dist/esm/root/inline/loader.js +23 -22
  85. package/dist/esm/root/inline/mediaInlineCard.js +145 -0
  86. package/dist/esm/root/inlinePlayer.js +5 -13
  87. package/dist/esm/root/ui/iconMessage/index.js +12 -7
  88. package/dist/esm/root/ui/imageRenderer/imageRenderer.js +28 -106
  89. package/dist/esm/root/ui/styled.js +1 -1
  90. package/dist/esm/root/ui/titleBox/failedTitleBox.js +6 -3
  91. package/dist/esm/utils/analytics.js +22 -35
  92. package/dist/esm/utils/cardActions/cardActionsDropdownMenu.js +16 -9
  93. package/dist/esm/utils/dimensionComparer.js +1 -1
  94. package/dist/esm/utils/document.js +3 -0
  95. package/dist/esm/utils/getDataURIDimension.js +8 -0
  96. package/dist/esm/utils/metadata.js +12 -4
  97. package/dist/esm/utils/objectURLCache.js +6 -0
  98. package/dist/esm/utils/resizeModeToMediaImageProps.js +6 -0
  99. package/dist/esm/utils/shouldDisplayImageThumbnail.js +1 -1
  100. package/dist/esm/version.json +1 -1
  101. package/dist/types/errors.d.ts +15 -1
  102. package/dist/types/files/cardImageView/index.d.ts +5 -12
  103. package/dist/types/files/cardImageView/styled.d.ts +1 -1
  104. package/dist/types/files/index.d.ts +1 -1
  105. package/dist/types/index.d.ts +11 -13
  106. package/dist/types/root/card/cardAnalytics.d.ts +5 -7
  107. package/dist/types/root/card/cardConstants.d.ts +1 -0
  108. package/dist/types/root/card/cardLoader.d.ts +4 -18
  109. package/dist/types/root/card/cardState.d.ts +5 -0
  110. package/dist/types/root/card/getCardPreview/cache.d.ts +4 -2
  111. package/dist/types/root/card/getCardPreview/filePreviewStatus.d.ts +5 -0
  112. package/dist/types/root/card/getCardPreview/helpers.d.ts +4 -5
  113. package/dist/types/root/card/getCardPreview/index.d.ts +25 -14
  114. package/dist/types/root/card/getCardStatus.d.ts +1 -0
  115. package/dist/types/root/card/index.d.ts +18 -15
  116. package/dist/types/root/cardView.d.ts +14 -8
  117. package/dist/types/root/index.d.ts +1 -0
  118. package/dist/types/root/inline/loader.d.ts +8 -8
  119. package/dist/types/root/inline/{inlineMediaCard.d.ts → mediaInlineCard.d.ts} +4 -4
  120. package/dist/types/root/inlinePlayer.d.ts +1 -1
  121. package/dist/types/root/ui/iconMessage/index.d.ts +7 -2
  122. package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +5 -18
  123. package/dist/types/root/ui/titleBox/failedTitleBox.d.ts +2 -0
  124. package/dist/types/types.d.ts +9 -1
  125. package/dist/types/utils/analytics.d.ts +20 -21
  126. package/dist/types/utils/cardDimensions.d.ts +5 -1
  127. package/dist/types/utils/dimensionComparer.d.ts +1 -1
  128. package/dist/types/utils/document.d.ts +2 -0
  129. package/dist/types/utils/getDataURIDimension.d.ts +3 -1
  130. package/dist/types/utils/index.d.ts +1 -0
  131. package/dist/types/utils/lazyContent/styled.d.ts +1 -1
  132. package/dist/types/utils/lightCards/types.d.ts +1 -1
  133. package/dist/types/utils/metadata.d.ts +2 -2
  134. package/dist/types/utils/objectURLCache.d.ts +2 -1
  135. package/dist/types/utils/resizeModeToMediaImageProps.d.ts +5 -0
  136. package/dist/types/utils/shouldDisplayImageThumbnail.d.ts +1 -1
  137. package/example-helpers/developmentUseMessage.tsx +14 -0
  138. package/example-helpers/index.tsx +55 -4
  139. package/example-helpers/selectableCard.tsx +2 -1
  140. package/package.json +18 -14
  141. package/dist/cjs/root/card/getCardPreview/types.js +0 -5
  142. package/dist/cjs/utils/fileAttributesContext.js +0 -40
  143. package/dist/es2019/root/card/getCardPreview/types.js +0 -1
  144. package/dist/es2019/root/inline/inlineMediaCard.js +0 -92
  145. package/dist/es2019/utils/fileAttributesContext.js +0 -19
  146. package/dist/esm/root/card/getCardPreview/types.js +0 -1
  147. package/dist/esm/root/inline/inlineMediaCard.js +0 -100
  148. package/dist/esm/utils/fileAttributesContext.js +0 -18
  149. package/dist/types/root/card/getCardPreview/types.d.ts +0 -5
  150. package/dist/types/utils/fileAttributesContext.d.ts +0 -10
@@ -1,80 +1,32 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import React from 'react';
2
+ import React, { useEffect } from 'react';
4
3
  import { MediaImage } from '@atlaskit/media-ui';
5
- import { withAnalyticsEvents } from '@atlaskit/analytics-next';
6
- import { fireMediaCardEvent, RenderEventAction, getRenderSucceededEventPayload, getRenderFailedFileUriPayload, getRenderFailedExternalUriPayload } from '../../../utils/analytics';
7
- import { withFileAttributes } from '../../../utils/fileAttributesContext';
8
- export const resizeModeToMediaImageProps = resizeMode => ({
9
- crop: resizeMode === 'crop',
10
- stretch: resizeMode === 'stretchy-fit'
11
- });
12
- export class ImageRendererBase extends React.Component {
13
- constructor(...args) {
14
- super(...args);
15
-
16
- _defineProperty(this, "onImageLoad", () => {
17
- const {
18
- createAnalyticsEvent,
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
- render() {
64
- const {
65
- dataURI,
66
- previewOrientation,
67
- alt,
68
- resizeMode
69
- } = this.props;
70
- return /*#__PURE__*/React.createElement(MediaImage, _extends({
71
- dataURI: dataURI,
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
+ };
@@ -112,6 +112,7 @@ export const NewFileExperienceWrapper = styled.div`
112
112
  &:hover .${blanketClassName} {
113
113
  ${fixedBlanketStyles}
114
114
  }
115
+
115
116
  &:hover .${actionsBarClassName} {
116
117
  ${fixedActionBarStyles}
117
118
  }
@@ -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 { getErrorMessage } from '../../../utils/getErrorMessage';
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
- }), getErrorMessage('error')));
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 getRenderCommencedEventPayload = fileAttributes => ({
21
- eventType: 'operational',
22
- action: RenderEventAction.COMMENCED,
23
- actionSubject: 'mediaCardRender',
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 getRenderSucceededEventPayload = fileAttributes => ({
29
- eventType: 'operational',
30
- action: RenderEventAction.SUCCEEDED,
31
- actionSubject: 'mediaCardRender',
32
- attributes: {
33
- fileAttributes,
34
- status: 'success'
35
- }
36
- });
37
- export const getFailedFileUriFailReason = fileStatus => {
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 getRenderFailedFileUriPayload = fileAttributes => ({
33
+ export const getRenderSucceededEventPayload = (fileAttributes, performanceAttributes) => ({
48
34
  eventType: 'operational',
49
- action: RenderEventAction.FAILED,
35
+ action: 'succeeded',
50
36
  actionSubject: 'mediaCardRender',
51
37
  attributes: {
52
38
  fileAttributes,
53
- status: 'fail',
54
- failReason: getFailedFileUriFailReason(fileAttributes.fileStatus)
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: RenderEventAction.FAILED,
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: RenderEventAction.FAILED,
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: RenderEventAction.FAILED,
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
- "data-testid": "media-card-actions-menu",
60
+ testId: "media-card-actions-menu",
61
61
  onOpenChange: onOpenChange,
62
- trigger: /*#__PURE__*/React.createElement(CardActionButtonWithAnalytics, {
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
- }, /*#__PURE__*/React.createElement(MoreIcon, {
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
- export const getFileDetails = state => !isErrorFileState(state) ? {
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
- id: state.id
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);
@@ -0,0 +1,6 @@
1
+ export function resizeModeToMediaImageProps(resizeMode) {
2
+ return {
3
+ crop: resizeMode === 'crop',
4
+ stretch: resizeMode === 'stretchy-fit'
5
+ };
6
+ }
@@ -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;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-card",
3
- "version": "70.10.0",
3
+ "version": "72.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -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
- }; // In a try/catch statement, the error caught is the type of any.
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
  };