@hi-ui/table 4.5.4-alpha.0 → 4.5.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @hi-ui/table
2
2
 
3
+ ## 4.5.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2867](https://github.com/XiaoMi/hiui/pull/2867) [`eec624313`](https://github.com/XiaoMi/hiui/commit/eec624313de88943869f592dd06248455bddedbc) Thanks [@aqiusen](https://github.com/aqiusen)! - 修复统计行中选中模式下显示异常问题(#2863)
8
+
9
+ - [#2859](https://github.com/XiaoMi/hiui/pull/2859) [`a8d3a1f26`](https://github.com/XiaoMi/hiui/commit/a8d3a1f2687709b986fc54408cb6c69b9eb56318) Thanks [@zyprepare](https://github.com/zyprepare)! - fix: 修复 onDragStart 事件不触发问题
10
+
11
+ - [#2847](https://github.com/XiaoMi/hiui/pull/2847) [`0e67d2263`](https://github.com/XiaoMi/hiui/commit/0e67d2263c7e1bf9213e1a2f74300ee201f3a52e) Thanks [@aqiusen](https://github.com/aqiusen)! - fix(table): 修复虚拟列表 maxHeight 无法支持字符串问题
12
+
13
+ - Updated dependencies [[`5508758ec`](https://github.com/XiaoMi/hiui/commit/5508758ec2fe241d635949828065111c9a465ef8)]:
14
+ - @hi-ui/pagination@4.0.16
15
+
16
+ ## 4.5.4
17
+
18
+ ### Patch Changes
19
+
20
+ - [#2839](https://github.com/XiaoMi/hiui/pull/2839) [`e8498f36e`](https://github.com/XiaoMi/hiui/commit/e8498f36efe4dd42e0ef26c2e4c60298e2ce0147) Thanks [@zyprepare](https://github.com/zyprepare)! - fix: 修复 columns 中将 title 设置为空字符串报错
21
+
22
+ - [#2840](https://github.com/XiaoMi/hiui/pull/2840) [`c2afbaf33`](https://github.com/XiaoMi/hiui/commit/c2afbaf337dc933aa3858187e0010255ee2b82d5) Thanks [@zyprepare](https://github.com/zyprepare)! - fix: 修复同时设置 fieldKey 和 rowSelection 时 onChange 回调参数异常问题
23
+
24
+ - Updated dependencies [[`3afbf239e`](https://github.com/XiaoMi/hiui/commit/3afbf239e816ede48d6a85cbd99b6b099b8c8eb3), [`613c15a41`](https://github.com/XiaoMi/hiui/commit/613c15a41d783b86d86ccfb1dccd4da897e5ba9c), [`5d531802b`](https://github.com/XiaoMi/hiui/commit/5d531802ba9b142d448a2de2a7a8315722be0af8)]:
25
+ - @hi-ui/env@4.0.7
26
+ - @hi-ui/select@4.4.2
27
+
3
28
  ## 4.5.3
4
29
 
5
30
  ### Patch Changes
@@ -32,6 +32,7 @@ var useEmbedExpand = require('./hooks/use-embed-expand.js');
32
32
  var TheadContent = require('./TheadContent.js');
33
33
  var ColGroupContent = require('./ColGroupContent.js');
34
34
  var TbodyContent = require('./TbodyContent.js');
35
+ var Table = require('./Table.js');
35
36
  function _interopDefaultCompat(e) {
36
37
  return e && _typeof(e) === 'object' && 'default' in e ? e : {
37
38
  'default': e
@@ -138,7 +139,8 @@ var BaseTable = /*#__PURE__*/React.forwardRef(function (_a, ref) {
138
139
  };
139
140
  var hasAvgColumn = false;
140
141
  columns.forEach(function (column, index$1) {
141
- if (index$1 === 0) {
142
+ // 行选中模式下,index=0是checkbox列,index=1才是第一列 ; fix issue: https://github.com/XiaoMi/hiui/issues/2863
143
+ if (index$1 === 0 || index$1 === 1 && columns[0].dataKey === Table.SELECTION_DATA_KEY) {
142
144
  // @ts-ignore
143
145
  avgRow.raw[column.dataKey] = i18n.get('table.average');
144
146
  }
@@ -166,7 +168,7 @@ var BaseTable = /*#__PURE__*/React.forwardRef(function (_a, ref) {
166
168
  };
167
169
  var hasSumColumn = false;
168
170
  columns.forEach(function (column, index$1) {
169
- if (index$1 === 0) {
171
+ if (index$1 === 0 || index$1 === 1 && columns[0].dataKey === Table.SELECTION_DATA_KEY) {
170
172
  // @ts-ignore
171
173
  sumRow.raw[column.dataKey] = i18n.get('table.total');
172
174
  }
@@ -33,7 +33,7 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
33
33
  var Scrollbar__default = /*#__PURE__*/_interopDefaultCompat(Scrollbar);
34
34
  var _role = 'table';
35
35
  var _prefix = classname.getPrefixCls(_role);
36
- var TableBody = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
36
+ var TableBody = /*#__PURE__*/React.forwardRef(function (_ref) {
37
37
  var _ref$prefixCls = _ref.prefixCls,
38
38
  prefixCls = _ref$prefixCls === void 0 ? _prefix : _ref$prefixCls,
39
39
  emptyContent = _ref.emptyContent;
@@ -54,6 +54,7 @@ var TableBody = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
54
54
  measureRowElementRef = _useTableContext.measureRowElementRef,
55
55
  scrollbar = _useTableContext.scrollbar,
56
56
  scrollLeft = _useTableContext.scrollLeft;
57
+ var virtualListRef = React.useRef(null);
57
58
  var cls = classname.cx(prefixCls + "-body");
58
59
  var getRequiredProps = useLatest.useLatestCallback(function (id) {
59
60
  return {
@@ -76,8 +77,9 @@ var TableBody = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
76
77
  }, [colWidths]);
77
78
  if (virtual) {
78
79
  // TODO: avg和summay row的逻辑
79
- var realHeight = (_a = scrollBodyElementRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height;
80
- var vMaxHeight = maxHeight ? !isNaN(Number(String(maxHeight).replace(/px/, ''))) ? Number(maxHeight) : realHeight : 300;
80
+ var realHeight = (_a = virtualListRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height;
81
+ var maxHeightNumStr = String(maxHeight).replace(/px$/, '');
82
+ var vMaxHeight = maxHeight ? !isNaN(Number(maxHeightNumStr)) ? Number(maxHeightNumStr) : realHeight : 300;
81
83
  return /*#__PURE__*/React__default["default"].createElement("div", {
82
84
  ref: scrollBodyElementRef,
83
85
  className: cls,
@@ -104,10 +106,12 @@ var TableBody = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
104
106
  width: rowWidth
105
107
  }
106
108
  }), typeAssertion.isArrayNonEmpty(transitionData) ? ( /*#__PURE__*/React__default["default"].createElement("div", {
109
+ ref: virtualListRef,
107
110
  style: {
108
111
  width: '100%',
109
112
  position: 'sticky',
110
- left: 0
113
+ left: 0,
114
+ maxHeight: maxHeight
111
115
  }
112
116
  }, /*#__PURE__*/React__default["default"].createElement(List["default"], {
113
117
  prefixCls: cls + "--virtual",
@@ -35,11 +35,10 @@ var useTableCheck = function useTableCheck(_ref) {
35
35
  checkedRowKeys = _useUncontrolledState[0],
36
36
  trySetCheckedRowKeys = _useUncontrolledState[1];
37
37
  React.useEffect(function () {
38
- checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter(function (_ref2) {
39
- var key = _ref2.key;
40
- return checkedRowKeys === null || checkedRowKeys === void 0 ? void 0 : checkedRowKeys.includes(key);
38
+ checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter(function (item) {
39
+ return checkedRowKeys === null || checkedRowKeys === void 0 ? void 0 : checkedRowKeys.includes(item[fieldKey]);
41
40
  });
42
- }, [checkedRowKeys]);
41
+ }, [checkedRowKeys, fieldKey]);
43
42
  // 已选中的行数据集合
44
43
  var checkedRowDataItemsRef = React__default["default"].useRef([]);
45
44
  var checkedRowDataItems = checkedRowDataItemsRef.current;
@@ -56,9 +55,8 @@ var useTableCheck = function useTableCheck(_ref) {
56
55
  // 选中项变化会触发该函数
57
56
  var onCheckedRowKeysChange = React__default["default"].useCallback(function (rowItem, checked) {
58
57
  // 记录选中的行数据集合
59
- var nextCheckedDataItems = checkedRowDataItems.filter(function (_ref3) {
60
- var key = _ref3.key;
61
- return checkedRowKeys.includes(key);
58
+ var nextCheckedDataItems = checkedRowDataItems.filter(function (item) {
59
+ return checkedRowKeys.includes(item[fieldKey]);
62
60
  });
63
61
  if (checked) {
64
62
  if (!nextCheckedDataItems.find(function (item) {
@@ -110,9 +108,8 @@ var useTableCheck = function useTableCheck(_ref) {
110
108
  });
111
109
  var checkedRowKeysSet = new Set(checkedRowKeys);
112
110
  if (checkedAll) {
113
- checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter(function (_ref4) {
114
- var key = _ref4.key;
115
- return !checkedRowKeysSet.has(key);
111
+ checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter(function (item) {
112
+ return !checkedRowKeysSet.has(item[fieldKey]);
116
113
  });
117
114
  // 移除当前页所有行 ids
118
115
  trySetCheckedRowKeys(function (prev) {
@@ -123,7 +120,7 @@ var useTableCheck = function useTableCheck(_ref) {
123
120
  return;
124
121
  }
125
122
  checkedRowDataItemsRef.current = targetRowItems.concat(checkedRowDataItemsRef.current.filter(function (item) {
126
- return !checkedRowKeysSet.has(item.key);
123
+ return !checkedRowKeysSet.has(item[fieldKey]);
127
124
  }));
128
125
  trySetCheckedRowKeys(
129
126
  // 添加当前页所有行 ids
@@ -78,6 +78,7 @@ var useTable = function useTable(_a) {
78
78
  stickyTop = _a$stickyTop === void 0 ? 0 : _a$stickyTop,
79
79
  _a$draggable = _a.draggable,
80
80
  draggable = _a$draggable === void 0 ? false : _a$draggable,
81
+ onDragStart = _a.onDragStart,
81
82
  onDropProp = _a.onDrop,
82
83
  onDropEnd = _a.onDropEnd,
83
84
  showColMenu = _a.showColMenu,
@@ -574,6 +575,7 @@ var useTable = function useTable(_a) {
574
575
  draggable: draggable,
575
576
  highlightColumns: [],
576
577
  dragRowRef: dragRowRef,
578
+ onDragStart: onDragStart,
577
579
  onDrop: onDrop,
578
580
  groupedColumns: groupedColumns,
579
581
  // 子树展开
@@ -26,6 +26,7 @@ import { useEmbedExpand } from './hooks/use-embed-expand.js';
26
26
  import { TheadContent } from './TheadContent.js';
27
27
  import { ColGroupContent } from './ColGroupContent.js';
28
28
  import { TbodyContent } from './TbodyContent.js';
29
+ import { SELECTION_DATA_KEY } from './Table.js';
29
30
  var _role = 'table';
30
31
  var _prefix = getPrefixCls('table');
31
32
  var EMBED_DATA_KEY = "TABLE_EMBED_DATA_KEY_" + uuid();
@@ -125,7 +126,8 @@ var BaseTable = /*#__PURE__*/forwardRef(function (_a, ref) {
125
126
  };
126
127
  var hasAvgColumn = false;
127
128
  columns.forEach(function (column, index) {
128
- if (index === 0) {
129
+ // 行选中模式下,index=0是checkbox列,index=1才是第一列 ; fix issue: https://github.com/XiaoMi/hiui/issues/2863
130
+ if (index === 0 || index === 1 && columns[0].dataKey === SELECTION_DATA_KEY) {
129
131
  // @ts-ignore
130
132
  avgRow.raw[column.dataKey] = i18n.get('table.average');
131
133
  }
@@ -153,7 +155,7 @@ var BaseTable = /*#__PURE__*/forwardRef(function (_a, ref) {
153
155
  };
154
156
  var hasSumColumn = false;
155
157
  columns.forEach(function (column, index) {
156
- if (index === 0) {
158
+ if (index === 0 || index === 1 && columns[0].dataKey === SELECTION_DATA_KEY) {
157
159
  // @ts-ignore
158
160
  sumRow.raw[column.dataKey] = i18n.get('table.total');
159
161
  }
@@ -7,7 +7,7 @@
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
- import React__default, { forwardRef, useMemo } from 'react';
10
+ import React__default, { forwardRef, useRef, useMemo } from 'react';
11
11
  import List from './node_modules/rc-virtual-list/es/List.js';
12
12
  import { getPrefixCls, cx } from '@hi-ui/classname';
13
13
  import { __DEV__ } from '@hi-ui/env';
@@ -20,7 +20,7 @@ import { ColGroupContent } from './ColGroupContent.js';
20
20
  import { renderEmptyContent, TbodyContent } from './TbodyContent.js';
21
21
  var _role = 'table';
22
22
  var _prefix = getPrefixCls(_role);
23
- var TableBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
23
+ var TableBody = /*#__PURE__*/forwardRef(function (_ref) {
24
24
  var _ref$prefixCls = _ref.prefixCls,
25
25
  prefixCls = _ref$prefixCls === void 0 ? _prefix : _ref$prefixCls,
26
26
  emptyContent = _ref.emptyContent;
@@ -41,6 +41,7 @@ var TableBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
41
41
  measureRowElementRef = _useTableContext.measureRowElementRef,
42
42
  scrollbar = _useTableContext.scrollbar,
43
43
  scrollLeft = _useTableContext.scrollLeft;
44
+ var virtualListRef = useRef(null);
44
45
  var cls = cx(prefixCls + "-body");
45
46
  var getRequiredProps = useLatestCallback(function (id) {
46
47
  return {
@@ -63,8 +64,9 @@ var TableBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
63
64
  }, [colWidths]);
64
65
  if (virtual) {
65
66
  // TODO: avg和summay row的逻辑
66
- var realHeight = (_a = scrollBodyElementRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height;
67
- var vMaxHeight = maxHeight ? !isNaN(Number(String(maxHeight).replace(/px/, ''))) ? Number(maxHeight) : realHeight : 300;
67
+ var realHeight = (_a = virtualListRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height;
68
+ var maxHeightNumStr = String(maxHeight).replace(/px$/, '');
69
+ var vMaxHeight = maxHeight ? !isNaN(Number(maxHeightNumStr)) ? Number(maxHeightNumStr) : realHeight : 300;
68
70
  return /*#__PURE__*/React__default.createElement("div", {
69
71
  ref: scrollBodyElementRef,
70
72
  className: cls,
@@ -91,10 +93,12 @@ var TableBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
91
93
  width: rowWidth
92
94
  }
93
95
  }), isArrayNonEmpty(transitionData) ? ( /*#__PURE__*/React__default.createElement("div", {
96
+ ref: virtualListRef,
94
97
  style: {
95
98
  width: '100%',
96
99
  position: 'sticky',
97
- left: 0
100
+ left: 0,
101
+ maxHeight: maxHeight
98
102
  }
99
103
  }, /*#__PURE__*/React__default.createElement(List, {
100
104
  prefixCls: cls + "--virtual",
@@ -23,11 +23,10 @@ var useTableCheck = function useTableCheck(_ref) {
23
23
  checkedRowKeys = _useUncontrolledState[0],
24
24
  trySetCheckedRowKeys = _useUncontrolledState[1];
25
25
  useEffect(function () {
26
- checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter(function (_ref2) {
27
- var key = _ref2.key;
28
- return checkedRowKeys === null || checkedRowKeys === void 0 ? void 0 : checkedRowKeys.includes(key);
26
+ checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter(function (item) {
27
+ return checkedRowKeys === null || checkedRowKeys === void 0 ? void 0 : checkedRowKeys.includes(item[fieldKey]);
29
28
  });
30
- }, [checkedRowKeys]);
29
+ }, [checkedRowKeys, fieldKey]);
31
30
  // 已选中的行数据集合
32
31
  var checkedRowDataItemsRef = React__default.useRef([]);
33
32
  var checkedRowDataItems = checkedRowDataItemsRef.current;
@@ -44,9 +43,8 @@ var useTableCheck = function useTableCheck(_ref) {
44
43
  // 选中项变化会触发该函数
45
44
  var onCheckedRowKeysChange = React__default.useCallback(function (rowItem, checked) {
46
45
  // 记录选中的行数据集合
47
- var nextCheckedDataItems = checkedRowDataItems.filter(function (_ref3) {
48
- var key = _ref3.key;
49
- return checkedRowKeys.includes(key);
46
+ var nextCheckedDataItems = checkedRowDataItems.filter(function (item) {
47
+ return checkedRowKeys.includes(item[fieldKey]);
50
48
  });
51
49
  if (checked) {
52
50
  if (!nextCheckedDataItems.find(function (item) {
@@ -98,9 +96,8 @@ var useTableCheck = function useTableCheck(_ref) {
98
96
  });
99
97
  var checkedRowKeysSet = new Set(checkedRowKeys);
100
98
  if (checkedAll) {
101
- checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter(function (_ref4) {
102
- var key = _ref4.key;
103
- return !checkedRowKeysSet.has(key);
99
+ checkedRowDataItemsRef.current = checkedRowDataItemsRef.current.filter(function (item) {
100
+ return !checkedRowKeysSet.has(item[fieldKey]);
104
101
  });
105
102
  // 移除当前页所有行 ids
106
103
  trySetCheckedRowKeys(function (prev) {
@@ -111,7 +108,7 @@ var useTableCheck = function useTableCheck(_ref) {
111
108
  return;
112
109
  }
113
110
  checkedRowDataItemsRef.current = targetRowItems.concat(checkedRowDataItemsRef.current.filter(function (item) {
114
- return !checkedRowKeysSet.has(item.key);
111
+ return !checkedRowKeysSet.has(item[fieldKey]);
115
112
  }));
116
113
  trySetCheckedRowKeys(
117
114
  // 添加当前页所有行 ids
@@ -66,6 +66,7 @@ var useTable = function useTable(_a) {
66
66
  stickyTop = _a$stickyTop === void 0 ? 0 : _a$stickyTop,
67
67
  _a$draggable = _a.draggable,
68
68
  draggable = _a$draggable === void 0 ? false : _a$draggable,
69
+ onDragStart = _a.onDragStart,
69
70
  onDropProp = _a.onDrop,
70
71
  onDropEnd = _a.onDropEnd,
71
72
  showColMenu = _a.showColMenu,
@@ -562,6 +563,7 @@ var useTable = function useTable(_a) {
562
563
  draggable: draggable,
563
564
  highlightColumns: [],
564
565
  dragRowRef: dragRowRef,
566
+ onDragStart: onDragStart,
565
567
  onDrop: onDrop,
566
568
  groupedColumns: groupedColumns,
567
569
  // 子树展开
@@ -26,6 +26,9 @@ export declare const TableProvider: import("react").Provider<(Omit<{
26
26
  draggable: boolean;
27
27
  highlightColumns: any;
28
28
  dragRowRef: import("react").MutableRefObject<any>;
29
+ onDragStart: ((evt: import("react").DragEvent<Element>, option: {
30
+ dragNode: object;
31
+ }) => void) | undefined;
29
32
  onDrop: (evt: any, sourceId: any, targetId: any, dragDirection: any) => void;
30
33
  groupedColumns: import("./types").FlattedTableColumnItemData[][];
31
34
  onExpandTreeRowsChange: (expandedNode: import("./types").TableRowEventData, shouldExpanded: boolean) => void;
@@ -138,6 +141,9 @@ export declare const useTableContext: () => Omit<{
138
141
  draggable: boolean;
139
142
  highlightColumns: any;
140
143
  dragRowRef: import("react").MutableRefObject<any>;
144
+ onDragStart: ((evt: import("react").DragEvent<Element>, option: {
145
+ dragNode: object;
146
+ }) => void) | undefined;
141
147
  onDrop: (evt: any, sourceId: any, targetId: any, dragDirection: any) => void;
142
148
  groupedColumns: import("./types").FlattedTableColumnItemData[][];
143
149
  onExpandTreeRowsChange: (expandedNode: import("./types").TableRowEventData, shouldExpanded: boolean) => void;
@@ -28,6 +28,9 @@ export declare const useTable: ({ data, columns: columnsProp, defaultFixedToColu
28
28
  draggable: boolean;
29
29
  highlightColumns: any;
30
30
  dragRowRef: React.MutableRefObject<any>;
31
+ onDragStart: ((evt: React.DragEvent, option: {
32
+ dragNode: object;
33
+ }) => void) | undefined;
31
34
  onDrop: (evt: any, sourceId: any, targetId: any, dragDirection: any) => void;
32
35
  groupedColumns: FlattedTableColumnItemData[][];
33
36
  onExpandTreeRowsChange: (expandedNode: TableRowEventData, shouldExpanded: boolean) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/table",
3
- "version": "4.5.4-alpha.0",
3
+ "version": "4.5.5",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",
@@ -50,17 +50,17 @@
50
50
  "@hi-ui/dom-utils": "^4.0.7",
51
51
  "@hi-ui/drawer": "^4.1.4",
52
52
  "@hi-ui/empty-state": "^4.1.1",
53
- "@hi-ui/env": "^4.0.5",
53
+ "@hi-ui/env": "^4.0.7",
54
54
  "@hi-ui/func-utils": "^4.0.4",
55
55
  "@hi-ui/icon-button": "^4.0.9",
56
56
  "@hi-ui/icons": "^4.0.19",
57
57
  "@hi-ui/loading": "^4.2.1",
58
58
  "@hi-ui/object-utils": "^4.0.4",
59
- "@hi-ui/pagination": "^4.0.15",
59
+ "@hi-ui/pagination": "^4.0.16",
60
60
  "@hi-ui/popper": "^4.1.5",
61
61
  "@hi-ui/react-utils": "^4.0.4",
62
62
  "@hi-ui/scrollbar": "^4.1.1",
63
- "@hi-ui/select": "^4.4.1",
63
+ "@hi-ui/select": "^4.4.2",
64
64
  "@hi-ui/spinner": "^4.0.9",
65
65
  "@hi-ui/times": "^4.0.4",
66
66
  "@hi-ui/tree-utils": "^4.1.6",