first commit
This commit is contained in:
32
frontend/node_modules/rc-table/lib/hooks/useColumns/index.d.ts
generated
vendored
Normal file
32
frontend/node_modules/rc-table/lib/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;
|
||||
280
frontend/node_modules/rc-table/lib/hooks/useColumns/index.js
generated
vendored
Normal file
280
frontend/node_modules/rc-table/lib/hooks/useColumns/index.js
generated
vendored
Normal file
@@ -0,0 +1,280 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.convertChildrenToColumns = convertChildrenToColumns;
|
||||
exports.default = void 0;
|
||||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
||||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
||||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
||||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
||||
var _toArray = _interopRequireDefault(require("rc-util/lib/Children/toArray"));
|
||||
var _warning = _interopRequireDefault(require("rc-util/lib/warning"));
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
var _constant = require("../../constant");
|
||||
var _legacyUtil = require("../../utils/legacyUtil");
|
||||
var _useWidthColumns3 = _interopRequireDefault(require("./useWidthColumns"));
|
||||
var _excluded = ["children"],
|
||||
_excluded2 = ["fixed"];
|
||||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
||||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
||||
function convertChildrenToColumns(children) {
|
||||
return (0, _toArray.default)(children).filter(function (node) {
|
||||
return /*#__PURE__*/React.isValidElement(node);
|
||||
}).map(function (_ref) {
|
||||
var key = _ref.key,
|
||||
props = _ref.props;
|
||||
var nodeChildren = props.children,
|
||||
restProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
||||
var column = (0, _objectSpread2.default)({
|
||||
key: key
|
||||
}, restProps);
|
||||
if (nodeChildren) {
|
||||
column.children = convertChildrenToColumns(nodeChildren);
|
||||
}
|
||||
return column;
|
||||
});
|
||||
}
|
||||
function filterHiddenColumns(columns) {
|
||||
return columns.filter(function (column) {
|
||||
return column && (0, _typeof2.default)(column) === 'object' && !column.hidden;
|
||||
}).map(function (column) {
|
||||
var subColumns = column.children;
|
||||
if (subColumns && subColumns.length > 0) {
|
||||
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, 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 && (0, _typeof2.default)(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((0, _toConsumableArray2.default)(list), (0, _toConsumableArray2.default)(flatColumns(subColumns, mergedKey).map(function (subColum) {
|
||||
var _subColum$fixed;
|
||||
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, subColum), {}, {
|
||||
fixed: (_subColum$fixed = subColum.fixed) !== null && _subColum$fixed !== void 0 ? _subColum$fixed : parsedFixed
|
||||
});
|
||||
})));
|
||||
}
|
||||
return [].concat((0, _toConsumableArray2.default)(list), [(0, _objectSpread2.default)((0, _objectSpread2.default)({
|
||||
key: mergedKey
|
||||
}, column), {}, {
|
||||
fixed: parsedFixed
|
||||
})]);
|
||||
}, []);
|
||||
}
|
||||
function revertForRtl(columns) {
|
||||
return columns.map(function (column) {
|
||||
var fixed = column.fixed,
|
||||
restProps = (0, _objectWithoutProperties2.default)(column, _excluded2);
|
||||
|
||||
// Convert `fixed='left'` to `fixed='right'` instead
|
||||
var parsedFixed = fixed;
|
||||
if (fixed === 'left') {
|
||||
parsedFixed = 'right';
|
||||
} else if (fixed === 'right') {
|
||||
parsedFixed = 'left';
|
||||
}
|
||||
return (0, _objectSpread2.default)({
|
||||
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) {
|
||||
(0, _warning.default)(false, '`expandIconColumnIndex` is deprecated. Please use `Table.EXPAND_COLUMN` in `columns` instead.');
|
||||
}
|
||||
|
||||
// >>> Insert expand column if not exist
|
||||
if (!cloneColumns.includes(_constant.EXPAND_COLUMN)) {
|
||||
var expandColIndex = expandIconColumnIndex || 0;
|
||||
var insertIndex = expandColIndex === 0 && fixed === 'right' ? baseColumns.length : expandColIndex;
|
||||
if (insertIndex >= 0) {
|
||||
cloneColumns.splice(insertIndex, 0, _constant.EXPAND_COLUMN);
|
||||
}
|
||||
}
|
||||
|
||||
// >>> Deduplicate additional expand column
|
||||
if (process.env.NODE_ENV !== 'production' && cloneColumns.filter(function (c) {
|
||||
return c === _constant.EXPAND_COLUMN;
|
||||
}).length > 1) {
|
||||
(0, _warning.default)(false, 'There exist more than one `EXPAND_COLUMN` in `columns`.');
|
||||
}
|
||||
var expandColumnIndex = cloneColumns.indexOf(_constant.EXPAND_COLUMN);
|
||||
cloneColumns = cloneColumns.filter(function (column, index) {
|
||||
return column !== _constant.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 = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _legacyUtil.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 === _constant.EXPAND_COLUMN ? expandColumn : col;
|
||||
if (index < expandedRowOffset) {
|
||||
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, column), {}, {
|
||||
fixed: column.fixed || 'left'
|
||||
});
|
||||
}
|
||||
return column;
|
||||
});
|
||||
}
|
||||
if (process.env.NODE_ENV !== 'production' && baseColumns.includes(_constant.EXPAND_COLUMN)) {
|
||||
(0, _warning.default)(false, '`expandable` is not config but there exist `EXPAND_COLUMN` in `columns`.');
|
||||
}
|
||||
return baseColumns.filter(function (col) {
|
||||
return col !== _constant.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 = (0, _useWidthColumns3.default)(flattenColumns, scrollWidth, clientWidth),
|
||||
_useWidthColumns2 = (0, _slicedToArray2.default)(_useWidthColumns, 2),
|
||||
filledColumns = _useWidthColumns2[0],
|
||||
realScrollWidth = _useWidthColumns2[1];
|
||||
return [mergedColumns, filledColumns, realScrollWidth, hasGapFixed];
|
||||
}
|
||||
var _default = exports.default = useColumns;
|
||||
5
frontend/node_modules/rc-table/lib/hooks/useColumns/useWidthColumns.d.ts
generated
vendored
Normal file
5
frontend/node_modules/rc-table/lib/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];
|
||||
80
frontend/node_modules/rc-table/lib/hooks/useColumns/useWidthColumns.js
generated
vendored
Normal file
80
frontend/node_modules/rc-table/lib/hooks/useColumns/useWidthColumns.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
var _typeof = require("@babel/runtime/helpers/typeof");
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = useWidthColumns;
|
||||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
||||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
||||
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
|
||||
*/
|
||||
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 = (0, _objectSpread2.default)({}, 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]);
|
||||
}
|
||||
Reference in New Issue
Block a user