@atlaskit/media-card 72.0.0 → 72.1.0

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 (80) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/errors.js +26 -6
  3. package/dist/cjs/root/card/cardLoader.js +66 -124
  4. package/dist/cjs/root/card/getCardPreview/index.js +90 -10
  5. package/dist/cjs/root/card/index.js +154 -84
  6. package/dist/cjs/root/cardView.js +41 -54
  7. package/dist/cjs/root/inline/mediaInlineCard.js +10 -5
  8. package/dist/cjs/root/ui/common.js +11 -5
  9. package/dist/cjs/root/ui/imageRenderer/imageRenderer.js +6 -2
  10. package/dist/cjs/root/ui/loadingRateLimited/loadingRateLimited.js +2 -2
  11. package/dist/cjs/root/ui/progressBar/progressBar.js +2 -2
  12. package/dist/cjs/root/ui/progressBar/styled.js +1 -3
  13. package/dist/cjs/root/ui/styled.js +80 -17
  14. package/dist/cjs/root/ui/titleBox/styled.js +1 -3
  15. package/dist/cjs/utils/cardActions/cardActionsDropdownMenu.js +16 -9
  16. package/dist/cjs/version.json +1 -1
  17. package/dist/es2019/errors.js +9 -1
  18. package/dist/es2019/root/card/cardLoader.js +47 -53
  19. package/dist/es2019/root/card/getCardPreview/index.js +45 -3
  20. package/dist/es2019/root/card/index.js +87 -20
  21. package/dist/es2019/root/cardView.js +26 -40
  22. package/dist/es2019/root/inline/mediaInlineCard.js +10 -5
  23. package/dist/es2019/root/ui/common.js +7 -1
  24. package/dist/es2019/root/ui/imageRenderer/imageRenderer.js +6 -2
  25. package/dist/es2019/root/ui/loadingRateLimited/loadingRateLimited.js +1 -1
  26. package/dist/es2019/root/ui/progressBar/progressBar.js +1 -1
  27. package/dist/es2019/root/ui/progressBar/styled.js +1 -2
  28. package/dist/es2019/root/ui/styled.js +64 -3
  29. package/dist/es2019/root/ui/titleBox/styled.js +1 -2
  30. package/dist/es2019/utils/cardActions/cardActionsDropdownMenu.js +8 -4
  31. package/dist/es2019/version.json +1 -1
  32. package/dist/esm/errors.js +23 -5
  33. package/dist/esm/root/card/cardLoader.js +66 -126
  34. package/dist/esm/root/card/getCardPreview/index.js +72 -10
  35. package/dist/esm/root/card/index.js +156 -85
  36. package/dist/esm/root/cardView.js +40 -52
  37. package/dist/esm/root/inline/mediaInlineCard.js +10 -5
  38. package/dist/esm/root/ui/common.js +7 -1
  39. package/dist/esm/root/ui/imageRenderer/imageRenderer.js +6 -2
  40. package/dist/esm/root/ui/loadingRateLimited/loadingRateLimited.js +1 -1
  41. package/dist/esm/root/ui/progressBar/progressBar.js +1 -1
  42. package/dist/esm/root/ui/progressBar/styled.js +1 -2
  43. package/dist/esm/root/ui/styled.js +61 -13
  44. package/dist/esm/root/ui/titleBox/styled.js +1 -2
  45. package/dist/esm/utils/cardActions/cardActionsDropdownMenu.js +16 -9
  46. package/dist/esm/version.json +1 -1
  47. package/dist/types/errors.d.ts +9 -3
  48. package/dist/types/index.d.ts +2 -1
  49. package/dist/types/root/card/cardLoader.d.ts +4 -18
  50. package/dist/types/root/card/getCardPreview/index.d.ts +7 -1
  51. package/dist/types/root/card/index.d.ts +2 -0
  52. package/dist/types/root/cardView.d.ts +3 -1
  53. package/dist/types/root/ui/common.d.ts +4 -1
  54. package/dist/types/root/ui/iconWrapper/styled.d.ts +1 -1
  55. package/dist/types/root/ui/imageRenderer/imageRenderer.d.ts +3 -2
  56. package/dist/types/root/ui/loadingRateLimited/loadingRateLimited.d.ts +1 -1
  57. package/dist/types/root/ui/loadingRateLimited/styled.d.ts +1 -1
  58. package/dist/types/root/ui/progressBar/progressBar.d.ts +1 -1
  59. package/dist/types/root/ui/progressBar/styled.d.ts +1 -1
  60. package/dist/types/root/ui/styled.d.ts +10 -3
  61. package/dist/types/root/ui/titleBox/failedTitleBox.d.ts +1 -1
  62. package/dist/types/root/ui/titleBox/styled.d.ts +1 -1
  63. package/dist/types/root/ui/titleBox/titleBox.d.ts +1 -1
  64. package/dist/types/types.d.ts +1 -1
  65. package/example-helpers/developmentUseMessage.tsx +14 -0
  66. package/example-helpers/index.tsx +34 -4
  67. package/example-helpers/selectableCard.tsx +2 -1
  68. package/package.json +8 -5
  69. package/dist/cjs/root/card/cardSSRView.js +0 -114
  70. package/dist/cjs/root/ui/Breakpoint.js +0 -13
  71. package/dist/cjs/root/ui/styledSSR.js +0 -108
  72. package/dist/es2019/root/card/cardSSRView.js +0 -93
  73. package/dist/es2019/root/ui/Breakpoint.js +0 -6
  74. package/dist/es2019/root/ui/styledSSR.js +0 -93
  75. package/dist/esm/root/card/cardSSRView.js +0 -92
  76. package/dist/esm/root/ui/Breakpoint.js +0 -6
  77. package/dist/esm/root/ui/styledSSR.js +0 -76
  78. package/dist/types/root/card/cardSSRView.d.ts +0 -13
  79. package/dist/types/root/ui/Breakpoint.d.ts +0 -4
  80. package/dist/types/root/ui/styledSSR.d.ts +0 -16
