htmx-router 2.2.4 → 2.2.6
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/event-source.d.ts +21 -0
- package/dist/event-source.js +57 -1
- package/dist/internal/mount.js +10 -12
- package/package.json +1 -1
package/dist/event-source.d.ts
CHANGED
|
@@ -51,6 +51,27 @@ export declare class EventSourceSet<JsxEnabled extends boolean = false> extends
|
|
|
51
51
|
*/
|
|
52
52
|
closeAll(): number;
|
|
53
53
|
}
|
|
54
|
+
export declare class EventSourceMap<T, JsxEnabled extends boolean = false> extends Map<EventSource<JsxEnabled>, T> {
|
|
55
|
+
private onAbort;
|
|
56
|
+
constructor();
|
|
57
|
+
set(stream: EventSource<JsxEnabled>, value: T): this;
|
|
58
|
+
delete(stream: EventSource<JsxEnabled>): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Send update to all EventSources, auto closing failed dispatches
|
|
61
|
+
* @returns number of successful sends
|
|
62
|
+
*/
|
|
63
|
+
dispatch(type: string, data: string): number;
|
|
64
|
+
/**
|
|
65
|
+
* Cull all closed connections
|
|
66
|
+
* @returns number of connections closed
|
|
67
|
+
*/
|
|
68
|
+
cull(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Close all connections
|
|
71
|
+
* @returns number of connections closed
|
|
72
|
+
*/
|
|
73
|
+
closeAll(): number;
|
|
74
|
+
}
|
|
54
75
|
type SharedEventSourceCacheRule = {
|
|
55
76
|
limit: number;
|
|
56
77
|
ttl: number;
|
package/dist/event-source.js
CHANGED
|
@@ -182,7 +182,7 @@ export class EventSourceSet extends Set {
|
|
|
182
182
|
if (success)
|
|
183
183
|
count++;
|
|
184
184
|
}
|
|
185
|
-
return count;
|
|
185
|
+
return count - this.size;
|
|
186
186
|
}
|
|
187
187
|
/**
|
|
188
188
|
* Close all connections
|
|
@@ -196,6 +196,62 @@ export class EventSourceSet extends Set {
|
|
|
196
196
|
return count;
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
|
+
export class EventSourceMap extends Map {
|
|
200
|
+
onAbort;
|
|
201
|
+
constructor() {
|
|
202
|
+
super();
|
|
203
|
+
this.onAbort = () => this.cull();
|
|
204
|
+
}
|
|
205
|
+
set(stream, value) {
|
|
206
|
+
stream._signal.addEventListener('abort', this.onAbort);
|
|
207
|
+
return super.set(stream, value);
|
|
208
|
+
}
|
|
209
|
+
delete(stream) {
|
|
210
|
+
stream._signal.removeEventListener('abort', this.onAbort);
|
|
211
|
+
return super.delete(stream);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Send update to all EventSources, auto closing failed dispatches
|
|
215
|
+
* @returns number of successful sends
|
|
216
|
+
*/
|
|
217
|
+
dispatch(type, data) {
|
|
218
|
+
let count = 0;
|
|
219
|
+
for (const stream of this.keys()) {
|
|
220
|
+
if (stream.readyState !== EventSource.OPEN)
|
|
221
|
+
continue; // skip closed
|
|
222
|
+
const success = stream.dispatch(type, data);
|
|
223
|
+
if (success)
|
|
224
|
+
count++;
|
|
225
|
+
else
|
|
226
|
+
this.delete(stream);
|
|
227
|
+
}
|
|
228
|
+
return count;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Cull all closed connections
|
|
232
|
+
* @returns number of connections closed
|
|
233
|
+
*/
|
|
234
|
+
cull() {
|
|
235
|
+
const count = this.size;
|
|
236
|
+
for (const stream of this.keys()) {
|
|
237
|
+
if (stream.readyState !== EventSource.CLOSED)
|
|
238
|
+
continue;
|
|
239
|
+
this.delete(stream);
|
|
240
|
+
}
|
|
241
|
+
return count - this.size;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Close all connections
|
|
245
|
+
* @returns number of connections closed
|
|
246
|
+
*/
|
|
247
|
+
closeAll() {
|
|
248
|
+
const count = this.size;
|
|
249
|
+
for (const stream of this.keys())
|
|
250
|
+
stream.close();
|
|
251
|
+
this.clear();
|
|
252
|
+
return count;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
199
255
|
/**
|
|
200
256
|
* DO NOT USE: Experimental
|
|
201
257
|
* @deprecated
|
package/dist/internal/mount.js
CHANGED
|
@@ -14,18 +14,19 @@ function ClientMounter() {
|
|
|
14
14
|
return current;
|
|
15
15
|
},
|
|
16
16
|
apply: () => document.documentElement.setAttribute('data-theme', theme.get()),
|
|
17
|
-
set: (
|
|
18
|
-
localStorage.setItem("theme",
|
|
17
|
+
set: (value, sync = true) => {
|
|
18
|
+
localStorage.setItem("theme", value);
|
|
19
19
|
theme.apply();
|
|
20
|
-
|
|
20
|
+
if (sync)
|
|
21
|
+
channel.postMessage({ type: 'set', theme: value });
|
|
21
22
|
return theme;
|
|
22
23
|
},
|
|
23
24
|
toggle: () => {
|
|
24
|
-
const
|
|
25
|
-
localStorage.setItem("theme",
|
|
25
|
+
const value = theme.get() === 'dark' ? 'light' : 'dark';
|
|
26
|
+
localStorage.setItem("theme", value);
|
|
26
27
|
theme.apply();
|
|
27
|
-
channel.postMessage({ type: 'set', theme:
|
|
28
|
-
return
|
|
28
|
+
channel.postMessage({ type: 'set', theme: value });
|
|
29
|
+
return value;
|
|
29
30
|
}
|
|
30
31
|
};
|
|
31
32
|
const channel = new BroadcastChannel('hx-theme');
|
|
@@ -34,12 +35,9 @@ function ClientMounter() {
|
|
|
34
35
|
return;
|
|
35
36
|
const next = event.data.theme;
|
|
36
37
|
if (next === 'light')
|
|
37
|
-
|
|
38
|
+
theme.set('light', false);
|
|
38
39
|
if (next === 'dark')
|
|
39
|
-
|
|
40
|
-
else
|
|
41
|
-
return; // no-op on unrecognised
|
|
42
|
-
theme.apply();
|
|
40
|
+
theme.set('dark', false);
|
|
43
41
|
});
|
|
44
42
|
/**
|
|
45
43
|
* based on https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0,
|