@atlaskit/media-card 77.5.2 → 77.6.1

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 (82) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/card/card.js +1 -1
  3. package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
  4. package/dist/cjs/card/v2/cardV2.js +1 -1
  5. package/dist/cjs/card/v2/cardviews/cardViewWrapper.js +100 -0
  6. package/dist/cjs/card/v2/cardviews/errorCardView.js +87 -0
  7. package/dist/cjs/card/v2/cardviews/iconCardView.js +79 -0
  8. package/dist/cjs/card/v2/cardviews/imageCardView.js +89 -0
  9. package/dist/cjs/card/v2/cardviews/index.js +282 -0
  10. package/dist/cjs/card/v2/cardviews/loadingCardView.js +53 -0
  11. package/dist/cjs/card/v2/cardviews/processingCardView.js +65 -0
  12. package/dist/cjs/card/v2/cardviews/videoCardView.js +94 -0
  13. package/dist/cjs/card/v2/fileCard.js +4 -1
  14. package/dist/cjs/card/v2/useFilePreview/analytics.js +50 -0
  15. package/dist/cjs/card/v2/useFilePreview/errors.js +13 -2
  16. package/dist/cjs/card/v2/useFilePreview/helpers.js +1 -1
  17. package/dist/cjs/card/v2/useFilePreview/useFilePreview.js +1 -1
  18. package/dist/cjs/inline/loader.js +1 -1
  19. package/dist/cjs/utils/ufoExperiences.js +1 -1
  20. package/dist/es2019/card/card.js +1 -1
  21. package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
  22. package/dist/es2019/card/v2/cardV2.js +1 -1
  23. package/dist/es2019/card/v2/cardviews/cardViewWrapper.js +92 -0
  24. package/dist/es2019/card/v2/cardviews/errorCardView.js +82 -0
  25. package/dist/es2019/card/v2/cardviews/iconCardView.js +70 -0
  26. package/dist/es2019/card/v2/cardviews/imageCardView.js +75 -0
  27. package/dist/es2019/card/v2/cardviews/index.js +268 -0
  28. package/dist/es2019/card/v2/cardviews/loadingCardView.js +48 -0
  29. package/dist/es2019/card/v2/cardviews/processingCardView.js +60 -0
  30. package/dist/es2019/card/v2/cardviews/videoCardView.js +80 -0
  31. package/dist/es2019/card/v2/fileCard.js +4 -1
  32. package/dist/es2019/card/v2/useFilePreview/analytics.js +44 -0
  33. package/dist/es2019/card/v2/useFilePreview/errors.js +10 -1
  34. package/dist/es2019/card/v2/useFilePreview/helpers.js +1 -1
  35. package/dist/es2019/card/v2/useFilePreview/useFilePreview.js +1 -1
  36. package/dist/es2019/inline/loader.js +1 -1
  37. package/dist/es2019/utils/ufoExperiences.js +1 -1
  38. package/dist/esm/card/card.js +1 -1
  39. package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
  40. package/dist/esm/card/v2/cardV2.js +1 -1
  41. package/dist/esm/card/v2/cardviews/cardViewWrapper.js +93 -0
  42. package/dist/esm/card/v2/cardviews/errorCardView.js +79 -0
  43. package/dist/esm/card/v2/cardviews/iconCardView.js +71 -0
  44. package/dist/esm/card/v2/cardviews/imageCardView.js +81 -0
  45. package/dist/esm/card/v2/cardviews/index.js +271 -0
  46. package/dist/esm/card/v2/cardviews/loadingCardView.js +45 -0
  47. package/dist/esm/card/v2/cardviews/processingCardView.js +57 -0
  48. package/dist/esm/card/v2/cardviews/videoCardView.js +86 -0
  49. package/dist/esm/card/v2/fileCard.js +4 -1
  50. package/dist/esm/card/v2/useFilePreview/analytics.js +44 -0
  51. package/dist/esm/card/v2/useFilePreview/errors.js +10 -1
  52. package/dist/esm/card/v2/useFilePreview/helpers.js +1 -1
  53. package/dist/esm/card/v2/useFilePreview/useFilePreview.js +1 -1
  54. package/dist/esm/inline/loader.js +1 -1
  55. package/dist/esm/utils/ufoExperiences.js +1 -1
  56. package/dist/types/card/ui/wrapper/types.d.ts +2 -2
  57. package/dist/types/card/v2/cardviews/cardViewWrapper.d.ts +38 -0
  58. package/dist/types/card/v2/cardviews/errorCardView.d.ts +11 -0
  59. package/dist/types/card/v2/cardviews/iconCardView.d.ts +12 -0
  60. package/dist/types/card/v2/cardviews/imageCardView.d.ts +21 -0
  61. package/dist/types/card/v2/cardviews/index.d.ts +45 -0
  62. package/dist/types/card/v2/cardviews/loadingCardView.d.ts +10 -0
  63. package/dist/types/card/v2/cardviews/processingCardView.d.ts +8 -0
  64. package/dist/types/card/v2/cardviews/videoCardView.d.ts +21 -0
  65. package/dist/types/card/v2/useFilePreview/analytics.d.ts +28 -0
  66. package/dist/types/card/v2/useFilePreview/errors.d.ts +4 -0
  67. package/dist/types/card/v2/useFilePreview/helpers.d.ts +1 -1
  68. package/dist/types/card/v2/useFilePreview/useFilePreview.d.ts +1 -1
  69. package/dist/types-ts4.5/card/ui/wrapper/types.d.ts +2 -2
  70. package/dist/types-ts4.5/card/v2/cardviews/cardViewWrapper.d.ts +38 -0
  71. package/dist/types-ts4.5/card/v2/cardviews/errorCardView.d.ts +11 -0
  72. package/dist/types-ts4.5/card/v2/cardviews/iconCardView.d.ts +12 -0
  73. package/dist/types-ts4.5/card/v2/cardviews/imageCardView.d.ts +21 -0
  74. package/dist/types-ts4.5/card/v2/cardviews/index.d.ts +45 -0
  75. package/dist/types-ts4.5/card/v2/cardviews/loadingCardView.d.ts +10 -0
  76. package/dist/types-ts4.5/card/v2/cardviews/processingCardView.d.ts +8 -0
  77. package/dist/types-ts4.5/card/v2/cardviews/videoCardView.d.ts +21 -0
  78. package/dist/types-ts4.5/card/v2/useFilePreview/analytics.d.ts +28 -0
  79. package/dist/types-ts4.5/card/v2/useFilePreview/errors.d.ts +4 -0
  80. package/dist/types-ts4.5/card/v2/useFilePreview/helpers.d.ts +1 -1
  81. package/dist/types-ts4.5/card/v2/useFilePreview/useFilePreview.d.ts +1 -1
  82. package/package.json +7 -5
