pdyform 2.1.0 → 2.2.1

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.
@@ -1,13 +1,200 @@
1
- import { defineComponent as f, openBlock as n, createElementBlock as m, normalizeClass as S, unref as s, createBlock as p, computed as h, mergeProps as V, withCtx as r, renderSlot as w, createVNode as c, createElementVNode as I, normalizeProps as z, guardReactiveProps as N, Fragment as $, renderList as B, createTextVNode as C, toDisplayString as v, createCommentVNode as x, resolveDynamicComponent as T, ref as D, withModifiers as j } from "vue";
2
- import { normalizeFieldValue as q, createFormRuntimeState as G, applyFieldChange as A, setSubmitting as E, runSubmitValidation as L } from "pdyform/core";
3
- import { clsx as O } from "clsx";
4
- import { twMerge as W } from "tailwind-merge";
5
- import { useForwardProps as _, SelectTrigger as H, SelectIcon as J, SelectPortal as K, SelectContent as Q, SelectViewport as X, SelectItem as Y, SelectItemIndicator as Z, SelectItemText as ee, useForwardPropsEmits as P, SelectRoot as te, SelectValue as le, CheckboxRoot as ae, CheckboxIndicator as oe, Label as se, RadioGroupItem as de, RadioGroupIndicator as ne, RadioGroupRoot as ie } from "radix-vue";
6
- import { ChevronDown as re, Check as U, Circle as ue } from "lucide-vue-next";
7
- function y(...e) {
8
- return W(O(e));
1
+ import { defineComponent as p, openBlock as d, createElementBlock as g, mergeProps as I, unref as o, createBlock as v, computed as h, withCtx as m, renderSlot as q, createVNode as b, normalizeClass as D, createElementVNode as O, normalizeProps as X, guardReactiveProps as Y, Fragment as N, renderList as E, createTextVNode as U, toDisplayString as F, createCommentVNode as R, resolveDynamicComponent as Z, ref as _, onUnmounted as ee, withModifiers as te } from "vue";
2
+ import { clsx as ae } from "clsx";
3
+ import { twMerge as le } from "tailwind-merge";
4
+ import { useForwardProps as j, SelectTrigger as ie, SelectIcon as ne, SelectPortal as se, SelectContent as re, SelectViewport as oe, SelectItem as de, SelectItemIndicator as ue, SelectItemText as ce, useForwardPropsEmits as A, SelectRoot as me, SelectValue as fe, CheckboxRoot as be, CheckboxIndicator as pe, Label as ge, RadioGroupItem as ye, RadioGroupIndicator as ve, RadioGroupRoot as he, SwitchRoot as xe, SwitchThumb as Ve } from "radix-vue";
5
+ import { ChevronDown as ke, Check as K, Circle as we } from "lucide-vue-next";
6
+ function z(e) {
7
+ if (typeof e == "number") return Number.isNaN(e) ? null : e;
8
+ if (typeof e != "string" || e.trim() === "") return null;
9
+ const l = Number(e);
10
+ return Number.isNaN(l) ? null : l;
9
11
  }
10
- const ce = ["type", "value"], me = /* @__PURE__ */ f({
12
+ var Be = {
13
+ required: "{label} is required",
14
+ min: "{label} must be at least {value}",
15
+ max: "{label} must be at most {value}",
16
+ email: "Invalid email address",
17
+ pattern: "Invalid format",
18
+ custom: "Invalid value"
19
+ };
20
+ function S(e, l, i) {
21
+ return e.replace("{label}", l.label).replace("{value}", String(i.value || ""));
22
+ }
23
+ function M(e, l, i) {
24
+ if (!l) return i;
25
+ const n = l.split(/[.[\]]/).filter(Boolean);
26
+ let a = e;
27
+ for (const t of n) {
28
+ if (a == null) return i;
29
+ a = a[t];
30
+ }
31
+ return a === void 0 ? i : a;
32
+ }
33
+ function Se(e, l, i) {
34
+ if (Object(e) !== e) return e;
35
+ const n = l.split(/[.[\]]/).filter(Boolean), a = { ...e };
36
+ let t = a;
37
+ for (let r = 0; r < n.length - 1; r++) {
38
+ const s = n[r], u = n[r + 1], f = /^\d+$/.test(u);
39
+ !(s in t) || t[s] === null || typeof t[s] != "object" ? t[s] = f ? [] : {} : t[s] = Array.isArray(t[s]) ? [...t[s]] : { ...t[s] }, t = t[s];
40
+ }
41
+ return t[n[n.length - 1]] = i, a;
42
+ }
43
+ function W(e, l) {
44
+ if (e.type !== "number") return l;
45
+ if (l === "" || l === void 0 || l === null) return "";
46
+ const i = z(l);
47
+ return i === null ? l : i;
48
+ }
49
+ async function J(e, l, i) {
50
+ if (!l.validations) return null;
51
+ const n = { ...Be, ...i };
52
+ for (const a of l.validations)
53
+ switch (a.type) {
54
+ case "required":
55
+ if (e == null || e === "" || Array.isArray(e) && e.length === 0)
56
+ return a.message || S(n.required, l, a);
57
+ break;
58
+ case "min":
59
+ if (l.type === "number") {
60
+ const t = z(e);
61
+ if (t !== null && t < a.value) {
62
+ const r = l.type === "number" ? n.min : typeof e == "string" ? "{label} must be at least {value} characters" : n.min;
63
+ return a.message || S(r, l, a);
64
+ }
65
+ break;
66
+ }
67
+ if (typeof e == "number" && e < a.value)
68
+ return a.message || S(n.min, l, a);
69
+ if (typeof e == "string" && e.length < a.value)
70
+ return a.message || S("{label} must be at least {value} characters", l, a);
71
+ break;
72
+ case "max":
73
+ if (l.type === "number") {
74
+ const t = z(e);
75
+ if (t !== null && t > a.value)
76
+ return a.message || S(n.max, l, a);
77
+ break;
78
+ }
79
+ if (typeof e == "number" && e > a.value)
80
+ return a.message || S(n.max, l, a);
81
+ if (typeof e == "string" && e.length > a.value)
82
+ return a.message || S("{label} must be at most {value} characters", l, a);
83
+ break;
84
+ case "email": {
85
+ if (e && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))
86
+ return a.message || S(n.email, l, a);
87
+ break;
88
+ }
89
+ case "pattern":
90
+ if (e && a.value && !new RegExp(a.value).test(e))
91
+ return a.message || S(n.pattern, l, a);
92
+ break;
93
+ case "custom":
94
+ if (a.validator) {
95
+ const t = await a.validator(e);
96
+ if (typeof t == "string") return t;
97
+ if (t === !1) return a.message || S(n.custom, l, a);
98
+ }
99
+ break;
100
+ }
101
+ return null;
102
+ }
103
+ async function G(e, l, i, n, a, t) {
104
+ if (n && a) {
105
+ const s = await n(a);
106
+ if (s[l]) return s[l];
107
+ }
108
+ const r = e.find((s) => s.name === l);
109
+ return r ? await J(i, r, t) : null;
110
+ }
111
+ async function Ie(e, l, i, n) {
112
+ let a = {};
113
+ i && (a = await i(l));
114
+ const t = e.map(async (r) => {
115
+ if (a[r.name] || (typeof r.hidden == "function" ? r.hidden(l) : r.hidden)) return;
116
+ const u = await J(M(l, r.name), r, n);
117
+ u && (a[r.name] = u);
118
+ });
119
+ return await Promise.all(t), a;
120
+ }
121
+ function $e(e) {
122
+ return e.reduce((l, i) => (l[i.name] = i.defaultValue !== void 0 ? i.defaultValue : i.type === "checkbox" ? [] : "", l), {});
123
+ }
124
+ const L = (e) => {
125
+ let l;
126
+ const i = /* @__PURE__ */ new Set(), n = (f, $) => {
127
+ const c = typeof f == "function" ? f(l) : f;
128
+ if (!Object.is(c, l)) {
129
+ const x = l;
130
+ l = $ ?? (typeof c != "object" || c === null) ? c : Object.assign({}, l, c), i.forEach((V) => V(l, x));
131
+ }
132
+ }, a = () => l, s = { setState: n, getState: a, getInitialState: () => u, subscribe: (f) => (i.add(f), () => i.delete(f)) }, u = l = e(n, a, s);
133
+ return s;
134
+ }, Fe = (e) => e ? L(e) : L;
135
+ function Re(e, l, i) {
136
+ return Fe()((n, a) => ({
137
+ values: $e(e),
138
+ errors: {},
139
+ validatingFields: [],
140
+ isSubmitting: !1,
141
+ setFieldValue: async (t, r) => {
142
+ const s = e.find((c) => c.name === t), u = s ? W(s, r) : r;
143
+ n((c) => ({
144
+ values: Se(c.values, t, u)
145
+ }));
146
+ const f = !!a().errors[t];
147
+ if (s && ["select", "checkbox", "radio", "switch", "date"].includes(s.type) || f) {
148
+ n((c) => ({
149
+ validatingFields: [...c.validatingFields, t]
150
+ }));
151
+ try {
152
+ const c = a().values, x = await G(e, t, u, l, c, i);
153
+ n((V) => ({
154
+ errors: { ...V.errors, [t]: x || "" },
155
+ validatingFields: V.validatingFields.filter((y) => y !== t)
156
+ }));
157
+ } catch {
158
+ n((x) => ({
159
+ validatingFields: x.validatingFields.filter((V) => V !== t)
160
+ }));
161
+ }
162
+ }
163
+ },
164
+ setFieldBlur: async (t) => {
165
+ n((r) => ({
166
+ validatingFields: [...r.validatingFields, t]
167
+ }));
168
+ try {
169
+ const r = a().values, s = M(r, t), u = await G(e, t, s, l, r, i);
170
+ n((f) => ({
171
+ errors: { ...f.errors, [t]: u || "" },
172
+ validatingFields: f.validatingFields.filter(($) => $ !== t)
173
+ }));
174
+ } catch {
175
+ n((s) => ({
176
+ validatingFields: s.validatingFields.filter((u) => u !== t)
177
+ }));
178
+ }
179
+ },
180
+ setSubmitting: (t) => n({ isSubmitting: t }),
181
+ runSubmitValidation: async () => {
182
+ n({ isSubmitting: !0 });
183
+ const t = a(), r = await Ie(e, t.values, l, i), s = Object.keys(r).length > 0;
184
+ return n({
185
+ errors: r,
186
+ isSubmitting: !1
187
+ }), {
188
+ state: a(),
189
+ hasError: s
190
+ };
191
+ }
192
+ }));
193
+ }
194
+ function w(...e) {
195
+ return le(ae(e));
196
+ }
197
+ const Ce = ["type", "value"], Q = /* @__PURE__ */ p({
11
198
  __name: "Input",
12
199
  props: {
13
200
  class: {},
@@ -15,74 +202,81 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
15
202
  modelValue: {}
16
203
  },
17
204
  emits: ["update:modelValue", "blur"],
18
- setup(e, { emit: o }) {
19
- const a = e, d = o;
20
- return (l, t) => (n(), m("input", {
205
+ setup(e, { emit: l }) {
206
+ const i = e, n = l;
207
+ return (a, t) => (d(), g("input", I(a.$attrs, {
21
208
  type: e.type,
22
- class: S(s(y)("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", a.class)),
209
+ class: o(w)("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", i.class),
23
210
  value: e.modelValue,
24
- onInput: t[0] || (t[0] = (u) => d("update:modelValue", u.target.value)),
25
- onBlur: t[1] || (t[1] = (u) => d("blur", u))
26
- }, null, 42, ce));
211
+ onInput: t[0] || (t[0] = (r) => n("update:modelValue", r.target.value)),
212
+ onBlur: t[1] || (t[1] = (r) => n("blur", r))
213
+ }), null, 16, Ce));
27
214
  }
28
- }), k = /* @__PURE__ */ f({
215
+ }), P = /* @__PURE__ */ p({
29
216
  __name: "InputRenderer",
30
217
  props: {
31
218
  field: {},
219
+ fieldId: {},
32
220
  modelValue: {},
33
- fieldId: {}
221
+ ariaInvalid: { type: Boolean },
222
+ ariaRequired: { type: Boolean },
223
+ ariaDescribedby: {}
34
224
  },
35
- emits: ["update:modelValue"],
36
- setup(e, { emit: o }) {
37
- const a = e, d = o, l = (t) => {
38
- d("update:modelValue", q(a.field, t));
225
+ emits: ["update:modelValue", "blur"],
226
+ setup(e, { emit: l }) {
227
+ const i = e, n = l, a = (t) => {
228
+ n("update:modelValue", W(i.field, t));
39
229
  };
40
- return (t, u) => (n(), p(me, {
230
+ return (t, r) => (d(), v(Q, {
41
231
  id: e.fieldId,
42
232
  type: e.field.type,
43
233
  placeholder: e.field.placeholder,
44
- disabled: e.field.disabled,
234
+ disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
45
235
  name: e.field.name,
46
236
  modelValue: e.modelValue ?? "",
47
- "onUpdate:modelValue": l
237
+ "onUpdate:modelValue": a,
238
+ onBlur: r[0] || (r[0] = (s) => n("blur", s))
48
239
  }, null, 8, ["id", "type", "placeholder", "disabled", "name", "modelValue"]));
49
240
  }
50
- }), fe = ["value"], pe = /* @__PURE__ */ f({
241
+ }), qe = ["value"], Pe = /* @__PURE__ */ p({
51
242
  __name: "Textarea",
52
243
  props: {
53
244
  class: {},
54
245
  modelValue: {}
55
246
  },
56
247
  emits: ["update:modelValue", "blur"],
57
- setup(e, { emit: o }) {
58
- const a = e, d = o;
59
- return (l, t) => (n(), m("textarea", {
60
- class: S(s(y)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", a.class)),
248
+ setup(e, { emit: l }) {
249
+ const i = e, n = l;
250
+ return (a, t) => (d(), g("textarea", I(a.$attrs, {
251
+ class: o(w)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", i.class),
61
252
  value: e.modelValue,
62
- onInput: t[0] || (t[0] = (u) => d("update:modelValue", u.target.value)),
63
- onBlur: t[1] || (t[1] = (u) => d("blur", u))
64
- }, null, 42, fe));
253
+ onInput: t[0] || (t[0] = (r) => n("update:modelValue", r.target.value)),
254
+ onBlur: t[1] || (t[1] = (r) => n("blur", r))
255
+ }), null, 16, qe));
65
256
  }
66
- }), be = /* @__PURE__ */ f({
257
+ }), De = /* @__PURE__ */ p({
67
258
  __name: "TextareaRenderer",
68
259
  props: {
69
260
  field: {},
261
+ fieldId: {},
70
262
  modelValue: {},
71
- fieldId: {}
263
+ ariaInvalid: { type: Boolean },
264
+ ariaRequired: { type: Boolean },
265
+ ariaDescribedby: {}
72
266
  },
73
267
  emits: ["update:modelValue"],
74
- setup(e, { emit: o }) {
75
- const a = o;
76
- return (d, l) => (n(), p(pe, {
268
+ setup(e, { emit: l }) {
269
+ const i = l;
270
+ return (n, a) => (d(), v(Pe, {
77
271
  id: e.fieldId,
78
272
  placeholder: e.field.placeholder,
79
- disabled: e.field.disabled,
273
+ disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
80
274
  name: e.field.name,
81
275
  modelValue: e.modelValue ?? "",
82
- "onUpdate:modelValue": l[0] || (l[0] = (t) => a("update:modelValue", t))
276
+ "onUpdate:modelValue": a[0] || (a[0] = (t) => i("update:modelValue", t))
83
277
  }, null, 8, ["id", "placeholder", "disabled", "name", "modelValue"]));
84
278
  }
85
- }), ge = /* @__PURE__ */ f({
279
+ }), Ne = /* @__PURE__ */ p({
86
280
  __name: "SelectTrigger",
87
281
  props: {
88
282
  disabled: { type: Boolean },
@@ -91,18 +285,18 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
91
285
  class: {}
92
286
  },
93
287
  setup(e) {
94
- const o = e, a = h(() => {
95
- const { class: l, ...t } = o;
288
+ const l = e, i = h(() => {
289
+ const { class: a, ...t } = l;
96
290
  return t;
97
- }), d = _(a);
98
- return (l, t) => (n(), p(s(H), V(s(d), {
99
- class: s(y)("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", o.class)
291
+ }), n = j(i);
292
+ return (a, t) => (d(), v(o(ie), I(o(n), {
293
+ class: o(w)("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", l.class)
100
294
  }), {
101
- default: r(() => [
102
- w(l.$slots, "default"),
103
- c(s(J), { "as-child": "" }, {
104
- default: r(() => [
105
- c(s(re), { class: "h-4 w-4 opacity-50" })
295
+ default: m(() => [
296
+ q(a.$slots, "default"),
297
+ b(o(ne), { "as-child": "" }, {
298
+ default: m(() => [
299
+ b(o(ke), { class: "h-4 w-4 opacity-50" })
106
300
  ]),
107
301
  _: 1
108
302
  })
@@ -110,7 +304,7 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
110
304
  _: 3
111
305
  }, 16, ["class"]));
112
306
  }
113
- }), he = /* @__PURE__ */ f({
307
+ }), Ee = /* @__PURE__ */ p({
114
308
  __name: "SelectContent",
115
309
  props: {
116
310
  forceMount: { type: Boolean },
@@ -133,21 +327,21 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
133
327
  class: {}
134
328
  },
135
329
  setup(e) {
136
- const o = e, a = h(() => {
137
- const { class: l, ...t } = o;
330
+ const l = e, i = h(() => {
331
+ const { class: a, ...t } = l;
138
332
  return t;
139
- }), d = _(a);
140
- return (l, t) => (n(), p(s(K), null, {
141
- default: r(() => [
142
- c(s(Q), V(s(d), {
143
- class: s(y)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", e.position === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", o.class)
333
+ }), n = j(i);
334
+ return (a, t) => (d(), v(o(se), null, {
335
+ default: m(() => [
336
+ b(o(re), I(o(n), {
337
+ class: o(w)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", e.position === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", l.class)
144
338
  }), {
145
- default: r(() => [
146
- c(s(X), {
147
- class: S(s(y)("p-1", e.position === "popper" && "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"))
339
+ default: m(() => [
340
+ b(o(oe), {
341
+ class: D(o(w)("p-1", e.position === "popper" && "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"))
148
342
  }, {
149
- default: r(() => [
150
- w(l.$slots, "default")
343
+ default: m(() => [
344
+ q(a.$slots, "default")
151
345
  ]),
152
346
  _: 3
153
347
  }, 8, ["class"])
@@ -158,7 +352,7 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
158
352
  _: 3
159
353
  }));
160
354
  }
161
- }), ye = { class: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center" }, ve = /* @__PURE__ */ f({
355
+ }), Ue = { class: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center" }, je = /* @__PURE__ */ p({
162
356
  __name: "SelectItem",
163
357
  props: {
164
358
  value: {},
@@ -169,28 +363,28 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
169
363
  class: {}
170
364
  },
171
365
  setup(e) {
172
- const o = e, a = h(() => {
173
- const { class: l, ...t } = o;
366
+ const l = e, i = h(() => {
367
+ const { class: a, ...t } = l;
174
368
  return t;
175
- }), d = _(a);
176
- return (l, t) => (n(), p(s(Y), V(s(d), {
177
- class: s(y)(
369
+ }), n = j(i);
370
+ return (a, t) => (d(), v(o(de), I(o(n), {
371
+ class: o(w)(
178
372
  "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
179
- o.class
373
+ l.class
180
374
  )
181
375
  }), {
182
- default: r(() => [
183
- I("span", ye, [
184
- c(s(Z), null, {
185
- default: r(() => [
186
- c(s(U), { class: "h-4 w-4" })
376
+ default: m(() => [
377
+ O("span", Ue, [
378
+ b(o(ue), null, {
379
+ default: m(() => [
380
+ b(o(K), { class: "h-4 w-4" })
187
381
  ]),
188
382
  _: 1
189
383
  })
190
384
  ]),
191
- c(s(ee), null, {
192
- default: r(() => [
193
- w(l.$slots, "default")
385
+ b(o(ce), null, {
386
+ default: m(() => [
387
+ q(a.$slots, "default")
194
388
  ]),
195
389
  _: 3
196
390
  })
@@ -198,7 +392,7 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
198
392
  _: 3
199
393
  }, 16, ["class"]));
200
394
  }
201
- }), xe = /* @__PURE__ */ f({
395
+ }), Ae = /* @__PURE__ */ p({
202
396
  __name: "Select",
203
397
  props: {
204
398
  open: { type: Boolean },
@@ -212,48 +406,51 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
212
406
  required: { type: Boolean }
213
407
  },
214
408
  emits: ["update:modelValue", "update:open"],
215
- setup(e, { emit: o }) {
216
- const l = P(e, o);
217
- return (t, u) => (n(), p(s(te), z(N(s(l))), {
218
- default: r(() => [
219
- w(t.$slots, "default")
409
+ setup(e, { emit: l }) {
410
+ const a = A(e, l);
411
+ return (t, r) => (d(), v(o(me), X(Y(o(a))), {
412
+ default: m(() => [
413
+ q(t.$slots, "default")
220
414
  ]),
221
415
  _: 3
222
416
  }, 16));
223
417
  }
224
- }), Ve = /* @__PURE__ */ f({
418
+ }), Me = /* @__PURE__ */ p({
225
419
  __name: "SelectRenderer",
226
420
  props: {
227
421
  field: {},
422
+ fieldId: {},
228
423
  modelValue: {},
229
- fieldId: {}
424
+ ariaInvalid: { type: Boolean },
425
+ ariaRequired: { type: Boolean },
426
+ ariaDescribedby: {}
230
427
  },
231
428
  emits: ["update:modelValue"],
232
- setup(e, { emit: o }) {
233
- const a = o;
234
- return (d, l) => (n(), p(xe, {
235
- disabled: e.field.disabled,
429
+ setup(e, { emit: l }) {
430
+ const i = l;
431
+ return (n, a) => (d(), v(Ae, {
432
+ disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
236
433
  name: e.field.name,
237
434
  modelValue: e.modelValue != null ? String(e.modelValue) : "",
238
- "onUpdate:modelValue": l[0] || (l[0] = (t) => a("update:modelValue", t))
435
+ "onUpdate:modelValue": a[0] || (a[0] = (t) => i("update:modelValue", t))
239
436
  }, {
240
- default: r(() => [
241
- c(ge, { id: e.fieldId }, {
242
- default: r(() => [
243
- c(s(le), {
437
+ default: m(() => [
438
+ b(Ne, { id: e.fieldId }, {
439
+ default: m(() => [
440
+ b(o(fe), {
244
441
  placeholder: e.field.placeholder || "Select an option"
245
442
  }, null, 8, ["placeholder"])
246
443
  ]),
247
444
  _: 1
248
445
  }, 8, ["id"]),
249
- c(he, null, {
250
- default: r(() => [
251
- (n(!0), m($, null, B(e.field.options, (t) => (n(), p(ve, {
446
+ b(Ee, null, {
447
+ default: m(() => [
448
+ (d(!0), g(N, null, E(e.field.options, (t) => (d(), v(je, {
252
449
  key: t.value,
253
450
  value: String(t.value)
254
451
  }, {
255
- default: r(() => [
256
- C(v(t.label), 1)
452
+ default: m(() => [
453
+ U(F(t.label), 1)
257
454
  ]),
258
455
  _: 2
259
456
  }, 1032, ["value"]))), 128))
@@ -264,7 +461,7 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
264
461
  _: 1
265
462
  }, 8, ["disabled", "name", "modelValue"]));
266
463
  }
267
- }), ke = /* @__PURE__ */ f({
464
+ }), Oe = /* @__PURE__ */ p({
268
465
  __name: "Checkbox",
269
466
  props: {
270
467
  defaultChecked: { type: Boolean },
@@ -279,19 +476,19 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
279
476
  class: {}
280
477
  },
281
478
  emits: ["update:checked", "blur"],
282
- setup(e, { emit: o }) {
283
- const a = e, d = o, l = h(() => {
284
- const { class: u, ...i } = a;
285
- return i;
286
- }), t = P(l, d);
287
- return (u, i) => (n(), p(s(ae), V(s(t), {
288
- class: s(y)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground", a.class),
289
- onBlur: i[0] || (i[0] = (b) => d("blur"))
479
+ setup(e, { emit: l }) {
480
+ const i = e, n = l, a = h(() => {
481
+ const { class: r, ...s } = i;
482
+ return s;
483
+ }), t = A(a, n);
484
+ return (r, s) => (d(), v(o(be), I(o(t), {
485
+ class: o(w)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground", i.class),
486
+ onBlur: s[0] || (s[0] = (u) => n("blur"))
290
487
  }), {
291
- default: r(() => [
292
- c(s(oe), { class: "flex h-full w-full items-center justify-center text-current" }, {
293
- default: r(() => [
294
- c(s(U), { class: "h-4 w-4" })
488
+ default: m(() => [
489
+ b(o(pe), { class: "flex h-full w-full items-center justify-center text-current" }, {
490
+ default: m(() => [
491
+ b(o(K), { class: "h-4 w-4" })
295
492
  ]),
296
493
  _: 1
297
494
  })
@@ -299,7 +496,7 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
299
496
  _: 1
300
497
  }, 16, ["class"]));
301
498
  }
302
- }), R = /* @__PURE__ */ f({
499
+ }), T = /* @__PURE__ */ p({
303
500
  __name: "Label",
304
501
  props: {
305
502
  for: {},
@@ -308,62 +505,65 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
308
505
  class: {}
309
506
  },
310
507
  setup(e) {
311
- const o = e, a = h(() => {
312
- const { class: d, ...l } = o;
313
- return l;
508
+ const l = e, i = h(() => {
509
+ const { class: n, ...a } = l;
510
+ return a;
314
511
  });
315
- return (d, l) => (n(), p(s(se), V(a.value, {
316
- class: s(y)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", o.class)
512
+ return (n, a) => (d(), v(o(ge), I(i.value, {
513
+ class: o(w)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", l.class)
317
514
  }), {
318
- default: r(() => [
319
- w(d.$slots, "default")
515
+ default: m(() => [
516
+ q(n.$slots, "default")
320
517
  ]),
321
518
  _: 3
322
519
  }, 16, ["class"]));
323
520
  }
324
- }), we = { class: "flex flex-wrap gap-4" }, $e = /* @__PURE__ */ f({
521
+ }), ze = { class: "flex flex-wrap gap-4" }, Te = /* @__PURE__ */ p({
325
522
  __name: "CheckboxRenderer",
326
523
  props: {
327
524
  field: {},
525
+ fieldId: {},
328
526
  modelValue: {},
329
- fieldId: {}
527
+ ariaInvalid: { type: Boolean },
528
+ ariaRequired: { type: Boolean },
529
+ ariaDescribedby: {}
330
530
  },
331
531
  emits: ["update:modelValue"],
332
- setup(e, { emit: o }) {
333
- const a = e, d = o, l = (t, u) => {
334
- const i = Array.isArray(a.modelValue) ? [...a.modelValue] : [];
335
- if (u)
336
- i.push(t);
532
+ setup(e, { emit: l }) {
533
+ const i = e, n = l, a = (t, r) => {
534
+ const s = Array.isArray(i.modelValue) ? [...i.modelValue] : [];
535
+ if (r)
536
+ s.push(t);
337
537
  else {
338
- const b = i.indexOf(t);
339
- b > -1 && i.splice(b, 1);
538
+ const u = s.indexOf(t);
539
+ u > -1 && s.splice(u, 1);
340
540
  }
341
- d("update:modelValue", i);
541
+ n("update:modelValue", s);
342
542
  };
343
- return (t, u) => (n(), m("div", we, [
344
- (n(!0), m($, null, B(e.field.options, (i) => (n(), m("div", {
345
- key: i.value,
543
+ return (t, r) => (d(), g("div", ze, [
544
+ (d(!0), g(N, null, E(e.field.options, (s) => (d(), g("div", {
545
+ key: s.value,
346
546
  class: "flex items-center space-x-2"
347
547
  }, [
348
- c(ke, {
349
- id: `checkbox-${e.field.name}-${i.value}`,
350
- disabled: e.field.disabled,
351
- checked: Array.isArray(e.modelValue) && e.modelValue.includes(i.value),
352
- "onUpdate:checked": (b) => l(i.value, !!b)
548
+ b(Oe, {
549
+ id: `checkbox-${e.field.name}-${s.value}`,
550
+ disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
551
+ checked: Array.isArray(e.modelValue) && e.modelValue.includes(s.value),
552
+ "onUpdate:checked": (u) => a(s.value, !!u)
353
553
  }, null, 8, ["id", "disabled", "checked", "onUpdate:checked"]),
354
- c(R, {
355
- for: `checkbox-${e.field.name}-${i.value}`,
554
+ b(T, {
555
+ for: `checkbox-${e.field.name}-${s.value}`,
356
556
  class: "font-normal"
357
557
  }, {
358
- default: r(() => [
359
- C(v(i.label), 1)
558
+ default: m(() => [
559
+ U(F(s.label), 1)
360
560
  ]),
361
561
  _: 2
362
562
  }, 1032, ["for"])
363
563
  ]))), 128))
364
564
  ]));
365
565
  }
366
- }), Se = /* @__PURE__ */ f({
566
+ }), Ge = /* @__PURE__ */ p({
367
567
  __name: "RadioGroupItem",
368
568
  props: {
369
569
  id: {},
@@ -376,17 +576,17 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
376
576
  class: {}
377
577
  },
378
578
  setup(e) {
379
- const o = e, a = h(() => {
380
- const { class: l, ...t } = o;
579
+ const l = e, i = h(() => {
580
+ const { class: a, ...t } = l;
381
581
  return t;
382
- }), d = _(a);
383
- return (l, t) => (n(), p(s(de), V(s(d), {
384
- class: s(y)("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", o.class)
582
+ }), n = j(i);
583
+ return (a, t) => (d(), v(o(ye), I(o(n), {
584
+ class: o(w)("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", l.class)
385
585
  }), {
386
- default: r(() => [
387
- c(s(ne), { class: "flex items-center justify-center" }, {
388
- default: r(() => [
389
- c(s(ue), { class: "h-2.5 w-2.5 fill-current text-current" })
586
+ default: m(() => [
587
+ b(o(ve), { class: "flex items-center justify-center" }, {
588
+ default: m(() => [
589
+ b(o(we), { class: "h-2.5 w-2.5 fill-current text-current" })
390
590
  ]),
391
591
  _: 1
392
592
  })
@@ -394,7 +594,7 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
394
594
  _: 1
395
595
  }, 16, ["class"]));
396
596
  }
397
- }), Be = /* @__PURE__ */ f({
597
+ }), Le = /* @__PURE__ */ p({
398
598
  __name: "RadioGroup",
399
599
  props: {
400
600
  modelValue: {},
@@ -410,52 +610,55 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
410
610
  class: {}
411
611
  },
412
612
  emits: ["update:modelValue"],
413
- setup(e, { emit: o }) {
414
- const a = e, d = o, l = h(() => {
415
- const { class: u, ...i } = a;
416
- return i;
417
- }), t = P(l, d);
418
- return (u, i) => (n(), p(s(ie), V(s(t), {
419
- class: s(y)("grid gap-2", a.class)
613
+ setup(e, { emit: l }) {
614
+ const i = e, n = l, a = h(() => {
615
+ const { class: r, ...s } = i;
616
+ return s;
617
+ }), t = A(a, n);
618
+ return (r, s) => (d(), v(o(he), I(o(t), {
619
+ class: o(w)("grid gap-2", i.class)
420
620
  }), {
421
- default: r(() => [
422
- w(u.$slots, "default")
621
+ default: m(() => [
622
+ q(r.$slots, "default")
423
623
  ]),
424
624
  _: 3
425
625
  }, 16, ["class"]));
426
626
  }
427
- }), Ce = /* @__PURE__ */ f({
627
+ }), He = /* @__PURE__ */ p({
428
628
  __name: "RadioRenderer",
429
629
  props: {
430
630
  field: {},
631
+ fieldId: {},
431
632
  modelValue: {},
432
- fieldId: {}
633
+ ariaInvalid: { type: Boolean },
634
+ ariaRequired: { type: Boolean },
635
+ ariaDescribedby: {}
433
636
  },
434
637
  emits: ["update:modelValue"],
435
- setup(e, { emit: o }) {
436
- const a = o;
437
- return (d, l) => (n(), p(Be, {
638
+ setup(e, { emit: l }) {
639
+ const i = l;
640
+ return (n, a) => (d(), v(Le, {
438
641
  class: "flex flex-wrap gap-4",
439
- disabled: e.field.disabled,
642
+ disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
440
643
  name: e.field.name,
441
644
  modelValue: e.modelValue != null ? String(e.modelValue) : "",
442
- "onUpdate:modelValue": l[0] || (l[0] = (t) => a("update:modelValue", t))
645
+ "onUpdate:modelValue": a[0] || (a[0] = (t) => i("update:modelValue", t))
443
646
  }, {
444
- default: r(() => [
445
- (n(!0), m($, null, B(e.field.options, (t) => (n(), m("div", {
647
+ default: m(() => [
648
+ (d(!0), g(N, null, E(e.field.options, (t) => (d(), g("div", {
446
649
  key: t.value,
447
650
  class: "flex items-center space-x-2"
448
651
  }, [
449
- c(Se, {
652
+ b(Ge, {
450
653
  id: `radio-${e.field.name}-${t.value}`,
451
654
  value: String(t.value)
452
655
  }, null, 8, ["id", "value"]),
453
- c(R, {
656
+ b(T, {
454
657
  for: `radio-${e.field.name}-${t.value}`,
455
658
  class: "font-normal"
456
659
  }, {
457
- default: r(() => [
458
- C(v(t.label), 1)
660
+ default: m(() => [
661
+ U(F(t.label), 1)
459
662
  ]),
460
663
  _: 2
461
664
  }, 1032, ["for"])
@@ -464,23 +667,109 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
464
667
  _: 1
465
668
  }, 8, ["disabled", "name", "modelValue"]));
466
669
  }
467
- }), F = {
468
- text: k,
469
- number: k,
470
- password: k,
471
- email: k,
472
- date: k,
473
- textarea: be,
474
- select: Ve,
475
- checkbox: $e,
476
- radio: Ce
477
- }, _e = {
478
- key: 1,
479
- class: "text-[0.8rem] text-muted-foreground"
480
- }, Ie = {
481
- key: 2,
482
- class: "text-[0.8rem] font-medium text-destructive"
483
- }, Pe = /* @__PURE__ */ f({
670
+ }), Ke = /* @__PURE__ */ p({
671
+ __name: "DateRenderer",
672
+ props: {
673
+ field: {},
674
+ modelValue: {},
675
+ fieldId: {},
676
+ ariaInvalid: { type: Boolean },
677
+ ariaRequired: { type: Boolean },
678
+ ariaDescribedby: {}
679
+ },
680
+ emits: ["update:modelValue", "blur"],
681
+ setup(e, { emit: l }) {
682
+ const i = l;
683
+ return (n, a) => (d(), v(Q, {
684
+ id: e.fieldId,
685
+ type: "date",
686
+ modelValue: e.modelValue,
687
+ placeholder: e.field.placeholder,
688
+ disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
689
+ name: e.field.name,
690
+ "aria-invalid": e.ariaInvalid,
691
+ "aria-required": e.ariaRequired,
692
+ "aria-describedby": e.ariaDescribedby,
693
+ "onUpdate:modelValue": a[0] || (a[0] = (t) => i("update:modelValue", t)),
694
+ onBlur: a[1] || (a[1] = (t) => i("blur", t))
695
+ }, null, 8, ["id", "modelValue", "placeholder", "disabled", "name", "aria-invalid", "aria-required", "aria-describedby"]));
696
+ }
697
+ }), We = /* @__PURE__ */ p({
698
+ __name: "Switch",
699
+ props: {
700
+ defaultChecked: { type: Boolean },
701
+ checked: { type: Boolean },
702
+ disabled: { type: Boolean },
703
+ required: { type: Boolean },
704
+ name: {},
705
+ id: {},
706
+ value: {},
707
+ asChild: { type: Boolean },
708
+ as: {},
709
+ class: {}
710
+ },
711
+ emits: ["update:checked"],
712
+ setup(e, { emit: l }) {
713
+ const i = e, n = l, a = h(() => {
714
+ const { class: r, ...s } = i;
715
+ return s;
716
+ }), t = A(a, n);
717
+ return (r, s) => (d(), v(o(xe), I(o(t), {
718
+ class: o(w)(
719
+ "peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
720
+ i.class
721
+ )
722
+ }), {
723
+ default: m(() => [
724
+ b(o(Ve), {
725
+ class: D(o(w)(
726
+ "pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"
727
+ ))
728
+ }, null, 8, ["class"])
729
+ ]),
730
+ _: 1
731
+ }, 16, ["class"]));
732
+ }
733
+ }), Je = { class: "flex items-center space-x-2" }, Qe = /* @__PURE__ */ p({
734
+ __name: "SwitchRenderer",
735
+ props: {
736
+ field: {},
737
+ modelValue: { type: Boolean },
738
+ fieldId: {},
739
+ ariaInvalid: { type: Boolean },
740
+ ariaRequired: { type: Boolean },
741
+ ariaDescribedby: {}
742
+ },
743
+ emits: ["update:modelValue", "blur"],
744
+ setup(e, { emit: l }) {
745
+ const i = l;
746
+ return (n, a) => (d(), g("div", Je, [
747
+ b(We, {
748
+ id: e.fieldId,
749
+ checked: e.modelValue,
750
+ disabled: typeof e.field.disabled == "boolean" ? e.field.disabled : void 0,
751
+ "aria-invalid": e.ariaInvalid,
752
+ "aria-required": e.ariaRequired,
753
+ "aria-describedby": e.ariaDescribedby,
754
+ "onUpdate:checked": a[0] || (a[0] = (t) => i("update:modelValue", t))
755
+ }, null, 8, ["id", "checked", "disabled", "aria-invalid", "aria-required", "aria-describedby"])
756
+ ]));
757
+ }
758
+ }), H = {
759
+ text: P,
760
+ number: P,
761
+ password: P,
762
+ email: P,
763
+ textarea: De,
764
+ select: Me,
765
+ checkbox: Te,
766
+ radio: He,
767
+ date: Ke,
768
+ switch: Qe
769
+ }, Xe = {
770
+ key: 0,
771
+ class: "text-destructive"
772
+ }, Ye = ["id"], Ze = ["id"], _e = /* @__PURE__ */ p({
484
773
  __name: "FormFieldRenderer",
485
774
  props: {
486
775
  field: {},
@@ -488,89 +777,153 @@ const ce = ["type", "value"], me = /* @__PURE__ */ f({
488
777
  error: {},
489
778
  componentMap: {}
490
779
  },
491
- emits: ["update:modelValue"],
492
- setup(e, { emit: o }) {
493
- const a = e, d = o, l = h(() => `field-${a.field.name}`), t = h(
494
- () => a.componentMap ? { ...F, ...a.componentMap } : F
495
- ), u = h(
496
- () => t.value[a.field.type] ?? k
780
+ emits: ["update:modelValue", "blur"],
781
+ setup(e, { emit: l }) {
782
+ const i = e, n = l, a = h(() => `field-${i.field.name}`), t = h(() => `${a.value}-description`), r = h(() => `${a.value}-error`), s = h(() => {
783
+ var c;
784
+ return (c = i.field.validations) == null ? void 0 : c.some((x) => x.type === "required");
785
+ }), u = h(() => {
786
+ const c = [];
787
+ return i.field.description && c.push(t.value), i.error && c.push(r.value), c.length > 0 ? c.join(" ") : void 0;
788
+ }), f = h(
789
+ () => i.componentMap ? { ...H, ...i.componentMap } : H
790
+ ), $ = h(
791
+ () => f.value[i.field.type] ?? P
497
792
  );
498
- return (i, b) => (n(), m("div", {
499
- class: S(["space-y-2", e.field.className])
793
+ return (c, x) => (d(), g("div", {
794
+ class: D(["space-y-2", e.field.className])
500
795
  }, [
501
- e.field.label ? (n(), p(R, {
796
+ e.field.label ? (d(), v(T, {
502
797
  key: 0,
503
- for: l.value
798
+ for: a.value,
799
+ class: D(s.value ? "flex items-center gap-1" : "")
504
800
  }, {
505
- default: r(() => [
506
- C(v(e.field.label), 1)
801
+ default: m(() => [
802
+ U(F(e.field.label) + " ", 1),
803
+ s.value ? (d(), g("span", Xe, "*")) : R("", !0)
507
804
  ]),
508
805
  _: 1
509
- }, 8, ["for"])) : x("", !0),
510
- (n(), p(T(u.value), {
806
+ }, 8, ["for", "class"])) : R("", !0),
807
+ (d(), v(Z($.value), {
511
808
  field: e.field,
512
- fieldId: l.value,
809
+ fieldId: a.value,
513
810
  modelValue: e.modelValue,
514
- "onUpdate:modelValue": b[0] || (b[0] = (g) => d("update:modelValue", g))
515
- }, null, 8, ["field", "fieldId", "modelValue"])),
516
- e.field.description ? (n(), m("p", _e, v(e.field.description), 1)) : x("", !0),
517
- e.error ? (n(), m("p", Ie, v(e.error), 1)) : x("", !0)
811
+ "aria-invalid": !!e.error,
812
+ "aria-required": s.value,
813
+ "aria-describedby": u.value,
814
+ "onUpdate:modelValue": x[0] || (x[0] = (V) => n("update:modelValue", V)),
815
+ onBlur: x[1] || (x[1] = (V) => n("blur", V))
816
+ }, null, 40, ["field", "fieldId", "modelValue", "aria-invalid", "aria-required", "aria-describedby"])),
817
+ e.field.description ? (d(), g("p", {
818
+ key: 1,
819
+ id: t.value,
820
+ class: "text-[0.8rem] text-muted-foreground"
821
+ }, F(e.field.description), 9, Ye)) : R("", !0),
822
+ e.error ? (d(), g("p", {
823
+ key: 2,
824
+ id: r.value,
825
+ class: "text-[0.8rem] font-medium text-destructive"
826
+ }, F(e.error), 9, Ze)) : R("", !0)
518
827
  ], 2));
519
828
  }
520
- }), Re = {
829
+ });
830
+ function et({ schema: e }) {
831
+ const l = Re(e.fields, e.resolver, e.errorMessages), i = _(l.getState()), n = l.subscribe((u) => {
832
+ i.value = u;
833
+ });
834
+ return ee(() => {
835
+ n();
836
+ }), {
837
+ store: l,
838
+ state: i,
839
+ // This is a Ref
840
+ setValue: async (u, f) => {
841
+ await l.getState().setFieldValue(u, f);
842
+ },
843
+ getValue: (u) => M(i.value.values, u),
844
+ validate: async () => {
845
+ const { hasError: u, state: f } = await l.getState().runSubmitValidation();
846
+ return { hasError: u, values: f.values };
847
+ },
848
+ reset: () => {
849
+ l.setState({
850
+ values: {},
851
+ errors: {},
852
+ isSubmitting: !1
853
+ });
854
+ }
855
+ };
856
+ }
857
+ const tt = {
521
858
  key: 0,
522
859
  class: "space-y-1"
523
- }, Fe = {
860
+ }, at = {
524
861
  key: 0,
525
862
  class: "text-2xl font-bold tracking-tight"
526
- }, Ue = {
863
+ }, lt = {
527
864
  key: 1,
528
865
  class: "text-muted-foreground"
529
- }, Me = { class: "space-y-4" }, ze = ["disabled"], Ae = /* @__PURE__ */ f({
866
+ }, it = { class: "space-y-4" }, nt = ["disabled"], ct = /* @__PURE__ */ p({
530
867
  __name: "DynamicForm",
531
868
  props: {
532
869
  schema: {},
533
- className: {}
870
+ className: {},
871
+ form: {}
534
872
  },
535
873
  emits: ["submit"],
536
- setup(e, { emit: o }) {
537
- const a = e, d = o, l = D(G(a.schema.fields)), t = (i, b) => {
538
- l.value = A(a.schema.fields, l.value, i, b);
539
- }, u = () => {
540
- const i = E(l.value, !0), { state: b, hasError: g } = L(a.schema.fields, i);
541
- l.value = b, g || d("submit", { ...b.values });
542
- };
543
- return (i, b) => (n(), m("form", {
544
- class: S(["space-y-6", e.className]),
545
- onSubmit: j(u, ["prevent"])
874
+ setup(e, { emit: l }) {
875
+ const i = e, n = l, a = et({ schema: i.schema }), t = i.form || a, { store: r, state: s } = t, u = async (y, C) => {
876
+ await r.getState().setFieldValue(y, C);
877
+ }, f = async (y) => {
878
+ await r.getState().setFieldBlur(y);
879
+ }, $ = (y) => typeof y.hidden == "function" ? y.hidden(s.value.values) : !!y.hidden, c = (y) => {
880
+ const C = typeof y.disabled == "function" ? y.disabled(s.value.values) : !!y.disabled, k = s.value.validatingFields.includes(y.name);
881
+ return { ...y, disabled: C || k };
882
+ }, x = async () => {
883
+ const { hasError: y, values: C } = await t.validate();
884
+ if (y) {
885
+ const k = i.schema.fields.find((B) => s.value.errors[B.name]);
886
+ if (k) {
887
+ const B = document.getElementById(`field-${k.name}`);
888
+ B == null || B.focus(), B == null || B.scrollIntoView({ behavior: "smooth", block: "center" });
889
+ }
890
+ return;
891
+ }
892
+ await n("submit", C);
893
+ }, V = h(() => s.value.validatingFields.length > 0);
894
+ return (y, C) => (d(), g("form", {
895
+ class: D(["space-y-6", e.className]),
896
+ onSubmit: te(x, ["prevent"])
546
897
  }, [
547
- e.schema.title || e.schema.description ? (n(), m("div", Re, [
548
- e.schema.title ? (n(), m("h2", Fe, v(e.schema.title), 1)) : x("", !0),
549
- e.schema.description ? (n(), m("p", Ue, v(e.schema.description), 1)) : x("", !0)
550
- ])) : x("", !0),
551
- I("div", Me, [
552
- (n(!0), m($, null, B(e.schema.fields, (g) => (n(), m($, {
553
- key: g.id
898
+ e.schema.title || e.schema.description ? (d(), g("div", tt, [
899
+ e.schema.title ? (d(), g("h2", at, F(e.schema.title), 1)) : R("", !0),
900
+ e.schema.description ? (d(), g("p", lt, F(e.schema.description), 1)) : R("", !0)
901
+ ])) : R("", !0),
902
+ O("div", it, [
903
+ (d(!0), g(N, null, E(e.schema.fields, (k) => (d(), g(N, {
904
+ key: k.id
554
905
  }, [
555
- g.hidden ? x("", !0) : (n(), p(Pe, {
906
+ $(k) ? R("", !0) : (d(), v(_e, {
556
907
  key: 0,
557
- field: g,
558
- "model-value": l.value.values[g.name],
559
- error: l.value.errors[g.name],
560
- "onUpdate:modelValue": (M) => t(g.name, M)
561
- }, null, 8, ["field", "model-value", "error", "onUpdate:modelValue"]))
908
+ field: c(k),
909
+ "model-value": o(M)(o(s).values, k.name),
910
+ error: o(s).errors[k.name],
911
+ "onUpdate:modelValue": (B) => u(k.name, B),
912
+ onBlur: (B) => f(k.name)
913
+ }, null, 8, ["field", "model-value", "error", "onUpdate:modelValue", "onBlur"]))
562
914
  ], 64))), 128))
563
915
  ]),
564
- I("button", {
916
+ O("button", {
565
917
  type: "submit",
566
- disabled: l.value.isSubmitting,
918
+ disabled: o(s).isSubmitting || V.value,
567
919
  class: "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full"
568
- }, v(l.value.isSubmitting ? "Submitting..." : e.schema.submitButtonText || "Submit"), 9, ze)
920
+ }, F(o(s).isSubmitting ? "Submitting..." : V.value ? "Validating..." : e.schema.submitButtonText || "Submit"), 9, nt)
569
921
  ], 34));
570
922
  }
571
923
  });
572
924
  export {
573
- Ae as DynamicForm,
574
- Pe as FormFieldRenderer,
575
- F as defaultComponentMap
925
+ ct as DynamicForm,
926
+ _e as FormFieldRenderer,
927
+ H as defaultComponentMap,
928
+ et as useForm
576
929
  };