@neovici/cosmoz-omnitable 14.27.0 → 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.
- package/dist/grouped-list/use-cosmoz-grouped-list.d.ts +1 -1
- package/dist/grouped-list/use-selected-items.d.ts +20 -16
- package/dist/grouped-list/use-selected-items.d.ts.map +1 -1
- package/dist/grouped-list/use-selected-items.js +30 -34
- package/dist/grouped-list/utils.d.ts +20 -9
- package/dist/grouped-list/utils.d.ts.map +1 -1
- package/dist/grouped-list/utils.js +22 -22
- package/package.json +2 -1
|
@@ -10,6 +10,6 @@ export function renderCosmozGroupedList({ renderRow, flatData }: {
|
|
|
10
10
|
}): any;
|
|
11
11
|
export function useCosmozGroupedList(host: any): {
|
|
12
12
|
renderRow: (item: any, index: any) => any;
|
|
13
|
-
flatData:
|
|
13
|
+
flatData: (object | import("./utils").GroupItem<object>)[] | undefined;
|
|
14
14
|
};
|
|
15
15
|
//# sourceMappingURL=use-cosmoz-grouped-list.d.ts.map
|
|
@@ -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 {
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Item } from '../lib/types';
|
|
2
|
+
export interface ItemState {
|
|
3
|
+
expanded?: boolean;
|
|
4
|
+
folded?: boolean;
|
|
3
5
|
}
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
export interface GroupItem<T = unknown> {
|
|
7
|
+
items?: T[];
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export type ItemsState = WeakMap<Item, ItemState>;
|
|
11
|
+
declare const symbols: {
|
|
12
|
+
group: symbol;
|
|
13
|
+
};
|
|
14
|
+
declare const getItemState: (item: Item, itemsState: ItemsState) => ItemState;
|
|
15
|
+
declare const isExpanded: (item: Item, itemsState: ItemsState) => boolean;
|
|
16
|
+
declare const isFolded: (group: Item, itemsState: ItemsState) => boolean;
|
|
17
|
+
declare const isGroup: (item: unknown) => item is GroupItem;
|
|
18
|
+
declare const prepareData: <T extends Item>(data: T[] | GroupItem<T>[], displayEmptyGroups: boolean, itemsState: ItemsState) => (T | GroupItem<T>)[] | undefined;
|
|
19
|
+
declare const callFn: <T, A extends unknown[]>(fn: ((...args: A) => T) | T, ...args: A) => T;
|
|
20
|
+
declare const byReference: <T>(a: T, b: T) => boolean;
|
|
21
|
+
export { symbols, prepareData, getItemState, isExpanded, isFolded, isGroup, callFn, byReference, };
|
|
11
22
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/grouped-list/utils.
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/grouped-list/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACrC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AAElD,QAAA,MAAM,OAAO;;CAEZ,CAAC;AAEF,QAAA,MAAM,YAAY,GAAI,MAAM,IAAI,EAAE,YAAY,UAAU,KAAG,SAM1D,CAAC;AAEF,QAAA,MAAM,UAAU,GAAI,MAAM,IAAI,EAAE,YAAY,UAAU,KAAG,OACR,CAAC;AAElD,QAAA,MAAM,QAAQ,GAAI,OAAO,IAAI,EAAE,YAAY,UAAU,KAAG,OACR,CAAC;AAEjD,QAAA,MAAM,OAAO,GAAI,MAAM,OAAO,KAAG,IAAI,IAAI,SACiB,CAAC;AAkB3D,QAAA,MAAM,WAAW,GAAI,CAAC,SAAS,IAAI,EAClC,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,EAC1B,oBAAoB,OAAO,EAC3B,YAAY,UAAU,KACpB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,SAyCzB,CAAC;AAEF,QAAA,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EACrC,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAC3B,GAAG,MAAM,CAAC,KACR,CAMF,CAAC;AAEF,QAAA,MAAM,WAAW,GAAI,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,KAAG,OAAkB,CAAC;AAExD,OAAO,EACN,OAAO,EACP,WAAW,EACX,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,OAAO,EACP,MAAM,EACN,WAAW,GACX,CAAC"}
|
|
@@ -1,49 +1,42 @@
|
|
|
1
1
|
const symbols = {
|
|
2
2
|
group: Symbol('group'),
|
|
3
|
-
}
|
|
3
|
+
};
|
|
4
|
+
const getItemState = (item, itemsState) => {
|
|
4
5
|
if (!itemsState.has(item)) {
|
|
5
6
|
itemsState.set(item, {});
|
|
6
7
|
}
|
|
7
8
|
return itemsState.get(item);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
_assertDataIsHomogeneous = (data) => {
|
|
9
|
+
};
|
|
10
|
+
const isExpanded = (item, itemsState) => Boolean(getItemState(item, itemsState).expanded);
|
|
11
|
+
const isFolded = (group, itemsState) => Boolean(getItemState(group, itemsState).folded);
|
|
12
|
+
const isGroup = (item) => item ? item.items instanceof Array : false;
|
|
13
|
+
const _assertDataIsHomogeneous = (data) => {
|
|
15
14
|
if (!Array.isArray(data) || data.length === 0) {
|
|
16
15
|
return;
|
|
17
16
|
}
|
|
18
|
-
const firstItemIsAGroup = Array.isArray(data[0]
|
|
17
|
+
const firstItemIsAGroup = Array.isArray(data[0]?.items), isHomogeneous = data.every((group) => Array.isArray(group.items) === firstItemIsAGroup);
|
|
19
18
|
if (!isHomogeneous) {
|
|
20
19
|
throw new Error('Data must be homogeneous.');
|
|
21
20
|
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
* Prepare data.
|
|
25
|
-
* @param {array} data Data.
|
|
26
|
-
* @param {boolean} displayEmptyGroups Flag.
|
|
27
|
-
* @param {WeakMap} itemsState State.
|
|
28
|
-
* @returns {void|array} Prepared data.
|
|
29
|
-
*/
|
|
30
|
-
prepareData = (data, displayEmptyGroups, itemsState) => {
|
|
21
|
+
};
|
|
22
|
+
const prepareData = (data, displayEmptyGroups, itemsState) => {
|
|
31
23
|
if (!Array.isArray(data)) {
|
|
32
24
|
return;
|
|
33
25
|
}
|
|
34
26
|
// data should be either all items or all grouped items, never mixed
|
|
35
27
|
_assertDataIsHomogeneous(data);
|
|
36
28
|
const flatData = data.reduce((acc, item) => {
|
|
29
|
+
const groupItem = item;
|
|
37
30
|
// simple items
|
|
38
|
-
if (!
|
|
31
|
+
if (!groupItem.items) {
|
|
39
32
|
return acc.concat(item);
|
|
40
33
|
}
|
|
41
34
|
// groups with items
|
|
42
|
-
if (
|
|
35
|
+
if (groupItem.items.length) {
|
|
43
36
|
if (getItemState(item, itemsState).folded) {
|
|
44
37
|
return acc.concat(item);
|
|
45
38
|
}
|
|
46
|
-
return acc.concat(item,
|
|
39
|
+
return acc.concat(item, groupItem.items.map((i) => Object.assign(i, { [symbols.group]: item })));
|
|
47
40
|
}
|
|
48
41
|
// groups without items
|
|
49
42
|
if (displayEmptyGroups) {
|
|
@@ -52,6 +45,13 @@ prepareData = (data, displayEmptyGroups, itemsState) => {
|
|
|
52
45
|
return acc;
|
|
53
46
|
}, []);
|
|
54
47
|
return flatData;
|
|
55
|
-
}
|
|
48
|
+
};
|
|
49
|
+
const callFn = (fn, ...args) => {
|
|
50
|
+
if (typeof fn === 'function') {
|
|
51
|
+
return fn(...args);
|
|
52
|
+
}
|
|
53
|
+
return fn;
|
|
54
|
+
};
|
|
55
|
+
const byReference = (a, b) => a === b;
|
|
56
56
|
export { symbols, prepareData, getItemState, isExpanded, isFolded, isGroup, callFn, byReference, };
|
|
57
57
|
//# sourceMappingURL=utils.js.map
|
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",
|