@hi-ui/table 4.0.13 → 4.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/lib/cjs/BaseTable.js +7 -4
  3. package/lib/cjs/Table.js +19 -6
  4. package/lib/cjs/TableBody.js +83 -2
  5. package/lib/cjs/TableCell.js +42 -1
  6. package/lib/cjs/TableRow.js +42 -2
  7. package/lib/cjs/_virtual/index.js +18 -0
  8. package/lib/cjs/_virtual/index2.js +18 -0
  9. package/lib/cjs/_virtual/react-is.development.js +16 -0
  10. package/lib/cjs/_virtual/react-is.production.min.js +16 -0
  11. package/lib/cjs/hooks/use-check.js +28 -4
  12. package/lib/cjs/hooks/use-col-width.js +37 -8
  13. package/lib/cjs/hooks/use-pagination.js +51 -9
  14. package/lib/cjs/node_modules/classnames/index.js +76 -0
  15. package/lib/cjs/node_modules/rc-resize-observer/es/index.js +236 -0
  16. package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/Children/toArray.js +51 -0
  17. package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/Dom/findDOMNode.js +40 -0
  18. package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/ref.js +77 -0
  19. package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/warning.js +42 -0
  20. package/lib/cjs/node_modules/rc-util/es/Dom/canUseDom.js +20 -0
  21. package/lib/cjs/node_modules/rc-util/es/Dom/findDOMNode.js +40 -0
  22. package/lib/cjs/node_modules/rc-util/es/hooks/useLayoutEffect.js +49 -0
  23. package/lib/cjs/node_modules/rc-util/es/raf.js +72 -0
  24. package/lib/cjs/node_modules/rc-virtual-list/es/Filler.js +135 -0
  25. package/lib/cjs/node_modules/rc-virtual-list/es/Item.js +53 -0
  26. package/lib/cjs/node_modules/rc-virtual-list/es/List.js +550 -0
  27. package/lib/cjs/node_modules/rc-virtual-list/es/ScrollBar.js +431 -0
  28. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useChildren.js +60 -0
  29. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useDiffItem.js +129 -0
  30. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js +64 -0
  31. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useHeights.js +182 -0
  32. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js +93 -0
  33. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useOriginScroll.js +56 -0
  34. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useScrollTo.js +154 -0
  35. package/lib/cjs/node_modules/rc-virtual-list/es/index.js +18 -0
  36. package/lib/cjs/node_modules/rc-virtual-list/es/utils/CacheMap.js +65 -0
  37. package/lib/cjs/node_modules/rc-virtual-list/es/utils/algorithmUtil.js +85 -0
  38. package/lib/cjs/node_modules/rc-virtual-list/es/utils/isFirefox.js +27 -0
  39. package/lib/cjs/node_modules/react-is/cjs/react-is.development.js +208 -0
  40. package/lib/cjs/node_modules/react-is/cjs/react-is.production.min.js +158 -0
  41. package/lib/cjs/node_modules/react-is/index.js +26 -0
  42. package/lib/cjs/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +1127 -0
  43. package/lib/cjs/styles/index.scss.js +1 -1
  44. package/lib/cjs/use-table.js +4 -2
  45. package/lib/esm/BaseTable.js +24 -21
  46. package/lib/esm/Table.js +28 -15
  47. package/lib/esm/TableAdvancedFilter.js +13 -13
  48. package/lib/esm/TableBody.js +95 -15
  49. package/lib/esm/TableCell.js +50 -9
  50. package/lib/esm/TableColumnMenu.js +16 -16
  51. package/lib/esm/TableEmbedRow.js +4 -4
  52. package/lib/esm/TableHeader.js +10 -10
  53. package/lib/esm/TableRow.js +53 -13
  54. package/lib/esm/TableSettingMenu.js +14 -14
  55. package/lib/esm/_virtual/index.js +13 -0
  56. package/lib/esm/_virtual/index2.js +13 -0
  57. package/lib/esm/_virtual/react-is.development.js +11 -0
  58. package/lib/esm/_virtual/react-is.production.min.js +11 -0
  59. package/lib/esm/hooks/use-check.js +32 -8
  60. package/lib/esm/hooks/use-col-width.js +44 -15
  61. package/lib/esm/hooks/use-colgroup.js +4 -4
  62. package/lib/esm/hooks/use-drag.js +2 -2
  63. package/lib/esm/hooks/use-embed-expand.js +2 -2
  64. package/lib/esm/hooks/use-pagination.js +51 -10
  65. package/lib/esm/icons/index.js +5 -5
  66. package/lib/esm/node_modules/classnames/index.js +69 -0
  67. package/lib/esm/node_modules/rc-resize-observer/es/index.js +177 -0
  68. package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/Children/toArray.js +33 -0
  69. package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/Dom/findDOMNode.js +23 -0
  70. package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/ref.js +57 -0
  71. package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/warning.js +34 -0
  72. package/lib/esm/node_modules/rc-util/es/Dom/canUseDom.js +14 -0
  73. package/lib/esm/node_modules/rc-util/es/Dom/findDOMNode.js +23 -0
  74. package/lib/esm/node_modules/rc-util/es/hooks/useLayoutEffect.js +17 -0
  75. package/lib/esm/node_modules/rc-util/es/raf.js +66 -0
  76. package/lib/esm/node_modules/rc-virtual-list/es/Filler.js +103 -0
  77. package/lib/esm/node_modules/rc-virtual-list/es/Item.js +23 -0
  78. package/lib/esm/node_modules/rc-virtual-list/es/List.js +508 -0
  79. package/lib/esm/node_modules/rc-virtual-list/es/ScrollBar.js +399 -0
  80. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useChildren.js +29 -0
  81. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useDiffItem.js +98 -0
  82. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js +55 -0
  83. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useHeights.js +150 -0
  84. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js +85 -0
  85. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useOriginScroll.js +50 -0
  86. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useScrollTo.js +123 -0
  87. package/lib/esm/node_modules/rc-virtual-list/es/index.js +11 -0
  88. package/lib/esm/node_modules/rc-virtual-list/es/utils/CacheMap.js +59 -0
  89. package/lib/esm/node_modules/rc-virtual-list/es/utils/algorithmUtil.js +80 -0
  90. package/lib/esm/node_modules/rc-virtual-list/es/utils/isFirefox.js +21 -0
  91. package/lib/esm/node_modules/react-is/cjs/react-is.development.js +200 -0
  92. package/lib/esm/node_modules/react-is/cjs/react-is.production.min.js +151 -0
  93. package/lib/esm/node_modules/react-is/index.js +20 -0
  94. package/lib/esm/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +1122 -0
  95. package/lib/esm/styles/index.scss.js +1 -1
  96. package/lib/esm/use-table.js +12 -10
  97. package/lib/types/Table.d.ts +1 -1
  98. package/lib/types/TableCell.d.ts +4 -0
  99. package/lib/types/context.d.ts +2 -0
  100. package/lib/types/hooks/use-check.d.ts +1 -1
  101. package/lib/types/hooks/use-col-width.d.ts +2 -1
  102. package/lib/types/hooks/use-pagination.d.ts +7 -2
  103. package/lib/types/types.d.ts +7 -3
  104. package/lib/types/use-table.d.ts +14 -1
  105. package/package.json +5 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @hi-ui/table
