@ucloud-fe/react-components 1.4.4 → 1.5.0

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/icon.min.js +1 -1
  3. package/dist/main.min.js +4 -4
  4. package/lib/components/Calendar/style/index.js +5 -5
  5. package/lib/components/DatePicker/Range.js +16 -6
  6. package/lib/components/DatePicker/usePicker.js +31 -15
  7. package/lib/components/DatePicker/useRangePicker.d.ts +1 -0
  8. package/lib/components/DatePicker/useRangePicker.js +3 -2
  9. package/lib/components/DatePicker/utils.d.ts +2 -1
  10. package/lib/components/DatePicker/utils.js +13 -1
  11. package/lib/components/Form/ControllerContext.d.ts +1 -1
  12. package/lib/components/Input/.recodo/interaction.js +2 -2
  13. package/lib/components/Input/Input.js +12 -60
  14. package/lib/components/Input/Search.js +1 -0
  15. package/lib/components/Input/style/index.d.ts +23 -8
  16. package/lib/components/Input/style/index.js +97 -17
  17. package/lib/components/Menu/Item.js +9 -2
  18. package/lib/components/Menu/Menu.d.ts +11 -3
  19. package/lib/components/Menu/Menu.js +23 -9
  20. package/lib/components/Menu/MenuContext.d.ts +1 -0
  21. package/lib/components/Menu/index.d.ts +2 -2
  22. package/lib/components/Menu/style/index.d.ts +3 -0
  23. package/lib/components/Menu/style/index.js +14 -8
  24. package/lib/components/Notice/index.d.ts +1 -1
  25. package/lib/components/Select/Group.d.ts +3 -0
  26. package/lib/components/Select/Group.js +4 -0
  27. package/lib/components/Select/Overflow.d.ts +19 -0
  28. package/lib/components/Select/Overflow.js +155 -0
  29. package/lib/components/Select/Select.d.ts +15 -9
  30. package/lib/components/Select/Select.js +1149 -322
  31. package/lib/components/Select/SelectContext.d.ts +1 -1
  32. package/lib/components/Select/index.d.ts +3 -1
  33. package/lib/components/Select/locale/en_US.js +2 -1
  34. package/lib/components/Select/locale/zh_CN.d.ts +1 -0
  35. package/lib/components/Select/locale/zh_CN.js +2 -1
  36. package/lib/components/Select/style/index.d.ts +43 -6
  37. package/lib/components/Select/style/index.js +128 -42
  38. package/lib/components/SvgIcon/icons/ArrowDown.js +2 -2
  39. package/lib/components/SvgIcon/icons/ArrowLeft.js +3 -2
  40. package/lib/components/SvgIcon/icons/ArrowRight.js +2 -2
  41. package/lib/components/SvgIcon/icons/ArrowUp.js +2 -2
  42. package/lib/components/SvgIcon/icons/DoubleArrowLeft.js +4 -7
  43. package/lib/components/SvgIcon/icons/DoubleArrowRight.js +4 -6
  44. package/lib/components/SvgIcon/style/index.js +2 -2
  45. package/lib/hooks/group.d.ts +1 -1
  46. package/lib/hooks/group.js +5 -9
  47. package/lib/hooks/useUncontrolled.d.ts +1 -1
  48. package/lib/hooks/useUncontrolled.js +1 -1
  49. package/lib/libs/rc-table/Table.js +2 -3
  50. package/lib/sharedComponents/InputWrap.d.ts +16 -0
  51. package/lib/sharedComponents/InputWrap.js +66 -0
  52. package/lib/utils/pick.d.ts +1 -1
  53. package/package.json +3 -3
@@ -11,7 +11,7 @@ exports.default = exports.deprecatedLogForPopover = void 0;
11
11
 
12
12
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
13
 
14
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
15
 
16
16
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
17
17
 
@@ -19,7 +19,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
19
19
 
20
20
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
21
21
 
22
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
22
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
23
 
24
24
  var _newArrowCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/newArrowCheck"));
25
25
 
@@ -27,15 +27,21 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
27
27
 
28
28
  var _react = _interopRequireWildcard(require("react"));
29
29
 
30
+ var _classnames = _interopRequireDefault(require("classnames"));
31
+
30
32
  var _Popover = _interopRequireDefault(require("../../components/Popover"));
31
33
 
32
- var _ConfigContext = _interopRequireDefault(require("../../components/ConfigProvider/ConfigContext"));
34
+ var _Tag = _interopRequireDefault(require("../../components/Tag"));
35
+
36
+ var _Tooltip = _interopRequireDefault(require("../../components/Tooltip"));
37
+
38
+ var _Search = require("../../sharedComponents/Search");
33
39
 
34
40
  var _useLocale = _interopRequireDefault(require("../../components/LocaleProvider/useLocale"));
35
41
 
36
- var _group3 = require("../../hooks/group");
42
+ var _SvgIcon = _interopRequireDefault(require("../../components/SvgIcon"));
37
43
 
38
- var _usePopoverConfig = require("../../hooks/usePopoverConfig");
44
+ var _usePopoverConfig = _interopRequireDefault(require("../../hooks/usePopoverConfig"));
39
45
 
40
46
  var _useUncontrolled5 = _interopRequireDefault(require("../../hooks/useUncontrolled"));
41
47
 
@@ -51,23 +57,32 @@ var _isObject = _interopRequireDefault(require("../../utils/isObject"));
51
57
 
52
58
  var _isEmpty = _interopRequireDefault(require("../../utils/isEmpty"));
53
59
 
60
+ var _style = require("../../components/Input/style");
61
+
62
+ var _VirtualScrollList = _interopRequireDefault(require("../../sharedComponents/VirtualScrollList"));
63
+
54
64
  var _Option = require("./Option");
55
65
 
56
66
  var _Group = _interopRequireDefault(require("./Group"));
57
67
 
58
68
  var _Extra = _interopRequireDefault(require("./Extra"));
59
69
 
60
- var _style = require("./style");
70
+ var _style2 = require("./style");
61
71
 
62
72
  var _SelectContext = _interopRequireDefault(require("./SelectContext"));
63
73
 
64
74
  var _zh_CN = _interopRequireDefault(require("./locale/zh_CN"));
65
75
 
66
- var _excluded = ["size", "disabled", "multiple", "placeholder", "renderContent", "renderSelector", "renderPopup", "value", "visible", "locale", "dataSource"],
67
- _excluded2 = ["content"],
68
- _excluded3 = ["size", "value", "defaultValue", "onChange", "onVisibleChange", "disabled", "search", "multiple", "renderContent", "renderSelector", "placeholder", "locale", "options", "children", "emptyContent", "showSelectAll", "extra", "customStyle", "popover", "popoverProps", "renderPopup", "virtualList"];
76
+ var _Overflow = _interopRequireWildcard(require("./Overflow"));
69
77
 
70
- var _this = void 0;
78
+ var _this7 = void 0;
79
+
80
+ var _excluded = ["v1"],
81
+ _excluded2 = ["content"],
82
+ _excluded3 = ["content"],
83
+ _excluded4 = ["v1", "size", "disabled", "multiple", "placeholder", "renderContent", "renderSelector", "renderPopup", "value", "onChange", "visible", "locale", "dataSource", "search", "searchValue", "setSearchValue", "wrapRef", "clearable", "styleType", "block"],
84
+ _excluded5 = ["items", "onClose", "disabled"],
85
+ _excluded6 = ["size", "value", "defaultValue", "onChange", "onVisibleChange", "disabled", "search", "multiple", "renderContent", "renderSelector", "placeholder", "locale", "options", "children", "emptyContent", "showSelectAll", "extra", "clearable", "customStyle", "popover", "popoverProps", "renderPopup", "virtualList", "block", "styleType"];
71
86
 
72
87
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
73
88
 
@@ -82,6 +97,9 @@ exports.deprecatedLogForPopover = deprecatedLogForPopover;
82
97
  var warnLogForVirtualList = (0, _warning.onceWarning)('Select virtualList only valid when use options');
83
98
  var warnLogForCustomHeight = (0, _warning.onceWarning)('CustomStyle.optionListMaxHeight is invalid when use virtualList, please use virtualList.height');
84
99
  var warnLogForSearchProps = (0, _warning.onceWarning)("Don't use item.props in custom search, just use item as props.");
