assui 3.2.106 → 3.3.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.
@@ -1,14 +1,12 @@
1
1
  import * as React from 'react';
2
2
  import type { DefaultOptionType, SelectProps } from 'antd/lib/select';
3
- declare const Option: import("rc-select/lib/Option").OptionFC;
4
- export { Option };
5
3
  export type ComplexValSelectValueType = string | number | any[] | Record<string, any> | null | undefined;
6
4
  export interface ComplexValSelectOptionType extends Omit<DefaultOptionType, 'value' | 'children' | 'options'> {
7
5
  value?: ComplexValSelectValueType;
8
6
  children?: ComplexValSelectOptionType[];
9
7
  options?: Omit<ComplexValSelectOptionType, 'children' | 'options'>[];
10
8
  }
11
- /** 判断optionsValue是否是引用类型 */
9
+ /** 判断 options 的 value 中是否包含引用类型(对象或数组) */
12
10
  export declare const isReferenceTypeOption: (options?: ComplexValSelectOptionType[]) => boolean;
13
11
  export interface ComplexValSelectProps<T> extends Omit<SelectProps, 'value' | 'onChange' | 'options'> {
14
12
  value?: T;
@@ -17,3 +15,6 @@ export interface ComplexValSelectProps<T> extends Omit<SelectProps, 'value' | 'o
17
15
  }
18
16
  declare const ComplexValSelect: React.ForwardRefExoticComponent<ComplexValSelectProps<ComplexValSelectValueType> & React.RefAttributes<unknown>>;
19
17
  export default ComplexValSelect;
18
+ declare const Option: import("rc-select/lib/Option").OptionFC;
19
+ export { Option };
20
+ export { stableStringify } from 'aa-utils';
@@ -40,27 +40,34 @@ import Select from "antd/es/select";
40
40
  import classNames from 'classnames';
41
41
  import ArrowDownOutlined from "a-icons/es/ArrowDownOutlined";
42
42
  import useControllableValue from "ahooks/es/useControllableValue";
