@atlaskit/media-card 71.0.0 → 73.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 (204) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/dist/cjs/actions.js +2 -2
  3. package/dist/cjs/errors.js +83 -8
  4. package/dist/cjs/files/cardImageView/cardOverlay/styled.js +1 -1
  5. package/dist/cjs/files/cardImageView/index.js +53 -104
  6. package/dist/cjs/files/cardImageView/styled.js +1 -1
  7. package/dist/cjs/files/index.js +0 -6
  8. package/dist/cjs/index.js +8 -8
  9. package/dist/cjs/root/card/cardAnalytics.js +4 -16
  10. package/dist/cjs/root/card/cardLoader.js +66 -124
  11. package/dist/cjs/root/card/cardState.js +50 -0
  12. package/dist/cjs/root/card/getCardPreview/cache.js +10 -5
  13. package/dist/cjs/root/card/getCardPreview/filePreviewStatus.js +53 -0
  14. package/dist/cjs/root/card/getCardPreview/helpers.js +14 -22
  15. package/dist/cjs/root/card/getCardPreview/index.js +177 -97
  16. package/dist/cjs/root/card/getCardStatus.js +7 -1
  17. package/dist/cjs/root/card/index.js +384 -285
  18. package/dist/cjs/root/cardView.js +113 -88
  19. package/dist/cjs/root/inline/loader.js +47 -15
  20. package/dist/cjs/root/inline/mediaInlineCard.js +33 -12
  21. package/dist/cjs/root/inlinePlayer.js +77 -24
  22. package/dist/cjs/root/styled.js +7 -3
  23. package/dist/cjs/root/ui/actionsBar/styled.js +1 -1
  24. package/dist/cjs/root/ui/blanket/styled.js +1 -1
  25. package/dist/cjs/root/ui/common.js +11 -5
  26. package/dist/cjs/root/ui/iconMessage/index.js +16 -7
  27. package/dist/cjs/root/ui/iconWrapper/styled.js +1 -1
  28. package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +47 -123
  29. package/dist/cjs/root/ui/loadingRateLimited/loadingRateLimited.js +6 -4
  30. package/dist/cjs/root/ui/loadingRateLimited/styled.js +2 -2
  31. package/dist/cjs/root/ui/playButton/styled.js +1 -1
  32. package/dist/cjs/root/ui/progressBar/progressBar.js +7 -4
  33. package/dist/cjs/root/ui/progressBar/styled.js +8 -9
  34. package/dist/cjs/root/ui/styled.js +80 -17
  35. package/dist/cjs/root/ui/tickBox/styled.js +1 -1
  36. package/dist/cjs/root/ui/titleBox/failedTitleBox.js +9 -3
  37. package/dist/cjs/root/ui/titleBox/styled.js +2 -4
  38. package/dist/cjs/root/ui/titleBox/titleBox.js +2 -2
  39. package/dist/cjs/styles/index.js +25 -23
  40. package/dist/cjs/styles/mixins.js +1 -1
  41. package/dist/cjs/utils/analytics.js +7 -44
  42. package/dist/cjs/utils/breakpoint.js +1 -1
  43. package/dist/cjs/utils/cardActions/cardActionsDropdownMenu.js +18 -9
  44. package/dist/cjs/utils/cardActions/index.js +10 -10
  45. package/dist/cjs/utils/cardActions/styled.js +1 -1
  46. package/dist/cjs/utils/cardDimensions.js +1 -1
  47. package/dist/cjs/utils/dimensionComparer.js +1 -1
  48. package/dist/cjs/utils/getErrorMessage.js +2 -2
  49. package/dist/cjs/utils/index.js +46 -46
  50. package/dist/cjs/utils/lightCards/styled.js +1 -1
  51. package/dist/cjs/utils/metadata.js +11 -3
  52. package/dist/cjs/utils/objectURLCache.js +7 -1
  53. package/dist/cjs/utils/shouldDisplayImageThumbnail.js +1 -1
  54. package/dist/cjs/utils/viewportDetector.js +49 -22
  55. package/dist/cjs/version.json +1 -1
  56. package/dist/es2019/errors.js +42 -2
  57. package/dist/es2019/files/cardImageView/index.js +8 -61
  58. package/dist/es2019/files/index.js +1 -1
  59. package/dist/es2019/root/card/cardAnalytics.js +3 -14
  60. package/dist/es2019/root/card/cardLoader.js +47 -53
  61. package/dist/es2019/root/card/cardState.js +26 -0
  62. package/dist/es2019/root/card/getCardPreview/cache.js +5 -0
  63. package/dist/es2019/root/card/getCardPreview/filePreviewStatus.js +38 -0
  64. package/dist/es2019/root/card/getCardPreview/helpers.js +2 -12
  65. package/dist/es2019/root/card/getCardPreview/index.js +112 -73
  66. package/dist/es2019/root/card/getCardStatus.js +1 -0
  67. package/dist/es2019/root/card/index.js +308 -190
  68. package/dist/es2019/root/cardView.js +97 -68
  69. package/dist/es2019/root/inline/loader.js +17 -5
  70. package/dist/es2019/root/inline/mediaInlineCard.js +32 -11
  71. package/dist/es2019/root/inlinePlayer.js +56 -4
  72. package/dist/es2019/root/styled.js +2 -1
  73. package/dist/es2019/root/ui/common.js +7 -1
  74. package/dist/es2019/root/ui/iconMessage/index.js +8 -5
  75. package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +35 -88
  76. package/dist/es2019/root/ui/loadingRateLimited/loadingRateLimited.js +4 -3
  77. package/dist/es2019/root/ui/loadingRateLimited/styled.js +1 -1
  78. package/dist/es2019/root/ui/progressBar/progressBar.js +5 -3
  79. package/dist/es2019/root/ui/progressBar/styled.js +7 -6
  80. package/dist/es2019/root/ui/styled.js +65 -4
  81. package/dist/es2019/root/ui/titleBox/failedTitleBox.js +6 -3
  82. package/dist/es2019/root/ui/titleBox/styled.js +1 -2
  83. package/dist/es2019/root/ui/titleBox/titleBox.js +1 -1
  84. package/dist/es2019/utils/analytics.js +5 -34
  85. package/dist/es2019/utils/cardActions/cardActionsDropdownMenu.js +8 -4
  86. package/dist/es2019/utils/dimensionComparer.js +1 -1
  87. package/dist/es2019/utils/getErrorMessage.js +1 -1
  88. package/dist/es2019/utils/metadata.js +12 -4
  89. package/dist/es2019/utils/objectURLCache.js +5 -0
  90. package/dist/es2019/utils/shouldDisplayImageThumbnail.js +1 -1
  91. package/dist/es2019/utils/viewportDetector.js +48 -18
  92. package/dist/es2019/version.json +1 -1
  93. package/dist/esm/actions.js +2 -2
  94. package/dist/esm/errors.js +64 -4
  95. package/dist/esm/files/cardImageView/index.js +51 -102
  96. package/dist/esm/files/index.js +1 -1
  97. package/dist/esm/root/card/cardAnalytics.js +3 -15
  98. package/dist/esm/root/card/cardLoader.js +66 -126
  99. package/dist/esm/root/card/cardState.js +32 -0
  100. package/dist/esm/root/card/getCardPreview/cache.js +9 -2
  101. package/dist/esm/root/card/getCardPreview/filePreviewStatus.js +38 -0
  102. package/dist/esm/root/card/getCardPreview/helpers.js +13 -21
  103. package/dist/esm/root/card/getCardPreview/index.js +144 -91
  104. package/dist/esm/root/card/getCardStatus.js +3 -0
  105. package/dist/esm/root/card/index.js +396 -288
  106. package/dist/esm/root/cardView.js +113 -86
  107. package/dist/esm/root/inline/loader.js +48 -15
  108. package/dist/esm/root/inline/mediaInlineCard.js +32 -11
  109. package/dist/esm/root/inlinePlayer.js +74 -23
  110. package/dist/esm/root/styled.js +3 -2
  111. package/dist/esm/root/ui/common.js +7 -1
  112. package/dist/esm/root/ui/iconMessage/index.js +10 -5
  113. package/dist/esm/root/ui/imageRenderer/imageRenderer.js +37 -116
  114. package/dist/esm/root/ui/loadingRateLimited/loadingRateLimited.js +4 -3
  115. package/dist/esm/root/ui/loadingRateLimited/styled.js +1 -1
  116. package/dist/esm/root/ui/progressBar/progressBar.js +6 -3
  117. package/dist/esm/root/ui/progressBar/styled.js +7 -7
  118. package/dist/esm/root/ui/styled.js +61 -13
  119. package/dist/esm/root/ui/titleBox/failedTitleBox.js +7 -3
  120. package/dist/esm/root/ui/titleBox/styled.js +1 -2
  121. package/dist/esm/root/ui/titleBox/titleBox.js +1 -1
  122. package/dist/esm/utils/analytics.js +5 -36
  123. package/dist/esm/utils/cardActions/cardActionsDropdownMenu.js +17 -9
  124. package/dist/esm/utils/dimensionComparer.js +1 -1
  125. package/dist/esm/utils/getErrorMessage.js +1 -1
  126. package/dist/esm/utils/metadata.js +12 -4
  127. package/dist/esm/utils/objectURLCache.js +6 -0
  128. package/dist/esm/utils/shouldDisplayImageThumbnail.js +1 -1
  129. package/dist/esm/utils/viewportDetector.js +48 -21
  130. package/dist/esm/version.json +1 -1
  131. package/dist/types/errors.d.ts +15 -1
  132. package/dist/types/files/cardImageView/index.d.ts +4 -13
  133. package/dist/types/files/cardImageView/styled.d.ts +1 -1
  134. package/dist/types/files/index.d.ts +1 -1
  135. package/dist/types/index.d.ts +7 -4
  136. package/dist/types/root/card/cardAnalytics.d.ts +1 -6
  137. package/dist/types/root/card/cardLoader.d.ts +5 -19
  138. package/dist/types/root/card/cardState.d.ts +5 -0
  139. package/dist/types/root/card/getCardPreview/cache.d.ts +3 -1
  140. package/dist/types/root/card/getCardPreview/filePreviewStatus.d.ts +5 -0
  141. package/dist/types/root/card/getCardPreview/helpers.d.ts +3 -4
  142. package/dist/types/root/card/getCardPreview/index.d.ts +24 -14
  143. package/dist/types/root/card/getCardStatus.d.ts +1 -0
  144. package/dist/types/root/card/index.d.ts +20 -18
  145. package/dist/types/root/cardView.d.ts +13 -8
  146. package/dist/types/root/inline/loader.d.ts +2 -0
  147. package/dist/types/root/inline/mediaInlineCard.d.ts +3 -5
  148. package/dist/types/root/inlinePlayer.d.ts +8 -1
  149. package/dist/types/root/styled.d.ts +1 -0
  150. package/dist/types/root/ui/common.d.ts +4 -1
  151. package/dist/types/root/ui/iconMessage/index.d.ts +4 -3
  152. package/dist/types/root/ui/iconWrapper/styled.d.ts +1 -1
  153. package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +14 -15
  154. package/dist/types/root/ui/loadingRateLimited/loadingRateLimited.d.ts +2 -1
  155. package/dist/types/root/ui/loadingRateLimited/styled.d.ts +1 -1
  156. package/dist/types/root/ui/playButton/playButton.d.ts +1 -0
  157. package/dist/types/root/ui/progressBar/progressBar.d.ts +4 -2
  158. package/dist/types/root/ui/progressBar/styled.d.ts +3 -2
  159. package/dist/types/root/ui/styled.d.ts +10 -3
  160. package/dist/types/root/ui/tickBox/tickBox.d.ts +1 -0
  161. package/dist/types/root/ui/titleBox/failedTitleBox.d.ts +3 -1
  162. package/dist/types/root/ui/titleBox/styled.d.ts +1 -1
  163. package/dist/types/root/ui/titleBox/titleBox.d.ts +2 -10
  164. package/dist/types/styles/mixins.d.ts +1 -1
  165. package/dist/types/types.d.ts +7 -1
  166. package/dist/types/utils/analytics.d.ts +6 -15
  167. package/dist/types/utils/cardDimensions.d.ts +4 -4
  168. package/dist/types/utils/dimensionComparer.d.ts +1 -1
  169. package/dist/types/utils/getErrorMessage.d.ts +1 -0
  170. package/dist/types/utils/metadata.d.ts +2 -2
  171. package/dist/types/utils/objectURLCache.d.ts +2 -1
  172. package/dist/types/utils/viewportDetector.d.ts +13 -5
  173. package/example-helpers/developmentUseMessage.tsx +14 -0
  174. package/example-helpers/index.tsx +55 -4
  175. package/example-helpers/selectableCard.tsx +2 -1
  176. package/package.json +18 -16
  177. package/dist/cjs/root/card/cardSSRView.js +0 -112
  178. package/dist/cjs/root/card/getCardPreview/types.js +0 -5
  179. package/dist/cjs/root/ui/Breakpoint.js +0 -13
  180. package/dist/cjs/root/ui/styledSSR.js +0 -108
  181. package/dist/cjs/utils/fileAttributesContext.js +0 -40
  182. package/dist/cjs/utils/lazyContent/index.js +0 -56
  183. package/dist/cjs/utils/lazyContent/styled.js +0 -23
  184. package/dist/es2019/root/card/cardSSRView.js +0 -92
  185. package/dist/es2019/root/card/getCardPreview/types.js +0 -1
  186. package/dist/es2019/root/ui/Breakpoint.js +0 -6
  187. package/dist/es2019/root/ui/styledSSR.js +0 -93
  188. package/dist/es2019/utils/fileAttributesContext.js +0 -19
  189. package/dist/es2019/utils/lazyContent/index.js +0 -18
  190. package/dist/es2019/utils/lazyContent/styled.js +0 -12
  191. package/dist/esm/root/card/cardSSRView.js +0 -91
  192. package/dist/esm/root/card/getCardPreview/types.js +0 -1
  193. package/dist/esm/root/ui/Breakpoint.js +0 -6
  194. package/dist/esm/root/ui/styledSSR.js +0 -76
  195. package/dist/esm/utils/fileAttributesContext.js +0 -18
  196. package/dist/esm/utils/lazyContent/index.js +0 -41
  197. package/dist/esm/utils/lazyContent/styled.js +0 -14
  198. package/dist/types/root/card/cardSSRView.d.ts +0 -13
  199. package/dist/types/root/card/getCardPreview/types.d.ts +0 -5
  200. package/dist/types/root/ui/Breakpoint.d.ts +0 -4
  201. package/dist/types/root/ui/styledSSR.d.ts +0 -16
  202. package/dist/types/utils/fileAttributesContext.d.ts +0 -10
  203. package/dist/types/utils/lazyContent/index.d.ts +0 -11
  204. package/dist/types/utils/lazyContent/styled.d.ts +0 -5
