@atlaskit/media-card 77.4.7 → 77.4.9

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 (77) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/card/card.js +1 -1
  3. package/dist/cjs/card/cardView.js +11 -7
  4. package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
  5. package/dist/cjs/card/ui/titleBox/styles.js +2 -18
  6. package/dist/cjs/card/ui/titleBox/titleBoxComponents.js +1 -4
  7. package/dist/cjs/card/ui/wrapper/styles.js +2 -10
  8. package/dist/cjs/card/ui/wrapper/wrapper.js +1 -4
  9. package/dist/cjs/card/v2/cardV2.js +1 -1
  10. package/dist/cjs/card/v2/cardViewV2.js +0 -3
  11. package/dist/cjs/card/v2/externalImageCard.js +3 -3
  12. package/dist/cjs/card/v2/fileCard.js +16 -15
  13. package/dist/cjs/card/v2/useFilePreview.js +44 -20
  14. package/dist/cjs/inline/loader.js +1 -1
  15. package/dist/cjs/utils/getDataURIDimension.js +38 -1
  16. package/dist/cjs/utils/lightCards/lightCardWrappers.js +1 -4
  17. package/dist/cjs/utils/lightCards/styles.js +2 -14
  18. package/dist/cjs/utils/ufoExperiences.js +1 -1
  19. package/dist/es2019/card/card.js +1 -1
  20. package/dist/es2019/card/cardView.js +6 -1
  21. package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
  22. package/dist/es2019/card/ui/titleBox/styles.js +3 -19
  23. package/dist/es2019/card/ui/titleBox/titleBoxComponents.js +1 -4
  24. package/dist/es2019/card/ui/wrapper/styles.js +2 -10
  25. package/dist/es2019/card/ui/wrapper/wrapper.js +1 -4
  26. package/dist/es2019/card/v2/cardV2.js +1 -1
  27. package/dist/es2019/card/v2/cardViewV2.js +0 -2
  28. package/dist/es2019/card/v2/externalImageCard.js +3 -3
  29. package/dist/es2019/card/v2/fileCard.js +18 -17
  30. package/dist/es2019/card/v2/useFilePreview.js +46 -21
  31. package/dist/es2019/inline/loader.js +1 -1
  32. package/dist/es2019/utils/getDataURIDimension.js +39 -0
  33. package/dist/es2019/utils/lightCards/lightCardWrappers.js +1 -4
  34. package/dist/es2019/utils/lightCards/styles.js +4 -16
  35. package/dist/es2019/utils/ufoExperiences.js +1 -1
  36. package/dist/esm/card/card.js +1 -1
  37. package/dist/esm/card/cardView.js +11 -7
  38. package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
  39. package/dist/esm/card/ui/titleBox/styles.js +2 -18
  40. package/dist/esm/card/ui/titleBox/titleBoxComponents.js +1 -4
  41. package/dist/esm/card/ui/wrapper/styles.js +2 -10
  42. package/dist/esm/card/ui/wrapper/wrapper.js +1 -4
  43. package/dist/esm/card/v2/cardV2.js +1 -1
  44. package/dist/esm/card/v2/cardViewV2.js +0 -3
  45. package/dist/esm/card/v2/externalImageCard.js +3 -3
  46. package/dist/esm/card/v2/fileCard.js +18 -17
  47. package/dist/esm/card/v2/useFilePreview.js +45 -21
  48. package/dist/esm/inline/loader.js +1 -1
  49. package/dist/esm/utils/getDataURIDimension.js +38 -0
  50. package/dist/esm/utils/lightCards/lightCardWrappers.js +1 -4
  51. package/dist/esm/utils/lightCards/styles.js +3 -15
  52. package/dist/esm/utils/ufoExperiences.js +1 -1
  53. package/dist/types/card/ui/titleBox/styles.d.ts +1 -1
  54. package/dist/types/card/ui/titleBox/types.d.ts +0 -2
  55. package/dist/types/card/ui/wrapper/styles.d.ts +1 -1
  56. package/dist/types/card/ui/wrapper/types.d.ts +0 -2
  57. package/dist/types/card/v2/cardViewV2.d.ts +17 -6
  58. package/dist/types/card/v2/fileCard.d.ts +40 -6
  59. package/dist/types/card/v2/useFilePreview.d.ts +5 -9
  60. package/dist/types/utils/getDataURIDimension.d.ts +17 -0
  61. package/dist/types/utils/globalScope/globalScope.d.ts +2 -2
  62. package/dist/types/utils/globalScope/types.d.ts +1 -1
  63. package/dist/types/utils/lightCards/styles.d.ts +1 -1
  64. package/dist/types/utils/lightCards/types.d.ts +0 -2
  65. package/dist/types-ts4.5/card/ui/titleBox/styles.d.ts +1 -1
  66. package/dist/types-ts4.5/card/ui/titleBox/types.d.ts +0 -2
  67. package/dist/types-ts4.5/card/ui/wrapper/styles.d.ts +1 -1
  68. package/dist/types-ts4.5/card/ui/wrapper/types.d.ts +0 -2
  69. package/dist/types-ts4.5/card/v2/cardViewV2.d.ts +17 -6
  70. package/dist/types-ts4.5/card/v2/fileCard.d.ts +40 -6
  71. package/dist/types-ts4.5/card/v2/useFilePreview.d.ts +5 -9
  72. package/dist/types-ts4.5/utils/getDataURIDimension.d.ts +17 -0
  73. package/dist/types-ts4.5/utils/globalScope/globalScope.d.ts +2 -2
  74. package/dist/types-ts4.5/utils/globalScope/types.d.ts +1 -1
  75. package/dist/types-ts4.5/utils/lightCards/styles.d.ts +1 -1
  76. package/dist/types-ts4.5/utils/lightCards/types.d.ts +0 -2
  77. package/package.json +5 -2
