@atlaskit/media-card 77.4.0 → 77.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/media-card
2
2
 
3
+ ## 77.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#43093](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43093) [`ccba4cddc23`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ccba4cddc23) - [ux] CXP-2736 Bug fix to ensure that a poster attribute is provided to videos for CardV2.
8
+
9
+ ## 77.4.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 77.4.0
4
16
 
5
17
  ### Minor Changes
@@ -49,7 +49,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
49
49
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
50
50
  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; } }
51
51
  var packageName = "@atlaskit/media-card";
52
- var packageVersion = "77.4.0";
52
+ var packageVersion = "77.4.2";
53
53
  var CardBase = exports.CardBase = /*#__PURE__*/function (_Component) {
54
54
  (0, _inherits2.default)(CardBase, _Component);
55
55
  var _super = _createSuper(CardBase);
@@ -90,7 +90,7 @@ var WrappedMediaCardAnalyticsErrorBoundary = /*#__PURE__*/function (_React$Compo
90
90
  }(_react.default.Component);
91
91
  (0, _defineProperty2.default)(WrappedMediaCardAnalyticsErrorBoundary, "displayName", 'MediaCardAnalyticsErrorBoundary');
92
92
  var packageName = "@atlaskit/media-card";
93
- var packageVersion = "77.4.0";
93
+ var packageVersion = "77.4.2";
94
94
  var MediaCardAnalyticsErrorBoundary = (0, _mediaCommon.withMediaAnalyticsContext)({
95
95
  packageVersion: packageVersion,
96
96
  packageName: packageName,
@@ -16,7 +16,7 @@ var _externalImageCard = require("./externalImageCard");
16
16
  var _fileCard = require("./fileCard");
17
17
  var _excluded = ["identifier"];
18
18
  var packageName = "@atlaskit/media-card";
19
- var packageVersion = "77.4.0";
19
+ var packageVersion = "77.4.2";
20
20
  var CardV2Base = exports.CardV2Base = function CardV2Base(_ref) {
21
21
  var identifier = _ref.identifier,
22
22
  otherProps = (0, _objectWithoutProperties2.default)(_ref, _excluded);
@@ -81,19 +81,6 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
81
81
  //---------------- State Initializer Functions -------------------//
82
82
  //----------------------------------------------------------------//
83
83
 
84
- var _useFileState = (0, _mediaClientReact.useFileState)(identifier.id, {
85
- collectionName: identifier.collectionName,
86
- occurrenceKey: identifier.occurrenceKey
87
- }),
88
- fileState = _useFileState.fileState;
89
- var prevFileState = (0, _usePrevious.usePrevious)(fileState);
90
- var fileStateValue = (0, _react.useMemo)(function () {
91
- if (fileState && (fileState === null || fileState === void 0 ? void 0 : fileState.status) !== 'error') {
92
- return fileState;
93
- }
94
- return prevFileState;
95
- // eslint-disable-next-line react-hooks/exhaustive-deps
96
- }, [fileState]);
97
84
  var ssrDataRef = (0, _react.useRef)();
98
85
  var ssrReliabilityRef = (0, _react.useRef)({
99
86
  server: {
@@ -118,10 +105,10 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
118
105
  allowAnimated: true
119
106
  });
120
107
  }, [cardElement, dimensions, identifier.collectionName, resizeMode]);
121
- var mediaBlobUrlAttrs = (0, _react.useMemo)(function () {
108
+ var getMediaBlobUrlAttrs = (0, _react.useCallback)(function (fileState) {
122
109
  var id = identifier.id,
123
110
  collection = identifier.collectionName;
124
- var _getFileDetails = (0, _metadata.getFileDetails)(identifier, fileStateValue),
111
+ var _getFileDetails = (0, _metadata.getFileDetails)(identifier, fileState),
125
112
  mimeType = _getFileDetails.mimeType,
126
113
  name = _getFileDetails.name,
127
114
  size = _getFileDetails.size;
@@ -138,7 +125,7 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
138
125
  })), {}, {
139
126
  alt: alt
140
127
  }) : undefined;
141
- }, [alt, cardElement, contextId, dimensions, fileStateValue, identifier, originalDimensions]);
128
+ }, [alt, cardElement, contextId, dimensions, identifier, originalDimensions]);
142
129
  var getSSRPreview = function getSSRPreview(ssr, identifier, mediaClient) {
143
130
  var _ssrDataRef$current, _ssrDataRef$current2;
144
131
  ssrDataRef.current = (0, _globalScope.getSSRData)(identifier);
@@ -149,7 +136,7 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
149
136
  }
