@guozhi5658/srp-table 1.1.0 → 1.1.1
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/__tests__/fillRemainingWidth.test.d.ts +1 -1
- package/dist/base-table/calculations.d.ts +3 -3
- package/dist/base-table/colgroup.d.ts +4 -5
- package/dist/base-table/empty.d.ts +9 -9
- package/dist/base-table/header.d.ts +4 -5
- package/dist/base-table/helpers/SpanManager.d.ts +9 -9
- package/dist/base-table/helpers/TableDOMUtils.d.ts +16 -16
- package/dist/base-table/helpers/getMaximumColSpan.d.ts +9 -9
- package/dist/base-table/helpers/getRichVisibleRectsStream.d.ts +23 -23
- package/dist/base-table/helpers/rowHeightManager.d.ts +7 -7
- package/dist/base-table/html-table.d.ts +14 -15
- package/dist/base-table/index.d.ts +3 -3
- package/dist/base-table/interfaces.d.ts +54 -54
- package/dist/base-table/loading.d.ts +13 -13
- package/dist/base-table/styles.d.ts +86 -83
- package/dist/base-table/table.d.ts +185 -185
- package/dist/base-table/utils.d.ts +22 -22
- package/dist/chunks/{srp-table-pipeline-0b26f8d2.esm.js → srp-table-pipeline-414f4fea.esm.js} +2061 -2061
- package/dist/chunks/{srp-table-pipeline-8dff19ec.js → srp-table-pipeline-7f69aca0.js} +2075 -2075
- package/dist/common-views.d.ts +26 -23
- package/dist/fillRemainingWidth.d.ts +9 -9
- package/dist/interfaces.d.ts +65 -65
- package/dist/internals.d.ts +14 -15
- package/dist/pipeline/features/autoRowSpan.d.ts +2 -2
- package/dist/pipeline/features/buildTree.d.ts +2 -2
- package/dist/pipeline/features/columnHover.d.ts +12 -12
- package/dist/pipeline/features/columnRangeHover.d.ts +15 -15
- package/dist/pipeline/features/columnResize.d.ts +24 -24
- package/dist/pipeline/features/fillRemainingWidth.d.ts +2 -2
- package/dist/pipeline/features/index.d.ts +15 -15
- package/dist/pipeline/features/multiSelect.d.ts +27 -27
- package/dist/pipeline/features/rowDetail.d.ts +29 -29
- package/dist/pipeline/features/rowGrouping.d.ts +14 -14
- package/dist/pipeline/features/rowPopover.d.ts +13 -13
- package/dist/pipeline/features/singleSelect.d.ts +23 -23
- package/dist/pipeline/features/sort.d.ts +42 -42
- package/dist/pipeline/features/tips.d.ts +2 -2
- package/dist/pipeline/features/treeMode.d.ts +29 -29
- package/dist/pipeline/features/treeSelect.d.ts +38 -38
- package/dist/pipeline/index.d.ts +3 -3
- package/dist/pipeline/pipeline.d.ts +79 -79
- package/dist/pivot/cross-table/buildCrossTable.d.ts +17 -17
- package/dist/pivot/cross-table/constants.d.ts +1 -1
- package/dist/pivot/cross-table/cross-table.d.ts +18 -18
- package/dist/pivot/cross-table/index.d.ts +4 -4
- package/dist/pivot/cross-table/interfaces.d.ts +29 -29
- package/dist/pivot/cross-table/internals.d.ts +13 -13
- package/dist/pivot/cross-tree-table/buildCrossTreeTable.d.ts +14 -14
- package/dist/pivot/cross-tree-table/cross-tree-table.d.ts +38 -38
- package/dist/pivot/cross-tree-table/index.d.ts +2 -2
- package/dist/pivot/pivot-utils/buildDrillTree.d.ts +16 -16
- package/dist/pivot/pivot-utils/builders.d.ts +26 -26
- package/dist/pivot/pivot-utils/convert-utils.d.ts +31 -31
- package/dist/pivot/pivot-utils/index.d.ts +5 -5
- package/dist/pivot/pivot-utils/interfaces.d.ts +12 -12
- package/dist/pivot/pivot-utils/simpleEncode.d.ts +1 -1
- package/dist/srp-table-pivot.d.ts +3 -3
- package/dist/srp-table-pivot.esm.js +647 -646
- package/dist/srp-table-pivot.js +647 -646
- package/dist/srp-table.d.ts +6 -6
- package/dist/srp-table.esm.js +2334 -2331
- package/dist/srp-table.js +2347 -2344
- package/dist/transforms/autoRowSpan.d.ts +3 -3
- package/dist/transforms/autoWidth.d.ts +25 -25
- package/dist/transforms/buildTree.d.ts +3 -3
- package/dist/transforms/columnHover.d.ts +14 -14
- package/dist/transforms/columnRangeHover.d.ts +14 -14
- package/dist/transforms/columnResize.d.ts +24 -24
- package/dist/transforms/flatten.d.ts +3 -3
- package/dist/transforms/index.d.ts +12 -12
- package/dist/transforms/orderField.d.ts +3 -3
- package/dist/transforms/sort.d.ts +40 -40
- package/dist/transforms/tips.d.ts +8 -8
- package/dist/transforms/treeMode.d.ts +27 -27
- package/dist/transforms/visible.d.ts +2 -2
- package/dist/transforms/warnTransformsDeprecated.d.ts +1 -1
- package/dist/utils/applyTransforms.d.ts +6 -6
- package/dist/utils/buildTree.d.ts +36 -36
- package/dist/utils/collectNodes.d.ts +8 -8
- package/dist/utils/exportTableAsExcel.d.ts +4 -4
- package/dist/utils/getTreeDepth.d.ts +3 -3
- package/dist/utils/groupBy.d.ts +1 -1
- package/dist/utils/groupBy2.d.ts +1 -1
- package/dist/utils/index.d.ts +14 -14
- package/dist/utils/isLeafNode.d.ts +2 -2
- package/dist/utils/layeredSort.d.ts +5 -5
- package/dist/utils/makeRecursiveMapper.d.ts +9 -9
- package/dist/utils/mergeCellProps.d.ts +9 -9
- package/dist/utils/others.d.ts +11 -10
- package/dist/utils/proto.d.ts +21 -21
- package/dist/utils/smartCompare.d.ts +9 -9
- package/dist/utils/traverseColumn.d.ts +11 -11
- package/dist/utils/tree-data-helpers/StrictTreeDataHelper.d.ts +22 -22
- package/dist/utils/tree-data-helpers/TreeDataHelper.d.ts +26 -26
- package/dist/utils/tree-data-helpers/__tests__/helpers.test.d.ts +1 -1
- package/package.json +4 -3
package/dist/srp-table.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as flatMap, g as getTreeDepth, i as isLeafNode, c as collectNodes, a as internals, S as SpanManager, C as Classes, b as appendFillRemainingWidthColumn, m as mergeCellProps, _ as __rest, d as icons, t as takeFillRemainingWidthColumn, e as always, h as arrayUtils, I as InlineFlexCell, E as ExpansionCell, j as treeMode, k as treeMetaSymbol } from './chunks/srp-table-pipeline-
|
|
2
|
-
export { B as BaseTable, C as Classes, T as TablePipeline, c as collectNodes, g as getTreeDepth, l as groupBy2, a as internals, i as isLeafNode, m as mergeCellProps, u as useTablePipeline } from './chunks/srp-table-pipeline-
|
|
1
|
+
import { f as flatMap, g as getTreeDepth, i as isLeafNode, c as collectNodes, a as internals, S as SpanManager, C as Classes, b as appendFillRemainingWidthColumn, m as mergeCellProps, _ as __rest, d as icons, t as takeFillRemainingWidthColumn, e as always, h as arrayUtils, I as InlineFlexCell, E as ExpansionCell, j as treeMode, k as treeMetaSymbol } from './chunks/srp-table-pipeline-414f4fea.esm.js';
|
|
2
|
+
export { B as BaseTable, C as Classes, T as TablePipeline, c as collectNodes, g as getTreeDepth, l as groupBy2, a as internals, i as isLeafNode, m as mergeCellProps, u as useTablePipeline } from './chunks/srp-table-pipeline-414f4fea.esm.js';
|
|
3
3
|
import React, { useState, useEffect } from 'react';
|
|
4
4
|
import styled__default from 'styled-components';
|
|
5
5
|
import { fromEvent } from 'rxjs';
|
|
@@ -7,667 +7,668 @@ import * as op from 'rxjs/operators';
|
|
|
7
7
|
import cx from 'classnames';
|
|
8
8
|
import 'resize-observer-polyfill';
|
|
9
9
|
|
|
10
|
-
function groupBy(list, iteratee) {
|
|
11
|
-
const groups = {};
|
|
12
|
-
for (const item of list) {
|
|
13
|
-
const key = iteratee(item);
|
|
14
|
-
if (groups[key] == null) {
|
|
15
|
-
groups[key] = [];
|
|
16
|
-
}
|
|
17
|
-
groups[key].push(item);
|
|
18
|
-
}
|
|
19
|
-
return groups;
|
|
10
|
+
function groupBy(list, iteratee) {
|
|
11
|
+
const groups = {};
|
|
12
|
+
for (const item of list) {
|
|
13
|
+
const key = iteratee(item);
|
|
14
|
+
if (groups[key] == null) {
|
|
15
|
+
groups[key] = [];
|
|
16
|
+
}
|
|
17
|
+
groups[key].push(item);
|
|
18
|
+
}
|
|
19
|
+
return groups;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* 以 input 作为输入,按序使用 transform.
|
|
24
|
-
*
|
|
25
|
-
* `applyTransforms(input, f1, f2, f3)` 等价于 `f3(f2(f1(input)))` */
|
|
26
|
-
function applyTransforms(input, ...transforms) {
|
|
27
|
-
return transforms.reduce((v, fn) => fn(v), input);
|
|
22
|
+
/**
|
|
23
|
+
* 以 input 作为输入,按序使用 transform.
|
|
24
|
+
*
|
|
25
|
+
* `applyTransforms(input, f1, f2, f3)` 等价于 `f3(f2(f1(input)))` */
|
|
26
|
+
function applyTransforms(input, ...transforms) {
|
|
27
|
+
return transforms.reduce((v, fn) => fn(v), input);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
* 根据 idProp 与 parentIdProp 从对象数组中构建对应的树
|
|
32
|
-
* 当 A[parentIdProp] === B[idProp] 时,对象A会被移动到对象B的children。
|
|
33
|
-
* 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点
|
|
34
|
-
* @example
|
|
35
|
-
* const array = [
|
|
36
|
-
* { id: 'node-1', parent: 'root' },
|
|
37
|
-
* { id: 'node-2', parent: 'root' },
|
|
38
|
-
* { id: 'node-3', parent: 'node-2' },
|
|
39
|
-
* { id: 'node-4', parent: 'node-2' },
|
|
40
|
-
* { id: 'node-5', parent: 'node-4' },
|
|
41
|
-
* ]
|
|
42
|
-
* const tree = buildTree('id', 'parent', array)
|
|
43
|
-
* expect(tree).toEqual([
|
|
44
|
-
* { id: 'node-1', parent: 'root' },
|
|
45
|
-
* {
|
|
46
|
-
* id: 'node-2',
|
|
47
|
-
* parent: 'root',
|
|
48
|
-
* children: [
|
|
49
|
-
* { id: 'node-3', parent: 'node-2' },
|
|
50
|
-
* {
|
|
51
|
-
* id: 'node-4',
|
|
52
|
-
* parent: 'node-2',
|
|
53
|
-
* children: [{ id: 'node-5', parent: 'node-4' }],
|
|
54
|
-
* },
|
|
55
|
-
* ],
|
|
56
|
-
* },
|
|
57
|
-
* ])
|
|
58
|
-
*/
|
|
59
|
-
function buildTree$1(idProp, parentIdProp, items) {
|
|
60
|
-
const wrapperMap = new Map();
|
|
61
|
-
const ensure = (id) => {
|
|
62
|
-
if (wrapperMap.has(id)) {
|
|
63
|
-
return wrapperMap.get(id);
|
|
64
|
-
}
|
|
65
|
-
const wrapper = { id, parent: null, item: null, children: [] };
|
|
66
|
-
wrapperMap.set(id, wrapper);
|
|
67
|
-
return wrapper;
|
|
68
|
-
};
|
|
69
|
-
for (const item of items) {
|
|
70
|
-
const parentWrapper = ensure(item[parentIdProp]);
|
|
71
|
-
const itemWrapper = ensure(item[idProp]);
|
|
72
|
-
itemWrapper.parent = parentWrapper;
|
|
73
|
-
parentWrapper.children.push(itemWrapper);
|
|
74
|
-
itemWrapper.item = item;
|
|
75
|
-
}
|
|
76
|
-
const topLevelWrappers = flatMap(Array.from(wrapperMap.values()).filter((wrapper) => wrapper.parent == null), (wrapper) => wrapper.children);
|
|
77
|
-
return unwrapRecursively(topLevelWrappers);
|
|
78
|
-
function unwrapRecursively(wrapperArray) {
|
|
79
|
-
const result = [];
|
|
80
|
-
for (const wrapper of wrapperArray) {
|
|
81
|
-
if (wrapper.children.length === 0) {
|
|
82
|
-
result.push(wrapper.item);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
result.push(Object.assign(Object.assign({}, wrapper.item), { children: unwrapRecursively(wrapper.children) }));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
30
|
+
/**
|
|
31
|
+
* 根据 idProp 与 parentIdProp 从对象数组中构建对应的树
|
|
32
|
+
* 当 A[parentIdProp] === B[idProp] 时,对象A会被移动到对象B的children。
|
|
33
|
+
* 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点
|
|
34
|
+
* @example
|
|
35
|
+
* const array = [
|
|
36
|
+
* { id: 'node-1', parent: 'root' },
|
|
37
|
+
* { id: 'node-2', parent: 'root' },
|
|
38
|
+
* { id: 'node-3', parent: 'node-2' },
|
|
39
|
+
* { id: 'node-4', parent: 'node-2' },
|
|
40
|
+
* { id: 'node-5', parent: 'node-4' },
|
|
41
|
+
* ]
|
|
42
|
+
* const tree = buildTree('id', 'parent', array)
|
|
43
|
+
* expect(tree).toEqual([
|
|
44
|
+
* { id: 'node-1', parent: 'root' },
|
|
45
|
+
* {
|
|
46
|
+
* id: 'node-2',
|
|
47
|
+
* parent: 'root',
|
|
48
|
+
* children: [
|
|
49
|
+
* { id: 'node-3', parent: 'node-2' },
|
|
50
|
+
* {
|
|
51
|
+
* id: 'node-4',
|
|
52
|
+
* parent: 'node-2',
|
|
53
|
+
* children: [{ id: 'node-5', parent: 'node-4' }],
|
|
54
|
+
* },
|
|
55
|
+
* ],
|
|
56
|
+
* },
|
|
57
|
+
* ])
|
|
58
|
+
*/
|
|
59
|
+
function buildTree$1(idProp, parentIdProp, items) {
|
|
60
|
+
const wrapperMap = new Map();
|
|
61
|
+
const ensure = (id) => {
|
|
62
|
+
if (wrapperMap.has(id)) {
|
|
63
|
+
return wrapperMap.get(id);
|
|
64
|
+
}
|
|
65
|
+
const wrapper = { id, parent: null, item: null, children: [] };
|
|
66
|
+
wrapperMap.set(id, wrapper);
|
|
67
|
+
return wrapper;
|
|
68
|
+
};
|
|
69
|
+
for (const item of items) {
|
|
70
|
+
const parentWrapper = ensure(item[parentIdProp]);
|
|
71
|
+
const itemWrapper = ensure(item[idProp]);
|
|
72
|
+
itemWrapper.parent = parentWrapper;
|
|
73
|
+
parentWrapper.children.push(itemWrapper);
|
|
74
|
+
itemWrapper.item = item;
|
|
75
|
+
}
|
|
76
|
+
const topLevelWrappers = flatMap(Array.from(wrapperMap.values()).filter((wrapper) => wrapper.parent == null), (wrapper) => wrapper.children);
|
|
77
|
+
return unwrapRecursively(topLevelWrappers);
|
|
78
|
+
function unwrapRecursively(wrapperArray) {
|
|
79
|
+
const result = [];
|
|
80
|
+
for (const wrapper of wrapperArray) {
|
|
81
|
+
if (wrapper.children.length === 0) {
|
|
82
|
+
result.push(wrapper.item);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
result.push(Object.assign(Object.assign({}, wrapper.item), { children: unwrapRecursively(wrapper.children) }));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
function safeGetSpanRect(column, record, rowIndex, colIndex) {
|
|
93
|
-
let colSpan = 1;
|
|
94
|
-
let rowSpan = 1;
|
|
95
|
-
if (column.getSpanRect) {
|
|
96
|
-
const value = internals.safeGetValue(column, record, rowIndex);
|
|
97
|
-
const spanRect = column.getSpanRect(value, record, rowIndex);
|
|
98
|
-
colSpan = spanRect == null ? 1 : spanRect.right - colIndex;
|
|
99
|
-
rowSpan = spanRect == null ? 1 : spanRect.bottom - rowIndex;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
const cellProps = internals.safeGetCellProps(column, record, rowIndex);
|
|
103
|
-
if (cellProps.colSpan != null) {
|
|
104
|
-
colSpan = cellProps.colSpan;
|
|
105
|
-
}
|
|
106
|
-
if (cellProps.rowSpan != null) {
|
|
107
|
-
rowSpan = cellProps.rowSpan;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// 注意这里没有考虑「rowSpan/colSpan 不能过大,避免 rowSpan/colSpan 影响因虚拟滚动而未渲染的单元格」
|
|
111
|
-
return {
|
|
112
|
-
top: rowIndex,
|
|
113
|
-
bottom: rowIndex + rowSpan,
|
|
114
|
-
left: colIndex,
|
|
115
|
-
right: colIndex + colSpan,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function move({ c, r }, dx, dy) {
|
|
119
|
-
return { c: c + dx, r: r + dy };
|
|
120
|
-
}
|
|
121
|
-
function sanitizeCellDatum(value) {
|
|
122
|
-
if (value === Infinity || value === -Infinity || (typeof value === 'number' && isNaN(value))) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
return value;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/** 根据 BaseTable 的 dataSource 和 column,将表格数据导出为 Excel 文件 */
|
|
130
|
-
function exportTableAsExcel(xlsxPackage, dataSource, columns, filename) {
|
|
131
|
-
const sheet = xlsxPackage.utils.aoa_to_sheet([]);
|
|
132
|
-
const topHeaderHeight = getTreeDepth(columns) + 1;
|
|
133
|
-
const origin = { c: 0, r: 0 };
|
|
134
|
-
addTopHeaders(origin);
|
|
135
|
-
addDataPart(move(origin, 0, topHeaderHeight));
|
|
136
|
-
xlsxPackage.writeFile({
|
|
137
|
-
SheetNames: ['Sheet1'],
|
|
138
|
-
Sheets: { Sheet1: sheet },
|
|
139
|
-
}, filename);
|
|
140
|
-
function addTopHeaders(origin) {
|
|
141
|
-
dfs(columns, 0, 0);
|
|
142
|
-
function dfs(cols, startDx, startDy) {
|
|
143
|
-
var _a;
|
|
144
|
-
const start = move(origin, startDx, startDy);
|
|
145
|
-
let offsetX = 0;
|
|
146
|
-
for (const col of cols) {
|
|
147
|
-
if ((_a = col.features) === null || _a === void 0 ? void 0 : _a.noExport) {
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
const current = move(start, offsetX, 0);
|
|
151
|
-
addOne(col.name, current);
|
|
152
|
-
if (isLeafNode(col)) {
|
|
153
|
-
offsetX += 1;
|
|
154
|
-
mergeCells(current, 1, topHeaderHeight - startDy);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
const childrenWidth = dfs(col.children, startDx + offsetX, startDy + 1);
|
|
158
|
-
mergeCells(current, childrenWidth, 1);
|
|
159
|
-
offsetX += childrenWidth;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return offsetX;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function addDataPart(origin) {
|
|
166
|
-
const leafColumns = collectNodes(columns, 'leaf-only').filter((col) => { var _a; return !((_a = col.features) === null || _a === void 0 ? void 0 : _a.noExport); });
|
|
167
|
-
const spanManager = new SpanManager();
|
|
168
|
-
const dataPart = dataSource.map((record, rowIndex) => {
|
|
169
|
-
spanManager.stripUpwards(rowIndex);
|
|
170
|
-
return leafColumns.map((col, colIndex) => {
|
|
171
|
-
if (spanManager.testSkip(rowIndex, colIndex)) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
const spanRect = safeGetSpanRect(col, record, rowIndex, colIndex);
|
|
175
|
-
const rowSpan = spanRect.bottom - spanRect.top;
|
|
176
|
-
const colSpan = spanRect.right - spanRect.left;
|
|
177
|
-
if (rowSpan > 1 || colSpan > 1) {
|
|
178
|
-
spanManager.add(spanRect.top, spanRect.left, colSpan, rowSpan);
|
|
179
|
-
mergeCells(move(origin, spanRect.left, spanRect.top), colSpan, rowSpan);
|
|
180
|
-
}
|
|
181
|
-
return sanitizeCellDatum(internals.safeGetValue(col, record, rowIndex));
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
add(dataPart, origin);
|
|
185
|
-
}
|
|
186
|
-
function add(data, origin) {
|
|
187
|
-
xlsxPackage.utils.sheet_add_aoa(sheet, data, { origin });
|
|
188
|
-
}
|
|
189
|
-
function addOne(datum, origin) {
|
|
190
|
-
xlsxPackage.utils.sheet_add_aoa(sheet, [[datum]], { origin });
|
|
191
|
-
}
|
|
192
|
-
function mergeCells(addr, width, height) {
|
|
193
|
-
if (width === 1 && height === 1) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
if (sheet['!merges'] == null) {
|
|
197
|
-
sheet['!merges'] = [];
|
|
198
|
-
}
|
|
199
|
-
sheet['!merges'].push({ s: addr, e: move(addr, width - 1, height - 1) });
|
|
200
|
-
}
|
|
92
|
+
function safeGetSpanRect(column, record, rowIndex, colIndex) {
|
|
93
|
+
let colSpan = 1;
|
|
94
|
+
let rowSpan = 1;
|
|
95
|
+
if (column.getSpanRect) {
|
|
96
|
+
const value = internals.safeGetValue(column, record, rowIndex);
|
|
97
|
+
const spanRect = column.getSpanRect(value, record, rowIndex);
|
|
98
|
+
colSpan = spanRect == null ? 1 : spanRect.right - colIndex;
|
|
99
|
+
rowSpan = spanRect == null ? 1 : spanRect.bottom - rowIndex;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const cellProps = internals.safeGetCellProps(column, record, rowIndex);
|
|
103
|
+
if (cellProps.colSpan != null) {
|
|
104
|
+
colSpan = cellProps.colSpan;
|
|
105
|
+
}
|
|
106
|
+
if (cellProps.rowSpan != null) {
|
|
107
|
+
rowSpan = cellProps.rowSpan;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// 注意这里没有考虑「rowSpan/colSpan 不能过大,避免 rowSpan/colSpan 影响因虚拟滚动而未渲染的单元格」
|
|
111
|
+
return {
|
|
112
|
+
top: rowIndex,
|
|
113
|
+
bottom: rowIndex + rowSpan,
|
|
114
|
+
left: colIndex,
|
|
115
|
+
right: colIndex + colSpan,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function move({ c, r }, dx, dy) {
|
|
119
|
+
return { c: c + dx, r: r + dy };
|
|
120
|
+
}
|
|
121
|
+
function sanitizeCellDatum(value) {
|
|
122
|
+
if (value === Infinity || value === -Infinity || (typeof value === 'number' && isNaN(value))) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** 根据 BaseTable 的 dataSource 和 column,将表格数据导出为 Excel 文件 */
|
|
130
|
+
function exportTableAsExcel(xlsxPackage, dataSource, columns, filename) {
|
|
131
|
+
const sheet = xlsxPackage.utils.aoa_to_sheet([]);
|
|
132
|
+
const topHeaderHeight = getTreeDepth(columns) + 1;
|
|
133
|
+
const origin = { c: 0, r: 0 };
|
|
134
|
+
addTopHeaders(origin);
|
|
135
|
+
addDataPart(move(origin, 0, topHeaderHeight));
|
|
136
|
+
xlsxPackage.writeFile({
|
|
137
|
+
SheetNames: ['Sheet1'],
|
|
138
|
+
Sheets: { Sheet1: sheet },
|
|
139
|
+
}, filename);
|
|
140
|
+
function addTopHeaders(origin) {
|
|
141
|
+
dfs(columns, 0, 0);
|
|
142
|
+
function dfs(cols, startDx, startDy) {
|
|
143
|
+
var _a;
|
|
144
|
+
const start = move(origin, startDx, startDy);
|
|
145
|
+
let offsetX = 0;
|
|
146
|
+
for (const col of cols) {
|
|
147
|
+
if ((_a = col.features) === null || _a === void 0 ? void 0 : _a.noExport) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const current = move(start, offsetX, 0);
|
|
151
|
+
addOne(col.name, current);
|
|
152
|
+
if (isLeafNode(col)) {
|
|
153
|
+
offsetX += 1;
|
|
154
|
+
mergeCells(current, 1, topHeaderHeight - startDy);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const childrenWidth = dfs(col.children, startDx + offsetX, startDy + 1);
|
|
158
|
+
mergeCells(current, childrenWidth, 1);
|
|
159
|
+
offsetX += childrenWidth;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return offsetX;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function addDataPart(origin) {
|
|
166
|
+
const leafColumns = collectNodes(columns, 'leaf-only').filter((col) => { var _a; return !((_a = col.features) === null || _a === void 0 ? void 0 : _a.noExport); });
|
|
167
|
+
const spanManager = new SpanManager();
|
|
168
|
+
const dataPart = dataSource.map((record, rowIndex) => {
|
|
169
|
+
spanManager.stripUpwards(rowIndex);
|
|
170
|
+
return leafColumns.map((col, colIndex) => {
|
|
171
|
+
if (spanManager.testSkip(rowIndex, colIndex)) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const spanRect = safeGetSpanRect(col, record, rowIndex, colIndex);
|
|
175
|
+
const rowSpan = spanRect.bottom - spanRect.top;
|
|
176
|
+
const colSpan = spanRect.right - spanRect.left;
|
|
177
|
+
if (rowSpan > 1 || colSpan > 1) {
|
|
178
|
+
spanManager.add(spanRect.top, spanRect.left, colSpan, rowSpan);
|
|
179
|
+
mergeCells(move(origin, spanRect.left, spanRect.top), colSpan, rowSpan);
|
|
180
|
+
}
|
|
181
|
+
return sanitizeCellDatum(internals.safeGetValue(col, record, rowIndex));
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
add(dataPart, origin);
|
|
185
|
+
}
|
|
186
|
+
function add(data, origin) {
|
|
187
|
+
xlsxPackage.utils.sheet_add_aoa(sheet, data, { origin });
|
|
188
|
+
}
|
|
189
|
+
function addOne(datum, origin) {
|
|
190
|
+
xlsxPackage.utils.sheet_add_aoa(sheet, [[datum]], { origin });
|
|
191
|
+
}
|
|
192
|
+
function mergeCells(addr, width, height) {
|
|
193
|
+
if (width === 1 && height === 1) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (sheet['!merges'] == null) {
|
|
197
|
+
sheet['!merges'] = [];
|
|
198
|
+
}
|
|
199
|
+
sheet['!merges'].push({ s: addr, e: move(addr, width - 1, height - 1) });
|
|
200
|
+
}
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
/** 对树状结构的数据进行排序.
|
|
204
|
-
* layeredSort 是一个递归的过程,针对树上的每一个父节点,该函数都会重新对其子节点数组(children) 进行排序.
|
|
205
|
-
* */
|
|
206
|
-
function layeredSort(array, compare) {
|
|
207
|
-
return dfs(array);
|
|
208
|
-
function dfs(rows) {
|
|
209
|
-
if (!Array.isArray(array)) {
|
|
210
|
-
return array;
|
|
211
|
-
}
|
|
212
|
-
return rows
|
|
213
|
-
.map((row) => {
|
|
214
|
-
if (isLeafNode(row)) {
|
|
215
|
-
return row;
|
|
216
|
-
}
|
|
217
|
-
return Object.assign(Object.assign({}, row), { children: dfs(row.children) });
|
|
218
|
-
})
|
|
219
|
-
.sort(compare);
|
|
220
|
-
}
|
|
203
|
+
/** 对树状结构的数据进行排序.
|
|
204
|
+
* layeredSort 是一个递归的过程,针对树上的每一个父节点,该函数都会重新对其子节点数组(children) 进行排序.
|
|
205
|
+
* */
|
|
206
|
+
function layeredSort(array, compare) {
|
|
207
|
+
return dfs(array);
|
|
208
|
+
function dfs(rows) {
|
|
209
|
+
if (!Array.isArray(array)) {
|
|
210
|
+
return array;
|
|
211
|
+
}
|
|
212
|
+
return rows
|
|
213
|
+
.map((row) => {
|
|
214
|
+
if (isLeafNode(row)) {
|
|
215
|
+
return row;
|
|
216
|
+
}
|
|
217
|
+
return Object.assign(Object.assign({}, row), { children: dfs(row.children) });
|
|
218
|
+
})
|
|
219
|
+
.sort(compare);
|
|
220
|
+
}
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
const factorySymbol = Symbol('factory-symbol');
|
|
224
|
-
function isProtoFactory(v) {
|
|
225
|
-
return v && v[factorySymbol];
|
|
226
|
-
}
|
|
227
|
-
function proto(baseRecord, ensureArray = 'auto') {
|
|
228
|
-
const baseKeys = Object.keys(baseRecord);
|
|
229
|
-
function process(record) {
|
|
230
|
-
const result = Object.assign({}, record);
|
|
231
|
-
baseKeys.forEach((key) => {
|
|
232
|
-
var _a;
|
|
233
|
-
if (result[key] === proto.empty) {
|
|
234
|
-
delete result[key];
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
const base = baseRecord[key];
|
|
238
|
-
if (isProtoFactory(base)) {
|
|
239
|
-
result[key] = base(result[key]);
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
result[key] = (_a = result[key]) !== null && _a !== void 0 ? _a : base;
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
return result;
|
|
246
|
-
}
|
|
247
|
-
function factory(arg) {
|
|
248
|
-
const isEnsureArray = ensureArray === 'auto' ? Array.isArray(arg) : ensureArray;
|
|
249
|
-
if (isEnsureArray) {
|
|
250
|
-
if (arg == null) {
|
|
251
|
-
return [];
|
|
252
|
-
}
|
|
253
|
-
return arg.map(process);
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
return process(arg);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
// @ts-ignore
|
|
260
|
-
factory[factorySymbol] = true;
|
|
261
|
-
factory.extends = (extRecord) => {
|
|
262
|
-
const extFactory = proto(extRecord, ensureArray);
|
|
263
|
-
return (arg) => factory(extFactory(arg));
|
|
264
|
-
};
|
|
265
|
-
return factory;
|
|
266
|
-
}
|
|
267
|
-
proto.empty = Symbol('proto.empty');
|
|
268
|
-
proto.string = ((v) => {
|
|
269
|
-
if (v != null && typeof v !== 'string') {
|
|
270
|
-
throw new Error('must be string');
|
|
271
|
-
}
|
|
272
|
-
return v;
|
|
273
|
-
});
|
|
274
|
-
proto.string[factorySymbol] = true;
|
|
275
|
-
proto.number = ((v) => {
|
|
276
|
-
if (v != null && typeof v !== 'number') {
|
|
277
|
-
throw new Error('must be number');
|
|
278
|
-
}
|
|
279
|
-
return v;
|
|
280
|
-
});
|
|
281
|
-
proto.number[factorySymbol] = true;
|
|
282
|
-
proto.notNull = ((v) => {
|
|
283
|
-
if (v == null) {
|
|
284
|
-
throw new Error('must be not null');
|
|
285
|
-
}
|
|
286
|
-
return v;
|
|
287
|
-
});
|
|
288
|
-
proto.notNull[factorySymbol] = true;
|
|
289
|
-
proto.object = (baseRecord) => proto(baseRecord, false);
|
|
223
|
+
const factorySymbol = Symbol('factory-symbol');
|
|
224
|
+
function isProtoFactory(v) {
|
|
225
|
+
return v && v[factorySymbol];
|
|
226
|
+
}
|
|
227
|
+
function proto(baseRecord, ensureArray = 'auto') {
|
|
228
|
+
const baseKeys = Object.keys(baseRecord);
|
|
229
|
+
function process(record) {
|
|
230
|
+
const result = Object.assign({}, record);
|
|
231
|
+
baseKeys.forEach((key) => {
|
|
232
|
+
var _a;
|
|
233
|
+
if (result[key] === proto.empty) {
|
|
234
|
+
delete result[key];
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const base = baseRecord[key];
|
|
238
|
+
if (isProtoFactory(base)) {
|
|
239
|
+
result[key] = base(result[key]);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
result[key] = (_a = result[key]) !== null && _a !== void 0 ? _a : base;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
function factory(arg) {
|
|
248
|
+
const isEnsureArray = ensureArray === 'auto' ? Array.isArray(arg) : ensureArray;
|
|
249
|
+
if (isEnsureArray) {
|
|
250
|
+
if (arg == null) {
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
return arg.map(process);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
return process(arg);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// @ts-ignore
|
|
260
|
+
factory[factorySymbol] = true;
|
|
261
|
+
factory.extends = (extRecord) => {
|
|
262
|
+
const extFactory = proto(extRecord, ensureArray);
|
|
263
|
+
return (arg) => factory(extFactory(arg));
|
|
264
|
+
};
|
|
265
|
+
return factory;
|
|
266
|
+
}
|
|
267
|
+
proto.empty = Symbol('proto.empty');
|
|
268
|
+
proto.string = ((v) => {
|
|
269
|
+
if (v != null && typeof v !== 'string') {
|
|
270
|
+
throw new Error('must be string');
|
|
271
|
+
}
|
|
272
|
+
return v;
|
|
273
|
+
});
|
|
274
|
+
proto.string[factorySymbol] = true;
|
|
275
|
+
proto.number = ((v) => {
|
|
276
|
+
if (v != null && typeof v !== 'number') {
|
|
277
|
+
throw new Error('must be number');
|
|
278
|
+
}
|
|
279
|
+
return v;
|
|
280
|
+
});
|
|
281
|
+
proto.number[factorySymbol] = true;
|
|
282
|
+
proto.notNull = ((v) => {
|
|
283
|
+
if (v == null) {
|
|
284
|
+
throw new Error('must be not null');
|
|
285
|
+
}
|
|
286
|
+
return v;
|
|
287
|
+
});
|
|
288
|
+
proto.notNull[factorySymbol] = true;
|
|
289
|
+
proto.object = (baseRecord) => proto(baseRecord, false);
|
|
290
290
|
proto.array = (baseRecord) => proto(baseRecord, true);
|
|
291
291
|
|
|
292
|
-
function makeRecursiveMapper(fn) {
|
|
293
|
-
return (tree) => {
|
|
294
|
-
return dfs(tree, 0, []).result;
|
|
295
|
-
function dfs(nodes, parentStartIndex, path) {
|
|
296
|
-
let flatCount = 0;
|
|
297
|
-
const result = [];
|
|
298
|
-
for (const node of nodes) {
|
|
299
|
-
path.push(node);
|
|
300
|
-
const startIndex = parentStartIndex + flatCount;
|
|
301
|
-
let subResult;
|
|
302
|
-
if (isLeafNode(node)) {
|
|
303
|
-
subResult = fn(node, {
|
|
304
|
-
startIndex,
|
|
305
|
-
endIndex: startIndex + 1,
|
|
306
|
-
path: path.slice(),
|
|
307
|
-
isLeaf: true,
|
|
308
|
-
});
|
|
309
|
-
flatCount += 1;
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
const dfsResult = dfs(node.children, startIndex, path);
|
|
313
|
-
subResult = fn(Object.assign(Object.assign({}, node), { children: dfsResult.result }), { startIndex, endIndex: startIndex + dfsResult.flatCount, path: path.slice(), isLeaf: false });
|
|
314
|
-
flatCount += dfsResult.flatCount;
|
|
315
|
-
}
|
|
316
|
-
if (Array.isArray(subResult)) {
|
|
317
|
-
result.push(...subResult);
|
|
318
|
-
}
|
|
319
|
-
else if (subResult != null) {
|
|
320
|
-
result.push(subResult);
|
|
321
|
-
}
|
|
322
|
-
path.pop();
|
|
323
|
-
}
|
|
324
|
-
return { result, flatCount };
|
|
325
|
-
}
|
|
326
|
-
};
|
|
292
|
+
function makeRecursiveMapper(fn) {
|
|
293
|
+
return (tree) => {
|
|
294
|
+
return dfs(tree, 0, []).result;
|
|
295
|
+
function dfs(nodes, parentStartIndex, path) {
|
|
296
|
+
let flatCount = 0;
|
|
297
|
+
const result = [];
|
|
298
|
+
for (const node of nodes) {
|
|
299
|
+
path.push(node);
|
|
300
|
+
const startIndex = parentStartIndex + flatCount;
|
|
301
|
+
let subResult;
|
|
302
|
+
if (isLeafNode(node)) {
|
|
303
|
+
subResult = fn(node, {
|
|
304
|
+
startIndex,
|
|
305
|
+
endIndex: startIndex + 1,
|
|
306
|
+
path: path.slice(),
|
|
307
|
+
isLeaf: true,
|
|
308
|
+
});
|
|
309
|
+
flatCount += 1;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
const dfsResult = dfs(node.children, startIndex, path);
|
|
313
|
+
subResult = fn(Object.assign(Object.assign({}, node), { children: dfsResult.result }), { startIndex, endIndex: startIndex + dfsResult.flatCount, path: path.slice(), isLeaf: false });
|
|
314
|
+
flatCount += dfsResult.flatCount;
|
|
315
|
+
}
|
|
316
|
+
if (Array.isArray(subResult)) {
|
|
317
|
+
result.push(...subResult);
|
|
318
|
+
}
|
|
319
|
+
else if (subResult != null) {
|
|
320
|
+
result.push(subResult);
|
|
321
|
+
}
|
|
322
|
+
path.pop();
|
|
323
|
+
}
|
|
324
|
+
return { result, flatCount };
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
/** 比较函数,支持字符串、数字、数组和 null。
|
|
330
|
-
* * 对于字符串将比较两者的字典序;
|
|
331
|
-
* * 对数字将比较两者大小;
|
|
332
|
-
* * null 值在比较时总是小于另一个值;
|
|
333
|
-
* * 对于数组来说,将逐个比较数组中的元素,第一个不相等的比较结果将作为整个数组的比较结果
|
|
334
|
-
*
|
|
335
|
-
* 数组的比较可参考 python 中的元祖比较:
|
|
336
|
-
* https://stackoverflow.com/questions/5292303/how-does-tuple-comparison-work-in-python */
|
|
337
|
-
function smartCompare(x, y) {
|
|
338
|
-
// 将 null 排在最后面
|
|
339
|
-
if (x == null) {
|
|
340
|
-
return 1;
|
|
341
|
-
}
|
|
342
|
-
if (y == null) {
|
|
343
|
-
return -1;
|
|
344
|
-
}
|
|
345
|
-
if (typeof x === 'number' && typeof y === 'number') {
|
|
346
|
-
return x - y;
|
|
347
|
-
}
|
|
348
|
-
if (typeof x === 'string' && typeof y === 'string') {
|
|
349
|
-
// 字符串使用 默认的字典序
|
|
350
|
-
if (x < y) {
|
|
351
|
-
return -1;
|
|
352
|
-
}
|
|
353
|
-
else if (x > y) {
|
|
354
|
-
return 1;
|
|
355
|
-
}
|
|
356
|
-
else {
|
|
357
|
-
return 0;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (Array.isArray(x) && Array.isArray(y)) {
|
|
361
|
-
const len = Math.min(x.length, y.length);
|
|
362
|
-
for (let i = 0; i < len; i++) {
|
|
363
|
-
const cmp = smartCompare(x[i], y[i]);
|
|
364
|
-
if (cmp !== 0) {
|
|
365
|
-
return cmp;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
// 数组长度不等时,元素少的字段放在前面
|
|
369
|
-
return x.length - y.length;
|
|
370
|
-
}
|
|
371
|
-
// 对于不认识的数据类型,返回 0
|
|
372
|
-
return 0;
|
|
329
|
+
/** 比较函数,支持字符串、数字、数组和 null。
|
|
330
|
+
* * 对于字符串将比较两者的字典序;
|
|
331
|
+
* * 对数字将比较两者大小;
|
|
332
|
+
* * null 值在比较时总是小于另一个值;
|
|
333
|
+
* * 对于数组来说,将逐个比较数组中的元素,第一个不相等的比较结果将作为整个数组的比较结果
|
|
334
|
+
*
|
|
335
|
+
* 数组的比较可参考 python 中的元祖比较:
|
|
336
|
+
* https://stackoverflow.com/questions/5292303/how-does-tuple-comparison-work-in-python */
|
|
337
|
+
function smartCompare(x, y) {
|
|
338
|
+
// 将 null 排在最后面
|
|
339
|
+
if (x == null) {
|
|
340
|
+
return 1;
|
|
341
|
+
}
|
|
342
|
+
if (y == null) {
|
|
343
|
+
return -1;
|
|
344
|
+
}
|
|
345
|
+
if (typeof x === 'number' && typeof y === 'number') {
|
|
346
|
+
return x - y;
|
|
347
|
+
}
|
|
348
|
+
if (typeof x === 'string' && typeof y === 'string') {
|
|
349
|
+
// 字符串使用 默认的字典序
|
|
350
|
+
if (x < y) {
|
|
351
|
+
return -1;
|
|
352
|
+
}
|
|
353
|
+
else if (x > y) {
|
|
354
|
+
return 1;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
return 0;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (Array.isArray(x) && Array.isArray(y)) {
|
|
361
|
+
const len = Math.min(x.length, y.length);
|
|
362
|
+
for (let i = 0; i < len; i++) {
|
|
363
|
+
const cmp = smartCompare(x[i], y[i]);
|
|
364
|
+
if (cmp !== 0) {
|
|
365
|
+
return cmp;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// 数组长度不等时,元素少的字段放在前面
|
|
369
|
+
return x.length - y.length;
|
|
370
|
+
}
|
|
371
|
+
// 对于不认识的数据类型,返回 0
|
|
372
|
+
return 0;
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
-
function normalizeAsArray(input) {
|
|
376
|
-
if (input == null) {
|
|
377
|
-
return [];
|
|
378
|
-
}
|
|
379
|
-
else if (Array.isArray(input)) {
|
|
380
|
-
return input;
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
return [input];
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
/** @deprecated 该 API 已经过时,请使用 makeRecursiveMapper */
|
|
387
|
-
function traverseColumn(fn) {
|
|
388
|
-
return ({ columns, dataSource }) => {
|
|
389
|
-
return { dataSource, columns: dfs(columns, 0).result };
|
|
390
|
-
function dfs(columns, parentStartColIndex) {
|
|
391
|
-
let flatColCount = 0;
|
|
392
|
-
const result = [];
|
|
393
|
-
for (const col of columns) {
|
|
394
|
-
const startColIndex = parentStartColIndex + flatColCount;
|
|
395
|
-
let unNormalized;
|
|
396
|
-
if (isLeafNode(col)) {
|
|
397
|
-
unNormalized = fn(col, {
|
|
398
|
-
range: { start: startColIndex, end: startColIndex + 1 },
|
|
399
|
-
dataSource,
|
|
400
|
-
});
|
|
401
|
-
flatColCount += 1;
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
const dfsResult = dfs(col.children, startColIndex);
|
|
405
|
-
unNormalized = fn(Object.assign(Object.assign({}, col), { children: dfsResult.result }), {
|
|
406
|
-
range: {
|
|
407
|
-
start: startColIndex,
|
|
408
|
-
end: startColIndex + dfsResult.flatColCount,
|
|
409
|
-
},
|
|
410
|
-
dataSource,
|
|
411
|
-
});
|
|
412
|
-
flatColCount += dfsResult.flatColCount;
|
|
413
|
-
}
|
|
414
|
-
result.push(...normalizeAsArray(unNormalized));
|
|
415
|
-
}
|
|
416
|
-
return { result, flatColCount };
|
|
417
|
-
}
|
|
418
|
-
};
|
|
375
|
+
function normalizeAsArray(input) {
|
|
376
|
+
if (input == null) {
|
|
377
|
+
return [];
|
|
378
|
+
}
|
|
379
|
+
else if (Array.isArray(input)) {
|
|
380
|
+
return input;
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
return [input];
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/** @deprecated 该 API 已经过时,请使用 makeRecursiveMapper */
|
|
387
|
+
function traverseColumn(fn) {
|
|
388
|
+
return ({ columns, dataSource }) => {
|
|
389
|
+
return { dataSource, columns: dfs(columns, 0).result };
|
|
390
|
+
function dfs(columns, parentStartColIndex) {
|
|
391
|
+
let flatColCount = 0;
|
|
392
|
+
const result = [];
|
|
393
|
+
for (const col of columns) {
|
|
394
|
+
const startColIndex = parentStartColIndex + flatColCount;
|
|
395
|
+
let unNormalized;
|
|
396
|
+
if (isLeafNode(col)) {
|
|
397
|
+
unNormalized = fn(col, {
|
|
398
|
+
range: { start: startColIndex, end: startColIndex + 1 },
|
|
399
|
+
dataSource,
|
|
400
|
+
});
|
|
401
|
+
flatColCount += 1;
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
const dfsResult = dfs(col.children, startColIndex);
|
|
405
|
+
unNormalized = fn(Object.assign(Object.assign({}, col), { children: dfsResult.result }), {
|
|
406
|
+
range: {
|
|
407
|
+
start: startColIndex,
|
|
408
|
+
end: startColIndex + dfsResult.flatColCount,
|
|
409
|
+
},
|
|
410
|
+
dataSource,
|
|
411
|
+
});
|
|
412
|
+
flatColCount += dfsResult.flatColCount;
|
|
413
|
+
}
|
|
414
|
+
result.push(...normalizeAsArray(unNormalized));
|
|
415
|
+
}
|
|
416
|
+
return { result, flatColCount };
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
419
|
}
|
|
420
420
|
|
|
421
|
-
const warnedSet = new Set();
|
|
422
|
-
function warnTransformsDeprecated(apiName) {
|
|
423
|
-
if (!warnedSet.has(apiName)) {
|
|
424
|
-
warnedSet.add(apiName);
|
|
425
|
-
console.warn(`[srp-table] transform 用法已经过时,请使用 pipeline 来对表格进行拓展` +
|
|
426
|
-
`\n 请移除以下 API 的调用:${apiName}`);
|
|
427
|
-
}
|
|
421
|
+
const warnedSet = new Set();
|
|
422
|
+
function warnTransformsDeprecated(apiName) {
|
|
423
|
+
if (!warnedSet.has(apiName)) {
|
|
424
|
+
warnedSet.add(apiName);
|
|
425
|
+
console.warn(`[srp-table] transform 用法已经过时,请使用 pipeline 来对表格进行拓展` +
|
|
426
|
+
`\n 请移除以下 API 的调用:${apiName}`);
|
|
427
|
+
}
|
|
428
428
|
}
|
|
429
429
|
|
|
430
|
-
function isIdentity$1(x, y) {
|
|
431
|
-
return x === y;
|
|
432
|
-
}
|
|
433
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
434
|
-
function makeAutoRowSpanTransform() {
|
|
435
|
-
warnTransformsDeprecated('makeAutoRowSpanTransform');
|
|
436
|
-
return traverseColumn((col, { dataSource, range }) => {
|
|
437
|
-
var _a;
|
|
438
|
-
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.autoRowSpan)) {
|
|
439
|
-
return col;
|
|
440
|
-
}
|
|
441
|
-
if (!isLeafNode(col)) {
|
|
442
|
-
return col;
|
|
443
|
-
}
|
|
444
|
-
const isFunc = typeof col.features.autoRowSpan === 'function';
|
|
445
|
-
const shouldMergeCell = isFunc ? col.features.autoRowSpan : isIdentity$1;
|
|
446
|
-
const spanRects = [];
|
|
447
|
-
let lastBottom = 0;
|
|
448
|
-
let prevValue = null;
|
|
449
|
-
let prevRow = null;
|
|
450
|
-
for (let rowIndex = 0; rowIndex < dataSource.length; rowIndex++) {
|
|
451
|
-
const row = dataSource[rowIndex];
|
|
452
|
-
const value = internals.safeGetValue(col, row, rowIndex);
|
|
453
|
-
if (rowIndex === 0 || !shouldMergeCell(prevValue, value, prevRow, row)) {
|
|
454
|
-
const spanRect = {
|
|
455
|
-
top: lastBottom,
|
|
456
|
-
bottom: rowIndex,
|
|
457
|
-
left: range.start,
|
|
458
|
-
right: range.end,
|
|
459
|
-
};
|
|
460
|
-
for (let i = lastBottom; i < rowIndex; i++) {
|
|
461
|
-
spanRects.push(spanRect);
|
|
462
|
-
}
|
|
463
|
-
lastBottom = rowIndex;
|
|
464
|
-
}
|
|
465
|
-
prevValue = value;
|
|
466
|
-
prevRow = row;
|
|
467
|
-
}
|
|
468
|
-
for (let i = lastBottom; i < dataSource.length; i++) {
|
|
469
|
-
spanRects.push({
|
|
470
|
-
top: lastBottom,
|
|
471
|
-
bottom: dataSource.length,
|
|
472
|
-
left: range.start,
|
|
473
|
-
right: range.end,
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
return Object.assign(Object.assign({}, col), { getSpanRect(value, row, rowIndex) {
|
|
477
|
-
return spanRects[rowIndex];
|
|
478
|
-
} });
|
|
479
|
-
});
|
|
430
|
+
function isIdentity$1(x, y) {
|
|
431
|
+
return x === y;
|
|
432
|
+
}
|
|
433
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
434
|
+
function makeAutoRowSpanTransform() {
|
|
435
|
+
warnTransformsDeprecated('makeAutoRowSpanTransform');
|
|
436
|
+
return traverseColumn((col, { dataSource, range }) => {
|
|
437
|
+
var _a;
|
|
438
|
+
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.autoRowSpan)) {
|
|
439
|
+
return col;
|
|
440
|
+
}
|
|
441
|
+
if (!isLeafNode(col)) {
|
|
442
|
+
return col;
|
|
443
|
+
}
|
|
444
|
+
const isFunc = typeof col.features.autoRowSpan === 'function';
|
|
445
|
+
const shouldMergeCell = isFunc ? col.features.autoRowSpan : isIdentity$1;
|
|
446
|
+
const spanRects = [];
|
|
447
|
+
let lastBottom = 0;
|
|
448
|
+
let prevValue = null;
|
|
449
|
+
let prevRow = null;
|
|
450
|
+
for (let rowIndex = 0; rowIndex < dataSource.length; rowIndex++) {
|
|
451
|
+
const row = dataSource[rowIndex];
|
|
452
|
+
const value = internals.safeGetValue(col, row, rowIndex);
|
|
453
|
+
if (rowIndex === 0 || !shouldMergeCell(prevValue, value, prevRow, row)) {
|
|
454
|
+
const spanRect = {
|
|
455
|
+
top: lastBottom,
|
|
456
|
+
bottom: rowIndex,
|
|
457
|
+
left: range.start,
|
|
458
|
+
right: range.end,
|
|
459
|
+
};
|
|
460
|
+
for (let i = lastBottom; i < rowIndex; i++) {
|
|
461
|
+
spanRects.push(spanRect);
|
|
462
|
+
}
|
|
463
|
+
lastBottom = rowIndex;
|
|
464
|
+
}
|
|
465
|
+
prevValue = value;
|
|
466
|
+
prevRow = row;
|
|
467
|
+
}
|
|
468
|
+
for (let i = lastBottom; i < dataSource.length; i++) {
|
|
469
|
+
spanRects.push({
|
|
470
|
+
top: lastBottom,
|
|
471
|
+
bottom: dataSource.length,
|
|
472
|
+
left: range.start,
|
|
473
|
+
right: range.end,
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
return Object.assign(Object.assign({}, col), { getSpanRect(value, row, rowIndex) {
|
|
477
|
+
return spanRects[rowIndex];
|
|
478
|
+
} });
|
|
479
|
+
});
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
-
const AUTO_WIDTH_WRAPPER_CLS = 'auto-width-wrapper';
|
|
483
|
-
const AUTO_WIDTH_EXPANDER_CLS = 'auto-width-expander';
|
|
482
|
+
const AUTO_WIDTH_WRAPPER_CLS = 'auto-width-wrapper';
|
|
483
|
+
const AUTO_WIDTH_EXPANDER_CLS = 'auto-width-expander';
|
|
484
484
|
const AutoWidthWrapper = styled__default.div `
|
|
485
485
|
height: 100%;
|
|
486
486
|
display: inline-flex;
|
|
487
487
|
align-items: center;
|
|
488
488
|
white-space: nowrap;
|
|
489
489
|
padding: 8px 12px;
|
|
490
|
-
`;
|
|
491
|
-
function isSameArray(arr1, arr2) {
|
|
492
|
-
return arr1.length === arr2.length && arr1.every((x, i) => x === arr2[i]);
|
|
493
|
-
}
|
|
494
|
-
/** 自适应列宽
|
|
495
|
-
*
|
|
496
|
-
* @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展
|
|
497
|
-
*
|
|
498
|
-
* @param tableRef BaseTable 的 ref
|
|
499
|
-
* @param options 参数
|
|
500
|
-
* @param deps 重新调整列宽的依赖数组,每当依赖数组发生变化时, useAutoWidthTransform 会根据单元格内容的实际渲染宽度 设置单元格的宽度
|
|
501
|
-
*
|
|
502
|
-
* options 说明:
|
|
503
|
-
* - options.appendExpander 是否在列的末尾追加可伸缩列
|
|
504
|
-
* - options.expanderVisibility 设置为 `'hidden'` 可以隐藏可伸缩列
|
|
505
|
-
* - options.wrapperStyle 单元格中 div.auto-width-wrapper 的样式
|
|
506
|
-
* - options.initColumnWidth 自适应的初始列宽
|
|
507
|
-
*
|
|
508
|
-
* 注意 useAutoWidthTransform 是一个 React hooks,要遵循 hooks 的用法规范
|
|
509
|
-
* */
|
|
510
|
-
function useAutoWidthTransform(tableRef, options, deps) {
|
|
511
|
-
warnTransformsDeprecated('useAutoWidthTransform');
|
|
512
|
-
const [widthList, setWidthList] = useState([]);
|
|
513
|
-
useEffect(() => {
|
|
514
|
-
const artTable = tableRef.current.getDoms().artTable;
|
|
515
|
-
const rows = Array.from(artTable.querySelectorAll(`.${Classes.tableRow}`));
|
|
516
|
-
if (rows.length === 0) {
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
const preferredWidthList = [];
|
|
520
|
-
for (const row of rows) {
|
|
521
|
-
const autoWidthDivList = row.querySelectorAll(`.${AUTO_WIDTH_WRAPPER_CLS}`);
|
|
522
|
-
autoWidthDivList.forEach((div, i) => {
|
|
523
|
-
var _a;
|
|
524
|
-
preferredWidthList[i] = Math.max((_a = preferredWidthList[i]) !== null && _a !== void 0 ? _a : 0, div.scrollWidth);
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
if (!isSameArray(preferredWidthList, widthList)) {
|
|
528
|
-
setWidthList(preferredWidthList);
|
|
529
|
-
}
|
|
530
|
-
}, deps);
|
|
531
|
-
let i = 0;
|
|
532
|
-
const innerTransform = traverseColumn((col) => {
|
|
533
|
-
var _a, _b, _c;
|
|
534
|
-
if (!isLeafNode(col)) {
|
|
535
|
-
return col;
|
|
536
|
-
}
|
|
537
|
-
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.autoWidth)) {
|
|
538
|
-
return col;
|
|
539
|
-
}
|
|
540
|
-
const { max = Infinity, min = -Infinity } = col.features.autoWidth;
|
|
541
|
-
const width = (_c = (_b = widthList[i++]) !== null && _b !== void 0 ? _b : col.width) !== null && _c !== void 0 ? _c : options === null || options === void 0 ? void 0 : options.initColumnWidth;
|
|
542
|
-
const clampedWidth = Math.max(min, Math.min(max, width));
|
|
543
|
-
return Object.assign(Object.assign({}, col), { width: clampedWidth, getCellProps(_, record, rowIndex) {
|
|
544
|
-
return mergeCellProps(internals.safeGetCellProps(col, record, rowIndex), {
|
|
545
|
-
style: { padding: 0 },
|
|
546
|
-
});
|
|
547
|
-
},
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
490
|
+
`;
|
|
491
|
+
function isSameArray(arr1, arr2) {
|
|
492
|
+
return arr1.length === arr2.length && arr1.every((x, i) => x === arr2[i]);
|
|
493
|
+
}
|
|
494
|
+
/** 自适应列宽
|
|
495
|
+
*
|
|
496
|
+
* @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展
|
|
497
|
+
*
|
|
498
|
+
* @param tableRef BaseTable 的 ref
|
|
499
|
+
* @param options 参数
|
|
500
|
+
* @param deps 重新调整列宽的依赖数组,每当依赖数组发生变化时, useAutoWidthTransform 会根据单元格内容的实际渲染宽度 设置单元格的宽度
|
|
501
|
+
*
|
|
502
|
+
* options 说明:
|
|
503
|
+
* - options.appendExpander 是否在列的末尾追加可伸缩列
|
|
504
|
+
* - options.expanderVisibility 设置为 `'hidden'` 可以隐藏可伸缩列
|
|
505
|
+
* - options.wrapperStyle 单元格中 div.auto-width-wrapper 的样式
|
|
506
|
+
* - options.initColumnWidth 自适应的初始列宽
|
|
507
|
+
*
|
|
508
|
+
* 注意 useAutoWidthTransform 是一个 React hooks,要遵循 hooks 的用法规范
|
|
509
|
+
* */
|
|
510
|
+
function useAutoWidthTransform(tableRef, options, deps) {
|
|
511
|
+
warnTransformsDeprecated('useAutoWidthTransform');
|
|
512
|
+
const [widthList, setWidthList] = useState([]);
|
|
513
|
+
useEffect(() => {
|
|
514
|
+
const artTable = tableRef.current.getDoms().artTable;
|
|
515
|
+
const rows = Array.from(artTable.querySelectorAll(`.${Classes.tableRow}`));
|
|
516
|
+
if (rows.length === 0) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
const preferredWidthList = [];
|
|
520
|
+
for (const row of rows) {
|
|
521
|
+
const autoWidthDivList = row.querySelectorAll(`.${AUTO_WIDTH_WRAPPER_CLS}`);
|
|
522
|
+
autoWidthDivList.forEach((div, i) => {
|
|
523
|
+
var _a;
|
|
524
|
+
preferredWidthList[i] = Math.max((_a = preferredWidthList[i]) !== null && _a !== void 0 ? _a : 0, div.scrollWidth);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
if (!isSameArray(preferredWidthList, widthList)) {
|
|
528
|
+
setWidthList(preferredWidthList);
|
|
529
|
+
}
|
|
530
|
+
}, deps);
|
|
531
|
+
let i = 0;
|
|
532
|
+
const innerTransform = traverseColumn((col) => {
|
|
533
|
+
var _a, _b, _c;
|
|
534
|
+
if (!isLeafNode(col)) {
|
|
535
|
+
return col;
|
|
536
|
+
}
|
|
537
|
+
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.autoWidth)) {
|
|
538
|
+
return col;
|
|
539
|
+
}
|
|
540
|
+
const { max = Infinity, min = -Infinity } = col.features.autoWidth;
|
|
541
|
+
const width = (_c = (_b = widthList[i++]) !== null && _b !== void 0 ? _b : col.width) !== null && _c !== void 0 ? _c : options === null || options === void 0 ? void 0 : options.initColumnWidth;
|
|
542
|
+
const clampedWidth = Math.max(min, Math.min(max, width));
|
|
543
|
+
return Object.assign(Object.assign({}, col), { width: clampedWidth, getCellProps(_, record, rowIndex) {
|
|
544
|
+
return mergeCellProps(internals.safeGetCellProps(col, record, rowIndex), {
|
|
545
|
+
style: { padding: 0 },
|
|
546
|
+
});
|
|
547
|
+
},
|
|
548
|
+
render(_, record, rowIndex) {
|
|
549
|
+
return (React.createElement(AutoWidthWrapper, { className: AUTO_WIDTH_WRAPPER_CLS, style: options === null || options === void 0 ? void 0 : options.wrapperStyle }, internals.safeRender(col, record, rowIndex)));
|
|
550
|
+
} });
|
|
551
|
+
});
|
|
552
|
+
return (input) => {
|
|
553
|
+
var _a;
|
|
554
|
+
const { columns, dataSource } = innerTransform(input);
|
|
555
|
+
const expanderVisibility = (_a = options === null || options === void 0 ? void 0 : options.expanderVisibility) !== null && _a !== void 0 ? _a : 'visible';
|
|
556
|
+
return {
|
|
557
|
+
columns: (options === null || options === void 0 ? void 0 : options.appendExpander)
|
|
558
|
+
? appendFillRemainingWidthColumn(columns, {
|
|
559
|
+
headerCellProps: {
|
|
560
|
+
className: AUTO_WIDTH_EXPANDER_CLS,
|
|
561
|
+
style: {
|
|
562
|
+
background: expanderVisibility === 'hidden' ? 'var(--bgcolor)' : undefined,
|
|
563
|
+
border: expanderVisibility === 'hidden' ? 'none' : undefined,
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
getCellProps() {
|
|
567
|
+
return {
|
|
568
|
+
className: AUTO_WIDTH_EXPANDER_CLS,
|
|
569
|
+
style: { visibility: expanderVisibility },
|
|
570
|
+
};
|
|
571
|
+
},
|
|
572
|
+
})
|
|
573
|
+
: columns,
|
|
574
|
+
dataSource,
|
|
575
|
+
};
|
|
576
|
+
};
|
|
576
577
|
}
|
|
577
578
|
|
|
578
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
579
|
-
function makeBuildTreeTransform(idProp, parentIdProp) {
|
|
580
|
-
warnTransformsDeprecated('makeBuildTreeTransform');
|
|
581
|
-
return ({ columns, dataSource }) => {
|
|
582
|
-
return { columns, dataSource: buildTree$1(idProp, parentIdProp, dataSource) };
|
|
583
|
-
};
|
|
579
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
580
|
+
function makeBuildTreeTransform(idProp, parentIdProp) {
|
|
581
|
+
warnTransformsDeprecated('makeBuildTreeTransform');
|
|
582
|
+
return ({ columns, dataSource }) => {
|
|
583
|
+
return { columns, dataSource: buildTree$1(idProp, parentIdProp, dataSource) };
|
|
584
|
+
};
|
|
584
585
|
}
|
|
585
586
|
|
|
586
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
587
|
-
function makeColumnHoverTransform({ hoverColor = 'var(--hover-bgcolor)', hoverColIndex, onChangeHoverColIndex, }) {
|
|
588
|
-
warnTransformsDeprecated('makeColumnHoverTransform');
|
|
589
|
-
return traverseColumn((col, { range }) => {
|
|
590
|
-
if (!isLeafNode(col)) {
|
|
591
|
-
return col;
|
|
592
|
-
}
|
|
593
|
-
const colIndexMatched = range.start <= hoverColIndex && hoverColIndex < range.end;
|
|
594
|
-
const prevGetCellProps = col.getCellProps;
|
|
595
|
-
return Object.assign(Object.assign({}, col), { getCellProps(value, record, rowIndex) {
|
|
596
|
-
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
597
|
-
return mergeCellProps(prevCellProps, {
|
|
598
|
-
style: { '--bgcolor': colIndexMatched ? hoverColor : undefined },
|
|
599
|
-
onMouseEnter() {
|
|
600
|
-
onChangeHoverColIndex(range.start);
|
|
601
|
-
},
|
|
602
|
-
onMouseLeave() {
|
|
603
|
-
onChangeHoverColIndex(-1);
|
|
604
|
-
},
|
|
605
|
-
});
|
|
606
|
-
} });
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
610
|
-
function useColumnHoverTransform({ hoverColor, defaultHoverColIndex = -1, } = {}) {
|
|
611
|
-
const [hoverColIndex, onChangeHoverColIndex] = useState(defaultHoverColIndex);
|
|
612
|
-
return makeColumnHoverTransform({ hoverColor, hoverColIndex, onChangeHoverColIndex });
|
|
587
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
588
|
+
function makeColumnHoverTransform({ hoverColor = 'var(--hover-bgcolor)', hoverColIndex, onChangeHoverColIndex, }) {
|
|
589
|
+
warnTransformsDeprecated('makeColumnHoverTransform');
|
|
590
|
+
return traverseColumn((col, { range }) => {
|
|
591
|
+
if (!isLeafNode(col)) {
|
|
592
|
+
return col;
|
|
593
|
+
}
|
|
594
|
+
const colIndexMatched = range.start <= hoverColIndex && hoverColIndex < range.end;
|
|
595
|
+
const prevGetCellProps = col.getCellProps;
|
|
596
|
+
return Object.assign(Object.assign({}, col), { getCellProps(value, record, rowIndex) {
|
|
597
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
598
|
+
return mergeCellProps(prevCellProps, {
|
|
599
|
+
style: { '--bgcolor': colIndexMatched ? hoverColor : undefined },
|
|
600
|
+
onMouseEnter() {
|
|
601
|
+
onChangeHoverColIndex(range.start);
|
|
602
|
+
},
|
|
603
|
+
onMouseLeave() {
|
|
604
|
+
onChangeHoverColIndex(-1);
|
|
605
|
+
},
|
|
606
|
+
});
|
|
607
|
+
} });
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
611
|
+
function useColumnHoverTransform({ hoverColor, defaultHoverColIndex = -1, } = {}) {
|
|
612
|
+
const [hoverColIndex, onChangeHoverColIndex] = useState(defaultHoverColIndex);
|
|
613
|
+
return makeColumnHoverTransform({ hoverColor, hoverColIndex, onChangeHoverColIndex });
|
|
613
614
|
}
|
|
614
615
|
|
|
615
|
-
const EMPTY_RANGE$1 = {
|
|
616
|
-
start: -1,
|
|
617
|
-
end: -1,
|
|
618
|
-
};
|
|
619
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
620
|
-
function makeColumnRangeHoverTransform({ hoverColor = 'var(--hover-bgcolor)', headerHoverColor = 'var(--header-hover-bgcolor)', hoverRange, onChangeHoverRange, }) {
|
|
621
|
-
warnTransformsDeprecated('makeColumnRangeHoverTransform');
|
|
622
|
-
return traverseColumn((col, { range: colRange }) => {
|
|
623
|
-
const match = colRange.end > hoverRange.start && hoverRange.end > colRange.start;
|
|
624
|
-
if (!isLeafNode(col)) {
|
|
625
|
-
if (headerHoverColor == null) {
|
|
626
|
-
return col;
|
|
627
|
-
}
|
|
628
|
-
return Object.assign(Object.assign({}, col), { headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
629
|
-
onMouseEnter() {
|
|
630
|
-
onChangeHoverRange(colRange);
|
|
631
|
-
},
|
|
632
|
-
onMouseLeave() {
|
|
633
|
-
onChangeHoverRange(EMPTY_RANGE$1);
|
|
634
|
-
},
|
|
635
|
-
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
636
|
-
}) });
|
|
637
|
-
}
|
|
638
|
-
const prevGetCellProps = col.getCellProps;
|
|
639
|
-
return Object.assign(Object.assign({}, col), { headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
640
|
-
onMouseEnter() {
|
|
641
|
-
onChangeHoverRange(colRange);
|
|
642
|
-
},
|
|
643
|
-
onMouseLeave() {
|
|
644
|
-
onChangeHoverRange(EMPTY_RANGE$1);
|
|
645
|
-
},
|
|
646
|
-
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
647
|
-
}), getCellProps(value, record, rowIndex) {
|
|
648
|
-
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
649
|
-
return mergeCellProps(prevCellProps, {
|
|
650
|
-
onMouseEnter() {
|
|
651
|
-
onChangeHoverRange(colRange);
|
|
652
|
-
},
|
|
653
|
-
onMouseLeave() {
|
|
654
|
-
onChangeHoverRange(EMPTY_RANGE$1);
|
|
655
|
-
},
|
|
656
|
-
style: { '--bgcolor': match ? hoverColor : undefined },
|
|
657
|
-
});
|
|
658
|
-
} });
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
662
|
-
function useColumnHoverRangeTransform({ hoverColor, headerHoverColor, defaultHoverRange = EMPTY_RANGE$1, } = {}) {
|
|
663
|
-
const [hoverRange, onChangeHoverRange] = useState(defaultHoverRange);
|
|
664
|
-
return makeColumnRangeHoverTransform({ hoverColor, headerHoverColor, hoverRange, onChangeHoverRange });
|
|
616
|
+
const EMPTY_RANGE$1 = {
|
|
617
|
+
start: -1,
|
|
618
|
+
end: -1,
|
|
619
|
+
};
|
|
620
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
621
|
+
function makeColumnRangeHoverTransform({ hoverColor = 'var(--hover-bgcolor)', headerHoverColor = 'var(--header-hover-bgcolor)', hoverRange, onChangeHoverRange, }) {
|
|
622
|
+
warnTransformsDeprecated('makeColumnRangeHoverTransform');
|
|
623
|
+
return traverseColumn((col, { range: colRange }) => {
|
|
624
|
+
const match = colRange.end > hoverRange.start && hoverRange.end > colRange.start;
|
|
625
|
+
if (!isLeafNode(col)) {
|
|
626
|
+
if (headerHoverColor == null) {
|
|
627
|
+
return col;
|
|
628
|
+
}
|
|
629
|
+
return Object.assign(Object.assign({}, col), { headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
630
|
+
onMouseEnter() {
|
|
631
|
+
onChangeHoverRange(colRange);
|
|
632
|
+
},
|
|
633
|
+
onMouseLeave() {
|
|
634
|
+
onChangeHoverRange(EMPTY_RANGE$1);
|
|
635
|
+
},
|
|
636
|
+
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
637
|
+
}) });
|
|
638
|
+
}
|
|
639
|
+
const prevGetCellProps = col.getCellProps;
|
|
640
|
+
return Object.assign(Object.assign({}, col), { headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
641
|
+
onMouseEnter() {
|
|
642
|
+
onChangeHoverRange(colRange);
|
|
643
|
+
},
|
|
644
|
+
onMouseLeave() {
|
|
645
|
+
onChangeHoverRange(EMPTY_RANGE$1);
|
|
646
|
+
},
|
|
647
|
+
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
648
|
+
}), getCellProps(value, record, rowIndex) {
|
|
649
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
650
|
+
return mergeCellProps(prevCellProps, {
|
|
651
|
+
onMouseEnter() {
|
|
652
|
+
onChangeHoverRange(colRange);
|
|
653
|
+
},
|
|
654
|
+
onMouseLeave() {
|
|
655
|
+
onChangeHoverRange(EMPTY_RANGE$1);
|
|
656
|
+
},
|
|
657
|
+
style: { '--bgcolor': match ? hoverColor : undefined },
|
|
658
|
+
});
|
|
659
|
+
} });
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
663
|
+
function useColumnHoverRangeTransform({ hoverColor, headerHoverColor, defaultHoverRange = EMPTY_RANGE$1, } = {}) {
|
|
664
|
+
const [hoverRange, onChangeHoverRange] = useState(defaultHoverRange);
|
|
665
|
+
return makeColumnRangeHoverTransform({ hoverColor, headerHoverColor, hoverRange, onChangeHoverRange });
|
|
665
666
|
}
|
|
666
667
|
|
|
667
|
-
function clamp$1(min, x, max) {
|
|
668
|
-
return Math.max(min, Math.min(max, x));
|
|
669
|
-
}
|
|
670
|
-
const RESIZE_EXPANDER_CLS = 'resize-expander';
|
|
668
|
+
function clamp$1(min, x, max) {
|
|
669
|
+
return Math.max(min, Math.min(max, x));
|
|
670
|
+
}
|
|
671
|
+
const RESIZE_EXPANDER_CLS = 'resize-expander';
|
|
671
672
|
const ResizeHandle$1 = styled__default.span `
|
|
672
673
|
position: absolute;
|
|
673
674
|
top: 0;
|
|
@@ -676,258 +677,258 @@ const ResizeHandle$1 = styled__default.span `
|
|
|
676
677
|
width: 10px;
|
|
677
678
|
cursor: col-resize;
|
|
678
679
|
z-index: 1;
|
|
679
|
-
`;
|
|
680
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
681
|
-
function makeColumnResizeTransform({ sizes, onChangeSizes, minSize = 40, maxSize = Infinity, appendExpander, expanderVisibility = 'visible', disableUserSelectWhenResizing, }) {
|
|
682
|
-
warnTransformsDeprecated('makeColumnResizeTransform');
|
|
683
|
-
const startResize = (colIndex, e) => {
|
|
684
|
-
const startX = e.clientX;
|
|
685
|
-
const startSize = sizes[colIndex];
|
|
686
|
-
const nextSizes$ = fromEvent(window, 'mousemove').pipe(op.takeUntil(fromEvent(window, 'mouseup')), op.map((e) => {
|
|
687
|
-
const movingX = e.clientX;
|
|
688
|
-
const nextSizes = sizes.slice();
|
|
689
|
-
nextSizes[colIndex] = clamp$1(minSize, startSize + (movingX - startX), maxSize);
|
|
690
|
-
return nextSizes;
|
|
691
|
-
}));
|
|
692
|
-
let prevUserSelect = '';
|
|
693
|
-
let docElemStyle;
|
|
694
|
-
if (disableUserSelectWhenResizing) {
|
|
695
|
-
docElemStyle = document.documentElement.style;
|
|
696
|
-
prevUserSelect = docElemStyle.userSelect;
|
|
697
|
-
docElemStyle.userSelect = 'none';
|
|
698
|
-
}
|
|
699
|
-
nextSizes$.subscribe({
|
|
700
|
-
next: onChangeSizes,
|
|
701
|
-
complete() {
|
|
702
|
-
if (disableUserSelectWhenResizing) {
|
|
703
|
-
docElemStyle.userSelect = prevUserSelect;
|
|
704
|
-
}
|
|
705
|
-
},
|
|
706
|
-
});
|
|
707
|
-
};
|
|
708
|
-
const innerTransform = traverseColumn((col, { range }) => {
|
|
709
|
-
var _a;
|
|
710
|
-
if (!isLeafNode(col)) {
|
|
711
|
-
return col;
|
|
712
|
-
}
|
|
713
|
-
const prevTitle = internals.safeRenderHeader(col);
|
|
714
|
-
return Object.assign(Object.assign({}, col), { width: sizes[range.start], title: (React.createElement(React.Fragment, null,
|
|
715
|
-
prevTitle,
|
|
716
|
-
React.createElement(ResizeHandle$1, { className: "resize-handle", onMouseDown: (e) => startResize(range.start, e) }))), headerCellProps: Object.assign(Object.assign({}, col.headerCellProps), { style: Object.assign(Object.assign({}, (_a = col.headerCellProps) === null || _a === void 0 ? void 0 : _a.style), { overflow: 'visible', position: 'relative' }) }) });
|
|
717
|
-
});
|
|
718
|
-
return (input) => {
|
|
719
|
-
const { columns, dataSource } = innerTransform(input);
|
|
720
|
-
return {
|
|
721
|
-
columns: appendExpander
|
|
722
|
-
? columns.concat([
|
|
723
|
-
{
|
|
724
|
-
name: '',
|
|
725
|
-
headerCellProps: {
|
|
726
|
-
className: RESIZE_EXPANDER_CLS,
|
|
727
|
-
style: {
|
|
728
|
-
background: expanderVisibility === 'hidden' ? 'var(--bgcolor)' : undefined,
|
|
729
|
-
border: expanderVisibility === 'hidden' ? 'none' : undefined,
|
|
730
|
-
},
|
|
731
|
-
},
|
|
732
|
-
getCellProps() {
|
|
733
|
-
return {
|
|
734
|
-
className: RESIZE_EXPANDER_CLS,
|
|
735
|
-
style: { visibility: expanderVisibility },
|
|
736
|
-
};
|
|
737
|
-
},
|
|
738
|
-
},
|
|
739
|
-
])
|
|
740
|
-
: columns,
|
|
741
|
-
dataSource,
|
|
742
|
-
};
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
746
|
-
function useColumnResizeTransform(_a) {
|
|
747
|
-
var { defaultSizes } = _a, others = __rest(_a, ["defaultSizes"]);
|
|
748
|
-
const [sizes, onChangeSizes] = useState(defaultSizes);
|
|
749
|
-
return makeColumnResizeTransform(Object.assign({ sizes, onChangeSizes }, others));
|
|
680
|
+
`;
|
|
681
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
682
|
+
function makeColumnResizeTransform({ sizes, onChangeSizes, minSize = 40, maxSize = Infinity, appendExpander, expanderVisibility = 'visible', disableUserSelectWhenResizing, }) {
|
|
683
|
+
warnTransformsDeprecated('makeColumnResizeTransform');
|
|
684
|
+
const startResize = (colIndex, e) => {
|
|
685
|
+
const startX = e.clientX;
|
|
686
|
+
const startSize = sizes[colIndex];
|
|
687
|
+
const nextSizes$ = fromEvent(window, 'mousemove').pipe(op.takeUntil(fromEvent(window, 'mouseup')), op.map((e) => {
|
|
688
|
+
const movingX = e.clientX;
|
|
689
|
+
const nextSizes = sizes.slice();
|
|
690
|
+
nextSizes[colIndex] = clamp$1(minSize, startSize + (movingX - startX), maxSize);
|
|
691
|
+
return nextSizes;
|
|
692
|
+
}));
|
|
693
|
+
let prevUserSelect = '';
|
|
694
|
+
let docElemStyle;
|
|
695
|
+
if (disableUserSelectWhenResizing) {
|
|
696
|
+
docElemStyle = document.documentElement.style;
|
|
697
|
+
prevUserSelect = docElemStyle.userSelect;
|
|
698
|
+
docElemStyle.userSelect = 'none';
|
|
699
|
+
}
|
|
700
|
+
nextSizes$.subscribe({
|
|
701
|
+
next: onChangeSizes,
|
|
702
|
+
complete() {
|
|
703
|
+
if (disableUserSelectWhenResizing) {
|
|
704
|
+
docElemStyle.userSelect = prevUserSelect;
|
|
705
|
+
}
|
|
706
|
+
},
|
|
707
|
+
});
|
|
708
|
+
};
|
|
709
|
+
const innerTransform = traverseColumn((col, { range }) => {
|
|
710
|
+
var _a;
|
|
711
|
+
if (!isLeafNode(col)) {
|
|
712
|
+
return col;
|
|
713
|
+
}
|
|
714
|
+
const prevTitle = internals.safeRenderHeader(col);
|
|
715
|
+
return Object.assign(Object.assign({}, col), { width: sizes[range.start], title: (React.createElement(React.Fragment, null,
|
|
716
|
+
prevTitle,
|
|
717
|
+
React.createElement(ResizeHandle$1, { className: "resize-handle", onMouseDown: (e) => startResize(range.start, e) }))), headerCellProps: Object.assign(Object.assign({}, col.headerCellProps), { style: Object.assign(Object.assign({}, (_a = col.headerCellProps) === null || _a === void 0 ? void 0 : _a.style), { overflow: 'visible', position: 'relative' }) }) });
|
|
718
|
+
});
|
|
719
|
+
return (input) => {
|
|
720
|
+
const { columns, dataSource } = innerTransform(input);
|
|
721
|
+
return {
|
|
722
|
+
columns: appendExpander
|
|
723
|
+
? columns.concat([
|
|
724
|
+
{
|
|
725
|
+
name: '',
|
|
726
|
+
headerCellProps: {
|
|
727
|
+
className: RESIZE_EXPANDER_CLS,
|
|
728
|
+
style: {
|
|
729
|
+
background: expanderVisibility === 'hidden' ? 'var(--bgcolor)' : undefined,
|
|
730
|
+
border: expanderVisibility === 'hidden' ? 'none' : undefined,
|
|
731
|
+
},
|
|
732
|
+
},
|
|
733
|
+
getCellProps() {
|
|
734
|
+
return {
|
|
735
|
+
className: RESIZE_EXPANDER_CLS,
|
|
736
|
+
style: { visibility: expanderVisibility },
|
|
737
|
+
};
|
|
738
|
+
},
|
|
739
|
+
},
|
|
740
|
+
])
|
|
741
|
+
: columns,
|
|
742
|
+
dataSource,
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
747
|
+
function useColumnResizeTransform(_a) {
|
|
748
|
+
var { defaultSizes } = _a, others = __rest(_a, ["defaultSizes"]);
|
|
749
|
+
const [sizes, onChangeSizes] = useState(defaultSizes);
|
|
750
|
+
return makeColumnResizeTransform(Object.assign({ sizes, onChangeSizes }, others));
|
|
750
751
|
}
|
|
751
752
|
|
|
752
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
753
|
-
function makeFlattenTransform() {
|
|
754
|
-
warnTransformsDeprecated('makeFlattenTransform');
|
|
755
|
-
return traverseColumn((column) => {
|
|
756
|
-
var _a;
|
|
757
|
-
if (isLeafNode(column)) {
|
|
758
|
-
return column;
|
|
759
|
-
}
|
|
760
|
-
return ((_a = column.features) === null || _a === void 0 ? void 0 : _a.flatten) ? column.children : column;
|
|
761
|
-
});
|
|
753
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
754
|
+
function makeFlattenTransform() {
|
|
755
|
+
warnTransformsDeprecated('makeFlattenTransform');
|
|
756
|
+
return traverseColumn((column) => {
|
|
757
|
+
var _a;
|
|
758
|
+
if (isLeafNode(column)) {
|
|
759
|
+
return column;
|
|
760
|
+
}
|
|
761
|
+
return ((_a = column.features) === null || _a === void 0 ? void 0 : _a.flatten) ? column.children : column;
|
|
762
|
+
});
|
|
762
763
|
}
|
|
763
764
|
|
|
764
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
765
|
-
function makeOrderFieldTransform(startOrder = 1) {
|
|
766
|
-
warnTransformsDeprecated('makeOrderFieldTransform');
|
|
767
|
-
return traverseColumn((column) => {
|
|
768
|
-
var _a, _b;
|
|
769
|
-
if (((_a = column.features) === null || _a === void 0 ? void 0 : _a.order) || ((_b = column.features) === null || _b === void 0 ? void 0 : _b.orderField)) {
|
|
770
|
-
return Object.assign(Object.assign({}, column), { getValue(record, index) {
|
|
771
|
-
return index + startOrder;
|
|
772
|
-
} });
|
|
773
|
-
}
|
|
774
|
-
return column;
|
|
775
|
-
});
|
|
765
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
766
|
+
function makeOrderFieldTransform(startOrder = 1) {
|
|
767
|
+
warnTransformsDeprecated('makeOrderFieldTransform');
|
|
768
|
+
return traverseColumn((column) => {
|
|
769
|
+
var _a, _b;
|
|
770
|
+
if (((_a = column.features) === null || _a === void 0 ? void 0 : _a.order) || ((_b = column.features) === null || _b === void 0 ? void 0 : _b.orderField)) {
|
|
771
|
+
return Object.assign(Object.assign({}, column), { getValue(record, index) {
|
|
772
|
+
return index + startOrder;
|
|
773
|
+
} });
|
|
774
|
+
}
|
|
775
|
+
return column;
|
|
776
|
+
});
|
|
776
777
|
}
|
|
777
778
|
|
|
778
|
-
function SortIcon$1({ size = 32, style, className, order, }) {
|
|
779
|
-
return (React.createElement("svg", { style: style, className: className, focusable: "false", preserveAspectRatio: "xMidYMid meet", width: size, height: size, viewBox: "0 0 32 32", "aria-hidden": "true" },
|
|
780
|
-
React.createElement("path", { fill: order === 'asc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, 4)", d: "M8 8L16 0 24 8z" }),
|
|
781
|
-
React.createElement("path", { fill: order === 'desc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, -4)", d: "M24 24L16 32 8 24z " })));
|
|
782
|
-
}
|
|
783
|
-
function DefaultSortHeaderCell$1({ children, column, onToggle, sortOrder, sortIndex, sortOptions }) {
|
|
784
|
-
// 通过 justify-content 来与 col.align 保持对齐方向一致
|
|
785
|
-
const justifyContent = column.align === 'right' ? 'flex-end' : column.align === 'center' ? 'center' : 'flex-start';
|
|
786
|
-
return (React.createElement(TableHeaderCell$1, { onClick: onToggle, style: { justifyContent } },
|
|
787
|
-
children,
|
|
788
|
-
React.createElement(SortIcon$1, { style: { userSelect: 'none', marginLeft: 2, flexShrink: 0 }, size: 16, order: sortOrder }),
|
|
789
|
-
sortOptions.mode === 'multiple' && sortIndex != -1 && (React.createElement("div", { style: {
|
|
790
|
-
userSelect: 'none',
|
|
791
|
-
marginLeft: 2,
|
|
792
|
-
color: '#666',
|
|
793
|
-
flex: '0 0 auto',
|
|
794
|
-
fontSize: 10,
|
|
795
|
-
fontFamily: 'monospace',
|
|
796
|
-
} }, sortIndex + 1))));
|
|
797
|
-
}
|
|
798
|
-
function hasAnySortableColumns$1(cols) {
|
|
799
|
-
return cols.some((col) => { var _a; return Boolean((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) || (!isLeafNode(col) && hasAnySortableColumns$1(col.children)); });
|
|
800
|
-
}
|
|
779
|
+
function SortIcon$1({ size = 32, style, className, order, }) {
|
|
780
|
+
return (React.createElement("svg", { style: style, className: className, focusable: "false", preserveAspectRatio: "xMidYMid meet", width: size, height: size, viewBox: "0 0 32 32", "aria-hidden": "true" },
|
|
781
|
+
React.createElement("path", { fill: order === 'asc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, 4)", d: "M8 8L16 0 24 8z" }),
|
|
782
|
+
React.createElement("path", { fill: order === 'desc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, -4)", d: "M24 24L16 32 8 24z " })));
|
|
783
|
+
}
|
|
784
|
+
function DefaultSortHeaderCell$1({ children, column, onToggle, sortOrder, sortIndex, sortOptions }) {
|
|
785
|
+
// 通过 justify-content 来与 col.align 保持对齐方向一致
|
|
786
|
+
const justifyContent = column.align === 'right' ? 'flex-end' : column.align === 'center' ? 'center' : 'flex-start';
|
|
787
|
+
return (React.createElement(TableHeaderCell$1, { onClick: onToggle, style: { justifyContent } },
|
|
788
|
+
children,
|
|
789
|
+
React.createElement(SortIcon$1, { style: { userSelect: 'none', marginLeft: 2, flexShrink: 0 }, size: 16, order: sortOrder }),
|
|
790
|
+
sortOptions.mode === 'multiple' && sortIndex != -1 && (React.createElement("div", { style: {
|
|
791
|
+
userSelect: 'none',
|
|
792
|
+
marginLeft: 2,
|
|
793
|
+
color: '#666',
|
|
794
|
+
flex: '0 0 auto',
|
|
795
|
+
fontSize: 10,
|
|
796
|
+
fontFamily: 'monospace',
|
|
797
|
+
} }, sortIndex + 1))));
|
|
798
|
+
}
|
|
799
|
+
function hasAnySortableColumns$1(cols) {
|
|
800
|
+
return cols.some((col) => { var _a; return Boolean((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) || (!isLeafNode(col) && hasAnySortableColumns$1(col.children)); });
|
|
801
|
+
}
|
|
801
802
|
const TableHeaderCell$1 = styled__default.div `
|
|
802
803
|
cursor: pointer;
|
|
803
804
|
display: flex;
|
|
804
805
|
align-items: center;
|
|
805
|
-
`;
|
|
806
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
807
|
-
function makeSortTransform({ sorts: inputSorts, onChangeSorts: inputOnChangeSorts, orders = ['desc', 'asc', 'none'], mode = 'multiple', SortHeaderCell = DefaultSortHeaderCell$1, keepDataSource, highlightColumnWhenActive, stopClickEventPropagation, }) {
|
|
808
|
-
warnTransformsDeprecated('makeSortTransform');
|
|
809
|
-
const filteredInputSorts = inputSorts.filter((s) => s.order !== 'none');
|
|
810
|
-
// 单字段排序的情况下 sorts 中只有第一个排序字段才会生效
|
|
811
|
-
const sorts = mode === 'multiple' ? filteredInputSorts : filteredInputSorts.slice(0, 1);
|
|
812
|
-
const onChangeSorts = mode === 'multiple'
|
|
813
|
-
? inputOnChangeSorts
|
|
814
|
-
: (nextSorts) => {
|
|
815
|
-
// 单字段排序的情况下,nextSorts 中只有最后一个排序字段才会生效
|
|
816
|
-
const len = nextSorts.length;
|
|
817
|
-
inputOnChangeSorts(nextSorts.slice(len - 1));
|
|
818
|
-
};
|
|
819
|
-
const sortOptions = {
|
|
820
|
-
sorts,
|
|
821
|
-
onChangeSorts,
|
|
822
|
-
orders,
|
|
823
|
-
mode,
|
|
824
|
-
keepDataSource,
|
|
825
|
-
highlightColumnWhenActive,
|
|
826
|
-
stopClickEventPropagation,
|
|
827
|
-
};
|
|
828
|
-
const sortMap = new Map(sorts.map((sort, index) => [sort.code, Object.assign({ index }, sort)]));
|
|
829
|
-
return ({ dataSource, columns }) => {
|
|
830
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
831
|
-
if (!hasAnySortableColumns$1(columns)) {
|
|
832
|
-
console.warn('[srp-table] commonTransform.sort 缺少可排序的列,请通过 column.features.sortable 来指定哪些列可排序', columns);
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
return { columns: processColumns(columns), dataSource: processDataSource(dataSource) };
|
|
836
|
-
function processDataSource(dataSource) {
|
|
837
|
-
if (keepDataSource) {
|
|
838
|
-
return dataSource;
|
|
839
|
-
}
|
|
840
|
-
const sortColumnsMap = new Map(collectNodes(columns, 'leaf-only')
|
|
841
|
-
.filter((col) => { var _a; return ((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) != null; })
|
|
842
|
-
.map((col) => [col.code, col]));
|
|
843
|
-
return layeredSort(dataSource, (x, y) => {
|
|
844
|
-
for (const { code, order } of sorts) {
|
|
845
|
-
const column = sortColumnsMap.get(code);
|
|
846
|
-
// 如果 code 对应的 column 不可排序,我们跳过该 code
|
|
847
|
-
if (column == null) {
|
|
848
|
-
continue;
|
|
849
|
-
}
|
|
850
|
-
const sortable = column.features.sortable;
|
|
851
|
-
const compareFn = typeof sortable === 'function' ? sortable : smartCompare;
|
|
852
|
-
const xValue = internals.safeGetValue(column, x, -1);
|
|
853
|
-
const yValue = internals.safeGetValue(column, y, -1);
|
|
854
|
-
const cmp = compareFn(xValue, yValue);
|
|
855
|
-
if (cmp !== 0) {
|
|
856
|
-
return cmp * (order === 'asc' ? 1 : -1);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
return 0;
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
// 在「升序 - 降序 - 不排序」之间不断切换
|
|
863
|
-
function toggle(code) {
|
|
864
|
-
const sort = sortMap.get(code);
|
|
865
|
-
if (sort == null) {
|
|
866
|
-
onChangeSorts(sorts.concat([{ code, order: orders[0] }]));
|
|
867
|
-
}
|
|
868
|
-
else {
|
|
869
|
-
const index = sorts.findIndex((s) => s.code === code);
|
|
870
|
-
const nextSorts = sorts.slice(0, index + 1);
|
|
871
|
-
const nextOrder = getNextOrder(sort.order);
|
|
872
|
-
if (nextOrder === 'none') {
|
|
873
|
-
nextSorts.pop();
|
|
874
|
-
}
|
|
875
|
-
else {
|
|
876
|
-
nextSorts[index] = Object.assign(Object.assign({}, nextSorts[index]), { order: nextOrder });
|
|
877
|
-
}
|
|
878
|
-
onChangeSorts(nextSorts);
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
function processColumns(columns) {
|
|
882
|
-
return columns.map(dfs);
|
|
883
|
-
function dfs(col) {
|
|
884
|
-
var _a;
|
|
885
|
-
const result = Object.assign({}, col);
|
|
886
|
-
const sortable = col.code && (((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) || sortMap.has(col.code));
|
|
887
|
-
const active = sortable && sortMap.has(col.code);
|
|
888
|
-
if (sortable) {
|
|
889
|
-
let sortIndex = -1;
|
|
890
|
-
let sortOrder = 'none';
|
|
891
|
-
if (active) {
|
|
892
|
-
const { order, index } = sortMap.get(col.code);
|
|
893
|
-
sortOrder = order;
|
|
894
|
-
sortIndex = index;
|
|
895
|
-
if (highlightColumnWhenActive) {
|
|
896
|
-
result.headerCellProps = mergeCellProps(col.headerCellProps, {
|
|
897
|
-
style: { background: 'var(--header-highlight-bgcolor)' },
|
|
898
|
-
});
|
|
899
|
-
result.getCellProps = (value, row, rowIndex) => {
|
|
900
|
-
const prevCellProps = internals.safeGetCellProps(col, row, rowIndex);
|
|
901
|
-
return mergeCellProps(prevCellProps, {
|
|
902
|
-
style: { background: 'var(--highlight-bgcolor)' },
|
|
903
|
-
});
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
result.title = (React.createElement(SortHeaderCell, { onToggle: (e) => {
|
|
908
|
-
if (stopClickEventPropagation) {
|
|
909
|
-
e.stopPropagation();
|
|
910
|
-
}
|
|
911
|
-
toggle(col.code);
|
|
912
|
-
}, sortOrder: sortOrder, column: col, sortIndex: sortIndex, sortOptions: sortOptions }, internals.safeRenderHeader(col)));
|
|
913
|
-
}
|
|
914
|
-
if (!isLeafNode(col)) {
|
|
915
|
-
result.children = col.children.map(dfs);
|
|
916
|
-
}
|
|
917
|
-
return result;
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
};
|
|
921
|
-
function getNextOrder(order) {
|
|
922
|
-
const idx = orders.indexOf(order);
|
|
923
|
-
return orders[idx === orders.length - 1 ? 0 : idx + 1];
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
927
|
-
function useSortTransform(_a = {}) {
|
|
928
|
-
var { defaultSorts = [] } = _a, others = __rest(_a, ["defaultSorts"]);
|
|
929
|
-
const [sorts, onChangeSorts] = useState(defaultSorts);
|
|
930
|
-
return makeSortTransform(Object.assign({ sorts, onChangeSorts }, others));
|
|
806
|
+
`;
|
|
807
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
808
|
+
function makeSortTransform({ sorts: inputSorts, onChangeSorts: inputOnChangeSorts, orders = ['desc', 'asc', 'none'], mode = 'multiple', SortHeaderCell = DefaultSortHeaderCell$1, keepDataSource, highlightColumnWhenActive, stopClickEventPropagation, }) {
|
|
809
|
+
warnTransformsDeprecated('makeSortTransform');
|
|
810
|
+
const filteredInputSorts = inputSorts.filter((s) => s.order !== 'none');
|
|
811
|
+
// 单字段排序的情况下 sorts 中只有第一个排序字段才会生效
|
|
812
|
+
const sorts = mode === 'multiple' ? filteredInputSorts : filteredInputSorts.slice(0, 1);
|
|
813
|
+
const onChangeSorts = mode === 'multiple'
|
|
814
|
+
? inputOnChangeSorts
|
|
815
|
+
: (nextSorts) => {
|
|
816
|
+
// 单字段排序的情况下,nextSorts 中只有最后一个排序字段才会生效
|
|
817
|
+
const len = nextSorts.length;
|
|
818
|
+
inputOnChangeSorts(nextSorts.slice(len - 1));
|
|
819
|
+
};
|
|
820
|
+
const sortOptions = {
|
|
821
|
+
sorts,
|
|
822
|
+
onChangeSorts,
|
|
823
|
+
orders,
|
|
824
|
+
mode,
|
|
825
|
+
keepDataSource,
|
|
826
|
+
highlightColumnWhenActive,
|
|
827
|
+
stopClickEventPropagation,
|
|
828
|
+
};
|
|
829
|
+
const sortMap = new Map(sorts.map((sort, index) => [sort.code, Object.assign({ index }, sort)]));
|
|
830
|
+
return ({ dataSource, columns }) => {
|
|
831
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
832
|
+
if (!hasAnySortableColumns$1(columns)) {
|
|
833
|
+
console.warn('[srp-table] commonTransform.sort 缺少可排序的列,请通过 column.features.sortable 来指定哪些列可排序', columns);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
return { columns: processColumns(columns), dataSource: processDataSource(dataSource) };
|
|
837
|
+
function processDataSource(dataSource) {
|
|
838
|
+
if (keepDataSource) {
|
|
839
|
+
return dataSource;
|
|
840
|
+
}
|
|
841
|
+
const sortColumnsMap = new Map(collectNodes(columns, 'leaf-only')
|
|
842
|
+
.filter((col) => { var _a; return ((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) != null; })
|
|
843
|
+
.map((col) => [col.code, col]));
|
|
844
|
+
return layeredSort(dataSource, (x, y) => {
|
|
845
|
+
for (const { code, order } of sorts) {
|
|
846
|
+
const column = sortColumnsMap.get(code);
|
|
847
|
+
// 如果 code 对应的 column 不可排序,我们跳过该 code
|
|
848
|
+
if (column == null) {
|
|
849
|
+
continue;
|
|
850
|
+
}
|
|
851
|
+
const sortable = column.features.sortable;
|
|
852
|
+
const compareFn = typeof sortable === 'function' ? sortable : smartCompare;
|
|
853
|
+
const xValue = internals.safeGetValue(column, x, -1);
|
|
854
|
+
const yValue = internals.safeGetValue(column, y, -1);
|
|
855
|
+
const cmp = compareFn(xValue, yValue);
|
|
856
|
+
if (cmp !== 0) {
|
|
857
|
+
return cmp * (order === 'asc' ? 1 : -1);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
return 0;
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
// 在「升序 - 降序 - 不排序」之间不断切换
|
|
864
|
+
function toggle(code) {
|
|
865
|
+
const sort = sortMap.get(code);
|
|
866
|
+
if (sort == null) {
|
|
867
|
+
onChangeSorts(sorts.concat([{ code, order: orders[0] }]));
|
|
868
|
+
}
|
|
869
|
+
else {
|
|
870
|
+
const index = sorts.findIndex((s) => s.code === code);
|
|
871
|
+
const nextSorts = sorts.slice(0, index + 1);
|
|
872
|
+
const nextOrder = getNextOrder(sort.order);
|
|
873
|
+
if (nextOrder === 'none') {
|
|
874
|
+
nextSorts.pop();
|
|
875
|
+
}
|
|
876
|
+
else {
|
|
877
|
+
nextSorts[index] = Object.assign(Object.assign({}, nextSorts[index]), { order: nextOrder });
|
|
878
|
+
}
|
|
879
|
+
onChangeSorts(nextSorts);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
function processColumns(columns) {
|
|
883
|
+
return columns.map(dfs);
|
|
884
|
+
function dfs(col) {
|
|
885
|
+
var _a;
|
|
886
|
+
const result = Object.assign({}, col);
|
|
887
|
+
const sortable = col.code && (((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) || sortMap.has(col.code));
|
|
888
|
+
const active = sortable && sortMap.has(col.code);
|
|
889
|
+
if (sortable) {
|
|
890
|
+
let sortIndex = -1;
|
|
891
|
+
let sortOrder = 'none';
|
|
892
|
+
if (active) {
|
|
893
|
+
const { order, index } = sortMap.get(col.code);
|
|
894
|
+
sortOrder = order;
|
|
895
|
+
sortIndex = index;
|
|
896
|
+
if (highlightColumnWhenActive) {
|
|
897
|
+
result.headerCellProps = mergeCellProps(col.headerCellProps, {
|
|
898
|
+
style: { background: 'var(--header-highlight-bgcolor)' },
|
|
899
|
+
});
|
|
900
|
+
result.getCellProps = (value, row, rowIndex) => {
|
|
901
|
+
const prevCellProps = internals.safeGetCellProps(col, row, rowIndex);
|
|
902
|
+
return mergeCellProps(prevCellProps, {
|
|
903
|
+
style: { background: 'var(--highlight-bgcolor)' },
|
|
904
|
+
});
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
result.title = (React.createElement(SortHeaderCell, { onToggle: (e) => {
|
|
909
|
+
if (stopClickEventPropagation) {
|
|
910
|
+
e.stopPropagation();
|
|
911
|
+
}
|
|
912
|
+
toggle(col.code);
|
|
913
|
+
}, sortOrder: sortOrder, column: col, sortIndex: sortIndex, sortOptions: sortOptions }, internals.safeRenderHeader(col)));
|
|
914
|
+
}
|
|
915
|
+
if (!isLeafNode(col)) {
|
|
916
|
+
result.children = col.children.map(dfs);
|
|
917
|
+
}
|
|
918
|
+
return result;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
function getNextOrder(order) {
|
|
923
|
+
const idx = orders.indexOf(order);
|
|
924
|
+
return orders[idx === orders.length - 1 ? 0 : idx + 1];
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
928
|
+
function useSortTransform(_a = {}) {
|
|
929
|
+
var { defaultSorts = [] } = _a, others = __rest(_a, ["defaultSorts"]);
|
|
930
|
+
const [sorts, onChangeSorts] = useState(defaultSorts);
|
|
931
|
+
return makeSortTransform(Object.assign({ sorts, onChangeSorts }, others));
|
|
931
932
|
}
|
|
932
933
|
|
|
933
934
|
const HeaderCellWithTips$1 = styled__default.div `
|
|
@@ -942,181 +943,181 @@ const HeaderCellWithTips$1 = styled__default.div `
|
|
|
942
943
|
display: flex;
|
|
943
944
|
fill: currentColor;
|
|
944
945
|
}
|
|
945
|
-
`;
|
|
946
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
947
|
-
function makeTipsTransform({ Balloon, Tooltip }) {
|
|
948
|
-
warnTransformsDeprecated('makeTipsTransform');
|
|
949
|
-
return traverseColumn((col) => {
|
|
950
|
-
var _a;
|
|
951
|
-
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.tips)) {
|
|
952
|
-
return col;
|
|
953
|
-
}
|
|
954
|
-
const justifyContent = col.align === 'right' ? 'flex-end' : col.align === 'center' ? 'center' : 'flex-start';
|
|
955
|
-
return Object.assign(Object.assign({}, col), { title: (React.createElement(HeaderCellWithTips$1, { style: { justifyContent } },
|
|
956
|
-
internals.safeRenderHeader(col),
|
|
957
|
-
Balloon ? (
|
|
958
|
-
// fusion/hippo
|
|
959
|
-
React.createElement(Balloon, { closable: false, trigger: React.createElement("div", { className: "tip-icon-wrapper" },
|
|
960
|
-
React.createElement(icons.Info, { className: "tip-icon" })) }, col.features.tips)) : (
|
|
961
|
-
// antd
|
|
962
|
-
React.createElement(Tooltip, { title: col.features.tips },
|
|
963
|
-
React.createElement("div", { className: "tip-icon-wrapper" },
|
|
964
|
-
React.createElement(icons.Info, { className: "tip-icon" })))))) });
|
|
965
|
-
});
|
|
946
|
+
`;
|
|
947
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
948
|
+
function makeTipsTransform({ Balloon, Tooltip }) {
|
|
949
|
+
warnTransformsDeprecated('makeTipsTransform');
|
|
950
|
+
return traverseColumn((col) => {
|
|
951
|
+
var _a;
|
|
952
|
+
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.tips)) {
|
|
953
|
+
return col;
|
|
954
|
+
}
|
|
955
|
+
const justifyContent = col.align === 'right' ? 'flex-end' : col.align === 'center' ? 'center' : 'flex-start';
|
|
956
|
+
return Object.assign(Object.assign({}, col), { title: (React.createElement(HeaderCellWithTips$1, { style: { justifyContent } },
|
|
957
|
+
internals.safeRenderHeader(col),
|
|
958
|
+
Balloon ? (
|
|
959
|
+
// fusion/hippo
|
|
960
|
+
React.createElement(Balloon, { closable: false, trigger: React.createElement("div", { className: "tip-icon-wrapper" },
|
|
961
|
+
React.createElement(icons.Info, { className: "tip-icon" })) }, col.features.tips)) : (
|
|
962
|
+
// antd
|
|
963
|
+
React.createElement(Tooltip, { title: col.features.tips },
|
|
964
|
+
React.createElement("div", { className: "tip-icon-wrapper" },
|
|
965
|
+
React.createElement(icons.Info, { className: "tip-icon" })))))) });
|
|
966
|
+
});
|
|
966
967
|
}
|
|
967
968
|
|
|
968
|
-
function isIdentity(x, y) {
|
|
969
|
-
return x === y;
|
|
970
|
-
}
|
|
971
|
-
function autoRowSpan() {
|
|
972
|
-
return function autoRowSpanStep(pipeline) {
|
|
973
|
-
const dataSource = pipeline.getDataSource();
|
|
974
|
-
return pipeline.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
975
|
-
var _a;
|
|
976
|
-
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.autoRowSpan)) {
|
|
977
|
-
return col;
|
|
978
|
-
}
|
|
979
|
-
if (!isLeafNode(col)) {
|
|
980
|
-
return col;
|
|
981
|
-
}
|
|
982
|
-
const isFunc = typeof col.features.autoRowSpan === 'function';
|
|
983
|
-
const shouldMergeCell = isFunc ? col.features.autoRowSpan : isIdentity;
|
|
984
|
-
const spanRects = [];
|
|
985
|
-
let lastBottom = 0;
|
|
986
|
-
let prevValue = null;
|
|
987
|
-
let prevRow = null;
|
|
988
|
-
for (let rowIndex = 0; rowIndex < dataSource.length; rowIndex++) {
|
|
989
|
-
const row = dataSource[rowIndex];
|
|
990
|
-
const value = internals.safeGetValue(col, row, rowIndex);
|
|
991
|
-
if (rowIndex === 0 || !shouldMergeCell(prevValue, value, prevRow, row)) {
|
|
992
|
-
const spanRect = {
|
|
993
|
-
top: lastBottom,
|
|
994
|
-
bottom: rowIndex,
|
|
995
|
-
left: startIndex,
|
|
996
|
-
right: endIndex,
|
|
997
|
-
};
|
|
998
|
-
for (let i = lastBottom; i < rowIndex; i++) {
|
|
999
|
-
spanRects.push(spanRect);
|
|
1000
|
-
}
|
|
1001
|
-
lastBottom = rowIndex;
|
|
1002
|
-
}
|
|
1003
|
-
prevValue = value;
|
|
1004
|
-
prevRow = row;
|
|
1005
|
-
}
|
|
1006
|
-
for (let i = lastBottom; i < dataSource.length; i++) {
|
|
1007
|
-
spanRects.push({
|
|
1008
|
-
top: lastBottom,
|
|
1009
|
-
bottom: dataSource.length,
|
|
1010
|
-
left: startIndex,
|
|
1011
|
-
right: endIndex,
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
return Object.assign(Object.assign({}, col), { getSpanRect(value, row, rowIndex) {
|
|
1015
|
-
return spanRects[rowIndex];
|
|
1016
|
-
} });
|
|
1017
|
-
}));
|
|
1018
|
-
};
|
|
969
|
+
function isIdentity(x, y) {
|
|
970
|
+
return x === y;
|
|
971
|
+
}
|
|
972
|
+
function autoRowSpan() {
|
|
973
|
+
return function autoRowSpanStep(pipeline) {
|
|
974
|
+
const dataSource = pipeline.getDataSource();
|
|
975
|
+
return pipeline.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
976
|
+
var _a;
|
|
977
|
+
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.autoRowSpan)) {
|
|
978
|
+
return col;
|
|
979
|
+
}
|
|
980
|
+
if (!isLeafNode(col)) {
|
|
981
|
+
return col;
|
|
982
|
+
}
|
|
983
|
+
const isFunc = typeof col.features.autoRowSpan === 'function';
|
|
984
|
+
const shouldMergeCell = isFunc ? col.features.autoRowSpan : isIdentity;
|
|
985
|
+
const spanRects = [];
|
|
986
|
+
let lastBottom = 0;
|
|
987
|
+
let prevValue = null;
|
|
988
|
+
let prevRow = null;
|
|
989
|
+
for (let rowIndex = 0; rowIndex < dataSource.length; rowIndex++) {
|
|
990
|
+
const row = dataSource[rowIndex];
|
|
991
|
+
const value = internals.safeGetValue(col, row, rowIndex);
|
|
992
|
+
if (rowIndex === 0 || !shouldMergeCell(prevValue, value, prevRow, row)) {
|
|
993
|
+
const spanRect = {
|
|
994
|
+
top: lastBottom,
|
|
995
|
+
bottom: rowIndex,
|
|
996
|
+
left: startIndex,
|
|
997
|
+
right: endIndex,
|
|
998
|
+
};
|
|
999
|
+
for (let i = lastBottom; i < rowIndex; i++) {
|
|
1000
|
+
spanRects.push(spanRect);
|
|
1001
|
+
}
|
|
1002
|
+
lastBottom = rowIndex;
|
|
1003
|
+
}
|
|
1004
|
+
prevValue = value;
|
|
1005
|
+
prevRow = row;
|
|
1006
|
+
}
|
|
1007
|
+
for (let i = lastBottom; i < dataSource.length; i++) {
|
|
1008
|
+
spanRects.push({
|
|
1009
|
+
top: lastBottom,
|
|
1010
|
+
bottom: dataSource.length,
|
|
1011
|
+
left: startIndex,
|
|
1012
|
+
right: endIndex,
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
return Object.assign(Object.assign({}, col), { getSpanRect(value, row, rowIndex) {
|
|
1016
|
+
return spanRects[rowIndex];
|
|
1017
|
+
} });
|
|
1018
|
+
}));
|
|
1019
|
+
};
|
|
1019
1020
|
}
|
|
1020
1021
|
|
|
1021
|
-
function buildTree(idProp, parentIdProp) {
|
|
1022
|
-
return (pipeline) => pipeline.mapDataSource((rows) => buildTree$1(idProp, parentIdProp, rows));
|
|
1022
|
+
function buildTree(idProp, parentIdProp) {
|
|
1023
|
+
return (pipeline) => pipeline.mapDataSource((rows) => buildTree$1(idProp, parentIdProp, rows));
|
|
1023
1024
|
}
|
|
1024
1025
|
|
|
1025
|
-
function columnHover(opts = {}) {
|
|
1026
|
-
const stateKey = 'columnHover';
|
|
1027
|
-
return (pipeline) => {
|
|
1028
|
-
var _a, _b, _c, _d;
|
|
1029
|
-
const hoverColor = (_a = opts.hoverColor) !== null && _a !== void 0 ? _a : 'var(--hover-bgcolor)';
|
|
1030
|
-
const hoverColIndex = (_d = (_c = (_b = opts.hoverColIndex) !== null && _b !== void 0 ? _b : pipeline.getStateAtKey(stateKey)) !== null && _c !== void 0 ? _c : opts.defaultHoverColIndex) !== null && _d !== void 0 ? _d : -1;
|
|
1031
|
-
const onChangeHoverColIndex = (nextColIndex) => {
|
|
1032
|
-
var _a;
|
|
1033
|
-
pipeline.setStateAtKey(stateKey, nextColIndex);
|
|
1034
|
-
(_a = opts.onChangeHoverColIndex) === null || _a === void 0 ? void 0 : _a.call(opts, nextColIndex);
|
|
1035
|
-
};
|
|
1036
|
-
return pipeline.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1037
|
-
const range = { start: startIndex, end: endIndex };
|
|
1038
|
-
if (!isLeafNode(col)) {
|
|
1039
|
-
return col;
|
|
1040
|
-
}
|
|
1041
|
-
const colIndexMatched = range.start <= hoverColIndex && hoverColIndex < range.end;
|
|
1042
|
-
const prevGetCellProps = col.getCellProps;
|
|
1043
|
-
return Object.assign(Object.assign({}, col), { getCellProps(value, record, rowIndex) {
|
|
1044
|
-
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1045
|
-
return mergeCellProps(prevCellProps, {
|
|
1046
|
-
style: { '--bgcolor': colIndexMatched ? hoverColor : undefined },
|
|
1047
|
-
onMouseEnter() {
|
|
1048
|
-
onChangeHoverColIndex(range.start);
|
|
1049
|
-
},
|
|
1050
|
-
onMouseLeave() {
|
|
1051
|
-
onChangeHoverColIndex(-1);
|
|
1052
|
-
},
|
|
1053
|
-
});
|
|
1054
|
-
} });
|
|
1055
|
-
}));
|
|
1056
|
-
};
|
|
1026
|
+
function columnHover(opts = {}) {
|
|
1027
|
+
const stateKey = 'columnHover';
|
|
1028
|
+
return (pipeline) => {
|
|
1029
|
+
var _a, _b, _c, _d;
|
|
1030
|
+
const hoverColor = (_a = opts.hoverColor) !== null && _a !== void 0 ? _a : 'var(--hover-bgcolor)';
|
|
1031
|
+
const hoverColIndex = (_d = (_c = (_b = opts.hoverColIndex) !== null && _b !== void 0 ? _b : pipeline.getStateAtKey(stateKey)) !== null && _c !== void 0 ? _c : opts.defaultHoverColIndex) !== null && _d !== void 0 ? _d : -1;
|
|
1032
|
+
const onChangeHoverColIndex = (nextColIndex) => {
|
|
1033
|
+
var _a;
|
|
1034
|
+
pipeline.setStateAtKey(stateKey, nextColIndex);
|
|
1035
|
+
(_a = opts.onChangeHoverColIndex) === null || _a === void 0 ? void 0 : _a.call(opts, nextColIndex);
|
|
1036
|
+
};
|
|
1037
|
+
return pipeline.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1038
|
+
const range = { start: startIndex, end: endIndex };
|
|
1039
|
+
if (!isLeafNode(col)) {
|
|
1040
|
+
return col;
|
|
1041
|
+
}
|
|
1042
|
+
const colIndexMatched = range.start <= hoverColIndex && hoverColIndex < range.end;
|
|
1043
|
+
const prevGetCellProps = col.getCellProps;
|
|
1044
|
+
return Object.assign(Object.assign({}, col), { getCellProps(value, record, rowIndex) {
|
|
1045
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1046
|
+
return mergeCellProps(prevCellProps, {
|
|
1047
|
+
style: { '--bgcolor': colIndexMatched ? hoverColor : undefined },
|
|
1048
|
+
onMouseEnter() {
|
|
1049
|
+
onChangeHoverColIndex(range.start);
|
|
1050
|
+
},
|
|
1051
|
+
onMouseLeave() {
|
|
1052
|
+
onChangeHoverColIndex(-1);
|
|
1053
|
+
},
|
|
1054
|
+
});
|
|
1055
|
+
} });
|
|
1056
|
+
}));
|
|
1057
|
+
};
|
|
1057
1058
|
}
|
|
1058
1059
|
|
|
1059
|
-
const EMPTY_RANGE = {
|
|
1060
|
-
start: -1,
|
|
1061
|
-
end: -1,
|
|
1062
|
-
};
|
|
1063
|
-
function columnRangeHover(opts = {}) {
|
|
1064
|
-
const stateKey = 'columnHover';
|
|
1065
|
-
return function columnRangeHoverStep(pipeline) {
|
|
1066
|
-
var _a, _b, _c, _d, _e;
|
|
1067
|
-
const hoverRange = (_c = (_b = (_a = opts.hoverRange) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : opts.defaultHoverRange) !== null && _c !== void 0 ? _c : EMPTY_RANGE;
|
|
1068
|
-
const hoverColor = (_d = opts.hoverColor) !== null && _d !== void 0 ? _d : 'var(--hover-bgcolor)';
|
|
1069
|
-
const headerHoverColor = (_e = opts.headerHoverColor) !== null && _e !== void 0 ? _e : 'var(--header-hover-bgcolor)';
|
|
1070
|
-
const onChangeHoverRange = (nextColIndexRange) => {
|
|
1071
|
-
var _a;
|
|
1072
|
-
pipeline.setStateAtKey(stateKey, nextColIndexRange);
|
|
1073
|
-
(_a = opts.onChangeHoverRange) === null || _a === void 0 ? void 0 : _a.call(opts, nextColIndexRange);
|
|
1074
|
-
};
|
|
1075
|
-
return pipeline.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1076
|
-
const colRange = { start: startIndex, end: endIndex };
|
|
1077
|
-
const match = colRange.end > hoverRange.start && hoverRange.end > colRange.start;
|
|
1078
|
-
if (!isLeafNode(col)) {
|
|
1079
|
-
if (headerHoverColor == null) {
|
|
1080
|
-
return col;
|
|
1081
|
-
}
|
|
1082
|
-
return Object.assign(Object.assign({}, col), { headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
1083
|
-
onMouseEnter() {
|
|
1084
|
-
onChangeHoverRange(colRange);
|
|
1085
|
-
},
|
|
1086
|
-
onMouseLeave() {
|
|
1087
|
-
onChangeHoverRange(EMPTY_RANGE);
|
|
1088
|
-
},
|
|
1089
|
-
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
1090
|
-
}) });
|
|
1091
|
-
}
|
|
1092
|
-
const prevGetCellProps = col.getCellProps;
|
|
1093
|
-
return Object.assign(Object.assign({}, col), { headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
1094
|
-
onMouseEnter() {
|
|
1095
|
-
onChangeHoverRange(colRange);
|
|
1096
|
-
},
|
|
1097
|
-
onMouseLeave() {
|
|
1098
|
-
onChangeHoverRange(EMPTY_RANGE);
|
|
1099
|
-
},
|
|
1100
|
-
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
1101
|
-
}), getCellProps(value, record, rowIndex) {
|
|
1102
|
-
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1103
|
-
return mergeCellProps(prevCellProps, {
|
|
1104
|
-
onMouseEnter() {
|
|
1105
|
-
onChangeHoverRange(colRange);
|
|
1106
|
-
},
|
|
1107
|
-
onMouseLeave() {
|
|
1108
|
-
onChangeHoverRange(EMPTY_RANGE);
|
|
1109
|
-
},
|
|
1110
|
-
style: { '--bgcolor': match ? hoverColor : undefined },
|
|
1111
|
-
});
|
|
1112
|
-
} });
|
|
1113
|
-
}));
|
|
1114
|
-
};
|
|
1060
|
+
const EMPTY_RANGE = {
|
|
1061
|
+
start: -1,
|
|
1062
|
+
end: -1,
|
|
1063
|
+
};
|
|
1064
|
+
function columnRangeHover(opts = {}) {
|
|
1065
|
+
const stateKey = 'columnHover';
|
|
1066
|
+
return function columnRangeHoverStep(pipeline) {
|
|
1067
|
+
var _a, _b, _c, _d, _e;
|
|
1068
|
+
const hoverRange = (_c = (_b = (_a = opts.hoverRange) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : opts.defaultHoverRange) !== null && _c !== void 0 ? _c : EMPTY_RANGE;
|
|
1069
|
+
const hoverColor = (_d = opts.hoverColor) !== null && _d !== void 0 ? _d : 'var(--hover-bgcolor)';
|
|
1070
|
+
const headerHoverColor = (_e = opts.headerHoverColor) !== null && _e !== void 0 ? _e : 'var(--header-hover-bgcolor)';
|
|
1071
|
+
const onChangeHoverRange = (nextColIndexRange) => {
|
|
1072
|
+
var _a;
|
|
1073
|
+
pipeline.setStateAtKey(stateKey, nextColIndexRange);
|
|
1074
|
+
(_a = opts.onChangeHoverRange) === null || _a === void 0 ? void 0 : _a.call(opts, nextColIndexRange);
|
|
1075
|
+
};
|
|
1076
|
+
return pipeline.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1077
|
+
const colRange = { start: startIndex, end: endIndex };
|
|
1078
|
+
const match = colRange.end > hoverRange.start && hoverRange.end > colRange.start;
|
|
1079
|
+
if (!isLeafNode(col)) {
|
|
1080
|
+
if (headerHoverColor == null) {
|
|
1081
|
+
return col;
|
|
1082
|
+
}
|
|
1083
|
+
return Object.assign(Object.assign({}, col), { headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
1084
|
+
onMouseEnter() {
|
|
1085
|
+
onChangeHoverRange(colRange);
|
|
1086
|
+
},
|
|
1087
|
+
onMouseLeave() {
|
|
1088
|
+
onChangeHoverRange(EMPTY_RANGE);
|
|
1089
|
+
},
|
|
1090
|
+
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
1091
|
+
}) });
|
|
1092
|
+
}
|
|
1093
|
+
const prevGetCellProps = col.getCellProps;
|
|
1094
|
+
return Object.assign(Object.assign({}, col), { headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
1095
|
+
onMouseEnter() {
|
|
1096
|
+
onChangeHoverRange(colRange);
|
|
1097
|
+
},
|
|
1098
|
+
onMouseLeave() {
|
|
1099
|
+
onChangeHoverRange(EMPTY_RANGE);
|
|
1100
|
+
},
|
|
1101
|
+
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
1102
|
+
}), getCellProps(value, record, rowIndex) {
|
|
1103
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1104
|
+
return mergeCellProps(prevCellProps, {
|
|
1105
|
+
onMouseEnter() {
|
|
1106
|
+
onChangeHoverRange(colRange);
|
|
1107
|
+
},
|
|
1108
|
+
onMouseLeave() {
|
|
1109
|
+
onChangeHoverRange(EMPTY_RANGE);
|
|
1110
|
+
},
|
|
1111
|
+
style: { '--bgcolor': match ? hoverColor : undefined },
|
|
1112
|
+
});
|
|
1113
|
+
} });
|
|
1114
|
+
}));
|
|
1115
|
+
};
|
|
1115
1116
|
}
|
|
1116
1117
|
|
|
1117
|
-
function clamp(min, x, max) {
|
|
1118
|
-
return Math.max(min, Math.min(max, x));
|
|
1119
|
-
}
|
|
1118
|
+
function clamp(min, x, max) {
|
|
1119
|
+
return Math.max(min, Math.min(max, x));
|
|
1120
|
+
}
|
|
1120
1121
|
const ResizeHandle = styled__default.span `
|
|
1121
1122
|
position: absolute;
|
|
1122
1123
|
top: 0;
|
|
@@ -1127,820 +1128,821 @@ const ResizeHandle = styled__default.span `
|
|
|
1127
1128
|
z-index: 1;
|
|
1128
1129
|
transition: background-color 200ms;
|
|
1129
1130
|
|
|
1130
|
-
background: ${(props) => {
|
|
1131
|
-
return props['var-handleBackground'];
|
|
1131
|
+
background: ${(props) => {
|
|
1132
|
+
return props['var-handleBackground'];
|
|
1132
1133
|
}};
|
|
1133
1134
|
|
|
1134
1135
|
&:hover {
|
|
1135
|
-
background: ${(props) => {
|
|
1136
|
-
return props['var-handleHoverBackground'];
|
|
1136
|
+
background: ${(props) => {
|
|
1137
|
+
return props['var-handleHoverBackground'];
|
|
1137
1138
|
}};
|
|
1138
1139
|
}
|
|
1139
|
-
`;
|
|
1140
|
-
function columnResize(opts = {}) {
|
|
1141
|
-
var _a, _b, _c, _d;
|
|
1142
|
-
const stateKey = 'columnResize';
|
|
1143
|
-
const disableUserSelectWhenResizing = (_a = opts.disableUserSelectWhenResizing) !== null && _a !== void 0 ? _a : true;
|
|
1144
|
-
const minSize = (_b = opts.minSize) !== null && _b !== void 0 ? _b : 60;
|
|
1145
|
-
const fallbackSize = (_c = opts.fallbackSize) !== null && _c !== void 0 ? _c : 150;
|
|
1146
|
-
const maxSize = (_d = opts.maxSize) !== null && _d !== void 0 ? _d : 1000;
|
|
1147
|
-
return function columnResizeFeature(pipeline) {
|
|
1148
|
-
var _a, _b, _c;
|
|
1149
|
-
const sizes = (_c = (_b = (_a = opts.sizes) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : opts.defaultSizes) !== null && _c !== void 0 ? _c : [];
|
|
1150
|
-
const { columns, fillColumn } = takeFillRemainingWidthColumn(pipeline.getColumns());
|
|
1151
|
-
const leafColumns = collectNodes(columns, 'leaf-only');
|
|
1152
|
-
leafColumns.forEach((col, colIndex) => {
|
|
1153
|
-
if (sizes[colIndex] == null) {
|
|
1154
|
-
if (typeof col.width === 'number') {
|
|
1155
|
-
sizes[colIndex] = col.width;
|
|
1156
|
-
}
|
|
1157
|
-
else {
|
|
1158
|
-
sizes[colIndex] = fallbackSize;
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
});
|
|
1162
|
-
const onChangeSizes = (nextSizes) => {
|
|
1163
|
-
var _a;
|
|
1164
|
-
pipeline.setStateAtKey(stateKey, nextSizes);
|
|
1165
|
-
(_a = opts.onChangeSizes) === null || _a === void 0 ? void 0 : _a.call(opts, nextSizes);
|
|
1166
|
-
};
|
|
1167
|
-
const startResize = (startIndex, endIndex, e) => {
|
|
1168
|
-
const startX = e.clientX;
|
|
1169
|
-
const target = e.target;
|
|
1170
|
-
const nextSizes$ = fromEvent(window, 'mousemove').pipe(op.takeUntil(fromEvent(window, 'mouseup')), op.map((e) => {
|
|
1171
|
-
const movingX = e.clientX;
|
|
1172
|
-
const nextSizes = sizes.slice();
|
|
1173
|
-
const deltaSum = movingX - startX;
|
|
1174
|
-
const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
|
|
1175
|
-
let deltaRemaining = deltaSum;
|
|
1176
|
-
for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
|
|
1177
|
-
const startSize = sizes[colIndex];
|
|
1178
|
-
// 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
|
|
1179
|
-
const colDelta = Math.round(deltaSum * (startSize / sizeSum));
|
|
1180
|
-
nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
|
|
1181
|
-
deltaRemaining -= colDelta;
|
|
1182
|
-
}
|
|
1183
|
-
// 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
|
|
1184
|
-
nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
|
|
1185
|
-
return nextSizes;
|
|
1186
|
-
}));
|
|
1187
|
-
let prevUserSelect = '';
|
|
1188
|
-
let docElemStyle;
|
|
1189
|
-
if (disableUserSelectWhenResizing) {
|
|
1190
|
-
docElemStyle = document.documentElement.style;
|
|
1191
|
-
prevUserSelect = docElemStyle.userSelect;
|
|
1192
|
-
docElemStyle.userSelect = 'none';
|
|
1193
|
-
}
|
|
1194
|
-
if (opts.handleActiveBackground) {
|
|
1195
|
-
target.style.background = opts.handleActiveBackground;
|
|
1196
|
-
}
|
|
1197
|
-
nextSizes$.subscribe({
|
|
1198
|
-
next: onChangeSizes,
|
|
1199
|
-
complete() {
|
|
1200
|
-
if (disableUserSelectWhenResizing) {
|
|
1201
|
-
docElemStyle.userSelect = prevUserSelect;
|
|
1202
|
-
}
|
|
1203
|
-
if (opts.handleActiveBackground) {
|
|
1204
|
-
target.style.background = '';
|
|
1205
|
-
}
|
|
1206
|
-
},
|
|
1207
|
-
});
|
|
1208
|
-
};
|
|
1209
|
-
const resizedColumns = makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1210
|
-
const prevTitle = internals.safeRenderHeader(col);
|
|
1211
|
-
return Object.assign(Object.assign({}, col), { width: sizes[startIndex], title: (React.createElement(React.Fragment, null,
|
|
1212
|
-
prevTitle,
|
|
1213
|
-
React.createElement(ResizeHandle, { className: "resize-handle", "var-handleBackground": opts.handleBackground, "var-handleHoverBackground": opts.handleHoverBackground, onMouseDown: (e) => startResize(startIndex, endIndex, e) }))), headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
1214
|
-
style: {
|
|
1215
|
-
overflow: 'visible',
|
|
1216
|
-
position: 'relative',
|
|
1217
|
-
},
|
|
1218
|
-
}) });
|
|
1219
|
-
})(columns);
|
|
1220
|
-
return pipeline.columns(fillColumn == null ? resizedColumns : appendFillRemainingWidthColumn(resizedColumns, fillColumn));
|
|
1221
|
-
};
|
|
1140
|
+
`;
|
|
1141
|
+
function columnResize(opts = {}) {
|
|
1142
|
+
var _a, _b, _c, _d;
|
|
1143
|
+
const stateKey = 'columnResize';
|
|
1144
|
+
const disableUserSelectWhenResizing = (_a = opts.disableUserSelectWhenResizing) !== null && _a !== void 0 ? _a : true;
|
|
1145
|
+
const minSize = (_b = opts.minSize) !== null && _b !== void 0 ? _b : 60;
|
|
1146
|
+
const fallbackSize = (_c = opts.fallbackSize) !== null && _c !== void 0 ? _c : 150;
|
|
1147
|
+
const maxSize = (_d = opts.maxSize) !== null && _d !== void 0 ? _d : 1000;
|
|
1148
|
+
return function columnResizeFeature(pipeline) {
|
|
1149
|
+
var _a, _b, _c;
|
|
1150
|
+
const sizes = (_c = (_b = (_a = opts.sizes) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : opts.defaultSizes) !== null && _c !== void 0 ? _c : [];
|
|
1151
|
+
const { columns, fillColumn } = takeFillRemainingWidthColumn(pipeline.getColumns());
|
|
1152
|
+
const leafColumns = collectNodes(columns, 'leaf-only');
|
|
1153
|
+
leafColumns.forEach((col, colIndex) => {
|
|
1154
|
+
if (sizes[colIndex] == null) {
|
|
1155
|
+
if (typeof col.width === 'number') {
|
|
1156
|
+
sizes[colIndex] = col.width;
|
|
1157
|
+
}
|
|
1158
|
+
else {
|
|
1159
|
+
sizes[colIndex] = fallbackSize;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
const onChangeSizes = (nextSizes) => {
|
|
1164
|
+
var _a;
|
|
1165
|
+
pipeline.setStateAtKey(stateKey, nextSizes);
|
|
1166
|
+
(_a = opts.onChangeSizes) === null || _a === void 0 ? void 0 : _a.call(opts, nextSizes);
|
|
1167
|
+
};
|
|
1168
|
+
const startResize = (startIndex, endIndex, e) => {
|
|
1169
|
+
const startX = e.clientX;
|
|
1170
|
+
const target = e.target;
|
|
1171
|
+
const nextSizes$ = fromEvent(window, 'mousemove').pipe(op.takeUntil(fromEvent(window, 'mouseup')), op.map((e) => {
|
|
1172
|
+
const movingX = e.clientX;
|
|
1173
|
+
const nextSizes = sizes.slice();
|
|
1174
|
+
const deltaSum = movingX - startX;
|
|
1175
|
+
const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
|
|
1176
|
+
let deltaRemaining = deltaSum;
|
|
1177
|
+
for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
|
|
1178
|
+
const startSize = sizes[colIndex];
|
|
1179
|
+
// 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
|
|
1180
|
+
const colDelta = Math.round(deltaSum * (startSize / sizeSum));
|
|
1181
|
+
nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
|
|
1182
|
+
deltaRemaining -= colDelta;
|
|
1183
|
+
}
|
|
1184
|
+
// 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
|
|
1185
|
+
nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
|
|
1186
|
+
return nextSizes;
|
|
1187
|
+
}));
|
|
1188
|
+
let prevUserSelect = '';
|
|
1189
|
+
let docElemStyle;
|
|
1190
|
+
if (disableUserSelectWhenResizing) {
|
|
1191
|
+
docElemStyle = document.documentElement.style;
|
|
1192
|
+
prevUserSelect = docElemStyle.userSelect;
|
|
1193
|
+
docElemStyle.userSelect = 'none';
|
|
1194
|
+
}
|
|
1195
|
+
if (opts.handleActiveBackground) {
|
|
1196
|
+
target.style.background = opts.handleActiveBackground;
|
|
1197
|
+
}
|
|
1198
|
+
nextSizes$.subscribe({
|
|
1199
|
+
next: onChangeSizes,
|
|
1200
|
+
complete() {
|
|
1201
|
+
if (disableUserSelectWhenResizing) {
|
|
1202
|
+
docElemStyle.userSelect = prevUserSelect;
|
|
1203
|
+
}
|
|
1204
|
+
if (opts.handleActiveBackground) {
|
|
1205
|
+
target.style.background = '';
|
|
1206
|
+
}
|
|
1207
|
+
},
|
|
1208
|
+
});
|
|
1209
|
+
};
|
|
1210
|
+
const resizedColumns = makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1211
|
+
const prevTitle = internals.safeRenderHeader(col);
|
|
1212
|
+
return Object.assign(Object.assign({}, col), { width: sizes[startIndex], title: (React.createElement(React.Fragment, null,
|
|
1213
|
+
prevTitle,
|
|
1214
|
+
React.createElement(ResizeHandle, { className: "resize-handle", "var-handleBackground": opts.handleBackground, "var-handleHoverBackground": opts.handleHoverBackground, onMouseDown: (e) => startResize(startIndex, endIndex, e) }))), headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
1215
|
+
style: {
|
|
1216
|
+
overflow: 'visible',
|
|
1217
|
+
position: 'relative',
|
|
1218
|
+
},
|
|
1219
|
+
}) });
|
|
1220
|
+
})(columns);
|
|
1221
|
+
return pipeline.columns(fillColumn == null ? resizedColumns : appendFillRemainingWidthColumn(resizedColumns, fillColumn));
|
|
1222
|
+
};
|
|
1222
1223
|
}
|
|
1223
1224
|
|
|
1224
|
-
function fillRemainingWidth() {
|
|
1225
|
-
return function fillRemainingWidthStep(pipeline) {
|
|
1226
|
-
return pipeline.columns(appendFillRemainingWidthColumn(pipeline.getColumns()));
|
|
1227
|
-
};
|
|
1225
|
+
function fillRemainingWidth() {
|
|
1226
|
+
return function fillRemainingWidthStep(pipeline) {
|
|
1227
|
+
return pipeline.columns(appendFillRemainingWidthColumn(pipeline.getColumns()));
|
|
1228
|
+
};
|
|
1228
1229
|
}
|
|
1229
1230
|
|
|
1230
|
-
function multiSelect(opts = {}) {
|
|
1231
|
-
return function multiSelectStep(pipeline) {
|
|
1232
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1233
|
-
const stateKey = 'multiSelect';
|
|
1234
|
-
const Checkbox = pipeline.ctx.components.Checkbox;
|
|
1235
|
-
if (Checkbox == null) {
|
|
1236
|
-
throw new Error('使用 multiSelect 之前需要设置 pipeline.ctx.components.Checkbox');
|
|
1237
|
-
}
|
|
1238
|
-
const primaryKey = pipeline.ensurePrimaryKey('multiSelect');
|
|
1239
|
-
const isDisabled = (_a = opts.isDisabled) !== null && _a !== void 0 ? _a : always(false);
|
|
1240
|
-
const clickArea = (_b = opts.clickArea) !== null && _b !== void 0 ? _b : 'checkbox';
|
|
1241
|
-
const value = (_f = (_e = (_c = opts.value) !== null && _c !== void 0 ? _c : (_d = pipeline.getStateAtKey(stateKey)) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : opts.defaultValue) !== null && _f !== void 0 ? _f : [];
|
|
1242
|
-
const lastKey = (_k = (_j = (_g = opts.lastKey) !== null && _g !== void 0 ? _g : (_h = pipeline.getStateAtKey(stateKey)) === null || _h === void 0 ? void 0 : _h.lastKey) !== null && _j !== void 0 ? _j : opts.defaultLastKey) !== null && _k !== void 0 ? _k : '';
|
|
1243
|
-
const onChange = (nextValue, key, keys, action) => {
|
|
1244
|
-
var _a;
|
|
1245
|
-
(_a = opts.onChange) === null || _a === void 0 ? void 0 : _a.call(opts, nextValue, key, keys, action);
|
|
1246
|
-
pipeline.setStateAtKey(stateKey, { value: nextValue, lastKey: key }, { keys, action });
|
|
1247
|
-
};
|
|
1248
|
-
const dataSource = pipeline.getDataSource();
|
|
1249
|
-
/** dataSource 中包含的所有 keys */
|
|
1250
|
-
const fullKeySet = new Set();
|
|
1251
|
-
/** 所有有效的 keys(disable 状态为 false) */
|
|
1252
|
-
const allKeys = [];
|
|
1253
|
-
dataSource.forEach((row, rowIndex) => {
|
|
1254
|
-
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1255
|
-
fullKeySet.add(rowKey);
|
|
1256
|
-
// 在 allKeys 中排除被禁用的 key
|
|
1257
|
-
if (!isDisabled(row, rowIndex)) {
|
|
1258
|
-
allKeys.push(rowKey);
|
|
1259
|
-
}
|
|
1260
|
-
});
|
|
1261
|
-
const set = new Set(value);
|
|
1262
|
-
const isAllChecked = allKeys.length > 0 && allKeys.every((key) => set.has(key));
|
|
1263
|
-
const isAnyChecked = allKeys.some((key) => set.has(key));
|
|
1264
|
-
const defaultCheckboxColumnTitle = (React.createElement(Checkbox, { checked: isAllChecked, indeterminate: !isAllChecked && isAnyChecked, onChange: (_) => {
|
|
1265
|
-
if (isAllChecked) {
|
|
1266
|
-
onChange(arrayUtils.diff(value, allKeys), '', allKeys, 'uncheck-all');
|
|
1267
|
-
}
|
|
1268
|
-
else {
|
|
1269
|
-
onChange(arrayUtils.merge(value, allKeys), '', allKeys, 'check-all');
|
|
1270
|
-
}
|
|
1271
|
-
} }));
|
|
1272
|
-
const checkboxColumn = Object.assign(Object.assign({ name: '是否选中', title: defaultCheckboxColumnTitle, width: 50, align: 'center' }, opts.checkboxColumn), { getCellProps(value, row, rowIndex) {
|
|
1273
|
-
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1274
|
-
if (fullKeySet.has(rowKey) && clickArea === 'cell') {
|
|
1275
|
-
const prevChecked = set.has(rowKey);
|
|
1276
|
-
const disabled = isDisabled(row, rowIndex);
|
|
1277
|
-
return {
|
|
1278
|
-
style: { cursor: disabled ? 'not-allowed' : 'pointer' },
|
|
1279
|
-
onClick: disabled
|
|
1280
|
-
? undefined
|
|
1281
|
-
: (e) => {
|
|
1282
|
-
if (opts.stopClickEventPropagation) {
|
|
1283
|
-
e.stopPropagation();
|
|
1284
|
-
}
|
|
1285
|
-
onCheckboxChange(prevChecked, rowKey, e.shiftKey);
|
|
1286
|
-
},
|
|
1287
|
-
};
|
|
1288
|
-
}
|
|
1289
|
-
},
|
|
1290
|
-
render(_, row, rowIndex) {
|
|
1291
|
-
const key = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1292
|
-
const checked = set.has(key);
|
|
1293
|
-
return (React.createElement(Checkbox, { checked: checked, disabled: isDisabled(row, rowIndex), onChange: clickArea === 'checkbox'
|
|
1294
|
-
? (arg1, arg2) => {
|
|
1295
|
-
var _a;
|
|
1296
|
-
// 这里要同时兼容 antd 和 fusion 的用法
|
|
1297
|
-
// fusion: arg2?.nativeEvent
|
|
1298
|
-
// antd: arg1.nativeEvent
|
|
1299
|
-
const nativeEvent = (_a = arg2 === null || arg2 === void 0 ? void 0 : arg2.nativeEvent) !== null && _a !== void 0 ? _a : arg1.nativeEvent;
|
|
1300
|
-
if (nativeEvent) {
|
|
1301
|
-
if (opts.stopClickEventPropagation) {
|
|
1302
|
-
nativeEvent.stopPropagation();
|
|
1303
|
-
}
|
|
1304
|
-
onCheckboxChange(checked, key, nativeEvent.shiftKey);
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
: undefined }));
|
|
1308
|
-
} });
|
|
1309
|
-
const nextColumns = pipeline.getColumns().slice();
|
|
1310
|
-
const checkboxPlacement = (_l = opts.checkboxPlacement) !== null && _l !== void 0 ? _l : 'start';
|
|
1311
|
-
if (checkboxPlacement === 'start') {
|
|
1312
|
-
nextColumns.unshift(checkboxColumn);
|
|
1313
|
-
}
|
|
1314
|
-
else {
|
|
1315
|
-
nextColumns.push(checkboxColumn);
|
|
1316
|
-
}
|
|
1317
|
-
pipeline.columns(nextColumns);
|
|
1318
|
-
pipeline.appendRowPropsGetter((row, rowIndex) => {
|
|
1319
|
-
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1320
|
-
if (!fullKeySet.has(rowKey)) {
|
|
1321
|
-
// rowKey 不在 fullKeySet 中说明这一行是在 multiSelect 之后才生成的,multiSelect 不对之后生成的行进行处理
|
|
1322
|
-
return;
|
|
1323
|
-
}
|
|
1324
|
-
let style = {};
|
|
1325
|
-
let className;
|
|
1326
|
-
let onClick;
|
|
1327
|
-
const checked = set.has(rowKey);
|
|
1328
|
-
if (opts.highlightRowWhenSelected && checked) {
|
|
1329
|
-
className = 'highlight';
|
|
1330
|
-
}
|
|
1331
|
-
if (clickArea === 'row') {
|
|
1332
|
-
const disabled = isDisabled(row, rowIndex);
|
|
1333
|
-
if (!disabled) {
|
|
1334
|
-
style.cursor = 'pointer';
|
|
1335
|
-
onClick = (e) => {
|
|
1336
|
-
if (opts.stopClickEventPropagation) {
|
|
1337
|
-
e.stopPropagation();
|
|
1338
|
-
}
|
|
1339
|
-
onCheckboxChange(checked, rowKey, e.shiftKey);
|
|
1340
|
-
};
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
return { className, style, onClick };
|
|
1344
|
-
});
|
|
1345
|
-
return pipeline;
|
|
1346
|
-
function onCheckboxChange(prevChecked, key, batch) {
|
|
1347
|
-
let batchKeys = [key];
|
|
1348
|
-
if (batch && lastKey) {
|
|
1349
|
-
const lastIdx = allKeys.indexOf(lastKey);
|
|
1350
|
-
const cntIdx = allKeys.indexOf(key);
|
|
1351
|
-
const [start, end] = lastIdx < cntIdx ? [lastIdx, cntIdx] : [cntIdx, lastIdx];
|
|
1352
|
-
batchKeys = allKeys.slice(start, end + 1);
|
|
1353
|
-
}
|
|
1354
|
-
if (prevChecked) {
|
|
1355
|
-
onChange(arrayUtils.diff(value, batchKeys), key, batchKeys, 'uncheck');
|
|
1356
|
-
}
|
|
1357
|
-
else {
|
|
1358
|
-
onChange(arrayUtils.merge(value, batchKeys), key, batchKeys, 'check');
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
};
|
|
1231
|
+
function multiSelect(opts = {}) {
|
|
1232
|
+
return function multiSelectStep(pipeline) {
|
|
1233
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1234
|
+
const stateKey = 'multiSelect';
|
|
1235
|
+
const Checkbox = pipeline.ctx.components.Checkbox;
|
|
1236
|
+
if (Checkbox == null) {
|
|
1237
|
+
throw new Error('使用 multiSelect 之前需要设置 pipeline.ctx.components.Checkbox');
|
|
1238
|
+
}
|
|
1239
|
+
const primaryKey = pipeline.ensurePrimaryKey('multiSelect');
|
|
1240
|
+
const isDisabled = (_a = opts.isDisabled) !== null && _a !== void 0 ? _a : always(false);
|
|
1241
|
+
const clickArea = (_b = opts.clickArea) !== null && _b !== void 0 ? _b : 'checkbox';
|
|
1242
|
+
const value = (_f = (_e = (_c = opts.value) !== null && _c !== void 0 ? _c : (_d = pipeline.getStateAtKey(stateKey)) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : opts.defaultValue) !== null && _f !== void 0 ? _f : [];
|
|
1243
|
+
const lastKey = (_k = (_j = (_g = opts.lastKey) !== null && _g !== void 0 ? _g : (_h = pipeline.getStateAtKey(stateKey)) === null || _h === void 0 ? void 0 : _h.lastKey) !== null && _j !== void 0 ? _j : opts.defaultLastKey) !== null && _k !== void 0 ? _k : '';
|
|
1244
|
+
const onChange = (nextValue, key, keys, action) => {
|
|
1245
|
+
var _a;
|
|
1246
|
+
(_a = opts.onChange) === null || _a === void 0 ? void 0 : _a.call(opts, nextValue, key, keys, action);
|
|
1247
|
+
pipeline.setStateAtKey(stateKey, { value: nextValue, lastKey: key }, { keys, action });
|
|
1248
|
+
};
|
|
1249
|
+
const dataSource = pipeline.getDataSource();
|
|
1250
|
+
/** dataSource 中包含的所有 keys */
|
|
1251
|
+
const fullKeySet = new Set();
|
|
1252
|
+
/** 所有有效的 keys(disable 状态为 false) */
|
|
1253
|
+
const allKeys = [];
|
|
1254
|
+
dataSource.forEach((row, rowIndex) => {
|
|
1255
|
+
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1256
|
+
fullKeySet.add(rowKey);
|
|
1257
|
+
// 在 allKeys 中排除被禁用的 key
|
|
1258
|
+
if (!isDisabled(row, rowIndex)) {
|
|
1259
|
+
allKeys.push(rowKey);
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
const set = new Set(value);
|
|
1263
|
+
const isAllChecked = allKeys.length > 0 && allKeys.every((key) => set.has(key));
|
|
1264
|
+
const isAnyChecked = allKeys.some((key) => set.has(key));
|
|
1265
|
+
const defaultCheckboxColumnTitle = (React.createElement(Checkbox, { checked: isAllChecked, indeterminate: !isAllChecked && isAnyChecked, onChange: (_) => {
|
|
1266
|
+
if (isAllChecked) {
|
|
1267
|
+
onChange(arrayUtils.diff(value, allKeys), '', allKeys, 'uncheck-all');
|
|
1268
|
+
}
|
|
1269
|
+
else {
|
|
1270
|
+
onChange(arrayUtils.merge(value, allKeys), '', allKeys, 'check-all');
|
|
1271
|
+
}
|
|
1272
|
+
} }));
|
|
1273
|
+
const checkboxColumn = Object.assign(Object.assign({ name: '是否选中', title: defaultCheckboxColumnTitle, width: 50, align: 'center' }, opts.checkboxColumn), { getCellProps(value, row, rowIndex) {
|
|
1274
|
+
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1275
|
+
if (fullKeySet.has(rowKey) && clickArea === 'cell') {
|
|
1276
|
+
const prevChecked = set.has(rowKey);
|
|
1277
|
+
const disabled = isDisabled(row, rowIndex);
|
|
1278
|
+
return {
|
|
1279
|
+
style: { cursor: disabled ? 'not-allowed' : 'pointer' },
|
|
1280
|
+
onClick: disabled
|
|
1281
|
+
? undefined
|
|
1282
|
+
: (e) => {
|
|
1283
|
+
if (opts.stopClickEventPropagation) {
|
|
1284
|
+
e.stopPropagation();
|
|
1285
|
+
}
|
|
1286
|
+
onCheckboxChange(prevChecked, rowKey, e.shiftKey);
|
|
1287
|
+
},
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1290
|
+
},
|
|
1291
|
+
render(_, row, rowIndex) {
|
|
1292
|
+
const key = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1293
|
+
const checked = set.has(key);
|
|
1294
|
+
return (React.createElement(Checkbox, { checked: checked, disabled: isDisabled(row, rowIndex), onChange: clickArea === 'checkbox'
|
|
1295
|
+
? (arg1, arg2) => {
|
|
1296
|
+
var _a;
|
|
1297
|
+
// 这里要同时兼容 antd 和 fusion 的用法
|
|
1298
|
+
// fusion: arg2?.nativeEvent
|
|
1299
|
+
// antd: arg1.nativeEvent
|
|
1300
|
+
const nativeEvent = (_a = arg2 === null || arg2 === void 0 ? void 0 : arg2.nativeEvent) !== null && _a !== void 0 ? _a : arg1.nativeEvent;
|
|
1301
|
+
if (nativeEvent) {
|
|
1302
|
+
if (opts.stopClickEventPropagation) {
|
|
1303
|
+
nativeEvent.stopPropagation();
|
|
1304
|
+
}
|
|
1305
|
+
onCheckboxChange(checked, key, nativeEvent.shiftKey);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
: undefined }));
|
|
1309
|
+
} });
|
|
1310
|
+
const nextColumns = pipeline.getColumns().slice();
|
|
1311
|
+
const checkboxPlacement = (_l = opts.checkboxPlacement) !== null && _l !== void 0 ? _l : 'start';
|
|
1312
|
+
if (checkboxPlacement === 'start') {
|
|
1313
|
+
nextColumns.unshift(checkboxColumn);
|
|
1314
|
+
}
|
|
1315
|
+
else {
|
|
1316
|
+
nextColumns.push(checkboxColumn);
|
|
1317
|
+
}
|
|
1318
|
+
pipeline.columns(nextColumns);
|
|
1319
|
+
pipeline.appendRowPropsGetter((row, rowIndex) => {
|
|
1320
|
+
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1321
|
+
if (!fullKeySet.has(rowKey)) {
|
|
1322
|
+
// rowKey 不在 fullKeySet 中说明这一行是在 multiSelect 之后才生成的,multiSelect 不对之后生成的行进行处理
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
let style = {};
|
|
1326
|
+
let className;
|
|
1327
|
+
let onClick;
|
|
1328
|
+
const checked = set.has(rowKey);
|
|
1329
|
+
if (opts.highlightRowWhenSelected && checked) {
|
|
1330
|
+
className = 'highlight';
|
|
1331
|
+
}
|
|
1332
|
+
if (clickArea === 'row') {
|
|
1333
|
+
const disabled = isDisabled(row, rowIndex);
|
|
1334
|
+
if (!disabled) {
|
|
1335
|
+
style.cursor = 'pointer';
|
|
1336
|
+
onClick = (e) => {
|
|
1337
|
+
if (opts.stopClickEventPropagation) {
|
|
1338
|
+
e.stopPropagation();
|
|
1339
|
+
}
|
|
1340
|
+
onCheckboxChange(checked, rowKey, e.shiftKey);
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
return { className, style, onClick };
|
|
1345
|
+
});
|
|
1346
|
+
return pipeline;
|
|
1347
|
+
function onCheckboxChange(prevChecked, key, batch) {
|
|
1348
|
+
let batchKeys = [key];
|
|
1349
|
+
if (batch && lastKey) {
|
|
1350
|
+
const lastIdx = allKeys.indexOf(lastKey);
|
|
1351
|
+
const cntIdx = allKeys.indexOf(key);
|
|
1352
|
+
const [start, end] = lastIdx < cntIdx ? [lastIdx, cntIdx] : [cntIdx, lastIdx];
|
|
1353
|
+
batchKeys = allKeys.slice(start, end + 1);
|
|
1354
|
+
}
|
|
1355
|
+
if (prevChecked) {
|
|
1356
|
+
onChange(arrayUtils.diff(value, batchKeys), key, batchKeys, 'uncheck');
|
|
1357
|
+
}
|
|
1358
|
+
else {
|
|
1359
|
+
onChange(arrayUtils.merge(value, batchKeys), key, batchKeys, 'check');
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1362
1363
|
}
|
|
1363
1364
|
|
|
1364
|
-
const rowDetailSymbol = Symbol('row-detail');
|
|
1365
|
-
const fallbackRenderDetail = () => (React.createElement("div", { style: { margin: '8px 24px' } },
|
|
1366
|
-
React.createElement("b", { style: { color: 'indianred' } },
|
|
1367
|
-
"\u8BBE\u7F6E ",
|
|
1368
|
-
React.createElement("code", null, "rowDetail.renderDetail"),
|
|
1369
|
-
" \u6765\u81EA\u5B9A\u4E49\u8BE6\u60C5\u5185\u5BB9")));
|
|
1370
|
-
function rowDetail(opts = {}) {
|
|
1371
|
-
return function rowDetailStep(pipeline) {
|
|
1372
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1373
|
-
const stateKey = 'rowDetail';
|
|
1374
|
-
const primaryKey = pipeline.ensurePrimaryKey('rowDetail');
|
|
1375
|
-
if (typeof primaryKey !== 'string') {
|
|
1376
|
-
throw new Error('rowDetail 仅支持字符串作为 primaryKey');
|
|
1377
|
-
}
|
|
1378
|
-
const rowDetailMetaKey = (_a = opts.rowDetailMetaKey) !== null && _a !== void 0 ? _a : rowDetailSymbol;
|
|
1379
|
-
const indents = pipeline.ctx.indents;
|
|
1380
|
-
const textOffset = indents.iconIndent + indents.iconWidth + indents.iconGap;
|
|
1381
|
-
const clickArea = (_b = opts.clickArea) !== null && _b !== void 0 ? _b : 'cell';
|
|
1382
|
-
const getDetailKey = (_c = opts.getDetailKey) !== null && _c !== void 0 ? _c : ((row) => row[primaryKey] + '_detail');
|
|
1383
|
-
const renderDetail = (_d = opts.renderDetail) !== null && _d !== void 0 ? _d : fallbackRenderDetail;
|
|
1384
|
-
const hasDetail = (_e = opts.hasDetail) !== null && _e !== void 0 ? _e : always(true);
|
|
1385
|
-
const openKeys = (_h = (_g = (_f = opts.openKeys) !== null && _f !== void 0 ? _f : pipeline.getStateAtKey(stateKey)) !== null && _g !== void 0 ? _g : (opts.defaultOpenAll
|
|
1386
|
-
? pipeline
|
|
1387
|
-
.getDataSource()
|
|
1388
|
-
.filter(hasDetail)
|
|
1389
|
-
.map((row) => row[primaryKey])
|
|
1390
|
-
: opts.defaultOpenKeys)) !== null && _h !== void 0 ? _h : [];
|
|
1391
|
-
const onChangeOpenKeys = (nextKeys, key, action) => {
|
|
1392
|
-
var _a;
|
|
1393
|
-
(_a = opts.onChangeOpenKeys) === null || _a === void 0 ? void 0 : _a.call(opts, nextKeys, key, action);
|
|
1394
|
-
pipeline.setStateAtKey(stateKey, nextKeys, { key, action });
|
|
1395
|
-
};
|
|
1396
|
-
const openKeySet = new Set(openKeys);
|
|
1397
|
-
const toggle = (rowKey) => {
|
|
1398
|
-
const expanded = openKeySet.has(rowKey);
|
|
1399
|
-
if (expanded) {
|
|
1400
|
-
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'collapse');
|
|
1401
|
-
}
|
|
1402
|
-
else {
|
|
1403
|
-
onChangeOpenKeys([...openKeys, rowKey], rowKey, 'expand');
|
|
1404
|
-
}
|
|
1405
|
-
};
|
|
1406
|
-
return pipeline
|
|
1407
|
-
.dataSource(flatMap(pipeline.getDataSource(), (row, rowIndex) => {
|
|
1408
|
-
if (openKeySet.has(row[primaryKey])) {
|
|
1409
|
-
return [row, Object.assign(Object.assign({ [rowDetailMetaKey]: true }, row), { [primaryKey]: getDetailKey(row, rowIndex) })];
|
|
1410
|
-
}
|
|
1411
|
-
else {
|
|
1412
|
-
return [row];
|
|
1413
|
-
}
|
|
1414
|
-
}))
|
|
1415
|
-
.columns(processColumns(pipeline.getColumns()))
|
|
1416
|
-
.appendRowPropsGetter((row) => {
|
|
1417
|
-
if (row[rowDetailMetaKey]) {
|
|
1418
|
-
return { className: 'no-hover' };
|
|
1419
|
-
}
|
|
1420
|
-
});
|
|
1421
|
-
function processColumns(columns) {
|
|
1422
|
-
if (columns.length === 0) {
|
|
1423
|
-
return columns;
|
|
1424
|
-
}
|
|
1425
|
-
const columnFlatCount = collectNodes(columns, 'leaf-only').length;
|
|
1426
|
-
const [firstCol, ...others] = columns;
|
|
1427
|
-
const render = (value, row, rowIndex) => {
|
|
1428
|
-
if (row[rowDetailMetaKey]) {
|
|
1429
|
-
return renderDetail(row, rowIndex);
|
|
1430
|
-
}
|
|
1431
|
-
const content = internals.safeRender(firstCol, row, rowIndex);
|
|
1432
|
-
if (!hasDetail(row, rowIndex)) {
|
|
1433
|
-
return React.createElement(InlineFlexCell, { style: { marginLeft: textOffset } }, content);
|
|
1434
|
-
}
|
|
1435
|
-
const rowKey = row[primaryKey];
|
|
1436
|
-
const expanded = openKeySet.has(rowKey);
|
|
1437
|
-
const onClick = (e) => {
|
|
1438
|
-
if (opts.stopClickEventPropagation) {
|
|
1439
|
-
e.stopPropagation();
|
|
1440
|
-
}
|
|
1441
|
-
toggle(rowKey);
|
|
1442
|
-
};
|
|
1443
|
-
const expandCls = expanded ? 'expanded' : 'collapsed';
|
|
1444
|
-
return opts.useCustomExpandAction ? content : (React.createElement(ExpansionCell, { className: cx('expansion-cell', expandCls), style: { cursor: clickArea === 'content' ? 'pointer' : undefined }, onClick: clickArea === 'content' ? onClick : undefined },
|
|
1445
|
-
React.createElement(icons.CaretRight, { style: {
|
|
1446
|
-
cursor: clickArea === 'icon' ? 'pointer' : undefined,
|
|
1447
|
-
marginLeft: indents.iconIndent,
|
|
1448
|
-
marginRight: indents.iconGap,
|
|
1449
|
-
}, className: cx('expansion-icon', expandCls), onClick: clickArea === 'icon' ? onClick : undefined }),
|
|
1450
|
-
content));
|
|
1451
|
-
};
|
|
1452
|
-
const getCellProps = (value, row, rowIndex) => {
|
|
1453
|
-
var _a;
|
|
1454
|
-
if (row[rowDetailMetaKey]) {
|
|
1455
|
-
return {
|
|
1456
|
-
style: Object.assign({ '--cell-padding': '0', overflow: 'hidden' }, opts.detailCellStyle),
|
|
1457
|
-
};
|
|
1458
|
-
}
|
|
1459
|
-
const prevProps = (_a = firstCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(firstCol, value, row, rowIndex);
|
|
1460
|
-
if (!hasDetail(row, rowIndex)) {
|
|
1461
|
-
return prevProps;
|
|
1462
|
-
}
|
|
1463
|
-
const toggleProps = opts.useCustomExpandAction ? undefined : {
|
|
1464
|
-
onClick: (e) => {
|
|
1465
|
-
if (opts.stopClickEventPropagation) {
|
|
1466
|
-
e.stopPropagation();
|
|
1467
|
-
}
|
|
1468
|
-
toggle(row[primaryKey]);
|
|
1469
|
-
},
|
|
1470
|
-
style: { cursor: 'pointer' },
|
|
1471
|
-
};
|
|
1472
|
-
return mergeCellProps(prevProps, toggleProps);
|
|
1473
|
-
};
|
|
1474
|
-
return [
|
|
1475
|
-
Object.assign(Object.assign({}, firstCol), { title: (React.createElement("div", { style: { display: 'inline-block', marginLeft: textOffset } }, internals.safeRenderHeader(firstCol))), render, getCellProps: clickArea === 'cell' ? getCellProps : firstCol.getCellProps, getSpanRect(value, row, rowIndex) {
|
|
1476
|
-
if (row[rowDetailMetaKey]) {
|
|
1477
|
-
// detail 总是成一行
|
|
1478
|
-
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: columnFlatCount };
|
|
1479
|
-
}
|
|
1480
|
-
} }),
|
|
1481
|
-
...others,
|
|
1482
|
-
];
|
|
1483
|
-
}
|
|
1484
|
-
};
|
|
1365
|
+
const rowDetailSymbol = Symbol('row-detail');
|
|
1366
|
+
const fallbackRenderDetail = () => (React.createElement("div", { style: { margin: '8px 24px' } },
|
|
1367
|
+
React.createElement("b", { style: { color: 'indianred' } },
|
|
1368
|
+
"\u8BBE\u7F6E ",
|
|
1369
|
+
React.createElement("code", null, "rowDetail.renderDetail"),
|
|
1370
|
+
" \u6765\u81EA\u5B9A\u4E49\u8BE6\u60C5\u5185\u5BB9")));
|
|
1371
|
+
function rowDetail(opts = {}) {
|
|
1372
|
+
return function rowDetailStep(pipeline) {
|
|
1373
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1374
|
+
const stateKey = 'rowDetail';
|
|
1375
|
+
const primaryKey = pipeline.ensurePrimaryKey('rowDetail');
|
|
1376
|
+
if (typeof primaryKey !== 'string') {
|
|
1377
|
+
throw new Error('rowDetail 仅支持字符串作为 primaryKey');
|
|
1378
|
+
}
|
|
1379
|
+
const rowDetailMetaKey = (_a = opts.rowDetailMetaKey) !== null && _a !== void 0 ? _a : rowDetailSymbol;
|
|
1380
|
+
const indents = pipeline.ctx.indents;
|
|
1381
|
+
const textOffset = indents.iconIndent + indents.iconWidth + indents.iconGap;
|
|
1382
|
+
const clickArea = (_b = opts.clickArea) !== null && _b !== void 0 ? _b : 'cell';
|
|
1383
|
+
const getDetailKey = (_c = opts.getDetailKey) !== null && _c !== void 0 ? _c : ((row) => row[primaryKey] + '_detail');
|
|
1384
|
+
const renderDetail = (_d = opts.renderDetail) !== null && _d !== void 0 ? _d : fallbackRenderDetail;
|
|
1385
|
+
const hasDetail = (_e = opts.hasDetail) !== null && _e !== void 0 ? _e : always(true);
|
|
1386
|
+
const openKeys = (_h = (_g = (_f = opts.openKeys) !== null && _f !== void 0 ? _f : pipeline.getStateAtKey(stateKey)) !== null && _g !== void 0 ? _g : (opts.defaultOpenAll
|
|
1387
|
+
? pipeline
|
|
1388
|
+
.getDataSource()
|
|
1389
|
+
.filter(hasDetail)
|
|
1390
|
+
.map((row) => row[primaryKey])
|
|
1391
|
+
: opts.defaultOpenKeys)) !== null && _h !== void 0 ? _h : [];
|
|
1392
|
+
const onChangeOpenKeys = (nextKeys, key, action) => {
|
|
1393
|
+
var _a;
|
|
1394
|
+
(_a = opts.onChangeOpenKeys) === null || _a === void 0 ? void 0 : _a.call(opts, nextKeys, key, action);
|
|
1395
|
+
pipeline.setStateAtKey(stateKey, nextKeys, { key, action });
|
|
1396
|
+
};
|
|
1397
|
+
const openKeySet = new Set(openKeys);
|
|
1398
|
+
const toggle = (rowKey) => {
|
|
1399
|
+
const expanded = openKeySet.has(rowKey);
|
|
1400
|
+
if (expanded) {
|
|
1401
|
+
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'collapse');
|
|
1402
|
+
}
|
|
1403
|
+
else {
|
|
1404
|
+
onChangeOpenKeys([...openKeys, rowKey], rowKey, 'expand');
|
|
1405
|
+
}
|
|
1406
|
+
};
|
|
1407
|
+
return pipeline
|
|
1408
|
+
.dataSource(flatMap(pipeline.getDataSource(), (row, rowIndex) => {
|
|
1409
|
+
if (openKeySet.has(row[primaryKey])) {
|
|
1410
|
+
return [row, Object.assign(Object.assign({ [rowDetailMetaKey]: true }, row), { [primaryKey]: getDetailKey(row, rowIndex) })];
|
|
1411
|
+
}
|
|
1412
|
+
else {
|
|
1413
|
+
return [row];
|
|
1414
|
+
}
|
|
1415
|
+
}))
|
|
1416
|
+
.columns(processColumns(pipeline.getColumns()))
|
|
1417
|
+
.appendRowPropsGetter((row) => {
|
|
1418
|
+
if (row[rowDetailMetaKey]) {
|
|
1419
|
+
return { className: 'no-hover' };
|
|
1420
|
+
}
|
|
1421
|
+
});
|
|
1422
|
+
function processColumns(columns) {
|
|
1423
|
+
if (columns.length === 0) {
|
|
1424
|
+
return columns;
|
|
1425
|
+
}
|
|
1426
|
+
const columnFlatCount = collectNodes(columns, 'leaf-only').length;
|
|
1427
|
+
const [firstCol, ...others] = columns;
|
|
1428
|
+
const render = (value, row, rowIndex) => {
|
|
1429
|
+
if (row[rowDetailMetaKey]) {
|
|
1430
|
+
return renderDetail(row, rowIndex);
|
|
1431
|
+
}
|
|
1432
|
+
const content = internals.safeRender(firstCol, row, rowIndex);
|
|
1433
|
+
if (!hasDetail(row, rowIndex)) {
|
|
1434
|
+
return React.createElement(InlineFlexCell, { style: { marginLeft: textOffset } }, content);
|
|
1435
|
+
}
|
|
1436
|
+
const rowKey = row[primaryKey];
|
|
1437
|
+
const expanded = openKeySet.has(rowKey);
|
|
1438
|
+
const onClick = (e) => {
|
|
1439
|
+
if (opts.stopClickEventPropagation) {
|
|
1440
|
+
e.stopPropagation();
|
|
1441
|
+
}
|
|
1442
|
+
toggle(rowKey);
|
|
1443
|
+
};
|
|
1444
|
+
const expandCls = expanded ? 'expanded' : 'collapsed';
|
|
1445
|
+
return opts.useCustomExpandAction ? content : (React.createElement(ExpansionCell, { className: cx('expansion-cell', expandCls), style: { cursor: clickArea === 'content' ? 'pointer' : undefined }, onClick: clickArea === 'content' ? onClick : undefined },
|
|
1446
|
+
React.createElement(icons.CaretRight, { style: {
|
|
1447
|
+
cursor: clickArea === 'icon' ? 'pointer' : undefined,
|
|
1448
|
+
marginLeft: indents.iconIndent,
|
|
1449
|
+
marginRight: indents.iconGap,
|
|
1450
|
+
}, className: cx('expansion-icon', expandCls), onClick: clickArea === 'icon' ? onClick : undefined }),
|
|
1451
|
+
content));
|
|
1452
|
+
};
|
|
1453
|
+
const getCellProps = (value, row, rowIndex) => {
|
|
1454
|
+
var _a;
|
|
1455
|
+
if (row[rowDetailMetaKey]) {
|
|
1456
|
+
return {
|
|
1457
|
+
style: Object.assign({ '--cell-padding': '0', overflow: 'hidden' }, opts.detailCellStyle),
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
const prevProps = (_a = firstCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(firstCol, value, row, rowIndex);
|
|
1461
|
+
if (!hasDetail(row, rowIndex)) {
|
|
1462
|
+
return prevProps;
|
|
1463
|
+
}
|
|
1464
|
+
const toggleProps = opts.useCustomExpandAction ? undefined : {
|
|
1465
|
+
onClick: (e) => {
|
|
1466
|
+
if (opts.stopClickEventPropagation) {
|
|
1467
|
+
e.stopPropagation();
|
|
1468
|
+
}
|
|
1469
|
+
toggle(row[primaryKey]);
|
|
1470
|
+
},
|
|
1471
|
+
style: { cursor: 'pointer' },
|
|
1472
|
+
};
|
|
1473
|
+
return mergeCellProps(prevProps, toggleProps);
|
|
1474
|
+
};
|
|
1475
|
+
return [
|
|
1476
|
+
Object.assign(Object.assign({}, firstCol), { title: (React.createElement("div", { style: { display: 'inline-block', marginLeft: textOffset } }, internals.safeRenderHeader(firstCol))), render, getCellProps: clickArea === 'cell' ? getCellProps : firstCol.getCellProps, getSpanRect(value, row, rowIndex) {
|
|
1477
|
+
if (row[rowDetailMetaKey]) {
|
|
1478
|
+
// detail 总是成一行
|
|
1479
|
+
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: columnFlatCount };
|
|
1480
|
+
}
|
|
1481
|
+
} }),
|
|
1482
|
+
...others,
|
|
1483
|
+
];
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1485
1486
|
}
|
|
1486
1487
|
|
|
1487
|
-
const rowPopoverSymbol = Symbol('row-popover');
|
|
1488
|
-
const fallbackRenderPopover = () => (React.createElement("div", { style: { margin: '8px 24px' } },
|
|
1489
|
-
React.createElement("b", { style: { color: 'indianred' } },
|
|
1490
|
-
"\u8BBE\u7F6E ",
|
|
1491
|
-
React.createElement("code", null, "rowPopover.renderPopover"),
|
|
1492
|
-
" \u6765\u81EA\u5B9A\u4E49\u8BE6\u60C5\u5185\u5BB9")));
|
|
1493
|
-
function rowPopover(opts = {}) {
|
|
1494
|
-
return function rowPopoverStep(pipeline) {
|
|
1495
|
-
var _a, _b;
|
|
1496
|
-
const Popover = pipeline.ctx.components.Popover;
|
|
1497
|
-
if (Popover == null) {
|
|
1498
|
-
throw new Error('使用 rowPopover 之前需要设置 pipeline.ctx.components.Popover');
|
|
1499
|
-
}
|
|
1500
|
-
const stateKey = 'rowPopover';
|
|
1501
|
-
const primaryKey = pipeline.ensurePrimaryKey(stateKey);
|
|
1502
|
-
if (typeof primaryKey !== 'string') {
|
|
1503
|
-
throw new Error(`${stateKey} 仅支持字符串作为 primaryKey`);
|
|
1504
|
-
}
|
|
1505
|
-
const renderPopover = (_a = opts.renderPopover) !== null && _a !== void 0 ? _a : fallbackRenderPopover;
|
|
1506
|
-
const openKeys = (_b = pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : [];
|
|
1507
|
-
const onChangeOpenKeys = (nextKeys, key, action) => {
|
|
1508
|
-
pipeline.setStateAtKey(stateKey, nextKeys, { key, action });
|
|
1509
|
-
};
|
|
1510
|
-
const openKeySet = new Set(openKeys);
|
|
1511
|
-
const toggle = (rowKey, flag) => {
|
|
1512
|
-
if (!flag) {
|
|
1513
|
-
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'mouseleave');
|
|
1514
|
-
}
|
|
1515
|
-
else {
|
|
1516
|
-
onChangeOpenKeys([rowKey], rowKey, 'mouseenter');
|
|
1517
|
-
}
|
|
1518
|
-
};
|
|
1519
|
-
return pipeline
|
|
1520
|
-
.dataSource(flatMap(pipeline.getDataSource(), (row, rowIndex) => {
|
|
1521
|
-
if (openKeySet.has(row[primaryKey])) {
|
|
1522
|
-
return [Object.assign({ [rowPopoverSymbol]: true }, row)];
|
|
1523
|
-
}
|
|
1524
|
-
else {
|
|
1525
|
-
return [row];
|
|
1526
|
-
}
|
|
1527
|
-
}))
|
|
1528
|
-
.columns(processColumns(pipeline.getColumns()));
|
|
1529
|
-
function processColumns(columns) {
|
|
1530
|
-
if (columns.length === 0) {
|
|
1531
|
-
return columns;
|
|
1532
|
-
}
|
|
1533
|
-
const render = (mountCol, value, row, rowIndex) => {
|
|
1534
|
-
const content = internals.safeRender(mountCol, row, rowIndex);
|
|
1535
|
-
if (!row[rowPopoverSymbol]) {
|
|
1536
|
-
return content;
|
|
1537
|
-
}
|
|
1538
|
-
const rowKey = row[primaryKey];
|
|
1539
|
-
const expanded = openKeySet.has(rowKey);
|
|
1540
|
-
return (React.createElement(Popover, Object.assign({ visible: expanded }, opts.popoverProps, { content: renderPopover(row, rowIndex) }), content));
|
|
1541
|
-
};
|
|
1542
|
-
return columns.map((column, columnIndex) => {
|
|
1543
|
-
// 弹框挂载列
|
|
1544
|
-
if (opts.mountColCode ? (opts.mountColCode === column.code) : (columnIndex === 0)) {
|
|
1545
|
-
return Object.assign(Object.assign({}, column), { getCellProps(value, record, rowIndex) {
|
|
1546
|
-
const prevGetCellProps = column.getCellProps;
|
|
1547
|
-
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1548
|
-
const rowKey = record[primaryKey];
|
|
1549
|
-
return mergeCellProps(prevCellProps, {
|
|
1550
|
-
onMouseEnter() {
|
|
1551
|
-
toggle(rowKey, true);
|
|
1552
|
-
},
|
|
1553
|
-
onMouseLeave() {
|
|
1554
|
-
toggle(rowKey, false);
|
|
1555
|
-
},
|
|
1556
|
-
});
|
|
1557
|
-
}, render: (value, record, rowIndex) => render(column, value, record, rowIndex) });
|
|
1558
|
-
}
|
|
1559
|
-
// 禁用弹框挂载列
|
|
1560
|
-
if (Array.isArray(opts.excludeColCodes) && opts.excludeColCodes.includes(column.code)) {
|
|
1561
|
-
return column;
|
|
1562
|
-
}
|
|
1563
|
-
return Object.assign(Object.assign({}, column), { getCellProps(value, record, rowIndex) {
|
|
1564
|
-
const prevGetCellProps = column.getCellProps;
|
|
1565
|
-
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1566
|
-
const rowKey = record[primaryKey];
|
|
1567
|
-
return mergeCellProps(prevCellProps, {
|
|
1568
|
-
onMouseEnter() {
|
|
1569
|
-
toggle(rowKey, true);
|
|
1570
|
-
},
|
|
1571
|
-
onMouseLeave() {
|
|
1572
|
-
toggle(rowKey, false);
|
|
1573
|
-
},
|
|
1574
|
-
});
|
|
1575
|
-
} });
|
|
1576
|
-
});
|
|
1577
|
-
}
|
|
1578
|
-
};
|
|
1488
|
+
const rowPopoverSymbol = Symbol('row-popover');
|
|
1489
|
+
const fallbackRenderPopover = () => (React.createElement("div", { style: { margin: '8px 24px' } },
|
|
1490
|
+
React.createElement("b", { style: { color: 'indianred' } },
|
|
1491
|
+
"\u8BBE\u7F6E ",
|
|
1492
|
+
React.createElement("code", null, "rowPopover.renderPopover"),
|
|
1493
|
+
" \u6765\u81EA\u5B9A\u4E49\u8BE6\u60C5\u5185\u5BB9")));
|
|
1494
|
+
function rowPopover(opts = {}) {
|
|
1495
|
+
return function rowPopoverStep(pipeline) {
|
|
1496
|
+
var _a, _b;
|
|
1497
|
+
const Popover = pipeline.ctx.components.Popover;
|
|
1498
|
+
if (Popover == null) {
|
|
1499
|
+
throw new Error('使用 rowPopover 之前需要设置 pipeline.ctx.components.Popover');
|
|
1500
|
+
}
|
|
1501
|
+
const stateKey = 'rowPopover';
|
|
1502
|
+
const primaryKey = pipeline.ensurePrimaryKey(stateKey);
|
|
1503
|
+
if (typeof primaryKey !== 'string') {
|
|
1504
|
+
throw new Error(`${stateKey} 仅支持字符串作为 primaryKey`);
|
|
1505
|
+
}
|
|
1506
|
+
const renderPopover = (_a = opts.renderPopover) !== null && _a !== void 0 ? _a : fallbackRenderPopover;
|
|
1507
|
+
const openKeys = (_b = pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : [];
|
|
1508
|
+
const onChangeOpenKeys = (nextKeys, key, action) => {
|
|
1509
|
+
pipeline.setStateAtKey(stateKey, nextKeys, { key, action });
|
|
1510
|
+
};
|
|
1511
|
+
const openKeySet = new Set(openKeys);
|
|
1512
|
+
const toggle = (rowKey, flag) => {
|
|
1513
|
+
if (!flag) {
|
|
1514
|
+
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'mouseleave');
|
|
1515
|
+
}
|
|
1516
|
+
else {
|
|
1517
|
+
onChangeOpenKeys([rowKey], rowKey, 'mouseenter');
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
return pipeline
|
|
1521
|
+
.dataSource(flatMap(pipeline.getDataSource(), (row, rowIndex) => {
|
|
1522
|
+
if (openKeySet.has(row[primaryKey])) {
|
|
1523
|
+
return [Object.assign({ [rowPopoverSymbol]: true }, row)];
|
|
1524
|
+
}
|
|
1525
|
+
else {
|
|
1526
|
+
return [row];
|
|
1527
|
+
}
|
|
1528
|
+
}))
|
|
1529
|
+
.columns(processColumns(pipeline.getColumns()));
|
|
1530
|
+
function processColumns(columns) {
|
|
1531
|
+
if (columns.length === 0) {
|
|
1532
|
+
return columns;
|
|
1533
|
+
}
|
|
1534
|
+
const render = (mountCol, value, row, rowIndex) => {
|
|
1535
|
+
const content = internals.safeRender(mountCol, row, rowIndex);
|
|
1536
|
+
if (!row[rowPopoverSymbol]) {
|
|
1537
|
+
return content;
|
|
1538
|
+
}
|
|
1539
|
+
const rowKey = row[primaryKey];
|
|
1540
|
+
const expanded = openKeySet.has(rowKey);
|
|
1541
|
+
return (React.createElement(Popover, Object.assign({ visible: expanded }, opts.popoverProps, { content: renderPopover(row, rowIndex) }), content));
|
|
1542
|
+
};
|
|
1543
|
+
return columns.map((column, columnIndex) => {
|
|
1544
|
+
// 弹框挂载列
|
|
1545
|
+
if (opts.mountColCode ? (opts.mountColCode === column.code) : (columnIndex === 0)) {
|
|
1546
|
+
return Object.assign(Object.assign({}, column), { getCellProps(value, record, rowIndex) {
|
|
1547
|
+
const prevGetCellProps = column.getCellProps;
|
|
1548
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1549
|
+
const rowKey = record[primaryKey];
|
|
1550
|
+
return mergeCellProps(prevCellProps, {
|
|
1551
|
+
onMouseEnter() {
|
|
1552
|
+
toggle(rowKey, true);
|
|
1553
|
+
},
|
|
1554
|
+
onMouseLeave() {
|
|
1555
|
+
toggle(rowKey, false);
|
|
1556
|
+
},
|
|
1557
|
+
});
|
|
1558
|
+
}, render: (value, record, rowIndex) => render(column, value, record, rowIndex) });
|
|
1559
|
+
}
|
|
1560
|
+
// 禁用弹框挂载列
|
|
1561
|
+
if (Array.isArray(opts.excludeColCodes) && opts.excludeColCodes.includes(column.code)) {
|
|
1562
|
+
return column;
|
|
1563
|
+
}
|
|
1564
|
+
return Object.assign(Object.assign({}, column), { getCellProps(value, record, rowIndex) {
|
|
1565
|
+
const prevGetCellProps = column.getCellProps;
|
|
1566
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1567
|
+
const rowKey = record[primaryKey];
|
|
1568
|
+
return mergeCellProps(prevCellProps, {
|
|
1569
|
+
onMouseEnter() {
|
|
1570
|
+
toggle(rowKey, true);
|
|
1571
|
+
},
|
|
1572
|
+
onMouseLeave() {
|
|
1573
|
+
toggle(rowKey, false);
|
|
1574
|
+
},
|
|
1575
|
+
});
|
|
1576
|
+
} });
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1579
1580
|
}
|
|
1580
1581
|
|
|
1581
|
-
const groupingMetaSymbol = Symbol('row-grouping-meta');
|
|
1582
|
-
function attachGroupingMeta(row) {
|
|
1583
|
-
return Object.assign({ [groupingMetaSymbol]: { expandable: !isLeafNode(row) } }, row);
|
|
1584
|
-
}
|
|
1585
|
-
function getGroupingMeta(row) {
|
|
1586
|
-
if (row[groupingMetaSymbol] == null) {
|
|
1587
|
-
return { isGroupHeader: false, expandable: false };
|
|
1588
|
-
}
|
|
1589
|
-
return { isGroupHeader: true, expandable: row[groupingMetaSymbol].expandable };
|
|
1590
|
-
}
|
|
1591
|
-
function rowGroupingRowPropsGetter(row) {
|
|
1592
|
-
if (getGroupingMeta(row).isGroupHeader) {
|
|
1593
|
-
return { className: 'alternative' };
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
function rowGrouping(opts = {}) {
|
|
1597
|
-
return (pipeline) => {
|
|
1598
|
-
var _a, _b, _c;
|
|
1599
|
-
const stateKey = 'rowGrouping';
|
|
1600
|
-
const indents = pipeline.ctx.indents;
|
|
1601
|
-
const textOffset = indents.iconIndent + indents.iconWidth + indents.iconGap;
|
|
1602
|
-
const primaryKey = pipeline.ensurePrimaryKey('rowGrouping');
|
|
1603
|
-
if (typeof primaryKey !== 'string') {
|
|
1604
|
-
throw new Error('rowGrouping 仅支持字符串作为 primaryKey');
|
|
1605
|
-
}
|
|
1606
|
-
const openKeys = (_c = (_b = (_a = opts.openKeys) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : (opts.defaultOpenAll ? pipeline.getDataSource().map((row) => row[primaryKey]) : opts.defaultOpenKeys)) !== null && _c !== void 0 ? _c : [];
|
|
1607
|
-
const openKeySet = new Set(openKeys);
|
|
1608
|
-
const onChangeOpenKeys = (nextKeys, key, action) => {
|
|
1609
|
-
var _a;
|
|
1610
|
-
(_a = opts.onChangeOpenKeys) === null || _a === void 0 ? void 0 : _a.call(opts, nextKeys, key, action);
|
|
1611
|
-
pipeline.setStateAtKey(stateKey, nextKeys, { key, action });
|
|
1612
|
-
};
|
|
1613
|
-
return pipeline
|
|
1614
|
-
.mapDataSource(processDataSource)
|
|
1615
|
-
.mapColumns(processColumns)
|
|
1616
|
-
.appendRowPropsGetter(rowGroupingRowPropsGetter);
|
|
1617
|
-
function processDataSource(input) {
|
|
1618
|
-
return flatMap(input, (row) => {
|
|
1619
|
-
let result = [attachGroupingMeta(row)];
|
|
1620
|
-
const expanded = openKeySet.has(row[primaryKey]);
|
|
1621
|
-
if (expanded) {
|
|
1622
|
-
if (Array.isArray(row.children)) {
|
|
1623
|
-
result = result.concat(row.children);
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
return result;
|
|
1627
|
-
});
|
|
1628
|
-
}
|
|
1629
|
-
function processColumns(columns) {
|
|
1630
|
-
if (columns.length === 0) {
|
|
1631
|
-
return columns;
|
|
1632
|
-
}
|
|
1633
|
-
const columnFlatCount = collectNodes(columns, 'leaf-only').length;
|
|
1634
|
-
const [firstCol, ...others] = columns;
|
|
1635
|
-
const render = (value, row, rowIndex) => {
|
|
1636
|
-
var _a, _b;
|
|
1637
|
-
const content = internals.safeRender(firstCol, row, rowIndex);
|
|
1638
|
-
const meta = getGroupingMeta(row);
|
|
1639
|
-
if (!meta.isGroupHeader || !meta.expandable) {
|
|
1640
|
-
const marginLeft = textOffset + (meta.isGroupHeader ? 0 : indents.indentSize);
|
|
1641
|
-
return (React.createElement(InlineFlexCell, { style: { marginLeft } }, meta.isGroupHeader ? (_a = row.groupTitle) !== null && _a !== void 0 ? _a : content : content));
|
|
1642
|
-
}
|
|
1643
|
-
const expanded = openKeySet.has(row[primaryKey]);
|
|
1644
|
-
const expandCls = expanded ? 'expanded' : 'collapsed';
|
|
1645
|
-
return (React.createElement(ExpansionCell, { className: cx('expansion-cell', expandCls) },
|
|
1646
|
-
React.createElement(icons.CaretRight, { className: cx('expansion-icon', expandCls), style: { marginLeft: indents.iconIndent, marginRight: indents.iconGap } }), (_b = row.groupTitle) !== null && _b !== void 0 ? _b : content));
|
|
1647
|
-
};
|
|
1648
|
-
const getCellProps = (value, row, rowIndex) => {
|
|
1649
|
-
var _a;
|
|
1650
|
-
const meta = getGroupingMeta(row);
|
|
1651
|
-
if (!meta.isGroupHeader) {
|
|
1652
|
-
return;
|
|
1653
|
-
}
|
|
1654
|
-
const { expandable } = meta;
|
|
1655
|
-
const rowKey = row[primaryKey];
|
|
1656
|
-
const expanded = openKeySet.has(rowKey);
|
|
1657
|
-
let onClick;
|
|
1658
|
-
if (expandable) {
|
|
1659
|
-
onClick = (e) => {
|
|
1660
|
-
if (opts.stopClickEventPropagation) {
|
|
1661
|
-
e.stopPropagation();
|
|
1662
|
-
}
|
|
1663
|
-
if (expanded) {
|
|
1664
|
-
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'collapse');
|
|
1665
|
-
}
|
|
1666
|
-
else {
|
|
1667
|
-
onChangeOpenKeys([...openKeys, rowKey], rowKey, 'expand');
|
|
1668
|
-
}
|
|
1669
|
-
};
|
|
1670
|
-
}
|
|
1671
|
-
const prevProps = (_a = firstCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(firstCol, value, row, rowIndex);
|
|
1672
|
-
return mergeCellProps(prevProps, {
|
|
1673
|
-
onClick,
|
|
1674
|
-
style: { cursor: expandable ? 'pointer' : undefined },
|
|
1675
|
-
});
|
|
1676
|
-
};
|
|
1677
|
-
return [
|
|
1678
|
-
Object.assign(Object.assign({}, firstCol), { title: (React.createElement("div", { style: { display: 'inline-block', marginLeft: textOffset } }, internals.safeRenderHeader(firstCol))), render,
|
|
1679
|
-
getCellProps,
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1582
|
+
const groupingMetaSymbol = Symbol('row-grouping-meta');
|
|
1583
|
+
function attachGroupingMeta(row) {
|
|
1584
|
+
return Object.assign({ [groupingMetaSymbol]: { expandable: !isLeafNode(row) } }, row);
|
|
1585
|
+
}
|
|
1586
|
+
function getGroupingMeta(row) {
|
|
1587
|
+
if (row[groupingMetaSymbol] == null) {
|
|
1588
|
+
return { isGroupHeader: false, expandable: false };
|
|
1589
|
+
}
|
|
1590
|
+
return { isGroupHeader: true, expandable: row[groupingMetaSymbol].expandable };
|
|
1591
|
+
}
|
|
1592
|
+
function rowGroupingRowPropsGetter(row) {
|
|
1593
|
+
if (getGroupingMeta(row).isGroupHeader) {
|
|
1594
|
+
return { className: 'alternative' };
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
function rowGrouping(opts = {}) {
|
|
1598
|
+
return (pipeline) => {
|
|
1599
|
+
var _a, _b, _c;
|
|
1600
|
+
const stateKey = 'rowGrouping';
|
|
1601
|
+
const indents = pipeline.ctx.indents;
|
|
1602
|
+
const textOffset = indents.iconIndent + indents.iconWidth + indents.iconGap;
|
|
1603
|
+
const primaryKey = pipeline.ensurePrimaryKey('rowGrouping');
|
|
1604
|
+
if (typeof primaryKey !== 'string') {
|
|
1605
|
+
throw new Error('rowGrouping 仅支持字符串作为 primaryKey');
|
|
1606
|
+
}
|
|
1607
|
+
const openKeys = (_c = (_b = (_a = opts.openKeys) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : (opts.defaultOpenAll ? pipeline.getDataSource().map((row) => row[primaryKey]) : opts.defaultOpenKeys)) !== null && _c !== void 0 ? _c : [];
|
|
1608
|
+
const openKeySet = new Set(openKeys);
|
|
1609
|
+
const onChangeOpenKeys = (nextKeys, key, action) => {
|
|
1610
|
+
var _a;
|
|
1611
|
+
(_a = opts.onChangeOpenKeys) === null || _a === void 0 ? void 0 : _a.call(opts, nextKeys, key, action);
|
|
1612
|
+
pipeline.setStateAtKey(stateKey, nextKeys, { key, action });
|
|
1613
|
+
};
|
|
1614
|
+
return pipeline
|
|
1615
|
+
.mapDataSource(processDataSource)
|
|
1616
|
+
.mapColumns(processColumns)
|
|
1617
|
+
.appendRowPropsGetter(rowGroupingRowPropsGetter);
|
|
1618
|
+
function processDataSource(input) {
|
|
1619
|
+
return flatMap(input, (row) => {
|
|
1620
|
+
let result = [attachGroupingMeta(row)];
|
|
1621
|
+
const expanded = openKeySet.has(row[primaryKey]);
|
|
1622
|
+
if (expanded) {
|
|
1623
|
+
if (Array.isArray(row.children)) {
|
|
1624
|
+
result = result.concat(row.children);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
return result;
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
function processColumns(columns) {
|
|
1631
|
+
if (columns.length === 0) {
|
|
1632
|
+
return columns;
|
|
1633
|
+
}
|
|
1634
|
+
const columnFlatCount = collectNodes(columns, 'leaf-only').length;
|
|
1635
|
+
const [firstCol, ...others] = columns;
|
|
1636
|
+
const render = (value, row, rowIndex) => {
|
|
1637
|
+
var _a, _b;
|
|
1638
|
+
const content = internals.safeRender(firstCol, row, rowIndex);
|
|
1639
|
+
const meta = getGroupingMeta(row);
|
|
1640
|
+
if (!meta.isGroupHeader || !meta.expandable) {
|
|
1641
|
+
const marginLeft = textOffset + (meta.isGroupHeader ? 0 : indents.indentSize);
|
|
1642
|
+
return (React.createElement(InlineFlexCell, { style: { marginLeft } }, meta.isGroupHeader ? (_a = row.groupTitle) !== null && _a !== void 0 ? _a : content : content));
|
|
1643
|
+
}
|
|
1644
|
+
const expanded = openKeySet.has(row[primaryKey]);
|
|
1645
|
+
const expandCls = expanded ? 'expanded' : 'collapsed';
|
|
1646
|
+
return (React.createElement(ExpansionCell, { className: cx('expansion-cell', expandCls) },
|
|
1647
|
+
React.createElement(icons.CaretRight, { className: cx('expansion-icon', expandCls), style: { marginLeft: indents.iconIndent, marginRight: indents.iconGap } }), (_b = row.groupTitle) !== null && _b !== void 0 ? _b : content));
|
|
1648
|
+
};
|
|
1649
|
+
const getCellProps = (value, row, rowIndex) => {
|
|
1650
|
+
var _a;
|
|
1651
|
+
const meta = getGroupingMeta(row);
|
|
1652
|
+
if (!meta.isGroupHeader) {
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1655
|
+
const { expandable } = meta;
|
|
1656
|
+
const rowKey = row[primaryKey];
|
|
1657
|
+
const expanded = openKeySet.has(rowKey);
|
|
1658
|
+
let onClick;
|
|
1659
|
+
if (expandable) {
|
|
1660
|
+
onClick = (e) => {
|
|
1661
|
+
if (opts.stopClickEventPropagation) {
|
|
1662
|
+
e.stopPropagation();
|
|
1663
|
+
}
|
|
1664
|
+
if (expanded) {
|
|
1665
|
+
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'collapse');
|
|
1666
|
+
}
|
|
1667
|
+
else {
|
|
1668
|
+
onChangeOpenKeys([...openKeys, rowKey], rowKey, 'expand');
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
const prevProps = (_a = firstCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(firstCol, value, row, rowIndex);
|
|
1673
|
+
return mergeCellProps(prevProps, {
|
|
1674
|
+
onClick,
|
|
1675
|
+
style: { cursor: expandable ? 'pointer' : undefined },
|
|
1676
|
+
});
|
|
1677
|
+
};
|
|
1678
|
+
return [
|
|
1679
|
+
Object.assign(Object.assign({}, firstCol), { title: (React.createElement("div", { style: { display: 'inline-block', marginLeft: textOffset } }, internals.safeRenderHeader(firstCol))), render,
|
|
1680
|
+
getCellProps,
|
|
1681
|
+
getSpanRect(value, row, rowIndex) {
|
|
1682
|
+
if (getGroupingMeta(row).isGroupHeader) {
|
|
1683
|
+
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: columnFlatCount };
|
|
1684
|
+
}
|
|
1685
|
+
} }),
|
|
1686
|
+
...others,
|
|
1687
|
+
];
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1688
1690
|
}
|
|
1689
1691
|
|
|
1690
|
-
function getFirstDefinedValue(...values) {
|
|
1691
|
-
for (let i = 0; i < values.length; i++) {
|
|
1692
|
-
const v = values[i];
|
|
1693
|
-
if (v !== undefined) {
|
|
1694
|
-
return v;
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
function singleSelect(opts = {}) {
|
|
1699
|
-
return function singleSelectStep(pipeline) {
|
|
1700
|
-
var _a, _b, _c;
|
|
1701
|
-
const Radio = pipeline.ctx.components.Radio;
|
|
1702
|
-
if (Radio == null) {
|
|
1703
|
-
throw new Error('使用 singleSelect 之前需要通过 pipeline context 设置 components.Radio');
|
|
1704
|
-
}
|
|
1705
|
-
const stateKey = 'singleSelect';
|
|
1706
|
-
const clickArea = (_a = opts.clickArea) !== null && _a !== void 0 ? _a : 'radio';
|
|
1707
|
-
const isDisabled = (_b = opts.isDisabled) !== null && _b !== void 0 ? _b : always(false);
|
|
1708
|
-
const primaryKey = pipeline.ensurePrimaryKey('singleSelect');
|
|
1709
|
-
const value = getFirstDefinedValue(opts.value, pipeline.getStateAtKey(stateKey), opts.defaultValue);
|
|
1710
|
-
const onChange = (rowKey) => {
|
|
1711
|
-
var _a;
|
|
1712
|
-
(_a = opts.onChange) === null || _a === void 0 ? void 0 : _a.call(opts, rowKey);
|
|
1713
|
-
pipeline.setStateAtKey(stateKey, rowKey);
|
|
1714
|
-
};
|
|
1715
|
-
const radioColumn = Object.assign(Object.assign({ name: '', width: 50, align: 'center' }, opts.radioColumn), { getCellProps(value, row, rowIndex) {
|
|
1716
|
-
if (clickArea === 'cell') {
|
|
1717
|
-
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1718
|
-
const disabled = isDisabled(row, rowIndex);
|
|
1719
|
-
return {
|
|
1720
|
-
style: { cursor: disabled ? 'not-allowed' : 'pointer' },
|
|
1721
|
-
onClick: disabled
|
|
1722
|
-
? undefined
|
|
1723
|
-
: (e) => {
|
|
1724
|
-
if (opts.stopClickEventPropagation) {
|
|
1725
|
-
e.stopPropagation();
|
|
1726
|
-
}
|
|
1727
|
-
onChange(rowKey);
|
|
1728
|
-
},
|
|
1729
|
-
};
|
|
1730
|
-
}
|
|
1731
|
-
}, render: (_, row, rowIndex) => {
|
|
1732
|
-
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1733
|
-
return (React.createElement(Radio, { checked: value === rowKey, disabled: isDisabled(row, rowIndex), onChange: clickArea === 'radio'
|
|
1734
|
-
? (arg1, arg2) => {
|
|
1735
|
-
var _a;
|
|
1736
|
-
const nativeEvent = (_a = arg2 === null || arg2 === void 0 ? void 0 : arg2.nativeEvent) !== null && _a !== void 0 ? _a : arg1 === null || arg1 === void 0 ? void 0 : arg1.nativeEvent;
|
|
1737
|
-
if (nativeEvent && opts.stopClickEventPropagation) {
|
|
1738
|
-
nativeEvent.stopPropagation();
|
|
1739
|
-
}
|
|
1740
|
-
onChange(rowKey);
|
|
1741
|
-
}
|
|
1742
|
-
: undefined }));
|
|
1743
|
-
} });
|
|
1744
|
-
const nextColumns = pipeline.getColumns().slice();
|
|
1745
|
-
const radioPlacement = (_c = opts.radioPlacement) !== null && _c !== void 0 ? _c : 'start';
|
|
1746
|
-
if (radioPlacement === 'start') {
|
|
1747
|
-
nextColumns.unshift(radioColumn);
|
|
1748
|
-
}
|
|
1749
|
-
else {
|
|
1750
|
-
nextColumns.push(radioColumn);
|
|
1751
|
-
}
|
|
1752
|
-
pipeline.columns(nextColumns);
|
|
1753
|
-
pipeline.appendRowPropsGetter((row, rowIndex) => {
|
|
1754
|
-
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1755
|
-
let style = {};
|
|
1756
|
-
let className;
|
|
1757
|
-
let onClick;
|
|
1758
|
-
if (opts.highlightRowWhenSelected) {
|
|
1759
|
-
if (value === rowKey) {
|
|
1760
|
-
className = 'highlight';
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
if (clickArea === 'row' && !isDisabled(row, rowIndex)) {
|
|
1764
|
-
style.cursor = 'pointer';
|
|
1765
|
-
onClick = (e) => {
|
|
1766
|
-
if (opts.stopClickEventPropagation) {
|
|
1767
|
-
e.stopPropagation();
|
|
1768
|
-
}
|
|
1769
|
-
onChange(rowKey);
|
|
1770
|
-
};
|
|
1771
|
-
}
|
|
1772
|
-
return { className, style, onClick };
|
|
1773
|
-
});
|
|
1774
|
-
return pipeline;
|
|
1775
|
-
};
|
|
1692
|
+
function getFirstDefinedValue(...values) {
|
|
1693
|
+
for (let i = 0; i < values.length; i++) {
|
|
1694
|
+
const v = values[i];
|
|
1695
|
+
if (v !== undefined) {
|
|
1696
|
+
return v;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
function singleSelect(opts = {}) {
|
|
1701
|
+
return function singleSelectStep(pipeline) {
|
|
1702
|
+
var _a, _b, _c;
|
|
1703
|
+
const Radio = pipeline.ctx.components.Radio;
|
|
1704
|
+
if (Radio == null) {
|
|
1705
|
+
throw new Error('使用 singleSelect 之前需要通过 pipeline context 设置 components.Radio');
|
|
1706
|
+
}
|
|
1707
|
+
const stateKey = 'singleSelect';
|
|
1708
|
+
const clickArea = (_a = opts.clickArea) !== null && _a !== void 0 ? _a : 'radio';
|
|
1709
|
+
const isDisabled = (_b = opts.isDisabled) !== null && _b !== void 0 ? _b : always(false);
|
|
1710
|
+
const primaryKey = pipeline.ensurePrimaryKey('singleSelect');
|
|
1711
|
+
const value = getFirstDefinedValue(opts.value, pipeline.getStateAtKey(stateKey), opts.defaultValue);
|
|
1712
|
+
const onChange = (rowKey) => {
|
|
1713
|
+
var _a;
|
|
1714
|
+
(_a = opts.onChange) === null || _a === void 0 ? void 0 : _a.call(opts, rowKey);
|
|
1715
|
+
pipeline.setStateAtKey(stateKey, rowKey);
|
|
1716
|
+
};
|
|
1717
|
+
const radioColumn = Object.assign(Object.assign({ name: '', width: 50, align: 'center' }, opts.radioColumn), { getCellProps(value, row, rowIndex) {
|
|
1718
|
+
if (clickArea === 'cell') {
|
|
1719
|
+
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1720
|
+
const disabled = isDisabled(row, rowIndex);
|
|
1721
|
+
return {
|
|
1722
|
+
style: { cursor: disabled ? 'not-allowed' : 'pointer' },
|
|
1723
|
+
onClick: disabled
|
|
1724
|
+
? undefined
|
|
1725
|
+
: (e) => {
|
|
1726
|
+
if (opts.stopClickEventPropagation) {
|
|
1727
|
+
e.stopPropagation();
|
|
1728
|
+
}
|
|
1729
|
+
onChange(rowKey);
|
|
1730
|
+
},
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1733
|
+
}, render: (_, row, rowIndex) => {
|
|
1734
|
+
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1735
|
+
return (React.createElement(Radio, { checked: value === rowKey, disabled: isDisabled(row, rowIndex), onChange: clickArea === 'radio'
|
|
1736
|
+
? (arg1, arg2) => {
|
|
1737
|
+
var _a;
|
|
1738
|
+
const nativeEvent = (_a = arg2 === null || arg2 === void 0 ? void 0 : arg2.nativeEvent) !== null && _a !== void 0 ? _a : arg1 === null || arg1 === void 0 ? void 0 : arg1.nativeEvent;
|
|
1739
|
+
if (nativeEvent && opts.stopClickEventPropagation) {
|
|
1740
|
+
nativeEvent.stopPropagation();
|
|
1741
|
+
}
|
|
1742
|
+
onChange(rowKey);
|
|
1743
|
+
}
|
|
1744
|
+
: undefined }));
|
|
1745
|
+
} });
|
|
1746
|
+
const nextColumns = pipeline.getColumns().slice();
|
|
1747
|
+
const radioPlacement = (_c = opts.radioPlacement) !== null && _c !== void 0 ? _c : 'start';
|
|
1748
|
+
if (radioPlacement === 'start') {
|
|
1749
|
+
nextColumns.unshift(radioColumn);
|
|
1750
|
+
}
|
|
1751
|
+
else {
|
|
1752
|
+
nextColumns.push(radioColumn);
|
|
1753
|
+
}
|
|
1754
|
+
pipeline.columns(nextColumns);
|
|
1755
|
+
pipeline.appendRowPropsGetter((row, rowIndex) => {
|
|
1756
|
+
const rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1757
|
+
let style = {};
|
|
1758
|
+
let className;
|
|
1759
|
+
let onClick;
|
|
1760
|
+
if (opts.highlightRowWhenSelected) {
|
|
1761
|
+
if (value === rowKey) {
|
|
1762
|
+
className = 'highlight';
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
if (clickArea === 'row' && !isDisabled(row, rowIndex)) {
|
|
1766
|
+
style.cursor = 'pointer';
|
|
1767
|
+
onClick = (e) => {
|
|
1768
|
+
if (opts.stopClickEventPropagation) {
|
|
1769
|
+
e.stopPropagation();
|
|
1770
|
+
}
|
|
1771
|
+
onChange(rowKey);
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
return { className, style, onClick };
|
|
1775
|
+
});
|
|
1776
|
+
return pipeline;
|
|
1777
|
+
};
|
|
1776
1778
|
}
|
|
1777
1779
|
|
|
1778
|
-
function SortIcon({ size = 32, style, className, order, onClick }) {
|
|
1779
|
-
return (React.createElement("svg", { style: style, className: className, focusable: "false", preserveAspectRatio: "xMidYMid meet", width: size, height: size, viewBox: "0 0 32 32", "aria-hidden": "true", onClick: onClick },
|
|
1780
|
-
React.createElement("path", { fill: order === 'asc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, 4)", d: "M8 8L16 0 24 8z" }),
|
|
1781
|
-
React.createElement("path", { fill: order === 'desc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, -4)", d: "M24 24L16 32 8 24z " })));
|
|
1782
|
-
}
|
|
1783
|
-
function DefaultSortHeaderCell({ children, column, onToggle, sortOrder, sortIndex, sortOptions, clickArea, }) {
|
|
1784
|
-
// 通过 justify-content 来与 col.align 保持对齐方向一致
|
|
1785
|
-
const justifyContent = column.align === 'right' ? 'flex-end' : column.align === 'center' ? 'center' : 'flex-start';
|
|
1786
|
-
return (React.createElement(TableHeaderCell, { onClick: clickArea === 'content' ? onToggle : undefined, style: {
|
|
1787
|
-
justifyContent,
|
|
1788
|
-
cursor: clickArea === 'content' ? 'pointer' : undefined,
|
|
1789
|
-
} },
|
|
1790
|
-
children,
|
|
1791
|
-
React.createElement(SortIcon, { onClick: clickArea === 'icon' ? onToggle : undefined, style: {
|
|
1792
|
-
userSelect: 'none',
|
|
1793
|
-
marginLeft: 2,
|
|
1794
|
-
flexShrink: 0,
|
|
1795
|
-
cursor: clickArea === 'icon' ? 'pointer' : undefined,
|
|
1796
|
-
}, size: 16, order: sortOrder }),
|
|
1797
|
-
sortOptions.mode === 'multiple' && sortIndex != -1 && (React.createElement("div", { style: {
|
|
1798
|
-
userSelect: 'none',
|
|
1799
|
-
marginLeft: 2,
|
|
1800
|
-
color: '#666',
|
|
1801
|
-
flex: '0 0 auto',
|
|
1802
|
-
fontSize: 10,
|
|
1803
|
-
fontFamily: 'monospace',
|
|
1804
|
-
} }, sortIndex + 1))));
|
|
1805
|
-
}
|
|
1806
|
-
function hasAnySortableColumns(cols) {
|
|
1807
|
-
return cols.some((col) => { var _a; return Boolean((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) || (!isLeafNode(col) && hasAnySortableColumns(col.children)); });
|
|
1808
|
-
}
|
|
1780
|
+
function SortIcon({ size = 32, style, className, order, onClick }) {
|
|
1781
|
+
return (React.createElement("svg", { style: style, className: className, focusable: "false", preserveAspectRatio: "xMidYMid meet", width: size, height: size, viewBox: "0 0 32 32", "aria-hidden": "true", onClick: onClick },
|
|
1782
|
+
React.createElement("path", { fill: order === 'asc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, 4)", d: "M8 8L16 0 24 8z" }),
|
|
1783
|
+
React.createElement("path", { fill: order === 'desc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, -4)", d: "M24 24L16 32 8 24z " })));
|
|
1784
|
+
}
|
|
1785
|
+
function DefaultSortHeaderCell({ children, column, onToggle, sortOrder, sortIndex, sortOptions, clickArea, }) {
|
|
1786
|
+
// 通过 justify-content 来与 col.align 保持对齐方向一致
|
|
1787
|
+
const justifyContent = column.align === 'right' ? 'flex-end' : column.align === 'center' ? 'center' : 'flex-start';
|
|
1788
|
+
return (React.createElement(TableHeaderCell, { onClick: clickArea === 'content' ? onToggle : undefined, style: {
|
|
1789
|
+
justifyContent,
|
|
1790
|
+
cursor: clickArea === 'content' ? 'pointer' : undefined,
|
|
1791
|
+
} },
|
|
1792
|
+
children,
|
|
1793
|
+
React.createElement(SortIcon, { onClick: clickArea === 'icon' ? onToggle : undefined, style: {
|
|
1794
|
+
userSelect: 'none',
|
|
1795
|
+
marginLeft: 2,
|
|
1796
|
+
flexShrink: 0,
|
|
1797
|
+
cursor: clickArea === 'icon' ? 'pointer' : undefined,
|
|
1798
|
+
}, size: 16, order: sortOrder }),
|
|
1799
|
+
sortOptions.mode === 'multiple' && sortIndex != -1 && (React.createElement("div", { style: {
|
|
1800
|
+
userSelect: 'none',
|
|
1801
|
+
marginLeft: 2,
|
|
1802
|
+
color: '#666',
|
|
1803
|
+
flex: '0 0 auto',
|
|
1804
|
+
fontSize: 10,
|
|
1805
|
+
fontFamily: 'monospace',
|
|
1806
|
+
} }, sortIndex + 1))));
|
|
1807
|
+
}
|
|
1808
|
+
function hasAnySortableColumns(cols) {
|
|
1809
|
+
return cols.some((col) => { var _a; return Boolean((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) || (!isLeafNode(col) && hasAnySortableColumns(col.children)); });
|
|
1810
|
+
}
|
|
1809
1811
|
const TableHeaderCell = styled__default.div `
|
|
1810
1812
|
display: flex;
|
|
1811
1813
|
align-items: center;
|
|
1812
|
-
`;
|
|
1813
|
-
const stateKey = 'sort';
|
|
1814
|
-
function sort(opts = {}) {
|
|
1815
|
-
return function sortStep(pipeline) {
|
|
1816
|
-
var _a, _b, _c;
|
|
1817
|
-
const { orders = ['desc', 'asc', 'none'], mode = 'multiple', SortHeaderCell = DefaultSortHeaderCell, keepDataSource, highlightColumnWhenActive, stopClickEventPropagation, clickArea = 'content', } = opts;
|
|
1818
|
-
const inputSorts = (_c = (_b = (_a = opts.sorts) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : opts.defaultSorts) !== null && _c !== void 0 ? _c : [];
|
|
1819
|
-
const activeSorts = inputSorts.filter((s) => s.order !== 'none');
|
|
1820
|
-
// 单字段排序的情况下 sorts 中只有第一个排序字段才会生效
|
|
1821
|
-
const sorts = mode === 'multiple' ? activeSorts : activeSorts.slice(0, 1);
|
|
1822
|
-
const onChangeSortsInMultipleMode = (nextSorts) => {
|
|
1823
|
-
var _a;
|
|
1824
|
-
(_a = opts.onChangeSorts) === null || _a === void 0 ? void 0 : _a.call(opts, nextSorts);
|
|
1825
|
-
pipeline.setStateAtKey(stateKey, nextSorts);
|
|
1826
|
-
};
|
|
1827
|
-
const onChangeSorts = mode === 'multiple'
|
|
1828
|
-
? onChangeSortsInMultipleMode
|
|
1829
|
-
: (nextSorts) => {
|
|
1830
|
-
// 单字段排序的情况下,nextSorts 中只有最后一个排序字段才会生效
|
|
1831
|
-
const len = nextSorts.length;
|
|
1832
|
-
onChangeSortsInMultipleMode(nextSorts.slice(len - 1));
|
|
1833
|
-
};
|
|
1834
|
-
const sortOptions = {
|
|
1835
|
-
sorts,
|
|
1836
|
-
onChangeSorts,
|
|
1837
|
-
orders,
|
|
1838
|
-
mode,
|
|
1839
|
-
keepDataSource,
|
|
1840
|
-
highlightColumnWhenActive,
|
|
1841
|
-
stopClickEventPropagation,
|
|
1842
|
-
clickArea,
|
|
1843
|
-
};
|
|
1844
|
-
const sortMap = new Map(sorts.map((sort, index) => [sort.code, Object.assign({ index }, sort)]));
|
|
1845
|
-
const dataSource = pipeline.getDataSource();
|
|
1846
|
-
const columns = pipeline.getColumns();
|
|
1847
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1848
|
-
if (!hasAnySortableColumns(columns)) {
|
|
1849
|
-
console.warn('[srp-table] commonTransform.sort 缺少可排序的列,请通过 column.features.sortable 来指定哪些列可排序', columns);
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
pipeline.dataSource(processDataSource(dataSource));
|
|
1853
|
-
pipeline.columns(processColumns(columns));
|
|
1854
|
-
return pipeline;
|
|
1855
|
-
function processDataSource(dataSource) {
|
|
1856
|
-
if (keepDataSource) {
|
|
1857
|
-
return dataSource;
|
|
1858
|
-
}
|
|
1859
|
-
const sortColumnsMap = new Map(collectNodes(columns, 'leaf-only')
|
|
1860
|
-
.filter((col) => { var _a, _b; return ((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) !== false && ((_b = col.features) === null || _b === void 0 ? void 0 : _b.sortable) != null; })
|
|
1861
|
-
.map((col) => [col.code, col]));
|
|
1862
|
-
return layeredSort(dataSource, (x, y) => {
|
|
1863
|
-
for (const { code, order } of sorts) {
|
|
1864
|
-
const column = sortColumnsMap.get(code);
|
|
1865
|
-
// 如果 code 对应的 column 不可排序,我们跳过该 code
|
|
1866
|
-
if (column == null) {
|
|
1867
|
-
continue;
|
|
1868
|
-
}
|
|
1869
|
-
const sortable = column.features.sortable;
|
|
1870
|
-
const compareFn = typeof sortable === 'function' ? sortable : smartCompare;
|
|
1871
|
-
const xValue = internals.safeGetValue(column, x, -1);
|
|
1872
|
-
const yValue = internals.safeGetValue(column, y, -1);
|
|
1873
|
-
const cmp = compareFn(xValue, yValue, x, y);
|
|
1874
|
-
if (cmp !== 0) {
|
|
1875
|
-
return cmp * (order === 'asc' ? 1 : -1);
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
return 0;
|
|
1879
|
-
});
|
|
1880
|
-
}
|
|
1881
|
-
// 在「升序 - 降序 - 不排序」之间不断切换
|
|
1882
|
-
function toggle(code) {
|
|
1883
|
-
const sort = sortMap.get(code);
|
|
1884
|
-
if (sort == null) {
|
|
1885
|
-
onChangeSorts(sorts.concat([{ code, order: orders[0] }]));
|
|
1886
|
-
}
|
|
1887
|
-
else {
|
|
1888
|
-
const index = sorts.findIndex((s) => s.code === code);
|
|
1889
|
-
const nextSorts = sorts.slice(0, index + 1);
|
|
1890
|
-
const nextOrder = getNextOrder(sort.order);
|
|
1891
|
-
if (nextOrder === 'none') {
|
|
1892
|
-
nextSorts.pop();
|
|
1893
|
-
}
|
|
1894
|
-
else {
|
|
1895
|
-
nextSorts[index] = Object.assign(Object.assign({}, nextSorts[index]), { order: nextOrder });
|
|
1896
|
-
}
|
|
1897
|
-
onChangeSorts(nextSorts);
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
function processColumns(columns) {
|
|
1901
|
-
return columns.map(dfs);
|
|
1902
|
-
function dfs(col) {
|
|
1903
|
-
var _a;
|
|
1904
|
-
const result = Object.assign({}, col);
|
|
1905
|
-
const sortable = col.code && (((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) || sortMap.has(col.code));
|
|
1906
|
-
const active = sortable && sortMap.has(col.code);
|
|
1907
|
-
if (sortable) {
|
|
1908
|
-
let sortIndex = -1;
|
|
1909
|
-
let sortOrder = 'none';
|
|
1910
|
-
if (active) {
|
|
1911
|
-
const { order, index } = sortMap.get(col.code);
|
|
1912
|
-
sortOrder = order;
|
|
1913
|
-
sortIndex = index;
|
|
1914
|
-
if (highlightColumnWhenActive) {
|
|
1915
|
-
result.headerCellProps = mergeCellProps(col.headerCellProps, {
|
|
1916
|
-
style: { background: 'var(--header-highlight-bgcolor)' },
|
|
1917
|
-
});
|
|
1918
|
-
result.getCellProps = (value, row, rowIndex) => {
|
|
1919
|
-
const prevCellProps = internals.safeGetCellProps(col, row, rowIndex);
|
|
1920
|
-
return mergeCellProps(prevCellProps, {
|
|
1921
|
-
style: { background: 'var(--highlight-bgcolor)' },
|
|
1922
|
-
});
|
|
1923
|
-
};
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
result.title = (React.createElement(SortHeaderCell, { clickArea: clickArea, onToggle: (e) => {
|
|
1927
|
-
if (stopClickEventPropagation) {
|
|
1928
|
-
e.stopPropagation();
|
|
1929
|
-
}
|
|
1930
|
-
toggle(col.code);
|
|
1931
|
-
}, sortOrder: sortOrder, column: col, sortIndex: sortIndex, sortOptions: sortOptions }, internals.safeRenderHeader(col)));
|
|
1932
|
-
}
|
|
1933
|
-
if (!isLeafNode(col)) {
|
|
1934
|
-
result.children = col.children.map(dfs);
|
|
1935
|
-
}
|
|
1936
|
-
return result;
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
function getNextOrder(order) {
|
|
1940
|
-
const idx = orders.indexOf(order);
|
|
1941
|
-
return orders[idx === orders.length - 1 ? 0 : idx + 1];
|
|
1942
|
-
}
|
|
1943
|
-
};
|
|
1814
|
+
`;
|
|
1815
|
+
const stateKey = 'sort';
|
|
1816
|
+
function sort(opts = {}) {
|
|
1817
|
+
return function sortStep(pipeline) {
|
|
1818
|
+
var _a, _b, _c;
|
|
1819
|
+
const { orders = ['desc', 'asc', 'none'], mode = 'multiple', SortHeaderCell = DefaultSortHeaderCell, keepDataSource, highlightColumnWhenActive, stopClickEventPropagation, clickArea = 'content', } = opts;
|
|
1820
|
+
const inputSorts = (_c = (_b = (_a = opts.sorts) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : opts.defaultSorts) !== null && _c !== void 0 ? _c : [];
|
|
1821
|
+
const activeSorts = inputSorts.filter((s) => s.order !== 'none');
|
|
1822
|
+
// 单字段排序的情况下 sorts 中只有第一个排序字段才会生效
|
|
1823
|
+
const sorts = mode === 'multiple' ? activeSorts : activeSorts.slice(0, 1);
|
|
1824
|
+
const onChangeSortsInMultipleMode = (nextSorts) => {
|
|
1825
|
+
var _a;
|
|
1826
|
+
(_a = opts.onChangeSorts) === null || _a === void 0 ? void 0 : _a.call(opts, nextSorts);
|
|
1827
|
+
pipeline.setStateAtKey(stateKey, nextSorts);
|
|
1828
|
+
};
|
|
1829
|
+
const onChangeSorts = mode === 'multiple'
|
|
1830
|
+
? onChangeSortsInMultipleMode
|
|
1831
|
+
: (nextSorts) => {
|
|
1832
|
+
// 单字段排序的情况下,nextSorts 中只有最后一个排序字段才会生效
|
|
1833
|
+
const len = nextSorts.length;
|
|
1834
|
+
onChangeSortsInMultipleMode(nextSorts.slice(len - 1));
|
|
1835
|
+
};
|
|
1836
|
+
const sortOptions = {
|
|
1837
|
+
sorts,
|
|
1838
|
+
onChangeSorts,
|
|
1839
|
+
orders,
|
|
1840
|
+
mode,
|
|
1841
|
+
keepDataSource,
|
|
1842
|
+
highlightColumnWhenActive,
|
|
1843
|
+
stopClickEventPropagation,
|
|
1844
|
+
clickArea,
|
|
1845
|
+
};
|
|
1846
|
+
const sortMap = new Map(sorts.map((sort, index) => [sort.code, Object.assign({ index }, sort)]));
|
|
1847
|
+
const dataSource = pipeline.getDataSource();
|
|
1848
|
+
const columns = pipeline.getColumns();
|
|
1849
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1850
|
+
if (!hasAnySortableColumns(columns)) {
|
|
1851
|
+
console.warn('[srp-table] commonTransform.sort 缺少可排序的列,请通过 column.features.sortable 来指定哪些列可排序', columns);
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
pipeline.dataSource(processDataSource(dataSource));
|
|
1855
|
+
pipeline.columns(processColumns(columns));
|
|
1856
|
+
return pipeline;
|
|
1857
|
+
function processDataSource(dataSource) {
|
|
1858
|
+
if (keepDataSource) {
|
|
1859
|
+
return dataSource;
|
|
1860
|
+
}
|
|
1861
|
+
const sortColumnsMap = new Map(collectNodes(columns, 'leaf-only')
|
|
1862
|
+
.filter((col) => { var _a, _b; return ((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) !== false && ((_b = col.features) === null || _b === void 0 ? void 0 : _b.sortable) != null; })
|
|
1863
|
+
.map((col) => [col.code, col]));
|
|
1864
|
+
return layeredSort(dataSource, (x, y) => {
|
|
1865
|
+
for (const { code, order } of sorts) {
|
|
1866
|
+
const column = sortColumnsMap.get(code);
|
|
1867
|
+
// 如果 code 对应的 column 不可排序,我们跳过该 code
|
|
1868
|
+
if (column == null) {
|
|
1869
|
+
continue;
|
|
1870
|
+
}
|
|
1871
|
+
const sortable = column.features.sortable;
|
|
1872
|
+
const compareFn = typeof sortable === 'function' ? sortable : smartCompare;
|
|
1873
|
+
const xValue = internals.safeGetValue(column, x, -1);
|
|
1874
|
+
const yValue = internals.safeGetValue(column, y, -1);
|
|
1875
|
+
const cmp = compareFn(xValue, yValue, x, y);
|
|
1876
|
+
if (cmp !== 0) {
|
|
1877
|
+
return cmp * (order === 'asc' ? 1 : -1);
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
return 0;
|
|
1881
|
+
});
|
|
1882
|
+
}
|
|
1883
|
+
// 在「升序 - 降序 - 不排序」之间不断切换
|
|
1884
|
+
function toggle(code) {
|
|
1885
|
+
const sort = sortMap.get(code);
|
|
1886
|
+
if (sort == null) {
|
|
1887
|
+
onChangeSorts(sorts.concat([{ code, order: orders[0] }]));
|
|
1888
|
+
}
|
|
1889
|
+
else {
|
|
1890
|
+
const index = sorts.findIndex((s) => s.code === code);
|
|
1891
|
+
const nextSorts = sorts.slice(0, index + 1);
|
|
1892
|
+
const nextOrder = getNextOrder(sort.order);
|
|
1893
|
+
if (nextOrder === 'none') {
|
|
1894
|
+
nextSorts.pop();
|
|
1895
|
+
}
|
|
1896
|
+
else {
|
|
1897
|
+
nextSorts[index] = Object.assign(Object.assign({}, nextSorts[index]), { order: nextOrder });
|
|
1898
|
+
}
|
|
1899
|
+
onChangeSorts(nextSorts);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
function processColumns(columns) {
|
|
1903
|
+
return columns.map(dfs);
|
|
1904
|
+
function dfs(col) {
|
|
1905
|
+
var _a;
|
|
1906
|
+
const result = Object.assign({}, col);
|
|
1907
|
+
const sortable = col.code && (((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) || sortMap.has(col.code));
|
|
1908
|
+
const active = sortable && sortMap.has(col.code);
|
|
1909
|
+
if (sortable) {
|
|
1910
|
+
let sortIndex = -1;
|
|
1911
|
+
let sortOrder = 'none';
|
|
1912
|
+
if (active) {
|
|
1913
|
+
const { order, index } = sortMap.get(col.code);
|
|
1914
|
+
sortOrder = order;
|
|
1915
|
+
sortIndex = index;
|
|
1916
|
+
if (highlightColumnWhenActive) {
|
|
1917
|
+
result.headerCellProps = mergeCellProps(col.headerCellProps, {
|
|
1918
|
+
style: { background: 'var(--header-highlight-bgcolor)' },
|
|
1919
|
+
});
|
|
1920
|
+
result.getCellProps = (value, row, rowIndex) => {
|
|
1921
|
+
const prevCellProps = internals.safeGetCellProps(col, row, rowIndex);
|
|
1922
|
+
return mergeCellProps(prevCellProps, {
|
|
1923
|
+
style: { background: 'var(--highlight-bgcolor)' },
|
|
1924
|
+
});
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
result.title = (React.createElement(SortHeaderCell, { clickArea: clickArea, onToggle: (e) => {
|
|
1929
|
+
if (stopClickEventPropagation) {
|
|
1930
|
+
e.stopPropagation();
|
|
1931
|
+
}
|
|
1932
|
+
toggle(col.code);
|
|
1933
|
+
}, sortOrder: sortOrder, column: col, sortIndex: sortIndex, sortOptions: sortOptions }, internals.safeRenderHeader(col)));
|
|
1934
|
+
}
|
|
1935
|
+
if (!isLeafNode(col)) {
|
|
1936
|
+
result.children = col.children.map(dfs);
|
|
1937
|
+
}
|
|
1938
|
+
return result;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
function getNextOrder(order) {
|
|
1942
|
+
const idx = orders.indexOf(order);
|
|
1943
|
+
return orders[idx === orders.length - 1 ? 0 : idx + 1];
|
|
1944
|
+
}
|
|
1945
|
+
};
|
|
1944
1946
|
}
|
|
1945
1947
|
|
|
1946
1948
|
const HeaderCellWithTips = styled__default.div `
|
|
@@ -1955,524 +1957,525 @@ const HeaderCellWithTips = styled__default.div `
|
|
|
1955
1957
|
display: flex;
|
|
1956
1958
|
fill: currentColor;
|
|
1957
1959
|
}
|
|
1958
|
-
`;
|
|
1959
|
-
function tips() {
|
|
1960
|
-
return function tipsSteap(pipeline) {
|
|
1961
|
-
const Balloon = pipeline.ctx.components.Balloon;
|
|
1962
|
-
const Tooltip = pipeline.ctx.components.Tooltip;
|
|
1963
|
-
if (Balloon == null && Tooltip == null) {
|
|
1964
|
-
throw new Error('使用 tips 之前需要通过 pipeline context 设置 components.Balloon / components.Tooltip');
|
|
1965
|
-
}
|
|
1966
|
-
return pipeline.mapColumns(makeRecursiveMapper((col) => {
|
|
1967
|
-
var _a;
|
|
1968
|
-
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.tips)) {
|
|
1969
|
-
return col;
|
|
1970
|
-
}
|
|
1971
|
-
const justifyContent = col.align === 'right' ? 'flex-end' : col.align === 'center' ? 'center' : 'flex-start';
|
|
1972
|
-
return Object.assign(Object.assign({}, col), { title: (React.createElement(HeaderCellWithTips, { style: { justifyContent } },
|
|
1973
|
-
internals.safeRenderHeader(col),
|
|
1974
|
-
Balloon ? (
|
|
1975
|
-
// fusion/hippo
|
|
1976
|
-
React.createElement(Balloon, { closable: false, trigger: React.createElement("div", { className: "tip-icon-wrapper" },
|
|
1977
|
-
React.createElement(icons.Info, { className: "tip-icon" })) }, col.features.tips)) : (
|
|
1978
|
-
// antd
|
|
1979
|
-
React.createElement(Tooltip, { title: col.features.tips },
|
|
1980
|
-
React.createElement("div", { className: "tip-icon-wrapper" },
|
|
1981
|
-
React.createElement(icons.Info, { className: "tip-icon" })))))) });
|
|
1982
|
-
}));
|
|
1983
|
-
};
|
|
1960
|
+
`;
|
|
1961
|
+
function tips() {
|
|
1962
|
+
return function tipsSteap(pipeline) {
|
|
1963
|
+
const Balloon = pipeline.ctx.components.Balloon;
|
|
1964
|
+
const Tooltip = pipeline.ctx.components.Tooltip;
|
|
1965
|
+
if (Balloon == null && Tooltip == null) {
|
|
1966
|
+
throw new Error('使用 tips 之前需要通过 pipeline context 设置 components.Balloon / components.Tooltip');
|
|
1967
|
+
}
|
|
1968
|
+
return pipeline.mapColumns(makeRecursiveMapper((col) => {
|
|
1969
|
+
var _a;
|
|
1970
|
+
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.tips)) {
|
|
1971
|
+
return col;
|
|
1972
|
+
}
|
|
1973
|
+
const justifyContent = col.align === 'right' ? 'flex-end' : col.align === 'center' ? 'center' : 'flex-start';
|
|
1974
|
+
return Object.assign(Object.assign({}, col), { title: (React.createElement(HeaderCellWithTips, { style: { justifyContent } },
|
|
1975
|
+
internals.safeRenderHeader(col),
|
|
1976
|
+
Balloon ? (
|
|
1977
|
+
// fusion/hippo
|
|
1978
|
+
React.createElement(Balloon, { closable: false, trigger: React.createElement("div", { className: "tip-icon-wrapper" },
|
|
1979
|
+
React.createElement(icons.Info, { className: "tip-icon" })) }, col.features.tips)) : (
|
|
1980
|
+
// antd
|
|
1981
|
+
React.createElement(Tooltip, { title: col.features.tips },
|
|
1982
|
+
React.createElement("div", { className: "tip-icon-wrapper" },
|
|
1983
|
+
React.createElement(icons.Info, { className: "tip-icon" })))))) });
|
|
1984
|
+
}));
|
|
1985
|
+
};
|
|
1984
1986
|
}
|
|
1985
1987
|
|
|
1986
|
-
class Wrapper$1 {
|
|
1987
|
-
constructor(input) {
|
|
1988
|
-
Object.assign(this, input);
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
class StrictTreeDataHelper {
|
|
1992
|
-
constructor(opts) {
|
|
1993
|
-
this.opts = opts;
|
|
1994
|
-
this.valueSet = new Set(opts.value);
|
|
1995
|
-
this.initWrapperTree();
|
|
1996
|
-
}
|
|
1997
|
-
initWrapperTree() {
|
|
1998
|
-
const { getNodeValue } = this.opts;
|
|
1999
|
-
this.rootWrapper = new Wrapper$1({ root: true, children: [] });
|
|
2000
|
-
this.wrapperMap = new Map();
|
|
2001
|
-
const dfs = (parentWrapper, nodes) => {
|
|
2002
|
-
for (const node of nodes) {
|
|
2003
|
-
const wrapper = new Wrapper$1({
|
|
2004
|
-
parent: parentWrapper,
|
|
2005
|
-
node,
|
|
2006
|
-
checked: this.valueSet.has(getNodeValue(node)),
|
|
2007
|
-
});
|
|
2008
|
-
this.wrapperMap.set(getNodeValue(node), wrapper);
|
|
2009
|
-
parentWrapper.children.push(wrapper);
|
|
2010
|
-
if (!isLeafNode(node)) {
|
|
2011
|
-
wrapper.children = [];
|
|
2012
|
-
dfs(wrapper, node.children);
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
};
|
|
2016
|
-
dfs(this.rootWrapper, this.opts.tree);
|
|
2017
|
-
}
|
|
2018
|
-
get value() {
|
|
2019
|
-
return this.opts.value;
|
|
2020
|
-
}
|
|
2021
|
-
isIndeterminate(nodeValue) {
|
|
2022
|
-
return false;
|
|
2023
|
-
}
|
|
2024
|
-
isChecked(nodeValue) {
|
|
2025
|
-
return this.valueSet.has(nodeValue);
|
|
2026
|
-
}
|
|
2027
|
-
getValueAfterCheck(nodeValue) {
|
|
2028
|
-
if (!this.isChecked(nodeValue)) {
|
|
2029
|
-
return arrayUtils.merge(this.value, [nodeValue]);
|
|
2030
|
-
}
|
|
2031
|
-
return this.value;
|
|
2032
|
-
}
|
|
2033
|
-
getValueAfterUncheck(nodeValue) {
|
|
2034
|
-
if (this.isChecked(nodeValue)) {
|
|
2035
|
-
return arrayUtils.diff(this.value, [nodeValue]);
|
|
2036
|
-
}
|
|
2037
|
-
return this.value;
|
|
2038
|
-
}
|
|
2039
|
-
getValueAfterToggle(nodeValue) {
|
|
2040
|
-
if (this.isChecked(nodeValue)) {
|
|
2041
|
-
return this.getValueAfterUncheck(nodeValue);
|
|
2042
|
-
}
|
|
2043
|
-
else {
|
|
2044
|
-
return this.getValueAfterCheck(nodeValue);
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
getNode(nodeValue) {
|
|
2048
|
-
var _a;
|
|
2049
|
-
return (_a = this.wrapperMap.get(nodeValue)) === null || _a === void 0 ? void 0 : _a.node;
|
|
2050
|
-
}
|
|
2051
|
-
getCleanValue() {
|
|
2052
|
-
return this.value;
|
|
2053
|
-
}
|
|
1988
|
+
class Wrapper$1 {
|
|
1989
|
+
constructor(input) {
|
|
1990
|
+
Object.assign(this, input);
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
class StrictTreeDataHelper {
|
|
1994
|
+
constructor(opts) {
|
|
1995
|
+
this.opts = opts;
|
|
1996
|
+
this.valueSet = new Set(opts.value);
|
|
1997
|
+
this.initWrapperTree();
|
|
1998
|
+
}
|
|
1999
|
+
initWrapperTree() {
|
|
2000
|
+
const { getNodeValue } = this.opts;
|
|
2001
|
+
this.rootWrapper = new Wrapper$1({ root: true, children: [] });
|
|
2002
|
+
this.wrapperMap = new Map();
|
|
2003
|
+
const dfs = (parentWrapper, nodes) => {
|
|
2004
|
+
for (const node of nodes) {
|
|
2005
|
+
const wrapper = new Wrapper$1({
|
|
2006
|
+
parent: parentWrapper,
|
|
2007
|
+
node,
|
|
2008
|
+
checked: this.valueSet.has(getNodeValue(node)),
|
|
2009
|
+
});
|
|
2010
|
+
this.wrapperMap.set(getNodeValue(node), wrapper);
|
|
2011
|
+
parentWrapper.children.push(wrapper);
|
|
2012
|
+
if (!isLeafNode(node)) {
|
|
2013
|
+
wrapper.children = [];
|
|
2014
|
+
dfs(wrapper, node.children);
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
dfs(this.rootWrapper, this.opts.tree);
|
|
2019
|
+
}
|
|
2020
|
+
get value() {
|
|
2021
|
+
return this.opts.value;
|
|
2022
|
+
}
|
|
2023
|
+
isIndeterminate(nodeValue) {
|
|
2024
|
+
return false;
|
|
2025
|
+
}
|
|
2026
|
+
isChecked(nodeValue) {
|
|
2027
|
+
return this.valueSet.has(nodeValue);
|
|
2028
|
+
}
|
|
2029
|
+
getValueAfterCheck(nodeValue) {
|
|
2030
|
+
if (!this.isChecked(nodeValue)) {
|
|
2031
|
+
return arrayUtils.merge(this.value, [nodeValue]);
|
|
2032
|
+
}
|
|
2033
|
+
return this.value;
|
|
2034
|
+
}
|
|
2035
|
+
getValueAfterUncheck(nodeValue) {
|
|
2036
|
+
if (this.isChecked(nodeValue)) {
|
|
2037
|
+
return arrayUtils.diff(this.value, [nodeValue]);
|
|
2038
|
+
}
|
|
2039
|
+
return this.value;
|
|
2040
|
+
}
|
|
2041
|
+
getValueAfterToggle(nodeValue) {
|
|
2042
|
+
if (this.isChecked(nodeValue)) {
|
|
2043
|
+
return this.getValueAfterUncheck(nodeValue);
|
|
2044
|
+
}
|
|
2045
|
+
else {
|
|
2046
|
+
return this.getValueAfterCheck(nodeValue);
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
getNode(nodeValue) {
|
|
2050
|
+
var _a;
|
|
2051
|
+
return (_a = this.wrapperMap.get(nodeValue)) === null || _a === void 0 ? void 0 : _a.node;
|
|
2052
|
+
}
|
|
2053
|
+
getCleanValue() {
|
|
2054
|
+
return this.value;
|
|
2055
|
+
}
|
|
2054
2056
|
}
|
|
2055
2057
|
|
|
2056
|
-
class Wrapper {
|
|
2057
|
-
constructor(input) {
|
|
2058
|
-
Object.assign(this, input);
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
class TreeDataHelper {
|
|
2062
|
-
constructor(opts) {
|
|
2063
|
-
this.isDetached = (node) => {
|
|
2064
|
-
var _a, _b, _c;
|
|
2065
|
-
return (_c = (_b = (_a = this.opts).isDetached) === null || _b === void 0 ? void 0 : _b.call(_a, node)) !== null && _c !== void 0 ? _c : false;
|
|
2066
|
-
};
|
|
2067
|
-
this.opts = opts;
|
|
2068
|
-
this.valueSet = new Set(opts.value);
|
|
2069
|
-
this.initWrapperTree();
|
|
2070
|
-
}
|
|
2071
|
-
get value() {
|
|
2072
|
-
return this.opts.value;
|
|
2073
|
-
}
|
|
2074
|
-
initWrapperTree() {
|
|
2075
|
-
const valueSet = new Set(this.value);
|
|
2076
|
-
this.rootWrapper = new Wrapper({ root: true, children: [] });
|
|
2077
|
-
this.wrapperMap = new Map();
|
|
2078
|
-
const getNodeValue = this.opts.getNodeValue;
|
|
2079
|
-
const { isDetached, wrapperMap } = this;
|
|
2080
|
-
dfs(this.rootWrapper, this.opts.tree, false);
|
|
2081
|
-
function dfs(parentWrapper, nodes, inheritParentChecked) {
|
|
2082
|
-
// allChildrenChecked 先默认设置为 true
|
|
2083
|
-
// dfs 过程中可能会更新 allChildrenChecked
|
|
2084
|
-
parentWrapper.allChildrenChecked = true;
|
|
2085
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2086
|
-
if (nodes.every(isDetached)) {
|
|
2087
|
-
console.warn('TreeDataHelper 检测到部分节点的下所有子节点均为 detached 状态,这将导致该节点变为「无效节点」', parentWrapper.node);
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
for (const node of nodes) {
|
|
2091
|
-
const detached = isDetached(node);
|
|
2092
|
-
const exactChecked = valueSet.has(getNodeValue(node));
|
|
2093
|
-
if (exactChecked && !detached) {
|
|
2094
|
-
parentWrapper.anyDescendentsChecked = true;
|
|
2095
|
-
}
|
|
2096
|
-
const parentChecked = !detached && inheritParentChecked;
|
|
2097
|
-
const checked = exactChecked || parentChecked;
|
|
2098
|
-
const wrapper = new Wrapper({
|
|
2099
|
-
parent: parentWrapper,
|
|
2100
|
-
node,
|
|
2101
|
-
checked,
|
|
2102
|
-
exactChecked,
|
|
2103
|
-
parentChecked,
|
|
2104
|
-
anyDescendentsChecked: checked,
|
|
2105
|
-
detached,
|
|
2106
|
-
});
|
|
2107
|
-
wrapperMap.set(getNodeValue(node), wrapper);
|
|
2108
|
-
parentWrapper.children.push(wrapper);
|
|
2109
|
-
if (!isLeafNode(node)) {
|
|
2110
|
-
wrapper.children = [];
|
|
2111
|
-
dfs(wrapper, node.children, checked);
|
|
2112
|
-
if (wrapper.anyDescendentsChecked && !detached) {
|
|
2113
|
-
parentWrapper.anyDescendentsChecked = true;
|
|
2114
|
-
}
|
|
2115
|
-
if (wrapper.allChildrenChecked) {
|
|
2116
|
-
wrapper.checked = true;
|
|
2117
|
-
// 当一个节点因为「子节点被全选」而变为 checked 时,我们需要更新子节点的 parentChecked 字段
|
|
2118
|
-
for (const child of wrapper.children) {
|
|
2119
|
-
if (!child.detached) {
|
|
2120
|
-
child.parentChecked = true;
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
if (!wrapper.checked && !detached) {
|
|
2126
|
-
parentWrapper.allChildrenChecked = false;
|
|
2127
|
-
}
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
isIndeterminate(nodeValue) {
|
|
2132
|
-
const wrapper = this.wrapperMap.get(nodeValue);
|
|
2133
|
-
return !wrapper.checked && wrapper.anyDescendentsChecked;
|
|
2134
|
-
}
|
|
2135
|
-
isChecked(nodeValue) {
|
|
2136
|
-
const wrapper = this.wrapperMap.get(nodeValue);
|
|
2137
|
-
return wrapper.checked;
|
|
2138
|
-
}
|
|
2139
|
-
getValueAfterCheck(nodeValue) {
|
|
2140
|
-
if (this.isChecked(nodeValue)) {
|
|
2141
|
-
return this.getCleanValue();
|
|
2142
|
-
}
|
|
2143
|
-
const nextValue = arrayUtils.merge(this.value, [nodeValue]);
|
|
2144
|
-
return new TreeDataHelper(Object.assign(Object.assign({}, this.opts), { value: nextValue })).getCleanValue();
|
|
2145
|
-
}
|
|
2146
|
-
getValueAfterUncheck(nodeValue) {
|
|
2147
|
-
if (!this.isChecked(nodeValue)) {
|
|
2148
|
-
return this.getCleanValue();
|
|
2149
|
-
}
|
|
2150
|
-
const wrapper = this.wrapperMap.get(nodeValue);
|
|
2151
|
-
const { getNodeValue } = this.opts;
|
|
2152
|
-
const appendArray = getAppendArray(wrapper);
|
|
2153
|
-
const removeSet = getRemoveSet(wrapper);
|
|
2154
|
-
const nextValue = arrayUtils.diff(this.value.concat(appendArray), removeSet);
|
|
2155
|
-
return new TreeDataHelper(Object.assign(Object.assign({}, this.opts), { value: nextValue })).getCleanValue();
|
|
2156
|
-
function getAppendArray(startWrapper) {
|
|
2157
|
-
let result = [];
|
|
2158
|
-
let current = startWrapper;
|
|
2159
|
-
while (current.parentChecked && !current.detached) {
|
|
2160
|
-
for (const sibling of current.parent.children) {
|
|
2161
|
-
if (sibling === current || sibling.exactChecked || sibling.detached) {
|
|
2162
|
-
continue;
|
|
2163
|
-
}
|
|
2164
|
-
result.push(getNodeValue(sibling.node));
|
|
2165
|
-
}
|
|
2166
|
-
current = current.parent;
|
|
2167
|
-
}
|
|
2168
|
-
return result;
|
|
2169
|
-
}
|
|
2170
|
-
function getRemoveSet(startWrapper) {
|
|
2171
|
-
const result = new Set();
|
|
2172
|
-
let wrapper = startWrapper;
|
|
2173
|
-
// 不断向上收集选中的父节点
|
|
2174
|
-
while (true) {
|
|
2175
|
-
result.add(getNodeValue(wrapper.node));
|
|
2176
|
-
if (wrapper.detached || !wrapper.parentChecked) {
|
|
2177
|
-
break;
|
|
2178
|
-
}
|
|
2179
|
-
wrapper = wrapper.parent;
|
|
2180
|
-
}
|
|
2181
|
-
function dfs(wrappers) {
|
|
2182
|
-
if (wrappers == null) {
|
|
2183
|
-
return;
|
|
2184
|
-
}
|
|
2185
|
-
for (const wrapper of wrappers) {
|
|
2186
|
-
if (wrapper.detached || !wrapper.checked) {
|
|
2187
|
-
continue;
|
|
2188
|
-
}
|
|
2189
|
-
result.add(getNodeValue(wrapper.node));
|
|
2190
|
-
if (!isLeafNode(wrapper) && wrapper.anyDescendentsChecked) {
|
|
2191
|
-
dfs(wrapper.children);
|
|
2192
|
-
}
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
// 收集所有的子孙节点
|
|
2196
|
-
dfs(startWrapper.children);
|
|
2197
|
-
return result;
|
|
2198
|
-
}
|
|
2199
|
-
}
|
|
2200
|
-
getValueAfterToggle(nodeValue) {
|
|
2201
|
-
if (this.isChecked(nodeValue)) {
|
|
2202
|
-
return this.getValueAfterUncheck(nodeValue);
|
|
2203
|
-
}
|
|
2204
|
-
else {
|
|
2205
|
-
return this.getValueAfterCheck(nodeValue);
|
|
2206
|
-
}
|
|
2207
|
-
}
|
|
2208
|
-
getNode(nodeValue) {
|
|
2209
|
-
var _a;
|
|
2210
|
-
return (_a = this.wrapperMap.get(nodeValue)) === null || _a === void 0 ? void 0 : _a.node;
|
|
2211
|
-
}
|
|
2212
|
-
getCleanValue() {
|
|
2213
|
-
const { checkedStrategy, getNodeValue } = this.opts;
|
|
2214
|
-
const result = this.value.filter((nodeValue) => {
|
|
2215
|
-
return !this.wrapperMap.has(nodeValue);
|
|
2216
|
-
});
|
|
2217
|
-
dfs(this.rootWrapper.children);
|
|
2218
|
-
return result;
|
|
2219
|
-
function dfs(wrappers) {
|
|
2220
|
-
for (const wrapper of wrappers) {
|
|
2221
|
-
if (wrapper.checked) {
|
|
2222
|
-
if (checkedStrategy === 'all') {
|
|
2223
|
-
result.push(getNodeValue(wrapper.node));
|
|
2224
|
-
}
|
|
2225
|
-
else if (checkedStrategy === 'parent') {
|
|
2226
|
-
if (!wrapper.parentChecked) {
|
|
2227
|
-
result.push(getNodeValue(wrapper.node));
|
|
2228
|
-
}
|
|
2229
|
-
}
|
|
2230
|
-
else {
|
|
2231
|
-
// checkedStrategy === 'child'
|
|
2232
|
-
if (isLeafNode(wrapper)) {
|
|
2233
|
-
result.push(getNodeValue(wrapper.node));
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
}
|
|
2237
|
-
if (!isLeafNode(wrapper)) {
|
|
2238
|
-
dfs(wrapper.children);
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2242
|
-
}
|
|
2058
|
+
class Wrapper {
|
|
2059
|
+
constructor(input) {
|
|
2060
|
+
Object.assign(this, input);
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
class TreeDataHelper {
|
|
2064
|
+
constructor(opts) {
|
|
2065
|
+
this.isDetached = (node) => {
|
|
2066
|
+
var _a, _b, _c;
|
|
2067
|
+
return (_c = (_b = (_a = this.opts).isDetached) === null || _b === void 0 ? void 0 : _b.call(_a, node)) !== null && _c !== void 0 ? _c : false;
|
|
2068
|
+
};
|
|
2069
|
+
this.opts = opts;
|
|
2070
|
+
this.valueSet = new Set(opts.value);
|
|
2071
|
+
this.initWrapperTree();
|
|
2072
|
+
}
|
|
2073
|
+
get value() {
|
|
2074
|
+
return this.opts.value;
|
|
2075
|
+
}
|
|
2076
|
+
initWrapperTree() {
|
|
2077
|
+
const valueSet = new Set(this.value);
|
|
2078
|
+
this.rootWrapper = new Wrapper({ root: true, children: [] });
|
|
2079
|
+
this.wrapperMap = new Map();
|
|
2080
|
+
const getNodeValue = this.opts.getNodeValue;
|
|
2081
|
+
const { isDetached, wrapperMap } = this;
|
|
2082
|
+
dfs(this.rootWrapper, this.opts.tree, false);
|
|
2083
|
+
function dfs(parentWrapper, nodes, inheritParentChecked) {
|
|
2084
|
+
// allChildrenChecked 先默认设置为 true
|
|
2085
|
+
// dfs 过程中可能会更新 allChildrenChecked
|
|
2086
|
+
parentWrapper.allChildrenChecked = true;
|
|
2087
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2088
|
+
if (nodes.every(isDetached)) {
|
|
2089
|
+
console.warn('TreeDataHelper 检测到部分节点的下所有子节点均为 detached 状态,这将导致该节点变为「无效节点」', parentWrapper.node);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
for (const node of nodes) {
|
|
2093
|
+
const detached = isDetached(node);
|
|
2094
|
+
const exactChecked = valueSet.has(getNodeValue(node));
|
|
2095
|
+
if (exactChecked && !detached) {
|
|
2096
|
+
parentWrapper.anyDescendentsChecked = true;
|
|
2097
|
+
}
|
|
2098
|
+
const parentChecked = !detached && inheritParentChecked;
|
|
2099
|
+
const checked = exactChecked || parentChecked;
|
|
2100
|
+
const wrapper = new Wrapper({
|
|
2101
|
+
parent: parentWrapper,
|
|
2102
|
+
node,
|
|
2103
|
+
checked,
|
|
2104
|
+
exactChecked,
|
|
2105
|
+
parentChecked,
|
|
2106
|
+
anyDescendentsChecked: checked,
|
|
2107
|
+
detached,
|
|
2108
|
+
});
|
|
2109
|
+
wrapperMap.set(getNodeValue(node), wrapper);
|
|
2110
|
+
parentWrapper.children.push(wrapper);
|
|
2111
|
+
if (!isLeafNode(node)) {
|
|
2112
|
+
wrapper.children = [];
|
|
2113
|
+
dfs(wrapper, node.children, checked);
|
|
2114
|
+
if (wrapper.anyDescendentsChecked && !detached) {
|
|
2115
|
+
parentWrapper.anyDescendentsChecked = true;
|
|
2116
|
+
}
|
|
2117
|
+
if (wrapper.allChildrenChecked) {
|
|
2118
|
+
wrapper.checked = true;
|
|
2119
|
+
// 当一个节点因为「子节点被全选」而变为 checked 时,我们需要更新子节点的 parentChecked 字段
|
|
2120
|
+
for (const child of wrapper.children) {
|
|
2121
|
+
if (!child.detached) {
|
|
2122
|
+
child.parentChecked = true;
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
if (!wrapper.checked && !detached) {
|
|
2128
|
+
parentWrapper.allChildrenChecked = false;
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
isIndeterminate(nodeValue) {
|
|
2134
|
+
const wrapper = this.wrapperMap.get(nodeValue);
|
|
2135
|
+
return !wrapper.checked && wrapper.anyDescendentsChecked;
|
|
2136
|
+
}
|
|
2137
|
+
isChecked(nodeValue) {
|
|
2138
|
+
const wrapper = this.wrapperMap.get(nodeValue);
|
|
2139
|
+
return wrapper.checked;
|
|
2140
|
+
}
|
|
2141
|
+
getValueAfterCheck(nodeValue) {
|
|
2142
|
+
if (this.isChecked(nodeValue)) {
|
|
2143
|
+
return this.getCleanValue();
|
|
2144
|
+
}
|
|
2145
|
+
const nextValue = arrayUtils.merge(this.value, [nodeValue]);
|
|
2146
|
+
return new TreeDataHelper(Object.assign(Object.assign({}, this.opts), { value: nextValue })).getCleanValue();
|
|
2147
|
+
}
|
|
2148
|
+
getValueAfterUncheck(nodeValue) {
|
|
2149
|
+
if (!this.isChecked(nodeValue)) {
|
|
2150
|
+
return this.getCleanValue();
|
|
2151
|
+
}
|
|
2152
|
+
const wrapper = this.wrapperMap.get(nodeValue);
|
|
2153
|
+
const { getNodeValue } = this.opts;
|
|
2154
|
+
const appendArray = getAppendArray(wrapper);
|
|
2155
|
+
const removeSet = getRemoveSet(wrapper);
|
|
2156
|
+
const nextValue = arrayUtils.diff(this.value.concat(appendArray), removeSet);
|
|
2157
|
+
return new TreeDataHelper(Object.assign(Object.assign({}, this.opts), { value: nextValue })).getCleanValue();
|
|
2158
|
+
function getAppendArray(startWrapper) {
|
|
2159
|
+
let result = [];
|
|
2160
|
+
let current = startWrapper;
|
|
2161
|
+
while (current.parentChecked && !current.detached) {
|
|
2162
|
+
for (const sibling of current.parent.children) {
|
|
2163
|
+
if (sibling === current || sibling.exactChecked || sibling.detached) {
|
|
2164
|
+
continue;
|
|
2165
|
+
}
|
|
2166
|
+
result.push(getNodeValue(sibling.node));
|
|
2167
|
+
}
|
|
2168
|
+
current = current.parent;
|
|
2169
|
+
}
|
|
2170
|
+
return result;
|
|
2171
|
+
}
|
|
2172
|
+
function getRemoveSet(startWrapper) {
|
|
2173
|
+
const result = new Set();
|
|
2174
|
+
let wrapper = startWrapper;
|
|
2175
|
+
// 不断向上收集选中的父节点
|
|
2176
|
+
while (true) {
|
|
2177
|
+
result.add(getNodeValue(wrapper.node));
|
|
2178
|
+
if (wrapper.detached || !wrapper.parentChecked) {
|
|
2179
|
+
break;
|
|
2180
|
+
}
|
|
2181
|
+
wrapper = wrapper.parent;
|
|
2182
|
+
}
|
|
2183
|
+
function dfs(wrappers) {
|
|
2184
|
+
if (wrappers == null) {
|
|
2185
|
+
return;
|
|
2186
|
+
}
|
|
2187
|
+
for (const wrapper of wrappers) {
|
|
2188
|
+
if (wrapper.detached || !wrapper.checked) {
|
|
2189
|
+
continue;
|
|
2190
|
+
}
|
|
2191
|
+
result.add(getNodeValue(wrapper.node));
|
|
2192
|
+
if (!isLeafNode(wrapper) && wrapper.anyDescendentsChecked) {
|
|
2193
|
+
dfs(wrapper.children);
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
// 收集所有的子孙节点
|
|
2198
|
+
dfs(startWrapper.children);
|
|
2199
|
+
return result;
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
getValueAfterToggle(nodeValue) {
|
|
2203
|
+
if (this.isChecked(nodeValue)) {
|
|
2204
|
+
return this.getValueAfterUncheck(nodeValue);
|
|
2205
|
+
}
|
|
2206
|
+
else {
|
|
2207
|
+
return this.getValueAfterCheck(nodeValue);
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
getNode(nodeValue) {
|
|
2211
|
+
var _a;
|
|
2212
|
+
return (_a = this.wrapperMap.get(nodeValue)) === null || _a === void 0 ? void 0 : _a.node;
|
|
2213
|
+
}
|
|
2214
|
+
getCleanValue() {
|
|
2215
|
+
const { checkedStrategy, getNodeValue } = this.opts;
|
|
2216
|
+
const result = this.value.filter((nodeValue) => {
|
|
2217
|
+
return !this.wrapperMap.has(nodeValue);
|
|
2218
|
+
});
|
|
2219
|
+
dfs(this.rootWrapper.children);
|
|
2220
|
+
return result;
|
|
2221
|
+
function dfs(wrappers) {
|
|
2222
|
+
for (const wrapper of wrappers) {
|
|
2223
|
+
if (wrapper.checked) {
|
|
2224
|
+
if (checkedStrategy === 'all') {
|
|
2225
|
+
result.push(getNodeValue(wrapper.node));
|
|
2226
|
+
}
|
|
2227
|
+
else if (checkedStrategy === 'parent') {
|
|
2228
|
+
if (!wrapper.parentChecked) {
|
|
2229
|
+
result.push(getNodeValue(wrapper.node));
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
else {
|
|
2233
|
+
// checkedStrategy === 'child'
|
|
2234
|
+
if (isLeafNode(wrapper)) {
|
|
2235
|
+
result.push(getNodeValue(wrapper.node));
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
if (!isLeafNode(wrapper)) {
|
|
2240
|
+
dfs(wrapper.children);
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2243
2245
|
}
|
|
2244
2246
|
|
|
2245
|
-
const STATE_KEY = 'treeSelect';
|
|
2246
|
-
function treeSelect(opts) {
|
|
2247
|
-
return function treeSelectStep(pipeline) {
|
|
2248
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2249
|
-
const Checkbox = pipeline.ctx.components.Checkbox;
|
|
2250
|
-
if (Checkbox == null) {
|
|
2251
|
-
throw new Error('使用 treeSelect 之前需要通过 pipeline context 设置 components.Checkbox');
|
|
2252
|
-
}
|
|
2253
|
-
const primaryKey = pipeline.ensurePrimaryKey('treeSelect');
|
|
2254
|
-
if (typeof primaryKey !== 'string') {
|
|
2255
|
-
throw new Error('treeSelect 仅支持字符串作为 primaryKey');
|
|
2256
|
-
}
|
|
2257
|
-
const clickArea = (_a = opts.clickArea) !== null && _a !== void 0 ? _a : 'checkbox';
|
|
2258
|
-
const isDisabled = (_b = opts.isDisabled) !== null && _b !== void 0 ? _b : always(false);
|
|
2259
|
-
const isDetached = (_c = opts.isDetached) !== null && _c !== void 0 ? _c : always(false);
|
|
2260
|
-
const value = (_f = (_e = (_d = opts.value) !== null && _d !== void 0 ? _d : pipeline.getStateAtKey(STATE_KEY)) !== null && _e !== void 0 ? _e : opts.defaultValue) !== null && _f !== void 0 ? _f : [];
|
|
2261
|
-
const tree = opts.rootKey != null ? [{ [primaryKey]: opts.rootKey, children: opts.tree }] : opts.tree;
|
|
2262
|
-
const getNodeValue = (node) => node[primaryKey];
|
|
2263
|
-
const treeDataHelper = opts.checkStrictly
|
|
2264
|
-
? new StrictTreeDataHelper({ value, getNodeValue, tree })
|
|
2265
|
-
: new TreeDataHelper({
|
|
2266
|
-
value,
|
|
2267
|
-
getNodeValue,
|
|
2268
|
-
isDetached,
|
|
2269
|
-
tree,
|
|
2270
|
-
checkedStrategy: (_g = opts.checkedStrategy) !== null && _g !== void 0 ? _g : 'parent',
|
|
2271
|
-
});
|
|
2272
|
-
const onToggleKey = (key) => {
|
|
2273
|
-
var _a;
|
|
2274
|
-
const nextValue = treeDataHelper.getValueAfterToggle(key);
|
|
2275
|
-
pipeline.setStateAtKey(STATE_KEY, nextValue);
|
|
2276
|
-
(_a = opts.onChange) === null || _a === void 0 ? void 0 : _a.call(opts, nextValue);
|
|
2277
|
-
};
|
|
2278
|
-
const makeCheckbox = (key, root, row) => {
|
|
2279
|
-
return (React.createElement(Checkbox, { checked: treeDataHelper.isChecked(key), indeterminate: treeDataHelper.isIndeterminate(key), disabled: !root && isDisabled(row), onChange: clickArea === 'checkbox' || root ? () => onToggleKey(key) : undefined }));
|
|
2280
|
-
};
|
|
2281
|
-
const checkboxColumn = Object.assign(Object.assign({ name: '', width: 50, align: 'center', title: opts.rootKey != null ? makeCheckbox(opts.rootKey, true) : undefined }, opts.checkboxColumn), { render(value, record) {
|
|
2282
|
-
return makeCheckbox(record[primaryKey], false, record);
|
|
2283
|
-
},
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
const
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2247
|
+
const STATE_KEY = 'treeSelect';
|
|
2248
|
+
function treeSelect(opts) {
|
|
2249
|
+
return function treeSelectStep(pipeline) {
|
|
2250
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2251
|
+
const Checkbox = pipeline.ctx.components.Checkbox;
|
|
2252
|
+
if (Checkbox == null) {
|
|
2253
|
+
throw new Error('使用 treeSelect 之前需要通过 pipeline context 设置 components.Checkbox');
|
|
2254
|
+
}
|
|
2255
|
+
const primaryKey = pipeline.ensurePrimaryKey('treeSelect');
|
|
2256
|
+
if (typeof primaryKey !== 'string') {
|
|
2257
|
+
throw new Error('treeSelect 仅支持字符串作为 primaryKey');
|
|
2258
|
+
}
|
|
2259
|
+
const clickArea = (_a = opts.clickArea) !== null && _a !== void 0 ? _a : 'checkbox';
|
|
2260
|
+
const isDisabled = (_b = opts.isDisabled) !== null && _b !== void 0 ? _b : always(false);
|
|
2261
|
+
const isDetached = (_c = opts.isDetached) !== null && _c !== void 0 ? _c : always(false);
|
|
2262
|
+
const value = (_f = (_e = (_d = opts.value) !== null && _d !== void 0 ? _d : pipeline.getStateAtKey(STATE_KEY)) !== null && _e !== void 0 ? _e : opts.defaultValue) !== null && _f !== void 0 ? _f : [];
|
|
2263
|
+
const tree = opts.rootKey != null ? [{ [primaryKey]: opts.rootKey, children: opts.tree }] : opts.tree;
|
|
2264
|
+
const getNodeValue = (node) => node[primaryKey];
|
|
2265
|
+
const treeDataHelper = opts.checkStrictly
|
|
2266
|
+
? new StrictTreeDataHelper({ value, getNodeValue, tree })
|
|
2267
|
+
: new TreeDataHelper({
|
|
2268
|
+
value,
|
|
2269
|
+
getNodeValue,
|
|
2270
|
+
isDetached,
|
|
2271
|
+
tree,
|
|
2272
|
+
checkedStrategy: (_g = opts.checkedStrategy) !== null && _g !== void 0 ? _g : 'parent',
|
|
2273
|
+
});
|
|
2274
|
+
const onToggleKey = (key) => {
|
|
2275
|
+
var _a;
|
|
2276
|
+
const nextValue = treeDataHelper.getValueAfterToggle(key);
|
|
2277
|
+
pipeline.setStateAtKey(STATE_KEY, nextValue);
|
|
2278
|
+
(_a = opts.onChange) === null || _a === void 0 ? void 0 : _a.call(opts, nextValue);
|
|
2279
|
+
};
|
|
2280
|
+
const makeCheckbox = (key, root, row) => {
|
|
2281
|
+
return (React.createElement(Checkbox, { checked: treeDataHelper.isChecked(key), indeterminate: treeDataHelper.isIndeterminate(key), disabled: !root && isDisabled(row), onChange: clickArea === 'checkbox' || root ? () => onToggleKey(key) : undefined }));
|
|
2282
|
+
};
|
|
2283
|
+
const checkboxColumn = Object.assign(Object.assign({ name: '', width: 50, align: 'center', title: opts.rootKey != null ? makeCheckbox(opts.rootKey, true) : undefined }, opts.checkboxColumn), { render(value, record) {
|
|
2284
|
+
return makeCheckbox(record[primaryKey], false, record);
|
|
2285
|
+
},
|
|
2286
|
+
getCellProps(value, row) {
|
|
2287
|
+
const rowKey = row[primaryKey];
|
|
2288
|
+
if (clickArea !== 'cell') {
|
|
2289
|
+
return;
|
|
2290
|
+
}
|
|
2291
|
+
const disabled = isDisabled(row);
|
|
2292
|
+
if (disabled) {
|
|
2293
|
+
return { style: { cursor: 'not-allowed' } };
|
|
2294
|
+
}
|
|
2295
|
+
return {
|
|
2296
|
+
style: { cursor: 'pointer' },
|
|
2297
|
+
onClick(e) {
|
|
2298
|
+
if (opts.stopClickEventPropagation) {
|
|
2299
|
+
e.stopPropagation();
|
|
2300
|
+
}
|
|
2301
|
+
onToggleKey(rowKey);
|
|
2302
|
+
},
|
|
2303
|
+
};
|
|
2304
|
+
} });
|
|
2305
|
+
const nextColumns = pipeline.getColumns().slice();
|
|
2306
|
+
const checkboxPlacement = (_h = opts.checkboxPlacement) !== null && _h !== void 0 ? _h : 'start';
|
|
2307
|
+
if (checkboxPlacement === 'start') {
|
|
2308
|
+
nextColumns.unshift(checkboxColumn);
|
|
2309
|
+
}
|
|
2310
|
+
else {
|
|
2311
|
+
nextColumns.push(checkboxColumn);
|
|
2312
|
+
}
|
|
2313
|
+
pipeline.columns(nextColumns);
|
|
2314
|
+
if (clickArea === 'row') {
|
|
2315
|
+
pipeline.appendRowPropsGetter((row) => {
|
|
2316
|
+
const disabled = isDisabled(row);
|
|
2317
|
+
if (!disabled) {
|
|
2318
|
+
return {
|
|
2319
|
+
style: { cursor: 'pointer' },
|
|
2320
|
+
onClick(e) {
|
|
2321
|
+
if (opts.stopClickEventPropagation) {
|
|
2322
|
+
e.stopPropagation();
|
|
2323
|
+
}
|
|
2324
|
+
onToggleKey(row[primaryKey]);
|
|
2325
|
+
},
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
});
|
|
2329
|
+
}
|
|
2330
|
+
if (opts.highlightRowWhenSelected) {
|
|
2331
|
+
pipeline.appendRowPropsGetter((row) => {
|
|
2332
|
+
if (treeDataHelper.isChecked(row[primaryKey])) {
|
|
2333
|
+
return { className: 'highlight' };
|
|
2334
|
+
}
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2337
|
+
return pipeline;
|
|
2338
|
+
};
|
|
2336
2339
|
}
|
|
2337
2340
|
|
|
2338
2341
|
var index = /*#__PURE__*/Object.freeze({
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2342
|
+
__proto__: null,
|
|
2343
|
+
autoRowSpan: autoRowSpan,
|
|
2344
|
+
buildTree: buildTree,
|
|
2345
|
+
columnHover: columnHover,
|
|
2346
|
+
columnRangeHover: columnRangeHover,
|
|
2347
|
+
columnResize: columnResize,
|
|
2348
|
+
fillRemainingWidth: fillRemainingWidth,
|
|
2349
|
+
multiSelect: multiSelect,
|
|
2350
|
+
rowDetail: rowDetail,
|
|
2351
|
+
rowPopover: rowPopover,
|
|
2352
|
+
rowGrouping: rowGrouping,
|
|
2353
|
+
singleSelect: singleSelect,
|
|
2354
|
+
sort: sort,
|
|
2355
|
+
tips: tips,
|
|
2356
|
+
treeMode: treeMode,
|
|
2357
|
+
treeMetaSymbol: treeMetaSymbol,
|
|
2358
|
+
treeSelect: treeSelect
|
|
2356
2359
|
});
|
|
2357
2360
|
|
|
2358
|
-
const ICON_WIDTH = 16;
|
|
2359
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
2360
|
-
function makeTreeModeTransform({ onChangeOpenKeys, openKeys, primaryKey, iconIndent = -6, iconGap = 0, indentSize = 16, isLeafNode: isLeafNode$1 = isLeafNode, clickArea = 'cell', treeMetaKey = treeMetaSymbol, stopClickEventPropagation, }) {
|
|
2361
|
-
warnTransformsDeprecated('makeTreeModeTransform');
|
|
2362
|
-
const openKeySet = new Set(openKeys);
|
|
2363
|
-
const toggle = (rowKey) => {
|
|
2364
|
-
const expanded = openKeySet.has(rowKey);
|
|
2365
|
-
if (expanded) {
|
|
2366
|
-
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'collapse');
|
|
2367
|
-
}
|
|
2368
|
-
else {
|
|
2369
|
-
onChangeOpenKeys([...openKeys, rowKey], rowKey, 'expand');
|
|
2370
|
-
}
|
|
2371
|
-
};
|
|
2372
|
-
return ({ columns, dataSource }) => {
|
|
2373
|
-
return {
|
|
2374
|
-
columns: processColumns(columns),
|
|
2375
|
-
dataSource: processDataSource(dataSource),
|
|
2376
|
-
};
|
|
2377
|
-
function processDataSource(input) {
|
|
2378
|
-
const result = [];
|
|
2379
|
-
dfs(input, 0);
|
|
2380
|
-
function dfs(nodes, depth) {
|
|
2381
|
-
if (nodes == null) {
|
|
2382
|
-
return;
|
|
2383
|
-
}
|
|
2384
|
-
for (const node of nodes) {
|
|
2385
|
-
const rowKey = node[primaryKey];
|
|
2386
|
-
const expanded = openKeySet.has(rowKey);
|
|
2387
|
-
const isLeaf = isLeafNode$1(node, { depth, expanded, rowKey });
|
|
2388
|
-
const treeMeta = { depth, isLeaf, expanded, rowKey };
|
|
2389
|
-
result.push(Object.assign({ [treeMetaKey]: treeMeta }, node));
|
|
2390
|
-
if (!isLeaf && expanded) {
|
|
2391
|
-
dfs(node.children, depth + 1);
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
return result;
|
|
2396
|
-
}
|
|
2397
|
-
function processColumns(columns) {
|
|
2398
|
-
if (columns.length === 0) {
|
|
2399
|
-
return columns;
|
|
2400
|
-
}
|
|
2401
|
-
const [firstCol, ...others] = columns;
|
|
2402
|
-
const render = (value, record, recordIndex) => {
|
|
2403
|
-
const content = internals.safeRender(firstCol, record, recordIndex);
|
|
2404
|
-
if (record[treeMetaKey] == null) {
|
|
2405
|
-
// 没有 treeMeta 信息的话,就返回原先的渲染结果
|
|
2406
|
-
return content;
|
|
2407
|
-
}
|
|
2408
|
-
const { rowKey, depth, isLeaf, expanded } = record[treeMetaKey];
|
|
2409
|
-
const indent = iconIndent + depth * indentSize;
|
|
2410
|
-
if (isLeaf) {
|
|
2411
|
-
return (React.createElement(InlineFlexCell, { className: "expansion-cell leaf" },
|
|
2412
|
-
React.createElement("div", { style: { marginLeft: indent + ICON_WIDTH + iconGap } }, content)));
|
|
2413
|
-
}
|
|
2414
|
-
const onClick = (e) => {
|
|
2415
|
-
if (stopClickEventPropagation) {
|
|
2416
|
-
e.stopPropagation();
|
|
2417
|
-
}
|
|
2418
|
-
toggle(rowKey);
|
|
2419
|
-
};
|
|
2420
|
-
const expandCls = expanded ? 'expanded' : 'collapsed';
|
|
2421
|
-
return (React.createElement(ExpansionCell, { className: cx('expansion-cell', expandCls), style: {
|
|
2422
|
-
cursor: clickArea === 'content' ? 'pointer' : undefined,
|
|
2423
|
-
}, onClick: clickArea === 'content' ? onClick : undefined },
|
|
2424
|
-
React.createElement(icons.CaretRight, { className: cx('expansion-icon', expandCls), style: {
|
|
2425
|
-
cursor: clickArea === 'icon' ? 'pointer' : undefined,
|
|
2426
|
-
marginLeft: indent,
|
|
2427
|
-
marginRight: iconGap,
|
|
2428
|
-
}, onClick: clickArea === 'icon' ? onClick : undefined }),
|
|
2429
|
-
content));
|
|
2430
|
-
};
|
|
2431
|
-
const getCellProps = (value, record, rowIndex) => {
|
|
2432
|
-
const prevProps = internals.safeGetCellProps(firstCol, record, rowIndex);
|
|
2433
|
-
if (record[treeMetaKey] == null) {
|
|
2434
|
-
// 没有 treeMeta 信息的话,就返回原先的 cellProps
|
|
2435
|
-
return prevProps;
|
|
2436
|
-
}
|
|
2437
|
-
const { isLeaf, rowKey } = record[treeMetaKey];
|
|
2438
|
-
if (isLeaf) {
|
|
2439
|
-
return prevProps;
|
|
2440
|
-
}
|
|
2441
|
-
return mergeCellProps(prevProps, {
|
|
2442
|
-
onClick(e) {
|
|
2443
|
-
if (stopClickEventPropagation) {
|
|
2444
|
-
e.stopPropagation();
|
|
2445
|
-
}
|
|
2446
|
-
toggle(rowKey);
|
|
2447
|
-
},
|
|
2448
|
-
style: { cursor: 'pointer' },
|
|
2449
|
-
});
|
|
2450
|
-
};
|
|
2451
|
-
return [
|
|
2452
|
-
Object.assign(Object.assign({}, firstCol), { title: (React.createElement("div", { style: { marginLeft: iconIndent + ICON_WIDTH + iconGap } }, internals.safeRenderHeader(firstCol))), render, getCellProps: clickArea === 'cell' ? getCellProps : firstCol.getCellProps }),
|
|
2453
|
-
...others,
|
|
2454
|
-
];
|
|
2455
|
-
}
|
|
2456
|
-
};
|
|
2457
|
-
}
|
|
2458
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
2459
|
-
function useTreeModeTransform(_a) {
|
|
2460
|
-
var { defaultOpenKeys = [] } = _a, others = __rest(_a, ["defaultOpenKeys"]);
|
|
2461
|
-
const [openKeys, onChangeOpenKeys] = useState(defaultOpenKeys);
|
|
2462
|
-
return makeTreeModeTransform(Object.assign({ openKeys,
|
|
2463
|
-
onChangeOpenKeys }, others));
|
|
2361
|
+
const ICON_WIDTH = 16;
|
|
2362
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
2363
|
+
function makeTreeModeTransform({ onChangeOpenKeys, openKeys, primaryKey, iconIndent = -6, iconGap = 0, indentSize = 16, isLeafNode: isLeafNode$1 = isLeafNode, clickArea = 'cell', treeMetaKey = treeMetaSymbol, stopClickEventPropagation, }) {
|
|
2364
|
+
warnTransformsDeprecated('makeTreeModeTransform');
|
|
2365
|
+
const openKeySet = new Set(openKeys);
|
|
2366
|
+
const toggle = (rowKey) => {
|
|
2367
|
+
const expanded = openKeySet.has(rowKey);
|
|
2368
|
+
if (expanded) {
|
|
2369
|
+
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'collapse');
|
|
2370
|
+
}
|
|
2371
|
+
else {
|
|
2372
|
+
onChangeOpenKeys([...openKeys, rowKey], rowKey, 'expand');
|
|
2373
|
+
}
|
|
2374
|
+
};
|
|
2375
|
+
return ({ columns, dataSource }) => {
|
|
2376
|
+
return {
|
|
2377
|
+
columns: processColumns(columns),
|
|
2378
|
+
dataSource: processDataSource(dataSource),
|
|
2379
|
+
};
|
|
2380
|
+
function processDataSource(input) {
|
|
2381
|
+
const result = [];
|
|
2382
|
+
dfs(input, 0);
|
|
2383
|
+
function dfs(nodes, depth) {
|
|
2384
|
+
if (nodes == null) {
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
for (const node of nodes) {
|
|
2388
|
+
const rowKey = node[primaryKey];
|
|
2389
|
+
const expanded = openKeySet.has(rowKey);
|
|
2390
|
+
const isLeaf = isLeafNode$1(node, { depth, expanded, rowKey });
|
|
2391
|
+
const treeMeta = { depth, isLeaf, expanded, rowKey };
|
|
2392
|
+
result.push(Object.assign({ [treeMetaKey]: treeMeta }, node));
|
|
2393
|
+
if (!isLeaf && expanded) {
|
|
2394
|
+
dfs(node.children, depth + 1);
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
return result;
|
|
2399
|
+
}
|
|
2400
|
+
function processColumns(columns) {
|
|
2401
|
+
if (columns.length === 0) {
|
|
2402
|
+
return columns;
|
|
2403
|
+
}
|
|
2404
|
+
const [firstCol, ...others] = columns;
|
|
2405
|
+
const render = (value, record, recordIndex) => {
|
|
2406
|
+
const content = internals.safeRender(firstCol, record, recordIndex);
|
|
2407
|
+
if (record[treeMetaKey] == null) {
|
|
2408
|
+
// 没有 treeMeta 信息的话,就返回原先的渲染结果
|
|
2409
|
+
return content;
|
|
2410
|
+
}
|
|
2411
|
+
const { rowKey, depth, isLeaf, expanded } = record[treeMetaKey];
|
|
2412
|
+
const indent = iconIndent + depth * indentSize;
|
|
2413
|
+
if (isLeaf) {
|
|
2414
|
+
return (React.createElement(InlineFlexCell, { className: "expansion-cell leaf" },
|
|
2415
|
+
React.createElement("div", { style: { marginLeft: indent + ICON_WIDTH + iconGap } }, content)));
|
|
2416
|
+
}
|
|
2417
|
+
const onClick = (e) => {
|
|
2418
|
+
if (stopClickEventPropagation) {
|
|
2419
|
+
e.stopPropagation();
|
|
2420
|
+
}
|
|
2421
|
+
toggle(rowKey);
|
|
2422
|
+
};
|
|
2423
|
+
const expandCls = expanded ? 'expanded' : 'collapsed';
|
|
2424
|
+
return (React.createElement(ExpansionCell, { className: cx('expansion-cell', expandCls), style: {
|
|
2425
|
+
cursor: clickArea === 'content' ? 'pointer' : undefined,
|
|
2426
|
+
}, onClick: clickArea === 'content' ? onClick : undefined },
|
|
2427
|
+
React.createElement(icons.CaretRight, { className: cx('expansion-icon', expandCls), style: {
|
|
2428
|
+
cursor: clickArea === 'icon' ? 'pointer' : undefined,
|
|
2429
|
+
marginLeft: indent,
|
|
2430
|
+
marginRight: iconGap,
|
|
2431
|
+
}, onClick: clickArea === 'icon' ? onClick : undefined }),
|
|
2432
|
+
content));
|
|
2433
|
+
};
|
|
2434
|
+
const getCellProps = (value, record, rowIndex) => {
|
|
2435
|
+
const prevProps = internals.safeGetCellProps(firstCol, record, rowIndex);
|
|
2436
|
+
if (record[treeMetaKey] == null) {
|
|
2437
|
+
// 没有 treeMeta 信息的话,就返回原先的 cellProps
|
|
2438
|
+
return prevProps;
|
|
2439
|
+
}
|
|
2440
|
+
const { isLeaf, rowKey } = record[treeMetaKey];
|
|
2441
|
+
if (isLeaf) {
|
|
2442
|
+
return prevProps;
|
|
2443
|
+
}
|
|
2444
|
+
return mergeCellProps(prevProps, {
|
|
2445
|
+
onClick(e) {
|
|
2446
|
+
if (stopClickEventPropagation) {
|
|
2447
|
+
e.stopPropagation();
|
|
2448
|
+
}
|
|
2449
|
+
toggle(rowKey);
|
|
2450
|
+
},
|
|
2451
|
+
style: { cursor: 'pointer' },
|
|
2452
|
+
});
|
|
2453
|
+
};
|
|
2454
|
+
return [
|
|
2455
|
+
Object.assign(Object.assign({}, firstCol), { title: (React.createElement("div", { style: { marginLeft: iconIndent + ICON_WIDTH + iconGap } }, internals.safeRenderHeader(firstCol))), render, getCellProps: clickArea === 'cell' ? getCellProps : firstCol.getCellProps }),
|
|
2456
|
+
...others,
|
|
2457
|
+
];
|
|
2458
|
+
}
|
|
2459
|
+
};
|
|
2460
|
+
}
|
|
2461
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
2462
|
+
function useTreeModeTransform(_a) {
|
|
2463
|
+
var { defaultOpenKeys = [] } = _a, others = __rest(_a, ["defaultOpenKeys"]);
|
|
2464
|
+
const [openKeys, onChangeOpenKeys] = useState(defaultOpenKeys);
|
|
2465
|
+
return makeTreeModeTransform(Object.assign({ openKeys,
|
|
2466
|
+
onChangeOpenKeys }, others));
|
|
2464
2467
|
}
|
|
2465
2468
|
|
|
2466
|
-
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
2467
|
-
function makeVisibleTransform(visibleCodes) {
|
|
2468
|
-
warnTransformsDeprecated('makeVisibleTransform');
|
|
2469
|
-
const set = new Set(visibleCodes);
|
|
2470
|
-
return traverseColumn((column) => {
|
|
2471
|
-
if (!isLeafNode(column)) {
|
|
2472
|
-
return column;
|
|
2473
|
-
}
|
|
2474
|
-
return set.has(column.code) ? column : Object.assign(Object.assign({}, column), { hidden: true });
|
|
2475
|
-
});
|
|
2469
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
2470
|
+
function makeVisibleTransform(visibleCodes) {
|
|
2471
|
+
warnTransformsDeprecated('makeVisibleTransform');
|
|
2472
|
+
const set = new Set(visibleCodes);
|
|
2473
|
+
return traverseColumn((column) => {
|
|
2474
|
+
if (!isLeafNode(column)) {
|
|
2475
|
+
return column;
|
|
2476
|
+
}
|
|
2477
|
+
return set.has(column.code) ? column : Object.assign(Object.assign({}, column), { hidden: true });
|
|
2478
|
+
});
|
|
2476
2479
|
}
|
|
2477
2480
|
|
|
2478
2481
|
export { applyTransforms, buildTree$1 as buildTree, exportTableAsExcel, index as features, groupBy, layeredSort, makeAutoRowSpanTransform, makeBuildTreeTransform, makeColumnHoverTransform, makeColumnRangeHoverTransform, makeColumnResizeTransform, makeFlattenTransform, makeOrderFieldTransform, makeRecursiveMapper, makeSortTransform, makeTipsTransform, makeTreeModeTransform, makeVisibleTransform, proto, smartCompare, traverseColumn, useAutoWidthTransform, useColumnHoverRangeTransform, useColumnHoverTransform, useColumnResizeTransform, useSortTransform, useTreeModeTransform };
|