"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _select = _interopRequireDefault(require("../select"));

var _tree = _interopRequireDefault(require("../tree"));

var _util = require("../tree/view/util");

var _util2 = require("../util");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var noop = function noop() {};

var TreeNode = _tree["default"].Node;
var pickOthers = _util2.obj.pickOthers;
/**
 * TreeSelect
 */

var TreeSelect =
/*#__PURE__*/
function (_Component) {
  _inherits(TreeSelect, _Component);

  function TreeSelect(_props, context) {
    var _this;

    _classCallCheck(this, TreeSelect);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(TreeSelect).call(this, _props, context));

    _defineProperty(_assertThisInitialized(_this), "updateCache", function (props) {
      _this._k2n = {};
      _this._p2n = {};
      _this._v2n = {};

      if ('dataSource' in props) {
        var loop = function loop(data) {
          var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
          return data.map(function (item, index) {
            var value = item.value,
                children = item.children;
            var pos = "".concat(prefix, "-").concat(index);
            var key = item.key || pos;

            var newItem = _objectSpread({}, item, {
              key: key,
              pos: pos
            });

            if (children && children.length) {
              newItem.children = loop(children, pos);
            }

            _this._k2n[key] = _this._p2n[pos] = _this._v2n[value] = newItem;
            return newItem;
          });
        };

        loop(props.dataSource);
      } else if ('children' in props) {
        var _loop = function _loop(children) {
          var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
          return _react.Children.map(children, function (node, index) {
            if (!_react["default"].isValidElement(node)) {
              return;
            }

            var _node$props = node.props,
                value = _node$props.value,
                children = _node$props.children;
            var pos = "".concat(prefix, "-").concat(index);
            var key = node.key || pos;

            var newItem = _objectSpread({}, node.props, {
              key: key,
              pos: pos
            });

            if (children && _react.Children.count(children)) {
              newItem.children = _loop(children, pos);
            }

            _this._k2n[key] = _this._p2n[pos] = _this._v2n[value] = newItem;
            return newItem;
          });
        };

        _loop(props.children);
      }
    });

    _defineProperty(_assertThisInitialized(_this), "getKeysByValue", function (value) {
      return value.reduce(function (ret, v) {
        var k = _this._v2n[v] && _this._v2n[v].key;

        if (k) {
          ret.push(k);
        } else {
          // value不在dataSource中，将value作为key
          ret.push(v);
        }

        return ret;
      }, []);
    });

    _defineProperty(_assertThisInitialized(_this), "getValueByKeys", function (keys) {
      return keys.map(function (k) {
        return typeof _this._k2n[k].value === 'undefined' ? k : _this._k2n[k].value;
      });
    });

    _defineProperty(_assertThisInitialized(_this), "getValueForSelect", function (value) {
      var treeCheckedStrategy = _this.props.treeCheckedStrategy;

      var keys = _this.getKeysByValue(value);

      var keyNotInDataSource = keys.find(function (k) {
        return typeof _this._k2n[k] === 'undefined';
      });
      keys = (0, _util.getAllCheckedKeys)(keys, _this._k2n, _this._p2n);

      switch (treeCheckedStrategy) {
        case 'parent':
          keys = (0, _util.filterChildKey)(keys, _this._k2n);
          break;

        case 'child':
          keys = (0, _util.filterParentKey)(keys, _this._k2n);
          break;

        default:
          break;
      }

      var result = _this.getValueByKeys(keys);

      if (typeof keyNotInDataSource !== 'undefined') {
        result.push(keyNotInDataSource);
      }

      return result;
    });

    _defineProperty(_assertThisInitialized(_this), "getData", function (value, forSelect) {
      return value.reduce(function (ret, v) {
        var k = _this._v2n[v] && _this._v2n[v].key;

        if (k) {
          var _this$_k2n$k = _this._k2n[k],
              label = _this$_k2n$k.label,
              pos = _this$_k2n$k.pos,
              disabled = _this$_k2n$k.disabled,
              checkboxDisabled = _this$_k2n$k.checkboxDisabled;
          var d = {
            value: v,
            label: label,
            pos: pos
          };

          if (forSelect) {
            d.disabled = disabled || checkboxDisabled;
          } else {
            d.key = k;
          }

          ret.push(d);
        } else {
          // 不存在强行构造
          ret.push({
            value: v,
            label: '',
            pos: ''
          });
        }

        return ret;
      }, []);
    });

    _defineProperty(_assertThisInitialized(_this), "saveTreeRef", function (ref) {
      _this.tree = ref;
    });

    _defineProperty(_assertThisInitialized(_this), "saveSelectRef", function (ref) {
      _this.select = ref;
    });

    _defineProperty(_assertThisInitialized(_this), "handleVisibleChange", function (visible, type) {
      if (!('visible' in _this.props)) {
        _this.setState({
          visible: visible
        });
      }

      if (['fromTree', 'keyboard'].indexOf(type) !== -1 && !visible) {
        _this.select.focusInput();
      }

      _this.props.onVisibleChange(visible, type);
    });

    _defineProperty(_assertThisInitialized(_this), "handleSelect", function (selectedKeys, extra) {
      var _this$props = _this.props,
          multiple = _this$props.multiple,
          onChange = _this$props.onChange;
      var selected = extra.selected;

      if (multiple || selected) {
        var value = _this.getValueByKeys(selectedKeys);

        if (!('value' in _this.props)) {
          _this.setState({
            value: value
          });
        }

        if (!multiple) {
          _this.handleVisibleChange(false, 'fromTree');
        }

        var data = _this.getData(value);

        multiple ? onChange(value, data) : onChange(value[0], data[0]);
      } else {
        _this.handleVisibleChange(false, 'fromTree');
      }
    });

    _defineProperty(_assertThisInitialized(_this), "handleCheck", function (checkedKeys) {
      var onChange = _this.props.onChange;

      var value = _this.getValueByKeys(checkedKeys);

      var keys = _this.getKeysByValue(_this.state.value);

      var keyNotInDataSource = keys.find(function (k) {
        return typeof _this._k2n[k] === 'undefined';
      });

      if (typeof keyNotInDataSource !== 'undefined') {
        value.push(keyNotInDataSource);
      }

      if (!('value' in _this.props)) {
        _this.setState({
          value: value
        });
      }

      onChange(value, _this.getData(value));
    });

    _defineProperty(_assertThisInitialized(_this), "handleRemove", function (removedItem) {
      var removedValue = removedItem.value;
      var _this$props2 = _this.props,
          treeCheckable = _this$props2.treeCheckable,
          treeCheckStrictly = _this$props2.treeCheckStrictly,
          treeCheckedStrategy = _this$props2.treeCheckedStrategy,
          onChange = _this$props2.onChange;
      var value;

      if (treeCheckable && !treeCheckStrictly && treeCheckedStrategy === 'all') {
        var removedPos = _this._v2n[removedValue].pos;
        value = _this.state.value.filter(function (v) {
          var p = _this._v2n[v].pos;
          return !(0, _util.isDescendantOrSelf)(removedPos, p);
        });
        var nums = removedPos.split('-');

        for (var i = nums.length; i > 2; i--) {
          var parentPos = nums.slice(0, i - 1).join('-');
          var parentValue = _this._p2n[parentPos].value;
          var parentIndex = value.indexOf(parentValue);

          if (parentIndex > -1) {
            value.splice(parentIndex, 1);
          } else {
            break;
          }
        }
      } else {
        value = _this.state.value.filter(function (v) {
          return v !== removedValue;
        });
      }

      if (!('value' in _this.props)) {
        _this.setState({
          value: value
        });
      }

      var data = _this.getData(value);

      onChange(value, data);
    });

    _defineProperty(_assertThisInitialized(_this), "handleSearch", function (searchedValue) {
      var searchedKeys = [];
      var retainedKeys = [];
      Object.keys(_this._k2n).forEach(function (k) {
        var _this$_k2n$k2 = _this._k2n[k],
            label = _this$_k2n$k2.label,
            pos = _this$_k2n$k2.pos;

        if (_this.isSearched(label, searchedValue)) {
          searchedKeys.push(k);
          var posArr = pos.split('-');
          posArr.forEach(function (n, i) {
            if (i > 0) {
              var p = posArr.slice(0, i + 1).join('-');
              var kk = _this._p2n[p].key;

              if (retainedKeys.indexOf(kk) === -1) {
                retainedKeys.push(kk);
              }
            }
          });
        }
      });

      _this.setState({
        searchedValue: searchedValue,
        expandedKeys: searchedKeys,
        autoExpandParent: true
      });

      _this.searchedKeys = searchedKeys;
      _this.retainedKeys = retainedKeys;

      _this.props.onSearch(searchedValue);
    });

    _defineProperty(_assertThisInitialized(_this), "handleSearchClear", function (triggerType) {
      _this.setState({
        searchedValue: '',
        expandedKeys: []
      });

      _this.props.onSearchClear(triggerType);
    });

    _defineProperty(_assertThisInitialized(_this), "handleExpand", function (expandedKeys) {
      _this.setState({
        expandedKeys: expandedKeys,
        autoExpandParent: false
      });
    });

    _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (e) {
      var onKeyDown = _this.props.onKeyDown;
      var visible = _this.state.visible;

      if (onKeyDown) {
        onKeyDown(e);
      }

      if (!visible) {
        return;
      }

      switch (e.keyCode) {
        case _util2.KEYCODE.UP:
        case _util2.KEYCODE.DOWN:
          _this.tree.setFocusKey();

          e.preventDefault();
          break;

        default:
          break;
      }
    });

    _defineProperty(_assertThisInitialized(_this), "handleChange", function () {
      // 单选时点击清空按钮
      var _this$props3 = _this.props,
          hasClear = _this$props3.hasClear,
          multiple = _this$props3.multiple,
          treeCheckable = _this$props3.treeCheckable;

      if (hasClear && (!multiple || !treeCheckable)) {
        if (!('value' in _this.props)) {
          _this.setState({
            value: []
          });
        }

        _this.props.onChange(null, null);
      }
    });

    _defineProperty(_assertThisInitialized(_this), "isSearched", function (label, searchedValue) {
      var labelString = '';

      var loop = function loop(arg) {
        if ((0, _react.isValidElement)(arg) && arg.props.children) {
          _react.Children.forEach(arg.props.children, loop);
        } else if (typeof arg === 'string') {
          labelString += arg;
        }
      };

      loop(label);

      if (labelString.length >= searchedValue.length && labelString.indexOf(searchedValue) > -1) {
        return true;
      }

      return false;
    });

    _defineProperty(_assertThisInitialized(_this), "searchNodes", function (children) {
      var loop = function loop(children) {
        var retainedNodes = [];

        _react.Children.forEach(children, function (child) {
          if (_this.searchedKeys.indexOf(child.key) > -1) {
            retainedNodes.push(child);
          } else if (_this.retainedKeys.indexOf(child.key) > -1) {
            var retainedNode = child.props.children ? (0, _react.cloneElement)(child, {}, loop(child.props.children)) : child;
            retainedNodes.push(retainedNode);
          } else {
            var hideNode = (0, _react.cloneElement)(child, {
              style: {
                display: 'none'
              }
            });
            retainedNodes.push(hideNode);
          }
        });

        return retainedNodes;
      };

      return loop(children);
    });

    _defineProperty(_assertThisInitialized(_this), "createNodesByData", function (data, searching) {
      var loop = function loop(data, isParentMatched) {
        var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '0';
        var retainedNodes = [];
        data.forEach(function (item, index) {
          var children = item.children,
              others = _objectWithoutProperties(item, ["children"]);

          var pos = "".concat(prefix, "-").concat(index);
          var key = _this._p2n[pos].key;

          var addNode = function addNode(isParentMatched, hide) {
            if (hide) {
              others.style = {
                display: 'none'
              };
            }

            retainedNodes.push(_react["default"].createElement(TreeNode, _extends({}, others, {
              key: key
            }), children && children.length ? loop(children, isParentMatched, pos) : null));
          };

          if (searching) {
            if (_this.searchedKeys.indexOf(key) > -1 || isParentMatched) {
              addNode(true);
            } else if (_this.retainedKeys.indexOf(key) > -1) {
              addNode(false);
            } else {
              addNode(false, true);
            }
          } else {
            addNode();
          }
        });
        return retainedNodes;
      };

      return loop(data, false);
    });

    _defineProperty(_assertThisInitialized(_this), "renderPopupContent", function () {
      var prefix = _this.props.prefix;
      var treeSelectPrefix = "".concat(prefix, "tree-select-");

      if (!_this.state.visible) {
        return _react["default"].createElement("div", {
          className: "".concat(treeSelectPrefix, "dropdown")
        });
      }

      var _this$props4 = _this.props,
          multiple = _this$props4.multiple,
          treeCheckable = _this$props4.treeCheckable,
          treeCheckStrictly = _this$props4.treeCheckStrictly,
          treeCheckedStrategy = _this$props4.treeCheckedStrategy,
          treeDefaultExpandAll = _this$props4.treeDefaultExpandAll,
          treeDefaultExpandedKeys = _this$props4.treeDefaultExpandedKeys,
          treeLoadData = _this$props4.treeLoadData,
          customTreeProps = _this$props4.treeProps,
          showSearch = _this$props4.showSearch,
          dataSource = _this$props4.dataSource,
          children = _this$props4.children,
          readOnly = _this$props4.readOnly,
          notFoundContent = _this$props4.notFoundContent;
      var _this$state = _this.state,
          value = _this$state.value,
          searchedValue = _this$state.searchedValue,
          expandedKeys = _this$state.expandedKeys,
          autoExpandParent = _this$state.autoExpandParent;
      var treeProps = {
        multiple: multiple,
        ref: _this.saveTreeRef,
        loadData: treeLoadData,
        defaultExpandAll: treeDefaultExpandAll,
        defaultExpandedKeys: treeDefaultExpandedKeys
      };

      var keys = _this.getKeysByValue(value);

      if (treeCheckable) {
        treeProps.checkable = treeCheckable;
        treeProps.checkStrictly = treeCheckStrictly;
        treeProps.checkedStrategy = treeCheckStrictly ? 'all' : treeCheckedStrategy;
        treeProps.checkedKeys = keys;

        if (!readOnly) {
          treeProps.onCheck = _this.handleCheck;
        }
      } else {
        treeProps.selectedKeys = keys;

        if (!readOnly) {
          treeProps.onSelect = _this.handleSelect;
        }
      }

      var notFound = false;
      var newChildren;

      if (showSearch && searchedValue) {
        treeProps.expandedKeys = expandedKeys;
        treeProps.autoExpandParent = autoExpandParent;
        treeProps.onExpand = _this.handleExpand;

        treeProps.filterTreeNode = function (node) {
          return _this.searchedKeys.indexOf(node.props.eventKey) > -1;
        };

        if (_this.searchedKeys.length) {
          newChildren = dataSource ? _this.createNodesByData(dataSource, true) : _this.searchNodes(children);
        } else {
          notFound = true;
        }
      } else {
        // eslint-disable-next-line
        if (dataSource) {
          if (dataSource.length) {
            newChildren = _this.createNodesByData(dataSource);
          } else {
            notFound = true;
          }
        } else {
          // eslint-disable-next-line
          if (_react.Children.count(children)) {
            newChildren = children;
          } else {
            notFound = true;
          }
        }
      }

      return _react["default"].createElement("div", {
        className: "".concat(treeSelectPrefix, "dropdown")
      }, notFound ? _react["default"].createElement("div", {
        className: "".concat(treeSelectPrefix, "not-found")
      }, notFoundContent) : _react["default"].createElement(_tree["default"], _extends({}, customTreeProps, treeProps), newChildren));
    });

    var defaultVisible = _props.defaultVisible,
        _visible = _props.visible,
        defaultValue = _props.defaultValue,
        _value = _props.value;
    _this.state = {
      visible: typeof _visible === 'undefined' ? defaultVisible : _visible,
      value: (0, _util.normalizeToArray)(typeof _value === 'undefined' ? defaultValue : _value),
      searchedValue: '',
      expandedKeys: [],
      autoExpandParent: false
    };

    _this.updateCache(_props);

    return _this;
  }

  _createClass(TreeSelect, [{
    key: "UNSAFE_componentWillReceiveProps",
    value: function UNSAFE_componentWillReceiveProps(nextProps) {
      this.updateCache(nextProps);
      var st = {};

      if ('value' in nextProps) {
        st.value = (0, _util.normalizeToArray)(nextProps.value);
      }

      if ('visible' in nextProps) {
        st.visible = nextProps.visible;
      }

      if (Object.keys(st).length) {
        this.setState(st);
      }
    }
  }, {
    key: "render",

    /* eslint-enable */
    value: function render() {
      var _this$props5 = this.props,
          prefix = _this$props5.prefix,
          size = _this$props5.size,
          placeholder = _this$props5.placeholder,
          disabled = _this$props5.disabled,
          hasArrow = _this$props5.hasArrow,
          hasBorder = _this$props5.hasBorder,
          hasClear = _this$props5.hasClear,
          label = _this$props5.label,
          readOnly = _this$props5.readOnly,
          autoWidth = _this$props5.autoWidth,
          popupStyle = _this$props5.popupStyle,
          popupClassName = _this$props5.popupClassName,
          showSearch = _this$props5.showSearch,
          valueRender = _this$props5.valueRender,
          multiple = _this$props5.multiple,
          treeCheckable = _this$props5.treeCheckable,
          treeCheckStrictly = _this$props5.treeCheckStrictly,
          className = _this$props5.className,
          popupContainer = _this$props5.popupContainer,
          popupProps = _this$props5.popupProps,
          followTrigger = _this$props5.followTrigger;
      var others = pickOthers(Object.keys(TreeSelect.propTypes), this.props);
      var _this$state2 = this.state,
          value = _this$state2.value,
          visible = _this$state2.visible;
      var valueForSelect = treeCheckable && !treeCheckStrictly ? this.getValueForSelect(value) : value; // 设置的value不存在于dataSource中时，直接用传入的value代替

      if (!valueForSelect.length) {
        valueForSelect = value;
      }

      var data = this.getData(valueForSelect, true);

      if (!multiple && !treeCheckable) {
        data = data[0];
      }

      return _react["default"].createElement(_select["default"], _extends({
        prefix: prefix,
        className: className,
        size: size,
        hasBorder: hasBorder,
        hasArrow: hasArrow,
        hasClear: hasClear,
        valueRender: valueRender,
        placeholder: placeholder,
        disabled: disabled,
        autoWidth: autoWidth,
        label: label,
        readOnly: readOnly,
        ref: this.saveSelectRef,
        mode: treeCheckable || multiple ? 'multiple' : 'single',
        value: data,
        onRemove: this.handleRemove,
        onChange: this.handleChange,
        visible: visible,
        onVisibleChange: this.handleVisibleChange,
        showSearch: showSearch,
        onSearch: this.handleSearch,
        onSearchClear: this.handleSearchClear,
        onKeyDown: this.handleKeyDown,
        popupContent: this.renderPopupContent(),
        popupContainer: popupContainer,
        popupStyle: popupStyle,
        popupClassName: popupClassName,
        popupProps: popupProps,
        followTrigger: followTrigger
      }, others));
    }
  }]);

  return TreeSelect;
}(_react.Component);