100
+ var warnLogForSubGroup = (0, _deprecatedLog.default)('Select.Group', 'Cascader');
101
+ var popoverStretch = ['minWidth'];
102
+ var blockPopoverStretch = ['width'];
85
103
  var groupOptions = {
86
104
  itemTag: 'isMenuItem',
87
105
  subGroupTag: 'isMenuSubMenu',
@@ -93,227 +111,133 @@ var groupOptions = {
93
111
  SubGroupComponent: _Group.default
94
112
  };
95
113
 
96
- var Selector = function Selector(_ref) {
97
- var _this2 = this;
98
-
99
- (0, _newArrowCheck2.default)(this, _this);
100
- var size = _ref.size,
101
- disabled = _ref.disabled,
102
- multiple = _ref.multiple,
103
- placeholder = _ref.placeholder,
104
- renderContent = _ref.renderContent,
105
- renderSelector = _ref.renderSelector,
106
- renderPopup = _ref.renderPopup,
107
- value = _ref.value,
108
- visible = _ref.visible,
109
- locale = _ref.locale,
110
- dataSource = _ref.dataSource,
111
- rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
112
- placeholder = (0, _react.useMemo)(function () {
113
- (0, _newArrowCheck2.default)(this, _this2);
114
- return placeholder || locale.placeholder;
115
- }.bind(this), [locale.placeholder, placeholder]);
116
- var defaultRenderContent = (0, _react.useCallback)(function (value, valueChild) {
117
- (0, _newArrowCheck2.default)(this, _this2);
114
+ var groupChildrenAsDataSource = function groupChildrenAsDataSource(children) {
115
+ var _this = this;
118
116
 
119
- if (!multiple) {
120
- if (value === undefined) {
121
- return placeholder;
122
- } else {
123
- return valueChild;
124
- }
125
- } else {
126
- if (value && value.length) {
127
- return "".concat(locale.selected).concat(value.length).concat(locale.items);
128
- } else {
129
- return placeholder;
130
- }
131
- }
132
- }.bind(this), [locale.items, locale.selected, multiple, placeholder]);
133
- var getContent = (0, _react.useCallback)(function () {
134
- var _this3 = this;
117
+ var globalDisabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
135
118
 
136
- (0, _newArrowCheck2.default)(this, _this2);
119
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
120
+ itemTag: 'isItem',
121
+ subGroupTag: 'isSubGroup',
122
+ itemKeyName: 'itemKey',
123
+ subGroupKeyName: 'subGroupKey'
124
+ },
125
+ itemTag = _ref.itemTag,
126
+ subGroupTag = _ref.subGroupTag,
127
+ itemKeyName = _ref.itemKeyName,
128
+ subGroupKeyName = _ref.subGroupKeyName;
137
129
 
138
- var _dataSource = (0, _slicedToArray2.default)(dataSource, 5),
139
- _dataSource$ = _dataSource[4],
140
- childrenMap = _dataSource$ === void 0 ? new Map() : _dataSource$;
130
+ var searchValue = arguments.length > 3 ? arguments[3] : undefined;
131
+ var handleSearch = arguments.length > 4 ? arguments[4] : undefined;
132
+ var subGroupMap = new Map();
133
+ var childrenMap = new Map();
141
134
 
142
- var valueChild;
135
+ var _group = function group(children, disabled, prefix) {
136
+ var _this2 = this;
143
137
 
144
- var getValueChild = function getValueChild(v) {
145
- (0, _newArrowCheck2.default)(this, _this3);
146
- return childrenMap.has(v) ? childrenMap.get(v) : v;
147
- }.bind(this);
138
+ (0, _newArrowCheck2.default)(this, _this);
139
+ var validKeys = [];
140
+ var disabledKeys = [];
148
141
 
149
- if (!multiple) {
150
- valueChild = getValueChild(value);
151
- } else {
152
- var _value = value ? (0, _toConsumableArray2.default)(value) : []; // only get the top twenty item child for better performance
142
+ var l = _react.default.Children.count(children);
153
143
 
144
+ var renderChildren = [];
154
145
 
155
- if (_value.length > 20) {
156
- _value.length = 20;
157
- }
146
+ _react.default.Children.forEach(children, function (child, i) {
147
+ (0, _newArrowCheck2.default)(this, _this2);
148
+ var isFirst = i === 0;
149
+ var isLast = i === l - 1;
158
150
 
159
- valueChild = _value.map(getValueChild);
160
- }
151
+ if ( /*#__PURE__*/_react.default.isValidElement(child)) {
152
+ var _child$type, _child$type2;
161
153
 
162
- if (renderContent) {
163
- return renderContent(value, valueChild);
164
- } else {
165
- return defaultRenderContent(value, valueChild);
166
- }
167
- }.bind(this), [dataSource, defaultRenderContent, multiple, renderContent, value]);
168
- var content = (0, _react.useMemo)(getContent, [getContent]); // 自定义渲染弹层时,开发者可能不传入 options 和 children,导致 content memo deps 不触发变更,故强制更新
154
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
+ if ((_child$type = child.type) !== null && _child$type !== void 0 && _child$type[itemTag]) {
156
+ var _props = child.props;
169
157
 
170
- if (renderPopup) content = getContent();
158
+ var _key = _props[itemKeyName] === undefined ? child.key : _props[itemKeyName];
171
159
 
172
- if (renderSelector) {
173
- var selector = renderSelector(content, visible) || /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
160
+ var _visible = searchValue ? handleSearch(_key, child.props) : true;
174
161
 
175
- return /*#__PURE__*/_react.default.isValidElement(selector) ? /*#__PURE__*/_react.default.cloneElement(selector, rest) : null;
176
- }
162
+ if (_visible) {
163
+ var _ref2, _React$cloneElement;
177
164
 
178
- var title = typeof content === 'string' ? content : undefined;
179
- return /*#__PURE__*/_react.default.createElement(_style.SSelector, (0, _extends2.default)({
180
- styleType: "border",
181
- size: size,
182
- disabled: disabled,
183
- title: title
184
- }, rest), /*#__PURE__*/_react.default.createElement("div", {
185
- className: _style.selectorContentCls,
186
- key: "content"
187
- }, content), /*#__PURE__*/_react.default.createElement(_style.Arrow, {
188
- key: "icon",
189
- type: visible ? 'arrow-up' : 'arrow-down'
190
- }));
191
- }.bind(void 0);
165
+ var isDisabled = disabled || _props.disabled;
192
166
 
193
- var Popup = function Popup(_ref2) {
194
- var _this4 = this;
195
-
196
- (0, _newArrowCheck2.default)(this, _this);
197
- var extra = _ref2.extra,
198
- _ref2$customStyle = _ref2.customStyle,
199
- customStyle = _ref2$customStyle === void 0 ? {} : _ref2$customStyle,
200
- search = _ref2.search,
201
- multiple = _ref2.multiple,
202
- emptyContent = _ref2.emptyContent,
203
- showSelectAll = _ref2.showSelectAll,
204
- value = _ref2.value,
205
- renderPopup = _ref2.renderPopup,
206
- options = _ref2.options,
207
- children = _ref2.children,
208
- onChange = _ref2.onChange,
209
- locale = _ref2.locale,
210
- handleVisibleChange = _ref2.handleVisibleChange,
211
- hidePopup = _ref2.hidePopup,
212
- dataSource = _ref2.dataSource,
213
- searchValue = _ref2.searchValue,
214
- setSearchValue = _ref2.setSearchValue,
215
- virtualList = _ref2.virtualList;
216
- var handleChange = (0, _react.useCallback)(function (value) {
217
- (0, _newArrowCheck2.default)(this, _this4);
167
+ if (isDisabled) {
168
+ disabledKeys.push(_key);
169
+ } else {
170
+ validKeys.push(_key);
171
+ }
218
172
 
219
- if (!multiple) {
220
- handleVisibleChange(false);
221
- onChange(value[0]);
222
- } else {
223
- onChange(value);
224
- }
225
- }.bind(this), [multiple, onChange, handleVisibleChange]);
226
- var handleSearchInput = (0, _react.useCallback)(function (e) {
227
- (0, _newArrowCheck2.default)(this, _this4);
228
- setSearchValue(e.target.value);
229
- }.bind(this), [setSearchValue]);
230
- var finalExtra = (0, _react.useMemo)(function () {
231
- (0, _newArrowCheck2.default)(this, _this4);
173
+ var display = Array.isArray(_visible) ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, _visible[0], /*#__PURE__*/_react.default.createElement(_Search.Highlight, null, _visible[1]), _visible[2]) : (_ref2 = _props.children) !== null && _ref2 !== void 0 ? _ref2 : _key;
174
+ renderChildren.push( /*#__PURE__*/_react.default.cloneElement(child, (_React$cloneElement = {}, (0, _defineProperty2.default)(_React$cloneElement, itemKeyName, _key), (0, _defineProperty2.default)(_React$cloneElement, "disabled", globalDisabled || isDisabled), (0, _defineProperty2.default)(_React$cloneElement, "isFirst", isFirst), (0, _defineProperty2.default)(_React$cloneElement, "isLast", isLast), (0, _defineProperty2.default)(_React$cloneElement, "key", _key), (0, _defineProperty2.default)(_React$cloneElement, "children", display), _React$cloneElement)));
175
+ childrenMap.set(_key, display);
176
+ } else {
177
+ childrenMap.set(_key, _props.children);
178
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
232
179
 
233
- if (typeof extra === 'function') {
234
- return /*#__PURE__*/_react.default.createElement(_Extra.default, null, extra(hidePopup));
235
- } else if (!(0, _isEmpty.default)(extra)) {
236
- if ( /*#__PURE__*/_react.default.isValidElement(extra)) {
237
- return /*#__PURE__*/_react.default.createElement(_Extra.default, null, extra);
238
- } else if ((0, _isObject.default)(extra)) {
239
- var _ref3 = extra,
240
- _content = _ref3.content,
241
- rest = (0, _objectWithoutProperties2.default)(_ref3, _excluded2);
242
- return /*#__PURE__*/_react.default.createElement(_Extra.default, rest, _content);
243
- }
244
- }
245
- }.bind(this), [extra, hidePopup]);
180
+ } else if (subGroupTag && subGroupKeyName && (_child$type2 = child.type) !== null && _child$type2 !== void 0 && _child$type2[subGroupTag]) {
181
+ var _React$cloneElement2;
246
182
 
247
- if (renderPopup) {
248
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, renderPopup({
249
- handleVisible: handleVisibleChange,
250
- onChange: onChange,
251
- value: value,
252
- multiple: multiple,
253
- extra: extra,
254
- search: search,
255
- children: children,
256
- options: options
257
- }));
258
- }
183
+ var _props2 = child.props;
259
184
 
260
- var maxWidth = customStyle.popupMaxWidth ? customStyle.popupMaxWidth : 'none';
185
+ var _key2 = _props2[subGroupKeyName] || child.key || "".concat(prefix, "-").concat(i);
261
186
 
262
- var newCustomStyle = _objectSpread({}, customStyle);
187
+ var _isDisabled = disabled || _props2.disabled;
263
188
 
264
- if (virtualList) {
265
- newCustomStyle.optionListMaxHeight = 'none';
266
- if ('optionListMaxHeight' in newCustomStyle) warnLogForCustomHeight();
267
- }
189
+ var _group2 = _group(child.props.children, _isDisabled, _key2),
190
+ _group3 = (0, _slicedToArray2.default)(_group2, 3),
191
+ subValidKeys = _group3[0],
192
+ subDisabledKeys = _group3[1],
193
+ subRenderChildren = _group3[2];
194
+
195
+ subGroupMap.set(_key2, {
196
+ validKeys: subValidKeys,
197
+ disabledKeys: subDisabledKeys
198
+ });
199
+ validKeys.push.apply(validKeys, (0, _toConsumableArray2.default)(subValidKeys));
200
+ disabledKeys.push.apply(disabledKeys, (0, _toConsumableArray2.default)(subDisabledKeys));
201
+ renderChildren.push( /*#__PURE__*/_react.default.cloneElement(child, (_React$cloneElement2 = {
202
+ disabled: globalDisabled || _isDisabled
203
+ }, (0, _defineProperty2.default)(_React$cloneElement2, subGroupKeyName, _key2), (0, _defineProperty2.default)(_React$cloneElement2, "isFirst", isFirst), (0, _defineProperty2.default)(_React$cloneElement2, "isLast", isLast), (0, _defineProperty2.default)(_React$cloneElement2, "key", _key2), _React$cloneElement2), subRenderChildren));
204
+ } else {
205
+ renderChildren.push(child);
206
+ }
207
+ }
208
+ }.bind(this));
268
209
 
269
- var renderEmptyContent = function renderEmptyContent() {
270
- (0, _newArrowCheck2.default)(this, _this4);
271
- return emptyContent || /*#__PURE__*/_react.default.createElement(_style.EmptyContentWrapper, null, locale.emptyTip);
210
+ return [validKeys, disabledKeys, renderChildren];
272
211
  }.bind(this);
273
212
 
274
- return /*#__PURE__*/_react.default.createElement(_style.MenuWrap, null, search && /*#__PURE__*/_react.default.createElement(_style.SelectSearchInput, {
275
- onChange: handleSearchInput,
276
- value: searchValue,
277
- status: "default"
278
- }), children || options !== null && options !== void 0 && options.length ? /*#__PURE__*/_react.default.createElement(_style.BlockMenu, {
279
- onChange: handleChange,
280
- customStyle: newCustomStyle,
281
- menuCustomStyle: {
282
- maxWidth: maxWidth
283
- },
284
- dataSource: dataSource,
285
- multiple: multiple,
286
- showSelectAll: showSelectAll,
287
- selectedKeys: multiple ? value : [value],
288
- virtualList: options ? virtualList : false
289
- }) : /*#__PURE__*/_react.default.createElement(_style.BlockMenu, null, renderEmptyContent()), finalExtra ? /*#__PURE__*/_react.default.createElement(_style.FooterWrap, null, finalExtra) : null);
290
- }.bind(void 0);
213
+ return [].concat((0, _toConsumableArray2.default)(_group(children, false, 'group-root')), [subGroupMap, childrenMap]);
214
+ };
291
215
 
