@gravity-ui/page-constructor 2.1.1 → 2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.0](https://github.com/gravity-ui/page-constructor/compare/v2.1.1...v2.2.0) (2023-03-29)
4
+
5
+
6
+ ### Features
7
+
8
+ * dropdown a ReactPlayer version ([#254](https://github.com/gravity-ui/page-constructor/issues/254)) ([fec1c3f](https://github.com/gravity-ui/page-constructor/commit/fec1c3fee50dcd86d08c0501f80d7aca0795e026))
9
+
3
10
  ## [2.1.1](https://github.com/gravity-ui/page-constructor/compare/v2.1.0...v2.1.1) (2023-03-28)
4
11
 
5
12
 
@@ -14,6 +14,7 @@ const metrikaContext_1 = require("../../context/metrikaContext");
14
14
  const mobileContext_1 = require("../../context/mobileContext");
15
15
  const hooks_1 = require("../../hooks");
16
16
  const icons_1 = require("../../icons");
17
+ const utils_2 = require("./utils");
17
18
  const b = (0, utils_1.block)('ReactPlayer');
18
19
  const FPS = 60;
19
20
  // eslint-disable-next-line react/display-name
@@ -35,6 +36,7 @@ exports.ReactPlayerBlock = react_1.default.forwardRef((props, originRef) => {
35
36
  const [started, setStarted] = (0, react_1.useState)(autoPlay);
36
37
  const [paused, setPaused] = (0, react_1.useState)(false);
37
38
  const [ended, setEnded] = (0, react_1.useState)(false);
39
+ const videoSrc = (0, react_1.useMemo)(() => (0, utils_2.checkYoutubeVideos)(src), [src]);
38
40
  const eventsArray = (0, react_1.useMemo)(() => {
39
41
  if (analyticsEvents) {
40
42
  return Array.isArray(analyticsEvents) ? analyticsEvents : [analyticsEvents];
@@ -193,7 +195,7 @@ exports.ReactPlayerBlock = react_1.default.forwardRef((props, originRef) => {
193
195
  }, elapsedTimePercent: elapsedTimePercent }));
194
196
  }, [controls, isPlaying, customBarControlsClassName, changeMute]);
195
197
  return (react_1.default.createElement("div", { className: b({ wrapper: !currentHeight }, className), ref: ref, onClick: handleClick },
196
- react_1.default.createElement(react_player_1.default, { className: b('player'), url: src, muted: muted, controls: controls === models_1.MediaVideoControlsType.Default, height: currentHeight || '100%', width: width || '100%', light: previewImgUrl, playing: isPlaying, playIcon: playIcon, progressInterval: FPS, onClickPreview: handleClickPreview, onStart: onStart, onReady: setPlayerRef, onPlay: onPlay, onPause: onPause, onProgress: onProgress, onEnded: onEnded }),
198
+ react_1.default.createElement(react_player_1.default, { className: b('player'), url: videoSrc, muted: muted, controls: controls === models_1.MediaVideoControlsType.Default, height: currentHeight || '100%', width: width || '100%', light: previewImgUrl, playing: isPlaying, playIcon: playIcon, progressInterval: FPS, onClickPreview: handleClickPreview, onStart: onStart, onReady: setPlayerRef, onPlay: onPlay, onPause: onPause, onProgress: onProgress, onEnded: onEnded }),
197
199
  renderCustomBarControls(muted, playedPercent)));
198
200
  });
199
201
  function getHeight(width) {
@@ -0,0 +1 @@
1
+ export declare const checkYoutubeVideos: (src: string | string[]) => string | string[];
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkYoutubeVideos = void 0;
4
+ // the file serves to support live video with react-player@2.9
5
+ const LIVE_YUOTUBE_VIDEO_REGEX = /(?:youtu\.be\/live\/|youtube(?:-nocookie)?\.com\/(?:live\/))((\w|-){11})/;
6
+ const YOUTUBE_VIDEO_TEMPLATE = 'https://www.youtube.com/watch?v=';
7
+ const checkYoutubeVideos = (src) => {
8
+ if (Array.isArray(src)) {
9
+ return src.map((videoUrl) => {
10
+ var _a;
11
+ if (LIVE_YUOTUBE_VIDEO_REGEX.test(videoUrl)) {
12
+ const youtubeLiveId = (_a = videoUrl.match(LIVE_YUOTUBE_VIDEO_REGEX)) === null || _a === void 0 ? void 0 : _a[1];
13
+ if (!youtubeLiveId) {
14
+ return videoUrl;
15
+ }
16
+ return `${YOUTUBE_VIDEO_TEMPLATE}${youtubeLiveId}`;
17
+ }
18
+ return videoUrl;
19
+ });
20
+ }
21
+ return src;
22
+ };
23
+ exports.checkYoutubeVideos = checkYoutubeVideos;
@@ -10,6 +10,7 @@ import { MetrikaContext } from '../../context/metrikaContext';
10
10
  import { MobileContext } from '../../context/mobileContext';
11
11
  import { useAnalytics } from '../../hooks';
12
12
  import { PlayVideo } from '../../icons';
13
+ import { checkYoutubeVideos } from './utils';
13
14
  import './ReactPlayer.css';
14
15
  const b = block('ReactPlayer');
15
16
  const FPS = 60;
@@ -32,6 +33,7 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
32
33
  const [started, setStarted] = useState(autoPlay);
33
34
  const [paused, setPaused] = useState(false);
34
35
  const [ended, setEnded] = useState(false);
36
+ const videoSrc = useMemo(() => checkYoutubeVideos(src), [src]);
35
37
  const eventsArray = useMemo(() => {
36
38
  if (analyticsEvents) {
37
39
  return Array.isArray(analyticsEvents) ? analyticsEvents : [analyticsEvents];
@@ -190,7 +192,7 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
190
192
  }, elapsedTimePercent: elapsedTimePercent }));
191
193
  }, [controls, isPlaying, customBarControlsClassName, changeMute]);
