@gravity-ui/dynamic-forms 3.4.0 → 3.4.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.
Files changed (26) hide show
  1. package/build/cjs/lib/core/components/Form/Controller/Controller.js +4 -4
  2. package/build/cjs/lib/core/components/Form/Controller/utils.js +39 -29
  3. package/build/cjs/lib/core/components/Form/DynamicField.js +3 -3
  4. package/build/cjs/lib/core/components/Form/hooks/useMutators.js +21 -7
  5. package/build/cjs/lib/kit/components/Inputs/TextArea/TextArea.js +1 -1
  6. package/build/cjs/lib/kit/components/Layouts/Row/Row.css +1 -0
  7. package/build/cjs/lib/kit/components/Views/CardOneOfView.js +1 -1
  8. package/build/cjs/lib/kit/components/Views/MultiOneOfView/MultiOneOfView.js +1 -1
  9. package/build/cjs/lib/kit/components/Views/OneOfView/OneOfView.js +1 -1
  10. package/build/cjs/lib/kit/components/Views/TextLinkView/TextLinkView.js +1 -1
  11. package/build/esm/lib/core/components/Form/Controller/Controller.js +4 -4
  12. package/build/esm/lib/core/components/Form/Controller/types.d.ts +6 -6
  13. package/build/esm/lib/core/components/Form/Controller/utils.d.ts +6 -6
  14. package/build/esm/lib/core/components/Form/Controller/utils.js +39 -29
  15. package/build/esm/lib/core/components/Form/DynamicField.js +3 -3
  16. package/build/esm/lib/core/components/Form/hooks/useMutators.d.ts +2 -2
  17. package/build/esm/lib/core/components/Form/hooks/useMutators.js +21 -7
  18. package/build/esm/lib/core/components/Form/types/context.d.ts +2 -2
  19. package/build/esm/lib/core/components/Form/types/mutators.d.ts +11 -0
  20. package/build/esm/lib/kit/components/Inputs/TextArea/TextArea.js +1 -1
  21. package/build/esm/lib/kit/components/Layouts/Row/Row.css +1 -0
  22. package/build/esm/lib/kit/components/Views/CardOneOfView.js +1 -1
  23. package/build/esm/lib/kit/components/Views/MultiOneOfView/MultiOneOfView.js +1 -1
  24. package/build/esm/lib/kit/components/Views/OneOfView/OneOfView.js +1 -1
  25. package/build/esm/lib/kit/components/Views/TextLinkView/TextLinkView.js +1 -1
  26. package/package.json +4 -3
@@ -7,12 +7,12 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const hooks_1 = require("../hooks");
8
8
  const utils_1 = require("./utils");
