@page-speed/forms 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/README.md +469 -0
- package/dist/builder.cjs +4 -0
- package/dist/builder.cjs.map +1 -0
- package/dist/builder.d.cts +2 -0
- package/dist/builder.d.ts +2 -0
- package/dist/builder.js +3 -0
- package/dist/builder.js.map +1 -0
- package/dist/chunk-2FXAQT7S.cjs +236 -0
- package/dist/chunk-2FXAQT7S.cjs.map +1 -0
- package/dist/chunk-A3UV7BIN.js +357 -0
- package/dist/chunk-A3UV7BIN.js.map +1 -0
- package/dist/chunk-P37YLBFA.cjs +138 -0
- package/dist/chunk-P37YLBFA.cjs.map +1 -0
- package/dist/chunk-WHQMBQNI.js +127 -0
- package/dist/chunk-WHQMBQNI.js.map +1 -0
- package/dist/chunk-YTTOWHBZ.js +217 -0
- package/dist/chunk-YTTOWHBZ.js.map +1 -0
- package/dist/chunk-ZQCPEOB6.cjs +382 -0
- package/dist/chunk-ZQCPEOB6.cjs.map +1 -0
- package/dist/core.cjs +28 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +143 -0
- package/dist/core.d.ts +143 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +28 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/inputs.cjs +555 -0
- package/dist/inputs.cjs.map +1 -0
- package/dist/inputs.d.cts +433 -0
- package/dist/inputs.d.ts +433 -0
- package/dist/inputs.js +529 -0
- package/dist/inputs.js.map +1 -0
- package/dist/integration.cjs +4 -0
- package/dist/integration.cjs.map +1 -0
- package/dist/integration.d.cts +2 -0
- package/dist/integration.d.ts +2 -0
- package/dist/integration.js +3 -0
- package/dist/integration.js.map +1 -0
- package/dist/types-Cw5CeZP-.d.cts +387 -0
- package/dist/types-Cw5CeZP-.d.ts +387 -0
- package/dist/upload.cjs +4 -0
- package/dist/upload.cjs.map +1 -0
- package/dist/upload.d.cts +2 -0
- package/dist/upload.d.ts +2 -0
- package/dist/upload.js +3 -0
- package/dist/upload.js.map +1 -0
- package/dist/validation-rules.cjs +80 -0
- package/dist/validation-rules.cjs.map +1 -0
- package/dist/validation-rules.d.cts +123 -0
- package/dist/validation-rules.d.ts +123 -0
- package/dist/validation-rules.js +3 -0
- package/dist/validation-rules.js.map +1 -0
- package/dist/validation-utils.cjs +48 -0
- package/dist/validation-utils.cjs.map +1 -0
- package/dist/validation-utils.d.cts +166 -0
- package/dist/validation-utils.d.ts +166 -0
- package/dist/validation-utils.js +3 -0
- package/dist/validation-utils.js.map +1 -0
- package/dist/validation-valibot.cjs +94 -0
- package/dist/validation-valibot.cjs.map +1 -0
- package/dist/validation-valibot.d.cts +92 -0
- package/dist/validation-valibot.d.ts +92 -0
- package/dist/validation-valibot.js +91 -0
- package/dist/validation-valibot.js.map +1 -0
- package/dist/validation.cjs +121 -0
- package/dist/validation.cjs.map +1 -0
- package/dist/validation.d.cts +4 -0
- package/dist/validation.d.ts +4 -0
- package/dist/validation.js +4 -0
- package/dist/validation.js.map +1 -0
- package/package.json +133 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Core TypeScript types for @page-speed/forms
|
|
5
|
+
*
|
|
6
|
+
* Provides type-safe form state management, validation, and submission handling
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Generic form values type
|
|
11
|
+
* Represents the structure of form data
|
|
12
|
+
*/
|
|
13
|
+
type FormValues = Record<string, any>;
|
|
14
|
+
/**
|
|
15
|
+
* Form errors type
|
|
16
|
+
* Maps field names to error messages
|
|
17
|
+
*/
|
|
18
|
+
type FormErrors<T extends FormValues = FormValues> = {
|
|
19
|
+
[K in keyof T]?: string | string[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Touched fields type
|
|
23
|
+
* Tracks which fields have been interacted with
|
|
24
|
+
*/
|
|
25
|
+
type TouchedFields<T extends FormValues = FormValues> = {
|
|
26
|
+
[K in keyof T]?: boolean;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Field validation function
|
|
30
|
+
* Validates a single field value
|
|
31
|
+
*/
|
|
32
|
+
type FieldValidator<T = any> = (value: T, allValues: FormValues) => string | undefined | Promise<string | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Form validation schema
|
|
35
|
+
* Defines validation rules for form fields
|
|
36
|
+
*/
|
|
37
|
+
type ValidationSchema<T extends FormValues = FormValues> = {
|
|
38
|
+
[K in keyof T]?: FieldValidator<T[K]> | FieldValidator<T[K]>[];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Validation mode configuration
|
|
42
|
+
*/
|
|
43
|
+
type ValidationMode = "onChange" | "onBlur" | "onSubmit";
|
|
44
|
+
/**
|
|
45
|
+
* Form submission status
|
|
46
|
+
*/
|
|
47
|
+
type SubmissionStatus = "idle" | "submitting" | "success" | "error";
|
|
48
|
+
/**
|
|
49
|
+
* Form helpers provided to submission handler
|
|
50
|
+
*/
|
|
51
|
+
interface FormHelpers<T extends FormValues = FormValues> {
|
|
52
|
+
/**
|
|
53
|
+
* Set form values
|
|
54
|
+
*/
|
|
55
|
+
setValues: (values: T | ((prev: T) => T)) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Set a single field value
|
|
58
|
+
*/
|
|
59
|
+
setFieldValue: <K extends keyof T>(field: K, value: T[K]) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Set form errors
|
|
62
|
+
*/
|
|
63
|
+
setErrors: (errors: FormErrors<T>) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Set a single field error
|
|
66
|
+
*/
|
|
67
|
+
setFieldError: <K extends keyof T>(field: K, error: string | undefined) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Set touched fields
|
|
70
|
+
*/
|
|
71
|
+
setTouched: (touched: TouchedFields<T>) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Set a single field as touched
|
|
74
|
+
*/
|
|
75
|
+
setFieldTouched: <K extends keyof T>(field: K, touched: boolean) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Mark submission as complete
|
|
78
|
+
*/
|
|
79
|
+
setSubmitting: (submitting: boolean) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Reset form to initial values
|
|
82
|
+
*/
|
|
83
|
+
resetForm: () => void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Form submission handler
|
|
87
|
+
*/
|
|
88
|
+
type SubmitHandler<T extends FormValues = FormValues> = (values: T, helpers: FormHelpers<T>) => void | Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Form error handler
|
|
91
|
+
*/
|
|
92
|
+
type ErrorHandler<T extends FormValues = FormValues> = (errors: FormErrors<T>) => void;
|
|
93
|
+
/**
|
|
94
|
+
* useForm hook options
|
|
95
|
+
*/
|
|
96
|
+
interface UseFormOptions<T extends FormValues = FormValues> {
|
|
97
|
+
/**
|
|
98
|
+
* Initial form values
|
|
99
|
+
*/
|
|
100
|
+
initialValues: T;
|
|
101
|
+
/**
|
|
102
|
+
* Validation schema
|
|
103
|
+
*/
|
|
104
|
+
validationSchema?: ValidationSchema<T>;
|
|
105
|
+
/**
|
|
106
|
+
* When to validate fields
|
|
107
|
+
* @default "onBlur"
|
|
108
|
+
*/
|
|
109
|
+
validateOn?: ValidationMode;
|
|
110
|
+
/**
|
|
111
|
+
* When to revalidate fields after initial validation
|
|
112
|
+
* @default "onChange"
|
|
113
|
+
*/
|
|
114
|
+
revalidateOn?: ValidationMode;
|
|
115
|
+
/**
|
|
116
|
+
* Form submission handler
|
|
117
|
+
*/
|
|
118
|
+
onSubmit: SubmitHandler<T>;
|
|
119
|
+
/**
|
|
120
|
+
* Form error handler
|
|
121
|
+
*/
|
|
122
|
+
onError?: ErrorHandler<T>;
|
|
123
|
+
/**
|
|
124
|
+
* Enable debug mode
|
|
125
|
+
* @default false
|
|
126
|
+
*/
|
|
127
|
+
debug?: boolean;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Form state returned by useForm
|
|
131
|
+
*/
|
|
132
|
+
interface FormState<T extends FormValues = FormValues> {
|
|
133
|
+
/**
|
|
134
|
+
* Current form values
|
|
135
|
+
*/
|
|
136
|
+
values: T;
|
|
137
|
+
/**
|
|
138
|
+
* Current form errors
|
|
139
|
+
*/
|
|
140
|
+
errors: FormErrors<T>;
|
|
141
|
+
/**
|
|
142
|
+
* Touched fields
|
|
143
|
+
*/
|
|
144
|
+
touched: TouchedFields<T>;
|
|
145
|
+
/**
|
|
146
|
+
* Is form currently submitting
|
|
147
|
+
*/
|
|
148
|
+
isSubmitting: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Is form valid (no errors)
|
|
151
|
+
*/
|
|
152
|
+
isValid: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Has form been touched
|
|
155
|
+
*/
|
|
156
|
+
isDirty: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Submission status
|
|
159
|
+
*/
|
|
160
|
+
status: SubmissionStatus;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Form actions returned by useForm
|
|
164
|
+
*/
|
|
165
|
+
interface FormActions<T extends FormValues = FormValues> {
|
|
166
|
+
/**
|
|
167
|
+
* Handle form submission
|
|
168
|
+
*/
|
|
169
|
+
handleSubmit: (e?: React.FormEvent) => Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Set form values
|
|
172
|
+
*/
|
|
173
|
+
setValues: (values: T | ((prev: T) => T)) => void;
|
|
174
|
+
/**
|
|
175
|
+
* Set a single field value
|
|
176
|
+
*/
|
|
177
|
+
setFieldValue: <K extends keyof T>(field: K, value: T[K]) => void;
|
|
178
|
+
/**
|
|
179
|
+
* Set form errors
|
|
180
|
+
*/
|
|
181
|
+
setErrors: (errors: FormErrors<T>) => void;
|
|
182
|
+
/**
|
|
183
|
+
* Set a single field error
|
|
184
|
+
*/
|
|
185
|
+
setFieldError: <K extends keyof T>(field: K, error: string | undefined) => void;
|
|
186
|
+
/**
|
|
187
|
+
* Set touched fields
|
|
188
|
+
*/
|
|
189
|
+
setTouched: (touched: TouchedFields<T>) => void;
|
|
190
|
+
/**
|
|
191
|
+
* Set a single field as touched
|
|
192
|
+
*/
|
|
193
|
+
setFieldTouched: <K extends keyof T>(field: K, touched: boolean) => void;
|
|
194
|
+
/**
|
|
195
|
+
* Validate entire form
|
|
196
|
+
*/
|
|
197
|
+
validateForm: () => Promise<FormErrors<T>>;
|
|
198
|
+
/**
|
|
199
|
+
* Validate a single field
|
|
200
|
+
*/
|
|
201
|
+
validateField: <K extends keyof T>(field: K) => Promise<string | undefined>;
|
|
202
|
+
/**
|
|
203
|
+
* Reset form to initial values
|
|
204
|
+
*/
|
|
205
|
+
resetForm: () => void;
|
|
206
|
+
/**
|
|
207
|
+
* Get field props for binding to inputs
|
|
208
|
+
*/
|
|
209
|
+
getFieldProps: <K extends keyof T>(field: K) => FieldInputProps<T[K]>;
|
|
210
|
+
/**
|
|
211
|
+
* Get field meta information
|
|
212
|
+
*/
|
|
213
|
+
getFieldMeta: <K extends keyof T>(field: K) => FieldMeta;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Complete form API returned by useForm
|
|
217
|
+
*/
|
|
218
|
+
type UseFormReturn<T extends FormValues = FormValues> = FormState<T> & FormActions<T>;
|
|
219
|
+
/**
|
|
220
|
+
* Field input props for binding to form inputs
|
|
221
|
+
*/
|
|
222
|
+
interface FieldInputProps<T = any> {
|
|
223
|
+
name: string;
|
|
224
|
+
value: T;
|
|
225
|
+
onChange: (value: T) => void;
|
|
226
|
+
onBlur: () => void;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Field meta information
|
|
230
|
+
*/
|
|
231
|
+
interface FieldMeta {
|
|
232
|
+
error?: string | string[];
|
|
233
|
+
touched: boolean;
|
|
234
|
+
isDirty: boolean;
|
|
235
|
+
isValidating: boolean;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* useField hook options
|
|
239
|
+
*/
|
|
240
|
+
interface UseFieldOptions<T = any> {
|
|
241
|
+
/**
|
|
242
|
+
* Field name
|
|
243
|
+
*/
|
|
244
|
+
name: string;
|
|
245
|
+
/**
|
|
246
|
+
* Field validator
|
|
247
|
+
*/
|
|
248
|
+
validate?: FieldValidator<T>;
|
|
249
|
+
/**
|
|
250
|
+
* Transform value before setting
|
|
251
|
+
*/
|
|
252
|
+
transform?: (value: any) => T;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Field state returned by useField
|
|
256
|
+
*/
|
|
257
|
+
interface UseFieldReturn<T = any> {
|
|
258
|
+
/**
|
|
259
|
+
* Input props for binding to form controls
|
|
260
|
+
*/
|
|
261
|
+
field: FieldInputProps<T>;
|
|
262
|
+
/**
|
|
263
|
+
* Field meta information
|
|
264
|
+
*/
|
|
265
|
+
meta: FieldMeta;
|
|
266
|
+
/**
|
|
267
|
+
* Field helpers
|
|
268
|
+
*/
|
|
269
|
+
helpers: {
|
|
270
|
+
setValue: (value: T) => void;
|
|
271
|
+
setTouched: (touched: boolean) => void;
|
|
272
|
+
setError: (error: string | undefined) => void;
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Form component props
|
|
277
|
+
*/
|
|
278
|
+
interface FormProps<T extends FormValues = FormValues> {
|
|
279
|
+
/**
|
|
280
|
+
* Form instance from useForm
|
|
281
|
+
*/
|
|
282
|
+
form: UseFormReturn<T>;
|
|
283
|
+
/**
|
|
284
|
+
* Form children
|
|
285
|
+
*/
|
|
286
|
+
children: ReactNode;
|
|
287
|
+
/**
|
|
288
|
+
* Additional className
|
|
289
|
+
*/
|
|
290
|
+
className?: string;
|
|
291
|
+
/**
|
|
292
|
+
* Form action URL (for progressive enhancement)
|
|
293
|
+
*/
|
|
294
|
+
action?: string;
|
|
295
|
+
/**
|
|
296
|
+
* Form method (for progressive enhancement)
|
|
297
|
+
*/
|
|
298
|
+
method?: "get" | "post";
|
|
299
|
+
/**
|
|
300
|
+
* Disable browser validation
|
|
301
|
+
* @default true
|
|
302
|
+
*/
|
|
303
|
+
noValidate?: boolean;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Field component props
|
|
307
|
+
*/
|
|
308
|
+
interface FieldProps {
|
|
309
|
+
/**
|
|
310
|
+
* Field name
|
|
311
|
+
*/
|
|
312
|
+
name: string;
|
|
313
|
+
/**
|
|
314
|
+
* Field label
|
|
315
|
+
*/
|
|
316
|
+
label?: ReactNode;
|
|
317
|
+
/**
|
|
318
|
+
* Field description
|
|
319
|
+
*/
|
|
320
|
+
description?: ReactNode;
|
|
321
|
+
/**
|
|
322
|
+
* Field children (render prop or component)
|
|
323
|
+
*/
|
|
324
|
+
children: ReactNode | ((field: UseFieldReturn) => ReactNode);
|
|
325
|
+
/**
|
|
326
|
+
* Show error immediately
|
|
327
|
+
* @default false
|
|
328
|
+
*/
|
|
329
|
+
showError?: boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Additional className
|
|
332
|
+
*/
|
|
333
|
+
className?: string;
|
|
334
|
+
/**
|
|
335
|
+
* Field validator
|
|
336
|
+
*/
|
|
337
|
+
validate?: FieldValidator;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Input component base props
|
|
341
|
+
*/
|
|
342
|
+
interface InputProps<T = string> {
|
|
343
|
+
/**
|
|
344
|
+
* Input name
|
|
345
|
+
*/
|
|
346
|
+
name: string;
|
|
347
|
+
/**
|
|
348
|
+
* Input value
|
|
349
|
+
*/
|
|
350
|
+
value: T;
|
|
351
|
+
/**
|
|
352
|
+
* Change handler
|
|
353
|
+
*/
|
|
354
|
+
onChange: (value: T) => void;
|
|
355
|
+
/**
|
|
356
|
+
* Blur handler
|
|
357
|
+
*/
|
|
358
|
+
onBlur?: () => void;
|
|
359
|
+
/**
|
|
360
|
+
* Placeholder text
|
|
361
|
+
*/
|
|
362
|
+
placeholder?: string;
|
|
363
|
+
/**
|
|
364
|
+
* Is input disabled
|
|
365
|
+
*/
|
|
366
|
+
disabled?: boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Is input required
|
|
369
|
+
*/
|
|
370
|
+
required?: boolean;
|
|
371
|
+
/**
|
|
372
|
+
* Has error
|
|
373
|
+
*/
|
|
374
|
+
error?: boolean;
|
|
375
|
+
/**
|
|
376
|
+
* Additional className
|
|
377
|
+
*/
|
|
378
|
+
className?: string;
|
|
379
|
+
/**
|
|
380
|
+
* ARIA attributes
|
|
381
|
+
*/
|
|
382
|
+
"aria-invalid"?: boolean;
|
|
383
|
+
"aria-describedby"?: string;
|
|
384
|
+
"aria-required"?: boolean;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export type { ErrorHandler as E, FieldValidator as F, InputProps as I, SubmissionStatus as S, TouchedFields as T, UseFormOptions as U, ValidationSchema as V, ValidationMode as a, FormValues as b, UseFormReturn as c, UseFieldOptions as d, UseFieldReturn as e, FormProps as f, FieldProps as g, FormErrors as h, FormHelpers as i, SubmitHandler as j, FormState as k, FormActions as l, FieldInputProps as m, FieldMeta as n };
|
package/dist/upload.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"upload.cjs"}
|
package/dist/upload.d.ts
ADDED
package/dist/upload.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"upload.js"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk2FXAQT7S_cjs = require('./chunk-2FXAQT7S.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "alpha", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunk2FXAQT7S_cjs.alpha; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "alphanumeric", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunk2FXAQT7S_cjs.alphanumeric; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "compose", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunk2FXAQT7S_cjs.compose; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "creditCard", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return chunk2FXAQT7S_cjs.creditCard; }
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "email", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return chunk2FXAQT7S_cjs.email; }
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "integer", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return chunk2FXAQT7S_cjs.integer; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "matches", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return chunk2FXAQT7S_cjs.matches; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "max", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return chunk2FXAQT7S_cjs.max; }
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "maxLength", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () { return chunk2FXAQT7S_cjs.maxLength; }
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "min", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () { return chunk2FXAQT7S_cjs.min; }
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(exports, "minLength", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () { return chunk2FXAQT7S_cjs.minLength; }
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "numeric", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () { return chunk2FXAQT7S_cjs.numeric; }
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, "oneOf", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () { return chunk2FXAQT7S_cjs.oneOf; }
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(exports, "pattern", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function () { return chunk2FXAQT7S_cjs.pattern; }
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "phone", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function () { return chunk2FXAQT7S_cjs.phone; }
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "postalCode", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () { return chunk2FXAQT7S_cjs.postalCode; }
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(exports, "required", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function () { return chunk2FXAQT7S_cjs.required; }
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "url", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () { return chunk2FXAQT7S_cjs.url; }
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=validation-rules.cjs.map
|
|
80
|
+
//# sourceMappingURL=validation-rules.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"validation-rules.cjs"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { F as FieldValidator } from './types-Cw5CeZP-.cjs';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @page-speed/forms - Validation Rules
|
|
6
|
+
*
|
|
7
|
+
* Common validation rules for form fields.
|
|
8
|
+
* Tree-shakable - import only the rules you need.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { required, email, minLength } from '@page-speed/forms/validation/rules';
|
|
13
|
+
*
|
|
14
|
+
* const form = useForm({
|
|
15
|
+
* validationSchema: {
|
|
16
|
+
* email: [required(), email()],
|
|
17
|
+
* password: [required(), minLength(8)],
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Error message template function
|
|
25
|
+
* Allows customization of error messages
|
|
26
|
+
*/
|
|
27
|
+
type ErrorMessageFn = (params?: Record<string, any>) => string;
|
|
28
|
+
/**
|
|
29
|
+
* Validation rule options
|
|
30
|
+
*/
|
|
31
|
+
interface ValidationRuleOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Custom error message
|
|
34
|
+
*/
|
|
35
|
+
message?: string | ErrorMessageFn;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Required field validator
|
|
39
|
+
* Ensures field has a truthy value
|
|
40
|
+
*/
|
|
41
|
+
declare function required(options?: ValidationRuleOptions): FieldValidator;
|
|
42
|
+
/**
|
|
43
|
+
* Email validator
|
|
44
|
+
* Validates email format using RFC 5322 compatible regex
|
|
45
|
+
*/
|
|
46
|
+
declare function email(options?: ValidationRuleOptions): FieldValidator;
|
|
47
|
+
/**
|
|
48
|
+
* URL validator
|
|
49
|
+
* Validates URL format
|
|
50
|
+
*/
|
|
51
|
+
declare function url(options?: ValidationRuleOptions): FieldValidator;
|
|
52
|
+
/**
|
|
53
|
+
* Phone number validator
|
|
54
|
+
* Validates US phone numbers (flexible formats)
|
|
55
|
+
*/
|
|
56
|
+
declare function phone(options?: ValidationRuleOptions): FieldValidator;
|
|
57
|
+
/**
|
|
58
|
+
* Minimum length validator
|
|
59
|
+
*/
|
|
60
|
+
declare function minLength(min: number, options?: ValidationRuleOptions): FieldValidator;
|
|
61
|
+
/**
|
|
62
|
+
* Maximum length validator
|
|
63
|
+
*/
|
|
64
|
+
declare function maxLength(max: number, options?: ValidationRuleOptions): FieldValidator;
|
|
65
|
+
/**
|
|
66
|
+
* Minimum value validator (for numbers)
|
|
67
|
+
*/
|
|
68
|
+
declare function min(minValue: number, options?: ValidationRuleOptions): FieldValidator;
|
|
69
|
+
/**
|
|
70
|
+
* Maximum value validator (for numbers)
|
|
71
|
+
*/
|
|
72
|
+
declare function max(maxValue: number, options?: ValidationRuleOptions): FieldValidator;
|
|
73
|
+
/**
|
|
74
|
+
* Pattern validator
|
|
75
|
+
* Validates against a regular expression
|
|
76
|
+
*/
|
|
77
|
+
declare function pattern(regex: RegExp, options?: ValidationRuleOptions): FieldValidator;
|
|
78
|
+
/**
|
|
79
|
+
* Match validator
|
|
80
|
+
* Ensures field matches another field (e.g., password confirmation)
|
|
81
|
+
*/
|
|
82
|
+
declare function matches(fieldName: string, options?: ValidationRuleOptions): FieldValidator;
|
|
83
|
+
/**
|
|
84
|
+
* One of validator
|
|
85
|
+
* Ensures value is one of the allowed values
|
|
86
|
+
*/
|
|
87
|
+
declare function oneOf<T = any>(allowedValues: T[], options?: ValidationRuleOptions): FieldValidator<T>;
|
|
88
|
+
/**
|
|
89
|
+
* Credit card validator
|
|
90
|
+
* Validates credit card numbers using Luhn algorithm
|
|
91
|
+
*/
|
|
92
|
+
declare function creditCard(options?: ValidationRuleOptions): FieldValidator;
|
|
93
|
+
/**
|
|
94
|
+
* Postal code validator (US ZIP codes)
|
|
95
|
+
*/
|
|
96
|
+
declare function postalCode(options?: ValidationRuleOptions): FieldValidator;
|
|
97
|
+
/**
|
|
98
|
+
* Alpha validator
|
|
99
|
+
* Ensures value contains only alphabetic characters
|
|
100
|
+
*/
|
|
101
|
+
declare function alpha(options?: ValidationRuleOptions): FieldValidator;
|
|
102
|
+
/**
|
|
103
|
+
* Alphanumeric validator
|
|
104
|
+
* Ensures value contains only letters and numbers
|
|
105
|
+
*/
|
|
106
|
+
declare function alphanumeric(options?: ValidationRuleOptions): FieldValidator;
|
|
107
|
+
/**
|
|
108
|
+
* Numeric validator
|
|
109
|
+
* Ensures value is a valid number
|
|
110
|
+
*/
|
|
111
|
+
declare function numeric(options?: ValidationRuleOptions): FieldValidator;
|
|
112
|
+
/**
|
|
113
|
+
* Integer validator
|
|
114
|
+
* Ensures value is a valid integer
|
|
115
|
+
*/
|
|
116
|
+
declare function integer(options?: ValidationRuleOptions): FieldValidator;
|
|
117
|
+
/**
|
|
118
|
+
* Compose multiple validators
|
|
119
|
+
* Runs validators in sequence and returns first error
|
|
120
|
+
*/
|
|
121
|
+
declare function compose(...validators: FieldValidator[]): FieldValidator;
|
|
122
|
+
|
|
123
|
+
export { type ErrorMessageFn, type ValidationRuleOptions, alpha, alphanumeric, compose, creditCard, email, integer, matches, max, maxLength, min, minLength, numeric, oneOf, pattern, phone, postalCode, required, url };
|