@hi-ui/table 5.0.0 → 5.0.1-alpha.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
CHANGED
|
@@ -22,6 +22,28 @@ function _interopDefaultCompat(e) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
25
|
+
var getVirtualColWidths = function getVirtualColWidths(columns, containerWidth, currentWidths) {
|
|
26
|
+
if (currentWidths === void 0) {
|
|
27
|
+
currentWidths = [];
|
|
28
|
+
}
|
|
29
|
+
var columnDefaultWidth = 200;
|
|
30
|
+
var hasCurrentWidths = currentWidths.length === columns.length && currentWidths.every(function (width) {
|
|
31
|
+
return width > 0;
|
|
32
|
+
});
|
|
33
|
+
var baseWidths = hasCurrentWidths ? currentWidths : columns.map(function (columnItem) {
|
|
34
|
+
return columnItem.width || columnDefaultWidth;
|
|
35
|
+
});
|
|
36
|
+
var totalWidth = baseWidths.reduce(function (total, width) {
|
|
37
|
+
return total + width;
|
|
38
|
+
}, 0);
|
|
39
|
+
if (totalWidth > 0 && totalWidth < containerWidth) {
|
|
40
|
+
// 容器宽度大于设置的宽度总和时,col宽度等比分配占满容器。
|
|
41
|
+
return baseWidths.map(function (width) {
|
|
42
|
+
return width * containerWidth / totalWidth;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return baseWidths;
|
|
46
|
+
};
|
|
25
47
|
var useColWidth = function useColWidth(_ref) {
|
|
26
48
|
var resizable = _ref.resizable,
|
|
27
49
|
tableWidthAdjustOnResize = _ref.tableWidthAdjustOnResize,
|
|
@@ -36,6 +58,10 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
36
58
|
}),
|
|
37
59
|
colWidths = _React$useState[0],
|
|
38
60
|
setColWidths = _React$useState[1];
|
|
61
|
+
var colWidthsRef = React__default["default"].useRef(colWidths);
|
|
62
|
+
React__default["default"].useEffect(function () {
|
|
63
|
+
colWidthsRef.current = colWidths;
|
|
64
|
+
}, [colWidths]);
|
|
39
65
|
/**
|
|
40
66
|
* 根据实际内容区(table 的第一行)渲染,再次精确收集并设置每列宽度
|
|
41
67
|
* 如果实际总宽度大于设置的宽度,则将多余的宽度平分到没有设置 fixed 的列上
|
|
@@ -87,24 +113,7 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
87
113
|
return index.getGroupItemWidth(columns).colWidths;
|
|
88
114
|
}
|
|
89
115
|
/** 虚拟滚动时,内容宽度不能用以前table自动渲染的方式获取,需要手动计算 */
|
|
90
|
-
|
|
91
|
-
var containerWidth = measureRowElement.clientWidth;
|
|
92
|
-
var totalWidth = 0;
|
|
93
|
-
/** 虚拟滚动,需要根据collist的虚拟宽度来计算宽度 */
|
|
94
|
-
columns.forEach(function (columnItem) {
|
|
95
|
-
totalWidth += columnItem.width || columnDefaultWidth;
|
|
96
|
-
});
|
|
97
|
-
if (totalWidth < containerWidth) {
|
|
98
|
-
// 容器宽度大于设置的宽度总和时,col宽度等比分分配占满容器。
|
|
99
|
-
return columns.map(function (columnItem) {
|
|
100
|
-
return (columnItem.width || columnDefaultWidth) * containerWidth / totalWidth;
|
|
101
|
-
});
|
|
102
|
-
} else {
|
|
103
|
-
// 容器宽度小于设置的宽度总和时,col宽度等于设置/默认宽度。
|
|
104
|
-
return columns.map(function (columnItem) {
|
|
105
|
-
return columnItem.width || columnDefaultWidth;
|
|
106
|
-
});
|
|
107
|
-
}
|
|
116
|
+
return getVirtualColWidths(columns, measureRowElement.clientWidth, colWidthsRef.current);
|
|
108
117
|
}, [columns]);
|
|
109
118
|
// 记录上一轮的列,用于判断列是否发生变化,只有发生变化时才重新计算列宽
|
|
110
119
|
var prevColumnsRef = React__default["default"].useRef(columns);
|
|
@@ -260,4 +269,5 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
260
269
|
colWidths: colWidths
|
|
261
270
|
};
|
|
262
271
|
};
|
|
272
|
+
exports.getVirtualColWidths = getVirtualColWidths;
|
|
263
273
|
exports.useColWidth = useColWidth;
|
|
@@ -10,6 +10,28 @@
|
|
|
10
10
|
import React__default, { useCallback } from 'react';
|
|
11
11
|
import { getGroupItemWidth } from '../utils/index.js';
|
|
12
12
|
import { useUpdateEffect } from '@hi-ui/use-update-effect';
|
|
13
|
+
var getVirtualColWidths = function getVirtualColWidths(columns, containerWidth, currentWidths) {
|
|
14
|
+
if (currentWidths === void 0) {
|
|
15
|
+
currentWidths = [];
|
|
16
|
+
}
|
|
17
|
+
var columnDefaultWidth = 200;
|
|
18
|
+
var hasCurrentWidths = currentWidths.length === columns.length && currentWidths.every(function (width) {
|
|
19
|
+
return width > 0;
|
|
20
|
+
});
|
|
21
|
+
var baseWidths = hasCurrentWidths ? currentWidths : columns.map(function (columnItem) {
|
|
22
|
+
return columnItem.width || columnDefaultWidth;
|
|
23
|
+
});
|
|
24
|
+
var totalWidth = baseWidths.reduce(function (total, width) {
|
|
25
|
+
return total + width;
|
|
26
|
+
}, 0);
|
|
27
|
+
if (totalWidth > 0 && totalWidth < containerWidth) {
|
|
28
|
+
// 容器宽度大于设置的宽度总和时,col宽度等比分配占满容器。
|
|
29
|
+
return baseWidths.map(function (width) {
|
|
30
|
+
return width * containerWidth / totalWidth;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return baseWidths;
|
|
34
|
+
};
|
|
13
35
|
var useColWidth = function useColWidth(_ref) {
|
|
14
36
|
var resizable = _ref.resizable,
|
|
15
37
|
tableWidthAdjustOnResize = _ref.tableWidthAdjustOnResize,
|
|
@@ -24,6 +46,10 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
24
46
|
}),
|
|
25
47
|
colWidths = _React$useState[0],
|
|
26
48
|
setColWidths = _React$useState[1];
|
|
49
|
+
var colWidthsRef = React__default.useRef(colWidths);
|
|
50
|
+
React__default.useEffect(function () {
|
|
51
|
+
colWidthsRef.current = colWidths;
|
|
52
|
+
}, [colWidths]);
|
|
27
53
|
/**
|
|
28
54
|
* 根据实际内容区(table 的第一行)渲染,再次精确收集并设置每列宽度
|
|
29
55
|
* 如果实际总宽度大于设置的宽度,则将多余的宽度平分到没有设置 fixed 的列上
|
|
@@ -75,24 +101,7 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
75
101
|
return getGroupItemWidth(columns).colWidths;
|
|
76
102
|
}
|
|
77
103
|
/** 虚拟滚动时,内容宽度不能用以前table自动渲染的方式获取,需要手动计算 */
|
|
78
|
-
|
|
79
|
-
var containerWidth = measureRowElement.clientWidth;
|
|
80
|
-
var totalWidth = 0;
|
|
81
|
-
/** 虚拟滚动,需要根据collist的虚拟宽度来计算宽度 */
|
|
82
|
-
columns.forEach(function (columnItem) {
|
|
83
|
-
totalWidth += columnItem.width || columnDefaultWidth;
|
|
84
|
-
});
|
|
85
|
-
if (totalWidth < containerWidth) {
|
|
86
|
-
// 容器宽度大于设置的宽度总和时,col宽度等比分分配占满容器。
|
|
87
|
-
return columns.map(function (columnItem) {
|
|
88
|
-
return (columnItem.width || columnDefaultWidth) * containerWidth / totalWidth;
|
|
89
|
-
});
|
|
90
|
-
} else {
|
|
91
|
-
// 容器宽度小于设置的宽度总和时,col宽度等于设置/默认宽度。
|
|
92
|
-
return columns.map(function (columnItem) {
|
|
93
|
-
return columnItem.width || columnDefaultWidth;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
104
|
+
return getVirtualColWidths(columns, measureRowElement.clientWidth, colWidthsRef.current);
|
|
96
105
|
}, [columns]);
|
|
97
106
|
// 记录上一轮的列,用于判断列是否发生变化,只有发生变化时才重新计算列宽
|
|
98
107
|
var prevColumnsRef = React__default.useRef(columns);
|
|
@@ -248,4 +257,4 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
248
257
|
colWidths: colWidths
|
|
249
258
|
};
|
|
250
259
|
};
|
|
251
|
-
export { useColWidth };
|
|
260
|
+
export { getVirtualColWidths, useColWidth };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FlattedTableColumnItemData, TableColumnItem, TableRowRecord } from '../types';
|
|
3
|
+
export declare const getVirtualColWidths: (columns: TableColumnItem[], containerWidth: number, currentWidths?: number[]) => number[];
|
|
3
4
|
export declare const useColWidth: ({ resizable, tableWidthAdjustOnResize, data, columns, virtual, scrollBodyElementRef, }: {
|
|
4
5
|
resizable: boolean;
|
|
5
6
|
tableWidthAdjustOnResize: boolean;
|