@@ -1,8 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
 
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
4
 
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
6
 
7
7
  export function attachDetailsToActions(actions, details) {
8
8
  return actions.map(function (action) {
@@ -1,3 +1,4 @@
1
+ import _createClass from "@babel/runtime/helpers/createClass";
1
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
3
  import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
3
4
  import _inherits from "@babel/runtime/helpers/inherits";
@@ -32,7 +33,7 @@ export var MediaCardError = /*#__PURE__*/function (_Error) {
32
33
  return _this;
33
34
  }
34
35
 
35
- return MediaCardError;
36
+ return _createClass(MediaCardError);
36
37
  }( /*#__PURE__*/_wrapNativeSuper(Error));
37
38
  export var LocalPreviewError = /*#__PURE__*/function (_MediaCardError) {
38
39
  _inherits(LocalPreviewError, _MediaCardError);
@@ -50,7 +51,7 @@ export var LocalPreviewError = /*#__PURE__*/function (_MediaCardError) {
50
51
  return _this2;
51
52
  }
52
53
 
53
- return LocalPreviewError;
54
+ return _createClass(LocalPreviewError);
54
55
  }(MediaCardError);
55
56
  export var RemotePreviewError = /*#__PURE__*/function (_MediaCardError2) {
56
57
  _inherits(RemotePreviewError, _MediaCardError2);
@@ -68,7 +69,60 @@ export var RemotePreviewError = /*#__PURE__*/function (_MediaCardError2) {
68
69
  return _this3;
69
70
  }
70
71
 
71
- return RemotePreviewError;
72
+ return _createClass(RemotePreviewError);
73
+ }(MediaCardError);
74
+ export var SsrPreviewError = /*#__PURE__*/function (_MediaCardError3) {
75
+ _inherits(SsrPreviewError, _MediaCardError3);
76
+
77
+ var _super4 = _createSuper(SsrPreviewError);
78
+
79
+ function SsrPreviewError(primaryReason, secondaryError) {
80
+ var _this4;
81
+
82
+ _classCallCheck(this, SsrPreviewError);
83
+
84
+ _this4 = _super4.call(this, primaryReason, secondaryError);
85
+ _this4.primaryReason = primaryReason;
86
+ _this4.secondaryError = secondaryError;
87
+ return _this4;
88
+ }
89
+
90
+ return _createClass(SsrPreviewError);
91
+ }(MediaCardError);
92
+ export var getImageLoadPrimaryReason = function getImageLoadPrimaryReason(source) {
93
+ switch (source) {
94
+ case 'cache-remote':
95
+ return 'cache-remote-uri';
96
+
97
+ case 'cache-local':
98
+ return 'cache-local-uri';
99
+
100
+ case 'external':
101
+ return 'external-uri';
102
+
103
+ case 'local':
104
+ return 'local-uri';
105
+
106
+ case 'remote':
107
+ return 'remote-uri';
108
+ // This fail reason will come from a bug, most likely.
109
+
110
+ default:
111
+ return "unknown-uri";
112
+ }
113
+ };
114
+ export var ImageLoadError = /*#__PURE__*/function (_MediaCardError4) {
115
+ _inherits(ImageLoadError, _MediaCardError4);
116
+
117
+ var _super5 = _createSuper(ImageLoadError);
118
+
119
+ function ImageLoadError(source) {
120
+ _classCallCheck(this, ImageLoadError);
121
+
122
+ return _super5.call(this, getImageLoadPrimaryReason(source));
123
+ }
124
+
125
+ return _createClass(ImageLoadError);
72
126
  }(MediaCardError);
73
127
  export function isMediaCardError(err) {
74
128
  return err instanceof MediaCardError;
@@ -81,9 +135,15 @@ export var isRemotePreviewError = function isRemotePreviewError(err) {
81
135
  };
82
136
  export var isUnsupportedLocalPreviewError = function isUnsupportedLocalPreviewError(err) {
83
137
  return isMediaCardError(err) && err.primaryReason === 'local-preview-unsupported';
84
- }; // In a try/catch statement, the error caught is the type of any.
138
+ };
139
+ export function isImageLoadError(err) {
140
+ return err instanceof ImageLoadError;
141
+ } // In a try/catch statement, the error caught is the type of any.
85
142
  // We can use this helper to ensure that the error handled is the type of MediaCardError if unsure
86
143
 
87
144
  export var ensureMediaCardError = function ensureMediaCardError(primaryReason, error) {
88
145
  return isMediaCardError(error) ? error : new MediaCardError(primaryReason, error);
146
+ };
147
+ export var isUploadError = function isUploadError(error) {
148
+ return error && error.primaryReason === 'upload';
89
149
  };
@@ -20,20 +20,17 @@ import { CardLoading } from '../../utils/lightCards/cardLoading';
20
20
  import { shouldDisplayImageThumbnail } from '../../utils/shouldDisplayImageThumbnail';
21
21
  import { ProgressBar } from '../../utils/progressBar';
22
22
  import CardActions from '../../utils/cardActions';
23
- import { withAnalyticsEvents } from '@atlaskit/analytics-next';
24
- import { fireMediaCardEvent, RenderEventAction, getRenderSucceededEventPayload, getRenderFailedFileUriPayload, getRenderFailedExternalUriPayload } from '../../utils/analytics';
25
- import { withFileAttributes } from '../../utils/fileAttributesContext';
26
23
  export var fileCardImageViewSelector = 'media-file-card-view';
27
24
  export var fileCardImageViewSelectedSelector = 'media-file-card-view-selected';
28
- export var FileCardImageViewBase = /*#__PURE__*/function (_Component) {
29
- _inherits(FileCardImageViewBase, _Component);
25
+ export var FileCardImageView = /*#__PURE__*/function (_Component) {
26
+ _inherits(FileCardImageView, _Component);
30
27
 
31
- var _super = _createSuper(FileCardImageViewBase);
28
+ var _super = _createSuper(FileCardImageView);
32
29
 
33
- function FileCardImageViewBase() {
30
+ function FileCardImageView() {
34
31
  var _this;
35
32
 
36
- _classCallCheck(this, FileCardImageViewBase);
33
+ _classCallCheck(this, FileCardImageView);
37
34
 
38
35
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
39
36
  args[_key] = arguments[_key];
@@ -159,60 +156,18 @@ export var FileCardImageViewBase = /*#__PURE__*/function (_Component) {
159
156
  })));
160
157
  });
161
158
 
162
- _defineProperty(_assertThisInitialized(_this), "onImageLoad", function () {
163
- var _this$props6 = _this.props,
164
- createAnalyticsEvent = _this$props6.createAnalyticsEvent,
165
- fileAttributes = _this$props6.fileAttributes,
166
- timeElapsedTillCommenced = _this$props6.timeElapsedTillCommenced;
167
-
168
- if (fileAttributes && _this.shouldFireEvent(RenderEventAction.SUCCEEDED)) {
169
- var timeElapsedTillSucceeded = performance.now();
170
- var durationSinceCommenced = timeElapsedTillCommenced && timeElapsedTillSucceeded - timeElapsedTillCommenced;
171
- var performanceAttributes = {
172
- overall: {
173
- durationSincePageStart: timeElapsedTillSucceeded,
174
- durationSinceCommenced: durationSinceCommenced
175
- }
176
- };
177
- fireMediaCardEvent(getRenderSucceededEventPayload(fileAttributes, performanceAttributes), createAnalyticsEvent);
178
- }
179
- });
180
-
181
- _defineProperty(_assertThisInitialized(_this), "onImageError", function () {
182
- var fileAttributes = _this.props.fileAttributes;
183
-
184
- if (fileAttributes && _this.shouldFireEvent(RenderEventAction.FAILED)) {
185
- var _this$props7 = _this.props,
186
- createAnalyticsEvent = _this$props7.createAnalyticsEvent,
187
- mediaItemType = _this$props7.mediaItemType,
188
- timeElapsedTillCommenced = _this$props7.timeElapsedTillCommenced;
189
- var timeElapsedTillFailed = performance.now();
190
- var durationSinceCommenced = timeElapsedTillCommenced && timeElapsedTillFailed - timeElapsedTillCommenced;
191
- var performanceAttributes = {
192
- overall: {
193
- durationSincePageStart: timeElapsedTillFailed,
194
- durationSinceCommenced: durationSinceCommenced
195
- }
196
- };
197
-
198
- if (mediaItemType === 'file') {
199
- fireMediaCardEvent(getRenderFailedFileUriPayload(fileAttributes, performanceAttributes), createAnalyticsEvent);
200
- } else if (mediaItemType === 'external-image') {
201
- fireMediaCardEvent(getRenderFailedExternalUriPayload(fileAttributes, performanceAttributes), createAnalyticsEvent);
202
- }
203
- }
204
- });
205
-
206
159
  _defineProperty(_assertThisInitialized(_this), "renderMediaImage", function () {
207
- var _this$props8 = _this.props,
208
- status = _this$props8.status,
209
- mediaItemType = _this$props8.mediaItemType,
210
- dataURI = _this$props8.dataURI,
211
- mediaType = _this$props8.mediaType,
212
- mimeType = _this$props8.mimeType,
213
- previewOrientation = _this$props8.previewOrientation,
214
- onDisplayImage = _this$props8.onDisplayImage,
215
- alt = _this$props8.alt;
160
+ var _this$props6 = _this.props,
161
+ status = _this$props6.status,
162
+ mediaItemType = _this$props6.mediaItemType,
163
+ dataURI = _this$props6.dataURI,
164
+ mediaType = _this$props6.mediaType,
165
+ mimeType = _this$props6.mimeType,
166
+ previewOrientation = _this$props6.previewOrientation,
167
+ onDisplayImage = _this$props6.onDisplayImage,
168
+ alt = _this$props6.alt,
169
+ onImageLoad = _this$props6.onImageLoad,
170
+ onImageError = _this$props6.onImageError;
216
171
 
217
172
  if (!shouldDisplayImageThumbnail(status, mediaItemType, dataURI, mediaType, mimeType)) {
218
173
  return null;
@@ -229,21 +184,17 @@ export var FileCardImageViewBase = /*#__PURE__*/function (_Component) {
229
184
  crop: _this.isCropped,
230
185
  stretch: _this.isStretched,
231
186
  previewOrientation: previewOrientation,
232
- onImageLoad: _this.onImageLoad,
233
- onImageError: _this.onImageError
187
+ onImageLoad: onImageLoad,
188
+ onImageError: onImageError
234
189
  });
235
190
  });
236
191
 
237
- _defineProperty(_assertThisInitialized(_this), "shouldFireEvent", function (action) {
238
- return !_this.lastAnalyticsAction || _this.lastAnalyticsAction !== action;
239
- });
240
-
241
192
  _defineProperty(_assertThisInitialized(_this), "renderProgressBar", function () {
242
- var _this$props9 = _this.props,
243
- mediaName = _this$props9.mediaName,
244
- progress = _this$props9.progress,
245
- actions = _this$props9.actions,
246
- status = _this$props9.status;
193
+ var _this$props7 = _this.props,
194
+ mediaName = _this$props7.mediaName,
195
+ progress = _this$props7.progress,
196
+ actions = _this$props7.actions,
197
+ status = _this$props7.status;
247
198
 
248
199
  if (status !== 'uploading') {
249
200
  return null;
@@ -262,10 +213,10 @@ export var FileCardImageViewBase = /*#__PURE__*/function (_Component) {
262
213
  });
263
214
 
264
215
  _defineProperty(_assertThisInitialized(_this), "renderSuccessCardContents", function () {
265
- var _this$props10 = _this.props,
266
- disableOverlay = _this$props10.disableOverlay,
267
- selectable = _this$props10.selectable,
268
- status = _this$props10.status;
216
+ var _this$props8 = _this.props,
217
+ disableOverlay = _this$props8.disableOverlay,
218
+ selectable = _this$props8.selectable,
219
+ status = _this$props8.status;
269
220
  var overlay = null;
270
221
 
271
222
  if (!disableOverlay) {
@@ -286,15 +237,15 @@ export var FileCardImageViewBase = /*#__PURE__*/function (_Component) {
286
237
  });
287
238
 
288
239
  _defineProperty(_assertThisInitialized(_this), "renderSuccessCardOverlay", function () {
289
- var _this$props11 = _this.props,
290
- status = _this$props11.status,
291
- mediaName = _this$props11.mediaName,
292
- mediaType = _this$props11.mediaType,
293
- fileSize = _this$props11.fileSize,
294
- dataURI = _this$props11.dataURI,
295
- selectable = _this$props11.selectable,
296
- selected = _this$props11.selected,
297
- actions = _this$props11.actions;
240
+ var _this$props9 = _this.props,
241
+ status = _this$props9.status,
242
+ mediaName = _this$props9.mediaName,
243
+ mediaType = _this$props9.mediaType,
244
+ fileSize = _this$props9.fileSize,
245
+ dataURI = _this$props9.dataURI,
246
+ selectable = _this$props9.selectable,
247
+ selected = _this$props9.selected,
248
+ actions = _this$props9.actions;
298
249
  var isPersistent = mediaType === 'doc' || !dataURI;
299
250
  return /*#__PURE__*/React.createElement(CardOverlay, {
300
251
  cardStatus: status,
@@ -311,17 +262,17 @@ export var FileCardImageViewBase = /*#__PURE__*/function (_Component) {
311
262
  return _this;
312
263
  }
313
264
 
314
- _createClass(FileCardImageViewBase, [{
265
+ _createClass(FileCardImageView, [{
315
266
  key: "render",
316
267
  value: function render() {
317
- var _this$props12 = this.props,
318
- disableOverlay = _this$props12.disableOverlay,
319
- selectable = _this$props12.selectable,
320
- selected = _this$props12.selected,
321
- mediaType = _this$props12.mediaType,
322
- progress = _this$props12.progress,
323
- status = _this$props12.status,
324
- mediaName = _this$props12.mediaName;
268
+ var _this$props10 = this.props,
269
+ disableOverlay = _this$props10.disableOverlay,
270
+ selectable = _this$props10.selectable,
271
+ selected = _this$props10.selected,
272
+ mediaType = _this$props10.mediaType,
273
+ progress = _this$props10.progress,
274
+ status = _this$props10.status,
275
+ mediaName = _this$props10.mediaName;
325
276
  return /*#__PURE__*/React.createElement(Wrapper, {
326
277
  "data-testid": "media-file-card-view",
327
278
  "data-test-media-name": mediaName,
@@ -338,9 +289,9 @@ export var FileCardImageViewBase = /*#__PURE__*/function (_Component) {
338
289
  }, {
339
290
  key: "isFileCardImageReadyForDisplay",
340
291
  get: function get() {
341
- var _this$props13 = this.props,
342
- dataURI = _this$props13.dataURI,
343
- status = _this$props13.status;
292
+ var _this$props11 = this.props,
293
+ dataURI = _this$props11.dataURI,
294
+ status = _this$props11.status;
344
295
  return !!dataURI || !['loading', 'processing', 'loading-preview'].includes(status);
345
296
  }
346
297
  }, {
@@ -357,12 +308,10 @@ export var FileCardImageViewBase = /*#__PURE__*/function (_Component) {
357
308
  }
358
309
  }]);
359
310
 
360
- return FileCardImageViewBase;
311
+ return FileCardImageView;
361
312
  }(Component);
362
313
 
363
- _defineProperty(FileCardImageViewBase, "defaultProps", {
314
+ _defineProperty(FileCardImageView, "defaultProps", {
364
315
  resizeMode: 'crop',
365
316
  disableOverlay: false
366
- });
367
-
368
- export var FileCardImageView = withAnalyticsEvents()(withFileAttributes(FileCardImageViewBase));
317
+ });
@@ -1 +1 @@
1
- export { FileCardImageView, FileCardImageViewBase } from './cardImageView';
1
+ export { FileCardImageView } from './cardImageView';
@@ -1,25 +1,13 @@
1
1
  import { fireMediaCardEvent, getRenderSucceededEventPayload, getRenderErrorEventPayload, getRenderFailedFileStatusPayload, getCopiedFilePayload, getRenderCommencedEventPayload, getRenderPreviewableCardPayload } from '../../utils/analytics';
2
- export var relevantFeatureFlagNames = ['newCardExperience', 'poll_intervalMs', 'poll_maxAttempts', 'poll_backoffFactor', 'poll_maxIntervalMs', 'captions'];
3
- export var fireOperationalEvent = function fireOperationalEvent(createAnalyticsEvent, status, fileAttributes, performanceAttributes) {
4
- var _ref = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
5
- cardPreview = _ref.cardPreview,
6
- error = _ref.error;
7
-
2
+ export var relevantFeatureFlagNames = ['newCardExperience', 'captions', 'timestampOnVideo'];
3
+ export var fireOperationalEvent = function fireOperationalEvent(createAnalyticsEvent, status, fileAttributes, performanceAttributes, error) {
8
4
  var fireEvent = function fireEvent(payload) {
9
5
  return fireMediaCardEvent(payload, createAnalyticsEvent);
10
6
  };
11
7
 
12
8
  switch (status) {
13
9
  case 'complete':
14
- /**
15
- * A Card that is considered Complete and has no preview,
16
- * reflects an expected behaviour, and thus a legitimate
17
- * success case to be logged.
18
- */
19
- if (!(cardPreview !== null && cardPreview !== void 0 && cardPreview.dataURI)) {
20
- fireEvent(getRenderSucceededEventPayload(fileAttributes, performanceAttributes));
21
- }
22
-
10
+ fireEvent(getRenderSucceededEventPayload(fileAttributes, performanceAttributes));
23
11
  break;
24
12
 
25
13
  case 'failed-processing':
@@ -1,129 +1,69 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5
- import _createClass from "@babel/runtime/helpers/createClass";
6
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
7
- import _inherits from "@babel/runtime/helpers/inherits";
8
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
9
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
10
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
11
-
12
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13
-
14
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
-
16
- import React from 'react';
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React, { useContext } from 'react';
3
+ import { useMemoizeFeatureFlags } from '@atlaskit/media-common';
4
+ import Loadable from 'react-loadable';
17
5
  import { CardLoading } from '../..';
18
-
19
- var CardLoader = /*#__PURE__*/function (_React$PureComponent) {
20
- _inherits(CardLoader, _React$PureComponent);
21
-
22
- var _super = _createSuper(CardLoader);
23
-
24
- function CardLoader() {
25
- var _this;
26
-
27
- _classCallCheck(this, CardLoader);
28
-
29
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
30
- args[_key] = arguments[_key];
31
- }
32
-
33
- _this = _super.call.apply(_super, [this].concat(args));
34
-
35
- _defineProperty(_assertThisInitialized(_this), "state", {
36
- Card: CardLoader.Card,
37
- MediaCardErrorBoundary: CardLoader.MediaCardErrorBoundary
6
+ var MediaCardContext = /*#__PURE__*/React.createContext({});
7
+
8
+ var CardLoadingWithContext = function CardLoadingWithContext() {
9
+ var props = useContext(MediaCardContext);
10
+ return /*#__PURE__*/React.createElement(CardLoading, props);
11
+ };
12
+
13
+ var MediaCard = Loadable({
14
+ loader: function loader() {
15
+ return import(
16
+ /* webpackChunkName: "@atlaskit-internal_media-card" */
17
+ './index').then(function (mod) {
18
+ return mod.Card;
38
19
  });
39
-
40
- return _this;
20
+ },
21
+ loading: function loading() {
22
+ return /*#__PURE__*/React.createElement(CardLoadingWithContext, null);
41
23
  }
42
-
43
- _createClass(CardLoader, [{
44
- key: "componentDidMount",
45
- value: function () {
46
- var _componentDidMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
47
- var _yield$Promise$all, _yield$Promise$all2, mediaClient, cardModule, mediaCardErrorBoundaryModule;
48
-
49
- return _regeneratorRuntime.wrap(function _callee$(_context) {
50
- while (1) {
51
- switch (_context.prev = _context.next) {
52
- case 0:
53
- if (this.state.Card) {
54
- _context.next = 16;
55
- break;
56
- }
57
-
58
- _context.prev = 1;
59
- _context.next = 4;
60
- return Promise.all([import(
61
- /* webpackChunkName: "@atlaskit-internal_media-client" */
62
- '@atlaskit/media-client'), import(
63
- /* webpackChunkName: "@atlaskit-internal_media-card" */
64
- './index'), import(
65
- /* webpackChunkName: "@atlaskit-internal_media-card-error-boundary" */
66
- '../media-card-analytics-error-boundary')]);
67
-
68
- case 4:
69
- _yield$Promise$all = _context.sent;
70
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
71
- mediaClient = _yield$Promise$all2[0];
72
- cardModule = _yield$Promise$all2[1];
73
- mediaCardErrorBoundaryModule = _yield$Promise$all2[2];
74
- CardLoader.Card = mediaClient.withMediaClient(cardModule.Card, this.props.featureFlags);
75
- CardLoader.MediaCardErrorBoundary = mediaCardErrorBoundaryModule.default;
76
- this.setState({
77
- Card: CardLoader.Card,
78
- MediaCardErrorBoundary: CardLoader.MediaCardErrorBoundary
79
- });
80
- _context.next = 16;
81
- break;
82
-
83
- case 14:
84
- _context.prev = 14;
85
- _context.t0 = _context["catch"](1);
86
-
87
- case 16:
88
- case "end":
89
- return _context.stop();
90
- }
91
- }
92
- }, _callee, this, [[1, 14]]);
93
- }));
94
-
95
- function componentDidMount() {
96
- return _componentDidMount.apply(this, arguments);
97
- }
98
-
99
- return componentDidMount;
100
- }()
101
- }, {
102
- key: "render",
103
- value: function render() {
104
- var _this$props = this.props,
105
- dimensions = _this$props.dimensions,
106
- testId = _this$props.testId,
107
- featureFlags = _this$props.featureFlags;
108
- var _this$state = this.state,
109
- Card = _this$state.Card,
110
- MediaCardErrorBoundary = _this$state.MediaCardErrorBoundary;
111
-
112
- if (!Card || !MediaCardErrorBoundary) {
113
- return /*#__PURE__*/React.createElement(CardLoading, {
114
- testId: testId,
115
- dimensions: dimensions,
116
- featureFlags: featureFlags
117
- });
118
- }
119
-
120
- return /*#__PURE__*/React.createElement(MediaCardErrorBoundary, null, /*#__PURE__*/React.createElement(Card, this.props));
121
- }
122
- }]);
123
-
124
- return CardLoader;
125
- }(React.PureComponent);
126
-
127
- _defineProperty(CardLoader, "displayName", 'AsyncCard');
128
-
129
- export { CardLoader as default };
24
+ });
25
+ var MediaCardErrorBoundary = Loadable({
26
+ loader: function loader() {
27
+ return import(
28
+ /* webpackChunkName: "@atlaskit-internal_media-card-error-boundary" */
29
+ '../media-card-analytics-error-boundary').then(function (mod) {
30
+ return mod.default;
31
+ });
32
+ },
33
+ loading: function loading() {
34
+ return /*#__PURE__*/React.createElement(CardLoadingWithContext, null);
35
+ }
36
+ });
37
+ var MediaCardWithMediaClient = Loadable({
38
+ loader: function loader() {
39
+ return import(
40
+ /* webpackChunkName: "@atlaskit-internal_media-client" */
41
+ '@atlaskit/media-client');
42
+ },
43
+ loading: function loading() {
44
+ return /*#__PURE__*/React.createElement(CardLoadingWithContext, null);
45
+ },
46
+ render: function render(loaded, props) {
47
+ return /*#__PURE__*/React.createElement(CardWithMediaClient, _extends({}, props, {
48
+ withMediaClient: loaded.withMediaClient
49
+ }));
50
+ }
51
+ });
52
+
53
+ var CardWithMediaClient = function CardWithMediaClient(props) {
54
+ var withMediaClient = props.withMediaClient,
55
+ featureFlags = props.featureFlags;
56
+ var memoizedFeatureFlags = useMemoizeFeatureFlags(featureFlags);
57
+ var Card = React.useMemo(function () {
58
+ return withMediaClient(MediaCard, memoizedFeatureFlags);
59
+ }, [withMediaClient, memoizedFeatureFlags]);
60
+ return /*#__PURE__*/React.createElement(MediaCardErrorBoundary, null, /*#__PURE__*/React.createElement(Card, props));
61
+ };
62
+
63
+ var CardLoader = function CardLoader(props) {
64
+ return /*#__PURE__*/React.createElement(MediaCardContext.Provider, {
65
+ value: props
66
+ }, /*#__PURE__*/React.createElement(MediaCardWithMediaClient, props));
67
+ };
68
+
69
+ export default CardLoader;
@@ -0,0 +1,32 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+
7
+ import { isErrorFileState } from '@atlaskit/media-client';
8
+ import { MediaCardError } from '../../errors';
9
+ import { getCardStatus, isFinalCardStatus } from './getCardStatus';
10
+ import { extractFilePreviewStatus } from './getCardPreview';
11
+ export var createStateUpdater = function createStateUpdater(newState) {
12
+ return function (prevState) {
13
+ // Only override if previous status is non-final
14
+ // or new status is 'complete'
15
+ if (isFinalCardStatus(prevState.status) && newState.status !== 'complete') {
16
+ return prevState;
17
+ }
18
+
19
+ return _objectSpread(_objectSpread({}, prevState), newState);
20
+ };
21
+ };
22
+ export var getCardStateFromFileState = function getCardStateFromFileState(fileState, isBannedLocalPreview, featureFlags) {
23
+ var status = getCardStatus(fileState.status, extractFilePreviewStatus(fileState, isBannedLocalPreview, featureFlags));
24
+ var error = status === 'error' && isErrorFileState(fileState) ? new MediaCardError('error-file-state', new Error(fileState.message)) : undefined;
25
+ var progress = status === 'uploading' && fileState.status === 'uploading' ? fileState.progress : 1;
26
+ return {
27
+ fileState: fileState,
28
+ status: status,
29
+ progress: progress,
30
+ error: error
31
+ };
32
+ };
@@ -1,3 +1,4 @@
1
+ import _createClass from "@babel/runtime/helpers/createClass";
1
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
4
  import { createObjectURLCache } from '../../../utils/objectURLCache';
@@ -6,7 +7,7 @@ import { createObjectURLCache } from '../../../utils/objectURLCache';
6
7
  export var getCacheKey = function getCacheKey(id, dimensions) {
7
8
  return [id, dimensions.height, dimensions.width].join('-');
8
9
  };
9
- export var CardPreviewCacheImpl = function CardPreviewCacheImpl(previewCache) {
10
+ export var CardPreviewCacheImpl = /*#__PURE__*/_createClass(function CardPreviewCacheImpl(previewCache) {
10
11
  var _this = this;
11
12
 
12
13
  _classCallCheck(this, CardPreviewCacheImpl);
@@ -22,6 +23,12 @@ export var CardPreviewCacheImpl = function CardPreviewCacheImpl(previewCache) {
22
23
  _this.previewCache.set(cacheKey, cardPreview);
23
24
  });
24
25
 
26
+ _defineProperty(this, "remove", function (id, dimensions) {
27
+ var cacheKey = getCacheKey(id, dimensions);
28
+
29
+ _this.previewCache.remove(cacheKey);
30
+ });
31
+
25
32
  this.previewCache = previewCache;
26
- };
33
+ });
27
34
  export default new CardPreviewCacheImpl(createObjectURLCache());