@hi-ui/table 4.7.0 → 4.8.0
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 +16 -0
- package/lib/cjs/SettingDrawer.js +2 -0
- package/lib/cjs/TableColumnMenu.js +10 -1
- package/lib/cjs/TheadContent.js +11 -4
- package/lib/cjs/hooks/use-change.js +53 -0
- package/lib/cjs/hooks/use-colgroup.js +4 -2
- package/lib/cjs/use-table.js +13 -2
- package/lib/esm/SettingDrawer.js +2 -0
- package/lib/esm/TableColumnMenu.js +10 -1
- package/lib/esm/TheadContent.js +11 -4
- package/lib/esm/hooks/use-change.js +48 -0
- package/lib/esm/hooks/use-colgroup.js +4 -2
- package/lib/esm/use-table.js +13 -2
- package/lib/types/SettingDrawer.d.ts +4 -0
- package/lib/types/context.d.ts +8 -0
- package/lib/types/hooks/use-change.d.ts +20 -0
- package/lib/types/types.d.ts +4 -0
- package/lib/types/use-table.d.ts +17 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @hi-ui/table
|
|
2
2
|
|
|
3
|
+
## 4.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#3033](https://github.com/XiaoMi/hiui/pull/3033) [`17158fa6e`](https://github.com/XiaoMi/hiui/commit/17158fa6e286a560aeb9fd65d68856c2e7a00736) Thanks [@zyprepare](https://github.com/zyprepare)! - feat(table): 支持表头列合并 (#3032)
|
|
8
|
+
|
|
9
|
+
- [#2978](https://github.com/XiaoMi/hiui/pull/2978) [`f807f7dda`](https://github.com/XiaoMi/hiui/commit/f807f7ddae07184a0584e16d017a3d9f5785d4b8) Thanks [@fcppddl](https://github.com/fcppddl)! - feat(table): 将表格中的交互统一加上回调事件 (#2977)
|
|
10
|
+
|
|
11
|
+
- [#3034](https://github.com/XiaoMi/hiui/pull/3034) [`83be3c14b`](https://github.com/XiaoMi/hiui/commit/83be3c14b9e8cd3e73ec477895a47b925439a3a5) Thanks [@zyprepare](https://github.com/zyprepare)! - feat(table): SettingDrawer 增加 onReset api (#3021)
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`241447e14`](https://github.com/XiaoMi/hiui/commit/241447e148f4544c6a08623d60d977e286ec9d64), [`b2d784b23`](https://github.com/XiaoMi/hiui/commit/b2d784b23682e70cbc7b09e3396f51fda02e2223)]:
|
|
16
|
+
- @hi-ui/scrollbar@4.2.0
|
|
17
|
+
- @hi-ui/select@4.6.0
|
|
18
|
+
|
|
3
19
|
## 4.7.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/lib/cjs/SettingDrawer.js
CHANGED
|
@@ -55,6 +55,7 @@ var SettingDrawer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
55
55
|
sortedColKeysPropBeforeVerify = _ref.sortedColKeys,
|
|
56
56
|
onSortedColKeysChange = _ref.onSortedColKeysChange,
|
|
57
57
|
onSetColKeysChange = _ref.onSetColKeysChange,
|
|
58
|
+
onReset = _ref.onReset,
|
|
58
59
|
checkDisabledColKeys = _ref.checkDisabledColKeys,
|
|
59
60
|
dragDisabledColKeys = _ref.dragDisabledColKeys,
|
|
60
61
|
extraHeader = _ref.extraHeader,
|
|
@@ -124,6 +125,7 @@ var SettingDrawer = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
124
125
|
var resetLatest = useLatest.useLatestCallback(function () {
|
|
125
126
|
setCacheHiddenColKeys(hiddenColKeys);
|
|
126
127
|
setCacheSortedCols(sortedCols);
|
|
128
|
+
onReset === null || onReset === void 0 ? void 0 : onReset();
|
|
127
129
|
});
|
|
128
130
|
// 当 visible 由 false 变为 true 时触发
|
|
129
131
|
var prevShowPopperRef = React.useRef(!visible);
|
|
@@ -48,7 +48,9 @@ var TableColumnMenu = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
48
48
|
leftFreezeColumn = _useTableContext.leftFreezeColumn,
|
|
49
49
|
setLeftFreezeColumn = _useTableContext.setLeftFreezeColumn,
|
|
50
50
|
isHighlightedCol = _useTableContext.isHighlightedCol,
|
|
51
|
-
onHighlightedColChange = _useTableContext.onHighlightedColChange
|
|
51
|
+
onHighlightedColChange = _useTableContext.onHighlightedColChange,
|
|
52
|
+
highlightedColKeys = _useTableContext.highlightedColKeys,
|
|
53
|
+
onHighlightedCol = _useTableContext.onHighlightedCol;
|
|
52
54
|
var dataKey = column.id,
|
|
53
55
|
columnRaw = column.raw;
|
|
54
56
|
var canSort = !!columnRaw.sorter;
|
|
@@ -112,6 +114,13 @@ var TableColumnMenu = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
112
114
|
icon: /*#__PURE__*/React__default["default"].createElement(icons.ColumnHeightOutlined, null),
|
|
113
115
|
onSwitch: function onSwitch(shouldActive) {
|
|
114
116
|
onHighlightedColChange(column, shouldActive);
|
|
117
|
+
var latestHighlightedColKeys = shouldActive ? [].concat(highlightedColKeys, [column.raw.dataKey || '']).filter(Boolean) : [].concat(highlightedColKeys.filter(function (keys) {
|
|
118
|
+
return keys !== column.raw.dataKey;
|
|
119
|
+
}));
|
|
120
|
+
onHighlightedCol === null || onHighlightedCol === void 0 ? void 0 : onHighlightedCol({
|
|
121
|
+
active: shouldActive,
|
|
122
|
+
column: column.raw
|
|
123
|
+
}, latestHighlightedColKeys);
|
|
115
124
|
menuVisibleAction.off();
|
|
116
125
|
}
|
|
117
126
|
}), /*#__PURE__*/React__default["default"].createElement(TableColumnMenuItem, {
|
package/lib/cjs/TheadContent.js
CHANGED
|
@@ -68,9 +68,14 @@ var TheadContent = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
68
68
|
groupLastColumn = true;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
var stickyColProps = getStickyColProps(col);
|
|
71
72
|
var cell = /*#__PURE__*/React__default["default"].createElement("th", Object.assign({
|
|
72
73
|
key: dataKey
|
|
73
|
-
},
|
|
74
|
+
}, stickyColProps, {
|
|
75
|
+
style: Object.assign(Object.assign({}, stickyColProps.style), {
|
|
76
|
+
// 表头合并场景下,被合并的表头需要隐藏
|
|
77
|
+
display: (col === null || col === void 0 ? void 0 : col.colSpan) === 0 ? 'none' : undefined
|
|
78
|
+
}),
|
|
74
79
|
className: classname.cx(prefixCls + "-cell", raw.className, isHighlightedCol(dataKey) && prefixCls + "-cell__col--highlight", isHoveredHighlightCol(dataKey) && prefixCls + "-cell__col--hovered-highlight", activeColumnKeysAction.has(dataKey) && prefixCls + "-cell__col--active", groupLastColumn && prefixCls + "-cell--group-last-column"),
|
|
75
80
|
// @ts-ignore
|
|
76
81
|
colSpan: col.colSpan,
|
|
@@ -88,6 +93,8 @@ var TheadContent = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
88
93
|
return activeColumnKeysAction.remove(dataKey);
|
|
89
94
|
}
|
|
90
95
|
}));
|
|
96
|
+
// 当有表头列合并时,将当前列的索引设置为最后一个被合并的列的索引,这样在拖拽时,UI 和交互才更符合直觉
|
|
97
|
+
var index = col.colSpan && col.colSpan > 1 ? colIndex + col.colSpan - 1 : colIndex;
|
|
91
98
|
return resizable && colIndex !== colWidths.length - 1 ? ( /*#__PURE__*/React__default["default"].createElement(reactResizable.Resizable, {
|
|
92
99
|
key: colIndex,
|
|
93
100
|
className: prefixCls + "__resizable",
|
|
@@ -98,12 +105,12 @@ var TheadContent = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
98
105
|
className: prefixCls + "__resizable-handle"
|
|
99
106
|
}),
|
|
100
107
|
height: 0,
|
|
101
|
-
width: colWidths[
|
|
108
|
+
width: colWidths[index],
|
|
102
109
|
onResize: function onResize(evt, options) {
|
|
103
|
-
onColumnResizable(evt, options,
|
|
110
|
+
onColumnResizable(evt, options, index);
|
|
104
111
|
},
|
|
105
112
|
onResizeStop: function onResizeStop(evt, options) {
|
|
106
|
-
_onResizeStop === null || _onResizeStop === void 0 ? void 0 : _onResizeStop(evt, options === null || options === void 0 ? void 0 : options.size,
|
|
113
|
+
_onResizeStop === null || _onResizeStop === void 0 ? void 0 : _onResizeStop(evt, options === null || options === void 0 ? void 0 : options.size, index, colWidths);
|
|
107
114
|
}
|
|
108
115
|
}, cell)) : cell;
|
|
109
116
|
}));
|
|
@@ -0,0 +1,53 @@
|
|
|
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 React = require('react');
|
|
16
|
+
var useChange = function useChange(_ref) {
|
|
17
|
+
var activeSorterColumn = _ref.activeSorterColumn,
|
|
18
|
+
activeSorterType = _ref.activeSorterType,
|
|
19
|
+
columns = _ref.columns,
|
|
20
|
+
showData = _ref.showData,
|
|
21
|
+
onChange = _ref.onChange;
|
|
22
|
+
var changeRef = React.useRef({
|
|
23
|
+
sort: {
|
|
24
|
+
activeSorterColumn: activeSorterColumn,
|
|
25
|
+
activeSorterType: activeSorterType
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
React.useEffect(function () {
|
|
29
|
+
var sort = changeRef.current.sort;
|
|
30
|
+
var sortNotChange = sort.activeSorterColumn === activeSorterColumn && sort.activeSorterType === activeSorterType;
|
|
31
|
+
if (sortNotChange) return;
|
|
32
|
+
var changeObj = {
|
|
33
|
+
sorter: {
|
|
34
|
+
order: activeSorterType,
|
|
35
|
+
column: columns.filter(function (d) {
|
|
36
|
+
return d.dataKey === activeSorterColumn;
|
|
37
|
+
})[0]
|
|
38
|
+
},
|
|
39
|
+
extra: {
|
|
40
|
+
action: 'sorter',
|
|
41
|
+
currentDataSource: showData.map(function (d) {
|
|
42
|
+
return d.raw;
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
47
|
+
sorter: changeObj.sorter
|
|
48
|
+
}, changeObj.extra);
|
|
49
|
+
sort.activeSorterColumn = activeSorterColumn;
|
|
50
|
+
sort.activeSorterType = activeSorterType;
|
|
51
|
+
}, [activeSorterColumn, activeSorterType, columns, showData, onChange]);
|
|
52
|
+
};
|
|
53
|
+
exports.useChange = useChange;
|
|
@@ -43,7 +43,8 @@ var useColumns = function useColumns(_ref) {
|
|
|
43
43
|
dataKey: raw.dataKey,
|
|
44
44
|
title: raw.title,
|
|
45
45
|
align: (_a = raw.align) !== null && _a !== void 0 ? _a : 'left',
|
|
46
|
-
render: raw.render
|
|
46
|
+
render: raw.render,
|
|
47
|
+
colSpan: raw.colSpan
|
|
47
48
|
});
|
|
48
49
|
});
|
|
49
50
|
// 记录下标位置,方便冻结列操作计算时快速获取更新
|
|
@@ -74,9 +75,10 @@ var useColumns = function useColumns(_ref) {
|
|
|
74
75
|
// 在最后一层,colSpan = 1, rowSpan = maxDepth - depth + 1
|
|
75
76
|
// 不在最后一层,rowSpan = 1, colSpan = 叶子节点后代数量
|
|
76
77
|
flattedColumns.forEach(function (column) {
|
|
78
|
+
var _a;
|
|
77
79
|
if (treeUtils.isLeaf(column)) {
|
|
78
80
|
column.rowSpan = maxColumnDepth - column.depth + 1;
|
|
79
|
-
column.colSpan = 1;
|
|
81
|
+
column.colSpan = (_a = column.colSpan) !== null && _a !== void 0 ? _a : 1;
|
|
80
82
|
} else {
|
|
81
83
|
column.rowSpan = 1;
|
|
82
84
|
column.colSpan = treeUtils.getLeafChildren(column).length;
|
package/lib/cjs/use-table.js
CHANGED
|
@@ -26,6 +26,7 @@ var useLatest = require('@hi-ui/use-latest');
|
|
|
26
26
|
var index = require('./utils/index.js');
|
|
27
27
|
var useAsyncSwitch = require('./hooks/use-async-switch.js');
|
|
28
28
|
var useExpand = require('./hooks/use-expand.js');
|
|
29
|
+
var useChange = require('./hooks/use-change.js');
|
|
29
30
|
var useColWidth = require('./hooks/use-col-width.js');
|
|
30
31
|
var useColgroup = require('./hooks/use-colgroup.js');
|
|
31
32
|
var useDrag = require('./hooks/use-drag.js');
|
|
@@ -91,7 +92,9 @@ var useTable = function useTable(_a) {
|
|
|
91
92
|
scrollbar = _a.scrollbar,
|
|
92
93
|
rowClassName = _a.rowClassName,
|
|
93
94
|
cellClassName = _a.cellClassName,
|
|
94
|
-
|
|
95
|
+
onChange = _a.onChange,
|
|
96
|
+
onHighlightedCol = _a.onHighlightedCol,
|
|
97
|
+
rootProps = tslib.__rest(_a, ["data", "columns", "defaultFixedToColumn", "fixedToColumn", "onFixedToColumn", "scrollWidth", "resizable", "errorRowKeys", "highlightedColKeys", "highlightedRowKeys", "showColHighlight", "showRowHighlight", "highlightRowOnDoubleClick", "defaultExpandedRowKeys", "expandedRowKeys", "onExpand", "defaultExpandAll", "onLoadChildren", "maxHeight", "sticky", "stickyTop", "draggable", "onDragStart", "onDrop", "onDropEnd", "showColMenu", "rowSelection", "cellRender", "footerRender", "fieldKey", "virtual", "scrollbar", "rowClassName", "cellClassName", "onChange", "onHighlightedCol"]);
|
|
95
98
|
/**
|
|
96
99
|
* 获取 key 字段值
|
|
97
100
|
*/
|
|
@@ -513,6 +516,13 @@ var useTable = function useTable(_a) {
|
|
|
513
516
|
}
|
|
514
517
|
return _data;
|
|
515
518
|
}, [activeSorterColumn, activeSorterType, transitionData, columns]);
|
|
519
|
+
useChange.useChange({
|
|
520
|
+
activeSorterColumn: activeSorterColumn,
|
|
521
|
+
activeSorterType: activeSorterType,
|
|
522
|
+
columns: columns,
|
|
523
|
+
showData: showData,
|
|
524
|
+
onChange: onChange
|
|
525
|
+
});
|
|
516
526
|
return Object.assign(Object.assign({
|
|
517
527
|
measureRowElementRef: measureRowElementRef,
|
|
518
528
|
rootProps: rootProps,
|
|
@@ -594,7 +604,8 @@ var useTable = function useTable(_a) {
|
|
|
594
604
|
setHeaderTableElement: setHeaderTableElement,
|
|
595
605
|
scrollbar: scrollbar,
|
|
596
606
|
rowClassName: rowClassName,
|
|
597
|
-
cellClassName: cellClassName
|
|
607
|
+
cellClassName: cellClassName,
|
|
608
|
+
onHighlightedCol: onHighlightedCol
|
|
598
609
|
});
|
|
599
610
|
};
|
|
600
611
|
exports.useTable = useTable;
|
package/lib/esm/SettingDrawer.js
CHANGED
|
@@ -42,6 +42,7 @@ var SettingDrawer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
42
42
|
sortedColKeysPropBeforeVerify = _ref.sortedColKeys,
|
|
43
43
|
onSortedColKeysChange = _ref.onSortedColKeysChange,
|
|
44
44
|
onSetColKeysChange = _ref.onSetColKeysChange,
|
|
45
|
+
onReset = _ref.onReset,
|
|
45
46
|
checkDisabledColKeys = _ref.checkDisabledColKeys,
|
|
46
47
|
dragDisabledColKeys = _ref.dragDisabledColKeys,
|
|
47
48
|
extraHeader = _ref.extraHeader,
|
|
@@ -111,6 +112,7 @@ var SettingDrawer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
111
112
|
var resetLatest = useLatestCallback(function () {
|
|
112
113
|
setCacheHiddenColKeys(hiddenColKeys);
|
|
113
114
|
setCacheSortedCols(sortedCols);
|
|
115
|
+
onReset === null || onReset === void 0 ? void 0 : onReset();
|
|
114
116
|
});
|
|
115
117
|
// 当 visible 由 false 变为 true 时触发
|
|
116
118
|
var prevShowPopperRef = useRef(!visible);
|
|
@@ -35,7 +35,9 @@ var TableColumnMenu = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
35
35
|
leftFreezeColumn = _useTableContext.leftFreezeColumn,
|
|
36
36
|
setLeftFreezeColumn = _useTableContext.setLeftFreezeColumn,
|
|
37
37
|
isHighlightedCol = _useTableContext.isHighlightedCol,
|
|
38
|
-
onHighlightedColChange = _useTableContext.onHighlightedColChange
|
|
38
|
+
onHighlightedColChange = _useTableContext.onHighlightedColChange,
|
|
39
|
+
highlightedColKeys = _useTableContext.highlightedColKeys,
|
|
40
|
+
onHighlightedCol = _useTableContext.onHighlightedCol;
|
|
39
41
|
var dataKey = column.id,
|
|
40
42
|
columnRaw = column.raw;
|
|
41
43
|
var canSort = !!columnRaw.sorter;
|
|
@@ -99,6 +101,13 @@ var TableColumnMenu = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
99
101
|
icon: /*#__PURE__*/React__default.createElement(ColumnHeightOutlined, null),
|
|
100
102
|
onSwitch: function onSwitch(shouldActive) {
|
|
101
103
|
onHighlightedColChange(column, shouldActive);
|
|
104
|
+
var latestHighlightedColKeys = shouldActive ? [].concat(highlightedColKeys, [column.raw.dataKey || '']).filter(Boolean) : [].concat(highlightedColKeys.filter(function (keys) {
|
|
105
|
+
return keys !== column.raw.dataKey;
|
|
106
|
+
}));
|
|
107
|
+
onHighlightedCol === null || onHighlightedCol === void 0 ? void 0 : onHighlightedCol({
|
|
108
|
+
active: shouldActive,
|
|
109
|
+
column: column.raw
|
|
110
|
+
}, latestHighlightedColKeys);
|
|
102
111
|
menuVisibleAction.off();
|
|
103
112
|
}
|
|
104
113
|
}), /*#__PURE__*/React__default.createElement(TableColumnMenuItem, {
|
package/lib/esm/TheadContent.js
CHANGED
|
@@ -56,9 +56,14 @@ var TheadContent = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
56
56
|
groupLastColumn = true;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
var stickyColProps = getStickyColProps(col);
|
|
59
60
|
var cell = /*#__PURE__*/React__default.createElement("th", Object.assign({
|
|
60
61
|
key: dataKey
|
|
61
|
-
},
|
|
62
|
+
}, stickyColProps, {
|
|
63
|
+
style: Object.assign(Object.assign({}, stickyColProps.style), {
|
|
64
|
+
// 表头合并场景下,被合并的表头需要隐藏
|
|
65
|
+
display: (col === null || col === void 0 ? void 0 : col.colSpan) === 0 ? 'none' : undefined
|
|
66
|
+
}),
|
|
62
67
|
className: cx(prefixCls + "-cell", raw.className, isHighlightedCol(dataKey) && prefixCls + "-cell__col--highlight", isHoveredHighlightCol(dataKey) && prefixCls + "-cell__col--hovered-highlight", activeColumnKeysAction.has(dataKey) && prefixCls + "-cell__col--active", groupLastColumn && prefixCls + "-cell--group-last-column"),
|
|
63
68
|
// @ts-ignore
|
|
64
69
|
colSpan: col.colSpan,
|
|
@@ -76,6 +81,8 @@ var TheadContent = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
76
81
|
return activeColumnKeysAction.remove(dataKey);
|
|
77
82
|
}
|
|
78
83
|
}));
|
|
84
|
+
// 当有表头列合并时,将当前列的索引设置为最后一个被合并的列的索引,这样在拖拽时,UI 和交互才更符合直觉
|
|
85
|
+
var index = col.colSpan && col.colSpan > 1 ? colIndex + col.colSpan - 1 : colIndex;
|
|
79
86
|
return resizable && colIndex !== colWidths.length - 1 ? ( /*#__PURE__*/React__default.createElement(Resizable, {
|
|
80
87
|
key: colIndex,
|
|
81
88
|
className: prefixCls + "__resizable",
|
|
@@ -86,12 +93,12 @@ var TheadContent = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
86
93
|
className: prefixCls + "__resizable-handle"
|
|
87
94
|
}),
|
|
88
95
|
height: 0,
|
|
89
|
-
width: colWidths[
|
|
96
|
+
width: colWidths[index],
|
|
90
97
|
onResize: function onResize(evt, options) {
|
|
91
|
-
onColumnResizable(evt, options,
|
|
98
|
+
onColumnResizable(evt, options, index);
|
|
92
99
|
},
|
|
93
100
|
onResizeStop: function onResizeStop(evt, options) {
|
|
94
|
-
_onResizeStop === null || _onResizeStop === void 0 ? void 0 : _onResizeStop(evt, options === null || options === void 0 ? void 0 : options.size,
|
|
101
|
+
_onResizeStop === null || _onResizeStop === void 0 ? void 0 : _onResizeStop(evt, options === null || options === void 0 ? void 0 : options.size, index, colWidths);
|
|
95
102
|
}
|
|
96
103
|
}, cell)) : cell;
|
|
97
104
|
}));
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
import { useRef, useEffect } from 'react';
|
|
11
|
+
var useChange = function useChange(_ref) {
|
|
12
|
+
var activeSorterColumn = _ref.activeSorterColumn,
|
|
13
|
+
activeSorterType = _ref.activeSorterType,
|
|
14
|
+
columns = _ref.columns,
|
|
15
|
+
showData = _ref.showData,
|
|
16
|
+
onChange = _ref.onChange;
|
|
17
|
+
var changeRef = useRef({
|
|
18
|
+
sort: {
|
|
19
|
+
activeSorterColumn: activeSorterColumn,
|
|
20
|
+
activeSorterType: activeSorterType
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
useEffect(function () {
|
|
24
|
+
var sort = changeRef.current.sort;
|
|
25
|
+
var sortNotChange = sort.activeSorterColumn === activeSorterColumn && sort.activeSorterType === activeSorterType;
|
|
26
|
+
if (sortNotChange) return;
|
|
27
|
+
var changeObj = {
|
|
28
|
+
sorter: {
|
|
29
|
+
order: activeSorterType,
|
|
30
|
+
column: columns.filter(function (d) {
|
|
31
|
+
return d.dataKey === activeSorterColumn;
|
|
32
|
+
})[0]
|
|
33
|
+
},
|
|
34
|
+
extra: {
|
|
35
|
+
action: 'sorter',
|
|
36
|
+
currentDataSource: showData.map(function (d) {
|
|
37
|
+
return d.raw;
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
onChange === null || onChange === void 0 ? void 0 : onChange({
|
|
42
|
+
sorter: changeObj.sorter
|
|
43
|
+
}, changeObj.extra);
|
|
44
|
+
sort.activeSorterColumn = activeSorterColumn;
|
|
45
|
+
sort.activeSorterType = activeSorterType;
|
|
46
|
+
}, [activeSorterColumn, activeSorterType, columns, showData, onChange]);
|
|
47
|
+
};
|
|
48
|
+
export { useChange };
|
|
@@ -31,7 +31,8 @@ var useColumns = function useColumns(_ref) {
|
|
|
31
31
|
dataKey: raw.dataKey,
|
|
32
32
|
title: raw.title,
|
|
33
33
|
align: (_a = raw.align) !== null && _a !== void 0 ? _a : 'left',
|
|
34
|
-
render: raw.render
|
|
34
|
+
render: raw.render,
|
|
35
|
+
colSpan: raw.colSpan
|
|
35
36
|
});
|
|
36
37
|
});
|
|
37
38
|
// 记录下标位置,方便冻结列操作计算时快速获取更新
|
|
@@ -62,9 +63,10 @@ var useColumns = function useColumns(_ref) {
|
|
|
62
63
|
// 在最后一层,colSpan = 1, rowSpan = maxDepth - depth + 1
|
|
63
64
|
// 不在最后一层,rowSpan = 1, colSpan = 叶子节点后代数量
|
|
64
65
|
flattedColumns.forEach(function (column) {
|
|
66
|
+
var _a;
|
|
65
67
|
if (isLeaf(column)) {
|
|
66
68
|
column.rowSpan = maxColumnDepth - column.depth + 1;
|
|
67
|
-
column.colSpan = 1;
|
|
69
|
+
column.colSpan = (_a = column.colSpan) !== null && _a !== void 0 ? _a : 1;
|
|
68
70
|
} else {
|
|
69
71
|
column.rowSpan = 1;
|
|
70
72
|
column.colSpan = getLeafChildren(column).length;
|
package/lib/esm/use-table.js
CHANGED
|
@@ -20,6 +20,7 @@ import { useLatestCallback } from '@hi-ui/use-latest';
|
|
|
20
20
|
import { setColumnsDefaultWidth, parseFixedColumns } from './utils/index.js';
|
|
21
21
|
import { useAsyncSwitch } from './hooks/use-async-switch.js';
|
|
22
22
|
import { useExpand } from './hooks/use-expand.js';
|
|
23
|
+
import { useChange } from './hooks/use-change.js';
|
|
23
24
|
import { useColWidth } from './hooks/use-col-width.js';
|
|
24
25
|
import { useColumns } from './hooks/use-colgroup.js';
|
|
25
26
|
import { useTableDrag } from './hooks/use-drag.js';
|
|
@@ -79,7 +80,9 @@ var useTable = function useTable(_a) {
|
|
|
79
80
|
scrollbar = _a.scrollbar,
|
|
80
81
|
rowClassName = _a.rowClassName,
|
|
81
82
|
cellClassName = _a.cellClassName,
|
|
82
|
-
|
|
83
|
+
onChange = _a.onChange,
|
|
84
|
+
onHighlightedCol = _a.onHighlightedCol,
|
|
85
|
+
rootProps = __rest(_a, ["data", "columns", "defaultFixedToColumn", "fixedToColumn", "onFixedToColumn", "scrollWidth", "resizable", "errorRowKeys", "highlightedColKeys", "highlightedRowKeys", "showColHighlight", "showRowHighlight", "highlightRowOnDoubleClick", "defaultExpandedRowKeys", "expandedRowKeys", "onExpand", "defaultExpandAll", "onLoadChildren", "maxHeight", "sticky", "stickyTop", "draggable", "onDragStart", "onDrop", "onDropEnd", "showColMenu", "rowSelection", "cellRender", "footerRender", "fieldKey", "virtual", "scrollbar", "rowClassName", "cellClassName", "onChange", "onHighlightedCol"]);
|
|
83
86
|
/**
|
|
84
87
|
* 获取 key 字段值
|
|
85
88
|
*/
|
|
@@ -501,6 +504,13 @@ var useTable = function useTable(_a) {
|
|
|
501
504
|
}
|
|
502
505
|
return _data;
|
|
503
506
|
}, [activeSorterColumn, activeSorterType, transitionData, columns]);
|
|
507
|
+
useChange({
|
|
508
|
+
activeSorterColumn: activeSorterColumn,
|
|
509
|
+
activeSorterType: activeSorterType,
|
|
510
|
+
columns: columns,
|
|
511
|
+
showData: showData,
|
|
512
|
+
onChange: onChange
|
|
513
|
+
});
|
|
504
514
|
return Object.assign(Object.assign({
|
|
505
515
|
measureRowElementRef: measureRowElementRef,
|
|
506
516
|
rootProps: rootProps,
|
|
@@ -582,7 +592,8 @@ var useTable = function useTable(_a) {
|
|
|
582
592
|
setHeaderTableElement: setHeaderTableElement,
|
|
583
593
|
scrollbar: scrollbar,
|
|
584
594
|
rowClassName: rowClassName,
|
|
585
|
-
cellClassName: cellClassName
|
|
595
|
+
cellClassName: cellClassName,
|
|
596
|
+
onHighlightedCol: onHighlightedCol
|
|
586
597
|
});
|
|
587
598
|
};
|
|
588
599
|
export { useTable };
|
|
@@ -32,6 +32,10 @@ export interface SettingDrawerProps extends HiBaseHTMLProps<'div'> {
|
|
|
32
32
|
* 确认设置回调
|
|
33
33
|
*/
|
|
34
34
|
onSetColKeysChange?: (sortedColKeys: string[], hiddenColKeys: string[], visibleCols: TableColumnItem[]) => void;
|
|
35
|
+
/**
|
|
36
|
+
* 重置按钮点击时回调
|
|
37
|
+
*/
|
|
38
|
+
onReset?: () => void;
|
|
35
39
|
/**
|
|
36
40
|
* 隐藏列
|
|
37
41
|
*/
|
package/lib/types/context.d.ts
CHANGED
|
@@ -48,6 +48,10 @@ export declare const TableProvider: import("react").Provider<(Omit<{
|
|
|
48
48
|
scrollbar: boolean | import("packages/ui/scrollbar/lib/types").ScrollbarProps | undefined;
|
|
49
49
|
rowClassName: ((record: Record<string, any>, index: number) => string) | undefined;
|
|
50
50
|
cellClassName: ((record: Record<string, any>, column: Record<string, any>, index: number) => string) | undefined;
|
|
51
|
+
onHighlightedCol: ((changedColInfo: {
|
|
52
|
+
active: boolean;
|
|
53
|
+
column: import("./types").TableColumnItem;
|
|
54
|
+
}, highlightedColKeys: string[]) => void) | undefined;
|
|
51
55
|
scrollLeft: number;
|
|
52
56
|
scrollRight: number;
|
|
53
57
|
measureRowElementRef: import("react").MutableRefObject<HTMLTableRowElement | null>;
|
|
@@ -171,6 +175,10 @@ export declare const useTableContext: () => Omit<{
|
|
|
171
175
|
scrollbar: boolean | import("packages/ui/scrollbar/lib/types").ScrollbarProps | undefined;
|
|
172
176
|
rowClassName: ((record: Record<string, any>, index: number) => string) | undefined;
|
|
173
177
|
cellClassName: ((record: Record<string, any>, column: Record<string, any>, index: number) => string) | undefined;
|
|
178
|
+
onHighlightedCol: ((changedColInfo: {
|
|
179
|
+
active: boolean;
|
|
180
|
+
column: import("./types").TableColumnItem;
|
|
181
|
+
}, highlightedColKeys: string[]) => void) | undefined;
|
|
174
182
|
scrollLeft: number;
|
|
175
183
|
scrollRight: number;
|
|
176
184
|
measureRowElementRef: import("react").MutableRefObject<HTMLTableRowElement | null>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TableColumnItem, FlattedTableRowData } from '../types';
|
|
2
|
+
export interface Sorter {
|
|
3
|
+
order: string | null;
|
|
4
|
+
column: TableColumnItem;
|
|
5
|
+
}
|
|
6
|
+
export interface Action {
|
|
7
|
+
sorter?: Sorter;
|
|
8
|
+
}
|
|
9
|
+
export interface Extra {
|
|
10
|
+
action: keyof Action;
|
|
11
|
+
currentDataSource: object[];
|
|
12
|
+
}
|
|
13
|
+
export interface UseChangeProps {
|
|
14
|
+
activeSorterColumn: string | null;
|
|
15
|
+
activeSorterType: string | null;
|
|
16
|
+
columns: TableColumnItem[];
|
|
17
|
+
showData: FlattedTableRowData[];
|
|
18
|
+
onChange?: (action: Action, extra: Extra) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare const useChange: ({ activeSorterColumn, activeSorterType, columns, showData, onChange, }: UseChangeProps) => void;
|
package/lib/types/types.d.ts
CHANGED
package/lib/types/use-table.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { PaginationProps } from '@hi-ui/pagination';
|
|
3
3
|
import { ScrollbarProps } from '@hi-ui/scrollbar';
|
|
4
|
+
import { Action, Extra } from './hooks/use-change';
|
|
4
5
|
import { TableColumnItem, TableFrozenColumnOptions, TableRowEventData, TableRowSelection, FlattedTableColumnItemData, FlattedTableRowData } from './types';
|
|
5
|
-
export declare const useTable: ({ data, columns: columnsProp, defaultFixedToColumn, fixedToColumn: fixedToColumnProp, onFixedToColumn, scrollWidth, resizable, errorRowKeys, highlightedColKeys: highlightedColKeysProp, highlightedRowKeys: highlightedRowKeysProp, showColHighlight, showRowHighlight, highlightRowOnDoubleClick, defaultExpandedRowKeys, expandedRowKeys: expandRowKeysProp, onExpand, defaultExpandAll, onLoadChildren, maxHeight, sticky, stickyTop, draggable, onDragStart, onDrop: onDropProp, onDropEnd, showColMenu, rowSelection, cellRender, footerRender, fieldKey, virtual, scrollbar, rowClassName, cellClassName, ...rootProps }: UseTableProps) => {
|
|
6
|
+
export declare const useTable: ({ data, columns: columnsProp, defaultFixedToColumn, fixedToColumn: fixedToColumnProp, onFixedToColumn, scrollWidth, resizable, errorRowKeys, highlightedColKeys: highlightedColKeysProp, highlightedRowKeys: highlightedRowKeysProp, showColHighlight, showRowHighlight, highlightRowOnDoubleClick, defaultExpandedRowKeys, expandedRowKeys: expandRowKeysProp, onExpand, defaultExpandAll, onLoadChildren, maxHeight, sticky, stickyTop, draggable, onDragStart, onDrop: onDropProp, onDropEnd, showColMenu, rowSelection, cellRender, footerRender, fieldKey, virtual, scrollbar, rowClassName, cellClassName, onChange, onHighlightedCol, ...rootProps }: UseTableProps) => {
|
|
6
7
|
getColgroupProps: (column: FlattedTableColumnItemData, index: number) => {
|
|
7
8
|
style: {
|
|
8
9
|
width: number | undefined;
|
|
@@ -49,6 +50,10 @@ export declare const useTable: ({ data, columns: columnsProp, defaultFixedToColu
|
|
|
49
50
|
scrollbar: boolean | ScrollbarProps | undefined;
|
|
50
51
|
rowClassName: ((record: Record<string, any>, index: number) => string) | undefined;
|
|
51
52
|
cellClassName: ((record: Record<string, any>, column: Record<string, any>, index: number) => string) | undefined;
|
|
53
|
+
onHighlightedCol: ((changedColInfo: {
|
|
54
|
+
active: boolean;
|
|
55
|
+
column: TableColumnItem;
|
|
56
|
+
}, highlightedColKeys: string[]) => void) | undefined;
|
|
52
57
|
scrollLeft: number;
|
|
53
58
|
scrollRight: number;
|
|
54
59
|
measureRowElementRef: React.MutableRefObject<HTMLTableRowElement | null>;
|
|
@@ -303,5 +308,16 @@ export interface UseTableProps {
|
|
|
303
308
|
* 设置单元格类名
|
|
304
309
|
*/
|
|
305
310
|
cellClassName?: (record: Record<string, any>, column: Record<string, any>, index: number) => string;
|
|
311
|
+
/**
|
|
312
|
+
* 设置排序变化回调
|
|
313
|
+
*/
|
|
314
|
+
onChange?: (action: Action, extra: Extra) => void;
|
|
315
|
+
/**
|
|
316
|
+
* 设置列高亮回调
|
|
317
|
+
*/
|
|
318
|
+
onHighlightedCol?: (changedColInfo: {
|
|
319
|
+
active: boolean;
|
|
320
|
+
column: TableColumnItem;
|
|
321
|
+
}, highlightedColKeys: string[]) => void;
|
|
306
322
|
}
|
|
307
323
|
export declare type UseTableReturn = ReturnType<typeof useTable>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hi-ui/table",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.0",
|
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "HiUI <mi-hiui@xiaomi.com>",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
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
|
-
"@hi-ui/scrollbar": "^4.
|
|
63
|
-
"@hi-ui/select": "^4.
|
|
62
|
+
"@hi-ui/scrollbar": "^4.2.0",
|
|
63
|
+
"@hi-ui/select": "^4.6.0",
|
|
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",
|