choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
1,524 lines (1,281 loc) • 140 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
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 _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _extends from "@babel/runtime/helpers/extends";
var _excluded = ["lock", "className", "headerClassName", "footerClassName"];
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { __decorate } from "tslib";
import React, { Children, isValidElement } from 'react';
import { action, computed, get as _get, observable, reaction, runInAction, set } from 'mobx';
import classNames from 'classnames';
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 lodashGet from 'lodash/get';
import defaultTo from 'lodash/defaultTo';
import { warning } from 'choerodon-ui/dataset/utils';
import measureScrollbar from '../../../es/_util/measureScrollbar';
import { isCalcSize, pxToRem, scaleSize, toPx } from '../../../es/_util/UnitConvertor';
import Icon from '../../../es/icon';
import isFunction from 'lodash/isFunction';
import omit from 'lodash/omit';
import pick from 'lodash/pick';
import noop from 'lodash/noop';
import { ColumnDefaultProps, defaultAggregationRenderer } from './Column';
import CustomizationSettings from './customization-settings/CustomizationSettings';
import isFragment from '../_util/isFragment';
import ObserverCheckBox from '../check-box/CheckBox';
import ObserverRadio from '../radio/Radio';
import { DataSetSelection, FieldType, RecordCachedType } from '../data-set/enum';
import { ColumnAlign, ColumnLock, DragColumnAlign, GroupType, RowBoxPlacement, ScrollPosition, SelectionMode, TableAutoHeightType, TableBoxSizing, TableColumnTooltip, TableEditMode, TableHeightType, TableMode, TableQueryBarType } from './enum';
import { stopPropagation } from '../_util/EventManager';
import { getCachedSelectableCounts, getCachedSelectableRecords, getColumnKey, getCurrentSelectableCounts, getHeader, isDisabledRow } 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';
import ComboCustomizationSettings from './combo-customization-settings';
import Dropdown from '../dropdown/Dropdown';
import Menu from '../menu';
import Modal from '../modal/Modal';
import { treeMap, treeSome } from '../_util/treeUtils';
import { getIf, mergeGroupStates, normalizeGroups } from '../data-set/utils';
import BatchRunner from '../_util/BatchRunner';
import { LabelLayout } from '../form/enum';
export var SELECTION_KEY = '__selection-column__'; // TODO:Symbol
export var COMBOBAR_KEY = '__combo-column__'; // TODO:Symbol
export var ROW_NUMBER_KEY = '__row-number-column__'; // TODO:Symbol
export var DRAG_KEY = '__drag-column__'; // TODO:Symbol
export var EXPAND_KEY = '__expand-column__'; // TODO:Symbol
export var CUSTOMIZED_KEY = '__customized-column__'; // TODO:Symbol
export var AGGREGATION_EXPAND_CELL_KEY = '__aggregation-expand-cell__'; // TODO:Symbol
export var BODY_EXPANDED = '__body_expanded__'; // TODO:Symbol
export var VIRTUAL_ROOT_MARGIN = 50;
function columnFilter(column) {
return Boolean(column);
}
function getOverScanCount(tableStore, index, next) {
var rowMetaData = tableStore.rowMetaData;
if (rowMetaData) {
var count = 0;
var height = 0;
while (height < VIRTUAL_ROOT_MARGIN) {
index += next ? 1 : -1;
var metaData = rowMetaData[index];
if (!metaData) {
return count;
}
height += metaData.height;
count++;
}
return count;
}
return Math.ceil(VIRTUAL_ROOT_MARGIN / tableStore.virtualRowHeight);
}
function getItemMetadata(rowMetaData, index, tableStore) {
var lastMeasuredIndex = tableStore.lastMeasuredIndex;
if (index > lastMeasuredIndex) {
tableStore.lastMeasuredIndex = index;
}
return rowMetaData[index];
}
function findNearestItemBinarySearch(rowMetaData, tableStore, high, low, offset) {
while (low <= high) {
var middle = low + Math.floor((high - low) / 2);
var item = getItemMetadata(rowMetaData, middle, tableStore);
if (!item) {
return 0;
}
var currentOffset = item.offset;
if (currentOffset === offset) {
return middle;
}
if (currentOffset < offset) {
low = middle + 1;
}
if (currentOffset > offset) {
high = middle - 1;
}
}
if (low > 0) {
return low - 1;
}
return 0;
}
function overOffset(rowMetaData, tableStore, index, offset) {
var item = getItemMetadata(rowMetaData, index, tableStore);
if (item) {
return item.offset < offset;
}
return false;
}
function findNearestItemExponentialSearch(rowMetaData, tableStore, index, offset) {
var virtualEstimatedRows = tableStore.virtualEstimatedRows;
var interval = 1;
while (index < virtualEstimatedRows && overOffset(rowMetaData, tableStore, index, offset)) {
index += interval;
interval *= 2;
}
return findNearestItemBinarySearch(rowMetaData, tableStore, Math.min(index, virtualEstimatedRows - 1), Math.floor(index / 2), offset);
}
function getVisibleStartIndex(tableStore) {
var getLastScrollTop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
return tableStore.lastScrollTop;
};
var height = tableStore.height,
virtualEstimatedRows = tableStore.virtualEstimatedRows;
if (height === undefined || !virtualEstimatedRows) {
return 0;
}
var lastScrollTop = getLastScrollTop();
var virtualRowHeight = tableStore.virtualRowHeight,
rowMetaData = tableStore.rowMetaData;
if (rowMetaData) {
if (!rowMetaData.length) {
return 0;
}
var lastMeasuredIndex = tableStore.lastMeasuredIndex;
var lastRowMetaData = lastMeasuredIndex > 0 ? rowMetaData[lastMeasuredIndex] : undefined;
var lastMeasuredItemOffset = lastRowMetaData ? lastRowMetaData.offset : 0;
if (lastMeasuredItemOffset >= lastScrollTop) {
return findNearestItemBinarySearch(rowMetaData, tableStore, lastMeasuredIndex, 0, lastScrollTop);
}
return findNearestItemExponentialSearch(rowMetaData, tableStore, Math.max(0, lastMeasuredIndex), lastScrollTop);
}
return Math.max(0, Math.min(virtualEstimatedRows, Math.floor(lastScrollTop / virtualRowHeight)));
}
function getVisibleEndIndex(tableStore) {
var getVirtualVisibleStartIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
return tableStore.virtualVisibleStartIndex;
};
var getLastScrollTop = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
return tableStore.lastScrollTop;
};
var height = tableStore.height,
virtualEstimatedRows = tableStore.virtualEstimatedRows;
if (height === undefined) {
return virtualEstimatedRows;
}
var virtualVisibleStartIndex = getVirtualVisibleStartIndex();
var virtualRowHeight = tableStore.virtualRowHeight,
rowMetaData = tableStore.rowMetaData;
if (rowMetaData) {
if (!rowMetaData.length) {
return 0;
}
var itemMetadata = getItemMetadata(rowMetaData, virtualVisibleStartIndex, tableStore);
if (!itemMetadata) {
return 0;
}
var maxOffset = getLastScrollTop() + height;
var offset = itemMetadata.offset + itemMetadata.height;
var stopIndex = virtualVisibleStartIndex;
while (stopIndex < virtualEstimatedRows - 1 && offset < maxOffset) {
stopIndex++;
var item = getItemMetadata(rowMetaData, stopIndex, tableStore);
if (item) {
offset += item.height;
}
}
return Math.max(0, Math.min(virtualEstimatedRows, stopIndex + 1));
}
var numVisibleItems = Math.ceil(height / virtualRowHeight);
return Math.max(0, Math.min(virtualEstimatedRows, virtualVisibleStartIndex + numVisibleItems));
}
function getStartIndex(tableStore) {
var getVirtualVisibleStartIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
return tableStore.virtualVisibleStartIndex;
};
var virtualVisibleStartIndex = getVirtualVisibleStartIndex();
return Math.max(0, virtualVisibleStartIndex - getOverScanCount(tableStore, virtualVisibleStartIndex));
}
function getEndIndex(tableStore) {
var getVirtualVisibleEndIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
return tableStore.virtualVisibleEndIndex;
};
var virtualVisibleEndIndex = getVirtualVisibleEndIndex();
var virtualEstimatedRows = tableStore.virtualEstimatedRows;
return Math.min(virtualEstimatedRows, virtualVisibleEndIndex + getOverScanCount(tableStore, virtualVisibleEndIndex, true));
}
export function getIdList(store) {
var mouseBatchChooseStartId = store.mouseBatchChooseStartId,
mouseBatchChooseEndId = store.mouseBatchChooseEndId,
element = store.node.element,
prefixCls = store.prefixCls;
var rows = Array.from(element.querySelectorAll(".".concat(prefixCls, "-row")));
var endId;
var idList = [];
rows.some(function (row) {
var index = Number(row.dataset.index);
if (!endId) {
if (mouseBatchChooseStartId === index) {
endId = mouseBatchChooseEndId;
} else if (mouseBatchChooseEndId === index) {
endId = mouseBatchChooseStartId;
}
}
if (endId) {
idList.push(index);
}
return endId === index;
});
return idList;
}
function getRowNumbers(record, dataSet, isTree) {
if (record && dataSet) {
if (record.isCached) {
return [];
}
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 hasCheckField(_ref, checkField) {
var editor = _ref.editor,
name = _ref.name,
hidden = _ref.hidden;
return !hidden && !!editor && checkField === name;
}
function _renderSelectionBox(_ref2) {
var record = _ref2.record,
store = _ref2.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 (selection === DataSetSelection.multiple) {
var lastSelected = store.lastSelected;
if (lastSelected) {
var nativeEvent = e.nativeEvent;
var startIndex = -1;
var endIndex = -1;
if (nativeEvent.shiftKey) {
var pointKeys = new Set([lastSelected.key, record.key]);
dataSet.some(function (pointRecord, index) {
if (pointKeys.has(pointRecord.key)) {
if (startIndex === -1) {
startIndex = index;
} else {
endIndex = index;
return true;
}
}
return false;
});
}
if (endIndex !== -1 && startIndex !== endIndex) {
// Batch update selections
var rangeRecords = dataSet.slice(startIndex, endIndex + 1);
var changedRecords = [];
var selectedKeys = new Set(dataSet.selected.map(function (selected) {
return selected.key;
}));
if (record.isSelected) {
rangeRecords.forEach(function (rangeRecord) {
if (selectedKeys.has(rangeRecord.key)) {
changedRecords.push(rangeRecord);
}
});
dataSet.batchUnSelect(changedRecords);
} else {
rangeRecords.forEach(function (rangeRecord) {
if (!selectedKeys.has(rangeRecord.key)) {
changedRecords.push(rangeRecord);
}
});
dataSet.batchSelect(changedRecords);
}
}
}
store.lastSelected = record;
} else if (record.isSelected) {
dataSet.unSelect(record);
}
};
if (selection === DataSetSelection.multiple) {
var batchSelectProps = {};
var handleDragMouseUp = action(function () {
var mouseBatchChooseIdList = store.mouseBatchChooseIdList;
if (store.mouseBatchChooseState) {
store.mouseBatchChooseState = false;
store.changeMouseBatchChooseIdList([]);
var mouseBatchChooseStartId = store.mouseBatchChooseStartId,
mouseBatchChooseEndId = store.mouseBatchChooseEndId;
if (mouseBatchChooseStartId === mouseBatchChooseEndId) {
return;
}
var startRecord = dataSet.findRecordById(mouseBatchChooseStartId);
var _ref3 = startRecord || {},
isSelected = _ref3.isSelected;
if (isSelected) {
dataSet.batchUnSelect(mouseBatchChooseIdList);
} else {
dataSet.batchSelect(mouseBatchChooseIdList);
}
}
document.removeEventListener('pointerup', handleDragMouseUp);
});
if (store.useMouseBatchChoose) {
batchSelectProps.onMouseDown = action(function () {
store.mouseBatchChooseStartId = record.id;
store.mouseBatchChooseEndId = record.id;
store.mouseBatchChooseState = true; // 为什么使用 pointerup
// 因为需要对disabled的元素进行特殊处理
// 因为状态的改变依赖 mouseup 而在disabled的元素上 无法触发mouseup事件
// 导致状态无法进行修正
// 以下两种方案通过 pointer-events:none 进行处理
// https://stackoverflow.com/questions/322378/javascript-check-if-mouse-button-down
// https://stackoverflow.com/questions/62081666/the-event-of-the-document-is-not-triggered-when-it-is-on-a-disabled-element
// 而使用指针事件可以突破disabled的限制
// https://stackoverflow.com/questions/62126515/how-to-get-the-state-of-the-mouse-through-javascript/62127845#62127845
document.addEventListener('pointerup', handleDragMouseUp);
});
batchSelectProps.onMouseEnter = function () {
if (store.mouseBatchChooseState) {
store.mouseBatchChooseEndId = record.id;
store.changeMouseBatchChooseIdList(getIdList(store));
}
};
}
return /*#__PURE__*/React.createElement(ObserverCheckBox, _extends({}, batchSelectProps, {
checked: record.isSelected,
onChange: handleChange,
onClick: handleClick,
disabled: !record.selectable,
"data-selection-key": SELECTION_KEY,
labelLayout: LabelLayout.none,
value: true
}));
}
if (selection === DataSetSelection.single) {
return /*#__PURE__*/React.createElement(ObserverRadio, {
checked: record.isSelected,
onChange: handleChange,
onClick: handleClick,
disabled: !record.selectable,
"data-selection-key": SELECTION_KEY,
value: true
});
}
}
}
function getCustomizedColumnByKey(key, customizedColumns) {
if (customizedColumns) {
return customizedColumns[key];
}
}
function getCustomizedColumn(column, customizedColumns) {
if (customizedColumns) {
return getCustomizedColumnByKey(getColumnKey(column).toString(), customizedColumns);
}
}
function mergeColumnLock(column, parent, customizedColumn) {
if (parent) {
column.lock = parent.lock;
} else if (customizedColumn && 'lock' in customizedColumn) {
column.lock = customizedColumn.lock;
}
}
function mergeCustomizedColumn(column, tableStore, customizedColumn, isChildrenHideDisabled) {
if (isChildrenHideDisabled) {
column.hideable = false;
} else {
var field = tableStore.dataSet.getField(column.name);
if (field) {
var dynamicProps = field.get('dynamicProps');
var computedProps = field.get('computedProps');
if (dynamicProps && dynamicProps.required || computedProps && computedProps.required || field.get('required')) {
column.hideable = false;
}
}
}
if (customizedColumn) {
if (column.hideable === false || !tableStore.columnHideable) {
delete customizedColumn.hidden;
}
if (column.resizable === false || !tableStore.columnResizable) {
delete customizedColumn.width;
}
if (column.titleEditable === false || !tableStore.columnTitleEditable) {
delete customizedColumn.title;
}
if (!tableStore.columnDraggable) {
delete customizedColumn.sort;
}
_extends(column, customizedColumn);
}
}
function findAndMergeCustomizedColumn(column, tableStore, customizedColumns, isChildrenHideDisabled) {
var customizedColumn = getCustomizedColumn(column, customizedColumns);
mergeCustomizedColumn(column, tableStore, customizedColumn, isChildrenHideDisabled);
}
function mergeDefaultProps(tableStore, originalColumns, tableAggregation, customizedColumns) {
var parent = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
var defaultKey = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [0];
var columnSort = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {
left: 0,
center: 0,
right: 0
};
var columns = [];
var leftColumns = [];
var rightColumns = [];
var hasAggregationColumn = false;
var isHideDisabled = false;
originalColumns.forEach(function (column) {
if (isPlainObject(column)) {
var newColumn = _objectSpread(_objectSpread({}, ColumnDefaultProps), column);
if (isNil(getColumnKey(newColumn))) {
newColumn.key = "anonymous-".concat(defaultKey[0]++);
}
var children = newColumn.children,
aggregation = newColumn.aggregation;
if (!hasAggregationColumn && aggregation) {
hasAggregationColumn = true;
}
if (tableAggregation || !aggregation) {
var customizedColumn = getCustomizedColumn(newColumn, customizedColumns);
mergeColumnLock(newColumn, parent, customizedColumn);
if (children) {
var _mergeDefaultProps = mergeDefaultProps(tableStore, children, tableAggregation, customizedColumns, newColumn, defaultKey),
_mergeDefaultProps2 = _slicedToArray(_mergeDefaultProps, 4),
childrenColumns = _mergeDefaultProps2[1],
_mergeDefaultProps2$ = _mergeDefaultProps2[3],
childrenHasAggregationColumn = _mergeDefaultProps2$.hasAggregationColumn,
childrenIsHideDisabled = _mergeDefaultProps2$.isHideDisabled;
newColumn.children = childrenColumns;
if (!hasAggregationColumn && childrenHasAggregationColumn) {
hasAggregationColumn = true;
}
if (!isHideDisabled && childrenIsHideDisabled) {
isHideDisabled = true;
}
mergeCustomizedColumn(newColumn, tableStore, customizedColumn, childrenIsHideDisabled);
} else {
mergeCustomizedColumn(newColumn, tableStore, customizedColumn);
}
if (!isHideDisabled && newColumn.hideable === false) {
isHideDisabled = true;
}
if (parent || !newColumn.lock) {
if (newColumn.sort === undefined) {
newColumn.sort = columnSort.center;
}
columnSort.center++;
columns.push(newColumn);
} else if (newColumn.lock === true || newColumn.lock === ColumnLock.left) {
if (newColumn.sort === undefined) {
newColumn.sort = columnSort.left;
}
columnSort.left++;
leftColumns.push(newColumn);
} else {
if (newColumn.sort === undefined) {
newColumn.sort = columnSort.right;
}
columnSort.right++;
rightColumns.push(newColumn);
}
} else if (children) {
var _mergeDefaultProps3 = mergeDefaultProps(tableStore, children, tableAggregation, customizedColumns, parent, defaultKey, parent ? undefined : columnSort),
_mergeDefaultProps4 = _slicedToArray(_mergeDefaultProps3, 4),
leftNodes = _mergeDefaultProps4[0],
nodes = _mergeDefaultProps4[1],
rightNodes = _mergeDefaultProps4[2],
_mergeDefaultProps4$ = _mergeDefaultProps4[3],
_childrenHasAggregationColumn = _mergeDefaultProps4$.hasAggregationColumn,
_childrenIsHideDisabled = _mergeDefaultProps4$.isHideDisabled;
if (!hasAggregationColumn && _childrenHasAggregationColumn) {
hasAggregationColumn = true;
}
if (!isHideDisabled && _childrenIsHideDisabled) {
newColumn.hideable = false;
isHideDisabled = true;
}
if (parent) {
parent.children = [].concat(_toConsumableArray(leftNodes), _toConsumableArray(nodes), _toConsumableArray(rightNodes));
} else {
leftColumns.push.apply(leftColumns, _toConsumableArray(leftNodes));
columns.push.apply(columns, _toConsumableArray(nodes));
rightColumns.push.apply(rightColumns, _toConsumableArray(rightNodes));
}
}
}
}, []);
if (parent) {
return [[], sortBy(columns, function (_ref4) {
var sort = _ref4.sort;
return sort;
}), [], {
hasAggregationColumn: hasAggregationColumn,
isHideDisabled: isHideDisabled
}];
}
return [sortBy(leftColumns, function (_ref5) {
var sort = _ref5.sort;
return sort;
}), sortBy(columns, function (_ref6) {
var sort = _ref6.sort;
return sort;
}), sortBy(rightColumns, function (_ref7) {
var sort = _ref7.sort;
return sort;
}), {
hasAggregationColumn: hasAggregationColumn,
isHideDisabled: isHideDisabled
}];
}
function normalizeColumns(tableStore, elements, tableAggregation, customizedColumns) {
var parent = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
var defaultKey = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [0];
var columnSort = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {
left: 0,
center: 0,
right: 0
};
var columns = [];
var leftColumns = [];
var rightColumns = [];
var hasAggregationColumn = false;
var isHideDisabled = false;
var normalizeColumn = function normalizeColumn(element) {
if ( /*#__PURE__*/isValidElement(element)) {
var props = element.props,
key = element.key,
type = element.type;
if (isFragment(element)) {
var children = props.children;
if (children) {
Children.forEach(children, normalizeColumn);
}
} else if (type.__PRO_TABLE_COLUMN) {
var column = _objectSpread({}, props);
if (key) {
column.key = key;
} else if (isNil(getColumnKey(column))) {
column.key = "anonymous-".concat(defaultKey[0]++);
}
var _children = column.children,
aggregation = column.aggregation;
if (!hasAggregationColumn && aggregation) {
hasAggregationColumn = true;
}
if (tableAggregation || !aggregation) {
var customizedColumn = getCustomizedColumn(column, customizedColumns);
mergeColumnLock(column, parent, customizedColumn);
var _normalizeColumns = normalizeColumns(tableStore, _children, tableAggregation, customizedColumns, column, defaultKey),
_normalizeColumns2 = _slicedToArray(_normalizeColumns, 4),
childrenColumns = _normalizeColumns2[1],
_normalizeColumns2$ = _normalizeColumns2[3],
childrenHasAggregationColumn = _normalizeColumns2$.hasAggregationColumn,
childrenIsHideDisabled = _normalizeColumns2$.isHideDisabled;
column.children = childrenColumns;
if (!hasAggregationColumn && childrenHasAggregationColumn) {
hasAggregationColumn = childrenHasAggregationColumn;
}
if (!isHideDisabled && childrenIsHideDisabled) {
isHideDisabled = true;
}
mergeCustomizedColumn(column, tableStore, customizedColumn, childrenIsHideDisabled);
if (!isHideDisabled && column.hideable === false) {
isHideDisabled = true;
}
if (parent || !column.lock) {
if (column.sort === undefined) {
column.sort = columnSort.center;
}
columnSort.center++;
columns.push(column);
} else if (column.lock === true || column.lock === ColumnLock.left) {
if (column.sort === undefined) {
column.sort = columnSort.left;
}
columnSort.left++;
leftColumns.push(column);
} else {
if (column.sort === undefined) {
column.sort = columnSort.right;
}
columnSort.right++;
rightColumns.push(column);
}
} else {
var _normalizeColumns3 = normalizeColumns(tableStore, _children, tableAggregation, customizedColumns, parent, defaultKey, parent ? undefined : columnSort),
_normalizeColumns4 = _slicedToArray(_normalizeColumns3, 4),
leftNodes = _normalizeColumns4[0],
nodes = _normalizeColumns4[1],
rightNodes = _normalizeColumns4[2],
_normalizeColumns4$ = _normalizeColumns4[3],
_childrenHasAggregationColumn2 = _normalizeColumns4$.hasAggregationColumn,
_childrenIsHideDisabled2 = _normalizeColumns4$.isHideDisabled;
if (!hasAggregationColumn && _childrenHasAggregationColumn2) {
hasAggregationColumn = _childrenHasAggregationColumn2;
}
if (!isHideDisabled && _childrenIsHideDisabled2) {
column.hideable = false;
isHideDisabled = true;
}
if (parent) {
parent.children = [].concat(_toConsumableArray(leftNodes), _toConsumableArray(nodes), _toConsumableArray(rightNodes));
} else {
leftColumns.push.apply(leftColumns, _toConsumableArray(leftNodes));
columns.push.apply(columns, _toConsumableArray(nodes));
rightColumns.push.apply(rightColumns, _toConsumableArray(rightNodes));
}
}
}
}
};
Children.forEach(elements, normalizeColumn);
if (parent) {
return [[], sortBy(columns, function (_ref8) {
var sort = _ref8.sort;
return sort;
}), [], {
hasAggregationColumn: hasAggregationColumn,
isHideDisabled: isHideDisabled
}];
}
return [sortBy(leftColumns, function (_ref9) {
var sort = _ref9.sort;
return sort;
}), sortBy(columns, function (_ref10) {
var sort = _ref10.sort;
return sort;
}), sortBy(rightColumns, function (_ref11) {
var sort = _ref11.sort;
return sort;
}), {
hasAggregationColumn: hasAggregationColumn,
isHideDisabled: isHideDisabled
}];
}
function getColumnGroupedColumns(tableStore, groups, customizedColumns) {
var leftGroupedColumns = [];
var groupedColumns = [];
var rightGroupedColumns = [];
var hasAggregation = false;
groups.forEach(function (group) {
var name = group.name,
type = group.type,
columnProps = group.columnProps;
if (type === GroupType.column) {
var column = _objectSpread(_objectSpread(_objectSpread({}, ColumnDefaultProps), {}, {
lock: ColumnLock.left
}, columnProps), {}, {
draggable: false,
hideable: false,
key: "__group-".concat(name),
name: name,
__tableGroup: group
});
column.children = columnProps && columnProps.children ? treeMap(columnProps.children, function (col, index, parentNode) {
var newCol = _objectSpread(_objectSpread({}, col), {}, {
__tableGroup: group,
lock: column.lock
});
if (!getColumnKey(col)) {
newCol.key = parentNode ? "".concat(parentNode.key, "-").concat(index) : "__group-".concat(name, "-").concat(index);
}
findAndMergeCustomizedColumn(newCol, tableStore, customizedColumns);
return newCol;
}, function (_ref12, _ref13) {
var _ref12$sort = _ref12.sort,
sort = _ref12$sort === void 0 ? Infinity : _ref12$sort;
var _ref13$sort = _ref13.sort,
sort2 = _ref13$sort === void 0 ? Infinity : _ref13$sort;
return sort - sort2;
}) : undefined;
findAndMergeCustomizedColumn(column, tableStore, customizedColumns);
if (!column.lock) {
groupedColumns.push(column);
} else if (column.lock === true || column.lock === ColumnLock.left) {
leftGroupedColumns.push(column);
} else {
rightGroupedColumns.push(column);
}
if (columnProps && !hasAggregation && columnProps.aggregation) {
hasAggregation = true;
}
}
});
return [leftGroupedColumns, groupedColumns, rightGroupedColumns, hasAggregation];
}
function getHeaderGroupedColumns(tableStore, groups, tableGroups, columns, dataSet, groupedColumns, customizedColumns, parentKey) {
var generatedColumns = new Set();
var headerUsed = false;
groups.forEach(function (group) {
var name = group.name,
subGroups = group.subGroups,
value = group.value;
var key = parentKey ? "".concat(parentKey, "-").concat(value) : value;
var subColumns = subGroups.length ? getHeaderGroupedColumns(tableStore, subGroups, tableGroups, columns, dataSet, groupedColumns, customizedColumns, key) : columns;
var tableGroup = tableGroups.find(function ($tableGroup) {
return name === $tableGroup.name;
});
if (tableGroup) {
var columnProps = tableGroup.columnProps,
groupName = tableGroup.name,
hidden = tableGroup.hidden;
if (hidden) {
subColumns.forEach(function (col) {
var __originalKey = getColumnKey(col);
var colKey = "".concat(key, "-").concat(__originalKey);
var newCol = _objectSpread(_objectSpread({}, col), {}, {
key: colKey,
__tableGroup: tableGroup,
__group: group,
__groups: groups,
__originalKey: __originalKey
});
findAndMergeCustomizedColumn(newCol, tableStore, customizedColumns);
newCol.lock = false;
generatedColumns.add(newCol);
});
} else {
var length = groupedColumns.length;
if (length && !headerUsed) {
headerUsed = true;
var header = getHeader(_objectSpread(_objectSpread({}, columnProps), {}, {
name: groupName,
dataSet: dataSet,
group: group,
groups: groups
}));
if (header) {
var oldColumn = groupedColumns[length - 1];
var newKey = "".concat(key, "-").concat(getColumnKey(oldColumn));
var newColumn = _objectSpread(_objectSpread({}, columnProps), {}, {
lock: oldColumn.lock,
titleEditable: false,
draggable: false,
hideable: false,
key: newKey,
header: header,
children: [oldColumn],
__tableGroup: tableGroup
});
var customizedColumn = getCustomizedColumnByKey(newKey, customizedColumns);
mergeCustomizedColumn(newColumn, tableStore, customizedColumn);
groupedColumns[length - 1] = newColumn;
}
}
var renderer = columnProps && columnProps.renderer || defaultAggregationRenderer;
var column = _objectSpread(_objectSpread({}, columnProps), {}, {
titleEditable: false,
key: key,
headerStyle: columnProps && columnProps.style,
header: function header() {
return renderer({
dataSet: dataSet,
record: group.totalRecords[0],
name: groupName,
text: value,
value: value,
headerGroup: group
});
},
children: treeMap(subColumns, function (col) {
var __originalKey = getColumnKey(col);
var colKey = "".concat(key, "-").concat(__originalKey);
var newCol = _objectSpread(_objectSpread({}, col), {}, {
key: colKey,
__originalKey: __originalKey
});
if (customizedColumns) {
_extends(newCol, customizedColumns[__originalKey], customizedColumns[colKey]);
}
newCol.lock = false;
return newCol;
}, function (_ref14, _ref15) {
var _ref14$sort = _ref14.sort,
sort = _ref14$sort === void 0 ? Infinity : _ref14$sort;
var _ref15$sort = _ref15.sort,
sort2 = _ref15$sort === void 0 ? Infinity : _ref15$sort;
return sort - sort2;
}),
__tableGroup: tableGroup,
__group: group,
__groups: groups
});
findAndMergeCustomizedColumn(column, tableStore, customizedColumns);
generatedColumns.add(column);
}
} else if (subColumns.length) {
subColumns.forEach(function (column) {
return generatedColumns.add(column);
});
}
});
return _toConsumableArray(generatedColumns);
}
export function normalizeGroupColumns(tableStore, columns, children, aggregation, customizedColumns) {
var headerTableGroups = tableStore.headerTableGroups,
groups = tableStore.groups,
dataSet = tableStore.dataSet;
var hasHeaderGroup = headerTableGroups.length > 0;
var generatedColumns = columns ? mergeDefaultProps(tableStore, columns, aggregation, customizedColumns) : normalizeColumns(tableStore, children, aggregation, customizedColumns);
var _generatedColumns = _slicedToArray(generatedColumns, 4),
leftOriginalColumns = _generatedColumns[0],
originalColumns = _generatedColumns[1],
rightOriginalColumns = _generatedColumns[2],
hasAggregationColumn = _generatedColumns[3].hasAggregationColumn;
var _ref16 = groups.length ? getColumnGroupedColumns(tableStore, groups, customizedColumns) : [[], [], [], false],
_ref17 = _slicedToArray(_ref16, 4),
leftColumnGroupedColumns = _ref17[0],
columnGroupedColumns = _ref17[1],
rightColumnGroupedColumns = _ref17[2],
hasAggregationColumnGroup = _ref17[3];
if (hasHeaderGroup) {
var groupedColumns = [].concat(_toConsumableArray(leftColumnGroupedColumns), _toConsumableArray(columnGroupedColumns));
return [groupedColumns, getHeaderGroupedColumns(tableStore, tableStore.groupedDataWithHeader, headerTableGroups, [].concat(_toConsumableArray(leftOriginalColumns), _toConsumableArray(originalColumns), _toConsumableArray(rightOriginalColumns)), dataSet, groupedColumns, customizedColumns), rightColumnGroupedColumns, hasAggregationColumnGroup || hasAggregationColumn];
}
return [[].concat(_toConsumableArray(leftColumnGroupedColumns), _toConsumableArray(leftOriginalColumns)), [].concat(_toConsumableArray(columnGroupedColumns), _toConsumableArray(originalColumns)), [].concat(_toConsumableArray(rightOriginalColumns), _toConsumableArray(rightColumnGroupedColumns)), hasAggregationColumnGroup || hasAggregationColumn];
}
function getHeaderTexts(_x, _x2, _x3) {
return _getHeaderTexts.apply(this, arguments);
}
function _getHeaderTexts() {
_getHeaderTexts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(dataSet, columns, aggregation) {
var headers,
column,
_args5 = arguments;
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
headers = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : [];
column = columns.shift();
if (!column) {
_context5.next = 10;
break;
}
_context5.t0 = headers;
_context5.t1 = column.name;
_context5.next = 7;
return getReactNodeText(getHeader(_objectSpread(_objectSpread({}, column), {}, {
dataSet: dataSet,
aggregation: aggregation
})));
case 7:
_context5.t2 = _context5.sent;
_context5.t3 = {
name: _context5.t1,
label: _context5.t2
};
_context5.t0.push.call(_context5.t0, _context5.t3);
case 10:
if (!columns.length) {
_context5.next = 13;
break;
}
_context5.next = 13;
return getHeaderTexts(dataSet, columns, aggregation, headers);
case 13:
return _context5.abrupt("return", headers);
case 14:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
return _getHeaderTexts.apply(this, arguments);
}
function autoHeightToStyle(autoHeight) {
var parentPaddingTop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var type = autoHeight.type,
diff = autoHeight.diff;
var height = "calc(100% - ".concat(diff + parentPaddingTop, "px)");
if (type === TableAutoHeightType.minHeight) {
return {
height: height
};
}
return {
maxHeight: height
};
}
var TableStore = /*#__PURE__*/function () {
function TableStore(node) {
var _this = this;
_classCallCheck(this, TableStore);
this.editors = new Map();
this.mouseBatchChooseStartId = 0;
this.mouseBatchChooseEndId = 0;
this.inBatchExpansion = false;
this.performanceOn = false;
this.timing = {
renderStart: 0,
renderEnd: 0
};
this.lastMeasuredIndex = 0;
this.handleSelectAllChange = action(function () {
if (_this.allChecked) {
_this.unCheckAllCurrent();
_this.unCheckAllCached();
} else {
_this.checkAllCurrent();
_this.checkAllCached();
}
});
this.saveCustomizedDebounce = debounce(this.saveCustomized, 1000);
this.stopScroll = debounce(action(function () {
_this.scrolling = false;
}), 300);
runInAction(function () {
_this.scrollPosition = ScrollPosition.left;
_this.mouseBatchChooseIdList = [];
_this.mouseBatchChooseState = false;
_this.showCachedSelection = false;
_this.lockColumnsHeadRowsHeight = {};
_this.lockColumnsBodyRowsHeight = {};
_this.lockColumnsFootRowsHeight = {};
_this.node = node;
_this.expandedRows = [];
_this.screenHeight = typeof window === 'undefined' ? 0 : document.documentElement.clientHeight;
_this.headerHeight = 0;
_this.footerHeight = 0;
_this.lastScrollTop = 0;
_this.lastScrollLeft = 0;
_this.customizedActiveKey = ['columns'];
_this.leftOriginalColumns = [];
_this.originalColumns = [];
_this.rightOriginalColumns = [];
_this.tempCustomized = {
columns: {}
};
_this.customized = {
columns: {}
};
_this.isCopyPristine = false;
_this.setProps(node.props);
if (_this.customizable) {
_this.loadCustomized();
} else {
_this.initColumns();
}
});
}
_createClass(TableStore, [{
key: "styleHeight",
get: function get() {
var autoHeight = this.autoHeight,
style = this.props.style,
parentPaddingTop = this.parentPaddingTop;
return autoHeight ? autoHeightToStyle(autoHeight, parentPaddingTop).height : style && style.height;
}
}, {
key: "styleMaxHeight",
get: function get() {
var autoHeight = this.autoHeight,
style = this.props.style,
parentPaddingTop = this.parentPaddingTop;
return autoHeight ? autoHeightToStyle(autoHeight, parentPaddingTop).maxHeight : style && style.maxHeight;
}
}, {
key: "styleMinHeight",
get: function get() {
var style = this.props.style;
return style && toPx(style.minHeight, this.getRelationSize);
}
}, {
key: "computedHeight",
get: function get() {
if (this.heightChangeable) {
var _this$customized = this.customized,
heightType = _this$customized.heightType,
height = _this$customized.height,
heightDiff = _this$customized.heightDiff,
tempCustomized = this.tempCustomized;
var tempHeightType = _get(tempCustomized, 'heightType');
if (tempHeightType) {
if (tempHeightType === TableHeightType.fixed) {
return _get(tempCustomized, 'height');
}
if (tempHeightType === TableHeightType.flex) {
return this.screenHeight - (_get(tempCustomized, 'heightDiff') || 0);
}
return undefined;
}
if (heightType) {
if (heightType === TableHeightType.fixed) {
return height;
}
if (heightType === TableHeightType.flex) {
return this.screenHeight - (heightDiff || 0);
}
return undefined;
}
}
return toPx(this.styleHeight, this.getRelationSize);
}
}, {
key: "otherHeight",
get: function get() {
var footerHeight = this.footerHeight,
boxSizing = this.props.boxSizing;
var footerTotalHeight = footerHeight && this.overflowX ? measureScrollbar() + footerHeight : footerHeight;
var otherHeight = this.headerHeight + footerTotalHeight;
if (boxSizing === TableBoxSizing.wrapper) {
var _ref18 = this.siblingHeihgt || {},
_ref18$before = _ref18.before,
before = _ref18$before === void 0 ? 0 : _ref18$before,
_ref18$after = _ref18.after,
after = _ref18$after === void 0 ? 0 : _ref18$after;
return otherHeight + before + after;
}
return otherHeight;
}
}, {
key: "height",
get: function get() {
if (!this.isBodyExpanded) {
return undefined;
}
var computedHeight = this.computedHeight;
var maxHeight = toPx(this.styleMaxHeight, this.getRelationSize);
var minHeight = toPx(this.styleMinHeight, this.getRelationSize);
var isComputedHeight = isNumber(computedHeight);
if (isComputedHeight || isNumber(minHeight) || isNumber(maxHeight)) {
var rowHeight = this.rowHeight,
otherHeight = this.otherHeight;
var rowMinHeight = (isNumber(rowHeight) ? rowHeight : 30) + otherHeight;
var minTotalHeight = minHeight ? Math.max(rowMinHeight, minHeight) : rowMinHeight;
var height = defaultTo(computedHeight, this.bodyHeight + otherHeight);
var totalHeight = Math.max(minTotalHeight, maxHeight ? Math.min(maxHeight, height) : height);
return isComputedHeight || totalHeight !== height ? totalHeight - otherHeight : undefined;
}
}
}, {
key: "totalHeight",
get: function get() {
var height = this.height,
bodyHeight = this.bodyHeight,
otherHeight = this.otherHeight;
return defaultTo(height, bodyHeight) + otherHeight;
}
}, {
key: "bodyHeight",
get: function get() {
if (this.propVirtual) {
var virtualHeight = this.virtualHeight;
if (virtualHeight > 0) {
return virtualHeight;
}
}
return this.calcBodyHeight || 0;
}
}, {
key: "stickyLeft",
get: function get() {
return [ScrollPosition.right, ScrollPosition.middle].includes(this.scrollPosition);
}
}, {
key: "stickyRight",
get: function get() {
return [ScrollPosition.left, ScrollPosition.middle].includes(this.scrollPosition);
}
}, {
key: "performanceEnabled",
get: function get() {
var performanceEnabled = this.getConfig('performanceEnabled');
return performanceEnabled && performanceEnabled.Table;
}
}, {
key: "dataSet",
get: function get() {
return this.props.dataSet;
}
}, {
key: "prefixCls",
get: function get() {
return this.node.prefixCls;
}
}, {
key: "customizable",
get: function get() {
var customizedCode = this.props.customizedCode;
var queryBarProps = this.props.queryBarProps;
var isSimpleMode = queryBarProps && queryBarProps.simpleMode;
if (customizedCode || this.queryBar === TableQueryBarType.comboBar && !isSimpleMode) {
if ('customizable' in this.props) {
return this.props.customizable;
}
return this.getConfig('tableCustomizable') || this.node.context.getCustomizable('Table');
}
return false;
}
/**
* board 组件个性化按钮 in buttons
*/
}, {
key: "customizedBtn",
get: function get() {
var _this$props = this.props,
customizedCode = _this$props.customizedCode,
boardCustomized = _this$props.boardCustomized;
if (customizedCode && boardCustomized) {
return boardCustomized.customizedBtn;
}
return false;
}
}, {
key: "aggregation",
get: function get() {
var aggregation = this.customized.aggregation;
if (aggregation !== undefined) {
return aggregation;
}
var propAggregation = this.props.aggregation;
return propAggregation;
}
}, {
key: "aggregationExpandType",
get: function get() {
return this.customized.aggregationExpandType || 'cell';
}
}, {
key: "autoHeight",
get: function get() {
var autoHeight = this.props.autoHeight;
if (autoHeight) {
var defaultAutoHeight = {
type: TableAutoHeightType.minHeight,
diff: this.getConfig('tableAutoHeightDiff') || 80
};
if (isObject(autoHeight)) {
return _objectSpread(_objectSpread({}, defaultAutoHeight), autoHeight);
}
return defaultAutoHeight;
}
return undefined;
}
}, {
key: "heightType",
get: function get() {
if (this.heightChangeable) {
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 styleHeight = this.styleHeight;
if (styleHeight) {
if (isString(styleHeight) && isCalcSize(styleHeight)) {
return TableHeightType.flex;
}
if (isNumber(toPx(styleHeight))) {
return TableHeightType.fixed;
}
}
return TableHeightType.auto;
}
}, {
key: "virtualCell",
get: function get() {
if ('virtualCell' in this.props) {
return this.props.virtualCell;
}
return this.getConfig('tableVirtualCell');
}
}, {
key: "isFixedRowHeight",
get: function get() {
if (!this.aggregation || !this.hasAggregationColumn) {
return isNumber(this.rowHeight);
}
return false;
}
}, {
key: "propVirtual",
get: function get() {
if (this.isTree && this.rowDraggable) {
return true;
}
if ('virtual' in this.props) {
return this.props.virtual;
}
var configTableVirtual = this.getConfig('tableVirtual');
if (typeof configTableVirtual === 'function') {
return configTableVirtual(this.currentData.length, this.columnGroups.leafs.length);
}
return configTableVirtual;
}
}, {
key: "virtual",
get: function get() {
if (this.height !== undefined) {
return this.propVirtual;
}
return false;
}
}, {
key: "columnBuffer",
get: function get() {
var columnBuffer = this.props.columnBuffer;
if ('columnBuffer' in this.props && typeof columnBuffer === 'number' && columnBuffer >= 0) {
return columnBuffer;
}
var bufferConfig = this.getConfig('tableVirtualBuffer');
if (bufferConfig && 'columnBuffer' in bufferConfig && typeof bufferConfig.columnBuffer === 'number' && bufferConfig.columnBuffer >= 0) {
return bufferConfig.columnBuffer;
}
return 3;
}
}, {
key: "columnThreshold",
get: function get() {
var columnThreshold = this.props.columnThreshold;
if ('columnThreshold' in this.props && typeof columnThreshold === 'number' && columnThreshold >= 0) {
return columnThreshold;
}
var bufferConfig = this.getConfig('tableVirtualBuffer');
if (bufferConfig && 'columnThreshold' in bufferConfig && typeof bufferConfig.columnThreshold === 'number' && bufferConfig.columnThreshold >= 0) {
return bufferConfig.columnThreshold;
}
return 3;
}
}, {
key: "updateRenderZonePosition",
value: function upd