@atlaskit/media-viewer 54.11.0 → 54.11.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.
@@ -3,33 +3,43 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _get from "@babel/runtime/helpers/get";
6
7
  import _inherits from "@babel/runtime/helpers/inherits";
7
8
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
9
  import _regeneratorRuntime from "@babel/runtime/regenerator";
9
10
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
10
11
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
12
+ function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
11
13
  import React from 'react';
12
14
  import { getArtifactUrl, globalMediaEventEmitter, isFileIdentifier } from '@atlaskit/media-client';
15
+ import { Camera } from '@atlaskit/media-ui/camera/camera';
13
16
  import { CustomMediaPlayer } from '@atlaskit/media-ui/customMediaPlayer';
17
+ import { InsetViewerProvider } from '@atlaskit/media-ui/insetViewerProvider';
14
18
  import { MediaPlayer } from '@atlaskit/media-ui/mediaPlayer';
19
+ import { Rectangle } from '@atlaskit/media-ui/rectangle';
15
20
  import { fg } from '@atlaskit/platform-feature-flags/fg';
16
21
  import { buildVideoErrorDiagnostics } from '../buildVideoErrorDiagnostics';
17
22
  import { Outcome } from '../domain/outcome';
23
+ import { withInsetViewerFooter } from '../insetViewerContext';
18
24
  import { MediaViewerError } from '../MediaViewerError';
19
- import { Video, CustomVideoPlayerWrapper } from '../styleWrappers';
25
+ import { Video, CustomVideoPlayerWrapper, FittedVideoFrame } from '../styleWrappers';
26
+ import { insetFittedViewport } from '../utils/fit-viewport';
20
27
  import { getObjectUrlFromFileState } from '../utils/getObjectUrlFromFileState';
21
28
  import { isIE } from '../utils/isIE';
22
29
  import { BaseViewer } from './base-viewer';
23
30
  var hdArtifact = 'video_1280.mp4';
24
31
  var sdArtifact = 'video_640.mp4';
