@atlaskit/media-card 77.1.1 → 77.2.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 (51) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/card/card.js +17 -13
  3. package/dist/cjs/card/cardState.js +1 -1
  4. package/dist/cjs/card/getCardPreview/index.js +2 -5
  5. package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
  6. package/dist/cjs/card/useBreakpoint.js +29 -0
  7. package/dist/cjs/card/v2/cardV2.js +22 -20
  8. package/dist/cjs/card/v2/cardViewV2.js +5 -22
  9. package/dist/cjs/card/v2/inlinePlayerLazyV2.js +35 -0
  10. package/dist/cjs/card/v2/inlinePlayerV2.js +222 -0
  11. package/dist/cjs/inline/loader.js +1 -1
  12. package/dist/cjs/utils/ufoExperiences.js +18 -14
  13. package/dist/es2019/card/card.js +18 -16
  14. package/dist/es2019/card/cardState.js +1 -1
  15. package/dist/es2019/card/getCardPreview/index.js +0 -5
  16. package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
  17. package/dist/es2019/card/useBreakpoint.js +22 -0
  18. package/dist/es2019/card/v2/cardV2.js +23 -23
  19. package/dist/es2019/card/v2/cardViewV2.js +4 -18
  20. package/dist/es2019/card/v2/inlinePlayerLazyV2.js +10 -0
  21. package/dist/es2019/card/v2/inlinePlayerV2.js +164 -0
  22. package/dist/es2019/inline/loader.js +1 -1
  23. package/dist/es2019/utils/ufoExperiences.js +18 -9
  24. package/dist/esm/card/card.js +18 -14
  25. package/dist/esm/card/cardState.js +1 -1
  26. package/dist/esm/card/getCardPreview/index.js +2 -5
  27. package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
  28. package/dist/esm/card/useBreakpoint.js +24 -0
  29. package/dist/esm/card/v2/cardV2.js +23 -21
  30. package/dist/esm/card/v2/cardViewV2.js +7 -24
  31. package/dist/esm/card/v2/inlinePlayerLazyV2.js +23 -0
  32. package/dist/esm/card/v2/inlinePlayerV2.js +212 -0
  33. package/dist/esm/inline/loader.js +1 -1
  34. package/dist/esm/utils/ufoExperiences.js +17 -13
  35. package/dist/types/card/card.d.ts +1 -0
  36. package/dist/types/card/cardState.d.ts +1 -2
  37. package/dist/types/card/getCardPreview/index.d.ts +4 -10
  38. package/dist/types/card/useBreakpoint.d.ts +3 -0
  39. package/dist/types/card/v2/cardV2.d.ts +3 -2
  40. package/dist/types/card/v2/inlinePlayerLazyV2.d.ts +2 -0
  41. package/dist/types/card/v2/inlinePlayerV2.d.ts +23 -0
  42. package/dist/types/utils/ufoExperiences.d.ts +7 -0
  43. package/dist/types-ts4.5/card/card.d.ts +1 -0
  44. package/dist/types-ts4.5/card/cardState.d.ts +1 -2
  45. package/dist/types-ts4.5/card/getCardPreview/index.d.ts +4 -10
  46. package/dist/types-ts4.5/card/useBreakpoint.d.ts +3 -0
  47. package/dist/types-ts4.5/card/v2/cardV2.d.ts +3 -2
  48. package/dist/types-ts4.5/card/v2/inlinePlayerLazyV2.d.ts +2 -0
  49. package/dist/types-ts4.5/card/v2/inlinePlayerV2.d.ts +23 -0
  50. package/dist/types-ts4.5/utils/ufoExperiences.d.ts +7 -0
  51. package/package.json +5 -4