150
137
  if (!((_ssrDataRef$current2 = ssrDataRef.current) !== null && _ssrDataRef$current2 !== void 0 && _ssrDataRef$current2.dataURI)) {
151
138
  try {
152
- return (0, _getCardPreview.getSSRCardPreview)(ssr, mediaClient, identifier.id, imageURLParams, mediaBlobUrlAttrs);
139
+ return (0, _getCardPreview.getSSRCardPreview)(ssr, mediaClient, identifier.id, imageURLParams, getMediaBlobUrlAttrs(fileStateValue));
153
140
  } catch (e) {
154
141
  ssrReliabilityRef.current[ssr] = _objectSpread({
155
142
  status: 'fail'
@@ -172,6 +159,35 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
172
159
  }
173
160
  return cardPreview;
174
161
  };
162
+ var _useState3 = (0, _react.useState)(cardPreviewInitializer),
163
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
164
+ cardPreview = _useState4[0],
165
+ setCardPreview = _useState4[1];
166
+
167
+ // If cardPreview is available from local cache or external, `isCardVisible`
168
+ // should be true to avoid flickers during re-mount of the component
169
+ // should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
170
+ // outside the viewport
171
+ var _useState5 = (0, _react.useState)(function () {
172
+ return !isLazy || cardPreview && !(0, _getCardPreview.isSSRPreview)(cardPreview);
173
+ }),
174
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
175
+ isCardVisible = _useState6[0],
176
+ setIsCardVisible = _useState6[1];
177
+ var _useFileState = (0, _mediaClientReact.useFileState)(identifier.id, {
178
+ skipRemote: !isCardVisible,
179
+ collectionName: identifier.collectionName,
180
+ occurrenceKey: identifier.occurrenceKey
181
+ }),
182
+ fileState = _useFileState.fileState;
183
+ var prevFileState = (0, _usePrevious.usePrevious)(fileState);
184
+ var fileStateValue = (0, _react.useMemo)(function () {
185
+ if (fileState && (fileState === null || fileState === void 0 ? void 0 : fileState.status) !== 'error') {
186
+ return fileState;
187
+ }
188
+ return prevFileState;
189
+ // eslint-disable-next-line react-hooks/exhaustive-deps
190
+ }, [fileState]);
175
191
 
176
192
  //----------------------------------------------------------------//
177
193
  //------------ State, Refs & Initial Values ----------------------//
@@ -194,28 +210,13 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
194
210
  traceId: (0, _mediaCommon.getRandomHex)(8)
195
211
  };
196
212
  }, []);
197
- var _useState3 = (0, _react.useState)('loading'),
198
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
199
- status = _useState4[0],
200
- setStatus = _useState4[1];
213
+ var _useState7 = (0, _react.useState)('loading'),
214
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
215
+ status = _useState8[0],
216
+ setStatus = _useState8[1];
201
217
  (0, _react.useEffect)(function () {
202
218
  setStatus('loading');
203
219
  }, [identifier]);
204
- var _useState5 = (0, _react.useState)(cardPreviewInitializer),
205
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
206
- cardPreview = _useState6[0],
207
- setCardPreview = _useState6[1];
208
-
209
- // If cardPreview is available from local cache or external, `isCardVisible`
210
- // should be true to avoid flickers during re-mount of the component
211
- // should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
212
- // outside the viewport
213
- var _useState7 = (0, _react.useState)(function () {
214
- return !isLazy || !!cardPreview && !(0, _getCardPreview.isSSRPreview)(cardPreview);
215
- }),
216
- _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
217
- isCardVisible = _useState8[0],
218
- setIsCardVisible = _useState8[1];
219
220
  var _useState9 = (0, _react.useState)(false),
220
221
  _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
221
222
  isPlayingFile = _useState10[0],
@@ -440,11 +441,11 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
440
441
  //----------------------------------------------------------------//
441
442
 
442
443
  var fetchRemotePreviewRef = (0, _useCurrentValueRef.useCurrentValueRef)(function (identifier) {
443
- return (0, _getCardPreview.fetchAndCacheRemotePreview)(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs);
444
+ return (0, _getCardPreview.fetchAndCacheRemotePreview)(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, getMediaBlobUrlAttrs(fileStateValue));
444
445
  });
