@ucloud-fe/react-components 1.4.5 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) 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/usePicker.js +17 -7
  6. package/lib/components/DatePicker/utils.d.ts +2 -1
  7. package/lib/components/DatePicker/utils.js +13 -1
  8. package/lib/components/Form/ControllerContext.d.ts +1 -1
  9. package/lib/components/Input/.recodo/interaction.js +2 -2
  10. package/lib/components/Input/Input.js +12 -60
  11. package/lib/components/Input/Search.js +1 -0
  12. package/lib/components/Input/style/index.d.ts +23 -8
  13. package/lib/components/Input/style/index.js +97 -17
  14. package/lib/components/Menu/Item.js +9 -2
  15. package/lib/components/Menu/Menu.d.ts +11 -3
  16. package/lib/components/Menu/Menu.js +23 -9
  17. package/lib/components/Menu/MenuContext.d.ts +1 -0
  18. package/lib/components/Menu/index.d.ts +2 -2
  19. package/lib/components/Menu/style/index.d.ts +3 -0
  20. package/lib/components/Menu/style/index.js +14 -8
  21. package/lib/components/Notice/index.d.ts +1 -1
  22. package/lib/components/Select/Group.d.ts +3 -0
  23. package/lib/components/Select/Group.js +4 -0
  24. package/lib/components/Select/Overflow.d.ts +19 -0
  25. package/lib/components/Select/Overflow.js +155 -0
  26. package/lib/components/Select/Select.d.ts +15 -9
  27. package/lib/components/Select/Select.js +1150 -322
  28. package/lib/components/Select/SelectContext.d.ts +1 -1
  29. package/lib/components/Select/index.d.ts +3 -1
  30. package/lib/components/Select/locale/en_US.js +2 -1
  31. package/lib/components/Select/locale/zh_CN.d.ts +1 -0
  32. package/lib/components/Select/locale/zh_CN.js +2 -1
  33. package/lib/components/Select/style/index.d.ts +43 -6
  34. package/lib/components/Select/style/index.js +132 -46
  35. package/lib/components/SvgIcon/icons/ArrowDown.js +2 -2
  36. package/lib/components/SvgIcon/icons/ArrowLeft.js +3 -2
  37. package/lib/components/SvgIcon/icons/ArrowRight.js +2 -2
  38. package/lib/components/SvgIcon/icons/ArrowUp.js +2 -2
  39. package/lib/components/SvgIcon/icons/DoubleArrowLeft.js +4 -7
  40. package/lib/components/SvgIcon/icons/DoubleArrowRight.js +4 -6
  41. package/lib/components/SvgIcon/style/index.js +2 -2
  42. package/lib/hooks/group.d.ts +1 -1
  43. package/lib/hooks/group.js +5 -9
  44. package/lib/hooks/useUncontrolled.d.ts +1 -1
  45. package/lib/hooks/useUncontrolled.js +1 -1
  46. package/lib/libs/rc-table/Table.js +2 -3
  47. package/lib/sharedComponents/InputWrap.d.ts +16 -0
  48. package/lib/sharedComponents/InputWrap.js +66 -0
  49. package/lib/utils/pick.d.ts +1 -1
  50. 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,892 @@ 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
