@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
@@ -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 rxjs = require('rxjs');
8
8
  var styled = require('styled-components');
@@ -15,214 +15,214 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
15
15
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
16
16
  var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
17
17
 
18
- function simpleEncode(path) {
19
- if (path.length === 0) {
20
- return 'key:@total@';
21
- }
22
- return `key:${path.join(' ')}`;
18
+ function simpleEncode(path) {
19
+ if (path.length === 0) {
20
+ return 'key:@total@';
21
+ }
22
+ return `key:${path.join(' ')}`;
23
23
  }
24
24
 
25
- /** 根据指定的 code 序列计算下钻树 */
26
- function buildDrillTree(data, codes, { encode = simpleEncode, totalValue = '总计', includeTopWrapper = false, isExpand = pipeline.always(true), enforceExpandTotalNode = true, } = {}) {
27
- const emptyPath = [];
28
- const totalKey = encode(emptyPath);
29
- let array;
30
- let hasChild = false;
31
- if (codes.length === 0) {
32
- array = [];
33
- }
34
- else if (!enforceExpandTotalNode && !isExpand(totalKey)) {
35
- array = [];
36
- hasChild = data.length > 0;
37
- }
38
- else {
39
- array = dfs(data, []);
40
- }
41
- if (includeTopWrapper) {
42
- const rootNode = {
43
- key: totalKey,
44
- value: totalValue,
45
- path: emptyPath,
46
- children: array,
47
- };
48
- if (hasChild) {
49
- rootNode.hasChild = hasChild;
50
- }
51
- return [rootNode];
52
- }
53
- if (includeTopWrapper) {
54
- return [
55
- {
56
- key: totalKey,
57
- value: totalValue,
58
- path: emptyPath,
59
- children: array,
60
- },
61
- ];
62
- }
63
- return array;
64
- function dfs(slice, path) {
65
- const depth = path.length;
66
- const array = [];
67
- const code = codes[depth];
68
- const groups = pipeline.groupBy2(slice, (row) => row[code]);
69
- for (const groupKey of groups.keys()) {
70
- path.push(groupKey);
71
- const node = {
72
- key: encode(path),
73
- value: groupKey,
74
- path: path.slice(),
75
- };
76
- array.push(node);
77
- const group = groups.get(groupKey);
78
- if (group.length > 0 && depth < codes.length - 1) {
79
- if (isExpand(node.key)) {
80
- node.children = dfs(group, path);
81
- }
82
- else {
83
- node.hasChild = true;
84
- }
85
- }
86
- path.pop();
87
- }
88
- return array;
89
- }
25
+ /** 根据指定的 code 序列计算下钻树 */
26
+ function buildDrillTree(data, codes, { encode = simpleEncode, totalValue = '总计', includeTopWrapper = false, isExpand = pipeline.always(true), enforceExpandTotalNode = true, } = {}) {
27
+ const emptyPath = [];
28
+ const totalKey = encode(emptyPath);
29
+ let array;
30
+ let hasChild = false;
31
+ if (codes.length === 0) {
32
+ array = [];
33
+ }
34
+ else if (!enforceExpandTotalNode && !isExpand(totalKey)) {
35
+ array = [];
36
+ hasChild = data.length > 0;
37
+ }
38
+ else {
39
+ array = dfs(data, []);
40
+ }
41
+ if (includeTopWrapper) {
42
+ const rootNode = {
43
+ key: totalKey,
44
+ value: totalValue,
45
+ path: emptyPath,
46
+ children: array,
47
+ };
48
+ if (hasChild) {
49
+ rootNode.hasChild = hasChild;
50
+ }
51
+ return [rootNode];
52
+ }
53
+ if (includeTopWrapper) {
54
+ return [
55
+ {
56
+ key: totalKey,
57
+ value: totalValue,
58
+ path: emptyPath,
59
+ children: array,
60
+ },
61
+ ];
62
+ }
63
+ return array;
64
+ function dfs(slice, path) {
65
+ const depth = path.length;
66
+ const array = [];
67
+ const code = codes[depth];
68
+ const groups = pipeline.groupBy2(slice, (row) => row[code]);
69
+ for (const groupKey of groups.keys()) {
70
+ path.push(groupKey);
71
+ const node = {
72
+ key: encode(path),
73
+ value: groupKey,
74
+ path: path.slice(),
75
+ };
76
+ array.push(node);
77
+ const group = groups.get(groupKey);
78
+ if (group.length > 0 && depth < codes.length - 1) {
79
+ if (isExpand(node.key)) {
80
+ node.children = dfs(group, path);
81
+ }
82
+ else {
83
+ node.hasChild = true;
84
+ }
85
+ }
86
+ path.pop();
87
+ }
88
+ return array;
89
+ }
90
90
  }
91
91
 
92
- function fallbackAggregate(slice) {
93
- return slice.length === 1 ? slice[0] : {};
94
- }
95
- /** 根据表格左侧与上方的下钻树,从全量明细数据中计算对应的数据立方 */
96
- function buildRecordMatrix({ data, leftCodes, topCodes, aggregate = fallbackAggregate, encode = simpleEncode, isLeftExpand = pipeline.always(true), isTopExpand = pipeline.always(true), prebuiltLeftTree, prebuiltTopTree, }) {
97
- const ctx = {
98
- peculiarity: new Set(),
99
- };
100
- const [leftRootDrillNode] = prebuiltLeftTree !== null && prebuiltLeftTree !== void 0 ? prebuiltLeftTree : buildDrillTree(data, leftCodes, {
101
- encode,
102
- includeTopWrapper: true,
103
- isExpand: isLeftExpand,
104
- });
105
- const [topRootDrillNode] = prebuiltTopTree !== null && prebuiltTopTree !== void 0 ? prebuiltTopTree : buildDrillTree(data, topCodes, {
106
- encode,
107
- includeTopWrapper: true,
108
- isExpand: isTopExpand,
109
- });
110
- const transientMatrixRow = buildByLeft(ctx, data, leftRootDrillNode, 0);
111
- return makeMatrix(transientMatrixRow);
112
- function buildByLeft(ctx, slice, drillNode, depth) {
113
- let children = null;
114
- let col;
115
- if (pipeline.isLeafNode(drillNode)) {
116
- col = buildByTop(ctx, slice, topRootDrillNode, 0);
117
- }
118
- else {
119
- children = [];
120
- const code = leftCodes[depth];
121
- const groups = pipeline.groupBy2(slice, (dwdRow) => dwdRow[code]);
122
- ctx.peculiarity.add(code);
123
- for (const child of drillNode.children) {
124
- const group = groups.get(child.value);
125
- if (group) {
126
- children.push(buildByLeft(ctx, group, child, depth + 1));
127
- }
128
- }
129
- ctx.peculiarity.delete(code);
130
- col = mergeColsByTopTree(ctx, children.map((child) => child.col));
131
- }
132
- return {
133
- leftKey: drillNode.key,
134
- children,
135
- col,
136
- };
137
- }
138
- function buildByTop(ctx, slice, drillNode, depth) {
139
- let children = null;
140
- let record;
141
- if (pipeline.isLeafNode(drillNode)) {
142
- record = aggregate(slice, ctx);
143
- }
144
- else {
145
- children = [];
146
- const code = topCodes[depth];
147
- const groups = pipeline.groupBy2(slice, (dwdRow) => dwdRow[code]);
148
- ctx.peculiarity.add(code);
149
- for (const child of drillNode.children) {
150
- const group = groups.get(child.value);
151
- if (group) {
152
- children.push(buildByTop(ctx, group, child, depth + 1));
153
- }
154
- }
155
- ctx.peculiarity.delete(code);
156
- record = aggregate(children.map((child) => child.record), ctx);
157
- }
158
- return {
159
- topKey: drillNode.key,
160
- topValue: drillNode.value,
161
- children,
162
- record,
163
- };
164
- }
165
- function mergeColsByTopTree(ctx, colsToMerge) {
166
- return dfs(ctx, colsToMerge, topRootDrillNode, 0);
167
- function dfs(ctx, cols, topDrillNode, depth) {
168
- let children = null;
169
- const record = aggregate(cols.map((c) => c.record), ctx);
170
- if (!pipeline.isLeafNode(topDrillNode)) {
171
- const topCode = topCodes[depth];
172
- ctx.peculiarity.add(topCode);
173
- const drillChildDict = pipeline.fromEntries(topDrillNode.children.map((child) => [child.value, child]));
174
- const colChildDictArray = cols.map((col) => pipeline.fromEntries(col.children.map((child) => [child.topValue, child])));
175
- children = topDrillNode.children.map((item) => {
176
- const childCols = colChildDictArray.map((colChildDict) => colChildDict[item.value]).filter(Boolean);
177
- return dfs(ctx, childCols, drillChildDict[item.value], depth + 1);
178
- });
179
- ctx.peculiarity.delete(topCode);
180
- }
181
- return {
182
- topKey: topDrillNode.key,
183
- topValue: topDrillNode.value,
184
- record,
185
- children,
186
- };
187
- }
188
- }
189
- function makeMatrix(rootRow) {
190
- const result = new Map();
191
- dfsRow(result, rootRow);
192
- return result;
193
- function dfsRow(matrix, row) {
194
- const subMap = new Map();
195
- matrix.set(row.leftKey, subMap);
196
- dfsCol(subMap, row.col);
197
- if (!pipeline.isLeafNode(row)) {
198
- row.children.forEach((childRow) => {
199
- dfsRow(matrix, childRow);
200
- });
201
- }
202
- }
203
- function dfsCol(subMap, col) {
204
- subMap.set(col.topKey, col.record);
205
- if (!pipeline.isLeafNode(col)) {
206
- col.children.forEach((childCol) => {
207
- dfsCol(subMap, childCol);
208
- });
209
- }
210
- }
211
- }
212
- }
213
- /** buildRecordMatrix 的简化版本,只能处理一个维度序列,返回一个 Map。
214
- * 相当于只处理 matrix 的第一行(汇总行) */
215
- function buildRecordMap({ codes, encode = simpleEncode, data, aggregate, isExpand, }) {
216
- const matrix = buildRecordMatrix({
217
- data,
218
- leftCodes: [],
219
- topCodes: codes,
220
- isTopExpand: isExpand,
221
- aggregate,
222
- encode,
223
- });
224
- const totalKey = encode([]);
225
- return matrix.get(totalKey);
92
+ function fallbackAggregate(slice) {
93
+ return slice.length === 1 ? slice[0] : {};
94
+ }
95
+ /** 根据表格左侧与上方的下钻树,从全量明细数据中计算对应的数据立方 */
96
+ function buildRecordMatrix({ data, leftCodes, topCodes, aggregate = fallbackAggregate, encode = simpleEncode, isLeftExpand = pipeline.always(true), isTopExpand = pipeline.always(true), prebuiltLeftTree, prebuiltTopTree, }) {
97
+ const ctx = {
98
+ peculiarity: new Set(),
99
+ };
100
+ const [leftRootDrillNode] = prebuiltLeftTree !== null && prebuiltLeftTree !== void 0 ? prebuiltLeftTree : buildDrillTree(data, leftCodes, {
101
+ encode,
102
+ includeTopWrapper: true,
103
+ isExpand: isLeftExpand,
104
+ });
105
+ const [topRootDrillNode] = prebuiltTopTree !== null && prebuiltTopTree !== void 0 ? prebuiltTopTree : buildDrillTree(data, topCodes, {
106
+ encode,
107
+ includeTopWrapper: true,
108
+ isExpand: isTopExpand,
109
+ });
110
+ const transientMatrixRow = buildByLeft(ctx, data, leftRootDrillNode, 0);
111
+ return makeMatrix(transientMatrixRow);
112
+ function buildByLeft(ctx, slice, drillNode, depth) {
113
+ let children = null;
114
+ let col;
115
+ if (pipeline.isLeafNode(drillNode)) {
116
+ col = buildByTop(ctx, slice, topRootDrillNode, 0);
117
+ }
118
+ else {
119
+ children = [];
120
+ const code = leftCodes[depth];
121
+ const groups = pipeline.groupBy2(slice, (dwdRow) => dwdRow[code]);
122
+ ctx.peculiarity.add(code);
123
+ for (const child of drillNode.children) {
124
+ const group = groups.get(child.value);
125
+ if (group) {
126
+ children.push(buildByLeft(ctx, group, child, depth + 1));
127
+ }
128
+ }
129
+ ctx.peculiarity.delete(code);
130
+ col = mergeColsByTopTree(ctx, children.map((child) => child.col));
131
+ }
132
+ return {
133
+ leftKey: drillNode.key,
134
+ children,
135
+ col,
136
+ };
137
+ }
138
+ function buildByTop(ctx, slice, drillNode, depth) {
139
+ let children = null;
140
+ let record;
141
+ if (pipeline.isLeafNode(drillNode)) {
142
+ record = aggregate(slice, ctx);
143
+ }
144
+ else {
145
+ children = [];
146
+ const code = topCodes[depth];
147
+ const groups = pipeline.groupBy2(slice, (dwdRow) => dwdRow[code]);
148
+ ctx.peculiarity.add(code);
149
+ for (const child of drillNode.children) {
150
+ const group = groups.get(child.value);
151
+ if (group) {
152
+ children.push(buildByTop(ctx, group, child, depth + 1));
153
+ }
154
+ }
155
+ ctx.peculiarity.delete(code);
156
+ record = aggregate(children.map((child) => child.record), ctx);
157
+ }
158
+ return {
159
+ topKey: drillNode.key,
160
+ topValue: drillNode.value,
161
+ children,
162
+ record,
163
+ };
164
+ }
165
+ function mergeColsByTopTree(ctx, colsToMerge) {
166
+ return dfs(ctx, colsToMerge, topRootDrillNode, 0);
167
+ function dfs(ctx, cols, topDrillNode, depth) {
168
+ let children = null;
169
+ const record = aggregate(cols.map((c) => c.record), ctx);
170
+ if (!pipeline.isLeafNode(topDrillNode)) {
171
+ const topCode = topCodes[depth];
172
+ ctx.peculiarity.add(topCode);
173
+ const drillChildDict = pipeline.fromEntries(topDrillNode.children.map((child) => [child.value, child]));
174
+ const colChildDictArray = cols.map((col) => pipeline.fromEntries(col.children.map((child) => [child.topValue, child])));
175
+ children = topDrillNode.children.map((item) => {
176
+ const childCols = colChildDictArray.map((colChildDict) => colChildDict[item.value]).filter(Boolean);
177
+ return dfs(ctx, childCols, drillChildDict[item.value], depth + 1);
178
+ });
179
+ ctx.peculiarity.delete(topCode);
180
+ }
181
+ return {
182
+ topKey: topDrillNode.key,
183
+ topValue: topDrillNode.value,
184
+ record,
185
+ children,
186
+ };
187
+ }
188
+ }
189
+ function makeMatrix(rootRow) {
190
+ const result = new Map();
191
+ dfsRow(result, rootRow);
192
+ return result;
193
+ function dfsRow(matrix, row) {
194
+ const subMap = new Map();
195
+ matrix.set(row.leftKey, subMap);
196
+ dfsCol(subMap, row.col);
197
+ if (!pipeline.isLeafNode(row)) {
198
+ row.children.forEach((childRow) => {
199
+ dfsRow(matrix, childRow);
200
+ });
201
+ }
202
+ }
203
+ function dfsCol(subMap, col) {
204
+ subMap.set(col.topKey, col.record);
205
+ if (!pipeline.isLeafNode(col)) {
206
+ col.children.forEach((childCol) => {
207
+ dfsCol(subMap, childCol);
208
+ });
209
+ }
210
+ }
211
+ }
212
+ }
213
+ /** buildRecordMatrix 的简化版本,只能处理一个维度序列,返回一个 Map。
214
+ * 相当于只处理 matrix 的第一行(汇总行) */
215
+ function buildRecordMap({ codes, encode = simpleEncode, data, aggregate, isExpand, }) {
216
+ const matrix = buildRecordMatrix({
217
+ data,
218
+ leftCodes: [],
219
+ topCodes: codes,
220
+ isTopExpand: isExpand,
221
+ aggregate,
222
+ encode,
223
+ });
224
+ const totalKey = encode([]);
225
+ return matrix.get(totalKey);
226
226
  }
227
227
 
228
228
  const ExpandSpan = styled__default["default"].span `
@@ -240,460 +240,461 @@ const ExpandSpan = styled__default["default"].span `
240
240
  transform: rotate(90deg);
241
241
  }
242
242
  }
243
- `;
244
- function convertDrillTreeToCrossTree(drillTree, { indicators, encode = simpleEncode, generateSubtotalNode, enforceExpandTotalNode = true, expandKeys, onChangeExpandKeys = rxjs.noop, supportsExpand, } = {}) {
245
- const totalKey = encode([]);
246
- if (supportsExpand && expandKeys == null) {
247
- throw new Error('[srp-table] convertDrillTreeToCrossTree(...) 设置 supportsExpand=true 时,expandKeys 不能为 null/undefined.');
248
- }
249
- const expandKeySet = new Set(expandKeys);
250
- return dfs(drillTree);
251
- /** 在 indicators 非空的情况下获取指标对应的 CrossTreeNode */
252
- function getIndicators(node, nodeData) {
253
- return indicators.map((indicator) => (Object.assign({ key: encode(node.path.concat([indicator.code])), value: indicator.name, data: Object.assign(Object.assign({}, nodeData), { indicator }) }, indicator)));
254
- }
255
- function drillNodeToTreeNode(node, nodeData) {
256
- if (indicators != null) {
257
- return {
258
- key: node.key,
259
- value: node.value,
260
- data: nodeData,
261
- children: getIndicators(node, nodeData),
262
- };
263
- }
264
- else {
265
- return {
266
- key: node.key,
267
- value: node.value,
268
- data: nodeData,
269
- };
270
- }
271
- }
272
- function dfs(drillNodes, depth) {
273
- const result = [];
274
- for (const node of drillNodes) {
275
- const nodeData = { dataKey: node.key, dataPath: node.path };
276
- if (pipeline.isLeafNode(node) && !node.hasChild) {
277
- result.push(drillNodeToTreeNode(node, nodeData));
278
- }
279
- else {
280
- let needProcessChildren = true;
281
- let crossTreeNode = {
282
- key: node.key,
283
- value: node.value,
284
- data: nodeData,
285
- };
286
- if (!supportsExpand || (enforceExpandTotalNode && node.key === totalKey)) {
287
- // 不支持展开功能 或是强制展开
288
- crossTreeNode.children = dfs(node.children);
289
- }
290
- else if (expandKeySet.has(node.key)) {
291
- // 展开的父节点
292
- // @ts-ignore
293
- crossTreeNode.title = (React__default["default"].createElement(ExpandSpan, { onClick: () => {
294
- onChangeExpandKeys(expandKeys.filter((k) => k !== node.key), node, 'collapse');
295
- } },
296
- React__default["default"].createElement(pipeline.icons.CaretRight, { className: "icon expanded" }),
297
- node.value));
298
- crossTreeNode.children = dfs(node.children);
299
- }
300
- else {
301
- // 收拢的父节点
302
- needProcessChildren = false;
303
- crossTreeNode.title = (React__default["default"].createElement(ExpandSpan, { onClick: () => {
304
- onChangeExpandKeys(expandKeys.concat([node.key]), node, 'expand');
305
- } },
306
- React__default["default"].createElement(pipeline.icons.CaretRight, { className: "icon collapsed" }),
307
- node.value));
308
- if (indicators != null) {
309
- crossTreeNode.children = getIndicators(node, nodeData);
310
- }
311
- }
312
- if (needProcessChildren) {
313
- const subtotalNodeData = generateSubtotalNode === null || generateSubtotalNode === void 0 ? void 0 : generateSubtotalNode(node);
314
- if (subtotalNodeData) {
315
- const { position = 'start', value } = subtotalNodeData;
316
- const subtotalPath = node.path.concat([value]);
317
- const subtotalDrillNode = {
318
- key: encode(subtotalPath),
319
- path: subtotalPath,
320
- value,
321
- };
322
- const subtotalTreeNode = drillNodeToTreeNode(subtotalDrillNode, nodeData);
323
- if (position === 'start') {
324
- crossTreeNode.children.unshift(subtotalTreeNode);
325
- }
326
- else {
327
- crossTreeNode.children.push(subtotalTreeNode);
328
- }
329
- }
330
- }
331
- result.push(crossTreeNode);
332
- }
333
- }
334
- return result;
335
- }
243
+ `;
244
+ function convertDrillTreeToCrossTree(drillTree, { indicators, encode = simpleEncode, generateSubtotalNode, enforceExpandTotalNode = true, expandKeys, onChangeExpandKeys = rxjs.noop, supportsExpand, } = {}) {
245
+ const totalKey = encode([]);
246
+ if (supportsExpand && expandKeys == null) {
247
+ throw new Error('[srp-table] convertDrillTreeToCrossTree(...) 设置 supportsExpand=true 时,expandKeys 不能为 null/undefined.');
248
+ }
249
+ const expandKeySet = new Set(expandKeys);
250
+ return dfs(drillTree);
251
+ /** 在 indicators 非空的情况下获取指标对应的 CrossTreeNode */
252
+ function getIndicators(node, nodeData) {
253
+ return indicators.map((indicator) => (Object.assign({ key: encode(node.path.concat([indicator.code])), value: indicator.name, data: Object.assign(Object.assign({}, nodeData), { indicator }) }, indicator)));
254
+ }
255
+ function drillNodeToTreeNode(node, nodeData) {
256
+ if (indicators != null) {
257
+ return {
258
+ key: node.key,
259
+ value: node.value,
260
+ data: nodeData,
261
+ children: getIndicators(node, nodeData),
262
+ };
263
+ }
264
+ else {
265
+ return {
266
+ key: node.key,
267
+ value: node.value,
268
+ data: nodeData,
269
+ };
270
+ }
271
+ }
272
+ function dfs(drillNodes, depth) {
273
+ const result = [];
274
+ for (const node of drillNodes) {
275
+ const nodeData = { dataKey: node.key, dataPath: node.path };
276
+ if (pipeline.isLeafNode(node) && !node.hasChild) {
277
+ result.push(drillNodeToTreeNode(node, nodeData));
278
+ }
279
+ else {
280
+ let needProcessChildren = true;
281
+ let crossTreeNode = {
282
+ key: node.key,
283
+ value: node.value,
284
+ data: nodeData,
285
+ };
286
+ if (!supportsExpand || (enforceExpandTotalNode && node.key === totalKey)) {
287
+ // 不支持展开功能 或是强制展开
288
+ crossTreeNode.children = dfs(node.children);
289
+ }
290
+ else if (expandKeySet.has(node.key)) {
291
+ // 展开的父节点
292
+ // @ts-ignore
293
+ crossTreeNode.title = (React__default["default"].createElement(ExpandSpan, { onClick: () => {
294
+ onChangeExpandKeys(expandKeys.filter((k) => k !== node.key), node, 'collapse');
295
+ } },
296
+ React__default["default"].createElement(pipeline.icons.CaretRight, { className: "icon expanded" }),
297
+ node.value));
298
+ crossTreeNode.children = dfs(node.children);
299
+ }
300
+ else {
301
+ // 收拢的父节点
302
+ needProcessChildren = false;
303
+ crossTreeNode.title = (React__default["default"].createElement(ExpandSpan, { onClick: () => {
304
+ onChangeExpandKeys(expandKeys.concat([node.key]), node, 'expand');
305
+ } },
306
+ React__default["default"].createElement(pipeline.icons.CaretRight, { className: "icon collapsed" }),
307
+ node.value));
308
+ if (indicators != null) {
309
+ crossTreeNode.children = getIndicators(node, nodeData);
310
+ }
311
+ }
312
+ if (needProcessChildren) {
313
+ const subtotalNodeData = generateSubtotalNode === null || generateSubtotalNode === void 0 ? void 0 : generateSubtotalNode(node);
314
+ if (subtotalNodeData) {
315
+ const { position = 'start', value } = subtotalNodeData;
316
+ const subtotalPath = node.path.concat([value]);
317
+ const subtotalDrillNode = {
318
+ key: encode(subtotalPath),
319
+ path: subtotalPath,
320
+ value,
321
+ };
322
+ const subtotalTreeNode = drillNodeToTreeNode(subtotalDrillNode, nodeData);
323
+ if (position === 'start') {
324
+ crossTreeNode.children.unshift(subtotalTreeNode);
325
+ }
326
+ else {
327
+ crossTreeNode.children.push(subtotalTreeNode);
328
+ }
329
+ }
330
+ }
331
+ result.push(crossTreeNode);
332
+ }
333
+ }
334
+ return result;
335
+ }
336
336
  }
337
337
 
338
338
  const ROW_KEY = 'rowKey';
339
339
 
340
- function buildCrossTable(options) {
341
- var _a, _b, _c, _d, _e, _f;
342
- const { leftTotalNode, topTotalNode } = options;
343
- const columnOffset = (_a = options.columnOffset) !== null && _a !== void 0 ? _a : 0;
344
- const rowOffset = (_b = options.rowOffset) !== null && _b !== void 0 ? _b : 0;
345
- const hasOffset = columnOffset !== 0 || rowOffset !== 0;
346
- // 有的时候 leftTree/topTree 是通过 node.children 传入的
347
- // 此时 leftTree/topTree 等于 null 和等于空数组是等价的
348
- // 故在这里兼容 leftTree/topTree 为空的情况
349
- const leftTree = (_c = options.leftTree) !== null && _c !== void 0 ? _c : [];
350
- const topTree = (_d = options.topTree) !== null && _d !== void 0 ? _d : [];
351
- const getValue = (_e = options.getValue) !== null && _e !== void 0 ? _e : pipeline.always(null);
352
- const leftMetaColumns = (_f = options.leftMetaColumns) !== null && _f !== void 0 ? _f : [];
353
- const leftHeaderWidth = Math.max(leftMetaColumns.length, pipeline.getTreeDepth(leftTree) + 1);
354
- return {
355
- columns: getColumns(),
356
- dataSource: getDataSource(),
357
- };
358
- /** 获取表格的列配置 */
359
- function getColumns() {
360
- return [...getLeftPartColumns(), ...getDataPartColumns()];
361
- function getLeftPartColumns() {
362
- var _a;
363
- const leftPartColumns = [];
364
- for (let index = 0; index < leftHeaderWidth; index++) {
365
- const metaCol = (_a = leftMetaColumns[index]) !== null && _a !== void 0 ? _a : {};
366
- const staticMetaColConfig = pipeline.__rest(metaCol, ["getCellProps", "render"]);
367
- leftPartColumns.push(Object.assign(Object.assign({ columnType: 'left', lock: true }, staticMetaColConfig), { getCellProps: leftHeaderGetCellPropsFactory(metaCol, index), getSpanRect: leftHeaderGetSpanRectFactory(metaCol, index), getValue: leftHeaderGetValueFactory(metaCol, index), render: leftHeaderRenderFactory(metaCol, index) }));
368
- }
369
- return leftPartColumns;
370
- function leftHeaderGetCellPropsFactory(metaCol, colIndex) {
371
- return (_value, row, rowIndex) => {
372
- var _a;
373
- const node = row.nodes[colIndex];
374
- return (_a = metaCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(metaCol, node, colIndex);
375
- };
376
- }
377
- function leftHeaderGetSpanRectFactory(metaCol, colIndex) {
378
- return (_value, row) => {
379
- const rect = row.rects[colIndex];
380
- if (hasOffset) {
381
- return {
382
- left: rect.left + columnOffset,
383
- right: rect.right + columnOffset,
384
- top: rect.top + rowOffset,
385
- bottom: rect.bottom + rowOffset,
386
- };
387
- }
388
- return rect;
389
- };
390
- }
391
- function leftHeaderGetValueFactory(metaCol, colIndex) {
392
- return (row, rowIndex) => {
393
- const node = row.nodes[colIndex];
394
- return node.value;
395
- };
396
- }
397
- function leftHeaderRenderFactory(metaCol, colIndex) {
398
- return (v, row, rowIndex) => {
399
- var _a;
400
- const node = row.nodes[colIndex];
401
- if (metaCol.render) {
402
- return metaCol.render(node, colIndex);
403
- }
404
- return (_a = node.title) !== null && _a !== void 0 ? _a : node.value;
405
- };
406
- }
407
- }
408
- /** 获取表格数据部分的列配置 */
409
- function getDataPartColumns() {
410
- if (topTree.length > 0) {
411
- return dfs(topTree, { valuePath: [], depth: 0 });
412
- }
413
- else if (topTotalNode) {
414
- return dfs([topTotalNode], { valuePath: [], depth: 0 });
415
- }
416
- else {
417
- return [];
418
- }
419
- function dfs(nodes, ctx) {
420
- const result = [];
421
- for (const node of nodes) {
422
- ctx.valuePath.push(node.value);
423
- if (pipeline.isLeafNode(node)) {
424
- // 叶子节点
425
- result.push(getDataColumn(node, ctx.depth));
426
- }
427
- else {
428
- const { key, value, children } = node, others = pipeline.__rest(node
429
- // 强制展开的节点
430
- , ["key", "value", "children"]);
431
- // 强制展开的节点
432
- result.push(Object.assign(Object.assign({ columnType: 'data-parent' }, others), { name: value, children: dfs(children, { valuePath: ctx.valuePath, depth: ctx.depth + 1 }) }));
433
- }
434
- ctx.valuePath.pop();
435
- }
436
- return result;
437
- }
438
- }
439
- function getDataColumn(topNode, topDepth) {
440
- const columnGetValue = (row) => {
441
- const leftDepth = row.nodes.length - 1;
442
- const leftNode = row.nodes[leftDepth];
443
- return getValue(leftNode, topNode, leftDepth, topDepth);
444
- };
445
- const { key, value, children } = topNode, others = pipeline.__rest(topNode, ["key", "value", "children"]);
446
- return Object.assign(Object.assign({ columnType: 'data' }, others), { getValue: columnGetValue, name: value, children: null, render(value, row) {
447
- if (options.render) {
448
- const leftDepth = row.nodes.length - 1;
449
- const leftNode = row.nodes[leftDepth];
450
- return options.render(value, leftNode, topNode, leftDepth, topDepth);
451
- }
452
- return value;
453
- },
454
- getCellProps(value, row) {
455
- if (options.getCellProps) {
456
- const leftDepth = row.nodes.length - 1;
457
- const leftNode = row.nodes[leftDepth];
458
- return options.getCellProps(value, leftNode, topNode, leftDepth, topDepth);
459
- }
460
- } });
461
- }
462
- }
463
- function getDataSource() {
464
- const flatRows = [];
465
- const ctx = { depth: 0, nodes: [], rects: [], rowIndex: 0 };
466
- if (leftTree.length > 0) {
467
- dfs(leftTree, ctx);
468
- }
469
- else if (leftTotalNode) {
470
- dfs([leftTotalNode], ctx);
471
- } // else 表格没有行,展示空表格
472
- return flatRows;
473
- function dfs(nodes, ctx) {
474
- let count = 0;
475
- for (const node of nodes) {
476
- if (node.hidden) {
477
- // 跳过被隐藏的节点
478
- continue;
479
- }
480
- const rect = {
481
- top: ctx.rowIndex + count,
482
- bottom: -1,
483
- left: ctx.depth,
484
- right: -1, // 会在 dfs 之后算出结果
485
- };
486
- const row = {
487
- [ROW_KEY]: node.key,
488
- rects: [...ctx.rects, rect],
489
- nodes: [...ctx.nodes, node],
490
- };
491
- if (pipeline.isLeafNode(node)) {
492
- rect.right = leftHeaderWidth;
493
- rect.bottom = rect.top + 1;
494
- flatRows.push(row);
495
- count += 1;
496
- }
497
- else {
498
- ctx.rects.push(rect);
499
- ctx.nodes.push(node);
500
- const ret = dfs(node.children, {
501
- nodes: ctx.nodes,
502
- rects: ctx.rects,
503
- depth: ctx.depth + 1,
504
- rowIndex: ctx.rowIndex + count,
505
- });
506
- ctx.rects.pop();
507
- ctx.nodes.pop();
508
- count += ret.count;
509
- rect.right = rect.left + 1;
510
- rect.bottom = rect.top + ret.count;
511
- }
512
- }
513
- return { count };
514
- }
515
- }
340
+ function buildCrossTable(options) {
341
+ var _a, _b, _c, _d, _e, _f;
342
+ const { leftTotalNode, topTotalNode } = options;
343
+ const columnOffset = (_a = options.columnOffset) !== null && _a !== void 0 ? _a : 0;
344
+ const rowOffset = (_b = options.rowOffset) !== null && _b !== void 0 ? _b : 0;
345
+ const hasOffset = columnOffset !== 0 || rowOffset !== 0;
346
+ // 有的时候 leftTree/topTree 是通过 node.children 传入的
347
+ // 此时 leftTree/topTree 等于 null 和等于空数组是等价的
348
+ // 故在这里兼容 leftTree/topTree 为空的情况
349
+ const leftTree = (_c = options.leftTree) !== null && _c !== void 0 ? _c : [];
350
+ const topTree = (_d = options.topTree) !== null && _d !== void 0 ? _d : [];
351
+ const getValue = (_e = options.getValue) !== null && _e !== void 0 ? _e : pipeline.always(null);
352
+ const leftMetaColumns = (_f = options.leftMetaColumns) !== null && _f !== void 0 ? _f : [];
353
+ const leftHeaderWidth = Math.max(leftMetaColumns.length, pipeline.getTreeDepth(leftTree) + 1);
354
+ return {
355
+ columns: getColumns(),
356
+ dataSource: getDataSource(),
357
+ };
358
+ /** 获取表格的列配置 */
359
+ function getColumns() {
360
+ return [...getLeftPartColumns(), ...getDataPartColumns()];
361
+ function getLeftPartColumns() {
362
+ var _a;
363
+ const leftPartColumns = [];
364
+ for (let index = 0; index < leftHeaderWidth; index++) {
365
+ const metaCol = (_a = leftMetaColumns[index]) !== null && _a !== void 0 ? _a : {};
366
+ const staticMetaColConfig = pipeline.__rest(metaCol, ["getCellProps", "render"]);
367
+ leftPartColumns.push(Object.assign(Object.assign({ columnType: 'left', lock: true }, staticMetaColConfig), { getCellProps: leftHeaderGetCellPropsFactory(metaCol, index), getSpanRect: leftHeaderGetSpanRectFactory(metaCol, index), getValue: leftHeaderGetValueFactory(metaCol, index), render: leftHeaderRenderFactory(metaCol, index) }));
368
+ }
369
+ return leftPartColumns;
370
+ function leftHeaderGetCellPropsFactory(metaCol, colIndex) {
371
+ return (_value, row, rowIndex) => {
372
+ var _a;
373
+ const node = row.nodes[colIndex];
374
+ return (_a = metaCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(metaCol, node, colIndex);
375
+ };
376
+ }
377
+ function leftHeaderGetSpanRectFactory(metaCol, colIndex) {
378
+ return (_value, row) => {
379
+ const rect = row.rects[colIndex];
380
+ if (hasOffset) {
381
+ return {
382
+ left: rect.left + columnOffset,
383
+ right: rect.right + columnOffset,
384
+ top: rect.top + rowOffset,
385
+ bottom: rect.bottom + rowOffset,
386
+ };
387
+ }
388
+ return rect;
389
+ };
390
+ }
391
+ function leftHeaderGetValueFactory(metaCol, colIndex) {
392
+ return (row, rowIndex) => {
393
+ const node = row.nodes[colIndex];
394
+ return node.value;
395
+ };
396
+ }
397
+ function leftHeaderRenderFactory(metaCol, colIndex) {
398
+ return (v, row, rowIndex) => {
399
+ var _a;
400
+ const node = row.nodes[colIndex];
401
+ if (metaCol.render) {
402
+ return metaCol.render(node, colIndex);
403
+ }
404
+ return (_a = node.title) !== null && _a !== void 0 ? _a : node.value;
405
+ };
406
+ }
407
+ }
408
+ /** 获取表格数据部分的列配置 */
409
+ function getDataPartColumns() {
410
+ if (topTree.length > 0) {
411
+ return dfs(topTree, { valuePath: [], depth: 0 });
412
+ }
413
+ else if (topTotalNode) {
414
+ return dfs([topTotalNode], { valuePath: [], depth: 0 });
415
+ }
416
+ else {
417
+ return [];
418
+ }
419
+ function dfs(nodes, ctx) {
420
+ const result = [];
421
+ for (const node of nodes) {
422
+ ctx.valuePath.push(node.value);
423
+ if (pipeline.isLeafNode(node)) {
424
+ // 叶子节点
425
+ result.push(getDataColumn(node, ctx.depth));
426
+ }
427
+ else {
428
+ const { key, value, children } = node, others = pipeline.__rest(node
429
+ // 强制展开的节点
430
+ , ["key", "value", "children"]);
431
+ // 强制展开的节点
432
+ result.push(Object.assign(Object.assign({ columnType: 'data-parent' }, others), { name: value, children: dfs(children, { valuePath: ctx.valuePath, depth: ctx.depth + 1 }) }));
433
+ }
434
+ ctx.valuePath.pop();
435
+ }
436
+ return result;
437
+ }
438
+ }
439
+ function getDataColumn(topNode, topDepth) {
440
+ const columnGetValue = (row) => {
441
+ const leftDepth = row.nodes.length - 1;
442
+ const leftNode = row.nodes[leftDepth];
443
+ return getValue(leftNode, topNode, leftDepth, topDepth);
444
+ };
445
+ const { key, value, children } = topNode, others = pipeline.__rest(topNode, ["key", "value", "children"]);
446
+ return Object.assign(Object.assign({ columnType: 'data' }, others), { getValue: columnGetValue, name: value, children: null, render(value, row) {
447
+ if (options.render) {
448
+ const leftDepth = row.nodes.length - 1;
449
+ const leftNode = row.nodes[leftDepth];
450
+ return options.render(value, leftNode, topNode, leftDepth, topDepth);
451
+ }
452
+ return value;
453
+ },
454
+ getCellProps(value, row) {
455
+ if (options.getCellProps) {
456
+ const leftDepth = row.nodes.length - 1;
457
+ const leftNode = row.nodes[leftDepth];
458
+ return options.getCellProps(value, leftNode, topNode, leftDepth, topDepth);
459
+ }
460
+ } });
461
+ }
462
+ }
463
+ function getDataSource() {
464
+ const flatRows = [];
465
+ const ctx = { depth: 0, nodes: [], rects: [], rowIndex: 0 };
466
+ if (leftTree.length > 0) {
467
+ dfs(leftTree, ctx);
468
+ }
469
+ else if (leftTotalNode) {
470
+ dfs([leftTotalNode], ctx);
471
+ } // else 表格没有行,展示空表格
472
+ return flatRows;
473
+ function dfs(nodes, ctx) {
474
+ let count = 0;
475
+ for (const node of nodes) {
476
+ if (node.hidden) {
477
+ // 跳过被隐藏的节点
478
+ continue;
479
+ }
480
+ const rect = {
481
+ top: ctx.rowIndex + count,
482
+ bottom: -1, // 会在 dfs 之后算出结果
483
+ left: ctx.depth,
484
+ right: -1, // 会在 dfs 之后算出结果
485
+ };
486
+ const row = {
487
+ [ROW_KEY]: node.key,
488
+ rects: [...ctx.rects, rect],
489
+ nodes: [...ctx.nodes, node],
490
+ };
491
+ if (pipeline.isLeafNode(node)) {
492
+ rect.right = leftHeaderWidth;
493
+ rect.bottom = rect.top + 1;
494
+ flatRows.push(row);
495
+ count += 1;
496
+ }
497
+ else {
498
+ ctx.rects.push(rect);
499
+ ctx.nodes.push(node);
500
+ const ret = dfs(node.children, {
501
+ nodes: ctx.nodes,
502
+ rects: ctx.rects,
503
+ depth: ctx.depth + 1,
504
+ rowIndex: ctx.rowIndex + count,
505
+ });
506
+ ctx.rects.pop();
507
+ ctx.nodes.pop();
508
+ count += ret.count;
509
+ rect.right = rect.left + 1;
510
+ rect.bottom = rect.top + ret.count;
511
+ }
512
+ }
513
+ return { count };
514
+ }
515
+ }
516
516
  }
517
517
 
518
- function CrossTable(_a) {
519
- var { BaseTableComponent = pipeline.BaseTable, leftTree, leftTotalNode, topTree, topTotalNode, getValue, getCellProps, leftMetaColumns, render, baseTableRef } = _a, others = pipeline.__rest(_a, ["BaseTableComponent", "leftTree", "leftTotalNode", "topTree", "topTotalNode", "getValue", "getCellProps", "leftMetaColumns", "render", "baseTableRef"]);
520
- const { dataSource, columns } = buildCrossTable({
521
- leftTree,
522
- topTree,
523
- leftTotalNode,
524
- topTotalNode,
525
- getValue,
526
- getCellProps,
527
- render,
528
- leftMetaColumns,
529
- });
530
- return (React__default["default"].createElement(BaseTableComponent, Object.assign({ ref: baseTableRef }, others, { primaryKey: ROW_KEY, dataSource: dataSource, columns: columns })));
518
+ function CrossTable(_a) {
519
+ var { BaseTableComponent = pipeline.BaseTable, leftTree, leftTotalNode, topTree, topTotalNode, getValue, getCellProps, leftMetaColumns, render, baseTableRef } = _a, others = pipeline.__rest(_a, ["BaseTableComponent", "leftTree", "leftTotalNode", "topTree", "topTotalNode", "getValue", "getCellProps", "leftMetaColumns", "render", "baseTableRef"]);
520
+ const { dataSource, columns } = buildCrossTable({
521
+ leftTree,
522
+ topTree,
523
+ leftTotalNode,
524
+ topTotalNode,
525
+ getValue,
526
+ getCellProps,
527
+ render,
528
+ leftMetaColumns,
529
+ });
530
+ return (React__default["default"].createElement(BaseTableComponent, Object.assign({ ref: baseTableRef }, others, { primaryKey: ROW_KEY, dataSource: dataSource, columns: columns })));
531
531
  }
532
532
 
533
- function buildCrossTreeTable(options) {
534
- var _a, _b;
535
- const { primaryColumn = { name: '' }, openKeys, onChangeOpenKeys, indentSize, isLeafNode: isLeafNodeOpt = pipeline.isLeafNode, } = options;
536
- // 有的时候 leftTree/topTree 是通过 node.children 传入的
537
- // 此时 leftTree/topTree 等于 null 和等于空数组是等价的
538
- // 故在这里兼容 leftTree/topTree 为空的情况
539
- const leftTree = (_a = options.leftTree) !== null && _a !== void 0 ? _a : [];
540
- const topTree = (_b = options.topTree) !== null && _b !== void 0 ? _b : [];
541
- const pipeline$1 = new pipeline.TablePipeline({
542
- state: {},
543
- setState: rxjs.noop,
544
- ctx: { primaryKey: ROW_KEY },
545
- });
546
- pipeline$1.input({ dataSource: getDataSource(), columns: getColumns() });
547
- pipeline$1.use(pipeline.treeMode({
548
- openKeys,
549
- onChangeOpenKeys,
550
- indentSize,
551
- isLeafNode(row, nodeMeta) {
552
- // 调用上层 isLeafNodeOpt 时,会从 row.node 中读取该表格行对应的 leftTreeNode
553
- return isLeafNodeOpt(row.node, nodeMeta);
554
- },
555
- }));
556
- return {
557
- dataSource: pipeline$1.getDataSource(),
558
- columns: pipeline$1.getColumns(),
559
- };
560
- /** 获取表格的列配置 */
561
- function getColumns() {
562
- return [
563
- Object.assign(Object.assign({}, primaryColumn), { getValue(row) {
564
- return row.node.value;
565
- },
566
- getCellProps(value, row) {
567
- if (primaryColumn.getCellProps) {
568
- return primaryColumn.getCellProps(row.node, row.nodes.length - 1);
569
- }
570
- },
571
- render(value, row) {
572
- if (primaryColumn.render) {
573
- return primaryColumn.render(row.node, row.nodes.length - 1);
574
- }
575
- return value;
576
- } }),
577
- ...getDataPartColumns(),
578
- ];
579
- /** 获取表格数据部分的列配置 */
580
- function getDataPartColumns() {
581
- return dfs(topTree, { depth: 0 });
582
- function dfs(nodes, ctx) {
583
- const result = [];
584
- for (const node of nodes) {
585
- if (pipeline.isLeafNode(node)) {
586
- result.push(getDataColumn(node, ctx.depth));
587
- }
588
- else {
589
- const { key, value, children } = node, others = pipeline.__rest(node, ["key", "value", "children"]);
590
- result.push(Object.assign(Object.assign({}, others), { name: value, children: dfs(children, { depth: ctx.depth + 1 }) }));
591
- }
592
- }
593
- return result;
594
- }
595
- }
596
- function getDataColumn(topNode, topDepth) {
597
- const columnGetValue = (row) => {
598
- const leftDepth = row.nodes.length - 1;
599
- const leftNode = row.node;
600
- if (options.getValue) {
601
- return options.getValue(leftNode, topNode, leftDepth, topDepth);
602
- }
603
- return null;
604
- };
605
- const { key, value, children } = topNode, others = pipeline.__rest(topNode, ["key", "value", "children"]);
606
- return Object.assign(Object.assign({}, others), { getValue: columnGetValue, name: value, children: null, render(value, row) {
607
- if (options.render) {
608
- const leftDepth = row.nodes.length - 1;
609
- const leftNode = row.node;
610
- return options.render(value, leftNode, topNode, leftDepth, topDepth);
611
- }
612
- return value;
613
- },
614
- getCellProps(value, row) {
615
- if (options.getCellProps) {
616
- const leftDepth = row.nodes.length - 1;
617
- const leftNode = row.node;
618
- return options.getCellProps(value, leftNode, topNode, leftDepth, topDepth);
619
- }
620
- } });
621
- }
622
- }
623
- function getDataSource() {
624
- return dfs(leftTree, { nodes: [] });
625
- function dfs(nodes, ctx) {
626
- const result = [];
627
- for (const node of nodes) {
628
- if (node.hidden) {
629
- // 跳过被隐藏的节点
630
- continue;
631
- }
632
- if (pipeline.isLeafNode(node)) {
633
- result.push({
634
- [ROW_KEY]: node.key,
635
- node,
636
- nodes: [...ctx.nodes, node],
637
- });
638
- }
639
- else {
640
- const nodes = [...ctx.nodes, node];
641
- ctx.nodes.push(node);
642
- const children = dfs(node.children, ctx);
643
- result.push({ [ROW_KEY]: node.key, node, nodes, children });
644
- ctx.nodes.pop();
645
- }
646
- }
647
- return result;
648
- }
649
- }
533
+ function buildCrossTreeTable(options) {
534
+ var _a, _b;
535
+ const { primaryColumn = { name: '' }, openKeys, onChangeOpenKeys, indentSize, isLeafNode: isLeafNodeOpt = pipeline.isLeafNode, } = options;
536
+ // 有的时候 leftTree/topTree 是通过 node.children 传入的
537
+ // 此时 leftTree/topTree 等于 null 和等于空数组是等价的
538
+ // 故在这里兼容 leftTree/topTree 为空的情况
539
+ const leftTree = (_a = options.leftTree) !== null && _a !== void 0 ? _a : [];
540
+ const topTree = (_b = options.topTree) !== null && _b !== void 0 ? _b : [];
541
+ const pipeline$1 = new pipeline.TablePipeline({
542
+ state: {},
543
+ setState: rxjs.noop,
544
+ ctx: { primaryKey: ROW_KEY },
545
+ });
546
+ pipeline$1.input({ dataSource: getDataSource(), columns: getColumns() });
547
+ pipeline$1.use(pipeline.treeMode({
548
+ openKeys,
549
+ onChangeOpenKeys,
550
+ indentSize,
551
+ isLeafNode(row, nodeMeta) {
552
+ // 调用上层 isLeafNodeOpt 时,会从 row.node 中读取该表格行对应的 leftTreeNode
553
+ return isLeafNodeOpt(row.node, nodeMeta);
554
+ },
555
+ }));
556
+ return {
557
+ dataSource: pipeline$1.getDataSource(),
558
+ columns: pipeline$1.getColumns(),
559
+ };
560
+ /** 获取表格的列配置 */
561
+ function getColumns() {
562
+ return [
563
+ Object.assign(Object.assign({}, primaryColumn), { getValue(row) {
564
+ return row.node.value;
565
+ },
566
+ getCellProps(value, row) {
567
+ if (primaryColumn.getCellProps) {
568
+ return primaryColumn.getCellProps(row.node, row.nodes.length - 1);
569
+ }
570
+ },
571
+ render(value, row) {
572
+ if (primaryColumn.render) {
573
+ return primaryColumn.render(row.node, row.nodes.length - 1);
574
+ }
575
+ return value;
576
+ } }),
577
+ ...getDataPartColumns(),
578
+ ];
579
+ /** 获取表格数据部分的列配置 */
580
+ function getDataPartColumns() {
581
+ return dfs(topTree, { depth: 0 });
582
+ function dfs(nodes, ctx) {
583
+ const result = [];
584
+ for (const node of nodes) {
585
+ if (pipeline.isLeafNode(node)) {
586
+ result.push(getDataColumn(node, ctx.depth));
587
+ }
588
+ else {
589
+ const { key, value, children } = node, others = pipeline.__rest(node, ["key", "value", "children"]);
590
+ result.push(Object.assign(Object.assign({}, others), { name: value, children: dfs(children, { depth: ctx.depth + 1 }) }));
591
+ }
592
+ }
593
+ return result;
594
+ }
595
+ }
596
+ function getDataColumn(topNode, topDepth) {
597
+ const columnGetValue = (row) => {
598
+ const leftDepth = row.nodes.length - 1;
599
+ const leftNode = row.node;
600
+ if (options.getValue) {
601
+ return options.getValue(leftNode, topNode, leftDepth, topDepth);
602
+ }
603
+ return null;
604
+ };
605
+ const { key, value, children } = topNode, others = pipeline.__rest(topNode, ["key", "value", "children"]);
606
+ return Object.assign(Object.assign({}, others), { getValue: columnGetValue, name: value, children: null, render(value, row) {
607
+ if (options.render) {
608
+ const leftDepth = row.nodes.length - 1;
609
+ const leftNode = row.node;
610
+ return options.render(value, leftNode, topNode, leftDepth, topDepth);
611
+ }
612
+ return value;
613
+ },
614
+ getCellProps(value, row) {
615
+ if (options.getCellProps) {
616
+ const leftDepth = row.nodes.length - 1;
617
+ const leftNode = row.node;
618
+ return options.getCellProps(value, leftNode, topNode, leftDepth, topDepth);
619
+ }
620
+ } });
621
+ }
622
+ }
623
+ function getDataSource() {
624
+ return dfs(leftTree, { nodes: [] });
625
+ function dfs(nodes, ctx) {
626
+ const result = [];
627
+ for (const node of nodes) {
628
+ if (node.hidden) {
629
+ // 跳过被隐藏的节点
630
+ continue;
631
+ }
632
+ if (pipeline.isLeafNode(node)) {
633
+ result.push({
634
+ [ROW_KEY]: node.key,
635
+ node,
636
+ nodes: [...ctx.nodes, node],
637
+ });
638
+ }
639
+ else {
640
+ const nodes = [...ctx.nodes, node];
641
+ ctx.nodes.push(node);
642
+ const children = dfs(node.children, ctx);
643
+ result.push({ [ROW_KEY]: node.key, node, nodes, children });
644
+ ctx.nodes.pop();
645
+ }
646
+ }
647
+ return result;
648
+ }
649
+ }
650
650
  }
651
651
 
652
- class CrossTreeTable extends React__default["default"].Component {
653
- constructor(props) {
654
- super(props);
655
- this.onChangeOpenKeys = (nextOpenKeys) => {
656
- this.props.onChangeOpenKeys(nextOpenKeys);
657
- if (!('openKeys' in this.props)) {
658
- this.setState({ openKeys: nextOpenKeys });
659
- }
660
- };
661
- this.state = {
662
- openKeys: props.defaultOpenKeys,
663
- };
664
- }
665
- static getDerivedStateFromProps(nextProps) {
666
- if ('openKeys' in nextProps) {
667
- return { openKeys: nextProps.openKeys };
668
- }
669
- return null;
670
- }
671
- render() {
672
- const _a = this.props, { BaseTableComponent = pipeline.BaseTable, leftTree, topTree, getValue, getCellProps, primaryColumn, render, openKeys: openKeysProp, defaultOpenKeys, onChangeOpenKeys, indentSize, isLeafNode, baseTableRef } = _a, others = pipeline.__rest(_a, ["BaseTableComponent", "leftTree", "topTree", "getValue", "getCellProps", "primaryColumn", "render", "openKeys", "defaultOpenKeys", "onChangeOpenKeys", "indentSize", "isLeafNode", "baseTableRef"]) // 透传其他 BaseTable 的 props
673
- ;
674
- const openKeys = openKeysProp !== null && openKeysProp !== void 0 ? openKeysProp : this.state.openKeys;
675
- const { dataSource, columns } = buildCrossTreeTable({
676
- leftTree,
677
- topTree,
678
- getValue,
679
- getCellProps,
680
- render,
681
- primaryColumn,
682
- openKeys,
683
- onChangeOpenKeys: this.onChangeOpenKeys,
684
- indentSize,
685
- isLeafNode,
686
- });
687
- return (React__default["default"].createElement(BaseTableComponent, Object.assign({ ref: baseTableRef }, others, { primaryKey: ROW_KEY, dataSource: dataSource, columns: columns })));
688
- }
689
- }
690
- CrossTreeTable.defaultProps = {
691
- defaultOpenKeys: [],
692
- onChangeOpenKeys: rxjs.noop,
652
+ class CrossTreeTable extends React__default["default"].Component {
653
+ static getDerivedStateFromProps(nextProps) {
654
+ if ('openKeys' in nextProps) {
655
+ return { openKeys: nextProps.openKeys };
656
+ }
657
+ return null;
658
+ }
659
+ constructor(props) {
660
+ super(props);
661
+ this.onChangeOpenKeys = (nextOpenKeys) => {
662
+ this.props.onChangeOpenKeys(nextOpenKeys);
663
+ if (!('openKeys' in this.props)) {
664
+ this.setState({ openKeys: nextOpenKeys });
665
+ }
666
+ };
667
+ this.state = {
668
+ openKeys: props.defaultOpenKeys,
669
+ };
670
+ }
671
+ render() {
672
+ const _a = this.props, { BaseTableComponent = pipeline.BaseTable, leftTree, topTree, getValue, getCellProps, primaryColumn, render, openKeys: openKeysProp, defaultOpenKeys, onChangeOpenKeys, indentSize, isLeafNode, baseTableRef } = _a, others = pipeline.__rest(_a, ["BaseTableComponent", "leftTree", "topTree", "getValue", "getCellProps", "primaryColumn", "render", "openKeys", "defaultOpenKeys", "onChangeOpenKeys", "indentSize", "isLeafNode", "baseTableRef"]) // 透传其他 BaseTable 的 props
673
+ ;
674
+ const openKeys = openKeysProp !== null && openKeysProp !== void 0 ? openKeysProp : this.state.openKeys;
675
+ const { dataSource, columns } = buildCrossTreeTable({
676
+ leftTree,
677
+ topTree,
678
+ getValue,
679
+ getCellProps,
680
+ render,
681
+ primaryColumn,
682
+ openKeys,
683
+ onChangeOpenKeys: this.onChangeOpenKeys,
684
+ indentSize,
685
+ isLeafNode,
686
+ });
687
+ return (React__default["default"].createElement(BaseTableComponent, Object.assign({ ref: baseTableRef }, others, { primaryKey: ROW_KEY, dataSource: dataSource, columns: columns })));
688
+ }
689
+ }
690
+ CrossTreeTable.defaultProps = {
691
+ defaultOpenKeys: [],
692
+ onChangeOpenKeys: rxjs.noop,
693
693
  };
694
+ var CrossTreeTable$1 = CrossTreeTable;
694
695
 
695
696
  exports.CrossTable = CrossTable;
696
- exports.CrossTreeTable = CrossTreeTable;
697
+ exports.CrossTreeTable = CrossTreeTable$1;
697
698
  exports.ROW_KEY = ROW_KEY;
698
699
  exports.buildCrossTable = buildCrossTable;
699
700
  exports.buildCrossTreeTable = buildCrossTreeTable;