@gravity-ui/dynamic-forms 3.3.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 (65) 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/AccordeonCard/AccordeonCard.css +6 -6
  6. package/build/cjs/lib/kit/components/Card/Card.css +3 -3
  7. package/build/cjs/lib/kit/components/ErrorWrapper/ErrorWrapper.css +4 -4
  8. package/build/cjs/lib/kit/components/GroupIndent/GroupIndent.css +1 -1
  9. package/build/cjs/lib/kit/components/Inputs/FileInput/FileInput.css +1 -1
  10. package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoHeader.css +1 -1
  11. package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoInputBase.css +1 -1
  12. package/build/cjs/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.css +1 -1
  13. package/build/cjs/lib/kit/components/Inputs/OneOf/OneOf.css +1 -1
  14. package/build/cjs/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.css +1 -1
  15. package/build/cjs/lib/kit/components/Inputs/TextArea/TextArea.js +1 -1
  16. package/build/cjs/lib/kit/components/Layouts/Row/Row.css +4 -3
  17. package/build/cjs/lib/kit/components/LongValue/LongValue.css +1 -1
  18. package/build/cjs/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.css +4 -4
  19. package/build/cjs/lib/kit/components/ViewLayouts/ViewRow/ViewRow.css +2 -2
  20. package/build/cjs/lib/kit/components/Views/CardOneOfView.js +1 -1
  21. package/build/cjs/lib/kit/components/Views/MonacoInputView/MonacoBaseView.css +1 -1
  22. package/build/cjs/lib/kit/components/Views/MonacoInputView/MonacoViewDialog.css +1 -1
  23. package/build/cjs/lib/kit/components/Views/MultiOneOfView/MultiOneOfView.js +1 -1
  24. package/build/cjs/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +1 -1
  25. package/build/cjs/lib/kit/components/Views/OneOfView/OneOfView.js +1 -1
  26. package/build/cjs/lib/kit/components/Views/TextLinkView/TextLinkView.js +1 -1
  27. package/build/cjs/lib/kit/validators/types.js +2 -0
  28. package/build/cjs/lib/kit/validators/validators.js +32 -25
  29. package/build/esm/lib/core/components/Form/Controller/Controller.js +4 -4
  30. package/build/esm/lib/core/components/Form/Controller/types.d.ts +6 -6
  31. package/build/esm/lib/core/components/Form/Controller/utils.d.ts +6 -6
  32. package/build/esm/lib/core/components/Form/Controller/utils.js +39 -29
  33. package/build/esm/lib/core/components/Form/DynamicField.js +3 -3
  34. package/build/esm/lib/core/components/Form/hooks/useMutators.d.ts +2 -2
  35. package/build/esm/lib/core/components/Form/hooks/useMutators.js +21 -7
  36. package/build/esm/lib/core/components/Form/types/context.d.ts +2 -2
  37. package/build/esm/lib/core/components/Form/types/mutators.d.ts +11 -0
  38. package/build/esm/lib/kit/components/AccordeonCard/AccordeonCard.css +6 -6
  39. package/build/esm/lib/kit/components/Card/Card.css +3 -3
  40. package/build/esm/lib/kit/components/ErrorWrapper/ErrorWrapper.css +4 -4
  41. package/build/esm/lib/kit/components/GroupIndent/GroupIndent.css +1 -1
  42. package/build/esm/lib/kit/components/Inputs/FileInput/FileInput.css +1 -1
  43. package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoHeader.css +1 -1
  44. package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoInputBase.css +1 -1
  45. package/build/esm/lib/kit/components/Inputs/MonacoInput/MonacoInputDialog.css +1 -1
  46. package/build/esm/lib/kit/components/Inputs/OneOf/OneOf.css +1 -1
  47. package/build/esm/lib/kit/components/Inputs/TableArrayInput/TableArrayInput.css +1 -1
  48. package/build/esm/lib/kit/components/Inputs/TextArea/TextArea.js +1 -1
  49. package/build/esm/lib/kit/components/Layouts/Row/Row.css +4 -3
  50. package/build/esm/lib/kit/components/LongValue/LongValue.css +1 -1
  51. package/build/esm/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.css +4 -4
  52. package/build/esm/lib/kit/components/ViewLayouts/ViewRow/ViewRow.css +2 -2
  53. package/build/esm/lib/kit/components/Views/CardOneOfView.js +1 -1
  54. package/build/esm/lib/kit/components/Views/MonacoInputView/MonacoBaseView.css +1 -1
  55. package/build/esm/lib/kit/components/Views/MonacoInputView/MonacoViewDialog.css +1 -1
  56. package/build/esm/lib/kit/components/Views/MultiOneOfView/MultiOneOfView.js +1 -1
  57. package/build/esm/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +1 -1
  58. package/build/esm/lib/kit/components/Views/OneOfView/OneOfView.js +1 -1
  59. package/build/esm/lib/kit/components/Views/TextLinkView/TextLinkView.js +1 -1
  60. package/build/esm/lib/kit/validators/messages.d.ts +2 -16
  61. package/build/esm/lib/kit/validators/types.d.ts +16 -0
  62. package/build/esm/lib/kit/validators/types.js +1 -0
  63. package/build/esm/lib/kit/validators/validators.d.ts +10 -9
  64. package/build/esm/lib/kit/validators/validators.js +32 -25
  65. package/package.json +11 -2
