htmx-router 2.2.3 → 2.2.4
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/internal/mount.js +24 -11
- package/dist/internal/router.d.ts +1 -0
- package/dist/internal/router.js +5 -1
- package/dist/response.js +1 -0
- package/package.json +1 -1
package/dist/internal/mount.js
CHANGED
|
@@ -13,18 +13,34 @@ function ClientMounter() {
|
|
|
13
13
|
localStorage.setItem("theme", current);
|
|
14
14
|
return current;
|
|
15
15
|
},
|
|
16
|
-
apply: () =>
|
|
17
|
-
|
|
16
|
+
apply: () => document.documentElement.setAttribute('data-theme', theme.get()),
|
|
17
|
+
set: (next) => {
|
|
18
|
+
localStorage.setItem("theme", next);
|
|
19
|
+
theme.apply();
|
|
20
|
+
channel.postMessage({ type: 'set', theme: next });
|
|
21
|
+
return theme;
|
|
18
22
|
},
|
|
19
23
|
toggle: () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
else
|
|
23
|
-
localStorage.setItem("theme", "dark");
|
|
24
|
+
const next = theme.get() === 'dark' ? 'light' : 'dark';
|
|
25
|
+
localStorage.setItem("theme", next);
|
|
24
26
|
theme.apply();
|
|
25
|
-
|
|
27
|
+
channel.postMessage({ type: 'set', theme: next });
|
|
28
|
+
return theme;
|
|
26
29
|
}
|
|
27
30
|
};
|
|
31
|
+
const channel = new BroadcastChannel('hx-theme');
|
|
32
|
+
channel.addEventListener('message', (event) => {
|
|
33
|
+
if (event?.data?.type !== 'set')
|
|
34
|
+
return;
|
|
35
|
+
const next = event.data.theme;
|
|
36
|
+
if (next === 'light')
|
|
37
|
+
localStorage.setItem("theme", 'light');
|
|
38
|
+
if (next === 'dark')
|
|
39
|
+
localStorage.setItem("theme", 'dark');
|
|
40
|
+
else
|
|
41
|
+
return; // no-op on unrecognised
|
|
42
|
+
theme.apply();
|
|
43
|
+
});
|
|
28
44
|
/**
|
|
29
45
|
* based on https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0,
|
|
30
46
|
* derived from Java's string hashcode implementation
|
|
@@ -143,13 +159,10 @@ export function GetMountUrl() {
|
|
|
143
159
|
* RouteTree mounting point
|
|
144
160
|
*/
|
|
145
161
|
export const path = "/_/mount/$hash";
|
|
146
|
-
export const parameters = {
|
|
147
|
-
hash: String
|
|
148
|
-
};
|
|
162
|
+
export const parameters = { hash: String };
|
|
149
163
|
export async function loader(ctx) {
|
|
150
164
|
if (!ctx.params.hash)
|
|
151
165
|
return null;
|
|
152
|
-
// const build = GetSheet();
|
|
153
166
|
if (!ctx.params.hash.startsWith(hash))
|
|
154
167
|
return null;
|
|
155
168
|
ctx.headers.set("Content-Type", "text/javascript");
|
|
@@ -14,6 +14,7 @@ export declare class GenericContext {
|
|
|
14
14
|
readonly timer: RequestTimer;
|
|
15
15
|
readonly url: URL;
|
|
16
16
|
readonly render: HtmxRouterServer["render"];
|
|
17
|
+
path: string;
|
|
17
18
|
constructor(request: GenericContext["request"], url: GenericContext["url"], scope: HtmxRouterServer);
|
|
18
19
|
finalize(res: Response): void;
|
|
19
20
|
shape<T extends ParameterShaper>(shape: T, path: string): RouteContext<T>;
|
package/dist/internal/router.js
CHANGED
|
@@ -12,6 +12,7 @@ export class GenericContext {
|
|
|
12
12
|
timer;
|
|
13
13
|
url;
|
|
14
14
|
render;
|
|
15
|
+
path;
|
|
15
16
|
constructor(request, url, scope) {
|
|
16
17
|
this.cookie = new Cookies(request.headers.get("cookie"));
|
|
17
18
|
this.headers = new Headers(scope.headers);
|
|
@@ -21,9 +22,12 @@ export class GenericContext {
|
|
|
21
22
|
this.timer = new RequestTimer(scope.timers);
|
|
22
23
|
this.scope = scope;
|
|
23
24
|
this.render = scope.render;
|
|
25
|
+
this.path = '$';
|
|
24
26
|
}
|
|
25
27
|
finalize(res) { this.timer.writeTo(res.headers); }
|
|
26
28
|
shape(shape, path) {
|
|
27
|
-
|
|
29
|
+
const ctx = new RouteContext(this, this.params, shape, path);
|
|
30
|
+
this.path = path;
|
|
31
|
+
return ctx;
|
|
28
32
|
}
|
|
29
33
|
}
|
package/dist/response.js
CHANGED