@gravity-ui/page-constructor 5.18.1-alpha.2 → 5.18.1-alpha.3
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/build/cjs/blocks/Banner/Banner.js +2 -2
- package/build/cjs/blocks/CardLayout/schema.d.ts +32 -0
- package/build/cjs/blocks/ContentLayout/schema.d.ts +34 -6
- package/build/cjs/blocks/Header/Header.css +3 -0
- package/build/cjs/blocks/Header/Header.js +2 -1
- package/build/cjs/blocks/Header/schema.d.ts +30 -3
- package/build/cjs/blocks/HeaderSlider/schema.d.ts +11 -1
- package/build/cjs/blocks/Media/schema.d.ts +16 -2
- package/build/cjs/blocks/PromoFeaturesBlock/schema.d.ts +8 -1
- package/build/cjs/blocks/Slider/Arrow/Arrow.css +1 -1
- package/build/cjs/blocks/Slider/Slider.css +20 -1
- package/build/cjs/blocks/Slider/Slider.js +83 -29
- package/build/cjs/blocks/Slider/i18n/en.json +3 -1
- package/build/cjs/blocks/Slider/i18n/index.d.ts +1 -1
- package/build/cjs/blocks/Slider/i18n/ru.json +3 -1
- package/build/cjs/blocks/Slider/utils.d.ts +10 -0
- package/build/cjs/blocks/Slider/utils.js +85 -1
- package/build/cjs/blocks/SliderNew/Arrow/Arrow.d.ts +3 -1
- package/build/cjs/blocks/SliderNew/Arrow/Arrow.js +2 -2
- package/build/cjs/blocks/SliderNew/Slider.css +4 -1
- package/build/cjs/blocks/SliderNew/Slider.js +20 -8
- package/build/cjs/blocks/SliderNew/i18n/en.json +3 -1
- package/build/cjs/blocks/SliderNew/i18n/index.d.ts +1 -1
- package/build/cjs/blocks/SliderNew/i18n/ru.json +3 -1
- package/build/cjs/blocks/SliderNew/useSlider.d.ts +8 -6
- package/build/cjs/blocks/SliderNew/useSlider.js +4 -2
- package/build/cjs/blocks/SliderNew/useSliderPagination.d.ts +9 -0
- package/build/cjs/blocks/SliderNew/useSliderPagination.js +36 -0
- package/build/cjs/blocks/SliderNew/utils.d.ts +2 -0
- package/build/cjs/blocks/SliderNew/utils.js +13 -1
- package/build/cjs/blocks/Tabs/schema.d.ts +8 -1
- package/build/cjs/components/ButtonTabs/ButtonTabs.js +3 -2
- package/build/cjs/components/DefaultVideo/DefaultVideo.js +3 -3
- package/build/cjs/components/FullscreenImage/FullscreenImage.css +6 -2
- package/build/cjs/components/HeaderBreadcrumbs/HeaderBreadcrumbs.css +14 -11
- package/build/cjs/components/HeaderBreadcrumbs/HeaderBreadcrumbs.js +4 -2
- package/build/cjs/components/Image/Image.js +2 -2
- package/build/cjs/components/Image/schema.d.ts +40 -0
- package/build/cjs/components/Image/schema.js +8 -0
- package/build/cjs/components/ImageBase/ImageBase.d.ts +1 -1
- package/build/cjs/components/ImageBase/ImageBase.js +8 -2
- package/build/cjs/components/Media/Media.js +4 -3
- package/build/cjs/components/Media/Video/Video.js +2 -2
- package/build/cjs/components/ReactPlayer/ReactPlayer.css +7 -0
- package/build/cjs/components/ReactPlayer/ReactPlayer.d.ts +1 -0
- package/build/cjs/components/ReactPlayer/ReactPlayer.js +15 -4
- package/build/cjs/components/VideoBlock/VideoBlock.d.ts +1 -0
- package/build/cjs/components/VideoBlock/VideoBlock.js +24 -37
- package/build/cjs/constructor-items.d.ts +4 -4
- package/build/cjs/containers/PageConstructor/PageConstructor.js +3 -1
- package/build/cjs/context/imageContext/imageContext.d.ts +2 -3
- package/build/cjs/context/projectSettingsContext/ProjectSettingsContext.d.ts +1 -0
- package/build/cjs/editor/components/AddBlock/AddBlock.js +23 -6
- package/build/cjs/editor/data/index.d.ts +3 -2
- package/build/cjs/editor/data/index.js +19 -12
- package/build/cjs/models/constructor-items/common.d.ts +9 -4
- package/build/cjs/models/constructor-items/sub-blocks.d.ts +2 -1
- package/build/cjs/models/navigation.d.ts +8 -0
- package/build/cjs/navigation/components/DesktopNavigation/DesktopNavigation.css +42 -3
- package/build/cjs/navigation/components/DesktopNavigation/DesktopNavigation.d.ts +1 -1
- package/build/cjs/navigation/components/DesktopNavigation/DesktopNavigation.js +7 -2
- package/build/cjs/navigation/components/Logo/Logo.d.ts +1 -1
- package/build/cjs/navigation/components/Logo/Logo.js +3 -1
- package/build/cjs/navigation/components/MobileNavigation/MobileNavigation.d.ts +1 -1
- package/build/cjs/navigation/components/MobileNavigation/MobileNavigation.js +3 -1
- package/build/cjs/navigation/components/Navigation/Navigation.d.ts +2 -2
- package/build/cjs/navigation/components/Navigation/Navigation.js +5 -24
- package/build/cjs/navigation/components/NavigationItem/NavigationItem.d.ts +1 -1
- package/build/cjs/navigation/components/NavigationItem/NavigationItem.js +3 -1
- package/build/cjs/navigation/components/NavigationItem/hooks/useNavigationItemMap.d.ts +5 -5
- package/build/cjs/navigation/components/NavigationListItem/NavigationListItem.d.ts +1 -1
- package/build/cjs/navigation/components/NavigationListItem/NavigationListItem.js +3 -1
- package/build/cjs/navigation/components/Standalone/index.d.ts +2 -2
- package/build/cjs/navigation/containers/Layout/Layout.js +2 -1
- package/build/cjs/navigation/hooks/index.d.ts +2 -0
- package/build/cjs/navigation/hooks/index.js +10 -0
- package/build/cjs/navigation/hooks/useActiveNavItem.d.ts +26 -0
- package/build/cjs/navigation/hooks/useActiveNavItem.js +15 -0
- package/build/cjs/navigation/hooks/useShowBorder.d.ts +2 -0
- package/build/cjs/navigation/hooks/useShowBorder.js +21 -0
- package/build/cjs/navigation/index.d.ts +14 -0
- package/build/cjs/navigation/index.js +16 -4
- package/build/cjs/navigation/models.d.ts +1 -0
- package/build/cjs/schema/constants.d.ts +16 -1
- package/build/cjs/schema/validators/common.d.ts +14 -1
- package/build/cjs/schema/validators/common.js +8 -1
- package/build/cjs/sub-blocks/BackgroundCard/schema.d.ts +8 -0
- package/build/cjs/sub-blocks/BannerCard/BannerCard.js +3 -3
- package/build/cjs/sub-blocks/Content/Content.css +4 -4
- package/build/cjs/sub-blocks/HubspotForm/HubspotForm.css +8 -4
- package/build/cjs/sub-blocks/ImageCard/ImageCard.css +34 -1
- package/build/cjs/sub-blocks/ImageCard/ImageCard.js +1 -1
- package/build/cjs/sub-blocks/LayoutItem/schema.d.ts +8 -1
- package/build/cjs/sub-blocks/LayoutItem/utils.d.ts +1 -1
- package/build/cjs/sub-blocks/LayoutItem/utils.js +1 -1
- package/build/cjs/sub-blocks/MediaCard/schema.d.ts +8 -1
- package/build/cjs/text-transform/utils.js +1 -1
- package/build/esm/blocks/Banner/Banner.js +2 -2
- package/build/esm/blocks/CardLayout/schema.d.ts +32 -0
- package/build/esm/blocks/ContentLayout/schema.d.ts +34 -6
- package/build/esm/blocks/Header/Header.css +3 -0
- package/build/esm/blocks/Header/Header.js +2 -1
- package/build/esm/blocks/Header/schema.d.ts +30 -3
- package/build/esm/blocks/HeaderSlider/schema.d.ts +11 -1
- package/build/esm/blocks/Media/schema.d.ts +16 -2
- package/build/esm/blocks/PromoFeaturesBlock/schema.d.ts +8 -1
- package/build/esm/blocks/Slider/Arrow/Arrow.css +1 -1
- package/build/esm/blocks/Slider/Slider.css +20 -1
- package/build/esm/blocks/Slider/Slider.js +84 -30
- package/build/esm/blocks/Slider/i18n/en.json +3 -1
- package/build/esm/blocks/Slider/i18n/index.d.ts +1 -1
- package/build/esm/blocks/Slider/i18n/ru.json +3 -1
- package/build/esm/blocks/Slider/utils.d.ts +10 -0
- package/build/esm/blocks/Slider/utils.js +82 -0
- package/build/esm/blocks/SliderNew/Arrow/Arrow.d.ts +3 -1
- package/build/esm/blocks/SliderNew/Arrow/Arrow.js +2 -2
- package/build/esm/blocks/SliderNew/Slider.css +4 -1
- package/build/esm/blocks/SliderNew/Slider.js +20 -8
- package/build/esm/blocks/SliderNew/i18n/en.json +3 -1
- package/build/esm/blocks/SliderNew/i18n/index.d.ts +1 -1
- package/build/esm/blocks/SliderNew/i18n/ru.json +3 -1
- package/build/esm/blocks/SliderNew/useSlider.d.ts +8 -6
- package/build/esm/blocks/SliderNew/useSlider.js +6 -3
- package/build/esm/blocks/SliderNew/useSliderPagination.d.ts +9 -0
- package/build/esm/blocks/SliderNew/useSliderPagination.js +32 -0
- package/build/esm/blocks/SliderNew/utils.d.ts +2 -0
- package/build/esm/blocks/SliderNew/utils.js +10 -0
- package/build/esm/blocks/Tabs/schema.d.ts +8 -1
- package/build/esm/components/ButtonTabs/ButtonTabs.js +3 -2
- package/build/esm/components/DefaultVideo/DefaultVideo.js +3 -3
- package/build/esm/components/FullscreenImage/FullscreenImage.css +6 -2
- package/build/esm/components/HeaderBreadcrumbs/HeaderBreadcrumbs.css +14 -11
- package/build/esm/components/HeaderBreadcrumbs/HeaderBreadcrumbs.js +4 -2
- package/build/esm/components/Image/Image.js +2 -2
- package/build/esm/components/Image/schema.d.ts +40 -0
- package/build/esm/components/Image/schema.js +8 -0
- package/build/esm/components/ImageBase/ImageBase.d.ts +1 -1
- package/build/esm/components/ImageBase/ImageBase.js +9 -2
- package/build/esm/components/Media/Media.js +5 -4
- package/build/esm/components/Media/Video/Video.js +2 -2
- package/build/esm/components/ReactPlayer/ReactPlayer.css +7 -0
- package/build/esm/components/ReactPlayer/ReactPlayer.d.ts +1 -0
- package/build/esm/components/ReactPlayer/ReactPlayer.js +15 -4
- package/build/esm/components/VideoBlock/VideoBlock.d.ts +1 -0
- package/build/esm/components/VideoBlock/VideoBlock.js +25 -38
- package/build/esm/constructor-items.d.ts +4 -4
- package/build/esm/containers/PageConstructor/PageConstructor.js +4 -2
- package/build/esm/context/imageContext/imageContext.d.ts +2 -3
- package/build/esm/context/projectSettingsContext/ProjectSettingsContext.d.ts +1 -0
- package/build/esm/editor/components/AddBlock/AddBlock.js +24 -7
- package/build/esm/editor/data/index.d.ts +3 -2
- package/build/esm/editor/data/index.js +18 -12
- package/build/esm/models/constructor-items/common.d.ts +9 -4
- package/build/esm/models/constructor-items/sub-blocks.d.ts +2 -1
- package/build/esm/models/navigation.d.ts +8 -0
- package/build/esm/navigation/components/DesktopNavigation/DesktopNavigation.css +42 -3
- package/build/esm/navigation/components/DesktopNavigation/DesktopNavigation.d.ts +1 -1
- package/build/esm/navigation/components/DesktopNavigation/DesktopNavigation.js +4 -1
- package/build/esm/navigation/components/Logo/Logo.d.ts +1 -1
- package/build/esm/navigation/components/Logo/Logo.js +1 -1
- package/build/esm/navigation/components/MobileNavigation/MobileNavigation.d.ts +1 -1
- package/build/esm/navigation/components/MobileNavigation/MobileNavigation.js +1 -1
- package/build/esm/navigation/components/Navigation/Navigation.d.ts +2 -2
- package/build/esm/navigation/components/Navigation/Navigation.js +6 -25
- package/build/esm/navigation/components/NavigationItem/NavigationItem.d.ts +1 -1
- package/build/esm/navigation/components/NavigationItem/NavigationItem.js +1 -1
- package/build/esm/navigation/components/NavigationItem/hooks/useNavigationItemMap.d.ts +5 -5
- package/build/esm/navigation/components/NavigationListItem/NavigationListItem.d.ts +1 -1
- package/build/esm/navigation/components/NavigationListItem/NavigationListItem.js +1 -1
- package/build/esm/navigation/components/Standalone/index.d.ts +2 -2
- package/build/esm/navigation/containers/Layout/Layout.js +2 -1
- package/build/esm/navigation/hooks/index.d.ts +2 -0
- package/build/esm/navigation/hooks/index.js +2 -0
- package/build/esm/navigation/hooks/useActiveNavItem.d.ts +26 -0
- package/build/esm/navigation/hooks/useActiveNavItem.js +13 -0
- package/build/esm/navigation/hooks/useShowBorder.d.ts +2 -0
- package/build/esm/navigation/hooks/useShowBorder.js +19 -0
- package/build/esm/navigation/index.d.ts +14 -0
- package/build/esm/navigation/index.js +14 -0
- package/build/esm/navigation/models.d.ts +1 -0
- package/build/esm/schema/constants.d.ts +16 -1
- package/build/esm/schema/validators/common.d.ts +14 -1
- package/build/esm/schema/validators/common.js +8 -1
- package/build/esm/sub-blocks/BackgroundCard/schema.d.ts +8 -0
- package/build/esm/sub-blocks/BannerCard/BannerCard.js +3 -3
- package/build/esm/sub-blocks/Content/Content.css +4 -4
- package/build/esm/sub-blocks/HubspotForm/HubspotForm.css +8 -4
- package/build/esm/sub-blocks/ImageCard/ImageCard.css +34 -1
- package/build/esm/sub-blocks/ImageCard/ImageCard.js +1 -1
- package/build/esm/sub-blocks/LayoutItem/schema.d.ts +8 -1
- package/build/esm/sub-blocks/LayoutItem/utils.d.ts +1 -1
- package/build/esm/sub-blocks/LayoutItem/utils.js +1 -1
- package/build/esm/sub-blocks/MediaCard/schema.d.ts +8 -1
- package/build/esm/text-transform/utils.js +1 -1
- package/package.json +8 -5
- package/server/models/constructor-items/common.d.ts +9 -4
- package/server/models/constructor-items/sub-blocks.d.ts +2 -1
- package/server/models/navigation.d.ts +8 -0
- package/server/text-transform/utils.js +1 -1
- package/styles/variables.scss +1 -0
- package/widget/index.js +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
2
2
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
3
3
|
// TODO fix in https://github.com/gravity-ui/page-constructor/issues/965
|
|
4
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { PlayFill } from '@gravity-ui/icons';
|
|
6
6
|
import { Icon } from '@gravity-ui/uikit';
|
|
7
7
|
import debounce from 'lodash/debounce';
|
|
@@ -21,8 +21,11 @@ export const AUTOPLAY_ATTRIBUTES = {
|
|
|
21
21
|
autoplay: 1,
|
|
22
22
|
mute: 1,
|
|
23
23
|
};
|
|
24
|
+
const NO_AUTOPLAY_ATTRIBUTES = {
|
|
25
|
+
autoplay: 0,
|
|
26
|
+
};
|
|
24
27
|
const b = block('VideoBlock');
|
|
25
|
-
function
|
|
28
|
+
function getYoutubeVideoSrc(stream, record) {
|
|
26
29
|
if (!stream && !record) {
|
|
27
30
|
return null;
|
|
28
31
|
}
|
|
@@ -40,22 +43,22 @@ export function getHeight(width) {
|
|
|
40
43
|
return (width / 16) * 9;
|
|
41
44
|
}
|
|
42
45
|
const VideoBlock = (props) => {
|
|
43
|
-
const { stream, record, attributes, className, id, previewImg, playButton, height, fullscreen, analyticsEvents, autoplay, onImageLoad, } = props;
|
|
46
|
+
const { stream, record, videoIframe, attributes, className, id, previewImg, playButton, height, fullscreen, analyticsEvents, autoplay, onImageLoad, } = props;
|
|
44
47
|
const handleAnalytics = useAnalytics(DefaultEventNames.VideoPreview);
|
|
45
|
-
const src =
|
|
48
|
+
const src = videoIframe ? videoIframe : getYoutubeVideoSrc(stream, record);
|
|
46
49
|
const ref = useRef(null);
|
|
47
|
-
const iframeRef = useRef();
|
|
48
50
|
const [hidePreview, setHidePreview] = useState(false);
|
|
49
|
-
const norender = (!stream && !record) || !src;
|
|
50
51
|
const [currentHeight, setCurrentHeight] = useState(height || undefined);
|
|
51
|
-
const fullId = id || uuidv4();
|
|
52
|
+
const fullId = useMemo(() => id || uuidv4(), [id]);
|
|
53
|
+
const [isPlaying, setIsPlaying] = useState(!previewImg);
|
|
54
|
+
const iframeSrc = src && isPlaying
|
|
55
|
+
? `${src}?${getPageSearchParams(Object.assign(Object.assign({}, (attributes || {})), (previewImg || autoplay ? AUTOPLAY_ATTRIBUTES : NO_AUTOPLAY_ATTRIBUTES)))}`
|
|
56
|
+
: undefined;
|
|
52
57
|
const onPreviewClick = useCallback(() => {
|
|
53
58
|
handleAnalytics(analyticsEvents);
|
|
54
|
-
|
|
55
|
-
iframeRef.current.src = `${src}?${getPageSearchParams(Object.assign(Object.assign({}, AUTOPLAY_ATTRIBUTES), (attributes || {})))}`;
|
|
56
|
-
}
|
|
59
|
+
setIsPlaying(true);
|
|
57
60
|
setTimeout(() => setHidePreview(true), AUTOPLAY_DELAY);
|
|
58
|
-
}, [handleAnalytics, analyticsEvents
|
|
61
|
+
}, [handleAnalytics, analyticsEvents]);
|
|
59
62
|
useEffect(() => {
|
|
60
63
|
const updateSize = debounce(() => {
|
|
61
64
|
setCurrentHeight(ref.current ? Math.round(getHeight(ref.current.offsetWidth)) : undefined);
|
|
@@ -66,36 +69,20 @@ const VideoBlock = (props) => {
|
|
|
66
69
|
window.removeEventListener('resize', updateSize);
|
|
67
70
|
};
|
|
68
71
|
}, [height]);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
if (ref.current && !iframeRef.current) {
|
|
74
|
-
const iframe = document.createElement('iframe');
|
|
75
|
-
iframe.id = fullId;
|
|
76
|
-
if (!previewImg) {
|
|
77
|
-
iframe.src = `${src}?${getPageSearchParams(Object.assign(Object.assign({}, (attributes || {})), (autoplay ? AUTOPLAY_ATTRIBUTES : {})))}`;
|
|
78
|
-
}
|
|
79
|
-
iframe.width = '100%';
|
|
80
|
-
iframe.height = '100%';
|
|
81
|
-
iframe.title = i18n('iframe-title');
|
|
82
|
-
iframe.frameBorder = '0';
|
|
83
|
-
iframe.setAttribute('allowfullscreen', 'true');
|
|
84
|
-
iframe.setAttribute('allow', 'autoplay');
|
|
85
|
-
iframe.setAttribute('loading', 'lazy');
|
|
86
|
-
ref.current.appendChild(iframe);
|
|
87
|
-
iframeRef.current = iframe;
|
|
88
|
-
}
|
|
89
|
-
}, [stream, record, norender, src, fullId, attributes, iframeRef, previewImg, autoplay]);
|
|
72
|
+
const iframeContent = useMemo(() => {
|
|
73
|
+
return (React.createElement("iframe", { id: fullId, src: iframeSrc, width: "100%", height: "100%", title: i18n('iframe-title'), frameBorder: "0", allowFullScreen: true, allow: "autoplay; fullscreen; encrypted-media; accelerometer; gyroscope; picture-in-picture; clipboard-write; web-share; screen-wake-lock", loading: "lazy" }));
|
|
74
|
+
}, [fullId, iframeSrc]);
|
|
90
75
|
useEffect(() => {
|
|
91
76
|
setHidePreview(false);
|
|
92
|
-
}, [src
|
|
93
|
-
if (
|
|
77
|
+
}, [src]);
|
|
78
|
+
if (!src) {
|
|
94
79
|
return null;
|
|
95
80
|
}
|
|
96
|
-
return (React.createElement("div", { className: b(null, className),
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
React.createElement(
|
|
81
|
+
return (React.createElement("div", { className: b(null, className), style: { height: currentHeight }, ref: ref },
|
|
82
|
+
iframeContent,
|
|
83
|
+
previewImg && !hidePreview && !fullscreen && (React.createElement("div", { className: b('preview'), onClick: onPreviewClick },
|
|
84
|
+
React.createElement(Image, { src: previewImg, className: b('image'), containerClassName: b('image-wrapper'), onLoad: onImageLoad }),
|
|
85
|
+
playButton || (React.createElement("button", { title: "Play", className: b('button') },
|
|
86
|
+
React.createElement(Icon, { className: b('icon'), data: PlayFill, size: 24 })))))));
|
|
100
87
|
};
|
|
101
88
|
export default VideoBlock;
|
|
@@ -34,9 +34,9 @@ export declare const subBlockMap: {
|
|
|
34
34
|
"image-card": (props: import("./models").ImageCardProps) => JSX.Element;
|
|
35
35
|
};
|
|
36
36
|
export declare const navItemMap: {
|
|
37
|
-
button: import("react").FC<Pick<import("./navigation
|
|
37
|
+
button: import("react").FC<Pick<import("./navigation").NavigationItemProps, "className"> & import("./models").ButtonProps>;
|
|
38
38
|
social: import("react").FC<import("./navigation/components/SocialIcon/SocialIcon").NavigationSocialItemOwnProps>;
|
|
39
|
-
dropdown: ({ text, icon, className, iconSize, hidePopup, items, isActive, ...props }: import("./navigation
|
|
40
|
-
link: import("react").FC<import("./navigation
|
|
41
|
-
"github-button": ({ text, url, className, label, size, icon, urlTitle, }: import("./navigation
|
|
39
|
+
dropdown: ({ text, icon, className, iconSize, hidePopup, items, isActive, ...props }: import("./navigation").NavigationItemProps & import("./models").NavigationDropdownItem) => JSX.Element;
|
|
40
|
+
link: import("react").FC<import("./navigation").NavigationItemProps & import("./models").NavigationLinkItem>;
|
|
41
|
+
"github-button": ({ text, url, className, label, size, icon, urlTitle, }: import("./navigation").NavigationItemProps & import("./models").NavigationGithubButton) => JSX.Element;
|
|
42
42
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import React, { useMemo } from 'react';
|
|
2
|
+
import React, { useContext, useMemo } from 'react';
|
|
3
3
|
import '@diplodoc/transform/dist/js/yfm';
|
|
4
4
|
import BackgroundMedia from '../../components/BackgroundMedia/BackgroundMedia';
|
|
5
5
|
import RootCn from '../../components/RootCn';
|
|
6
6
|
import { blockMap, navItemMap, subBlockMap } from '../../constructor-items';
|
|
7
7
|
import { AnimateContext } from '../../context/animateContext';
|
|
8
8
|
import { InnerContext } from '../../context/innerContext';
|
|
9
|
+
import { ProjectSettingsContext } from '../../context/projectSettingsContext';
|
|
9
10
|
import { useTheme } from '../../context/theme';
|
|
10
11
|
import { Grid } from '../../grid';
|
|
11
12
|
import { BlockType, BlockTypes, HeaderBlockTypes, NavigationItemTypes, SubBlockTypes, } from '../../models';
|
|
@@ -51,7 +52,8 @@ export const Constructor = (props) => {
|
|
|
51
52
|
React.createElement(ConstructorBlocks, { items: restBlocks })))))))));
|
|
52
53
|
};
|
|
53
54
|
export const PageConstructor = (props) => {
|
|
54
|
-
const {
|
|
55
|
+
const { isAnimationEnabled = true } = useContext(ProjectSettingsContext);
|
|
56
|
+
const { content: { animated = isAnimationEnabled } = {} } = props, rest = __rest(props, ["content"]);
|
|
55
57
|
return (React.createElement(AnimateContext.Provider, { value: { animated } },
|
|
56
58
|
React.createElement(Constructor, Object.assign({ content: props.content }, rest))));
|
|
57
59
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ImageBaseProps } from '../../components';
|
|
3
|
-
export type Image = React.ComponentClass<ImageBaseProps> | React.FC<ImageBaseProps>;
|
|
2
|
+
import type { ImageBaseProps } from '../../components';
|
|
4
3
|
export type ImageContextProps = {
|
|
5
|
-
Image?:
|
|
4
|
+
Image?: React.ComponentType<ImageBaseProps>;
|
|
6
5
|
};
|
|
7
6
|
export declare const ImageContext: React.Context<ImageContextProps>;
|
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
2
2
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
3
3
|
// TODO fix in https://github.com/gravity-ui/page-constructor/issues/965
|
|
4
|
-
import React, { useMemo, useRef, useState } from 'react';
|
|
4
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { Plus } from '@gravity-ui/icons';
|
|
6
6
|
import { Popup, TextInput } from '@gravity-ui/uikit';
|
|
7
7
|
import { blockMap } from '../../../constructor-items';
|
|
8
8
|
import { block } from '../../../utils';
|
|
9
|
-
import
|
|
9
|
+
import { getEditorBlocksData } from '../../data';
|
|
10
10
|
import './AddBlock.css';
|
|
11
11
|
const b = block('add-block');
|
|
12
12
|
const sortedBlockNames = Object.keys(blockMap).sort();
|
|
13
13
|
const AddBlock = ({ onAdd, className }) => {
|
|
14
14
|
const [isOpened, setIsOpened] = useState(false);
|
|
15
15
|
const [search, setSearch] = useState('');
|
|
16
|
+
const [editorBlocksData, setEditorBlocksData] = useState(null);
|
|
16
17
|
const ref = useRef(null);
|
|
17
|
-
const blocks = useMemo(() =>
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const blocks = useMemo(() => {
|
|
19
|
+
if (!editorBlocksData) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
return sortedBlockNames.filter((blockName) => {
|
|
23
|
+
var _a;
|
|
24
|
+
return (_a = editorBlocksData[blockName]) === null || _a === void 0 ? void 0 : _a.meta.title.toLocaleLowerCase().startsWith(search.toLocaleLowerCase());
|
|
25
|
+
});
|
|
26
|
+
}, [editorBlocksData, search]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const loadEditorBlocksData = async () => {
|
|
29
|
+
const data = await getEditorBlocksData();
|
|
30
|
+
setEditorBlocksData(data);
|
|
31
|
+
};
|
|
32
|
+
loadEditorBlocksData();
|
|
33
|
+
}, []);
|
|
20
34
|
return (React.createElement("div", { className: b(null, className), ref: ref },
|
|
21
35
|
React.createElement("button", { className: b('button'), type: "button", onClick: () => {
|
|
22
36
|
setIsOpened(!isOpened);
|
|
@@ -28,8 +42,11 @@ const AddBlock = ({ onAdd, className }) => {
|
|
|
28
42
|
React.createElement(TextInput, { placeholder: "search", type: "text", value: search, size: "l", onUpdate: (value) => setSearch(value) })),
|
|
29
43
|
React.createElement("div", { className: b('blocks') }, blocks.map((blockName) => {
|
|
30
44
|
var _a;
|
|
31
|
-
const blockData =
|
|
32
|
-
|
|
45
|
+
const blockData = editorBlocksData === null || editorBlocksData === void 0 ? void 0 : editorBlocksData[blockName];
|
|
46
|
+
if (!blockData) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const Preview = blockData.preview;
|
|
33
50
|
return (React.createElement("div", { key: blockName, className: b('block'), onClick: () => {
|
|
34
51
|
onAdd(blockData === null || blockData === void 0 ? void 0 : blockData.template);
|
|
35
52
|
setIsOpened(false);
|
|
@@ -9,5 +9,6 @@ export interface EdiorBlockData {
|
|
|
9
9
|
description?: string;
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
type EditorBlocksData = Partial<Record<BlockType, EdiorBlockData>>;
|
|
13
|
+
declare function getEditorBlocksData(): Promise<EditorBlocksData>;
|
|
14
|
+
export { EditorBlocksData, getEditorBlocksData };
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { BlockType } from '../../models';
|
|
2
2
|
import { formatBlockName } from '../utils';
|
|
3
3
|
import DefaultPreview from './previews/default-preview';
|
|
4
|
-
|
|
4
|
+
import HeaderBlock from './previews/header-block';
|
|
5
|
+
const getBlockTemplate = (blockType) => import(`./templates/${blockType}.json`).then((data) => data.default);
|
|
5
6
|
const getBlockPreview = (blockType) => {
|
|
6
7
|
try {
|
|
7
|
-
|
|
8
|
+
if (blockType === BlockType.HeaderBlock) {
|
|
9
|
+
return HeaderBlock;
|
|
10
|
+
}
|
|
11
|
+
return DefaultPreview;
|
|
8
12
|
}
|
|
9
13
|
catch (err) {
|
|
10
14
|
/*eslint-disable no-console */
|
|
@@ -12,13 +16,15 @@ const getBlockPreview = (blockType) => {
|
|
|
12
16
|
return DefaultPreview;
|
|
13
17
|
}
|
|
14
18
|
};
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
19
|
+
async function getEditorBlocksData() {
|
|
20
|
+
const EdiorBlockData = {};
|
|
21
|
+
for (const blockType of Object.values(BlockType)) {
|
|
22
|
+
const template = await getBlockTemplate(blockType);
|
|
23
|
+
const preview = getBlockPreview(blockType);
|
|
24
|
+
template.meta = template.meta || {};
|
|
25
|
+
template.meta.title = template.meta.title || formatBlockName(blockType);
|
|
26
|
+
EdiorBlockData[blockType] = Object.assign(Object.assign({}, template), { preview });
|
|
27
|
+
}
|
|
28
|
+
return EdiorBlockData;
|
|
29
|
+
}
|
|
30
|
+
export { getEditorBlocksData };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { CSSProperties, HTMLProps, ReactNode } from 'react';
|
|
1
|
+
import React, { CSSProperties, DetailedHTMLProps, HTMLProps, ImgHTMLAttributes, ReactNode } from 'react';
|
|
2
2
|
import { ButtonView, ButtonProps as UikitButtonProps } from '@gravity-ui/uikit';
|
|
3
3
|
import { ThemeSupporting } from '../../utils';
|
|
4
4
|
import { AnalyticsEventsBase, AnalyticsEventsProp, ClassNameProps, QAProps } from '../common';
|
|
@@ -96,8 +96,9 @@ interface LoopProps {
|
|
|
96
96
|
start: number;
|
|
97
97
|
end?: number;
|
|
98
98
|
}
|
|
99
|
-
export interface ImageInfoProps extends Pick<
|
|
99
|
+
export interface ImageInfoProps extends Pick<DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, 'aria-describedby' | 'loading'> {
|
|
100
100
|
alt?: string;
|
|
101
|
+
fetchPriority?: 'high' | 'low' | 'auto';
|
|
101
102
|
disableCompress?: boolean;
|
|
102
103
|
}
|
|
103
104
|
export interface ImageObjectProps extends ImageInfoProps {
|
|
@@ -126,6 +127,7 @@ export interface MediaVideoProps extends AnalyticsEventsBase {
|
|
|
126
127
|
controls?: MediaVideoControlsType;
|
|
127
128
|
customControlsOptions?: CustomControlsOptions;
|
|
128
129
|
ariaLabel?: string;
|
|
130
|
+
contain?: boolean;
|
|
129
131
|
}
|
|
130
132
|
export interface LinkProps extends AnalyticsEventsBase, Stylable, Tabbable {
|
|
131
133
|
url: string;
|
|
@@ -178,9 +180,12 @@ export type ThemedMediaVideoProps = ThemeSupporting<MediaVideoProps>;
|
|
|
178
180
|
export interface MediaComponentVideoProps extends AnalyticsEventsBase {
|
|
179
181
|
video: MediaVideoProps;
|
|
180
182
|
height?: number;
|
|
181
|
-
ratio?: number;
|
|
183
|
+
ratio?: number | 'auto';
|
|
182
184
|
previewImg?: string;
|
|
183
185
|
}
|
|
186
|
+
export interface MediaComponentVideoIframeProps {
|
|
187
|
+
videoIframe: string;
|
|
188
|
+
}
|
|
184
189
|
export interface MediaComponentYoutubeProps {
|
|
185
190
|
youtube: string;
|
|
186
191
|
previewImg?: string;
|
|
@@ -200,7 +205,7 @@ export interface MediaComponentIframeProps {
|
|
|
200
205
|
iframe: IframeProps;
|
|
201
206
|
margins?: boolean;
|
|
202
207
|
}
|
|
203
|
-
export interface MediaProps extends Animatable, Partial<MediaComponentDataLensProps>, Partial<MediaComponentYoutubeProps>, Partial<MediaComponentImageProps>, Partial<MediaComponentIframeProps>, Partial<MediaComponentVideoProps> {
|
|
208
|
+
export interface MediaProps extends Animatable, Partial<MediaComponentDataLensProps>, Partial<MediaComponentYoutubeProps>, Partial<MediaComponentVideoIframeProps>, Partial<MediaComponentImageProps>, Partial<MediaComponentIframeProps>, Partial<MediaComponentVideoProps> {
|
|
204
209
|
color?: string;
|
|
205
210
|
}
|
|
206
211
|
export interface BackgroundMediaProps extends MediaProps, Animatable, QAProps {
|
|
@@ -113,11 +113,12 @@ export interface BasicCardProps extends CardBaseProps, AnalyticsEventsBase, Card
|
|
|
113
113
|
export interface BannerCardProps {
|
|
114
114
|
title: string;
|
|
115
115
|
subtitle?: string;
|
|
116
|
+
className?: string;
|
|
116
117
|
image?: ThemeSupporting<string>;
|
|
117
118
|
disableCompress?: boolean;
|
|
118
119
|
color?: ThemeSupporting<string>;
|
|
119
120
|
theme?: TextTheme;
|
|
120
|
-
button
|
|
121
|
+
button?: Pick<ButtonProps, 'text' | 'url' | 'target' | 'theme'>;
|
|
121
122
|
mediaView?: MediaView;
|
|
122
123
|
}
|
|
123
124
|
export interface MediaCardProps extends MediaProps, AnalyticsEventsBase, CardBaseProps {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { ThemeSupporting } from '../utils';
|
|
2
3
|
import { ButtonProps, ImageProps } from './constructor-items';
|
|
3
4
|
export declare enum NavigationItemType {
|
|
@@ -69,6 +70,12 @@ export type ThemedNavigationLogoData = NavigationLogoData & ThemeSupporting<Navi
|
|
|
69
70
|
export interface HeaderData {
|
|
70
71
|
leftItems: NavigationItemModel[];
|
|
71
72
|
rightItems?: NavigationItemModel[];
|
|
73
|
+
/**
|
|
74
|
+
* Items for the navigation header on mobile devices.
|
|
75
|
+
* They are located to the right of the Logo and to the left of the MobileMenuButton.
|
|
76
|
+
* @type {NavigationItemModel[]}
|
|
77
|
+
*/
|
|
78
|
+
customMobileHeaderItems?: NavigationItemModel[];
|
|
72
79
|
iconSize?: number;
|
|
73
80
|
withBorder?: boolean;
|
|
74
81
|
withBorderOnScroll?: boolean;
|
|
@@ -90,4 +97,5 @@ export interface NavigationData {
|
|
|
90
97
|
logo: ThemedNavigationLogoData;
|
|
91
98
|
header: HeaderData;
|
|
92
99
|
footer?: FooterData;
|
|
100
|
+
renderNavigation?: () => React.ReactNode;
|
|
93
101
|
}
|
|
@@ -27,18 +27,43 @@ unpredictable css rules order in build */
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
.pc-desktop-navigation__mobile-navigation.pc-desktop-navigation__mobile-navigation {
|
|
31
|
+
justify-content: flex-end;
|
|
32
|
+
}
|
|
33
|
+
@media (min-width: 769px) {
|
|
34
|
+
.pc-desktop-navigation__mobile-navigation.pc-desktop-navigation__mobile-navigation {
|
|
35
|
+
display: none;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.pc-desktop-navigation__mobile-navigation-container {
|
|
40
|
+
padding-right: 8px;
|
|
41
|
+
}
|
|
42
|
+
.pc-desktop-navigation__mobile-navigation-container:has(.pc-overflow-scroller__arrow) .pc-desktop-navigation__mobile-navigation {
|
|
43
|
+
justify-content: flex-start;
|
|
44
|
+
}
|
|
45
|
+
.pc-desktop-navigation__mobile-navigation-container:has(.pc-overflow-scroller__arrow_type_right) {
|
|
46
|
+
padding-right: 16px;
|
|
47
|
+
}
|
|
30
48
|
.pc-desktop-navigation__right {
|
|
31
|
-
flex: 0;
|
|
32
49
|
justify-content: flex-end;
|
|
33
50
|
font-size: var(--g-text-body-2-font-size);
|
|
34
51
|
line-height: var(--g-text-body-2-line-height);
|
|
35
52
|
}
|
|
36
|
-
|
|
53
|
+
@media (max-width: 768px) {
|
|
54
|
+
.pc-desktop-navigation__right {
|
|
55
|
+
flex: 3 0 0;
|
|
56
|
+
max-width: 50%;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
.pc-desktop-navigation__navigation-container, .pc-desktop-navigation__mobile-navigation-container {
|
|
37
60
|
display: flex;
|
|
38
61
|
overflow-x: hidden;
|
|
39
62
|
flex: 1 0 0;
|
|
40
63
|
justify-content: space-between;
|
|
41
64
|
align-items: center;
|
|
65
|
+
}
|
|
66
|
+
.pc-desktop-navigation__navigation-container {
|
|
42
67
|
margin-right: 32px;
|
|
43
68
|
}
|
|
44
69
|
.pc-desktop-navigation__button {
|
|
@@ -48,7 +73,7 @@ unpredictable css rules order in build */
|
|
|
48
73
|
margin: 0 32px 0 0;
|
|
49
74
|
cursor: pointer;
|
|
50
75
|
}
|
|
51
|
-
.pc-desktop-navigation__buttons, .pc-desktop-
|
|
76
|
+
.pc-desktop-navigation__links, .pc-desktop-navigation__buttons, .pc-desktop-navigation__mobile-buttons {
|
|
52
77
|
display: flex;
|
|
53
78
|
align-items: center;
|
|
54
79
|
margin: 0;
|
|
@@ -63,6 +88,14 @@ unpredictable css rules order in build */
|
|
|
63
88
|
.pc-desktop-navigation__buttons > *:not(:last-child) {
|
|
64
89
|
margin-right: 16px;
|
|
65
90
|
}
|
|
91
|
+
@media (min-width: 769px) {
|
|
92
|
+
.pc-desktop-navigation__mobile-buttons {
|
|
93
|
+
display: none;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
.pc-desktop-navigation__mobile-buttons .pc-desktop-navigation__item:not(:last-child) {
|
|
97
|
+
margin-right: 0;
|
|
98
|
+
}
|
|
66
99
|
.pc-desktop-navigation__links {
|
|
67
100
|
position: relative;
|
|
68
101
|
font-size: var(--g-text-body-2-font-size);
|
|
@@ -78,6 +111,12 @@ unpredictable css rules order in build */
|
|
|
78
111
|
.pc-desktop-navigation__navigation-container {
|
|
79
112
|
justify-content: flex-end;
|
|
80
113
|
}
|
|
114
|
+
.pc-desktop-navigation__navigation-container, .pc-desktop-navigation__mobile-navigation-container {
|
|
115
|
+
justify-content: flex-end;
|
|
116
|
+
}
|
|
117
|
+
.pc-desktop-navigation__navigation-container {
|
|
118
|
+
flex: 0 0 0;
|
|
119
|
+
}
|
|
81
120
|
.pc-desktop-navigation__left {
|
|
82
121
|
flex: 1 0 0;
|
|
83
122
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DesktopNavigationProps } from '../../models';
|
|
3
3
|
import './DesktopNavigation.css';
|
|
4
|
-
declare const DesktopNavigation: React.FC<DesktopNavigationProps>;
|
|
4
|
+
export declare const DesktopNavigation: React.FC<DesktopNavigationProps>;
|
|
5
5
|
export default DesktopNavigation;
|
|
@@ -7,13 +7,16 @@ import { MobileMenuButton } from '../MobileMenuButton/MobileMenuButton';
|
|
|
7
7
|
import { NavigationList } from '../NavigationList/NavigationList';
|
|
8
8
|
import './DesktopNavigation.css';
|
|
9
9
|
const b = block('desktop-navigation');
|
|
10
|
-
const DesktopNavigation = ({ logo, leftItemsWithIconSize, rightItemsWithIconSize, isSidebarOpened, onSidebarOpenedChange, onActiveItemChange, activeItemId, }) => (React.createElement("div", { className: b('wrapper') },
|
|
10
|
+
export const DesktopNavigation = ({ logo, leftItemsWithIconSize, rightItemsWithIconSize, customMobileHeaderItems, isSidebarOpened, onSidebarOpenedChange, onActiveItemChange, activeItemId, }) => (React.createElement("div", { className: b('wrapper') },
|
|
11
11
|
logo && (React.createElement("div", { className: b('left') },
|
|
12
12
|
React.createElement(Logo, Object.assign({}, logo, { className: b('logo') })))),
|
|
13
13
|
React.createElement("div", { className: b('navigation-container') },
|
|
14
14
|
React.createElement(OverflowScroller, { className: b('navigation'), onScrollStart: onActiveItemChange },
|
|
15
15
|
React.createElement(NavigationList, { items: leftItemsWithIconSize, onActiveItemChange: onActiveItemChange, className: b('links'), itemClassName: b('item'), column: ItemColumnName.Left, activeItemId: activeItemId, menuLayout: NavigationLayout.Desktop }))),
|
|
16
16
|
React.createElement("div", { className: b('right') },
|
|
17
|
+
customMobileHeaderItems && (React.createElement("div", { className: b('mobile-navigation-container') },
|
|
18
|
+
React.createElement(OverflowScroller, { className: b('mobile-navigation'), onScrollStart: onActiveItemChange, arrowSize: 18 },
|
|
19
|
+
React.createElement(NavigationList, { items: customMobileHeaderItems, onActiveItemChange: onActiveItemChange, className: b('mobile-buttons'), itemClassName: b('item'), column: ItemColumnName.Left, activeItemId: activeItemId, menuLayout: NavigationLayout.Dropdown })))),
|
|
17
20
|
React.createElement(MobileMenuButton, { isSidebarOpened: isSidebarOpened, onSidebarOpenedChange: onSidebarOpenedChange }),
|
|
18
21
|
rightItemsWithIconSize && (React.createElement(NavigationList, { onActiveItemChange: onActiveItemChange, column: ItemColumnName.Right, items: rightItemsWithIconSize, activeItemId: activeItemId, className: b('buttons'), itemClassName: b('item'), menuLayout: NavigationLayout.Desktop })))));
|
|
19
22
|
export default DesktopNavigation;
|
|
@@ -9,7 +9,7 @@ import { block, getLinkProps, getThemedValue } from '../../../utils';
|
|
|
9
9
|
import { i18n } from './i18n';
|
|
10
10
|
import './Logo.css';
|
|
11
11
|
const b = block('logo');
|
|
12
|
-
const Logo = (_a) => {
|
|
12
|
+
export const Logo = (_a) => {
|
|
13
13
|
var { alt = i18n('image-alt') } = _a, restProps = __rest(_a, ["alt"]);
|
|
14
14
|
const props = Object.assign(Object.assign({}, restProps), { alt });
|
|
15
15
|
const { hostname, Link } = useContext(LocationContext);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { MobileNavigationProps } from '../../models';
|
|
3
3
|
import './MobileNavigation.css';
|
|
4
|
-
declare const MobileNavigation: React.FC<MobileNavigationProps>;
|
|
4
|
+
export declare const MobileNavigation: React.FC<MobileNavigationProps>;
|
|
5
5
|
export default MobileNavigation;
|
|
@@ -8,7 +8,7 @@ import { ItemColumnName, NavigationLayout } from '../../models';
|
|
|
8
8
|
import { NavigationList } from '../NavigationList/NavigationList';
|
|
9
9
|
import './MobileNavigation.css';
|
|
10
10
|
const b = block('mobile-navigation');
|
|
11
|
-
const MobileNavigation = (_a) => {
|
|
11
|
+
export const MobileNavigation = (_a) => {
|
|
12
12
|
var { isOpened, topItems, bottomItems } = _a, props = __rest(_a, ["isOpened", "topItems", "bottomItems"]);
|
|
13
13
|
const [isMounted, setIsMounted] = React.useState(false);
|
|
14
14
|
useMount(() => setIsMounted(true));
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ClassNameProps, HeaderData, ThemedNavigationLogoData } from '../../../models';
|
|
3
3
|
import './Navigation.css';
|
|
4
|
-
export interface
|
|
4
|
+
export interface NavigationComponentProps extends ClassNameProps {
|
|
5
5
|
logo: ThemedNavigationLogoData;
|
|
6
6
|
data: HeaderData;
|
|
7
7
|
}
|
|
8
|
-
export declare const Navigation: React.FC<
|
|
8
|
+
export declare const Navigation: React.FC<NavigationComponentProps>;
|
|
9
9
|
export default Navigation;
|
|
@@ -1,42 +1,23 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import debounce from 'lodash/debounce';
|
|
1
|
+
import React, { useState } from 'react';
|
|
3
2
|
import OutsideClick from '../../../components/OutsideClick/OutsideClick';
|
|
4
3
|
import { Col, Grid, Row } from '../../../grid';
|
|
5
4
|
import { block } from '../../../utils';
|
|
6
|
-
import {
|
|
5
|
+
import { useActiveNavItem, useShowBorder } from '../../hooks';
|
|
7
6
|
import DesktopNavigation from '../DesktopNavigation/DesktopNavigation';
|
|
8
7
|
import MobileNavigation from '../MobileNavigation/MobileNavigation';
|
|
9
8
|
import './Navigation.css';
|
|
10
9
|
const b = block('navigation');
|
|
11
10
|
export const Navigation = ({ data, logo, className }) => {
|
|
12
|
-
const { leftItems, rightItems, iconSize = 20, withBorder = false, withBorderOnScroll = true, } = data;
|
|
11
|
+
const { leftItems, rightItems, customMobileHeaderItems, iconSize = 20, withBorder = false, withBorderOnScroll = true, } = data;
|
|
13
12
|
const [isSidebarOpened, setIsSidebarOpened] = useState(false);
|
|
14
|
-
const [
|
|
15
|
-
const
|
|
16
|
-
const getNavigationItem = getNavigationItemWithIconSize(iconSize);
|
|
17
|
-
const leftItemsWithIconSize = useMemo(() => leftItems.map(getNavigationItem), [getNavigationItem, leftItems]);
|
|
18
|
-
const rightItemsWithIconSize = useMemo(() => rightItems === null || rightItems === void 0 ? void 0 : rightItems.map(getNavigationItem), [getNavigationItem, rightItems]);
|
|
19
|
-
const onActiveItemChange = (id) => {
|
|
20
|
-
setActiveItemId(id);
|
|
21
|
-
};
|
|
13
|
+
const [showBorder] = useShowBorder(withBorder, withBorderOnScroll);
|
|
14
|
+
const { activeItemId, leftItemsWithIconSize, rightItemsWithIconSize, onActiveItemChange } = useActiveNavItem(iconSize, leftItems, rightItems);
|
|
22
15
|
const onSidebarOpenedChange = (isOpen) => setIsSidebarOpened(isOpen);
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (!withBorderOnScroll)
|
|
25
|
-
return () => { };
|
|
26
|
-
const showBorderOnScroll = () => {
|
|
27
|
-
if (!withBorder) {
|
|
28
|
-
setShowBorder(window.scrollY > 0);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const scrollHandler = debounce(showBorderOnScroll, 20);
|
|
32
|
-
window.addEventListener('scroll', scrollHandler, { passive: true });
|
|
33
|
-
return () => window.removeEventListener('scroll', scrollHandler);
|
|
34
|
-
});
|
|
35
16
|
return (React.createElement(Grid, { className: b({ 'with-border': showBorder }, className) },
|
|
36
17
|
React.createElement(Row, null,
|
|
37
18
|
React.createElement(Col, null,
|
|
38
19
|
React.createElement("nav", null,
|
|
39
|
-
React.createElement(DesktopNavigation, { logo: logo, activeItemId: activeItemId, onActiveItemChange: onActiveItemChange, leftItemsWithIconSize: leftItemsWithIconSize, rightItemsWithIconSize: rightItemsWithIconSize, isSidebarOpened: isSidebarOpened, onSidebarOpenedChange: onSidebarOpenedChange }),
|
|
20
|
+
React.createElement(DesktopNavigation, { logo: logo, activeItemId: activeItemId, onActiveItemChange: onActiveItemChange, leftItemsWithIconSize: leftItemsWithIconSize, rightItemsWithIconSize: rightItemsWithIconSize, customMobileHeaderItems: customMobileHeaderItems, isSidebarOpened: isSidebarOpened, onSidebarOpenedChange: onSidebarOpenedChange }),
|
|
40
21
|
React.createElement(OutsideClick, { onOutsideClick: () => onSidebarOpenedChange(false) },
|
|
41
22
|
React.createElement(MobileNavigation, { topItems: leftItemsWithIconSize, bottomItems: rightItemsWithIconSize, isOpened: isSidebarOpened, activeItemId: activeItemId, onActiveItemChange: onActiveItemChange })))))));
|
|
42
23
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { NavigationItemProps } from '../../models';
|
|
3
3
|
import './NavigationItem.css';
|
|
4
|
-
declare const NavigationItem: React.FC<NavigationItemProps>;
|
|
4
|
+
export declare const NavigationItem: React.FC<NavigationItemProps>;
|
|
5
5
|
export default NavigationItem;
|
|
@@ -9,7 +9,7 @@ import './NavigationItem.css';
|
|
|
9
9
|
const b = block('navigation-item');
|
|
10
10
|
const ANALYTICS_ID = 'navigation';
|
|
11
11
|
const nonComplexNavigationItemTypes = NavigationItemTypes.filter((type) => type !== NavigationItemType.Dropdown);
|
|
12
|
-
const NavigationItem = (_a) => {
|
|
12
|
+
export const NavigationItem = (_a) => {
|
|
13
13
|
var { data, className, menuLayout } = _a, props = __rest(_a, ["data", "className", "menuLayout"]);
|
|
14
14
|
const { type = NavigationItemType.Link } = data;
|
|
15
15
|
const navItemMap = useNavigationItemMap();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const useNavigationItemMap: () => {
|
|
2
|
-
button: import("react").FC<Pick<import("
|
|
3
|
-
social: import("react").FC<import("
|
|
4
|
-
dropdown: ({ text, icon, className, iconSize, hidePopup, items, isActive, ...props }: import("
|
|
5
|
-
link: import("react").FC<import("
|
|
6
|
-
"github-button": ({ text, url, className, label, size, icon, urlTitle, }: import("
|
|
2
|
+
button: import("react").FC<Pick<import("../../..").NavigationItemProps, "className"> & import("../../../..").ButtonProps>;
|
|
3
|
+
social: import("react").FC<import("../../..").NavigationSocialItemOwnProps>;
|
|
4
|
+
dropdown: ({ text, icon, className, iconSize, hidePopup, items, isActive, ...props }: import("../../..").NavigationItemProps & import("../../../..").NavigationDropdownItem) => JSX.Element;
|
|
5
|
+
link: import("react").FC<import("../../..").NavigationItemProps & import("../../../..").NavigationLinkItem>;
|
|
6
|
+
"github-button": ({ text, url, className, label, size, icon, urlTitle, }: import("../../..").NavigationItemProps & import("../../../..").NavigationGithubButton) => JSX.Element;
|
|
7
7
|
};
|
|
@@ -2,7 +2,7 @@ import { __rest } from "tslib";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { getItemClickHandler } from '../../utils';
|
|
4
4
|
import NavigationItem from '../NavigationItem';
|
|
5
|
-
const NavigationListItem = (_a) => {
|
|
5
|
+
export const NavigationListItem = (_a) => {
|
|
6
6
|
var { column, index, activeItemId, onActiveItemChange } = _a, props = __rest(_a, ["column", "index", "activeItemId", "onActiveItemChange"]);
|
|
7
7
|
const id = `${column}-${index}`;
|
|
8
8
|
const isActive = id === activeItemId;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const Standalone: (props:
|
|
1
|
+
import { NavigationComponentProps } from './../../components/Navigation/Navigation';
|
|
2
|
+
declare const Standalone: (props: NavigationComponentProps) => JSX.Element;
|
|
3
3
|
export default Standalone;
|