@pinnacle0/web-ui 0.3.9 → 0.3.12
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.
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
var __read = (this && this.__read) || function (o, n) {
|
|
13
2
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
3
|
if (!m) return o;
|
|
@@ -36,105 +25,59 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
36
25
|
};
|
|
37
26
|
import React from "react";
|
|
38
27
|
import { Checkbox } from "../Checkbox";
|
|
28
|
+
import { ArrayUtil } from "../../internal/ArrayUtil";
|
|
39
29
|
export var useRowSelection = function (_a) {
|
|
40
30
|
var columns = _a.columns, dataSource = _a.dataSource, rowSelection = _a.rowSelection, rowKey = _a.rowKey;
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (rowSelection) {
|
|
45
|
-
var selectedRowKeys_1 = rowSelection.selectedRowKeys, isDisabled_1 = rowSelection.isDisabled;
|
|
46
|
-
dataSource.forEach(function (data, rowIndex) {
|
|
47
|
-
var key = rowKey === "index" ? rowIndex : data[rowKey];
|
|
48
|
-
var isChecked = selectedRowKeys_1.findIndex(function (_) { return _ === key; }) !== -1;
|
|
49
|
-
var isDisabledRow = (isDisabled_1 === null || isDisabled_1 === void 0 ? void 0 : isDisabled_1(data, rowIndex)) || false;
|
|
50
|
-
result[key] = {
|
|
51
|
-
isChecked: isChecked,
|
|
52
|
-
isDisabled: isDisabledRow,
|
|
53
|
-
data: data,
|
|
54
|
-
};
|
|
55
|
-
});
|
|
31
|
+
var transformedColumns = React.useMemo(function () {
|
|
32
|
+
if (!rowSelection) {
|
|
33
|
+
return __spreadArray([], __read(columns), false);
|
|
56
34
|
}
|
|
57
|
-
|
|
58
|
-
}), 2), rowStatus = _b[0], setRowStatus = _b[1];
|
|
59
|
-
var onRowSelectClick = React.useCallback(function (rowKey) {
|
|
60
|
-
setRowStatus(function (rowStatus) {
|
|
61
|
-
var _a;
|
|
62
|
-
return (__assign(__assign({}, rowStatus), (_a = {}, _a[rowKey] = __assign(__assign({}, rowStatus[rowKey]), { isChecked: !rowStatus[rowKey].isChecked }), _a)));
|
|
63
|
-
});
|
|
64
|
-
}, []);
|
|
65
|
-
var onAllSelectClick = React.useCallback(function (val) {
|
|
66
|
-
setRowStatus(function (rowStatus) {
|
|
67
|
-
var newStatus = {};
|
|
68
|
-
Object.entries(rowStatus).forEach(function (_a) {
|
|
69
|
-
var _b = __read(_a, 2), rowKey = _b[0], status = _b[1];
|
|
70
|
-
newStatus[rowKey] = __assign(__assign({}, status), { isChecked: val ? status.isChecked || !status.isDisabled : status.isChecked && status.isDisabled });
|
|
71
|
-
});
|
|
72
|
-
return newStatus;
|
|
73
|
-
});
|
|
74
|
-
}, []);
|
|
75
|
-
var selectionAllStatus = React.useMemo(function () {
|
|
35
|
+
var width = rowSelection.width, onChange = rowSelection.onChange, selectedRowKeys = rowSelection.selectedRowKeys, fixed = rowSelection.fixed, isDisabled = rowSelection.isDisabled, isSelectAllDisabled = rowSelection.isSelectAllDisabled, title = rowSelection.title;
|
|
76
36
|
var allSelectionRowKeys = [];
|
|
77
37
|
var allSelectionRows = [];
|
|
78
38
|
var unAllSelectionRowKeys = [];
|
|
79
39
|
var unAllSelectionRows = [];
|
|
80
40
|
var enabledRowKeys = [];
|
|
81
41
|
var enabledCheckedRowKeys = [];
|
|
82
|
-
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
42
|
+
dataSource.forEach(function (data, rowIndex) {
|
|
43
|
+
var key = rowKey === "index" ? rowIndex : data[rowKey];
|
|
44
|
+
var isSelected = selectedRowKeys.findIndex(function (_) { return _ === key; }) !== -1;
|
|
45
|
+
var isDisabledRow = (isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(data, rowIndex)) || false;
|
|
46
|
+
if (isDisabledRow) {
|
|
47
|
+
if (isSelected) {
|
|
48
|
+
allSelectionRowKeys.push(key);
|
|
49
|
+
allSelectionRows.push(data[rowIndex]);
|
|
50
|
+
unAllSelectionRowKeys.push(key);
|
|
51
|
+
unAllSelectionRows.push(data[rowIndex]);
|
|
90
52
|
}
|
|
91
53
|
}
|
|
92
54
|
else {
|
|
93
|
-
enabledRowKeys.push(
|
|
94
|
-
|
|
95
|
-
allSelectionRowKeys.push(
|
|
96
|
-
allSelectionRows.push(data);
|
|
55
|
+
enabledRowKeys.push(key);
|
|
56
|
+
isSelected && enabledCheckedRowKeys.push(key);
|
|
57
|
+
allSelectionRowKeys.push(key);
|
|
58
|
+
allSelectionRows.push(data[rowIndex]);
|
|
97
59
|
}
|
|
98
60
|
});
|
|
99
|
-
var
|
|
61
|
+
var onSelectAll = function (val) {
|
|
62
|
+
return val ? onChange(allSelectionRowKeys, allSelectionRows) : onChange(unAllSelectionRowKeys, unAllSelectionRows);
|
|
63
|
+
};
|
|
64
|
+
var isAllSelectionDisabled = isSelectAllDisabled || enabledRowKeys.length === 0;
|
|
100
65
|
var isAllSelected = enabledRowKeys.length === enabledCheckedRowKeys.length;
|
|
101
66
|
var isIndeterminate = enabledCheckedRowKeys.length > 0 && !isAllSelected;
|
|
102
|
-
return {
|
|
103
|
-
isDisabled: isAllSelectionDisabled,
|
|
104
|
-
isSelected: isAllSelected,
|
|
105
|
-
isIndeterminate: isIndeterminate,
|
|
106
|
-
};
|
|
107
|
-
}, [rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.isSelectAllDisabled, rowStatus]);
|
|
108
|
-
var transformedColumns = React.useMemo(function () {
|
|
109
|
-
if (!rowSelection) {
|
|
110
|
-
return __spreadArray([], __read(columns), false);
|
|
111
|
-
}
|
|
112
|
-
var width = rowSelection.width, fixed = rowSelection.fixed, isDisabled = rowSelection.isDisabled, title = rowSelection.title;
|
|
113
67
|
var rowSelectionColumn = {
|
|
114
68
|
width: width,
|
|
115
69
|
fixed: fixed ? "left" : undefined,
|
|
116
|
-
title: title || React.createElement(Checkbox, { disabled:
|
|
70
|
+
title: title || React.createElement(Checkbox, { disabled: isAllSelectionDisabled, indeterminate: isIndeterminate, onChange: onSelectAll, value: isAllSelected }),
|
|
117
71
|
renderData: function (data, rowIndex) {
|
|
118
72
|
var key = rowKey === "index" ? rowIndex : data[rowKey];
|
|
119
|
-
|
|
73
|
+
var toggledSelectedRowKeys = ArrayUtil.toggleElement(selectedRowKeys, key);
|
|
74
|
+
var toggledSelectedRow = ArrayUtil.toggleElement(dataSource, data);
|
|
75
|
+
var isChecked = selectedRowKeys.findIndex(function (_) { return _ === key; }) !== -1;
|
|
76
|
+
return React.createElement(Checkbox, { disabled: isDisabled === null || isDisabled === void 0 ? void 0 : isDisabled(data, rowIndex), value: isChecked, onChange: function () { return onChange(toggledSelectedRowKeys, toggledSelectedRow); } });
|
|
120
77
|
},
|
|
121
78
|
};
|
|
122
79
|
return __spreadArray([rowSelectionColumn], __read(columns), false);
|
|
123
|
-
}, [columns,
|
|
124
|
-
React.useEffect(function () {
|
|
125
|
-
if (onChangeRef.current) {
|
|
126
|
-
var rowKeys_1 = [];
|
|
127
|
-
var rows_1 = [];
|
|
128
|
-
Object.entries(rowStatus).forEach(function (_a) {
|
|
129
|
-
var _b = __read(_a, 2), rowKey = _b[0], status = _b[1];
|
|
130
|
-
if (status.isChecked) {
|
|
131
|
-
rowKeys_1.push(rowKey);
|
|
132
|
-
rows_1.push(status.data);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
onChangeRef.current(rowKeys_1, rows_1);
|
|
136
|
-
}
|
|
137
|
-
}, [rowStatus, onChangeRef]);
|
|
80
|
+
}, [columns, dataSource, rowKey, rowSelection]);
|
|
138
81
|
return transformedColumns;
|
|
139
82
|
};
|
|
140
83
|
//# sourceMappingURL=useRowSelection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRowSelection.js","sourceRoot":"","sources":["../../../src/core/VirtualTable/useRowSelection.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRowSelection.js","sourceRoot":"","sources":["../../../src/core/VirtualTable/useRowSelection.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAC;AACrC,OAAO,EAAC,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAUnD,MAAM,CAAC,IAAM,eAAe,GAAG,UAAkC,EAA2D;QAA1D,OAAO,aAAA,EAAE,UAAU,gBAAA,EAAE,YAAY,kBAAA,EAAE,MAAM,YAAA;IACvG,IAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC;QACrC,IAAI,CAAC,YAAY,EAAE;YACf,gCAAW,OAAO,UAAE;SACvB;QAEM,IAAA,KAAK,GAA8E,YAAY,MAA1F,EAAE,QAAQ,GAAoE,YAAY,SAAhF,EAAE,eAAe,GAAmD,YAAY,gBAA/D,EAAE,KAAK,GAA4C,YAAY,MAAxD,EAAE,UAAU,GAAgC,YAAY,WAA5C,EAAE,mBAAmB,GAAW,YAAY,oBAAvB,EAAE,KAAK,GAAI,YAAY,MAAhB,CAAiB;QAEvG,IAAM,mBAAmB,GAAgB,EAAE,CAAC;QAC5C,IAAM,gBAAgB,GAAc,EAAE,CAAC;QACvC,IAAM,qBAAqB,GAAgB,EAAE,CAAC;QAC9C,IAAM,kBAAkB,GAAc,EAAE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