@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
@@ -20,6 +20,10 @@ import { CustomMediaPlayer, InactivityDetector } from '@atlaskit/media-ui';
20
20
  import { InlinePlayerWrapper } from './styled';
21
21
  import { defaultImageCardDimensions } from '..';
22
22
  import { CardLoading } from '../utils/lightCards/cardLoading';
23
+ import { ProgressBar } from './ui/progressBar/progressBar';
24
+ import { calcBreakpointSize } from './ui/styled';
25
+ import { isValidPercentageUnit } from '../utils/isValidPercentageUnit';
26
+ import { getElementDimension } from '../utils/getElementDimension';
23
27
  export var inlinePlayerClassName = 'media-card-inline-player';
24
28
  export var getPreferredVideoArtifact = function getPreferredVideoArtifact(fileState) {
25
29
  if (fileState.status === 'processed' || fileState.status === 'processing') {
@@ -52,6 +56,8 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
52
56
 
53
57
  _defineProperty(_assertThisInitialized(_this), "state", {});
54
58
 
59
+ _defineProperty(_assertThisInitialized(_this), "divRef", /*#__PURE__*/React.createRef());
60
+
55
61
  _defineProperty(_assertThisInitialized(_this), "setFileSrc", function (fileSrc) {
56
62
  _this.setState({
57
63
  fileSrc: fileSrc
@@ -126,6 +132,24 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
126
132
  });
127
133
  });
128
134
 
135
+ _defineProperty(_assertThisInitialized(_this), "saveElementWidth", function () {
136
+ var dimensions = _this.props.dimensions;
137
+
138
+ if (!dimensions) {
139
+ return;
140
+ }
141
+
142
+ var width = dimensions.width;
143
+
144
+ if (width && isValidPercentageUnit(width) && !!_this.divRef.current) {
145
+ var elementWidth = getElementDimension(_this.divRef.current, 'width');
146
+
147
+ _this.setState({
148
+ elementWidth: elementWidth
149
+ });
150
+ }
151
+ });
152
+
129
153
  return _this;
130
154
  }
131
155
 
@@ -134,6 +158,7 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
134
158
  value: function componentDidMount() {
135
159
  var _this2 = this;
136
160
 
161
+ this.saveElementWidth();
137
162
  var _this$props3 = this.props,
138
163
  mediaClient = _this$props3.mediaClient,
139
164
  identifier = _this$props3.identifier;
@@ -152,30 +177,41 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
152
177
  while (1) {
153
178
  switch (_context2.prev = _context2.next) {
154
179
  case 0:
180
+ if (fileState.status === 'uploading') {
181
+ _this2.setState({
182
+ isUploading: true,
183
+ progress: fileState.progress
184
+ });
185
+ } else {
186
+ _this2.setState({
187
+ isUploading: false
188
+ });
189
+ }
190
+
155
191
  existingFileSrc = _this2.state.fileSrc; // we want to reuse the existing fileSrc to prevent re renders
156
192
 
157
193
  if (!existingFileSrc) {
158
- _context2.next = 3;
194
+ _context2.next = 4;
159
195
  break;
160
196
  }
161
197
 
162
198
  return _context2.abrupt("return");
163
199
 
164
- case 3:
200
+ case 4:
165
201
  if (!(fileState.status !== 'error' && fileState.preview)) {
166
- _context2.next = 12;
202
+ _context2.next = 13;
167
203
  break;
168
204
  }
169
205
 
170
- _context2.next = 6;
206
+ _context2.next = 7;
171
207
  return fileState.preview;
172
208
 
173
- case 6:
209
+ case 7:
174
210
  _yield$fileState$prev = _context2.sent;
175
211
  value = _yield$fileState$prev.value;
176
212
 
177
213
  if (!(value instanceof Blob && value.type.indexOf('video/') === 0)) {
178
- _context2.next = 12;
214
+ _context2.next = 13;
179
215
  break;
180
216
  }
181
217
 
@@ -185,9 +221,9 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
185
221
 
186
222
  return _context2.abrupt("return");
187
223
 
188
- case 12:
224
+ case 13:
189
225
  if (!(fileState.status === 'processed' || fileState.status === 'processing')) {
190
- _context2.next = 29;
226
+ _context2.next = 30;
191
227
  break;
192
228
  }
193
229
 
@@ -195,7 +231,7 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
195
231
  artifacts = fileState.artifacts;
196
232
 
197
233
  if (!(!artifactName || !artifacts)) {
198
- _context2.next = 18;
234
+ _context2.next = 19;
199
235
  break;
200
236
  }
201
237
 
@@ -203,34 +239,34 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
203
239
 
204
240
  return _context2.abrupt("return");
205
241
 
206
- case 18:
207
- _context2.prev = 18;
208
- _context2.next = 21;
242
+ case 19:
243
+ _context2.prev = 19;
244
+ _context2.next = 22;
209
245
  return mediaClient.file.getArtifactURL(artifacts, artifactName, collectionName);
210
246
 
211
- case 21:
247
+ case 22:
212
248
  _fileSrc = _context2.sent;
213
249
 
214
250
  _this2.setFileSrc(_fileSrc);
215
251
 
216
- _context2.next = 29;
252
+ _context2.next = 30;
217
253
  break;
218
254
 
219
- case 25:
220
- _context2.prev = 25;
221
- _context2.t0 = _context2["catch"](18);
255
+ case 26:
256
+ _context2.prev = 26;
257
+ _context2.t0 = _context2["catch"](19);
222
258
  onError = _this2.props.onError;
223
259
 
224
260
  if (onError) {
225
261
  onError(_context2.t0);
226
262
  }
227
263
 
228
- case 29:
264
+ case 30:
229
265
  case "end":
230
266
  return _context2.stop();
231
267
  }
232
268
  }
233
- }, _callee2, null, [[18, 25]]);
269
+ }, _callee2, null, [[19, 26]]);
234
270
  }));
