@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.
- package/README.md +461 -180
- package/dist/MaskEngine-BEXwX4BK.js +144 -0
- package/dist/MaskEngine-CPr-fSPy.cjs +1 -0
- package/dist/ValidationEngine-BC4U1ef1.js +135 -0
- package/dist/ValidationEngine-Diz-qTFs.cjs +1 -0
- package/dist/_plugin-vue_export-helper-BHFhmbuH.cjs +1 -0
- package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
- package/dist/core/ConditionEvaluator.d.ts.map +1 -1
- package/dist/core/MaskEngine.d.ts.map +1 -1
- package/dist/core/ValidationEngine.d.ts +7 -0
- package/dist/core/ValidationEngine.d.ts.map +1 -1
- package/dist/core/formRegistry.d.ts +33 -0
- package/dist/core/formRegistry.d.ts.map +1 -0
- package/dist/core/inferTypes.d.ts.map +1 -1
- package/dist/core/schemaUtils.d.ts +38 -0
- package/dist/core/schemaUtils.d.ts.map +1 -1
- package/dist/core/serverErrors.d.ts +69 -0
- package/dist/core/serverErrors.d.ts.map +1 -0
- package/dist/core/types.d.ts +12 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/useForm.d.ts +4 -1
- package/dist/core/useForm.d.ts.map +1 -1
- package/dist/core/useMultiStepForm.d.ts.map +1 -1
- package/dist/devtools/index.d.ts +26 -0
- package/dist/devtools/index.d.ts.map +1 -0
- package/dist/devtools.cjs +1 -0
- package/dist/devtools.d.ts +6 -0
- package/dist/devtools.js +93 -0
- package/dist/formRegistry-Bv1eaWQ-.js +31 -0
- package/dist/formRegistry-DaDmXyYY.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +393 -368
- package/dist/openapi.cjs +1 -0
- package/dist/openapi.d.ts +202 -0
- package/dist/openapi.js +118 -0
- package/dist/parsers/json.d.ts.map +1 -1
- package/dist/parsers/openapi.d.ts +139 -0
- package/dist/parsers/openapi.d.ts.map +1 -0
- package/dist/parsers/valibot.d.ts +13 -4
- package/dist/parsers/valibot.d.ts.map +1 -1
- package/dist/parsers/yup.d.ts +10 -4
- package/dist/parsers/yup.d.ts.map +1 -1
- package/dist/parsers/zod.d.ts +18 -4
- package/dist/parsers/zod.d.ts.map +1 -1
- package/dist/schemaUtils-Cc7CwGXB.cjs +1 -0
- package/dist/schemaUtils-Cvlsk24U.js +337 -0
- package/dist/style.css +1 -0
- package/dist/ui/naive/index.d.ts +11 -0
- package/dist/ui/naive/index.d.ts.map +1 -0
- package/dist/ui/primevue/index.d.ts +11 -0
- package/dist/ui/primevue/index.d.ts.map +1 -0
- package/dist/ui/shadcn/index.d.ts +11 -0
- package/dist/ui/shadcn/index.d.ts.map +1 -0
- package/dist/ui-naive.cjs +1 -0
- package/dist/ui-naive.d.ts +411 -0
- package/dist/ui-naive.js +667 -0
- package/dist/ui-primevue.cjs +1 -0
- package/dist/ui-primevue.d.ts +411 -0
- package/dist/ui-primevue.js +651 -0
- package/dist/ui-shadcn.cjs +1 -0
- package/dist/ui-shadcn.d.ts +411 -0
- package/dist/ui-shadcn.js +650 -0
- package/dist/ui-tailwind.cjs +1 -1
- package/dist/ui-tailwind.d.ts +14 -0
- package/dist/ui-tailwind.js +180 -161
- package/dist/ui.cjs +1 -1
- package/dist/ui.d.ts +14 -0
- package/dist/ui.js +130 -131
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.d.ts +25 -2
- package/dist/valibot.js +47 -20
- package/dist/yup.cjs +1 -1
- package/dist/yup.d.ts +23 -3
- package/dist/yup.js +16 -15
- package/dist/zod.cjs +1 -1
- package/dist/zod.d.ts +31 -3
- package/dist/zod.js +58 -28
- package/package.json +66 -6
- package/dist/MaskEngine-DAKSNIHQ.cjs +0 -1
- package/dist/MaskEngine-mLoXKd4d.js +0 -251
package/dist/index.js
CHANGED
|
@@ -1,476 +1,501 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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:
|
|
12
|
+
return { hasError: r, errorMessage: t, allErrors: n, isRequired: o, isDisabled: c };
|
|
9
13
|
}
|
|
10
|
-
|
|
11
|
-
|
|
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 ? (
|
|
17
|
+
return t ? (n, o) => X(n) ? t : null : X;
|
|
82
18
|
case "minLength":
|
|
83
|
-
return
|
|
19
|
+
return he(Number(r), t);
|
|
84
20
|
case "maxLength":
|
|
85
|
-
return
|
|
21
|
+
return ge(Number(r), t);
|
|
86
22
|
case "min":
|
|
87
|
-
return
|
|
23
|
+
return pe(Number(r), t);
|
|
88
24
|
case "max":
|
|
89
|
-
return
|
|
25
|
+
return ye(Number(r), t);
|
|
90
26
|
case "pattern":
|
|
91
|
-
return
|
|
27
|
+
return me(new RegExp(String(r)), t);
|
|
92
28
|
case "email":
|
|
93
|
-
return t ? (
|
|
29
|
+
return t ? (n, o) => W(n) ? t : null : W;
|
|
94
30
|
case "url":
|
|
95
|
-
return t ? (
|
|
31
|
+
return t ? (n, o) => Q(n) ? t : null : Q;
|
|
96
32
|
default:
|
|
97
|
-
return console.warn(`[vue-form-schema] Unknown validator rule: "${
|
|
33
|
+
return console.warn(`[vue-form-schema] Unknown validator rule: "${e}"`), null;
|
|
98
34
|
}
|
|
99
35
|
}
|
|
100
|
-
function
|
|
101
|
-
const
|
|
102
|
-
for (const t of
|
|
103
|
-
const
|
|
104
|
-
|
|
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:
|
|
108
|
-
name:
|
|
109
|
-
label:
|
|
110
|
-
placeholder:
|
|
111
|
-
defaultValue:
|
|
112
|
-
required:
|
|
113
|
-
disabled:
|
|
114
|
-
visible:
|
|
115
|
-
mask:
|
|
116
|
-
options:
|
|
117
|
-
validators:
|
|
118
|
-
fields:
|
|
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
|
|
122
|
-
return
|
|
57
|
+
function Ae(e) {
|
|
58
|
+
return e.map(Y);
|
|
123
59
|
}
|
|
124
|
-
function
|
|
125
|
-
if (!Array.isArray(
|
|
126
|
-
for (const
|
|
127
|
-
const t =
|
|
128
|
-
if (Array.isArray(t) && t.some((
|
|
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
|
|
132
|
-
const t =
|
|
67
|
+
return e.some((r) => {
|
|
68
|
+
const t = r;
|
|
133
69
|
if ("default" in t) return !0;
|
|
134
|
-
const
|
|
135
|
-
return Array.isArray(
|
|
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
|
|
139
|
-
return
|
|
74
|
+
function Ve(e) {
|
|
75
|
+
return je(e) ? Ae(e) : e;
|
|
140
76
|
}
|
|
141
|
-
function
|
|
142
|
-
|
|
143
|
-
for (const
|
|
144
|
-
if (
|
|
145
|
-
const
|
|
146
|
-
Object.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
|
155
|
-
if (
|
|
156
|
-
const
|
|
157
|
-
|
|
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 [
|
|
160
|
-
|
|
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
|
|
164
|
-
var
|
|
108
|
+
function ke(e) {
|
|
109
|
+
var H, G;
|
|
165
110
|
const {
|
|
166
|
-
schema:
|
|
111
|
+
schema: r,
|
|
167
112
|
initialValues: t = {},
|
|
168
|
-
validateOn:
|
|
169
|
-
validateMode:
|
|
113
|
+
validateOn: n = "blur",
|
|
114
|
+
validateMode: o = "first",
|
|
170
115
|
clearOnHide: c = !1,
|
|
171
|
-
onSubmit:
|
|
172
|
-
persist:
|
|
116
|
+
onSubmit: f,
|
|
117
|
+
persist: v = !1,
|
|
173
118
|
persistKey: m,
|
|
174
|
-
debug:
|
|
175
|
-
} =
|
|
176
|
-
|
|
177
|
-
|
|
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
|
|
180
|
-
|
|
181
|
-
),
|
|
182
|
-
let
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
|
191
|
-
|
|
192
|
-
} catch (
|
|
193
|
-
console.warn(`[vue-form-schema] Failed to load options for "${
|
|
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
|
-
|
|
147
|
+
w.value = { ...w.value, [s.name]: !1 };
|
|
196
148
|
}
|
|
197
149
|
}
|
|
198
150
|
}
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
if (
|
|
151
|
+
const _ = E.filter((s) => typeof s.options == "function");
|
|
152
|
+
de(async () => {
|
|
153
|
+
const s = L();
|
|
154
|
+
if (s)
|
|
203
155
|
try {
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
...
|
|
209
|
-
...
|
|
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(
|
|
215
|
-
}),
|
|
216
|
-
|
|
217
|
-
(
|
|
218
|
-
var
|
|
219
|
-
if (!
|
|
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
|
-
(
|
|
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
|
|
228
|
-
(
|
|
229
|
-
() =>
|
|
230
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
(
|
|
235
|
-
console.group("[vue-form-schema] values changed"), console.log("values:", JSON.parse(JSON.stringify(
|
|
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
|
|
240
|
-
() =>
|
|
241
|
-
...
|
|
242
|
-
options:
|
|
243
|
-
optionsLoading:
|
|
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
|
-
),
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
|
253
|
-
if (
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
(
|
|
264
|
-
|
|
265
|
-
...
|
|
266
|
-
[
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
224
|
+
y.value = O.validateAll(
|
|
225
|
+
F.value,
|
|
226
|
+
l.value
|
|
274
227
|
);
|
|
275
228
|
}
|
|
276
|
-
function
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
), (
|
|
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
|
|
285
|
-
return
|
|
237
|
+
function ae(s) {
|
|
238
|
+
return V(l.value, s);
|
|
286
239
|
}
|
|
287
|
-
function
|
|
288
|
-
if (
|
|
289
|
-
const
|
|
290
|
-
|
|
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
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
|
310
|
-
var
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
),
|
|
316
|
-
|
|
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
|
-
|
|
320
|
-
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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:
|
|
305
|
+
touchField: ie
|
|
337
306
|
};
|
|
307
|
+
return a = Oe(U, k ?? "Form"), U;
|
|
338
308
|
}
|
|
339
|
-
function
|
|
340
|
-
for (const t of
|
|
341
|
-
if (t.name ===
|
|
309
|
+
function $(e, r) {
|
|
310
|
+
for (const t of e) {
|
|
311
|
+
if (t.name === r) return t;
|
|
342
312
|
if (t.fields) {
|
|
343
|
-
const
|
|
344
|
-
if (
|
|
313
|
+
const n = $(t.fields, r);
|
|
314
|
+
if (n) return n;
|
|
345
315
|
}
|
|
346
316
|
}
|
|
347
317
|
}
|
|
348
|
-
function
|
|
349
|
-
return
|
|
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
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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 (
|
|
359
|
-
const
|
|
360
|
-
Object.assign(t,
|
|
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
|
|
366
|
-
const t =
|
|
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
|
-
(
|
|
351
|
+
(a, S) => ({ ...a, ...S.values.value }),
|
|
369
352
|
{}
|
|
370
353
|
)
|
|
371
|
-
),
|
|
372
|
-
async function
|
|
373
|
-
return await t[
|
|
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
|
|
378
|
-
c.value ||
|
|
358
|
+
function E() {
|
|
359
|
+
c.value || n.value--;
|
|
379
360
|
}
|
|
380
|
-
function
|
|
381
|
-
|
|
361
|
+
function O(a) {
|
|
362
|
+
a >= 0 && a < o && (n.value = a);
|
|
382
363
|
}
|
|
383
|
-
async function
|
|
384
|
-
for (const
|
|
385
|
-
if (await
|
|
386
|
-
await (
|
|
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:
|
|
390
|
-
totalSteps:
|
|
370
|
+
currentStep: n,
|
|
371
|
+
totalSteps: o,
|
|
391
372
|
isFirstStep: c,
|
|
392
|
-
isLastStep:
|
|
393
|
-
form:
|
|
373
|
+
isLastStep: f,
|
|
374
|
+
form: v,
|
|
394
375
|
steps: t,
|
|
395
376
|
values: m,
|
|
396
|
-
isValid:
|
|
397
|
-
isSubmitting:
|
|
398
|
-
next:
|
|
399
|
-
back:
|
|
400
|
-
goTo:
|
|
401
|
-
submit:
|
|
377
|
+
isValid: b,
|
|
378
|
+
isSubmitting: h,
|
|
379
|
+
next: k,
|
|
380
|
+
back: E,
|
|
381
|
+
goTo: O,
|
|
382
|
+
submit: J
|
|
402
383
|
};
|
|
403
384
|
}
|
|
404
|
-
function
|
|
405
|
-
return { snapshot:
|
|
406
|
-
values: JSON.parse(JSON.stringify(
|
|
407
|
-
errors:
|
|
408
|
-
touched:
|
|
409
|
-
isDirty:
|
|
410
|
-
isValid:
|
|
411
|
-
isSubmitting:
|
|
412
|
-
optionsLoading:
|
|
413
|
-
fields:
|
|
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
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
|
428
|
-
const t =
|
|
429
|
-
|
|
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(
|
|
432
|
-
const t =
|
|
433
|
-
|
|
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
|
|
436
|
-
|
|
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
|
|
439
|
-
return
|
|
460
|
+
function Ke(e) {
|
|
461
|
+
return e;
|
|
440
462
|
}
|
|
441
463
|
export {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
$e as
|
|
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
|
};
|