@gravity-ui/page-constructor 4.18.1 → 4.18.2-alpha.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.
Files changed (41) hide show
  1. package/README.md +5 -1
  2. package/build/cjs/components/Media/Media.js +3 -1
  3. package/build/cjs/components/Media/Video/Video.js +3 -2
  4. package/build/cjs/components/ReactPlayer/CustomBarControls.css +45 -24
  5. package/build/cjs/components/ReactPlayer/CustomBarControls.d.ts +3 -2
  6. package/build/cjs/components/ReactPlayer/CustomBarControls.js +29 -17
  7. package/build/cjs/components/ReactPlayer/ReactPlayer.css +2 -16
  8. package/build/cjs/components/ReactPlayer/ReactPlayer.d.ts +1 -0
  9. package/build/cjs/components/ReactPlayer/ReactPlayer.js +19 -14
  10. package/build/cjs/models/constructor-items/common.d.ts +8 -0
  11. package/build/cjs/models/constructor-items/common.js +7 -1
  12. package/build/esm/components/Media/Media.js +3 -1
  13. package/build/esm/components/Media/Video/Video.js +3 -2
  14. package/build/esm/components/ReactPlayer/CustomBarControls.css +45 -24
  15. package/build/esm/components/ReactPlayer/CustomBarControls.d.ts +3 -2
  16. package/build/esm/components/ReactPlayer/CustomBarControls.js +29 -17
  17. package/build/esm/components/ReactPlayer/ReactPlayer.css +2 -16
  18. package/build/esm/components/ReactPlayer/ReactPlayer.d.ts +1 -0
  19. package/build/esm/components/ReactPlayer/ReactPlayer.js +20 -15
  20. package/build/esm/models/constructor-items/common.d.ts +8 -0
  21. package/build/esm/models/constructor-items/common.js +6 -0
  22. package/package.json +1 -1
  23. package/server/models/constructor-items/common.d.ts +8 -0
  24. package/server/models/constructor-items/common.js +7 -1
  25. package/widget/index.js +1 -1
  26. package/build/cjs/icons/MuteSmall.d.ts +0 -2
  27. package/build/cjs/icons/MuteSmall.js +0 -15
  28. package/build/cjs/icons/UnmuteSmall.d.ts +0 -2
  29. package/build/cjs/icons/UnmuteSmall.js +0 -17
  30. package/build/cjs/icons/VideoControlPause.d.ts +0 -2
  31. package/build/cjs/icons/VideoControlPause.js +0 -16
  32. package/build/cjs/icons/VideoControlPlay.d.ts +0 -2
  33. package/build/cjs/icons/VideoControlPlay.js +0 -12
  34. package/build/esm/icons/MuteSmall.d.ts +0 -2
  35. package/build/esm/icons/MuteSmall.js +0 -10
  36. package/build/esm/icons/UnmuteSmall.d.ts +0 -2
  37. package/build/esm/icons/UnmuteSmall.js +0 -12
  38. package/build/esm/icons/VideoControlPause.d.ts +0 -2
  39. package/build/esm/icons/VideoControlPause.js +0 -11
  40. package/build/esm/icons/VideoControlPlay.d.ts +0 -2
  41. package/build/esm/icons/VideoControlPlay.js +0 -7
@@ -1,42 +1,54 @@
1
1
  import React, { useMemo } from 'react';
2
+ import { Pause, Play, VolumeLow, VolumeXmark } from '@gravity-ui/icons';
2
3
  import { Icon } from '@gravity-ui/uikit';
3
4
  import { Mute } from '../../icons/Mute';
4
- import { MuteSmall } from '../../icons/MuteSmall';
5
5
  import { Unmute } from '../../icons/Unmute';
6
- import { UnmuteSmall } from '../../icons/UnmuteSmall';
7
- import { VideoControlPause } from '../../icons/VideoControlPause';
8
- import { VideoControlPlay } from '../../icons/VideoControlPlay';
9
6
  import { CustomControlsType } from '../../models';
10
7
  import { block } from '../../utils';
11
8
  import CircleProgress from './CircleProgress';
12
9
  import i18n from './i18n';
13
10
  import './CustomBarControls.css';
14
11
  const b = block('CustomBarControls');
