@atlaskit/media-card 70.9.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.
Files changed (181) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/cjs/errors.js +109 -6
  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/cardSSRView.js +114 -0
  9. package/dist/cjs/root/card/cardState.js +50 -0
  10. package/dist/cjs/root/card/getCardPreview/cache.js +49 -0
  11. package/dist/cjs/root/card/getCardPreview/filePreviewStatus.js +50 -0
  12. package/dist/cjs/root/card/getCardPreview/helpers.js +215 -0
  13. package/dist/cjs/root/card/getCardPreview/index.js +225 -0
  14. package/dist/cjs/root/card/getCardStatus.js +16 -21
  15. package/dist/cjs/root/card/index.js +339 -398
  16. package/dist/cjs/root/cardView.js +108 -56
  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} +66 -24
  20. package/dist/cjs/root/inlinePlayer.js +5 -15
  21. package/dist/cjs/root/ui/Breakpoint.js +13 -0
  22. package/dist/cjs/root/ui/common.js +5 -11
  23. package/dist/cjs/root/ui/iconMessage/index.js +17 -9
  24. package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +32 -115
  25. package/dist/cjs/root/ui/loadingRateLimited/loadingRateLimited.js +2 -2
  26. package/dist/cjs/root/ui/progressBar/progressBar.js +2 -2
  27. package/dist/cjs/root/ui/progressBar/styled.js +3 -1
  28. package/dist/cjs/root/ui/styled.js +17 -80
  29. package/dist/cjs/root/ui/styledSSR.js +108 -0
  30. package/dist/cjs/root/ui/titleBox/failedTitleBox.js +7 -3
  31. package/dist/cjs/root/ui/titleBox/styled.js +3 -1
  32. package/dist/cjs/utils/analytics.js +26 -43
  33. package/dist/cjs/utils/dimensionComparer.js +1 -1
  34. package/dist/cjs/utils/document.js +12 -0
  35. package/dist/cjs/utils/getDataURIDimension.js +13 -2
  36. package/dist/cjs/utils/metadata.js +11 -3
  37. package/dist/cjs/utils/objectURLCache.js +6 -0
  38. package/dist/cjs/utils/resizeModeToMediaImageProps.js +13 -0
  39. package/dist/cjs/utils/shouldDisplayImageThumbnail.js +1 -1
  40. package/dist/cjs/utils/videoSnapshot.js +45 -0
  41. package/dist/cjs/version.json +1 -1
  42. package/dist/es2019/errors.js +52 -2
  43. package/dist/es2019/files/cardImageView/index.js +12 -46
  44. package/dist/es2019/files/index.js +1 -1
  45. package/dist/es2019/index.js +3 -3
  46. package/dist/es2019/root/card/cardAnalytics.js +23 -17
  47. package/dist/es2019/root/card/cardConstants.js +1 -0
  48. package/dist/es2019/root/card/cardSSRView.js +93 -0
  49. package/dist/es2019/root/card/cardState.js +26 -0
  50. package/dist/es2019/root/card/getCardPreview/cache.js +29 -0
  51. package/dist/es2019/root/card/getCardPreview/filePreviewStatus.js +35 -0
  52. package/dist/es2019/root/card/getCardPreview/helpers.js +83 -0
  53. package/dist/es2019/root/card/getCardPreview/index.js +129 -0
  54. package/dist/es2019/root/card/getCardStatus.js +11 -15
  55. package/dist/es2019/root/card/index.js +292 -276
  56. package/dist/es2019/root/cardView.js +107 -53
  57. package/dist/es2019/root/index.js +2 -1
  58. package/dist/es2019/root/inline/loader.js +16 -15
  59. package/dist/es2019/root/inline/mediaInlineCard.js +127 -0
  60. package/dist/es2019/root/inlinePlayer.js +5 -13
  61. package/dist/es2019/root/ui/Breakpoint.js +6 -0
  62. package/dist/es2019/root/ui/common.js +1 -7
  63. package/dist/es2019/root/ui/iconMessage/index.js +10 -6
  64. package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +22 -74
  65. package/dist/es2019/root/ui/loadingRateLimited/loadingRateLimited.js +1 -1
  66. package/dist/es2019/root/ui/progressBar/progressBar.js +1 -1
  67. package/dist/es2019/root/ui/progressBar/styled.js +2 -1
  68. package/dist/es2019/root/ui/styled.js +4 -64
  69. package/dist/es2019/root/ui/styledSSR.js +93 -0
  70. package/dist/es2019/root/ui/titleBox/failedTitleBox.js +5 -3
  71. package/dist/es2019/root/ui/titleBox/styled.js +2 -1
  72. package/dist/es2019/utils/analytics.js +29 -40
  73. package/dist/es2019/utils/dimensionComparer.js +1 -1
  74. package/dist/es2019/utils/document.js +1 -0
  75. package/dist/es2019/utils/getDataURIDimension.js +8 -0
  76. package/dist/es2019/utils/metadata.js +12 -4
  77. package/dist/es2019/utils/objectURLCache.js +5 -0
  78. package/dist/es2019/utils/resizeModeToMediaImageProps.js +6 -0
  79. package/dist/es2019/utils/shouldDisplayImageThumbnail.js +1 -1
  80. package/dist/es2019/utils/videoSnapshot.js +7 -0
  81. package/dist/es2019/version.json +1 -1
  82. package/dist/esm/errors.js +85 -2
  83. package/dist/esm/files/cardImageView/index.js +55 -87
  84. package/dist/esm/files/index.js +1 -1
  85. package/dist/esm/index.js +3 -3
  86. package/dist/esm/root/card/cardAnalytics.js +23 -18
  87. package/dist/esm/root/card/cardConstants.js +1 -0
  88. package/dist/esm/root/card/cardSSRView.js +92 -0
  89. package/dist/esm/root/card/cardState.js +32 -0
  90. package/dist/esm/root/card/getCardPreview/cache.js +33 -0
  91. package/dist/esm/root/card/getCardPreview/filePreviewStatus.js +35 -0
  92. package/dist/esm/root/card/getCardPreview/helpers.js +194 -0
  93. package/dist/esm/root/card/getCardPreview/index.js +174 -0
  94. package/dist/esm/root/card/getCardStatus.js +13 -17
  95. package/dist/esm/root/card/index.js +349 -401
  96. package/dist/esm/root/cardView.js +105 -52
  97. package/dist/esm/root/index.js +2 -1
  98. package/dist/esm/root/inline/loader.js +23 -22
  99. package/dist/esm/root/inline/{inlineMediaCard.js → mediaInlineCard.js} +62 -22
  100. package/dist/esm/root/inlinePlayer.js +5 -13
  101. package/dist/esm/root/ui/Breakpoint.js +6 -0
  102. package/dist/esm/root/ui/common.js +1 -7
  103. package/dist/esm/root/ui/iconMessage/index.js +12 -7
  104. package/dist/esm/root/ui/imageRenderer/imageRenderer.js +24 -106
  105. package/dist/esm/root/ui/loadingRateLimited/loadingRateLimited.js +1 -1
  106. package/dist/esm/root/ui/progressBar/progressBar.js +1 -1
  107. package/dist/esm/root/ui/progressBar/styled.js +2 -1
  108. package/dist/esm/root/ui/styled.js +13 -61
  109. package/dist/esm/root/ui/styledSSR.js +76 -0
  110. package/dist/esm/root/ui/titleBox/failedTitleBox.js +6 -3
  111. package/dist/esm/root/ui/titleBox/styled.js +2 -1
  112. package/dist/esm/utils/analytics.js +22 -35
  113. package/dist/esm/utils/dimensionComparer.js +1 -1
  114. package/dist/esm/utils/document.js +3 -0
  115. package/dist/esm/utils/getDataURIDimension.js +8 -0
  116. package/dist/esm/utils/metadata.js +12 -4
  117. package/dist/esm/utils/objectURLCache.js +6 -0
  118. package/dist/esm/utils/resizeModeToMediaImageProps.js +6 -0
  119. package/dist/esm/utils/shouldDisplayImageThumbnail.js +1 -1
  120. package/dist/esm/utils/videoSnapshot.js +31 -0
  121. package/dist/esm/version.json +1 -1
  122. package/dist/types/__tests_external__/page-objects/MediaCard.d.ts +4 -3
  123. package/dist/types/errors.d.ts +24 -2
  124. package/dist/types/files/cardImageView/index.d.ts +5 -12
  125. package/dist/types/files/cardImageView/styled.d.ts +1 -1
  126. package/dist/types/files/index.d.ts +1 -1
  127. package/dist/types/index.d.ts +9 -12
  128. package/dist/types/root/card/cardAnalytics.d.ts +5 -7
  129. package/dist/types/root/card/cardConstants.d.ts +1 -0
  130. package/dist/types/root/card/cardSSRView.d.ts +13 -0
  131. package/dist/types/root/card/cardState.d.ts +5 -0
  132. package/dist/types/root/card/getCardPreview/cache.d.ts +18 -0
  133. package/dist/types/root/card/getCardPreview/filePreviewStatus.d.ts +5 -0
  134. package/dist/types/root/card/getCardPreview/helpers.d.ts +9 -0
  135. package/dist/types/root/card/getCardPreview/index.d.ts +44 -0
  136. package/dist/types/root/card/getCardStatus.d.ts +4 -14
  137. package/dist/types/root/card/index.d.ts +17 -21
  138. package/dist/types/root/cardView.d.ts +12 -8
  139. package/dist/types/root/index.d.ts +1 -0
  140. package/dist/types/root/inline/loader.d.ts +8 -8
  141. package/dist/types/root/inline/{inlineMediaCard.d.ts → mediaInlineCard.d.ts} +4 -4
  142. package/dist/types/root/inlinePlayer.d.ts +1 -1
  143. package/dist/types/root/ui/Breakpoint.d.ts +4 -0
  144. package/dist/types/root/ui/common.d.ts +1 -4
  145. package/dist/types/root/ui/iconMessage/index.d.ts +7 -2
  146. package/dist/types/root/ui/iconWrapper/styled.d.ts +1 -1
  147. package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +2 -16
  148. package/dist/types/root/ui/loadingRateLimited/loadingRateLimited.d.ts +1 -1
  149. package/dist/types/root/ui/loadingRateLimited/styled.d.ts +1 -1
  150. package/dist/types/root/ui/progressBar/progressBar.d.ts +1 -1
  151. package/dist/types/root/ui/progressBar/styled.d.ts +1 -1
  152. package/dist/types/root/ui/styled.d.ts +3 -10
  153. package/dist/types/root/ui/styledSSR.d.ts +16 -0
  154. package/dist/types/root/ui/titleBox/failedTitleBox.d.ts +3 -1
  155. package/dist/types/root/ui/titleBox/styled.d.ts +1 -1
  156. package/dist/types/root/ui/titleBox/titleBox.d.ts +1 -1
  157. package/dist/types/types.d.ts +15 -1
  158. package/dist/types/utils/analytics.d.ts +20 -21
  159. package/dist/types/utils/cardDimensions.d.ts +5 -1
  160. package/dist/types/utils/dimensionComparer.d.ts +1 -1
  161. package/dist/types/utils/document.d.ts +2 -0
  162. package/dist/types/utils/getDataURIDimension.d.ts +3 -1
  163. package/dist/types/utils/index.d.ts +1 -0
  164. package/dist/types/utils/lazyContent/styled.d.ts +1 -1
  165. package/dist/types/utils/lightCards/types.d.ts +1 -1
  166. package/dist/types/utils/metadata.d.ts +2 -2
  167. package/dist/types/utils/objectURLCache.d.ts +2 -1
  168. package/dist/types/utils/resizeModeToMediaImageProps.d.ts +5 -0
  169. package/dist/types/utils/shouldDisplayImageThumbnail.d.ts +1 -1
  170. package/dist/types/utils/videoSnapshot.d.ts +1 -0
  171. package/example-helpers/index.tsx +21 -0
  172. package/package.json +19 -17
  173. package/dist/cjs/root/card/getCardPreview.js +0 -173
  174. package/dist/cjs/utils/fileAttributesContext.js +0 -40
  175. package/dist/es2019/root/card/getCardPreview.js +0 -86
  176. package/dist/es2019/root/inline/inlineMediaCard.js +0 -92
  177. package/dist/es2019/utils/fileAttributesContext.js +0 -19
  178. package/dist/esm/root/card/getCardPreview.js +0 -153
  179. package/dist/esm/utils/fileAttributesContext.js +0 -18
  180. package/dist/types/root/card/getCardPreview.d.ts +0 -8
  181. package/dist/types/utils/fileAttributesContext.d.ts +0 -10
