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