@guozhi5658/srp-table 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base-table/__tests__/fillRemainingWidth.test.d.ts +1 -0
- package/dist/base-table/calculations.d.ts +3 -3
- package/dist/base-table/colgroup.d.ts +4 -5
- package/dist/base-table/empty.d.ts +9 -9
- package/dist/base-table/header.d.ts +4 -5
- package/dist/base-table/helpers/SpanManager.d.ts +9 -9
- package/dist/base-table/helpers/TableDOMUtils.d.ts +16 -16
- package/dist/base-table/helpers/getMaximumColSpan.d.ts +9 -0
- package/dist/base-table/helpers/getRichVisibleRectsStream.d.ts +23 -23
- package/dist/base-table/helpers/rowHeightManager.d.ts +7 -7
- package/dist/base-table/html-table.d.ts +14 -15
- package/dist/base-table/index.d.ts +3 -3
- package/dist/base-table/interfaces.d.ts +54 -54
- package/dist/base-table/loading.d.ts +13 -13
- package/dist/base-table/styles.d.ts +86 -83
- package/dist/base-table/table.d.ts +185 -185
- package/dist/base-table/utils.d.ts +22 -22
- package/dist/chunks/{srp-table-pipeline-cc27a3d4.esm.js → srp-table-pipeline-414f4fea.esm.js} +2065 -1987
- package/dist/chunks/{srp-table-pipeline-93090855.js → srp-table-pipeline-7f69aca0.js} +2064 -1984
- package/dist/common-views.d.ts +26 -23
- package/dist/fillRemainingWidth.d.ts +9 -0
- package/dist/interfaces.d.ts +65 -65
- package/dist/internals.d.ts +14 -15
- package/dist/pipeline/features/autoRowSpan.d.ts +2 -2
- package/dist/pipeline/features/buildTree.d.ts +2 -2
- package/dist/pipeline/features/columnHover.d.ts +12 -12
- package/dist/pipeline/features/columnRangeHover.d.ts +15 -15
- package/dist/pipeline/features/columnResize.d.ts +24 -24
- package/dist/pipeline/features/fillRemainingWidth.d.ts +2 -0
- package/dist/pipeline/features/index.d.ts +15 -14
- package/dist/pipeline/features/multiSelect.d.ts +27 -27
- package/dist/pipeline/features/rowDetail.d.ts +29 -29
- package/dist/pipeline/features/rowGrouping.d.ts +14 -14
- package/dist/pipeline/features/rowPopover.d.ts +13 -13
- package/dist/pipeline/features/singleSelect.d.ts +23 -23
- package/dist/pipeline/features/sort.d.ts +42 -42
- package/dist/pipeline/features/tips.d.ts +2 -2
- package/dist/pipeline/features/treeMode.d.ts +29 -29
- package/dist/pipeline/features/treeSelect.d.ts +38 -38
- package/dist/pipeline/index.d.ts +3 -3
- package/dist/pipeline/pipeline.d.ts +79 -79
- package/dist/pivot/cross-table/buildCrossTable.d.ts +17 -17
- package/dist/pivot/cross-table/constants.d.ts +1 -1
- package/dist/pivot/cross-table/cross-table.d.ts +18 -18
- package/dist/pivot/cross-table/index.d.ts +4 -4
- package/dist/pivot/cross-table/interfaces.d.ts +29 -29
- package/dist/pivot/cross-table/internals.d.ts +13 -13
- package/dist/pivot/cross-tree-table/buildCrossTreeTable.d.ts +14 -14
- package/dist/pivot/cross-tree-table/cross-tree-table.d.ts +38 -38
- package/dist/pivot/cross-tree-table/index.d.ts +2 -2
- package/dist/pivot/pivot-utils/buildDrillTree.d.ts +16 -16
- package/dist/pivot/pivot-utils/builders.d.ts +26 -26
- package/dist/pivot/pivot-utils/convert-utils.d.ts +31 -31
- package/dist/pivot/pivot-utils/index.d.ts +5 -5
- package/dist/pivot/pivot-utils/interfaces.d.ts +12 -12
- package/dist/pivot/pivot-utils/simpleEncode.d.ts +1 -1
- package/dist/srp-table-pivot.d.ts +3 -3
- package/dist/srp-table-pivot.esm.js +647 -646
- package/dist/srp-table-pivot.js +647 -646
- package/dist/srp-table.d.ts +6 -6
- package/dist/srp-table.esm.js +2336 -2327
- package/dist/srp-table.js +2349 -2340
- package/dist/transforms/autoRowSpan.d.ts +3 -3
- package/dist/transforms/autoWidth.d.ts +25 -25
- package/dist/transforms/buildTree.d.ts +3 -3
- package/dist/transforms/columnHover.d.ts +14 -14
- package/dist/transforms/columnRangeHover.d.ts +14 -14
- package/dist/transforms/columnResize.d.ts +24 -24
- package/dist/transforms/flatten.d.ts +3 -3
- package/dist/transforms/index.d.ts +12 -12
- package/dist/transforms/orderField.d.ts +3 -3
- package/dist/transforms/sort.d.ts +40 -40
- package/dist/transforms/tips.d.ts +8 -8
- package/dist/transforms/treeMode.d.ts +27 -27
- package/dist/transforms/visible.d.ts +2 -2
- package/dist/transforms/warnTransformsDeprecated.d.ts +1 -1
- package/dist/utils/applyTransforms.d.ts +6 -6
- package/dist/utils/buildTree.d.ts +36 -36
- package/dist/utils/collectNodes.d.ts +8 -8
- package/dist/utils/exportTableAsExcel.d.ts +4 -4
- package/dist/utils/getTreeDepth.d.ts +3 -3
- package/dist/utils/groupBy.d.ts +1 -1
- package/dist/utils/groupBy2.d.ts +1 -1
- package/dist/utils/index.d.ts +14 -14
- package/dist/utils/isLeafNode.d.ts +2 -2
- package/dist/utils/layeredSort.d.ts +5 -5
- package/dist/utils/makeRecursiveMapper.d.ts +9 -9
- package/dist/utils/mergeCellProps.d.ts +9 -9
- package/dist/utils/others.d.ts +11 -10
- package/dist/utils/proto.d.ts +21 -21
- package/dist/utils/smartCompare.d.ts +9 -9
- package/dist/utils/traverseColumn.d.ts +11 -11
- package/dist/utils/tree-data-helpers/StrictTreeDataHelper.d.ts +22 -22
- package/dist/utils/tree-data-helpers/TreeDataHelper.d.ts +26 -26
- package/dist/utils/tree-data-helpers/__tests__/helpers.test.d.ts +1 -1
- package/package.json +4 -3
- package/readme.md +28 -0
package/dist/srp-table.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var pipeline = require('./chunks/srp-table-pipeline-
|
|
5
|
+
var pipeline = require('./chunks/srp-table-pipeline-7f69aca0.js');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var styled = require('styled-components');
|
|
8
8
|
var rxjs = require('rxjs');
|
|
@@ -13,21 +13,21 @@ require('resize-observer-polyfill');
|
|
|
13
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
14
|
|
|
15
15
|
function _interopNamespace(e) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
}
|
|
25
27
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
n["default"] = e;
|
|
30
|
-
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
n["default"] = e;
|
|
30
|
+
return Object.freeze(n);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
@@ -35,670 +35,668 @@ var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
|
35
35
|
var op__namespace = /*#__PURE__*/_interopNamespace(op);
|
|
36
36
|
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
37
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;
|
|
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
48
|
}
|
|
49
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);
|
|
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
56
|
}
|
|
57
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
|
-
}
|
|
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
118
|
}
|
|
119
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
|
-
}
|
|
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
229
|
}
|
|
230
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
|
-
}
|
|
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
249
|
}
|
|
250
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);
|
|
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
318
|
proto.array = (baseRecord) => proto(baseRecord, true);
|
|
319
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
|
-
};
|
|
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
355
|
}
|
|
356
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;
|
|
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
401
|
}
|
|
402
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
|
-
};
|
|
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
447
|
}
|
|
448
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
|
-
}
|
|
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
456
|
}
|
|
457
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
|
-
});
|
|
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
508
|
}
|
|
509
509
|
|
|
510
|
-
const AUTO_WIDTH_WRAPPER_CLS = 'auto-width-wrapper';
|
|
511
|
-
const AUTO_WIDTH_EXPANDER_CLS = 'auto-width-expander';
|
|
510
|
+
const AUTO_WIDTH_WRAPPER_CLS = 'auto-width-wrapper';
|
|
511
|
+
const AUTO_WIDTH_EXPANDER_CLS = 'auto-width-expander';
|
|
512
512
|
const AutoWidthWrapper = styled__default["default"].div `
|
|
513
513
|
height: 100%;
|
|
514
514
|
display: inline-flex;
|
|
515
515
|
align-items: center;
|
|
516
516
|
white-space: nowrap;
|
|
517
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
|
-
},
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
};
|
|
606
|
-
};
|
|
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
|
+
},
|
|
576
|
+
render(_, record, rowIndex) {
|
|
577
|
+
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)));
|
|
578
|
+
} });
|
|
579
|
+
});
|
|
580
|
+
return (input) => {
|
|
581
|
+
var _a;
|
|
582
|
+
const { columns, dataSource } = innerTransform(input);
|
|
583
|
+
const expanderVisibility = (_a = options === null || options === void 0 ? void 0 : options.expanderVisibility) !== null && _a !== void 0 ? _a : 'visible';
|
|
584
|
+
return {
|
|
585
|
+
columns: (options === null || options === void 0 ? void 0 : options.appendExpander)
|
|
586
|
+
? pipeline.appendFillRemainingWidthColumn(columns, {
|
|
587
|
+
headerCellProps: {
|
|
588
|
+
className: AUTO_WIDTH_EXPANDER_CLS,
|
|
589
|
+
style: {
|
|
590
|
+
background: expanderVisibility === 'hidden' ? 'var(--bgcolor)' : undefined,
|
|
591
|
+
border: expanderVisibility === 'hidden' ? 'none' : undefined,
|
|
592
|
+
},
|
|
593
|
+
},
|
|
594
|
+
getCellProps() {
|
|
595
|
+
return {
|
|
596
|
+
className: AUTO_WIDTH_EXPANDER_CLS,
|
|
597
|
+
style: { visibility: expanderVisibility },
|
|
598
|
+
};
|
|
599
|
+
},
|
|
600
|
+
})
|
|
601
|
+
: columns,
|
|
602
|
+
dataSource,
|
|
603
|
+
};
|
|
604
|
+
};
|
|
607
605
|
}
|
|
608
606
|
|
|
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
|
-
};
|
|
607
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
608
|
+
function makeBuildTreeTransform(idProp, parentIdProp) {
|
|
609
|
+
warnTransformsDeprecated('makeBuildTreeTransform');
|
|
610
|
+
return ({ columns, dataSource }) => {
|
|
611
|
+
return { columns, dataSource: buildTree$1(idProp, parentIdProp, dataSource) };
|
|
612
|
+
};
|
|
615
613
|
}
|
|
616
614
|
|
|
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 });
|
|
615
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
616
|
+
function makeColumnHoverTransform({ hoverColor = 'var(--hover-bgcolor)', hoverColIndex, onChangeHoverColIndex, }) {
|
|
617
|
+
warnTransformsDeprecated('makeColumnHoverTransform');
|
|
618
|
+
return traverseColumn((col, { range }) => {
|
|
619
|
+
if (!pipeline.isLeafNode(col)) {
|
|
620
|
+
return col;
|
|
621
|
+
}
|
|
622
|
+
const colIndexMatched = range.start <= hoverColIndex && hoverColIndex < range.end;
|
|
623
|
+
const prevGetCellProps = col.getCellProps;
|
|
624
|
+
return Object.assign(Object.assign({}, col), { getCellProps(value, record, rowIndex) {
|
|
625
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
626
|
+
return pipeline.mergeCellProps(prevCellProps, {
|
|
627
|
+
style: { '--bgcolor': colIndexMatched ? hoverColor : undefined },
|
|
628
|
+
onMouseEnter() {
|
|
629
|
+
onChangeHoverColIndex(range.start);
|
|
630
|
+
},
|
|
631
|
+
onMouseLeave() {
|
|
632
|
+
onChangeHoverColIndex(-1);
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
} });
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
639
|
+
function useColumnHoverTransform({ hoverColor, defaultHoverColIndex = -1, } = {}) {
|
|
640
|
+
const [hoverColIndex, onChangeHoverColIndex] = React.useState(defaultHoverColIndex);
|
|
641
|
+
return makeColumnHoverTransform({ hoverColor, hoverColIndex, onChangeHoverColIndex });
|
|
644
642
|
}
|
|
645
643
|
|
|
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 });
|
|
644
|
+
const EMPTY_RANGE$1 = {
|
|
645
|
+
start: -1,
|
|
646
|
+
end: -1,
|
|
647
|
+
};
|
|
648
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
649
|
+
function makeColumnRangeHoverTransform({ hoverColor = 'var(--hover-bgcolor)', headerHoverColor = 'var(--header-hover-bgcolor)', hoverRange, onChangeHoverRange, }) {
|
|
650
|
+
warnTransformsDeprecated('makeColumnRangeHoverTransform');
|
|
651
|
+
return traverseColumn((col, { range: colRange }) => {
|
|
652
|
+
const match = colRange.end > hoverRange.start && hoverRange.end > colRange.start;
|
|
653
|
+
if (!pipeline.isLeafNode(col)) {
|
|
654
|
+
if (headerHoverColor == null) {
|
|
655
|
+
return col;
|
|
656
|
+
}
|
|
657
|
+
return Object.assign(Object.assign({}, col), { headerCellProps: pipeline.mergeCellProps(col.headerCellProps, {
|
|
658
|
+
onMouseEnter() {
|
|
659
|
+
onChangeHoverRange(colRange);
|
|
660
|
+
},
|
|
661
|
+
onMouseLeave() {
|
|
662
|
+
onChangeHoverRange(EMPTY_RANGE$1);
|
|
663
|
+
},
|
|
664
|
+
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
665
|
+
}) });
|
|
666
|
+
}
|
|
667
|
+
const prevGetCellProps = col.getCellProps;
|
|
668
|
+
return Object.assign(Object.assign({}, col), { headerCellProps: pipeline.mergeCellProps(col.headerCellProps, {
|
|
669
|
+
onMouseEnter() {
|
|
670
|
+
onChangeHoverRange(colRange);
|
|
671
|
+
},
|
|
672
|
+
onMouseLeave() {
|
|
673
|
+
onChangeHoverRange(EMPTY_RANGE$1);
|
|
674
|
+
},
|
|
675
|
+
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
676
|
+
}), getCellProps(value, record, rowIndex) {
|
|
677
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
678
|
+
return pipeline.mergeCellProps(prevCellProps, {
|
|
679
|
+
onMouseEnter() {
|
|
680
|
+
onChangeHoverRange(colRange);
|
|
681
|
+
},
|
|
682
|
+
onMouseLeave() {
|
|
683
|
+
onChangeHoverRange(EMPTY_RANGE$1);
|
|
684
|
+
},
|
|
685
|
+
style: { '--bgcolor': match ? hoverColor : undefined },
|
|
686
|
+
});
|
|
687
|
+
} });
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
691
|
+
function useColumnHoverRangeTransform({ hoverColor, headerHoverColor, defaultHoverRange = EMPTY_RANGE$1, } = {}) {
|
|
692
|
+
const [hoverRange, onChangeHoverRange] = React.useState(defaultHoverRange);
|
|
693
|
+
return makeColumnRangeHoverTransform({ hoverColor, headerHoverColor, hoverRange, onChangeHoverRange });
|
|
696
694
|
}
|
|
697
695
|
|
|
698
|
-
function clamp$1(min, x, max) {
|
|
699
|
-
return Math.max(min, Math.min(max, x));
|
|
700
|
-
}
|
|
701
|
-
const RESIZE_EXPANDER_CLS = 'resize-expander';
|
|
696
|
+
function clamp$1(min, x, max) {
|
|
697
|
+
return Math.max(min, Math.min(max, x));
|
|
698
|
+
}
|
|
699
|
+
const RESIZE_EXPANDER_CLS = 'resize-expander';
|
|
702
700
|
const ResizeHandle$1 = styled__default["default"].span `
|
|
703
701
|
position: absolute;
|
|
704
702
|
top: 0;
|
|
@@ -707,258 +705,258 @@ const ResizeHandle$1 = styled__default["default"].span `
|
|
|
707
705
|
width: 10px;
|
|
708
706
|
cursor: col-resize;
|
|
709
707
|
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));
|
|
708
|
+
`;
|
|
709
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
710
|
+
function makeColumnResizeTransform({ sizes, onChangeSizes, minSize = 40, maxSize = Infinity, appendExpander, expanderVisibility = 'visible', disableUserSelectWhenResizing, }) {
|
|
711
|
+
warnTransformsDeprecated('makeColumnResizeTransform');
|
|
712
|
+
const startResize = (colIndex, e) => {
|
|
713
|
+
const startX = e.clientX;
|
|
714
|
+
const startSize = sizes[colIndex];
|
|
715
|
+
const nextSizes$ = rxjs.fromEvent(window, 'mousemove').pipe(op__namespace.takeUntil(rxjs.fromEvent(window, 'mouseup')), op__namespace.map((e) => {
|
|
716
|
+
const movingX = e.clientX;
|
|
717
|
+
const nextSizes = sizes.slice();
|
|
718
|
+
nextSizes[colIndex] = clamp$1(minSize, startSize + (movingX - startX), maxSize);
|
|
719
|
+
return nextSizes;
|
|
720
|
+
}));
|
|
721
|
+
let prevUserSelect = '';
|
|
722
|
+
let docElemStyle;
|
|
723
|
+
if (disableUserSelectWhenResizing) {
|
|
724
|
+
docElemStyle = document.documentElement.style;
|
|
725
|
+
prevUserSelect = docElemStyle.userSelect;
|
|
726
|
+
docElemStyle.userSelect = 'none';
|
|
727
|
+
}
|
|
728
|
+
nextSizes$.subscribe({
|
|
729
|
+
next: onChangeSizes,
|
|
730
|
+
complete() {
|
|
731
|
+
if (disableUserSelectWhenResizing) {
|
|
732
|
+
docElemStyle.userSelect = prevUserSelect;
|
|
733
|
+
}
|
|
734
|
+
},
|
|
735
|
+
});
|
|
736
|
+
};
|
|
737
|
+
const innerTransform = traverseColumn((col, { range }) => {
|
|
738
|
+
var _a;
|
|
739
|
+
if (!pipeline.isLeafNode(col)) {
|
|
740
|
+
return col;
|
|
741
|
+
}
|
|
742
|
+
const prevTitle = pipeline.internals.safeRenderHeader(col);
|
|
743
|
+
return Object.assign(Object.assign({}, col), { width: sizes[range.start], title: (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
744
|
+
prevTitle,
|
|
745
|
+
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' }) }) });
|
|
746
|
+
});
|
|
747
|
+
return (input) => {
|
|
748
|
+
const { columns, dataSource } = innerTransform(input);
|
|
749
|
+
return {
|
|
750
|
+
columns: appendExpander
|
|
751
|
+
? columns.concat([
|
|
752
|
+
{
|
|
753
|
+
name: '',
|
|
754
|
+
headerCellProps: {
|
|
755
|
+
className: RESIZE_EXPANDER_CLS,
|
|
756
|
+
style: {
|
|
757
|
+
background: expanderVisibility === 'hidden' ? 'var(--bgcolor)' : undefined,
|
|
758
|
+
border: expanderVisibility === 'hidden' ? 'none' : undefined,
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
getCellProps() {
|
|
762
|
+
return {
|
|
763
|
+
className: RESIZE_EXPANDER_CLS,
|
|
764
|
+
style: { visibility: expanderVisibility },
|
|
765
|
+
};
|
|
766
|
+
},
|
|
767
|
+
},
|
|
768
|
+
])
|
|
769
|
+
: columns,
|
|
770
|
+
dataSource,
|
|
771
|
+
};
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
775
|
+
function useColumnResizeTransform(_a) {
|
|
776
|
+
var { defaultSizes } = _a, others = pipeline.__rest(_a, ["defaultSizes"]);
|
|
777
|
+
const [sizes, onChangeSizes] = React.useState(defaultSizes);
|
|
778
|
+
return makeColumnResizeTransform(Object.assign({ sizes, onChangeSizes }, others));
|
|
781
779
|
}
|
|
782
780
|
|
|
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
|
-
});
|
|
781
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
782
|
+
function makeFlattenTransform() {
|
|
783
|
+
warnTransformsDeprecated('makeFlattenTransform');
|
|
784
|
+
return traverseColumn((column) => {
|
|
785
|
+
var _a;
|
|
786
|
+
if (pipeline.isLeafNode(column)) {
|
|
787
|
+
return column;
|
|
788
|
+
}
|
|
789
|
+
return ((_a = column.features) === null || _a === void 0 ? void 0 : _a.flatten) ? column.children : column;
|
|
790
|
+
});
|
|
793
791
|
}
|
|
794
792
|
|
|
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
|
-
});
|
|
793
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
794
|
+
function makeOrderFieldTransform(startOrder = 1) {
|
|
795
|
+
warnTransformsDeprecated('makeOrderFieldTransform');
|
|
796
|
+
return traverseColumn((column) => {
|
|
797
|
+
var _a, _b;
|
|
798
|
+
if (((_a = column.features) === null || _a === void 0 ? void 0 : _a.order) || ((_b = column.features) === null || _b === void 0 ? void 0 : _b.orderField)) {
|
|
799
|
+
return Object.assign(Object.assign({}, column), { getValue(record, index) {
|
|
800
|
+
return index + startOrder;
|
|
801
|
+
} });
|
|
802
|
+
}
|
|
803
|
+
return column;
|
|
804
|
+
});
|
|
807
805
|
}
|
|
808
806
|
|
|
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
|
-
}
|
|
807
|
+
function SortIcon$1({ size = 32, style, className, order, }) {
|
|
808
|
+
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" },
|
|
809
|
+
React__default["default"].createElement("path", { fill: order === 'asc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, 4)", d: "M8 8L16 0 24 8z" }),
|
|
810
|
+
React__default["default"].createElement("path", { fill: order === 'desc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, -4)", d: "M24 24L16 32 8 24z " })));
|
|
811
|
+
}
|
|
812
|
+
function DefaultSortHeaderCell$1({ children, column, onToggle, sortOrder, sortIndex, sortOptions }) {
|
|
813
|
+
// 通过 justify-content 来与 col.align 保持对齐方向一致
|
|
814
|
+
const justifyContent = column.align === 'right' ? 'flex-end' : column.align === 'center' ? 'center' : 'flex-start';
|
|
815
|
+
return (React__default["default"].createElement(TableHeaderCell$1, { onClick: onToggle, style: { justifyContent } },
|
|
816
|
+
children,
|
|
817
|
+
React__default["default"].createElement(SortIcon$1, { style: { userSelect: 'none', marginLeft: 2, flexShrink: 0 }, size: 16, order: sortOrder }),
|
|
818
|
+
sortOptions.mode === 'multiple' && sortIndex != -1 && (React__default["default"].createElement("div", { style: {
|
|
819
|
+
userSelect: 'none',
|
|
820
|
+
marginLeft: 2,
|
|
821
|
+
color: '#666',
|
|
822
|
+
flex: '0 0 auto',
|
|
823
|
+
fontSize: 10,
|
|
824
|
+
fontFamily: 'monospace',
|
|
825
|
+
} }, sortIndex + 1))));
|
|
826
|
+
}
|
|
827
|
+
function hasAnySortableColumns$1(cols) {
|
|
828
|
+
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)); });
|
|
829
|
+
}
|
|
832
830
|
const TableHeaderCell$1 = styled__default["default"].div `
|
|
833
831
|
cursor: pointer;
|
|
834
832
|
display: flex;
|
|
835
833
|
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));
|
|
834
|
+
`;
|
|
835
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
836
|
+
function makeSortTransform({ sorts: inputSorts, onChangeSorts: inputOnChangeSorts, orders = ['desc', 'asc', 'none'], mode = 'multiple', SortHeaderCell = DefaultSortHeaderCell$1, keepDataSource, highlightColumnWhenActive, stopClickEventPropagation, }) {
|
|
837
|
+
warnTransformsDeprecated('makeSortTransform');
|
|
838
|
+
const filteredInputSorts = inputSorts.filter((s) => s.order !== 'none');
|
|
839
|
+
// 单字段排序的情况下 sorts 中只有第一个排序字段才会生效
|
|
840
|
+
const sorts = mode === 'multiple' ? filteredInputSorts : filteredInputSorts.slice(0, 1);
|
|
841
|
+
const onChangeSorts = mode === 'multiple'
|
|
842
|
+
? inputOnChangeSorts
|
|
843
|
+
: (nextSorts) => {
|
|
844
|
+
// 单字段排序的情况下,nextSorts 中只有最后一个排序字段才会生效
|
|
845
|
+
const len = nextSorts.length;
|
|
846
|
+
inputOnChangeSorts(nextSorts.slice(len - 1));
|
|
847
|
+
};
|
|
848
|
+
const sortOptions = {
|
|
849
|
+
sorts,
|
|
850
|
+
onChangeSorts,
|
|
851
|
+
orders,
|
|
852
|
+
mode,
|
|
853
|
+
keepDataSource,
|
|
854
|
+
highlightColumnWhenActive,
|
|
855
|
+
stopClickEventPropagation,
|
|
856
|
+
};
|
|
857
|
+
const sortMap = new Map(sorts.map((sort, index) => [sort.code, Object.assign({ index }, sort)]));
|
|
858
|
+
return ({ dataSource, columns }) => {
|
|
859
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
860
|
+
if (!hasAnySortableColumns$1(columns)) {
|
|
861
|
+
console.warn('[srp-table] commonTransform.sort 缺少可排序的列,请通过 column.features.sortable 来指定哪些列可排序', columns);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return { columns: processColumns(columns), dataSource: processDataSource(dataSource) };
|
|
865
|
+
function processDataSource(dataSource) {
|
|
866
|
+
if (keepDataSource) {
|
|
867
|
+
return dataSource;
|
|
868
|
+
}
|
|
869
|
+
const sortColumnsMap = new Map(pipeline.collectNodes(columns, 'leaf-only')
|
|
870
|
+
.filter((col) => { var _a; return ((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) != null; })
|
|
871
|
+
.map((col) => [col.code, col]));
|
|
872
|
+
return layeredSort(dataSource, (x, y) => {
|
|
873
|
+
for (const { code, order } of sorts) {
|
|
874
|
+
const column = sortColumnsMap.get(code);
|
|
875
|
+
// 如果 code 对应的 column 不可排序,我们跳过该 code
|
|
876
|
+
if (column == null) {
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
const sortable = column.features.sortable;
|
|
880
|
+
const compareFn = typeof sortable === 'function' ? sortable : smartCompare;
|
|
881
|
+
const xValue = pipeline.internals.safeGetValue(column, x, -1);
|
|
882
|
+
const yValue = pipeline.internals.safeGetValue(column, y, -1);
|
|
883
|
+
const cmp = compareFn(xValue, yValue);
|
|
884
|
+
if (cmp !== 0) {
|
|
885
|
+
return cmp * (order === 'asc' ? 1 : -1);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return 0;
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
// 在「升序 - 降序 - 不排序」之间不断切换
|
|
892
|
+
function toggle(code) {
|
|
893
|
+
const sort = sortMap.get(code);
|
|
894
|
+
if (sort == null) {
|
|
895
|
+
onChangeSorts(sorts.concat([{ code, order: orders[0] }]));
|
|
896
|
+
}
|
|
897
|
+
else {
|
|
898
|
+
const index = sorts.findIndex((s) => s.code === code);
|
|
899
|
+
const nextSorts = sorts.slice(0, index + 1);
|
|
900
|
+
const nextOrder = getNextOrder(sort.order);
|
|
901
|
+
if (nextOrder === 'none') {
|
|
902
|
+
nextSorts.pop();
|
|
903
|
+
}
|
|
904
|
+
else {
|
|
905
|
+
nextSorts[index] = Object.assign(Object.assign({}, nextSorts[index]), { order: nextOrder });
|
|
906
|
+
}
|
|
907
|
+
onChangeSorts(nextSorts);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
function processColumns(columns) {
|
|
911
|
+
return columns.map(dfs);
|
|
912
|
+
function dfs(col) {
|
|
913
|
+
var _a;
|
|
914
|
+
const result = Object.assign({}, col);
|
|
915
|
+
const sortable = col.code && (((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) || sortMap.has(col.code));
|
|
916
|
+
const active = sortable && sortMap.has(col.code);
|
|
917
|
+
if (sortable) {
|
|
918
|
+
let sortIndex = -1;
|
|
919
|
+
let sortOrder = 'none';
|
|
920
|
+
if (active) {
|
|
921
|
+
const { order, index } = sortMap.get(col.code);
|
|
922
|
+
sortOrder = order;
|
|
923
|
+
sortIndex = index;
|
|
924
|
+
if (highlightColumnWhenActive) {
|
|
925
|
+
result.headerCellProps = pipeline.mergeCellProps(col.headerCellProps, {
|
|
926
|
+
style: { background: 'var(--header-highlight-bgcolor)' },
|
|
927
|
+
});
|
|
928
|
+
result.getCellProps = (value, row, rowIndex) => {
|
|
929
|
+
const prevCellProps = pipeline.internals.safeGetCellProps(col, row, rowIndex);
|
|
930
|
+
return pipeline.mergeCellProps(prevCellProps, {
|
|
931
|
+
style: { background: 'var(--highlight-bgcolor)' },
|
|
932
|
+
});
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
result.title = (React__default["default"].createElement(SortHeaderCell, { onToggle: (e) => {
|
|
937
|
+
if (stopClickEventPropagation) {
|
|
938
|
+
e.stopPropagation();
|
|
939
|
+
}
|
|
940
|
+
toggle(col.code);
|
|
941
|
+
}, sortOrder: sortOrder, column: col, sortIndex: sortIndex, sortOptions: sortOptions }, pipeline.internals.safeRenderHeader(col)));
|
|
942
|
+
}
|
|
943
|
+
if (!pipeline.isLeafNode(col)) {
|
|
944
|
+
result.children = col.children.map(dfs);
|
|
945
|
+
}
|
|
946
|
+
return result;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
function getNextOrder(order) {
|
|
951
|
+
const idx = orders.indexOf(order);
|
|
952
|
+
return orders[idx === orders.length - 1 ? 0 : idx + 1];
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
956
|
+
function useSortTransform(_a = {}) {
|
|
957
|
+
var { defaultSorts = [] } = _a, others = pipeline.__rest(_a, ["defaultSorts"]);
|
|
958
|
+
const [sorts, onChangeSorts] = React.useState(defaultSorts);
|
|
959
|
+
return makeSortTransform(Object.assign({ sorts, onChangeSorts }, others));
|
|
962
960
|
}
|
|
963
961
|
|
|
964
962
|
const HeaderCellWithTips$1 = styled__default["default"].div `
|
|
@@ -973,181 +971,181 @@ const HeaderCellWithTips$1 = styled__default["default"].div `
|
|
|
973
971
|
display: flex;
|
|
974
972
|
fill: currentColor;
|
|
975
973
|
}
|
|
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
|
-
});
|
|
974
|
+
`;
|
|
975
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
976
|
+
function makeTipsTransform({ Balloon, Tooltip }) {
|
|
977
|
+
warnTransformsDeprecated('makeTipsTransform');
|
|
978
|
+
return traverseColumn((col) => {
|
|
979
|
+
var _a;
|
|
980
|
+
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.tips)) {
|
|
981
|
+
return col;
|
|
982
|
+
}
|
|
983
|
+
const justifyContent = col.align === 'right' ? 'flex-end' : col.align === 'center' ? 'center' : 'flex-start';
|
|
984
|
+
return Object.assign(Object.assign({}, col), { title: (React__default["default"].createElement(HeaderCellWithTips$1, { style: { justifyContent } },
|
|
985
|
+
pipeline.internals.safeRenderHeader(col),
|
|
986
|
+
Balloon ? (
|
|
987
|
+
// fusion/hippo
|
|
988
|
+
React__default["default"].createElement(Balloon, { closable: false, trigger: React__default["default"].createElement("div", { className: "tip-icon-wrapper" },
|
|
989
|
+
React__default["default"].createElement(pipeline.icons.Info, { className: "tip-icon" })) }, col.features.tips)) : (
|
|
990
|
+
// antd
|
|
991
|
+
React__default["default"].createElement(Tooltip, { title: col.features.tips },
|
|
992
|
+
React__default["default"].createElement("div", { className: "tip-icon-wrapper" },
|
|
993
|
+
React__default["default"].createElement(pipeline.icons.Info, { className: "tip-icon" })))))) });
|
|
994
|
+
});
|
|
997
995
|
}
|
|
998
996
|
|
|
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
|
-
};
|
|
997
|
+
function isIdentity(x, y) {
|
|
998
|
+
return x === y;
|
|
999
|
+
}
|
|
1000
|
+
function autoRowSpan() {
|
|
1001
|
+
return function autoRowSpanStep(pipeline$1) {
|
|
1002
|
+
const dataSource = pipeline$1.getDataSource();
|
|
1003
|
+
return pipeline$1.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1004
|
+
var _a;
|
|
1005
|
+
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.autoRowSpan)) {
|
|
1006
|
+
return col;
|
|
1007
|
+
}
|
|
1008
|
+
if (!pipeline.isLeafNode(col)) {
|
|
1009
|
+
return col;
|
|
1010
|
+
}
|
|
1011
|
+
const isFunc = typeof col.features.autoRowSpan === 'function';
|
|
1012
|
+
const shouldMergeCell = isFunc ? col.features.autoRowSpan : isIdentity;
|
|
1013
|
+
const spanRects = [];
|
|
1014
|
+
let lastBottom = 0;
|
|
1015
|
+
let prevValue = null;
|
|
1016
|
+
let prevRow = null;
|
|
1017
|
+
for (let rowIndex = 0; rowIndex < dataSource.length; rowIndex++) {
|
|
1018
|
+
const row = dataSource[rowIndex];
|
|
1019
|
+
const value = pipeline.internals.safeGetValue(col, row, rowIndex);
|
|
1020
|
+
if (rowIndex === 0 || !shouldMergeCell(prevValue, value, prevRow, row)) {
|
|
1021
|
+
const spanRect = {
|
|
1022
|
+
top: lastBottom,
|
|
1023
|
+
bottom: rowIndex,
|
|
1024
|
+
left: startIndex,
|
|
1025
|
+
right: endIndex,
|
|
1026
|
+
};
|
|
1027
|
+
for (let i = lastBottom; i < rowIndex; i++) {
|
|
1028
|
+
spanRects.push(spanRect);
|
|
1029
|
+
}
|
|
1030
|
+
lastBottom = rowIndex;
|
|
1031
|
+
}
|
|
1032
|
+
prevValue = value;
|
|
1033
|
+
prevRow = row;
|
|
1034
|
+
}
|
|
1035
|
+
for (let i = lastBottom; i < dataSource.length; i++) {
|
|
1036
|
+
spanRects.push({
|
|
1037
|
+
top: lastBottom,
|
|
1038
|
+
bottom: dataSource.length,
|
|
1039
|
+
left: startIndex,
|
|
1040
|
+
right: endIndex,
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
return Object.assign(Object.assign({}, col), { getSpanRect(value, row, rowIndex) {
|
|
1044
|
+
return spanRects[rowIndex];
|
|
1045
|
+
} });
|
|
1046
|
+
}));
|
|
1047
|
+
};
|
|
1050
1048
|
}
|
|
1051
1049
|
|
|
1052
|
-
function buildTree(idProp, parentIdProp) {
|
|
1053
|
-
return (pipeline) => pipeline.mapDataSource((rows) => buildTree$1(idProp, parentIdProp, rows));
|
|
1050
|
+
function buildTree(idProp, parentIdProp) {
|
|
1051
|
+
return (pipeline) => pipeline.mapDataSource((rows) => buildTree$1(idProp, parentIdProp, rows));
|
|
1054
1052
|
}
|
|
1055
1053
|
|
|
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
|
-
};
|
|
1054
|
+
function columnHover(opts = {}) {
|
|
1055
|
+
const stateKey = 'columnHover';
|
|
1056
|
+
return (pipeline$1) => {
|
|
1057
|
+
var _a, _b, _c, _d;
|
|
1058
|
+
const hoverColor = (_a = opts.hoverColor) !== null && _a !== void 0 ? _a : 'var(--hover-bgcolor)';
|
|
1059
|
+
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;
|
|
1060
|
+
const onChangeHoverColIndex = (nextColIndex) => {
|
|
1061
|
+
var _a;
|
|
1062
|
+
pipeline$1.setStateAtKey(stateKey, nextColIndex);
|
|
1063
|
+
(_a = opts.onChangeHoverColIndex) === null || _a === void 0 ? void 0 : _a.call(opts, nextColIndex);
|
|
1064
|
+
};
|
|
1065
|
+
return pipeline$1.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1066
|
+
const range = { start: startIndex, end: endIndex };
|
|
1067
|
+
if (!pipeline.isLeafNode(col)) {
|
|
1068
|
+
return col;
|
|
1069
|
+
}
|
|
1070
|
+
const colIndexMatched = range.start <= hoverColIndex && hoverColIndex < range.end;
|
|
1071
|
+
const prevGetCellProps = col.getCellProps;
|
|
1072
|
+
return Object.assign(Object.assign({}, col), { getCellProps(value, record, rowIndex) {
|
|
1073
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1074
|
+
return pipeline.mergeCellProps(prevCellProps, {
|
|
1075
|
+
style: { '--bgcolor': colIndexMatched ? hoverColor : undefined },
|
|
1076
|
+
onMouseEnter() {
|
|
1077
|
+
onChangeHoverColIndex(range.start);
|
|
1078
|
+
},
|
|
1079
|
+
onMouseLeave() {
|
|
1080
|
+
onChangeHoverColIndex(-1);
|
|
1081
|
+
},
|
|
1082
|
+
});
|
|
1083
|
+
} });
|
|
1084
|
+
}));
|
|
1085
|
+
};
|
|
1088
1086
|
}
|
|
1089
1087
|
|
|
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
|
-
};
|
|
1088
|
+
const EMPTY_RANGE = {
|
|
1089
|
+
start: -1,
|
|
1090
|
+
end: -1,
|
|
1091
|
+
};
|
|
1092
|
+
function columnRangeHover(opts = {}) {
|
|
1093
|
+
const stateKey = 'columnHover';
|
|
1094
|
+
return function columnRangeHoverStep(pipeline$1) {
|
|
1095
|
+
var _a, _b, _c, _d, _e;
|
|
1096
|
+
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;
|
|
1097
|
+
const hoverColor = (_d = opts.hoverColor) !== null && _d !== void 0 ? _d : 'var(--hover-bgcolor)';
|
|
1098
|
+
const headerHoverColor = (_e = opts.headerHoverColor) !== null && _e !== void 0 ? _e : 'var(--header-hover-bgcolor)';
|
|
1099
|
+
const onChangeHoverRange = (nextColIndexRange) => {
|
|
1100
|
+
var _a;
|
|
1101
|
+
pipeline$1.setStateAtKey(stateKey, nextColIndexRange);
|
|
1102
|
+
(_a = opts.onChangeHoverRange) === null || _a === void 0 ? void 0 : _a.call(opts, nextColIndexRange);
|
|
1103
|
+
};
|
|
1104
|
+
return pipeline$1.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1105
|
+
const colRange = { start: startIndex, end: endIndex };
|
|
1106
|
+
const match = colRange.end > hoverRange.start && hoverRange.end > colRange.start;
|
|
1107
|
+
if (!pipeline.isLeafNode(col)) {
|
|
1108
|
+
if (headerHoverColor == null) {
|
|
1109
|
+
return col;
|
|
1110
|
+
}
|
|
1111
|
+
return Object.assign(Object.assign({}, col), { headerCellProps: pipeline.mergeCellProps(col.headerCellProps, {
|
|
1112
|
+
onMouseEnter() {
|
|
1113
|
+
onChangeHoverRange(colRange);
|
|
1114
|
+
},
|
|
1115
|
+
onMouseLeave() {
|
|
1116
|
+
onChangeHoverRange(EMPTY_RANGE);
|
|
1117
|
+
},
|
|
1118
|
+
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
1119
|
+
}) });
|
|
1120
|
+
}
|
|
1121
|
+
const prevGetCellProps = col.getCellProps;
|
|
1122
|
+
return Object.assign(Object.assign({}, col), { headerCellProps: pipeline.mergeCellProps(col.headerCellProps, {
|
|
1123
|
+
onMouseEnter() {
|
|
1124
|
+
onChangeHoverRange(colRange);
|
|
1125
|
+
},
|
|
1126
|
+
onMouseLeave() {
|
|
1127
|
+
onChangeHoverRange(EMPTY_RANGE);
|
|
1128
|
+
},
|
|
1129
|
+
style: { '--header-bgcolor': match ? headerHoverColor : undefined },
|
|
1130
|
+
}), getCellProps(value, record, rowIndex) {
|
|
1131
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1132
|
+
return pipeline.mergeCellProps(prevCellProps, {
|
|
1133
|
+
onMouseEnter() {
|
|
1134
|
+
onChangeHoverRange(colRange);
|
|
1135
|
+
},
|
|
1136
|
+
onMouseLeave() {
|
|
1137
|
+
onChangeHoverRange(EMPTY_RANGE);
|
|
1138
|
+
},
|
|
1139
|
+
style: { '--bgcolor': match ? hoverColor : undefined },
|
|
1140
|
+
});
|
|
1141
|
+
} });
|
|
1142
|
+
}));
|
|
1143
|
+
};
|
|
1146
1144
|
}
|
|
1147
1145
|
|
|
1148
|
-
function clamp(min, x, max) {
|
|
1149
|
-
return Math.max(min, Math.min(max, x));
|
|
1150
|
-
}
|
|
1146
|
+
function clamp(min, x, max) {
|
|
1147
|
+
return Math.max(min, Math.min(max, x));
|
|
1148
|
+
}
|
|
1151
1149
|
const ResizeHandle = styled__default["default"].span `
|
|
1152
1150
|
position: absolute;
|
|
1153
1151
|
top: 0;
|
|
@@ -1158,812 +1156,821 @@ const ResizeHandle = styled__default["default"].span `
|
|
|
1158
1156
|
z-index: 1;
|
|
1159
1157
|
transition: background-color 200ms;
|
|
1160
1158
|
|
|
1161
|
-
background: ${(props) => {
|
|
1162
|
-
return props['var-handleBackground'];
|
|
1159
|
+
background: ${(props) => {
|
|
1160
|
+
return props['var-handleBackground'];
|
|
1163
1161
|
}};
|
|
1164
1162
|
|
|
1165
1163
|
&:hover {
|
|
1166
|
-
background: ${(props) => {
|
|
1167
|
-
return props['var-handleHoverBackground'];
|
|
1164
|
+
background: ${(props) => {
|
|
1165
|
+
return props['var-handleHoverBackground'];
|
|
1168
1166
|
}};
|
|
1169
1167
|
}
|
|
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
|
|
1182
|
-
leafColumns.
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
const
|
|
1200
|
-
const
|
|
1201
|
-
|
|
1202
|
-
const
|
|
1203
|
-
const
|
|
1204
|
-
const
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
let
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
docElemStyle.userSelect
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1168
|
+
`;
|
|
1169
|
+
function columnResize(opts = {}) {
|
|
1170
|
+
var _a, _b, _c, _d;
|
|
1171
|
+
const stateKey = 'columnResize';
|
|
1172
|
+
const disableUserSelectWhenResizing = (_a = opts.disableUserSelectWhenResizing) !== null && _a !== void 0 ? _a : true;
|
|
1173
|
+
const minSize = (_b = opts.minSize) !== null && _b !== void 0 ? _b : 60;
|
|
1174
|
+
const fallbackSize = (_c = opts.fallbackSize) !== null && _c !== void 0 ? _c : 150;
|
|
1175
|
+
const maxSize = (_d = opts.maxSize) !== null && _d !== void 0 ? _d : 1000;
|
|
1176
|
+
return function columnResizeFeature(pipeline$1) {
|
|
1177
|
+
var _a, _b, _c;
|
|
1178
|
+
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 : [];
|
|
1179
|
+
const { columns, fillColumn } = pipeline.takeFillRemainingWidthColumn(pipeline$1.getColumns());
|
|
1180
|
+
const leafColumns = pipeline.collectNodes(columns, 'leaf-only');
|
|
1181
|
+
leafColumns.forEach((col, colIndex) => {
|
|
1182
|
+
if (sizes[colIndex] == null) {
|
|
1183
|
+
if (typeof col.width === 'number') {
|
|
1184
|
+
sizes[colIndex] = col.width;
|
|
1185
|
+
}
|
|
1186
|
+
else {
|
|
1187
|
+
sizes[colIndex] = fallbackSize;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
const onChangeSizes = (nextSizes) => {
|
|
1192
|
+
var _a;
|
|
1193
|
+
pipeline$1.setStateAtKey(stateKey, nextSizes);
|
|
1194
|
+
(_a = opts.onChangeSizes) === null || _a === void 0 ? void 0 : _a.call(opts, nextSizes);
|
|
1195
|
+
};
|
|
1196
|
+
const startResize = (startIndex, endIndex, e) => {
|
|
1197
|
+
const startX = e.clientX;
|
|
1198
|
+
const target = e.target;
|
|
1199
|
+
const nextSizes$ = rxjs.fromEvent(window, 'mousemove').pipe(op__namespace.takeUntil(rxjs.fromEvent(window, 'mouseup')), op__namespace.map((e) => {
|
|
1200
|
+
const movingX = e.clientX;
|
|
1201
|
+
const nextSizes = sizes.slice();
|
|
1202
|
+
const deltaSum = movingX - startX;
|
|
1203
|
+
const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
|
|
1204
|
+
let deltaRemaining = deltaSum;
|
|
1205
|
+
for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
|
|
1206
|
+
const startSize = sizes[colIndex];
|
|
1207
|
+
// 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
|
|
1208
|
+
const colDelta = Math.round(deltaSum * (startSize / sizeSum));
|
|
1209
|
+
nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
|
|
1210
|
+
deltaRemaining -= colDelta;
|
|
1211
|
+
}
|
|
1212
|
+
// 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
|
|
1213
|
+
nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
|
|
1214
|
+
return nextSizes;
|
|
1215
|
+
}));
|
|
1216
|
+
let prevUserSelect = '';
|
|
1217
|
+
let docElemStyle;
|
|
1218
|
+
if (disableUserSelectWhenResizing) {
|
|
1219
|
+
docElemStyle = document.documentElement.style;
|
|
1220
|
+
prevUserSelect = docElemStyle.userSelect;
|
|
1221
|
+
docElemStyle.userSelect = 'none';
|
|
1222
|
+
}
|
|
1223
|
+
if (opts.handleActiveBackground) {
|
|
1224
|
+
target.style.background = opts.handleActiveBackground;
|
|
1225
|
+
}
|
|
1226
|
+
nextSizes$.subscribe({
|
|
1227
|
+
next: onChangeSizes,
|
|
1228
|
+
complete() {
|
|
1229
|
+
if (disableUserSelectWhenResizing) {
|
|
1230
|
+
docElemStyle.userSelect = prevUserSelect;
|
|
1231
|
+
}
|
|
1232
|
+
if (opts.handleActiveBackground) {
|
|
1233
|
+
target.style.background = '';
|
|
1234
|
+
}
|
|
1235
|
+
},
|
|
1236
|
+
});
|
|
1237
|
+
};
|
|
1238
|
+
const resizedColumns = makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1239
|
+
const prevTitle = pipeline.internals.safeRenderHeader(col);
|
|
1240
|
+
return Object.assign(Object.assign({}, col), { width: sizes[startIndex], title: (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
1241
|
+
prevTitle,
|
|
1242
|
+
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, {
|
|
1243
|
+
style: {
|
|
1244
|
+
overflow: 'visible',
|
|
1245
|
+
position: 'relative',
|
|
1246
|
+
},
|
|
1247
|
+
}) });
|
|
1248
|
+
})(columns);
|
|
1249
|
+
return pipeline$1.columns(fillColumn == null ? resizedColumns : pipeline.appendFillRemainingWidthColumn(resizedColumns, fillColumn));
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
function fillRemainingWidth() {
|
|
1254
|
+
return function fillRemainingWidthStep(pipeline$1) {
|
|
1255
|
+
return pipeline$1.columns(pipeline.appendFillRemainingWidthColumn(pipeline$1.getColumns()));
|
|
1256
|
+
};
|
|
1251
1257
|
}
|
|
1252
1258
|
|
|
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
|
-
};
|
|
1259
|
+
function multiSelect(opts = {}) {
|
|
1260
|
+
return function multiSelectStep(pipeline$1) {
|
|
1261
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1262
|
+
const stateKey = 'multiSelect';
|
|
1263
|
+
const Checkbox = pipeline$1.ctx.components.Checkbox;
|
|
1264
|
+
if (Checkbox == null) {
|
|
1265
|
+
throw new Error('使用 multiSelect 之前需要设置 pipeline.ctx.components.Checkbox');
|
|
1266
|
+
}
|
|
1267
|
+
const primaryKey = pipeline$1.ensurePrimaryKey('multiSelect');
|
|
1268
|
+
const isDisabled = (_a = opts.isDisabled) !== null && _a !== void 0 ? _a : pipeline.always(false);
|
|
1269
|
+
const clickArea = (_b = opts.clickArea) !== null && _b !== void 0 ? _b : 'checkbox';
|
|
1270
|
+
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 : [];
|
|
1271
|
+
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 : '';
|
|
1272
|
+
const onChange = (nextValue, key, keys, action) => {
|
|
1273
|
+
var _a;
|
|
1274
|
+
(_a = opts.onChange) === null || _a === void 0 ? void 0 : _a.call(opts, nextValue, key, keys, action);
|
|
1275
|
+
pipeline$1.setStateAtKey(stateKey, { value: nextValue, lastKey: key }, { keys, action });
|
|
1276
|
+
};
|
|
1277
|
+
const dataSource = pipeline$1.getDataSource();
|
|
1278
|
+
/** dataSource 中包含的所有 keys */
|
|
1279
|
+
const fullKeySet = new Set();
|
|
1280
|
+
/** 所有有效的 keys(disable 状态为 false) */
|
|
1281
|
+
const allKeys = [];
|
|
1282
|
+
dataSource.forEach((row, rowIndex) => {
|
|
1283
|
+
const rowKey = pipeline.internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1284
|
+
fullKeySet.add(rowKey);
|
|
1285
|
+
// 在 allKeys 中排除被禁用的 key
|
|
1286
|
+
if (!isDisabled(row, rowIndex)) {
|
|
1287
|
+
allKeys.push(rowKey);
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
const set = new Set(value);
|
|
1291
|
+
const isAllChecked = allKeys.length > 0 && allKeys.every((key) => set.has(key));
|
|
1292
|
+
const isAnyChecked = allKeys.some((key) => set.has(key));
|
|
1293
|
+
const defaultCheckboxColumnTitle = (React__default["default"].createElement(Checkbox, { checked: isAllChecked, indeterminate: !isAllChecked && isAnyChecked, onChange: (_) => {
|
|
1294
|
+
if (isAllChecked) {
|
|
1295
|
+
onChange(pipeline.arrayUtils.diff(value, allKeys), '', allKeys, 'uncheck-all');
|
|
1296
|
+
}
|
|
1297
|
+
else {
|
|
1298
|
+
onChange(pipeline.arrayUtils.merge(value, allKeys), '', allKeys, 'check-all');
|
|
1299
|
+
}
|
|
1300
|
+
} }));
|
|
1301
|
+
const checkboxColumn = Object.assign(Object.assign({ name: '是否选中', title: defaultCheckboxColumnTitle, width: 50, align: 'center' }, opts.checkboxColumn), { getCellProps(value, row, rowIndex) {
|
|
1302
|
+
const rowKey = pipeline.internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1303
|
+
if (fullKeySet.has(rowKey) && clickArea === 'cell') {
|
|
1304
|
+
const prevChecked = set.has(rowKey);
|
|
1305
|
+
const disabled = isDisabled(row, rowIndex);
|
|
1306
|
+
return {
|
|
1307
|
+
style: { cursor: disabled ? 'not-allowed' : 'pointer' },
|
|
1308
|
+
onClick: disabled
|
|
1309
|
+
? undefined
|
|
1310
|
+
: (e) => {
|
|
1311
|
+
if (opts.stopClickEventPropagation) {
|
|
1312
|
+
e.stopPropagation();
|
|
1313
|
+
}
|
|
1314
|
+
onCheckboxChange(prevChecked, rowKey, e.shiftKey);
|
|
1315
|
+
},
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
},
|
|
1319
|
+
render(_, row, rowIndex) {
|
|
1320
|
+
const key = pipeline.internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1321
|
+
const checked = set.has(key);
|
|
1322
|
+
return (React__default["default"].createElement(Checkbox, { checked: checked, disabled: isDisabled(row, rowIndex), onChange: clickArea === 'checkbox'
|
|
1323
|
+
? (arg1, arg2) => {
|
|
1324
|
+
var _a;
|
|
1325
|
+
// 这里要同时兼容 antd 和 fusion 的用法
|
|
1326
|
+
// fusion: arg2?.nativeEvent
|
|
1327
|
+
// antd: arg1.nativeEvent
|
|
1328
|
+
const nativeEvent = (_a = arg2 === null || arg2 === void 0 ? void 0 : arg2.nativeEvent) !== null && _a !== void 0 ? _a : arg1.nativeEvent;
|
|
1329
|
+
if (nativeEvent) {
|
|
1330
|
+
if (opts.stopClickEventPropagation) {
|
|
1331
|
+
nativeEvent.stopPropagation();
|
|
1332
|
+
}
|
|
1333
|
+
onCheckboxChange(checked, key, nativeEvent.shiftKey);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
: undefined }));
|
|
1337
|
+
} });
|
|
1338
|
+
const nextColumns = pipeline$1.getColumns().slice();
|
|
1339
|
+
const checkboxPlacement = (_l = opts.checkboxPlacement) !== null && _l !== void 0 ? _l : 'start';
|
|
1340
|
+
if (checkboxPlacement === 'start') {
|
|
1341
|
+
nextColumns.unshift(checkboxColumn);
|
|
1342
|
+
}
|
|
1343
|
+
else {
|
|
1344
|
+
nextColumns.push(checkboxColumn);
|
|
1345
|
+
}
|
|
1346
|
+
pipeline$1.columns(nextColumns);
|
|
1347
|
+
pipeline$1.appendRowPropsGetter((row, rowIndex) => {
|
|
1348
|
+
const rowKey = pipeline.internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1349
|
+
if (!fullKeySet.has(rowKey)) {
|
|
1350
|
+
// rowKey 不在 fullKeySet 中说明这一行是在 multiSelect 之后才生成的,multiSelect 不对之后生成的行进行处理
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
let style = {};
|
|
1354
|
+
let className;
|
|
1355
|
+
let onClick;
|
|
1356
|
+
const checked = set.has(rowKey);
|
|
1357
|
+
if (opts.highlightRowWhenSelected && checked) {
|
|
1358
|
+
className = 'highlight';
|
|
1359
|
+
}
|
|
1360
|
+
if (clickArea === 'row') {
|
|
1361
|
+
const disabled = isDisabled(row, rowIndex);
|
|
1362
|
+
if (!disabled) {
|
|
1363
|
+
style.cursor = 'pointer';
|
|
1364
|
+
onClick = (e) => {
|
|
1365
|
+
if (opts.stopClickEventPropagation) {
|
|
1366
|
+
e.stopPropagation();
|
|
1367
|
+
}
|
|
1368
|
+
onCheckboxChange(checked, rowKey, e.shiftKey);
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
return { className, style, onClick };
|
|
1373
|
+
});
|
|
1374
|
+
return pipeline$1;
|
|
1375
|
+
function onCheckboxChange(prevChecked, key, batch) {
|
|
1376
|
+
let batchKeys = [key];
|
|
1377
|
+
if (batch && lastKey) {
|
|
1378
|
+
const lastIdx = allKeys.indexOf(lastKey);
|
|
1379
|
+
const cntIdx = allKeys.indexOf(key);
|
|
1380
|
+
const [start, end] = lastIdx < cntIdx ? [lastIdx, cntIdx] : [cntIdx, lastIdx];
|
|
1381
|
+
batchKeys = allKeys.slice(start, end + 1);
|
|
1382
|
+
}
|
|
1383
|
+
if (prevChecked) {
|
|
1384
|
+
onChange(pipeline.arrayUtils.diff(value, batchKeys), key, batchKeys, 'uncheck');
|
|
1385
|
+
}
|
|
1386
|
+
else {
|
|
1387
|
+
onChange(pipeline.arrayUtils.merge(value, batchKeys), key, batchKeys, 'check');
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
};
|
|
1385
1391
|
}
|
|
1386
1392
|
|
|
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
|
-
};
|
|
1393
|
+
const rowDetailSymbol = Symbol('row-detail');
|
|
1394
|
+
const fallbackRenderDetail = () => (React__default["default"].createElement("div", { style: { margin: '8px 24px' } },
|
|
1395
|
+
React__default["default"].createElement("b", { style: { color: 'indianred' } },
|
|
1396
|
+
"\u8BBE\u7F6E ",
|
|
1397
|
+
React__default["default"].createElement("code", null, "rowDetail.renderDetail"),
|
|
1398
|
+
" \u6765\u81EA\u5B9A\u4E49\u8BE6\u60C5\u5185\u5BB9")));
|
|
1399
|
+
function rowDetail(opts = {}) {
|
|
1400
|
+
return function rowDetailStep(pipeline$1) {
|
|
1401
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1402
|
+
const stateKey = 'rowDetail';
|
|
1403
|
+
const primaryKey = pipeline$1.ensurePrimaryKey('rowDetail');
|
|
1404
|
+
if (typeof primaryKey !== 'string') {
|
|
1405
|
+
throw new Error('rowDetail 仅支持字符串作为 primaryKey');
|
|
1406
|
+
}
|
|
1407
|
+
const rowDetailMetaKey = (_a = opts.rowDetailMetaKey) !== null && _a !== void 0 ? _a : rowDetailSymbol;
|
|
1408
|
+
const indents = pipeline$1.ctx.indents;
|
|
1409
|
+
const textOffset = indents.iconIndent + indents.iconWidth + indents.iconGap;
|
|
1410
|
+
const clickArea = (_b = opts.clickArea) !== null && _b !== void 0 ? _b : 'cell';
|
|
1411
|
+
const getDetailKey = (_c = opts.getDetailKey) !== null && _c !== void 0 ? _c : ((row) => row[primaryKey] + '_detail');
|
|
1412
|
+
const renderDetail = (_d = opts.renderDetail) !== null && _d !== void 0 ? _d : fallbackRenderDetail;
|
|
1413
|
+
const hasDetail = (_e = opts.hasDetail) !== null && _e !== void 0 ? _e : pipeline.always(true);
|
|
1414
|
+
const openKeys = (_h = (_g = (_f = opts.openKeys) !== null && _f !== void 0 ? _f : pipeline$1.getStateAtKey(stateKey)) !== null && _g !== void 0 ? _g : (opts.defaultOpenAll
|
|
1415
|
+
? pipeline$1
|
|
1416
|
+
.getDataSource()
|
|
1417
|
+
.filter(hasDetail)
|
|
1418
|
+
.map((row) => row[primaryKey])
|
|
1419
|
+
: opts.defaultOpenKeys)) !== null && _h !== void 0 ? _h : [];
|
|
1420
|
+
const onChangeOpenKeys = (nextKeys, key, action) => {
|
|
1421
|
+
var _a;
|
|
1422
|
+
(_a = opts.onChangeOpenKeys) === null || _a === void 0 ? void 0 : _a.call(opts, nextKeys, key, action);
|
|
1423
|
+
pipeline$1.setStateAtKey(stateKey, nextKeys, { key, action });
|
|
1424
|
+
};
|
|
1425
|
+
const openKeySet = new Set(openKeys);
|
|
1426
|
+
const toggle = (rowKey) => {
|
|
1427
|
+
const expanded = openKeySet.has(rowKey);
|
|
1428
|
+
if (expanded) {
|
|
1429
|
+
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'collapse');
|
|
1430
|
+
}
|
|
1431
|
+
else {
|
|
1432
|
+
onChangeOpenKeys([...openKeys, rowKey], rowKey, 'expand');
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
return pipeline$1
|
|
1436
|
+
.dataSource(pipeline.flatMap(pipeline$1.getDataSource(), (row, rowIndex) => {
|
|
1437
|
+
if (openKeySet.has(row[primaryKey])) {
|
|
1438
|
+
return [row, Object.assign(Object.assign({ [rowDetailMetaKey]: true }, row), { [primaryKey]: getDetailKey(row, rowIndex) })];
|
|
1439
|
+
}
|
|
1440
|
+
else {
|
|
1441
|
+
return [row];
|
|
1442
|
+
}
|
|
1443
|
+
}))
|
|
1444
|
+
.columns(processColumns(pipeline$1.getColumns()))
|
|
1445
|
+
.appendRowPropsGetter((row) => {
|
|
1446
|
+
if (row[rowDetailMetaKey]) {
|
|
1447
|
+
return { className: 'no-hover' };
|
|
1448
|
+
}
|
|
1449
|
+
});
|
|
1450
|
+
function processColumns(columns) {
|
|
1451
|
+
if (columns.length === 0) {
|
|
1452
|
+
return columns;
|
|
1453
|
+
}
|
|
1454
|
+
const columnFlatCount = pipeline.collectNodes(columns, 'leaf-only').length;
|
|
1455
|
+
const [firstCol, ...others] = columns;
|
|
1456
|
+
const render = (value, row, rowIndex) => {
|
|
1457
|
+
if (row[rowDetailMetaKey]) {
|
|
1458
|
+
return renderDetail(row, rowIndex);
|
|
1459
|
+
}
|
|
1460
|
+
const content = pipeline.internals.safeRender(firstCol, row, rowIndex);
|
|
1461
|
+
if (!hasDetail(row, rowIndex)) {
|
|
1462
|
+
return React__default["default"].createElement(pipeline.InlineFlexCell, { style: { marginLeft: textOffset } }, content);
|
|
1463
|
+
}
|
|
1464
|
+
const rowKey = row[primaryKey];
|
|
1465
|
+
const expanded = openKeySet.has(rowKey);
|
|
1466
|
+
const onClick = (e) => {
|
|
1467
|
+
if (opts.stopClickEventPropagation) {
|
|
1468
|
+
e.stopPropagation();
|
|
1469
|
+
}
|
|
1470
|
+
toggle(rowKey);
|
|
1471
|
+
};
|
|
1472
|
+
const expandCls = expanded ? 'expanded' : 'collapsed';
|
|
1473
|
+
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 },
|
|
1474
|
+
React__default["default"].createElement(pipeline.icons.CaretRight, { style: {
|
|
1475
|
+
cursor: clickArea === 'icon' ? 'pointer' : undefined,
|
|
1476
|
+
marginLeft: indents.iconIndent,
|
|
1477
|
+
marginRight: indents.iconGap,
|
|
1478
|
+
}, className: cx__default["default"]('expansion-icon', expandCls), onClick: clickArea === 'icon' ? onClick : undefined }),
|
|
1479
|
+
content));
|
|
1480
|
+
};
|
|
1481
|
+
const getCellProps = (value, row, rowIndex) => {
|
|
1482
|
+
var _a;
|
|
1483
|
+
if (row[rowDetailMetaKey]) {
|
|
1484
|
+
return {
|
|
1485
|
+
style: Object.assign({ '--cell-padding': '0', overflow: 'hidden' }, opts.detailCellStyle),
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
const prevProps = (_a = firstCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(firstCol, value, row, rowIndex);
|
|
1489
|
+
if (!hasDetail(row, rowIndex)) {
|
|
1490
|
+
return prevProps;
|
|
1491
|
+
}
|
|
1492
|
+
const toggleProps = opts.useCustomExpandAction ? undefined : {
|
|
1493
|
+
onClick: (e) => {
|
|
1494
|
+
if (opts.stopClickEventPropagation) {
|
|
1495
|
+
e.stopPropagation();
|
|
1496
|
+
}
|
|
1497
|
+
toggle(row[primaryKey]);
|
|
1498
|
+
},
|
|
1499
|
+
style: { cursor: 'pointer' },
|
|
1500
|
+
};
|
|
1501
|
+
return pipeline.mergeCellProps(prevProps, toggleProps);
|
|
1502
|
+
};
|
|
1503
|
+
return [
|
|
1504
|
+
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) {
|
|
1505
|
+
if (row[rowDetailMetaKey]) {
|
|
1506
|
+
// detail 总是成一行
|
|
1507
|
+
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: columnFlatCount };
|
|
1508
|
+
}
|
|
1509
|
+
} }),
|
|
1510
|
+
...others,
|
|
1511
|
+
];
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1508
1514
|
}
|
|
1509
1515
|
|
|
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
|
-
};
|
|
1516
|
+
const rowPopoverSymbol = Symbol('row-popover');
|
|
1517
|
+
const fallbackRenderPopover = () => (React__default["default"].createElement("div", { style: { margin: '8px 24px' } },
|
|
1518
|
+
React__default["default"].createElement("b", { style: { color: 'indianred' } },
|
|
1519
|
+
"\u8BBE\u7F6E ",
|
|
1520
|
+
React__default["default"].createElement("code", null, "rowPopover.renderPopover"),
|
|
1521
|
+
" \u6765\u81EA\u5B9A\u4E49\u8BE6\u60C5\u5185\u5BB9")));
|
|
1522
|
+
function rowPopover(opts = {}) {
|
|
1523
|
+
return function rowPopoverStep(pipeline$1) {
|
|
1524
|
+
var _a, _b;
|
|
1525
|
+
const Popover = pipeline$1.ctx.components.Popover;
|
|
1526
|
+
if (Popover == null) {
|
|
1527
|
+
throw new Error('使用 rowPopover 之前需要设置 pipeline.ctx.components.Popover');
|
|
1528
|
+
}
|
|
1529
|
+
const stateKey = 'rowPopover';
|
|
1530
|
+
const primaryKey = pipeline$1.ensurePrimaryKey(stateKey);
|
|
1531
|
+
if (typeof primaryKey !== 'string') {
|
|
1532
|
+
throw new Error(`${stateKey} 仅支持字符串作为 primaryKey`);
|
|
1533
|
+
}
|
|
1534
|
+
const renderPopover = (_a = opts.renderPopover) !== null && _a !== void 0 ? _a : fallbackRenderPopover;
|
|
1535
|
+
const openKeys = (_b = pipeline$1.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : [];
|
|
1536
|
+
const onChangeOpenKeys = (nextKeys, key, action) => {
|
|
1537
|
+
pipeline$1.setStateAtKey(stateKey, nextKeys, { key, action });
|
|
1538
|
+
};
|
|
1539
|
+
const openKeySet = new Set(openKeys);
|
|
1540
|
+
const toggle = (rowKey, flag) => {
|
|
1541
|
+
if (!flag) {
|
|
1542
|
+
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'mouseleave');
|
|
1543
|
+
}
|
|
1544
|
+
else {
|
|
1545
|
+
onChangeOpenKeys([rowKey], rowKey, 'mouseenter');
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
return pipeline$1
|
|
1549
|
+
.dataSource(pipeline.flatMap(pipeline$1.getDataSource(), (row, rowIndex) => {
|
|
1550
|
+
if (openKeySet.has(row[primaryKey])) {
|
|
1551
|
+
return [Object.assign({ [rowPopoverSymbol]: true }, row)];
|
|
1552
|
+
}
|
|
1553
|
+
else {
|
|
1554
|
+
return [row];
|
|
1555
|
+
}
|
|
1556
|
+
}))
|
|
1557
|
+
.columns(processColumns(pipeline$1.getColumns()));
|
|
1558
|
+
function processColumns(columns) {
|
|
1559
|
+
if (columns.length === 0) {
|
|
1560
|
+
return columns;
|
|
1561
|
+
}
|
|
1562
|
+
const render = (mountCol, value, row, rowIndex) => {
|
|
1563
|
+
const content = pipeline.internals.safeRender(mountCol, row, rowIndex);
|
|
1564
|
+
if (!row[rowPopoverSymbol]) {
|
|
1565
|
+
return content;
|
|
1566
|
+
}
|
|
1567
|
+
const rowKey = row[primaryKey];
|
|
1568
|
+
const expanded = openKeySet.has(rowKey);
|
|
1569
|
+
return (React__default["default"].createElement(Popover, Object.assign({ visible: expanded }, opts.popoverProps, { content: renderPopover(row, rowIndex) }), content));
|
|
1570
|
+
};
|
|
1571
|
+
return columns.map((column, columnIndex) => {
|
|
1572
|
+
// 弹框挂载列
|
|
1573
|
+
if (opts.mountColCode ? (opts.mountColCode === column.code) : (columnIndex === 0)) {
|
|
1574
|
+
return Object.assign(Object.assign({}, column), { getCellProps(value, record, rowIndex) {
|
|
1575
|
+
const prevGetCellProps = column.getCellProps;
|
|
1576
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1577
|
+
const rowKey = record[primaryKey];
|
|
1578
|
+
return pipeline.mergeCellProps(prevCellProps, {
|
|
1579
|
+
onMouseEnter() {
|
|
1580
|
+
toggle(rowKey, true);
|
|
1581
|
+
},
|
|
1582
|
+
onMouseLeave() {
|
|
1583
|
+
toggle(rowKey, false);
|
|
1584
|
+
},
|
|
1585
|
+
});
|
|
1586
|
+
}, render: (value, record, rowIndex) => render(column, value, record, rowIndex) });
|
|
1587
|
+
}
|
|
1588
|
+
// 禁用弹框挂载列
|
|
1589
|
+
if (Array.isArray(opts.excludeColCodes) && opts.excludeColCodes.includes(column.code)) {
|
|
1590
|
+
return column;
|
|
1591
|
+
}
|
|
1592
|
+
return Object.assign(Object.assign({}, column), { getCellProps(value, record, rowIndex) {
|
|
1593
|
+
const prevGetCellProps = column.getCellProps;
|
|
1594
|
+
const prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
1595
|
+
const rowKey = record[primaryKey];
|
|
1596
|
+
return pipeline.mergeCellProps(prevCellProps, {
|
|
1597
|
+
onMouseEnter() {
|
|
1598
|
+
toggle(rowKey, true);
|
|
1599
|
+
},
|
|
1600
|
+
onMouseLeave() {
|
|
1601
|
+
toggle(rowKey, false);
|
|
1602
|
+
},
|
|
1603
|
+
});
|
|
1604
|
+
} });
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1602
1608
|
}
|
|
1603
1609
|
|
|
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,
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1610
|
+
const groupingMetaSymbol = Symbol('row-grouping-meta');
|
|
1611
|
+
function attachGroupingMeta(row) {
|
|
1612
|
+
return Object.assign({ [groupingMetaSymbol]: { expandable: !pipeline.isLeafNode(row) } }, row);
|
|
1613
|
+
}
|
|
1614
|
+
function getGroupingMeta(row) {
|
|
1615
|
+
if (row[groupingMetaSymbol] == null) {
|
|
1616
|
+
return { isGroupHeader: false, expandable: false };
|
|
1617
|
+
}
|
|
1618
|
+
return { isGroupHeader: true, expandable: row[groupingMetaSymbol].expandable };
|
|
1619
|
+
}
|
|
1620
|
+
function rowGroupingRowPropsGetter(row) {
|
|
1621
|
+
if (getGroupingMeta(row).isGroupHeader) {
|
|
1622
|
+
return { className: 'alternative' };
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
function rowGrouping(opts = {}) {
|
|
1626
|
+
return (pipeline$1) => {
|
|
1627
|
+
var _a, _b, _c;
|
|
1628
|
+
const stateKey = 'rowGrouping';
|
|
1629
|
+
const indents = pipeline$1.ctx.indents;
|
|
1630
|
+
const textOffset = indents.iconIndent + indents.iconWidth + indents.iconGap;
|
|
1631
|
+
const primaryKey = pipeline$1.ensurePrimaryKey('rowGrouping');
|
|
1632
|
+
if (typeof primaryKey !== 'string') {
|
|
1633
|
+
throw new Error('rowGrouping 仅支持字符串作为 primaryKey');
|
|
1634
|
+
}
|
|
1635
|
+
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 : [];
|
|
1636
|
+
const openKeySet = new Set(openKeys);
|
|
1637
|
+
const onChangeOpenKeys = (nextKeys, key, action) => {
|
|
1638
|
+
var _a;
|
|
1639
|
+
(_a = opts.onChangeOpenKeys) === null || _a === void 0 ? void 0 : _a.call(opts, nextKeys, key, action);
|
|
1640
|
+
pipeline$1.setStateAtKey(stateKey, nextKeys, { key, action });
|
|
1641
|
+
};
|
|
1642
|
+
return pipeline$1
|
|
1643
|
+
.mapDataSource(processDataSource)
|
|
1644
|
+
.mapColumns(processColumns)
|
|
1645
|
+
.appendRowPropsGetter(rowGroupingRowPropsGetter);
|
|
1646
|
+
function processDataSource(input) {
|
|
1647
|
+
return pipeline.flatMap(input, (row) => {
|
|
1648
|
+
let result = [attachGroupingMeta(row)];
|
|
1649
|
+
const expanded = openKeySet.has(row[primaryKey]);
|
|
1650
|
+
if (expanded) {
|
|
1651
|
+
if (Array.isArray(row.children)) {
|
|
1652
|
+
result = result.concat(row.children);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return result;
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
function processColumns(columns) {
|
|
1659
|
+
if (columns.length === 0) {
|
|
1660
|
+
return columns;
|
|
1661
|
+
}
|
|
1662
|
+
const columnFlatCount = pipeline.collectNodes(columns, 'leaf-only').length;
|
|
1663
|
+
const [firstCol, ...others] = columns;
|
|
1664
|
+
const render = (value, row, rowIndex) => {
|
|
1665
|
+
var _a, _b;
|
|
1666
|
+
const content = pipeline.internals.safeRender(firstCol, row, rowIndex);
|
|
1667
|
+
const meta = getGroupingMeta(row);
|
|
1668
|
+
if (!meta.isGroupHeader || !meta.expandable) {
|
|
1669
|
+
const marginLeft = textOffset + (meta.isGroupHeader ? 0 : indents.indentSize);
|
|
1670
|
+
return (React__default["default"].createElement(pipeline.InlineFlexCell, { style: { marginLeft } }, meta.isGroupHeader ? (_a = row.groupTitle) !== null && _a !== void 0 ? _a : content : content));
|
|
1671
|
+
}
|
|
1672
|
+
const expanded = openKeySet.has(row[primaryKey]);
|
|
1673
|
+
const expandCls = expanded ? 'expanded' : 'collapsed';
|
|
1674
|
+
return (React__default["default"].createElement(pipeline.ExpansionCell, { className: cx__default["default"]('expansion-cell', expandCls) },
|
|
1675
|
+
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));
|
|
1676
|
+
};
|
|
1677
|
+
const getCellProps = (value, row, rowIndex) => {
|
|
1678
|
+
var _a;
|
|
1679
|
+
const meta = getGroupingMeta(row);
|
|
1680
|
+
if (!meta.isGroupHeader) {
|
|
1681
|
+
return;
|
|
1682
|
+
}
|
|
1683
|
+
const { expandable } = meta;
|
|
1684
|
+
const rowKey = row[primaryKey];
|
|
1685
|
+
const expanded = openKeySet.has(rowKey);
|
|
1686
|
+
let onClick;
|
|
1687
|
+
if (expandable) {
|
|
1688
|
+
onClick = (e) => {
|
|
1689
|
+
if (opts.stopClickEventPropagation) {
|
|
1690
|
+
e.stopPropagation();
|
|
1691
|
+
}
|
|
1692
|
+
if (expanded) {
|
|
1693
|
+
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'collapse');
|
|
1694
|
+
}
|
|
1695
|
+
else {
|
|
1696
|
+
onChangeOpenKeys([...openKeys, rowKey], rowKey, 'expand');
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
const prevProps = (_a = firstCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(firstCol, value, row, rowIndex);
|
|
1701
|
+
return pipeline.mergeCellProps(prevProps, {
|
|
1702
|
+
onClick,
|
|
1703
|
+
style: { cursor: expandable ? 'pointer' : undefined },
|
|
1704
|
+
});
|
|
1705
|
+
};
|
|
1706
|
+
return [
|
|
1707
|
+
Object.assign(Object.assign({}, firstCol), { title: (React__default["default"].createElement("div", { style: { display: 'inline-block', marginLeft: textOffset } }, pipeline.internals.safeRenderHeader(firstCol))), render,
|
|
1708
|
+
getCellProps,
|
|
1709
|
+
getSpanRect(value, row, rowIndex) {
|
|
1710
|
+
if (getGroupingMeta(row).isGroupHeader) {
|
|
1711
|
+
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: columnFlatCount };
|
|
1712
|
+
}
|
|
1713
|
+
} }),
|
|
1714
|
+
...others,
|
|
1715
|
+
];
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1711
1718
|
}
|
|
1712
1719
|
|
|
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
|
-
};
|
|
1720
|
+
function getFirstDefinedValue(...values) {
|
|
1721
|
+
for (let i = 0; i < values.length; i++) {
|
|
1722
|
+
const v = values[i];
|
|
1723
|
+
if (v !== undefined) {
|
|
1724
|
+
return v;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
function singleSelect(opts = {}) {
|
|
1729
|
+
return function singleSelectStep(pipeline$1) {
|
|
1730
|
+
var _a, _b, _c;
|
|
1731
|
+
const Radio = pipeline$1.ctx.components.Radio;
|
|
1732
|
+
if (Radio == null) {
|
|
1733
|
+
throw new Error('使用 singleSelect 之前需要通过 pipeline context 设置 components.Radio');
|
|
1734
|
+
}
|
|
1735
|
+
const stateKey = 'singleSelect';
|
|
1736
|
+
const clickArea = (_a = opts.clickArea) !== null && _a !== void 0 ? _a : 'radio';
|
|
1737
|
+
const isDisabled = (_b = opts.isDisabled) !== null && _b !== void 0 ? _b : pipeline.always(false);
|
|
1738
|
+
const primaryKey = pipeline$1.ensurePrimaryKey('singleSelect');
|
|
1739
|
+
const value = getFirstDefinedValue(opts.value, pipeline$1.getStateAtKey(stateKey), opts.defaultValue);
|
|
1740
|
+
const onChange = (rowKey) => {
|
|
1741
|
+
var _a;
|
|
1742
|
+
(_a = opts.onChange) === null || _a === void 0 ? void 0 : _a.call(opts, rowKey);
|
|
1743
|
+
pipeline$1.setStateAtKey(stateKey, rowKey);
|
|
1744
|
+
};
|
|
1745
|
+
const radioColumn = Object.assign(Object.assign({ name: '', width: 50, align: 'center' }, opts.radioColumn), { getCellProps(value, row, rowIndex) {
|
|
1746
|
+
if (clickArea === 'cell') {
|
|
1747
|
+
const rowKey = pipeline.internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1748
|
+
const disabled = isDisabled(row, rowIndex);
|
|
1749
|
+
return {
|
|
1750
|
+
style: { cursor: disabled ? 'not-allowed' : 'pointer' },
|
|
1751
|
+
onClick: disabled
|
|
1752
|
+
? undefined
|
|
1753
|
+
: (e) => {
|
|
1754
|
+
if (opts.stopClickEventPropagation) {
|
|
1755
|
+
e.stopPropagation();
|
|
1756
|
+
}
|
|
1757
|
+
onChange(rowKey);
|
|
1758
|
+
},
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
}, render: (_, row, rowIndex) => {
|
|
1762
|
+
const rowKey = pipeline.internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1763
|
+
return (React__default["default"].createElement(Radio, { checked: value === rowKey, disabled: isDisabled(row, rowIndex), onChange: clickArea === 'radio'
|
|
1764
|
+
? (arg1, arg2) => {
|
|
1765
|
+
var _a;
|
|
1766
|
+
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;
|
|
1767
|
+
if (nativeEvent && opts.stopClickEventPropagation) {
|
|
1768
|
+
nativeEvent.stopPropagation();
|
|
1769
|
+
}
|
|
1770
|
+
onChange(rowKey);
|
|
1771
|
+
}
|
|
1772
|
+
: undefined }));
|
|
1773
|
+
} });
|
|
1774
|
+
const nextColumns = pipeline$1.getColumns().slice();
|
|
1775
|
+
const radioPlacement = (_c = opts.radioPlacement) !== null && _c !== void 0 ? _c : 'start';
|
|
1776
|
+
if (radioPlacement === 'start') {
|
|
1777
|
+
nextColumns.unshift(radioColumn);
|
|
1778
|
+
}
|
|
1779
|
+
else {
|
|
1780
|
+
nextColumns.push(radioColumn);
|
|
1781
|
+
}
|
|
1782
|
+
pipeline$1.columns(nextColumns);
|
|
1783
|
+
pipeline$1.appendRowPropsGetter((row, rowIndex) => {
|
|
1784
|
+
const rowKey = pipeline.internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
1785
|
+
let style = {};
|
|
1786
|
+
let className;
|
|
1787
|
+
let onClick;
|
|
1788
|
+
if (opts.highlightRowWhenSelected) {
|
|
1789
|
+
if (value === rowKey) {
|
|
1790
|
+
className = 'highlight';
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
if (clickArea === 'row' && !isDisabled(row, rowIndex)) {
|
|
1794
|
+
style.cursor = 'pointer';
|
|
1795
|
+
onClick = (e) => {
|
|
1796
|
+
if (opts.stopClickEventPropagation) {
|
|
1797
|
+
e.stopPropagation();
|
|
1798
|
+
}
|
|
1799
|
+
onChange(rowKey);
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1802
|
+
return { className, style, onClick };
|
|
1803
|
+
});
|
|
1804
|
+
return pipeline$1;
|
|
1805
|
+
};
|
|
1799
1806
|
}
|
|
1800
1807
|
|
|
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
|
-
}
|
|
1808
|
+
function SortIcon({ size = 32, style, className, order, onClick }) {
|
|
1809
|
+
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 },
|
|
1810
|
+
React__default["default"].createElement("path", { fill: order === 'asc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, 4)", d: "M8 8L16 0 24 8z" }),
|
|
1811
|
+
React__default["default"].createElement("path", { fill: order === 'desc' ? '#23A3FF' : '#bfbfbf', transform: "translate(0, -4)", d: "M24 24L16 32 8 24z " })));
|
|
1812
|
+
}
|
|
1813
|
+
function DefaultSortHeaderCell({ children, column, onToggle, sortOrder, sortIndex, sortOptions, clickArea, }) {
|
|
1814
|
+
// 通过 justify-content 来与 col.align 保持对齐方向一致
|
|
1815
|
+
const justifyContent = column.align === 'right' ? 'flex-end' : column.align === 'center' ? 'center' : 'flex-start';
|
|
1816
|
+
return (React__default["default"].createElement(TableHeaderCell, { onClick: clickArea === 'content' ? onToggle : undefined, style: {
|
|
1817
|
+
justifyContent,
|
|
1818
|
+
cursor: clickArea === 'content' ? 'pointer' : undefined,
|
|
1819
|
+
} },
|
|
1820
|
+
children,
|
|
1821
|
+
React__default["default"].createElement(SortIcon, { onClick: clickArea === 'icon' ? onToggle : undefined, style: {
|
|
1822
|
+
userSelect: 'none',
|
|
1823
|
+
marginLeft: 2,
|
|
1824
|
+
flexShrink: 0,
|
|
1825
|
+
cursor: clickArea === 'icon' ? 'pointer' : undefined,
|
|
1826
|
+
}, size: 16, order: sortOrder }),
|
|
1827
|
+
sortOptions.mode === 'multiple' && sortIndex != -1 && (React__default["default"].createElement("div", { style: {
|
|
1828
|
+
userSelect: 'none',
|
|
1829
|
+
marginLeft: 2,
|
|
1830
|
+
color: '#666',
|
|
1831
|
+
flex: '0 0 auto',
|
|
1832
|
+
fontSize: 10,
|
|
1833
|
+
fontFamily: 'monospace',
|
|
1834
|
+
} }, sortIndex + 1))));
|
|
1835
|
+
}
|
|
1836
|
+
function hasAnySortableColumns(cols) {
|
|
1837
|
+
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)); });
|
|
1838
|
+
}
|
|
1832
1839
|
const TableHeaderCell = styled__default["default"].div `
|
|
1833
1840
|
display: flex;
|
|
1834
1841
|
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
|
-
};
|
|
1842
|
+
`;
|
|
1843
|
+
const stateKey = 'sort';
|
|
1844
|
+
function sort(opts = {}) {
|
|
1845
|
+
return function sortStep(pipeline$1) {
|
|
1846
|
+
var _a, _b, _c;
|
|
1847
|
+
const { orders = ['desc', 'asc', 'none'], mode = 'multiple', SortHeaderCell = DefaultSortHeaderCell, keepDataSource, highlightColumnWhenActive, stopClickEventPropagation, clickArea = 'content', } = opts;
|
|
1848
|
+
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 : [];
|
|
1849
|
+
const activeSorts = inputSorts.filter((s) => s.order !== 'none');
|
|
1850
|
+
// 单字段排序的情况下 sorts 中只有第一个排序字段才会生效
|
|
1851
|
+
const sorts = mode === 'multiple' ? activeSorts : activeSorts.slice(0, 1);
|
|
1852
|
+
const onChangeSortsInMultipleMode = (nextSorts) => {
|
|
1853
|
+
var _a;
|
|
1854
|
+
(_a = opts.onChangeSorts) === null || _a === void 0 ? void 0 : _a.call(opts, nextSorts);
|
|
1855
|
+
pipeline$1.setStateAtKey(stateKey, nextSorts);
|
|
1856
|
+
};
|
|
1857
|
+
const onChangeSorts = mode === 'multiple'
|
|
1858
|
+
? onChangeSortsInMultipleMode
|
|
1859
|
+
: (nextSorts) => {
|
|
1860
|
+
// 单字段排序的情况下,nextSorts 中只有最后一个排序字段才会生效
|
|
1861
|
+
const len = nextSorts.length;
|
|
1862
|
+
onChangeSortsInMultipleMode(nextSorts.slice(len - 1));
|
|
1863
|
+
};
|
|
1864
|
+
const sortOptions = {
|
|
1865
|
+
sorts,
|
|
1866
|
+
onChangeSorts,
|
|
1867
|
+
orders,
|
|
1868
|
+
mode,
|
|
1869
|
+
keepDataSource,
|
|
1870
|
+
highlightColumnWhenActive,
|
|
1871
|
+
stopClickEventPropagation,
|
|
1872
|
+
clickArea,
|
|
1873
|
+
};
|
|
1874
|
+
const sortMap = new Map(sorts.map((sort, index) => [sort.code, Object.assign({ index }, sort)]));
|
|
1875
|
+
const dataSource = pipeline$1.getDataSource();
|
|
1876
|
+
const columns = pipeline$1.getColumns();
|
|
1877
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1878
|
+
if (!hasAnySortableColumns(columns)) {
|
|
1879
|
+
console.warn('[srp-table] commonTransform.sort 缺少可排序的列,请通过 column.features.sortable 来指定哪些列可排序', columns);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
pipeline$1.dataSource(processDataSource(dataSource));
|
|
1883
|
+
pipeline$1.columns(processColumns(columns));
|
|
1884
|
+
return pipeline$1;
|
|
1885
|
+
function processDataSource(dataSource) {
|
|
1886
|
+
if (keepDataSource) {
|
|
1887
|
+
return dataSource;
|
|
1888
|
+
}
|
|
1889
|
+
const sortColumnsMap = new Map(pipeline.collectNodes(columns, 'leaf-only')
|
|
1890
|
+
.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; })
|
|
1891
|
+
.map((col) => [col.code, col]));
|
|
1892
|
+
return layeredSort(dataSource, (x, y) => {
|
|
1893
|
+
for (const { code, order } of sorts) {
|
|
1894
|
+
const column = sortColumnsMap.get(code);
|
|
1895
|
+
// 如果 code 对应的 column 不可排序,我们跳过该 code
|
|
1896
|
+
if (column == null) {
|
|
1897
|
+
continue;
|
|
1898
|
+
}
|
|
1899
|
+
const sortable = column.features.sortable;
|
|
1900
|
+
const compareFn = typeof sortable === 'function' ? sortable : smartCompare;
|
|
1901
|
+
const xValue = pipeline.internals.safeGetValue(column, x, -1);
|
|
1902
|
+
const yValue = pipeline.internals.safeGetValue(column, y, -1);
|
|
1903
|
+
const cmp = compareFn(xValue, yValue, x, y);
|
|
1904
|
+
if (cmp !== 0) {
|
|
1905
|
+
return cmp * (order === 'asc' ? 1 : -1);
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
return 0;
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
// 在「升序 - 降序 - 不排序」之间不断切换
|
|
1912
|
+
function toggle(code) {
|
|
1913
|
+
const sort = sortMap.get(code);
|
|
1914
|
+
if (sort == null) {
|
|
1915
|
+
onChangeSorts(sorts.concat([{ code, order: orders[0] }]));
|
|
1916
|
+
}
|
|
1917
|
+
else {
|
|
1918
|
+
const index = sorts.findIndex((s) => s.code === code);
|
|
1919
|
+
const nextSorts = sorts.slice(0, index + 1);
|
|
1920
|
+
const nextOrder = getNextOrder(sort.order);
|
|
1921
|
+
if (nextOrder === 'none') {
|
|
1922
|
+
nextSorts.pop();
|
|
1923
|
+
}
|
|
1924
|
+
else {
|
|
1925
|
+
nextSorts[index] = Object.assign(Object.assign({}, nextSorts[index]), { order: nextOrder });
|
|
1926
|
+
}
|
|
1927
|
+
onChangeSorts(nextSorts);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
function processColumns(columns) {
|
|
1931
|
+
return columns.map(dfs);
|
|
1932
|
+
function dfs(col) {
|
|
1933
|
+
var _a;
|
|
1934
|
+
const result = Object.assign({}, col);
|
|
1935
|
+
const sortable = col.code && (((_a = col.features) === null || _a === void 0 ? void 0 : _a.sortable) || sortMap.has(col.code));
|
|
1936
|
+
const active = sortable && sortMap.has(col.code);
|
|
1937
|
+
if (sortable) {
|
|
1938
|
+
let sortIndex = -1;
|
|
1939
|
+
let sortOrder = 'none';
|
|
1940
|
+
if (active) {
|
|
1941
|
+
const { order, index } = sortMap.get(col.code);
|
|
1942
|
+
sortOrder = order;
|
|
1943
|
+
sortIndex = index;
|
|
1944
|
+
if (highlightColumnWhenActive) {
|
|
1945
|
+
result.headerCellProps = pipeline.mergeCellProps(col.headerCellProps, {
|
|
1946
|
+
style: { background: 'var(--header-highlight-bgcolor)' },
|
|
1947
|
+
});
|
|
1948
|
+
result.getCellProps = (value, row, rowIndex) => {
|
|
1949
|
+
const prevCellProps = pipeline.internals.safeGetCellProps(col, row, rowIndex);
|
|
1950
|
+
return pipeline.mergeCellProps(prevCellProps, {
|
|
1951
|
+
style: { background: 'var(--highlight-bgcolor)' },
|
|
1952
|
+
});
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
result.title = (React__default["default"].createElement(SortHeaderCell, { clickArea: clickArea, onToggle: (e) => {
|
|
1957
|
+
if (stopClickEventPropagation) {
|
|
1958
|
+
e.stopPropagation();
|
|
1959
|
+
}
|
|
1960
|
+
toggle(col.code);
|
|
1961
|
+
}, sortOrder: sortOrder, column: col, sortIndex: sortIndex, sortOptions: sortOptions }, pipeline.internals.safeRenderHeader(col)));
|
|
1962
|
+
}
|
|
1963
|
+
if (!pipeline.isLeafNode(col)) {
|
|
1964
|
+
result.children = col.children.map(dfs);
|
|
1965
|
+
}
|
|
1966
|
+
return result;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
function getNextOrder(order) {
|
|
1970
|
+
const idx = orders.indexOf(order);
|
|
1971
|
+
return orders[idx === orders.length - 1 ? 0 : idx + 1];
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1967
1974
|
}
|
|
1968
1975
|
|
|
1969
1976
|
const HeaderCellWithTips = styled__default["default"].div `
|
|
@@ -1978,523 +1985,525 @@ const HeaderCellWithTips = styled__default["default"].div `
|
|
|
1978
1985
|
display: flex;
|
|
1979
1986
|
fill: currentColor;
|
|
1980
1987
|
}
|
|
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
|
-
};
|
|
1988
|
+
`;
|
|
1989
|
+
function tips() {
|
|
1990
|
+
return function tipsSteap(pipeline$1) {
|
|
1991
|
+
const Balloon = pipeline$1.ctx.components.Balloon;
|
|
1992
|
+
const Tooltip = pipeline$1.ctx.components.Tooltip;
|
|
1993
|
+
if (Balloon == null && Tooltip == null) {
|
|
1994
|
+
throw new Error('使用 tips 之前需要通过 pipeline context 设置 components.Balloon / components.Tooltip');
|
|
1995
|
+
}
|
|
1996
|
+
return pipeline$1.mapColumns(makeRecursiveMapper((col) => {
|
|
1997
|
+
var _a;
|
|
1998
|
+
if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.tips)) {
|
|
1999
|
+
return col;
|
|
2000
|
+
}
|
|
2001
|
+
const justifyContent = col.align === 'right' ? 'flex-end' : col.align === 'center' ? 'center' : 'flex-start';
|
|
2002
|
+
return Object.assign(Object.assign({}, col), { title: (React__default["default"].createElement(HeaderCellWithTips, { style: { justifyContent } },
|
|
2003
|
+
pipeline.internals.safeRenderHeader(col),
|
|
2004
|
+
Balloon ? (
|
|
2005
|
+
// fusion/hippo
|
|
2006
|
+
React__default["default"].createElement(Balloon, { closable: false, trigger: React__default["default"].createElement("div", { className: "tip-icon-wrapper" },
|
|
2007
|
+
React__default["default"].createElement(pipeline.icons.Info, { className: "tip-icon" })) }, col.features.tips)) : (
|
|
2008
|
+
// antd
|
|
2009
|
+
React__default["default"].createElement(Tooltip, { title: col.features.tips },
|
|
2010
|
+
React__default["default"].createElement("div", { className: "tip-icon-wrapper" },
|
|
2011
|
+
React__default["default"].createElement(pipeline.icons.Info, { className: "tip-icon" })))))) });
|
|
2012
|
+
}));
|
|
2013
|
+
};
|
|
2007
2014
|
}
|
|
2008
2015
|
|
|
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
|
-
}
|
|
2016
|
+
class Wrapper$1 {
|
|
2017
|
+
constructor(input) {
|
|
2018
|
+
Object.assign(this, input);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
class StrictTreeDataHelper {
|
|
2022
|
+
constructor(opts) {
|
|
2023
|
+
this.opts = opts;
|
|
2024
|
+
this.valueSet = new Set(opts.value);
|
|
2025
|
+
this.initWrapperTree();
|
|
2026
|
+
}
|
|
2027
|
+
initWrapperTree() {
|
|
2028
|
+
const { getNodeValue } = this.opts;
|
|
2029
|
+
this.rootWrapper = new Wrapper$1({ root: true, children: [] });
|
|
2030
|
+
this.wrapperMap = new Map();
|
|
2031
|
+
const dfs = (parentWrapper, nodes) => {
|
|
2032
|
+
for (const node of nodes) {
|
|
2033
|
+
const wrapper = new Wrapper$1({
|
|
2034
|
+
parent: parentWrapper,
|
|
2035
|
+
node,
|
|
2036
|
+
checked: this.valueSet.has(getNodeValue(node)),
|
|
2037
|
+
});
|
|
2038
|
+
this.wrapperMap.set(getNodeValue(node), wrapper);
|
|
2039
|
+
parentWrapper.children.push(wrapper);
|
|
2040
|
+
if (!pipeline.isLeafNode(node)) {
|
|
2041
|
+
wrapper.children = [];
|
|
2042
|
+
dfs(wrapper, node.children);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
dfs(this.rootWrapper, this.opts.tree);
|
|
2047
|
+
}
|
|
2048
|
+
get value() {
|
|
2049
|
+
return this.opts.value;
|
|
2050
|
+
}
|
|
2051
|
+
isIndeterminate(nodeValue) {
|
|
2052
|
+
return false;
|
|
2053
|
+
}
|
|
2054
|
+
isChecked(nodeValue) {
|
|
2055
|
+
return this.valueSet.has(nodeValue);
|
|
2056
|
+
}
|
|
2057
|
+
getValueAfterCheck(nodeValue) {
|
|
2058
|
+
if (!this.isChecked(nodeValue)) {
|
|
2059
|
+
return pipeline.arrayUtils.merge(this.value, [nodeValue]);
|
|
2060
|
+
}
|
|
2061
|
+
return this.value;
|
|
2062
|
+
}
|
|
2063
|
+
getValueAfterUncheck(nodeValue) {
|
|
2064
|
+
if (this.isChecked(nodeValue)) {
|
|
2065
|
+
return pipeline.arrayUtils.diff(this.value, [nodeValue]);
|
|
2066
|
+
}
|
|
2067
|
+
return this.value;
|
|
2068
|
+
}
|
|
2069
|
+
getValueAfterToggle(nodeValue) {
|
|
2070
|
+
if (this.isChecked(nodeValue)) {
|
|
2071
|
+
return this.getValueAfterUncheck(nodeValue);
|
|
2072
|
+
}
|
|
2073
|
+
else {
|
|
2074
|
+
return this.getValueAfterCheck(nodeValue);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
getNode(nodeValue) {
|
|
2078
|
+
var _a;
|
|
2079
|
+
return (_a = this.wrapperMap.get(nodeValue)) === null || _a === void 0 ? void 0 : _a.node;
|
|
2080
|
+
}
|
|
2081
|
+
getCleanValue() {
|
|
2082
|
+
return this.value;
|
|
2083
|
+
}
|
|
2077
2084
|
}
|
|
2078
2085
|
|
|
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
|
-
}
|
|
2086
|
+
class Wrapper {
|
|
2087
|
+
constructor(input) {
|
|
2088
|
+
Object.assign(this, input);
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
class TreeDataHelper {
|
|
2092
|
+
constructor(opts) {
|
|
2093
|
+
this.isDetached = (node) => {
|
|
2094
|
+
var _a, _b, _c;
|
|
2095
|
+
return (_c = (_b = (_a = this.opts).isDetached) === null || _b === void 0 ? void 0 : _b.call(_a, node)) !== null && _c !== void 0 ? _c : false;
|
|
2096
|
+
};
|
|
2097
|
+
this.opts = opts;
|
|
2098
|
+
this.valueSet = new Set(opts.value);
|
|
2099
|
+
this.initWrapperTree();
|
|
2100
|
+
}
|
|
2101
|
+
get value() {
|
|
2102
|
+
return this.opts.value;
|
|
2103
|
+
}
|
|
2104
|
+
initWrapperTree() {
|
|
2105
|
+
const valueSet = new Set(this.value);
|
|
2106
|
+
this.rootWrapper = new Wrapper({ root: true, children: [] });
|
|
2107
|
+
this.wrapperMap = new Map();
|
|
2108
|
+
const getNodeValue = this.opts.getNodeValue;
|
|
2109
|
+
const { isDetached, wrapperMap } = this;
|
|
2110
|
+
dfs(this.rootWrapper, this.opts.tree, false);
|
|
2111
|
+
function dfs(parentWrapper, nodes, inheritParentChecked) {
|
|
2112
|
+
// allChildrenChecked 先默认设置为 true
|
|
2113
|
+
// dfs 过程中可能会更新 allChildrenChecked
|
|
2114
|
+
parentWrapper.allChildrenChecked = true;
|
|
2115
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2116
|
+
if (nodes.every(isDetached)) {
|
|
2117
|
+
console.warn('TreeDataHelper 检测到部分节点的下所有子节点均为 detached 状态,这将导致该节点变为「无效节点」', parentWrapper.node);
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
for (const node of nodes) {
|
|
2121
|
+
const detached = isDetached(node);
|
|
2122
|
+
const exactChecked = valueSet.has(getNodeValue(node));
|
|
2123
|
+
if (exactChecked && !detached) {
|
|
2124
|
+
parentWrapper.anyDescendentsChecked = true;
|
|
2125
|
+
}
|
|
2126
|
+
const parentChecked = !detached && inheritParentChecked;
|
|
2127
|
+
const checked = exactChecked || parentChecked;
|
|
2128
|
+
const wrapper = new Wrapper({
|
|
2129
|
+
parent: parentWrapper,
|
|
2130
|
+
node,
|
|
2131
|
+
checked,
|
|
2132
|
+
exactChecked,
|
|
2133
|
+
parentChecked,
|
|
2134
|
+
anyDescendentsChecked: checked,
|
|
2135
|
+
detached,
|
|
2136
|
+
});
|
|
2137
|
+
wrapperMap.set(getNodeValue(node), wrapper);
|
|
2138
|
+
parentWrapper.children.push(wrapper);
|
|
2139
|
+
if (!pipeline.isLeafNode(node)) {
|
|
2140
|
+
wrapper.children = [];
|
|
2141
|
+
dfs(wrapper, node.children, checked);
|
|
2142
|
+
if (wrapper.anyDescendentsChecked && !detached) {
|
|
2143
|
+
parentWrapper.anyDescendentsChecked = true;
|
|
2144
|
+
}
|
|
2145
|
+
if (wrapper.allChildrenChecked) {
|
|
2146
|
+
wrapper.checked = true;
|
|
2147
|
+
// 当一个节点因为「子节点被全选」而变为 checked 时,我们需要更新子节点的 parentChecked 字段
|
|
2148
|
+
for (const child of wrapper.children) {
|
|
2149
|
+
if (!child.detached) {
|
|
2150
|
+
child.parentChecked = true;
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
if (!wrapper.checked && !detached) {
|
|
2156
|
+
parentWrapper.allChildrenChecked = false;
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
isIndeterminate(nodeValue) {
|
|
2162
|
+
const wrapper = this.wrapperMap.get(nodeValue);
|
|
2163
|
+
return !wrapper.checked && wrapper.anyDescendentsChecked;
|
|
2164
|
+
}
|
|
2165
|
+
isChecked(nodeValue) {
|
|
2166
|
+
const wrapper = this.wrapperMap.get(nodeValue);
|
|
2167
|
+
return wrapper.checked;
|
|
2168
|
+
}
|
|
2169
|
+
getValueAfterCheck(nodeValue) {
|
|
2170
|
+
if (this.isChecked(nodeValue)) {
|
|
2171
|
+
return this.getCleanValue();
|
|
2172
|
+
}
|
|
2173
|
+
const nextValue = pipeline.arrayUtils.merge(this.value, [nodeValue]);
|
|
2174
|
+
return new TreeDataHelper(Object.assign(Object.assign({}, this.opts), { value: nextValue })).getCleanValue();
|
|
2175
|
+
}
|
|
2176
|
+
getValueAfterUncheck(nodeValue) {
|
|
2177
|
+
if (!this.isChecked(nodeValue)) {
|
|
2178
|
+
return this.getCleanValue();
|
|
2179
|
+
}
|
|
2180
|
+
const wrapper = this.wrapperMap.get(nodeValue);
|
|
2181
|
+
const { getNodeValue } = this.opts;
|
|
2182
|
+
const appendArray = getAppendArray(wrapper);
|
|
2183
|
+
const removeSet = getRemoveSet(wrapper);
|
|
2184
|
+
const nextValue = pipeline.arrayUtils.diff(this.value.concat(appendArray), removeSet);
|
|
2185
|
+
return new TreeDataHelper(Object.assign(Object.assign({}, this.opts), { value: nextValue })).getCleanValue();
|
|
2186
|
+
function getAppendArray(startWrapper) {
|
|
2187
|
+
let result = [];
|
|
2188
|
+
let current = startWrapper;
|
|
2189
|
+
while (current.parentChecked && !current.detached) {
|
|
2190
|
+
for (const sibling of current.parent.children) {
|
|
2191
|
+
if (sibling === current || sibling.exactChecked || sibling.detached) {
|
|
2192
|
+
continue;
|
|
2193
|
+
}
|
|
2194
|
+
result.push(getNodeValue(sibling.node));
|
|
2195
|
+
}
|
|
2196
|
+
current = current.parent;
|
|
2197
|
+
}
|
|
2198
|
+
return result;
|
|
2199
|
+
}
|
|
2200
|
+
function getRemoveSet(startWrapper) {
|
|
2201
|
+
const result = new Set();
|
|
2202
|
+
let wrapper = startWrapper;
|
|
2203
|
+
// 不断向上收集选中的父节点
|
|
2204
|
+
while (true) {
|
|
2205
|
+
result.add(getNodeValue(wrapper.node));
|
|
2206
|
+
if (wrapper.detached || !wrapper.parentChecked) {
|
|
2207
|
+
break;
|
|
2208
|
+
}
|
|
2209
|
+
wrapper = wrapper.parent;
|
|
2210
|
+
}
|
|
2211
|
+
function dfs(wrappers) {
|
|
2212
|
+
if (wrappers == null) {
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
for (const wrapper of wrappers) {
|
|
2216
|
+
if (wrapper.detached || !wrapper.checked) {
|
|
2217
|
+
continue;
|
|
2218
|
+
}
|
|
2219
|
+
result.add(getNodeValue(wrapper.node));
|
|
2220
|
+
if (!pipeline.isLeafNode(wrapper) && wrapper.anyDescendentsChecked) {
|
|
2221
|
+
dfs(wrapper.children);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
// 收集所有的子孙节点
|
|
2226
|
+
dfs(startWrapper.children);
|
|
2227
|
+
return result;
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
getValueAfterToggle(nodeValue) {
|
|
2231
|
+
if (this.isChecked(nodeValue)) {
|
|
2232
|
+
return this.getValueAfterUncheck(nodeValue);
|
|
2233
|
+
}
|
|
2234
|
+
else {
|
|
2235
|
+
return this.getValueAfterCheck(nodeValue);
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
getNode(nodeValue) {
|
|
2239
|
+
var _a;
|
|
2240
|
+
return (_a = this.wrapperMap.get(nodeValue)) === null || _a === void 0 ? void 0 : _a.node;
|
|
2241
|
+
}
|
|
2242
|
+
getCleanValue() {
|
|
2243
|
+
const { checkedStrategy, getNodeValue } = this.opts;
|
|
2244
|
+
const result = this.value.filter((nodeValue) => {
|
|
2245
|
+
return !this.wrapperMap.has(nodeValue);
|
|
2246
|
+
});
|
|
2247
|
+
dfs(this.rootWrapper.children);
|
|
2248
|
+
return result;
|
|
2249
|
+
function dfs(wrappers) {
|
|
2250
|
+
for (const wrapper of wrappers) {
|
|
2251
|
+
if (wrapper.checked) {
|
|
2252
|
+
if (checkedStrategy === 'all') {
|
|
2253
|
+
result.push(getNodeValue(wrapper.node));
|
|
2254
|
+
}
|
|
2255
|
+
else if (checkedStrategy === 'parent') {
|
|
2256
|
+
if (!wrapper.parentChecked) {
|
|
2257
|
+
result.push(getNodeValue(wrapper.node));
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
else {
|
|
2261
|
+
// checkedStrategy === 'child'
|
|
2262
|
+
if (pipeline.isLeafNode(wrapper)) {
|
|
2263
|
+
result.push(getNodeValue(wrapper.node));
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
if (!pipeline.isLeafNode(wrapper)) {
|
|
2268
|
+
dfs(wrapper.children);
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2266
2273
|
}
|
|
2267
2274
|
|
|
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
|
-
},
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
const
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2275
|
+
const STATE_KEY = 'treeSelect';
|
|
2276
|
+
function treeSelect(opts) {
|
|
2277
|
+
return function treeSelectStep(pipeline$1) {
|
|
2278
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2279
|
+
const Checkbox = pipeline$1.ctx.components.Checkbox;
|
|
2280
|
+
if (Checkbox == null) {
|
|
2281
|
+
throw new Error('使用 treeSelect 之前需要通过 pipeline context 设置 components.Checkbox');
|
|
2282
|
+
}
|
|
2283
|
+
const primaryKey = pipeline$1.ensurePrimaryKey('treeSelect');
|
|
2284
|
+
if (typeof primaryKey !== 'string') {
|
|
2285
|
+
throw new Error('treeSelect 仅支持字符串作为 primaryKey');
|
|
2286
|
+
}
|
|
2287
|
+
const clickArea = (_a = opts.clickArea) !== null && _a !== void 0 ? _a : 'checkbox';
|
|
2288
|
+
const isDisabled = (_b = opts.isDisabled) !== null && _b !== void 0 ? _b : pipeline.always(false);
|
|
2289
|
+
const isDetached = (_c = opts.isDetached) !== null && _c !== void 0 ? _c : pipeline.always(false);
|
|
2290
|
+
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 : [];
|
|
2291
|
+
const tree = opts.rootKey != null ? [{ [primaryKey]: opts.rootKey, children: opts.tree }] : opts.tree;
|
|
2292
|
+
const getNodeValue = (node) => node[primaryKey];
|
|
2293
|
+
const treeDataHelper = opts.checkStrictly
|
|
2294
|
+
? new StrictTreeDataHelper({ value, getNodeValue, tree })
|
|
2295
|
+
: new TreeDataHelper({
|
|
2296
|
+
value,
|
|
2297
|
+
getNodeValue,
|
|
2298
|
+
isDetached,
|
|
2299
|
+
tree,
|
|
2300
|
+
checkedStrategy: (_g = opts.checkedStrategy) !== null && _g !== void 0 ? _g : 'parent',
|
|
2301
|
+
});
|
|
2302
|
+
const onToggleKey = (key) => {
|
|
2303
|
+
var _a;
|
|
2304
|
+
const nextValue = treeDataHelper.getValueAfterToggle(key);
|
|
2305
|
+
pipeline$1.setStateAtKey(STATE_KEY, nextValue);
|
|
2306
|
+
(_a = opts.onChange) === null || _a === void 0 ? void 0 : _a.call(opts, nextValue);
|
|
2307
|
+
};
|
|
2308
|
+
const makeCheckbox = (key, root, row) => {
|
|
2309
|
+
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 }));
|
|
2310
|
+
};
|
|
2311
|
+
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) {
|
|
2312
|
+
return makeCheckbox(record[primaryKey], false, record);
|
|
2313
|
+
},
|
|
2314
|
+
getCellProps(value, row) {
|
|
2315
|
+
const rowKey = row[primaryKey];
|
|
2316
|
+
if (clickArea !== 'cell') {
|
|
2317
|
+
return;
|
|
2318
|
+
}
|
|
2319
|
+
const disabled = isDisabled(row);
|
|
2320
|
+
if (disabled) {
|
|
2321
|
+
return { style: { cursor: 'not-allowed' } };
|
|
2322
|
+
}
|
|
2323
|
+
return {
|
|
2324
|
+
style: { cursor: 'pointer' },
|
|
2325
|
+
onClick(e) {
|
|
2326
|
+
if (opts.stopClickEventPropagation) {
|
|
2327
|
+
e.stopPropagation();
|
|
2328
|
+
}
|
|
2329
|
+
onToggleKey(rowKey);
|
|
2330
|
+
},
|
|
2331
|
+
};
|
|
2332
|
+
} });
|
|
2333
|
+
const nextColumns = pipeline$1.getColumns().slice();
|
|
2334
|
+
const checkboxPlacement = (_h = opts.checkboxPlacement) !== null && _h !== void 0 ? _h : 'start';
|
|
2335
|
+
if (checkboxPlacement === 'start') {
|
|
2336
|
+
nextColumns.unshift(checkboxColumn);
|
|
2337
|
+
}
|
|
2338
|
+
else {
|
|
2339
|
+
nextColumns.push(checkboxColumn);
|
|
2340
|
+
}
|
|
2341
|
+
pipeline$1.columns(nextColumns);
|
|
2342
|
+
if (clickArea === 'row') {
|
|
2343
|
+
pipeline$1.appendRowPropsGetter((row) => {
|
|
2344
|
+
const disabled = isDisabled(row);
|
|
2345
|
+
if (!disabled) {
|
|
2346
|
+
return {
|
|
2347
|
+
style: { cursor: 'pointer' },
|
|
2348
|
+
onClick(e) {
|
|
2349
|
+
if (opts.stopClickEventPropagation) {
|
|
2350
|
+
e.stopPropagation();
|
|
2351
|
+
}
|
|
2352
|
+
onToggleKey(row[primaryKey]);
|
|
2353
|
+
},
|
|
2354
|
+
};
|
|
2355
|
+
}
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
if (opts.highlightRowWhenSelected) {
|
|
2359
|
+
pipeline$1.appendRowPropsGetter((row) => {
|
|
2360
|
+
if (treeDataHelper.isChecked(row[primaryKey])) {
|
|
2361
|
+
return { className: 'highlight' };
|
|
2362
|
+
}
|
|
2363
|
+
});
|
|
2364
|
+
}
|
|
2365
|
+
return pipeline$1;
|
|
2366
|
+
};
|
|
2359
2367
|
}
|
|
2360
2368
|
|
|
2361
2369
|
var index = /*#__PURE__*/Object.freeze({
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2370
|
+
__proto__: null,
|
|
2371
|
+
autoRowSpan: autoRowSpan,
|
|
2372
|
+
buildTree: buildTree,
|
|
2373
|
+
columnHover: columnHover,
|
|
2374
|
+
columnRangeHover: columnRangeHover,
|
|
2375
|
+
columnResize: columnResize,
|
|
2376
|
+
fillRemainingWidth: fillRemainingWidth,
|
|
2377
|
+
multiSelect: multiSelect,
|
|
2378
|
+
rowDetail: rowDetail,
|
|
2379
|
+
rowPopover: rowPopover,
|
|
2380
|
+
rowGrouping: rowGrouping,
|
|
2381
|
+
singleSelect: singleSelect,
|
|
2382
|
+
sort: sort,
|
|
2383
|
+
tips: tips,
|
|
2384
|
+
treeMode: pipeline.treeMode,
|
|
2385
|
+
treeMetaSymbol: pipeline.treeMetaSymbol,
|
|
2386
|
+
treeSelect: treeSelect
|
|
2378
2387
|
});
|
|
2379
2388
|
|
|
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));
|
|
2389
|
+
const ICON_WIDTH = 16;
|
|
2390
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
2391
|
+
function makeTreeModeTransform({ onChangeOpenKeys, openKeys, primaryKey, iconIndent = -6, iconGap = 0, indentSize = 16, isLeafNode = pipeline.isLeafNode, clickArea = 'cell', treeMetaKey = pipeline.treeMetaSymbol, stopClickEventPropagation, }) {
|
|
2392
|
+
warnTransformsDeprecated('makeTreeModeTransform');
|
|
2393
|
+
const openKeySet = new Set(openKeys);
|
|
2394
|
+
const toggle = (rowKey) => {
|
|
2395
|
+
const expanded = openKeySet.has(rowKey);
|
|
2396
|
+
if (expanded) {
|
|
2397
|
+
onChangeOpenKeys(openKeys.filter((key) => key !== rowKey), rowKey, 'collapse');
|
|
2398
|
+
}
|
|
2399
|
+
else {
|
|
2400
|
+
onChangeOpenKeys([...openKeys, rowKey], rowKey, 'expand');
|
|
2401
|
+
}
|
|
2402
|
+
};
|
|
2403
|
+
return ({ columns, dataSource }) => {
|
|
2404
|
+
return {
|
|
2405
|
+
columns: processColumns(columns),
|
|
2406
|
+
dataSource: processDataSource(dataSource),
|
|
2407
|
+
};
|
|
2408
|
+
function processDataSource(input) {
|
|
2409
|
+
const result = [];
|
|
2410
|
+
dfs(input, 0);
|
|
2411
|
+
function dfs(nodes, depth) {
|
|
2412
|
+
if (nodes == null) {
|
|
2413
|
+
return;
|
|
2414
|
+
}
|
|
2415
|
+
for (const node of nodes) {
|
|
2416
|
+
const rowKey = node[primaryKey];
|
|
2417
|
+
const expanded = openKeySet.has(rowKey);
|
|
2418
|
+
const isLeaf = isLeafNode(node, { depth, expanded, rowKey });
|
|
2419
|
+
const treeMeta = { depth, isLeaf, expanded, rowKey };
|
|
2420
|
+
result.push(Object.assign({ [treeMetaKey]: treeMeta }, node));
|
|
2421
|
+
if (!isLeaf && expanded) {
|
|
2422
|
+
dfs(node.children, depth + 1);
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
return result;
|
|
2427
|
+
}
|
|
2428
|
+
function processColumns(columns) {
|
|
2429
|
+
if (columns.length === 0) {
|
|
2430
|
+
return columns;
|
|
2431
|
+
}
|
|
2432
|
+
const [firstCol, ...others] = columns;
|
|
2433
|
+
const render = (value, record, recordIndex) => {
|
|
2434
|
+
const content = pipeline.internals.safeRender(firstCol, record, recordIndex);
|
|
2435
|
+
if (record[treeMetaKey] == null) {
|
|
2436
|
+
// 没有 treeMeta 信息的话,就返回原先的渲染结果
|
|
2437
|
+
return content;
|
|
2438
|
+
}
|
|
2439
|
+
const { rowKey, depth, isLeaf, expanded } = record[treeMetaKey];
|
|
2440
|
+
const indent = iconIndent + depth * indentSize;
|
|
2441
|
+
if (isLeaf) {
|
|
2442
|
+
return (React__default["default"].createElement(pipeline.InlineFlexCell, { className: "expansion-cell leaf" },
|
|
2443
|
+
React__default["default"].createElement("div", { style: { marginLeft: indent + ICON_WIDTH + iconGap } }, content)));
|
|
2444
|
+
}
|
|
2445
|
+
const onClick = (e) => {
|
|
2446
|
+
if (stopClickEventPropagation) {
|
|
2447
|
+
e.stopPropagation();
|
|
2448
|
+
}
|
|
2449
|
+
toggle(rowKey);
|
|
2450
|
+
};
|
|
2451
|
+
const expandCls = expanded ? 'expanded' : 'collapsed';
|
|
2452
|
+
return (React__default["default"].createElement(pipeline.ExpansionCell, { className: cx__default["default"]('expansion-cell', expandCls), style: {
|
|
2453
|
+
cursor: clickArea === 'content' ? 'pointer' : undefined,
|
|
2454
|
+
}, onClick: clickArea === 'content' ? onClick : undefined },
|
|
2455
|
+
React__default["default"].createElement(pipeline.icons.CaretRight, { className: cx__default["default"]('expansion-icon', expandCls), style: {
|
|
2456
|
+
cursor: clickArea === 'icon' ? 'pointer' : undefined,
|
|
2457
|
+
marginLeft: indent,
|
|
2458
|
+
marginRight: iconGap,
|
|
2459
|
+
}, onClick: clickArea === 'icon' ? onClick : undefined }),
|
|
2460
|
+
content));
|
|
2461
|
+
};
|
|
2462
|
+
const getCellProps = (value, record, rowIndex) => {
|
|
2463
|
+
const prevProps = pipeline.internals.safeGetCellProps(firstCol, record, rowIndex);
|
|
2464
|
+
if (record[treeMetaKey] == null) {
|
|
2465
|
+
// 没有 treeMeta 信息的话,就返回原先的 cellProps
|
|
2466
|
+
return prevProps;
|
|
2467
|
+
}
|
|
2468
|
+
const { isLeaf, rowKey } = record[treeMetaKey];
|
|
2469
|
+
if (isLeaf) {
|
|
2470
|
+
return prevProps;
|
|
2471
|
+
}
|
|
2472
|
+
return pipeline.mergeCellProps(prevProps, {
|
|
2473
|
+
onClick(e) {
|
|
2474
|
+
if (stopClickEventPropagation) {
|
|
2475
|
+
e.stopPropagation();
|
|
2476
|
+
}
|
|
2477
|
+
toggle(rowKey);
|
|
2478
|
+
},
|
|
2479
|
+
style: { cursor: 'pointer' },
|
|
2480
|
+
});
|
|
2481
|
+
};
|
|
2482
|
+
return [
|
|
2483
|
+
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 }),
|
|
2484
|
+
...others,
|
|
2485
|
+
];
|
|
2486
|
+
}
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
2490
|
+
function useTreeModeTransform(_a) {
|
|
2491
|
+
var { defaultOpenKeys = [] } = _a, others = pipeline.__rest(_a, ["defaultOpenKeys"]);
|
|
2492
|
+
const [openKeys, onChangeOpenKeys] = React.useState(defaultOpenKeys);
|
|
2493
|
+
return makeTreeModeTransform(Object.assign({ openKeys,
|
|
2494
|
+
onChangeOpenKeys }, others));
|
|
2486
2495
|
}
|
|
2487
2496
|
|
|
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
|
-
});
|
|
2497
|
+
/** @deprecated transform 用法已经过时,请使用 pipeline 来对表格进行拓展 */
|
|
2498
|
+
function makeVisibleTransform(visibleCodes) {
|
|
2499
|
+
warnTransformsDeprecated('makeVisibleTransform');
|
|
2500
|
+
const set = new Set(visibleCodes);
|
|
2501
|
+
return traverseColumn((column) => {
|
|
2502
|
+
if (!pipeline.isLeafNode(column)) {
|
|
2503
|
+
return column;
|
|
2504
|
+
}
|
|
2505
|
+
return set.has(column.code) ? column : Object.assign(Object.assign({}, column), { hidden: true });
|
|
2506
|
+
});
|
|
2498
2507
|
}
|
|
2499
2508
|
|
|
2500
2509
|
exports.BaseTable = pipeline.BaseTable;
|