@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
@@ -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;
@@ -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
  };
@@ -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;
@@ -55,17 +55,18 @@
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;
61
- color: var(--yc-color-text-secondary);
62
+ color: var(--g-color-text-secondary);
62
63
  word-break: break-word;
63
64
  }
64
65
  .df-row__remove-button {
65
66
  margin-left: 5px;
66
67
  }
67
68
  .df-row__required-mark {
68
- color: var(--yc-color-text-danger);
69
+ color: var(--g-color-text-danger);
69
70
  }
70
71
  .df-row__error-wrapper {
71
72
  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;
@@ -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
  };
@@ -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;
@@ -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 })));
@@ -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
  }
@@ -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
  }
@@ -1,16 +1,2 @@
1
- export declare let ErrorMessages: {
2
- REQUIRED: string;
3
- INVALID: string;
4
- INT: string;
5
- NUMBER: string;
6
- minLength(count: number | bigint): string;
7
- minLengthArr(count: number | bigint): string;
8
- maxLength(count: number | bigint): string;
9
- maxLengthArr(count: number | bigint): string;
10
- minNumber(count: number | bigint): string;
11
- maxNumber(count: number | bigint): string;
12
- SPACE_START: string;
13
- SPACE_END: string;
14
- DOT_END: string;
15
- ZERO_START: string;
16
- };
1
+ import type { ErrorMessagesType } from './types';
2
+ export declare let ErrorMessages: ErrorMessagesType;
@@ -0,0 +1,16 @@
1
+ export interface ErrorMessagesType {
2
+ REQUIRED: string;
3
+ INVALID: string;
4
+ INT: string;
5
+ NUMBER: string;
6
+ minLength: (count: number | bigint) => string;
7
+ minLengthArr: (count: number | bigint) => string;
8
+ maxLength: (count: number | bigint) => string;
9
+ maxLengthArr: (count: number | bigint) => string;
10
+ minNumber: (count: number | bigint) => string;
11
+ maxNumber: (count: number | bigint) => string;
12
+ SPACE_START: string;
13
+ SPACE_END: string;
14
+ DOT_END: string;
15
+ ZERO_START: string;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,16 +1,18 @@
1
1
  import { ArraySpec, ArrayValue, BooleanSpec, NumberSpec, ObjectSpec, ObjectValue, StringSpec } from '../../core';
2
- export interface GetArrayValidatorParams {
2
+ import { ErrorMessagesType } from './types';
3
+ interface CommonValidatorParams {
3
4
  ignoreRequiredCheck?: boolean;
5
+ customErrorMessages?: Partial<ErrorMessagesType>;
6
+ }
7
+ export interface GetArrayValidatorParams extends CommonValidatorParams {
4
8
  ignoreMaxLengthCheck?: boolean;
5
9
  ignoreMinLengthCheck?: boolean;
6
10
  }
7
11
  export declare const getArrayValidator: (params?: GetArrayValidatorParams) => (spec: ArraySpec, value?: ArrayValue) => string | false;
8
- export interface GetBooleanValidatorParams {
9
- ignoreRequiredCheck?: boolean;
12
+ export interface GetBooleanValidatorParams extends CommonValidatorParams {
10
13
  }
11
14
  export declare const getBooleanValidator: (params?: GetBooleanValidatorParams) => (spec: BooleanSpec, value?: boolean) => string | false;
12
- export interface GetNumberValidatorParams {
13
- ignoreRequiredCheck?: boolean;
15
+ export interface GetNumberValidatorParams extends CommonValidatorParams {
14
16
  ignoreSpaceStartCheck?: boolean;
15
17
  ignoreSpaceEndCheck?: boolean;
16
18
  ignoreNumberCheck?: boolean;
@@ -21,12 +23,10 @@ export interface GetNumberValidatorParams {
21
23
  ignoreZeroStart?: boolean;
22
24
  }
23
25
  export declare const getNumberValidator: (params?: GetNumberValidatorParams) => (spec: NumberSpec, value?: string | number) => string | false;
24
- export interface GetObjectValidatorParams {
25
- ignoreRequiredCheck?: boolean;
26
+ export interface GetObjectValidatorParams extends CommonValidatorParams {
26
27
  }
27
28
  export declare const getObjectValidator: (params?: GetObjectValidatorParams) => (spec: ObjectSpec, value?: ObjectValue) => string | false;
28
- export interface GetStringValidatorParams {
29
- ignoreRequiredCheck?: boolean;
29
+ export interface GetStringValidatorParams extends CommonValidatorParams {
30
30
  ignoreSpaceStartCheck?: boolean;
31
31
  ignoreSpaceEndCheck?: boolean;
32
32
  ignoreMaxLengthCheck?: boolean;
@@ -34,3 +34,4 @@ export interface GetStringValidatorParams {
34
34
  ignoreRegExpCheck?: boolean;
35
35
  }
36
36
  export declare const getStringValidator: (params?: GetStringValidatorParams) => (spec: StringSpec, value?: string) => string | false;
37
+ export {};
@@ -2,122 +2,129 @@ import _ from 'lodash';
2
2
  import { ErrorMessages } from '../validators';
3
3
  import { isFloat, isInt } from './helpers';
4
4
  export const getArrayValidator = (params = {}) => {
5
- const { ignoreRequiredCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck } = params;
5
+ const { ignoreRequiredCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck, customErrorMessages } = params;
6
+ const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
6
7
  return (spec, value) => {
7
8
  const valueLength = (value === null || value === void 0 ? void 0 : value.length) || 0;
8
9
  if (!ignoreRequiredCheck && spec.required && !_.isArray(value)) {
9
- return ErrorMessages.REQUIRED;
10
+ return errorMessages.REQUIRED;
10
11
  }
11
12
  if (!ignoreMaxLengthCheck &&
12
13
  typeof spec.maxLength === 'bigint' &&
13
14
  valueLength > spec.maxLength) {
14
- return ErrorMessages.maxLengthArr(spec.maxLength);
15
+ return errorMessages.maxLengthArr(spec.maxLength);
15
16
  }
16
17
  if (!ignoreMinLengthCheck &&
17
18
  typeof spec.minLength === 'bigint' &&
18
19
  valueLength < spec.minLength) {
19
- return ErrorMessages.minLengthArr(spec.minLength);
20
+ return errorMessages.minLengthArr(spec.minLength);
20
21
  }
21
22
  return false;
22
23
  };
23
24
  };
24
25
  export const getBooleanValidator = (params = {}) => {
25
- const { ignoreRequiredCheck } = params;
26
+ const { ignoreRequiredCheck, customErrorMessages } = params;
27
+ const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
26
28
  return (spec, value) => {
27
29
  if (!ignoreRequiredCheck && spec.required && !value) {
28
- return ErrorMessages.REQUIRED;
30
+ return errorMessages.REQUIRED;
29
31
  }
30
32
  return false;
31
33
  };
32
34
  };
33
35
  export const getNumberValidator = (params = {}) => {
34
- const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreNumberCheck, ignoreMaximumCheck, ignoreMinimumCheck, ignoreIntCheck, ignoreDotEnd, ignoreZeroStart, } = params;
36
+ const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreNumberCheck, ignoreMaximumCheck, ignoreMinimumCheck, ignoreIntCheck, ignoreDotEnd, ignoreZeroStart, customErrorMessages, } = params;
37
+ const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
38
+ // eslint-disable-next-line complexity
35
39
  return (spec, value = '') => {
36
40
  const stringValue = String(value);
37
41
  if (!ignoreRequiredCheck && spec.required && !stringValue.length) {
38
- return ErrorMessages.REQUIRED;
42
+ return errorMessages.REQUIRED;
39
43
  }
40
44
  if (stringValue.length) {
41
45
  if (!ignoreSpaceStartCheck && !stringValue[0].trim()) {
42
- return ErrorMessages.SPACE_START;
46
+ return errorMessages.SPACE_START;
43
47
  }
44
48
  if (!ignoreSpaceEndCheck && !stringValue[stringValue.length - 1].trim()) {
45
- return ErrorMessages.SPACE_END;
49
+ return errorMessages.SPACE_END;
46
50
  }
47
51
  if (!ignoreDotEnd && stringValue[stringValue.length - 1] === '.') {
48
- return ErrorMessages.DOT_END;
52
+ return errorMessages.DOT_END;
49
53
  }
50
54
  if (!ignoreNumberCheck && !isFloat(stringValue)) {
51
- return ErrorMessages.NUMBER;
55
+ return errorMessages.NUMBER;
52
56
  }
53
57
  if (!ignoreZeroStart &&
54
58
  ((stringValue.length > 1 && stringValue[0] === '0' && stringValue[1] !== '.') ||
55
59
  (stringValue.length > 2 &&
56
60
  stringValue.substring(0, 2) === '-0' &&
57
61
  stringValue[2] !== '.'))) {
58
- return ErrorMessages.ZERO_START;
62
+ return errorMessages.ZERO_START;
59
63
  }
60
64
  }
61
65
  if (!ignoreMaximumCheck &&
62
66
  _.isNumber(spec.maximum) &&
63
67
  stringValue.length &&
64
68
  Number(stringValue) > spec.maximum) {
65
- return ErrorMessages.maxNumber(spec.maximum);
69
+ return errorMessages.maxNumber(spec.maximum);
66
70
  }
67
71
  if (!ignoreMinimumCheck &&
68
72
  _.isNumber(spec.minimum) &&
69
73
  stringValue.length &&
70
74
  spec.minimum > Number(stringValue)) {
71
- return ErrorMessages.minNumber(spec.minimum);
75
+ return errorMessages.minNumber(spec.minimum);
72
76
  }
73
77
  if (_.isString(spec.format) && stringValue.length) {
74
78
  if (!ignoreIntCheck && spec.format === 'int64' && !isInt(stringValue)) {
75
- return ErrorMessages.INT;
79
+ return errorMessages.INT;
76
80
  }
77
81
  }
78
82
  return false;
79
83
  };
80
84
  };
81
85
  export const getObjectValidator = (params = {}) => {
82
- const { ignoreRequiredCheck } = params;
86
+ const { ignoreRequiredCheck, customErrorMessages } = params;
87
+ const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
83
88
  return (spec, value) => {
84
89
  if (!ignoreRequiredCheck && spec.required && !value) {
85
- return ErrorMessages.REQUIRED;
90
+ return errorMessages.REQUIRED;
86
91
  }
87
92
  return false;
88
93
  };
89
94
  };
90
95
  export const getStringValidator = (params = {}) => {
91
- const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck, ignoreRegExpCheck, } = params;
96
+ const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck, ignoreRegExpCheck, customErrorMessages, } = params;
97
+ const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
98
+ // eslint-disable-next-line complexity
92
99
  return (spec, value = '') => {
93
100
  const valueLength = value === null || value === void 0 ? void 0 : value.length;
94
101
  if (!ignoreRequiredCheck && spec.required && !valueLength) {
95
- return ErrorMessages.REQUIRED;
102
+ return errorMessages.REQUIRED;
96
103
  }
97
104
  if (valueLength) {
98
105
  if (!ignoreSpaceStartCheck && !value[0].trim()) {
99
- return ErrorMessages.SPACE_START;
106
+ return errorMessages.SPACE_START;
100
107
  }
101
108
  if (!ignoreSpaceEndCheck && !value[value.length - 1].trim()) {
102
- return ErrorMessages.SPACE_END;
109
+ return errorMessages.SPACE_END;
103
110
  }
104
111
  }
105
112
  if (!ignoreMaxLengthCheck &&
106
113
  typeof spec.maxLength === 'bigint' &&
107
114
  valueLength > spec.maxLength) {
108
- return ErrorMessages.maxLength(spec.maxLength);
115
+ return errorMessages.maxLength(spec.maxLength);
109
116
  }
110
117
  if (!ignoreMinLengthCheck &&
111
118
  typeof spec.minLength === 'bigint' &&
112
119
  valueLength < spec.minLength) {
113
- return ErrorMessages.minLength(spec.minLength);
120
+ return errorMessages.minLength(spec.minLength);
114
121
  }
115
122
  if (_.isString(spec.pattern) && spec.pattern.length) {
116
123
  const regex = new RegExp(spec.pattern);
117
124
  if (!ignoreRegExpCheck && !regex.test(value)) {
118
125
  return _.isString(spec.patternError) && spec.patternError.length
119
126
  ? spec.patternError
120
- : ErrorMessages.INVALID;
127
+ : errorMessages.INVALID;
121
128
  }
122
129
  }
123
130
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "3.3.0",
3
+ "version": "3.4.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",
@@ -34,7 +34,13 @@
34
34
  "build-storybook": "sb build",
35
35
  "dev": "sb dev -p 6006",
36
36
  "start": "sb dev",
37
- "prepublishOnly": "npm run build"
37
+ "prepublishOnly": "npm run build",
38
+ "playwright:install": "playwright install --with-deps",
39
+ "playwright": "playwright test --config=playwright/playwright.config.ts",
40
+ "playwright:update": "npm run playwright -- -u",
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"
38
44
  },
39
45
  "dependencies": {
40
46
  "@bem-react/classname": "^1.6.0",
@@ -53,6 +59,8 @@
53
59
  "@gravity-ui/stylelint-config": "^2.0.0",
54
60
  "@gravity-ui/tsconfig": "^1.0.0",
55
61
  "@gravity-ui/uikit": "^5.19.1",
62
+ "@playwright/experimental-ct-react": "^1.40.0",
63
+ "@playwright/test": "^1.40.0",
56
64
  "@storybook/addon-essentials": "^7.0.27",
57
65
  "@storybook/preset-scss": "^1.0.3",
58
66
  "@storybook/react": "^7.0.27",
@@ -66,6 +74,7 @@
66
74
  "@types/react-dom": "^18.0.11",
67
75
  "@types/react-is": "^17.0.3",
68
76
  "@types/uuid": "^9.0.4",
77
+ "@vitejs/plugin-react": "^4.2.0",
69
78
  "css-loader": "^5.2.6",
70
79
  "eslint": "^8.27.0",
71
80
  "final-form": "^4.20.2",