12
+ const playIconsMap = {
13
+ [CustomControlsType.WithMuteButton]: null,
14
+ [CustomControlsType.WithPlayPauseButton]: Play,
15
+ };
16
+ const pauseIconsMap = {
17
+ [CustomControlsType.WithMuteButton]: null,
18
+ [CustomControlsType.WithPlayPauseButton]: Pause,
19
+ };
20
+ const muteIconsMap = {
21
+ [CustomControlsType.WithMuteButton]: Mute,
22
+ [CustomControlsType.WithPlayPauseButton]: VolumeLow,
23
+ };
24
+ const unmuteIconsMap = {
25
+ [CustomControlsType.WithMuteButton]: Unmute,
26
+ [CustomControlsType.WithPlayPauseButton]: VolumeXmark,
27
+ };
15
28
  const CustomBarControls = (props) => {
16
- const { mute, elapsedTimePercent = 0, className, type = CustomControlsType.WithMuteButton, isPaused, onPlayClick, } = props;
17
- const muteIcon = useMemo(() => {
18
- return type === CustomControlsType.WithMuteButton ? Mute : MuteSmall;
19
- }, [type]);
20
- const unmuteIcon = useMemo(() => {
21
- return type === CustomControlsType.WithMuteButton ? Unmute : UnmuteSmall;
22
- }, [type]);
29
+ const { mute, elapsedTimePercent = 0, className, type = CustomControlsType.WithMuteButton, isPaused, onPlayClick, muteButtonShown: isMuteButtonShown = true, shown, positioning, } = props;
30
+ const muteIcon = muteIconsMap[type];
31
+ const unmuteIcon = unmuteIconsMap[type];
32
+ const playIcon = playIconsMap[type];
33
+ const pauseIcon = pauseIconsMap[type];
23
34
  const muteButton = useMemo(() => {
24
- if (!mute) {
35
+ if (!mute || !isMuteButtonShown) {
25
36
  return null;
26
37
  }
27
38
  const { isMuted, changeMute } = mute;
28
39
  return (React.createElement("button", { className: b('button', { type }), onClick: changeMute, "aria-label": i18n(isMuted ? 'unmute' : 'mute') },
29
40
  React.createElement(Icon, { data: isMuted ? unmuteIcon : muteIcon, className: b('mute-icon', { type }) }),
30
41
  type === CustomControlsType.WithMuteButton && !isMuted && (React.createElement(CircleProgress, { elapsedTime: elapsedTimePercent, strokeWidth: 5 }))));
31
- }, [elapsedTimePercent, mute, muteIcon, type, unmuteIcon]);
42
+ }, [elapsedTimePercent, isMuteButtonShown, mute, muteIcon, type, unmuteIcon]);
32
43
  const playPauseButton = useMemo(() => {
33
- if (type !== CustomControlsType.WithPlayPauseButton) {
44
+ const icon = isPaused ? playIcon : pauseIcon;
45
+ if (type === CustomControlsType.WithMuteButton || !icon) {
34
46
  return null;
35
47
  }
36
48
  return (React.createElement("button", { onClick: onPlayClick, className: b('button', { type }), "aria-label": i18n(isPaused ? 'play' : 'pause') },
37
- React.createElement(Icon, { data: isPaused ? VideoControlPlay : VideoControlPause, className: b('play-icon') })));
38
- }, [isPaused, onPlayClick, type]);
39
- return (React.createElement("div", { className: b('wrapper', { type }, className) },
49
+ React.createElement(Icon, { data: icon, className: b('play-icon', { type }) })));
50
+ }, [isPaused, onPlayClick, type, playIcon, pauseIcon]);
51
+ return (React.createElement("div", { className: b('wrapper', { type, shown, positioning }, className) },
40
52
  playPauseButton,
41
53
  muteButton));
42
54
  };
@@ -46,14 +46,8 @@ unpredictable css rules order in build */
46
46
  .pc-ReactPlayer__icon {
47
47
  margin-left: 6px;
48
48
  }
