@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.
Files changed (79) hide show
  1. package/build/cjs/lib/core/components/Form/Controller/Controller.js +120 -0
  2. package/build/cjs/lib/core/components/Form/Controller/index.js +4 -0
  3. package/build/cjs/lib/core/components/Form/Controller/types.js +2 -0
  4. package/build/cjs/lib/core/components/Form/Controller/utils.js +305 -0
  5. package/build/cjs/lib/core/components/Form/hooks/index.js +0 -4
  6. package/build/cjs/lib/core/components/Form/hooks/useMutators.js +21 -1
  7. package/build/cjs/lib/core/components/Form/utils/common.js +1 -5
  8. package/build/cjs/lib/kit/components/AccordeonCard/AccordeonCard.css +6 -6
  9. package/build/cjs/lib/kit/components/Card/Card.css +3 -3
  10. package/build/cjs/lib/kit/components/ErrorWrapper/ErrorWrapper.css +4 -4
  11. package/build/cjs/lib/kit/components/GroupIndent/GroupIndent.css +1 -1
  12. package/build/cjs/lib/kit/components/Inputs/FileInput/FileInput.css +1 -1
  13. package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoHeader.css +1 -1
  14. package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoInputBase.css +1 -1
  15. package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.css +1 -1
  16. package/build/cjs/lib/kit/components/Inputs/OneOf/OneOf.css +1 -1
  17. package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.css +1 -1
  18. package/build/cjs/lib/kit/components/Layouts/Row/Row.css +3 -3
  19. package/build/cjs/lib/kit/components/LongValue/LongValue.css +1 -1
  20. package/build/cjs/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.css +4 -4
  21. package/build/cjs/lib/kit/components/ViewLayouts/ViewRow/ViewRow.css +2 -2
  22. package/build/cjs/lib/kit/components/Views/MonacoInputView/MonacoBaseView.css +1 -1
  23. package/build/cjs/lib/kit/components/Views/MonacoInputView/MonacoViewDialog.css +1 -1
  24. package/build/cjs/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +1 -1
  25. package/build/cjs/lib/kit/validators/types.js +2 -0
  26. package/build/cjs/lib/kit/validators/validators.js +32 -25
  27. package/build/esm/lib/core/components/Form/Controller/Controller.d.ts +10 -0
  28. package/build/esm/lib/core/components/Form/Controller/Controller.js +115 -0
  29. package/build/esm/lib/core/components/Form/Controller/index.d.ts +1 -0
  30. package/build/esm/lib/core/components/Form/Controller/index.js +1 -0
  31. package/build/esm/lib/core/components/Form/Controller/types.d.ts +98 -0
  32. package/build/esm/lib/core/components/Form/Controller/types.js +1 -0
  33. package/build/esm/lib/core/components/Form/Controller/utils.d.ts +26 -0
  34. package/build/esm/lib/core/components/Form/Controller/utils.js +291 -0
  35. package/build/esm/lib/core/components/Form/hooks/index.d.ts +0 -4
  36. package/build/esm/lib/core/components/Form/hooks/index.js +0 -4
  37. package/build/esm/lib/core/components/Form/hooks/useMutators.js +21 -1
  38. package/build/esm/lib/core/components/Form/types/mirror.d.ts +3 -5
  39. package/build/esm/lib/core/components/Form/types/mutators.d.ts +13 -2
  40. package/build/esm/lib/core/components/Form/utils/common.d.ts +0 -3
  41. package/build/esm/lib/core/components/Form/utils/common.js +0 -2
  42. package/build/esm/lib/kit/components/AccordeonCard/AccordeonCard.css +6 -6
  43. package/build/esm/lib/kit/components/Card/Card.css +3 -3
  44. package/build/esm/lib/kit/components/ErrorWrapper/ErrorWrapper.css +4 -4
  45. package/build/esm/lib/kit/components/GroupIndent/GroupIndent.css +1 -1
  46. package/build/esm/lib/kit/components/Inputs/FileInput/FileInput.css +1 -1
  47. package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoHeader.css +1 -1
  48. package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoInputBase.css +1 -1
  49. package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.css +1 -1
  50. package/build/esm/lib/kit/components/Inputs/OneOf/OneOf.css +1 -1
  51. package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.css +1 -1
  52. package/build/esm/lib/kit/components/Layouts/Row/Row.css +3 -3
  53. package/build/esm/lib/kit/components/LongValue/LongValue.css +1 -1
  54. package/build/esm/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.css +4 -4
  55. package/build/esm/lib/kit/components/ViewLayouts/ViewRow/ViewRow.css +2 -2
  56. package/build/esm/lib/kit/components/Views/MonacoInputView/MonacoBaseView.css +1 -1
  57. package/build/esm/lib/kit/components/Views/MonacoInputView/MonacoViewDialog.css +1 -1
  58. package/build/esm/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +1 -1
  59. package/build/esm/lib/kit/validators/messages.d.ts +2 -16
  60. package/build/esm/lib/kit/validators/types.d.ts +16 -0
  61. package/build/esm/lib/kit/validators/types.js +1 -0
  62. package/build/esm/lib/kit/validators/validators.d.ts +10 -9
  63. package/build/esm/lib/kit/validators/validators.js +32 -25
  64. package/package.json +10 -2
  65. package/build/cjs/lib/core/components/Form/Controller.js +0 -42
  66. package/build/cjs/lib/core/components/Form/hooks/useComponents.js +0 -40
  67. package/build/cjs/lib/core/components/Form/hooks/useField.js +0 -176
  68. package/build/cjs/lib/core/components/Form/hooks/useRender.js +0 -28
  69. package/build/cjs/lib/core/components/Form/hooks/useValidate.js +0 -32
  70. package/build/esm/lib/core/components/Form/Controller.d.ts +0 -10
  71. package/build/esm/lib/core/components/Form/Controller.js +0 -37
  72. package/build/esm/lib/core/components/Form/hooks/useComponents.d.ts +0 -6
  73. package/build/esm/lib/core/components/Form/hooks/useComponents.js +0 -35
  74. package/build/esm/lib/core/components/Form/hooks/useField.d.ts +0 -14
  75. package/build/esm/lib/core/components/Form/hooks/useField.js +0 -171
  76. package/build/esm/lib/core/components/Form/hooks/useRender.d.ts +0 -9
  77. package/build/esm/lib/core/components/Form/hooks/useRender.js +0 -23
  78. package/build/esm/lib/core/components/Form/hooks/useValidate.d.ts +0 -3
  79. package/build/esm/lib/core/components/Form/hooks/useValidate.js +0 -27
