@gravity-ui/page-constructor 8.14.2 → 8.16.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 (75) hide show
  1. package/README.md +31 -9
  2. package/build/cjs/components/ReactPlayer/ReactPlayer.css +0 -50
  3. package/build/cjs/components/ReactPlayer/ReactPlayer.js +4 -16
  4. package/build/cjs/components/ReactPlayer/ReactPlayer.js.map +1 -1
  5. package/build/cjs/components/VideoBlock/VideoBlock.css +0 -30
  6. package/build/cjs/components/VideoBlock/VideoBlock.d.ts +2 -1
  7. package/build/cjs/components/VideoBlock/VideoBlock.js +18 -2
  8. package/build/cjs/components/VideoBlock/VideoBlock.js.map +1 -1
  9. package/build/cjs/components/VideoButton/VideoButton.css +64 -0
  10. package/build/cjs/components/VideoButton/VideoButton.d.ts +9 -0
  11. package/build/cjs/components/VideoButton/VideoButton.js +50 -0
  12. package/build/cjs/components/VideoButton/VideoButton.js.map +1 -0
  13. package/build/cjs/context/projectSettingsContext/ProjectSettingsContext.d.ts +7 -0
  14. package/build/cjs/context/projectSettingsContext/ProjectSettingsContext.js.map +1 -1
  15. package/build/cjs/models/constructor-items/common.d.ts +8 -1
  16. package/build/cjs/models/constructor-items/common.js +1 -0
  17. package/build/cjs/models/constructor-items/common.js.map +1 -1
  18. package/build/docs/INDEX.md +191 -0
  19. package/build/docs/blocks/Banner.md +59 -0
  20. package/build/docs/blocks/CardLayout.md +79 -0
  21. package/build/docs/blocks/Companies.md +67 -0
  22. package/build/docs/blocks/ContentLayout.md +54 -0
  23. package/build/docs/blocks/ExtendedFeatures.md +74 -0
  24. package/build/docs/blocks/FilterBlock.md +112 -0
  25. package/build/docs/blocks/FoldableList.md +78 -0
  26. package/build/docs/blocks/Footer.md +110 -0
  27. package/build/docs/blocks/Form.md +89 -0
  28. package/build/docs/blocks/Header.md +70 -0
  29. package/build/docs/blocks/HeaderSlider.md +70 -0
  30. package/build/docs/blocks/Hero.md +67 -0
  31. package/build/docs/blocks/Icons.md +61 -0
  32. package/build/docs/blocks/Info.md +73 -0
  33. package/build/docs/blocks/Map.md +81 -0
  34. package/build/docs/blocks/Media.md +63 -0
  35. package/build/docs/blocks/PromoFeaturesBlock.md +74 -0
  36. package/build/docs/blocks/Questions.md +78 -0
  37. package/build/docs/blocks/Share.md +45 -0
  38. package/build/docs/blocks/Slider.md +89 -0
  39. package/build/docs/blocks/SliderOld.md +63 -0
  40. package/build/docs/blocks/Table.md +64 -0
  41. package/build/docs/blocks/Tabs.md +92 -0
  42. package/build/docs/guides/data-preparation-ru.md +257 -0
  43. package/build/docs/guides/data-preparation.md +259 -0
  44. package/build/docs/sub-blocks/BackgroundCard.md +63 -0
  45. package/build/docs/sub-blocks/BannerCard.md +57 -0
  46. package/build/docs/sub-blocks/BasicCard.md +60 -0
  47. package/build/docs/sub-blocks/Content.md +58 -0
  48. package/build/docs/sub-blocks/Divider.md +47 -0
  49. package/build/docs/sub-blocks/HubspotForm.md +47 -0
  50. package/build/docs/sub-blocks/ImageCard.md +59 -0
  51. package/build/docs/sub-blocks/LayoutItem.md +70 -0
  52. package/build/docs/sub-blocks/MediaCard.md +66 -0
  53. package/build/docs/sub-blocks/PriceCard.md +60 -0
  54. package/build/docs/sub-blocks/PriceDetailed.md +74 -0
  55. package/build/docs/sub-blocks/Quote.md +74 -0
  56. package/build/esm/components/ReactPlayer/ReactPlayer.css +0 -50
  57. package/build/esm/components/ReactPlayer/ReactPlayer.js +4 -16
  58. package/build/esm/components/ReactPlayer/ReactPlayer.js.map +1 -1
  59. package/build/esm/components/VideoBlock/VideoBlock.css +0 -30
  60. package/build/esm/components/VideoBlock/VideoBlock.d.ts +2 -1
  61. package/build/esm/components/VideoBlock/VideoBlock.js +19 -3
  62. package/build/esm/components/VideoBlock/VideoBlock.js.map +1 -1
  63. package/build/esm/components/VideoButton/VideoButton.css +64 -0
  64. package/build/esm/components/VideoButton/VideoButton.d.ts +10 -0
  65. package/build/esm/components/VideoButton/VideoButton.js +48 -0
  66. package/build/esm/components/VideoButton/VideoButton.js.map +1 -0
  67. package/build/esm/context/projectSettingsContext/ProjectSettingsContext.d.ts +7 -0
  68. package/build/esm/context/projectSettingsContext/ProjectSettingsContext.js.map +1 -1
  69. package/build/esm/models/constructor-items/common.d.ts +8 -1
  70. package/build/esm/models/constructor-items/common.js +1 -0
  71. package/build/esm/models/constructor-items/common.js.map +1 -1
  72. package/package.json +3 -2
  73. package/server/models/constructor-items/common.d.ts +8 -1
  74. package/server/models/constructor-items/common.js +1 -0
  75. package/widget/index.js +1 -1
package/README.md CHANGED
@@ -582,17 +582,39 @@ The Memory Bank is located in the `memory-bank/` directory and consists of regul
582
582
  - `usage/` - Component-specific usage documentation
583
583
  - `storybookComponents.md` - Storybook integration details
584
584
 
585
- ### For AI Agents
585
+ ## Tests
586
586
 
587
- When working with AI agents on this project, the Memory Bank serves as a comprehensive knowledge base that helps agents understand:
587
+ Comprehensive documentation is available at the provided [link](./test-utils/docs/README.md).
588
588
 
589
- - Project structure and patterns
590
- - Component APIs and usage examples
591
- - Development workflows and best practices
592
- - Current implementation status and next steps
589
+ ## License
593
590
 
594
- AI agents can read these files to quickly get up to speed with the project context and make more informed decisions about code changes and implementations.
591
+ Distributed under the MIT License. See [LICENSE](LICENSE) for details.
595
592
 
596
- ## Tests
593
+ ## For AI agents
597
594
 