235
271
 
236
272
  function next(_x) {
@@ -247,6 +283,12 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
247
283
  this.unsubscribe();
248
284
  this.revoke();
249
285
  }
286
+ }, {
287
+ key: "breakpoint",
288
+ get: function get() {
289
+ var width = this.state.elementWidth || (this.props.dimensions ? this.props.dimensions.width : '') || defaultImageCardDimensions.width;
290
+ return calcBreakpointSize(parseInt("".concat(width), 10));
291
+ }
250
292
  }, {
251
293
  key: "render",
252
294
  value: function render() {
@@ -259,8 +301,12 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
259
301
  selected = _this$props4.selected,
260
302
  testId = _this$props4.testId,
261
303
  identifier = _this$props4.identifier,
262
- forwardRef = _this$props4.forwardRef;
263
- var fileSrc = this.state.fileSrc;
304
+ forwardRef = _this$props4.forwardRef,
305
+ autoplay = _this$props4.autoplay;
306
+ var _this$state = this.state,
307
+ fileSrc = _this$state.fileSrc,
308
+ isUploading = _this$state.isUploading,
309
+ progress = _this$state.progress;
264
310
 
265
311
  if (!fileSrc) {
266
312
  return /*#__PURE__*/React.createElement(CardLoading, {
@@ -281,7 +327,7 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
281
327
  type: "video",
282
328
  src: fileSrc,
283
329
  fileId: identifier.id,
284
- isAutoPlay: true,
330
+ isAutoPlay: autoplay,
285
331
  isHDAvailable: false,
286
332
  onDownloadClick: _this3.onDownloadClick,
287
333
  onFirstPlay: _this3.onFirstPlay,
@@ -291,7 +337,12 @@ export var InlinePlayerBase = /*#__PURE__*/function (_Component) {
291
337
  originalDimensions: originalDimensions,
292
338
  showControls: checkMouseMovement
293
339
  });
294
- }));
340
+ }), isUploading ? /*#__PURE__*/React.createElement(ProgressBar, {
341
+ progress: progress,
342
+ breakpoint: this.breakpoint,
343
+ positionBottom: true,
344
+ showOnTop: true
345
+ }) : null);
295
346
  }
296
347
  }]);
297
348
 
@@ -10,7 +10,7 @@ export var WarningIconWrapper = styled.div(_templateObject2 || (_templateObject2
10
10
  export var LoadingRateLimitedTextWrapper = styled.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n ", "\n"])), function (_ref) {
11
11
  var breakpoint = _ref.breakpoint,
12
12
  positionBottom = _ref.positionBottom;
13
- return "\n margin-top: 10px;\n overflow: hidden;\n color: ".concat(N300, ";\n display: block;\n width:100%;\n text-align:center;\n ").concat(generateResponsiveStyles(breakpoint, positionBottom, 1), "\n ");
13
+ return "\n margin-top: 10px;\n overflow: hidden;\n color: ".concat(N300, ";\n display: block;\n width:100%;\n text-align:center;\n ").concat(generateResponsiveStyles(breakpoint, positionBottom, false, 1), "\n ");
14
14
  });
