@snack-uikit/table 0.36.8 → 0.36.9
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 +11 -0
- package/dist/cjs/components/Table/Table.js +7 -1
- package/dist/cjs/components/Table/hooks/useStateControl.js +1 -7
- package/dist/cjs/helperComponents/Cells/SelectionCell/SelectionCell.js +5 -1
- package/dist/esm/components/Table/Table.js +8 -1
- package/dist/esm/components/Table/hooks/useStateControl.js +1 -7
- package/dist/esm/helperComponents/Cells/SelectionCell/SelectionCell.js +5 -1
- package/package.json +2 -2
- package/src/components/Table/Table.tsx +7 -1
- package/src/components/Table/hooks/useStateControl.ts +1 -12
- package/src/helperComponents/Cells/SelectionCell/SelectionCell.tsx +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.36.9 (2025-06-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **FF-0000:** rowSelection.onChange callback ([e5f537d](https://github.com/cloud-ru-tech/snack-uikit/commit/e5f537d8dcc26cda4bde8afd59b4ef334006f4af))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 0.36.8 (2025-06-16)
|
|
7
18
|
|
|
8
19
|
### Only dependencies have been changed
|
|
@@ -224,7 +224,13 @@ function Table(_a) {
|
|
|
224
224
|
globalFilterFn: enableFuzzySearch ? utils_2.fuzzyFilter : 'includesString',
|
|
225
225
|
onGlobalFilterChange,
|
|
226
226
|
getRowId,
|
|
227
|
-
onRowSelectionChange
|
|
227
|
+
onRowSelectionChange: updater => {
|
|
228
|
+
if (typeof updater === 'function') {
|
|
229
|
+
onRowSelectionChange(updater(rowSelection));
|
|
230
|
+
} else {
|
|
231
|
+
onRowSelectionChange(updater);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
228
234
|
enableGrouping: true,
|
|
229
235
|
enableRowSelection,
|
|
230
236
|
enableMultiRowSelection: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow,
|
|
@@ -4,14 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useStateControl = useStateControl;
|
|
7
|
-
const react_1 = require("react");
|
|
8
7
|
const uncontrollable_1 = require("uncontrollable");
|
|
9
8
|
function useStateControl(control, defaultState) {
|
|
10
9
|
var _a, _b;
|
|
11
|
-
|
|
12
|
-
const onChange = control === null || control === void 0 ? void 0 : control.onChange;
|
|
13
|
-
return (0, uncontrollable_1.useUncontrolledProp)(control === null || control === void 0 ? void 0 : control.state, (_b = (_a = control === null || control === void 0 ? void 0 : control.state) !== null && _a !== void 0 ? _a : control === null || control === void 0 ? void 0 : control.initialState) !== null && _b !== void 0 ? _b : defaultState, (0, react_1.useCallback)(controlState => {
|
|
14
|
-
const newState = typeof controlState === 'function' ? controlState(state || defaultState) : controlState;
|
|
15
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(newState);
|
|
16
|
-
}, [state, defaultState, onChange]));
|
|
10
|
+
return (0, uncontrollable_1.useUncontrolledProp)(control === null || control === void 0 ? void 0 : control.state, (_b = (_a = control === null || control === void 0 ? void 0 : control.state) !== null && _a !== void 0 ? _a : control === null || control === void 0 ? void 0 : control.initialState) !== null && _b !== void 0 ? _b : defaultState, control === null || control === void 0 ? void 0 : control.onChange);
|
|
17
11
|
}
|
|
@@ -69,7 +69,11 @@ function getSelectionCellColumnDef(enableSelectPinned) {
|
|
|
69
69
|
} = table.getRowModel();
|
|
70
70
|
const rowsToToggle = getRowsToToggle(rows, row.id, rows.map(r => r.id).includes(previousClickedRowId) ? previousClickedRowId : '');
|
|
71
71
|
const isSelected = !((_b = rowsById[row.id]) === null || _b === void 0 ? void 0 : _b.getIsSelected()) || false;
|
|
72
|
-
rowsToToggle.
|
|
72
|
+
const newSelected = rowsToToggle.reduce((acc, row) => {
|
|
73
|
+
acc[row.index] = isSelected;
|
|
74
|
+
return acc;
|
|
75
|
+
}, {});
|
|
76
|
+
table.setRowSelection(oldState => Object.assign(Object.assign({}, oldState), newSelected));
|
|
73
77
|
} else {
|
|
74
78
|
row.toggleSelected(!checked);
|
|
75
79
|
}
|
|
@@ -138,7 +138,14 @@ export function Table(_a) {
|
|
|
138
138
|
globalFilterFn: enableFuzzySearch ? fuzzyFilter : 'includesString',
|
|
139
139
|
onGlobalFilterChange,
|
|
140
140
|
getRowId,
|
|
141
|
-
onRowSelectionChange
|
|
141
|
+
onRowSelectionChange: updater => {
|
|
142
|
+
if (typeof updater === 'function') {
|
|
143
|
+
onRowSelectionChange(updater(rowSelection));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
onRowSelectionChange(updater);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
142
149
|
enableGrouping: true,
|
|
143
150
|
enableRowSelection,
|
|
144
151
|
enableMultiRowSelection: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.multiRow,
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
1
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
3
2
|
export function useStateControl(control, defaultState) {
|
|
4
3
|
var _a, _b;
|
|
5
|
-
|
|
6
|
-
const onChange = control === null || control === void 0 ? void 0 : control.onChange;
|
|
7
|
-
return useUncontrolledProp(control === null || control === void 0 ? void 0 : control.state, (_b = (_a = control === null || control === void 0 ? void 0 : control.state) !== null && _a !== void 0 ? _a : control === null || control === void 0 ? void 0 : control.initialState) !== null && _b !== void 0 ? _b : defaultState, useCallback((controlState) => {
|
|
8
|
-
const newState = typeof controlState === 'function' ? controlState(state || defaultState) : controlState;
|
|
9
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(newState);
|
|
10
|
-
}, [state, defaultState, onChange]));
|
|
4
|
+
return useUncontrolledProp(control === null || control === void 0 ? void 0 : control.state, (_b = (_a = control === null || control === void 0 ? void 0 : control.state) !== null && _a !== void 0 ? _a : control === null || control === void 0 ? void 0 : control.initialState) !== null && _b !== void 0 ? _b : defaultState, control === null || control === void 0 ? void 0 : control.onChange);
|
|
11
5
|
}
|
|
@@ -50,7 +50,11 @@ export function getSelectionCellColumnDef(enableSelectPinned) {
|
|
|
50
50
|
const { rows, rowsById } = table.getRowModel();
|
|
51
51
|
const rowsToToggle = getRowsToToggle(rows, row.id, rows.map(r => r.id).includes(previousClickedRowId) ? previousClickedRowId : '');
|
|
52
52
|
const isSelected = !((_b = rowsById[row.id]) === null || _b === void 0 ? void 0 : _b.getIsSelected()) || false;
|
|
53
|
-
rowsToToggle.
|
|
53
|
+
const newSelected = rowsToToggle.reduce((acc, row) => {
|
|
54
|
+
acc[row.index] = isSelected;
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
57
|
+
table.setRowSelection(oldState => (Object.assign(Object.assign({}, oldState), newSelected)));
|
|
54
58
|
}
|
|
55
59
|
else {
|
|
56
60
|
row.toggleSelected(!checked);
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Table",
|
|
7
|
-
"version": "0.36.
|
|
7
|
+
"version": "0.36.9",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"@snack-uikit/locale": "*"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "4898ffc6db1c53aa9998f54b1e41741b80cb01cd"
|
|
70
70
|
}
|
|
@@ -257,7 +257,13 @@ export function Table<TData extends object, TFilters extends FiltersState = Reco
|
|
|
257
257
|
onGlobalFilterChange,
|
|
258
258
|
|
|
259
259
|
getRowId,
|
|
260
|
-
onRowSelectionChange
|
|
260
|
+
onRowSelectionChange: updater => {
|
|
261
|
+
if (typeof updater === 'function') {
|
|
262
|
+
onRowSelectionChange(updater(rowSelection));
|
|
263
|
+
} else {
|
|
264
|
+
onRowSelectionChange(updater);
|
|
265
|
+
}
|
|
266
|
+
},
|
|
261
267
|
enableGrouping: true,
|
|
262
268
|
enableRowSelection,
|
|
263
269
|
enableMultiRowSelection: rowSelectionProp?.multiRow,
|
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
1
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
3
2
|
|
|
4
3
|
export function useStateControl<TState>(
|
|
5
4
|
control: { initialState?: TState; state?: TState; onChange?(state: TState): void } | undefined,
|
|
6
5
|
defaultState: TState,
|
|
7
6
|
) {
|
|
8
|
-
const state = control?.state;
|
|
9
|
-
const onChange = control?.onChange;
|
|
10
|
-
|
|
11
7
|
return useUncontrolledProp<TState>(
|
|
12
8
|
control?.state,
|
|
13
9
|
control?.state ?? control?.initialState ?? defaultState,
|
|
14
|
-
|
|
15
|
-
(controlState: TState) => {
|
|
16
|
-
const newState = typeof controlState === 'function' ? controlState(state || defaultState) : controlState;
|
|
17
|
-
|
|
18
|
-
onChange?.(newState);
|
|
19
|
-
},
|
|
20
|
-
[state, defaultState, onChange],
|
|
21
|
-
),
|
|
10
|
+
control?.onChange,
|
|
22
11
|
);
|
|
23
12
|
}
|
|
@@ -72,7 +72,16 @@ export function getSelectionCellColumnDef<TData>(enableSelectPinned: boolean): C
|
|
|
72
72
|
rows.map(r => r.id).includes(previousClickedRowId) ? previousClickedRowId : '',
|
|
73
73
|
);
|
|
74
74
|
const isSelected = !rowsById[row.id]?.getIsSelected() || false;
|
|
75
|
-
|
|
75
|
+
|
|
76
|
+
const newSelected = rowsToToggle.reduce<Record<string, boolean>>((acc, row) => {
|
|
77
|
+
acc[row.index] = isSelected;
|
|
78
|
+
return acc;
|
|
79
|
+
}, {});
|
|
80
|
+
|
|
81
|
+
table.setRowSelection(oldState => ({
|
|
82
|
+
...oldState,
|
|
83
|
+
...newSelected,
|
|
84
|
+
}));
|
|
76
85
|
} else {
|
|
77
86
|
row.toggleSelected(!checked);
|
|
78
87
|
}
|