9
9
  const Controller = ({ spec: _spec, name, value: valueFromParent, parentOnChange, parentOnUnmount, }) => {
10
- const { config, tools, mutators, __mirror } = (0, hooks_1.useDynamicFormsCtx)();
10
+ const { config, tools, mutatorsStore, __mirror } = (0, hooks_1.useDynamicFormsCtx)();
11
11
  const firstRenderRef = react_1.default.useRef(true);
12
12
  const [store, setStore] = react_1.default.useState((0, utils_1.initializeStore)({
13
13
  name,
14
14
  spec: _spec,
15
- mutators,
15
+ mutatorsStore,
16
16
  config,
17
17
  valueFromParent,
18
18
  tools,
@@ -92,7 +92,7 @@ const Controller = ({ spec: _spec, name, value: valueFromParent, parentOnChange,
92
92
  name,
93
93
  parentOnChange,
94
94
  parentOnUnmount,
95
- mutators,
95
+ mutatorsStore,
96
96
  config,
97
97
  tools,
98
98
  methodOnChange: fieldMethods.onChange,
@@ -104,7 +104,7 @@ const Controller = ({ spec: _spec, name, value: valueFromParent, parentOnChange,
104
104
  name,
105
105
  parentOnChange,
106
106
  parentOnUnmount,
107
- mutators,
107
+ mutatorsStore,
108
108
  config,
109
109
  tools.onChange,
110
110
  tools.onUnmount,
@@ -9,10 +9,14 @@ const constants_1 = require("../../../constants");
9
9
  const helpers_1 = require("../../../helpers");
10
10
  const constants_2 = require("../constants");
11
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));
12
+ const isErrorMutatorCorrect = (errorMutator) => errorMutator !== constants_2.EMPTY_MUTATOR &&
13
+ (lodash_1.default.isString(errorMutator.value) ||
14
+ lodash_1.default.isBoolean(errorMutator.value) ||
15
+ lodash_1.default.isUndefined(errorMutator.value));
13
16
  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));
17
+ (typeof valueMutator.value === spec.type ||
18
+ (lodash_1.default.isArray(valueMutator.value) && spec.type === constants_1.SpecTypes.Array) ||
19
+ valueMutator.value === undefined);
16
20
  const updateParentStore = (store) => {
17
21
  (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
22
  };
@@ -21,10 +25,10 @@ const callUnmout = (store) => {
21
25
  (store.parentOnUnmount ? store.parentOnUnmount : store.tools.onUnmount)(store.name);
22
26
  };
23
27
  exports.callUnmout = callUnmout;
24
- const getSpec = ({ name, spec, mutators, }) => {
25
- const mutator = lodash_1.default.get(mutators.spec, name, constants_2.EMPTY_MUTATOR);
28
+ const getSpec = ({ name, spec, mutatorsStore, }) => {
29
+ const mutator = lodash_1.default.get(mutatorsStore.spec, name, constants_2.EMPTY_MUTATOR);
26
30
  if (mutator !== constants_2.EMPTY_MUTATOR) {
27
- const mutatedSpec = lodash_1.default.merge(lodash_1.default.cloneDeep(spec), mutator);
31
+ const mutatedSpec = lodash_1.default.merge(lodash_1.default.cloneDeep(spec), mutator.value);
28
32
  if ((0, helpers_1.isCorrectSpec)(mutatedSpec)) {
29
33
  return mutatedSpec;
30
34
  }
@@ -90,11 +94,11 @@ const getValidate = ({ spec, config, }) => {
90
94
  return validate;
91
95
  };
92
96
  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));
97
+ const getFieldInitials = ({ name, spec, valueFromParent, initialValue, validate, mutatorsStore, }) => {
98
+ const valueMutator = (0, utils_1.transformArrIn)(lodash_1.default.get(mutatorsStore.values, name, constants_2.EMPTY_MUTATOR));
95
99
  let value = lodash_1.default.cloneDeep(valueFromParent);
96
100
  if (isValueMutatorCorrect(valueMutator, spec)) {
97
- value = valueMutator;
101
+ value = valueMutator.value;
98
102
  }
99
103
  if (lodash_1.default.isNil(value)) {
100
104
  if (spec.defaultValue) {
@@ -111,11 +115,11 @@ const getFieldInitials = ({ name, spec, valueFromParent, initialValue, validate,
111
115
  }
112
116
  }
113
117
  }
114
- let errorMutator = lodash_1.default.get(mutators.errors, name, constants_2.EMPTY_MUTATOR);
118
+ let errorMutator = lodash_1.default.get(mutatorsStore.errors, name, constants_2.EMPTY_MUTATOR);
115
119
  if (!isErrorMutatorCorrect(errorMutator)) {
116
- errorMutator = undefined;
120
+ errorMutator = { value: undefined };
117
121
  }
118
- const error = (validate === null || validate === void 0 ? void 0 : validate((0, utils_1.transformArrOut)(value))) || errorMutator;
122
+ const error = (validate === null || validate === void 0 ? void 0 : validate((0, utils_1.transformArrOut)(value))) || (errorMutator === null || errorMutator === void 0 ? void 0 : errorMutator.value);
119
123
  const dirty = !lodash_1.default.isEqual(value, initialValue);
120
124
  return {
121
125
  initialValue,
@@ -209,8 +213,8 @@ const getFieldMethods = () => {
209
213
  };
210
214
  };
211
215
  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 });
216
+ const initializeStore = ({ name, spec: _spec, mutatorsStore, config, valueFromParent, tools, parentOnChange, parentOnUnmount, }) => {
217
+ const spec = (0, exports.getSpec)({ name, spec: _spec, mutatorsStore });
214
218
  const components = (0, exports.getComponents)({ spec, config });
215
219
  const render = (0, exports.getRender)(Object.assign({ name, spec }, components));
216
220
  const validate = (0, exports.getValidate)({ spec, config });
@@ -219,7 +223,7 @@ const initializeStore = ({ name, spec: _spec, mutators, config, valueFromParent,
219
223
  spec,
220
224
  valueFromParent,
221
225
  validate,
222
- mutators,
226
+ mutatorsStore,
223
227
  initialValue: lodash_1.default.get(tools.initialValue, name),
224
228
  });
225
229
  const initialsStore = {
@@ -228,7 +232,7 @@ const initializeStore = ({ name, spec: _spec, mutators, config, valueFromParent,
228
232
  initialSpec: _spec,
229
233
  config,
230
234
  tools,
231
- mutators,
235
+ mutatorsStore,
232
236
  render,
233
237
  validate,
234
238
  parentOnChange,
@@ -241,14 +245,14 @@ const initializeStore = ({ name, spec: _spec, mutators, config, valueFromParent,
241
245
  return initialsStore;
242
246
  };
243
247
  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 })) &&
248
+ const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange, parentOnUnmount, mutatorsStore, valueFromParent, config, tools, methodOnChange, }) => {
249
+ const storeSpecMutator = lodash_1.default.get(store.mutatorsStore.spec, store.name, constants_2.EMPTY_MUTATOR);
250
+ const storeValueMutator = lodash_1.default.get(store.mutatorsStore.values, store.name, constants_2.EMPTY_MUTATOR);
251
+ const storeErrorMutator = lodash_1.default.get(store.mutatorsStore.errors, store.name, constants_2.EMPTY_MUTATOR);
252
+ const specMutator = lodash_1.default.get(mutatorsStore.spec, name, constants_2.EMPTY_MUTATOR);
253
+ const valueMutator = lodash_1.default.get(mutatorsStore.values, name, constants_2.EMPTY_MUTATOR);
254
+ const errorMutator = lodash_1.default.get(mutatorsStore.errors, name, constants_2.EMPTY_MUTATOR);
255
+ const valueMutatorUpdated = isValueMutatorCorrect(valueMutator, (0, exports.getSpec)({ name, spec: _spec, mutatorsStore })) &&
252
256
  valueMutator !== storeValueMutator;
253
257
  const errorMutatorUpdated = isErrorMutatorCorrect(errorMutator) && errorMutator !== storeErrorMutator;
254
258
  const updateState = valueMutatorUpdated || errorMutatorUpdated;
@@ -265,7 +269,7 @@ const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange, paren
265
269
  setStore((0, exports.initializeStore)({
266
270
  name,
267
271
  spec: _spec,
268
- mutators,
272
+ mutatorsStore,
269
273
  config,
270
274
  valueFromParent,
271
275
  tools,
@@ -277,7 +281,7 @@ const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange, paren
277
281
  let nextStore = Object.assign(Object.assign({}, (0, exports.initializeStore)({
278
282
  name,
279
283
  spec: _spec,
280
- mutators,
284
+ mutatorsStore,
281
285
  config,
282
286
  valueFromParent,
283
287
  tools,
@@ -285,7 +289,9 @@ const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange, paren
285
289
  parentOnUnmount,
286
290
  })), { state: store.state });
287
291
  if (updateState) {
288
- nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {})));
292
+ nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator.value : value }, (errorMutatorUpdated
293
+ ? { errorMutator: errorMutator.value }
294
+ : {})));
289
295
  }
290
296
  setStore(nextStore);
291
297
  }
@@ -294,12 +300,16 @@ const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange, paren
294
300
  parentOnUnmount,
295
301
  tools });
296
302
  if (updateState) {
297
- nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {})));
303
+ nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator.value : value }, (errorMutatorUpdated
304
+ ? { errorMutator: errorMutator.value }
305
+ : {})));
298
306
  }
299
307
  setStore(nextStore);
300
308
  }
301
309
  else if (updateState) {
302
- setStore(methodOnChange(store, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {}))));
310
+ setStore(methodOnChange(Object.assign(Object.assign({}, store), { mutatorsStore }), Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator.value : value }, (errorMutatorUpdated
311
+ ? { errorMutator: errorMutator.value }
312
+ : {}))));
303
313
  }
304
314
  };
305
315
  exports.updateStore = updateStore;
@@ -14,7 +14,7 @@ const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search,
14
14
  const SearchContext = (0, hooks_1.useCreateSearchContext)();
