@kdcloudjs/table 1.2.0-canary.15 → 1.2.0-canary.16-hotfix

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 (233) hide show
  1. package/dist/@kdcloudjs/table.css +1 -1
  2. package/dist/@kdcloudjs/table.js +2051 -3489
  3. package/dist/@kdcloudjs/table.js.map +1 -1
  4. package/dist/@kdcloudjs/table.min.css +1 -1
  5. package/dist/@kdcloudjs/table.min.js +16 -16
  6. package/dist/@kdcloudjs/table.min.js.map +1 -1
  7. package/es/_utils/arrayUtil.js +0 -3
  8. package/es/_utils/devwarning.js +0 -1
  9. package/es/_utils/formatUtil.js +35 -96
  10. package/es/_utils/hooks.js +18 -42
  11. package/es/_utils/index.js +0 -2
  12. package/es/_utils/numberUtil.js +32 -55
  13. package/es/_utils/omit.js +0 -2
  14. package/es/_utils/type.js +0 -2
  15. package/es/_utils/usePopper.js +74 -137
  16. package/es/config-provider/compDefaultProps.js +0 -1
  17. package/es/config-provider/configProvider.js +2 -7
  18. package/es/config-provider/defaultConfig.js +0 -1
  19. package/es/index.js +0 -2
  20. package/es/locale/locale.js +5 -43
  21. package/es/table/base/calculations.js +22 -72
  22. package/es/table/base/colgroup.js +0 -1
  23. package/es/table/base/empty.js +4 -4
  24. package/es/table/base/header.js +14 -67
  25. package/es/table/base/helpers/SpanManager.js +3 -9
  26. package/es/table/base/helpers/TableDOMUtils.js +4 -27
  27. package/es/table/base/helpers/__test__/SpanManager.test.js +2 -2
  28. package/es/table/base/helpers/__test__/TableDOMUtils.test.js +0 -1
  29. package/es/table/base/helpers/getRichVisibleRectsStream.js +11 -44
  30. package/es/table/base/helpers/rowHeightManager.js +0 -28
  31. package/es/table/base/html-table.js +14 -35
  32. package/es/table/base/loading.js +6 -8
  33. package/es/table/base/renderTemplates.js +26 -44
  34. package/es/table/base/styles.js +1 -10
  35. package/es/table/base/table.js +96 -179
  36. package/es/table/base/utils.js +14 -54
  37. package/es/table/common-views.js +0 -7
  38. package/es/table/internals.js +0 -13
  39. package/es/table/pipeline/features/autoFill.js +11 -40
  40. package/es/table/pipeline/features/autoRowSpan.js +1 -14
  41. package/es/table/pipeline/features/colGroupExtendable.js +4 -19
  42. package/es/table/pipeline/features/columnDrag.d.ts +1 -0
  43. package/es/table/pipeline/features/columnDrag.js +236 -303
  44. package/es/table/pipeline/features/columnFilter.js +11 -48
  45. package/es/table/pipeline/features/columnHover.js +1 -7
  46. package/es/table/pipeline/features/columnRangeHover.js +1 -8
  47. package/es/table/pipeline/features/columnResizeWidth.js +51 -42
  48. package/es/table/pipeline/features/contextMenu.js +18 -89
  49. package/es/table/pipeline/features/filter/DefaultFilterContent.js +10 -25
  50. package/es/table/pipeline/features/filter/DefaultFilterIcon.js +1 -1
  51. package/es/table/pipeline/features/filter/Filter.js +25 -48
  52. package/es/table/pipeline/features/filter/FilterPanel.js +11 -25
  53. package/es/table/pipeline/features/filter/util.js +0 -4
  54. package/es/table/pipeline/features/footerDataSource.js +0 -3
  55. package/es/table/pipeline/features/mergeCellHover.js +0 -1
  56. package/es/table/pipeline/features/multiSelect.js +15 -57
  57. package/es/table/pipeline/features/rangeSelection.js +65 -143
  58. package/es/table/pipeline/features/rowDetail.js +2 -41
  59. package/es/table/pipeline/features/rowDrag.js +36 -71
  60. package/es/table/pipeline/features/rowGrouping.js +2 -35
  61. package/es/table/pipeline/features/singleSelect.js +0 -24
  62. package/es/table/pipeline/features/sort.js +31 -83
  63. package/es/table/pipeline/features/tips.js +0 -6
  64. package/es/table/pipeline/features/treeMode.js +9 -44
  65. package/es/table/pipeline/features/treeSelect.js +0 -26
  66. package/es/table/pipeline/features/utils/touchEventUtils.d.ts +15 -0
  67. package/es/table/pipeline/features/utils/touchEventUtils.js +65 -0
  68. package/es/table/pipeline/pipeline.js +11 -51
  69. package/es/table/pivot/cross-table/buildCrossTable.js +15 -64
  70. package/es/table/pivot/cross-table/cross-table.js +22 -28
  71. package/es/table/pivot/cross-tree-table/buildCrossTreeTable.js +14 -47
  72. package/es/table/pivot/cross-tree-table/cross-tree-table.js +28 -50
  73. package/es/table/pivot/pivot-utils/buildDrillTree.js +10 -23
  74. package/es/table/pivot/pivot-utils/builders.js +31 -71
  75. package/es/table/pivot/pivot-utils/convert-utils.js +13 -39
  76. package/es/table/pivot/pivot-utils/simpleEncode.js +0 -1
  77. package/es/table/transforms/autoRowSpan.js +1 -15
  78. package/es/table/transforms/autoWidth.js +10 -32
  79. package/es/table/transforms/buildTree.js +1 -2
  80. package/es/table/transforms/columnHover.js +9 -15
  81. package/es/table/transforms/columnRangeHover.js +12 -19
  82. package/es/table/transforms/columnResize.js +15 -37
  83. package/es/table/transforms/flatten.js +0 -3
  84. package/es/table/transforms/orderField.js +0 -3
  85. package/es/table/transforms/sort.js +36 -88
  86. package/es/table/transforms/tips.js +1 -6
  87. package/es/table/transforms/treeMode.js +30 -69
  88. package/es/table/transforms/visible.js +0 -2
  89. package/es/table/use/useResizeObserver.js +1 -4
  90. package/es/table/utils/applyTransforms.js +0 -1
  91. package/es/table/utils/buildTree.js +4 -19
  92. package/es/table/utils/collectNodes.js +1 -10
  93. package/es/table/utils/console.js +0 -14
  94. package/es/table/utils/copyToClipboard.js +0 -4
  95. package/es/table/utils/element.js +14 -41
  96. package/es/table/utils/exportTableAsExcel.js +4 -40
  97. package/es/table/utils/getTreeDepth.js +1 -9
  98. package/es/table/utils/groupBy.js +1 -10
  99. package/es/table/utils/layeredFilter.js +0 -4
  100. package/es/table/utils/layeredSort.js +0 -5
  101. package/es/table/utils/makeRecursiveMapper.js +1 -12
  102. package/es/table/utils/mergeCellProps.js +6 -13
  103. package/es/table/utils/others.js +3 -16
  104. package/es/table/utils/proto.js +2 -30
  105. package/es/table/utils/smartCompare.js +4 -12
  106. package/es/table/utils/traverseColumn.js +2 -15
  107. package/es/table/utils/tree-data-helpers/StrictTreeDataHelper.js +1 -22
  108. package/es/table/utils/tree-data-helpers/TreeDataHelper.js +15 -69
  109. package/lib/_utils/arrayUtil.js +0 -5
  110. package/lib/_utils/devwarning.js +0 -5
  111. package/lib/_utils/formatUtil.js +35 -100
  112. package/lib/_utils/hooks.js +18 -53
  113. package/lib/_utils/index.js +0 -6
  114. package/lib/_utils/numberUtil.js +32 -63
  115. package/lib/_utils/omit.js +0 -5
  116. package/lib/_utils/react-children.js +0 -5
  117. package/lib/_utils/type.js +0 -6
  118. package/lib/_utils/usePopper.js +74 -158
  119. package/lib/config-provider/ConfigContext.js +1 -4
  120. package/lib/config-provider/compDefaultProps.js +0 -1
  121. package/lib/config-provider/configProvider.js +3 -18
  122. package/lib/config-provider/defaultConfig.js +0 -5
  123. package/lib/config-provider/index.js +0 -6
  124. package/lib/index.js +2 -8
  125. package/lib/locale/index.js +0 -7
  126. package/lib/locale/locale.js +5 -57
  127. package/lib/table/base/calculations.js +22 -83
  128. package/lib/table/base/colgroup.js +0 -5
  129. package/lib/table/base/empty.js +4 -16
  130. package/lib/table/base/header.js +14 -77
  131. package/lib/table/base/helpers/SpanManager.js +3 -11
  132. package/lib/table/base/helpers/TableDOMUtils.js +2 -27
  133. package/lib/table/base/helpers/__test__/SpanManager.test.js +2 -4
  134. package/lib/table/base/helpers/__test__/TableDOMUtils.test.js +0 -5
  135. package/lib/table/base/helpers/__test__/rowHeightManager.test.js +0 -1
  136. package/lib/table/base/helpers/getRichVisibleRectsStream.js +11 -62
  137. package/lib/table/base/helpers/rowHeightManager.js +0 -33
  138. package/lib/table/base/html-table.js +14 -45
  139. package/lib/table/base/index.js +0 -2
  140. package/lib/table/base/loading.js +6 -12
  141. package/lib/table/base/renderTemplates.js +27 -58
  142. package/lib/table/base/styles.js +1 -22
  143. package/lib/table/base/table.js +96 -212
  144. package/lib/table/base/utils.js +14 -89
  145. package/lib/table/common-views.js +0 -16
  146. package/lib/table/index.js +0 -13
  147. package/lib/table/internals.js +0 -14
  148. package/lib/table/pipeline/features/autoFill.js +11 -47
  149. package/lib/table/pipeline/features/autoRowSpan.js +1 -19
  150. package/lib/table/pipeline/features/buildTree.js +0 -2
  151. package/lib/table/pipeline/features/colGroupExtendable.js +4 -32
  152. package/lib/table/pipeline/features/columnDrag.d.ts +1 -0
  153. package/lib/table/pipeline/features/columnDrag.js +236 -309
  154. package/lib/table/pipeline/features/columnFilter.js +11 -62
  155. package/lib/table/pipeline/features/columnHover.js +1 -11
  156. package/lib/table/pipeline/features/columnRangeHover.js +1 -13
  157. package/lib/table/pipeline/features/columnResizeWidth.js +51 -58
  158. package/lib/table/pipeline/features/contextMenu.js +18 -113
  159. package/lib/table/pipeline/features/filter/DefaultFilterContent.js +10 -43
  160. package/lib/table/pipeline/features/filter/DefaultFilterIcon.js +1 -4
  161. package/lib/table/pipeline/features/filter/Filter.js +25 -70
  162. package/lib/table/pipeline/features/filter/FilterPanel.js +11 -40
  163. package/lib/table/pipeline/features/filter/index.js +0 -5
  164. package/lib/table/pipeline/features/filter/util.js +0 -7
  165. package/lib/table/pipeline/features/footerDataSource.js +0 -10
  166. package/lib/table/pipeline/features/index.js +0 -23
  167. package/lib/table/pipeline/features/mergeCellHover.js +0 -5
  168. package/lib/table/pipeline/features/multiSelect.js +15 -71
  169. package/lib/table/pipeline/features/rangeSelection.js +65 -160
  170. package/lib/table/pipeline/features/rowDetail.js +2 -65
  171. package/lib/table/pipeline/features/rowDrag.js +36 -81
  172. package/lib/table/pipeline/features/rowGrouping.js +2 -55
  173. package/lib/table/pipeline/features/singleSelect.js +0 -34
  174. package/lib/table/pipeline/features/sort.js +31 -103
  175. package/lib/table/pipeline/features/tips.js +0 -15
  176. package/lib/table/pipeline/features/treeMode.js +9 -65
  177. package/lib/table/pipeline/features/treeSelect.js +0 -34
  178. package/lib/table/pipeline/features/utils/touchEventUtils.d.ts +15 -0
  179. package/lib/table/pipeline/features/utils/touchEventUtils.js +76 -0
  180. package/lib/table/pipeline/index.js +0 -8
  181. package/lib/table/pipeline/pipeline.js +11 -60
  182. package/lib/table/pivot/cross-table/buildCrossTable.js +15 -75
  183. package/lib/table/pivot/cross-table/cross-table.js +22 -36
  184. package/lib/table/pivot/cross-table/index.js +0 -4
  185. package/lib/table/pivot/cross-tree-table/buildCrossTreeTable.js +14 -60
  186. package/lib/table/pivot/cross-tree-table/cross-tree-table.js +28 -60
  187. package/lib/table/pivot/cross-tree-table/index.js +0 -3
  188. package/lib/table/pivot/pivot-utils/buildDrillTree.js +10 -29
  189. package/lib/table/pivot/pivot-utils/builders.js +31 -82
  190. package/lib/table/pivot/pivot-utils/convert-utils.js +13 -57
  191. package/lib/table/pivot/pivot-utils/index.js +0 -7
  192. package/lib/table/pivot/pivot-utils/simpleEncode.js +0 -2
  193. package/lib/table/style/css.js +0 -1
  194. package/lib/table/style/index.js +0 -1
  195. package/lib/table/transforms/autoRowSpan.js +1 -21
  196. package/lib/table/transforms/autoWidth.js +10 -53
  197. package/lib/table/transforms/buildTree.js +1 -4
  198. package/lib/table/transforms/columnHover.js +9 -22
  199. package/lib/table/transforms/columnRangeHover.js +12 -27
  200. package/lib/table/transforms/columnResize.js +15 -56
  201. package/lib/table/transforms/flatten.js +0 -5
  202. package/lib/table/transforms/index.js +0 -12
  203. package/lib/table/transforms/orderField.js +0 -7
  204. package/lib/table/transforms/sort.js +36 -112
  205. package/lib/table/transforms/tips.js +1 -16
  206. package/lib/table/transforms/treeMode.js +30 -96
  207. package/lib/table/transforms/visible.js +0 -7
  208. package/lib/table/transforms/warnTransformsDeprecated.js +0 -4
  209. package/lib/table/use/useResizeObserver.js +1 -8
  210. package/lib/table/utils/applyTransforms.js +0 -2
  211. package/lib/table/utils/buildTree.js +4 -30
  212. package/lib/table/utils/collectNodes.js +1 -15
  213. package/lib/table/utils/console.js +0 -16
  214. package/lib/table/utils/copyToClipboard.js +0 -6
  215. package/lib/table/utils/element.js +14 -46
  216. package/lib/table/utils/exportTableAsExcel.js +4 -49
  217. package/lib/table/utils/getTreeDepth.js +1 -14
  218. package/lib/table/utils/groupBy.js +1 -14
  219. package/lib/table/utils/index.js +0 -21
  220. package/lib/table/utils/isGroupColumn.js +0 -3
  221. package/lib/table/utils/isLeafNode.js +0 -1
  222. package/lib/table/utils/layeredFilter.js +0 -10
  223. package/lib/table/utils/layeredSort.js +0 -10
  224. package/lib/table/utils/makeRecursiveMapper.js +1 -21
  225. package/lib/table/utils/mergeCellProps.js +6 -17
  226. package/lib/table/utils/others.js +3 -31
  227. package/lib/table/utils/proto.js +2 -33
  228. package/lib/table/utils/selectColumn.js +0 -1
  229. package/lib/table/utils/smartCompare.js +4 -13
  230. package/lib/table/utils/traverseColumn.js +2 -22
  231. package/lib/table/utils/tree-data-helpers/StrictTreeDataHelper.js +1 -30
  232. package/lib/table/utils/tree-data-helpers/TreeDataHelper.js +15 -82
  233. package/package.json +2 -1