@@ -0,0 +1,60 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+ import { jsx } from '@emotion/react';
4
+ import { useEffect, useRef } from 'react';
5
+ import { withAnalyticsEvents } from '@atlaskit/analytics-next';
6
+ import { MimeTypeIcon } from '@atlaskit/media-ui/mime-type-icon';
7
+ import { createAndFireMediaCardEvent } from '../../../utils/analytics';
8
+ import { IconWrapper } from '../../ui/iconWrapper/iconWrapper';
9
+ import { CreatingPreview } from '../../ui/iconMessage';
10
+ import { useBreakpoint } from '../../useBreakpoint';
11
+ import { CardViewWrapper } from './cardViewWrapper';
12
+ const ProcessingCardViewBase = props => {
13
+ const {
14
+ disableAnimation,
15
+ dimensions,
16
+ metadata,
17
+ disableOverlay,
18
+ innerRef
19
+ } = props;
20
+ const divRef = useRef(null);
21
+ const breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
22
+ useEffect(() => {
23
+ innerRef && !!divRef.current && innerRef(divRef.current);
24
+ }, [innerRef]);
25
+ const {
26
+ name,
27
+ size,
28
+ mediaType,
29
+ mimeType
30
+ } = metadata || {};
31
+ const isZeroSize = size === 0;
32
+ const hasTitleBox = !disableOverlay && !!name;
33
+ return jsx(CardViewWrapper, _extends({}, props, {
34
+ metadata: metadata,
35
+ breakpoint: breakpoint,
36
+ "data-test-status": "processing",
37
+ ref: divRef
38
+ }), jsx(IconWrapper, {
39
+ breakpoint: breakpoint,
40
+ hasTitleBox: hasTitleBox
41
+ }, jsx(MimeTypeIcon, {
42
+ testId: "media-card-file-type-icon",
43
+ mediaType: mediaType,
44
+ mimeType: mimeType,
45
+ name: name
46
+ }), !isZeroSize && jsx(CreatingPreview, {
47
+ disableAnimation: disableAnimation
48
+ })));
49
+ };
50
+
51
+ // TODO: check if analytics is correct
52
+
53
+ export const ProcessingCardView = withAnalyticsEvents({
54
+ onClick: createAndFireMediaCardEvent({
55
+ eventType: 'ui',
56
+ action: 'clicked',
57
+ actionSubject: 'mediaCard',
58
+ attributes: {}
59
+ })
60
+ })(ProcessingCardViewBase);
@@ -0,0 +1,80 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+ import { jsx } from '@emotion/react';
4
+ import { useEffect, useRef } from 'react';
5
+ import { withAnalyticsEvents } from '@atlaskit/analytics-next';
6
+ import { createAndFireMediaCardEvent } from '../../../utils/analytics';
7
+ import { IconWrapper } from '../../ui/iconWrapper/iconWrapper';
8
+ import { PlayButton } from '../../ui/playButton/playButton';
9
+ import { ImageRenderer } from '../../ui/imageRenderer/imageRenderer';
10
+ import { useBreakpoint } from '../../useBreakpoint';
11
+ import { CardViewWrapper } from './cardViewWrapper';
12
+ import { ProgressBar } from '../../ui/progressBar/progressBar';
13
+ import { Blanket } from '../../ui/blanket/blanket';
14
+ const VideoCardViewBase = props => {
15
+ const {
16
+ status,
17
+ dimensions,
18
+ metadata,
19
+ disableOverlay,
20
+ innerRef,
21
+ progress,
22
+ cardPreview,
23
+ alt,
24
+ resizeMode,
25
+ onDisplayImage,
26
+ nativeLazyLoad,
27
+ forceSyncDisplay,
28
+ onImageLoad,
29
+ onImageError
30
+ } = props;
31
+ const divRef = useRef(null);
32
+ const breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
33
+ useEffect(() => {
34
+ innerRef && !!divRef.current && innerRef(divRef.current);
35
+ }, [innerRef]);
36
+ const {
37
+ name,
38
+ mediaType = 'unknown'
39
+ } = metadata || {};
40
+ const hasTitleBox = !disableOverlay && !!name;
41
+ const isUploading = status === 'uploading';
42
+ return jsx(CardViewWrapper, _extends({}, props, {
43
+ breakpoint: breakpoint,
44
+ "data-test-status": status,
45
+ "data-test-progress": progress,
46
+ ref: divRef,
47
+ customBlanket: () => disableOverlay ? null : jsx(Blanket, {
48
+ isFixed: isUploading
49
+ }),
50
+ progressBar: isUploading ? () => jsx(ProgressBar, {
51
+ progress: progress,
52
+ breakpoint: breakpoint,
53
+ positionBottom: !hasTitleBox
54
+ }) : undefined
55
+ }), jsx(ImageRenderer, {
56
+ cardPreview: cardPreview,
57
+ mediaType: mediaType,
58
+ alt: alt,
59
+ resizeMode: resizeMode,
60
+ onDisplayImage: onDisplayImage,
61
+ onImageLoad: () => onImageLoad === null || onImageLoad === void 0 ? void 0 : onImageLoad(cardPreview),
62
+ onImageError: () => onImageError === null || onImageError === void 0 ? void 0 : onImageError(cardPreview),
63
+ nativeLazyLoad: nativeLazyLoad,
64
+ forceSyncDisplay: forceSyncDisplay
65
+ }), cardPreview && jsx(IconWrapper, {
66
+ breakpoint: breakpoint,
67
+ hasTitleBox: hasTitleBox
68
+ }, jsx(PlayButton, null)));
69
+ };
70
+
71
+ // TODO: check if analytics is correct
72
+
73
+ export const VideoCardView = withAnalyticsEvents({
74
+ onClick: createAndFireMediaCardEvent({
75
+ eventType: 'ui',
76
+ action: 'clicked',
77
+ actionSubject: 'mediaCard',
78
+ attributes: {}
79
+ })
80
+ })(VideoCardViewBase);
@@ -1,3 +1,4 @@
1
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
1
2
  import DownloadIcon from '@atlaskit/icon/glyph/download';