49
- .pc-ReactPlayer:hover .pc-ReactPlayer__custom-bar-controls {
50
- opacity: 1;
51
- transition: opacity 300ms ease 0s;
52
- }
53
- .pc-ReactPlayer_started.pc-ReactPlayer_controls_custom.pc-ReactPlayer_hovered::before {
54
- opacity: 1;
55
- }
56
- .pc-ReactPlayer_started.pc-ReactPlayer_controls_custom::before {
49
+ .pc-ReactPlayer_controls_custom::before {
50
+ display: none;
57
51
  position: absolute;
58
52
  width: 100%;
59
53
  height: 100%;
@@ -62,14 +56,6 @@ unpredictable css rules order in build */
62
56
  opacity: 0;
63
57
  transition: opacity 300ms;
64
58
  }
65
- .pc-ReactPlayer__custom-bar-controls {
66
- opacity: 0;
67
- transition: opacity 300ms ease 3s;
68
- }
69
- .pc-ReactPlayer__custom-bar-controls_muted {
70
- opacity: 1;
71
- transition: opacity 0s ease 0s;
72
- }
73
59
  @media only screen and (max-width: 577px) {
74
60
  .pc-ReactPlayer__button_text {
75
61
  font-size: 20px;
@@ -9,6 +9,7 @@ export interface ReactPlayerBlockProps extends Omit<MediaVideoProps, 'loop' | 's
9
9
  showPreview?: boolean;
10
10
  onClickPreview?: () => void;
11
11
  height?: number;
12
+ ratio?: number;
12
13
  children?: React.ReactNode;
13
14
  }
14
15
  export declare const ReactPlayerBlock: React.ForwardRefExoticComponent<ReactPlayerBlockProps & React.RefAttributes<ReactPlayerBlockHandler>>;
@@ -7,7 +7,7 @@ import { MobileContext } from '../../context/mobileContext';
7
7
  import { VideoContext } from '../../context/videoContext';
8
8
  import { useAnalytics, useMount } from '../../hooks';
9
9
  import { PlayVideo } from '../../icons';
10
- import { CustomControlsType, DefaultEventNames, MediaVideoControlsType, PlayButtonThemes, PlayButtonType, PredefinedEventTypes, } from '../../models';
10
+ import { CustomControlsButtonPositioning, CustomControlsType, DefaultEventNames, MediaVideoControlsType, PlayButtonThemes, PlayButtonType, PredefinedEventTypes, } from '../../models';
11
11
  import { block } from '../../utils';
12
12
  import CustomBarControls from './CustomBarControls';
13
13
  import i18n from './i18n';
@@ -19,9 +19,9 @@ const FPS = 60;
19
19
  export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
20
20
  const isMobile = useContext(MobileContext);
21
21
  const { metrika } = useContext(MetrikaContext);
22
- const { src, previewImgUrl, loop = false, controls = MediaVideoControlsType.Default, customControlsOptions = {}, muted: initiallyMuted = false, elapsedTime, playButton, className, customBarControlsClassName, showPreview, onClickPreview, metrika: videoMetrika, analyticsEvents, height, ariaLabel, } = props;
22
+ const { src, previewImgUrl, loop = false, controls = MediaVideoControlsType.Default, customControlsOptions = {}, muted: initiallyMuted = false, elapsedTime, playButton, className, customBarControlsClassName, showPreview, onClickPreview, metrika: videoMetrika, analyticsEvents, height, ariaLabel, ratio, } = props;
23
23
  const { type = PlayButtonType.Default, theme = PlayButtonThemes.Blue, text, className: buttonClassName, } = playButton || {};
24
- const { type: customControlsType = CustomControlsType.WithMuteButton } = customControlsOptions;
24
+ const { type: customControlsType = CustomControlsType.WithMuteButton, muteButtonShown, positioning = CustomControlsButtonPositioning.Center, } = customControlsOptions;
25
25
  const autoPlay = Boolean(!isMobile && !previewImgUrl && props.autoplay);
26
26
  const mute = initiallyMuted || autoPlay;
27
27
  const { playingVideoRef, setProps } = useContext(VideoContext);
@@ -59,10 +59,10 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
59
59
  }
60
60
  }, [showPreview, playerRef]);
61
61
  useEffect(() => {
62
- if (playerRef) {
62
+ if (playerRef && !started) {
63
63
  setIsPlaying(autoPlay);
64
64
  }
65
- }, [autoPlay, playerRef]);
65
+ }, [autoPlay, playerRef, started]);
66
66
  useEffect(() => setMuted(mute), [mute]);
67
67
  useEffect(() => {
68
68
  if (!started && isPlaying) {
@@ -84,7 +84,7 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
84
84
  parseFloat(paddingLeft) -
85
85
  parseFloat(paddingRight);
86
86
  setWidth(newWidth);
87
- setCurrentHeight(Math.floor(getHeight(newWidth)));
87
+ setCurrentHeight(Math.floor(getHeight(newWidth, ratio)));
88
88
  }
89
89
  }, 200);
90
90
  updateSize();
@@ -92,7 +92,7 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
92
92
  return () => {
93
93
  window.removeEventListener('resize', updateSize);
94
94
  };
