what-core 0.13.11 → 0.15.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.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -38
  3. package/a11y.d.ts +128 -0
  4. package/data.d.ts +294 -0
  5. package/dist/a11y.js +510 -0
  6. package/dist/a11y.min.js +413 -0
  7. package/dist/actions.js +158 -0
  8. package/dist/actions.min.js +112 -0
  9. package/dist/animation.js +481 -0
  10. package/dist/animation.min.js +295 -0
  11. package/dist/async.js +180 -0
  12. package/dist/async.min.js +134 -0
  13. package/dist/components.js +577 -0
  14. package/dist/components.min.js +413 -0
  15. package/dist/data.js +1212 -0
  16. package/dist/data.min.js +918 -0
  17. package/dist/diagnostics.js +187 -0
  18. package/dist/diagnostics.min.js +134 -0
  19. package/dist/dom.js +796 -0
  20. package/dist/dom.min.js +603 -0
  21. package/dist/entries/a11y.js +43 -0
  22. package/dist/entries/a11y.min.js +43 -0
  23. package/dist/entries/data.js +29 -0
  24. package/dist/entries/data.min.js +29 -0
  25. package/dist/entries/dom.js +45 -0
  26. package/dist/entries/dom.min.js +45 -0
  27. package/dist/entries/form.js +31 -0
  28. package/dist/entries/form.min.js +31 -0
  29. package/dist/entries/internal.js +123 -0
  30. package/dist/entries/internal.min.js +123 -0
  31. package/dist/entries/motion.js +23 -0
  32. package/dist/entries/motion.min.js +23 -0
  33. package/dist/entries/ui.js +25 -0
  34. package/dist/entries/ui.min.js +25 -0
  35. package/dist/env.js +5 -0
  36. package/dist/env.min.js +5 -0
  37. package/dist/errors.js +1518 -0
  38. package/dist/errors.min.js +548 -0
  39. package/dist/form.js +936 -0
  40. package/dist/form.min.js +703 -0
  41. package/dist/guardrails.js +84 -0
  42. package/dist/guardrails.min.js +55 -0
  43. package/dist/h.js +232 -0
  44. package/dist/h.min.js +171 -0
  45. package/dist/head.js +241 -0
  46. package/dist/head.min.js +207 -0
  47. package/dist/helpers.js +126 -0
  48. package/dist/helpers.min.js +98 -0
  49. package/dist/hooks.js +255 -0
  50. package/dist/hooks.min.js +153 -0
  51. package/dist/hot.js +215 -0
  52. package/dist/hot.min.js +24 -0
  53. package/dist/hydration-data.js +495 -0
  54. package/dist/hydration-data.min.js +371 -0
  55. package/dist/import-changes.js +273 -0
  56. package/dist/import-changes.min.js +272 -0
  57. package/dist/index.js +95 -0
  58. package/dist/index.min.js +95 -227
  59. package/dist/jsx-dev-runtime.js +10 -0
  60. package/dist/jsx-dev-runtime.min.js +10 -1
  61. package/dist/jsx-runtime.js +27 -0
  62. package/dist/jsx-runtime.min.js +15 -1
  63. package/dist/live.js +54 -0
  64. package/dist/live.min.js +49 -0
  65. package/dist/markup-rules.js +250 -0
  66. package/dist/markup-rules.min.js +213 -0
  67. package/dist/reactive.js +3334 -0
  68. package/dist/reactive.min.js +2033 -0
  69. package/dist/render.js +4746 -0
  70. package/dist/render.min.js +2797 -1
  71. package/dist/scheduler.js +225 -0
  72. package/dist/scheduler.min.js +162 -0
  73. package/dist/selector.js +11 -0
  74. package/dist/selector.min.js +10 -0
  75. package/dist/server-context.js +148 -0
  76. package/dist/server-context.min.js +121 -0
  77. package/dist/skeleton.js +342 -0
  78. package/dist/skeleton.min.js +310 -0
  79. package/dist/store.js +72 -0
  80. package/dist/store.min.js +50 -0
  81. package/dist/testing.js +720 -0
  82. package/dist/testing.min.js +458 -1
  83. package/dist/vnode-adoption.js +19 -0
  84. package/dist/vnode-adoption.min.js +19 -0
  85. package/dist/vnode-renderer.js +61 -0
  86. package/dist/vnode-renderer.min.js +47 -0
  87. package/dom.d.ts +44 -0
  88. package/form.d.ts +218 -0
  89. package/hot.d.ts +35 -0
  90. package/index.d.ts +421 -736
  91. package/internal.d.ts +284 -0
  92. package/jsx-runtime.d.ts +160 -137
  93. package/markup-rules.d.ts +83 -0
  94. package/motion.d.ts +156 -0
  95. package/package.json +117 -3
  96. package/render.d.ts +278 -29
  97. package/src/a11y.js +64 -59
  98. package/src/actions.js +226 -0
  99. package/src/animation.js +105 -57
  100. package/src/async.js +259 -0
  101. package/src/components.js +495 -144
  102. package/src/data.js +1410 -1159
  103. package/src/diagnostics.js +263 -0
  104. package/src/dom.js +1159 -872
  105. package/src/entries/a11y.js +24 -0
  106. package/src/entries/data.js +17 -0
  107. package/src/entries/dom.js +29 -0
  108. package/src/entries/form.js +16 -0
  109. package/src/entries/internal.js +63 -0
  110. package/src/entries/motion.js +13 -0
  111. package/src/entries/ui.js +13 -0
  112. package/src/env-development.js +12 -0
  113. package/src/env.js +33 -0
  114. package/src/errors.js +1144 -168
  115. package/src/form.js +723 -225
  116. package/src/guardrails.js +38 -126
  117. package/src/h.js +227 -152
  118. package/src/head.js +189 -19
  119. package/src/helpers.js +47 -75
  120. package/src/hooks.js +233 -248
  121. package/src/hot.js +316 -0
  122. package/src/hydration-data.js +859 -16
  123. package/src/import-changes.js +156 -0
  124. package/src/index.js +38 -188
  125. package/src/jsx-dev-runtime.js +7 -14
  126. package/src/jsx-runtime.js +25 -9
  127. package/src/live.js +80 -0
  128. package/src/markup-rules.js +387 -0
  129. package/src/reactive.js +4400 -862
  130. package/src/render.js +6502 -2570
  131. package/src/scheduler.js +56 -21
  132. package/src/selector.js +31 -0
  133. package/src/server-context.js +252 -22
  134. package/src/skeleton.js +22 -12
  135. package/src/store.js +17 -31
  136. package/src/testing.js +389 -63
  137. package/src/vnode-adoption.js +48 -0
  138. package/src/vnode-renderer.js +114 -0
  139. package/testing.d.ts +81 -1
  140. package/ui.d.ts +20 -0
  141. package/dist/chunk-6YOUZ6T4.min.js +0 -1
  142. package/dist/chunk-FN6HXME3.min.js +0 -11
  143. package/dist/chunk-VKZY7JPN.min.js +0 -1
  144. package/src/agent-context.js +0 -127
  145. package/src/warnings.js +0 -193
