@gravity-ui/page-constructor 3.4.0 → 3.5.0-alpha.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 +0 -27
- package/README.md +0 -2
- package/build/cjs/blocks/Banner/schema.d.ts +21 -63
- package/build/cjs/blocks/CardLayout/schema.d.ts +4 -10
- package/build/cjs/blocks/Companies/schema.d.ts +2 -5
- package/build/cjs/blocks/ContentLayout/ContentLayout.js +2 -3
- package/build/cjs/blocks/ContentLayout/schema.d.ts +61 -107
- package/build/cjs/blocks/ContentLayout/schema.js +18 -23
- package/build/cjs/blocks/ExtendedFeatures/schema.d.ts +4 -31
- package/build/cjs/blocks/ExtendedFeatures/schema.js +3 -2
- package/build/cjs/blocks/FilterBlock/schema.d.ts +5 -13
- package/build/cjs/blocks/FilterBlock/schema.js +2 -13
- package/build/cjs/blocks/Header/Header.css +7 -6
- package/build/cjs/blocks/Header/schema.d.ts +36 -92
- package/build/cjs/blocks/Header/schema.js +0 -1
- package/build/cjs/blocks/HeaderSlider/schema.d.ts +53 -48
- package/build/cjs/blocks/HeaderSlider/schema.js +1 -3
- package/build/cjs/blocks/Icons/schema.d.ts +1 -3
- package/build/cjs/blocks/Icons/schema.js +1 -2
- package/build/cjs/blocks/Info/schema.d.ts +8 -19
- package/build/cjs/blocks/Map/schema.d.ts +6 -17
- package/build/cjs/blocks/Media/schema.d.ts +152 -204
- package/build/cjs/blocks/Media/schema.js +1 -1
- package/build/cjs/blocks/PromoFeaturesBlock/schema.d.ts +8 -22
- package/build/cjs/blocks/PromoFeaturesBlock/schema.js +0 -1
- package/build/cjs/blocks/Questions/schema.d.ts +3 -7
- package/build/cjs/blocks/Slider/schema.d.ts +18 -13
- package/build/cjs/blocks/Slider/schema.js +5 -4
- package/build/cjs/blocks/Table/schema.d.ts +2 -5
- package/build/cjs/blocks/Table/schema.js +2 -12
- package/build/cjs/blocks/Tabs/schema.d.ts +16 -43
- package/build/cjs/components/BlockBase/BlockBase.js +2 -2
- package/build/cjs/components/HeaderBreadcrumbs/HeaderBreadcrumbs.js +1 -1
- package/build/cjs/components/Image/schema.d.ts +0 -1
- package/build/cjs/components/Image/schema.js +2 -3
- package/build/cjs/containers/PageConstructor/components/ConstructorBlock/ConstructorBlock.js +1 -1
- package/build/cjs/containers/PageConstructor/components/ConstructorItem/ConstructorItem.js +1 -1
- package/build/cjs/customization/BlockDecoration.d.ts +1 -1
- package/build/cjs/customization/BlockDecoration.js +6 -5
- package/build/cjs/editor/{components → Components}/AddBlock/AddBlock.css +1 -1
- package/build/cjs/editor/Components/AddBlock/AddBlock.d.ts +7 -0
- package/build/cjs/editor/{components → Components}/AddBlock/AddBlock.js +2 -2
- package/build/cjs/editor/Components/EditBlock/EditBlock.d.ts +4 -0
- package/build/cjs/editor/Components/EditBlock/EditBlock.js +32 -0
- package/build/cjs/editor/Containers/Editor.d.ts +2 -0
- package/build/cjs/editor/Containers/Editor.js +24 -0
- package/build/cjs/editor/index.d.ts +1 -1
- package/build/cjs/editor/index.js +1 -1
- package/build/cjs/editor/store/index.d.ts +11 -10
- package/build/cjs/editor/store/index.js +15 -66
- package/build/cjs/editor/store/reducer.d.ts +9 -24
- package/build/cjs/editor/store/reducer.js +31 -17
- package/build/cjs/editor/store/utils.d.ts +0 -1
- package/build/cjs/editor/store/utils.js +1 -3
- package/build/cjs/editor/types/index.d.ts +9 -15
- package/build/cjs/editor/types/index.js +0 -6
- package/build/cjs/editor/utils/index.d.ts +3 -4
- package/build/cjs/editor/utils/index.js +4 -6
- package/build/cjs/grid/Col/Col.d.ts +1 -1
- package/build/cjs/models/constructor-items/blocks.d.ts +8 -13
- package/build/cjs/models/constructor.d.ts +2 -2
- package/build/cjs/models/customization.d.ts +8 -3
- package/build/cjs/models/navigation.d.ts +0 -1
- package/build/cjs/navigation/components/Header/Header.css +0 -2
- package/build/cjs/navigation/components/Header/Header.js +4 -15
- package/build/cjs/navigation/schema.d.ts +0 -1
- package/build/cjs/schema/index.d.ts +228 -9
- package/build/cjs/schema/index.js +46 -8
- package/build/cjs/schema/validators/common.d.ts +27 -71
- package/build/cjs/schema/validators/common.js +17 -50
- package/build/cjs/sub-blocks/BackgroundCard/schema.d.ts +5 -12
- package/build/cjs/sub-blocks/BasicCard/schema.d.ts +3 -8
- package/build/cjs/sub-blocks/Content/schema.d.ts +6 -14
- package/build/cjs/sub-blocks/Content/schema.js +1 -9
- package/build/cjs/sub-blocks/LayoutItem/schema.d.ts +9 -23
- package/build/cjs/sub-blocks/MediaCard/schema.d.ts +6 -16
- package/build/cjs/sub-blocks/PriceDetailed/schema.d.ts +0 -1
- package/build/cjs/sub-blocks/PriceDetailed/schema.js +1 -5
- package/build/cjs/sub-blocks/Quote/schema.d.ts +2 -6
- package/build/cjs/text-transform/utils.js +6 -1
- package/build/esm/blocks/Banner/schema.d.ts +21 -63
- package/build/esm/blocks/CardLayout/schema.d.ts +4 -10
- package/build/esm/blocks/Companies/schema.d.ts +2 -5
- package/build/esm/blocks/ContentLayout/ContentLayout.js +2 -3
- package/build/esm/blocks/ContentLayout/schema.d.ts +61 -107
- package/build/esm/blocks/ContentLayout/schema.js +18 -23
- package/build/esm/blocks/ExtendedFeatures/schema.d.ts +4 -31
- package/build/esm/blocks/ExtendedFeatures/schema.js +4 -3
- package/build/esm/blocks/FilterBlock/schema.d.ts +5 -13
- package/build/esm/blocks/FilterBlock/schema.js +2 -13
- package/build/esm/blocks/Header/Header.css +7 -6
- package/build/esm/blocks/Header/schema.d.ts +36 -92
- package/build/esm/blocks/Header/schema.js +0 -1
- package/build/esm/blocks/HeaderSlider/schema.d.ts +53 -48
- package/build/esm/blocks/HeaderSlider/schema.js +1 -2
- package/build/esm/blocks/Icons/schema.d.ts +1 -3
- package/build/esm/blocks/Icons/schema.js +1 -2
- package/build/esm/blocks/Info/schema.d.ts +8 -19
- package/build/esm/blocks/Map/schema.d.ts +6 -17
- package/build/esm/blocks/Media/schema.d.ts +152 -204
- package/build/esm/blocks/Media/schema.js +2 -2
- package/build/esm/blocks/PromoFeaturesBlock/schema.d.ts +8 -22
- package/build/esm/blocks/PromoFeaturesBlock/schema.js +0 -1
- package/build/esm/blocks/Questions/schema.d.ts +3 -7
- package/build/esm/blocks/Slider/schema.d.ts +18 -13
- package/build/esm/blocks/Slider/schema.js +5 -4
- package/build/esm/blocks/Table/schema.d.ts +2 -5
- package/build/esm/blocks/Table/schema.js +2 -12
- package/build/esm/blocks/Tabs/schema.d.ts +16 -43
- package/build/esm/components/BlockBase/BlockBase.js +2 -2
- package/build/esm/components/HeaderBreadcrumbs/HeaderBreadcrumbs.js +1 -1
- package/build/esm/components/Image/schema.d.ts +0 -1
- package/build/esm/components/Image/schema.js +2 -3
- package/build/esm/containers/PageConstructor/components/ConstructorBlock/ConstructorBlock.js +1 -1
- package/build/esm/containers/PageConstructor/components/ConstructorItem/ConstructorItem.js +1 -1
- package/build/esm/customization/BlockDecoration.d.ts +1 -1
- package/build/esm/customization/BlockDecoration.js +6 -6
- package/build/esm/editor/{components → Components}/AddBlock/AddBlock.css +1 -1
- package/build/esm/editor/Components/AddBlock/AddBlock.d.ts +8 -0
- package/build/esm/editor/{components → Components}/AddBlock/AddBlock.js +2 -2
- package/build/esm/editor/Components/EditBlock/EditBlock.d.ts +5 -0
- package/build/esm/editor/Components/EditBlock/EditBlock.js +30 -0
- package/build/esm/editor/Containers/Editor.d.ts +2 -0
- package/build/esm/editor/Containers/Editor.js +20 -0
- package/build/esm/editor/index.d.ts +1 -1
- package/build/esm/editor/index.js +1 -1
- package/build/esm/editor/store/index.d.ts +11 -10
- package/build/esm/editor/store/index.js +17 -68
- package/build/esm/editor/store/reducer.d.ts +9 -24
- package/build/esm/editor/store/reducer.js +29 -15
- package/build/esm/editor/store/utils.d.ts +0 -1
- package/build/esm/editor/store/utils.js +0 -1
- package/build/esm/editor/types/index.d.ts +9 -15
- package/build/esm/editor/types/index.js +1 -5
- package/build/esm/editor/utils/index.d.ts +3 -4
- package/build/esm/editor/utils/index.js +3 -4
- package/build/esm/grid/Col/Col.d.ts +1 -1
- package/build/esm/models/constructor-items/blocks.d.ts +8 -13
- package/build/esm/models/constructor.d.ts +2 -2
- package/build/esm/models/customization.d.ts +8 -3
- package/build/esm/models/navigation.d.ts +0 -1
- package/build/esm/navigation/components/Header/Header.css +0 -2
- package/build/esm/navigation/components/Header/Header.js +5 -16
- package/build/esm/navigation/schema.d.ts +0 -1
- package/build/esm/schema/index.d.ts +228 -9
- package/build/esm/schema/index.js +42 -4
- package/build/esm/schema/validators/common.d.ts +27 -71
- package/build/esm/schema/validators/common.js +16 -49
- package/build/esm/sub-blocks/BackgroundCard/schema.d.ts +5 -12
- package/build/esm/sub-blocks/BasicCard/schema.d.ts +3 -8
- package/build/esm/sub-blocks/Content/schema.d.ts +6 -14
- package/build/esm/sub-blocks/Content/schema.js +1 -9
- package/build/esm/sub-blocks/LayoutItem/schema.d.ts +9 -23
- package/build/esm/sub-blocks/MediaCard/schema.d.ts +6 -16
- package/build/esm/sub-blocks/PriceDetailed/schema.d.ts +0 -1
- package/build/esm/sub-blocks/PriceDetailed/schema.js +1 -5
- package/build/esm/sub-blocks/Quote/schema.d.ts +2 -6
- package/build/esm/text-transform/utils.js +6 -1
- package/package.json +4 -5
- package/server/models/constructor-items/blocks.d.ts +8 -13
- package/server/models/constructor.d.ts +2 -2
- package/server/models/customization.d.ts +8 -3
- package/server/models/navigation.d.ts +0 -1
- package/server/text-transform/utils.js +6 -1
- package/build/cjs/editor/components/AddBlock/AddBlock.d.ts +0 -7
- package/build/cjs/editor/components/BlockForm/BlockForm.d.ts +0 -12
- package/build/cjs/editor/components/BlockForm/BlockForm.js +0 -33
- package/build/cjs/editor/components/ControlPanel/ControlPanel.css +0 -26
- package/build/cjs/editor/components/ControlPanel/ControlPanel.d.ts +0 -8
- package/build/cjs/editor/components/ControlPanel/ControlPanel.js +0 -24
- package/build/cjs/editor/components/ControlPanel/i18n/en.json +0 -3
- package/build/cjs/editor/components/ControlPanel/i18n/index.d.ts +0 -2
- package/build/cjs/editor/components/ControlPanel/i18n/index.js +0 -8
- package/build/cjs/editor/components/ControlPanel/i18n/ru.json +0 -3
- package/build/cjs/editor/components/EditBlock/EditBlock.d.ts +0 -13
- package/build/cjs/editor/components/EditBlock/EditBlock.js +0 -44
- package/build/cjs/editor/components/ErrorBoundary/ErrorBoundary.css +0 -27
- package/build/cjs/editor/components/ErrorBoundary/ErrorBoundary.d.ts +0 -13
- package/build/cjs/editor/components/ErrorBoundary/ErrorBoundary.js +0 -35
- package/build/cjs/editor/components/ErrorBoundary/i18n/en.json +0 -4
- package/build/cjs/editor/components/ErrorBoundary/i18n/index.d.ts +0 -2
- package/build/cjs/editor/components/ErrorBoundary/i18n/index.js +0 -8
- package/build/cjs/editor/components/ErrorBoundary/i18n/ru.json +0 -4
- package/build/cjs/editor/components/Layout/Layout.css +0 -36
- package/build/cjs/editor/components/Layout/Layout.d.ts +0 -16
- package/build/cjs/editor/components/Layout/Layout.js +0 -34
- package/build/cjs/editor/components/PagePropsForm/PagePropsForm.d.ts +0 -10
- package/build/cjs/editor/components/PagePropsForm/PagePropsForm.js +0 -17
- package/build/cjs/editor/containers/Editor/Editor.d.ts +0 -2
- package/build/cjs/editor/containers/Editor/Editor.js +0 -40
- package/build/cjs/editor/containers/Form/Form.css +0 -94
- package/build/cjs/editor/containers/Form/Form.d.ts +0 -11
- package/build/cjs/editor/containers/Form/Form.js +0 -47
- package/build/cjs/editor/containers/Form/dynamic-form-custom.css +0 -0
- package/build/cjs/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.css +0 -27
- package/build/cjs/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.d.ts +0 -19
- package/build/cjs/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.js +0 -72
- package/build/cjs/editor/dynamic-forms-custom/config.d.ts +0 -2
- package/build/cjs/editor/dynamic-forms-custom/config.js +0 -13
- package/build/cjs/editor/dynamic-forms-custom/hooks/useOneOf.d.ts +0 -12
- package/build/cjs/editor/dynamic-forms-custom/hooks/useOneOf.js +0 -75
- package/build/cjs/editor/dynamic-forms-custom/parser/detect.d.ts +0 -9
- package/build/cjs/editor/dynamic-forms-custom/parser/detect.js +0 -36
- package/build/cjs/editor/dynamic-forms-custom/parser/index.d.ts +0 -28
- package/build/cjs/editor/dynamic-forms-custom/parser/index.js +0 -188
- package/build/cjs/editor/dynamic-forms-custom/parser/types.d.ts +0 -29
- package/build/cjs/editor/dynamic-forms-custom/parser/types.js +0 -2
- package/build/cjs/editor/dynamic-forms-custom/parser/views.d.ts +0 -37
- package/build/cjs/editor/dynamic-forms-custom/parser/views.js +0 -46
- package/build/cjs/editor/hooks/useFormSpec.d.ts +0 -2
- package/build/cjs/editor/hooks/useFormSpec.js +0 -13
- package/build/cjs/editor/hooks/usePreviousValue.d.ts +0 -1
- package/build/cjs/editor/hooks/usePreviousValue.js +0 -11
- package/build/cjs/editor/styles/root.css +0 -5
- package/build/cjs/schema/constants.d.ts +0 -908
- package/build/cjs/schema/constants.js +0 -42
- package/build/esm/editor/components/AddBlock/AddBlock.d.ts +0 -8
- package/build/esm/editor/components/BlockForm/BlockForm.d.ts +0 -12
- package/build/esm/editor/components/BlockForm/BlockForm.js +0 -30
- package/build/esm/editor/components/ControlPanel/ControlPanel.css +0 -26
- package/build/esm/editor/components/ControlPanel/ControlPanel.d.ts +0 -9
- package/build/esm/editor/components/ControlPanel/ControlPanel.js +0 -22
- package/build/esm/editor/components/ControlPanel/i18n/en.json +0 -3
- package/build/esm/editor/components/ControlPanel/i18n/index.d.ts +0 -2
- package/build/esm/editor/components/ControlPanel/i18n/index.js +0 -5
- package/build/esm/editor/components/ControlPanel/i18n/ru.json +0 -3
- package/build/esm/editor/components/EditBlock/EditBlock.d.ts +0 -14
- package/build/esm/editor/components/EditBlock/EditBlock.js +0 -41
- package/build/esm/editor/components/ErrorBoundary/ErrorBoundary.css +0 -27
- package/build/esm/editor/components/ErrorBoundary/ErrorBoundary.d.ts +0 -14
- package/build/esm/editor/components/ErrorBoundary/ErrorBoundary.js +0 -31
- package/build/esm/editor/components/ErrorBoundary/i18n/en.json +0 -4
- package/build/esm/editor/components/ErrorBoundary/i18n/index.d.ts +0 -2
- package/build/esm/editor/components/ErrorBoundary/i18n/index.js +0 -5
- package/build/esm/editor/components/ErrorBoundary/i18n/ru.json +0 -4
- package/build/esm/editor/components/Layout/Layout.css +0 -36
- package/build/esm/editor/components/Layout/Layout.d.ts +0 -17
- package/build/esm/editor/components/Layout/Layout.js +0 -32
- package/build/esm/editor/components/PagePropsForm/PagePropsForm.d.ts +0 -10
- package/build/esm/editor/components/PagePropsForm/PagePropsForm.js +0 -13
- package/build/esm/editor/containers/Editor/Editor.d.ts +0 -2
- package/build/esm/editor/containers/Editor/Editor.js +0 -36
- package/build/esm/editor/containers/Form/Form.css +0 -94
- package/build/esm/editor/containers/Form/Form.d.ts +0 -12
- package/build/esm/editor/containers/Form/Form.js +0 -45
- package/build/esm/editor/containers/Form/dynamic-form-custom.css +0 -0
- package/build/esm/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.css +0 -27
- package/build/esm/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.d.ts +0 -20
- package/build/esm/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.js +0 -68
- package/build/esm/editor/dynamic-forms-custom/config.d.ts +0 -2
- package/build/esm/editor/dynamic-forms-custom/config.js +0 -9
- package/build/esm/editor/dynamic-forms-custom/hooks/useOneOf.d.ts +0 -12
- package/build/esm/editor/dynamic-forms-custom/hooks/useOneOf.js +0 -69
- package/build/esm/editor/dynamic-forms-custom/parser/detect.d.ts +0 -9
- package/build/esm/editor/dynamic-forms-custom/parser/detect.js +0 -32
- package/build/esm/editor/dynamic-forms-custom/parser/index.d.ts +0 -28
- package/build/esm/editor/dynamic-forms-custom/parser/index.js +0 -186
- package/build/esm/editor/dynamic-forms-custom/parser/types.d.ts +0 -29
- package/build/esm/editor/dynamic-forms-custom/parser/types.js +0 -1
- package/build/esm/editor/dynamic-forms-custom/parser/views.d.ts +0 -37
- package/build/esm/editor/dynamic-forms-custom/parser/views.js +0 -39
- package/build/esm/editor/hooks/useFormSpec.d.ts +0 -2
- package/build/esm/editor/hooks/useFormSpec.js +0 -9
- package/build/esm/editor/hooks/usePreviousValue.d.ts +0 -1
- package/build/esm/editor/hooks/usePreviousValue.js +0 -8
- package/build/esm/editor/styles/root.css +0 -5
- package/build/esm/schema/constants.d.ts +0 -908
- package/build/esm/schema/constants.js +0 -39
- /package/build/cjs/editor/{components → Components}/EditBlock/EditBlock.css +0 -0
- /package/build/esm/editor/{components → Components}/EditBlock/EditBlock.css +0 -0
|
@@ -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, isHeader, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }: EditBlockProps) => JSX.Element>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { Fragment, useEffect, useRef } from 'react';
|
|
2
|
+
import { ChevronDown, ChevronUp, Copy, TrashBin } from '@gravity-ui/icons';
|
|
3
|
+
import { block } from '../../../utils';
|
|
4
|
+
import './EditBlock.css';
|
|
5
|
+
const b = block('edit-block');
|
|
6
|
+
const EditBlock = ({ id, isHeader, activeBlockId, onDelete, onSelect, onCopy, onOrderChange, children, orderedBlocksCount, }) => {
|
|
7
|
+
const ref = useRef(null);
|
|
8
|
+
const controlsActive = activeBlockId === id;
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
var _a;
|
|
11
|
+
if (controlsActive && ref.current) {
|
|
12
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
13
|
+
}
|
|
14
|
+
}, [controlsActive]);
|
|
15
|
+
return (React.createElement("div", { className: b(), onClick: () => {
|
|
16
|
+
onSelect(id);
|
|
17
|
+
}, ref: ref },
|
|
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) },
|
|
21
|
+
React.createElement(ChevronUp, null))),
|
|
22
|
+
id < orderedBlocksCount - 1 && (React.createElement("div", { className: b('control'), onClick: () => onOrderChange(id, id + 1) },
|
|
23
|
+
React.createElement(ChevronDown, null))),
|
|
24
|
+
React.createElement("div", { className: b('control'), onClick: () => onCopy(id) },
|
|
25
|
+
React.createElement(Copy, null)))),
|
|
26
|
+
React.createElement("div", { className: b('control'), onClick: () => onDelete(id) },
|
|
27
|
+
React.createElement(TrashBin, null))))),
|
|
28
|
+
children));
|
|
29
|
+
};
|
|
30
|
+
export default React.memo(EditBlock);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React, { useMemo } from 'react';
|
|
3
|
+
import AddBlock from '../Components/AddBlock/AddBlock';
|
|
4
|
+
import EditBlock from '../Components/EditBlock/EditBlock';
|
|
5
|
+
import { useEditorState } from '../store';
|
|
6
|
+
import { addCustomDecorator } from '../utils';
|
|
7
|
+
export const Editor = (_a) => {
|
|
8
|
+
var { children } = _a, rest = __rest(_a, ["children"]);
|
|
9
|
+
const { content, onAdd, editControlsProps } = useEditorState(rest);
|
|
10
|
+
const constructorProps = useMemo(() => {
|
|
11
|
+
const editControlsDecorator = (props) => (React.createElement(EditBlock, Object.assign({}, props, editControlsProps)));
|
|
12
|
+
return {
|
|
13
|
+
content,
|
|
14
|
+
custom: addCustomDecorator(editControlsDecorator, rest.custom),
|
|
15
|
+
};
|
|
16
|
+
}, [editControlsProps, content, rest.custom]);
|
|
17
|
+
return (React.createElement("div", null,
|
|
18
|
+
children(constructorProps),
|
|
19
|
+
React.createElement(AddBlock, { onAdd: onAdd })));
|
|
20
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Editor } from './
|
|
1
|
+
export { Editor } from './Containers/Editor';
|
|
2
2
|
export * from './types';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Editor } from './
|
|
1
|
+
export { Editor } from './Containers/Editor';
|
|
2
2
|
export * from './types';
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { Block
|
|
2
|
-
import {
|
|
1
|
+
import { Block } from '../../models';
|
|
2
|
+
import { EditorProps } from '../types';
|
|
3
3
|
export type EditorBlockId = number | string;
|
|
4
4
|
export declare function useEditorState({ content: intialContent, custom }: Omit<EditorProps, 'children'>): {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
content: import("../../models").PageContent;
|
|
6
|
+
editControlsProps: {
|
|
7
|
+
activeBlockId: import("./reducer").EditorBlockId;
|
|
8
|
+
orderedBlocksCount: number;
|
|
9
|
+
onDelete: (id: EditorBlockId) => void;
|
|
10
|
+
onSelect: (id: EditorBlockId) => void;
|
|
11
|
+
onCopy: (index: number) => void;
|
|
12
|
+
onOrderChange: (oldIndex: number, newIndex: number) => void;
|
|
13
|
+
};
|
|
10
14
|
onAdd: (block: Block) => void;
|
|
11
|
-
onSelect: (index: number) => void;
|
|
12
|
-
onContentUpdate: (newContent: PageContent) => void;
|
|
13
|
-
onViewModeUpdate: (newViewMode: ViewModeItem) => void;
|
|
14
15
|
};
|
|
@@ -1,79 +1,28 @@
|
|
|
1
1
|
import { useMemo, useReducer } from 'react';
|
|
2
2
|
import { HeaderBlockTypes } from '../../models';
|
|
3
|
-
import { getCustomHeaderTypes,
|
|
4
|
-
import {
|
|
5
|
-
import { ViewModeItem } from '../types';
|
|
6
|
-
import { ADD_BLOCK, COPY_BLOCK, DELETE_BLOCK, ORDER_BLOCK, SELECT_BLOCK, UPDATE_CONTENT, UPDATE_VIEW_MODE, reducer, } from './reducer';
|
|
3
|
+
import { getCustomHeaderTypes, getOrderedBlocks } from '../../utils';
|
|
4
|
+
import { ADD_BLOCK, COPY_BLOCK, DELETE_BLOCK, ORDER_BLOCK, SELECT_BLOCK, getReducer, } from './reducer';
|
|
7
5
|
import { addEditorProps } from './utils';
|
|
8
6
|
export function useEditorState({ content: intialContent, custom }) {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const headerBlockTypes = useMemo(() => [...HeaderBlockTypes, ...getCustomHeaderTypes(custom)], [custom]);
|
|
8
|
+
const reducer = useMemo(() => getReducer(headerBlockTypes), [headerBlockTypes]);
|
|
9
|
+
const [{ activeBlockId, content, orderedBlocksCount }, dispatch] = useReducer(reducer, {
|
|
10
|
+
activeBlockId: 0,
|
|
11
|
+
orderedBlocksCount: getOrderedBlocks(intialContent.blocks, headerBlockTypes).length,
|
|
12
12
|
content: addEditorProps(intialContent),
|
|
13
|
-
viewMode: ViewModeItem.Edititng,
|
|
14
13
|
});
|
|
15
14
|
return useMemo(() => {
|
|
16
|
-
const headerBlockTypes = [...HeaderBlockTypes, ...getCustomHeaderTypes(custom)];
|
|
17
|
-
const contentHasHeader = Boolean(getHeaderBlock(content.blocks, headerBlockTypes));
|
|
18
|
-
const checkIsHeader = (type) => headerBlockTypes.includes(type);
|
|
19
|
-
const onAdd = (block) => {
|
|
20
|
-
const isHeader = checkIsHeader(block.type);
|
|
21
|
-
if (contentHasHeader && isHeader) {
|
|
22
|
-
//TODO: add warning that it should be only one header block
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
// eslint-disable-next-line no-nested-ternary
|
|
26
|
-
const index = isHeader
|
|
27
|
-
? 0
|
|
28
|
-
: activeBlockIndex === -1
|
|
29
|
-
? content.blocks.length
|
|
30
|
-
: activeBlockIndex + 1;
|
|
31
|
-
dispatch({ type: ADD_BLOCK, payload: { block, index } });
|
|
32
|
-
};
|
|
33
|
-
const onSelect = (index) => dispatch({ type: SELECT_BLOCK, payload: index });
|
|
34
|
-
const onContentUpdate = (newContent) => dispatch({ type: UPDATE_CONTENT, payload: newContent });
|
|
35
|
-
const onViewModeUpdate = (newViewMode) => dispatch({ type: UPDATE_VIEW_MODE, payload: newViewMode });
|
|
36
|
-
const injectEditBlockProps = ({ type, index: relativeIndex = 0, children, }) => {
|
|
37
|
-
const orderedBlocksStartIndex = contentHasHeader ? 1 : 0;
|
|
38
|
-
const isHeader = checkIsHeader(type);
|
|
39
|
-
const index = isHeader ? 0 : relativeIndex + orderedBlocksStartIndex;
|
|
40
|
-
const isActive = activeBlockIndex === index;
|
|
41
|
-
const actions = {
|
|
42
|
-
[EditBlockControls.Delete]: () => dispatch({ type: DELETE_BLOCK, payload: index }),
|
|
43
|
-
};
|
|
44
|
-
if (!isHeader) {
|
|
45
|
-
actions[EditBlockControls.Copy] = () => dispatch({ type: COPY_BLOCK, payload: index });
|
|
46
|
-
if (index > orderedBlocksStartIndex) {
|
|
47
|
-
actions[EditBlockControls.Up] = () => dispatch({
|
|
48
|
-
type: ORDER_BLOCK,
|
|
49
|
-
payload: { oldIndex: index, newIndex: index - 1 },
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
if (index < content.blocks.length - 1) {
|
|
53
|
-
actions[EditBlockControls.Down] = () => dispatch({
|
|
54
|
-
type: ORDER_BLOCK,
|
|
55
|
-
payload: { oldIndex: index, newIndex: index + 1 },
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
children,
|
|
61
|
-
isHeader,
|
|
62
|
-
isActive,
|
|
63
|
-
actions,
|
|
64
|
-
onSelect: () => onSelect(index),
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
15
|
return {
|
|
68
|
-
activeBlockIndex,
|
|
69
16
|
content,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
17
|
+
editControlsProps: {
|
|
18
|
+
activeBlockId,
|
|
19
|
+
orderedBlocksCount,
|
|
20
|
+
onDelete: (id) => dispatch({ type: DELETE_BLOCK, payload: id }),
|
|
21
|
+
onSelect: (id) => dispatch({ type: SELECT_BLOCK, payload: id }),
|
|
22
|
+
onCopy: (index) => dispatch({ type: COPY_BLOCK, payload: index }),
|
|
23
|
+
onOrderChange: (oldIndex, newIndex) => dispatch({ type: ORDER_BLOCK, payload: { oldIndex, newIndex } }),
|
|
24
|
+
},
|
|
25
|
+
onAdd: (block) => dispatch({ type: ADD_BLOCK, payload: block }),
|
|
77
26
|
};
|
|
78
|
-
}, [content,
|
|
27
|
+
}, [content, activeBlockId, orderedBlocksCount]);
|
|
79
28
|
}
|
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
import { Block, PageContent } from '../../models';
|
|
2
|
-
import { ViewModeItem } from '../types';
|
|
1
|
+
import { Block, CustomConfig, PageContent } from '../../models';
|
|
3
2
|
export type EditorBlockId = number | string;
|
|
4
3
|
interface EditorState {
|
|
5
4
|
content: PageContent;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
activeBlockId: EditorBlockId;
|
|
6
|
+
orderedBlocksCount: number;
|
|
7
|
+
custom?: CustomConfig;
|
|
9
8
|
}
|
|
10
9
|
interface OrderBlockParams {
|
|
11
10
|
oldIndex: number;
|
|
12
11
|
newIndex: number;
|
|
13
12
|
}
|
|
14
|
-
interface AddBlockParams {
|
|
15
|
-
block: Block;
|
|
16
|
-
index: number;
|
|
17
|
-
}
|
|
18
13
|
export declare const SELECT_BLOCK = "SELECT_BLOCK";
|
|
19
14
|
export declare const DELETE_BLOCK = "DELETE_BLOCK";
|
|
20
15
|
export declare const COPY_BLOCK = "COPY_BLOCK";
|
|
21
16
|
export declare const ADD_BLOCK = "ADD_BLOCK";
|
|
22
17
|
export declare const SET_REGION = "SET_REGION";
|
|
23
18
|
export declare const ORDER_BLOCK = "ORDER_BLOCK";
|
|
24
|
-
export declare const UPDATE_CONTENT = "UPDATE_CONTENT";
|
|
25
|
-
export declare const UPDATE_VIEW_MODE = "UPDATE_VIEW_MODE";
|
|
26
19
|
interface SelectBlock {
|
|
27
20
|
type: typeof SELECT_BLOCK;
|
|
28
|
-
payload:
|
|
21
|
+
payload: EditorBlockId;
|
|
29
22
|
}
|
|
30
23
|
interface DeleteBlock {
|
|
31
24
|
type: typeof DELETE_BLOCK;
|
|
32
|
-
payload:
|
|
25
|
+
payload: EditorBlockId;
|
|
33
26
|
}
|
|
34
27
|
interface CopyBlock {
|
|
35
28
|
type: typeof COPY_BLOCK;
|
|
@@ -37,20 +30,12 @@ interface CopyBlock {
|
|
|
37
30
|
}
|
|
38
31
|
interface AddBlock {
|
|
39
32
|
type: typeof ADD_BLOCK;
|
|
40
|
-
payload:
|
|
33
|
+
payload: Block;
|
|
41
34
|
}
|
|
42
35
|
interface OrderBlock {
|
|
43
36
|
type: typeof ORDER_BLOCK;
|
|
44
37
|
payload: OrderBlockParams;
|
|
45
38
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
payload: PageContent;
|
|
49
|
-
}
|
|
50
|
-
interface UpdateViewMode {
|
|
51
|
-
type: typeof UPDATE_VIEW_MODE;
|
|
52
|
-
payload: ViewModeItem;
|
|
53
|
-
}
|
|
54
|
-
export type EditorAction = SelectBlock | DeleteBlock | CopyBlock | AddBlock | OrderBlock | UpdateContent | UpdateViewMode;
|
|
55
|
-
export declare const reducer: (state: EditorState, action: EditorAction) => EditorState;
|
|
39
|
+
export type EditorAction = SelectBlock | DeleteBlock | CopyBlock | AddBlock | OrderBlock;
|
|
40
|
+
export declare const getReducer: (headerBlockTypes: string[]) => (state: EditorState, action: EditorAction) => EditorState;
|
|
56
41
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getHeaderBlock, getOrderedBlocks } from '../../utils';
|
|
2
|
+
import { addBlock, changeBlocksOrder, duplicateBlock, getNewBlockIndex } from './utils';
|
|
2
3
|
// actions
|
|
3
4
|
export const SELECT_BLOCK = 'SELECT_BLOCK';
|
|
4
5
|
export const DELETE_BLOCK = 'DELETE_BLOCK';
|
|
@@ -6,35 +7,48 @@ export const COPY_BLOCK = 'COPY_BLOCK';
|
|
|
6
7
|
export const ADD_BLOCK = 'ADD_BLOCK';
|
|
7
8
|
export const SET_REGION = 'SET_REGION';
|
|
8
9
|
export const ORDER_BLOCK = 'ORDER_BLOCK';
|
|
9
|
-
export const UPDATE_CONTENT = 'UPDATE_CONTENT';
|
|
10
|
-
export const UPDATE_VIEW_MODE = 'UPDATE_VIEW_MODE';
|
|
11
10
|
// reducer
|
|
12
|
-
export const
|
|
11
|
+
export const getReducer = (headerBlockTypes) => (state, action) => {
|
|
13
12
|
const { content } = state;
|
|
14
|
-
const
|
|
13
|
+
const header = getHeaderBlock(content.blocks, headerBlockTypes);
|
|
14
|
+
const orderedBlocks = getOrderedBlocks(content.blocks, headerBlockTypes);
|
|
15
|
+
const withHeader = (blocks) => [header, ...blocks].filter(Boolean);
|
|
16
|
+
const getNewState = (blocks, activeBlockId) => (Object.assign(Object.assign({}, state), { content: Object.assign(Object.assign({}, content), { blocks }), activeBlockId, orderedBlocksCount: orderedBlocks.length }));
|
|
15
17
|
switch (action.type) {
|
|
16
|
-
case UPDATE_CONTENT:
|
|
17
|
-
return Object.assign(Object.assign({}, state), { content: action.payload, errorBoundaryState: getErrorBoundaryState(state.errorBoundaryState) });
|
|
18
18
|
case SELECT_BLOCK:
|
|
19
|
-
return
|
|
19
|
+
return getNewState(content.blocks, action.payload);
|
|
20
20
|
case DELETE_BLOCK: {
|
|
21
21
|
const blockId = action.payload;
|
|
22
|
-
return getNewState(
|
|
22
|
+
return getNewState(typeof blockId === 'string'
|
|
23
|
+
? content.blocks.filter(({ type }) => type !== blockId)
|
|
24
|
+
: withHeader(orderedBlocks.filter((_block, index) => index !== blockId)), -1);
|
|
23
25
|
}
|
|
24
26
|
case COPY_BLOCK: {
|
|
25
27
|
const index = action.payload;
|
|
26
|
-
return getNewState(duplicateBlock(
|
|
28
|
+
return getNewState(withHeader(duplicateBlock(orderedBlocks, index)), index + 1);
|
|
27
29
|
}
|
|
28
30
|
case ADD_BLOCK: {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
let blocks;
|
|
32
|
+
let activeBlockId;
|
|
33
|
+
const block = action.payload;
|
|
34
|
+
if (headerBlockTypes.includes(block.type)) {
|
|
35
|
+
blocks = header ? blocks : [block, ...orderedBlocks];
|
|
36
|
+
activeBlockId = block.type;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const newBlockIndex = getNewBlockIndex(state.activeBlockId, orderedBlocks.length);
|
|
40
|
+
blocks = withHeader(addBlock(orderedBlocks, block, newBlockIndex));
|
|
41
|
+
activeBlockId = newBlockIndex;
|
|
42
|
+
}
|
|
43
|
+
if (blocks) {
|
|
44
|
+
return getNewState(blocks, activeBlockId);
|
|
45
|
+
}
|
|
46
|
+
return state;
|
|
31
47
|
}
|
|
32
48
|
case ORDER_BLOCK: {
|
|
33
49
|
const { oldIndex, newIndex } = action.payload;
|
|
34
|
-
return getNewState(changeBlocksOrder(
|
|
50
|
+
return getNewState(withHeader(changeBlocksOrder(orderedBlocks, oldIndex, newIndex)), newIndex);
|
|
35
51
|
}
|
|
36
|
-
case UPDATE_VIEW_MODE:
|
|
37
|
-
return Object.assign(Object.assign({}, state), { viewMode: action.payload });
|
|
38
52
|
default:
|
|
39
53
|
return state;
|
|
40
54
|
}
|
|
@@ -24,4 +24,3 @@ export const addBlock = (array, block, index) => {
|
|
|
24
24
|
export const addEditorProps = (content) => {
|
|
25
25
|
return Object.assign(Object.assign({}, content), { animated: false });
|
|
26
26
|
};
|
|
27
|
-
export const getErrorBoundaryState = (prevState) => prevState === Number.MAX_SAFE_INTEGER ? 0 : prevState + 1;
|
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PageConstructorProps } from '../../containers/PageConstructor';
|
|
3
|
-
import {
|
|
4
|
-
import { SchemaCustomConfig } from '../../schema';
|
|
5
|
-
import { EditBlockActions } from '../components/EditBlock/EditBlock';
|
|
3
|
+
import { BlockDecoratorProps, PageData } from '../../models';
|
|
6
4
|
export type EditorBlockId = number | string;
|
|
7
5
|
export interface EditorProps extends Required<Pick<PageConstructorProps, 'content'>>, Partial<Omit<PageConstructorProps, 'content'>> {
|
|
8
6
|
children: (props: Partial<PageConstructorProps>) => React.ReactNode;
|
|
9
|
-
onChange?: (data:
|
|
10
|
-
customSchema?: SchemaCustomConfig;
|
|
7
|
+
onChange?: (data: PageData) => void;
|
|
11
8
|
}
|
|
12
9
|
export interface EditBlockEditorProps {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
export declare enum ViewModeItem {
|
|
21
|
-
Edititng = "editing",
|
|
22
|
-
View = "view"
|
|
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;
|
|
23
16
|
}
|
|
17
|
+
export type EditBlockProps = EditBlockEditorProps & BlockDecoratorProps;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockDecorator, CustomConfig } from '../../models';
|
|
2
2
|
export declare const formatBlockName: (name: string) => string;
|
|
3
|
-
export declare const addCustomDecorator: (
|
|
3
|
+
export declare const addCustomDecorator: (decorator: BlockDecorator, custom?: CustomConfig) => {
|
|
4
4
|
decorators: {
|
|
5
|
-
block: ((props:
|
|
5
|
+
block: ((props: import("../../models").BlockDecoratorProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>)[];
|
|
6
6
|
};
|
|
7
7
|
blocks?: import("../../models").CustomItems | undefined;
|
|
8
8
|
subBlocks?: import("../../models").CustomItems | undefined;
|
|
9
9
|
headers?: import("../../models").CustomItems | undefined;
|
|
10
10
|
loadable?: import("../../models").LoadableConfig | undefined;
|
|
11
11
|
};
|
|
12
|
-
export declare const getBlockId: ({ index, type }: BlockDecorationProps) => string;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
export const formatBlockName = (name) => _.capitalize(name).replace(/(block|-)/g, ' ');
|
|
3
|
-
export const addCustomDecorator = (
|
|
4
|
-
const
|
|
5
|
-
return Object.assign(Object.assign({}, custom), { decorators: Object.assign(Object.assign({},
|
|
3
|
+
export const addCustomDecorator = (decorator, custom = {}) => {
|
|
4
|
+
const decorators = custom.decorators || {};
|
|
5
|
+
return Object.assign(Object.assign({}, custom), { decorators: Object.assign(Object.assign({}, decorators), { block: [...(decorators.block || []), decorator] }) });
|
|
6
6
|
};
|
|
7
|
-
export const getBlockId = ({ index, type }) => `${type}${index === undefined ? '' : `-${index}`}`;
|
|
@@ -7,4 +7,4 @@ export interface GridColumnProps extends GridColumnClassParams, Refable<HTMLDivE
|
|
|
7
7
|
dataQa?: string;
|
|
8
8
|
children?: React.ReactNode;
|
|
9
9
|
}
|
|
10
|
-
export declare const Col: React.ForwardRefExoticComponent<Pick<WithChildren<GridColumnProps>, "style" | "children" | "className" | "
|
|
10
|
+
export declare const Col: React.ForwardRefExoticComponent<Pick<WithChildren<GridColumnProps>, "style" | "children" | "className" | "reset" | "visible" | "sizes" | "offsets" | "orders" | "hidden" | "alignSelf" | "justifyContent" | "dataQa"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -30,7 +30,6 @@ export interface Childable {
|
|
|
30
30
|
children?: SubBlock[];
|
|
31
31
|
}
|
|
32
32
|
export interface BlockBaseProps {
|
|
33
|
-
type: BlockType;
|
|
34
33
|
index?: number;
|
|
35
34
|
anchor?: AnchorProps;
|
|
36
35
|
visible?: GridColumnSize;
|
|
@@ -245,18 +244,14 @@ export interface IconsBlockProps {
|
|
|
245
244
|
src: string;
|
|
246
245
|
}[];
|
|
247
246
|
}
|
|
248
|
-
interface
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* @deprecated Use params on top level instead
|
|
258
|
-
*/
|
|
259
|
-
properties?: ContentLayoutBlockParams;
|
|
247
|
+
export interface ContentLayoutBlockProps {
|
|
248
|
+
properties?: {
|
|
249
|
+
size?: ContentSize;
|
|
250
|
+
background?: BackgroundImageProps;
|
|
251
|
+
centered?: boolean;
|
|
252
|
+
theme?: ContentTheme;
|
|
253
|
+
textWidth?: ContentTextSize;
|
|
254
|
+
};
|
|
260
255
|
textContent: ContentBlockProps;
|
|
261
256
|
fileContent?: FileLinkProps[];
|
|
262
257
|
}
|
|
@@ -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
|
}
|
|
@@ -41,7 +41,7 @@ export interface CustomConfig {
|
|
|
41
41
|
headers?: CustomItems;
|
|
42
42
|
loadable?: LoadableConfig;
|
|
43
43
|
decorators?: {
|
|
44
|
-
block?: ((props:
|
|
44
|
+
block?: ((props: BlockDecoratorProps) => React.ReactElement)[];
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
export {};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export interface BlockDecorationProps extends PropsWithChildren {
|
|
3
|
+
id: string | number;
|
|
4
|
+
}
|
|
5
|
+
export interface BlockDecoratorProps extends PropsWithChildren {
|
|
6
|
+
id: string | number;
|
|
7
|
+
isHeader?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type BlockDecorator = (props: BlockDecoratorProps) => React.ReactElement;
|
|
@@ -9,8 +9,6 @@ unpredictable css rules order in build */
|
|
|
9
9
|
align-items: center;
|
|
10
10
|
height: var(--header-height);
|
|
11
11
|
background-color: var(--yc-color-base-background);
|
|
12
|
-
}
|
|
13
|
-
.pc-header_with-border {
|
|
14
12
|
box-shadow: inset 0 -1px 0 var(--yc-color-line-generic);
|
|
15
13
|
}
|
|
16
14
|
.pc-header__wrapper {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import React, { useCallback,
|
|
2
|
-
import _ from 'lodash';
|
|
1
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
3
2
|
import Control from '../../../components/Control/Control';
|
|
4
3
|
import OutsideClick from '../../../components/OutsideClick/OutsideClick';
|
|
5
4
|
import { Col, Grid, Row } from '../../../grid';
|
|
@@ -28,10 +27,9 @@ const iconSizeKey = 'iconSize';
|
|
|
28
27
|
const isButtonItem = (item) => item.type === NavigationItemType.Button;
|
|
29
28
|
const isDropdownItem = (item) => item.type === NavigationItemType.Dropdown;
|
|
30
29
|
export const Header = ({ data, logo }) => {
|
|
31
|
-
const { leftItems, rightItems, iconSize = 20
|
|
30
|
+
const { leftItems, rightItems, iconSize = 20 } = data;
|
|
32
31
|
const [isSidebarOpened, setIsSidebarOpened] = useState(false);
|
|
33
|
-
const [activeItemId,
|
|
34
|
-
const [showBorder, setShowBorder] = useState(withBorder);
|
|
32
|
+
const [activeItemId, setactiveItemId] = useState(undefined);
|
|
35
33
|
const getNavigationItemWithIconSize = useCallback((item) => {
|
|
36
34
|
const newItem = Object.assign({}, item);
|
|
37
35
|
if ('items' in newItem && isDropdownItem(newItem)) {
|
|
@@ -45,7 +43,7 @@ export const Header = ({ data, logo }) => {
|
|
|
45
43
|
const leftItemsWithIconSize = useMemo(() => leftItems.map(getNavigationItemWithIconSize), [getNavigationItemWithIconSize, leftItems]);
|
|
46
44
|
const rightItemsWithIconSize = useMemo(() => rightItems === null || rightItems === void 0 ? void 0 : rightItems.map(getNavigationItemWithIconSize), [getNavigationItemWithIconSize, rightItems]);
|
|
47
45
|
const onActiveItemChange = useCallback((id) => {
|
|
48
|
-
|
|
46
|
+
setactiveItemId(id);
|
|
49
47
|
}, []);
|
|
50
48
|
const hidePopup = useCallback(() => {
|
|
51
49
|
onActiveItemChange();
|
|
@@ -56,16 +54,7 @@ export const Header = ({ data, logo }) => {
|
|
|
56
54
|
const hideSidebar = useCallback(() => {
|
|
57
55
|
setIsSidebarOpened(false);
|
|
58
56
|
}, []);
|
|
59
|
-
|
|
60
|
-
const showBorderOnScroll = () => {
|
|
61
|
-
if (!showBorder) {
|
|
62
|
-
setShowBorder(window.scrollY > 0);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
window.addEventListener('scroll', _.debounce(showBorderOnScroll, 20), { passive: true });
|
|
66
|
-
return () => window.removeEventListener('scroll', _.debounce(showBorderOnScroll, 20));
|
|
67
|
-
});
|
|
68
|
-
return (React.createElement(Grid, { className: b({ 'with-border': showBorder }) },
|
|
57
|
+
return (React.createElement(Grid, { className: b() },
|
|
69
58
|
React.createElement(Row, null,
|
|
70
59
|
React.createElement(Col, null,
|
|
71
60
|
React.createElement("header", { className: b('wrapper') },
|