@tachui/forms 0.7.0-alpha1 → 0.8.0-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 +136 -0
- package/dist/DatePicker-D5nRFTUm.js +475 -0
- package/dist/DatePicker-D5nRFTUm.js.map +1 -0
- package/dist/Select-yZyKooXk.js +945 -0
- package/dist/Select-yZyKooXk.js.map +1 -0
- package/dist/Slider-0-oal5YR.js +644 -0
- package/dist/Slider-0-oal5YR.js.map +1 -0
- package/dist/TextField-hX15dY3U.js +509 -0
- package/dist/TextField-hX15dY3U.js.map +1 -0
- package/dist/components/advanced/Slider.d.ts +190 -0
- package/dist/components/advanced/Slider.d.ts.map +1 -0
- package/dist/components/advanced/Stepper.d.ts +161 -0
- package/dist/components/advanced/Stepper.d.ts.map +1 -0
- package/dist/components/advanced/index.d.ts +15 -0
- package/dist/components/advanced/index.d.ts.map +1 -0
- package/dist/components/advanced/index.js +6 -0
- package/dist/{state → components/advanced}/index.js.map +1 -1
- package/dist/components/date-picker/DatePicker.d.ts +126 -0
- package/dist/components/date-picker/DatePicker.d.ts.map +1 -0
- package/dist/components/date-picker/index.d.ts +14 -0
- package/dist/components/date-picker/index.d.ts.map +1 -0
- package/dist/components/date-picker/index.js +5 -0
- package/dist/components/{index.js.map → date-picker/index.js.map} +1 -1
- package/dist/components/form-container/index.d.ts +58 -0
- package/dist/components/form-container/index.d.ts.map +1 -0
- package/dist/components/selection/Checkbox.d.ts.map +1 -0
- package/dist/components/selection/Radio.d.ts.map +1 -0
- package/dist/components/selection/Select.d.ts.map +1 -0
- package/dist/components/selection/index.d.ts +68 -0
- package/dist/components/selection/index.d.ts.map +1 -0
- package/dist/components/selection/index.js +12 -0
- package/dist/components/selection/index.js.map +1 -0
- package/dist/components/text-input/TextField.d.ts.map +1 -0
- package/dist/components/text-input/index.d.ts +8 -0
- package/dist/components/text-input/index.d.ts.map +1 -0
- package/dist/components/text-input/index.js +18 -0
- package/dist/components/text-input/index.js.map +1 -0
- package/dist/index-D3WfkqVv.js +249 -0
- package/dist/index-D3WfkqVv.js.map +1 -0
- package/dist/index.d.ts +10 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +196 -376
- package/dist/index.js.map +1 -1
- package/dist/state/index.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/validation/component-validation.d.ts +11 -2
- package/dist/validation/component-validation.d.ts.map +1 -1
- package/dist/validation/index.d.ts.map +1 -1
- package/dist/validation/index.js +687 -17
- package/dist/validation/index.js.map +1 -1
- package/package.json +54 -41
- package/src/components/advanced/Slider.ts +722 -0
- package/src/components/advanced/Stepper.ts +715 -0
- package/src/components/advanced/index.ts +20 -0
- package/src/components/date-picker/DatePicker.ts +925 -0
- package/src/components/date-picker/index.ts +20 -0
- package/src/components/form-container/index.ts +266 -0
- package/src/components/selection/Checkbox.ts +478 -0
- package/src/components/selection/Radio.ts +470 -0
- package/src/components/selection/Select.ts +620 -0
- package/src/components/selection/index.ts +81 -0
- package/src/components/text-input/TextField.ts +728 -0
- package/src/components/text-input/index.ts +35 -0
- package/src/index.ts +48 -0
- package/src/state/index.ts +544 -0
- package/src/types/index.ts +579 -0
- package/src/utils/formatters.ts +184 -0
- package/src/utils/index.ts +57 -0
- package/src/validation/component-validation.ts +429 -0
- package/src/validation/index.ts +641 -0
- 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/Form.d.ts +0 -76
- package/dist/components/Form.d.ts.map +0 -1
- package/dist/components/index.cjs +0 -2
- package/dist/components/index.cjs.map +0 -1
- package/dist/components/index.d.ts +0 -9
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -31
- package/dist/components/input/Checkbox.d.ts.map +0 -1
- package/dist/components/input/Radio.d.ts.map +0 -1
- package/dist/components/input/Select.d.ts.map +0 -1
- package/dist/components/input/TextField.d.ts.map +0 -1
- package/dist/components/input/index.d.ts +0 -11
- package/dist/components/input/index.d.ts.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/state/index.cjs +0 -2
- package/dist/state/index.cjs.map +0 -1
- package/dist/state/index.js +0 -9
- package/dist/utils/validators.d.ts +0 -101
- package/dist/utils/validators.d.ts.map +0 -1
- package/dist/validation/index.cjs +0 -2
- package/dist/validation/index.cjs.map +0 -1
- /package/dist/components/{input → selection}/Checkbox.d.ts +0 -0
- /package/dist/components/{input → selection}/Radio.d.ts +0 -0
- /package/dist/components/{input → selection}/Select.d.ts +0 -0
- /package/dist/components/{input → text-input}/TextField.d.ts +0 -0
package/dist/validation/index.js
CHANGED
|
@@ -1,21 +1,691 @@
|
|
|
1
|
-
|
|
1
|
+
class s extends Error {
|
|
2
|
+
constructor(t, r) {
|
|
3
|
+
super(t), this.context = r, this.name = "FormsValidationError";
|
|
4
|
+
}
|
|
5
|
+
getFormattedMessage() {
|
|
6
|
+
const { component: t, suggestion: r, example: a, documentation: n } = this.context;
|
|
7
|
+
let i = `❌ [@tachui/advanced-forms] ${t} Component Error: ${this.message}
|
|
8
|
+
`;
|
|
9
|
+
return r && (i += `
|
|
10
|
+
💡 Suggestion: ${r}
|
|
11
|
+
`), a && (i += `
|
|
12
|
+
❌ Wrong: ${a.wrong}`, i += `
|
|
13
|
+
✅ Correct: ${a.correct}
|
|
14
|
+
`), n && (i += `
|
|
15
|
+
📚 Documentation: ${n}`), i;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const l = {
|
|
19
|
+
// TextField Component
|
|
20
|
+
validateTextField(e) {
|
|
21
|
+
if (e.length === 0)
|
|
22
|
+
throw new s(
|
|
23
|
+
"TextField component requires a props object with name",
|
|
24
|
+
{
|
|
25
|
+
component: "TextField",
|
|
26
|
+
suggestion: 'Add name property: TextField({ name: "fieldName" })',
|
|
27
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/textfield",
|
|
28
|
+
example: {
|
|
29
|
+
wrong: "TextField()",
|
|
30
|
+
correct: 'TextField({ name: "email", value: emailSignal })'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
const [t] = e;
|
|
35
|
+
if (!t || typeof t != "object")
|
|
36
|
+
throw new s("TextField requires a props object", {
|
|
37
|
+
component: "TextField",
|
|
38
|
+
suggestion: "Pass a props object with name property",
|
|
39
|
+
example: {
|
|
40
|
+
wrong: 'TextField("email")',
|
|
41
|
+
correct: 'TextField({ name: "email" })'
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const r = t;
|
|
45
|
+
if (!r.name || typeof r.name != "string")
|
|
46
|
+
throw new s(
|
|
47
|
+
"TextField name property is required and must be a string",
|
|
48
|
+
{
|
|
49
|
+
component: "TextField",
|
|
50
|
+
suggestion: "Provide a unique name for the field",
|
|
51
|
+
example: {
|
|
52
|
+
wrong: 'TextField({ placeholder: "Email" })',
|
|
53
|
+
correct: 'TextField({ name: "email", placeholder: "Email" })'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
// EmailField Component
|
|
59
|
+
validateEmailField(e) {
|
|
60
|
+
if (e.length === 0)
|
|
61
|
+
throw new s(
|
|
62
|
+
"EmailField component requires a props object with name",
|
|
63
|
+
{
|
|
64
|
+
component: "EmailField",
|
|
65
|
+
suggestion: 'Add name property: EmailField({ name: "email" })',
|
|
66
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/emailfield",
|
|
67
|
+
example: {
|
|
68
|
+
wrong: "EmailField()",
|
|
69
|
+
correct: 'EmailField({ name: "email", value: emailSignal })'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
const [t] = e;
|
|
74
|
+
if (!t || typeof t != "object")
|
|
75
|
+
throw new s("EmailField requires a props object", {
|
|
76
|
+
component: "EmailField",
|
|
77
|
+
suggestion: "Pass a props object with name property",
|
|
78
|
+
example: {
|
|
79
|
+
wrong: 'EmailField("email@example.com")',
|
|
80
|
+
correct: 'EmailField({ name: "email", value: "email@example.com" })'
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const r = t;
|
|
84
|
+
if (!r.name || typeof r.name != "string")
|
|
85
|
+
throw new s(
|
|
86
|
+
"EmailField name property is required and must be a string",
|
|
87
|
+
{
|
|
88
|
+
component: "EmailField",
|
|
89
|
+
suggestion: "Provide a unique name for the email field",
|
|
90
|
+
example: {
|
|
91
|
+
wrong: 'EmailField({ placeholder: "Email" })',
|
|
92
|
+
correct: 'EmailField({ name: "email", placeholder: "Email" })'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
// PasswordField Component
|
|
98
|
+
validatePasswordField(e) {
|
|
99
|
+
if (e.length === 0)
|
|
100
|
+
throw new s(
|
|
101
|
+
"PasswordField component requires a props object with name",
|
|
102
|
+
{
|
|
103
|
+
component: "PasswordField",
|
|
104
|
+
suggestion: 'Add name property: PasswordField({ name: "password" })',
|
|
105
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/passwordfield",
|
|
106
|
+
example: {
|
|
107
|
+
wrong: "PasswordField()",
|
|
108
|
+
correct: 'PasswordField({ name: "password", value: passwordSignal })'
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
const [t] = e;
|
|
113
|
+
if (!t || typeof t != "object")
|
|
114
|
+
throw new s("PasswordField requires a props object", {
|
|
115
|
+
component: "PasswordField",
|
|
116
|
+
suggestion: "Pass a props object with name property",
|
|
117
|
+
example: {
|
|
118
|
+
wrong: 'PasswordField("password")',
|
|
119
|
+
correct: 'PasswordField({ name: "password", value: passwordSignal })'
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
const r = t;
|
|
123
|
+
if (!r.name || typeof r.name != "string")
|
|
124
|
+
throw new s(
|
|
125
|
+
"PasswordField name property is required and must be a string",
|
|
126
|
+
{
|
|
127
|
+
component: "PasswordField",
|
|
128
|
+
suggestion: "Provide a unique name for the password field",
|
|
129
|
+
example: {
|
|
130
|
+
wrong: 'PasswordField({ placeholder: "Password" })',
|
|
131
|
+
correct: 'PasswordField({ name: "password", placeholder: "Password" })'
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
},
|
|
136
|
+
// PhoneField Component
|
|
137
|
+
validatePhoneField(e) {
|
|
138
|
+
if (e.length === 0)
|
|
139
|
+
throw new s(
|
|
140
|
+
"PhoneField component requires a props object with name",
|
|
141
|
+
{
|
|
142
|
+
component: "PhoneField",
|
|
143
|
+
suggestion: 'Add name property: PhoneField({ name: "phone" })',
|
|
144
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/phonefield",
|
|
145
|
+
example: {
|
|
146
|
+
wrong: "PhoneField()",
|
|
147
|
+
correct: 'PhoneField({ name: "phone", format: "US" })'
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
const [t] = e;
|
|
152
|
+
if (!t || typeof t != "object")
|
|
153
|
+
throw new s("PhoneField requires a props object", {
|
|
154
|
+
component: "PhoneField",
|
|
155
|
+
suggestion: "Pass a props object with name property",
|
|
156
|
+
example: {
|
|
157
|
+
wrong: 'PhoneField("(555) 123-4567")',
|
|
158
|
+
correct: 'PhoneField({ name: "phone", value: phoneSignal })'
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
const r = t;
|
|
162
|
+
if (!r.name || typeof r.name != "string")
|
|
163
|
+
throw new s(
|
|
164
|
+
"PhoneField name property is required and must be a string",
|
|
165
|
+
{
|
|
166
|
+
component: "PhoneField",
|
|
167
|
+
suggestion: "Provide a unique name for the phone field",
|
|
168
|
+
example: {
|
|
169
|
+
wrong: 'PhoneField({ format: "US" })',
|
|
170
|
+
correct: 'PhoneField({ name: "phone", format: "US" })'
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
},
|
|
175
|
+
// NumberField Component
|
|
176
|
+
validateNumberField(e) {
|
|
177
|
+
if (e.length === 0)
|
|
178
|
+
throw new s(
|
|
179
|
+
"NumberField component requires a props object with name",
|
|
180
|
+
{
|
|
181
|
+
component: "NumberField",
|
|
182
|
+
suggestion: 'Add name property: NumberField({ name: "amount" })',
|
|
183
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/numberfield",
|
|
184
|
+
example: {
|
|
185
|
+
wrong: "NumberField()",
|
|
186
|
+
correct: 'NumberField({ name: "amount", min: 0, max: 100 })'
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
const [t] = e;
|
|
191
|
+
if (!t || typeof t != "object")
|
|
192
|
+
throw new s("NumberField requires a props object", {
|
|
193
|
+
component: "NumberField",
|
|
194
|
+
suggestion: "Pass a props object with name property",
|
|
195
|
+
example: {
|
|
196
|
+
wrong: "NumberField(42)",
|
|
197
|
+
correct: 'NumberField({ name: "amount", value: 42 })'
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
const r = t;
|
|
201
|
+
if (!r.name || typeof r.name != "string")
|
|
202
|
+
throw new s(
|
|
203
|
+
"NumberField name property is required and must be a string",
|
|
204
|
+
{
|
|
205
|
+
component: "NumberField",
|
|
206
|
+
suggestion: "Provide a unique name for the number field",
|
|
207
|
+
example: {
|
|
208
|
+
wrong: "NumberField({ min: 0, max: 100 })",
|
|
209
|
+
correct: 'NumberField({ name: "amount", min: 0, max: 100 })'
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
},
|
|
214
|
+
// CreditCardField Component
|
|
215
|
+
validateCreditCardField(e) {
|
|
216
|
+
if (e.length === 0)
|
|
217
|
+
throw new s(
|
|
218
|
+
"CreditCardField component requires a props object with name",
|
|
219
|
+
{
|
|
220
|
+
component: "CreditCardField",
|
|
221
|
+
suggestion: 'Add name property: CreditCardField({ name: "cardNumber" })',
|
|
222
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/creditcardfield",
|
|
223
|
+
example: {
|
|
224
|
+
wrong: "CreditCardField()",
|
|
225
|
+
correct: 'CreditCardField({ name: "cardNumber", onChange: handleChange })'
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
const [t] = e;
|
|
230
|
+
if (!t || typeof t != "object")
|
|
231
|
+
throw new s(
|
|
232
|
+
"CreditCardField requires a props object",
|
|
233
|
+
{
|
|
234
|
+
component: "CreditCardField",
|
|
235
|
+
suggestion: "Pass a props object with name property",
|
|
236
|
+
example: {
|
|
237
|
+
wrong: 'CreditCardField("4111111111111111")',
|
|
238
|
+
correct: 'CreditCardField({ name: "cardNumber", value: cardSignal })'
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
const r = t;
|
|
243
|
+
if (!r.name || typeof r.name != "string")
|
|
244
|
+
throw new s(
|
|
245
|
+
"CreditCardField name property is required and must be a string",
|
|
246
|
+
{
|
|
247
|
+
component: "CreditCardField",
|
|
248
|
+
suggestion: "Provide a unique name for the credit card field",
|
|
249
|
+
example: {
|
|
250
|
+
wrong: 'CreditCardField({ placeholder: "Card Number" })',
|
|
251
|
+
correct: 'CreditCardField({ name: "cardNumber", placeholder: "Card Number" })'
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
// Additional Forms components would go here...
|
|
257
|
+
// (SearchField, URLField, TextArea, ColorField, etc.)
|
|
258
|
+
};
|
|
259
|
+
function p() {
|
|
260
|
+
return [
|
|
261
|
+
{
|
|
262
|
+
packageName: "advanced-forms",
|
|
263
|
+
componentName: "TextField",
|
|
264
|
+
validate: l.validateTextField
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
packageName: "advanced-forms",
|
|
268
|
+
componentName: "EmailField",
|
|
269
|
+
validate: l.validateEmailField
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
packageName: "advanced-forms",
|
|
273
|
+
componentName: "PasswordField",
|
|
274
|
+
validate: l.validatePasswordField
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
packageName: "advanced-forms",
|
|
278
|
+
componentName: "PhoneField",
|
|
279
|
+
validate: l.validatePhoneField
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
packageName: "advanced-forms",
|
|
283
|
+
componentName: "NumberField",
|
|
284
|
+
validate: l.validateNumberField
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
packageName: "advanced-forms",
|
|
288
|
+
componentName: "CreditCardField",
|
|
289
|
+
validate: l.validateCreditCardField
|
|
290
|
+
}
|
|
291
|
+
// Additional validators would be added here for remaining Forms components
|
|
292
|
+
];
|
|
293
|
+
}
|
|
294
|
+
async function g() {
|
|
295
|
+
try {
|
|
296
|
+
const { registerComponentValidator: e } = await import("@tachui/core/validation"), t = p();
|
|
297
|
+
for (const r of t)
|
|
298
|
+
e(r);
|
|
299
|
+
process.env.NODE_ENV !== "production" && console.info(
|
|
300
|
+
`🔍 [@tachui/advanced-forms] Registered ${t.length} component validators`
|
|
301
|
+
);
|
|
302
|
+
} catch (e) {
|
|
303
|
+
process.env.NODE_ENV !== "production" && console.warn(
|
|
304
|
+
"⚠️ [@tachui/advanced-forms] Could not register validators with Core:",
|
|
305
|
+
e
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
typeof window < "u" && process.env.NODE_ENV !== "production" && setTimeout(g, 10);
|
|
310
|
+
const m = {
|
|
311
|
+
required: (e) => ({
|
|
312
|
+
valid: e != null && e !== "",
|
|
313
|
+
message: "This field is required",
|
|
314
|
+
code: "REQUIRED"
|
|
315
|
+
}),
|
|
316
|
+
email: (e) => e ? {
|
|
317
|
+
valid: /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),
|
|
318
|
+
message: "Please enter a valid email address",
|
|
319
|
+
code: "INVALID_EMAIL"
|
|
320
|
+
} : { valid: !0 },
|
|
321
|
+
url: (e) => {
|
|
322
|
+
if (!e) return { valid: !0 };
|
|
323
|
+
try {
|
|
324
|
+
return new URL(e), { valid: !0 };
|
|
325
|
+
} catch {
|
|
326
|
+
return {
|
|
327
|
+
valid: !1,
|
|
328
|
+
message: "Please enter a valid URL",
|
|
329
|
+
code: "INVALID_URL"
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
number: (e) => {
|
|
334
|
+
if (!e) return { valid: !0 };
|
|
335
|
+
const t = Number(e);
|
|
336
|
+
return {
|
|
337
|
+
valid: !Number.isNaN(t) && Number.isFinite(t),
|
|
338
|
+
message: "Please enter a valid number",
|
|
339
|
+
code: "INVALID_NUMBER"
|
|
340
|
+
};
|
|
341
|
+
},
|
|
342
|
+
integer: (e) => {
|
|
343
|
+
if (!e) return { valid: !0 };
|
|
344
|
+
const t = Number(e);
|
|
345
|
+
return {
|
|
346
|
+
valid: !Number.isNaN(t) && Number.isFinite(t) && Number.isInteger(t),
|
|
347
|
+
message: "Please enter a valid integer",
|
|
348
|
+
code: "INVALID_INTEGER"
|
|
349
|
+
};
|
|
350
|
+
},
|
|
351
|
+
min: (e, t) => {
|
|
352
|
+
if (!e) return { valid: !0 };
|
|
353
|
+
const r = Number(e);
|
|
354
|
+
return Number.isNaN(r) ? { valid: !0 } : {
|
|
355
|
+
valid: r >= t.min,
|
|
356
|
+
message: `Value must be at least ${t.min}`,
|
|
357
|
+
code: "MIN_VALUE"
|
|
358
|
+
};
|
|
359
|
+
},
|
|
360
|
+
max: (e, t) => {
|
|
361
|
+
if (!e) return { valid: !0 };
|
|
362
|
+
const r = Number(e);
|
|
363
|
+
return Number.isNaN(r) ? { valid: !0 } : {
|
|
364
|
+
valid: r <= t.max,
|
|
365
|
+
message: `Value must be at most ${t.max}`,
|
|
366
|
+
code: "MAX_VALUE"
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
minLength: (e, t) => e ? {
|
|
370
|
+
valid: e.length >= t.minLength,
|
|
371
|
+
message: `Must be at least ${t.minLength} characters`,
|
|
372
|
+
code: "MIN_LENGTH"
|
|
373
|
+
} : { valid: !0 },
|
|
374
|
+
maxLength: (e, t) => e ? {
|
|
375
|
+
valid: e.length <= t.maxLength,
|
|
376
|
+
message: `Must be at most ${t.maxLength} characters`,
|
|
377
|
+
code: "MAX_LENGTH"
|
|
378
|
+
} : { valid: !0 },
|
|
379
|
+
pattern: (e, t) => e ? {
|
|
380
|
+
valid: (typeof t.pattern == "string" ? new RegExp(t.pattern) : t.pattern).test(e),
|
|
381
|
+
message: t.message || "Value does not match required pattern",
|
|
382
|
+
code: "PATTERN_MISMATCH"
|
|
383
|
+
} : { valid: !0 },
|
|
384
|
+
// Additional validation rules expected by tests
|
|
385
|
+
numeric: (e) => {
|
|
386
|
+
if (!e) return { valid: !0 };
|
|
387
|
+
const t = Number(e);
|
|
388
|
+
return {
|
|
389
|
+
valid: !Number.isNaN(t) && Number.isFinite(t),
|
|
390
|
+
message: "Please enter a valid number",
|
|
391
|
+
code: "INVALID_NUMERIC"
|
|
392
|
+
};
|
|
393
|
+
},
|
|
394
|
+
phone: (e) => {
|
|
395
|
+
if (!e) return { valid: !0 };
|
|
396
|
+
const t = /^\+?[\d\s\-().]+$/, r = e.replace(/[\s\-().]/g, "");
|
|
397
|
+
return {
|
|
398
|
+
valid: t.test(e) && r.length >= 10,
|
|
399
|
+
message: "Please enter a valid phone number",
|
|
400
|
+
code: "INVALID_PHONE"
|
|
401
|
+
};
|
|
402
|
+
},
|
|
403
|
+
creditCard: (e) => {
|
|
404
|
+
if (!e) return { valid: !0 };
|
|
405
|
+
const t = e.replace(/\s/g, "");
|
|
406
|
+
let r = 0, a = !1;
|
|
407
|
+
for (let n = t.length - 1; n >= 0; n--) {
|
|
408
|
+
let i = parseInt(t.charAt(n));
|
|
409
|
+
a && (i *= 2, i > 9 && (i = i % 10 + 1)), r += i, a = !a;
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
valid: /^\d{13,19}$/.test(t) && r % 10 === 0,
|
|
413
|
+
message: "Please enter a valid credit card number",
|
|
414
|
+
code: "INVALID_CREDIT_CARD"
|
|
415
|
+
};
|
|
416
|
+
},
|
|
417
|
+
ssn: (e) => {
|
|
418
|
+
if (!e) return { valid: !0 };
|
|
419
|
+
const t = e.replace(/[-\s]/g, "");
|
|
420
|
+
return {
|
|
421
|
+
valid: /^\d{9}$/.test(t),
|
|
422
|
+
message: "Please enter a valid Social Security Number",
|
|
423
|
+
code: "INVALID_SSN"
|
|
424
|
+
};
|
|
425
|
+
},
|
|
426
|
+
postalCode: (e) => {
|
|
427
|
+
if (!e) return { valid: !0 };
|
|
428
|
+
const t = /^\d{5}(-\d{4})?$/, r = /^[A-Z0-9]{3,10}$/i;
|
|
429
|
+
return {
|
|
430
|
+
valid: t.test(e) || r.test(e),
|
|
431
|
+
message: "Please enter a valid postal code",
|
|
432
|
+
code: "INVALID_POSTAL_CODE"
|
|
433
|
+
};
|
|
434
|
+
},
|
|
435
|
+
zipCode: (e) => e ? {
|
|
436
|
+
valid: /^\d{5}(-\d{4})?$/.test(e),
|
|
437
|
+
message: "Please enter a valid ZIP code",
|
|
438
|
+
code: "INVALID_ZIP_CODE"
|
|
439
|
+
} : { valid: !0 },
|
|
440
|
+
date: (e) => {
|
|
441
|
+
if (!e) return { valid: !0 };
|
|
442
|
+
const t = new Date(e);
|
|
443
|
+
return {
|
|
444
|
+
valid: !Number.isNaN(t.getTime()) && !!e.match(/^\d{4}-\d{2}-\d{2}$/),
|
|
445
|
+
message: "Please enter a valid date (YYYY-MM-DD)",
|
|
446
|
+
code: "INVALID_DATE"
|
|
447
|
+
};
|
|
448
|
+
},
|
|
449
|
+
time: (e) => e ? {
|
|
450
|
+
valid: /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/.test(e),
|
|
451
|
+
message: "Please enter a valid time (HH:MM)",
|
|
452
|
+
code: "INVALID_TIME"
|
|
453
|
+
} : { valid: !0 },
|
|
454
|
+
strongPassword: (e) => {
|
|
455
|
+
if (!e) return { valid: !0 };
|
|
456
|
+
const t = /[A-Z]/.test(e), r = /[a-z]/.test(e), a = /\d/.test(e), n = /\W/.test(e), i = e.length >= 8, o = t && r && a && n && i;
|
|
457
|
+
return {
|
|
458
|
+
valid: o,
|
|
459
|
+
message: o ? void 0 : "Password must be at least 8 characters with uppercase, lowercase, number and special character",
|
|
460
|
+
code: "WEAK_PASSWORD"
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
}, c = /* @__PURE__ */ new Map();
|
|
464
|
+
function v(e) {
|
|
465
|
+
c.set(e.name, e);
|
|
466
|
+
}
|
|
467
|
+
function F(e) {
|
|
468
|
+
c.delete(e);
|
|
469
|
+
}
|
|
470
|
+
function N() {
|
|
471
|
+
return [...Object.keys(m), ...c.keys()];
|
|
472
|
+
}
|
|
473
|
+
function u(e, t, r) {
|
|
474
|
+
for (const a of t) {
|
|
475
|
+
let n;
|
|
476
|
+
if (typeof a == "string") {
|
|
477
|
+
const i = m[a];
|
|
478
|
+
if (i)
|
|
479
|
+
n = i(e, r?.[a]);
|
|
480
|
+
else {
|
|
481
|
+
const o = c.get(a);
|
|
482
|
+
if (o)
|
|
483
|
+
n = o.validate(e, o.options);
|
|
484
|
+
else {
|
|
485
|
+
console.warn(`Unknown validation rule: ${a}`);
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
} else if ("validate" in a)
|
|
490
|
+
n = a.validate(e, a.options);
|
|
491
|
+
else {
|
|
492
|
+
const i = m[a.name];
|
|
493
|
+
if (i)
|
|
494
|
+
n = i(e, a.options);
|
|
495
|
+
else {
|
|
496
|
+
console.warn(`Unknown built-in validation rule: ${a.name}`);
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (!n.valid)
|
|
501
|
+
return n;
|
|
502
|
+
}
|
|
503
|
+
return { valid: !0 };
|
|
504
|
+
}
|
|
505
|
+
function b(e, t) {
|
|
506
|
+
return !t?.rules || t.rules.length === 0 ? { valid: !0 } : u(e.value, t.rules);
|
|
507
|
+
}
|
|
508
|
+
async function f(e, t, r) {
|
|
509
|
+
for (const a of t) {
|
|
510
|
+
let n;
|
|
511
|
+
if (typeof a == "string") {
|
|
512
|
+
const o = m[a];
|
|
513
|
+
if (o)
|
|
514
|
+
n = o(e, r?.[a]);
|
|
515
|
+
else {
|
|
516
|
+
const d = c.get(a);
|
|
517
|
+
if (d)
|
|
518
|
+
n = d.validate(e, d.options);
|
|
519
|
+
else
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
} else if ("validate" in a)
|
|
523
|
+
n = a.validate(e, a.options);
|
|
524
|
+
else {
|
|
525
|
+
const o = m[a.name];
|
|
526
|
+
if (o)
|
|
527
|
+
n = o(e, a.options);
|
|
528
|
+
else
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
const i = await Promise.resolve(n);
|
|
532
|
+
if (!i.valid)
|
|
533
|
+
return i;
|
|
534
|
+
}
|
|
535
|
+
return { valid: !0 };
|
|
536
|
+
}
|
|
537
|
+
function P(e, t = 300) {
|
|
538
|
+
let r, a, n;
|
|
539
|
+
return (i) => new Promise((o) => {
|
|
540
|
+
if (i === a && n) {
|
|
541
|
+
Promise.resolve(n).then(o);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
a = i, clearTimeout(r), r = setTimeout(async () => {
|
|
545
|
+
try {
|
|
546
|
+
n = e(i);
|
|
547
|
+
const d = await Promise.resolve(n);
|
|
548
|
+
o(d);
|
|
549
|
+
} catch {
|
|
550
|
+
o({
|
|
551
|
+
valid: !1,
|
|
552
|
+
message: "Validation error occurred",
|
|
553
|
+
code: "VALIDATION_ERROR"
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
}, t);
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
const E = {
|
|
560
|
+
/**
|
|
561
|
+
* Validate that two fields match (e.g., password confirmation)
|
|
562
|
+
*/
|
|
563
|
+
fieldMatch: (e, t, r = "Fields must match") => (a) => a[e] === a[t] ? { valid: !0 } : {
|
|
564
|
+
valid: !1,
|
|
565
|
+
message: r,
|
|
566
|
+
code: "FIELD_MISMATCH"
|
|
567
|
+
},
|
|
568
|
+
/**
|
|
569
|
+
* Validate that at least one field in a group is filled
|
|
570
|
+
*/
|
|
571
|
+
requireOneOf: (e, t = "At least one field is required") => (r) => e.some((n) => {
|
|
572
|
+
const i = r[n];
|
|
573
|
+
return i != null && i !== "";
|
|
574
|
+
}) ? { valid: !0 } : {
|
|
575
|
+
valid: !1,
|
|
576
|
+
message: t,
|
|
577
|
+
code: "REQUIRE_ONE_OF"
|
|
578
|
+
},
|
|
579
|
+
/**
|
|
580
|
+
* Validate that a field is required when another field has a specific value
|
|
581
|
+
*/
|
|
582
|
+
requiredWhen: (e, t, r, a = `${e} is required`) => (n) => {
|
|
583
|
+
if (n[t] === r) {
|
|
584
|
+
const i = n[e];
|
|
585
|
+
return i != null && i !== "" ? { valid: !0 } : {
|
|
586
|
+
valid: !1,
|
|
587
|
+
message: a,
|
|
588
|
+
code: "REQUIRED_WHEN"
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
return { valid: !0 };
|
|
592
|
+
},
|
|
593
|
+
/**
|
|
594
|
+
* Validate date range (start date before end date)
|
|
595
|
+
*/
|
|
596
|
+
dateRange: (e, t, r = "End date must be after start date") => (a) => {
|
|
597
|
+
const n = a[e], i = a[t];
|
|
598
|
+
if (!n || !i) return { valid: !0 };
|
|
599
|
+
const o = new Date(n);
|
|
600
|
+
return new Date(i) >= o ? { valid: !0 } : {
|
|
601
|
+
valid: !1,
|
|
602
|
+
message: r,
|
|
603
|
+
code: "INVALID_DATE_RANGE"
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
}, x = {
|
|
607
|
+
email: ["required", "email"],
|
|
608
|
+
password: ["required", { name: "minLength", options: { minLength: 8 } }],
|
|
609
|
+
phone: [
|
|
610
|
+
"required",
|
|
611
|
+
{
|
|
612
|
+
name: "pattern",
|
|
613
|
+
options: { pattern: /^\+?[\d\s-()]+$/, message: "Invalid phone number" }
|
|
614
|
+
}
|
|
615
|
+
],
|
|
616
|
+
url: ["required", "url"],
|
|
617
|
+
positiveNumber: ["required", "number", { name: "min", options: { min: 0 } }],
|
|
618
|
+
percentage: [
|
|
619
|
+
"required",
|
|
620
|
+
"number",
|
|
621
|
+
{ name: "min", options: { min: 0 } },
|
|
622
|
+
{ name: "max", options: { max: 100 } }
|
|
623
|
+
]
|
|
624
|
+
};
|
|
625
|
+
class h {
|
|
626
|
+
messages = {};
|
|
627
|
+
constructor(t = {}) {
|
|
628
|
+
this.messages = t;
|
|
629
|
+
}
|
|
630
|
+
setMessage(t, r) {
|
|
631
|
+
this.messages[t] = r;
|
|
632
|
+
}
|
|
633
|
+
setMessages(t) {
|
|
634
|
+
this.messages = { ...this.messages, ...t };
|
|
635
|
+
}
|
|
636
|
+
format(t, r) {
|
|
637
|
+
return t.code && this.messages[t.code] ? this.messages[t.code].replace(
|
|
638
|
+
"${field}",
|
|
639
|
+
r || "field"
|
|
640
|
+
) : t.message || "Validation failed";
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
const C = new h(), V = {
|
|
644
|
+
/**
|
|
645
|
+
* Check if a validation result represents an error
|
|
646
|
+
*/
|
|
647
|
+
isError: (e) => !e.valid,
|
|
648
|
+
/**
|
|
649
|
+
* Check if a validation result is valid
|
|
650
|
+
*/
|
|
651
|
+
isValid: (e) => e.valid,
|
|
652
|
+
/**
|
|
653
|
+
* Combine multiple validation results
|
|
654
|
+
*/
|
|
655
|
+
combineResults: (e) => {
|
|
656
|
+
const t = e.filter((r) => !r.valid);
|
|
657
|
+
return t.length === 0 ? { valid: !0 } : {
|
|
658
|
+
valid: !1,
|
|
659
|
+
message: t.map((r) => r.message).join(", "),
|
|
660
|
+
code: "MULTIPLE_ERRORS"
|
|
661
|
+
};
|
|
662
|
+
},
|
|
663
|
+
/**
|
|
664
|
+
* Create a validation function from a rule configuration
|
|
665
|
+
*/
|
|
666
|
+
createValidator: (e, t) => (r) => u(r, e, t),
|
|
667
|
+
/**
|
|
668
|
+
* Create an async validation function
|
|
669
|
+
*/
|
|
670
|
+
createAsyncValidator: (e, t) => (r) => f(r, e, t)
|
|
671
|
+
};
|
|
2
672
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
673
|
+
E as CrossFieldValidators,
|
|
674
|
+
l as FormsComponentValidation,
|
|
675
|
+
s as FormsValidationError,
|
|
676
|
+
m as VALIDATION_RULES,
|
|
677
|
+
h as ValidationMessageFormatter,
|
|
678
|
+
x as ValidationPresets,
|
|
679
|
+
V as ValidationUtils,
|
|
680
|
+
P as createDebouncedValidator,
|
|
681
|
+
p as createFormsValidators,
|
|
682
|
+
C as defaultMessageFormatter,
|
|
683
|
+
N as getValidationRules,
|
|
684
|
+
g as registerFormsValidators,
|
|
685
|
+
v as registerValidationRule,
|
|
686
|
+
F as unregisterValidationRule,
|
|
687
|
+
b as validateField,
|
|
688
|
+
u as validateValue,
|
|
19
689
|
f as validateValueAsync
|
|
20
690
|
};
|
|
21
691
|
//# sourceMappingURL=index.js.map
|