+ block: true,
430
+ onChange: handleSearchInput,
431
+ value: searchValue,
432
+ status: "default"
433
+ }), children || options !== null && options !== void 0 && options.length ? /*#__PURE__*/_react.default.createElement(_style2.BlockMenu, {
434
+ onChange: handleChange,
435
+ customStyle: newCustomStyle,
436
+ menuCustomStyle: {
437
+ maxWidth: 'none'
438
+ },
439
+ dataSource: dataSource,
440
+ multiple: multiple,
441
+ showSelectAll: showSelectAll,
442
+ selectedKeys: multiple ? value : [value],
443
+ virtualList: options ? virtualList : false
444
+ }) : /*#__PURE__*/_react.default.createElement(_style2.BlockMenu, {
445
+ customStyle: newCustomStyle,
446
+ menuCustomStyle: {
447
+ maxWidth: 'none'
448
+ }
449
+ }, emptyContent), finalExtra ? /*#__PURE__*/_react.default.createElement(_style2.FooterWrap, null, finalExtra) : null);
450
+ });
451
+
452
+ var PopupV2 = /*#__PURE__*/_react.default.memo(function PopupV2(_ref11) {
453
+ var _this6 = this,
454
+ _dataSource$;
455
+
456
+ var extra = _ref11.extra,
457
+ _ref11$customStyle = _ref11.customStyle,
458
+ customStyle = _ref11$customStyle === void 0 ? {} : _ref11$customStyle,
459
+ multiple = _ref11.multiple,
460
+ _emptyContent = _ref11.emptyContent,
461
+ showSelectAll = _ref11.showSelectAll,
462
+ value = _ref11.value,
463
+ options = _ref11.options,
464
+ children = _ref11.children,
465
+ onChange = _ref11.onChange,
466
+ locale = _ref11.locale,
467
+ handleVisibleChange = _ref11.handleVisibleChange,
468
+ hidePopup = _ref11.hidePopup,
469
+ dataSource = _ref11.dataSource,
470
+ virtualList = _ref11.virtualList,
471
+ searchValue = _ref11.searchValue;
472
+ var menuRef = (0, _react.useRef)(null);
473
+ var handleChange = (0, _react.useCallback)(function (value) {
474
+ (0, _newArrowCheck2.default)(this, _this6);
475
+
476
+ if (!multiple) {
477
+ handleVisibleChange(false);
478
+ onChange(value[0]);
479
+ } else {
480
+ onChange(value);
481
+ }
482
+ }.bind(this), [multiple, onChange, handleVisibleChange]);
483
+ var handleSelectAll = (0, _react.useCallback)(function () {
484
+ (0, _newArrowCheck2.default)(this, _this6);
485
+ var validKeys = dataSource[0];
486
+ var newValue = Array.from(new Set([].concat((0, _toConsumableArray2.default)(value || []), (0, _toConsumableArray2.default)(validKeys))));
487
+ onChange(newValue);
488
+ }.bind(this), [dataSource, onChange, value]);
489
+ var emptyContent = (0, _react.useMemo)(function () {
490
+ (0, _newArrowCheck2.default)(this, _this6);
491
+ return _emptyContent || /*#__PURE__*/_react.default.createElement(_style2.EmptyContentWrapper, null, locale.emptyTip);
492
+ }.bind(this), [_emptyContent, locale]);
493
+ var finalExtra = (0, _react.useMemo)(function () {
494
+ (0, _newArrowCheck2.default)(this, _this6);
495
+
496
+ if (typeof extra === 'function') {
497
+ return /*#__PURE__*/_react.default.createElement(_Extra.default, null, extra(hidePopup));
498
+ } else if (!(0, _isEmpty.default)(extra)) {
499
+ if ( /*#__PURE__*/_react.default.isValidElement(extra)) {
500
+ return /*#__PURE__*/_react.default.createElement(_Extra.default, null, extra);
501
+ } else if ((0, _isObject.default)(extra)) {
502
+ var _ref12 = extra,
503
+ _content2 = _ref12.content,
504
+ rest = (0, _objectWithoutProperties2.default)(_ref12, _excluded3);
505
+ return /*#__PURE__*/_react.default.createElement(_Extra.default, rest, _content2);
506
+ }
507
+ }
508
+ }.bind(this), [extra, hidePopup]);
509
+ var maxWidth = customStyle.popupMaxWidth ? customStyle.popupMaxWidth : 'none';
510
+
511
+ var newCustomStyle = _objectSpread({}, customStyle);
512
+
513
+ if (virtualList) {
514
+ if ('optionListMaxHeight' in newCustomStyle) {
515
+ warnLogForCustomHeight();
516
+ }
517
+
518
+ newCustomStyle.optionListMaxHeight = 'none';
519
+ }
520
+
521
+ 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]);
522
+ return /*#__PURE__*/_react.default.createElement(_style2.MenuWrap, {
523
+ maxWidth: maxWidth
524
+ }, hasContent ? /*#__PURE__*/_react.default.createElement(_style2.BlockMenu, {
525
+ showSelectAll: showSelectAll && multiple && /*#__PURE__*/_react.default.createElement("div", {
526
+ className: _style2.selectAllBtnWrapCls,
527
+ key: "__select_select_all",
528
+ onClick: handleSelectAll
529
+ }, locale.selectAll, searchValue ? " (".concat(searchValue, ")") : ''),
530
+ onChange: handleChange,
531
+ customStyle: newCustomStyle,
532
+ menuCustomStyle: {
533
+ maxWidth: 'none'
534
+ },
535
+ dataSource: dataSource,
536
+ multiple: multiple,
537
+ selectedKeys: multiple ? value : [value],
538
+ virtualList: options ? virtualList : false,
539
+ ref: menuRef,
540
+ _selectStyle: multiple
541
+ }) : /*#__PURE__*/_react.default.createElement(_style2.BlockMenu, {
542
+ customStyle: newCustomStyle,
543
+ menuCustomStyle: {
544
+ maxWidth: 'none'
545
+ }
546
+ }, emptyContent), finalExtra ? /*#__PURE__*/_react.default.createElement(_style2.FooterWrap, null, finalExtra) : null);
547
+ });
548
+
549
+ var Selector = /*#__PURE__*/_react.default.memo(function Selector(_ref13) {
550
+ var v1 = _ref13.v1,
551
+ size = _ref13.size,
552
+ disabled = _ref13.disabled,
553
+ multiple = _ref13.multiple,
554
+ placeholder = _ref13.placeholder,
555
+ renderContent = _ref13.renderContent,
556
+ renderSelector = _ref13.renderSelector,
557
+ renderPopup = _ref13.renderPopup,
558
+ value = _ref13.value,
559
+ onChange = _ref13.onChange,
560
+ visible = _ref13.visible,
561
+ locale = _ref13.locale,
562
+ dataSource = _ref13.dataSource,
563
+ search = _ref13.search,
564
+ searchValue = _ref13.searchValue,
565
+ setSearchValue = _ref13.setSearchValue,
566
+ wrapRef = _ref13.wrapRef,
567
+ clearable = _ref13.clearable,
568
+ styleType = _ref13.styleType,
569
+ block = _ref13.block,
570
+ _popupProps = (0, _objectWithoutProperties2.default)(_ref13, _excluded4);
571
+
572
+ var props = {
573
+ size: size,
574
+ disabled: disabled,
575
+ multiple: multiple,
576
+ placeholder: placeholder,
577
+ renderContent: renderContent,
578
+ renderSelector: renderSelector,
579
+ renderPopup: renderPopup,
580
+ value: value,
581
+ onChange: onChange,
582
+ visible: visible,
583
+ locale: locale,
584
+ dataSource: dataSource,
585
+ search: search,
586
+ searchValue: searchValue,
587
+ setSearchValue: setSearchValue,
588
+ wrapRef: wrapRef,
589
+ clearable: clearable,
590
+ block: block,
591
+ _popupProps: _popupProps
592
+ };
593
+ var SelectorComponent = renderSelector ? CustomSelector : v1 ? SelectorV1 : multiple ? styleType === 'list' ? MultipleListSelector : MultipleSelector : SingleSelector;
594
+ return /*#__PURE__*/_react.default.createElement(SelectorComponent, props);
595
+ });
596
+
597
+ var useOldContent = function useOldContent(_ref14) {
598
+ var _this8 = this;
599
+
600
+ (0, _newArrowCheck2.default)(this, _this7);
601
+ var locale = _ref14.locale,
602
+ placeholder = _ref14.placeholder,
603
+ multiple = _ref14.multiple,
604
+ dataSource = _ref14.dataSource,
605
+ value = _ref14.value,
606
+ renderContent = _ref14.renderContent,
607
+ renderPopup = _ref14.renderPopup;
608
+ placeholder = (0, _react.useMemo)(function () {
609
+ (0, _newArrowCheck2.default)(this, _this8);
610
+ return placeholder || locale.placeholder;
611
+ }.bind(this), [locale.placeholder, placeholder]);
612
+ var defaultRenderContent = (0, _react.useCallback)(function (value, valueChild) {
613
+ (0, _newArrowCheck2.default)(this, _this8);
614
+
615
+ if (!multiple) {
616
+ if (value === undefined) {
617
+ return placeholder;
618
+ } else {
619
+ return valueChild;
620
+ }
621
+ } else {
622
+ if (value && value.length) {
623
+ return "".concat(locale.selected).concat(value.length).concat(locale.items);
624
+ } else {
625
+ return placeholder;
626
+ }
627
+ }
628
+ }.bind(this), [locale.items, locale.selected, multiple, placeholder]);
629
+ var getContent = (0, _react.useCallback)(function () {
630
+ var _this9 = this;
631
+
632
+ (0, _newArrowCheck2.default)(this, _this8);
633
+
634
+ var _dataSource = (0, _slicedToArray2.default)(dataSource, 5),
635
+ _dataSource$2 = _dataSource[4],
636
+ childrenMap = _dataSource$2 === void 0 ? new Map() : _dataSource$2;
637
+
638
+ var valueChild;
639
+
640
+ var getValueChild = function getValueChild(v) {
641
+ (0, _newArrowCheck2.default)(this, _this9);
642
+ return childrenMap.has(v) ? childrenMap.get(v) : v;
643
+ }.bind(this);
644
+
645
+ if (!multiple) {
646
+ valueChild = getValueChild(value);
647
+ } else {
648
+ var _value = value ? (0, _toConsumableArray2.default)(value) : []; // only get the top twenty item child for better performance
649
+
650
+
651
+ if (_value.length > 20) {
652
+ _value.length = 20;
653
+ }
654
+
655
+ valueChild = _value.map(getValueChild);
656
+ }
657
+
658
+ if (renderContent) {
659
+ return renderContent(value, valueChild);
660
+ } else {
661
+ return defaultRenderContent(value, valueChild);
662
+ }
663
+ }.bind(this), [dataSource, defaultRenderContent, multiple, renderContent, value]);
664
+ var content = (0, _react.useMemo)(getContent, [getContent]); // 自定义渲染弹层时,开发者可能不传入 options 和 children,导致 content memo deps 不触发变更,故强制更新
665
+
666
+ if (renderPopup) content = getContent();
667
+ return content;
668
+ }.bind(void 0);
669
+
670
+ var CustomSelector = /*#__PURE__*/_react.default.memo(function CustomSelector(props) {
671
+ var content = useOldContent(props); // eslint-disable-next-line react/prop-types
672
+
673
+ var renderSelector = props.renderSelector,
674
+ visible = props.visible,
675
+ _popupProps = props._popupProps;
676
+
677
+ var selector = (renderSelector === null || renderSelector === void 0 ? void 0 : renderSelector(content, visible)) || /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
678
+
679
+ return /*#__PURE__*/_react.default.isValidElement(selector) ? /*#__PURE__*/_react.default.cloneElement(selector, _popupProps) : null;
680
+ });
681
+
682
+ var SelectorV1 = /*#__PURE__*/_react.default.memo(function SelectorV1(props) {
683
+ var size = props.size,
684
+ disabled = props.disabled,
685
+ visible = props.visible,
686
+ _popupProps = props._popupProps;
687
+ var content = useOldContent(props);
688
+ var title = typeof content === 'string' ? content : undefined;
689
+ return /*#__PURE__*/_react.default.createElement(_style2.SSelector, (0, _extends2.default)({
690
+ styleType: "border",
691
+ size: size,
692
+ disabled: disabled,
693
+ title: title
694
+ }, _popupProps), /*#__PURE__*/_react.default.createElement("div", {
695
+ className: _style2.selectorContentCls,
696
+ key: "content"
697
+ }, content), /*#__PURE__*/_react.default.createElement(_style2.Arrow, {
698
+ key: "icon",
699
+ type: visible ? 'arrow-up' : 'arrow-down'
700
+ }));
701
+ });
702
+
703
+ var RestListItem = /*#__PURE__*/_react.default.memo(function RestListItem(_ref15) {
704
+ var _this10 = this;
705
+
706
+ var item = _ref15.item,
707
+ disabled = _ref15.disabled,
708
+ onClose = _ref15.onClose;
709
+ var handleClose = (0, _react.useCallback)(function () {
710
+ (0, _newArrowCheck2.default)(this, _this10);
711
+ onClose(item.key);
712
+ }.bind(this), [item.key, onClose]);
713
+ return /*#__PURE__*/_react.default.createElement("div", {
714
+ key: item.key,
715
+ className: _style2.restItemCls
716
+ }, /*#__PURE__*/_react.default.createElement("span", {
717
+ "data-role": "label"
718
+ }, item.children), !disabled && /*#__PURE__*/_react.default.createElement("span", {
719
+ "data-role": "close",
720
+ onClick: handleClose
721
+ }, /*#__PURE__*/_react.default.createElement(_SvgIcon.default, {
722
+ type: "cross"
723
+ })));
724
+ });
725
+
726
+ var RestList = /*#__PURE__*/_react.default.memo(function RestList(_ref16) {
727
+ var _this11 = this;
728
+
729
+ var items = _ref16.items,
730
+ onClose = _ref16.onClose,
731
+ disabled = _ref16.disabled,
732
+ rest = (0, _objectWithoutProperties2.default)(_ref16, _excluded5);
733
+ var prevent = (0, _react.useCallback)(function (e) {
734
+ (0, _newArrowCheck2.default)(this, _this11);
735
+ e.preventDefault();
736
+ e.stopPropagation();
737
+ }.bind(this), []);
738
+ return /*#__PURE__*/_react.default.createElement(_style2.SRestList, (0, _extends2.default)({}, rest, {
739
+ onClick: prevent,
740
+ onContextMenu: prevent
741
+ }), /*#__PURE__*/_react.default.createElement(_VirtualScrollList.default, {
742
+ width: 160,
743
+ height: 180
744
+ }, items.map(function (item) {
745
+ (0, _newArrowCheck2.default)(this, _this11);
746
+ return /*#__PURE__*/_react.default.createElement(RestListItem, {
747
+ item: item,
748
+ key: item.key,
749
+ onClose: onClose,
750
+ disabled: disabled
751
+ });
752
+ }.bind(this))));
753
+ });
754
+
755
+ var TagItem = /*#__PURE__*/_react.default.memo(function TagItem(_ref17) {
756
+ var _this12 = this;
757
+
758
+ var item = _ref17.item,
759
+ disabled = _ref17.disabled,
760
+ onClose = _ref17.onClose;
761
+ var handleClose = (0, _react.useCallback)(function () {
762
+ (0, _newArrowCheck2.default)(this, _this12);
763
+ onClose(item.key);
764
+ }.bind(this), [item.key, onClose]);
765
+ return /*#__PURE__*/_react.default.createElement(_Tag.default, {
766
+ key: item.key,
767
+ closable: true,
768
+ disabled: disabled,
769
+ onClose: handleClose
770
+ }, item.children);
771
+ });
772
+
773
+ var restAlign = {
774
+ points: ['tl', 'br'],
775
+ overflow: {
776
+ adjustX: 1,
777
+ adjustY: 1
778
+ },
779
+ offset: [10, 10],
780
+ targetOffset: [0, 0]
781
+ };
782
+
783
+ var MultipleListSelector = /*#__PURE__*/_react.default.memo(function MultipleSelector(props) {
784
+ var _this13 = this;
785
+
786
+ var size = props.size,
787
+ disabled = props.disabled,
788
+ visible = props.visible,
789
+ dataSource = props.dataSource,
790
+ value = props.value,
791
+ onChange = props.onChange,
792
+ placeholder = props.placeholder,
793
+ search = props.search,
794
+ _props$searchValue = props.searchValue,
795
+ searchValue = _props$searchValue === void 0 ? '' : _props$searchValue,
796
+ setSearchValue = props.setSearchValue,
797
+ clearable = props.clearable,
798
+ locale = props.locale,
799
+ block = props.block,
800
+ _popupProps = props._popupProps;
801
+
802
+ var _dataSource2 = (0, _slicedToArray2.default)(dataSource, 5),
803
+ _dataSource2$ = _dataSource2[4],
804
+ childrenMap = _dataSource2$ === void 0 ? new Map() : _dataSource2$;
805
+
806
+ var inputRef = (0, _react.useRef)(null);
807
+ var items = (0, _react.useMemo)(function () {
808
+ var _this14 = this;
809
+
810
+ (0, _newArrowCheck2.default)(this, _this13);
811
+ return (value || []).map(function (v) {
812
+ (0, _newArrowCheck2.default)(this, _this14);
813
+ return {
814
+ key: v,
815
+ children: childrenMap.has(v) ? childrenMap.get(v) : v
816
+ };
817
+ }.bind(this));
818
+ }.bind(this), [childrenMap, value]);
819
+ var handleClose = (0, _react.useCallback)(function (key) {
820
+ var _this15 = this;
821
+
822
+ (0, _newArrowCheck2.default)(this, _this13);
823
+ onChange === null || onChange === void 0 ? void 0 : onChange(value.filter(function (v) {
824
+ (0, _newArrowCheck2.default)(this, _this15);
825
+ return v !== key;
826
+ }.bind(this)));
827
+ }.bind(this), [onChange, value]);
828
+ var renderItem = (0, _react.useCallback)(function (item) {
829
+ (0, _newArrowCheck2.default)(this, _this13);
830
+ return /*#__PURE__*/_react.default.createElement(TagItem, {
831
+ key: item.key,
832
+ disabled: disabled,
833
+ onClose: handleClose,
834
+ item: item
835
+ });
836
+ }.bind(this), [disabled, handleClose]);
837
+ var handleInput = (0, _react.useCallback)(function (e) {
838
+ (0, _newArrowCheck2.default)(this, _this13);
839
+ setSearchValue(e.target.value);
840
+ }.bind(this), [setSearchValue]);
841
+ (0, _react.useEffect)(function () {
842
+ var _inputRef$current;
843
+
844
+ (0, _newArrowCheck2.default)(this, _this13);
845
+ if (visible) (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
846
+ }.bind(this), [visible]);
847
+ var handleClear = (0, _react.useCallback)(function (e) {
848
+ (0, _newArrowCheck2.default)(this, _this13);
849
+ e.stopPropagation();
850
+ e.preventDefault();
851
+
852
+ if (!disabled) {
853
+ var _inputRef$current2;
854
+
855
+ onChange === null || onChange === void 0 ? void 0 : onChange([]);
856
+ (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus();
857
+ }
858
+ }.bind(this), [disabled, onChange]);
859
+ var empty = (0, _react.useMemo)(function () {
860
+ (0, _newArrowCheck2.default)(this, _this13);
861
+ return !(value !== null && value !== void 0 && value.length);
862
+ }.bind(this), [value]);
863
+ var handleSelectorClick = (0, _react.useCallback)(function (e) {
864
+ var _inputRef$current3, _popupProps$onClick;
865
+
866
+ (0, _newArrowCheck2.default)(this, _this13);
867
+ (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 ? void 0 : _inputRef$current3.focus();
868
+ (_popupProps$onClick = _popupProps.onClick) === null || _popupProps$onClick === void 0 ? void 0 : _popupProps$onClick.call(_popupProps, e);
869
+ }.bind(this), [_popupProps]);
870
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_style2.SSelectorMultiple, (0, _extends2.default)({
871
+ focused: visible,
872
+ empty: empty
873
+ }, _popupProps, {
874
+ onClick: handleSelectorClick,
875
+ block: block,
876
+ size: size,
877
+ disabled: disabled
878
+ }), /*#__PURE__*/_react.default.createElement(_style.InputPart, {
879
+ stretch: true,
880
+ className: _style2.measureWrapCls
881
+ }, placeholder && empty && !searchValue && /*#__PURE__*/_react.default.createElement("div", {
882
+ className: _style2.placeholderCls
883
+ }, placeholder), !searchValue && !empty && /*#__PURE__*/_react.default.createElement("div", {
884
+ className: (0, _classnames.default)(_style2.placeholderCls, _style2.contentCls)
885
+ }, locale.selected, items.length, locale.items), search ? /*#__PURE__*/_react.default.createElement("input", {
886
+ value: searchValue,
887
+ ref: inputRef,
888
+ onChange: handleInput,
889
+ disabled: disabled
890
+ }) : null), /*#__PURE__*/_react.default.createElement(_style.Clear, {
891
+ clearable: clearable && !empty,
892
+ onClick: handleClear
893
+ }), /*#__PURE__*/_react.default.createElement(_style.InputPart, null, /*#__PURE__*/_react.default.createElement(_SvgIcon.default, {
894
+ type: visible ? search ? 'search' : 'arrow-up' : 'arrow-down'
895
+ }))), items.length ? /*#__PURE__*/_react.default.createElement("div", {
896
+ className: _style2.listCls
897
+ }, /*#__PURE__*/_react.default.createElement(_Tag.default.Group, null, items.map(renderItem))) : null);
898
+ });
899
+
900
+ var MultipleSelector = /*#__PURE__*/_react.default.memo(function MultipleSelector(props) {
901
+ var _this16 = this;
902
+
903
+ var size = props.size,
904
+ disabled = props.disabled,
905
+ visible = props.visible,
906
+ dataSource = props.dataSource,
907
+ value = props.value,
908
+ onChange = props.onChange,
909
+ placeholder = props.placeholder,
910
+ search = props.search,
911
+ _props$searchValue2 = props.searchValue,
912
+ searchValue = _props$searchValue2 === void 0 ? '' : _props$searchValue2,
913
+ setSearchValue = props.setSearchValue,
914
+ wrapRef = props.wrapRef,
915
+ clearable = props.clearable,
916
+ block = props.block,
917
+ _popupProps = props._popupProps;
918
+
919
+ var _dataSource3 = (0, _slicedToArray2.default)(dataSource, 5),
920
+ _dataSource3$ = _dataSource3[4],
921
+ childrenMap = _dataSource3$ === void 0 ? new Map() : _dataSource3$;
922
+
923
+ var inputRef = (0, _react.useRef)(null);
924
+ var items = (0, _react.useMemo)(function () {
925
+ var _this17 = this;
926
+
927
+ (0, _newArrowCheck2.default)(this, _this16);
928
+ return (value || []).map(function (v) {
929
+ (0, _newArrowCheck2.default)(this, _this17);
930
+ return {
931
+ key: v,
932
+ children: childrenMap.has(v) ? childrenMap.get(v) : v
933
+ };
934
+ }.bind(this));
935
+ }.bind(this), [childrenMap, value]);
936
+ var handleClose = (0, _react.useCallback)(function (key) {
937
+ var _this18 = this;
938
+
939
+ (0, _newArrowCheck2.default)(this, _this16);
940
+ onChange === null || onChange === void 0 ? void 0 : onChange(value.filter(function (v) {
941
+ (0, _newArrowCheck2.default)(this, _this18);
942
+ return v !== key;
943
+ }.bind(this)));
944
+ }.bind(this), [onChange, value]);
945
+ var popoverConfigProps = (0, _usePopoverConfig.default)();
946
+ var renderItem = (0, _react.useCallback)(function (item) {
947
+ (0, _newArrowCheck2.default)(this, _this16);
948
+ return /*#__PURE__*/_react.default.createElement(TagItem, {
949
+ key: item.key,
950
+ disabled: disabled,
951
+ onClose: handleClose,
952
+ item: item
953
+ });
954
+ }.bind(this), [disabled, handleClose]);
955
+ var getRestPopupContainer = (0, _react.useCallback)(function () {
956
+ (0, _newArrowCheck2.default)(this, _this16);
957
+ return wrapRef === null || wrapRef === void 0 ? void 0 : wrapRef.current;
958
+ }.bind(this), [wrapRef]);
959
+ var renderRest = (0, _react.useCallback)(function (items) {
960
+ (0, _newArrowCheck2.default)(this, _this16);
961
+ if (!items.length) return null;
962
+ return /*#__PURE__*/_react.default.createElement(_Tooltip.default, (0, _extends2.default)({
963
+ key: "rest",
964
+ popup: /*#__PURE__*/_react.default.createElement(RestList, {
965
+ onClose: handleClose,
966
+ disabled: disabled,
967
+ items: items
968
+ }),
969
+ arrow: false,
970
+ getPopupContainer: getRestPopupContainer,
971
+ customStyle: {
972
+ popupWrapperPadding: '0'
973
+ },
974
+ align: restAlign
975
+ }, popoverConfigProps), /*#__PURE__*/_react.default.createElement(_Tag.default, {
976
+ disabled: disabled
977
+ }, "+", items.length));
978
+ }.bind(this), [disabled, getRestPopupContainer, handleClose, popoverConfigProps]);
979
+ var handleInput = (0, _react.useCallback)(function (e) {
980
+ (0, _newArrowCheck2.default)(this, _this16);
981
+ setSearchValue(e.target.value);
982
+ }.bind(this), [setSearchValue]);
983
+ (0, _react.useEffect)(function () {
984
+ var _inputRef$current4;
985
+
986
+ (0, _newArrowCheck2.default)(this, _this16);
987
+ if (visible) (_inputRef$current4 = inputRef.current) === null || _inputRef$current4 === void 0 ? void 0 : _inputRef$current4.focus();
988
+ }.bind(this), [visible]);
989
+ var handleClear = (0, _react.useCallback)(function (e) {
990
+ (0, _newArrowCheck2.default)(this, _this16);
991
+ e.stopPropagation();
992
+ e.preventDefault();
993
+
994
+ if (!disabled) {
995
+ var _inputRef$current5;
996
+
997
+ onChange === null || onChange === void 0 ? void 0 : onChange([]);
998
+ (_inputRef$current5 = inputRef.current) === null || _inputRef$current5 === void 0 ? void 0 : _inputRef$current5.focus();
999
+ }
1000
+ }.bind(this), [disabled, onChange]);
1001
+ var empty = (0, _react.useMemo)(function () {
1002
+ (0, _newArrowCheck2.default)(this, _this16);
1003
+ return !(value !== null && value !== void 0 && value.length);
1004
+ }.bind(this), [value]);
1005
+ var handleSelectorClick = (0, _react.useCallback)(function (e) {
1006
+ var _inputRef$current6, _popupProps$onClick2;
1007
+
1008
+ (0, _newArrowCheck2.default)(this, _this16);
1009
+ (_inputRef$current6 = inputRef.current) === null || _inputRef$current6 === void 0 ? void 0 : _inputRef$current6.focus();
1010
+ (_popupProps$onClick2 = _popupProps.onClick) === null || _popupProps$onClick2 === void 0 ? void 0 : _popupProps$onClick2.call(_popupProps, e);
1011
+ }.bind(this), [_popupProps]);
1012
+
1013
+ var _useState = (0, _react.useState)(0),
1014
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
1015
+ count = _useState2[0],
1016
+ setCount = _useState2[1];
1017
+
1018
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_style2.SSelectorMultiple, (0, _extends2.default)({
1019
+ focused: visible,
1020
+ empty: empty
1021
+ }, _popupProps, {
1022
+ onClick: handleSelectorClick,
1023
+ block: block,
1024
+ size: size,
1025
+ disabled: disabled
1026
+ }), /*#__PURE__*/_react.default.createElement(_style.InputPart, {
1027
+ stretch: true,
1028
+ className: _style2.measureWrapCls
1029
+ }, placeholder && empty && !searchValue && /*#__PURE__*/_react.default.createElement("div", {
1030
+ className: _style2.placeholderCls
1031
+ }, placeholder), items.length ? /*#__PURE__*/_react.default.createElement(_Overflow.Static, (0, _extends2.default)({
1032
+ items: items,
1033
+ renderItem: renderItem,
1034
+ renderRest: renderRest,
1035
+ static: true,
1036
+ count: count
1037
+ }, _popupProps)) : null, search ? /*#__PURE__*/_react.default.createElement("input", {
1038
+ value: searchValue,
1039
+ ref: inputRef,
1040
+ onChange: handleInput,
1041
+ disabled: disabled
1042
+ }) : null, /*#__PURE__*/_react.default.createElement("div", {
1043
+ className: _style2.measureCls
1044
+ }, items.length ? /*#__PURE__*/_react.default.createElement(_Overflow.default, {
1045
+ items: items,
1046
+ renderItem: renderItem,
1047
+ renderRest: renderRest,
1048
+ onMeasure: setCount,
1049
+ changeContent: searchValue
1050
+ }) : null, search ? /*#__PURE__*/_react.default.createElement("span", {
1051
+ className: _style2.measureContentCls
1052
+ }, searchValue) : null)), /*#__PURE__*/_react.default.createElement(_style.Clear, {
1053
+ clearable: clearable && !empty,
1054
+ onClick: handleClear
1055
+ }), /*#__PURE__*/_react.default.createElement(_style.InputPart, null, /*#__PURE__*/_react.default.createElement(_SvgIcon.default, {
1056
+ type: visible ? 'arrow-up' : 'arrow-down'
1057
+ }))));
1058
+ }); // 单选下的选择器
1059
+
1060
+
1061
+ var SingleSelector = /*#__PURE__*/_react.default.memo(function SingleSelector(_ref18) {
1062
+ var _this19 = this;
1063
+
1064
+ var size = _ref18.size,
1065
+ disabled = _ref18.disabled,
1066
+ placeholder = _ref18.placeholder,
1067
+ renderContent = _ref18.renderContent,
1068
+ renderPopup = _ref18.renderPopup,
1069
+ value = _ref18.value,
1070
+ onChange = _ref18.onChange,
1071
+ visible = _ref18.visible,
1072
+ dataSource = _ref18.dataSource,
1073
+ search = _ref18.search,
1074
+ _ref18$searchValue = _ref18.searchValue,
1075
+ searchValue = _ref18$searchValue === void 0 ? '' : _ref18$searchValue,
1076
+ setSearchValue = _ref18.setSearchValue,
1077
+ clearable = _ref18.clearable,
1078
+ _popupProps = _ref18._popupProps;
1079
+ var inputRef = (0, _react.useRef)(null);
1080
+ var getContent = (0, _react.useCallback)(function () {
1081
+ var _this20 = this;
1082
+
1083
+ (0, _newArrowCheck2.default)(this, _this19);
1084
+
1085
+ var _dataSource4 = (0, _slicedToArray2.default)(dataSource, 5),
1086
+ _dataSource4$ = _dataSource4[4],
1087
+ childrenMap = _dataSource4$ === void 0 ? new Map() : _dataSource4$;
1088
+
1089
+ var getValueChild = function getValueChild(v) {
1090
+ (0, _newArrowCheck2.default)(this, _this20);
1091
+ return childrenMap.has(v) ? childrenMap.get(v) : v;
1092
+ }.bind(this);
1093
+
1094
+ var valueChild = getValueChild(value);
1095
+
1096
+ if (renderContent) {
1097
+ return renderContent(value, valueChild);
1098
+ }
1099
+
1100
+ return value === undefined ? undefined : valueChild;
1101
+ }.bind(this), [dataSource, renderContent, value]);
1102
+ var content = (0, _react.useMemo)(getContent, [getContent]); // 自定义渲染弹层时,开发者可能不传入 options 和 children,导致 content memo deps 不触发变更,故强制更新
1103
+
1104
+ if (renderPopup) content = getContent();
1105
+ var handleInput = (0, _react.useCallback)(function (e) {
1106
+ (0, _newArrowCheck2.default)(this, _this19);
1107
+ setSearchValue(e.target.value);
1108
+ }.bind(this), [setSearchValue]);
1109
+ var empty = value === undefined;
1110
+
1111
+ var sharedProps = _objectSpread({
1112
+ className: _style2.selectInputCls,
1113
+ size: size,
1114
+ disabled: disabled,
1115
+ block: true,
1116
+ cursor: search ? 'text' : 'pointer',
1117
+ focused: visible,
1118
+ empty: empty,
1119
+ search: search
1120
+ }, _popupProps);
1121
+
1122
+ (0, _react.useEffect)(function () {
1123
+ var _inputRef$current7;
1124
+
1125
+ (0, _newArrowCheck2.default)(this, _this19);
1126
+ if (visible) (_inputRef$current7 = inputRef.current) === null || _inputRef$current7 === void 0 ? void 0 : _inputRef$current7.focus();
1127
+ }.bind(this), [visible]);
1128
+ var handleClear = (0, _react.useCallback)(function (e) {
1129
+ (0, _newArrowCheck2.default)(this, _this19);
1130
+ e.preventDefault();
1131
+ e.stopPropagation();
1132
+
1133
+ if (!disabled) {
1134
+ var _inputRef$current8;
1135
+
1136
+ onChange === null || onChange === void 0 ? void 0 : onChange(undefined);
1137
+ (_inputRef$current8 = inputRef.current) === null || _inputRef$current8 === void 0 ? void 0 : _inputRef$current8.focus();
1138
+ }
1139
+ }.bind(this), [disabled, onChange]);
1140
+ return /*#__PURE__*/_react.default.createElement(_style2.SSelectorSingle, sharedProps, /*#__PURE__*/_react.default.createElement(_style.InputPart, {
1141
+ stretch: true,
1142
+ className: _style2.inputWrapCls
1143
+ }, content ? /*#__PURE__*/_react.default.createElement("span", {
1144
+ className: (0, _classnames.default)(_style2.placeholderCls, _style2.contentCls),
1145
+ style: {
1146
+ visibility: searchValue ? 'hidden' : 'visible'
1147
+ }
1148
+ }, content) : /*#__PURE__*/_react.default.createElement("span", {
1149
+ className: _style2.placeholderCls,
1150
+ style: {
1151
+ visibility: searchValue ? 'hidden' : 'visible'
1152
+ }
1153
+ }, placeholder), search && /*#__PURE__*/_react.default.createElement("input", {
1154
+ className: _style2.inputCls,
1155
+ value: searchValue,
1156
+ onChange: handleInput,
1157
+ disabled: disabled,
1158
+ ref: inputRef
1159
+ })), /*#__PURE__*/_react.default.createElement(_style.Clear, {
1160
+ clearable: clearable && !empty,
1161
+ onClick: handleClear
1162
+ }), /*#__PURE__*/_react.default.createElement(_style.InputPart, null, /*#__PURE__*/_react.default.createElement(_SvgIcon.default, {
1163
+ type: visible ? search ? 'search' : 'arrow-up' : 'arrow-down'
1164
+ })));
1165
+ });
1166
+
1167
+ var Select = function Select(_ref19) {
405
1168
  var _search,
406
1169
  _search2,
407
1170
  _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);
