@macrulez/vue-form-schema 0.1.6 → 0.1.9
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/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/MaskEngine-DAKSNIHQ.cjs +1 -0
- package/dist/MaskEngine-mLoXKd4d.js +251 -0
- package/dist/core/ValidationEngine.d.ts +6 -0
- package/dist/core/ValidationEngine.d.ts.map +1 -1
- package/dist/core/types.d.ts +10 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/useForm.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +159 -151
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/tailwind/index.d.ts +11 -0
- package/dist/ui/tailwind/index.d.ts.map +1 -0
- package/dist/ui-tailwind.cjs +1 -0
- package/dist/ui-tailwind.d.ts +397 -0
- package/dist/ui-tailwind.js +650 -0
- package/dist/ui.cjs +1 -1
- package/dist/ui.d.ts +47 -10
- package/dist/ui.js +436 -300
- package/dist/valibot.d.ts +10 -2
- package/dist/yup.d.ts +10 -2
- package/dist/zod.d.ts +10 -2
- package/package.json +38 -24
- package/dist/MaskEngine-BqJQYybS.js +0 -233
- package/dist/MaskEngine-BwAs2Zb0.cjs +0 -1
- package/dist/__tests__/ConditionEvaluator.test.d.ts +0 -2
- package/dist/__tests__/ConditionEvaluator.test.d.ts.map +0 -1
- package/dist/__tests__/MaskEngine.test.d.ts +0 -2
- package/dist/__tests__/MaskEngine.test.d.ts.map +0 -1
- package/dist/__tests__/ValidationEngine.test.d.ts +0 -2
- package/dist/__tests__/ValidationEngine.test.d.ts.map +0 -1
- package/dist/__tests__/parsers.test.d.ts +0 -2
- package/dist/__tests__/parsers.test.d.ts.map +0 -1
- package/dist/__tests__/phase3.test.d.ts +0 -2
- package/dist/__tests__/phase3.test.d.ts.map +0 -1
- package/dist/__tests__/phase4.test.d.ts +0 -2
- package/dist/__tests__/phase4.test.d.ts.map +0 -1
- package/dist/__tests__/useFieldArray.test.d.ts +0 -2
- package/dist/__tests__/useFieldArray.test.d.ts.map +0 -1
- package/dist/__tests__/useForm.test.d.ts +0 -2
- package/dist/__tests__/useForm.test.d.ts.map +0 -1
- package/dist/__tests__/useMultiStepForm.test.d.ts +0 -2
- package/dist/__tests__/useMultiStepForm.test.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as xe, b as Le, c as je,
|
|
3
|
-
import { computed as v, watchEffect as
|
|
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
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 : []),
|
|
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
6
|
() => typeof n.field.disabled == "boolean" ? n.field.disabled : !1
|
|
7
7
|
);
|
|
8
|
-
return { hasError: s, errorMessage: t, allErrors: e, isRequired:
|
|
8
|
+
return { hasError: s, errorMessage: t, allErrors: e, isRequired: i, isDisabled: c };
|
|
9
9
|
}
|
|
10
10
|
const ue = /^[\w\s\d.'"[\]()!<>=&|?:+\-*/%]+$/;
|
|
11
11
|
function ce(n, s) {
|
|
@@ -17,7 +17,7 @@ function ce(n, s) {
|
|
|
17
17
|
return !0;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
class
|
|
20
|
+
class I {
|
|
21
21
|
constructor() {
|
|
22
22
|
this.stopHandle = null;
|
|
23
23
|
}
|
|
@@ -25,10 +25,10 @@ class T {
|
|
|
25
25
|
* Start reactively watching values and writing evaluated fields into
|
|
26
26
|
* `resolvedFields`. Also handles clearOnHide side effect.
|
|
27
27
|
*/
|
|
28
|
-
start(s, t, e,
|
|
29
|
-
this.stopHandle =
|
|
30
|
-
const
|
|
31
|
-
|
|
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
32
|
});
|
|
33
33
|
}
|
|
34
34
|
stop() {
|
|
@@ -38,7 +38,7 @@ class T {
|
|
|
38
38
|
/** Recursively evaluate visible/disabled/options for each field */
|
|
39
39
|
evaluateFields(s, t) {
|
|
40
40
|
return s.map((e) => {
|
|
41
|
-
const
|
|
41
|
+
const i = this.resolveBoolean(e.visible, t, !0), c = this.resolveBoolean(e.disabled, t, !1);
|
|
42
42
|
let u;
|
|
43
43
|
if (typeof e.options == "function") {
|
|
44
44
|
const m = e.options(t);
|
|
@@ -47,8 +47,8 @@ class T {
|
|
|
47
47
|
u = e.options;
|
|
48
48
|
return {
|
|
49
49
|
...e,
|
|
50
|
-
visible:
|
|
51
|
-
disabled:
|
|
50
|
+
visible: i,
|
|
51
|
+
disabled: c,
|
|
52
52
|
options: u,
|
|
53
53
|
fields: e.fields ? this.evaluateFields(e.fields, t) : void 0
|
|
54
54
|
};
|
|
@@ -57,28 +57,28 @@ class T {
|
|
|
57
57
|
resolveBoolean(s, t, e) {
|
|
58
58
|
return s === void 0 ? e : typeof s == "boolean" ? s : typeof s == "function" ? s(t) : typeof s == "string" ? ce(s, t) : e;
|
|
59
59
|
}
|
|
60
|
-
clearHiddenValues(s, t, e,
|
|
60
|
+
clearHiddenValues(s, t, e, i, c) {
|
|
61
61
|
for (let u = 0; u < s.length; u++) {
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
const
|
|
65
|
-
|
|
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
66
|
}
|
|
67
|
-
|
|
67
|
+
f.fields && m.fields && this.clearHiddenValues(f.fields, m.fields, e, i, c);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
wasVisible(s, t) {
|
|
71
|
-
const e = s.find((
|
|
71
|
+
const e = s.find((i) => i.name === t);
|
|
72
72
|
return e ? e.visible !== !1 : !0;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
function be(n, s) {
|
|
76
|
-
return new
|
|
76
|
+
return new I().evaluateFields(n, s);
|
|
77
77
|
}
|
|
78
78
|
function fe(n, s, t) {
|
|
79
79
|
switch (n) {
|
|
80
80
|
case "required":
|
|
81
|
-
return t ? (e,
|
|
81
|
+
return t ? (e, i) => T(e) ? t : null : T;
|
|
82
82
|
case "minLength":
|
|
83
83
|
return ae(Number(s), t);
|
|
84
84
|
case "maxLength":
|
|
@@ -90,14 +90,14 @@ function fe(n, s, t) {
|
|
|
90
90
|
case "pattern":
|
|
91
91
|
return ee(new RegExp(String(s)), t);
|
|
92
92
|
case "email":
|
|
93
|
-
return t ? (e,
|
|
93
|
+
return t ? (e, i) => $(e) ? t : null : $;
|
|
94
94
|
case "url":
|
|
95
|
-
return t ? (e,
|
|
95
|
+
return t ? (e, i) => q(e) ? t : null : q;
|
|
96
96
|
default:
|
|
97
97
|
return console.warn(`[vue-form-schema] Unknown validator rule: "${n}"`), null;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
function
|
|
100
|
+
function R(n) {
|
|
101
101
|
const s = [];
|
|
102
102
|
for (const t of n.validators ?? []) {
|
|
103
103
|
const e = fe(t.rule, t.value, t.message);
|
|
@@ -115,13 +115,13 @@ function C(n) {
|
|
|
115
115
|
mask: n.mask,
|
|
116
116
|
options: n.options,
|
|
117
117
|
validators: s.length ? s : void 0,
|
|
118
|
-
fields: n.fields ? n.fields.map(
|
|
118
|
+
fields: n.fields ? n.fields.map(R) : void 0
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
function ve(n) {
|
|
122
|
-
return n.map(C);
|
|
123
|
-
}
|
|
124
121
|
function de(n) {
|
|
122
|
+
return n.map(R);
|
|
123
|
+
}
|
|
124
|
+
function ve(n) {
|
|
125
125
|
if (!Array.isArray(n) || n.length === 0) return !1;
|
|
126
126
|
for (const s of n) {
|
|
127
127
|
const t = s.validators;
|
|
@@ -136,23 +136,28 @@ function de(n) {
|
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
function me(n) {
|
|
139
|
-
return
|
|
139
|
+
return ve(n) ? de(n) : n;
|
|
140
140
|
}
|
|
141
141
|
function N(n, s = {}) {
|
|
142
142
|
const t = {};
|
|
143
143
|
for (const e of n)
|
|
144
144
|
if (e.type === "group" && e.fields) {
|
|
145
|
-
const
|
|
146
|
-
Object.assign(t,
|
|
145
|
+
const i = N(e.fields, s);
|
|
146
|
+
Object.assign(t, i);
|
|
147
147
|
} else if (e.type === "array") {
|
|
148
|
-
const
|
|
149
|
-
t[e.name] =
|
|
150
|
-
} else {
|
|
151
|
-
const
|
|
152
|
-
t[e.name] =
|
|
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;
|
|
153
153
|
}
|
|
154
|
-
for (const
|
|
155
|
-
e
|
|
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;
|
|
158
|
+
}
|
|
159
|
+
for (const [e, i] of Object.entries(s))
|
|
160
|
+
e in t || (t[e] = i);
|
|
156
161
|
return t;
|
|
157
162
|
}
|
|
158
163
|
function pe(n) {
|
|
@@ -161,59 +166,59 @@ function pe(n) {
|
|
|
161
166
|
schema: s,
|
|
162
167
|
initialValues: t = {},
|
|
163
168
|
validateOn: e = "blur",
|
|
164
|
-
validateMode:
|
|
165
|
-
clearOnHide:
|
|
169
|
+
validateMode: i = "first",
|
|
170
|
+
clearOnHide: c = !1,
|
|
166
171
|
onSubmit: u,
|
|
167
|
-
persist:
|
|
172
|
+
persist: f = !1,
|
|
168
173
|
persistKey: m,
|
|
169
|
-
debug:
|
|
170
|
-
} = n, p = me(s),
|
|
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(",")}`;
|
|
171
176
|
function E() {
|
|
172
|
-
return typeof window > "u" || !
|
|
177
|
+
return typeof window > "u" || !f ? null : f === "local" ? window.localStorage : window.sessionStorage;
|
|
173
178
|
}
|
|
174
|
-
const o =
|
|
179
|
+
const o = S(
|
|
175
180
|
N(p, t)
|
|
176
|
-
),
|
|
181
|
+
), d = S({}), b = S({}), A = S(!1), h = S(p), F = S({}), k = S({}), P = /* @__PURE__ */ new Set();
|
|
177
182
|
let x = !1;
|
|
178
|
-
|
|
183
|
+
V.start(p, o, h, c ?? !1);
|
|
179
184
|
async function B(a) {
|
|
180
185
|
if (typeof a.options != "function") return;
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
183
|
-
|
|
186
|
+
const l = a.options(o.value);
|
|
187
|
+
if (l instanceof Promise) {
|
|
188
|
+
F.value = { ...F.value, [a.name]: !0 };
|
|
184
189
|
try {
|
|
185
|
-
const
|
|
186
|
-
k.value = { ...k.value, [a.name]:
|
|
187
|
-
} catch (
|
|
188
|
-
console.warn(`[vue-form-schema] Failed to load options for "${a.name}"`,
|
|
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);
|
|
189
194
|
} finally {
|
|
190
|
-
|
|
195
|
+
F.value = { ...F.value, [a.name]: !1 };
|
|
191
196
|
}
|
|
192
197
|
}
|
|
193
198
|
}
|
|
194
199
|
const D = p.filter((a) => typeof a.options == "function");
|
|
195
|
-
|
|
200
|
+
le(async () => {
|
|
196
201
|
const a = E();
|
|
197
202
|
if (a)
|
|
198
203
|
try {
|
|
199
|
-
const
|
|
200
|
-
if (
|
|
201
|
-
const
|
|
204
|
+
const l = a.getItem(w);
|
|
205
|
+
if (l) {
|
|
206
|
+
const r = JSON.parse(l);
|
|
202
207
|
o.value = {
|
|
203
208
|
...o.value,
|
|
204
|
-
...
|
|
209
|
+
...r
|
|
205
210
|
};
|
|
206
211
|
}
|
|
207
212
|
} catch {
|
|
208
213
|
}
|
|
209
|
-
await Promise.all(D.map((
|
|
210
|
-
}),
|
|
214
|
+
await Promise.all(D.map((l) => B(l)));
|
|
215
|
+
}), f && j(
|
|
211
216
|
o,
|
|
212
217
|
(a) => {
|
|
213
|
-
var
|
|
218
|
+
var l;
|
|
214
219
|
if (!x)
|
|
215
220
|
try {
|
|
216
|
-
(
|
|
221
|
+
(l = E()) == null || l.setItem(w, JSON.stringify(a));
|
|
217
222
|
} catch {
|
|
218
223
|
}
|
|
219
224
|
},
|
|
@@ -221,110 +226,110 @@ function pe(n) {
|
|
|
221
226
|
);
|
|
222
227
|
for (const a of D)
|
|
223
228
|
(M = a.optionsDeps) != null && M.length && j(
|
|
224
|
-
() => a.optionsDeps.map((
|
|
229
|
+
() => a.optionsDeps.map((l) => g(o.value, l)),
|
|
225
230
|
() => B(a)
|
|
226
231
|
);
|
|
227
|
-
|
|
232
|
+
O && j(
|
|
228
233
|
o,
|
|
229
234
|
(a) => {
|
|
230
|
-
console.group("[vue-form-schema] values changed"), console.log("values:", JSON.parse(JSON.stringify(a))), console.log("errors:",
|
|
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();
|
|
231
236
|
},
|
|
232
237
|
{ deep: !0 }
|
|
233
238
|
);
|
|
234
|
-
const
|
|
235
|
-
() =>
|
|
239
|
+
const z = v(
|
|
240
|
+
() => h.value.map((a) => ({
|
|
236
241
|
...a,
|
|
237
242
|
options: k.value[a.name] ?? a.options,
|
|
238
|
-
optionsLoading:
|
|
243
|
+
optionsLoading: F.value[a.name] ?? !1
|
|
239
244
|
}))
|
|
240
|
-
),
|
|
245
|
+
), W = v(() => {
|
|
241
246
|
const a = N(p, t);
|
|
242
247
|
return JSON.stringify(o.value) !== JSON.stringify(a);
|
|
243
|
-
}),
|
|
244
|
-
const a =
|
|
245
|
-
return Object.values(a).every((
|
|
248
|
+
}), X = v(() => {
|
|
249
|
+
const a = y.validateAll(h.value, o.value);
|
|
250
|
+
return Object.values(a).every((l) => l.length === 0);
|
|
246
251
|
});
|
|
247
252
|
function H(a) {
|
|
248
253
|
if (a) {
|
|
249
|
-
const
|
|
254
|
+
const l = y.validateField(
|
|
250
255
|
a,
|
|
251
|
-
|
|
256
|
+
g(o.value, a.name),
|
|
252
257
|
o.value
|
|
253
258
|
);
|
|
254
|
-
|
|
259
|
+
d.value = { ...d.value, [a.name]: l }, y.validateAsync(
|
|
255
260
|
a,
|
|
256
|
-
|
|
261
|
+
g(o.value, a.name),
|
|
257
262
|
o.value,
|
|
258
|
-
(
|
|
259
|
-
|
|
260
|
-
...
|
|
261
|
-
[
|
|
263
|
+
(r, L) => {
|
|
264
|
+
d.value = {
|
|
265
|
+
...d.value,
|
|
266
|
+
[r]: [...d.value[r] ?? [], ...L]
|
|
262
267
|
};
|
|
263
268
|
}
|
|
264
269
|
);
|
|
265
270
|
} else
|
|
266
|
-
|
|
267
|
-
|
|
271
|
+
d.value = y.validateAll(
|
|
272
|
+
h.value,
|
|
268
273
|
o.value
|
|
269
274
|
);
|
|
270
275
|
}
|
|
271
|
-
function
|
|
272
|
-
const
|
|
273
|
-
o.value =
|
|
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(
|
|
274
279
|
o.value,
|
|
275
280
|
a,
|
|
276
281
|
L
|
|
277
|
-
), (e === "input" || e === "eager" && P.has(a)) &&
|
|
282
|
+
), (e === "input" || e === "eager" && P.has(a)) && r && H(r);
|
|
278
283
|
}
|
|
279
284
|
function G(a) {
|
|
280
|
-
return
|
|
285
|
+
return g(o.value, a);
|
|
281
286
|
}
|
|
282
287
|
function Q(a) {
|
|
283
|
-
if (
|
|
284
|
-
const
|
|
285
|
-
|
|
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);
|
|
286
291
|
}
|
|
287
292
|
}
|
|
288
293
|
async function Y() {
|
|
289
294
|
const a = {};
|
|
290
|
-
for (const
|
|
291
|
-
if (
|
|
292
|
-
|
|
295
|
+
for (const r of h.value) K(r, a);
|
|
296
|
+
if (b.value = a, d.value = y.validateAll(
|
|
297
|
+
h.value,
|
|
293
298
|
o.value
|
|
294
|
-
), !Object.values(
|
|
299
|
+
), !Object.values(d.value).some((r) => r.length > 0)) {
|
|
295
300
|
A.value = !0;
|
|
296
301
|
try {
|
|
297
|
-
const
|
|
298
|
-
await (u == null ? void 0 : u(
|
|
302
|
+
const r = U(h.value, o.value);
|
|
303
|
+
await (u == null ? void 0 : u(r));
|
|
299
304
|
} finally {
|
|
300
305
|
A.value = !1;
|
|
301
306
|
}
|
|
302
307
|
}
|
|
303
308
|
}
|
|
304
309
|
function Z(a) {
|
|
305
|
-
var
|
|
306
|
-
const
|
|
310
|
+
var r;
|
|
311
|
+
const l = a ?? t;
|
|
307
312
|
o.value = N(
|
|
308
313
|
p,
|
|
309
|
-
|
|
310
|
-
),
|
|
314
|
+
l ?? {}
|
|
315
|
+
), d.value = {}, b.value = {}, A.value = !1, x = !0, (r = E()) == null || r.removeItem(w), Promise.resolve().then(() => {
|
|
311
316
|
x = !1;
|
|
312
317
|
});
|
|
313
318
|
}
|
|
314
|
-
return
|
|
315
|
-
|
|
319
|
+
return re(() => {
|
|
320
|
+
V.stop(), y.destroy();
|
|
316
321
|
}), {
|
|
317
|
-
fields:
|
|
322
|
+
fields: z,
|
|
318
323
|
values: o,
|
|
319
|
-
errors:
|
|
320
|
-
touched:
|
|
321
|
-
optionsLoading:
|
|
322
|
-
isDirty:
|
|
323
|
-
isValid:
|
|
324
|
+
errors: d,
|
|
325
|
+
touched: b,
|
|
326
|
+
optionsLoading: F,
|
|
327
|
+
isDirty: W,
|
|
328
|
+
isValid: X,
|
|
324
329
|
isSubmitting: A,
|
|
325
330
|
submit: Y,
|
|
326
331
|
reset: Z,
|
|
327
|
-
setField:
|
|
332
|
+
setField: _,
|
|
328
333
|
getField: G,
|
|
329
334
|
// expose touch for FormRenderer
|
|
330
335
|
// @ts-expect-error - internal
|
|
@@ -347,56 +352,56 @@ function U(n, s) {
|
|
|
347
352
|
const t = { ...s };
|
|
348
353
|
for (const e of n) {
|
|
349
354
|
if (e.parse) {
|
|
350
|
-
const
|
|
351
|
-
t[e.name] = e.parse(
|
|
355
|
+
const i = g(t, e.name);
|
|
356
|
+
t[e.name] = e.parse(i);
|
|
352
357
|
}
|
|
353
358
|
if (e.fields) {
|
|
354
|
-
const
|
|
355
|
-
Object.assign(t,
|
|
359
|
+
const i = U(e.fields, t);
|
|
360
|
+
Object.assign(t, i);
|
|
356
361
|
}
|
|
357
362
|
}
|
|
358
363
|
return t;
|
|
359
364
|
}
|
|
360
365
|
function Se(n, s) {
|
|
361
|
-
const t = n.map((o) => pe(o)), e =
|
|
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(
|
|
362
367
|
() => t.reduce(
|
|
363
|
-
(o,
|
|
368
|
+
(o, d) => ({ ...o, ...d.values.value }),
|
|
364
369
|
{}
|
|
365
370
|
)
|
|
366
|
-
),
|
|
367
|
-
async function
|
|
371
|
+
), O = v(() => t.every((o) => o.isValid.value)), p = v(() => t.some((o) => o.isSubmitting.value));
|
|
372
|
+
async function y() {
|
|
368
373
|
return await t[e.value].submit(), Object.values(t[e.value].errors.value).some(
|
|
369
|
-
(
|
|
374
|
+
(d) => d.length > 0
|
|
370
375
|
) ? !1 : (u.value || e.value++, !0);
|
|
371
376
|
}
|
|
372
|
-
function
|
|
373
|
-
|
|
377
|
+
function V() {
|
|
378
|
+
c.value || e.value--;
|
|
374
379
|
}
|
|
375
|
-
function
|
|
376
|
-
o >= 0 && o <
|
|
380
|
+
function w(o) {
|
|
381
|
+
o >= 0 && o < i && (e.value = o);
|
|
377
382
|
}
|
|
378
383
|
async function E() {
|
|
379
384
|
for (const o of t)
|
|
380
|
-
if (await o.submit(), Object.values(o.errors.value).some((
|
|
385
|
+
if (await o.submit(), Object.values(o.errors.value).some((b) => b.length > 0)) return;
|
|
381
386
|
await (s == null ? void 0 : s(m.value));
|
|
382
387
|
}
|
|
383
388
|
return {
|
|
384
389
|
currentStep: e,
|
|
385
|
-
totalSteps:
|
|
386
|
-
isFirstStep:
|
|
390
|
+
totalSteps: i,
|
|
391
|
+
isFirstStep: c,
|
|
387
392
|
isLastStep: u,
|
|
388
|
-
form:
|
|
393
|
+
form: f,
|
|
389
394
|
steps: t,
|
|
390
395
|
values: m,
|
|
391
|
-
isValid:
|
|
396
|
+
isValid: O,
|
|
392
397
|
isSubmitting: p,
|
|
393
|
-
next:
|
|
394
|
-
back:
|
|
395
|
-
goTo:
|
|
398
|
+
next: y,
|
|
399
|
+
back: V,
|
|
400
|
+
goTo: w,
|
|
396
401
|
submit: E
|
|
397
402
|
};
|
|
398
403
|
}
|
|
399
|
-
function
|
|
404
|
+
function Ve(n) {
|
|
400
405
|
return { snapshot: v(() => ({
|
|
401
406
|
values: JSON.parse(JSON.stringify(n.values.value)),
|
|
402
407
|
errors: n.errors.value,
|
|
@@ -412,18 +417,18 @@ function Fe(n) {
|
|
|
412
417
|
}))
|
|
413
418
|
})) };
|
|
414
419
|
}
|
|
415
|
-
function
|
|
420
|
+
function Fe(...n) {
|
|
416
421
|
const s = /* @__PURE__ */ new Map();
|
|
417
422
|
for (const t of n)
|
|
418
423
|
for (const e of t)
|
|
419
424
|
s.set(e.name, e);
|
|
420
425
|
return Array.from(s.values());
|
|
421
426
|
}
|
|
422
|
-
function
|
|
427
|
+
function Oe(n, s) {
|
|
423
428
|
const t = new Set(s);
|
|
424
429
|
return n.filter((e) => !t.has(e.name));
|
|
425
430
|
}
|
|
426
|
-
function
|
|
431
|
+
function we(n, s) {
|
|
427
432
|
const t = new Set(s);
|
|
428
433
|
return n.filter((e) => t.has(e.name));
|
|
429
434
|
}
|
|
@@ -434,7 +439,7 @@ function Ae(n) {
|
|
|
434
439
|
return n;
|
|
435
440
|
}
|
|
436
441
|
export {
|
|
437
|
-
|
|
442
|
+
I as ConditionEvaluator,
|
|
438
443
|
oe as ValidationEngine,
|
|
439
444
|
xe as applyMask,
|
|
440
445
|
Le as bindMask,
|
|
@@ -443,26 +448,29 @@ export {
|
|
|
443
448
|
$ as email,
|
|
444
449
|
be as evaluateFieldConditions,
|
|
445
450
|
Ee as extendField,
|
|
446
|
-
|
|
451
|
+
Je as fileCount,
|
|
452
|
+
Pe as fileSize,
|
|
453
|
+
Be as fileType,
|
|
454
|
+
g as getByPath,
|
|
447
455
|
te as max,
|
|
448
456
|
se as maxLength,
|
|
449
|
-
|
|
457
|
+
Fe as mergeSchemas,
|
|
450
458
|
ne as min,
|
|
451
459
|
ae as minLength,
|
|
452
|
-
|
|
453
|
-
|
|
460
|
+
Oe as omitFields,
|
|
461
|
+
de as parseJSON,
|
|
454
462
|
ee as pattern,
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
463
|
+
we as pickFields,
|
|
464
|
+
De as provideRegistry,
|
|
465
|
+
He as removeMask,
|
|
466
|
+
T as required,
|
|
467
|
+
Me as sameAs,
|
|
468
|
+
C as setByPath,
|
|
461
469
|
q as url,
|
|
462
|
-
|
|
470
|
+
qe as useFieldArray,
|
|
463
471
|
pe as useForm,
|
|
464
|
-
|
|
472
|
+
Ve as useFormDebug,
|
|
465
473
|
ge as useFormField,
|
|
466
474
|
Se as useMultiStepForm,
|
|
467
|
-
|
|
475
|
+
$e as useRegistry
|
|
468
476
|
};
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ export { default as CheckboxField } from './fields/CheckboxField.vue';
|
|
|
8
8
|
export { default as RadioField } from './fields/RadioField.vue';
|
|
9
9
|
export { default as DateField } from './fields/DateField.vue';
|
|
10
10
|
export { default as ArrayField } from './fields/ArrayField.vue';
|
|
11
|
+
export { default as FileField } from './fields/FileField.vue';
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/ui/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAC9E,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAC9E,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default as TailwindFormRenderer } from './TailwindFormRenderer.vue';
|
|
2
|
+
export { default as TwTextField } from './TextField.vue';
|
|
3
|
+
export { default as TwNumberField } from './NumberField.vue';
|
|
4
|
+
export { default as TwTextareaField } from './TextareaField.vue';
|
|
5
|
+
export { default as TwSelectField } from './SelectField.vue';
|
|
6
|
+
export { default as TwCheckboxField } from './CheckboxField.vue';
|
|
7
|
+
export { default as TwRadioField } from './RadioField.vue';
|
|
8
|
+
export { default as TwDateField } from './DateField.vue';
|
|
9
|
+
export { default as TwFileField } from './FileField.vue';
|
|
10
|
+
export { default as TwArrayField } from './ArrayField.vue';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/tailwind/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAC5E,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),v=require("./MaskEngine-DAKSNIHQ.cjs"),q={class:"mb-4"},D=["for"],T={key:0,class:"text-red-400 ml-0.5","aria-hidden":"true"},R=["id"],k=e.defineComponent({__name:"BaseField",props:{field:{},error:{},touched:{type:Boolean}},setup(t){const s=t,r=e.computed(()=>{var a;return!!(s.touched&&((a=s.error)!=null&&a.length))}),c=e.computed(()=>`${s.field.name}-error`),n=e.computed(()=>({"aria-required":s.field.required?"true":void 0,"aria-invalid":r.value?"true":"false","aria-describedby":r.value?c.value:void 0}));return(a,d)=>(e.openBlock(),e.createElementBlock("div",q,[t.field.label?(e.openBlock(),e.createElementBlock("label",{key:0,for:t.field.name,class:"block text-xs font-semibold uppercase tracking-wider text-gray-400 mb-1.5"},[e.createTextVNode(e.toDisplayString(t.field.label)+" ",1),t.field.required?(e.openBlock(),e.createElementBlock("span",T,"*")):e.createCommentVNode("",!0)],8,D)):e.createCommentVNode("",!0),e.renderSlot(a.$slots,"default",e.normalizeProps(e.guardReactiveProps(n.value))),r.value?(e.openBlock(),e.createElementBlock("ul",{key:1,id:c.value,class:"mt-1 space-y-0.5",role:"alert","aria-live":"polite"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.error,(i,m)=>(e.openBlock(),e.createElementBlock("li",{key:m,class:"text-red-400 text-xs"},e.toDisplayString(i),1))),128))],8,R)):e.createCommentVNode("",!0)]))}}),A=["id","type","name","value","placeholder","disabled","required"],x=e.defineComponent({__name:"TextField",props:{field:{},modelValue:{},error:{},touched:{type:Boolean}},emits:["update:modelValue","blur"],setup(t,{emit:s}){const r=t,c=s,n=e.ref(null);let a=null;const d=e.computed(()=>{var i;return!!(r.touched&&((i=r.error)!=null&&i.length))});return e.onMounted(()=>{n.value&&r.field.mask&&(a=v.bindMask(n.value,r.field.mask))}),e.onUnmounted(()=>a==null?void 0:a()),(i,m)=>(e.openBlock(),e.createBlock(k,{field:t.field,error:t.error,touched:t.touched},{default:e.withCtx(f=>[e.createElementVNode("input",e.mergeProps({id:t.field.name,ref_key:"inputRef",ref:n,type:t.field.type==="email"?"email":"text",name:t.field.name,value:t.modelValue??"",placeholder:t.field.placeholder,disabled:t.field.disabled===!0,required:t.field.required},f,{class:["w-full rounded-lg border bg-gray-900 px-3 py-2 text-sm text-gray-100 placeholder-gray-500 outline-none transition focus:ring-2 disabled:cursor-not-allowed disabled:opacity-50",d.value?"border-red-500 focus:ring-red-500":"border-gray-700 focus:ring-indigo-500 focus:border-indigo-500"],onInput:m[0]||(m[0]=g=>c("update:modelValue",g.target.value)),onBlur:m[1]||(m[1]=g=>c("blur"))}),null,16,A)]),_:1},8,["field","error","touched"]))}}),P=["id","name","value","placeholder","disabled","required"],V=e.defineComponent({__name:"NumberField",props:{field:{},modelValue:{},error:{},touched:{type:Boolean}},emits:["update:modelValue","blur"],setup(t,{emit:s}){const r=t,c=s,n=e.computed(()=>{var d;return!!(r.touched&&((d=r.error)!=null&&d.length))});function a(d){const i=d.target.value;c("update:modelValue",i===""?null:Number(i))}return(d,i)=>(e.openBlock(),e.createBlock(k,{field:t.field,error:t.error,touched:t.touched},{default:e.withCtx(m=>[e.createElementVNode("input",e.mergeProps({id:t.field.name,type:"number",name:t.field.name,value:t.modelValue??"",placeholder:t.field.placeholder,disabled:t.field.disabled===!0,required:t.field.required},m,{class:["w-full rounded-lg border bg-gray-900 px-3 py-2 text-sm text-gray-100 placeholder-gray-500 outline-none transition focus:ring-2 disabled:cursor-not-allowed disabled:opacity-50",n.value?"border-red-500 focus:ring-red-500":"border-gray-700 focus:ring-indigo-500 focus:border-indigo-500"],onInput:a,onBlur:i[0]||(i[0]=f=>c("blur"))}),null,16,P)]),_:1},8,["field","error","touched"]))}}),L=["id","name","value","placeholder","disabled","required"],$=e.defineComponent({__name:"TextareaField",props:{field:{},modelValue:{},error:{},touched:{type:Boolean}},emits:["update:modelValue","blur"],setup(t,{emit:s}){const r=t,c=s,n=e.computed(()=>{var a;return!!(r.touched&&((a=r.error)!=null&&a.length))});return(a,d)=>(e.openBlock(),e.createBlock(k,{field:t.field,error:t.error,touched:t.touched},{default:e.withCtx(i=>[e.createElementVNode("textarea",e.mergeProps({id:t.field.name,name:t.field.name,value:t.modelValue??"",placeholder:t.field.placeholder,disabled:t.field.disabled===!0,required:t.field.required},i,{class:["w-full resize-y rounded-lg border bg-gray-900 px-3 py-2 text-sm text-gray-100 placeholder-gray-500 outline-none transition focus:ring-2 disabled:cursor-not-allowed disabled:opacity-50",n.value?"border-red-500 focus:ring-red-500":"border-gray-700 focus:ring-indigo-500 focus:border-indigo-500"],style:{"min-height":"80px"},onInput:d[0]||(d[0]=m=>c("update:modelValue",m.target.value)),onBlur:d[1]||(d[1]=m=>c("blur"))}),null,16,L)]),_:1},8,["field","error","touched"]))}}),I={key:0,class:"py-2 text-sm text-gray-400"},M=["id","name","disabled","required"],z=["selected"],U=["value","selected"],E=e.defineComponent({__name:"SelectField",props:{field:{},modelValue:{},error:{},touched:{type:Boolean}},emits:["update:modelValue","blur"],setup(t,{emit:s}){const r=t,c=s,n=e.computed(()=>Array.isArray(r.field.options)?r.field.options:[]),a=e.computed(()=>{var i;return!!(r.touched&&((i=r.error)!=null&&i.length))});function d(i){const m=i.target,f=n.value.find(g=>String(g.value)===m.value);c("update:modelValue",(f==null?void 0:f.value)??m.value)}return(i,m)=>(e.openBlock(),e.createBlock(k,{field:t.field,error:t.error,touched:t.touched},{default:e.withCtx(f=>[t.field.optionsLoading?(e.openBlock(),e.createElementBlock("div",I,"Loading…")):(e.openBlock(),e.createElementBlock("select",e.mergeProps({key:1,id:t.field.name,name:t.field.name,disabled:t.field.disabled===!0||t.field.optionsLoading,required:t.field.required},f,{class:["w-full rounded-lg border bg-gray-900 px-3 py-2 text-sm text-gray-100 outline-none transition focus:ring-2 disabled:cursor-not-allowed disabled:opacity-50",a.value?"border-red-500 focus:ring-red-500":"border-gray-700 focus:ring-indigo-500 focus:border-indigo-500"],onChange:d,onBlur:m[0]||(m[0]=g=>c("blur"))}),[e.createElementVNode("option",{value:"",disabled:"",selected:t.modelValue===null||t.modelValue===void 0||t.modelValue==="",class:"bg-gray-800"},e.toDisplayString(t.field.placeholder??"Select an option"),9,z),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.value,g=>(e.openBlock(),e.createElementBlock("option",{key:String(g.value),value:String(g.value),selected:t.modelValue===g.value,class:"bg-gray-800"},e.toDisplayString(g.label),9,U))),128))],16,M))]),_:1},8,["field","error","touched"]))}}),j={class:"flex cursor-pointer items-center gap-2.5"},K=["id","name","checked","disabled","required","aria-checked"],O={key:0,class:"text-sm text-gray-200"},C=e.defineComponent({__name:"CheckboxField",props:{field:{},modelValue:{type:[Boolean,null]},error:{},touched:{type:Boolean}},emits:["update:modelValue","blur"],setup(t,{emit:s}){const r=s;return(c,n)=>(e.openBlock(),e.createBlock(k,{field:{...t.field,label:void 0},error:t.error,touched:t.touched},{default:e.withCtx(a=>[e.createElementVNode("label",j,[e.createElementVNode("input",e.mergeProps({id:t.field.name,type:"checkbox",name:t.field.name,checked:!!t.modelValue,disabled:t.field.disabled===!0,required:t.field.required,"aria-checked":t.modelValue?"true":"false"},a,{class:"h-4 w-4 cursor-pointer rounded border-gray-600 bg-gray-900 text-indigo-500 accent-indigo-500 disabled:cursor-not-allowed disabled:opacity-50",onChange:n[0]||(n[0]=d=>r("update:modelValue",d.target.checked)),onBlur:n[1]||(n[1]=d=>r("blur"))}),null,16,K),t.field.label?(e.openBlock(),e.createElementBlock("span",O,e.toDisplayString(t.field.label),1)):e.createCommentVNode("",!0)])]),_:1},8,["field","error","touched"]))}}),G=["aria-required","aria-invalid","aria-describedby"],H={key:0,class:"block text-xs font-semibold uppercase tracking-wider text-gray-400 mb-2"},J={key:0,class:"text-red-400 ml-0.5","aria-hidden":"true"},Q={class:"space-y-2"},W=["name","value","checked","disabled","onChange"],X={class:"text-sm text-gray-200"},Y=["id"],w=e.defineComponent({__name:"RadioField",props:{field:{},modelValue:{},error:{},touched:{type:Boolean}},emits:["update:modelValue","blur"],setup(t,{emit:s}){const r=t,c=s,n=e.computed(()=>{var i;return!!(r.touched&&((i=r.error)!=null&&i.length))}),a=e.computed(()=>`${r.field.name}-error`),d=e.computed(()=>Array.isArray(r.field.options)?r.field.options:[]);return(i,m)=>(e.openBlock(),e.createElementBlock("fieldset",{class:"mb-4","aria-required":t.field.required?"true":void 0,"aria-invalid":n.value?"true":"false","aria-describedby":n.value?a.value:void 0},[t.field.label?(e.openBlock(),e.createElementBlock("legend",H,[e.createTextVNode(e.toDisplayString(t.field.label)+" ",1),t.field.required?(e.openBlock(),e.createElementBlock("span",J,"*")):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.createElementVNode("div",Q,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(d.value,f=>(e.openBlock(),e.createElementBlock("label",{key:String(f.value),class:"flex cursor-pointer items-center gap-2.5"},[e.createElementVNode("input",{type:"radio",name:t.field.name,value:String(f.value),checked:t.modelValue===f.value,disabled:t.field.disabled===!0,class:"h-4 w-4 cursor-pointer border-gray-600 bg-gray-900 text-indigo-500 accent-indigo-500 disabled:cursor-not-allowed disabled:opacity-50",onChange:g=>c("update:modelValue",f.value),onBlur:m[0]||(m[0]=g=>c("blur"))},null,40,W),e.createElementVNode("span",X,e.toDisplayString(f.label),1)]))),128))]),n.value?(e.openBlock(),e.createElementBlock("ul",{key:1,id:a.value,class:"mt-1 space-y-0.5",role:"alert","aria-live":"polite"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.error,(f,g)=>(e.openBlock(),e.createElementBlock("li",{key:g,class:"text-red-400 text-xs"},e.toDisplayString(f),1))),128))],8,Y)):e.createCommentVNode("",!0)],8,G))}}),Z=["id","name","value","disabled","required"],N=e.defineComponent({__name:"DateField",props:{field:{},modelValue:{},error:{},touched:{type:Boolean}},emits:["update:modelValue","blur"],setup(t,{emit:s}){const r=t,c=s,n=e.computed(()=>{var a;return!!(r.touched&&((a=r.error)!=null&&a.length))});return(a,d)=>(e.openBlock(),e.createBlock(k,{field:t.field,error:t.error,touched:t.touched},{default:e.withCtx(i=>[e.createElementVNode("input",e.mergeProps({id:t.field.name,type:"date",name:t.field.name,value:t.modelValue??"",disabled:t.field.disabled===!0,required:t.field.required},i,{class:["w-full rounded-lg border bg-gray-900 px-3 py-2 text-sm text-gray-100 outline-none transition focus:ring-2 disabled:cursor-not-allowed disabled:opacity-50",n.value?"border-red-500 focus:ring-red-500":"border-gray-700 focus:ring-indigo-500 focus:border-indigo-500"],onInput:d[0]||(d[0]=m=>c("update:modelValue",m.target.value)),onBlur:d[1]||(d[1]=m=>c("blur"))}),null,16,Z)]),_:1},8,["field","error","touched"]))}}),_=["id","name","accept","multiple","disabled","required"],ee={class:"pointer-events-none space-y-1"},te={class:"text-sm text-gray-300"},oe={key:0,class:"text-xs text-gray-500"},re={key:0,class:"mt-2 space-y-1"},le={class:"truncate text-gray-200"},ne={class:"ml-2 shrink-0 text-xs text-gray-500"},ae=["aria-label","onClick"],F=e.defineComponent({__name:"FileField",props:{field:{},modelValue:{},error:{},touched:{type:Boolean}},emits:["update:modelValue","blur"],setup(t,{emit:s}){const r=t,c=s,n=e.ref(!1),a=e.ref(null),d=e.computed(()=>r.modelValue?Array.isArray(r.modelValue)?r.modelValue:[r.modelValue]:[]),i=e.computed(()=>r.field.multiple??!1);function m(l){if(!l||l.length===0){c("update:modelValue",null);return}c("update:modelValue",i.value?Array.from(l):l[0])}function f(l){m(l.target.files),c("blur")}function g(l){var o;n.value=!1,l.preventDefault(),m(((o=l.dataTransfer)==null?void 0:o.files)??null),c("blur")}function h(l){const o=d.value.filter((b,y)=>y!==l);o.length===0?(c("update:modelValue",null),a.value&&(a.value.value="")):c("update:modelValue",i.value?o:o[0])}function B(l){return l<1024?`${l} B`:l<1024*1024?`${(l/1024).toFixed(1)} KB`:`${(l/(1024*1024)).toFixed(1)} MB`}return(l,o)=>(e.openBlock(),e.createBlock(k,{field:t.field,error:t.error,touched:t.touched},{default:e.withCtx(b=>{var y;return[e.createElementVNode("div",{class:e.normalizeClass(["relative rounded-lg border-2 border-dashed p-6 text-center transition",n.value?"border-indigo-500 bg-indigo-500/10":t.touched&&((y=t.error)!=null&&y.length)?"border-red-500 bg-red-500/5":"border-gray-700 bg-gray-900 hover:border-gray-500"]),onDragover:o[0]||(o[0]=e.withModifiers(u=>n.value=!0,["prevent"])),onDragleave:o[1]||(o[1]=u=>n.value=!1),onDrop:g},[e.createElementVNode("input",e.mergeProps({id:t.field.name,ref_key:"inputRef",ref:a,type:"file",name:t.field.name,accept:t.field.accept,multiple:i.value,disabled:t.field.disabled===!0,required:t.field.required},b,{class:"absolute inset-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",onChange:f}),null,16,_),e.createElementVNode("div",ee,[o[2]||(o[2]=e.createElementVNode("div",{class:"text-2xl"},"📁",-1)),e.createElementVNode("p",te,e.toDisplayString(n.value?"Drop files here":"Click to upload or drag & drop"),1),t.field.accept?(e.openBlock(),e.createElementBlock("p",oe,e.toDisplayString(t.field.accept),1)):e.createCommentVNode("",!0)])],34),d.value.length?(e.openBlock(),e.createElementBlock("ul",re,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(d.value,(u,p)=>(e.openBlock(),e.createElementBlock("li",{key:`${u.name}-${p}`,class:"flex items-center justify-between rounded-lg border border-gray-700 bg-gray-900 px-3 py-2 text-sm"},[e.createElementVNode("span",le,e.toDisplayString(u.name),1),e.createElementVNode("span",ne,e.toDisplayString(B(u.size)),1),e.createElementVNode("button",{type:"button","aria-label":`Remove ${u.name}`,class:"ml-2 shrink-0 text-gray-500 hover:text-red-400 transition",onClick:be=>h(p)}," × ",8,ae)]))),128))])):e.createCommentVNode("",!0)]}),_:1},8,["field","error","touched"]))}}),de={class:"mb-4"},ie={key:0,class:"block text-xs font-semibold uppercase tracking-wider text-gray-400 mb-2"},ue={class:"flex-1 space-y-0"},ce=["onClick"],S=e.defineComponent({__name:"ArrayField",props:{field:{},form:{},components:{}},setup(t){const s=t,r=v.useRegistry(),c={text:x,email:x,number:V,textarea:$,select:E,checkbox:C,radio:w,date:N};function n(l){var o;return l.component?l.component:((o=s.components)==null?void 0:o[l.type])??r[l.type]??c[l.type]??null}const{rows:a,append:d,remove:i}=v.useFieldArray(s.form,s.field.name);function m(l){return v.getByPath(s.form.values.value,l.name)}function f(l,o){s.form.setField(l.name,o)}function g(l){var b;const o=s.form;(b=o.touchField)==null||b.call(o,l.name)}function h(l){return s.form.errors.value[l.name]??[]}function B(l){return s.form.touched.value[l.name]??!1}return(l,o)=>(e.openBlock(),e.createElementBlock("div",de,[t.field.label?(e.openBlock(),e.createElementBlock("div",ie,e.toDisplayString(t.field.label),1)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(a),b=>(e.openBlock(),e.createElementBlock("div",{key:b.key,class:"mb-2 flex items-start gap-2 rounded-lg border border-gray-700 bg-gray-900 p-3"},[e.createElementVNode("div",ue,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b.fields,y=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:y.name},[n(y)?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n(y)),{key:0,field:y,"model-value":m(y),error:h(y),touched:B(y),"onUpdate:modelValue":u=>f(y,u),onBlur:u=>g(y)},null,40,["field","model-value","error","touched","onUpdate:modelValue","onBlur"])):e.createCommentVNode("",!0)],64))),128))]),e.createElementVNode("button",{type:"button",class:"mt-7 shrink-0 rounded px-2 py-1 text-xs text-gray-500 hover:bg-red-500/10 hover:text-red-400 transition",onClick:y=>e.unref(i)(b.index)}," Remove ",8,ce)]))),128)),e.createElementVNode("button",{type:"button",class:"mt-1 rounded-lg border border-dashed border-gray-600 px-4 py-2 text-sm text-gray-400 hover:border-indigo-500 hover:text-indigo-400 transition",onClick:o[0]||(o[0]=b=>e.unref(d)())}," + Add row ")]))}}),se={key:1,class:"mb-4 rounded-lg border border-gray-700 p-4"},me={key:0,class:"px-1 text-xs font-semibold uppercase tracking-wider text-gray-400"},fe=["disabled"],ge=e.defineComponent({__name:"TailwindFormRenderer",props:{form:{},components:{},submitLabel:{}},emits:["submit"],setup(t,{emit:s}){const r=t,c=v.useRegistry(),n=s,a={text:x,email:x,number:V,textarea:$,select:E,checkbox:C,radio:w,date:N,file:F};function d(o){var b;return o.component?o.component:((b=r.components)==null?void 0:b[o.type])??c[o.type]??a[o.type]??null}function i(o){return v.getByPath(r.form.values.value,o.name)}function m(o,b){r.form.setField(o.name,b)}function f(o){var y;const b=r.form;(y=b.touchField)==null||y.call(b,o.name)}function g(o){return r.form.errors.value[o.name]??[]}function h(o){return r.form.touched.value[o.name]??!1}const B=e.computed(()=>r.form.fields.value.filter(o=>o.visible!==!1));async function l(o){o.preventDefault(),await r.form.submit(),n("submit")}return(o,b)=>{const y=e.resolveComponent("TailwindFormRenderer",!0);return e.openBlock(),e.createElementBlock("form",{novalidate:"",onSubmit:l},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.value,u=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:u.name},[o.$slots[`field-${u.name}`]?e.renderSlot(o.$slots,`field-${u.name}`,{key:0,field:u,value:i(u),error:g(u),touched:h(u),setValue:p=>m(u,p),touch:()=>f(u)}):u.type==="group"?(e.openBlock(),e.createElementBlock("fieldset",se,[u.label?(e.openBlock(),e.createElementBlock("legend",me,e.toDisplayString(u.label),1)):e.createCommentVNode("",!0),u.fields?(e.openBlock(),e.createBlock(y,{key:1,form:t.form,components:t.components},null,8,["form","components"])):e.createCommentVNode("",!0)])):u.type==="array"?(e.openBlock(),e.createBlock(S,{key:2,field:u,form:t.form,components:t.components},null,8,["field","form","components"])):d(u)?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(d(u)),{key:3,field:u,"model-value":i(u),error:g(u),touched:h(u),"onUpdate:modelValue":p=>m(u,p),onBlur:p=>f(u)},null,40,["field","model-value","error","touched","onUpdate:modelValue","onBlur"])):e.createCommentVNode("",!0)],64))),128)),e.renderSlot(o.$slots,"submit",{isSubmitting:t.form.isSubmitting.value,isValid:t.form.isValid.value},()=>[e.createElementVNode("button",{type:"submit",disabled:t.form.isSubmitting.value,class:"mt-2 rounded-lg bg-indigo-600 px-5 py-2 text-sm font-medium text-white transition hover:bg-indigo-500 disabled:cursor-not-allowed disabled:opacity-40"},e.toDisplayString(t.submitLabel??"Submit"),9,fe)])],32)}}});exports.TailwindFormRenderer=ge;exports.TwArrayField=S;exports.TwCheckboxField=C;exports.TwDateField=N;exports.TwFileField=F;exports.TwNumberField=V;exports.TwRadioField=w;exports.TwSelectField=E;exports.TwTextField=x;exports.TwTextareaField=$;
|