43
- var Option = Select.Option;
44
- export { Option };
45
- var _formatOptions = function formatOptions(dateSource) {
46
- if (dateSource) {
47
- var options = dateSource.map(function (item) {
48
- var otherProps = item.options ? {
49
- options: _formatOptions(item.options)
50
- } : {};
51
- return __assign(__assign(__assign({}, item), {
52
- label: item.label,
53
- value: isUndefined(item.value) ? undefined : JSON.stringify(item.value)
54
- }), otherProps);
55
- });
56
- return options;
43
+ import { stableStringify } from 'aa-utils';
44
+ import { isNil } from 'lodash';
45
+ // 核心防御:防止非标准 JSON 字符串(如 tags 模式下手敲的纯文本或 undefined)导致页面崩溃
46
+ var safeParse = function safeParse(str) {
47
+ if (typeof str !== 'string') return str;
48
+ try {
49
+ return JSON.parse(str);
50
+ } catch (_a) {
51
+ return str; // 解析失败直接返回原字符串
57
52
  }
58
- return dateSource;
59
53
  };
60
- /** 判断optionsValue是否是引用类型 */
54
+ /** 递归格式化 options,将复杂 value 序列化为字符串 */
55
+ var _formatOptions = function formatOptions(dataSource) {
56
+ if (!dataSource) return dataSource;
57
+ return dataSource.map(function (item) {
58
+ var otherProps = item.options ? {
59
+ options: _formatOptions(item.options)
60
+ } : {};
61
+ return __assign(__assign(__assign({}, item), {
62
+ label: item.label,
63
+ value: isUndefined(item.value) ? undefined : stableStringify(item.value)
64
+ }), otherProps);
65
+ });
66
+ };
67
+ /** 判断 options 的 value 中是否包含引用类型(对象或数组) */
61
68
  export var isReferenceTypeOption = function isReferenceTypeOption(options) {
62
- var resultBoolean = some(options, function (item) {
63
- if (item.value) {
69
+ return some(options, function (item) {
70
+ if (!isUndefined(item.value)) {
64
71
  return isArray(item.value) || isObject(item.value);
65
72
  }
66
73
  if (item.options) {
@@ -70,42 +77,48 @@ export var isReferenceTypeOption = function isReferenceTypeOption(options) {
70
77
  }
71
78
  return false;
72
79
  });
73
- return resultBoolean;
74
80
  };
75
81
  var ComplexValSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
76
82
  var _a = __read(useControllableValue(props), 2),
77
83
  value = _a[0],
78
84
  setValue = _a[1];
79
85
  var options = props.options,
80
- onSelect = props.onSelect;
86
+ onSelect = props.onSelect,
87
+ mode = props.mode;
81
88
  var selectRef = React.useRef(null);
82
89
  React.useImperativeHandle(ref, function () {
83
90
  return selectRef.current;
84
91
  });
85
- // 判断是否需要将optionValue转为JSON字符串
92
+ // 判断是否为多选模式 (multiple 或 tags)
93
+ var isMultiple = mode === 'multiple' || mode === 'tags';
94
+ // 判断是否需要将 option 的 value 转为 JSON 字符串
86
95
  var isReferenceTypeVal = isReferenceTypeOption(options);
87
96
  var finalOptions = isReferenceTypeVal ? _formatOptions(options) : options;
97
+ // 处理选中值改变:将底层传出的字符串安全地 parse 回真实的数据结构
88
98
  var handleChange = function handleChange(val, option) {
89
99
  var nextVal = val;
90
- if (val && isReferenceTypeVal) {
91
- nextVal = isArray(val) ? val.map(function (item) {
92
- return JSON.parse(item);
93
- }) : JSON.parse(val);
100
+ if (!isNil(val) && isReferenceTypeVal) {
101
+ nextVal = isMultiple && isArray(val) ? val.map(function (item) {
102
+ return safeParse(item);
103
+ }) : safeParse(val);
94
104
  }
95
105
  setValue(nextVal, option);
96
106
  };
97
107
  var handleSelect = function handleSelect(val, option) {
98
- var nextVal = val && isReferenceTypeVal ? JSON.parse(val) : val;
108
+ var nextVal = !isNil(val) && isReferenceTypeVal ? safeParse(val) : val;
99
109
  onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextVal, option);
100
110
  };
111
+ // 处理回显展示值:将传入的真实数据结构 stringify 成字符串去匹配底层 Option
101
112
  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);
113
+ if (!isNil(value) && isReferenceTypeVal) {
114
+ return isMultiple && isArray(value) ? value.map(function (v) {
115
+ // 在 tags 模式下,如果 v 已经是手敲的基础字符串,直接放行,避免产生多余的双引号
116
+ if (mode === 'tags' && typeof v === 'string') return v;
117
+ return stableStringify(v);
118
+ }) : stableStringify(value);
106
119
  }
107
120
  return value;
108
- }, [value, isReferenceTypeVal]);
121
+ }, [value, isReferenceTypeVal, isMultiple, mode]);
109
122
  return /*#__PURE__*/React.createElement(Select, __assign({
110
123
  ref: selectRef,
111
124
  className: classNames('complex-val-select', props === null || props === void 0 ? void 0 : props.className),
@@ -116,4 +129,7 @@ var ComplexValSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
116
129
  onSelect: handleSelect
117
130
  }, omit(props, ['value', 'defaultValue', 'onChange', 'options', 'onSelect', 'className'])));
118
131
  });
119
- export default ComplexValSelect;
132
+ export default ComplexValSelect;
133
+ var Option = Select.Option;
134
+ export { Option };
135
+ export { stableStringify } from 'aa-utils';
@@ -1,14 +1,12 @@
1
1
  import * as React from 'react';
2
2
  import type { DefaultOptionType, SelectProps } from 'antd/lib/select';
3
- declare const Option: import("rc-select/lib/Option").OptionFC;
4
- export { Option };
5
3
  export type ComplexValSelectValueType = string | number | any[] | Record<string, any> | null | undefined;
6
4
  export interface ComplexValSelectOptionType extends Omit<DefaultOptionType, 'value' | 'children' | 'options'> {
7
5
  value?: ComplexValSelectValueType;
8
6
  children?: ComplexValSelectOptionType[];
9
7
  options?: Omit<ComplexValSelectOptionType, 'children' | 'options'>[];
10
8
  }
11
- /** 判断optionsValue是否是引用类型 */
9
+ /** 判断 options 的 value 中是否包含引用类型(对象或数组) */
12
10
  export declare const isReferenceTypeOption: (options?: ComplexValSelectOptionType[]) => boolean;