@@ -0,0 +1,291 @@
1
+ import React from 'react';
2
+ import _ from 'lodash';
3
+ import { isValidElementType } from 'react-is';
4
+ import { SpecTypes } from '../../../constants';
5
+ import { isArraySpec, isCorrectSpec, isNumberSpec, isObjectSpec } from '../../../helpers';
6
+ import { EMPTY_MUTATOR, OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG } from '../constants';
7
+ import { isArrayItem, isCorrectConfig, transformArrIn, transformArrOut } from '../utils';
8
+ const isErrorMutatorCorrect = (errorMutator) => errorMutator !== EMPTY_MUTATOR && (_.isString(errorMutator) || _.isBoolean(errorMutator));
9
+ const isValueMutatorCorrect = (valueMutator, spec) => valueMutator !== EMPTY_MUTATOR &&
10
+ (typeof valueMutator === spec.type ||
11
+ (_.isArray(valueMutator) && spec.type === SpecTypes.Array));
12
+ export const updateParentStore = (store) => {
13
+ (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
+ };
15
+ export const callUnmout = (store) => {
16
+ (store.parentOnUnmount ? store.parentOnUnmount : store.tools.onUnmount)(store.name);
17
+ };
18
+ export const getSpec = ({ name, spec, mutators, }) => {
19
+ const mutator = _.get(mutators.spec, name, EMPTY_MUTATOR);
20
+ if (mutator !== EMPTY_MUTATOR) {
21
+ const mutatedSpec = _.merge(_.cloneDeep(spec), mutator);
22
+ if (isCorrectSpec(mutatedSpec)) {
23
+ return mutatedSpec;
24
+ }
25
+ }
26
+ return spec;
27
+ };
28
+ export const getComponents = ({ spec, config, }) => {
29
+ const result = {};
30
+ if (isCorrectConfig(config) && isCorrectSpec(spec)) {
31
+ const { inputs, layouts } = config[spec.type];
32
+ if (inputs) {
33
+ const entity = inputs[spec.viewSpec.type];
34
+ if (isValidElementType(entity === null || entity === void 0 ? void 0 : entity.Component)) {
35
+ result.inputEntity = entity;
36
+ }
37
+ }
38
+ if (layouts && _.isString(spec.viewSpec.layout)) {
39
+ const Component = layouts[spec.viewSpec.layout];
40
+ if (isValidElementType(Component)) {
41
+ result.Layout = Component;
42
+ }
43
+ }
44
+ }
45
+ return result;
46
+ };
47
+ export const getRender = ({ name, spec, inputEntity, Layout, }) => {
48
+ const render = (props) => {
49
+ if (inputEntity && isCorrectSpec(spec) && _.isString(name)) {
50
+ if (!spec.viewSpec.hidden) {
51
+ if (inputEntity.independent) {
52
+ const InputComponent = inputEntity.Component;
53
+ return React.createElement(InputComponent, Object.assign({ spec: spec, name: name, Layout: Layout }, props));
54
+ }
55
+ const InputComponent = inputEntity.Component;
56
+ const input = React.createElement(InputComponent, Object.assign({ spec: spec, name: name }, props));
57
+ if (Layout) {
58
+ return (React.createElement(Layout, Object.assign({ spec: spec, name: name }, props), input));
59
+ }
60
+ return input;
61
+ }
62
+ }
63
+ return null;
64
+ };
65
+ return render;
66
+ };
67
+ export const getValidate = ({ spec, config, }) => {
68
+ let validate = () => undefined;
69
+ if (isCorrectConfig(config) && isCorrectSpec(spec)) {
70
+ const { validators } = config[spec.type];
71
+ if (validators) {
72
+ if ((!_.isString(spec.validator) || !spec.validator.length) &&
73
+ _.isFunction(validators.base)) {
74
+ validate = (value) => validators.base(spec, value);
75
+ }
76
+ if (_.isString(spec.validator) && _.isFunction(validators[spec.validator])) {
77
+ validate = (value) => validators[spec.validator](spec, value);
78
+ }
79
+ }
80
+ }
81
+ return validate;
82
+ };
83
+ export const getFieldInitials = ({ name, spec, valueFromParent, initialValue, validate, mutators, }) => {
84
+ const valueMutator = transformArrIn(_.get(mutators.values, name, EMPTY_MUTATOR));
85
+ let value = _.cloneDeep(valueFromParent);
86
+ if (isValueMutatorCorrect(valueMutator, spec)) {
87
+ value = valueMutator;
88
+ }
89
+ if (_.isNil(value)) {
90
+ if (spec.defaultValue) {
91
+ value = transformArrIn(spec.defaultValue);
92
+ }
93
+ // if the spec with type array or object, and this spec has "required === true",
94
+ // we immediately exclude empty value
95
+ else if (spec.required) {
96
+ if (isArraySpec(spec)) {
97
+ value = { [OBJECT_ARRAY_FLAG]: true, [OBJECT_ARRAY_CNT]: 0 };
98
+ }
99
+ else if (isObjectSpec(spec)) {
100
+ value = {};
101
+ }
102
+ }
103
+ }
104
+ let errorMutator = _.get(mutators.errors, name, EMPTY_MUTATOR);
105
+ if (!isErrorMutatorCorrect(errorMutator)) {
106
+ errorMutator = undefined;
107
+ }
108
+ const error = (validate === null || validate === void 0 ? void 0 : validate(transformArrOut(value))) || errorMutator;
109
+ const dirty = !_.isEqual(value, initialValue);
110
+ return {
111
+ initialValue,
112
+ active: false,
113
+ dirty,
114
+ error,
115
+ invalid: Boolean(error),
116
+ modified: dirty,
117
+ pristine: true,
118
+ touched: false,
119
+ valid: !error,
120
+ value,
121
+ visited: false,
122
+ childErrors: {},
123
+ };
124
+ };
125
+ export const getFieldMethods = () => {
126
+ const onChange = (store, { valOrSetter, childErrors, errorMutator }) => {
127
+ const { state, validate, spec } = store;
128
+ const _value = _.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
129
+ const error = (validate === null || validate === void 0 ? void 0 : validate(transformArrOut(_value))) || errorMutator;
130
+ let value = transformArrIn(_value);
131
+ if (isNumberSpec(spec) && !error) {
132
+ value = (value ? Number(value) : undefined);
133
+ }
134
+ let newChildErrors = Object.assign({}, state.childErrors);
135
+ if (childErrors) {
136
+ const nearestChildName = _.keys(childErrors).sort((a, b) => a.length - b.length)[0];
137
+ if (nearestChildName) {
138
+ const existingСhildNames = _.keys(newChildErrors).filter((childName) => childName.startsWith(nearestChildName));
139
+ newChildErrors = Object.assign(Object.assign({}, _.omit(newChildErrors, existingСhildNames)), childErrors);
140
+ }
141
+ }
142
+ 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 }) });
143
+ nextStore.afterStoreUpdateCB = () => updateParentStore(nextStore);
144
+ return nextStore;
145
+ };
146
+ const onDrop = (store) => {
147
+ const { name } = store;
148
+ if (isArrayItem(name)) {
149
+ const afterStoreUpdateCB = () => callUnmout(store);
150
+ return Object.assign(Object.assign({}, store), { afterStoreUpdateCB });
151
+ }
152
+ return onChange(store, {
153
+ valOrSetter: undefined,
154
+ childErrors: { [name]: false },
155
+ });
156
+ };
157
+ const onBlur = (store) => {
158
+ return Object.assign(Object.assign({}, store), { state: Object.assign(Object.assign({}, store.state), { active: false, touched: true }) });
159
+ };
160
+ const onFocus = (store) => {
161
+ return Object.assign(Object.assign({}, store), { state: Object.assign(Object.assign({}, store.state), { active: true, visited: true }) });
162
+ };
163
+ const parentOnUnmount = (store, childName) => {
164
+ const { name, spec } = store;
165
+ if (isArraySpec(spec) || isObjectSpec(spec)) {
166
+ return onChange(store, {
167
+ valOrSetter: (currentValue) => currentValue
168
+ ? _.omit(currentValue, childName.split(`${name}.`)[1])
169
+ : currentValue,
170
+ childErrors: { [childName]: false },
171
+ });
172
+ }
173
+ return store;
174
+ };
175
+ const onItemAdd = (store, _value) => {
176
+ const { validate, state } = store;
177
+ const stateValue = (state.value || {
178
+ [OBJECT_ARRAY_FLAG]: true,
179
+ [OBJECT_ARRAY_CNT]: 0,
180
+ });
181
+ const value = Object.assign(Object.assign({}, stateValue), { [`<${stateValue[OBJECT_ARRAY_CNT]}>`]: transformArrIn(_value), [OBJECT_ARRAY_CNT]: stateValue[OBJECT_ARRAY_CNT] + 1 });
182
+ const error = validate === null || validate === void 0 ? void 0 : validate(transformArrOut(value));
183
+ 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 }) });
184
+ nextStore.afterStoreUpdateCB = () => updateParentStore(nextStore);
185
+ return nextStore;
186
+ };
187
+ const onItemRemove = (store, idx) => {
188
+ return parentOnUnmount(store, `${store.name}.<${idx}>`);
189
+ };
190
+ return {
191
+ onChange,
192
+ onDrop,
193
+ onBlur,
194
+ onFocus,
195
+ parentOnUnmount,
196
+ onItemAdd,
197
+ onItemRemove,
198
+ };
199
+ };
200
+ export const initializeStore = ({ name, spec: _spec, mutators, config, valueFromParent, tools, parentOnChange, parentOnUnmount, }) => {
201
+ const spec = getSpec({ name, spec: _spec, mutators });
202
+ const components = getComponents({ spec, config });
203
+ const render = getRender(Object.assign({ name, spec }, components));
204
+ const validate = getValidate({ spec, config });
205
+ const state = getFieldInitials({
206
+ name,
207
+ spec,
208
+ valueFromParent,
209
+ validate,
210
+ mutators,
211
+ initialValue: _.get(tools.initialValue, name),
212
+ });
213
+ const initialsStore = {
214
+ name,
215
+ spec,
216
+ initialSpec: _spec,
217
+ config,
218
+ tools,
219
+ mutators,
220
+ render,
221
+ validate,
222
+ parentOnChange,
223
+ parentOnUnmount,
224
+ state,
225
+ };
226
+ if (!_.isEqual(valueFromParent, state.value) || state.error) {
227
+ initialsStore.afterStoreUpdateCB = () => updateParentStore(initialsStore);
228
+ }
229
+ return initialsStore;
230
+ };
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 })) &&
239
+ valueMutator !== storeValueMutator;
240
+ const errorMutatorUpdated = isErrorMutatorCorrect(errorMutator) && errorMutator !== storeErrorMutator;
241
+ const updateState = valueMutatorUpdated || errorMutatorUpdated;
242
+ const updateNonCritical = parentOnChange !== store.parentOnChange ||
243
+ parentOnUnmount !== store.parentOnUnmount ||
244
+ tools.onChange !== store.tools.onChange ||
245
+ tools.onUnmount !== store.tools.onUnmount;
246
+ const updateAllStore = !_.isEqual(_spec, store.initialSpec) ||
247
+ config !== store.config ||
248
+ (specMutator !== EMPTY_MUTATOR && specMutator !== storeSpecMutator);
249
+ const updateAllStoreAndClearParentValues = name !== store.name;
250
+ if (updateAllStoreAndClearParentValues) {
251
+ callUnmout(store);
252
+ setStore(initializeStore({
253
+ name,
254
+ spec: _spec,
255
+ mutators,
256
+ config,
257
+ valueFromParent,
258
+ tools,
259
+ parentOnChange,
260
+ parentOnUnmount,
261
+ }));
262
+ }
263
+ else if (updateAllStore) {
264
+ let nextStore = Object.assign(Object.assign({}, initializeStore({
265
+ name,
266
+ spec: _spec,
267
+ mutators,
268
+ config,
269
+ valueFromParent,
270
+ tools,
271
+ parentOnChange,
272
+ parentOnUnmount,
273
+ })), { state: store.state });
274
+ if (updateState) {
275
+ nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {})));
276
+ }
277
+ setStore(nextStore);
278
+ }
279
+ else if (updateNonCritical) {
280
+ let nextStore = Object.assign(Object.assign({}, store), { parentOnChange,
281
+ parentOnUnmount,
282
+ tools });
283
+ if (updateState) {
284
+ nextStore = methodOnChange(nextStore, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {})));
285
+ }
286
+ setStore(nextStore);
287
+ }
288
+ else if (updateState) {
289
+ setStore(methodOnChange(store, Object.assign({ valOrSetter: (value) => valueMutatorUpdated ? valueMutator : value }, (errorMutatorUpdated ? { errorMutator } : {}))));
290
+ }
291
+ };
@@ -1,17 +1,13 @@
1
- export * from './useComponents';
2
1
  export * from './useControllerMirror';
