"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

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

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _objectSpread4 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

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

var _reactDom = require("react-dom");

var _classnames = _interopRequireDefault(require("classnames"));

var _omit = _interopRequireDefault(require("lodash/omit"));

var _defaultTo = _interopRequireDefault(require("lodash/defaultTo"));

var _noop = _interopRequireDefault(require("lodash/noop"));

var _scrollIntoViewIfNeeded = _interopRequireDefault(require("scroll-into-view-if-needed"));

var _smoothScrollIntoViewIfNeeded = _interopRequireDefault(require("smooth-scroll-into-view-if-needed"));

var _isEqual = _interopRequireDefault(require("lodash/isEqual"));

var _componentClasses = _interopRequireDefault(require("component-classes"));

var _pagination = _interopRequireDefault(require("../pagination"));

var _icon = _interopRequireDefault(require("../icon"));

var _spin = _interopRequireDefault(require("../spin"));

var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver"));

var _default = _interopRequireDefault(require("../locale-provider/default"));

var _warning = _interopRequireDefault(require("../_util/warning"));

var _filterDropdown = _interopRequireDefault(require("./filterDropdown"));

var _createStore = _interopRequireDefault(require("./createStore"));

var _SelectionBox = _interopRequireDefault(require("./SelectionBox"));

var _SelectionCheckboxAll = _interopRequireDefault(require("./SelectionCheckboxAll"));

var _Column = _interopRequireDefault(require("./Column"));

var _button = _interopRequireDefault(require("../button"));

var _ColumnGroup = _interopRequireDefault(require("./ColumnGroup"));

var _createBodyRow = _interopRequireDefault(require("./createBodyRow"));

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

var _interface = require("./interface");

var _FilterBar = _interopRequireDefault(require("./FilterBar"));

var _FilterSelect = require("./FilterSelect");

var _table = _interopRequireDefault(require("../rc-components/table"));

var _enum = require("../_util/enum");

var _Resizable = _interopRequireDefault(require("./Resizable"));

var _ColumnFilterMenu = _interopRequireDefault(require("./ColumnFilterMenu"));

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

var _excluded = ["onResize", "onDrag", "width"],
    _excluded2 = ["autoHeight", "bodyStyle", "showHeader", "empty", "scroll", "resizable"];

var ResizeableTitle = function ResizeableTitle(props) {
  var onResize = props.onResize,
      onDrag = props.onDrag,
      width = props.width,
      restProps = (0, _objectWithoutProperties2["default"])(props, _excluded);

  if (!width) {
    return /*#__PURE__*/_react["default"].createElement("th", (0, _extends2["default"])({}, restProps));
  }

  return /*#__PURE__*/_react["default"].createElement(_Resizable["default"], {
    onResize: onResize,
    onDrag: onDrag
  }, /*#__PURE__*/_react["default"].createElement("th", (0, _extends2["default"])({}, restProps)));
};

function findBodyDom(dom, reg) {
  if (dom.childElementCount > 0) {
    for (var i = 0; i < dom.childElementCount; i += 1) {
      if (reg.test(dom.children[i].className)) {
        return dom.children[i];
      }

      if (dom.childElementCount > 0) {
        var childFound = findBodyDom(dom.children[i], reg);

        if (childFound !== null) {
          return childFound;
        }
      }
    }
  }

  return null;
}

function stopPropagation(e) {
  e.stopPropagation();

  if (e.nativeEvent.stopImmediatePropagation) {
    e.nativeEvent.stopImmediatePropagation();
  }
}

function getRowSelection(props) {
  return props.rowSelection || {};
}

function defaultRenderSorter(props) {
  var column = props.column,
      isSortColumn = props.isSortColumn,
      sortOrder = props.sortOrder,
      prefixCls = props.prefixCls,
      changeOrder = props.changeOrder;
  var isAscend = isSortColumn && sortOrder === 'ascend';
  column.className = (0, _classnames["default"])(column.className, (0, _defineProperty2["default"])({}, "".concat(prefixCls, "-sort-").concat(sortOrder), isSortColumn));
  var onHeaderCell = column.onHeaderCell;

  column.onHeaderCell = function (col) {
    var customProps = onHeaderCell && onHeaderCell(col) || {};
    var _onClick = customProps.onClick;
    return (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, customProps), {}, {
      onClick: function onClick(e) {
        if (!e.isDefaultPrevented()) {
          if (typeof _onClick === 'function') {
            _onClick(e);
          }

          if (!e.isDefaultPrevented()) {
            changeOrder(isAscend ? 'descend' : 'ascend');
          }
        }
      }
    });
  };

  return /*#__PURE__*/_react["default"].createElement(_icon["default"], {
    type: "arrow_upward",
    className: "".concat(prefixCls, "-sort-icon")
  });
}

var defaultPagination = {
  onChange: _noop["default"],
  onShowSizeChange: _noop["default"]
};
/**
 * Avoid creating new object, so that parent component's shouldComponentUpdate
 * can works appropriately。
 */

var emptyObject = {};