192
194
  return (React.createElement("div", { className: b({ wrapper: !currentHeight }, className), ref: ref, onClick: handleClick },
193
- React.createElement(ReactPlayer, { className: b('player'), url: src, muted: muted, controls: controls === MediaVideoControlsType.Default, height: currentHeight || '100%', width: width || '100%', light: previewImgUrl, playing: isPlaying, playIcon: playIcon, progressInterval: FPS, onClickPreview: handleClickPreview, onStart: onStart, onReady: setPlayerRef, onPlay: onPlay, onPause: onPause, onProgress: onProgress, onEnded: onEnded }),
195
+ React.createElement(ReactPlayer, { className: b('player'), url: videoSrc, muted: muted, controls: controls === MediaVideoControlsType.Default, height: currentHeight || '100%', width: width || '100%', light: previewImgUrl, playing: isPlaying, playIcon: playIcon, progressInterval: FPS, onClickPreview: handleClickPreview, onStart: onStart, onReady: setPlayerRef, onPlay: onPlay, onPause: onPause, onProgress: onProgress, onEnded: onEnded }),
194
196
  renderCustomBarControls(muted, playedPercent)));
195
197
  });
196
198
  function getHeight(width) {
@@ -0,0 +1 @@
1
+ export declare const checkYoutubeVideos: (src: string | string[]) => string | string[];
@@ -0,0 +1,19 @@
1
+ // the file serves to support live video with react-player@2.9
2
+ const LIVE_YUOTUBE_VIDEO_REGEX = /(?:youtu\.be\/live\/|youtube(?:-nocookie)?\.com\/(?:live\/))((\w|-){11})/;
3
+ const YOUTUBE_VIDEO_TEMPLATE = 'https://www.youtube.com/watch?v=';
4
+ export const checkYoutubeVideos = (src) => {
5
+ if (Array.isArray(src)) {
6
+ return src.map((videoUrl) => {
7
+ var _a;
8
+ if (LIVE_YUOTUBE_VIDEO_REGEX.test(videoUrl)) {
9
+ const youtubeLiveId = (_a = videoUrl.match(LIVE_YUOTUBE_VIDEO_REGEX)) === null || _a === void 0 ? void 0 : _a[1];
10
+ if (!youtubeLiveId) {
11
+ return videoUrl;
12
+ }
13
+ return `${YOUTUBE_VIDEO_TEMPLATE}${youtubeLiveId}`;
14
+ }
15
+ return videoUrl;
16
+ });
17
+ }
18
+ return src;
19
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -50,7 +50,7 @@
50
50
  "bem-cn-lite": "^4.0.0",
51
51
  "github-buttons": "2.23.0",
52
52
  "lodash": "^4.17.21",
53
- "react-player": "^2.12.0",
53
+ "react-player": "^2.9.0",
54
54
  "react-slick": "^0.28.1",
55
55
  "react-spring": "^9.3.0",
56
56
  "react-transition-group": "^4.4.2",