@macrulez/vue-form-schema 0.1.9 → 0.2.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 (82) hide show
  1. package/README.md +461 -180
  2. package/dist/MaskEngine-BEXwX4BK.js +144 -0
  3. package/dist/MaskEngine-CPr-fSPy.cjs +1 -0
  4. package/dist/ValidationEngine-BC4U1ef1.js +135 -0
  5. package/dist/ValidationEngine-Diz-qTFs.cjs +1 -0
  6. package/dist/_plugin-vue_export-helper-BHFhmbuH.cjs +1 -0
  7. package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
  8. package/dist/core/ConditionEvaluator.d.ts.map +1 -1
  9. package/dist/core/MaskEngine.d.ts.map +1 -1
  10. package/dist/core/ValidationEngine.d.ts +7 -0
  11. package/dist/core/ValidationEngine.d.ts.map +1 -1
  12. package/dist/core/formRegistry.d.ts +33 -0
  13. package/dist/core/formRegistry.d.ts.map +1 -0
  14. package/dist/core/inferTypes.d.ts.map +1 -1
  15. package/dist/core/schemaUtils.d.ts +38 -0
  16. package/dist/core/schemaUtils.d.ts.map +1 -1
  17. package/dist/core/serverErrors.d.ts +69 -0
  18. package/dist/core/serverErrors.d.ts.map +1 -0
  19. package/dist/core/types.d.ts +12 -0
  20. package/dist/core/types.d.ts.map +1 -1
  21. package/dist/core/useForm.d.ts +4 -1
  22. package/dist/core/useForm.d.ts.map +1 -1
  23. package/dist/core/useMultiStepForm.d.ts.map +1 -1
  24. package/dist/devtools/index.d.ts +26 -0
  25. package/dist/devtools/index.d.ts.map +1 -0
  26. package/dist/devtools.cjs +1 -0
  27. package/dist/devtools.d.ts +6 -0
  28. package/dist/devtools.js +93 -0
  29. package/dist/formRegistry-Bv1eaWQ-.js +31 -0
  30. package/dist/formRegistry-DaDmXyYY.cjs +1 -0
  31. package/dist/index.cjs +1 -1
  32. package/dist/index.d.ts +4 -2
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +393 -368
  35. package/dist/openapi.cjs +1 -0
  36. package/dist/openapi.d.ts +202 -0
  37. package/dist/openapi.js +118 -0
  38. package/dist/parsers/json.d.ts.map +1 -1
  39. package/dist/parsers/openapi.d.ts +139 -0
  40. package/dist/parsers/openapi.d.ts.map +1 -0
  41. package/dist/parsers/valibot.d.ts +13 -4
  42. package/dist/parsers/valibot.d.ts.map +1 -1
  43. package/dist/parsers/yup.d.ts +10 -4
  44. package/dist/parsers/yup.d.ts.map +1 -1
  45. package/dist/parsers/zod.d.ts +18 -4
  46. package/dist/parsers/zod.d.ts.map +1 -1
  47. package/dist/schemaUtils-Cc7CwGXB.cjs +1 -0
  48. package/dist/schemaUtils-Cvlsk24U.js +337 -0
  49. package/dist/style.css +1 -0
  50. package/dist/ui/naive/index.d.ts +11 -0
  51. package/dist/ui/naive/index.d.ts.map +1 -0
  52. package/dist/ui/primevue/index.d.ts +11 -0
  53. package/dist/ui/primevue/index.d.ts.map +1 -0
  54. package/dist/ui/shadcn/index.d.ts +11 -0
  55. package/dist/ui/shadcn/index.d.ts.map +1 -0
  56. package/dist/ui-naive.cjs +1 -0
  57. package/dist/ui-naive.d.ts +411 -0
  58. package/dist/ui-naive.js +667 -0
  59. package/dist/ui-primevue.cjs +1 -0
  60. package/dist/ui-primevue.d.ts +411 -0
  61. package/dist/ui-primevue.js +651 -0
  62. package/dist/ui-shadcn.cjs +1 -0
  63. package/dist/ui-shadcn.d.ts +411 -0
  64. package/dist/ui-shadcn.js +650 -0
  65. package/dist/ui-tailwind.cjs +1 -1
  66. package/dist/ui-tailwind.d.ts +14 -0
  67. package/dist/ui-tailwind.js +180 -161
  68. package/dist/ui.cjs +1 -1
  69. package/dist/ui.d.ts +14 -0
  70. package/dist/ui.js +130 -131
  71. package/dist/valibot.cjs +1 -1
  72. package/dist/valibot.d.ts +25 -2
  73. package/dist/valibot.js +47 -20
  74. package/dist/yup.cjs +1 -1
  75. package/dist/yup.d.ts +23 -3
  76. package/dist/yup.js +16 -15
  77. package/dist/zod.cjs +1 -1
  78. package/dist/zod.d.ts +31 -3
  79. package/dist/zod.js +58 -28
  80. package/package.json +66 -6
  81. package/dist/MaskEngine-DAKSNIHQ.cjs +0 -1
  82. package/dist/MaskEngine-mLoXKd4d.js +0 -251