95
- }, []);
95
+ }, [ratio]);
96
96
  const playEvents = useMemo(() => eventsArray === null || eventsArray === void 0 ? void 0 : eventsArray.filter((e) => e.type === PredefinedEventTypes.Play), [eventsArray]);
97
97
  const stopEvents = useMemo(() => eventsArray === null || eventsArray === void 0 ? void 0 : eventsArray.filter((e) => e.type === PredefinedEventTypes.Stop), [eventsArray]);
98
98
  const playIcon = useMemo(() => {
@@ -111,7 +111,7 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
111
111
  const changeMute = useCallback((isMuted) => {
112
112
  if (isMuted &&
113
113
  playerRef &&
114
- customControlsType !== CustomControlsType.WithPlayPauseButton) {
114
+ customControlsType === CustomControlsType.WithMuteButton) {
115
115
  playerRef.seekTo(0);
116
116
  setPlayedPercent(0);
117
117
  }
@@ -153,7 +153,7 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
153
153
  const onPause = useCallback(() => {
154
154
  // For support correct state for youtube
155
155
  if (controls !== MediaVideoControlsType.Custom ||
156
- customControlsType === CustomControlsType.WithPlayPauseButton) {
156
+ customControlsType !== CustomControlsType.WithMuteButton) {
157
157
  setIsPlaying(false);
158
158
  }
159
159
  }, [controls, customControlsType]);
@@ -210,18 +210,23 @@ export const ReactPlayerBlock = React.forwardRef((props, originRef) => {
210
210
  }, [changeMute, customControlsType, muted, onPlayClick]);
211
211
  const onFocusIn = useCallback(() => setHovered(true), []);
212
212
  const onFocusOut = useCallback(() => setHovered(false), []);
213
- return (React.createElement("div", { className: b({ wrapper: !currentHeight, controls, started, hovered }, className), ref: ref, onClick: handleClick, onMouseEnter: onFocusIn, onMouseLeave: onFocusOut, onFocus: onFocusIn, onBlur: onFocusOut }, isMounted ? (React.createElement(Fragment, null,
214
- 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, "aria-label": ariaLabel }),
215
- controls === MediaVideoControlsType.Custom && started && (React.createElement(CustomBarControls, { className: b('custom-bar-controls', { muted }, customBarControlsClassName), mute: {
213
+ return (React.createElement("div", { className: b({
214
+ wrapper: !currentHeight,
215
+ controls,
216
+ }, className), ref: ref, onClick: handleClick, onMouseEnter: onFocusIn, onMouseLeave: onFocusOut, onFocus: onFocusIn, onBlur: onFocusOut }, isMounted ? (React.createElement(Fragment, null,
217
+ 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: autoPlay && customControlsType !== CustomControlsType.WithMuteButton
218
+ ? undefined
219
+ : onPause, onProgress: onProgress, onEnded: onEnded, "aria-label": ariaLabel }),
220
+ controls === MediaVideoControlsType.Custom && (React.createElement(CustomBarControls, { className: customBarControlsClassName, mute: {
216
221
  isMuted: muted,
217
222
  changeMute: (event) => {
218
223
  event.stopPropagation();
219
224
  changeMute(muted);
220
225
  },
221
- }, elapsedTimePercent: playedPercent, type: customControlsType, isPaused: !isPlaying, onPlayClick: onPlayClick })))) : null));
226
+ }, elapsedTimePercent: playedPercent, type: customControlsType, isPaused: !isPlaying, onPlayClick: onPlayClick, muteButtonShown: muteButtonShown, shown: hovered && ((!started && !previewImgUrl) || started), positioning: positioning })))) : null));
222
227
  });
