@voltro/client 0.86.0 → 0.87.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.
@@ -4,16 +4,18 @@ import { useMutation as n } from "./useMutation.js";
4
4
  import { schemaToFields as r } from "./schemaFields.js";
5
5
  import { resolveValidationMessage as i, restrictToSchema as a, validateFields as o } from "./formBinding.js";
6
6
  import { useValidationMessages as s } from "./validationMessages.js";
7
- import { createElement as c, useCallback as l, useContext as u, useEffect as ee, useId as d, useLayoutEffect as te, useMemo as f, useRef as p, useState as m, useSyncExternalStore as h } from "react";
8
- import { Schema as g } from "effect";
9
- import { fieldIssuesOf as _ } from "@voltro/protocol";
10
- import { FormApi as ne } from "@tanstack/form-core";
11
- import { useStore as re } from "@tanstack/react-store";
7
+ import { recoverNativeFormValues as c } from "./formData.js";
8
+ import { useServerRequest as l } from "./serverRequest.js";
9
+ import { createElement as u, useCallback as d, useContext as f, useEffect as ee, useId as p, useLayoutEffect as te, useMemo as m, useRef as h, useState as g, useSyncExternalStore as ne } from "react";
10
+ import { Schema as _ } from "effect";
11
+ import { fieldIssuesOf as re } from "@voltro/protocol";
12
+ import { FormApi as ie } from "@tanstack/form-core";
13
+ import { useStore as ae } from "@tanstack/react-store";
12
14
  //#region src/useFormBinding.ts
13
- var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), ie = (e, t) => Object.is(e.value, t.value) && e.error === t.error && e.serverError === t.serverError && e.touched === t.touched && e.blurred === t.blurred && e.dirty === t.dirty && e.required === t.required && e.label === t.label && e.widget === t.widget && e.options === t.options && e.description === t.description && e.asyncStatus === t.asyncStatus && e.a11y.id === t.a11y.id && e.a11y["aria-invalid"] === t.a11y["aria-invalid"] && e.a11y["aria-required"] === t.a11y["aria-required"] && e.a11y["aria-describedby"] === t.a11y["aria-describedby"], ae = (e, t) => {
15
+ var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), b = (e, t) => Object.is(e.value, t.value) && e.error === t.error && e.serverError === t.serverError && e.touched === t.touched && e.blurred === t.blurred && e.dirty === t.dirty && e.required === t.required && e.label === t.label && e.widget === t.widget && e.options === t.options && e.description === t.description && e.asyncStatus === t.asyncStatus && e.a11y.id === t.a11y.id && e.a11y["aria-invalid"] === t.a11y["aria-invalid"] && e.a11y["aria-required"] === t.a11y["aria-required"] && e.a11y["aria-describedby"] === t.a11y["aria-describedby"], oe = (e, t) => {
14
16
  let n = t, r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a, o = (e) => {
15
17
  let t = n(e), i = r.get(e);
16
- return i !== void 0 && ie(i, t) ? i : (r.set(e, t), t);
18
+ return i !== void 0 && b(i, t) ? i : (r.set(e, t), t);
17
19
  }, s = () => {
18
20
  for (let [e, t] of i) {
19
21
  let n = r.get(e);
@@ -37,17 +39,17 @@ var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), ie
37
39
  };
38
40
  }
39
41
  };
40
- }, b = e("formBinding", void 0), oe = (e, t) => {
42
+ }, x = e("formBinding", void 0), se = (e, t) => {
41
43
  let n = e;
42
44
  for (let e of t.split(".")) {
43
45
  if (typeof n != "object" || !n) return;
44
46
  n = n[e];
45
47
  }
46
48
  return n;
47
- }, se = (e, t) => {
49
+ }, ce = (e, t) => {
48
50
  let n = `vf-${e}-${t}-`.replace(/[^a-zA-Z0-9_-]/g, "-");
49
51
  return (e) => n + `${e}`.replace(/[^a-zA-Z0-9_-]/g, "-");
50
- }, ce = (e, t) => {
52
+ }, le = (e, t) => {
51
53
  let n = e.map((e) => e.name), r = Object.keys(t), i;
52
54
  if (e.length >= 32 && r.length >= 32 && Object.getPrototypeOf(e) === Array.prototype && Object.getOwnPropertyDescriptor(e, "some") === void 0) {
53
55
  let t = /* @__PURE__ */ new Set();
@@ -58,7 +60,7 @@ var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), ie
58
60
  }