@@ -6,79 +6,83 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
6
  const validators_1 = require("../validators");
7
7
  const helpers_1 = require("./helpers");
8
8
  const getArrayValidator = (params = {}) => {
9
- const { ignoreRequiredCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck } = params;
9
+ const { ignoreRequiredCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck, customErrorMessages } = params;
10
+ const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
10
11
  return (spec, value) => {
11
12
  const valueLength = (value === null || value === void 0 ? void 0 : value.length) || 0;
12
13
  if (!ignoreRequiredCheck && spec.required && !lodash_1.default.isArray(value)) {
13
- return validators_1.ErrorMessages.REQUIRED;
14
+ return errorMessages.REQUIRED;
14
15
  }
15
16
  if (!ignoreMaxLengthCheck &&
16
17
  typeof spec.maxLength === 'bigint' &&
17
18
  valueLength > spec.maxLength) {
18
- return validators_1.ErrorMessages.maxLengthArr(spec.maxLength);
19
+ return errorMessages.maxLengthArr(spec.maxLength);
19
20
  }
20
21
  if (!ignoreMinLengthCheck &&
21
22
  typeof spec.minLength === 'bigint' &&
22
23
  valueLength < spec.minLength) {
23
- return validators_1.ErrorMessages.minLengthArr(spec.minLength);
24
+ return errorMessages.minLengthArr(spec.minLength);
24
25
  }
25
26
  return false;
26
27
  };
27
28
  };
28
29
  exports.getArrayValidator = getArrayValidator;
29
30
  const getBooleanValidator = (params = {}) => {
30
- const { ignoreRequiredCheck } = params;
31
+ const { ignoreRequiredCheck, customErrorMessages } = params;
32
+ const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
31
33
  return (spec, value) => {
32
34
  if (!ignoreRequiredCheck && spec.required && !value) {
33
- return validators_1.ErrorMessages.REQUIRED;
35
+ return errorMessages.REQUIRED;
34
36
  }
35
37
  return false;
36
38
  };
37
39
  };
38
40
  exports.getBooleanValidator = getBooleanValidator;
