@gravity-ui/dynamic-forms 3.2.0 → 3.4.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/build/cjs/lib/core/components/Form/Controller/Controller.js +120 -0
- package/build/cjs/lib/core/components/Form/Controller/index.js +4 -0
- package/build/cjs/lib/core/components/Form/Controller/types.js +2 -0
- package/build/cjs/lib/core/components/Form/Controller/utils.js +305 -0
- package/build/cjs/lib/core/components/Form/hooks/index.js +0 -4
- package/build/cjs/lib/core/components/Form/hooks/useMutators.js +21 -1
- package/build/cjs/lib/core/components/Form/utils/common.js +1 -5
- package/build/cjs/lib/kit/components/AccordeonCard/AccordeonCard.css +6 -6
- package/build/cjs/lib/kit/components/Card/Card.css +3 -3
- package/build/cjs/lib/kit/components/ErrorWrapper/ErrorWrapper.css +4 -4
- package/build/cjs/lib/kit/components/GroupIndent/GroupIndent.css +1 -1
- package/build/cjs/lib/kit/components/Inputs/FileInput/FileInput.css +1 -1
- package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoHeader.css +1 -1
- package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoInputBase.css +1 -1
- package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.css +1 -1
- package/build/cjs/lib/kit/components/Inputs/OneOf/OneOf.css +1 -1
- package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.css +1 -1
- package/build/cjs/lib/kit/components/Layouts/Row/Row.css +3 -3
- package/build/cjs/lib/kit/components/LongValue/LongValue.css +1 -1
- package/build/cjs/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.css +4 -4
- package/build/cjs/lib/kit/components/ViewLayouts/ViewRow/ViewRow.css +2 -2
- package/build/cjs/lib/kit/components/Views/MonacoInputView/MonacoBaseView.css +1 -1
- package/build/cjs/lib/kit/components/Views/MonacoInputView/MonacoViewDialog.css +1 -1
- package/build/cjs/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +1 -1
- package/build/cjs/lib/kit/validators/types.js +2 -0
- package/build/cjs/lib/kit/validators/validators.js +32 -25
- package/build/esm/lib/core/components/Form/Controller/Controller.d.ts +10 -0
- package/build/esm/lib/core/components/Form/Controller/Controller.js +115 -0
- package/build/esm/lib/core/components/Form/Controller/index.d.ts +1 -0
- package/build/esm/lib/core/components/Form/Controller/index.js +1 -0
- package/build/esm/lib/core/components/Form/Controller/types.d.ts +98 -0
- package/build/esm/lib/core/components/Form/Controller/types.js +1 -0
- package/build/esm/lib/core/components/Form/Controller/utils.d.ts +26 -0
- package/build/esm/lib/core/components/Form/Controller/utils.js +291 -0
- package/build/esm/lib/core/components/Form/hooks/index.d.ts +0 -4
- package/build/esm/lib/core/components/Form/hooks/index.js +0 -4
- package/build/esm/lib/core/components/Form/hooks/useMutators.js +21 -1
- package/build/esm/lib/core/components/Form/types/mirror.d.ts +3 -5
- package/build/esm/lib/core/components/Form/types/mutators.d.ts +13 -2
- package/build/esm/lib/core/components/Form/utils/common.d.ts +0 -3
- package/build/esm/lib/core/components/Form/utils/common.js +0 -2
- package/build/esm/lib/kit/components/AccordeonCard/AccordeonCard.css +6 -6
- package/build/esm/lib/kit/components/Card/Card.css +3 -3
- package/build/esm/lib/kit/components/ErrorWrapper/ErrorWrapper.css +4 -4
- package/build/esm/lib/kit/components/GroupIndent/GroupIndent.css +1 -1
- package/build/esm/lib/kit/components/Inputs/FileInput/FileInput.css +1 -1
- package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoHeader.css +1 -1
- package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoInputBase.css +1 -1
- package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.css +1 -1
- package/build/esm/lib/kit/components/Inputs/OneOf/OneOf.css +1 -1
- package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.css +1 -1
- package/build/esm/lib/kit/components/Layouts/Row/Row.css +3 -3
- package/build/esm/lib/kit/components/LongValue/LongValue.css +1 -1
- package/build/esm/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.css +4 -4
- package/build/esm/lib/kit/components/ViewLayouts/ViewRow/ViewRow.css +2 -2
- package/build/esm/lib/kit/components/Views/MonacoInputView/MonacoBaseView.css +1 -1
- package/build/esm/lib/kit/components/Views/MonacoInputView/MonacoViewDialog.css +1 -1
- package/build/esm/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +1 -1
- package/build/esm/lib/kit/validators/messages.d.ts +2 -16
- package/build/esm/lib/kit/validators/types.d.ts +16 -0
- package/build/esm/lib/kit/validators/types.js +1 -0
- package/build/esm/lib/kit/validators/validators.d.ts +10 -9
- package/build/esm/lib/kit/validators/validators.js +32 -25
- package/package.json +10 -2
- package/build/cjs/lib/core/components/Form/Controller.js +0 -42
- package/build/cjs/lib/core/components/Form/hooks/useComponents.js +0 -40
- package/build/cjs/lib/core/components/Form/hooks/useField.js +0 -176
- package/build/cjs/lib/core/components/Form/hooks/useRender.js +0 -28
- package/build/cjs/lib/core/components/Form/hooks/useValidate.js +0 -32
- package/build/esm/lib/core/components/Form/Controller.d.ts +0 -10
- package/build/esm/lib/core/components/Form/Controller.js +0 -37
- package/build/esm/lib/core/components/Form/hooks/useComponents.d.ts +0 -6
- package/build/esm/lib/core/components/Form/hooks/useComponents.js +0 -35
- package/build/esm/lib/core/components/Form/hooks/useField.d.ts +0 -14
- package/build/esm/lib/core/components/Form/hooks/useField.js +0 -171
- package/build/esm/lib/core/components/Form/hooks/useRender.d.ts +0 -9
- package/build/esm/lib/core/components/Form/hooks/useRender.js +0 -23
- package/build/esm/lib/core/components/Form/hooks/useValidate.d.ts +0 -3
- package/build/esm/lib/core/components/Form/hooks/useValidate.js +0 -27
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Controller = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
|
+
const hooks_1 = require("../hooks");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const Controller = ({ spec: _spec, name, value: valueFromParent, parentOnChange, parentOnUnmount, }) => {
|
|
10
|
+
const { config, tools, mutators, __mirror } = (0, hooks_1.useDynamicFormsCtx)();
|
|
11
|
+
const firstRenderRef = react_1.default.useRef(true);
|
|
12
|
+
const [store, setStore] = react_1.default.useState((0, utils_1.initializeStore)({
|
|
13
|
+
name,
|
|
14
|
+
spec: _spec,
|
|
15
|
+
mutators,
|
|
16
|
+
config,
|
|
17
|
+
valueFromParent,
|
|
18
|
+
tools,
|
|
19
|
+
parentOnChange,
|
|
20
|
+
parentOnUnmount,
|
|
21
|
+
}));
|
|
22
|
+
const { methods, fieldMethods } = react_1.default.useMemo(() => {
|
|
23
|
+
const fieldMethods = (0, utils_1.getFieldMethods)();
|
|
24
|
+
const onChange = (valOrSetter, childErrors, errorMutator) => {
|
|
25
|
+
setStore((store) => fieldMethods.onChange(store, { valOrSetter, childErrors, errorMutator }));
|
|
26
|
+
};
|
|
27
|
+
const onDrop = () => {
|
|
28
|
+
setStore((store) => fieldMethods.onDrop(store, undefined));
|
|
29
|
+
};
|
|
30
|
+
const onBlur = () => {
|
|
31
|
+
setStore((store) => fieldMethods.onBlur(store, undefined));
|
|
32
|
+
};
|
|
33
|
+
const onFocus = () => {
|
|
34
|
+
setStore((store) => fieldMethods.onFocus(store, undefined));
|
|
35
|
+
};
|
|
36
|
+
const parentOnUnmount = (childName) => {
|
|
37
|
+
setStore((store) => fieldMethods.parentOnUnmount(store, childName));
|
|
38
|
+
};
|
|
39
|
+
const onItemAdd = (value) => {
|
|
40
|
+
setStore((store) => fieldMethods.onItemAdd(store, value));
|
|
41
|
+
};
|
|
42
|
+
const onItemRemove = (idx) => {
|
|
43
|
+
setStore((store) => fieldMethods.onItemRemove(store, idx));
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
methods: {
|
|
47
|
+
onChange,
|
|
48
|
+
onDrop,
|
|
49
|
+
onBlur,
|
|
50
|
+
onFocus,
|
|
51
|
+
parentOnUnmount,
|
|
52
|
+
onItemAdd,
|
|
53
|
+
onItemRemove,
|
|
54
|
+
},
|
|
55
|
+
fieldMethods,
|
|
56
|
+
};
|
|
57
|
+
}, [setStore]);
|
|
58
|
+
const renderProps = react_1.default.useMemo(() => ({
|
|
59
|
+
input: {
|
|
60
|
+
name: store.name,
|
|
61
|
+
value: store.state.value,
|
|
62
|
+
onChange: methods.onChange,
|
|
63
|
+
onBlur: methods.onBlur,
|
|
64
|
+
onFocus: methods.onFocus,
|
|
65
|
+
onDrop: methods.onDrop,
|
|
66
|
+
parentOnUnmount: methods.parentOnUnmount,
|
|
67
|
+
},
|
|
68
|
+
arrayInput: {
|
|
69
|
+
name: store.name,
|
|
70
|
+
value: store.state.value,
|
|
71
|
+
onItemAdd: methods.onItemAdd,
|
|
72
|
+
onItemRemove: methods.onItemRemove,
|
|
73
|
+
onDrop: methods.onDrop,
|
|
74
|
+
},
|
|
75
|
+
meta: Object.assign(Object.assign({}, lodash_1.default.omit(store.state, 'value')), { submitFailed: store.tools.submitFailed }),
|
|
76
|
+
}), [methods, store.name, store.state, store.tools.submitFailed]);
|
|
77
|
+
const withSearch = (0, hooks_1.useSearch)(store.spec, store.state.value, store.name);
|
|
78
|
+
(0, hooks_1.useControllerMirror)(store.name, {
|
|
79
|
+
useField: renderProps,
|
|
80
|
+
useSearch: withSearch,
|
|
81
|
+
}, __mirror);
|
|
82
|
+
react_1.default.useEffect(() => {
|
|
83
|
+
var _a;
|
|
84
|
+
(_a = store.afterStoreUpdateCB) === null || _a === void 0 ? void 0 : _a.call(store);
|
|
85
|
+
}, [store.afterStoreUpdateCB]);
|
|
86
|
+
react_1.default.useEffect(() => {
|
|
87
|
+
if (!firstRenderRef.current) {
|
|
88
|
+
(0, utils_1.updateStore)({
|
|
89
|
+
store,
|
|
90
|
+
setStore,
|
|
91
|
+
spec: _spec,
|
|
92
|
+
name,
|
|
93
|
+
parentOnChange,
|
|
94
|
+
parentOnUnmount,
|
|
95
|
+
mutators,
|
|
96
|
+
config,
|
|
97
|
+
tools,
|
|
98
|
+
methodOnChange: fieldMethods.onChange,
|
|
99
|
+
valueFromParent,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}, [
|
|
103
|
+
_spec,
|
|
104
|
+
name,
|
|
105
|
+
parentOnChange,
|
|
106
|
+
parentOnUnmount,
|
|
107
|
+
mutators,
|
|
108
|
+
config,
|
|
109
|
+
tools.onChange,
|
|
110
|
+
tools.onUnmount,
|
|
111
|
+
]);
|
|
112
|
+
react_1.default.useEffect(() => {
|
|
113
|
+
firstRenderRef.current = false;
|
|
114
|
+
return () => {
|
|
115
|
+
(0, utils_1.callUnmout)(store);
|
|
116
|
+
};
|
|
117
|
+
}, []);
|
|
118
|
+
return withSearch(store.render(renderProps));
|
|
119
|
+
};
|
|
120
|
+
exports.Controller = Controller;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateStore = exports.initializeStore = exports.getFieldMethods = exports.getFieldInitials = exports.getValidate = exports.getRender = exports.getComponents = exports.getSpec = exports.callUnmout = exports.updateParentStore = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
|
+
const react_is_1 = require("react-is");
|
|
8
|
+
const constants_1 = require("../../../constants");
|
|
9
|
+
const helpers_1 = require("../../../helpers");
|
|
10
|
+
const constants_2 = require("../constants");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
12
|
+
const isErrorMutatorCorrect = (errorMutator) => errorMutator !== constants_2.EMPTY_MUTATOR && (lodash_1.default.isString(errorMutator) || lodash_1.default.isBoolean(errorMutator));
|
|
13
|
+
const isValueMutatorCorrect = (valueMutator, spec) => valueMutator !== constants_2.EMPTY_MUTATOR &&
|
|
14
|
+
(typeof valueMutator === spec.type ||
|
|
15
|
+
(lodash_1.default.isArray(valueMutator) && spec.type === constants_1.SpecTypes.Array));
|
|
16
|
+
const updateParentStore = (store) => {
|
|
17
|
+
(store.parentOnChange ? store.parentOnChange : store.tools.onChange)(store.name, store.state.value, Object.assign(Object.assign({}, store.state.childErrors), { [store.name]: store.state.error }));
|
|
18
|
+
};
|
|
19
|
+
exports.updateParentStore = updateParentStore;
|
|
20
|
+
const callUnmout = (store) => {
|
|
21
|
+
(store.parentOnUnmount ? store.parentOnUnmount : store.tools.onUnmount)(store.name);
|
|
22
|
+
};
|
|
23
|
+
exports.callUnmout = callUnmout;
|
|
24
|
+
const getSpec = ({ name, spec, mutators, }) => {
|
|
25
|
+
const mutator = lodash_1.default.get(mutators.spec, name, constants_2.EMPTY_MUTATOR);
|
|
26
|
+
if (mutator !== constants_2.EMPTY_MUTATOR) {
|
|
27
|
+
const mutatedSpec = lodash_1.default.merge(lodash_1.default.cloneDeep(spec), mutator);
|
|
28
|
+
if ((0, helpers_1.isCorrectSpec)(mutatedSpec)) {
|
|
29
|
+
return mutatedSpec;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return spec;
|
|
33
|
+
};
|
|
34
|
+
exports.getSpec = getSpec;
|
|
35
|
+
const getComponents = ({ spec, config, }) => {
|
|
36
|
+
const result = {};
|
|
37
|
+
if ((0, utils_1.isCorrectConfig)(config) && (0, helpers_1.isCorrectSpec)(spec)) {
|
|
38
|
+
const { inputs, layouts } = config[spec.type];
|
|
39
|
+
if (inputs) {
|
|
40
|
+
const entity = inputs[spec.viewSpec.type];
|
|
41
|
+
if ((0, react_is_1.isValidElementType)(entity === null || entity === void 0 ? void 0 : entity.Component)) {
|
|
42
|
+
result.inputEntity = entity;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (layouts && lodash_1.default.isString(spec.viewSpec.layout)) {
|
|
46
|
+
const Component = layouts[spec.viewSpec.layout];
|
|
47
|
+
if ((0, react_is_1.isValidElementType)(Component)) {
|
|
48
|
+
result.Layout = Component;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
exports.getComponents = getComponents;
|
|
55
|
+
const getRender = ({ name, spec, inputEntity, Layout, }) => {
|
|
56
|
+
const render = (props) => {
|
|
57
|
+
if (inputEntity && (0, helpers_1.isCorrectSpec)(spec) && lodash_1.default.isString(name)) {
|
|
58
|
+
if (!spec.viewSpec.hidden) {
|
|
59
|
+
if (inputEntity.independent) {
|
|
60
|
+
const InputComponent = inputEntity.Component;
|
|
61
|
+
return react_1.default.createElement(InputComponent, Object.assign({ spec: spec, name: name, Layout: Layout }, props));
|
|
62
|
+
}
|
|
63
|
+
const InputComponent = inputEntity.Component;
|
|
64
|
+
const input = react_1.default.createElement(InputComponent, Object.assign({ spec: spec, name: name }, props));
|
|
65
|
+
if (Layout) {
|
|
66
|
+
return (react_1.default.createElement(Layout, Object.assign({ spec: spec, name: name }, props), input));
|
|
67
|
+
}
|
|
68
|
+
return input;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
};
|
|
73
|
+
return render;
|
|
74
|
+
};
|
|
75
|
+
exports.getRender = getRender;
|
|
76
|
+
const getValidate = ({ spec, config, }) => {
|
|
77
|
+
let validate = () => undefined;
|
|
78
|
+
if ((0, utils_1.isCorrectConfig)(config) && (0, helpers_1.isCorrectSpec)(spec)) {
|
|
79
|
+
const { validators } = config[spec.type];
|
|
80
|
+
if (validators) {
|
|
81
|
+
if ((!lodash_1.default.isString(spec.validator) || !spec.validator.length) &&
|
|
82
|
+
lodash_1.default.isFunction(validators.base)) {
|
|
83
|
+
validate = (value) => validators.base(spec, value);
|
|
84
|
+
}
|
|
85
|
+
if (lodash_1.default.isString(spec.validator) && lodash_1.default.isFunction(validators[spec.validator])) {
|
|
86
|
+
validate = (value) => validators[spec.validator](spec, value);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return validate;
|
|
91
|
+
};
|
|
92
|
+
exports.getValidate = getValidate;
|
|
93
|
+
const getFieldInitials = ({ name, spec, valueFromParent, initialValue, validate, mutators, }) => {
|
|
94
|
+
const valueMutator = (0, utils_1.transformArrIn)(lodash_1.default.get(mutators.values, name, constants_2.EMPTY_MUTATOR));
|
|
95
|
+
let value = lodash_1.default.cloneDeep(valueFromParent);
|
|
96
|
+
if (isValueMutatorCorrect(valueMutator, spec)) {
|
|
97
|
+
value = valueMutator;
|
|
98
|
+
}
|
|
99
|
+
if (lodash_1.default.isNil(value)) {
|
|
100
|
+
if (spec.defaultValue) {
|
|
101
|
+
value = (0, utils_1.transformArrIn)(spec.defaultValue);
|
|
102
|
+
}
|
|
103
|
+
// if the spec with type array or object, and this spec has "required === true",
|
|
104
|
+
// we immediately exclude empty value
|
|
105
|
+
else if (spec.required) {
|
|
106
|
+
if ((0, helpers_1.isArraySpec)(spec)) {
|
|
107
|
+
value = { [constants_2.OBJECT_ARRAY_FLAG]: true, [constants_2.OBJECT_ARRAY_CNT]: 0 };
|
|
108
|
+
}
|
|
109
|
+
else if ((0, helpers_1.isObjectSpec)(spec)) {
|
|
110
|
+
value = {};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
let errorMutator = lodash_1.default.get(mutators.errors, name, constants_2.EMPTY_MUTATOR);
|
|
115
|
+
if (!isErrorMutatorCorrect(errorMutator)) {
|
|
116
|
+
errorMutator = undefined;
|
|
117
|
+
}
|
|
118
|
+
const error = (validate === null || validate === void 0 ? void 0 : validate((0, utils_1.transformArrOut)(value))) || errorMutator;
|
|
119
|
+
const dirty = !lodash_1.default.isEqual(value, initialValue);
|
|
120
|
+
return {
|
|
121
|
+
initialValue,
|
|
122
|
+
active: false,
|
|
123
|
+
dirty,
|
|
124
|
+
error,
|
|
125
|
+
invalid: Boolean(error),
|
|
126
|
+
modified: dirty,
|
|
127
|
+
pristine: true,
|
|
128
|
+
touched: false,
|
|
129
|
+
valid: !error,
|
|
130
|
+
value,
|
|
131
|
+
visited: false,
|
|
132
|
+
childErrors: {},
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
exports.getFieldInitials = getFieldInitials;
|
|
136
|
+
const getFieldMethods = () => {
|
|
137
|
+
const onChange = (store, { valOrSetter, childErrors, errorMutator }) => {
|
|
138
|
+
const { state, validate, spec } = store;
|
|
139
|
+
const _value = lodash_1.default.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
|
|
140
|
+
const error = (validate === null || validate === void 0 ? void 0 : validate((0, utils_1.transformArrOut)(_value))) || errorMutator;
|
|
141
|
+
let value = (0, utils_1.transformArrIn)(_value);
|
|
142
|
+
if ((0, helpers_1.isNumberSpec)(spec) && !error) {
|
|
143
|
+
value = (value ? Number(value) : undefined);
|
|
144
|
+
}
|
|
145
|
+
let newChildErrors = Object.assign({}, state.childErrors);
|
|
146
|
+
if (childErrors) {
|
|
147
|
+
const nearestChildName = lodash_1.default.keys(childErrors).sort((a, b) => a.length - b.length)[0];
|
|
148
|
+
if (nearestChildName) {
|
|
149
|
+
const existingСhildNames = lodash_1.default.keys(newChildErrors).filter((childName) => childName.startsWith(nearestChildName));
|
|
150
|
+
newChildErrors = Object.assign(Object.assign({}, lodash_1.default.omit(newChildErrors, existingСhildNames)), childErrors);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const nextStore = Object.assign(Object.assign({}, store), { state: Object.assign(Object.assign({}, store.state), { dirty: !lodash_1.default.isEqual(value, state.initialValue), error, invalid: Boolean(error), modified: true, pristine: value === state.initialValue, touched: true, valid: !error, value, visited: true, childErrors: newChildErrors }) });
|
|
154
|
+
nextStore.afterStoreUpdateCB = () => (0, exports.updateParentStore)(nextStore);
|
|
155
|
+
return nextStore;
|
|
156
|
+
};
|
|
157
|
+
const onDrop = (store) => {
|
|
158
|
+
const { name } = store;
|
|
159
|
+
if ((0, utils_1.isArrayItem)(name)) {
|
|
160
|
+
const afterStoreUpdateCB = () => (0, exports.callUnmout)(store);
|
|
161
|
+
return Object.assign(Object.assign({}, store), { afterStoreUpdateCB });
|
|
162
|
+
}
|
|
163
|
+
return onChange(store, {
|
|
164
|
+
valOrSetter: undefined,
|
|
165
|
+
childErrors: { [name]: false },
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
const onBlur = (store) => {
|
|
169
|
+
return Object.assign(Object.assign({}, store), { state: Object.assign(Object.assign({}, store.state), { active: false, touched: true }) });
|
|
170
|
+
};
|
|
171
|
+
const onFocus = (store) => {
|
|
172
|
+
return Object.assign(Object.assign({}, store), { state: Object.assign(Object.assign({}, store.state), { active: true, visited: true }) });
|
|
173
|
+
};
|
|
174
|
+
const parentOnUnmount = (store, childName) => {
|
|
175
|
+
const { name, spec } = store;
|
|
176
|
+
if ((0, helpers_1.isArraySpec)(spec) || (0, helpers_1.isObjectSpec)(spec)) {
|
|
177
|
+
return onChange(store, {
|
|
178
|
+
valOrSetter: (currentValue) => currentValue
|
|
179
|
+
? lodash_1.default.omit(currentValue, childName.split(`${name}.`)[1])
|
|
180
|
+
: currentValue,
|
|
181
|
+
childErrors: { [childName]: false },
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return store;
|
|
185
|
+
};
|
|
186
|
+
const onItemAdd = (store, _value) => {
|
|
187
|
+
const { validate, state } = store;
|
|
188
|
+
const stateValue = (state.value || {
|
|
189
|
+
[constants_2.OBJECT_ARRAY_FLAG]: true,
|
|
190
|
+
[constants_2.OBJECT_ARRAY_CNT]: 0,
|
|
191
|
+
});
|
|
192
|
+
const value = Object.assign(Object.assign({}, stateValue), { [`<${stateValue[constants_2.OBJECT_ARRAY_CNT]}>`]: (0, utils_1.transformArrIn)(_value), [constants_2.OBJECT_ARRAY_CNT]: stateValue[constants_2.OBJECT_ARRAY_CNT] + 1 });
|
|
193
|
+
const error = validate === null || validate === void 0 ? void 0 : validate((0, utils_1.transformArrOut)(value));
|
|
194
|
+
const nextStore = Object.assign(Object.assign({}, store), { state: Object.assign(Object.assign({}, store.state), { dirty: !lodash_1.default.isEqual(value, store.state.initialValue), error, invalid: Boolean(error), modified: true, pristine: value === store.state.initialValue, touched: true, valid: !error, value, visited: true }) });
|
|
195
|
+
nextStore.afterStoreUpdateCB = () => (0, exports.updateParentStore)(nextStore);
|
|
196
|
+
return nextStore;
|
|
197
|
+
};
|
|
198
|
+
const onItemRemove = (store, idx) => {
|
|
199
|
+
return parentOnUnmount(store, `${store.name}.<${idx}>`);
|
|
200
|
+
};
|
|
201
|
+
return {
|
|
202
|
+
onChange,
|
|
203
|
+
onDrop,
|
|
204
|
+
onBlur,
|
|
205
|
+
onFocus,
|
|
206
|
+
parentOnUnmount,
|
|
207
|
+
onItemAdd,
|
|
208
|
+
onItemRemove,
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
exports.getFieldMethods = getFieldMethods;
|
|
212
|
+
const initializeStore = ({ name, spec: _spec, mutators, config, valueFromParent, tools, parentOnChange, parentOnUnmount, }) => {
|
|
213
|
+
const spec = (0, exports.getSpec)({ name, spec: _spec, mutators });
|
|
214
|
+
const components = (0, exports.getComponents)({ spec, config });
|
|
215
|
+
const render = (0, exports.getRender)(Object.assign({ name, spec }, components));
|
|
216
|
+
const validate = (0, exports.getValidate)({ spec, config });
|
|
217
|
+
const state = (0, exports.getFieldInitials)({
|
|
218
|
+
name,
|
|
219
|
+
spec,
|
|
220
|
+
valueFromParent,
|
|
221
|
+
validate,
|
|
222
|
+
mutators,
|
|
223
|
+
initialValue: lodash_1.default.get(tools.initialValue, name),
|
|
224
|
+
});
|
|
225
|
+
const initialsStore = {
|
|
226
|
+
name,
|
|
227
|
+
spec,
|
|
228
|
+
initialSpec: _spec,
|
|
229
|
+
config,
|
|
230
|
+
tools,
|
|
231
|
+
mutators,
|
|
232
|
+
render,
|
|
233
|
+
validate,
|
|
234
|
+
parentOnChange,
|
|
235
|
+
parentOnUnmount,
|
|
236
|
+
state,
|
|
237
|
+
};
|
|
238
|
+
if (!lodash_1.default.isEqual(valueFromParent, state.value) || state.error) {
|
|
239
|
+
initialsStore.afterStoreUpdateCB = () => (0, exports.updateParentStore)(initialsStore);
|
|
240
|
+
}
|
|
241
|
+
return initialsStore;
|
|
242
|
+
};
|
|
243
|
+
exports.initializeStore = initializeStore;
|
|
244
|
+
const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange, parentOnUnmount, mutators, valueFromParent, config, tools, methodOnChange, }) => {
|
|
245
|
+
const storeSpecMutator = lodash_1.default.get(store.mutators.spec, store.name, constants_2.EMPTY_MUTATOR);
|
|
246
|
+
const storeValueMutator = lodash_1.default.get(store.mutators.values, store.name, constants_2.EMPTY_MUTATOR);
|
|
247
|
+
const storeErrorMutator = lodash_1.default.get(store.mutators.errors, store.name, constants_2.EMPTY_MUTATOR);
|
|
248
|
+
const specMutator = lodash_1.default.get(mutators.spec, name, constants_2.EMPTY_MUTATOR);
|
|
249
|
+
const valueMutator = lodash_1.default.get(mutators.values, name, constants_2.EMPTY_MUTATOR);
|
|
250
|
+
const errorMutator = lodash_1.default.get(mutators.errors, name, constants_2.EMPTY_MUTATOR);
|
|
251
|
+
const valueMutatorUpdated = isValueMutatorCorrect(valueMutator, (0, exports.getSpec)({ name, spec: _spec, mutators })) &&
|
|
252
|
+
valueMutator !== storeValueMutator;
|
|
253
|
+
const errorMutatorUpdated = isErrorMutatorCorrect(errorMutator) && errorMutator !== storeErrorMutator;
|
|
254
|
+
const updateState = valueMutatorUpdated || errorMutatorUpdated;
|
|
255
|
+
const updateNonCritical = parentOnChange !== store.parentOnChange ||
|
|
256
|
+
parentOnUnmount !== store.parentOnUnmount ||
|
|
257
|
+
tools.onChange !== store.tools.onChange ||
|
|
258
|
+
tools.onUnmount !== store.tools.onUnmount;
|
|
259
|
+
const updateAllStore = !lodash_1.default.isEqual(_spec, store.initialSpec) ||
|
|
260
|
+
config !== store.config ||
|
|
261
|
+
(specMutator !== constants_2.EMPTY_MUTATOR && specMutator !== storeSpecMutator);
|
|
262
|
+
const updateAllStoreAndClearParentValues = name !== store.name;
|
|
263
|
+
if (updateAllStoreAndClearParentValues) {
|
|
264
|
+
(0, exports.callUnmout)(store);
|
|
265
|
+
setStore((0, exports.initializeStore)({
|
|
266
|
+
name,
|
|
267
|
+
spec: _spec,
|
|
268
|
+
mutators,
|
|
269
|
+
config,
|
|
270
|
+
valueFromParent,
|
|
271
|
+
tools,
|
|
272
|
+
parentOnChange,
|
|
273
|
+
parentOnUnmount,
|
|
274
|
+
}));
|
|
275
|
+
}
|
|
276
|
+
else if (updateAllStore) {
|
|
277
|
+
let nextStore = Object.assign(Object.assign({}, (0, exports.initializeStore)({
|
|
278
|
+
name,
|
|
279
|
+
spec: _spec,
|
|
280
|
+
mutators,
|
|
281
|
+
config,
|
|
282
|
+
valueFromParent,
|
|
283
|
+
tools,
|
|
284
|
+
parentOnChange,
|
|
285
|
+
parentOnUnmount,
|
|
286
|
+
})), { state: store.state });
|
|
287
|
+
if (updateState) {
|
|
288
|
+
nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {})));
|
|
289
|
+
}
|
|
290
|
+
setStore(nextStore);
|
|
291
|
+
}
|
|
292
|
+
else if (updateNonCritical) {
|
|
293
|
+
let nextStore = Object.assign(Object.assign({}, store), { parentOnChange,
|
|
294
|
+
parentOnUnmount,
|
|
295
|
+
tools });
|
|
296
|
+
if (updateState) {
|
|
297
|
+
nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {})));
|
|
298
|
+
}
|
|
299
|
+
setStore(nextStore);
|
|
300
|
+
}
|
|
301
|
+
else if (updateState) {
|
|
302
|
+
setStore(methodOnChange(store, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {}))));
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
exports.updateStore = updateStore;
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./useComponents"), exports);
|
|
5
4
|
tslib_1.__exportStar(require("./useControllerMirror"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./useCreateContext"), exports);
|
|
7
6
|
tslib_1.__exportStar(require("./useDynamicFieldMirror"), exports);
|
|
8
7
|
tslib_1.__exportStar(require("./useDynamicFormsCtx"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./useField"), exports);
|
|
10
8
|
tslib_1.__exportStar(require("./useGenerateRandomValue"), exports);
|
|
11
9
|
tslib_1.__exportStar(require("./useIntegrationFF"), exports);
|
|
12
10
|
tslib_1.__exportStar(require("./useMutateDFState"), exports);
|
|
13
11
|
tslib_1.__exportStar(require("./useMutators"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./useRender"), exports);
|
|
15
12
|
tslib_1.__exportStar(require("./useStore"), exports);
|
|
16
13
|
tslib_1.__exportStar(require("./useStoreValue"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("./useValidate"), exports);
|
|
18
14
|
tslib_1.__exportStar(require("./useMonaco"), exports);
|
|
19
15
|
tslib_1.__exportStar(require("./useSearchStore"), exports);
|
|
20
16
|
tslib_1.__exportStar(require("./useSearchContext"), exports);
|
|
@@ -8,7 +8,27 @@ const useMutators = (externalMutators) => {
|
|
|
8
8
|
const firstRenderRef = react_1.default.useRef(true);
|
|
9
9
|
const [store, setStore] = react_1.default.useState(externalMutators || {});
|
|
10
10
|
const mutateDFState = react_1.default.useCallback((mutators) => {
|
|
11
|
-
|
|
11
|
+
const mergeSpec = (a, b) => {
|
|
12
|
+
const result = lodash_1.default.cloneDeep(a);
|
|
13
|
+
const getKeys = (parent) => {
|
|
14
|
+
if (lodash_1.default.isObjectLike(parent)) {
|
|
15
|
+
return lodash_1.default.keys(parent).reduce((acc, parentKey) => {
|
|
16
|
+
const childKeys = getKeys(parent[parentKey]);
|
|
17
|
+
return [
|
|
18
|
+
...acc,
|
|
19
|
+
...(childKeys.length ? [] : [[parentKey]]),
|
|
20
|
+
...childKeys.map((childKey) => [parentKey, ...childKey]),
|
|
21
|
+
];
|
|
22
|
+
}, []);
|
|
23
|
+
}
|
|
24
|
+
return [];
|
|
25
|
+
};
|
|
26
|
+
getKeys(b).forEach((key) => {
|
|
27
|
+
lodash_1.default.set(result, key, lodash_1.default.get(b, key));
|
|
28
|
+
});
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
setStore((store) => (Object.assign(Object.assign(Object.assign(Object.assign({}, store), (mutators.errors ? { errors: lodash_1.default.merge(store.errors, mutators.errors) } : {})), (mutators.values ? { values: lodash_1.default.merge(store.values, mutators.values) } : {})), (mutators.spec ? { spec: mergeSpec(store.spec || {}, mutators.spec) } : {}))));
|
|
12
32
|
}, [setStore]);
|
|
13
33
|
react_1.default.useEffect(() => {
|
|
14
34
|
if (firstRenderRef.current) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.withGenerateButton = exports.isArrayItem = exports.transformArrOut = exports.transformArrIn = exports.isCorrectConfig = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
6
|
const constants_1 = require("../../../constants");
|
|
@@ -54,7 +54,3 @@ const withGenerateButton = (spec) => (0, helpers_1.isStringSpec)(spec) &&
|
|
|
54
54
|
constants_2.SPEC_TYPE_FOR_GENERATE_BUTTON.includes(spec.viewSpec.type) &&
|
|
55
55
|
spec.viewSpec.generateRandomValueButton;
|
|
56
56
|
exports.withGenerateButton = withGenerateButton;
|
|
57
|
-
const isErrorMutatorCorrect = (errorMutator) => lodash_1.default.isString(errorMutator) || lodash_1.default.isBoolean(errorMutator) || lodash_1.default.isUndefined(errorMutator);
|
|
58
|
-
exports.isErrorMutatorCorrect = isErrorMutatorCorrect;
|
|
59
|
-
const isValueMutatorCorrect = (valueMutator, spec) => typeof valueMutator === spec.type || (lodash_1.default.isArray(valueMutator) && spec.type === constants_1.SpecTypes.Array);
|
|
60
|
-
exports.isValueMutatorCorrect = isValueMutatorCorrect;
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
justify-content: space-between;
|
|
5
5
|
box-sizing: border-box;
|
|
6
6
|
max-width: 750px;
|
|
7
|
-
box-shadow: 0 1px 5px var(--
|
|
7
|
+
box-shadow: 0 1px 5px var(--g-color-sfx-shadow);
|
|
8
8
|
border-radius: 5px;
|
|
9
|
-
color: var(--
|
|
10
|
-
background-color: var(--
|
|
9
|
+
color: var(--g-color-text-primary);
|
|
10
|
+
background-color: var(--g-color-base-float);
|
|
11
11
|
}
|
|
12
12
|
.df-accordeon-card:hover {
|
|
13
|
-
box-shadow: 0 3px 10px var(--
|
|
13
|
+
box-shadow: 0 3px 10px var(--g-color-sfx-shadow);
|
|
14
14
|
}
|
|
15
15
|
.df-accordeon-card:last-child {
|
|
16
16
|
margin-bottom: 0;
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
cursor: pointer;
|
|
34
34
|
}
|
|
35
35
|
.df-accordeon-card__header_open {
|
|
36
|
-
border-bottom: 1px solid var(--
|
|
36
|
+
border-bottom: 1px solid var(--g-color-line-generic);
|
|
37
37
|
}
|
|
38
38
|
.df-accordeon-card__header_without-action:hover {
|
|
39
39
|
cursor: default;
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
}
|
|
59
59
|
.df-accordeon-card__header-content-description {
|
|
60
60
|
margin-top: 12px;
|
|
61
|
-
color: var(--
|
|
61
|
+
color: var(--g-color-text-complementary);
|
|
62
62
|
}
|
|
63
63
|
.df-accordeon-card__header-toggle-btn {
|
|
64
64
|
flex-grow: 0;
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
margin-left: 10px;
|
|
49
49
|
}
|
|
50
50
|
.df-card__title {
|
|
51
|
-
font-size: var(--
|
|
52
|
-
font-weight: var(--
|
|
53
|
-
line-height: var(--
|
|
51
|
+
font-size: var(--g-text-subheader-2-font-size);
|
|
52
|
+
font-weight: var(--g-text-subheader-font-weight);
|
|
53
|
+
line-height: var(--g-text-subheader-2-line-height);
|
|
54
54
|
white-space: nowrap;
|
|
55
55
|
overflow: hidden;
|
|
56
56
|
text-overflow: ellipsis;
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
.df-error-wrapper_error .yc-text-input_view_normal:not(.df-error-wrapper-ignore) .yc-text-input__control,
|
|
18
18
|
.df-error-wrapper_error .yc-text-input_view_normal:not(.df-error-wrapper-ignore) .yc-text-input__content,
|
|
19
19
|
.df-error-wrapper_error .yc-checkbox__indicator:not(.df-error-wrapper-ignore)::before {
|
|
20
|
-
border-color: var(--
|
|
20
|
+
border-color: var(--g-color-text-danger);
|
|
21
21
|
}
|
|
22
22
|
.df-error-wrapper__error-text {
|
|
23
|
-
color: var(--
|
|
23
|
+
color: var(--g-color-text-danger);
|
|
24
24
|
margin-top: 2px;
|
|
25
|
-
font-size: var(--
|
|
26
|
-
line-height: var(--
|
|
25
|
+
font-size: var(--g-text-body-1-font-size);
|
|
26
|
+
line-height: var(--g-text-body-1-line-height);
|
|
27
27
|
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
margin-top: 4px;
|
|
15
15
|
margin-bottom: 20px;
|
|
16
16
|
margin-left: 5px;
|
|
17
|
-
border-left: 1px solid var(--
|
|
17
|
+
border-left: 1px solid var(--g-color-line-generic-accent);
|
|
18
18
|
}
|
|
19
19
|
.df-oneof_base > .df-group-indent > .df-use-search:empty {
|
|
20
20
|
display: none;
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
}
|
|
32
32
|
.df-row__title_required::after {
|
|
33
33
|
content: "*";
|
|
34
|
-
color: var(--
|
|
34
|
+
color: var(--g-color-text-danger);
|
|
35
35
|
}
|
|
36
36
|
.df-row__note {
|
|
37
37
|
padding-right: 16px;
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
}
|
|
59
59
|
.df-row__description {
|
|
60
60
|
margin-top: 10px;
|
|
61
|
-
color: var(--
|
|
61
|
+
color: var(--g-color-text-secondary);
|
|
62
62
|
word-break: break-word;
|
|
63
63
|
}
|
|
64
64
|
.df-row__remove-button {
|
|
65
65
|
margin-left: 5px;
|
|
66
66
|
}
|
|
67
67
|
.df-row__required-mark {
|
|
68
|
-
color: var(--
|
|
68
|
+
color: var(--g-color-text-danger);
|
|
69
69
|
}
|
|
70
70
|
.df-row__error-wrapper {
|
|
71
71
|
min-width: 100%;
|