13
11
  export interface ComplexValSelectProps<T> extends Omit<SelectProps, 'value' | 'onChange' | 'options'> {
14
12
  value?: T;
@@ -17,3 +15,6 @@ export interface ComplexValSelectProps<T> extends Omit<SelectProps, 'value' | 'o
17
15
  }
18
16
  declare const ComplexValSelect: React.ForwardRefExoticComponent<ComplexValSelectProps<ComplexValSelectValueType> & React.RefAttributes<unknown>>;
19
17
  export default ComplexValSelect;
18
+ declare const Option: import("rc-select/lib/Option").OptionFC;
19
+ export { Option };
20
+ export { stableStringify } from 'aa-utils';
@@ -71,7 +71,7 @@ var __importDefault = this && this.__importDefault || function (mod) {
71
71
  Object.defineProperty(exports, "__esModule", {
72
72
  value: true
73
73
  });
74
- exports.isReferenceTypeOption = exports.Option = void 0;
74
+ exports.stableStringify = exports.Option = exports.isReferenceTypeOption = void 0;
75
75
  var React = __importStar(require("react"));
76
76
  var omit_1 = __importDefault(require("lodash/omit"));
77
77
  var some_1 = __importDefault(require("lodash/some"));
@@ -82,27 +82,34 @@ 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"));
84
84
  var useControllableValue_1 = __importDefault(require("ahooks/lib/useControllableValue"));
85
- var Option = select_1["default"].Option;
86
- exports.Option = Option;
87
- var _formatOptions = function formatOptions(dateSource) {
88
- if (dateSource) {
89
- var options = dateSource.map(function (item) {
90
- var otherProps = item.options ? {
91
- options: _formatOptions(item.options)
92
- } : {};
93
- return __assign(__assign(__assign({}, item), {
94
- label: item.label,
95
- value: (0, isUndefined_1["default"])(item.value) ? undefined : JSON.stringify(item.value)
96
- }), otherProps);
97
- });
98
- return options;
85
+ var aa_utils_1 = require("aa-utils");
86
+ var lodash_1 = require("lodash");
87
+ // 核心防御:防止非标准 JSON 字符串(如 tags 模式下手敲的纯文本或 undefined)导致页面崩溃
88
+ var safeParse = function safeParse(str) {
89
+ if (typeof str !== 'string') return str;
90
+ try {
91
+ return JSON.parse(str);
92
+ } catch (_a) {
93
+ return str; // 解析失败直接返回原字符串
99
94
  }
100
- return dateSource;
101
95
  };
102
- /** 判断optionsValue是否是引用类型 */
96
+ /** 递归格式化 options,将复杂 value 序列化为字符串 */
97
+ var _formatOptions = function formatOptions(dataSource) {
98
+ if (!dataSource) return dataSource;
99
+ return dataSource.map(function (item) {
100
+ var otherProps = item.options ? {
101
+ options: _formatOptions(item.options)
102
+ } : {};
103
+ return __assign(__assign(__assign({}, item), {
104
+ label: item.label,
105
+ value: (0, isUndefined_1["default"])(item.value) ? undefined : (0, aa_utils_1.stableStringify)(item.value)
106
+ }), otherProps);
107
+ });
108
+ };
109
+ /** 判断 options 的 value 中是否包含引用类型(对象或数组) */
103
110
  var isReferenceTypeOption = function isReferenceTypeOption(options) {
104
- var resultBoolean = (0, some_1["default"])(options, function (item) {
105
- if (item.value) {
111
+ return (0, some_1["default"])(options, function (item) {
112
+ if (!(0, isUndefined_1["default"])(item.value)) {
106
113
  return (0, isArray_1["default"])(item.value) || (0, isObject_1["default"])(item.value);
107
114
  }
108
115
  if (item.options) {
@@ -112,7 +119,6 @@ var isReferenceTypeOption = function isReferenceTypeOption(options) {
112
119
  }
113
120
  return false;
114
121
  });
115
- return resultBoolean;
116
122
  };
117
123
  exports.isReferenceTypeOption = isReferenceTypeOption;
118
124
  var ComplexValSelect = React.forwardRef(function (props, ref) {
@@ -120,35 +126,42 @@ var ComplexValSelect = React.forwardRef(function (props, ref) {
120
126
  value = _a[0],
121
127
  setValue = _a[1];
122
128
  var options = props.options,
123
- onSelect = props.onSelect;
129
+ onSelect = props.onSelect,
130
+ mode = props.mode;
124
131
  var selectRef = React.useRef(null);
125
132
  React.useImperativeHandle(ref, function () {
126
133
  return selectRef.current;
127
134
  });
128
- // 判断是否需要将optionValue转为JSON字符串
135
+ // 判断是否为多选模式 (multiple 或 tags)
136
+ var isMultiple = mode === 'multiple' || mode === 'tags';
137
+ // 判断是否需要将 option 的 value 转为 JSON 字符串
129
138
  var isReferenceTypeVal = (0, exports.isReferenceTypeOption)(options);
130
139
  var finalOptions = isReferenceTypeVal ? _formatOptions(options) : options;
140
+ // 处理选中值改变:将底层传出的字符串安全地 parse 回真实的数据结构
131
141
  var handleChange = function handleChange(val, option) {
132
142
  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);
143
+ if (!(0, lodash_1.isNil)(val) && isReferenceTypeVal) {
144
+ nextVal = isMultiple && (0, isArray_1["default"])(val) ? val.map(function (item) {
145
+ return safeParse(item);
146
+ }) : safeParse(val);
137
147
  }
138
148
  setValue(nextVal, option);
139
149
  };
140
150
  var handleSelect = function handleSelect(val, option) {
141
- var nextVal = val && isReferenceTypeVal ? JSON.parse(val) : val;
151
+ var nextVal = !(0, lodash_1.isNil)(val) && isReferenceTypeVal ? safeParse(val) : val;
142
152
  onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextVal, option);
143
153
  };
154
+ // 处理回显展示值:将传入的真实数据结构 stringify 成字符串去匹配底层 Option
144
155
  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);
156
+ if (!(0, lodash_1.isNil)(value) && isReferenceTypeVal) {
157
+ return isMultiple && (0, isArray_1["default"])(value) ? value.map(function (v) {
158
+ // 在 tags 模式下,如果 v 已经是手敲的基础字符串,直接放行,避免产生多余的双引号
159
+ if (mode === 'tags' && typeof v === 'string') return v;
160
+ return (0, aa_utils_1.stableStringify)(v);
161
+ }) : (0, aa_utils_1.stableStringify)(value);
149
162
  }
150
163
  return value;
151
- }, [value, isReferenceTypeVal]);
164
+ }, [value, isReferenceTypeVal, isMultiple, mode]);
152
165
  return React.createElement(select_1["default"], __assign({
153
166
  ref: selectRef,
154
167
  className: (0, classnames_1["default"])('complex-val-select', props === null || props === void 0 ? void 0 : props.className),
@@ -159,4 +172,13 @@ var ComplexValSelect = React.forwardRef(function (props, ref) {
159
172
  onSelect: handleSelect
160
173
  }, (0, omit_1["default"])(props, ['value', 'defaultValue', 'onChange', 'options', 'onSelect', 'className'])));
161
174
  });
162
- exports["default"] = ComplexValSelect;
175
+ exports["default"] = ComplexValSelect;
176
+ var Option = select_1["default"].Option;
177
+ exports.Option = Option;
178
+ var aa_utils_2 = require("aa-utils");
179
+ Object.defineProperty(exports, "stableStringify", {
180
+ enumerable: true,
181
+ get: function get() {
182
+ return aa_utils_2.stableStringify;
183
+ }
184
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assui",
3
- "version": "3.2.106",
3
+ "version": "3.3.1",
4
4
  "description": "react ui library",
5
5
  "author": "jason <usochen@gmail.com>",
6
6
  "main": "./lib/index.js",
@@ -36,7 +36,7 @@
36
36
  "@types/react-color": "^3.0.6",
37
37
  "@types/react-resizable": "^3.0.0",
38
38
  "a-icons": "^1.2.68",
39
- "aa-utils": "^2.1.34",
39
+ "aa-utils": "^2.1.35",
40
40
  "ahooks": "^3.9.5",
41
41
  "bignumber.js": "^9.0.1",
42
42
  "copy-to-clipboard": "^3.3.1",
@@ -87,5 +87,5 @@
87
87
  "node": ">=10.0.0"
88
88
  },
89
89
  "license": "MIT",
90
- "gitHead": "a733655570b6114592c403f0a0e9df03f438e686"
90
+ "gitHead": "43025f6771ae7e9d0b93a75891cfd5064555593c"
91
91
  }