@neovici/cosmoz-omnitable 12.6.1 → 12.6.3
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/cosmoz-omnitable.js +1 -0
- package/lib/use-public-interface.js +46 -55
- package/package.json +2 -2
package/cosmoz-omnitable.js
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
/* eslint-disable max-lines-per-function */
|
|
2
2
|
import { useImperativeApi } from '@neovici/cosmoz-utils/hooks/use-imperative-api';
|
|
3
|
-
import { useEffect } from 'haunted';
|
|
3
|
+
import { useEffect, useMemo } from 'haunted';
|
|
4
4
|
import { useNotifyProperty } from '@neovici/cosmoz-utils/hooks/use-notify-property';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const removeItems = (items) => {
|
|
10
|
-
const removedItems = [];
|
|
11
|
-
|
|
12
|
-
for (let i = items.length - 1; i >= 0; i -= 1) {
|
|
13
|
-
const removed = host.removeItem(items[i]);
|
|
14
|
-
if (removed != null) {
|
|
15
|
-
removedItems.push(removed);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return removedItems;
|
|
19
|
-
},
|
|
20
|
-
/**
|
|
6
|
+
const mkNapi = (host) => {
|
|
7
|
+
const /**
|
|
21
8
|
* Helper method to remove an item from `data`.
|
|
22
9
|
* @param {Object} item Item to remove
|
|
23
10
|
* @return {Object} item removed
|
|
@@ -35,32 +22,61 @@ export const usePublicInterface = ({ host, visibleData, ...api }) => {
|
|
|
35
22
|
return removed[0];
|
|
36
23
|
}
|
|
37
24
|
},
|
|
38
|
-
replaceItem = (oldItem, newItem) => {
|
|
39
|
-
const itemIndex = host.data.indexOf(oldItem);
|
|
40
|
-
if (itemIndex > -1) {
|
|
41
|
-
return host.replaceItemAtIndex(itemIndex, newItem);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
25
|
replaceItemAtIndex = (index, newItem) => {
|
|
45
26
|
host.data.splice(index, 1, newItem);
|
|
46
27
|
host.data = host.data.slice();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
removeItem,
|
|
32
|
+
removeItems(items) {
|
|
33
|
+
const removedItems = [];
|
|
34
|
+
|
|
35
|
+
for (let i = items.length - 1; i >= 0; i -= 1) {
|
|
36
|
+
const removed = host.removeItem(items[i]);
|
|
37
|
+
if (removed != null) {
|
|
38
|
+
removedItems.push(removed);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return removedItems;
|
|
47
42
|
},
|
|
48
|
-
|
|
43
|
+
|
|
44
|
+
replaceItemAtIndex,
|
|
45
|
+
replaceItem(oldItem, newItem) {
|
|
46
|
+
const itemIndex = host.data.indexOf(oldItem);
|
|
47
|
+
if (itemIndex > -1) {
|
|
48
|
+
return replaceItemAtIndex(itemIndex, newItem);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
selectItem(item) {
|
|
49
53
|
host.shadowRoot.querySelector('#groupedList').select(item);
|
|
50
54
|
},
|
|
51
|
-
selectAll
|
|
55
|
+
selectAll() {
|
|
52
56
|
host.shadowRoot.querySelector('#groupedList').selectAll();
|
|
53
57
|
},
|
|
54
|
-
deselectAll
|
|
58
|
+
deselectAll() {
|
|
55
59
|
host.shadowRoot.querySelector('#groupedList').deselectAll();
|
|
56
60
|
},
|
|
57
|
-
deselectItem
|
|
61
|
+
deselectItem(item) {
|
|
58
62
|
host.shadowRoot.querySelector('#groupedList').deselect(item);
|
|
59
63
|
},
|
|
60
|
-
isItemSelected
|
|
64
|
+
isItemSelected(item) {
|
|
61
65
|
return host.shadowRoot.querySelector('#groupedList').isItemSelected(item);
|
|
62
66
|
},
|
|
63
|
-
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const usePublicInterface = ({
|
|
71
|
+
host,
|
|
72
|
+
visibleData,
|
|
73
|
+
...api
|
|
74
|
+
}) => {
|
|
75
|
+
const { setFilterState } = api,
|
|
76
|
+
napi = useMemo(() => mkNapi(host), []);
|
|
77
|
+
|
|
78
|
+
useImperativeApi(api, Object.values(api));
|
|
79
|
+
useImperativeApi(napi, Object.values(napi));
|
|
64
80
|
|
|
65
81
|
useEffect(() => {
|
|
66
82
|
const handler = (ev) =>
|
|
@@ -78,31 +94,6 @@ export const usePublicInterface = ({ host, visibleData, ...api }) => {
|
|
|
78
94
|
api.sortedFilteredGroupedItems
|
|
79
95
|
);
|
|
80
96
|
useNotifyProperty('selectedItems', api.selectedItems);
|
|
81
|
-
useNotifyProperty('sortOn', api.sortOn)
|
|
82
|
-
useNotifyProperty('descending', api.descending)
|
|
83
|
-
|
|
84
|
-
useImperativeApi(
|
|
85
|
-
{
|
|
86
|
-
removeItems,
|
|
87
|
-
removeItem,
|
|
88
|
-
replaceItem,
|
|
89
|
-
replaceItemAtIndex,
|
|
90
|
-
selectItem,
|
|
91
|
-
selectAll,
|
|
92
|
-
deselectItem,
|
|
93
|
-
deselectAll,
|
|
94
|
-
isItemSelected,
|
|
95
|
-
},
|
|
96
|
-
[
|
|
97
|
-
removeItems,
|
|
98
|
-
removeItem,
|
|
99
|
-
replaceItem,
|
|
100
|
-
replaceItemAtIndex,
|
|
101
|
-
selectItem,
|
|
102
|
-
selectAll,
|
|
103
|
-
deselectItem,
|
|
104
|
-
deselectAll,
|
|
105
|
-
isItemSelected,
|
|
106
|
-
]
|
|
107
|
-
);
|
|
97
|
+
useNotifyProperty('sortOn', api.sortOn);
|
|
98
|
+
useNotifyProperty('descending', api.descending);
|
|
108
99
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-omnitable",
|
|
3
|
-
"version": "12.6.
|
|
3
|
+
"version": "12.6.3",
|
|
4
4
|
"description": "[](https://travis-ci.org/Neovici/cosmoz-omnitable)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"@web/dev-server": "^0.1.10",
|
|
98
98
|
"husky": "^8.0.0",
|
|
99
99
|
"semantic-release": "^19.0.0",
|
|
100
|
-
"sinon": "^
|
|
100
|
+
"sinon": "^15.0.0",
|
|
101
101
|
"web-animations-js": "^2.3.0"
|
|
102
102
|
}
|
|
103
103
|
}
|