@gravity-ui/page-constructor 2.20.0 → 2.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/build/cjs/components/BackgroundImage/BackgroundImage.js +2 -2
- package/build/cjs/components/Image/Image.d.ts +1 -0
- package/build/cjs/components/Image/Image.js +2 -2
- package/build/cjs/customization/BlockDecoration.js +7 -1
- package/build/cjs/editor/Components/EditBlock/EditBlock.css +11 -5
- package/build/cjs/editor/Components/EditBlock/EditBlock.d.ts +1 -1
- package/build/cjs/editor/Components/EditBlock/EditBlock.js +12 -16
- package/build/cjs/editor/types/index.d.ts +2 -2
- package/build/cjs/editor/utils/index.d.ts +1 -2
- package/build/cjs/editor/utils/index.js +1 -3
- package/build/cjs/models/constructor-items/common.d.ts +1 -0
- package/build/cjs/models/constructor.d.ts +2 -2
- package/build/cjs/models/customization.d.ts +5 -1
- package/build/cjs/utils/blocks.d.ts +1 -0
- package/build/cjs/utils/blocks.js +3 -1
- package/build/esm/components/BackgroundImage/BackgroundImage.js +2 -2
- package/build/esm/components/Image/Image.d.ts +1 -0
- package/build/esm/components/Image/Image.js +2 -2
- package/build/esm/customization/BlockDecoration.js +7 -1
- package/build/esm/editor/Components/EditBlock/EditBlock.css +11 -5
- package/build/esm/editor/Components/EditBlock/EditBlock.d.ts +1 -1
- package/build/esm/editor/Components/EditBlock/EditBlock.js +11 -15
- package/build/esm/editor/types/index.d.ts +2 -2
- package/build/esm/editor/utils/index.d.ts +1 -2
- package/build/esm/editor/utils/index.js +0 -1
- package/build/esm/models/constructor-items/common.d.ts +1 -0
- package/build/esm/models/constructor.d.ts +2 -2
- package/build/esm/models/customization.d.ts +5 -1
- package/build/esm/utils/blocks.d.ts +1 -0
- package/build/esm/utils/blocks.js +1 -0
- package/package.json +1 -1
- package/server/models/constructor-items/common.d.ts +1 -0
- package/server/models/constructor.d.ts +2 -2
- package/server/models/customization.d.ts +5 -1
- package/server/utils/blocks.d.ts +1 -0
- package/server/utils/blocks.js +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.20.1](https://github.com/gravity-ui/page-constructor/compare/v2.20.0...v2.20.1) (2023-05-29)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* editor scroll ([#352](https://github.com/gravity-ui/page-constructor/issues/352)) ([9fbbefe](https://github.com/gravity-ui/page-constructor/commit/9fbbefec311a0017eab7533b0b26bbddf97ff453))
|
|
9
|
+
|
|
3
10
|
## [2.20.0](https://github.com/gravity-ui/page-constructor/compare/v2.19.0...v2.20.0) (2023-05-25)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -6,8 +6,8 @@ const utils_1 = require("../../utils");
|
|
|
6
6
|
const Image_1 = tslib_1.__importDefault(require("../Image/Image"));
|
|
7
7
|
const b = (0, utils_1.block)('storage-background-image');
|
|
8
8
|
const BackgroundImage = (props) => {
|
|
9
|
-
const { children, src, desktop, className, imageClassName, style, hide } = props;
|
|
10
|
-
return (react_1.default.createElement("div", { className: b(null, className), style: style },
|
|
9
|
+
const { children, src, desktop, className, imageClassName, style, hide, qa } = props;
|
|
10
|
+
return (react_1.default.createElement("div", { className: b(null, className), style: style, "data-qa": qa },
|
|
11
11
|
(src || desktop) && !hide && react_1.default.createElement(Image_1.default, Object.assign({}, props, { className: b('img', imageClassName) })),
|
|
12
12
|
children && react_1.default.createElement("div", { className: b('container') }, children)));
|
|
13
13
|
};
|
|
@@ -5,6 +5,7 @@ export interface ImageProps extends Partial<ImageObjectProps>, Partial<ImageDevi
|
|
|
5
5
|
className?: string;
|
|
6
6
|
onClick?: MouseEventHandler;
|
|
7
7
|
containerClassName?: string;
|
|
8
|
+
qa?: string;
|
|
8
9
|
}
|
|
9
10
|
declare const Image: (props: ImageProps) => JSX.Element | null;
|
|
10
11
|
export default Image;
|
|
@@ -12,7 +12,7 @@ const checkWebP = (src) => {
|
|
|
12
12
|
};
|
|
13
13
|
const Image = (props) => {
|
|
14
14
|
const projectSettings = (0, react_1.useContext)(projectSettingsContext_1.ProjectSettingsContext);
|
|
15
|
-
const { src: imageSrc, alt = (0, i18n_1.default)('img-alt'), disableCompress, tablet, desktop, mobile, style, className, onClick, containerClassName, } = props;
|
|
15
|
+
const { src: imageSrc, alt = (0, i18n_1.default)('img-alt'), disableCompress, tablet, desktop, mobile, style, className, onClick, containerClassName, qa, } = props;
|
|
16
16
|
const [imgLoadingError, setImgLoadingError] = (0, react_1.useState)(false);
|
|
17
17
|
const src = imageSrc || desktop;
|
|
18
18
|
if (!src) {
|
|
@@ -22,7 +22,7 @@ const Image = (props) => {
|
|
|
22
22
|
disableCompress ||
|
|
23
23
|
!(0, imageCompress_1.isCompressible)(src) ||
|
|
24
24
|
imgLoadingError;
|
|
25
|
-
return (react_1.default.createElement("picture", { className: containerClassName },
|
|
25
|
+
return (react_1.default.createElement("picture", { className: containerClassName, "data-qa": qa },
|
|
26
26
|
mobile && (react_1.default.createElement(react_1.Fragment, null,
|
|
27
27
|
!disableWebp && (react_1.default.createElement("source", { srcSet: checkWebP(mobile), type: "image/webp", media: `(max-width: ${constants_1.BREAKPOINTS.sm}px)` })),
|
|
28
28
|
react_1.default.createElement("source", { srcSet: mobile, media: `(max-width: ${constants_1.BREAKPOINTS.sm}px)` }))),
|
|
@@ -3,14 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BlockDecoration = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
const blockIdContext_1 = require("../context/blockIdContext");
|
|
6
7
|
const innerContext_1 = require("../context/innerContext");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
7
9
|
const BlockDecoration = (props) => {
|
|
8
10
|
var _a, _b;
|
|
11
|
+
const blockContenxtId = (0, utils_1.getBlockIndexFromId)((0, react_1.useContext)(blockIdContext_1.BlockIdContext));
|
|
12
|
+
const { headerBlockTypes } = (0, react_1.useContext)(innerContext_1.InnerContext);
|
|
13
|
+
const blockId = props.id || blockContenxtId;
|
|
14
|
+
const isHeader = Boolean(props.id && headerBlockTypes.includes(props.id));
|
|
9
15
|
const block = react_1.default.createElement(react_1.Fragment, null, props.children);
|
|
10
16
|
const blockDecorators = (_b = (_a = (0, react_1.useContext)(innerContext_1.InnerContext).customization) === null || _a === void 0 ? void 0 : _a.decorators) === null || _b === void 0 ? void 0 : _b.block;
|
|
11
17
|
if (!blockDecorators) {
|
|
12
18
|
return block;
|
|
13
19
|
}
|
|
14
|
-
return blockDecorators.reduce((children, decorator) => react_1.default.createElement(react_1.Fragment, null, decorator({ children, id:
|
|
20
|
+
return blockDecorators.reduce((children, decorator) => (react_1.default.createElement(react_1.Fragment, null, decorator({ children, id: blockId, isHeader }))), block);
|
|
15
21
|
};
|
|
16
22
|
exports.BlockDecoration = BlockDecoration;
|
|
@@ -6,20 +6,26 @@ unpredictable css rules order in build */
|
|
|
6
6
|
}
|
|
7
7
|
.pc-edit-block__controls {
|
|
8
8
|
position: absolute;
|
|
9
|
-
width: calc(100% +
|
|
10
|
-
height: calc(100% +
|
|
11
|
-
top: -
|
|
12
|
-
left: -
|
|
9
|
+
width: calc(100% + 40px);
|
|
10
|
+
height: calc(100% + 40px);
|
|
11
|
+
top: -20px;
|
|
12
|
+
left: -20px;
|
|
13
13
|
border-radius: 8px;
|
|
14
14
|
z-index: 100;
|
|
15
15
|
}
|
|
16
|
+
.pc-edit-block__controls_isHeader {
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 100%;
|
|
19
|
+
top: 0;
|
|
20
|
+
left: 0;
|
|
21
|
+
}
|
|
16
22
|
.pc-edit-block__controls_active {
|
|
17
23
|
border: 4px solid var(--yc-color-promo-base-neon);
|
|
18
24
|
}
|
|
19
25
|
.pc-edit-block__controls-content {
|
|
20
26
|
display: flex;
|
|
21
27
|
position: absolute;
|
|
22
|
-
bottom: -
|
|
28
|
+
bottom: -44px;
|
|
23
29
|
left: 50%;
|
|
24
30
|
transform: translateX(-50%);
|
|
25
31
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { EditBlockProps } from '../../../editor/types';
|
|
3
|
-
declare const _default: React.MemoExoticComponent<({ id, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }: EditBlockProps) => JSX.Element>;
|
|
3
|
+
declare const _default: React.MemoExoticComponent<({ id, isHeader, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }: EditBlockProps) => JSX.Element>;
|
|
4
4
|
export default _default;
|
|
@@ -3,33 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
5
|
const icons_1 = require("@gravity-ui/icons");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const b = (0, utils_2.block)('edit-block');
|
|
10
|
-
const EditBlock = ({ id, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }) => {
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const b = (0, utils_1.block)('edit-block');
|
|
8
|
+
const EditBlock = ({ id, isHeader, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }) => {
|
|
11
9
|
const ref = (0, react_1.useRef)(null);
|
|
12
|
-
const
|
|
13
|
-
const blockId = id || blockContenxtId;
|
|
14
|
-
const controlsActive = activeBlockId === blockId;
|
|
10
|
+
const controlsActive = activeBlockId === id;
|
|
15
11
|
(0, react_1.useEffect)(() => {
|
|
16
12
|
var _a;
|
|
17
13
|
if (controlsActive && ref.current) {
|
|
18
|
-
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ behavior: 'smooth', block: 'center'
|
|
14
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
19
15
|
}
|
|
20
16
|
}, [controlsActive]);
|
|
21
17
|
return (react_1.default.createElement("div", { className: b(), onClick: () => {
|
|
22
|
-
onSelect(
|
|
18
|
+
onSelect(id);
|
|
23
19
|
}, ref: ref },
|
|
24
|
-
react_1.default.createElement("div", { className: b('controls', { active: controlsActive }) }, controlsActive && (react_1.default.createElement("div", { className: b('controls-content'), onClick: (e) => e.stopPropagation() },
|
|
25
|
-
typeof
|
|
26
|
-
|
|
20
|
+
react_1.default.createElement("div", { className: b('controls', { active: controlsActive, isHeader }) }, controlsActive && (react_1.default.createElement("div", { className: b('controls-content'), onClick: (e) => e.stopPropagation() },
|
|
21
|
+
typeof id === 'number' && (react_1.default.createElement(react_1.Fragment, null,
|
|
22
|
+
id > 0 && (react_1.default.createElement("div", { className: b('control'), onClick: () => onOrderChange(id, id - 1) },
|
|
27
23
|
react_1.default.createElement(icons_1.ChevronUp, null))),
|
|
28
|
-
|
|
24
|
+
id < orderedBlocksCount - 1 && (react_1.default.createElement("div", { className: b('control'), onClick: () => onOrderChange(id, id + 1) },
|
|
29
25
|
react_1.default.createElement(icons_1.ChevronDown, null))),
|
|
30
|
-
react_1.default.createElement("div", { className: b('control'), onClick: () => onCopy(
|
|
26
|
+
react_1.default.createElement("div", { className: b('control'), onClick: () => onCopy(id) },
|
|
31
27
|
react_1.default.createElement(icons_1.Copy, null)))),
|
|
32
|
-
react_1.default.createElement("div", { className: b('control'), onClick: () => onDelete(
|
|
28
|
+
react_1.default.createElement("div", { className: b('control'), onClick: () => onDelete(id) },
|
|
33
29
|
react_1.default.createElement(icons_1.TrashBin, null))))),
|
|
34
30
|
children));
|
|
35
31
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PageConstructorProps } from '../../containers/PageConstructor';
|
|
3
|
-
import {
|
|
3
|
+
import { BlockDecoratorProps, PageData } from '../../models';
|
|
4
4
|
export type EditorBlockId = number | string;
|
|
5
5
|
export interface EditorProps extends Required<Pick<PageConstructorProps, 'content'>>, Partial<Omit<PageConstructorProps, 'content'>> {
|
|
6
6
|
children: (props: Partial<PageConstructorProps>) => React.ReactNode;
|
|
@@ -14,4 +14,4 @@ export interface EditBlockEditorProps {
|
|
|
14
14
|
onCopy: (index: number) => void;
|
|
15
15
|
onOrderChange: (index: number, newIndex: number) => void;
|
|
16
16
|
}
|
|
17
|
-
export type EditBlockProps = EditBlockEditorProps &
|
|
17
|
+
export type EditBlockProps = EditBlockEditorProps & BlockDecoratorProps;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { BlockDecorator, CustomConfig } from '../../models';
|
|
2
2
|
export declare const formatBlockName: (name: string) => string;
|
|
3
|
-
export declare const getBlockIndexFromId: (blockId?: string) => number;
|
|
4
3
|
export declare const addCustomDecorator: (decorator: BlockDecorator, custom?: CustomConfig) => {
|
|
5
4
|
decorators: {
|
|
6
|
-
block: ((props: import("../../models").
|
|
5
|
+
block: ((props: import("../../models").BlockDecoratorProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>)[];
|
|
7
6
|
};
|
|
8
7
|
blocks?: import("../../models").CustomItems | undefined;
|
|
9
8
|
subBlocks?: import("../../models").CustomItems | undefined;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addCustomDecorator = exports.
|
|
3
|
+
exports.addCustomDecorator = exports.formatBlockName = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
6
|
const formatBlockName = (name) => lodash_1.default.capitalize(name).replace(/(block|-)/g, ' ');
|
|
7
7
|
exports.formatBlockName = formatBlockName;
|
|
8
|
-
const getBlockIndexFromId = (blockId) => { var _a; return Number((_a = blockId === null || blockId === void 0 ? void 0 : blockId.split('-')) === null || _a === void 0 ? void 0 : _a.at(-1)); };
|
|
9
|
-
exports.getBlockIndexFromId = getBlockIndexFromId;
|
|
10
8
|
const addCustomDecorator = (decorator, custom = {}) => {
|
|
11
9
|
const decorators = custom.decorators || {};
|
|
12
10
|
return Object.assign(Object.assign({}, custom), { decorators: Object.assign(Object.assign({}, decorators), { block: [...(decorators.block || []), decorator] }) });
|
|
@@ -99,6 +99,7 @@ export interface BackgroundImageProps extends React.HTMLProps<HTMLDivElement>, P
|
|
|
99
99
|
style?: CSSProperties;
|
|
100
100
|
imageClassName?: string;
|
|
101
101
|
hide?: boolean;
|
|
102
|
+
qa?: string;
|
|
102
103
|
}
|
|
103
104
|
export interface MediaVideoProps extends AnalyticsEventsBase {
|
|
104
105
|
src: string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import { Animatable, Block,
|
|
2
|
+
import { Animatable, Block, BlockDecoratorProps, ConstructorItem, ThemedMediaProps, WithChildren } from './';
|
|
3
3
|
export interface PageData {
|
|
4
4
|
content: PageContent;
|
|
5
5
|
}
|
|
@@ -42,7 +42,7 @@ export interface CustomConfig {
|
|
|
42
42
|
headers?: CustomItems;
|
|
43
43
|
loadable?: LoadableConfig;
|
|
44
44
|
decorators?: {
|
|
45
|
-
block?: ((props:
|
|
45
|
+
block?: ((props: BlockDecoratorProps) => React.ReactElement)[];
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
export {};
|
|
@@ -2,4 +2,8 @@ import { PropsWithChildren } from 'react';
|
|
|
2
2
|
export interface BlockDecorationProps extends PropsWithChildren {
|
|
3
3
|
id?: string;
|
|
4
4
|
}
|
|
5
|
-
export
|
|
5
|
+
export interface BlockDecoratorProps extends PropsWithChildren {
|
|
6
|
+
id: string | number;
|
|
7
|
+
isHeader?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type BlockDecorator = (props: BlockDecoratorProps) => React.ReactElement;
|
|
@@ -11,3 +11,4 @@ export declare const getCustomHeaderTypes: (customBlocks?: CustomConfig) => stri
|
|
|
11
11
|
export declare const getOrderedBlocks: (blocks: Block[], headerBlockTypes?: string[]) => Block[];
|
|
12
12
|
export declare const getHeaderBlock: (blocks: Block[], headerBlockTypes?: string[]) => Block | undefined;
|
|
13
13
|
export declare const getShareLink: (url: string, type: PCShareSocialNetwork, title?: string, text?: string) => string | undefined;
|
|
14
|
+
export declare const getBlockIndexFromId: (blockId?: string) => number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getShareLink = exports.getHeaderBlock = exports.getOrderedBlocks = exports.getCustomHeaderTypes = exports.getCustomSubBlockTypes = exports.getCustomItems = exports.getCustomBlockTypes = exports.getBlockKey = exports.getHeaderTag = void 0;
|
|
3
|
+
exports.getBlockIndexFromId = exports.getShareLink = exports.getHeaderBlock = exports.getOrderedBlocks = exports.getCustomHeaderTypes = exports.getCustomSubBlockTypes = exports.getCustomItems = exports.getCustomBlockTypes = exports.getBlockKey = exports.getHeaderTag = void 0;
|
|
4
4
|
const models_1 = require("../models");
|
|
5
5
|
function getHeaderTag(size) {
|
|
6
6
|
switch (size) {
|
|
@@ -83,3 +83,5 @@ const getShareLink = (url, type, title, text) => {
|
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
exports.getShareLink = getShareLink;
|
|
86
|
+
const getBlockIndexFromId = (blockId) => { var _a; return Number((_a = blockId === null || blockId === void 0 ? void 0 : blockId.split('-')) === null || _a === void 0 ? void 0 : _a.slice(-1).pop()); };
|
|
87
|
+
exports.getBlockIndexFromId = getBlockIndexFromId;
|
|
@@ -4,8 +4,8 @@ import Image from '../Image/Image';
|
|
|
4
4
|
import './BackgroundImage.css';
|
|
5
5
|
const b = block('storage-background-image');
|
|
6
6
|
const BackgroundImage = (props) => {
|
|
7
|
-
const { children, src, desktop, className, imageClassName, style, hide } = props;
|
|
8
|
-
return (React.createElement("div", { className: b(null, className), style: style },
|
|
7
|
+
const { children, src, desktop, className, imageClassName, style, hide, qa } = props;
|
|
8
|
+
return (React.createElement("div", { className: b(null, className), style: style, "data-qa": qa },
|
|
9
9
|
(src || desktop) && !hide && React.createElement(Image, Object.assign({}, props, { className: b('img', imageClassName) })),
|
|
10
10
|
children && React.createElement("div", { className: b('container') }, children)));
|
|
11
11
|
};
|
|
@@ -5,6 +5,7 @@ export interface ImageProps extends Partial<ImageObjectProps>, Partial<ImageDevi
|
|
|
5
5
|
className?: string;
|
|
6
6
|
onClick?: MouseEventHandler;
|
|
7
7
|
containerClassName?: string;
|
|
8
|
+
qa?: string;
|
|
8
9
|
}
|
|
9
10
|
declare const Image: (props: ImageProps) => JSX.Element | null;
|
|
10
11
|
export default Image;
|
|
@@ -9,7 +9,7 @@ const checkWebP = (src) => {
|
|
|
9
9
|
};
|
|
10
10
|
const Image = (props) => {
|
|
11
11
|
const projectSettings = useContext(ProjectSettingsContext);
|
|
12
|
-
const { src: imageSrc, alt = i18n('img-alt'), disableCompress, tablet, desktop, mobile, style, className, onClick, containerClassName, } = props;
|
|
12
|
+
const { src: imageSrc, alt = i18n('img-alt'), disableCompress, tablet, desktop, mobile, style, className, onClick, containerClassName, qa, } = props;
|
|
13
13
|
const [imgLoadingError, setImgLoadingError] = useState(false);
|
|
14
14
|
const src = imageSrc || desktop;
|
|
15
15
|
if (!src) {
|
|
@@ -19,7 +19,7 @@ const Image = (props) => {
|
|
|
19
19
|
disableCompress ||
|
|
20
20
|
!isCompressible(src) ||
|
|
21
21
|
imgLoadingError;
|
|
22
|
-
return (React.createElement("picture", { className: containerClassName },
|
|
22
|
+
return (React.createElement("picture", { className: containerClassName, "data-qa": qa },
|
|
23
23
|
mobile && (React.createElement(Fragment, null,
|
|
24
24
|
!disableWebp && (React.createElement("source", { srcSet: checkWebP(mobile), type: "image/webp", media: `(max-width: ${BREAKPOINTS.sm}px)` })),
|
|
25
25
|
React.createElement("source", { srcSet: mobile, media: `(max-width: ${BREAKPOINTS.sm}px)` }))),
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import React, { Fragment, useContext } from 'react';
|
|
2
|
+
import { BlockIdContext } from '../context/blockIdContext';
|
|
2
3
|
import { InnerContext } from '../context/innerContext';
|
|
4
|
+
import { getBlockIndexFromId } from '../utils';
|
|
3
5
|
export const BlockDecoration = (props) => {
|
|
4
6
|
var _a, _b;
|
|
7
|
+
const blockContenxtId = getBlockIndexFromId(useContext(BlockIdContext));
|
|
8
|
+
const { headerBlockTypes } = useContext(InnerContext);
|
|
9
|
+
const blockId = props.id || blockContenxtId;
|
|
10
|
+
const isHeader = Boolean(props.id && headerBlockTypes.includes(props.id));
|
|
5
11
|
const block = React.createElement(Fragment, null, props.children);
|
|
6
12
|
const blockDecorators = (_b = (_a = useContext(InnerContext).customization) === null || _a === void 0 ? void 0 : _a.decorators) === null || _b === void 0 ? void 0 : _b.block;
|
|
7
13
|
if (!blockDecorators) {
|
|
8
14
|
return block;
|
|
9
15
|
}
|
|
10
|
-
return blockDecorators.reduce((children, decorator) => React.createElement(Fragment, null, decorator({ children, id:
|
|
16
|
+
return blockDecorators.reduce((children, decorator) => (React.createElement(Fragment, null, decorator({ children, id: blockId, isHeader }))), block);
|
|
11
17
|
};
|
|
@@ -6,20 +6,26 @@ unpredictable css rules order in build */
|
|
|
6
6
|
}
|
|
7
7
|
.pc-edit-block__controls {
|
|
8
8
|
position: absolute;
|
|
9
|
-
width: calc(100% +
|
|
10
|
-
height: calc(100% +
|
|
11
|
-
top: -
|
|
12
|
-
left: -
|
|
9
|
+
width: calc(100% + 40px);
|
|
10
|
+
height: calc(100% + 40px);
|
|
11
|
+
top: -20px;
|
|
12
|
+
left: -20px;
|
|
13
13
|
border-radius: 8px;
|
|
14
14
|
z-index: 100;
|
|
15
15
|
}
|
|
16
|
+
.pc-edit-block__controls_isHeader {
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 100%;
|
|
19
|
+
top: 0;
|
|
20
|
+
left: 0;
|
|
21
|
+
}
|
|
16
22
|
.pc-edit-block__controls_active {
|
|
17
23
|
border: 4px solid var(--yc-color-promo-base-neon);
|
|
18
24
|
}
|
|
19
25
|
.pc-edit-block__controls-content {
|
|
20
26
|
display: flex;
|
|
21
27
|
position: absolute;
|
|
22
|
-
bottom: -
|
|
28
|
+
bottom: -44px;
|
|
23
29
|
left: 50%;
|
|
24
30
|
transform: translateX(-50%);
|
|
25
31
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { EditBlockProps } from '../../../editor/types';
|
|
3
3
|
import './EditBlock.css';
|
|
4
|
-
declare const _default: React.MemoExoticComponent<({ id, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }: EditBlockProps) => JSX.Element>;
|
|
4
|
+
declare const _default: React.MemoExoticComponent<({ id, isHeader, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }: EditBlockProps) => JSX.Element>;
|
|
5
5
|
export default _default;
|
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
import React, { Fragment,
|
|
1
|
+
import React, { Fragment, useEffect, useRef } from 'react';
|
|
2
2
|
import { ChevronDown, ChevronUp, Copy, TrashBin } from '@gravity-ui/icons';
|
|
3
|
-
import { BlockIdContext } from '../../../context/blockIdContext';
|
|
4
|
-
import { getBlockIndexFromId } from '../../../editor/utils';
|
|
5
3
|
import { block } from '../../../utils';
|
|
6
4
|
import './EditBlock.css';
|
|
7
5
|
const b = block('edit-block');
|
|
8
|
-
const EditBlock = ({ id, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }) => {
|
|
6
|
+
const EditBlock = ({ id, isHeader, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }) => {
|
|
9
7
|
const ref = useRef(null);
|
|
10
|
-
const
|
|
11
|
-
const blockId = id || blockContenxtId;
|
|
12
|
-
const controlsActive = activeBlockId === blockId;
|
|
8
|
+
const controlsActive = activeBlockId === id;
|
|
13
9
|
useEffect(() => {
|
|
14
10
|
var _a;
|
|
15
11
|
if (controlsActive && ref.current) {
|
|
16
|
-
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ behavior: 'smooth', block: 'center'
|
|
12
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
17
13
|
}
|
|
18
14
|
}, [controlsActive]);
|
|
19
15
|
return (React.createElement("div", { className: b(), onClick: () => {
|
|
20
|
-
onSelect(
|
|
16
|
+
onSelect(id);
|
|
21
17
|
}, ref: ref },
|
|
22
|
-
React.createElement("div", { className: b('controls', { active: controlsActive }) }, controlsActive && (React.createElement("div", { className: b('controls-content'), onClick: (e) => e.stopPropagation() },
|
|
23
|
-
typeof
|
|
24
|
-
|
|
18
|
+
React.createElement("div", { className: b('controls', { active: controlsActive, isHeader }) }, controlsActive && (React.createElement("div", { className: b('controls-content'), onClick: (e) => e.stopPropagation() },
|
|
19
|
+
typeof id === 'number' && (React.createElement(Fragment, null,
|
|
20
|
+
id > 0 && (React.createElement("div", { className: b('control'), onClick: () => onOrderChange(id, id - 1) },
|
|
25
21
|
React.createElement(ChevronUp, null))),
|
|
26
|
-
|
|
22
|
+
id < orderedBlocksCount - 1 && (React.createElement("div", { className: b('control'), onClick: () => onOrderChange(id, id + 1) },
|
|
27
23
|
React.createElement(ChevronDown, null))),
|
|
28
|
-
React.createElement("div", { className: b('control'), onClick: () => onCopy(
|
|
24
|
+
React.createElement("div", { className: b('control'), onClick: () => onCopy(id) },
|
|
29
25
|
React.createElement(Copy, null)))),
|
|
30
|
-
React.createElement("div", { className: b('control'), onClick: () => onDelete(
|
|
26
|
+
React.createElement("div", { className: b('control'), onClick: () => onDelete(id) },
|
|
31
27
|
React.createElement(TrashBin, null))))),
|
|
32
28
|
children));
|
|
33
29
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PageConstructorProps } from '../../containers/PageConstructor';
|
|
3
|
-
import {
|
|
3
|
+
import { BlockDecoratorProps, PageData } from '../../models';
|
|
4
4
|
export type EditorBlockId = number | string;
|
|
5
5
|
export interface EditorProps extends Required<Pick<PageConstructorProps, 'content'>>, Partial<Omit<PageConstructorProps, 'content'>> {
|
|
6
6
|
children: (props: Partial<PageConstructorProps>) => React.ReactNode;
|
|
@@ -14,4 +14,4 @@ export interface EditBlockEditorProps {
|
|
|
14
14
|
onCopy: (index: number) => void;
|
|
15
15
|
onOrderChange: (index: number, newIndex: number) => void;
|
|
16
16
|
}
|
|
17
|
-
export type EditBlockProps = EditBlockEditorProps &
|
|
17
|
+
export type EditBlockProps = EditBlockEditorProps & BlockDecoratorProps;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { BlockDecorator, CustomConfig } from '../../models';
|
|
2
2
|
export declare const formatBlockName: (name: string) => string;
|
|
3
|
-
export declare const getBlockIndexFromId: (blockId?: string) => number;
|
|
4
3
|
export declare const addCustomDecorator: (decorator: BlockDecorator, custom?: CustomConfig) => {
|
|
5
4
|
decorators: {
|
|
6
|
-
block: ((props: import("../../models").
|
|
5
|
+
block: ((props: import("../../models").BlockDecoratorProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>)[];
|
|
7
6
|
};
|
|
8
7
|
blocks?: import("../../models").CustomItems | undefined;
|
|
9
8
|
subBlocks?: import("../../models").CustomItems | undefined;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
export const formatBlockName = (name) => _.capitalize(name).replace(/(block|-)/g, ' ');
|
|
3
|
-
export const getBlockIndexFromId = (blockId) => { var _a; return Number((_a = blockId === null || blockId === void 0 ? void 0 : blockId.split('-')) === null || _a === void 0 ? void 0 : _a.at(-1)); };
|
|
4
3
|
export const addCustomDecorator = (decorator, custom = {}) => {
|
|
5
4
|
const decorators = custom.decorators || {};
|
|
6
5
|
return Object.assign(Object.assign({}, custom), { decorators: Object.assign(Object.assign({}, decorators), { block: [...(decorators.block || []), decorator] }) });
|
|
@@ -99,6 +99,7 @@ export interface BackgroundImageProps extends React.HTMLProps<HTMLDivElement>, P
|
|
|
99
99
|
style?: CSSProperties;
|
|
100
100
|
imageClassName?: string;
|
|
101
101
|
hide?: boolean;
|
|
102
|
+
qa?: string;
|
|
102
103
|
}
|
|
103
104
|
export interface MediaVideoProps extends AnalyticsEventsBase {
|
|
104
105
|
src: string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import { Animatable, Block,
|
|
2
|
+
import { Animatable, Block, BlockDecoratorProps, ConstructorItem, ThemedMediaProps, WithChildren } from './';
|
|
3
3
|
export interface PageData {
|
|
4
4
|
content: PageContent;
|
|
5
5
|
}
|
|
@@ -42,7 +42,7 @@ export interface CustomConfig {
|
|
|
42
42
|
headers?: CustomItems;
|
|
43
43
|
loadable?: LoadableConfig;
|
|
44
44
|
decorators?: {
|
|
45
|
-
block?: ((props:
|
|
45
|
+
block?: ((props: BlockDecoratorProps) => React.ReactElement)[];
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
export {};
|
|
@@ -2,4 +2,8 @@ import { PropsWithChildren } from 'react';
|
|
|
2
2
|
export interface BlockDecorationProps extends PropsWithChildren {
|
|
3
3
|
id?: string;
|
|
4
4
|
}
|
|
5
|
-
export
|
|
5
|
+
export interface BlockDecoratorProps extends PropsWithChildren {
|
|
6
|
+
id: string | number;
|
|
7
|
+
isHeader?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type BlockDecorator = (props: BlockDecoratorProps) => React.ReactElement;
|
|
@@ -11,3 +11,4 @@ export declare const getCustomHeaderTypes: (customBlocks?: CustomConfig) => stri
|
|
|
11
11
|
export declare const getOrderedBlocks: (blocks: Block[], headerBlockTypes?: string[]) => Block[];
|
|
12
12
|
export declare const getHeaderBlock: (blocks: Block[], headerBlockTypes?: string[]) => Block | undefined;
|
|
13
13
|
export declare const getShareLink: (url: string, type: PCShareSocialNetwork, title?: string, text?: string) => string | undefined;
|
|
14
|
+
export declare const getBlockIndexFromId: (blockId?: string) => number;
|
|
@@ -71,3 +71,4 @@ export const getShareLink = (url, type, title, text) => {
|
|
|
71
71
|
return undefined;
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
|
+
export const getBlockIndexFromId = (blockId) => { var _a; return Number((_a = blockId === null || blockId === void 0 ? void 0 : blockId.split('-')) === null || _a === void 0 ? void 0 : _a.slice(-1).pop()); };
|
package/package.json
CHANGED
|
@@ -99,6 +99,7 @@ export interface BackgroundImageProps extends React.HTMLProps<HTMLDivElement>, P
|
|
|
99
99
|
style?: CSSProperties;
|
|
100
100
|
imageClassName?: string;
|
|
101
101
|
hide?: boolean;
|
|
102
|
+
qa?: string;
|
|
102
103
|
}
|
|
103
104
|
export interface MediaVideoProps extends AnalyticsEventsBase {
|
|
104
105
|
src: string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import { Animatable, Block,
|
|
2
|
+
import { Animatable, Block, BlockDecoratorProps, ConstructorItem, ThemedMediaProps, WithChildren } from './';
|
|
3
3
|
export interface PageData {
|
|
4
4
|
content: PageContent;
|
|
5
5
|
}
|
|
@@ -42,7 +42,7 @@ export interface CustomConfig {
|
|
|
42
42
|
headers?: CustomItems;
|
|
43
43
|
loadable?: LoadableConfig;
|
|
44
44
|
decorators?: {
|
|
45
|
-
block?: ((props:
|
|
45
|
+
block?: ((props: BlockDecoratorProps) => React.ReactElement)[];
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
export {};
|
|
@@ -2,4 +2,8 @@ import { PropsWithChildren } from 'react';
|
|
|
2
2
|
export interface BlockDecorationProps extends PropsWithChildren {
|
|
3
3
|
id?: string;
|
|
4
4
|
}
|
|
5
|
-
export
|
|
5
|
+
export interface BlockDecoratorProps extends PropsWithChildren {
|
|
6
|
+
id: string | number;
|
|
7
|
+
isHeader?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type BlockDecorator = (props: BlockDecoratorProps) => React.ReactElement;
|
package/server/utils/blocks.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export declare const getCustomHeaderTypes: (customBlocks?: CustomConfig) => stri
|
|
|
11
11
|
export declare const getOrderedBlocks: (blocks: Block[], headerBlockTypes?: string[]) => Block[];
|
|
12
12
|
export declare const getHeaderBlock: (blocks: Block[], headerBlockTypes?: string[]) => Block | undefined;
|
|
13
13
|
export declare const getShareLink: (url: string, type: PCShareSocialNetwork, title?: string, text?: string) => string | undefined;
|
|
14
|
+
export declare const getBlockIndexFromId: (blockId?: string) => number;
|
package/server/utils/blocks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getShareLink = exports.getHeaderBlock = exports.getOrderedBlocks = exports.getCustomHeaderTypes = exports.getCustomSubBlockTypes = exports.getCustomItems = exports.getCustomBlockTypes = exports.getBlockKey = exports.getHeaderTag = void 0;
|
|
3
|
+
exports.getBlockIndexFromId = exports.getShareLink = exports.getHeaderBlock = exports.getOrderedBlocks = exports.getCustomHeaderTypes = exports.getCustomSubBlockTypes = exports.getCustomItems = exports.getCustomBlockTypes = exports.getBlockKey = exports.getHeaderTag = void 0;
|
|
4
4
|
const models_1 = require("../models");
|
|
5
5
|
function getHeaderTag(size) {
|
|
6
6
|
switch (size) {
|
|
@@ -83,3 +83,5 @@ const getShareLink = (url, type, title, text) => {
|
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
exports.getShareLink = getShareLink;
|
|
86
|
+
const getBlockIndexFromId = (blockId) => { var _a; return Number((_a = blockId === null || blockId === void 0 ? void 0 : blockId.split('-')) === null || _a === void 0 ? void 0 : _a.slice(-1).pop()); };
|
|
87
|
+
exports.getBlockIndexFromId = getBlockIndexFromId;
|