3
2
  export * from './useCreateContext';
4
3
  export * from './useDynamicFieldMirror';
5
4
  export * from './useDynamicFormsCtx';
6
- export * from './useField';
7
5
  export * from './useGenerateRandomValue';
8
6
  export * from './useIntegrationFF';
9
7
  export * from './useMutateDFState';
10
8
  export * from './useMutators';
11
- export * from './useRender';
12
9
  export * from './useStore';
13
10
  export * from './useStoreValue';
14
- export * from './useValidate';
15
11
  export * from './useMonaco';
16
12
  export * from './useSearchStore';
17
13
  export * from './useSearchContext';
@@ -1,17 +1,13 @@
1
- export * from './useComponents';
2
1
  export * from './useControllerMirror';
3
2
  export * from './useCreateContext';
4
3
  export * from './useDynamicFieldMirror';
5
4
  export * from './useDynamicFormsCtx';
6
- export * from './useField';
7
5
  export * from './useGenerateRandomValue';
8
6
  export * from './useIntegrationFF';
9
7
  export * from './useMutateDFState';
10
8
  export * from './useMutators';
11
- export * from './useRender';
12
9
  export * from './useStore';
13
10
  export * from './useStoreValue';
14
- export * from './useValidate';
15
11
  export * from './useMonaco';
