@neovici/cosmoz-omnitable 14.10.0 → 14.11.1
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/lib/render-header.js +1 -0
- package/lib/use-hash-state.js +53 -40
- package/lib/use-list.js +2 -1
- package/package.json +2 -2
package/lib/render-header.js
CHANGED
package/lib/use-hash-state.js
CHANGED
|
@@ -1,58 +1,71 @@
|
|
|
1
1
|
import { useCallback, useState } from '@pionjs/pion';
|
|
2
2
|
import { navigate } from '@neovici/cosmoz-router';
|
|
3
3
|
import { identity, invoke } from '@neovici/cosmoz-utils/function';
|
|
4
|
+
import {
|
|
5
|
+
hashUrl,
|
|
6
|
+
multiParse,
|
|
7
|
+
singleParse,
|
|
8
|
+
} from '@neovici/cosmoz-utils/location';
|
|
4
9
|
|
|
5
|
-
const
|
|
6
|
-
|
|
10
|
+
const makeLinker =
|
|
11
|
+
(parameterize) =>
|
|
12
|
+
(hashParam, value, codec = identity) => {
|
|
13
|
+
const url = hashUrl(),
|
|
14
|
+
searchParams = new URLSearchParams(url.hash.replace('#', ''));
|
|
7
15
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const params = Array.from(new URLSearchParams(hashUrl().hash.replace('#', '')).entries())
|
|
11
|
-
.filter(([param]) => param.startsWith(hashParam))
|
|
12
|
-
.map(([param, value]) => codec([param.replace(hashParam, ''), value]))
|
|
13
|
-
.filter(([, value]) => value != null);
|
|
16
|
+
// TODO: make parameterize pure
|
|
17
|
+
parameterize(hashParam, value, codec, searchParams);
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
parameterize(hashParam, value, codec, searchParams);
|
|
25
|
-
|
|
26
|
-
return '#!' + Object.assign(url, { hash: searchParams }).href.replace(location.origin, '');
|
|
27
|
-
},
|
|
28
|
-
isEmpty = v => v == null || v === '',
|
|
19
|
+
return (
|
|
20
|
+
'#!' +
|
|
21
|
+
Object.assign(url, { hash: searchParams }).href.replace(
|
|
22
|
+
location.origin,
|
|
23
|
+
'',
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
},
|
|
27
|
+
isEmpty = (v) => v == null || v === '',
|
|
29
28
|
singleLink = makeLinker((hashParam, value, codec, searchParams) =>
|
|
30
29
|
!isEmpty(codec(value))
|
|
31
30
|
? searchParams.set(hashParam, codec(value))
|
|
32
|
-
: searchParams.delete(hashParam)
|
|
31
|
+
: searchParams.delete(hashParam),
|
|
32
|
+
),
|
|
33
33
|
multiLink = makeLinker((hashParam, value, codec, searchParams) =>
|
|
34
34
|
Object.entries(value)
|
|
35
35
|
.map(codec)
|
|
36
|
-
.forEach(([key, value]) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
[link, parseHash] = multi ? [multiLink, multiParse] : [singleLink, singleParse],
|
|
43
|
-
[state, _setState] = useState(() => param == null
|
|
44
|
-
? initial
|
|
45
|
-
: parseHash(param + suffix, read) ?? initial),
|
|
36
|
+
.forEach(([key, value]) =>
|
|
37
|
+
!isEmpty(value)
|
|
38
|
+
? searchParams.set(hashParam + key, value)
|
|
39
|
+
: searchParams.delete(hashParam + key),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
export const useHashState = (
|
|
44
|
+
initial,
|
|
45
|
+
param,
|
|
46
|
+
{ suffix = '', read, write, multi } = {},
|
|
47
|
+
) => {
|
|
48
|
+
const [link, parseHash] = multi
|
|
49
|
+
? [multiLink, multiParse]
|
|
50
|
+
: [singleLink, singleParse],
|
|
51
|
+
[state, _setState] = useState(() =>
|
|
52
|
+
param == null ? initial : parseHash(param + suffix, read) ?? initial,
|
|
53
|
+
),
|
|
54
|
+
setState = useCallback(
|
|
55
|
+
(state) =>
|
|
56
|
+
_setState((oldState) => {
|
|
57
|
+
const newState = invoke(state, oldState);
|
|
49
58
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
if (param != null) {
|
|
60
|
+
navigate(link(param + suffix, newState, write), null, {
|
|
61
|
+
notify: false,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
return newState;
|
|
66
|
+
}),
|
|
67
|
+
[param, suffix, link, write],
|
|
68
|
+
);
|
|
56
69
|
|
|
57
70
|
return [state, setState];
|
|
58
71
|
};
|
package/lib/use-list.js
CHANGED
|
@@ -69,7 +69,7 @@ const renderItem =
|
|
|
69
69
|
class="itemRow"
|
|
70
70
|
@click=${onItemClick}
|
|
71
71
|
>
|
|
72
|
-
<div class="itemRow-wrapper">
|
|
72
|
+
<div class="itemRow-wrapper" part="itemRow-wrapper">
|
|
73
73
|
<input
|
|
74
74
|
class="checkbox"
|
|
75
75
|
type="checkbox"
|
|
@@ -80,6 +80,7 @@ const renderItem =
|
|
|
80
80
|
?disabled=${!dataIsValid}
|
|
81
81
|
/>
|
|
82
82
|
<cosmoz-omnitable-item-row
|
|
83
|
+
part="itemRow-inner"
|
|
83
84
|
.columns=${columns}
|
|
84
85
|
.index=${index}
|
|
85
86
|
.selected=${selected}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-omnitable",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.11.1",
|
|
4
4
|
"description": "[](https://travis-ci.org/Neovici/cosmoz-omnitable)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@neovici/cosmoz-i18next": "^3.1.1",
|
|
69
69
|
"@neovici/cosmoz-input": "^5.0.0",
|
|
70
70
|
"@neovici/cosmoz-router": "^11.0.0",
|
|
71
|
-
"@neovici/cosmoz-utils": "^6.
|
|
71
|
+
"@neovici/cosmoz-utils": "^6.14.2",
|
|
72
72
|
"@neovici/nullxlsx": "^3.0.0",
|
|
73
73
|
"@pionjs/pion": "^2.0.0",
|
|
74
74
|
"@polymer/iron-icon": "^3.0.0",
|