@@ -8,21 +8,9 @@ exports.wrapperStyles = void 0;
8
8
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
9
9
  var _react = require("@emotion/react");
10
10
  var _mediaUi = require("@atlaskit/media-ui");
11
- var _components = require("@atlaskit/theme/components");
12
11
  var _colors = require("@atlaskit/theme/colors");
13
12
  var _templateObject;
14
13
  var wrapperStyles = exports.wrapperStyles = function wrapperStyles(_ref) {
15
- var dimensions = _ref.dimensions,
16
- theme = _ref.theme;
17
- return (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n ", "\n background: ", ";\n color: ", ";\n ", "\n max-height: 100%;\n max-width: 100%;\n width: ", ";\n height: ", ";\n"])), _mediaUi.center, (0, _components.themed)({
18
- light: "var(--ds-background-neutral, ".concat(_colors.N20, ")"),
19
- dark: "var(--ds-background-neutral, ".concat(_colors.DN50, ")")
20
- })({
21
- theme: theme
22
- }), (0, _components.themed)({
23
- light: "var(--ds-icon, ".concat(_colors.N50, ")"),
24
- dark: "var(--ds-icon, ".concat(_colors.DN100, ")")
25
- })({
26
- theme: theme
27
- }), _mediaUi.borderRadius, dimensions.width, dimensions.height);
14
+ var dimensions = _ref.dimensions;
15
+ return (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n ", "\n background: ", ";\n color: ", ";\n ", "\n max-height: 100%;\n max-width: 100%;\n width: ", ";\n height: ", ";\n"])), _mediaUi.center, "var(--ds-background-neutral, ".concat(_colors.N20, ")"), "var(--ds-icon, ".concat(_colors.N50, ")"), _mediaUi.borderRadius, dimensions.width, dimensions.height);
28
16
  };