@@ -11,7 +11,7 @@ import { IntlProvider, intlShape } from 'react-intl';
11
11
  import { CardView } from '../cardView';
12
12
  import { ViewportDetector } from '../../utils/viewportDetector';
13
13
  import { getRequestedDimensions } from '../../utils/getDataURIDimension';
14
- import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview } from './getCardPreview';
14
+ import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, fetchAndCacheRemotePreview } from './getCardPreview';
15
15
  import { getFileDetails } from '../../utils/metadata';
16
16
  import { InlinePlayer } from '../inlinePlayer';
17
17
  import { getFileAttributes } from '../../utils/analytics';
@@ -88,6 +88,30 @@ export class CardBase extends Component {
88
88
  };
89
89
  });
90
90
 
91
+ _defineProperty(this, "setCacheSSRPreview", identifier => {
92
+ const {
93
+ mediaClient,
94
+ dimensions = {}
95
+ } = this.props;
96
+ fetchAndCacheRemotePreview(mediaClient, identifier.id, dimensions, this.getImageURLParams(identifier), this.getMediaBlobUrlAttrs(identifier)).catch(() => {// No need to log this error.
97
+ // If preview fails, it will be refetched later
98
+ //TODO: test this catch
99
+ // https://product-fabric.atlassian.net/browse/MEX-1071
100
+ });
101
+ });
102
+
103
+ _defineProperty(this, "resolveSSRPreview", (identifier, ssr) => {
104
+ const {
105
+ mediaClient
106
+ } = this.props;
107
+
108
+ try {
109
+ return getSSRCardPreview(ssr, mediaClient, identifier.id, this.getImageURLParams(identifier), this.getMediaBlobUrlAttrs(identifier));
110
+ } catch (e) {// TODO: log SSR reliability 'failed'
111
+ // https://product-fabric.atlassian.net/browse/MEX-770
112
+ }
113
+ });
114
+
91
115
  _defineProperty(this, "resolvePreview", async (identifier, fileState) => {
92
116
  try {
93
117
  const params = this.getCardPreviewParams(identifier, fileState);
@@ -133,18 +157,29 @@ export class CardBase extends Component {
133
157
  cardPreview
134
158
  } = this.state;
135
159
  const error = new ImageLoadError(cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.source);
160
+ const isLocal = cardPreview && isLocalPreview(cardPreview);
161
+ const isSSR = cardPreview && isSSRClientPreview(cardPreview);
162
+
163
+ if (isLocal || isSSR) {
164
+ const updateState = {
165
+ cardPreview: undefined
166
+ };
167
+
168
+ if (isLocal) {
169
+ updateState.isBannedLocalPreview = true;
170
+ this.fireLocalPreviewErrorEvent(error);
171
+ }
172
+
173
+ if (isSSR) {// TODO: set SSR-client reliability 'failed'.
174
+ // https://product-fabric.atlassian.net/browse/MEX-770
175
+ }
136
176
 
137
- if (cardPreview !== null && cardPreview !== void 0 && cardPreview.source && ['local', 'cache-local'].includes(cardPreview.source)) {
138
177
  const {
139
178
  identifier,
140
179
  dimensions = {}
141
180
  } = this.props;
142
181
  isFileIdentifier(identifier) && removeCardPreviewFromCache(identifier.id, dimensions);
143
- this.safeSetState({
144
- cardPreview: undefined,
145
- isBannedLocalPreview: true
146
- });
147
- this.fireLocalPreviewErrorEvent(error);
182
+ this.safeSetState(updateState);
148
183
  } else {
149
184
  this.safeSetState({
150
185
  status: 'error',
@@ -360,7 +395,8 @@ export class CardBase extends Component {
360
395
  testId,
361
396
  featureFlags,
362
397
  titleBoxBgColor,
363
- titleBoxIcon
398
+ titleBoxIcon,
399
+ ssr
364
400
  } = this.props;
365
401
  const {
366
402
  mediaItemType
@@ -376,7 +412,8 @@ export class CardBase extends Component {
376
412
  orientation: 1
377
413
  },
378
414
  error,
379
- cardRef
415
+ cardRef,
416
+ isCardVisible
380
417
  } = this.state;
381
418
  const {
382
419
  metadata
@@ -386,7 +423,12 @@ export class CardBase extends Component {
386
423
  onDisplayImage,
387
424
  actions,
388
425
  onMouseEnter
389
- } = this;
426
+ } = this; // Card can be artificially turned visible before entering the viewport
427
+ // For example, when we have the image in cache
428
+
429
+ const nativeLazyLoad = isLazy && !isCardVisible; // Force Media Image to always display img for SSR
430
+
431
+ const forceSyncDisplay = !!ssr;
390
432
  const card = /*#__PURE__*/React.createElement(CardView, {
391
433
  status: status,
392
434
  error: error,
@@ -412,7 +454,9 @@ export class CardBase extends Component {
412
454
  titleBoxBgColor: titleBoxBgColor,
413
455
  titleBoxIcon: titleBoxIcon,
414
456
  onImageError: this.onImageError,
415
- onImageLoad: this.onImageLoad
457
+ onImageLoad: this.onImageLoad,
458
+ nativeLazyLoad: nativeLazyLoad,
459
+ forceSyncDisplay: forceSyncDisplay
416
460
  });
417
461
  return isLazy ? /*#__PURE__*/React.createElement(ViewportDetector, {
418
462
  targetRef: cardRef,
@@ -466,7 +510,8 @@ export class CardBase extends Component {
466
510
 
467
511
  const {
468
512
  identifier: _identifier,
469
- dimensions: _dimensions = {}
513
+ dimensions: _dimensions = {},
514
+ ssr: _ssr
470
515
  } = this.props;
471
516
 
472
517
  if (isFileIdentifier(_identifier)) {
@@ -474,6 +519,11 @@ export class CardBase extends Component {
474
519
  id
475
520
  } = _identifier;
476
521
  _cardPreview = getCardPreviewFromCache(id, _dimensions);
522
+
523
+ if (!_cardPreview && _ssr) {
524
+ this.fireCommencedEvent();
525
+ _cardPreview = this.resolveSSRPreview(_identifier, _ssr);
526
+ }
477
527
  } else if (isExternalImageIdentifier(_identifier)) {
478
528
  this.fireCommencedEvent();
479
529
  _status = 'loading-preview';
@@ -485,14 +535,17 @@ export class CardBase extends Component {
485
535
  orientation: 1,
486
536
  source: 'external'
487
537
  };
488
- } // If cardPreview is available from local cache, `isCardVisible`
489
- // should be true to avoid flickers during re-mount of the component
538
+ } // If cardPreview is available from local cache or external, `isCardVisible`
539
+ // should be true to avoid flickers during re-mount of the component
540
+ // should not be visible for SSR preview, otherwise we'll fire the metadata fetch from
541
+ // outside the viewport
490
542
 
491
543
 
492
- const isCardVisible = _cardPreview ? true : !this.props.isLazy;
544
+ const _isCardVisible = !this.props.isLazy || !!_cardPreview && !isSSRPreview(_cardPreview);
545
+
493
546
  this.state = {
494
547
  status: _status,
495
- isCardVisible,
548
+ isCardVisible: _isCardVisible,
496
549
  isPlayingFile: false,
497
550
  cardPreview: _cardPreview,
498
551
  cardRef: null,
@@ -504,14 +557,22 @@ export class CardBase extends Component {
504
557
  componentDidMount() {
505
558
  this.hasBeenMounted = true;
506
559
  const {
507
- isCardVisible
560
+ isCardVisible,
561
+ cardPreview
508
562
  } = this.state;
509
563
  const {
510
- identifier
564
+ identifier,
565
+ ssr
511
566
  } = this.props;
512
567
 
513
568
  if (isCardVisible && isFileIdentifier(identifier)) {
514
569
  this.updateStateForIdentifier(identifier);
570
+ }
571
+
572
+ if (isCardVisible && !!ssr && !!cardPreview && isSSRClientPreview(cardPreview) && isFileIdentifier(identifier)) {
573
+ // Since the SSR preview brings the token in the query params,
574
+ // We need to fetch the remote preview to be able to cache it,
575
+ this.setCacheSSRPreview(identifier);
515
576
  } // we add a listener for each of the cards on the page
516
577
  // and then check if the triggered listener is from the card
517
578
  // that contains a div in current window.getSelection()
@@ -588,8 +649,14 @@ export class CardBase extends Component {
588
649
  this.resolvePreview(identifier, fileState);
589
650
  }
590
651
 
652
+ if (turnedVisible && this.props.ssr && !!cardPreview && isSSRClientPreview(cardPreview) && isFileIdentifier(identifier)) {
653
+ // Since the SSR preview brings the token in the query params,
654
+ // We need to fetch the remote preview to be able to cache it,
655
+ this.setCacheSSRPreview(identifier);
656
+ }
657
+
591
658
  if (previewDidRender && // We should't complete if status is uploading
592
- ['loading', 'loading-preview', 'processing'].includes(status)) {
659
+ ['loading-preview', 'processing'].includes(status)) {
593
660
  this.safeSetState({
594
661
  status: 'complete'
595
662
  });
@@ -649,7 +716,7 @@ export class CardBase extends Component {
649
716
  } = this.props;
650
717
  const {
651
718
  cardRef: element
652
- } = this.state;
719
+ } = this.state || {};
653
720
  return getRequestedDimensions({
654
721
  dimensions,
655
722
  element
@@ -13,8 +13,7 @@ import { createAndFireMediaCardEvent } from '../utils/analytics';
13
13
  import { attachDetailsToActions } from '../actions';
14
14
  import { getErrorMessage } from '../utils/getErrorMessage';
15
15
  import { toHumanReadableMediaSize, messages } from '@atlaskit/media-ui';
16
- import { NewFileExperienceWrapper } from './ui/styled';
17
- import { CardImageContainer, calcBreakpointSize } from './ui/styledSSR';
16
+ import { NewFileExperienceWrapper, CardImageContainer, calcBreakpointSize } from './ui/styled';
18
17
  import { ImageRenderer } from './ui/imageRenderer/imageRenderer';
19
18
  import { TitleBox } from './ui/titleBox/titleBox';
20
19
  import { FailedTitleBox } from './ui/titleBox/failedTitleBox';
@@ -115,11 +114,9 @@ export class CardViewBase extends React.Component {
115
114
  const shouldUsePointerCursor = status !== 'error' && status !== 'failed-processing';
116
115
  const shouldDisplayBackground = !dataURI || !disableOverlay || status === 'error' || status === 'failed-processing';
117
116
  const isPlayButtonClickable = !!(this.shouldRenderPlayButton() && disableOverlay);
118
- const isTickBoxSelectable = !disableOverlay && !!selectable && !selected; // Make tooltip optional for media singles - images, videos.
119
- // Intention is to show full file name when it's truncate in titlebox,
120
- // and to hide it when no titlebox exists.
117
+ const isTickBoxSelectable = !disableOverlay && !!selectable && !selected; // Disable tooltip for Media Single
121
118
 
122
- const shouldDisplayTooltip = !!name && !disableOverlay;
119
+ const shouldDisplayTooltip = !disableOverlay;
123
120
  return /*#__PURE__*/React.createElement(NewFileExperienceWrapper, {
124
121
  className: newFileExperienceClassName,
125
122
  "data-testid": testId || 'media-card-view',
@@ -248,42 +245,29 @@ export class CardViewBase extends React.Component {
248
245
  renderPlayButton: false
249
246
  };
250
247
  let iconMessage;
251
-
252
- if (!!metadata) {
253
- if (error) {
254
- const {
255
- secondaryError
256
- } = error;
257
-
258
- if (isRateLimitedError(secondaryError) || secondaryError && isPollingError(secondaryError)) {
259
- iconMessage = /*#__PURE__*/React.createElement(PreviewCurrentlyUnavailable, null);
260
- }
261
- } else if (!isZeroSize) {
262
- iconMessage = /*#__PURE__*/React.createElement(PreviewUnavailable, null);
263
- }
264
- } else if (!!disableOverlay) {
248
+ let customTitleMessage;
249
+ const {
250
+ secondaryError
251
+ } = error || {};
252
+
253
+ if (isRateLimitedError(secondaryError) || isPollingError(secondaryError)) {
254
+ iconMessage = /*#__PURE__*/React.createElement(PreviewCurrentlyUnavailable, null);
255
+ } else if (isUploadError(error)) {
256
+ iconMessage = /*#__PURE__*/React.createElement(FailedToUpload, null);
257
+ customTitleMessage = messages.failed_to_upload;
258
+ } else if (!metadata) {
265
259
  iconMessage = /*#__PURE__*/React.createElement(FailedToLoad, null);
266
- }
267
-
268
- if (error && isUploadError(error)) {
269
- if (!disableOverlay) {
270
- return { ...baseErrorConfig,
271
- renderFailedTitleBox: true,
272
- customTitleMessage: messages.failed_to_upload
273
- };
274
- }
275
-
276
- return { ...baseErrorConfig,
277
- renderTitleBox: !metadata && !!name,
278
- iconMessage: /*#__PURE__*/React.createElement(FailedToUpload, null)
279
- };
260
+ } else {
261
+ iconMessage = /*#__PURE__*/React.createElement(PreviewUnavailable, null);
280
262
  }
281
263
 
282
264
  if (!disableOverlay) {
265
+ const renderFailedTitleBox = !name || !!customTitleMessage;
283
266
  return { ...baseErrorConfig,
284
- renderTitleBox: !!name,
285
- renderFailedTitleBox: !metadata,
286
- iconMessage
267
+ renderTitleBox: !!name && !customTitleMessage,
268
+ renderFailedTitleBox,
269
+ iconMessage: !renderFailedTitleBox ? iconMessage : undefined,
270
+ customTitleMessage
287
271
  };
288
272
  }
289
273
 
@@ -504,18 +488,20 @@ export class CardViewBase extends React.Component {
504
488
  alt,
505
489
  resizeMode,
506
490
  onDisplayImage,
507
- mediaItemType
491
+ nativeLazyLoad,
492
+ forceSyncDisplay
508
493
  } = this.props;
509
494
  return !!dataURI && /*#__PURE__*/React.createElement(ImageRenderer, {
510
495
  dataURI: dataURI,
511
496
  mediaType: mediaType,
512
- mediaItemType: mediaItemType,
513
497
  previewOrientation: previewOrientation,
514
498
  alt: alt,
515
499
  resizeMode: resizeMode,
516
500
  onDisplayImage: onDisplayImage,
517
501
  onImageLoad: this.onImageLoad,
518
- onImageError: this.onImageError
502
+ onImageError: this.onImageError,
503
+ nativeLazyLoad: nativeLazyLoad,
504
+ forceSyncDisplay: forceSyncDisplay
519
505
  });
520
506
  }
521
507
 
@@ -64,31 +64,36 @@ export const MediaInlineCardInternal = ({
64
64
 
65
65
  if (!fileState) {
66
66
  return /*#__PURE__*/React.createElement(MediaInlineCardLoadingView, {
67
- message: intl.formatMessage(messages.loading_file)
67
+ message: intl.formatMessage(messages.loading_file),
68
+ isSelected: isSelected
68
69
  });
69
70
  }
70
71
 
71
72
  if (isErrored) {
72
73
  return /*#__PURE__*/React.createElement(MediaInlineCardErroredView, {
73
- message: intl.formatMessage(messages.couldnt_load_file)
74
+ message: intl.formatMessage(messages.couldnt_load_file),
75
+ isSelected: isSelected
74
76
  });
75
77
  }
76
78
 
77
79
  if (fileState.status === 'error') {
78
80
  return /*#__PURE__*/React.createElement(MediaInlineCardErroredView, {
79
- message: fileState.message || ''
81
+ message: fileState.message || '',
82
+ isSelected: isSelected
80
83
  });
81
84
  }
82
85
 
83
86
  if (fileState.status === 'failed-processing') {
84
87
  return /*#__PURE__*/React.createElement(MediaInlineCardErroredView, {
85
- message: intl.formatMessage(messages.couldnt_load_file)
88
+ message: intl.formatMessage(messages.couldnt_load_file),
89
+ isSelected: isSelected
86
90
  });
87
91
  }
88
92
 
89
93
  if (fileState.status === 'uploading') {
90
94
  return /*#__PURE__*/React.createElement(MediaInlineCardLoadingView, {
91
- message: fileState.name
95
+ message: fileState.name,
96
+ isSelected: isSelected
92
97
  });
93
98
  }
94
99
 
@@ -1,4 +1,10 @@
1
- import { Breakpoint } from './Breakpoint';
1
+ export let Breakpoint;
2
+
3
+ (function (Breakpoint) {
4
+ Breakpoint["SMALL"] = "small";
5
+ Breakpoint["LARGE"] = "large";
6
+ })(Breakpoint || (Breakpoint = {}));
7
+
2
8
  export const responsiveSettings = {
3
9
  [Breakpoint.SMALL]: {
4
10
  fontSize: 11,
@@ -10,7 +10,9 @@ export const ImageRenderer = ({
10
10
  onImageLoad,
11
11
  onImageError,
12
12
  onDisplayImage,
13
- mediaType
13
+ mediaType,
14
+ nativeLazyLoad,
15
+ forceSyncDisplay
14
16
  }) => {
15
17
  useEffect(() => {
16
18
  // TODO: trigger accordingly with the succeeded event. This could be a breaking change
@@ -23,6 +25,8 @@ export const ImageRenderer = ({
23
25
  alt: alt,
24
26
  previewOrientation: previewOrientation,
25
27
  onImageLoad: onImageLoad,
26
- onImageError: onImageError
28
+ onImageError: onImageError,
29
+ loading: nativeLazyLoad ? 'lazy' : undefined,
30
+ forceSyncDisplay: forceSyncDisplay
27
31
  }, resizeModeToMediaImageProps(resizeMode)));
28
32
  };
@@ -3,7 +3,7 @@ import { errorIcon } from '@atlaskit/media-ui/errorIcon';
3
3
  import { WarningIconWrapper, LoadingRateLimitedContainer, CouldntLoadWrapper, ErrorWrapper, LoadingRateLimitedTextWrapper } from './styled';
4
4
  import { messages } from '@atlaskit/media-ui';
5
5
  import { FormattedMessage } from 'react-intl';
6
- import { Breakpoint } from '../Breakpoint';
6
+ import { Breakpoint } from '../common';
7
7
  export const LoadingRateLimited = ({
8
8
  breakpoint = Breakpoint.SMALL,
9
9
  positionBottom = true
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { StyledBar } from './styled';
3
- import { Breakpoint } from '../Breakpoint';
3
+ import { Breakpoint } from '../common';
4
4
  export const ProgressBar = ({
5
5
  progress,
6
6
  breakpoint = Breakpoint.SMALL,
@@ -2,8 +2,7 @@ import styled from 'styled-components';
2
2
  import { borderRadius } from '@atlaskit/media-ui';
3
3
  import { rgba } from '../../../styles/mixins';
4
4
  import { N0, N400 } from '@atlaskit/theme/colors';
5
- import { getTitleBoxHeight, responsiveSettings } from '../common';
6
- import { Breakpoint } from '../Breakpoint';
5
+ import { Breakpoint, getTitleBoxHeight, responsiveSettings } from '../common';
7
6
  const height = 3;
8
7
  const padding = 1;
9
8
  const width = 95; // %
@@ -1,11 +1,30 @@
1
1
  import styled from 'styled-components';
2
2
  import { getCSSUnitValue } from '../../utils/getCSSUnitValue';
3
3
  import { getDefaultCardDimensions } from '../../utils/cardDimensions';
4
+ import { fontFamily } from '@atlaskit/theme/constants';
5
+ import { borderRadius } from '@atlaskit/media-ui';
6
+ import { N20, N60A } from '@atlaskit/theme/colors';
7
+ import { akEditorSelectedBoxShadow } from '@atlaskit/editor-shared-styles/consts';
4
8
  import { hideNativeBrowserTextSelectionStyles } from '@atlaskit/editor-shared-styles/selection';
9
+ import { transition } from '../../styles';
5
10
  import { tickBoxClassName, tickboxFixedStyles } from './tickBox/styled';
11
+ import { fixedBlanketStyles, blanketClassName } from './blanket/styled';
6
12
  import { fixedActionBarStyles, actionsBarClassName } from './actionsBar/styled';
7
13
  import { fixedPlayButtonStyles, playButtonClassName } from './playButton/styled';
8
- import { SSRFileExperienceWrapper } from './styledSSR';
14
+ import { Breakpoint, responsiveSettings } from './common';
15
+ const breakpointSizes = [[Breakpoint.SMALL, 599], [Breakpoint.LARGE, Infinity]];
16
+ export const calcBreakpointSize = (wrapperWidth = 0) => {
17
+ const [breakpoint] = breakpointSizes.find(([_breakpoint, limit]) => wrapperWidth <= limit) || [Breakpoint.SMALL];
18
+ return breakpoint;
19
+ };
20
+
21
+ const generateResponsiveStyles = (breakpoint = Breakpoint.SMALL) => {
22
+ const setting = responsiveSettings[breakpoint];
23
+ return `
24
+ font-size: ${setting.fontSize}px;
25
+ line-height: ${setting.lineHeight}px;
26
+ `;
27
+ };
9
28
 
10
29
  const getWrapperDimensions = (dimensions, appearance) => {
11
30
  const {
@@ -22,8 +41,19 @@ const getWrapperDimensions = (dimensions, appearance) => {
22
41
  height: ${getCSSUnitValue(height || defaultHeight)};
23
42
  max-height: 100%;
24
43
  `;
44
+ }; // This is a trick to simulate the blue border without affecting the dimensions.
45
+ // CSS outline has no 'radius', therefore we can't achieve the same effect with it
46
+
47
+
48
+ const getWrapperShadow = (disableOverlay, selected) => {
49
+ const withOverlayShadow = !disableOverlay ? `0 1px 1px ${N60A}, 0 0 1px 0 ${N60A}` : '';
50
+ const selectedShadow = selected ? akEditorSelectedBoxShadow : '';
51
+ const shadow = [selectedShadow, withOverlayShadow].filter(Boolean).join(', ');
52
+ return shadow ? `box-shadow: ${shadow};` : '';
25
53
  };
26
54
 
55
+ const getCursorStyle = shouldUsePointerCursor => `cursor: ${shouldUsePointerCursor ? 'pointer' : 'default'};`;
56
+
27
57
  const getClickablePlayButtonStyles = isPlayButtonClickable => {
28
58
  if (!isPlayButtonClickable) {
29
59
  return '';
@@ -48,19 +78,40 @@ const getSelectableTickBoxStyles = isTickBoxSelectable => {
48
78
  `;
49
79
  };
50
80
 
51
- export const NewFileExperienceWrapper = styled(SSRFileExperienceWrapper)`
81
+ export const NewFileExperienceWrapper = styled.div`
52
82
  ${({
83
+ breakpoint,
53
84
  dimensions,
54
85
  appearance,
86
+ shouldUsePointerCursor,
87
+ disableOverlay,
88
+ displayBackground,
89
+ selected,
55
90
  isPlayButtonClickable,
56
91
  isTickBoxSelectable,
57
92
  shouldDisplayTooltip
58
93
  }) => `
94
+ ${transition()}
95
+ box-sizing: border-box;
96
+ * {
97
+ box-sizing: border-box;
98
+ }
99
+ position: relative;
100
+ font-family: ${fontFamily()};
101
+ ${getWrapperDimensions(dimensions, appearance)}
102
+ ${displayBackground ? `background-color: ${N20};` : ''}
103
+ ${borderRadius}
104
+ ${getCursorStyle(shouldUsePointerCursor)}
105
+ ${getWrapperShadow(disableOverlay, selected)}
106
+ ${generateResponsiveStyles(breakpoint)}
59
107
  ${hideNativeBrowserTextSelectionStyles}
60
108
 
61
109
  /* We use classnames from here exceptionally to be able to handle styles when the Card is on hover */
62
110
  ${getClickablePlayButtonStyles(isPlayButtonClickable)}
63
111
  ${getSelectableTickBoxStyles(isTickBoxSelectable)}
112
+ &:hover .${blanketClassName} {
113
+ ${fixedBlanketStyles}
114
+ }
64
115
 
65
116
  &:hover .${actionsBarClassName} {
66
117
  ${fixedActionBarStyles}
@@ -70,4 +121,14 @@ export const NewFileExperienceWrapper = styled(SSRFileExperienceWrapper)`
70
121
  ${shouldDisplayTooltip ? `> div { ${getWrapperDimensions(dimensions, appearance)} }` : ''}
71
122
  `}
72
123
  `;
73
- NewFileExperienceWrapper.displayName = 'NewFileExperienceWrapper';
124
+ NewFileExperienceWrapper.displayName = 'NewFileExperienceWrapper';
125
+ export const CardImageContainer = styled.div`
126
+ display: flex;
127
+ position: relative;
128
+ max-width: 100%;
129
+ width: 100%;
130
+ height: 100%;
131
+ max-height: 100%;
132
+ overflow: hidden;
133
+ ${borderRadius}
134
+ `;
@@ -1,6 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { responsiveSettings, getTitleBoxHeight } from '../common';
3
- import { Breakpoint } from '../Breakpoint';
2
+ import { responsiveSettings, getTitleBoxHeight, Breakpoint } from '../common';
4
3
  import { N0 } from '@atlaskit/theme/colors';
5
4
  import { rgba } from '../../../styles/mixins';
6
5
 
@@ -57,14 +57,18 @@ export class CardActionsDropdownMenu extends Component {
57
57
 
58
58
  if (actions.length > 0) {
59
59
  return /*#__PURE__*/React.createElement(DropdownMenu, {
60
- "data-testid": "media-card-actions-menu",
60
+ testId: "media-card-actions-menu",
61
61
  onOpenChange: onOpenChange,
62
- trigger: /*#__PURE__*/React.createElement(CardActionButtonWithAnalytics, {
62
+ trigger: ({
63
+ triggerRef,
64
+ ...providedProps
65
+ }) => /*#__PURE__*/React.createElement(CardActionButtonWithAnalytics, _extends({
63
66
  variant: triggerVariant,
64
67
  style: {
65
68
  color: triggerColor
66
- }
67
- }, /*#__PURE__*/React.createElement(MoreIcon, {
69
+ },
70
+ ref: triggerRef
71
+ }, providedProps), /*#__PURE__*/React.createElement(MoreIcon, {
68
72
  label: "more"
69
73
  }))
70
74
  }, /*#__PURE__*/React.createElement(DropdownItemGroup, null, actions.map(createDropdownItemWithAnalytics)));
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-card",
3
- "version": "72.0.0",
3
+ "version": "72.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -70,6 +70,24 @@ export var RemotePreviewError = /*#__PURE__*/function (_MediaCardError2) {
70
70
 
71
71
  return RemotePreviewError;
72
72
  }(MediaCardError);
73
+ export var SsrPreviewError = /*#__PURE__*/function (_MediaCardError3) {
74
+ _inherits(SsrPreviewError, _MediaCardError3);
75
+
76
+ var _super4 = _createSuper(SsrPreviewError);
77
+
78
+ function SsrPreviewError(primaryReason, secondaryError) {
79
+ var _this4;
80
+
81
+ _classCallCheck(this, SsrPreviewError);
82
+
83
+ _this4 = _super4.call(this, primaryReason, secondaryError);
84
+ _this4.primaryReason = primaryReason;
85
+ _this4.secondaryError = secondaryError;
86
+ return _this4;
87
+ }
88
+
89
+ return SsrPreviewError;
90
+ }(MediaCardError);
73
91
  export var getImageLoadPrimaryReason = function getImageLoadPrimaryReason(source) {
74
92
  switch (source) {
75
93
  case 'cache-remote':
@@ -92,15 +110,15 @@ export var getImageLoadPrimaryReason = function getImageLoadPrimaryReason(source
92
110
  return "unknown-uri";
93
111
  }
94
112
  };
95
- export var ImageLoadError = /*#__PURE__*/function (_MediaCardError3) {
96
- _inherits(ImageLoadError, _MediaCardError3);
113
+ export var ImageLoadError = /*#__PURE__*/function (_MediaCardError4) {
114
+ _inherits(ImageLoadError, _MediaCardError4);
97
115
 
98
- var _super4 = _createSuper(ImageLoadError);
116
+ var _super5 = _createSuper(ImageLoadError);
99
117
 
100
118
  function ImageLoadError(source) {
101
119
  _classCallCheck(this, ImageLoadError);
102
120
 
103
- return _super4.call(this, getImageLoadPrimaryReason(source));
121
+ return _super5.call(this, getImageLoadPrimaryReason(source));
104
122
  }
105
123
 
106
124
  return ImageLoadError;
@@ -126,5 +144,5 @@ export var ensureMediaCardError = function ensureMediaCardError(primaryReason, e
126
144
  return isMediaCardError(error) ? error : new MediaCardError(primaryReason, error);
127
145
  };
128
146
  export var isUploadError = function isUploadError(error) {
129
- return error.primaryReason === 'upload';
147
+ return error && error.primaryReason === 'upload';
130
148
  };