@gravity-ui/page-constructor 3.2.0 → 3.3.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 +12 -0
- package/README.md +2 -0
- package/build/cjs/blocks/Banner/schema.d.ts +63 -21
- package/build/cjs/blocks/CardLayout/schema.d.ts +10 -4
- package/build/cjs/blocks/Companies/schema.d.ts +5 -2
- package/build/cjs/blocks/ContentLayout/ContentLayout.js +3 -2
- package/build/cjs/blocks/ContentLayout/schema.d.ts +107 -61
- package/build/cjs/blocks/ContentLayout/schema.js +23 -18
- package/build/cjs/blocks/ExtendedFeatures/schema.d.ts +31 -4
- package/build/cjs/blocks/ExtendedFeatures/schema.js +2 -3
- package/build/cjs/blocks/FilterBlock/schema.d.ts +13 -5
- package/build/cjs/blocks/FilterBlock/schema.js +13 -2
- package/build/cjs/blocks/Header/schema.d.ts +92 -36
- package/build/cjs/blocks/Header/schema.js +1 -0
- package/build/cjs/blocks/HeaderSlider/schema.d.ts +48 -53
- package/build/cjs/blocks/HeaderSlider/schema.js +3 -1
- package/build/cjs/blocks/Icons/schema.d.ts +3 -1
- package/build/cjs/blocks/Icons/schema.js +2 -1
- package/build/cjs/blocks/Info/schema.d.ts +19 -8
- package/build/cjs/blocks/Map/schema.d.ts +17 -6
- package/build/cjs/blocks/Media/schema.d.ts +204 -152
- package/build/cjs/blocks/Media/schema.js +1 -1
- package/build/cjs/blocks/PromoFeaturesBlock/schema.d.ts +22 -8
- package/build/cjs/blocks/PromoFeaturesBlock/schema.js +1 -0
- package/build/cjs/blocks/Questions/schema.d.ts +7 -3
- package/build/cjs/blocks/Slider/schema.d.ts +13 -18
- package/build/cjs/blocks/Slider/schema.js +4 -5
- package/build/cjs/blocks/Table/schema.d.ts +5 -2
- package/build/cjs/blocks/Table/schema.js +12 -2
- package/build/cjs/blocks/Tabs/schema.d.ts +43 -16
- 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 +1 -0
- package/build/cjs/components/Image/schema.js +3 -2
- 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 +5 -6
- package/build/cjs/editor/{Components → components}/AddBlock/AddBlock.css +0 -7
- 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/BlockForm/BlockForm.d.ts +12 -0
- package/build/cjs/editor/components/BlockForm/BlockForm.js +26 -0
- package/build/cjs/editor/components/EditBlock/EditBlock.d.ts +13 -0
- package/build/cjs/editor/components/EditBlock/EditBlock.js +44 -0
- package/build/cjs/editor/components/ErrorBoundary/ErrorBoundary.css +27 -0
- package/build/cjs/editor/components/ErrorBoundary/ErrorBoundary.d.ts +13 -0
- package/build/cjs/editor/components/ErrorBoundary/ErrorBoundary.js +35 -0
- package/build/cjs/editor/components/ErrorBoundary/i18n/en.json +4 -0
- package/build/cjs/editor/components/ErrorBoundary/i18n/index.d.ts +2 -0
- package/build/cjs/editor/components/ErrorBoundary/i18n/index.js +8 -0
- package/build/cjs/editor/components/ErrorBoundary/i18n/ru.json +4 -0
- package/build/cjs/editor/components/PagePropsForm/PagePropsForm.d.ts +10 -0
- package/build/cjs/editor/components/PagePropsForm/PagePropsForm.js +17 -0
- package/build/cjs/editor/containers/Editor/Editor.css +28 -0
- package/build/cjs/editor/containers/Editor/Editor.d.ts +2 -0
- package/build/cjs/editor/containers/Editor/Editor.js +37 -0
- package/build/cjs/editor/containers/Form/Form.css +94 -0
- package/build/cjs/editor/containers/Form/Form.d.ts +11 -0
- package/build/cjs/editor/containers/Form/Form.js +47 -0
- package/build/cjs/editor/containers/Form/dynamic-form-custom.css +0 -0
- package/build/cjs/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.css +27 -0
- package/build/cjs/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.d.ts +19 -0
- package/build/cjs/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.js +72 -0
- package/build/cjs/editor/dynamic-forms-custom/config.d.ts +2 -0
- package/build/cjs/editor/dynamic-forms-custom/config.js +13 -0
- package/build/cjs/editor/dynamic-forms-custom/hooks/useOneOf.d.ts +12 -0
- package/build/cjs/editor/dynamic-forms-custom/hooks/useOneOf.js +75 -0
- package/build/cjs/editor/dynamic-forms-custom/parser/detect.d.ts +9 -0
- package/build/cjs/editor/dynamic-forms-custom/parser/detect.js +36 -0
- package/build/cjs/editor/dynamic-forms-custom/parser/index.d.ts +28 -0
- package/build/cjs/editor/dynamic-forms-custom/parser/index.js +188 -0
- package/build/cjs/editor/dynamic-forms-custom/parser/types.d.ts +29 -0
- package/build/cjs/editor/dynamic-forms-custom/parser/types.js +2 -0
- package/build/cjs/editor/dynamic-forms-custom/parser/views.d.ts +37 -0
- package/build/cjs/editor/dynamic-forms-custom/parser/views.js +46 -0
- package/build/cjs/editor/hooks/useFormSpec.d.ts +2 -0
- package/build/cjs/editor/hooks/useFormSpec.js +13 -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 +8 -11
- package/build/cjs/editor/store/index.js +61 -15
- package/build/cjs/editor/store/reducer.d.ts +17 -9
- package/build/cjs/editor/store/reducer.js +14 -31
- package/build/cjs/editor/store/utils.d.ts +1 -0
- package/build/cjs/editor/store/utils.js +3 -1
- package/build/cjs/editor/types/index.d.ts +11 -9
- package/build/cjs/editor/utils/index.d.ts +4 -3
- package/build/cjs/editor/utils/index.js +6 -4
- package/build/cjs/grid/Col/Col.d.ts +1 -1
- package/build/cjs/models/constructor-items/blocks.d.ts +13 -8
- package/build/cjs/models/constructor.d.ts +2 -2
- package/build/cjs/models/customization.d.ts +3 -8
- package/build/cjs/navigation/schema.d.ts +1 -0
- package/build/cjs/schema/constants.d.ts +908 -0
- package/build/cjs/schema/constants.js +42 -0
- package/build/cjs/schema/index.d.ts +9 -228
- package/build/cjs/schema/index.js +8 -46
- package/build/cjs/schema/validators/common.d.ts +71 -27
- package/build/cjs/schema/validators/common.js +50 -17
- package/build/cjs/sub-blocks/BackgroundCard/schema.d.ts +12 -5
- package/build/cjs/sub-blocks/BasicCard/schema.d.ts +8 -3
- package/build/cjs/sub-blocks/Content/schema.d.ts +14 -6
- package/build/cjs/sub-blocks/Content/schema.js +9 -1
- package/build/cjs/sub-blocks/LayoutItem/schema.d.ts +23 -9
- package/build/cjs/sub-blocks/MediaCard/schema.d.ts +16 -6
- package/build/cjs/sub-blocks/PriceDetailed/schema.d.ts +1 -0
- package/build/cjs/sub-blocks/PriceDetailed/schema.js +5 -1
- package/build/cjs/sub-blocks/Quote/schema.d.ts +6 -2
- package/build/esm/blocks/Banner/schema.d.ts +63 -21
- package/build/esm/blocks/CardLayout/schema.d.ts +10 -4
- package/build/esm/blocks/Companies/schema.d.ts +5 -2
- package/build/esm/blocks/ContentLayout/ContentLayout.js +3 -2
- package/build/esm/blocks/ContentLayout/schema.d.ts +107 -61
- package/build/esm/blocks/ContentLayout/schema.js +23 -18
- package/build/esm/blocks/ExtendedFeatures/schema.d.ts +31 -4
- package/build/esm/blocks/ExtendedFeatures/schema.js +3 -4
- package/build/esm/blocks/FilterBlock/schema.d.ts +13 -5
- package/build/esm/blocks/FilterBlock/schema.js +13 -2
- package/build/esm/blocks/Header/schema.d.ts +92 -36
- package/build/esm/blocks/Header/schema.js +1 -0
- package/build/esm/blocks/HeaderSlider/schema.d.ts +48 -53
- package/build/esm/blocks/HeaderSlider/schema.js +2 -1
- package/build/esm/blocks/Icons/schema.d.ts +3 -1
- package/build/esm/blocks/Icons/schema.js +2 -1
- package/build/esm/blocks/Info/schema.d.ts +19 -8
- package/build/esm/blocks/Map/schema.d.ts +17 -6
- package/build/esm/blocks/Media/schema.d.ts +204 -152
- package/build/esm/blocks/Media/schema.js +2 -2
- package/build/esm/blocks/PromoFeaturesBlock/schema.d.ts +22 -8
- package/build/esm/blocks/PromoFeaturesBlock/schema.js +1 -0
- package/build/esm/blocks/Questions/schema.d.ts +7 -3
- package/build/esm/blocks/Slider/schema.d.ts +13 -18
- package/build/esm/blocks/Slider/schema.js +4 -5
- package/build/esm/blocks/Table/schema.d.ts +5 -2
- package/build/esm/blocks/Table/schema.js +12 -2
- package/build/esm/blocks/Tabs/schema.d.ts +43 -16
- 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 +1 -0
- package/build/esm/components/Image/schema.js +3 -2
- 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 +0 -7
- 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/BlockForm/BlockForm.d.ts +12 -0
- package/build/esm/editor/components/BlockForm/BlockForm.js +23 -0
- package/build/esm/editor/components/EditBlock/EditBlock.d.ts +14 -0
- package/build/esm/editor/components/EditBlock/EditBlock.js +41 -0
- package/build/esm/editor/components/ErrorBoundary/ErrorBoundary.css +27 -0
- package/build/esm/editor/components/ErrorBoundary/ErrorBoundary.d.ts +14 -0
- package/build/esm/editor/components/ErrorBoundary/ErrorBoundary.js +31 -0
- package/build/esm/editor/components/ErrorBoundary/i18n/en.json +4 -0
- package/build/esm/editor/components/ErrorBoundary/i18n/index.d.ts +2 -0
- package/build/esm/editor/components/ErrorBoundary/i18n/index.js +5 -0
- package/build/esm/editor/components/ErrorBoundary/i18n/ru.json +4 -0
- package/build/esm/editor/components/PagePropsForm/PagePropsForm.d.ts +10 -0
- package/build/esm/editor/components/PagePropsForm/PagePropsForm.js +13 -0
- package/build/esm/editor/containers/Editor/Editor.css +28 -0
- package/build/esm/editor/containers/Editor/Editor.d.ts +3 -0
- package/build/esm/editor/containers/Editor/Editor.js +34 -0
- package/build/esm/editor/containers/Form/Form.css +94 -0
- package/build/esm/editor/containers/Form/Form.d.ts +12 -0
- package/build/esm/editor/containers/Form/Form.js +45 -0
- package/build/esm/editor/containers/Form/dynamic-form-custom.css +0 -0
- package/build/esm/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.css +27 -0
- package/build/esm/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.d.ts +20 -0
- package/build/esm/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.js +68 -0
- package/build/esm/editor/dynamic-forms-custom/config.d.ts +2 -0
- package/build/esm/editor/dynamic-forms-custom/config.js +9 -0
- package/build/esm/editor/dynamic-forms-custom/hooks/useOneOf.d.ts +12 -0
- package/build/esm/editor/dynamic-forms-custom/hooks/useOneOf.js +69 -0
- package/build/esm/editor/dynamic-forms-custom/parser/detect.d.ts +9 -0
- package/build/esm/editor/dynamic-forms-custom/parser/detect.js +32 -0
- package/build/esm/editor/dynamic-forms-custom/parser/index.d.ts +28 -0
- package/build/esm/editor/dynamic-forms-custom/parser/index.js +186 -0
- package/build/esm/editor/dynamic-forms-custom/parser/types.d.ts +29 -0
- package/build/esm/editor/dynamic-forms-custom/parser/types.js +1 -0
- package/build/esm/editor/dynamic-forms-custom/parser/views.d.ts +37 -0
- package/build/esm/editor/dynamic-forms-custom/parser/views.js +39 -0
- package/build/esm/editor/hooks/useFormSpec.d.ts +2 -0
- package/build/esm/editor/hooks/useFormSpec.js +9 -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 +8 -11
- package/build/esm/editor/store/index.js +63 -17
- package/build/esm/editor/store/reducer.d.ts +17 -9
- package/build/esm/editor/store/reducer.js +12 -29
- package/build/esm/editor/store/utils.d.ts +1 -0
- package/build/esm/editor/store/utils.js +1 -0
- package/build/esm/editor/types/index.d.ts +11 -9
- package/build/esm/editor/utils/index.d.ts +4 -3
- package/build/esm/editor/utils/index.js +4 -3
- package/build/esm/grid/Col/Col.d.ts +1 -1
- package/build/esm/models/constructor-items/blocks.d.ts +13 -8
- package/build/esm/models/constructor.d.ts +2 -2
- package/build/esm/models/customization.d.ts +3 -8
- package/build/esm/navigation/schema.d.ts +1 -0
- package/build/esm/schema/constants.d.ts +908 -0
- package/build/esm/schema/constants.js +39 -0
- package/build/esm/schema/index.d.ts +9 -228
- package/build/esm/schema/index.js +4 -42
- package/build/esm/schema/validators/common.d.ts +71 -27
- package/build/esm/schema/validators/common.js +49 -16
- package/build/esm/sub-blocks/BackgroundCard/schema.d.ts +12 -5
- package/build/esm/sub-blocks/BasicCard/schema.d.ts +8 -3
- package/build/esm/sub-blocks/Content/schema.d.ts +14 -6
- package/build/esm/sub-blocks/Content/schema.js +9 -1
- package/build/esm/sub-blocks/LayoutItem/schema.d.ts +23 -9
- package/build/esm/sub-blocks/MediaCard/schema.d.ts +16 -6
- package/build/esm/sub-blocks/PriceDetailed/schema.d.ts +1 -0
- package/build/esm/sub-blocks/PriceDetailed/schema.js +5 -1
- package/build/esm/sub-blocks/Quote/schema.d.ts +6 -2
- package/package.json +5 -1
- package/server/models/constructor-items/blocks.d.ts +13 -8
- package/server/models/constructor.d.ts +2 -2
- package/server/models/customization.d.ts +3 -8
- package/build/cjs/editor/Components/AddBlock/AddBlock.d.ts +0 -7
- package/build/cjs/editor/Components/EditBlock/EditBlock.d.ts +0 -4
- package/build/cjs/editor/Components/EditBlock/EditBlock.js +0 -32
- package/build/cjs/editor/Containers/Editor.d.ts +0 -2
- package/build/cjs/editor/Containers/Editor.js +0 -24
- package/build/esm/editor/Components/AddBlock/AddBlock.d.ts +0 -8
- package/build/esm/editor/Components/EditBlock/EditBlock.d.ts +0 -5
- package/build/esm/editor/Components/EditBlock/EditBlock.js +0 -30
- package/build/esm/editor/Containers/Editor.d.ts +0 -2
- package/build/esm/editor/Containers/Editor.js +0 -20
- /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,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SpecTypes, } from '@gravity-ui/dynamic-forms';
|
|
3
|
+
import { RadioButton, Select } from '@gravity-ui/uikit';
|
|
4
|
+
import _ from 'lodash';
|
|
5
|
+
const MAX_TAB_TITLE_LENGTH = 20;
|
|
6
|
+
export const getSpecTypeDefaultValue = (type) => {
|
|
7
|
+
switch (type) {
|
|
8
|
+
case SpecTypes.Array:
|
|
9
|
+
return [];
|
|
10
|
+
case SpecTypes.Boolean:
|
|
11
|
+
case SpecTypes.Number:
|
|
12
|
+
case SpecTypes.String:
|
|
13
|
+
return undefined;
|
|
14
|
+
default:
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export const useOneOf = ({ props, onTogglerChange }) => {
|
|
19
|
+
const { name, input, spec, Layout } = props;
|
|
20
|
+
const { order, disabled, oneOfParams } = spec.viewSpec;
|
|
21
|
+
const specProperties = React.useMemo(() => (_.isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
|
|
22
|
+
const [oneOfValue, setOneOfValue] = React.useState(() => {
|
|
23
|
+
let valueKeys;
|
|
24
|
+
if (_.isObjectLike(input.value)) {
|
|
25
|
+
const keys = Object.keys(input.value);
|
|
26
|
+
if (keys.length) {
|
|
27
|
+
valueKeys = keys;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return (valueKeys || order || Object.keys(specProperties))[0];
|
|
31
|
+
});
|
|
32
|
+
const onOneOfChange = React.useCallback(([newValue]) => {
|
|
33
|
+
var _a;
|
|
34
|
+
if (newValue !== oneOfValue) {
|
|
35
|
+
const specType = ((_a = specProperties[newValue]) === null || _a === void 0 ? void 0 : _a.type) || SpecTypes.Object;
|
|
36
|
+
input.onChange(getSpecTypeDefaultValue(specType));
|
|
37
|
+
setOneOfValue(newValue);
|
|
38
|
+
onTogglerChange === null || onTogglerChange === void 0 ? void 0 : onTogglerChange(newValue);
|
|
39
|
+
}
|
|
40
|
+
}, [setOneOfValue, input, oneOfValue, specProperties, onTogglerChange]);
|
|
41
|
+
const options = React.useMemo(() => (order || Object.keys(specProperties)).map((value) => {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const title = ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[value]) ||
|
|
44
|
+
((_b = specProperties[value]) === null || _b === void 0 ? void 0 : _b.viewSpec.layoutTitle) ||
|
|
45
|
+
value ||
|
|
46
|
+
'';
|
|
47
|
+
return {
|
|
48
|
+
value,
|
|
49
|
+
title,
|
|
50
|
+
content: title,
|
|
51
|
+
};
|
|
52
|
+
}), [spec.description, order, specProperties]);
|
|
53
|
+
const togglerInput = React.useMemo(() => {
|
|
54
|
+
if ((oneOfParams === null || oneOfParams === void 0 ? void 0 : oneOfParams.toggler) !== 'radio' &&
|
|
55
|
+
((oneOfParams === null || oneOfParams === void 0 ? void 0 : oneOfParams.toggler) === 'select' ||
|
|
56
|
+
options.length > 3 ||
|
|
57
|
+
_.some(options, ({ title }) => title.length > MAX_TAB_TITLE_LENGTH))) {
|
|
58
|
+
return (React.createElement(Select, { width: "max", value: [oneOfValue], onUpdate: onOneOfChange, options: options, disabled: disabled, filterable: options.length > 7, qa: name }));
|
|
59
|
+
}
|
|
60
|
+
return (React.createElement(RadioButton, { value: oneOfValue, onChange: (event) => onOneOfChange([event.target.value]), disabled: disabled, qa: name }, options.map(({ value, title }) => (React.createElement(RadioButton.Option, { key: value, value: value }, title)))));
|
|
61
|
+
}, [options, oneOfValue, onOneOfChange, name, oneOfParams === null || oneOfParams === void 0 ? void 0 : oneOfParams.toggler, disabled]);
|
|
62
|
+
const toggler = React.useMemo(() => {
|
|
63
|
+
if (Layout) {
|
|
64
|
+
return React.createElement(Layout, Object.assign({}, props), togglerInput);
|
|
65
|
+
}
|
|
66
|
+
return togglerInput;
|
|
67
|
+
}, [Layout, togglerInput, props]);
|
|
68
|
+
return { oneOfValue, specProperties, toggler, togglerInput };
|
|
69
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SpecTypes } from '@gravity-ui/dynamic-forms';
|
|
2
|
+
export var ParserType;
|
|
3
|
+
(function (ParserType) {
|
|
4
|
+
ParserType["Object"] = "object";
|
|
5
|
+
ParserType["Array"] = "array";
|
|
6
|
+
ParserType["Children"] = "children";
|
|
7
|
+
ParserType["OneOf"] = "oneOf";
|
|
8
|
+
ParserType["Primitive"] = "primitive";
|
|
9
|
+
})(ParserType || (ParserType = {}));
|
|
10
|
+
const isOneOf = (data) => 'oneOf' in data;
|
|
11
|
+
const isObject = (data) => 'properties' in data;
|
|
12
|
+
const isArray = (data) => 'type' in data && data.type === SpecTypes.Array;
|
|
13
|
+
const isChildren = (data) => 'type' in data &&
|
|
14
|
+
data.type === SpecTypes.Array &&
|
|
15
|
+
'items' in data &&
|
|
16
|
+
typeof data.items !== 'undefined' &&
|
|
17
|
+
'$ref' in data.items;
|
|
18
|
+
//detector applying order matters!
|
|
19
|
+
const ParserTypeDetectors = [
|
|
20
|
+
{ type: ParserType.OneOf, detector: isOneOf },
|
|
21
|
+
{ type: ParserType.Children, detector: isChildren },
|
|
22
|
+
{ type: ParserType.Object, detector: isObject },
|
|
23
|
+
{ type: ParserType.Array, detector: isArray },
|
|
24
|
+
];
|
|
25
|
+
export const detectParserType = (data) => {
|
|
26
|
+
for (const { type, detector } of ParserTypeDetectors) {
|
|
27
|
+
if (detector(data)) {
|
|
28
|
+
return type;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return ParserType.Primitive;
|
|
32
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Schema } from '../../../schema';
|
|
2
|
+
import { FormSpecs } from './types';
|
|
3
|
+
declare class FormSpecParser {
|
|
4
|
+
private schema;
|
|
5
|
+
private definitions;
|
|
6
|
+
/**
|
|
7
|
+
* Transforms page-constructor json schema into dynamic-forms specs for each block
|
|
8
|
+
*
|
|
9
|
+
* @param schema {Schema} - page-constructor json schema
|
|
10
|
+
* @returns {FormSpecs} - object containig dynamic-forms specs for each constructor block
|
|
11
|
+
*/
|
|
12
|
+
parse(schema: Schema): FormSpecs;
|
|
13
|
+
private getChildrenSpec;
|
|
14
|
+
private getRequiredProperties;
|
|
15
|
+
private childrenParser;
|
|
16
|
+
private oneOfParser;
|
|
17
|
+
private arrayParser;
|
|
18
|
+
private objectParser;
|
|
19
|
+
private primitiveParser;
|
|
20
|
+
private schemaParserMap;
|
|
21
|
+
private parseSchemaProperty;
|
|
22
|
+
private getBlocksSpec;
|
|
23
|
+
private getPageSpec;
|
|
24
|
+
private getFormSpec;
|
|
25
|
+
private init;
|
|
26
|
+
}
|
|
27
|
+
declare const _default: FormSpecParser;
|
|
28
|
+
export default _default;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
/* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign */
|
|
4
|
+
import { SpecTypes } from '@gravity-ui/dynamic-forms';
|
|
5
|
+
import { BlockType } from '../../../models';
|
|
6
|
+
import { ParserType, detectParserType } from './detect';
|
|
7
|
+
import { getArrayViewSpec, getObjectViewSpec, getOneOfViewSpec, getPrimitiveViewSpec } from './views';
|
|
8
|
+
class FormSpecParser {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.schema = {};
|
|
11
|
+
this.definitions = {};
|
|
12
|
+
this.getChildrenSpec = (data) => {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
const childrenType = (_c = (_b = (_a = data.items) === null || _a === void 0 ? void 0 : _a.$ref) === null || _b === void 0 ? void 0 : _b.split('/')) === null || _c === void 0 ? void 0 : _c.pop();
|
|
15
|
+
return this.definitions[childrenType];
|
|
16
|
+
};
|
|
17
|
+
this.getRequiredProperties = (data) => Array.isArray(data.required) ? data.required : [];
|
|
18
|
+
this.childrenParser = ({ data, name, required }) => {
|
|
19
|
+
const childSpec = this.getChildrenSpec(data);
|
|
20
|
+
const properties = childSpec &&
|
|
21
|
+
Object.entries(childSpec).reduce((parsedChildSpecProperties, [childName, childSchema]) => {
|
|
22
|
+
const childRequiredProperties = this.getRequiredProperties(childSchema);
|
|
23
|
+
const childProperies = childSchema.properties &&
|
|
24
|
+
Object.entries(childSchema.properties).reduce((parsedChildProperties, [childPropertyName, childPropertyData]) => {
|
|
25
|
+
parsedChildProperties[childPropertyName] = this.parseSchemaProperty({
|
|
26
|
+
data: childPropertyData,
|
|
27
|
+
name: childPropertyName,
|
|
28
|
+
required: childRequiredProperties.includes(childPropertyName),
|
|
29
|
+
});
|
|
30
|
+
return parsedChildProperties;
|
|
31
|
+
}, {});
|
|
32
|
+
const childJsonSchema = Object.assign(Object.assign({}, childSchema), { properties: Object.assign(Object.assign({}, childSchema.properties), { type: {
|
|
33
|
+
type: SpecTypes.String,
|
|
34
|
+
enum: [childName],
|
|
35
|
+
} }) });
|
|
36
|
+
parsedChildSpecProperties[childName] = {
|
|
37
|
+
type: SpecTypes.Array,
|
|
38
|
+
items: Object.assign(Object.assign({}, childSchema), { type: SpecTypes.Object, properties: Object.assign(Object.assign({}, childProperies), { type: {
|
|
39
|
+
type: SpecTypes.String,
|
|
40
|
+
defaultValue: childName,
|
|
41
|
+
viewSpec: {
|
|
42
|
+
type: 'hidden',
|
|
43
|
+
},
|
|
44
|
+
} }), viewSpec: childProperies &&
|
|
45
|
+
getObjectViewSpec({
|
|
46
|
+
properties: childProperies,
|
|
47
|
+
layoutTitle: childName,
|
|
48
|
+
}), __schema: childJsonSchema }),
|
|
49
|
+
required: false,
|
|
50
|
+
viewSpec: getArrayViewSpec({ layoutTitle: childName }),
|
|
51
|
+
__schema: {
|
|
52
|
+
type: SpecTypes.Array,
|
|
53
|
+
items: childJsonSchema,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
return parsedChildSpecProperties;
|
|
57
|
+
}, {});
|
|
58
|
+
return {
|
|
59
|
+
type: SpecTypes.Object,
|
|
60
|
+
properties,
|
|
61
|
+
viewSpec: {
|
|
62
|
+
type: 'oneof_custom',
|
|
63
|
+
layout: 'row',
|
|
64
|
+
layoutTitle: name,
|
|
65
|
+
oneOfParams: {
|
|
66
|
+
toggler: 'select',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
required,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
this.oneOfParser = ({ data, name, required }) => {
|
|
73
|
+
const requiredProperties = this.getRequiredProperties(data);
|
|
74
|
+
const properties = data.oneOf &&
|
|
75
|
+
data.oneOf.reduce((result, propertyData, index) => {
|
|
76
|
+
const propertyName = (propertyData === null || propertyData === void 0 ? void 0 : propertyData.optionName)
|
|
77
|
+
? propertyData === null || propertyData === void 0 ? void 0 : propertyData.optionName
|
|
78
|
+
: `${name}_${index}`;
|
|
79
|
+
result[propertyName] = this.parseSchemaProperty({
|
|
80
|
+
data: propertyData,
|
|
81
|
+
name: propertyName,
|
|
82
|
+
required: requiredProperties.includes(propertyName),
|
|
83
|
+
});
|
|
84
|
+
return result;
|
|
85
|
+
}, {});
|
|
86
|
+
return {
|
|
87
|
+
type: SpecTypes.Object,
|
|
88
|
+
properties,
|
|
89
|
+
required,
|
|
90
|
+
viewSpec: getOneOfViewSpec({ layoutTitle: name }),
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
this.arrayParser = ({ data, name }) => {
|
|
94
|
+
const items = data.items && this.parseSchemaProperty({ data: data.items, name });
|
|
95
|
+
return Object.assign(Object.assign({}, data), { type: SpecTypes.Array, items, viewSpec: getArrayViewSpec({ layoutTitle: name }) });
|
|
96
|
+
};
|
|
97
|
+
this.objectParser = ({ data, name, required }) => {
|
|
98
|
+
const requiredProperties = this.getRequiredProperties(data);
|
|
99
|
+
const properties = data.properties &&
|
|
100
|
+
Object.entries(data.properties).reduce((result, [propertyName, propertyData]) => {
|
|
101
|
+
result[propertyName] = this.parseSchemaProperty({
|
|
102
|
+
data: propertyData,
|
|
103
|
+
name: propertyName,
|
|
104
|
+
required: requiredProperties.includes(propertyName),
|
|
105
|
+
});
|
|
106
|
+
return result;
|
|
107
|
+
}, {});
|
|
108
|
+
return Object.assign(Object.assign({}, data), { type: SpecTypes.Object, properties, viewSpec: getObjectViewSpec({ properties, layoutTitle: name }), required });
|
|
109
|
+
};
|
|
110
|
+
this.primitiveParser = ({ data, name, required }) => {
|
|
111
|
+
return Object.assign(Object.assign({}, data), { type: data.type, required, defaultValue: data.default, viewSpec: getPrimitiveViewSpec({ layoutTitle: name, data }), validator: 'base' });
|
|
112
|
+
};
|
|
113
|
+
//eslint-disable-next-line @typescript-eslint/member-ordering
|
|
114
|
+
this.schemaParserMap = {
|
|
115
|
+
[ParserType.Object]: this.objectParser,
|
|
116
|
+
[ParserType.Array]: this.arrayParser,
|
|
117
|
+
[ParserType.Primitive]: this.primitiveParser,
|
|
118
|
+
[ParserType.OneOf]: this.oneOfParser,
|
|
119
|
+
[ParserType.Children]: this.childrenParser,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Transforms page-constructor json schema into dynamic-forms specs for each block
|
|
124
|
+
*
|
|
125
|
+
* @param schema {Schema} - page-constructor json schema
|
|
126
|
+
* @returns {FormSpecs} - object containig dynamic-forms specs for each constructor block
|
|
127
|
+
*/
|
|
128
|
+
parse(schema) {
|
|
129
|
+
this.init(schema);
|
|
130
|
+
return this.getFormSpec();
|
|
131
|
+
}
|
|
132
|
+
parseSchemaProperty({ data, name, required }) {
|
|
133
|
+
const parserType = detectParserType(data);
|
|
134
|
+
const parser = this.schemaParserMap[parserType];
|
|
135
|
+
return Object.assign(Object.assign({}, parser({ data, name, required })), {
|
|
136
|
+
//save json schema from constructor to compare with incoming intial data inside oneOf form fields
|
|
137
|
+
__schema: data });
|
|
138
|
+
}
|
|
139
|
+
getBlocksSpec() {
|
|
140
|
+
const blocks = this.definitions.children;
|
|
141
|
+
return Object.values(BlockType).reduce((result, blockName) => {
|
|
142
|
+
result[blockName] = this.parseSchemaProperty({
|
|
143
|
+
name: blockName,
|
|
144
|
+
data: Object.assign({}, blocks[blockName]),
|
|
145
|
+
required: true,
|
|
146
|
+
});
|
|
147
|
+
return result;
|
|
148
|
+
}, {});
|
|
149
|
+
}
|
|
150
|
+
getPageSpec() {
|
|
151
|
+
var _a;
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
153
|
+
const _b = ((_a = this.schema) === null || _a === void 0 ? void 0 : _a.properties) || {}, { blocks } = _b, pageSchema = __rest(_b, ["blocks"]);
|
|
154
|
+
const requiredProperties = this.getRequiredProperties(this.schema);
|
|
155
|
+
const properties = Object.entries(pageSchema).reduce((result, [propertyName, propertyData]) => {
|
|
156
|
+
result[propertyName] = this.parseSchemaProperty({
|
|
157
|
+
name: propertyName,
|
|
158
|
+
data: propertyData,
|
|
159
|
+
required: requiredProperties.includes(propertyName),
|
|
160
|
+
});
|
|
161
|
+
return result;
|
|
162
|
+
}, {});
|
|
163
|
+
return {
|
|
164
|
+
type: SpecTypes.Object,
|
|
165
|
+
properties,
|
|
166
|
+
viewSpec: getObjectViewSpec({ properties, layout: 'section' }),
|
|
167
|
+
required: true,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
getFormSpec() {
|
|
171
|
+
return {
|
|
172
|
+
blocks: this.getBlocksSpec(),
|
|
173
|
+
page: this.getPageSpec(),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
init(schema) {
|
|
177
|
+
this.schema = schema;
|
|
178
|
+
if (schema.definitions) {
|
|
179
|
+
this.definitions = Object.entries(schema.definitions).reduce((result, [childType, childSpec]) => {
|
|
180
|
+
result[childType] = childSpec === null || childSpec === void 0 ? void 0 : childSpec.selectCases;
|
|
181
|
+
return result;
|
|
182
|
+
}, {});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
export default new FormSpecParser();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Spec as DynamicFormSpec, ObjectSpec } from '@gravity-ui/dynamic-forms';
|
|
2
|
+
import { BlockType } from '../../../models';
|
|
3
|
+
import { Schema } from '../../../schema';
|
|
4
|
+
export type OneOfSpec = {
|
|
5
|
+
oneOf: DynamicFormSpec[];
|
|
6
|
+
viewSpec: ObjectSpec['viewSpec'];
|
|
7
|
+
};
|
|
8
|
+
export type CustomObjectSpec = Omit<ObjectSpec, 'properties'> & {
|
|
9
|
+
properties: Record<string, CustomSpec>;
|
|
10
|
+
};
|
|
11
|
+
export interface SpecCustomProps {
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
inputType?: string;
|
|
14
|
+
__schema?: Schema;
|
|
15
|
+
}
|
|
16
|
+
export type Spec = Exclude<DynamicFormSpec, 'ObjectSpec'> | CustomObjectSpec | OneOfSpec;
|
|
17
|
+
export type CustomSpec = Spec & SpecCustomProps;
|
|
18
|
+
export type BlocksSpec = Record<BlockType, CustomSpec>;
|
|
19
|
+
export type PageSpec = CustomSpec;
|
|
20
|
+
export interface FormSpecs {
|
|
21
|
+
blocks: BlocksSpec;
|
|
22
|
+
page: PageSpec;
|
|
23
|
+
}
|
|
24
|
+
export interface SchemaParserParams {
|
|
25
|
+
data: Schema;
|
|
26
|
+
name: string;
|
|
27
|
+
required?: Schema['required'];
|
|
28
|
+
}
|
|
29
|
+
export type SchemaParser = (params: SchemaParserParams) => CustomSpec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Schema } from '../../../schema';
|
|
2
|
+
import { CustomObjectSpec, CustomSpec } from './types';
|
|
3
|
+
interface BaseParams {
|
|
4
|
+
layoutTitle?: string;
|
|
5
|
+
}
|
|
6
|
+
interface GetObjectViewSpecParams extends BaseParams, Partial<Extract<CustomSpec, CustomObjectSpec>> {
|
|
7
|
+
layout?: string;
|
|
8
|
+
}
|
|
9
|
+
type GetPrimitiveViewSpecParams = BaseParams & Schema;
|
|
10
|
+
export declare const getOneOfViewSpec: ({ layoutTitle }: BaseParams) => {
|
|
11
|
+
type: string;
|
|
12
|
+
layout: string;
|
|
13
|
+
layoutTitle: string | undefined;
|
|
14
|
+
oneOfParams: {
|
|
15
|
+
toggler: "select";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare const getObjectViewSpec: ({ properties, disabled, layoutTitle, layout, }: GetObjectViewSpecParams) => {
|
|
19
|
+
layoutTitle: string | undefined;
|
|
20
|
+
type: string;
|
|
21
|
+
layout: string;
|
|
22
|
+
order: string[] | undefined;
|
|
23
|
+
disabled: boolean | undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare const getArrayViewSpec: ({ layoutTitle }: BaseParams) => {
|
|
26
|
+
layoutTitle: string | undefined;
|
|
27
|
+
type: string;
|
|
28
|
+
layout: string;
|
|
29
|
+
layoutOpen: boolean;
|
|
30
|
+
itemLabel: string;
|
|
31
|
+
};
|
|
32
|
+
export declare const getPrimitiveViewSpec: ({ layoutTitle, ...data }: GetPrimitiveViewSpecParams) => {
|
|
33
|
+
layout: string;
|
|
34
|
+
type: any;
|
|
35
|
+
layoutTitle: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
export const getOneOfViewSpec = ({ layoutTitle }) => {
|
|
3
|
+
return {
|
|
4
|
+
type: 'oneof_custom',
|
|
5
|
+
layout: 'row',
|
|
6
|
+
layoutTitle,
|
|
7
|
+
oneOfParams: {
|
|
8
|
+
toggler: 'select',
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export const getObjectViewSpec = ({ properties, disabled, layoutTitle, layout = 'accordeon', }) => {
|
|
13
|
+
return {
|
|
14
|
+
layoutTitle,
|
|
15
|
+
type: 'base',
|
|
16
|
+
layout,
|
|
17
|
+
order: properties && Object.keys(properties).sort(),
|
|
18
|
+
disabled,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const getArrayViewSpec = ({ layoutTitle }) => ({
|
|
22
|
+
layoutTitle,
|
|
23
|
+
type: 'base',
|
|
24
|
+
layout: 'accordeon',
|
|
25
|
+
layoutOpen: true,
|
|
26
|
+
itemLabel: 'Add Item',
|
|
27
|
+
});
|
|
28
|
+
export const getPrimitiveViewSpec = (_a) => {
|
|
29
|
+
var { layoutTitle } = _a, data = __rest(_a, ["layoutTitle"]);
|
|
30
|
+
let type = (data === null || data === void 0 ? void 0 : data.inputType) || 'base';
|
|
31
|
+
if (data && 'enum' in data && data.enum) {
|
|
32
|
+
type = 'select';
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
layout: 'row',
|
|
36
|
+
type,
|
|
37
|
+
layoutTitle,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { generateDefaultSchema } from '../../schema';
|
|
3
|
+
import formSpecParser from '../dynamic-forms-custom/parser';
|
|
4
|
+
export default function useFormSpec(customSchema) {
|
|
5
|
+
return useMemo(() => {
|
|
6
|
+
const schema = generateDefaultSchema(customSchema);
|
|
7
|
+
return formSpecParser.parse(schema);
|
|
8
|
+
}, [customSchema]);
|
|
9
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Editor } from './
|
|
1
|
+
export { Editor } from './containers/Editor/Editor';
|
|
2
2
|
export * from './types';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Editor } from './
|
|
1
|
+
export { Editor } from './containers/Editor/Editor';
|
|
2
2
|
export * from './types';
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { Block } from '../../models';
|
|
2
|
-
import { EditorProps } from '../types';
|
|
1
|
+
import { Block, BlockDecorationProps, PageContent } from '../../models';
|
|
2
|
+
import { EditBlockProps, 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
|
-
onDelete: (id: EditorBlockId) => void;
|
|
10
|
-
onSelect: (id: EditorBlockId) => void;
|
|
11
|
-
onCopy: (index: number) => void;
|
|
12
|
-
onOrderChange: (oldIndex: number, newIndex: number) => void;
|
|
13
|
-
};
|
|
5
|
+
activeBlockIndex: number;
|
|
6
|
+
content: PageContent;
|
|
7
|
+
errorBoundaryState: number;
|
|
8
|
+
injectEditBlockProps: ({ type, index: relativeIndex, children, }: BlockDecorationProps) => EditBlockProps;
|
|
14
9
|
onAdd: (block: Block) => void;
|
|
10
|
+
onSelect: (index: number) => void;
|
|
11
|
+
onContentUpdate: (newContent: PageContent) => void;
|
|
15
12
|
};
|
|
@@ -1,28 +1,74 @@
|
|
|
1
1
|
import { useMemo, useReducer } from 'react';
|
|
2
2
|
import { HeaderBlockTypes } from '../../models';
|
|
3
|
-
import { getCustomHeaderTypes,
|
|
4
|
-
import {
|
|
3
|
+
import { getCustomHeaderTypes, getHeaderBlock } from '../../utils';
|
|
4
|
+
import { EditBlockControls } from '../components/EditBlock/EditBlock';
|
|
5
|
+
import { ADD_BLOCK, COPY_BLOCK, DELETE_BLOCK, ORDER_BLOCK, SELECT_BLOCK, UPDATE_CONTENT, reducer, } from './reducer';
|
|
5
6
|
import { addEditorProps } from './utils';
|
|
6
7
|
export function useEditorState({ content: intialContent, custom }) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
activeBlockId: 0,
|
|
11
|
-
orderedBlocksCount: getOrderedBlocks(intialContent.blocks, headerBlockTypes).length,
|
|
8
|
+
const [{ activeBlockIndex, content, errorBoundaryState }, dispatch] = useReducer(reducer, {
|
|
9
|
+
activeBlockIndex: 0,
|
|
10
|
+
errorBoundaryState: 0,
|
|
12
11
|
content: addEditorProps(intialContent),
|
|
13
12
|
});
|
|
14
13
|
return useMemo(() => {
|
|
14
|
+
const headerBlockTypes = [...HeaderBlockTypes, ...getCustomHeaderTypes(custom)];
|
|
15
|
+
const contentHasHeader = Boolean(getHeaderBlock(content.blocks, headerBlockTypes));
|
|
16
|
+
const checkIsHeader = (type) => headerBlockTypes.includes(type);
|
|
17
|
+
const onAdd = (block) => {
|
|
18
|
+
const isHeader = checkIsHeader(block.type);
|
|
19
|
+
if (contentHasHeader && isHeader) {
|
|
20
|
+
//TODO: add warning that it should be only one header block
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// eslint-disable-next-line no-nested-ternary
|
|
24
|
+
const index = isHeader
|
|
25
|
+
? 0
|
|
26
|
+
: activeBlockIndex === -1
|
|
27
|
+
? content.blocks.length
|
|
28
|
+
: activeBlockIndex + 1;
|
|
29
|
+
dispatch({ type: ADD_BLOCK, payload: { block, index } });
|
|
30
|
+
};
|
|
31
|
+
const onSelect = (index) => dispatch({ type: SELECT_BLOCK, payload: index });
|
|
32
|
+
const onContentUpdate = (newContent) => dispatch({ type: UPDATE_CONTENT, payload: newContent });
|
|
33
|
+
const injectEditBlockProps = ({ type, index: relativeIndex = 0, children, }) => {
|
|
34
|
+
const orderedBlocksStartIndex = contentHasHeader ? 1 : 0;
|
|
35
|
+
const isHeader = checkIsHeader(type);
|
|
36
|
+
const index = isHeader ? 0 : relativeIndex + orderedBlocksStartIndex;
|
|
37
|
+
const isActive = activeBlockIndex === index;
|
|
38
|
+
const actions = {
|
|
39
|
+
[EditBlockControls.Delete]: () => dispatch({ type: DELETE_BLOCK, payload: index }),
|
|
40
|
+
};
|
|
41
|
+
if (!isHeader) {
|
|
42
|
+
actions[EditBlockControls.Copy] = () => dispatch({ type: COPY_BLOCK, payload: index });
|
|
43
|
+
if (index > orderedBlocksStartIndex) {
|
|
44
|
+
actions[EditBlockControls.Up] = () => dispatch({
|
|
45
|
+
type: ORDER_BLOCK,
|
|
46
|
+
payload: { oldIndex: index, newIndex: index - 1 },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (index < content.blocks.length - 1) {
|
|
50
|
+
actions[EditBlockControls.Down] = () => dispatch({
|
|
51
|
+
type: ORDER_BLOCK,
|
|
52
|
+
payload: { oldIndex: index, newIndex: index + 1 },
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
children,
|
|
58
|
+
isHeader,
|
|
59
|
+
isActive,
|
|
60
|
+
actions,
|
|
61
|
+
onSelect: () => onSelect(index),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
15
64
|
return {
|
|
65
|
+
activeBlockIndex,
|
|
16
66
|
content,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 }),
|
|
67
|
+
errorBoundaryState,
|
|
68
|
+
injectEditBlockProps,
|
|
69
|
+
onAdd,
|
|
70
|
+
onSelect,
|
|
71
|
+
onContentUpdate,
|
|
26
72
|
};
|
|
27
|
-
}, [content,
|
|
73
|
+
}, [content, activeBlockIndex, errorBoundaryState, custom]);
|
|
28
74
|
}
|
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
import { Block,
|
|
1
|
+
import { Block, PageContent } from '../../models';
|
|
2
2
|
export type EditorBlockId = number | string;
|
|
3
3
|
interface EditorState {
|
|
4
4
|
content: PageContent;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
custom?: CustomConfig;
|
|
5
|
+
activeBlockIndex: number;
|
|
6
|
+
errorBoundaryState: number;
|
|
8
7
|
}
|
|
9
8
|
interface OrderBlockParams {
|
|
10
9
|
oldIndex: number;
|
|
11
10
|
newIndex: number;
|
|
12
11
|
}
|
|
12
|
+
interface AddBlockParams {
|
|
13
|
+
block: Block;
|
|
14
|
+
index: number;
|
|
15
|
+
}
|
|
13
16
|
export declare const SELECT_BLOCK = "SELECT_BLOCK";
|
|
14
17
|
export declare const DELETE_BLOCK = "DELETE_BLOCK";
|
|
15
18
|
export declare const COPY_BLOCK = "COPY_BLOCK";
|
|
16
19
|
export declare const ADD_BLOCK = "ADD_BLOCK";
|
|
17
20
|
export declare const SET_REGION = "SET_REGION";
|
|
18
21
|
export declare const ORDER_BLOCK = "ORDER_BLOCK";
|
|
22
|
+
export declare const UPDATE_CONTENT = "UPDATE_CONTENT";
|
|
19
23
|
interface SelectBlock {
|
|
20
24
|
type: typeof SELECT_BLOCK;
|
|
21
|
-
payload:
|
|
25
|
+
payload: number;
|
|
22
26
|
}
|
|
23
27
|
interface DeleteBlock {
|
|
24
28
|
type: typeof DELETE_BLOCK;
|
|
25
|
-
payload:
|
|
29
|
+
payload: number;
|
|
26
30
|
}
|
|
27
31
|
interface CopyBlock {
|
|
28
32
|
type: typeof COPY_BLOCK;
|
|
@@ -30,12 +34,16 @@ interface CopyBlock {
|
|
|
30
34
|
}
|
|
31
35
|
interface AddBlock {
|
|
32
36
|
type: typeof ADD_BLOCK;
|
|
33
|
-
payload:
|
|
37
|
+
payload: AddBlockParams;
|
|
34
38
|
}
|
|
35
39
|
interface OrderBlock {
|
|
36
40
|
type: typeof ORDER_BLOCK;
|
|
37
41
|
payload: OrderBlockParams;
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
interface UpdateContent {
|
|
44
|
+
type: typeof UPDATE_CONTENT;
|
|
45
|
+
payload: PageContent;
|
|
46
|
+
}
|
|
47
|
+
export type EditorAction = SelectBlock | DeleteBlock | CopyBlock | AddBlock | OrderBlock | UpdateContent;
|
|
48
|
+
export declare const reducer: (state: EditorState, action: EditorAction) => EditorState;
|
|
41
49
|
export {};
|