@atlaskit/media-card 77.1.2 → 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 (149) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/card/card.js +1 -1
  3. package/dist/cjs/card/media-card-analytics-error-boundary.js +1 -1
  4. package/dist/cjs/card/useBreakpoint.js +29 -0
  5. package/dist/cjs/card/v2/cardV2.js +3 -5
  6. package/dist/cjs/card/v2/cardViewV2.js +5 -22
  7. package/dist/cjs/card/v2/inlinePlayerLazyV2.js +35 -0
  8. package/dist/cjs/card/v2/inlinePlayerV2.js +222 -0
  9. package/dist/cjs/inline/loader.js +1 -1
  10. package/dist/cjs/utils/ufoExperiences.js +1 -1
  11. package/dist/es2019/card/card.js +1 -1
  12. package/dist/es2019/card/media-card-analytics-error-boundary.js +1 -1
  13. package/dist/es2019/card/useBreakpoint.js +22 -0
  14. package/dist/es2019/card/v2/cardV2.js +3 -5
  15. package/dist/es2019/card/v2/cardViewV2.js +4 -18
  16. package/dist/es2019/card/v2/inlinePlayerLazyV2.js +10 -0
  17. package/dist/es2019/card/v2/inlinePlayerV2.js +164 -0
  18. package/dist/es2019/inline/loader.js +1 -1
  19. package/dist/es2019/utils/ufoExperiences.js +1 -1
  20. package/dist/esm/card/card.js +1 -1
  21. package/dist/esm/card/media-card-analytics-error-boundary.js +1 -1
  22. package/dist/esm/card/useBreakpoint.js +24 -0
  23. package/dist/esm/card/v2/cardV2.js +3 -5
  24. package/dist/esm/card/v2/cardViewV2.js +7 -24
  25. package/dist/esm/card/v2/inlinePlayerLazyV2.js +23 -0
  26. package/dist/esm/card/v2/inlinePlayerV2.js +212 -0
  27. package/dist/esm/inline/loader.js +1 -1
  28. package/dist/esm/utils/ufoExperiences.js +1 -1
  29. package/dist/types/card/useBreakpoint.d.ts +3 -0
  30. package/dist/types/card/v2/inlinePlayerLazyV2.d.ts +2 -0
  31. package/dist/types/card/v2/inlinePlayerV2.d.ts +23 -0
  32. package/dist/types-ts4.5/card/actions.d.ts +9 -0
  33. package/dist/types-ts4.5/card/card.d.ts +64 -0
  34. package/dist/types-ts4.5/card/cardAnalytics.d.ts +10 -0
  35. package/dist/types-ts4.5/card/cardConstants.d.ts +1 -0
  36. package/dist/types-ts4.5/card/cardLoader.d.ts +6 -0
  37. package/dist/types-ts4.5/card/cardState.d.ts +9 -0
  38. package/dist/types-ts4.5/card/cardSwitcher.d.ts +4 -0
  39. package/dist/types-ts4.5/card/cardView.d.ts +78 -0
  40. package/dist/types-ts4.5/card/classnames.d.ts +2 -0
  41. package/dist/types-ts4.5/card/getCardPreview/cache.d.ts +21 -0
  42. package/dist/types-ts4.5/card/getCardPreview/filePreviewStatus.d.ts +4 -0
  43. package/dist/types-ts4.5/card/getCardPreview/helpers.d.ts +10 -0
  44. package/dist/types-ts4.5/card/getCardPreview/index.d.ts +53 -0
  45. package/dist/types-ts4.5/card/getCardStatus.d.ts +4 -0
  46. package/dist/types-ts4.5/card/index.d.ts +1 -0
  47. package/dist/types-ts4.5/card/inlinePlayer.d.ts +52 -0
  48. package/dist/types-ts4.5/card/inlinePlayerLazy.d.ts +2 -0
  49. package/dist/types-ts4.5/card/inlinePlayerWrapper.d.ts +4 -0
  50. package/dist/types-ts4.5/card/inlinePlayerWrapperStyles.d.ts +6 -0
  51. package/dist/types-ts4.5/card/media-card-analytics-error-boundary.d.ts +14 -0
  52. package/dist/types-ts4.5/card/types.d.ts +13 -0
  53. package/dist/types-ts4.5/card/ui/actionsBar/actionsBar.d.ts +5 -0
  54. package/dist/types-ts4.5/card/ui/actionsBar/actionsBarWrapper.d.ts +4 -0
  55. package/dist/types-ts4.5/card/ui/actionsBar/cardActions/cardActionButton.d.ts +3 -0
  56. package/dist/types-ts4.5/card/ui/actionsBar/cardActions/cardActionIconButton.d.ts +12 -0
  57. package/dist/types-ts4.5/card/ui/actionsBar/cardActions/cardActionsDropdownMenu.d.ts +14 -0
  58. package/dist/types-ts4.5/card/ui/actionsBar/cardActions/cardActionsView.d.ts +16 -0
  59. package/dist/types-ts4.5/card/ui/actionsBar/cardActions/index.d.ts +7 -0
  60. package/dist/types-ts4.5/card/ui/actionsBar/cardActions/styles.d.ts +18 -0
  61. package/dist/types-ts4.5/card/ui/actionsBar/styles.d.ts +6 -0
  62. package/dist/types-ts4.5/card/ui/actionsBar/types.d.ts +10 -0
  63. package/dist/types-ts4.5/card/ui/blanket/blanket.d.ts +6 -0
  64. package/dist/types-ts4.5/card/ui/blanket/styles.d.ts +6 -0
  65. package/dist/types-ts4.5/card/ui/common.d.ts +23 -0
  66. package/dist/types-ts4.5/card/ui/iconMessage/iconMessageWrapper.d.ts +4 -0
  67. package/dist/types-ts4.5/card/ui/iconMessage/index.d.ts +8 -0
  68. package/dist/types-ts4.5/card/ui/iconMessage/styles.d.ts +5 -0
  69. package/dist/types-ts4.5/card/ui/iconMessage/types.d.ts +19 -0
  70. package/dist/types-ts4.5/card/ui/iconWrapper/iconWrapper.d.ts +4 -0
  71. package/dist/types-ts4.5/card/ui/iconWrapper/styles.d.ts +7 -0
  72. package/dist/types-ts4.5/card/ui/iconWrapper/types.d.ts +6 -0
  73. package/dist/types-ts4.5/card/ui/imageRenderer/imageRenderer.d.ts +15 -0
  74. package/dist/types-ts4.5/card/ui/imageRenderer/resizeModeToMediaImageProps.d.ts +5 -0
  75. package/dist/types-ts4.5/card/ui/playButton/playButton.d.ts +2 -0
  76. package/dist/types-ts4.5/card/ui/playButton/playButtonBackground.d.ts +3 -0
  77. package/dist/types-ts4.5/card/ui/playButton/playButtonWrapper.d.ts +3 -0
  78. package/dist/types-ts4.5/card/ui/playButton/styles.d.ts +5 -0
  79. package/dist/types-ts4.5/card/ui/progressBar/progressBar.d.ts +10 -0
  80. package/dist/types-ts4.5/card/ui/progressBar/styledBar.d.ts +4 -0
  81. package/dist/types-ts4.5/card/ui/progressBar/styles.d.ts +7 -0
  82. package/dist/types-ts4.5/card/ui/progressBar/types.d.ts +7 -0
  83. package/dist/types-ts4.5/card/ui/styles.d.ts +13 -0
  84. package/dist/types-ts4.5/card/ui/tickBox/styles.d.ts +7 -0
  85. package/dist/types-ts4.5/card/ui/tickBox/tickBox.d.ts +3 -0
  86. package/dist/types-ts4.5/card/ui/tickBox/tickBoxWrapper.d.ts +4 -0
  87. package/dist/types-ts4.5/card/ui/tickBox/types.d.ts +4 -0
  88. package/dist/types-ts4.5/card/ui/titleBox/failedTitleBox.d.ts +3 -0
  89. package/dist/types-ts4.5/card/ui/titleBox/styles.d.ts +15 -0
  90. package/dist/types-ts4.5/card/ui/titleBox/titleBox.d.ts +4 -0
  91. package/dist/types-ts4.5/card/ui/titleBox/titleBoxComponents.d.ts +8 -0
  92. package/dist/types-ts4.5/card/ui/titleBox/types.d.ts +34 -0
  93. package/dist/types-ts4.5/card/ui/unhandledErrorCard/index.d.ts +7 -0
  94. package/dist/types-ts4.5/card/ui/unhandledErrorCard/types.d.ts +6 -0
  95. package/dist/types-ts4.5/card/ui/wrapper/index.d.ts +1 -0
  96. package/dist/types-ts4.5/card/ui/wrapper/styles.d.ts +5 -0
  97. package/dist/types-ts4.5/card/ui/wrapper/types.d.ts +25 -0
  98. package/dist/types-ts4.5/card/ui/wrapper/wrapper.d.ts +4 -0
  99. package/dist/types-ts4.5/card/useBreakpoint.d.ts +3 -0
  100. package/dist/types-ts4.5/card/v2/cardV2.d.ts +63 -0
  101. package/dist/types-ts4.5/card/v2/cardV2Loader.d.ts +4 -0
  102. package/dist/types-ts4.5/card/v2/cardViewV2.d.ts +44 -0
  103. package/dist/types-ts4.5/card/v2/inlinePlayerLazyV2.d.ts +2 -0
  104. package/dist/types-ts4.5/card/v2/inlinePlayerV2.d.ts +23 -0
  105. package/dist/types-ts4.5/classnames.d.ts +5 -0
  106. package/dist/types-ts4.5/errors.d.ts +53 -0
  107. package/dist/types-ts4.5/index.d.ts +15 -0
  108. package/dist/types-ts4.5/inline/index.d.ts +1 -0
  109. package/dist/types-ts4.5/inline/loader.d.ts +26 -0
  110. package/dist/types-ts4.5/inline/mediaInlineAnalyticsErrorBoundary.d.ts +12 -0
  111. package/dist/types-ts4.5/inline/mediaInlineCard.d.ts +15 -0
  112. package/dist/types-ts4.5/inline/mediaInlineCardAnalytics.d.ts +6 -0
  113. package/dist/types-ts4.5/types.d.ts +105 -0
  114. package/dist/types-ts4.5/utils/analytics.d.ts +101 -0
  115. package/dist/types-ts4.5/utils/cardDimensions.d.ts +14 -0
  116. package/dist/types-ts4.5/utils/containsPixelUnit.d.ts +1 -0
  117. package/dist/types-ts4.5/utils/dimensionComparer.d.ts +3 -0
  118. package/dist/types-ts4.5/utils/document.d.ts +2 -0
  119. package/dist/types-ts4.5/utils/generateUniqueId.d.ts +1 -0
  120. package/dist/types-ts4.5/utils/getCSSUnitValue.d.ts +1 -0
  121. package/dist/types-ts4.5/utils/getDataURIDimension.d.ts +9 -0
  122. package/dist/types-ts4.5/utils/getElementDimension.d.ts +2 -0
  123. package/dist/types-ts4.5/utils/getMediaCardCursor.d.ts +6 -0
  124. package/dist/types-ts4.5/utils/globalScope/getSSRData.d.ts +3 -0
  125. package/dist/types-ts4.5/utils/globalScope/globalScope.d.ts +21 -0
  126. package/dist/types-ts4.5/utils/globalScope/index.d.ts +4 -0
  127. package/dist/types-ts4.5/utils/globalScope/types.d.ts +8 -0
  128. package/dist/types-ts4.5/utils/index.d.ts +6 -0
  129. package/dist/types-ts4.5/utils/isRetina.d.ts +1 -0
  130. package/dist/types-ts4.5/utils/isValidPercentageUnit.d.ts +1 -0
  131. package/dist/types-ts4.5/utils/lightCards/cardError.d.ts +12 -0
  132. package/dist/types-ts4.5/utils/lightCards/cardLoading.d.ts +5 -0
  133. package/dist/types-ts4.5/utils/lightCards/errorIcon/index.d.ts +12 -0
  134. package/dist/types-ts4.5/utils/lightCards/errorIcon/styles.d.ts +1 -0
  135. package/dist/types-ts4.5/utils/lightCards/getDimensionsWithDefault.d.ts +2 -0
  136. package/dist/types-ts4.5/utils/lightCards/lightCardWrappers.d.ts +4 -0
  137. package/dist/types-ts4.5/utils/lightCards/styles.d.ts +2 -0
  138. package/dist/types-ts4.5/utils/lightCards/types.d.ts +15 -0
  139. package/dist/types-ts4.5/utils/metadata.d.ts +2 -0
  140. package/dist/types-ts4.5/utils/mockIntersectionObserver.d.ts +20 -0
  141. package/dist/types-ts4.5/utils/objectURLCache.d.ts +12 -0
  142. package/dist/types-ts4.5/utils/preventClickThrough.d.ts +8 -0
  143. package/dist/types-ts4.5/utils/printScript.d.ts +2 -0
  144. package/dist/types-ts4.5/utils/ufoExperiences.d.ts +14 -0
  145. package/dist/types-ts4.5/utils/videoIsPlayable.d.ts +2 -0
  146. package/dist/types-ts4.5/utils/videoSnapshot.d.ts +1 -0
  147. package/dist/types-ts4.5/utils/viewportDetector.d.ts +6 -0
  148. package/package.json +5 -4
  149. package/tmp/api-report-tmp.d.ts +345 -0
