@atlaskit/media-card 74.3.2 → 74.4.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 (119) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/cjs/card/card.js +27 -18
  3. package/dist/cjs/card/cardAnalytics.js +16 -5
  4. package/dist/cjs/card/cardImageView/cardOverlay/index.js +1 -3
  5. package/dist/cjs/card/cardImageView/cardOverlay/styles.js +6 -8
  6. package/dist/cjs/card/cardImageView/fileCardImageView.js +1 -3
  7. package/dist/cjs/card/cardImageView/styles.js +7 -9
  8. package/dist/cjs/card/cardLoader.js +12 -3
  9. package/dist/cjs/card/cardState.js +11 -13
  10. package/dist/cjs/card/media-card-analytics-error-boundary.js +129 -0
  11. package/dist/cjs/card/styles/index.js +1 -3
  12. package/dist/cjs/card/ui/blanket/styles.js +1 -3
  13. package/dist/cjs/card/ui/iconMessage/styles.js +1 -3
  14. package/dist/cjs/card/ui/loadingRateLimited/styles.js +1 -3
  15. package/dist/cjs/card/ui/newFileExperience/newFileExperienceWrapper.js +5 -1
  16. package/dist/cjs/card/ui/newFileExperience/styles.js +12 -4
  17. package/dist/cjs/card/ui/playButton/styles.js +2 -4
  18. package/dist/cjs/card/ui/styles.js +1 -3
  19. package/dist/cjs/card/ui/tickBox/styles.js +2 -4
  20. package/dist/cjs/card/ui/titleBox/failedTitleBox.js +1 -3
  21. package/dist/cjs/card/ui/titleBox/styles.js +19 -5
  22. package/dist/cjs/card/ui/titleBox/titleBoxComponents.js +5 -1
  23. package/dist/cjs/card/ui/unhandledErrorCard/index.js +112 -0
  24. package/dist/cjs/card/ui/unhandledErrorCard/types.js +5 -0
  25. package/dist/cjs/errors.js +12 -3
  26. package/dist/cjs/inline/loader.js +4 -4
  27. package/dist/cjs/inline/mediaInlineAnalyticsErrorBoundary.js +113 -0
  28. package/dist/cjs/utils/analytics.js +41 -10
  29. package/dist/cjs/utils/cardActions/styles.js +2 -4
  30. package/dist/cjs/utils/errorIcon/styles.js +1 -3
  31. package/dist/cjs/utils/lightCards/styles.js +4 -6
  32. package/dist/cjs/utils/ufoExperiences.js +1 -1
  33. package/dist/cjs/version.json +1 -1
  34. package/dist/es2019/card/card.js +29 -17
  35. package/dist/es2019/card/cardAnalytics.js +9 -5
  36. package/dist/es2019/card/cardImageView/cardOverlay/index.js +1 -2
  37. package/dist/es2019/card/cardImageView/cardOverlay/styles.js +20 -21
  38. package/dist/es2019/card/cardImageView/fileCardImageView.js +1 -2
  39. package/dist/es2019/card/cardImageView/styles.js +7 -8
  40. package/dist/es2019/card/cardLoader.js +12 -3
  41. package/dist/es2019/card/cardState.js +12 -7
  42. package/dist/es2019/card/media-card-analytics-error-boundary.js +90 -0
  43. package/dist/es2019/card/styles/index.js +1 -2
  44. package/dist/es2019/card/ui/blanket/styles.js +1 -2
  45. package/dist/es2019/card/ui/iconMessage/styles.js +1 -2
  46. package/dist/es2019/card/ui/loadingRateLimited/styles.js +1 -2
  47. package/dist/es2019/card/ui/newFileExperience/newFileExperienceWrapper.js +4 -1
  48. package/dist/es2019/card/ui/newFileExperience/styles.js +10 -3
  49. package/dist/es2019/card/ui/playButton/styles.js +2 -3
  50. package/dist/es2019/card/ui/styles.js +1 -2
  51. package/dist/es2019/card/ui/tickBox/styles.js +4 -5
  52. package/dist/es2019/card/ui/titleBox/failedTitleBox.js +1 -2
  53. package/dist/es2019/card/ui/titleBox/styles.js +20 -7
  54. package/dist/es2019/card/ui/titleBox/titleBoxComponents.js +4 -1
  55. package/dist/es2019/card/ui/unhandledErrorCard/index.js +79 -0
  56. package/dist/es2019/card/ui/unhandledErrorCard/types.js +1 -0
  57. package/dist/es2019/errors.js +13 -2
  58. package/dist/es2019/inline/loader.js +4 -4
  59. package/dist/es2019/inline/mediaInlineAnalyticsErrorBoundary.js +75 -0
  60. package/dist/es2019/utils/analytics.js +32 -9
  61. package/dist/es2019/utils/cardActions/styles.js +4 -5
  62. package/dist/es2019/utils/errorIcon/styles.js +1 -2
  63. package/dist/es2019/utils/lightCards/styles.js +4 -5
  64. package/dist/es2019/utils/ufoExperiences.js +1 -1
  65. package/dist/es2019/version.json +1 -1
  66. package/dist/esm/card/card.js +28 -19
  67. package/dist/esm/card/cardAnalytics.js +12 -4
  68. package/dist/esm/card/cardImageView/cardOverlay/index.js +1 -2
  69. package/dist/esm/card/cardImageView/cardOverlay/styles.js +6 -7
  70. package/dist/esm/card/cardImageView/fileCardImageView.js +1 -2
  71. package/dist/esm/card/cardImageView/styles.js +7 -8
  72. package/dist/esm/card/cardLoader.js +12 -3
  73. package/dist/esm/card/cardState.js +12 -11
  74. package/dist/esm/card/media-card-analytics-error-boundary.js +115 -0
  75. package/dist/esm/card/styles/index.js +1 -2
  76. package/dist/esm/card/ui/blanket/styles.js +1 -2
  77. package/dist/esm/card/ui/iconMessage/styles.js +1 -2
  78. package/dist/esm/card/ui/loadingRateLimited/styles.js +1 -2
  79. package/dist/esm/card/ui/newFileExperience/newFileExperienceWrapper.js +4 -1
  80. package/dist/esm/card/ui/newFileExperience/styles.js +10 -3
  81. package/dist/esm/card/ui/playButton/styles.js +2 -3
  82. package/dist/esm/card/ui/styles.js +1 -2
  83. package/dist/esm/card/ui/tickBox/styles.js +2 -3
  84. package/dist/esm/card/ui/titleBox/failedTitleBox.js +1 -2
  85. package/dist/esm/card/ui/titleBox/styles.js +19 -5
  86. package/dist/esm/card/ui/titleBox/titleBoxComponents.js +4 -1
  87. package/dist/esm/card/ui/unhandledErrorCard/index.js +93 -0
  88. package/dist/esm/card/ui/unhandledErrorCard/types.js +1 -0
  89. package/dist/esm/errors.js +12 -3
  90. package/dist/esm/inline/loader.js +5 -5
  91. package/dist/esm/inline/mediaInlineAnalyticsErrorBoundary.js +99 -0
  92. package/dist/esm/utils/analytics.js +34 -9
  93. package/dist/esm/utils/cardActions/styles.js +2 -3
  94. package/dist/esm/utils/errorIcon/styles.js +1 -2
  95. package/dist/esm/utils/lightCards/styles.js +4 -5
  96. package/dist/esm/utils/ufoExperiences.js +1 -1
  97. package/dist/esm/version.json +1 -1
  98. package/dist/types/card/card.d.ts +1 -1
  99. package/dist/types/card/cardAnalytics.d.ts +2 -1
  100. package/dist/types/card/cardState.d.ts +6 -1
  101. package/dist/types/card/getCardPreview/index.d.ts +1 -1
  102. package/dist/types/card/media-card-analytics-error-boundary.d.ts +14 -0
  103. package/dist/types/card/ui/newFileExperience/styles.d.ts +1 -1
  104. package/dist/types/card/ui/newFileExperience/types.d.ts +2 -0
  105. package/dist/types/card/ui/titleBox/styles.d.ts +1 -1
  106. package/dist/types/card/ui/titleBox/types.d.ts +2 -0
  107. package/dist/types/card/ui/unhandledErrorCard/index.d.ts +7 -0
  108. package/dist/types/card/ui/unhandledErrorCard/types.d.ts +6 -0
  109. package/dist/types/errors.d.ts +2 -2
  110. package/dist/types/inline/mediaInlineAnalyticsErrorBoundary.d.ts +11 -0
  111. package/dist/types/types.d.ts +3 -0
  112. package/dist/types/utils/analytics.d.ts +26 -6
  113. package/example-helpers/styles.ts +13 -0
  114. package/package.json +9 -8
  115. package/report.api.md +18 -2
  116. package/dist/cjs/utils/media-card-analytics-error-boundary.js +0 -59
  117. package/dist/es2019/utils/media-card-analytics-error-boundary.js +0 -19
  118. package/dist/esm/utils/media-card-analytics-error-boundary.js +0 -46
  119. package/dist/types/utils/media-card-analytics-error-boundary.d.ts +0 -10
