@atlaskit/media-card 73.0.0 → 73.1.2

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 (65) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/actions.js +2 -2
  3. package/dist/cjs/errors.js +7 -5
  4. package/dist/cjs/root/card/cardAnalytics.js +1 -1
  5. package/dist/cjs/root/card/cardState.js +2 -2
  6. package/dist/cjs/root/card/getCardPreview/cache.js +4 -4
  7. package/dist/cjs/root/card/getCardPreview/index.js +2 -2
  8. package/dist/cjs/root/card/index.js +33 -7
  9. package/dist/cjs/root/cardView.js +2 -2
  10. package/dist/cjs/root/inline/loader.js +45 -14
  11. package/dist/cjs/root/inline/mediaInlineCard.js +5 -1
  12. package/dist/cjs/root/inlinePlayer.js +76 -23
  13. package/dist/cjs/root/ui/loadingRateLimited/styled.js +1 -1
  14. package/dist/cjs/root/ui/progressBar/progressBar.js +5 -2
  15. package/dist/cjs/root/ui/progressBar/styled.js +6 -5
  16. package/dist/cjs/root/ui/styled.js +1 -1
  17. package/dist/cjs/utils/cardActions/cardActionsDropdownMenu.js +3 -1
  18. package/dist/cjs/utils/viewportDetector.js +51 -22
  19. package/dist/cjs/version.json +1 -1
  20. package/dist/es2019/root/card/cardAnalytics.js +1 -1
  21. package/dist/es2019/root/card/index.js +39 -7
  22. package/dist/es2019/root/inline/loader.js +15 -4
  23. package/dist/es2019/root/inline/mediaInlineCard.js +5 -1
  24. package/dist/es2019/root/inlinePlayer.js +56 -4
  25. package/dist/es2019/root/ui/loadingRateLimited/styled.js +1 -1
  26. package/dist/es2019/root/ui/progressBar/progressBar.js +4 -2
  27. package/dist/es2019/root/ui/progressBar/styled.js +6 -4
  28. package/dist/es2019/root/ui/styled.js +1 -1
  29. package/dist/es2019/utils/viewportDetector.js +50 -18
  30. package/dist/es2019/version.json +1 -1
  31. package/dist/esm/actions.js +2 -2
  32. package/dist/esm/errors.js +6 -5
  33. package/dist/esm/root/card/cardAnalytics.js +1 -1
  34. package/dist/esm/root/card/cardState.js +2 -2
  35. package/dist/esm/root/card/getCardPreview/cache.js +3 -2
  36. package/dist/esm/root/card/getCardPreview/index.js +2 -2
  37. package/dist/esm/root/card/index.js +39 -9
  38. package/dist/esm/root/cardView.js +2 -2
  39. package/dist/esm/root/inline/loader.js +46 -14
  40. package/dist/esm/root/inline/mediaInlineCard.js +5 -1
  41. package/dist/esm/root/inlinePlayer.js +74 -23
  42. package/dist/esm/root/ui/loadingRateLimited/styled.js +1 -1
  43. package/dist/esm/root/ui/progressBar/progressBar.js +5 -2
  44. package/dist/esm/root/ui/progressBar/styled.js +6 -5
  45. package/dist/esm/root/ui/styled.js +1 -1
  46. package/dist/esm/utils/cardActions/cardActionsDropdownMenu.js +2 -1
  47. package/dist/esm/utils/viewportDetector.js +50 -21
  48. package/dist/esm/version.json +1 -1
  49. package/dist/types/index.d.ts +1 -0
  50. package/dist/types/root/card/index.d.ts +2 -0
  51. package/dist/types/root/cardView.d.ts +1 -1
  52. package/dist/types/root/inline/loader.d.ts +2 -0
  53. package/dist/types/root/inlinePlayer.d.ts +8 -1
  54. package/dist/types/root/ui/progressBar/progressBar.d.ts +2 -1
  55. package/dist/types/root/ui/progressBar/styled.d.ts +2 -1
  56. package/dist/types/utils/viewportDetector.d.ts +13 -5
  57. package/package.json +7 -9
  58. package/dist/cjs/utils/lazyContent/index.js +0 -56
  59. package/dist/cjs/utils/lazyContent/styled.js +0 -23
  60. package/dist/es2019/utils/lazyContent/index.js +0 -18
  61. package/dist/es2019/utils/lazyContent/styled.js +0 -12
  62. package/dist/esm/utils/lazyContent/index.js +0 -41
  63. package/dist/esm/utils/lazyContent/styled.js +0 -14
  64. package/dist/types/utils/lazyContent/index.d.ts +0 -11
  65. package/dist/types/utils/lazyContent/styled.d.ts +0 -5
