@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
@@ -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.5.2";
69
+ const packageVersion = "77.6.1";
70
70
  const MediaCardAnalyticsErrorBoundary = withMediaAnalyticsContext({
71
71
  packageVersion,
72
72
  packageName,
@@ -7,7 +7,7 @@ import { IntlProvider, injectIntl } from 'react-intl-next';
7
7
  import { ExternalImageCard } from './externalImageCard';
8
8
  import { FileCard } from './fileCard';
9
9
  const packageName = "@atlaskit/media-card";
10
- const packageVersion = "77.5.2";
10
+ const packageVersion = "77.6.1";
11
11
  export const CardV2Base = ({
12
12
  identifier,
13
13
  ...otherProps
@@ -0,0 +1,92 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+ import { jsx } from '@emotion/react';
4
+ import React from 'react';
5
+ import Tooltip from '@atlaskit/tooltip';
6
+ import { Wrapper } from '../../ui/wrapper';
7
+ import { attachDetailsToActions } from '../../actions';
8
+ import { cardImageContainerStyles } from '../../ui/styles';
9
+ import { TitleBox } from '../../ui/titleBox/titleBox';
10
+ import { TickBox } from '../../ui/tickBox/tickBox';
11
+ import { Blanket } from '../../ui/blanket/blanket';
12
+ import { ActionsBar } from '../../ui/actionsBar/actionsBar';
13
+ import { fileCardImageViewSelector } from '../../classnames';
14
+ export const CardViewWrapper = /*#__PURE__*/React.forwardRef(({
15
+ cardPreview,
16
+ testId,
17
+ dimensions,
18
+ appearance = 'auto',
19
+ metadata,
20
+ selected,
21
+ selectable,
22
+ actions,
23
+ breakpoint,
24
+ disableOverlay,
25
+ titleBoxBgColor,
26
+ titleBoxIcon,
27
+ shouldHideTooltip,
28
+ children,
29
+ onClick,
30
+ onMouseEnter,
31
+ mediaCardCursor,
32
+ customBlanket,
33
+ customTitleBox,
34
+ progressBar,
35
+ ...props
36
+ }, ref) => {
37
+ const {
38
+ name,
39
+ createdAt,
40
+ mediaType
41
+ } = metadata || {};
42
+ const actionsWithDetails = metadata && actions ? attachDetailsToActions(actions, metadata) : [];
43
+ const defaultBlanket = !disableOverlay && jsx(Blanket, null);
44
+ const defaultTitleBox = !disableOverlay && !!name && jsx(TitleBox, {
45
+ name: name,
46
+ createdAt: createdAt,
47
+ breakpoint: breakpoint,
48
+ titleBoxIcon: titleBoxIcon,
49
+ titleBoxBgColor: titleBoxBgColor
50
+ });
51
+ const content = jsx(React.Fragment, null, jsx("div", _extends({
52
+ css: cardImageContainerStyles,
53
+ className: fileCardImageViewSelector,
54
+ "data-testid": fileCardImageViewSelector,
55
+ "data-test-media-name": name,
56
+ "data-test-selected": selected ? true : undefined
57
+ }, props), children, customBlanket ? customBlanket() : defaultBlanket, customTitleBox ? customTitleBox() : defaultTitleBox, !disableOverlay && !!selectable && jsx(TickBox, {
58
+ selected: selected
59
+ }), progressBar && progressBar()), !disableOverlay && actions && actions.length !== 0 && jsx(ActionsBar, {
60
+ actions: actionsWithDetails
61
+ }));
62
+ const shouldRenderPlayButton = () => {
63
+ if (mediaType !== 'video' || !cardPreview) {
64
+ return false;
65
+ }
66
+ return true;
67
+ };
68
+ const isPlayButtonClickable = shouldRenderPlayButton() && disableOverlay;
69
+ const isTickBoxSelectable = !disableOverlay && !!selectable && !selected;
70
+ const shouldDisplayTooltip = !disableOverlay && !shouldHideTooltip;
71
+ const shouldDisplayBackground = !cardPreview || !disableOverlay;
72
+ return jsx(Wrapper, {
73
+ testId: testId || 'media-card-view',
74
+ dimensions: dimensions,
75
+ appearance: appearance,
76
+ onClick: onClick,
77
+ onMouseEnter: onMouseEnter,
78
+ innerRef: ref,
79
+ breakpoint: breakpoint,
80
+ mediaCardCursor: mediaCardCursor,
81
+ disableOverlay: !!disableOverlay,
82
+ selected: !!selected,
83
+ displayBackground: shouldDisplayBackground,
84
+ isPlayButtonClickable: !!isPlayButtonClickable,
85
+ isTickBoxSelectable: isTickBoxSelectable,
86
+ shouldDisplayTooltip: shouldDisplayTooltip
87
+ }, shouldDisplayTooltip ? jsx(Tooltip, {
88
+ content: name,
89
+ position: "bottom",
90
+ tag: "div"
91
+ }, content) : content);
92
+ });
@@ -0,0 +1,82 @@
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
+ const IconMessage = ({
16
+ error,
17
+ metadata
18
+ }) => {
19
+ const {
20
+ secondaryError
21
+ } = error || {};
22
+ if (isRateLimitedError(secondaryError) || isPollingError(secondaryError)) {
23
+ return jsx(PreviewCurrentlyUnavailable, null);
24
+ } else if (isUploadError(error)) {
25
+ return jsx(FailedToUpload, null);
26
+ } else if (!metadata) {
27
+ return jsx(FailedToLoad, null);
28
+ } else {
29
+ return jsx(PreviewUnavailable, null);
30
+ }
31
+ };
32
+ const ErrorCardViewBase = props => {
33
+ const {
34
+ error,
35
+ metadata,
36
+ dimensions,
37
+ disableOverlay
38
+ } = props;
39
+ const {
40
+ name,
41
+ mediaType,
42
+ mimeType
43
+ } = metadata || {};
44
+ const divRef = useRef(null);
45
+ const breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
46
+ const customMessage = isUploadError(props.error) ? messages.failed_to_upload : undefined;
47
+ const renderFailedTitleBox = !disableOverlay && (!name || !!customMessage);
48
+ const renderTitleBox = !disableOverlay && !!name && !customMessage;
49
+ const hasTitleBox = !!renderTitleBox || !!renderFailedTitleBox;
50
+ return jsx(CardViewWrapper, _extends({}, props, {
51
+ metadata: metadata,
52
+ breakpoint: breakpoint,
53
+ "data-test-status": "error",
54
+ ref: divRef,
55
+ customTitleBox: renderFailedTitleBox ? () => jsx(FailedTitleBox, {
56
+ breakpoint: breakpoint,
57
+ customMessage: customMessage
58
+ }) : undefined
59
+ }), jsx(IconWrapper, {
60
+ breakpoint: breakpoint,
61
+ hasTitleBox: hasTitleBox
62
+ }, jsx(MimeTypeIcon, {
63
+ testId: "media-card-file-type-icon",
64
+ mediaType: mediaType,
65
+ mimeType: mimeType,
66
+ name: name
67
+ }), !renderFailedTitleBox && jsx(IconMessage, {
68
+ error: error,
69
+ metadata: metadata
70
+ })));
71
+ };
72
+
73
+ // TODO: check if analytics is correct
74
+
75
+ export const ErrorCardView = withAnalyticsEvents({
76
+ onClick: createAndFireMediaCardEvent({
77
+ eventType: 'ui',
78
+ action: 'clicked',
79
+ actionSubject: 'mediaCard',
80
+ attributes: {}
81
+ })
82
+ })(ErrorCardViewBase);
@@ -0,0 +1,70 @@
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
+ const IconCardViewBase = props => {
16
+ const {
17
+ dimensions,
18
+ metadata,
19
+ disableOverlay,
20
+ innerRef,
21
+ progress,
22
+ status
23
+ } = props;
24
+ const divRef = useRef(null);
25
+ const breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
26
+ useEffect(() => {
27
+ innerRef && !!divRef.current && innerRef(divRef.current);
28
+ }, [innerRef]);
29
+ const {
30
+ name,
31
+ mediaType,
32
+ mimeType
33
+ } = metadata || {};
34
+ const hasTitleBox = !disableOverlay && !!name;
35
+ const isUploading = status === 'uploading';
36
+ return jsx(CardViewWrapper, _extends({}, props, {
37
+ metadata: metadata,
38
+ breakpoint: breakpoint,
39
+ "data-test-status": status,
40
+ "data-test-progress": progress,
41
+ ref: divRef,
42
+ customBlanket: () => jsx(Blanket, {
43
+ isFixed: isUploading
44
+ }),
45
+ progressBar: isUploading ? () => jsx(ProgressBar, {
46
+ progress: progress,
47
+ breakpoint: breakpoint,
48
+ positionBottom: !hasTitleBox
49
+ }) : undefined
50
+ }), jsx(IconWrapper, {
51
+ breakpoint: breakpoint,
52
+ hasTitleBox: hasTitleBox
53
+ }, jsx(MimeTypeIcon, {
54
+ testId: "media-card-file-type-icon",
55
+ mediaType: mediaType,
56
+ mimeType: mimeType,
57
+ name: name
58
+ })));
59
+ };
60
+
61
+ // TODO: check if analytics is correct
62
+
63
+ export const IconCardView = withAnalyticsEvents({
64
+ onClick: createAndFireMediaCardEvent({
65
+ eventType: 'ui',
66
+ action: 'clicked',
67
+ actionSubject: 'mediaCard',
68
+ attributes: {}
69
+ })
70
+ })(IconCardViewBase);
@@ -0,0 +1,75 @@
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
+ const ImageCardViewBase = props => {
13
+ const {
14
+ status,
15
+ dimensions,
16
+ metadata,
17
+ disableOverlay,
18
+ innerRef,
19
+ progress,
20
+ cardPreview,
21
+ alt,
22
+ resizeMode,
23
+ onDisplayImage,
24
+ nativeLazyLoad,
25
+ forceSyncDisplay,
26
+ onImageLoad,
27
+ onImageError
28
+ } = props;
29
+ const divRef = useRef(null);
30
+ const breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
31
+ useEffect(() => {
32
+ innerRef && !!divRef.current && innerRef(divRef.current);
33
+ }, [innerRef]);
34
+ const {
35
+ name,
36
+ mediaType = 'unknown'
37
+ } = metadata || {};
38
+ const hasTitleBox = !disableOverlay && !!name;
39
+ const isUploading = status === 'uploading';
40
+ return jsx(CardViewWrapper, _extends({}, props, {
41
+ breakpoint: breakpoint,
42
+ "data-test-status": status,
43
+ "data-test-progress": progress,
44
+ ref: divRef,
45
+ customBlanket: () => jsx(Blanket, {
46
+ isFixed: isUploading
47
+ }),
48
+ progressBar: isUploading ? () => jsx(ProgressBar, {
49
+ progress: progress,
50
+ breakpoint: breakpoint,
51
+ positionBottom: !hasTitleBox
52
+ }) : undefined
53
+ }), jsx(ImageRenderer, {
54
+ cardPreview: cardPreview,
55
+ mediaType: mediaType,
56
+ alt: alt,
57
+ resizeMode: resizeMode,
58
+ onDisplayImage: onDisplayImage,
59
+ onImageLoad: () => onImageLoad === null || onImageLoad === void 0 ? void 0 : onImageLoad(cardPreview),
60
+ onImageError: () => onImageError === null || onImageError === void 0 ? void 0 : onImageError(cardPreview),
61
+ nativeLazyLoad: nativeLazyLoad,
62
+ forceSyncDisplay: forceSyncDisplay
63
+ }));
64
+ };
65
+
66
+ // TODO: check if analytics is correct
67
+
68
+ export const ImageCardView = withAnalyticsEvents({
69
+ onClick: createAndFireMediaCardEvent({
70
+ eventType: 'ui',
71
+ action: 'clicked',
72
+ actionSubject: 'mediaCard',
73
+ attributes: {}
74
+ })
75
+ })(ImageCardViewBase);
@@ -0,0 +1,268 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+ import { jsx } from '@emotion/react';
4
+ import React, { useEffect, useState, useRef } from 'react';
5
+ import { withAnalyticsEvents } from '@atlaskit/analytics-next';
6
+ import { createAndFireMediaCardEvent } from '../../../utils/analytics';
7
+ import { useBreakpoint } from '../../useBreakpoint';
8
+ import { ProcessingCardView } from './processingCardView';
9
+ import { ErrorCardView } from './errorCardView';
10
+ import { VideoCardView } from './videoCardView';
11
+ import { ImageCardView } from './imageCardView';
12
+ import { IconCardView } from './iconCardView';
13
+ import { LoadingCardView } from './loadingCardView';
14
+ export const CardViewsBase = ({
15
+ innerRef,
16
+ onImageLoad,
17
+ onImageError,
18
+ dimensions,
19
+ appearance = 'auto',
20
+ onClick,
21
+ onMouseEnter,
22
+ testId,
23
+ metadata,
24
+ status,
25
+ selected,
26
+ selectable,
27
+ cardPreview,
28
+ mediaCardCursor,
29
+ shouldHideTooltip,
30
+ progress,
31
+ alt,
32
+ resizeMode,
33
+ onDisplayImage,
34
+ nativeLazyLoad,
35
+ forceSyncDisplay,
36
+ actions,
37
+ disableOverlay,
38
+ titleBoxBgColor,
39
+ titleBoxIcon,
40
+ error,
41
+ disableAnimation
42
+ }) => {
43
+ const [didImageRender, setDidImageRender] = useState(false);
44
+ const divRef = useRef(null);
45
+ const prevCardPreviewRef = useRef();
46
+ const breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
47
+ useEffect(() => {
48
+ innerRef && !!divRef.current && innerRef(divRef.current);
49
+ }, [innerRef]);
50
+
51
+ /* didImageRender movements */
52
+
53
+ useEffect(() => {
54
+ // We should only switch didImageRender to false when cardPreview goes undefined, not when it is changed. as this method could be triggered after onImageLoad callback, falling on a race condition
55
+ if (prevCardPreviewRef.current && !cardPreview) {
56
+ setDidImageRender(false);
57
+ }
58
+ prevCardPreviewRef.current = cardPreview;
59
+ }, [cardPreview]);
60
+ const handleOnImageLoad = prevCardPreview => {
61
+ if (prevCardPreview.dataURI !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
62
+ return;
63
+ }
64
+ setDidImageRender(true);
65
+ onImageLoad === null || onImageLoad === void 0 ? void 0 : onImageLoad(cardPreview);
66
+ };
67
+ const handleOnImageError = prevCardPreview => {
68
+ if (prevCardPreview.dataURI !== (cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI)) {
69
+ return;
70
+ }
71
+ setDidImageRender(false);
72
+ onImageError === null || onImageError === void 0 ? void 0 : onImageError(cardPreview);
73
+ };
74
+ const getRenderConfigByStatus = () => {
75
+ const {
76
+ mediaType
77
+ } = metadata || {};
78
+
79
+ // TODO: figure out if data-test-progress for all the card views
80
+
81
+ const baseProps = {
82
+ testId,
83
+ dimensions,
84
+ appearance,
85
+ metadata,
86
+ selected,
87
+ selectable,
88
+ actions,
89
+ breakpoint,
90
+ disableOverlay,
91
+ titleBoxBgColor,
92
+ titleBoxIcon,
93
+ shouldHideTooltip,
94
+ onClick,
95
+ onMouseEnter,
96
+ mediaCardCursor,
97
+ innerRef
98
+ };
99
+ switch (status) {
100
+ case 'uploading':
101
+ if (cardPreview) {
102
+ return jsx(React.Fragment, null, jsx("div", {
103
+ style: {
104
+ display: !didImageRender ? 'none' : 'inline'
105
+ }
106
+ }, mediaType === 'video' ? jsx(VideoCardView, _extends({}, baseProps, {
107
+ status: status,
108
+ cardPreview: cardPreview,
109
+ alt: alt,
110
+ resizeMode: resizeMode,
111
+ onDisplayImage: onDisplayImage,
112
+ onImageLoad: handleOnImageLoad,
113
+ onImageError: handleOnImageError,
114
+ nativeLazyLoad: nativeLazyLoad,
115
+ forceSyncDisplay: forceSyncDisplay,
116
+ progress: progress
117
+ })) : jsx(ImageCardView, _extends({}, baseProps, {
118
+ status: status,
119
+ cardPreview: cardPreview,
120
+ alt: alt,
121
+ resizeMode: resizeMode,
122
+ onDisplayImage: onDisplayImage,
123
+ onImageLoad: handleOnImageLoad,
124
+ onImageError: handleOnImageError,
125
+ nativeLazyLoad: nativeLazyLoad,
126
+ forceSyncDisplay: forceSyncDisplay,
127
+ progress: progress
128
+ }))), jsx("div", {
129
+ style: {
130
+ display: didImageRender ? 'none' : 'inline'
131
+ }
132
+ }, jsx(IconCardView, _extends({
133
+ status: status,
134
+ progress: progress
135
+ }, baseProps))));
136
+ } else {
137
+ return jsx(IconCardView, _extends({
138
+ status: status,
139
+ progress: progress
140
+ }, baseProps));
141
+ }
142
+ case 'processing':
143
+ if (cardPreview) {
144
+ return jsx(React.Fragment, null, jsx("div", {
145
+ style: {
146
+ display: !didImageRender ? 'none' : 'inline'
147
+ }
148
+ }, mediaType === 'video' ? jsx(VideoCardView, _extends({}, baseProps, {
149
+ status: status,
150
+ cardPreview: cardPreview,
151
+ alt: alt,
152
+ resizeMode: resizeMode,
153
+ onDisplayImage: onDisplayImage,
154
+ onImageLoad: handleOnImageLoad,
155
+ onImageError: handleOnImageError,
156
+ nativeLazyLoad: nativeLazyLoad,
157
+ forceSyncDisplay: forceSyncDisplay,
158
+ progress: progress
159
+ })) : jsx(ImageCardView, _extends({}, baseProps, {
160
+ status: status,
161
+ cardPreview: cardPreview,
162
+ alt: alt,
163
+ resizeMode: resizeMode,
164
+ onDisplayImage: onDisplayImage,
165
+ onImageLoad: handleOnImageLoad,
166
+ onImageError: handleOnImageError,
167
+ nativeLazyLoad: nativeLazyLoad,
168
+ forceSyncDisplay: forceSyncDisplay,
169
+ progress: progress
170
+ }))), jsx("div", {
171
+ style: {
172
+ display: didImageRender ? 'none' : 'inline'
173
+ }
174
+ }, jsx(ProcessingCardView, _extends({
175
+ disableAnimation: disableAnimation
176
+ }, baseProps))));
177
+ } else {
178
+ return jsx(ProcessingCardView, _extends({
179
+ disableAnimation: disableAnimation
180
+ }, baseProps));
181
+ }
182
+ case 'complete':
183
+ if (cardPreview) {
184
+ return jsx(React.Fragment, null, jsx("div", {
185
+ style: {
186
+ display: !didImageRender ? 'none' : 'inline'
187
+ }
188
+ }, mediaType === 'video' ? jsx(VideoCardView, _extends({}, baseProps, {
189
+ status: status,
190
+ cardPreview: cardPreview,
191
+ alt: alt,
192
+ resizeMode: resizeMode,
193
+ onDisplayImage: onDisplayImage,
194
+ onImageLoad: handleOnImageLoad,
195
+ onImageError: handleOnImageError,
196
+ nativeLazyLoad: nativeLazyLoad,
197
+ forceSyncDisplay: forceSyncDisplay
198
+ })) : jsx(ImageCardView, _extends({}, baseProps, {
199
+ status: status,
200
+ cardPreview: cardPreview,
201
+ alt: alt,
202
+ resizeMode: resizeMode,
203
+ onDisplayImage: onDisplayImage,
204
+ onImageLoad: handleOnImageLoad,
205
+ onImageError: handleOnImageError,
206
+ nativeLazyLoad: nativeLazyLoad,
207
+ forceSyncDisplay: forceSyncDisplay
208
+ }))), jsx("div", {
209
+ style: {
210
+ display: didImageRender ? 'none' : 'inline'
211
+ }
212
+ }, jsx(IconCardView, _extends({
213
+ status: status
214
+ }, baseProps))));
215
+ } else {
216
+ return jsx(IconCardView, _extends({
217
+ status: status
218
+ }, baseProps));
219
+ }
220
+ case 'error':
221
+ case 'failed-processing':
222
+ return jsx(ErrorCardView, _extends({
223
+ disableAnimation: disableAnimation,
224
+ error: error
225
+ }, baseProps));
226
+ case 'loading-preview':
227
+ case 'loading':
228
+ default:
229
+ if (cardPreview) {
230
+ return jsx(React.Fragment, null, jsx("div", {
231
+ style: {
232
+ display: !didImageRender ? 'none' : 'inline'
233
+ }
234
+ }, jsx(ImageCardView, _extends({}, baseProps, {
235
+ status: status,
236
+ cardPreview: cardPreview,
237
+ alt: alt,
238
+ resizeMode: resizeMode,
239
+ onDisplayImage: onDisplayImage,
240
+ onImageLoad: handleOnImageLoad,
241
+ onImageError: handleOnImageError,
242
+ nativeLazyLoad: nativeLazyLoad,
243
+ forceSyncDisplay: forceSyncDisplay,
244
+ progress: progress
245
+ }))), jsx("div", {
246
+ style: {
247
+ display: didImageRender ? 'none' : 'inline'
248
+ }
249
+ }, jsx(LoadingCardView, _extends({}, baseProps, {
250
+ disableAnimation: disableAnimation
251
+ }))));
252
+ } else {
253
+ return jsx(LoadingCardView, _extends({}, baseProps, {
254
+ disableAnimation: disableAnimation
255
+ }));
256
+ }
257
+ }
258
+ };
259
+ return getRenderConfigByStatus();
260
+ };
261
+ export const CardViews = withAnalyticsEvents({
262
+ onClick: createAndFireMediaCardEvent({
263
+ eventType: 'ui',
264
+ action: 'clicked',
265
+ actionSubject: 'mediaCard',
266
+ attributes: {}
267
+ })
268
+ })(CardViewsBase);
@@ -0,0 +1,48 @@
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 SpinnerIcon from '@atlaskit/spinner';
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
+ const LoadingCardViewBase = props => {
12
+ const {
13
+ dimensions,
14
+ metadata,
15
+ disableOverlay,
16
+ innerRef
17
+ } = props;
18
+ const divRef = useRef(null);
19
+ const breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
20
+ useEffect(() => {
21
+ innerRef && !!divRef.current && innerRef(divRef.current);
22
+ }, [innerRef]);
23
+ const {
24
+ name
25
+ } = metadata || {};
26
+ const hasTitleBox = !disableOverlay && !!name;
27
+ return jsx(CardViewWrapper, _extends({}, props, {
28
+ metadata: metadata,
29
+ breakpoint: breakpoint,
30
+ ref: divRef
31
+ }), jsx(IconWrapper, {
32
+ breakpoint: breakpoint,
33
+ hasTitleBox: hasTitleBox
34
+ }, jsx(SpinnerIcon, {
35
+ testId: "media-card-loading"
36
+ })));
37
+ };
38
+
39
+ // TODO: check if analytics is correct
40
+
41
+ export const LoadingCardView = withAnalyticsEvents({
42
+ onClick: createAndFireMediaCardEvent({
43
+ eventType: 'ui',
44
+ action: 'clicked',
45
+ actionSubject: 'mediaCard',
46
+ attributes: {}
47
+ })
48
+ })(LoadingCardViewBase);