16
12
  export * from './useSearchStore';
17
13
  export * from './useSearchContext';
@@ -4,7 +4,27 @@ export const useMutators = (externalMutators) => {
4
4
  const firstRenderRef = React.useRef(true);
5
5
  const [store, setStore] = React.useState(externalMutators || {});
6
6
  const mutateDFState = React.useCallback((mutators) => {
7
- 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: _.merge(store.spec, mutators.spec) } : {}))));
7
+ const mergeSpec = (a, b) => {
8
+ const result = _.cloneDeep(a);
9
+ const getKeys = (parent) => {
10
+ if (_.isObjectLike(parent)) {
11
+ return _.keys(parent).reduce((acc, parentKey) => {
12
+ const childKeys = getKeys(parent[parentKey]);
13
+ return [
14
+ ...acc,
15
+ ...(childKeys.length ? [] : [[parentKey]]),
16
+ ...childKeys.map((childKey) => [parentKey, ...childKey]),
17
+ ];
18
+ }, []);
19
+ }
20
+ return [];
21
+ };
22
+ getKeys(b).forEach((key) => {
23
+ _.set(result, key, _.get(b, key));
24
+ });
25
+ return result;
26
+ };
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) } : {}))));
8
28
  }, [setStore]);
9
29
  React.useEffect(() => {
10
30
  if (firstRenderRef.current) {
@@ -1,9 +1,7 @@
1
- import { useComponents, useField, useIntegrationFF, useRender, useSearch, useSearchStore, useStore, useValidate } from '../hooks';
1
+ import { useIntegrationFF, useSearch, useSearchStore, useStore } from '../hooks';
2
+ import { FieldRenderProps } from './field';
2
3
  export interface ControllerMirror {
3
- useComponents?: ReturnType<typeof useComponents>;
4
- useRender?: ReturnType<typeof useRender>;
5
- useValidate?: ReturnType<typeof useValidate>;
6
- useField?: ReturnType<typeof useField>;
4
+ useField?: FieldRenderProps<any>;
7
5
  useSearch?: ReturnType<typeof useSearch>;
8
6
  }
9
7
  export interface DynamicFieldMirror {
@@ -1,7 +1,18 @@
1
- import { FormValue, Spec } from '../../../types';
1
+ import { ArraySpec, BooleanSpec, FormValue, NumberSpec, ObjectSpec, StringSpec } from '../../../types';
2
2
  import { BaseValidateError } from './';
3
+ export type SpecMutator = Partial<(Omit<ArraySpec, 'viewSpec'> & {
4
+ viewSpec: Partial<ArraySpec['viewSpec']>;
5
+ }) | (Omit<BooleanSpec, 'viewSpec'> & {
6
+ viewSpec: Partial<BooleanSpec['viewSpec']>;
7
+ }) | (Omit<NumberSpec, 'viewSpec'> & {
8
+ viewSpec: Partial<NumberSpec['viewSpec']>;
9
+ }) | (Omit<ObjectSpec, 'viewSpec'> & {
10
+ viewSpec: Partial<ObjectSpec['viewSpec']>;
11
+ }) | (Omit<StringSpec, 'viewSpec'> & {
12
+ viewSpec: Partial<StringSpec['viewSpec']>;
13
+ })>;
3
14
  export interface DynamicFormMutators {
4
15
  errors?: Record<string, BaseValidateError>;
5
16
  values?: Record<string, FormValue>;
6
- spec?: Record<string, Partial<Spec>>;
17
+ spec?: Record<string, SpecMutator>;
7
18
  }
@@ -1,9 +1,6 @@
1
1
  import { FormValue, Spec } from '../../../types';
2
- import { ValidateError } from '../types';
3
2
  export declare const isCorrectConfig: (candidate: any) => boolean;
4
3
  export declare const transformArrIn: <Type extends FormValue, ReturnType_1 extends FormValue = Type>(value: Type) => ReturnType_1;
5
4
  export declare const transformArrOut: <Type extends FormValue, ReturnType_1 extends FormValue = Type>(value: Type) => ReturnType_1;
6
5
  export declare const isArrayItem: (name: string) => boolean;
7
6
  export declare const withGenerateButton: (spec: Spec) => boolean | undefined;
8
- export declare const isErrorMutatorCorrect: (errorMutator: ValidateError) => boolean;
9
- export declare const isValueMutatorCorrect: (valueMutator: FormValue, spec: Spec) => boolean;
@@ -45,5 +45,3 @@ export const isArrayItem = (name) => name[name.length - 1] === '>';
45
45
  export const withGenerateButton = (spec) => isStringSpec(spec) &&
46
46
  SPEC_TYPE_FOR_GENERATE_BUTTON.includes(spec.viewSpec.type) &&
47
47
  spec.viewSpec.generateRandomValueButton;
48
- export const isErrorMutatorCorrect = (errorMutator) => _.isString(errorMutator) || _.isBoolean(errorMutator) || _.isUndefined(errorMutator);
49
- export const isValueMutatorCorrect = (valueMutator, spec) => typeof valueMutator === spec.type || (_.isArray(valueMutator) && spec.type === SpecTypes.Array);
@@ -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(--yc-color-sfx-shadow);
7
+ box-shadow: 0 1px 5px var(--g-color-sfx-shadow);
8
8
  border-radius: 5px;
9
- color: var(--yc-color-text-primary);
10
- background-color: var(--yc-color-base-float);
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(--yc-color-sfx-shadow);
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(--yc-color-line-generic);
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(--yc-color-text-complementary);
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(--yc-text-subheader-2-font-size);
52
- font-weight: var(--yc-text-subheader-font-weight);
53
- line-height: var(--yc-text-subheader-2-line-height);
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(--yc-color-text-danger);
20
+ border-color: var(--g-color-text-danger);
21
21
  }
22
22
  .df-error-wrapper__error-text {
23
- color: var(--yc-color-text-danger);
23
+ color: var(--g-color-text-danger);
24
24
  margin-top: 2px;
25
- font-size: var(--yc-text-body-1-font-size);
26
- line-height: var(--yc-text-body-1-line-height);
25
+ font-size: var(--g-text-body-1-font-size);
26
+ line-height: var(--g-text-body-1-line-height);
27
27
  }
@@ -4,7 +4,7 @@
4
4
  margin-top: -11px;
5
5
  margin-bottom: 20px;
6
6
  margin-left: 5px;
7
- border-left: 1px solid var(--yc-color-line-generic-accent);
7
+ border-left: 1px solid var(--g-color-line-generic-accent);
8
8
  }
9
9
  .df-group-indent:last-child {
10
10
  margin-bottom: 0;
@@ -11,5 +11,5 @@
11
11
  text-overflow: ellipsis;
12
12
  overflow: hidden;
13
13
  white-space: nowrap;
14
- color: var(--yc-color-text-secondary);
14
+ color: var(--g-color-text-secondary);
15
15
  }
@@ -4,7 +4,7 @@
4
4
  justify-content: space-between;
5
5
  padding: 15px;
6
6
  align-items: center;
7
- background-color: var(--yc-color-base-float-hover);
7
+ background-color: var(--g-color-base-float-hover);
8
8
  }
9
9
  .df-monaco-header__language {
10
10
  margin-top: 2px;
@@ -2,5 +2,5 @@
2
2
  width: 550px;
3
3
  }
4
4
  .df-monaco-input__container {
5
- border: 1px solid var(--yc-color-line-generic);
5
+ border: 1px solid var(--g-color-line-generic);
6
6
  }
@@ -2,7 +2,7 @@
2
2
  padding: 10px 32px 32px;
3
3
  }
