"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});

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

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

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

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

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

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

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

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

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

var _inherits3 = _interopRequireDefault(_inherits2);

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

var _extends3 = _interopRequireDefault(_extends2);

var _slicedToArray2 = require("babel-runtime/helpers/slicedToArray");

var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

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

var _table = require("antd/lib/table");

var _table2 = _interopRequireDefault(_table);

var _cloneDeep = require("lodash/cloneDeep");

var _cloneDeep2 = _interopRequireDefault(_cloneDeep);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactResizable = require("react-resizable");

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

var _isEqual2 = _interopRequireDefault(_isEqual);

var _isFunction = require("lodash/isFunction");

var _isFunction2 = _interopRequireDefault(_isFunction);

var _get = require("lodash/get");

var _get2 = _interopRequireDefault(_get);

var _dragTable = require("./dragTable");

var _reactDnd = require("react-dnd");

var _reactDndHtml5Backend = require("react-dnd-html5-backend");

var _editCell = require("./editCell");

var _editRow = require("./editRow");

var _immutabilityHelper = require("immutability-helper");

var _immutabilityHelper2 = _interopRequireDefault(_immutabilityHelper);

var _pagePointEnhanced = require("../page-point/pagePointEnhanced");

var _pagePointEnhanced2 = _interopRequireDefault(_pagePointEnhanced);

var _index = require("../page-point/index");

var _index2 = _interopRequireDefault(_index);

var _configProvider = require("../config-provider");

var _message = require("../message");

var _message2 = _interopRequireDefault(_message);

var _Column = require("antd/lib/table/Column");

var _Column2 = _interopRequireDefault(_Column);

require("antd/lib/table/style");

require("@whalecloud/fdx-theme-fdx/table.less");

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

var __rest = undefined && undefined.__rest || function (s, e) {
    var t = {};
    for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
    }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
        if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
    }
    return t;
};

var DEFAULT_COLUMN_WIDTH = 100;
var DEFAULT_COLUMN_EDITTYPE = "text";
var DEFAULT_COLUMN_OPTIONS_LABEL = "name";
var DEFAULT_COLUMN_OPTIONS_VALUE = "value";
var DEFAULT_PAGE_SIZE = 10;
var sendPagePoint = _index2["default"].sendPagePoint,
    regKey = _index2["default"].pagePointConfig.regKey,
    clickType = _index2["default"].EventType.clickType;

