@guozhi5658/srp-table 1.1.0 → 1.1.2

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