1171
+ _this21 = this;
1172
+
1173
+ (0, _newArrowCheck2.default)(this, _this7);
1174
+ var _ref19$size = _ref19.size,
1175
+ size = _ref19$size === void 0 ? 'md' : _ref19$size,
1176
+ _value = _ref19.value,
1177
+ defaultValue = _ref19.defaultValue,
1178
+ _onChange = _ref19.onChange,
1179
+ _ref19$onVisibleChang = _ref19.onVisibleChange,
1180
+ onVisibleChange = _ref19$onVisibleChang === void 0 ? _noop.default : _ref19$onVisibleChang,
1181
+ disabled = _ref19.disabled,
1182
+ search = _ref19.search,
1183
+ multiple = _ref19.multiple,
1184
+ renderContent = _ref19.renderContent,
1185
+ renderSelector = _ref19.renderSelector,
1186
+ placeholder = _ref19.placeholder,
1187
+ _locale = _ref19.locale,
1188
+ options = _ref19.options,
1189
+ children = _ref19.children,
1190
+ emptyContent = _ref19.emptyContent,
1191
+ showSelectAll = _ref19.showSelectAll,
1192
+ extra = _ref19.extra,
1193
+ clearable = _ref19.clearable,
1194
+ customStyle = _ref19.customStyle,
1195
+ popover = _ref19.popover,
1196
+ popoverProps = _ref19.popoverProps,
1197
+ renderPopup = _ref19.renderPopup,
1198
+ virtualList = _ref19.virtualList,
1199
+ block = _ref19.block,
1200
+ styleType = _ref19.styleType,
1201
+ htmlProps = (0, _objectWithoutProperties2.default)(_ref19, _excluded6);
1202
+ if (multiple) clearable = true;
436
1203
 
