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.
- package/dist/components/Form.d.ts +5 -2
- package/dist/components/Form.js +184 -175
- package/dist/components/Form.js.map +1 -1
- package/dist/components/Input.js +128 -123
- package/dist/components/Input.js.map +1 -1
- package/dist/components/RichTextEditor.js +18 -18
- package/dist/components/RichTextEditor.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +180 -177
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -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 };
|
package/dist/components/Form.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as t, jsxs as E } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
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
|
|
21
|
-
if (!
|
|
21
|
+
const i = ke(G);
|
|
22
|
+
if (!i)
|
|
22
23
|
throw new Error("Form compound components must be used within Form");
|
|
23
|
-
return
|
|
24
|
+
return i;
|
|
24
25
|
}
|
|
25
26
|
function Ie({
|
|
26
|
-
form:
|
|
27
|
+
form: i,
|
|
27
28
|
onFinish: a,
|
|
28
|
-
onFinishFailed:
|
|
29
|
-
initialValues:
|
|
30
|
-
layout:
|
|
31
|
-
labelWidth:
|
|
29
|
+
onFinishFailed: s,
|
|
30
|
+
initialValues: n,
|
|
31
|
+
layout: m = "vertical",
|
|
32
|
+
labelWidth: p = 60,
|
|
32
33
|
size: w,
|
|
33
|
-
disabled:
|
|
34
|
-
children:
|
|
34
|
+
disabled: y = !1,
|
|
35
|
+
children: d,
|
|
35
36
|
className: l = "",
|
|
36
|
-
noValidate:
|
|
37
|
+
noValidate: $ = !0,
|
|
37
38
|
...b
|
|
38
39
|
}) {
|
|
39
|
-
const { componentSize:
|
|
40
|
-
defaultValues:
|
|
41
|
-
}),
|
|
42
|
-
if (C.preventDefault(), await
|
|
43
|
-
a && a(
|
|
44
|
-
else if (
|
|
45
|
-
const
|
|
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 =
|
|
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(
|
|
52
|
+
M(u), s({ values: N.getValues(), errorFields: k });
|
|
52
53
|
}
|
|
53
54
|
}, S = (C) => {
|
|
54
|
-
C.preventDefault(),
|
|
55
|
+
C.preventDefault(), N.reset(n);
|
|
55
56
|
};
|
|
56
|
-
return /* @__PURE__ */ t(G.Provider, { value: { form:
|
|
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
|
|
59
|
-
name:
|
|
59
|
+
function De({
|
|
60
|
+
name: i,
|
|
60
61
|
label: a,
|
|
61
|
-
floatingLabel:
|
|
62
|
-
help:
|
|
63
|
-
required:
|
|
64
|
-
rules:
|
|
62
|
+
floatingLabel: s,
|
|
63
|
+
help: n,
|
|
64
|
+
required: m = !1,
|
|
65
|
+
rules: p,
|
|
65
66
|
valuePropName: w = "value",
|
|
66
|
-
inline:
|
|
67
|
-
className:
|
|
67
|
+
inline: y = !1,
|
|
68
|
+
className: d = "",
|
|
68
69
|
children: l,
|
|
69
|
-
tooltip:
|
|
70
|
+
tooltip: $,
|
|
70
71
|
extra: b,
|
|
71
|
-
hasFeedback:
|
|
72
|
-
dependencies:
|
|
72
|
+
hasFeedback: F = !1,
|
|
73
|
+
dependencies: f,
|
|
73
74
|
validateTrigger: z = "onChange",
|
|
74
|
-
initialValue:
|
|
75
|
+
initialValue: N,
|
|
75
76
|
hidden: I = !1,
|
|
76
77
|
addonBefore: S,
|
|
77
78
|
addonAfter: C,
|
|
78
|
-
"data-testid":
|
|
79
|
+
"data-testid": h
|
|
79
80
|
}) {
|
|
80
|
-
const { form:
|
|
81
|
-
if (!
|
|
82
|
-
return /* @__PURE__ */ t("div", { className: `${
|
|
83
|
-
let
|
|
84
|
-
Array.isArray(
|
|
85
|
-
|
|
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
|
|
88
|
-
control:
|
|
89
|
-
name:
|
|
90
|
-
disabled: !
|
|
91
|
-
}),
|
|
92
|
-
|
|
93
|
-
const
|
|
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 (!
|
|
96
|
-
if (
|
|
97
|
-
|
|
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(
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
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
|
-
}, [
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
let o =
|
|
110
|
-
for (const
|
|
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[
|
|
113
|
+
o = o[v];
|
|
113
114
|
}
|
|
114
115
|
return o;
|
|
115
|
-
})(
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
getFieldValue: (e) =>
|
|
119
|
-
getFieldsValue: () =>
|
|
120
|
-
},
|
|
121
|
-
(e) => typeof e == "function" ? e(
|
|
122
|
-
), j = {},
|
|
123
|
-
|
|
124
|
-
for (const e of
|
|
125
|
-
if (e.required && (j.required = typeof e.required == "string" ? e.required : e.message || "This field is required"), e.type && Y[e.type] &&
|
|
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
|
|
130
|
-
j.minLength = { value:
|
|
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
|
|
134
|
-
j.maxLength = { value:
|
|
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
|
|
138
|
-
|
|
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 &&
|
|
141
|
-
const
|
|
142
|
-
|
|
141
|
+
if (e.validate && _.push(e.validate), e.validator) {
|
|
142
|
+
const r = e.validator;
|
|
143
|
+
_.push(async (o) => {
|
|
143
144
|
try {
|
|
144
|
-
return await
|
|
145
|
-
} catch (
|
|
146
|
-
return
|
|
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
|
-
(
|
|
152
|
-
for (const { pattern:
|
|
153
|
-
if (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
|
|
156
|
-
const o = await
|
|
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"),
|
|
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
|
-
|
|
165
|
+
we,
|
|
165
166
|
{
|
|
166
|
-
name:
|
|
167
|
-
control:
|
|
167
|
+
name: g,
|
|
168
|
+
control: u.control,
|
|
168
169
|
rules: j,
|
|
169
|
-
render: ({ field: e, fieldState:
|
|
170
|
-
const { value: o, onChange:
|
|
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:
|
|
173
|
-
"aria-invalid":
|
|
174
|
-
"aria-describedby":
|
|
175
|
-
"data-testid":
|
|
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
|
-
|
|
178
|
-
|
|
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" ? (
|
|
182
|
-
|
|
183
|
-
}) : (
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
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 (
|
|
198
|
-
const
|
|
199
|
-
|
|
203
|
+
if (s) {
|
|
204
|
+
const B = [
|
|
205
|
+
Me,
|
|
200
206
|
k && oe[k]
|
|
201
207
|
].filter(Boolean).join(" ");
|
|
202
|
-
return /* @__PURE__ */ E("label", { className:
|
|
208
|
+
return /* @__PURE__ */ E("label", { className: B, children: [
|
|
203
209
|
re,
|
|
204
210
|
/* @__PURE__ */ E("span", { children: [
|
|
205
|
-
|
|
206
|
-
|
|
211
|
+
s,
|
|
212
|
+
m && /* @__PURE__ */ t("span", { className: "text-error ml-1", children: "*" })
|
|
207
213
|
] })
|
|
208
214
|
] });
|
|
209
215
|
}
|
|
210
|
-
return
|
|
211
|
-
},
|
|
212
|
-
if (!S && !C) return
|
|
213
|
-
const
|
|
214
|
-
|
|
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:
|
|
226
|
+
return /* @__PURE__ */ E("label", { className: B, children: [
|
|
221
227
|
S && /* @__PURE__ */ t("span", { className: "text-base-content/70", children: S }),
|
|
222
|
-
|
|
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: `${
|
|
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 && !
|
|
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:
|
|
234
|
-
"data-testid":
|
|
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
|
-
|
|
238
|
-
|
|
243
|
+
m && /* @__PURE__ */ t("span", { className: "text-error ml-1", children: "*" }),
|
|
244
|
+
$ && /* @__PURE__ */ t(ve, {})
|
|
239
245
|
] })
|
|
240
246
|
}
|
|
241
247
|
),
|
|
242
|
-
|
|
248
|
+
be($e())
|
|
243
249
|
] }),
|
|
244
|
-
!L && !
|
|
245
|
-
L && (A ||
|
|
246
|
-
b && /* @__PURE__ */ t("div", { className: "text-sm text-base-content/60 mt-1", "data-testid":
|
|
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
|
|
253
|
-
name:
|
|
258
|
+
function Ze({
|
|
259
|
+
name: i,
|
|
254
260
|
children: a
|
|
255
261
|
}) {
|
|
256
|
-
const { form:
|
|
257
|
-
control:
|
|
258
|
-
name:
|
|
259
|
-
}),
|
|
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:
|
|
267
|
+
name: F
|
|
262
268
|
}));
|
|
263
|
-
return /* @__PURE__ */ t(G.Provider, { value: { form:
|
|
264
|
-
add:
|
|
265
|
-
remove:
|
|
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
|
|
270
|
-
const
|
|
271
|
-
return
|
|
272
|
-
Object.keys(
|
|
273
|
-
|
|
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
|
-
},
|
|
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:
|
|
278
|
-
const { form:
|
|
279
|
-
const
|
|
280
|
-
for (const b in
|
|
281
|
-
const
|
|
282
|
-
|
|
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
|
|
285
|
-
}, w =
|
|
286
|
-
return
|
|
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:
|
|
289
|
-
] }, `${
|
|
294
|
+
/* @__PURE__ */ t("span", { children: d.message })
|
|
295
|
+
] }, `${d.field}-${l}`)) });
|
|
290
296
|
}
|
|
291
297
|
const Ue = Object.assign(Ie, {
|
|
292
|
-
Item:
|
|
293
|
-
List:
|
|
298
|
+
Item: De,
|
|
299
|
+
List: Ze,
|
|
294
300
|
ErrorList: qe,
|
|
295
|
-
useForm:
|
|
296
|
-
|
|
301
|
+
useForm: ue,
|
|
302
|
+
useWatch: ce
|
|
303
|
+
}), Ye = ue;
|
|
297
304
|
export {
|
|
298
305
|
Ue as Form,
|
|
299
|
-
|
|
306
|
+
Ye as useForm,
|
|
307
|
+
ue as useFormInstance,
|
|
308
|
+
et as useWatch
|
|
300
309
|
};
|
|
301
310
|
//# sourceMappingURL=Form.js.map
|