@@ -0,0 +1,413 @@
1
+ // src/a11y.js
2
+ import { signal as b, effect as S, onCleanup as T } from "./reactive.min.js";
3
+ import { h as g } from "./h.min.js";
4
+ import { getServerContext as K } from "./server-context.min.js";
5
+ var x = null;
6
+ function _() {
7
+ if (x === null) {
8
+ let t = typeof document < "u" ? document.activeElement : null;
9
+ x = b(t && t !== document.body ? t : null), typeof document < "u" && (document.addEventListener("focusin", (e) => x.set(e.target)), document.addEventListener("focusout", () => x.set(null)));
10
+ }
11
+ return x;
12
+ }
13
+ function O() {
14
+ let t = _();
15
+ return {
16
+ current: () => t(),
17
+ focus: (e) => e?.focus(),
18
+ blur: () => (
19
+ /** @type {HTMLElement | null} */
20
+ document.activeElement?.blur()
21
+ )
22
+ };
23
+ }
24
+ function U() {
25
+ let t = { current: null };
26
+ function e(u) {
27
+ typeof document > "u" || (t.current = u || document.activeElement || null);
28
+ }
29
+ function n(u) {
30
+ let c = t.current || u;
31
+ c && typeof c.focus == "function" && c.focus();
32
+ }
33
+ return {
34
+ capture: e,
35
+ restore: n,
36
+ previous: () => t.current
37
+ };
38
+ }
39
+ function j(t) {
40
+ let e = null;
41
+ function n() {
42
+ if (typeof document > "u") return;
43
+ e = /** @type {HTMLElement | null} */
44
+ document.activeElement;
45
+ let c = t.current || t;
46
+ if (!c || typeof c.querySelectorAll != "function") return;
47
+ let i = F(c);
48
+ if (i.length === 0) return;
49
+ i[0].focus();
50
+ function s(p) {
51
+ if (p.key !== "Tab") return;
52
+ let a = F(c);
53
+ if (p.preventDefault(), a.length === 0) return;
54
+ let d = a.indexOf(
55
+ /** @type {HTMLElement} */
56
+ document.activeElement
57
+ ), y = a.length - 1;
58
+ (p.shiftKey ? a[d <= 0 ? y : d - 1] : a[d === -1 || d === y ? 0 : d + 1]).focus();
59
+ }
60
+ return c.addEventListener("keydown", s), () => {
61
+ c.removeEventListener("keydown", s);
62
+ };
63
+ }
64
+ function u() {
65
+ e && typeof e.focus == "function" && e.focus();
66
+ }
67
+ return { activate: n, deactivate: u };
68
+ }
69
+ function F(t) {
70
+ let e = [
71
+ "button:not([disabled])",
72
+ "a[href]",
73
+ "input:not([disabled])",
74
+ "select:not([disabled])",
75
+ "textarea:not([disabled])",
76
+ '[tabindex]:not([tabindex="-1"])'
77
+ ].join(",");
78
+ return Array.from(t.querySelectorAll(e)).filter((n) => n.offsetParent !== null);
79
+ }
80
+ var z = /* @__PURE__ */ Object.assign(function({ children: e, active: n = !0 }) {
81
+ let u = { current: null }, c = b(0), i = j(u), s = null, p = (a) => {
82
+ u.current = a, c.set((d) => d + 1);
83
+ };
84
+ return S(() => {
85
+ if (c(), s && (s(), s = null, i.deactivate()), n && u.current)
86
+ return s = i.activate(), () => {
87
+ s?.(), s = null, i.deactivate();
88
+ };
89
+ }), T(() => {
90
+ s?.(), s = null, i.deactivate();
91
+ }), g("div", { ref: p }, e);
92
+ }, { _deferChildren: !0 }), m = null, h = 0;
93
+ function B() {
94
+ return typeof document > "u" ? null : (m || (m = document.createElement("div"), m.id = "what-announcer", m.setAttribute("aria-live", "polite"), m.setAttribute("aria-atomic", "true"), m.style.cssText = `
95
+ position: absolute;
96
+ width: 1px;
97
+ height: 1px;
98
+ padding: 0;
99
+ margin: -1px;
100
+ overflow: hidden;
101
+ clip: rect(0, 0, 0, 0);
102
+ white-space: nowrap;
103
+ border: 0;
104
+ `, document.body.appendChild(m)), m);
105
+ }
106
+ function H(t, e = {}) {
107
+ let { priority: n = "polite", timeout: u = 1e3 } = e, c = B();
108
+ if (!c) return;
109
+ c.setAttribute("aria-live", n);
110
+ let i = ++h;
111
+ c.textContent = "", requestAnimationFrame(() => {
112
+ h === i && (c.textContent = t);
113
+ }), setTimeout(() => {
114
+ h === i && (c.textContent = "");
115
+ }, u);
116
+ }
117
+ function N(t) {
118
+ return H(t, { priority: "assertive" });
119
+ }
120
+ var G = /* @__PURE__ */ Object.assign(function({ href: e = "#main", children: n = "Skip to content" }) {
121
+ return g("a", {
122
+ href: e,
123
+ class: "what-skip-link",
124
+ onClick: (u) => {
125
+ u.preventDefault();
126
+ let c = (
127
+ /** @type {HTMLElement | null} */
128
+ document.querySelector(e)
129
+ );
130
+ c && (c.focus(), c.scrollIntoView());
131
+ },
132
+ style: {
133
+ position: "absolute",
134
+ top: "-40px",
135
+ left: "0",
136
+ padding: "8px",
137
+ background: "#000",
138
+ color: "#fff",
139
+ textDecoration: "none",
140
+ zIndex: "10000"
141
+ },
142
+ onFocus: (u) => {
143
+ u.target.style.top = "0";
144
+ },
145
+ onBlur: (u) => {
146
+ u.target.style.top = "-40px";
147
+ }
148
+ }, n);
149
+ }, { _deferChildren: !0 });
150
+ function k(t) {
151
+ return t ? "true" : "false";
152
+ }
153
+ function J(t = !1) {
154
+ let e = b(t);
155
+ return {
156
+ expanded: () => e(),
157
+ toggle: () => e.set(!e.peek()),
158
+ open: () => e.set(!0),
159
+ close: () => e.set(!1),
160
+ buttonProps: () => ({
161
+ "aria-expanded": () => k(e()),
162
+ onClick: () => e.set(!e.peek())
163
+ }),
164
+ panelProps: () => ({
165
+ // `hidden` is a genuine HTML boolean attribute, so it stays a boolean:
166
+ // present-or-absent is the correct serialization here, unlike ARIA.
167
+ hidden: () => !e()
168
+ })
169
+ };
170
+ }
171
+ function M(t = null) {
172
+ let e = b(t);
173
+ return {
174
+ selected: () => e(),
175
+ select: (n) => e.set(n),
176
+ isSelected: (n) => e() === n,
177
+ itemProps: (n) => ({
178
+ "aria-selected": () => k(e() === n),
179
+ onClick: () => e.set(n)
180
+ })
181
+ };
182
+ }
183
+ function Q(t = !1) {
184
+ let e = b(t);
185
+ return {
186
+ checked: () => e(),
187
+ toggle: () => e.set(!e.peek()),
188
+ set: (n) => e.set(n),
189
+ checkboxProps: () => ({
190
+ role: "checkbox",
191
+ "aria-checked": () => k(e()),
192
+ tabIndex: 0,
193
+ onClick: () => e.set(!e.peek()),
194
+ onKeyDown: (n) => {
195
+ (n.key === " " || n.key === "Enter") && (n.preventDefault(), e.set(!e.peek()));
196
+ }
197
+ })
198
+ };
199
+ }
200
+ function W(t, e = {}) {
201
+ let n = typeof t == "function" ? t : () => t, u = b(0), c = e?.role || null, i = [], s = [], p = [];
202
+ function a(r) {
203
+ let o = s[r];
204
+ return o || (o = {
205
+ get current() {
206
+ return i[r] || null;
207
+ },
208
+ set current(l) {
209
+ i[r] = l || null;
210
+ let f = p[r];
211
+ typeof f == "function" ? f(l) : f && typeof f == "object" && (f.current = l);
212
+ }
213
+ }, s[r] = o), o;
214
+ }
215
+ function d(r) {
216
+ let o = i[r];
217
+ return o ? o.isConnected === !1 ? null : o : null;
218
+ }
219
+ function y(r) {
220
+ let o = d(r);
221
+ return !o || typeof o.focus != "function" ? null : ((typeof document > "u" || document.activeElement !== o) && o.focus(), o);
222
+ }
223
+ function w() {
224
+ if (typeof document > "u") return !1;
225
+ let r = document.activeElement;
226
+ if (!r) return !1;
227
+ for (let o = 0; o < i.length; o++) {
228
+ let l = i[o];
229
+ if (l && (l === r || typeof l.contains == "function" && l.contains(r)))
230
+ return !0;
231
+ }
232
+ return !1;
233
+ }
234
+ function E(r, o) {
235
+ return !(o > 0) || r < 0 ? 0 : r > o - 1 ? o - 1 : r;
236
+ }
237
+ function A() {
238
+ return E(u(), n());
239
+ }
240
+ function I(r) {
241
+ return Number.isInteger(r) && r >= 0 && r < n();
242
+ }
243
+ function P(r) {
244
+ let o = n();
245
+ if (o <= 0) return;
246
+ let l = E(u.peek(), o), f = l;
247
+ switch (r.key) {
248
+ case "ArrowDown":
249
+ case "ArrowRight":
250
+ f = (l + 1) % o;
251
+ break;
252
+ case "ArrowUp":
253
+ case "ArrowLeft":
254
+ f = (l - 1 + o) % o;
255
+ break;
256
+ case "Home":
257
+ f = 0;
258
+ break;
259
+ case "End":
260
+ f = o - 1;
261
+ break;
262
+ default:
263
+ return;
264
+ }
265
+ r.preventDefault(), u.set(f), y(f);
266
+ }
267
+ return {
268
+ focusIndex: () => A(),
269
+ // Follows focus only when the group already owns it, so syncing the index
270
+ // from application state cannot steal focus from elsewhere on the page.
271
+ // Use focusItem() when moving focus is the intent.
272
+ setFocusIndex: (r) => {
273
+ I(r) && (u.set(r), w() && y(r));
274
+ },
275
+ // Explicitly move focus to an item, e.g. a menu focusing its first item on
276
+ // open. Returns the element it focused, or null when the index is out of
277
+ // range or the item is not in the DOM.
278
+ focusItem: (r) => I(r) ? (u.set(r), y(r)) : null,
279
+ // `overrides` are spread last and win, except for `ref`, which is chained
280
+ // (see refFor) because this hook needs the node to move focus at all.
281
+ getItemProps: (r, o) => {
282
+ let { ref: l, ...f } = o || {};
283
+ return p[r] = l || null, {
284
+ ref: a(r),
285
+ // Accessor, not a snapshot: exactly one item is tabbable at a time and
286
+ // which one has to change as focus roves. See the ariaBool note above
287
+ // for why a resolved value cannot survive a spread.
288
+ tabIndex: () => A() === r ? 0 : -1,
289
+ onKeyDown: P,
290
+ // The ref is the registration; this is a free corrective for it. A call
291
+ // site that spreads its own ref AFTER getItemProps() replaces ours, and
292
+ // an element reporting its own focus event is first-hand evidence of
293
+ // which node index `index` rendered to.
294
+ onFocus: (v) => {
295
+ let C = v && (v.currentTarget || v.target);
296
+ C && (i[r] = C), u.set(r);
297
+ },
298
+ ...f
299
+ };
300
+ },
301
+ containerProps: (r) => c ? { role: c, ...r } : { ...r }
302
+ };
303
+ }
304
+ var X = /* @__PURE__ */ Object.assign(function({ children: e, as: n = "span" }) {
305
+ return g(n, {
306
+ style: {
307
+ position: "absolute",
308
+ width: "1px",
309
+ height: "1px",
310
+ padding: "0",
311
+ margin: "-1px",
312
+ overflow: "hidden",
313
+ clip: "rect(0, 0, 0, 0)",
314
+ whiteSpace: "nowrap",
315
+ border: "0"
316
+ }
317
+ }, e);
318
+ }, { _deferChildren: !0 }), Y = /* @__PURE__ */ Object.assign(function({ children: e, priority: n = "polite", atomic: u = !0 }) {
319
+ return g("div", {
320
+ "aria-live": n,
321
+ "aria-atomic": u
322
+ }, e);
323
+ }, { _deferChildren: !0 }), D = 0;
324
+ function R() {
325
+ let t = K();
326
+ return t ? (t.idCounter = (t.idCounter || 0) + 1, t.idCounter) : ++D;
327
+ }
328
+ function Z() {
329
+ D = 0;
330
+ }
331
+ function L(t = "what") {
332
+ return `${t}-${R()}`;
333
+ }
334
+ function ee(t, e = "what") {
335
+ let n = [];
336
+ for (let u = 0; u < t; u++)
337
+ n.push(`${e}-${R()}`);
338
+ return n;
339
+ }
340
+ function te(t) {
341
+ let e = L("desc");
342
+ return {
343
+ descriptionId: e,
344
+ descriptionProps: () => ({
345
+ id: e,
346
+ style: { display: "none" }
347
+ }),
348
+ describedByProps: () => ({
349
+ "aria-describedby": e
350
+ }),
351
+ Description: () => g("div", {
352
+ id: e,
353
+ style: { display: "none" }
354
+ }, t)
355
+ };
356
+ }
357
+ function ne(t) {
358
+ let e = L("label");
359
+ return {
360
+ labelId: e,
361
+ labelProps: () => ({
362
+ id: e
363
+ }),
364
+ labelledByProps: () => ({
365
+ "aria-labelledby": e
366
+ })
367
+ };
368
+ }
369
+ var re = {
370
+ Enter: "Enter",
371
+ Space: " ",
372
+ Escape: "Escape",
373
+ ArrowUp: "ArrowUp",
374
+ ArrowDown: "ArrowDown",
375
+ ArrowLeft: "ArrowLeft",
376
+ ArrowRight: "ArrowRight",
377
+ Home: "Home",
378
+ End: "End",
379
+ Tab: "Tab"
380
+ };
381
+ function oe(t, e) {
382
+ return (n) => {
383
+ n.key === t && e(n);
384
+ };
385
+ }
386
+ function ue(t, e) {
387
+ return (n) => {
388
+ t.includes(n.key) && e(n);
389
+ };
390
+ }
391
+ export {
392
+ z as FocusTrap,
393
+ re as Keys,
394
+ Y as LiveRegion,
395
+ G as SkipLink,
396
+ X as VisuallyHidden,
397
+ Z as __resetIdCounter,
398
+ H as announce,
399
+ N as announceAssertive,
400
+ oe as onKey,
401
+ ue as onKeys,
402
+ Q as useAriaChecked,
403
+ J as useAriaExpanded,
404
+ M as useAriaSelected,
405
+ te as useDescribedBy,
406
+ O as useFocus,
407
+ U as useFocusRestore,
408
+ j as useFocusTrap,
409
+ L as useId,
410
+ ee as useIds,
411
+ ne as useLabelledBy,
412
+ W as useRovingTabIndex
413
+ };
@@ -0,0 +1,158 @@
1
+ // src/actions.js
2
+ import { signal, getOwner, onCleanup, _startTransition, _onCommit, _handleError, HANDLED } from "./reactive.js";
3
+ import { createContext, useContext } from "./hooks.js";
4
+ function useActionState(action, initialState, permalink) {
5
+ const id = action != null ? action._actionId : void 0;
6
+ const form = id !== void 0 && action._formState ? action._formState() : null;
7
+ const start = form !== null && "state" in form ? form.state : initialState;
8
+ const state = signal(start);
9
+ const open = signal(0);
10
+ const owner = getOwner();
11
+ const calls = /* @__PURE__ */ new Set();
12
+ const waits = /* @__PURE__ */ new Set();
13
+ let latest = start;
14
+ let queue = null;
15
+ let generation = 0;
16
+ if (owner !== null) {
17
+ onCleanup(() => {
18
+ generation++;
19
+ for (const call of calls) call.abandon();
20
+ for (const leave of waits) leave();
21
+ });
22
+ }
23
+ const dispatch = (payload) => {
24
+ const gen = generation;
25
+ let tx = null;
26
+ const before = queue;
27
+ let done = () => {
28
+ };
29
+ const mine = queue = new Promise((resolve) => {
30
+ done = resolve;
31
+ });
32
+ _startTransition(async () => {
33
+ try {
34
+ if (before !== null) await before;
35
+ if (gen !== generation) {
36
+ failedIn.add(tx);
37
+ return;
38
+ }
39
+ const [settled, leave] = untilLeft(action(latest, payload));
40
+ waits.add(leave);
41
+ let next;
42
+ try {
43
+ next = await settled;
44
+ } finally {
45
+ waits.delete(leave);
46
+ }
47
+ if (gen !== generation) {
48
+ failedIn.add(tx);
49
+ return;
50
+ }
51
+ latest = next;
52
+ _onCommit(tx, () => state(next));
53
+ } catch (err) {
54
+ generation++;
55
+ failedIn.add(tx);
56
+ const left = _handleError(owner, err);
57
+ if (left !== HANDLED) throw left;
58
+ } finally {
59
+ if (queue === mine) queue = null;
60
+ done();
61
+ }
62
+ }, (t, call) => {
63
+ tx = t;
64
+ open((n) => n + 1);
65
+ calls.add(call);
66
+ _onCommit(t, () => {
67
+ open((n) => n - 1);
68
+ calls.delete(call);
69
+ });
70
+ }).catch((err) => {
71
+ try {
72
+ console.error("[what] Uncaught error in action:", err);
73
+ } catch {
74
+ }
75
+ });
76
+ };
77
+ if (permalink !== void 0) dispatch.permalink = permalink;
78
+ if (id !== void 0) {
79
+ dispatch._actionId = id;
80
+ dispatch._key = form !== null ? form.key : null;
81
+ dispatch._state = () => state();
82
+ }
83
+ return [() => state(), dispatch, () => open() > 0];
84
+ }
85
+ function untilLeft(value) {
86
+ const wait = { resolve: (_v) => {
87
+ }, reject: (_e) => {
88
+ } };
89
+ const settled = new Promise((resolve, reject) => {
90
+ wait.resolve = resolve;
91
+ wait.reject = reject;
92
+ });
93
+ Promise.resolve(value).then((v) => wait.resolve(v), (err) => wait.reject(err));
94
+ const leave = () => {
95
+ const resolve = wait.resolve;
96
+ wait.resolve = wait.reject = () => {
97
+ };
98
+ resolve(void 0);
99
+ };
100
+ return [settled, leave];
101
+ }
102
+ var failedIn = /* @__PURE__ */ new WeakSet();
103
+ var NO_FORM = /* @__PURE__ */ Object.freeze({
104
+ pending: () => false,
105
+ data: () => null,
106
+ method: null,
107
+ action: null
108
+ });
109
+ var formContext = null;
110
+ function _formStatusContext() {
111
+ return formContext || (formContext = createContext(NO_FORM));
112
+ }
113
+ function useFormStatus() {
114
+ return formContext === null ? NO_FORM : useContext(formContext);
115
+ }
116
+ function _formStatus(method, action) {
117
+ const pending = signal(
118
+ /** @type {FormData[]} */
119
+ []
120
+ );
121
+ const calls = /* @__PURE__ */ new Set();
122
+ let mounted = true;
123
+ if (getOwner() !== null) {
124
+ onCleanup(() => {
125
+ mounted = false;
126
+ for (const call of calls) call.abandon();
127
+ });
128
+ }
129
+ return {
130
+ pending: () => pending().length > 0,
131
+ data: () => pending().at(-1) ?? null,
132
+ method,
133
+ action: typeof action === "function" ? action : null,
134
+ submit(formData, run, reset) {
135
+ return _startTransition(() => {
136
+ try {
137
+ return run(formData);
138
+ } catch (error) {
139
+ return Promise.reject(error);
140
+ }
141
+ }, (t, call) => {
142
+ calls.add(call);
143
+ pending((list) => [...list, formData]);
144
+ _onCommit(t, () => {
145
+ calls.delete(call);
146
+ pending((list) => list.filter((entry) => entry !== formData));
147
+ if (mounted && !call.failed && !failedIn.has(t)) queueMicrotask(() => mounted && reset());
148
+ });
149
+ });
150
+ }
151
+ };
152
+ }
153
+ export {
154
+ _formStatus,
155
+ _formStatusContext,
156
+ useActionState,
157
+ useFormStatus
158
+ };
@@ -0,0 +1,112 @@
1
+ // src/actions.js
2
+ import { signal as g, getOwner as O, onCleanup as P, _startTransition as I, _onCommit as j, _handleError as E, HANDLED as F } from "./reactive.min.js";
3
+ import { createContext as L, useContext as M } from "./hooks.min.js";
4
+ function R(r, t, l) {
5
+ let s = r?._actionId, e = s !== void 0 && r._formState ? r._formState() : null, n = e !== null && "state" in e ? e.state : t, d = g(n), m = g(0), u = O(), c = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), v = n, x = null, w = 0;
6
+ u !== null && P(() => {
7
+ w++;
8
+ for (let h of c) h.abandon();
9
+ for (let h of i) h();
10
+ });
11
+ let _ = (h) => {
12
+ let C = w, p = null, b = x, k = () => {
13
+ }, A = x = new Promise((o) => {
14
+ k = o;
15
+ });
16
+ I(async () => {
17
+ try {
18
+ if (b !== null && await b, C !== w) {
19
+ y.add(p);
20
+ return;
21
+ }
22
+ let [o, a] = N(r(v, h));
23
+ i.add(a);
24
+ let f;
25
+ try {
26
+ f = await o;
27
+ } finally {
28
+ i.delete(a);
29
+ }
30
+ if (C !== w) {
31
+ y.add(p);
32
+ return;
33
+ }
34
+ v = f, j(p, () => d(f));
35
+ } catch (o) {
36
+ w++, y.add(p);
37
+ let a = E(u, o);
38
+ if (a !== F) throw a;
39
+ } finally {
40
+ x === A && (x = null), k();
41
+ }
42
+ }, (o, a) => {
43
+ p = o, m((f) => f + 1), c.add(a), j(o, () => {
44
+ m((f) => f - 1), c.delete(a);
45
+ });
46
+ }).catch((o) => {
47
+ try {
48
+ console.error("[what] Uncaught error in action:", o);
49
+ } catch {
50
+ }
51
+ });
52
+ };
53
+ return l !== void 0 && (_.permalink = l), s !== void 0 && (_._actionId = s, _._key = e !== null ? e.key : null, _._state = () => d()), [() => d(), _, () => m() > 0];
54
+ }
55
+ function N(r) {
56
+ let t = { resolve: (e) => {
57
+ }, reject: (e) => {
58
+ } }, l = new Promise((e, n) => {
59
+ t.resolve = e, t.reject = n;
60
+ });
61
+ return Promise.resolve(r).then((e) => t.resolve(e), (e) => t.reject(e)), [l, () => {
62
+ let e = t.resolve;
63
+ t.resolve = t.reject = () => {
64
+ }, e(void 0);
65
+ }];
66
+ }
67
+ var y = /* @__PURE__ */ new WeakSet(), q = /* @__PURE__ */ Object.freeze({
68
+ pending: () => !1,
69
+ data: () => null,
70
+ method: null,
71
+ action: null
72
+ }), S = null;
73
+ function T() {
74
+ return S || (S = L(q));
75
+ }
76
+ function U() {
77
+ return S === null ? q : M(S);
78
+ }
79
+ function W(r, t) {
80
+ let l = g(
81
+ /** @type {FormData[]} */
82
+ []
83
+ ), s = /* @__PURE__ */ new Set(), e = !0;
84
+ return O() !== null && P(() => {
85
+ e = !1;
86
+ for (let n of s) n.abandon();
87
+ }), {
88
+ pending: () => l().length > 0,
89
+ data: () => l().at(-1) ?? null,
90
+ method: r,
91
+ action: typeof t == "function" ? t : null,
92
+ submit(n, d, m) {
93
+ return I(() => {
94
+ try {
95
+ return d(n);
96
+ } catch (u) {
97
+ return Promise.reject(u);
98
+ }
99
+ }, (u, c) => {
100
+ s.add(c), l((i) => [...i, n]), j(u, () => {
101
+ s.delete(c), l((i) => i.filter((v) => v !== n)), e && !c.failed && !y.has(u) && queueMicrotask(() => e && m());
102
+ });
103
+ });
104
+ }
105
+ };
106
+ }
107
+ export {
108
+ W as _formStatus,
109
+ T as _formStatusContext,
110
+ R as useActionState,
111
+ U as useFormStatus
112
+ };