@@ -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.7";
17
+ var packageVersion = "77.4.9";
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.7";
30
+ const packageVersion = "77.4.9";
31
31
  export class CardBase extends Component {
32
32
  constructor(props) {
33
33
  super(props);
@@ -26,6 +26,7 @@ import { PreviewUnavailable, CreatingPreview, FailedToUpload, PreviewCurrentlyUn
26
26
  import { isUploadError, isRateLimitedError, isPollingError } from '../errors';
27
27
  import { Wrapper } from './ui/wrapper';
28
28
  import { fileCardImageViewSelector } from './classnames';
29
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
29
30
  /**
30
31
  * This is classic vanilla CardView class. To create an instance of class one would need to supply
31
32
  * `createAnalyticsEvent` prop to satisfy it's Analytics Events needs.
@@ -320,10 +321,14 @@ export class CardViewBase extends React.Component {
320
321
  nativeLazyLoad,
321
322
  forceSyncDisplay
322
323
  } = this.props;
324
+ const {
325
+ name
326
+ } = this.props.metadata || {};
327
+ const altText = getBooleanFF('platform.editor.a11y-media_er96o') ? alt || name : alt;
323
328
  return !!cardPreview && jsx(ImageRenderer, {
324
329
  cardPreview: cardPreview,
325
330
  mediaType: mediaType,
326
- alt: alt,
331
+ alt: altText,
327
332
  resizeMode: resizeMode,
328
333
  onDisplayImage: onDisplayImage,
329
334
  onImageLoad: this.onImageLoad,
@@ -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.7";
69
+ const packageVersion = "77.4.9";
70
70
  const MediaCardAnalyticsErrorBoundary = withMediaAnalyticsContext({
71
71
  packageVersion,
72
72
  packageName,
@@ -2,7 +2,6 @@ import { css } from '@emotion/react';
2
2
  import { responsiveSettings, getTitleBoxHeight, Breakpoint } from '../common';
3
3
  import { N0, N800 } from '@atlaskit/theme/colors';
4
4
  import { rgba } from '../styles';
5
- import { themed } from '@atlaskit/theme/components';
6
5
  const generateResponsiveStyles = (breakpoint = Breakpoint.SMALL) => {
7
6
  const setting = responsiveSettings[breakpoint];
8
7
  const verticalPadding = setting.titleBox.verticalPadding;
@@ -12,30 +11,15 @@ const generateResponsiveStyles = (breakpoint = Breakpoint.SMALL) => {
12
11
  padding: ${verticalPadding}px ${horizontalPadding}px;`;
13
12
  };
14
13
  const HEX_REGEX = /^#[0-9A-F]{6}$/i;
15
- const BACKGROUND_COLOR_DARK = '#161a1d';
16
- const TEXT_COLOR_DARK = '#C7D1DB';
17
14
  export const titleBoxWrapperStyles = ({
18
15
  breakpoint,
19
- titleBoxBgColor,
20
- theme
16
+ titleBoxBgColor
21
17
  }) => css`
22
18
  position: absolute;
23
19
  bottom: 0;
24
20
  width: 100%;
25
- background-color: ${themed({
26
- light: `var(--ds-surface, ${rgba(titleBoxBgColor && HEX_REGEX.test(titleBoxBgColor) ? titleBoxBgColor : N0, 1)})`,
27
- dark: `var(--ds-surface, ${rgba(
28
- // theme does not contain this color, use constant instead
29
- titleBoxBgColor && HEX_REGEX.test(titleBoxBgColor) ? titleBoxBgColor : BACKGROUND_COLOR_DARK, 1)})`
30
- })({
31
- theme
32
- })};
33
- color: ${themed({
34
- light: `var(--ds-text, ${N800})`,
35
- dark: `var(--ds-text, ${TEXT_COLOR_DARK})`
36
- })({
37
- theme
38
- })};
21
+ background-color: ${`var(--ds-surface, ${rgba(titleBoxBgColor && HEX_REGEX.test(titleBoxBgColor) ? titleBoxBgColor : N0, 1)})`};
22
+ color: ${`var(--ds-text, ${N800})`};
39
23
  cursor: inherit;
40
24
  pointer-events: none;
41
25
  display: flex;
@@ -1,20 +1,17 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
3
  import { errorMessageWrapperStyles, titleBoxFooterStyles, titleBoxHeaderStyles, titleBoxIconStyles, titleBoxWrapperStyles } from './styles';
4
- import { useGlobalTheme } from '@atlaskit/theme/components';
5
4
  export const TitleBoxWrapper = props => {
6
5
  const {
7
6
  breakpoint,
8
7
  titleBoxBgColor
9
8
  } = props;
10
- const theme = useGlobalTheme();
11
9
  return jsx("div", {
12
10
  id: "titleBoxWrapper",
13
11
  "data-testid": "media-title-box",
14
12
  css: titleBoxWrapperStyles({
15
13
  breakpoint: breakpoint,
16
- titleBoxBgColor: titleBoxBgColor,
17
- theme
14
+ titleBoxBgColor: titleBoxBgColor
18
15
  })
19
16
  }, props.children);
20
17
  };
@@ -3,12 +3,10 @@ import { fontFamily } from '@atlaskit/theme/constants';
3
3
  import { borderRadius } from '@atlaskit/media-ui';
4
4
  import { N20 } from '@atlaskit/theme/colors';
5
5
  import { hideNativeBrowserTextSelectionStyles } from '@atlaskit/editor-shared-styles/selection';
6
- import { themed } from '@atlaskit/theme/components';
7
6
  import { transition } from '../styles';
8
7
  import { fixedBlanketStyles, blanketClassName } from '../blanket/styles';
9
8
  import { fixedActionBarStyles, actionsBarClassName } from '../actionsBar/styles';
10
9
  import { generateResponsiveStyles, getClickablePlayButtonStyles, getCursorStyle, getSelectableTickBoxStyles, getWrapperDimensions, getWrapperShadow } from '../styles';
11
- const BACKGROUND_COLOR_DARK = '#22272C';
12
10
  export const wrapperStyles = ({
13
11
  breakpoint,
14
12
  dimensions,
@@ -19,8 +17,7 @@ export const wrapperStyles = ({
19
17
  isPlayButtonClickable,
20
18
  isTickBoxSelectable,
21
19
  shouldDisplayTooltip,
22
- mediaCardCursor,
23
- theme
20
+ mediaCardCursor
24
21
  }) => css`
25
22
  ${transition()}
26
23
  box-sizing: border-box;
@@ -30,12 +27,7 @@ export const wrapperStyles = ({
30
27
  position: relative;
31
28
  font-family: ${fontFamily()};
32
29
  ${getWrapperDimensions(dimensions, appearance)}
33
- ${displayBackground && `background: ${themed({
34
- light: `var(--ds-background-neutral, ${N20})`,
35
- dark: `var(--ds-background-neutral, ${BACKGROUND_COLOR_DARK})`
36
- })({
37
- theme
38
- })};`}
30
+ ${displayBackground && `background: ${`var(--ds-background-neutral, ${N20})`};`}
39
31
  ${borderRadius}
40
32
  ${getCursorStyle(mediaCardCursor)}
41
33
  ${getWrapperShadow(disableOverlay, selected)}
@@ -2,7 +2,6 @@
2
2
  import { jsx } from '@emotion/react';
3
3
  import { newFileExperienceClassName } from '../../cardConstants';
4
4
  import { wrapperStyles } from './styles';
5
- import { useGlobalTheme } from '@atlaskit/theme/components';
6
5
  export const Wrapper = props => {
7
6
  const {
8
7
  testId,
@@ -20,7 +19,6 @@ export const Wrapper = props => {
20
19
  isTickBoxSelectable,
21
20
  shouldDisplayTooltip
22
21
  } = props;
23
- const theme = useGlobalTheme();
24
22
  return jsx("div", {
25
23
  id: "newFileExperienceWrapper",
26
24
  className: newFileExperienceClassName,
@@ -35,8 +33,7 @@ export const Wrapper = props => {
35
33
  isPlayButtonClickable,
36
34
  isTickBoxSelectable,
37
35
  shouldDisplayTooltip,
38
- mediaCardCursor,
39
- theme
36
+ mediaCardCursor
40
37
  }),
41
38
  ref: innerRef,
42
39
  onClick: onClick,
@@ -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.7";
10
+ const packageVersion = "77.4.9";
11
11
  export const CardV2Base = ({
12
12
  identifier,
13
13
  ...otherProps
@@ -28,7 +28,6 @@ export const CardViewV2Base = ({
28
28
  onImageLoad,
29
29
  onImageError,
30
30
  dimensions,
31
- appearance = 'auto',
32
31
  onClick,
33
32
  onMouseEnter,
34
33
  testId,
@@ -258,7 +257,6 @@ export const CardViewV2Base = ({
258
257
  return jsx(Wrapper, {
259
258
  testId: testId || 'media-card-view',
260
259
  dimensions: dimensions,
261
- appearance: appearance,
262
260
  onClick: onClick,
263
261
  onMouseEnter: onMouseEnter,
264
262
  innerRef: divRef,
@@ -9,6 +9,7 @@ import { generateUniqueId } from '../../utils/generateUniqueId';
9
9
  import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
10
10
  import { abortUfoExperience, completeUfoExperience, startUfoExperience } from '../../utils/ufoExperiences';
11
11
  import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
12
+ import { getDefaultCardDimensions } from '../../utils/cardDimensions';
12
13
  import { usePrevious } from '../../utils/usePrevious';
13
14
  import { fireCommencedEvent, fireCopiedEvent, fireOperationalEvent, fireScreenEvent } from '../cardAnalytics';
14
15
  import { CardViewV2 } from './cardViewV2';
@@ -36,6 +37,7 @@ export const ExternalImageCard = ({
36
37
  onMouseEnter,
37
38
  createAnalyticsEvent
38
39
  }) => {
40
+ const cardDimensions = dimensions || getDefaultCardDimensions(appearance);
39
41
  const internalOccurrenceKey = useMemo(() => generateUniqueId(), []);
40
42
  const timeElapsedTillCommenced = useMemo(() => performance.now(), []);
41
43
 
@@ -194,9 +196,8 @@ export const ExternalImageCard = ({
194
196
  metadata: metadata,
195
197
  cardPreview: cardPreview,
196
198
  alt: alt,
197
- appearance: appearance,
198
199
  resizeMode: resizeMode,
199
- dimensions: dimensions,
200
+ dimensions: cardDimensions,
200
201
  actions: actions,
201
202
  selectable: selectable,
202
203
  selected: selected,
@@ -235,7 +236,6 @@ export const ExternalImageCard = ({
235
236
  },
236
237
  innerRef: setCardElement,
237
238
  testId: testId,
238
- featureFlags: featureFlags,
239
239
  titleBoxBgColor: titleBoxBgColor,
240
240
  titleBoxIcon: titleBoxIcon,
241
241
  onImageError: newCardPreview => {
@@ -1,6 +1,6 @@
1
1
  import DownloadIcon from '@atlaskit/icon/glyph/download';
2
2
  import { globalMediaEventEmitter, isImageRepresentationReady, RECENTS_COLLECTION } from '@atlaskit/media-client';
3
- import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
3
+ import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
4
4
  import { getRandomHex, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
5
5
  import { MediaViewer } from '@atlaskit/media-viewer';
6
6
  import React, { Suspense, useEffect, useMemo, useRef, useState } from 'react';
@@ -8,7 +8,7 @@ import ReactDOM from 'react-dom';
8
8
  import { MediaCardError } from '../../errors';
9
9
  import getDocument from '../../utils/document';
10
10
  import { generateUniqueId } from '../../utils/generateUniqueId';
11
- import { getRequestedDimensions } from '../../utils/getDataURIDimension';
11
+ import { resolveCardPreviewDimensions } from '../../utils/getDataURIDimension';
12
12
  import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
13
13
  import { getFileDetails } from '../../utils/metadata';
14
14
  import { abortUfoExperience, completeUfoExperience, startUfoExperience } from '../../utils/ufoExperiences';
@@ -16,6 +16,7 @@ import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
16
16
  import { usePrevious } from '../../utils/usePrevious';
17
17
  import { videoIsPlayable } from '../../utils/videoIsPlayable';
18
18
  import { ViewportDetector } from '../../utils/viewportDetector';
19
+ import { getDefaultCardDimensions } from '../../utils/cardDimensions';
19
20
  import { fireCommencedEvent, fireCopiedEvent, fireNonCriticalErrorEvent, fireOperationalEvent, fireScreenEvent } from '../cardAnalytics';
20
21
  import { isSSRPreview } from '../getCardPreview';
21
22
  import { CardViewV2 } from './cardViewV2';
@@ -30,7 +31,6 @@ export const FileCard = ({
30
31
  featureFlags = {},
31
32
  identifier,
32
33
  ssr,
33
- mediaClient,
34
34
  dimensions,
35
35
  originalDimensions,
36
36
  contextId,
@@ -55,13 +55,18 @@ export const FileCard = ({
55
55
  //------------ State, Refs & Initial Values ----------------------//
56
56
  //----------------------------------------------------------------//
57
57
 
58
+ const mediaClient = useMediaClient();
58
59
  const [cardElement, setCardElement] = useState(null);
59
- const requestedDimensions = useMemo(() =>
60
- // requested dimensions is eventually an expensive operation if the dimensions are a percentage
61
- getRequestedDimensions({
62
- dimensions,
60
+ const cardDimensions = dimensions || getDefaultCardDimensions(appearance);
61
+
62
+ // Calculate the preview dimensions if card dimensions are "percentage" based
63
+ const previewDimensions = useMemo(() =>
64
+ // resolving dimensions is eventually an expensive operation if the dimensions are a percentage
65
+ // thus needs to be memoized
66
+ resolveCardPreviewDimensions({
67
+ dimensions: cardDimensions,
63
68
  element: cardElement
64
- }), [dimensions, cardElement]);
69
+ }), [cardDimensions, cardElement]);
65
70
  const [isCardVisible, setIsCardVisible] = useState(!isLazy);
66
71
  const {
67
72
  fileState
@@ -120,10 +125,10 @@ export const FileCard = ({
120
125
  mimeType,
121
126
  name,
122
127
  size,
123
- ...(originalDimensions || requestedDimensions),
128
+ ...(originalDimensions || previewDimensions),
124
129
  alt
125
130
  } : undefined;
126
- }, [alt, requestedDimensions, contextId, fileStateValue, identifier, originalDimensions]);
131
+ }, [alt, previewDimensions, contextId, fileStateValue, identifier, originalDimensions]);
127
132
  const {
128
133
  cardPreview,
129
134
  error: previewError,
@@ -137,9 +142,7 @@ export const FileCard = ({
137
142
  resizeMode,
138
143
  identifier,
139
144
  ssr,
140
- mediaClient,
141
- dimensions,
142
- requestedDimensions,
145
+ dimensions: previewDimensions,
143
146
  traceContext,
144
147
  previewDidRender,
145
148
  skipRemote: !isCardVisible
@@ -472,9 +475,8 @@ export const FileCard = ({
472
475
  metadata: metadata,
473
476
  cardPreview: cardPreview,
474
477
  alt: alt,
475
- appearance: appearance,
476
478
  resizeMode: resizeMode,
477
- dimensions: dimensions,
479
+ dimensions: cardDimensions,
478
480
  actions: computedActions,
479
481
  selectable: selectable,
480
482
  selected: selected,
@@ -499,7 +501,6 @@ export const FileCard = ({
499
501
  } : undefined,
500
502
  innerRef: setCardElement,
501
503
  testId: testId,
502
- featureFlags: featureFlags,
503
504
  titleBoxBgColor: titleBoxBgColor,
504
505
  titleBoxIcon: titleBoxIcon,
505
506
  onImageError: withCallbacks ? onImageError : undefined,
@@ -526,7 +527,7 @@ export const FileCard = ({
526
527
  return /*#__PURE__*/React.createElement(React.Fragment, null, isPlayingFile ? /*#__PURE__*/React.createElement(Suspense, {
527
528
  fallback: inlinePlayerFallback
528
529
  }, /*#__PURE__*/React.createElement(InlinePlayerLazyV2, {
529
- dimensions: dimensions,
530
+ dimensions: cardDimensions,
530
531
  originalDimensions: originalDimensions,
531
532
  identifier: identifier,
532
533
  autoplay: !!shouldAutoplay,
@@ -1,11 +1,12 @@
1
1
  import { addFileAttrsToUrl, imageResizeModeToFileImageMode, isImageRepresentationReady } from '@atlaskit/media-client';
2
- import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
2
+ import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
3
3
  import { getMediaTypeFromMimeType, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
4
4
  import { getOrientation } from '@atlaskit/media-ui';
5
5
  import { useEffect, useMemo, useRef, useState } from 'react';
6
6
  import { ensureMediaCardError, ImageLoadError, isLocalPreviewError, isUnsupportedLocalPreviewError, LocalPreviewError, MediaCardError } from '../../errors';
7
7
  import { extractErrorInfo } from '../../utils/analytics';
8
8
  import { isBigger } from '../../utils/dimensionComparer';
9
+ import { isRetina } from '../../utils/isRetina';
9
10
  import { generateScriptProps, getSSRData } from '../../utils/globalScope';
10
11
  import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
11
12
  import { usePrevious } from '../../utils/usePrevious';
@@ -16,16 +17,17 @@ export const useFilePreview = ({
16
17
  resizeMode = 'crop',
17
18
  identifier,
18
19
  ssr,
19
- mediaClient,
20
20
  dimensions,
21
- requestedDimensions,
22
21
  traceContext,
23
22
  previewDidRender,
24
23
  skipRemote,
25
24
  mediaBlobUrlAttrs
26
25
  }) => {
26
+ const mediaClient = useMediaClient();
27
27
  const [error, setError] = useState();
28
28
  const [nonCriticalError, setNonCriticalError] = useState();
29
+ const requestDimensions = useMemo(() => dimensions ? createRequestDimensions(dimensions) : undefined, [dimensions]);
30
+
29
31
  //----------------------------------------------------------------//
30
32
  //---------------- State Initializer Functions -------------------//
31
33
  //----------------------------------------------------------------//
@@ -42,9 +44,9 @@ export const useFilePreview = ({
42
44
  const imageURLParams = useMemo(() => ({
43
45
  collection: identifier.collectionName,
44
46
  mode: resizeMode === 'stretchy-fit' ? 'full-fit' : resizeMode,
45
- ...requestedDimensions,
47
+ ...requestDimensions,
46
48
  allowAnimated: true
47
- }), [requestedDimensions, identifier.collectionName, resizeMode]);
49
+ }), [requestDimensions, identifier.collectionName, resizeMode]);
48
50
  const getSSRPreview = (ssr, identifier, mediaClient) => {
49
51
  var _ssrDataRef$current, _ssrDataRef$current2;
50
52
  ssrDataRef.current = getSSRData(identifier);
@@ -64,8 +66,13 @@ export const useFilePreview = ({
64
66
  };
65
67
  }
66
68
  } else {
69
+ const {
70
+ dimensions,
71
+ dataURI
72
+ } = ssrDataRef.current;
67
73
  return {
68
- dataURI: ssrDataRef.current.dataURI,
74
+ dataURI,
75
+ dimensions,
69
76
  source: 'ssr-data'
70
77
  };
71
78
  }
@@ -107,7 +114,7 @@ export const useFilePreview = ({
107
114
  //----------------------------------------------------------------//
108
115
 
109
116
  const fetchRemotePreviewRef = useCurrentValueRef(identifier => {
110
- return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs);
117
+ return fetchAndCacheRemotePreview(mediaClient, identifier.id, requestDimensions || {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
111
118
  });
112
119
  const resolvePreviewRef = useCurrentValueRef(async (identifier, fileState) => {
113
120
  const filePreview = isBannedLocalPreview ? undefined : fileState.status !== 'error' && 'mimeType' in fileState && isMimeTypeSupportedByBrowser(fileState.mimeType) ? fileState.preview : undefined;
@@ -115,7 +122,7 @@ export const useFilePreview = ({
115
122
  try {
116
123
  const mode = imageURLParams.mode;
117
124
  const cachedPreview = cardPreviewCache.get(identifier.id, mode);
118
- const dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, dimensions);
125
+ const dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, requestDimensions);
119
126
  if (cachedPreview && !dimensionsAreBigger) {
120
127
  return cachedPreview;
121
128
  }
@@ -174,7 +181,7 @@ export const useFilePreview = ({
174
181
  }
175
182
  const preview = {
176
183
  ...localPreview,
177
- dimensions
184
+ dimensions: requestDimensions
178
185
  };
179
186
  let source;
180
187
  switch (preview.source) {
@@ -239,7 +246,7 @@ export const useFilePreview = ({
239
246
  */
240
247
  throw new MediaCardError('remote-preview-not-ready');
241
248
  }
242
- const remotePreview = await fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
249
+ const remotePreview = await fetchRemotePreviewRef.current(identifier);
243
250
  setCardPreview(remotePreview);
244
251
  return;
245
252
  } catch (e) {
@@ -264,7 +271,7 @@ export const useFilePreview = ({
264
271
  //------------ resolveUpfrontPreview useEffect -------------------//
265
272
  //----------------------------------------------------------------//
266
273
  const prevCardPreview = usePrevious(cardPreview);
267
- const dimensionsRef = useCurrentValueRef(dimensions);
274
+ const requestDimensionsRef = useCurrentValueRef(requestDimensions);
268
275
  useEffect(() => {
269
276
  const resolveUpfrontPreview = async identifier => {
270
277
  // We block any possible future call to this method regardless of the outcome (success or fail)
@@ -272,10 +279,10 @@ export const useFilePreview = ({
272
279
  wasResolvedUpfrontPreviewRef.current = true;
273
280
  try {
274
281
  const fetchedDimensions = {
275
- ...dimensions
282
+ ...requestDimensions
276
283
  };
277
284
  const newCardPreview = await fetchRemotePreviewRef.current(identifier);
278
- const areValidFetchedDimensions = !isBigger(fetchedDimensions, dimensionsRef.current);
285
+ const areValidFetchedDimensions = !isBigger(fetchedDimensions, requestDimensionsRef.current);
279
286
 
280
287
  // If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
281
288
  // the fetched preview is no longer valid, and thus, we dismiss it
@@ -292,16 +299,16 @@ export const useFilePreview = ({
292
299
  if (!wasResolvedUpfrontPreviewRef.current && (!skipRemote || hadSSRCardPreview) && !cardPreview) {
293
300
  resolveUpfrontPreview(identifier);
294
301
  }
295
- }, [cardPreview, dimensions, dimensionsRef, fetchRemotePreviewRef, identifier, skipRemote, prevCardPreview, ssr]);
302
+ }, [cardPreview, requestDimensions, requestDimensionsRef, fetchRemotePreviewRef, identifier, skipRemote, prevCardPreview, ssr]);
296
303
 
297
304
  //----------------------------------------------------------------//
298
305
  //---------------- fetch and resolve card preview ----------------//
299
306
  //----------------------------------------------------------------//
300
307
 
301
- const prevDimensions = usePrevious(dimensions);
308
+ const prevRequestDimensions = usePrevious(requestDimensions);
302
309
  useEffect(() => {
303
- var _ssrDataRef$current3;
304
- if (cardPreview && !skipRemote && isSSRDataPreview(cardPreview) && isBigger((_ssrDataRef$current3 = ssrDataRef.current) === null || _ssrDataRef$current3 === void 0 ? void 0 : _ssrDataRef$current3.dimensions, dimensions)) {
310
+ // CXP-2813 TODO: This is called too many times if the refetch failed. Should be called only once
311
+ if (cardPreview && !skipRemote && isSSRDataPreview(cardPreview) && isBigger(cardPreview.dimensions, requestDimensions)) {
305
312
  // refetchSRRPreview: If dimensions from Server have changed and are bigger,
306
313
  // we need to refetch
307
314
  fetchRemotePreviewRef.current(identifier).then(setCardPreview).catch(e => {
@@ -316,8 +323,8 @@ export const useFilePreview = ({
316
323
  if (fileState && shouldResolvePreview({
317
324
  status,
318
325
  fileState: fileState,
319
- prevDimensions,
320
- dimensions,
326
+ prevDimensions: prevRequestDimensions,
327
+ dimensions: requestDimensions,
321
328
  hasCardPreview: !!cardPreview,
322
329
  isBannedLocalPreview,
323
330
  wasResolvedUpfrontPreview: wasResolvedUpfrontPreviewRef.current
@@ -334,7 +341,7 @@ export const useFilePreview = ({
334
341
  // https://product-fabric.atlassian.net/browse/MEX-1071
335
342
  });
336
343
  }
337
- }, [cardPreview, dimensions, fetchRemotePreviewRef, fileState, identifier, isBannedLocalPreview, prevDimensions, resolvePreviewRef, skipRemote, ssr, status]);
344
+ }, [cardPreview, requestDimensions, fetchRemotePreviewRef, fileState, identifier, isBannedLocalPreview, prevRequestDimensions, resolvePreviewRef, skipRemote, ssr, status]);
338
345
 
339
346
  //----------------------------------------------------------------//
340
347
  //----------------- set complete status --------------------------//
@@ -476,7 +483,7 @@ export const useFilePreview = ({
476
483
  // FOR SSR
477
484
  const getScriptProps = () => {
478
485
  var _ssrReliabilityRef$cu;
479
- return generateScriptProps(identifier, cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI, requestedDimensions, ((_ssrReliabilityRef$cu = ssrReliabilityRef.current.server) === null || _ssrReliabilityRef$cu === void 0 ? void 0 : _ssrReliabilityRef$cu.status) === 'fail' ? ssrReliabilityRef.current.server : undefined);
486
+ return generateScriptProps(identifier, cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI, requestDimensions, ((_ssrReliabilityRef$cu = ssrReliabilityRef.current.server) === null || _ssrReliabilityRef$cu === void 0 ? void 0 : _ssrReliabilityRef$cu.status) === 'fail' ? ssrReliabilityRef.current.server : undefined);
480
487
  };
481
488
 
482
489
  // CXP-2723 TODO: should consider simplifying our analytics, and how
@@ -490,4 +497,22 @@ export const useFilePreview = ({
490
497
  onImageLoad,
491
498
  getScriptProps
492
499
  };
500
+ };
501
+ const createRequestDimensions = dimensions => {
502
+ if (!dimensions) {
503
+ return;
504
+ }
505
+ const retinaFactor = isRetina() ? 2 : 1;
506
+ const {
507
+ width,
508
+ height
509
+ } = dimensions;
510
+ const result = {};
511
+ if (width) {
512
+ result.width = width * retinaFactor;
513
+ }
514
+ if (height) {
515
+ result.height = height * retinaFactor;
516
+ }
517
+ return result;
493
518
  };
@@ -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.7",
40
+ packageName: "77.4.9",
41
41
  componentName: 'mediaInlineCard',
42
42
  component: 'mediaInlineCard'
43
43
  };
@@ -3,6 +3,13 @@ import { getElementDimension } from './getElementDimension';
3
3
  import { defaultImageCardDimensions } from './cardDimensions';
4
4
  import { isValidPercentageUnit } from './isValidPercentageUnit';
5
5
  import { containsPixelUnit } from './containsPixelUnit';
6
+
7
+ /**
8
+ * ************************************************
9
+ * For Card v1
10
+ * ************************************************
11
+ */
12
+
6
13
  export const getDataURIDimension = (dimension, options) => {
7
14
  const retinaFactor = isRetina() ? 2 : 1;
8
15
  const dimensionValue = options.dimensions && options.dimensions[dimension] || '';
@@ -24,4 +31,36 @@ export const getRequestedDimensions = options => {
24
31
  width,
25
32
  height
26
33
  };
34
+ };
35
+
36
+ /**
37
+ * ************************************************
38
+ * For Card v2
39
+ * ************************************************
40
+ */
41
+
42
+ // Same as getDataURIDimension but without Retina factor
43
+ export const resolveCardPreviewDimension = (dimensionName, {
44
+ dimensions,
45
+ element
46
+ }) => {
47
+ const dimensionValue = (dimensions === null || dimensions === void 0 ? void 0 : dimensions[dimensionName]) || '';
48
+ if (isValidPercentageUnit(dimensionValue) && element) {
49
+ return getElementDimension(element, dimensionName);
50
+ }
51
+ if (typeof dimensionValue === 'number') {
52
+ return dimensionValue;
53
+ }
54
+ if (containsPixelUnit(`${dimensionValue}`)) {
55
+ return parseInt(`${dimensionValue}`, 10);
56
+ }
57
+ return defaultImageCardDimensions[dimensionName];
58
+ };
59
+ export const resolveCardPreviewDimensions = options => {
60
+ const width = resolveCardPreviewDimension('width', options);
61
+ const height = resolveCardPreviewDimension('height', options);
62
+ return {
63
+ width,
64
+ height
65
+ };
27
66
  };
@@ -2,13 +2,10 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  /**@jsx jsx */
3
3
  import { jsx } from '@emotion/react';
4
4
  import { wrapperStyles } from './styles';
5
- import { useGlobalTheme } from '@atlaskit/theme/components';
6
5
  export const Wrapper = props => {
7
- const theme = useGlobalTheme();
8
6
  return jsx("div", _extends({
9
7
  css: wrapperStyles({
10
- dimensions: props.dimensions,
11
- theme: theme
8
+ dimensions: props.dimensions
12
9
  })
13
10
  }, props), props.children);
14
11
  };