@@ -18,12 +18,15 @@ var ProgressBar = function ProgressBar(_ref) {
18
18
  _ref$breakpoint = _ref.breakpoint,
19
19
  breakpoint = _ref$breakpoint === void 0 ? _common.Breakpoint.SMALL : _ref$breakpoint,
20
20
  _ref$positionBottom = _ref.positionBottom,
21
- positionBottom = _ref$positionBottom === void 0 ? false : _ref$positionBottom;
21
+ positionBottom = _ref$positionBottom === void 0 ? false : _ref$positionBottom,
22
+ _ref$showOnTop = _ref.showOnTop,
23
+ showOnTop = _ref$showOnTop === void 0 ? false : _ref$showOnTop;
22
24
  var normalizedProgress = Math.min(1, Math.max(0, progress || 0)) * 100;
23
25
  return /*#__PURE__*/_react.default.createElement(_styled.StyledBar, {
24
26
  progress: normalizedProgress,
25
27
  breakpoint: breakpoint,
26
- positionBottom: positionBottom
28
+ positionBottom: positionBottom,
29
+ showOnTop: showOnTop
27
30
  });
28
31
  };
29
32
 
@@ -35,19 +35,20 @@ var largeSizeSettings = {
35
35
  marginBottom: 12
36
36
  };
37
37
 
38
- function generateResponsiveStyles(breakpoint, positionBottom) {
39
- var multiplier = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
38
+ function generateResponsiveStyles(breakpoint, positionBottom, showOnTop) {
39
+ var multiplier = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
40
40
  var setting = breakpoint === _common.Breakpoint.SMALL ? smallSizeSettings : largeSizeSettings;
41
41
  var marginPositionBottom = _common.responsiveSettings[breakpoint].titleBox.verticalPadding;
42
42
  var marginBottom = setting.marginBottom * multiplier + (positionBottom ? marginPositionBottom : (0, _common.getTitleBoxHeight)(breakpoint));
43
- return "\n bottom: ".concat(marginBottom, "px\n ");
43
+ return "\n ".concat(showOnTop ? 'top' : 'bottom', ": ").concat(marginBottom, "px\n ");
44
44
  }
45
45
 
46
46
  var StyledBar = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n ", "\n"])), function (_ref) {
47
47
  var progress = _ref.progress,
48
48
  breakpoint = _ref.breakpoint,
49
- positionBottom = _ref.positionBottom;
50
- return "\n ".concat(_mediaUi.borderRadius, "\n overflow: hidden;\n position: absolute;\n width: ").concat(width, "%;\n left: ").concat(left, "%;\n background-color: ").concat((0, _mixins.rgba)(_colors.N0, 0.8), ";\n height: ").concat(height + padding * 2, "px;\n padding: ").concat(padding, "px;\n\n ::before {\n content: '';\n width: ").concat(progress, "%;\n height: 100%;\n background-color: ").concat(_colors.N400, ";\n ").concat(_mediaUi.borderRadius, "\n display: block;\n }\n\n ").concat(generateResponsiveStyles(breakpoint, positionBottom), "\n");
49
+ positionBottom = _ref.positionBottom,
50
+ showOnTop = _ref.showOnTop;
51
+ return "\n ".concat(_mediaUi.borderRadius, "\n overflow: hidden;\n position: absolute;\n width: ").concat(width, "%;\n left: ").concat(left, "%;\n background-color: ").concat((0, _mixins.rgba)(_colors.N0, 0.8), ";\n height: ").concat(height + padding * 2, "px;\n padding: ").concat(padding, "px;\n box-sizing: border-box;\n\n ::before {\n content: '';\n width: ").concat(progress, "%;\n height: 100%;\n background-color: ").concat(_colors.N400, ";\n ").concat(_mediaUi.borderRadius, "\n display: block;\n }\n\n ").concat(generateResponsiveStyles(breakpoint, positionBottom, showOnTop), "\n");
51
52
  });
52
53
 
53
54
  exports.StyledBar = StyledBar;