25
- export var VideoViewer = /*#__PURE__*/function (_BaseViewer) {
26
- function VideoViewer() {
32
+ var _VideoViewer = /*#__PURE__*/function (_BaseViewer) {
33
+ function _VideoViewer() {
27
34
  var _this;
28
- _classCallCheck(this, VideoViewer);
35
+ _classCallCheck(this, _VideoViewer);
29
36
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
30
37
  args[_key] = arguments[_key];
31
38
  }
32
- _this = _callSuper(this, VideoViewer, [].concat(args));
39
+ _this = _callSuper(this, _VideoViewer, [].concat(args));
40
+ _defineProperty(_this, "insetVideoFrame", null);
41
+ _defineProperty(_this, "insetVideo", null);
42
+ _defineProperty(_this, "insetVideoResizeObserver", null);
33
43
  _defineProperty(_this, "onFirstPlay", function () {
34
44
  var _this$props = _this.props,
35
45
  item = _this$props.item,
@@ -63,10 +73,74 @@ export var VideoViewer = /*#__PURE__*/function (_BaseViewer) {
63
73
  }
64
74
  onError && onError(new MediaViewerError('videoviewer-playback', secondaryError));
65
75
  });
76
+ _defineProperty(_this, "updateInsetVideoSize", function () {
77
+ var frame = _this.insetVideoFrame;
78
+ var wrapper = frame === null || frame === void 0 ? void 0 : frame.parentElement;
79
+ var video = _this.insetVideo;
80
+ if (!wrapper || !frame || !video || video.videoWidth <= 0 || video.videoHeight <= 0) {
81
+ return;
82
+ }
83
+ var viewport = insetFittedViewport(wrapper);
84
+ if (viewport.width <= 0 || viewport.height <= 0) {
85
+ return;
86
+ }
87
+ var camera = new Camera(viewport, new Rectangle(video.videoWidth, video.videoHeight));
88
+ var nextSize = camera.scaledImg(camera.scaleToFit);
89
+ frame.style.width = "".concat(nextSize.width, "px");
90
+ frame.style.height = "".concat(nextSize.height, "px");
91
+ });
92
+ _defineProperty(_this, "unbindInsetVideoSize", function () {
93
+ var _this$insetVideo, _this$insetVideoResiz;
94
+ (_this$insetVideo = _this.insetVideo) === null || _this$insetVideo === void 0 || _this$insetVideo.removeEventListener('loadedmetadata', _this.updateInsetVideoSize);
95
+ (_this$insetVideoResiz = _this.insetVideoResizeObserver) === null || _this$insetVideoResiz === void 0 || _this$insetVideoResiz.disconnect();
96
+ _this.insetVideoResizeObserver = null;
97
+ });
98
+ _defineProperty(_this, "bindInsetVideoSize", function () {
99
+ var frame = _this.insetVideoFrame;
100
+ var wrapper = frame === null || frame === void 0 ? void 0 : frame.parentElement;
101
+ var video = _this.insetVideo;
102
+ if (!wrapper || !frame || !video) {
103
+ return;
104
+ }
105
+ video.addEventListener('loadedmetadata', _this.updateInsetVideoSize);
106
+ if (typeof ResizeObserver !== 'undefined') {
107
+ _this.insetVideoResizeObserver = new ResizeObserver(_this.updateInsetVideoSize);
108
+ _this.insetVideoResizeObserver.observe(wrapper);
109
+ }
110
+ _this.updateInsetVideoSize();
111
+ });
112
+ _defineProperty(_this, "setInsetVideo", function (video) {
113
+ _this.unbindInsetVideoSize();
114
+ _this.insetVideo = video;
115
+ _this.bindInsetVideoSize();
116
+ });
117
+ _defineProperty(_this, "setInsetVideoFrame", function (frame) {
118
+ _this.unbindInsetVideoSize();
119
+ _this.insetVideoFrame = frame;
120
+ _this.bindInsetVideoSize();
121
+ });
66
122
  return _this;
67
123
  }
68
- _inherits(VideoViewer, _BaseViewer);
69
- return _createClass(VideoViewer, [{
124
+ _inherits(_VideoViewer, _BaseViewer);
125
+ return _createClass(_VideoViewer, [{
126
+ key: "componentDidMount",
127
+ value: function componentDidMount() {
128
+ _superPropGet(_VideoViewer, "componentDidMount", this, 3)([]);
129
+ if (this.props.isInsetViewer) {
130
+ var _this$props$setHasVid, _this$props3;
131
+ (_this$props$setHasVid = (_this$props3 = this.props).setHasVideoControls) === null || _this$props$setHasVid === void 0 || _this$props$setHasVid.call(_this$props3, true);
132
+ }
133
+ }
134
+ }, {
135
+ key: "componentWillUnmount",
136
+ value: function componentWillUnmount() {
137
+ if (this.props.isInsetViewer) {
138
+ var _this$props$setHasVid2, _this$props4;
139
+ (_this$props$setHasVid2 = (_this$props4 = this.props).setHasVideoControls) === null || _this$props$setHasVid2 === void 0 || _this$props$setHasVid2.call(_this$props4, false);
140
+ }
141
+ _superPropGet(_VideoViewer, "componentWillUnmount", this, 3)([]);
142
+ }
143
+ }, {
70
144
  key: "initialState",
71
145
  get: function get() {
72
146
  return {
@@ -76,17 +150,34 @@ export var VideoViewer = /*#__PURE__*/function (_BaseViewer) {
76
150
  }, {
77
151
  key: "renderSuccessful",
78
152
  value: function renderSuccessful(content) {
79
- var _this$props3 = this.props,
80
- item = _this$props3.item,
81
- showControls = _this$props3.showControls,
82
- previewCount = _this$props3.previewCount,
83
- identifier = _this$props3.identifier;
153
+ var _this$props5 = this.props,
154
+ item = _this$props5.item,
155
+ showControls = _this$props5.showControls,
156
+ previewCount = _this$props5.previewCount,
157
+ identifier = _this$props5.identifier,
158
+ isInsetViewer = _this$props5.isInsetViewer,
159
+ mediaFooterControls = _this$props5.mediaFooterControls;
84
160
  var useCustomVideoPlayer = !isIE();
85
161
  var isAutoPlay = previewCount === 0;
86
162
  var hdAvailable = isHDAvailable(item);
87
- return useCustomVideoPlayer ? /*#__PURE__*/React.createElement(CustomVideoPlayerWrapper, {
88
- "data-testid": "media-viewer-video-content"
89
- }, isFileIdentifier(identifier) && fg('platform_media_video_captions') ? /*#__PURE__*/React.createElement(MediaPlayer, {
163
+ if (!useCustomVideoPlayer) {
164
+ if (!isInsetViewer) {
165
+ return /*#__PURE__*/React.createElement(Video, {
166
+ autoPlay: isAutoPlay,
167
+ controls: true,
168
+ src: content
169
+ });
170
+ }
171
+ return /*#__PURE__*/React.createElement(CustomVideoPlayerWrapper, null, /*#__PURE__*/React.createElement(FittedVideoFrame, {
172
+ ref: this.setInsetVideoFrame
173
+ }, /*#__PURE__*/React.createElement(Video, {
174
+ autoPlay: isAutoPlay,
175
+ controls: true,
176
+ src: content,
177
+ onVideoElementChange: this.setInsetVideo
178
+ })));
179
+ }
180
+ var playerElement = isFileIdentifier(identifier) && fg('platform_media_video_captions') ? /*#__PURE__*/React.createElement(MediaPlayer, {
90
181
  identifier: identifier,
91
182
  type: "video",
92
183
  isAutoPlay: isAutoPlay,
@@ -99,6 +190,8 @@ export var VideoViewer = /*#__PURE__*/function (_BaseViewer) {
99
190
  onError: this.onError,
100
191
  onPlay: this.onPlay,
101
192
  onTimeChanged: this.onTimeChanged,
193
+ controlsPortalElement: mediaFooterControls,
194
+ onVideoElementChange: isInsetViewer ? this.setInsetVideo : undefined,
102
195
  lastWatchTimeConfig: {
103
196
  contentId: item.id
104
197
  }
@@ -115,24 +208,30 @@ export var VideoViewer = /*#__PURE__*/function (_BaseViewer) {
115
208
  onError: this.onError,
116
209
  onPlay: this.onPlay,
117
210
  onTimeChanged: this.onTimeChanged,
211
+ controlsPortalElement: mediaFooterControls,
212
+ onVideoElementChange: isInsetViewer ? this.setInsetVideo : undefined,
118
213
  lastWatchTimeConfig: {
119
214
  contentId: item.id
120
215
  }
121
- })) : /*#__PURE__*/React.createElement(Video, {
122
- autoPlay: isAutoPlay,
123
- controls: true,
124
- src: content
125
216
  });
217
+ var player = /*#__PURE__*/React.createElement(InsetViewerProvider, {
218
+ isInsetViewer: isInsetViewer
219
+ }, playerElement);
220
+ return /*#__PURE__*/React.createElement(CustomVideoPlayerWrapper, {
221
+ "data-testid": "media-viewer-video-content"
222
+ }, isInsetViewer ? /*#__PURE__*/React.createElement(FittedVideoFrame, {
223
+ ref: this.setInsetVideoFrame
224
+ }, player) : player);
126
225
  }
127
226
  }, {
128
227
  key: "init",
129
228
  value: function () {
130
229
  var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
131
- var _this$props4, mediaClient, item, collectionName, contentUrl, preferredArtifact, _t;
230
+ var _this$props6, mediaClient, item, collectionName, contentUrl, preferredArtifact, _t;
132
231
  return _regeneratorRuntime.wrap(function (_context) {
133
232
  while (1) switch (_context.prev = _context.next) {
134
233
  case 0:
135
- _this$props4 = this.props, mediaClient = _this$props4.mediaClient, item = _this$props4.item, collectionName = _this$props4.collectionName;
234
+ _this$props6 = this.props, mediaClient = _this$props6.mediaClient, item = _this$props6.item, collectionName = _this$props6.collectionName;
136
235
  _context.prev = 1;
137
236
  if (!(item.status === 'processed')) {
138
237
  _context.next = 7;
@@ -207,7 +306,11 @@ export var VideoViewer = /*#__PURE__*/function (_BaseViewer) {
207
306
  }()
208
307
  }, {
209
308
  key: "release",
210
- value: function release() {}
309
+ value: function release() {
310
+ this.unbindInsetVideoSize();
311
+ this.insetVideo = null;
312
+ this.insetVideoFrame = null;
313
+ }
211
314
  }]);
212
315
  }(BaseViewer);
213
316
  function isHDAvailable(file) {
@@ -215,4 +318,5 @@ function isHDAvailable(file) {
215
318
  return false;
216
319
  }
217
320
  return !!getArtifactUrl(file.artifacts, hdArtifact);
218
- }
321
+ }
322
+ export var VideoViewer = withInsetViewerFooter(_VideoViewer);
@@ -6,11 +6,14 @@ export declare const InsetViewerProvider: ({ isInsetViewer, children, }: {
6
6
  export declare const useIsInsetViewer: () => boolean;
7
7
  export declare const useMediaFooterControls: () => HTMLElement | null;
8
8
  export declare const useSetMediaFooterControls: () => ((element: HTMLElement | null) => void);
9
+ export declare const useHasMediaFooterVideoControls: () => boolean;
10
+ export declare const useSetHasMediaFooterVideoControls: () => ((hasVideoControls: boolean) => void);
9
11
  export type WithInsetViewerProps = {
10
12
  isInsetViewer?: boolean;
11
13
  };
12
14
  export declare const withInsetViewer: <Props, Component>(WrappedComponent: (React.ComponentType<WithInsetViewerProps & Props> | React.ForwardRefExoticComponent<WithInsetViewerProps & Props>) & Component) => React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.LibraryManagedAttributes<Component, Omit<Props, keyof WithInsetViewerProps>>> & React.RefAttributes<any>>;
13
15
  export type WithInsetViewerFooterProps = WithInsetViewerProps & {
14
16
  mediaFooterControls?: HTMLElement | null;
17
+ setHasVideoControls?: (hasVideoControls: boolean) => void;
15
18
  };
16
19
  export declare const withInsetViewerFooter: <Props, Component>(WrappedComponent: (React.ComponentType<WithInsetViewerFooterProps & Props> | React.ForwardRefExoticComponent<WithInsetViewerFooterProps & Props>) & Component) => React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.LibraryManagedAttributes<Component, Omit<Props, keyof WithInsetViewerFooterProps>>> & React.RefAttributes<any>>;
@@ -68,8 +68,9 @@ type VideoProps = {
68
68
  controls: boolean;
69
69
  src: string;
70
70
  autoPlay: boolean;
71
+ onVideoElementChange?: (video: HTMLVideoElement | null) => void;
71
72
  };
72
- export declare const Video: ({ autoPlay, controls, src }: VideoProps) => JSX.Element;
73
+ export declare const Video: ({ autoPlay, controls, src, onVideoElementChange, }: VideoProps) => JSX.Element;
73
74
  export declare const PDFWrapper: ForwardRefExoticComponent<DataTestID & Children & RefAttributes<HTMLDivElement>>;
74
75
  export declare const Arrow: ({ className, children }: ClassName & Children) => JSX.Element;
75
76
  export type LeftWrapperProps = {
@@ -135,7 +136,8 @@ export declare const AudioCover: ({ src, alt }: AudioCoverProps) => JSX.Element;
135
136
  export declare const DefaultCoverWrapper: ({ children }: Children) => JSX.Element;
136
137
  export declare const DownloadButtonWrapper: ({ children }: Children) => JSX.Element;
137
138
  type CustomVideoPlayerWrapperProps = DataTestID & Children;
138
- export declare const CustomVideoPlayerWrapper: ({ 'data-testid': datatestId, children, }: CustomVideoPlayerWrapperProps) => JSX.Element;
139
+ export declare const CustomVideoPlayerWrapper: ForwardRefExoticComponent<CustomVideoPlayerWrapperProps & RefAttributes<HTMLDivElement>>;
140
+ export declare const FittedVideoFrame: ForwardRefExoticComponent<Children & RefAttributes<HTMLDivElement>>;
139
141
  type SidebarWrapperProps = DataTestID & Children;
140
142
  export declare const SidebarWrapper: ({ 'data-testid': datatestId, children, }: SidebarWrapperProps) => JSX.Element;
141
143
  export declare const SpinnerWrapper: ({ children }: Children) => JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { Rectangle } from '@atlaskit/media-ui/rectangle';
2
+ export declare const insetFittedViewport: (el: HTMLElement) => Rectangle;
@@ -2,9 +2,8 @@ import React from 'react';
2
2
  import { type MediaClient, type FileState, type Identifier } from '@atlaskit/media-client';
3
3
  import { type MediaTraceContext } from '@atlaskit/media-common';
4
4
  import type { WithShowControlMethodProp } from '@atlaskit/media-ui/types';
5
- import { Outcome } from '../domain/outcome';
6
5
  import { MediaViewerError } from '../MediaViewerError';
7
- import { type BaseState, BaseViewer } from './base-viewer';
6
+ import { type BaseState } from './base-viewer';
8
7
  export type Props = Readonly<{
9
8
  identifier: Identifier;
10
9
  item: FileState;
@@ -18,15 +17,4 @@ export type Props = Readonly<{
18
17
  export type State = BaseState<string> & {
19
18
  coverUrl?: string;
20
19
  };
21
- export declare class VideoViewer extends BaseViewer<string, Props, State> {
22
- protected get initialState(): {
23
- content: Outcome<string, MediaViewerError>;
24
- };
25
- private onFirstPlay;
26
- private onPlay;
27
- private onTimeChanged;
28
- private onError;
29
- protected renderSuccessful(content: string): React.JSX.Element;
30
- protected init(): Promise<void>;
31
- protected release(): void;
32
- }
20
+ export declare const VideoViewer: React.ForwardRefExoticComponent<React.PropsWithoutRef<Props> & React.RefAttributes<any>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-viewer",
3
- "version": "54.11.0",
3
+ "version": "54.11.2",
4
4
  "description": "MediaViewer is Atlassian's powerful solution for viewing files on the web. It's both powerful and extendable yet easy-to-integrate",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -48,7 +48,7 @@
48
48
  "@atlaskit/media-document-viewer": "^2.2.0",
49
49
  "@atlaskit/media-state": "^4.0.0",
50
50
  "@atlaskit/media-svg": "^4.0.0",
51
- "@atlaskit/media-ui": "^31.1.0",
51
+ "@atlaskit/media-ui": "^31.3.0",
52
52
  "@atlaskit/menu": "^11.0.0",
53
53
  "@atlaskit/motion": "^9.3.0",
54
54
  "@atlaskit/platform-feature-experiments": "^0.3.0",
@@ -60,8 +60,8 @@
60
60
  "@atlaskit/spinner": "^20.4.0",
61
61
  "@atlaskit/textfield": "^10.2.0",
62
62
  "@atlaskit/theme": "^28.2.0",
63
- "@atlaskit/tmp-editor-statsig": "^221.0.0",
64
- "@atlaskit/tokens": "^20.2.0",
63
+ "@atlaskit/tmp-editor-statsig": "^223.0.0",
64
+ "@atlaskit/tokens": "^20.3.0",
65
65
  "@atlaskit/tooltip": "^24.4.0",
66
66
  "@atlaskit/ufo": "^2.0.0",
67
67
  "@babel/runtime": "^7.0.0",