@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
@@ -23,29 +23,27 @@ import { version as packageVersion, name as packageName } from '../../version.js
23
23
  import { withAnalyticsEvents } from '@atlaskit/analytics-next';
24
24
  import { withMediaAnalyticsContext } from '@atlaskit/media-common';
25
25
  import DownloadIcon from '@atlaskit/icon/glyph/download';
26
- import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
27
- import { addFileAttrsToUrl, globalMediaEventEmitter, isDifferentIdentifier, isFileIdentifier, isErrorFileState, RECENTS_COLLECTION, isPreviewableType } from '@atlaskit/media-client';
26
+ import { globalMediaEventEmitter, isDifferentIdentifier, isFileIdentifier, RECENTS_COLLECTION, isImageRepresentationReady, isExternalImageIdentifier, imageResizeModeToFileImageMode } from '@atlaskit/media-client';
28
27
  import { MediaViewer } from '@atlaskit/media-viewer';
29
28
  import { IntlProvider, intlShape } from 'react-intl';
30
29
  import { CardView } from '../cardView';
31
30
  import { ViewportDetector } from '../../utils/viewportDetector';
32
- import { getDataURIDimension } from '../../utils/getDataURIDimension';
33
- import { getCardPreviewFromFileState, getCardPreviewFromBackend } from './getCardPreview';
31
+ import { getRequestedDimensions } from '../../utils/getDataURIDimension';
32
+ import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview } from './getCardPreview';
34
33
  import { getFileDetails } from '../../utils/metadata';
35
- import { isBigger } from '../../utils/dimensionComparer';
36
- import { createObjectURLCache } from '../../utils/objectURLCache';
37
- import { getCardStatus, extractCardStatusParams } from './getCardStatus';
38
34
  import { InlinePlayer } from '../inlinePlayer';
