htmx-router 2.2.3 → 2.2.5

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.
@@ -13,18 +13,32 @@ function ClientMounter() {
13
13
  localStorage.setItem("theme", current);
14
14
  return current;
15
15
  },
16
- apply: () => {
17
- document.documentElement.setAttribute('data-theme', theme.get());
16
+ apply: () => document.documentElement.setAttribute('data-theme', theme.get()),
17
+ set: (value, sync = true) => {
18
+ localStorage.setItem("theme", value);
19
+ theme.apply();
20
+ if (sync)
21
+ channel.postMessage({ type: 'set', theme: value });
22
+ return theme;
18
23
  },
19
24
  toggle: () => {
20
- if (theme.get() === "dark")
21
- localStorage.setItem("theme", "light");
22
- else
23
- localStorage.setItem("theme", "dark");
25
+ const value = theme.get() === 'dark' ? 'light' : 'dark';
26
+ localStorage.setItem("theme", value);
24
27
  theme.apply();
25
- return localStorage.getItem("theme");
28
+ channel.postMessage({ type: 'set', theme: value });
29
+ return value;
26
30
  }
27
31
  };
32
+ const channel = new BroadcastChannel('hx-theme');
33
+ channel.addEventListener('message', (event) => {
34
+ if (event?.data?.type !== 'set')
35
+ return;
36
+ const next = event.data.theme;
37
+ if (next === 'light')
38
+ theme.set('light', false);
39
+ if (next === 'dark')
40
+ theme.set('dark', false);
41
+ });
28
42
  /**
29
43
  * based on https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0,
30
44
  * derived from Java's string hashcode implementation
@@ -143,13 +157,10 @@ export function GetMountUrl() {
143
157
  * RouteTree mounting point
144
158
  */
145
159
  export const path = "/_/mount/$hash";
146
- export const parameters = {
147
- hash: String
148
- };
160
+ export const parameters = { hash: String };
149
161
  export async function loader(ctx) {
150
162
  if (!ctx.params.hash)
151
163
  return null;
152
- // const build = GetSheet();
153
164
  if (!ctx.params.hash.startsWith(hash))
154
165
  return null;
155
166
  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>;
@@ -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
- return new RouteContext(this, this.params, shape, path);
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
@@ -36,6 +36,7 @@ export function revalidate(init) {
36
36
  const res = new Response("", init);
37
37
  res.headers.set("HX-Location", "");
38
38
  res.headers.set("HX-Replace-Url", "");
39
+ res.headers.set("HX-Push-Url", "false");
39
40
  res.headers.set("X-Caught", "true");
40
41
  return res;
41
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "htmx-router",
3
- "version": "2.2.3",
3
+ "version": "2.2.5",
4
4
  "description": "A lightweight SSR framework with server+client islands",
5
5
  "keywords": [ "htmx", "router", "client islands", "ssr", "vite" ],
6
6
  "type": "module",