4
4
  .df-monaco-input-dialog__container {
5
- border: 1px solid var(--yc-color-line-generic);
5
+ border: 1px solid var(--g-color-line-generic);
6
6
  }
7
7
  .df-monaco-input-dialog__dialog-header .yc-dialog-header__caption {
8
8
  min-height: 24px;
@@ -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(--yc-color-line-generic-accent);
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;
@@ -6,7 +6,7 @@
6
6
  }
7
7
  .df-table-array__row .yc-table__cell {
8
8
  border-bottom: 0px transparent;
9
- border-top: 1px solid var(--yc-color-line-generic);
9
+ border-top: 1px solid var(--g-color-line-generic);
10
10
  }
11
11
  .df-table-array__row_hidden {
12
12
  display: none;
@@ -31,7 +31,7 @@
31
31
  }
32
32
  .df-row__title_required::after {
33
33
  content: "*";
34
- color: var(--yc-color-text-danger);
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(--yc-color-text-secondary);
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(--yc-color-text-danger);
68
+ color: var(--g-color-text-danger);
69
69
  }
70
70
  .df-row__error-wrapper {
71
71
  min-width: 100%;
@@ -11,5 +11,5 @@
11
11
  cursor: pointer;
12
12
  }
13
13
  .df-long-value_long:hover {
14
- color: var(--yc-color-text-secondary);
14
+ color: var(--g-color-text-secondary);
15
15
  }