15
15
  const { tools, store } = (0, hooks_1.useStore)(name);
16
16
  const watcher = (0, hooks_1.useIntegrationFF)(store, withoutInsertFFDebounce);
17
- const { mutators, mutateDFState } = (0, hooks_1.useMutators)(externalMutators);
17
+ const { mutatorsStore, mutateDFState } = (0, hooks_1.useMutators)(externalMutators);
18
18
  const { store: searchStore, setField, removeField, isHiddenField } = (0, hooks_1.useSearchStore)();
19
19
  const context = react_1.default.useMemo(() => ({
20
20
  config,
@@ -22,9 +22,9 @@ const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search,
22
22
  generateRandomValue,
23
23
  tools: Object.assign(Object.assign({}, tools), { mutateDFState }),
24
24
  store,
25
- mutators,
25
+ mutatorsStore,
26
26
  __mirror,
27
- }), [tools, config, Monaco, __mirror, generateRandomValue, mutators, mutateDFState, store]);
27
+ }), [tools, config, Monaco, __mirror, generateRandomValue, mutatorsStore, mutateDFState, store]);
28
28
  const searchContext = react_1.default.useMemo(() => ({
29
29
  setField,
30
30
  removeField,
@@ -5,10 +5,8 @@ const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const useMutators = (externalMutators) => {
8
- const firstRenderRef = react_1.default.useRef(true);
9
- const [store, setStore] = react_1.default.useState(externalMutators || {});
10
- const mutateDFState = react_1.default.useCallback((mutators) => {
11
- const mergeSpec = (a, b) => {
8
+ const merge = react_1.default.useCallback((mutators, store) => {
9
+ const mergeSpec = (a = {}, b) => {
12
10
  const result = lodash_1.default.cloneDeep(a);
13
11
  const getKeys = (parent) => {
14
12
  if (lodash_1.default.isObjectLike(parent)) {
@@ -24,11 +22,27 @@ const useMutators = (externalMutators) => {
24
22
  return [];
25
23
  };
26
24
  getKeys(b).forEach((key) => {
27
- lodash_1.default.set(result, key, lodash_1.default.get(b, key));
25
+ lodash_1.default.set(result, [key[0], 'value', ...key.slice(1)], lodash_1.default.get(b, key));
26
+ });
27
+ return result;
28
+ };
29
+ const mergeValuesOrErrors = (a = {}, b) => {
30
+ const result = lodash_1.default.cloneDeep(a);
31
+ Object.keys(b).forEach((key) => {
32
+ lodash_1.default.set(result, [key, 'value'], b[key]);
28
33
  });
29
34
  return result;
30
35
  };
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) } : {}))));
36
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, store), (mutators.errors
37
+ ? { errors: mergeValuesOrErrors(store.errors, mutators.errors) }
38
+ : {})), (mutators.values
39
+ ? { values: mergeValuesOrErrors(store.values, mutators.values) }
40
+ : {})), (mutators.spec ? { spec: mergeSpec(store.spec, mutators.spec) } : {}));
41
+ }, []);
42
+ const firstRenderRef = react_1.default.useRef(true);
43
+ const [store, setStore] = react_1.default.useState(merge(externalMutators || {}, {}));
44
+ const mutateDFState = react_1.default.useCallback((mutators) => {
45
+ setStore((store) => merge(mutators, store));
32
46
  }, [setStore]);
33
47
  react_1.default.useEffect(() => {
34
48
  if (firstRenderRef.current) {
@@ -38,6 +52,6 @@ const useMutators = (externalMutators) => {
38
52
  mutateDFState(externalMutators);
39
53
  }
40
54
  }, [externalMutators]);
41
- return { mutators: store, mutateDFState };
55
+ return { mutatorsStore: store, mutateDFState };
42
56
  };
43
57
  exports.useMutators = useMutators;
@@ -6,6 +6,6 @@ const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const uikit_1 = require("@gravity-ui/uikit");
7
7
  const TextArea = ({ name, input, spec }) => {
8
8
  const { value, onBlur, onChange, onFocus } = input;
9
- return (react_1.default.createElement(uikit_1.TextArea, { value: value, onBlur: onBlur, onFocus: onFocus, onUpdate: onChange, maxRows: 20, minRows: 8, hasClear: true, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, qa: name }));
9
+ return (react_1.default.createElement(uikit_1.TextArea, { value: value || '', onBlur: onBlur, onFocus: onFocus, onUpdate: onChange, maxRows: 20, minRows: 8, hasClear: true, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, qa: name }));
10
10
  };
11
11
  exports.TextArea = TextArea;
@@ -55,6 +55,7 @@
55
55
  }
56
56
  .df-row__right-inner {
57
57
  display: flex;
58
+ justify-content: space-around;
58
59
  }
59
60
  .df-row__description {
60
61
  margin-top: 10px;
@@ -23,6 +23,6 @@ const CardOneOfView = (props) => {
23
23
  if (!value || !Object.keys(value).length) {
24
24
  return null;
25
25
  }
26
- return (react_1.default.createElement(__1.Card, { name: name, title: title, open: open, onToggle: onToggle, disableHeaderToggle: true, checkEmptyBody: true }, specProperties[valueKey] ? (react_1.default.createElement(core_1.ViewController, { spec: specProperties[valueKey], name: `${name}.${valueKey}`, key: `${name}.${valueKey}` })) : null));
26
+ return (react_1.default.createElement(__1.Card, { name: name, title: title, open: open, onToggle: onToggle, disableHeaderToggle: true, checkEmptyBody: true }, specProperties[valueKey] ? (react_1.default.createElement(core_1.ViewController, { spec: specProperties[valueKey], name: `${name ? name + '.' : ''}${valueKey}`, key: `${name ? name + '.' : ''}${valueKey}` })) : null));
27
27
  };
28
28
  exports.CardOneOfView = CardOneOfView;
@@ -36,7 +36,7 @@ const MultiOneOfView = (props) => {
36
36
  return (react_1.default.createElement(react_1.default.Fragment, null,
37
37
  selectView,
38
38
  react_1.default.createElement("div", { className: b('content', { flat: withoutIndent, 'multiple-values': items.length > 1 }) },
39
- react_1.default.createElement(GroupIndent_1.GroupIndent, null, values.map((value) => (react_1.default.createElement(react_1.default.Fragment, { key: value }, specProperties && specProperties[value] ? (react_1.default.createElement(core_1.ViewController, { name: `${name}.${value}`, spec: specProperties[value] })) : null)))))));
39
+ react_1.default.createElement(GroupIndent_1.GroupIndent, null, values.map((value) => (react_1.default.createElement(react_1.default.Fragment, { key: value }, specProperties && specProperties[value] ? (react_1.default.createElement(core_1.ViewController, { name: `${name ? name + '.' : ''}${value}`, spec: specProperties[value] })) : null)))))));
40
40
  };