@@ -0,0 +1,65 @@
1
+ // 统一获取事件坐标的函数
2
+ export function getEventCoordinates(event) {
3
+ if ('touches' in event && event.touches.length > 0) {
4
+ return {
5
+ clientX: event.touches[0].clientX,
6
+ clientY: event.touches[0].clientY
7
+ };
8
+ } else if ('changedTouches' in event && event.changedTouches.length > 0) {
9
+ return {
10
+ clientX: event.changedTouches[0].clientX,
11
+ clientY: event.changedTouches[0].clientY
12
+ };
13
+ } else {
14
+ return {
15
+ clientX: event.clientX,
16
+ clientY: event.clientY
17
+ };
18
+ }
19
+ }
20
+ // 获取事件目标元素
21
+ export function getEventTarget(event) {
22
+ if ('touches' in event && event.touches.length > 0) {
23
+ return document.elementFromPoint(event.touches[0].clientX, event.touches[0].clientY);
24
+ }
25
+ // 处理touchend事件,此时touches为空,需要使用changedTouches
26
+ if ('changedTouches' in event && event.changedTouches.length > 0) {
27
+ return document.elementFromPoint(event.changedTouches[0].clientX, event.changedTouches[0].clientY);
28
+ }
29
+ return event.target;
30
+ }
31
+ // 判断是否为触摸事件
32
+ export function isTouchEvent(event) {
33
+ return 'touches' in event;
34
+ }
35
+ // 为元素添加统一的指针事件监听器
36
+ export function addPointerEventListeners(element, handlers, isTouchStart) {
37
+ if (isTouchStart) {
38
+ element.addEventListener('touchmove', handlers.onPointerMove, {
39
+ passive: false
40
+ });
41
+ element.addEventListener('touchend', handlers.onPointerUp, {
42
+ passive: false
43
+ });
44
+ } else {
45
+ element.addEventListener('mousemove', handlers.onPointerMove);
46
+ element.addEventListener('mouseup', handlers.onPointerUp);
47
+ }
48
+ }
49
+ // 移除统一的指针事件监听器
50
+ export function removePointerEventListeners(element, handlers, isTouchStart) {
51
+ if (isTouchStart) {
52
+ element.removeEventListener('touchmove', handlers.onPointerMove);
53
+ element.removeEventListener('touchend', handlers.onPointerUp);
54
+ } else {
55
+ element.removeEventListener('mousemove', handlers.onPointerMove);
56
+ element.removeEventListener('mouseup', handlers.onPointerUp);
57
+ }
58
+ }
59
+ // 检查是否移动了足够的距离(用于区分点击和拖拽)
60
+ export function hasMovedEnough(startX, startY, endX, endY) {
61
+ var threshold = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 5;
62
+ var xDiff = endX - startX;
63
+ var yDiff = endY - startY;
64
+ return Math.sqrt(xDiff * xDiff + yDiff * yDiff) > threshold;
65
+ }
@@ -21,16 +21,13 @@ import { autoFillTableWidth, tableWidthKey } from './features/autoFill';
21
21
  *