exports["default"] = TreeSelect;

_defineProperty(TreeSelect, "propTypes", {
  prefix: _propTypes["default"].string,
  pure: _propTypes["default"].bool,
  className: _propTypes["default"].string,

  /**
   * 树节点
   */
  children: _propTypes["default"].node,

  /**
   * 选择框大小
   */
  size: _propTypes["default"].oneOf(['small', 'medium', 'large']),

  /**
   * 选择框占位符
   */
  placeholder: _propTypes["default"].string,

  /**
   * 是否禁用
   */
  disabled: _propTypes["default"].bool,

  /**
   * 是否有下拉箭头
   */
  hasArrow: _propTypes["default"].bool,

  /**
   * 是否有边框
   */
  hasBorder: _propTypes["default"].bool,

  /**
   * 是否有清空按钮
   */
  hasClear: _propTypes["default"].bool,

  /**
   * 自定义内联 label
   */
  label: _propTypes["default"].node,

  /**
   * 是否只读，只读模式下可以展开弹层但不能选择
   */
  readOnly: _propTypes["default"].bool,

  /**
   * 下拉框是否与选择器对齐
   */
  autoWidth: _propTypes["default"].bool,

  /**
   * 数据源，该属性优先级高于 children
   */
  dataSource: _propTypes["default"].arrayOf(_propTypes["default"].object),

  /**
   * 选中的值渲染方式
   */
  valueRender: _propTypes["default"].func,

  /**
   * （受控）当前值
   */
  value: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].arrayOf(_propTypes["default"].string)]),

  /**
   * （非受控）默认值
   */
  defaultValue: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].arrayOf(_propTypes["default"].string)]),

  /**
   * 选中值改变时触发的回调函数
   * @param {String|Array} value 选中的值，单选时返回单个值，多选时返回数组
   * @param {Object|Array} data 选中的数据，包括 value, label, pos, key属性，单选时返回单个值，多选时返回数组，父子节点选中关联时，同时选中，只返回父节点
   */
  onChange: _propTypes["default"].func,

  /**
   * 是否显示搜索框
   */
  showSearch: _propTypes["default"].bool,

  /**
   * 在搜索框中输入时触发的回调函数
   * @param {String} keyword 输入的关键字
   */
  onSearch: _propTypes["default"].func,
  onSearchClear: _propTypes["default"].func,

  /**
   * 无数据时显示内容
   */
  notFoundContent: _propTypes["default"].node,

  /**
   * 是否支持多选
   */
  multiple: _propTypes["default"].bool,

  /**
   * 下拉框中的树是否支持勾选节点的复选框
   */
  treeCheckable: _propTypes["default"].bool,

  /**
   * 下拉框中的树勾选节点复选框是否完全受控（父子节点选中状态不再关联）
   */
  treeCheckStrictly: _propTypes["default"].bool,

  /**
   * 定义选中时回填的方式
   * @enumdesc 返回所有选中的节点, 父子节点都选中时只返回父节点, 父子节点都选中时只返回子节点
   */
  treeCheckedStrategy: _propTypes["default"].oneOf(['all', 'parent', 'child']),

  /**
   * 下拉框中的树是否默认展开所有节点
   */
  treeDefaultExpandAll: _propTypes["default"].bool,

  /**
   * 下拉框中的树默认展开节点key的数组
   */
  treeDefaultExpandedKeys: _propTypes["default"].arrayOf(_propTypes["default"].string),

  /**
   * 下拉框中的树异步加载数据的函数，使用请参考[Tree的异步加载数据Demo](https://fusion.design/component/tree)
   * @param {ReactElement} node 被点击展开的节点
   */
  treeLoadData: _propTypes["default"].func,

  /**
   * 透传到 Tree 的属性对象
   */
  treeProps: _propTypes["default"].object,

  /**
   * 初始下拉框是否显示
   */
  defaultVisible: _propTypes["default"].bool,

  /**
   * 当前下拉框是否显示
   */
  visible: _propTypes["default"].bool,

  /**
   * 下拉框显示或关闭时触发事件的回调函数
   * @param {Boolean} visible 是否显示
   * @param {String} type 触发显示关闭的操作类型
   */
  onVisibleChange: _propTypes["default"].func,

  /**
   * 下拉框自定义样式对象
   */
  popupStyle: _propTypes["default"].object,

  /**
   * 下拉框样式自定义类名
   */
  popupClassName: _propTypes["default"].string,

  /**
   * 下拉框挂载的容器节点
   */
  popupContainer: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].func]),

  /**
   * 透传到 Popup 的属性对象
   */
  popupProps: _propTypes["default"].object,

  /**
   * 是否跟随滚动
   */
  followTrigger: _propTypes["default"].bool
});

_defineProperty(TreeSelect, "defaultProps", {
  prefix: 'next-',
  pure: false,
  size: 'medium',
  disabled: false,
  hasArrow: true,
  hasBorder: true,
  hasClear: false,
  autoWidth: true,
  defaultValue: null,
  valueRender: function valueRender(item) {
    return item.label || item.value;
  },
  onChange: noop,
  showSearch: false,
  onSearch: noop,
  onSearchClear: noop,
  notFoundContent: 'Not Found',
  multiple: false,
  treeCheckable: false,
  treeCheckStrictly: false,
  treeCheckedStrategy: 'parent',
  treeDefaultExpandAll: false,
  treeDefaultExpandedKeys: [],
  treeProps: {},
  defaultVisible: false,
  onVisibleChange: noop
});

TreeSelect.Node = TreeNode;