@@ -7,7 +7,7 @@
7
7
  .df-simple-vertical-accordeon_branch .df-simple-vertical-accordeon__body {
8
8
  padding-left: 20px;
9
9
  margin-left: 5px;
10
- border-left: 1px solid var(--yc-color-line-generic-accent);
10
+ border-left: 1px solid var(--g-color-line-generic-accent);
11
11
  }
12
12
  .df-simple-vertical-accordeon__header {
13
13
  display: flex;
@@ -22,15 +22,15 @@
22
22
  }
23
23
  .df-simple-vertical-accordeon__title_size_s {
24
24
  margin-bottom: 0;
25
- font-size: var(--yc-text-body-1-font-size);
25
+ font-size: var(--g-text-body-1-font-size);
26
26
  }
27
27
  .df-simple-vertical-accordeon__title_size_m {
28
28
  margin-bottom: 1px;
29
- font-size: var(--yc-text-body2-font-size);
29
+ font-size: var(--g-text-body2-font-size);
30
30
  }
31
31
  .df-simple-vertical-accordeon__title_size_l {
32
32
  margin-bottom: 2px;
33
- font-size: var(--yc-text-body3-font-size);
33
+ font-size: var(--g-text-body3-font-size);
34
34
  }
35
35
  .df-simple-vertical-accordeon__tooltip {
36
36
  margin: 0px 5px;
@@ -18,13 +18,13 @@
18
18
  white-space: nowrap;
19
19
  overflow: hidden;
20
20
  text-overflow: ellipsis;
21
- color: var(--yc-color-text-secondary);
21
+ color: var(--g-color-text-secondary);
22
22
  }