223
- function getHeight(width) {
224
- return (width / 16) * 9;
228
+ function getHeight(width, ratio = 9 / 16) {
229
+ return width * ratio;
225
230
  }
226
231
  function getParentElement(element) {
227
232
  const parentElement = element.parentElement;
@@ -29,6 +29,11 @@ export declare enum CustomControlsType {
29
29
  WithMuteButton = "with-mute-button",
30
30
  WithPlayPauseButton = "with-play-pause-button"
31
31
  }
32
+ export declare enum CustomControlsButtonPositioning {
33
+ Left = "left",
34
+ Right = "right",
35
+ Center = "center"
36
+ }
32
37
  export declare enum MediaVideoType {
33
38
  Default = "default",
34
39
  Player = "player"
@@ -158,6 +163,8 @@ export interface ButtonImageProps {
158
163
  }
159
164
  export interface CustomControlsOptions {
160
165
  type?: CustomControlsType;
166
+ muteButtonShown?: boolean;
167
+ positioning?: CustomControlsButtonPositioning;
161
168
  }
162
169
  export interface PlayButtonProps extends ClassNameProps {
163
170
  type?: PlayButtonType;
@@ -168,6 +175,7 @@ export type ThemedMediaVideoProps = ThemeSupporting<MediaVideoProps>;
168
175
  export interface MediaComponentVideoProps extends AnalyticsEventsBase {
169
176
  video: MediaVideoProps;
170
177
  height?: number;
178
+ ratio?: number;
171
179
  metrika?: MetrikaVideo;
172
180
  previewImg?: string;
173
181
  }
@@ -32,6 +32,12 @@ export var CustomControlsType;
32
32
  CustomControlsType["WithMuteButton"] = "with-mute-button";
33
33
  CustomControlsType["WithPlayPauseButton"] = "with-play-pause-button";
34
34
  })(CustomControlsType || (CustomControlsType = {}));
35
+ export var CustomControlsButtonPositioning;
36
+ (function (CustomControlsButtonPositioning) {
37
+ CustomControlsButtonPositioning["Left"] = "left";
38
+ CustomControlsButtonPositioning["Right"] = "right";
39
+ CustomControlsButtonPositioning["Center"] = "center";
40
+ })(CustomControlsButtonPositioning || (CustomControlsButtonPositioning = {}));
35
41
  export var MediaVideoType;
36
42
  (function (MediaVideoType) {
37
43
  MediaVideoType["Default"] = "default";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "4.18.1",
3
+ "version": "4.18.2-alpha.1",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,6 +29,11 @@ export declare enum CustomControlsType {
29
29
  WithMuteButton = "with-mute-button",
30
30
  WithPlayPauseButton = "with-play-pause-button"
31
31
  }
32
+ export declare enum CustomControlsButtonPositioning {
33
+ Left = "left",
34
+ Right = "right",
35
+ Center = "center"
36
+ }
32
37
  export declare enum MediaVideoType {
33
38
  Default = "default",
34
39
  Player = "player"
@@ -158,6 +163,8 @@ export interface ButtonImageProps {
158
163
  }
159
164
  export interface CustomControlsOptions {
160
165
  type?: CustomControlsType;
166
+ muteButtonShown?: boolean;
167
+ positioning?: CustomControlsButtonPositioning;
161
168
  }
162
169
  export interface PlayButtonProps extends ClassNameProps {
163
170
  type?: PlayButtonType;
@@ -168,6 +175,7 @@ export type ThemedMediaVideoProps = ThemeSupporting<MediaVideoProps>;
168
175
  export interface MediaComponentVideoProps extends AnalyticsEventsBase {
169
176
  video: MediaVideoProps;
170
177
  height?: number;
178
+ ratio?: number;
171
179
  metrika?: MetrikaVideo;
172
180
  previewImg?: string;
173
181
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MediaVideoControlsType = exports.MediaVideoType = exports.CustomControlsType = exports.PlayButtonThemes = exports.PlayButtonType = exports.PriceLabelColor = exports.PriceDetailsType = exports.AuthorType = void 0;
3
+ exports.MediaVideoControlsType = exports.MediaVideoType = exports.CustomControlsButtonPositioning = exports.CustomControlsType = exports.PlayButtonThemes = exports.PlayButtonType = exports.PriceLabelColor = exports.PriceDetailsType = exports.AuthorType = void 0;
4
4
  // enums
5
5
  var AuthorType;
6
6
  (function (AuthorType) {
@@ -35,6 +35,12 @@ var CustomControlsType;
35
35
  CustomControlsType["WithMuteButton"] = "with-mute-button";
36
36
  CustomControlsType["WithPlayPauseButton"] = "with-play-pause-button";
37
37
  })(CustomControlsType = exports.CustomControlsType || (exports.CustomControlsType = {}));
38
+ var CustomControlsButtonPositioning;
39
+ (function (CustomControlsButtonPositioning) {
40
+ CustomControlsButtonPositioning["Left"] = "left";
41
+ CustomControlsButtonPositioning["Right"] = "right";
42
+ CustomControlsButtonPositioning["Center"] = "center";
43
+ })(CustomControlsButtonPositioning = exports.CustomControlsButtonPositioning || (exports.CustomControlsButtonPositioning = {}));
38
44
  var MediaVideoType;
39
45
  (function (MediaVideoType) {
40
46
  MediaVideoType["Default"] = "default";