assui 3.2.105 → 3.2.106

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.
@@ -12,7 +12,7 @@ export interface ComplexValSelectOptionType extends Omit<DefaultOptionType, 'val
12
12
  export declare const isReferenceTypeOption: (options?: ComplexValSelectOptionType[]) => boolean;
13
13
  export interface ComplexValSelectProps<T> extends Omit<SelectProps, 'value' | 'onChange' | 'options'> {
14
14
  value?: T;
15
- onChange?: (val: T, opt?: ComplexValSelectOptionType[]) => void;
15
+ onChange?: (val: T, opt?: ComplexValSelectOptionType | ComplexValSelectOptionType[]) => void;
16
16
  options?: ComplexValSelectOptionType[];
17
17
  }
18
18
  declare const ComplexValSelect: React.ForwardRefExoticComponent<ComplexValSelectProps<ComplexValSelectValueType> & React.RefAttributes<unknown>>;
@@ -32,10 +32,10 @@ var __read = this && this.__read || function (o, n) {
32
32
  };
33
33
  import * as React from 'react';
34
34
  import omit from 'lodash/omit';
35
- import find from 'lodash/find';
36
35
  import some from 'lodash/some';
37
36
  import isArray from 'lodash/isArray';
38
37
  import isObject from 'lodash/isObject';
38
+ import isUndefined from 'lodash/isUndefined';
39
39
  import Select from "antd/es/select";
40
40
  import classNames from 'classnames';
41
41
  import ArrowDownOutlined from "a-icons/es/ArrowDownOutlined";
@@ -50,7 +50,7 @@ var _formatOptions = function formatOptions(dateSource) {
50
50
  } : {};
51
51
  return __assign(__assign(__assign({}, item), {
52
52
  label: item.label,
53
- value: item.value ? JSON.stringify(item.value) : undefined
53
+ value: isUndefined(item.value) ? undefined : JSON.stringify(item.value)
54
54
  }), otherProps);
55
55
  });
56
56
  return options;
@@ -85,25 +85,35 @@ var ComplexValSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
85
85
  // 判断是否需要将optionValue转为JSON字符串
86
86
  var isReferenceTypeVal = isReferenceTypeOption(options);
87
87
  var finalOptions = isReferenceTypeVal ? _formatOptions(options) : options;
88
- var handleChange = function handleChange(val) {
89
- var nextVal = val && isReferenceTypeVal ? JSON.parse(val) : val;
90
- setValue(nextVal, options);
88
+ var handleChange = function handleChange(val, option) {
89
+ var nextVal = val;
90
+ if (val && isReferenceTypeVal) {
91
+ nextVal = isArray(val) ? val.map(function (item) {
92
+ return JSON.parse(item);
93
+ }) : JSON.parse(val);
94
+ }
95
+ setValue(nextVal, option);
91
96
  };
92
- var handleSelect = function handleSelect(val) {
97
+ var handleSelect = function handleSelect(val, option) {
93
98
  var nextVal = val && isReferenceTypeVal ? JSON.parse(val) : val;
94
- var selectOption = find(finalOptions, {
95
- value: val
96
- });
97
- onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextVal, selectOption);
99
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextVal, option);
98
100
  };
101
+ var displayValue = React.useMemo(function () {
102
+ if (value && isReferenceTypeVal) {
103
+ return isArray(value) ? value.map(function (v) {
104
+ return JSON.stringify(v);
105
+ }) : JSON.stringify(value);
106
+ }
107
+ return value;
108
+ }, [value, isReferenceTypeVal]);
99
109
  return /*#__PURE__*/React.createElement(Select, __assign({
100
110
  ref: selectRef,
101
111
  className: classNames('complex-val-select', props === null || props === void 0 ? void 0 : props.className),
102
112
  suffixIcon: /*#__PURE__*/React.createElement(ArrowDownOutlined, null),
103
- value: value && isReferenceTypeVal ? JSON.stringify(value) : value,
113
+ value: displayValue,
104
114
  options: finalOptions,
105
115
  onChange: handleChange,
106
116
  onSelect: handleSelect
107
- }, omit(props, ['value', 'onChange', 'options', 'onSelect', 'className'])));
117
+ }, omit(props, ['value', 'defaultValue', 'onChange', 'options', 'onSelect', 'className'])));
108
118
  });
109
119
  export default ComplexValSelect;
@@ -12,7 +12,7 @@ export interface ComplexValSelectOptionType extends Omit<DefaultOptionType, 'val
12
12
  export declare const isReferenceTypeOption: (options?: ComplexValSelectOptionType[]) => boolean;
13
13
  export interface ComplexValSelectProps<T> extends Omit<SelectProps, 'value' | 'onChange' | 'options'> {
14
14
  value?: T;
15
- onChange?: (val: T, opt?: ComplexValSelectOptionType[]) => void;
15
+ onChange?: (val: T, opt?: ComplexValSelectOptionType | ComplexValSelectOptionType[]) => void;
16
16
  options?: ComplexValSelectOptionType[];
17
17
  }
