@gravity-ui/dynamic-forms 5.23.0 → 5.23.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.
@@ -8,7 +8,7 @@ export interface ArraySpec<LinkType = any, InputComponentProps extends Record<st
8
8
  maxLength?: bigint;
9
9
  minLength?: bigint;
10
10
  items?: Spec;
11
- enum?: string[];
11
+ enum?: Array<string | number>;
12
12
  description?: Record<string, string>;
13
13
  validator?: string;
14
14
  viewSpec: {
@@ -16,17 +16,19 @@ const MultiSelect = ({ name, input, spec, inputProps }) => {
16
16
  var _a;
17
17
  return withCustomOptions
18
18
  ? externalOptions || []
19
- : (_a = spec.enum) === null || _a === void 0 ? void 0 : _a.map((id) => {
20
- var _a, _b, _c, _d, _e;
21
- return ({
22
- id,
23
- value: id,
24
- text: ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[id]) || id,
25
- content: ((_c = (_b = spec.viewSpec.selectParams) === null || _b === void 0 ? void 0 : _b.meta) === null || _c === void 0 ? void 0 : _c[id]) ? (react_1.default.createElement("div", { key: id },
26
- react_1.default.createElement(uikit_1.Text, null, ((_d = spec.description) === null || _d === void 0 ? void 0 : _d[id]) || id),
27
- react_1.default.createElement(uikit_1.Text, { color: "secondary", className: b('meta-text') }, spec.viewSpec.selectParams.meta[id]))) : (((_e = spec.description) === null || _e === void 0 ? void 0 : _e[id]) || id),
28
- key: id,
29
- });
19
+ : (_a = spec.enum) === null || _a === void 0 ? void 0 : _a.map((enumValue) => {
20
+ var _a, _b, _c;
21
+ const value = String(enumValue);
22
+ const text = ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[value]) || value;
23
+ return {
24
+ id: value,
25
+ value,
26
+ text,
27
+ content: ((_c = (_b = spec.viewSpec.selectParams) === null || _b === void 0 ? void 0 : _b.meta) === null || _c === void 0 ? void 0 : _c[value]) ? (react_1.default.createElement("div", { key: value },
28
+ react_1.default.createElement(uikit_1.Text, null, text),
29
+ react_1.default.createElement(uikit_1.Text, { color: "secondary", className: b('meta-text') }, spec.viewSpec.selectParams.meta[value]))) : (text),
30
+ key: value,
31
+ };
30
32
  });
31
33
  }, [
32
34
  spec.enum,
@@ -53,8 +55,17 @@ const MultiSelect = ({ name, input, spec, inputProps }) => {
53
55
  onBlur();
54
56
  }
55
57
  }, [onFocus, onBlur]);
56
- const _value = react_1.default.useMemo(() => (0, core_1.transformArrOut)(value), [value]);
57
- const handleChange = react_1.default.useCallback((value) => onChange((0, core_1.transformArrIn)(value)), [onChange]);
58
+ const _value = react_1.default.useMemo(() => {
59
+ var _a;
60
+ return (_a = (0, core_1.transformArrOut)(value)) === null || _a === void 0 ? void 0 : _a.map(String);
61
+ }, [value]);
62
+ const handleChange = react_1.default.useCallback((value) => {
63
+ const enumValues = value.map((selectedValue) => {
64
+ var _a, _b;
65
+ return (_b = (_a = spec.enum) === null || _a === void 0 ? void 0 : _a.find((enumValue) => String(enumValue) === selectedValue)) !== null && _b !== void 0 ? _b : selectedValue;
66
+ });
67
+ onChange((0, core_1.transformArrIn)(enumValues));
68
+ }, [onChange, spec.enum]);
58
69
  return (react_1.default.createElement(uikit_1.Select, Object.assign({ width: "max", className: b(), filterable: filterable, renderOption: renderOption, getOptionHeight: getOptionHeight }, inputProps, { value: _value, options: options, onUpdate: handleChange, onOpenChange: handleToggle, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, filterPlaceholder: (_d = spec.viewSpec.selectParams) === null || _d === void 0 ? void 0 : _d.filterPlaceholder, multiple: true, qa: name })));