445
446
  var resolvePreviewRef = (0, _useCurrentValueRef.useCurrentValueRef)( /*#__PURE__*/function () {
446
447
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(identifier, fileState) {
447
- var filePreview, isRemotePreviewReady, mode, cachedPreview, dimensionsAreBigger, localPreview, value, resolvedFilePreview, _value, type, mediaType, orientation, _dataURI, _dataURI2, preview, source, dataURI, remotePreview, wrappedError;
448
+ var filePreview, isRemotePreviewReady, mode, cachedPreview, dimensionsAreBigger, localPreview, value, resolvedFilePreview, _value, type, mediaType, orientation, _dataURI, _dataURI2, preview, source, mediaBlobUrlAttrs, dataURI, remotePreview, wrappedError;
448
449
  return _regenerator.default.wrap(function _callee$(_context) {
449
450
  while (1) switch (_context.prev = _context.next) {
450
451
  case 0:
@@ -462,7 +463,7 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
462
463
  case 8:
463
464
  _context.prev = 8;
464
465
  if (!filePreview) {
465
- _context.next = 74;
466
+ _context.next = 75;
466
467
  break;
467
468
  }
468
469
  _context.prev = 10;
@@ -568,6 +569,7 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
568
569
  source = preview.source;
569
570
  case 70:
570
571
  // We want to embed some meta context into dataURI for Copy/Paste to work.
572
+ mediaBlobUrlAttrs = getMediaBlobUrlAttrs(fileStateValue);
571
573
  dataURI = mediaBlobUrlAttrs ? (0, _mediaClient.addFileAttrsToUrl)(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI; // We store new cardPreview into cache
572
574
  _cache.default.set(identifier.id, mode, _objectSpread(_objectSpread({}, preview), {}, {
573
575
  source: source,
@@ -577,11 +579,11 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
577
579
  dataURI: dataURI
578
580
  }));
579
581
  return _context.abrupt("return");
580
- case 74:
581
- _context.next = 81;
582
+ case 75:
583
+ _context.next = 82;
582
584
  break;
583
- case 76:
584
- _context.prev = 76;
585
+ case 77:
586
+ _context.prev = 77;
585
587
  _context.t5 = _context["catch"](8);
586
588
  /**
587
589
  * We report the error if:
@@ -601,25 +603,25 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
601
603
  * if there is no remote preview available
602
604
  */
603
605
  if (isRemotePreviewReady) {
604
- _context.next = 81;
606
+ _context.next = 82;
605
607
  break;
606
608
  }
607
609
  throw _context.t5;
608
- case 81:
610
+ case 82:
609
611
  if (isRemotePreviewReady) {
610
- _context.next = 83;
612
+ _context.next = 84;
611
613
  break;
612
614
  }
613
615
  throw new _errors.MediaCardError('remote-preview-not-ready');
614
- case 83:
615
- _context.next = 85;
616
- return (0, _getCardPreview.fetchAndCacheRemotePreview)(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
617
- case 85:
616
+ case 84:
617
+ _context.next = 86;
618
+ return (0, _getCardPreview.fetchAndCacheRemotePreview)(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, getMediaBlobUrlAttrs(fileStateValue), traceContext);
619
+ case 86:
618
620
  remotePreview = _context.sent;
619
621
  setCardPreview(remotePreview);
620
622
  return _context.abrupt("return");
621
- case 90:
622
- _context.prev = 90;
623
+ case 91:
624
+ _context.prev = 91;
623
625
  _context.t6 = _context["catch"](2);
624
626
  wrappedError = (0, _errors.ensureMediaCardError)('preview-fetch', _context.t6); // If remote preview fails, we set status 'error'
625
627
  // If local preview fails (i.e, no remote preview available),
@@ -634,11 +636,11 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
634
636
  setError(wrappedError);
635
637
  }
636
638
  }
637
- case 94:
639
+ case 95:
638
640
  case "end":
639
641
  return _context.stop();
640
642
  }
641
- }, _callee, null, [[2, 90], [8, 76], [10, 17], [30, 38], [42, 49]]);
643
+ }, _callee, null, [[2, 91], [8, 77], [10, 17], [30, 38], [42, 49]]);
642
644
  }));
643
645
  return function (_x, _x2) {
644
646
  return _ref2.apply(this, arguments);
@@ -811,10 +813,16 @@ var FileCard = exports.FileCard = function FileCard(_ref) {
811
813
  var _getFileDetails2 = (0, _metadata.getFileDetails)(identifier, fileStateValue),
812
814
  mimeType = _getFileDetails2.mimeType;
813
815
  var isVideoPlayable = (0, _videoIsPlayable.videoIsPlayable)(isBannedLocalPreview, fileStateValue, mimeType);
814
- if (isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && isVideoPlayable) {
816
+ if (
817
+ /**
818
+ * We need to check that the card is visible before switching to inline player
819
+ * in order to avoid race conditions of the ViewportDector being unmounted before
820
+ * it is able to set isCardVisible to true.
821
+ */
822
+ isCardVisible && isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && isVideoPlayable) {
815
823
  setIsPlayingFile(true);
816
824
  }
817
- }, [disableOverlay, fileAttributes.fileMediatype, fileStateValue, identifier, isBannedLocalPreview, isPlayingFile, useInlinePlayer]);
825
+ }, [isCardVisible, disableOverlay, fileAttributes.fileMediatype, fileStateValue, identifier, isBannedLocalPreview, isPlayingFile, useInlinePlayer]);
818
826
 
819
827
  //----------------------------------------------------------------//
820
828
  //----------------- fireScreenEvent ------------------------------//