41
41
  exports.MultiOneOfView = MultiOneOfView;
42
42
  const MultiOneOfFlatView = (props) => (react_1.default.createElement(exports.MultiOneOfView, Object.assign({}, props, { withoutIndent: true })));
@@ -31,7 +31,7 @@ const OneOfViewComponent = (props) => {
31
31
  return (react_1.default.createElement("div", { className: b({ flat: props.withoutIndent }) },
32
32
  wrappedValue,
33
33
  specProperties[valueKey] ? (react_1.default.createElement(__1.GroupIndent, null,
34
- react_1.default.createElement(core_1.ViewController, { spec: specProperties[valueKey], name: `${name}.${valueKey}`, key: `${name}.${valueKey}` }))) : null));
34
+ react_1.default.createElement(core_1.ViewController, { spec: specProperties[valueKey], name: `${name ? name + '.' : ''}${valueKey}`, key: `${name ? name + '.' : ''}${valueKey}` }))) : null));
35
35
  };
36
36
  exports.OneOfView = OneOfViewComponent;
37
37
  const OneOfFlatView = (props) => (react_1.default.createElement(OneOfViewComponent, Object.assign({}, props, { withoutIndent: true })));
@@ -22,7 +22,7 @@ const TextLinkView = (_a) => {
22
22
  if (!childSpec || !(value === null || value === void 0 ? void 0 : value.text)) {
23
23
  return null;
24
24
  }
25
- const content = react_1.default.createElement(core_1.ViewController, { spec: childSpec, name: `${name}.${TEXT_LINK_PROPERTY_NAME}` });
25
+ const content = (react_1.default.createElement(core_1.ViewController, { spec: childSpec, name: `${name ? name + '.' : ''}${TEXT_LINK_PROPERTY_NAME}` }));
26
26
  if (Layout) {
27
27
  return (react_1.default.createElement(Layout, Object.assign({ spec: spec, name: name, value: value }, restProps), content));
28
28
  }
@@ -3,12 +3,12 @@ import _ from 'lodash';
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, }) => {
6
- const { config, tools, mutators, __mirror } = useDynamicFormsCtx();
6
+ const { config, tools, mutatorsStore, __mirror } = useDynamicFormsCtx();
7
7
  const firstRenderRef = React.useRef(true);
8
8
  const [store, setStore] = React.useState(initializeStore({
9
9
  name,
10
10
  spec: _spec,
11
- mutators,
11
+ mutatorsStore,
12
12
  config,
13
13
  valueFromParent,
14
14
  tools,
@@ -88,7 +88,7 @@ export const Controller = ({ spec: _spec, name, value: valueFromParent, parentOn
88
88
  name,
89
89
  parentOnChange,
90
90
  parentOnUnmount,
91
- mutators,
91
+ mutatorsStore,
92
92
  config,
93
93
  tools,
94
94
  methodOnChange: fieldMethods.onChange,
@@ -100,7 +100,7 @@ export const Controller = ({ spec: _spec, name, value: valueFromParent, parentOn
100
100
  name,
101
101
  parentOnChange,
102
102
  parentOnUnmount,
103
- mutators,
103
+ mutatorsStore,
104
104
  config,
105
105
  tools.onChange,
106
106
  tools.onUnmount,
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { FormValue, Spec } from '../../../types';
3
- import { DynamicFormConfig, DynamicFormMutators, DynamicFormsContext, FieldRenderProps, FieldValue, IndependentInputEntity, InputEntity, LayoutType, ValidateError } from '../types';
3
+ import { DynamicFormConfig, DynamicFormMutatorsStore, DynamicFormsContext, FieldRenderProps, FieldValue, IndependentInputEntity, InputEntity, LayoutType, ValidateError } from '../types';
4
4
  export interface GetSpecParams<SpecType extends Spec> {
5
5
  name: string;
6
6
  spec: SpecType;
7
- mutators: DynamicFormMutators;
7
+ mutatorsStore: DynamicFormMutatorsStore;
8
8
  }
9
9
  export interface GetComponentsParams<SpecType extends Spec> {
10
10
  spec: SpecType;
@@ -30,7 +30,7 @@ export interface GetFieldInitialsParams<DirtyValue extends FieldValue, Value ext
30
30
  valueFromParent: DirtyValue;
31
31
  initialValue: DirtyValue;
32
32
  validate: (value?: Value) => ValidateError;
33
- mutators: DynamicFormMutators;
33
+ mutatorsStore: DynamicFormMutatorsStore;
34
34
  }
35
35
  export type FieldMethod<DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec, Params extends any = undefined> = (store: ControllerStore<DirtyValue, Value, SpecType>, params: Params) => ControllerStore<DirtyValue, Value, SpecType>;
36
36
  export interface GetFieldMethodsReturn<DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec> {
@@ -49,7 +49,7 @@ export interface GetFieldMethodsReturn<DirtyValue extends FieldValue, Value exte
49
49
  export interface InitializeStoreParams<DirtyValue extends FieldValue, SpecType extends Spec> {
50
50
  name: string;
51
51
  spec: SpecType;
52
- mutators: DynamicFormMutators;
52
+ mutatorsStore: DynamicFormMutatorsStore;
53
53
  config: DynamicFormConfig;
54
54
  valueFromParent: DirtyValue;
55
55
  tools: DynamicFormsContext['tools'];
@@ -62,7 +62,7 @@ export interface ControllerStore<DirtyValue extends FieldValue, Value extends Fo
62
62
  initialSpec: SpecType;
63
63
  config: DynamicFormConfig;
64
64
  tools: DynamicFormsContext['tools'];
65
- mutators: DynamicFormMutators;
65
+ mutatorsStore: DynamicFormMutatorsStore;
66
66
  render: (props: FieldRenderProps<DirtyValue>) => JSX.Element | null;
67
67
  validate: (value?: Value) => ValidateError;
68
68
  parentOnChange: ((childName: string, childValue: FieldValue, childErrors: Record<string, ValidateError>) => void) | null;
@@ -90,7 +90,7 @@ export interface UpdateStoreParams<DirtyValue extends FieldValue, Value extends
90
90
  name: string;
91
91
  parentOnChange: ((childName: string, childValue: FieldValue, childErrors: Record<string, ValidateError>) => void) | null;
92
92
  parentOnUnmount: ((childName: string) => void) | null;
93
- mutators: DynamicFormMutators;
93
+ mutatorsStore: DynamicFormMutatorsStore;
94
94
  valueFromParent: DirtyValue;
95
95
  config: DynamicFormConfig;
96
96
  tools: DynamicFormsContext['tools'];
@@ -1,17 +1,17 @@
1
1
  import { FormValue, Spec } from '../../../types';
2
- import { FieldRenderProps, FieldValue, ValidateError } from '../types';
2
+ import { BaseValidateError, FieldRenderProps, FieldValue, ValidateError } from '../types';
3
3
  import { ControllerStore, GetComponentsParams, GetComponentsReturn, GetFieldInitialsParams, GetFieldMethodsReturn, GetRenderParams, GetSpecParams, GetValidateParams, InitializeStoreParams, UpdateStoreParams } from './types';
4
4
  export declare const updateParentStore: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>(store: ControllerStore<DirtyValue, Value, SpecType>) => void;
5
5
  export declare const callUnmout: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>(store: ControllerStore<DirtyValue, Value, SpecType>) => void;
6
- export declare const getSpec: <SpecType extends Spec>({ name, spec, mutators, }: GetSpecParams<SpecType>) => SpecType;
6
+ export declare const getSpec: <SpecType extends Spec>({ name, spec, mutatorsStore, }: GetSpecParams<SpecType>) => SpecType;
7
7
  export declare const getComponents: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>({ spec, config, }: GetComponentsParams<SpecType>) => GetComponentsReturn<DirtyValue, SpecType>;
8
8
  export declare const getRender: <DirtyValue extends FieldValue, SpecType extends Spec>({ name, spec, inputEntity, Layout, }: GetRenderParams<DirtyValue, SpecType>) => (props: FieldRenderProps<DirtyValue>) => JSX.Element | null;
9
9
  export declare const getValidate: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>({ spec, config, }: GetValidateParams<SpecType>) => (value?: Value | undefined) => ValidateError;
10
- export declare const getFieldInitials: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>({ name, spec, valueFromParent, initialValue, validate, mutators, }: GetFieldInitialsParams<DirtyValue, Value, SpecType>) => {
10
+ export declare const getFieldInitials: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>({ name, spec, valueFromParent, initialValue, validate, mutatorsStore, }: GetFieldInitialsParams<DirtyValue, Value, SpecType>) => {
11
11
  initialValue: DirtyValue;
12
12
  active: boolean;
13
13
  dirty: boolean;
14
- error: string | boolean | import("../types").AsyncValidateError | undefined;
14
+ error: BaseValidateError | import("../types").AsyncValidateError;
15
15
  invalid: boolean;
16
16
  modified: boolean;
17
17
  pristine: boolean;
@@ -22,5 +22,5 @@ export declare const getFieldInitials: <DirtyValue extends FieldValue, Value ext
22
22
  childErrors: {};
23
23
  };
24
24
  export declare const getFieldMethods: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>() => GetFieldMethodsReturn<DirtyValue, Value, SpecType>;
25
- export declare const initializeStore: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>({ name, spec: _spec, mutators, config, valueFromParent, tools, parentOnChange, parentOnUnmount, }: InitializeStoreParams<DirtyValue, SpecType>) => ControllerStore<DirtyValue, Value, SpecType>;
26
- export declare const updateStore: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>({ store, setStore, spec: _spec, name, parentOnChange, parentOnUnmount, mutators, valueFromParent, config, tools, methodOnChange, }: UpdateStoreParams<DirtyValue, Value, SpecType>) => void;
25
+ export declare const initializeStore: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>({ name, spec: _spec, mutatorsStore, config, valueFromParent, tools, parentOnChange, parentOnUnmount, }: InitializeStoreParams<DirtyValue, SpecType>) => ControllerStore<DirtyValue, Value, SpecType>;
26
+ export declare const updateStore: <DirtyValue extends FieldValue, Value extends FormValue, SpecType extends Spec>({ store, setStore, spec: _spec, name, parentOnChange, parentOnUnmount, mutatorsStore, valueFromParent, config, tools, methodOnChange, }: UpdateStoreParams<DirtyValue, Value, SpecType>) => void;
@@ -5,20 +5,24 @@ import { SpecTypes } from '../../../constants';
5
5
  import { isArraySpec, isCorrectSpec, isNumberSpec, isObjectSpec } from '../../../helpers';
6
6
  import { EMPTY_MUTATOR, OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG } from '../constants';
7
7
  import { isArrayItem, isCorrectConfig, transformArrIn, transformArrOut } from '../utils';
8
- const isErrorMutatorCorrect = (errorMutator) => errorMutator !== EMPTY_MUTATOR && (_.isString(errorMutator) || _.isBoolean(errorMutator));
8
+ const isErrorMutatorCorrect = (errorMutator) => errorMutator !== EMPTY_MUTATOR &&
9
+ (_.isString(errorMutator.value) ||
10
+ _.isBoolean(errorMutator.value) ||
11
+ _.isUndefined(errorMutator.value));
9
12
  const isValueMutatorCorrect = (valueMutator, spec) => valueMutator !== EMPTY_MUTATOR &&
10
- (typeof valueMutator === spec.type ||
11
- (_.isArray(valueMutator) && spec.type === SpecTypes.Array));
13
+ (typeof valueMutator.value === spec.type ||
14
+ (_.isArray(valueMutator.value) && spec.type === SpecTypes.Array) ||
15
+ valueMutator.value === undefined);
12
16
  export const updateParentStore = (store) => {
13
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 }));
14
18
  };
15
19
  export const callUnmout = (store) => {
16
20
  (store.parentOnUnmount ? store.parentOnUnmount : store.tools.onUnmount)(store.name);
17
21
  };
18
- export const getSpec = ({ name, spec, mutators, }) => {
19
- const mutator = _.get(mutators.spec, name, EMPTY_MUTATOR);
22
+ export const getSpec = ({ name, spec, mutatorsStore, }) => {
23
+ const mutator = _.get(mutatorsStore.spec, name, EMPTY_MUTATOR);
20
24
  if (mutator !== EMPTY_MUTATOR) {
21
- const mutatedSpec = _.merge(_.cloneDeep(spec), mutator);
25
+ const mutatedSpec = _.merge(_.cloneDeep(spec), mutator.value);
22
26
  if (isCorrectSpec(mutatedSpec)) {
23
27
  return mutatedSpec;
24
28
  }
@@ -80,11 +84,11 @@ export const getValidate = ({ spec, config, }) => {
80
84
  }
81
85
  return validate;
82
86
  };
83
- export const getFieldInitials = ({ name, spec, valueFromParent, initialValue, validate, mutators, }) => {
84
- const valueMutator = transformArrIn(_.get(mutators.values, name, EMPTY_MUTATOR));
87
+ export const getFieldInitials = ({ name, spec, valueFromParent, initialValue, validate, mutatorsStore, }) => {
88
+ const valueMutator = transformArrIn(_.get(mutatorsStore.values, name, EMPTY_MUTATOR));
85
89
  let value = _.cloneDeep(valueFromParent);
86
90
  if (isValueMutatorCorrect(valueMutator, spec)) {
87
- value = valueMutator;
91
+ value = valueMutator.value;
88
92
  }
89
93
  if (_.isNil(value)) {
90
94
  if (spec.defaultValue) {
@@ -101,11 +105,11 @@ export const getFieldInitials = ({ name, spec, valueFromParent, initialValue, va
101
105
  }
102
106
  }
103
107
  }
104
- let errorMutator = _.get(mutators.errors, name, EMPTY_MUTATOR);
108
+ let errorMutator = _.get(mutatorsStore.errors, name, EMPTY_MUTATOR);
105
109
  if (!isErrorMutatorCorrect(errorMutator)) {
106
- errorMutator = undefined;
110
+ errorMutator = { value: undefined };
107
111
  }
108
- const error = (validate === null || validate === void 0 ? void 0 : validate(transformArrOut(value))) || errorMutator;
112
+ const error = (validate === null || validate === void 0 ? void 0 : validate(transformArrOut(value))) || (errorMutator === null || errorMutator === void 0 ? void 0 : errorMutator.value);
109
113
  const dirty = !_.isEqual(value, initialValue);
110
114
  return {
111
115
  initialValue,
@@ -197,8 +201,8 @@ export const getFieldMethods = () => {
197
201
  onItemRemove,
198
202
  };
199
203
  };
200
- export const initializeStore = ({ name, spec: _spec, mutators, config, valueFromParent, tools, parentOnChange, parentOnUnmount, }) => {
201
- const spec = getSpec({ name, spec: _spec, mutators });
204
+ export const initializeStore = ({ name, spec: _spec, mutatorsStore, config, valueFromParent, tools, parentOnChange, parentOnUnmount, }) => {
205
+ const spec = getSpec({ name, spec: _spec, mutatorsStore });
202
206
  const components = getComponents({ spec, config });
203
207
  const render = getRender(Object.assign({ name, spec }, components));
204
208
  const validate = getValidate({ spec, config });
@@ -207,7 +211,7 @@ export const initializeStore = ({ name, spec: _spec, mutators, config, valueFrom
207
211
  spec,
208
212
  valueFromParent,
209
213
  validate,
210
- mutators,
214
+ mutatorsStore,
211
215
  initialValue: _.get(tools.initialValue, name),
212
216
  });
213
217
  const initialsStore = {
@@ -216,7 +220,7 @@ export const initializeStore = ({ name, spec: _spec, mutators, config, valueFrom
216
220
  initialSpec: _spec,
217
221
  config,
218
222
  tools,
219
- mutators,
223
+ mutatorsStore,
220
224
  render,
221
225
  validate,
222
226
  parentOnChange,
@@ -228,14 +232,14 @@ export const initializeStore = ({ name, spec: _spec, mutators, config, valueFrom
228
232
  }
229
233
  return initialsStore;
230
234
  };
231
- export const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange, parentOnUnmount, mutators, valueFromParent, config, tools, methodOnChange, }) => {
232
- const storeSpecMutator = _.get(store.mutators.spec, store.name, EMPTY_MUTATOR);
233
- const storeValueMutator = _.get(store.mutators.values, store.name, EMPTY_MUTATOR);
234
- const storeErrorMutator = _.get(store.mutators.errors, store.name, EMPTY_MUTATOR);
235
- const specMutator = _.get(mutators.spec, name, EMPTY_MUTATOR);
236
- const valueMutator = _.get(mutators.values, name, EMPTY_MUTATOR);
237
- const errorMutator = _.get(mutators.errors, name, EMPTY_MUTATOR);
238
- const valueMutatorUpdated = isValueMutatorCorrect(valueMutator, getSpec({ name, spec: _spec, mutators })) &&
235
+ export const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange, parentOnUnmount, mutatorsStore, valueFromParent, config, tools, methodOnChange, }) => {
236
+ const storeSpecMutator = _.get(store.mutatorsStore.spec, store.name, EMPTY_MUTATOR);
237
+ const storeValueMutator = _.get(store.mutatorsStore.values, store.name, EMPTY_MUTATOR);
238
+ const storeErrorMutator = _.get(store.mutatorsStore.errors, store.name, EMPTY_MUTATOR);
239
+ const specMutator = _.get(mutatorsStore.spec, name, EMPTY_MUTATOR);
240
+ const valueMutator = _.get(mutatorsStore.values, name, EMPTY_MUTATOR);
241
+ const errorMutator = _.get(mutatorsStore.errors, name, EMPTY_MUTATOR);
242
+ const valueMutatorUpdated = isValueMutatorCorrect(valueMutator, getSpec({ name, spec: _spec, mutatorsStore })) &&
239
243
  valueMutator !== storeValueMutator;
240
244
  const errorMutatorUpdated = isErrorMutatorCorrect(errorMutator) && errorMutator !== storeErrorMutator;
241
245
  const updateState = valueMutatorUpdated || errorMutatorUpdated;
@@ -252,7 +256,7 @@ export const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange
252
256
  setStore(initializeStore({
253
257
  name,
254
258
  spec: _spec,
255
- mutators,
259
+ mutatorsStore,
256
260
  config,
257
261
  valueFromParent,
258
262
  tools,
@@ -264,7 +268,7 @@ export const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange
264
268
  let nextStore = Object.assign(Object.assign({}, initializeStore({
265
269
  name,
266
270
  spec: _spec,
267
- mutators,
271
+ mutatorsStore,
268
272
  config,
269
273
  valueFromParent,
270
274
  tools,
@@ -272,7 +276,9 @@ export const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange
272
276
  parentOnUnmount,
273
277
  })), { state: store.state });
274
278
  if (updateState) {
275
- nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {})));
279
+ nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator.value : value }, (errorMutatorUpdated
280
+ ? { errorMutator: errorMutator.value }
281
+ : {})));
276
282
  }
277
283
  setStore(nextStore);
278
284
  }
@@ -281,11 +287,15 @@ export const updateStore = ({ store, setStore, spec: _spec, name, parentOnChange
281
287
  parentOnUnmount,
282
288
  tools });
283
289
  if (updateState) {
284
- nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {})));
290
+ nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator.value : value }, (errorMutatorUpdated
291
+ ? { errorMutator: errorMutator.value }
292
+ : {})));
285
293
  }
286
294
  setStore(nextStore);
287
295
  }
288
296
  else if (updateState) {
289
- setStore(methodOnChange(store, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {}))));
297
+ setStore(methodOnChange(Object.assign(Object.assign({}, store), { mutatorsStore }), Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator.value : value }, (errorMutatorUpdated
298
+ ? { errorMutator: errorMutator.value }
299
+ : {}))));
290
300
  }
291
301
  };