39
- import { fireMediaCardEvent, getFileAttributes, getRenderCommencedEventPayload, getCopiedFilePayload } from '../../utils/analytics';
40
- import { FileAttributesProvider } from '../../utils/fileAttributesContext';
41
- import { isLocalPreviewError, MediaCardError, ensureMediaCardError } from '../../errors';
42
- import { fireOperationalEvent, relevantFeatureFlagNames } from './cardAnalytics';
43
- var cardPreviewCache = createObjectURLCache();
35
+ import { getFileAttributes } from '../../utils/analytics';
36
+ import { isLocalPreviewError, MediaCardError, ensureMediaCardError, ImageLoadError } from '../../errors';
37
+ import { fireOperationalEvent as _fireOperationalEvent, fireCommencedEvent as _fireCommencedEvent, relevantFeatureFlagNames, fireCopiedEvent, fireScreenEvent } from './cardAnalytics';
38
+ import getDocument from '../../utils/document';
39
+ import { getCardStateFromFileState, createStateUpdater } from './cardState';
44
40
  export var CardBase = /*#__PURE__*/function (_Component) {
45
41
  _inherits(CardBase, _Component);
46
42
 
47
43
  var _super = _createSuper(CardBase);
48
44
 
45
+ // We initialise timeElapsedTillCommenced
46
+ // to avoid extra branching on a possibly undefined value.
49
47
  function CardBase(props) {
50
48
  var _this;
51
49
 
@@ -55,147 +53,184 @@ export var CardBase = /*#__PURE__*/function (_Component) {
55
53
 
56
54
  _defineProperty(_assertThisInitialized(_this), "hasBeenMounted", false);
57
55
 
58
- _defineProperty(_assertThisInitialized(_this), "onCopyListener", function () {
59
- if (typeof window.getSelection === 'function') {
60
- var selection = window.getSelection();
61
- var cardRef = _this.state.cardRef;
56
+ _defineProperty(_assertThisInitialized(_this), "timeElapsedTillCommenced", performance.now());
62
57
 
63
- if (cardRef && selection && selection.containsNode && selection.containsNode(cardRef, true)) {
64
- _this.fireFileCopiedEvent();
65
- }
66
- }
67
- });
68
-
69
- _defineProperty(_assertThisInitialized(_this), "getPreviewCacheKey", function (id, dimensions) {
70
- // Dimensions are used to create a key.
71
- // Cache is invalidated when different dimensions are provided.
72
- return [id, dimensions.height, dimensions.width].join('-');
58
+ _defineProperty(_assertThisInitialized(_this), "getImageURLParams", function (_ref) {
59
+ var collection = _ref.collectionName;
60
+ return _objectSpread(_objectSpread({
61
+ collection: collection,
62
+ mode: imageResizeModeToFileImageMode(_this.props.resizeMode)
63
+ }, _this.requestedDimensions), {}, {
64
+ allowAnimated: true
65
+ });
73
66
  });
74
67
 
75
- _defineProperty(_assertThisInitialized(_this), "shouldRefetchImage", function (current, next) {
76
- if (!current || !next) {
77
- return false;
78
- }
79
-
80
- return isBigger(current, next);
68
+ _defineProperty(_assertThisInitialized(_this), "getMediaBlobUrlAttrs", function (identifier, fileState) {
69
+ var id = identifier.id,
70
+ collection = identifier.collectionName;
71
+ var _this$props = _this.props,
72
+ originalDimensions = _this$props.originalDimensions,
73
+ contextId = _this$props.contextId,
74
+ alt = _this$props.alt;
75
+
76
+ var _getFileDetails = getFileDetails(identifier, fileState),
77
+ mimeType = _getFileDetails.mimeType,
78
+ name = _getFileDetails.name,
79
+ size = _getFileDetails.size;
80
+
81
+ return contextId ? _objectSpread(_objectSpread({
82
+ id: id,
83
+ collection: collection,
84
+ contextId: contextId,
85
+ mimeType: mimeType,
86
+ name: name,
87
+ size: size
88
+ }, originalDimensions || _this.requestedDimensions), {}, {
89
+ alt: alt
90
+ }) : undefined;
81
91
  });
82
92
 
83
- _defineProperty(_assertThisInitialized(_this), "isLatestCardStatusUpdate", function (cardStatusUpdateTimestamp) {
84
- return !_this.lastCardStatusUpdateTimestamp || _this.lastCardStatusUpdateTimestamp <= cardStatusUpdateTimestamp;
93
+ _defineProperty(_assertThisInitialized(_this), "getCardPreviewParams", function (identifier, fileState) {
94
+ var isBannedLocalPreview = _this.state.isBannedLocalPreview;
95
+ var id = identifier.id;
96
+ var _this$props2 = _this.props,
97
+ _this$props2$dimensio = _this$props2.dimensions,
98
+ dimensions = _this$props2$dimensio === void 0 ? {} : _this$props2$dimensio,
99
+ mediaClient = _this$props2.mediaClient;
100
+ return {
101
+ mediaClient: mediaClient,
102
+ id: id,
103
+ dimensions: dimensions,
104
+ onLocalPreviewError: _this.fireLocalPreviewErrorEvent,
105
+ filePreview: isBannedLocalPreview ? undefined : getFilePreviewFromFileState(fileState),
106
+ isRemotePreviewReady: isImageRepresentationReady(fileState),
107
+ imageUrlParams: _this.getImageURLParams(identifier),
108
+ mediaBlobUrlAttrs: _this.getMediaBlobUrlAttrs(identifier, fileState)
109
+ };
85
110
  });
86
111
 
87
- _defineProperty(_assertThisInitialized(_this), "getCardPreview", /*#__PURE__*/function () {
88
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(mediaClient, identifier, fileState, metadata) {
89
- var _this$props, _this$props$dimension, dimensions, originalDimensions, resizeMode, featureFlags, id, collectionName, cacheKey, mediaType, mimeType, requestedDimensions, shouldUseLocalPreview, previewableType, cardPreview, contextDimensions;
90
-
112
+ _defineProperty(_assertThisInitialized(_this), "resolvePreview", /*#__PURE__*/function () {
113
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(identifier, fileState) {
114
+ var params, cardPreview, wrappedError;
91
115
  return _regeneratorRuntime.wrap(function _callee$(_context) {
92
116
  while (1) {
93
117
  switch (_context.prev = _context.next) {
94
118
  case 0:
95
- _this$props = _this.props, _this$props$dimension = _this$props.dimensions, dimensions = _this$props$dimension === void 0 ? {} : _this$props$dimension, originalDimensions = _this$props.originalDimensions, resizeMode = _this$props.resizeMode, featureFlags = _this$props.featureFlags;
96
- id = identifier.id, collectionName = identifier.collectionName; // We aren't using the component state here, as cardPreviewCache has a shorter lifecycle
97
-
98
- cacheKey = _this.getPreviewCacheKey(id, dimensions);
99
-
100
- if (!cardPreviewCache.has(cacheKey)) {
101
- _context.next = 5;
102
- break;
119
+ _context.prev = 0;
120
+ params = _this.getCardPreviewParams(identifier, fileState);
121
+ _context.next = 4;
122
+ return getCardPreview(params);
123
+
124
+ case 4:
125
+ cardPreview = _context.sent;
126
+
127
+ _this.safeSetState({
128
+ cardPreview: cardPreview
129
+ });
130
+
131
+ _context.next = 12;
132
+ break;
133
+
134
+ case 8:
135
+ _context.prev = 8;
136
+ _context.t0 = _context["catch"](0);
137
+ wrappedError = ensureMediaCardError('preview-fetch', _context.t0); // If remote preview fails, we set status 'error'
138
+ // If local preview fails (i.e, no remote preview available),
139
+ // we can stay in the same status until there is a remote preview available
140
+ // If it's any other error we set status 'error'
141
+
142
+ if (isLocalPreviewError(wrappedError)) {
143
+ _this.safeSetState({
144
+ isBannedLocalPreview: true
145
+ });
146
+ } else {
147
+ _this.safeSetState({
148
+ status: 'error',
149
+ error: wrappedError
150
+ });
103
151
  }
104
152
 
105
- return _context.abrupt("return", cardPreviewCache.get(cacheKey));
106
-
107
- case 5:
108
- if (!isErrorFileState(fileState)) {
109
- _context.next = 7;
110
- break;
111
- }
112
-
113
- return _context.abrupt("return");
114
-
115
- case 7:
116
- mediaType = fileState.mediaType, mimeType = fileState.mimeType;
117
- requestedDimensions = _this.getRequestedDimensions(); // TODO: align these checks with helpers from Media Client
118
- // https://product-fabric.atlassian.net/browse/BMPT-1300
119
-
120
- shouldUseLocalPreview = mediaType !== 'doc' && !!mimeType && isMimeTypeSupportedByBrowser(mimeType);
121
- previewableType = isPreviewableType(mediaType, featureFlags);
122
- _context.t1 = shouldUseLocalPreview;
123
-
124
- if (!_context.t1) {
125
- _context.next = 16;
126
- break;
127
- }
128
-
129
- _context.next = 15;
130
- return getCardPreviewFromFileState(fileState);
131
-
132
- case 15:
133
- _context.t1 = _context.sent;
134
-
135
- case 16:
136
- _context.t0 = _context.t1;
137
-
138
- if (_context.t0) {
139
- _context.next = 24;
140
- break;
141
- }
142
-
143
- _context.t2 = previewableType;
144
-
145
- if (!_context.t2) {
146
- _context.next = 23;
147
- break;
148
- }
149
-
150
- _context.next = 22;
151
- return getCardPreviewFromBackend(mediaClient, identifier, fileState, requestedDimensions, resizeMode);
152
-
153
- case 22:
154
- _context.t2 = _context.sent;
155
-
156
- case 23:
157
- _context.t0 = _context.t2;
158
-
159
- case 24:
160
- cardPreview = _context.t0;
161
-
162
- if (!cardPreview) {
163
- _context.next = 29;
164
- break;
165
- }
166
-
167
- if (cardPreview.dataURI) {
168
- // In case we've retrieved cardPreview using one of the two methods above,
169
- // we want to embed some meta context into dataURI for Copy/Paste to work.
170
- contextDimensions = originalDimensions || requestedDimensions;
171
- cardPreview.dataURI = _this.addContextToDataURI(cardPreview.dataURI, id, metadata, contextDimensions, collectionName);
172
- } // We store new cardPreview into cache
173
-
174
-
175
- cardPreviewCache.set(cacheKey, cardPreview);
176
- return _context.abrupt("return", cardPreview);
177
-
178
- case 29:
153
+ case 12:
179
154
  case "end":
180
155
  return _context.stop();
181
156
  }
182
157
  }
183
- }, _callee);
158
+ }, _callee, null, [[0, 8]]);
184
159
  }));
185
160
 
186
- return function (_x, _x2, _x3, _x4) {
187
- return _ref.apply(this, arguments);
161
+ return function (_x, _x2) {
162
+ return _ref2.apply(this, arguments);
188
163
  };
189
164
  }());
190
165
 
191
- _defineProperty(_assertThisInitialized(_this), "fireFileCopiedEvent", function () {
166
+ _defineProperty(_assertThisInitialized(_this), "getPerformanceAttributes", function () {
167
+ var _assertThisInitialize = _assertThisInitialized(_this),
168
+ timeElapsedTillCommenced = _assertThisInitialize.timeElapsedTillCommenced;
169
+
170
+ var timeElapsedTillEvent = performance.now();
171
+ var durationSinceCommenced = timeElapsedTillCommenced && timeElapsedTillEvent - timeElapsedTillCommenced;
172
+ return {
173
+ overall: {
174
+ durationSincePageStart: timeElapsedTillEvent,
175
+ durationSinceCommenced: durationSinceCommenced
176
+ }
177
+ };
178
+ });
179
+
180
+ _defineProperty(_assertThisInitialized(_this), "onImageError", function () {
181
+ var cardPreview = _this.state.cardPreview;
182
+ var error = new ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
183
+
184
+ if (cardPreview !== null && cardPreview !== void 0 && cardPreview.source && ['local', 'cache-local'].includes(cardPreview.source)) {
185
+ var _this$props3 = _this.props,
186
+ identifier = _this$props3.identifier,
187
+ _this$props3$dimensio = _this$props3.dimensions,
188
+ dimensions = _this$props3$dimensio === void 0 ? {} : _this$props3$dimensio;
189
+ isFileIdentifier(identifier) && removeCardPreviewFromCache(identifier.id, dimensions);
190
+
191
+ _this.safeSetState({
192
+ cardPreview: undefined,
193
+ isBannedLocalPreview: true
194
+ });
195
+
196
+ _this.fireLocalPreviewErrorEvent(error);
197
+ } else {
198
+ _this.safeSetState({
199
+ status: 'error',
200
+ error: error
201
+ });
202
+ }
203
+ });
204
+
205
+ _defineProperty(_assertThisInitialized(_this), "onImageLoad", function () {
206
+ _this.safeSetState({
207
+ previewDidRender: true
208
+ });
209
+ });
210
+
211
+ _defineProperty(_assertThisInitialized(_this), "fireCopiedEvent", function () {
212
+ var createAnalyticsEvent = _this.props.createAnalyticsEvent;
213
+ var cardRef = _this.state.cardRef;
214
+ cardRef && createAnalyticsEvent && fireCopiedEvent(createAnalyticsEvent, _this.metadata.id, cardRef);
215
+ });
216
+
217
+ _defineProperty(_assertThisInitialized(_this), "fireScreenEvent", function () {
192
218
  var createAnalyticsEvent = _this.props.createAnalyticsEvent;
193
- fireMediaCardEvent(getCopiedFilePayload(_this.metadata.id), createAnalyticsEvent);
219
+ createAnalyticsEvent && fireScreenEvent(createAnalyticsEvent, _this.fileAttributes);
220
+ });
221
+
222
+ _defineProperty(_assertThisInitialized(_this), "fireLocalPreviewErrorEvent", function (error) {// TODO: track local preview success rate
223
+ // https://product-fabric.atlassian.net/browse/MEX-774
194
224
  });
195
225
 
196
226
  _defineProperty(_assertThisInitialized(_this), "safeSetState", function (state) {
197
227
  if (_this.hasBeenMounted) {
198
- _this.setState(state);
228
+ // If it's setting the status, we need to use a state updater function,
229
+ // which ensures that no non-final status overrides a final status.
230
+ // If no status is set, we don't need a sate updater
231
+ var updater = !!state.status ? createStateUpdater(state) : state;
232
+
233
+ _this.setState(updater);
199
234
  }
200
235
  });
201
236
 
@@ -205,21 +240,22 @@ export var CardBase = /*#__PURE__*/function (_Component) {
205
240
  }
206
241
 
207
242
  if (_this.hasBeenMounted) {
243
+ // TODO MEX-788: add test for "do not remove the card preview when unsubscribing".
208
244
  _this.setState({
209
- cardPreview: undefined
245
+ isBannedLocalPreview: false
210
246
  });
211
247
  }
212
248
  });
213
249
 
214
250
  _defineProperty(_assertThisInitialized(_this), "onCardViewClick", function (event, analyticsEvent) {
215
- var _this$props2 = _this.props,
216
- identifier = _this$props2.identifier,
217
- useInlinePlayer = _this$props2.useInlinePlayer,
218
- shouldOpenMediaViewer = _this$props2.shouldOpenMediaViewer;
251
+ var _this$props4 = _this.props,
252
+ identifier = _this$props4.identifier,
253
+ useInlinePlayer = _this$props4.useInlinePlayer,
254
+ shouldOpenMediaViewer = _this$props4.shouldOpenMediaViewer;
219
255
  var cardPreview = _this.state.cardPreview;
220
256
 
221
- var _assertThisInitialize = _assertThisInitialized(_this),
222
- metadata = _assertThisInitialize.metadata;
257
+ var _assertThisInitialize2 = _assertThisInitialized(_this),
258
+ metadata = _assertThisInitialize2.metadata;
223
259
 
224
260
  _this.onClick(event, analyticsEvent);
225
261
 
@@ -270,13 +306,13 @@ export var CardBase = /*#__PURE__*/function (_Component) {
270
306
  });
271
307
 
272
308
  _defineProperty(_assertThisInitialized(_this), "renderInlinePlayer", function () {
273
- var _this$props3 = _this.props,
274
- identifier = _this$props3.identifier,
275
- mediaClient = _this$props3.mediaClient,
276
- dimensions = _this$props3.dimensions,
277
- selected = _this$props3.selected,
278
- testId = _this$props3.testId,
279
- originalDimensions = _this$props3.originalDimensions;
309
+ var _this$props5 = _this.props,
310
+ identifier = _this$props5.identifier,
311
+ mediaClient = _this$props5.mediaClient,
312
+ dimensions = _this$props5.dimensions,
313
+ selected = _this$props5.selected,
314
+ testId = _this$props5.testId,
315
+ originalDimensions = _this$props5.originalDimensions;
280
316
  return /*#__PURE__*/React.createElement(InlinePlayer, {
281
317
  mediaClient: mediaClient,
282
318
  dimensions: dimensions,
@@ -319,12 +355,12 @@ export var CardBase = /*#__PURE__*/function (_Component) {
319
355
 
320
356
  _defineProperty(_assertThisInitialized(_this), "renderMediaViewer", function () {
321
357
  var mediaViewerSelectedItem = _this.state.mediaViewerSelectedItem;
322
- var _this$props4 = _this.props,
323
- mediaClient = _this$props4.mediaClient,
324
- identifier = _this$props4.identifier,
325
- mediaViewerDataSource = _this$props4.mediaViewerDataSource,
326
- contextId = _this$props4.contextId,
327
- featureFlags = _this$props4.featureFlags;
358
+ var _this$props6 = _this.props,
359
+ mediaClient = _this$props6.mediaClient,
360
+ identifier = _this$props6.identifier,
361
+ mediaViewerDataSource = _this$props6.mediaViewerDataSource,
362
+ contextId = _this$props6.contextId,
363
+ featureFlags = _this$props6.featureFlags;
328
364
 
329
365
  if (!mediaViewerSelectedItem) {
330
366
  return;
@@ -346,20 +382,20 @@ export var CardBase = /*#__PURE__*/function (_Component) {
346
382
  });
347
383
 
348
384
  _defineProperty(_assertThisInitialized(_this), "renderCard", function () {
349
- var _this$props5 = _this.props,
350
- identifier = _this$props5.identifier,
351
- isLazy = _this$props5.isLazy,
352
- appearance = _this$props5.appearance,
353
- resizeMode = _this$props5.resizeMode,
354
- dimensions = _this$props5.dimensions,
355
- selectable = _this$props5.selectable,
356
- selected = _this$props5.selected,
357
- disableOverlay = _this$props5.disableOverlay,
358
- alt = _this$props5.alt,
359
- testId = _this$props5.testId,
360
- featureFlags = _this$props5.featureFlags,
361
- titleBoxBgColor = _this$props5.titleBoxBgColor,
362
- titleBoxIcon = _this$props5.titleBoxIcon;
385
+ var _this$props7 = _this.props,
386
+ identifier = _this$props7.identifier,
387
+ isLazy = _this$props7.isLazy,
388
+ appearance = _this$props7.appearance,
389
+ resizeMode = _this$props7.resizeMode,
390
+ dimensions = _this$props7.dimensions,
391
+ selectable = _this$props7.selectable,
392
+ selected = _this$props7.selected,
393
+ disableOverlay = _this$props7.disableOverlay,
394
+ alt = _this$props7.alt,
395
+ testId = _this$props7.testId,
396
+ featureFlags = _this$props7.featureFlags,
397
+ titleBoxBgColor = _this$props7.titleBoxBgColor,
398
+ titleBoxIcon = _this$props7.titleBoxIcon;
363
399
  var mediaItemType = identifier.mediaItemType;
364
400
  var _this$state = _this.state,
365
401
  status = _this$state.status,
@@ -374,18 +410,18 @@ export var CardBase = /*#__PURE__*/function (_Component) {
374
410
  error = _this$state.error,
375
411
  cardRef = _this$state.cardRef;
376
412
 
377
- var _assertThisInitialize2 = _assertThisInitialized(_this),
378
- metadata = _assertThisInitialize2.metadata;
379
-
380
413
  var _assertThisInitialize3 = _assertThisInitialized(_this),
381
- onCardViewClick = _assertThisInitialize3.onCardViewClick,
382
- onDisplayImage = _assertThisInitialize3.onDisplayImage,
383
- actions = _assertThisInitialize3.actions,
384
- onMouseEnter = _assertThisInitialize3.onMouseEnter;
414
+ metadata = _assertThisInitialize3.metadata;
415
+
416
+ var _assertThisInitialize4 = _assertThisInitialized(_this),
417
+ onCardViewClick = _assertThisInitialize4.onCardViewClick,
418
+ onDisplayImage = _assertThisInitialize4.onDisplayImage,
419
+ actions = _assertThisInitialize4.actions,
420
+ onMouseEnter = _assertThisInitialize4.onMouseEnter;
385
421
 
386
422
  var card = /*#__PURE__*/React.createElement(CardView, {
387
423
  status: status,
388
- error: error && error.secondaryError,
424
+ error: error,
389
425
  mediaItemType: mediaItemType,
390
426
  metadata: metadata,
391
427
  dataURI: dataURI,
@@ -406,7 +442,9 @@ export var CardBase = /*#__PURE__*/function (_Component) {
406
442
  testId: testId,
407
443
  featureFlags: featureFlags,
408
444
  titleBoxBgColor: titleBoxBgColor,
409
- titleBoxIcon: titleBoxIcon
445
+ titleBoxIcon: titleBoxIcon,
446
+ onImageError: _this.onImageError,
447
+ onImageLoad: _this.onImageLoad
410
448
  });
411
449
  return isLazy ? /*#__PURE__*/React.createElement(ViewportDetector, {
412
450
  targetRef: cardRef,
@@ -423,8 +461,8 @@ export var CardBase = /*#__PURE__*/function (_Component) {
423
461
  _defineProperty(_assertThisInitialized(_this), "onClick", function (event, analyticsEvent) {
424
462
  var onClick = _this.props.onClick;
425
463
 
426
- var _assertThisInitialize4 = _assertThisInitialized(_this),
427
- metadata = _assertThisInitialize4.metadata;
464
+ var _assertThisInitialize5 = _assertThisInitialized(_this),
465
+ metadata = _assertThisInitialize5.metadata;
428
466
 
429
467
  if (onClick) {
430
468
  var cardEvent = {
@@ -438,8 +476,8 @@ export var CardBase = /*#__PURE__*/function (_Component) {
438
476
  _defineProperty(_assertThisInitialized(_this), "onMouseEnter", function (event) {
439
477
  var onMouseEnter = _this.props.onMouseEnter;
440
478
 
441
- var _assertThisInitialize5 = _assertThisInitialized(_this),
442
- metadata = _assertThisInitialize5.metadata;
479
+ var _assertThisInitialize6 = _assertThisInitialized(_this),
480
+ metadata = _assertThisInitialize6.metadata;
443
481
 
444
482
  if (onMouseEnter) {
445
483
  var cardEvent = {
@@ -450,47 +488,61 @@ export var CardBase = /*#__PURE__*/function (_Component) {
450
488
  }
451
489
  });
452
490
 
491
+ var _status = 'loading';
492
+
453
493
  var _cardPreview;
454
494
 
455
- var _this$props6 = _this.props,
456
- _identifier = _this$props6.identifier,
457
- _this$props6$dimensio = _this$props6.dimensions,
458
- _dimensions = _this$props6$dimensio === void 0 ? {} : _this$props6$dimensio;
495
+ var _this$props8 = _this.props,
496
+ _identifier = _this$props8.identifier,
497
+ _this$props8$dimensio = _this$props8.dimensions,
498
+ _dimensions = _this$props8$dimensio === void 0 ? {} : _this$props8$dimensio;
459
499
 
460
500
  if (isFileIdentifier(_identifier)) {
461
501
  var id = _identifier.id;
502
+ _cardPreview = getCardPreviewFromCache(id, _dimensions);
503
+ } else if (isExternalImageIdentifier(_identifier)) {
504
+ _this.fireCommencedEvent();
462
505
 
463
- var cacheKey = _this.getPreviewCacheKey(id, _dimensions);
464
-
465
- _cardPreview = cardPreviewCache.get(cacheKey);
466
- }
467
- /**
468
- * If cardPreview is available from local cache, `isCardVisible`
469
- * should be true to avoid flickers during re-mount of the component
470
- */
506
+ _status = 'loading-preview';
507
+ var dataURI = _identifier.dataURI;
508
+ _cardPreview = {
509
+ dataURI: dataURI,
510
+ orientation: 1,
511
+ source: 'external'
512
+ };
513
+ } // If cardPreview is available from local cache, `isCardVisible`
514
+ // should be true to avoid flickers during re-mount of the component
471
515
 
472
516
 
517
+ var isCardVisible = _cardPreview ? true : !_this.props.isLazy;
473
518
  _this.state = {
474
- status: 'loading',
475
- isCardVisible: _cardPreview ? true : !_this.props.isLazy,
519
+ status: _status,
520
+ isCardVisible: isCardVisible,
476
521
  isPlayingFile: false,
477
522
  cardPreview: _cardPreview,
478
- cardRef: null
523
+ cardRef: null,
524
+ isBannedLocalPreview: false,
525
+ previewDidRender: false
479
526
  };
480
527
  return _this;
481
- } // we add a listener for each of the cards on the page
482
- // and then check if the triggered listener is from the card
483
- // that contains a div in current window.getSelection()
484
- // won't work in IE11
485
-
528
+ }
486
529
 
487
530
  _createClass(CardBase, [{
488
531
  key: "componentDidMount",
489
532
  value: function componentDidMount() {
490
533
  this.hasBeenMounted = true;
491
- this.fireCommencedEvent();
492
- this.updateStateForIdentifier();
493
- document.addEventListener('copy', this.onCopyListener);
534
+ var isCardVisible = this.state.isCardVisible;
535
+ var identifier = this.props.identifier;
536
+
537
+ if (isCardVisible && isFileIdentifier(identifier)) {
538
+ this.updateStateForIdentifier(identifier);
539
+ } // we add a listener for each of the cards on the page
540
+ // and then check if the triggered listener is from the card
541
+ // that contains a div in current window.getSelection()
542
+ // won't work in IE11
543
+
544
+
545
+ getDocument().addEventListener('copy', this.fireCopiedEvent);
494
546
  }
495
547
  }, {
496
548
  key: "componentDidUpdate",
@@ -499,28 +551,66 @@ export var CardBase = /*#__PURE__*/function (_Component) {
499
551
  prevIdentifier = prevProps.identifier,
500
552
  prevDimensions = prevProps.dimensions;
501
553
  var prevIsCardVisible = prevState.isCardVisible;
502
- var _this$props7 = this.props,
503
- mediaClient = _this$props7.mediaClient,
504
- identifier = _this$props7.identifier,
505
- dimensions = _this$props7.dimensions;
506
- var isCardVisible = this.state.isCardVisible;
554
+ var _this$props9 = this.props,
555
+ mediaClient = _this$props9.mediaClient,
556
+ identifier = _this$props9.identifier,
557
+ dimensions = _this$props9.dimensions,
558
+ featureFlags = _this$props9.featureFlags;
559
+ var _this$state2 = this.state,
560
+ isCardVisible = _this$state2.isCardVisible,
561
+ cardPreview = _this$state2.cardPreview,
562
+ status = _this$state2.status,
563
+ fileState = _this$state2.fileState,
564
+ isBannedLocalPreview = _this$state2.isBannedLocalPreview,
565
+ previewDidRender = _this$state2.previewDidRender;
507
566
  var isDifferent = isDifferentIdentifier(prevIdentifier, identifier);
567
+ var turnedVisible = !prevIsCardVisible && isCardVisible;
568
+ var isNewMediaClient = prevMediaClient !== mediaClient;
508
569
 
509
- if (prevIsCardVisible !== isCardVisible && isCardVisible || prevMediaClient !== mediaClient || isDifferent || this.shouldRefetchImage(prevDimensions, dimensions)) {
570
+ if (isExternalImageIdentifier(identifier) && isDifferent) {
510
571
  this.fireCommencedEvent();
511
- this.updateStateForIdentifier();
572
+ var dataURI = identifier.dataURI;
573
+ this.setState({
574
+ status: 'loading-preview',
575
+ cardPreview: {
576
+ dataURI: dataURI,
577
+ orientation: 1,
578
+ source: 'external'
579
+ },
580
+ isCardVisible: true
581
+ });
582
+ }
583
+
584
+ if (isFileIdentifier(identifier) && (turnedVisible || !!this.subscription && (isNewMediaClient || isDifferent))) {
585
+ this.updateStateForIdentifier(identifier);
512
586
  }
513
587
 
514
588
  if (this.state.status !== prevState.status) {
515
- var _this$state2 = this.state,
516
- status = _this$state2.status,
517
- cardPreview = _this$state2.cardPreview,
518
- error = _this$state2.error;
519
- var createAnalyticsEvent = this.props.createAnalyticsEvent;
520
- createAnalyticsEvent && fireOperationalEvent(createAnalyticsEvent, status, this.fileAttributes, {
521
- cardPreview: cardPreview,
522
- error: error
589
+ this.fireOperationalEvent();
590
+
591
+ if (this.state.status === 'complete' || this.fileAttributes.fileMediatype === 'video' && !!cardPreview && this.state.status === 'processing') {
592
+ this.fireScreenEvent();
593
+ }
594
+ }
595
+
596
+ if (isFileIdentifier(identifier) && fileState && shouldResolvePreview({
597
+ status: status,
598
+ fileState: fileState,
599
+ dimensions: dimensions,
600
+ prevDimensions: prevDimensions,
601
+ featureFlags: featureFlags,
602
+ hasCardPreview: !!cardPreview,
603
+ isBannedLocalPreview: isBannedLocalPreview
604
+ })) {
605
+ this.resolvePreview(identifier, fileState);
606
+ }
607
+
608
+ if (previewDidRender && // We should't complete if status is uploading
609
+ ['loading', 'loading-preview', 'processing'].includes(status)) {
610
+ this.safeSetState({
611
+ status: 'complete'
523
612
  });
613
+ this.unsubscribe();
524
614
  }
525
615
  }
526
616
  }, {
@@ -528,209 +618,89 @@ export var CardBase = /*#__PURE__*/function (_Component) {
528
618
  value: function componentWillUnmount() {
529
619
  this.hasBeenMounted = false;
530
620
  this.unsubscribe();
531
- document.removeEventListener('copy', this.onCopyListener);
621
+ getDocument().removeEventListener('copy', this.fireCopiedEvent);
532
622
  }
533
623
  }, {
534
624
  key: "updateStateForIdentifier",
535
- value: function updateStateForIdentifier() {
536
- var _this$props8 = this.props,
537
- mediaClient = _this$props8.mediaClient,
538
- identifier = _this$props8.identifier;
539
- var isCardVisible = this.state.isCardVisible;
540
-
541
- if (!isCardVisible) {
542
- return;
543
- }
544
-
545
- if (identifier.mediaItemType === 'file') {
546
- this.unsubscribe();
547
- this.subscribeInternalFile(identifier, mediaClient);
548
- }
549
- }
550
- }, {
551
- key: "getRequestedDimensions",
552
- value: function getRequestedDimensions() {
553
- var dimensions = this.props.dimensions;
554
- var cardRef = this.state.cardRef;
555
- var options = {
556
- dimensions: dimensions,
557
- element: cardRef
558
- };
559
- var width = getDataURIDimension('width', options);
560
- var height = getDataURIDimension('height', options);
561
- return {
562
- width: width,
563
- height: height
564
- };
565
- }
566
- }, {
567
- key: "addContextToDataURI",
568
- value: function addContextToDataURI(dataURI, fileId, metadata, _ref2, collectionName) {
569
- var width = _ref2.width,
570
- height = _ref2.height;
571
- var _this$props9 = this.props,
572
- contextId = _this$props9.contextId,
573
- alt = _this$props9.alt;
574
-
575
- if (!contextId) {
576
- return dataURI;
577
- }
578
-
579
- return addFileAttrsToUrl(dataURI, {
580
- id: fileId,
581
- collection: collectionName,
582
- contextId: contextId,
583
- mimeType: metadata.mimeType,
584
- name: metadata.name,
585
- size: metadata.size,
586
- width: width,
587
- height: height,
588
- alt: alt
589
- });
625
+ value: function updateStateForIdentifier(identifier) {
626
+ this.fireCommencedEvent();
627
+ this.subscribeInternalFile(identifier);
590
628
  }
591
629
  }, {
592
630
  key: "subscribeInternalFile",
593
- value: function subscribeInternalFile(identifier, mediaClient) {
631
+ value: function subscribeInternalFile(identifier) {
594
632
  var _this2 = this;
595
633
 
634
+ var mediaClient = this.props.mediaClient;
635
+ var isBannedLocalPreview = this.state.isBannedLocalPreview;
596
636
  var id = identifier.id,
597
637
  collectionName = identifier.collectionName,
598
638
  occurrenceKey = identifier.occurrenceKey;
639
+ this.unsubscribe();
599
640
  this.subscription = mediaClient.file.getFileState(id, {
600
641
  collectionName: collectionName,
601
642
  occurrenceKey: occurrenceKey
602
643
  }).subscribe({
603
- next: function () {
604
- var _next = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(fileState) {
605
- var thisCardStatusUpdateTimestamp, status, cardPreview, error, wrappedError;
606
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
607
- while (1) {
608
- switch (_context2.prev = _context2.next) {
609
- case 0:
610
- _this2.lastFileState = fileState;
611
- thisCardStatusUpdateTimestamp = (performance || Date).now();
612
- status = getCardStatus(fileState.status, extractCardStatusParams(fileState, _this2.props.featureFlags));
613
-
614
- _this2.safeSetState({
615
- fileState: fileState
616
- });
617
-
618
- _context2.prev = 4;
619
- _context2.next = 7;
620
- return _this2.getCardPreview(mediaClient, identifier, fileState, getFileDetails(fileState));
621
-
622
- case 7:
623
- cardPreview = _context2.sent;
624
- _context2.next = 14;
625
- break;
626
-
627
- case 10:
628
- _context2.prev = 10;
629
- _context2.t0 = _context2["catch"](4);
630
- wrappedError = ensureMediaCardError('preview-fetch', _context2.t0); // If the local preview fails, we don't need to display the error.
631
- // TODO: if file has local preview card will be complete status. But if the local preview fails,
632
- // and we don't change the status, we will have
633
- // [ !cardPreview && status == complete -> log succeeded event ]
634
- // https://product-fabric.atlassian.net/browse/BMPT-1315
635
-
636
- if (!isLocalPreviewError(wrappedError)) {
637
- status = 'error';
638
- error = wrappedError;
639
- }
640
-
641
- case 14:
642
- if (_this2.isLatestCardStatusUpdate(thisCardStatusUpdateTimestamp)) {
643
- // These status and progress must not override values representing more recent FileState
644
-
645
- /* next() start some await() delay in next() status & progress update
646
- * ------- ------------------ ------------------------
647
- * |----[1]FileState:uploading------>| |
648
- * | | |
649
- * |----[2]FileState:uploading------>| |
650
- * | | |
651
- * | |----[2]FileState:uploading------>| Update status to `uploading`
652
- * |----[3]FileState:processing----->| |
653
- * | |----[3]FileState:processing----->| Update status to `complete`
654
- * | | |
655
- * | |----[1]FileState:uploading------>| We do not want to update status to `uploading` again!
656
- *
657
- */
658
- if (status === 'error' && isErrorFileState(fileState) && !error) {
659
- error = new MediaCardError('error-file-state', new Error(fileState.message));
660
- }
661
-
662
- _this2.safeSetState({
663
- status: status,
664
- cardPreview: cardPreview,
665
- progress: status === 'uploading' && fileState.status === 'uploading' ? fileState.progress : 1,
666
- error: status === 'error' && error ? error : undefined
667
- });
668
-
669
- _this2.lastCardStatusUpdateTimestamp = thisCardStatusUpdateTimestamp;
670
- }
671
-
672
- case 15:
673
- case "end":
674
- return _context2.stop();
675
- }
676
- }
677
- }, _callee2, null, [[4, 10]]);
678
- }));
679
-
680
- function next(_x5) {
681
- return _next.apply(this, arguments);
682
- }
644
+ next: function next(fileState) {
645
+ var featureFlags = _this2.props.featureFlags;
646
+ var newState = getCardStateFromFileState(fileState, isBannedLocalPreview, featureFlags);
683
647
 
684
- return next;
685
- }(),
648
+ _this2.safeSetState(newState);
649
+ },
686
650
  error: function error(e) {
687
- // If file state subscription decides that the card is complete
688
- // and later there is an error, we won't change the card's status.
689
- if (_this2.state.status === 'complete') {
690
- return;
691
- }
692
-
693
- var errorReason = _this2.fileAttributes.fileStatus === 'uploading' ? 'upload' : 'metadata-fetch';
651
+ var errorReason = _this2.state.status === 'uploading' ? 'upload' : 'metadata-fetch';
694
652
  var error = new MediaCardError(errorReason, e);
695
653
 
696
654
  _this2.safeSetState({
697
655
  error: error,
698
656
  status: 'error'
699
657
  });
700
-
701
- _this2.lastCardStatusUpdateTimestamp = (performance || Date).now();
702
658
  }
703
659
  });
704
660
  }
661
+ }, {
662
+ key: "requestedDimensions",
663
+ get: function get() {
664
+ var dimensions = this.props.dimensions;
665
+ var element = this.state.cardRef;
666
+ return getRequestedDimensions({
667
+ dimensions: dimensions,
668
+ element: element
669
+ });
670
+ }
705
671
  }, {
706
672
  key: "metadata",
707
673
  get: function get() {
708
- var identifier = this.props.identifier;
709
- return isFileIdentifier(identifier) ? this.state.fileState ? getFileDetails(this.state.fileState) : {
710
- id: identifier.id
711
- } : {
712
- id: identifier.mediaItemType,
713
- name: identifier.name || identifier.dataURI,
714
- mediaType: 'image'
715
- };
674
+ var _this$state3;
675
+
676
+ return getFileDetails(this.props.identifier, (_this$state3 = this.state) === null || _this$state3 === void 0 ? void 0 : _this$state3.fileState);
716
677
  }
717
678
  }, {
718
679
  key: "fileAttributes",
719
680
  get: function get() {
720
- var _this$lastFileState;
681
+ var _this$state4, _this$state4$fileStat;
721
682
 
722
- return getFileAttributes(this.metadata, (_this$lastFileState = this.lastFileState) === null || _this$lastFileState === void 0 ? void 0 : _this$lastFileState.status);
683
+ return getFileAttributes(this.metadata, (_this$state4 = this.state) === null || _this$state4 === void 0 ? void 0 : (_this$state4$fileStat = _this$state4.fileState) === null || _this$state4$fileStat === void 0 ? void 0 : _this$state4$fileStat.status);
684
+ }
685
+ }, {
686
+ key: "fireOperationalEvent",
687
+ value: function fireOperationalEvent() {
688
+ var _this$state5 = this.state,
689
+ status = _this$state5.status,
690
+ error = _this$state5.error;
691
+ var createAnalyticsEvent = this.props.createAnalyticsEvent;
692
+ createAnalyticsEvent && _fireOperationalEvent(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), error);
723
693
  }
724
694
  }, {
725
695
  key: "fireCommencedEvent",
726
696
  value: function fireCommencedEvent() {
727
- if (!this.state.isCardVisible) {
728
- return;
729
- }
730
-
697
+ this.timeElapsedTillCommenced = performance.now();
731
698
  var createAnalyticsEvent = this.props.createAnalyticsEvent;
732
- var payload = getRenderCommencedEventPayload(this.fileAttributes);
733
- fireMediaCardEvent(payload, createAnalyticsEvent);
699
+ createAnalyticsEvent && _fireCommencedEvent(createAnalyticsEvent, this.fileAttributes, {
700
+ overall: {
701
+ durationSincePageStart: this.timeElapsedTillCommenced
702
+ }
703
+ });
734
704
  }
735
705
  }, {
736
706
  key: "actions",
@@ -763,18 +733,13 @@ export var CardBase = /*#__PURE__*/function (_Component) {
763
733
  }, {
764
734
  key: "render",
765
735
  value: function render() {
766
- var _this$lastFileState2;
767
-
768
- var _this$state3 = this.state,
769
- isPlayingFile = _this$state3.isPlayingFile,
770
- mediaViewerSelectedItem = _this$state3.mediaViewerSelectedItem;
736
+ var _this$state6 = this.state,
737
+ isPlayingFile = _this$state6.isPlayingFile,
738
+ mediaViewerSelectedItem = _this$state6.mediaViewerSelectedItem;
771
739
  var innerContent = /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? this.renderInlinePlayer() : this.renderCard(), mediaViewerSelectedItem ? this.renderMediaViewer() : null);
772
- var content = this.context.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
740
+ return this.context.intl ? innerContent : /*#__PURE__*/React.createElement(IntlProvider, {
773
741
  locale: "en"
774
742
  }, innerContent);
775
- return /*#__PURE__*/React.createElement(FileAttributesProvider, {
776
- data: getFileAttributes(this.metadata, (_this$lastFileState2 = this.lastFileState) === null || _this$lastFileState2 === void 0 ? void 0 : _this$lastFileState2.status)
777
- }, content);
778
743
  }
779
744
  }]);
780
745
 
@@ -795,23 +760,6 @@ _defineProperty(CardBase, "contextTypes", {
795
760
  intl: intlShape
796
761
  });
797
762
 
798
- _defineProperty(CardBase, "getDerivedStateFromProps", function (props) {
799
- var identifier = props.identifier;
800
-
801
- if (identifier.mediaItemType === 'external-image') {
802
- var dataURI = identifier.dataURI;
803
- return {
804
- status: 'complete',
805
- cardPreview: {
806
- dataURI: dataURI,
807
- orientation: 1
808
- }
809
- };
810
- }
811
-
812
- return null;
813
- });
814
-
815
763
  export var Card = withMediaAnalyticsContext({
816
764
  packageVersion: packageVersion,
817
765
  packageName: packageName,