@gravity-ui/page-constructor 5.26.1 → 5.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/blocks/Banner/Banner.js +2 -2
- package/build/cjs/blocks/Slider/Slider.css +1 -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.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/containers/PageConstructor/PageConstructor.js +3 -1
- package/build/cjs/context/projectSettingsContext/ProjectSettingsContext.d.ts +1 -0
- package/build/cjs/models/constructor-items/sub-blocks.d.ts +2 -1
- package/build/cjs/sub-blocks/BannerCard/BannerCard.js +3 -3
- package/build/esm/blocks/Banner/Banner.js +2 -2
- package/build/esm/blocks/Slider/Slider.css +1 -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.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/containers/PageConstructor/PageConstructor.js +4 -2
- package/build/esm/context/projectSettingsContext/ProjectSettingsContext.d.ts +1 -0
- package/build/esm/models/constructor-items/sub-blocks.d.ts +2 -1
- package/build/esm/sub-blocks/BannerCard/BannerCard.js +3 -3
- package/package.json +4 -1
- package/server/models/constructor-items/sub-blocks.d.ts +2 -1
- package/widget/index.js +1 -1
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
1
2
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
3
|
import { SliderType } from '../../models';
|
|
3
|
-
import { getSliderResponsiveParams } from './utils';
|
|
4
|
-
export const useSlider = (
|
|
4
|
+
import { getSliderResponsiveParams, useMemoized } from './utils';
|
|
5
|
+
export const useSlider = (_a) => {
|
|
6
|
+
var { children, autoplayMs, type } = _a, props = __rest(_a, ["children", "autoplayMs", "type"]);
|
|
5
7
|
const [slider, setSlider] = useState();
|
|
6
8
|
const [isLocked, setIsLocked] = useState(false);
|
|
9
|
+
const slidesToShow = useMemoized(props.slidesToShow);
|
|
7
10
|
const childrenCount = React.Children.count(children);
|
|
8
|
-
const autoplayEnabled =
|
|
11
|
+
const autoplayEnabled = autoplayMs !== undefined && autoplayMs > 0;
|
|
9
12
|
const breakpoints = useMemo(() => {
|
|
10
13
|
return getSliderResponsiveParams({
|
|
11
14
|
contentLength: childrenCount,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Swiper as SwiperProps } from 'swiper/swiper-react';
|
|
2
|
+
export declare const useSliderPagination: (props: {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
isA11yControlHidden: boolean;
|
|
5
|
+
controlTabIndex: number;
|
|
6
|
+
bulletClass: string;
|
|
7
|
+
bulletActiveClass: string;
|
|
8
|
+
paginationLabel: string;
|
|
9
|
+
}) => Pick<SwiperProps, 'pagination' | 'onPaginationUpdate'> | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { setElementAtrributes } from './utils';
|
|
2
|
+
export const useSliderPagination = (props) => {
|
|
3
|
+
if (!props.enabled) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
const { isA11yControlHidden, controlTabIndex, bulletClass, bulletActiveClass, paginationLabel } = props;
|
|
7
|
+
return {
|
|
8
|
+
pagination: {
|
|
9
|
+
clickable: true,
|
|
10
|
+
bulletClass,
|
|
11
|
+
bulletActiveClass,
|
|
12
|
+
},
|
|
13
|
+
onPaginationUpdate: (slider) => {
|
|
14
|
+
const pagination = slider.pagination.el;
|
|
15
|
+
setElementAtrributes(pagination, {
|
|
16
|
+
role: 'menu',
|
|
17
|
+
'aria-hidden': isA11yControlHidden,
|
|
18
|
+
'aria-label': paginationLabel,
|
|
19
|
+
});
|
|
20
|
+
const bullets = pagination.querySelectorAll(`.${bulletClass}`);
|
|
21
|
+
bullets.forEach((bullet) => {
|
|
22
|
+
const isActive = bullet.classList.contains(bulletActiveClass);
|
|
23
|
+
setElementAtrributes(bullet, {
|
|
24
|
+
role: 'menuitemradio',
|
|
25
|
+
'aria-hidden': isA11yControlHidden,
|
|
26
|
+
'aria-checked': isActive,
|
|
27
|
+
tabindex: controlTabIndex,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -12,3 +12,5 @@ export interface GetSlidesToShowParams {
|
|
|
12
12
|
mobileFullscreen?: boolean;
|
|
13
13
|
}
|
|
14
14
|
export declare function getSliderResponsiveParams({ contentLength, slidesToShow, mobileFullscreen, }: GetSlidesToShowParams): Record<number, SwiperOptions>;
|
|
15
|
+
export declare const useMemoized: <T>(value: T) => T;
|
|
16
|
+
export declare const setElementAtrributes: (element: Element, attributes: Record<string, unknown>) => void;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import isEqual from 'lodash/isEqual';
|
|
1
3
|
import pickBy from 'lodash/pickBy';
|
|
2
4
|
import { BREAKPOINTS } from '../../constants';
|
|
3
5
|
import { SliderBreakpointNames } from './models';
|
|
@@ -24,3 +26,11 @@ export function getSliderResponsiveParams({ contentLength, slidesToShow, mobileF
|
|
|
24
26
|
return res;
|
|
25
27
|
}, {});
|
|
26
28
|
}
|
|
29
|
+
export const useMemoized = (value) => {
|
|
30
|
+
const [memoizedValue, setMemoizedValue] = useState(value);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
setMemoizedValue((memoized) => value && typeof value === 'object' && isEqual(memoized, value) ? memoized : value);
|
|
33
|
+
}, [value]);
|
|
34
|
+
return memoizedValue;
|
|
35
|
+
};
|
|
36
|
+
export const setElementAtrributes = (element, attributes) => Object.entries(attributes).forEach(([attribute, value]) => element.setAttribute(attribute, String(value)));
|
|
@@ -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
|
};
|
|
@@ -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 {
|
|
@@ -5,7 +5,7 @@ import { block, getThemedValue } from '../../utils';
|
|
|
5
5
|
import './BannerCard.css';
|
|
6
6
|
const b = block('banner-card');
|
|
7
7
|
export const BannerCard = (props) => {
|
|
8
|
-
const { title, subtitle, button: { url, text, target, theme: buttonTheme = 'raised' }, color, theme: textTheme = 'light', image, disableCompress, mediaView = 'full', } = props;
|
|
8
|
+
const { title, subtitle, button: { url, text, target, theme: buttonTheme = 'raised' } = {}, color, theme: textTheme = 'light', image, disableCompress, mediaView = 'full', } = props;
|
|
9
9
|
const theme = useTheme();
|
|
10
10
|
const contentStyle = {};
|
|
11
11
|
if (color) {
|
|
@@ -18,8 +18,8 @@ export const BannerCard = (props) => {
|
|
|
18
18
|
React.createElement("h2", { className: b('title') },
|
|
19
19
|
React.createElement(HTML, null, title)),
|
|
20
20
|
subtitle && (React.createElement(YFMWrapper, { className: b('subtitle'), content: subtitle, modifiers: { constructor: true } }))),
|
|
21
|
-
React.createElement(RouterLink, { href: url },
|
|
22
|
-
React.createElement(Button, { className: b('button'), theme: buttonTheme, size: "xl", text: text, url: url, target: target }))),
|
|
21
|
+
url && (React.createElement(RouterLink, { href: url },
|
|
22
|
+
React.createElement(Button, { className: b('button'), theme: buttonTheme, size: "xl", text: text !== null && text !== void 0 ? text : '', url: url, target: target })))),
|
|
23
23
|
React.createElement(BackgroundImage, { className: b('image'), src: getThemedValue(image, theme), disableCompress: disableCompress }))));
|
|
24
24
|
};
|
|
25
25
|
export default BannerCard;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/page-constructor",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.27.1",
|
|
4
4
|
"description": "Gravity UI Page Constructor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"test:watch": "jest --watchAll",
|
|
81
81
|
"playwright": "playwright test --config=playwright/playwright.config.ts",
|
|
82
82
|
"playwright:update": "npm run playwright -- -u",
|
|
83
|
+
"playwright:clear-cache": "rm -rf ./playwright/.cache",
|
|
83
84
|
"playwright:docker": "./scripts/playwright-docker.sh 'npm run playwright'",
|
|
84
85
|
"playwright:docker:update": "./scripts/playwright-docker.sh 'npm run playwright:update'",
|
|
85
86
|
"playwright:docker:clear-cache": "./scripts/playwright-docker.sh clear-cache",
|
|
@@ -202,6 +203,8 @@
|
|
|
202
203
|
"ts-jest": "^29.0.3",
|
|
203
204
|
"tslib": "^2.4.0",
|
|
204
205
|
"typescript": "^4.9.4",
|
|
206
|
+
"vite-plugin-commonjs": "^0.10.1",
|
|
207
|
+
"vite-plugin-svgr": "^4.2.0",
|
|
205
208
|
"webpack": "^5.88.2",
|
|
206
209
|
"webpack-cli": "^5.1.4",
|
|
207
210
|
"webpack-shell-plugin-next": "^2.3.1"
|
|
@@ -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 {
|