Skip to content

Commit 8d1dafe

Browse files
authored
feat: Edit mode (#347)
feat: add page structure editor
1 parent 940dfe6 commit 8d1dafe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1990
-66
lines changed

.devexp.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,16 @@
6161
"uuid": "^9.0.0"
6262
},
6363
"peerDependencies": {
64-
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
64+
"@doc-tools/transform": "^2.6.1",
6565
"@gravity-ui/uikit": "^4.1.0",
66-
"@doc-tools/transform": "^2.6.1"
66+
"react": "^16.0.0 || ^17.0.0 || ^18.0.0"
6767
},
6868
"devDependencies": {
6969
"@commitlint/cli": "^17.1.2",
7070
"@commitlint/config-conventional": "^17.1.0",
7171
"@doc-tools/transform": "2.12.0",
7272
"@gravity-ui/eslint-config": "^2.0.0",
73+
"@gravity-ui/icons": "^2.1.0",
7374
"@gravity-ui/prettier-config": "^1.0.1",
7475
"@gravity-ui/stylelint-config": "^1.0.0",
7576
"@gravity-ui/tsconfig": "^1.0.0",

src/blocks/Companies/__stories__/data.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
"default": {
33
"content": {
44
"type": "companies-block",
5-
"title": "Our Clients",
5+
"title": "Page constructor",
66
"images": {
77
"light": {
88
"desktop": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_desktop_light.svg",
99
"tablet": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_tablet_light.svg",
1010
"mobile": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_mobile_light.svg",
11-
"alt": "Our Clients"
11+
"alt": "Page constructor"
1212
},
1313
"dark": {
1414
"desktop": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_desktop_dark.svg",
1515
"tablet": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_tablet_dark.svg",
1616
"mobile": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_mobile_dark.svg",
17-
"alt": "Our Clients"
17+
"alt": "Page constructor"
1818
}
1919
}
2020
}

src/components/BlockBase/BlockBase.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import React from 'react';
1+
import React, {PropsWithChildren} from 'react';
22

3+
import {BlockDecoration} from '../../customization/BlockDecoration';
34
import {Col} from '../../grid';
4-
import {BlockBaseProps, ClassNameProps, WithChildren} from '../../models';
5+
import {BlockBaseProps, ClassNameProps} from '../../models';
56
import {block} from '../../utils';
67
import Anchor from '../Anchor/Anchor';
78

89
import './BlockBase.scss';
910

1011
const b = block('block-base');
1112

12-
const BlockBase = (props: WithChildren<BlockBaseProps & ClassNameProps>) => {
13+
const BlockBase = (props: PropsWithChildren<BlockBaseProps & ClassNameProps>) => {
1314
const {anchor, visible, children, className, resetPaddings, qa} = props;
1415

1516
return (
@@ -19,8 +20,10 @@ const BlockBase = (props: WithChildren<BlockBaseProps & ClassNameProps>) => {
1920
reset={true}
2021
dataQa={qa}
2122
>
22-
{anchor && <Anchor id={anchor.url} className={b('anchor')} />}
23-
{children}
23+
<BlockDecoration>
24+
{anchor && <Anchor id={anchor.url} className={b('anchor')} />}
25+
{children}
26+
</BlockDecoration>
2427
</Col>
2528
);
2629
};

src/containers/Loadable/Loadable.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import {Spin} from '@gravity-ui/uikit';
44
import blockCn from 'bem-cn-lite';
55

66
import ErrorWrapper from '../../components/ErrorWrapper/ErrorWrapper';
7-
import {Block, CustomItem, FetchLoadableData, LoadableData, LoadableProps} from '../../models';
7+
import {
8+
ConstructorItem,
9+
CustomItem,
10+
FetchLoadableData,
11+
LoadableData,
12+
LoadableProps,
13+
} from '../../models';
814

915
import i18n from './i18n';
1016

@@ -21,7 +27,7 @@ export interface LoadableState {
2127
export interface LoadableComponentsProps extends Omit<PropsWithChildren<LoadableProps>, 'source'> {
2228
Component: CustomItem;
2329
ChildComponent: CustomItem;
24-
block: Block;
30+
block: ConstructorItem;
2531
blockKey: string;
2632
fetch: FetchLoadableData;
2733
}

src/containers/PageConstructor/PageConstructor.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {InnerContext} from '../../context/innerContext';
99
import {ThemeValueContext} from '../../context/theme/ThemeValueContext';
1010
import {Grid} from '../../grid';
1111
import {
12-
Block,
1312
BlockType,
1413
BlockTypes,
1514
CustomConfig,
@@ -27,6 +26,8 @@ import {
2726
getCustomHeaderTypes,
2827
getCustomItems,
2928
getCustomSubBlockTypes,
29+
getHeaderBlock,
30+
getOrderedBlocks,
3031
getThemedValue,
3132
} from '../../utils';
3233

@@ -71,6 +72,9 @@ export const Constructor = (props: PageConstructorProps) => {
7172
},
7273
loadables: custom?.loadable,
7374
shouldRenderBlock,
75+
customization: {
76+
decorators: custom?.decorators,
77+
},
7478
},
7579
}),
7680
[custom, shouldRenderBlock],
@@ -79,9 +83,8 @@ export const Constructor = (props: PageConstructorProps) => {
7983
const {themeValue: theme} = useContext(ThemeValueContext);
8084

8185
const hasFootnotes = footnotes.length > 0;
82-
const isHeaderBlock = (block: Block) => context.headerBlockTypes.includes(block.type);
83-
const header = blocks?.find(isHeaderBlock);
84-
const restBlocks = blocks?.filter((block) => !isHeaderBlock(block));
86+
const header = getHeaderBlock(blocks, context.headerBlockTypes);
87+
const restBlocks = getOrderedBlocks(blocks, context.headerBlockTypes);
8588
const themedBackground = getThemedValue(background, theme);
8689

8790
return (

src/containers/PageConstructor/components/ConstructorBlocks/ConstructorBlocks.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {Fragment, ReactElement, useContext} from 'react';
22

33
import _ from 'lodash';
44

5+
import {BlockIdContext} from '../../../../context/blockIdContext';
56
import {InnerContext} from '../../../../context/innerContext';
67
import {Block, ConstructorItem as ConstructorItemType} from '../../../../models';
78
import {getBlockKey} from '../../../../utils';
@@ -57,18 +58,20 @@ export const ConstructorBlocks: React.FC<ConstructorBlocksProps> = ({items}) =>
5758
}
5859

5960
itemElement = (
60-
<ConstructorItem data={item} key={blockId} blockKey={blockId}>
61+
<ConstructorItem data={item} blockKey={blockId}>
6162
{children}
6263
</ConstructorItem>
6364
);
6465
}
6566

66-
return blockTypes.includes(item.type) ? (
67-
<ConstructorBlock data={item as Block} key={blockId}>
68-
{itemElement}
69-
</ConstructorBlock>
70-
) : (
71-
itemElement
67+
return (
68+
<BlockIdContext.Provider value={blockId} key={blockId}>
69+
{blockTypes.includes(item.type) ? (
70+
<ConstructorBlock data={item as Block}>{itemElement}</ConstructorBlock>
71+
) : (
72+
itemElement
73+
)}
74+
</BlockIdContext.Provider>
7275
);
7376
};
7477

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
import React, {useContext} from 'react';
22

3-
import {BlockIdContext} from '../../../../context/blockIdContext';
43
import {InnerContext} from '../../../../context/innerContext';
4+
import {BlockDecoration} from '../../../../customization/BlockDecoration';
55
import {ConstructorItem as ConstructorItemType, WithChildren} from '../../../../models';
66

77
export interface ConstructorItemProps {
88
data: ConstructorItemType;
99
blockKey: string;
1010
}
1111

12-
export const ConstructorItem = ({data, blockKey, children}: WithChildren<ConstructorItemProps>) => {
12+
export const ConstructorItem = ({data, children}: WithChildren<ConstructorItemProps>) => {
1313
const {itemMap} = useContext(InnerContext);
1414
const {type, ...rest} = data;
1515

1616
const Component = itemMap[type] as React.ComponentType<
1717
React.ComponentProps<typeof itemMap[typeof type]>
1818
>;
1919

20-
return (
21-
<BlockIdContext.Provider value={blockKey}>
22-
<Component {...rest}>{children}</Component>
23-
</BlockIdContext.Provider>
24-
);
20+
return <Component {...rest}>{children}</Component>;
2521
};
2622

2723
export const ConstructorHeader = ({
2824
data,
2925
blockKey,
3026
}: Pick<ConstructorItemProps, 'data' | 'blockKey'>) => (
31-
<ConstructorItem data={data} key={data.type} blockKey={blockKey} />
27+
<BlockDecoration id={data.type}>
28+
<ConstructorItem data={data} key={data.type} blockKey={blockKey} />
29+
</BlockDecoration>
3230
);

src/context/innerContext/InnerContext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
import {ItemMap} from '../../containers/PageConstructor/PageConstructor';
4-
import {LoadableConfig, ShouldRenderBlock} from '../../models';
4+
import {CustomConfig, LoadableConfig, ShouldRenderBlock} from '../../models';
55

66
export interface InnerContextType {
77
blockTypes: string[];
@@ -10,6 +10,7 @@ export interface InnerContextType {
1010
itemMap: ItemMap;
1111
loadables?: LoadableConfig;
1212
shouldRenderBlock?: ShouldRenderBlock;
13+
customization?: Pick<CustomConfig, 'decorators'>;
1314
}
1415

1516
export const InnerContext = React.createContext<InnerContextType>({

0 commit comments

Comments
 (0)