@@ -119,7 +119,7 @@ var MediaInlineCardLoader = exports.default = /*#__PURE__*/function (_React$Pure
119
119
  ErrorBoundary = _this$state.ErrorBoundary;
120
120
  var analyticsContext = {
121
121
  packageVersion: "@atlaskit/media-card",
122
- packageName: "77.1.1",
122
+ packageName: "77.2.0",
123
123
  componentName: 'mediaInlineCard',
124
124
  component: 'mediaInlineCard'
125
125
  };
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.startUfoExperience = exports.completeUfoExperience = void 0;
7
+ exports.startUfoExperience = exports.completeUfoExperience = exports.abortUfoExperience = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _ufo = require("@atlaskit/ufo");
10
10
  var _mediaCommon = require("@atlaskit/media-common");
@@ -14,7 +14,7 @@ var _mediaClient = require("@atlaskit/media-client");
14
14
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
15
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
16
  var packageName = "@atlaskit/media-card";
17
- var packageVersion = "77.1.1";
17
+ var packageVersion = "77.2.0";
18
18
  var concurrentExperience;
19
19
  var getExperience = function getExperience(id) {
20
20
  if (!concurrentExperience) {
@@ -62,23 +62,27 @@ var completeUfoExperience = exports.completeUfoExperience = function completeUfo
62
62
  break;
63
63
  }
64
64
  };
65
+ var getBasePayloadAttributes = function getBasePayloadAttributes() {
66
+ return {
67
+ packageName: packageName,
68
+ packageVersion: packageVersion,
69
+ mediaEnvironment: (0, _mediaClient.getMediaEnvironment)(),
70
+ mediaRegion: (0, _mediaClient.getMediaRegion)()
71
+ };
72
+ };
65
73
  var succeedUfoExperience = function succeedUfoExperience(id, properties) {
66
74
  getExperience(id).success({
67
- metadata: _objectSpread(_objectSpread({}, properties), {}, {
68
- packageName: packageName,
69
- packageVersion: packageVersion,
70
- mediaEnvironment: (0, _mediaClient.getMediaEnvironment)(),
71
- mediaRegion: (0, _mediaClient.getMediaRegion)()
72
- })
75
+ metadata: _objectSpread(_objectSpread({}, properties), getBasePayloadAttributes())
73
76
  });
74
77
  };
75
78
  var failUfoExperience = function failUfoExperience(id, properties) {
76
79
  getExperience(id).failure({
77
- metadata: _objectSpread(_objectSpread({}, properties), {}, {
78
- packageName: packageName,
79
- packageVersion: packageVersion,
80
- mediaEnvironment: (0, _mediaClient.getMediaEnvironment)(),
81
- mediaRegion: (0, _mediaClient.getMediaRegion)()
82
- })
80
+ metadata: _objectSpread(_objectSpread({}, properties), getBasePayloadAttributes())
81
+ });
82
+ };
83
+ var abortUfoExperience = exports.abortUfoExperience = function abortUfoExperience(id, properties) {
84
+ // UFO won't abort if it's already in a final state (succeeded, failed, aborted, etc)
85
+ getExperience(id).abort({
86
+ metadata: _objectSpread(_objectSpread({}, properties), getBasePayloadAttributes())
83
87
  });
84
88
  };
@@ -24,10 +24,10 @@ import { StoreSSRDataScript, getSSRData } from '../utils/globalScope';
24
24
  import { getCardStateFromFileState, createStateUpdater } from './cardState';
25
25
  import { isBigger } from '../utils/dimensionComparer';
26
26
  import { getMediaCardCursor } from '../utils/getMediaCardCursor';
27
- import { completeUfoExperience, startUfoExperience } from '../utils/ufoExperiences';
27
+ import { completeUfoExperience, startUfoExperience, abortUfoExperience } from '../utils/ufoExperiences';
28
28
  import { generateUniqueId } from '../utils/generateUniqueId';
29
29
  const packageName = "@atlaskit/media-card";
30
- const packageVersion = "77.1.1";
30
+ const packageVersion = "77.2.0";
31
31
  export class CardBase extends Component {
32
32
  constructor(props) {
33
33
  super(props);
@@ -97,8 +97,7 @@ export class CardBase extends Component {
97
97
  } = identifier;
98
98
  const {
99
99
  dimensions = {},
100
- mediaClient,
101
- createAnalyticsEvent
100
+ mediaClient
102
101
  } = this.props;
103
102
  return {
104
103
  mediaClient,
@@ -109,8 +108,6 @@ export class CardBase extends Component {
109
108
  isRemotePreviewReady: isImageRepresentationReady(fileState),
110
109
  imageUrlParams: this.getImageURLParams(identifier),
111
110
  mediaBlobUrlAttrs: this.getMediaBlobUrlAttrs(identifier, fileState),
112
- createAnalyticsEvent,
113
- featureFlags: this.props.featureFlags,
114
111
  traceContext: this.traceContext
115
112
  };
116
113
  });
@@ -743,10 +740,8 @@ export class CardBase extends Component {
743
740
  mediaClient,
744
741
  identifier,
745
742
  dimensions,
746
- featureFlags,
747
743
  useInlinePlayer,
748
744
  disableOverlay,
749
- resizeMode,
750
745
  ssr
751
746
  } = this.props;
752
747
  const {
@@ -775,7 +770,6 @@ export class CardBase extends Component {
775
770
  const turnedVisible = !prevIsCardVisible && isCardVisible;
776
771
  const hadSSRCardPreview = !!prevCardPreview && isSSRClientPreview(prevCardPreview) && !cardPreview;
777
772
  const isNewMediaClient = prevMediaClient !== mediaClient;
778
- const fileImageMode = imageResizeModeToFileImageMode(resizeMode);
779
773
  this.updateFileStateFlag(fileState);
780
774
  if (isExternalImageIdentifier(identifier) && isDiffIdentifier) {
781
775
  this.fireCommencedEvent();
@@ -816,9 +810,6 @@ export class CardBase extends Component {
816
810
  fileState,
817
811
  prevDimensions,
818
812
  dimensions,
819
- identifier,
820
- fileImageMode,
821
- featureFlags,
822
813
  hasCardPreview: !!cardPreview,
823
814
  isBannedLocalPreview,
824
815
  wasResolvedUpfrontPreview
@@ -851,6 +842,7 @@ export class CardBase extends Component {
851
842
  }
852
843
  componentWillUnmount() {
853
844
  var _getDocument2;
845
+ this.fireAbortedEvent();
854
846
  this.hasBeenMounted = false;
855
847
  this.unsubscribe();
856
848
  (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.removeEventListener('copy', this.fireCopiedEvent);
@@ -890,10 +882,7 @@ export class CardBase extends Component {
890
882
  occurrenceKey
891
883
  }).subscribe({
892
884
  next: fileState => {
893
- const {
894
- featureFlags
895
- } = this.props;
896
- const newState = getCardStateFromFileState(fileState, isBannedLocalPreview, featureFlags);
885
+ const newState = getCardStateFromFileState(fileState, isBannedLocalPreview);
897
886
  this.safeSetState(newState);
898
887
  },
899
888
  error: e => {
@@ -938,6 +927,19 @@ export class CardBase extends Component {
938
927
  createAnalyticsEvent && fireOperationalEvent(createAnalyticsEvent, status, this.fileAttributes, this.getPerformanceAttributes(), this.ssrReliability, error, this.traceContext, fileState === null || fileState === void 0 ? void 0 : fileState.metadataTraceContext);
939
928
  completeUfoExperience(this.internalOccurrenceKey, status, this.fileAttributes, this.fileStateFlags, this.ssrReliability, error);
940
929
  }
930
+ fireAbortedEvent() {
931
+ const {
932
+ fileAttributes,
933
+ fileStateFlags,
934
+ ssrReliability
935
+ } = this;
936
+ // UFO won't abort if it's already in a final state (succeeded, failed, aborted, etc)
937
+ abortUfoExperience(this.internalOccurrenceKey, {
938
+ fileAttributes,
939
+ fileStateFlags,
940
+ ssrReliability
941
+ });
942
+ }
941
943
  fireCommencedEvent() {
942
944
  this.timeElapsedTillCommenced = performance.now();
943
945
  const {
@@ -17,7 +17,7 @@ export const createStateUpdater = (newState, fireErrorEvent) => prevState => {
17
17
  }
18
18
  return newState;
19
19
  };
20
- export const getCardStateFromFileState = (fileState, isBannedLocalPreview, featureFlags) => {
20
+ export const getCardStateFromFileState = (fileState, isBannedLocalPreview) => {
21
21
  const status = getCardStatus(fileState.status, extractFilePreviewStatus(fileState, isBannedLocalPreview));
22
22
  const error = status === 'error' && isErrorFileState(fileState) ? new MediaCardError('error-file-state', new Error(fileState.message)) : undefined;
23
23
  const progress = status === 'uploading' && fileState.status === 'uploading' ? fileState.progress : 1;
@@ -66,8 +66,6 @@ export const getCardPreview = async ({
66
66
  isRemotePreviewReady,
67
67
  imageUrlParams,
68
68
  mediaBlobUrlAttrs,
69
- createAnalyticsEvent,
70
- featureFlags,
71
69
  traceContext
72
70
  }) => {
73
71
  const mode = imageUrlParams.mode;
@@ -123,11 +121,8 @@ export const shouldResolvePreview = ({
123
121
  fileState,
124
122
  prevDimensions,
125
123
  dimensions,
126
- identifier,
127
- fileImageMode,
128
124
  hasCardPreview,
129
125
  isBannedLocalPreview,
130
- featureFlags,
131
126
  wasResolvedUpfrontPreview
132
127
  }) => {
133
128
  const statusIsPreviewable = isPreviewableStatus(status, extractFilePreviewStatus(fileState, isBannedLocalPreview));
@@ -66,7 +66,7 @@ class WrappedMediaCardAnalyticsErrorBoundary extends React.Component {
66
66
  }
67
67
  _defineProperty(WrappedMediaCardAnalyticsErrorBoundary, "displayName", 'MediaCardAnalyticsErrorBoundary');
68
68
  const packageName = "@atlaskit/media-card";
69
- const packageVersion = "77.1.1";
69
+ const packageVersion = "77.2.0";
70
70
  const MediaCardAnalyticsErrorBoundary = withMediaAnalyticsContext({
71
71
  packageVersion,
72
72
  packageName,
@@ -0,0 +1,22 @@
1
+ import { useMemo } from 'react';
2
+ import { calcBreakpointSize } from './ui/styles';
3
+ import { getElementDimension, isValidPercentageUnit, defaultImageCardDimensions } from '../utils';
4
+
5
+ // Hook to calculate the breakpoint based on the width of the element
6
+ export const useBreakpoint = (dimensionWidth = 0, divRef) => {
7
+ const breakpoint = useMemo(() => {
8
+ let widthToCalculate;
9
+ if (dimensionWidth) {
10
+ if (isValidPercentageUnit(dimensionWidth) && divRef.current) {
11
+ const width = getElementDimension(divRef.current, 'width');
12
+ widthToCalculate = width || defaultImageCardDimensions.width;
13
+ } else {
14
+ widthToCalculate = dimensionWidth;
15
+ }
16
+ } else {
17
+ widthToCalculate = defaultImageCardDimensions.width;
18
+ }
19
+ return calcBreakpointSize(parseInt(`${widthToCalculate}`, 10));
20
+ }, [dimensionWidth, divRef]);
21
+ return breakpoint;
22
+ };
@@ -15,7 +15,7 @@ import { videoIsPlayable } from '../../utils/videoIsPlayable';
15
15
  import { getRequestedDimensions } from '../../utils/getDataURIDimension';
16
16
  import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, isSSRDataPreview, fetchAndCacheRemotePreview } from '../getCardPreview';
17
17
  import { getFileDetails } from '../../utils/metadata';
18
- import { InlinePlayerLazy } from '../inlinePlayerLazy';
18
+ import { InlinePlayerLazyV2 } from './inlinePlayerLazyV2';
19
19
  import { getFileAttributes, extractErrorInfo } from '../../utils/analytics';
20
20
  import { isLocalPreviewError, MediaCardError, MediaFileStateError, ensureMediaCardError, ImageLoadError } from '../../errors';
21
21
  import { fireOperationalEvent, fireCommencedEvent, fireCopiedEvent, fireScreenEvent, fireNonCriticalErrorEvent } from '../cardAnalytics';
@@ -24,11 +24,11 @@ import { StoreSSRDataScript, getSSRData } from '../../utils/globalScope';
24
24
  import { getCardStateFromFileState, createStateUpdater } from '../cardState';
25
25
  import { isBigger } from '../../utils/dimensionComparer';
26
26
  import { getMediaCardCursor } from '../../utils/getMediaCardCursor';
27
- import { completeUfoExperience, startUfoExperience } from '../../utils/ufoExperiences';
27
+ import { completeUfoExperience, startUfoExperience, abortUfoExperience } from '../../utils/ufoExperiences';
28
28
  import { generateUniqueId } from '../../utils/generateUniqueId';
29
29
  import { useFileState } from '@atlaskit/media-client-react';
30
30
  const packageName = "@atlaskit/media-card";
31
- const packageVersion = "77.1.1";
31
+ const packageVersion = "77.2.0";
32
32
  export class CardV2Base extends Component {
33
33
  constructor(props) {
34
34
  super(props);
@@ -98,8 +98,7 @@ export class CardV2Base extends Component {
98
98
  } = identifier;
99
99
  const {
100
100
  dimensions = {},
101
- mediaClient,
102
- createAnalyticsEvent
101
+ mediaClient
103
102
  } = this.props;
104
103
  return {
105
104
  mediaClient,
@@ -110,8 +109,6 @@ export class CardV2Base extends Component {
110
109
  isRemotePreviewReady: isImageRepresentationReady(fileState),
111
110
  imageUrlParams: this.getImageURLParams(identifier),
112
111
  mediaBlobUrlAttrs: this.getMediaBlobUrlAttrs(identifier, fileState),
113
- createAnalyticsEvent,
114
- featureFlags: this.props.featureFlags,
115
112
  traceContext: this.traceContext
116
113
  };
117
114
  });
@@ -203,10 +200,7 @@ export class CardV2Base extends Component {
203
200
  isBannedLocalPreview
204
201
  } = this.state;
205
202
  if (fileState.status !== 'error') {
206
- const {
207
- featureFlags
208
- } = this.props;
209
- const newState = getCardStateFromFileState(fileState, isBannedLocalPreview, featureFlags);
203
+ const newState = getCardStateFromFileState(fileState, isBannedLocalPreview);
210
204
  this.safeSetState(newState);
211
205
  } else {
212
206
  const e = new MediaFileStateError(fileState.id, fileState.reason, fileState.message, fileState.details);
@@ -409,7 +403,6 @@ export class CardV2Base extends Component {
409
403
  _defineProperty(this, "renderInlinePlayer", () => {
410
404
  const {
411
405
  identifier,
412
- mediaClient,
413
406
  dimensions,
414
407
  selected,
415
408
  testId,
@@ -423,8 +416,7 @@ export class CardV2Base extends Component {
423
416
  const card = this.renderCard(false, 'loading', false);
424
417
  return /*#__PURE__*/React.createElement(Suspense, {
425
418
  fallback: card
426
- }, /*#__PURE__*/React.createElement(InlinePlayerLazy, {
427
- mediaClient: mediaClient,
419
+ }, /*#__PURE__*/React.createElement(InlinePlayerLazyV2, {
428
420
  dimensions: dimensions,
429
421
  originalDimensions: originalDimensions,
430
422
  identifier: identifier,
@@ -713,7 +705,7 @@ export class CardV2Base extends Component {
713
705
  dimensions
714
706
  } = this.props;
715
707
  if (isCardVisible && isFileIdentifier(identifier)) {
716
- this.updateStateForIdentifier(identifier);
708
+ this.updateStateForIdentifier();
717
709
  if (!cardPreview) {
718
710
  this.resolveUpfrontPreview(identifier);
719
711
  }
@@ -752,10 +744,8 @@ export class CardV2Base extends Component {
752
744
  mediaClient,
753
745
  identifier,
754
746
  dimensions,
755
- featureFlags,
756
747
  useInlinePlayer,
757
748
  disableOverlay,
758
- resizeMode,
759
749
  ssr
760
750
  } = this.props;
761
751
  const {
@@ -784,7 +774,6 @@ export class CardV2Base extends Component {
784
774
  const turnedVisible = !prevIsCardVisible && isCardVisible;
785
775
  const hadSSRCardPreview = !!prevCardPreview && isSSRClientPreview(prevCardPreview) && !cardPreview;
786
776
  const isNewMediaClient = prevMediaClient !== mediaClient;
787
- const fileImageMode = imageResizeModeToFileImageMode(resizeMode);
788
777
  this.updateFileStateFlag(fileState);
789
778
  if (isExternalImageIdentifier(identifier) && isDiffIdentifier) {
790
779
  this.fireCommencedEvent();
@@ -807,7 +796,7 @@ export class CardV2Base extends Component {
807
796
  this.refetchSSRPreview(identifier);
808
797
  }
809
798
  if (isFileIdentifier(identifier) && (turnedVisible || !!this.subscription && (isNewMediaClient || isDiffIdentifier))) {
810
- this.updateStateForIdentifier(identifier);
799
+ this.updateStateForIdentifier();
811
800
  }
812
801
  if (this.state.status !== prevState.status) {
813
802
  this.fireOperationalEvent();
@@ -825,9 +814,6 @@ export class CardV2Base extends Component {
825
814
  fileState,
826
815
  prevDimensions,
827
816
  dimensions,
828
- identifier,
829
- fileImageMode,
830
- featureFlags,
831
817
  hasCardPreview: !!cardPreview,
832
818
  isBannedLocalPreview,
833
819
  wasResolvedUpfrontPreview
@@ -866,10 +852,11 @@ export class CardV2Base extends Component {
866
852
  }
867
853
  componentWillUnmount() {
868
854
  var _getDocument2;
855
+ this.fireAbortedEvent();
869
856
  this.hasBeenMounted = false;
870
857
  (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.removeEventListener('copy', this.fireCopiedEvent);
871
858
  }
872
- updateStateForIdentifier(identifier) {
859
+ updateStateForIdentifier() {
873
860
  this.fireCommencedEvent();
874
861
  this.setState({
875
862
  shouldUpdateStateForIdentifier: true
@@ -932,6 +919,19 @@ export class CardV2Base extends Component {
932
919
  }, this.traceContext);
933
920
  startUfoExperience(this.internalOccurrenceKey);
934
921
  }
922
+ fireAbortedEvent() {
923
+ const {
924
+ fileAttributes,
925
+ fileStateFlags,
926
+ ssrReliability
927
+ } = this;
928
+ // UFO won't abort if it's already in a final state (succeeded, failed, aborted, etc)
929
+ abortUfoExperience(this.internalOccurrenceKey, {
930
+ fileAttributes,
931
+ fileStateFlags,
932
+ ssrReliability
933
+ });
934
+ }
935
935
  get actions() {
936
936
  const {
937
937
  actions = [],
@@ -1,17 +1,14 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
- import React, { useEffect, useState, useRef, useMemo } from 'react';
3
+ import React, { useEffect, useState, useRef } from 'react';
4
4
  import { withAnalyticsEvents } from '@atlaskit/analytics-next';
5
5
  import { MimeTypeIcon } from '@atlaskit/media-ui/mime-type-icon';
6
6
  import SpinnerIcon from '@atlaskit/spinner';
7
7
  import Tooltip from '@atlaskit/tooltip';
8
8
  import { messages } from '@atlaskit/media-ui';
9
- import { defaultImageCardDimensions } from '../../utils/cardDimensions';
10
- import { isValidPercentageUnit } from '../../utils/isValidPercentageUnit';
11
- import { getElementDimension } from '../../utils/getElementDimension';
12
9
  import { createAndFireMediaCardEvent } from '../../utils/analytics';
13
10
  import { attachDetailsToActions } from '../actions';
14
- import { cardImageContainerStyles, calcBreakpointSize } from '../ui/styles';
11
+ import { cardImageContainerStyles } from '../ui/styles';
15
12
  import { ImageRenderer } from '../ui/imageRenderer/imageRenderer';
16
13
  import { TitleBox } from '../ui/titleBox/titleBox';
17
14
  import { FailedTitleBox } from '../ui/titleBox/failedTitleBox';
@@ -25,6 +22,7 @@ import { PreviewUnavailable, CreatingPreview, FailedToUpload, PreviewCurrentlyUn
25
22
  import { isUploadError, isRateLimitedError, isPollingError } from '../../errors';
26
23
  import { Wrapper } from '../ui/wrapper';
27
24
  import { fileCardImageViewSelector } from '../classnames';
25
+ import { useBreakpoint } from '../useBreakpoint';
28
26
  export const CardViewV2Base = ({
29
27
  innerRef,
30
28
  onImageLoad,
@@ -54,18 +52,10 @@ export const CardViewV2Base = ({
54
52
  error,
55
53
  disableAnimation
56
54
  }) => {
57
- const [elementWidth, setElementWidth] = useState();
58
55
  const [didImageRender, setDidImageRender] = useState(false);
59
56
  const divRef = useRef(null);
60
57
  const prevCardPreviewRef = useRef();
61
- const width = (dimensions === null || dimensions === void 0 ? void 0 : dimensions.width) || 0;
62
- useEffect(() => {
63
- // If the dimensions.width is a percentage, we need to transform it into a pixel value in order to get the right breakpoints applied.
64
- if (width && isValidPercentageUnit(width) && !!divRef.current) {
65
- const elementWidth = getElementDimension(divRef.current, 'width');
66
- setElementWidth(elementWidth);
67
- }
68
- }, [width]);
58
+ const breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
69
59
  useEffect(() => {
70
60
  innerRef && !!divRef.current && innerRef(divRef.current);
71
61
  }, [innerRef]);
@@ -95,10 +85,6 @@ export const CardViewV2Base = ({
95
85
  setDidImageRender(false);
96
86
  onImageError === null || onImageError === void 0 ? void 0 : onImageError(cardPreview);
97
87
  };
98
- const breakpoint = useMemo(() => {
99
- const width = elementWidth || (dimensions ? dimensions.width : '') || defaultImageCardDimensions.width;
100
- return calcBreakpointSize(parseInt(`${width}`, 10));
101
- }, [elementWidth, dimensions]);
102
88
  const shouldRenderPlayButton = () => {
103
89
  const {
104
90
  mediaType
@@ -0,0 +1,10 @@
1
+ import { lazy } from 'react';
2
+ export const InlinePlayerLazyV2 = /*#__PURE__*/lazy(async () => {
3
+ const {
4
+ InlinePlayerV2
5
+ } = await import( /* webpackChunkName: "@atlaskit-internal_media-card-inlineplayer-v2" */
6
+ './inlinePlayerV2');
7
+ return {
8
+ default: InlinePlayerV2
9
+ };
10
+ });
@@ -0,0 +1,164 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React, { useRef, useState, useEffect } from 'react';
3
+ import { globalMediaEventEmitter } from '@atlaskit/media-client';
4
+ import { CustomMediaPlayer, InactivityDetector } from '@atlaskit/media-ui';
5
+ import { defaultImageCardDimensions } from '../../utils';
6
+ import { CardLoading } from '../../utils/lightCards/cardLoading';
7
+ import { ProgressBar } from '../ui/progressBar/progressBar';
8
+ import { InlinePlayerWrapper } from '../inlinePlayerWrapper';
9
+ import { useBreakpoint } from '../useBreakpoint';
10
+ import { useFileState, useMediaClient } from '@atlaskit/media-client-react';
11
+ export const getPreferredVideoArtifact = fileState => {
12
+ if (fileState.status === 'processed' || fileState.status === 'processing') {
13
+ const {
14
+ artifacts
15
+ } = fileState;
16
+ if (!artifacts) {
17
+ return undefined;
18
+ }
19
+ return artifacts['video_1280.mp4'] ? 'video_1280.mp4' : artifacts['video_640.mp4'] ? 'video_640.mp4' : undefined;
20
+ }
21
+ return undefined;
22
+ };
23
+ export const InlinePlayerBaseV2 = ({
24
+ identifier,
25
+ onError,
26
+ onClick,
27
+ dimensions = defaultImageCardDimensions,
28
+ originalDimensions,
29
+ selected,
30
+ testId,
31
+ forwardRef,
32
+ autoplay,
33
+ cardPreview,
34
+ onFullscreenChange
35
+ }) => {
36
+ // === States ===
37
+ const [fileSrc, setFileSrc] = useState();
38
+ const [isUploading, setIsUploading] = useState();
39
+ const [progress, setProgress] = useState();
40
+
41
+ // === Refs and Local Variables ===
42
+ const divRef = useRef(null);
43
+ const onErrorRef = useRef(onError);
44
+ onErrorRef.current = onError;
45
+ const {
46
+ id,
47
+ collectionName,
48
+ occurrenceKey
49
+ } = identifier;
50
+ const breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
51
+ const mediaClient = useMediaClient();
52
+ const {
53
+ fileState
54
+ } = useFileState(id, {
55
+ collectionName,
56
+ occurrenceKey
57
+ });
58
+ useEffect(() => {
59
+ const subscribeFileState = async fileState => {
60
+ if (fileState.status === 'uploading') {
61
+ setIsUploading(true);
62
+ setProgress(fileState.progress);
63
+ } else {
64
+ setIsUploading(false);
65
+ }
66
+
67
+ // We reuse the existing fileSrc to prevent re renders, therefore we only perform fileSrc updates when there isn't any
68
+ if (fileSrc) {
69
+ return;
70
+ }
71
+ if (fileState.status !== 'error' && fileState.preview) {
72
+ const {
73
+ value
74
+ } = await fileState.preview;
75
+ if (value instanceof Blob && value.type.indexOf('video/') === 0) {
76
+ const newFileSrc = URL.createObjectURL(value);
77
+ setFileSrc(newFileSrc);
78
+ return;
79
+ }
80
+ }
81
+ if (fileState.status === 'processed' || fileState.status === 'processing') {
82
+ const artifactName = getPreferredVideoArtifact(fileState);
83
+ const {
84
+ artifacts
85
+ } = fileState;
86
+ if (!artifactName || !artifacts) {
87
+ // Tries to use the binary artifact to provide something to play while the video is still processing
88
+ try {
89
+ const newFileSrc = await mediaClient.file.getFileBinaryURL(id, collectionName);
90
+ setFileSrc(newFileSrc);
91
+ } catch (error) {
92
+ if (onErrorRef.current && error instanceof Error) {
93
+ onErrorRef.current(error);
94
+ }
95
+ }
96
+ return;
97
+ }
98
+ try {
99
+ const newFileSrc = await mediaClient.file.getArtifactURL(artifacts, artifactName, collectionName);
100
+ setFileSrc(newFileSrc);
101
+ } catch (error) {
102
+ if (onErrorRef.current && error instanceof Error) {
103
+ onErrorRef.current(error);
104
+ }
105
+ }
106
+ }
107
+ };
108
+ if (fileState) {
109
+ subscribeFileState(fileState);
110
+ }
111
+ }, [fileState, collectionName, fileSrc, id, mediaClient]);
112
+ useEffect(() => {
113
+ return () => {
114
+ fileSrc && URL.revokeObjectURL(fileSrc);
115
+ };
116
+ }, [fileSrc]);
117
+
118
+ // === Render ===
119
+ return fileSrc ? /*#__PURE__*/React.createElement(InlinePlayerWrapper, {
120
+ testId: testId || 'media-card-inline-player',
121
+ selected: {
122
+ selected
123
+ },
124
+ onClick: onClick,
125
+ innerRef: forwardRef || undefined,
126
+ dimensions: dimensions
127
+ }, /*#__PURE__*/React.createElement(InactivityDetector, null, checkMouseMovement => /*#__PURE__*/React.createElement(CustomMediaPlayer, {
128
+ type: "video",
129
+ src: fileSrc,
130
+ onFullscreenChange: onFullscreenChange,
131
+ fileId: id,
132
+ isAutoPlay: autoplay,
133
+ isHDAvailable: false,
134
+ onDownloadClick: () => {
135
+ mediaClient.file.downloadBinary(id, undefined, collectionName);
136
+ },
137
+ onFirstPlay: () => {
138
+ globalMediaEventEmitter.emit('media-viewed', {
139
+ fileId: id,
140
+ viewingLevel: 'full'
141
+ });
142
+ },
143
+ lastWatchTimeConfig: {
144
+ contentId: id
145
+ },
146
+ originalDimensions: originalDimensions,
147
+ showControls: checkMouseMovement,
148
+ poster: cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI
149
+ })), isUploading && /*#__PURE__*/React.createElement(ProgressBar, {
150
+ progress: progress,
151
+ breakpoint: breakpoint,
152
+ positionBottom: true,
153
+ showOnTop: true
154
+ })) : /*#__PURE__*/React.createElement(CardLoading, {
155
+ testId: testId,
156
+ dimensions: dimensions
157
+ });
158
+ };
159
+ const InlinePlayerForwardRef = /*#__PURE__*/React.forwardRef((props, ref) => {
160
+ return /*#__PURE__*/React.createElement(InlinePlayerBaseV2, _extends({}, props, {
161
+ forwardRef: ref
162
+ }));
163
+ });
164
+ export const InlinePlayerV2 = InlinePlayerForwardRef;
@@ -37,7 +37,7 @@ export default class MediaInlineCardLoader extends React.PureComponent {
37
37
  } = this.state;
38
38
  const analyticsContext = {
39
39
  packageVersion: "@atlaskit/media-card",
40
- packageName: "77.1.1",
40
+ packageName: "77.2.0",
41
41
  componentName: 'mediaInlineCard',
42
42
  component: 'mediaInlineCard'
43
43
  };
@@ -4,7 +4,7 @@ import { extractErrorInfo, getRenderErrorRequestMetadata } from './analytics';
4
4
  import { MediaCardError } from '../errors';
5
5
  import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
6
6
  const packageName = "@atlaskit/media-card";
7
- const packageVersion = "77.1.1";
7
+ const packageVersion = "77.2.0";
8
8
  let concurrentExperience;
9
9
  const getExperience = id => {
10
10
  if (!concurrentExperience) {
@@ -51,14 +51,17 @@ export const completeUfoExperience = (id, status, fileAttributes, fileStateFlags
51
51
  break;
52
52
  }
53
53
  };
54
+ const getBasePayloadAttributes = () => ({
55
+ packageName,
56
+ packageVersion,
57
+ mediaEnvironment: getMediaEnvironment(),
58
+ mediaRegion: getMediaRegion()
59
+ });
54
60
  const succeedUfoExperience = (id, properties) => {
55
61
  getExperience(id).success({
56
62
  metadata: {
57
63
  ...properties,
58
- packageName,
59
- packageVersion,
60
- mediaEnvironment: getMediaEnvironment(),
61
- mediaRegion: getMediaRegion()
64
+ ...getBasePayloadAttributes()
62
65
  }
63
66
  });
64
67
  };
@@ -66,10 +69,16 @@ const failUfoExperience = (id, properties) => {
66
69
  getExperience(id).failure({
67
70
  metadata: {
68
71
  ...properties,
69
- packageName,
70
- packageVersion,
71
- mediaEnvironment: getMediaEnvironment(),
72
- mediaRegion: getMediaRegion()
72
+ ...getBasePayloadAttributes()
73
+ }
74
+ });
75
+ };
76
+ export const abortUfoExperience = (id, properties) => {
77
+ // UFO won't abort if it's already in a final state (succeeded, failed, aborted, etc)
78
+ getExperience(id).abort({
79
+ metadata: {
80
+ ...properties,
81
+ ...getBasePayloadAttributes()
73
82
  }
74
83
  });
75
84
  };