@@ -2,16 +2,21 @@ import { isErrorFileState } from '@atlaskit/media-client';
2
2
  import { MediaCardError } from '../errors';
3
3
  import { getCardStatus, isFinalCardStatus } from './getCardStatus';
4
4
  import { extractFilePreviewStatus } from './getCardPreview';
5
- export const createStateUpdater = newState => prevState => {
6
- // Only override if previous status is non-final
7
- // or new status is 'complete'
8
- if (isFinalCardStatus(prevState.status) && newState.status !== 'complete') {
5
+ /**
6
+ * From docs: "Both state and props received by the updater function are guaranteed to be up-to-date.
7
+ * The output of the updater is shallowly merged with state."
8
+ */
9
+
10
+ export const createStateUpdater = (newState, fireErrorEvent) => prevState => {
11
+ // Only override if previous status is non-final or new status is 'complete'
12
+ if (!!newState.status && isFinalCardStatus(prevState.status) && newState.status !== 'complete') {
13
+ // Log the error if the new state is not going to store it.
14
+ // i.e. this is a non critical error
15
+ !!newState.error && fireErrorEvent(newState.error);
9
16
  return prevState;
10
17
  }
11
18
 
12
- return { ...prevState,
13
- ...newState
14
- };
19
+ return newState;
15
20
  };
16
21
  export const getCardStateFromFileState = (fileState, isBannedLocalPreview, featureFlags) => {
17
22
  const status = getCardStatus(fileState.status, extractFilePreviewStatus(fileState, isBannedLocalPreview, featureFlags));
@@ -0,0 +1,90 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import React from 'react';
3
+ import { withMediaAnalyticsContext } from '@atlaskit/media-common';
4
+ import { UnhandledErrorCard } from './ui/unhandledErrorCard';
5
+ import { withAnalyticsEvents } from '@atlaskit/analytics-next';
6
+ import { fireMediaCardEvent } from '../utils/analytics';
7
+
8
+ class WrappedMediaCardAnalyticsErrorBoundary extends React.Component {
9
+ constructor(props) {
10
+ super(props);
11
+
12
+ _defineProperty(this, "fireOperationalEvent", (error, info) => {
13
+ var _window, _window$navigator;
14
+
15
+ const {
16
+ data = {},
17
+ createAnalyticsEvent
18
+ } = this.props;
19
+ const payload = {
20
+ eventType: 'operational',
21
+ action: 'failed',
22
+ actionSubject: 'mediaCardRender',
23
+ attributes: {
24
+ browserInfo: (_window = window) !== null && _window !== void 0 && (_window$navigator = _window.navigator) !== null && _window$navigator !== void 0 && _window$navigator.userAgent ? window.navigator.userAgent : 'unknown',
25
+ error,
26
+ info,
27
+ failReason: 'unexpected-error',
28
+ ...data
29
+ }
30
+ };
31
+ fireMediaCardEvent(payload, createAnalyticsEvent);
32
+ });
33
+
34
+ _defineProperty(this, "handleOnClick", event => {
35
+ try {
36
+ var _this$props$onClick, _this$props;
37
+
38
+ (_this$props$onClick = (_this$props = this.props).onClick) === null || _this$props$onClick === void 0 ? void 0 : _this$props$onClick.call(_this$props, {
39
+ event
40
+ });
41
+ } catch (e) {}
42
+ });
43
+
44
+ this.state = {
45
+ hasError: false
46
+ };
47
+ }
48
+
49
+ componentDidCatch(error, info) {
50
+ try {
51
+ this.fireOperationalEvent(error, info);
52
+ } catch (e) {}
53
+
54
+ this.setState({
55
+ hasError: true
56
+ });
57
+ }
58
+
59
+ render() {
60
+ const {
61
+ hasError
62
+ } = this.state;
63
+ const {
64
+ dimensions,
65
+ children
66
+ } = this.props;
67
+
68
+ if (hasError) {
69
+ return /*#__PURE__*/React.createElement(UnhandledErrorCard, {
70
+ dimensions: dimensions,
71
+ onClick: this.handleOnClick
72
+ });
73
+ }
74
+
75
+ return children;
76
+ }
77
+
78
+ }
79
+
80
+ _defineProperty(WrappedMediaCardAnalyticsErrorBoundary, "displayName", 'MediaCardAnalyticsErrorBoundary');
81
+
82
+ const packageName = "@atlaskit/media-card";
83
+ const packageVersion = "74.4.1";
84
+ const MediaCardAnalyticsErrorBoundary = withMediaAnalyticsContext({
85
+ packageVersion,
86
+ packageName,
87
+ componentName: 'mediaCard',
88
+ component: 'mediaCard'
89
+ })(withAnalyticsEvents()(WrappedMediaCardAnalyticsErrorBoundary));
90
+ export default MediaCardAnalyticsErrorBoundary;
@@ -1,7 +1,6 @@
1
1
  import { css } from '@emotion/react';
2
2
  import { fontFamily } from '@atlaskit/theme/constants';
3
3
  import { fadeIn } from '@atlaskit/media-ui';
4
- import { token } from '@atlaskit/tokens';
5
4
  export { defaultTransitionDuration } from './config';
6
5
  export { antialiased, borderRadiusLeft, capitalize, centerSelf, centerSelfX, centerSelfY, centerX, hexToRgb, rgba, spaceAround, transition, withAppearance } from './mixins';
7
6
  export { easeOutCubic, easeOutExpo } from './easing';
@@ -15,7 +14,7 @@ export const rootStyles = () => css`
15
14
  }
16
15
  `;
17
16
  export const cardShadow = `
18
- box-shadow: ${token('elevation.shadow.raised', '0 1px 1px rgba(9, 30, 66, 0.2), 0 0 1px 0 rgba(9, 30, 66, 0.24)')};
17
+ box-shadow: ${"var(--ds-shadow-raised, 0 1px 1px rgba(9, 30, 66, 0.2), 0 0 1px 0 rgba(9, 30, 66, 0.24))"};
19
18
  `;
20
19
  export const fadeinImageStyles = () => css`
21
20
  ${fadeIn};
@@ -1,9 +1,8 @@
1
- import { token } from '@atlaskit/tokens';
2
1
  import { css } from '@emotion/react';
3
2
  import { transition } from '../../styles';
4
3
  import { N90A } from '@atlaskit/theme/colors';
5
4
  export const blanketClassName = 'media-card-blanket';
6
- export const fixedBlanketStyles = `background-color: ${token('color.blanket', N90A)};`;
5
+ export const fixedBlanketStyles = `background-color: ${`var(--ds-blanket, ${N90A})`};`;
7
6
  export const blanketStyles = isFixed => css`
8
7
  ${transition()}
9
8
  position: absolute;
@@ -1,4 +1,3 @@
1
- import { token } from '@atlaskit/tokens';
2
1
  import { css, keyframes } from '@emotion/react';
3
2
  import { N300 } from '@atlaskit/theme/colors';
4
3
  const breatheAnimation = keyframes`
@@ -20,7 +19,7 @@ const getStylesBasedOnProps = ({
20
19
  opacity: 1;
21
20
  font-weight: 450;
22
21
  ${reducedFont ? 'font-size: 0.7em;' : ''}
23
- color: ${token('color.text.subtlest', N300)};
22
+ color: ${`var(--ds-text-subtlest, ${N300})`};
24
23
  text-align: center;
25
24
  ${animated ? animatedStyles : ''}
26
25
  margin-bottom: -1em;
@@ -1,4 +1,3 @@
1
- import { token } from '@atlaskit/tokens';
2
1
  import { css } from '@emotion/react';
3
2
  import { generateResponsiveStyles } from '../progressBar/styles';
4
3
  import { N300 } from '@atlaskit/theme/colors';
@@ -27,7 +26,7 @@ export const loadingRateLimitedTextWrapperStyles = ({
27
26
  }) => css`
28
27
  margin-top: 10px;
29
28
  overflow: hidden;
30
- color: ${token('color.text.subtlest', N300)};
29
+ color: ${`var(--ds-text-subtlest, ${N300})`};
31
30
  display: block;
32
31
  width: 100%;
33
32
  text-align: center;
@@ -2,6 +2,7 @@
2
2
  import { jsx } from '@emotion/react';
3
3
  import { newFileExperienceClassName } from '../../cardConstants';
4
4
  import { newFileExperienceWrapperStyles } from './styles';
5
+ import { useGlobalTheme } from '@atlaskit/theme/components';
5
6
  export const NewFileExperienceWrapper = props => {
6
7
  const {
7
8
  testId,
@@ -19,6 +20,7 @@ export const NewFileExperienceWrapper = props => {
19
20
  isTickBoxSelectable,
20
21
  shouldDisplayTooltip
21
22
  } = props;
23
+ const theme = useGlobalTheme();
22
24
  return jsx("div", {
23
25
  id: "newFileExperienceWrapper",
24
26
  className: newFileExperienceClassName,
@@ -33,7 +35,8 @@ export const NewFileExperienceWrapper = props => {
33
35
  isPlayButtonClickable,
34
36
  isTickBoxSelectable,
35
37
  shouldDisplayTooltip,
36
- mediaCardCursor
38
+ mediaCardCursor,
39
+ theme
37
40
  }),
38
41
  ref: innerRef,
39
42
  onClick: onClick,
@@ -2,12 +2,13 @@ import { css } from '@emotion/react';
2
2
  import { fontFamily } from '@atlaskit/theme/constants';
3
3
  import { borderRadius } from '@atlaskit/media-ui';
4
4
  import { N20 } from '@atlaskit/theme/colors';
5
- import { token } from '@atlaskit/tokens';
6
5
  import { hideNativeBrowserTextSelectionStyles } from '@atlaskit/editor-shared-styles/selection';
6
+ import { themed } from '@atlaskit/theme/components';
7
7
  import { transition } from '../../styles';
8
8
  import { fixedBlanketStyles, blanketClassName } from '../blanket/styles';
9
9
  import { fixedActionBarStyles, actionsBarClassName } from '../actionsBar/styles';
10
10
  import { generateResponsiveStyles, getClickablePlayButtonStyles, getCursorStyle, getSelectableTickBoxStyles, getWrapperDimensions, getWrapperShadow } from '../styles';
11
+ const BACKGROUND_COLOR_DARK = '#22272C';
11
12
  export const newFileExperienceWrapperStyles = ({
12
13
  breakpoint,
13
14
  dimensions,
@@ -18,7 +19,8 @@ export const newFileExperienceWrapperStyles = ({
18
19
  isPlayButtonClickable,
19
20
  isTickBoxSelectable,
20
21
  shouldDisplayTooltip,
21
- mediaCardCursor
22
+ mediaCardCursor,
23
+ theme
22
24
  }) => css`
23
25
  ${transition()}
24
26
  box-sizing: border-box;
@@ -28,7 +30,12 @@ export const newFileExperienceWrapperStyles = ({
28
30
  position: relative;
29
31
  font-family: ${fontFamily()};
30
32
  ${getWrapperDimensions(dimensions, appearance)}
31
- ${displayBackground && `background-color: ${token('color.background.neutral', N20)};`}
33
+ ${displayBackground && `background: ${themed({
34
+ light: `var(--ds-background-neutral, ${N20})`,
35
+ dark: `var(--ds-background-neutral, ${BACKGROUND_COLOR_DARK})`
36
+ })({
37
+ theme
38
+ })};`}
32
39
  ${borderRadius}
33
40
  ${getCursorStyle(mediaCardCursor)}
34
41
  ${getWrapperShadow(disableOverlay, selected)}
@@ -1,6 +1,5 @@
1
1
  import { css } from '@emotion/react';
2
2
  import { N0, N90A } from '@atlaskit/theme/colors';
3
- import { token } from '@atlaskit/tokens';
4
3
  export const playButtonClassName = 'media-card-play-button';
5
4
  export const bkgClassName = 'play-icon-background';
6
5
  const discSize = 48;
@@ -20,7 +19,7 @@ export const playButtonWrapperStyles = css`
20
19
  display: flex;
21
20
  align-items: center;
22
21
  justify-content: center;
23
- color: ${token('color.icon.inverse', N0)};
22
+ color: ${`var(--ds-icon-inverse, ${N0})`};
24
23
  span {
25
24
  position: absolute;
26
25
  }
@@ -31,6 +30,6 @@ export const backgroundStyles = css`
31
30
  position: absolute;
32
31
  width: ${discSize}px;
33
32
  height: ${discSize}px;
34
- background: ${token('color.background.neutral.bold', N90A)};
33
+ background: ${`var(--ds-background-neutral-bold, ${N90A})`};
35
34
  border-radius: 100%;
36
35
  `;
@@ -1,7 +1,6 @@
1
1
  import { css } from '@emotion/react';
2
2
  import { borderRadius } from '@atlaskit/media-ui';
3
3
  import { N60A } from '@atlaskit/theme/colors';
4
- import { token } from '@atlaskit/tokens';
5
4
  import { akEditorSelectedBoxShadow } from '@atlaskit/editor-shared-styles/consts';
6
5
  import { getCSSUnitValue } from '../../utils/getCSSUnitValue';
7
6
  import { getDefaultCardDimensions } from '../../utils/cardDimensions';
@@ -39,7 +38,7 @@ export const getWrapperDimensions = (dimensions, appearance) => {
39
38
  // CSS outline has no 'radius', therefore we can't achieve the same effect with it
40
39
 
41
40
  export const getWrapperShadow = (disableOverlay, selected) => {
42
- const withOverlayShadow = !disableOverlay ? `${token('elevation.shadow.raised', `0 1px 1px ${N60A}, 0 0 1px 0 ${N60A}`)}` : '';
41
+ const withOverlayShadow = !disableOverlay ? `${`var(--ds-shadow-raised, ${`0 1px 1px ${N60A}, 0 0 1px 0 ${N60A}`})`}` : '';
43
42
  const selectedShadow = selected ? akEditorSelectedBoxShadow : '';
44
43
  const shadow = [selectedShadow, withOverlayShadow].filter(Boolean).join(', ');
45
44
  return shadow ? `box-shadow: ${shadow};` : '';
@@ -1,14 +1,13 @@
1
1
  import { css } from '@emotion/react';
2
2
  import { transition } from '../../styles';
3
3
  import { B200, N0, N100 } from '@atlaskit/theme/colors';
4
- import { token } from '@atlaskit/tokens';
5
4
  export const tickBoxClassName = 'media-card-tickbox';
6
5
  export const tickboxFixedStyles = `
7
- background-color: ${token('color.background.input', N0)};
8
- color: ${token('color.icon.subtle', N100)};
6
+ background-color: ${`var(--ds-background-input, ${N0})`};
7
+ color: ${`var(--ds-icon-subtle, ${N100})`};
9
8
  `;
10
- export const getSelectedStyles = selected => selected ? `background-color: ${token('color.icon.information', B200)};
11
- color: ${token('color.icon.inverse', 'white')};` : ``;
9
+ export const getSelectedStyles = selected => selected ? `background-color: ${`var(--ds-icon-information, ${B200})`};
10
+ color: ${"var(--ds-icon-inverse, white)"};` : ``;
12
11
  export const wrapperStyles = selected => css`
13
12
  ${transition()}
14
13
  font-size: 14px;
@@ -3,7 +3,6 @@ import { FormattedMessage } from 'react-intl-next';
3
3
  import EditorWarningIcon from '@atlaskit/icon/glyph/editor/warning';
4
4
  import { messages } from '@atlaskit/media-ui';
5
5
  import { R300 } from '@atlaskit/theme/colors';
6
- import { token } from '@atlaskit/tokens';
7
6
  import { ErrorMessageWrapper, TitleBoxWrapper } from './titleBoxComponents';
8
7
  export const FailedTitleBox = ({
9
8
  breakpoint,
@@ -14,6 +13,6 @@ export const FailedTitleBox = ({
14
13
  }, /*#__PURE__*/React.createElement(ErrorMessageWrapper, null, /*#__PURE__*/React.createElement(EditorWarningIcon, {
15
14
  label: 'Warning',
16
15
  size: 'small',
17
- primaryColor: token('color.text.danger', R300)
16
+ primaryColor: `var(--ds-text-danger, ${R300})`
18
17
  }), /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(FormattedMessage, customMessage))));
19
18
  };
@@ -1,8 +1,8 @@
1
1
  import { css } from '@emotion/react';
2
- import { token } from '@atlaskit/tokens';
3
2
  import { responsiveSettings, getTitleBoxHeight, Breakpoint } from '../common';
4
- import { N0 } from '@atlaskit/theme/colors';
3
+ import { N0, N800 } from '@atlaskit/theme/colors';
5
4
  import { rgba } from '../../styles/mixins';
5
+ import { themed } from '@atlaskit/theme/components';
6
6
 
7
7
  const generateResponsiveStyles = (breakpoint = Breakpoint.SMALL) => {
8
8
  const setting = responsiveSettings[breakpoint];
@@ -14,15 +14,29 @@ const generateResponsiveStyles = (breakpoint = Breakpoint.SMALL) => {
14
14
  };
15
15
 
16
16
  const HEX_REGEX = /^#[0-9A-F]{6}$/i;
17
+ const BACKGROUND_COLOR_DARK = '#161a1d';
18
+ const TEXT_COLOR_DARK = '#C7D1DB';
17
19
  export const titleBoxWrapperStyles = ({
18
20
  breakpoint,
19
- titleBoxBgColor
21
+ titleBoxBgColor,
22
+ theme
20
23
  }) => css`
21
24
  position: absolute;
22
25
  bottom: 0;
23
26
  width: 100%;
24
- background-color: ${token('elevation.surface', rgba(titleBoxBgColor && HEX_REGEX.test(titleBoxBgColor) ? titleBoxBgColor : N0, 0.8))};
25
- color: inherit;
27
+ background-color: ${themed({
28
+ light: `var(--ds-surface, ${rgba(titleBoxBgColor && HEX_REGEX.test(titleBoxBgColor) ? titleBoxBgColor : N0, 1)})`,
29
+ dark: `var(--ds-surface, ${rgba( // theme does not contain this color, use constant instead
30
+ titleBoxBgColor && HEX_REGEX.test(titleBoxBgColor) ? titleBoxBgColor : BACKGROUND_COLOR_DARK, 1)})`
31
+ })({
32
+ theme
33
+ })};
34
+ color: ${themed({
35
+ light: `var(--ds-text, ${N800})`,
36
+ dark: `var(--ds-text, ${TEXT_COLOR_DARK})`
37
+ })({
38
+ theme
39
+ })};
26
40
  cursor: inherit;
27
41
  pointer-events: none;
28
42
  display: flex;
@@ -31,8 +45,7 @@ export const titleBoxWrapperStyles = ({
31
45
  ${generateResponsiveStyles(breakpoint)}
32
46
  `;
33
47
  titleBoxWrapperStyles.displayName = 'TitleBoxWrapper';
34
- const infoStyles = `white-space: nowrap;
35
- overflow: hidden;`;
48
+ const infoStyles = `white-space: nowrap;overflow: hidden;`;
36
49
  const iconOverlapStyles = `padding-right: 10px;`;
37
50
  export const titleBoxHeaderStyles = ({
38
51
  hasIconOverlap
@@ -1,16 +1,19 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
3
  import { errorMessageWrapperStyles, titleBoxFooterStyles, titleBoxHeaderStyles, titleBoxIconStyles, titleBoxWrapperStyles } from './styles';
4
+ import { useGlobalTheme } from '@atlaskit/theme/components';
4
5
  export const TitleBoxWrapper = props => {
5
6
  const {
6
7
  breakpoint,
7
8
  titleBoxBgColor
8
9
  } = props;
10
+ const theme = useGlobalTheme();
9
11
  return jsx("div", {
10
12
  id: "titleBoxWrapper",
11
13
  css: titleBoxWrapperStyles({
12
14
  breakpoint: breakpoint,
13
- titleBoxBgColor: titleBoxBgColor
15
+ titleBoxBgColor: titleBoxBgColor,
16
+ theme
14
17
  })
15
18
  }, props.children);
16
19
  };
@@ -0,0 +1,79 @@
1
+ /** @jsx jsx */
2
+ import { Component } from 'react';
3
+ import { css, jsx } from '@emotion/react';
4
+ import WarningIcon from '@atlaskit/icon/glyph/editor/warning';
5
+ import { N20, N800, Y500 } from '@atlaskit/theme/colors';
6
+ import { fontSize } from '@atlaskit/theme/constants';
7
+ import { center, borderRadius } from '@atlaskit/media-ui';
8
+ import { defaultImageCardDimensions } from '../../../utils';
9
+
10
+ const isPercentage = value => /^\d+(\.\d+)?%$/.test(value);
11
+
12
+ const shouldShowText = ({
13
+ width,
14
+ height
15
+ }) => {
16
+ if (isPercentage(width) || isPercentage(height)) {
17
+ return false;
18
+ }
19
+
20
+ return parseInt(width, 10) >= 240 && parseInt(height, 10) >= 90;
21
+ };
22
+
23
+ const normalizeDimension = (value, defaultValue) => {
24
+ const sValue = value.toString();
25
+ return isPercentage(sValue) ? sValue : isNaN(parseInt(sValue, 10)) ? defaultValue + 'px' : parseInt(sValue, 10) + 'px';
26
+ };
27
+
28
+ const getConvertedDimension = dimensions => {
29
+ const {
30
+ width = defaultImageCardDimensions.width,
31
+ height = defaultImageCardDimensions.height
32
+ } = dimensions;
33
+ return {
34
+ width: normalizeDimension(width, defaultImageCardDimensions.width),
35
+ height: normalizeDimension(height, defaultImageCardDimensions.height)
36
+ };
37
+ };
38
+
39
+ const wrapperStyles = (dimensions = defaultImageCardDimensions) => {
40
+ try {
41
+ return css`
42
+ ${center};
43
+ ${borderRadius};
44
+ background: ${`var(--ds-background-neutral, ${N20})`};
45
+ color: ${`var(--ds-text-subtle, ${N800})`};
46
+ max-height: 100%;
47
+ max-width: 100%;
48
+ ${getConvertedDimension(dimensions)};
49
+ display: flex;
50
+ flex-direction: column;
51
+
52
+ p {
53
+ font-size: ${fontSize()}px;
54
+ text-align: center;
55
+ display: ${shouldShowText(getConvertedDimension(dimensions)) ? 'block' : 'none'};
56
+ }
57
+ `;
58
+ } catch (e) {
59
+ return null;
60
+ }
61
+ };
62
+
63
+ export class UnhandledErrorCard extends Component {
64
+ render() {
65
+ const {
66
+ dimensions,
67
+ onClick
68
+ } = this.props;
69
+ return jsx("div", {
70
+ css: wrapperStyles(dimensions),
71
+ onClick: onClick
72
+ }, jsx(WarningIcon, {
73
+ label: "Error",
74
+ primaryColor: `var(--ds-icon-warning, ${Y500})`,
75
+ size: "medium"
76
+ }), jsx("p", null, "We couldn't load this content"));
77
+ }
78
+
79
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -76,8 +76,19 @@ export const isRemotePreviewError = err => err instanceof RemotePreviewError;
76
76
  export const isUnsupportedLocalPreviewError = err => isMediaCardError(err) && err.primaryReason === 'local-preview-unsupported';
77
77
  export function isImageLoadError(err) {
78
78
  return err instanceof ImageLoadError;
79
- } // In a try/catch statement, the error caught is the type of any.
79
+ } // In a try/catch statement, the error caught is the type of unknown.
80
80
  // We can use this helper to ensure that the error handled is the type of MediaCardError if unsure
81
+ // If updatePrimaryReason is true, if it's a MediaCardError already, it will update it's primary reason
81
82
 
82
- export const ensureMediaCardError = (primaryReason, error) => isMediaCardError(error) ? error : new MediaCardError(primaryReason, error);
83
+ export const ensureMediaCardError = (primaryReason, error, updatePrimaryReason) => {
84
+ if (isMediaCardError(error)) {
85
+ if (updatePrimaryReason && error.primaryReason !== primaryReason) {
86
+ return new MediaCardError(primaryReason, error.secondaryError);
87
+ }
88
+
89
+ return error;
90
+ }
91
+
92
+ return new MediaCardError(primaryReason, error);
93
+ };
83
94
  export const isUploadError = error => error && error.primaryReason === 'upload';
@@ -18,15 +18,15 @@ export default class MediaInlineCardLoader extends React.PureComponent {
18
18
 
19
19
  if (!this.state.MediaInlineCard) {
20
20
  try {
21
- const [mediaClient, cardModule, mediaCardErrorBoundaryModule] = await Promise.all([import(
21
+ const [mediaClient, cardModule, mediaInlineErrorBoundaryModule] = await Promise.all([import(
22
22
  /* webpackChunkName: "@atlaskit-internal_media-client" */
23
23
  '@atlaskit/media-client'), import(
24
24
  /* webpackChunkName: "@atlaskit-internal_inline-media-card" */
25
25
  './mediaInlineCard'), import(
26
- /* webpackChunkName: "@atlaskit-internal_media-card-error-boundary" */
27
- '../utils/media-card-analytics-error-boundary')]);
26
+ /* webpackChunkName: "@atlaskit-internal_media-inline-error-boundary" */
27
+ './mediaInlineAnalyticsErrorBoundary')]);
28
28
  MediaInlineCardLoader.MediaInlineCard = mediaClient.withMediaClient(cardModule.MediaInlineCard);
29
- MediaInlineCardLoader.ErrorBoundary = mediaCardErrorBoundaryModule.default;
29
+ MediaInlineCardLoader.ErrorBoundary = mediaInlineErrorBoundaryModule.default;
30
30
 
31
31
  if (this.isMounted) {
32
32
  this.setState({
@@ -0,0 +1,75 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import React from 'react';
3
+ import { withMediaAnalyticsContext } from '@atlaskit/media-common';
4
+ import { withAnalyticsEvents } from '@atlaskit/analytics-next';
5
+ import { fireMediaCardEvent } from '../utils/analytics';
6
+
7
+ class WrappedMediaInlineAnalyticsErrorBoundary extends React.Component {
8
+ constructor(props) {
9
+ super(props);
10
+
11
+ _defineProperty(this, "fireOperationalEvent", (error, info) => {
12
+ var _window, _window$navigator;
13
+
14
+ const {
15
+ data = {},
16
+ createAnalyticsEvent
17
+ } = this.props;
18
+ const payload = {
19
+ eventType: 'operational',
20
+ action: 'failed',
21
+ actionSubject: 'mediaInlineRender',
22
+ attributes: {
23
+ browserInfo: (_window = window) !== null && _window !== void 0 && (_window$navigator = _window.navigator) !== null && _window$navigator !== void 0 && _window$navigator.userAgent ? window.navigator.userAgent : 'unknown',
24
+ error,
25
+ failReason: 'unexpected-error',
26
+ info,
27
+ ...data
28
+ }
29
+ };
30
+ fireMediaCardEvent(payload, createAnalyticsEvent);
31
+ });
32
+
33
+ this.state = {
34
+ hasError: false
35
+ };
36
+ }
37
+
38
+ componentDidCatch(error, info) {
39
+ try {
40
+ this.fireOperationalEvent(error, info);
41
+ this.setState({
42
+ hasError: true
43
+ });
44
+ } catch (e) {}
45
+ }
46
+
47
+ render() {
48
+ const {
49
+ hasError
50
+ } = this.state;
51
+ const {
52
+ children
53
+ } = this.props;
54
+
55
+ if (hasError) {
56
+ // TODO refactor error boundary for inline card https://product-fabric.atlassian.net/browse/MEX-2140
57
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
58
+ }
59
+
60
+ return children;
61
+ }
62
+
63
+ }
64
+
65
+ _defineProperty(WrappedMediaInlineAnalyticsErrorBoundary, "displayName", 'MediaInlineAnalyticsErrorBoundary');
66
+
67
+ const packageName = "@atlaskit/media-card";
68
+ const packageVersion = "74.4.1";
69
+ const MediaInlineAnalyticsErrorBoundary = withMediaAnalyticsContext({
70
+ packageVersion,
71
+ packageName,
72
+ componentName: 'mediaInlineCard',
73
+ component: 'mediaInlineCard'
74
+ })(withAnalyticsEvents()(WrappedMediaInlineAnalyticsErrorBoundary));
75
+ export default MediaInlineAnalyticsErrorBoundary;