@@ -119,7 +119,7 @@ var NewFileExperienceWrapper = _styledComponents.default.div(_templateObject ||
119
119
  isPlayButtonClickable = _ref6.isPlayButtonClickable,
120
120
  isTickBoxSelectable = _ref6.isTickBoxSelectable,
121
121
  shouldDisplayTooltip = _ref6.shouldDisplayTooltip;
122
- return "\n ".concat((0, _styles.transition)(), "\n box-sizing: border-box;\n * {\n box-sizing: border-box;\n }\n position: relative;\n font-family: ").concat((0, _constants.fontFamily)(), ";\n ").concat(getWrapperDimensions(dimensions, appearance), "\n ").concat(displayBackground ? "background-color: ".concat(_colors.N20, ";") : '', "\n ").concat(_mediaUi.borderRadius, "\n ").concat(getCursorStyle(shouldUsePointerCursor), "\n ").concat(getWrapperShadow(disableOverlay, selected), "\n ").concat(generateResponsiveStyles(breakpoint), "\n ").concat(_selection.hideNativeBrowserTextSelectionStyles, "\n\n /* We use classnames from here exceptionally to be able to handle styles when the Card is on hover */\n ").concat(getClickablePlayButtonStyles(isPlayButtonClickable), "\n ").concat(getSelectableTickBoxStyles(isTickBoxSelectable), "\n &:hover .").concat(_styled2.blanketClassName, " {\n ").concat(_styled2.fixedBlanketStyles, "\n }\n\n &:hover .").concat(_styled3.actionsBarClassName, " {\n ").concat(_styled3.fixedActionBarStyles, "\n }\n\n /* Tooltip does not support percentage dimensions. We enforce them here */\n ").concat(shouldDisplayTooltip ? "> div { ".concat(getWrapperDimensions(dimensions, appearance), " }") : '', "\n");
122
+ return "\n ".concat((0, _styles.transition)(), "\n box-sizing: border-box;\n * {\n box-sizing: border-box;\n }\n position: relative;\n font-family: ").concat((0, _constants.fontFamily)(), ";\n ").concat(getWrapperDimensions(dimensions, appearance), "\n ").concat(displayBackground ? "background-color: ".concat(_colors.N20, ";") : '', "\n ").concat(_mediaUi.borderRadius, "\n ").concat(getCursorStyle(shouldUsePointerCursor), "\n ").concat(getWrapperShadow(disableOverlay, selected), "\n ").concat(generateResponsiveStyles(breakpoint), "\n ").concat(_selection.hideNativeBrowserTextSelectionStyles, "\n\n /* We use classnames from here exceptionally to be able to handle styles when the Card is on hover */\n ").concat(getClickablePlayButtonStyles(isPlayButtonClickable), "\n ").concat(getSelectableTickBoxStyles(isTickBoxSelectable), "\n &:hover .").concat(_styled2.blanketClassName, " {\n ").concat(_styled2.fixedBlanketStyles, "\n }\n\n &:hover .").concat(_styled3.actionsBarClassName, " {\n ").concat(_styled3.fixedActionBarStyles, "\n }\n\n /* Tooltip does not support percentage dimensions. We enforce them here */\n ").concat(shouldDisplayTooltip ? "> div { width: 100%; height: 100% }" : '', "\n");
123
123
  });
124
124
 
125
125
  exports.NewFileExperienceWrapper = NewFileExperienceWrapper;
@@ -35,6 +35,8 @@ var _analyticsNext = require("@atlaskit/analytics-next");
35
35
 
36
36
  var _analytics = require("../analytics");
37
37
 
38
+ var _excluded = ["triggerRef"];
39
+
38
40
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
39
41
 
