@gravity-ui/dynamic-forms 4.0.0 → 4.0.1
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 +2 -2
- package/build/cjs/lib/core/components/Form/Controller/utils.js +45 -34
- package/build/cjs/lib/core/components/Form/DynamicField.js +6 -4
- package/build/cjs/lib/core/components/Form/hooks/useCreateContext.js +2 -2
- package/build/cjs/lib/core/components/Form/hooks/useCreateSearchContext.js +2 -2
- package/build/cjs/lib/core/components/Form/hooks/useIntegrationFF.js +6 -4
- package/build/cjs/lib/core/components/Form/hooks/useMutators.js +11 -7
- package/build/cjs/lib/core/components/Form/hooks/useSearchStore.js +4 -3
- package/build/cjs/lib/core/components/Form/hooks/useStore.js +15 -11
- package/build/cjs/lib/core/components/Form/utils/common.js +14 -11
- package/build/cjs/lib/core/components/View/helpers.js +5 -5
- package/build/cjs/lib/core/components/View/hooks/useComponents.js +2 -2
- package/build/cjs/lib/core/components/View/hooks/useCreateContext.js +2 -2
- package/build/cjs/lib/core/components/View/hooks/useRender.js +4 -3
- package/build/cjs/lib/core/helpers.js +5 -4
- package/build/cjs/lib/kit/components/AccordeonCard/AccordeonCard.js +2 -2
- package/build/cjs/lib/kit/components/Card/Card.js +2 -2
- package/build/cjs/lib/kit/components/GenerateRandomValueButton/GenerateRandomValueButton.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/ArrayBase/ArrayBase.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/MultiOneOf/MultiOneOf.js +4 -3
- package/build/cjs/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +4 -3
- package/build/cjs/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.js +4 -3
- package/build/cjs/lib/kit/components/Inputs/OneOf/OneOf.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/Secret/Secret.js +4 -3
- package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +4 -3
- package/build/cjs/lib/kit/components/Inputs/Text/Text.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/TextContent/TextContent.js +2 -2
- package/build/cjs/lib/kit/components/Inputs/TextLink/TextLink.js +4 -3
- package/build/cjs/lib/kit/components/LazyLoader/LazyLoader.js +2 -2
- package/build/cjs/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.js +2 -2
- package/build/cjs/lib/kit/components/ViewLayouts/ViewAccordeonCard/ViewAccordeonCard.js +2 -2
- package/build/cjs/lib/kit/components/ViewLayouts/ViewCardAccordeon.js +2 -2
- package/build/cjs/lib/kit/components/Views/ArrayBaseView/ArrayBaseView.js +2 -2
- package/build/cjs/lib/kit/components/Views/BaseView/BaseView.js +2 -2
- package/build/cjs/lib/kit/components/Views/CardOneOfView.js +2 -2
- package/build/cjs/lib/kit/components/Views/MultiOneOfView/MultiOneOfView.js +2 -2
- package/build/cjs/lib/kit/components/Views/ObjectBaseView/ObjectBaseView.js +2 -2
- package/build/cjs/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +2 -2
- package/build/cjs/lib/kit/components/Views/OneOfView/OneOfView.js +2 -2
- package/build/cjs/lib/kit/components/Views/TextLinkView/TextLinkView.js +2 -2
- package/build/cjs/lib/kit/hooks/useOneOf/useOneOf.js +5 -4
- package/build/cjs/lib/kit/utils/common.js +30 -25
- package/build/cjs/lib/kit/validators/validators.js +9 -7
- package/build/esm/lib/core/components/Form/Controller/Controller.js +2 -2
- package/build/esm/lib/core/components/Form/Controller/utils.js +45 -34
- package/build/esm/lib/core/components/Form/DynamicField.js +6 -4
- package/build/esm/lib/core/components/Form/hooks/useCreateContext.js +2 -2
- package/build/esm/lib/core/components/Form/hooks/useCreateSearchContext.js +2 -2
- package/build/esm/lib/core/components/Form/hooks/useIntegrationFF.js +6 -4
- package/build/esm/lib/core/components/Form/hooks/useMutators.js +11 -7
- package/build/esm/lib/core/components/Form/hooks/useSearchStore.js +4 -3
- package/build/esm/lib/core/components/Form/hooks/useStore.js +15 -11
- package/build/esm/lib/core/components/Form/utils/common.js +14 -11
- package/build/esm/lib/core/components/View/helpers.js +5 -5
- package/build/esm/lib/core/components/View/hooks/useComponents.js +2 -2
- package/build/esm/lib/core/components/View/hooks/useCreateContext.js +2 -2
- package/build/esm/lib/core/components/View/hooks/useRender.js +4 -3
- package/build/esm/lib/core/helpers.js +5 -4
- package/build/esm/lib/kit/components/AccordeonCard/AccordeonCard.js +2 -2
- package/build/esm/lib/kit/components/Card/Card.js +2 -2
- package/build/esm/lib/kit/components/GenerateRandomValueButton/GenerateRandomValueButton.js +2 -2
- package/build/esm/lib/kit/components/Inputs/ArrayBase/ArrayBase.js +2 -2
- package/build/esm/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +2 -2
- package/build/esm/lib/kit/components/Inputs/MultiOneOf/MultiOneOf.js +4 -3
- package/build/esm/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +4 -3
- package/build/esm/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.js +4 -3
- package/build/esm/lib/kit/components/Inputs/OneOf/OneOf.js +2 -2
- package/build/esm/lib/kit/components/Inputs/Secret/Secret.js +4 -3
- package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.js +4 -3
- package/build/esm/lib/kit/components/Inputs/Text/Text.js +2 -2
- package/build/esm/lib/kit/components/Inputs/TextContent/TextContent.js +2 -2
- package/build/esm/lib/kit/components/Inputs/TextLink/TextLink.js +4 -3
- package/build/esm/lib/kit/components/LazyLoader/LazyLoader.js +2 -2
- package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.js +2 -2
- package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeonCard/ViewAccordeonCard.js +2 -2
- package/build/esm/lib/kit/components/ViewLayouts/ViewCardAccordeon.js +2 -2
- package/build/esm/lib/kit/components/Views/ArrayBaseView/ArrayBaseView.js +2 -2
- package/build/esm/lib/kit/components/Views/BaseView/BaseView.js +2 -2
- package/build/esm/lib/kit/components/Views/CardOneOfView.js +2 -2
- package/build/esm/lib/kit/components/Views/MultiOneOfView/MultiOneOfView.js +2 -2
- package/build/esm/lib/kit/components/Views/ObjectBaseView/ObjectBaseView.js +2 -2
- package/build/esm/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +2 -2
- package/build/esm/lib/kit/components/Views/OneOfView/OneOfView.js +2 -2
- package/build/esm/lib/kit/components/Views/TextLinkView/TextLinkView.js +2 -2
- package/build/esm/lib/kit/hooks/useOneOf/useOneOf.js +5 -4
- package/build/esm/lib/kit/utils/common.js +30 -25
- package/build/esm/lib/kit/validators/validators.js +9 -7
- package/package.json +1 -1
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isCorrectSizeParams = exports.prepareSpec = exports.isNotEmptyValue = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
|
|
6
|
+
const isArray_1 = tslib_1.__importDefault(require("lodash/isArray"));
|
|
7
|
+
const isNil_1 = tslib_1.__importDefault(require("lodash/isNil"));
|
|
8
|
+
const isObject_1 = tslib_1.__importDefault(require("lodash/isObject"));
|
|
9
|
+
const isObjectLike_1 = tslib_1.__importDefault(require("lodash/isObjectLike"));
|
|
10
|
+
const isString_1 = tslib_1.__importDefault(require("lodash/isString"));
|
|
6
11
|
const core_1 = require("../../core");
|
|
7
12
|
const helpers_1 = require("../validators/helpers");
|
|
8
13
|
const bigIntMath_1 = require("./bigIntMath");
|
|
9
14
|
const isNotEmptyValue = (value, spec) => {
|
|
10
15
|
var _a;
|
|
11
|
-
if (
|
|
16
|
+
if ((0, isNil_1.default)(value)) {
|
|
12
17
|
return false;
|
|
13
18
|
}
|
|
14
|
-
if (
|
|
19
|
+
if ((0, isString_1.default)(value)) {
|
|
15
20
|
if (!value) {
|
|
16
21
|
return false;
|
|
17
22
|
}
|
|
@@ -19,7 +24,7 @@ const isNotEmptyValue = (value, spec) => {
|
|
|
19
24
|
return false;
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
|
-
if (
|
|
27
|
+
if ((0, isObject_1.default)(value) && (0, core_1.isObjectSpec)(spec)) {
|
|
23
28
|
const keys = Object.keys(value);
|
|
24
29
|
// the only case when an empty object is considered a non-empty value is when it is a stub for oneof
|
|
25
30
|
if (!keys.filter((key) => { var _a; return (0, exports.isNotEmptyValue)(value[key], (_a = spec.properties) === null || _a === void 0 ? void 0 : _a[key]); }).length &&
|
|
@@ -27,7 +32,7 @@ const isNotEmptyValue = (value, spec) => {
|
|
|
27
32
|
return false;
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
|
-
if (
|
|
35
|
+
if ((0, isArray_1.default)(value) &&
|
|
31
36
|
(0, core_1.isArraySpec)(spec) &&
|
|
32
37
|
!value.filter((item) => (0, exports.isNotEmptyValue)(item, spec.items)).length) {
|
|
33
38
|
return false;
|
|
@@ -37,12 +42,12 @@ const isNotEmptyValue = (value, spec) => {
|
|
|
37
42
|
exports.isNotEmptyValue = isNotEmptyValue;
|
|
38
43
|
const prepareSpec = (spec, parseJsonDefaultValue) => {
|
|
39
44
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
40
|
-
if (
|
|
41
|
-
const result =
|
|
42
|
-
if (
|
|
45
|
+
if ((0, isObjectLike_1.default)(spec)) {
|
|
46
|
+
const result = (0, cloneDeep_1.default)(spec);
|
|
47
|
+
if ((0, isString_1.default)(result.type)) {
|
|
43
48
|
result.type = result.type.toLowerCase();
|
|
44
49
|
}
|
|
45
|
-
if (!
|
|
50
|
+
if (!(0, isNil_1.default)(result.defaultValue)) {
|
|
46
51
|
let _defaultValue = result.defaultValue;
|
|
47
52
|
if (parseJsonDefaultValue) {
|
|
48
53
|
try {
|
|
@@ -53,33 +58,33 @@ const prepareSpec = (spec, parseJsonDefaultValue) => {
|
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
if (typeof _defaultValue === result.type ||
|
|
56
|
-
(
|
|
61
|
+
((0, isArray_1.default)(_defaultValue) && result.type === core_1.SpecTypes.Array)) {
|
|
57
62
|
result.defaultValue = _defaultValue;
|
|
58
63
|
}
|
|
59
64
|
else {
|
|
60
65
|
result.defaultValue = undefined;
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
|
-
if (
|
|
68
|
+
if ((0, isString_1.default)((_a = result.viewSpec) === null || _a === void 0 ? void 0 : _a.type)) {
|
|
64
69
|
result.viewSpec.type = result.viewSpec.type.toLowerCase();
|
|
65
70
|
}
|
|
66
|
-
if (
|
|
71
|
+
if ((0, isString_1.default)((_b = result.viewSpec) === null || _b === void 0 ? void 0 : _b.layout)) {
|
|
67
72
|
result.viewSpec.layout = result.viewSpec.layout.toLowerCase();
|
|
68
73
|
}
|
|
69
|
-
if (
|
|
74
|
+
if ((0, isString_1.default)((_c = result.viewSpec) === null || _c === void 0 ? void 0 : _c.addButtonPosition)) {
|
|
70
75
|
result.viewSpec.addButtonPosition = result.viewSpec.addButtonPosition.toLowerCase();
|
|
71
76
|
}
|
|
72
|
-
if (
|
|
77
|
+
if ((0, isString_1.default)((_d = result.viewSpec) === null || _d === void 0 ? void 0 : _d.themeLabel)) {
|
|
73
78
|
result.viewSpec.textContentParams = Object.assign(Object.assign({}, result.viewSpec.textContentParams), { themeLabel: result.viewSpec.themeLabel.toLowerCase() });
|
|
74
79
|
}
|
|
75
|
-
if (
|
|
80
|
+
if ((0, isString_1.default)((_f = (_e = result.viewSpec) === null || _e === void 0 ? void 0 : _e.oneOfParams) === null || _f === void 0 ? void 0 : _f.toggler)) {
|
|
76
81
|
result.viewSpec.oneOfParams.toggler = result.viewSpec.oneOfParams.toggler.toLowerCase();
|
|
77
82
|
}
|
|
78
|
-
if (
|
|
83
|
+
if ((0, isString_1.default)((_h = (_g = result.viewSpec) === null || _g === void 0 ? void 0 : _g.textContentParams) === null || _h === void 0 ? void 0 : _h.themeLabel)) {
|
|
79
84
|
result.viewSpec.textContentParams.themeLabel =
|
|
80
85
|
result.viewSpec.textContentParams.themeLabel.toLowerCase();
|
|
81
86
|
}
|
|
82
|
-
if (
|
|
87
|
+
if ((0, isString_1.default)(result.validator)) {
|
|
83
88
|
result.validator = result.validator.toLowerCase();
|
|
84
89
|
}
|
|
85
90
|
if (result.maxLength === '0' &&
|
|
@@ -88,10 +93,10 @@ const prepareSpec = (spec, parseJsonDefaultValue) => {
|
|
|
88
93
|
result.minLength = undefined;
|
|
89
94
|
}
|
|
90
95
|
else {
|
|
91
|
-
if (!
|
|
96
|
+
if (!(0, isNil_1.default)(result.maxLength) && (0, helpers_1.isFloat)(`${result.maxLength}`)) {
|
|
92
97
|
result.maxLength = BigInt(result.maxLength);
|
|
93
98
|
}
|
|
94
|
-
if (!
|
|
99
|
+
if (!(0, isNil_1.default)(result.minLength) && (0, helpers_1.isFloat)(`${result.minLength}`)) {
|
|
95
100
|
result.minLength = BigInt(result.minLength);
|
|
96
101
|
}
|
|
97
102
|
}
|
|
@@ -103,17 +108,17 @@ const prepareSpec = (spec, parseJsonDefaultValue) => {
|
|
|
103
108
|
result.minimum = undefined;
|
|
104
109
|
}
|
|
105
110
|
else {
|
|
106
|
-
if (!
|
|
111
|
+
if (!(0, isNil_1.default)(result.maximum) && (0, helpers_1.isFloat)(`${result.maximum}`)) {
|
|
107
112
|
result.maximum = Number(result.maximum);
|
|
108
113
|
}
|
|
109
|
-
if (!
|
|
114
|
+
if (!(0, isNil_1.default)(result.minimum) && (0, helpers_1.isFloat)(`${result.minimum}`)) {
|
|
110
115
|
result.minimum = Number(result.minimum);
|
|
111
116
|
}
|
|
112
117
|
}
|
|
113
|
-
if (
|
|
118
|
+
if ((0, isString_1.default)(result.format)) {
|
|
114
119
|
result.format = result.format.toLowerCase();
|
|
115
120
|
}
|
|
116
|
-
if (
|
|
121
|
+
if ((0, isObjectLike_1.default)(result.properties)) {
|
|
117
122
|
Object.keys(result.properties).forEach((key) => {
|
|
118
123
|
result.properties[key] = (0, exports.prepareSpec)(result.properties[key], parseJsonDefaultValue);
|
|
119
124
|
});
|
|
@@ -126,8 +131,8 @@ exports.prepareSpec = prepareSpec;
|
|
|
126
131
|
const isCorrectSizeParams = (spec) => {
|
|
127
132
|
const { sizeParams } = spec.viewSpec;
|
|
128
133
|
if (!sizeParams ||
|
|
129
|
-
!
|
|
130
|
-
!
|
|
134
|
+
!(0, isString_1.default)(sizeParams.defaultType) ||
|
|
135
|
+
!(0, isObject_1.default)(sizeParams.scale) ||
|
|
131
136
|
!sizeParams.scale[sizeParams.defaultType] ||
|
|
132
137
|
Object.values(sizeParams.scale).some(({ factor }) => !(0, bigIntMath_1.divide)(factor, factor))) {
|
|
133
138
|
return false;
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getStringValidator = exports.getObjectValidator = exports.getNumberValidator = exports.getBooleanValidator = exports.getArrayValidator = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const isArray_1 = tslib_1.__importDefault(require("lodash/isArray"));
|
|
6
|
+
const isNumber_1 = tslib_1.__importDefault(require("lodash/isNumber"));
|
|
7
|
+
const isString_1 = tslib_1.__importDefault(require("lodash/isString"));
|
|
6
8
|
const validators_1 = require("../validators");
|
|
7
9
|
const helpers_1 = require("./helpers");
|
|
8
10
|
const getArrayValidator = (params = {}) => {
|
|
@@ -10,7 +12,7 @@ const getArrayValidator = (params = {}) => {
|
|
|
10
12
|
return (spec, value) => {
|
|
11
13
|
const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
|
|
12
14
|
const valueLength = (value === null || value === void 0 ? void 0 : value.length) || 0;
|
|
13
|
-
if (!ignoreRequiredCheck && spec.required && !
|
|
15
|
+
if (!ignoreRequiredCheck && spec.required && !(0, isArray_1.default)(value)) {
|
|
14
16
|
return errorMessages.REQUIRED;
|
|
15
17
|
}
|
|
16
18
|
if (!ignoreMaxLengthCheck &&
|
|
@@ -69,18 +71,18 @@ const getNumberValidator = (params = {}) => {
|
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
if (!ignoreMaximumCheck &&
|
|
72
|
-
|
|
74
|
+
(0, isNumber_1.default)(spec.maximum) &&
|
|
73
75
|
stringValue.length &&
|
|
74
76
|
Number(stringValue) > spec.maximum) {
|
|
75
77
|
return errorMessages.maxNumber(spec.maximum);
|
|
76
78
|
}
|
|
77
79
|
if (!ignoreMinimumCheck &&
|
|
78
|
-
|
|
80
|
+
(0, isNumber_1.default)(spec.minimum) &&
|
|
79
81
|
stringValue.length &&
|
|
80
82
|
spec.minimum > Number(stringValue)) {
|
|
81
83
|
return errorMessages.minNumber(spec.minimum);
|
|
82
84
|
}
|
|
83
|
-
if (
|
|
85
|
+
if ((0, isString_1.default)(spec.format) && stringValue.length) {
|
|
84
86
|
if (!ignoreIntCheck && spec.format === 'int64' && !(0, helpers_1.isInt)(stringValue)) {
|
|
85
87
|
return errorMessages.INT;
|
|
86
88
|
}
|
|
@@ -127,10 +129,10 @@ const getStringValidator = (params = {}) => {
|
|
|
127
129
|
valueLength < spec.minLength) {
|
|
128
130
|
return errorMessages.minLength(spec.minLength);
|
|
129
131
|
}
|
|
130
|
-
if (
|
|
132
|
+
if ((0, isString_1.default)(spec.pattern) && spec.pattern.length) {
|
|
131
133
|
const regex = new RegExp(spec.pattern);
|
|
132
134
|
if (!ignoreRegExpCheck && !regex.test(value)) {
|
|
133
|
-
return
|
|
135
|
+
return (0, isString_1.default)(spec.patternError) && spec.patternError.length
|
|
134
136
|
? spec.patternError
|
|
135
137
|
: errorMessages.INVALID;
|
|
136
138
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import omit from 'lodash/omit';
|
|
3
3
|
import { useControllerMirror, useDynamicFormsCtx, useSearch } from '../hooks';
|
|
4
4
|
import { callUnmout, getFieldMethods, initializeStore, updateStore } from './utils';
|
|
5
5
|
export const Controller = ({ spec: _spec, name, value: valueFromParent, parentOnChange, parentOnUnmount, }) => {
|
|
@@ -68,7 +68,7 @@ export const Controller = ({ spec: _spec, name, value: valueFromParent, parentOn
|
|
|
68
68
|
onItemRemove: methods.onItemRemove,
|
|
69
69
|
onDrop: methods.onDrop,
|
|
70
70
|
},
|
|
71
|
-
meta: Object.assign(Object.assign({},
|
|
71
|
+
meta: Object.assign(Object.assign({}, omit(store.state, 'value')), { submitFailed: store.tools.submitFailed }),
|
|
72
72
|
}), [methods, store.name, store.state, store.tools.submitFailed]);
|
|
73
73
|
const withSearch = useSearch(store.spec, store.state.value, store.name);
|
|
74
74
|
useControllerMirror(store.name, {
|
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
3
|
+
import get from 'lodash/get';
|
|
4
|
+
import isArray from 'lodash/isArray';
|
|
5
|
+
import isBoolean from 'lodash/isBoolean';
|
|
6
|
+
import isEqual from 'lodash/isEqual';
|
|
7
|
+
import isFunction from 'lodash/isFunction';
|
|
8
|
+
import isNil from 'lodash/isNil';
|
|
9
|
+
import isString from 'lodash/isString';
|
|
10
|
+
import isUndefined from 'lodash/isUndefined';
|
|
11
|
+
import keys from 'lodash/keys';
|
|
12
|
+
import merge from 'lodash/merge';
|
|
13
|
+
import omit from 'lodash/omit';
|
|
3
14
|
import { isValidElementType } from 'react-is';
|
|
4
15
|
import { SpecTypes } from '../../../constants';
|
|
5
16
|
import { isArraySpec, isCorrectSpec, isNumberSpec, isObjectSpec } from '../../../helpers';
|
|
6
17
|
import { EMPTY_MUTATOR, OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG } from '../constants';
|
|
7
18
|
import { isArrayItem, isCorrectConfig, transformArrIn, transformArrOut } from '../utils';
|
|
8
19
|
const isErrorMutatorCorrect = (errorMutator) => errorMutator !== EMPTY_MUTATOR &&
|
|
9
|
-
(
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
(isString(errorMutator.value) ||
|
|
21
|
+
isBoolean(errorMutator.value) ||
|
|
22
|
+
isUndefined(errorMutator.value));
|
|
12
23
|
const isValueMutatorCorrect = (valueMutator, spec) => valueMutator !== EMPTY_MUTATOR &&
|
|
13
24
|
(typeof valueMutator.value === spec.type ||
|
|
14
|
-
(
|
|
25
|
+
(isArray(valueMutator.value) && spec.type === SpecTypes.Array) ||
|
|
15
26
|
valueMutator.value === undefined);
|
|
16
27
|
export const updateParentStore = (store) => {
|
|
17
28
|
(store.parentOnChange ? store.parentOnChange : store.tools.onChange)(store.name, store.state.value, Object.assign(Object.assign({}, store.state.childErrors), { [store.name]: store.state.error }));
|
|
@@ -20,9 +31,9 @@ export const callUnmout = (store) => {
|
|
|
20
31
|
(store.parentOnUnmount ? store.parentOnUnmount : store.tools.onUnmount)(store.name);
|
|
21
32
|
};
|
|
22
33
|
export const getSpec = ({ name, spec, mutatorsStore, }) => {
|
|
23
|
-
const mutator =
|
|
34
|
+
const mutator = get(mutatorsStore.spec, name, EMPTY_MUTATOR);
|
|
24
35
|
if (mutator !== EMPTY_MUTATOR) {
|
|
25
|
-
const mutatedSpec =
|
|
36
|
+
const mutatedSpec = merge(cloneDeep(spec), mutator.value);
|
|
26
37
|
if (isCorrectSpec(mutatedSpec)) {
|
|
27
38
|
return mutatedSpec;
|
|
28
39
|
}
|
|
@@ -39,7 +50,7 @@ export const getComponents = ({ spec, config, }) => {
|
|
|
39
50
|
result.inputEntity = entity;
|
|
40
51
|
}
|
|
41
52
|
}
|
|
42
|
-
if (layouts &&
|
|
53
|
+
if (layouts && isString(spec.viewSpec.layout)) {
|
|
43
54
|
const Component = layouts[spec.viewSpec.layout];
|
|
44
55
|
if (isValidElementType(Component)) {
|
|
45
56
|
result.Layout = Component;
|
|
@@ -50,7 +61,7 @@ export const getComponents = ({ spec, config, }) => {
|
|
|
50
61
|
};
|
|
51
62
|
export const getRender = ({ name, spec, inputEntity, Layout, }) => {
|
|
52
63
|
const render = (props) => {
|
|
53
|
-
if (inputEntity && isCorrectSpec(spec) &&
|
|
64
|
+
if (inputEntity && isCorrectSpec(spec) && isString(name)) {
|
|
54
65
|
if (!spec.viewSpec.hidden) {
|
|
55
66
|
const { layoutProps, inputProps } = spec.viewSpec;
|
|
56
67
|
if (inputEntity.independent) {
|
|
@@ -71,14 +82,14 @@ export const getRender = ({ name, spec, inputEntity, Layout, }) => {
|
|
|
71
82
|
};
|
|
72
83
|
export const getValidate = ({ spec, config, }) => {
|
|
73
84
|
let validate = () => undefined;
|
|
74
|
-
if (isCorrectConfig(config) && isCorrectSpec(spec)) {
|
|
85
|
+
if (isCorrectConfig(config) && isCorrectSpec(spec) && !spec.viewSpec.hidden) {
|
|
75
86
|
const { validators } = config[spec.type];
|
|
76
87
|
if (validators) {
|
|
77
|
-
if ((!
|
|
78
|
-
|
|
88
|
+
if ((!isString(spec.validator) || !spec.validator.length) &&
|
|
89
|
+
isFunction(validators.base)) {
|
|
79
90
|
validate = (value) => validators.base(spec, value);
|
|
80
91
|
}
|
|
81
|
-
if (
|
|
92
|
+
if (isString(spec.validator) && isFunction(validators[spec.validator])) {
|
|
82
93
|
validate = (value) => validators[spec.validator](spec, value);
|
|
83
94
|
}
|
|
84
95
|
}
|
|
@@ -86,12 +97,12 @@ export const getValidate = ({ spec, config, }) => {
|
|
|
86
97
|
return validate;
|
|
87
98
|
};
|
|
88
99
|
export const getFieldInitials = ({ name, spec, valueFromParent, initialValue, validate, mutatorsStore, }) => {
|
|
89
|
-
const valueMutator = transformArrIn(
|
|
90
|
-
let value =
|
|
100
|
+
const valueMutator = transformArrIn(get(mutatorsStore.values, name, EMPTY_MUTATOR));
|
|
101
|
+
let value = cloneDeep(valueFromParent);
|
|
91
102
|
if (isValueMutatorCorrect(valueMutator, spec)) {
|
|
92
103
|
value = valueMutator.value;
|
|
93
104
|
}
|
|
94
|
-
if (
|
|
105
|
+
if (isNil(value)) {
|
|
95
106
|
if (spec.defaultValue) {
|
|
96
107
|
value = transformArrIn(spec.defaultValue);
|
|
97
108
|
}
|
|
@@ -106,12 +117,12 @@ export const getFieldInitials = ({ name, spec, valueFromParent, initialValue, va
|
|
|
106
117
|
}
|
|
107
118
|
}
|
|
108
119
|
}
|
|
109
|
-
let errorMutator =
|
|
120
|
+
let errorMutator = get(mutatorsStore.errors, name, EMPTY_MUTATOR);
|
|
110
121
|
if (!isErrorMutatorCorrect(errorMutator)) {
|
|
111
122
|
errorMutator = { value: undefined };
|
|
112
123
|
}
|
|
113
124
|
const error = (validate === null || validate === void 0 ? void 0 : validate(transformArrOut(value))) || (errorMutator === null || errorMutator === void 0 ? void 0 : errorMutator.value);
|
|
114
|
-
const dirty = !
|
|
125
|
+
const dirty = !isEqual(value, initialValue);
|
|
115
126
|
return {
|
|
116
127
|
initialValue,
|
|
117
128
|
active: false,
|
|
@@ -130,7 +141,7 @@ export const getFieldInitials = ({ name, spec, valueFromParent, initialValue, va
|
|
|
130
141
|
export const getFieldMethods = () => {
|
|
131
142
|
const onChange = (store, { valOrSetter, childErrors, errorMutator }) => {
|
|
132
143
|
const { state, validate, spec } = store;
|
|
133
|
-
const _value =
|
|
144
|
+
const _value = isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
|
|
134
145
|
const error = (validate === null || validate === void 0 ? void 0 : validate(transformArrOut(_value))) || errorMutator;
|
|
135
146
|
let value = transformArrIn(_value);
|
|
136
147
|
if (isNumberSpec(spec) && !error) {
|
|
@@ -138,13 +149,13 @@ export const getFieldMethods = () => {
|
|
|
138
149
|
}
|
|
139
150
|
let newChildErrors = Object.assign({}, state.childErrors);
|
|
140
151
|
if (childErrors) {
|
|
141
|
-
const nearestChildName =
|
|
152
|
+
const nearestChildName = keys(childErrors).sort((a, b) => a.length - b.length)[0];
|
|
142
153
|
if (nearestChildName) {
|
|
143
|
-
const existingСhildNames =
|
|
144
|
-
newChildErrors = Object.assign(Object.assign({},
|
|
154
|
+
const existingСhildNames = keys(newChildErrors).filter((childName) => childName.startsWith(nearestChildName));
|
|
155
|
+
newChildErrors = Object.assign(Object.assign({}, omit(newChildErrors, existingСhildNames)), childErrors);
|
|
145
156
|
}
|
|
146
157
|
}
|
|
147
|
-
const nextStore = Object.assign(Object.assign({}, store), { state: Object.assign(Object.assign({}, store.state), { dirty: !
|
|
158
|
+
const nextStore = Object.assign(Object.assign({}, store), { state: Object.assign(Object.assign({}, store.state), { dirty: !isEqual(value, state.initialValue), error, invalid: Boolean(error), modified: true, pristine: value === state.initialValue, touched: true, valid: !error, value, visited: true, childErrors: newChildErrors }) });
|
|
148
159
|
nextStore.afterStoreUpdateCB = () => updateParentStore(nextStore);
|
|
149
160
|
return nextStore;
|
|
150
161
|
};
|
|
@@ -170,7 +181,7 @@ export const getFieldMethods = () => {
|
|
|
170
181
|
if (isArraySpec(spec) || isObjectSpec(spec)) {
|
|
171
182
|
return onChange(store, {
|
|
172
183
|
valOrSetter: (currentValue) => currentValue
|
|
173
|
-
?
|
|
184
|
+
? omit(currentValue, childName.split(`${name}.`)[1])
|
|
174
185
|
: currentValue,
|
|
175
186
|
childErrors: { [childName]: false },
|
|
176
187
|
});
|
|
@@ -185,7 +196,7 @@ export const getFieldMethods = () => {
|
|
|
185
196
|
});
|
|
186
197
|
const value = Object.assign(Object.assign({}, stateValue), { [`<${stateValue[OBJECT_ARRAY_CNT]}>`]: transformArrIn(_value), [OBJECT_ARRAY_CNT]: stateValue[OBJECT_ARRAY_CNT] + 1 });
|
|
187
198
|
const error = validate === null || validate === void 0 ? void 0 : validate(transformArrOut(value));
|
|
188
|
-
const nextStore = Object.assign(Object.assign({}, store), { state: Object.assign(Object.assign({}, store.state), { dirty: !
|
|
199
|
+
const nextStore = Object.assign(Object.assign({}, store), { state: Object.assign(Object.assign({}, store.state), { dirty: !isEqual(value, store.state.initialValue), error, invalid: Boolean(error), modified: true, pristine: value === store.state.initialValue, touched: true, valid: !error, value, visited: true }) });
|
|
189
200
|
nextStore.afterStoreUpdateCB = () => updateParentStore(nextStore);
|
|
190
201
|
return nextStore;
|
|
191
202
|
};
|
|
@@ -213,7 +224,7 @@ export const initializeStore = ({ name, spec: _spec, mutatorsStore, config, valu
|
|
|
213
224
|
valueFromParent,
|
|
214
225
|
validate,
|
|
215
226
|
mutatorsStore,
|
|
216
|
-
initialValue:
|
|
227
|
+
initialValue: get(tools.initialValue, name),
|
|
217
228
|
});
|
|
218
229
|
const initialsStore = {
|
|
219
230
|
name,
|
|
@@ -228,18 +239,18 @@ export const initializeStore = ({ name, spec: _spec, mutatorsStore, config, valu
|
|
|
228
239
|
parentOnUnmount,
|
|
229
240
|
state,
|
|
230
241
|
};
|
|
231
|
-
if (!
|
|
242
|
+
if (!isEqual(valueFromParent, state.value) || state.error) {
|
|
232
243
|
initialsStore.afterStoreUpdateCB = () => updateParentStore(initialsStore);
|
|
233
244
|
}
|
|
234
245
|
return initialsStore;
|
|
235
246
|
};
|
|
236
247
|
export const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange, parentOnUnmount, mutatorsStore, valueFromParent, config, tools, methodOnChange, }) => {
|
|
237
|
-
const storeSpecMutator =
|
|
238
|
-
const storeValueMutator =
|
|
239
|
-
const storeErrorMutator =
|
|
240
|
-
const specMutator =
|
|
241
|
-
const valueMutator =
|
|
242
|
-
const errorMutator =
|
|
248
|
+
const storeSpecMutator = get(store.mutatorsStore.spec, store.name, EMPTY_MUTATOR);
|
|
249
|
+
const storeValueMutator = get(store.mutatorsStore.values, store.name, EMPTY_MUTATOR);
|
|
250
|
+
const storeErrorMutator = get(store.mutatorsStore.errors, store.name, EMPTY_MUTATOR);
|
|
251
|
+
const specMutator = get(mutatorsStore.spec, name, EMPTY_MUTATOR);
|
|
252
|
+
const valueMutator = get(mutatorsStore.values, name, EMPTY_MUTATOR);
|
|
253
|
+
const errorMutator = get(mutatorsStore.errors, name, EMPTY_MUTATOR);
|
|
243
254
|
const valueMutatorUpdated = isValueMutatorCorrect(valueMutator, getSpec({ name, spec: _spec, mutatorsStore })) &&
|
|
244
255
|
valueMutator !== storeValueMutator;
|
|
245
256
|
const errorMutatorUpdated = isErrorMutatorCorrect(errorMutator) && errorMutator !== storeErrorMutator;
|
|
@@ -248,7 +259,7 @@ export const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange
|
|
|
248
259
|
parentOnUnmount !== store.parentOnUnmount ||
|
|
249
260
|
tools.onChange !== store.tools.onChange ||
|
|
250
261
|
tools.onUnmount !== store.tools.onUnmount;
|
|
251
|
-
const updateAllStore = !
|
|
262
|
+
const updateAllStore = !isEqual(_spec, store.initialSpec) ||
|
|
252
263
|
config !== store.config ||
|
|
253
264
|
(specMutator !== EMPTY_MUTATOR && specMutator !== storeSpecMutator);
|
|
254
265
|
const updateAllStoreAndClearParentValues = name !== store.name;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import isFunction from 'lodash/isFunction';
|
|
3
|
+
import isString from 'lodash/isString';
|
|
4
|
+
import get from 'lodash/get';
|
|
3
5
|
import { isValidElementType } from 'react-is';
|
|
4
6
|
import { isCorrectSpec } from '../../helpers';
|
|
5
7
|
import { Controller } from './Controller';
|
|
@@ -25,9 +27,9 @@ export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue,
|
|
|
25
27
|
setField,
|
|
26
28
|
removeField,
|
|
27
29
|
isHiddenField,
|
|
28
|
-
searchFunction:
|
|
30
|
+
searchFunction: isFunction(search) ? search : getDefaultSearchFunction(search),
|
|
29
31
|
}), [isHiddenField, removeField, search, setField]);
|
|
30
|
-
const correctParams = React.useMemo(() =>
|
|
32
|
+
const correctParams = React.useMemo(() => isString(name) && isCorrectSpec(spec) && isCorrectConfig(config), [name, spec, config]);
|
|
31
33
|
useDynamicFieldMirror({
|
|
32
34
|
useStore: { tools, store },
|
|
33
35
|
useIntegrationFF: watcher,
|
|
@@ -36,7 +38,7 @@ export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue,
|
|
|
36
38
|
if (correctParams) {
|
|
37
39
|
return (React.createElement(DynamicFormsCtx.Provider, { value: context },
|
|
38
40
|
React.createElement(SearchContext.Provider, { value: searchContext },
|
|
39
|
-
React.createElement(Controller, { spec: spec, name: name, parentOnChange: null, parentOnUnmount: null, value:
|
|
41
|
+
React.createElement(Controller, { spec: spec, name: name, parentOnChange: null, parentOnUnmount: null, value: get(store.values, name) }),
|
|
40
42
|
watcher)));
|
|
41
43
|
}
|
|
42
44
|
return null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
const createContext =
|
|
2
|
+
import once from 'lodash/once';
|
|
3
|
+
const createContext = once(() => React.createContext({}));
|
|
4
4
|
export const useCreateSearchContext = () => createContext();
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import _ from 'lodash';
|
|
3
2
|
import debounce from 'lodash/debounce';
|
|
3
|
+
import get from 'lodash/get';
|
|
4
|
+
import isFunction from 'lodash/isFunction';
|
|
5
|
+
import values from 'lodash/values';
|
|
4
6
|
import { Field as FinalFormField, useForm } from 'react-final-form';
|
|
5
7
|
import { transformArrOut } from '../utils';
|
|
6
8
|
export const useIntegrationFF = (store, withoutDebounce) => {
|
|
@@ -13,9 +15,9 @@ export const useIntegrationFF = (store, withoutDebounce) => {
|
|
|
13
15
|
validate: () => {
|
|
14
16
|
const asyncErrors = [];
|
|
15
17
|
let error;
|
|
16
|
-
|
|
18
|
+
values(store.errors).forEach((err) => {
|
|
17
19
|
if (err) {
|
|
18
|
-
if (
|
|
20
|
+
if (isFunction(err === null || err === void 0 ? void 0 : err.then)) {
|
|
19
21
|
asyncErrors.push(err);
|
|
20
22
|
}
|
|
21
23
|
else {
|
|
@@ -34,7 +36,7 @@ export const useIntegrationFF = (store, withoutDebounce) => {
|
|
|
34
36
|
const change = React.useMemo(() => {
|
|
35
37
|
const cb = (value) => {
|
|
36
38
|
if (store.name) {
|
|
37
|
-
form.change(store.name,
|
|
39
|
+
form.change(store.name, get(transformArrOut(value), store.name));
|
|
38
40
|
}
|
|
39
41
|
};
|
|
40
42
|
if (withoutDebounce) {
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
3
|
+
import get from 'lodash/get';
|
|
4
|
+
import isObjectLike from 'lodash/isObjectLike';
|
|
5
|
+
import keys from 'lodash/keys';
|
|
6
|
+
import set from 'lodash/set';
|
|
3
7
|
export const useMutators = (externalMutators) => {
|
|
4
8
|
const merge = React.useCallback((mutators, store) => {
|
|
5
9
|
const mergeSpec = (a = {}, b) => {
|
|
6
|
-
const result =
|
|
10
|
+
const result = cloneDeep(a);
|
|
7
11
|
const getKeys = (parent) => {
|
|
8
|
-
if (
|
|
9
|
-
return
|
|
12
|
+
if (isObjectLike(parent)) {
|
|
13
|
+
return keys(parent).reduce((acc, parentKey) => {
|
|
10
14
|
const childKeys = getKeys(parent[parentKey]);
|
|
11
15
|
return [
|
|
12
16
|
...acc,
|
|
@@ -18,14 +22,14 @@ export const useMutators = (externalMutators) => {
|
|
|
18
22
|
return [];
|
|
19
23
|
};
|
|
20
24
|
getKeys(b).forEach((key) => {
|
|
21
|
-
|
|
25
|
+
set(result, [key[0], 'value', ...key.slice(1)], get(b, key));
|
|
22
26
|
});
|
|
23
27
|
return result;
|
|
24
28
|
};
|
|
25
29
|
const mergeValuesOrErrors = (a = {}, b) => {
|
|
26
|
-
const result =
|
|
30
|
+
const result = cloneDeep(a);
|
|
27
31
|
Object.keys(b).forEach((key) => {
|
|
28
|
-
|
|
32
|
+
set(result, [key, 'value'], b[key]);
|
|
29
33
|
});
|
|
30
34
|
return result;
|
|
31
35
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import isUndefined from 'lodash/isUndefined';
|
|
3
|
+
import omit from 'lodash/omit';
|
|
3
4
|
import { getParentName } from '../';
|
|
4
5
|
export const useSearchStore = () => {
|
|
5
6
|
const [store, setStore] = React.useState({});
|
|
@@ -20,7 +21,7 @@ export const useSearchStore = () => {
|
|
|
20
21
|
return false;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
|
-
if (
|
|
24
|
+
if (isUndefined(selfFlag)) {
|
|
24
25
|
return false;
|
|
25
26
|
}
|
|
26
27
|
return true;
|
|
@@ -29,7 +30,7 @@ export const useSearchStore = () => {
|
|
|
29
30
|
store,
|
|
30
31
|
setField: (name, search) => setStore((store) => (Object.assign(Object.assign({}, store), { [name]: search }))),
|
|
31
32
|
removeField: (name) => {
|
|
32
|
-
setStore((store) =>
|
|
33
|
+
setStore((store) => omit(store, name));
|
|
33
34
|
},
|
|
34
35
|
isHiddenField,
|
|
35
36
|
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import clone from 'lodash/clone';
|
|
3
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
4
|
+
import get from 'lodash/get';
|
|
5
|
+
import omit from 'lodash/omit';
|
|
6
|
+
import set from 'lodash/set';
|
|
3
7
|
import { useFormState } from 'react-final-form';
|
|
4
8
|
import { transformArrIn } from '../utils';
|
|
5
9
|
export const useStore = (name) => {
|
|
@@ -7,37 +11,37 @@ export const useStore = (name) => {
|
|
|
7
11
|
const firstRenderRef = React.useRef(true);
|
|
8
12
|
const [store, setStore] = React.useState(() => {
|
|
9
13
|
const values = transformArrIn({
|
|
10
|
-
[name]:
|
|
14
|
+
[name]: get(formState.values, name),
|
|
11
15
|
});
|
|
12
16
|
const initialValue = transformArrIn({
|
|
13
|
-
[name]:
|
|
17
|
+
[name]: get(formState.initialValues, name),
|
|
14
18
|
});
|
|
15
19
|
return {
|
|
16
20
|
name,
|
|
17
|
-
initialValue:
|
|
18
|
-
values:
|
|
21
|
+
initialValue: cloneDeep(initialValue),
|
|
22
|
+
values: cloneDeep(values),
|
|
19
23
|
errors: {},
|
|
20
24
|
};
|
|
21
25
|
});
|
|
22
26
|
const submitFailed = formState.submitFailed;
|
|
23
27
|
const tools = React.useMemo(() => ({
|
|
24
28
|
initialValue: store.initialValue,
|
|
25
|
-
onChange: (name, value, errors) => setStore((store) => (Object.assign(Object.assign({}, store), { values:
|
|
26
|
-
onUnmount: (name) => setStore((store) => (Object.assign(Object.assign({}, store), { values:
|
|
29
|
+
onChange: (name, value, errors) => setStore((store) => (Object.assign(Object.assign({}, store), { values: set(Object.assign({}, store.values), name, clone(value)), errors: errors || {} }))),
|
|
30
|
+
onUnmount: (name) => setStore((store) => (Object.assign(Object.assign({}, store), { values: omit(store.values, name), errors: omit(store.errors, Object.keys(store.errors).filter((key) => key.startsWith(name))) }))),
|
|
27
31
|
submitFailed,
|
|
28
32
|
}), [store.initialValue, setStore, submitFailed]);
|
|
29
33
|
React.useEffect(() => {
|
|
30
34
|
if (!firstRenderRef.current) {
|
|
31
35
|
const values = transformArrIn({
|
|
32
|
-
[name]:
|
|
36
|
+
[name]: get(formState.values, name),
|
|
33
37
|
});
|
|
34
38
|
const initialValue = transformArrIn({
|
|
35
|
-
[name]:
|
|
39
|
+
[name]: get(formState.initialValues, name),
|
|
36
40
|
});
|
|
37
41
|
setStore({
|
|
38
42
|
name: name,
|
|
39
|
-
initialValue:
|
|
40
|
-
values:
|
|
43
|
+
initialValue: cloneDeep(initialValue),
|
|
44
|
+
values: cloneDeep(values),
|
|
41
45
|
errors: {},
|
|
42
46
|
});
|
|
43
47
|
}
|