@aloudata/aloudata-design 2.18.0 → 2.18.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.
- package/dist/InputSearch/index.d.ts +1 -0
- package/dist/InputSearch/index.js +24 -8
- package/dist/Table/components/Footer/index.js +2 -1
- package/dist/Table/hooks/useExpandable.d.ts +1 -0
- package/dist/Table/hooks/useExpandable.js +4 -2
- package/dist/Table/hooks/useRowSelection.d.ts +48 -1
- package/dist/Table/hooks/useRowSelection.js +259 -27
- package/dist/Table/index.js +7 -3
- package/dist/Table/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
3
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
4
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -36,6 +37,7 @@ export default function InputSearch(props) {
|
|
|
36
37
|
_props$size = props.size,
|
|
37
38
|
size = _props$size === void 0 ? 'small' : _props$size,
|
|
38
39
|
defaultValue = props.defaultValue,
|
|
40
|
+
value = props.value,
|
|
39
41
|
_props$inputMode = props.inputMode,
|
|
40
42
|
inputMode = _props$inputMode === void 0 ? false : _props$inputMode,
|
|
41
43
|
style = props.style,
|
|
@@ -58,10 +60,16 @@ export default function InputSearch(props) {
|
|
|
58
60
|
return DEFAULT_LARGE_WIDTH;
|
|
59
61
|
}
|
|
60
62
|
}, [locale, size]);
|
|
63
|
+
|
|
64
|
+
// 判断是否为受控模式
|
|
65
|
+
var isControlled = value !== undefined;
|
|
61
66
|
var _useState = useState(defaultValue || ''),
|
|
62
67
|
_useState2 = _slicedToArray(_useState, 2),
|
|
63
68
|
searchValue = _useState2[0],
|
|
64
69
|
setSearchValue = _useState2[1];
|
|
70
|
+
|
|
71
|
+
// 获取当前值:受控模式使用 value,非受控模式使用内部状态
|
|
72
|
+
var currentValue = isControlled ? value : searchValue;
|
|
65
73
|
var isComposing = useRef(false);
|
|
66
74
|
var onPressEnter = useCallback(function (e) {
|
|
67
75
|
if (!isComposing.current) {
|
|
@@ -79,7 +87,11 @@ export default function InputSearch(props) {
|
|
|
79
87
|
debounceSearch = _useDebounceFn.run;
|
|
80
88
|
var onChangeValue = useCallback(function (e) {
|
|
81
89
|
var newValue = e.target.value;
|
|
82
|
-
|
|
90
|
+
|
|
91
|
+
// 非受控模式才更新内部状态
|
|
92
|
+
if (!isControlled) {
|
|
93
|
+
setSearchValue(newValue);
|
|
94
|
+
}
|
|
83
95
|
if (!isComposing.current) {
|
|
84
96
|
if (debounce) {
|
|
85
97
|
debounceSearch(newValue);
|
|
@@ -87,7 +99,7 @@ export default function InputSearch(props) {
|
|
|
87
99
|
onSearch(newValue);
|
|
88
100
|
}
|
|
89
101
|
}
|
|
90
|
-
}, [debounce, debounceSearch, onSearch]);
|
|
102
|
+
}, [debounce, debounceSearch, onSearch, isControlled]);
|
|
91
103
|
var handleCompositionStart = useCallback(function () {
|
|
92
104
|
isComposing.current = true;
|
|
93
105
|
}, []);
|
|
@@ -112,8 +124,8 @@ export default function InputSearch(props) {
|
|
|
112
124
|
style: _objectSpread(_objectSpread({}, style), {}, {
|
|
113
125
|
'--init-width': (props.initWidth || defaultWidth) + 'px'
|
|
114
126
|
})
|
|
115
|
-
}, /*#__PURE__*/React.createElement(Input, {
|
|
116
|
-
className: classnames((_classnames2 = {}, _defineProperty(_classnames2, 'input-search-has-value',
|
|
127
|
+
}, /*#__PURE__*/React.createElement(Input, _extends({
|
|
128
|
+
className: classnames((_classnames2 = {}, _defineProperty(_classnames2, 'input-search-has-value', currentValue.length !== 0 || inputMode), _defineProperty(_classnames2, 'inputMode', inputMode), _classnames2)),
|
|
117
129
|
size: size
|
|
118
130
|
// @ts-ignore
|
|
119
131
|
,
|
|
@@ -126,12 +138,16 @@ export default function InputSearch(props) {
|
|
|
126
138
|
size: iconSize
|
|
127
139
|
}),
|
|
128
140
|
placeholder: placeholder || t.InputSearch.search,
|
|
129
|
-
allowClear: true
|
|
130
|
-
|
|
141
|
+
allowClear: true
|
|
142
|
+
}, isControlled ? {
|
|
143
|
+
value: currentValue
|
|
144
|
+
} : {
|
|
145
|
+
defaultValue: defaultValue
|
|
146
|
+
}, {
|
|
131
147
|
onBlur: function onBlur(e) {
|
|
132
148
|
if (_onBlur) {
|
|
133
|
-
_onBlur(
|
|
149
|
+
_onBlur(currentValue, e);
|
|
134
150
|
}
|
|
135
151
|
}
|
|
136
|
-
}));
|
|
152
|
+
})));
|
|
137
153
|
}
|
|
@@ -24,6 +24,7 @@ export default function TableFooter(props) {
|
|
|
24
24
|
// 选择行
|
|
25
25
|
var getCheckboxAllNode = rowSelectionInfo.getCheckboxAllNode,
|
|
26
26
|
selectedRowKeys = rowSelectionInfo.selectedRowKeys,
|
|
27
|
+
selectedRowKeysInCurrPage = rowSelectionInfo.selectedRowKeysInCurrPage,
|
|
27
28
|
items = rowSelectionInfo.items,
|
|
28
29
|
isShowRowSelectionInFooter = rowSelectionInfo.isShowRowSelectionInFooter,
|
|
29
30
|
changeSelectedRowKeys = rowSelectionInfo.onChange;
|
|
@@ -73,7 +74,7 @@ export default function TableFooter(props) {
|
|
|
73
74
|
}, pagination, {
|
|
74
75
|
onChange: onChangePage
|
|
75
76
|
})));
|
|
76
|
-
var isShowRowSelection = rowSelectionInfo.isRowSelectionEnabled &&
|
|
77
|
+
var isShowRowSelection = rowSelectionInfo.isRowSelectionEnabled && selectedRowKeysInCurrPage.length > 0;
|
|
77
78
|
var isShowFooter = isShowPagination || isShowRowSelection;
|
|
78
79
|
return isShowFooter ? /*#__PURE__*/React.createElement("div", {
|
|
79
80
|
className: prefixCls('footer')
|
|
@@ -85,14 +85,16 @@ export default function useExpandable(props) {
|
|
|
85
85
|
expandItemMap: {},
|
|
86
86
|
onExpand: function onExpand() {},
|
|
87
87
|
isExpandable: false,
|
|
88
|
-
data: data
|
|
88
|
+
data: data,
|
|
89
|
+
flattenData: undefined
|
|
89
90
|
};
|
|
90
91
|
}
|
|
91
92
|
return {
|
|
92
93
|
expandItemMap: expandItemMap,
|
|
93
94
|
onExpand: onExpand,
|
|
94
95
|
isExpandable: true,
|
|
95
|
-
data: visibleList
|
|
96
|
+
data: visibleList,
|
|
97
|
+
flattenData: flattenList
|
|
96
98
|
};
|
|
97
99
|
}
|
|
98
100
|
function getListItemsByTree(currNode, expandedKeys, isRenderCustomExpandRow,
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ITableProps } from '../types';
|
|
3
|
-
export default function useRowSelection<TDataItem extends object>(props: ITableProps<TDataItem>
|
|
3
|
+
export default function useRowSelection<TDataItem extends object>(props: ITableProps<TDataItem> & {
|
|
4
|
+
isExpandable?: boolean;
|
|
5
|
+
flattenData?: TDataItem[];
|
|
6
|
+
}): IRowSelectionInfo<TDataItem>;
|
|
4
7
|
export interface IRowSelectionInfo<TDataItem extends object> {
|
|
5
8
|
columns: ITableProps<TDataItem>['columns'];
|
|
6
9
|
isRowSelectionEnabled: boolean;
|
|
7
10
|
getCheckboxAllNode: ((children?: React.ReactNode) => React.ReactNode) | null;
|
|
8
11
|
selectedRowKeys: string[];
|
|
12
|
+
selectedRowKeysInCurrPage: string[];
|
|
9
13
|
unSelectAll: (e: React.MouseEvent) => void;
|
|
10
14
|
isShowRowSelectionInFooter: boolean;
|
|
11
15
|
items: {
|
|
@@ -15,3 +19,46 @@ export interface IRowSelectionInfo<TDataItem extends object> {
|
|
|
15
19
|
}[];
|
|
16
20
|
onChange: (selectedRowKeys: string[]) => void;
|
|
17
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* 获取节点的所有子孙节点keys
|
|
24
|
+
* @param parentKey 父节点key
|
|
25
|
+
* @param isExpandable 是否启用展开功能
|
|
26
|
+
* @param flattenData 扁平化后的数据(包含所有节点,包括子节点)
|
|
27
|
+
* @param rowKey 行key获取函数
|
|
28
|
+
* @returns 子孙节点keys数组
|
|
29
|
+
*/
|
|
30
|
+
export declare function getNodeDescendants<TDataItem extends object>(parentKey: string, isExpandable?: boolean, flattenData?: TDataItem[], rowKey?: ITableProps<TDataItem>['rowKey']): string[];
|
|
31
|
+
/**
|
|
32
|
+
* 获取节点的所有祖先节点keys
|
|
33
|
+
* @param targetKey 目标节点key
|
|
34
|
+
* @param isExpandable 是否启用展开功能
|
|
35
|
+
* @param flattenData 扁平化后的数据
|
|
36
|
+
* @param rowKey 行key获取函数
|
|
37
|
+
* @returns 祖先节点keys数组(从直接父节点到根节点)
|
|
38
|
+
*/
|
|
39
|
+
export declare function getNodeAncestors<TDataItem extends object>(targetKey: string, isExpandable?: boolean, flattenData?: TDataItem[], rowKey?: ITableProps<TDataItem>['rowKey']): string[];
|
|
40
|
+
/**
|
|
41
|
+
* 计算级联选择后的keys(包含向上级联)
|
|
42
|
+
* @param targetKey 被操作的节点key
|
|
43
|
+
* @param isChecked 当前是否选中
|
|
44
|
+
* @param currentSelectedKeys 当前已选中的keys
|
|
45
|
+
* @param checkStrictly 是否严格模式
|
|
46
|
+
* @param isExpandable 是否启用展开功能
|
|
47
|
+
* @param getDescendantKeys 获取子孙节点keys的函数
|
|
48
|
+
* @param getAncestorKeys 获取祖先节点keys的函数
|
|
49
|
+
* @returns 新的选中keys
|
|
50
|
+
*/
|
|
51
|
+
export declare function calculateCascadeSelection(targetKey: string, isChecked: boolean, currentSelectedKeys: string[], checkStrictly?: boolean, isExpandable?: boolean, getDescendantKeys?: (nodeKey: string) => string[], getAncestorKeys?: (nodeKey: string) => string[]): string[];
|
|
52
|
+
/**
|
|
53
|
+
* 计算节点的选择状态(考虑子节点状态)
|
|
54
|
+
* @param nodeKey 节点key
|
|
55
|
+
* @param selectedRowKeys 已选中的keys
|
|
56
|
+
* @param checkStrictly 是否严格模式
|
|
57
|
+
* @param isExpandable 是否启用展开功能
|
|
58
|
+
* @param getDescendantKeys 获取子孙节点keys的函数
|
|
59
|
+
* @returns 节点的选择状态
|
|
60
|
+
*/
|
|
61
|
+
export declare function calculateNodeCheckStatus(nodeKey: string, selectedRowKeys: string[], checkStrictly?: boolean, isExpandable?: boolean, getDescendantKeys?: (nodeKey: string) => string[]): {
|
|
62
|
+
checked: boolean;
|
|
63
|
+
indeterminate: boolean;
|
|
64
|
+
};
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { throw e; }), f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function (_e3) { function e(_x3) { return _e3.apply(this, arguments); } e.toString = function () { return _e3.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
2
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
8
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
9
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
10
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
11
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
12
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
8
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
13
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
14
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
15
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
16
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
17
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
17
18
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
-
import React, { useCallback, useState } from 'react';
|
|
19
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
19
20
|
import Checkbox from "../../Checkbox";
|
|
20
21
|
import { getRowKey, hasFixedLeftColumn, prefixCls } from "../helper";
|
|
21
22
|
export default function useRowSelection(props) {
|
|
@@ -23,7 +24,9 @@ export default function useRowSelection(props) {
|
|
|
23
24
|
var columns = props.columns,
|
|
24
25
|
rowSelection = props.rowSelection,
|
|
25
26
|
rowKey = props.rowKey,
|
|
26
|
-
data = props.data
|
|
27
|
+
data = props.data,
|
|
28
|
+
isExpandable = props.isExpandable,
|
|
29
|
+
flattenData = props.flattenData;
|
|
27
30
|
var _useState = useState((rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys) || (rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.defaultSelectedRowKeys) || []),
|
|
28
31
|
_useState2 = _slicedToArray(_useState, 2),
|
|
29
32
|
selectedRowKeysState = _useState2[0],
|
|
@@ -34,25 +37,38 @@ export default function useRowSelection(props) {
|
|
|
34
37
|
return rowKeys.includes(getRowKey(record, rowKey));
|
|
35
38
|
});
|
|
36
39
|
}, [data, rowKey]);
|
|
40
|
+
|
|
41
|
+
// 获取用于全选状态计算和数据获取的完整数据
|
|
42
|
+
var allDataForSelection = useMemo(function () {
|
|
43
|
+
// 如果开启了 expandable,使用扁平化后的数据
|
|
44
|
+
if (isExpandable && flattenData) {
|
|
45
|
+
return flattenData;
|
|
46
|
+
}
|
|
47
|
+
// 否则使用原始数据
|
|
48
|
+
return data;
|
|
49
|
+
}, [isExpandable, flattenData, data]);
|
|
50
|
+
|
|
51
|
+
// 从完整数据中获取选中的行
|
|
52
|
+
var getAllSelectedRows = useCallback(function (rowKeys) {
|
|
53
|
+
return allDataForSelection.filter(function (record) {
|
|
54
|
+
return rowKeys.includes(getRowKey(record, rowKey));
|
|
55
|
+
});
|
|
56
|
+
}, [allDataForSelection, rowKey]);
|
|
37
57
|
var changeSelectedRowKeys = useCallback(function (newSelectedRowKeys) {
|
|
38
58
|
var _rowSelection$onChang;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var selectedRows = getSelectedRows(visibleSelectedRowKeys);
|
|
47
|
-
rowSelection === null || rowSelection === void 0 ? void 0 : (_rowSelection$onChang = rowSelection.onChange) === null || _rowSelection$onChang === void 0 ? void 0 : _rowSelection$onChang.call(rowSelection, visibleSelectedRowKeys, selectedRows);
|
|
48
|
-
}, [getSelectedRows, rowSelection, data, rowKey]);
|
|
49
|
-
var checkboxAllStatus = getCheckboxAllStatus(data, selectedRowKeys, rowKey, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.getCheckboxProps);
|
|
59
|
+
setSelectedRowKeysState(newSelectedRowKeys);
|
|
60
|
+
|
|
61
|
+
// 获取所有选中的行数据(包括被折叠的子项)
|
|
62
|
+
var allSelectedRows = getAllSelectedRows(newSelectedRowKeys);
|
|
63
|
+
rowSelection === null || rowSelection === void 0 ? void 0 : (_rowSelection$onChang = rowSelection.onChange) === null || _rowSelection$onChang === void 0 ? void 0 : _rowSelection$onChang.call(rowSelection, newSelectedRowKeys, allSelectedRows);
|
|
64
|
+
}, [getAllSelectedRows, rowSelection]);
|
|
65
|
+
var checkboxAllStatus = getCheckboxAllStatus(allDataForSelection, selectedRowKeys, rowKey, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.getCheckboxProps);
|
|
50
66
|
var selectAll = useCallback(function () {
|
|
51
|
-
var newKeys =
|
|
67
|
+
var newKeys = allDataForSelection.map(function (record) {
|
|
52
68
|
return getRowKey(record, rowKey);
|
|
53
69
|
});
|
|
54
70
|
changeSelectedRowKeys(newKeys);
|
|
55
|
-
}, [
|
|
71
|
+
}, [allDataForSelection, rowKey, changeSelectedRowKeys]);
|
|
56
72
|
var unSelectAll = useCallback(function () {
|
|
57
73
|
changeSelectedRowKeys([]);
|
|
58
74
|
}, [changeSelectedRowKeys]);
|
|
@@ -63,14 +79,27 @@ export default function useRowSelection(props) {
|
|
|
63
79
|
selectAll();
|
|
64
80
|
}
|
|
65
81
|
}, [checkboxAllStatus, unSelectAll, selectAll]);
|
|
82
|
+
|
|
83
|
+
// 获取节点的所有子孙节点keys
|
|
84
|
+
var getDescendantKeys = useCallback(function (parentKey) {
|
|
85
|
+
return getNodeDescendants(parentKey, isExpandable, flattenData, rowKey);
|
|
86
|
+
}, [isExpandable, flattenData, rowKey]);
|
|
87
|
+
|
|
88
|
+
// 获取节点的所有祖先节点keys
|
|
89
|
+
var getAncestorKeys = useCallback(function (targetKey) {
|
|
90
|
+
return getNodeAncestors(targetKey, isExpandable, flattenData, rowKey);
|
|
91
|
+
}, [isExpandable, flattenData, rowKey]);
|
|
92
|
+
|
|
93
|
+
// 获取节点的选择状态(考虑子节点状态)
|
|
94
|
+
var getNodeCheckStatus = useCallback(function (nodeKey) {
|
|
95
|
+
return calculateNodeCheckStatus(nodeKey, selectedRowKeys, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.checkStrictly, isExpandable, getDescendantKeys);
|
|
96
|
+
}, [selectedRowKeys, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.checkStrictly, isExpandable, getDescendantKeys]);
|
|
66
97
|
var onClickCheckbox = useCallback(function (key, isChecked) {
|
|
67
98
|
return function () {
|
|
68
|
-
var newKeys = isChecked ?
|
|
69
|
-
return keyItem !== key;
|
|
70
|
-
}) : [].concat(_toConsumableArray(selectedRowKeys), [key]);
|
|
99
|
+
var newKeys = calculateCascadeSelection(key, isChecked, selectedRowKeys, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.checkStrictly, isExpandable, getDescendantKeys, getAncestorKeys);
|
|
71
100
|
changeSelectedRowKeys(newKeys);
|
|
72
101
|
};
|
|
73
|
-
}, [selectedRowKeys, changeSelectedRowKeys]);
|
|
102
|
+
}, [selectedRowKeys, changeSelectedRowKeys, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.checkStrictly, isExpandable, getDescendantKeys, getAncestorKeys]);
|
|
74
103
|
|
|
75
104
|
// 全选按钮
|
|
76
105
|
var getCheckboxAllNode = function getCheckboxAllNode(children) {
|
|
@@ -88,6 +117,7 @@ export default function useRowSelection(props) {
|
|
|
88
117
|
isRowSelectionEnabled: false,
|
|
89
118
|
getCheckboxAllNode: getCheckboxAllNode,
|
|
90
119
|
selectedRowKeys: [],
|
|
120
|
+
selectedRowKeysInCurrPage: [],
|
|
91
121
|
unSelectAll: unSelectAll,
|
|
92
122
|
isShowRowSelectionInFooter: false,
|
|
93
123
|
items: [],
|
|
@@ -107,13 +137,14 @@ export default function useRowSelection(props) {
|
|
|
107
137
|
render: function render(text, record) {
|
|
108
138
|
var _rowSelection$getChec;
|
|
109
139
|
var key = getRowKey(record, rowKey);
|
|
110
|
-
var
|
|
140
|
+
var nodeStatus = getNodeCheckStatus(key);
|
|
111
141
|
var checkboxProps = ((_rowSelection$getChec = rowSelection.getCheckboxProps) === null || _rowSelection$getChec === void 0 ? void 0 : _rowSelection$getChec.call(rowSelection, record)) || {};
|
|
112
142
|
return /*#__PURE__*/React.createElement("div", {
|
|
113
143
|
className: prefixCls('row-selection-item')
|
|
114
144
|
}, /*#__PURE__*/React.createElement(Checkbox, _extends({
|
|
115
|
-
onClick: onClickCheckbox(key,
|
|
116
|
-
checked:
|
|
145
|
+
onClick: onClickCheckbox(key, nodeStatus.checked || nodeStatus.indeterminate),
|
|
146
|
+
checked: nodeStatus.checked,
|
|
147
|
+
indeterminate: nodeStatus.indeterminate
|
|
117
148
|
}, checkboxProps)));
|
|
118
149
|
},
|
|
119
150
|
fixed: fixed ? 'left' : undefined
|
|
@@ -135,7 +166,10 @@ export default function useRowSelection(props) {
|
|
|
135
166
|
columns: [rowSelectionColumn].concat(_toConsumableArray(columns)),
|
|
136
167
|
isRowSelectionEnabled: true,
|
|
137
168
|
getCheckboxAllNode: getCheckboxAllNode,
|
|
138
|
-
selectedRowKeys:
|
|
169
|
+
selectedRowKeys: selectedRowKeys,
|
|
170
|
+
// 返回完整的选中项列表
|
|
171
|
+
selectedRowKeysInCurrPage: selectedRowKeysInCurrPage,
|
|
172
|
+
// 当前页面可见的选中项
|
|
139
173
|
unSelectAll: unSelectAll,
|
|
140
174
|
isShowRowSelectionInFooter: isShowRowSelectionInFooter,
|
|
141
175
|
items: items,
|
|
@@ -167,4 +201,202 @@ function getDataWithoutDisabled(data, getCheckboxProps) {
|
|
|
167
201
|
var disabled = checkboxProps.disabled;
|
|
168
202
|
return !disabled;
|
|
169
203
|
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* 获取节点的所有子孙节点keys
|
|
207
|
+
* @param parentKey 父节点key
|
|
208
|
+
* @param isExpandable 是否启用展开功能
|
|
209
|
+
* @param flattenData 扁平化后的数据(包含所有节点,包括子节点)
|
|
210
|
+
* @param rowKey 行key获取函数
|
|
211
|
+
* @returns 子孙节点keys数组
|
|
212
|
+
*/
|
|
213
|
+
export function getNodeDescendants(parentKey, isExpandable, flattenData, rowKey) {
|
|
214
|
+
if (!isExpandable || !flattenData || !rowKey) return [];
|
|
215
|
+
var descendants = [];
|
|
216
|
+
|
|
217
|
+
// 找到父节点在flattenData中的记录
|
|
218
|
+
var parentNode = flattenData.find(function (item) {
|
|
219
|
+
return getRowKey(item, rowKey) === parentKey;
|
|
220
|
+
});
|
|
221
|
+
if (!parentNode) return [];
|
|
222
|
+
|
|
223
|
+
// 从原始节点的children中收集所有子孙节点
|
|
224
|
+
var collectDescendants = function collectDescendants(node) {
|
|
225
|
+
var children = node.children || [];
|
|
226
|
+
children.forEach(function (child) {
|
|
227
|
+
var childKey = getRowKey(child, rowKey);
|
|
228
|
+
descendants.push(childKey);
|
|
229
|
+
collectDescendants(child);
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
collectDescendants(parentNode);
|
|
233
|
+
return descendants;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 获取节点的所有祖先节点keys
|
|
238
|
+
* @param targetKey 目标节点key
|
|
239
|
+
* @param isExpandable 是否启用展开功能
|
|
240
|
+
* @param flattenData 扁平化后的数据
|
|
241
|
+
* @param rowKey 行key获取函数
|
|
242
|
+
* @returns 祖先节点keys数组(从直接父节点到根节点)
|
|
243
|
+
*/
|
|
244
|
+
export function getNodeAncestors(targetKey, isExpandable, flattenData, rowKey) {
|
|
245
|
+
if (!isExpandable || !flattenData || !rowKey) return [];
|
|
246
|
+
var ancestors = [];
|
|
247
|
+
|
|
248
|
+
// 找到目标节点的直接父节点
|
|
249
|
+
var findDirectParent = function findDirectParent(childKey) {
|
|
250
|
+
var _iterator = _createForOfIteratorHelper(flattenData),
|
|
251
|
+
_step;
|
|
252
|
+
try {
|
|
253
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
254
|
+
var item = _step.value;
|
|
255
|
+
var _children = item.children || [];
|
|
256
|
+
if (_children.some(function (child) {
|
|
257
|
+
return getRowKey(child, rowKey) === childKey;
|
|
258
|
+
})) {
|
|
259
|
+
return item;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
} catch (err) {
|
|
263
|
+
_iterator.e(err);
|
|
264
|
+
} finally {
|
|
265
|
+
_iterator.f();
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
};
|
|
269
|
+
var currentKey = targetKey;
|
|
270
|
+
while (true) {
|
|
271
|
+
var parent = findDirectParent(currentKey);
|
|
272
|
+
if (!parent) break;
|
|
273
|
+
var parentKey = getRowKey(parent, rowKey);
|
|
274
|
+
ancestors.push(parentKey);
|
|
275
|
+
currentKey = parentKey;
|
|
276
|
+
}
|
|
277
|
+
return ancestors;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* 计算级联选择后的keys(包含向上级联)
|
|
282
|
+
* @param targetKey 被操作的节点key
|
|
283
|
+
* @param isChecked 当前是否选中
|
|
284
|
+
* @param currentSelectedKeys 当前已选中的keys
|
|
285
|
+
* @param checkStrictly 是否严格模式
|
|
286
|
+
* @param isExpandable 是否启用展开功能
|
|
287
|
+
* @param getDescendantKeys 获取子孙节点keys的函数
|
|
288
|
+
* @param getAncestorKeys 获取祖先节点keys的函数
|
|
289
|
+
* @returns 新的选中keys
|
|
290
|
+
*/
|
|
291
|
+
export function calculateCascadeSelection(targetKey, isChecked, currentSelectedKeys, checkStrictly, isExpandable, getDescendantKeys, getAncestorKeys) {
|
|
292
|
+
if (checkStrictly || !isExpandable || !getDescendantKeys || !getAncestorKeys) {
|
|
293
|
+
// 严格模式,不进行级联
|
|
294
|
+
return isChecked ? currentSelectedKeys.filter(function (key) {
|
|
295
|
+
return key !== targetKey;
|
|
296
|
+
}) : [].concat(_toConsumableArray(currentSelectedKeys), [targetKey]);
|
|
297
|
+
}
|
|
298
|
+
var newKeys = _toConsumableArray(currentSelectedKeys);
|
|
299
|
+
if (isChecked) {
|
|
300
|
+
// 取消选择:移除目标节点和所有子孙节点
|
|
301
|
+
newKeys = newKeys.filter(function (key) {
|
|
302
|
+
return key !== targetKey;
|
|
303
|
+
});
|
|
304
|
+
var descendants = getDescendantKeys(targetKey);
|
|
305
|
+
newKeys = newKeys.filter(function (key) {
|
|
306
|
+
return !descendants.includes(key);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// 向上级联:检查父节点是否需要取消选择
|
|
310
|
+
var ancestors = getAncestorKeys(targetKey);
|
|
311
|
+
ancestors.forEach(function (ancestorKey) {
|
|
312
|
+
var ancestorDescendants = getDescendantKeys(ancestorKey);
|
|
313
|
+
var selectedDescendantsCount = ancestorDescendants.filter(function (key) {
|
|
314
|
+
return newKeys.includes(key);
|
|
315
|
+
}).length;
|
|
316
|
+
|
|
317
|
+
// 如果子孙节点没有全部选中,则父节点也应该取消选择
|
|
318
|
+
if (selectedDescendantsCount < ancestorDescendants.length) {
|
|
319
|
+
newKeys = newKeys.filter(function (key) {
|
|
320
|
+
return key !== ancestorKey;
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
} else {
|
|
325
|
+
// 选择:添加目标节点和所有子孙节点
|
|
326
|
+
if (!newKeys.includes(targetKey)) {
|
|
327
|
+
newKeys.push(targetKey);
|
|
328
|
+
}
|
|
329
|
+
var _descendants = getDescendantKeys(targetKey);
|
|
330
|
+
_descendants.forEach(function (descendantKey) {
|
|
331
|
+
if (!newKeys.includes(descendantKey)) {
|
|
332
|
+
newKeys.push(descendantKey);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// 向上级联:检查父节点是否需要选择
|
|
337
|
+
var _ancestors = getAncestorKeys(targetKey);
|
|
338
|
+
_ancestors.forEach(function (ancestorKey) {
|
|
339
|
+
var ancestorDescendants = getDescendantKeys(ancestorKey);
|
|
340
|
+
var selectedDescendantsCount = ancestorDescendants.filter(function (key) {
|
|
341
|
+
return newKeys.includes(key);
|
|
342
|
+
}).length;
|
|
343
|
+
|
|
344
|
+
// 如果所有子孙节点都被选中,则父节点也应该被选中
|
|
345
|
+
if (selectedDescendantsCount === ancestorDescendants.length && !newKeys.includes(ancestorKey)) {
|
|
346
|
+
newKeys.push(ancestorKey);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
return newKeys;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* 计算节点的选择状态(考虑子节点状态)
|
|
355
|
+
* @param nodeKey 节点key
|
|
356
|
+
* @param selectedRowKeys 已选中的keys
|
|
357
|
+
* @param checkStrictly 是否严格模式
|
|
358
|
+
* @param isExpandable 是否启用展开功能
|
|
359
|
+
* @param getDescendantKeys 获取子孙节点keys的函数
|
|
360
|
+
* @returns 节点的选择状态
|
|
361
|
+
*/
|
|
362
|
+
export function calculateNodeCheckStatus(nodeKey, selectedRowKeys, checkStrictly, isExpandable, getDescendantKeys) {
|
|
363
|
+
if (checkStrictly || !isExpandable || !getDescendantKeys) {
|
|
364
|
+
// 严格模式下或非展开模式,直接返回节点本身的选择状态
|
|
365
|
+
return {
|
|
366
|
+
checked: selectedRowKeys.includes(nodeKey),
|
|
367
|
+
indeterminate: false
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
var descendants = getDescendantKeys(nodeKey);
|
|
371
|
+
|
|
372
|
+
// 如果没有子节点,直接返回本身状态
|
|
373
|
+
if (descendants.length === 0) {
|
|
374
|
+
return {
|
|
375
|
+
checked: selectedRowKeys.includes(nodeKey),
|
|
376
|
+
indeterminate: false
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
var selectedDescendants = descendants.filter(function (key) {
|
|
380
|
+
return selectedRowKeys.includes(key);
|
|
381
|
+
});
|
|
382
|
+
var isNodeSelected = selectedRowKeys.includes(nodeKey);
|
|
383
|
+
if (isNodeSelected && selectedDescendants.length === descendants.length) {
|
|
384
|
+
// 节点本身选中且所有子节点都选中
|
|
385
|
+
return {
|
|
386
|
+
checked: true,
|
|
387
|
+
indeterminate: false
|
|
388
|
+
};
|
|
389
|
+
} else if (!isNodeSelected && selectedDescendants.length === 0) {
|
|
390
|
+
// 节点本身未选中且所有子节点都未选中
|
|
391
|
+
return {
|
|
392
|
+
checked: false,
|
|
393
|
+
indeterminate: false
|
|
394
|
+
};
|
|
395
|
+
} else {
|
|
396
|
+
// 部分选中的情况:节点选中但子节点未全选,或节点未选中但部分子节点选中
|
|
397
|
+
return {
|
|
398
|
+
checked: false,
|
|
399
|
+
indeterminate: true
|
|
400
|
+
};
|
|
401
|
+
}
|
|
170
402
|
}
|
package/dist/Table/index.js
CHANGED
|
@@ -90,7 +90,11 @@ function Table(props, ref) {
|
|
|
90
90
|
rowKey: rowKey
|
|
91
91
|
});
|
|
92
92
|
var expandableConfig = getExpandableConfig(expandable);
|
|
93
|
-
var rowSelectionInfo = useRowSelection(props)
|
|
93
|
+
var rowSelectionInfo = useRowSelection(_objectSpread(_objectSpread({}, props), {}, {
|
|
94
|
+
data: expandableInfo.data,
|
|
95
|
+
isExpandable: expandableInfo.isExpandable,
|
|
96
|
+
flattenData: expandableInfo.flattenData
|
|
97
|
+
}));
|
|
94
98
|
var rowDndInfo = useRowDnd(_objectSpread(_objectSpread({}, props), {}, {
|
|
95
99
|
columns: rowSelectionInfo.columns,
|
|
96
100
|
data: expandableInfo.data
|
|
@@ -306,13 +310,13 @@ function Table(props, ref) {
|
|
|
306
310
|
style: _objectSpread({
|
|
307
311
|
width: cell.column.getSize()
|
|
308
312
|
}, fixedStyle)
|
|
309
|
-
}, expandableInfo.isExpandable && colIndex === 0 ? /*#__PURE__*/React.createElement(ExpandCell, {
|
|
313
|
+
}, expandableInfo.isExpandable && colIndex === (rowSelectionInfo.isRowSelectionEnabled ? 1 : 0) ? /*#__PURE__*/React.createElement(ExpandCell, {
|
|
310
314
|
expandableInfo: expandableInfo,
|
|
311
315
|
expandable: expandable,
|
|
312
316
|
data: row.original,
|
|
313
317
|
rowKey: rowKey
|
|
314
318
|
}, tdContent) : tdContent);
|
|
315
|
-
}, [expandableInfo, expandable, rowKey, getColumnFixedInfo]);
|
|
319
|
+
}, [expandableInfo, expandable, rowKey, getColumnFixedInfo, rowSelectionInfo.isRowSelectionEnabled]);
|
|
316
320
|
|
|
317
321
|
// 渲染 body
|
|
318
322
|
var bodyContent = /*#__PURE__*/React.createElement("div", {
|
package/dist/Table/types.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export interface IRowSelection<TDataItem extends object> {
|
|
|
59
59
|
selectedRowKeys?: string[];
|
|
60
60
|
defaultSelectedRowKeys?: string[];
|
|
61
61
|
items?: IRowSelectionBtnItem<TDataItem>[];
|
|
62
|
+
checkStrictly?: boolean;
|
|
62
63
|
onChange?: (selectedRowKeys: string[], selectedRows: TDataItem[]) => void;
|
|
63
64
|
getCheckboxProps?: (record: TDataItem) => Pick<ICheckboxProps, 'disabled' | 'indeterminate' | 'checked'>;
|
|
64
65
|
}
|