437
1204
  var _useUncontrolled = (0, _useUncontrolled5.default)(_value, defaultValue, _onChange),
438
1205
  _useUncontrolled2 = (0, _slicedToArray2.default)(_useUncontrolled, 2),
439
1206
  value = _useUncontrolled2[0],
440
1207
  onChange = _useUncontrolled2[1];
441
1208
 
442
- var _useState = (0, _react.useState)(false),
443
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
444
- visible = _useState2[0],
445
- setVisible = _useState2[1];
1209
+ var _useState3 = (0, _react.useState)(false),
1210
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
1211
+ visible = _useState4[0],
1212
+ setVisible = _useState4[1];
446
1213
 
447
1214
  var locale = (0, _useLocale.default)(_zh_CN.default, 'Select', _locale);
1215
+ var wrapRef = (0, _react.useRef)(null);
448
1216
  if (search === true) search = {};
449
1217
 
450
1218
  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 +1221,14 @@ var Select = function Select(_ref8) {
453
1221
  setSearchValue = _useUncontrolled4[1];
454
1222
 
455
1223
  (0, _useInitial.default)(function () {
456
- (0, _newArrowCheck2.default)(this, _this7);
1224
+ (0, _newArrowCheck2.default)(this, _this21);
457
1225
  if (popover) deprecatedLogForPopover();
458
1226
  if (virtualList && !options) warnLogForVirtualList();
459
1227
  }.bind(this));
460
1228
  var handleSearch = (0, _react.useCallback)(function (value, props) {
461
- var _this8 = this;
1229
+ var _this22 = this;
462
1230
 
463
- (0, _newArrowCheck2.default)(this, _this7);
1231
+ (0, _newArrowCheck2.default)(this, _this21);
464
1232
 
465
1233
  if (!search || !searchValue) {
466
1234
  return true;
@@ -479,7 +1247,7 @@ var Select = function Select(_ref8) {
479
1247
  if (!('props' in itemInfo)) {
480
1248
  Object.defineProperty(itemInfo, 'props', {
481
1249
  get: function get() {
482
- (0, _newArrowCheck2.default)(this, _this8);
1250
+ (0, _newArrowCheck2.default)(this, _this22);
483
1251
  warnLogForSearchProps();
484
1252
  return beforeProps;
485
1253
  }.bind(this)
@@ -488,88 +1256,143 @@ var Select = function Select(_ref8) {
488
1256
 
489
1257
  return search.handleSearch(searchValue, value, itemInfo);
490
1258
  } else {
1259
+ var _props$label;
1260
+
491
1261
  // use label for options case
492
- var _children = options ? props.label : props.children;
1262
+ var _children = options ? (_props$label = props.label) !== null && _props$label !== void 0 ? _props$label : props.value : props.children;
1263
+
1264
+ if (_children && typeof _children === 'string') {
1265
+ var i = _children.indexOf(searchValue);
1266
+
1267
+ if (i >= 0) {
1268
+ var l = searchValue.length;
1269
+ return [_children.substring(0, i), _children.substring(i, i + l), _children.substring(i + l)];
1270
+ }
1271
+ }
493
1272
 
494
- return (value + '').indexOf(searchValue) >= 0 || _children && typeof _children === 'string' && _children.indexOf(searchValue) >= 0;
1273
+ return (value + '').indexOf(searchValue) >= 0;
495
1274
  }
496
1275
  }.bind(this), [options, search, searchValue]);
497
1276
  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]);
1277
+ (0, _newArrowCheck2.default)(this, _this21);
1278
+ return options ? [] : groupChildrenAsDataSource(children, disabled, groupOptions, searchValue, handleSearch);
1279
+ }.bind(this), [children, disabled, handleSearch, options, searchValue]);
501
1280
  var optionsDataSource = (0, _react.useMemo)(function () {
502
- (0, _newArrowCheck2.default)(this, _this7);
1281
+ (0, _newArrowCheck2.default)(this, _this21);
503
1282
  return options ? groupOptionsAsDataSource(options, disabled, groupOptions, searchValue, handleSearch) : [];
504
1283
  }.bind(this), [disabled, handleSearch, options, searchValue]);
1284
+ var dataSource = (0, _react.useMemo)(function () {
1285
+ (0, _newArrowCheck2.default)(this, _this21);
1286
+
1287
+ if (options) {
1288
+ return optionsDataSource;
1289
+ }
1290
+
1291
+ return childrenDataSource;
1292
+ }.bind(this), [options, childrenDataSource, optionsDataSource]);
505
1293
  virtualList = (0, _react.useMemo)(function () {
506
- (0, _newArrowCheck2.default)(this, _this7);
1294
+ (0, _newArrowCheck2.default)(this, _this21);
507
1295
  return options ? virtualList : false;
508
1296
  }.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
1297
  var handleVisibleChange = (0, _react.useCallback)(function (open) {
514
- (0, _newArrowCheck2.default)(this, _this7);
1298
+ (0, _newArrowCheck2.default)(this, _this21);
1299
+ if (disabled) return;
515
1300
  setVisible(open);
516
1301
  onVisibleChange(open);
517
- }.bind(this), [onVisibleChange]);
1302
+ if (!open) setSearchValue('');
1303
+ }.bind(this), [disabled, onVisibleChange, setSearchValue]);
518
1304
  var hidePopup = (0, _react.useCallback)(function () {
519
- (0, _newArrowCheck2.default)(this, _this7);
1305
+ (0, _newArrowCheck2.default)(this, _this21);
520
1306
  return handleVisibleChange(false);
521
1307
  }.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",
1308
+ var hasSubGroup = (0, _react.useMemo)(function () {
1309
+ (0, _newArrowCheck2.default)(this, _this21);
1310
+ var hasSubGroup = dataSource[3].size > 0;
1311
+ warnLogForSubGroup();
1312
+ return hasSubGroup;
1313
+ }.bind(this), [dataSource]); // 多层数据/搜索且自定义 selector/自定义渲染内容时,无法兼容,回滚到老版本
1314
+
1315
+ var _useState5 = (0, _react.useState)(function () {
1316
+ (0, _newArrowCheck2.default)(this, _this21);
1317
+ return hasSubGroup || !!(search && (renderContent || renderSelector));
1318
+ }.bind(this)),
1319
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 1),
1320
+ v1 = _useState6[0];
1321
+
1322
+ var popup = /*#__PURE__*/_react.default.createElement(Popup, {
1323
+ v1: v1,
1324
+ extra: extra,
1325
+ customStyle: customStyle,
1326
+ search: search,
1327
+ multiple: multiple,
1328
+ emptyContent: emptyContent,
1329
+ showSelectAll: showSelectAll,
1330
+ value: value,
1331
+ renderPopup: renderPopup,
1332
+ handleVisibleChange: handleVisibleChange,
1333
+ options: options,
1334
+ onChange: onChange,
1335
+ locale: locale,
1336
+ hidePopup: hidePopup,
1337
+ dataSource: dataSource,
1338
+ searchValue: searchValue,
1339
+ setSearchValue: setSearchValue,
1340
+ virtualList: virtualList
1341
+ }, children);
1342
+
1343
+ var selector = /*#__PURE__*/_react.default.createElement(Selector, {
1344
+ v1: v1,
1345
+ size: size,
1346
+ disabled: disabled,
1347
+ multiple: multiple,
1348
+ placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : locale.placeholder,
1349
+ renderContent: renderContent,
1350
+ renderSelector: renderSelector,
1351
+ renderPopup: renderPopup,
1352
+ value: value,
1353
+ onChange: onChange,
1354
+ visible: visible,
1355
+ locale: locale,
1356
+ dataSource: dataSource,
1357
+ clearable: clearable,
1358
+ search: search,
1359
+ searchValue: searchValue,
1360
+ setSearchValue: setSearchValue,
1361
+ styleType: styleType,
1362
+ wrapRef: wrapRef,
1363
+ block: block
1364
+ });
1365
+
1366
+ var popoverTriggerAttrs = (0, _react.useMemo)(function () {
1367
+ (0, _newArrowCheck2.default)(this, _this21);
1368
+ return v1 ? {
534
1369
  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));
1370
+ } : {
1371
+ trigger: [],
1372
+ showAction: ['click', 'contextMenu', 'focus']
1373
+ };
1374
+ }.bind(this), [v1]);
1375
+ var popoverConfigProps = (0, _usePopoverConfig.default)();
1376
+ return /*#__PURE__*/_react.default.createElement(_SelectContext.default.Provider, {
1377
+ value: {
1378
+ hidePopup: hidePopup,
1379
+ handleSearch: handleSearch,
1380
+ searchValue: searchValue
1381
+ }
1382
+ }, /*#__PURE__*/_react.default.createElement(_style2.SelectWrap, (0, _extends2.default)({
1383
+ ref: wrapRef,
1384
+ disabled: disabled,
1385
+ multiple: multiple,
1386
+ block: block
1387
+ }, htmlProps), /*#__PURE__*/_react.default.createElement(_Popover.default, (0, _extends2.default)({
1388
+ visible: visible,
1389
+ onVisibleChange: handleVisibleChange,
1390
+ placement: "bottomLeft",
1391
+ stretch: block ? blockPopoverStretch : popoverStretch
1392
+ }, popoverTriggerAttrs, popoverConfigProps, popover, popoverProps, {
1393
+ popup: popup,
1394
+ forceRender: false
1395
+ }), selector)));
573
1396
  }.bind(void 0);