@@ -10,7 +10,7 @@ export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue,
10
10
  const SearchContext = useCreateSearchContext();
11
11
  const { tools, store } = useStore(name);
12
12
  const watcher = useIntegrationFF(store, withoutInsertFFDebounce);
13
- const { mutators, mutateDFState } = useMutators(externalMutators);
13
+ const { mutatorsStore, mutateDFState } = useMutators(externalMutators);
14
14
  const { store: searchStore, setField, removeField, isHiddenField } = useSearchStore();
15
15
  const context = React.useMemo(() => ({
16
16
  config,
@@ -18,9 +18,9 @@ export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue,
18
18
  generateRandomValue,
19
19
  tools: Object.assign(Object.assign({}, tools), { mutateDFState }),
20
20
  store,
21
- mutators,
21
+ mutatorsStore,
22
22
  __mirror,
23
- }), [tools, config, Monaco, __mirror, generateRandomValue, mutators, mutateDFState, store]);
23
+ }), [tools, config, Monaco, __mirror, generateRandomValue, mutatorsStore, mutateDFState, store]);
24
24
  const searchContext = React.useMemo(() => ({
25
25
  setField,
26
26
  removeField,
@@ -1,5 +1,5 @@
1
- import { DynamicFormMutators } from '../types';
1
+ import { DynamicFormMutators, DynamicFormMutatorsStore } from '../types';
2
2
  export declare const useMutators: (externalMutators?: DynamicFormMutators) => {
3
- mutators: DynamicFormMutators;
3
+ mutatorsStore: DynamicFormMutatorsStore;
4
4
  mutateDFState: (mutators: DynamicFormMutators) => void;
5
5
  };
@@ -1,10 +1,8 @@
1
1
  import React from 'react';
2
2
  import _ from 'lodash';
3
3
  export const useMutators = (externalMutators) => {
4
- const firstRenderRef = React.useRef(true);
5
- const [store, setStore] = React.useState(externalMutators || {});
6
- const mutateDFState = React.useCallback((mutators) => {
7
- const mergeSpec = (a, b) => {
4
+ const merge = React.useCallback((mutators, store) => {
5
+ const mergeSpec = (a = {}, b) => {
8
6
  const result = _.cloneDeep(a);
9
7
  const getKeys = (parent) => {
10
8
  if (_.isObjectLike(parent)) {
@@ -20,11 +18,27 @@ export const useMutators = (externalMutators) => {
20
18
  return [];
21
19
  };
22
20
  getKeys(b).forEach((key) => {
23
- _.set(result, key, _.get(b, key));
21
+ _.set(result, [key[0], 'value', ...key.slice(1)], _.get(b, key));
22
+ });
23
+ return result;
24
+ };
25
+ const mergeValuesOrErrors = (a = {}, b) => {
26
+ const result = _.cloneDeep(a);
27
+ Object.keys(b).forEach((key) => {
28
+ _.set(result, [key, 'value'], b[key]);
24
29
  });
25
30
  return result;
26
31
  };
27
- setStore((store) => (Object.assign(Object.assign(Object.assign(Object.assign({}, store), (mutators.errors ? { errors: _.merge(store.errors, mutators.errors) } : {})), (mutators.values ? { values: _.merge(store.values, mutators.values) } : {})), (mutators.spec ? { spec: mergeSpec(store.spec || {}, mutators.spec) } : {}))));
32
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, store), (mutators.errors
33
+ ? { errors: mergeValuesOrErrors(store.errors, mutators.errors) }
34
+ : {})), (mutators.values
35
+ ? { values: mergeValuesOrErrors(store.values, mutators.values) }
36
+ : {})), (mutators.spec ? { spec: mergeSpec(store.spec, mutators.spec) } : {}));
37
+ }, []);
38
+ const firstRenderRef = React.useRef(true);
39
+ const [store, setStore] = React.useState(merge(externalMutators || {}, {}));
40
+ const mutateDFState = React.useCallback((mutators) => {
41
+ setStore((store) => merge(mutators, store));
28
42
  }, [setStore]);
29
43
  React.useEffect(() => {
30
44
  if (firstRenderRef.current) {
@@ -34,5 +48,5 @@ export const useMutators = (externalMutators) => {
34
48
  mutateDFState(externalMutators);
35
49
  }
36
50
  }, [externalMutators]);
37
- return { mutators: store, mutateDFState };
51
+ return { mutatorsStore: store, mutateDFState };
38
52
  };
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { MonacoEditorProps } from 'react-monaco-editor/lib/types';
3
3
  import { StringSpec } from '../../../types';
4
- import { DynamicFieldStore, DynamicFormConfig, DynamicFormMutators, FieldValue, ValidateError, WonderMirror } from './';
4
+ import { DynamicFieldStore, DynamicFormConfig, DynamicFormMutators, DynamicFormMutatorsStore, FieldValue, ValidateError, WonderMirror } from './';
5
5
  export interface DynamicFormsContext {
6
6
  config: DynamicFormConfig;
7
7
  Monaco?: React.ComponentType<MonacoEditorProps>;
@@ -14,6 +14,6 @@ export interface DynamicFormsContext {
14
14
  mutateDFState: (mutators: DynamicFormMutators) => void;
15
15
  };
16
16
  store: DynamicFieldStore;
17
- mutators: DynamicFormMutators;
17
+ mutatorsStore: DynamicFormMutatorsStore;
18
18
  __mirror?: WonderMirror;
19
19
  }
@@ -16,3 +16,14 @@ export interface DynamicFormMutators {
16
16
  values?: Record<string, FormValue>;
17
17
  spec?: Record<string, SpecMutator>;
18
18
  }
19
+ export interface DynamicFormMutatorsStore {
20
+ errors?: Record<string, {
21
+ value: BaseValidateError;
22
+ }>;
23
+ values?: Record<string, {
24
+ value: FormValue;
25
+ }>;
26
+ spec?: Record<string, {
27
+ value: SpecMutator;
28
+ }>;
29
+ }
@@ -2,5 +2,5 @@ import React from 'react';
2
2
  import { TextArea as TextAreaBase } from '@gravity-ui/uikit';
3
3
  export const TextArea = ({ name, input, spec }) => {
4
4
  const { value, onBlur, onChange, onFocus } = input;
5
- return (React.createElement(TextAreaBase, { value: value, onBlur: onBlur, onFocus: onFocus, onUpdate: onChange, maxRows: 20, minRows: 8, hasClear: true, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, qa: name }));
5
+ return (React.createElement(TextAreaBase, { value: value || '', onBlur: onBlur, onFocus: onFocus, onUpdate: onChange, maxRows: 20, minRows: 8, hasClear: true, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, qa: name }));
6
6
  };
@@ -55,6 +55,7 @@
55
55
  }
56
56
  .df-row__right-inner {
57
57
  display: flex;
58
+ justify-content: space-around;
58
59
  }
59
60
  .df-row__description {
60
61
  margin-top: 10px;
@@ -19,5 +19,5 @@ export const CardOneOfView = (props) => {
19
19
  if (!value || !Object.keys(value).length) {
20
20
  return null;
21
21
  }
22
- return (React.createElement(Card, { name: name, title: title, open: open, onToggle: onToggle, disableHeaderToggle: true, checkEmptyBody: true }, specProperties[valueKey] ? (React.createElement(ViewController, { spec: specProperties[valueKey], name: `${name}.${valueKey}`, key: `${name}.${valueKey}` })) : null));
22
+ return (React.createElement(Card, { name: name, title: title, open: open, onToggle: onToggle, disableHeaderToggle: true, checkEmptyBody: true }, specProperties[valueKey] ? (React.createElement(ViewController, { spec: specProperties[valueKey], name: `${name ? name + '.' : ''}${valueKey}`, key: `${name ? name + '.' : ''}${valueKey}` })) : null));
23
23
  };
@@ -33,6 +33,6 @@ export const MultiOneOfView = (props) => {
33
33
  return (React.createElement(React.Fragment, null,
34
34
  selectView,
35
35
  React.createElement("div", { className: b('content', { flat: withoutIndent, 'multiple-values': items.length > 1 }) },
36
- React.createElement(GroupIndent, null, values.map((value) => (React.createElement(React.Fragment, { key: value }, specProperties && specProperties[value] ? (React.createElement(ViewController, { name: `${name}.${value}`, spec: specProperties[value] })) : null)))))));
36
+ React.createElement(GroupIndent, null, values.map((value) => (React.createElement(React.Fragment, { key: value }, specProperties && specProperties[value] ? (React.createElement(ViewController, { name: `${name ? name + '.' : ''}${value}`, spec: specProperties[value] })) : null)))))));
37
37
  };
38
38
  export const MultiOneOfFlatView = (props) => (React.createElement(MultiOneOfView, Object.assign({}, props, { withoutIndent: true })));
@@ -28,7 +28,7 @@ const OneOfViewComponent = (props) => {
28
28
  return (React.createElement("div", { className: b({ flat: props.withoutIndent }) },
29
29
  wrappedValue,
30
30
  specProperties[valueKey] ? (React.createElement(GroupIndent, null,
31
- React.createElement(ViewController, { spec: specProperties[valueKey], name: `${name}.${valueKey}`, key: `${name}.${valueKey}` }))) : null));
31
+ React.createElement(ViewController, { spec: specProperties[valueKey], name: `${name ? name + '.' : ''}${valueKey}`, key: `${name ? name + '.' : ''}${valueKey}` }))) : null));
32
32
  };
