@omnitron-dev/prism 0.1.1
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 +21 -0
- package/README.md +44 -0
- package/bin/prism.js +13 -0
- package/dist/accessibility/index.d.ts +157 -0
- package/dist/accessibility/index.js +186 -0
- package/dist/accessibility/index.js.map +1 -0
- package/dist/blocks/index.d.ts +1239 -0
- package/dist/blocks/index.js +1712 -0
- package/dist/blocks/index.js.map +1 -0
- package/dist/chunk-77KIJLPP.js +37 -0
- package/dist/chunk-77KIJLPP.js.map +1 -0
- package/dist/chunk-BTIT7WYH.js +339 -0
- package/dist/chunk-BTIT7WYH.js.map +1 -0
- package/dist/chunk-BV32OJ2A.js +1409 -0
- package/dist/chunk-BV32OJ2A.js.map +1 -0
- package/dist/chunk-DDY7TLUI.js +139 -0
- package/dist/chunk-DDY7TLUI.js.map +1 -0
- package/dist/chunk-DXXZ3ITR.js +4227 -0
- package/dist/chunk-DXXZ3ITR.js.map +1 -0
- package/dist/chunk-E3XANPTO.js +2319 -0
- package/dist/chunk-E3XANPTO.js.map +1 -0
- package/dist/chunk-FU52GL2E.js +3 -0
- package/dist/chunk-FU52GL2E.js.map +1 -0
- package/dist/chunk-GYDT5EKX.js +16505 -0
- package/dist/chunk-GYDT5EKX.js.map +1 -0
- package/dist/chunk-HO2GKTWJ.js +28 -0
- package/dist/chunk-HO2GKTWJ.js.map +1 -0
- package/dist/chunk-JDTC2SBY.js +140 -0
- package/dist/chunk-JDTC2SBY.js.map +1 -0
- package/dist/chunk-JNU4QHJK.js +6 -0
- package/dist/chunk-JNU4QHJK.js.map +1 -0
- package/dist/chunk-LAEY5USO.js +2621 -0
- package/dist/chunk-LAEY5USO.js.map +1 -0
- package/dist/chunk-UR6X3W5I.js +530 -0
- package/dist/chunk-UR6X3W5I.js.map +1 -0
- package/dist/chunk-WC2WM2JD.js +883 -0
- package/dist/chunk-WC2WM2JD.js.map +1 -0
- package/dist/chunk-XWL6J6IO.js +40 -0
- package/dist/chunk-XWL6J6IO.js.map +1 -0
- package/dist/cli/index.js +2695 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/config-BA6IeTq9.d.ts +100 -0
- package/dist/core/index.d.ts +454 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/forms/index.d.ts +562 -0
- package/dist/forms/index.js +545 -0
- package/dist/forms/index.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.js +10 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/http/index.d.ts +233 -0
- package/dist/http/index.js +282 -0
- package/dist/http/index.js.map +1 -0
- package/dist/index-odhPSv9I.d.ts +2491 -0
- package/dist/index.css +131 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +9109 -0
- package/dist/index.js +13280 -0
- package/dist/index.js.map +1 -0
- package/dist/layouts/index.d.ts +854 -0
- package/dist/layouts/index.js +6 -0
- package/dist/layouts/index.js.map +1 -0
- package/dist/netron/index.d.ts +4 -0
- package/dist/netron/index.js +4 -0
- package/dist/netron/index.js.map +1 -0
- package/dist/registry/index.d.ts +352 -0
- package/dist/registry/index.js +4 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry-BrDNftd5.d.ts +574 -0
- package/dist/settings-plpR26Xk.d.ts +455 -0
- package/dist/state/index.d.ts +981 -0
- package/dist/state/index.js +5 -0
- package/dist/state/index.js.map +1 -0
- package/dist/theme/index.d.ts +1049 -0
- package/dist/theme/index.js +5 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme-CrXLfP1c.d.ts +389 -0
- package/dist/types/index.d.ts +146 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/use-timeout-D7U3EAtH.d.ts +808 -0
- package/package.json +194 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema Utilities
|
|
7
|
+
*
|
|
8
|
+
* Pre-built Zod schema helpers for common form field validations.
|
|
9
|
+
* Designed to work seamlessly with React Hook Form + Zod resolver.
|
|
10
|
+
*
|
|
11
|
+
* Features:
|
|
12
|
+
* - Type-safe schema builders
|
|
13
|
+
* - Customizable error messages with i18n support
|
|
14
|
+
* - Common field validations (email, phone, date, file, etc.)
|
|
15
|
+
* - Nullable input handling
|
|
16
|
+
* - Slider range validation
|
|
17
|
+
* - Rich text editor validation
|
|
18
|
+
*
|
|
19
|
+
* @module @omnitron-dev/prism/forms
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Common error message configuration.
|
|
24
|
+
*/
|
|
25
|
+
interface SchemaErrorMessages {
|
|
26
|
+
/** Error message when field is required but empty */
|
|
27
|
+
required?: string;
|
|
28
|
+
/** Error message when field format is invalid */
|
|
29
|
+
invalid?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options for file validation.
|
|
33
|
+
*/
|
|
34
|
+
interface FileSchemaOptions extends SchemaErrorMessages {
|
|
35
|
+
/** Maximum file size in bytes */
|
|
36
|
+
maxSize?: number;
|
|
37
|
+
/** Allowed MIME types */
|
|
38
|
+
accept?: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Options for slider range validation.
|
|
42
|
+
*/
|
|
43
|
+
interface SliderRangeOptions extends SchemaErrorMessages {
|
|
44
|
+
/** Minimum value */
|
|
45
|
+
min: number;
|
|
46
|
+
/** Maximum value */
|
|
47
|
+
max: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Pre-built Zod schema helpers for common form validations.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* import { z } from 'zod';
|
|
55
|
+
* import { schemaUtils } from '@omnitron-dev/prism/forms';
|
|
56
|
+
*
|
|
57
|
+
* // Define form schema
|
|
58
|
+
* const UserSchema = z.object({
|
|
59
|
+
* email: schemaUtils.email(),
|
|
60
|
+
* phone: schemaUtils.phone(),
|
|
61
|
+
* birthDate: schemaUtils.date(),
|
|
62
|
+
* avatar: schemaUtils.file(),
|
|
63
|
+
* agreeToTerms: schemaUtils.boolean({ error: 'You must accept the terms' }),
|
|
64
|
+
* bio: schemaUtils.editor(),
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* // With custom error messages
|
|
68
|
+
* const CustomSchema = z.object({
|
|
69
|
+
* email: schemaUtils.email({
|
|
70
|
+
* required: 'Please enter your email',
|
|
71
|
+
* invalid: 'That email doesn\'t look right',
|
|
72
|
+
* }),
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
declare const schemaUtils: {
|
|
77
|
+
/**
|
|
78
|
+
* Email validation schema.
|
|
79
|
+
* Validates format and provides clear error messages.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```tsx
|
|
83
|
+
* const schema = z.object({
|
|
84
|
+
* email: schemaUtils.email(),
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
email: (errors?: SchemaErrorMessages) => z.ZodString;
|
|
89
|
+
/**
|
|
90
|
+
* Phone number validation schema.
|
|
91
|
+
* Basic validation with optional custom validator.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```tsx
|
|
95
|
+
* const schema = z.object({
|
|
96
|
+
* phone: schemaUtils.phone({
|
|
97
|
+
* isValid: (val) => /^\+?[1-9]\d{1,14}$/.test(val),
|
|
98
|
+
* }),
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
phone: (options?: SchemaErrorMessages & {
|
|
103
|
+
isValid?: (val: string) => boolean;
|
|
104
|
+
}) => z.ZodString;
|
|
105
|
+
/**
|
|
106
|
+
* Date validation schema.
|
|
107
|
+
* Works with Date objects, timestamps, and ISO strings.
|
|
108
|
+
* Compatible with date pickers.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* const schema = z.object({
|
|
113
|
+
* birthDate: schemaUtils.date(),
|
|
114
|
+
* appointmentTime: schemaUtils.date({ required: 'Please select a time' }),
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
date: (errors?: SchemaErrorMessages) => z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate, z.ZodNull]>;
|
|
119
|
+
/**
|
|
120
|
+
* Optional date schema (nullable).
|
|
121
|
+
* For date fields that aren't required.
|
|
122
|
+
*/
|
|
123
|
+
dateOptional: (errors?: SchemaErrorMessages) => z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate, z.ZodNull]>>;
|
|
124
|
+
/**
|
|
125
|
+
* Rich text editor validation schema.
|
|
126
|
+
* Treats empty paragraphs as empty content.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```tsx
|
|
130
|
+
* const schema = z.object({
|
|
131
|
+
* description: schemaUtils.editor(),
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
editor: (error?: string) => z.ZodString;
|
|
136
|
+
/**
|
|
137
|
+
* Boolean validation schema.
|
|
138
|
+
* For checkboxes/switches that must be true (e.g., terms acceptance).
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```tsx
|
|
142
|
+
* const schema = z.object({
|
|
143
|
+
* agreeToTerms: schemaUtils.boolean({ error: 'You must accept the terms' }),
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
boolean: (options?: {
|
|
148
|
+
error?: string;
|
|
149
|
+
}) => z.ZodBoolean;
|
|
150
|
+
/**
|
|
151
|
+
* Optional boolean schema.
|
|
152
|
+
* For optional checkboxes.
|
|
153
|
+
*/
|
|
154
|
+
booleanOptional: () => z.ZodOptional<z.ZodBoolean>;
|
|
155
|
+
/**
|
|
156
|
+
* Nullable input wrapper.
|
|
157
|
+
* Wraps any schema to handle null values as required errors.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```tsx
|
|
161
|
+
* const schema = z.object({
|
|
162
|
+
* country: schemaUtils.nullableInput(
|
|
163
|
+
* z.string().min(1),
|
|
164
|
+
* { error: 'Please select a country' }
|
|
165
|
+
* ),
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
nullableInput: <T extends z.ZodTypeAny>(schema: T, options?: {
|
|
170
|
+
error?: string;
|
|
171
|
+
}) => z.ZodNullable<T> & z.ZodType<z.core.output<T> & {}, z.core.input<T> | null, z.core.$ZodTypeInternals<z.core.output<T> & {}, z.core.input<T> | null>>;
|
|
172
|
+
/**
|
|
173
|
+
* Single file upload validation.
|
|
174
|
+
* Supports File objects and URL strings (for existing files).
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```tsx
|
|
178
|
+
* const schema = z.object({
|
|
179
|
+
* avatar: schemaUtils.file(),
|
|
180
|
+
* document: schemaUtils.file({
|
|
181
|
+
* maxSize: 5 * 1024 * 1024, // 5MB
|
|
182
|
+
* accept: ['application/pdf'],
|
|
183
|
+
* }),
|
|
184
|
+
* });
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
file: (options?: FileSchemaOptions) => z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodString, z.ZodNull]>;
|
|
188
|
+
/**
|
|
189
|
+
* Optional single file upload.
|
|
190
|
+
*/
|
|
191
|
+
fileOptional: (options?: Omit<FileSchemaOptions, "required">) => z.ZodNullable<z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodString, z.ZodNull]>>;
|
|
192
|
+
/**
|
|
193
|
+
* Multiple file upload validation.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```tsx
|
|
197
|
+
* const schema = z.object({
|
|
198
|
+
* images: schemaUtils.files({ minFiles: 1, error: 'Upload at least one image' }),
|
|
199
|
+
* });
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
files: (options?: {
|
|
203
|
+
error?: string;
|
|
204
|
+
minFiles?: number;
|
|
205
|
+
}) => z.ZodArray<z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodString]>>;
|
|
206
|
+
/**
|
|
207
|
+
* Slider range validation.
|
|
208
|
+
* For dual-thumb sliders with [min, max] value.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```tsx
|
|
212
|
+
* const schema = z.object({
|
|
213
|
+
* priceRange: schemaUtils.sliderRange({ min: 0, max: 1000 }),
|
|
214
|
+
* });
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
sliderRange: (options: SliderRangeOptions) => z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
218
|
+
/**
|
|
219
|
+
* URL validation schema.
|
|
220
|
+
*/
|
|
221
|
+
url: (errors?: SchemaErrorMessages) => z.ZodString;
|
|
222
|
+
/**
|
|
223
|
+
* Optional URL schema.
|
|
224
|
+
*/
|
|
225
|
+
urlOptional: (errors?: SchemaErrorMessages) => z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
|
|
226
|
+
/**
|
|
227
|
+
* Password validation with strength requirements.
|
|
228
|
+
*/
|
|
229
|
+
password: (options?: {
|
|
230
|
+
minLength?: number;
|
|
231
|
+
requireUppercase?: boolean;
|
|
232
|
+
requireLowercase?: boolean;
|
|
233
|
+
requireNumber?: boolean;
|
|
234
|
+
requireSpecial?: boolean;
|
|
235
|
+
error?: string;
|
|
236
|
+
}) => z.ZodString;
|
|
237
|
+
/**
|
|
238
|
+
* Confirmation field (e.g., confirm password).
|
|
239
|
+
* Use with z.object().refine() for cross-field validation.
|
|
240
|
+
*/
|
|
241
|
+
confirm: (fieldName: string, error?: string) => {
|
|
242
|
+
message: string;
|
|
243
|
+
path: string[];
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Test schema validation with multiple values.
|
|
248
|
+
* Useful for development and debugging.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* testSchema(schemaUtils.email(), [
|
|
253
|
+
* 'valid@email.com',
|
|
254
|
+
* 'invalid-email',
|
|
255
|
+
* '',
|
|
256
|
+
* null,
|
|
257
|
+
* ]);
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
/**
|
|
261
|
+
* Test results from schema validation.
|
|
262
|
+
*/
|
|
263
|
+
interface SchemaTestResult {
|
|
264
|
+
value: unknown;
|
|
265
|
+
success: boolean;
|
|
266
|
+
data?: unknown;
|
|
267
|
+
errors?: string[];
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Test a schema against multiple values.
|
|
271
|
+
* Returns structured results instead of logging to console.
|
|
272
|
+
* Use testSchemaDebug for console output during development.
|
|
273
|
+
*/
|
|
274
|
+
declare function testSchema<T extends z.ZodTypeAny>(schema: T, values: unknown[]): SchemaTestResult[];
|
|
275
|
+
/**
|
|
276
|
+
* Test a schema with console output (development only).
|
|
277
|
+
* This function does nothing in production builds.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* testSchemaDebug(schemaUtils.email(), [
|
|
282
|
+
* 'valid@email.com',
|
|
283
|
+
* 'invalid-email',
|
|
284
|
+
* '',
|
|
285
|
+
* null,
|
|
286
|
+
* ]);
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
declare function testSchemaDebug<T extends z.ZodTypeAny>(schema: T, values: unknown[]): void;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Translation function type.
|
|
293
|
+
* Compatible with i18next t() function signature.
|
|
294
|
+
*/
|
|
295
|
+
type TranslateFunction = (key: string, options?: Record<string, unknown>) => string;
|
|
296
|
+
/**
|
|
297
|
+
* Default translation keys for schema error messages.
|
|
298
|
+
*/
|
|
299
|
+
interface SchemaTranslationKeys {
|
|
300
|
+
'validation.required': string;
|
|
301
|
+
'validation.email.required': string;
|
|
302
|
+
'validation.email.invalid': string;
|
|
303
|
+
'validation.phone.required': string;
|
|
304
|
+
'validation.phone.invalid': string;
|
|
305
|
+
'validation.date.required': string;
|
|
306
|
+
'validation.date.invalid': string;
|
|
307
|
+
'validation.file.required': string;
|
|
308
|
+
'validation.file.tooLarge': string;
|
|
309
|
+
'validation.file.invalidType': string;
|
|
310
|
+
'validation.boolean.required': string;
|
|
311
|
+
'validation.editor.required': string;
|
|
312
|
+
'validation.url.required': string;
|
|
313
|
+
'validation.url.invalid': string;
|
|
314
|
+
'validation.password.minLength': string;
|
|
315
|
+
'validation.password.uppercase': string;
|
|
316
|
+
'validation.password.lowercase': string;
|
|
317
|
+
'validation.password.number': string;
|
|
318
|
+
'validation.password.special': string;
|
|
319
|
+
'validation.confirm.mismatch': string;
|
|
320
|
+
[key: string]: string;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Schema provider configuration.
|
|
324
|
+
*/
|
|
325
|
+
interface SchemaProviderConfig {
|
|
326
|
+
/**
|
|
327
|
+
* Translation function from your i18n library.
|
|
328
|
+
* If not provided, keys will be used as-is.
|
|
329
|
+
*/
|
|
330
|
+
t?: TranslateFunction;
|
|
331
|
+
/**
|
|
332
|
+
* Default locale for error messages.
|
|
333
|
+
* @default 'en'
|
|
334
|
+
*/
|
|
335
|
+
locale?: string;
|
|
336
|
+
/**
|
|
337
|
+
* Custom error message overrides.
|
|
338
|
+
*/
|
|
339
|
+
messages?: Partial<SchemaTranslationKeys>;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Schema context value.
|
|
343
|
+
*/
|
|
344
|
+
interface SchemaContextValue {
|
|
345
|
+
/**
|
|
346
|
+
* Translate a validation key.
|
|
347
|
+
*/
|
|
348
|
+
t: TranslateFunction;
|
|
349
|
+
/**
|
|
350
|
+
* Current locale.
|
|
351
|
+
*/
|
|
352
|
+
locale: string;
|
|
353
|
+
/**
|
|
354
|
+
* Get schema helpers with translated messages.
|
|
355
|
+
*/
|
|
356
|
+
schema: ReturnType<typeof createTranslatedSchemaUtils>;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Create schema utilities with translated error messages.
|
|
360
|
+
*/
|
|
361
|
+
declare function createTranslatedSchemaUtils(t: TranslateFunction): {
|
|
362
|
+
/**
|
|
363
|
+
* Email validation with i18n messages.
|
|
364
|
+
*/
|
|
365
|
+
email: (options?: {
|
|
366
|
+
required?: string;
|
|
367
|
+
invalid?: string;
|
|
368
|
+
}) => z.ZodString;
|
|
369
|
+
/**
|
|
370
|
+
* Phone validation with i18n messages.
|
|
371
|
+
*/
|
|
372
|
+
phone: (options?: {
|
|
373
|
+
required?: string;
|
|
374
|
+
invalid?: string;
|
|
375
|
+
isValid?: (val: string) => boolean;
|
|
376
|
+
}) => z.ZodString;
|
|
377
|
+
/**
|
|
378
|
+
* Date validation with i18n messages.
|
|
379
|
+
*/
|
|
380
|
+
date: (options?: {
|
|
381
|
+
required?: string;
|
|
382
|
+
invalid?: string;
|
|
383
|
+
}) => z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate, z.ZodNull]>;
|
|
384
|
+
/**
|
|
385
|
+
* Optional date schema.
|
|
386
|
+
*/
|
|
387
|
+
dateOptional: (options?: {
|
|
388
|
+
invalid?: string;
|
|
389
|
+
}) => z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate, z.ZodNull]>>;
|
|
390
|
+
/**
|
|
391
|
+
* Boolean (checkbox) validation with i18n messages.
|
|
392
|
+
*/
|
|
393
|
+
boolean: (options?: {
|
|
394
|
+
error?: string;
|
|
395
|
+
}) => z.ZodBoolean;
|
|
396
|
+
/**
|
|
397
|
+
* Optional boolean schema.
|
|
398
|
+
*/
|
|
399
|
+
booleanOptional: () => z.ZodOptional<z.ZodBoolean>;
|
|
400
|
+
/**
|
|
401
|
+
* Rich text editor validation with i18n messages.
|
|
402
|
+
*/
|
|
403
|
+
editor: (options?: {
|
|
404
|
+
error?: string;
|
|
405
|
+
}) => z.ZodString;
|
|
406
|
+
/**
|
|
407
|
+
* File validation with i18n messages.
|
|
408
|
+
*/
|
|
409
|
+
file: (options?: {
|
|
410
|
+
required?: string;
|
|
411
|
+
tooLarge?: string;
|
|
412
|
+
invalidType?: string;
|
|
413
|
+
maxSize?: number;
|
|
414
|
+
accept?: string[];
|
|
415
|
+
}) => z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodString, z.ZodNull]>;
|
|
416
|
+
/**
|
|
417
|
+
* Optional file schema.
|
|
418
|
+
*/
|
|
419
|
+
fileOptional: (options?: {
|
|
420
|
+
tooLarge?: string;
|
|
421
|
+
invalidType?: string;
|
|
422
|
+
maxSize?: number;
|
|
423
|
+
accept?: string[];
|
|
424
|
+
}) => z.ZodNullable<z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodString, z.ZodNull]>>;
|
|
425
|
+
/**
|
|
426
|
+
* Multiple files validation.
|
|
427
|
+
*/
|
|
428
|
+
files: (options?: {
|
|
429
|
+
error?: string;
|
|
430
|
+
minFiles?: number;
|
|
431
|
+
}) => z.ZodArray<z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodString]>>;
|
|
432
|
+
/**
|
|
433
|
+
* URL validation with i18n messages.
|
|
434
|
+
*/
|
|
435
|
+
url: (options?: {
|
|
436
|
+
required?: string;
|
|
437
|
+
invalid?: string;
|
|
438
|
+
}) => z.ZodString;
|
|
439
|
+
/**
|
|
440
|
+
* Optional URL schema.
|
|
441
|
+
*/
|
|
442
|
+
urlOptional: (options?: {
|
|
443
|
+
invalid?: string;
|
|
444
|
+
}) => z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
|
|
445
|
+
/**
|
|
446
|
+
* Password validation with strength requirements.
|
|
447
|
+
*/
|
|
448
|
+
password: (options?: {
|
|
449
|
+
minLength?: number;
|
|
450
|
+
requireUppercase?: boolean;
|
|
451
|
+
requireLowercase?: boolean;
|
|
452
|
+
requireNumber?: boolean;
|
|
453
|
+
requireSpecial?: boolean;
|
|
454
|
+
}) => z.ZodString;
|
|
455
|
+
/**
|
|
456
|
+
* Nullable input wrapper.
|
|
457
|
+
*/
|
|
458
|
+
nullableInput: <T extends z.ZodTypeAny>(schema: T, options?: {
|
|
459
|
+
error?: string;
|
|
460
|
+
}) => z.ZodNullable<T> & z.ZodType<z.core.output<T> & {}, z.core.input<T> | null, z.core.$ZodTypeInternals<z.core.output<T> & {}, z.core.input<T> | null>>;
|
|
461
|
+
/**
|
|
462
|
+
* Slider range validation.
|
|
463
|
+
*/
|
|
464
|
+
sliderRange: (options: {
|
|
465
|
+
min: number;
|
|
466
|
+
max: number;
|
|
467
|
+
invalid?: string;
|
|
468
|
+
}) => z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
469
|
+
/**
|
|
470
|
+
* Required string with i18n message.
|
|
471
|
+
*/
|
|
472
|
+
required: (options?: {
|
|
473
|
+
error?: string;
|
|
474
|
+
}) => z.ZodString;
|
|
475
|
+
/**
|
|
476
|
+
* Confirmation field helper.
|
|
477
|
+
*/
|
|
478
|
+
confirm: (fieldName: string, error?: string) => {
|
|
479
|
+
message: string;
|
|
480
|
+
path: string[];
|
|
481
|
+
};
|
|
482
|
+
};
|
|
483
|
+
/**
|
|
484
|
+
* Provider props.
|
|
485
|
+
*/
|
|
486
|
+
interface SchemaProviderProps extends SchemaProviderConfig {
|
|
487
|
+
children: ReactNode;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* SchemaProvider - Provides i18n-aware schema validation context.
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```tsx
|
|
494
|
+
* // With i18next
|
|
495
|
+
* import { useTranslation } from 'react-i18next';
|
|
496
|
+
*
|
|
497
|
+
* function App() {
|
|
498
|
+
* const { t, i18n } = useTranslation();
|
|
499
|
+
*
|
|
500
|
+
* return (
|
|
501
|
+
* <SchemaProvider t={t} locale={i18n.language}>
|
|
502
|
+
* <MyForm />
|
|
503
|
+
* </SchemaProvider>
|
|
504
|
+
* );
|
|
505
|
+
* }
|
|
506
|
+
*
|
|
507
|
+
* // In form component
|
|
508
|
+
* function MyForm() {
|
|
509
|
+
* const { schema } = useSchema();
|
|
510
|
+
*
|
|
511
|
+
* const formSchema = z.object({
|
|
512
|
+
* email: schema.email(),
|
|
513
|
+
* password: schema.password(),
|
|
514
|
+
* });
|
|
515
|
+
*
|
|
516
|
+
* // ... form implementation
|
|
517
|
+
* }
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
declare function SchemaProvider({ children, t: providedT, locale, messages }: SchemaProviderProps): react_jsx_runtime.JSX.Element;
|
|
521
|
+
/**
|
|
522
|
+
* Hook to access schema context.
|
|
523
|
+
*
|
|
524
|
+
* @throws Error if used outside SchemaProvider
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```tsx
|
|
528
|
+
* function MyForm() {
|
|
529
|
+
* const { schema, t } = useSchema();
|
|
530
|
+
*
|
|
531
|
+
* const formSchema = z.object({
|
|
532
|
+
* email: schema.email(),
|
|
533
|
+
* name: z.string().min(1, { message: t('validation.required') }),
|
|
534
|
+
* });
|
|
535
|
+
*
|
|
536
|
+
* // ... use formSchema with react-hook-form
|
|
537
|
+
* }
|
|
538
|
+
* ```
|
|
539
|
+
*/
|
|
540
|
+
declare function useSchema(): SchemaContextValue;
|
|
541
|
+
/**
|
|
542
|
+
* Hook to access schema context safely (returns null if not in provider).
|
|
543
|
+
*/
|
|
544
|
+
declare function useSchemaOptional(): SchemaContextValue | null;
|
|
545
|
+
/**
|
|
546
|
+
* Create translated schema utilities without provider.
|
|
547
|
+
* Useful for server-side validation or standalone usage.
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```ts
|
|
551
|
+
* // Server-side validation
|
|
552
|
+
* const t = (key: string) => translations[key] ?? key;
|
|
553
|
+
* const schema = createSchemaUtils(t);
|
|
554
|
+
*
|
|
555
|
+
* const userSchema = z.object({
|
|
556
|
+
* email: schema.email(),
|
|
557
|
+
* });
|
|
558
|
+
* ```
|
|
559
|
+
*/
|
|
560
|
+
declare function createSchemaUtils(t?: TranslateFunction): ReturnType<typeof createTranslatedSchemaUtils>;
|
|
561
|
+
|
|
562
|
+
export { type FileSchemaOptions, type SchemaContextValue, type SchemaErrorMessages, SchemaProvider, type SchemaProviderConfig, type SchemaProviderProps, type SchemaTestResult, type SchemaTranslationKeys, type SliderRangeOptions, type TranslateFunction, createSchemaUtils, schemaUtils, testSchema, testSchemaDebug, useSchema, useSchemaOptional };
|