UNPKG

34.8 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4
5var _extends2 = require('babel-runtime/helpers/extends');
6
7var _extends3 = _interopRequireDefault(_extends2);
8
9var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
10
11var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
12
13var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
14
15var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
16
17var _inherits2 = require('babel-runtime/helpers/inherits');
18
19var _inherits3 = _interopRequireDefault(_inherits2);
20
21var _class, _temp;
22
23var _react = require('react');
24
25var _react2 = _interopRequireDefault(_react);
26
27var _propTypes = require('prop-types');
28
29var _propTypes2 = _interopRequireDefault(_propTypes);
30
31var _reactLifecyclesCompat = require('react-lifecycles-compat');
32
33var _classnames = require('classnames');
34
35var _classnames2 = _interopRequireDefault(_classnames);
36
37var _select = require('../select');
38
39var _select2 = _interopRequireDefault(_select);
40
41var _cascader = require('../cascader');
42
43var _cascader2 = _interopRequireDefault(_cascader);
44
45var _menu = require('../menu');
46
47var _menu2 = _interopRequireDefault(_menu);
48
49var _util = require('../util');
50
51function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
52
53var bindCtx = _util.func.bindCtx;
54var pickOthers = _util.obj.pickOthers;
55var getStyle = _util.dom.getStyle;
56
57
58var normalizeValue = function normalizeValue(value) {
59 if (value) {
60 if (Array.isArray(value)) {
61 return value;
62 }
63
64 return [value];
65 }
66
67 return [];
68};
69
70/**
71 * CascaderSelect
72 */
73var CascaderSelect = (_temp = _class = function (_Component) {
74 (0, _inherits3.default)(CascaderSelect, _Component);
75
76 function CascaderSelect(props) {
77 (0, _classCallCheck3.default)(this, CascaderSelect);
78
79 var _this = (0, _possibleConstructorReturn3.default)(this, _Component.call(this, props));
80
81 _this.refreshValueDataCache = function (curValue) {
82 if (curValue) {
83 var valueArr = Array.isArray(curValue) ? curValue : [curValue];
84
85 valueArr.length && Object.keys(_this._valueDataCache).forEach(function (v) {
86 if (!valueArr.includes(v)) {
87 delete _this._valueDataCache[v];
88 }
89 });
90 } else {
91 _this._valueDataCache = {};
92 }
93 };
94
95 _this.state = {
96 value: normalizeValue('value' in props ? props.value : props.defaultValue),
97 searchValue: '',
98 visible: typeof props.visible === 'undefined' ? props.defaultVisible : props.visible
99 };
100
101 // 缓存选中值数据
102 _this._valueDataCache = {};
103
104 bindCtx(_this, ['handleVisibleChange', 'handleAfterOpen', 'handleSelect', 'handleChange', 'handleClear', 'handleRemove', 'handleSearch', 'getPopup', 'saveSelectRef', 'saveCascaderRef', 'handleKeyDown']);
105 return _this;
106 }
107
108 CascaderSelect.getDerivedStateFromProps = function getDerivedStateFromProps(props) {
109 var st = {};
110
111 if ('value' in props) {
112 st.value = normalizeValue(props.value);
113 }
114 if ('visible' in props) {
115 st.visible = props.visible;
116 }
117
118 return st;
119 };
120
121 CascaderSelect.prototype.updateCache = function updateCache(dataSource) {
122 var _this2 = this;
123
124 this._v2n = {};
125 this._p2n = {};
126 var loop = function loop(data) {
127 var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
128 return data.forEach(function (item, index) {
129 var value = item.value,
130 children = item.children;
131
132 var pos = prefix + '-' + index;
133 _this2._v2n[value] = _this2._p2n[pos] = (0, _extends3.default)({}, item, { pos: pos });
134
135 if (children && children.length) {
136 loop(children, pos);
137 }
138 });
139 };
140
141 loop(dataSource);
142 };
143
144 CascaderSelect.prototype.flatValue = function flatValue(value) {
145 var _this3 = this;
146
147 var getDepth = function getDepth(v) {
148 var pos = _this3.getPos(v);
149 if (!pos) {
150 return 0;
151 }
152 return pos.split('-').length;
153 };
154 var newValue = value.slice(0).sort(function (prev, next) {
155 return getDepth(prev) - getDepth(next);
156 });
157
158 for (var i = 0; i < newValue.length; i++) {
159 for (var j = 0; j < newValue.length; j++) {
160 if (i !== j && this.isDescendantOrSelf(this.getPos(newValue[i]), this.getPos(newValue[j]))) {
161 newValue.splice(j, 1);
162 j--;
163 }
164 }
165 }
166
167 return newValue;
168 };
169
170 CascaderSelect.prototype.isDescendantOrSelf = function isDescendantOrSelf(currentPos, targetPos) {
171 if (!currentPos || !targetPos) {
172 return false;
173 }
174
175 var currentNums = currentPos.split('-');
176 var targetNums = targetPos.split('-');
177
178 return currentNums.length <= targetNums.length && currentNums.every(function (num, index) {
179 return num === targetNums[index];
180 });
181 };
182
183 CascaderSelect.prototype.getValue = function getValue(pos) {
184 return this._p2n[pos] ? this._p2n[pos].value : null;
185 };
186
187 CascaderSelect.prototype.getPos = function getPos(value) {
188 return this._v2n[value] ? this._v2n[value].pos : null;
189 };
190
191 CascaderSelect.prototype.getData = function getData(value) {
192 var _this4 = this;
193
194 return value.map(function (v) {
195 return _this4._v2n[v] || _this4._valueDataCache[v];
196 });
197 };
198
199 CascaderSelect.prototype.getLabelPath = function getLabelPath(data) {
200 var _this5 = this;
201
202 var nums = data.pos.split('-');
203 return nums.slice(1).reduce(function (ret, num, index) {
204 var p = nums.slice(0, index + 2).join('-');
205 ret.push(_this5._p2n[p].label);
206 return ret;
207 }, []);
208 };
209
210 CascaderSelect.prototype.getSingleData = function getSingleData(value) {
211 if (!value.length) {
212 return null;
213 }
214
215 if (Array.isArray(value)) value = value[0];
216
217 var data = this._v2n[value];
218
219 if (data) {
220 var labelPath = this.getLabelPath(data);
221 var displayRender = this.props.displayRender || function (labels) {
222 return labels.join(' / ');
223 };
224
225 data = (0, _extends3.default)({}, data, {
226 label: displayRender(labelPath, data)
227 });
228
229 this._valueDataCache[value] = data;
230 this.refreshValueDataCache(value);
231 } else {
232 data = this._valueDataCache[value];
233 }
234
235 return data || {
236 value: value
237 };
238 };
239
240 CascaderSelect.prototype.getMultipleData = function getMultipleData(value) {
241 var _this6 = this;
242
243 if (!value.length) {
244 return null;
245 }
246
247 var _props = this.props,
248 checkStrictly = _props.checkStrictly,
249 canOnlyCheckLeaf = _props.canOnlyCheckLeaf,
250 displayRender = _props.displayRender;
251
252 var flatValue = checkStrictly || canOnlyCheckLeaf ? value : this.flatValue(value);
253 var data = flatValue.map(function (v) {
254 var item = _this6._v2n[v];
255
256 if (item) {
257 _this6._valueDataCache[v] = item;
258 } else {
259 item = _this6._valueDataCache[v];
260 }
261
262 return item || { value: v };
263 });
264
265 if (displayRender) {
266 data = data.map(function (item) {
267 if (!item.pos || !(item.value in _this6._v2n)) {
268 return item;
269 }
270
271 var labelPath = _this6.getLabelPath(item);
272 var newItem = (0, _extends3.default)({}, item, {
273 label: displayRender(labelPath, item)
274 });
275
276 _this6._valueDataCache[item.value] = newItem;
277
278 return newItem;
279 });
280 }
281
282 return data;
283 };
284
285 CascaderSelect.prototype.getIndeterminate = function getIndeterminate(value) {
286 var _this7 = this;
287
288 var indeterminate = [];
289
290 var positions = value.map(this.getPos.bind(this));
291 positions.forEach(function (pos) {
292 if (!pos) {
293 return false;
294 }
295 var nums = pos.split('-');
296 for (var i = nums.length; i > 2; i--) {
297 var parentPos = nums.slice(0, i - 1).join('-');
298 var parentValue = _this7.getValue(parentPos);
299 if (indeterminate.indexOf(parentValue) === -1) {
300 indeterminate.push(parentValue);
301 }
302 }
303 });
304
305 return indeterminate;
306 };
307
308 CascaderSelect.prototype.saveSelectRef = function saveSelectRef(ref) {
309 this.select = ref;
310 };
311
312 CascaderSelect.prototype.saveCascaderRef = function saveCascaderRef(ref) {
313 this.cascader = ref;
314 };
315
316 CascaderSelect.prototype.completeValue = function completeValue(value) {
317 var newValue = [];
318
319 var flatValue = this.flatValue(value).reverse();
320 var ps = Object.keys(this._p2n);
321 for (var i = 0; i < ps.length; i++) {
322 for (var j = 0; j < flatValue.length; j++) {
323 var v = flatValue[j];
324 if (this.isDescendantOrSelf(this.getPos(v), ps[i])) {
325 newValue.push(this.getValue(ps[i]));
326 ps.splice(i, 1);
327 i--;
328 break;
329 }
330 }
331 }
332
333 return newValue;
334 };
335
336 CascaderSelect.prototype.isLeaf = function isLeaf(data) {
337 return !(data.children && data.children.length || !!this.props.loadData && !data.isLeaf);
338 };
339
340 CascaderSelect.prototype.handleVisibleChange = function handleVisibleChange(visible, type) {
341 var _this8 = this;
342
343 var searchValue = this.state.searchValue;
344
345 if (!('visible' in this.props)) {
346 this.setState({
347 visible: visible
348 });
349 }
350
351 if (!visible && searchValue) {
352 this.setState({
353 searchValue: ''
354 });
355 }
356
357 if (['fromCascader', 'keyboard'].indexOf(type) !== -1 && !visible) {
358 // 这里需要延迟下,showSearch 的情况下通过手动设置 menuProps={{focusable: true}} 回车 focus 会有延迟
359 setTimeout(function () {
360 return _this8.select.focusInput();
361 }, 0);
362 }
363
364 this.props.onVisibleChange(visible, type);
365 };
366
367 CascaderSelect.prototype.handleKeyDown = function handleKeyDown(e) {
368 var onKeyDown = this.props.onKeyDown;
369 var visible = this.state.visible;
370
371
372 if (onKeyDown) {
373 onKeyDown(e);
374 }
375
376 if (!visible) {
377 return;
378 }
379
380 switch (e.keyCode) {
381 case _util.KEYCODE.UP:
382 case _util.KEYCODE.DOWN:
383 this.cascader.setFocusValue();
384 e.preventDefault();
385 break;
386 default:
387 break;
388 }
389 };
390
391 CascaderSelect.prototype.getPopup = function getPopup(ref) {
392 this.popup = ref;
393 if (typeof this.props.popupProps.ref === 'function') {
394 this.props.popupProps.ref(ref);
395 }
396 };
397
398 CascaderSelect.prototype.handleAfterOpen = function handleAfterOpen() {
399 if (!this.popup) {
400 return;
401 }
402
403 var _props2 = this.props,
404 prefix = _props2.prefix,
405 popupProps = _props2.popupProps;
406
407 var dropDownNode = this.popup.getInstance().overlay.getInstance().getContentNode();
408 var cascaderNode = dropDownNode.querySelector('.' + prefix + 'cascader');
409 if (cascaderNode) {
410 this.cascaderHeight = getStyle(cascaderNode, 'height');
411 }
412
413 if (typeof popupProps.afterOpen === 'function') {
414 popupProps.afterOpen();
415 }
416 };
417
418 CascaderSelect.prototype.handleSelect = function handleSelect(value, data) {
419 var _props3 = this.props,
420 multiple = _props3.multiple,
421 changeOnSelect = _props3.changeOnSelect;
422 var _state = this.state,
423 visible = _state.visible,
424 searchValue = _state.searchValue;
425
426
427 if (!multiple && (!changeOnSelect || this.isLeaf(data) || !!searchValue)) {
428 this.handleVisibleChange(!visible, 'fromCascader');
429 }
430 };
431
432 /**
433 * 刷新值数据缓存,删除无效值
434 * @param {Arrary | String} curValue 当前值
435 */
436
437
438 CascaderSelect.prototype.handleChange = function handleChange(value, data, extra) {
439 var _this9 = this;
440
441 var _props4 = this.props,
442 multiple = _props4.multiple,
443 onChange = _props4.onChange;
444 var _state2 = this.state,
445 searchValue = _state2.searchValue,
446 stateValue = _state2.value;
447
448
449 var st = {};
450
451 if (multiple && stateValue && Array.isArray(stateValue)) {
452 var noExistedValues = stateValue.filter(function (v) {
453 return !_this9._v2n[v];
454 });
455
456 value = [].concat(noExistedValues, value);
457 // onChange 中的 data 参数也应该保留不存在的 value 的数据
458 // 在 dataSource 异步加载的情况下,会出现value重复的现象,需要去重
459 data = [].concat(noExistedValues.map(function (v) {
460 return _this9._valueDataCache[v];
461 }).filter(function (v) {
462 return v;
463 }), data).filter(function (current, index, arr) {
464 return index === arr.indexOf(current);
465 });
466 // 更新缓存
467 this.refreshValueDataCache(value);
468 }
469
470 if (!('value' in this.props)) {
471 st.value = value;
472 }
473 if (!multiple && searchValue) {
474 st.searchValue = '';
475 }
476 if (Object.keys(st).length) {
477 this.setState(st);
478 }
479
480 if (onChange) {
481 onChange(value, data, extra);
482 }
483
484 if (searchValue && this.select) {
485 this.select.handleSearchClear();
486 }
487 };
488
489 CascaderSelect.prototype.handleClear = function handleClear() {
490 // 单选时点击清空按钮
491 var _props5 = this.props,
492 hasClear = _props5.hasClear,
493 multiple = _props5.multiple,
494 treeCheckable = _props5.treeCheckable;
495
496 if (hasClear && (!multiple || !treeCheckable)) {
497 if (!('value' in this.props)) {
498 this.setState({
499 value: []
500 });
501 }
502
503 this.props.onChange(null, null);
504 }
505 };
506
507 CascaderSelect.prototype.handleRemove = function handleRemove(currentData) {
508 var currentValue = currentData.value;
509
510 var value = void 0;
511
512 var _props6 = this.props,
513 multiple = _props6.multiple,
514 checkStrictly = _props6.checkStrictly,
515 onChange = _props6.onChange;
516
517 if (multiple) {
518 value = [].concat(this.state.value);
519 value.splice(value.indexOf(currentValue), 1);
520
521 if (this.props.onChange) {
522 var data = this.getData(value);
523 var checked = false;
524
525 if (checkStrictly) {
526 this.props.onChange(value, data, {
527 checked: checked,
528 currentData: currentData,
529 checkedData: data
530 });
531 } else {
532 var checkedValue = this.completeValue(value);
533 var checkedData = this.getData(checkedValue);
534 var indeterminateValue = this.getIndeterminate(value);
535 var indeterminateData = this.getData(indeterminateValue);
536 this.props.onChange(value, data, {
537 checked: checked,
538 currentData: currentData,
539 checkedData: checkedData,
540 indeterminateData: indeterminateData
541 });
542 }
543 }
544 } else {
545 value = [];
546 onChange(null, null);
547 }
548
549 if (!('value' in this.props)) {
550 this.setState({
551 value: value
552 });
553 }
554
555 this.refreshValueDataCache(value);
556 };
557
558 CascaderSelect.prototype.handleSearch = function handleSearch(searchValue) {
559 this.setState({
560 searchValue: searchValue
561 });
562
563 this.props.onSearch && this.props.onSearch(searchValue);
564 };
565
566 CascaderSelect.prototype.getPath = function getPath(pos) {
567 var items = [];
568
569 var nums = pos.split('-');
570 if (nums === 2) {
571 items.push(this._p2n[pos]);
572 } else {
573 for (var i = 1; i < nums.length; i++) {
574 var p = nums.slice(0, i + 1).join('-');
575 items.push(this._p2n[p]);
576 }
577 }
578
579 return items;
580 };
581
582 CascaderSelect.prototype.filterItems = function filterItems() {
583 var _this10 = this;
584
585 var _props7 = this.props,
586 multiple = _props7.multiple,
587 changeOnSelect = _props7.changeOnSelect,
588 canOnlyCheckLeaf = _props7.canOnlyCheckLeaf,
589 filter = _props7.filter;
590 var searchValue = this.state.searchValue;
591
592 var items = Object.keys(this._p2n).map(function (p) {
593 return _this10._p2n[p];
594 });
595 if (!multiple && !changeOnSelect || multiple && canOnlyCheckLeaf) {
596 items = items.filter(function (item) {
597 return !item.children || !item.children.length;
598 });
599 }
600
601 return items.map(function (item) {
602 return _this10.getPath(item.pos);
603 }).filter(function (path) {
604 return filter(searchValue, path);
605 });
606 };
607
608 CascaderSelect.prototype.renderNotFound = function renderNotFound() {
609 var _props8 = this.props,
610 prefix = _props8.prefix,
611 notFoundContent = _props8.notFoundContent;
612
613
614 return _react2.default.createElement(
615 _menu2.default,
616 { className: prefix + 'cascader-select-not-found' },
617 _react2.default.createElement(
618 _menu2.default.Item,
619 null,
620 notFoundContent
621 )
622 );
623 };
624
625 CascaderSelect.prototype.renderCascader = function renderCascader() {
626 var dataSource = this.props.dataSource;
627
628 if (dataSource.length === 0) {
629 return this.renderNotFound();
630 }
631
632 var searchValue = this.state.searchValue;
633
634 var filteredPaths = [];
635
636 if (searchValue) {
637 filteredPaths = this.filterItems();
638 if (filteredPaths.length === 0) {
639 return this.renderNotFound();
640 }
641 }
642
643 var _props9 = this.props,
644 multiple = _props9.multiple,
645 useVirtual = _props9.useVirtual,
646 changeOnSelect = _props9.changeOnSelect,
647 checkStrictly = _props9.checkStrictly,
648 canOnlyCheckLeaf = _props9.canOnlyCheckLeaf,
649 defaultExpandedValue = _props9.defaultExpandedValue,
650 expandTriggerType = _props9.expandTriggerType,
651 onExpand = _props9.onExpand,
652 listStyle = _props9.listStyle,
653 listClassName = _props9.listClassName,
654 loadData = _props9.loadData,
655 showSearch = _props9.showSearch,
656 resultRender = _props9.resultRender,
657 readOnly = _props9.readOnly,
658 itemRender = _props9.itemRender,
659 immutable = _props9.immutable,
660 _props9$menuProps = _props9.menuProps,
661 menuProps = _props9$menuProps === undefined ? {} : _props9$menuProps;
662 var value = this.state.value;
663
664
665 var props = {
666 dataSource: dataSource,
667 value: value,
668 multiple: multiple,
669 useVirtual: useVirtual,
670 canOnlySelectLeaf: !changeOnSelect,
671 checkStrictly: checkStrictly,
672 canOnlyCheckLeaf: canOnlyCheckLeaf,
673 defaultExpandedValue: defaultExpandedValue,
674 expandTriggerType: expandTriggerType,
675 ref: this.saveCascaderRef,
676 onExpand: onExpand,
677 listStyle: listStyle,
678 listClassName: listClassName,
679 loadData: loadData,
680 itemRender: itemRender,
681 immutable: immutable
682 };
683
684 if ('expandedValue' in this.props) {
685 props.expandedValue = this.props.expandedValue;
686 }
687
688 if (!readOnly) {
689 props.onChange = this.handleChange;
690 props.onSelect = this.handleSelect;
691 }
692 if (showSearch) {
693 props.searchValue = searchValue;
694 props.filteredPaths = filteredPaths;
695 props.resultRender = resultRender;
696 props.filteredListStyle = { height: this.cascaderHeight };
697 }
698
699 return _react2.default.createElement(_cascader2.default, (0, _extends3.default)({}, props, menuProps));
700 };
701
702 CascaderSelect.prototype.renderPopupContent = function renderPopupContent() {
703 var _props10 = this.props,
704 prefix = _props10.prefix,
705 header = _props10.header,
706 footer = _props10.footer;
707
708 return _react2.default.createElement(
709 'div',
710 { className: prefix + 'cascader-select-dropdown' },
711 header,
712 this.renderCascader(),
713 footer
714 );
715 };
716
717 CascaderSelect.prototype.renderPreview = function renderPreview(others) {
718 var _props11 = this.props,
719 prefix = _props11.prefix,
720 multiple = _props11.multiple,
721 className = _props11.className,
722 renderPreview = _props11.renderPreview;
723 var value = this.state.value;
724
725 var previewCls = (0, _classnames2.default)(className, prefix + 'form-preview');
726 var items = (multiple ? this.getMultipleData(value) : this.getSingleData(value)) || [];
727
728 if (!Array.isArray(items)) {
729 items = [items];
730 }
731
732 if (typeof renderPreview === 'function') {
733 return _react2.default.createElement(
734 'div',
735 (0, _extends3.default)({}, others, { className: previewCls }),
736 renderPreview(items, this.props)
737 );
738 }
739
740 return _react2.default.createElement(
741 'p',
742 (0, _extends3.default)({}, others, { className: previewCls }),
743 items.map(function (_ref) {
744 var label = _ref.label;
745 return label;
746 }).join(', ')
747 );
748 };
749
750 CascaderSelect.prototype.render = function render() {
751 var _props12 = this.props,
752 prefix = _props12.prefix,
753 size = _props12.size,
754 hasArrow = _props12.hasArrow,
755 hasBorder = _props12.hasBorder,
756 hasClear = _props12.hasClear,
757 label = _props12.label,
758 readOnly = _props12.readOnly,
759 placeholder = _props12.placeholder,
760 dataSource = _props12.dataSource,
761 disabled = _props12.disabled,
762 multiple = _props12.multiple,
763 className = _props12.className,
764 showSearch = _props12.showSearch,
765 popupStyle = _props12.popupStyle,
766 popupClassName = _props12.popupClassName,
767 popupContainer = _props12.popupContainer,
768 popupProps = _props12.popupProps,
769 followTrigger = _props12.followTrigger,
770 isPreview = _props12.isPreview,
771 resultAutoWidth = _props12.resultAutoWidth;
772 var _state3 = this.state,
773 value = _state3.value,
774 searchValue = _state3.searchValue,
775 visible = _state3.visible;
776
777 var others = pickOthers(Object.keys(CascaderSelect.propTypes), this.props);
778
779 this.updateCache(dataSource);
780
781 if (isPreview) {
782 return this.renderPreview(others);
783 }
784
785 var popupContent = this.renderPopupContent();
786
787 var props = {
788 prefix: prefix,
789 className: className,
790 size: size,
791 placeholder: placeholder,
792 disabled: disabled,
793 hasArrow: hasArrow,
794 hasBorder: hasBorder,
795 hasClear: hasClear,
796 label: label,
797 readOnly: readOnly,
798 ref: this.saveSelectRef,
799 autoWidth: false,
800 mode: multiple ? 'multiple' : 'single',
801 value: multiple ? this.getMultipleData(value) : this.getSingleData(value),
802 onChange: this.handleClear,
803 onRemove: this.handleRemove,
804 visible: visible,
805 onVisibleChange: this.handleVisibleChange,
806 showSearch: showSearch,
807 onSearch: this.handleSearch,
808 onKeyDown: this.handleKeyDown,
809 popupContent: popupContent,
810 popupStyle: popupStyle,
811 popupClassName: popupClassName,
812 popupContainer: popupContainer,
813 popupProps: popupProps,
814 followTrigger: followTrigger
815 };
816
817 if (showSearch) {
818 props.popupProps = (0, _extends3.default)({}, popupProps, {
819 ref: this.getPopup,
820 afterOpen: this.handleAfterOpen
821 });
822 props.autoWidth = resultAutoWidth && !!searchValue;
823 }
824
825 return _react2.default.createElement(_select2.default, (0, _extends3.default)({}, props, others));
826 };
827
828 return CascaderSelect;
829}(_react.Component), _class.propTypes = {
830 prefix: _propTypes2.default.string,
831 pure: _propTypes2.default.bool,
832 className: _propTypes2.default.string,
833 /**
834 * 选择框大小
835 */
836 size: _propTypes2.default.oneOf(['small', 'medium', 'large']),
837 /**
838 * 选择框占位符
839 */
840 placeholder: _propTypes2.default.string,
841 /**
842 * 是否禁用
843 */
844 disabled: _propTypes2.default.bool,
845 /**
846 * 是否有下拉箭头
847 */
848 hasArrow: _propTypes2.default.bool,
849 /**
850 * 是否有边框
851 */
852 hasBorder: _propTypes2.default.bool,
853 /**
854 * 是否有清除按钮
855 */
856 hasClear: _propTypes2.default.bool,
857 /**
858 * 自定义内联 label
859 */
860 label: _propTypes2.default.node,
861 /**
862 * 是否只读,只读模式下可以展开弹层但不能选
863 */
864 readOnly: _propTypes2.default.bool,
865 /**
866 * 数据源,结构可参考下方说明
867 */
868 dataSource: _propTypes2.default.arrayOf(_propTypes2.default.object),
869 /**
870 * (非受控)默认值
871 */
872 defaultValue: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.arrayOf(_propTypes2.default.string)]),
873 /**
874 * (受控)当前值
875 */
876 value: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.arrayOf(_propTypes2.default.string)]),
877 /**
878 * 选中值改变时触发的回调函数
879 * @param {String|Array} value 选中的值,单选时返回单个值,多选时返回数组
880 * @param {Object|Array} data 选中的数据,包括 value 和 label,单选时返回单个值,多选时返回数组,父子节点选中关联时,同时选中,只返回父节点
881 * @param {Object} extra 额外参数
882 * @param {Array} extra.selectedPath 单选时选中的数据的路径
883 * @param {Boolean} extra.checked 多选时当前的操作是选中还是取消选中
884 * @param {Object} extra.currentData 多选时当前操作的数据
885 * @param {Array} extra.checkedData 多选时所有被选中的数据
886 * @param {Array} extra.indeterminateData 多选时半选的数据
887 */
888 onChange: _propTypes2.default.func,
889 /**
890 * 默认展开值,如果不设置,组件内部会根据 defaultValue/value 进行自动设置
891 */
892 defaultExpandedValue: _propTypes2.default.arrayOf(_propTypes2.default.string),
893 /**
894 * (受控)当前展开值
895 */
896 expandedValue: _propTypes2.default.arrayOf(_propTypes2.default.string),
897 /**
898 * 展开触发的方式
899 */
900 expandTriggerType: _propTypes2.default.oneOf(['click', 'hover']),
901 onExpand: _propTypes2.default.func,
902 /**
903 * 是否开启虚拟滚动
904 */
905 useVirtual: _propTypes2.default.bool,
906 /**
907 * 是否多选
908 */
909 multiple: _propTypes2.default.bool,
910 /**
911 * 是否选中即发生改变, 该属性仅在单选模式下有效
912 */
913 changeOnSelect: _propTypes2.default.bool,
914 /**
915 * 是否只能勾选叶子项的checkbox,该属性仅在多选模式下有效
916 */
917 canOnlyCheckLeaf: _propTypes2.default.bool,
918 /**
919 * 父子节点是否选中不关联
920 */
921 checkStrictly: _propTypes2.default.bool,
922 /**
923 * 每列列表样式对象
924 */
925 listStyle: _propTypes2.default.object,
926 /**
927 * 每列列表类名
928 */
929 listClassName: _propTypes2.default.string,
930 /**
931 * 选择框单选时展示结果的自定义渲染函数
932 * @param {Array} label 选中路径的文本数组
933 * @return {ReactNode} 渲染在选择框中的内容
934 * @default 单选时:labelPath => labelPath.join(' / ');多选时:labelPath => labelPath[labelPath.length - 1]
935 */
936 displayRender: _propTypes2.default.func,
937 /**
938 * 渲染 item 内容的方法
939 * @param {Object} item 渲染节点的item
940 * @return {ReactNode} item node
941 */
942 itemRender: _propTypes2.default.func,
943 /**
944 * 是否显示搜索框
945 */
946 showSearch: _propTypes2.default.bool,
947 /**
948 * 自定义搜索函数
949 * @param {String} searchValue 搜索的关键字
950 * @param {Array} path 节点路径
951 * @return {Boolean} 是否匹配
952 * @default 根据路径所有节点的文本值模糊匹配
953 */
954 filter: _propTypes2.default.func,
955 /**
956 * 当搜索框值变化时回调
957 * @param {String} value 数据
958 * @version 1.23
959 */
960 onSearch: _propTypes2.default.func,
961 /**
962 * 搜索结果自定义渲染函数
963 * @param {String} searchValue 搜索的关键字
964 * @param {Array} path 匹配到的节点路径
965 * @return {ReactNode} 渲染的内容
966 * @default 按照节点文本 a / b / c 的模式渲染
967 */
968 resultRender: _propTypes2.default.func,
969 /**
970 * 搜索结果列表是否和选择框等宽
971 */
972 resultAutoWidth: _propTypes2.default.bool,
973 /**
974 * 无数据时显示内容
975 */
976 notFoundContent: _propTypes2.default.node,
977 /**
978 * 异步加载数据函数
979 * @param {Object} data 当前点击异步加载的数据
980 */
981 loadData: _propTypes2.default.func,
982 /**
983 * 自定义下拉框头部
984 */
985 header: _propTypes2.default.node,
986 /**
987 * 自定义下拉框底部
988 */
989 footer: _propTypes2.default.node,
990 /**
991 * 初始下拉框是否显示
992 */
993 defaultVisible: _propTypes2.default.bool,
994 /**
995 * 当前下拉框是否显示
996 */
997 visible: _propTypes2.default.bool,
998 /**
999 * 下拉框显示或关闭时触发事件的回调函数
1000 * @param {Boolean} visible 是否显示
1001 * @param {String} type 触发显示关闭的操作类型, fromTrigger 表示由trigger的点击触发; docClick 表示由document的点击触发
1002 */
1003 onVisibleChange: _propTypes2.default.func,
1004 /**
1005 * 下拉框自定义样式对象
1006 */
1007 popupStyle: _propTypes2.default.object,
1008 /**
1009 * 下拉框样式自定义类名
1010 */
1011 popupClassName: _propTypes2.default.string,
1012 /**
1013 * 下拉框挂载的容器节点
1014 */
1015 popupContainer: _propTypes2.default.any,
1016 /**
1017 * 透传到 Popup 的属性对象
1018 */
1019 popupProps: _propTypes2.default.object,
1020 /**
1021 * 是否跟随滚动
1022 */
1023 followTrigger: _propTypes2.default.bool,
1024 /**
1025 * 是否为预览态
1026 */
1027 isPreview: _propTypes2.default.bool,
1028 /**
1029 * 预览态模式下渲染的内容
1030 * @param {Array<data>} value 选择值 { label: , value:}
1031 */
1032 renderPreview: _propTypes2.default.func,
1033 /**
1034 * 是否是不可变数据
1035 * @version 1.23
1036 */
1037 immutable: _propTypes2.default.bool
1038}, _class.defaultProps = {
1039 prefix: 'next-',
1040 pure: false,
1041 size: 'medium',
1042 disabled: false,
1043 hasArrow: true,
1044 hasBorder: true,
1045 hasClear: false,
1046 dataSource: [],
1047 defaultValue: null,
1048 expandTriggerType: 'click',
1049 onExpand: function onExpand() {},
1050 useVirtual: false,
1051 multiple: false,
1052 changeOnSelect: false,
1053 canOnlyCheckLeaf: false,
1054 checkStrictly: false,
1055 showSearch: false,
1056 filter: function filter(searchValue, path) {
1057 return path.some(function (item) {
1058 return String(item.label).toLowerCase().indexOf(String(searchValue).toLowerCase()) > -1;
1059 });
1060 },
1061 resultRender: function resultRender(searchValue, path) {
1062 var parts = [];
1063 path.forEach(function (item, i) {
1064 var reExp = searchValue.replace(/[-.+*?^$()[\]{}|\\]/g, function (v) {
1065 return '\\' + v;
1066 });
1067
1068 var re = new RegExp(reExp, 'gi');
1069 var others = item.label.split(re);
1070 var matches = item.label.match(re);
1071
1072 others.forEach(function (other, j) {
1073 if (other) {
1074 parts.push(other);
1075 }
1076 if (j < others.length - 1) {
1077 parts.push(_react2.default.createElement(
1078 'em',
1079 { key: i + '-' + j },
1080 matches[j]
1081 ));
1082 }
1083 });
1084 if (i < path.length - 1) {
1085 parts.push(' / ');
1086 }
1087 });
1088 return _react2.default.createElement(
1089 'span',
1090 null,
1091 parts
1092 );
1093 },
1094 resultAutoWidth: true,
1095 notFoundContent: 'Not Found',
1096 defaultVisible: false,
1097 onVisibleChange: function onVisibleChange() {},
1098 popupProps: {},
1099 immutable: false
1100}, _temp);
1101CascaderSelect.displayName = 'CascaderSelect';
1102exports.default = (0, _reactLifecyclesCompat.polyfill)(CascaderSelect);
1103module.exports = exports['default'];
\No newline at end of file