@guozhi5658/srp-table 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base-table/calculations.d.ts +3 -0
- package/dist/base-table/colgroup.d.ts +5 -0
- package/dist/base-table/empty.d.ts +9 -0
- package/dist/base-table/header.d.ts +5 -0
- package/dist/base-table/helpers/SpanManager.d.ts +9 -0
- package/dist/base-table/helpers/TableDOMUtils.d.ts +16 -0
- package/dist/base-table/helpers/getRichVisibleRectsStream.d.ts +23 -0
- package/dist/base-table/helpers/rowHeightManager.d.ts +7 -0
- package/dist/base-table/html-table.d.ts +15 -0
- package/dist/base-table/index.d.ts +3 -0
- package/dist/base-table/interfaces.d.ts +54 -0
- package/dist/base-table/loading.d.ts +13 -0
- package/dist/base-table/styles.d.ts +83 -0
- package/dist/base-table/table.d.ts +185 -0
- package/dist/base-table/utils.d.ts +22 -0
- package/dist/chunks/srp-table-pipeline-93090855.js +2564 -0
- package/dist/chunks/srp-table-pipeline-cc27a3d4.esm.js +2517 -0
- package/dist/common-views.d.ts +23 -0
- package/dist/interfaces.d.ts +65 -0
- package/dist/internals.d.ts +15 -0
- package/dist/pipeline/features/autoRowSpan.d.ts +2 -0
- package/dist/pipeline/features/buildTree.d.ts +2 -0
- package/dist/pipeline/features/columnHover.d.ts +12 -0
- package/dist/pipeline/features/columnRangeHover.d.ts +15 -0
- package/dist/pipeline/features/columnResize.d.ts +24 -0
- package/dist/pipeline/features/index.d.ts +14 -0
- package/dist/pipeline/features/multiSelect.d.ts +27 -0
- package/dist/pipeline/features/rowDetail.d.ts +29 -0
- package/dist/pipeline/features/rowGrouping.d.ts +14 -0
- package/dist/pipeline/features/rowPopover.d.ts +13 -0
- package/dist/pipeline/features/singleSelect.d.ts +23 -0
- package/dist/pipeline/features/sort.d.ts +42 -0
- package/dist/pipeline/features/tips.d.ts +2 -0
- package/dist/pipeline/features/treeMode.d.ts +29 -0
- package/dist/pipeline/features/treeSelect.d.ts +38 -0
- package/dist/pipeline/index.d.ts +3 -0
- package/dist/pipeline/pipeline.d.ts +79 -0
- package/dist/pivot/cross-table/buildCrossTable.d.ts +17 -0
- package/dist/pivot/cross-table/constants.d.ts +1 -0
- package/dist/pivot/cross-table/cross-table.d.ts +18 -0
- package/dist/pivot/cross-table/index.d.ts +4 -0
- package/dist/pivot/cross-table/interfaces.d.ts +29 -0
- package/dist/pivot/cross-table/internals.d.ts +13 -0
- package/dist/pivot/cross-tree-table/buildCrossTreeTable.d.ts +14 -0
- package/dist/pivot/cross-tree-table/cross-tree-table.d.ts +38 -0
- package/dist/pivot/cross-tree-table/index.d.ts +2 -0
- package/dist/pivot/pivot-utils/buildDrillTree.d.ts +16 -0
- package/dist/pivot/pivot-utils/builders.d.ts +26 -0
- package/dist/pivot/pivot-utils/convert-utils.d.ts +31 -0
- package/dist/pivot/pivot-utils/index.d.ts +5 -0
- package/dist/pivot/pivot-utils/interfaces.d.ts +12 -0
- package/dist/pivot/pivot-utils/simpleEncode.d.ts +1 -0
- package/dist/srp-table-pivot.d.ts +3 -0
- package/dist/srp-table-pivot.esm.js +686 -0
- package/dist/srp-table-pivot.js +704 -0
- package/dist/srp-table.d.ts +6 -0
- package/dist/srp-table.esm.js +2472 -0
- package/dist/srp-table.js +2536 -0
- package/dist/transforms/autoRowSpan.d.ts +3 -0
- package/dist/transforms/autoWidth.d.ts +25 -0
- package/dist/transforms/buildTree.d.ts +3 -0
- package/dist/transforms/columnHover.d.ts +14 -0
- package/dist/transforms/columnRangeHover.d.ts +14 -0
- package/dist/transforms/columnResize.d.ts +24 -0
- package/dist/transforms/flatten.d.ts +3 -0
- package/dist/transforms/index.d.ts +12 -0
- package/dist/transforms/orderField.d.ts +3 -0
- package/dist/transforms/sort.d.ts +40 -0
- package/dist/transforms/tips.d.ts +8 -0
- package/dist/transforms/treeMode.d.ts +27 -0
- package/dist/transforms/visible.d.ts +2 -0
- package/dist/transforms/warnTransformsDeprecated.d.ts +1 -0
- package/dist/utils/applyTransforms.d.ts +6 -0
- package/dist/utils/buildTree.d.ts +36 -0
- package/dist/utils/collectNodes.d.ts +8 -0
- package/dist/utils/exportTableAsExcel.d.ts +4 -0
- package/dist/utils/getTreeDepth.d.ts +3 -0
- package/dist/utils/groupBy.d.ts +1 -0
- package/dist/utils/groupBy2.d.ts +1 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/isLeafNode.d.ts +2 -0
- package/dist/utils/layeredSort.d.ts +5 -0
- package/dist/utils/makeRecursiveMapper.d.ts +9 -0
- package/dist/utils/mergeCellProps.d.ts +9 -0
- package/dist/utils/others.d.ts +10 -0
- package/dist/utils/proto.d.ts +21 -0
- package/dist/utils/smartCompare.d.ts +9 -0
- package/dist/utils/traverseColumn.d.ts +11 -0
- package/dist/utils/tree-data-helpers/StrictTreeDataHelper.d.ts +22 -0
- package/dist/utils/tree-data-helpers/TreeDataHelper.d.ts +26 -0
- package/dist/utils/tree-data-helpers/__tests__/helpers.test.d.ts +1 -0
- package/package.json +72 -0
- package/pivot/package.json +9 -0
- package/readme.md +124 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BaseTable } from '../base-table';
|
|
3
|
+
import { TableTransform } from '../interfaces';
|
|
4
|
+
/** 自适应列宽
|
|
5
|
+
*
|
|
6
|
+
* @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展
|
|
7
|
+
*
|
|
8
|
+
* @param tableRef BaseTable 的 ref
|
|
9
|
+
* @param options 参数
|
|
10
|
+
* @param deps 重新调整列宽的依赖数组,每当依赖数组发生变化时, useAutoWidthTransform 会根据单元格内容的实际渲染宽度 设置单元格的宽度
|
|
11
|
+
*
|
|
12
|
+
* options 说明:
|
|
13
|
+
* - options.appendExpander 是否在列的末尾追加可伸缩列
|
|
14
|
+
* - options.expanderVisibility 设置为 `'hidden'` 可以隐藏可伸缩列
|
|
15
|
+
* - options.wrapperStyle 单元格中 div.auto-width-wrapper 的样式
|
|
16
|
+
* - options.initColumnWidth 自适应的初始列宽
|
|
17
|
+
*
|
|
18
|
+
* 注意 useAutoWidthTransform 是一个 React hooks,要遵循 hooks 的用法规范
|
|
19
|
+
* */
|
|
20
|
+
export declare function useAutoWidthTransform(tableRef: React.MutableRefObject<BaseTable>, options?: {
|
|
21
|
+
wrapperStyle?: React.CSSProperties;
|
|
22
|
+
initColumnWidth?: number;
|
|
23
|
+
appendExpander?: boolean;
|
|
24
|
+
expanderVisibility?: 'visible' | 'hidden';
|
|
25
|
+
}, deps?: any[]): TableTransform;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TableTransform } from '../interfaces';
|
|
2
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
3
|
+
export interface ColumnHoverOptions {
|
|
4
|
+
hoverColor?: string;
|
|
5
|
+
hoverColIndex: number;
|
|
6
|
+
onChangeHoverColIndex(nextColIndex: number): void;
|
|
7
|
+
}
|
|
8
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
9
|
+
export declare function makeColumnHoverTransform({ hoverColor, hoverColIndex, onChangeHoverColIndex, }: ColumnHoverOptions): TableTransform;
|
|
10
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
11
|
+
export declare function useColumnHoverTransform({ hoverColor, defaultHoverColIndex, }?: {
|
|
12
|
+
hoverColor?: string;
|
|
13
|
+
defaultHoverColIndex?: number;
|
|
14
|
+
}): TableTransform;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HoverRange, TableTransform } from '../interfaces';
|
|
2
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
3
|
+
export interface ColumnRangeHoverOptions {
|
|
4
|
+
hoverColor?: string;
|
|
5
|
+
headerHoverColor?: string;
|
|
6
|
+
hoverRange: HoverRange;
|
|
7
|
+
onChangeHoverRange(nextColIndexRange: HoverRange): void;
|
|
8
|
+
}
|
|
9
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
10
|
+
export declare function makeColumnRangeHoverTransform({ hoverColor, headerHoverColor, hoverRange, onChangeHoverRange, }: ColumnRangeHoverOptions): TableTransform;
|
|
11
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
12
|
+
export declare function useColumnHoverRangeTransform({ hoverColor, headerHoverColor, defaultHoverRange, }?: Omit<ColumnRangeHoverOptions, 'hoverRange' | 'onChangeHoverRange'> & {
|
|
13
|
+
defaultHoverRange?: HoverRange;
|
|
14
|
+
}): TableTransform;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TableTransform } from '../interfaces';
|
|
2
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
3
|
+
export interface ColumnResizeOptions {
|
|
4
|
+
/** 每一列的宽度 */
|
|
5
|
+
sizes: number[];
|
|
6
|
+
/** 修改宽度的回调函数 */
|
|
7
|
+
onChangeSizes(nextSizes: number[]): void;
|
|
8
|
+
/** 列的最小宽度,默认为 40 */
|
|
9
|
+
minSize?: number;
|
|
10
|
+
/** 列的最大宽度,默认为 Infinity */
|
|
11
|
+
maxSize?: number;
|
|
12
|
+
/** 是否在列的末尾追加可伸缩列,默认为 false */
|
|
13
|
+
appendExpander?: boolean;
|
|
14
|
+
/** 是否在调整列宽时禁用 user-select,默认为 false */
|
|
15
|
+
disableUserSelectWhenResizing?: boolean;
|
|
16
|
+
/** 可伸缩列 style.visibility */
|
|
17
|
+
expanderVisibility?: 'visible' | 'hidden';
|
|
18
|
+
}
|
|
19
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
20
|
+
export declare function makeColumnResizeTransform({ sizes, onChangeSizes, minSize, maxSize, appendExpander, expanderVisibility, disableUserSelectWhenResizing, }: ColumnResizeOptions): TableTransform;
|
|
21
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
22
|
+
export declare function useColumnResizeTransform({ defaultSizes, ...others }: Omit<ColumnResizeOptions, 'sizes' | 'onChangeSizes'> & {
|
|
23
|
+
defaultSizes: number[];
|
|
24
|
+
}): TableTransform;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { makeAutoRowSpanTransform } from './autoRowSpan';
|
|
2
|
+
export { useAutoWidthTransform } from './autoWidth';
|
|
3
|
+
export { makeBuildTreeTransform } from './buildTree';
|
|
4
|
+
export { makeColumnHoverTransform, ColumnHoverOptions, useColumnHoverTransform } from './columnHover';
|
|
5
|
+
export { makeColumnRangeHoverTransform, ColumnRangeHoverOptions, useColumnHoverRangeTransform, } from './columnRangeHover';
|
|
6
|
+
export { makeColumnResizeTransform, ColumnResizeOptions, useColumnResizeTransform } from './columnResize';
|
|
7
|
+
export { makeFlattenTransform } from './flatten';
|
|
8
|
+
export { makeOrderFieldTransform } from './orderField';
|
|
9
|
+
export { makeSortTransform, SortHeaderCellProps, SortOptions, useSortTransform } from './sort';
|
|
10
|
+
export { makeTipsTransform, TipsOptions } from './tips';
|
|
11
|
+
export { makeTreeModeTransform, TreeModeOptions, useTreeModeTransform } from './treeMode';
|
|
12
|
+
export { makeVisibleTransform } from './visible';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ArtColumn, SortItem, SortOrder, TableTransform } from '../interfaces';
|
|
3
|
+
export interface SortHeaderCellProps {
|
|
4
|
+
/** 调用 makeSortTransform(...) 时的参数 */
|
|
5
|
+
sortOptions: Required<Omit<SortOptions, 'SortHeaderCell'>>;
|
|
6
|
+
/** 在添加排序相关的内容之前 表头原有的渲染内容 */
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
/** 当前排序 */
|
|
9
|
+
sortOrder: SortOrder;
|
|
10
|
+
/** 多列排序下,sortIndex 指明了当前排序字段起作用的顺序. 当 sortOrder 为 none 时,sortIndex 固定为 -1 */
|
|
11
|
+
sortIndex: number;
|
|
12
|
+
/** 当前列的配置 */
|
|
13
|
+
column: ArtColumn;
|
|
14
|
+
/** 切换排序的回调 */
|
|
15
|
+
onToggle(e: React.MouseEvent): void;
|
|
16
|
+
}
|
|
17
|
+
export interface SortOptions {
|
|
18
|
+
/** 排序字段列表 */
|
|
19
|
+
sorts: SortItem[];
|
|
20
|
+
/** 更新排序字段列表的回调函数 */
|
|
21
|
+
onChangeSorts(nextSorts: SortItem[]): void;
|
|
22
|
+
/** 排序切换顺序 */
|
|
23
|
+
orders?: SortOrder[];
|
|
24
|
+
/** 排序模式。单选 single,多选 multiple,默认为多选 */
|
|
25
|
+
mode?: 'single' | 'multiple';
|
|
26
|
+
/** 自定义排序表头 */
|
|
27
|
+
SortHeaderCell?: React.ComponentType<SortHeaderCellProps>;
|
|
28
|
+
/** 是否保持 dataSource 不变 */
|
|
29
|
+
keepDataSource?: boolean;
|
|
30
|
+
/** 排序激活时 是否高亮这一列的单元格 */
|
|
31
|
+
highlightColumnWhenActive?: boolean;
|
|
32
|
+
/** 是否对触发 onChangeOpenKeys 的 click 事件调用 event.stopPropagation() */
|
|
33
|
+
stopClickEventPropagation?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
36
|
+
export declare function makeSortTransform({ sorts: inputSorts, onChangeSorts: inputOnChangeSorts, orders, mode, SortHeaderCell, keepDataSource, highlightColumnWhenActive, stopClickEventPropagation, }: SortOptions): TableTransform;
|
|
37
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
38
|
+
export declare function useSortTransform({ defaultSorts, ...others }?: Omit<SortOptions, 'sorts' | 'onChangeSorts'> & {
|
|
39
|
+
defaultSorts?: SortItem[];
|
|
40
|
+
}): TableTransform;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TableTransform } from '../interfaces';
|
|
2
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
3
|
+
export interface TipsOptions {
|
|
4
|
+
Balloon?: any;
|
|
5
|
+
Tooltip?: any;
|
|
6
|
+
}
|
|
7
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
8
|
+
export declare function makeTipsTransform({ Balloon, Tooltip }: TipsOptions): TableTransform;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TableTransform } from '../interfaces';
|
|
2
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
3
|
+
export interface TreeModeOptions {
|
|
4
|
+
primaryKey: string;
|
|
5
|
+
openKeys: string[];
|
|
6
|
+
onChangeOpenKeys(nextKeys: string[], key: string, action: 'expand' | 'collapse'): void;
|
|
7
|
+
isLeafNode?(node: any, nodeMeta: {
|
|
8
|
+
depth: number;
|
|
9
|
+
expanded: boolean;
|
|
10
|
+
rowKey: string;
|
|
11
|
+
}): boolean;
|
|
12
|
+
/** icon 的缩进值,一般为负数,此时 icon 将向左偏移. 默认为 -6 */
|
|
13
|
+
iconIndent?: number;
|
|
14
|
+
/** icon 与右侧文本的距离,默认为 0 */
|
|
15
|
+
iconGap?: number;
|
|
16
|
+
/** 每一级缩进产生的距离,默认为 16 */
|
|
17
|
+
indentSize?: number;
|
|
18
|
+
clickArea?: 'cell' | 'content' | 'icon';
|
|
19
|
+
treeMetaKey?: string | symbol;
|
|
20
|
+
stopClickEventPropagation?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
23
|
+
export declare function makeTreeModeTransform({ onChangeOpenKeys, openKeys, primaryKey, iconIndent, iconGap, indentSize, isLeafNode, clickArea, treeMetaKey, stopClickEventPropagation, }: TreeModeOptions): TableTransform;
|
|
24
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
25
|
+
export declare function useTreeModeTransform({ defaultOpenKeys, ...others }: Omit<TreeModeOptions, 'openKeys' | 'onChangeOpenKeys'> & {
|
|
26
|
+
defaultOpenKeys?: string[];
|
|
27
|
+
}): TableTransform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function warnTransformsDeprecated(apiName: string): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
declare type WithChildren<T> = T & {
|
|
2
|
+
children?: WithChildren<T>[];
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* 根据 idProp 与 parentIdProp 从对象数组中构建对应的树
|
|
6
|
+
* 当 A[parentIdProp] === B[idProp] 时,对象A会被移动到对象B的children。
|
|
7
|
+
* 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点
|
|
8
|
+
* @example
|
|
9
|
+
* const array = [
|
|
10
|
+
* { id: 'node-1', parent: 'root' },
|
|
11
|
+
* { id: 'node-2', parent: 'root' },
|
|
12
|
+
* { id: 'node-3', parent: 'node-2' },
|
|
13
|
+
* { id: 'node-4', parent: 'node-2' },
|
|
14
|
+
* { id: 'node-5', parent: 'node-4' },
|
|
15
|
+
* ]
|
|
16
|
+
* const tree = buildTree('id', 'parent', array)
|
|
17
|
+
* expect(tree).toEqual([
|
|
18
|
+
* { id: 'node-1', parent: 'root' },
|
|
19
|
+
* {
|
|
20
|
+
* id: 'node-2',
|
|
21
|
+
* parent: 'root',
|
|
22
|
+
* children: [
|
|
23
|
+
* { id: 'node-3', parent: 'node-2' },
|
|
24
|
+
* {
|
|
25
|
+
* id: 'node-4',
|
|
26
|
+
* parent: 'node-2',
|
|
27
|
+
* children: [{ id: 'node-5', parent: 'node-4' }],
|
|
28
|
+
* },
|
|
29
|
+
* ],
|
|
30
|
+
* },
|
|
31
|
+
* ])
|
|
32
|
+
*/
|
|
33
|
+
export default function buildTree<ID extends string, PID extends string, T extends {
|
|
34
|
+
[key in ID | PID]: string;
|
|
35
|
+
}>(idProp: ID, parentIdProp: PID, items: T[]): WithChildren<T>[];
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AbstractTreeNode } from '../interfaces';
|
|
2
|
+
/** 遍历所有节点,并将节点收集到一个数组中.
|
|
3
|
+
* order 参数可用于指定遍历规则:
|
|
4
|
+
* * `pre` 前序遍历 (默认)
|
|
5
|
+
* * `post` 后续遍历
|
|
6
|
+
* * `leaf-only` 忽略内部节点,只收集叶子节点
|
|
7
|
+
* */
|
|
8
|
+
export default function collectNodes<T extends AbstractTreeNode>(nodes: T[], order?: 'pre' | 'post' | 'leaf-only'): T[];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type XLSX_NS from 'xlsx';
|
|
2
|
+
import { ArtColumn } from '../interfaces';
|
|
3
|
+
/** 根据 BaseTable 的 dataSource 和 column,将表格数据导出为 Excel 文件 */
|
|
4
|
+
export default function exportTableAsExcel(xlsxPackage: typeof XLSX_NS, dataSource: any[], columns: ArtColumn[], filename: string): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function groupBy<T, K extends string>(list: T[], iteratee: (t: T) => K): { [key in K]: T[]; };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function groupBy2<T, K extends string | number>(list: T[], iteratee: (t: T) => K): Map<K, T[]>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { default as collectNodes } from './collectNodes';
|
|
2
|
+
export { default as getTreeDepth } from './getTreeDepth';
|
|
3
|
+
export { default as groupBy } from './groupBy';
|
|
4
|
+
export { default as groupBy2 } from './groupBy2';
|
|
5
|
+
export { default as isLeafNode } from './isLeafNode';
|
|
6
|
+
export { default as applyTransforms } from './applyTransforms';
|
|
7
|
+
export { default as buildTree } from './buildTree';
|
|
8
|
+
export { default as exportTableAsExcel } from './exportTableAsExcel';
|
|
9
|
+
export { default as layeredSort } from './layeredSort';
|
|
10
|
+
export { default as mergeCellProps } from './mergeCellProps';
|
|
11
|
+
export { default as proto } from './proto';
|
|
12
|
+
export { default as makeRecursiveMapper } from './makeRecursiveMapper';
|
|
13
|
+
export { default as smartCompare } from './smartCompare';
|
|
14
|
+
export { default as traverseColumn } from './traverseColumn';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbstractTreeNode } from '../interfaces';
|
|
2
|
+
declare type RecursiveFlatMapInfo<T> = {
|
|
3
|
+
startIndex: number;
|
|
4
|
+
endIndex: number;
|
|
5
|
+
path: T[];
|
|
6
|
+
isLeaf: boolean;
|
|
7
|
+
};
|
|
8
|
+
export default function makeRecursiveMapper<T extends AbstractTreeNode>(fn: (node: T, info: RecursiveFlatMapInfo<T>) => null | T | T[]): (tree: T[]) => T[];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CellProps } from '../interfaces';
|
|
2
|
+
/** 合并两个 cellProps(单元格属性)对象,返回一个合并后的全新对象。
|
|
3
|
+
*
|
|
4
|
+
* mergeCellProps 会按照以下规则来合并两个对象:
|
|
5
|
+
* * 对于 数字、字符串、布尔值类型的字段,extra 中的字段值将直接覆盖 base 中的字段值(className 是个特例,会进行字符串拼接)
|
|
6
|
+
* * 对于函数/方法类型的字段(对应单元格的事件回调函数),mergeCellProps 将生成一个新的函数,新函数将按序调用 base 和 extra 中的方法
|
|
7
|
+
* * 对于普通对象类型的字段(对应单元格的样式),mergeCellProps 将合并两个对象
|
|
8
|
+
* */
|
|
9
|
+
export default function mergeCellProps(base: CellProps, extra: CellProps): CellProps;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function flatMap<T, U>(array: T[], callback: (value: T, index: number, array: T[]) => U[]): U[];
|
|
2
|
+
export declare function fromEntries<T = any>(entries: Iterable<readonly [PropertyKey, T]>): {
|
|
3
|
+
[x: string]: T;
|
|
4
|
+
[x: number]: T;
|
|
5
|
+
};
|
|
6
|
+
export declare const arrayUtils: {
|
|
7
|
+
readonly diff: (arr1: string[], arr2: Iterable<string>) => string[];
|
|
8
|
+
readonly merge: (arr1: string[], arr2: string[]) => string[];
|
|
9
|
+
};
|
|
10
|
+
export declare function always<T>(value: T): (...args: any[]) => T;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare type SameKeysWith<T> = T extends object ? {
|
|
2
|
+
[key in keyof T]?: any;
|
|
3
|
+
} : T;
|
|
4
|
+
interface ObjectProto<T> {
|
|
5
|
+
(v: SameKeysWith<T>): T;
|
|
6
|
+
extends(ext: SameKeysWith<T>): ObjectProto<T>;
|
|
7
|
+
}
|
|
8
|
+
interface ArrayProto<T> {
|
|
9
|
+
(items: SameKeysWith<T>[]): T[];
|
|
10
|
+
extends(extRecord: SameKeysWith<T>): ArrayProto<T>;
|
|
11
|
+
}
|
|
12
|
+
export interface ProtoStatic {
|
|
13
|
+
string(v: string): string;
|
|
14
|
+
number(v: number): number;
|
|
15
|
+
notNull<T = any>(v: any): T;
|
|
16
|
+
object<O extends object = any>(base: SameKeysWith<O>): ObjectProto<O>;
|
|
17
|
+
array<T extends object = any>(base: SameKeysWith<T>): ArrayProto<T>;
|
|
18
|
+
readonly empty: unique symbol;
|
|
19
|
+
}
|
|
20
|
+
declare const _default: ProtoStatic;
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** 比较函数,支持字符串、数字、数组和 null。
|
|
2
|
+
* * 对于字符串将比较两者的字典序;
|
|
3
|
+
* * 对数字将比较两者大小;
|
|
4
|
+
* * null 值在比较时总是小于另一个值;
|
|
5
|
+
* * 对于数组来说,将逐个比较数组中的元素,第一个不相等的比较结果将作为整个数组的比较结果
|
|
6
|
+
*
|
|
7
|
+
* 数组的比较可参考 python 中的元祖比较:
|
|
8
|
+
* https://stackoverflow.com/questions/5292303/how-does-tuple-comparison-work-in-python */
|
|
9
|
+
export default function smartCompare(x: any, y: any): number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ArtColumn, TableTransform } from '../interfaces';
|
|
2
|
+
declare type NormalizeAsArrayInput<T> = null | T | T[];
|
|
3
|
+
/** @deprecated 该 API 已经过时,请使用 makeRecursiveMapper */
|
|
4
|
+
export default function traverseColumn(fn: (column: ArtColumn, ctx: {
|
|
5
|
+
range: {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
};
|
|
9
|
+
dataSource: any[];
|
|
10
|
+
}) => NormalizeAsArrayInput<ArtColumn>): TableTransform;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AbstractTreeNode } from '../../interfaces';
|
|
2
|
+
export interface StrictTreeDataHelperOptions<N extends AbstractTreeNode> {
|
|
3
|
+
tree: N[];
|
|
4
|
+
getNodeValue(node: N): string;
|
|
5
|
+
value: string[];
|
|
6
|
+
}
|
|
7
|
+
export default class StrictTreeDataHelper<N extends AbstractTreeNode> {
|
|
8
|
+
private readonly opts;
|
|
9
|
+
private readonly valueSet;
|
|
10
|
+
private wrapperMap;
|
|
11
|
+
private rootWrapper;
|
|
12
|
+
constructor(opts: StrictTreeDataHelperOptions<N>);
|
|
13
|
+
private initWrapperTree;
|
|
14
|
+
private get value();
|
|
15
|
+
isIndeterminate(nodeValue: string): boolean;
|
|
16
|
+
isChecked(nodeValue: string): boolean;
|
|
17
|
+
getValueAfterCheck(nodeValue: string): string[];
|
|
18
|
+
getValueAfterUncheck(nodeValue: string): string[];
|
|
19
|
+
getValueAfterToggle(nodeValue: string): string[];
|
|
20
|
+
getNode(nodeValue: string): N;
|
|
21
|
+
getCleanValue(): string[];
|
|
22
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AbstractTreeNode } from '../../interfaces';
|
|
2
|
+
export declare type CheckedStrategy = 'all' | 'parent' | 'child';
|
|
3
|
+
export interface TreeDataHelperOptions<N extends AbstractTreeNode> {
|
|
4
|
+
tree: N[];
|
|
5
|
+
getNodeValue(node: N): string;
|
|
6
|
+
value: string[];
|
|
7
|
+
checkedStrategy: CheckedStrategy;
|
|
8
|
+
isDetached?(node: N): boolean;
|
|
9
|
+
}
|
|
10
|
+
export default class TreeDataHelper<N extends AbstractTreeNode> {
|
|
11
|
+
private readonly opts;
|
|
12
|
+
private readonly valueSet;
|
|
13
|
+
private wrapperMap;
|
|
14
|
+
private rootWrapper;
|
|
15
|
+
constructor(opts: TreeDataHelperOptions<N>);
|
|
16
|
+
private get value();
|
|
17
|
+
private isDetached;
|
|
18
|
+
private initWrapperTree;
|
|
19
|
+
isIndeterminate(nodeValue: string): boolean;
|
|
20
|
+
isChecked(nodeValue: string): boolean;
|
|
21
|
+
getValueAfterCheck(nodeValue: string): string[];
|
|
22
|
+
getValueAfterUncheck(nodeValue: string): string[];
|
|
23
|
+
getValueAfterToggle(nodeValue: string): string[];
|
|
24
|
+
getNode(nodeValue: string): N;
|
|
25
|
+
getCleanValue(): string[];
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@guozhi5658/srp-table",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "High-performance React table component library",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"module": "dist/srp-table.esm.js",
|
|
7
|
+
"main": "dist/srp-table.js",
|
|
8
|
+
"types": "dist/srp-table.d.ts",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/scofield5658/ali-react-table.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/scofield5658/ali-react-table",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Scofield Guo",
|
|
20
|
+
"email": "guoz5658@outlook.com"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"watch": "rollup --config rollup.config.js --watch",
|
|
24
|
+
"build": "rimraf dist/ && rollup --config rollup.config.js",
|
|
25
|
+
"playground": "vite --config vite.playground.config.ts",
|
|
26
|
+
"playground:build": "vite build --config vite.playground.config.ts",
|
|
27
|
+
"verify:react-compat": "node scripts/verify-react-compat.js",
|
|
28
|
+
"preversion": "npm run build",
|
|
29
|
+
"prepublishOnly": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"pivot"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@popperjs/core": "^2.9.1",
|
|
37
|
+
"@types/classnames": "^2.2.9",
|
|
38
|
+
"classnames": "^2.2.6",
|
|
39
|
+
"resize-observer-polyfill": "^1.5.1",
|
|
40
|
+
"rxjs": "^6.5.4",
|
|
41
|
+
"styled-components": "^3.4.10 || ^5.0.1"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": "^16.8.0 || ^17.0.1 || ^18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@babel/core": "^7.12.3",
|
|
48
|
+
"@babel/preset-env": "^7.12.1",
|
|
49
|
+
"@babel/preset-typescript": "^7.12.1",
|
|
50
|
+
"@rollup/plugin-node-resolve": "^11.2.0",
|
|
51
|
+
"@types/jest": "^26.0.15",
|
|
52
|
+
"@types/react": "18.0.17",
|
|
53
|
+
"@types/react-dom": "18.0.11",
|
|
54
|
+
"@types/styled-components": "^5.1.9",
|
|
55
|
+
"@vitejs/plugin-react": "^4.7.0",
|
|
56
|
+
"jest": "^26.6.0",
|
|
57
|
+
"react": "^16.14.0",
|
|
58
|
+
"react-dom": "^16.13.1",
|
|
59
|
+
"react-is": "^16.13.0",
|
|
60
|
+
"rimraf": "^3.0.2",
|
|
61
|
+
"rollup": "^2.3.1",
|
|
62
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
63
|
+
"tslib": "^2.8.1",
|
|
64
|
+
"typescript": "~4.2",
|
|
65
|
+
"vite": "^4.5.14",
|
|
66
|
+
"xlsx": "^0.16.0"
|
|
67
|
+
},
|
|
68
|
+
"volta": {
|
|
69
|
+
"node": "22.22.0",
|
|
70
|
+
"npm": "10.9.4"
|
|
71
|
+
}
|
|
72
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# srp-table
|
|
2
|
+
|
|
3
|
+
[![NPM version][npm-image]][npm-url]
|
|
4
|
+
[![node version][node-image]][node-url]
|
|
5
|
+
[![npm download][download-image]][download-url]
|
|
6
|
+
[![npm license][license-image]][download-url]
|
|
7
|
+
|
|
8
|
+
[npm-image]: https://img.shields.io/npm/v/%40guozhi5658%2Fsrp-table.svg?style=flat-square
|
|
9
|
+
[npm-url]: https://www.npmjs.com/package/@guozhi5658/srp-table
|
|
10
|
+
[node-image]: https://img.shields.io/badge/node.js-%3E=_18-green.svg?style=flat-square
|
|
11
|
+
[node-url]: http://nodejs.org/download/
|
|
12
|
+
[download-image]: https://img.shields.io/npm/dm/%40guozhi5658%2Fsrp-table.svg?style=flat-square
|
|
13
|
+
[download-url]: https://www.npmjs.com/package/@guozhi5658/srp-table
|
|
14
|
+
[license-image]: https://img.shields.io/npm/l/%40guozhi5658%2Fsrp-table.svg
|
|
15
|
+
|
|
16
|
+
`srp-table` is a high-performance table component library for React applications. It is designed for data-intensive UIs and supports two integration styles:
|
|
17
|
+
|
|
18
|
+
- direct prop-based usage with `BaseTable`
|
|
19
|
+
- composable enhancement through `pipeline` and feature plugins
|
|
20
|
+
|
|
21
|
+
The library also exposes customizable component injection points and feature slots so teams can adapt rendering, interaction, and business behaviors without rewriting the rendering core.
|
|
22
|
+
|
|
23
|
+
## Project Status
|
|
24
|
+
|
|
25
|
+
This project is forked from [alibaba/ali-react-table](https://github.com/alibaba/ali-react-table).
|
|
26
|
+
|
|
27
|
+
The fork keeps the original MIT licensing model. Please retain the upstream attribution and license terms when redistributing or modifying the codebase.
|
|
28
|
+
|
|
29
|
+
## Highlights
|
|
30
|
+
|
|
31
|
+
- high-performance rendering for large datasets
|
|
32
|
+
- sticky header and sticky footer support
|
|
33
|
+
- left and right locked columns
|
|
34
|
+
- horizontal and vertical virtualization
|
|
35
|
+
- tree data, row detail, sorting, and other pipeline-driven features
|
|
36
|
+
- pluggable renderers and component slots for customization
|
|
37
|
+
- pivot table entry for cross-table and cross-tree-table scenarios
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install @guozhi5658/srp-table
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
### BaseTable
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { BaseTable } from '@guozhi5658/srp-table'
|
|
51
|
+
|
|
52
|
+
const columns = [
|
|
53
|
+
{ code: 'name', name: 'Name', width: 180 },
|
|
54
|
+
{ code: 'status', name: 'Status', width: 120 },
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
const dataSource = [
|
|
58
|
+
{ id: '1', name: 'Alpha', status: 'Ready' },
|
|
59
|
+
{ id: '2', name: 'Beta', status: 'Running' },
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
export function DemoTable() {
|
|
63
|
+
return (
|
|
64
|
+
<BaseTable
|
|
65
|
+
primaryKey="id"
|
|
66
|
+
columns={columns}
|
|
67
|
+
dataSource={dataSource}
|
|
68
|
+
isStickyHeader
|
|
69
|
+
/>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Pipeline
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { BaseTable, features, useTablePipeline } from '@guozhi5658/srp-table'
|
|
78
|
+
|
|
79
|
+
export function PipelineDemo({ columns, dataSource }) {
|
|
80
|
+
const pipeline = useTablePipeline()
|
|
81
|
+
|
|
82
|
+
const tableProps = pipeline
|
|
83
|
+
.input({ columns, dataSource })
|
|
84
|
+
.primaryKey('id')
|
|
85
|
+
.use(
|
|
86
|
+
features.sort({
|
|
87
|
+
mode: 'multiple',
|
|
88
|
+
}),
|
|
89
|
+
)
|
|
90
|
+
.getProps()
|
|
91
|
+
|
|
92
|
+
return <BaseTable {...tableProps} />
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Playground
|
|
97
|
+
|
|
98
|
+
Run the local playground to develop and validate new features against the built-in flat, tree, and row-detail mock datasets:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npm install
|
|
102
|
+
npm run playground
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The playground is intended for iterative feature work in a real React runtime and is the fastest way to verify layout, interaction, sticky behavior, and virtualization changes.
|
|
106
|
+
|
|
107
|
+
## Build
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npm run build
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Build artifacts are emitted to `dist/`, including:
|
|
114
|
+
|
|
115
|
+
- `dist/srp-table.js`
|
|
116
|
+
- `dist/srp-table.esm.js`
|
|
117
|
+
- `dist/srp-table.d.ts`
|
|
118
|
+
- `dist/srp-table-pivot.js`
|
|
119
|
+
- `dist/srp-table-pivot.esm.js`
|
|
120
|
+
- `dist/srp-table-pivot.d.ts`
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
MIT. This fork is based on [alibaba/ali-react-table](https://github.com/alibaba/ali-react-table), and the upstream attribution should be preserved.
|