@atlaskit/media-card 77.4.7 → 77.4.8

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 (47) hide show
  1. package/CHANGELOG.md +9 -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/v2/cardV2.js +1 -1
  6. package/dist/cjs/card/v2/cardViewV2.js +0 -3
  7. package/dist/cjs/card/v2/externalImageCard.js +3 -3
  8. package/dist/cjs/card/v2/fileCard.js +16 -15
  9. package/dist/cjs/card/v2/useFilePreview.js +44 -20
  10. package/dist/cjs/inline/loader.js +1 -1
  11. package/dist/cjs/utils/getDataURIDimension.js +38 -1
  12. package/dist/cjs/utils/ufoExperiences.js +1 -1
  13. package/dist/es2019/card/card.js +1 -1
  14. package/dist/es2019/card/cardView.js +6 -1
  15. package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
  16. package/dist/es2019/card/v2/cardV2.js +1 -1
  17. package/dist/es2019/card/v2/cardViewV2.js +0 -2
  18. package/dist/es2019/card/v2/externalImageCard.js +3 -3
  19. package/dist/es2019/card/v2/fileCard.js +18 -17
  20. package/dist/es2019/card/v2/useFilePreview.js +46 -21
  21. package/dist/es2019/inline/loader.js +1 -1
  22. package/dist/es2019/utils/getDataURIDimension.js +39 -0
  23. package/dist/es2019/utils/ufoExperiences.js +1 -1
  24. package/dist/esm/card/card.js +1 -1
  25. package/dist/esm/card/cardView.js +11 -7
  26. package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
  27. package/dist/esm/card/v2/cardV2.js +1 -1
  28. package/dist/esm/card/v2/cardViewV2.js +0 -3
  29. package/dist/esm/card/v2/externalImageCard.js +3 -3
  30. package/dist/esm/card/v2/fileCard.js +18 -17
  31. package/dist/esm/card/v2/useFilePreview.js +45 -21
  32. package/dist/esm/inline/loader.js +1 -1
  33. package/dist/esm/utils/getDataURIDimension.js +38 -0
  34. package/dist/esm/utils/ufoExperiences.js +1 -1
  35. package/dist/types/card/v2/cardViewV2.d.ts +17 -6
  36. package/dist/types/card/v2/fileCard.d.ts +40 -6
  37. package/dist/types/card/v2/useFilePreview.d.ts +5 -9
  38. package/dist/types/utils/getDataURIDimension.d.ts +17 -0
  39. package/dist/types/utils/globalScope/globalScope.d.ts +2 -2
  40. package/dist/types/utils/globalScope/types.d.ts +1 -1
  41. package/dist/types-ts4.5/card/v2/cardViewV2.d.ts +17 -6
  42. package/dist/types-ts4.5/card/v2/fileCard.d.ts +40 -6
  43. package/dist/types-ts4.5/card/v2/useFilePreview.d.ts +5 -9
  44. package/dist/types-ts4.5/utils/getDataURIDimension.d.ts +17 -0
  45. package/dist/types-ts4.5/utils/globalScope/globalScope.d.ts +2 -2
  46. package/dist/types-ts4.5/utils/globalScope/types.d.ts +1 -1
  47. package/package.json +5 -2
@@ -5,13 +5,14 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
5
  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; }
6
6
  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) { _defineProperty(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; }
7
7
  import { addFileAttrsToUrl, imageResizeModeToFileImageMode, isImageRepresentationReady } from '@atlaskit/media-client';
8
- import { MediaFileStateError, useFileState } from '@atlaskit/media-client-react';
8
+ import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
9
9
  import { getMediaTypeFromMimeType, isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
10
10
  import { getOrientation } from '@atlaskit/media-ui';
11
11
  import { useEffect, useMemo, useRef, useState } from 'react';
12
12
  import { ensureMediaCardError, ImageLoadError, isLocalPreviewError, isUnsupportedLocalPreviewError, LocalPreviewError, MediaCardError } from '../../errors';
13
13
  import { extractErrorInfo } from '../../utils/analytics';
14
14
  import { isBigger } from '../../utils/dimensionComparer';
15
+ import { isRetina } from '../../utils/isRetina';
15
16
  import { generateScriptProps, getSSRData } from '../../utils/globalScope';
16
17
  import { useCurrentValueRef } from '../../utils/useCurrentValueRef';
17
18
  import { usePrevious } from '../../utils/usePrevious';
@@ -23,13 +24,12 @@ export var useFilePreview = function useFilePreview(_ref) {
23
24
  resizeMode = _ref$resizeMode === void 0 ? 'crop' : _ref$resizeMode,
24
25
  identifier = _ref.identifier,
25
26
  ssr = _ref.ssr,
26
- mediaClient = _ref.mediaClient,
27
27
  dimensions = _ref.dimensions,
28
- requestedDimensions = _ref.requestedDimensions,
29
28
  traceContext = _ref.traceContext,
30
29
  previewDidRender = _ref.previewDidRender,
31
30
  skipRemote = _ref.skipRemote,
32
31
  mediaBlobUrlAttrs = _ref.mediaBlobUrlAttrs;
32
+ var mediaClient = useMediaClient();
33
33
  var _useState = useState(),
34
34
  _useState2 = _slicedToArray(_useState, 2),
35
35
  error = _useState2[0],
@@ -38,6 +38,10 @@ export var useFilePreview = function useFilePreview(_ref) {
38
38
  _useState4 = _slicedToArray(_useState3, 2),
39
39
  nonCriticalError = _useState4[0],
40
40
  setNonCriticalError = _useState4[1];
41
+ var requestDimensions = useMemo(function () {
42
+ return dimensions ? createRequestDimensions(dimensions) : undefined;
43
+ }, [dimensions]);
44
+
41
45
  //----------------------------------------------------------------//
42
46
  //---------------- State Initializer Functions -------------------//
43
47
  //----------------------------------------------------------------//
@@ -55,10 +59,10 @@ export var useFilePreview = function useFilePreview(_ref) {
55
59
  return _objectSpread(_objectSpread({
56
60
  collection: identifier.collectionName,
57
61
  mode: resizeMode === 'stretchy-fit' ? 'full-fit' : resizeMode
58
- }, requestedDimensions), {}, {
62
+ }, requestDimensions), {}, {
59
63
  allowAnimated: true
60
64
  });
61
- }, [requestedDimensions, identifier.collectionName, resizeMode]);
65
+ }, [requestDimensions, identifier.collectionName, resizeMode]);
62
66
  var getSSRPreview = function getSSRPreview(ssr, identifier, mediaClient) {
63
67
  var _ssrDataRef$current, _ssrDataRef$current2;
64
68
  ssrDataRef.current = getSSRData(identifier);
@@ -76,8 +80,12 @@ export var useFilePreview = function useFilePreview(_ref) {
76
80
  }, extractErrorInfo(e));
