@gravity-ui/page-constructor 2.19.0 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/build/cjs/components/BlockBase/BlockBase.d.ts +3 -2
- package/build/cjs/components/BlockBase/BlockBase.js +4 -2
- package/build/cjs/containers/Loadable/Loadable.d.ts +2 -2
- package/build/cjs/containers/PageConstructor/PageConstructor.js +5 -3
- package/build/cjs/containers/PageConstructor/components/ConstructorBlocks/ConstructorBlocks.js +3 -2
- package/build/cjs/containers/PageConstructor/components/ConstructorItem/ConstructorItem.d.ts +1 -1
- package/build/cjs/containers/PageConstructor/components/ConstructorItem/ConstructorItem.js +5 -5
- package/build/cjs/context/innerContext/InnerContext.d.ts +2 -1
- package/build/cjs/customization/BlockDecoration.d.ts +3 -0
- package/build/cjs/customization/BlockDecoration.js +16 -0
- package/build/cjs/editor/Components/AddBlock/AddBlock.css +82 -0
- package/build/cjs/editor/Components/AddBlock/AddBlock.d.ts +7 -0
- package/build/cjs/editor/Components/AddBlock/AddBlock.js +43 -0
- package/build/cjs/editor/Components/EditBlock/EditBlock.css +41 -0
- package/build/cjs/editor/Components/EditBlock/EditBlock.d.ts +4 -0
- package/build/cjs/editor/Components/EditBlock/EditBlock.js +36 -0
- package/build/cjs/editor/Containers/Editor.d.ts +2 -0
- package/build/cjs/editor/Containers/Editor.js +24 -0
- package/build/cjs/editor/data/index.d.ts +13 -0
- package/build/cjs/editor/data/index.js +27 -0
- package/build/cjs/editor/data/previews/default-preview.d.ts +3 -0
- package/build/cjs/editor/data/previews/default-preview.js +18 -0
- package/build/cjs/editor/data/previews/header-block.d.ts +3 -0
- package/build/cjs/editor/data/previews/header-block.js +19 -0
- package/build/cjs/editor/index.d.ts +2 -0
- package/build/cjs/editor/index.js +7 -0
- package/build/cjs/editor/store/index.d.ts +15 -0
- package/build/cjs/editor/store/index.js +32 -0
- package/build/cjs/editor/store/reducer.d.ts +41 -0
- package/build/cjs/editor/store/reducer.js +59 -0
- package/build/cjs/editor/store/utils.d.ts +13 -0
- package/build/cjs/editor/store/utils.js +34 -0
- package/build/cjs/editor/styles/mixins.css +0 -0
- package/build/cjs/editor/styles/variables.css +0 -0
- package/build/cjs/editor/types/index.d.ts +17 -0
- package/build/cjs/editor/types/index.js +2 -0
- package/build/cjs/editor/utils/index.d.ts +12 -0
- package/build/cjs/editor/utils/index.js +14 -0
- package/build/cjs/models/constructor-items/blocks.d.ts +1 -11
- package/build/cjs/models/constructor-items/blocks.js +0 -2
- package/build/cjs/models/constructor.d.ts +4 -1
- package/build/cjs/models/customization.d.ts +5 -0
- package/build/cjs/models/customization.js +2 -0
- package/build/cjs/models/index.d.ts +1 -0
- package/build/cjs/models/index.js +1 -0
- package/build/cjs/utils/blocks.d.ts +3 -1
- package/build/cjs/utils/blocks.js +9 -1
- package/build/esm/components/BlockBase/BlockBase.d.ts +3 -2
- package/build/esm/components/BlockBase/BlockBase.js +4 -2
- package/build/esm/containers/Loadable/Loadable.d.ts +2 -2
- package/build/esm/containers/PageConstructor/PageConstructor.js +6 -4
- package/build/esm/containers/PageConstructor/components/ConstructorBlocks/ConstructorBlocks.js +3 -2
- package/build/esm/containers/PageConstructor/components/ConstructorItem/ConstructorItem.d.ts +1 -1
- package/build/esm/containers/PageConstructor/components/ConstructorItem/ConstructorItem.js +5 -5
- package/build/esm/context/innerContext/InnerContext.d.ts +2 -1
- package/build/esm/customization/BlockDecoration.d.ts +3 -0
- package/build/esm/customization/BlockDecoration.js +11 -0
- package/build/esm/editor/Components/AddBlock/AddBlock.css +82 -0
- package/build/esm/editor/Components/AddBlock/AddBlock.d.ts +8 -0
- package/build/esm/editor/Components/AddBlock/AddBlock.js +41 -0
- package/build/esm/editor/Components/EditBlock/EditBlock.css +41 -0
- package/build/esm/editor/Components/EditBlock/EditBlock.d.ts +5 -0
- package/build/esm/editor/Components/EditBlock/EditBlock.js +34 -0
- package/build/esm/editor/Containers/Editor.d.ts +2 -0
- package/build/esm/editor/Containers/Editor.js +20 -0
- package/build/esm/editor/data/index.d.ts +13 -0
- package/build/esm/editor/data/index.js +24 -0
- package/build/esm/editor/data/previews/default-preview.d.ts +3 -0
- package/build/esm/editor/data/previews/default-preview.js +15 -0
- package/build/esm/editor/data/previews/header-block.d.ts +3 -0
- package/build/esm/editor/data/previews/header-block.js +16 -0
- package/build/esm/editor/index.d.ts +2 -0
- package/build/esm/editor/index.js +2 -0
- package/build/esm/editor/store/index.d.ts +15 -0
- package/build/esm/editor/store/index.js +28 -0
- package/build/esm/editor/store/reducer.d.ts +41 -0
- package/build/esm/editor/store/reducer.js +55 -0
- package/build/esm/editor/store/utils.d.ts +13 -0
- package/build/esm/editor/store/utils.js +26 -0
- package/build/esm/editor/styles/mixins.css +0 -0
- package/build/esm/editor/styles/variables.css +0 -0
- package/build/esm/editor/types/index.d.ts +17 -0
- package/build/esm/editor/types/index.js +1 -0
- package/build/esm/editor/utils/index.d.ts +12 -0
- package/build/esm/editor/utils/index.js +7 -0
- package/build/esm/models/constructor-items/blocks.d.ts +1 -11
- package/build/esm/models/constructor-items/blocks.js +0 -2
- package/build/esm/models/constructor.d.ts +4 -1
- package/build/esm/models/customization.d.ts +5 -0
- package/build/esm/models/customization.js +1 -0
- package/build/esm/models/index.d.ts +1 -0
- package/build/esm/models/index.js +1 -0
- package/build/esm/utils/blocks.d.ts +3 -1
- package/build/esm/utils/blocks.js +6 -0
- package/package.json +4 -3
- package/server/models/constructor-items/blocks.d.ts +1 -11
- package/server/models/constructor-items/blocks.js +0 -2
- package/server/models/constructor.d.ts +4 -1
- package/server/models/customization.d.ts +5 -0
- package/server/models/customization.js +2 -0
- package/server/models/index.d.ts +1 -0
- package/server/models/index.js +1 -0
- package/server/utils/blocks.d.ts +3 -1
- package/server/utils/blocks.js +9 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getReducer = exports.ORDER_BLOCK = exports.SET_REGION = exports.ADD_BLOCK = exports.COPY_BLOCK = exports.DELETE_BLOCK = exports.SELECT_BLOCK = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const utils_2 = require("./utils");
|
|
6
|
+
// actions
|
|
7
|
+
exports.SELECT_BLOCK = 'SELECT_BLOCK';
|
|
8
|
+
exports.DELETE_BLOCK = 'DELETE_BLOCK';
|
|
9
|
+
exports.COPY_BLOCK = 'COPY_BLOCK';
|
|
10
|
+
exports.ADD_BLOCK = 'ADD_BLOCK';
|
|
11
|
+
exports.SET_REGION = 'SET_REGION';
|
|
12
|
+
exports.ORDER_BLOCK = 'ORDER_BLOCK';
|
|
13
|
+
// reducer
|
|
14
|
+
const getReducer = (headerBlockTypes) => (state, action) => {
|
|
15
|
+
const { content } = state;
|
|
16
|
+
const header = (0, utils_1.getHeaderBlock)(content.blocks, headerBlockTypes);
|
|
17
|
+
const orderedBlocks = (0, utils_1.getOrderedBlocks)(content.blocks, headerBlockTypes);
|
|
18
|
+
const withHeader = (blocks) => [header, ...blocks].filter(Boolean);
|
|
19
|
+
const getNewState = (blocks, activeBlockId) => (Object.assign(Object.assign({}, state), { content: Object.assign(Object.assign({}, content), { blocks }), activeBlockId, orderedBlocksCount: orderedBlocks.length }));
|
|
20
|
+
switch (action.type) {
|
|
21
|
+
case exports.SELECT_BLOCK:
|
|
22
|
+
return getNewState(content.blocks, action.payload);
|
|
23
|
+
case exports.DELETE_BLOCK: {
|
|
24
|
+
const blockId = action.payload;
|
|
25
|
+
return getNewState(typeof blockId === 'string'
|
|
26
|
+
? content.blocks.filter(({ type }) => type !== blockId)
|
|
27
|
+
: withHeader(orderedBlocks.filter((_block, index) => index !== blockId)), -1);
|
|
28
|
+
}
|
|
29
|
+
case exports.COPY_BLOCK: {
|
|
30
|
+
const index = action.payload;
|
|
31
|
+
return getNewState(withHeader((0, utils_2.duplicateBlock)(orderedBlocks, index)), index + 1);
|
|
32
|
+
}
|
|
33
|
+
case exports.ADD_BLOCK: {
|
|
34
|
+
let blocks;
|
|
35
|
+
let activeBlockId;
|
|
36
|
+
const block = action.payload;
|
|
37
|
+
if (headerBlockTypes.includes(block.type)) {
|
|
38
|
+
blocks = header ? blocks : [block, ...orderedBlocks];
|
|
39
|
+
activeBlockId = block.type;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const newBlockIndex = (0, utils_2.getNewBlockIndex)(state.activeBlockId, orderedBlocks.length);
|
|
43
|
+
blocks = withHeader((0, utils_2.addBlock)(orderedBlocks, block, newBlockIndex));
|
|
44
|
+
activeBlockId = newBlockIndex;
|
|
45
|
+
}
|
|
46
|
+
if (blocks) {
|
|
47
|
+
return getNewState(blocks, activeBlockId);
|
|
48
|
+
}
|
|
49
|
+
return state;
|
|
50
|
+
}
|
|
51
|
+
case exports.ORDER_BLOCK: {
|
|
52
|
+
const { oldIndex, newIndex } = action.payload;
|
|
53
|
+
return getNewState(withHeader((0, utils_2.changeBlocksOrder)(orderedBlocks, oldIndex, newIndex)), newIndex);
|
|
54
|
+
}
|
|
55
|
+
default:
|
|
56
|
+
return state;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.getReducer = getReducer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Block, PageContent } from '../../models';
|
|
2
|
+
import { EditorBlockId } from './reducer';
|
|
3
|
+
export declare const changeBlocksOrder: (array: Block[], oldIndex: number, newIndex: number) => Block[];
|
|
4
|
+
export declare const duplicateBlock: (array: Block[], index: number) => Block[];
|
|
5
|
+
export declare const getNewBlockIndex: (id: EditorBlockId, orderedBlocksCount: number) => number;
|
|
6
|
+
export declare const addBlock: (array: Block[], block: Block, index: number) => Block[];
|
|
7
|
+
export declare const addEditorProps: (content: PageContent) => {
|
|
8
|
+
animated: boolean;
|
|
9
|
+
blocks: Block[];
|
|
10
|
+
menu?: import("../../models").Menu | undefined;
|
|
11
|
+
background?: import("../../models").ThemedMediaProps | undefined;
|
|
12
|
+
footnotes?: string[] | undefined;
|
|
13
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addEditorProps = exports.addBlock = exports.getNewBlockIndex = exports.duplicateBlock = exports.changeBlocksOrder = void 0;
|
|
4
|
+
const changeBlocksOrder = (array, oldIndex, newIndex) => {
|
|
5
|
+
const result = [...array];
|
|
6
|
+
const element = result.splice(oldIndex, 1)[0];
|
|
7
|
+
result.splice(newIndex, 0, element);
|
|
8
|
+
return result;
|
|
9
|
+
};
|
|
10
|
+
exports.changeBlocksOrder = changeBlocksOrder;
|
|
11
|
+
const duplicateBlock = (array, index) => {
|
|
12
|
+
const result = [...array];
|
|
13
|
+
result.splice(index + 1, 0, result[index]);
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
exports.duplicateBlock = duplicateBlock;
|
|
17
|
+
const getNewBlockIndex = (id, orderedBlocksCount) => {
|
|
18
|
+
if (id === -1) {
|
|
19
|
+
return orderedBlocksCount;
|
|
20
|
+
}
|
|
21
|
+
// id === 'string' - header block
|
|
22
|
+
return typeof id === 'string' ? 0 : id + 1;
|
|
23
|
+
};
|
|
24
|
+
exports.getNewBlockIndex = getNewBlockIndex;
|
|
25
|
+
const addBlock = (array, block, index) => {
|
|
26
|
+
const result = [...array];
|
|
27
|
+
result.splice(index, 0, block);
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
exports.addBlock = addBlock;
|
|
31
|
+
const addEditorProps = (content) => {
|
|
32
|
+
return Object.assign(Object.assign({}, content), { animated: false });
|
|
33
|
+
};
|
|
34
|
+
exports.addEditorProps = addEditorProps;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PageConstructorProps } from '../../containers/PageConstructor';
|
|
3
|
+
import { BlockDecorationProps, PageData } from '../../models';
|
|
4
|
+
export type EditorBlockId = number | string;
|
|
5
|
+
export interface EditorProps extends Required<Pick<PageConstructorProps, 'content'>>, Partial<Omit<PageConstructorProps, 'content'>> {
|
|
6
|
+
children: (props: Partial<PageConstructorProps>) => React.ReactNode;
|
|
7
|
+
onChange?: (data: PageData) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface EditBlockEditorProps {
|
|
10
|
+
activeBlockId: EditorBlockId;
|
|
11
|
+
orderedBlocksCount: number;
|
|
12
|
+
onSelect: (index: EditorBlockId) => void;
|
|
13
|
+
onDelete: (index: EditorBlockId) => void;
|
|
14
|
+
onCopy: (index: number) => void;
|
|
15
|
+
onOrderChange: (index: number, newIndex: number) => void;
|
|
16
|
+
}
|
|
17
|
+
export type EditBlockProps = EditBlockEditorProps & BlockDecorationProps;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BlockDecorator, CustomConfig } from '../../models';
|
|
2
|
+
export declare const formatBlockName: (name: string) => string;
|
|
3
|
+
export declare const getBlockIndexFromId: (blockId?: string) => number;
|
|
4
|
+
export declare const addCustomDecorator: (decorator: BlockDecorator, custom?: CustomConfig) => {
|
|
5
|
+
decorators: {
|
|
6
|
+
block: ((props: import("../../models").BlockDecorationProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>)[];
|
|
7
|
+
};
|
|
8
|
+
blocks?: import("../../models").CustomItems | undefined;
|
|
9
|
+
subBlocks?: import("../../models").CustomItems | undefined;
|
|
10
|
+
headers?: import("../../models").CustomItems | undefined;
|
|
11
|
+
loadable?: import("../../models").LoadableConfig | undefined;
|
|
12
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addCustomDecorator = exports.getBlockIndexFromId = exports.formatBlockName = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
+
const formatBlockName = (name) => lodash_1.default.capitalize(name).replace(/(block|-)/g, ' ');
|
|
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
|
+
const addCustomDecorator = (decorator, custom = {}) => {
|
|
11
|
+
const decorators = custom.decorators || {};
|
|
12
|
+
return Object.assign(Object.assign({}, custom), { decorators: Object.assign(Object.assign({}, decorators), { block: [...(decorators.block || []), decorator] }) });
|
|
13
|
+
};
|
|
14
|
+
exports.addCustomDecorator = addCustomDecorator;
|
|
@@ -8,8 +8,6 @@ export declare enum BlockType {
|
|
|
8
8
|
PromoFeaturesBlock = "promo-features-block",
|
|
9
9
|
ExtendedFeaturesBlock = "extended-features-block",
|
|
10
10
|
SliderBlock = "slider-block",
|
|
11
|
-
CalculatorBlock = "calculator-block",
|
|
12
|
-
ServiceDemoBlock = "service-demo-block",
|
|
13
11
|
QuestionsBlock = "questions-block",
|
|
14
12
|
BannerBlock = "banner-block",
|
|
15
13
|
CompaniesBlock = "companies-block",
|
|
@@ -52,7 +50,6 @@ export interface LoadableProps {
|
|
|
52
50
|
export interface LoadableChildren {
|
|
53
51
|
loadable?: LoadableProps;
|
|
54
52
|
}
|
|
55
|
-
export type ServiceDemoProps = Animatable;
|
|
56
53
|
export declare enum SliderBreakpointNames {
|
|
57
54
|
Sm = "sm",
|
|
58
55
|
Md = "md",
|
|
@@ -114,7 +111,6 @@ export interface HeaderBlockProps {
|
|
|
114
111
|
breadcrumbs?: HeaderBreadCrumbsProps;
|
|
115
112
|
status?: JSX.Element;
|
|
116
113
|
}
|
|
117
|
-
export type CalculatorProps = Animatable;
|
|
118
114
|
export interface SimpleBlockProps extends Animatable, Childable {
|
|
119
115
|
title: TitleBaseProps;
|
|
120
116
|
description: string;
|
|
@@ -317,15 +313,9 @@ export interface ShareBlockProps {
|
|
|
317
313
|
export type HeaderBlockModel = {
|
|
318
314
|
type: BlockType.HeaderBlock;
|
|
319
315
|
} & HeaderBlockProps;
|
|
320
|
-
export type CalculatorBlockModel = {
|
|
321
|
-
type: BlockType.CalculatorBlock;
|
|
322
|
-
} & CalculatorProps;
|
|
323
316
|
export type SliderBlockModel = {
|
|
324
317
|
type: BlockType.SliderBlock;
|
|
325
318
|
} & SliderProps;
|
|
326
|
-
export type ServiceDemoBlockModel = {
|
|
327
|
-
type: BlockType.ServiceDemoBlock;
|
|
328
|
-
} & ServiceDemoProps;
|
|
329
319
|
export type ExtendedFeaturesBlockModel = {
|
|
330
320
|
type: BlockType.ExtendedFeaturesBlock;
|
|
331
321
|
} & ExtendedFeaturesProps;
|
|
@@ -386,6 +376,6 @@ export type ContentLayoutBlockModel = {
|
|
|
386
376
|
export type ShareBLockModel = {
|
|
387
377
|
type: BlockType.ShareBlock;
|
|
388
378
|
} & ShareBlockProps;
|
|
389
|
-
type BlockModels = SliderBlockModel |
|
|
379
|
+
type BlockModels = SliderBlockModel | ExtendedFeaturesBlockModel | PromoFeaturesBlockModel | QuestionsBlockModel | BannerBlockModel | CompaniesBlockModel | MediaBlockModel | MapBlockModel | InfoBlockModel | SecurityBlockModel | TableBlockModel | TabsBlockModel | SimpleBlockModel | LinkTableBlockModel | HeaderBlockModel | PreviewBlockModel | IconsBlockModel | HeaderSliderBlockModel | CardLayoutBlockModel | ContentLayoutBlockModel | ShareBLockModel | FilterBlockModel;
|
|
390
380
|
export type Block = BlockModels & BlockBaseProps;
|
|
391
381
|
export {};
|
|
@@ -6,8 +6,6 @@ var BlockType;
|
|
|
6
6
|
BlockType["PromoFeaturesBlock"] = "promo-features-block";
|
|
7
7
|
BlockType["ExtendedFeaturesBlock"] = "extended-features-block";
|
|
8
8
|
BlockType["SliderBlock"] = "slider-block";
|
|
9
|
-
BlockType["CalculatorBlock"] = "calculator-block";
|
|
10
|
-
BlockType["ServiceDemoBlock"] = "service-demo-block";
|
|
11
9
|
BlockType["QuestionsBlock"] = "questions-block";
|
|
12
10
|
BlockType["BannerBlock"] = "banner-block";
|
|
13
11
|
BlockType["CompaniesBlock"] = "companies-block";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import { Animatable, Block, ConstructorItem, ThemedMediaProps, WithChildren } from './';
|
|
2
|
+
import { Animatable, Block, BlockDecorationProps, ConstructorItem, ThemedMediaProps, WithChildren } from './';
|
|
3
3
|
export interface PageData {
|
|
4
4
|
content: PageContent;
|
|
5
5
|
}
|
|
@@ -41,5 +41,8 @@ export interface CustomConfig {
|
|
|
41
41
|
subBlocks?: CustomItems;
|
|
42
42
|
headers?: CustomItems;
|
|
43
43
|
loadable?: LoadableConfig;
|
|
44
|
+
decorators?: {
|
|
45
|
+
block?: ((props: BlockDecorationProps) => React.ReactElement)[];
|
|
46
|
+
};
|
|
44
47
|
}
|
|
45
48
|
export {};
|
|
@@ -8,3 +8,4 @@ tslib_1.__exportStar(require("./components"), exports);
|
|
|
8
8
|
tslib_1.__exportStar(require("./guards"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./react"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./navigation"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./customization"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomConfig, PCShareSocialNetwork, TextSize } from '../models';
|
|
1
|
+
import { Block, CustomConfig, PCShareSocialNetwork, TextSize } from '../models';
|
|
2
2
|
import { ConstructorBlock } from '../models/constructor';
|
|
3
3
|
export declare function getHeaderTag(size: TextSize): "h1" | "h2" | "h4" | "h5";
|
|
4
4
|
export declare function getBlockKey(block: ConstructorBlock, index: number): string;
|
|
@@ -8,4 +8,6 @@ export declare const getCustomItems: ({ blocks, headers, subBlocks }?: CustomCon
|
|
|
8
8
|
};
|
|
9
9
|
export declare const getCustomSubBlockTypes: (customBlocks?: CustomConfig) => string[];
|
|
10
10
|
export declare const getCustomHeaderTypes: (customBlocks?: CustomConfig) => string[];
|
|
11
|
+
export declare const getOrderedBlocks: (blocks: Block[], headerBlockTypes?: string[]) => Block[];
|
|
12
|
+
export declare const getHeaderBlock: (blocks: Block[], headerBlockTypes?: string[]) => Block | undefined;
|
|
11
13
|
export declare const getShareLink: (url: string, type: PCShareSocialNetwork, title?: string, text?: string) => string | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getShareLink = exports.getCustomHeaderTypes = exports.getCustomSubBlockTypes = exports.getCustomItems = exports.getCustomBlockTypes = exports.getBlockKey = exports.getHeaderTag = void 0;
|
|
3
|
+
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) {
|
|
@@ -46,6 +46,14 @@ const getShareUrlWithParams = (url, params = {}) => {
|
|
|
46
46
|
});
|
|
47
47
|
return result.toString();
|
|
48
48
|
};
|
|
49
|
+
const getOrderedBlocks = (blocks, headerBlockTypes = []) => {
|
|
50
|
+
return blocks.filter(({ type }) => !headerBlockTypes.includes(type));
|
|
51
|
+
};
|
|
52
|
+
exports.getOrderedBlocks = getOrderedBlocks;
|
|
53
|
+
const getHeaderBlock = (blocks, headerBlockTypes = []) => {
|
|
54
|
+
return blocks.find(({ type }) => headerBlockTypes.includes(type));
|
|
55
|
+
};
|
|
56
|
+
exports.getHeaderBlock = getHeaderBlock;
|
|
49
57
|
const getShareLink = (url, type, title, text) => {
|
|
50
58
|
// https://github.com/bradvin/social-share-urls
|
|
51
59
|
switch (type) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { BlockBaseProps, ClassNameProps } from '../../models';
|
|
2
3
|
import './BlockBase.css';
|
|
3
|
-
declare const BlockBase: (props:
|
|
4
|
+
declare const BlockBase: (props: PropsWithChildren<BlockBaseProps & ClassNameProps>) => JSX.Element;
|
|
4
5
|
export default BlockBase;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { BlockDecoration } from '../../customization/BlockDecoration';
|
|
2
3
|
import { Col } from '../../grid';
|
|
3
4
|
import { block } from '../../utils';
|
|
4
5
|
import Anchor from '../Anchor/Anchor';
|
|
@@ -7,7 +8,8 @@ const b = block('block-base');
|
|
|
7
8
|
const BlockBase = (props) => {
|
|
8
9
|
const { anchor, visible, children, className, resetPaddings, qa } = props;
|
|
9
10
|
return (React.createElement(Col, { className: b({ ['reset-paddings']: resetPaddings }, className), visible: visible, reset: true, dataQa: qa },
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
React.createElement(BlockDecoration, null,
|
|
12
|
+
anchor && React.createElement(Anchor, { id: anchor.url, className: b('anchor') }),
|
|
13
|
+
children)));
|
|
12
14
|
};
|
|
13
15
|
export default BlockBase;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ConstructorItem, CustomItem, FetchLoadableData, LoadableData, LoadableProps } from '../../models';
|
|
3
3
|
import './Loadable.css';
|
|
4
4
|
export interface LoadableState {
|
|
5
5
|
loading: boolean;
|
|
@@ -9,7 +9,7 @@ export interface LoadableState {
|
|
|
9
9
|
export interface LoadableComponentsProps extends Omit<PropsWithChildren<LoadableProps>, 'source'> {
|
|
10
10
|
Component: CustomItem;
|
|
11
11
|
ChildComponent: CustomItem;
|
|
12
|
-
block:
|
|
12
|
+
block: ConstructorItem;
|
|
13
13
|
blockKey: string;
|
|
14
14
|
fetch: FetchLoadableData;
|
|
15
15
|
}
|
|
@@ -9,7 +9,7 @@ import { ThemeValueContext } from '../../context/theme/ThemeValueContext';
|
|
|
9
9
|
import { Grid } from '../../grid';
|
|
10
10
|
import { BlockType, BlockTypes, HeaderBlockTypes, SubBlockTypes, } from '../../models';
|
|
11
11
|
import Layout from '../../navigation/containers/Layout/Layout';
|
|
12
|
-
import { block as cnBlock, getCustomBlockTypes, getCustomHeaderTypes, getCustomItems, getCustomSubBlockTypes, getThemedValue, } from '../../utils';
|
|
12
|
+
import { block as cnBlock, getCustomBlockTypes, getCustomHeaderTypes, getCustomItems, getCustomSubBlockTypes, getHeaderBlock, getOrderedBlocks, getThemedValue, } from '../../utils';
|
|
13
13
|
import { ConstructorBlocks } from './components/ConstructorBlocks';
|
|
14
14
|
import { ConstructorFootnotes } from './components/ConstructorFootnotes';
|
|
15
15
|
import { ConstructorHeader } from './components/ConstructorItem';
|
|
@@ -26,13 +26,15 @@ export const Constructor = (props) => {
|
|
|
26
26
|
itemMap: Object.assign(Object.assign(Object.assign({}, blockMap), subBlockMap), getCustomItems(custom)),
|
|
27
27
|
loadables: custom === null || custom === void 0 ? void 0 : custom.loadable,
|
|
28
28
|
shouldRenderBlock,
|
|
29
|
+
customization: {
|
|
30
|
+
decorators: custom === null || custom === void 0 ? void 0 : custom.decorators,
|
|
31
|
+
},
|
|
29
32
|
},
|
|
30
33
|
}), [custom, shouldRenderBlock]);
|
|
31
34
|
const { themeValue: theme } = useContext(ThemeValueContext);
|
|
32
35
|
const hasFootnotes = footnotes.length > 0;
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const restBlocks = blocks === null || blocks === void 0 ? void 0 : blocks.filter((block) => !isHeaderBlock(block));
|
|
36
|
+
const header = getHeaderBlock(blocks, context.headerBlockTypes);
|
|
37
|
+
const restBlocks = getOrderedBlocks(blocks, context.headerBlockTypes);
|
|
36
38
|
const themedBackground = getThemedValue(background, theme);
|
|
37
39
|
return (React.createElement(InnerContext.Provider, { value: context },
|
|
38
40
|
React.createElement("div", { className: b() },
|
package/build/esm/containers/PageConstructor/components/ConstructorBlocks/ConstructorBlocks.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { Fragment, useContext } from 'react';
|
|
2
2
|
import _ from 'lodash';
|
|
3
|
+
import { BlockIdContext } from '../../../../context/blockIdContext';
|
|
3
4
|
import { InnerContext } from '../../../../context/innerContext';
|
|
4
5
|
import { getBlockKey } from '../../../../utils';
|
|
5
6
|
import { ConstructorBlock } from '../ConstructorBlock/ConstructorBlock';
|
|
@@ -30,9 +31,9 @@ export const ConstructorBlocks = ({ items }) => {
|
|
|
30
31
|
if ('children' in item && item.children) {
|
|
31
32
|
children = item.children.map(renderer.bind(null, blockId));
|
|
32
33
|
}
|
|
33
|
-
itemElement = (React.createElement(ConstructorItem, { data: item,
|
|
34
|
+
itemElement = (React.createElement(ConstructorItem, { data: item, blockKey: blockId }, children));
|
|
34
35
|
}
|
|
35
|
-
return blockTypes.includes(item.type) ? (React.createElement(ConstructorBlock, { data: item
|
|
36
|
+
return (React.createElement(BlockIdContext.Provider, { value: blockId, key: blockId }, blockTypes.includes(item.type) ? (React.createElement(ConstructorBlock, { data: item }, itemElement)) : (itemElement)));
|
|
36
37
|
};
|
|
37
38
|
return React.createElement(Fragment, null, items.map(renderer.bind(null, '')));
|
|
38
39
|
};
|
package/build/esm/containers/PageConstructor/components/ConstructorItem/ConstructorItem.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export interface ConstructorItemProps {
|
|
|
3
3
|
data: ConstructorItemType;
|
|
4
4
|
blockKey: string;
|
|
5
5
|
}
|
|
6
|
-
export declare const ConstructorItem: ({ data,
|
|
6
|
+
export declare const ConstructorItem: ({ data, children }: WithChildren<ConstructorItemProps>) => JSX.Element;
|
|
7
7
|
export declare const ConstructorHeader: ({ data, blockKey, }: Pick<ConstructorItemProps, 'data' | 'blockKey'>) => JSX.Element;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React, { useContext } from 'react';
|
|
3
|
-
import { BlockIdContext } from '../../../../context/blockIdContext';
|
|
4
3
|
import { InnerContext } from '../../../../context/innerContext';
|
|
5
|
-
|
|
4
|
+
import { BlockDecoration } from '../../../../customization/BlockDecoration';
|
|
5
|
+
export const ConstructorItem = ({ data, children }) => {
|
|
6
6
|
const { itemMap } = useContext(InnerContext);
|
|
7
7
|
const { type } = data, rest = __rest(data, ["type"]);
|
|
8
8
|
const Component = itemMap[type];
|
|
9
|
-
return
|
|
10
|
-
React.createElement(Component, Object.assign({}, rest), children)));
|
|
9
|
+
return React.createElement(Component, Object.assign({}, rest), children);
|
|
11
10
|
};
|
|
12
|
-
export const ConstructorHeader = ({ data, blockKey, }) => (React.createElement(
|
|
11
|
+
export const ConstructorHeader = ({ data, blockKey, }) => (React.createElement(BlockDecoration, { id: data.type },
|
|
12
|
+
React.createElement(ConstructorItem, { data: data, key: data.type, blockKey: blockKey })));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ItemMap } from '../../containers/PageConstructor/PageConstructor';
|
|
3
|
-
import { LoadableConfig, ShouldRenderBlock } from '../../models';
|
|
3
|
+
import { CustomConfig, LoadableConfig, ShouldRenderBlock } from '../../models';
|
|
4
4
|
export interface InnerContextType {
|
|
5
5
|
blockTypes: string[];
|
|
6
6
|
subBlockTypes: string[];
|
|
@@ -8,5 +8,6 @@ export interface InnerContextType {
|
|
|
8
8
|
itemMap: ItemMap;
|
|
9
9
|
loadables?: LoadableConfig;
|
|
10
10
|
shouldRenderBlock?: ShouldRenderBlock;
|
|
11
|
+
customization?: Pick<CustomConfig, 'decorators'>;
|
|
11
12
|
}
|
|
12
13
|
export declare const InnerContext: React.Context<InnerContextType>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { Fragment, useContext } from 'react';
|
|
2
|
+
import { InnerContext } from '../context/innerContext';
|
|
3
|
+
export const BlockDecoration = (props) => {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
const block = React.createElement(Fragment, null, props.children);
|
|
6
|
+
const blockDecorators = (_b = (_a = useContext(InnerContext).customization) === null || _a === void 0 ? void 0 : _a.decorators) === null || _b === void 0 ? void 0 : _b.block;
|
|
7
|
+
if (!blockDecorators) {
|
|
8
|
+
return block;
|
|
9
|
+
}
|
|
10
|
+
return blockDecorators.reduce((children, decorator) => React.createElement(Fragment, null, decorator({ children, id: props.id })), block);
|
|
11
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* use this for style redefinitions to awoid problems with
|
|
2
|
+
unpredictable css rules order in build */
|
|
3
|
+
.pc-add-block {
|
|
4
|
+
position: fixed;
|
|
5
|
+
bottom: 32px;
|
|
6
|
+
left: 50%;
|
|
7
|
+
transform: translateX(-50%);
|
|
8
|
+
z-index: 110;
|
|
9
|
+
}
|
|
10
|
+
.pc-add-block__button {
|
|
11
|
+
display: inline-block;
|
|
12
|
+
margin: 0;
|
|
13
|
+
padding: 0;
|
|
14
|
+
font: inherit;
|
|
15
|
+
border: none;
|
|
16
|
+
outline: none;
|
|
17
|
+
color: inherit;
|
|
18
|
+
background: none;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
display: flex;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
align-items: center;
|
|
23
|
+
transition: transform 0.2s;
|
|
24
|
+
width: 76px;
|
|
25
|
+
height: 40px;
|
|
26
|
+
color: var(--yc-color-text-inverted-primary);
|
|
27
|
+
background-color: var(--yc-color-promo-base-neon);
|
|
28
|
+
border-radius: 8px;
|
|
29
|
+
}
|
|
30
|
+
.pc-add-block__button:hover {
|
|
31
|
+
transform: scale(1.05);
|
|
32
|
+
}
|
|
33
|
+
.pc-add-block__icon {
|
|
34
|
+
width: 16px;
|
|
35
|
+
height: 16px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.pc-add-block__popup {
|
|
39
|
+
min-width: 420px;
|
|
40
|
+
border-radius: var(--pc-border-radius);
|
|
41
|
+
box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.06), 0px 4px 24px rgba(0, 0, 0, 0.06);
|
|
42
|
+
}
|
|
43
|
+
.pc-add-block__popup .pc-add-block__search {
|
|
44
|
+
padding: 20px 20px 0;
|
|
45
|
+
}
|
|
46
|
+
.pc-add-block__popup .pc-add-block__blocks {
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-direction: column;
|
|
49
|
+
padding: 20px;
|
|
50
|
+
height: 296px;
|
|
51
|
+
max-height: 296px;
|
|
52
|
+
overflow-y: auto;
|
|
53
|
+
}
|
|
54
|
+
.pc-add-block__popup .pc-add-block__block {
|
|
55
|
+
display: flex;
|
|
56
|
+
justify-content: center;
|
|
57
|
+
align-items: center;
|
|
58
|
+
transition: transform 0.2s;
|
|
59
|
+
margin-top: 20px;
|
|
60
|
+
justify-content: flex-start;
|
|
61
|
+
cursor: pointer;
|
|
62
|
+
}
|
|
63
|
+
.pc-add-block__popup .pc-add-block__block:hover {
|
|
64
|
+
transform: scale(1.05);
|
|
65
|
+
}
|
|
66
|
+
.pc-add-block__popup .pc-add-block__block:first-child {
|
|
67
|
+
margin-top: 0;
|
|
68
|
+
}
|
|
69
|
+
.pc-add-block__popup .pc-add-block__preview {
|
|
70
|
+
width: 148px;
|
|
71
|
+
height: 74px;
|
|
72
|
+
border-radius: var(--pc-border-radius);
|
|
73
|
+
margin-right: 16px;
|
|
74
|
+
}
|
|
75
|
+
.pc-add-block__popup .pc-add-block__title {
|
|
76
|
+
font-size: var(--yc-text-body-2-font-size);
|
|
77
|
+
line-height: var(--yc-text-body-2-line-height);
|
|
78
|
+
}
|
|
79
|
+
.pc-add-block__popup .pc-add-block__title,
|
|
80
|
+
.pc-add-block__popup .pc-add-block__description {
|
|
81
|
+
margin: 0;
|
|
82
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { Block } from '../../../models';
|
|
3
|
+
import './AddBlock.css';
|
|
4
|
+
export interface AddBlockProps {
|
|
5
|
+
onAdd: (data: Block) => void;
|
|
6
|
+
}
|
|
7
|
+
declare const AddBlock: ({ onAdd }: PropsWithChildren<AddBlockProps>) => JSX.Element;
|
|
8
|
+
export default AddBlock;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { Plus } from '@gravity-ui/icons';
|
|
3
|
+
import { Popup, TextInput } from '@gravity-ui/uikit';
|
|
4
|
+
import { blockMap } from '../../../constructor-items';
|
|
5
|
+
import { block } from '../../../utils';
|
|
6
|
+
import EditorBlocksData from '../../data';
|
|
7
|
+
import './AddBlock.css';
|
|
8
|
+
const b = block('add-block');
|
|
9
|
+
const sortedBlockNames = Object.keys(blockMap).sort();
|
|
10
|
+
const AddBlock = ({ onAdd }) => {
|
|
11
|
+
const [isOpened, setIsOpened] = useState(false);
|
|
12
|
+
const [search, setSearch] = useState('');
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
const blocks = useMemo(() => sortedBlockNames.filter((blockName) => EditorBlocksData[blockName].meta.title
|
|
15
|
+
.toLocaleLowerCase()
|
|
16
|
+
.startsWith(search.toLocaleLowerCase())), [search]);
|
|
17
|
+
return (React.createElement("div", { className: b(), ref: ref },
|
|
18
|
+
React.createElement("button", { className: b('button'), onClick: () => {
|
|
19
|
+
setIsOpened(!isOpened);
|
|
20
|
+
setSearch('');
|
|
21
|
+
} },
|
|
22
|
+
React.createElement(Plus, { className: b('icon') })),
|
|
23
|
+
isOpened && (React.createElement(Popup, { anchorRef: ref, open: isOpened, className: b('popup'), placement: "top", offset: [0, 24], onOutsideClick: () => setIsOpened(false) },
|
|
24
|
+
React.createElement("div", { className: b('search') },
|
|
25
|
+
React.createElement(TextInput, { placeholder: "search", type: "text", value: search, size: "l", onUpdate: (value) => setSearch(value) })),
|
|
26
|
+
React.createElement("div", { className: b('blocks') }, blocks.map((blockName) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const blockData = EditorBlocksData[blockName];
|
|
29
|
+
const Preview = blockData === null || blockData === void 0 ? void 0 : blockData.preview;
|
|
30
|
+
return (React.createElement("div", { key: blockName, className: b('block'), onClick: () => {
|
|
31
|
+
onAdd(blockData === null || blockData === void 0 ? void 0 : blockData.template);
|
|
32
|
+
setIsOpened(false);
|
|
33
|
+
} },
|
|
34
|
+
React.createElement("div", { className: b('preview') },
|
|
35
|
+
React.createElement(Preview, null)),
|
|
36
|
+
React.createElement("div", { className: b('info') },
|
|
37
|
+
React.createElement("h4", { className: b('title') }, blockData.meta.title),
|
|
38
|
+
((_a = blockData === null || blockData === void 0 ? void 0 : blockData.meta) === null || _a === void 0 ? void 0 : _a.description) && (React.createElement("p", { className: b('description') }, blockData.meta.description)))));
|
|
39
|
+
}))))));
|
|
40
|
+
};
|
|
41
|
+
export default AddBlock;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* use this for style redefinitions to awoid problems with
|
|
2
|
+
unpredictable css rules order in build */
|
|
3
|
+
.pc-edit-block {
|
|
4
|
+
cursor: pointer;
|
|
5
|
+
position: relative;
|
|
6
|
+
}
|
|
7
|
+
.pc-edit-block__controls {
|
|
8
|
+
position: absolute;
|
|
9
|
+
width: calc(100% + 24px);
|
|
10
|
+
height: calc(100% + 24px);
|
|
11
|
+
top: -12px;
|
|
12
|
+
left: -12px;
|
|
13
|
+
border-radius: 8px;
|
|
14
|
+
z-index: 100;
|
|
15
|
+
}
|
|
16
|
+
.pc-edit-block__controls_active {
|
|
17
|
+
border: 4px solid var(--yc-color-promo-base-neon);
|
|
18
|
+
}
|
|
19
|
+
.pc-edit-block__controls-content {
|
|
20
|
+
display: flex;
|
|
21
|
+
position: absolute;
|
|
22
|
+
bottom: -36px;
|
|
23
|
+
left: 50%;
|
|
24
|
+
transform: translateX(-50%);
|
|
25
|
+
}
|
|
26
|
+
.pc-edit-block__control {
|
|
27
|
+
display: flex;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
align-items: center;
|
|
30
|
+
transition: transform 0.2s;
|
|
31
|
+
width: 24px;
|
|
32
|
+
height: 24px;
|
|
33
|
+
border-radius: calc(8px / 2);
|
|
34
|
+
background-color: var(--yc-color-promo-highlight-neon);
|
|
35
|
+
}
|
|
36
|
+
.pc-edit-block__control:hover {
|
|
37
|
+
transform: scale(1.1);
|
|
38
|
+
}
|
|
39
|
+
.pc-edit-block__control:not(:first-child) {
|
|
40
|
+
margin-left: 12px;
|
|
41
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { EditBlockProps } from '../../../editor/types';
|
|
3
|
+
import './EditBlock.css';
|
|
4
|
+
declare const _default: React.MemoExoticComponent<({ id, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }: EditBlockProps) => JSX.Element>;
|
|
5
|
+
export default _default;
|