23
23
  .df-view-row__dots {
24
24
  min-width: 40px;
25
25
  flex-grow: 1;
26
26
  margin: 0 2px;
27
- border-bottom: 1px dotted var(--yc-color-text-secondary);
27
+ border-bottom: 1px dotted var(--g-color-text-secondary);
28
28
  }
29
29
  .df-view-row__right {
30
30
  max-width: 480px;
@@ -1,4 +1,4 @@
1
1
  .df-monaco-base-view {
2
- border: 1px solid var(--yc-color-line-generic);
2
+ border: 1px solid var(--g-color-line-generic);
3
3
  width: 550px;
4
4
  }
@@ -2,7 +2,7 @@
2
2
  padding: 10px 32px 32px;
3
3
  }
4
4
  .df-monaco-view-dialog__container {
5
- border: 1px solid var(--yc-color-line-generic);
5
+ border: 1px solid var(--g-color-line-generic);
6
6
  }
7
7
  .df-monaco-view-dialog__dialog-header {
8
8
  height: 48px;
@@ -17,7 +17,7 @@ export const ObjectValueInputView = (_a) => {
17
17
  if (!childSpec) {
18
18
  return null;
19
19
  }
20
- const content = (React.createElement(ViewController, { spec: childSpec, name: `${name}.${OBJECT_VALUE_PROPERTY_NAME}` }));
20
+ const content = (React.createElement(ViewController, { spec: childSpec, name: `${name ? name + '.' : ''}${OBJECT_VALUE_PROPERTY_NAME}` }));
21
21
  if (Layout) {
22
22
  return (React.createElement(Layout, Object.assign({ spec: spec, name: name }, restProps), content));
23
23
  }