package/dist/index.js CHANGED
@@ -1,476 +1,501 @@
1
- import { h as g, o as C, u as q, e as $, p as ee, m as te, j as ne, i as se, k as ae, n as T, V as oe } from "./MaskEngine-mLoXKd4d.js";
2
- import { a as xe, b as Le, c as je, f as Je, d as Pe, g as Be, l as De, r as He, s as Me, q as qe, t as $e } from "./MaskEngine-mLoXKd4d.js";
3
- import { computed as v, watchEffect as ie, ref as S, onMounted as le, watch as j, onUnmounted as re } from "vue";
4
- function ge(n) {
5
- const s = v(() => n.touched && n.error.length > 0), t = v(() => s.value ? n.error[0] : null), e = v(() => n.touched ? n.error : []), i = v(() => n.field.required ?? !1), c = v(
6
- () => typeof n.field.disabled == "boolean" ? n.field.disabled : !1
1
+ import { a as Be, b as Ue, c as He, p as Ge, r as Qe, u as We, d as Xe } from "./MaskEngine-BEXwX4BK.js";
2
+ import { computed as d, getCurrentInstance as fe, ref as j, onMounted as de, watch as I, onUnmounted as ve } from "vue";
3
+ import { u as Q, e as W, p as me, m as ye, d as pe, c as ge, h as he, r as X, g as V, V as be, i as N } from "./ValidationEngine-BC4U1ef1.js";
4
+ import { f as Ze, a as et, b as tt, s as nt } from "./ValidationEngine-BC4U1ef1.js";
5
+ import { C as Fe } from "./schemaUtils-Cvlsk24U.js";
6
+ import { d as st, e as ot, a as at, m as it, o as lt, p as ut } from "./schemaUtils-Cvlsk24U.js";
7
+ import { u as Ee, r as Oe, e as A } from "./formRegistry-Bv1eaWQ-.js";
8
+ function ze(e) {
9
+ const r = d(() => e.touched && e.error.length > 0), t = d(() => r.value ? e.error[0] : null), n = d(() => e.touched ? e.error : []), o = d(() => e.field.required ?? !1), c = d(
10
+ () => typeof e.field.disabled == "boolean" ? e.field.disabled : !1
7
11
  );
8
- return { hasError: s, errorMessage: t, allErrors: e, isRequired: i, isDisabled: c };
12
+ return { hasError: r, errorMessage: t, allErrors: n, isRequired: o, isDisabled: c };
9
13
  }
10
- const ue = /^[\w\s\d.'"[\]()!<>=&|?:+\-*/%]+$/;
11
- function ce(n, s) {
12
- if (!ue.test(n))
13
- return console.warn(`[vue-form-schema] Blocked unsafe expression: "${n}"`), !0;
14
- try {
15
- return !!new Function("values", `"use strict"; return (${n})`)(s);
16
- } catch {
17
- return !0;
18
- }
19
- }
20
- class I {
21
- constructor() {
22
- this.stopHandle = null;
23
- }
24
- /**
25
- * Start reactively watching values and writing evaluated fields into
26
- * `resolvedFields`. Also handles clearOnHide side effect.
27
- */
28
- start(s, t, e, i) {
29
- this.stopHandle = ie(() => {
30
- const c = t.value, u = e.value, f = this.evaluateFields(s, c);
31
- i && this.clearHiddenValues(s, f, c, t, u), e.value = f;
32
- });
33
- }
34
- stop() {
35
- var s;
36
- (s = this.stopHandle) == null || s.call(this), this.stopHandle = null;
37
- }
38
- /** Recursively evaluate visible/disabled/options for each field */
39
- evaluateFields(s, t) {
40
- return s.map((e) => {
41
- const i = this.resolveBoolean(e.visible, t, !0), c = this.resolveBoolean(e.disabled, t, !1);
42
- let u;
43
- if (typeof e.options == "function") {
44
- const m = e.options(t);
45
- u = m instanceof Promise ? void 0 : m;
46
- } else
47
- u = e.options;
48
- return {
49
- ...e,
50
- visible: i,
51
- disabled: c,
52
- options: u,
53
- fields: e.fields ? this.evaluateFields(e.fields, t) : void 0
54
- };
55
- });
56
- }
57
- resolveBoolean(s, t, e) {
58
- return s === void 0 ? e : typeof s == "boolean" ? s : typeof s == "function" ? s(t) : typeof s == "string" ? ce(s, t) : e;
59
- }
60
- clearHiddenValues(s, t, e, i, c) {
61
- for (let u = 0; u < s.length; u++) {
62
- const f = s[u], m = t[u], O = this.wasVisible(c, f.name), p = m.visible;
63
- if (O && !p) {
64
- const y = g(e, f.name), V = f.defaultValue ?? null;
65
- y !== V && (i.value = C(i.value, f.name, V));
66
- }
67
- f.fields && m.fields && this.clearHiddenValues(f.fields, m.fields, e, i, c);
68
- }
69
- }
70
- wasVisible(s, t) {
71
- const e = s.find((i) => i.name === t);
72
- return e ? e.visible !== !1 : !0;
73
- }
74
- }
75
- function be(n, s) {
76
- return new I().evaluateFields(n, s);
77
- }
78
- function fe(n, s, t) {
79
- switch (n) {
14
+ function Se(e, r, t) {
15
+ switch (e) {
80
16
  case "required":
81
- return t ? (e, i) => T(e) ? t : null : T;
17
+ return t ? (n, o) => X(n) ? t : null : X;
82
18
  case "minLength":
83
- return ae(Number(s), t);
19
+ return he(Number(r), t);
84
20
  case "maxLength":
85
- return se(Number(s), t);
21
+ return ge(Number(r), t);
86
22
  case "min":
87
- return ne(Number(s), t);
23
+ return pe(Number(r), t);
88
24
  case "max":
89
- return te(Number(s), t);
25
+ return ye(Number(r), t);
90
26
  case "pattern":
91
- return ee(new RegExp(String(s)), t);
27
+ return me(new RegExp(String(r)), t);
92
28
  case "email":
93
- return t ? (e, i) => $(e) ? t : null : $;
29
+ return t ? (n, o) => W(n) ? t : null : W;
94
30
  case "url":
95
- return t ? (e, i) => q(e) ? t : null : q;
31
+ return t ? (n, o) => Q(n) ? t : null : Q;
96
32
  default:
97
- return console.warn(`[vue-form-schema] Unknown validator rule: "${n}"`), null;
33
+ return console.warn(`[vue-form-schema] Unknown validator rule: "${e}"`), null;
98
34
  }
99
35
  }
100
- function R(n) {
101
- const s = [];
102
- for (const t of n.validators ?? []) {
103
- const e = fe(t.rule, t.value, t.message);
104
- e && s.push(e);
36
+ function Y(e) {
37
+ const r = [];
38
+ for (const t of e.validators ?? []) {
39
+ const n = Se(t.rule, t.value, t.message);
40
+ n && r.push(n);
105
41
  }
106
42
  return {
107
- type: n.type,
108
- name: n.name,
109
- label: n.label,
110
- placeholder: n.placeholder,
111
- defaultValue: n.default,
112
- required: n.required,
113
- disabled: n.disabled,
114
- visible: n.visible,
115
- mask: n.mask,
116
- options: n.options,
117
- validators: s.length ? s : void 0,
118
- fields: n.fields ? n.fields.map(R) : void 0
43
+ type: e.type,
44
+ name: e.name,
45
+ label: e.label,
46
+ placeholder: e.placeholder,
47
+ defaultValue: e.default,
48
+ required: e.required,
49
+ disabled: e.disabled,
50
+ visible: e.visible,
51
+ mask: e.mask,
52
+ options: e.options,
53
+ validators: r.length ? r : void 0,
54
+ fields: e.fields ? e.fields.map(Y) : void 0
119
55
  };
120
56
  }
121
- function de(n) {
122
- return n.map(R);
57
+ function Ae(e) {
58
+ return e.map(Y);
123
59
  }
124
- function ve(n) {
125
- if (!Array.isArray(n) || n.length === 0) return !1;
126
- for (const s of n) {
127
- const t = s.validators;
128
- if (Array.isArray(t) && t.some((e) => typeof e == "function"))
60
+ function je(e) {
61
+ if (!Array.isArray(e) || e.length === 0) return !1;
62
+ for (const r of e) {
63
+ const t = r.validators;
64
+ if (Array.isArray(t) && t.some((n) => typeof n == "function"))
129
65
  return !1;
130
66
  }
131
- return n.some((s) => {
132
- const t = s;
67
+ return e.some((r) => {
68
+ const t = r;
133
69
  if ("default" in t) return !0;
134
- const e = t.validators;
135
- return Array.isArray(e) && e.length > 0 && typeof e[0] == "object" && e[0] !== null && "rule" in e[0];
70
+ const n = t.validators;
71
+ return Array.isArray(n) && n.length > 0 && typeof n[0] == "object" && n[0] !== null && "rule" in n[0];
136
72
  });
137
73
  }
138
- function me(n) {
139
- return ve(n) ? de(n) : n;
74
+ function Ve(e) {
75
+ return je(e) ? Ae(e) : e;
140
76
  }
141
- function N(n, s = {}) {
142
- const t = {};
143
- for (const e of n)
144
- if (e.type === "group" && e.fields) {
145
- const i = N(e.fields, s);
146
- Object.assign(t, i);
147
- } else if (e.type === "array") {
148
- const i = g(s, e.name), c = typeof e.defaultValue == "function" ? void 0 : e.defaultValue;
149
- t[e.name] = i ?? c ?? [];
150
- } else if (typeof e.defaultValue != "function") {
151
- const i = g(s, e.name);
152
- t[e.name] = i !== void 0 ? i : e.defaultValue ?? null;
77
+ function R(e, r = {}) {
78
+ let t = {};
79
+ for (const n of e)
80
+ if (n.type === "group" && n.fields) {
81
+ const o = R(n.fields, r);
82
+ for (const [c, f] of Object.entries(o))
83
+ t = N(t, c, f);
84
+ } else if (n.type === "array") {
85
+ const o = V(r, n.name), c = typeof n.defaultValue == "function" ? void 0 : n.defaultValue;
86
+ t = N(t, n.name, o ?? c ?? []);
87
+ } else if (typeof n.defaultValue != "function") {
88
+ const o = V(r, n.name);
89
+ t = N(
90
+ t,
91
+ n.name,
92
+ o !== void 0 ? o : n.defaultValue ?? null
93
+ );
153
94
  }
154
- for (const e of n)
155
- if (e.type !== "group" && typeof e.defaultValue == "function") {
156
- const i = g(s, e.name);
157
- i === void 0 ? t[e.name] = e.defaultValue(t) : t[e.name] = i;
95
+ for (const n of e)
96
+ if (n.type !== "group" && typeof n.defaultValue == "function") {
97
+ const o = V(r, n.name);
98
+ t = N(
99
+ t,
100
+ n.name,
101
+ o === void 0 ? n.defaultValue(t) : o
102
+ );
158
103
  }
159
- for (const [e, i] of Object.entries(s))
160
- e in t || (t[e] = i);
104
+ for (const [n, o] of Object.entries(r))
105
+ n in t || (t = N(t, n, o));
161
106
  return t;
162
107
  }
163
- function pe(n) {
164
- var M;
108
+ function ke(e) {
109
+ var H, G;
165
110
  const {
166
- schema: s,
111
+ schema: r,
167
112
  initialValues: t = {},
168
- validateOn: e = "blur",
169
- validateMode: i = "first",
113
+ validateOn: n = "blur",
114
+ validateMode: o = "first",
170
115
  clearOnHide: c = !1,
171
- onSubmit: u,
172
- persist: f = !1,
116
+ onSubmit: f,
117
+ persist: v = !1,
173
118
  persistKey: m,
174
- debug: O = !1
175
- } = n, p = me(s), y = new oe(300, i), V = new I(), w = m ?? `vfs:${p.map((a) => a.name).join(",")}`;
176
- function E() {
177
- return typeof window > "u" || !f ? null : f === "local" ? window.localStorage : window.sessionStorage;
119
+ debug: b = !1
120
+ } = e, h = (H = fe()) == null ? void 0 : H.type, k = (h == null ? void 0 : h.__name) ?? (h == null ? void 0 : h.name), E = Ve(r), O = new be(300, o), J = new Fe();
121
+ let a = 0;
122
+ const S = m ?? `vfs:${E.map((s) => s.name).join(",")}`;
123
+ function L() {
124
+ return typeof window > "u" || !v ? null : v === "local" ? window.localStorage : window.sessionStorage;
178
125
  }
179
- const o = S(
180
- N(p, t)
181
- ), d = S({}), b = S({}), A = S(!1), h = S(p), F = S({}), k = S({}), P = /* @__PURE__ */ new Set();
182
- let x = !1;
183
- V.start(p, o, h, c ?? !1);
184
- async function B(a) {
185
- if (typeof a.options != "function") return;
186
- const l = a.options(o.value);
187
- if (l instanceof Promise) {
188
- F.value = { ...F.value, [a.name]: !0 };
126
+ const l = j(
127
+ R(E, t)
128
+ ), y = j({}), x = j({}), M = j(!1), F = j(E), w = j({}), P = j({}), K = /* @__PURE__ */ new Set();
129
+ let z = !1;
130
+ J.start(
131
+ E,
132
+ l,
133
+ F,
134
+ c ?? !1
135
+ );
136
+ async function T(s) {
137
+ if (typeof s.options != "function") return;
138
+ const i = s.options(l.value);
139
+ if (i instanceof Promise) {
140
+ w.value = { ...w.value, [s.name]: !0 };
189
141
  try {
190
- const r = await l;
191
- k.value = { ...k.value, [a.name]: r };
192
- } catch (r) {
193
- console.warn(`[vue-form-schema] Failed to load options for "${a.name}"`, r);
142
+ const u = await i;
143
+ P.value = { ...P.value, [s.name]: u };
144
+ } catch (u) {
145
+ console.warn(`[vue-form-schema] Failed to load options for "${s.name}"`, u);
194
146
  } finally {
195
- F.value = { ...F.value, [a.name]: !1 };
147
+ w.value = { ...w.value, [s.name]: !1 };
196
148
  }
197
149
  }
198
150
  }
199
- const D = p.filter((a) => typeof a.options == "function");
200
- le(async () => {
201
- const a = E();
202
- if (a)
151
+ const _ = E.filter((s) => typeof s.options == "function");
152
+ de(async () => {
153
+ const s = L();
154
+ if (s)
203
155
  try {
204
- const l = a.getItem(w);
205
- if (l) {
206
- const r = JSON.parse(l);
207
- o.value = {
208
- ...o.value,
209
- ...r
156
+ const i = s.getItem(S);
157
+ if (i) {
158
+ const u = JSON.parse(i);
159
+ l.value = {
160
+ ...l.value,
161
+ ...u
210
162
  };
211
163
  }
212
164
  } catch {
213
165
  }
214
- await Promise.all(D.map((l) => B(l)));
215
- }), f && j(
216
- o,
217
- (a) => {
218
- var l;
219
- if (!x)
166
+ await Promise.all(_.map((i) => T(i)));
167
+ }), v && I(
168
+ l,
169
+ (s) => {
170
+ var i;
171
+ if (!z)
220
172
  try {
221
- (l = E()) == null || l.setItem(w, JSON.stringify(a));
173
+ (i = L()) == null || i.setItem(S, JSON.stringify(s));
222
174
  } catch {
223
175
  }
224
176
  },
225
177
  { deep: !0 }
226
178
  );
227
- for (const a of D)
228
- (M = a.optionsDeps) != null && M.length && j(
229
- () => a.optionsDeps.map((l) => g(o.value, l)),
230
- () => B(a)
179
+ for (const s of _)
180
+ (G = s.optionsDeps) != null && G.length && I(
181
+ () => s.optionsDeps.map(
182
+ (i) => V(l.value, i)
183
+ ),
184
+ () => T(s)
231
185
  );
232
- O && j(
233
- o,
234
- (a) => {
235
- console.group("[vue-form-schema] values changed"), console.log("values:", JSON.parse(JSON.stringify(a))), console.log("errors:", d.value), console.log("touched:", b.value), console.groupEnd();
186
+ b && I(
187
+ l,
188
+ (s) => {
189
+ console.group("[vue-form-schema] values changed"), console.log("values:", JSON.parse(JSON.stringify(s))), console.log("errors:", y.value), console.log("touched:", x.value), console.groupEnd();
236
190
  },
237
191
  { deep: !0 }
238
192
  );
239
- const z = v(
240
- () => h.value.map((a) => ({
241
- ...a,
242
- options: k.value[a.name] ?? a.options,
243
- optionsLoading: F.value[a.name] ?? !1
193
+ const te = d(
194
+ () => F.value.map((s) => ({
195
+ ...s,
196
+ options: P.value[s.name] ?? s.options,
197
+ optionsLoading: w.value[s.name] ?? !1
244
198
  }))
245
- ), W = v(() => {
246
- const a = N(p, t);
247
- return JSON.stringify(o.value) !== JSON.stringify(a);
248
- }), X = v(() => {
249
- const a = y.validateAll(h.value, o.value);
250
- return Object.values(a).every((l) => l.length === 0);
199
+ ), ne = R(E, t), re = d(
200
+ () => !C(l.value, ne)
201
+ ), se = d(() => {
202
+ const s = O.validateAll(F.value, l.value), i = Object.values(s).every((p) => p.length === 0), u = Object.values(y.value).every((p) => p.length === 0);
203
+ return i && u;
251
204
  });
252
- function H(a) {
253
- if (a) {
254
- const l = y.validateField(
255
- a,
256
- g(o.value, a.name),
257
- o.value
205
+ function B(s) {
206
+ if (s) {
207
+ const i = O.validateField(
208
+ s,
209
+ V(l.value, s.name),
210
+ l.value
258
211
  );
259
- d.value = { ...d.value, [a.name]: l }, y.validateAsync(
260
- a,
261
- g(o.value, a.name),
262
- o.value,
263
- (r, L) => {
264
- d.value = {
265
- ...d.value,
266
- [r]: [...d.value[r] ?? [], ...L]
267
- };
212
+ y.value = { ...y.value, [s.name]: i }, O.validateAsync(
213
+ s,
214
+ V(l.value, s.name),
215
+ l.value,
216
+ (u, p) => {
217
+ y.value = {
218
+ ...y.value,
219
+ [u]: [...y.value[u] ?? [], ...p]
220
+ }, A(a, "asyncValidate", { path: u, errors: p });
268
221
  }
269
222
  );
270
223
  } else
271
- d.value = y.validateAll(
272
- h.value,
273
- o.value
224
+ y.value = O.validateAll(
225
+ F.value,
226
+ l.value
274
227
  );
275
228
  }
276
- function _(a, l) {
277
- const r = J(h.value, a), L = r != null && r.transform ? r.transform(l, o.value) : l;
278
- o.value = C(
279
- o.value,
280
- a,
281
- L
282
- ), (e === "input" || e === "eager" && P.has(a)) && r && H(r);
229
+ function oe(s, i) {
230
+ const u = $(F.value, s), p = u != null && u.transform ? u.transform(i, l.value) : i;
231
+ l.value = N(
232
+ l.value,
233
+ s,
234
+ p
235
+ ), A(a, "setField", { path: s, value: p }), (n === "input" || n === "eager" && K.has(s)) && u && B(u);
283
236
  }
284
- function G(a) {
285
- return g(o.value, a);
237
+ function ae(s) {
238
+ return V(l.value, s);
286
239
  }
287
- function Q(a) {
288
- if (b.value = { ...b.value, [a]: !0 }, P.add(a), e === "blur" || e === "eager") {
289
- const l = J(h.value, a);
290
- l && H(l);
240
+ function ie(s) {
241
+ if (x.value = { ...x.value, [s]: !0 }, K.add(s), A(a, "touch", { path: s }), n === "blur" || n === "eager") {
242
+ const i = $(F.value, s);
243
+ i && B(i);
291
244
  }
292
245
  }
293
- async function Y() {
294
- const a = {};
295
- for (const r of h.value) K(r, a);
296
- if (b.value = a, d.value = y.validateAll(
297
- h.value,
298
- o.value
299
- ), !Object.values(d.value).some((r) => r.length > 0)) {
300
- A.value = !0;
301
- try {
302
- const r = U(h.value, o.value);
303
- await (u == null ? void 0 : u(r));
304
- } finally {
305
- A.value = !1;
306
- }
246
+ async function le() {
247
+ A(a, "submit");
248
+ const s = {};
249
+ for (const g of F.value) Z(g, s);
250
+ x.value = s;
251
+ const i = O.validateAll(
252
+ F.value,
253
+ l.value
254
+ ), u = await O.validateAllAsync(
255
+ F.value,
256
+ l.value
257
+ ), p = { ...i };
258
+ for (const [g, ce] of Object.entries(u))
259
+ p[g] = [...p[g] ?? [], ...ce];
260
+ if (y.value = p, Object.values(y.value).some((g) => g.length > 0)) {
261
+ A(a, "submitError", { reason: "validation", errors: y.value });
262
+ return;
263
+ }
264
+ M.value = !0;
265
+ try {
266
+ const g = ee(F.value, l.value);
267
+ await (f == null ? void 0 : f(g)), A(a, "submitSuccess");
268
+ } catch (g) {
269
+ throw A(a, "submitError", {
270
+ reason: "exception",
271
+ error: g instanceof Error ? g.message : String(g)
272
+ }), g;
273
+ } finally {
274
+ M.value = !1;
307
275
  }
308
276
  }
309
- function Z(a) {
310
- var r;
311
- const l = a ?? t;
312
- o.value = N(
313
- p,
314
- l ?? {}
315
- ), d.value = {}, b.value = {}, A.value = !1, x = !0, (r = E()) == null || r.removeItem(w), Promise.resolve().then(() => {
316
- x = !1;
317
- });
277
+ function ue(s) {
278
+ var u;
279
+ const i = s ?? t;
280
+ l.value = R(
281
+ E,
282
+ i ?? {}
283
+ ), y.value = {}, x.value = {}, M.value = !1, z = !0, (u = L()) == null || u.removeItem(S), Promise.resolve().then(() => {
284
+ z = !1;
285
+ }), A(a, "reset");
318
286
  }
319
- return re(() => {
320
- V.stop(), y.destroy();
321
- }), {
322
- fields: z,
323
- values: o,
324
- errors: d,
325
- touched: b,
326
- optionsLoading: F,
327
- isDirty: W,
328
- isValid: X,
329
- isSubmitting: A,
330
- submit: Y,
331
- reset: Z,
332
- setField: _,
333
- getField: G,
287
+ ve(() => {
288
+ J.stop(), O.destroy(), Ee(a);
289
+ });
290
+ const U = {
291
+ fields: te,
292
+ values: l,
293
+ errors: y,
294
+ touched: x,
295
+ optionsLoading: w,
296
+ isDirty: re,
297
+ isValid: se,
298
+ isSubmitting: M,
299
+ submit: le,
300
+ reset: ue,
301
+ setField: oe,
302
+ getField: ae,
334
303
  // expose touch for FormRenderer
335
304
  // @ts-expect-error - internal
336
- touchField: Q
305
+ touchField: ie
337
306
  };
307
+ return a = Oe(U, k ?? "Form"), U;
338
308
  }
339
- function J(n, s) {
340
- for (const t of n) {
341
- if (t.name === s) return t;
309
+ function $(e, r) {
310
+ for (const t of e) {
311
+ if (t.name === r) return t;
342
312
  if (t.fields) {
343
- const e = J(t.fields, s);
344
- if (e) return e;
313
+ const n = $(t.fields, r);
314
+ if (n) return n;
345
315
  }
346
316
  }
347
317
  }
348
- function K(n, s = {}) {
349
- return s[n.name] = !0, n.fields && n.fields.forEach((t) => K(t, s)), s;
318
+ function Z(e, r = {}) {
319
+ return r[e.name] = !0, e.fields && e.fields.forEach((t) => Z(t, r)), r;
350
320
  }
351
- function U(n, s) {
352
- const t = { ...s };
353
- for (const e of n) {
354
- if (e.parse) {
355
- const i = g(t, e.name);
356
- t[e.name] = e.parse(i);
321
+ function C(e, r) {
322
+ if (e === r) return !0;
323
+ if (e instanceof File || r instanceof File) return e === r;
324
+ if (Array.isArray(e) && Array.isArray(r))
325
+ return e.length === r.length && e.every((t, n) => C(t, r[n]));
326
+ if (e && r && typeof e == "object" && typeof r == "object") {
327
+ const t = Object.keys(e), n = Object.keys(r);
328
+ return t.length === n.length && t.every(
329
+ (o) => C(e[o], r[o])
330
+ );
331
+ }
332
+ return !1;
333
+ }
334
+ function ee(e, r) {
335
+ const t = { ...r };
336
+ for (const n of e) {
337
+ if (n.parse) {
338
+ const o = V(t, n.name);
339
+ t[n.name] = n.parse(o);
357
340
  }
358
- if (e.fields) {
359
- const i = U(e.fields, t);
360
- Object.assign(t, i);
341
+ if (n.fields) {
342
+ const o = ee(n.fields, t);
343
+ Object.assign(t, o);
361
344
  }
362
345
  }
363
346
  return t;
364
347
  }
365
- function Se(n, s) {
366
- const t = n.map((o) => pe(o)), e = S(0), i = t.length, c = v(() => e.value === 0), u = v(() => e.value === i - 1), f = v(() => t[e.value]), m = v(
348
+ function Ie(e, r) {
349
+ const t = e.map((a) => ke(a)), n = j(0), o = t.length, c = d(() => n.value === 0), f = d(() => n.value === o - 1), v = d(() => t[n.value]), m = d(
367
350
  () => t.reduce(
368
- (o, d) => ({ ...o, ...d.values.value }),
351
+ (a, S) => ({ ...a, ...S.values.value }),
369
352
  {}
370
353
  )
371
- ), O = v(() => t.every((o) => o.isValid.value)), p = v(() => t.some((o) => o.isSubmitting.value));
372
- async function y() {
373
- return await t[e.value].submit(), Object.values(t[e.value].errors.value).some(
374
- (d) => d.length > 0
375
- ) ? !1 : (u.value || e.value++, !0);
354
+ ), b = d(() => t.every((a) => a.isValid.value)), h = d(() => t.some((a) => a.isSubmitting.value));
355
+ async function k() {
356
+ return await t[n.value].submit(), Object.values(t[n.value].errors.value).some((S) => S.length > 0) ? !1 : (f.value || n.value++, !0);
376
357
  }
377
- function V() {
378
- c.value || e.value--;
358
+ function E() {
359
+ c.value || n.value--;
379
360
  }
380
- function w(o) {
381
- o >= 0 && o < i && (e.value = o);
361
+ function O(a) {
362
+ a >= 0 && a < o && (n.value = a);
382
363
  }
383
- async function E() {
384
- for (const o of t)
385
- if (await o.submit(), Object.values(o.errors.value).some((b) => b.length > 0)) return;
386
- await (s == null ? void 0 : s(m.value));
364
+ async function J() {
365
+ for (const a of t)
366
+ if (await a.submit(), Object.values(a.errors.value).some((L) => L.length > 0)) return;
367
+ await (r == null ? void 0 : r(m.value));
387
368
  }
388
369
  return {
389
- currentStep: e,
390
- totalSteps: i,
370
+ currentStep: n,
371
+ totalSteps: o,
391
372
  isFirstStep: c,
392
- isLastStep: u,
393
- form: f,
373
+ isLastStep: f,
374
+ form: v,
394
375
  steps: t,
395
376
  values: m,
396
- isValid: O,
397
- isSubmitting: p,
398
- next: y,
399
- back: V,
400
- goTo: w,
401
- submit: E
377
+ isValid: b,
378
+ isSubmitting: h,
379
+ next: k,
380
+ back: E,
381
+ goTo: O,
382
+ submit: J
402
383
  };
403
384
  }
404
- function Ve(n) {
405
- return { snapshot: v(() => ({
406
- values: JSON.parse(JSON.stringify(n.values.value)),
407
- errors: n.errors.value,
408
- touched: n.touched.value,
409
- isDirty: n.isDirty.value,
410
- isValid: n.isValid.value,
411
- isSubmitting: n.isSubmitting.value,
412
- optionsLoading: n.optionsLoading.value,
413
- fields: n.fields.value.map((t) => ({
385
+ function $e(e) {
386
+ return { snapshot: d(() => ({
387
+ values: JSON.parse(JSON.stringify(e.values.value)),
388
+ errors: e.errors.value,
389
+ touched: e.touched.value,
390
+ isDirty: e.isDirty.value,
391
+ isValid: e.isValid.value,
392
+ isSubmitting: e.isSubmitting.value,
393
+ optionsLoading: e.optionsLoading.value,
394
+ fields: e.fields.value.map((t) => ({
414
395
  name: t.name,
415
396
  visible: t.visible,
416
397
  disabled: t.disabled
417
398
  }))
418
399
  })) };
419
400
  }
420
- function Fe(...n) {
421
- const s = /* @__PURE__ */ new Map();
422
- for (const t of n)
423
- for (const e of t)
424
- s.set(e.name, e);
425
- return Array.from(s.values());
401
+ function D(e) {
402
+ return e !== null && typeof e == "object" && !Array.isArray(e) ? e : void 0;
403
+ }
404
+ function q(e) {
405
+ return Array.isArray(e) ? e.filter((r) => typeof r == "string") : typeof e == "string" ? [e] : [];
426
406
  }
427
- function Oe(n, s) {
428
- const t = new Set(s);
429
- return n.filter((e) => !t.has(e.name));
407
+ function xe(e) {
408
+ const r = D(e), t = D(r == null ? void 0 : r.errors) ?? {}, n = {};
409
+ for (const [o, c] of Object.entries(t))
410
+ n[o] = q(c);
411
+ return { fieldErrors: n, formErrors: [] };
430
412
  }
431
- function we(n, s) {
432
- const t = new Set(s);
433
- return n.filter((e) => t.has(e.name));
413
+ function we(e) {
414
+ const r = {}, t = [];
415
+ function n(c, f) {
416
+ for (const [v, m] of Object.entries(c)) {
417
+ if (v === "non_field_errors" || v === "detail") {
418
+ t.push(...q(m));
419
+ continue;
420
+ }
421
+ const b = f ? `${f}.${v}` : v, h = D(m);
422
+ if (h)
423
+ n(h, b);
424
+ else {
425
+ const k = q(m);
426
+ k.length && (r[b] = k);
427
+ }
428
+ }
429
+ }
430
+ const o = D(e);
431
+ return o && n(o, ""), { fieldErrors: r, formErrors: t };
434
432
  }
435
- function Ee(n, s, t) {
436
- return n.map((e) => e.name === s ? { ...e, ...t } : e);
433
+ function Ne(e) {
434
+ const r = D(e) ?? {}, t = {};
435
+ for (const [n, o] of Object.entries(r)) {
436
+ const c = q(o);
437
+ c.length && (t[n] = c);
438
+ }
439
+ return { fieldErrors: t, formErrors: [] };
440
+ }
441
+ const Le = {
442
+ laravel: xe,
443
+ drf: we,
444
+ flat: Ne
445
+ };
446
+ function De(e, r = "flat") {
447
+ return typeof r == "function" ? r(e) : Le[r](e);
448
+ }
449
+ function Ce(e, r, t = {}) {
450
+ const { format: n = "flat", touch: o = !0, merge: c = !0 } = t, f = De(r, n), v = c ? { ...e.errors.value } : {};
451
+ for (const [m, b] of Object.entries(f.fieldErrors))
452
+ v[m] = b;
453
+ if (e.errors.value = v, o) {
454
+ const m = { ...e.touched.value };
455
+ for (const b of Object.keys(f.fieldErrors)) m[b] = !0;
456
+ e.touched.value = m;
457
+ }
458
+ return f;
437
459
  }
438
- function Ae(n) {
439
- return n;
460
+ function Ke(e) {
461
+ return e;
440
462
  }
441
463
  export {
442
- I as ConditionEvaluator,
443
- oe as ValidationEngine,
444
- xe as applyMask,
445
- Le as bindMask,
446
- je as createFormRegistry,
447
- Ae as defineSchema,
448
- $ as email,
449
- be as evaluateFieldConditions,
450
- Ee as extendField,
451
- Je as fileCount,
452
- Pe as fileSize,
453
- Be as fileType,
454
- g as getByPath,
455
- te as max,
456
- se as maxLength,
457
- Fe as mergeSchemas,
458
- ne as min,
459
- ae as minLength,
460
- Oe as omitFields,
461
- de as parseJSON,
462
- ee as pattern,
463
- we as pickFields,
464
- De as provideRegistry,
465
- He as removeMask,
466
- T as required,
467
- Me as sameAs,
468
- C as setByPath,
469
- q as url,
470
- qe as useFieldArray,
471
- pe as useForm,
472
- Ve as useFormDebug,
473
- ge as useFormField,
474
- Se as useMultiStepForm,
475
- $e as useRegistry
464
+ Fe as ConditionEvaluator,
465
+ be as ValidationEngine,
466
+ Be as applyMask,
467
+ Ce as applyServerErrors,
468
+ Ue as bindMask,
469
+ He as createFormRegistry,
470
+ Ke as defineSchema,
471
+ st as discriminatedFields,
472
+ W as email,
473
+ ot as evaluateFieldConditions,
474
+ at as extendField,
475
+ Ze as fileCount,
476
+ et as fileSize,
477
+ tt as fileType,
478
+ V as getByPath,
479
+ ye as max,
480
+ ge as maxLength,
481
+ it as mergeSchemas,
482
+ pe as min,
483
+ he as minLength,
484
+ De as normalizeServerErrors,
485
+ lt as omitFields,
486
+ Ae as parseJSON,
487
+ me as pattern,
488
+ ut as pickFields,
489
+ Ge as provideRegistry,
490
+ Qe as removeMask,
491
+ X as required,
492
+ nt as sameAs,
493
+ N as setByPath,
494
+ Q as url,
495
+ We as useFieldArray,
496
+ ke as useForm,
497
+ $e as useFormDebug,
498
+ ze as useFormField,
499
+ Ie as useMultiStepForm,
500
+ Xe as useRegistry
476
501
  };