@tachui/forms 0.7.0-alpha1 → 0.7.1-alpha
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/README.md +321 -0
- package/dist/TextField-CGBM3x7K.js +1799 -0
- package/dist/components/index.js +25 -28
- package/dist/index.js +79 -81
- package/dist/state/index.js +240 -7
- package/dist/validation/index.js +598 -19
- package/package.json +5 -6
- package/dist/Form-ueYEcSg1.cjs +0 -2
- package/dist/Form-ueYEcSg1.cjs.map +0 -1
- package/dist/Form-ylAr3o_e.js +0 -376
- package/dist/Form-ylAr3o_e.js.map +0 -1
- package/dist/components/index.cjs +0 -2
- package/dist/components/index.cjs.map +0 -1
- package/dist/components/index.js.map +0 -1
- package/dist/forms-complex-BiQsZZlT.js +0 -361
- package/dist/forms-complex-BiQsZZlT.js.map +0 -1
- package/dist/forms-complex-DLEnXXJ5.cjs +0 -2
- package/dist/forms-complex-DLEnXXJ5.cjs.map +0 -1
- package/dist/forms-core-B1bx1drO.js +0 -839
- package/dist/forms-core-B1bx1drO.js.map +0 -1
- package/dist/forms-core-W_JGVLAI.cjs +0 -9
- package/dist/forms-core-W_JGVLAI.cjs.map +0 -1
- package/dist/forms-inputs-6QdeMWFk.js +0 -1075
- package/dist/forms-inputs-6QdeMWFk.js.map +0 -1
- package/dist/forms-inputs-DQ5QI_SU.cjs +0 -2
- package/dist/forms-inputs-DQ5QI_SU.cjs.map +0 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/state/index.cjs +0 -2
- package/dist/state/index.cjs.map +0 -1
- package/dist/state/index.js.map +0 -1
- package/dist/validation/index.cjs +0 -2
- package/dist/validation/index.cjs.map +0 -1
- package/dist/validation/index.js.map +0 -1
|
@@ -1,839 +0,0 @@
|
|
|
1
|
-
var $ = Object.defineProperty;
|
|
2
|
-
var q = (e, t, r) => t in e ? $(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var O = (e, t, r) => q(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
-
import { createSignal as w, createComputed as D, createEffect as x } from "@tachui/core";
|
|
5
|
-
class g extends Error {
|
|
6
|
-
constructor(t, r) {
|
|
7
|
-
super(t), this.context = r, this.name = "FormsValidationError";
|
|
8
|
-
}
|
|
9
|
-
getFormattedMessage() {
|
|
10
|
-
const { component: t, suggestion: r, example: a, documentation: s } = this.context;
|
|
11
|
-
let o = `❌ [@tachui/forms] ${t} Component Error: ${this.message}
|
|
12
|
-
`;
|
|
13
|
-
return r && (o += `
|
|
14
|
-
💡 Suggestion: ${r}
|
|
15
|
-
`), a && (o += `
|
|
16
|
-
❌ Wrong: ${a.wrong}`, o += `
|
|
17
|
-
✅ Correct: ${a.correct}
|
|
18
|
-
`), s && (o += `
|
|
19
|
-
📚 Documentation: ${s}`), o;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
const y = {
|
|
23
|
-
// EmailField Component
|
|
24
|
-
validateEmailField(e) {
|
|
25
|
-
if (e.length === 0)
|
|
26
|
-
throw new g("EmailField component requires a props object with value", {
|
|
27
|
-
component: "EmailField",
|
|
28
|
-
suggestion: "Add value: EmailField({ value: emailSignal })",
|
|
29
|
-
documentation: "https://docs.tachui.dev/forms/components/emailfield",
|
|
30
|
-
example: {
|
|
31
|
-
wrong: "EmailField()",
|
|
32
|
-
correct: "EmailField({ value: emailSignal, onChange: handleChange })"
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
const [t] = e;
|
|
36
|
-
if (!t || typeof t != "object")
|
|
37
|
-
throw new g("EmailField requires a props object", {
|
|
38
|
-
component: "EmailField",
|
|
39
|
-
suggestion: "Pass a props object with value property",
|
|
40
|
-
example: {
|
|
41
|
-
wrong: 'EmailField("email@example.com")',
|
|
42
|
-
correct: 'EmailField({ value: "email@example.com" })'
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
if (t.value === void 0)
|
|
46
|
-
throw new g("EmailField value property is required", {
|
|
47
|
-
component: "EmailField",
|
|
48
|
-
suggestion: "Provide a value for the email field",
|
|
49
|
-
example: {
|
|
50
|
-
wrong: 'EmailField({ placeholder: "Email" })',
|
|
51
|
-
correct: 'EmailField({ value: emailSignal, placeholder: "Email" })'
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
// PasswordField Component
|
|
56
|
-
validatePasswordField(e) {
|
|
57
|
-
if (e.length === 0)
|
|
58
|
-
throw new g("PasswordField component requires a props object with value", {
|
|
59
|
-
component: "PasswordField",
|
|
60
|
-
suggestion: "Add value: PasswordField({ value: passwordSignal })",
|
|
61
|
-
documentation: "https://docs.tachui.dev/forms/components/passwordfield",
|
|
62
|
-
example: {
|
|
63
|
-
wrong: "PasswordField()",
|
|
64
|
-
correct: "PasswordField({ value: passwordSignal, onChange: handleChange })"
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
const [t] = e;
|
|
68
|
-
if (!t || typeof t != "object")
|
|
69
|
-
throw new g("PasswordField requires a props object", {
|
|
70
|
-
component: "PasswordField",
|
|
71
|
-
suggestion: "Pass a props object with value property",
|
|
72
|
-
example: {
|
|
73
|
-
wrong: 'PasswordField("password")',
|
|
74
|
-
correct: "PasswordField({ value: passwordSignal })"
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
if (t.value === void 0)
|
|
78
|
-
throw new g("PasswordField value property is required", {
|
|
79
|
-
component: "PasswordField",
|
|
80
|
-
suggestion: "Provide a value for the password field",
|
|
81
|
-
example: {
|
|
82
|
-
wrong: 'PasswordField({ placeholder: "Password" })',
|
|
83
|
-
correct: 'PasswordField({ value: passwordSignal, placeholder: "Password" })'
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
// PhoneField Component
|
|
88
|
-
validatePhoneField(e) {
|
|
89
|
-
if (e.length === 0)
|
|
90
|
-
throw new g("PhoneField component requires a props object with value", {
|
|
91
|
-
component: "PhoneField",
|
|
92
|
-
suggestion: "Add value: PhoneField({ value: phoneSignal })",
|
|
93
|
-
documentation: "https://docs.tachui.dev/forms/components/phonefield",
|
|
94
|
-
example: {
|
|
95
|
-
wrong: "PhoneField()",
|
|
96
|
-
correct: 'PhoneField({ value: phoneSignal, format: "US" })'
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
const [t] = e;
|
|
100
|
-
if (!t || typeof t != "object")
|
|
101
|
-
throw new g("PhoneField requires a props object", {
|
|
102
|
-
component: "PhoneField",
|
|
103
|
-
suggestion: "Pass a props object with value property",
|
|
104
|
-
example: {
|
|
105
|
-
wrong: 'PhoneField("(555) 123-4567")',
|
|
106
|
-
correct: "PhoneField({ value: phoneSignal })"
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
if (t.value === void 0)
|
|
110
|
-
throw new g("PhoneField value property is required", {
|
|
111
|
-
component: "PhoneField",
|
|
112
|
-
suggestion: "Provide a value for the phone field",
|
|
113
|
-
example: {
|
|
114
|
-
wrong: 'PhoneField({ format: "US" })',
|
|
115
|
-
correct: 'PhoneField({ value: phoneSignal, format: "US" })'
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
},
|
|
119
|
-
// NumberField Component
|
|
120
|
-
validateNumberField(e) {
|
|
121
|
-
if (e.length === 0)
|
|
122
|
-
throw new g("NumberField component requires a props object with value", {
|
|
123
|
-
component: "NumberField",
|
|
124
|
-
suggestion: "Add value: NumberField({ value: numberSignal })",
|
|
125
|
-
documentation: "https://docs.tachui.dev/forms/components/numberfield",
|
|
126
|
-
example: {
|
|
127
|
-
wrong: "NumberField()",
|
|
128
|
-
correct: "NumberField({ value: numberSignal, min: 0, max: 100 })"
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
const [t] = e;
|
|
132
|
-
if (!t || typeof t != "object")
|
|
133
|
-
throw new g("NumberField requires a props object", {
|
|
134
|
-
component: "NumberField",
|
|
135
|
-
suggestion: "Pass a props object with value property",
|
|
136
|
-
example: {
|
|
137
|
-
wrong: "NumberField(42)",
|
|
138
|
-
correct: "NumberField({ value: 42 })"
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
if (t.value === void 0)
|
|
142
|
-
throw new g("NumberField value property is required", {
|
|
143
|
-
component: "NumberField",
|
|
144
|
-
suggestion: "Provide a numeric value for the field",
|
|
145
|
-
example: {
|
|
146
|
-
wrong: "NumberField({ min: 0, max: 100 })",
|
|
147
|
-
correct: "NumberField({ value: 42, min: 0, max: 100 })"
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
},
|
|
151
|
-
// CreditCardField Component
|
|
152
|
-
validateCreditCardField(e) {
|
|
153
|
-
if (e.length === 0)
|
|
154
|
-
throw new g("CreditCardField component requires a props object with value", {
|
|
155
|
-
component: "CreditCardField",
|
|
156
|
-
suggestion: "Add value: CreditCardField({ value: cardSignal })",
|
|
157
|
-
documentation: "https://docs.tachui.dev/forms/components/creditcardfield",
|
|
158
|
-
example: {
|
|
159
|
-
wrong: "CreditCardField()",
|
|
160
|
-
correct: "CreditCardField({ value: cardSignal, onChange: handleChange })"
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
const [t] = e;
|
|
164
|
-
if (!t || typeof t != "object")
|
|
165
|
-
throw new g("CreditCardField requires a props object", {
|
|
166
|
-
component: "CreditCardField",
|
|
167
|
-
suggestion: "Pass a props object with value property",
|
|
168
|
-
example: {
|
|
169
|
-
wrong: 'CreditCardField("4111111111111111")',
|
|
170
|
-
correct: "CreditCardField({ value: cardSignal })"
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
if (t.value === void 0)
|
|
174
|
-
throw new g("CreditCardField value property is required", {
|
|
175
|
-
component: "CreditCardField",
|
|
176
|
-
suggestion: "Provide a value for the credit card field",
|
|
177
|
-
example: {
|
|
178
|
-
wrong: 'CreditCardField({ placeholder: "Card Number" })',
|
|
179
|
-
correct: 'CreditCardField({ value: cardSignal, placeholder: "Card Number" })'
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
// Additional Forms components would go here...
|
|
184
|
-
// (SearchField, URLField, TextArea, ColorField, Select, MultiSelect, Checkbox, Radio, etc.)
|
|
185
|
-
};
|
|
186
|
-
function U() {
|
|
187
|
-
return [
|
|
188
|
-
{
|
|
189
|
-
packageName: "forms",
|
|
190
|
-
componentName: "EmailField",
|
|
191
|
-
validate: y.validateEmailField
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
packageName: "forms",
|
|
195
|
-
componentName: "PasswordField",
|
|
196
|
-
validate: y.validatePasswordField
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
packageName: "forms",
|
|
200
|
-
componentName: "PhoneField",
|
|
201
|
-
validate: y.validatePhoneField
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
packageName: "forms",
|
|
205
|
-
componentName: "NumberField",
|
|
206
|
-
validate: y.validateNumberField
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
packageName: "forms",
|
|
210
|
-
componentName: "CreditCardField",
|
|
211
|
-
validate: y.validateCreditCardField
|
|
212
|
-
}
|
|
213
|
-
// Additional validators would be added here for remaining 9+ Forms components
|
|
214
|
-
];
|
|
215
|
-
}
|
|
216
|
-
async function k() {
|
|
217
|
-
try {
|
|
218
|
-
const { registerComponentValidator: e } = await import("@tachui/core/validation"), t = U();
|
|
219
|
-
for (const r of t)
|
|
220
|
-
e(r);
|
|
221
|
-
process.env.NODE_ENV !== "production" && console.info(`🔍 [@tachui/forms] Registered ${t.length} component validators`);
|
|
222
|
-
} catch (e) {
|
|
223
|
-
process.env.NODE_ENV !== "production" && console.warn("⚠️ [@tachui/forms] Could not register validators with Core:", e);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
typeof window < "u" && process.env.NODE_ENV !== "production" && setTimeout(k, 10);
|
|
227
|
-
const C = {
|
|
228
|
-
required: (e) => ({
|
|
229
|
-
valid: e != null && e !== "",
|
|
230
|
-
message: "This field is required",
|
|
231
|
-
code: "REQUIRED"
|
|
232
|
-
}),
|
|
233
|
-
email: (e) => e ? {
|
|
234
|
-
valid: /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),
|
|
235
|
-
message: "Please enter a valid email address",
|
|
236
|
-
code: "INVALID_EMAIL"
|
|
237
|
-
} : { valid: !0 },
|
|
238
|
-
url: (e) => {
|
|
239
|
-
if (!e) return { valid: !0 };
|
|
240
|
-
try {
|
|
241
|
-
return new URL(e), { valid: !0 };
|
|
242
|
-
} catch {
|
|
243
|
-
return {
|
|
244
|
-
valid: !1,
|
|
245
|
-
message: "Please enter a valid URL",
|
|
246
|
-
code: "INVALID_URL"
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
number: (e) => {
|
|
251
|
-
if (!e) return { valid: !0 };
|
|
252
|
-
const t = Number(e);
|
|
253
|
-
return {
|
|
254
|
-
valid: !Number.isNaN(t) && Number.isFinite(t),
|
|
255
|
-
message: "Please enter a valid number",
|
|
256
|
-
code: "INVALID_NUMBER"
|
|
257
|
-
};
|
|
258
|
-
},
|
|
259
|
-
integer: (e) => {
|
|
260
|
-
if (!e) return { valid: !0 };
|
|
261
|
-
const t = Number(e);
|
|
262
|
-
return {
|
|
263
|
-
valid: !Number.isNaN(t) && Number.isFinite(t) && Number.isInteger(t),
|
|
264
|
-
message: "Please enter a valid integer",
|
|
265
|
-
code: "INVALID_INTEGER"
|
|
266
|
-
};
|
|
267
|
-
},
|
|
268
|
-
min: (e, t) => {
|
|
269
|
-
if (!e) return { valid: !0 };
|
|
270
|
-
const r = Number(e);
|
|
271
|
-
return Number.isNaN(r) ? { valid: !0 } : {
|
|
272
|
-
valid: r >= t.min,
|
|
273
|
-
message: `Value must be at least ${t.min}`,
|
|
274
|
-
code: "MIN_VALUE"
|
|
275
|
-
};
|
|
276
|
-
},
|
|
277
|
-
max: (e, t) => {
|
|
278
|
-
if (!e) return { valid: !0 };
|
|
279
|
-
const r = Number(e);
|
|
280
|
-
return Number.isNaN(r) ? { valid: !0 } : {
|
|
281
|
-
valid: r <= t.max,
|
|
282
|
-
message: `Value must be at most ${t.max}`,
|
|
283
|
-
code: "MAX_VALUE"
|
|
284
|
-
};
|
|
285
|
-
},
|
|
286
|
-
minLength: (e, t) => e ? {
|
|
287
|
-
valid: e.length >= t.minLength,
|
|
288
|
-
message: `Must be at least ${t.minLength} characters`,
|
|
289
|
-
code: "MIN_LENGTH"
|
|
290
|
-
} : { valid: !0 },
|
|
291
|
-
maxLength: (e, t) => e ? {
|
|
292
|
-
valid: e.length <= t.maxLength,
|
|
293
|
-
message: `Must be at most ${t.maxLength} characters`,
|
|
294
|
-
code: "MAX_LENGTH"
|
|
295
|
-
} : { valid: !0 },
|
|
296
|
-
pattern: (e, t) => e ? {
|
|
297
|
-
valid: (typeof t.pattern == "string" ? new RegExp(t.pattern) : t.pattern).test(e),
|
|
298
|
-
message: t.message || "Value does not match required pattern",
|
|
299
|
-
code: "PATTERN_MISMATCH"
|
|
300
|
-
} : { valid: !0 },
|
|
301
|
-
// Additional validation rules expected by tests
|
|
302
|
-
numeric: (e) => {
|
|
303
|
-
if (!e) return { valid: !0 };
|
|
304
|
-
const t = Number(e);
|
|
305
|
-
return {
|
|
306
|
-
valid: !Number.isNaN(t) && Number.isFinite(t),
|
|
307
|
-
message: "Please enter a valid number",
|
|
308
|
-
code: "INVALID_NUMERIC"
|
|
309
|
-
};
|
|
310
|
-
},
|
|
311
|
-
phone: (e) => {
|
|
312
|
-
if (!e) return { valid: !0 };
|
|
313
|
-
const t = /^\+?[\d\s\-().]+$/, r = e.replace(/[\s\-().]/g, "");
|
|
314
|
-
return {
|
|
315
|
-
valid: t.test(e) && r.length >= 10,
|
|
316
|
-
message: "Please enter a valid phone number",
|
|
317
|
-
code: "INVALID_PHONE"
|
|
318
|
-
};
|
|
319
|
-
},
|
|
320
|
-
creditCard: (e) => {
|
|
321
|
-
if (!e) return { valid: !0 };
|
|
322
|
-
const t = e.replace(/\s/g, "");
|
|
323
|
-
let r = 0, a = !1;
|
|
324
|
-
for (let s = t.length - 1; s >= 0; s--) {
|
|
325
|
-
let o = parseInt(t.charAt(s));
|
|
326
|
-
a && (o *= 2, o > 9 && (o = o % 10 + 1)), r += o, a = !a;
|
|
327
|
-
}
|
|
328
|
-
return {
|
|
329
|
-
valid: /^\d{13,19}$/.test(t) && r % 10 === 0,
|
|
330
|
-
message: "Please enter a valid credit card number",
|
|
331
|
-
code: "INVALID_CREDIT_CARD"
|
|
332
|
-
};
|
|
333
|
-
},
|
|
334
|
-
ssn: (e) => {
|
|
335
|
-
if (!e) return { valid: !0 };
|
|
336
|
-
const t = e.replace(/[-\s]/g, "");
|
|
337
|
-
return {
|
|
338
|
-
valid: /^\d{9}$/.test(t),
|
|
339
|
-
message: "Please enter a valid Social Security Number",
|
|
340
|
-
code: "INVALID_SSN"
|
|
341
|
-
};
|
|
342
|
-
},
|
|
343
|
-
postalCode: (e) => {
|
|
344
|
-
if (!e) return { valid: !0 };
|
|
345
|
-
const t = /^\d{5}(-\d{4})?$/, r = /^[A-Z0-9]{3,10}$/i;
|
|
346
|
-
return {
|
|
347
|
-
valid: t.test(e) || r.test(e),
|
|
348
|
-
message: "Please enter a valid postal code",
|
|
349
|
-
code: "INVALID_POSTAL_CODE"
|
|
350
|
-
};
|
|
351
|
-
},
|
|
352
|
-
zipCode: (e) => e ? {
|
|
353
|
-
valid: /^\d{5}(-\d{4})?$/.test(e),
|
|
354
|
-
message: "Please enter a valid ZIP code",
|
|
355
|
-
code: "INVALID_ZIP_CODE"
|
|
356
|
-
} : { valid: !0 },
|
|
357
|
-
date: (e) => {
|
|
358
|
-
if (!e) return { valid: !0 };
|
|
359
|
-
const t = new Date(e);
|
|
360
|
-
return {
|
|
361
|
-
valid: !Number.isNaN(t.getTime()) && !!e.match(/^\d{4}-\d{2}-\d{2}$/),
|
|
362
|
-
message: "Please enter a valid date (YYYY-MM-DD)",
|
|
363
|
-
code: "INVALID_DATE"
|
|
364
|
-
};
|
|
365
|
-
},
|
|
366
|
-
time: (e) => e ? {
|
|
367
|
-
valid: /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/.test(e),
|
|
368
|
-
message: "Please enter a valid time (HH:MM)",
|
|
369
|
-
code: "INVALID_TIME"
|
|
370
|
-
} : { valid: !0 },
|
|
371
|
-
strongPassword: (e) => {
|
|
372
|
-
if (!e) return { valid: !0 };
|
|
373
|
-
const t = /[A-Z]/.test(e), r = /[a-z]/.test(e), a = /\d/.test(e), s = /\W/.test(e), o = e.length >= 8, l = t && r && a && s && o;
|
|
374
|
-
return {
|
|
375
|
-
valid: l,
|
|
376
|
-
message: l ? void 0 : "Password must be at least 8 characters with uppercase, lowercase, number and special character",
|
|
377
|
-
code: "WEAK_PASSWORD"
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
}, S = /* @__PURE__ */ new Map();
|
|
381
|
-
function Y(e) {
|
|
382
|
-
S.set(e.name, e);
|
|
383
|
-
}
|
|
384
|
-
function Q(e) {
|
|
385
|
-
S.delete(e);
|
|
386
|
-
}
|
|
387
|
-
function z() {
|
|
388
|
-
return [...Object.keys(C), ...S.keys()];
|
|
389
|
-
}
|
|
390
|
-
function T(e, t, r) {
|
|
391
|
-
for (const a of t) {
|
|
392
|
-
let s;
|
|
393
|
-
if (typeof a == "string") {
|
|
394
|
-
const o = C[a];
|
|
395
|
-
if (o)
|
|
396
|
-
s = o(e, r?.[a]);
|
|
397
|
-
else {
|
|
398
|
-
const l = S.get(a);
|
|
399
|
-
if (l)
|
|
400
|
-
s = l.validate(e, l.options);
|
|
401
|
-
else {
|
|
402
|
-
console.warn(`Unknown validation rule: ${a}`);
|
|
403
|
-
continue;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
} else if ("validate" in a)
|
|
407
|
-
s = a.validate(e, a.options);
|
|
408
|
-
else {
|
|
409
|
-
const o = C[a.name];
|
|
410
|
-
if (o)
|
|
411
|
-
s = o(e, a.options);
|
|
412
|
-
else {
|
|
413
|
-
console.warn(`Unknown built-in validation rule: ${a.name}`);
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
if (!s.valid)
|
|
418
|
-
return s;
|
|
419
|
-
}
|
|
420
|
-
return { valid: !0 };
|
|
421
|
-
}
|
|
422
|
-
function B(e, t) {
|
|
423
|
-
return !t?.rules || t.rules.length === 0 ? { valid: !0 } : T(e.value, t.rules);
|
|
424
|
-
}
|
|
425
|
-
async function L(e, t, r) {
|
|
426
|
-
for (const a of t) {
|
|
427
|
-
let s;
|
|
428
|
-
if (typeof a == "string") {
|
|
429
|
-
const l = C[a];
|
|
430
|
-
if (l)
|
|
431
|
-
s = l(e, r?.[a]);
|
|
432
|
-
else {
|
|
433
|
-
const c = S.get(a);
|
|
434
|
-
if (c)
|
|
435
|
-
s = c.validate(e, c.options);
|
|
436
|
-
else
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
} else if ("validate" in a)
|
|
440
|
-
s = a.validate(e, a.options);
|
|
441
|
-
else {
|
|
442
|
-
const l = C[a.name];
|
|
443
|
-
if (l)
|
|
444
|
-
s = l(e, a.options);
|
|
445
|
-
else
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
const o = await Promise.resolve(s);
|
|
449
|
-
if (!o.valid)
|
|
450
|
-
return o;
|
|
451
|
-
}
|
|
452
|
-
return { valid: !0 };
|
|
453
|
-
}
|
|
454
|
-
function X(e, t = 300) {
|
|
455
|
-
let r, a, s;
|
|
456
|
-
return (o) => new Promise((l) => {
|
|
457
|
-
if (o === a && s) {
|
|
458
|
-
Promise.resolve(s).then(l);
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
a = o, clearTimeout(r), r = setTimeout(async () => {
|
|
462
|
-
try {
|
|
463
|
-
s = e(o);
|
|
464
|
-
const c = await Promise.resolve(s);
|
|
465
|
-
l(c);
|
|
466
|
-
} catch {
|
|
467
|
-
l({
|
|
468
|
-
valid: !1,
|
|
469
|
-
message: "Validation error occurred",
|
|
470
|
-
code: "VALIDATION_ERROR"
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
}, t);
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
const K = {
|
|
477
|
-
/**
|
|
478
|
-
* Validate that two fields match (e.g., password confirmation)
|
|
479
|
-
*/
|
|
480
|
-
fieldMatch: (e, t, r = "Fields must match") => (a) => a[e] === a[t] ? { valid: !0 } : {
|
|
481
|
-
valid: !1,
|
|
482
|
-
message: r,
|
|
483
|
-
code: "FIELD_MISMATCH"
|
|
484
|
-
},
|
|
485
|
-
/**
|
|
486
|
-
* Validate that at least one field in a group is filled
|
|
487
|
-
*/
|
|
488
|
-
requireOneOf: (e, t = "At least one field is required") => (r) => e.some((s) => {
|
|
489
|
-
const o = r[s];
|
|
490
|
-
return o != null && o !== "";
|
|
491
|
-
}) ? { valid: !0 } : {
|
|
492
|
-
valid: !1,
|
|
493
|
-
message: t,
|
|
494
|
-
code: "REQUIRE_ONE_OF"
|
|
495
|
-
},
|
|
496
|
-
/**
|
|
497
|
-
* Validate that a field is required when another field has a specific value
|
|
498
|
-
*/
|
|
499
|
-
requiredWhen: (e, t, r, a = `${e} is required`) => (s) => {
|
|
500
|
-
if (s[t] === r) {
|
|
501
|
-
const o = s[e];
|
|
502
|
-
return o != null && o !== "" ? { valid: !0 } : {
|
|
503
|
-
valid: !1,
|
|
504
|
-
message: a,
|
|
505
|
-
code: "REQUIRED_WHEN"
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
return { valid: !0 };
|
|
509
|
-
},
|
|
510
|
-
/**
|
|
511
|
-
* Validate date range (start date before end date)
|
|
512
|
-
*/
|
|
513
|
-
dateRange: (e, t, r = "End date must be after start date") => (a) => {
|
|
514
|
-
const s = a[e], o = a[t];
|
|
515
|
-
if (!s || !o) return { valid: !0 };
|
|
516
|
-
const l = new Date(s);
|
|
517
|
-
return new Date(o) >= l ? { valid: !0 } : {
|
|
518
|
-
valid: !1,
|
|
519
|
-
message: r,
|
|
520
|
-
code: "INVALID_DATE_RANGE"
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
}, J = {
|
|
524
|
-
email: ["required", "email"],
|
|
525
|
-
password: ["required", { name: "minLength", options: { minLength: 8 } }],
|
|
526
|
-
phone: [
|
|
527
|
-
"required",
|
|
528
|
-
{ name: "pattern", options: { pattern: /^\+?[\d\s-()]+$/, message: "Invalid phone number" } }
|
|
529
|
-
],
|
|
530
|
-
url: ["required", "url"],
|
|
531
|
-
positiveNumber: ["required", "number", { name: "min", options: { min: 0 } }],
|
|
532
|
-
percentage: [
|
|
533
|
-
"required",
|
|
534
|
-
"number",
|
|
535
|
-
{ name: "min", options: { min: 0 } },
|
|
536
|
-
{ name: "max", options: { max: 100 } }
|
|
537
|
-
]
|
|
538
|
-
};
|
|
539
|
-
class H {
|
|
540
|
-
constructor(t = {}) {
|
|
541
|
-
O(this, "messages", {});
|
|
542
|
-
this.messages = t;
|
|
543
|
-
}
|
|
544
|
-
setMessage(t, r) {
|
|
545
|
-
this.messages[t] = r;
|
|
546
|
-
}
|
|
547
|
-
setMessages(t) {
|
|
548
|
-
this.messages = { ...this.messages, ...t };
|
|
549
|
-
}
|
|
550
|
-
format(t, r) {
|
|
551
|
-
return t.code && this.messages[t.code] ? this.messages[t.code].replace("${field}", r || "field") : t.message || "Validation failed";
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
const ee = new H(), te = {
|
|
555
|
-
/**
|
|
556
|
-
* Check if a validation result represents an error
|
|
557
|
-
*/
|
|
558
|
-
isError: (e) => !e.valid,
|
|
559
|
-
/**
|
|
560
|
-
* Check if a validation result is valid
|
|
561
|
-
*/
|
|
562
|
-
isValid: (e) => e.valid,
|
|
563
|
-
/**
|
|
564
|
-
* Combine multiple validation results
|
|
565
|
-
*/
|
|
566
|
-
combineResults: (e) => {
|
|
567
|
-
const t = e.filter((r) => !r.valid);
|
|
568
|
-
return t.length === 0 ? { valid: !0 } : {
|
|
569
|
-
valid: !1,
|
|
570
|
-
message: t.map((r) => r.message).join(", "),
|
|
571
|
-
code: "MULTIPLE_ERRORS"
|
|
572
|
-
};
|
|
573
|
-
},
|
|
574
|
-
/**
|
|
575
|
-
* Create a validation function from a rule configuration
|
|
576
|
-
*/
|
|
577
|
-
createValidator: (e, t) => (r) => T(r, e, t),
|
|
578
|
-
/**
|
|
579
|
-
* Create an async validation function
|
|
580
|
-
*/
|
|
581
|
-
createAsyncValidator: (e, t) => (r) => L(r, e, t)
|
|
582
|
-
};
|
|
583
|
-
function j(e) {
|
|
584
|
-
const [t, r] = w(e), [a, s] = w(void 0), [o, l] = w(!1), [c, F] = w(!1), [b, A] = w(!1), [V, I] = w(!1);
|
|
585
|
-
x(() => {
|
|
586
|
-
t() !== e && F(!0);
|
|
587
|
-
});
|
|
588
|
-
const d = D(() => !a());
|
|
589
|
-
return {
|
|
590
|
-
state: D(
|
|
591
|
-
() => ({
|
|
592
|
-
value: t(),
|
|
593
|
-
error: a(),
|
|
594
|
-
touched: o(),
|
|
595
|
-
dirty: c(),
|
|
596
|
-
valid: d(),
|
|
597
|
-
validating: V(),
|
|
598
|
-
focused: b()
|
|
599
|
-
})
|
|
600
|
-
),
|
|
601
|
-
setValue: (m) => {
|
|
602
|
-
r(m), F(m !== e), o();
|
|
603
|
-
},
|
|
604
|
-
setError: s,
|
|
605
|
-
setTouched: l,
|
|
606
|
-
setFocused: A,
|
|
607
|
-
setValidating: I
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
function W(e = {}) {
|
|
611
|
-
const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), [a, s] = w(!1), [o, l] = w(!1);
|
|
612
|
-
Object.keys(e).forEach((n) => {
|
|
613
|
-
const i = j(e[n]);
|
|
614
|
-
t.set(n, i);
|
|
615
|
-
});
|
|
616
|
-
const c = D(() => {
|
|
617
|
-
const n = {}, i = {}, u = {};
|
|
618
|
-
let v = !0, f = !1;
|
|
619
|
-
for (const [_, E] of t) {
|
|
620
|
-
const P = E.state();
|
|
621
|
-
n[_] = P, P.error && (i[_] = P.error, v = !1), P.touched && (u[_] = !0), P.dirty && (f = !0);
|
|
622
|
-
}
|
|
623
|
-
return {
|
|
624
|
-
fields: n,
|
|
625
|
-
valid: v,
|
|
626
|
-
dirty: f,
|
|
627
|
-
submitting: a(),
|
|
628
|
-
submitted: o(),
|
|
629
|
-
errors: i,
|
|
630
|
-
touched: u
|
|
631
|
-
};
|
|
632
|
-
}), F = (n, i) => {
|
|
633
|
-
if (t.has(n)) {
|
|
634
|
-
i && r.set(n, i);
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
const u = j(e[n]);
|
|
638
|
-
if (t.set(n, u), i && r.set(n, i), i) {
|
|
639
|
-
const v = u.state;
|
|
640
|
-
x(async () => {
|
|
641
|
-
const f = v();
|
|
642
|
-
if ((i.validateOn === "change" || i.validateOn === "blur" && f.touched || i.validateOn === "submit" && o()) && (f.dirty || f.touched)) {
|
|
643
|
-
u.setValidating(!0);
|
|
644
|
-
try {
|
|
645
|
-
const E = await M(f, i);
|
|
646
|
-
u.setError(E.valid ? void 0 : E.message);
|
|
647
|
-
} catch {
|
|
648
|
-
u.setError("Validation error occurred");
|
|
649
|
-
} finally {
|
|
650
|
-
u.setValidating(!1);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
}, b = (n) => {
|
|
656
|
-
t.delete(n), r.delete(n);
|
|
657
|
-
}, A = (n, i) => {
|
|
658
|
-
const u = t.get(n);
|
|
659
|
-
u && u.setValue(i);
|
|
660
|
-
}, V = (n) => t.get(n)?.state().value, I = (n) => t.get(n)?.state().error, d = async (n) => {
|
|
661
|
-
const i = t.get(n), u = r.get(n);
|
|
662
|
-
if (!i || !u)
|
|
663
|
-
return !0;
|
|
664
|
-
const v = i.state();
|
|
665
|
-
i.setValidating(!0);
|
|
666
|
-
try {
|
|
667
|
-
const f = await M(v, u);
|
|
668
|
-
return i.setError(f.valid ? void 0 : f.message), f.valid;
|
|
669
|
-
} catch {
|
|
670
|
-
return i.setError("Validation error occurred"), !1;
|
|
671
|
-
} finally {
|
|
672
|
-
i.setValidating(!1);
|
|
673
|
-
}
|
|
674
|
-
}, p = async () => {
|
|
675
|
-
const n = Array.from(t.keys()).map(d);
|
|
676
|
-
return (await Promise.all(n)).every((u) => u);
|
|
677
|
-
}, m = () => {
|
|
678
|
-
for (const [n, i] of t)
|
|
679
|
-
i.setValue(e[n]), i.setError(void 0), i.setTouched(!1), i.setFocused(!1), i.setValidating(!1);
|
|
680
|
-
s(!1), l(!1);
|
|
681
|
-
}, h = async (n) => {
|
|
682
|
-
s(!0), l(!0);
|
|
683
|
-
try {
|
|
684
|
-
if (await p() && n) {
|
|
685
|
-
const u = {};
|
|
686
|
-
for (const [v, f] of t)
|
|
687
|
-
u[v] = f.state().value;
|
|
688
|
-
await n(u, c());
|
|
689
|
-
}
|
|
690
|
-
} finally {
|
|
691
|
-
s(!1);
|
|
692
|
-
}
|
|
693
|
-
}, N = (n) => {
|
|
694
|
-
const i = {}, u = n || Array.from(t.keys());
|
|
695
|
-
for (const v of u)
|
|
696
|
-
t.has(v) && (i[v] = V(v));
|
|
697
|
-
return i;
|
|
698
|
-
}, R = async (n) => {
|
|
699
|
-
const u = (n || Array.from(t.keys())).map(d);
|
|
700
|
-
return (await Promise.all(u)).every((f) => f);
|
|
701
|
-
};
|
|
702
|
-
return {
|
|
703
|
-
fields: c().fields,
|
|
704
|
-
state: c(),
|
|
705
|
-
register: F,
|
|
706
|
-
unregister: b,
|
|
707
|
-
setValue: A,
|
|
708
|
-
getValue: V,
|
|
709
|
-
getError: I,
|
|
710
|
-
validateField: d,
|
|
711
|
-
validateForm: p,
|
|
712
|
-
resetForm: m,
|
|
713
|
-
submitForm: h,
|
|
714
|
-
watch: N,
|
|
715
|
-
trigger: R
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
async function M(e, t) {
|
|
719
|
-
return !t.rules || t.rules.length === 0 ? { valid: !0 } : t.debounceMs ? new Promise((r) => {
|
|
720
|
-
setTimeout(async () => {
|
|
721
|
-
const a = await L(e.value, t.rules);
|
|
722
|
-
r(a);
|
|
723
|
-
}, t.debounceMs);
|
|
724
|
-
}) : L(e.value, t.rules);
|
|
725
|
-
}
|
|
726
|
-
function re(e, t, r) {
|
|
727
|
-
const a = j(t), s = a.state;
|
|
728
|
-
r && x(async () => {
|
|
729
|
-
const c = s();
|
|
730
|
-
if ((r.validateOn === "change" || r.validateOn === "blur" && c.touched) && (c.dirty || c.touched)) {
|
|
731
|
-
a.setValidating(!0);
|
|
732
|
-
try {
|
|
733
|
-
const b = await M(c, r);
|
|
734
|
-
a.setError(b.valid ? void 0 : b.message);
|
|
735
|
-
} catch {
|
|
736
|
-
a.setError("Validation error occurred");
|
|
737
|
-
} finally {
|
|
738
|
-
a.setValidating(!1);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
});
|
|
742
|
-
const o = async () => {
|
|
743
|
-
if (!r) return !0;
|
|
744
|
-
a.setValidating(!0);
|
|
745
|
-
try {
|
|
746
|
-
const c = await M(s(), r);
|
|
747
|
-
return a.setError(c.valid ? void 0 : c.message), c.valid;
|
|
748
|
-
} catch {
|
|
749
|
-
return a.setError("Validation error occurred"), !1;
|
|
750
|
-
} finally {
|
|
751
|
-
a.setValidating(!1);
|
|
752
|
-
}
|
|
753
|
-
}, l = () => {
|
|
754
|
-
a.setValue(t), a.setError(void 0), a.setTouched(!1), a.setFocused(!1), a.setValidating(!1);
|
|
755
|
-
};
|
|
756
|
-
return {
|
|
757
|
-
value: () => s().value,
|
|
758
|
-
setValue: a.setValue,
|
|
759
|
-
error: () => s().error,
|
|
760
|
-
touched: () => s().touched,
|
|
761
|
-
dirty: () => s().dirty,
|
|
762
|
-
valid: () => s().valid,
|
|
763
|
-
validating: () => s().validating,
|
|
764
|
-
focused: () => s().focused,
|
|
765
|
-
onFocus: () => {
|
|
766
|
-
a.setFocused(!0);
|
|
767
|
-
},
|
|
768
|
-
onBlur: () => {
|
|
769
|
-
a.setFocused(!1), a.setTouched(!0);
|
|
770
|
-
},
|
|
771
|
-
validate: o,
|
|
772
|
-
reset: l
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
function ae(e, t = {}) {
|
|
776
|
-
const [r, a] = w(0), [s, o] = w(/* @__PURE__ */ new Set()), l = /* @__PURE__ */ new Map();
|
|
777
|
-
return e.forEach((d, p) => {
|
|
778
|
-
const m = Object.keys(t).filter((h) => h.startsWith(`step_${p}_`)).reduce(
|
|
779
|
-
(h, N) => {
|
|
780
|
-
const R = N.replace(`step_${p}_`, "");
|
|
781
|
-
return h[R] = t[N], h;
|
|
782
|
-
},
|
|
783
|
-
{}
|
|
784
|
-
);
|
|
785
|
-
l.set(p, W(m));
|
|
786
|
-
}), {
|
|
787
|
-
currentStep: r,
|
|
788
|
-
completedSteps: s,
|
|
789
|
-
nextStep: async (d = !0) => {
|
|
790
|
-
const p = r(), m = l.get(p);
|
|
791
|
-
return d && m && !await m.validateForm() ? !1 : p < e.length - 1 ? (o((h) => /* @__PURE__ */ new Set([...h, p])), a(p + 1), !0) : !1;
|
|
792
|
-
},
|
|
793
|
-
previousStep: () => {
|
|
794
|
-
const d = r();
|
|
795
|
-
return d > 0 ? (a(d - 1), !0) : !1;
|
|
796
|
-
},
|
|
797
|
-
goToStep: (d) => d >= 0 && d < e.length ? (a(d), !0) : !1,
|
|
798
|
-
getCurrentForm: () => l.get(r()),
|
|
799
|
-
getAllValues: () => {
|
|
800
|
-
const d = {};
|
|
801
|
-
return l.forEach((p, m) => {
|
|
802
|
-
const h = p.watch();
|
|
803
|
-
Object.keys(h).forEach((N) => {
|
|
804
|
-
d[`step_${m}_${N}`] = h[N];
|
|
805
|
-
});
|
|
806
|
-
}), d;
|
|
807
|
-
},
|
|
808
|
-
validateAllSteps: async () => {
|
|
809
|
-
const d = Array.from(l.values()).map((m) => m.validateForm());
|
|
810
|
-
return (await Promise.all(d)).every((m) => m);
|
|
811
|
-
},
|
|
812
|
-
getStepForm: (d) => l.get(d),
|
|
813
|
-
isStepCompleted: (d) => s().has(d),
|
|
814
|
-
canGoToStep: (d) => d <= r() || s().has(d)
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
export {
|
|
818
|
-
K as C,
|
|
819
|
-
g as F,
|
|
820
|
-
J as V,
|
|
821
|
-
W as a,
|
|
822
|
-
ae as b,
|
|
823
|
-
re as c,
|
|
824
|
-
ee as d,
|
|
825
|
-
Y as e,
|
|
826
|
-
T as f,
|
|
827
|
-
z as g,
|
|
828
|
-
B as h,
|
|
829
|
-
X as i,
|
|
830
|
-
H as j,
|
|
831
|
-
te as k,
|
|
832
|
-
C as l,
|
|
833
|
-
y as m,
|
|
834
|
-
U as n,
|
|
835
|
-
k as r,
|
|
836
|
-
Q as u,
|
|
837
|
-
L as v
|
|
838
|
-
};
|
|
839
|
-
//# sourceMappingURL=forms-core-B1bx1drO.js.map
|