2
2
 
3
+ ## 4.1.0-beta.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 优化 setting 设置
8
+
9
+ ## 4.1.0-beta.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 094ff4861: rowSelection onChange 回调增加已选数据集合参数
14
+ - 增加虚拟滚动功能
15
+ - f74da3dc8: 增加 dataSource 功能
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+ - Updated dependencies
21
+ - @hi-ui/spinner@4.0.5-beta.0
22
+ - @hi-ui/loading@4.1.0-beta.0
23
+ - @hi-ui/select@4.0.10-beta.0
24
+ - @hi-ui/pagination@4.0.9-beta.0
25
+
3
26
  ## 4.0.13
4
27
 
5
28
  ### Patch Changes
@@ -92,7 +92,8 @@ var BaseTable = /*#__PURE__*/React.forwardRef(function (_a, ref) {
92
92
  _a$fixedColumnTrigger = _a.fixedColumnTrigger,
93
93
  fixedColumnTrigger = _a$fixedColumnTrigger === void 0 ? 'auto' : _a$fixedColumnTrigger,
94
94
  emptyContent = _a.emptyContent,
95
- rest = tslib.__rest(_a, ["prefixCls", "role", "className", "columns", "data", "striped", "bordered", "rowExpandable", "defaultExpandedEmbedRowKeys", "expandedEmbedRowKeys", "onEmbedExpand", "expandedRender", "size", "extra", "onRow", "onHeaderRow", "stickyFooter", "stickyFooterBottom", "fixedColumnTrigger", "emptyContent"]);
95
+ virtual = _a.virtual,
96
+ rest = tslib.__rest(_a, ["prefixCls", "role", "className", "columns", "data", "striped", "bordered", "rowExpandable", "defaultExpandedEmbedRowKeys", "expandedEmbedRowKeys", "onEmbedExpand", "expandedRender", "size", "extra", "onRow", "onHeaderRow", "stickyFooter", "stickyFooterBottom", "fixedColumnTrigger", "emptyContent", "virtual"]);
96
97
 
97
98
  var _useEmbedExpand = useEmbedExpand.useEmbedExpand({
98
99
  defaultExpandedEmbedRowKeys: defaultExpandedEmbedRowKeys,
@@ -192,7 +193,8 @@ var BaseTable = /*#__PURE__*/React.forwardRef(function (_a, ref) {
192
193
  });
193
194
  var providedValue = useTable.useTable(Object.assign(Object.assign({}, rest), {
194
195
  columns: mergedColumns,
195
- data: data
196
+ data: data,
197
+ virtual: virtual
196
198
  }));
197
199
  var rootProps = providedValue.rootProps,
198
200
  bordered = providedValue.bordered,
@@ -206,7 +208,7 @@ var BaseTable = /*#__PURE__*/React.forwardRef(function (_a, ref) {
206
208
  var extraHeader = extra && extra.header;
207
209
  var extraFooter = extra && extra.footer;
208
210
  var alwaysFixedColumn = fixedColumnTrigger === 'always';
209
- var cls = classname.cx(prefixCls, className, hasBorder && prefixCls + "--bordered", striped && prefixCls + "--striped", size && prefixCls + "--size-" + size);
211
+ var cls = classname.cx(prefixCls, className, hasBorder && prefixCls + "--bordered", striped && prefixCls + "--striped", size && prefixCls + "--size-" + size, virtual && prefixCls + "--virtual");
210
212
  return /*#__PURE__*/React__default["default"].createElement("div", Object.assign({
211
213
  ref: ref,
212
214
  role: role,
@@ -226,7 +228,8 @@ var BaseTable = /*#__PURE__*/React.forwardRef(function (_a, ref) {
226
228
  avgRow: avgRow,
227
229
  hasAvgColumn: hasAvgColumn,
228
230
  sumRow: sumRow,
229
- hasSumColumn: hasSumColumn
231
+ hasSumColumn: hasSumColumn,
232
+ virtual: virtual
230
233
  })
231
234
  }, /*#__PURE__*/React__default["default"].createElement("div", Object.assign({}, getTableHeaderProps()), /*#__PURE__*/React__default["default"].createElement(TableHeader.TableHeader, {
232
235
  prefixCls: prefixCls + "-header"
package/lib/cjs/Table.js CHANGED
@@ -89,7 +89,7 @@ var Table = /*#__PURE__*/React.forwardRef(function (_a, ref) {
89
89
  _a$standard = _a.standard,
90
90
  standard = _a$standard === void 0 ? false : _a$standard,
91
91
  _a$loading = _a.loading,
92
- loading = _a$loading === void 0 ? false : _a$loading,
92
+ loadingProp = _a$loading === void 0 ? false : _a$loading,
93
93
  dataSource = _a.dataSource,
94
94
  paginationProp = _a.pagination,
95
95
  uniqueId = _a.uniqueId,
@@ -104,7 +104,8 @@ var Table = /*#__PURE__*/React.forwardRef(function (_a, ref) {
104
104
  extra = _a.extra,
105
105
  _a$data = _a.data,
106
106
  data = _a$data === void 0 ? DEFAULT_DATA : _a$data,
107
- rest = tslib.__rest(_a, ["prefixCls", "standard", "loading", "dataSource", "pagination", "uniqueId", "columns", "hiddenColKeys", "onHiddenColKeysChange", "sortedColKeys", "onSortedColKeysChange", "rowSelection", "fieldKey", "extra", "data"]);
107
+ virtual = _a.virtual,
108
+ rest = tslib.__rest(_a, ["prefixCls", "standard", "loading", "dataSource", "pagination", "uniqueId", "columns", "hiddenColKeys", "onHiddenColKeysChange", "sortedColKeys", "onSortedColKeysChange", "rowSelection", "fieldKey", "extra", "data", "virtual"]);
108
109
 
109
110
  var tableProps = reactUtils.withDefaultProps(rest, standard ? STANDARD_PRESET : undefined);
110
111
 
@@ -156,15 +157,24 @@ var Table = /*#__PURE__*/React.forwardRef(function (_a, ref) {
156
157
  */
157
158
 
158
159
  var _useTablePagination = usePagination.useTablePagination({
160
+ loadingProp: loadingProp,
159
161
  pagination: pagination,
160
162
  data: data,
161
163
  dataSource: dataSource
162
164
  }),
165
+ loading = _useTablePagination.loading,
163
166
  mergedData = _useTablePagination.mergedData,
164
167
  currentPage = _useTablePagination.currentPage,
165
- trySetCurrentPage = _useTablePagination.trySetCurrentPage; // 优化数据在第一页且数据一页内时,不展示 pagination 配置项
168
+ trySetCurrentPage = _useTablePagination.trySetCurrentPage,
169
+ pageSize = _useTablePagination.pageSize,
170
+ trySetPageSize = _useTablePagination.trySetPageSize,
171
+ total = _useTablePagination.total; // 可能是从 dataSource 中拿到的 total 值,在此更新该值
166
172
 
167
173
 
174
+ pagination = Object.assign(Object.assign({}, pagination), {
175
+ total: total
176
+ }); // 优化数据在第一页且数据一页内时,不展示 pagination 配置项
177
+
168
178
  var hiddenPagination = !paginationProp || pagination.autoHide && currentPage === 1 && typeof pagination.pageSize === 'number' && typeof pagination.total === 'number' && pagination.total <= pagination.pageSize && data.length <= pagination.pageSize; // 获取 key 字段值
169
179
 
170
180
  var getRowKeyField = React.useCallback(function (item) {
@@ -300,6 +310,7 @@ var Table = /*#__PURE__*/React.forwardRef(function (_a, ref) {
300
310
  columns: mergedColumns,
301
311
  data: mergedData,
302
312
  fieldKey: fieldKey,
313
+ virtual: virtual,
303
314
  extra: Object.assign({
304
315
  header: setting ? /*#__PURE__*/React__default["default"].createElement(TableSettingMenu.TableSettingMenu, {
305
316
  prefixCls: prefixCls + "-setting",
@@ -314,12 +325,14 @@ var Table = /*#__PURE__*/React.forwardRef(function (_a, ref) {
314
325
  cacheHiddenColKeys: cacheHiddenColKeys,
315
326
  setCacheHiddenColKeys: setCacheHiddenColKeys
316
327
  }) : null,
317
- footer: hiddenPagination ? null : /*#__PURE__*/React__default["default"].createElement(Pagination__default["default"], Object.assign({
328
+ footer: dataSource || !hiddenPagination ? /*#__PURE__*/React__default["default"].createElement(Pagination__default["default"], Object.assign({
318
329
  className: classname.cx(prefixCls + "-pagination", pagination.placement && prefixCls + "-pagination--placement-" + pagination.placement)
319
330
  }, pagination, {
320
331
  current: currentPage,
321
- onChange: trySetCurrentPage
322
- }))
332
+ onChange: trySetCurrentPage,
333
+ pageSize: pageSize,
334
+ onPageSizeChange: trySetPageSize
335
+ })) : null
323
336
  }, extra)
324
337
  })));
325
338
  });
@@ -17,6 +17,8 @@ Object.defineProperty(exports, '__esModule', {
17
17
 
18
18
  var React = require('react');
19
19
 
20
+ var List = require('./node_modules/rc-virtual-list/es/List.js');
21
+
20
22
  var classname = require('@hi-ui/classname');
21
23
 
22
24
  var env = require('@hi-ui/env');
@@ -68,7 +70,9 @@ var TableBody = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
68
70
  hasAvgColumn = _useTableContext.hasAvgColumn,
69
71
  avgRow = _useTableContext.avgRow,
70
72
  hasSumColumn = _useTableContext.hasSumColumn,
71
- sumRow = _useTableContext.sumRow;
73
+ sumRow = _useTableContext.sumRow,
74
+ colWidths = _useTableContext.colWidths,
75
+ virtual = _useTableContext.virtual;
72
76
 
73
77
  var cls = classname.cx(prefixCls + "-body");
74
78
  var getRequiredProps = useLatest.useLatestCallback(function (id) {
@@ -81,7 +85,84 @@ var TableBody = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
81
85
  // focused: focusedId === id,
82
86
 
83
87
  };
84
- }); // 外层增加 div 作为滚动容器
88
+ });
89
+
90
+ var _useState = React.useState(0),
91
+ scrollLeft = _useState[0],
92
+ setScrollLeft = _useState[1]; // 是否使用虚拟滚动
93
+
94
+
95
+ var showVirtual = virtual && typeAssertion.isArrayNonEmpty(transitionData);
96
+ var rowWidth = React.useMemo(function () {
97
+ var tmpWidth = 0;
98
+ colWidths.forEach(function (width) {
99
+ return tmpWidth += width;
100
+ });
101
+ return tmpWidth;
102
+ }, [colWidths]);
103
+ var onVirtualContainerScroll = React.useCallback(function (evt) {
104
+ var _a;
105
+
106
+ setScrollLeft(((_a = scrollBodyElementRef === null || scrollBodyElementRef === void 0 ? void 0 : scrollBodyElementRef.current) === null || _a === void 0 ? void 0 : _a.scrollLeft) || 0);
107
+ onTableBodyScroll(evt);
108
+ }, [scrollBodyElementRef, onTableBodyScroll]);
109
+
110
+ if (showVirtual) {
111
+ // TODO: avg和summay row的逻辑
112
+ var vMaxHeight = maxHeight || 300;
113
+ return /*#__PURE__*/React__default["default"].createElement("div", {
114
+ ref: scrollBodyElementRef,
115
+ className: cls,
116
+ onScroll: onVirtualContainerScroll,
117
+ style: {
118
+ maxHeight: maxHeight !== undefined ? maxHeight : undefined,
119
+ // maxHeight 小于 table 实际高度才出现纵向滚动条
120
+ overflowY: maxHeight !== undefined && bodyTableRef.current && bodyTableRef.current.clientHeight > maxHeight ? 'scroll' : undefined,
121
+ // 表格宽度大于div宽度才出现横向滚动条
122
+ overflowX: canScroll ? 'scroll' : undefined
123
+ }
124
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
125
+ ref: measureRowElementRef,
126
+ style: {
127
+ height: 1,
128
+ background: 'transparent'
129
+ }
130
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
131
+ ref: bodyTableRef,
132
+ style: {
133
+ height: 1,
134
+ background: 'transparent',
135
+ width: rowWidth
136
+ }
137
+ }), /*#__PURE__*/React__default["default"].createElement("div", {
138
+ style: {
139
+ width: '100%',
140
+ position: 'sticky',
141
+ left: 0
142
+ }
143
+ }, /*#__PURE__*/React__default["default"].createElement(List["default"], {
144
+ data: transitionData,
145
+ height: vMaxHeight,
146
+ itemHeight: 10,
147
+ itemKey: "id",
148
+ children: function children(row, index) {
149
+ return /*#__PURE__*/React__default["default"].createElement("div", {
150
+ style: {
151
+ position: 'relative',
152
+ left: -scrollLeft
153
+ }
154
+ }, /*#__PURE__*/React__default["default"].createElement(TableRow.TableRow // key={depth + index}
155
+ , Object.assign({
156
+ // key={depth + index}
157
+ key: row.id,
158
+ // @ts-ignore
159
+ rowIndex: index,
160
+ rowData: row
161
+ }, getRequiredProps(row.id))));
162
+ }
163
+ })));
164
+ } // 外层增加 div 作为滚动容器
165
+
85
166
 
86
167
  return /*#__PURE__*/React__default["default"].createElement("div", {
87
168
  ref: scrollBodyElementRef,
@@ -54,6 +54,7 @@ var TableCell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
54
54
  column = _ref.column,
55
55
  rowData = _ref.rowData,
56
56
  rowIndex = _ref.rowIndex,
57
+ colIndex = _ref.colIndex,
57
58
  _ref$isSwitcherCol = _ref.isSwitcherCol,
58
59
  isSwitcherCol = _ref$isSwitcherCol === void 0 ? false : _ref$isSwitcherCol,
59
60
  _ref$expandedTree = _ref.expandedTree,
@@ -76,7 +77,9 @@ var TableCell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
76
77
  canScroll = _useTableContext.canScroll,
77
78
  isTree = _useTableContext.isTree,
78
79
  cellRender = _useTableContext.cellRender,
79
- isLoadingTreeNodeId = _useTableContext.isLoadingTreeNodeId;
80
+ isLoadingTreeNodeId = _useTableContext.isLoadingTreeNodeId,
81
+ colWidths = _useTableContext.colWidths,
82
+ virtual = _useTableContext.virtual;
80
83
 
81
84
  var dataKey = column.id,
82
85
  leftStickyWidth = column.leftStickyWidth,
@@ -122,6 +125,44 @@ var TableCell = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
122
125
  var loading = isLoadingTreeNodeId(rowId);
123
126
  var sticky = typeof rightStickyWidth !== 'undefined' || typeof leftStickyWidth !== 'undefined';
124
127
  var cls = classname.cx(prefixCls, className, raw.className, canScroll && sticky && prefixCls + "__col--sticky", isHighlightedCol(dataKey) && prefixCls + "__col--highlight", isHoveredHighlightCol(dataKey) && prefixCls + "__col--hovered-highlight");
128
+
129
+ if (virtual) {
130
+ var width = colWidths[colIndex];
131
+ var colProps = getStickyColProps(column);
132
+ return /*#__PURE__*/React__default["default"].createElement("div", Object.assign({
133
+ ref: ref,
134
+ key: dataKey,
135
+ className: cls
136
+ }, colProps, {
137
+ // 按需绑定函数,避免频繁调用 setState 特别消耗性能
138
+ onMouseEnter: showColHighlight ? function () {
139
+ return onHoveredColChange(column, true);
140
+ } : undefined,
141
+ onMouseLeave: showColHighlight ? function () {
142
+ return onHoveredColChange(column, false);
143
+ } : undefined,
144
+ style: Object.assign(Object.assign({}, colProps.style), {
145
+ width: width
146
+ })
147
+ }), isSwitcherCol && depth > 0 ? renderIndent({
148
+ depth: depth,
149
+ prefixCls: prefixCls
150
+ }) : null, isSwitcherCol ? renderSwitcher({
151
+ prefixCls: prefixCls,
152
+ node: rowData,
153
+ loading: loading,
154
+ expanded: expandedTree,
155
+ expandedIcon: expandedIcon,
156
+ collapsedIcon: collapsedIcon,
157
+ leafIcon: leafIcon,
158
+ onLoadChildren: onLoadChildren,
159
+ isTree: isTree,
160
+ onNodeExpand: function onNodeExpand(shouldExpanded) {
161
+ return onTreeNodeSwitch(rowData, shouldExpanded);
162
+ }
163
+ }) : null, cellContent.children);
164
+ }
165
+
125
166
  return /*#__PURE__*/React__default["default"].createElement("td", Object.assign({
126
167
  ref: ref,
127
168
  key: dataKey,
@@ -78,7 +78,9 @@ var TableRow = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
78
78
  onDragEndContext = _useTableContext.onDragEnd,
79
79
  onDropContext = _useTableContext.onDrop,
80
80
  dragRowRef = _useTableContext.dragRowRef,
81
- onRow = _useTableContext.onRow;
81
+ onRow = _useTableContext.onRow,
82
+ colWidths = _useTableContext.colWidths,
83
+ virtual = _useTableContext.virtual;
82
84
 
83
85
  var rowData = rowDataProp.raw,
84
86
  rowId = rowDataProp.id; // ** ************** 拖拽管理 *************** *//
@@ -170,11 +172,48 @@ var TableRow = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
170
172
 
171
173
  var highlighted = isHighlightedRow(rowId);
172
174
  var hasError = isErrorRow(rowId);
173
- var cls = classname.cx(prefixCls + "-row", showRowHighlight && prefixCls + "-row--hover", striped && (rowIndex & 1) === 1 && prefixCls + "-row--striped", hasError && prefixCls + "-row--error", highlighted && prefixCls + "-row--highlight", draggable && prefixCls + "-row--draggable", draggable && dragging && prefixCls + "-row--dragging", draggable && dragDirection && prefixCls + "-row--drag-" + dragDirection, isSumRow && prefixCls + "-row--total", isAvgRow && prefixCls + "-row--avg");
175
+ var cls = classname.cx(prefixCls + "-row", showRowHighlight && prefixCls + "-row--hover", striped && (rowIndex & 1) === 1 && prefixCls + "-row--striped", hasError && prefixCls + "-row--error", highlighted && prefixCls + "-row--highlight", draggable && prefixCls + "-row--draggable", draggable && dragging && prefixCls + "-row--dragging", draggable && dragDirection && prefixCls + "-row--drag-" + dragDirection, isSumRow && prefixCls + "-row--total", isAvgRow && prefixCls + "-row--avg", virtual && prefixCls + "-row--virtual");
174
176
  var firstColumn = flattedColumnsWithoutChildren.find(function (item) {
175
177
  return item.dataKey !== Table.SELECTION_DATA_KEY && item.dataKey !== BaseTable.EMBED_DATA_KEY;
176
178
  });
177
179
  var rowExtraProps = typeAssertion.isFunction(onRow) ? onRow(isSumRow || isAvgRow ? null : rowData, rowIndex) : EMBED_ON_ROW_PROPS;
180
+ var rowWidth = React.useMemo(function () {
181
+ var tmpWidth = 0;
182
+ colWidths.forEach(function (width) {
183
+ return tmpWidth += width;
184
+ });
185
+ return tmpWidth;
186
+ }, [colWidths]);
187
+
188
+ if (virtual) {
189
+ return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", Object.assign({
190
+ ref: ref,
191
+ className: cls,
192
+ key: "row"
193
+ }, rowExtraProps, {
194
+ onDoubleClick: function onDoubleClick(evt) {
195
+ if (rowExtraProps.onDoubleClick) {
196
+ rowExtraProps.onDoubleClick(evt);
197
+ }
198
+
199
+ onHighlightedRowChange(rowDataProp, !highlighted);
200
+ },
201
+ style: Object.assign(Object.assign({}, rowExtraProps.style), {
202
+ width: rowWidth
203
+ })
204
+ }), flattedColumnsWithoutChildren.map(function (column, idx) {
205
+ return /*#__PURE__*/React__default["default"].createElement(TableCell.TableCell, {
206
+ key: idx,
207
+ column: column,
208
+ isSwitcherCol: firstColumn ? firstColumn.id === column.id : false,
209
+ rowData: rowDataProp,
210
+ rowIndex: rowIndex,
211
+ colIndex: idx,
212
+ expandedTree: expandedTree
213
+ });
214
+ })));
215
+ }
216
+
178
217
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("tr", Object.assign({
179
218
  ref: ref,
180
219
  className: cls,
@@ -200,6 +239,7 @@ var TableRow = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
200
239
  isSwitcherCol: firstColumn ? firstColumn.id === column.id : false,
201
240
  rowData: rowDataProp,
202
241
  rowIndex: rowIndex,
242
+ colIndex: idx,
203
243
  expandedTree: expandedTree
204
244
  });
205
245
  })), embedExpandable ? /*#__PURE__*/React__default["default"].createElement(TableEmbedRow.TableEmbedRow, {
@@ -0,0 +1,18 @@
1
+ /** @LICENSE
2
+ * @hi-ui/table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var classnames = {
16
+ exports: {}
17
+ };
18
+ exports.classnames = classnames;
@@ -0,0 +1,18 @@
1
+ /** @LICENSE
2
+ * @hi-ui/table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var reactIs = {
16
+ exports: {}
17
+ };
18
+ exports.reactIs = reactIs;
@@ -0,0 +1,16 @@
1
+ /** @LICENSE
2
+ * @hi-ui/table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var reactIs_development = {};
16
+ exports.__exports = reactIs_development;
@@ -0,0 +1,16 @@
1
+ /** @LICENSE
2
+ * @hi-ui/table
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', {
13
+ value: true
14
+ });
15
+ var reactIs_production_min = {};
16
+ exports.__exports = reactIs_production_min;
@@ -42,17 +42,41 @@ var useTableCheck = function useTableCheck(_ref) {
42
42
 
43
43
  var _useUncontrolledState = useUncontrolledState.useUncontrolledState(DEFAULT_CHECKED_ROW_KEYS, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.onChange),
44
44
  checkedRowKeys = _useUncontrolledState[0],
45
- trySetCheckedRowKeys = _useUncontrolledState[1]; // TODO: 暂时不支持正反选
45
+ trySetCheckedRowKeys = _useUncontrolledState[1]; // 已选中的行数据集合
46
46
 
47
47
 
48
+ var checkedRowDataItemsRef = React__default["default"].useRef([]);
49
+ var checkedRowDataItems = checkedRowDataItemsRef.current; // TODO: 暂时不支持正反选
50
+
48
51
  var _useCheck = useCheck.useCheck({
49
52
  checkedIds: checkedRowKeys,
50
- onCheck: trySetCheckedRowKeys,
53
+ onCheck: function onCheck(checkedRowKeys, rowItem, checked) {
54
+ trySetCheckedRowKeys(checkedRowKeys, rowItem, checked, checkedRowDataItemsRef.current);
55
+ },
51
56
  idFieldName: fieldKey
52
57
  }),
53
- onCheckedRowKeysChange = _useCheck[0],
54
- isCheckedRowKey = _useCheck[1]; // 判断是否全选
58
+ handleCheckedRowKeysChange = _useCheck[0],
59
+ isCheckedRowKey = _useCheck[1]; // 选中项变化会触发该函数
60
+
61
+
62
+ var onCheckedRowKeysChange = React__default["default"].useCallback(function (rowItem, checked) {
63
+ // 记录选中的行数据集合
64
+ var nextCheckedDataItems = checkedRowDataItems;
65
+
66
+ if (checked) {
67
+ if (!nextCheckedDataItems.find(function (item) {
68
+ return item[fieldKey] === rowItem[fieldKey];
69
+ })) {
70
+ checkedRowDataItemsRef.current = nextCheckedDataItems.concat(rowItem);
71
+ }
72
+ } else {
73
+ checkedRowDataItemsRef.current = nextCheckedDataItems.filter(function (item) {
74
+ return item[fieldKey] !== rowItem[fieldKey];
75
+ });
76
+ }
55
77
 
78
+ handleCheckedRowKeysChange(rowItem, checked);
79
+ }, [checkedRowDataItems, fieldKey, handleCheckedRowKeysChange]); // 判断是否全选
56
80
 
57
81
  var _React$useMemo = React__default["default"].useMemo(function () {
58
82
  if (rowSelection) {
@@ -30,7 +30,8 @@ function _interopDefaultLegacy(e) {
30
30
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
31
31
 
32
32
  var useColWidth = function useColWidth(_ref) {
33
- var columns = _ref.columns;
33
+ var columns = _ref.columns,
34
+ virtual = _ref.virtual;
34
35
  var measureRowElementRef = React.useRef(null);
35
36
 
36
37
  var _React$useState = React__default["default"].useState(function () {
@@ -39,6 +40,10 @@ var useColWidth = function useColWidth(_ref) {
39
40
  colWidths = _React$useState[0],
40
41
  setColWidths = _React$useState[1];
41
42
 
43
+ console.error({
44
+ useColWidth: 1,
45
+ colWidths: colWidths
46
+ });
42
47
  useUpdateEffect.useUpdateEffect(function () {
43
48
  setColWidths(index.getGroupItemWidth(columns));
44
49
  }, [columns]);
@@ -51,15 +56,39 @@ var useColWidth = function useColWidth(_ref) {
51
56
 
52
57
  if (measureRowElement) {
53
58
  var _resizeObserver = new ResizeObserver(function () {
54
- if (measureRowElement.childNodes) {
55
- var _realColumnsWidth = Array.from(measureRowElement.childNodes).map(function (node) {
56
- return node.getBoundingClientRect().width || 0;
59
+ if (virtual) {
60
+ /** 虚拟滚动时,内容宽度不能用以前table自动渲染的方式获取,需要手动计算 */
61
+ var columnDefaultWidth = 200;
62
+ var containerWidth = measureRowElement.clientWidth;
63
+ var totalWidth = 0;
64
+ /** 虚拟滚动,需要根据collist的虚拟宽度来计算宽度 */
65
+
66
+ columns.forEach(function (columnItem) {
67
+ totalWidth += columnItem.width || columnDefaultWidth;
57
68
  });
58
69
 
59
- if (_realColumnsWidth.some(function (width) {
60
- return width && width > 0;
61
- })) {
62
- setColWidths(_realColumnsWidth);
70
+ if (totalWidth < containerWidth) {
71
+ // 容器宽度大于设置的宽度总和时,col宽度等比分分配占满容器。
72
+ setColWidths(columns.map(function (columnItem) {
73
+ return (columnItem.width || columnDefaultWidth) * containerWidth / totalWidth;
74
+ }));
75
+ } else {
76
+ // 容器宽度小于设置的宽度总和时,col宽度等于设置/默认宽度。
77
+ setColWidths(columns.map(function (columnItem) {
78
+ return columnItem.width || columnDefaultWidth;
79
+ }));
80
+ }
81
+ } else {
82
+ if (measureRowElement.childNodes) {
83
+ var _realColumnsWidth = Array.from(measureRowElement.childNodes).map(function (node) {
84
+ return node.getBoundingClientRect().width || 0;
85
+ });
86
+
87
+ if (_realColumnsWidth.some(function (width) {
88
+ return width && width > 0;
89
+ })) {
90
+ setColWidths(_realColumnsWidth);
91
+ }
63
92
  }
64
93
  }
65
94
  });
@@ -19,6 +19,8 @@ var React = require('react');
19
19
 
20
20
  var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
21
21
 
22
+ var useLatest = require('@hi-ui/use-latest');
23
+
22
24
  var axios = require('axios');
23
25
 
24
26
  function _interopDefaultLegacy(e) {
@@ -33,32 +35,72 @@ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
33
35
 
34
36
  var useTablePagination = function useTablePagination(_ref) {
35
37
  var pagination = _ref.pagination,
38
+ loadingProp = _ref.loadingProp,
36
39
  dataProp = _ref.data,
37
40
  dataSource = _ref.dataSource;
38
41
 
42
+ var _a, _b;
43
+
39
44
  var _useUncontrolledState = useUncontrolledState.useUncontrolledState(1, pagination.current, pagination.onChange),
40
45
  currentPage = _useUncontrolledState[0],
41
46
  trySetCurrentPage = _useUncontrolledState[1];
42
47
 
43
- var _React$useState = React__default["default"].useState([]),
44
- remoteTableData = _React$useState[0],
45
- setRemoteTableData = _React$useState[1];
48
+ var _useUncontrolledState2 = useUncontrolledState.useUncontrolledState((_b = (_a = pagination === null || pagination === void 0 ? void 0 : pagination.pageSizeOptions) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : 10, pagination.pageSize, pagination.onPageSizeChange),
49
+ pageSize = _useUncontrolledState2[0],
50
+ trySetPageSize = _useUncontrolledState2[1];
46
51
 
47
- var mergedData = dataSource ? remoteTableData : dataProp; // 内置远程数据配置 table,包括 data,pagination
52
+ var _React$useState = React__default["default"].useState(false),
53
+ internalLoading = _React$useState[0],
54
+ setInternalLoading = _React$useState[1];
48
55
 
49
- React__default["default"].useEffect(function () {
56
+ var loading = dataSource ? internalLoading : loadingProp;
57
+
58
+ var _React$useState2 = React__default["default"].useState(0),
59
+ internalTotal = _React$useState2[0],
60
+ setInternalTotal = _React$useState2[1];
61
+
62
+ var total = dataSource ? internalTotal : pagination.total;
63
+
64
+ var _React$useState3 = React__default["default"].useState([]),
65
+ remoteTableData = _React$useState3[0],
66
+ setRemoteTableData = _React$useState3[1];
67
+
68
+ var mergedData = dataSource ? remoteTableData : dataProp;
69
+ /**
70
+ * 当设置 dataSource 后,则自动获取数据
71
+ */
72
+
73
+ var getData = useLatest.useLatestCallback(function () {
50
74
  if (dataSource) {
51
- var requestConfig = dataSource(currentPage);
75
+ var requestConfig = dataSource(currentPage, pageSize);
76
+ setInternalLoading(true);
52
77
  axios__default["default"](requestConfig).then(function (res) {
53
- setRemoteTableData(res.data);
78
+ var data = res.data;
79
+ setRemoteTableData(data === null || data === void 0 ? void 0 : data.list);
80
+ setInternalTotal(data === null || data === void 0 ? void 0 : data.total);
81
+ })["finally"](function () {
82
+ setInternalLoading(false);
54
83
  });
55
84
  }
56
- }, [dataSource, currentPage]);
85
+ });
86
+ React__default["default"].useEffect(function () {
87
+ getData();
88
+ }, [currentPage, getData, pageSize]);
89
+ React__default["default"].useEffect(function () {
90
+ if (dataSource) {
91
+ // 如果已经在第一页则直接刷新数据,否则重置到第一页
92
+ currentPage === 1 ? getData() : trySetCurrentPage(1);
93
+ }
94
+ }, [dataSource, getData, trySetCurrentPage]);
57
95
  return {
58
96
  mergedData: mergedData,
59
97
  pagination: pagination,
60
98
  currentPage: currentPage,
61
- trySetCurrentPage: trySetCurrentPage
99
+ trySetCurrentPage: trySetCurrentPage,
100
+ pageSize: pageSize,
101
+ trySetPageSize: trySetPageSize,
102
+ loading: loading,
103
+ total: total
62
104
  };
63
105
  };
64
106