@@ -119,7 +119,7 @@ var MediaInlineCardLoader = exports.default = /*#__PURE__*/function (_React$Pure
119
119
  ErrorBoundary = _this$state.ErrorBoundary;
120
120
  var analyticsContext = {
121
121
  packageVersion: "@atlaskit/media-card",
122
- packageName: "77.4.0",
122
+ packageName: "77.4.2",
123
123
  componentName: 'mediaInlineCard',
124
124
  component: 'mediaInlineCard'
125
125
  };
@@ -14,7 +14,7 @@ var _mediaClient = require("@atlaskit/media-client");
14
14
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
15
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
16
  var packageName = "@atlaskit/media-card";
17
- var packageVersion = "77.4.0";
17
+ var packageVersion = "77.4.2";
18
18
  var concurrentExperience;
19
19
  var getExperience = function getExperience(id) {
20
20
  if (!concurrentExperience) {
@@ -27,7 +27,7 @@ import { getMediaCardCursor } from '../utils/getMediaCardCursor';
27
27
  import { completeUfoExperience, startUfoExperience, abortUfoExperience } from '../utils/ufoExperiences';
28
28
  import { generateUniqueId } from '../utils/generateUniqueId';
29
29
  const packageName = "@atlaskit/media-card";
30
- const packageVersion = "77.4.0";
30
+ const packageVersion = "77.4.2";
31
31
  export class CardBase extends Component {
32
32
  constructor(props) {
33
33
  super(props);
@@ -66,7 +66,7 @@ class WrappedMediaCardAnalyticsErrorBoundary extends React.Component {
66
66
  }
67
67
  _defineProperty(WrappedMediaCardAnalyticsErrorBoundary, "displayName", 'MediaCardAnalyticsErrorBoundary');
68
68
  const packageName = "@atlaskit/media-card";
69
- const packageVersion = "77.4.0";
69
+ const packageVersion = "77.4.2";
70
70
  const MediaCardAnalyticsErrorBoundary = withMediaAnalyticsContext({
71
71
  packageVersion,
72
72
  packageName,
@@ -7,7 +7,7 @@ import { IntlProvider, injectIntl } from 'react-intl-next';
7
7
  import { ExternalImageCard } from './externalImageCard';
8
8
  import { FileCard } from './fileCard';
9
9
  const packageName = "@atlaskit/media-card";
10
- const packageVersion = "77.4.0";
10
+ const packageVersion = "77.4.2";
11
11
  export const CardV2Base = ({
12
12
  identifier,
13
13
  ...otherProps
@@ -4,7 +4,7 @@ import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react'
4
4
  import { getMediaTypeFromMimeType, getRandomHex, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
5
5
  import { getOrientation } from '@atlaskit/media-ui';
6
6
  import { MediaViewer } from '@atlaskit/media-viewer';
7
- import React, { Suspense, useEffect, useMemo, useRef, useState } from 'react';
7
+ import React, { Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';
8
8
  import ReactDOM from 'react-dom';
9
9
  import { ImageLoadError, LocalPreviewError, MediaCardError, ensureMediaCardError, isLocalPreviewError, isUnsupportedLocalPreviewError } from '../../errors';
10
10
  import { extractErrorInfo } from '../../utils/analytics';
@@ -61,20 +61,6 @@ export const FileCard = ({
61
61
  //---------------- State Initializer Functions -------------------//
62
62
  //----------------------------------------------------------------//
63
63
 
64
- const {
65
- fileState
66
- } = useFileState(identifier.id, {
67
- collectionName: identifier.collectionName,
68
- occurrenceKey: identifier.occurrenceKey
69
- });
70
- const prevFileState = usePrevious(fileState);
71
- const fileStateValue = useMemo(() => {
72
- if (fileState && (fileState === null || fileState === void 0 ? void 0 : fileState.status) !== 'error') {
73
- return fileState;
74
- }
75
- return prevFileState;
76
- // eslint-disable-next-line react-hooks/exhaustive-deps
77
- }, [fileState]);
78
64
  const ssrDataRef = useRef();
79
65
  const ssrReliabilityRef = useRef({
80
66
  server: {
@@ -94,7 +80,7 @@ export const FileCard = ({
94
80
  }),
95
81
  allowAnimated: true
96
82
  }), [cardElement, dimensions, identifier.collectionName, resizeMode]);
97
- const mediaBlobUrlAttrs = useMemo(() => {
83
+ const getMediaBlobUrlAttrs = useCallback(fileState => {
98
84
  const {
99
85
  id,
100
86
  collectionName: collection
@@ -103,7 +89,7 @@ export const FileCard = ({
103
89
  mimeType,
104
90
  name,
105
91
  size
106
- } = getFileDetails(identifier, fileStateValue);
92
+ } = getFileDetails(identifier, fileState);
107
93
  return contextId ? {
108
94
  id,
109
95
  collection,
@@ -117,7 +103,7 @@ export const FileCard = ({
117
103
  })),
118
104
  alt
119
105
  } : undefined;
120
- }, [alt, cardElement, contextId, dimensions, fileStateValue, identifier, originalDimensions]);
106
+ }, [alt, cardElement, contextId, dimensions, identifier, originalDimensions]);
121
107
  const getSSRPreview = (ssr, identifier, mediaClient) => {
122
108
  var _ssrDataRef$current, _ssrDataRef$current2;
123
109
  ssrDataRef.current = getSSRData(identifier);
@@ -129,7 +115,7 @@ export const FileCard = ({
129
115
  }
130
116
  if (!((_ssrDataRef$current2 = ssrDataRef.current) !== null && _ssrDataRef$current2 !== void 0 && _ssrDataRef$current2.dataURI)) {
131
117
  try {
132
- return getSSRCardPreview(ssr, mediaClient, identifier.id, imageURLParams, mediaBlobUrlAttrs);
118
+ return getSSRCardPreview(ssr, mediaClient, identifier.id, imageURLParams, getMediaBlobUrlAttrs(fileStateValue));
133
119
  } catch (e) {
134
120
  ssrReliabilityRef.current[ssr] = {
135
121
  status: 'fail',
@@ -155,6 +141,28 @@ export const FileCard = ({
155
141
  }
156
142
  return cardPreview;
157
143
  };
144
+ const [cardPreview, setCardPreview] = useState(cardPreviewInitializer);
145
+
146
+ // If cardPreview is available from local cache or external, `isCardVisible`
147
+ // should be true to avoid flickers during re-mount of the component
148
+ // should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
149
+ // outside the viewport
150
+ const [isCardVisible, setIsCardVisible] = useState(() => !isLazy || cardPreview && !isSSRPreview(cardPreview));
151
+ const {
152
+ fileState
153
+ } = useFileState(identifier.id, {
154
+ skipRemote: !isCardVisible,
155
+ collectionName: identifier.collectionName,
156
+ occurrenceKey: identifier.occurrenceKey
157
+ });
158
+ const prevFileState = usePrevious(fileState);
159
+ const fileStateValue = useMemo(() => {
160
+ if (fileState && (fileState === null || fileState === void 0 ? void 0 : fileState.status) !== 'error') {
161
+ return fileState;
162
+ }
163
+ return prevFileState;
164
+ // eslint-disable-next-line react-hooks/exhaustive-deps
165
+ }, [fileState]);
158
166
 
159
167
  //----------------------------------------------------------------//
160
168
  //------------ State, Refs & Initial Values ----------------------//
@@ -175,13 +183,6 @@ export const FileCard = ({
175
183
  useEffect(() => {
176
184
  setStatus('loading');
177
185
  }, [identifier]);
178
- const [cardPreview, setCardPreview] = useState(cardPreviewInitializer);
179
-
180
- // If cardPreview is available from local cache or external, `isCardVisible`
181
- // should be true to avoid flickers during re-mount of the component
182
- // should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
183
- // outside the viewport
184
- const [isCardVisible, setIsCardVisible] = useState(() => !isLazy || !!cardPreview && !isSSRPreview(cardPreview));
185
186
  const [isPlayingFile, setIsPlayingFile] = useState(false);
186
187
  const [shouldAutoplay, setShouldAutoplay] = useState(false);
187
188
  const [isBannedLocalPreview, setIsBannedLocalPreview] = useState(false);
@@ -387,7 +388,7 @@ export const FileCard = ({
387
388
  //----------------------------------------------------------------//
388
389
 
389
390
  const fetchRemotePreviewRef = useCurrentValueRef(identifier => {
390
- return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs);
391
+ return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, getMediaBlobUrlAttrs(fileStateValue));
391
392
  });
392
393
  const resolvePreviewRef = useCurrentValueRef(async (identifier, fileState) => {
393
394
  const filePreview = isBannedLocalPreview ? undefined : fileState.status !== 'error' && 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) ? fileState.preview : undefined;
@@ -474,6 +475,7 @@ export const FileCard = ({
474
475
  source = preview.source;
475
476
  }
476
477
  // We want to embed some meta context into dataURI for Copy/Paste to work.
478
+ const mediaBlobUrlAttrs = getMediaBlobUrlAttrs(fileStateValue);
477
479
  const dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI;
478
480
  // We store new cardPreview into cache
479
481
  cardPreviewCache.set(identifier.id, mode, {
@@ -518,7 +520,7 @@ export const FileCard = ({
518
520
  */
519
521
  throw new MediaCardError('remote-preview-not-ready');
520
522
  }
521
- const remotePreview = await fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
523
+ const remotePreview = await fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, getMediaBlobUrlAttrs(fileStateValue), traceContext);
522
524
  setCardPreview(remotePreview);
523
525
  return;
524
526
  } catch (e) {
@@ -691,10 +693,16 @@ export const FileCard = ({
691
693
  mimeType
692
694
  } = getFileDetails(identifier, fileStateValue);
693
695
  const isVideoPlayable = videoIsPlayable(isBannedLocalPreview, fileStateValue, mimeType);
694
- if (isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && isVideoPlayable) {
696
+ if (
697
+ /**
698
+ * We need to check that the card is visible before switching to inline player
699
+ * in order to avoid race conditions of the ViewportDector being unmounted before
700
+ * it is able to set isCardVisible to true.
701
+ */
702
+ isCardVisible && isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && isVideoPlayable) {
695
703
  setIsPlayingFile(true);
696
704
  }
697
- }, [disableOverlay, fileAttributes.fileMediatype, fileStateValue, identifier, isBannedLocalPreview, isPlayingFile, useInlinePlayer]);
705
+ }, [isCardVisible, disableOverlay, fileAttributes.fileMediatype, fileStateValue, identifier, isBannedLocalPreview, isPlayingFile, useInlinePlayer]);
698
706
 
699
707
  //----------------------------------------------------------------//
700
708
  //----------------- fireScreenEvent ------------------------------//
@@ -37,7 +37,7 @@ export default class MediaInlineCardLoader extends React.PureComponent {
37
37
  } = this.state;
38
38
  const analyticsContext = {
39
39
  packageVersion: "@atlaskit/media-card",
40
- packageName: "77.4.0",
40
+ packageName: "77.4.2",
41
41
  componentName: 'mediaInlineCard',
42
42
  component: 'mediaInlineCard'
43
43
  };
@@ -4,7 +4,7 @@ import { extractErrorInfo, getRenderErrorRequestMetadata } from './analytics';
4
4
  import { MediaCardError } from '../errors';
5
5
  import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
6
6
  const packageName = "@atlaskit/media-card";
7
- const packageVersion = "77.4.0";
7
+ const packageVersion = "77.4.2";
8
8
  let concurrentExperience;
9
9
  const getExperience = id => {
10
10
  if (!concurrentExperience) {
@@ -40,7 +40,7 @@ import { getMediaCardCursor } from '../utils/getMediaCardCursor';
40
40
  import { completeUfoExperience, startUfoExperience, abortUfoExperience } from '../utils/ufoExperiences';
41
41
  import { generateUniqueId } from '../utils/generateUniqueId';
42
42
  var packageName = "@atlaskit/media-card";
43
- var packageVersion = "77.4.0";
43
+ var packageVersion = "77.4.2";
44
44
  export var CardBase = /*#__PURE__*/function (_Component) {
45
45
  _inherits(CardBase, _Component);
46
46
  var _super = _createSuper(CardBase);
@@ -83,7 +83,7 @@ var WrappedMediaCardAnalyticsErrorBoundary = /*#__PURE__*/function (_React$Compo
83
83
  }(React.Component);
84
84
  _defineProperty(WrappedMediaCardAnalyticsErrorBoundary, "displayName", 'MediaCardAnalyticsErrorBoundary');
85
85
  var packageName = "@atlaskit/media-card";
86
- var packageVersion = "77.4.0";
86
+ var packageVersion = "77.4.2";
87
87
  var MediaCardAnalyticsErrorBoundary = withMediaAnalyticsContext({
88
88
  packageVersion: packageVersion,
89
89
  packageName: packageName,
@@ -9,7 +9,7 @@ import { IntlProvider, injectIntl } from 'react-intl-next';
9
9
  import { ExternalImageCard } from './externalImageCard';
10
10
  import { FileCard } from './fileCard';
11
11
  var packageName = "@atlaskit/media-card";
12
- var packageVersion = "77.4.0";
12
+ var packageVersion = "77.4.2";
13
13
  export var CardV2Base = function CardV2Base(_ref) {
14
14
  var identifier = _ref.identifier,
15
15
  otherProps = _objectWithoutProperties(_ref, _excluded);
@@ -11,7 +11,7 @@ import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react'
11
11
  import { getMediaTypeFromMimeType, getRandomHex, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
12
12
  import { getOrientation } from '@atlaskit/media-ui';
13
13
  import { MediaViewer } from '@atlaskit/media-viewer';
14
- import React, { Suspense, useEffect, useMemo, useRef, useState } from 'react';
14
+ import React, { Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';
15
15
  import ReactDOM from 'react-dom';
16
16
  import { ImageLoadError, LocalPreviewError, MediaCardError, ensureMediaCardError, isLocalPreviewError, isUnsupportedLocalPreviewError } from '../../errors';
17
17
  import { extractErrorInfo } from '../../utils/analytics';
@@ -71,19 +71,6 @@ export var FileCard = function FileCard(_ref) {
71
71
  //---------------- State Initializer Functions -------------------//
72
72
  //----------------------------------------------------------------//
73
73
 
74
- var _useFileState = useFileState(identifier.id, {
75
- collectionName: identifier.collectionName,
76
- occurrenceKey: identifier.occurrenceKey
77
- }),
78
- fileState = _useFileState.fileState;
79
- var prevFileState = usePrevious(fileState);
80
- var fileStateValue = useMemo(function () {
81
- if (fileState && (fileState === null || fileState === void 0 ? void 0 : fileState.status) !== 'error') {
82
- return fileState;
83
- }
84
- return prevFileState;
85
- // eslint-disable-next-line react-hooks/exhaustive-deps
86
- }, [fileState]);
87
74
  var ssrDataRef = useRef();
88
75
  var ssrReliabilityRef = useRef({
89
76
  server: {
@@ -108,10 +95,10 @@ export var FileCard = function FileCard(_ref) {
108
95
  allowAnimated: true
109
96
  });
110
97
  }, [cardElement, dimensions, identifier.collectionName, resizeMode]);
111
- var mediaBlobUrlAttrs = useMemo(function () {
98
+ var getMediaBlobUrlAttrs = useCallback(function (fileState) {
112
99
  var id = identifier.id,
113
100
  collection = identifier.collectionName;
114
- var _getFileDetails = getFileDetails(identifier, fileStateValue),
101
+ var _getFileDetails = getFileDetails(identifier, fileState),
115
102
  mimeType = _getFileDetails.mimeType,
116
103
  name = _getFileDetails.name,
117
104
  size = _getFileDetails.size;
@@ -128,7 +115,7 @@ export var FileCard = function FileCard(_ref) {
128
115
  })), {}, {
129
116
  alt: alt
130
117
  }) : undefined;
131
- }, [alt, cardElement, contextId, dimensions, fileStateValue, identifier, originalDimensions]);
118
+ }, [alt, cardElement, contextId, dimensions, identifier, originalDimensions]);
132
119
  var getSSRPreview = function getSSRPreview(ssr, identifier, mediaClient) {
133
120
  var _ssrDataRef$current, _ssrDataRef$current2;
134
121
  ssrDataRef.current = getSSRData(identifier);
@@ -139,7 +126,7 @@ export var FileCard = function FileCard(_ref) {
139
126
  }
140
127
  if (!((_ssrDataRef$current2 = ssrDataRef.current) !== null && _ssrDataRef$current2 !== void 0 && _ssrDataRef$current2.dataURI)) {
141
128
  try {
142
- return getSSRCardPreview(ssr, mediaClient, identifier.id, imageURLParams, mediaBlobUrlAttrs);
129
+ return getSSRCardPreview(ssr, mediaClient, identifier.id, imageURLParams, getMediaBlobUrlAttrs(fileStateValue));
143
130
  } catch (e) {
144
131
  ssrReliabilityRef.current[ssr] = _objectSpread({
145
132
  status: 'fail'
@@ -162,6 +149,35 @@ export var FileCard = function FileCard(_ref) {
162
149
  }
163
150
  return cardPreview;
164
151
  };
152
+ var _useState3 = useState(cardPreviewInitializer),
153
+ _useState4 = _slicedToArray(_useState3, 2),
154
+ cardPreview = _useState4[0],
155
+ setCardPreview = _useState4[1];
156
+
157
+ // If cardPreview is available from local cache or external, `isCardVisible`
158
+ // should be true to avoid flickers during re-mount of the component
159
+ // should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
160
+ // outside the viewport
161
+ var _useState5 = useState(function () {
162
+ return !isLazy || cardPreview && !isSSRPreview(cardPreview);
163
+ }),
164
+ _useState6 = _slicedToArray(_useState5, 2),
165
+ isCardVisible = _useState6[0],
166
+ setIsCardVisible = _useState6[1];
167
+ var _useFileState = useFileState(identifier.id, {
168
+ skipRemote: !isCardVisible,
169
+ collectionName: identifier.collectionName,
170
+ occurrenceKey: identifier.occurrenceKey
171
+ }),
172
+ fileState = _useFileState.fileState;
173
+ var prevFileState = usePrevious(fileState);
174
+ var fileStateValue = useMemo(function () {
175
+ if (fileState && (fileState === null || fileState === void 0 ? void 0 : fileState.status) !== 'error') {
176
+ return fileState;
177
+ }
178
+ return prevFileState;
179
+ // eslint-disable-next-line react-hooks/exhaustive-deps
180
+ }, [fileState]);
165
181
 
166
182
  //----------------------------------------------------------------//
167
183
  //------------ State, Refs & Initial Values ----------------------//
@@ -184,28 +200,13 @@ export var FileCard = function FileCard(_ref) {
184
200
  traceId: getRandomHex(8)
185
201
  };
186
202
  }, []);
187
- var _useState3 = useState('loading'),
188
- _useState4 = _slicedToArray(_useState3, 2),
189
- status = _useState4[0],
190
- setStatus = _useState4[1];
203
+ var _useState7 = useState('loading'),
204
+ _useState8 = _slicedToArray(_useState7, 2),
205
+ status = _useState8[0],
206
+ setStatus = _useState8[1];
191
207
  useEffect(function () {
192
208
  setStatus('loading');
193
209
  }, [identifier]);
194
- var _useState5 = useState(cardPreviewInitializer),
195
- _useState6 = _slicedToArray(_useState5, 2),
196
- cardPreview = _useState6[0],
197
- setCardPreview = _useState6[1];
198
-
199
- // If cardPreview is available from local cache or external, `isCardVisible`
200
- // should be true to avoid flickers during re-mount of the component
201
- // should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
202
- // outside the viewport
203
- var _useState7 = useState(function () {
204
- return !isLazy || !!cardPreview && !isSSRPreview(cardPreview);
205
- }),
206
- _useState8 = _slicedToArray(_useState7, 2),
207
- isCardVisible = _useState8[0],
208
- setIsCardVisible = _useState8[1];
209
210
  var _useState9 = useState(false),
210
211
  _useState10 = _slicedToArray(_useState9, 2),
211
212
  isPlayingFile = _useState10[0],
@@ -430,11 +431,11 @@ export var FileCard = function FileCard(_ref) {
430
431
  //----------------------------------------------------------------//
431
432
 
432
433
  var fetchRemotePreviewRef = useCurrentValueRef(function (identifier) {
433
- return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs);
434
+ return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, getMediaBlobUrlAttrs(fileStateValue));
434
435
  });
435
436
  var resolvePreviewRef = useCurrentValueRef( /*#__PURE__*/function () {
436
437
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(identifier, fileState) {
437
- var filePreview, isRemotePreviewReady, mode, cachedPreview, dimensionsAreBigger, localPreview, value, resolvedFilePreview, _value, type, mediaType, orientation, _dataURI, _dataURI2, preview, source, dataURI, remotePreview, wrappedError;
438
+ var filePreview, isRemotePreviewReady, mode, cachedPreview, dimensionsAreBigger, localPreview, value, resolvedFilePreview, _value, type, mediaType, orientation, _dataURI, _dataURI2, preview, source, mediaBlobUrlAttrs, dataURI, remotePreview, wrappedError;
438
439
  return _regeneratorRuntime.wrap(function _callee$(_context) {
439
440
  while (1) switch (_context.prev = _context.next) {
440
441
  case 0:
@@ -452,7 +453,7 @@ export var FileCard = function FileCard(_ref) {
452
453
  case 8:
453
454
  _context.prev = 8;
454
455
  if (!filePreview) {
455
- _context.next = 74;
456
+ _context.next = 75;
456
457
  break;
457
458
  }
458
459
  _context.prev = 10;
@@ -558,6 +559,7 @@ export var FileCard = function FileCard(_ref) {
558
559
  source = preview.source;
559
560
  case 70:
560
561
  // We want to embed some meta context into dataURI for Copy/Paste to work.
562
+ mediaBlobUrlAttrs = getMediaBlobUrlAttrs(fileStateValue);
561
563
  dataURI = mediaBlobUrlAttrs ? addFileAttrsToUrl(preview.dataURI, mediaBlobUrlAttrs) : preview.dataURI; // We store new cardPreview into cache
562
564
  cardPreviewCache.set(identifier.id, mode, _objectSpread(_objectSpread({}, preview), {}, {
563
565
  source: source,
@@ -567,11 +569,11 @@ export var FileCard = function FileCard(_ref) {
567
569
  dataURI: dataURI
568
570
  }));
569
571
  return _context.abrupt("return");
570
- case 74:
571
- _context.next = 81;
572
+ case 75:
573
+ _context.next = 82;
572
574
  break;
573
- case 76:
574
- _context.prev = 76;
575
+ case 77:
576
+ _context.prev = 77;
575
577
  _context.t5 = _context["catch"](8);
576
578
  /**
577
579
  * We report the error if:
@@ -591,25 +593,25 @@ export var FileCard = function FileCard(_ref) {
591
593
  * if there is no remote preview available
592
594
  */
593
595
  if (isRemotePreviewReady) {
594
- _context.next = 81;
596
+ _context.next = 82;
595
597
  break;
596
598
  }
597
599
  throw _context.t5;
598
- case 81:
600
+ case 82:
599
601
  if (isRemotePreviewReady) {
600
- _context.next = 83;
602
+ _context.next = 84;
601
603
  break;
602
604
  }
603
605
  throw new MediaCardError('remote-preview-not-ready');
604
- case 83:
605
- _context.next = 85;
606
- return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
607
- case 85:
606
+ case 84:
607
+ _context.next = 86;
608
+ return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, getMediaBlobUrlAttrs(fileStateValue), traceContext);
609
+ case 86:
608
610
  remotePreview = _context.sent;
609
611
  setCardPreview(remotePreview);
610
612
  return _context.abrupt("return");
611
- case 90:
612
- _context.prev = 90;
613
+ case 91:
614
+ _context.prev = 91;
613
615
  _context.t6 = _context["catch"](2);
614
616
  wrappedError = ensureMediaCardError('preview-fetch', _context.t6); // If remote preview fails, we set status 'error'
615
617
  // If local preview fails (i.e, no remote preview available),
@@ -624,11 +626,11 @@ export var FileCard = function FileCard(_ref) {
624
626
  setError(wrappedError);
625
627
  }
626
628
  }
627
- case 94:
629
+ case 95:
628
630
  case "end":
629
631
  return _context.stop();
630
632
  }
631
- }, _callee, null, [[2, 90], [8, 76], [10, 17], [30, 38], [42, 49]]);
633
+ }, _callee, null, [[2, 91], [8, 77], [10, 17], [30, 38], [42, 49]]);
632
634
  }));
633
635
  return function (_x, _x2) {
634
636
  return _ref2.apply(this, arguments);
@@ -801,10 +803,16 @@ export var FileCard = function FileCard(_ref) {
801
803
  var _getFileDetails2 = getFileDetails(identifier, fileStateValue),
802
804
  mimeType = _getFileDetails2.mimeType;
803
805
  var isVideoPlayable = videoIsPlayable(isBannedLocalPreview, fileStateValue, mimeType);
804
- if (isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && isVideoPlayable) {
806
+ if (
807
+ /**
808
+ * We need to check that the card is visible before switching to inline player
809
+ * in order to avoid race conditions of the ViewportDector being unmounted before
810
+ * it is able to set isCardVisible to true.
811
+ */
812
+ isCardVisible && isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && isVideoPlayable) {
805
813
  setIsPlayingFile(true);
806
814
  }
807
- }, [disableOverlay, fileAttributes.fileMediatype, fileStateValue, identifier, isBannedLocalPreview, isPlayingFile, useInlinePlayer]);
815
+ }, [isCardVisible, disableOverlay, fileAttributes.fileMediatype, fileStateValue, identifier, isBannedLocalPreview, isPlayingFile, useInlinePlayer]);
808
816
 
809
817
  //----------------------------------------------------------------//
810
818
  //----------------- fireScreenEvent ------------------------------//
@@ -103,7 +103,7 @@ var MediaInlineCardLoader = /*#__PURE__*/function (_React$PureComponent) {
103
103
  ErrorBoundary = _this$state.ErrorBoundary;
104
104
  var analyticsContext = {
105
105
  packageVersion: "@atlaskit/media-card",
106
- packageName: "77.4.0",
106
+ packageName: "77.4.2",
107
107
  componentName: 'mediaInlineCard',
108
108
  component: 'mediaInlineCard'
109
109
  };
@@ -7,7 +7,7 @@ import { extractErrorInfo, getRenderErrorRequestMetadata } from './analytics';
7
7
  import { MediaCardError } from '../errors';
8
8
  import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
9
9
  var packageName = "@atlaskit/media-card";
10
- var packageVersion = "77.4.0";
10
+ var packageVersion = "77.4.2";
11
11
  var concurrentExperience;
12
12
  var getExperience = function getExperience(id) {
13
13
  if (!concurrentExperience) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-card",
3
- "version": "77.4.0",
3
+ "version": "77.4.2",
4
4
  "description": "Includes all media card related components, CardView, CardViewSmall, Card...",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -49,7 +49,7 @@
49
49
  "@atlaskit/spinner": "^15.6.0",
50
50
  "@atlaskit/theme": "^12.6.0",
51
51
  "@atlaskit/tokens": "^1.28.0",
52
- "@atlaskit/tooltip": "^17.8.0",
52
+ "@atlaskit/tooltip": "^18.0.0",
53
53
  "@atlaskit/ufo": "^0.2.0",
54
54
  "@babel/runtime": "^7.0.0",
55
55
  "classnames": "^2.2.5",