@oaiz/app-kit 0.1.4128 → 0.1.4156
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/README.md +6 -0
- package/package.json +1 -1
- package/src/hooks/use-url-state.ts +8 -3
package/README.md
CHANGED
|
@@ -137,6 +137,12 @@ The package holds no font files. The theme's `font-sans` is the device's system
|
|
|
137
137
|
accordion uses `font-inter`, which names the Inter typeface first; install and load Inter yourself
|
|
138
138
|
if you want it, otherwise the browser falls back to the system fonts.
|
|
139
139
|
|
|
140
|
+
## Source and provenance
|
|
141
|
+
|
|
142
|
+
The source is in the `app-kit/` folder of [oaiz-io/oaiz-sdk](https://github.com/oaiz-io/oaiz-sdk).
|
|
143
|
+
Each release is published from there by the repository's publish workflow, with npm provenance;
|
|
144
|
+
run `npm audit signatures` in a project that installs the package to verify its signatures.
|
|
145
|
+
|
|
140
146
|
## Licence
|
|
141
147
|
|
|
142
148
|
MIT. Some files are adapted from [shadcn/ui](https://ui.shadcn.com), also under MIT;
|
package/package.json
CHANGED
|
@@ -25,23 +25,28 @@ export type UrlStateOptions = {
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* One value in the page address, read and set like `useState`, so that a reload and Back keep it
|
|
28
|
-
* and a link shares it. The address leaves out a value equal to `initial`.
|
|
28
|
+
* and a link shares it. The address leaves out a value equal to `initial`. The setter's optional
|
|
29
|
+
* second argument updates related keys in the same navigation; `null` removes a key.
|
|
29
30
|
*/
|
|
30
31
|
export function useUrlState(
|
|
31
32
|
key: string,
|
|
32
33
|
initial = '',
|
|
33
34
|
options: UrlStateOptions = {},
|
|
34
|
-
): [string, (next: string) => void] {
|
|
35
|
+
): [string, (next: string, related?: Record<string, string | null>) => void] {
|
|
35
36
|
const history = options.history ?? 'replace';
|
|
36
37
|
const value = useSyncExternalStore(
|
|
37
38
|
subscribe,
|
|
38
39
|
() => new URLSearchParams(window.location.search).get(key) ?? initial,
|
|
39
40
|
);
|
|
40
41
|
const set = useCallback(
|
|
41
|
-
(next: string) => {
|
|
42
|
+
(next: string, related: Record<string, string | null> = {}) => {
|
|
42
43
|
// Values set while a push waits for its transition join that push, so one click that sets
|
|
43
44
|
// two values makes one history entry holding both.
|
|
44
45
|
const url = new URL((pending ?? window.location).href);
|
|
46
|
+
for (const [relatedKey, relatedValue] of Object.entries(related)) {
|
|
47
|
+
if (relatedValue === null) url.searchParams.delete(relatedKey);
|
|
48
|
+
else url.searchParams.set(relatedKey, relatedValue);
|
|
49
|
+
}
|
|
45
50
|
if (next === initial) url.searchParams.delete(key);
|
|
46
51
|
else url.searchParams.set(key, next);
|
|
47
52
|
if (pending) {
|