adui
Version:
<div> <img src="https://wxa.wxs.qq.com/mpweb/delivery/legacy/wxadtouch/upload/t1/od834zef_52939fc6.png" style="margin:40px 0 0 -8px; background-color: #fcfcfc; box-shadow: none;" /> </div>
1,157 lines (990 loc) • 232 kB
JavaScript
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var _excluded = ["rowSpan", "colSpan"],
_excluded2 = ["className", "dataSource", "emptyText", "headerAffixed", "headerAffixedOffsetTop", "headerAffixGetTarget", "headerEmphasized", "height", "loading", "size", "virtualScroll"];
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
import * as React from "react";
import { VariableSizeList } from "react-window";
import PropTypes from "prop-types";
import shallowEqual from "shallowequal";
import addEventListener from "rc-util/lib/Dom/addEventListener";
import { debounce } from "debounce";
import classNames from "classnames";
import omit from "../_util/omit";
import Column from "./Column";
import Affix from "../affix";
import Checkbox from "../checkbox";
import Icon from "../icon";
import Popover from "../popover";
import Radio from "../radio";
import ResizeObserver from "../resize-observer";
import TableSort from "./TableSort";
import TableFilter from "./TableFilter";
import ColumnManager from "./ColumnManager";
import "./style";
var noop = function noop() {};
var prefix = "adui-table";
var TD_MIN_WIDTH = 100;
var SELECT_TD_WIDTH = 50;
var SELECT_AND_EXPAND_TD_WIDTH = 80;
var TD_HEIGHT = {
large: 60,
medium: 50,
mini: 40,
small: 40
};
var HORIZONTAL_ALIGN = {
center: "center",
left: "flex-start",
right: "flex-end"
};
var VERTICAL_ALIGN = {
bottom: "flex-end",
center: "center",
top: "flex-start"
};
var isFixedLeft = function isFixedLeft(col) {
return col.fixed === "left" || col.fixed === true;
};
var isFixedRight = function isFixedRight(col) {
return col.fixed === "right";
};
var Table = function (_React$Component) {
_inherits(Table, _React$Component);
var _super = _createSuper(Table);
function Table(_props) {
var _this;
_classCallCheck(this, Table);
_this = _super.call(this, _props);
_this.combinedCellsInfo = [];
_this.affixHeader = void 0;
_this.affixScrollbar = void 0;
_this.mainTable = void 0;
_this.mainTableBody = void 0;
_this.mainThead = void 0;
_this.wrapper = void 0;
_this.virtualList = void 0;
_this.debouncedWindowResize = void 0;
_this.resizeEvent = void 0;
_this.columnManager = void 0;
_this.fixedColumnsInfosRef = [];
_this.shouldComponentUpdate = function (nextProps, nextState) {
return !shallowEqual(_this.props, nextProps) || !shallowEqual(_this.state, nextState);
};
_this.componentDidMount = function () {
var _assertThisInitialize = _assertThisInitialized(_this),
columnManager = _assertThisInitialize.columnManager,
combinedCellsInfo = _assertThisInitialize.combinedCellsInfo,
debouncedWindowResize = _assertThisInitialize.debouncedWindowResize,
props = _assertThisInitialize.props;
var isAnyColumnsFixed = columnManager.isAnyColumnsFixed;
var headerAffixed = props.headerAffixed,
height = props.height,
virtualScroll = props.virtualScroll;
if (headerAffixed || height || isAnyColumnsFixed) {
_this.handleWindowResize();
_this.resizeEvent = addEventListener(window, "resize", debouncedWindowResize);
}
if (combinedCellsInfo.length) {
_this.setState({
combinedCellsInfo: combinedCellsInfo
});
}
setTimeout(function () {
var _this$virtualList;
var virtualWrapper = (_this$virtualList = _this.virtualList) === null || _this$virtualList === void 0 ? void 0 : _this$virtualList._outerRef;
if (virtualScroll && virtualWrapper) {
_this.mainThead.style.paddingRight = "14px";
virtualWrapper.addEventListener("scroll", function () {
_this.mainThead.scrollLeft = virtualWrapper.scrollLeft;
}, true);
}
}, 0);
};
_this.componentDidUpdate = function (_ref) {
var dataSourceOld = _ref.dataSource,
getCellPropsOld = _ref.getCellProps,
columnsOld = _ref.columns;
var _this$props = _this.props,
dataSource = _this$props.dataSource,
getCellProps = _this$props.getCellProps,
columns = _this$props.columns;
if (!shallowEqual(dataSourceOld, dataSource)) {
setTimeout(_this.handleWindowResize, 0);
}
if (!shallowEqual(columnsOld, columns)) {
columns === null || columns === void 0 ? void 0 : columns.forEach(function (_ref2, index) {
var dataIndex = _ref2.dataIndex,
fixed = _ref2.fixed,
width = _ref2.width;
if (typeof width === "number" && fixed) {
_this.handleThResize(columns.length, width, dataIndex, index, fixed);
}
});
}
if (!shallowEqual(getCellPropsOld, getCellProps) && getCellProps) {
_this.forceUpdate();
}
};
_this.componentWillUnmount = function () {
if (_this.resizeEvent) {
_this.resizeEvent.remove();
}
if (_this.debouncedWindowResize) {
_this.debouncedWindowResize.clear();
}
};
_this.resizeColumnStart = function (e, col) {
e.stopPropagation();
document.body.style.cursor = "col-resize";
_this.setState({
currentlyResizing: {
col: col,
dataIndex: col.dataIndex,
parentWidth: e.currentTarget.parentElement && e.currentTarget.parentElement.parentElement && e.currentTarget.parentElement.parentElement.getBoundingClientRect().width,
startX: e.pageX
}
});
setTimeout(function () {
window.addEventListener("mousemove", _this.resizeColumnMoving);
window.addEventListener("mouseup", _this.resizeColumnEnd);
window.addEventListener("mouseleave", _this.resizeColumnEnd);
}, 0);
};
_this.resizeColumnMoving = function (e) {
e.stopPropagation();
var _this$state = _this.state,
resized = _this$state.resized,
currentlyResizing = _this$state.currentlyResizing;
var col = currentlyResizing.col,
dataIndex = currentlyResizing.dataIndex,
parentWidth = currentlyResizing.parentWidth,
startX = currentlyResizing.startX;
var title = col.title || "";
var baseWidth = Math.ceil(title.length > 4 ? title.length / 2 : title.length) * 13 + 2;
if (!baseWidth) {
baseWidth = 100;
}
var newResized = resized.filter(function (o) {
return o.dataIndex !== dataIndex;
});
var newWidth = Math.max(Math.ceil(parentWidth + e.pageX - startX), !!col.onSort || !!col.onFilter ? baseWidth + 36 : baseWidth + 16);
newResized.push({
dataIndex: dataIndex,
value: newWidth
});
_this.setState({
resized: newResized
});
_this.debouncedWindowResize();
};
_this.resizeColumnEnd = function (e) {
var _assertThisInitialize2 = _assertThisInitialized(_this),
mainTable = _assertThisInitialize2.mainTable;
document.body.style.cursor = "";
e.stopPropagation();
window.removeEventListener("mousemove", _this.resizeColumnMoving);
window.removeEventListener("mouseup", _this.resizeColumnEnd);
window.removeEventListener("mouseleave", _this.resizeColumnEnd);
_this.setState({
currentlyResizing: {},
isMainTableOverflowX: mainTable && mainTable.scrollWidth > mainTable.offsetWidth,
isMainTableOverflowY: mainTable && mainTable.scrollHeight > mainTable.offsetHeight,
isResizerShow: false
});
};
_this.handleWindowResize = function () {
var _assertThisInitialize3 = _assertThisInitialized(_this),
columnManager = _assertThisInitialize3.columnManager,
mainTable = _assertThisInitialize3.mainTable,
props = _assertThisInitialize3.props;
var isAnyColumnsFixed = columnManager.isAnyColumnsFixed;
var headerAffixed = props.headerAffixed,
height = props.height;
if ((headerAffixed || height || isAnyColumnsFixed) && mainTable) {
var oldStyle = _this.state.mainTableStyle;
var rect = mainTable.getBoundingClientRect();
var mainTableStyle = {};
mainTableStyle.left = rect.left;
mainTableStyle.width = rect.width;
if (!shallowEqual(mainTableStyle, oldStyle)) {
_this.setState({
mainTableStyle: mainTableStyle
});
}
_this.setState({
isMainTableOverflowX: mainTable && mainTable.scrollWidth > mainTable.offsetWidth,
isMainTableOverflowY: mainTable && mainTable.scrollHeight > mainTable.offsetHeight
});
}
};
_this.handleMainTableScroll = function (e) {
var _assertThisInitialize4 = _assertThisInitialized(_this),
affixHeader = _assertThisInitialize4.affixHeader,
mainTable = _assertThisInitialize4.mainTable;
var onScroll = _this.props.onScroll;
var affixedTop = _this.state.affixedTop;
if (onScroll && e) {
var target = e.target;
if (target.getAttribute("role") === "table") {
onScroll(e);
}
}
if (affixedTop && affixHeader && mainTable && affixHeader.fixedNode) {
affixHeader.fixedNode.scrollLeft = mainTable.scrollLeft;
}
_this.syncTableScrollPosition(mainTable.scrollLeft);
};
_this.syncTableScrollPosition = function (value) {
var _assertThisInitialize5 = _assertThisInitialized(_this),
affixScrollbar = _assertThisInitialize5.affixScrollbar,
mainTable = _assertThisInitialize5.mainTable,
mainThead = _assertThisInitialize5.mainThead;
var height = _this.props.height;
if (mainTable && affixScrollbar && affixScrollbar.fixedNode) {
if (mainTable.scrollLeft !== value) {
mainTable.scrollLeft = value;
}
if (affixScrollbar.fixedNode.scrollLeft !== value) {
affixScrollbar.fixedNode.scrollLeft = value;
}
}
if (height && mainThead) {
mainThead.scrollLeft = value;
}
};
_this.handleRowClick = function (row, i, e) {
var _this$props2 = _this.props,
expandOnRowClick = _this$props2.expandOnRowClick,
getSelectProps = _this$props2.getSelectProps,
onRowClick = _this$props2.onRowClick,
selectOnRowClick = _this$props2.selectOnRowClick;
var selectedRowKeys = _this.state.selectedRowKeys;
var key = row.key;
if (selectOnRowClick && typeof key !== "undefined" && !(getSelectProps && getSelectProps(row, i) && getSelectProps(row, i).disabled)) {
_this.handleSelect(key, !selectedRowKeys.includes(key));
}
if (expandOnRowClick) {
_this.handleExpand(key);
}
if (onRowClick) {
onRowClick(row, i, e);
}
};
_this.handleThResize = function (columnsLength, width, dataIndex, index, fixedPosition) {
var getColumns = _this.columnManager.getColumns;
var _assertThisInitialize6 = _assertThisInitialized(_this),
fixedColumnsInfos = _assertThisInitialize6.fixedColumnsInfosRef;
var columns = getColumns();
fixedColumnsInfos = fixedColumnsInfos.filter(function (o) {
return columns.find(function (p) {
return p.dataIndex === o.dataIndex && !!p.fixed;
});
});
var i = fixedColumnsInfos.findIndex(function (o) {
return o.dataIndex === dataIndex;
});
var fixed = fixedPosition === "right" ? "right" : "left";
if (i > -1) {
if (fixedColumnsInfos[i].width === width && fixedColumnsInfos[i].columnsLength === columnsLength && fixedColumnsInfos[i].index === index) {
return;
}
fixedColumnsInfos.splice(i, 1);
}
fixedColumnsInfos.push({
width: width,
dataIndex: dataIndex,
index: index,
fixed: fixed,
columnsLength: columnsLength
});
fixedColumnsInfos.sort(function (a, b) {
return a.index - b.index;
});
var fixedColumnsInfosLeft = fixedColumnsInfos.filter(function (o) {
return o.fixed === "left";
});
var fixedColumnsInfosRight = fixedColumnsInfos.filter(function (o) {
return o.fixed === "right";
}).sort(function (a, b) {
return b.index - a.index;
});
fixedColumnsInfos.forEach(function (col) {
var colIndex;
if (col.fixed === "left") {
colIndex = fixedColumnsInfosLeft.findIndex(function (o) {
return o.dataIndex === col.dataIndex;
});
if (colIndex === fixedColumnsInfosLeft.length - 1) {
col.isLastLeft = true;
} else {
col.isLastLeft = false;
}
col.offset = colIndex === -1 ? 0 : fixedColumnsInfosLeft.slice(0, colIndex).reduce(function (acc, cur) {
return acc + cur.width;
}, 0);
} else {
colIndex = fixedColumnsInfosRight.findIndex(function (o) {
return o.dataIndex === col.dataIndex;
});
if (colIndex === fixedColumnsInfosRight.length - 1) {
col.isFirstRight = true;
} else {
col.isFirstRight = false;
}
col.offset = colIndex === -1 ? 0 : fixedColumnsInfosRight.slice(0, colIndex).reduce(function (acc, cur) {
return acc + cur.width;
}, 0);
}
});
_this.fixedColumnsInfosRef = fixedColumnsInfos;
_this.setState({
fixedColumnsInfos: fixedColumnsInfos
});
};
_this.handleTheadMouseEnter = function () {
var isResizerShow = _this.state.isResizerShow;
if (!isResizerShow) {
_this.setState({
isResizerShow: true
});
}
};
_this.handleTheadMouseLeave = function () {
var currentlyResizing = _this.state.currentlyResizing;
if (Object.keys(currentlyResizing).length === 0) {
_this.setState({
isResizerShow: false
});
}
};
_this.handleExpand = function (key) {
if (typeof key === "undefined") {
return;
}
var _this$props3 = _this.props,
expandedRowKeysProp = _this$props3.expandedRowKeys,
onExpandChange = _this$props3.onExpandChange;
var expandedRowKeys = _this.state.expandedRowKeys;
var keys = _toConsumableArray(expandedRowKeys);
var index = keys.indexOf(key);
if (index > -1) {
keys.splice(index, 1);
} else {
keys.push(key);
}
if (expandedRowKeysProp === null) {
_this.setState({
expandedRowKeys: keys
});
}
if (onExpandChange) {
onExpandChange(keys);
}
};
_this.handleSelect = function (key, selected) {
var _this$props4 = _this.props,
onSelectChange = _this$props4.onSelectChange,
selectedRowKeysProp = _this$props4.selectedRowKeys,
selectMultiple = _this$props4.selectMultiple,
dataSource = _this$props4.dataSource;
var currentRow = dataSource === null || dataSource === void 0 ? void 0 : dataSource.find(function (o) {
return o.key === key;
});
if (typeof key === "undefined" || !(dataSource !== null && dataSource !== void 0 && dataSource.length) || !currentRow) {
return;
}
var selectedRowKeys = _this.state.selectedRowKeys;
var keys = _toConsumableArray(selectedRowKeys);
if (selectMultiple) {
if (selected) {
keys.push(key);
} else {
keys.splice(selectedRowKeys.indexOf(key), 1);
}
} else {
keys = [key];
}
if (selectedRowKeysProp === null) {
_this.setState({
selectedRowKeys: keys
});
}
if (onSelectChange) {
onSelectChange(keys, {
selected: !selectMultiple || selected,
currentRowKey: key,
selectedRows: dataSource.filter(function (o) {
return keys.includes(o.key);
}),
currentRow: currentRow
});
}
};
_this.handleSelectAll = function (checked) {
var _this$props5 = _this.props,
onSelectChange = _this$props5.onSelectChange,
selectedRowKeysProp = _this$props5.selectedRowKeys;
var selectedRowKeys = _this.state.selectedRowKeys;
var keys = _toConsumableArray(selectedRowKeys);
var availableKeys = _this.getAvailableRowsKeys();
if (checked) {
availableKeys.forEach(function (key) {
if (!selectedRowKeys.includes(key)) {
keys.push(key);
}
});
} else {
selectedRowKeys.forEach(function (key) {
if (availableKeys.includes(key)) {
keys.splice(keys.indexOf(key), 1);
}
});
}
if (selectedRowKeysProp === null) {
_this.setState({
selectedRowKeys: keys
});
}
if (onSelectChange) {
onSelectChange(keys);
}
};
_this.hasSelected = function (mode) {
var keys = _this.getAvailableRowsKeys();
var dataSource = _this.props.dataSource;
var selectedRowKeys = _this.state.selectedRowKeys;
if (dataSource && dataSource.length && keys.length && (mode === "all" ? keys.every(function (key) {
return selectedRowKeys.includes(key);
}) : keys.some(function (key) {
return selectedRowKeys.includes(key);
}))) {
return true;
}
return false;
};
_this.getAvailableRowsKeys = function () {
var _this$props6 = _this.props,
dataSource = _this$props6.dataSource,
getSelectProps = _this$props6.getSelectProps;
var keys = [];
if (!dataSource) {
return [];
}
dataSource.forEach(function (row, i) {
var key = row.key;
if (typeof key !== "undefined" && !(getSelectProps && getSelectProps(row, i) && getSelectProps(row, i).disabled)) {
keys.push(key);
}
});
return keys;
};
_this.generateTable = function () {
var _classNames, _this$mainTable;
var _this$props7 = _this.props,
dataSource = _this$props7.dataSource,
expandIconVisible = _this$props7.expandIconVisible,
expandedRowRender = _this$props7.expandedRowRender,
expandOnRowClick = _this$props7.expandOnRowClick,
getHeadClassName = _this$props7.getHeadClassName,
getHeadStyle = _this$props7.getHeadStyle,
getRowClassName = _this$props7.getRowClassName,
getRowProps = _this$props7.getRowProps,
getRowStyle = _this$props7.getRowStyle,
getSelectProps = _this$props7.getSelectProps,
grow = _this$props7.grow,
headerAffixed = _this$props7.headerAffixed,
headerAffixedOffsetTop = _this$props7.headerAffixedOffsetTop,
headerAffixGetTarget = _this$props7.headerAffixGetTarget,
scrollXAffixedOffsetBottom = _this$props7.scrollXAffixedOffsetBottom,
height = _this$props7.height,
onExpandChange = _this$props7.onExpandChange,
onRowMouseEnter = _this$props7.onRowMouseEnter,
onRowMouseLeave = _this$props7.onRowMouseLeave,
onSelectChange = _this$props7.onSelectChange,
selectMultiple = _this$props7.selectMultiple,
selectOnRowClick = _this$props7.selectOnRowClick,
size = _this$props7.size,
verticalAlign = _this$props7.verticalAlign,
virtualListProps = _this$props7.virtualListProps,
virtualListStyle = _this$props7.virtualListStyle,
virtualScroll = _this$props7.virtualScroll;
var _this$state2 = _this.state,
affixedTop = _this$state2.affixedTop,
affixedBottom = _this$state2.affixedBottom,
expandedRowKeys = _this$state2.expandedRowKeys,
fixedColumnsInfos = _this$state2.fixedColumnsInfos,
isMainTableOverflowX = _this$state2.isMainTableOverflowX,
isMainTableOverflowY = _this$state2.isMainTableOverflowY,
mainTableStyle = _this$state2.mainTableStyle,
resized = _this$state2.resized,
selectedRowKeys = _this$state2.selectedRowKeys;
var _this$columnManager = _this.columnManager,
getColumns = _this$columnManager.getColumns,
getGroupColumnsDepth = _this$columnManager.getGroupColumnsDepth,
isAnyColumnsLeftFixed = _this$columnManager.isAnyColumnsLeftFixed;
var columns = getColumns();
var theadStyle = _objectSpread({
height: "".concat(TD_HEIGHT[size || "small"] * getGroupColumnsDepth(), "px")
}, getHeadStyle && getHeadStyle() || {});
var selectAndExpand = !!onSelectChange && !!onExpandChange;
var theadPlaceholderVisible = expandIconVisible && (!!onSelectChange || !!onExpandChange);
var thead = React.createElement("div", {
key: 0,
className: classNames("".concat(prefix, "-thead"), getHeadClassName && getHeadClassName()),
onMouseEnter: _this.handleTheadMouseEnter,
onMouseLeave: _this.handleTheadMouseLeave,
ref: _this.saveRef("mainThead"),
style: theadStyle
}, theadPlaceholderVisible && React.createElement("div", {
className: classNames("".concat(prefix, "-th"), "".concat(prefix, "-th_functional"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "-th_left"), isAnyColumnsLeftFixed()), _defineProperty(_classNames, "".concat(prefix, "-th_functional_both"), selectAndExpand), _classNames)),
key: "functional-all"
}, selectMultiple && !!onSelectChange && function () {
var hasSelectedAll = _this.hasSelected("all");
var hasSelectedOne = _this.hasSelected("one");
return React.createElement("div", {
className: "".concat(prefix, "-cell")
}, React.createElement(Checkbox, {
disabled: !_this.getAvailableRowsKeys().length,
onChange: _this.handleSelectAll,
checked: hasSelectedAll,
indeterminate: !hasSelectedAll && hasSelectedOne,
className: "".concat(prefix, "-selectComponent")
}));
}()), columns.map(function (col, index) {
var _fixedColumnsInfos$fi, _fixedColumnsInfos$fi2, _classNames2, _fixedColumnsInfos$fi3, _fixedColumnsInfos$fi4;
var align = col.align,
dataIndex = col.dataIndex,
filters = col.filters,
fixed = col.fixed,
colGrow = col.grow,
onFilter = col.onFilter,
onSort = col.onSort,
sortOrder = col.sortOrder,
title = col.title,
width = col.width;
var isGrow = colGrow !== undefined ? colGrow : grow;
var resizedCol = resized.find(function (o) {
return o.dataIndex === dataIndex;
});
var clickable = !!onSort || sortOrder !== null && sortOrder !== undefined || !!onFilter || !!filters;
var sortableAndFilterable = (!!onSort || sortOrder !== null && sortOrder !== undefined) && (!!onFilter || !!filters);
var minWidth = 0;
if (typeof title === "string") {
minWidth = Math.ceil(title.length > 4 ? title.length / 2 : title.length) * 13 + 16;
if (clickable) {
minWidth += 20;
}
}
var flexValue;
if (typeof width === "number") {
flexValue = "".concat(width, " 0 auto");
} else if (typeof width === "string") {
if (width.length - width.lastIndexOf("px") === 2) {
flexValue = "".concat(width.slice(0, -2), " 0 auto");
} else {
flexValue = "0 0 ".concat(width);
}
} else {
flexValue = "".concat(Math.max(TD_MIN_WIDTH, minWidth), " 0 auto");
}
return React.createElement(ResizeObserver, {
onResize: function onResize(_ref3) {
var widthResize = _ref3.width;
_this.handleThResize(columns.length, widthResize, dataIndex, index, fixed);
},
disabled: !fixed,
key: "".concat(dataIndex || index, "_").concat(columns.length)
}, React.createElement("div", {
className: classNames("".concat(prefix, "-th"), (_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefix, "-th_clickable"), clickable && !sortableAndFilterable), _defineProperty(_classNames2, "".concat(prefix, "-th_sortableAndFilterable"), sortableAndFilterable), _defineProperty(_classNames2, "".concat(prefix, "-th_left"), isFixedLeft(col)), _defineProperty(_classNames2, "".concat(prefix, "-th_right"), isFixedRight(col)), _defineProperty(_classNames2, "".concat(prefix, "-th_leftLast"), (_fixedColumnsInfos$fi = fixedColumnsInfos.find(function (o) {
return o.dataIndex === dataIndex;
})) === null || _fixedColumnsInfos$fi === void 0 ? void 0 : _fixedColumnsInfos$fi.isLastLeft), _defineProperty(_classNames2, "".concat(prefix, "-th_rightFirst"), (_fixedColumnsInfos$fi2 = fixedColumnsInfos.find(function (o) {
return o.dataIndex === dataIndex;
})) === null || _fixedColumnsInfos$fi2 === void 0 ? void 0 : _fixedColumnsInfos$fi2.isFirstRight), _classNames2)),
key: dataIndex ? "".concat(dataIndex, "_").concat(index) : index,
style: {
left: isFixedLeft(col) ? (((_fixedColumnsInfos$fi3 = fixedColumnsInfos.find(function (o) {
return o.dataIndex === dataIndex;
})) === null || _fixedColumnsInfos$fi3 === void 0 ? void 0 : _fixedColumnsInfos$fi3.offset) || 0) + (theadPlaceholderVisible ? selectAndExpand ? SELECT_AND_EXPAND_TD_WIDTH : SELECT_TD_WIDTH : 0) : undefined,
right: isFixedRight(col) ? (((_fixedColumnsInfos$fi4 = fixedColumnsInfos.find(function (o) {
return o.dataIndex === dataIndex;
})) === null || _fixedColumnsInfos$fi4 === void 0 ? void 0 : _fixedColumnsInfos$fi4.offset) || 0) + (isMainTableOverflowY && height ? 14 : 0) : undefined,
flex: resizedCol ? "".concat(resizedCol.value, " 0 auto") : flexValue,
maxWidth: isGrow ? undefined : resizedCol ? resizedCol.value : width || "",
textAlign: align || undefined,
width: resizedCol ? resizedCol.value : width || Math.max(TD_MIN_WIDTH, minWidth)
},
"data-column": index,
"data-column-key": dataIndex ? "".concat(dataIndex, "_").concat(index) : index
}, _this.generateThCell(col, {
index: index,
columns: columns
}), col.children && React.createElement("div", {
className: "".concat(prefix, "-thGroup")
}, col.children.map(function (childCol, childColIndex) {
return React.createElement("div", {
className: classNames("".concat(prefix, "-th"), _defineProperty({}, "".concat(prefix, "-th_clickable"), !!childCol.onSort || childCol.sortOrder !== null && childCol.sortOrder !== undefined || !!childCol.onFilter || !!childCol.filters)),
key: childCol.dataIndex || childColIndex,
style: {
flex: "100 0 auto",
width: "100px",
textAlign: childCol.align || undefined
}
}, _this.generateThCell(childCol), childCol.children && React.createElement("div", {
className: "".concat(prefix, "-thGroup")
}, childCol.children.map(function (grandCol, grandColIndex) {
return React.createElement("div", {
className: classNames("".concat(prefix, "-th"), _defineProperty({}, "".concat(prefix, "-th_clickable"), !!grandCol.onSort || grandCol.sortOrder !== null && grandCol.sortOrder !== undefined || !!grandCol.onFilter || !!grandCol.filters)),
key: grandCol.dataIndex || grandColIndex,
style: {
flex: "100 0 auto",
width: "100px",
textAlign: grandCol.align || undefined
}
}, _this.generateThCell(grandCol));
})));
}))));
}));
var generateTrs = function generateTrs(row, rowIndex, style) {
var _classNames5, _classNames6, _selectPropsGetted$po;
var key = row.key;
var colArray = [];
var selectPropsGetted = getSelectProps && getSelectProps(row, rowIndex);
var allSelectProps = _objectSpread({
checked: selectedRowKeys.includes(key),
className: "".concat(prefix, "-selectComponent"),
onChange: function onChange(checked) {
return _this.handleSelect(key, checked);
},
onClick: function onClick(e) {
return e.stopPropagation();
}
}, selectPropsGetted || {});
var selectProps = omit(allSelectProps, ["popoverProps"]);
var selectContent = selectMultiple ? React.createElement(Checkbox, selectProps) : React.createElement(Radio, selectProps);
var expandContent = React.createElement("div", {
className: "".concat(prefix, "-selectComponent"),
style: {
cursor: "pointer"
},
onClick: function onClick() {
return _this.handleExpand(key);
},
role: "none"
}, React.createElement(Icon, {
className: "".concat(prefix, "-expandIcon"),
icon: "arrow-down"
}));
var selectCell = onExpandChange ? expandContent : selectContent;
if (selectAndExpand) {
selectCell = React.createElement("div", {
className: "".concat(prefix, "-selectComponent-wrapper")
}, selectContent, expandContent);
}
var generateTr = function generateTr(columnsParam, parentIndex) {
columnsParam.forEach(function (col, colIndexParam) {
var colIndex = colIndexParam;
if (parentIndex) {
for (var i = 0; i < parentIndex; i += 1) {
var _columns$i$children;
var childrenCount = ((_columns$i$children = columns[i].children) === null || _columns$i$children === void 0 ? void 0 : _columns$i$children.length) || 1;
if (childrenCount) {
colIndex += childrenCount;
}
}
}
if (!col.children) {
colArray.push(_this.generateTbodyCell(row, col, rowIndex, colIndex));
} else {
generateTr(col.children, colIndexParam);
}
});
};
generateTr(columns);
var tr = React.createElement("div", _extends({
className: classNames("".concat(prefix, "-tr"), getRowClassName && getRowClassName(row, rowIndex), (_classNames5 = {}, _defineProperty(_classNames5, "".concat(prefix, "-tr_clickable"), expandOnRowClick || selectOnRowClick), _defineProperty(_classNames5, "".concat(prefix, "-tr_expanded"), expandedRowKeys.includes(key)), _defineProperty(_classNames5, "".concat(prefix, "-tr_selected"), selectedRowKeys.includes(key)), _classNames5)),
key: key !== undefined ? key : rowIndex,
role: "row",
"data-row": rowIndex,
onMouseEnter: onRowMouseEnter ? function (e) {
return onRowMouseEnter(row, rowIndex, e);
} : undefined,
onMouseLeave: onRowMouseLeave ? function (e) {
return onRowMouseLeave(row, rowIndex, e);
} : undefined,
onClick: function onClick(e) {
return _this.handleRowClick(row, rowIndex, e);
},
onKeyDown: noop,
style: _objectSpread(_objectSpread({}, getRowStyle && getRowStyle(row, rowIndex) || {}), style || {})
}, omit(getRowProps && getRowProps(row, rowIndex) || {}, ["popover"])), theadPlaceholderVisible && React.createElement("div", {
className: classNames("".concat(prefix, "-td"), "".concat(prefix, "-td_functional"), (_classNames6 = {}, _defineProperty(_classNames6, "".concat(prefix, "-td_left"), isAnyColumnsLeftFixed()), _defineProperty(_classNames6, "".concat(prefix, "-td_functional_both"), selectAndExpand), _classNames6)),
key: "functional",
role: "cell"
}, React.createElement("div", {
className: "".concat(prefix, "-cell"),
style: {
alignItems: verticalAlign && VERTICAL_ALIGN[verticalAlign]
}
}, selectPropsGetted !== null && selectPropsGetted !== void 0 && (_selectPropsGetted$po = selectPropsGetted.popoverProps) !== null && _selectPropsGetted$po !== void 0 && _selectPropsGetted$po.popup ? React.createElement(Popover, _extends({
mouseEnterDelay: 0.1,
alignEdge: false,
placement: "right"
}, (getSelectProps && getSelectProps(row, rowIndex) || {}).popoverProps), selectCell) : selectCell)), colArray);
if (getRowProps) {
var _getRowProps = getRowProps(row, rowIndex),
popover = _getRowProps.popover;
if (popover !== null && popover !== void 0 && popover.popup) {
tr = React.createElement(Popover, popover, tr);
}
}
if (onExpandChange) {
return React.createElement(React.Fragment, {
key: key !== undefined ? key : rowIndex
}, tr, expandedRowKeys.includes(key) ? React.createElement("div", {
className: "".concat(prefix, "-expandRow"),
style: {
maxWidth: mainTableStyle.width
}
}, React.createElement("div", {
className: "".concat(prefix, "-expandRow-inner"),
style: isMainTableOverflowX ? {
width: mainTableStyle.width
} : undefined
}, !!expandedRowRender && expandedRowRender(row, rowIndex))) : null);
}
return tr;
};
return [headerAffixed ? React.createElement(Affix, {
key: 0,
offsetTop: headerAffixedOffsetTop,
getContainer: function getContainer() {
return _this.wrapper;
},
getTarget: headerAffixGetTarget,
onChange: function onChange(bool) {
_this.setState({
affixedTop: bool
}, function () {
if (bool) {
_this.handleWindowResize();
_this.handleMainTableScroll();
}
});
},
className: affixedTop ? "".concat(prefix, "-affix") : "",
style: _objectSpread({
display: "flex",
zIndex: 2,
alignItems: "baseline",
flexDirection: "column"
}, affixedTop ? mainTableStyle : {}),
ref: _this.saveRef("affixHeader")
}, thead) : thead, React.createElement("div", {
key: 1,
className: "".concat(prefix, "-tbody"),
ref: _this.saveRef("mainTableBody")
}, !virtualScroll && dataSource && !!dataSource.length && dataSource.map(function (row, rowIndex) {
return generateTrs(row, rowIndex);
}), virtualScroll && dataSource && !!dataSource.length && React.createElement(VariableSizeList, _extends({
height: (height || 400) - 40,
itemCount: dataSource.length,
itemSize: function itemSize() {
return 42;
},
className: "".concat(prefix, "-virtual-wrapper"),
style: _objectSpread({}, virtualListStyle),
ref: function ref(o) {
_this.virtualList = o;
}
}, virtualListProps, {
onScroll: function onScroll(options) {
if (virtualListProps !== null && virtualListProps !== void 0 && virtualListProps.onScroll) {
virtualListProps.onScroll(options);
}
}
}), function (_ref4) {
var index = _ref4.index,
style = _ref4.style;
return generateTrs(dataSource[index], index, style);
})), isMainTableOverflowX && headerAffixed && React.createElement(Affix, {
key: 2,
offsetBottom: scrollXAffixedOffsetBottom,
getContainer: function getContainer() {
return _this.mainTableBody;
},
getTarget: headerAffixGetTarget,
ref: _this.saveRef("affixScrollbar"),
className: classNames("".concat(prefix, "-affixScrollbar"), _defineProperty({}, "".concat(prefix, "-affixScrollbar_show"), affixedBottom)),
style: _objectSpread({
zIndex: 2
}, mainTableStyle),
onScroll: function onScroll(e) {
return _this.syncTableScrollPosition(e.currentTarget.scrollLeft);
},
onChange: function onChange(bool) {
return _this.setState({
affixedBottom: bool
});
}
}, React.createElement("div", {
style: {
width: (_this$mainTable = _this.mainTable) === null || _this$mainTable === void 0 ? void 0 : _this$mainTable.scrollWidth
}
}))];
};
_this.generateThCell = function (col, options) {
var _classNames8;
var _this$props8 = _this.props,
align = _this$props8.align,
columnsResizable = _this$props8.columnsResizable,
getHeadCellClassNameProp = _this$props8.getHeadCellClassName,
getHeadCellStyleProp = _this$props8.getHeadCellStyle;
var colResizable = col.resizable,
getHeadCellClassName = col.getHeadCellClassName,
getHeadCellStyle = col.getHeadCellStyle,
onSort = col.onSort,
sortOrder = col.sortOrder,
onFilter = col.onFilter,
filters = col.filters;
var clickable = !!onSort || sortOrder !== null && sortOrder !== undefined || !!onFilter || !!filters;
var sortableAndFilterable = (!!onSort || sortOrder !== null && sortOrder !== undefined) && (!!onFilter || !!filters);
var resizable = true;
if (typeof colResizable === "boolean") {
resizable = colResizable;
} else if (typeof columnsResizable === "boolean") {
resizable = columnsResizable;
}
var _this$state3 = _this.state,
currentlyResizing = _this$state3.currentlyResizing,
isResizerShow = _this$state3.isResizerShow;
var isLastTh = options && options.index === options.columns.length - 1;
var thCell = React.createElement("div", {
className: classNames("".concat(prefix, "-cell"), getHeadCellClassName && getHeadCellClassName(), getHeadCellClassNameProp && getHeadCellClassNameProp(col, options ? options.index : undefined)),
style: _objectSpread(_objectSpread({
justifyContent: col.align && HORIZONTAL_ALIGN[col.align] || align && HORIZONTAL_ALIGN[align] || undefined
}, getHeadCellStyle && getHeadCellStyle() || {}), getHeadCellStyleProp && getHeadCellStyleProp(col, options ? options.index : undefined) || {})
}, (!clickable || sortableAndFilterable) && col.title, (!!col.onSort || col.sortOrder !== null && col.sortOrder !== undefined) && React.createElement(TableSort, {
sortableAndFilterable: sortableAndFilterable,
onSort: function onSort(order) {
return col.onSort ? col.onSort(order) : {};
},
sortOrder: col.sortOrder,
title: col.title
}), (!!col.onFilter || !!col.filters) && React.createElement(TableFilter, {
sortableAndFilterable: sortableAndFilterable,
filteredValue: col.filteredValue,
filterVisible: col.filterVisible,
filterMultiple: col.filterMultiple,
filterSearchable: col.filterSearchable,
filterSearchPlaceholder: col.filterSearchPlaceholder,
filterSearchCaseSensitive: col.filterSearchCaseSensitive,
filterSearchFunc: col.filterSearchFunc,
filterPopoverProps: col.filterPopoverProps,
filters: col.filters,
onFilter: function onFilter(filter) {
if (col.onFilter) {
col.onFilter(filter);
}
},
onFilterVisibleChange: function onFilterVisibleChange(visible) {
if (col.onFilterVisibleChange) {
col.onFilterVisibleChange(visible);
}
},
title: col.title
}), resizable && !isLastTh && React.createElement("div", {
className: classNames("".concat(prefix, "-resizer"), (_classNames8 = {}, _defineProperty(_classNames8, "".concat(prefix, "-resizer_show"), isResizerShow), _defineProperty(_classNames8, "".concat(prefix, "-resizer_current"), currentlyResizing.dataIndex === col.dataIndex), _classNames8)),
onMouseDown: function onMouseDown(e) {
return _this.resizeColumnStart(e, col);
},
role: "none"
}));
if (col.popover) {
return React.createElement(Popover, {
mouseEnterDelay: 0.3,
placement: col.align === "center" ? "top" : col.align === "right" ? "topRight" : "topLeft",
alignEdge: true,
arrowed: true,
popup: col.popover
}, thCell);
}
return thCell;
};
_this.generateTbodyCell = function (row, cell, rowIndex, cellIndex) {
var _fixedColumnsInfos$fi5, _fixedColumnsInfos$fi6, _classNames9, _fixedColumnsInfos$fi7, _fixedColumnsInfos$fi8;
var _this$props9 = _this.props,
alignProp = _this$props9.align,
expandIconVisible = _this$props9.expandIconVisible,
getCellClassNameProp = _this$props9.getCellClassName,
getCellPropsProp = _this$props9.getCellProps,
getCellStyleProp = _this$props9.getCellStyle,
grow = _this$props9.grow,
onExpandChange = _this$props9.onExpandChange,
onSelectChange = _this$props9.onSelectChange,
verticalAlignProp = _this$props9.verticalAlign;
var selectAndExpand = !!onSelectChange && !!onExpandChange;
var theadPlaceholderVisible = expandIconVisible && (!!onSelectChange || !!onExpandChange);
var _this$state4 = _this.state,
currentlyResizing = _this$state4.currentlyResizing,
fixedColumnsInfos = _this$state4.fixedColumnsInfos,
resized = _this$state4.resized;
var align = cell.align,
dataIndex = cell.dataIndex,
filters = cell.filters,
colGrow = cell.grow,
onFilter = cell.onFilter,
onSort = cell.onSort,
render = cell.render,
sortOrder = cell.sortOrder,
title = cell.title,
verticalAlign = cell.verticalAlign,
width = cell.width,
getCellClassName = cell.getCellClassName,
getCellProps = cell.getCellProps,
getCellStyle = cell.getCellStyle;
var isGrow = colGrow !== undefined ? colGrow : grow;
var clickable = !!onSort || sortOrder !== null && sortOrder !== undefined || !!onFilter || !!filters;
var minWidth = 0;
if (typeof title === "string") {
minWidth = Math.ceil(title.length > 4 ? title.length / 2 : title.length) * 13 + 16;
if (clickable) {
minWidth += 20;
}
}
var flexValue;
if (typeof width === "number") {
flexValue = "".concat(width, " 0 auto");
} else if (typeof width === "string") {
if (width.length - width.lastIndexOf("px") === 2) {
flexValue = "".concat(width.slice(0, -2), " 0 auto");
} else {
flexValue = "0 0 ".concat(width);
}
} else {
flexValue = "".concat(Math.max(TD_MIN_WIDTH, minWidth), " 0 auto");
}
var resizedCol = resized.find(function (o) {
return o.dataIndex === dataIndex;
});
var cellClassName = getCellClassName && getCellClassName(row, rowIndex) || getCellClassNameProp && getCellClassNameProp(row, cell, rowIndex, cell