@hi-ui/table 4.3.1 → 4.3.2
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 +40 -0
- package/lib/cjs/BaseTable.js +136 -189
- package/lib/cjs/ColGroupContent.js +5 -28
- package/lib/cjs/SettingDrawer.js +76 -127
- package/lib/cjs/Table.js +107 -171
- package/lib/cjs/TableAdvancedFilter.js +49 -85
- package/lib/cjs/TableBody.js +33 -69
- package/lib/cjs/TableCell.js +56 -102
- package/lib/cjs/TableColumnMenu.js +39 -77
- package/lib/cjs/TableEmbedRow.js +11 -38
- package/lib/cjs/TableHeader.js +8 -33
- package/lib/cjs/TableRow.js +48 -88
- package/lib/cjs/TableSettingMenu.js +48 -94
- package/lib/cjs/TbodyContent.js +28 -56
- package/lib/cjs/TheadContent.js +20 -49
- package/lib/cjs/_virtual/index.js +0 -3
- package/lib/cjs/_virtual/index2.js +0 -3
- package/lib/cjs/_virtual/react-is.development.js +0 -3
- package/lib/cjs/_virtual/react-is.production.min.js +0 -3
- package/lib/cjs/context.js +0 -9
- package/lib/cjs/hooks/use-async-switch.js +13 -51
- package/lib/cjs/hooks/use-check.js +47 -77
- package/lib/cjs/hooks/use-col-hidden.js +16 -28
- package/lib/cjs/hooks/use-col-set.js +5 -18
- package/lib/cjs/hooks/use-col-sorter.js +18 -32
- package/lib/cjs/hooks/use-col-width.js +21 -57
- package/lib/cjs/hooks/use-colgroup.js +63 -85
- package/lib/cjs/hooks/use-drag.js +10 -31
- package/lib/cjs/hooks/use-embed-expand.js +23 -68
- package/lib/cjs/hooks/use-expand.js +32 -64
- package/lib/cjs/hooks/use-pagination.js +19 -50
- package/lib/cjs/hooks/use-queue.js +2 -14
- package/lib/cjs/icons/index.js +4 -21
- package/lib/cjs/index.js +0 -4
- package/lib/cjs/node_modules/classnames/index.js +2 -11
- package/lib/cjs/node_modules/perfect-scrollbar/dist/perfect-scrollbar.esm.js +31 -227
- package/lib/cjs/node_modules/rc-resize-observer/es/index.js +10 -68
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/Children/toArray.js +1 -17
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/Dom/findDOMNode.js +1 -14
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/ref.js +1 -25
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/warning.js +1 -5
- package/lib/cjs/node_modules/rc-util/es/Dom/canUseDom.js +0 -2
- package/lib/cjs/node_modules/rc-util/es/Dom/findDOMNode.js +1 -14
- package/lib/cjs/node_modules/rc-util/es/hooks/useLayoutEffect.js +2 -9
- package/lib/cjs/node_modules/rc-util/es/raf.js +0 -11
- package/lib/cjs/node_modules/rc-virtual-list/es/Filler.js +6 -25
- package/lib/cjs/node_modules/rc-virtual-list/es/Item.js +3 -14
- package/lib/cjs/node_modules/rc-virtual-list/es/List.js +103 -194
- package/lib/cjs/node_modules/rc-virtual-list/es/ScrollBar.js +16 -96
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useChildren.js +2 -11
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useDiffItem.js +8 -34
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js +0 -10
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useHeights.js +6 -39
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js +0 -16
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useOriginScroll.js +4 -9
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useScrollTo.js +3 -28
- package/lib/cjs/node_modules/rc-virtual-list/es/index.js +0 -2
- package/lib/cjs/node_modules/rc-virtual-list/es/utils/CacheMap.js +2 -9
- package/lib/cjs/node_modules/rc-virtual-list/es/utils/algorithmUtil.js +0 -15
- package/lib/cjs/node_modules/rc-virtual-list/es/utils/isFirefox.js +0 -2
- package/lib/cjs/node_modules/react-is/cjs/react-is.development.js +3 -29
- package/lib/cjs/node_modules/react-is/cjs/react-is.production.min.js +19 -45
- package/lib/cjs/node_modules/react-is/index.js +0 -5
- package/lib/cjs/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +83 -248
- package/lib/cjs/packages/hooks/use-merge-refs/lib/esm/index.js +3 -14
- package/lib/cjs/packages/ui/scrollbar/lib/esm/Scrollbar.js +48 -86
- package/lib/cjs/packages/ui/scrollbar/lib/esm/styles/index.scss.js +1 -15
- package/lib/cjs/packages/ui/scrollbar/lib/esm/utils/index.js +0 -13
- package/lib/cjs/styles/index.scss.js +1 -4
- package/lib/cjs/use-table.js +268 -355
- package/lib/cjs/utils/index.js +11 -45
- package/lib/esm/BaseTable.js +117 -138
- package/lib/esm/ColGroupContent.js +3 -9
- package/lib/esm/SettingDrawer.js +64 -83
- package/lib/esm/Table.js +97 -124
- package/lib/esm/TableAdvancedFilter.js +37 -47
- package/lib/esm/TableBody.js +24 -34
- package/lib/esm/TableCell.js +48 -72
- package/lib/esm/TableColumnMenu.js +24 -38
- package/lib/esm/TableEmbedRow.js +8 -15
- package/lib/esm/TableHeader.js +5 -11
- package/lib/esm/TableRow.js +36 -51
- package/lib/esm/TableSettingMenu.js +33 -49
- package/lib/esm/TbodyContent.js +20 -27
- package/lib/esm/TheadContent.js +14 -21
- package/lib/esm/context.js +0 -4
- package/lib/esm/hooks/use-async-switch.js +9 -28
- package/lib/esm/hooks/use-check.js +42 -55
- package/lib/esm/hooks/use-col-hidden.js +16 -21
- package/lib/esm/hooks/use-col-set.js +5 -13
- package/lib/esm/hooks/use-col-sorter.js +18 -23
- package/lib/esm/hooks/use-col-width.js +14 -34
- package/lib/esm/hooks/use-colgroup.js +60 -66
- package/lib/esm/hooks/use-drag.js +9 -13
- package/lib/esm/hooks/use-embed-expand.js +20 -42
- package/lib/esm/hooks/use-expand.js +32 -56
- package/lib/esm/hooks/use-pagination.js +13 -25
- package/lib/esm/hooks/use-queue.js +2 -10
- package/lib/esm/node_modules/classnames/index.js +2 -9
- package/lib/esm/node_modules/perfect-scrollbar/dist/perfect-scrollbar.esm.js +31 -228
- package/lib/esm/node_modules/rc-resize-observer/es/index.js +3 -26
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/Children/toArray.js +0 -3
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/Dom/findDOMNode.js +1 -2
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/ref.js +0 -8
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/warning.js +0 -5
- package/lib/esm/node_modules/rc-util/es/Dom/canUseDom.js +0 -1
- package/lib/esm/node_modules/rc-util/es/Dom/findDOMNode.js +1 -2
- package/lib/esm/node_modules/rc-util/es/hooks/useLayoutEffect.js +1 -0
- package/lib/esm/node_modules/rc-util/es/raf.js +0 -10
- package/lib/esm/node_modules/rc-virtual-list/es/Filler.js +4 -15
- package/lib/esm/node_modules/rc-virtual-list/es/Item.js +1 -3
- package/lib/esm/node_modules/rc-virtual-list/es/List.js +101 -174
- package/lib/esm/node_modules/rc-virtual-list/es/ScrollBar.js +14 -86
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useChildren.js +0 -2
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useDiffItem.js +6 -25
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js +0 -6
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useHeights.js +4 -28
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js +0 -13
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useOriginScroll.js +4 -8
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useScrollTo.js +1 -19
- package/lib/esm/node_modules/rc-virtual-list/es/index.js +1 -1
- package/lib/esm/node_modules/rc-virtual-list/es/utils/CacheMap.js +2 -8
- package/lib/esm/node_modules/rc-virtual-list/es/utils/algorithmUtil.js +1 -12
- package/lib/esm/node_modules/rc-virtual-list/es/utils/isFirefox.js +0 -1
- package/lib/esm/node_modules/react-is/cjs/react-is.development.js +4 -27
- package/lib/esm/node_modules/react-is/cjs/react-is.production.min.js +20 -44
- package/lib/esm/node_modules/react-is/index.js +0 -1
- package/lib/esm/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +82 -248
- package/lib/esm/packages/hooks/use-merge-refs/lib/esm/index.js +3 -9
- package/lib/esm/packages/ui/scrollbar/lib/esm/Scrollbar.js +47 -64
- package/lib/esm/packages/ui/scrollbar/lib/esm/styles/index.scss.js +1 -3
- package/lib/esm/packages/ui/scrollbar/lib/esm/utils/index.js +0 -10
- package/lib/esm/styles/index.scss.js +1 -3
- package/lib/esm/use-table.js +261 -318
- package/lib/esm/utils/index.js +11 -41
- package/lib/types/BaseTable.d.ts +2 -2
- package/package.json +33 -33
|
@@ -11,39 +11,34 @@ import { useCheck } from '@hi-ui/use-check';
|
|
|
11
11
|
import React__default from 'react';
|
|
12
12
|
import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
|
|
13
13
|
var DEFAULT_CHECKED_ROW_KEYS = [];
|
|
14
|
-
|
|
15
14
|
var useTableCheck = function useTableCheck(_ref) {
|
|
16
15
|
var rowSelection = _ref.rowSelection,
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
flattedData = _ref.flattedData,
|
|
17
|
+
fieldKey = _ref.fieldKey;
|
|
19
18
|
var checkRowIsDisabledCheckbox = React__default.useCallback(function (rowItem) {
|
|
20
19
|
var checkboxConfig = rowSelection && rowSelection.getCheckboxConfig && rowSelection.getCheckboxConfig(rowItem);
|
|
21
20
|
return checkboxConfig && checkboxConfig.disabled || false;
|
|
22
21
|
}, [rowSelection]);
|
|
23
|
-
|
|
24
22
|
var _useUncontrolledState = useUncontrolledState(DEFAULT_CHECKED_ROW_KEYS, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.onChange),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
checkedRowKeys = _useUncontrolledState[0],
|
|
24
|
+
trySetCheckedRowKeys = _useUncontrolledState[1];
|
|
25
|
+
// 已选中的行数据集合
|
|
29
26
|
var checkedRowDataItemsRef = React__default.useRef([]);
|
|
30
|
-
var checkedRowDataItems = checkedRowDataItemsRef.current;
|
|
31
|
-
|
|
27
|
+
var checkedRowDataItems = checkedRowDataItemsRef.current;
|
|
28
|
+
// TODO: 暂时不支持正反选
|
|
32
29
|
var _useCheck = useCheck({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
checkedIds: checkedRowKeys,
|
|
31
|
+
onCheck: function onCheck(checkedRowKeys, rowItem, checked) {
|
|
32
|
+
trySetCheckedRowKeys(checkedRowKeys, rowItem, checked, checkedRowDataItemsRef.current);
|
|
33
|
+
},
|
|
34
|
+
idFieldName: fieldKey
|
|
35
|
+
}),
|
|
36
|
+
handleCheckedRowKeysChange = _useCheck[0],
|
|
37
|
+
isCheckedRowKey = _useCheck[1];
|
|
38
|
+
// 选中项变化会触发该函数
|
|
43
39
|
var onCheckedRowKeysChange = React__default.useCallback(function (rowItem, checked) {
|
|
44
40
|
// 记录选中的行数据集合
|
|
45
41
|
var nextCheckedDataItems = checkedRowDataItems;
|
|
46
|
-
|
|
47
42
|
if (checked) {
|
|
48
43
|
if (!nextCheckedDataItems.find(function (item) {
|
|
49
44
|
return item[fieldKey] === rowItem[fieldKey];
|
|
@@ -55,39 +50,33 @@ var useTableCheck = function useTableCheck(_ref) {
|
|
|
55
50
|
return item[fieldKey] !== rowItem[fieldKey];
|
|
56
51
|
});
|
|
57
52
|
}
|
|
58
|
-
|
|
59
53
|
handleCheckedRowKeysChange(rowItem, checked);
|
|
60
|
-
}, [checkedRowDataItems, fieldKey, handleCheckedRowKeysChange]);
|
|
61
|
-
|
|
54
|
+
}, [checkedRowDataItems, fieldKey, handleCheckedRowKeysChange]);
|
|
55
|
+
// 判断是否全选
|
|
62
56
|
var _React$useMemo = React__default.useMemo(function () {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
if (rowSelection) {
|
|
58
|
+
if (flattedData.length === 0 || checkedRowKeys.length === 0) {
|
|
59
|
+
return [false, false];
|
|
60
|
+
}
|
|
61
|
+
var idsCanBeChecked = flattedData.filter(function (item) {
|
|
62
|
+
return !checkRowIsDisabledCheckbox(item.raw);
|
|
63
|
+
}).map(function (item) {
|
|
64
|
+
return item.id;
|
|
65
|
+
});
|
|
66
|
+
// TODO: 数组项完全匹配工具函数
|
|
67
|
+
// TODO: 数组项完全匹配工具函数
|
|
68
|
+
var _checkedAll = idsCanBeChecked.every(function (id) {
|
|
69
|
+
return isCheckedRowKey(id);
|
|
70
|
+
});
|
|
71
|
+
var _semiChecked = _checkedAll ? false : checkedRowKeys.length > 0 && idsCanBeChecked.some(function (id) {
|
|
72
|
+
return isCheckedRowKey(id);
|
|
73
|
+
});
|
|
74
|
+
return [_checkedAll, _semiChecked];
|
|
66
75
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return item.id;
|
|
72
|
-
}); // TODO: 数组项完全匹配工具函数
|
|
73
|
-
// TODO: 数组项完全匹配工具函数
|
|
74
|
-
|
|
75
|
-
var _checkedAll = idsCanBeChecked.every(function (id) {
|
|
76
|
-
return isCheckedRowKey(id);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
var _semiChecked = _checkedAll ? false : checkedRowKeys.length > 0 && idsCanBeChecked.some(function (id) {
|
|
80
|
-
return isCheckedRowKey(id);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return [_checkedAll, _semiChecked];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return [false, false];
|
|
87
|
-
}, [flattedData, rowSelection, isCheckedRowKey, checkedRowKeys.length, checkRowIsDisabledCheckbox]),
|
|
88
|
-
checkedAll = _React$useMemo[0],
|
|
89
|
-
semiChecked = _React$useMemo[1];
|
|
90
|
-
|
|
76
|
+
return [false, false];
|
|
77
|
+
}, [flattedData, rowSelection, isCheckedRowKey, checkedRowKeys.length, checkRowIsDisabledCheckbox]),
|
|
78
|
+
checkedAll = _React$useMemo[0],
|
|
79
|
+
semiChecked = _React$useMemo[1];
|
|
91
80
|
var tryCheckAllRow = React__default.useCallback(function () {
|
|
92
81
|
var targetItems = flattedData.filter(function (item) {
|
|
93
82
|
return !checkRowIsDisabledCheckbox(item.raw);
|
|
@@ -99,7 +88,6 @@ var useTableCheck = function useTableCheck(_ref) {
|
|
|
99
88
|
return item.raw;
|
|
100
89
|
});
|
|
101
90
|
var checkedRowKeysSet = new Set(checkedRowKeys);
|
|
102
|
-
|
|
103
91
|
if (checkedAll) {
|
|
104
92
|
// 移除当前页所有行 ids
|
|
105
93
|
trySetCheckedRowKeys(function (prev) {
|
|
@@ -109,8 +97,8 @@ var useTableCheck = function useTableCheck(_ref) {
|
|
|
109
97
|
}, targetRowItems, false);
|
|
110
98
|
return;
|
|
111
99
|
}
|
|
112
|
-
|
|
113
|
-
|
|
100
|
+
trySetCheckedRowKeys(
|
|
101
|
+
// 添加当前页所有行 ids
|
|
114
102
|
function (prev) {
|
|
115
103
|
prev.forEach(function (id) {
|
|
116
104
|
return checkedRowKeysSet.add(id);
|
|
@@ -129,5 +117,4 @@ var useTableCheck = function useTableCheck(_ref) {
|
|
|
129
117
|
checkRowIsDisabledCheckbox: checkRowIsDisabledCheckbox
|
|
130
118
|
};
|
|
131
119
|
};
|
|
132
|
-
|
|
133
120
|
export { useTableCheck };
|
|
@@ -14,25 +14,22 @@ var DEFAULT_COLUMNS = [];
|
|
|
14
14
|
/**
|
|
15
15
|
* 列操作逻辑
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
17
|
var useColHidden = function useColHidden(_ref) {
|
|
19
18
|
var uniqueId = _ref.uniqueId,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
_ref$columns = _ref.columns,
|
|
20
|
+
columns = _ref$columns === void 0 ? DEFAULT_COLUMNS : _ref$columns,
|
|
21
|
+
hiddenColKeysProp = _ref.hiddenColKeys,
|
|
22
|
+
onHiddenColKeysChange = _ref.onHiddenColKeysChange;
|
|
24
23
|
var cacheKey = uniqueId ? uniqueId + "_hiddenColKeys" : '';
|
|
25
|
-
|
|
26
24
|
var _useUncontrolledState = useUncontrolledState(function () {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
return parseLocalArray({
|
|
26
|
+
key: cacheKey,
|
|
27
|
+
defaultValue: []
|
|
28
|
+
});
|
|
29
|
+
}, hiddenColKeysProp, onHiddenColKeysChange),
|
|
30
|
+
_hiddenColKeys = _useUncontrolledState[0],
|
|
31
|
+
setHiddenColKeys = _useUncontrolledState[1];
|
|
32
|
+
// 保证 includes 匹配 column,是有效的可展示的列
|
|
36
33
|
var hiddenColKeys = useMemo(function () {
|
|
37
34
|
return _hiddenColKeys.filter(function (dataKey) {
|
|
38
35
|
return typeof dataKey === 'string' && dataKey !== '';
|
|
@@ -41,12 +38,11 @@ var useColHidden = function useColHidden(_ref) {
|
|
|
41
38
|
useEffect(function () {
|
|
42
39
|
if (!cacheKey) return;
|
|
43
40
|
window.localStorage.setItem(cacheKey, JSON.stringify(hiddenColKeys));
|
|
44
|
-
}, [cacheKey, hiddenColKeys]);
|
|
45
|
-
|
|
41
|
+
}, [cacheKey, hiddenColKeys]);
|
|
42
|
+
// 用于维护列操作时显隐临时状态
|
|
46
43
|
var _useState = useState(hiddenColKeys),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
cacheHiddenColKeys = _useState[0],
|
|
45
|
+
setCacheHiddenColKeys = _useState[1];
|
|
50
46
|
var visibleCols = useMemo(function () {
|
|
51
47
|
// TODO: 支持隐藏叶子结点,而不是根节点
|
|
52
48
|
// @ts-ignore
|
|
@@ -62,5 +58,4 @@ var useColHidden = function useColHidden(_ref) {
|
|
|
62
58
|
setCacheHiddenColKeys: setCacheHiddenColKeys
|
|
63
59
|
};
|
|
64
60
|
};
|
|
65
|
-
|
|
66
61
|
export { useColHidden };
|
|
@@ -12,40 +12,33 @@ var DEFAULT_COLUMNS = [];
|
|
|
12
12
|
/**
|
|
13
13
|
* 列设置
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
15
|
var useColSet = function useColSet(_ref) {
|
|
17
16
|
var _ref$columns = _ref.columns,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
columns = _ref$columns === void 0 ? DEFAULT_COLUMNS : _ref$columns,
|
|
18
|
+
sortedColKeysProp = _ref.sortedColKeys,
|
|
19
|
+
hiddenColKeysProp = _ref.hiddenColKeys;
|
|
21
20
|
var isColumnsEqual = useMemo(function () {
|
|
22
|
-
var _a;
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
var _a;
|
|
22
|
+
// 判断columns和之前的是不是一样的,如果之前columns对不上,那么认为设置数据无效。
|
|
25
23
|
if (!sortedColKeysProp) {
|
|
26
24
|
return true;
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
if (columns.length !== sortedColKeysProp.length) {
|
|
30
27
|
return false;
|
|
31
28
|
}
|
|
32
|
-
|
|
33
29
|
for (var cIndex = 0; cIndex < columns.length; cIndex++) {
|
|
34
30
|
var exist = false;
|
|
35
31
|
var dataKey = (_a = columns[cIndex]) === null || _a === void 0 ? void 0 : _a.dataKey;
|
|
36
|
-
|
|
37
32
|
for (var sIndex = 0; sIndex < sortedColKeysProp.length; sIndex++) {
|
|
38
33
|
if (dataKey === sortedColKeysProp[sIndex]) {
|
|
39
34
|
exist = true;
|
|
40
35
|
break;
|
|
41
36
|
}
|
|
42
37
|
}
|
|
43
|
-
|
|
44
38
|
if (!exist) {
|
|
45
39
|
return false;
|
|
46
40
|
}
|
|
47
41
|
}
|
|
48
|
-
|
|
49
42
|
return true;
|
|
50
43
|
}, [columns, sortedColKeysProp]);
|
|
51
44
|
return {
|
|
@@ -53,5 +46,4 @@ var useColSet = function useColSet(_ref) {
|
|
|
53
46
|
hiddenColKeys: isColumnsEqual ? hiddenColKeysProp : undefined
|
|
54
47
|
};
|
|
55
48
|
};
|
|
56
|
-
|
|
57
49
|
export { useColSet };
|
|
@@ -16,26 +16,23 @@ var DEFAULT_COLUMNS = [];
|
|
|
16
16
|
/**
|
|
17
17
|
* 列排序
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
19
|
var useColSorter = function useColSorter(_ref) {
|
|
21
20
|
var uniqueId = _ref.uniqueId,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
_ref$columns = _ref.columns,
|
|
22
|
+
columns = _ref$columns === void 0 ? DEFAULT_COLUMNS : _ref$columns,
|
|
23
|
+
sortedColKeysProp = _ref.sortedColKeys,
|
|
24
|
+
onSortedColKeysChange = _ref.onSortedColKeysChange;
|
|
26
25
|
var cacheKey = uniqueId ? uniqueId + "_sortCols" : '';
|
|
27
|
-
|
|
28
26
|
var _useUncontrolledState = useUncontrolledState(function () {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
return parseLocalArray({
|
|
28
|
+
key: cacheKey,
|
|
29
|
+
defaultValue: columns.map(function (column) {
|
|
30
|
+
return column.dataKey;
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
}, sortedColKeysProp, onSortedColKeysChange),
|
|
34
|
+
sortedColKeys = _useUncontrolledState[0],
|
|
35
|
+
setSortColKeys = _useUncontrolledState[1];
|
|
39
36
|
useUpdateEffect(function () {
|
|
40
37
|
// 当column发生改变的时候,同步 setting 的 sortedCols 设置
|
|
41
38
|
setSortColKeys(columns.map(function (column) {
|
|
@@ -55,13 +52,12 @@ var useColSorter = function useColSorter(_ref) {
|
|
|
55
52
|
useEffect(function () {
|
|
56
53
|
if (!cacheKey) return;
|
|
57
54
|
window.localStorage.setItem(cacheKey, JSON.stringify(sortedColKeys));
|
|
58
|
-
}, [cacheKey, sortedColKeys]);
|
|
59
|
-
|
|
55
|
+
}, [cacheKey, sortedColKeys]);
|
|
56
|
+
// 用于维护列操作时排序临时状态((未确认保存时))
|
|
60
57
|
var _useState = useState(sortedCols),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
_cacheSortedCols = _useState[0],
|
|
59
|
+
setCacheSortedCols = _useState[1];
|
|
60
|
+
// 保证排序的 column,是有效的可展示的列
|
|
65
61
|
var cacheSortedCols = useMemo(function () {
|
|
66
62
|
return _cacheSortedCols.filter(function (col) {
|
|
67
63
|
return col && typeof col.dataKey === 'string' && col.dataKey !== '';
|
|
@@ -74,5 +70,4 @@ var useColSorter = function useColSorter(_ref) {
|
|
|
74
70
|
setCacheSortedCols: setCacheSortedCols
|
|
75
71
|
};
|
|
76
72
|
};
|
|
77
|
-
|
|
78
73
|
export { useColSorter };
|
|
@@ -10,37 +10,29 @@
|
|
|
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
|
-
|
|
14
13
|
var useColWidth = function useColWidth(_ref) {
|
|
15
14
|
var resizable = _ref.resizable,
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
columns = _ref.columns,
|
|
16
|
+
virtual = _ref.virtual;
|
|
18
17
|
var measureRowElementRef = React__default.useRef(null);
|
|
19
|
-
|
|
20
18
|
var _React$useState = React__default.useState(function () {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
return getGroupItemWidth(columns);
|
|
20
|
+
}),
|
|
21
|
+
colWidths = _React$useState[0],
|
|
22
|
+
setColWidths = _React$useState[1];
|
|
26
23
|
var getVirtualWidths = useCallback(function () {
|
|
27
24
|
var measureRowElement = measureRowElementRef.current;
|
|
28
|
-
|
|
29
25
|
if (!measureRowElement) {
|
|
30
26
|
return getGroupItemWidth(columns);
|
|
31
27
|
}
|
|
32
28
|
/** 虚拟滚动时,内容宽度不能用以前table自动渲染的方式获取,需要手动计算 */
|
|
33
|
-
|
|
34
|
-
|
|
35
29
|
var columnDefaultWidth = 200;
|
|
36
30
|
var containerWidth = measureRowElement.clientWidth;
|
|
37
31
|
var totalWidth = 0;
|
|
38
32
|
/** 虚拟滚动,需要根据collist的虚拟宽度来计算宽度 */
|
|
39
|
-
|
|
40
33
|
columns.forEach(function (columnItem) {
|
|
41
34
|
totalWidth += columnItem.width || columnDefaultWidth;
|
|
42
35
|
});
|
|
43
|
-
|
|
44
36
|
if (totalWidth < containerWidth) {
|
|
45
37
|
// 容器宽度大于设置的宽度总和时,col宽度等比分分配占满容器。
|
|
46
38
|
return columns.map(function (columnItem) {
|
|
@@ -65,15 +57,14 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
65
57
|
/**
|
|
66
58
|
* 根据实际内容区(table 的第一行)渲染,再次精确收集并设置每列宽度
|
|
67
59
|
*/
|
|
68
|
-
|
|
69
60
|
React__default.useEffect(function () {
|
|
70
61
|
var measureRowElement = measureRowElementRef.current;
|
|
71
|
-
|
|
72
62
|
if (measureRowElement) {
|
|
73
63
|
var _resizeObserver = new ResizeObserver(function () {
|
|
74
64
|
if (virtual) {
|
|
75
65
|
setColWidths(getVirtualWidths());
|
|
76
|
-
}
|
|
66
|
+
}
|
|
67
|
+
// else {
|
|
77
68
|
// if (measureRowElement.childNodes) {
|
|
78
69
|
// const _realColumnsWidth = Array.from(measureRowElement.childNodes).map((node) => {
|
|
79
70
|
// return (node as HTMLElement).getBoundingClientRect().width || 0
|
|
@@ -83,27 +74,22 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
83
74
|
// }
|
|
84
75
|
// }
|
|
85
76
|
// }
|
|
86
|
-
|
|
87
77
|
});
|
|
88
78
|
|
|
89
79
|
_resizeObserver.observe(measureRowElement);
|
|
90
80
|
}
|
|
91
|
-
|
|
92
|
-
|
|
81
|
+
return function () {};
|
|
82
|
+
// 测量元素在内容列为空时会是空,切换会使测量元素变化,导致后续的resize时间无法响应,此处测量元素变化时需要重新绑定
|
|
93
83
|
}, [getVirtualWidths, virtual]);
|
|
94
|
-
|
|
95
84
|
var _React$useState2 = React__default.useState(null),
|
|
96
|
-
|
|
97
|
-
|
|
85
|
+
headerTableElement = _React$useState2[0],
|
|
86
|
+
setHeaderTableElement = _React$useState2[1];
|
|
98
87
|
/**
|
|
99
88
|
* 控制列最小可调整宽度
|
|
100
89
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
90
|
var minColWidth = React__default.useMemo(function () {
|
|
104
91
|
if (resizable && headerTableElement) {
|
|
105
92
|
var resizableHandlerWidth = 4;
|
|
106
|
-
|
|
107
93
|
var _minColWidth = Array.from(headerTableElement.childNodes).map(function (th) {
|
|
108
94
|
var thPaddingLeft = parseFloat(window.getComputedStyle(th).getPropertyValue('padding-left'));
|
|
109
95
|
var childNodes = Array.from(th.childNodes);
|
|
@@ -113,16 +99,13 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
113
99
|
return prev + next;
|
|
114
100
|
}) + thPaddingLeft * 2 + resizableHandlerWidth;
|
|
115
101
|
});
|
|
116
|
-
|
|
117
102
|
return _minColWidth;
|
|
118
103
|
}
|
|
119
|
-
|
|
120
104
|
return Array(columns.length).fill(0);
|
|
121
105
|
}, [columns.length, headerTableElement, resizable]);
|
|
122
106
|
/**
|
|
123
107
|
* 列宽拖拽 resize,只处理拖拽线两边的列宽度
|
|
124
108
|
*/
|
|
125
|
-
|
|
126
109
|
var onColumnResizable = React__default.useCallback(function (_, _ref2, index) {
|
|
127
110
|
var size = _ref2.size;
|
|
128
111
|
var minWidth = minColWidth[index];
|
|
@@ -131,12 +114,10 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
131
114
|
setColWidths(function (prev) {
|
|
132
115
|
var nextColWidths = [].concat(prev);
|
|
133
116
|
var anotherWidth = nextColWidths[index + 1] + nextColWidths[index] - nextWidth;
|
|
134
|
-
|
|
135
117
|
if (anotherWidth <= anotherMinWidth) {
|
|
136
118
|
anotherWidth = anotherMinWidth;
|
|
137
119
|
nextWidth = nextColWidths[index + 1] - anotherMinWidth + nextColWidths[index];
|
|
138
120
|
}
|
|
139
|
-
|
|
140
121
|
nextColWidths[index] = nextWidth;
|
|
141
122
|
nextColWidths[index + 1] = anotherWidth;
|
|
142
123
|
return nextColWidths;
|
|
@@ -149,8 +130,8 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
149
130
|
width: width,
|
|
150
131
|
// TODO(疑惑): minWidth 所要解决的问题
|
|
151
132
|
minWidth: width
|
|
152
|
-
}
|
|
153
|
-
|
|
133
|
+
}
|
|
134
|
+
// 'data-hover-highlight': setAttrStatus(isHoveredCol(column.dataKey)),
|
|
154
135
|
};
|
|
155
136
|
}, [colWidths]);
|
|
156
137
|
return {
|
|
@@ -161,5 +142,4 @@ var useColWidth = function useColWidth(_ref) {
|
|
|
161
142
|
colWidths: colWidths
|
|
162
143
|
};
|
|
163
144
|
};
|
|
164
|
-
|
|
165
145
|
export { useColWidth };
|
|
@@ -10,80 +10,75 @@
|
|
|
10
10
|
import React__default from 'react';
|
|
11
11
|
import { cloneTree, flattenTree, isLeaf, getLeafChildren, groupByTreeDepth } from '@hi-ui/tree-utils';
|
|
12
12
|
import { isArrayNonEmpty } from '@hi-ui/type-assertion';
|
|
13
|
-
|
|
14
13
|
var useColumns = function useColumns(_ref) {
|
|
15
|
-
var columns = _ref.columns;
|
|
16
|
-
|
|
14
|
+
var columns = _ref.columns;
|
|
15
|
+
// 拉平后的数据
|
|
17
16
|
var _React$useMemo = React__default.useMemo(function () {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
|
|
22
|
-
var flattedColumns = flattenTree(clonedColumns, function (node) {
|
|
23
|
-
var _a;
|
|
24
|
-
|
|
25
|
-
if (node.depth > maxDepth) {
|
|
26
|
-
maxDepth = node.depth;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var raw = node.raw;
|
|
30
|
-
return Object.assign(Object.assign({}, node), {
|
|
31
|
-
id: raw.dataKey,
|
|
32
|
-
width: raw.width,
|
|
33
|
-
// TODO: remove it
|
|
34
|
-
dataKey: raw.dataKey,
|
|
35
|
-
title: raw.title,
|
|
36
|
-
align: (_a = raw.align) !== null && _a !== void 0 ? _a : 'left',
|
|
37
|
-
render: raw.render
|
|
38
|
-
});
|
|
39
|
-
}); // 记录下标位置,方便冻结列操作计算时快速获取更新
|
|
40
|
-
// 记录下标位置,方便冻结列操作计算时快速获取更新
|
|
41
|
-
|
|
42
|
-
flattedColumns.forEach(function (column, index) {
|
|
17
|
+
var clonedColumns = cloneTree(columns);
|
|
18
|
+
var maxDepth = 0;
|
|
43
19
|
// @ts-ignore
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
var flattedColumns = flattenTree(clonedColumns, function (node) {
|
|
22
|
+
var _a;
|
|
23
|
+
if (node.depth > maxDepth) {
|
|
24
|
+
maxDepth = node.depth;
|
|
25
|
+
}
|
|
26
|
+
var raw = node.raw;
|
|
27
|
+
return Object.assign(Object.assign({}, node), {
|
|
28
|
+
id: raw.dataKey,
|
|
29
|
+
width: raw.width,
|
|
30
|
+
// TODO: remove it
|
|
31
|
+
dataKey: raw.dataKey,
|
|
32
|
+
title: raw.title,
|
|
33
|
+
align: (_a = raw.align) !== null && _a !== void 0 ? _a : 'left',
|
|
34
|
+
render: raw.render
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
// 记录下标位置,方便冻结列操作计算时快速获取更新
|
|
38
|
+
// 记录下标位置,方便冻结列操作计算时快速获取更新
|
|
39
|
+
flattedColumns.forEach(function (column, index) {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
column.index = index;
|
|
42
|
+
});
|
|
43
|
+
return [flattedColumns, maxDepth];
|
|
44
|
+
}, [columns]),
|
|
45
|
+
flattedColumns = _React$useMemo[0],
|
|
46
|
+
maxColumnDepth = _React$useMemo[1];
|
|
47
|
+
// 末级 column
|
|
52
48
|
var flattedColumnsWithoutChildren = React__default.useMemo(function () {
|
|
53
49
|
return flattedColumns.filter(function (col) {
|
|
54
50
|
return !isArrayNonEmpty(col.children);
|
|
55
51
|
});
|
|
56
52
|
}, [flattedColumns]);
|
|
57
|
-
|
|
58
53
|
var _React$useMemo2 = React__default.useMemo(function () {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
54
|
+
var nextColumns = [].concat(
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
// flattedColumns.filter((col) => isLeaf(col)) as FlattedTableColumnItemData[]
|
|
57
|
+
flattedColumns);
|
|
58
|
+
// 表头分组
|
|
59
|
+
// 在最后一层,colSpan = 1, rowSpan = maxDepth - depth + 1
|
|
60
|
+
// 不在最后一层,rowSpan = 1, colSpan = 叶子节点后代数量
|
|
61
|
+
// 表头分组
|
|
62
|
+
// 在最后一层,colSpan = 1, rowSpan = maxDepth - depth + 1
|
|
63
|
+
// 不在最后一层,rowSpan = 1, colSpan = 叶子节点后代数量
|
|
64
|
+
flattedColumns.forEach(function (column) {
|
|
65
|
+
if (isLeaf(column)) {
|
|
66
|
+
column.rowSpan = maxColumnDepth - column.depth + 1;
|
|
67
|
+
column.colSpan = 1;
|
|
68
|
+
} else {
|
|
69
|
+
column.rowSpan = 1;
|
|
70
|
+
column.colSpan = getLeafChildren(column).length;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
var leafColumns = flattedColumns.filter(function (col) {
|
|
74
|
+
return isLeaf(col);
|
|
75
|
+
});
|
|
76
|
+
var groupedColumns = groupByTreeDepth(nextColumns);
|
|
77
|
+
return [nextColumns, groupedColumns, leafColumns];
|
|
78
|
+
}, [flattedColumns, maxColumnDepth]),
|
|
79
|
+
mergedColumns = _React$useMemo2[0],
|
|
80
|
+
groupedColumns = _React$useMemo2[1],
|
|
81
|
+
leafColumns = _React$useMemo2[2];
|
|
87
82
|
return {
|
|
88
83
|
// getColgroupProps,
|
|
89
84
|
flattedColumns: flattedColumns,
|
|
@@ -93,5 +88,4 @@ var useColumns = function useColumns(_ref) {
|
|
|
93
88
|
flattedColumnsWithoutChildren: flattedColumnsWithoutChildren
|
|
94
89
|
};
|
|
95
90
|
};
|
|
96
|
-
|
|
97
91
|
export { useColumns };
|
|
@@ -11,33 +11,30 @@ import React__default, { useCallback } from 'react';
|
|
|
11
11
|
import { useLatestCallback } from '@hi-ui/use-latest';
|
|
12
12
|
import { findNodeById, cloneTree, deleteNodeById, insertNodeById } from '@hi-ui/tree-utils';
|
|
13
13
|
import { isFunction, isPromise } from '@hi-ui/type-assertion';
|
|
14
|
-
|
|
15
14
|
var useTableDrag = function useTableDrag(_ref) {
|
|
16
15
|
var cacheData = _ref.cacheData,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
setCacheData = _ref.setCacheData,
|
|
17
|
+
draggable = _ref.draggable,
|
|
18
|
+
onDropEnd = _ref.onDropEnd,
|
|
19
|
+
onDropProp = _ref.onDrop,
|
|
20
|
+
fieldKey = _ref.fieldKey;
|
|
22
21
|
var dragRowRef = React__default.useRef(null);
|
|
23
22
|
var onDropEndLatest = useLatestCallback(onDropEnd);
|
|
24
23
|
var onDrop = useCallback(function (evt, sourceId, targetId, dragDirection) {
|
|
25
24
|
if (!draggable) return;
|
|
26
|
-
if (targetId === sourceId) return;
|
|
25
|
+
if (targetId === sourceId) return;
|
|
26
|
+
// TODO: 根据 id 查询数据原始数据或者直接使用引用值,两者选择,避免bug
|
|
27
27
|
// const { rowData, dropRowData, level } = dragRowRef.current
|
|
28
|
-
|
|
29
28
|
var sourceNode = findNodeById(cacheData, sourceId, {
|
|
30
29
|
idFieldName: fieldKey
|
|
31
30
|
});
|
|
32
31
|
var targetNode = findNodeById(cacheData, targetId, {
|
|
33
32
|
idFieldName: fieldKey
|
|
34
33
|
});
|
|
35
|
-
|
|
36
34
|
if (!sourceNode || !targetNode) {
|
|
37
35
|
// console.log('未找到任何节点(sourceNode, targetNode)', sourceNode, targetNode)
|
|
38
36
|
return;
|
|
39
37
|
}
|
|
40
|
-
|
|
41
38
|
var nextTreeData = cloneTree(cacheData);
|
|
42
39
|
deleteNodeById(nextTreeData, sourceId, {
|
|
43
40
|
idFieldName: fieldKey
|
|
@@ -45,7 +42,8 @@ var useTableDrag = function useTableDrag(_ref) {
|
|
|
45
42
|
insertNodeById(nextTreeData, targetId, sourceNode, dragDirection === 'top' ? 0 : 1, {
|
|
46
43
|
idFieldName: fieldKey
|
|
47
44
|
});
|
|
48
|
-
var resultMaybePromise = isFunction(onDropProp) ?
|
|
45
|
+
var resultMaybePromise = isFunction(onDropProp) ?
|
|
46
|
+
// TODO: 支持 tree 拖拽层级,第四个参数
|
|
49
47
|
onDropProp(evt, {
|
|
50
48
|
dragNode: sourceNode,
|
|
51
49
|
dropNode: targetNode,
|
|
@@ -54,7 +52,6 @@ var useTableDrag = function useTableDrag(_ref) {
|
|
|
54
52
|
after: nextTreeData
|
|
55
53
|
}
|
|
56
54
|
}) : true;
|
|
57
|
-
|
|
58
55
|
if (isPromise(resultMaybePromise)) {
|
|
59
56
|
resultMaybePromise.then(function (returnResult) {
|
|
60
57
|
if (returnResult === true) {
|
|
@@ -86,5 +83,4 @@ var useTableDrag = function useTableDrag(_ref) {
|
|
|
86
83
|
dragRowRef: dragRowRef
|
|
87
84
|
};
|
|
88
85
|
};
|
|
89
|
-
|
|
90
86
|
export { useTableDrag };
|