292
216
  var groupOptionsAsDataSource = function groupOptionsAsDataSource(options) {
293
- var _this5 = this;
217
+ var _this3 = this;
294
218
 
295
219
  var globalDisabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
296
220
 
297
- var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
221
+ var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
298
222
  subGroupName: 'children',
299
223
  displayName: 'label',
300
224
  itemKeyName: 'itemKey',
301
225
  subGroupKeyName: 'subGroupKey',
302
226
  ItemComponent: function ItemComponent() {
303
- (0, _newArrowCheck2.default)(this, _this5);
227
+ (0, _newArrowCheck2.default)(this, _this3);
304
228
  return null;
305
229
  }.bind(this),
306
230
  SubGroupComponent: function SubGroupComponent() {
307
- (0, _newArrowCheck2.default)(this, _this5);
231
+ (0, _newArrowCheck2.default)(this, _this3);
308
232
  return null;
309
233
  }.bind(this)
310
234
  },
311
- subGroupName = _ref4.subGroupName,
312
- displayName = _ref4.displayName,
313
- itemKeyName = _ref4.itemKeyName,
314
- subGroupKeyName = _ref4.subGroupKeyName,
315
- ItemComponent = _ref4.ItemComponent,
316
- SubGroupComponent = _ref4.SubGroupComponent;
235
+ subGroupName = _ref3.subGroupName,
236
+ displayName = _ref3.displayName,
237
+ itemKeyName = _ref3.itemKeyName,
238
+ subGroupKeyName = _ref3.subGroupKeyName,
239
+ ItemComponent = _ref3.ItemComponent,
240
+ SubGroupComponent = _ref3.SubGroupComponent;
317
241
 
318
242
  var searchValue = arguments.length > 3 ? arguments[3] : undefined;
319
243
  var handleSearch = arguments.length > 4 ? arguments[4] : undefined;
@@ -321,12 +245,12 @@ var groupOptionsAsDataSource = function groupOptionsAsDataSource(options) {
321
245
  var childrenMap = new Map();
322
246
 
323
247
  var isValidKey = function isValidKey(v) {
324
- (0, _newArrowCheck2.default)(this, _this5);
248
+ (0, _newArrowCheck2.default)(this, _this3);
325
249
  return typeof v === 'string' || typeof v === 'number';
326
250
  }.bind(this);
327
251
 
328
252
  var group = function group(options) {
329
- var _this6 = this;
253
+ var _this4 = this;
330
254
 
331
255
  var disabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
332
256
  var prefixKey = arguments.length > 2 ? arguments[2] : undefined;
@@ -334,65 +258,67 @@ var groupOptionsAsDataSource = function groupOptionsAsDataSource(options) {
334
258
  var disabledKeys = [];
335
259
  var renderChildren = [];
336
260
  options.forEach(function (child, i) {
337
- (0, _newArrowCheck2.default)(this, _this6);
261
+ (0, _newArrowCheck2.default)(this, _this4);
338
262
  var subChildren = child[subGroupName];
339
263
 
340
264
  if (subChildren) {
341
- var _key = child[subGroupKeyName] || child.key || "".concat(prefixKey, "-").concat(i);
265
+ var _key3 = child[subGroupKeyName] || child.key || "".concat(prefixKey, "-").concat(i);
342
266
 
343
267
  var reactKey = child.key || isValidKey(child[subGroupKeyName]) ? child[subGroupKeyName] : "".concat(prefixKey, "-").concat(i);
344
268
  var isDisabled = disabled || child.disabled;
345
269
 
346
- var _group = group(subChildren, isDisabled, _key),
347
- _group2 = (0, _slicedToArray2.default)(_group, 3),
348
- subValidKeys = _group2[0],
349
- subDisabledKeys = _group2[1],
350
- subRenderChildren = _group2[2];
270
+ var _group4 = group(subChildren, isDisabled, _key3),
271
+ _group5 = (0, _slicedToArray2.default)(_group4, 3),
272
+ subValidKeys = _group5[0],
273
+ subDisabledKeys = _group5[1],
274
+ subRenderChildren = _group5[2];
351
275
 
352
- subGroupMap.set(_key, {
276
+ subGroupMap.set(_key3, {
353
277
  validKeys: subValidKeys,
354
278
  disabledKeys: subDisabledKeys
355
279
  });
356
280
  validKeys.push.apply(validKeys, (0, _toConsumableArray2.default)(subValidKeys));
357
281
  disabledKeys.push.apply(disabledKeys, (0, _toConsumableArray2.default)(subDisabledKeys));
358
282
 
359
- var _visible = searchValue ? !!subRenderChildren.length : true;
283
+ var _visible2 = searchValue ? !!subRenderChildren.length : true;
360
284
 
361
- if (_visible) {
285
+ if (_visible2) {
362
286
  renderChildren.push( /*#__PURE__*/_react.default.createElement(SubGroupComponent, (0, _extends2.default)({
363
287
  key: reactKey
364
288
  }, child, (0, _defineProperty2.default)({
365
289
  disabled: globalDisabled || isDisabled
366
- }, subGroupKeyName, _key)), subRenderChildren));
290
+ }, subGroupKeyName, _key3)), subRenderChildren));
367
291
  }
368
292
  } else {
369
- var _ref6;
370
-
371
- var _key2 = child[itemKeyName] === undefined ? child.key : child[itemKeyName];
293
+ var _key4 = child[itemKeyName] === undefined ? child.key : child[itemKeyName];
372
294
 
373
295
  var _reactKey = child.key || isValidKey(child[itemKeyName]) ? child[itemKeyName] : "".concat(prefixKey, "-").concat(i);
374
296
 
375
- var _isDisabled = disabled || child.disabled;
297
+ var _isDisabled2 = disabled || child.disabled;
376
298
 
377
- if (_isDisabled) {
378
- disabledKeys.push(_key2);
379
- } else {
380
- validKeys.push(_key2);
381
- }
299
+ var _visible3 = searchValue ? handleSearch(_key4, child) : true;
382
300
 
383
- var display = (_ref6 = child[displayName]) !== null && _ref6 !== void 0 ? _ref6 : _key2;
301
+ if (_visible3) {
302
+ var _ref5;
384
303
 
385
- var _visible2 = searchValue ? handleSearch(_key2, child) : true;
304
+ if (_isDisabled2) {
305
+ disabledKeys.push(_key4);
306
+ } else {
307
+ validKeys.push(_key4);
308
+ }
386
309
 
387
- if (_visible2) {
310
+ var display = Array.isArray(_visible3) ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, _visible3[0], /*#__PURE__*/_react.default.createElement(_Search.Highlight, null, _visible3[1]), _visible3[2]) : (_ref5 = child[displayName]) !== null && _ref5 !== void 0 ? _ref5 : _key4;
388
311
  renderChildren.push( /*#__PURE__*/_react.default.createElement(ItemComponent, (0, _extends2.default)({
389
312
  key: _reactKey
390
313
  }, child, (0, _defineProperty2.default)({
391
- disabled: globalDisabled || _isDisabled
392
- }, itemKeyName, _key2)), display));
393
- }
314
+ disabled: globalDisabled || _isDisabled2
315
+ }, itemKeyName, _key4)), display));
316
+ childrenMap.set(_key4, display);
317
+ } else {
318
+ var _ref7;
394
319
 
395
- childrenMap.set(_key2, display);
320
+ childrenMap.set(_key4, (_ref7 = child[displayName]) !== null && _ref7 !== void 0 ? _ref7 : child[itemKeyName]);
321
+ }
396
322
  }
397
323
  }.bind(this));
398
324
  return [validKeys, disabledKeys, renderChildren];
@@ -401,50 +327,891 @@ var groupOptionsAsDataSource = function groupOptionsAsDataSource(options) {
401
327
  return [].concat((0, _toConsumableArray2.default)(group(options, false, 'group-root')), [subGroupMap, childrenMap]);
402
328
  };
403
329
 