59
61
  }
60
62
  return [...n, ...r.filter((t) => i === void 0 ? !e.some((e) => e.name === t) : !i.has(t))];
61
- }, le = {
63
+ }, ue = {
62
64
  isTouched: !1,
63
65
  isBlurred: !1,
64
66
  isDirty: !1,
@@ -67,7 +69,7 @@ var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), ie
67
69
  isValidating: !1,
68
70
  errorMap: {},
69
71
  errorSourceMap: {}
70
- }, ue = (e) => {
72
+ }, de = (e) => {
71
73
  let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
72
74
  for (let r of e) {
73
75
  if (t.has(r.name) || t.set(r.name, r), r.widget !== "array" || n.has(r.name)) continue;
@@ -81,171 +83,171 @@ var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), ie
81
83
  let i = /^(.+?)\.\d+\.(.+)$/.exec(e);
82
84
  return i === null ? void 0 : n.get(i[1])?.get(i[2]);
83
85
  };
84
- }, x = (e, r, i) => {
85
- let a = t(e), o = p(void 0), s = typeof r == "function" ? r(o.current?.state?.values ?? i.defaults ?? {}) : r, c = p(s).current, l = n(e, s), u = i.schema ?? a.descriptors[s]?.input;
86
- return process.env.NODE_ENV !== "production" && u === void 0 && console.error(`[@voltro/client] useFormBinding('${e}', '${r}'): no input schema. Pass options.schema, or mount the descriptor so its input reaches the client. Rendering no fields; submit skips client-side validation.`), C(e, c, i, u, o, l);
87
- }, S = (e) => {
88
- let t = p(void 0);
89
- return C("local", d(), {
86
+ }, S = (e, r, i) => {
87
+ let a = t(e), o = h(void 0), s = typeof r == "function" ? r(o.current?.state?.values ?? i.defaults ?? {}) : r, c = h(s).current, l = n(e, s), u = i.schema ?? a.descriptors[s]?.input;
88
+ return process.env.NODE_ENV !== "production" && u === void 0 && console.error(`[@voltro/client] useFormBinding('${e}', '${r}'): no input schema. Pass options.schema, or mount the descriptor so its input reaches the client. Rendering no fields; submit skips client-side validation.`), w(e, c, i, u, o, l);
89
+ }, C = (e) => {
90
+ let t = h(void 0);
91
+ return w("local", p(), {
90
92
  ...e,
91
- onSubmit: async ({ input: t }) => e.onSubmit(await g.decodeUnknownPromise(e.schema)(t))
93
+ onSubmit: async ({ input: t }) => e.onSubmit(await _.decodeUnknownPromise(e.schema)(t))
92
94
  }, e.schema, t);
93
- }, C = (e, t, n, c, u, d) => {
94
- let h = f(() => c ? r(c) : [], [c]), g = f(() => ue(h), [h]), y = f(() => se(e, t), [e, t]), ie = s(), b = n.messages ?? ie, x = f(() => ({
95
+ }, w = (e, t, n, u, f, p) => {
96
+ let ne = l(), _ = m(() => u ? r(u) : [], [u]), y = m(() => de(_), [_]), b = m(() => ce(e, t), [e, t]), x = s(), S = n.messages ?? x, C = m(() => ({
95
97
  ...n.locale === void 0 ? {} : { locale: n.locale },
96
- ...b === void 0 ? {} : { messages: b }
97
- }), [n.locale, b]), S = p(n.asyncFields);
98
- S.current = n.asyncFields;
99
- let C = p(n);
100
- C.current = n;
101
- let w = p(d);
102
- w.current = d;
103
- let T = p(x);
104
- T.current = x;
105
- let E = p(c);
106
- E.current = c;
107
- let [D, O] = m(() => n.flash?.errors ?? {}), [de, k] = m(n.flash?.formError), [fe, A] = m(void 0), j = p(void 0), M = p(!1), N = l((e) => {
108
- let t = E.current;
98
+ ...S === void 0 ? {} : { messages: S }
99
+ }), [n.locale, S]), w = h(n.asyncFields);
100
+ w.current = n.asyncFields;
101
+ let T = h(n);
102
+ T.current = n;
103
+ let E = h(p);
104
+ E.current = p;
105
+ let D = h(C);
106
+ D.current = C;
107
+ let O = h(u);
108
+ O.current = u;
109
+ let [k, A] = g(() => n.flash?.errors ?? {}), [fe, j] = g(n.flash?.formError), [pe, M] = g(void 0), N = h(void 0), P = h(!1), F = d((e) => {
110
+ let t = O.current;
109
111
  if (t === void 0) return [];
110
- let n = C.current, r = e;
112
+ let n = T.current, r = e;
111
113
  if (n.toInput !== void 0) try {
112
114
  r = n.toInput(e);
113
115
  } catch {
114
116
  r = e;
115
117
  }
116
- let i = o(t, r, T.current).issues;
118
+ let i = o(t, r, D.current).issues;
117
119
  if (n.toInput === void 0) return i;
118
120
  let a = n.errorPath ?? {};
119
121
  return i.map((t) => {
120
122
  let n = a[t.path];
121
- return n === void 0 ? (oe(e, t.path) !== void 0 || t.path.includes("."), t) : {
123
+ return n === void 0 ? (se(e, t.path) !== void 0 || t.path.includes("."), t) : {
122
124
  ...t,
123
125
  path: n
124
126
  };
125
127
  });
126
- }, []), P = l((e) => {
127
- let t = { ...e ?? {} }, n = E.current;
128
+ }, []), I = d((e) => {
129
+ let t = { ...e ?? {} }, n = O.current;
128
130
  if (n !== void 0) for (let e of r(n)) (e.widget === "checkbox" || e.widget === "switch") && !(e.name in t) && (t[e.name] = !1);
129
131
  return t;
130
- }, []), pe = p(() => Promise.resolve());
131
- if (u.current === void 0) {
132
- let e = n.flash, t = e === void 0 ? P(n.defaults) : {
133
- ...P(n.defaults),
132
+ }, []), me = h(() => Promise.resolve());
133
+ if (f.current === void 0) {
134
+ let e = n.flash, r = e === void 0 ? I(n.defaults) : {
135
+ ...I(n.defaults),
134
136
  ...e.values
135
- };
136
- u.current = new ne({
137
- onSubmit: ({ value: e }) => pe.current(e),
138
- defaultValues: t,
137
+ }, a = ne === null && u !== void 0 ? c(u, n.formKey ?? e?.formKey ?? t, r) : r;
138
+ f.current = new ie({
139
+ onSubmit: ({ value: e }) => me.current(e),
140
+ defaultValues: a,
139
141
  validators: { onChange: ({ value: e }) => {
140
- let t = N(e);
142
+ let t = F(e);
141
143
  if (t.length === 0) return;
142
144
  let n = {};
143
- for (let e of t) e.path !== "" && !(e.path in n) && (n[e.path] = i(e, T.current));
145
+ for (let e of t) e.path !== "" && !(e.path in n) && (n[e.path] = i(e, D.current));
144
146
  return { fields: n };
145
147
  } }
146
148
  });
147
149
  }
148
- let F = u.current, I = F;
149
- ee(() => I.mount(), [I]);
150
- let me = n.subscribe ?? "all";
151
- re(F.store, (e) => me === "all" ? e : `${e.submissionAttempts}|${String(e.isSubmitting)}|${String(e.isDirty)}|${String(e.isTouched)}`);
152
- let L = F.store.state.values, R = F.store.state, z = f(() => N(L), [
153
- N,
154
- L,
155
- c,
150
+ let L = f.current, R = L;
151
+ ee(() => R.mount(), [R]);
152
+ let he = n.subscribe ?? "all";
153
+ ae(L.store, (e) => he === "all" ? e : `${e.submissionAttempts}|${String(e.isSubmitting)}|${String(e.isDirty)}|${String(e.isTouched)}`);
154
+ let z = L.store.state.values, B = L.store.state, V = m(() => F(z), [
155
+ F,
156
+ z,
157
+ u,
156
158
  n.toInput,
157
159
  n.errorPath,
158
- x
159
- ]), B = f(() => {
160
+ C
161
+ ]), ge = m(() => {
160
162
  let e = /* @__PURE__ */ new Map();
161
- for (let t of z) e.has(t.path) || e.set(t.path, t);
163
+ for (let t of V) e.has(t.path) || e.set(t.path, t);
162
164
  return e;
163
- }, [z]), V = p({
164
- values: L,
165
- index: B
165
+ }, [V]), H = h({
166
+ values: z,
167
+ index: ge
166
168
  });
167
- V.current = {
168
- values: L,
169
- index: B
169
+ H.current = {
170
+ values: z,
171
+ index: ge
170
172
  };
171
- let he = l((e) => {
172
- let t = F.store.state.values;
173
- if (V.current.values !== t) {
173
+ let _e = d((e) => {
174
+ let t = L.store.state.values;
175
+ if (H.current.values !== t) {
174
176
  let e = /* @__PURE__ */ new Map();
175
- for (let n of N(t)) e.has(n.path) || e.set(n.path, n);
176
- V.current = {
177
+ for (let n of F(t)) e.has(n.path) || e.set(n.path, n);
178
+ H.current = {
177
179
  values: t,
178
180
  index: e
179
181
  };
180
182
  }
181
- return V.current.index.get(e);
182
- }, [F, N]), H = n.isLoading === !0, ge = n.validate, U = ge?.onChange ?? "afterTouched", _e = ge?.onBlur ?? !0, ve = l((e) => {
183
- if (H) return !1;
184
- if (F.store.state.submissionAttempts > 0 || U === "always") return !0;
185
- if (U === "never") return !1;
186
- let t = I.getFieldMeta(e);
187
- return t === void 0 ? !1 : _e ? t.isBlurred === !0 : t.isTouched === !0;
183
+ return H.current.index.get(e);
184
+ }, [L, F]), U = n.isLoading === !0, ve = n.validate, W = ve?.onChange ?? "afterTouched", ye = ve?.onBlur ?? !0, be = d((e) => {
185
+ if (U) return !1;
186
+ if (L.store.state.submissionAttempts > 0 || W === "always") return !0;
187
+ if (W === "never") return !1;
188
+ let t = R.getFieldMeta(e);
189
+ return t === void 0 ? !1 : ye ? t.isBlurred === !0 : t.isTouched === !0;
188
190
  }, [
189
- F,
190
- I,
191
- H,
191
+ L,
192
+ R,
192
193
  U,
193
- _e
194
- ]), W = l((e) => {
195
- let t = D[e];
194
+ W,
195
+ ye
196
+ ]), G = d((e) => {
197
+ let t = k[e];
196
198
  if (t !== void 0) return t;
197
- let n = S.current?.[e];
199
+ let n = w.current?.[e];
198
200
  if (n !== void 0 && n.status === "invalid") return n.message ?? i({
199
201
  id: "validation.invalid",
200
202
  fallback: "Invalid value"
201
- }, T.current);
202
- if (!ve(e)) return;
203
- let r = he(e);
204
- return r === void 0 ? void 0 : i(r, T.current);
203
+ }, D.current);
204
+ if (!be(e)) return;
205
+ let r = _e(e);
206
+ return r === void 0 ? void 0 : i(r, D.current);
205
207
  }, [
206
- D,
207
- ve,
208
- he
209
- ]), G = f(() => {
208
+ k,
209
+ be,
210
+ _e
211
+ ]), K = m(() => {
210
212
  let e = {}, t = /* @__PURE__ */ new Set();
211
- for (let e of z) e.path !== "" && t.add(e.path);
212
- for (let e of Object.keys(D)) t.add(e);
213
- for (let [e, n] of Object.entries(S.current ?? {})) n.status === "invalid" && t.add(e);
213
+ for (let e of V) e.path !== "" && t.add(e.path);
214
+ for (let e of Object.keys(k)) t.add(e);
215
+ for (let [e, n] of Object.entries(w.current ?? {})) n.status === "invalid" && t.add(e);
214
216
  for (let n of t) {
215
- let t = W(n);
217
+ let t = G(n);
216
218
  t !== void 0 && (e[n] = t);
217
219
  }
218
220
  return e;
219
221
  }, [
220
- z,
221
- D,
222
- W,
223
- R.fieldMetaBase,
224
- R.submissionAttempts,
222
+ V,
223
+ k,
224
+ G,
225
+ B.fieldMetaBase,
226
+ B.submissionAttempts,
225
227
  n.asyncFields
226
- ]), K = l((e) => {
227
- O((t) => {
228
+ ]), q = d((e) => {
229
+ A((t) => {
228
230
  if (!(e in t)) return t;
229
231
  let n = { ...t };
230
232
  return delete n[e], n;
231
233
  });
232
- }, []), q = l((e) => {
233
- let t = g(e), n = I.getFieldMeta(e), r = W(e), i = y(e), a = S.current?.[e], o = [r === void 0 ? void 0 : `${i}-error`, t?.description === void 0 ? void 0 : `${i}-help`].filter((e) => e !== void 0);
234
+ }, []), J = d((e) => {
235
+ let t = y(e), n = R.getFieldMeta(e), r = G(e), i = b(e), a = w.current?.[e], o = [r === void 0 ? void 0 : `${i}-error`, t?.description === void 0 ? void 0 : `${i}-help`].filter((e) => e !== void 0);
234
236
  return {
235
- value: I.getFieldValue(e),
237
+ value: R.getFieldValue(e),
236
238
  setValue: (t) => {
237
- K(e), !Object.is(I.getFieldValue(e), t) && I.setFieldValue(e, t);
239
+ q(e), !Object.is(R.getFieldValue(e), t) && R.setFieldValue(e, t);
238
240
  },
239
241
  onBlur: () => {
240
- I.setFieldMeta(e, (e) => ({
241
- ...le,
242
+ R.setFieldMeta(e, (e) => ({
243
+ ...ue,
242
244
  ...e ?? {},
243
245
  isTouched: !0,
244
246
  isBlurred: !0
245
247
  }));
246
248
  },
247
249
  error: r,
248
- serverError: D[e],
250
+ serverError: k[e],
249
251
  touched: n?.isTouched === !0,
250
252
  blurred: n?.isBlurred === !0,
251
253
  dirty: n?.isDirty === !0,
@@ -263,46 +265,46 @@ var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), ie
263
265
  }
264
266
  };
265
267
  }, [
268
+ b,
269
+ q,
270
+ R,
266
271
  y,
267
- K,
268
- I,
269
- g,
270
- D,
271
- W
272
- ]), J = p(void 0);
273
- J.current === void 0 && (J.current = ae(F.store, q));
274
- let ye = J.current;
272
+ k,
273
+ G
274
+ ]), Y = h(void 0);
275
+ Y.current === void 0 && (Y.current = oe(L.store, J));
276
+ let xe = Y.current;
275
277
  te(() => {
276
- ye.refresh(q);
278
+ xe.refresh(J);
277
279
  });
278
- let be = l((e) => ({
279
- items: I.getFieldValue(e) ?? [],
280
+ let Se = d((e) => ({
281
+ items: R.getFieldValue(e) ?? [],
280
282
  push: (t) => {
281
- I.pushFieldValue(e, t);
283
+ R.pushFieldValue(e, t);
282
284
  },
283
285
  insert: (t, n) => {
284
- I.insertFieldValue(e, t, n);
286
+ R.insertFieldValue(e, t, n);
285
287
  },
286
288
  remove: (t) => {
287
- I.removeFieldValue(e, t);
289
+ R.removeFieldValue(e, t);
288
290
  },
289
291
  move: (t, n) => {
290
- I.moveFieldValues(e, t, n);
292
+ R.moveFieldValues(e, t, n);
291
293
  },
292
294
  swap: (t, n) => {
293
- I.swapFieldValues(e, t, n);
295
+ R.swapFieldValues(e, t, n);
294
296
  },
295
- field: (t, n) => q(`${e}.${t}.${n}`)
296
- }), [I, q]), xe = l((e) => h.filter((t) => t.section === e), [h]), Se = l((e, t) => {
297
- K(e), !Object.is(I.getFieldValue(e), t) && I.setFieldValue(e, t);
298
- }, [K, I]), Ce = l((e) => {
299
- for (let [t, n] of Object.entries(e)) I.setFieldValue(t, n);
300
- }, [I]), we = l((e) => {
301
- O({}), k(void 0), A(void 0), j.current = void 0, M.current = !1, e === void 0 ? I.reset() : I.reset(P(e));
302
- }, [I, P]), Te = n.asyncTimeoutMs ?? 5e3, Ee = l(async () => {
297
+ field: (t, n) => J(`${e}.${t}.${n}`)
298
+ }), [R, J]), Ce = d((e) => _.filter((t) => t.section === e), [_]), we = d((e, t) => {
299
+ q(e), !Object.is(R.getFieldValue(e), t) && R.setFieldValue(e, t);
300
+ }, [q, R]), Te = d((e) => {
301
+ for (let [t, n] of Object.entries(e)) R.setFieldValue(t, n);
302
+ }, [R]), Ee = d((e) => {
303
+ A({}), j(void 0), M(void 0), N.current = void 0, P.current = !1, e === void 0 ? R.reset() : R.reset(I(e));
304
+ }, [R, I]), De = n.asyncTimeoutMs ?? 5e3, Oe = d(async () => {
303
305
  let e = Date.now();
304
306
  for (;;) {
305
- let t = S.current;
307
+ let t = w.current;
306
308
  if (t === void 0) return;
307
309
  let n = Object.entries(t), r;
308
310
  for (let e of n) e[1].status === "checking" && (r ??= []).push(e);
@@ -316,75 +318,75 @@ var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), ie
316
318
  for (let [e, n] of t) r[e] = n.message ?? i({
317
319
  id: "validation.invalid",
318
320
  fallback: "Invalid value"
319
- }, T.current);
321
+ }, D.current);
320
322
  return r;
321
323
  }
322
- if (Date.now() - e > Te) {
324
+ if (Date.now() - e > De) {
323
325
  let e = Object.fromEntries(r);
324
326
  for (let [t] of r) e[t] = i({
325
327
  id: "validation.checking",
326
328
  fallback: "Still checking…"
327
- }, T.current);
329
+ }, D.current);
328
330
  return e;
329
331
  }
330
332
  await new Promise((e) => setTimeout(e, 50));
331
333
  }
332
- }, [Te]), Y = l(() => {
334
+ }, [De]), X = d(() => {
333
335
  let e = globalThis.document;
334
336
  if (e?.getElementById === void 0) return;
335
- let t = ce(h, D);
336
- for (let n of t) if (W(n) !== void 0) {
337
- e.getElementById(y(n))?.focus?.();
337
+ let t = le(_, k);
338
+ for (let n of t) if (G(n) !== void 0) {
339
+ e.getElementById(b(n))?.focus?.();
338
340
  return;
339
341
  }
340
342
  }, [
341
- y,
342
- h,
343
- D,
344
- W
345
- ]), X = p(Y);
346
- X.current = Y;
347
- let De = l(async () => {
348
- k(void 0), O({}), A(void 0), j.current = void 0, M.current = !1;
343
+ b,
344
+ _,
345
+ k,
346
+ G
347
+ ]), Z = h(X);
348
+ Z.current = X;
349
+ let ke = d(async () => {
350
+ j(void 0), A({}), M(void 0), N.current = void 0, P.current = !1;
349
351
  let e, t = !1;
350
- if (await I.handleSubmit().catch((n) => {
352
+ if (await R.handleSubmit().catch((n) => {
351
353
  t = !0, e = n;
352
354
  }), t) throw e;
353
- return M.current || queueMicrotask(() => {
354
- X.current();
355
- }), j.current;
356
- }, [I]);
357
- pe.current = (async (e) => {
358
- let t = C.current, n = e, r = n;
355
+ return P.current || queueMicrotask(() => {
356
+ Z.current();
357
+ }), N.current;
358
+ }, [R]);
359
+ me.current = (async (e) => {
360
+ let t = T.current, n = e, r = n;
359
361
  if (t.toInput !== void 0) try {
360
362
  r = t.toInput(n);
361
363
  } catch (e) {
362
- k(e instanceof Error ? e.message : String(e));
364
+ j(e instanceof Error ? e.message : String(e));
363
365
  return;
364
366
  }
365
- if (N(n).length > 0) {
367
+ if (F(n).length > 0) {
366
368
  queueMicrotask(() => {
367
- X.current();
369
+ Z.current();
368
370
  });
369
371
  return;
370
372
  }
371
- let o = E.current;
373
+ let o = O.current;
372
374
  if (o !== void 0) {
373
375
  let e = a(o, r);
374
376
  e.dropped.length > 0 && process.env.NODE_ENV !== "production" && console.warn(`[@voltro/client] useFormBinding: dropped ${e.dropped.length} value(s) the mutation's input does not declare (${e.dropped.join(", ")}). The server refuses undeclared fields, so they are not sent. Map them with \`toInput\` if they belong in the write; ignore this if they are form-only state.`), r = e.input;
375
377
  }
376
- let s = await Ee();
378
+ let s = await Oe();
377
379
  if (s !== void 0) {
378
- O((e) => ({
380
+ A((e) => ({
379
381
  ...e,
380
382
  ...s
381
383
  })), queueMicrotask(() => {
382
- X.current();
384
+ Z.current();
383
385
  });
384
386
  return;
385
387
  }
386
388
  let c = (e) => {
387
- let t = w.current;
389
+ let t = E.current;
388
390
  return t === void 0 ? Promise.reject(/* @__PURE__ */ Error("A schema form submits through its onSubmit callback")) : t.mutate(e);
389
391
  };
390
392
  try {
@@ -393,11 +395,11 @@ var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), ie
393
395
  values: n,
394
396
  mutate: c
395
397
  });
396
- j.current = e, M.current = !0, t.onSuccess?.(e);
398
+ N.current = e, P.current = !0, t.onSuccess?.(e);
397
399
  } catch (e) {
398
- let t = _(e);
400
+ let t = re(e);
399
401
  if (t.length === 0) {
400
- A(e), C.current.onError?.(e);
402
+ M(e), T.current.onError?.(e);
401
403
  return;
402
404
  }
403
405
  let n = {};
@@ -405,72 +407,72 @@ var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), ie
405
407
  id: e.message,
406
408
  ...e.params === void 0 ? {} : { params: e.params },
407
409
  fallback: e.message
408
- }, T.current));
409
- O((e) => ({
410
+ }, D.current));
411
+ A((e) => ({
410
412
  ...e,
411
413
  ...n
412
414
  })), queueMicrotask(() => {
413
- X.current();
415
+ Z.current();
414
416
  });
415
417
  }
416
418
  });
417
- let Z = z.length === 0, Oe = Object.values(S.current ?? {}).some((e) => e.status === "checking"), Q = fe ?? d?.error, ke = Q !== void 0 && _(Q).length > 0 ? void 0 : Q, Ae = Object.keys(G).length, je = (() => {
418
- for (let e of h) if (G[e.name] !== void 0) return e.name;
419
- let e = Object.keys(G);
419
+ let Q = V.length === 0, Ae = Object.values(w.current ?? {}).some((e) => e.status === "checking"), $ = pe ?? p?.error, je = $ !== void 0 && re($).length > 0 ? void 0 : $, Me = Object.keys(K).length, Ne = (() => {
420
+ for (let e of _) if (K[e.name] !== void 0) return e.name;
421
+ let e = Object.keys(K);
420
422
  return e.length > 0 ? e[0] : void 0;
421
- })(), Me = {
422
- isDirty: !H && R.isDirty,
423
- isPristine: R.isPristine,
424
- isTouched: R.isTouched,
425
- isValid: Z,
426
- isValidating: Oe,
427
- canSubmit: Z && !Oe && !R.isSubmitting && !H,
428
- isSubmitting: R.isSubmitting,
429
- isSubmitted: R.isSubmitted,
430
- isSubmitSuccessful: R.isSubmitSuccessful && M.current,
431
- submissionAttempts: R.submissionAttempts,
432
- errorCount: Ae,
433
- firstInvalidPath: je,
434
- pending: d?.pending ?? R.isSubmitting,
435
- isLoading: H,
436
- submitError: ke,
437
- data: d?.data ?? j.current
438
- }, $ = {
439
- fields: h,
440
- values: L,
441
- errors: G,
442
- issues: z,
443
- isValid: Z,
444
- pending: d?.pending ?? R.isSubmitting,
445
- submitError: ke,
446
- formError: de,
447
- data: d?.data ?? j.current,
448
- setValue: Se,
449
- setValues: Ce,
450
- reset: we,
451
- submit: De,
452
- field: q,
453
- array: be,
454
- section: xe,
455
- state: Me,
456
- focusFirstInvalid: Y
423
+ })(), Pe = {
424
+ isDirty: !U && B.isDirty,
425
+ isPristine: B.isPristine,
426
+ isTouched: B.isTouched,
427
+ isValid: Q,
428
+ isValidating: Ae,
429
+ canSubmit: Q && !Ae && !B.isSubmitting && !U,
430
+ isSubmitting: B.isSubmitting,
431
+ isSubmitted: B.isSubmitted,
432
+ isSubmitSuccessful: B.isSubmitSuccessful && P.current,
433
+ submissionAttempts: B.submissionAttempts,
434
+ errorCount: Me,
435
+ firstInvalidPath: Ne,
436
+ pending: p?.pending ?? B.isSubmitting,
437
+ isLoading: U,
438
+ submitError: je,
439
+ data: p?.data ?? N.current
440
+ }, Fe = {
441
+ fields: _,
442
+ values: z,
443
+ errors: K,
444
+ issues: V,
445
+ isValid: Q,
446
+ pending: p?.pending ?? B.isSubmitting,
447
+ submitError: je,
448
+ formError: fe,
449
+ data: p?.data ?? N.current,
450
+ setValue: we,
451
+ setValues: Te,
452
+ reset: Ee,
453
+ submit: ke,
454
+ field: J,
455
+ array: Se,
456
+ section: Ce,
457
+ state: Pe,
458
+ focusFirstInvalid: X
457
459
  };
458
- return Object.defineProperty($, v, {
460
+ return Object.defineProperty(Fe, v, {
459
461
  value: {
460
- store: F.store,
461
- field: q,
462
- channel: ye
462
+ store: L.store,
463
+ field: J,
464
+ channel: xe
463
465
  },
464
466
  enumerable: !1
465
- }), $;
466
- }, w = (e) => {
467
+ }), Fe;
468
+ }, T = (e) => {
467
469
  let t = e.binding[v];
468
- return c(b.Provider, { value: e.binding }, c(y.Provider, { value: t?.channel }, e.children));
469
- }, T = () => u(b);
470
- function E(e, t) {
471
- let n = u(y), r = typeof e == "string" ? void 0 : e, i = typeof e == "string" ? e : t, a = r?.[v], o = r === void 0 ? n : a?.channel;
470
+ return u(x.Provider, { value: e.binding }, u(y.Provider, { value: t?.channel }, e.children));
471
+ }, E = () => f(x);
472
+ function D(e, t) {
473
+ let n = f(y), r = typeof e == "string" ? void 0 : e, i = typeof e == "string" ? e : t, a = r?.[v], o = r === void 0 ? n : a?.channel;
472
474
  if (o === void 0) throw Error(r === void 0 ? "useFormField(path) found no form binding — mount <FormBindingProvider binding={form}> above this field, or call useFormField(form, path)." : "useFormField: not a useFormBinding result");
473
- return h(l((e) => o.subscribe(i, e), [o, i]), l(() => o.snapshot(i), [o, i]), l(() => o.snapshot(i), [o, i]));
475
+ return ne(d((e) => o.subscribe(i, e), [o, i]), d(() => o.snapshot(i), [o, i]), d(() => o.snapshot(i), [o, i]));
474
476
  }
475
477
  //#endregion
476
- export { w as FormBindingProvider, x as useFormBinding, T as useFormBindingContext, E as useFormField, S as useSchemaFormBinding };
478
+ export { T as FormBindingProvider, S as useFormBinding, E as useFormBindingContext, D as useFormField, C as useSchemaFormBinding };