39
41
  const getNumberValidator = (params = {}) => {
40
- const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreNumberCheck, ignoreMaximumCheck, ignoreMinimumCheck, ignoreIntCheck, ignoreDotEnd, ignoreZeroStart, } = params;
42
+ const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreNumberCheck, ignoreMaximumCheck, ignoreMinimumCheck, ignoreIntCheck, ignoreDotEnd, ignoreZeroStart, customErrorMessages, } = params;
43
+ const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
44
+ // eslint-disable-next-line complexity
41
45
  return (spec, value = '') => {
42
46
  const stringValue = String(value);
43
47
  if (!ignoreRequiredCheck && spec.required && !stringValue.length) {
44
- return validators_1.ErrorMessages.REQUIRED;
48
+ return errorMessages.REQUIRED;
45
49
  }
46
50
  if (stringValue.length) {
47
51
  if (!ignoreSpaceStartCheck && !stringValue[0].trim()) {
48
- return validators_1.ErrorMessages.SPACE_START;
52
+ return errorMessages.SPACE_START;
49
53
  }
50
54
  if (!ignoreSpaceEndCheck && !stringValue[stringValue.length - 1].trim()) {
51
- return validators_1.ErrorMessages.SPACE_END;
55
+ return errorMessages.SPACE_END;
52
56
  }
53
57
  if (!ignoreDotEnd && stringValue[stringValue.length - 1] === '.') {
54
- return validators_1.ErrorMessages.DOT_END;
58
+ return errorMessages.DOT_END;
55
59
  }
56
60
  if (!ignoreNumberCheck && !(0, helpers_1.isFloat)(stringValue)) {
57
- return validators_1.ErrorMessages.NUMBER;
61
+ return errorMessages.NUMBER;
58
62
  }
59
63
  if (!ignoreZeroStart &&
60
64
  ((stringValue.length > 1 && stringValue[0] === '0' && stringValue[1] !== '.') ||
61
65
  (stringValue.length > 2 &&
62
66
  stringValue.substring(0, 2) === '-0' &&
63
67
  stringValue[2] !== '.'))) {
64
- return validators_1.ErrorMessages.ZERO_START;
68
+ return errorMessages.ZERO_START;
65
69
  }
66
70
  }
67
71
  if (!ignoreMaximumCheck &&
68
72
  lodash_1.default.isNumber(spec.maximum) &&
69
73
  stringValue.length &&
70
74
  Number(stringValue) > spec.maximum) {
71
- return validators_1.ErrorMessages.maxNumber(spec.maximum);
75
+ return errorMessages.maxNumber(spec.maximum);
72
76
  }
73
77
  if (!ignoreMinimumCheck &&
74
78
  lodash_1.default.isNumber(spec.minimum) &&
75
79
  stringValue.length &&
76
80
  spec.minimum > Number(stringValue)) {
77
- return validators_1.ErrorMessages.minNumber(spec.minimum);
81
+ return errorMessages.minNumber(spec.minimum);
78
82
  }
79
83
  if (lodash_1.default.isString(spec.format) && stringValue.length) {
80
84
  if (!ignoreIntCheck && spec.format === 'int64' && !(0, helpers_1.isInt)(stringValue)) {
81
- return validators_1.ErrorMessages.INT;
85
+ return errorMessages.INT;
82
86
  }
83
87
  }
84
88
  return false;
@@ -86,46 +90,49 @@ const getNumberValidator = (params = {}) => {
86
90
  };
87
91
  exports.getNumberValidator = getNumberValidator;
88
92
  const getObjectValidator = (params = {}) => {
89
- const { ignoreRequiredCheck } = params;
93
+ const { ignoreRequiredCheck, customErrorMessages } = params;
94
+ const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
90
95
  return (spec, value) => {
91
96
  if (!ignoreRequiredCheck && spec.required && !value) {
92
- return validators_1.ErrorMessages.REQUIRED;
97
+ return errorMessages.REQUIRED;
93
98
  }
94
99
  return false;
95
100
  };
96
101
  };
97
102
  exports.getObjectValidator = getObjectValidator;
98
103
  const getStringValidator = (params = {}) => {
99
- const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck, ignoreRegExpCheck, } = params;
104
+ const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck, ignoreRegExpCheck, customErrorMessages, } = params;
105
+ const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
106
+ // eslint-disable-next-line complexity
100
107
  return (spec, value = '') => {
101
108
  const valueLength = value === null || value === void 0 ? void 0 : value.length;
102
109
  if (!ignoreRequiredCheck && spec.required && !valueLength) {
103
- return validators_1.ErrorMessages.REQUIRED;
110
+ return errorMessages.REQUIRED;
104
111
  }
105
112
  if (valueLength) {
106
113
  if (!ignoreSpaceStartCheck && !value[0].trim()) {
107
- return validators_1.ErrorMessages.SPACE_START;
114
+ return errorMessages.SPACE_START;
108
115
  }
109
116
  if (!ignoreSpaceEndCheck && !value[value.length - 1].trim()) {
110
- return validators_1.ErrorMessages.SPACE_END;
117
+ return errorMessages.SPACE_END;
111
118
  }
112
119
  }
113
120
  if (!ignoreMaxLengthCheck &&
114
121
  typeof spec.maxLength === 'bigint' &&
115
122
  valueLength > spec.maxLength) {
116
- return validators_1.ErrorMessages.maxLength(spec.maxLength);
123
+ return errorMessages.maxLength(spec.maxLength);
117
124
  }
118
125
  if (!ignoreMinLengthCheck &&
119
126
  typeof spec.minLength === 'bigint' &&
120
127
  valueLength < spec.minLength) {
121
- return validators_1.ErrorMessages.minLength(spec.minLength);
128
+ return errorMessages.minLength(spec.minLength);
122
129
  }
123
130
  if (lodash_1.default.isString(spec.pattern) && spec.pattern.length) {
124
131
  const regex = new RegExp(spec.pattern);
125
132
  if (!ignoreRegExpCheck && !regex.test(value)) {
126
133
  return lodash_1.default.isString(spec.patternError) && spec.patternError.length
127
134
  ? spec.patternError
128
- : validators_1.ErrorMessages.INVALID;
135
+ : errorMessages.INVALID;
129
136
  }
130
137
  }
131
138
  return false;
@@ -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.errors, 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
+ }
@@ -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;