@vtx/components 4.0.0-beta.69 → 4.0.0-beta.70
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/es/vtx-select/index.js +99 -32
- package/lib/vtx-select/index.js +100 -33
- package/package.json +30 -29
package/es/vtx-select/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var _excluded = ["value", "mode", "size", "onChange", "maxTagCount", "maxTagTextLength", "maxTagPlaceholder", "showAll", "selectStyle", "selectAll", "selectSearchAll", "defaultBindBodyToPopupContainer", "customEnumText", "showSearch", "optionFilterProp", "onSearch"],
|
|
2
|
+
_excluded2 = ["onSearch", "optionFilterProp"];
|
|
1
3
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
4
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
5
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -9,6 +11,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
9
11
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
12
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
11
13
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
16
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
17
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
18
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -59,16 +63,25 @@ var VtxSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
59
63
|
_props$defaultBindBod = props.defaultBindBodyToPopupContainer,
|
|
60
64
|
defaultBindBodyToPopupContainer = _props$defaultBindBod === void 0 ? true : _props$defaultBindBod,
|
|
61
65
|
_props$customEnumText = props.customEnumText,
|
|
62
|
-
customEnumText = _props$customEnumText === void 0 ? {} : _props$customEnumText
|
|
66
|
+
customEnumText = _props$customEnumText === void 0 ? {} : _props$customEnumText,
|
|
67
|
+
showSearch = props.showSearch,
|
|
68
|
+
optionFilterProp = props.optionFilterProp,
|
|
69
|
+
_onSearch = props.onSearch,
|
|
70
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
63
71
|
var TextEnum = _objectSpread({
|
|
64
72
|
selectAllText: intl.getMessage('select.selectAll', '全选'),
|
|
65
73
|
defaultPlaceholderText: intl.getMessage('tableForm.selectPlaceholder', '请选择'),
|
|
66
74
|
emptyDescriptionText: intl.getMessage('select.empty', '暂无数据')
|
|
67
75
|
}, customEnumText);
|
|
76
|
+
var _useContext = useContext(VtxProvider),
|
|
77
|
+
getPrefixCls = _useContext.getPrefixCls;
|
|
78
|
+
var prefixCls = getPrefixCls('select', props.prefixCls);
|
|
79
|
+
var _useStyle = useStyle(prefixCls),
|
|
80
|
+
wrapSSR = _useStyle.wrapSSR,
|
|
81
|
+
hashId = _useStyle.hashId;
|
|
68
82
|
useEffect(function () {
|
|
69
83
|
if ((mode === 'multiple' || mode === 'tags') && elRef.current) {
|
|
70
84
|
var element = elRef.current;
|
|
71
|
-
|
|
72
85
|
// 立即设置一次
|
|
73
86
|
setPopWidth(element.clientWidth);
|
|
74
87
|
|
|
@@ -93,24 +106,47 @@ var VtxSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
93
106
|
};
|
|
94
107
|
}
|
|
95
108
|
}, [mode]);
|
|
96
|
-
var newChildren = props.children ?
|
|
109
|
+
var newChildren = props.children ? React.Children.toArray(props.children) : ((_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.map(function (v) {
|
|
97
110
|
return _objectSpread(_objectSpread({}, v), {}, {
|
|
98
111
|
key: v.value,
|
|
99
|
-
props: {
|
|
112
|
+
props: _objectSpread(_objectSpread({}, v), {}, {
|
|
100
113
|
children: v.label
|
|
101
|
-
}
|
|
114
|
+
})
|
|
102
115
|
});
|
|
103
116
|
})) || [];
|
|
117
|
+
var getOptionValue = function getOptionValue(item) {
|
|
118
|
+
var _ref, _itemProps$value;
|
|
119
|
+
var itemProps = (item === null || item === void 0 ? void 0 : item.props) || {};
|
|
120
|
+
return (_ref = (_itemProps$value = itemProps.value) !== null && _itemProps$value !== void 0 ? _itemProps$value : item.value) !== null && _ref !== void 0 ? _ref : item.key;
|
|
121
|
+
};
|
|
122
|
+
var getOptionLabel = function getOptionLabel(item) {
|
|
123
|
+
var _ref2, _itemProps$children;
|
|
124
|
+
var itemProps = (item === null || item === void 0 ? void 0 : item.props) || {};
|
|
125
|
+
return (_ref2 = (_itemProps$children = itemProps.children) !== null && _itemProps$children !== void 0 ? _itemProps$children : itemProps.label) !== null && _ref2 !== void 0 ? _ref2 : item.label;
|
|
126
|
+
};
|
|
127
|
+
var getSelectedValue = function getSelectedValue(item) {
|
|
128
|
+
if (isObject(item)) {
|
|
129
|
+
var _item$value;
|
|
130
|
+
return (_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : item.key;
|
|
131
|
+
}
|
|
132
|
+
return item;
|
|
133
|
+
};
|
|
134
|
+
var normalizedOptions = newChildren.map(function (item) {
|
|
135
|
+
return {
|
|
136
|
+
value: getOptionValue(item),
|
|
137
|
+
label: getOptionLabel(item),
|
|
138
|
+
raw: item
|
|
139
|
+
};
|
|
140
|
+
});
|
|
104
141
|
var getContent = function getContent() {
|
|
105
142
|
var child = {};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
child[item.key] = item === null || item === void 0 || (_item$props = item.props) === null || _item$props === void 0 ? void 0 : _item$props.children;
|
|
143
|
+
normalizedOptions.forEach(function (item) {
|
|
144
|
+
child[item.value] = item.label;
|
|
109
145
|
});
|
|
110
146
|
var getChildren = function getChildren() {
|
|
111
147
|
var child = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
112
148
|
var value = arguments.length > 1 ? arguments[1] : undefined;
|
|
113
|
-
var key =
|
|
149
|
+
var key = getSelectedValue(value);
|
|
114
150
|
return child[key] || '';
|
|
115
151
|
};
|
|
116
152
|
return /*#__PURE__*/_jsx("div", {
|
|
@@ -126,10 +162,13 @@ var VtxSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
126
162
|
e.preventDefault();
|
|
127
163
|
var valueClone = _toConsumableArray(value);
|
|
128
164
|
valueClone.splice(index, 1);
|
|
129
|
-
var
|
|
130
|
-
|
|
165
|
+
var selectedValueSet = new Set(valueClone.map(getSelectedValue));
|
|
166
|
+
var options = normalizedOptions.filter(function (ite) {
|
|
167
|
+
return selectedValueSet.has(ite.value);
|
|
168
|
+
}).map(function (ite) {
|
|
169
|
+
return ite.raw;
|
|
131
170
|
});
|
|
132
|
-
_onChange(valueClone, options);
|
|
171
|
+
_onChange && _onChange(valueClone, options);
|
|
133
172
|
},
|
|
134
173
|
children: /*#__PURE__*/_jsx(Tooltip, {
|
|
135
174
|
title: name,
|
|
@@ -142,17 +181,51 @@ var VtxSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
142
181
|
})
|
|
143
182
|
});
|
|
144
183
|
};
|
|
145
|
-
var
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
184
|
+
var defaultOptionFilterProp = ['label', 'children'];
|
|
185
|
+
var handleSearch = function handleSearch(value) {
|
|
186
|
+
setSearchValue(value ? String(value).toLowerCase() : '');
|
|
187
|
+
_onSearch && _onSearch(value);
|
|
188
|
+
};
|
|
189
|
+
var getSearchProps = function getSearchProps() {
|
|
190
|
+
if (showSearch && _typeof(showSearch) === 'object') {
|
|
191
|
+
var showSearchOnSearch = showSearch.onSearch,
|
|
192
|
+
showSearchOptionFilterProp = showSearch.optionFilterProp,
|
|
193
|
+
searchConfig = _objectWithoutProperties(showSearch, _excluded2);
|
|
194
|
+
return {
|
|
195
|
+
showSearch: _objectSpread(_objectSpread({}, searchConfig), {}, {
|
|
196
|
+
optionFilterProp: showSearchOptionFilterProp || optionFilterProp || defaultOptionFilterProp,
|
|
197
|
+
onSearch: function onSearch(value) {
|
|
198
|
+
setSearchValue(value ? String(value).toLowerCase() : '');
|
|
199
|
+
showSearchOnSearch && showSearchOnSearch(value);
|
|
200
|
+
_onSearch && _onSearch(value);
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
showSearch: showSearch === undefined ? true : showSearch,
|
|
207
|
+
optionFilterProp: optionFilterProp || defaultOptionFilterProp
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
var newProps = _objectSpread(_objectSpread(_objectSpread({}, getSearchProps()), {}, {
|
|
149
211
|
placeholder: TextEnum.defaultPlaceholderText,
|
|
150
|
-
allowClear: true
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
212
|
+
allowClear: true,
|
|
213
|
+
value: value,
|
|
214
|
+
mode: mode,
|
|
215
|
+
size: size,
|
|
216
|
+
//同步button大小
|
|
217
|
+
onChange: _onChange,
|
|
218
|
+
maxTagCount: maxTagCount,
|
|
219
|
+
maxTagTextLength: maxTagTextLength,
|
|
220
|
+
maxTagPlaceholder: maxTagPlaceholder,
|
|
221
|
+
showAll: showAll,
|
|
222
|
+
//是否显示全部选项
|
|
223
|
+
selectStyle: selectStyle,
|
|
224
|
+
selectAll: selectAll,
|
|
225
|
+
selectSearchAll: selectSearchAll,
|
|
226
|
+
defaultBindBodyToPopupContainer: defaultBindBodyToPopupContainer
|
|
227
|
+
}, rest), {}, {
|
|
228
|
+
onSearch: handleSearch,
|
|
156
229
|
onBlur: function onBlur(e) {
|
|
157
230
|
setSearchValue('');
|
|
158
231
|
props.onBlur && props.onBlur(e);
|
|
@@ -181,7 +254,7 @@ var VtxSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
181
254
|
if (e.target.checked) {
|
|
182
255
|
var tempChildren = newChildren.filter(function (item) {
|
|
183
256
|
if (selectSearchAll && searchValue) {
|
|
184
|
-
return String(item
|
|
257
|
+
return String(getOptionLabel(item)).toLowerCase().indexOf(searchValue) > -1;
|
|
185
258
|
}
|
|
186
259
|
return true;
|
|
187
260
|
});
|
|
@@ -189,13 +262,13 @@ var VtxSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
189
262
|
if (props.labelInValue) {
|
|
190
263
|
keys = tempChildren.map(function (item) {
|
|
191
264
|
return {
|
|
192
|
-
label: item
|
|
193
|
-
value: item
|
|
265
|
+
label: getOptionLabel(item),
|
|
266
|
+
value: getOptionValue(item)
|
|
194
267
|
};
|
|
195
268
|
});
|
|
196
269
|
} else {
|
|
197
270
|
keys = tempChildren.map(function (item) {
|
|
198
|
-
return item
|
|
271
|
+
return getOptionValue(item);
|
|
199
272
|
});
|
|
200
273
|
}
|
|
201
274
|
_onChange && _onChange(keys, tempChildren);
|
|
@@ -215,12 +288,6 @@ var VtxSelect = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
215
288
|
});
|
|
216
289
|
}
|
|
217
290
|
}
|
|
218
|
-
var _useContext = useContext(VtxProvider),
|
|
219
|
-
getPrefixCls = _useContext.getPrefixCls;
|
|
220
|
-
var prefixCls = getPrefixCls('select', props.prefixCls);
|
|
221
|
-
var _useStyle = useStyle(prefixCls),
|
|
222
|
-
wrapSSR = _useStyle.wrapSSR,
|
|
223
|
-
hashId = _useStyle.hashId;
|
|
224
291
|
return wrapSSR( /*#__PURE__*/_jsx("div", {
|
|
225
292
|
className: classnames(prefixCls, hashId, _defineProperty({}, "".concat(prefixCls, "-multi"), mode == 'multiple' || mode == 'tags')),
|
|
226
293
|
id: elId.current,
|
package/lib/vtx-select/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -14,9 +13,12 @@ var _vtxIcon = _interopRequireDefault(require("../vtx-icon"));
|
|
|
14
13
|
var _utils = require("../utils");
|
|
15
14
|
var _vtxProvider = require("../vtx-provider");
|
|
16
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
var _excluded = ["value", "mode", "size", "onChange", "maxTagCount", "maxTagTextLength", "maxTagPlaceholder", "showAll", "selectStyle", "selectAll", "selectSearchAll", "defaultBindBodyToPopupContainer", "customEnumText", "showSearch", "optionFilterProp", "onSearch"],
|
|
17
|
+
_excluded2 = ["onSearch", "optionFilterProp"];
|
|
17
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
18
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
19
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
20
22
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
21
23
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
22
24
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
@@ -27,6 +29,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
27
29
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
28
30
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
29
31
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
32
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
33
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
30
34
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
31
35
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
32
36
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -67,16 +71,25 @@ var VtxSelect = exports.VtxSelect = /*#__PURE__*/(0, _react.forwardRef)(function
|
|
|
67
71
|
_props$defaultBindBod = props.defaultBindBodyToPopupContainer,
|
|
68
72
|
defaultBindBodyToPopupContainer = _props$defaultBindBod === void 0 ? true : _props$defaultBindBod,
|
|
69
73
|
_props$customEnumText = props.customEnumText,
|
|
70
|
-
customEnumText = _props$customEnumText === void 0 ? {} : _props$customEnumText
|
|
74
|
+
customEnumText = _props$customEnumText === void 0 ? {} : _props$customEnumText,
|
|
75
|
+
showSearch = props.showSearch,
|
|
76
|
+
optionFilterProp = props.optionFilterProp,
|
|
77
|
+
_onSearch = props.onSearch,
|
|
78
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
71
79
|
var TextEnum = _objectSpread({
|
|
72
80
|
selectAllText: intl.getMessage('select.selectAll', '全选'),
|
|
73
81
|
defaultPlaceholderText: intl.getMessage('tableForm.selectPlaceholder', '请选择'),
|
|
74
82
|
emptyDescriptionText: intl.getMessage('select.empty', '暂无数据')
|
|
75
83
|
}, customEnumText);
|
|
84
|
+
var _useContext = (0, _react.useContext)(_vtxProvider.VtxProvider),
|
|
85
|
+
getPrefixCls = _useContext.getPrefixCls;
|
|
86
|
+
var prefixCls = getPrefixCls('select', props.prefixCls);
|
|
87
|
+
var _useStyle = (0, _style.useStyle)(prefixCls),
|
|
88
|
+
wrapSSR = _useStyle.wrapSSR,
|
|
89
|
+
hashId = _useStyle.hashId;
|
|
76
90
|
(0, _react.useEffect)(function () {
|
|
77
91
|
if ((mode === 'multiple' || mode === 'tags') && elRef.current) {
|
|
78
92
|
var element = elRef.current;
|
|
79
|
-
|
|
80
93
|
// 立即设置一次
|
|
81
94
|
setPopWidth(element.clientWidth);
|
|
82
95
|
|
|
@@ -101,24 +114,47 @@ var VtxSelect = exports.VtxSelect = /*#__PURE__*/(0, _react.forwardRef)(function
|
|
|
101
114
|
};
|
|
102
115
|
}
|
|
103
116
|
}, [mode]);
|
|
104
|
-
var newChildren = props.children ?
|
|
117
|
+
var newChildren = props.children ? _react.default.Children.toArray(props.children) : ((_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.map(function (v) {
|
|
105
118
|
return _objectSpread(_objectSpread({}, v), {}, {
|
|
106
119
|
key: v.value,
|
|
107
|
-
props: {
|
|
120
|
+
props: _objectSpread(_objectSpread({}, v), {}, {
|
|
108
121
|
children: v.label
|
|
109
|
-
}
|
|
122
|
+
})
|
|
110
123
|
});
|
|
111
124
|
})) || [];
|
|
125
|
+
var getOptionValue = function getOptionValue(item) {
|
|
126
|
+
var _ref, _itemProps$value;
|
|
127
|
+
var itemProps = (item === null || item === void 0 ? void 0 : item.props) || {};
|
|
128
|
+
return (_ref = (_itemProps$value = itemProps.value) !== null && _itemProps$value !== void 0 ? _itemProps$value : item.value) !== null && _ref !== void 0 ? _ref : item.key;
|
|
129
|
+
};
|
|
130
|
+
var getOptionLabel = function getOptionLabel(item) {
|
|
131
|
+
var _ref2, _itemProps$children;
|
|
132
|
+
var itemProps = (item === null || item === void 0 ? void 0 : item.props) || {};
|
|
133
|
+
return (_ref2 = (_itemProps$children = itemProps.children) !== null && _itemProps$children !== void 0 ? _itemProps$children : itemProps.label) !== null && _ref2 !== void 0 ? _ref2 : item.label;
|
|
134
|
+
};
|
|
135
|
+
var getSelectedValue = function getSelectedValue(item) {
|
|
136
|
+
if ((0, _utils.isObject)(item)) {
|
|
137
|
+
var _item$value;
|
|
138
|
+
return (_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : item.key;
|
|
139
|
+
}
|
|
140
|
+
return item;
|
|
141
|
+
};
|
|
142
|
+
var normalizedOptions = newChildren.map(function (item) {
|
|
143
|
+
return {
|
|
144
|
+
value: getOptionValue(item),
|
|
145
|
+
label: getOptionLabel(item),
|
|
146
|
+
raw: item
|
|
147
|
+
};
|
|
148
|
+
});
|
|
112
149
|
var getContent = function getContent() {
|
|
113
150
|
var child = {};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
child[item.key] = item === null || item === void 0 || (_item$props = item.props) === null || _item$props === void 0 ? void 0 : _item$props.children;
|
|
151
|
+
normalizedOptions.forEach(function (item) {
|
|
152
|
+
child[item.value] = item.label;
|
|
117
153
|
});
|
|
118
154
|
var getChildren = function getChildren() {
|
|
119
155
|
var child = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
120
156
|
var value = arguments.length > 1 ? arguments[1] : undefined;
|
|
121
|
-
var key = (
|
|
157
|
+
var key = getSelectedValue(value);
|
|
122
158
|
return child[key] || '';
|
|
123
159
|
};
|
|
124
160
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
@@ -134,10 +170,13 @@ var VtxSelect = exports.VtxSelect = /*#__PURE__*/(0, _react.forwardRef)(function
|
|
|
134
170
|
e.preventDefault();
|
|
135
171
|
var valueClone = _toConsumableArray(value);
|
|
136
172
|
valueClone.splice(index, 1);
|
|
137
|
-
var
|
|
138
|
-
|
|
173
|
+
var selectedValueSet = new Set(valueClone.map(getSelectedValue));
|
|
174
|
+
var options = normalizedOptions.filter(function (ite) {
|
|
175
|
+
return selectedValueSet.has(ite.value);
|
|
176
|
+
}).map(function (ite) {
|
|
177
|
+
return ite.raw;
|
|
139
178
|
});
|
|
140
|
-
_onChange(valueClone, options);
|
|
179
|
+
_onChange && _onChange(valueClone, options);
|
|
141
180
|
},
|
|
142
181
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Tooltip, {
|
|
143
182
|
title: name,
|
|
@@ -150,17 +189,51 @@ var VtxSelect = exports.VtxSelect = /*#__PURE__*/(0, _react.forwardRef)(function
|
|
|
150
189
|
})
|
|
151
190
|
});
|
|
152
191
|
};
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
192
|
+
var defaultOptionFilterProp = ['label', 'children'];
|
|
193
|
+
var handleSearch = function handleSearch(value) {
|
|
194
|
+
setSearchValue(value ? String(value).toLowerCase() : '');
|
|
195
|
+
_onSearch && _onSearch(value);
|
|
196
|
+
};
|
|
197
|
+
var getSearchProps = function getSearchProps() {
|
|
198
|
+
if (showSearch && _typeof(showSearch) === 'object') {
|
|
199
|
+
var showSearchOnSearch = showSearch.onSearch,
|
|
200
|
+
showSearchOptionFilterProp = showSearch.optionFilterProp,
|
|
201
|
+
searchConfig = _objectWithoutProperties(showSearch, _excluded2);
|
|
202
|
+
return {
|
|
203
|
+
showSearch: _objectSpread(_objectSpread({}, searchConfig), {}, {
|
|
204
|
+
optionFilterProp: showSearchOptionFilterProp || optionFilterProp || defaultOptionFilterProp,
|
|
205
|
+
onSearch: function onSearch(value) {
|
|
206
|
+
setSearchValue(value ? String(value).toLowerCase() : '');
|
|
207
|
+
showSearchOnSearch && showSearchOnSearch(value);
|
|
208
|
+
_onSearch && _onSearch(value);
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
showSearch: showSearch === undefined ? true : showSearch,
|
|
215
|
+
optionFilterProp: optionFilterProp || defaultOptionFilterProp
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
var newProps = _objectSpread(_objectSpread(_objectSpread({}, getSearchProps()), {}, {
|
|
157
219
|
placeholder: TextEnum.defaultPlaceholderText,
|
|
158
|
-
allowClear: true
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
220
|
+
allowClear: true,
|
|
221
|
+
value: value,
|
|
222
|
+
mode: mode,
|
|
223
|
+
size: size,
|
|
224
|
+
//同步button大小
|
|
225
|
+
onChange: _onChange,
|
|
226
|
+
maxTagCount: maxTagCount,
|
|
227
|
+
maxTagTextLength: maxTagTextLength,
|
|
228
|
+
maxTagPlaceholder: maxTagPlaceholder,
|
|
229
|
+
showAll: showAll,
|
|
230
|
+
//是否显示全部选项
|
|
231
|
+
selectStyle: selectStyle,
|
|
232
|
+
selectAll: selectAll,
|
|
233
|
+
selectSearchAll: selectSearchAll,
|
|
234
|
+
defaultBindBodyToPopupContainer: defaultBindBodyToPopupContainer
|
|
235
|
+
}, rest), {}, {
|
|
236
|
+
onSearch: handleSearch,
|
|
164
237
|
onBlur: function onBlur(e) {
|
|
165
238
|
setSearchValue('');
|
|
166
239
|
props.onBlur && props.onBlur(e);
|
|
@@ -189,7 +262,7 @@ var VtxSelect = exports.VtxSelect = /*#__PURE__*/(0, _react.forwardRef)(function
|
|
|
189
262
|
if (e.target.checked) {
|
|
190
263
|
var tempChildren = newChildren.filter(function (item) {
|
|
191
264
|
if (selectSearchAll && searchValue) {
|
|
192
|
-
return String(item
|
|
265
|
+
return String(getOptionLabel(item)).toLowerCase().indexOf(searchValue) > -1;
|
|
193
266
|
}
|
|
194
267
|
return true;
|
|
195
268
|
});
|
|
@@ -197,13 +270,13 @@ var VtxSelect = exports.VtxSelect = /*#__PURE__*/(0, _react.forwardRef)(function
|
|
|
197
270
|
if (props.labelInValue) {
|
|
198
271
|
keys = tempChildren.map(function (item) {
|
|
199
272
|
return {
|
|
200
|
-
label: item
|
|
201
|
-
value: item
|
|
273
|
+
label: getOptionLabel(item),
|
|
274
|
+
value: getOptionValue(item)
|
|
202
275
|
};
|
|
203
276
|
});
|
|
204
277
|
} else {
|
|
205
278
|
keys = tempChildren.map(function (item) {
|
|
206
|
-
return item
|
|
279
|
+
return getOptionValue(item);
|
|
207
280
|
});
|
|
208
281
|
}
|
|
209
282
|
_onChange && _onChange(keys, tempChildren);
|
|
@@ -223,12 +296,6 @@ var VtxSelect = exports.VtxSelect = /*#__PURE__*/(0, _react.forwardRef)(function
|
|
|
223
296
|
});
|
|
224
297
|
}
|
|
225
298
|
}
|
|
226
|
-
var _useContext = (0, _react.useContext)(_vtxProvider.VtxProvider),
|
|
227
|
-
getPrefixCls = _useContext.getPrefixCls;
|
|
228
|
-
var prefixCls = getPrefixCls('select', props.prefixCls);
|
|
229
|
-
var _useStyle = (0, _style.useStyle)(prefixCls),
|
|
230
|
-
wrapSSR = _useStyle.wrapSSR,
|
|
231
|
-
hashId = _useStyle.hashId;
|
|
232
299
|
return wrapSSR( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
233
300
|
className: (0, _classnames2.default)(prefixCls, hashId, _defineProperty({}, "".concat(prefixCls, "-multi"), mode == 'multiple' || mode == 'tags')),
|
|
234
301
|
id: elId.current,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtx/components",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.70",
|
|
4
4
|
"description": "React components for Vortex",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -12,6 +12,34 @@
|
|
|
12
12
|
"es"
|
|
13
13
|
],
|
|
14
14
|
"main": "lib/index.js",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"start": "dumi dev",
|
|
17
|
+
"compile": "father build",
|
|
18
|
+
"build": "father build",
|
|
19
|
+
"bootstrap": "node ./scripts/bootstrap.mjs",
|
|
20
|
+
"changelog": "node ./scripts/changelogs.mjs",
|
|
21
|
+
"checkPublish": "npm run sync:tnpm && node ./scripts/checkPublish.mjs && npm run sync:tnpm",
|
|
22
|
+
"deploy": "cross-env SITE_DEPLOY='TRUE' npm run site && gh-pages -d ./dist",
|
|
23
|
+
"dumi": "cross-env SITE_DEPLOY='TRUE' dumi build",
|
|
24
|
+
"docs": "node ./scripts/docs.mjs",
|
|
25
|
+
"docs:dev": "pnpm docs dev",
|
|
26
|
+
"docs:build": "pnpm docs build",
|
|
27
|
+
"docs:preview": "pnpm docs preview",
|
|
28
|
+
"docs:create": "pnpm docs create",
|
|
29
|
+
"docs:check": "pnpm docs check",
|
|
30
|
+
"lint": "eslint --cache --ext .js,.jsx,.ts,.tsx --fix ./ && npm run tsc",
|
|
31
|
+
"prettier": "prettier --write \"**/**.{js,jsx,tsx,ts,less,md,yaml,json}\" --log-level warn",
|
|
32
|
+
"createRelease": "node ./scripts/createRelease.mjs",
|
|
33
|
+
"site": "npm run build && cross-env SITE_DEPLOY='TRUE' dumi build",
|
|
34
|
+
"sync:tnpm": "node -e 'import(\"./scripts/syncTNPM.mjs\").then(m => m.default())'",
|
|
35
|
+
"test": "cross-env TZ=UTC vitest run",
|
|
36
|
+
"test:coverage": "cross-env TZ=UTC TEST_LOG=none vitest run --coverage",
|
|
37
|
+
"test:ui": "cross-env TZ=UTC vitest --ui",
|
|
38
|
+
"test:update": "cross-env TZ=UTC vitest -u",
|
|
39
|
+
"tsc": "tsc --noEmit",
|
|
40
|
+
"publish:beta": "npm publish --tag beta",
|
|
41
|
+
"update:deps": "pnpm up --latest"
|
|
42
|
+
},
|
|
15
43
|
"homepage": "https://git.cloudhw.cn:3443/front-end/react-components.git",
|
|
16
44
|
"bugs": "https://git.cloudhw.cn:3443/front-end/react-components/-/issues",
|
|
17
45
|
"repository": {
|
|
@@ -200,39 +228,12 @@
|
|
|
200
228
|
"@vtx/utils": "^1.0.25"
|
|
201
229
|
},
|
|
202
230
|
"peerDependenciesName": "声明宿主依赖",
|
|
231
|
+
"packageManager": "pnpm@9.6.0",
|
|
203
232
|
"publishConfig": {
|
|
204
233
|
"access": "public"
|
|
205
234
|
},
|
|
206
235
|
"gitHooks": {
|
|
207
236
|
"pre-commit": "pretty-quick --staged",
|
|
208
237
|
"commit-msg": "fabric verify-commit"
|
|
209
|
-
},
|
|
210
|
-
"scripts": {
|
|
211
|
-
"start": "dumi dev",
|
|
212
|
-
"compile": "father build",
|
|
213
|
-
"build": "father build",
|
|
214
|
-
"bootstrap": "node ./scripts/bootstrap.mjs",
|
|
215
|
-
"changelog": "node ./scripts/changelogs.mjs",
|
|
216
|
-
"checkPublish": "npm run sync:tnpm && node ./scripts/checkPublish.mjs && npm run sync:tnpm",
|
|
217
|
-
"deploy": "cross-env SITE_DEPLOY='TRUE' npm run site && gh-pages -d ./dist",
|
|
218
|
-
"dumi": "cross-env SITE_DEPLOY='TRUE' dumi build",
|
|
219
|
-
"docs": "node ./scripts/docs.mjs",
|
|
220
|
-
"docs:dev": "pnpm docs dev",
|
|
221
|
-
"docs:build": "pnpm docs build",
|
|
222
|
-
"docs:preview": "pnpm docs preview",
|
|
223
|
-
"docs:create": "pnpm docs create",
|
|
224
|
-
"docs:check": "pnpm docs check",
|
|
225
|
-
"lint": "eslint --cache --ext .js,.jsx,.ts,.tsx --fix ./ && npm run tsc",
|
|
226
|
-
"prettier": "prettier --write \"**/**.{js,jsx,tsx,ts,less,md,yaml,json}\" --log-level warn",
|
|
227
|
-
"createRelease": "node ./scripts/createRelease.mjs",
|
|
228
|
-
"site": "npm run build && cross-env SITE_DEPLOY='TRUE' dumi build",
|
|
229
|
-
"sync:tnpm": "node -e 'import(\"./scripts/syncTNPM.mjs\").then(m => m.default())'",
|
|
230
|
-
"test": "cross-env TZ=UTC vitest run",
|
|
231
|
-
"test:coverage": "cross-env TZ=UTC TEST_LOG=none vitest run --coverage",
|
|
232
|
-
"test:ui": "cross-env TZ=UTC vitest --ui",
|
|
233
|
-
"test:update": "cross-env TZ=UTC vitest -u",
|
|
234
|
-
"tsc": "tsc --noEmit",
|
|
235
|
-
"publish:beta": "npm publish --tag beta",
|
|
236
|
-
"update:deps": "pnpm up --latest"
|
|
237
238
|
}
|
|
238
239
|
}
|