22
22
  * 4. snapshots,调用 pipeline.snapshot(name) 可以记录当前的状态,后续可以通过 name 来读取保存的状态
23
23
  * */
24
-
25
24
  export var TablePipeline = /*#__PURE__*/function () {
26
25
  function TablePipeline(_ref) {
27
26
  var state = _ref.state,
28
- setState = _ref.setState,
29
- ctx = _ref.ctx,
30
- ref = _ref.ref;
31
-
27
+ setState = _ref.setState,
28
+ ctx = _ref.ctx,
29
+ ref = _ref.ref;
32
30
  _classCallCheck(this, TablePipeline);
33
-
34
31
  this._snapshots = {};
35
32
  this._rowPropsGetters = [];
36
33
  this._tableProps = {};
@@ -41,25 +38,21 @@ export var TablePipeline = /*#__PURE__*/function () {
41
38
  this.state = state;
42
39
  this.setState = setState;
43
40
  this.ref = ref;
44
-
45
41
  _extends(this.ctx, ctx);
46
- } // Generate a pseudo-GUID by concatenating random hexadecimal.
47
-
48
-
42
+ }
43
+ // Generate a pseudo-GUID by concatenating random hexadecimal.
49
44
  _createClass(TablePipeline, [{
50
45
  key: "guid",
51
46
  value: function guid() {
52
47
  function S4() {
53
48
  return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
54
49
  }
55
-
56
50
  return S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4();
57
51
  }
58
52
  }, {
59
53
  key: "appendRowPropsGetter",
60
54
  value: function appendRowPropsGetter(getter) {
61
55
  this._rowPropsGetters.push(getter);
62
-
63
56
  return this;
64
57
  }
65
58
  }, {
@@ -99,11 +92,9 @@ export var TablePipeline = /*#__PURE__*/function () {
99
92
  key: "getStateAtKey",
100
93
  value: function getStateAtKey(stateKey, defaultValue) {
101
94
  var _a;
102
-
103
95
  return (_a = this.state[stateKey]) !== null && _a !== void 0 ? _a : defaultValue;
104
96
  }
105
97
  /** 将 stateKey 对应的状态设置为 partialState */
106
-
107
98
  }, {
108
99
  key: "setStateAtKey",
109
100
  value: function setStateAtKey(stateKey, partialState, extraInfo) {
@@ -112,29 +103,24 @@ export var TablePipeline = /*#__PURE__*/function () {
112
103
  }, stateKey, partialState, extraInfo);
113
104
  }
114
105
  /** 确保 primaryKey 已被设置,并返回 primaryKey */
115
-
116
106
  }, {
117
107
  key: "ensurePrimaryKey",
118
108
  value: function ensurePrimaryKey(hint) {
119
109
  if (this.ctx.primaryKey == null) {
120
110
  throw new Error(hint ? "\u4F7F\u7528 ".concat(hint, " \u4E4B\u524D\u5FC5\u987B\u5148\u8BBE\u7F6E primaryKey") : '必须先设置 primaryKey');
121
111
  }
122
-
123
112
  return this.ctx.primaryKey;
124
113
  }
125
114
  /** 设置流水线的输入数据 */
126
-
127
115
  }, {
128
116
  key: "input",
129
117
  value: function input(_input) {
130
118
  var _context,
131
- _this = this;
132
-
119
+ _this = this;
133
120
  if (this._dataSource != null || this._columns != null) {
134
121
  throw new Error('input 不能调用两次');
135
- } // 在 pipeline 中识别本次更新是否有数据变化
136
-
137
-
122
+ }
123
+ // 在 pipeline 中识别本次更新是否有数据变化
138
124
  this._isSameInputDataSource = _input.dataSource === this.ref.current._lastInputDataSource;
139
125
  this._dataSource = _input.dataSource;
140
126
  this.ref.current._lastInputDataSource = _input.dataSource;
@@ -147,7 +133,6 @@ export var TablePipeline = /*#__PURE__*/function () {
147
133
  return this;
148
134
  }
149
135
  /** 设置 dataSource */
150
-
151
136
  }, {
152
137
  key: "dataSource",
153
138
  value: function dataSource(rows) {
@@ -155,7 +140,6 @@ export var TablePipeline = /*#__PURE__*/function () {
155
140
  return this;
156
141
  }
157
142
  /** 设置 columns */
158
-
159
143
  }, {
160
144
  key: "columns",
161
145
  value: function columns(cols) {
@@ -163,7 +147,6 @@ export var TablePipeline = /*#__PURE__*/function () {
163
147
  return this;
164
148
  }
165
149
  /** 设置主键 */
166
-
167
150
  }, {
168
151
  key: "primaryKey",
169
152
  value: function primaryKey(key) {
@@ -171,7 +154,6 @@ export var TablePipeline = /*#__PURE__*/function () {
171
154
  return this;
172
155
  }
173
156
  /** 设置页脚数据 */
174
-
175
157
  }, {
176
158
  key: "footerDataSource",
177
159
  value: function footerDataSource(rows) {
@@ -179,12 +161,10 @@ export var TablePipeline = /*#__PURE__*/function () {
179
161
  return this;
180
162
  }
181
163
  /** 保存快照 */
182
-
183
164
  }, {
184
165
  key: "snapshot",
185
166
  value: function snapshot(name) {
186
167
  var _context2;
187
-
188
168
  this._snapshots[name] = {
189
169
  dataSource: this._dataSource,
190
170
  columns: this._columns,
@@ -194,7 +174,6 @@ export var TablePipeline = /*#__PURE__*/function () {
194
174
  }
195
175
  /** @deprecated
196
176
  * 应用一个 kd-table Table transform */
197
-
198
177
  }, {
199
178
  key: "useTransform",
200
179
  value: function useTransform(transform) {
@@ -205,63 +184,52 @@ export var TablePipeline = /*#__PURE__*/function () {
205
184
  return this.dataSource(next.dataSource).columns(next.columns);
206
185
  }
207
186
  /** 使用 pipeline 功能拓展 */
208
-
209
187
  }, {
210
188
  key: "use",
211
189
  value: function use(step) {
212
190
  return step(this);
213
191
  }
214
192
  /** 转换 dataSource */
215
-
216
193
  }, {
217
194
  key: "mapDataSource",
218
195
  value: function mapDataSource(mapper) {
219
196
  return this.dataSource(mapper(this.getDataSource()));
220
197
  }
221
198
  /** 转换 columns */
222
-
223
199
  }, {
224
200
  key: "mapColumns",
225
201
  value: function mapColumns(mapper) {
226
202
  return this.columns(mapper(this.getColumns()));
227
203
  }
228
204
  /** 获取featureOptions 内容 */
229
-
230
205
  }, {
231
206
  key: "getFeatureOptions",
232
207
  value: function getFeatureOptions(optionKey) {
233
208
  var _a;
234
-
235
209
  return (_a = this.ref.current.featureOptions) === null || _a === void 0 ? void 0 : _a[optionKey];
236
210
  }
237
211
  /** 设置pipelineOptions 内容 */
238
-
239
212
  }, {
240
213
  key: "setFeatureOptions",
241
214
  value: function setFeatureOptions(optionKey, value) {
242
215
  this.ref.current.featureOptions[optionKey] = value;
243
216
  }
244
217
  /** 获取 BaseTable 的 props,结果中包含 dataSource/columns/primaryKey/getRowProps 四个字段 */
245
-
246
218
  }, {
247
219
  key: "getProps",
248
220
  value: function getProps() {
249
221
  var _this2 = this;
250
-
251
222
  this.use(autoFillTableWidth());
252
223
  var result = {
253
224
  dataSource: this._dataSource,
254
225
  columns: this._columns
255
226
  };
256
-
257
227
  if (this.ctx.primaryKey) {
258
228
  result.primaryKey = this.ctx.primaryKey;
259
229
  }
260
-
261
230
  if (this._footerDataSource) {
262
231
  result.footerDataSource = this._footerDataSource;
263
232
  }
264
-
265
233
  if (this._rowPropsGetters.length > 0) {
266
234
  result.getRowProps = function (row, rowIndex) {
267
235
  return _this2._rowPropsGetters.reduce(function (res, get) {
@@ -269,31 +237,24 @@ export var TablePipeline = /*#__PURE__*/function () {
269
237
  }, {});
270
238
  };
271
239
  }
272
-
273
240
  result.getTableProps = function () {
274
241
  return _this2._tableProps;
275
242
  };
276
-
277
243
  result.setTableWidth = function (tableWidth) {
278
244
  var preTableWidth = _this2.getStateAtKey(tableWidthKey);
279
-
280
245
  if (preTableWidth !== tableWidth) {
281
246
  tableWidth && _this2.setStateAtKey(tableWidthKey, tableWidth);
282
247
  }
283
248
  };
284
-
285
249
  result.setTableDomHelper = function (domHelper) {
286
250
  _this2.ref.current.domHelper = domHelper;
287
251
  };
288
-
289
252
  result.setRowHeightManager = function (rowHeightManager) {
290
253
  _this2.ref.current.rowHeightManager = rowHeightManager;
291
254
  };
292
-
293
255
  return result;
294
256
  }
295
257
  }]);
296
-
297
258
  return TablePipeline;
298
259
  }();
299
260
  TablePipeline.defaultIndents = {
@@ -304,10 +265,9 @@ TablePipeline.defaultIndents = {
304
265
  };
305
266
  export function useTablePipeline(ctx) {
306
267
  var _useState = useState({}),
307
- _useState2 = _slicedToArray(_useState, 2),
308
- state = _useState2[0],
309
- setState = _useState2[1];
310
-
268
+ _useState2 = _slicedToArray(_useState, 2),
269
+ state = _useState2[0],
270
+ setState = _useState2[1];
311
271
  var ref = useRef({
312
272
  featureOptions: {}
313
273
  });
@@ -1,43 +1,34 @@
1
1
  import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
2
2
  import _extends from "@babel/runtime-corejs3/helpers/extends";
3
3
  import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
4
-
5
4
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
6
-
7
5
  function _unsupportedIterableToArray(o, minLen) { var _context4; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context4 = Object.prototype.toString.call(o)).call(_context4, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
-
9
6
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
10
-
11
7
  import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
12
8
  import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
13
9
  import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
14
10
  import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
15
11
  import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
16
12
  import _getIteratorMethod from "@babel/runtime-corejs3/core-js/get-iterator-method";
17
-
18
13
  var __rest = this && this.__rest || function (s, e) {
19
14
  var t = {};
20
-
21
15
  for (var p in s) {
22
16
  if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
23
17
  }
24
-
25
18
  if (s != null && typeof _Object$getOwnPropertySymbols === "function") for (var i = 0, p = _Object$getOwnPropertySymbols(s); i < p.length; i++) {
26
19
  if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
27
20
  }
28
21
  return t;
29
22
  };
30
-
31
23
  import { getTreeDepth, isLeafNode } from '../../utils';
32
24
  import { ROW_KEY } from './constants';
33
25
  export default function buildCrossTable(options) {
34
26
  var _a, _b, _c;
35
-
36
27
  var leftTotalNode = options.leftTotalNode,
37
- topTotalNode = options.topTotalNode; // 有的时候 leftTree/topTree 是通过 node.children 传入的
28
+ topTotalNode = options.topTotalNode;
29
+ // 有的时候 leftTree/topTree 是通过 node.children 传入的
38
30
  // 此时 leftTree/topTree 等于 null 和等于空数组是等价的
39
31
  // 故在这里兼容 leftTree/topTree 为空的情况
40
-
41
32
  var leftTree = (_a = options.leftTree) !== null && _a !== void 0 ? _a : [];
42
33
  var topTree = (_b = options.topTree) !== null && _b !== void 0 ? _b : [];
43
34
  var leftMetaColumns = (_c = options.leftMetaColumns) !== null && _c !== void 0 ? _c : [];
@@ -47,24 +38,17 @@ export default function buildCrossTable(options) {
47
38
  dataSource: getDataSource()
48
39
  };
49
40
  /** 获取表格的列配置 */
50
-
51
41
  function getColumns() {
52
42
  var _context;
53
-
54
43
  return _concatInstanceProperty(_context = []).call(_context, _toConsumableArray(getLeftPartColumns()), _toConsumableArray(getDataPartColumns()));
55
-
56
44
  function getLeftPartColumns() {
57
45
  var _a;
58
-
59
46
  var leftPartColumns = [];
60
-
61
47
  for (var index = 0; index < leftHeaderWidth; index++) {
62
48
  var metaCol = (_a = leftMetaColumns[index]) !== null && _a !== void 0 ? _a : {};
63
-
64
49
  var getCellProps = metaCol.getCellProps,
65
- render = metaCol.render,
66
- staticMetaColConfig = __rest(metaCol, ["getCellProps", "render"]);
67
-
50
+ render = metaCol.render,
51
+ staticMetaColConfig = __rest(metaCol, ["getCellProps", "render"]);
68
52
  leftPartColumns.push(_extends(_extends({
69
53
  columnType: 'left',
70
54
  lock: true
@@ -75,48 +59,37 @@ export default function buildCrossTable(options) {
75
59
  render: leftHeaderRenderFactory(metaCol, index)
76
60
  }));
77
61
  }
78
-
79
62
  return leftPartColumns;
80
-
81
63
  function leftHeaderGetCellPropsFactory(metaCol, colIndex) {
82
64
  return function (_value, row, rowIndex) {
83
65
  var _a;
84
-
85
66
  var node = row.nodes[colIndex];
86
67
  return (_a = metaCol.getCellProps) === null || _a === void 0 ? void 0 : _a.call(metaCol, node, colIndex);
87
68
  };
88
69
  }
89
-
90
70
  function leftHeaderGetSpanRectFactory(metaCol, colIndex) {
91
71
  return function (_value, row) {
92
72
  return row.rects[colIndex];
93
73
  };
94
74
  }
95
-
96
75
  function leftHeaderGetValueFactory(metaCol, colIndex) {
97
76
  return function (row, rowIndex) {
98
77
  var node = row.nodes[colIndex];
99
78
  return node.value;
100
79
  };
101
80
  }
102
-
103
81
  function leftHeaderRenderFactory(metaCol, colIndex) {
104
82
  return function (v, row, rowIndex) {
105
83
  var _a;
106
-
107
84
  var node = row.nodes[colIndex];
108
-
109
85
  if (metaCol.render) {
110
86
  return metaCol.render(node, colIndex);
111
87
  }
112
-
113
88
  return (_a = node.title) !== null && _a !== void 0 ? _a : node.value;
114
89
  };
115
90
  }
116
91
  }
117
92
  /** 获取表格数据部分的列配置 */
118
-
119
-
120
93
  function getDataPartColumns() {
121
94
  if (topTree.length > 0) {
122
95
  return dfs(topTree, {
@@ -131,29 +104,25 @@ export default function buildCrossTable(options) {
131
104
  } else {
132
105
  return [];
133
106
  }
134
-
135
107
  function dfs(nodes, ctx) {
136
108
  var result = [];
137
-
138
109
  var _iterator = _createForOfIteratorHelper(nodes),
139
- _step;
140
-
110
+ _step;
141
111
  try {
142
112
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
143
113
  var node = _step.value;
144
114
  ctx.valuePath.push(node.value);
145
-
146
115
  if (isLeafNode(node)) {
147
116
  // 叶子节点
148
117
  result.push(getDataColumn(node, ctx.depth));
149
118
  } else {
150
119
  var key = node.key,
151
- value = node.value,
152
- children = node.children,
153
- others = __rest(node // 强制展开的节点
154
- , ["key", "value", "children"]); // 强制展开的节点
155
-
156
-
120
+ value = node.value,
121
+ children = node.children,
122
+ others = __rest(node
123
+ // 强制展开的节点
124
+ , ["key", "value", "children"]);
125
+ // 强制展开的节点
157
126
  result.push(_extends(_extends({
158
127
  columnType: 'data-parent'
159
128
  }, others), {
@@ -164,7 +133,6 @@ export default function buildCrossTable(options) {
164
133
  })
165
134
  }));
166
135
  }
167
-
168
136
  ctx.valuePath.pop();
169
137
  }
170
138
  } catch (err) {
@@ -172,23 +140,19 @@ export default function buildCrossTable(options) {
172
140
  } finally {
173
141
  _iterator.f();
174
142
  }
175
-
176
143
  return result;
177
144
  }
178
145
  }
179
-
180
146
  function getDataColumn(topNode, topDepth) {
181
147
  var columnGetValue = function columnGetValue(row) {
182
148
  var leftDepth = row.nodes.length - 1;
183
149
  var leftNode = row.nodes[leftDepth];
184
150
  return options.getValue(leftNode, topNode, leftDepth, topDepth);
185
151
  };
186
-
187
152
  var key = topNode.key,
188
- value = topNode.value,
189
- children = topNode.children,
190
- others = __rest(topNode, ["key", "value", "children"]);
191
-
153
+ value = topNode.value,
154
+ children = topNode.children,
155
+ others = __rest(topNode, ["key", "value", "children"]);
192
156
  return _extends(_extends({
193
157
  columnType: 'data'
194
158
  }, others), {
@@ -201,7 +165,6 @@ export default function buildCrossTable(options) {
201
165
  var leftNode = row.nodes[leftDepth];
202
166
  return options.render(value, leftNode, topNode, leftDepth, topDepth);
203
167
  }
204
-
205
168
  return value;
206
169
  },
207
170
  getCellProps: function getCellProps(value, row) {
@@ -214,7 +177,6 @@ export default function buildCrossTable(options) {
214
177
  });
215
178
  }
216
179
  }
217
-
218
180
  function getDataSource() {
219
181
  var flatRows = [];
220
182
  var ctx = {
@@ -223,33 +185,24 @@ export default function buildCrossTable(options) {
223
185
  rects: [],
224
186
  rowIndex: 0
225
187
  };
226
-
227
188
  if (leftTree.length > 0) {
228
189
  dfs(leftTree, ctx);
229
190
  } else if (leftTotalNode) {
230
191
  dfs([leftTotalNode], ctx);
231
192
  } // else 表格没有行,展示空表格
232
-
233
-
234
193
  return flatRows;
235
-
236
194
  function dfs(nodes, ctx) {
237
195
  var count = 0;
238
-
239
196
  var _iterator2 = _createForOfIteratorHelper(nodes),
240
- _step2;
241
-
197
+ _step2;
242
198
  try {
243
199
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
244
200
  var _context2, _context3, _row;
245
-
246
201
  var node = _step2.value;
247
-
248
202
  if (node.hidden) {
249
203
  // 跳过被隐藏的节点
250
204
  continue;
251
205
  }
252
-
253
206
  var rect = {
254
207
  top: ctx.rowIndex + count,
255
208
  bottom: -1,
@@ -257,7 +210,6 @@ export default function buildCrossTable(options) {
257
210
  right: -1
258
211
  };
259
212
  var row = (_row = {}, _defineProperty(_row, ROW_KEY, node.key), _defineProperty(_row, "rects", _concatInstanceProperty(_context2 = []).call(_context2, _toConsumableArray(ctx.rects), [rect])), _defineProperty(_row, "nodes", _concatInstanceProperty(_context3 = []).call(_context3, _toConsumableArray(ctx.nodes), [node])), _row);
260
-
261
213
  if (isLeafNode(node)) {
262
214
  rect.right = leftHeaderWidth;
263
215
  rect.bottom = rect.top + 1;
@@ -284,7 +236,6 @@ export default function buildCrossTable(options) {
284
236
  } finally {
285
237
  _iterator2.f();
286
238
  }
287
-
288
239
  return {
289
240
  count: count
290
241
  };
@@ -1,50 +1,44 @@
1
1
  import _extends from "@babel/runtime-corejs3/helpers/extends";
2
2
  import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
3
-
4
3
  var __rest = this && this.__rest || function (s, e) {
5
4
  var t = {};
6
-
7
5
  for (var p in s) {
8
6
  if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
9
7
  }
10
-
11
8
  if (s != null && typeof _Object$getOwnPropertySymbols === "function") for (var i = 0, p = _Object$getOwnPropertySymbols(s); i < p.length; i++) {
12
9
  if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
13
10
  }
14
11
  return t;
15
12
  };
16
-
17
13
  import React from 'react';
18
14
  import { Table } from '../../base';
19
15
  import buildCrossTable from './buildCrossTable';
20
16
  import { ROW_KEY } from './constants';
21
17
  export default (function CrossTable(_a) {
22
18
  var _a$BaseTableComponent = _a.BaseTableComponent,
23
- BaseTableComponent = _a$BaseTableComponent === void 0 ? Table : _a$BaseTableComponent,
24
- leftTree = _a.leftTree,
25
- leftTotalNode = _a.leftTotalNode,
26
- topTree = _a.topTree,
27
- topTotalNode = _a.topTotalNode,
28
- getValue = _a.getValue,
29
- getCellProps = _a.getCellProps,
30
- leftMetaColumns = _a.leftMetaColumns,
31
- render = _a.render,
32
- baseTableRef = _a.baseTableRef,
33
- others = __rest(_a, ["BaseTableComponent", "leftTree", "leftTotalNode", "topTree", "topTotalNode", "getValue", "getCellProps", "leftMetaColumns", "render", "baseTableRef"]);
34
-
19
+ BaseTableComponent = _a$BaseTableComponent === void 0 ? Table : _a$BaseTableComponent,
20
+ leftTree = _a.leftTree,
21
+ leftTotalNode = _a.leftTotalNode,
22
+ topTree = _a.topTree,
23
+ topTotalNode = _a.topTotalNode,
24
+ getValue = _a.getValue,
25
+ getCellProps = _a.getCellProps,
26
+ leftMetaColumns = _a.leftMetaColumns,
27
+ render = _a.render,
28
+ baseTableRef = _a.baseTableRef,
29
+ others = __rest(_a, ["BaseTableComponent", "leftTree", "leftTotalNode", "topTree", "topTotalNode", "getValue", "getCellProps", "leftMetaColumns", "render", "baseTableRef"]);
35
30
  var _buildCrossTable = buildCrossTable({
36
- leftTree: leftTree,
37
- topTree: topTree,
38
- leftTotalNode: leftTotalNode,
39
- topTotalNode: topTotalNode,
40
- getValue: getValue,
41
- getCellProps: getCellProps,
42
- render: render,
43
- leftMetaColumns: leftMetaColumns
44
- }),
45
- dataSource = _buildCrossTable.dataSource,
46
- columns = _buildCrossTable.columns;
47
-
31
+ leftTree: leftTree,
32
+ topTree: topTree,
33
+ leftTotalNode: leftTotalNode,
34
+ topTotalNode: topTotalNode,
35
+ getValue: getValue,
36
+ getCellProps: getCellProps,
37
+ render: render,
38
+ leftMetaColumns: leftMetaColumns
39
+ }),
40
+ dataSource = _buildCrossTable.dataSource,
41
+ columns = _buildCrossTable.columns;
48
42
  return /*#__PURE__*/React.createElement(BaseTableComponent, _extends({
49
43
  ref: baseTableRef
50
44
  }, others, {