elements-kit 0.18.2 → 0.20.0
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 +14 -0
- package/dist/await.d.mts +53 -0
- package/dist/await.mjs +70 -0
- package/dist/custom-elements.d.mts +1 -1
- package/dist/{element-xQwq4ulc.mjs → element-D3om9yA6.mjs} +71 -4
- package/dist/for.d.mts +20 -26
- package/dist/for.mjs +29 -4
- package/dist/fragment-ROPRBJQd.mjs +61 -0
- package/dist/hydrate/index.d.mts +41 -0
- package/dist/hydrate/index.mjs +2 -0
- package/dist/hydrate-6Qx4n4Su.mjs +380 -0
- package/dist/integrations/astro-client.d.mts +17 -0
- package/dist/integrations/astro-client.mjs +23 -0
- package/dist/integrations/astro-server.d.mts +15 -0
- package/dist/integrations/astro-server.mjs +39 -0
- package/dist/integrations/astro-slots.d.mts +12 -0
- package/dist/integrations/astro-slots.mjs +30 -0
- package/dist/integrations/astro.d.mts +46 -0
- package/dist/integrations/astro.mjs +64 -0
- package/dist/integrations/react.d.mts +1 -1
- package/dist/integrations/react.mjs +2 -2
- package/dist/jsx-runtime/index.d.mts +1 -1
- package/dist/jsx-runtime/index.mjs +2 -20
- package/dist/{lib-Dkc7cV5F.mjs → lib-DYypKhxk.mjs} +63 -5
- package/dist/render.mjs +1 -1
- package/dist/{scope-CnEvL9Nd.mjs → scope-zbEG299F.mjs} +1 -1
- package/dist/server/index.d.mts +43 -0
- package/dist/server/index.mjs +2 -0
- package/dist/server-iFSng50i.mjs +385 -0
- package/dist/signals/index.d.mts +2 -2
- package/dist/signals/index.mjs +5 -3
- package/dist/{slot-B8y0aEoz.d.mts → slot-BFWXeFRl.d.mts} +6 -0
- package/dist/{slot-Cne__au7.mjs → slot-Dvf30O0B.mjs} +12 -1
- package/dist/slot.d.mts +1 -1
- package/dist/slot.mjs +1 -1
- package/dist/{infer-B7T5hi_D.d.mts → types-ncUK9rki.d.mts} +140 -141
- package/dist/ui/overlay/index.css +70 -0
- package/dist/ui/overlay/index.d.mts +209 -0
- package/dist/ui/overlay/index.mjs +1001 -0
- package/dist/ui/overlay/overlay.css +332 -0
- package/dist/utilities/_observe.mjs +1 -1
- package/dist/utilities/active-element.d.mts +1 -1
- package/dist/utilities/active-element.mjs +1 -1
- package/dist/utilities/async.d.mts +19 -2
- package/dist/utilities/async.mjs +49 -2
- package/dist/utilities/context.mjs +1 -1
- package/dist/utilities/debounced.d.mts +1 -1
- package/dist/utilities/debounced.mjs +1 -1
- package/dist/utilities/dom-lifecycle.bench.mjs +3255 -1
- package/dist/utilities/dom-lifecycle.mjs +1 -1
- package/dist/utilities/element-rect.d.mts +1 -1
- package/dist/utilities/element-rect.mjs +1 -1
- package/dist/utilities/element-scroll.d.mts +1 -1
- package/dist/utilities/event-driven.d.mts +1 -1
- package/dist/utilities/event-driven.mjs +1 -1
- package/dist/utilities/event-listener.d.mts +1 -1
- package/dist/utilities/event-listener.mjs +1 -1
- package/dist/utilities/focus-within.d.mts +1 -1
- package/dist/utilities/focus-within.mjs +1 -1
- package/dist/utilities/form-object.d.mts +96 -0
- package/dist/utilities/form-object.mjs +285 -0
- package/dist/utilities/hover.d.mts +1 -1
- package/dist/utilities/hover.mjs +1 -1
- package/dist/utilities/interval.d.mts +1 -1
- package/dist/utilities/interval.mjs +1 -1
- package/dist/utilities/location.d.mts +1 -1
- package/dist/utilities/location.mjs +1 -1
- package/dist/utilities/media-devices.d.mts +1 -1
- package/dist/utilities/media-devices.mjs +1 -1
- package/dist/utilities/media-player.d.mts +1 -1
- package/dist/utilities/media-query.d.mts +1 -1
- package/dist/utilities/media-query.mjs +1 -1
- package/dist/utilities/network.d.mts +1 -1
- package/dist/utilities/network.mjs +1 -1
- package/dist/utilities/orientation.d.mts +1 -1
- package/dist/utilities/orientation.mjs +1 -1
- package/dist/utilities/previous.d.mts +1 -1
- package/dist/utilities/previous.mjs +1 -1
- package/dist/utilities/promise.d.mts +19 -2
- package/dist/utilities/promise.mjs +33 -3
- package/dist/utilities/retry.mjs +1 -1
- package/dist/utilities/routing.d.mts +1 -1
- package/dist/utilities/routing.mjs +1 -1
- package/dist/utilities/search-params.d.mts +1 -1
- package/dist/utilities/storage.d.mts +1 -1
- package/dist/utilities/throttled.d.mts +1 -1
- package/dist/utilities/throttled.mjs +1 -1
- package/dist/utilities/timeout.d.mts +1 -1
- package/dist/utilities/timeout.mjs +1 -1
- package/dist/utilities/window-focus.d.mts +1 -1
- package/dist/utilities/window-focus.mjs +1 -1
- package/dist/utilities/window-size.d.mts +1 -1
- package/dist/utilities/window-size.mjs +1 -1
- package/package.json +20 -5
- package/dist/benchmark.CX_oY03V-CSLAXL5f.mjs +0 -5145
- package/dist/magic-string.es-CXefOmkB.mjs +0 -1011
- package/dist/test.BmQO5GaM-Ddz9cDxc.mjs +0 -8266
- package/dist/utilities/active-element.test.d.mts +0 -1
- package/dist/utilities/active-element.test.mjs +0 -25
- package/dist/utilities/async.test.d.mts +0 -1
- package/dist/utilities/async.test.mjs +0 -275
- package/dist/utilities/context.test.d.mts +0 -1
- package/dist/utilities/context.test.mjs +0 -171
- package/dist/utilities/debounced.test.d.mts +0 -1
- package/dist/utilities/debounced.test.mjs +0 -68
- package/dist/utilities/dom-lifecycle.test.d.mts +0 -1
- package/dist/utilities/dom-lifecycle.test.mjs +0 -228
- package/dist/utilities/element-rect.test.d.mts +0 -1
- package/dist/utilities/element-rect.test.mjs +0 -101
- package/dist/utilities/element-scroll.test.d.mts +0 -1
- package/dist/utilities/element-scroll.test.mjs +0 -27
- package/dist/utilities/event-listener.test.d.mts +0 -1
- package/dist/utilities/event-listener.test.mjs +0 -60
- package/dist/utilities/focus-within.test.d.mts +0 -1
- package/dist/utilities/focus-within.test.mjs +0 -51
- package/dist/utilities/hover.test.d.mts +0 -1
- package/dist/utilities/hover.test.mjs +0 -54
- package/dist/utilities/intersection-observer.test.d.mts +0 -1
- package/dist/utilities/intersection-observer.test.mjs +0 -46
- package/dist/utilities/interval.test.d.mts +0 -1
- package/dist/utilities/interval.test.mjs +0 -115
- package/dist/utilities/location.test.d.mts +0 -1
- package/dist/utilities/location.test.mjs +0 -61
- package/dist/utilities/long-press.test.d.mts +0 -1
- package/dist/utilities/long-press.test.mjs +0 -54
- package/dist/utilities/media-devices.test.d.mts +0 -1
- package/dist/utilities/media-devices.test.mjs +0 -44
- package/dist/utilities/media-player.test.d.mts +0 -1
- package/dist/utilities/media-player.test.mjs +0 -102
- package/dist/utilities/mutation-observer.test.d.mts +0 -1
- package/dist/utilities/mutation-observer.test.mjs +0 -48
- package/dist/utilities/network.test.d.mts +0 -1
- package/dist/utilities/network.test.mjs +0 -30
- package/dist/utilities/on-click-outside.test.d.mts +0 -1
- package/dist/utilities/on-click-outside.test.mjs +0 -45
- package/dist/utilities/previous.test.d.mts +0 -1
- package/dist/utilities/previous.test.mjs +0 -90
- package/dist/utilities/promise.test.d.mts +0 -1
- package/dist/utilities/promise.test.mjs +0 -158
- package/dist/utilities/retry.test.d.mts +0 -1
- package/dist/utilities/retry.test.mjs +0 -85
- package/dist/utilities/routing.test.d.mts +0 -1
- package/dist/utilities/routing.test.mjs +0 -129
- package/dist/utilities/search-params.test.d.mts +0 -1
- package/dist/utilities/search-params.test.mjs +0 -37
- package/dist/utilities/ssr.test.d.mts +0 -1
- package/dist/utilities/ssr.test.mjs +0 -65
- package/dist/utilities/storage.test.d.mts +0 -1
- package/dist/utilities/storage.test.mjs +0 -139
- package/dist/utilities/throttled.test.d.mts +0 -1
- package/dist/utilities/throttled.test.mjs +0 -58
- package/dist/utilities/timeout.test.d.mts +0 -1
- package/dist/utilities/timeout.test.mjs +0 -121
- package/dist/utilities/window-size.test.d.mts +0 -1
- package/dist/utilities/window-size.test.mjs +0 -43
- /package/dist/{custom-elements-D5CgfNKc.d.mts → custom-elements-DK5VUcWA.d.mts} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { f as it, l as describe } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
|
|
2
|
-
import { t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
|
|
3
|
-
import { activeElement } from "./active-element.mjs";
|
|
4
|
-
//#region src/utilities/active-element.test.ts
|
|
5
|
-
describe("activeElement (singleton)", () => {
|
|
6
|
-
it("returns a computed that reads the current activeElement", () => {
|
|
7
|
-
globalExpect(activeElement()).toBe(document.activeElement);
|
|
8
|
-
});
|
|
9
|
-
it("updates when focus changes", () => {
|
|
10
|
-
const input = document.createElement("input");
|
|
11
|
-
document.body.appendChild(input);
|
|
12
|
-
input.focus();
|
|
13
|
-
globalExpect(activeElement()).toBe(input);
|
|
14
|
-
document.body.removeChild(input);
|
|
15
|
-
});
|
|
16
|
-
it("remains reactive after scope disposal", () => {
|
|
17
|
-
const input = document.createElement("input");
|
|
18
|
-
document.body.appendChild(input);
|
|
19
|
-
input.focus();
|
|
20
|
-
globalExpect(activeElement()).toBe(input);
|
|
21
|
-
document.body.removeChild(input);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
//#endregion
|
|
25
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import { m as signal, p as onCleanup, s as effect } from "../lib-Dkc7cV5F.mjs";
|
|
2
|
-
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
|
|
5
|
-
import { Async, async } from "./async.mjs";
|
|
6
|
-
import { createInterval } from "./interval.mjs";
|
|
7
|
-
//#region src/utilities/async.test.ts
|
|
8
|
-
function deferred() {
|
|
9
|
-
let resolve;
|
|
10
|
-
let reject;
|
|
11
|
-
return {
|
|
12
|
-
promise: new Promise((res, rej) => {
|
|
13
|
-
resolve = res;
|
|
14
|
-
reject = rej;
|
|
15
|
-
}),
|
|
16
|
-
resolve,
|
|
17
|
-
reject
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
describe("Async", () => {
|
|
21
|
-
it("is reactive as a computed signal (effect)", async () => {
|
|
22
|
-
const op = async((x) => Promise.resolve(x * 2));
|
|
23
|
-
const values = [];
|
|
24
|
-
const stop = effect(() => {
|
|
25
|
-
values.push(op());
|
|
26
|
-
});
|
|
27
|
-
op.run(2);
|
|
28
|
-
await op;
|
|
29
|
-
op.run(3);
|
|
30
|
-
await op;
|
|
31
|
-
stop();
|
|
32
|
-
globalExpect(values).toContain(void 0);
|
|
33
|
-
globalExpect(values).toContain(4);
|
|
34
|
-
globalExpect(values).toContain(6);
|
|
35
|
-
globalExpect(values.at(-1)).toBe(6);
|
|
36
|
-
});
|
|
37
|
-
it("is callable as a signal and returns the current result", async () => {
|
|
38
|
-
const op = async(() => Promise.resolve(123));
|
|
39
|
-
globalExpect(op()).toBeUndefined();
|
|
40
|
-
op.start();
|
|
41
|
-
await op;
|
|
42
|
-
globalExpect(op()).toBe(123);
|
|
43
|
-
const err = /* @__PURE__ */ new Error("fail");
|
|
44
|
-
const op2 = async(() => Promise.reject(err));
|
|
45
|
-
op2.start();
|
|
46
|
-
await op2.catch(() => {});
|
|
47
|
-
globalExpect(op2()).toBe(err);
|
|
48
|
-
});
|
|
49
|
-
it("starts in pending state with no value or reason", () => {
|
|
50
|
-
const op = async(() => Promise.resolve(1));
|
|
51
|
-
globalExpect(op.state).toBe("pending");
|
|
52
|
-
globalExpect(op.pending).toBe(true);
|
|
53
|
-
globalExpect(op.value).toBeUndefined();
|
|
54
|
-
globalExpect(op.reason).toBeUndefined();
|
|
55
|
-
globalExpect(op.result).toBeUndefined();
|
|
56
|
-
globalExpect(op.pending).toBe(op.state === "pending");
|
|
57
|
-
});
|
|
58
|
-
it("transitions to fulfilled after start()", async () => {
|
|
59
|
-
const op = async(() => Promise.resolve(42));
|
|
60
|
-
op.start();
|
|
61
|
-
await op;
|
|
62
|
-
globalExpect(op.state).toBe("fulfilled");
|
|
63
|
-
globalExpect(op.pending).toBe(false);
|
|
64
|
-
globalExpect(op.value).toBe(42);
|
|
65
|
-
globalExpect(op.reason).toBeUndefined();
|
|
66
|
-
globalExpect(op.result).toBe(42);
|
|
67
|
-
globalExpect(op.result).toBe(42);
|
|
68
|
-
});
|
|
69
|
-
it("transitions to rejected after start()", async () => {
|
|
70
|
-
const err = /* @__PURE__ */ new Error("fail");
|
|
71
|
-
const op = async(() => Promise.reject(err));
|
|
72
|
-
op.start();
|
|
73
|
-
await op.catch(() => {});
|
|
74
|
-
globalExpect(op.state).toBe("rejected");
|
|
75
|
-
globalExpect(op.pending).toBe(false);
|
|
76
|
-
globalExpect(op.reason).toBe(err);
|
|
77
|
-
globalExpect(op.value).toBeUndefined();
|
|
78
|
-
globalExpect(op.result).toBe(err);
|
|
79
|
-
globalExpect(op.reason).toBe(err);
|
|
80
|
-
});
|
|
81
|
-
it("await op.run(args) resolves to the fulfilled value", async () => {
|
|
82
|
-
const op = async((x) => Promise.resolve(x + 100));
|
|
83
|
-
globalExpect(await op.run(23)).toBe(123);
|
|
84
|
-
globalExpect(op.value).toBe(123);
|
|
85
|
-
globalExpect(op.state).toBe("fulfilled");
|
|
86
|
-
});
|
|
87
|
-
it("run() resolves to the fulfilled value", async () => {
|
|
88
|
-
globalExpect(await async((x) => Promise.resolve(x * 2)).run(5)).toBe(10);
|
|
89
|
-
});
|
|
90
|
-
it("await op resolves to the fulfilled value", async () => {
|
|
91
|
-
const op = async(() => Promise.resolve(7));
|
|
92
|
-
op.start();
|
|
93
|
-
globalExpect(await op).toBe(7);
|
|
94
|
-
});
|
|
95
|
-
it("await op.catch() resolves on rejection", async () => {
|
|
96
|
-
const err = /* @__PURE__ */ new Error("fail");
|
|
97
|
-
const op = async(() => Promise.reject(err));
|
|
98
|
-
op.start();
|
|
99
|
-
globalExpect(await op.catch((e) => e)).toBe(err);
|
|
100
|
-
});
|
|
101
|
-
it("delegates .then()", async () => {
|
|
102
|
-
const op = async(() => Promise.resolve(3));
|
|
103
|
-
op.start();
|
|
104
|
-
globalExpect(await op.then((v) => (v ?? 0) * 2)).toBe(6);
|
|
105
|
-
});
|
|
106
|
-
it("instanceof Async", () => {
|
|
107
|
-
globalExpect(async(() => Promise.resolve()) instanceof Async).toBe(true);
|
|
108
|
-
});
|
|
109
|
-
it("is reactive — effect reruns when state transitions to fulfilled", async () => {
|
|
110
|
-
const op = async(() => Promise.resolve(10));
|
|
111
|
-
const snapshots = [];
|
|
112
|
-
const stop = effect(() => {
|
|
113
|
-
snapshots.push(op.state);
|
|
114
|
-
});
|
|
115
|
-
op.start();
|
|
116
|
-
await op;
|
|
117
|
-
stop();
|
|
118
|
-
globalExpect(snapshots).toContain("pending");
|
|
119
|
-
globalExpect(snapshots.at(-1)).toBe("fulfilled");
|
|
120
|
-
});
|
|
121
|
-
it("is reactive — effect sees value after fulfillment", async () => {
|
|
122
|
-
const op = async(() => Promise.resolve(99));
|
|
123
|
-
const values = [];
|
|
124
|
-
const stop = effect(() => {
|
|
125
|
-
values.push(op.value);
|
|
126
|
-
});
|
|
127
|
-
op.start();
|
|
128
|
-
await op;
|
|
129
|
-
stop();
|
|
130
|
-
globalExpect(values).toEqual([
|
|
131
|
-
void 0,
|
|
132
|
-
void 0,
|
|
133
|
-
99
|
|
134
|
-
]);
|
|
135
|
-
});
|
|
136
|
-
it("is reactive — effect reruns on rejection", async () => {
|
|
137
|
-
const err = /* @__PURE__ */ new Error("x");
|
|
138
|
-
const op = async(() => Promise.reject(err));
|
|
139
|
-
const reasons = [];
|
|
140
|
-
const stop = effect(() => {
|
|
141
|
-
reasons.push(op.reason);
|
|
142
|
-
});
|
|
143
|
-
op.start();
|
|
144
|
-
await op.catch(() => {});
|
|
145
|
-
stop();
|
|
146
|
-
globalExpect(reasons).toEqual([
|
|
147
|
-
void 0,
|
|
148
|
-
void 0,
|
|
149
|
-
err
|
|
150
|
-
]);
|
|
151
|
-
});
|
|
152
|
-
it("start() re-runs when a signal read inside fn changes", async () => {
|
|
153
|
-
const id = signal(1);
|
|
154
|
-
const calls = [];
|
|
155
|
-
const op = async(() => {
|
|
156
|
-
const current = id();
|
|
157
|
-
calls.push(current);
|
|
158
|
-
return Promise.resolve(current);
|
|
159
|
-
});
|
|
160
|
-
op.start();
|
|
161
|
-
await op;
|
|
162
|
-
id(2);
|
|
163
|
-
await op;
|
|
164
|
-
op.stop();
|
|
165
|
-
globalExpect(calls).toEqual([1, 2]);
|
|
166
|
-
});
|
|
167
|
-
it("run() is not reactive — signal change does not re-run", async () => {
|
|
168
|
-
const id = signal(1);
|
|
169
|
-
const calls = [];
|
|
170
|
-
const op = async(() => {
|
|
171
|
-
const current = id();
|
|
172
|
-
calls.push(current);
|
|
173
|
-
return Promise.resolve(current);
|
|
174
|
-
});
|
|
175
|
-
op.run();
|
|
176
|
-
await op;
|
|
177
|
-
id(2);
|
|
178
|
-
await Promise.resolve();
|
|
179
|
-
op.stop();
|
|
180
|
-
globalExpect(calls).toEqual([1]);
|
|
181
|
-
});
|
|
182
|
-
it("start() resets to pending on re-run", async () => {
|
|
183
|
-
const d = deferred();
|
|
184
|
-
const id = signal(1);
|
|
185
|
-
const op = async(() => {
|
|
186
|
-
id();
|
|
187
|
-
return d.promise;
|
|
188
|
-
});
|
|
189
|
-
op.start();
|
|
190
|
-
globalExpect(op.pending).toBe(true);
|
|
191
|
-
id(2);
|
|
192
|
-
globalExpect(op.pending).toBe(true);
|
|
193
|
-
d.resolve(5);
|
|
194
|
-
op.stop();
|
|
195
|
-
});
|
|
196
|
-
it("stop() prevents further reactive reruns", async () => {
|
|
197
|
-
const id = signal(1);
|
|
198
|
-
const calls = [];
|
|
199
|
-
const op = async(() => {
|
|
200
|
-
calls.push(id());
|
|
201
|
-
return Promise.resolve(id());
|
|
202
|
-
});
|
|
203
|
-
op.start();
|
|
204
|
-
await op;
|
|
205
|
-
op.stop();
|
|
206
|
-
id(2);
|
|
207
|
-
await Promise.resolve();
|
|
208
|
-
globalExpect(calls).toEqual([1]);
|
|
209
|
-
});
|
|
210
|
-
it("onCleanup inside run() fires when stop() is called", () => {
|
|
211
|
-
const cleaned = [];
|
|
212
|
-
const op = async(() => {
|
|
213
|
-
onCleanup(() => cleaned.push(1));
|
|
214
|
-
return Promise.resolve();
|
|
215
|
-
});
|
|
216
|
-
op.run();
|
|
217
|
-
globalExpect(cleaned).toEqual([]);
|
|
218
|
-
op.stop();
|
|
219
|
-
globalExpect(cleaned).toEqual([1]);
|
|
220
|
-
});
|
|
221
|
-
it("onCleanup inside start() fires on each re-run", async () => {
|
|
222
|
-
const id = signal(1);
|
|
223
|
-
const cleaned = [];
|
|
224
|
-
const op = async(() => {
|
|
225
|
-
const current = id();
|
|
226
|
-
onCleanup(() => cleaned.push(current));
|
|
227
|
-
return Promise.resolve();
|
|
228
|
-
});
|
|
229
|
-
op.start();
|
|
230
|
-
await op;
|
|
231
|
-
id(2);
|
|
232
|
-
await op;
|
|
233
|
-
op.stop();
|
|
234
|
-
globalExpect(cleaned[0]).toBe(1);
|
|
235
|
-
});
|
|
236
|
-
it("re-runs when createInterval ticks", async () => {
|
|
237
|
-
vi.useFakeTimers();
|
|
238
|
-
const timer = createInterval(1e3);
|
|
239
|
-
const calls = [];
|
|
240
|
-
const op = async(() => {
|
|
241
|
-
timer.timestamp();
|
|
242
|
-
calls.push(calls.length);
|
|
243
|
-
return Promise.resolve(calls.length);
|
|
244
|
-
});
|
|
245
|
-
op.start();
|
|
246
|
-
await op;
|
|
247
|
-
globalExpect(calls.length).toBe(1);
|
|
248
|
-
vi.advanceTimersByTime(1e3);
|
|
249
|
-
await op;
|
|
250
|
-
globalExpect(calls.length).toBe(2);
|
|
251
|
-
op.stop();
|
|
252
|
-
timer.stop();
|
|
253
|
-
vi.useRealTimers();
|
|
254
|
-
});
|
|
255
|
-
it("state and value update atomically — no inconsistent intermediate state", async () => {
|
|
256
|
-
const op = async(() => Promise.resolve(7));
|
|
257
|
-
const snapshots = [];
|
|
258
|
-
const stop = effect(() => {
|
|
259
|
-
snapshots.push({
|
|
260
|
-
state: op.state,
|
|
261
|
-
value: op.value
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
op.start();
|
|
265
|
-
await op;
|
|
266
|
-
stop();
|
|
267
|
-
globalExpect(snapshots.find((s) => s.state === "fulfilled" && s.value === void 0)).toBeUndefined();
|
|
268
|
-
globalExpect(snapshots.at(-1)).toEqual({
|
|
269
|
-
state: "fulfilled",
|
|
270
|
-
value: 7
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
//#endregion
|
|
275
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { c as effectScope, m as signal, s as effect } from "../lib-Dkc7cV5F.mjs";
|
|
2
|
-
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
|
|
5
|
-
import { getContext, setContext } from "./context.mjs";
|
|
6
|
-
//#region src/utilities/context.test.ts
|
|
7
|
-
afterEach(() => {
|
|
8
|
-
document.body.innerHTML = "";
|
|
9
|
-
});
|
|
10
|
-
describe("context", () => {
|
|
11
|
-
it("returns undefined when no provider exists above the consumer", () => {
|
|
12
|
-
const el = document.createElement("div");
|
|
13
|
-
document.body.appendChild(el);
|
|
14
|
-
globalExpect(getContext(el, "missing")).toBeUndefined();
|
|
15
|
-
});
|
|
16
|
-
it("resolves a value across one parent boundary", () => {
|
|
17
|
-
const host = document.createElement("section");
|
|
18
|
-
const child = document.createElement("span");
|
|
19
|
-
host.appendChild(child);
|
|
20
|
-
document.body.appendChild(host);
|
|
21
|
-
effectScope(() => {
|
|
22
|
-
setContext(host, "k", 42);
|
|
23
|
-
});
|
|
24
|
-
globalExpect(getContext(child, "k")).toBe(42);
|
|
25
|
-
});
|
|
26
|
-
it("propagates updates when the value is a Signal", () => {
|
|
27
|
-
const host = document.createElement("section");
|
|
28
|
-
const child = document.createElement("span");
|
|
29
|
-
host.appendChild(child);
|
|
30
|
-
document.body.appendChild(host);
|
|
31
|
-
const value = signal(1);
|
|
32
|
-
const seen = vi.fn();
|
|
33
|
-
effectScope(() => {
|
|
34
|
-
setContext(host, "n", value);
|
|
35
|
-
});
|
|
36
|
-
effect(() => {
|
|
37
|
-
seen(getContext(child, "n")?.());
|
|
38
|
-
});
|
|
39
|
-
globalExpect(seen).toHaveBeenLastCalledWith(1);
|
|
40
|
-
value(2);
|
|
41
|
-
globalExpect(seen).toHaveBeenLastCalledWith(2);
|
|
42
|
-
});
|
|
43
|
-
it("innermost provider wins when nested with the same key", () => {
|
|
44
|
-
const outer = document.createElement("section");
|
|
45
|
-
const inner = document.createElement("section");
|
|
46
|
-
const leaf = document.createElement("span");
|
|
47
|
-
outer.appendChild(inner);
|
|
48
|
-
inner.appendChild(leaf);
|
|
49
|
-
document.body.appendChild(outer);
|
|
50
|
-
effectScope(() => {
|
|
51
|
-
setContext(outer, "k", "outer");
|
|
52
|
-
setContext(inner, "k", "inner");
|
|
53
|
-
});
|
|
54
|
-
globalExpect(getContext(leaf, "k")).toBe("inner");
|
|
55
|
-
});
|
|
56
|
-
it("disposing the provider's scope removes the entry and falls through", () => {
|
|
57
|
-
const outer = document.createElement("section");
|
|
58
|
-
const inner = document.createElement("section");
|
|
59
|
-
const leaf = document.createElement("span");
|
|
60
|
-
outer.appendChild(inner);
|
|
61
|
-
inner.appendChild(leaf);
|
|
62
|
-
document.body.appendChild(outer);
|
|
63
|
-
const stopOuter = effectScope(() => {
|
|
64
|
-
setContext(outer, "k", "outer");
|
|
65
|
-
});
|
|
66
|
-
const stopInner = effectScope(() => {
|
|
67
|
-
setContext(inner, "k", "inner");
|
|
68
|
-
});
|
|
69
|
-
globalExpect(getContext(leaf, "k")).toBe("inner");
|
|
70
|
-
stopInner();
|
|
71
|
-
globalExpect(getContext(leaf, "k")).toBe("outer");
|
|
72
|
-
stopOuter();
|
|
73
|
-
globalExpect(getContext(leaf, "k")).toBeUndefined();
|
|
74
|
-
});
|
|
75
|
-
it("distinct keys do not cross-talk", () => {
|
|
76
|
-
const host = document.createElement("section");
|
|
77
|
-
const child = document.createElement("span");
|
|
78
|
-
host.appendChild(child);
|
|
79
|
-
document.body.appendChild(host);
|
|
80
|
-
const A = Symbol("a");
|
|
81
|
-
const B = Symbol("b");
|
|
82
|
-
effectScope(() => {
|
|
83
|
-
setContext(host, A, "value-a");
|
|
84
|
-
setContext(host, B, "value-b");
|
|
85
|
-
});
|
|
86
|
-
globalExpect(getContext(child, A)).toBe("value-a");
|
|
87
|
-
globalExpect(getContext(child, B)).toBe("value-b");
|
|
88
|
-
globalExpect(getContext(child, "c")).toBeUndefined();
|
|
89
|
-
});
|
|
90
|
-
it("crosses an open shadow root via getRootNode().host", () => {
|
|
91
|
-
const host = document.createElement("section");
|
|
92
|
-
const shadow = host.attachShadow({ mode: "open" });
|
|
93
|
-
const inner = document.createElement("span");
|
|
94
|
-
shadow.appendChild(inner);
|
|
95
|
-
document.body.appendChild(host);
|
|
96
|
-
effectScope(() => {
|
|
97
|
-
setContext(host, "k", "from-host");
|
|
98
|
-
});
|
|
99
|
-
globalExpect(getContext(inner, "k")).toBe("from-host");
|
|
100
|
-
});
|
|
101
|
-
it("moving the consumer picks up the new ancestor on next get", () => {
|
|
102
|
-
const a = document.createElement("section");
|
|
103
|
-
const b = document.createElement("section");
|
|
104
|
-
const leaf = document.createElement("span");
|
|
105
|
-
a.appendChild(leaf);
|
|
106
|
-
document.body.append(a, b);
|
|
107
|
-
effectScope(() => {
|
|
108
|
-
setContext(a, "k", "a");
|
|
109
|
-
setContext(b, "k", "b");
|
|
110
|
-
});
|
|
111
|
-
globalExpect(getContext(leaf, "k")).toBe("a");
|
|
112
|
-
b.appendChild(leaf);
|
|
113
|
-
globalExpect(getContext(leaf, "k")).toBe("b");
|
|
114
|
-
});
|
|
115
|
-
it("returns undefined for an orphan element not in any tree", () => {
|
|
116
|
-
globalExpect(getContext(document.createElement("div"), "k")).toBeUndefined();
|
|
117
|
-
});
|
|
118
|
-
it("two providers with different keys in the same subtree both resolve", () => {
|
|
119
|
-
const host = document.createElement("section");
|
|
120
|
-
const leaf = document.createElement("span");
|
|
121
|
-
host.appendChild(leaf);
|
|
122
|
-
document.body.appendChild(host);
|
|
123
|
-
effectScope(() => {
|
|
124
|
-
setContext(host, "x", 1);
|
|
125
|
-
setContext(host, "y", 2);
|
|
126
|
-
});
|
|
127
|
-
globalExpect(getContext(leaf, "x")).toBe(1);
|
|
128
|
-
globalExpect(getContext(leaf, "y")).toBe(2);
|
|
129
|
-
});
|
|
130
|
-
describe("with <dom-lifecycle> as wrapper", () => {
|
|
131
|
-
it("descendants resolve a context set on the lifecycle wrapper itself", () => {
|
|
132
|
-
const wrapper = document.createElement("dom-lifecycle");
|
|
133
|
-
const consumer = document.createElement("button");
|
|
134
|
-
wrapper.appendChild(consumer);
|
|
135
|
-
document.body.appendChild(wrapper);
|
|
136
|
-
effectScope(() => {
|
|
137
|
-
setContext(wrapper, "theme", "dark");
|
|
138
|
-
});
|
|
139
|
-
globalExpect(getContext(consumer, "theme")).toBe("dark");
|
|
140
|
-
});
|
|
141
|
-
it("the wrapper is transparent in the ancestor walk — outer providers still resolve", () => {
|
|
142
|
-
const provider = document.createElement("section");
|
|
143
|
-
document.body.appendChild(provider);
|
|
144
|
-
effectScope(() => {
|
|
145
|
-
setContext(provider, "theme", "outer");
|
|
146
|
-
});
|
|
147
|
-
const wrapper = document.createElement("dom-lifecycle");
|
|
148
|
-
const consumer = document.createElement("button");
|
|
149
|
-
wrapper.appendChild(consumer);
|
|
150
|
-
provider.appendChild(wrapper);
|
|
151
|
-
globalExpect(getContext(consumer, "theme")).toBe("outer");
|
|
152
|
-
});
|
|
153
|
-
it("the wrapper shadows an outer provider when both register the same key", () => {
|
|
154
|
-
const provider = document.createElement("section");
|
|
155
|
-
document.body.appendChild(provider);
|
|
156
|
-
effectScope(() => {
|
|
157
|
-
setContext(provider, "theme", "outer");
|
|
158
|
-
});
|
|
159
|
-
const wrapper = document.createElement("dom-lifecycle");
|
|
160
|
-
const consumer = document.createElement("button");
|
|
161
|
-
wrapper.appendChild(consumer);
|
|
162
|
-
provider.appendChild(wrapper);
|
|
163
|
-
effectScope(() => {
|
|
164
|
-
setContext(wrapper, "theme", "inner");
|
|
165
|
-
});
|
|
166
|
-
globalExpect(getContext(consumer, "theme")).toBe("inner");
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
//#endregion
|
|
171
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { c as effectScope, m as signal } from "../lib-Dkc7cV5F.mjs";
|
|
2
|
-
import "../signals/index.mjs";
|
|
3
|
-
import { c as beforeEach, f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
|
|
5
|
-
import { createDebounced } from "./debounced.mjs";
|
|
6
|
-
//#region src/utilities/debounced.test.ts
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
vi.useFakeTimers();
|
|
9
|
-
});
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
vi.useRealTimers();
|
|
12
|
-
});
|
|
13
|
-
describe("createDebounced", () => {
|
|
14
|
-
it("returns the initial value synchronously", () => {
|
|
15
|
-
const s = signal(42);
|
|
16
|
-
let d;
|
|
17
|
-
effectScope(() => {
|
|
18
|
-
d = createDebounced(() => s(), 100);
|
|
19
|
-
});
|
|
20
|
-
globalExpect(d()).toBe(42);
|
|
21
|
-
});
|
|
22
|
-
it("does not update before the delay elapses", () => {
|
|
23
|
-
const s = signal(0);
|
|
24
|
-
let d;
|
|
25
|
-
effectScope(() => {
|
|
26
|
-
d = createDebounced(() => s(), 100);
|
|
27
|
-
});
|
|
28
|
-
s(1);
|
|
29
|
-
vi.advanceTimersByTime(50);
|
|
30
|
-
globalExpect(d()).toBe(0);
|
|
31
|
-
});
|
|
32
|
-
it("updates after the delay elapses", () => {
|
|
33
|
-
const s = signal(0);
|
|
34
|
-
let d;
|
|
35
|
-
effectScope(() => {
|
|
36
|
-
d = createDebounced(() => s(), 100);
|
|
37
|
-
});
|
|
38
|
-
s(1);
|
|
39
|
-
vi.advanceTimersByTime(100);
|
|
40
|
-
globalExpect(d()).toBe(1);
|
|
41
|
-
});
|
|
42
|
-
it("resets the timer on each rapid change", () => {
|
|
43
|
-
const s = signal(0);
|
|
44
|
-
let d;
|
|
45
|
-
effectScope(() => {
|
|
46
|
-
d = createDebounced(() => s(), 100);
|
|
47
|
-
});
|
|
48
|
-
s(1);
|
|
49
|
-
vi.advanceTimersByTime(50);
|
|
50
|
-
s(2);
|
|
51
|
-
vi.advanceTimersByTime(50);
|
|
52
|
-
globalExpect(d()).toBe(0);
|
|
53
|
-
vi.advanceTimersByTime(50);
|
|
54
|
-
globalExpect(d()).toBe(2);
|
|
55
|
-
});
|
|
56
|
-
it("stops updating after scope disposal", () => {
|
|
57
|
-
const s = signal(0);
|
|
58
|
-
let d;
|
|
59
|
-
effectScope(() => {
|
|
60
|
-
d = createDebounced(() => s(), 100);
|
|
61
|
-
})();
|
|
62
|
-
s(99);
|
|
63
|
-
vi.advanceTimersByTime(200);
|
|
64
|
-
globalExpect(d()).toBe(0);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
//#endregion
|
|
68
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|