var Table = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(Table, _Component);

  var _super = (0, _createSuper2["default"])(Table);

  function Table(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, Table);
    _this = _super.call(this, props);

    _this.setElementRef = function (node) {
      if (node && node.tableContent) {
        _this.element = node.tableContent;
      }
    };

    _this.saveRef = function (ref) {
      _this.refTable = ref;
      _this.wrapper = ref;
    };

    _this.getCheckboxPropsByItem = function (item, index) {
      var rowSelection = getRowSelection(_this.props);

      if (!rowSelection.getCheckboxProps) {
        return {};
      }

      var key = _this.getRecordKey(item, index); // Cache checkboxProps


      if (!_this.CheckboxPropsCache[key]) {
        _this.CheckboxPropsCache[key] = rowSelection.getCheckboxProps(item);
      }

      return _this.CheckboxPropsCache[key];
    };

    _this.onRow = function (record, index) {
      var onRow = _this.props.onRow;

      var prefixCls = _this.getPrefixCls();

      var custom = onRow ? onRow(record, index) : {};
      return (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, custom), {}, {
        prefixCls: prefixCls,
        store: _this.store,
        rowKey: _this.getRecordKey(record, index)
      });
    };

    _this.handleFilter = function (column, nextFilters) {
      var stateFilters = _this.state.filters;
      var filters = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, stateFilters), {}, (0, _defineProperty2["default"])({}, _this.getColumnKey(column), nextFilters)); // Remove filters not in current columns

      var currentColumnKeys = [];
      (0, _util.treeMap)(_this.columns, function (c) {
        if (!c.children) {
          currentColumnKeys.push(_this.getColumnKey(c));
        }
      });
      Object.keys(filters).forEach(function (columnKey) {
        if (currentColumnKeys.indexOf(columnKey) < 0) {
          delete filters[columnKey];
        }
      });

      _this.setNewFilterState({
        filters: filters
      });
    };

    _this.handleFilterSelectClear = function () {
      var filters = _this.state.filters;
      Object.keys(filters).map(function (key) {
        return filters[key] = [];
      });

      _this.setNewFilterState({
        barFilters: [],
        filters: filters
      });
    };

    _this.handleFilterSelectChange = function (barFilters) {
      var onFilterSelectChange = _this.props.onFilterSelectChange;

      if (onFilterSelectChange) {
        onFilterSelectChange(barFilters);
      }

      _this.setNewFilterState({
        barFilters: barFilters
      });
    };

    _this.handleColumnFilterChange = function (e) {
      var onColumnFilterChange = _this.props.onColumnFilterChange;

      if (onColumnFilterChange) {
        onColumnFilterChange(e);
      }

      _this.forceUpdate();
    };

    _this.handleSelect = function (record, rowIndex, e) {
      var checked = e.target.checked;
      var nativeEvent = e.nativeEvent;
      var defaultSelection = _this.store.getState().selectionDirty ? [] : _this.getDefaultSelection();

      var selectedRowKeys = _this.store.getState().selectedRowKeys.concat(defaultSelection);

      var key = _this.getRecordKey(record, rowIndex);

      if (checked) {
        selectedRowKeys.push(_this.getRecordKey(record, rowIndex));
      } else {
        selectedRowKeys = selectedRowKeys.filter(function (i) {
          return key !== i;
        });
      }

      _this.store.setState({
        selectionDirty: true
      });

      _this.setSelectedRowKeys(selectedRowKeys, {
        selectWay: 'onSelect',
        record: record,
        checked: checked,
        changeRowKeys: undefined,
        nativeEvent: nativeEvent
      }, _this.getSelectedRows({
        e: e,
        record: record,
        rowIndex: rowIndex
      }));
    };

    _this.handleRadioSelect = function (record, rowIndex, e) {
      var checked = e.target.checked;
      var nativeEvent = e.nativeEvent;
      var defaultSelection = _this.store.getState().selectionDirty ? [] : _this.getDefaultSelection();

      var selectedRowKeys = _this.store.getState().selectedRowKeys.concat(defaultSelection);

      var key = _this.getRecordKey(record, rowIndex);

      selectedRowKeys = [key];

      _this.store.setState({
        selectionDirty: true
      });

      _this.setSelectedRowKeys(selectedRowKeys, {
        selectWay: 'onSelect',
        record: record,
        checked: checked,
        changeRowKeys: undefined,
        nativeEvent: nativeEvent
      }, _this.getSelectedRows({
        record: record,
        rowIndex: rowIndex
      }));
    };

    _this.handleSelectRow = function (selectionKey, index, onSelectFunc) {
      var data = _this.getFlatCurrentPageData();

      var defaultSelection = _this.store.getState().selectionDirty ? [] : _this.getDefaultSelection();

      var selectedRowKeys = _this.store.getState().selectedRowKeys.concat(defaultSelection);

      var changeableRowKeys = data.filter(function (item, i) {
        return !_this.getCheckboxPropsByItem(item, i).disabled;
      }).map(function (item, i) {
        return _this.getRecordKey(item, i);
      });
      var changeRowKeys = [];
      var selectWay = 'onSelectAll';
      var checked; // handle default selection

      switch (selectionKey) {
        case 'all':
          changeableRowKeys.forEach(function (key) {
            if (selectedRowKeys.indexOf(key) < 0) {
              selectedRowKeys.push(key);
              changeRowKeys.push(key);
            }
          });
          selectWay = 'onSelectAll';
          checked = true;
          break;

        case 'removeAll':
          changeableRowKeys.forEach(function (key) {
            if (selectedRowKeys.indexOf(key) >= 0) {
              selectedRowKeys.splice(selectedRowKeys.indexOf(key), 1);
              changeRowKeys.push(key);
            }
          });
          selectWay = 'onSelectAll';
          checked = false;
          break;

        case 'invert':
          changeableRowKeys.forEach(function (key) {
            if (selectedRowKeys.indexOf(key) < 0) {
              selectedRowKeys.push(key);
            } else {
              selectedRowKeys.splice(selectedRowKeys.indexOf(key), 1);
            }

            changeRowKeys.push(key);
            selectWay = 'onSelectInvert';
          });
          break;

        default:
          break;
      }

      _this.store.setState({
        selectionDirty: true
      }); // when select custom selection, callback selections[n].onSelect


      var rowSelection = _this.props.rowSelection;
      var customSelectionStartIndex = 2;

      if (rowSelection && rowSelection.hideDefaultSelections) {
        customSelectionStartIndex = 0;
      }

      if (index >= customSelectionStartIndex && typeof onSelectFunc === 'function') {
        return onSelectFunc(changeableRowKeys);
      }

      _this.setSelectedRowKeys(selectedRowKeys, {
        selectWay: selectWay,
        checked: checked,
        changeRowKeys: changeRowKeys
      }, _this.getSelectedRows({
        selectionKey: selectionKey
      }));
    };

    _this.handlePageChange = function (current) {
      var _this$props = _this.props,
          onChange = _this$props.onChange,
          autoScroll = _this$props.autoScroll,
          propsPagination = _this$props.pagination;
      var statePagination = _this.state.pagination;
      var pagination = (0, _objectSpread4["default"])({}, statePagination);

      if (autoScroll) {
        var _assertThisInitialize = (0, _assertThisInitialized2["default"])(_this),
            refTable = _assertThisInitialize.refTable;

        setTimeout(function () {
          var scrollIntoViewSmoothly = 'scrollBehavior' in document.documentElement.style ? _scrollIntoViewIfNeeded["default"] : _smoothScrollIntoViewIfNeeded["default"];

          if (refTable) {
            if (refTable.clientHeight > document.body.clientHeight) {
              scrollIntoViewSmoothly(refTable, {
                block: 'start',
                behavior: 'smooth',
                scrollMode: 'if-needed'
              });
            } else if ('scrollIntoViewIfNeeded' in refTable) {
              refTable.scrollIntoViewIfNeeded({
                block: 'start'
              });
            } else {
              scrollIntoViewSmoothly(refTable, {
                block: 'start',
                behavior: 'smooth',
                scrollMode: 'if-needed'
              });
            }
          }
        }, 10);

        if (refTable) {
          var dom = findBodyDom(refTable, new RegExp("".concat(_this.getPrefixCls(), "-body")));

          if (dom !== null && dom.scroll) {
            dom.scrollTop = 0;
          }
        }
      }

      if (current) {
        pagination.current = current;
      } else {
        pagination.current = pagination.current || 1;
      }

      for (var _len = arguments.length, otherArguments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
        otherArguments[_key - 1] = arguments[_key];
      }

      pagination.onChange.apply(pagination, [pagination.current].concat(otherArguments));
      var newState = {
        pagination: pagination
      }; // Controlled current prop will not respond user interaction

      if (propsPagination && (0, _typeof2["default"])(propsPagination) === 'object' && 'current' in propsPagination) {
        newState.pagination = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, pagination), {}, {
          current: statePagination.current
        });
      }

      _this.setState(newState);

      _this.store.setState({
        selectionDirty: false
      });

      if (onChange) {
        onChange.apply(void 0, (0, _toConsumableArray2["default"])(_this.prepareParamsArguments((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, _this.state), {}, {
          pagination: pagination
        }))));
      }
    };

    _this.renderSelectionBox = function (type) {
      return function (_, record, index) {
        var rowIndex = _this.getRecordKey(record, index); // 从 1 开始


        var props = _this.getCheckboxPropsByItem(record, index);

        var handleChange = function handleChange(e) {
          if (type === 'radio') {
            _this.handleRadioSelect(record, rowIndex, e);
          } else {
            _this.handleSelect(record, rowIndex, e);
          }
        };

        var _this$props2 = _this.props,
            radioPrefixCls = _this$props2.radioPrefixCls,
            checkboxPrefixCls = _this$props2.checkboxPrefixCls;
        return /*#__PURE__*/_react["default"].createElement("span", {
          onClick: stopPropagation
        }, /*#__PURE__*/_react["default"].createElement(_SelectionBox["default"], (0, _extends2["default"])({
          radioPrefixCls: radioPrefixCls,
          checkboxPrefixCls: checkboxPrefixCls,
          type: type,
          store: _this.store,
          rowIndex: rowIndex,
          onChange: handleChange,
          defaultSelection: _this.getDefaultSelection()
        }, props)));
      };
    };

    _this.getRecordKey = function (record, index) {
      var rowKey = _this.props.rowKey;
      var recordKey = typeof rowKey === 'function' ? rowKey(record, index) : record[rowKey];
      (0, _warning["default"])(recordKey !== undefined, 'Each record in dataSource of table should have a unique `key` prop, or set `rowKey` to an unique primary key');
      return recordKey === undefined ? index : recordKey;
    };

    _this.getPopupContainer = function () {
      return (0, _reactDom.findDOMNode)((0, _assertThisInitialized2["default"])(_this));
    }; // 根据 customColumns 返回新的 columns


    _this.renderCustomColumns = function (columns) {
      var customColumns = _this.getCustomColumns() || [];

      if (customColumns.length === 0) {
        return columns.map(function (column, colIndex) {
          return (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, column), {}, {
            orderSeq: colIndex
          });
        });
      }

      var newColumns = [];

      var _loop = function _loop(colIndex) {
        var column = columns[colIndex];
        var customColumn = customColumns.find(function (fCustomColumn) {
          return fCustomColumn.fieldKey === _this.getColumnKey(column);
        });

        if (!customColumn) {
          // 该字段没有自定义, 将排序设置为默认的顺序, 继续
          newColumns.push((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, column), {}, {
            orderSeq: colIndex
          }));
          return "continue";
        }

        if (customColumn.hidden === 1) {
          // 该字段隐藏了 不需要显示, 继续
          return "continue";
        }

        var newColumn = (0, _objectSpread4["default"])({}, column);

        if (customColumn.fixedLeft === 1) {
          newColumn.fixed = 'left';
        } // else if (customColumn.fixedRight) {
        //   newColumn.fixed = 'right';
        // }


        newColumn.orderSeq = customColumn.orderSeq === undefined ? colIndex : customColumn.orderSeq;
        newColumns.push(newColumn);
      };

      for (var colIndex = 0; colIndex < columns.length; colIndex++) {
        var _ret = _loop(colIndex);

        if (_ret === "continue") continue;
      }

      var noFixedColumns = [];
      var fixedLeftColumns = [];
      var fixedRightColumns = [];
      var actionColumns = newColumns.length === 0 ? [] : [newColumns[newColumns.length - 1]];

      for (var _colIndex = 0; _colIndex < newColumns.length - 1; _colIndex += 1) {
        var column = newColumns[_colIndex];

        if (column.fixed) {
          if (column.fixed === 'left') {
            fixedLeftColumns.push(column);
          } else if (column.fixed === 'right') {
            fixedRightColumns.push(column);
          } else {
            noFixedColumns.push(column);
          }
        } else {
          noFixedColumns.push(column);
        }
      }

      fixedLeftColumns.sort(function (a, b) {
        return a.orderSeq - b.orderSeq;
      });
      noFixedColumns.sort(function (a, b) {
        return a.orderSeq - b.orderSeq;
      });
      return [].concat(fixedLeftColumns, noFixedColumns, fixedRightColumns, actionColumns);
    };
    /**
     * 用户个性化 Table 编辑
     */


    _this.handleCustomColumnFilter = function () {
      var onCustomColumnFilter = _this.props.onCustomColumnFilter;

      var _this$store$getState = _this.store.getState(),
          _this$store$getState$ = _this$store$getState.customColumns,
          customColumns = _this$store$getState$ === void 0 ? [] : _this$store$getState$;

      _this.setCustomState(customColumns);

      if (onCustomColumnFilter) {
        onCustomColumnFilter(customColumns);
      }
    };

    _this.handleShowSizeChange = function (current, pageSize) {
      var pagination = _this.state.pagination;
      pagination.onShowSizeChange(current, pageSize);
      var nextPagination = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, pagination), {}, {
        pageSize: pageSize,
        current: current
      });

      _this.setState({
        pagination: nextPagination
      });

      var onChange = _this.props.onChange;

      if (onChange) {
        onChange.apply(void 0, (0, _toConsumableArray2["default"])(_this.prepareParamsArguments((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, _this.state), {}, {
          pagination: nextPagination
        }))));
      }
    };

    _this.handleResize = function (col) {
      return function (_, dragCallbackData) {
        var columnAdjust = _this.state.columnAdjust;

        var _this$store$getState2 = _this.store.getState(),
            scroll = _this$store$getState2.scroll;

        var c = _this.columns.find(function (column) {
          return column.key === col.key || column.dataIndex === col.dataIndex;
        });

        if (c) {
          var width = c.width + dragCallbackData.x;
          var key = c.dataIndex;
          /**
           * 使用以前存储的拖动的宽度值
           */

          if (columnAdjust && key && columnAdjust[key] && typeof columnAdjust[key] === 'number' && columnAdjust[key] >= 50) {
            width = columnAdjust[key] + dragCallbackData.x;
          }

          if (width <= 50) {
            width = 50;
          }

          if (key) {
            columnAdjust[key] = width;

            if (scroll && scroll.x) {
              _this.store.setState({
                scroll: (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, scroll), {}, {
                  x: scroll.x + dragCallbackData.x
                })
              });
            }
          }

          _this.setState({
            columnAdjust: columnAdjust
          });
        }
      };
    };

    _this.getContentHeight = function () {
      var _assertThisInitialize2 = (0, _assertThisInitialized2["default"])(_this),
          refTable = _assertThisInitialize2.refTable,
          element = _assertThisInitialize2.element,
          autoHeight = _assertThisInitialize2.props.autoHeight;

      if (autoHeight && refTable && refTable.parentNode) {
        var _refTable$parentNode$ = refTable.parentNode.getBoundingClientRect(),
            parentTop = _refTable$parentNode$.top,
            parentHeight = _refTable$parentNode$.height;

        var _element$getBoundingC = element.getBoundingClientRect(),
            tableTop = _element$getBoundingC.top;

        var diff = 80;

        if (autoHeight && autoHeight !== true && (0, _util.isNumber)(autoHeight.diff)) {
          diff = autoHeight.diff || 80;
        }

        if (refTable) {
          return parentHeight - (tableTop - parentTop) - diff || 0;
        }
      }

      return 0;
    };

    _this.syncSize = function () {
      var _assertThisInitialize3 = (0, _assertThisInitialized2["default"])(_this),
          element = _assertThisInitialize3.element;

      if (element) {
        var prefixCls = _this.getPrefixCls();

        var height = _this.getContentHeight();

        if (element && (0, _util.isNumber)(height)) {
          var tableTitle = element.querySelector(".".concat(prefixCls, "-title"));
          var tableHeader = element.querySelector(".".concat(prefixCls, "-thead"));
          var tableFooter = element.querySelector(".".concat(prefixCls, "-footer"));
          var tableFootWrap = element.querySelector(".".concat(prefixCls, "-foot"));

          if (tableTitle) {
            height -= (0, _util.getHeight)(tableTitle);
          }

          if (tableHeader) {
            height -= (0, _util.getHeight)(tableHeader);
          }

          if (tableFooter) {
            height -= (0, _util.getHeight)(tableFooter);
          }

          if (tableFootWrap) {
            height -= (0, _util.getHeight)(tableFootWrap);
          }

          return height;
        }
      }

      return 0;
    };

    _this.renderTable = function (contextLocale, loading) {
      var _classNames2;

      var _assertThisInitialize4 = (0, _assertThisInitialized2["default"])(_this),
          props = _assertThisInitialize4.props;

      var locale = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, contextLocale), props.locale);
      var autoHeight = props.autoHeight,
          tableBodyStyle = props.bodyStyle,
          showHeader = props.showHeader,
          empty = props.empty,
          scroll = props.scroll,
          resizable = props.resizable,
          restProps = (0, _objectWithoutProperties2["default"])(props, _excluded2);

      var prefixCls = _this.getPrefixCls();

      var data = _this.getCurrentPageData();

      var expandIconAsCell = props.expandedRowRender && props.expandIconAsCell !== false;
      var tableAutoHeight = _this.state.tableAutoHeight;

      var tableScroll = _this.store.getState().scroll;

      var bodyStyle = (0, _objectSpread4["default"])({}, tableBodyStyle);

      if (tableAutoHeight && tableAutoHeight > 0 && autoHeight) {
        if (autoHeight !== true && autoHeight.type === _interface.TableAutoHeightType.maxHeight) {
          bodyStyle = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, bodyStyle), {}, {
            maxHeight: tableAutoHeight
          });
        } else {
          bodyStyle = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, bodyStyle), {}, {
            height: tableAutoHeight
          });
        }
      }

      var classString = (0, _classnames["default"])((_classNames2 = {}, (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-").concat(props.size), true), (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-bordered"), props.bordered), (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-empty"), !data.length), (0, _defineProperty2["default"])(_classNames2, "".concat(prefixCls, "-without-column-header"), !showHeader), (0, _defineProperty2["default"])(_classNames2, 'resizable-table', resizable), _classNames2));

      var columns = _this.columns.concat(); // 为了不更改原先的 columns


      columns = _this.renderColumnsDropdown(columns, locale); // 先执行: renderColumnsDropDown, 可能会更改 columns 的 fixed 或者 数量

      columns = _this.renderCustomColumns(columns); // 改变了 columns, 依赖于 columns 的 fixed: left;

      columns = _this.renderRowSelection(columns, locale);
      columns = columns.map(function (column, i) {
        var newColumn = (0, _objectSpread4["default"])({}, column);
        newColumn.key = _this.getColumnKey(newColumn, i);
        return newColumn;
      });
      columns = (0, _util.removeHiddenColumns)(columns);
      var expandIconColumnIndex = 'expandIconColumnIndex' in restProps ? restProps.expandIconColumnIndex : columns[0] && columns[0].key === 'selection-column' ? 1 : 0;

      if (resizable) {
        var _this$state$columnAdj = _this.state.columnAdjust,
            columnAdjust = _this$state$columnAdj === void 0 ? {} : _this$state$columnAdj;
        var keys = Object.keys(columnAdjust);
        columns = columns.map(function (col) {
          var otherProp = {};
          var colWidth = col.width;

          if (typeof colWidth === 'number') {
            var key = col.dataIndex;

            if (key && keys.indexOf(key) !== -1) {
              otherProp.width = columnAdjust[key];
            }
          }

          return (0, _objectSpread4["default"])((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, col), otherProp), {}, {
            onCell: function onCell(record, _col) {
              var _mCol = _col || col;

              var cellProps = {};

              if (col.onCell) {
                cellProps = col.onCell(record) || {};
              }

              cellProps = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, cellProps), {}, {
                style: (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, cellProps.style || {}), {}, {
                  maxWidth: _mCol.width,
                  minWidth: _mCol.width
                })
              });
              return cellProps;
            },
            onHeaderCell: function onHeaderCell(column) {
              var headerCellProps = {};

              if (col.onHeaderCell) {
                headerCellProps = col.onHeaderCell(column) || {};
              }

              headerCellProps = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, headerCellProps), {}, {
                width: column.width,
                style: (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, headerCellProps.style || {}), {}, {
                  maxWidth: col.width,
                  minWidth: col.width
                }),
                onResize: _this.handleResize(col)
              });
              return headerCellProps;
            }
          });
        });
      }

      var omits = ['style', 'filterBarMultiple', 'filterBarPlaceholder', 'filterBar', 'dataSource', 'filters'];
      return /*#__PURE__*/_react["default"].createElement(_table["default"], (0, _extends2["default"])({
        key: "table"
      }, (0, _omit["default"])(restProps, omits), {
        ref: _this.setElementRef,
        scroll: tableScroll || scroll,
        resizable: resizable,
        onRow: _this.onRow,
        components: _this.components,
        prefixCls: prefixCls,
        data: data,
        bodyStyle: bodyStyle,
        columns: columns,
        showHeader: showHeader,
        className: classString,
        expandIconColumnIndex: expandIconColumnIndex,
        expandIconAsCell: expandIconAsCell,
        emptyText: !loading.spinning && (empty || locale.emptyText)
      }));
    };

    _this.renderExportButton = function (props) {
      var dataParam = props.dataParam,
          method = props.method,
          action = props.action;

      _this.store.setState({
        exportStoreProps: props
      });

      if (!dataParam) {
        dataParam = {};
      }

      if (!method) {
        method = 'get';
      }

      if (!action) {
        action = '';
      }

      var exportProps = {
        dataParam: dataParam,
        method: method,
        action: action
      };

      var onClick = function onClick() {
        _this.handleExport(exportProps);
      };

      var buttonProps = _this.props.buttonProps;
      return /*#__PURE__*/_react["default"].createElement(_button["default"], (0, _extends2["default"])({}, buttonProps, {
        type: "primary",
        disabled: _this.store.getState().exported,
        loading: _this.store.getState().exported
      }, props, {
        onClick: onClick
      }));
    };

    _this.handleExport = function (exportedProps) {
      var dataParam = exportedProps.dataParam,
          method = exportedProps.method,
          action = exportedProps.action;

      var _assertThisInitialize5 = (0, _assertThisInitialized2["default"])(_this),
          iframe = _assertThisInitialize5.iframe;

      var exportStoreProps = _this.store.getState().exportStoreProps;

      if (exportStoreProps && exportStoreProps.onClick && typeof exportStoreProps.onClick === 'function') {
        exportStoreProps.onClick(exportedProps);
      } else {
        if (!iframe) {
          iframe = document.createElement('iframe');
          iframe.id = '_export_window';
          iframe.name = '_export_window';
          iframe.style.cssText = 'position:absolute;left:-10000px;top:-10000px;width:1px;height:1px;display:none';
          document.body.appendChild(iframe);
        }

        _this.store.setState({
          exported: true
        });

        var form = document.createElement('form');
        form.target = '_export_window';
        form.method = method;
        form.action = action;
        var s = document.createElement('input');
        s.id = '_request_data';
        s.type = 'hidden';
        s.name = '_request_data';
        s.value = JSON.stringify(dataParam);
        form.appendChild(s);
        document.body.appendChild(form);
        form.submit();
        document.body.removeChild(form);

        _this.store.setState({
          exported: false
        });
      }
    };

    (0, _warning["default"])(!('columnsPageRange' in props || 'columnsPageSize' in props), '`columnsPageRange` and `columnsPageSize` are removed, please use fixed columns instead');
    _this.columns = props.columns || (0, _util.normalizeColumns)(props.children);

    _this.createComponents(props.components);

    var customColumns = _this.getCustomColumns() || [];
    _this.state = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, _this.getDefaultSortOrder(_this.columns)), {}, {
      // 减少状态
      filters: _this.getFiltersFromColumns(),
      barFilters: props.filters || [],
      pagination: _this.getDefaultPagination(props),
      columnAdjust: {},
      customColumns: customColumns,
      tableAutoHeight: 0
    });
    _this.CheckboxPropsCache = {};
    _this.store = (0, _createStore["default"])({
      selectedRowKeys: getRowSelection(props).selectedRowKeys || [],
      selectionDirty: false,
      customColumns: customColumns,
      exported: false,
      exportStoreProps: undefined,
      scroll: props.scroll
    });
    return _this;
  }

  (0, _createClass2["default"])(Table, [{
    key: "getPrefixCls",
    value: function getPrefixCls() {
      var prefixCls = this.props.prefixCls;
      var context = this.context;
      return context.getPrefixCls('table', prefixCls);
    }
  }, {
    key: "getDefaultSelection",
    value: function getDefaultSelection() {
      var _this2 = this;

      var rowSelection = getRowSelection(this.props);

      if (!rowSelection.getCheckboxProps) {
        return [];
      }

      return this.getFlatData().filter(function (item, rowIndex) {
        return _this2.getCheckboxPropsByItem(item, rowIndex).defaultChecked;
      }).map(function (record, rowIndex) {
        return _this2.getRecordKey(record, rowIndex);
      });
    }
  }, {
    key: "getDefaultPagination",
    value: function getDefaultPagination(props) {
      var pagination = props.pagination || {};
      return this.hasPagination(props) ? (0, _objectSpread4["default"])((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, defaultPagination), {}, {
        size: props.size
      }, pagination), {}, {
        current: pagination.defaultCurrent || pagination.current || 1,
        pageSize: pagination.defaultPageSize || pagination.pageSize || 10
      }) : {};
    }
  }, {
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(nextProps) {
      this.columns = nextProps.columns || (0, _util.normalizeColumns)(nextProps.children);

      if ('pagination' in nextProps || 'pagination' in this.props) {
        this.setState(function (previousState) {
          var newPagination = (0, _objectSpread4["default"])((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, defaultPagination), {}, {
            size: nextProps.size
          }, previousState.pagination), nextProps.pagination);
          newPagination.current = newPagination.current || 1;
          newPagination.pageSize = newPagination.pageSize || 10;
          return {
            pagination: nextProps.pagination !== false ? newPagination : emptyObject
          };
        });
      }

      var _this$props3 = this.props,
          dataSource = _this$props3.dataSource,
          scroll = _this$props3.scroll,
          components = _this$props3.components;
      var _this$state = this.state,
          filters = _this$state.filters,
          sortColumn = _this$state.sortColumn,
          sortOrder = _this$state.sortOrder;

      if (nextProps.rowSelection && 'selectedRowKeys' in nextProps.rowSelection) {
        this.store.setState({
          selectedRowKeys: nextProps.rowSelection.selectedRowKeys || []
        });
      }

      if ('dataSource' in nextProps && nextProps.dataSource !== dataSource) {
        this.store.setState({
          selectionDirty: false
        });
      }

      if ('scroll' in nextProps && !(0, _isEqual["default"])(nextProps.scroll, scroll)) {
        var tableScroll = this.store.getState().scroll;
        this.store.setState({
          scroll: (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, tableScroll), nextProps.scroll)
        });
      } // https://github.com/ant-design/ant-design/issues/10133


      this.CheckboxPropsCache = {};

      if (this.getSortOrderColumns(this.columns).length > 0) {
        var sortState = this.getSortStateFromColumns(this.columns);

        if (sortState.sortColumn !== sortColumn || sortState.sortOrder !== sortOrder) {
          this.setState(sortState);
        }
      }

      var filteredValueColumns = this.getFilteredValueColumns(this.columns);

      if (filteredValueColumns.length > 0) {
        var filtersFromColumns = this.getFiltersFromColumns(this.columns);
        var newFilters = (0, _objectSpread4["default"])({}, filters);
        Object.keys(filtersFromColumns).forEach(function (key) {
          newFilters[key] = filtersFromColumns[key];
        });

        if (this.isFiltersChanged(newFilters)) {
          this.setState({
            filters: newFilters
          });
        }
      }

      if ('filters' in nextProps) {
        this.setState({
          barFilters: nextProps.filters || []
        });
      }

      this.createComponents(nextProps.components, components);
    }
  }, {
    key: "setSelectedRowKeys",
    value: function setSelectedRowKeys(selectedRowKeys, selectionInfo, selectedRows) {
      var _this3 = this;

      var selectWay = selectionInfo.selectWay,
          record = selectionInfo.record,
          checked = selectionInfo.checked,
          changeRowKeys = selectionInfo.changeRowKeys,
          nativeEvent = selectionInfo.nativeEvent;
      var rowSelection = getRowSelection(this.props);

      if (rowSelection && !('selectedRowKeys' in rowSelection)) {
        this.store.setState({
          selectedRowKeys: selectedRowKeys
        });
      }

      if (!rowSelection.onChange && !rowSelection[selectWay]) {
        return;
      }

      var data = this.getFlatData();
      selectedRows = selectedRows || data.filter(function (row, i) {
        return selectedRowKeys.indexOf(_this3.getRecordKey(row, i)) >= 0;
      });

      if (rowSelection.onChange) {
        rowSelection.onChange(selectedRowKeys, selectedRows);
      }

      if (selectWay === 'onSelect' && rowSelection.onSelect) {
        rowSelection.onSelect(record, checked, selectedRows, nativeEvent);
      } else if (selectWay === 'onSelectAll' && rowSelection.onSelectAll) {
        var changeRows = data.filter(function (row, i) {
          return changeRowKeys.indexOf(_this3.getRecordKey(row, i)) >= 0;
        });
        rowSelection.onSelectAll(checked, selectedRows, changeRows);
      } else if (selectWay === 'onSelectInvert' && rowSelection.onSelectInvert) {
        rowSelection.onSelectInvert(selectedRowKeys);
      }
    }
  }, {
    key: "hasPagination",
    value: function hasPagination(props) {
      return (props || this.props).pagination !== false;
    }
  }, {
    key: "isFiltersChanged",
    value: function isFiltersChanged(filters) {
      var filtersChanged = false;
      var stateFilters = this.state.filters;

      if (Object.keys(filters).length !== Object.keys(stateFilters).length) {
        filtersChanged = true;
      } else {
        Object.keys(filters).forEach(function (columnKey) {
          if (filters[columnKey] !== stateFilters[columnKey]) {
            filtersChanged = true;
          }
        });
      }

      return filtersChanged;
    }
  }, {
    key: "getSortOrderColumns",
    value: function getSortOrderColumns(columns) {
      return (0, _util.flatFilter)(columns || this.columns || [], function (column) {
        return 'sortOrder' in column;
      });
    }
  }, {
    key: "getFilteredValueColumns",
    value: function getFilteredValueColumns(columns) {
      return (0, _util.flatFilter)(columns || this.columns || [], function (column) {
        return typeof column.filteredValue !== 'undefined';
      });
    }
  }, {
    key: "getFiltersFromColumns",
    value: function getFiltersFromColumns(columns) {
      var _this4 = this;

      var filters = {};
      this.getFilteredValueColumns(columns).forEach(function (col) {
        var colKey = _this4.getColumnKey(col);

        filters[colKey] = col.filteredValue;
      });
      return filters;
    }
  }, {
    key: "getDefaultSortOrder",
    value: function getDefaultSortOrder(columns) {
      var definedSortState = this.getSortStateFromColumns(columns);
      var defaultSortedColumn = (0, _util.flatFilter)(columns || [], function (column) {
        return column.defaultSortOrder != null;
      })[0];

      if (defaultSortedColumn && !definedSortState.sortColumn) {
        return {
          sortColumn: defaultSortedColumn,
          sortOrder: defaultSortedColumn.defaultSortOrder
        };
      }

      return definedSortState;
    }
  }, {
    key: "getSortStateFromColumns",
    value: function getSortStateFromColumns(columns) {
      // return first column which sortOrder is not falsy
      var sortedColumn = this.getSortOrderColumns(columns).find(function (col) {
        return col.sortOrder;
      });

      if (sortedColumn) {
        return {
          sortColumn: sortedColumn,
          sortOrder: sortedColumn.sortOrder
        };
      }

      return {
        sortColumn: null,
        sortOrder: null
      };
    }
  }, {
    key: "getSorterFn",
    value: function getSorterFn() {
      var _this$state2 = this.state,
          sortOrder = _this$state2.sortOrder,
          sortColumn = _this$state2.sortColumn;

      if (!sortOrder || !sortColumn || typeof sortColumn.sorter !== 'function') {
        return;
      }

      return function (a, b) {
        var result = sortColumn.sorter(a, b, sortOrder);

        if (result !== 0) {
          return sortOrder === 'descend' ? -result : result;
        }

        return 0;
      };
    }
  }, {
    key: "toggleSortOrder",
    value: function toggleSortOrder(order, column) {
      var _this$state3 = this.state,
          sortColumn = _this$state3.sortColumn,
          sortOrder = _this$state3.sortOrder; // 只同时允许一列进行排序，否则会导致排序顺序的逻辑问题

      var isSortColumn = this.isSortColumn(column);

      if (!isSortColumn) {
        // 当前列未排序
        sortOrder = order;
        sortColumn = column;
      } else if (sortOrder === order) {
        // 切换为未排序状态
        sortOrder = undefined;
        sortColumn = null;
      } else {
        // 切换为排序状态
        sortOrder = order;
      }

      var newState = {
        sortOrder: sortOrder,
        sortColumn: sortColumn
      }; // Controlled

      if (this.getSortOrderColumns().length === 0) {
        this.setState(newState);
      }

      var onChange = this.props.onChange;

      if (onChange) {
        onChange.apply(void 0, (0, _toConsumableArray2["default"])(this.prepareParamsArguments((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, this.state), newState))));
      }
    }
  }, {
    key: "setNewFilterState",
    value: function setNewFilterState(newState) {
      var _this5 = this;

      var _this$props4 = this.props,
          propsPagination = _this$props4.pagination,
          onChange = _this$props4.onChange;
      var statePagination = this.state.pagination;
      var pagination = (0, _objectSpread4["default"])({}, statePagination);

      if (propsPagination) {
        // Reset current prop
        pagination.current = 1;
        pagination.onChange(pagination.current);
      }

      var filtersToSetState = (0, _objectSpread4["default"])({}, newState.filters); // Remove filters which is controlled

      this.getFilteredValueColumns().forEach(function (col) {
        var columnKey = _this5.getColumnKey(col);

        if (columnKey) {
          delete filtersToSetState[columnKey];
        }
      });

      if (Object.keys(filtersToSetState).length > 0) {
        newState.filters = filtersToSetState;
      } // Controlled current prop will not respond user interaction


      if ((0, _typeof2["default"])(propsPagination) === 'object' && 'current' in propsPagination) {
        newState.pagination = (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, pagination), {}, {
          current: statePagination.current
        });
      }

      this.setState(newState, function () {
        _this5.store.setState({
          selectionDirty: false
        });

        if (onChange) {
          onChange.apply(void 0, (0, _toConsumableArray2["default"])(_this5.prepareParamsArguments((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, _this5.state), {}, {
            pagination: pagination
          }))));
        }
      });
    }
  }, {
    key: "getSelectedRows",
    value: function getSelectedRows(_) {
      return undefined;
    }
  }, {
    key: "renderRowSelection",
    value: function renderRowSelection(columns, locale) {
      var _this6 = this;

      var _this$props5 = this.props,
          rowSelection = _this$props5.rowSelection,
          dropdownProps = _this$props5.dropdownProps,
          menuProps = _this$props5.menuProps,
          checkboxPrefixCls = _this$props5.checkboxPrefixCls;
      var prefixCls = this.getPrefixCls();

      if (rowSelection) {
        var data = this.getFlatCurrentPageData().filter(function (item, index) {
          if (rowSelection.getCheckboxProps) {
            return !_this6.getCheckboxPropsByItem(item, index).disabled;
          }

          return true;
        });
        var selectionColumnClass = (0, _classnames["default"])("".concat(prefixCls, "-selection-column"), (0, _defineProperty2["default"])({}, "".concat(prefixCls, "-selection-column-custom"), rowSelection.selections));
        var selectionColumn = {
          key: 'selection-column',
          render: this.renderSelectionBox(rowSelection.type),
          className: selectionColumnClass,
          fixed: rowSelection.fixed,
          width: (0, _defaultTo["default"])(rowSelection.columnWidth, 50)
        };

        if (rowSelection.type !== 'radio') {
          var checkboxAllDisabled = data.every(function (item, index) {
            return _this6.getCheckboxPropsByItem(item, index).disabled;
          });
          selectionColumn.title = /*#__PURE__*/_react["default"].createElement(_SelectionCheckboxAll["default"], {
            checkboxPrefixCls: checkboxPrefixCls,
            dropdownProps: dropdownProps,
            menuProps: menuProps,
            store: this.store,
            locale: locale,
            data: data,
            getCheckboxPropsByItem: this.getCheckboxPropsByItem,
            getRecordKey: this.getRecordKey,
            disabled: checkboxAllDisabled,
            prefixCls: prefixCls,
            onSelect: this.handleSelectRow,
            selections: rowSelection.selections,
            hideDefaultSelections: rowSelection.hideDefaultSelections,
            getPopupContainer: this.getPopupContainer
          });
        }

        if ('fixed' in rowSelection) {
          selectionColumn.fixed = rowSelection.fixed;
        } else if (columns.some(function (column) {
          return column.fixed === 'left' || column.fixed === true;
        })) {
          selectionColumn.fixed = 'left';
        }

        if (columns[0] && columns[0].key === 'selection-column') {
          columns[0] = selectionColumn;
        } else {
          columns.unshift(selectionColumn);
        }
      }

      return columns;
    }
  }, {
    key: "getColumnKey",
    value: function getColumnKey(column, index) {
      return (0, _util.getColumnKey)(column, index);
    }
  }, {
    key: "getMaxCurrent",
    value: function getMaxCurrent(total) {
      var _this$state$paginatio = this.state.pagination,
          current = _this$state$paginatio.current,
          pageSize = _this$state$paginatio.pageSize;

      if ((current - 1) * pageSize >= total) {
        return Math.floor((total - 1) / pageSize) + 1;
      }

      return current;
    }
  }, {
    key: "isSortColumn",
    value: function isSortColumn(column) {
      var sortColumn = this.state.sortColumn;

      if (!column || !sortColumn) {
        return false;
      }

      return this.getColumnKey(sortColumn) === this.getColumnKey(column);
    }
  }, {
    key: "renderColumnsDropdown",
    value: function renderColumnsDropdown(columns, locale) {
      var _this7 = this;

      var _this$props6 = this.props,
          customizeDropdownPrefixCls = _this$props6.dropdownPrefixCls,
          radioPrefixCls = _this$props6.radioPrefixCls,
          checkboxPrefixCls = _this$props6.checkboxPrefixCls,
          rippleDisabled = _this$props6.rippleDisabled,
          filterBar = _this$props6.filterBar,
          customCode = _this$props6.customCode,
          filterBarLocale = _this$props6.filterBarLocale,
          renderSorter = _this$props6.renderSorter,
          $dropdownProps = _this$props6.dropdownProps,
          inputNumberProps = _this$props6.inputNumberProps;
      var getPrefixCls = this.context.getPrefixCls;
      var prefixCls = this.getPrefixCls();
      var dropdownProps = (0, _objectSpread4["default"])({
        prefixCls: getPrefixCls('dropdown', customizeDropdownPrefixCls)
      }, $dropdownProps);
      var _this$state4 = this.state,
          sortOrder = _this$state4.sortOrder,
          filters = _this$state4.filters;
      return (0, _util.treeMap)(columns, function (originColumn, i) {
        var column = (0, _objectSpread4["default"])({}, originColumn);

        var key = _this7.getColumnKey(column, i);

        var filterDropdown;
        var sortButton;

        if (!filterBar && column.filters && column.filters.length > 0 || column.filterDropdown) {
          var colFilters = filters[key] || [];
          filterDropdown = /*#__PURE__*/_react["default"].createElement(_filterDropdown["default"], {
            locale: locale,
            column: column,
            selectedKeys: colFilters,
            confirmFilter: _this7.handleFilter,
            prefixCls: "".concat(prefixCls, "-filter"),
            dropdownProps: dropdownProps,
            radioPrefixCls: radioPrefixCls,
            checkboxPrefixCls: checkboxPrefixCls,
            rippleDisabled: rippleDisabled,
            getPopupContainer: _this7.getPopupContainer
          });
        }

        if (column.sorter) {
          var isSortColumn = _this7.isSortColumn(column);

          sortButton = renderSorter({
            prefixCls: prefixCls,
            column: column,
            sortOrder: sortOrder,
            isSortColumn: isSortColumn,
            changeOrder: function changeOrder(order) {
              return _this7.toggleSortOrder(order, column);
            }
          });
        }

        var customButton;

        if (column.filterBar === true && customCode) {
          var filterColumns = columns.filter(function (c) {
            return c.filterField === true;
          });
          customButton = /*#__PURE__*/_react["default"].createElement(_ColumnFilterMenu["default"], {
            customCode: customCode,
            locale: locale,
            filterBarLocale: filterBarLocale,
            customColumns: _this7.getCustomColumns(),
            store: _this7.store,
            columns: filterColumns,
            prefixCls: "".concat(prefixCls, "-filter"),
            dropdownProps: dropdownProps,
            checkboxPrefixCls: checkboxPrefixCls,
            inputNumberProps: inputNumberProps,
            confirmFilter: _this7.handleCustomColumnFilter,
            getPopupContainer: _this7.getPopupContainer
          });
        }

        column.title = /*#__PURE__*/_react["default"].createElement("span", {
          key: key
        }, column.title, sortButton, customButton, filterDropdown);

        if (sortButton || filterDropdown || customButton) {
          column.className = (0, _classnames["default"])("".concat(prefixCls, "-column-has-filters"), column.className);
        }

        return column;
      });
    }
  }, {
    key: "setCustomState",
    value: function setCustomState(customColumns) {
      this.setState({
        customColumns: customColumns
      });
    }
    /**
     * 获取用户个性化的 Table 的 头设置
     * table's columns
     */

  }, {
    key: "getCustomColumns",
    value: function getCustomColumns() {
      var _this$props7 = this.props,
          customColumns = _this$props7.customColumns,
          defaultCustomColumns = _this$props7.defaultCustomColumns,
          onCustomColumnFilter = _this$props7.onCustomColumnFilter;

      if (customColumns) {
        if (defaultCustomColumns) {
          throw new Error('Table Can\'t set customColumns and defaultCustomColumns together');
        }

        if (!onCustomColumnFilter) {
          throw new Error('Table must set customColumns and onCustomColumnFilter together');
        }
      }

      if (customColumns) {
        return customColumns;
      }

      if (defaultCustomColumns) {
        var _this$state$customCol = this.state.customColumns,
            stateCustomColumns = _this$state$customCol === void 0 ? defaultCustomColumns : _this$state$customCol;
        return stateCustomColumns;
      }
    }
  }, {
    key: "renderPagination",
    value: function renderPagination(paginationPosition) {
      // 强制不需要分页
      if (!this.hasPagination()) {
        return null;
      }

      var pagination = this.state.pagination;
      var _this$props8 = this.props,
          size = _this$props8.size,
          paginationProps = _this$props8.paginationProps;
      var getConfig = this.context.getConfig;
      var prefixCls = this.getPrefixCls();
      var position = pagination.position || 'bottom';
      var total = pagination.total || this.getLocalData().length;
      var configPaginationProps = getConfig('pagination');
      return total > 0 && (position === paginationPosition || position === 'both') ? /*#__PURE__*/_react["default"].createElement(_pagination["default"], (0, _extends2["default"])({}, configPaginationProps, paginationProps, {
        key: "pagination-".concat(paginationPosition)
      }, pagination, {
        className: (0, _classnames["default"])(pagination.className, "".concat(prefixCls, "-pagination")),
        onChange: this.handlePageChange,
        total: total,
        size: pagination.size || (size === 'middle' ? _enum.Size.small : size),
        current: this.getMaxCurrent(total),
        onShowSizeChange: this.handleShowSizeChange
      })) : null;
    } // Get pagination, filters, sorter

  }, {
    key: "prepareParamsArguments",
    value: function prepareParamsArguments(state) {
      var pagination = (0, _objectSpread4["default"])({}, state.pagination); // remove useless handle function in Table.onChange

      delete pagination.onChange;
      delete pagination.onShowSizeChange;
      delete pagination.showTotal;
      delete pagination.sizeChangerOptionText;
      var filters = state.filters;
      var barFilters = state.barFilters;
      var sorter = {};
      var sortColumn = state.sortColumn,
          sortOrder = state.sortOrder;

      if (sortColumn && sortOrder) {
        sorter.column = sortColumn;
        sorter.order = sortOrder;
        sorter.field = sortColumn.dataIndex;
        sorter.columnKey = this.getColumnKey(sortColumn);
      }

      return [pagination, filters, sorter, barFilters];
    }
  }, {
    key: "findColumn",
    value: function findColumn(myKey) {
      var _this8 = this;

      var column;
      (0, _util.treeMap)(this.columns, function (c) {
        if (_this8.getColumnKey(c) === myKey) {
          column = c;
        }
      });
      return column;
    }
  }, {
    key: "componentDidMount",
    value: function componentDidMount() {
      var autoHeight = this.props.autoHeight;

      if (autoHeight) {
        var tableAutoHeight = this.syncSize();
        var stateTableAutoHeight = this.state.tableAutoHeight;

        if (stateTableAutoHeight !== tableAutoHeight) {
          var tableScroll = this.store.getState().scroll;
          this.store.setState({
            scroll: (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, tableScroll), {}, {
              y: tableAutoHeight
            })
          });
          this.setState({
            tableAutoHeight: tableAutoHeight
          });
        }
      }

      if (this.element) {
        var prefixCls = this.getPrefixCls();
        var isMac = /macintosh|mac os x/i.test(navigator.userAgent);

        if (isMac) {
          (0, _componentClasses["default"])(this.element).add("".concat(prefixCls, "-os-mac"));
        } else {
          (0, _componentClasses["default"])(this.element).add("".concat(prefixCls, "-os-win"));
        }
      }
    }
  }, {
    key: "getCurrentPageData",
    value: function getCurrentPageData() {
      var data = this.getLocalData();
      var current;
      var pageSize;
      var state = this.state; // 如果没有分页的话，默认全部展示

      if (!this.hasPagination()) {
        pageSize = Number.MAX_VALUE;
        current = 1;
      } else {
        pageSize = state.pagination.pageSize;
        current = this.getMaxCurrent(state.pagination.total || data.length);
      } // 分页
      // ---
      // 当数据量少于等于每页数量时，直接设置数据
      // 否则进行读取分页数据


      if (data.length > pageSize || pageSize === Number.MAX_VALUE) {
        data = data.filter(function (_, i) {
          return i >= (current - 1) * pageSize && i < current * pageSize;
        });
      }

      return data;
    }
  }, {
    key: "getFlatData",
    value: function getFlatData() {
      var childrenColumnName = this.props.childrenColumnName;
      return (0, _util.flatArray)(this.getLocalData(), childrenColumnName);
    }
  }, {
    key: "getFlatCurrentPageData",
    value: function getFlatCurrentPageData() {
      var childrenColumnName = this.props.childrenColumnName;
      return (0, _util.flatArray)(this.getCurrentPageData(), childrenColumnName);
    }
  }, {
    key: "recursiveSort",
    value: function recursiveSort(data, sorterFn) {
      var _this9 = this;

      var _this$props$childrenC = this.props.childrenColumnName,
          childrenColumnName = _this$props$childrenC === void 0 ? 'children' : _this$props$childrenC;
      return data.sort(sorterFn).map(function (item) {
        return item[childrenColumnName] ? (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, item), {}, (0, _defineProperty2["default"])({}, childrenColumnName, _this9.recursiveSort(item[childrenColumnName], sorterFn))) : item;
      });
    }
  }, {
    key: "getLocalData",
    value: function getLocalData() {
      var _this10 = this;

      var _this$props9 = this.props,
          dataSource = _this$props9.dataSource,
          noFilter = _this$props9.noFilter;

      if (dataSource) {
        var state = this.state;
        var filters = state.filters,
            barFilters = state.barFilters;
        var data = dataSource; // 优化本地排序

        data = data.slice(0);
        var sorterFn = this.getSorterFn();

        if (sorterFn) {
          data = this.recursiveSort(data, sorterFn);
        }

        if (noFilter) {
          return data;
        }

        var filteredData = data; // 筛选

        if (filters) {
          Object.keys(filters).forEach(function (columnKey) {
            var col = _this10.findColumn(columnKey);

            if (!col) {
              return;
            }

            var values = filters[columnKey] || [];

            if (values.length === 0) {
              return;
            }

            var onFilter = col.onFilter,
                columnFilters = col.filters;
            filteredData = onFilter ? filteredData.filter(function (record) {
              return values.some(function (v) {
                return onFilter(v, record, columnFilters);
              });
            }) : filteredData;
          });
        }

        if (barFilters.length) {
          var isOr = false;
          barFilters.forEach(function (filter) {
            if (filter === _FilterSelect.VALUE_OR) {
              isOr = true;
            } else {
              filteredData = data.filter(function (record) {
                return isOr ? filteredData.indexOf(record) !== -1 || _this10.doBarFilter(filter, record) : filteredData.indexOf(record) !== -1 && _this10.doBarFilter(filter, record);
              });
              isOr = false;
            }
          });
        }

        return filteredData;
      }

      return [];
    }
  }, {
    key: "doBarFilter",
    value: function doBarFilter(filter, record) {
      if (typeof filter === 'string') {
        return !!(0, _util.findColumnByFilterValue)(record, (0, _util.getLeafColumns)(this.columns), filter);
      }

      var columnKey = Object.keys(filter)[0];
      var col = this.findColumn(columnKey);

      if (!col) {
        return true;
      }

      var onFilter = col.onFilter,
          filters = col.filters;
      return !onFilter || onFilter(filter[columnKey], record, filters);
    }
  }, {
    key: "createComponents",
    value: function createComponents() {
      var components = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var prevComponents = arguments.length > 1 ? arguments[1] : undefined;
      var bodyRow = components && components.body && components.body.row;
      var preBodyRow = prevComponents && prevComponents.body && prevComponents.body.row;

      if (!this.row || bodyRow !== preBodyRow) {
        this.row = (0, _createBodyRow["default"])(bodyRow);
      }

      var headerProps = {};
      var resizable = this.props.resizable;

      if (resizable) {
        headerProps.header = {
          cell: ResizeableTitle
        };
      }

      this.components = (0, _objectSpread4["default"])((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, headerProps), components), {}, {
        body: (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, components.body), {}, {
          row: this.row
        })
      });
    }
  }, {
    key: "renderConfigConsumer",
    value: function renderConfigConsumer() {
      var exported = this.props.exported;

      if (exported) {
        return this.renderExportButton(exported);
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this11 = this;

      var props = this.props;
      var style = props.style,
          className = props.className,
          spinPrefixCls = props.spinPrefixCls,
          filterBarMultiple = props.filterBarMultiple,
          filterBarPlaceholder = props.filterBarPlaceholder,
          filterBar = props.filterBar,
          dataSource = props.dataSource,
          filters = props.filters;
      var columnFilters = this.state.filters;
      var prefixCls = this.getPrefixCls();
      var data = this.getCurrentPageData();
      var loading = props.loading;

      if (typeof loading === 'boolean') {
        loading = {
          spinning: loading
        };
      }

      var table = /*#__PURE__*/_react["default"].createElement(_LocaleReceiver["default"], {
        componentName: "Table",
        defaultLocale: _default["default"].Table
      }, function (locale) {
        return _this11.renderTable(locale, loading);
      }); // if there is no pagination or no data,
      // the height of spin should decrease by half of pagination


      var paginationPatchClass = this.hasPagination() && data && data.length !== 0 ? "".concat(prefixCls, "-with-pagination") : "".concat(prefixCls, "-without-pagination");

      var bar = filterBar && /*#__PURE__*/_react["default"].createElement(_FilterBar["default"], {
        key: "filter-bar",
        prefixCls: prefixCls,
        placeholder: filterBarPlaceholder,
        columns: (0, _util.getLeafColumns)(this.columns),
        onFilterSelectChange: this.handleFilterSelectChange,
        onFilterSelectClear: this.handleFilterSelectClear,
        onColumnFilterChange: this.handleColumnFilterChange,
        onFilter: this.handleFilter,
        dataSource: dataSource,
        filters: filters,
        columnFilters: columnFilters,
        multiple: filterBarMultiple,
        getPopupContainer: this.getPopupContainer
      });

      return /*#__PURE__*/_react["default"].createElement("div", {
        className: (0, _classnames["default"])("".concat(prefixCls, "-wrapper"), className),
        style: style,
        ref: this.saveRef
      }, /*#__PURE__*/_react["default"].createElement(_spin["default"], (0, _extends2["default"])({
        prefixCls: spinPrefixCls
      }, loading, {
        className: loading.spinning ? "".concat(paginationPatchClass, " ").concat(prefixCls, "-spin-holder") : ''
      }), this.renderPagination('top'), this.renderConfigConsumer(), bar, table, this.renderPagination('bottom')));
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _ConfigContext["default"];
    }
  }]);
  return Table;
}(_react.Component);

exports["default"] = Table;
Table.displayName = 'Table';
Table.TableRowContext = _util.TableRowContext;
Table.Column = _Column["default"];
Table.ColumnGroup = _ColumnGroup["default"];
Table.defaultProps = {
  dataSource: [],
  empty: null,
  useFixedHeader: false,
  rowSelection: null,
  className: '',
  size: _enum.Size["default"],
  loading: false,
  bordered: false,
  resizable: false,
  indentSize: 20,
  locale: {},
  rowKey: 'key',
  showHeader: true,
  autoHeight: false,
  filterBar: true,
  noFilter: false,
  autoScroll: true,
  renderSorter: defaultRenderSorter
};
//# sourceMappingURL=Table.js.map
