@gravity-ui/dynamic-forms 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.6.2](https://github.com/gravity-ui/dynamic-forms/compare/v1.6.1...v1.6.2) (2023-05-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * add css rule for errors ([#41](https://github.com/gravity-ui/dynamic-forms/issues/41)) ([a6661bc](https://github.com/gravity-ui/dynamic-forms/commit/a6661bcd3a86a29ec3b457bccbf6d8f46aaf0408))
9
+ * add number value transform ([#40](https://github.com/gravity-ui/dynamic-forms/issues/40)) ([d422d90](https://github.com/gravity-ui/dynamic-forms/commit/d422d901e675c6f7014a07f9bfae972fcd555b76))
10
+
11
+ ## [1.6.1](https://github.com/gravity-ui/dynamic-forms/compare/v1.6.0...v1.6.1) (2023-05-02)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * object inputs layout child ([#37](https://github.com/gravity-ui/dynamic-forms/issues/37)) ([821398e](https://github.com/gravity-ui/dynamic-forms/commit/821398eee3b19b590f6177896fc038ecd9bdd0df))
17
+
3
18
  ## [1.6.0](https://github.com/gravity-ui/dynamic-forms/compare/v1.5.0...v1.6.0) (2023-04-28)
4
19
 
5
20
 
@@ -52,7 +52,10 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
52
52
  setState((state) => {
53
53
  const _value = lodash_1.default.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
54
54
  const error = validate === null || validate === void 0 ? void 0 : validate(_value);
55
- const value = (0, utils_1.transformArrIn)(_value);
55
+ let value = (0, utils_1.transformArrIn)(_value);
56
+ if ((0, helpers_1.isNumberSpec)(spec) && value && !error) {
57
+ value = Number(value);
58
+ }
56
59
  let newChildErrors = Object.assign({}, state.childErrors);
57
60
  if (childErrors) {
58
61
  const nearestChildName = lodash_1.default.keys(childErrors).sort((a, b) => a.length - b.length)[0];
@@ -73,7 +76,7 @@ const useField = ({ name, spec, initialValue, validate: propsValidate, tools, pa
73
76
  }
74
77
  };
75
78
  return { onChange, onDrop };
76
- }, [initialValue, setState, name, validate]);
79
+ }, [initialValue, setState, name, validate, spec]);
77
80
  const onBlur = react_1.default.useCallback(() => {
78
81
  setState((state) => (Object.assign(Object.assign({}, state), { active: false, touched: true })));
79
82
  }, [setState]);
@@ -12,6 +12,7 @@
12
12
  .df-error-wrapper_error .g-select:not(.df-error-wrapper-ignore) .g-select-control::before,
13
13
  .df-error-wrapper_error .g-select:hover:not(.df-error-wrapper-ignore) .g-select-control_open::before,
14
14
  .df-error-wrapper_error .yc-text-input_view_normal:not(.df-error-wrapper-ignore) .yc-text-input__control,
15
+ .df-error-wrapper_error .yc-text-input_view_normal:not(.df-error-wrapper-ignore) .yc-text-input__content,
15
16
  .df-error-wrapper_error .yc-checkbox__indicator:not(.df-error-wrapper-ignore)::before {
16
17
  border-color: var(--yc-color-text-danger);
17
18
  }
@@ -15,7 +15,7 @@ const ObjectValueInput = (props) => {
15
15
  var _a;
16
16
  if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[OBJECT_VALUE_PROPERTY_NAME]) {
17
17
  const childSpec = lodash_1.default.cloneDeep(spec.properties[OBJECT_VALUE_PROPERTY_NAME]);
18
- childSpec.viewSpec.layout = '';
18
+ childSpec.viewSpec.layout = 'transparent';
19
19
  return childSpec;
20
20
  }
21
21
  return undefined;
@@ -13,7 +13,7 @@ const Secret = (props) => {
13
13
  var _a, _b;
14
14
  if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[SECRET_PROPERTY_NAME]) {
15
15
  const childSpec = lodash_1.default.cloneDeep((_b = spec.properties) === null || _b === void 0 ? void 0 : _b[SECRET_PROPERTY_NAME]);
16
- childSpec.viewSpec.layout = '';
16
+ childSpec.viewSpec.layout = 'transparent';
17
17
  return childSpec;
18
18
  }
19
19
  return undefined;
@@ -16,7 +16,7 @@ const TextLink = (props) => {
16
16
  if (((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[TEXT_LINK_PROPERTY_NAME]) &&
17
17
  (0, core_1.isStringSpec)(spec.properties[TEXT_LINK_PROPERTY_NAME])) {
18
18
  const childSpec = lodash_1.default.cloneDeep(spec.properties[TEXT_LINK_PROPERTY_NAME]);
19
- childSpec.viewSpec.layout = '';
19
+ childSpec.viewSpec.layout = 'transparent';
20
20
  return childSpec;
21
21
  }
22
22
  return undefined;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import _ from 'lodash';
3
- import { isArraySpec, isObjectSpec, isReact18OrMore } from '../../../helpers';
3
+ import { isArraySpec, isNumberSpec, isObjectSpec, isReact18OrMore } from '../../../helpers';
4
4
  import { OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, REMOVED_ITEM } from '../constants';
5
5
  import { isArrayItem, transformArrIn, transformArrOut } from '../utils';
6
6
  export const useField = ({ name, spec, initialValue, validate: propsValidate, tools, parentOnChange, parentOnUnmount, }) => {
@@ -48,7 +48,10 @@ export const useField = ({ name, spec, initialValue, validate: propsValidate, to
48
48
  setState((state) => {
49
49
  const _value = _.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
50
50
  const error = validate === null || validate === void 0 ? void 0 : validate(_value);
51
- const value = transformArrIn(_value);
51
+ let value = transformArrIn(_value);
52
+ if (isNumberSpec(spec) && value && !error) {
53
+ value = Number(value);
54
+ }
52
55
  let newChildErrors = Object.assign({}, state.childErrors);
53
56
  if (childErrors) {
54
57
  const nearestChildName = _.keys(childErrors).sort((a, b) => a.length - b.length)[0];
@@ -69,7 +72,7 @@ export const useField = ({ name, spec, initialValue, validate: propsValidate, to
69
72
  }
70
73
  };
71
74
  return { onChange, onDrop };
72
- }, [initialValue, setState, name, validate]);
75
+ }, [initialValue, setState, name, validate, spec]);
73
76
  const onBlur = React.useCallback(() => {
74
77
  setState((state) => (Object.assign(Object.assign({}, state), { active: false, touched: true })));
75
78
  }, [setState]);
@@ -12,6 +12,7 @@
12
12
  .df-error-wrapper_error .g-select:not(.df-error-wrapper-ignore) .g-select-control::before,
13
13
  .df-error-wrapper_error .g-select:hover:not(.df-error-wrapper-ignore) .g-select-control_open::before,
14
14
  .df-error-wrapper_error .yc-text-input_view_normal:not(.df-error-wrapper-ignore) .yc-text-input__control,
15
+ .df-error-wrapper_error .yc-text-input_view_normal:not(.df-error-wrapper-ignore) .yc-text-input__content,
15
16
  .df-error-wrapper_error .yc-checkbox__indicator:not(.df-error-wrapper-ignore)::before {
16
17
  border-color: var(--yc-color-text-danger);
17
18
  }
@@ -11,7 +11,7 @@ export const ObjectValueInput = (props) => {
11
11
  var _a;
12
12
  if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[OBJECT_VALUE_PROPERTY_NAME]) {
13
13
  const childSpec = _.cloneDeep(spec.properties[OBJECT_VALUE_PROPERTY_NAME]);
14
- childSpec.viewSpec.layout = '';
14
+ childSpec.viewSpec.layout = 'transparent';
15
15
  return childSpec;
16
16
  }
17
17
  return undefined;
@@ -9,7 +9,7 @@ export const Secret = (props) => {
9
9
  var _a, _b;
10
10
  if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[SECRET_PROPERTY_NAME]) {
11
11
  const childSpec = _.cloneDeep((_b = spec.properties) === null || _b === void 0 ? void 0 : _b[SECRET_PROPERTY_NAME]);
12
- childSpec.viewSpec.layout = '';
12
+ childSpec.viewSpec.layout = 'transparent';
13
13
  return childSpec;
14
14
  }
15
15
  return undefined;
@@ -12,7 +12,7 @@ export const TextLink = (props) => {
12
12
  if (((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[TEXT_LINK_PROPERTY_NAME]) &&
13
13
  isStringSpec(spec.properties[TEXT_LINK_PROPERTY_NAME])) {
14
14
  const childSpec = _.cloneDeep(spec.properties[TEXT_LINK_PROPERTY_NAME]);
15
- childSpec.viewSpec.layout = '';
15
+ childSpec.viewSpec.layout = 'transparent';
16
16
  return childSpec;
17
17
  }
18
18
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",