@snack-uikit/table 0.36.8 → 0.36.10-preview-b77e2c1f.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 +11 -0
- package/dist/cjs/components/Table/hooks/useFilters/useFilters.d.ts +4 -4
- package/dist/cjs/components/Table/hooks/useStateControl.d.ts +3 -2
- package/dist/cjs/components/Table/hooks/useStateControl.js +9 -7
- package/dist/cjs/helperComponents/Cells/SelectionCell/SelectionCell.js +5 -1
- package/dist/esm/components/Table/hooks/useFilters/useFilters.d.ts +4 -4
- package/dist/esm/components/Table/hooks/useStateControl.d.ts +3 -2
- package/dist/esm/components/Table/hooks/useStateControl.js +10 -7
- package/dist/esm/helperComponents/Cells/SelectionCell/SelectionCell.js +5 -1
- package/package.json +2 -2
- package/src/components/Table/hooks/useFilters/useFilters.ts +1 -1
- package/src/components/Table/hooks/useStateControl.ts +14 -14
- 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
|
|
@@ -2,12 +2,12 @@ import { TableProps } from '../../../types';
|
|
|
2
2
|
type useFiltersProps<TData extends object, TFilters extends Record<string, unknown>> = Pick<TableProps<TData, TFilters>, 'columnFilters'>;
|
|
3
3
|
export declare function useFilters<TData extends object, TFilters extends Record<string, unknown>>({ columnFilters, }: useFiltersProps<TData, TFilters>): {
|
|
4
4
|
filter: TFilters | undefined;
|
|
5
|
-
setFilter: import("
|
|
5
|
+
setFilter: import("@tanstack/react-table").OnChangeFn<TFilters | undefined>;
|
|
6
6
|
patchedFilter: {
|
|
7
7
|
value: TFilters | undefined;
|
|
8
|
-
onChange:
|
|
8
|
+
onChange: (filter: TFilters) => void;
|
|
9
9
|
visibleFilters: string[];
|
|
10
|
-
onVisibleFiltersChange: import("
|
|
10
|
+
onVisibleFiltersChange: import("@tanstack/react-table").OnChangeFn<string[]>;
|
|
11
11
|
className?: string;
|
|
12
12
|
"aria-activedescendant"?: string | undefined;
|
|
13
13
|
"aria-atomic"?: (boolean | "true" | "false") | undefined;
|
|
@@ -70,6 +70,6 @@ export declare function useFilters<TData extends object, TFilters extends Record
|
|
|
70
70
|
onOpenChange: (isOpen: boolean) => void;
|
|
71
71
|
initialOpen?: boolean;
|
|
72
72
|
} | undefined;
|
|
73
|
-
setFilterVisibility: import("
|
|
73
|
+
setFilterVisibility: import("@tanstack/react-table").OnChangeFn<string[]>;
|
|
74
74
|
};
|
|
75
75
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { OnChangeFn } from '@tanstack/react-table';
|
|
2
|
+
export declare function useStateControl<TState extends object | string | number | boolean | undefined>(control: {
|
|
2
3
|
initialState?: TState;
|
|
3
4
|
state?: TState;
|
|
4
5
|
onChange?(state: TState): void;
|
|
5
|
-
} | undefined, defaultState: TState): readonly [TState,
|
|
6
|
+
} | undefined, defaultState: TState): readonly [TState, OnChangeFn<TState>];
|
|
@@ -4,14 +4,16 @@ 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
|
-
const state = control === null || control === void 0 ? void 0 : control.state;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const [state, setState] = (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);
|
|
11
|
+
const onChangeFunction = updater => {
|
|
12
|
+
if (typeof updater === 'function') {
|
|
13
|
+
setState(updater(state));
|
|
14
|
+
} else {
|
|
15
|
+
setState(updater);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return [state, onChangeFunction];
|
|
17
19
|
}
|
|
@@ -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
|
}
|
|
@@ -2,12 +2,12 @@ import { TableProps } from '../../../types';
|
|
|
2
2
|
type useFiltersProps<TData extends object, TFilters extends Record<string, unknown>> = Pick<TableProps<TData, TFilters>, 'columnFilters'>;
|
|
3
3
|
export declare function useFilters<TData extends object, TFilters extends Record<string, unknown>>({ columnFilters, }: useFiltersProps<TData, TFilters>): {
|
|
4
4
|
filter: TFilters | undefined;
|
|
5
|
-
setFilter: import("
|
|
5
|
+
setFilter: import("@tanstack/react-table").OnChangeFn<TFilters | undefined>;
|
|
6
6
|
patchedFilter: {
|
|
7
7
|
value: TFilters | undefined;
|
|
8
|
-
onChange:
|
|
8
|
+
onChange: (filter: TFilters) => void;
|
|
9
9
|
visibleFilters: string[];
|
|
10
|
-
onVisibleFiltersChange: import("
|
|
10
|
+
onVisibleFiltersChange: import("@tanstack/react-table").OnChangeFn<string[]>;
|
|
11
11
|
className?: string;
|
|
12
12
|
"aria-activedescendant"?: string | undefined;
|
|
13
13
|
"aria-atomic"?: (boolean | "true" | "false") | undefined;
|
|
@@ -70,6 +70,6 @@ export declare function useFilters<TData extends object, TFilters extends Record
|
|
|
70
70
|
onOpenChange: (isOpen: boolean) => void;
|
|
71
71
|
initialOpen?: boolean;
|
|
72
72
|
} | undefined;
|
|
73
|
-
setFilterVisibility: import("
|
|
73
|
+
setFilterVisibility: import("@tanstack/react-table").OnChangeFn<string[]>;
|
|
74
74
|
};
|
|
75
75
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { OnChangeFn } from '@tanstack/react-table';
|
|
2
|
+
export declare function useStateControl<TState extends object | string | number | boolean | undefined>(control: {
|
|
2
3
|
initialState?: TState;
|
|
3
4
|
state?: TState;
|
|
4
5
|
onChange?(state: TState): void;
|
|
5
|
-
} | undefined, defaultState: TState): readonly [TState,
|
|
6
|
+
} | undefined, defaultState: TState): readonly [TState, OnChangeFn<TState>];
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
1
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
3
2
|
export function useStateControl(control, defaultState) {
|
|
4
3
|
var _a, _b;
|
|
5
|
-
const state = control === null || control === void 0 ? void 0 : control.state;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const [state, setState] = 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);
|
|
5
|
+
const onChangeFunction = updater => {
|
|
6
|
+
if (typeof updater === 'function') {
|
|
7
|
+
setState(updater(state));
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
setState(updater);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
return [state, onChangeFunction];
|
|
11
14
|
}
|
|
@@ -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.10-preview-b77e2c1f.0",
|
|
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": "836fb8f9e1ad5cea53441c1c087dee8d91b0fe3c"
|
|
70
70
|
}
|
|
@@ -45,7 +45,7 @@ export function useFilters<TData extends object, TFilters extends Record<string,
|
|
|
45
45
|
onOpenChange: setAreColumnFiltersOpen,
|
|
46
46
|
...columnFilters,
|
|
47
47
|
value: filter,
|
|
48
|
-
onChange: setFilter,
|
|
48
|
+
onChange: setFilter as (filter: TFilters) => void,
|
|
49
49
|
visibleFilters: filterVisibility,
|
|
50
50
|
onVisibleFiltersChange: setFilterVisibility,
|
|
51
51
|
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OnChangeFn } from '@tanstack/react-table';
|
|
2
2
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
3
3
|
|
|
4
|
-
export function useStateControl<TState>(
|
|
4
|
+
export function useStateControl<TState extends object | string | number | boolean | undefined>(
|
|
5
5
|
control: { initialState?: TState; state?: TState; onChange?(state: TState): void } | undefined,
|
|
6
6
|
defaultState: TState,
|
|
7
7
|
) {
|
|
8
|
-
const state =
|
|
9
|
-
const onChange = control?.onChange;
|
|
10
|
-
|
|
11
|
-
return useUncontrolledProp<TState>(
|
|
8
|
+
const [state, setState] = useUncontrolledProp<TState>(
|
|
12
9
|
control?.state,
|
|
13
10
|
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
|
-
),
|
|
11
|
+
control?.onChange,
|
|
22
12
|
);
|
|
13
|
+
|
|
14
|
+
const onChangeFunction: OnChangeFn<TState> = updater => {
|
|
15
|
+
if (typeof updater === 'function') {
|
|
16
|
+
setState(updater(state));
|
|
17
|
+
} else {
|
|
18
|
+
setState(updater);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return [state, onChangeFunction] as const;
|
|
23
23
|
}
|
|
@@ -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
|
}
|