15
15
  LoadingRateLimitedTextWrapper.displayName = 'LoadingRateLimitedTextWrapper';
16
16
  export var CouldntLoadWrapper = styled.div(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n font-weight: 550;\n"])));
@@ -6,11 +6,14 @@ export var ProgressBar = function ProgressBar(_ref) {
6
6
  _ref$breakpoint = _ref.breakpoint,
7
7
  breakpoint = _ref$breakpoint === void 0 ? Breakpoint.SMALL : _ref$breakpoint,
8
8
  _ref$positionBottom = _ref.positionBottom,
9
- positionBottom = _ref$positionBottom === void 0 ? false : _ref$positionBottom;
9
+ positionBottom = _ref$positionBottom === void 0 ? false : _ref$positionBottom,
10
+ _ref$showOnTop = _ref.showOnTop,
11
+ showOnTop = _ref$showOnTop === void 0 ? false : _ref$showOnTop;
10
12
  var normalizedProgress = Math.min(1, Math.max(0, progress || 0)) * 100;
11
13
  return /*#__PURE__*/React.createElement(StyledBar, {
12
14
  progress: normalizedProgress,
13
15
  breakpoint: breakpoint,
14
- positionBottom: positionBottom
16
+ positionBottom: positionBottom,
17
+ showOnTop: showOnTop
15
18
  });
16
19
  };
@@ -19,17 +19,18 @@ var smallSizeSettings = {
19
19
  var largeSizeSettings = {
20
20
  marginBottom: 12
21
21
  };
22
- export function generateResponsiveStyles(breakpoint, positionBottom) {
23
- var multiplier = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
22
+ export function generateResponsiveStyles(breakpoint, positionBottom, showOnTop) {
23
+ var multiplier = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
24
24
  var setting = breakpoint === Breakpoint.SMALL ? smallSizeSettings : largeSizeSettings;
25
25
  var marginPositionBottom = responsiveSettings[breakpoint].titleBox.verticalPadding;
26
26
  var marginBottom = setting.marginBottom * multiplier + (positionBottom ? marginPositionBottom : getTitleBoxHeight(breakpoint));
27
- return "\n bottom: ".concat(marginBottom, "px\n ");
27
+ return "\n ".concat(showOnTop ? 'top' : 'bottom', ": ").concat(marginBottom, "px\n ");
28
28
  }
29
29
  export var StyledBar = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", "\n"])), function (_ref) {
30
30
  var progress = _ref.progress,
31
31
  breakpoint = _ref.breakpoint,
32
- positionBottom = _ref.positionBottom;
33
- return "\n ".concat(borderRadius, "\n overflow: hidden;\n position: absolute;\n width: ").concat(width, "%;\n left: ").concat(left, "%;\n background-color: ").concat(rgba(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(N400, ";\n ").concat(borderRadius, "\n display: block;\n }\n\n ").concat(generateResponsiveStyles(breakpoint, positionBottom), "\n");
32
+ positionBottom = _ref.positionBottom,
33
+ showOnTop = _ref.showOnTop;
34
+ return "\n ".concat(borderRadius, "\n overflow: hidden;\n position: absolute;\n width: ").concat(width, "%;\n left: ").concat(left, "%;\n background-color: ").concat(rgba(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(N400, ";\n ").concat(borderRadius, "\n display: block;\n }\n\n ").concat(generateResponsiveStyles(breakpoint, positionBottom, showOnTop), "\n");
34
35
  });
35
36
  StyledBar.displayName = 'StyledProgressBar';
@@ -92,7 +92,7 @@ export var NewFileExperienceWrapper = styled.div(_templateObject || (_templateOb
92
92
  isPlayButtonClickable = _ref6.isPlayButtonClickable,
93
93
  isTickBoxSelectable = _ref6.isTickBoxSelectable,
94
94
  shouldDisplayTooltip = _ref6.shouldDisplayTooltip;
95
- return "\n ".concat(transition(), "\n box-sizing: border-box;\n * {\n box-sizing: border-box;\n }\n position: relative;\n font-family: ").concat(fontFamily(), ";\n ").concat(getWrapperDimensions(dimensions, appearance), "\n ").concat(displayBackground ? "background-color: ".concat(N20, ";") : '', "\n ").concat(borderRadius, "\n ").concat(getCursorStyle(shouldUsePointerCursor), "\n ").concat(getWrapperShadow(disableOverlay, selected), "\n ").concat(generateResponsiveStyles(breakpoint), "\n ").concat(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(blanketClassName, " {\n ").concat(fixedBlanketStyles, "\n }\n\n &:hover .").concat(actionsBarClassName, " {\n ").concat(fixedActionBarStyles, "\n }\n\n /* Tooltip does not support percentage dimensions. We enforce them here */\n ").concat(shouldDisplayTooltip ? "> div { ".concat(getWrapperDimensions(dimensions, appearance), " }") : '', "\n");
95
+ return "\n ".concat(transition(), "\n box-sizing: border-box;\n * {\n box-sizing: border-box;\n }\n position: relative;\n font-family: ").concat(fontFamily(), ";\n ").concat(getWrapperDimensions(dimensions, appearance), "\n ").concat(displayBackground ? "background-color: ".concat(N20, ";") : '', "\n ").concat(borderRadius, "\n ").concat(getCursorStyle(shouldUsePointerCursor), "\n ").concat(getWrapperShadow(disableOverlay, selected), "\n ").concat(generateResponsiveStyles(breakpoint), "\n ").concat(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(blanketClassName, " {\n ").concat(fixedBlanketStyles, "\n }\n\n &:hover .").concat(actionsBarClassName, " {\n ").concat(fixedActionBarStyles, "\n }\n\n /* Tooltip does not support percentage dimensions. We enforce them here */\n ").concat(shouldDisplayTooltip ? "> div { width: 100%; height: 100% }" : '', "\n");
96
96
  });
97
97
  NewFileExperienceWrapper.displayName = 'NewFileExperienceWrapper';
98
98
  export var CardImageContainer = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n position: relative;\n max-width: 100%;\n width: 100%;\n height: 100%;\n max-height: 100%;\n overflow: hidden;\n ", "\n"])), borderRadius);
@@ -5,6 +5,7 @@ import _inherits from "@babel/runtime/helpers/inherits";
5
5
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
6
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
7
  import _extends from "@babel/runtime/helpers/extends";
8
+ var _excluded = ["triggerRef"];
8
9
 
9
10
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
11
 
@@ -85,7 +86,7 @@ export var CardActionsDropdownMenu = /*#__PURE__*/function (_Component) {
85
86
  onOpenChange: onOpenChange,
86
87
  trigger: function trigger(_ref) {
87
88
  var triggerRef = _ref.triggerRef,
88
- providedProps = _objectWithoutProperties(_ref, ["triggerRef"]);
89
+ providedProps = _objectWithoutProperties(_ref, _excluded);
89
90
 
90
91
  return /*#__PURE__*/React.createElement(CardActionButtonWithAnalytics, _extends({
91
92
  variant: triggerVariant,
@@ -4,8 +4,30 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
 
5
5
  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; }
6
6
 
7
- import React, { useEffect } from 'react';
8
- import { LazyContent } from './lazyContent';
7
+ import React, { useEffect, forwardRef } from 'react';
8
+ /**
9
+ * As IntersectionObserver::rootMargin doesn't work within IFrames, we use an empty div + dynamic offsetTop to eagerly detect cards entering viewport.
10
+ * Using this approach, we can lazy load cards ABS_VIEWPORT_ANCHOR_OFFSET_TOP px before they enter viewport.
11
+ */
12
+
13
+ export var ABS_VIEWPORT_ANCHOR_OFFSET_TOP = 900; //px
14
+
15
+ export var ViewportAnchor = /*#__PURE__*/forwardRef(function (props, ref) {
16
+ if (typeof IntersectionObserver === 'undefined') {
17
+ return null;
18
+ }
19
+
20
+ return /*#__PURE__*/React.createElement("div", {
21
+ ref: ref,
22
+ className: "media-card-viewport-anchor",
23
+ style: {
24
+ position: 'absolute',
25
+ top: "".concat(props.offsetTop, "px"),
26
+ maxHeight: 0,
27
+ pointerEvents: 'none'
28
+ }
29
+ });
30
+ });
9
31
 
10
32
  var createIntersectionObserverCallback = function createIntersectionObserverCallback(onVisible) {
11
33
  return function (entries, observer) {
@@ -30,33 +52,40 @@ var createIntersectionObserverCallback = function createIntersectionObserverCall
30
52
  };
31
53
  };
32
54
 
33
- var Observer = function Observer(_ref) {
55
+ var ViewportObserver = function ViewportObserver(_ref) {
34
56
  var onVisible = _ref.onVisible,
57
+ cardEl = _ref.cardEl,
35
58
  children = _ref.children,
36
- targetRef = _ref.targetRef;
59
+ preAnchorRef = _ref.preAnchorRef,
60
+ postAnchorRef = _ref.postAnchorRef;
37
61
  useEffect(function () {
38
62
  // IntersectionObserver uses root and target elements to detect intersections, defaulting root to the viewport
39
63
  var intersectionObserver = new IntersectionObserver(createIntersectionObserverCallback(onVisible));
40
- targetRef && intersectionObserver.observe(targetRef);
64
+ (preAnchorRef === null || preAnchorRef === void 0 ? void 0 : preAnchorRef.current) && intersectionObserver.observe(preAnchorRef.current);
65
+ (postAnchorRef === null || postAnchorRef === void 0 ? void 0 : postAnchorRef.current) && intersectionObserver.observe(postAnchorRef.current);
66
+ cardEl && intersectionObserver.observe(cardEl);
41
67
  return function () {
42
68
  intersectionObserver.disconnect();
43
69
  };
44
- }, [targetRef, onVisible]);
70
+ }, [cardEl, preAnchorRef, postAnchorRef, onVisible]);
45
71
  return /*#__PURE__*/React.createElement(React.Fragment, null, children);
46
72
  };
47
73
 
48
- export var createViewportDetector = function createViewportDetector(isIntersectionObserverSupported) {
49
- return function (_ref2) {
50
- var children = _ref2.children,
51
- targetRef = _ref2.targetRef,
52
- onVisible = _ref2.onVisible;
53
- return isIntersectionObserverSupported ? /*#__PURE__*/React.createElement(Observer, {
54
- targetRef: targetRef,
55
- onVisible: onVisible
56
- }, children) : /*#__PURE__*/React.createElement(LazyContent, {
57
- placeholder: /*#__PURE__*/React.createElement(React.Fragment, null, children),
58
- onRender: onVisible
59
- }, children);
60
- };
61
- };
62
- export var ViewportDetector = createViewportDetector(typeof IntersectionObserver !== 'undefined');
74
+ export var ViewportDetector = function ViewportDetector(_ref2) {
75
+ var cardEl = _ref2.cardEl,
76
+ preAnchorRef = _ref2.preAnchorRef,
77
+ postAnchorRef = _ref2.postAnchorRef,
78
+ onVisible = _ref2.onVisible,
79
+ children = _ref2.children;
80
+
81
+ if (typeof IntersectionObserver === 'undefined') {
82
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
83
+ }
84
+
85
+ return /*#__PURE__*/React.createElement(ViewportObserver, {
86
+ cardEl: cardEl,
87
+ preAnchorRef: preAnchorRef,
88
+ postAnchorRef: postAnchorRef,
89
+ onVisible: onVisible
90
+ }, children);
91
+ };
@@ -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
  }
@@ -53,6 +53,7 @@ export interface CardProps extends SharedCardProps, CardEventProps {
53
53
  export interface CardState {
54
54
  status: CardStatus;
55
55
  isCardVisible: boolean;
56
+ shouldAutoplay?: boolean;
56
57
  isPlayingFile: boolean;
57
58
  mediaViewerSelectedItem?: Identifier;
58
59
  fileState?: FileState;
@@ -7,6 +7,8 @@ import { CardAction, CardProps, CardState } from '../..';
7
7
  export declare type CardBaseProps = CardProps & WithAnalyticsEventsProps & Partial<WrappedComponentProps>;
8
8
  export declare class CardBase extends Component<CardBaseProps, CardState> {
9
9
  private hasBeenMounted;
10
+ private viewportPreAnchorRef;
11
+ private viewportPostAnchorRef;
10
12
  private timeElapsedTillCommenced;
11
13
  subscription?: Subscription;
12
14
  static defaultProps: Partial<CardProps>;
@@ -73,4 +73,4 @@ export declare class CardViewBase extends React.Component<CardViewProps, CardVie
73
73
  private getRenderConfigByStatus;
74
74
  private renderNewExperienceCard;
75
75
  }
76
- export declare const CardView: React.ForwardRefExoticComponent<Pick<Pick<CardViewProps, "progress" | "metadata" | "onClick" | "onMouseEnter" | "innerRef" | "appearance" | "error" | "actions" | "testId" | "selectable" | "selected" | "alt" | "disableOverlay" | "dimensions" | "featureFlags" | "dataURI" | "status" | "mediaItemType" | "resizeMode" | "onDisplayImage" | "previewOrientation" | "onImageError" | "onImageLoad" | "forceSyncDisplay" | "nativeLazyLoad" | "titleBoxBgColor" | "titleBoxIcon" | "disableAnimation" | "originalDimensions">, never> & Partial<Pick<Pick<CardViewProps, "progress" | "metadata" | "onClick" | "onMouseEnter" | "innerRef" | "appearance" | "error" | "actions" | "testId" | "selectable" | "selected" | "alt" | "disableOverlay" | "dimensions" | "featureFlags" | "dataURI" | "status" | "mediaItemType" | "resizeMode" | "onDisplayImage" | "previewOrientation" | "onImageError" | "onImageLoad" | "forceSyncDisplay" | "nativeLazyLoad" | "titleBoxBgColor" | "titleBoxIcon" | "disableAnimation" | "originalDimensions">, "progress" | "metadata" | "onClick" | "onMouseEnter" | "innerRef" | "appearance" | "error" | "actions" | "testId" | "selectable" | "selected" | "alt" | "disableOverlay" | "dimensions" | "featureFlags" | "dataURI" | "status" | "mediaItemType" | "resizeMode" | "onDisplayImage" | "previewOrientation" | "onImageError" | "onImageLoad" | "forceSyncDisplay" | "nativeLazyLoad" | "titleBoxBgColor" | "titleBoxIcon" | "disableAnimation" | "originalDimensions">> & Partial<Pick<Partial<CardViewOwnProps>, never>> & React.RefAttributes<any>>;
76
+ export declare const CardView: React.ForwardRefExoticComponent<Pick<Pick<CardViewProps, "progress" | "metadata" | "onClick" | "onMouseEnter" | "innerRef" | "testId" | "appearance" | "error" | "actions" | "selectable" | "selected" | "alt" | "disableOverlay" | "dimensions" | "featureFlags" | "dataURI" | "status" | "mediaItemType" | "resizeMode" | "onDisplayImage" | "previewOrientation" | "onImageError" | "onImageLoad" | "forceSyncDisplay" | "nativeLazyLoad" | "titleBoxBgColor" | "titleBoxIcon" | "disableAnimation" | "originalDimensions">, never> & Partial<Pick<Pick<CardViewProps, "progress" | "metadata" | "onClick" | "onMouseEnter" | "innerRef" | "testId" | "appearance" | "error" | "actions" | "selectable" | "selected" | "alt" | "disableOverlay" | "dimensions" | "featureFlags" | "dataURI" | "status" | "mediaItemType" | "resizeMode" | "onDisplayImage" | "previewOrientation" | "onImageError" | "onImageLoad" | "forceSyncDisplay" | "nativeLazyLoad" | "titleBoxBgColor" | "titleBoxIcon" | "disableAnimation" | "originalDimensions">, "progress" | "metadata" | "onClick" | "onMouseEnter" | "innerRef" | "testId" | "appearance" | "error" | "actions" | "selectable" | "selected" | "alt" | "disableOverlay" | "dimensions" | "featureFlags" | "dataURI" | "status" | "mediaItemType" | "resizeMode" | "onDisplayImage" | "previewOrientation" | "onImageError" | "onImageLoad" | "forceSyncDisplay" | "nativeLazyLoad" | "titleBoxBgColor" | "titleBoxIcon" | "disableAnimation" | "originalDimensions">> & Partial<Pick<Partial<CardViewOwnProps>, never>> & React.RefAttributes<any>>;
@@ -16,8 +16,10 @@ export default class MediaInlineCardLoader extends React.PureComponent<MediaInli
16
16
  static displayName: string;
17
17
  static MediaInlineCard?: MediaInlineCardWithMediaClientConfigComponent;
18
18
  static ErrorBoundary?: ErrorBoundaryComponent;
19
+ isMounted: boolean;
19
20
  state: MediaInlineCardLoaderState;
20
21
  componentDidMount(): Promise<void>;
22
+ componentWillUnmount(): Promise<void>;
21
23
  render(): JSX.Element;
22
24
  }
23
25
  export {};
@@ -10,6 +10,7 @@ export interface InlinePlayerOwnProps {
10
10
  mediaClient: MediaClient;
11
11
  dimensions?: CardDimensions;
12
12
  originalDimensions?: NumericalCardDimensions;
13
+ autoplay: boolean;
13
14
  selected?: boolean;
14
15
  onError?: (error: Error) => void;
15
16
  readonly onClick?: (event: React.MouseEvent<HTMLDivElement>, analyticsEvent?: UIAnalyticsEvent) => void;
@@ -19,11 +20,15 @@ export interface InlinePlayerOwnProps {
19
20
  export declare type InlinePlayerProps = InlinePlayerOwnProps & WithAnalyticsEventsProps;
20
21
  export interface InlinePlayerState {
21
22
  fileSrc?: string;
23
+ isUploading?: boolean;
24
+ progress?: number;
25
+ elementWidth?: number;
22
26
  }
23
27
  export declare const getPreferredVideoArtifact: (fileState: FileState) => keyof MediaFileArtifacts | undefined;
24
28
  export declare class InlinePlayerBase extends Component<InlinePlayerProps, InlinePlayerState> {
25
29
  subscription?: Subscription;
26
30
  state: InlinePlayerState;
31
+ divRef: React.RefObject<HTMLDivElement>;
27
32
  static defaultProps: {
28
33
  dimensions: {
29
34
  width: number;
@@ -38,6 +43,8 @@ export declare class InlinePlayerBase extends Component<InlinePlayerProps, Inlin
38
43
  componentWillUnmount(): void;
39
44
  onDownloadClick: () => void;
40
45
  onFirstPlay: () => void;
46
+ private get breakpoint();
47
+ saveElementWidth: () => void;
41
48
  render(): JSX.Element;
42
49
  }
43
- export declare const InlinePlayer: React.ForwardRefExoticComponent<Pick<InlinePlayerProps, "onError" | "onClick" | "createAnalyticsEvent" | "testId" | "selected" | "dimensions" | "originalDimensions" | "mediaClient" | "identifier" | "forwardRef"> & React.RefAttributes<HTMLDivElement>>;
50
+ export declare const InlinePlayer: React.ForwardRefExoticComponent<Pick<InlinePlayerProps, "onError" | "onClick" | "testId" | "createAnalyticsEvent" | "selected" | "dimensions" | "originalDimensions" | "mediaClient" | "identifier" | "autoplay" | "forwardRef"> & React.RefAttributes<HTMLDivElement>>;
@@ -4,5 +4,6 @@ export declare type ProgressBarProps = {
4
4
  progress?: number;
5
5
  breakpoint?: Breakpoint;
6
6
  positionBottom?: boolean;
7
+ showOnTop?: boolean;
7
8
  };
8
- export declare const ProgressBar: ({ progress, breakpoint, positionBottom, }: ProgressBarProps) => JSX.Element;
9
+ export declare const ProgressBar: ({ progress, breakpoint, positionBottom, showOnTop, }: ProgressBarProps) => JSX.Element;
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { Breakpoint } from '../common';
3
- export declare function generateResponsiveStyles(breakpoint: Breakpoint, positionBottom: boolean, multiplier?: number): string;
3
+ export declare function generateResponsiveStyles(breakpoint: Breakpoint, positionBottom: boolean, showOnTop: boolean, multiplier?: number): string;
4
4
  export declare type StyledBarProps = {
5
5
  progress: number;
6
6
  breakpoint: Breakpoint;
7
7
  positionBottom: boolean;
8
+ showOnTop: boolean;
8
9
  };
9
10
  export declare const StyledBar: import("styled-components").StyledComponentClass<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & StyledBarProps, any, import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & StyledBarProps>;
@@ -1,8 +1,16 @@
1
- import React, { FC } from 'react';
2
- declare type ViewportDetectorProps = {
3
- targetRef: HTMLElement | null;
1
+ import React from 'react';
2
+ /**
3
+ * As IntersectionObserver::rootMargin doesn't work within IFrames, we use an empty div + dynamic offsetTop to eagerly detect cards entering viewport.
4
+ * Using this approach, we can lazy load cards ABS_VIEWPORT_ANCHOR_OFFSET_TOP px before they enter viewport.
5
+ */
6
+ export declare const ABS_VIEWPORT_ANCHOR_OFFSET_TOP = 900;
7
+ export declare const ViewportAnchor: React.ForwardRefExoticComponent<{
8
+ offsetTop: number;
9
+ } & React.RefAttributes<HTMLDivElement>>;
10
+ export declare type ViewportDetectorProps = {
11
+ cardEl: HTMLElement | null;
12
+ preAnchorRef: React.RefObject<HTMLDivElement>;
13
+ postAnchorRef: React.RefObject<HTMLDivElement>;
4
14
  onVisible: () => void;
5
15
  };
6
- export declare const createViewportDetector: (isIntersectionObserverSupported: boolean) => React.FC<ViewportDetectorProps>;
7
16
  export declare const ViewportDetector: React.FC<ViewportDetectorProps>;
8
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-card",
3
- "version": "73.0.0",
3
+ "version": "73.1.2",
4
4
  "description": "Includes all media card related components, CardView, CardViewSmall, Card...",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -31,20 +31,19 @@
31
31
  "@atlaskit/analytics-next": "^8.2.0",
32
32
  "@atlaskit/dropdown-menu": "^11.0.0",
33
33
  "@atlaskit/editor-shared-styles": "^1.6.0",
34
- "@atlaskit/icon": "^21.9.0",
34
+ "@atlaskit/icon": "^21.10.0",
35
35
  "@atlaskit/in-product-testing": "^0.1.0",
36
36
  "@atlaskit/media-client": "^14.3.0",
37
37
  "@atlaskit/media-common": "^2.10.0",
38
- "@atlaskit/media-ui": "^18.0.0",
38
+ "@atlaskit/media-ui": "^18.1.0",
39
39
  "@atlaskit/media-viewer": "^46.0.0",
40
40
  "@atlaskit/spinner": "^15.1.0",
41
- "@atlaskit/theme": "^12.0.0",
41
+ "@atlaskit/theme": "^12.1.0",
42
42
  "@atlaskit/tooltip": "^17.5.0",
43
43
  "@babel/runtime": "^7.0.0",
44
44
  "classnames": "^2.2.5",
45
45
  "eventemitter2": "^4.1.0",
46
46
  "lru-fast": "^0.2.2",
47
- "react-lazily-render": "^1.2.0",
48
47
  "react-loadable": "^5.1.0",
49
48
  "video-snapshot": "^1.0.11"
50
49
  },
@@ -56,9 +55,8 @@
56
55
  "styled-components": "^3.2.6"
57
56
  },
58
57
  "devDependencies": {
59
- "@atlaskit/analytics-listeners": "^8.0.0",
60
- "@atlaskit/analytics-namespaced-context": "^6.3.0",
61
- "@atlaskit/build-utils": "*",
58
+ "@atlaskit/analytics-listeners": "^8.2.0",
59
+ "@atlaskit/analytics-namespaced-context": "^6.4.0",
62
60
  "@atlaskit/button": "^16.1.0",
63
61
  "@atlaskit/checkbox": "^12.3.0",
64
62
  "@atlaskit/docs": "*",
@@ -71,7 +69,7 @@
71
69
  "@atlaskit/select": "^15.2.1",
72
70
  "@atlaskit/ssr": "*",
73
71
  "@atlaskit/textfield": "^5.1.0",
74
- "@atlaskit/toggle": "^12.3.0",
72
+ "@atlaskit/toggle": "^12.4.0",
75
73
  "@atlaskit/visual-regression": "*",
76
74
  "@atlaskit/webdriver-runner": "*",
77
75
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
@@ -1,56 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.LazyContent = void 0;
9
-
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
-
16
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
17
-
18
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
19
-
20
- var _react = _interopRequireDefault(require("react"));
21
-
22
- var _styled = require("./styled");
23
-
24
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
25
-
26
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
27
-
28
- var LazyContent = /*#__PURE__*/function (_React$Component) {
29
- (0, _inherits2.default)(LazyContent, _React$Component);
30
-
31
- var _super = _createSuper(LazyContent);
32
-
33
- function LazyContent() {
34
- (0, _classCallCheck2.default)(this, LazyContent);
35
- return _super.apply(this, arguments);
36
- }
37
-
38
- (0, _createClass2.default)(LazyContent, [{
39
- key: "render",
40
- value: function render() {
41
- var _this$props = this.props,
42
- children = _this$props.children,
43
- placeholder = _this$props.placeholder,
44
- onRender = _this$props.onRender;
45
- return /*#__PURE__*/_react.default.createElement(_styled.Wrapper, {
46
- offset: 300,
47
- onRender: onRender,
48
- placeholder: placeholder,
49
- content: children
50
- });
51
- }
52
- }]);
53
- return LazyContent;
54
- }(_react.default.Component);
55
-
56
- exports.LazyContent = LazyContent;