40
42
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -109,7 +111,7 @@ var CardActionsDropdownMenu = /*#__PURE__*/function (_Component) {
109
111
  onOpenChange: onOpenChange,
110
112
  trigger: function trigger(_ref) {
111
113
  var triggerRef = _ref.triggerRef,
112
- providedProps = (0, _objectWithoutProperties2.default)(_ref, ["triggerRef"]);
114
+ providedProps = (0, _objectWithoutProperties2.default)(_ref, _excluded);
113
115
  return /*#__PURE__*/_react.default.createElement(CardActionButtonWithAnalytics, (0, _extends2.default)({
114
116
  variant: triggerVariant,
115
117
  style: {
@@ -5,12 +5,10 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.createViewportDetector = exports.ViewportDetector = void 0;
8
+ exports.ViewportDetector = exports.ViewportAnchor = exports.ABS_VIEWPORT_ANCHOR_OFFSET_TOP = void 0;
9
9
 
10
10
  var _react = _interopRequireWildcard(require("react"));
11
11
 
12
- var _lazyContent = require("./lazyContent");
13
-
14
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
13
 
16
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -21,6 +19,31 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
21
19
 
22
20
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
23
21
 
22
+ /**
23
+ * As IntersectionObserver::rootMargin doesn't work within IFrames, we use an empty div + dynamic offsetTop to eagerly detect cards entering viewport.
24
+ * Using this approach, we can lazy load cards ABS_VIEWPORT_ANCHOR_OFFSET_TOP px before they enter viewport.
25
+ */
26
+ var ABS_VIEWPORT_ANCHOR_OFFSET_TOP = 900; //px
27
+
28
+ exports.ABS_VIEWPORT_ANCHOR_OFFSET_TOP = ABS_VIEWPORT_ANCHOR_OFFSET_TOP;
29
+ var ViewportAnchor = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
30
+ if (typeof IntersectionObserver === 'undefined') {
31
+ return null;
32
+ }
33
+
34
+ return /*#__PURE__*/_react.default.createElement("div", {
35
+ ref: ref,
36
+ className: "media-card-viewport-anchor",
37
+ style: {
38
+ position: 'absolute',
39
+ top: "".concat(props.offsetTop, "px"),
40
+ maxHeight: 0,
41
+ pointerEvents: 'none'
42
+ }
43
+ });
44
+ });
45
+ exports.ViewportAnchor = ViewportAnchor;
46
+
24
47
  var createIntersectionObserverCallback = function createIntersectionObserverCallback(onVisible) {
25
48
  return function (entries, observer) {
26
49
  var _iterator = _createForOfIteratorHelper(entries),
@@ -44,36 +67,42 @@ var createIntersectionObserverCallback = function createIntersectionObserverCall
44
67
  };
45
68
  };
46
69
 
47
- var Observer = function Observer(_ref) {
70
+ var ViewportObserver = function ViewportObserver(_ref) {
48
71
  var onVisible = _ref.onVisible,
72
+ cardEl = _ref.cardEl,
49
73
  children = _ref.children,
50
- targetRef = _ref.targetRef;
74
+ preAnchorRef = _ref.preAnchorRef,
75
+ postAnchorRef = _ref.postAnchorRef;
51
76
  (0, _react.useEffect)(function () {
52
77
  // IntersectionObserver uses root and target elements to detect intersections, defaulting root to the viewport
53
78
  var intersectionObserver = new IntersectionObserver(createIntersectionObserverCallback(onVisible));
54
- targetRef && intersectionObserver.observe(targetRef);
79
+ (preAnchorRef === null || preAnchorRef === void 0 ? void 0 : preAnchorRef.current) && intersectionObserver.observe(preAnchorRef.current);
80
+ (postAnchorRef === null || postAnchorRef === void 0 ? void 0 : postAnchorRef.current) && intersectionObserver.observe(postAnchorRef.current);
81
+ cardEl && intersectionObserver.observe(cardEl);
55
82
  return function () {
56
83
  intersectionObserver.disconnect();
57
84
  };
58
- }, [targetRef, onVisible]);
85
+ }, [cardEl, preAnchorRef, postAnchorRef, onVisible]);
59
86
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
60
87
  };
61
88
 
62
- var createViewportDetector = function createViewportDetector(isIntersectionObserverSupported) {
63
- return function (_ref2) {
64
- var children = _ref2.children,
65
- targetRef = _ref2.targetRef,
66
- onVisible = _ref2.onVisible;
67
- return isIntersectionObserverSupported ? /*#__PURE__*/_react.default.createElement(Observer, {
68
- targetRef: targetRef,
69
- onVisible: onVisible
70
- }, children) : /*#__PURE__*/_react.default.createElement(_lazyContent.LazyContent, {
71
- placeholder: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children),
72
- onRender: onVisible
73
- }, children);
74
- };
89
+ var ViewportDetector = function ViewportDetector(_ref2) {
90
+ var cardEl = _ref2.cardEl,
91
+ preAnchorRef = _ref2.preAnchorRef,
92
+ postAnchorRef = _ref2.postAnchorRef,
93
+ onVisible = _ref2.onVisible,
94
+ children = _ref2.children;
95
+
96
+ if (typeof IntersectionObserver === 'undefined') {
97
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
98
+ }
99
+
100
+ return /*#__PURE__*/_react.default.createElement(ViewportObserver, {
101
+ cardEl: cardEl,
102
+ preAnchorRef: preAnchorRef,
103
+ postAnchorRef: postAnchorRef,
104
+ onVisible: onVisible
105
+ }, children);
75
106
  };
76
107
 
77
- exports.createViewportDetector = createViewportDetector;
78
- var ViewportDetector = createViewportDetector(typeof IntersectionObserver !== 'undefined');
79
108
  exports.ViewportDetector = ViewportDetector;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-card",
3
- "version": "73.0.0",
3
+ "version": "73.1.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import { fireMediaCardEvent, getRenderSucceededEventPayload, getRenderErrorEventPayload, getRenderFailedFileStatusPayload, getCopiedFilePayload, getRenderCommencedEventPayload, getRenderPreviewableCardPayload } from '../../utils/analytics';
2
- export const relevantFeatureFlagNames = ['newCardExperience', 'captions'];
2
+ export const relevantFeatureFlagNames = ['newCardExperience', 'captions', 'timestampOnVideo'];
3
3
  export const fireOperationalEvent = (createAnalyticsEvent, status, fileAttributes, performanceAttributes, error) => {
4
4
  const fireEvent = payload => fireMediaCardEvent(payload, createAnalyticsEvent);
5
5
 
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React, { Component } from 'react';
2
+ import React, { Component, createRef } from 'react';
3
3
  import ReactDOM from 'react-dom';
4
4
  import { version as packageVersion, name as packageName } from '../../version.json';
5
5
  import { withAnalyticsEvents } from '@atlaskit/analytics-next';
@@ -9,7 +9,7 @@ import { globalMediaEventEmitter, isDifferentIdentifier, isFileIdentifier, RECEN
9
9
  import { MediaViewer } from '@atlaskit/media-viewer';
10
10
  import { injectIntl, IntlProvider } from 'react-intl-next';
11
11
  import { CardView } from '../cardView';
12
- import { ViewportDetector } from '../../utils/viewportDetector';
12
+ import { ABS_VIEWPORT_ANCHOR_OFFSET_TOP, ViewportDetector, ViewportAnchor } from '../../utils/viewportDetector';
13
13
  import { getRequestedDimensions } from '../../utils/getDataURIDimension';
14
14
  import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, fetchAndCacheRemotePreview } from './getCardPreview';
15
15
  import { getFileDetails } from '../../utils/metadata';
@@ -19,6 +19,8 @@ import { isLocalPreviewError, MediaCardError, ensureMediaCardError, ImageLoadErr
19
19
  import { fireOperationalEvent, fireCommencedEvent, relevantFeatureFlagNames, fireCopiedEvent, fireScreenEvent } from './cardAnalytics';
20
20
  import getDocument from '../../utils/document';
21
21
  import { getCardStateFromFileState, createStateUpdater } from './cardState';
22
+ import { isProcessedFileState } from '@atlaskit/media-client';
23
+ import { getMediaFeatureFlag } from '@atlaskit/media-common';
22
24
  export class CardBase extends Component {
23
25
  // We initialise timeElapsedTillCommenced
24
26
  // to avoid extra branching on a possibly undefined value.
@@ -27,6 +29,10 @@ export class CardBase extends Component {
27
29
 
28
30
  _defineProperty(this, "hasBeenMounted", false);
29
31
 
32
+ _defineProperty(this, "viewportPreAnchorRef", /*#__PURE__*/createRef());
33
+
34
+ _defineProperty(this, "viewportPostAnchorRef", /*#__PURE__*/createRef());
35
+
30
36
  _defineProperty(this, "timeElapsedTillCommenced", performance.now());
31
37
 
32
38
  _defineProperty(this, "getImageURLParams", ({
@@ -260,7 +266,8 @@ export class CardBase extends Component {
260
266
 
261
267
  if (useInlinePlayer && isVideo && !!cardPreview) {
262
268
  this.setState({
263
- isPlayingFile: true
269
+ isPlayingFile: true,
270
+ shouldAutoplay: true
264
271
  });
265
272
  } else if (shouldOpenMediaViewer) {
266
273
  let mediaViewerSelectedItem;
@@ -307,11 +314,15 @@ export class CardBase extends Component {
307
314
  testId,
308
315
  originalDimensions
309
316
  } = this.props;
317
+ const {
318
+ shouldAutoplay
319
+ } = this.state;
310
320
  return /*#__PURE__*/React.createElement(InlinePlayer, {
311
321
  mediaClient: mediaClient,
312
322
  dimensions: dimensions,
313
323
  originalDimensions: originalDimensions,
314
324
  identifier: identifier,
325
+ autoplay: !!shouldAutoplay,
315
326
  onError: this.onInlinePlayerError,
316
327
  onClick: this.onClick,
317
328
  selected: selected,
@@ -459,9 +470,17 @@ export class CardBase extends Component {
459
470
  forceSyncDisplay: forceSyncDisplay
460
471
  });
461
472
  return isLazy ? /*#__PURE__*/React.createElement(ViewportDetector, {
462
- targetRef: cardRef,
473
+ cardEl: cardRef,
474
+ preAnchorRef: this.viewportPreAnchorRef,
475
+ postAnchorRef: this.viewportPostAnchorRef,
463
476
  onVisible: this.onCardInViewport
464
- }, card) : card;
477
+ }, /*#__PURE__*/React.createElement(ViewportAnchor, {
478
+ ref: this.viewportPreAnchorRef,
479
+ offsetTop: -ABS_VIEWPORT_ANCHOR_OFFSET_TOP
480
+ }), card, /*#__PURE__*/React.createElement(ViewportAnchor, {
481
+ ref: this.viewportPostAnchorRef,
482
+ offsetTop: ABS_VIEWPORT_ANCHOR_OFFSET_TOP
483
+ })) : card;
465
484
  });
466
485
 
467
486
  _defineProperty(this, "onCardInViewport", () => {
@@ -547,6 +566,7 @@ export class CardBase extends Component {
547
566
  status: _status,
548
567
  isCardVisible: _isCardVisible,
549
568
  isPlayingFile: false,
569
+ shouldAutoplay: false,
550
570
  cardPreview: _cardPreview,
551
571
  cardRef: null,
552
572
  isBannedLocalPreview: false,
@@ -595,7 +615,9 @@ export class CardBase extends Component {
595
615
  mediaClient,
596
616
  identifier,
597
617
  dimensions,
598
- featureFlags
618
+ featureFlags,
619
+ useInlinePlayer,
620
+ disableOverlay
599
621
  } = this.props;
600
622
  const {
601
623
  isCardVisible,
@@ -603,7 +625,8 @@ export class CardBase extends Component {
603
625
  status,
604
626
  fileState,
605
627
  isBannedLocalPreview,
606
- previewDidRender
628
+ previewDidRender,
629
+ isPlayingFile
607
630
  } = this.state;
608
631
  const isDifferent = isDifferentIdentifier(prevIdentifier, identifier);
609
632
  const turnedVisible = !prevIsCardVisible && isCardVisible;
@@ -662,6 +685,15 @@ export class CardBase extends Component {
662
685
  });
663
686
  this.unsubscribe();
664
687
  }
688
+
689
+ const isVideo = this.fileAttributes.fileMediatype === 'video';
690
+ const videoAvailableToPlay = fileState && isProcessedFileState(fileState);
691
+
692
+ if (isVideo && !isPlayingFile && disableOverlay && useInlinePlayer && videoAvailableToPlay && getMediaFeatureFlag('timestampOnVideo', this.props.featureFlags)) {
693
+ this.setState({
694
+ isPlayingFile: true
695
+ });
696
+ }
665
697
  }
666
698
 
667
699
  componentWillUnmount() {
@@ -5,6 +5,8 @@ export default class MediaInlineCardLoader extends React.PureComponent {
5
5
  constructor(...args) {
6
6
  super(...args);
7
7
 
8
+ _defineProperty(this, "isMounted", false);
9
+
8
10
  _defineProperty(this, "state", {
9
11
  MediaInlineCard: MediaInlineCardLoader.MediaInlineCard,
10
12
  ErrorBoundary: MediaInlineCardLoader.ErrorBoundary
@@ -12,6 +14,8 @@ export default class MediaInlineCardLoader extends React.PureComponent {
12
14
  }
13
15
 
14
16
  async componentDidMount() {
17
+ this.isMounted = true;
18
+
15
19
  if (!this.state.MediaInlineCard) {
16
20
  try {
17
21
  const [mediaClient, cardModule, mediaCardErrorBoundaryModule] = await Promise.all([import(
@@ -23,14 +27,21 @@ export default class MediaInlineCardLoader extends React.PureComponent {
23
27
  '../media-card-analytics-error-boundary')]);
24
28
  MediaInlineCardLoader.MediaInlineCard = mediaClient.withMediaClient(cardModule.MediaInlineCard);
25
29
  MediaInlineCardLoader.ErrorBoundary = mediaCardErrorBoundaryModule.default;
26
- this.setState({
27
- MediaInlineCard: MediaInlineCardLoader.MediaInlineCard,
28
- ErrorBoundary: MediaInlineCardLoader.ErrorBoundary
29
- });
30
+
31
+ if (this.isMounted) {
32
+ this.setState({
33
+ MediaInlineCard: MediaInlineCardLoader.MediaInlineCard,
34
+ ErrorBoundary: MediaInlineCardLoader.ErrorBoundary
35
+ });
36
+ }
30
37
  } catch (error) {}
31
38
  }
32
39
  }
33
40
 
41
+ async componentWillUnmount() {
42
+ this.isMounted = false;
43
+ }
44
+
34
45
  render() {
35
46
  const {
36
47
  MediaInlineCard,
@@ -59,16 +59,20 @@ export const MediaInlineCardInternal = ({
59
59
  locale: 'en'
60
60
  });
61
61
  useEffect(() => {
62
- mediaClient.file.getFileState(identifier.id, {
62
+ const subscription = mediaClient.file.getFileState(identifier.id, {
63
63
  collectionName: identifier.collectionName
64
64
  }).subscribe({
65
65
  next: fileState => {
66
66
  setFileState(fileState);
67
+ setIsErrored(false);
67
68
  },
68
69
  error: () => {
69
70
  setIsErrored(true);
70
71
  }
71
72
  });
73
+ return () => {
74
+ subscription.unsubscribe();
75
+ };
72
76
  }, [identifier.collectionName, identifier.id, mediaClient.file]);
73
77
 
74
78
  if (!fileState) {
@@ -7,6 +7,10 @@ import { CustomMediaPlayer, InactivityDetector } from '@atlaskit/media-ui';
7
7
  import { InlinePlayerWrapper } from './styled';
8
8
  import { defaultImageCardDimensions } from '..';
9
9
  import { CardLoading } from '../utils/lightCards/cardLoading';
10
+ import { ProgressBar } from './ui/progressBar/progressBar';
11
+ import { calcBreakpointSize } from './ui/styled';
12
+ import { isValidPercentageUnit } from '../utils/isValidPercentageUnit';
13
+ import { getElementDimension } from '../utils/getElementDimension';
10
14
  export const inlinePlayerClassName = 'media-card-inline-player';
11
15
  export const getPreferredVideoArtifact = fileState => {
12
16
  if (fileState.status === 'processed' || fileState.status === 'processing') {
@@ -29,6 +33,8 @@ export class InlinePlayerBase extends Component {
29
33
 
30
34
  _defineProperty(this, "state", {});
31
35
 
36
+ _defineProperty(this, "divRef", /*#__PURE__*/React.createRef());
37
+
32
38
  _defineProperty(this, "setFileSrc", fileSrc => {
33
39
  this.setState({
34
40
  fileSrc
@@ -93,9 +99,31 @@ export class InlinePlayerBase extends Component {
93
99
  viewingLevel: 'full'
94
100
  });
95
101
  });
102
+
103
+ _defineProperty(this, "saveElementWidth", () => {
104
+ const {
105
+ dimensions
106
+ } = this.props;
107
+
108
+ if (!dimensions) {
109
+ return;
110
+ }
111
+
112
+ const {
113
+ width
114
+ } = dimensions;
115
+
116
+ if (width && isValidPercentageUnit(width) && !!this.divRef.current) {
117
+ const elementWidth = getElementDimension(this.divRef.current, 'width');
118
+ this.setState({
119
+ elementWidth
120
+ });
121
+ }
122
+ });
96
123
  }
97
124
 
98
125
  componentDidMount() {
126
+ this.saveElementWidth();
99
127
  const {
100
128
  mediaClient,
101
129
  identifier
@@ -110,6 +138,17 @@ export class InlinePlayerBase extends Component {
110
138
  collectionName
111
139
  }).subscribe({
112
140
  next: async fileState => {
141
+ if (fileState.status === 'uploading') {
142
+ this.setState({
143
+ isUploading: true,
144
+ progress: fileState.progress
145
+ });
146
+ } else {
147
+ this.setState({
148
+ isUploading: false
149
+ });
150
+ }
151
+
113
152
  const {
114
153
  fileSrc: existingFileSrc
115
154
  } = this.state; // we want to reuse the existing fileSrc to prevent re renders
@@ -163,6 +202,11 @@ export class InlinePlayerBase extends Component {
163
202
  this.revoke();
164
203
  }
165
204
 
205
+ get breakpoint() {
206
+ const width = this.state.elementWidth || (this.props.dimensions ? this.props.dimensions.width : '') || defaultImageCardDimensions.width;
207
+ return calcBreakpointSize(parseInt(`${width}`, 10));
208
+ }
209
+
166
210
  render() {
167
211
  const {
168
212
  onClick,
@@ -171,10 +215,13 @@ export class InlinePlayerBase extends Component {
171
215
  selected,
172
216
  testId,
173
217
  identifier,
174
- forwardRef
218
+ forwardRef,
219
+ autoplay
175
220
  } = this.props;
176
221
  const {
177
- fileSrc
222
+ fileSrc,
223
+ isUploading,
224
+ progress
178
225
  } = this.state;
179
226
 
180
227
  if (!fileSrc) {
@@ -195,7 +242,7 @@ export class InlinePlayerBase extends Component {
195
242
  type: "video",
196
243
  src: fileSrc,
197
244
  fileId: identifier.id,
198
- isAutoPlay: true,
245
+ isAutoPlay: autoplay,
199
246
  isHDAvailable: false,
200
247
  onDownloadClick: this.onDownloadClick,
201
248
  onFirstPlay: this.onFirstPlay,
@@ -204,7 +251,12 @@ export class InlinePlayerBase extends Component {
204
251
  },
205
252
  originalDimensions: originalDimensions,
206
253
  showControls: checkMouseMovement
207
- })));
254
+ })), isUploading ? /*#__PURE__*/React.createElement(ProgressBar, {
255
+ progress: progress,
256
+ breakpoint: this.breakpoint,
257
+ positionBottom: true,
258
+ showOnTop: true
259
+ }) : null);
208
260
  }
209
261
 
210
262
  }
@@ -31,7 +31,7 @@ export const LoadingRateLimitedTextWrapper = styled.div`
31
31
  display: block;
32
32
  width:100%;
33
33
  text-align:center;
34
- ${generateResponsiveStyles(breakpoint, positionBottom, 1)}
34
+ ${generateResponsiveStyles(breakpoint, positionBottom, false, 1)}
35
35
  `}
36
36
  `;
37
37
  LoadingRateLimitedTextWrapper.displayName = 'LoadingRateLimitedTextWrapper';
@@ -4,12 +4,14 @@ import { Breakpoint } from '../common';
4
4
  export const ProgressBar = ({
5
5
  progress,
6
6
  breakpoint = Breakpoint.SMALL,
7
- positionBottom = false
7
+ positionBottom = false,
8
+ showOnTop = false
8
9
  }) => {
9
10
  const normalizedProgress = Math.min(1, Math.max(0, progress || 0)) * 100;
10
11
  return /*#__PURE__*/React.createElement(StyledBar, {
11
12
  progress: normalizedProgress,
12
13
  breakpoint: breakpoint,
13
- positionBottom: positionBottom
14
+ positionBottom: positionBottom,
15
+ showOnTop: showOnTop
14
16
  });
15
17
  };
@@ -15,19 +15,20 @@ const smallSizeSettings = {
15
15
  const largeSizeSettings = {
16
16
  marginBottom: 12
17
17
  };
18
- export function generateResponsiveStyles(breakpoint, positionBottom, multiplier = 1) {
18
+ export function generateResponsiveStyles(breakpoint, positionBottom, showOnTop, multiplier = 1) {
19
19
  const setting = breakpoint === Breakpoint.SMALL ? smallSizeSettings : largeSizeSettings;
20
20
  const marginPositionBottom = responsiveSettings[breakpoint].titleBox.verticalPadding;
21
21
  const marginBottom = setting.marginBottom * multiplier + (positionBottom ? marginPositionBottom : getTitleBoxHeight(breakpoint));
22
22
  return `
23
- bottom: ${marginBottom}px
23
+ ${showOnTop ? 'top' : 'bottom'}: ${marginBottom}px
24
24
  `;
25
25
  }
26
26
  export const StyledBar = styled.div`
27
27
  ${({
28
28
  progress,
29
29
  breakpoint,
30
- positionBottom
30
+ positionBottom,
31
+ showOnTop
31
32
  }) => `
32
33
  ${borderRadius}
33
34
  overflow: hidden;
@@ -37,6 +38,7 @@ export const StyledBar = styled.div`
37
38
  background-color: ${rgba(N0, 0.8)};
38
39
  height: ${height + padding * 2}px;
39
40
  padding: ${padding}px;
41
+ box-sizing: border-box;
40
42
 
41
43
  ::before {
42
44
  content: '';
@@ -47,7 +49,7 @@ export const StyledBar = styled.div`
47
49
  display: block;
48
50
  }
49
51
 
50
- ${generateResponsiveStyles(breakpoint, positionBottom)}
52
+ ${generateResponsiveStyles(breakpoint, positionBottom, showOnTop)}
51
53
  `}
52
54
  `;
53
55
  StyledBar.displayName = 'StyledProgressBar';
@@ -118,7 +118,7 @@ export const NewFileExperienceWrapper = styled.div`
118
118
  }
119
119
 
120
120
  /* Tooltip does not support percentage dimensions. We enforce them here */
121
- ${shouldDisplayTooltip ? `> div { ${getWrapperDimensions(dimensions, appearance)} }` : ''}
121
+ ${shouldDisplayTooltip ? `> div { width: 100%; height: 100% }` : ''}
122
122
  `}
123
123
  `;
124
124
  NewFileExperienceWrapper.displayName = 'NewFileExperienceWrapper';