@gravity-ui/page-constructor 1.9.0 → 1.9.1
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 +7 -0
- package/build/cjs/blocks/Tabs/Tabs.js +6 -1
- package/build/cjs/components/Media/Media.js +1 -1
- package/build/cjs/components/Media/Video/Video.js +4 -3
- package/build/cjs/components/ReactPlayer/ReactPlayer.d.ts +1 -0
- package/build/cjs/components/ReactPlayer/ReactPlayer.js +5 -5
- package/build/cjs/components/VideoBlock/VideoBlock.d.ts +2 -0
- package/build/cjs/components/VideoBlock/VideoBlock.js +7 -6
- package/build/esm/blocks/Tabs/Tabs.js +7 -2
- package/build/esm/components/Media/Media.js +1 -1
- package/build/esm/components/Media/Video/Video.js +4 -3
- package/build/esm/components/ReactPlayer/ReactPlayer.d.ts +1 -0
- package/build/esm/components/ReactPlayer/ReactPlayer.js +5 -5
- package/build/esm/components/VideoBlock/VideoBlock.d.ts +2 -0
- package/build/esm/components/VideoBlock/VideoBlock.js +6 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.9.1](https://github.com/gravity-ui/page-constructor/compare/v1.9.0...v1.9.1) (2022-12-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **Tabs:** player video height ([a372ddb](https://github.com/gravity-ui/page-constructor/commit/a372ddbbde003ef82818ba167adbff0e8bf57905))
|
|
9
|
+
|
|
3
10
|
## [1.9.0](https://github.com/gravity-ui/page-constructor/compare/v1.8.2...v1.9.0) (2022-12-05)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -13,14 +13,19 @@ const ThemeValueContext_1 = require("../../context/theme/ThemeValueContext");
|
|
|
13
13
|
const utils_2 = require("../../components/Media/Image/utils");
|
|
14
14
|
const ButtonTabs_1 = (0, tslib_1.__importDefault)(require("../../components/ButtonTabs/ButtonTabs"));
|
|
15
15
|
const sub_blocks_1 = require("../../sub-blocks");
|
|
16
|
+
const VideoBlock_1 = require("../../components/VideoBlock/VideoBlock");
|
|
16
17
|
const b = (0, utils_1.block)('tabs-block');
|
|
17
18
|
const TabsBlock = ({ items, title, description, animated, tabsColSizes, centered, direction = 'media-content', }) => {
|
|
19
|
+
var _a;
|
|
18
20
|
const [activeTab, setActiveTab] = (0, react_1.useState)(items[0].tabName);
|
|
19
21
|
const [play, setPlay] = (0, react_1.useState)(false);
|
|
20
22
|
const { themeValue: theme } = (0, react_1.useContext)(ThemeValueContext_1.ThemeValueContext);
|
|
21
23
|
const tabs = items.map(({ tabName }) => ({ title: tabName, id: tabName }));
|
|
22
24
|
const activeTabData = items.find(({ tabName }) => tabName === activeTab);
|
|
23
25
|
const isReverse = direction === 'content-media';
|
|
26
|
+
const ref = (0, react_1.useRef)(null);
|
|
27
|
+
const mediaWidth = (_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.offsetWidth;
|
|
28
|
+
const mediaHeight = mediaWidth && (0, VideoBlock_1.getHeight)(mediaWidth);
|
|
24
29
|
let imageProps;
|
|
25
30
|
if (activeTabData) {
|
|
26
31
|
const themedImage = (0, utils_1.getThemedValue)(activeTabData.image, theme);
|
|
@@ -40,7 +45,7 @@ const TabsBlock = ({ items, title, description, animated, tabsColSizes, centered
|
|
|
40
45
|
all: grid_1.GridColumnOrderClasses.Last,
|
|
41
46
|
md: grid_1.GridColumnOrderClasses.First,
|
|
42
47
|
}, className: b('col', { centered: centered }) },
|
|
43
|
-
(activeTabData === null || activeTabData === void 0 ? void 0 : activeTabData.media) && (react_1.default.createElement(Media_1.default, Object.assign({}, (0, utils_1.getThemedValue)(activeTabData.media, theme), { key: activeTab, className: b('media'), playVideo: play }))),
|
|
48
|
+
react_1.default.createElement("div", { ref: ref }, (activeTabData === null || activeTabData === void 0 ? void 0 : activeTabData.media) && (react_1.default.createElement(Media_1.default, Object.assign({}, (0, utils_1.getThemedValue)(activeTabData.media, theme), { key: activeTab, className: b('media'), playVideo: play, height: mediaHeight })))),
|
|
44
49
|
imageProps && (react_1.default.createElement(react_1.Fragment, null,
|
|
45
50
|
react_1.default.createElement(FullscreenImage_1.default, Object.assign({}, imageProps, { imageClassName: b('image') })),
|
|
46
51
|
(activeTabData === null || activeTabData === void 0 ? void 0 : activeTabData.caption) && (react_1.default.createElement("p", { className: b('caption') }, activeTabData.caption))))));
|
|
@@ -22,7 +22,7 @@ const Media = (props) => {
|
|
|
22
22
|
result.push(react_1.default.createElement(Video_1.default, { key: "video", video: video, videoClassName: videoClassName, height: height, metrika: metrika, playVideo: playVideo, previewImg: previewImg, playButton: playButton, customBarControlsClassName: customBarControlsClassName, hasVideoFallback: hasVideoFallback, setHasVideoFallback: setHasVideoFallback }));
|
|
23
23
|
}
|
|
24
24
|
if (youtube) {
|
|
25
|
-
result = (react_1.default.createElement(VideoBlock_1.default, { className: b('youtube', youtubeClassName), record: youtube, attributes: { color: 'white', rel: '0' }, previewImg: previewImg }));
|
|
25
|
+
result = (react_1.default.createElement(VideoBlock_1.default, { className: b('youtube', youtubeClassName), record: youtube, attributes: { color: 'white', rel: '0' }, previewImg: previewImg, height: height }));
|
|
26
26
|
}
|
|
27
27
|
if (dataLens) {
|
|
28
28
|
result = react_1.default.createElement(DataLens_1.default, { dataLens: dataLens });
|
|
@@ -31,15 +31,16 @@ const Video = (props) => {
|
|
|
31
31
|
}, [playVideo, video, setHasVideoFallback]);
|
|
32
32
|
const reactPlayerBlock = (0, react_1.useMemo)(() => {
|
|
33
33
|
const { src, loop, controls, muted, autoplay = true, elapsedTime, playButton } = video;
|
|
34
|
-
return (react_1.default.createElement(ReactPlayer_1.default, { className: b('react-player', videoClassName), src: src, previewImgUrl: previewImg, loop: Boolean(loop), controls: controls, muted: muted, autoplay: autoplay && playVideo, elapsedTime: elapsedTime, playButton: playButton || commonPlayButton, customBarControlsClassName: customBarControlsClassName, metrika: metrika }));
|
|
34
|
+
return (react_1.default.createElement(ReactPlayer_1.default, { className: b('react-player', videoClassName), src: src, previewImgUrl: previewImg, loop: Boolean(loop), controls: controls, muted: muted, autoplay: autoplay && playVideo, elapsedTime: elapsedTime, playButton: playButton || commonPlayButton, customBarControlsClassName: customBarControlsClassName, metrika: metrika, height: height }));
|
|
35
35
|
}, [
|
|
36
36
|
video,
|
|
37
|
-
|
|
37
|
+
height,
|
|
38
|
+
videoClassName,
|
|
38
39
|
previewImg,
|
|
39
40
|
playVideo,
|
|
40
|
-
videoClassName,
|
|
41
41
|
commonPlayButton,
|
|
42
42
|
customBarControlsClassName,
|
|
43
|
+
metrika,
|
|
43
44
|
]);
|
|
44
45
|
const defaultVideoBlock = (0, react_1.useMemo)(() => {
|
|
45
46
|
return video.src.length && !hasVideoFallback ? (react_1.default.createElement("div", { className: b('wrap', videoClassName), style: { height } },
|
|
@@ -7,6 +7,7 @@ export interface ReactPlayerBlockProps extends Omit<MediaVideoProps, 'loop' | 's
|
|
|
7
7
|
customBarControlsClassName?: string;
|
|
8
8
|
showPreview?: boolean;
|
|
9
9
|
onClickPreview?: () => void;
|
|
10
|
+
height?: number;
|
|
10
11
|
children?: React.ReactNode;
|
|
11
12
|
}
|
|
12
13
|
export declare const ReactPlayerBlock: React.ForwardRefExoticComponent<ReactPlayerBlockProps & React.RefAttributes<ReactPlayerBlockHandler>>;
|
|
@@ -19,7 +19,7 @@ const FPS = 60;
|
|
|
19
19
|
exports.ReactPlayerBlock = react_1.default.forwardRef((props, originRef) => {
|
|
20
20
|
const isMobile = (0, react_1.useContext)(mobileContext_1.MobileContext);
|
|
21
21
|
const { metrika } = (0, react_1.useContext)(metrikaContext_1.MetrikaContext);
|
|
22
|
-
const { src, previewImgUrl, loop = false, controls = models_1.MediaVideoControlsType.Default, muted: initiallyMuted = false, elapsedTime, playButton, className, customBarControlsClassName, showPreview, onClickPreview, metrika: videoMetrika, } = props;
|
|
22
|
+
const { src, previewImgUrl, loop = false, controls = models_1.MediaVideoControlsType.Default, muted: initiallyMuted = false, elapsedTime, playButton, className, customBarControlsClassName, showPreview, onClickPreview, metrika: videoMetrika, height, } = props;
|
|
23
23
|
const { type = models_1.PlayButtonType.Default, theme = models_1.PlayButtonThemes.Blue, text, className: buttonClassName, } = playButton || {};
|
|
24
24
|
const autoPlay = Boolean(!isMobile && !previewImgUrl && props.autoplay);
|
|
25
25
|
const mute = initiallyMuted || autoPlay;
|
|
@@ -28,7 +28,7 @@ exports.ReactPlayerBlock = react_1.default.forwardRef((props, originRef) => {
|
|
|
28
28
|
const [playerRef, setPlayerRef] = (0, react_1.useState)();
|
|
29
29
|
const [isPlaying, setIsPlaying] = (0, react_1.useState)(autoPlay);
|
|
30
30
|
const [playedPercent, setPlayedPercent] = (0, react_1.useState)(0);
|
|
31
|
-
const [
|
|
31
|
+
const [currentHeight, setCurrentHeight] = (0, react_1.useState)(height);
|
|
32
32
|
const [width, setWidth] = (0, react_1.useState)(0);
|
|
33
33
|
const [muted, setMuted] = (0, react_1.useState)(mute);
|
|
34
34
|
const [started, setStarted] = (0, react_1.useState)(autoPlay);
|
|
@@ -73,7 +73,7 @@ exports.ReactPlayerBlock = react_1.default.forwardRef((props, originRef) => {
|
|
|
73
73
|
parseFloat(paddingLeft) -
|
|
74
74
|
parseFloat(paddingRight);
|
|
75
75
|
setWidth(newWidth);
|
|
76
|
-
|
|
76
|
+
setCurrentHeight(Math.floor(getHeight(newWidth)));
|
|
77
77
|
}
|
|
78
78
|
}, 200);
|
|
79
79
|
updateSize();
|
|
@@ -179,8 +179,8 @@ exports.ReactPlayerBlock = react_1.default.forwardRef((props, originRef) => {
|
|
|
179
179
|
},
|
|
180
180
|
}, elapsedTimePercent: elapsedTimePercent }));
|
|
181
181
|
}, [controls, isPlaying, customBarControlsClassName, changeMute]);
|
|
182
|
-
return (react_1.default.createElement("div", { className: b({ wrapper: !
|
|
183
|
-
react_1.default.createElement(react_player_1.default, { className: b('player'), url: src, muted: muted, controls: controls === models_1.MediaVideoControlsType.Default, height:
|
|
182
|
+
return (react_1.default.createElement("div", { className: b({ wrapper: !currentHeight }, className), ref: ref, onClick: handleClick },
|
|
183
|
+
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 }),
|
|
184
184
|
renderCustomBarControls(muted, playedPercent)));
|
|
185
185
|
});
|
|
186
186
|
function getHeight(width) {
|
|
@@ -3,6 +3,7 @@ export declare const AUTOPLAY_ATTRIBUTES: {
|
|
|
3
3
|
autoplay: number;
|
|
4
4
|
mute: number;
|
|
5
5
|
};
|
|
6
|
+
export declare function getHeight(width: number): number;
|
|
6
7
|
export interface VideoBlockProps {
|
|
7
8
|
id?: string;
|
|
8
9
|
stream?: string;
|
|
@@ -11,6 +12,7 @@ export interface VideoBlockProps {
|
|
|
11
12
|
className?: string;
|
|
12
13
|
previewImg?: string;
|
|
13
14
|
playButton?: React.ReactNode;
|
|
15
|
+
height?: number;
|
|
14
16
|
}
|
|
15
17
|
declare const VideoBlock: (props: VideoBlockProps) => JSX.Element | null;
|
|
16
18
|
export default VideoBlock;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AUTOPLAY_ATTRIBUTES = void 0;
|
|
3
|
+
exports.getHeight = exports.AUTOPLAY_ATTRIBUTES = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = (0, tslib_1.__importStar)(require("react"));
|
|
6
6
|
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
@@ -36,14 +36,15 @@ function getVideoSrc(stream, record) {
|
|
|
36
36
|
function getHeight(width) {
|
|
37
37
|
return (width / 16) * 9;
|
|
38
38
|
}
|
|
39
|
+
exports.getHeight = getHeight;
|
|
39
40
|
const VideoBlock = (props) => {
|
|
40
|
-
const { stream, record, attributes, className, id, previewImg, playButton } = props;
|
|
41
|
+
const { stream, record, attributes, className, id, previewImg, playButton, height } = props;
|
|
41
42
|
const src = getVideoSrc(stream, record);
|
|
42
43
|
const ref = (0, react_1.useRef)(null);
|
|
43
44
|
const iframeRef = (0, react_1.useRef)();
|
|
44
45
|
const [hidePreview, setHidePreview] = (0, react_1.useState)(false);
|
|
45
46
|
const norender = (!stream && !record) || !src;
|
|
46
|
-
const [
|
|
47
|
+
const [currentHeight, setCurrentHeight] = (0, react_1.useState)(height || undefined);
|
|
47
48
|
const fullId = `${iframeId}-${id || src}`;
|
|
48
49
|
const onPreviewClick = (0, react_1.useCallback)(() => {
|
|
49
50
|
if (iframeRef.current) {
|
|
@@ -53,14 +54,14 @@ const VideoBlock = (props) => {
|
|
|
53
54
|
}, [src, attributes]);
|
|
54
55
|
(0, react_1.useEffect)(() => {
|
|
55
56
|
const updateSize = lodash_1.default.debounce(() => {
|
|
56
|
-
|
|
57
|
+
setCurrentHeight(ref.current ? Math.round(getHeight(ref.current.offsetWidth)) : undefined);
|
|
57
58
|
}, 100);
|
|
58
59
|
updateSize();
|
|
59
60
|
window.addEventListener('resize', updateSize);
|
|
60
61
|
return () => {
|
|
61
62
|
window.removeEventListener('resize', updateSize);
|
|
62
63
|
};
|
|
63
|
-
}, []);
|
|
64
|
+
}, [height]);
|
|
64
65
|
(0, react_1.useEffect)(() => {
|
|
65
66
|
if (norender) {
|
|
66
67
|
return;
|
|
@@ -89,7 +90,7 @@ const VideoBlock = (props) => {
|
|
|
89
90
|
if (norender) {
|
|
90
91
|
return null;
|
|
91
92
|
}
|
|
92
|
-
return (react_1.default.createElement("div", { className: b(null, className), ref: ref, style: { height } }, previewImg && !hidePreview && (react_1.default.createElement("div", { className: b('preview'), onClick: onPreviewClick },
|
|
93
|
+
return (react_1.default.createElement("div", { className: b(null, className), ref: ref, style: { height: currentHeight } }, previewImg && !hidePreview && (react_1.default.createElement("div", { className: b('preview'), onClick: onPreviewClick },
|
|
93
94
|
react_1.default.createElement(Image_1.default, { src: previewImg, className: b('image') }),
|
|
94
95
|
playButton || (react_1.default.createElement("button", { className: b('button') },
|
|
95
96
|
react_1.default.createElement(uikit_1.Icon, { className: b('icon'), data: icons_1.PlayVideo, size: 24 })))))));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Fragment, useContext, useState } from 'react';
|
|
1
|
+
import React, { Fragment, useContext, useRef, useState } from 'react';
|
|
2
2
|
import { block, getThemedValue } from '../../utils';
|
|
3
3
|
import { Row, Col, GridColumnOrderClasses } from '../../grid';
|
|
4
4
|
import AnimateBlock from '../../components/AnimateBlock/AnimateBlock';
|
|
@@ -9,15 +9,20 @@ import { ThemeValueContext } from '../../context/theme/ThemeValueContext';
|
|
|
9
9
|
import { getMediaImage } from '../../components/Media/Image/utils';
|
|
10
10
|
import ButtonTabs from '../../components/ButtonTabs/ButtonTabs';
|
|
11
11
|
import { Content } from '../../sub-blocks';
|
|
12
|
+
import { getHeight } from '../../components/VideoBlock/VideoBlock';
|
|
12
13
|
import './Tabs.css';
|
|
13
14
|
const b = block('tabs-block');
|
|
14
15
|
export const TabsBlock = ({ items, title, description, animated, tabsColSizes, centered, direction = 'media-content', }) => {
|
|
16
|
+
var _a;
|
|
15
17
|
const [activeTab, setActiveTab] = useState(items[0].tabName);
|
|
16
18
|
const [play, setPlay] = useState(false);
|
|
17
19
|
const { themeValue: theme } = useContext(ThemeValueContext);
|
|
18
20
|
const tabs = items.map(({ tabName }) => ({ title: tabName, id: tabName }));
|
|
19
21
|
const activeTabData = items.find(({ tabName }) => tabName === activeTab);
|
|
20
22
|
const isReverse = direction === 'content-media';
|
|
23
|
+
const ref = useRef(null);
|
|
24
|
+
const mediaWidth = (_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.offsetWidth;
|
|
25
|
+
const mediaHeight = mediaWidth && getHeight(mediaWidth);
|
|
21
26
|
let imageProps;
|
|
22
27
|
if (activeTabData) {
|
|
23
28
|
const themedImage = getThemedValue(activeTabData.image, theme);
|
|
@@ -37,7 +42,7 @@ export const TabsBlock = ({ items, title, description, animated, tabsColSizes, c
|
|
|
37
42
|
all: GridColumnOrderClasses.Last,
|
|
38
43
|
md: GridColumnOrderClasses.First,
|
|
39
44
|
}, className: b('col', { centered: centered }) },
|
|
40
|
-
(activeTabData === null || activeTabData === void 0 ? void 0 : activeTabData.media) && (React.createElement(Media, Object.assign({}, getThemedValue(activeTabData.media, theme), { key: activeTab, className: b('media'), playVideo: play }))),
|
|
45
|
+
React.createElement("div", { ref: ref }, (activeTabData === null || activeTabData === void 0 ? void 0 : activeTabData.media) && (React.createElement(Media, Object.assign({}, getThemedValue(activeTabData.media, theme), { key: activeTab, className: b('media'), playVideo: play, height: mediaHeight })))),
|
|
41
46
|
imageProps && (React.createElement(Fragment, null,
|
|
42
47
|
React.createElement(FullScreenImage, Object.assign({}, imageProps, { imageClassName: b('image') })),
|
|
43
48
|
(activeTabData === null || activeTabData === void 0 ? void 0 : activeTabData.caption) && (React.createElement("p", { className: b('caption') }, activeTabData.caption))))));
|
|
@@ -19,7 +19,7 @@ export const Media = (props) => {
|
|
|
19
19
|
result.push(React.createElement(Video, { key: "video", video: video, videoClassName: videoClassName, height: height, metrika: metrika, playVideo: playVideo, previewImg: previewImg, playButton: playButton, customBarControlsClassName: customBarControlsClassName, hasVideoFallback: hasVideoFallback, setHasVideoFallback: setHasVideoFallback }));
|
|
20
20
|
}
|
|
21
21
|
if (youtube) {
|
|
22
|
-
result = (React.createElement(YoutubeBlock, { className: b('youtube', youtubeClassName), record: youtube, attributes: { color: 'white', rel: '0' }, previewImg: previewImg }));
|
|
22
|
+
result = (React.createElement(YoutubeBlock, { className: b('youtube', youtubeClassName), record: youtube, attributes: { color: 'white', rel: '0' }, previewImg: previewImg, height: height }));
|
|
23
23
|
}
|
|
24
24
|
if (dataLens) {
|
|
25
25
|
result = React.createElement(DataLens, { dataLens: dataLens });
|
|
@@ -29,15 +29,16 @@ const Video = (props) => {
|
|
|
29
29
|
}, [playVideo, video, setHasVideoFallback]);
|
|
30
30
|
const reactPlayerBlock = useMemo(() => {
|
|
31
31
|
const { src, loop, controls, muted, autoplay = true, elapsedTime, playButton } = video;
|
|
32
|
-
return (React.createElement(ReactPlayerBlock, { className: b('react-player', videoClassName), src: src, previewImgUrl: previewImg, loop: Boolean(loop), controls: controls, muted: muted, autoplay: autoplay && playVideo, elapsedTime: elapsedTime, playButton: playButton || commonPlayButton, customBarControlsClassName: customBarControlsClassName, metrika: metrika }));
|
|
32
|
+
return (React.createElement(ReactPlayerBlock, { className: b('react-player', videoClassName), src: src, previewImgUrl: previewImg, loop: Boolean(loop), controls: controls, muted: muted, autoplay: autoplay && playVideo, elapsedTime: elapsedTime, playButton: playButton || commonPlayButton, customBarControlsClassName: customBarControlsClassName, metrika: metrika, height: height }));
|
|
33
33
|
}, [
|
|
34
34
|
video,
|
|
35
|
-
|
|
35
|
+
height,
|
|
36
|
+
videoClassName,
|
|
36
37
|
previewImg,
|
|
37
38
|
playVideo,
|
|
38
|
-
videoClassName,
|
|
39
39
|
commonPlayButton,
|
|
40
40
|
customBarControlsClassName,
|
|
41
|
+
metrika,
|
|
41
42
|
]);
|
|
42
43
|
const defaultVideoBlock = useMemo(() => {
|
|
43
44
|
return video.src.length && !hasVideoFallback ? (React.createElement("div", { className: b('wrap', videoClassName), style: { height } },
|
|
@@ -8,6 +8,7 @@ export interface ReactPlayerBlockProps extends Omit<MediaVideoProps, 'loop' | 's
|
|
|
8
8
|
customBarControlsClassName?: string;
|
|
9
9
|
showPreview?: boolean;
|
|
10
10
|
onClickPreview?: () => void;
|
|
11
|
+
height?: number;
|
|
11
12
|
children?: React.ReactNode;
|
|
12
13
|
}
|
|
13
14
|
export declare const ReactPlayerBlock: React.ForwardRefExoticComponent<ReactPlayerBlockProps & React.RefAttributes<ReactPlayerBlockHandler>>;
|
|
@@ -16,7 +16,7 @@ const FPS = 60;
|
|
|
16
16
|
export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
|
|
17
17
|
const isMobile = useContext(MobileContext);
|
|
18
18
|
const { metrika } = useContext(MetrikaContext);
|
|
19
|
-
const { src, previewImgUrl, loop = false, controls = MediaVideoControlsType.Default, muted: initiallyMuted = false, elapsedTime, playButton, className, customBarControlsClassName, showPreview, onClickPreview, metrika: videoMetrika, } = props;
|
|
19
|
+
const { src, previewImgUrl, loop = false, controls = MediaVideoControlsType.Default, muted: initiallyMuted = false, elapsedTime, playButton, className, customBarControlsClassName, showPreview, onClickPreview, metrika: videoMetrika, height, } = props;
|
|
20
20
|
const { type = PlayButtonType.Default, theme = PlayButtonThemes.Blue, text, className: buttonClassName, } = playButton || {};
|
|
21
21
|
const autoPlay = Boolean(!isMobile && !previewImgUrl && props.autoplay);
|
|
22
22
|
const mute = initiallyMuted || autoPlay;
|
|
@@ -25,7 +25,7 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
|
|
|
25
25
|
const [playerRef, setPlayerRef] = useState();
|
|
26
26
|
const [isPlaying, setIsPlaying] = useState(autoPlay);
|
|
27
27
|
const [playedPercent, setPlayedPercent] = useState(0);
|
|
28
|
-
const [
|
|
28
|
+
const [currentHeight, setCurrentHeight] = useState(height);
|
|
29
29
|
const [width, setWidth] = useState(0);
|
|
30
30
|
const [muted, setMuted] = useState(mute);
|
|
31
31
|
const [started, setStarted] = useState(autoPlay);
|
|
@@ -70,7 +70,7 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
|
|
|
70
70
|
parseFloat(paddingLeft) -
|
|
71
71
|
parseFloat(paddingRight);
|
|
72
72
|
setWidth(newWidth);
|
|
73
|
-
|
|
73
|
+
setCurrentHeight(Math.floor(getHeight(newWidth)));
|
|
74
74
|
}
|
|
75
75
|
}, 200);
|
|
76
76
|
updateSize();
|
|
@@ -176,8 +176,8 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
|
|
|
176
176
|
},
|
|
177
177
|
}, elapsedTimePercent: elapsedTimePercent }));
|
|
178
178
|
}, [controls, isPlaying, customBarControlsClassName, changeMute]);
|
|
179
|
-
return (React.createElement("div", { className: b({ wrapper: !
|
|
180
|
-
React.createElement(ReactPlayer, { className: b('player'), url: src, muted: muted, controls: controls === MediaVideoControlsType.Default, height:
|
|
179
|
+
return (React.createElement("div", { className: b({ wrapper: !currentHeight }, className), ref: ref, onClick: handleClick },
|
|
180
|
+
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 }),
|
|
181
181
|
renderCustomBarControls(muted, playedPercent)));
|
|
182
182
|
});
|
|
183
183
|
function getHeight(width) {
|
|
@@ -4,6 +4,7 @@ export declare const AUTOPLAY_ATTRIBUTES: {
|
|
|
4
4
|
autoplay: number;
|
|
5
5
|
mute: number;
|
|
6
6
|
};
|
|
7
|
+
export declare function getHeight(width: number): number;
|
|
7
8
|
export interface VideoBlockProps {
|
|
8
9
|
id?: string;
|
|
9
10
|
stream?: string;
|
|
@@ -12,6 +13,7 @@ export interface VideoBlockProps {
|
|
|
12
13
|
className?: string;
|
|
13
14
|
previewImg?: string;
|
|
14
15
|
playButton?: React.ReactNode;
|
|
16
|
+
height?: number;
|
|
15
17
|
}
|
|
16
18
|
declare const VideoBlock: (props: VideoBlockProps) => JSX.Element | null;
|
|
17
19
|
export default VideoBlock;
|
|
@@ -30,17 +30,17 @@ function getVideoSrc(stream, record) {
|
|
|
30
30
|
}
|
|
31
31
|
return src;
|
|
32
32
|
}
|
|
33
|
-
function getHeight(width) {
|
|
33
|
+
export function getHeight(width) {
|
|
34
34
|
return (width / 16) * 9;
|
|
35
35
|
}
|
|
36
36
|
const VideoBlock = (props) => {
|
|
37
|
-
const { stream, record, attributes, className, id, previewImg, playButton } = props;
|
|
37
|
+
const { stream, record, attributes, className, id, previewImg, playButton, height } = props;
|
|
38
38
|
const src = getVideoSrc(stream, record);
|
|
39
39
|
const ref = useRef(null);
|
|
40
40
|
const iframeRef = useRef();
|
|
41
41
|
const [hidePreview, setHidePreview] = useState(false);
|
|
42
42
|
const norender = (!stream && !record) || !src;
|
|
43
|
-
const [
|
|
43
|
+
const [currentHeight, setCurrentHeight] = useState(height || undefined);
|
|
44
44
|
const fullId = `${iframeId}-${id || src}`;
|
|
45
45
|
const onPreviewClick = useCallback(() => {
|
|
46
46
|
if (iframeRef.current) {
|
|
@@ -50,14 +50,14 @@ const VideoBlock = (props) => {
|
|
|
50
50
|
}, [src, attributes]);
|
|
51
51
|
useEffect(() => {
|
|
52
52
|
const updateSize = _.debounce(() => {
|
|
53
|
-
|
|
53
|
+
setCurrentHeight(ref.current ? Math.round(getHeight(ref.current.offsetWidth)) : undefined);
|
|
54
54
|
}, 100);
|
|
55
55
|
updateSize();
|
|
56
56
|
window.addEventListener('resize', updateSize);
|
|
57
57
|
return () => {
|
|
58
58
|
window.removeEventListener('resize', updateSize);
|
|
59
59
|
};
|
|
60
|
-
}, []);
|
|
60
|
+
}, [height]);
|
|
61
61
|
useEffect(() => {
|
|
62
62
|
if (norender) {
|
|
63
63
|
return;
|
|
@@ -86,7 +86,7 @@ const VideoBlock = (props) => {
|
|
|
86
86
|
if (norender) {
|
|
87
87
|
return null;
|
|
88
88
|
}
|
|
89
|
-
return (React.createElement("div", { className: b(null, className), ref: ref, style: { height } }, previewImg && !hidePreview && (React.createElement("div", { className: b('preview'), onClick: onPreviewClick },
|
|
89
|
+
return (React.createElement("div", { className: b(null, className), ref: ref, style: { height: currentHeight } }, previewImg && !hidePreview && (React.createElement("div", { className: b('preview'), onClick: onPreviewClick },
|
|
90
90
|
React.createElement(Image, { src: previewImg, className: b('image') }),
|
|
91
91
|
playButton || (React.createElement("button", { className: b('button') },
|
|
92
92
|
React.createElement(Icon, { className: b('icon'), data: PlayVideo, size: 24 })))))));
|