598
- Comprehensive documentation is available at the provided [link](./test-utils/docs/README.md).
595
+ A library for rendering whole web pages or page sections from declarative JSON/YAML config, using a set of ready-made, orderable blocks — reach for it to build marketing/landing pages, not general application UI.
596
+
597
+ ### When to use
598
+
599
+ - Data-driven pages: render a `content` config of typed blocks with `PageConstructor` wrapped in `PageConstructorProvider`.
600
+ - Marketing, landing, and documentation pages assembled from prebuilt blocks (headers, media, cards, etc.).
601
+ - Server-side YFM processing of block text via the `@gravity-ui/page-constructor/server` utilities (`contentTransformer`, `fullTransform`).
602
+ - Reusing just the responsive grid (`Grid`/`Row`/`Col`) or `Navigation` component standalone.
603
+
604
+ ### When not to use
605
+
606
+ - General application UI (buttons, forms, modals) — use [`@gravity-ui/uikit`](https://github.com/gravity-ui/uikit).
607
+ - Editing Markdown/YFM content — use [`@gravity-ui/markdown-editor`](https://github.com/gravity-ui/markdown-editor).
608
+ - App navigation shells (aside header) — use [`@gravity-ui/navigation`](https://github.com/gravity-ui/navigation); this package's `Navigation` is a page-level top nav.
609
+
610
+ ### Common pitfalls
611
+
612
+ - **`PageConstructor` must be wrapped in `PageConstructorProvider`.** Rendering it bare breaks context (locale, theme, SSR, analytics).
613
+ - **The content prop is `content`, shaped `{blocks: [...]}`.** Each block object needs a `type` matching a known block plus its data fields; there is no `data`/`config` prop.
614
+ - **YFM in block text needs server processing.** Markdown-like fields render as plain text unless you run content through `contentTransformer`/`fullTransform` from `@gravity-ui/page-constructor/server`; `@diplodoc/transform` is a required peer dependency.
615
+ - **Import the SCSS styles.** Add `@gravity-ui/page-constructor/styles/styles.scss` (SCSS, not CSS); custom blocks import the same file to reuse mixins/variables.
616
+ - **Vite needs `vite-plugin-dynamic-import`.** Dynamic block imports fail under Vite without it.
617
+
618
+ ## Documentation for AI agents
619
+
620
+ Agent-readable documentation for the installed version is located in `node_modules/@gravity-ui/page-constructor/build/docs/INDEX.md`.
@@ -18,50 +18,6 @@ unpredictable css rules order in build */
18
18
  top: 0;
19
19
  left: 0;
20
20
  }
21
- .pc-ReactPlayer__button {
22
- display: inline-block;
23
- margin: 0;
24
- padding: 0;
25
- font: inherit;
26
- border: none;
27
- outline: none;
28
- color: inherit;
29
- background: none;
30
- cursor: pointer;
31
- display: flex;
32
- justify-content: center;
33
- align-items: center;
34
- position: absolute;
35
- width: 64px;
36
- height: 64px;
37
- border-radius: 166px;
38
- }
39
- .pc-ReactPlayer__button:focus {
40
- outline: 2px solid var(--g-color-line-focus);
41
- outline-offset: 0;
42
- }
43
- .pc-ReactPlayer__button:focus:not(:focus-visible) {
44
- outline: 0;
45
- }
46
- .pc-ReactPlayer__button_theme_blue {
47
- color: var(--g-color-base-background);
48
- background-color: var(--g-color-base-brand);
49
- }
50
- .pc-ReactPlayer__button_theme_grey {
51
- color: var(--pc-text-header-color);
52
- background-color: #eff2f8;
53
- }
54
- .pc-ReactPlayer__button_text {
55
- padding: 16px 32px;
56
- font-weight: 400;
57
- font-size: 24px;
58
- line-height: 32px;
59
- width: auto;
60
- height: auto;
61
- }
62
- .pc-ReactPlayer__icon {
63
- margin-left: 1px;
64
- }
65
21
  .pc-ReactPlayer_controls_custom::before {
66
22
  display: none;
67
23
  position: absolute;
@@ -77,10 +33,4 @@ unpredictable css rules order in build */
77
33
  }
78
34
  .pc-ReactPlayer_auto-ratio video {
79
35
  object-fit: cover;
80
- }
81
- @media only screen and (max-width: 577px) {
82
- .pc-ReactPlayer__button_text {
83
- font-size: 20px;
84
- line-height: 24px;
85
- }
86
36
  }
@@ -4,8 +4,6 @@ exports.ReactPlayerBlock = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  const React = tslib_1.__importStar(require("react"));
7
- const icons_1 = require("@gravity-ui/icons");
8
- const uikit_1 = require("@gravity-ui/uikit");
9
7
  const debounce_1 = tslib_1.__importDefault(require("lodash/debounce.js"));
10
8
  const react_player_1 = tslib_1.__importDefault(require("react-player"));
11
9
  const mobileContext_1 = require("../../context/mobileContext/index.js");
@@ -13,8 +11,8 @@ const videoContext_1 = require("../../context/videoContext/index.js");
13
11
  const hooks_1 = require("../../hooks/index.js");
14
12
  const models_1 = require("../../models/index.js");
15
13
  const utils_1 = require("../../utils/index.js");
14
+ const VideoButton_1 = tslib_1.__importDefault(require("../VideoButton/VideoButton.js"));
16
15
  const CustomBarControls_1 = tslib_1.__importDefault(require("./CustomBarControls.js"));
17
- const i18n_1 = require("./i18n/index.js");
18
16
  const utils_2 = require("./utils.js");
19
17
  const youtube_1 = require("./utils/youtube.js");
20
18
  const b = (0, utils_1.block)('ReactPlayer');
@@ -26,7 +24,6 @@ const ReactPlayer = 'default' in react_player_1.default && react_player_1.defaul
26
24
  exports.ReactPlayerBlock = React.forwardRef((props, originRef) => {
27
25
  const isMobile = React.useContext(mobileContext_1.MobileContext);
28
26
  const { src, previewImgUrl, loop = false, controls = models_1.MediaVideoControlsType.Default, customControlsOptions = {}, muted: initiallyMuted = false, elapsedTime, playButton, className, customBarControlsClassName, showPreview, onClickPreview, onIntrinsicSizeChange, disableAutoSizing, analyticsEvents, height, ariaLabel, ratio, autoRatio, contain = true, } = props;
29
- const { type = models_1.PlayButtonType.Default, theme = models_1.PlayButtonThemes.Blue, text, className: buttonClassName, } = playButton || {};
30
27
  const { type: customControlsType = models_1.CustomControlsType.WithMuteButton, muteButtonShown, positioning = models_1.CustomControlsButtonPositioning.Center, } = customControlsOptions;
31
28
  const autoPlay = Boolean(!isMobile && !previewImgUrl && props.autoplay);
32
29
  const mute = initiallyMuted || autoPlay;
@@ -129,18 +126,9 @@ exports.ReactPlayerBlock = React.forwardRef((props, originRef) => {
129
126
  const playEvents = React.useMemo(() => eventsArray?.filter((e) => e.type === models_1.PredefinedEventTypes.Play), [eventsArray]);
130
127
  const stopEvents = React.useMemo(() => eventsArray?.filter((e) => e.type === models_1.PredefinedEventTypes.Stop), [eventsArray]);
131
128
  const playIcon = React.useMemo(() => {
132
- let playButtonContent;
133
- switch (type) {
134
- case models_1.PlayButtonType.Text:
135
- playButtonContent = text;
136
- break;
137
- case models_1.PlayButtonType.Default:
138
- default:
139
- playButtonContent = (0, jsx_runtime_1.jsx)(uikit_1.Icon, { className: b('icon'), data: icons_1.PlayFill, size: 24 });
140
- break;
141
- }
142
- return ((0, jsx_runtime_1.jsx)("button", { className: b('button', { theme, text: Boolean(text) }, buttonClassName), "aria-label": (0, i18n_1.i18n)('play'), ref: buttonRef, children: playButtonContent }));
143
- }, [type, theme, text, buttonClassName]);
129
+ const { theme, type } = playButton || {};
130
+ return ((0, jsx_runtime_1.jsx)(VideoButton_1.default, { ...playButton, theme: theme || models_1.PlayButtonThemes.Blue, type: type || models_1.PlayButtonType.Default }));
131
+ }, [playButton]);
144
132
  const changeMute = React.useCallback((isMuted) => {
145
133
  if (isMuted &&
146
134
  playerRef &&
@@ -1 +1 @@
1
- {"version":3,"file":"ReactPlayer.js","sourceRoot":"../../../../src","sources":["components/ReactPlayer/ReactPlayer.tsx"],"names":[],"mappings":";;;;;AAAA,qDAA+B;AAE/B,6CAA2C;AAC3C,6CAAuC;AACvC,0EAAuC;AACvC,wEAAwC;AAGxC,wEAA0D;AAC1D,sEAAwD;AACxD,gDAAiE;AACjE,kDAasB;AACtB,gDAAkC;AAElC,uFAAoD;AACpD,0CAA4B;AAC5B,sCAA2C;AAC3C,gDAAwD;AAIxD,MAAM,CAAC,GAAG,IAAA,aAAK,EAAC,aAAa,CAAC,CAAC;AAE/B,MAAM,GAAG,GAAG,EAAE,CAAC;AAEf,MAAM,WAAW,GACb,SAAS,IAAI,sBAAY,IAAI,sBAAY,CAAC,OAAO;IAC7C,CAAC,CAAE,sBAAY,CAAC,OAA+B;IAC/C,CAAC,CAAC,sBAAY,CAAC;AAuBvB,8CAA8C;AACjC,QAAA,gBAAgB,GAAG,KAAK,CAAC,UAAU,CAC5C,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;IACjB,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,6BAAa,CAAC,CAAC;IACjD,MAAM,EACF,GAAG,EACH,aAAa,EACb,IAAI,GAAG,KAAK,EACZ,QAAQ,GAAG,+BAAsB,CAAC,OAAO,EACzC,qBAAqB,GAAG,EAAE,EAC1B,KAAK,EAAE,cAAc,GAAG,KAAK,EAC7B,WAAW,EACX,UAAU,EACV,SAAS,EACT,0BAA0B,EAC1B,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,MAAM,EACN,SAAS,EACT,KAAK,EACL,SAAS,EACT,OAAO,GAAG,IAAI,GACjB,GAAG,KAAK,CAAC;IAEV,MAAM,EACF,IAAI,GAAG,uBAAc,CAAC,OA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;AAEF,SAAS,SAAS,CAAC,KAAa,EAAE,QAAgB,CAAC,GAAG,EAAE;IACpD,OAAO,KAAK,GAAG,KAAK,CAAC;AACzB,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAoB;IAC1C,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAE5C,IAAI,CAAC,aAAa,EAAE,CAAC;QACjB,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,OAAO,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;AACvF,CAAC;AAED,kBAAe,wBAAgB,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {PlayFill} from '@gravity-ui/icons';\nimport {Icon} from '@gravity-ui/uikit';\nimport debounce from 'lodash/debounce';\nimport _ReactPlayer from 'react-player';\nimport type {ReactPlayerProps} from 'react-player';\n\nimport {MobileContext} from '../../context/mobileContext';\nimport {VideoContext} from '../../context/videoContext';\nimport {useAnalytics, useImageSize, useMount} from '../../hooks';\nimport {\n AnalyticsEvent,\n ClassNameProps,\n CustomControlsButtonPositioning,\n CustomControlsType,\n DefaultEventNames,\n MediaVideoControlsType,\n MediaVideoProps,\n PlayButtonProps,\n PlayButtonThemes,\n PlayButtonType,\n PredefinedEventTypes,\n ReactPlayerBlockHandler,\n} from '../../models';\nimport {block} from '../../utils';\n\nimport CustomBarControls from './CustomBarControls';\nimport {i18n} from './i18n';\nimport {checkYoutubeVideos} from './utils';\nimport {isYoutubePlayerInstance} from './utils/youtube';\n\nimport './ReactPlayer.scss';\n\nconst b = block('ReactPlayer');\n\nconst FPS = 60;\n\nconst ReactPlayer =\n 'default' in _ReactPlayer && _ReactPlayer.default\n ? (_ReactPlayer.default as typeof _ReactPlayer)\n : _ReactPlayer;\n\nexport interface ReactPlayerBlockProps\n extends Omit<MediaVideoProps, 'src' | 'ref'>,\n ClassNameProps {\n src: string | string[];\n previewImgUrl?: string;\n customBarControlsClassName?: string;\n showPreview?: boolean;\n onClickPreview?: () => void;\n height?: number;\n ratio?: number;\n autoRatio?: boolean;\n disableAutoSizing?: boolean;\n onIntrinsicSizeChange?: (size: {width: number; height: number}) => void;\n children?: React.ReactNode;\n}\n\ninterface PlayerPropgress {\n played: number;\n playedSeconds: number;\n}\n\n// eslint-disable-next-line react/display-name\nexport const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactPlayerBlockProps>(\n (props, originRef) => {\n const isMobile = React.useContext(MobileContext);\n const {\n src,\n previewImgUrl,\n loop = false,\n controls = MediaVideoControlsType.Default,\n customControlsOptions = {},\n muted: initiallyMuted = false,\n elapsedTime,\n playButton,\n className,\n customBarControlsClassName,\n showPreview,\n onClickPreview,\n onIntrinsicSizeChange,\n disableAutoSizing,\n analyticsEvents,\n height,\n ariaLabel,\n ratio,\n autoRatio,\n contain = true,\n } = props;\n\n const {\n type = PlayButtonType.Default,\n theme = PlayButtonThemes.Blue,\n text,\n className: buttonClassName,\n } = playButton || ({} as PlayButtonProps);\n const {\n type: customControlsType = CustomControlsType.WithMuteButton,\n muteButtonShown,\n positioning = CustomControlsButtonPositioning.Center,\n } = customControlsOptions;\n\n const autoPlay = Boolean(!isMobile && !previewImgUrl && props.autoplay);\n const mute = initiallyMuted || autoPlay;\n\n const {playingVideoRef, setProps} = React.useContext(VideoContext);\n\n const ref = React.useRef<HTMLDivElement>(null);\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n\n const [playerRef, setPlayerRef] = React.useState<_ReactPlayer>();\n const [isPlaying, setIsPlaying] = React.useState(autoPlay);\n const [playedPercent, setPlayedPercent] = React.useState<number>(0);\n const [currentHeight, setCurrentHeight] = React.useState(height);\n const [duration, setDuration] = React.useState<null | number>(null);\n const [width, setWidth] = React.useState<number>(0);\n const [actualRatio, setActualRatio] = React.useState<number>();\n const [muted, setMuted] = React.useState<boolean>(mute);\n const [started, setStarted] = React.useState(autoPlay);\n const [ended, setEnded] = React.useState<boolean>(false);\n const [isMounted, setIsMounted] = React.useState(false);\n const [hovered, setHovered] = React.useState(isMobile);\n\n useMount(() => setIsMounted(true));\n\n const videoSrc = React.useMemo(() => checkYoutubeVideos(src), [src]);\n\n const {imageRef: previewImgRef, onLoad: onPreviewImgLoad} = useImageSize({\n onIntrinsicSizeChange,\n });\n\n const eventsArray = React.useMemo(() => {\n if (analyticsEvents) {\n return Array.isArray(analyticsEvents) ? analyticsEvents : [analyticsEvents];\n }\n\n return [];\n }, [analyticsEvents]);\n const handleAnalytics = useAnalytics(DefaultEventNames.ReactPlayerControls);\n\n React.useImperativeHandle(originRef, () => {\n if (!playerRef) {\n return;\n }\n\n let play, pause, addEventListener;\n const videoInstance = playerRef.getInternalPlayer();\n if (isYoutubePlayerInstance(videoInstance)) {\n ({pauseVideo: pause, playVideo: play, addEventListener} = videoInstance);\n } else {\n // it is assumed that `videoInstance` is HTMLVideoElement by default\n ({play, pause, addEventListener} = videoInstance);\n }\n\n // eslint-disable-next-line consistent-return\n return {\n play: play.bind(videoInstance),\n pause: pause.bind(videoInstance),\n addEventListener: addEventListener.bind(videoInstance),\n };\n }, [playerRef]);\n\n React.useEffect(() => {\n if (ref.current && !playingVideoRef?.contains(ref.current)) {\n setMuted(true);\n }\n }, [playingVideoRef]);\n\n React.useEffect(() => {\n if (showPreview) {\n playerRef?.showPreview();\n }\n }, [showPreview, playerRef]);\n\n React.useEffect(() => {\n if (playerRef && !started) {\n setIsPlaying(autoPlay);\n }\n }, [autoPlay, playerRef, started]);\n\n React.useEffect(() => setMuted(mute), [mute]);\n\n React.useEffect(() => {\n if (!started && isPlaying) {\n setStarted(true);\n }\n }, [isPlaying, started]);\n\n React.useEffect(() => {\n if (started && !Number.isNaN(Number(elapsedTime))) {\n playerRef?.seekTo(elapsedTime ?? 0, 'seconds');\n }\n }, [elapsedTime, playerRef, started]);\n\n React.useEffect(() => {\n if (disableAutoSizing) {\n return;\n }\n\n const updateSize = debounce(() => {\n if (ref.current) {\n // We need to get parent's width does not equal 0\n const parentElement = getParentElement(ref.current);\n const {paddingLeft, paddingRight} = getComputedStyle(parentElement);\n const newWidth =\n parentElement.offsetWidth -\n parseFloat(paddingLeft) -\n parseFloat(paddingRight);\n\n setWidth(newWidth);\n setCurrentHeight(\n Math.floor(\n getHeight(newWidth, ratio ?? (autoRatio ? actualRatio : undefined)),\n ),\n );\n }\n }, 200);\n\n updateSize();\n window.addEventListener('resize', updateSize, {passive: true});\n // eslint-disable-next-line consistent-return\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, [actualRatio, autoRatio, disableAutoSizing, playerRef, ratio]);\n\n const playEvents = React.useMemo(\n () => eventsArray?.filter((e: AnalyticsEvent) => e.type === PredefinedEventTypes.Play),\n [eventsArray],\n );\n const stopEvents = React.useMemo(\n () => eventsArray?.filter((e: AnalyticsEvent) => e.type === PredefinedEventTypes.Stop),\n [eventsArray],\n );\n\n const playIcon = React.useMemo(() => {\n let playButtonContent;\n\n switch (type) {\n case PlayButtonType.Text:\n playButtonContent = text;\n break;\n case PlayButtonType.Default:\n default:\n playButtonContent = <Icon className={b('icon')} data={PlayFill} size={24} />;\n break;\n }\n\n return (\n <button\n className={b('button', {theme, text: Boolean(text)}, buttonClassName)}\n aria-label={i18n('play')}\n ref={buttonRef}\n >\n {playButtonContent}\n </button>\n );\n }, [type, theme, text, buttonClassName]);\n\n const changeMute = React.useCallback(\n (isMuted: boolean) => {\n if (\n isMuted &&\n playerRef &&\n controls === MediaVideoControlsType.Custom &&\n customControlsType === CustomControlsType.WithMuteButton\n ) {\n playerRef.seekTo(0);\n setPlayedPercent(0);\n }\n\n const events = isMuted ? playEvents : stopEvents;\n handleAnalytics(events);\n\n if (isMuted) {\n setProps({playingVideoRef: ref.current});\n }\n\n // In order to the progress bar to update (equals 0) before displaying\n setTimeout(() => setMuted(!isMuted), 0);\n },\n [\n playerRef,\n customControlsType,\n playEvents,\n stopEvents,\n handleAnalytics,\n setProps,\n controls,\n ],\n );\n\n const handleClickPreview = React.useCallback(() => {\n setIsPlaying(true);\n onClickPreview?.();\n\n handleAnalytics(playEvents);\n }, [onClickPreview, handleAnalytics, playEvents]);\n\n const onPause = React.useCallback(() => {\n // For support correct state for youtube\n if (\n controls !== MediaVideoControlsType.Custom ||\n customControlsType !== CustomControlsType.WithMuteButton\n ) {\n setIsPlaying(false);\n }\n }, [controls, customControlsType]);\n\n const onStart = React.useCallback(() => {\n if (!autoPlay && !initiallyMuted) {\n setMuted(false);\n }\n }, [autoPlay, initiallyMuted]);\n\n const onPlay = React.useCallback(() => {\n setIsPlaying(true);\n\n if (\n controls === MediaVideoControlsType.Custom &&\n customControlsType === CustomControlsType.WithMuteButton\n ) {\n if (ended) {\n changeMute(false);\n } else if (!isPlaying) {\n changeMute(muted);\n }\n setEnded(false);\n }\n }, [changeMute, controls, customControlsType, ended, isPlaying, muted]);\n\n const onReady = React.useCallback(\n (player: _ReactPlayer) => {\n setPlayerRef(player);\n const videoElement = player.getInternalPlayer();\n const videoWidth = videoElement.videoWidth as number | undefined;\n const videoHeight = videoElement.videoHeight as number | undefined;\n if (videoWidth && videoHeight) {\n setActualRatio(videoHeight / videoWidth);\n onIntrinsicSizeChange?.({width: videoWidth, height: videoHeight});\n }\n },\n [onIntrinsicSizeChange],\n );\n\n const onProgress: ReactPlayerProps['onProgress'] = React.useCallback(\n ({played, playedSeconds}: PlayerPropgress) => {\n setPlayedPercent(played);\n\n if (loop) {\n const {start = 0, end = duration} = typeof loop === 'boolean' ? {} : loop;\n\n // Youtube videos not muted after finishing playing and start again.\n // 'onEnded' does not fire when 'loop' is set to true.\n // It is custom loop with muted sound after finishing playing and start again.\n if (end !== null && playedSeconds >= end) {\n setIsPlaying(true);\n playerRef?.seekTo(start);\n }\n }\n\n if (played === 1) {\n setMuted(true);\n }\n },\n [duration, loop, playerRef],\n );\n\n const onDuration = React.useCallback((currentDuration: number) => {\n setDuration(currentDuration);\n }, []);\n\n const onEnded = React.useCallback(() => {\n setEnded(true);\n }, []);\n\n const onPlayClick = React.useCallback(() => {\n if (isPlaying) {\n onPause();\n } else {\n onPlay();\n }\n }, [isPlaying, onPlay, onPause]);\n\n const handleClick = React.useCallback(() => {\n buttonRef.current?.click();\n\n if (controls === MediaVideoControlsType.Custom) {\n if (customControlsType === CustomControlsType.WithMuteButton) {\n changeMute(muted);\n } else {\n onPlayClick();\n }\n }\n }, [controls, customControlsType, changeMute, muted, onPlayClick]);\n\n const handleKeyDown = React.useCallback((e: React.KeyboardEvent) => {\n const key = e.key.toLowerCase();\n\n if (key === 'enter') {\n buttonRef.current?.click();\n }\n }, []);\n\n const onFocusIn = React.useCallback(() => setHovered(true), []);\n const onFocusOut = React.useCallback(() => setHovered(false), []);\n\n return (\n <div\n className={b(\n {\n wrapper: !currentHeight,\n controls,\n contain,\n 'auto-ratio': autoRatio,\n },\n className,\n )}\n ref={ref}\n onClick={handleClick}\n onMouseEnter={onFocusIn}\n onMouseLeave={onFocusOut}\n onFocus={onFocusIn}\n onBlur={onFocusOut}\n onKeyDown={handleKeyDown}\n role=\"button\"\n tabIndex={0}\n >\n {isMounted ? (\n <React.Fragment>\n <ReactPlayer\n className={b('player')}\n url={videoSrc}\n muted={muted}\n controls={controls === MediaVideoControlsType.Default}\n height={currentHeight || '100%'}\n width={width || '100%'}\n light={\n previewImgUrl && (\n <img\n className={b('preview-img')}\n src={previewImgUrl}\n onLoad={onPreviewImgLoad}\n alt=\"\"\n aria-hidden={true}\n ref={previewImgRef}\n />\n )\n }\n playing={isPlaying}\n playIcon={playIcon}\n progressInterval={FPS}\n onClickPreview={handleClickPreview}\n onStart={onStart}\n onReady={onReady}\n onPlay={onPlay}\n onPause={\n autoPlay && customControlsType !== CustomControlsType.WithMuteButton\n ? undefined\n : onPause\n } // to prevent pause icon flickering when autoplayed video ends\n onProgress={onProgress}\n onEnded={onEnded}\n onDuration={onDuration}\n aria-label={ariaLabel}\n previewTabIndex={-1}\n config={{\n file: {\n attributes: {\n pip: isMobile ? 'false' : undefined,\n playsinline: isMobile ? '' : undefined,\n disablepictureinpicture: isMobile ? '' : undefined,\n },\n },\n }}\n />\n {controls === MediaVideoControlsType.Custom && (\n <CustomBarControls\n className={customBarControlsClassName}\n mute={{\n isMuted: muted,\n changeMute: (event: React.MouseEvent) => {\n event.stopPropagation();\n changeMute(muted);\n },\n }}\n elapsedTimePercent={playedPercent}\n type={customControlsType}\n isPaused={!isPlaying}\n onPlayClick={onPlayClick}\n muteButtonShown={muteButtonShown}\n shown={hovered && ((!started && !previewImgUrl) || started)}\n positioning={positioning}\n />\n )}\n </React.Fragment>\n ) : null}\n </div>\n );\n },\n);\n\nfunction getHeight(width: number, ratio: number = 9 / 16): number {\n return width * ratio;\n}\n\nfunction getParentElement(element: HTMLElement): HTMLElement {\n const parentElement = element.parentElement;\n\n if (!parentElement) {\n return element;\n }\n\n return parentElement.offsetWidth ? parentElement : getParentElement(parentElement);\n}\n\nexport default ReactPlayerBlock;\n"]}
1
+ {"version":3,"file":"ReactPlayer.js","sourceRoot":"../../../../src","sources":["components/ReactPlayer/ReactPlayer.tsx"],"names":[],"mappings":";;;;;AAAA,qDAA+B;AAE/B,0EAAuC;AACvC,wEAAwC;AAGxC,wEAA0D;AAC1D,sEAAwD;AACxD,gDAAiE;AACjE,kDAYsB;AACtB,gDAAkC;AAClC,wFAAqD;AAErD,uFAAoD;AACpD,sCAA2C;AAC3C,gDAAwD;AAIxD,MAAM,CAAC,GAAG,IAAA,aAAK,EAAC,aAAa,CAAC,CAAC;AAE/B,MAAM,GAAG,GAAG,EAAE,CAAC;AAEf,MAAM,WAAW,GACb,SAAS,IAAI,sBAAY,IAAI,sBAAY,CAAC,OAAO;IAC7C,CAAC,CAAE,sBAAY,CAAC,OAA+B;IAC/C,CAAC,CAAC,sBAAY,CAAC;AAuBvB,8CAA8C;AACjC,QAAA,gBAAgB,GAAG,KAAK,CAAC,UAAU,CAC5C,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;IACjB,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,6BAA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BAAgB,CAAC,OAAoB;IAC1C,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAE5C,IAAI,CAAC,aAAa,EAAE,CAAC;QACjB,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,OAAO,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;AACvF,CAAC;AAED,kBAAe,wBAAgB,CAAC","sourcesContent":["import * as React from 'react';\n\nimport debounce from 'lodash/debounce';\nimport _ReactPlayer from 'react-player';\nimport type {ReactPlayerProps} from 'react-player';\n\nimport {MobileContext} from '../../context/mobileContext';\nimport {VideoContext} from '../../context/videoContext';\nimport {useAnalytics, useImageSize, useMount} from '../../hooks';\nimport {\n AnalyticsEvent,\n ClassNameProps,\n CustomControlsButtonPositioning,\n CustomControlsType,\n DefaultEventNames,\n MediaVideoControlsType,\n MediaVideoProps,\n PlayButtonThemes,\n PlayButtonType,\n PredefinedEventTypes,\n ReactPlayerBlockHandler,\n} from '../../models';\nimport {block} from '../../utils';\nimport VideoButton from '../VideoButton/VideoButton';\n\nimport CustomBarControls from './CustomBarControls';\nimport {checkYoutubeVideos} from './utils';\nimport {isYoutubePlayerInstance} from './utils/youtube';\n\nimport './ReactPlayer.scss';\n\nconst b = block('ReactPlayer');\n\nconst FPS = 60;\n\nconst ReactPlayer =\n 'default' in _ReactPlayer && _ReactPlayer.default\n ? (_ReactPlayer.default as typeof _ReactPlayer)\n : _ReactPlayer;\n\nexport interface ReactPlayerBlockProps\n extends Omit<MediaVideoProps, 'src' | 'ref'>,\n ClassNameProps {\n src: string | string[];\n previewImgUrl?: string;\n customBarControlsClassName?: string;\n showPreview?: boolean;\n onClickPreview?: () => void;\n height?: number;\n ratio?: number;\n autoRatio?: boolean;\n disableAutoSizing?: boolean;\n onIntrinsicSizeChange?: (size: {width: number; height: number}) => void;\n children?: React.ReactNode;\n}\n\ninterface PlayerPropgress {\n played: number;\n playedSeconds: number;\n}\n\n// eslint-disable-next-line react/display-name\nexport const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactPlayerBlockProps>(\n (props, originRef) => {\n const isMobile = React.useContext(MobileContext);\n const {\n src,\n previewImgUrl,\n loop = false,\n controls = MediaVideoControlsType.Default,\n customControlsOptions = {},\n muted: initiallyMuted = false,\n elapsedTime,\n playButton,\n className,\n customBarControlsClassName,\n showPreview,\n onClickPreview,\n onIntrinsicSizeChange,\n disableAutoSizing,\n analyticsEvents,\n height,\n ariaLabel,\n ratio,\n autoRatio,\n contain = true,\n } = props;\n const {\n type: customControlsType = CustomControlsType.WithMuteButton,\n muteButtonShown,\n positioning = CustomControlsButtonPositioning.Center,\n } = customControlsOptions;\n\n const autoPlay = Boolean(!isMobile && !previewImgUrl && props.autoplay);\n const mute = initiallyMuted || autoPlay;\n\n const {playingVideoRef, setProps} = React.useContext(VideoContext);\n\n const ref = React.useRef<HTMLDivElement>(null);\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n\n const [playerRef, setPlayerRef] = React.useState<_ReactPlayer>();\n const [isPlaying, setIsPlaying] = React.useState(autoPlay);\n const [playedPercent, setPlayedPercent] = React.useState<number>(0);\n const [currentHeight, setCurrentHeight] = React.useState(height);\n const [duration, setDuration] = React.useState<null | number>(null);\n const [width, setWidth] = React.useState<number>(0);\n const [actualRatio, setActualRatio] = React.useState<number>();\n const [muted, setMuted] = React.useState<boolean>(mute);\n const [started, setStarted] = React.useState(autoPlay);\n const [ended, setEnded] = React.useState<boolean>(false);\n const [isMounted, setIsMounted] = React.useState(false);\n const [hovered, setHovered] = React.useState(isMobile);\n\n useMount(() => setIsMounted(true));\n\n const videoSrc = React.useMemo(() => checkYoutubeVideos(src), [src]);\n\n const {imageRef: previewImgRef, onLoad: onPreviewImgLoad} = useImageSize({\n onIntrinsicSizeChange,\n });\n\n const eventsArray = React.useMemo(() => {\n if (analyticsEvents) {\n return Array.isArray(analyticsEvents) ? analyticsEvents : [analyticsEvents];\n }\n\n return [];\n }, [analyticsEvents]);\n const handleAnalytics = useAnalytics(DefaultEventNames.ReactPlayerControls);\n\n React.useImperativeHandle(originRef, () => {\n if (!playerRef) {\n return;\n }\n\n let play, pause, addEventListener;\n const videoInstance = playerRef.getInternalPlayer();\n if (isYoutubePlayerInstance(videoInstance)) {\n ({pauseVideo: pause, playVideo: play, addEventListener} = videoInstance);\n } else {\n // it is assumed that `videoInstance` is HTMLVideoElement by default\n ({play, pause, addEventListener} = videoInstance);\n }\n\n // eslint-disable-next-line consistent-return\n return {\n play: play.bind(videoInstance),\n pause: pause.bind(videoInstance),\n addEventListener: addEventListener.bind(videoInstance),\n };\n }, [playerRef]);\n\n React.useEffect(() => {\n if (ref.current && !playingVideoRef?.contains(ref.current)) {\n setMuted(true);\n }\n }, [playingVideoRef]);\n\n React.useEffect(() => {\n if (showPreview) {\n playerRef?.showPreview();\n }\n }, [showPreview, playerRef]);\n\n React.useEffect(() => {\n if (playerRef && !started) {\n setIsPlaying(autoPlay);\n }\n }, [autoPlay, playerRef, started]);\n\n React.useEffect(() => setMuted(mute), [mute]);\n\n React.useEffect(() => {\n if (!started && isPlaying) {\n setStarted(true);\n }\n }, [isPlaying, started]);\n\n React.useEffect(() => {\n if (started && !Number.isNaN(Number(elapsedTime))) {\n playerRef?.seekTo(elapsedTime ?? 0, 'seconds');\n }\n }, [elapsedTime, playerRef, started]);\n\n React.useEffect(() => {\n if (disableAutoSizing) {\n return;\n }\n\n const updateSize = debounce(() => {\n if (ref.current) {\n // We need to get parent's width does not equal 0\n const parentElement = getParentElement(ref.current);\n const {paddingLeft, paddingRight} = getComputedStyle(parentElement);\n const newWidth =\n parentElement.offsetWidth -\n parseFloat(paddingLeft) -\n parseFloat(paddingRight);\n\n setWidth(newWidth);\n setCurrentHeight(\n Math.floor(\n getHeight(newWidth, ratio ?? (autoRatio ? actualRatio : undefined)),\n ),\n );\n }\n }, 200);\n\n updateSize();\n window.addEventListener('resize', updateSize, {passive: true});\n // eslint-disable-next-line consistent-return\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, [actualRatio, autoRatio, disableAutoSizing, playerRef, ratio]);\n\n const playEvents = React.useMemo(\n () => eventsArray?.filter((e: AnalyticsEvent) => e.type === PredefinedEventTypes.Play),\n [eventsArray],\n );\n const stopEvents = React.useMemo(\n () => eventsArray?.filter((e: AnalyticsEvent) => e.type === PredefinedEventTypes.Stop),\n [eventsArray],\n );\n\n const playIcon = React.useMemo(() => {\n const {theme, type} = playButton || {};\n return (\n <VideoButton\n {...playButton}\n theme={theme || PlayButtonThemes.Blue}\n type={type || PlayButtonType.Default}\n />\n );\n }, [playButton]);\n\n const changeMute = React.useCallback(\n (isMuted: boolean) => {\n if (\n isMuted &&\n playerRef &&\n controls === MediaVideoControlsType.Custom &&\n customControlsType === CustomControlsType.WithMuteButton\n ) {\n playerRef.seekTo(0);\n setPlayedPercent(0);\n }\n\n const events = isMuted ? playEvents : stopEvents;\n handleAnalytics(events);\n\n if (isMuted) {\n setProps({playingVideoRef: ref.current});\n }\n\n // In order to the progress bar to update (equals 0) before displaying\n setTimeout(() => setMuted(!isMuted), 0);\n },\n [\n playerRef,\n customControlsType,\n playEvents,\n stopEvents,\n handleAnalytics,\n setProps,\n controls,\n ],\n );\n\n const handleClickPreview = React.useCallback(() => {\n setIsPlaying(true);\n onClickPreview?.();\n\n handleAnalytics(playEvents);\n }, [onClickPreview, handleAnalytics, playEvents]);\n\n const onPause = React.useCallback(() => {\n // For support correct state for youtube\n if (\n controls !== MediaVideoControlsType.Custom ||\n customControlsType !== CustomControlsType.WithMuteButton\n ) {\n setIsPlaying(false);\n }\n }, [controls, customControlsType]);\n\n const onStart = React.useCallback(() => {\n if (!autoPlay && !initiallyMuted) {\n setMuted(false);\n }\n }, [autoPlay, initiallyMuted]);\n\n const onPlay = React.useCallback(() => {\n setIsPlaying(true);\n\n if (\n controls === MediaVideoControlsType.Custom &&\n customControlsType === CustomControlsType.WithMuteButton\n ) {\n if (ended) {\n changeMute(false);\n } else if (!isPlaying) {\n changeMute(muted);\n }\n setEnded(false);\n }\n }, [changeMute, controls, customControlsType, ended, isPlaying, muted]);\n\n const onReady = React.useCallback(\n (player: _ReactPlayer) => {\n setPlayerRef(player);\n const videoElement = player.getInternalPlayer();\n const videoWidth = videoElement.videoWidth as number | undefined;\n const videoHeight = videoElement.videoHeight as number | undefined;\n if (videoWidth && videoHeight) {\n setActualRatio(videoHeight / videoWidth);\n onIntrinsicSizeChange?.({width: videoWidth, height: videoHeight});\n }\n },\n [onIntrinsicSizeChange],\n );\n\n const onProgress: ReactPlayerProps['onProgress'] = React.useCallback(\n ({played, playedSeconds}: PlayerPropgress) => {\n setPlayedPercent(played);\n\n if (loop) {\n const {start = 0, end = duration} = typeof loop === 'boolean' ? {} : loop;\n\n // Youtube videos not muted after finishing playing and start again.\n // 'onEnded' does not fire when 'loop' is set to true.\n // It is custom loop with muted sound after finishing playing and start again.\n if (end !== null && playedSeconds >= end) {\n setIsPlaying(true);\n playerRef?.seekTo(start);\n }\n }\n\n if (played === 1) {\n setMuted(true);\n }\n },\n [duration, loop, playerRef],\n );\n\n const onDuration = React.useCallback((currentDuration: number) => {\n setDuration(currentDuration);\n }, []);\n\n const onEnded = React.useCallback(() => {\n setEnded(true);\n }, []);\n\n const onPlayClick = React.useCallback(() => {\n if (isPlaying) {\n onPause();\n } else {\n onPlay();\n }\n }, [isPlaying, onPlay, onPause]);\n\n const handleClick = React.useCallback(() => {\n buttonRef.current?.click();\n\n if (controls === MediaVideoControlsType.Custom) {\n if (customControlsType === CustomControlsType.WithMuteButton) {\n changeMute(muted);\n } else {\n onPlayClick();\n }\n }\n }, [controls, customControlsType, changeMute, muted, onPlayClick]);\n\n const handleKeyDown = React.useCallback((e: React.KeyboardEvent) => {\n const key = e.key.toLowerCase();\n\n if (key === 'enter') {\n buttonRef.current?.click();\n }\n }, []);\n\n const onFocusIn = React.useCallback(() => setHovered(true), []);\n const onFocusOut = React.useCallback(() => setHovered(false), []);\n\n return (\n <div\n className={b(\n {\n wrapper: !currentHeight,\n controls,\n contain,\n 'auto-ratio': autoRatio,\n },\n className,\n )}\n ref={ref}\n onClick={handleClick}\n onMouseEnter={onFocusIn}\n onMouseLeave={onFocusOut}\n onFocus={onFocusIn}\n onBlur={onFocusOut}\n onKeyDown={handleKeyDown}\n role=\"button\"\n tabIndex={0}\n >\n {isMounted ? (\n <React.Fragment>\n <ReactPlayer\n className={b('player')}\n url={videoSrc}\n muted={muted}\n controls={controls === MediaVideoControlsType.Default}\n height={currentHeight || '100%'}\n width={width || '100%'}\n light={\n previewImgUrl && (\n <img\n className={b('preview-img')}\n src={previewImgUrl}\n onLoad={onPreviewImgLoad}\n alt=\"\"\n aria-hidden={true}\n ref={previewImgRef}\n />\n )\n }\n playing={isPlaying}\n playIcon={playIcon}\n progressInterval={FPS}\n onClickPreview={handleClickPreview}\n onStart={onStart}\n onReady={onReady}\n onPlay={onPlay}\n onPause={\n autoPlay && customControlsType !== CustomControlsType.WithMuteButton\n ? undefined\n : onPause\n } // to prevent pause icon flickering when autoplayed video ends\n onProgress={onProgress}\n onEnded={onEnded}\n onDuration={onDuration}\n aria-label={ariaLabel}\n previewTabIndex={-1}\n config={{\n file: {\n attributes: {\n pip: isMobile ? 'false' : undefined,\n playsinline: isMobile ? '' : undefined,\n disablepictureinpicture: isMobile ? '' : undefined,\n },\n },\n }}\n />\n {controls === MediaVideoControlsType.Custom && (\n <CustomBarControls\n className={customBarControlsClassName}\n mute={{\n isMuted: muted,\n changeMute: (event: React.MouseEvent) => {\n event.stopPropagation();\n changeMute(muted);\n },\n }}\n elapsedTimePercent={playedPercent}\n type={customControlsType}\n isPaused={!isPlaying}\n onPlayClick={onPlayClick}\n muteButtonShown={muteButtonShown}\n shown={hovered && ((!started && !previewImgUrl) || started)}\n positioning={positioning}\n />\n )}\n </React.Fragment>\n ) : null}\n </div>\n );\n },\n);\n\nfunction getHeight(width: number, ratio: number = 9 / 16): number {\n return width * ratio;\n}\n\nfunction getParentElement(element: HTMLElement): HTMLElement {\n const parentElement = element.parentElement;\n\n if (!parentElement) {\n return element;\n }\n\n return parentElement.offsetWidth ? parentElement : getParentElement(parentElement);\n}\n\nexport default ReactPlayerBlock;\n"]}
@@ -22,34 +22,4 @@ unpredictable css rules order in build */
22
22
  .pc-VideoBlock__image-wrapper {
23
23
  height: 100%;
24
24
  width: 100%;
25
- }
26
- .pc-VideoBlock__button {
27
- display: inline-block;
28
- margin: 0;
29
- padding: 0;
30
- font: inherit;
31
- border: none;
32
- outline: none;
33
- color: inherit;
34
- background: none;
35
- cursor: pointer;
36
- display: flex;
37
- justify-content: center;
38
- align-items: center;
39
- position: absolute;
40
- width: 64px;
41
- height: 64px;
42
- color: var(--g-color-base-background);
43
- background-color: var(--g-color-base-brand);
44
- border-radius: 50%;
45
- }
46
- .pc-VideoBlock__button:focus {
47
- outline: 2px solid var(--g-color-line-focus);
48
- outline-offset: 0;
49
- }
50
- .pc-VideoBlock__button:focus:not(:focus-visible) {
51
- outline: 0;
52
- }
53
- .pc-VideoBlock__icon {
54
- margin-left: 1px;
55
25
  }
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { AnalyticsEventsBase } from "../../models/common.js";
3
+ import { VideoButtonProps } from "../VideoButton/VideoButton.js";
3
4
  export declare const AUTOPLAY_ATTRIBUTES: {
4
5
  autoplay: number;
5
6
  mute: number;
@@ -13,7 +14,7 @@ export interface VideoBlockProps extends AnalyticsEventsBase {
13
14
  attributes?: Record<string, string>;
14
15
  className?: string;
15
16
  previewImg?: string;
16
- playButton?: React.ReactNode;
17
+ playButton?: React.ReactNode | VideoButtonProps;
17
18
  playButtonId?: string;
18
19
  height?: number;
19
20
  fullscreen?: boolean;
@@ -5,7 +5,6 @@ exports.getHeight = getHeight;
5
5
  const tslib_1 = require("tslib");
6
6
  const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  const React = tslib_1.__importStar(require("react"));
8
- const icons_1 = require("@gravity-ui/icons");
9
8
  const uikit_1 = require("@gravity-ui/uikit");
10
9
  const debounce_1 = tslib_1.__importDefault(require("lodash/debounce.js"));
11
10
  const uuid_1 = require("uuid");
@@ -13,6 +12,7 @@ const useAnalytics_1 = require("../../hooks/useAnalytics.js");
13
12
  const common_1 = require("../../models/common.js");
14
13
  const utils_1 = require("../../utils/index.js");
15
14
  const Image_1 = tslib_1.__importDefault(require("../Image/Image.js"));
15
+ const VideoButton_1 = tslib_1.__importDefault(require("../VideoButton/VideoButton.js"));
16
16
  const i18n_1 = require("./i18n/index.js");
17
17
  const RECORD_URL = 'https://www.youtube.com/embed/';
18
18
  const STREAM_URL = 'https://www.youtube.com/embed/live_stream?channel=';
@@ -44,6 +44,18 @@ function getYoutubeVideoSrc(stream, record) {
44
44
  function getHeight(width) {
45
45
  return (width / 16) * 9;
46
46
  }
47
+ const isReactNode = (value) => {
48
+ if (value === null || typeof value === 'boolean')
49
+ return true;
50
+ if (typeof value === 'string' || typeof value === 'number')
51
+ return true;
52
+ if (React.isValidElement(value))
53
+ return true;
54
+ if (Array.isArray(value)) {
55
+ return value.every(isReactNode);
56
+ }
57
+ return false;
58
+ };
47
59
  const VideoBlock = (props) => {
48
60
  const { stream, record, videoIframe, attributes, className, id, previewImg, playButton, playButtonId, height, fullscreen, analyticsEvents, autoplay, onImageLoad, } = props;
49
61
  const handleAnalytics = (0, useAnalytics_1.useAnalytics)(common_1.DefaultEventNames.VideoPreview);
@@ -95,10 +107,14 @@ const VideoBlock = (props) => {
95
107
  React.useEffect(() => {
96
108
  setHidePreview(false);
97
109
  }, [src]);
110
+ const buttonProps = React.useMemo(() => isReactNode(playButton)
111
+ ? { customButton: playButton }
112
+ : playButton, [playButton]);
113
+ const buttonLabelId = buttonProps?.customButton ? playButtonId : buttonProps?.id || buttonId;
98
114
  if (!src) {
99
115
  return null;
100
116
  }
101
- return ((0, jsx_runtime_1.jsxs)("div", { className: b(null, className), style: { height: currentHeight }, ref: ref, children: [iframeContent, previewImg && !hidePreview && !fullscreen && ((0, jsx_runtime_1.jsxs)("div", { className: b('preview'), onClick: onPreviewClick, onKeyDown: onPreviewKeyDown, role: "button", tabIndex: 0, "aria-labelledby": playButton ? playButtonId : buttonId, children: [(0, jsx_runtime_1.jsx)(Image_1.default, { src: previewImg, className: b('image'), containerClassName: b('image-wrapper'), onLoad: onImageLoad }), playButton || ((0, jsx_runtime_1.jsx)("button", { title: "Play", id: buttonId, className: b('button'), children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { className: b('icon'), data: icons_1.PlayFill, size: 24 }) }))] }))] }));
117
+ return ((0, jsx_runtime_1.jsxs)("div", { className: b(null, className), style: { height: currentHeight }, ref: ref, children: [iframeContent, previewImg && !hidePreview && !fullscreen && ((0, jsx_runtime_1.jsxs)("div", { className: b('preview'), onClick: onPreviewClick, onKeyDown: onPreviewKeyDown, role: "button", tabIndex: 0, "aria-labelledby": buttonLabelId, children: [(0, jsx_runtime_1.jsx)(Image_1.default, { src: previewImg, className: b('image'), containerClassName: b('image-wrapper'), onLoad: onImageLoad }), (0, jsx_runtime_1.jsx)(VideoButton_1.default, { id: buttonId, ...buttonProps })] }))] }));
102
118
  };
103
119
  exports.default = VideoBlock;
104
120
  //# sourceMappingURL=VideoBlock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"VideoBlock.js","sourceRoot":"../../../../src","sources":["components/VideoBlock/VideoBlock.tsx"],"names":[],"mappings":";;;AAkDA,8BAEC;;;AApDD,qDAA+B;AAE/B,6CAA2C;AAC3C,6CAAqE;AACrE,0EAAuC;AACvC,+BAAkC;AAElC,8DAAsD;AACtD,mDAA2E;AAC3E,gDAAuD;AACvD,sEAAmC;AAEnC,0CAA4B;AAI5B,MAAM,UAAU,GAAG,gCAAgC,CAAC;AACpD,MAAM,UAAU,GAAG,oDAAoD,CAAC;AACxE,MAAM,SAAS,GAAG,mBAAmB,CAAC;AACtC,MAAM,SAAS,GAAG,sBAAsB,CAAC;AACzC,MAAM,cAAc,GAAG,GAAG,CAAC;AAEd,QAAA,mBA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AAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,gBAAQ,EAAE,IAAI,EAAE,EAAE,GAAI,GACnD,CACZ,IACC,CACT,IACC,CACT,CAAC;AACN,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {PlayFill} from '@gravity-ui/icons';\nimport {Icon, useActionHandlers, useUniqId} from '@gravity-ui/uikit';\nimport debounce from 'lodash/debounce';\nimport {v4 as uuidv4} from 'uuid';\n\nimport {useAnalytics} from '../../hooks/useAnalytics';\nimport {AnalyticsEventsBase, DefaultEventNames} from '../../models/common';\nimport {block, getPageSearchParams} from '../../utils';\nimport Image from '../Image/Image';\n\nimport {i18n} from './i18n';\n\nimport './VideoBlock.scss';\n\nconst RECORD_URL = 'https://www.youtube.com/embed/';\nconst STREAM_URL = 'https://www.youtube.com/embed/live_stream?channel=';\nconst RECORD_RE = /[0-9A-Za-z_-]{11}/;\nconst STREAM_RE = /[0-9A-Za-z_-]{23,25}/;\nconst AUTOPLAY_DELAY = 300;\n\nexport const AUTOPLAY_ATTRIBUTES = {\n autoplay: 1,\n mute: 1,\n};\nconst NO_AUTOPLAY_ATTRIBUTES = {\n autoplay: 0,\n};\n\nconst b = block('VideoBlock');\n\nfunction getYoutubeVideoSrc(stream?: string, record?: string) {\n if (!stream && !record) {\n return null;\n }\n\n const [videoLink, url, re] = stream\n ? [stream, STREAM_URL, STREAM_RE]\n : [record, RECORD_URL, RECORD_RE];\n const match = videoLink?.match(re);\n let src;\n\n if (match && match.length) {\n src = url + match[0];\n }\n\n return src;\n}\n\nexport function getHeight(width: number): number {\n return (width / 16) * 9;\n}\n\nexport interface VideoBlockProps extends AnalyticsEventsBase {\n id?: string;\n stream?: string;\n record?: string;\n videoIframe?: string;\n attributes?: Record<string, string>;\n className?: string;\n previewImg?: string;\n playButton?: React.ReactNode;\n playButtonId?: string;\n height?: number;\n fullscreen?: boolean;\n autoplay?: boolean;\n onImageLoad?: () => void;\n}\n\nconst VideoBlock = (props: VideoBlockProps) => {\n const {\n stream,\n record,\n videoIframe,\n attributes,\n className,\n id,\n previewImg,\n playButton,\n playButtonId,\n height,\n fullscreen,\n analyticsEvents,\n autoplay,\n onImageLoad,\n } = props;\n const handleAnalytics = useAnalytics(DefaultEventNames.VideoPreview);\n\n const src = videoIframe ? videoIframe : getYoutubeVideoSrc(stream, record);\n const ref = React.useRef<HTMLDivElement>(null);\n const [hidePreview, setHidePreview] = React.useState(false);\n const [currentHeight, setCurrentHeight] = React.useState(height || undefined);\n const fullId = React.useMemo(() => id || uuidv4(), [id]);\n const buttonId = useUniqId();\n\n const [isPlaying, setIsPlaying] = React.useState(!previewImg);\n\n const iframeSrc = React.useMemo(() => {\n if (src && isPlaying) {\n try {\n const url = new URL(src);\n const searchParams = getPageSearchParams({\n ...(attributes || {}),\n ...(previewImg || autoplay ? AUTOPLAY_ATTRIBUTES : NO_AUTOPLAY_ATTRIBUTES),\n });\n\n searchParams.forEach((value, key) => {\n url.searchParams.set(key, value);\n });\n\n return url.href;\n } catch {\n return src;\n }\n }\n\n return undefined;\n }, [attributes, autoplay, isPlaying, previewImg, src]);\n\n const onPreviewClick = React.useCallback(() => {\n handleAnalytics(analyticsEvents);\n\n setIsPlaying(true);\n\n setTimeout(() => setHidePreview(true), AUTOPLAY_DELAY);\n }, [handleAnalytics, analyticsEvents]);\n\n const {onKeyDown: onPreviewKeyDown} = useActionHandlers(onPreviewClick);\n\n React.useEffect(() => {\n const updateSize = debounce(() => {\n setCurrentHeight(\n ref.current ? Math.round(getHeight(ref.current.offsetWidth)) : undefined,\n );\n }, 100);\n\n updateSize();\n window.addEventListener('resize', updateSize, {passive: true});\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, [height]);\n\n const iframeContent = React.useMemo(() => {\n return (\n <iframe\n id={fullId}\n src={iframeSrc}\n width=\"100%\"\n height=\"100%\"\n title={i18n('iframe-title')}\n frameBorder=\"0\"\n allowFullScreen={true}\n scrolling=\"no\"\n allow=\"autoplay; fullscreen; encrypted-media; accelerometer; gyroscope; picture-in-picture; clipboard-write; web-share; screen-wake-lock\"\n loading=\"lazy\"\n />\n );\n }, [fullId, iframeSrc]);\n\n React.useEffect(() => {\n setHidePreview(false);\n }, [src]);\n\n if (!src) {\n return null;\n }\n\n return (\n <div className={b(null, className)} style={{height: currentHeight}} ref={ref}>\n {iframeContent}\n {previewImg && !hidePreview && !fullscreen && (\n <div\n className={b('preview')}\n onClick={onPreviewClick}\n onKeyDown={onPreviewKeyDown}\n role=\"button\"\n tabIndex={0}\n aria-labelledby={playButton ? playButtonId : buttonId}\n >\n <Image\n src={previewImg}\n className={b('image')}\n containerClassName={b('image-wrapper')}\n onLoad={onImageLoad}\n />\n {playButton || (\n <button title=\"Play\" id={buttonId} className={b('button')}>\n <Icon className={b('icon')} data={PlayFill} size={24} />\n </button>\n )}\n </div>\n )}\n </div>\n );\n};\n\nexport default VideoBlock;\n"]}
1
+ {"version":3,"file":"VideoBlock.js","sourceRoot":"../../../../src","sources":["components/VideoBlock/VideoBlock.tsx"],"names":[],"mappings":";;;AAkDA,8BAEC;;;AApDD,qDAA+B;AAE/B,6CAA+D;AAC/D,0EAAuC;AACvC,+BAAkC;AAElC,8DAAsD;AACtD,mDAA2E;AAC3E,gDAAuD;AACvD,sEAAmC;AACnC,wFAAyE;AAEzE,0CAA4B;AAI5B,MAAM,UAAU,GAAG,gCAAgC,CAAC;AACpD,MAAM,UAAU,GAAG,oDAAoD,CAAC;AACxE,MAAM,SAAS,GAAG,mBAAmB,CAAC;AACtC,MAAM,SAAS,GAAG,sBAAsB,CAAC;AACzC,MAAM,cAAc,GAAG,GAAG,CAAC;AAEd,QAAA,mBAAmB,GAAG;IAC/B,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,CAAC;CACV,CAAC;AACF,MAAM,sBAAsB,GAAG;IAC3B,QAAQ,EAAE,CAAC;CACd,CAAC;AAEF,MAAM,CAAC,GAAG,IAAA,aAAK,EA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AAM,EAAE,aAAa,EAAC,EAAE,GAAG,EAAE,GAAG,aACvE,aAAa,EACb,UAAU,IAAI,CAAC,WAAW,IAAI,CAAC,UAAU,IAAI,CAC1C,iCACI,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,EACvB,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,gBAAgB,EAC3B,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,CAAC,qBACM,aAAa,aAE9B,uBAAC,eAAK,IACF,GAAG,EAAE,UAAU,EACf,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,EACrB,kBAAkB,EAAE,CAAC,CAAC,eAAe,CAAC,EACtC,MAAM,EAAE,WAAW,GACrB,EACF,uBAAC,qBAAW,IAAC,EAAE,EAAE,QAAQ,KAAM,WAAW,GAAI,IAC5C,CACT,IACC,CACT,CAAC;AACN,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {useActionHandlers, useUniqId} from '@gravity-ui/uikit';\nimport debounce from 'lodash/debounce';\nimport {v4 as uuidv4} from 'uuid';\n\nimport {useAnalytics} from '../../hooks/useAnalytics';\nimport {AnalyticsEventsBase, DefaultEventNames} from '../../models/common';\nimport {block, getPageSearchParams} from '../../utils';\nimport Image from '../Image/Image';\nimport VideoButton, {VideoButtonProps} from '../VideoButton/VideoButton';\n\nimport {i18n} from './i18n';\n\nimport './VideoBlock.scss';\n\nconst RECORD_URL = 'https://www.youtube.com/embed/';\nconst STREAM_URL = 'https://www.youtube.com/embed/live_stream?channel=';\nconst RECORD_RE = /[0-9A-Za-z_-]{11}/;\nconst STREAM_RE = /[0-9A-Za-z_-]{23,25}/;\nconst AUTOPLAY_DELAY = 300;\n\nexport const AUTOPLAY_ATTRIBUTES = {\n autoplay: 1,\n mute: 1,\n};\nconst NO_AUTOPLAY_ATTRIBUTES = {\n autoplay: 0,\n};\n\nconst b = block('VideoBlock');\n\nfunction getYoutubeVideoSrc(stream?: string, record?: string) {\n if (!stream && !record) {\n return null;\n }\n\n const [videoLink, url, re] = stream\n ? [stream, STREAM_URL, STREAM_RE]\n : [record, RECORD_URL, RECORD_RE];\n const match = videoLink?.match(re);\n let src;\n\n if (match && match.length) {\n src = url + match[0];\n }\n\n return src;\n}\n\nexport function getHeight(width: number): number {\n return (width / 16) * 9;\n}\n\nconst isReactNode = (value: React.ReactNode | VideoButtonProps) => {\n if (value === null || typeof value === 'boolean') return true;\n\n if (typeof value === 'string' || typeof value === 'number') return true;\n\n if (React.isValidElement(value)) return true;\n\n if (Array.isArray(value)) {\n return value.every(isReactNode);\n }\n\n return false;\n};\n\nexport interface VideoBlockProps extends AnalyticsEventsBase {\n id?: string;\n stream?: string;\n record?: string;\n videoIframe?: string;\n attributes?: Record<string, string>;\n className?: string;\n previewImg?: string;\n playButton?: React.ReactNode | VideoButtonProps;\n playButtonId?: string;\n height?: number;\n fullscreen?: boolean;\n autoplay?: boolean;\n onImageLoad?: () => void;\n}\n\nconst VideoBlock = (props: VideoBlockProps) => {\n const {\n stream,\n record,\n videoIframe,\n attributes,\n className,\n id,\n previewImg,\n playButton,\n playButtonId,\n height,\n fullscreen,\n analyticsEvents,\n autoplay,\n onImageLoad,\n } = props;\n const handleAnalytics = useAnalytics(DefaultEventNames.VideoPreview);\n\n const src = videoIframe ? videoIframe : getYoutubeVideoSrc(stream, record);\n const ref = React.useRef<HTMLDivElement>(null);\n const [hidePreview, setHidePreview] = React.useState(false);\n const [currentHeight, setCurrentHeight] = React.useState(height || undefined);\n const fullId = React.useMemo(() => id || uuidv4(), [id]);\n const buttonId = useUniqId();\n\n const [isPlaying, setIsPlaying] = React.useState(!previewImg);\n\n const iframeSrc = React.useMemo(() => {\n if (src && isPlaying) {\n try {\n const url = new URL(src);\n const searchParams = getPageSearchParams({\n ...(attributes || {}),\n ...(previewImg || autoplay ? AUTOPLAY_ATTRIBUTES : NO_AUTOPLAY_ATTRIBUTES),\n });\n\n searchParams.forEach((value, key) => {\n url.searchParams.set(key, value);\n });\n\n return url.href;\n } catch {\n return src;\n }\n }\n\n return undefined;\n }, [attributes, autoplay, isPlaying, previewImg, src]);\n\n const onPreviewClick = React.useCallback(() => {\n handleAnalytics(analyticsEvents);\n\n setIsPlaying(true);\n\n setTimeout(() => setHidePreview(true), AUTOPLAY_DELAY);\n }, [handleAnalytics, analyticsEvents]);\n\n const {onKeyDown: onPreviewKeyDown} = useActionHandlers(onPreviewClick);\n\n React.useEffect(() => {\n const updateSize = debounce(() => {\n setCurrentHeight(\n ref.current ? Math.round(getHeight(ref.current.offsetWidth)) : undefined,\n );\n }, 100);\n\n updateSize();\n window.addEventListener('resize', updateSize, {passive: true});\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, [height]);\n\n const iframeContent = React.useMemo(() => {\n return (\n <iframe\n id={fullId}\n src={iframeSrc}\n width=\"100%\"\n height=\"100%\"\n title={i18n('iframe-title')}\n frameBorder=\"0\"\n allowFullScreen={true}\n scrolling=\"no\"\n allow=\"autoplay; fullscreen; encrypted-media; accelerometer; gyroscope; picture-in-picture; clipboard-write; web-share; screen-wake-lock\"\n loading=\"lazy\"\n />\n );\n }, [fullId, iframeSrc]);\n\n React.useEffect(() => {\n setHidePreview(false);\n }, [src]);\n\n const buttonProps = React.useMemo(\n () =>\n isReactNode(playButton)\n ? {customButton: playButton as React.ReactNode}\n : (playButton as VideoButtonProps | undefined),\n [playButton],\n );\n const buttonLabelId = buttonProps?.customButton ? playButtonId : buttonProps?.id || buttonId;\n\n if (!src) {\n return null;\n }\n\n return (\n <div className={b(null, className)} style={{height: currentHeight}} ref={ref}>\n {iframeContent}\n {previewImg && !hidePreview && !fullscreen && (\n <div\n className={b('preview')}\n onClick={onPreviewClick}\n onKeyDown={onPreviewKeyDown}\n role=\"button\"\n tabIndex={0}\n aria-labelledby={buttonLabelId}\n >\n <Image\n src={previewImg}\n className={b('image')}\n containerClassName={b('image-wrapper')}\n onLoad={onImageLoad}\n />\n <VideoButton id={buttonId} {...buttonProps} />\n </div>\n )}\n </div>\n );\n};\n\nexport default VideoBlock;\n"]}
@@ -0,0 +1,64 @@
1
+ /* use this for style redefinitions to awoid problems with
2
+ unpredictable css rules order in build */
3
+ .pc-video-button {
4
+ display: inline-block;
5
+ margin: 0;
6
+ padding: 0;
7
+ font: inherit;
8
+ border: none;
9
+ outline: none;
10
+ color: inherit;
11
+ background: none;
12
+ cursor: pointer;
13
+ display: flex;
14
+ justify-content: center;
15
+ align-items: center;
16
+ position: absolute;
17
+ width: 64px;
18
+ height: 64px;
19
+ border-radius: 50%;
20
+ transition: color 0.4s, background-color 0.4s;
21
+ }
22
+ .pc-video-button:focus {
23
+ outline: 2px solid var(--g-color-line-focus);
24
+ outline-offset: 0;
25
+ }
26
+ .pc-video-button:focus:not(:focus-visible) {
27
+ outline: 0;
28
+ }
29
+ .pc-video-button_theme_blue {
30
+ color: var(--g-color-base-background);
31
+ background-color: var(--g-color-base-brand);
32
+ }
33
+ .pc-video-button_theme_blue:hover {
34
+ background-color: var(--g-color-base-brand-hover);
35
+ }
36
+ .pc-video-button_theme_grey {
37
+ color: var(--pc-text-header-color);
38
+ background-color: #eff2f8;
39
+ }
40
+ .pc-video-button_theme_custom {
41
+ color: var(--pc-video-button-triangle-color);
42
+ background-color: var(--pc-video-button-circle-color);
43
+ }
44
+ .pc-video-button_theme_custom:hover {
45
+ color: var(--pc-video-button-triangle-hover-color, var(--pc-video-button-triangle-color));
46
+ background-color: var(--pc-video-button-circle-hover-color, var(--pc-video-button-circle-color));
47
+ }
48
+ .pc-video-button_text {
49
+ padding: 16px 32px;
50
+ font-weight: 400;
51
+ font-size: 24px;
52
+ line-height: 32px;
53
+ width: auto;
54
+ height: auto;
55
+ }
56
+ .pc-video-button__icon {
57
+ margin-left: 1px;
58
+ }
59
+ @media only screen and (max-width: 577px) {
60
+ .pc-video-button_text {
61
+ font-size: 20px;
62
+ line-height: 24px;
63
+ }
64
+ }
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import { PlayButtonProps } from "../../models/index.js";
3
+ export interface VideoButtonProps extends PlayButtonProps {
4
+ customButton?: React.ReactNode;
5
+ ref?: React.LegacyRef<HTMLButtonElement>;
6
+ id?: string;
7
+ }
8
+ declare const VideoButton: ({ customButton, text, type, theme: initialTheme, className, ref, id, }: VideoButtonProps) => string | number | true | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element;
9
+ export default VideoButton;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ const icons_1 = require("@gravity-ui/icons");
7
+ const uikit_1 = require("@gravity-ui/uikit");
8
+ const projectSettingsContext_1 = require("../../context/projectSettingsContext/index.js");
9
+ const theme_1 = require("../../context/theme/index.js");
10
+ const models_1 = require("../../models/index.js");
11
+ const utils_1 = require("../../utils/index.js");
12
+ const i18n_1 = require("../ReactPlayer/i18n/index.js");
13
+ const b = (0, utils_1.block)('video-button');
14
+ const VideoButton = ({ customButton, text, type, theme: initialTheme, className, ref, id, }) => {
15
+ const { defaultVideoButtonSettings } = React.useContext(projectSettingsContext_1.ProjectSettingsContext);
16
+ const currentTheme = (0, theme_1.useTheme)();
17
+ const playButtonContent = React.useMemo(() => {
18
+ switch (type) {
19
+ case models_1.PlayButtonType.Text:
20
+ return text;
21
+ case models_1.PlayButtonType.Default:
22
+ default:
23
+ return (0, jsx_runtime_1.jsx)(uikit_1.Icon, { className: b('icon'), data: icons_1.PlayFill, size: 24 });
24
+ }
25
+ }, [text, type]);
26
+ const theme = initialTheme || defaultVideoButtonSettings?.theme || models_1.PlayButtonThemes.Blue;
27
+ const style = React.useMemo(() => {
28
+ if (theme !== models_1.PlayButtonThemes.Custom) {
29
+ return undefined;
30
+ }
31
+ const themedColors = defaultVideoButtonSettings?.colors
32
+ ? (0, utils_1.getThemedValue)(defaultVideoButtonSettings.colors, currentTheme)
33
+ : undefined;
34
+ const resolveColor = (colorName) => {
35
+ return themedColors?.[colorName];
36
+ };
37
+ return {
38
+ '--pc-video-button-circle-color': resolveColor('circleColor'),
39
+ '--pc-video-button-circle-hover-color': resolveColor('circleHoverColor'),
40
+ '--pc-video-button-triangle-color': resolveColor('triangleColor'),
41
+ '--pc-video-button-triangle-hover-color': resolveColor('triangleHoverColor'),
42
+ };
43
+ }, [currentTheme, defaultVideoButtonSettings?.colors, theme]);
44
+ if (customButton) {
45
+ return customButton;
46
+ }
47
+ return ((0, jsx_runtime_1.jsx)("button", { className: b({ theme, text: Boolean(text) }, className), "aria-label": (0, i18n_1.i18n)('play'), ref: ref, id: id, style: style, children: playButtonContent }));
48
+ };
49
+ exports.default = VideoButton;
50
+ //# sourceMappingURL=VideoButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VideoButton.js","sourceRoot":"../../../../src","sources":["components/VideoButton/VideoButton.tsx"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAE/B,6CAA2C;AAC3C,6CAAuC;AAEvC,0FAA4E;AAC5E,wDAA6C;AAC7C,kDAAiG;AACjG,gDAAkD;AAClD,uDAAyC;AAUzC,MAAM,CAAC,GAAG,IAAA,aAAK,EAAC,cAAc,CAAC,CAAC;AAEhC,MAAM,WAAW,GAAG,CAAC,EACjB,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,KAAK,EAAE,YAAY,EACnB,SAAS,EACT,GAAG,EACH,EAAE,GACa,EAAE,EAAE;IACnB,MAAM,EAAC,0BAA0B,EAAC,GAAG,KAAK,CAAC,UAAU,CAAC,+CAAsB,CAAC,CAAC;IAC9E,MAAM,YAAY,GAAG,IAAA,gBAAQ,GAAE,CAAC;IAEhC,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACzC,QAAQ,IAAI,EAAE,CAAC;YACX,KAAK,uBAAc,CAAC,IAAI;gBACpB,OAAO,IAAI,CAAC;YAChB,KAAK,uBAAc,CAAC,OA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,EAAC,MAAM,CAAC,EACxB,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,KAAK,YAEX,iBAAiB,GACb,CACZ,CAAC;AACN,CAAC,CAAC;AAEF,kBAAe,WAAW,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {PlayFill} from '@gravity-ui/icons';\nimport {Icon} from '@gravity-ui/uikit';\n\nimport {ProjectSettingsContext} from '../../context/projectSettingsContext';\nimport {useTheme} from '../../context/theme';\nimport {PlayButtonColors, PlayButtonProps, PlayButtonThemes, PlayButtonType} from '../../models';\nimport {block, getThemedValue} from '../../utils';\nimport {i18n} from '../ReactPlayer/i18n';\n\nimport './VideoButton.scss';\n\nexport interface VideoButtonProps extends PlayButtonProps {\n customButton?: React.ReactNode;\n ref?: React.LegacyRef<HTMLButtonElement>;\n id?: string;\n}\n\nconst b = block('video-button');\n\nconst VideoButton = ({\n customButton,\n text,\n type,\n theme: initialTheme,\n className,\n ref,\n id,\n}: VideoButtonProps) => {\n const {defaultVideoButtonSettings} = React.useContext(ProjectSettingsContext);\n const currentTheme = useTheme();\n\n const playButtonContent = React.useMemo(() => {\n switch (type) {\n case PlayButtonType.Text:\n return text;\n case PlayButtonType.Default:\n default:\n return <Icon className={b('icon')} data={PlayFill} size={24} />;\n }\n }, [text, type]);\n\n const theme = initialTheme || defaultVideoButtonSettings?.theme || PlayButtonThemes.Blue;\n\n const style = React.useMemo(() => {\n if (theme !== PlayButtonThemes.Custom) {\n return undefined;\n }\n\n const themedColors = defaultVideoButtonSettings?.colors\n ? getThemedValue(defaultVideoButtonSettings.colors, currentTheme)\n : undefined;\n\n const resolveColor = (colorName: keyof PlayButtonColors) => {\n return themedColors?.[colorName];\n };\n\n return {\n '--pc-video-button-circle-color': resolveColor('circleColor'),\n '--pc-video-button-circle-hover-color': resolveColor('circleHoverColor'),\n '--pc-video-button-triangle-color': resolveColor('triangleColor'),\n '--pc-video-button-triangle-hover-color': resolveColor('triangleHoverColor'),\n } as React.CSSProperties;\n }, [currentTheme, defaultVideoButtonSettings?.colors, theme]);\n\n if (customButton) {\n return customButton;\n }\n\n return (\n <button\n className={b({theme, text: Boolean(text)}, className)}\n aria-label={i18n('play')}\n ref={ref}\n id={id}\n style={style}\n >\n {playButtonContent}\n </button>\n );\n};\n\nexport default VideoButton;\n"]}
@@ -1,8 +1,15 @@
1
1
  import * as React from 'react';
2
+ import { PlayButtonColors, PlayButtonProps } from "../../models/index.js";
3
+ import { ThemeSupporting } from "../../utils/index.js";
4
+ type DefaultVideoButtonSettings = Pick<PlayButtonProps, 'theme'> & {
5
+ colors?: ThemeSupporting<PlayButtonColors>;
6
+ };
2
7
  export interface ProjectSettingsContextProps {
3
8
  disableCompress?: boolean;
4
9
  isAnimationEnabled?: boolean;
5
10
  renderInvisibleBlocks?: boolean;
6
11
  defaultYandexFormTheme?: string;
12
+ defaultVideoButtonSettings?: DefaultVideoButtonSettings;
7
13
  }
8
14
  export declare const ProjectSettingsContext: React.Context<ProjectSettingsContextProps>;
15
+ export {};