77
81
  }
78
82
  } else {
83
+ var _ssrDataRef$current3 = ssrDataRef.current,
84
+ _dimensions = _ssrDataRef$current3.dimensions,
85
+ dataURI = _ssrDataRef$current3.dataURI;
79
86
  return {
80
- dataURI: ssrDataRef.current.dataURI,
87
+ dataURI: dataURI,
88
+ dimensions: _dimensions,
81
89
  source: 'ssr-data'
82
90
  };
83
91
  }
@@ -125,7 +133,7 @@ export var useFilePreview = function useFilePreview(_ref) {
125
133
  //----------------------------------------------------------------//
126
134
 
127
135
  var fetchRemotePreviewRef = useCurrentValueRef(function (identifier) {
128
- return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs);
136
+ return fetchAndCacheRemotePreview(mediaClient, identifier.id, requestDimensions || {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
129
137
  });
130
138
  var resolvePreviewRef = useCurrentValueRef( /*#__PURE__*/function () {
131
139
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(identifier, fileState) {
@@ -138,7 +146,7 @@ export var useFilePreview = function useFilePreview(_ref) {
138
146
  _context.prev = 2;
139
147
  mode = imageURLParams.mode;
140
148
  cachedPreview = cardPreviewCache.get(identifier.id, mode);
141
- dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, dimensions);
149
+ dimensionsAreBigger = isBigger(cachedPreview === null || cachedPreview === void 0 ? void 0 : cachedPreview.dimensions, requestDimensions);
142
150
  if (!(cachedPreview && !dimensionsAreBigger)) {
143
151
  _context.next = 8;
144
152
  break;
@@ -232,7 +240,7 @@ export var useFilePreview = function useFilePreview(_ref) {
232
240
  throw new LocalPreviewError('local-preview-unsupported');
233
241
  case 57:
234
242
  preview = _objectSpread(_objectSpread({}, localPreview), {}, {
235
- dimensions: dimensions
243
+ dimensions: requestDimensions
236
244
  });
237
245
  _context.t4 = preview.source;
238
246
  _context.next = _context.t4 === 'local' ? 61 : _context.t4 === 'remote' ? 63 : _context.t4 === 'ssr-server' ? 65 : _context.t4 === 'ssr-client' ? 67 : 69;
@@ -299,7 +307,7 @@ export var useFilePreview = function useFilePreview(_ref) {
299
307
  throw new MediaCardError('remote-preview-not-ready');
300
308
  case 83:
301
309
  _context.next = 85;
302
- return fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions !== null && dimensions !== void 0 ? dimensions : {}, imageURLParams, mediaBlobUrlAttrs, traceContext);
310
+ return fetchRemotePreviewRef.current(identifier);
303
311
  case 85:
304
312
  remotePreview = _context.sent;
305
313
  setCardPreview(remotePreview);
@@ -335,7 +343,7 @@ export var useFilePreview = function useFilePreview(_ref) {
335
343
  //------------ resolveUpfrontPreview useEffect -------------------//
336
344
  //----------------------------------------------------------------//
337
345
  var prevCardPreview = usePrevious(cardPreview);
338
- var dimensionsRef = useCurrentValueRef(dimensions);
346
+ var requestDimensionsRef = useCurrentValueRef(requestDimensions);
339
347
  useEffect(function () {
340
348
  var resolveUpfrontPreview = /*#__PURE__*/function () {
341
349
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(identifier) {
@@ -347,12 +355,12 @@ export var useFilePreview = function useFilePreview(_ref) {
347
355
  // If it fails, the normal preview fetch should occur after the file state is fetched anyways
348
356
  wasResolvedUpfrontPreviewRef.current = true;
349
357
  _context2.prev = 1;
350
- fetchedDimensions = _objectSpread({}, dimensions);
358
+ fetchedDimensions = _objectSpread({}, requestDimensions);
351
359
  _context2.next = 5;
352
360
  return fetchRemotePreviewRef.current(identifier);
353
361
  case 5:
354
362
  newCardPreview = _context2.sent;
355
- areValidFetchedDimensions = !isBigger(fetchedDimensions, dimensionsRef.current); // If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
363
+ areValidFetchedDimensions = !isBigger(fetchedDimensions, requestDimensionsRef.current); // If there are new and bigger dimensions in the props, and the upfront preview is still resolving,
356
364
  // the fetched preview is no longer valid, and thus, we dismiss it
357
365
  if (areValidFetchedDimensions) {
358
366
  setCardPreview(newCardPreview);
@@ -378,16 +386,16 @@ export var useFilePreview = function useFilePreview(_ref) {
378
386
  if (!wasResolvedUpfrontPreviewRef.current && (!skipRemote || hadSSRCardPreview) && !cardPreview) {
379
387
  resolveUpfrontPreview(identifier);
380
388
  }
381
- }, [cardPreview, dimensions, dimensionsRef, fetchRemotePreviewRef, identifier, skipRemote, prevCardPreview, ssr]);
389
+ }, [cardPreview, requestDimensions, requestDimensionsRef, fetchRemotePreviewRef, identifier, skipRemote, prevCardPreview, ssr]);
382
390
 
383
391
  //----------------------------------------------------------------//
384
392
  //---------------- fetch and resolve card preview ----------------//
385
393
  //----------------------------------------------------------------//
386
394
 
387
- var prevDimensions = usePrevious(dimensions);
395
+ var prevRequestDimensions = usePrevious(requestDimensions);
388
396
  useEffect(function () {
389
- var _ssrDataRef$current3;
390
- if (cardPreview && !skipRemote && isSSRDataPreview(cardPreview) && isBigger((_ssrDataRef$current3 = ssrDataRef.current) === null || _ssrDataRef$current3 === void 0 ? void 0 : _ssrDataRef$current3.dimensions, dimensions)) {
397
+ // CXP-2813 TODO: This is called too many times if the refetch failed. Should be called only once
398
+ if (cardPreview && !skipRemote && isSSRDataPreview(cardPreview) && isBigger(cardPreview.dimensions, requestDimensions)) {
391
399
  // refetchSRRPreview: If dimensions from Server have changed and are bigger,
392
400
  // we need to refetch
393
401
  fetchRemotePreviewRef.current(identifier).then(setCardPreview).catch(function (e) {
@@ -402,8 +410,8 @@ export var useFilePreview = function useFilePreview(_ref) {
402
410
  if (fileState && shouldResolvePreview({
403
411
  status: status,
404
412
  fileState: fileState,
405
- prevDimensions: prevDimensions,
406
- dimensions: dimensions,
413
+ prevDimensions: prevRequestDimensions,
414
+ dimensions: requestDimensions,
407
415
  hasCardPreview: !!cardPreview,
408
416
  isBannedLocalPreview: isBannedLocalPreview,
409
417
  wasResolvedUpfrontPreview: wasResolvedUpfrontPreviewRef.current
@@ -420,7 +428,7 @@ export var useFilePreview = function useFilePreview(_ref) {
420
428
  // https://product-fabric.atlassian.net/browse/MEX-1071
421
429
  });
422
430
  }
423
- }, [cardPreview, dimensions, fetchRemotePreviewRef, fileState, identifier, isBannedLocalPreview, prevDimensions, resolvePreviewRef, skipRemote, ssr, status]);
431
+ }, [cardPreview, requestDimensions, fetchRemotePreviewRef, fileState, identifier, isBannedLocalPreview, prevRequestDimensions, resolvePreviewRef, skipRemote, ssr, status]);
424
432
 
425
433
  //----------------------------------------------------------------//
426
434
  //----------------- set complete status --------------------------//
@@ -561,7 +569,7 @@ export var useFilePreview = function useFilePreview(_ref) {
561
569
  // FOR SSR
562
570
  var getScriptProps = function getScriptProps() {
563
571
  var _ssrReliabilityRef$cu;
564
- 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);
572
+ 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);
565
573
  };
566
574
 
567
575
  // CXP-2723 TODO: should consider simplifying our analytics, and how
@@ -575,4 +583,20 @@ export var useFilePreview = function useFilePreview(_ref) {
575
583
  onImageLoad: onImageLoad,
576
584
  getScriptProps: getScriptProps
577
585
  };
586
+ };
587
+ var createRequestDimensions = function createRequestDimensions(dimensions) {
588
+ if (!dimensions) {
589
+ return;
590
+ }
591
+ var retinaFactor = isRetina() ? 2 : 1;
592
+ var width = dimensions.width,
593
+ height = dimensions.height;
594
+ var result = {};
595
+ if (width) {
596
+ result.width = width * retinaFactor;
597
+ }
598
+ if (height) {
599
+ result.height = height * retinaFactor;
600
+ }
601
+ return result;
578
602
  };
@@ -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.7",
106
+ packageName: "77.4.8",
107
107
  componentName: 'mediaInlineCard',
108
108
  component: 'mediaInlineCard'
109
109
  };
@@ -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 var getDataURIDimension = function getDataURIDimension(dimension, options) {
7
14
  var retinaFactor = isRetina() ? 2 : 1;
8
15
  var dimensionValue = options.dimensions && options.dimensions[dimension] || '';
@@ -24,4 +31,35 @@ export var getRequestedDimensions = function getRequestedDimensions(options) {
24
31
  width: width,
25
32
  height: height
26
33
  };
34
+ };
35
+
36
+ /**
37
+ * ************************************************
38
+ * For Card v2
39
+ * ************************************************
40
+ */
41
+
42
+ // Same as getDataURIDimension but without Retina factor
43
+ export var resolveCardPreviewDimension = function resolveCardPreviewDimension(dimensionName, _ref) {
44
+ var dimensions = _ref.dimensions,
45
+ element = _ref.element;
46
+ var dimensionValue = (dimensions === null || dimensions === void 0 ? void 0 : dimensions[dimensionName]) || '';
47
+ if (isValidPercentageUnit(dimensionValue) && element) {
48
+ return getElementDimension(element, dimensionName);
49
+ }
50
+ if (typeof dimensionValue === 'number') {
51
+ return dimensionValue;
52
+ }
53
+ if (containsPixelUnit("".concat(dimensionValue))) {
54
+ return parseInt("".concat(dimensionValue), 10);
55
+ }
56
+ return defaultImageCardDimensions[dimensionName];
57
+ };
58
+ export var resolveCardPreviewDimensions = function resolveCardPreviewDimensions(options) {
59
+ var width = resolveCardPreviewDimension('width', options);
60
+ var height = resolveCardPreviewDimension('height', options);
61
+ return {
62
+ width: width,
63
+ height: height
64
+ };
27
65
  };
@@ -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.7";
10
+ var packageVersion = "77.4.8";
11
11
  var concurrentExperience;
12
12
  var getExperience = function getExperience(id) {
13
13
  if (!concurrentExperience) {
@@ -2,11 +2,22 @@
2
2
  import { jsx } from '@emotion/react';
3
3
  import React, { MouseEvent } from 'react';
4
4
  import { MessageDescriptor } from 'react-intl-next';
5
- import { MediaItemType, FileDetails } from '@atlaskit/media-client';
5
+ import { MediaItemType, FileDetails, ImageResizeMode } from '@atlaskit/media-client';
6
6
  import { WithAnalyticsEventsProps, UIAnalyticsEvent } from '@atlaskit/analytics-next';
7
- import { SharedCardProps, CardStatus, CardPreview, MediaCardCursor } from '../../types';
7
+ import { CardStatus, CardPreview, MediaCardCursor, CardDimensions, TitleBoxIcon } from '../../types';
8
+ import { CardAction } from '../actions';
8
9
  import { MediaCardError } from '../../errors';
9
- export interface CardViewV2OwnProps extends SharedCardProps {
10
+ export interface CardViewV2Props {
11
+ readonly disableOverlay?: boolean;
12
+ readonly resizeMode?: ImageResizeMode;
13
+ readonly dimensions: CardDimensions;
14
+ readonly actions?: Array<CardAction>;
15
+ readonly selectable?: boolean;
16
+ readonly selected?: boolean;
17
+ readonly alt?: string;
18
+ readonly testId?: string;
19
+ readonly titleBoxBgColor?: string;
20
+ readonly titleBoxIcon?: TitleBoxIcon;
10
21
  readonly status: CardStatus;
11
22
  readonly mediaItemType: MediaItemType;
12
23
  readonly mediaCardCursor?: MediaCardCursor;
@@ -25,7 +36,7 @@ export interface CardViewV2OwnProps extends SharedCardProps {
25
36
  disableAnimation?: boolean;
26
37
  shouldHideTooltip?: boolean;
27
38
  }
28
- export type CardViewV2Props = CardViewV2OwnProps & WithAnalyticsEventsProps;
39
+ export type CardViewV2BaseProps = CardViewV2Props & WithAnalyticsEventsProps;
29
40
  export interface RenderConfigByStatusV2 {
30
41
  renderTypeIcon?: boolean;
31
42
  iconMessage?: JSX.Element;
@@ -40,5 +51,5 @@ export interface RenderConfigByStatusV2 {
40
51
  renderTickBox?: boolean;
41
52
  customTitleMessage?: MessageDescriptor;
42
53
  }
43
- export declare const CardViewV2Base: ({ innerRef, onImageLoad, onImageError, dimensions, appearance, onClick, onMouseEnter, testId, metadata, status, selected, selectable, cardPreview, mediaCardCursor, shouldHideTooltip, progress, alt, resizeMode, onDisplayImage, nativeLazyLoad, forceSyncDisplay, actions, disableOverlay, titleBoxBgColor, titleBoxIcon, error, disableAnimation, }: CardViewV2Props) => jsx.JSX.Element;
44
- export declare const CardViewV2: React.ForwardRefExoticComponent<Omit<CardViewV2Props, keyof WithAnalyticsEventsProps> & React.RefAttributes<any>>;
54
+ export declare const CardViewV2Base: ({ innerRef, onImageLoad, onImageError, dimensions, onClick, onMouseEnter, testId, metadata, status, selected, selectable, cardPreview, mediaCardCursor, shouldHideTooltip, progress, alt, resizeMode, onDisplayImage, nativeLazyLoad, forceSyncDisplay, actions, disableOverlay, titleBoxBgColor, titleBoxIcon, error, disableAnimation, }: CardViewV2BaseProps) => jsx.JSX.Element;
55
+ export declare const CardViewV2: React.ForwardRefExoticComponent<Omit<CardViewV2BaseProps, keyof WithAnalyticsEventsProps> & React.RefAttributes<any>>;
@@ -1,19 +1,53 @@
1
1
  /// <reference types="react" />
2
2
  import { WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
3
- import { FileIdentifier, Identifier, MediaClient } from '@atlaskit/media-client';
4
- import { SSR } from '@atlaskit/media-common';
5
- import { CardEventProps, SharedCardProps } from '../../types';
6
- export interface FileCardProps extends SharedCardProps, CardEventProps {
7
- readonly mediaClient: MediaClient;
3
+ import { FileIdentifier, Identifier, ImageResizeMode } from '@atlaskit/media-client';
4
+ import { MediaFeatureFlags, NumericalCardDimensions, SSR } from '@atlaskit/media-common';
5
+ import { CardAppearance, CardDimensions, CardEventProps, TitleBoxIcon } from '../../types';
6
+ import { CardAction } from '../actions';
7
+ export interface FileCardProps extends CardEventProps {
8
+ /** Overlay the media file. */
9
+ readonly disableOverlay?: boolean;
10
+ /** Resize the media to 'crop' | 'fit' | 'full-fit' | 'stretchy-fit'. */
11
+ readonly resizeMode?: ImageResizeMode;
12
+ readonly featureFlags?: MediaFeatureFlags;
13
+ /** Sets meida card appearance */
14
+ readonly appearance?: CardAppearance;
15
+ /** Custom media card dimension like width and height. */
16
+ readonly dimensions?: CardDimensions;
17
+ /** Original media card dimension like width and height. */
18
+ readonly originalDimensions?: NumericalCardDimensions;
19
+ /** Array of additional media card actions. */
20
+ readonly actions?: Array<CardAction>;
21
+ /** Enable media card selectable. */
22
+ readonly selectable?: boolean;
23
+ /** Renders media card as selected, if selected is true. */
24
+ readonly selected?: boolean;
25
+ /** Alternate text for an media card. */
26
+ readonly alt?: string;
27
+ /** ID for testing the media card. */
28
+ readonly testId?: string;
29
+ /** Sets the title box background color. */
30
+ readonly titleBoxBgColor?: string;
31
+ /** Sets the title box icon. */
32
+ readonly titleBoxIcon?: TitleBoxIcon;
33
+ /** Instance of file identifier. */
8
34
  readonly identifier: FileIdentifier;
35
+ /** Lazy loads the media file. */
9
36
  readonly isLazy?: boolean;
37
+ /** Uses the inline player for media file. */
10
38
  readonly useInlinePlayer?: boolean;
39
+ /** Uses media MediaViewer to preview the media file. */
11
40
  readonly shouldOpenMediaViewer?: boolean;
41
+ /** Media file list to display in Media Viewer. */
12
42
  readonly mediaViewerItems?: Identifier[];
43
+ /** Retrieve auth based on a given context. */
13
44
  readonly contextId?: string;
45
+ /** Enables the download button for media file. */
14
46
  readonly shouldEnableDownloadButton?: boolean;
47
+ /** Server-Side-Rendering modes are "server" and "client" */
15
48
  readonly ssr?: SSR;
49
+ /** Disable tooltip for the card */
16
50
  readonly shouldHideTooltip?: boolean;
17
51
  }
18
52
  export type FileCardBaseProps = FileCardProps & WithAnalyticsEventsProps;
19
- export declare const FileCard: ({ appearance, resizeMode, isLazy, disableOverlay, featureFlags, identifier, ssr, mediaClient, dimensions, originalDimensions, contextId, alt, actions, shouldEnableDownloadButton, useInlinePlayer, shouldOpenMediaViewer, onFullscreenChange, selectable, selected, testId, titleBoxBgColor, titleBoxIcon, shouldHideTooltip, mediaViewerItems, onClick, onMouseEnter, createAnalyticsEvent, }: FileCardBaseProps) => JSX.Element;
53
+ export declare const FileCard: ({ appearance, resizeMode, isLazy, disableOverlay, featureFlags, identifier, ssr, dimensions, originalDimensions, contextId, alt, actions, shouldEnableDownloadButton, useInlinePlayer, shouldOpenMediaViewer, onFullscreenChange, selectable, selected, testId, titleBoxBgColor, titleBoxIcon, shouldHideTooltip, mediaViewerItems, onClick, onMouseEnter, createAnalyticsEvent, }: FileCardBaseProps) => JSX.Element;
@@ -1,20 +1,16 @@
1
1
  /// <reference types="react" />
2
- import { FileIdentifier, ImageResizeMode, MediaBlobUrlAttrs, MediaClient } from '@atlaskit/media-client';
2
+ import { FileIdentifier, ImageResizeMode, MediaBlobUrlAttrs } from '@atlaskit/media-client';
3
3
  import { MediaTraceContext, NumericalCardDimensions, SSR } from '@atlaskit/media-common';
4
4
  import { MediaCardError } from '../../errors';
5
- import { CardDimensions, CardPreview } from '../../types';
5
+ import { CardPreview } from '../../types';
6
6
  import { SSRStatus } from '../../utils/analytics';
7
7
  export interface UseFilePreviewParams {
8
8
  /** Instance of file identifier. */
9
9
  readonly identifier: FileIdentifier;
10
- /** Instance of MediaClient. */
11
- readonly mediaClient: MediaClient;
12
10
  /** Resize the media to 'crop' | 'fit' | 'full-fit' | 'stretchy-fit' */
13
11
  readonly resizeMode?: ImageResizeMode;
14
- /** Custom media card dimension like width and height. */
15
- readonly dimensions?: CardDimensions;
16
- /** Dimensions to be requested to the server */
17
- readonly requestedDimensions: NumericalCardDimensions;
12
+ /** Dimensions to be requested to the server. Will be scaled x2 in Retina Displays */
13
+ readonly dimensions?: Partial<NumericalCardDimensions>;
18
14
  /** Server-Side-Rendering modes are "server" and "client" */
19
15
  readonly ssr?: SSR;
20
16
  /** Attributes to attach to the created Blob Url */
@@ -26,7 +22,7 @@ export interface UseFilePreviewParams {
26
22
  /** Do not fetch a remote preview. Helpful for lazy loading */
27
23
  readonly skipRemote?: boolean;
28
24
  }
29
- export declare const useFilePreview: ({ resizeMode, identifier, ssr, mediaClient, dimensions, requestedDimensions, traceContext, previewDidRender, skipRemote, mediaBlobUrlAttrs, }: UseFilePreviewParams) => {
25
+ export declare const useFilePreview: ({ resizeMode, identifier, ssr, dimensions, traceContext, previewDidRender, skipRemote, mediaBlobUrlAttrs, }: UseFilePreviewParams) => {
30
26
  cardPreview: CardPreview | undefined;
31
27
  error: MediaCardError | undefined;
32
28
  nonCriticalError: MediaCardError | undefined;
@@ -1,9 +1,26 @@
1
1
  import { CardDimensions } from '../types';
2
2
  import { ElementDimension } from './getElementDimension';
3
3
  import { NumericalCardDimensions } from '@atlaskit/media-common';
4
+ /**
5
+ * ************************************************
6
+ * For Card v1
7
+ * ************************************************
8
+ */
4
9
  export type getDataURIDimensionOptions = {
5
10
  element?: Element | null;
6
11
  dimensions?: CardDimensions;
7
12
  };
8
13
  export declare const getDataURIDimension: (dimension: ElementDimension, options: getDataURIDimensionOptions) => number;
9
14
  export declare const getRequestedDimensions: (options: getDataURIDimensionOptions) => NumericalCardDimensions;
15
+ /**
16
+ * ************************************************
17
+ * For Card v2
18
+ * ************************************************
19
+ */
20
+ type ResolveCardDimensionOptions = {
21
+ element?: Element | null;
22
+ dimensions?: CardDimensions;
23
+ };
24
+ export declare const resolveCardPreviewDimension: (dimensionName: ElementDimension, { dimensions, element }: ResolveCardDimensionOptions) => number;
25
+ export declare const resolveCardPreviewDimensions: (options: ResolveCardDimensionOptions) => NumericalCardDimensions;
26
+ export {};
@@ -11,5 +11,5 @@ export type MediaGlobalScope = {
11
11
  export declare function getMediaGlobalScope(globalScope?: any): MediaGlobalScope;
12
12
  export declare function getMediaCardSSR(globalScope?: any): MediaCardSsr;
13
13
  export declare const getKey: ({ id, collectionName, occurrenceKey }: FileIdentifier) => string;
14
- export declare const storeDataURI: (key: string, dataURI?: string, dimensions?: NumericalCardDimensions, error?: MediaCardErrorInfo, globalScope?: any) => void;
15
- export declare const generateScriptProps: (identifier: FileIdentifier, dataURI?: string, dimensions?: NumericalCardDimensions, error?: MediaCardErrorInfo) => React.ScriptHTMLAttributes<HTMLScriptElement>;
14
+ export declare const storeDataURI: (key: string, dataURI?: string, dimensions?: Partial<NumericalCardDimensions>, error?: MediaCardErrorInfo, globalScope?: any) => void;
15
+ export declare const generateScriptProps: (identifier: FileIdentifier, dataURI?: string, dimensions?: Partial<NumericalCardDimensions>, error?: MediaCardErrorInfo) => React.ScriptHTMLAttributes<HTMLScriptElement>;
@@ -2,7 +2,7 @@ import { NumericalCardDimensions } from '@atlaskit/media-common';
2
2
  import { MediaCardErrorInfo } from '../../utils/analytics';
3
3
  export type MediaCardSsrData = {
4
4
  dataURI?: string;
5
- dimensions?: NumericalCardDimensions;
5
+ dimensions?: Partial<NumericalCardDimensions>;
6
6
  error?: MediaCardErrorInfo;
7
7
  };
8
8
  export type MediaCardSsr = Record<string, MediaCardSsrData>;
@@ -2,11 +2,22 @@
2
2
  import { jsx } from '@emotion/react';
3
3
  import React, { MouseEvent } from 'react';
4
4
  import { MessageDescriptor } from 'react-intl-next';
5
- import { MediaItemType, FileDetails } from '@atlaskit/media-client';
5
+ import { MediaItemType, FileDetails, ImageResizeMode } from '@atlaskit/media-client';
6
6
  import { WithAnalyticsEventsProps, UIAnalyticsEvent } from '@atlaskit/analytics-next';
7
- import { SharedCardProps, CardStatus, CardPreview, MediaCardCursor } from '../../types';
7
+ import { CardStatus, CardPreview, MediaCardCursor, CardDimensions, TitleBoxIcon } from '../../types';
8
+ import { CardAction } from '../actions';
8
9
  import { MediaCardError } from '../../errors';
9
- export interface CardViewV2OwnProps extends SharedCardProps {
10
+ export interface CardViewV2Props {
11
+ readonly disableOverlay?: boolean;
12
+ readonly resizeMode?: ImageResizeMode;
13
+ readonly dimensions: CardDimensions;
14
+ readonly actions?: Array<CardAction>;
15
+ readonly selectable?: boolean;
16
+ readonly selected?: boolean;
17
+ readonly alt?: string;
18
+ readonly testId?: string;
19
+ readonly titleBoxBgColor?: string;
20
+ readonly titleBoxIcon?: TitleBoxIcon;
10
21
  readonly status: CardStatus;
11
22
  readonly mediaItemType: MediaItemType;
12
23
  readonly mediaCardCursor?: MediaCardCursor;
@@ -25,7 +36,7 @@ export interface CardViewV2OwnProps extends SharedCardProps {
25
36
  disableAnimation?: boolean;
26
37
  shouldHideTooltip?: boolean;
27
38
  }
28
- export type CardViewV2Props = CardViewV2OwnProps & WithAnalyticsEventsProps;
39
+ export type CardViewV2BaseProps = CardViewV2Props & WithAnalyticsEventsProps;
29
40
  export interface RenderConfigByStatusV2 {
30
41
  renderTypeIcon?: boolean;
31
42
  iconMessage?: JSX.Element;
@@ -40,5 +51,5 @@ export interface RenderConfigByStatusV2 {
40
51
  renderTickBox?: boolean;
41
52
  customTitleMessage?: MessageDescriptor;
42
53
  }
43
- export declare const CardViewV2Base: ({ innerRef, onImageLoad, onImageError, dimensions, appearance, onClick, onMouseEnter, testId, metadata, status, selected, selectable, cardPreview, mediaCardCursor, shouldHideTooltip, progress, alt, resizeMode, onDisplayImage, nativeLazyLoad, forceSyncDisplay, actions, disableOverlay, titleBoxBgColor, titleBoxIcon, error, disableAnimation, }: CardViewV2Props) => jsx.JSX.Element;
44
- export declare const CardViewV2: React.ForwardRefExoticComponent<Omit<CardViewV2Props, keyof WithAnalyticsEventsProps> & React.RefAttributes<any>>;
54
+ export declare const CardViewV2Base: ({ innerRef, onImageLoad, onImageError, dimensions, onClick, onMouseEnter, testId, metadata, status, selected, selectable, cardPreview, mediaCardCursor, shouldHideTooltip, progress, alt, resizeMode, onDisplayImage, nativeLazyLoad, forceSyncDisplay, actions, disableOverlay, titleBoxBgColor, titleBoxIcon, error, disableAnimation, }: CardViewV2BaseProps) => jsx.JSX.Element;
55
+ export declare const CardViewV2: React.ForwardRefExoticComponent<Omit<CardViewV2BaseProps, keyof WithAnalyticsEventsProps> & React.RefAttributes<any>>;
@@ -1,19 +1,53 @@
1
1
  /// <reference types="react" />
2
2
  import { WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
3
- import { FileIdentifier, Identifier, MediaClient } from '@atlaskit/media-client';
4
- import { SSR } from '@atlaskit/media-common';
5
- import { CardEventProps, SharedCardProps } from '../../types';
6
- export interface FileCardProps extends SharedCardProps, CardEventProps {
7
- readonly mediaClient: MediaClient;
3
+ import { FileIdentifier, Identifier, ImageResizeMode } from '@atlaskit/media-client';
4
+ import { MediaFeatureFlags, NumericalCardDimensions, SSR } from '@atlaskit/media-common';
5
+ import { CardAppearance, CardDimensions, CardEventProps, TitleBoxIcon } from '../../types';
6
+ import { CardAction } from '../actions';
7
+ export interface FileCardProps extends CardEventProps {
8
+ /** Overlay the media file. */
9
+ readonly disableOverlay?: boolean;
10
+ /** Resize the media to 'crop' | 'fit' | 'full-fit' | 'stretchy-fit'. */
11
+ readonly resizeMode?: ImageResizeMode;
12
+ readonly featureFlags?: MediaFeatureFlags;
13
+ /** Sets meida card appearance */
14
+ readonly appearance?: CardAppearance;
15
+ /** Custom media card dimension like width and height. */
16
+ readonly dimensions?: CardDimensions;
17
+ /** Original media card dimension like width and height. */
18
+ readonly originalDimensions?: NumericalCardDimensions;
19
+ /** Array of additional media card actions. */
20
+ readonly actions?: Array<CardAction>;
21
+ /** Enable media card selectable. */
22
+ readonly selectable?: boolean;
23
+ /** Renders media card as selected, if selected is true. */
24
+ readonly selected?: boolean;
25
+ /** Alternate text for an media card. */
26
+ readonly alt?: string;
27
+ /** ID for testing the media card. */
28
+ readonly testId?: string;
29
+ /** Sets the title box background color. */
30
+ readonly titleBoxBgColor?: string;
31
+ /** Sets the title box icon. */
32
+ readonly titleBoxIcon?: TitleBoxIcon;
33
+ /** Instance of file identifier. */
8
34
  readonly identifier: FileIdentifier;
35
+ /** Lazy loads the media file. */
9
36
  readonly isLazy?: boolean;
37
+ /** Uses the inline player for media file. */
10
38
  readonly useInlinePlayer?: boolean;
39
+ /** Uses media MediaViewer to preview the media file. */
11
40
  readonly shouldOpenMediaViewer?: boolean;
41
+ /** Media file list to display in Media Viewer. */
12
42
  readonly mediaViewerItems?: Identifier[];
43
+ /** Retrieve auth based on a given context. */
13
44
  readonly contextId?: string;
45
+ /** Enables the download button for media file. */
14
46
  readonly shouldEnableDownloadButton?: boolean;
47
+ /** Server-Side-Rendering modes are "server" and "client" */
15
48
  readonly ssr?: SSR;
49
+ /** Disable tooltip for the card */
16
50
  readonly shouldHideTooltip?: boolean;
17
51
  }
18
52
  export type FileCardBaseProps = FileCardProps & WithAnalyticsEventsProps;
19
- export declare const FileCard: ({ appearance, resizeMode, isLazy, disableOverlay, featureFlags, identifier, ssr, mediaClient, dimensions, originalDimensions, contextId, alt, actions, shouldEnableDownloadButton, useInlinePlayer, shouldOpenMediaViewer, onFullscreenChange, selectable, selected, testId, titleBoxBgColor, titleBoxIcon, shouldHideTooltip, mediaViewerItems, onClick, onMouseEnter, createAnalyticsEvent, }: FileCardBaseProps) => JSX.Element;
53
+ export declare const FileCard: ({ appearance, resizeMode, isLazy, disableOverlay, featureFlags, identifier, ssr, dimensions, originalDimensions, contextId, alt, actions, shouldEnableDownloadButton, useInlinePlayer, shouldOpenMediaViewer, onFullscreenChange, selectable, selected, testId, titleBoxBgColor, titleBoxIcon, shouldHideTooltip, mediaViewerItems, onClick, onMouseEnter, createAnalyticsEvent, }: FileCardBaseProps) => JSX.Element;
@@ -1,20 +1,16 @@
1
1
  /// <reference types="react" />
2
- import { FileIdentifier, ImageResizeMode, MediaBlobUrlAttrs, MediaClient } from '@atlaskit/media-client';
2
+ import { FileIdentifier, ImageResizeMode, MediaBlobUrlAttrs } from '@atlaskit/media-client';
3
3
  import { MediaTraceContext, NumericalCardDimensions, SSR } from '@atlaskit/media-common';
4
4
  import { MediaCardError } from '../../errors';
5
- import { CardDimensions, CardPreview } from '../../types';
5
+ import { CardPreview } from '../../types';
6
6
  import { SSRStatus } from '../../utils/analytics';
7
7
  export interface UseFilePreviewParams {
8
8
  /** Instance of file identifier. */
9
9
  readonly identifier: FileIdentifier;
10
- /** Instance of MediaClient. */
11
- readonly mediaClient: MediaClient;
12
10
  /** Resize the media to 'crop' | 'fit' | 'full-fit' | 'stretchy-fit' */
13
11
  readonly resizeMode?: ImageResizeMode;
14
- /** Custom media card dimension like width and height. */
15
- readonly dimensions?: CardDimensions;
16
- /** Dimensions to be requested to the server */
17
- readonly requestedDimensions: NumericalCardDimensions;
12
+ /** Dimensions to be requested to the server. Will be scaled x2 in Retina Displays */
13
+ readonly dimensions?: Partial<NumericalCardDimensions>;
18
14
  /** Server-Side-Rendering modes are "server" and "client" */
19
15
  readonly ssr?: SSR;
20
16
  /** Attributes to attach to the created Blob Url */
@@ -26,7 +22,7 @@ export interface UseFilePreviewParams {
26
22
  /** Do not fetch a remote preview. Helpful for lazy loading */
27
23
  readonly skipRemote?: boolean;
28
24
  }
29
- export declare const useFilePreview: ({ resizeMode, identifier, ssr, mediaClient, dimensions, requestedDimensions, traceContext, previewDidRender, skipRemote, mediaBlobUrlAttrs, }: UseFilePreviewParams) => {
25
+ export declare const useFilePreview: ({ resizeMode, identifier, ssr, dimensions, traceContext, previewDidRender, skipRemote, mediaBlobUrlAttrs, }: UseFilePreviewParams) => {
30
26
  cardPreview: CardPreview | undefined;
31
27
  error: MediaCardError | undefined;
32
28
  nonCriticalError: MediaCardError | undefined;
@@ -1,9 +1,26 @@
1
1
  import { CardDimensions } from '../types';
2
2
  import { ElementDimension } from './getElementDimension';
3
3
  import { NumericalCardDimensions } from '@atlaskit/media-common';
4
+ /**
5
+ * ************************************************
6
+ * For Card v1
7
+ * ************************************************
8
+ */
4
9
  export type getDataURIDimensionOptions = {
5
10
  element?: Element | null;
6
11
  dimensions?: CardDimensions;
7
12
  };
8
13
  export declare const getDataURIDimension: (dimension: ElementDimension, options: getDataURIDimensionOptions) => number;
9
14
  export declare const getRequestedDimensions: (options: getDataURIDimensionOptions) => NumericalCardDimensions;
15
+ /**
16
+ * ************************************************
17
+ * For Card v2
18
+ * ************************************************
19
+ */
20
+ type ResolveCardDimensionOptions = {
21
+ element?: Element | null;
22
+ dimensions?: CardDimensions;
23
+ };
24
+ export declare const resolveCardPreviewDimension: (dimensionName: ElementDimension, { dimensions, element }: ResolveCardDimensionOptions) => number;
25
+ export declare const resolveCardPreviewDimensions: (options: ResolveCardDimensionOptions) => NumericalCardDimensions;
26
+ export {};
@@ -11,5 +11,5 @@ export type MediaGlobalScope = {
11
11
  export declare function getMediaGlobalScope(globalScope?: any): MediaGlobalScope;
12
12
  export declare function getMediaCardSSR(globalScope?: any): MediaCardSsr;
13
13
  export declare const getKey: ({ id, collectionName, occurrenceKey }: FileIdentifier) => string;
14
- export declare const storeDataURI: (key: string, dataURI?: string, dimensions?: NumericalCardDimensions, error?: MediaCardErrorInfo, globalScope?: any) => void;
15
- export declare const generateScriptProps: (identifier: FileIdentifier, dataURI?: string, dimensions?: NumericalCardDimensions, error?: MediaCardErrorInfo) => React.ScriptHTMLAttributes<HTMLScriptElement>;
14
+ export declare const storeDataURI: (key: string, dataURI?: string, dimensions?: Partial<NumericalCardDimensions>, error?: MediaCardErrorInfo, globalScope?: any) => void;
15
+ export declare const generateScriptProps: (identifier: FileIdentifier, dataURI?: string, dimensions?: Partial<NumericalCardDimensions>, error?: MediaCardErrorInfo) => React.ScriptHTMLAttributes<HTMLScriptElement>;