asterui 0.12.68 → 0.12.70

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,5 +1,5 @@
1
1
  import { default as React } from 'react';
2
- import { UseFormReturn, FieldValues, SubmitHandler, UseFormProps, FieldArrayPath, FieldArray } from 'react-hook-form';
2
+ import { UseFormReturn, FieldValues, SubmitHandler, UseFormProps, FieldArrayPath, FieldArray, useWatch } from 'react-hook-form';
3
3
  export interface FormProps<TFieldValues extends FieldValues = FieldValues> extends Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onSubmit'> {
4
4
  form?: UseFormReturn<TFieldValues>;
5
5
  onFinish?: SubmitHandler<TFieldValues>;
@@ -94,7 +94,7 @@ export interface FormListProps<TFieldValues extends FieldValues = FieldValues> {
94
94
  declare function FormRoot<TFieldValues extends FieldValues = FieldValues>({ form: externalForm, onFinish, onFinishFailed, initialValues, layout, labelWidth, size, disabled, children, className, noValidate, ...props }: FormProps<TFieldValues>): import("react/jsx-runtime").JSX.Element;
95
95
  declare function FormItem({ name, label, floatingLabel, help, required, rules, valuePropName, inline, className, children, tooltip, extra, hasFeedback, dependencies, validateTrigger, initialValue, hidden, addonBefore, addonAfter, 'data-testid': testId, }: FormItemProps): import("react/jsx-runtime").JSX.Element;
96
96
  declare function FormList<TFieldValues extends FieldValues = FieldValues>({ name, children, }: FormListProps<TFieldValues>): import("react/jsx-runtime").JSX.Element;
97
- export declare function useFormInstance<TFieldValues extends FieldValues = FieldValues>(): UseFormReturn<TFieldValues, any, TFieldValues> & {
97
+ export declare function useFormInstance<TFieldValues extends FieldValues = FieldValues>(options?: UseFormProps<TFieldValues>): UseFormReturn<TFieldValues, any, TFieldValues> & {
98
98
  setFieldValue: import('react-hook-form').UseFormSetValue<TFieldValues>;
99
99
  getFieldValue: (name: any) => any;
100
100
  getFieldsValue: import('react-hook-form').UseFormGetValues<TFieldValues>;
@@ -118,5 +118,8 @@ export declare const Form: typeof FormRoot & {
118
118
  List: typeof FormList;
119
119
  ErrorList: typeof FormErrorList;
120
120
  useForm: typeof useFormInstance;
121
+ useWatch: typeof useWatch;
121
122
  };
123
+ export declare const useForm: typeof useFormInstance;
124
+ export { useWatch };
122
125
  export type { UseFormReturn as FormInstance };
@@ -1,8 +1,9 @@
1
1
  import { jsx as t, jsxs as E } from "react/jsx-runtime";
2
- import { createContext as be, useId as ae, useEffect as ie, useRef as K, isValidElement as U, cloneElement as $e, useContext as Ne } from "react";
3
- import { useForm as ce, useFieldArray as Fe, useWatch as ke, Controller as Ve } from "react-hook-form";
4
- import { useConfig as we } from "../providers/ConfigProvider.js";
5
- const Ce = "input", Le = "input-xs", Ee = "input-sm", Ae = "input-md", Se = "input-lg", je = "input-xl", ze = "floating-label", Me = "loading", Pe = "loading-spinner", Re = "loading-xs", Te = "tooltip", Be = "tooltip-top", le = "validator-hint", G = be(void 0), Y = {
2
+ import { createContext as Fe, useId as ae, useEffect as ie, useRef as O, isValidElement as U, cloneElement as Ne, useContext as ke } from "react";
3
+ import { useWatch as ce, useForm as de, useFieldArray as Ve, Controller as we } from "react-hook-form";
4
+ import { useWatch as et } from "react-hook-form";
5
+ import { useConfig as Ce } from "../providers/ConfigProvider.js";
6
+ const Le = "input", Ee = "input-xs", Ae = "input-sm", Se = "input-md", je = "input-lg", ze = "input-xl", Me = "floating-label", Pe = "loading", Re = "loading-spinner", Te = "loading-xs", We = "tooltip", Be = "tooltip-top", le = "validator-hint", G = Fe(void 0), Y = {
6
7
  email: {
7
8
  value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
8
9
  message: "Please enter a valid email address"
@@ -17,285 +18,293 @@ const Ce = "input", Le = "input-xs", Ee = "input-sm", Ae = "input-md", Se = "inp
17
18
  }
18
19
  };
19
20
  function Q() {
20
- const s = Ne(G);
21
- if (!s)
21
+ const i = ke(G);
22
+ if (!i)
22
23
  throw new Error("Form compound components must be used within Form");
23
- return s;
24
+ return i;
24
25
  }
25
26
  function Ie({
26
- form: s,
27
+ form: i,
27
28
  onFinish: a,
28
- onFinishFailed: r,
29
- initialValues: i,
30
- layout: $ = "vertical",
31
- labelWidth: g = 60,
29
+ onFinishFailed: s,
30
+ initialValues: n,
31
+ layout: m = "vertical",
32
+ labelWidth: p = 60,
32
33
  size: w,
33
- disabled: x = !1,
34
- children: c,
34
+ disabled: y = !1,
35
+ children: d,
35
36
  className: l = "",
36
- noValidate: y = !0,
37
+ noValidate: $ = !0,
37
38
  ...b
38
39
  }) {
39
- const { componentSize: N } = we(), u = w ?? N ?? "md", z = ce({
40
- defaultValues: i
41
- }), F = s || z, I = async (C) => {
42
- if (C.preventDefault(), await F.trigger())
43
- a && a(F.getValues());
44
- else if (r) {
45
- const d = F.formState.errors, k = [], M = (P, W = "") => {
40
+ const { componentSize: F } = Ce(), f = w ?? F ?? "md", z = de({
41
+ defaultValues: n
42
+ }), N = i || z, I = async (C) => {
43
+ if (C.preventDefault(), await N.trigger())
44
+ a && a(N.getValues());
45
+ else if (s) {
46
+ const u = N.formState.errors, k = [], M = (P, D = "") => {
46
47
  for (const R in P) {
47
- const T = W ? `${W}.${R}` : R, V = P[R];
48
+ const T = D ? `${D}.${R}` : R, V = P[R];
48
49
  V?.message ? k.push({ name: T, errors: [V.message] }) : typeof V == "object" && V !== null && M(V, T);
49
50
  }
50
51
  };
51
- M(d), r({ values: F.getValues(), errorFields: k });
52
+ M(u), s({ values: N.getValues(), errorFields: k });
52
53
  }
53
54
  }, S = (C) => {
54
- C.preventDefault(), F.reset(i);
55
+ C.preventDefault(), N.reset(n);
55
56
  };
56
- return /* @__PURE__ */ t(G.Provider, { value: { form: F, layout: $, labelWidth: g, size: u, disabled: x }, children: /* @__PURE__ */ t("form", { onSubmit: I, onReset: S, className: l, noValidate: y, ...b, children: c }) });
57
+ return /* @__PURE__ */ t(G.Provider, { value: { form: N, layout: m, labelWidth: p, size: f, disabled: y }, children: /* @__PURE__ */ t("form", { onSubmit: I, onReset: S, className: l, noValidate: $, ...b, children: d }) });
57
58
  }
58
- function We({
59
- name: s,
59
+ function De({
60
+ name: i,
60
61
  label: a,
61
- floatingLabel: r,
62
- help: i,
63
- required: $ = !1,
64
- rules: g,
62
+ floatingLabel: s,
63
+ help: n,
64
+ required: m = !1,
65
+ rules: p,
65
66
  valuePropName: w = "value",
66
- inline: x = !1,
67
- className: c = "",
67
+ inline: y = !1,
68
+ className: d = "",
68
69
  children: l,
69
- tooltip: y,
70
+ tooltip: $,
70
71
  extra: b,
71
- hasFeedback: N = !1,
72
- dependencies: u,
72
+ hasFeedback: F = !1,
73
+ dependencies: f,
73
74
  validateTrigger: z = "onChange",
74
- initialValue: F,
75
+ initialValue: N,
75
76
  hidden: I = !1,
76
77
  addonBefore: S,
77
78
  addonAfter: C,
78
- "data-testid": f
79
+ "data-testid": h
79
80
  }) {
80
- const { form: d, size: k, listName: M, layout: P, labelWidth: W, disabled: R } = Q(), T = ae(), V = ae();
81
- if (!s)
82
- return /* @__PURE__ */ t("div", { className: `${x ? "w-auto" : "w-full"} ${c}`, style: I ? { display: "none" } : void 0, children: l });
83
- let h;
84
- Array.isArray(s) ? h = (M ? [M, ...s] : s).join(".") : h = s, ie(() => {
85
- F !== void 0 && d.getValues(h) === void 0 && d.setValue(h, F);
81
+ const { form: u, size: k, listName: M, layout: P, labelWidth: D, disabled: R } = Q(), T = ae(), V = ae();
82
+ if (!i)
83
+ return /* @__PURE__ */ t("div", { className: `${y ? "w-auto" : "w-full"} ${d}`, style: I ? { display: "none" } : void 0, children: l });
84
+ let g;
85
+ Array.isArray(i) ? g = (M ? [M, ...i] : i).join(".") : g = i, ie(() => {
86
+ N !== void 0 && u.getValues(g) === void 0 && u.setValue(g, N);
86
87
  }, []);
87
- const O = ke({
88
- control: d.control,
89
- name: u,
90
- disabled: !u || u.length === 0
91
- }), _ = K(d);
92
- _.current = d;
93
- const D = K(void 0);
88
+ const X = ce({
89
+ control: u.control,
90
+ name: f,
91
+ disabled: !f || f.length === 0
92
+ }), H = O(u);
93
+ H.current = u;
94
+ const Z = O(void 0);
94
95
  ie(() => {
95
- if (!u || u.length === 0) return;
96
- if (D.current === void 0) {
97
- D.current = JSON.stringify(O);
96
+ if (!f || f.length === 0) return;
97
+ if (Z.current === void 0) {
98
+ Z.current = JSON.stringify(X);
98
99
  return;
99
100
  }
100
- const e = JSON.stringify(O);
101
- if (D.current !== e) {
102
- D.current = e;
103
- const n = _.current.formState.touchedFields;
104
- h.split(".").reduce((p, H) => p?.[H], n) && _.current.trigger(h);
101
+ const e = JSON.stringify(X);
102
+ if (Z.current !== e) {
103
+ Z.current = e;
104
+ const r = H.current.formState.touchedFields;
105
+ g.split(".").reduce((v, K) => v?.[K], r) && H.current.trigger(g);
105
106
  }
106
- }, [O, u, h]);
107
- const B = ((e) => {
108
- const n = e.split(".");
109
- let o = d.formState.errors;
110
- for (const p of n) {
107
+ }, [X, f, g]);
108
+ const W = ((e) => {
109
+ const r = e.split(".");
110
+ let o = u.formState.errors;
111
+ for (const v of r) {
111
112
  if (!o) break;
112
- o = o[p];
113
+ o = o[v];
113
114
  }
114
115
  return o;
115
- })(h), A = B?.message, de = g ? Array.isArray(g) ? g : [g] : [], X = K(d);
116
- X.current = d;
117
- const ue = {
118
- getFieldValue: (e) => X.current.getValues(e),
119
- getFieldsValue: () => X.current.getValues()
120
- }, me = de.map(
121
- (e) => typeof e == "function" ? e(ue) : e
122
- ), j = {}, Z = [], q = [];
123
- $ && (j.required = "This field is required");
124
- for (const e of me) {
125
- if (e.required && (j.required = typeof e.required == "string" ? e.required : e.message || "This field is required"), e.type && Y[e.type] && Z.push({
116
+ })(g), A = W?.message, me = p ? Array.isArray(p) ? p : [p] : [], J = O(u);
117
+ J.current = u;
118
+ const fe = {
119
+ getFieldValue: (e) => J.current.getValues(e),
120
+ getFieldsValue: () => J.current.getValues()
121
+ }, he = me.map(
122
+ (e) => typeof e == "function" ? e(fe) : e
123
+ ), j = {}, q = [], _ = [];
124
+ m && (j.required = "This field is required");
125
+ for (const e of he) {
126
+ if (e.required && (j.required = typeof e.required == "string" ? e.required : e.message || "This field is required"), e.type && Y[e.type] && q.push({
126
127
  pattern: Y[e.type].value,
127
128
  message: e.message || Y[e.type].message
128
129
  }), e.min !== void 0) {
129
- const n = typeof e.min == "object" ? e.min.value : e.min, o = typeof e.min == "object" ? e.min.message : e.message || `Minimum length is ${n} characters`;
130
- j.minLength = { value: n, message: o };
130
+ const r = typeof e.min == "object" ? e.min.value : e.min, o = typeof e.min == "object" ? e.min.message : e.message || `Minimum length is ${r} characters`;
131
+ j.minLength = { value: r, message: o };
131
132
  }
132
133
  if (e.max !== void 0) {
133
- const n = typeof e.max == "object" ? e.max.value : e.max, o = typeof e.max == "object" ? e.max.message : e.message || `Maximum length is ${n} characters`;
134
- j.maxLength = { value: n, message: o };
134
+ const r = typeof e.max == "object" ? e.max.value : e.max, o = typeof e.max == "object" ? e.max.message : e.message || `Maximum length is ${r} characters`;
135
+ j.maxLength = { value: r, message: o };
135
136
  }
136
137
  if (e.pattern) {
137
- const n = e.pattern instanceof RegExp ? e.pattern : e.pattern.value, o = e.pattern instanceof RegExp ? e.message || "Invalid format" : e.pattern.message;
138
- Z.push({ pattern: n, message: o });
138
+ const r = e.pattern instanceof RegExp ? e.pattern : e.pattern.value, o = e.pattern instanceof RegExp ? e.message || "Invalid format" : e.pattern.message;
139
+ q.push({ pattern: r, message: o });
139
140
  }
140
- if (e.validate && q.push(e.validate), e.validator) {
141
- const n = e.validator;
142
- q.push(async (o) => {
141
+ if (e.validate && _.push(e.validate), e.validator) {
142
+ const r = e.validator;
143
+ _.push(async (o) => {
143
144
  try {
144
- return await n(e, o), !0;
145
- } catch (p) {
146
- return p instanceof Error ? p.message : String(p);
145
+ return await r(e, o), !0;
146
+ } catch (v) {
147
+ return v instanceof Error ? v.message : String(v);
147
148
  }
148
149
  });
149
150
  }
150
151
  }
151
- (Z.length > 0 || q.length > 0) && (j.validate = async (e) => {
152
- for (const { pattern: n, message: o } of Z)
153
- if (e && !n.test(e))
152
+ (q.length > 0 || _.length > 0) && (j.validate = async (e) => {
153
+ for (const { pattern: r, message: o } of q)
154
+ if (e && !r.test(e))
154
155
  return o;
155
- for (const n of q) {
156
- const o = await n(e);
156
+ for (const r of _) {
157
+ const o = await r(e);
157
158
  if (o !== !0)
158
159
  return o;
159
160
  }
160
161
  return !0;
161
162
  });
162
- const ee = Array.isArray(z) ? z : [z], te = ee.includes("onChange"), fe = ee.includes("onBlur"), he = ({ hasError: e, isValidating: n }) => n ? /* @__PURE__ */ t("span", { className: `${Me} ${Pe} ${Re} text-base-content/50` }) : e ? /* @__PURE__ */ t("svg", { className: "w-4 h-4 text-error", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ t("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }) : /* @__PURE__ */ t("svg", { className: "w-4 h-4 text-success", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ t("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M5 13l4 4L19 7" }) }), ge = () => /* @__PURE__ */ t("div", { className: `${Te} ${Be} ml-1`, "data-tip": y, children: /* @__PURE__ */ t("svg", { className: "w-4 h-4 text-base-content/50 cursor-help", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ t("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }) });
163
+ const ee = Array.isArray(z) ? z : [z], te = ee.includes("onChange"), ge = ee.includes("onBlur"), pe = ({ hasError: e, isValidating: r }) => r ? /* @__PURE__ */ t("span", { className: `${Pe} ${Re} ${Te} text-base-content/50` }) : e ? /* @__PURE__ */ t("svg", { className: "w-4 h-4 text-error", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ t("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }) : /* @__PURE__ */ t("svg", { className: "w-4 h-4 text-success", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ t("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M5 13l4 4L19 7" }) }), ve = () => /* @__PURE__ */ t("div", { className: `${We} ${Be} ml-1`, "data-tip": $, children: /* @__PURE__ */ t("svg", { className: "w-4 h-4 text-base-content/50 cursor-help", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ t("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }) });
163
164
  return /* @__PURE__ */ t(
164
- Ve,
165
+ we,
165
166
  {
166
- name: h,
167
- control: d.control,
167
+ name: g,
168
+ control: u.control,
168
169
  rules: j,
169
- render: ({ field: e, fieldState: n }) => {
170
- const { value: o, onChange: p, onBlur: H, ref: pe } = e, ve = n.isTouched && d.formState.isValidating, v = {
170
+ render: ({ field: e, fieldState: r }) => {
171
+ const { value: o, onChange: v, onBlur: K, ref: xe } = e, ye = r.isTouched && u.formState.isValidating, x = {
171
172
  id: T,
172
- ref: pe,
173
- "aria-invalid": B ? !0 : void 0,
174
- "aria-describedby": B ? V : void 0,
175
- "data-testid": f ? `${f}-input` : void 0
173
+ ref: xe,
174
+ "aria-invalid": W ? !0 : void 0,
175
+ "aria-describedby": W ? V : void 0,
176
+ "data-testid": h ? `${h}-input` : void 0
176
177
  };
177
- v.onBlur = () => {
178
- H(), fe && d.trigger(h);
178
+ x.onBlur = () => {
179
+ K(), ge && u.trigger(g);
179
180
  };
180
181
  const se = U(l) ? l.props.onChange : void 0;
181
- w === "checked" ? (v.checked = o, v.onChange = (m) => {
182
- p(m.target.checked), te && d.trigger(h), se?.(m);
183
- }) : (v.value = o || "", v.onChange = (m) => {
184
- m && m.target !== void 0 ? p(m.target.value) : p(m), te && d.trigger(h), se?.(m);
185
- }), k && U(l) && (l.props.size || (v.size = k)), B && (v.color = "error", v["aria-invalid"] = !0), R && (v.disabled = !0), (S || C) && (v.unstyled = !0);
186
- const re = U(l) ? $e(l, v) : l, L = P === "horizontal", ne = P === "inline", oe = {
187
- xs: Le,
188
- sm: Ee,
189
- md: Ae,
190
- lg: Se,
191
- xl: je
192
- }, xe = () => {
193
- const m = /* @__PURE__ */ E("div", { className: `${L ? "flex-1" : ""} ${N ? "relative" : ""}`, children: [
182
+ w === "checked" ? (x.checked = o, x.onChange = (c) => {
183
+ v(c.target.checked), te && u.trigger(g), se?.(c);
184
+ }) : (x.value = o ?? "", x.onChange = (c) => {
185
+ if (c && c.target !== void 0) {
186
+ const B = c.target.value ?? c.currentTarget?.value;
187
+ v(B ?? c);
188
+ } else
189
+ v(c);
190
+ te && u.trigger(g), se?.(c);
191
+ }), k && U(l) && (l.props.size || (x.size = k)), W && (x.color = "error", x["aria-invalid"] = !0), R && (x.disabled = !0), (S || C) && (x.unstyled = !0);
192
+ const re = U(l) ? Ne(l, x) : l, L = P === "horizontal", ne = P === "inline", oe = {
193
+ xs: Ee,
194
+ sm: Ae,
195
+ md: Se,
196
+ lg: je,
197
+ xl: ze
198
+ }, $e = () => {
199
+ const c = /* @__PURE__ */ E("div", { className: `${L ? "flex-1" : ""} ${F ? "relative" : ""}`, children: [
194
200
  re,
195
- N && n.isTouched && /* @__PURE__ */ t("span", { className: "absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none", children: /* @__PURE__ */ t(he, { hasError: !!B, isValidating: ve }) })
201
+ F && r.isTouched && /* @__PURE__ */ t("span", { className: "absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none", children: /* @__PURE__ */ t(pe, { hasError: !!W, isValidating: ye }) })
196
202
  ] });
197
- if (r) {
198
- const J = [
199
- ze,
203
+ if (s) {
204
+ const B = [
205
+ Me,
200
206
  k && oe[k]
201
207
  ].filter(Boolean).join(" ");
202
- return /* @__PURE__ */ E("label", { className: J, children: [
208
+ return /* @__PURE__ */ E("label", { className: B, children: [
203
209
  re,
204
210
  /* @__PURE__ */ E("span", { children: [
205
- r,
206
- $ && /* @__PURE__ */ t("span", { className: "text-error ml-1", children: "*" })
211
+ s,
212
+ m && /* @__PURE__ */ t("span", { className: "text-error ml-1", children: "*" })
207
213
  ] })
208
214
  ] });
209
215
  }
210
- return m;
211
- }, ye = (m) => {
212
- if (!S && !C) return m;
213
- const J = [
214
- Ce,
216
+ return c;
217
+ }, be = (c) => {
218
+ if (!S && !C) return c;
219
+ const B = [
220
+ Le,
215
221
  "flex",
216
222
  "items-center",
217
223
  "gap-2",
218
224
  k && oe[k]
219
225
  ].filter(Boolean).join(" ");
220
- return /* @__PURE__ */ E("label", { className: J, children: [
226
+ return /* @__PURE__ */ E("label", { className: B, children: [
221
227
  S && /* @__PURE__ */ t("span", { className: "text-base-content/70", children: S }),
222
- m,
228
+ c,
223
229
  C && /* @__PURE__ */ t("span", { className: "text-base-content/70", children: C })
224
230
  ] });
225
231
  };
226
- return /* @__PURE__ */ E("div", { className: `${x ? "w-auto" : "w-full"} ${L ? "mb-4" : ""} ${ne ? "inline-flex mr-4" : ""} ${c}`, style: I ? { display: "none" } : void 0, "data-testid": f, children: [
232
+ return /* @__PURE__ */ E("div", { className: `${y ? "w-auto" : "w-full"} ${L ? "mb-4" : ""} ${ne ? "inline-flex mr-4" : ""} ${d}`, style: I ? { display: "none" } : void 0, "data-testid": h, children: [
227
233
  /* @__PURE__ */ E("div", { className: L ? "flex items-center gap-4" : "", children: [
228
- a && !r && /* @__PURE__ */ t(
234
+ a && !s && /* @__PURE__ */ t(
229
235
  "label",
230
236
  {
231
237
  htmlFor: T,
232
238
  className: `block text-sm font-medium ${L ? "flex-shrink-0 text-right" : ""} ${!L && !ne ? "mb-1" : ""}`,
233
- style: L ? { width: W } : void 0,
234
- "data-testid": f ? `${f}-label` : void 0,
239
+ style: L ? { width: D } : void 0,
240
+ "data-testid": h ? `${h}-label` : void 0,
235
241
  children: /* @__PURE__ */ E("span", { className: "flex items-center", children: [
236
242
  a,
237
- $ && /* @__PURE__ */ t("span", { className: "text-error ml-1", children: "*" }),
238
- y && /* @__PURE__ */ t(ge, {})
243
+ m && /* @__PURE__ */ t("span", { className: "text-error ml-1", children: "*" }),
244
+ $ && /* @__PURE__ */ t(ve, {})
239
245
  ] })
240
246
  }
241
247
  ),
242
- ye(xe())
248
+ be($e())
243
249
  ] }),
244
- !L && !x && /* @__PURE__ */ t("p", { id: V, className: `${le} ${A ? "!visible text-error" : ""} min-h-[1.25rem]`, role: A ? "alert" : void 0, "data-testid": f ? `${f}-error` : void 0, children: A || i && /* @__PURE__ */ t("span", { className: "text-base-content/70", children: i }) || " " }),
245
- L && (A || i) && /* @__PURE__ */ t("p", { id: V, className: `${le} ${A ? "!visible text-error" : ""} min-h-[1.25rem]`, role: A ? "alert" : void 0, "data-testid": f ? `${f}-error` : void 0, children: A || i && /* @__PURE__ */ t("span", { className: "text-base-content/70", children: i }) }),
246
- b && /* @__PURE__ */ t("div", { className: "text-sm text-base-content/60 mt-1", "data-testid": f ? `${f}-extra` : void 0, children: b })
250
+ !L && !y && /* @__PURE__ */ t("p", { id: V, className: `${le} ${A ? "!visible text-error" : ""} min-h-[1.25rem]`, role: A ? "alert" : void 0, "data-testid": h ? `${h}-error` : void 0, children: A || n && /* @__PURE__ */ t("span", { className: "text-base-content/70", children: n }) || " " }),
251
+ L && (A || n) && /* @__PURE__ */ t("p", { id: V, className: `${le} ${A ? "!visible text-error" : ""} min-h-[1.25rem]`, role: A ? "alert" : void 0, "data-testid": h ? `${h}-error` : void 0, children: A || n && /* @__PURE__ */ t("span", { className: "text-base-content/70", children: n }) }),
252
+ b && /* @__PURE__ */ t("div", { className: "text-sm text-base-content/60 mt-1", "data-testid": h ? `${h}-extra` : void 0, children: b })
247
253
  ] });
248
254
  }
249
255
  }
250
256
  );
251
257
  }
252
- function De({
253
- name: s,
258
+ function Ze({
259
+ name: i,
254
260
  children: a
255
261
  }) {
256
- const { form: r, layout: i, size: $, disabled: g } = Q(), { fields: w, append: x, remove: c, move: l } = Fe({
257
- control: r.control,
258
- name: s
259
- }), y = w.map((b, N) => ({
262
+ const { form: s, layout: n, size: m, disabled: p } = Q(), { fields: w, append: y, remove: d, move: l } = Ve({
263
+ control: s.control,
264
+ name: i
265
+ }), $ = w.map((b, F) => ({
260
266
  ...b,
261
- name: N
267
+ name: F
262
268
  }));
263
- return /* @__PURE__ */ t(G.Provider, { value: { form: r, layout: i, size: $, listName: s, disabled: g }, children: a(y, {
264
- add: x,
265
- remove: c,
269
+ return /* @__PURE__ */ t(G.Provider, { value: { form: s, layout: n, size: m, listName: i, disabled: p }, children: a($, {
270
+ add: y,
271
+ remove: d,
266
272
  move: l
267
273
  }) });
268
274
  }
269
- function Ze() {
270
- const s = ce(), a = s;
271
- return a.setFieldValue = s.setValue, a.getFieldValue = (r) => s.getValues(r), a.getFieldsValue = s.getValues, a.setFieldsValue = (r) => {
272
- Object.keys(r).forEach((i) => {
273
- s.setValue(i, r[i]);
275
+ function ue(i) {
276
+ const a = de(i), s = a;
277
+ return s.setFieldValue = a.setValue, s.getFieldValue = (n) => a.getValues(n), s.getFieldsValue = a.getValues, s.setFieldsValue = (n) => {
278
+ Object.keys(n).forEach((m) => {
279
+ a.setValue(m, n[m]);
274
280
  });
275
- }, a.validateFields = s.trigger, a.resetFields = s.reset, a.isFieldTouched = (r) => !!s.formState.touchedFields[r], a.getFieldError = (r) => s.formState.errors[r]?.message, a;
281
+ }, s.validateFields = a.trigger, s.resetFields = a.reset, s.isFieldTouched = (n) => !!a.formState.touchedFields[n], s.getFieldError = (n) => a.formState.errors[n]?.message, s;
276
282
  }
277
- function qe({ fields: s, className: a = "", "data-testid": r }) {
278
- const { form: i } = Q(), { errors: $ } = i.formState, g = (c, l = "") => {
279
- const y = [];
280
- for (const b in c) {
281
- const N = l ? `${l}.${b}` : b, u = c[b];
282
- u?.message ? y.push({ field: N, message: u.message }) : typeof u == "object" && u !== null && y.push(...g(u, N));
283
+ function qe({ fields: i, className: a = "", "data-testid": s }) {
284
+ const { form: n } = Q(), { errors: m } = n.formState, p = (d, l = "") => {
285
+ const $ = [];
286
+ for (const b in d) {
287
+ const F = l ? `${l}.${b}` : b, f = d[b];
288
+ f?.message ? $.push({ field: F, message: f.message }) : typeof f == "object" && f !== null && $.push(...p(f, F));
283
289
  }
284
- return y;
285
- }, w = g($), x = s ? w.filter((c) => s.includes(c.field)) : w;
286
- return x.length === 0 ? null : /* @__PURE__ */ t("ul", { className: `text-error text-sm space-y-1 ${a}`, role: "alert", "data-testid": r, children: x.map((c, l) => /* @__PURE__ */ E("li", { className: "flex items-start gap-2", "data-testid": r ? `${r}-${c.field}` : void 0, children: [
290
+ return $;
291
+ }, w = p(m), y = i ? w.filter((d) => i.includes(d.field)) : w;
292
+ return y.length === 0 ? null : /* @__PURE__ */ t("ul", { className: `text-error text-sm space-y-1 ${a}`, role: "alert", "data-testid": s, children: y.map((d, l) => /* @__PURE__ */ E("li", { className: "flex items-start gap-2", "data-testid": s ? `${s}-${d.field}` : void 0, children: [
287
293
  /* @__PURE__ */ t("svg", { className: "w-4 h-4 mt-0.5 flex-shrink-0", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ t("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }),
288
- /* @__PURE__ */ t("span", { children: c.message })
289
- ] }, `${c.field}-${l}`)) });
294
+ /* @__PURE__ */ t("span", { children: d.message })
295
+ ] }, `${d.field}-${l}`)) });
290
296
  }
291
297
  const Ue = Object.assign(Ie, {
292
- Item: We,
293
- List: De,
298
+ Item: De,
299
+ List: Ze,
294
300
  ErrorList: qe,
295
- useForm: Ze
296
- });
301
+ useForm: ue,
302
+ useWatch: ce
303
+ }), Ye = ue;
297
304
  export {
298
305
  Ue as Form,
299
- Ze as useFormInstance
306
+ Ye as useForm,
307
+ ue as useFormInstance,
308
+ et as useWatch
300
309
  };
301
310
  //# sourceMappingURL=Form.js.map