assui 3.2.105 → 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,19 +1,20 @@
|
|
|
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
|
-
/** 判断
|
|
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;
|
|
15
|
-
onChange?: (val: T, opt?: ComplexValSelectOptionType[]) => void;
|
|
13
|
+
onChange?: (val: T, opt?: ComplexValSelectOptionType | ComplexValSelectOptionType[]) => void;
|
|
16
14
|
options?: ComplexValSelectOptionType[];
|
|
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';
|
|
@@ -32,35 +32,42 @@ 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";
|
|
42
42
|
import useControllableValue from "ahooks/es/useControllableValue";
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
label: item.label,
|
|
53
|
-
value: item.value ? JSON.stringify(item.value) : undefined
|
|
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
|
-
/**
|
|
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
|
-
|
|
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,40 +77,59 @@ 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
|
-
//
|
|
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;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
// 处理选中值改变:将底层传出的字符串安全地 parse 回真实的数据结构
|
|
98
|
+
var handleChange = function handleChange(val, option) {
|
|
99
|
+
var nextVal = val;
|
|
100
|
+
if (!isNil(val) && isReferenceTypeVal) {
|
|
101
|
+
nextVal = isMultiple && isArray(val) ? val.map(function (item) {
|
|
102
|
+
return safeParse(item);
|
|
103
|
+
}) : safeParse(val);
|
|
104
|
+
}
|
|
105
|
+
setValue(nextVal, option);
|
|
91
106
|
};
|
|
92
|
-
var handleSelect = function handleSelect(val) {
|
|
93
|
-
var nextVal = val && isReferenceTypeVal ?
|
|
94
|
-
|
|
95
|
-
value: val
|
|
96
|
-
});
|
|
97
|
-
onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextVal, selectOption);
|
|
107
|
+
var handleSelect = function handleSelect(val, option) {
|
|
108
|
+
var nextVal = !isNil(val) && isReferenceTypeVal ? safeParse(val) : val;
|
|
109
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextVal, option);
|
|
98
110
|
};
|
|
111
|
+
// 处理回显展示值:将传入的真实数据结构 stringify 成字符串去匹配底层 Option
|
|
112
|
+
var displayValue = React.useMemo(function () {
|
|
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);
|
|
119
|
+
}
|
|
120
|
+
return value;
|
|
121
|
+
}, [value, isReferenceTypeVal, isMultiple, mode]);
|
|
99
122
|
return /*#__PURE__*/React.createElement(Select, __assign({
|
|
100
123
|
ref: selectRef,
|
|
101
124
|
className: classNames('complex-val-select', props === null || props === void 0 ? void 0 : props.className),
|
|
102
125
|
suffixIcon: /*#__PURE__*/React.createElement(ArrowDownOutlined, null),
|
|
103
|
-
value:
|
|
126
|
+
value: displayValue,
|
|
104
127
|
options: finalOptions,
|
|
105
128
|
onChange: handleChange,
|
|
106
129
|
onSelect: handleSelect
|
|
107
|
-
}, omit(props, ['value', 'onChange', 'options', 'onSelect', 'className'])));
|
|
130
|
+
}, omit(props, ['value', 'defaultValue', 'onChange', 'options', 'onSelect', 'className'])));
|
|
108
131
|
});
|
|
109
|
-
export default ComplexValSelect;
|
|
132
|
+
export default ComplexValSelect;
|
|
133
|
+
var Option = Select.Option;
|
|
134
|
+
export { Option };
|
|
135
|
+
export { stableStringify } from 'aa-utils';
|
|
@@ -1,19 +1,20 @@
|
|
|
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
|
-
/** 判断
|
|
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;
|
|
15
|
-
onChange?: (val: T, opt?: ComplexValSelectOptionType[]) => void;
|
|
13
|
+
onChange?: (val: T, opt?: ComplexValSelectOptionType | ComplexValSelectOptionType[]) => void;
|
|
16
14
|
options?: ComplexValSelectOptionType[];
|
|
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,38 +71,45 @@ var __importDefault = this && this.__importDefault || function (mod) {
|
|
|
71
71
|
Object.defineProperty(exports, "__esModule", {
|
|
72
72
|
value: true
|
|
73
73
|
});
|
|
74
|
-
exports.
|
|
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
|
-
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"));
|
|
84
84
|
var useControllableValue_1 = __importDefault(require("ahooks/lib/useControllableValue"));
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
label: item.label,
|
|
95
|
-
value: item.value ? JSON.stringify(item.value) : undefined
|
|
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
|
-
/**
|
|
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
|
-
|
|
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,33 +126,59 @@ 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
|
-
//
|
|
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;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
// 处理选中值改变:将底层传出的字符串安全地 parse 回真实的数据结构
|
|
141
|
+
var handleChange = function handleChange(val, option) {
|
|
142
|
+
var nextVal = 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);
|
|
147
|
+
}
|
|
148
|
+
setValue(nextVal, option);
|
|
134
149
|
};
|
|
135
|
-
var handleSelect = function handleSelect(val) {
|
|
136
|
-
var nextVal = val && isReferenceTypeVal ?
|
|
137
|
-
|
|
138
|
-
value: val
|
|
139
|
-
});
|
|
140
|
-
onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextVal, selectOption);
|
|
150
|
+
var handleSelect = function handleSelect(val, option) {
|
|
151
|
+
var nextVal = !(0, lodash_1.isNil)(val) && isReferenceTypeVal ? safeParse(val) : val;
|
|
152
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(nextVal, option);
|
|
141
153
|
};
|
|
154
|
+
// 处理回显展示值:将传入的真实数据结构 stringify 成字符串去匹配底层 Option
|
|
155
|
+
var displayValue = React.useMemo(function () {
|
|
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);
|
|
162
|
+
}
|
|
163
|
+
return value;
|
|
164
|
+
}, [value, isReferenceTypeVal, isMultiple, mode]);
|
|
142
165
|
return React.createElement(select_1["default"], __assign({
|
|
143
166
|
ref: selectRef,
|
|
144
167
|
className: (0, classnames_1["default"])('complex-val-select', props === null || props === void 0 ? void 0 : props.className),
|
|
145
168
|
suffixIcon: React.createElement(ArrowDownOutlined_1["default"], null),
|
|
146
|
-
value:
|
|
169
|
+
value: displayValue,
|
|
147
170
|
options: finalOptions,
|
|
148
171
|
onChange: handleChange,
|
|
149
172
|
onSelect: handleSelect
|
|
150
|
-
}, (0, omit_1["default"])(props, ['value', 'onChange', 'options', 'onSelect', 'className'])));
|
|
173
|
+
}, (0, omit_1["default"])(props, ['value', 'defaultValue', 'onChange', 'options', 'onSelect', 'className'])));
|
|
151
174
|
});
|
|
152
|
-
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.
|
|
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.
|
|
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": "
|
|
90
|
+
"gitHead": "43025f6771ae7e9d0b93a75891cfd5064555593c"
|
|
91
91
|
}
|