404
- var Select = function Select(_ref8) {
330
+ var Popup = /*#__PURE__*/_react.default.memo(function Popup(_ref8) {
331
+ var v1 = _ref8.v1,
332
+ props = (0, _objectWithoutProperties2.default)(_ref8, _excluded);
333
+ var PopupComponent = props.renderPopup ? CustomPopup : v1 ? PopupV1 : PopupV2;
334
+ return /*#__PURE__*/_react.default.createElement(PopupComponent, props);
335
+ });
336
+
337
+ var CustomPopup = /*#__PURE__*/_react.default.memo(function CustomPopup(props) {
338
+ var onChange = props.onChange,
339
+ value = props.value,
340
+ multiple = props.multiple,
341
+ extra = props.extra,
342
+ search = props.search,
343
+ children = props.children,
344
+ options = props.options,
345
+ handleVisibleChange = props.handleVisibleChange,
346
+ renderPopup = props.renderPopup;
347
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, renderPopup === null || renderPopup === void 0 ? void 0 : renderPopup({
348
+ handleVisible: handleVisibleChange,
349
+ onChange: onChange,
350
+ value: value,
351
+ multiple: multiple,
352
+ extra: extra,
353
+ search: search,
354
+ children: children,
355
+ options: options
356
+ }));
357
+ });
358
+
359
+ var PopupV1 = /*#__PURE__*/_react.default.memo(function PopupV1(_ref9) {
360
+ var _this5 = this;
361
+
362
+ var extra = _ref9.extra,
363
+ _ref9$customStyle = _ref9.customStyle,
364
+ customStyle = _ref9$customStyle === void 0 ? {} : _ref9$customStyle,
365
+ search = _ref9.search,
366
+ multiple = _ref9.multiple,
367
+ _emptyContent = _ref9.emptyContent,
368
+ showSelectAll = _ref9.showSelectAll,
369
+ value = _ref9.value,
370
+ options = _ref9.options,
371
+ children = _ref9.children,
372
+ onChange = _ref9.onChange,
373
+ locale = _ref9.locale,
374
+ handleVisibleChange = _ref9.handleVisibleChange,
375
+ hidePopup = _ref9.hidePopup,
376
+ dataSource = _ref9.dataSource,
377
+ searchValue = _ref9.searchValue,
378
+ setSearchValue = _ref9.setSearchValue,
379
+ virtualList = _ref9.virtualList;
380
+ var handleChange = (0, _react.useCallback)(function (value) {
381
+ (0, _newArrowCheck2.default)(this, _this5);
382
+
383
+ if (!multiple) {
384
+ handleVisibleChange(false);
385
+ onChange(value[0]);
386
+ } else {
387
+ onChange(value);
388
+ }
389
+ }.bind(this), [multiple, onChange, handleVisibleChange]);
390
+ var handleSearchInput = (0, _react.useCallback)(function (e) {
391
+ (0, _newArrowCheck2.default)(this, _this5);
392
+ setSearchValue(e.target.value);
393
+ }.bind(this), [setSearchValue]);
394
+ var finalExtra = (0, _react.useMemo)(function () {
395
+ (0, _newArrowCheck2.default)(this, _this5);
396
+
397
+ if (typeof extra === 'function') {
398
+ return /*#__PURE__*/_react.default.createElement(_Extra.default, null, extra(hidePopup));
399
+ } else if (!(0, _isEmpty.default)(extra)) {
400
+ if ( /*#__PURE__*/_react.default.isValidElement(extra)) {
401
+ return /*#__PURE__*/_react.default.createElement(_Extra.default, null, extra);
402
+ } else if ((0, _isObject.default)(extra)) {
403
+ var _ref10 = extra,
404
+ _content = _ref10.content,
405
+ rest = (0, _objectWithoutProperties2.default)(_ref10, _excluded2);
406
+ return /*#__PURE__*/_react.default.createElement(_Extra.default, rest, _content);
407
+ }
408
+ }
409
+ }.bind(this), [extra, hidePopup]);
410
+ var maxWidth = customStyle.popupMaxWidth ? customStyle.popupMaxWidth : 'none';
411
+
412
+ var newCustomStyle = _objectSpread({}, customStyle);
413
+
414
+ if (virtualList) {
415
+ if ('optionListMaxHeight' in newCustomStyle) {
416
+ warnLogForCustomHeight();
417
+ }
418
+
419
+ newCustomStyle.optionListMaxHeight = 'none';
420
+ }
421
+
422
+ var emptyContent = (0, _react.useMemo)(function () {
423
+ (0, _newArrowCheck2.default)(this, _this5);
424
+ return _emptyContent || /*#__PURE__*/_react.default.createElement(_style2.EmptyContentWrapper, null, locale.emptyTip);
425
+ }.bind(this), [_emptyContent, locale]);
426
+ return /*#__PURE__*/_react.default.createElement(_style2.MenuWrap, {
427
+ maxWidth: maxWidth
428
+ }, search && /*#__PURE__*/_react.default.createElement(_style2.SelectSearchInput, {
429
+ onChange: handleSearchInput,
430
+ value: searchValue,
431
+ status: "default"
432
+ }), children || options !== null && options !== void 0 && options.length ? /*#__PURE__*/_react.default.createElement(_style2.BlockMenu, {
433
+ onChange: handleChange,
434
+ customStyle: newCustomStyle,
435
+ menuCustomStyle: {
436
+ maxWidth: 'none'
437
+ },
438
+ dataSource: dataSource,
439
+ multiple: multiple,
440
+ showSelectAll: showSelectAll,
441
+ selectedKeys: multiple ? value : [value],
442
+ virtualList: options ? virtualList : false
443
+ }) : /*#__PURE__*/_react.default.createElement(_style2.BlockMenu, {
444
+ customStyle: newCustomStyle,
445
+ menuCustomStyle: {
446
+ maxWidth: 'none'
447
+ }
448
+ }, emptyContent), finalExtra ? /*#__PURE__*/_react.default.createElement(_style2.FooterWrap, null, finalExtra) : null);
449
+ });
450
+
451
+ var PopupV2 = /*#__PURE__*/_react.default.memo(function PopupV2(_ref11) {
452
+ var _this6 = this,
453
+ _dataSource$;
454
+
455
+ var extra = _ref11.extra,
456
+ _ref11$customStyle = _ref11.customStyle,
457
+ customStyle = _ref11$customStyle === void 0 ? {} : _ref11$customStyle,
458
+ multiple = _ref11.multiple,
459
+ _emptyContent = _ref11.emptyContent,
460
+ showSelectAll = _ref11.showSelectAll,
461
+ value = _ref11.value,
462
+ options = _ref11.options,
463
+ children = _ref11.children,
464
+ onChange = _ref11.onChange,
465
+ locale = _ref11.locale,
466
+ handleVisibleChange = _ref11.handleVisibleChange,
467
+ hidePopup = _ref11.hidePopup,
468
+ dataSource = _ref11.dataSource,
469
+ virtualList = _ref11.virtualList,
470
+ searchValue = _ref11.searchValue;
471
+ var menuRef = (0, _react.useRef)(null);
472
+ var handleChange = (0, _react.useCallback)(function (value) {
473
+ (0, _newArrowCheck2.default)(this, _this6);
474
+
475
+ if (!multiple) {
476
+ handleVisibleChange(false);
477
+ onChange(value[0]);
478
+ } else {
479
+ onChange(value);
480
+ }
481
+ }.bind(this), [multiple, onChange, handleVisibleChange]);
482
+ var handleSelectAll = (0, _react.useCallback)(function () {
483
+ (0, _newArrowCheck2.default)(this, _this6);
484
+ var validKeys = dataSource[0];
485
+ var newValue = Array.from(new Set([].concat((0, _toConsumableArray2.default)(value || []), (0, _toConsumableArray2.default)(validKeys))));
486
+ onChange(newValue);
487
+ }.bind(this), [dataSource, onChange, value]);
488
+ var emptyContent = (0, _react.useMemo)(function () {
489
+ (0, _newArrowCheck2.default)(this, _this6);
490
+ return _emptyContent || /*#__PURE__*/_react.default.createElement(_style2.EmptyContentWrapper, null, locale.emptyTip);
491
+ }.bind(this), [_emptyContent, locale]);
492
+ var finalExtra = (0, _react.useMemo)(function () {
493
+ (0, _newArrowCheck2.default)(this, _this6);
494
+
495
+ if (typeof extra === 'function') {
496
+ return /*#__PURE__*/_react.default.createElement(_Extra.default, null, extra(hidePopup));
497
+ } else if (!(0, _isEmpty.default)(extra)) {
498
+ if ( /*#__PURE__*/_react.default.isValidElement(extra)) {
499
+ return /*#__PURE__*/_react.default.createElement(_Extra.default, null, extra);
500
+ } else if ((0, _isObject.default)(extra)) {
501
+ var _ref12 = extra,
502
+ _content2 = _ref12.content,
503
+ rest = (0, _objectWithoutProperties2.default)(_ref12, _excluded3);
504
+ return /*#__PURE__*/_react.default.createElement(_Extra.default, rest, _content2);
505
+ }
506
+ }
507
+ }.bind(this), [extra, hidePopup]);
508
+ var maxWidth = customStyle.popupMaxWidth ? customStyle.popupMaxWidth : 'none';
509
+
510
+ var newCustomStyle = _objectSpread({}, customStyle);
511
+
512
+ if (virtualList) {
513
+ if ('optionListMaxHeight' in newCustomStyle) {
514
+ warnLogForCustomHeight();
515
+ }
516
+
517
+ newCustomStyle.optionListMaxHeight = 'none';
518
+ }
519
+
520
+ var hasContent = (children || (options === null || options === void 0 ? void 0 : options.length)) && (Array.isArray(dataSource[2]) ? (_dataSource$ = dataSource[2]) === null || _dataSource$ === void 0 ? void 0 : _dataSource$.length : dataSource[2]);
521
+ return /*#__PURE__*/_react.default.createElement(_style2.MenuWrap, {
522
+ maxWidth: maxWidth
523
+ }, hasContent ? /*#__PURE__*/_react.default.createElement(_style2.BlockMenu, {
524
+ showSelectAll: showSelectAll && multiple && /*#__PURE__*/_react.default.createElement("div", {
525
+ className: _style2.selectAllBtnWrapCls,
526
+ key: "__select_select_all",
527
+ onClick: handleSelectAll
528
+ }, locale.selectAll, searchValue ? " (".concat(searchValue, ")") : ''),
529
+ onChange: handleChange,
530
+ customStyle: newCustomStyle,
531
+ menuCustomStyle: {
532
+ maxWidth: 'none'
533
+ },
534
+ dataSource: dataSource,
535
+ multiple: multiple,
536
+ selectedKeys: multiple ? value : [value],
537
+ virtualList: options ? virtualList : false,
538
+ ref: menuRef,
539
+ _selectStyle: multiple
540
+ }) : /*#__PURE__*/_react.default.createElement(_style2.BlockMenu, {
541
+ customStyle: newCustomStyle,
542
+ menuCustomStyle: {
543
+ maxWidth: 'none'
544
+ }
545
+ }, emptyContent), finalExtra ? /*#__PURE__*/_react.default.createElement(_style2.FooterWrap, null, finalExtra) : null);
546
+ });
547
+
548
+ var Selector = /*#__PURE__*/_react.default.memo(function Selector(_ref13) {
549
+ var v1 = _ref13.v1,
550
+ size = _ref13.size,
551
+ disabled = _ref13.disabled,
552
+ multiple = _ref13.multiple,
553
+ placeholder = _ref13.placeholder,
554
+ renderContent = _ref13.renderContent,
555
+ renderSelector = _ref13.renderSelector,
556
+ renderPopup = _ref13.renderPopup,
557
+ value = _ref13.value,
558
+ onChange = _ref13.onChange,
559
+ visible = _ref13.visible,
560
+ locale = _ref13.locale,
561
+ dataSource = _ref13.dataSource,
562
+ search = _ref13.search,
563
+ searchValue = _ref13.searchValue,
564
+ setSearchValue = _ref13.setSearchValue,
565
+ wrapRef = _ref13.wrapRef,
566
+ clearable = _ref13.clearable,
567
+ styleType = _ref13.styleType,
568
+ block = _ref13.block,
569
+ _popupProps = (0, _objectWithoutProperties2.default)(_ref13, _excluded4);
570
+
571
+ var props = {
572
+ size: size,
573
+ disabled: disabled,
574
+ multiple: multiple,
575
+ placeholder: placeholder,
576
+ renderContent: renderContent,
577
+ renderSelector: renderSelector,
578
+ renderPopup: renderPopup,
579
+ value: value,
580
+ onChange: onChange,
581
+ visible: visible,
582
+ locale: locale,
583
+ dataSource: dataSource,
584
+ search: search,
585
+ searchValue: searchValue,
586
+ setSearchValue: setSearchValue,
587
+ wrapRef: wrapRef,
588
+ clearable: clearable,
589
+ block: block,
590
+ _popupProps: _popupProps
591
+ };
592
+ var SelectorComponent = renderSelector ? CustomSelector : v1 ? SelectorV1 : multiple ? styleType === 'list' ? MultipleListSelector : MultipleSelector : SingleSelector;
593
+ return /*#__PURE__*/_react.default.createElement(SelectorComponent, props);
594
+ });
595
+
596
+ var useOldContent = function useOldContent(_ref14) {
597
+ var _this8 = this;
598
+
599
+ (0, _newArrowCheck2.default)(this, _this7);
600
+ var locale = _ref14.locale,
601
+ placeholder = _ref14.placeholder,
602
+ multiple = _ref14.multiple,
603
+ dataSource = _ref14.dataSource,
604
+ value = _ref14.value,
605
+ renderContent = _ref14.renderContent,
606
+ renderPopup = _ref14.renderPopup;
607
+ placeholder = (0, _react.useMemo)(function () {
608
+ (0, _newArrowCheck2.default)(this, _this8);
609
+ return placeholder || locale.placeholder;
610
+ }.bind(this), [locale.placeholder, placeholder]);
611
+ var defaultRenderContent = (0, _react.useCallback)(function (value, valueChild) {
612
+ (0, _newArrowCheck2.default)(this, _this8);
613
+
614
+ if (!multiple) {
615
+ if (value === undefined) {
616
+ return placeholder;
617
+ } else {
618
+ return valueChild;
619
+ }
620
+ } else {
621
+ if (value && value.length) {
622
+ return "".concat(locale.selected).concat(value.length).concat(locale.items);
623
+ } else {
624
+ return placeholder;
625
+ }
626
+ }
627
+ }.bind(this), [locale.items, locale.selected, multiple, placeholder]);
628
+ var getContent = (0, _react.useCallback)(function () {
629
+ var _this9 = this;
630
+
631
+ (0, _newArrowCheck2.default)(this, _this8);
632
+
633
+ var _dataSource = (0, _slicedToArray2.default)(dataSource, 5),
634
+ _dataSource$2 = _dataSource[4],
635
+ childrenMap = _dataSource$2 === void 0 ? new Map() : _dataSource$2;
636
+
637
+ var valueChild;
638
+
639
+ var getValueChild = function getValueChild(v) {
640
+ (0, _newArrowCheck2.default)(this, _this9);
641
+ return childrenMap.has(v) ? childrenMap.get(v) : v;
642
+ }.bind(this);
643
+
644
+ if (!multiple) {
645
+ valueChild = getValueChild(value);
646
+ } else {
647
+ var _value = value ? (0, _toConsumableArray2.default)(value) : []; // only get the top twenty item child for better performance
648
+
649
+
650
+ if (_value.length > 20) {
651
+ _value.length = 20;
652
+ }
653
+
654
+ valueChild = _value.map(getValueChild);
655
+ }
656
+
657
+ if (renderContent) {
658
+ return renderContent(value, valueChild);
659
+ } else {
660
+ return defaultRenderContent(value, valueChild);
661
+ }
662
+ }.bind(this), [dataSource, defaultRenderContent, multiple, renderContent, value]);
663
+ var content = (0, _react.useMemo)(getContent, [getContent]); // 自定义渲染弹层时,开发者可能不传入 options 和 children,导致 content memo deps 不触发变更,故强制更新
664
+
665
+ if (renderPopup) content = getContent();
666
+ return content;
667
+ }.bind(void 0);
668
+
669
+ var CustomSelector = /*#__PURE__*/_react.default.memo(function CustomSelector(props) {
670
+ var content = useOldContent(props); // eslint-disable-next-line react/prop-types
671
+
672
+ var renderSelector = props.renderSelector,
673
+ visible = props.visible,
674
+ _popupProps = props._popupProps;
675
+
676
+ var selector = (renderSelector === null || renderSelector === void 0 ? void 0 : renderSelector(content, visible)) || /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
677
+
678
+ return /*#__PURE__*/_react.default.isValidElement(selector) ? /*#__PURE__*/_react.default.cloneElement(selector, _popupProps) : null;
679
+ });
680
+
681
+ var SelectorV1 = /*#__PURE__*/_react.default.memo(function SelectorV1(props) {
682
+ var size = props.size,
683
+ disabled = props.disabled,
684
+ visible = props.visible,
685
+ _popupProps = props._popupProps;
686
+ var content = useOldContent(props);
687
+ var title = typeof content === 'string' ? content : undefined;
688
+ return /*#__PURE__*/_react.default.createElement(_style2.SSelector, (0, _extends2.default)({
689
+ styleType: "border",
690
+ size: size,
691
+ disabled: disabled,
692
+ title: title
693
+ }, _popupProps), /*#__PURE__*/_react.default.createElement("div", {
694
+ className: _style2.selectorContentCls,
695
+ key: "content"
696
+ }, content), /*#__PURE__*/_react.default.createElement(_style2.Arrow, {
697
+ key: "icon",
698
+ type: visible ? 'arrow-up' : 'arrow-down'
699
+ }));
700
+ });
701
+
702
+ var RestListItem = /*#__PURE__*/_react.default.memo(function RestListItem(_ref15) {
703
+ var _this10 = this;
704
+
705
+ var item = _ref15.item,
706
+ disabled = _ref15.disabled,
707
+ onClose = _ref15.onClose;
708
+ var handleClose = (0, _react.useCallback)(function () {
709
+ (0, _newArrowCheck2.default)(this, _this10);
710
+ onClose(item.key);
711
+ }.bind(this), [item.key, onClose]);
712
+ return /*#__PURE__*/_react.default.createElement("div", {
713
+ key: item.key,
714
+ className: _style2.restItemCls
715
+ }, /*#__PURE__*/_react.default.createElement("span", {
716
+ "data-role": "label"
717
+ }, item.children), !disabled && /*#__PURE__*/_react.default.createElement("span", {
718
+ "data-role": "close",
719
+ onClick: handleClose
720
+ }, /*#__PURE__*/_react.default.createElement(_SvgIcon.default, {
721
+ type: "cross"
722
+ })));
723
+ });
724
+
725
+ var RestList = /*#__PURE__*/_react.default.memo(function RestList(_ref16) {
726
+ var _this11 = this;
727
+
728
+ var items = _ref16.items,
729
+ onClose = _ref16.onClose,
730
+ disabled = _ref16.disabled,
731
+ rest = (0, _objectWithoutProperties2.default)(_ref16, _excluded5);
732
+ var prevent = (0, _react.useCallback)(function (e) {
733
+ (0, _newArrowCheck2.default)(this, _this11);
734
+ e.preventDefault();
735
+ e.stopPropagation();
736
+ }.bind(this), []);
737
+ return /*#__PURE__*/_react.default.createElement(_style2.SRestList, (0, _extends2.default)({}, rest, {
738
+ onClick: prevent,
739
+ onContextMenu: prevent
740
+ }), /*#__PURE__*/_react.default.createElement(_VirtualScrollList.default, {
741
+ width: 160,
742
+ height: 180
743
+ }, items.map(function (item) {
744
+ (0, _newArrowCheck2.default)(this, _this11);
745
+ return /*#__PURE__*/_react.default.createElement(RestListItem, {
746
+ item: item,
747
+ key: item.key,
748
+ onClose: onClose,
749
+ disabled: disabled
750
+ });
751
+ }.bind(this))));
752
+ });
753
+
754
+ var TagItem = /*#__PURE__*/_react.default.memo(function TagItem(_ref17) {
755
+ var _this12 = this;
756
+
757
+ var item = _ref17.item,
758
+ disabled = _ref17.disabled,
759
+ onClose = _ref17.onClose;
760
+ var handleClose = (0, _react.useCallback)(function () {
761
+ (0, _newArrowCheck2.default)(this, _this12);
762
+ onClose(item.key);
763
+ }.bind(this), [item.key, onClose]);
764
+ return /*#__PURE__*/_react.default.createElement(_Tag.default, {
765
+ key: item.key,
766
+ closable: true,
767
+ disabled: disabled,
768
+ onClose: handleClose
769
+ }, item.children);
770
+ });
771
+
772
+ var restAlign = {
773
+ points: ['tl', 'br'],
774
+ overflow: {
775
+ adjustX: 1,
776
+ adjustY: 1
777
+ },
778
+ offset: [10, 10],
779
+ targetOffset: [0, 0]
780
+ };
781
+
782
+ var MultipleListSelector = /*#__PURE__*/_react.default.memo(function MultipleSelector(props) {
783
+ var _this13 = this;
784
+
785
+ var size = props.size,
786
+ disabled = props.disabled,
787
+ visible = props.visible,
788
+ dataSource = props.dataSource,
789
+ value = props.value,
790
+ onChange = props.onChange,
791
+ placeholder = props.placeholder,
792
+ search = props.search,
793
+ _props$searchValue = props.searchValue,
794
+ searchValue = _props$searchValue === void 0 ? '' : _props$searchValue,
795
+ setSearchValue = props.setSearchValue,
796
+ clearable = props.clearable,
797
+ locale = props.locale,
798
+ block = props.block,
799
+ _popupProps = props._popupProps;
800
+
801
+ var _dataSource2 = (0, _slicedToArray2.default)(dataSource, 5),
802
+ _dataSource2$ = _dataSource2[4],
803
+ childrenMap = _dataSource2$ === void 0 ? new Map() : _dataSource2$;
804
+
805
+ var inputRef = (0, _react.useRef)(null);
806
+ var items = (0, _react.useMemo)(function () {
807
+ var _this14 = this;
808
+
809
+ (0, _newArrowCheck2.default)(this, _this13);
810
+ return (value || []).map(function (v) {
811
+ (0, _newArrowCheck2.default)(this, _this14);
812
+ return {
813
+ key: v,
814
+ children: childrenMap.has(v) ? childrenMap.get(v) : v
815
+ };
816
+ }.bind(this));
817
+ }.bind(this), [childrenMap, value]);
818
+ var handleClose = (0, _react.useCallback)(function (key) {
819
+ var _this15 = this;
820
+
821
+ (0, _newArrowCheck2.default)(this, _this13);
822
+ onChange === null || onChange === void 0 ? void 0 : onChange(value.filter(function (v) {
823
+ (0, _newArrowCheck2.default)(this, _this15);
824
+ return v !== key;
825
+ }.bind(this)));
826
+ }.bind(this), [onChange, value]);
827
+ var renderItem = (0, _react.useCallback)(function (item) {
828
+ (0, _newArrowCheck2.default)(this, _this13);
829
+ return /*#__PURE__*/_react.default.createElement(TagItem, {
830
+ key: item.key,
831
+ disabled: disabled,
832
+ onClose: handleClose,
833
+ item: item
834
+ });
835
+ }.bind(this), [disabled, handleClose]);
836
+ var handleInput = (0, _react.useCallback)(function (e) {
837
+ (0, _newArrowCheck2.default)(this, _this13);
838
+ setSearchValue(e.target.value);
839
+ }.bind(this), [setSearchValue]);
840
+ (0, _react.useEffect)(function () {
841
+ var _inputRef$current;
842
+
843
+ (0, _newArrowCheck2.default)(this, _this13);
844
+ if (visible) (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
845
+ }.bind(this), [visible]);
846
+ var handleClear = (0, _react.useCallback)(function (e) {
847
+ (0, _newArrowCheck2.default)(this, _this13);
848
+ e.stopPropagation();
849
+ e.preventDefault();
850
+
851
+ if (!disabled) {
852
+ var _inputRef$current2;
853
+
854
+ onChange === null || onChange === void 0 ? void 0 : onChange([]);
855
+ (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus();
856
+ }
857
+ }.bind(this), [disabled, onChange]);
858
+ var empty = (0, _react.useMemo)(function () {
859
+ (0, _newArrowCheck2.default)(this, _this13);
860
+ return !(value !== null && value !== void 0 && value.length);
861
+ }.bind(this), [value]);
862
+ var handleSelectorClick = (0, _react.useCallback)(function (e) {
863
+ var _inputRef$current3, _popupProps$onClick;
864
+
865
+ (0, _newArrowCheck2.default)(this, _this13);
866
+ (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 ? void 0 : _inputRef$current3.focus();
867
+ (_popupProps$onClick = _popupProps.onClick) === null || _popupProps$onClick === void 0 ? void 0 : _popupProps$onClick.call(_popupProps, e);
868
+ }.bind(this), [_popupProps]);
869
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_style2.SSelectorMultiple, (0, _extends2.default)({
870
+ focused: visible,
871
+ empty: empty
872
+ }, _popupProps, {
873
+ onClick: handleSelectorClick,
874
+ block: block,
875
+ size: size,
876
+ disabled: disabled
877
+ }), /*#__PURE__*/_react.default.createElement(_style.InputPart, {
878
+ stretch: true,
879
+ className: _style2.measureWrapCls
880
+ }, placeholder && empty && !searchValue && /*#__PURE__*/_react.default.createElement("div", {
881
+ className: _style2.placeholderCls
882
+ }, placeholder), !searchValue && !empty && /*#__PURE__*/_react.default.createElement("div", {
883
+ className: (0, _classnames.default)(_style2.placeholderCls, _style2.contentCls)
884
+ }, locale.selected, items.length, locale.items), search ? /*#__PURE__*/_react.default.createElement("input", {
885
+ value: searchValue,
886
+ ref: inputRef,
887
+ onChange: handleInput,
888
+ disabled: disabled
889
+ }) : null), /*#__PURE__*/_react.default.createElement(_style.Clear, {
890
+ clearable: clearable && !empty,
891
+ onClick: handleClear
892
+ }), /*#__PURE__*/_react.default.createElement(_style.InputPart, null, /*#__PURE__*/_react.default.createElement(_SvgIcon.default, {
893
+ type: visible ? search ? 'search' : 'arrow-up' : 'arrow-down'
894
+ }))), items.length ? /*#__PURE__*/_react.default.createElement("div", {
895
+ className: _style2.listCls
896
+ }, /*#__PURE__*/_react.default.createElement(_Tag.default.Group, null, items.map(renderItem))) : null);
897
+ });
898
+
899
+ var MultipleSelector = /*#__PURE__*/_react.default.memo(function MultipleSelector(props) {
900
+ var _this16 = this;
901
+
902
+ var size = props.size,
903
+ disabled = props.disabled,
904
+ visible = props.visible,
905
+ dataSource = props.dataSource,
906
+ value = props.value,
907
+ onChange = props.onChange,
908
+ placeholder = props.placeholder,
909
+ search = props.search,
910
+ _props$searchValue2 = props.searchValue,
911
+ searchValue = _props$searchValue2 === void 0 ? '' : _props$searchValue2,
912
+ setSearchValue = props.setSearchValue,
913
+ wrapRef = props.wrapRef,
914
+ clearable = props.clearable,
915
+ block = props.block,
916
+ _popupProps = props._popupProps;
917
+
918
+ var _dataSource3 = (0, _slicedToArray2.default)(dataSource, 5),
919
+ _dataSource3$ = _dataSource3[4],
920
+ childrenMap = _dataSource3$ === void 0 ? new Map() : _dataSource3$;
921
+
922
+ var inputRef = (0, _react.useRef)(null);
923
+ var items = (0, _react.useMemo)(function () {
924
+ var _this17 = this;
925
+
926
+ (0, _newArrowCheck2.default)(this, _this16);
927
+ return (value || []).map(function (v) {
928
+ (0, _newArrowCheck2.default)(this, _this17);
929
+ return {
930
+ key: v,
931
+ children: childrenMap.has(v) ? childrenMap.get(v) : v
932
+ };
933
+ }.bind(this));
934
+ }.bind(this), [childrenMap, value]);
935
+ var handleClose = (0, _react.useCallback)(function (key) {
936
+ var _this18 = this;
937
+
938
+ (0, _newArrowCheck2.default)(this, _this16);
939
+ onChange === null || onChange === void 0 ? void 0 : onChange(value.filter(function (v) {
940
+ (0, _newArrowCheck2.default)(this, _this18);
941
+ return v !== key;
942
+ }.bind(this)));
943
+ }.bind(this), [onChange, value]);
944
+ var popoverConfigProps = (0, _usePopoverConfig.default)();
945
+ var renderItem = (0, _react.useCallback)(function (item) {
946
+ (0, _newArrowCheck2.default)(this, _this16);
947
+ return /*#__PURE__*/_react.default.createElement(TagItem, {
948
+ key: item.key,
949
+ disabled: disabled,
950
+ onClose: handleClose,
951
+ item: item
952
+ });
953
+ }.bind(this), [disabled, handleClose]);
954
+ var getRestPopupContainer = (0, _react.useCallback)(function () {
955
+ (0, _newArrowCheck2.default)(this, _this16);
956
+ return wrapRef === null || wrapRef === void 0 ? void 0 : wrapRef.current;
957
+ }.bind(this), [wrapRef]);
958
+ var renderRest = (0, _react.useCallback)(function (items) {
959
+ (0, _newArrowCheck2.default)(this, _this16);
960
+ if (!items.length) return null;
961
+ return /*#__PURE__*/_react.default.createElement(_Tooltip.default, (0, _extends2.default)({
962
+ key: "rest",
963
+ popup: /*#__PURE__*/_react.default.createElement(RestList, {
964
+ onClose: handleClose,
965
+ disabled: disabled,
966
+ items: items
967
+ }),
968
+ arrow: false,
969
+ getPopupContainer: getRestPopupContainer,
970
+ customStyle: {
971
+ popupWrapperPadding: '0'
972
+ },
973
+ align: restAlign
974
+ }, popoverConfigProps), /*#__PURE__*/_react.default.createElement(_Tag.default, {
975
+ disabled: disabled
976
+ }, "+", items.length));
977
+ }.bind(this), [disabled, getRestPopupContainer, handleClose, popoverConfigProps]);
978
+ var handleInput = (0, _react.useCallback)(function (e) {
979
+ (0, _newArrowCheck2.default)(this, _this16);
980
+ setSearchValue(e.target.value);
981
+ }.bind(this), [setSearchValue]);
982
+ (0, _react.useEffect)(function () {
983
+ var _inputRef$current4;
984
+
985
+ (0, _newArrowCheck2.default)(this, _this16);
986
+ if (visible) (_inputRef$current4 = inputRef.current) === null || _inputRef$current4 === void 0 ? void 0 : _inputRef$current4.focus();
987
+ }.bind(this), [visible]);
988
+ var handleClear = (0, _react.useCallback)(function (e) {
989
+ (0, _newArrowCheck2.default)(this, _this16);
990
+ e.stopPropagation();
991
+ e.preventDefault();
992
+
993
+ if (!disabled) {
994
+ var _inputRef$current5;
995
+
996
+ onChange === null || onChange === void 0 ? void 0 : onChange([]);
997
+ (_inputRef$current5 = inputRef.current) === null || _inputRef$current5 === void 0 ? void 0 : _inputRef$current5.focus();
998
+ }
999
+ }.bind(this), [disabled, onChange]);
1000
+ var empty = (0, _react.useMemo)(function () {
1001
+ (0, _newArrowCheck2.default)(this, _this16);
1002
+ return !(value !== null && value !== void 0 && value.length);
1003
+ }.bind(this), [value]);
1004
+ var handleSelectorClick = (0, _react.useCallback)(function (e) {
1005
+ var _inputRef$current6, _popupProps$onClick2;
1006
+
1007
+ (0, _newArrowCheck2.default)(this, _this16);
1008
+ (_inputRef$current6 = inputRef.current) === null || _inputRef$current6 === void 0 ? void 0 : _inputRef$current6.focus();
1009
+ (_popupProps$onClick2 = _popupProps.onClick) === null || _popupProps$onClick2 === void 0 ? void 0 : _popupProps$onClick2.call(_popupProps, e);
1010
+ }.bind(this), [_popupProps]);
1011
+
1012
+ var _useState = (0, _react.useState)(0),
1013
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
1014
+ count = _useState2[0],
1015
+ setCount = _useState2[1];
1016
+
1017
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_style2.SSelectorMultiple, (0, _extends2.default)({
1018
+ focused: visible,
1019
+ empty: empty
1020
+ }, _popupProps, {
1021
+ onClick: handleSelectorClick,
1022
+ block: block,
1023
+ size: size,
1024
+ disabled: disabled
1025
+ }), /*#__PURE__*/_react.default.createElement(_style.InputPart, {
1026
+ stretch: true,
1027
+ className: _style2.measureWrapCls
1028
+ }, placeholder && empty && !searchValue && /*#__PURE__*/_react.default.createElement("div", {
1029
+ className: _style2.placeholderCls
1030
+ }, placeholder), items.length ? /*#__PURE__*/_react.default.createElement(_Overflow.Static, (0, _extends2.default)({
1031
+ items: items,
1032
+ renderItem: renderItem,
1033
+ renderRest: renderRest,
1034
+ static: true,
1035
+ count: count
1036
+ }, _popupProps)) : null, search ? /*#__PURE__*/_react.default.createElement("input", {
1037
+ value: searchValue,
1038
+ ref: inputRef,
1039
+ onChange: handleInput,
1040
+ disabled: disabled
1041
+ }) : null, /*#__PURE__*/_react.default.createElement("div", {
1042
+ className: _style2.measureCls
1043
+ }, items.length ? /*#__PURE__*/_react.default.createElement(_Overflow.default, {
1044
+ items: items,
1045
+ renderItem: renderItem,
1046
+ renderRest: renderRest,
1047
+ onMeasure: setCount,
1048
+ changeContent: searchValue
1049
+ }) : null, search ? /*#__PURE__*/_react.default.createElement("span", {
1050
+ className: _style2.measureContentCls
1051
+ }, searchValue) : null)), /*#__PURE__*/_react.default.createElement(_style.Clear, {
1052
+ clearable: clearable && !empty,
1053
+ onClick: handleClear
1054
+ }), /*#__PURE__*/_react.default.createElement(_style.InputPart, null, /*#__PURE__*/_react.default.createElement(_SvgIcon.default, {
1055
+ type: visible ? 'arrow-up' : 'arrow-down'
1056
+ }))));
1057
+ }); // 单选下的选择器
1058
+
1059
+
1060
+ var SingleSelector = /*#__PURE__*/_react.default.memo(function SingleSelector(_ref18) {
1061
+ var _this19 = this;
1062
+
1063
+ var size = _ref18.size,
1064
+ disabled = _ref18.disabled,
1065
+ placeholder = _ref18.placeholder,
1066
+ renderContent = _ref18.renderContent,
1067
+ renderPopup = _ref18.renderPopup,
1068
+ value = _ref18.value,
1069
+ onChange = _ref18.onChange,
1070
+ visible = _ref18.visible,
1071
+ dataSource = _ref18.dataSource,
1072
+ search = _ref18.search,
1073
+ _ref18$searchValue = _ref18.searchValue,
1074
+ searchValue = _ref18$searchValue === void 0 ? '' : _ref18$searchValue,
1075
+ setSearchValue = _ref18.setSearchValue,
1076
+ clearable = _ref18.clearable,
1077
+ _popupProps = _ref18._popupProps;
1078
+ var inputRef = (0, _react.useRef)(null);
1079
+ var getContent = (0, _react.useCallback)(function () {
1080
+ var _this20 = this;
1081
+
1082
+ (0, _newArrowCheck2.default)(this, _this19);
1083
+
1084
+ var _dataSource4 = (0, _slicedToArray2.default)(dataSource, 5),
1085
+ _dataSource4$ = _dataSource4[4],
1086
+ childrenMap = _dataSource4$ === void 0 ? new Map() : _dataSource4$;
1087
+
1088
+ var getValueChild = function getValueChild(v) {
1089
+ (0, _newArrowCheck2.default)(this, _this20);
1090
+ return childrenMap.has(v) ? childrenMap.get(v) : v;
1091
+ }.bind(this);
1092
+
1093
+ var valueChild = getValueChild(value);
1094
+
1095
+ if (renderContent) {
1096
+ return renderContent(value, valueChild);
1097
+ }
1098
+
1099
+ return value === undefined ? undefined : valueChild;
1100
+ }.bind(this), [dataSource, renderContent, value]);
1101
+ var content = (0, _react.useMemo)(getContent, [getContent]); // 自定义渲染弹层时,开发者可能不传入 options 和 children,导致 content memo deps 不触发变更,故强制更新
1102
+
1103
+ if (renderPopup) content = getContent();
1104
+ var handleInput = (0, _react.useCallback)(function (e) {
1105
+ (0, _newArrowCheck2.default)(this, _this19);
1106
+ setSearchValue(e.target.value);
1107
+ }.bind(this), [setSearchValue]);
1108
+ var empty = value === undefined;
1109
+
1110
+ var sharedProps = _objectSpread({
1111
+ className: _style2.selectInputCls,
1112
+ size: size,
1113
+ disabled: disabled,
1114
+ block: true,
1115
+ cursor: search ? 'text' : 'pointer',
1116
+ focused: visible,
1117
+ empty: empty,
1118
+ search: search
1119
+ }, _popupProps);
1120
+
1121
+ (0, _react.useEffect)(function () {
1122
+ var _inputRef$current7;
1123
+
1124
+ (0, _newArrowCheck2.default)(this, _this19);
1125
+ if (visible) (_inputRef$current7 = inputRef.current) === null || _inputRef$current7 === void 0 ? void 0 : _inputRef$current7.focus();
1126
+ }.bind(this), [visible]);
1127
+ var handleClear = (0, _react.useCallback)(function (e) {
1128
+ (0, _newArrowCheck2.default)(this, _this19);
1129
+ e.preventDefault();
1130
+ e.stopPropagation();
1131
+
1132
+ if (!disabled) {
1133
+ var _inputRef$current8;
1134
+
1135
+ onChange === null || onChange === void 0 ? void 0 : onChange(undefined);
1136
+ (_inputRef$current8 = inputRef.current) === null || _inputRef$current8 === void 0 ? void 0 : _inputRef$current8.focus();
1137
+ }
1138
+ }.bind(this), [disabled, onChange]);
1139
+ return /*#__PURE__*/_react.default.createElement(_style2.SSelectorSingle, sharedProps, /*#__PURE__*/_react.default.createElement(_style.InputPart, {
1140
+ stretch: true,
1141
+ className: _style2.inputWrapCls
1142
+ }, content ? /*#__PURE__*/_react.default.createElement("span", {
1143
+ className: (0, _classnames.default)(_style2.placeholderCls, _style2.contentCls),
1144
+ style: {
1145
+ visibility: searchValue ? 'hidden' : 'visible'
1146
+ }
1147
+ }, content) : /*#__PURE__*/_react.default.createElement("span", {
1148
+ className: _style2.placeholderCls,
1149
+ style: {
1150
+ visibility: searchValue ? 'hidden' : 'visible'
1151
+ }
1152
+ }, placeholder), search && /*#__PURE__*/_react.default.createElement("input", {
1153
+ className: _style2.inputCls,
1154
+ value: searchValue,
1155
+ onChange: handleInput,
1156
+ disabled: disabled,
1157
+ ref: inputRef
1158
+ })), /*#__PURE__*/_react.default.createElement(_style.Clear, {
1159
+ clearable: clearable && !empty,
1160
+ onClick: handleClear
1161
+ }), /*#__PURE__*/_react.default.createElement(_style.InputPart, null, /*#__PURE__*/_react.default.createElement(_SvgIcon.default, {
1162
+ type: visible ? search ? 'search' : 'arrow-up' : 'arrow-down'
1163
+ })));
1164
+ });
1165
+
1166
+ var Select = function Select(_ref19) {
405
1167
  var _search,
406
1168
  _search2,
407
1169
  _search3,
408
- _this7 = this;
409
-
410
- (0, _newArrowCheck2.default)(this, _this);
411
- var _ref8$size = _ref8.size,
412
- size = _ref8$size === void 0 ? 'md' : _ref8$size,
413
- _value = _ref8.value,
414
- defaultValue = _ref8.defaultValue,
415
- _onChange = _ref8.onChange,
416
- _ref8$onVisibleChange = _ref8.onVisibleChange,
417
- onVisibleChange = _ref8$onVisibleChange === void 0 ? _noop.default : _ref8$onVisibleChange,
418
- disabled = _ref8.disabled,
419
- search = _ref8.search,
420
- multiple = _ref8.multiple,
421
- renderContent = _ref8.renderContent,
422
- renderSelector = _ref8.renderSelector,
423
- placeholder = _ref8.placeholder,
424
- _locale = _ref8.locale,
425
- options = _ref8.options,
426
- children = _ref8.children,
427
- emptyContent = _ref8.emptyContent,
428
- showSelectAll = _ref8.showSelectAll,
429
- extra = _ref8.extra,
430
- customStyle = _ref8.customStyle,
431
- popover = _ref8.popover,
432
- popoverProps = _ref8.popoverProps,
433
- renderPopup = _ref8.renderPopup,
434
- virtualList = _ref8.virtualList,
435
- rest = (0, _objectWithoutProperties2.default)(_ref8, _excluded3);
1170
+ _this21 = this;
1171
+
1172
+ (0, _newArrowCheck2.default)(this, _this7);
1173
+ var _ref19$size = _ref19.size,
1174
+ size = _ref19$size === void 0 ? 'md' : _ref19$size,
1175
+ _value = _ref19.value,
1176
+ defaultValue = _ref19.defaultValue,
1177
+ _onChange = _ref19.onChange,
1178
+ _ref19$onVisibleChang = _ref19.onVisibleChange,
1179
+ onVisibleChange = _ref19$onVisibleChang === void 0 ? _noop.default : _ref19$onVisibleChang,
1180
+ disabled = _ref19.disabled,
1181
+ search = _ref19.search,
1182
+ multiple = _ref19.multiple,
1183
+ renderContent = _ref19.renderContent,
1184
+ renderSelector = _ref19.renderSelector,
1185
+ placeholder = _ref19.placeholder,
1186
+ _locale = _ref19.locale,
1187
+ options = _ref19.options,
1188
+ children = _ref19.children,
1189
+ emptyContent = _ref19.emptyContent,
1190
+ showSelectAll = _ref19.showSelectAll,
1191
+ extra = _ref19.extra,
1192
+ clearable = _ref19.clearable,
1193
+ customStyle = _ref19.customStyle,
1194
+ popover = _ref19.popover,
1195
+ popoverProps = _ref19.popoverProps,
1196
+ renderPopup = _ref19.renderPopup,
1197
+ virtualList = _ref19.virtualList,
1198
+ block = _ref19.block,
1199
+ styleType = _ref19.styleType,
1200
+ htmlProps = (0, _objectWithoutProperties2.default)(_ref19, _excluded6);
1201
+ if (multiple) clearable = true;
436
1202
 
437
1203
  var _useUncontrolled = (0, _useUncontrolled5.default)(_value, defaultValue, _onChange),
438
1204
  _useUncontrolled2 = (0, _slicedToArray2.default)(_useUncontrolled, 2),
439
1205
  value = _useUncontrolled2[0],
440
1206
  onChange = _useUncontrolled2[1];
441
1207
 
442
- var _useState = (0, _react.useState)(false),
443
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
444
- visible = _useState2[0],
445
- setVisible = _useState2[1];
1208
+ var _useState3 = (0, _react.useState)(false),
1209
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
1210
+ visible = _useState4[0],
1211
+ setVisible = _useState4[1];
446
1212
 
447
1213
  var locale = (0, _useLocale.default)(_zh_CN.default, 'Select', _locale);
1214
+ var wrapRef = (0, _react.useRef)(null);
448
1215
  if (search === true) search = {};
449
1216
 
450
1217
  var _useUncontrolled3 = (0, _useUncontrolled5.default)((_search = search) === null || _search === void 0 ? void 0 : _search.searchValue, ((_search2 = search) === null || _search2 === void 0 ? void 0 : _search2.defaultSearchValue) || '', (_search3 = search) === null || _search3 === void 0 ? void 0 : _search3.onSearchValueChange),
@@ -453,14 +1220,14 @@ var Select = function Select(_ref8) {
453
1220
  setSearchValue = _useUncontrolled4[1];
454
1221
 
455
1222
  (0, _useInitial.default)(function () {
456
- (0, _newArrowCheck2.default)(this, _this7);
1223
+ (0, _newArrowCheck2.default)(this, _this21);
457
1224
  if (popover) deprecatedLogForPopover();
458
1225
  if (virtualList && !options) warnLogForVirtualList();
459
1226
  }.bind(this));
460
1227
  var handleSearch = (0, _react.useCallback)(function (value, props) {
461
- var _this8 = this;
1228
+ var _this22 = this;
462
1229
 
463
- (0, _newArrowCheck2.default)(this, _this7);
1230
+ (0, _newArrowCheck2.default)(this, _this21);
464
1231
 
465
1232
  if (!search || !searchValue) {
466
1233
  return true;
@@ -479,7 +1246,7 @@ var Select = function Select(_ref8) {
479
1246
  if (!('props' in itemInfo)) {
480
1247
  Object.defineProperty(itemInfo, 'props', {
481
1248
  get: function get() {
482
- (0, _newArrowCheck2.default)(this, _this8);
1249
+ (0, _newArrowCheck2.default)(this, _this22);
483
1250
  warnLogForSearchProps();
484
1251
  return beforeProps;
485
1252
  }.bind(this)
@@ -488,88 +1255,143 @@ var Select = function Select(_ref8) {
488
1255
 
489
1256
  return search.handleSearch(searchValue, value, itemInfo);
490
1257
  } else {
1258
+ var _props$label;
1259
+
491
1260
  // use label for options case
492
- var _children = options ? props.label : props.children;
1261
+ var _children = options ? (_props$label = props.label) !== null && _props$label !== void 0 ? _props$label : props.value : props.children;
1262
+
1263
+ if (_children && typeof _children === 'string') {
1264
+ var i = _children.indexOf(searchValue);
1265
+
1266
+ if (i >= 0) {
1267
+ var l = searchValue.length;
1268
+ return [_children.substring(0, i), _children.substring(i, i + l), _children.substring(i + l)];
1269
+ }
1270
+ }
493
1271
 
494
- return (value + '').indexOf(searchValue) >= 0 || _children && typeof _children === 'string' && _children.indexOf(searchValue) >= 0;
1272
+ return (value + '').indexOf(searchValue) >= 0;
495
1273
  }
496
1274
  }.bind(this), [options, search, searchValue]);
497
1275
  var childrenDataSource = (0, _react.useMemo)(function () {
498
- (0, _newArrowCheck2.default)(this, _this7);
499
- return options ? [] : (0, _group3.groupChildrenAsDataSource)(children, disabled, groupOptions);
500
- }.bind(this), [children, disabled, options]);
1276
+ (0, _newArrowCheck2.default)(this, _this21);
1277
+ return options ? [] : groupChildrenAsDataSource(children, disabled, groupOptions, searchValue, handleSearch);
1278
+ }.bind(this), [children, disabled, handleSearch, options, searchValue]);
501
1279
  var optionsDataSource = (0, _react.useMemo)(function () {
502
- (0, _newArrowCheck2.default)(this, _this7);
1280
+ (0, _newArrowCheck2.default)(this, _this21);
503
1281
  return options ? groupOptionsAsDataSource(options, disabled, groupOptions, searchValue, handleSearch) : [];
504
1282
  }.bind(this), [disabled, handleSearch, options, searchValue]);
1283
+ var dataSource = (0, _react.useMemo)(function () {
1284
+ (0, _newArrowCheck2.default)(this, _this21);
1285
+
1286
+ if (options) {
1287
+ return optionsDataSource;
1288
+ }
1289
+
1290
+ return childrenDataSource;
1291
+ }.bind(this), [options, childrenDataSource, optionsDataSource]);
505
1292
  virtualList = (0, _react.useMemo)(function () {
506
- (0, _newArrowCheck2.default)(this, _this7);
1293
+ (0, _newArrowCheck2.default)(this, _this21);
507
1294
  return options ? virtualList : false;
508
1295
  }.bind(this), [options, virtualList]);
509
- var dataSource = (0, _react.useMemo)(function () {
510
- (0, _newArrowCheck2.default)(this, _this7);
511
- return options ? optionsDataSource : childrenDataSource;
512
- }.bind(this), [options, childrenDataSource, optionsDataSource]);
513
1296
  var handleVisibleChange = (0, _react.useCallback)(function (open) {
514
- (0, _newArrowCheck2.default)(this, _this7);
1297
+ (0, _newArrowCheck2.default)(this, _this21);
1298
+ if (disabled) return;
515
1299
  setVisible(open);
516
1300
  onVisibleChange(open);
517
- }.bind(this), [onVisibleChange]);
1301
+ if (!open) setSearchValue('');
1302
+ }.bind(this), [disabled, onVisibleChange, setSearchValue]);
518
1303
  var hidePopup = (0, _react.useCallback)(function () {
519
- (0, _newArrowCheck2.default)(this, _this7);
1304
+ (0, _newArrowCheck2.default)(this, _this21);
520
1305
  return handleVisibleChange(false);
521
1306
  }.bind(this), [handleVisibleChange]);
522
- return /*#__PURE__*/_react.default.createElement(_ConfigContext.default.Consumer, null, function (configContext) {
523
- (0, _newArrowCheck2.default)(this, _this7);
524
- var popupConfigProps = (0, _usePopoverConfig.getPopoverConfigFromContext)(configContext);
525
- return /*#__PURE__*/_react.default.createElement(_SelectContext.default.Provider, {
526
- value: {
527
- hidePopup: hidePopup,
528
- handleSearch: handleSearch,
529
- searchValue: searchValue
530
- }
531
- }, /*#__PURE__*/_react.default.createElement(_style.SelectWrap, rest, /*#__PURE__*/_react.default.createElement(_Popover.default, (0, _extends2.default)({
532
- onVisibleChange: handleVisibleChange,
533
- placement: "bottomLeft",
1307
+ var hasSubGroup = (0, _react.useMemo)(function () {
1308
+ (0, _newArrowCheck2.default)(this, _this21);
1309
+ var hasSubGroup = dataSource[3].size > 0;
1310
+ warnLogForSubGroup();
1311
+ return hasSubGroup;
1312
+ }.bind(this), [dataSource]); // 多层数据/搜索且自定义 selector/自定义渲染内容时,无法兼容,回滚到老版本
1313
+
1314
+ var _useState5 = (0, _react.useState)(function () {
1315
+ (0, _newArrowCheck2.default)(this, _this21);
1316
+ return hasSubGroup || !!(search && (renderContent || renderSelector));
1317
+ }.bind(this)),
1318
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 1),
1319
+ v1 = _useState6[0];
1320
+
1321
+ var popup = /*#__PURE__*/_react.default.createElement(Popup, {
1322
+ v1: v1,
1323
+ extra: extra,
1324
+ customStyle: customStyle,
1325
+ search: search,
1326
+ multiple: multiple,
1327
+ emptyContent: emptyContent,
1328
+ showSelectAll: showSelectAll,
1329
+ value: value,
1330
+ renderPopup: renderPopup,
1331
+ handleVisibleChange: handleVisibleChange,
1332
+ options: options,
1333
+ onChange: onChange,
1334
+ locale: locale,
1335
+ hidePopup: hidePopup,
1336
+ dataSource: dataSource,
1337
+ searchValue: searchValue,
1338
+ setSearchValue: setSearchValue,
1339
+ virtualList: virtualList
1340
+ }, children);
1341
+
1342
+ var selector = /*#__PURE__*/_react.default.createElement(Selector, {
1343
+ v1: v1,
1344
+ size: size,
1345
+ disabled: disabled,
1346
+ multiple: multiple,
1347
+ placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : locale.placeholder,
1348
+ renderContent: renderContent,
1349
+ renderSelector: renderSelector,
1350
+ renderPopup: renderPopup,
1351
+ value: value,
1352
+ onChange: onChange,
1353
+ visible: visible,
1354
+ locale: locale,
1355
+ dataSource: dataSource,
1356
+ clearable: clearable,
1357
+ search: search,
1358
+ searchValue: searchValue,
1359
+ setSearchValue: setSearchValue,
1360
+ styleType: styleType,
1361
+ wrapRef: wrapRef,
1362
+ block: block
1363
+ });
1364
+
1365
+ var popoverTriggerAttrs = (0, _react.useMemo)(function () {
1366
+ (0, _newArrowCheck2.default)(this, _this21);
1367
+ return v1 ? {
534
1368
  trigger: ['click']
535
- }, popupConfigProps, {
536
- visible: visible
537
- }, popover, popoverProps, {
538
- popup: /*#__PURE__*/_react.default.createElement(Popup, {
539
- extra: extra,
540
- customStyle: customStyle,
541
- search: search,
542
- multiple: multiple,
543
- emptyContent: emptyContent,
544
- showSelectAll: showSelectAll,
545
- value: value,
546
- renderPopup: renderPopup,
547
- options: options,
548
- children: children,
549
- onChange: onChange,
550
- locale: locale,
551
- handleVisibleChange: handleVisibleChange,
552
- hidePopup: hidePopup,
553
- dataSource: dataSource,
554
- searchValue: searchValue,
555
- setSearchValue: setSearchValue,
556
- virtualList: virtualList
557
- }),
558
- forceRender: false
559
- }), /*#__PURE__*/_react.default.createElement(Selector, {
560
- size: size,
561
- disabled: disabled,
562
- multiple: multiple,
563
- placeholder: placeholder,
564
- renderContent: renderContent,
565
- renderSelector: renderSelector,
566
- renderPopup: renderPopup,
567
- value: value,
568
- visible: visible,
569
- locale: locale,
570
- dataSource: dataSource
571
- }))));
572
- }.bind(this));
1369
+ } : {
1370
+ trigger: [],
1371
+ showAction: ['click', 'contextMenu', 'focus']
1372
+ };
1373
+ }.bind(this), [v1]);
1374
+ var popoverConfigProps = (0, _usePopoverConfig.default)();
1375
+ return /*#__PURE__*/_react.default.createElement(_SelectContext.default.Provider, {
1376
+ value: {
1377
+ hidePopup: hidePopup,
1378
+ handleSearch: handleSearch,
1379
+ searchValue: searchValue
1380
+ }
1381
+ }, /*#__PURE__*/_react.default.createElement(_style2.SelectWrap, (0, _extends2.default)({
1382
+ ref: wrapRef,
1383
+ disabled: disabled,
1384
+ multiple: multiple,
1385
+ block: block
1386
+ }, htmlProps), /*#__PURE__*/_react.default.createElement(_Popover.default, (0, _extends2.default)({
1387
+ visible: visible,
1388
+ onVisibleChange: handleVisibleChange,
1389
+ placement: "bottomLeft",
1390
+ stretch: block ? blockPopoverStretch : popoverStretch
1391
+ }, popoverTriggerAttrs, popoverConfigProps, popover, popoverProps, {
1392
+ popup: popup,
1393
+ forceRender: false
1394
+ }), selector)));
573
1395
  }.bind(void 0);
574
1396
 
575
1397
  Select.propTypes = {
@@ -584,6 +1406,7 @@ Select.propTypes = {
584
1406
  multiple: _propTypes.default.bool,
585
1407
  showSelectAll: _propTypes.default.bool,
586
1408
  disabled: _propTypes.default.bool,
1409
+ styleType: _propTypes.default.oneOf(['list']),
587
1410
  renderContent: _propTypes.default.func,
588
1411
  renderSelector: _propTypes.default.func,
589
1412
  renderPopup: _propTypes.default.func,
@@ -593,6 +1416,8 @@ Select.propTypes = {
593
1416
  defaultSearchValue: _propTypes.default.string,
594
1417
  onSearchValueChange: _propTypes.default.func
595
1418
  })]),
1419
+ block: _propTypes.default.bool,
1420
+ clearable: _propTypes.default.bool,
596
1421
  popover: _propTypes.default.any,
597
1422
  popoverProps: _propTypes.default.any,
598
1423
  onVisibleChange: _propTypes.default.func,
@@ -608,5 +1433,7 @@ Select.propTypes = {
608
1433
  height: _propTypes.default.number
609
1434
  })])
610
1435
  };
611
- var _default = Select;
1436
+
1437
+ var _default = /*#__PURE__*/_react.default.memo(Select);
1438
+
612
1439
  exports.default = _default;