18
18
  declare const ComplexValSelect: React.ForwardRefExoticComponent<ComplexValSelectProps<ComplexValSelectValueType> & React.RefAttributes<unknown>>;
@@ -74,10 +74,10 @@ Object.defineProperty(exports, "__esModule", {
74
74
  exports.isReferenceTypeOption = exports.Option = void 0;
75
75
  var React = __importStar(require("react"));
76
76
  var omit_1 = __importDefault(require("lodash/omit"));
77
- var find_1 = __importDefault(require("lodash/find"));
78
77
  var some_1 = __importDefault(require("lodash/some"));
79
78
  var isArray_1 = __importDefault(require("lodash/isArray"));
80
79
  var isObject_1 = __importDefault(require("lodash/isObject"));
80
+ var isUndefined_1 = __importDefault(require("lodash/isUndefined"));
81
81
  var select_1 = __importDefault(require("antd/lib/select"));
82
82
  var classnames_1 = __importDefault(require("classnames"));
83
83
  var ArrowDownOutlined_1 = __importDefault(require("a-icons/lib/ArrowDownOutlined"));
@@ -92,7 +92,7 @@ var _formatOptions = function formatOptions(dateSource) {
92
92
  } : {};
93
93
  return __assign(__assign(__assign({}, item), {
94
94
  label: item.label,
95
- value: item.value ? JSON.stringify(item.value) : undefined
95
+ value: (0, isUndefined_1["default"])(item.value) ? undefined : JSON.stringify(item.value)
96
96
  }), otherProps);
97
97
  });
98
98
  return options;
@@ -128,25 +128,35 @@ var ComplexValSelect = React.forwardRef(function (props, ref) {
128
128
  // 判断是否需要将optionValue转为JSON字符串
129
129
  var isReferenceTypeVal = (0, exports.isReferenceTypeOption)(options);
130
130
  var finalOptions = isReferenceTypeVal ? _formatOptions(options) : options;
131
- var handleChange = function handleChange(val) {
132
- var nextVal = val && isReferenceTypeVal ? JSON.parse(val) : val;
133
- setValue(nextVal, options);
131
+ var handleChange = function handleChange(val, option) {
132
+ var nextVal = val;
133
+ if (val && isReferenceTypeVal) {
134
+ nextVal = (0, isArray_1["default"])(val) ? val.map(function (item) {
135
+ return JSON.parse(item);
136
+ }) : JSON.parse(val);
137
+ }
138
+ setValue(nextVal, option);
134
139
  };
135
- var handleSelect = function handleSelect(val) {
140
+ var handleSelect = function handleSelect(val, option) {
136
141
  var nextVal = val && isReferenceTypeVal ? JSON.parse(val) : val;
137
- var selectOption = (0, find_1["default"])(finalOptions, {
138
- value: val
139
- });
140
- onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextVal, selectOption);
142
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextVal, option);
141
143
  };
144
+ var displayValue = React.useMemo(function () {
145
+ if (value && isReferenceTypeVal) {
146
+ return (0, isArray_1["default"])(value) ? value.map(function (v) {
147
+ return JSON.stringify(v);
148
+ }) : JSON.stringify(value);
149
+ }
150
+ return value;
151
+ }, [value, isReferenceTypeVal]);
142
152
  return React.createElement(select_1["default"], __assign({
143
153
  ref: selectRef,
144
154
  className: (0, classnames_1["default"])('complex-val-select', props === null || props === void 0 ? void 0 : props.className),
145
155
  suffixIcon: React.createElement(ArrowDownOutlined_1["default"], null),
146
- value: value && isReferenceTypeVal ? JSON.stringify(value) : value,
156
+ value: displayValue,
147
157
  options: finalOptions,
148
158
  onChange: handleChange,
149
159
  onSelect: handleSelect
150
- }, (0, omit_1["default"])(props, ['value', 'onChange', 'options', 'onSelect', 'className'])));
160
+ }, (0, omit_1["default"])(props, ['value', 'defaultValue', 'onChange', 'options', 'onSelect', 'className'])));
151
161
  });
152
162
  exports["default"] = ComplexValSelect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assui",
3
- "version": "3.2.105",
3
+ "version": "3.2.106",
4
4
  "description": "react ui library",
5
5
  "author": "jason <usochen@gmail.com>",
6
6
  "main": "./lib/index.js",
@@ -87,5 +87,5 @@
87
87
  "node": ">=10.0.0"
88
88
  },
89
89
  "license": "MIT",
90
- "gitHead": "339f0ad113cd267b75bf7ae54131dd66e0034a28"
90
+ "gitHead": "a733655570b6114592c403f0a0e9df03f438e686"
91
91
  }