59
70
  };
60
71
  exports.MultiSelect = MultiSelect;
@@ -8,7 +8,7 @@ export interface ArraySpec<LinkType = any, InputComponentProps extends Record<st
8
8
  maxLength?: bigint;
9
9
  minLength?: bigint;
10
10
  items?: Spec;
11
- enum?: string[];
11
+ enum?: Array<string | number>;
12
12
  description?: Record<string, string>;
13
13
  validator?: string;
14
14
  viewSpec: {
@@ -13,17 +13,19 @@ export const MultiSelect = ({ name, input, spec, inputProps }) => {
13
13
  var _a;
14
14
  return withCustomOptions
15
15
  ? externalOptions || []
16
- : (_a = spec.enum) === null || _a === void 0 ? void 0 : _a.map((id) => {
17
- var _a, _b, _c, _d, _e;
18
- return ({
19
- id,
20
- value: id,
21
- text: ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[id]) || id,
22
- content: ((_c = (_b = spec.viewSpec.selectParams) === null || _b === void 0 ? void 0 : _b.meta) === null || _c === void 0 ? void 0 : _c[id]) ? (React.createElement("div", { key: id },
23
- React.createElement(Text, null, ((_d = spec.description) === null || _d === void 0 ? void 0 : _d[id]) || id),
24
- React.createElement(Text, { color: "secondary", className: b('meta-text') }, spec.viewSpec.selectParams.meta[id]))) : (((_e = spec.description) === null || _e === void 0 ? void 0 : _e[id]) || id),
25
- key: id,
26
- });
16
+ : (_a = spec.enum) === null || _a === void 0 ? void 0 : _a.map((enumValue) => {
17
+ var _a, _b, _c;
18
+ const value = String(enumValue);
19
+ const text = ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[value]) || value;
20
+ return {
21
+ id: value,
22
+ value,
23
+ text,
24
+ content: ((_c = (_b = spec.viewSpec.selectParams) === null || _b === void 0 ? void 0 : _b.meta) === null || _c === void 0 ? void 0 : _c[value]) ? (React.createElement("div", { key: value },
25
+ React.createElement(Text, null, text),
26
+ React.createElement(Text, { color: "secondary", className: b('meta-text') }, spec.viewSpec.selectParams.meta[value]))) : (text),
27
+ key: value,
28
+ };
27
29
  });
28
30
  }, [
29
31
  spec.enum,
@@ -50,7 +52,16 @@ export const MultiSelect = ({ name, input, spec, inputProps }) => {
50
52
  onBlur();
51
53
  }
52
54
  }, [onFocus, onBlur]);
53
- const _value = React.useMemo(() => transformArrOut(value), [value]);
54
- const handleChange = React.useCallback((value) => onChange(transformArrIn(value)), [onChange]);
55
+ const _value = React.useMemo(() => {
56
+ var _a;
57
+ return (_a = transformArrOut(value)) === null || _a === void 0 ? void 0 : _a.map(String);
58
+ }, [value]);
59
+ const handleChange = React.useCallback((value) => {
60
+ const enumValues = value.map((selectedValue) => {
61
+ var _a, _b;
62
+ return (_b = (_a = spec.enum) === null || _a === void 0 ? void 0 : _a.find((enumValue) => String(enumValue) === selectedValue)) !== null && _b !== void 0 ? _b : selectedValue;
63
+ });
64
+ onChange(transformArrIn(enumValues));
65
+ }, [onChange, spec.enum]);
55
66
  return (React.createElement(Select, Object.assign({ width: "max", className: b(), filterable: filterable, renderOption: renderOption, getOptionHeight: getOptionHeight }, inputProps, { value: _value, options: options, onUpdate: handleChange, onOpenChange: handleToggle, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, filterPlaceholder: (_d = spec.viewSpec.selectParams) === null || _d === void 0 ? void 0 : _d.filterPlaceholder, multiple: true, qa: name })));
56
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "5.23.0",
3
+ "version": "5.23.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",