33
33
  export const OneOfView = OneOfViewComponent;
34
34
  export const OneOfFlatView = (props) => (React.createElement(OneOfViewComponent, Object.assign({}, props, { withoutIndent: true })));
@@ -19,7 +19,7 @@ export const TextLinkView = (_a) => {
19
19
  if (!childSpec || !(value === null || value === void 0 ? void 0 : value.text)) {
20
20
  return null;
21
21
  }
22
- const content = React.createElement(ViewController, { spec: childSpec, name: `${name}.${TEXT_LINK_PROPERTY_NAME}` });
22
+ const content = (React.createElement(ViewController, { spec: childSpec, name: `${name ? name + '.' : ''}${TEXT_LINK_PROPERTY_NAME}` }));
23
23
  if (Layout) {
24
24
  return (React.createElement(Layout, Object.assign({ spec: spec, name: name, value: value }, restProps), content));
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",
@@ -38,8 +38,9 @@
38
38
  "playwright:install": "playwright install --with-deps",
39
39
  "playwright": "playwright test --config=playwright/playwright.config.ts",
40
40
  "playwright:update": "npm run playwright -- -u",
41
- "playwright:docker": "docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.39.0-jammy /bin/bash -c 'npm ci && npx playwright install && npm run playwright'",
42
- "playwright:docker:update": " docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.39.0-jammy /bin/bash -c 'npm ci && npx playwright install && npm run playwright:update'"
41
+ "playwright:docker": "./scripts/playwright-docker.sh 'npm run playwright'",
42
+ "playwright:docker:update": "./scripts/playwright-docker.sh 'npm run playwright:update'",
43
+ "playwright:docker:clear-cache": "./scripts/playwright-docker.sh clear-cache"
43
44
  },
44
45
  "dependencies": {
45
46
  "@bem-react/classname": "^1.6.0",