first commit
This commit is contained in:
32
frontend/node_modules/rc-table/es/hooks/useColumns/index.d.ts
generated
vendored
Normal file
32
frontend/node_modules/rc-table/es/hooks/useColumns/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as React from 'react';
|
||||
import type { ColumnsType, ColumnType, Direction, FixedType, GetRowKey, Key, RenderExpandIcon, TriggerEventHandler } from '../../interface';
|
||||
export declare function convertChildrenToColumns<RecordType>(children: React.ReactNode): ColumnsType<RecordType>;
|
||||
/**
|
||||
* Parse `columns` & `children` into `columns`.
|
||||
*/
|
||||
declare function useColumns<RecordType>({ prefixCls, columns, children, expandable, expandedKeys, columnTitle, getRowKey, onTriggerExpand, expandIcon, rowExpandable, expandIconColumnIndex, expandedRowOffset, direction, expandRowByClick, columnWidth, fixed, scrollWidth, clientWidth, }: {
|
||||
prefixCls?: string;
|
||||
columns?: ColumnsType<RecordType>;
|
||||
children?: React.ReactNode;
|
||||
expandable: boolean;
|
||||
expandedKeys: Set<Key>;
|
||||
columnTitle?: React.ReactNode;
|
||||
getRowKey: GetRowKey<RecordType>;
|
||||
onTriggerExpand: TriggerEventHandler<RecordType>;
|
||||
expandIcon?: RenderExpandIcon<RecordType>;
|
||||
rowExpandable?: (record: RecordType) => boolean;
|
||||
expandIconColumnIndex?: number;
|
||||
direction?: Direction;
|
||||
expandRowByClick?: boolean;
|
||||
columnWidth?: number | string;
|
||||
clientWidth: number;
|
||||
fixed?: FixedType;
|
||||
scrollWidth?: number;
|
||||
expandedRowOffset?: number;
|
||||
}, transformColumns: (columns: ColumnsType<RecordType>) => ColumnsType<RecordType>): [
|
||||
columns: ColumnsType<RecordType>,
|
||||
flattenColumns: readonly ColumnType<RecordType>[],
|
||||
realScrollWidth: undefined | number,
|
||||
hasGapFixed: boolean
|
||||
];
|
||||
export default useColumns;
|
||||
269
frontend/node_modules/rc-table/es/hooks/useColumns/index.js
generated
vendored
Normal file
269
frontend/node_modules/rc-table/es/hooks/useColumns/index.js
generated
vendored
Normal file
@@ -0,0 +1,269 @@
|
||||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
||||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
||||
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
||||
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
||||
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
||||
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
||||
var _excluded = ["children"],
|
||||
_excluded2 = ["fixed"];
|
||||
import toArray from "rc-util/es/Children/toArray";
|
||||
import warning from "rc-util/es/warning";
|
||||
import * as React from 'react';
|
||||
import { EXPAND_COLUMN } from "../../constant";
|
||||
import { INTERNAL_COL_DEFINE } from "../../utils/legacyUtil";
|
||||
import useWidthColumns from "./useWidthColumns";
|
||||
export function convertChildrenToColumns(children) {
|
||||
return toArray(children).filter(function (node) {
|
||||
return /*#__PURE__*/React.isValidElement(node);
|
||||
}).map(function (_ref) {
|
||||
var key = _ref.key,
|
||||
props = _ref.props;
|
||||
var nodeChildren = props.children,
|
||||
restProps = _objectWithoutProperties(props, _excluded);
|
||||
var column = _objectSpread({
|
||||
key: key
|
||||
}, restProps);
|
||||
if (nodeChildren) {
|
||||
column.children = convertChildrenToColumns(nodeChildren);
|
||||
}
|
||||
return column;
|
||||
});
|
||||
}
|
||||
function filterHiddenColumns(columns) {
|
||||
return columns.filter(function (column) {
|
||||
return column && _typeof(column) === 'object' && !column.hidden;
|
||||
}).map(function (column) {
|
||||
var subColumns = column.children;
|
||||
if (subColumns && subColumns.length > 0) {
|
||||
return _objectSpread(_objectSpread({}, column), {}, {
|
||||
children: filterHiddenColumns(subColumns)
|
||||
});
|
||||
}
|
||||
return column;
|
||||
});
|
||||
}
|
||||
function flatColumns(columns) {
|
||||
var parentKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'key';
|
||||
return columns.filter(function (column) {
|
||||
return column && _typeof(column) === 'object';
|
||||
}).reduce(function (list, column, index) {
|
||||
var fixed = column.fixed;
|
||||
// Convert `fixed='true'` to `fixed='left'` instead
|
||||
var parsedFixed = fixed === true ? 'left' : fixed;
|
||||
var mergedKey = "".concat(parentKey, "-").concat(index);
|
||||
var subColumns = column.children;
|
||||
if (subColumns && subColumns.length > 0) {
|
||||
return [].concat(_toConsumableArray(list), _toConsumableArray(flatColumns(subColumns, mergedKey).map(function (subColum) {
|
||||
var _subColum$fixed;
|
||||
return _objectSpread(_objectSpread({}, subColum), {}, {
|
||||
fixed: (_subColum$fixed = subColum.fixed) !== null && _subColum$fixed !== void 0 ? _subColum$fixed : parsedFixed
|
||||
});
|
||||
})));
|
||||
}
|
||||
return [].concat(_toConsumableArray(list), [_objectSpread(_objectSpread({
|
||||
key: mergedKey
|
||||
}, column), {}, {
|
||||
fixed: parsedFixed
|
||||
})]);
|
||||
}, []);
|
||||
}
|
||||
function revertForRtl(columns) {
|
||||
return columns.map(function (column) {
|
||||
var fixed = column.fixed,
|
||||
restProps = _objectWithoutProperties(column, _excluded2);
|
||||
|
||||
// Convert `fixed='left'` to `fixed='right'` instead
|
||||
var parsedFixed = fixed;
|
||||
if (fixed === 'left') {
|
||||
parsedFixed = 'right';
|
||||
} else if (fixed === 'right') {
|
||||
parsedFixed = 'left';
|
||||
}
|
||||
return _objectSpread({
|
||||
fixed: parsedFixed
|
||||
}, restProps);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse `columns` & `children` into `columns`.
|
||||
*/
|
||||
function useColumns(_ref2, transformColumns) {
|
||||
var prefixCls = _ref2.prefixCls,
|
||||
columns = _ref2.columns,
|
||||
children = _ref2.children,
|
||||
expandable = _ref2.expandable,
|
||||
expandedKeys = _ref2.expandedKeys,
|
||||
columnTitle = _ref2.columnTitle,
|
||||
getRowKey = _ref2.getRowKey,
|
||||
onTriggerExpand = _ref2.onTriggerExpand,
|
||||
expandIcon = _ref2.expandIcon,
|
||||
rowExpandable = _ref2.rowExpandable,
|
||||
expandIconColumnIndex = _ref2.expandIconColumnIndex,
|
||||
_ref2$expandedRowOffs = _ref2.expandedRowOffset,
|
||||
expandedRowOffset = _ref2$expandedRowOffs === void 0 ? 0 : _ref2$expandedRowOffs,
|
||||
direction = _ref2.direction,
|
||||
expandRowByClick = _ref2.expandRowByClick,
|
||||
columnWidth = _ref2.columnWidth,
|
||||
fixed = _ref2.fixed,
|
||||
scrollWidth = _ref2.scrollWidth,
|
||||
clientWidth = _ref2.clientWidth;
|
||||
var baseColumns = React.useMemo(function () {
|
||||
var newColumns = columns || convertChildrenToColumns(children) || [];
|
||||
return filterHiddenColumns(newColumns.slice());
|
||||
}, [columns, children]);
|
||||
|
||||
// ========================== Expand ==========================
|
||||
var withExpandColumns = React.useMemo(function () {
|
||||
if (expandable) {
|
||||
var cloneColumns = baseColumns.slice();
|
||||
|
||||
// >>> Warning if use `expandIconColumnIndex`
|
||||
if (process.env.NODE_ENV !== 'production' && expandIconColumnIndex >= 0) {
|
||||
warning(false, '`expandIconColumnIndex` is deprecated. Please use `Table.EXPAND_COLUMN` in `columns` instead.');
|
||||
}
|
||||
|
||||
// >>> Insert expand column if not exist
|
||||
if (!cloneColumns.includes(EXPAND_COLUMN)) {
|
||||
var expandColIndex = expandIconColumnIndex || 0;
|
||||
var insertIndex = expandColIndex === 0 && fixed === 'right' ? baseColumns.length : expandColIndex;
|
||||
if (insertIndex >= 0) {
|
||||
cloneColumns.splice(insertIndex, 0, EXPAND_COLUMN);
|
||||
}
|
||||
}
|
||||
|
||||
// >>> Deduplicate additional expand column
|
||||
if (process.env.NODE_ENV !== 'production' && cloneColumns.filter(function (c) {
|
||||
return c === EXPAND_COLUMN;
|
||||
}).length > 1) {
|
||||
warning(false, 'There exist more than one `EXPAND_COLUMN` in `columns`.');
|
||||
}
|
||||
var expandColumnIndex = cloneColumns.indexOf(EXPAND_COLUMN);
|
||||
cloneColumns = cloneColumns.filter(function (column, index) {
|
||||
return column !== EXPAND_COLUMN || index === expandColumnIndex;
|
||||
});
|
||||
|
||||
// >>> Check if expand column need to fixed
|
||||
var prevColumn = baseColumns[expandColumnIndex];
|
||||
var fixedColumn;
|
||||
if (fixed) {
|
||||
fixedColumn = fixed;
|
||||
} else {
|
||||
fixedColumn = prevColumn ? prevColumn.fixed : null;
|
||||
}
|
||||
|
||||
// >>> Create expandable column
|
||||
var expandColumn = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, INTERNAL_COL_DEFINE, {
|
||||
className: "".concat(prefixCls, "-expand-icon-col"),
|
||||
columnType: 'EXPAND_COLUMN'
|
||||
}), "title", columnTitle), "fixed", fixedColumn), "className", "".concat(prefixCls, "-row-expand-icon-cell")), "width", columnWidth), "render", function render(_, record, index) {
|
||||
var rowKey = getRowKey(record, index);
|
||||
var expanded = expandedKeys.has(rowKey);
|
||||
var recordExpandable = rowExpandable ? rowExpandable(record) : true;
|
||||
var icon = expandIcon({
|
||||
prefixCls: prefixCls,
|
||||
expanded: expanded,
|
||||
expandable: recordExpandable,
|
||||
record: record,
|
||||
onExpand: onTriggerExpand
|
||||
});
|
||||
if (expandRowByClick) {
|
||||
return /*#__PURE__*/React.createElement("span", {
|
||||
onClick: function onClick(e) {
|
||||
return e.stopPropagation();
|
||||
}
|
||||
}, icon);
|
||||
}
|
||||
return icon;
|
||||
});
|
||||
return cloneColumns.map(function (col, index) {
|
||||
var column = col === EXPAND_COLUMN ? expandColumn : col;
|
||||
if (index < expandedRowOffset) {
|
||||
return _objectSpread(_objectSpread({}, column), {}, {
|
||||
fixed: column.fixed || 'left'
|
||||
});
|
||||
}
|
||||
return column;
|
||||
});
|
||||
}
|
||||
if (process.env.NODE_ENV !== 'production' && baseColumns.includes(EXPAND_COLUMN)) {
|
||||
warning(false, '`expandable` is not config but there exist `EXPAND_COLUMN` in `columns`.');
|
||||
}
|
||||
return baseColumns.filter(function (col) {
|
||||
return col !== EXPAND_COLUMN;
|
||||
});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [expandable, baseColumns, getRowKey, expandedKeys, expandIcon, direction, expandedRowOffset]);
|
||||
|
||||
// ========================= Transform ========================
|
||||
var mergedColumns = React.useMemo(function () {
|
||||
var finalColumns = withExpandColumns;
|
||||
if (transformColumns) {
|
||||
finalColumns = transformColumns(finalColumns);
|
||||
}
|
||||
|
||||
// Always provides at least one column for table display
|
||||
if (!finalColumns.length) {
|
||||
finalColumns = [{
|
||||
render: function render() {
|
||||
return null;
|
||||
}
|
||||
}];
|
||||
}
|
||||
return finalColumns;
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [transformColumns, withExpandColumns, direction]);
|
||||
|
||||
// ========================== Flatten =========================
|
||||
var flattenColumns = React.useMemo(function () {
|
||||
if (direction === 'rtl') {
|
||||
return revertForRtl(flatColumns(mergedColumns));
|
||||
}
|
||||
return flatColumns(mergedColumns);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [mergedColumns, direction, scrollWidth]);
|
||||
|
||||
// ========================= Gap Fixed ========================
|
||||
var hasGapFixed = React.useMemo(function () {
|
||||
// Fixed: left, since old browser not support `findLastIndex`, we should use reverse loop
|
||||
var lastLeftIndex = -1;
|
||||
for (var i = flattenColumns.length - 1; i >= 0; i -= 1) {
|
||||
var colFixed = flattenColumns[i].fixed;
|
||||
if (colFixed === 'left' || colFixed === true) {
|
||||
lastLeftIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastLeftIndex >= 0) {
|
||||
for (var _i = 0; _i <= lastLeftIndex; _i += 1) {
|
||||
var _colFixed = flattenColumns[_i].fixed;
|
||||
if (_colFixed !== 'left' && _colFixed !== true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fixed: right
|
||||
var firstRightIndex = flattenColumns.findIndex(function (_ref3) {
|
||||
var colFixed = _ref3.fixed;
|
||||
return colFixed === 'right';
|
||||
});
|
||||
if (firstRightIndex >= 0) {
|
||||
for (var _i2 = firstRightIndex; _i2 < flattenColumns.length; _i2 += 1) {
|
||||
var _colFixed2 = flattenColumns[_i2].fixed;
|
||||
if (_colFixed2 !== 'right') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}, [flattenColumns]);
|
||||
|
||||
// ========================= FillWidth ========================
|
||||
var _useWidthColumns = useWidthColumns(flattenColumns, scrollWidth, clientWidth),
|
||||
_useWidthColumns2 = _slicedToArray(_useWidthColumns, 2),
|
||||
filledColumns = _useWidthColumns2[0],
|
||||
realScrollWidth = _useWidthColumns2[1];
|
||||
return [mergedColumns, filledColumns, realScrollWidth, hasGapFixed];
|
||||
}
|
||||
export default useColumns;
|
||||
5
frontend/node_modules/rc-table/es/hooks/useColumns/useWidthColumns.d.ts
generated
vendored
Normal file
5
frontend/node_modules/rc-table/es/hooks/useColumns/useWidthColumns.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { ColumnsType } from '../../interface';
|
||||
/**
|
||||
* Fill all column with width
|
||||
*/
|
||||
export default function useWidthColumns(flattenColumns: ColumnsType<any>, scrollWidth: number, clientWidth: number): [columns: ColumnsType<any>, realScrollWidth: number];
|
||||
70
frontend/node_modules/rc-table/es/hooks/useColumns/useWidthColumns.js
generated
vendored
Normal file
70
frontend/node_modules/rc-table/es/hooks/useColumns/useWidthColumns.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
||||
import * as React from 'react';
|
||||
function parseColWidth(totalWidth) {
|
||||
var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
||||
if (typeof width === 'number') {
|
||||
return width;
|
||||
}
|
||||
if (width.endsWith('%')) {
|
||||
return totalWidth * parseFloat(width) / 100;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill all column with width
|
||||
*/
|
||||
export default function useWidthColumns(flattenColumns, scrollWidth, clientWidth) {
|
||||
return React.useMemo(function () {
|
||||
// Fill width if needed
|
||||
if (scrollWidth && scrollWidth > 0) {
|
||||
var totalWidth = 0;
|
||||
var missWidthCount = 0;
|
||||
|
||||
// collect not given width column
|
||||
flattenColumns.forEach(function (col) {
|
||||
var colWidth = parseColWidth(scrollWidth, col.width);
|
||||
if (colWidth) {
|
||||
totalWidth += colWidth;
|
||||
} else {
|
||||
missWidthCount += 1;
|
||||
}
|
||||
});
|
||||
|
||||
// Fill width
|
||||
var maxFitWidth = Math.max(scrollWidth, clientWidth);
|
||||
var restWidth = Math.max(maxFitWidth - totalWidth, missWidthCount);
|
||||
var restCount = missWidthCount;
|
||||
var avgWidth = restWidth / missWidthCount;
|
||||
var realTotal = 0;
|
||||
var filledColumns = flattenColumns.map(function (col) {
|
||||
var clone = _objectSpread({}, col);
|
||||
var colWidth = parseColWidth(scrollWidth, clone.width);
|
||||
if (colWidth) {
|
||||
clone.width = colWidth;
|
||||
} else {
|
||||
var colAvgWidth = Math.floor(avgWidth);
|
||||
clone.width = restCount === 1 ? restWidth : colAvgWidth;
|
||||
restWidth -= colAvgWidth;
|
||||
restCount -= 1;
|
||||
}
|
||||
realTotal += clone.width;
|
||||
return clone;
|
||||
});
|
||||
|
||||
// If realTotal is less than clientWidth,
|
||||
// We need extend column width
|
||||
if (realTotal < maxFitWidth) {
|
||||
var scale = maxFitWidth / realTotal;
|
||||
restWidth = maxFitWidth;
|
||||
filledColumns.forEach(function (col, index) {
|
||||
var colWidth = Math.floor(col.width * scale);
|
||||
col.width = index === filledColumns.length - 1 ? restWidth : colWidth;
|
||||
restWidth -= colWidth;
|
||||
});
|
||||
}
|
||||
return [filledColumns, Math.max(realTotal, maxFitWidth)];
|
||||
}
|
||||
return [flattenColumns, scrollWidth];
|
||||
}, [flattenColumns, scrollWidth, clientWidth]);
|
||||
}
|
||||
10
frontend/node_modules/rc-table/es/hooks/useExpand.d.ts
generated
vendored
Normal file
10
frontend/node_modules/rc-table/es/hooks/useExpand.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { ExpandableConfig, ExpandableType, GetRowKey, Key, RenderExpandIcon, TriggerEventHandler } from '../interface';
|
||||
import type { TableProps } from '../Table';
|
||||
export default function useExpand<RecordType>(props: TableProps<RecordType>, mergedData: readonly RecordType[], getRowKey: GetRowKey<RecordType>): [
|
||||
expandableConfig: ExpandableConfig<RecordType>,
|
||||
expandableType: ExpandableType,
|
||||
expandedKeys: Set<Key>,
|
||||
expandIcon: RenderExpandIcon<RecordType>,
|
||||
childrenColumnName: string,
|
||||
onTriggerExpand: TriggerEventHandler<RecordType>
|
||||
];
|
||||
83
frontend/node_modules/rc-table/es/hooks/useExpand.js
generated
vendored
Normal file
83
frontend/node_modules/rc-table/es/hooks/useExpand.js
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
||||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
||||
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
||||
import warning from "rc-util/es/warning";
|
||||
import * as React from 'react';
|
||||
import { INTERNAL_HOOKS } from "../constant";
|
||||
import { findAllChildrenKeys, renderExpandIcon } from "../utils/expandUtil";
|
||||
import { getExpandableProps } from "../utils/legacyUtil";
|
||||
export default function useExpand(props, mergedData, getRowKey) {
|
||||
var expandableConfig = getExpandableProps(props);
|
||||
var expandIcon = expandableConfig.expandIcon,
|
||||
expandedRowKeys = expandableConfig.expandedRowKeys,
|
||||
defaultExpandedRowKeys = expandableConfig.defaultExpandedRowKeys,
|
||||
defaultExpandAllRows = expandableConfig.defaultExpandAllRows,
|
||||
expandedRowRender = expandableConfig.expandedRowRender,
|
||||
onExpand = expandableConfig.onExpand,
|
||||
onExpandedRowsChange = expandableConfig.onExpandedRowsChange,
|
||||
childrenColumnName = expandableConfig.childrenColumnName;
|
||||
var mergedExpandIcon = expandIcon || renderExpandIcon;
|
||||
var mergedChildrenColumnName = childrenColumnName || 'children';
|
||||
var expandableType = React.useMemo(function () {
|
||||
if (expandedRowRender) {
|
||||
return 'row';
|
||||
}
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
/**
|
||||
* Fix https://github.com/ant-design/ant-design/issues/21154
|
||||
* This is a workaround to not to break current behavior.
|
||||
* We can remove follow code after final release.
|
||||
*
|
||||
* To other developer:
|
||||
* Do not use `__PARENT_RENDER_ICON__` in prod since we will remove this when refactor
|
||||
*/
|
||||
if (props.expandable && props.internalHooks === INTERNAL_HOOKS && props.expandable.__PARENT_RENDER_ICON__ || mergedData.some(function (record) {
|
||||
return record && _typeof(record) === 'object' && record[mergedChildrenColumnName];
|
||||
})) {
|
||||
return 'nest';
|
||||
}
|
||||
/* eslint-enable */
|
||||
return false;
|
||||
}, [!!expandedRowRender, mergedData]);
|
||||
var _React$useState = React.useState(function () {
|
||||
if (defaultExpandedRowKeys) {
|
||||
return defaultExpandedRowKeys;
|
||||
}
|
||||
if (defaultExpandAllRows) {
|
||||
return findAllChildrenKeys(mergedData, getRowKey, mergedChildrenColumnName);
|
||||
}
|
||||
return [];
|
||||
}),
|
||||
_React$useState2 = _slicedToArray(_React$useState, 2),
|
||||
innerExpandedKeys = _React$useState2[0],
|
||||
setInnerExpandedKeys = _React$useState2[1];
|
||||
var mergedExpandedKeys = React.useMemo(function () {
|
||||
return new Set(expandedRowKeys || innerExpandedKeys || []);
|
||||
}, [expandedRowKeys, innerExpandedKeys]);
|
||||
var onTriggerExpand = React.useCallback(function (record) {
|
||||
var key = getRowKey(record, mergedData.indexOf(record));
|
||||
var newExpandedKeys;
|
||||
var hasKey = mergedExpandedKeys.has(key);
|
||||
if (hasKey) {
|
||||
mergedExpandedKeys.delete(key);
|
||||
newExpandedKeys = _toConsumableArray(mergedExpandedKeys);
|
||||
} else {
|
||||
newExpandedKeys = [].concat(_toConsumableArray(mergedExpandedKeys), [key]);
|
||||
}
|
||||
setInnerExpandedKeys(newExpandedKeys);
|
||||
if (onExpand) {
|
||||
onExpand(!hasKey, record);
|
||||
}
|
||||
if (onExpandedRowsChange) {
|
||||
onExpandedRowsChange(newExpandedKeys);
|
||||
}
|
||||
}, [getRowKey, mergedExpandedKeys, mergedData, onExpand, onExpandedRowsChange]);
|
||||
|
||||
// Warning if use `expandedRowRender` and nest children in the same time
|
||||
if (process.env.NODE_ENV !== 'production' && expandedRowRender && mergedData.some(function (record) {
|
||||
return Array.isArray(record === null || record === void 0 ? void 0 : record[mergedChildrenColumnName]);
|
||||
})) {
|
||||
warning(false, '`expandedRowRender` should not use with nested Table');
|
||||
}
|
||||
return [expandableConfig, expandableType, mergedExpandedKeys, mergedExpandIcon, mergedChildrenColumnName, onTriggerExpand];
|
||||
}
|
||||
2
frontend/node_modules/rc-table/es/hooks/useFixedInfo.d.ts
generated
vendored
Normal file
2
frontend/node_modules/rc-table/es/hooks/useFixedInfo.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { ColumnType, Direction, StickyOffsets } from '../interface';
|
||||
export default function useFixedInfo<RecordType>(flattenColumns: readonly ColumnType<RecordType>[], stickyOffsets: StickyOffsets, direction: Direction): import("../utils/fixUtil").FixedInfo[];
|
||||
13
frontend/node_modules/rc-table/es/hooks/useFixedInfo.js
generated
vendored
Normal file
13
frontend/node_modules/rc-table/es/hooks/useFixedInfo.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import useMemo from "rc-util/es/hooks/useMemo";
|
||||
import isEqual from "rc-util/es/isEqual";
|
||||
import { getCellFixedInfo } from "../utils/fixUtil";
|
||||
export default function useFixedInfo(flattenColumns, stickyOffsets, direction) {
|
||||
var fixedInfoList = flattenColumns.map(function (_, colIndex) {
|
||||
return getCellFixedInfo(colIndex, colIndex, flattenColumns, stickyOffsets, direction);
|
||||
});
|
||||
return useMemo(function () {
|
||||
return fixedInfoList;
|
||||
}, [fixedInfoList], function (prev, next) {
|
||||
return !isEqual(prev, next);
|
||||
});
|
||||
}
|
||||
19
frontend/node_modules/rc-table/es/hooks/useFlattenRecords.d.ts
generated
vendored
Normal file
19
frontend/node_modules/rc-table/es/hooks/useFlattenRecords.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { GetRowKey, Key } from '../interface';
|
||||
export interface FlattenData<RecordType> {
|
||||
record: RecordType;
|
||||
indent: number;
|
||||
index: number;
|
||||
rowKey: Key;
|
||||
}
|
||||
/**
|
||||
* flat tree data on expanded state
|
||||
*
|
||||
* @export
|
||||
* @template T
|
||||
* @param {*} data : table data
|
||||
* @param {string} childrenColumnName : 指定树形结构的列名
|
||||
* @param {Set<Key>} expandedKeys : 展开的行对应的keys
|
||||
* @param {GetRowKey<T>} getRowKey : 获取当前rowKey的方法
|
||||
* @returns flattened data
|
||||
*/
|
||||
export default function useFlattenRecords<T>(data: T[] | readonly T[], childrenColumnName: string, expandedKeys: Set<Key>, getRowKey: GetRowKey<T>): FlattenData<T>[];
|
||||
54
frontend/node_modules/rc-table/es/hooks/useFlattenRecords.js
generated
vendored
Normal file
54
frontend/node_modules/rc-table/es/hooks/useFlattenRecords.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as React from 'react';
|
||||
// recursion (flat tree structure)
|
||||
function fillRecords(list, record, indent, childrenColumnName, expandedKeys, getRowKey, index) {
|
||||
var key = getRowKey(record, index);
|
||||
list.push({
|
||||
record: record,
|
||||
indent: indent,
|
||||
index: index,
|
||||
rowKey: key
|
||||
});
|
||||
var expanded = expandedKeys === null || expandedKeys === void 0 ? void 0 : expandedKeys.has(key);
|
||||
if (record && Array.isArray(record[childrenColumnName]) && expanded) {
|
||||
// expanded state, flat record
|
||||
for (var i = 0; i < record[childrenColumnName].length; i += 1) {
|
||||
fillRecords(list, record[childrenColumnName][i], indent + 1, childrenColumnName, expandedKeys, getRowKey, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* flat tree data on expanded state
|
||||
*
|
||||
* @export
|
||||
* @template T
|
||||
* @param {*} data : table data
|
||||
* @param {string} childrenColumnName : 指定树形结构的列名
|
||||
* @param {Set<Key>} expandedKeys : 展开的行对应的keys
|
||||
* @param {GetRowKey<T>} getRowKey : 获取当前rowKey的方法
|
||||
* @returns flattened data
|
||||
*/
|
||||
export default function useFlattenRecords(data, childrenColumnName, expandedKeys, getRowKey) {
|
||||
var arr = React.useMemo(function () {
|
||||
if (expandedKeys !== null && expandedKeys !== void 0 && expandedKeys.size) {
|
||||
var list = [];
|
||||
|
||||
// collect flattened record
|
||||
for (var i = 0; i < (data === null || data === void 0 ? void 0 : data.length); i += 1) {
|
||||
var record = data[i];
|
||||
|
||||
// using array.push or spread operator may cause "Maximum call stack size exceeded" exception if array size is big enough.
|
||||
fillRecords(list, record, 0, childrenColumnName, expandedKeys, getRowKey, i);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return data === null || data === void 0 ? void 0 : data.map(function (item, index) {
|
||||
return {
|
||||
record: item,
|
||||
indent: 0,
|
||||
index: index,
|
||||
rowKey: getRowKey(item, index)
|
||||
};
|
||||
});
|
||||
}, [data, childrenColumnName, expandedKeys, getRowKey]);
|
||||
return arr;
|
||||
}
|
||||
7
frontend/node_modules/rc-table/es/hooks/useFrame.d.ts
generated
vendored
Normal file
7
frontend/node_modules/rc-table/es/hooks/useFrame.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export type Updater<State> = (prev: State) => State;
|
||||
/**
|
||||
* Execute code before next frame but async
|
||||
*/
|
||||
export declare function useLayoutState<State>(defaultState: State): [State, (updater: Updater<State>) => void];
|
||||
/** Lock frame, when frame pass reset the lock. */
|
||||
export declare function useTimeoutLock<State>(defaultState?: State): [(state: State) => void, () => State | null];
|
||||
62
frontend/node_modules/rc-table/es/hooks/useFrame.js
generated
vendored
Normal file
62
frontend/node_modules/rc-table/es/hooks/useFrame.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
||||
import { useRef, useState, useEffect } from 'react';
|
||||
/**
|
||||
* Execute code before next frame but async
|
||||
*/
|
||||
export function useLayoutState(defaultState) {
|
||||
var stateRef = useRef(defaultState);
|
||||
var _useState = useState({}),
|
||||
_useState2 = _slicedToArray(_useState, 2),
|
||||
forceUpdate = _useState2[1];
|
||||
var lastPromiseRef = useRef(null);
|
||||
var updateBatchRef = useRef([]);
|
||||
function setFrameState(updater) {
|
||||
updateBatchRef.current.push(updater);
|
||||
var promise = Promise.resolve();
|
||||
lastPromiseRef.current = promise;
|
||||
promise.then(function () {
|
||||
if (lastPromiseRef.current === promise) {
|
||||
var prevBatch = updateBatchRef.current;
|
||||
var prevState = stateRef.current;
|
||||
updateBatchRef.current = [];
|
||||
prevBatch.forEach(function (batchUpdater) {
|
||||
stateRef.current = batchUpdater(stateRef.current);
|
||||
});
|
||||
lastPromiseRef.current = null;
|
||||
if (prevState !== stateRef.current) {
|
||||
forceUpdate({});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
useEffect(function () {
|
||||
return function () {
|
||||
lastPromiseRef.current = null;
|
||||
};
|
||||
}, []);
|
||||
return [stateRef.current, setFrameState];
|
||||
}
|
||||
|
||||
/** Lock frame, when frame pass reset the lock. */
|
||||
export function useTimeoutLock(defaultState) {
|
||||
var frameRef = useRef(defaultState || null);
|
||||
var timeoutRef = useRef();
|
||||
function cleanUp() {
|
||||
window.clearTimeout(timeoutRef.current);
|
||||
}
|
||||
function setState(newState) {
|
||||
frameRef.current = newState;
|
||||
cleanUp();
|
||||
timeoutRef.current = window.setTimeout(function () {
|
||||
frameRef.current = null;
|
||||
timeoutRef.current = undefined;
|
||||
}, 100);
|
||||
}
|
||||
function getState() {
|
||||
return frameRef.current;
|
||||
}
|
||||
useEffect(function () {
|
||||
return cleanUp;
|
||||
}, []);
|
||||
return [setState, getState];
|
||||
}
|
||||
2
frontend/node_modules/rc-table/es/hooks/useHover.d.ts
generated
vendored
Normal file
2
frontend/node_modules/rc-table/es/hooks/useHover.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export type OnHover = (start: number, end: number) => void;
|
||||
export default function useHover(): [startRow: number, endRow: number, onHover: OnHover];
|
||||
17
frontend/node_modules/rc-table/es/hooks/useHover.js
generated
vendored
Normal file
17
frontend/node_modules/rc-table/es/hooks/useHover.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
||||
import * as React from 'react';
|
||||
export default function useHover() {
|
||||
var _React$useState = React.useState(-1),
|
||||
_React$useState2 = _slicedToArray(_React$useState, 2),
|
||||
startRow = _React$useState2[0],
|
||||
setStartRow = _React$useState2[1];
|
||||
var _React$useState3 = React.useState(-1),
|
||||
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
||||
endRow = _React$useState4[0],
|
||||
setEndRow = _React$useState4[1];
|
||||
var onHover = React.useCallback(function (start, end) {
|
||||
setStartRow(start);
|
||||
setEndRow(end);
|
||||
}, []);
|
||||
return [startRow, endRow, onHover];
|
||||
}
|
||||
5
frontend/node_modules/rc-table/es/hooks/useRenderTimes.d.ts
generated
vendored
Normal file
5
frontend/node_modules/rc-table/es/hooks/useRenderTimes.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as React from 'react';
|
||||
declare function useRenderTimes<T extends object>(props?: T, debug?: string): number;
|
||||
declare const _default: typeof useRenderTimes | (() => void);
|
||||
export default _default;
|
||||
export declare const RenderBlock: React.MemoExoticComponent<() => React.JSX.Element>;
|
||||
38
frontend/node_modules/rc-table/es/hooks/useRenderTimes.js
generated
vendored
Normal file
38
frontend/node_modules/rc-table/es/hooks/useRenderTimes.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/* istanbul ignore file */
|
||||
import * as React from 'react';
|
||||
function useRenderTimes(props, debug) {
|
||||
// Render times
|
||||
var timesRef = React.useRef(0);
|
||||
timesRef.current += 1;
|
||||
|
||||
// Props changed
|
||||
var propsRef = React.useRef(props);
|
||||
var keys = [];
|
||||
Object.keys(props || {}).map(function (key) {
|
||||
var _propsRef$current;
|
||||
if ((props === null || props === void 0 ? void 0 : props[key]) !== ((_propsRef$current = propsRef.current) === null || _propsRef$current === void 0 ? void 0 : _propsRef$current[key])) {
|
||||
keys.push(key);
|
||||
}
|
||||
});
|
||||
propsRef.current = props;
|
||||
|
||||
// Cache keys since React rerender may cause it lost
|
||||
var keysRef = React.useRef([]);
|
||||
if (keys.length) {
|
||||
keysRef.current = keys;
|
||||
}
|
||||
React.useDebugValue(timesRef.current);
|
||||
React.useDebugValue(keysRef.current.join(', '));
|
||||
if (debug) {
|
||||
console.log("".concat(debug, ":"), timesRef.current, keysRef.current);
|
||||
}
|
||||
return timesRef.current;
|
||||
}
|
||||
export default process.env.NODE_ENV !== 'production' ? useRenderTimes : function () {};
|
||||
export var RenderBlock = /*#__PURE__*/React.memo(function () {
|
||||
var times = useRenderTimes();
|
||||
return /*#__PURE__*/React.createElement("h1", null, "Render Times: ", times);
|
||||
});
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
RenderBlock.displayName = 'RenderBlock';
|
||||
}
|
||||
12
frontend/node_modules/rc-table/es/hooks/useRowInfo.d.ts
generated
vendored
Normal file
12
frontend/node_modules/rc-table/es/hooks/useRowInfo.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/// <reference types="react" />
|
||||
import type { TableContextProps } from '../context/TableContext';
|
||||
export default function useRowInfo<RecordType>(record: RecordType, rowKey: React.Key, recordIndex: number, indent: number): Pick<TableContextProps, 'prefixCls' | 'fixedInfoList' | 'flattenColumns' | 'expandableType' | 'expandRowByClick' | 'onTriggerExpand' | 'rowClassName' | 'expandedRowClassName' | 'indentSize' | 'expandIcon' | 'expandedRowRender' | 'expandIconColumnIndex' | 'expandedKeys' | 'childrenColumnName' | 'onRow'> & {
|
||||
columnsKey: React.Key[];
|
||||
nestExpandable: boolean;
|
||||
expanded: boolean;
|
||||
hasNestChildren: boolean;
|
||||
record: RecordType;
|
||||
rowSupportExpand: boolean;
|
||||
expandable: boolean;
|
||||
rowProps: React.HTMLAttributes<any> & React.TdHTMLAttributes<any>;
|
||||
};
|
||||
65
frontend/node_modules/rc-table/es/hooks/useRowInfo.js
generated
vendored
Normal file
65
frontend/node_modules/rc-table/es/hooks/useRowInfo.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
||||
import { useContext } from '@rc-component/context';
|
||||
import TableContext from "../context/TableContext";
|
||||
import { getColumnsKey } from "../utils/valueUtil";
|
||||
import { useEvent } from 'rc-util';
|
||||
import classNames from 'classnames';
|
||||
export default function useRowInfo(record, rowKey, recordIndex, indent) {
|
||||
var context = useContext(TableContext, ['prefixCls', 'fixedInfoList', 'flattenColumns', 'expandableType', 'expandRowByClick', 'onTriggerExpand', 'rowClassName', 'expandedRowClassName', 'indentSize', 'expandIcon', 'expandedRowRender', 'expandIconColumnIndex', 'expandedKeys', 'childrenColumnName', 'rowExpandable', 'onRow']);
|
||||
var flattenColumns = context.flattenColumns,
|
||||
expandableType = context.expandableType,
|
||||
expandedKeys = context.expandedKeys,
|
||||
childrenColumnName = context.childrenColumnName,
|
||||
onTriggerExpand = context.onTriggerExpand,
|
||||
rowExpandable = context.rowExpandable,
|
||||
onRow = context.onRow,
|
||||
expandRowByClick = context.expandRowByClick,
|
||||
rowClassName = context.rowClassName;
|
||||
|
||||
// ======================= Expandable =======================
|
||||
// Only when row is not expandable and `children` exist in record
|
||||
var nestExpandable = expandableType === 'nest';
|
||||
var rowSupportExpand = expandableType === 'row' && (!rowExpandable || rowExpandable(record));
|
||||
var mergedExpandable = rowSupportExpand || nestExpandable;
|
||||
var expanded = expandedKeys && expandedKeys.has(rowKey);
|
||||
var hasNestChildren = childrenColumnName && record && record[childrenColumnName];
|
||||
var onInternalTriggerExpand = useEvent(onTriggerExpand);
|
||||
|
||||
// ========================= onRow ==========================
|
||||
var rowProps = onRow === null || onRow === void 0 ? void 0 : onRow(record, recordIndex);
|
||||
var onRowClick = rowProps === null || rowProps === void 0 ? void 0 : rowProps.onClick;
|
||||
var onClick = function onClick(event) {
|
||||
if (expandRowByClick && mergedExpandable) {
|
||||
onTriggerExpand(record, event);
|
||||
}
|
||||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
args[_key - 1] = arguments[_key];
|
||||
}
|
||||
onRowClick === null || onRowClick === void 0 || onRowClick.apply(void 0, [event].concat(args));
|
||||
};
|
||||
|
||||
// ====================== RowClassName ======================
|
||||
var computeRowClassName;
|
||||
if (typeof rowClassName === 'string') {
|
||||
computeRowClassName = rowClassName;
|
||||
} else if (typeof rowClassName === 'function') {
|
||||
computeRowClassName = rowClassName(record, recordIndex, indent);
|
||||
}
|
||||
|
||||
// ========================= Column =========================
|
||||
var columnsKey = getColumnsKey(flattenColumns);
|
||||
return _objectSpread(_objectSpread({}, context), {}, {
|
||||
columnsKey: columnsKey,
|
||||
nestExpandable: nestExpandable,
|
||||
expanded: expanded,
|
||||
hasNestChildren: hasNestChildren,
|
||||
record: record,
|
||||
onTriggerExpand: onInternalTriggerExpand,
|
||||
rowSupportExpand: rowSupportExpand,
|
||||
expandable: mergedExpandable,
|
||||
rowProps: _objectSpread(_objectSpread({}, rowProps), {}, {
|
||||
className: classNames(computeRowClassName, rowProps === null || rowProps === void 0 ? void 0 : rowProps.className),
|
||||
onClick: onClick
|
||||
})
|
||||
});
|
||||
}
|
||||
10
frontend/node_modules/rc-table/es/hooks/useSticky.d.ts
generated
vendored
Normal file
10
frontend/node_modules/rc-table/es/hooks/useSticky.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { TableSticky } from '../interface';
|
||||
/** Sticky header hooks */
|
||||
export default function useSticky(sticky: boolean | TableSticky, prefixCls: string): {
|
||||
isSticky: boolean;
|
||||
offsetHeader: number;
|
||||
offsetSummary: number;
|
||||
offsetScroll: number;
|
||||
stickyClassName: string;
|
||||
container: Window | HTMLElement;
|
||||
};
|
||||
32
frontend/node_modules/rc-table/es/hooks/useSticky.js
generated
vendored
Normal file
32
frontend/node_modules/rc-table/es/hooks/useSticky.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
||||
import * as React from 'react';
|
||||
import canUseDom from "rc-util/es/Dom/canUseDom";
|
||||
// fix ssr render
|
||||
var defaultContainer = canUseDom() ? window : null;
|
||||
|
||||
/** Sticky header hooks */
|
||||
export default function useSticky(sticky, prefixCls) {
|
||||
var _ref = _typeof(sticky) === 'object' ? sticky : {},
|
||||
_ref$offsetHeader = _ref.offsetHeader,
|
||||
offsetHeader = _ref$offsetHeader === void 0 ? 0 : _ref$offsetHeader,
|
||||
_ref$offsetSummary = _ref.offsetSummary,
|
||||
offsetSummary = _ref$offsetSummary === void 0 ? 0 : _ref$offsetSummary,
|
||||
_ref$offsetScroll = _ref.offsetScroll,
|
||||
offsetScroll = _ref$offsetScroll === void 0 ? 0 : _ref$offsetScroll,
|
||||
_ref$getContainer = _ref.getContainer,
|
||||
getContainer = _ref$getContainer === void 0 ? function () {
|
||||
return defaultContainer;
|
||||
} : _ref$getContainer;
|
||||
var container = getContainer() || defaultContainer;
|
||||
var isSticky = !!sticky;
|
||||
return React.useMemo(function () {
|
||||
return {
|
||||
isSticky: isSticky,
|
||||
stickyClassName: isSticky ? "".concat(prefixCls, "-sticky-holder") : '',
|
||||
offsetHeader: offsetHeader,
|
||||
offsetSummary: offsetSummary,
|
||||
offsetScroll: offsetScroll,
|
||||
container: container
|
||||
};
|
||||
}, [isSticky, offsetScroll, offsetHeader, offsetSummary, prefixCls, container]);
|
||||
}
|
||||
6
frontend/node_modules/rc-table/es/hooks/useStickyOffsets.d.ts
generated
vendored
Normal file
6
frontend/node_modules/rc-table/es/hooks/useStickyOffsets.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { ColumnType, Direction, StickyOffsets } from '../interface';
|
||||
/**
|
||||
* Get sticky column offset width
|
||||
*/
|
||||
declare function useStickyOffsets<RecordType>(colWidths: number[], flattenColumns: readonly ColumnType<RecordType>[], direction: Direction): StickyOffsets;
|
||||
export default useStickyOffsets;
|
||||
31
frontend/node_modules/rc-table/es/hooks/useStickyOffsets.js
generated
vendored
Normal file
31
frontend/node_modules/rc-table/es/hooks/useStickyOffsets.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useMemo } from 'react';
|
||||
/**
|
||||
* Get sticky column offset width
|
||||
*/
|
||||
function useStickyOffsets(colWidths, flattenColumns, direction) {
|
||||
var stickyOffsets = useMemo(function () {
|
||||
var columnCount = flattenColumns.length;
|
||||
var getOffsets = function getOffsets(startIndex, endIndex, offset) {
|
||||
var offsets = [];
|
||||
var total = 0;
|
||||
for (var i = startIndex; i !== endIndex; i += offset) {
|
||||
offsets.push(total);
|
||||
if (flattenColumns[i].fixed) {
|
||||
total += colWidths[i] || 0;
|
||||
}
|
||||
}
|
||||
return offsets;
|
||||
};
|
||||
var startOffsets = getOffsets(0, columnCount, 1);
|
||||
var endOffsets = getOffsets(columnCount - 1, -1, -1).reverse();
|
||||
return direction === 'rtl' ? {
|
||||
left: endOffsets,
|
||||
right: startOffsets
|
||||
} : {
|
||||
left: startOffsets,
|
||||
right: endOffsets
|
||||
};
|
||||
}, [colWidths, flattenColumns, direction]);
|
||||
return stickyOffsets;
|
||||
}
|
||||
export default useStickyOffsets;
|
||||
Reference in New Issue
Block a user