2
3
  import { globalMediaEventEmitter, isImageRepresentationReady, RECENTS_COLLECTION } from '@atlaskit/media-client';
3
4
  import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/media-client-react';
@@ -20,8 +21,10 @@ import { getDefaultCardDimensions } from '../../utils/cardDimensions';
20
21
  import { fireCommencedEvent, fireCopiedEvent, fireNonCriticalErrorEvent, fireOperationalEvent, fireScreenEvent } from '../cardAnalytics';
21
22
  import { isSSRPreview } from '../getCardPreview';
22
23
  import { CardViewV2 } from './cardViewV2';
24
+ import { CardViews } from './cardviews';
23
25
  import { InlinePlayerLazyV2 } from './inlinePlayerLazyV2';
24
26
  import { useFilePreview } from './useFilePreview';
27
+ const LoadedCardView = getBooleanFF('platform.media-experience.card-views-refactor_b91lr') ? CardViews : CardViewV2;
25
28
  export const FileCard = ({
26
29
  appearance = 'auto',
27
30
  resizeMode = 'crop',
@@ -468,7 +471,7 @@ export const FileCard = ({
468
471
  // Force Media Image to always display img for SSR
469
472
  const forceSyncDisplay = !!ssr;
470
473
  const mediaCardCursor = getMediaCardCursor(!!useInlinePlayer, !!shouldOpenMediaViewer, finalStatus === 'error' || finalStatus === 'failed-processing', !!cardPreview, metadata.mediaType);
471
- const card = /*#__PURE__*/React.createElement(CardViewV2, {
474
+ const card = /*#__PURE__*/React.createElement(LoadedCardView, {
472
475
  status: cardStatusOverride || finalStatus,
473
476
  error: finalError,
474
477
  mediaItemType: mediaItemType,
@@ -0,0 +1,44 @@
1
+ import { getMediaClientErrorReason, isRequestError } from '@atlaskit/media-client';
2
+ import { isMediaFilePreviewError, getFileStateErrorReason, isMediaFileStateError } from './errors';
3
+ export const getErrorTraceContext = error => {
4
+ if (isMediaFilePreviewError(error) && !!error.secondaryError) {
5
+ if (isRequestError(error.secondaryError)) {
6
+ var _error$secondaryError;
7
+ return (_error$secondaryError = error.secondaryError.metadata) === null || _error$secondaryError === void 0 ? void 0 : _error$secondaryError.traceContext;
8
+ } else if (isMediaFileStateError(error.secondaryError)) {
9
+ var _error$secondaryError2, _error$secondaryError3;
10
+ return (_error$secondaryError2 = error.secondaryError.details) === null || _error$secondaryError2 === void 0 ? void 0 : (_error$secondaryError3 = _error$secondaryError2.metadata) === null || _error$secondaryError3 === void 0 ? void 0 : _error$secondaryError3.traceContext;
11
+ }
12
+ }
13
+ };
14
+ export const getRenderErrorFailReason = error => {
15
+ if (isMediaFilePreviewError(error)) {
16
+ return error.primaryReason;
17
+ } else {
18
+ return 'nativeError';
19
+ }
20
+ };
21
+ export const getRenderErrorErrorReason = error => {
22
+ if (isMediaFilePreviewError(error) && error.secondaryError) {
23
+ const mediaClientReason = isMediaFileStateError(error.secondaryError) ? getFileStateErrorReason(error.secondaryError) : getMediaClientErrorReason(error.secondaryError);
24
+ if (mediaClientReason !== 'unknown') {
25
+ return mediaClientReason;
26
+ }
27
+ }
28
+ return 'nativeError';
29
+ };
30
+ export const getRenderErrorErrorDetail = error => {
31
+ if (isMediaFilePreviewError(error) && error.secondaryError) {
32
+ return error.secondaryError.message;
33
+ } else {
34
+ return error.message;
35
+ }
36
+ };
37
+ export const extractErrorInfo = (error, metadataTraceContext) => {
38
+ return {
39
+ failReason: getRenderErrorFailReason(error),
40
+ error: getRenderErrorErrorReason(error),
41
+ errorDetail: getRenderErrorErrorDetail(error),
42
+ metadataTraceContext: metadataTraceContext !== null && metadataTraceContext !== void 0 ? metadataTraceContext : getErrorTraceContext(error)
43
+ };
44
+ };
@@ -1,3 +1,5 @@
1
+ import { MediaFileStateError } from '@atlaskit/media-client-react';
2
+
1
3
  /**
2
4
  * Primary reason is logged through Data Portal.
3
5
  * Make sure all the values are whitelisted in Measure -> Event Regitry -> "mediaCardRender failed" event
@@ -78,4 +80,11 @@ export const ensureMediaFilePreviewError = (primaryReason, error, updatePrimaryR
78
80
  return error;
79
81
  }
80
82
  return new MediaFilePreviewError(primaryReason, error);
81
- };
83
+ };
84
+ export function isMediaFileStateError(err) {
85
+ return err instanceof MediaFileStateError;
86
+ }
87
+ export function getFileStateErrorReason(err) {
88
+ var _err$details$reason, _err$details;
89
+ return (_err$details$reason = (_err$details = err.details) === null || _err$details === void 0 ? void 0 : _err$details.reason) !== null && _err$details$reason !== void 0 ? _err$details$reason : 'unknown';
90
+ }
@@ -46,7 +46,7 @@ export const createRequestDimensions = dimensions => {
46
46
  return result;
47
47
  };
48
48
 
49
- /** Stores the provided value in a */
49
+ /** Stores the provided value in a ref object to avoid "component rerenders" when the value is used as a hook dependency */
50
50
  export function useCurrentValueRef(value) {
51
51
  const ref = useRef(value);
52
52
  ref.current = value;
@@ -3,7 +3,7 @@ import { MediaFileStateError, useFileState, useMediaClient } from '@atlaskit/med
3
3
  import { isMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
4
4
  import { useEffect, useMemo, useRef, useState } from 'react';
5
5
  import { ensureMediaFilePreviewError, ImageLoadError, isLocalPreviewError, isUnsupportedLocalPreviewError, MediaFilePreviewError } from './errors';
6
- import { extractErrorInfo } from '../../../utils/analytics';
6
+ import { extractErrorInfo } from './analytics';
7
7
  import { isBigger, createRequestDimensions, useCurrentValueRef, usePrevious } from './helpers';
8
8
  import { generateScriptProps, getSSRData } from './globalScope';
9
9
  import { getAndCacheRemotePreview, getSSRCardPreview, isLocalPreview, isSSRClientPreview, isSSRDataPreview, isPreviewableStatus, extractFilePreviewStatus, mediaFilePreviewCache, getAndCacheLocalPreview } from './getPreview';
@@ -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.5.2",
40
+ packageName: "77.6.1",
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.5.2";
7
+ const packageVersion = "77.6.1";
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.5.2";
43
+ var packageVersion = "77.6.1";
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.5.2";
86
+ var packageVersion = "77.6.1";
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.5.2";
12
+ var packageVersion = "77.6.1";
13
13
  export var CardV2Base = function CardV2Base(_ref) {
14
14
  var identifier = _ref.identifier,
15
15
  otherProps = _objectWithoutProperties(_ref, _excluded);
@@ -0,0 +1,93 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["cardPreview", "testId", "dimensions", "appearance", "metadata", "selected", "selectable", "actions", "breakpoint", "disableOverlay", "titleBoxBgColor", "titleBoxIcon", "shouldHideTooltip", "children", "onClick", "onMouseEnter", "mediaCardCursor", "customBlanket", "customTitleBox", "progressBar"];
4
+ /** @jsx jsx */
5
+ import { jsx } from '@emotion/react';
6
+ import React from 'react';
7
+ import Tooltip from '@atlaskit/tooltip';
8
+ import { Wrapper } from '../../ui/wrapper';
9
+ import { attachDetailsToActions } from '../../actions';
10
+ import { cardImageContainerStyles } from '../../ui/styles';
11
+ import { TitleBox } from '../../ui/titleBox/titleBox';
12
+ import { TickBox } from '../../ui/tickBox/tickBox';
13
+ import { Blanket } from '../../ui/blanket/blanket';
14
+ import { ActionsBar } from '../../ui/actionsBar/actionsBar';
15
+ import { fileCardImageViewSelector } from '../../classnames';
16
+ export var CardViewWrapper = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
17
+ var cardPreview = _ref.cardPreview,
18
+ testId = _ref.testId,
19
+ dimensions = _ref.dimensions,
20
+ _ref$appearance = _ref.appearance,
21
+ appearance = _ref$appearance === void 0 ? 'auto' : _ref$appearance,
22
+ metadata = _ref.metadata,
23
+ selected = _ref.selected,
24
+ selectable = _ref.selectable,
25
+ actions = _ref.actions,
26
+ breakpoint = _ref.breakpoint,
27
+ disableOverlay = _ref.disableOverlay,
28
+ titleBoxBgColor = _ref.titleBoxBgColor,
29
+ titleBoxIcon = _ref.titleBoxIcon,
30
+ shouldHideTooltip = _ref.shouldHideTooltip,
31
+ children = _ref.children,
32
+ onClick = _ref.onClick,
33
+ onMouseEnter = _ref.onMouseEnter,
34
+ mediaCardCursor = _ref.mediaCardCursor,
35
+ customBlanket = _ref.customBlanket,
36
+ customTitleBox = _ref.customTitleBox,
37
+ progressBar = _ref.progressBar,
38
+ props = _objectWithoutProperties(_ref, _excluded);
39
+ var _ref2 = metadata || {},
40
+ name = _ref2.name,
41
+ createdAt = _ref2.createdAt,
42
+ mediaType = _ref2.mediaType;
43
+ var actionsWithDetails = metadata && actions ? attachDetailsToActions(actions, metadata) : [];
44
+ var defaultBlanket = !disableOverlay && jsx(Blanket, null);
45
+ var defaultTitleBox = !disableOverlay && !!name && jsx(TitleBox, {
46
+ name: name,
47
+ createdAt: createdAt,
48
+ breakpoint: breakpoint,
49
+ titleBoxIcon: titleBoxIcon,
50
+ titleBoxBgColor: titleBoxBgColor
51
+ });
52
+ var content = jsx(React.Fragment, null, jsx("div", _extends({
53
+ css: cardImageContainerStyles,
54
+ className: fileCardImageViewSelector,
55
+ "data-testid": fileCardImageViewSelector,
56
+ "data-test-media-name": name,
57
+ "data-test-selected": selected ? true : undefined
58
+ }, props), children, customBlanket ? customBlanket() : defaultBlanket, customTitleBox ? customTitleBox() : defaultTitleBox, !disableOverlay && !!selectable && jsx(TickBox, {
59
+ selected: selected
60
+ }), progressBar && progressBar()), !disableOverlay && actions && actions.length !== 0 && jsx(ActionsBar, {
61
+ actions: actionsWithDetails
62
+ }));
63
+ var shouldRenderPlayButton = function shouldRenderPlayButton() {
64
+ if (mediaType !== 'video' || !cardPreview) {
65
+ return false;
66
+ }
67
+ return true;
68
+ };
69
+ var isPlayButtonClickable = shouldRenderPlayButton() && disableOverlay;
70
+ var isTickBoxSelectable = !disableOverlay && !!selectable && !selected;
71
+ var shouldDisplayTooltip = !disableOverlay && !shouldHideTooltip;
72
+ var shouldDisplayBackground = !cardPreview || !disableOverlay;
73
+ return jsx(Wrapper, {
74
+ testId: testId || 'media-card-view',
75
+ dimensions: dimensions,
76
+ appearance: appearance,
77
+ onClick: onClick,
78
+ onMouseEnter: onMouseEnter,
79
+ innerRef: ref,
80
+ breakpoint: breakpoint,
81
+ mediaCardCursor: mediaCardCursor,
82
+ disableOverlay: !!disableOverlay,
83
+ selected: !!selected,
84
+ displayBackground: shouldDisplayBackground,
85
+ isPlayButtonClickable: !!isPlayButtonClickable,
86
+ isTickBoxSelectable: isTickBoxSelectable,
87
+ shouldDisplayTooltip: shouldDisplayTooltip
88
+ }, shouldDisplayTooltip ? jsx(Tooltip, {
89
+ content: name,
90
+ position: "bottom",
91
+ tag: "div"
92
+ }, content) : content);
93
+ });
@@ -0,0 +1,79 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+ import { jsx } from '@emotion/react';
4
+ import { useRef } from 'react';
5
+ import { withAnalyticsEvents } from '@atlaskit/analytics-next';
6
+ import { createAndFireMediaCardEvent } from '../../../utils/analytics';
7
+ import { useBreakpoint } from '../../useBreakpoint';
8
+ import { CardViewWrapper } from './cardViewWrapper';
9
+ import { MimeTypeIcon } from '@atlaskit/media-ui/mime-type-icon';
10
+ import { IconWrapper } from '../../ui/iconWrapper/iconWrapper';
11
+ import { FailedTitleBox } from '../../ui/titleBox/failedTitleBox';
12
+ import { PreviewUnavailable, FailedToUpload, PreviewCurrentlyUnavailable, FailedToLoad } from '../../ui/iconMessage';
13
+ import { isUploadError, isRateLimitedError, isPollingError } from '../../../errors';
14
+ import { messages } from '@atlaskit/media-ui';
15
+ var IconMessage = function IconMessage(_ref) {
16
+ var error = _ref.error,
17
+ metadata = _ref.metadata;
18
+ var _ref2 = error || {},
19
+ secondaryError = _ref2.secondaryError;
20
+ if (isRateLimitedError(secondaryError) || isPollingError(secondaryError)) {
21
+ return jsx(PreviewCurrentlyUnavailable, null);
22
+ } else if (isUploadError(error)) {
23
+ return jsx(FailedToUpload, null);
24
+ } else if (!metadata) {
25
+ return jsx(FailedToLoad, null);
26
+ } else {
27
+ return jsx(PreviewUnavailable, null);
28
+ }
29
+ };
30
+ var ErrorCardViewBase = function ErrorCardViewBase(props) {
31
+ var error = props.error,
32
+ metadata = props.metadata,
33
+ dimensions = props.dimensions,
34
+ disableOverlay = props.disableOverlay;
35
+ var _ref3 = metadata || {},
36
+ name = _ref3.name,
37
+ mediaType = _ref3.mediaType,
38
+ mimeType = _ref3.mimeType;
39
+ var divRef = useRef(null);
40
+ var breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
41
+ var customMessage = isUploadError(props.error) ? messages.failed_to_upload : undefined;
42
+ var renderFailedTitleBox = !disableOverlay && (!name || !!customMessage);
43
+ var renderTitleBox = !disableOverlay && !!name && !customMessage;
44
+ var hasTitleBox = !!renderTitleBox || !!renderFailedTitleBox;
45
+ return jsx(CardViewWrapper, _extends({}, props, {
46
+ metadata: metadata,
47
+ breakpoint: breakpoint,
48
+ "data-test-status": "error",
49
+ ref: divRef,
50
+ customTitleBox: renderFailedTitleBox ? function () {
51
+ return jsx(FailedTitleBox, {
52
+ breakpoint: breakpoint,
53
+ customMessage: customMessage
54
+ });
55
+ } : undefined
56
+ }), jsx(IconWrapper, {
57
+ breakpoint: breakpoint,
58
+ hasTitleBox: hasTitleBox
59
+ }, jsx(MimeTypeIcon, {
60
+ testId: "media-card-file-type-icon",
61
+ mediaType: mediaType,
62
+ mimeType: mimeType,
63
+ name: name
64
+ }), !renderFailedTitleBox && jsx(IconMessage, {
65
+ error: error,
66
+ metadata: metadata
67
+ })));
68
+ };
69
+
70
+ // TODO: check if analytics is correct
71
+
72
+ export var ErrorCardView = withAnalyticsEvents({
73
+ onClick: createAndFireMediaCardEvent({
74
+ eventType: 'ui',
75
+ action: 'clicked',
76
+ actionSubject: 'mediaCard',
77
+ attributes: {}
78
+ })
79
+ })(ErrorCardViewBase);
@@ -0,0 +1,71 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+ import { jsx } from '@emotion/react';
4
+ import { useEffect, useRef } from 'react';
5
+ import { MimeTypeIcon } from '@atlaskit/media-ui/mime-type-icon';
6
+ import { withAnalyticsEvents } from '@atlaskit/analytics-next';
7
+ import { createAndFireMediaCardEvent } from '../../../utils/analytics';
8
+ import { IconWrapper } from '../../ui/iconWrapper/iconWrapper';
9
+ import { useBreakpoint } from '../../useBreakpoint';
10
+ import { CardViewWrapper } from './cardViewWrapper';
11
+ import { ProgressBar } from '../../ui/progressBar/progressBar';
12
+ import { Blanket } from '../../ui/blanket/blanket';
13
+ // NOTE: should we call this Icon or UploadingCardView since we now have ProgressBar?
14
+
15
+ var IconCardViewBase = function IconCardViewBase(props) {
16
+ var dimensions = props.dimensions,
17
+ metadata = props.metadata,
18
+ disableOverlay = props.disableOverlay,
19
+ innerRef = props.innerRef,
20
+ progress = props.progress,
21
+ status = props.status;
22
+ var divRef = useRef(null);
23
+ var breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
24
+ useEffect(function () {
25
+ innerRef && !!divRef.current && innerRef(divRef.current);
26
+ }, [innerRef]);
27
+ var _ref = metadata || {},
28
+ name = _ref.name,
29
+ mediaType = _ref.mediaType,
30
+ mimeType = _ref.mimeType;
31
+ var hasTitleBox = !disableOverlay && !!name;
32
+ var isUploading = status === 'uploading';
33
+ return jsx(CardViewWrapper, _extends({}, props, {
34
+ metadata: metadata,
35
+ breakpoint: breakpoint,
36
+ "data-test-status": status,
37
+ "data-test-progress": progress,
38
+ ref: divRef,
39
+ customBlanket: function customBlanket() {
40
+ return jsx(Blanket, {
41
+ isFixed: isUploading
42
+ });
43
+ },
44
+ progressBar: isUploading ? function () {
45
+ return jsx(ProgressBar, {
46
+ progress: progress,
47
+ breakpoint: breakpoint,
48
+ positionBottom: !hasTitleBox
49
+ });
50
+ } : undefined
51
+ }), jsx(IconWrapper, {
52
+ breakpoint: breakpoint,
53
+ hasTitleBox: hasTitleBox
54
+ }, jsx(MimeTypeIcon, {
55
+ testId: "media-card-file-type-icon",
56
+ mediaType: mediaType,
57
+ mimeType: mimeType,
58
+ name: name
59
+ })));
60
+ };
61
+
62
+ // TODO: check if analytics is correct
63
+
64
+ export var IconCardView = withAnalyticsEvents({
65
+ onClick: createAndFireMediaCardEvent({
66
+ eventType: 'ui',
67
+ action: 'clicked',
68
+ actionSubject: 'mediaCard',
69
+ attributes: {}
70
+ })
71
+ })(IconCardViewBase);
@@ -0,0 +1,81 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+ import { jsx } from '@emotion/react';
4
+ import { useEffect, useRef } from 'react';
5
+ import { withAnalyticsEvents } from '@atlaskit/analytics-next';
6
+ import { createAndFireMediaCardEvent } from '../../../utils/analytics';
7
+ import { ImageRenderer } from '../../ui/imageRenderer/imageRenderer';
8
+ import { useBreakpoint } from '../../useBreakpoint';
9
+ import { CardViewWrapper } from './cardViewWrapper';
10
+ import { ProgressBar } from '../../ui/progressBar/progressBar';
11
+ import { Blanket } from '../../ui/blanket/blanket';
12
+ var ImageCardViewBase = function ImageCardViewBase(props) {
13
+ var status = props.status,
14
+ dimensions = props.dimensions,
15
+ metadata = props.metadata,
16
+ disableOverlay = props.disableOverlay,
17
+ innerRef = props.innerRef,
18
+ progress = props.progress,
19
+ cardPreview = props.cardPreview,
20
+ alt = props.alt,
21
+ resizeMode = props.resizeMode,
22
+ onDisplayImage = props.onDisplayImage,
23
+ nativeLazyLoad = props.nativeLazyLoad,
24
+ forceSyncDisplay = props.forceSyncDisplay,
25
+ _onImageLoad = props.onImageLoad,
26
+ _onImageError = props.onImageError;
27
+ var divRef = useRef(null);
28
+ var breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
29
+ useEffect(function () {
30
+ innerRef && !!divRef.current && innerRef(divRef.current);
31
+ }, [innerRef]);
32
+ var _ref = metadata || {},
33
+ name = _ref.name,
34
+ _ref$mediaType = _ref.mediaType,
35
+ mediaType = _ref$mediaType === void 0 ? 'unknown' : _ref$mediaType;
36
+ var hasTitleBox = !disableOverlay && !!name;
37
+ var isUploading = status === 'uploading';
38
+ return jsx(CardViewWrapper, _extends({}, props, {
39
+ breakpoint: breakpoint,
40
+ "data-test-status": status,
41
+ "data-test-progress": progress,
42
+ ref: divRef,
43
+ customBlanket: function customBlanket() {
44
+ return jsx(Blanket, {
45
+ isFixed: isUploading
46
+ });
47
+ },
48
+ progressBar: isUploading ? function () {
49
+ return jsx(ProgressBar, {
50
+ progress: progress,
51
+ breakpoint: breakpoint,
52
+ positionBottom: !hasTitleBox
53
+ });
54
+ } : undefined
55
+ }), jsx(ImageRenderer, {
56
+ cardPreview: cardPreview,
57
+ mediaType: mediaType,
58
+ alt: alt,
59
+ resizeMode: resizeMode,
60
+ onDisplayImage: onDisplayImage,
61
+ onImageLoad: function onImageLoad() {
62
+ return _onImageLoad === null || _onImageLoad === void 0 ? void 0 : _onImageLoad(cardPreview);
63
+ },
64
+ onImageError: function onImageError() {
65
+ return _onImageError === null || _onImageError === void 0 ? void 0 : _onImageError(cardPreview);
66
+ },
67
+ nativeLazyLoad: nativeLazyLoad,
68
+ forceSyncDisplay: forceSyncDisplay
69
+ }));
70
+ };
71
+
72
+ // TODO: check if analytics is correct
73
+
74
+ export var ImageCardView = withAnalyticsEvents({
75
+ onClick: createAndFireMediaCardEvent({
76
+ eventType: 'ui',
77
+ action: 'clicked',
78
+ actionSubject: 'mediaCard',
79
+ attributes: {}
80
+ })
81
+ })(ImageCardViewBase);