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