1
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import type { RenderExpandIconProps, Key, GetRowKey, ExpandableConfig } from '../interface';
|
||||
export declare function renderExpandIcon<RecordType>({ prefixCls, record, onExpand, expanded, expandable, }: RenderExpandIconProps<RecordType>): React.JSX.Element;
|
||||
export declare function findAllChildrenKeys<RecordType>(data: readonly RecordType[], getRowKey: GetRowKey<RecordType>, childrenColumnName: string): Key[];
|
||||
export declare function computedExpandedClassName<RecordType>(cls: ExpandableConfig<RecordType>['expandedRowClassName'], record: RecordType, index: number, indent: number): string;
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
import * as React from 'react';
|
||||
import { clsx } from 'clsx';
|
||||
export function renderExpandIcon({
|
||||
prefixCls,
|
||||
record,
|
||||
onExpand,
|
||||
expanded,
|
||||
expandable
|
||||
}) {
|
||||
const expandClassName = `${prefixCls}-row-expand-icon`;
|
||||
if (!expandable) {
|
||||
return /*#__PURE__*/React.createElement("span", {
|
||||
className: clsx(expandClassName, `${prefixCls}-row-spaced`)
|
||||
});
|
||||
}
|
||||
const onClick = event => {
|
||||
onExpand(record, event);
|
||||
event.stopPropagation();
|
||||
};
|
||||
return /*#__PURE__*/React.createElement("span", {
|
||||
className: clsx(expandClassName, {
|
||||
[`${prefixCls}-row-expanded`]: expanded,
|
||||
[`${prefixCls}-row-collapsed`]: !expanded
|
||||
}),
|
||||
onClick: onClick
|
||||
});
|
||||
}
|
||||
export function findAllChildrenKeys(data, getRowKey, childrenColumnName) {
|
||||
const keys = [];
|
||||
function dig(list) {
|
||||
(list || []).forEach((item, index) => {
|
||||
keys.push(getRowKey(item, index));
|
||||
dig(item[childrenColumnName]);
|
||||
});
|
||||
}
|
||||
dig(data);
|
||||
return keys;
|
||||
}
|
||||
export function computedExpandedClassName(cls, record, index, indent) {
|
||||
if (typeof cls === 'string') {
|
||||
return cls;
|
||||
}
|
||||
if (typeof cls === 'function') {
|
||||
return cls(record, index, indent);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import type { FixedType, StickyOffsets } from '../interface';
|
||||
export interface FixedInfo {
|
||||
fixStart: number | false;
|
||||
fixEnd: number | false;
|
||||
isSticky: boolean;
|
||||
/** `fixed: start` with shadow */
|
||||
fixedStartShadow?: boolean;
|
||||
/** `fixed: end` with shadow */
|
||||
fixedEndShadow?: boolean;
|
||||
/** Show the shadow when `scrollLeft` arrive for `fixed: start` */
|
||||
offsetFixedStartShadow?: number;
|
||||
/** Show the shadow when `scrollLeft` arrive for `fixed: end` */
|
||||
offsetFixedEndShadow?: number;
|
||||
/** First sticky column `zIndex` will be larger than next */
|
||||
zIndex?: number;
|
||||
/** First sticky column `zIndex` will be smaller than next */
|
||||
zIndexReverse?: number;
|
||||
}
|
||||
export declare function getCellFixedInfo(colStart: number, colEnd: number, columns: readonly {
|
||||
fixed?: FixedType;
|
||||
}[], stickyOffsets: StickyOffsets): FixedInfo;
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
function isFixedStart(column) {
|
||||
return column.fixed === 'start';
|
||||
}
|
||||
function isFixedEnd(column) {
|
||||
return column.fixed === 'end';
|
||||
}
|
||||
export function getCellFixedInfo(colStart, colEnd, columns, stickyOffsets) {
|
||||
const startColumn = columns[colStart] || {};
|
||||
const endColumn = columns[colEnd] || {};
|
||||
let fixStart = null;
|
||||
let fixEnd = null;
|
||||
if (isFixedStart(startColumn) && isFixedStart(endColumn)) {
|
||||
fixStart = stickyOffsets.start[colStart];
|
||||
} else if (isFixedEnd(endColumn) && isFixedEnd(startColumn)) {
|
||||
fixEnd = stickyOffsets.end[colEnd];
|
||||
}
|
||||
|
||||
// check if need to add shadow
|
||||
let fixedStartShadow = false;
|
||||
let fixedEndShadow = false;
|
||||
|
||||
// Calc `zIndex`.
|
||||
// first fixed start (start -> end) column `zIndex` should be greater than next column.
|
||||
// first fixed end (end -> start) column `zIndex` should be greater than next column.
|
||||
let zIndex = 0;
|
||||
let zIndexReverse = 0;
|
||||
if (fixStart !== null) {
|
||||
fixedStartShadow = !columns[colEnd + 1] || !isFixedStart(columns[colEnd + 1]);
|
||||
zIndex = columns.length * 2 - colStart; // Fix start always overlay fix end
|
||||
zIndexReverse = columns.length + colStart;
|
||||
}
|
||||
if (fixEnd !== null) {
|
||||
fixedEndShadow = !columns[colStart - 1] || !isFixedEnd(columns[colStart - 1]);
|
||||
zIndex = colEnd;
|
||||
zIndexReverse = columns.length - colEnd; // Fix end always overlay fix start
|
||||
}
|
||||
|
||||
// Check if scrollLeft will show the shadow
|
||||
let offsetFixedStartShadow = 0;
|
||||
let offsetFixedEndShadow = 0;
|
||||
if (fixedStartShadow) {
|
||||
for (let i = 0; i < colStart; i += 1) {
|
||||
if (!isFixedStart(columns[i])) {
|
||||
offsetFixedStartShadow += stickyOffsets.widths[i] || 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fixedEndShadow) {
|
||||
for (let i = columns.length - 1; i > colEnd; i -= 1) {
|
||||
if (!isFixedEnd(columns[i])) {
|
||||
offsetFixedEndShadow += stickyOffsets.widths[i] || 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
fixStart,
|
||||
fixEnd,
|
||||
fixedStartShadow,
|
||||
fixedEndShadow,
|
||||
offsetFixedStartShadow,
|
||||
offsetFixedEndShadow,
|
||||
isSticky: stickyOffsets.isSticky,
|
||||
zIndex,
|
||||
zIndexReverse
|
||||
};
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { ExpandableConfig, LegacyExpandableProps } from '../interface';
|
||||
export declare const INTERNAL_COL_DEFINE = "RC_TABLE_INTERNAL_COL_DEFINE";
|
||||
export declare function getExpandableProps<RecordType>(props: LegacyExpandableProps<RecordType> & {
|
||||
expandable?: ExpandableConfig<RecordType>;
|
||||
}): ExpandableConfig<RecordType>;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import warning from "@rc-component/util/es/warning";
|
||||
export const INTERNAL_COL_DEFINE = 'RC_TABLE_INTERNAL_COL_DEFINE';
|
||||
export function getExpandableProps(props) {
|
||||
const {
|
||||
expandable,
|
||||
...legacyExpandableConfig
|
||||
} = props;
|
||||
let config;
|
||||
if ('expandable' in props) {
|
||||
config = {
|
||||
...legacyExpandableConfig,
|
||||
...expandable
|
||||
};
|
||||
} else {
|
||||
if (process.env.NODE_ENV !== 'production' && ['indentSize', 'expandedRowKeys', 'defaultExpandedRowKeys', 'defaultExpandAllRows', 'expandedRowRender', 'expandRowByClick', 'expandIcon', 'onExpand', 'onExpandedRowsChange', 'expandedRowClassName', 'expandIconColumnIndex', 'showExpandColumn', 'title'].some(prop => prop in props)) {
|
||||
warning(false, 'expanded related props have been moved into `expandable`.');
|
||||
}
|
||||
config = legacyExpandableConfig;
|
||||
}
|
||||
if (config.showExpandColumn === false) {
|
||||
config.expandIconColumnIndex = -1;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export declare function getOffset(node: HTMLElement | Window): {
|
||||
left: number;
|
||||
top: number;
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { getDOM } from "@rc-component/util/es/Dom/findDOMNode";
|
||||
|
||||
// Copy from `rc-component/util/Dom/css.js`
|
||||
export function getOffset(node) {
|
||||
const element = getDOM(node);
|
||||
const box = element.getBoundingClientRect();
|
||||
const docElem = document.documentElement;
|
||||
|
||||
// < ie8 not support win.pageXOffset, use docElem.scrollLeft instead
|
||||
return {
|
||||
left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0),
|
||||
top: box.top + (window.pageYOffset || docElem.scrollTop) - (docElem.clientTop || document.body.clientTop || 0)
|
||||
};
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
/// <reference types="react" />
|
||||
import type { DataIndex, Key } from '../interface';
|
||||
export interface GetColumnKeyColumn<T = any> {
|
||||
key?: Key;
|
||||
dataIndex?: DataIndex<T>;
|
||||
}
|
||||
export declare function getColumnsKey<T = any>(columns: readonly GetColumnKeyColumn<T>[]): import("react").Key[];
|
||||
export declare function validateValue<T>(val: T): boolean;
|
||||
export declare function validNumberValue(value: any): boolean;
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
const INTERNAL_KEY_PREFIX = 'RC_TABLE_KEY';
|
||||
function toArray(arr) {
|
||||
if (arr === undefined || arr === null) {
|
||||
return [];
|
||||
}
|
||||
return Array.isArray(arr) ? arr : [arr];
|
||||
}
|
||||
export function getColumnsKey(columns) {
|
||||
const columnKeys = [];
|
||||
const keys = {};
|
||||
columns.forEach(column => {
|
||||
const {
|
||||
key,
|
||||
dataIndex
|
||||
} = column || {};
|
||||
let mergedKey = key || toArray(dataIndex).join('-') || INTERNAL_KEY_PREFIX;
|
||||
while (keys[mergedKey]) {
|
||||
mergedKey = `${mergedKey}_next`;
|
||||
}
|
||||
keys[mergedKey] = true;
|
||||
columnKeys.push(mergedKey);
|
||||
});
|
||||
return columnKeys;
|
||||
}
|
||||
export function validateValue(val) {
|
||||
return val !== null && val !== undefined;
|
||||
}
|
||||
export function validNumberValue(value) {
|
||||
return typeof value === 'number' && !Number.isNaN(value);
|
||||
}
|
||||
Reference in New Issue
Block a user