574
1397
 
575
1398
  Select.propTypes = {
@@ -584,6 +1407,7 @@ Select.propTypes = {
584
1407
  multiple: _propTypes.default.bool,
585
1408
  showSelectAll: _propTypes.default.bool,
586
1409
  disabled: _propTypes.default.bool,
1410
+ styleType: _propTypes.default.oneOf(['list']),
587
1411
  renderContent: _propTypes.default.func,
588
1412
  renderSelector: _propTypes.default.func,
589
1413
  renderPopup: _propTypes.default.func,
@@ -593,6 +1417,8 @@ Select.propTypes = {
593
1417
  defaultSearchValue: _propTypes.default.string,
594
1418
  onSearchValueChange: _propTypes.default.func
595
1419
  })]),
1420
+ block: _propTypes.default.bool,
1421
+ clearable: _propTypes.default.bool,
596
1422
  popover: _propTypes.default.any,
597
1423
  popoverProps: _propTypes.default.any,
598
1424
  onVisibleChange: _propTypes.default.func,
@@ -608,5 +1434,7 @@ Select.propTypes = {
608
1434
  height: _propTypes.default.number
609
1435
  })])
610
1436
  };
611
- var _default = Select;
1437
+
1438
+ var _default = /*#__PURE__*/_react.default.memo(Select);
1439
+
612
1440
  exports.default = _default;