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