choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
1,797 lines (1,565 loc) • 56.1 kB
JavaScript
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _extends from "@babel/runtime/helpers/extends";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import { __decorate } from "tslib";
import React, { Children, isValidElement } from 'react';
import { action, computed, get as _get, observable, runInAction, set } from 'mobx';
import sortBy from 'lodash/sortBy';
import debounce from 'lodash/debounce';
import isNil from 'lodash/isNil';
import isObject from 'lodash/isObject';
import isPlainObject from 'lodash/isPlainObject';
import isString from 'lodash/isString';
import isNumber from 'lodash/isNumber';
import measureScrollbar from '../../../es/_util/measureScrollbar';
import { isCalcSize, toPx } from '../../../es/_util/UnitConvertor';
import { getConfig, getProPrefixCls } from '../../../es/configure';
import Icon from '../../../es/icon';
import isFunction from 'lodash/isFunction';
import Column, { columnWidth } from './Column';
import CustomizationSettings from './customization-settings/CustomizationSettings';
import ObserverCheckBox from '../check-box';
import ObserverRadio from '../radio';
import { DataSetSelection } from '../data-set/enum';
import { ColumnAlign, ColumnLock, DragColumnAlign, SelectionMode, TableAutoHeightType, TableColumnTooltip, TableEditMode, TableHeightType, TableMode } from './enum';
import { stopPropagation } from '../_util/EventManager';
import { getColumnKey, getColumnLock, getHeader } from './utils';
import getReactNodeText from '../_util/getReactNodeText';
import ColumnGroups from './ColumnGroups';
import autobind from '../_util/autobind';
import { Size } from '../core/enum';
import { $l } from '../locale-context';
import CustomizationColumnHeader from './customization-settings/CustomizationColumnHeader';
export var SELECTION_KEY = '__selection-column__';
export var ROW_NUMBER_KEY = '__row-number-column__';
export var DRAG_KEY = '__drag-column__';
export var EXPAND_KEY = '__expand-column__';
export var CUSTOMIZED_KEY = '__customized-column__';
function columnFilter(column) {
return Boolean(column);
}
export var getIdList = function getIdList(startId, endId) {
var idList = [];
var min = Math.min(startId, endId);
var max = Math.max(startId, endId);
for (var i = min; i <= max; i++) {
idList.push(i);
}
return idList;
};
function getRowNumbers(record, dataSet, isTree) {
if (record && dataSet) {
var paging = dataSet.paging,
currentPage = dataSet.currentPage,
pageSize = dataSet.pageSize;
var pageIndex = (isTree ? paging === 'server' : paging) ? (currentPage - 1) * pageSize : 0;
if (isTree) {
return record.path.map(function (r, index) {
return r.indexInParent + 1 + (index === 0 ? pageIndex : 0);
});
}
return [record.index + 1 + pageIndex];
}
return [0];
}
function _renderSelectionBox(_ref) {
var record = _ref.record,
store = _ref.store;
var dataSet = record.dataSet;
if (dataSet) {
var selection = dataSet.selection;
var handleChange = function handleChange(value) {
if (store.props.selectionMode === SelectionMode.mousedown) {
// 将处理逻辑交给 mousedown 的处理逻辑 不然会两次触发导致不被勾选上
return;
}
if (value) {
dataSet.select(record);
} else {
dataSet.unSelect(record);
}
};
var handleClick = function handleClick(e) {
stopPropagation(e);
if (record.isSelected) {
dataSet.unSelect(record);
}
};
var handleMouseDown = function handleMouseDown() {
if (store.useMouseBatchChoose) {
store.mouseBatchChooseStartId = record.id;
store.mouseBatchChooseEndId = record.id;
store.mouseBatchChooseState = true;
}
};
var handleMouseEnter = function handleMouseEnter() {
if (store.useMouseBatchChoose && store.mouseBatchChooseState) {
store.mouseBatchChooseEndId = record.id;
store.changeMouseBatchChooseIdList(getIdList(store.mouseBatchChooseStartId, store.mouseBatchChooseEndId));
}
};
if (selection === DataSetSelection.multiple) {
return React.createElement(ObserverCheckBox, {
checked: record.isSelected,
onChange: handleChange,
onClick: stopPropagation,
onMouseDown: handleMouseDown,
onMouseEnter: handleMouseEnter,
disabled: !record.selectable,
"data-selection-key": SELECTION_KEY,
value: true
});
}
if (selection === DataSetSelection.single) {
return React.createElement(ObserverRadio, {
checked: record.isSelected,
onChange: handleChange,
onClick: handleClick,
onMouseDown: handleMouseDown,
onMouseEnter: handleMouseEnter,
disabled: !record.selectable,
"data-selection-key": SELECTION_KEY,
value: true
});
}
}
}
export function mergeDefaultProps(originalColumns, customizedColumns) {
var parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var defaultKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [0];
var columns = [];
var leftColumns = [];
var rightColumns = [];
var columnSort = {
left: 0,
center: 0,
right: 0
};
originalColumns.forEach(function (column, index) {
if (isPlainObject(column)) {
var newColumn = _objectSpread({}, Column.defaultProps, {}, column);
if (isNil(getColumnKey(newColumn))) {
newColumn.key = "anonymous-".concat(defaultKey[0]++);
}
if (customizedColumns) {
_extends(newColumn, customizedColumns[getColumnKey(newColumn).toString()]);
}
if (parent) {
newColumn.lock = parent.lock;
}
if (newColumn.sort === undefined) {
if (parent) {
newColumn.sort = index;
} else {
newColumn.sort = columnSort[getColumnLock(newColumn.lock) || 'center']++;
}
}
var children = newColumn.children;
if (children) {
newColumn.children = mergeDefaultProps(children, customizedColumns, newColumn, defaultKey);
}
if (parent || !newColumn.lock) {
columns.push(newColumn);
} else if (newColumn.lock === true || newColumn.lock === ColumnLock.left) {
leftColumns.push(newColumn);
} else {
rightColumns.push(newColumn);
}
}
}, []);
if (parent) {
return sortBy(columns, function (_ref2) {
var sort = _ref2.sort;
return sort;
});
}
return [].concat(_toConsumableArray(sortBy(leftColumns, function (_ref3) {
var sort = _ref3.sort;
return sort;
})), _toConsumableArray(sortBy(columns, function (_ref4) {
var sort = _ref4.sort;
return sort;
})), _toConsumableArray(sortBy(rightColumns, function (_ref5) {
var sort = _ref5.sort;
return sort;
})));
}
export function normalizeColumns(elements, customizedColumns) {
var parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var defaultKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [0];
var columns = [];
var leftColumns = [];
var rightColumns = [];
var columnSort = {
left: 0,
center: 0,
right: 0
};
Children.forEach(elements, function (element, index) {
if (!isValidElement(element) || !element.type.__PRO_TABLE_COLUMN) {
return;
}
var props = element.props,
key = element.key;
var column = _objectSpread({}, props);
if (key) {
column.key = key;
} else if (isNil(getColumnKey(column))) {
column.key = "anonymous-".concat(defaultKey[0]++);
}
if (customizedColumns) {
_extends(column, customizedColumns[getColumnKey(column).toString()]);
}
if (parent) {
column.lock = parent.lock;
}
if (column.sort === undefined) {
if (parent) {
column.sort = index;
} else {
column.sort = columnSort[getColumnLock(column.lock) || 'center']++;
}
}
column.children = normalizeColumns(column.children, customizedColumns, column, defaultKey);
if (parent || !column.lock) {
columns.push(column);
} else if (column.lock === true || column.lock === ColumnLock.left) {
leftColumns.push(column);
} else {
rightColumns.push(column);
}
});
if (parent) {
return sortBy(columns, function (_ref6) {
var sort = _ref6.sort;
return sort;
});
}
return [].concat(_toConsumableArray(sortBy(leftColumns, function (_ref7) {
var sort = _ref7.sort;
return sort;
})), _toConsumableArray(sortBy(columns, function (_ref8) {
var sort = _ref8.sort;
return sort;
})), _toConsumableArray(sortBy(rightColumns, function (_ref9) {
var sort = _ref9.sort;
return sort;
})));
}
function getHeaderTexts(_x, _x2) {
return _getHeaderTexts.apply(this, arguments);
}
function _getHeaderTexts() {
_getHeaderTexts = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee3(dataSet, columns) {
var headers,
column,
_args3 = arguments;
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
headers = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : [];
column = columns.shift();
if (!column) {
_context3.next = 10;
break;
}
_context3.t0 = headers;
_context3.t1 = column.name;
_context3.next = 7;
return getReactNodeText(getHeader(column, dataSet));
case 7:
_context3.t2 = _context3.sent;
_context3.t3 = {
name: _context3.t1,
label: _context3.t2
};
_context3.t0.push.call(_context3.t0, _context3.t3);
case 10:
if (!columns.length) {
_context3.next = 13;
break;
}
_context3.next = 13;
return getHeaderTexts(dataSet, columns, headers);
case 13:
return _context3.abrupt("return", headers);
case 14:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
return _getHeaderTexts.apply(this, arguments);
}
var TableStore =
/*#__PURE__*/
function () {
function TableStore(node) {
var _this = this;
_classCallCheck(this, TableStore);
this.editors = new Map();
this.mouseBatchChooseStartId = 0;
this.mouseBatchChooseEndId = 0;
this.mouseBatchChooseState = false;
this.inBatchExpansion = false;
this.handleSelectAllChange = action(function (value) {
var _this$props = _this.props,
dataSet = _this$props.dataSet,
filter = _this$props.filter;
if (value) {
dataSet.selectAll(filter);
} else {
dataSet.unSelectAll();
if (_this.showCachedSelection) {
dataSet.clearCachedSelected();
}
}
});
this.saveCustomizedDebounce = debounce(this.saveCustomized, 1000);
runInAction(function () {
_this.showCachedSelection = false;
_this.lockColumnsHeadRowsHeight = {};
_this.lockColumnsBodyRowsHeight = {};
_this.lockColumnsFootRowsHeight = {};
_this.node = node;
_this.expandedRows = [];
_this.lastScrollTop = 0;
_this.multiLineHeight = [];
_this.rowHighLight = false;
_this.customizedActiveKey = ['columns'];
_this.originalColumns = [];
_this.tempCustomized = {
columns: {}
};
_this.customized = {
columns: {}
};
_this.setProps(node.props);
if (_this.customizable) {
_this.loadCustomized().then(function () {
_this.initColumns();
});
} else {
_this.initColumns();
}
});
}
_createClass(TableStore, [{
key: "customizedColumnHeader",
value: function customizedColumnHeader() {
return React.createElement(CustomizationColumnHeader, {
onHeaderClick: this.openCustomizationModal
});
}
}, {
key: "getColumnTooltip",
value: function getColumnTooltip(column) {
var tooltip = column.tooltip;
if (tooltip) {
return tooltip;
}
return getConfig('tableColumnTooltip');
}
}, {
key: "getColumnHeaders",
value: function getColumnHeaders() {
var leafNamedColumns = this.leafNamedColumns,
dataSet = this.dataSet;
return getHeaderTexts(dataSet, leafNamedColumns.slice());
}
}, {
key: "showEditor",
value: function showEditor(name) {
this.currentEditorName = name;
}
}, {
key: "setLastScrollTop",
value: function setLastScrollTop(lastScrollTop) {
this.lastScrollTop = lastScrollTop;
}
}, {
key: "hideEditor",
value: function hideEditor() {
this.currentEditorName = undefined;
}
}, {
key: "changeMouseBatchChooseIdList",
value: function changeMouseBatchChooseIdList(idList) {
this.mouseBatchChooseIdList = idList;
}
}, {
key: "showNextEditor",
value: function showNextEditor(name, reserve) {
if (reserve) {
this.dataSet.pre();
} else {
this.dataSet.next();
}
this.showEditor(name);
}
}, {
key: "setProps",
value: function setProps(props) {
this.props = props;
}
}, {
key: "updateProps",
value: function updateProps(props) {
var _this2 = this;
this.setProps(props);
var customizedCode = this.props.customizedCode;
if (this.customizable && customizedCode !== props.customizedCode) {
this.loadCustomized().then(function () {
return _this2.initColumns();
});
} else {
this.initColumns();
}
}
}, {
key: "initColumns",
value: function initColumns() {
var customized = this.customized,
customizable = this.customizable;
var _this$props2 = this.props,
columns = _this$props2.columns,
children = _this$props2.children;
var customizedColumns = customizable ? customized.columns : undefined;
this.originalColumns = columns ? mergeDefaultProps(columns, customizedColumns) : normalizeColumns(children, customizedColumns);
}
}, {
key: "isRowExpanded",
value: function isRowExpanded(record) {
var _record$isExpanded = record.isExpanded,
isExpanded = _record$isExpanded === void 0 ? this.expandedRows.indexOf(record.key) !== -1 : _record$isExpanded;
return isExpanded && (!this.isTree || !record.parent || this.isRowExpanded(record.parent));
}
/**
*
* @param record 想修改的record
* @param expanded 设置是否展开
* @param disHandler 设置是否需要触发展开事件
*/
}, {
key: "setRowExpanded",
value: function setRowExpanded(record, expanded, disHandler) {
record.isExpanded = expanded;
if (!this.inBatchExpansion) {
var index = this.expandedRows.indexOf(record.key);
if (expanded) {
if (index === -1) {
this.expandedRows.push(record.key);
}
} else if (index !== -1) {
this.expandedRows.splice(index, 1);
}
}
var onExpand = this.props.onExpand;
if (onExpand && !disHandler) {
onExpand(expanded, record);
}
if (expanded && this.canTreeLoadData) {
this.onTreeNodeLoad({
record: record
});
}
}
}, {
key: "isRowPending",
value: function isRowPending(record) {
return record.pending === true;
}
}, {
key: "setRowPending",
value: function setRowPending(record, pending) {
record.pending = pending;
}
}, {
key: "isRowLoaded",
value: function isRowLoaded(record) {
return record.childrenLoaded === true;
}
}, {
key: "setRowLoaded",
value: function setRowLoaded(record, loaded) {
record.childrenLoaded = loaded;
}
}, {
key: "isRowHover",
value: function isRowHover(record) {
return this.hoverRow === record;
}
}, {
key: "isRowClick",
value: function isRowClick(record) {
return this.clickRow === record;
}
}, {
key: "setRowClicked",
value: function setRowClicked(record, click) {
this.clickRow = click ? record : undefined;
}
}, {
key: "setRowHighLight",
value: function setRowHighLight(highLight) {
this.rowHighLight = highLight;
}
}, {
key: "setRowHover",
value: function setRowHover(record, hover) {
this.hoverRow = hover ? record : undefined;
}
}, {
key: "setMultiLineHeight",
value: function setMultiLineHeight(multiLineHeight) {
this.multiLineHeight.push(multiLineHeight);
}
}, {
key: "expandAll",
value: function expandAll() {
var _this3 = this;
this.inBatchExpansion = true;
this.expandedRows = this.dataSet.records.map(function (record) {
_this3.setRowExpanded(record, true);
return record.key;
});
this.inBatchExpansion = false;
}
}, {
key: "collapseAll",
value: function collapseAll() {
var _this4 = this;
this.inBatchExpansion = true;
this.dataSet.records.forEach(function (record) {
return _this4.setRowExpanded(record, false);
});
this.expandedRows = [];
this.inBatchExpansion = false;
}
}, {
key: "onTreeNodeLoad",
value: function () {
var _onTreeNodeLoad = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee(_ref10) {
var record, _this$props3, dataSet, treeLoadData, treeAsync, promises, _dataSet$props, idField, parentField, id;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
record = _ref10.record;
_this$props3 = this.props, dataSet = _this$props3.dataSet, treeLoadData = _this$props3.treeLoadData, treeAsync = _this$props3.treeAsync;
promises = [];
this.setRowPending(record, true);
if (treeAsync && dataSet) {
_dataSet$props = dataSet.props, idField = _dataSet$props.idField, parentField = _dataSet$props.parentField;
if (idField && parentField && record && !record.children) {
id = record.get(idField);
promises.push(dataSet.queryMore(-1, _defineProperty({}, parentField, id)));
}
}
if (treeLoadData) {
promises.push(treeLoadData({
record: record,
dataSet: dataSet
}));
}
_context.prev = 6;
_context.next = 9;
return Promise.all(promises);
case 9:
this.setRowLoaded(record, true);
case 10:
_context.prev = 10;
this.setRowPending(record, false);
return _context.finish(10);
case 13:
case "end":
return _context.stop();
}
}
}, _callee, this, [[6,, 10, 13]]);
}));
function onTreeNodeLoad(_x3) {
return _onTreeNodeLoad.apply(this, arguments);
}
return onTreeNodeLoad;
}()
}, {
key: "getLeafColumns",
value: function getLeafColumns(columns) {
var _this5 = this;
var leafColumns = [];
columns.forEach(function (column) {
if (!column.children || column.children.length === 0) {
leafColumns.push(column);
} else {
leafColumns.push.apply(leafColumns, _toConsumableArray(_this5.getLeafColumns(column.children)));
}
});
return leafColumns;
}
}, {
key: "renderSelectionBox",
value: function renderSelectionBox(_ref11) {
var record = _ref11.record;
return _renderSelectionBox({
record: record,
store: this
});
}
}, {
key: "renderRowNumber",
value: function renderRowNumber(_ref12) {
var record = _ref12.record,
dataSet = _ref12.dataSet;
var isTree = this.isTree,
rowNumber = this.props.rowNumber;
var numbers = getRowNumbers(record, dataSet, isTree);
var number = numbers.join('-');
if (typeof rowNumber === 'function') {
return rowNumber({
record: record,
dataSet: dataSet,
text: number,
pathNumbers: numbers
});
}
return number;
}
}, {
key: "renderDragBox",
value: function renderDragBox(_ref13) {
var record = _ref13.record;
var rowDragRender = this.props.rowDragRender;
if (rowDragRender && isFunction(rowDragRender.renderIcon)) {
return rowDragRender.renderIcon({
record: record
});
}
return React.createElement(Icon, {
type: "baseline-drag_indicator"
});
}
}, {
key: "changeCustomizedColumnValue",
value: function changeCustomizedColumnValue(column, value) {
var columns = this.customized.columns;
set(column, value);
var columnKey = getColumnKey(column).toString();
var oldCustomized = _get(columns, columnKey);
set(columns, columnKey, _objectSpread({}, oldCustomized, {}, value));
this.saveCustomizedDebounce();
}
}, {
key: "saveCustomized",
value: function saveCustomized(customized) {
if (this.customizable) {
var customizedCode = this.props.customizedCode;
if (customized) {
this.customized = customized;
}
if (customizedCode) {
var tableCustomizedSave = getConfig('tableCustomizedSave');
tableCustomizedSave(customizedCode, this.customized);
}
}
}
}, {
key: "openCustomizationModal",
value: function openCustomizationModal(modal) {
var customizedCode = this.props.customizedCode;
var modalProps = {
drawer: true,
size: Size.small,
children: React.createElement(CustomizationSettings, null),
bodyStyle: {
overflow: 'hidden auto',
padding: 0
}
};
if (customizedCode) {
modalProps.okText = $l('Table', 'save_button');
}
modal.open(modalProps);
}
}, {
key: "loadCustomized",
value: function () {
var _loadCustomized = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee2() {
var _this6 = this;
var customizedCode, tableCustomizedLoad, customized;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
customizedCode = this.props.customizedCode;
if (!(this.customizable && customizedCode)) {
_context2.next = 12;
break;
}
tableCustomizedLoad = getConfig('tableCustomizedLoad');
runInAction(function () {
_this6.loading = true;
});
_context2.prev = 4;
_context2.next = 7;
return tableCustomizedLoad(customizedCode);
case 7:
customized = _context2.sent;
if (customized) {
runInAction(function () {
_this6.customized = _objectSpread({
columns: {}
}, customized);
});
}
case 9:
_context2.prev = 9;
runInAction(function () {
_this6.loading = false;
});
return _context2.finish(9);
case 12:
case "end":
return _context2.stop();
}
}
}, _callee2, this, [[4,, 9, 12]]);
}));
function loadCustomized() {
return _loadCustomized.apply(this, arguments);
}
return loadCustomized;
}()
}, {
key: "multipleSelectionRenderer",
value: function multipleSelectionRenderer() {
return React.createElement(ObserverCheckBox, {
checked: this.allChecked,
indeterminate: this.indeterminate,
onChange: this.handleSelectAllChange,
value: true
});
}
}, {
key: "dataSet",
get: function get() {
return this.props.dataSet;
}
}, {
key: "prefixCls",
get: function get() {
var _this$props4 = this.props,
suffixCls = _this$props4.suffixCls,
prefixCls = _this$props4.prefixCls;
return getProPrefixCls(suffixCls, prefixCls);
}
}, {
key: "customizable",
get: function get() {
if (this.columnTitleEditable || this.columnDraggable || this.columnHideable) {
if ('customizable' in this.props) {
return this.props.customizable;
}
return getConfig('tableCustomizable');
}
return false;
}
}, {
key: "autoHeight",
get: function get() {
var autoHeight = this.props.autoHeight;
if (autoHeight) {
var defaultAutoHeight = {
type: TableAutoHeightType.minHeight,
diff: getConfig('tableAutoHeightDiff') || 80
};
if (isObject(autoHeight)) {
return _objectSpread({}, defaultAutoHeight, {}, autoHeight);
}
return defaultAutoHeight;
}
return undefined;
}
}, {
key: "heightType",
get: function get() {
var tempHeightType = _get(this.tempCustomized, 'heightType');
if (tempHeightType !== undefined) {
return tempHeightType;
}
var heightType = this.customized.heightType;
if (heightType !== undefined) {
return heightType;
}
return this.originalHeightType;
}
}, {
key: "originalHeightType",
get: function get() {
var _this$props5 = this.props,
style = _this$props5.style,
autoHeight = _this$props5.autoHeight;
if (autoHeight) {
return TableHeightType.flex;
}
if (style) {
var height = style.height;
if (isString(height) && isCalcSize(height)) {
return TableHeightType.flex;
}
if (isNumber(toPx(height))) {
return TableHeightType.fixed;
}
}
return TableHeightType.auto;
}
/**
* number 矫正虚拟滚动由于样式问题导致的高度不符问题
*/
}, {
key: "virtualRowHeight",
get: function get() {
var virtualRowHeight = this.props.virtualRowHeight;
if (virtualRowHeight) {
return virtualRowHeight;
}
return isNumber(this.rowHeight) ? this.rowHeight + 3 : 33;
}
}, {
key: "virtual",
get: function get() {
return this.props.virtual && this.height !== undefined && isNumber(this.virtualRowHeight);
}
}, {
key: "virtualHeight",
get: function get() {
var virtualRowHeight = this.virtualRowHeight,
data = this.data;
return Math.round(data.length * virtualRowHeight);
}
}, {
key: "virtualStartIndex",
get: function get() {
var virtualRowHeight = this.virtualRowHeight,
lastScrollTop = this.lastScrollTop;
return Math.max(Math.round(lastScrollTop / virtualRowHeight - 3), 0);
}
}, {
key: "virtualTop",
get: function get() {
var virtualRowHeight = this.virtualRowHeight,
virtualStartIndex = this.virtualStartIndex;
return virtualStartIndex * virtualRowHeight;
}
}, {
key: "virtualData",
get: function get() {
var data = this.data,
height = this.height,
virtualRowHeight = this.virtualRowHeight,
virtual = this.props.virtual;
if (virtual && height !== undefined && isNumber(virtualRowHeight)) {
var lastScrollTop = this.lastScrollTop,
virtualStartIndex = this.virtualStartIndex;
var virtualEndIndex = Math.min(Math.round((lastScrollTop + height) / virtualRowHeight) + 3, data.length);
return data.slice(virtualStartIndex, virtualEndIndex);
}
return data;
}
}, {
key: "hidden",
get: function get() {
return !!this.styledHidden || this.props.hidden;
}
}, {
key: "alwaysShowRowBox",
get: function get() {
if ('alwaysShowRowBox' in this.props) {
return this.props.alwaysShowRowBox;
}
var alwaysShowRowBox = getConfig('tableAlwaysShowRowBox');
if (typeof alwaysShowRowBox !== 'undefined') {
return alwaysShowRowBox;
}
return false;
}
}, {
key: "keyboard",
get: function get() {
if ('keyboard' in this.props) {
return this.props.keyboard;
}
var keyboard = getConfig('tableKeyboard');
if (typeof keyboard !== 'undefined') {
return keyboard;
}
return false;
}
}, {
key: "columnResizable",
get: function get() {
if (this.currentEditRecord) {
return false;
}
if ('columnResizable' in this.props) {
return this.props.columnResizable;
}
return getConfig('tableColumnResizable') !== false;
}
}, {
key: "columnHideable",
get: function get() {
if ('columnHideable' in this.props) {
return this.props.columnHideable;
}
return getConfig('tableColumnHideable') !== false;
}
/**
* 表头支持编辑
*/
}, {
key: "columnTitleEditable",
get: function get() {
if ('columnTitleEditable' in this.props) {
return this.props.columnTitleEditable;
}
return getConfig('tableColumnTitleEditable') === true;
}
}, {
key: "pagination",
get: function get() {
if ('pagination' in this.props) {
return this.props.pagination;
}
return getConfig('pagination');
}
}, {
key: "dragColumnAlign",
get: function get() {
if ('dragColumnAlign' in this.props) {
return this.props.dragColumnAlign;
}
return getConfig('tableDragColumnAlign');
}
}, {
key: "columnDraggable",
get: function get() {
if ('columnDraggable' in this.props) {
return this.props.columnDraggable;
}
if ('dragColumn' in this.props) {
return this.props.dragColumn;
}
if (getConfig('tableColumnDraggable') === true) {
return true;
}
return getConfig('tableDragColumn') === true;
}
}, {
key: "rowDraggable",
get: function get() {
if (this.isTree) {
return false;
}
if ('rowDraggable' in this.props) {
return this.props.rowDraggable;
}
if ('dragRow' in this.props) {
return this.props.dragRow;
}
if (getConfig('tableRowDraggable') === true) {
return true;
}
return getConfig('tableDragRow') === true;
}
}, {
key: "rowHeight",
get: function get() {
if ('rowHeight' in this.props) {
return this.props.rowHeight;
}
var rowHeight = getConfig('tableRowHeight');
if (typeof rowHeight !== 'undefined') {
return rowHeight;
}
return 30;
}
}, {
key: "autoFootHeight",
get: function get() {
if ('autoFootHeight' in this.props) {
return this.props.autoFootHeight;
}
return false;
}
}, {
key: "emptyText",
get: function get() {
return getConfig('renderEmpty')('Table');
}
}, {
key: "highLightRow",
get: function get() {
if ('highLightRow' in this.props) {
return this.props.highLightRow;
}
var tableHighLightRow = getConfig('tableHighLightRow');
if (tableHighLightRow === false) {
return false;
}
return tableHighLightRow;
}
}, {
key: "parityRow",
get: function get() {
if ('parityRow' in this.props) {
return this.props.parityRow;
}
return getConfig('tableParityRow') === true;
}
}, {
key: "autoFocus",
get: function get() {
if ('autoFocus' in this.props) {
return this.props.autoFocus;
}
return getConfig('tableAutoFocus') !== false;
}
}, {
key: "selectedHighLightRow",
get: function get() {
if ('selectedHighLightRow' in this.props) {
return this.props.selectedHighLightRow;
}
return getConfig('tableSelectedHighLightRow') !== false;
}
}, {
key: "editorNextKeyEnterDown",
get: function get() {
if ('editorNextKeyEnterDown' in this.props) {
return this.props.editorNextKeyEnterDown;
}
return getConfig('tableEditorNextKeyEnterDown') !== false;
}
}, {
key: "border",
get: function get() {
if ('border' in this.props) {
return this.props.border;
}
return getConfig('tableBorder') !== false;
}
}, {
key: "queryBar",
get: function get() {
return this.props.queryBar || getConfig('queryBar');
}
}, {
key: "expandIcon",
get: function get() {
return this.props.expandIcon || getConfig('tableExpandIcon');
}
}, {
key: "pristine",
get: function get() {
return this.props.pristine;
}
}, {
key: "currentEditRecord",
get: function get() {
return this.dataSet.find(function (record) {
return record.editing === true;
});
},
set: function set(record) {
var _this7 = this;
runInAction(function () {
var currentEditRecord = _this7.currentEditRecord,
dataSet = _this7.dataSet;
if (currentEditRecord) {
if (currentEditRecord.isNew) {
dataSet.remove(currentEditRecord);
} else {
currentEditRecord.reset();
currentEditRecord.editing = false;
}
}
if (record) {
record.editing = true;
}
});
}
}, {
key: "isTree",
get: function get() {
return this.props.mode === TableMode.tree;
}
}, {
key: "editing",
get: function get() {
return this.currentEditorName !== undefined || this.currentEditRecord !== undefined;
}
}, {
key: "hasRowBox",
get: function get() {
var _this$props6 = this.props,
dataSet = _this$props6.dataSet,
selectionMode = _this$props6.selectionMode;
var alwaysShowRowBox = this.alwaysShowRowBox;
if (dataSet) {
var selection = dataSet.selection;
return selection && (selectionMode === SelectionMode.rowbox || alwaysShowRowBox);
}
return false;
}
}, {
key: "useMouseBatchChoose",
get: function get() {
var useMouseBatchChoose = this.props.useMouseBatchChoose;
if (useMouseBatchChoose !== undefined) {
return useMouseBatchChoose;
}
if (getConfig('tableUseMouseBatchChoose') !== undefined) {
return getConfig('tableUseMouseBatchChoose');
}
return false;
}
}, {
key: "showSelectionTips",
get: function get() {
var showSelectionTips = this.props.showSelectionTips;
if (showSelectionTips !== undefined) {
return showSelectionTips;
}
if (getConfig('tableShowSelectionTips') !== undefined) {
return getConfig('tableShowSelectionTips');
}
return false;
}
}, {
key: "overflowX",
get: function get() {
if (isNumber(this.width)) {
return this.totalLeafColumnsWidth > this.width;
}
return false;
}
}, {
key: "overflowY",
get: function get() {
var bodyHeight = this.bodyHeight,
height = this.height;
return bodyHeight !== undefined && height !== undefined && height < bodyHeight + (this.overflowX ? measureScrollbar() : 0);
}
}, {
key: "customizedColumn",
get: function get() {
if (this.customizable && (!this.rowDraggable || this.dragColumnAlign !== DragColumnAlign.right)) {
return {
key: CUSTOMIZED_KEY,
resizable: false,
titleEditable: false,
align: ColumnAlign.center,
width: 30,
lock: ColumnLock.right,
header: this.customizedColumnHeader,
headerClassName: "".concat(this.prefixCls, "-customized-column")
};
}
return undefined;
}
}, {
key: "expandColumn",
get: function get() {
if (this.expandIconAsCell) {
return {
key: EXPAND_KEY,
resizable: false,
titleEditable: false,
align: ColumnAlign.center,
width: 50,
lock: true
};
}
return undefined;
}
}, {
key: "rowNumberColumn",
get: function get() {
var rowNumber = this.props.rowNumber;
if (rowNumber) {
return {
key: ROW_NUMBER_KEY,
resizable: false,
titleEditable: false,
headerClassName: "".concat(this.prefixCls, "-row-number-column"),
renderer: this.renderRowNumber,
tooltip: TableColumnTooltip.overflow,
align: ColumnAlign.center,
width: 50,
lock: true
};
}
return undefined;
}
}, {
key: "selectionColumn",
get: function get() {
if (this.hasRowBox) {
var dataSet = this.dataSet,
prefixCls = this.prefixCls;
var selectionColumn = {
key: SELECTION_KEY,
resizable: false,
titleEditable: false,
className: "".concat(prefixCls, "-selection-column"),
renderer: this.renderSelectionBox,
align: ColumnAlign.center,
width: 50,
lock: true
};
if (dataSet && dataSet.selection === DataSetSelection.multiple) {
selectionColumn.header = this.multipleSelectionRenderer;
selectionColumn.footer = this.multipleSelectionRenderer;
}
return selectionColumn;
}
return undefined;
}
}, {
key: "draggableColumn",
get: function get() {
var dragColumnAlign = this.dragColumnAlign,
rowDraggable = this.rowDraggable,
prefixCls = this.prefixCls;
if (dragColumnAlign && rowDraggable) {
var draggableColumn = {
key: DRAG_KEY,
resizable: false,
titleEditable: false,
className: "".concat(prefixCls, "-drag-column"),
renderer: this.renderDragBox,
align: ColumnAlign.center,
width: 50
};
if (dragColumnAlign === DragColumnAlign.left) {
draggableColumn.lock = ColumnLock.left;
}
if (dragColumnAlign === DragColumnAlign.right) {
draggableColumn.lock = ColumnLock.right;
draggableColumn.header = this.customizable && this.customizedColumnHeader;
}
return draggableColumn;
}
return undefined;
}
}, {
key: "columns",
get: function get() {
var dragColumnAlign = this.dragColumnAlign,
originalColumns = this.originalColumns,
expandColumn = this.expandColumn,
draggableColumn = this.draggableColumn,
rowNumberColumn = this.rowNumberColumn,
selectionColumn = this.selectionColumn,
customizedColumn = this.customizedColumn;
return observable.array([expandColumn, dragColumnAlign === DragColumnAlign.left ? draggableColumn : undefined, rowNumberColumn, selectionColumn].concat(_toConsumableArray(originalColumns), [customizedColumn, dragColumnAlign === DragColumnAlign.right ? draggableColumn : undefined])).filter(columnFilter);
}
}, {
key: "leftColumns",
get: function get() {
return this.columns.filter(function (column) {
return column.lock === ColumnLock.left || column.lock === true;
});
}
}, {
key: "centerColumns",
get: function get() {
return this.columns.filter(function (column) {
return !column.lock;
});
}
}, {
key: "rightColumns",
get: function get() {
return this.columns.filter(function (column) {
return column.lock === ColumnLock.right;
});
}
}, {
key: "columnGroups",
get: function get() {
return new ColumnGroups(this.columns);
}
}, {
key: "groupedColumns",
get: function get() {
return this.columnGroups.columns;
}
}, {
key: "leftGroupedColumns",
get: function get() {
return this.groupedColumns.filter(function (_ref14) {
var lock = _ref14.column.lock;
return lock === ColumnLock.left || lock === true;
});
}
}, {
key: "centerGroupedColumns",
get: function get() {
return this.groupedColumns.filter(function (_ref15) {
var lock = _ref15.column.lock;
return !lock;
});
}
}, {
key: "rightGroupedColumns",
get: function get() {
return this.groupedColumns.filter(function (_ref16) {
var lock = _ref16.column.lock;
return lock === ColumnLock.right;
});
}
}, {
key: "leafColumns",
get: function get() {
return this.getLeafColumns(this.columns);
}
}, {
key: "leftLeafColumns",
get: function get() {
return this.getLeafColumns(this.leftColumns);
}
}, {
key: "centerLeafColumns",
get: function get() {
return this.getLeafColumns(this.centerColumns);
}
}, {
key: "rightLeafColumns",
get: function get() {
return this.getLeafColumns(this.rightColumns);
}
}, {
key: "leafNamedColumns",
get: function get() {
return this.leafColumns.filter(function (column) {
return !!column.name;
});
}
}, {
key: "totalLeafColumnsWidth",
get: function get() {
return this.leafColumns.reduce(function (total, column) {
return total + columnWidth(column);
}, 0);
}
}, {
key: "leftLeafColumnsWidth",
get: function get() {
return this.leftLeafColumns.reduce(function (total, column) {
return total + columnWidth(column);
}, 0);
}
}, {
key: "rightLeafColumnsWidth",
get: function get() {
return this.rightLeafColumns.reduce(function (total, column) {
return total + columnWidth(column);
}, 0);
}
}, {
key: "hasCheckFieldColumn",
get: function get() {
var checkField = this.dataSet.props.checkField;
return this.leafColumns.some(function (_ref17) {
var name = _ref17.name,
editor = _ref17.editor;
return !!editor && checkField === name;
});
}
}, {
key: "hasFooter",
get: function get() {
return this.leafColumns.some(function (column) {
return !!column.footer && column.key !== SELECTION_KEY;
});
}
}, {
key: "isAnyColumnsResizable",
get: function get() {
return this.leafColumns.some(function (column) {
return column.resizable === true;
});
}
}, {
key: "isAnyColumnsLock",
get: function get() {
return this.columns.some(function (column) {
return !!column.lock;
});
}
}, {
key: "isAnyColumnsLeftLock",
get: function get() {
return this.columns.some(function (column) {
return column.lock === ColumnLock.left || column.lock === true;
});
}
}, {
key: "isAnyColumnsRightLock",
get: function get() {
return this.columns.some(function (column) {
return column.lock === ColumnLock.right;
});
}
}, {
key: "data",
get: function get() {
var _this$props7 = this.props,
filter = _this$props7.filter,
pristine = _this$props7.pristine;
var dataSet = this.dataSet,
isTree = this.isTree,
showCachedSelection = this.showCachedSelection;
var data = isTree ? dataSet.treeRecords : dataSet.records;
if (typeof filter === 'function') {
data = data.filter(filter);
}
if (pristine) {
data = data.filter(function (record) {
return !record.isNew;
});
}
if (showCachedSelection) {
return [].concat(_toConsumableArray(dataSet.cachedSelected), _toConsumableArray(data));
}
return data;
}
}, {
key: "indeterminate",
get: function get() {
var dataSet = this.dataSet;
if (dataSet) {
var selectedLength = dataSet.currentSelected.length;
return !!selectedLength && selectedLength !== dataSet.records.filter(function (record) {
return record.selectable;
}).length;
}
return false;
}
}, {
key: "allChecked",
get: function get() {
var dataSet = this.dataSet;
if (dataSet) {
var selectedLength = dataSet.currentSelected.length;
return !!selectedLength && selectedLength === dataSet.records.filter(function (record) {
return record.selectable;
}).length;
}
return false;
}
}, {
key: "expandIconAsCell",
get: function get() {
var _this$props8 = this.props,
expandedRowRenderer = _this$props8.expandedRowRenderer,
expandIconAsCell = _this$props8.expandIconAsCell;
if (expandIconAsCell !== undefined) {
return expandIconAsCell;
}
return !!expandedRowRenderer && !this.isTree;
}
}, {
key: "expandIconColumnIndex",
get: function get() {
var expandIconAsCell = this.expandIconAsCell,
dragColumnAlign = this.dragColumnAlign,
rowDraggable = this.rowDraggable,
_this$props9 = this.props,
_this$props9$expandIc = _this$props9.expandIconColumnIndex,
expandIconColumnIndex = _this$props9$expandIc === void 0 ? 0 : _this$props9$expandIc,
rowNumber = _this$props9.rowNumber;
if (expandIconAsCell) {
return 0;
}
return expandIconColumnIndex + [this.hasRowBox, rowNumber, dragColumnAlign && rowDraggable].filter(Boolean).length;
}
}, {
key: "inlineEdit",
get: function get() {
return this.props.editMode === TableEditMode.inline;
}
}, {
key: "canTreeLoadData",
get: function get() {
var _this$props10 = this.props,
treeLoadData = _this$props10.treeLoadData,
treeAsync = _this$props10.treeAsync;
return treeAsync || !!treeLoadData;
}
}, {
key: "isRowHighLight",
get: function get() {
return this.rowHighLight || this.highLightRow === true;
}
}]);
return TableStore;
}();
export { TableStore as default };
__decorate([observable], TableStore.prototype, "props", void 0);
__decorate([observable], TableStore.prototype, "customized", void 0);
__decorate([observable], TableStore.prototype, "tempCustomized", void 0);
__decorate([observable], TableStore.prototype, "loading", void 0);
__decorate([observable], TableStore.prototype, "originalColumns", void 0);
__decorate([observable], TableStore.prototype, "bodyHeight", void 0);
__decorate([observable], TableStore.prototype, "width", void 0);
__decorate([observable], TableStore.prototype, "height", void 0);
__decorate([observable], TableStore.prototype, "totalHeight", void 0);
__decorate([observable], TableStore.prototype, "lastScrollTop", void 0);
__decorate([observable], TableStore.prototype, "lockColumnsBodyRowsHeight", void 0);
__decorate([observable], TableStore.prototype, "lockColumnsFootRowsHeight", void 0);
__decorate([observable], TableStore.prototype, "lockColumnsHeadRowsHeight", void 0);
__decorate([observable], TableStore.prototype, "expandedRows", void 0);
__decorate([observable], TableStore.prototype, "isHeaderHover", void 0);
__decorate([observable], TableStore.prototype, "hoverRow", void 0);
__decorate([observable], TableStore.prototype, "clickRow", void 0);
__decorate([observable], TableStore.prototype, "currentEditorName", void 0);
__decorate([observable], TableStore.prototype, "styledHidden", void 0);
__decorate([observable], TableStore.prototype, "rowHighLight", void 0);
__decorate([observable], TableStore.prototype, "customizedActiveKey", void 0);
__decorate([observable], TableStore.prototype, "mouseBatchChooseIdList", void 0);
__decorate([observable], TableStore.prototype, "multiLineHeight", void 0);
__decorate([observable], TableStore.prototype, "columnResizing", void 0);
__decorate([computed], TableStore.prototype, "dataSet", null);
__decorate([computed], TableStore.prototype, "prefixCls", null);
__decorate([computed], TableStore.prototype, "customizable", null);
__decorate([computed], TableStore.prototype, "autoHeight", null);
__decorate([computed], TableStore.prototype, "heightType", null);
__decorate([computed], TableStore.prototype, "originalHeightType", null);
__decorate([computed], TableStore.prototype, "virtualRowHeight", null);
__decorate([computed], TableStore.prototype, "virtual", null);
__decorate([computed], TableStore.prototype, "virtualHeight", null);
__decorate([computed], TableStore.prototype, "virtualStartIndex", null);
__decorate([computed], TableStore.prototype, "virtualTop", null);
__decorate([computed], TableStore.prototype, "virtualData", null);
__decorate([computed], TableStore.prototype, "alwaysShowRowBox", null);
__decorate([computed], TableStore.prototype, "keyboard", null);
__decorate([computed], TableStore.prototype, "columnResizable", null);
__decorate([computed], TableStore.prototype, "columnHideable", null);
__decorate([computed], TableStore.prototype, "columnTitleEditable", null);
__decorate([co