@@ -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
+ };
@@ -0,0 +1,29 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { createObjectURLCache } from '../../../utils/objectURLCache';
3
+ // Dimensions are used to create a key.
4
+ // Cache is invalidated when different dimensions are provided.
5
+ export const getCacheKey = (id, dimensions) => {
6
+ return [id, dimensions.height, dimensions.width].join('-');
7
+ };
8
+ export class CardPreviewCacheImpl {
9
+ constructor(previewCache) {
10
+ _defineProperty(this, "get", (id, dimensions) => {
11
+ const cacheKey = getCacheKey(id, dimensions);
12
+ return this.previewCache.get(cacheKey);
13
+ });
14
+
15
+ _defineProperty(this, "set", (id, dimensions, cardPreview) => {
16
+ const cacheKey = getCacheKey(id, dimensions);
17
+ this.previewCache.set(cacheKey, cardPreview);
18
+ });
19
+
20
+ _defineProperty(this, "remove", (id, dimensions) => {
21
+ const cacheKey = getCacheKey(id, dimensions);
22
+ this.previewCache.remove(cacheKey);
23
+ });
24
+
25
+ this.previewCache = previewCache;
26
+ }
27
+
28
+ }
29
+ export default new CardPreviewCacheImpl(createObjectURLCache());
@@ -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
+ };
@@ -0,0 +1,83 @@
1
+ import { takeSnapshot } from '../../../utils/videoSnapshot';
2
+ import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
3
+ import { getOrientation } from '@atlaskit/media-ui';
4
+ import { LocalPreviewError, RemotePreviewError } from '../../../errors';
5
+
6
+ /**
7
+ * This method tells the support for the media
8
+ * types covered in getCardPreviewFromFilePreview
9
+ */
10
+ export const isSupportedLocalPreview = mediaType => mediaType === 'image' || mediaType === 'video';
11
+
12
+ const getImageLocalPreview = async value => {
13
+ try {
14
+ const orientation = await getOrientation(value);
15
+ const dataURI = URL.createObjectURL(value);
16
+ return {
17
+ dataURI,
18
+ orientation,
19
+ source: 'local'
20
+ };
21
+ } catch (e) {
22
+ throw new LocalPreviewError('local-preview-image', e);
23
+ }
24
+ };
25
+
26
+ const getVideoLocalPreview = async value => {
27
+ try {
28
+ const dataURI = await takeSnapshot(value);
29
+ return {
30
+ dataURI,
31
+ orientation: 1,
32
+ source: 'local'
33
+ };
34
+ } catch (e) {
35
+ throw new LocalPreviewError('local-preview-video', e);
36
+ }
37
+ };
38
+
39
+ export const getCardPreviewFromFilePreview = async filePreview => {
40
+ let value;
41
+
42
+ try {
43
+ const resolvedFilePreview = await filePreview;
44
+ value = resolvedFilePreview.value;
45
+ } catch (e) {
46
+ throw new LocalPreviewError('local-preview-rejected', e);
47
+ }
48
+
49
+ if (typeof value === 'string') {
50
+ return {
51
+ dataURI: value,
52
+ orientation: 1,
53
+ source: 'local'
54
+ };
55
+ } else if (value instanceof Blob) {
56
+ const {
57
+ type
58
+ } = value;
59
+ const mediaType = getMediaTypeFromMimeType(type);
60
+
61
+ switch (mediaType) {
62
+ case 'image':
63
+ return getImageLocalPreview(value);
64
+
65
+ case 'video':
66
+ return getVideoLocalPreview(value);
67
+ }
68
+ }
69
+
70
+ throw new LocalPreviewError('local-preview-unsupported');
71
+ };
72
+ export const getCardPreviewFromBackend = async (mediaClient, id, params) => {
73
+ try {
74
+ const blob = await mediaClient.getImage(id, params);
75
+ return {
76
+ dataURI: URL.createObjectURL(blob),
77
+ orientation: 1,
78
+ source: 'remote'
79
+ };
80
+ } catch (e) {
81
+ throw new RemotePreviewError('remote-preview-fetch', e);
82
+ }
83
+ };
@@ -0,0 +1,129 @@
1
+ import { isPreviewableFileState, addFileAttrsToUrl } from '@atlaskit/media-client';
2
+ import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
3
+ import cardPreviewCache from './cache';
4
+ import { getCardPreviewFromFilePreview, getCardPreviewFromBackend } from './helpers';
5
+ import { MediaCardError, 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';
10
+ export const getCardPreviewFromCache = cardPreviewCache.get;
11
+ export const removeCardPreviewFromCache = cardPreviewCache.remove;
12
+ /**
13
+ * Will return the preview if available and supported by the browser
14
+ * See extractFilePreviewStatus "hasLocalPreview" logic
15
+ */
16
+
17
+ export const getFilePreviewFromFileState = fileState => 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) && isPreviewableFileState(fileState) ? fileState.preview : undefined;
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
+ };
46
+ /**
47
+ * This function will try to return a Card preview, either from cache, local preview or remote preview.
48
+ * It should only be called if there is a chance to get either a remote or a local preview, or both.
49
+ * This, in order to ensure there is always going to be a valid return value OR throw an error if the process fails.
50
+ * It is worth noting that local preview failures break the process if there is no remote preview available.
51
+ * In that case we throw an error immediately.
52
+ * Otherwise, if the local preview fails but there is a remote preview available, the failure does not break the process.
53
+ * In that case, we still want to report the local preview error to the caller, for feature realiability track.
54
+ * hence the use of the optional callback onLocalPreviewError
55
+ */
56
+
57
+
58
+ export const getCardPreview = async ({
59
+ mediaClient,
60
+ id,
61
+ dimensions = {},
62
+ filePreview,
63
+ onLocalPreviewError,
64
+ isRemotePreviewReady,
65
+ imageUrlParams,
66
+ mediaBlobUrlAttrs
67
+ }) => {
68
+ const cachedPreview = cardPreviewCache.get(id, dimensions);
69
+
70
+ if (cachedPreview) {
71
+ return cachedPreview;
72
+ }
73
+
74
+ try {
75
+ if (filePreview) {
76
+ const localPreview = await getCardPreviewFromFilePreview(filePreview);
77
+ return extendAndCachePreview(id, dimensions, localPreview, mediaBlobUrlAttrs);
78
+ }
79
+ } catch (e) {
80
+ /**
81
+ * We report the error if:
82
+ * - local preview is supported and fails
83
+ * - local preview is unsupported and remote preview is NOT READY
84
+ * i.e. the function was called for "no reason".
85
+ * We DON'T report the error if:
86
+ * - local preview is unsupported and remote preview IS READY
87
+ * i.e. local preview is available and not supported,
88
+ * but we are after the remote preview instead.
89
+ */
90
+ if (!isUnsupportedLocalPreviewError(e) || isUnsupportedLocalPreviewError(e) && !isRemotePreviewReady) {
91
+ onLocalPreviewError && onLocalPreviewError(e);
92
+ }
93
+ /**
94
+ * No matter the reason why the local preview failed, we break the process
95
+ * if there is no remote preview available
96
+ */
97
+
98
+
99
+ if (!isRemotePreviewReady) {
100
+ throw e;
101
+ }
102
+ }
103
+
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');
112
+ }
113
+
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);
129
+ };
@@ -1,15 +1,8 @@
1
- import { isPreviewableType, isPreviewableFileState } from '@atlaskit/media-client';
2
- export const extractCardStatusParams = (fileState, featureFlags) => ({
3
- // TODO: align these checks with helpers from Media Client
4
- // https://product-fabric.atlassian.net/browse/BMPT-1300
5
- isPreviewableType: 'mediaType' in fileState && !!fileState.mediaType && isPreviewableType(fileState.mediaType, featureFlags),
6
- hasFilesize: 'size' in fileState && !!fileState.size,
7
- isPreviewableFileState: isPreviewableFileState(fileState)
8
- });
1
+ export const isFinalCardStatus = status => ['complete', 'error', 'failed-processing'].includes(status);
9
2
  export const getCardStatus = (fileStatus, {
10
- isPreviewableType,
11
3
  hasFilesize,
12
- isPreviewableFileState
4
+ isPreviewable,
5
+ hasPreview
13
6
  }) => {
14
7
  switch (fileStatus) {
15
8
  case 'uploading':
@@ -19,24 +12,27 @@ export const getCardStatus = (fileStatus, {
19
12
 
20
13
  case 'processing':
21
14
  // Legacy empty files logic
22
- // isPreviewableType will most likely be false for empty files,
15
+ // isPreviewable will most likely be false for empty files,
23
16
  // therefore we need to do this cut before that check.
24
17
  // TODO: https://product-fabric.atlassian.net/browse/BMPT-1247
25
18
  if (!hasFilesize) {
26
19
  return 'processing';
27
20
  } // If we show no preview for this file
28
- // we won't show the "creating preview" message
29
- // i.e. Card is "complete".
21
+ // we won't show the "creating preview" message, i.e. Card is "complete".
30
22
 
31
23
 
32
- if (!isPreviewableType || isPreviewableFileState) {
24
+ if (!isPreviewable) {
33
25
  return 'complete';
34
26
  }
35
27
 
36
28
  return 'processing';
37
29
 
38
30
  case 'processed':
39
- return 'complete';
31
+ if (!isPreviewable || !hasPreview) {
32
+ return 'complete';
33
+ }
34
+
35
+ return 'loading-preview';
40
36
 
41
37
  default:
42
38
  return 'loading';