@neovici/cosmoz-omnitable 14.27.1 → 14.27.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.
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { GroupItem } from './utils';
|
|
2
|
+
import type { Item } from '../lib/types';
|
|
3
|
+
export interface UseSelectedItemsParams {
|
|
4
|
+
initial: Item[];
|
|
5
|
+
compareItemsFn: <T>(a: T, b: T) => boolean;
|
|
6
|
+
data: (Item | GroupItem<Item>)[];
|
|
7
|
+
flatData: (Item | GroupItem<Item>)[] | undefined;
|
|
8
|
+
}
|
|
9
|
+
export interface UseSelectedItemsResult {
|
|
10
|
+
selectedItems: Item[];
|
|
11
|
+
isItemSelected: (item: Item) => boolean;
|
|
12
|
+
isGroupSelected: (group: GroupItem<Item>) => boolean;
|
|
13
|
+
isSelected: (item: Item | GroupItem<Item>) => boolean;
|
|
14
|
+
select: (item: Item | GroupItem<Item>) => void;
|
|
15
|
+
deselect: (item: Item | GroupItem<Item>) => void;
|
|
16
|
+
selectOnly: (item: Item | GroupItem<Item>) => void;
|
|
14
17
|
selectAll: () => void;
|
|
15
18
|
deselectAll: () => void;
|
|
16
|
-
toggleSelect: (item:
|
|
17
|
-
toggleSelectTo: (item:
|
|
18
|
-
}
|
|
19
|
+
toggleSelect: (item: Item | GroupItem<Item>, selected?: boolean) => void;
|
|
20
|
+
toggleSelectTo: (item: Item | GroupItem<Item>, selected?: boolean) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare const useSelectedItems: ({ initial, compareItemsFn, data, flatData, }: UseSelectedItemsParams) => UseSelectedItemsResult;
|
|
19
23
|
//# sourceMappingURL=use-selected-items.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-selected-items.d.ts","sourceRoot":"","sources":["../../src/grouped-list/use-selected-items.
|
|
1
|
+
{"version":3,"file":"use-selected-items.d.ts","sourceRoot":"","sources":["../../src/grouped-list/use-selected-items.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,WAAW,sBAAsB;IACtC,OAAO,EAAE,IAAI,EAAE,CAAC;IAChB,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;IAC3C,IAAI,EAAE,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;IACjC,QAAQ,EAAE,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;CACjD;AAED,MAAM,WAAW,sBAAsB;IACtC,aAAa,EAAE,IAAI,EAAE,CAAC;IACtB,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;IACxC,eAAe,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC;IACrD,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC;IACtD,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC/C,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IACjD,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IACnD,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACzE,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CAC3E;AAED,eAAO,MAAM,gBAAgB,GAAI,8CAK9B,sBAAsB,KAAG,sBAiI3B,CAAC"}
|
|
@@ -1,74 +1,70 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from '@pionjs/pion';
|
|
2
2
|
import { isGroup } from './utils';
|
|
3
3
|
export const useSelectedItems = ({ initial, compareItemsFn, data, flatData, }) => {
|
|
4
|
-
const [selectedItems, setSelectedItems] = useState(initial)
|
|
4
|
+
const [selectedItems, setSelectedItems] = useState(initial);
|
|
5
|
+
const [lastSelection, setLastSelection] = useState();
|
|
5
6
|
/**
|
|
6
7
|
* Check if item is selected.
|
|
7
|
-
* @param {object} item Item.
|
|
8
|
-
* @returns {boolean} Whether item is selected.
|
|
9
8
|
*/
|
|
10
|
-
isItemSelected = useCallback((item) => selectedItems.includes(item), [selectedItems])
|
|
9
|
+
const isItemSelected = useCallback((item) => selectedItems.includes(item), [selectedItems]);
|
|
11
10
|
/**
|
|
12
11
|
* Check if group is selected.
|
|
13
|
-
* @param {object} group Group.
|
|
14
|
-
* @returns {boolean} Whether group is selected.
|
|
15
12
|
*/
|
|
16
|
-
isGroupSelected = useCallback((group) => group?.items?.every(isItemSelected), [isItemSelected])
|
|
13
|
+
const isGroupSelected = useCallback((group) => group?.items?.every(isItemSelected) ?? false, [isItemSelected]);
|
|
17
14
|
/**
|
|
18
15
|
* Check if item.group is selected.
|
|
19
|
-
* @param {object} item Item.
|
|
20
|
-
* @returns {boolean} Whether item is selected.
|
|
21
16
|
*/
|
|
22
|
-
isSelected = useCallback((item) => isItemSelected(item) || isGroupSelected(item), [isItemSelected, isGroupSelected])
|
|
17
|
+
const isSelected = useCallback((item) => isItemSelected(item) || isGroupSelected(item), [isItemSelected, isGroupSelected]);
|
|
23
18
|
/**
|
|
24
19
|
* Add an item/group to the list of selected items.
|
|
25
|
-
* @param {object} item Item to select.
|
|
26
|
-
* @returns {void}
|
|
27
20
|
*/
|
|
28
|
-
select = useCallback((item) => {
|
|
29
|
-
const
|
|
21
|
+
const select = useCallback((item) => {
|
|
22
|
+
const groupItem = item;
|
|
23
|
+
const items = groupItem.items ?? [item];
|
|
30
24
|
setSelectedItems((selection) => [
|
|
31
25
|
...selection,
|
|
32
26
|
...items.filter((i) => !selection.includes(i)),
|
|
33
27
|
]);
|
|
34
28
|
setLastSelection(item);
|
|
35
|
-
}, [])
|
|
29
|
+
}, []);
|
|
36
30
|
/**
|
|
37
31
|
* Removes an item/group from the list of selected items.
|
|
38
|
-
* @param {object} item Item to select.
|
|
39
|
-
* @returns {void}
|
|
40
32
|
*/
|
|
41
|
-
deselect = useCallback((item) => {
|
|
42
|
-
const
|
|
33
|
+
const deselect = useCallback((item) => {
|
|
34
|
+
const groupItem = item;
|
|
35
|
+
const items = groupItem.items ?? [item];
|
|
43
36
|
setSelectedItems((selection) => selection.filter((i) => !items.includes(i)));
|
|
44
37
|
setLastSelection(item);
|
|
45
|
-
}, [])
|
|
46
|
-
|
|
38
|
+
}, []);
|
|
39
|
+
const selectOnly = useCallback((item) => {
|
|
40
|
+
const groupItem = item;
|
|
41
|
+
setSelectedItems(groupItem.items?.slice() || [item]);
|
|
47
42
|
setLastSelection(item);
|
|
48
|
-
}, [])
|
|
43
|
+
}, []);
|
|
49
44
|
/**
|
|
50
45
|
* Select all items.
|
|
51
|
-
* @returns {void}
|
|
52
46
|
*/
|
|
53
|
-
selectAll = useCallback(() => {
|
|
54
|
-
setSelectedItems(data.flatMap((item) =>
|
|
47
|
+
const selectAll = useCallback(() => {
|
|
48
|
+
setSelectedItems(data.flatMap((item) => {
|
|
49
|
+
const groupItem = item;
|
|
50
|
+
return groupItem.items || item;
|
|
51
|
+
}));
|
|
55
52
|
setLastSelection(undefined);
|
|
56
|
-
}, [data])
|
|
53
|
+
}, [data]);
|
|
57
54
|
/**
|
|
58
55
|
* Deselect all selected items.
|
|
59
|
-
* @returns {void}
|
|
60
56
|
*/
|
|
61
|
-
deselectAll = useCallback(() => {
|
|
57
|
+
const deselectAll = useCallback(() => {
|
|
62
58
|
setSelectedItems([]);
|
|
63
59
|
setLastSelection(undefined);
|
|
64
|
-
}, [])
|
|
60
|
+
}, []);
|
|
65
61
|
/**
|
|
66
62
|
* Toggles the selection of an item/group.
|
|
67
|
-
* @param {object} item Item to select.
|
|
68
|
-
* @param {boolean=} selected Select or deselect, fallback to toggling.
|
|
69
|
-
* @returns {void}
|
|
70
63
|
*/
|
|
71
|
-
toggleSelect = useCallback((item, selected = !isSelected(item)) => selected ? select(item) : deselect(item), [isSelected])
|
|
64
|
+
const toggleSelect = useCallback((item, selected = !isSelected(item)) => selected ? select(item) : deselect(item), [isSelected]);
|
|
65
|
+
const toggleSelectTo = useCallback((item, selected) => {
|
|
66
|
+
if (!flatData)
|
|
67
|
+
return;
|
|
72
68
|
const last = lastSelection
|
|
73
69
|
? flatData.findIndex((i) => compareItemsFn(i, lastSelection))
|
|
74
70
|
: -1;
|
|
@@ -85,7 +81,7 @@ export const useSelectedItems = ({ initial, compareItemsFn, data, flatData, }) =
|
|
|
85
81
|
setLastSelection(item);
|
|
86
82
|
}, [flatData, compareItemsFn, toggleSelect]);
|
|
87
83
|
// keep selected items across data updates
|
|
88
|
-
useEffect(() => setSelectedItems((selectedItems) => selectedItems.length > 0
|
|
84
|
+
useEffect(() => setSelectedItems((selectedItems) => selectedItems.length > 0 && flatData
|
|
89
85
|
? flatData.filter((i) => selectedItems.find((item) => compareItemsFn(i, item)))
|
|
90
86
|
: selectedItems), [flatData]);
|
|
91
87
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-omnitable",
|
|
3
|
-
"version": "14.27.
|
|
3
|
+
"version": "14.27.2",
|
|
4
4
|
"description": "[](https://travis-ci.org/Neovici/cosmoz-omnitable)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|
|
@@ -137,6 +137,7 @@
|
|
|
137
137
|
"@polymer/paper-toggle-button": "^3.0.0",
|
|
138
138
|
"@semantic-release/changelog": "^6.0.0",
|
|
139
139
|
"@semantic-release/git": "^10.0.0",
|
|
140
|
+
"@storybook/addon-docs": "^9.1.10",
|
|
140
141
|
"@storybook/web-components-vite": "^9.1.3",
|
|
141
142
|
"@types/file-saver": "^2.0.0",
|
|
142
143
|
"@web/dev-server-esbuild": "^1.0.4",
|