@@ -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.2",
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.2";
7
+ const packageVersion = "77.2.0";
8
8
  let concurrentExperience;
9
9
  const getExperience = id => {
10
10
  if (!concurrentExperience) {
@@ -40,7 +40,7 @@ import { getMediaCardCursor } from '../utils/getMediaCardCursor';
40
40
  import { completeUfoExperience, startUfoExperience, abortUfoExperience } from '../utils/ufoExperiences';
41
41
  import { generateUniqueId } from '../utils/generateUniqueId';
42
42
  var packageName = "@atlaskit/media-card";
43
- var packageVersion = "77.1.2";
43
+ var packageVersion = "77.2.0";
44
44
  export var CardBase = /*#__PURE__*/function (_Component) {
45
45
  _inherits(CardBase, _Component);
46
46
  var _super = _createSuper(CardBase);
@@ -83,7 +83,7 @@ var WrappedMediaCardAnalyticsErrorBoundary = /*#__PURE__*/function (_React$Compo
83
83
  }(React.Component);
84
84
  _defineProperty(WrappedMediaCardAnalyticsErrorBoundary, "displayName", 'MediaCardAnalyticsErrorBoundary');
85
85
  var packageName = "@atlaskit/media-card";
86
- var packageVersion = "77.1.2";
86
+ var packageVersion = "77.2.0";
87
87
  var MediaCardAnalyticsErrorBoundary = withMediaAnalyticsContext({
88
88
  packageVersion: packageVersion,
89
89
  packageName: packageName,
@@ -0,0 +1,24 @@
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 var useBreakpoint = function useBreakpoint() {
7
+ var dimensionWidth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
8
+ var divRef = arguments.length > 1 ? arguments[1] : undefined;
9
+ var breakpoint = useMemo(function () {
10
+ var widthToCalculate;
11
+ if (dimensionWidth) {
12
+ if (isValidPercentageUnit(dimensionWidth) && divRef.current) {
13
+ var width = getElementDimension(divRef.current, 'width');
14
+ widthToCalculate = width || defaultImageCardDimensions.width;
15
+ } else {
16
+ widthToCalculate = dimensionWidth;
17
+ }
18
+ } else {
19
+ widthToCalculate = defaultImageCardDimensions.width;
20
+ }
21
+ return calcBreakpointSize(parseInt("".concat(widthToCalculate), 10));
22
+ }, [dimensionWidth, divRef]);
23
+ return breakpoint;
24
+ };
@@ -28,7 +28,7 @@ import { videoIsPlayable } from '../../utils/videoIsPlayable';
28
28
  import { getRequestedDimensions } from '../../utils/getDataURIDimension';
29
29
  import { getCardPreview, getCardPreviewFromCache, removeCardPreviewFromCache, getFilePreviewFromFileState, shouldResolvePreview, getSSRCardPreview, isLocalPreview, isSSRPreview, isSSRClientPreview, isSSRDataPreview, fetchAndCacheRemotePreview } from '../getCardPreview';
30
30
  import { getFileDetails } from '../../utils/metadata';
31
- import { InlinePlayerLazy } from '../inlinePlayerLazy';
31
+ import { InlinePlayerLazyV2 } from './inlinePlayerLazyV2';
32
32
  import { getFileAttributes, extractErrorInfo } from '../../utils/analytics';
33
33
  import { isLocalPreviewError, MediaCardError, MediaFileStateError, ensureMediaCardError, ImageLoadError } from '../../errors';
34
34
  import { fireOperationalEvent as _fireOperationalEvent, fireCommencedEvent as _fireCommencedEvent, fireCopiedEvent, fireScreenEvent, fireNonCriticalErrorEvent } from '../cardAnalytics';
@@ -41,7 +41,7 @@ import { completeUfoExperience, startUfoExperience, abortUfoExperience } from '.
41
41
  import { generateUniqueId } from '../../utils/generateUniqueId';
42
42
  import { useFileState } from '@atlaskit/media-client-react';
43
43
  var packageName = "@atlaskit/media-card";
44
- var packageVersion = "77.1.2";
44
+ var packageVersion = "77.2.0";
45
45
  export var CardV2Base = /*#__PURE__*/function (_Component) {
46
46
  _inherits(CardV2Base, _Component);
47
47
  var _super = _createSuper(CardV2Base);
@@ -443,7 +443,6 @@ export var CardV2Base = /*#__PURE__*/function (_Component) {
443
443
  _defineProperty(_assertThisInitialized(_this), "renderInlinePlayer", function () {
444
444
  var _this$props6 = _this.props,
445
445
  identifier = _this$props6.identifier,
446
- mediaClient = _this$props6.mediaClient,
447
446
  dimensions = _this$props6.dimensions,
448
447
  selected = _this$props6.selected,
449
448
  testId = _this$props6.testId,
@@ -455,8 +454,7 @@ export var CardV2Base = /*#__PURE__*/function (_Component) {
455
454
  var card = _this.renderCard(false, 'loading', false);
456
455
  return /*#__PURE__*/React.createElement(Suspense, {
457
456
  fallback: card
458
- }, /*#__PURE__*/React.createElement(InlinePlayerLazy, {
459
- mediaClient: mediaClient,
457
+ }, /*#__PURE__*/React.createElement(InlinePlayerLazyV2, {
460
458
  dimensions: dimensions,
461
459
  originalDimensions: originalDimensions,
462
460
  identifier: identifier,
@@ -4,18 +4,15 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
4
4
  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) { _defineProperty(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; }
5
5
  /** @jsx jsx */
6
6
  import { jsx } from '@emotion/react';
7
- import React, { useEffect, useState, useRef, useMemo } from 'react';
7
+ import React, { useEffect, useState, useRef } from 'react';
8
8
  import { withAnalyticsEvents } from '@atlaskit/analytics-next';
9
9
  import { MimeTypeIcon } from '@atlaskit/media-ui/mime-type-icon';
10
10
  import SpinnerIcon from '@atlaskit/spinner';
11
11
  import Tooltip from '@atlaskit/tooltip';
12
12
  import { messages } from '@atlaskit/media-ui';
13
- import { defaultImageCardDimensions } from '../../utils/cardDimensions';
14
- import { isValidPercentageUnit } from '../../utils/isValidPercentageUnit';
15
- import { getElementDimension } from '../../utils/getElementDimension';
16
13
  import { createAndFireMediaCardEvent } from '../../utils/analytics';
17
14
  import { attachDetailsToActions } from '../actions';
18
- import { cardImageContainerStyles, calcBreakpointSize } from '../ui/styles';
15
+ import { cardImageContainerStyles } from '../ui/styles';
19
16
  import { ImageRenderer } from '../ui/imageRenderer/imageRenderer';
20
17
  import { TitleBox } from '../ui/titleBox/titleBox';
21
18
  import { FailedTitleBox } from '../ui/titleBox/failedTitleBox';
@@ -29,6 +26,7 @@ import { PreviewUnavailable, CreatingPreview, FailedToUpload, PreviewCurrentlyUn
29
26
  import { isUploadError, isRateLimitedError, isPollingError } from '../../errors';
30
27
  import { Wrapper } from '../ui/wrapper';
31
28
  import { fileCardImageViewSelector } from '../classnames';
29
+ import { useBreakpoint } from '../useBreakpoint';
32
30
  export var CardViewV2Base = function CardViewV2Base(_ref) {
33
31
  var innerRef = _ref.innerRef,
34
32
  onImageLoad = _ref.onImageLoad,
@@ -58,24 +56,13 @@ export var CardViewV2Base = function CardViewV2Base(_ref) {
58
56
  titleBoxIcon = _ref.titleBoxIcon,
59
57
  error = _ref.error,
60
58
  disableAnimation = _ref.disableAnimation;
61
- var _useState = useState(),
59
+ var _useState = useState(false),
62
60
  _useState2 = _slicedToArray(_useState, 2),
63
- elementWidth = _useState2[0],
64
- setElementWidth = _useState2[1];
65
- var _useState3 = useState(false),
66
- _useState4 = _slicedToArray(_useState3, 2),
67
- didImageRender = _useState4[0],
68
- setDidImageRender = _useState4[1];
61
+ didImageRender = _useState2[0],
62
+ setDidImageRender = _useState2[1];
69
63
  var divRef = useRef(null);
70
64
  var prevCardPreviewRef = useRef();
71
- var width = (dimensions === null || dimensions === void 0 ? void 0 : dimensions.width) || 0;
72
- useEffect(function () {
73
- // If the dimensions.width is a percentage, we need to transform it into a pixel value in order to get the right breakpoints applied.
74
- if (width && isValidPercentageUnit(width) && !!divRef.current) {
75
- var _elementWidth = getElementDimension(divRef.current, 'width');
76
- setElementWidth(_elementWidth);
77
- }
78
- }, [width]);
65
+ var breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
79
66
  useEffect(function () {
80
67
  innerRef && !!divRef.current && innerRef(divRef.current);
81
68
  }, [innerRef]);
@@ -105,10 +92,6 @@ export var CardViewV2Base = function CardViewV2Base(_ref) {
105
92
  setDidImageRender(false);
106
93
  onImageError === null || onImageError === void 0 || onImageError(cardPreview);
107
94
  };
108
- var breakpoint = useMemo(function () {
109
- var width = elementWidth || (dimensions ? dimensions.width : '') || defaultImageCardDimensions.width;
110
- return calcBreakpointSize(parseInt("".concat(width), 10));
111
- }, [elementWidth, dimensions]);
112
95
  var shouldRenderPlayButton = function shouldRenderPlayButton() {
113
96
  var _ref2 = metadata || {},
114
97
  mediaType = _ref2.mediaType;
@@ -0,0 +1,23 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import { lazy } from 'react';
4
+ export var InlinePlayerLazyV2 = /*#__PURE__*/lazy( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
5
+ var _yield$import, InlinePlayerV2;
6
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
7
+ while (1) switch (_context.prev = _context.next) {
8
+ case 0:
9
+ _context.next = 2;
10
+ return import( /* webpackChunkName: "@atlaskit-internal_media-card-inlineplayer-v2" */
11
+ './inlinePlayerV2');
12
+ case 2:
13
+ _yield$import = _context.sent;
14
+ InlinePlayerV2 = _yield$import.InlinePlayerV2;
15
+ return _context.abrupt("return", {
16
+ default: InlinePlayerV2
17
+ });
18
+ case 5:
19
+ case "end":
20
+ return _context.stop();
21
+ }
22
+ }, _callee);
23
+ })));
@@ -0,0 +1,212 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+ import React, { useRef, useState, useEffect } from 'react';
6
+ import { globalMediaEventEmitter } from '@atlaskit/media-client';
7
+ import { CustomMediaPlayer, InactivityDetector } from '@atlaskit/media-ui';
8
+ import { defaultImageCardDimensions } from '../../utils';
9
+ import { CardLoading } from '../../utils/lightCards/cardLoading';
10
+ import { ProgressBar } from '../ui/progressBar/progressBar';
11
+ import { InlinePlayerWrapper } from '../inlinePlayerWrapper';
12
+ import { useBreakpoint } from '../useBreakpoint';
13
+ import { useFileState, useMediaClient } from '@atlaskit/media-client-react';
14
+ export var getPreferredVideoArtifact = function getPreferredVideoArtifact(fileState) {
15
+ if (fileState.status === 'processed' || fileState.status === 'processing') {
16
+ var artifacts = fileState.artifacts;
17
+ if (!artifacts) {
18
+ return undefined;
19
+ }
20
+ return artifacts['video_1280.mp4'] ? 'video_1280.mp4' : artifacts['video_640.mp4'] ? 'video_640.mp4' : undefined;
21
+ }
22
+ return undefined;
23
+ };
24
+ export var InlinePlayerBaseV2 = function InlinePlayerBaseV2(_ref) {
25
+ var identifier = _ref.identifier,
26
+ onError = _ref.onError,
27
+ onClick = _ref.onClick,
28
+ _ref$dimensions = _ref.dimensions,
29
+ dimensions = _ref$dimensions === void 0 ? defaultImageCardDimensions : _ref$dimensions,
30
+ originalDimensions = _ref.originalDimensions,
31
+ selected = _ref.selected,
32
+ testId = _ref.testId,
33
+ forwardRef = _ref.forwardRef,
34
+ autoplay = _ref.autoplay,
35
+ cardPreview = _ref.cardPreview,
36
+ onFullscreenChange = _ref.onFullscreenChange;
37
+ // === States ===
38
+ var _useState = useState(),
39
+ _useState2 = _slicedToArray(_useState, 2),
40
+ fileSrc = _useState2[0],
41
+ setFileSrc = _useState2[1];
42
+ var _useState3 = useState(),
43
+ _useState4 = _slicedToArray(_useState3, 2),
44
+ isUploading = _useState4[0],
45
+ setIsUploading = _useState4[1];
46
+ var _useState5 = useState(),
47
+ _useState6 = _slicedToArray(_useState5, 2),
48
+ progress = _useState6[0],
49
+ setProgress = _useState6[1];
50
+
51
+ // === Refs and Local Variables ===
52
+ var divRef = useRef(null);
53
+ var onErrorRef = useRef(onError);
54
+ onErrorRef.current = onError;
55
+ var id = identifier.id,
56
+ collectionName = identifier.collectionName,
57
+ occurrenceKey = identifier.occurrenceKey;
58
+ var breakpoint = useBreakpoint(dimensions === null || dimensions === void 0 ? void 0 : dimensions.width, divRef);
59
+ var mediaClient = useMediaClient();
60
+ var _useFileState = useFileState(id, {
61
+ collectionName: collectionName,
62
+ occurrenceKey: occurrenceKey
63
+ }),
64
+ fileState = _useFileState.fileState;
65
+ useEffect(function () {
66
+ var subscribeFileState = /*#__PURE__*/function () {
67
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(fileState) {
68
+ var _yield$fileState$prev, value, newFileSrc, artifactName, artifacts, _newFileSrc, _newFileSrc2;
69
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
70
+ while (1) switch (_context.prev = _context.next) {
71
+ case 0:
72
+ if (fileState.status === 'uploading') {
73
+ setIsUploading(true);
74
+ setProgress(fileState.progress);
75
+ } else {
76
+ setIsUploading(false);
77
+ }
78
+
79
+ // We reuse the existing fileSrc to prevent re renders, therefore we only perform fileSrc updates when there isn't any
80
+ if (!fileSrc) {
81
+ _context.next = 3;
82
+ break;
83
+ }
84
+ return _context.abrupt("return");
85
+ case 3:
86
+ if (!(fileState.status !== 'error' && fileState.preview)) {
87
+ _context.next = 12;
88
+ break;
89
+ }
90
+ _context.next = 6;
91
+ return fileState.preview;
92
+ case 6:
93
+ _yield$fileState$prev = _context.sent;
94
+ value = _yield$fileState$prev.value;
95
+ if (!(value instanceof Blob && value.type.indexOf('video/') === 0)) {
96
+ _context.next = 12;
97
+ break;
98
+ }
99
+ newFileSrc = URL.createObjectURL(value);
100
+ setFileSrc(newFileSrc);
101
+ return _context.abrupt("return");
102
+ case 12:
103
+ if (!(fileState.status === 'processed' || fileState.status === 'processing')) {
104
+ _context.next = 37;
105
+ break;
106
+ }
107
+ artifactName = getPreferredVideoArtifact(fileState);
108
+ artifacts = fileState.artifacts;
109
+ if (!(!artifactName || !artifacts)) {
110
+ _context.next = 27;
111
+ break;
112
+ }
113
+ _context.prev = 16;
114
+ _context.next = 19;
115
+ return mediaClient.file.getFileBinaryURL(id, collectionName);
116
+ case 19:
117
+ _newFileSrc = _context.sent;
118
+ setFileSrc(_newFileSrc);
119
+ _context.next = 26;
120
+ break;
121
+ case 23:
122
+ _context.prev = 23;
123
+ _context.t0 = _context["catch"](16);
124
+ if (onErrorRef.current && _context.t0 instanceof Error) {
125
+ onErrorRef.current(_context.t0);
126
+ }
127
+ case 26:
128
+ return _context.abrupt("return");
129
+ case 27:
130
+ _context.prev = 27;
131
+ _context.next = 30;
132
+ return mediaClient.file.getArtifactURL(artifacts, artifactName, collectionName);
133
+ case 30:
134
+ _newFileSrc2 = _context.sent;
135
+ setFileSrc(_newFileSrc2);
136
+ _context.next = 37;
137
+ break;
138
+ case 34:
139
+ _context.prev = 34;
140
+ _context.t1 = _context["catch"](27);
141
+ if (onErrorRef.current && _context.t1 instanceof Error) {
142
+ onErrorRef.current(_context.t1);
143
+ }
144
+ case 37:
145
+ case "end":
146
+ return _context.stop();
147
+ }
148
+ }, _callee, null, [[16, 23], [27, 34]]);
149
+ }));
150
+ return function subscribeFileState(_x) {
151
+ return _ref2.apply(this, arguments);
152
+ };
153
+ }();
154
+ if (fileState) {
155
+ subscribeFileState(fileState);
156
+ }
157
+ }, [fileState, collectionName, fileSrc, id, mediaClient]);
158
+ useEffect(function () {
159
+ return function () {
160
+ fileSrc && URL.revokeObjectURL(fileSrc);
161
+ };
162
+ }, [fileSrc]);
163
+
164
+ // === Render ===
165
+ return fileSrc ? /*#__PURE__*/React.createElement(InlinePlayerWrapper, {
166
+ testId: testId || 'media-card-inline-player',
167
+ selected: {
168
+ selected: selected
169
+ },
170
+ onClick: onClick,
171
+ innerRef: forwardRef || undefined,
172
+ dimensions: dimensions
173
+ }, /*#__PURE__*/React.createElement(InactivityDetector, null, function (checkMouseMovement) {
174
+ return /*#__PURE__*/React.createElement(CustomMediaPlayer, {
175
+ type: "video",
176
+ src: fileSrc,
177
+ onFullscreenChange: onFullscreenChange,
178
+ fileId: id,
179
+ isAutoPlay: autoplay,
180
+ isHDAvailable: false,
181
+ onDownloadClick: function onDownloadClick() {
182
+ mediaClient.file.downloadBinary(id, undefined, collectionName);
183
+ },
184
+ onFirstPlay: function onFirstPlay() {
185
+ globalMediaEventEmitter.emit('media-viewed', {
186
+ fileId: id,
187
+ viewingLevel: 'full'
188
+ });
189
+ },
190
+ lastWatchTimeConfig: {
191
+ contentId: id
192
+ },
193
+ originalDimensions: originalDimensions,
194
+ showControls: checkMouseMovement,
195
+ poster: cardPreview === null || cardPreview === void 0 ? void 0 : cardPreview.dataURI
196
+ });
197
+ }), isUploading && /*#__PURE__*/React.createElement(ProgressBar, {
198
+ progress: progress,
199
+ breakpoint: breakpoint,
200
+ positionBottom: true,
201
+ showOnTop: true
202
+ })) : /*#__PURE__*/React.createElement(CardLoading, {
203
+ testId: testId,
204
+ dimensions: dimensions
205
+ });
206
+ };
207
+ var InlinePlayerForwardRef = /*#__PURE__*/React.forwardRef(function (props, ref) {
208
+ return /*#__PURE__*/React.createElement(InlinePlayerBaseV2, _extends({}, props, {
209
+ forwardRef: ref
210
+ }));
211
+ });
212
+ export var InlinePlayerV2 = InlinePlayerForwardRef;
@@ -103,7 +103,7 @@ var MediaInlineCardLoader = /*#__PURE__*/function (_React$PureComponent) {
103
103
  ErrorBoundary = _this$state.ErrorBoundary;
104
104
  var analyticsContext = {
105
105
  packageVersion: "@atlaskit/media-card",
106
- packageName: "77.1.2",
106
+ packageName: "77.2.0",
107
107
  componentName: 'mediaInlineCard',
108
108
  component: 'mediaInlineCard'
109
109
  };
@@ -7,7 +7,7 @@ import { extractErrorInfo, getRenderErrorRequestMetadata } from './analytics';
7
7
  import { MediaCardError } from '../errors';
8
8
  import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
9
9
  var packageName = "@atlaskit/media-card";
10
- var packageVersion = "77.1.2";
10
+ var packageVersion = "77.2.0";
11
11
  var concurrentExperience;
12
12
  var getExperience = function getExperience(id) {
13
13
  if (!concurrentExperience) {
@@ -0,0 +1,3 @@
1
+ import { Breakpoint } from './ui/common';
2
+ import { CardDimensionValue } from '../types';
3
+ export declare const useBreakpoint: (dimensionWidth: CardDimensionValue | undefined, divRef: React.RefObject<HTMLDivElement>) => Breakpoint;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const InlinePlayerLazyV2: import("react").LazyExoticComponent<import("react").ForwardRefExoticComponent<Pick<import("./inlinePlayerV2").InlinePlayerProps, "createAnalyticsEvent" | keyof import("./inlinePlayerV2").InlinePlayerOwnProps> & import("react").RefAttributes<HTMLDivElement>>>;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { FileIdentifier, FileState, MediaFileArtifacts } from '@atlaskit/media-client';
3
+ import { NumericalCardDimensions } from '@atlaskit/media-common';
4
+ import { CardDimensions } from '../../types';
5
+ import { WithAnalyticsEventsProps, UIAnalyticsEvent } from '@atlaskit/analytics-next';
6
+ import type { CardPreview } from '../../types';
7
+ export interface InlinePlayerOwnProps {
8
+ identifier: FileIdentifier;
9
+ dimensions?: CardDimensions;
10
+ originalDimensions?: NumericalCardDimensions;
11
+ autoplay: boolean;
12
+ selected?: boolean;
13
+ onFullscreenChange?: (fullscreen: boolean) => void;
14
+ onError?: (error: Error) => void;
15
+ readonly onClick?: (event: React.MouseEvent<HTMLDivElement>, analyticsEvent?: UIAnalyticsEvent) => void;
16
+ testId?: string;
17
+ readonly cardPreview?: CardPreview;
18
+ readonly forwardRef?: React.Ref<HTMLDivElement>;
19
+ }
20
+ export type InlinePlayerProps = InlinePlayerOwnProps & WithAnalyticsEventsProps;
21
+ export declare const getPreferredVideoArtifact: (fileState: FileState) => keyof MediaFileArtifacts | undefined;
22
+ export declare const InlinePlayerBaseV2: ({ identifier, onError, onClick, dimensions, originalDimensions, selected, testId, forwardRef, autoplay, cardPreview, onFullscreenChange, }: InlinePlayerProps) => JSX.Element;
23
+ export declare const InlinePlayerV2: React.ForwardRefExoticComponent<Pick<InlinePlayerProps, "createAnalyticsEvent" | keyof InlinePlayerOwnProps> & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,9 @@
1
+ import { FileItem, FileDetails } from '@atlaskit/media-client';
2
+ import { ReactNode } from 'react';
3
+ export interface CardAction {
4
+ label?: string;
5
+ handler: CardEventHandler;
6
+ icon?: ReactNode;
7
+ }
8
+ export type CardEventHandler = (item?: FileItem, event?: Event) => void;
9
+ export declare function attachDetailsToActions(actions: Array<CardAction>, details: FileDetails): Array<CardAction>;