var ResizeableTitle = function ResizeableTitle(props) {
    var onResize = props.onResize,
        width = props.width,
        _onClick = props.onClick,
        restProps = __rest(props, ["onResize", "width", "onClick"]);

    var _useState = (0, _react.useState)(false),
        _useState2 = (0, _slicedToArray3["default"])(_useState, 2),
        resizing = _useState2[0],
        setResizing = _useState2[1]; // 是否拖拽结束的标志


    return _react2["default"].createElement(
        _reactResizable.Resizable,
        { width: width, height: 0, onResizeStart: function onResizeStart() {
                return setResizing(true);
            }, onResizeStop: function onResizeStop() {
                setTimeout(function () {
                    setResizing(false);
                }, 0);
            }, onResize: onResize },
        _react2["default"].createElement("th", (0, _extends3["default"])({ onClick: function onClick() {
                if (!resizing && _onClick) {
                    _onClick.apply(undefined, arguments);
                }
            } }, restProps))
    );
};
// 动态为columnItem创建dataIndex(lowcode专用)
var handleColumns = function handleColumns(columns) {
    if (!columns) return columns;
    columns.forEach(function (column) {
        if (!column.dataIndex && column.render) {
            var render = column.render.toString();
            // 处理column没有dataIndex属性情况
            if (render.includes('createElement("span"')) {
                var matches = render.match(/createElement\(\"span\"[\s\S]*?\)/gi);
                var dataIndex = '';
                if (matches.length > 0) {
                    var dataIndexExpresses = matches[0].split(',');
                    if (dataIndexExpresses.length) {
                        var dataIndexExpress = dataIndexExpresses[dataIndexExpresses.length - 1];

                        var _dataIndexExpress$spl = dataIndexExpress.split('.'),
                            _dataIndexExpress$spl2 = (0, _slicedToArray3["default"])(_dataIndexExpress$spl, 2),
                            express = _dataIndexExpress$spl2[1];

                        if (express) {
                            dataIndex = express.replace(')', '');
                        }
                    }
                }
                if (dataIndex) {
                    column.dataIndex = dataIndex;
                }
            }
        }
    });
    return columns;
};
var caluColumnWidth = function caluColumnWidth(columns, tableWidth) {
    var someWidth = 0;
    var noWidthCnt = 0;
    var newColumns = columns.map(function (col) {
        var width = void 0;
        if (typeof col.width === "string") {
            if (col.width.includes("%")) {
                width = Math.floor(tableWidth * (parseInt(col.width.replace("%", "")) / 100));
            } else {
                width = +col.width;
            }
        } else if (typeof col.width === "number") {
            width = col.width;
        } else {
            width = 0;
            noWidthCnt++;
        }
        someWidth += width;
        return (0, _extends3["default"])((0, _extends3["default"])({}, col), { width: width });
    });
    if (noWidthCnt) {
        var restWidth = parseFloat(((tableWidth - someWidth) / noWidthCnt).toFixed(2));
        newColumns = newColumns.map(function (col) {
            if (!col.width) {
                col.width = restWidth;
            }
            return col;
        });
    }
    return newColumns;
};
// 根据value找到key(深度遍历)
var findKeyByValue = function findKeyByValue(value, obj) {
    var allKeys = {};
    var map = function map(mapObj, parentKey) {
        if (typeof mapObj === 'object' && !Array.isArray(mapObj)) {
            Object.keys(mapObj).forEach(function (key) {
                var realKey = key;
                var val = mapObj[key];
                if (parentKey) {
                    realKey = parentKey + "." + key;
                }
                allKeys[realKey] = val;
                if (val && typeof val === 'object') {
                    map(val, realKey);
                }
            });
        }
    };
    map(obj);
    var targetKey = Object.keys(allKeys).find(function (key) {
        return allKeys[key] === value;
    });
    return targetKey;
};

var Table = function (_Component) {
    (0, _inherits3["default"])(Table, _Component);

    function Table(props) {
        (0, _classCallCheck3["default"])(this, Table);

        var _a;

        var _this = (0, _possibleConstructorReturn3["default"])(this, (Table.__proto__ || Object.getPrototypeOf(Table)).call(this, props));

        _this.handleSave = function (row, type) {
            var _this$props = _this.props,
                rowKey = _this$props.rowKey,
                onSaveRowEdit = _this$props.onSaveRowEdit,
                onSaveCellEdit = _this$props.onSaveCellEdit,
                onCancelRowEdit = _this$props.onCancelRowEdit;
            var dataSource = _this.state.dataSource;

            var newData = [].concat((0, _toConsumableArray3["default"])(dataSource));
            var tableKey = '';
            if ((0, _isFunction2["default"])(rowKey)) {
                tableKey = findKeyByValue(rowKey(row), row);
            } else {
                tableKey = rowKey;
            }
            var index = newData.findIndex(function (item) {
                return (0, _get2["default"])(row, tableKey) === (0, _get2["default"])(item, tableKey);
            });
            if (index > -1) {
                var item = newData[index];
                newData.splice(index, 1, (0, _extends3["default"])((0, _extends3["default"])({}, item), row));
                _this.setState({ dataSource: newData, update: true });
            } else {
                // 新增功能
                newData.push(row);
                _this.setState({ dataSource: newData, update: true });
            }
            var dataRegId = _this.props[regKey];

            if (type === "save") {
                onSaveRowEdit(row, newData);
                if (dataRegId) sendPagePoint((0, _defineProperty3["default"])({
                    eventType: clickType,
                    tagname: "table",
                    value: row
                }, regKey, dataRegId));
            } else if (type === "cancel") {
                onCancelRowEdit(row);
            } else if (type === "saveCell") {
                onSaveCellEdit(newData[index], index);
            }
        };
        _this.moveRow = function (dragIndex, hoverIndex) {
            var dataSource = _this.state.dataSource;
            var afterRowDrag = _this.props.afterRowDrag;

            var dragRow = dataSource[dragIndex];
            /* eslint-disable */
            var dragData = (0, _immutabilityHelper2["default"])(dataSource, {
                $splice: [[dragIndex, 1], [hoverIndex, 0, dragRow]]
            });
            afterRowDrag(dragData);
            _this.setState({ dataSource: dragData, update: true });
        };
        _this.handleResize = function (index) {
            return function (_e, _ref) {
                var size = _ref.size;

                _this.setState(function (_ref2) {
                    var columns = _ref2.columns;

                    var nextColumns = [].concat((0, _toConsumableArray3["default"])(columns));
                    nextColumns[index] = (0, _extends3["default"])((0, _extends3["default"])({}, nextColumns[index]), { width: size.width });
                    return { columns: nextColumns, update: true };
                });
            };
        };
        _this.isEditing = function (record) {
            var rowKey = _this.props.rowKey;

            var key = (0, _isFunction2["default"])(rowKey) ? rowKey(record) : record[rowKey];
            var editingKey = _this.state.editingKey;

            return key === editingKey;
        };
        _this.toggleEditRow = function () {
            var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
            var record = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
            var method = arguments[2];
            var _this$props2 = _this.props,
                onRowEditing = _this$props2.onRowEditing,
                saveAddRowMsg = _this$props2.saveAddRowMsg;

            if (method === 'edit' && _this.state.freezAddRow) {
                _message2["default"].warn(saveAddRowMsg || '请先保存当前新增行！');
                return;
            }
            if (key) {
                onRowEditing(record);
            }
            _this.setState({ editingKey: key, update: true, freezAddRow: false });
        };
        _this.judgeCellEdit = function (columns) {
            return columns.some(function (item) {
                return item.editable === true;
            });
        };
        _this.selectRow = function (record) {
            _this.setState({ highlightRow: record, update: true });
        };
        _this.handleSelectRow = function (selectedRowKeys, selectedRows, onChange) {
            var onSelectRows = _this.props.onSelectRows;

            if (onChange) {
                onChange(selectedRowKeys, selectedRows);
            }
            if (onSelectRows) {
                onSelectRows(selectedRowKeys);
            }
        };
        _this.handleRowSelection = function (selection) {
            var selectType = _this.props.selectType;

            var rowSelection = typeof selection === 'boolean' ? {} : selection || {};
            if (selectType === 'radio') {
                rowSelection.type = selectType;
            }
            var newRowSelection = (0, _extends3["default"])((0, _extends3["default"])({}, rowSelection), { onChange: function onChange(selectedRowKeys, selectedRows) {
                    return _this.handleSelectRow(selectedRowKeys, selectedRows, rowSelection.onChange);
                } });
            if (!newRowSelection.onChange) {}
            return newRowSelection;
        };
        _this.handleTableChange = function (pagination, filters, sorter, extra) {
            var _this$props3 = _this.props,
                onChange = _this$props3.onChange,
                onSortChange = _this$props3.onSortChange;

            if (onChange) {
                onChange(pagination, filters, sorter, extra);
            }
            // 分页 筛选 排序都会触发onChange，需要区分排序
            if (onSortChange) {
                var currentSortInfo = _this.state.currentSortInfo;

                if (currentSortInfo.field !== sorter.field || currentSortInfo.order !== sorter.order) {
                    onSortChange(sorter.field, sorter.order);
                    _this.setState({ currentSortInfo: { field: sorter.field, order: sorter.order } });
                }
            }
        };
        _this.handlePageChange = function (currentPage, pageSize) {
            if (_this.state.freezAddRow) {
                _message2["default"].warn(_this.props.saveAddRowMsg || '请先保存当前新增行！');
                return;
            }
            if (_this.props.pagination && _this.props.pagination.onChange) {
                _this.props.pagination.onChange(currentPage, pageSize);
            } else if (_this.props.pagination) {
                _this.setState({
                    currentPage: currentPage
                });
            }
        };
        var _this$props4 = _this.props,
            dataSource = _this$props4.dataSource,
            editingKey = _this$props4.editingKey,
            highlightRow = _this$props4.highlightRow,
            children = _this$props4.children;

        var newColumns = [];
        if (children) {
            if (Array.isArray(children)) {
                for (var i = 0; i < children.length; i++) {
                    var child = children[i];
                    if (child.props) {
                        newColumns.push(child.props);
                    }
                }
            } else {
                newColumns.push(children.props);
            }
            newColumns = handleColumns((0, _cloneDeep2["default"])(newColumns));
        } else {
            newColumns = handleColumns((0, _cloneDeep2["default"])(_this.props.columns));
        }
        _this.state = {
            tableWidth: 0,
            columns: newColumns,
            dataSource: dataSource,
            editingKey: editingKey,
            update: false,
            highlightRow: highlightRow,
            currentSortInfo: {},
            currentPage: ((_a = _this.props.pagination) === null || _a === void 0 ? void 0 : _a.current) || 1,
            freezAddRow: false,
            copyDataSource: (0, _cloneDeep2["default"])(dataSource)
        };
        return _this;
    }

    (0, _createClass3["default"])(Table, [{
        key: "componentDidMount",
        value: function componentDidMount() {
            var columns = this.state.columns;

            var newColumns = caluColumnWidth(columns, this.table.offsetWidth);
            if (this.table && !(0, _isEqual2["default"])(columns, newColumns)) {
                this.setState({
                    columns: newColumns,
                    update: true,
                    tableWidth: this.table.offsetWidth
                });
            }
        }
    }, {
        key: "render",
        value: function render() {
            var _this2 = this;

            var _props = this.props,
                dragable = _props.dragable,
                _rowClassName = _props.rowClassName,
                editRow = _props.editRow,
                rowKey = _props.rowKey,
                onRow = _props.onRow,
                propRowSelection = _props.rowSelection,
                onSelectRows = _props.onSelectRows,
                onSortChange = _props.onSortChange;
            var _state = this.state,
                columns = _state.columns,
                dataSource = _state.dataSource,
                highlightRow = _state.highlightRow;

            var rowSelection = typeof propRowSelection === 'boolean' ? {} : propRowSelection;
            var editClass = "";
            if (editRow || this.judgeCellEdit(columns)) {
                editClass += "editable-row ";
            }
            this.components = {
                header: {
                    cell: ResizeableTitle
                }
            };
            if (editRow) {
                this.components.body = {
                    row: _editRow.EditableFormRow,
                    cell: _editRow.EditableRow
                };
            } else if (this.judgeCellEdit(columns)) {
                this.components.body = {
                    row: _editCell.EditableFormCell,
                    cell: _editCell.EditableCell
                };
            } else if (dragable) {
                this.components.body = {
                    row: _dragTable.DragableBodyRow
                };
            }
            var onRowNew = function onRowNew(record, index) {
                return (0, _extends3["default"])((0, _extends3["default"])((0, _extends3["default"])({}, dragable ? { moveRow: _this2.moveRow } : {}), onRow ? onRow(record, index) : {}), { index: index, onClick: function onClick(event) {
                        function findDomAncestor(dom) {
                            if (dom.nodeName === "A" || dom.nodeName === "BUTTON" || dom.nodeName === "INPUT") {
                                return true;
                            } else if (dom.nodeName === "BODY") {
                                return false;
                            } else {
                                return findDomAncestor(dom.parentNode);
                            }
                        }
                        if (findDomAncestor(event.target)) {
                            return;
                        }
                        if (onRow && onRow(record, index)["onClick"]) {
                            onRow(record, index)["onClick"](event);
                        }
                        _this2.selectRow(record);
                    } });
            };
            var opts = (0, _extends3["default"])((0, _extends3["default"])({}, this.props), { rowSelection: rowSelection, components: this.components, dataSource: dataSource, columns: columns.map(function (col, index) {
                    return (0, _extends3["default"])((0, _extends3["default"])((0, _extends3["default"])({}, col), { onHeaderCell: function onHeaderCell(column) {
                            return {
                                width: column.width || DEFAULT_COLUMN_WIDTH,
                                onResize: _this2.handleResize(index)
                            };
                        } }), col.editable ? {
                        onCell: function onCell(record) {
                            return (0, _extends3["default"])({ record: record, width: col.width || DEFAULT_COLUMN_WIDTH, editType: col.editType || DEFAULT_COLUMN_EDITTYPE, dataIndex: col.dataIndex, editRules: col.editRules, editOptions: col.editOptions || [], optionsLabel: col.optionsLabel || DEFAULT_COLUMN_OPTIONS_LABEL, optionsValue: col.optionsValue || DEFAULT_COLUMN_OPTIONS_VALUE, editInitValue: col.editInitValue, relationKey: col.relationKey, title: col.title, editContent: (0, _isFunction2["default"])(col.editContent) ? col.editContent() : "Edit", saveContent: (0, _isFunction2["default"])(col.saveContent) ? col.saveContent() : "Save", cancelContent: (0, _isFunction2["default"])(col.cancelContent) ? col.cancelContent() : "Cancel" }, editRow ? {
                                editing: _this2.isEditing(record),
                                handleSave: _this2.handleSave,
                                toggleEditRow: _this2.toggleEditRow,
                                keyValue: (0, _isFunction2["default"])(rowKey) ? rowKey(record) : record[rowKey]
                            } : { editable: col.editable, handleSave: _this2.handleSave });
                        }
                    } : {});
                }), rowClassName: function rowClassName(record, index) {
                    var res = [];
                    if (_rowClassName) {
                        res.push(_rowClassName(record, index));
                    }
                    if (editClass) {
                        res.push(editClass);
                    }
                    if ((0, _isFunction2["default"])(rowKey)) {
                        if (rowKey(record) === rowKey(highlightRow)) {
                            res.push("fdx-table-row-selected");
                        }
                    } else {
                        if (record[rowKey] === highlightRow[rowKey]) {
                            res.push("fdx-table-row-selected");
                        }
                    }
                    return res.join(" ");
                }, ref: function ref(_ref3) {
                    _this2.table = (0, _reactDom.findDOMNode)(_ref3);
                } });
            // 若用户直接设置rowSelection=true，或rowSelection未定义onChange 则行选择在table内部处理并触发onSelectRows
            if (onSelectRows) {
                opts.rowSelection = this.handleRowSelection(rowSelection);
            }
            // 若用户设置onSortChange,需要在内部onChange事件并触发onSortChange
            if (onSortChange) {
                opts.onChange = this.handleTableChange;
            }
            return _react2["default"].createElement(
                _reactDnd.DndProvider,
                { backend: _reactDndHtml5Backend.HTML5Backend },
                _react2["default"].createElement(
                    _configProvider.ConfigConsumer,
                    null,
                    function (_ref4) {
                        var pagePoint = _ref4.pagePoint;
                        return _react2["default"].createElement(
                            "div",
                            { className: "fdx-table" },
                            pagePoint ? _react2["default"].createElement(_pagePointEnhanced2["default"], (0, _extends3["default"])({ compType: "Table" }, _this2.props, { onRow: onRowNew, render: function render(eventprops) {
                                    return _react2["default"].createElement(_table2["default"], (0, _extends3["default"])({}, opts, { rowSelection: rowSelection ? (0, _extends3["default"])((0, _extends3["default"])({}, rowSelection), eventprops.onChange ? { onChange: eventprops.onChange } : {}) : null, onRow: eventprops.onRow ? eventprops.onRow : onRowNew, pagination: opts.pagination ? (0, _extends3["default"])({ current: _this2.state.currentPage, onChange: _this2.handlePageChange }, opts.pagination) : false, "data-ui-role": "Table" }));
                                } })) : _react2["default"].createElement(_table2["default"], (0, _extends3["default"])({}, opts, { pagination: opts.pagination ? (0, _extends3["default"])({ current: _this2.state.currentPage, onChange: _this2.handlePageChange }, opts.pagination) : false, onRow: onRowNew }))
                        );
                    }
                )
            );
        }
    }], [{
        key: "getDerivedStateFromProps",
        value: function getDerivedStateFromProps(nextProps, prevState) {
            var changeObj = {};
            if (nextProps.editingKey !== prevState.editingKey) {
                if (nextProps.update === prevState.update) {
                    changeObj.editingKey = nextProps.editingKey;
                } else {
                    changeObj.update = false;
                }
            }
            if (!(0, _isEqual2["default"])(nextProps.columns, prevState.columns)) {
                if (nextProps.columns && nextProps.update === prevState.update) {
                    var newColumns = nextProps.columns;
                    if (nextProps.columns.findIndex(function (col) {
                        return !col.width;
                    }) !== -1) {
                        //如果传入的columns中有位置width的列，则重新算一下每列的width，确保每一列都有确定的width
                        newColumns = caluColumnWidth(nextProps.columns, prevState.tableWidth);
                    }
                    changeObj.columns = newColumns;
                } else {
                    changeObj.update = false;
                }
            }
            if (nextProps.children) {
                var columns = prevState.columns;
                var children = nextProps.children;

                var _newColumns = [];
                if (Array.isArray(children)) {
                    for (var i = 0; i < children.length; i++) {
                        var child = children[i];
                        if (child.props) {
                            _newColumns.push(child.props);
                        }
                    }
                } else {
                    _newColumns.push(children.props);
                }
                _newColumns = handleColumns((0, _cloneDeep2["default"])(_newColumns));
                if (!(0, _isEqual2["default"])(columns, _newColumns) && nextProps.update === prevState.update) {
                    changeObj.columns = _newColumns;
                } else {
                    changeObj.update = false;
                }
            }
            if (!(0, _isEqual2["default"])(nextProps.highlightRow, prevState.highlightRow)) {
                if (nextProps.update === prevState.update) {
                    changeObj.highlightRow = nextProps.highlightRow;
                } else {
                    changeObj.update = false;
                }
            }
            if (!(0, _isEqual2["default"])(nextProps.dataSource, prevState.dataSource)) {
                if (!prevState.freezAddRow && nextProps.update === prevState.update) {
                    changeObj.dataSource = (0, _cloneDeep2["default"])(nextProps.dataSource);
                } else {
                    changeObj.copyDataSource = (0, _cloneDeep2["default"])(nextProps.dataSource);
                    changeObj.update = false;
                }
                if (nextProps.editRow && nextProps.dataSource.length - prevState.dataSource.length === 1) {
                    changeObj.freezAddRow = true;
                }
                if (nextProps.dataSource.length >= prevState.dataSource.length) {
                    if (!prevState.freezAddRow && nextProps.pagination && !nextProps.pagination.onChange) {
                        var pageSize = nextProps.pagination.pageSize || DEFAULT_PAGE_SIZE;
                        if (nextProps.dataSource.length / pageSize > prevState.currentPage) {
                            changeObj.currentPage = Math.ceil(nextProps.dataSource.length / pageSize);
                        }
                    }
                    if (nextProps.editRow && prevState.freezAddRow && prevState.editingKey && nextProps.editingKey !== prevState.editingKey) {
                        changeObj.editingKey = prevState.editingKey;
                        if (!(0, _isEqual2["default"])(nextProps.dataSource, prevState.copyDataSource)) {
                            _message2["default"].warn(nextProps.saveAddRowMsg || '请先保存当前新增行！');
                            changeObj.dataSource = (0, _cloneDeep2["default"])(prevState.dataSource);
                            changeObj.copyDataSource = (0, _cloneDeep2["default"])(prevState.dataSource);
                            nextProps.dataSource.pop();
                        }
                    }
                } else if (nextProps.editRow) {
                    changeObj.freezAddRow = false;
                    changeObj.editingKey = '';
                    changeObj.dataSource = (0, _cloneDeep2["default"])(nextProps.dataSource);
                }
            } else {
                // 如果不把 state 中的 update 重置为 false 在先编辑行，再新增行的场景 新增行会有一行的延迟
                changeObj.update = false;
            }
            return Object.keys(changeObj).length ? changeObj : null;
        }
    }]);
    return Table;
}(_react.Component);

Table.componentName = "Table";
Table.Column = _Column2["default"];
Table.propTypes = {
    dragable: _propTypes2["default"].bool,
    editRow: _propTypes2["default"].bool,
    onSaveCellEdit: _propTypes2["default"].func,
    onSaveRowEdit: _propTypes2["default"].func,
    editingKey: _propTypes2["default"].string,
    highlightRow: _propTypes2["default"].object,
    onCancelRowEdit: _propTypes2["default"].func,
    onRowEditing: _propTypes2["default"].func,
    afterRowDrag: _propTypes2["default"].func,
    onSortChange: _propTypes2["default"].func,
    onSelectRows: _propTypes2["default"].func
};
Table.defaultProps = {
    pagination: false,
    dragable: false,
    bordered: true,
    editRow: false,
    rowKey: "key",
    size: "small",
    //扩展属性
    update: false,
    highlightRow: {},
    editingKey: "",
    onSaveCellEdit: function onSaveCellEdit() {},
    onSaveRowEdit: function onSaveRowEdit() {},
    onCancelRowEdit: function onCancelRowEdit() {},
    onRowEditing: function onRowEditing() {},
    afterRowDrag: function afterRowDrag() {}
};
exports["default"] = Table;
module.exports = exports['default'];