@uniform-ts/core 0.0.4 → 0.0.5
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 +42 -1118
- package/dist/index.d.mts +465 -319
- package/dist/index.d.ts +465 -319
- package/dist/index.js +220 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +215 -132
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
2
|
import { FieldValues, FieldPath, FieldPathValue, RefCallBack, Control } from 'react-hook-form';
|
|
3
3
|
import * as z from 'zod/v4/core';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -36,12 +36,7 @@ type DeepKeys<T> = T extends object ? {
|
|
|
36
36
|
* // DeepFieldValue<{ name: string; items: { qty: number }[] }, 'items.qty'> → number
|
|
37
37
|
*/
|
|
38
38
|
type DeepFieldValue<T, K extends string> = K extends keyof T ? T[K] : K extends `${infer Head}.${infer Tail}` ? Head extends keyof T ? T[Head] extends (infer Item)[] ? DeepFieldValue<NonNullable<Item>, Tail> : DeepFieldValue<NonNullable<T[Head]>, Tail> : unknown : unknown;
|
|
39
|
-
|
|
40
|
-
* The resolved primitive or structural type of a schema field, as determined
|
|
41
|
-
* by introspecting the Zod schema. Used internally to decide which field
|
|
42
|
-
* component to render.
|
|
43
|
-
*/
|
|
44
|
-
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'select' | 'object' | 'array' | 'union' | 'unknown';
|
|
39
|
+
|
|
45
40
|
/**
|
|
46
41
|
* A single option entry used in `select` / enum fields.
|
|
47
42
|
*/
|
|
@@ -51,18 +46,305 @@ type SelectOption = {
|
|
|
51
46
|
/** The underlying value submitted with the form. */
|
|
52
47
|
value: string | number;
|
|
53
48
|
};
|
|
49
|
+
|
|
54
50
|
/**
|
|
55
|
-
* A
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
51
|
+
* A map of field type keys to React components used to render them.
|
|
52
|
+
* Built-in keys (`string`, `number`, `boolean`, `date`, `select`, `textarea`)
|
|
53
|
+
* are pre-typed. Additional custom keys can be added via the index signature
|
|
54
|
+
* and registered through `createAutoForm` or the `components` prop.
|
|
59
55
|
*/
|
|
60
|
-
type
|
|
56
|
+
type ComponentRegistry = {
|
|
57
|
+
string?: React$1.ComponentType<FieldProps>;
|
|
58
|
+
number?: React$1.ComponentType<FieldProps>;
|
|
59
|
+
boolean?: React$1.ComponentType<FieldProps>;
|
|
60
|
+
date?: React$1.ComponentType<FieldProps>;
|
|
61
|
+
select?: React$1.ComponentType<FieldProps>;
|
|
62
|
+
textarea?: React$1.ComponentType<FieldProps>;
|
|
63
|
+
[key: string]: React$1.ComponentType<FieldProps> | undefined;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Props passed to the field wrapper component that surrounds every rendered
|
|
67
|
+
* field. Used to render the label, description, error message, and grid span.
|
|
68
|
+
*/
|
|
69
|
+
interface FieldWrapperProps {
|
|
70
|
+
/** The field input component to wrap. */
|
|
71
|
+
children: React$1.ReactNode;
|
|
72
|
+
/** The fully resolved field configuration. */
|
|
73
|
+
field: FieldConfig;
|
|
74
|
+
/** Validation error message for the field. */
|
|
75
|
+
error?: string;
|
|
76
|
+
/** Grid column span override (takes precedence over `field.meta.span`). */
|
|
77
|
+
span?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Zero-based render index of this field within its parent container
|
|
80
|
+
* (form root or section). Exposed as the `--field-index` CSS custom property.
|
|
81
|
+
*/
|
|
82
|
+
index?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Nesting depth of this field (0 = top-level, 1 = inside object, etc.).
|
|
85
|
+
* Exposed as the `--field-depth` CSS custom property.
|
|
86
|
+
*/
|
|
87
|
+
depth?: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Props for a generic array action button. Compatible with standard design
|
|
92
|
+
* system button components — pass your own via the `arrayButton` layout slot
|
|
93
|
+
* and it will be used for all array buttons (add, remove, move, duplicate).
|
|
94
|
+
*/
|
|
95
|
+
interface ArrayButtonProps {
|
|
96
|
+
onClick?: React$1.MouseEventHandler<HTMLButtonElement>;
|
|
97
|
+
disabled?: boolean;
|
|
98
|
+
/** Always `"button"` — prevents accidental form submission. */
|
|
99
|
+
type?: 'button' | 'submit' | 'reset';
|
|
100
|
+
/** Accessible label describing the specific action and target row. */
|
|
101
|
+
'aria-label'?: string;
|
|
102
|
+
/** CSS class name forwarded from `classNames.arrayAdd` / `arrayRemove` / etc. */
|
|
103
|
+
className?: string;
|
|
104
|
+
children?: React$1.ReactNode;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Props for the collapse/expand toggle button on an array row.
|
|
108
|
+
* Extends `ArrayButtonProps` with collapse state so custom components
|
|
109
|
+
* can apply directional styling (e.g. rotating a chevron icon).
|
|
110
|
+
*/
|
|
111
|
+
interface ArrayCollapseButtonProps extends ArrayButtonProps {
|
|
112
|
+
/** Whether the row is currently collapsed. */
|
|
113
|
+
isCollapsed: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Props for the component that wraps the entire array field body,
|
|
117
|
+
* controlling the relative position of the rows and the add button.
|
|
118
|
+
*/
|
|
119
|
+
interface ArrayFieldLayoutProps {
|
|
120
|
+
/** The rendered list of array rows. */
|
|
121
|
+
rows: React$1.ReactNode;
|
|
122
|
+
/** The rendered "add row" button. */
|
|
123
|
+
addButton: React$1.ReactNode;
|
|
124
|
+
/** Total number of rows currently in the array. */
|
|
125
|
+
rowCount: number;
|
|
126
|
+
/** Whether adding another row is permitted (respects `maxItems`). */
|
|
127
|
+
canAdd: boolean;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Props passed to the component that renders a single row inside an array field,
|
|
131
|
+
* including the row's content and action buttons (move, duplicate, remove, collapse).
|
|
132
|
+
*/
|
|
133
|
+
interface ArrayRowLayoutProps {
|
|
134
|
+
/** The rendered fields for this array item. */
|
|
135
|
+
children: React$1.ReactNode;
|
|
136
|
+
/** Action button nodes for the row. */
|
|
137
|
+
buttons: {
|
|
138
|
+
/** Button to move the row up, or `null` if already first. */
|
|
139
|
+
moveUp: React$1.ReactNode | null;
|
|
140
|
+
/** Button to move the row down, or `null` if already last. */
|
|
141
|
+
moveDown: React$1.ReactNode | null;
|
|
142
|
+
/** Button to duplicate the row, or `null` if at max items. */
|
|
143
|
+
duplicate: React$1.ReactNode | null;
|
|
144
|
+
/** Button to remove the row. */
|
|
145
|
+
remove: React$1.ReactNode;
|
|
146
|
+
/** Button to collapse/expand the row, or `null` if collapsing is disabled. */
|
|
147
|
+
collapse: React$1.ReactNode | null;
|
|
148
|
+
};
|
|
149
|
+
/** Zero-based index of this row within the array. */
|
|
150
|
+
index: number;
|
|
151
|
+
/** Total number of rows currently in the array. */
|
|
152
|
+
rowCount: number;
|
|
153
|
+
}
|
|
154
|
+
/** Props received by the `layout.formWrapper` component. */
|
|
155
|
+
interface FormWrapperProps {
|
|
156
|
+
children: React$1.ReactNode;
|
|
157
|
+
}
|
|
158
|
+
/** Props received by the `layout.sectionWrapper` component (and per-section `SectionConfig.component`). */
|
|
159
|
+
interface SectionWrapperProps {
|
|
160
|
+
children: React$1.ReactNode;
|
|
161
|
+
title: string;
|
|
162
|
+
className?: string;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Props received by the `layout.objectWrapper` component.
|
|
166
|
+
* Replaces the default `<fieldset>` / `<legend>` wrapper rendered around
|
|
167
|
+
* nested object fields.
|
|
168
|
+
*/
|
|
169
|
+
interface ObjectWrapperProps {
|
|
170
|
+
/** The rendered child fields. */
|
|
171
|
+
children: React$1.ReactNode;
|
|
172
|
+
/** The field label (used as the legend / heading). May be undefined. */
|
|
173
|
+
label: string | undefined;
|
|
174
|
+
/** CSS class name forwarded from `classNames.objectFieldset`. */
|
|
175
|
+
className?: string;
|
|
176
|
+
/** CSS class name forwarded from `classNames.objectLegend` for the label element. */
|
|
177
|
+
labelClassName?: string;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Props received by the `layout.arrayWrapper` component.
|
|
181
|
+
* Replaces the default `<fieldset>` / `<legend>` wrapper rendered around
|
|
182
|
+
* array fields.
|
|
183
|
+
*/
|
|
184
|
+
interface ArrayWrapperProps {
|
|
185
|
+
/** The rendered array field body (rows + add button). */
|
|
186
|
+
children: React$1.ReactNode;
|
|
187
|
+
/** The field label (used as the legend / heading). May be undefined. */
|
|
188
|
+
label: string | undefined;
|
|
189
|
+
/** CSS class name forwarded from `classNames.arrayFieldset`. */
|
|
190
|
+
className?: string;
|
|
191
|
+
/** CSS class name forwarded from `classNames.arrayLegend` for the label element. */
|
|
192
|
+
labelClassName?: string;
|
|
193
|
+
}
|
|
194
|
+
/** Props received by the `layout.submitButton` component. */
|
|
195
|
+
interface SubmitButtonProps {
|
|
196
|
+
isSubmitting: boolean;
|
|
197
|
+
label: string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Per-section styling overrides forwarded to the `sectionWrapper` component.
|
|
201
|
+
* Keys are section titles; values control how that section wrapper is styled.
|
|
202
|
+
*/
|
|
203
|
+
type SectionConfig = {
|
|
204
|
+
/** CSS class name(s) applied to the section wrapper. */
|
|
205
|
+
className?: string;
|
|
206
|
+
/** Replaces the section wrapper component entirely for this section. */
|
|
207
|
+
component?: React$1.ComponentType<SectionWrapperProps>;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Button component overrides for array fields. Set `base` to swap in your
|
|
211
|
+
* design system's button everywhere; use the specific keys to override
|
|
212
|
+
* individual actions on top of that. All keys fall back to `base`, which
|
|
213
|
+
* itself falls back to a plain `<button>`.
|
|
214
|
+
*/
|
|
215
|
+
type ArrayButtonSlots = {
|
|
216
|
+
/** Used for every array button that has no specific override. */
|
|
217
|
+
base?: React$1.ComponentType<ArrayButtonProps>;
|
|
218
|
+
/** Override for the add-row button only. */
|
|
219
|
+
add?: React$1.ComponentType<ArrayButtonProps>;
|
|
220
|
+
/** Override for the remove-row button only. */
|
|
221
|
+
remove?: React$1.ComponentType<ArrayButtonProps>;
|
|
222
|
+
/** Override for the move-up button only. */
|
|
223
|
+
moveUp?: React$1.ComponentType<ArrayButtonProps>;
|
|
224
|
+
/** Override for the move-down button only. */
|
|
225
|
+
moveDown?: React$1.ComponentType<ArrayButtonProps>;
|
|
226
|
+
/** Override for the duplicate-row button only. */
|
|
227
|
+
duplicate?: React$1.ComponentType<ArrayButtonProps>;
|
|
228
|
+
/**
|
|
229
|
+
* Override for the collapse/expand toggle button only.
|
|
230
|
+
* Receives `isCollapsed` in addition to standard `ArrayButtonProps`.
|
|
231
|
+
*/
|
|
232
|
+
collapse?: React$1.ComponentType<ArrayCollapseButtonProps>;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Resolved button slots where every entry is guaranteed to be defined.
|
|
236
|
+
*/
|
|
237
|
+
type ResolvedArrayButtonSlots = {
|
|
238
|
+
base: React$1.ComponentType<ArrayButtonProps>;
|
|
239
|
+
add: React$1.ComponentType<ArrayButtonProps>;
|
|
240
|
+
remove: React$1.ComponentType<ArrayButtonProps>;
|
|
241
|
+
moveUp: React$1.ComponentType<ArrayButtonProps>;
|
|
242
|
+
moveDown: React$1.ComponentType<ArrayButtonProps>;
|
|
243
|
+
duplicate: React$1.ComponentType<ArrayButtonProps>;
|
|
244
|
+
collapse: React$1.ComponentType<ArrayCollapseButtonProps>;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Optional layout slot overrides for top-level structural components of the
|
|
248
|
+
* form. Provide only the slots you want to replace; omitted slots fall back
|
|
249
|
+
* to the built-in defaults.
|
|
250
|
+
*/
|
|
251
|
+
type LayoutSlots = {
|
|
252
|
+
/** Wrapper rendered around the entire form. */
|
|
253
|
+
formWrapper?: React$1.ComponentType<FormWrapperProps>;
|
|
254
|
+
/** Wrapper rendered around each named field section. */
|
|
255
|
+
sectionWrapper?: React$1.ComponentType<SectionWrapperProps>;
|
|
256
|
+
/** Custom submit button component. */
|
|
257
|
+
submitButton?: React$1.ComponentType<SubmitButtonProps>;
|
|
258
|
+
/** Custom layout component for individual rows in array fields. */
|
|
259
|
+
arrayRowLayout?: React$1.ComponentType<ArrayRowLayoutProps>;
|
|
260
|
+
/**
|
|
261
|
+
* Controls the layout of the entire array field body — position the rows
|
|
262
|
+
* and add button relative to each other (e.g. add button above rows).
|
|
263
|
+
*/
|
|
264
|
+
arrayFieldLayout?: React$1.ComponentType<ArrayFieldLayoutProps>;
|
|
265
|
+
/**
|
|
266
|
+
* Replaces the `<fieldset>` / `<legend>` wrapper rendered around nested
|
|
267
|
+
* object fields. Receives `label`, `className`, and `labelClassName` props.
|
|
268
|
+
*/
|
|
269
|
+
objectWrapper?: React$1.ComponentType<ObjectWrapperProps>;
|
|
270
|
+
/**
|
|
271
|
+
* Replaces the `<fieldset>` / `<legend>` wrapper rendered around array
|
|
272
|
+
* fields. Receives `label`, `className`, and `labelClassName` props.
|
|
273
|
+
*/
|
|
274
|
+
arrayWrapper?: React$1.ComponentType<ArrayWrapperProps>;
|
|
275
|
+
/**
|
|
276
|
+
* Button component overrides for array fields. Set `base` to use your
|
|
277
|
+
* design system's button everywhere; use specific keys to override
|
|
278
|
+
* individual actions.
|
|
279
|
+
*/
|
|
280
|
+
arrayButtons?: ArrayButtonSlots;
|
|
281
|
+
/**
|
|
282
|
+
* Content rendered while async `defaultValues` are loading.
|
|
283
|
+
* Defaults to a simple `<p>Loading…</p>` when not provided.
|
|
284
|
+
*/
|
|
285
|
+
loadingFallback?: React$1.ReactNode;
|
|
286
|
+
/**
|
|
287
|
+
* Per-section config keyed by section title.
|
|
288
|
+
* Forwarded to the `sectionWrapper` component as a `className` prop.
|
|
289
|
+
*/
|
|
290
|
+
sections?: Record<string, SectionConfig>;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* The resolved version of `LayoutSlots` used internally, where all slots are
|
|
294
|
+
* guaranteed to be defined (falling back to built-in defaults).
|
|
295
|
+
*/
|
|
296
|
+
type ResolvedLayoutSlots = {
|
|
297
|
+
formWrapper: React$1.ComponentType<FormWrapperProps>;
|
|
298
|
+
sectionWrapper: React$1.ComponentType<SectionWrapperProps>;
|
|
299
|
+
submitButton: React$1.ComponentType<SubmitButtonProps>;
|
|
300
|
+
arrayRowLayout: React$1.ComponentType<ArrayRowLayoutProps>;
|
|
301
|
+
arrayFieldLayout: React$1.ComponentType<ArrayFieldLayoutProps>;
|
|
302
|
+
objectWrapper: React$1.ComponentType<ObjectWrapperProps>;
|
|
303
|
+
arrayWrapper: React$1.ComponentType<ArrayWrapperProps>;
|
|
304
|
+
arrayButtons: ResolvedArrayButtonSlots;
|
|
305
|
+
loadingFallback: React$1.ReactNode;
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* CSS class name overrides for the various structural elements of the form.
|
|
309
|
+
* Only the keys you provide will be applied; omitted keys use the built-in
|
|
310
|
+
* default class names (or none, if the default components don't apply any).
|
|
311
|
+
*/
|
|
312
|
+
type FormClassNames = {
|
|
313
|
+
/** Class applied to the `<form>` element. */
|
|
314
|
+
form?: string;
|
|
315
|
+
/** Class applied to each field wrapper. */
|
|
316
|
+
fieldWrapper?: string;
|
|
317
|
+
/** Class applied to each field label. */
|
|
318
|
+
label?: string;
|
|
319
|
+
/** Class applied to each field description. */
|
|
320
|
+
description?: string;
|
|
321
|
+
/** Class applied to each field error message. */
|
|
322
|
+
error?: string;
|
|
323
|
+
/** Class applied to the "add item" button in array fields. */
|
|
324
|
+
arrayAdd?: string;
|
|
325
|
+
/** Class applied to the "remove item" button in array fields. */
|
|
326
|
+
arrayRemove?: string;
|
|
327
|
+
/** Class applied to the "move item" buttons in array fields. */
|
|
328
|
+
arrayMove?: string;
|
|
329
|
+
/** Class applied to the "duplicate item" button in array fields. */
|
|
330
|
+
arrayDuplicate?: string;
|
|
331
|
+
/** Class applied to the "collapse item" button in array fields. */
|
|
332
|
+
arrayCollapse?: string;
|
|
333
|
+
/** Class applied to the `<fieldset>` wrapper around nested object fields. */
|
|
334
|
+
objectFieldset?: string;
|
|
335
|
+
/** Class applied to the `<legend>` label inside nested object fields. */
|
|
336
|
+
objectLegend?: string;
|
|
337
|
+
/** Class applied to the `<fieldset>` wrapper around array fields. */
|
|
338
|
+
arrayFieldset?: string;
|
|
339
|
+
/** Class applied to the `<legend>` label inside array fields. */
|
|
340
|
+
arrayLegend?: string;
|
|
341
|
+
};
|
|
342
|
+
|
|
61
343
|
/**
|
|
62
344
|
* All programmatic form control methods, shared by both the field `onChange`
|
|
63
345
|
* callback and the imperative ref handle.
|
|
64
346
|
*
|
|
65
|
-
* @template
|
|
347
|
+
* @template TValues - The inferred shape of the form values.
|
|
66
348
|
*/
|
|
67
349
|
type FormMethods<TValues extends FieldValues = FieldValues> = {
|
|
68
350
|
/** Set a single field value programmatically */
|
|
@@ -85,12 +367,148 @@ type FormMethods<TValues extends FieldValues = FieldValues> = {
|
|
|
85
367
|
submit: () => void;
|
|
86
368
|
/** Focus a specific field by name (dot-notated for nested fields) */
|
|
87
369
|
focus: (fieldName: FieldPath<TValues>) => void;
|
|
88
|
-
/**
|
|
370
|
+
/** Watch field values reactively */
|
|
89
371
|
watch: {
|
|
90
372
|
(): TValues;
|
|
91
373
|
<K extends FieldPath<TValues>>(name: K): FieldPathValue<TValues, K>;
|
|
92
374
|
};
|
|
93
375
|
};
|
|
376
|
+
type FormLabels = {
|
|
377
|
+
/** Submit button text — default: "Submit" */
|
|
378
|
+
submit?: string;
|
|
379
|
+
/** Array "Add item" button — default: "Add" */
|
|
380
|
+
arrayAdd?: string;
|
|
381
|
+
/** Array "Remove row" button — default: "Remove" */
|
|
382
|
+
arrayRemove?: string;
|
|
383
|
+
/** Array "Move row up" button — default: "↑" */
|
|
384
|
+
arrayMoveUp?: string;
|
|
385
|
+
/** Array "Move row down" button — default: "↓" */
|
|
386
|
+
arrayMoveDown?: string;
|
|
387
|
+
/** Array "Duplicate row" button — default: "Duplicate" */
|
|
388
|
+
arrayDuplicate?: string;
|
|
389
|
+
/** Array row toggle shown when the row is expanded (clicking collapses it) — default: "▼" */
|
|
390
|
+
arrayCollapse?: string;
|
|
391
|
+
/** Array row toggle shown when the row is collapsed (clicking expands it) — default: "▶" */
|
|
392
|
+
arrayExpand?: string;
|
|
393
|
+
};
|
|
394
|
+
/**
|
|
395
|
+
* A map of field names to coercion functions. Each function receives the raw
|
|
396
|
+
* field value and returns the coerced value before Zod validation is applied.
|
|
397
|
+
* Useful for transforming string inputs (e.g. from native `<input>`) into the
|
|
398
|
+
* types expected by the schema (e.g. numbers, dates).
|
|
399
|
+
*/
|
|
400
|
+
type CoercionMap$1 = Record<string, (value: unknown) => unknown>;
|
|
401
|
+
/**
|
|
402
|
+
* Custom validation error message overrides. Use `required` to override the
|
|
403
|
+
* global "required field" message, or provide a field name key to override
|
|
404
|
+
* messages for a specific field (supports nested dot-notated paths).
|
|
405
|
+
*/
|
|
406
|
+
type ValidationMessages = {
|
|
407
|
+
required?: string;
|
|
408
|
+
[fieldName: string]: string | Record<string, string> | undefined;
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* A minimal storage adapter interface compatible with `localStorage` and
|
|
412
|
+
* `sessionStorage`. Provide a custom implementation to persist form values
|
|
413
|
+
* to any backing store (e.g. IndexedDB, AsyncStorage).
|
|
414
|
+
*/
|
|
415
|
+
type PersistStorage = {
|
|
416
|
+
getItem: (key: string) => string | null;
|
|
417
|
+
setItem: (key: string, value: string) => void;
|
|
418
|
+
removeItem: (key: string) => void;
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* The imperative handle exposed via `ref` on `<AutoForm>`. Provides methods
|
|
422
|
+
* to programmatically control the form from a parent component.
|
|
423
|
+
*
|
|
424
|
+
* @template TSchema - The Zod object schema that defines the form shape.
|
|
425
|
+
*/
|
|
426
|
+
type AutoFormHandle<TSchema extends z.$ZodObject = z.$ZodObject> = FormMethods<z.infer<TSchema>>;
|
|
427
|
+
/**
|
|
428
|
+
* Static configuration provided to `createAutoForm`. These options become the
|
|
429
|
+
* default for every form instance created by the factory, and can be
|
|
430
|
+
* overridden per-instance via the corresponding `<AutoForm>` props.
|
|
431
|
+
*/
|
|
432
|
+
type AutoFormConfig = {
|
|
433
|
+
/** Default component registry for all form instances. */
|
|
434
|
+
components?: ComponentRegistry;
|
|
435
|
+
/** Default field wrapper component for all form instances. */
|
|
436
|
+
fieldWrapper?: React.ComponentType<FieldWrapperProps>;
|
|
437
|
+
/** Default layout slot overrides for all form instances. */
|
|
438
|
+
layout?: LayoutSlots;
|
|
439
|
+
/** Default CSS class name overrides for all form instances. */
|
|
440
|
+
classNames?: FormClassNames;
|
|
441
|
+
/** When `true`, all fields in every form instance are disabled by default. */
|
|
442
|
+
disabled?: boolean;
|
|
443
|
+
/** Default coercion map applied to all form instances. */
|
|
444
|
+
coercions?: CoercionMap$1;
|
|
445
|
+
/** Default validation message overrides for all form instances. */
|
|
446
|
+
messages?: ValidationMessages;
|
|
447
|
+
/** Default label strings; overridden per-instance by the `labels` prop */
|
|
448
|
+
labels?: FormLabels;
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* Props for the `<AutoForm>` component. Drives schema introspection, field
|
|
452
|
+
* rendering, validation, and submission.
|
|
453
|
+
*
|
|
454
|
+
* @template TSchema - A `ZodObject` schema that defines the form shape.
|
|
455
|
+
*/
|
|
456
|
+
type AutoFormProps<TSchema extends z.$ZodObject> = {
|
|
457
|
+
/** A UniForm instance carrying the schema and typed onChange handlers. */
|
|
458
|
+
form: {
|
|
459
|
+
readonly schema: TSchema;
|
|
460
|
+
};
|
|
461
|
+
/** Called with the validated form values when the form is submitted successfully. */
|
|
462
|
+
onSubmit: (values: z.infer<TSchema>) => void | Promise<void>;
|
|
463
|
+
/**
|
|
464
|
+
* Initial values to pre-populate the form with.
|
|
465
|
+
* When an async function is provided, the form shows `loadingFallback` until the
|
|
466
|
+
* promise resolves, then resets the form with the loaded values.
|
|
467
|
+
*/
|
|
468
|
+
defaultValues?: Partial<z.infer<TSchema>> | (() => Promise<Partial<z.infer<TSchema>>>);
|
|
469
|
+
/** Component registry overrides for this form instance. */
|
|
470
|
+
components?: ComponentRegistry;
|
|
471
|
+
/** Per-field UI metadata overrides (label, placeholder, options, etc.). */
|
|
472
|
+
fields?: {
|
|
473
|
+
[K in DeepKeys<z.infer<TSchema>>]?: FieldOverride<TSchema, DeepFieldValue<z.infer<TSchema>, K>>;
|
|
474
|
+
};
|
|
475
|
+
/** Field wrapper component override for this form instance. */
|
|
476
|
+
fieldWrapper?: React.ComponentType<FieldWrapperProps>;
|
|
477
|
+
/** Layout slot overrides for this form instance. */
|
|
478
|
+
layout?: LayoutSlots;
|
|
479
|
+
/** CSS class name overrides for this form instance. */
|
|
480
|
+
classNames?: FormClassNames;
|
|
481
|
+
/** When `true`, all fields are rendered in a disabled (non-interactive) state. */
|
|
482
|
+
disabled?: boolean;
|
|
483
|
+
/** Coercion map applied before Zod validation for this form instance. */
|
|
484
|
+
coercions?: CoercionMap$1;
|
|
485
|
+
/** Validation message overrides for this form instance. */
|
|
486
|
+
messages?: ValidationMessages;
|
|
487
|
+
/** When set, form values are auto-saved to storage under this key */
|
|
488
|
+
persistKey?: string;
|
|
489
|
+
/** Debounce interval in ms for persistence writes (default: 300) */
|
|
490
|
+
persistDebounce?: number;
|
|
491
|
+
/** Custom storage adapter (default: localStorage) */
|
|
492
|
+
persistStorage?: PersistStorage;
|
|
493
|
+
/** Called on every value change with the current form values */
|
|
494
|
+
onValuesChange?: (values: z.infer<TSchema>) => void;
|
|
495
|
+
/** Customize hard-coded UI text (submit button, array buttons, etc.) */
|
|
496
|
+
labels?: FormLabels;
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* The resolved primitive or structural type of a schema field, as determined
|
|
501
|
+
* by introspecting the Zod schema. Used internally to decide which field
|
|
502
|
+
* component to render.
|
|
503
|
+
*/
|
|
504
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'select' | 'object' | 'array' | 'union' | 'unknown';
|
|
505
|
+
/**
|
|
506
|
+
* A predicate function that receives the current form values and returns
|
|
507
|
+
* `true` when the field should be visible, `false` when it should be hidden.
|
|
508
|
+
*
|
|
509
|
+
* @template TValues - The shape of the form values object.
|
|
510
|
+
*/
|
|
511
|
+
type FieldCondition<TValues = Record<string, unknown>> = (values: TValues) => boolean;
|
|
94
512
|
/**
|
|
95
513
|
* Dynamic field property overrides passed to `ctx.setFieldMeta()` inside a
|
|
96
514
|
* UniForm onChange handler. Each key is optional — only the properties you
|
|
@@ -147,11 +565,14 @@ type FieldMetaBase = {
|
|
|
147
565
|
* - **React component** — a `FieldProps`-compatible component passed inline,
|
|
148
566
|
* bypassing the registry entirely (e.g. `component: MyCustomInput`).
|
|
149
567
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
568
|
+
* Uses `React.ComponentType<never>` as the type parameter rather than
|
|
569
|
+
* `React.ComponentType<FieldProps>` to avoid both a circular inference error
|
|
570
|
+
* (FieldProps → FieldMeta → component → FieldProps) and a contravariance
|
|
571
|
+
* error when components typed as `(props: FieldProps) => JSX.Element` are
|
|
572
|
+
* assigned via Zod's `.meta()`, whose return type widens `meta` to `any`.
|
|
573
|
+
* `ComponentType<never>` is the widest possible assignable supertype.
|
|
153
574
|
*/
|
|
154
|
-
component?: string | React.ComponentType<any>;
|
|
575
|
+
component?: string | React$1.ComponentType<any>;
|
|
155
576
|
/** Called when this field's value changes. Receives the new value and form control methods. May be async. */
|
|
156
577
|
onChange?: (value: unknown, form: FormMethods) => void | Promise<void>;
|
|
157
578
|
/** When `true`, rows in an array field can be reordered via move-up/move-down buttons. */
|
|
@@ -160,6 +581,14 @@ type FieldMetaBase = {
|
|
|
160
581
|
duplicable?: boolean;
|
|
161
582
|
/** When `true`, rows in an array field can be individually collapsed. */
|
|
162
583
|
collapsible?: boolean;
|
|
584
|
+
/**
|
|
585
|
+
* Override the wrapper component rendered around this specific object or array field.
|
|
586
|
+
* Takes precedence over the global `layout.objectWrapper` / `layout.arrayWrapper` slots.
|
|
587
|
+
*
|
|
588
|
+
* The component receives the same `ObjectWrapperProps` / `ArrayWrapperProps` as the
|
|
589
|
+
* global slot — `children`, `label`, `className`, and `labelClassName`.
|
|
590
|
+
*/
|
|
591
|
+
wrapper?: React$1.ComponentType<ObjectWrapperProps | ArrayWrapperProps>;
|
|
163
592
|
};
|
|
164
593
|
/**
|
|
165
594
|
* Per-field UI metadata with an open index signature, allowing arbitrary
|
|
@@ -188,17 +617,6 @@ type FieldConfigBase = {
|
|
|
188
617
|
* This is a general escape hatch for custom components that need to inspect
|
|
189
618
|
* the raw schema — for example, to read union variants, access custom Zod
|
|
190
619
|
* metadata not captured by introspection, or build schema-aware validation UI.
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* function MyUnionInput({ field }: FieldProps) {
|
|
194
|
-
* // Inspect the original schema for any edge case
|
|
195
|
-
* const schema = field.schema
|
|
196
|
-
* if (schema._zod.def.type === 'union') {
|
|
197
|
-
* const variants = (schema._zod.def as z.$ZodUnionDef).options
|
|
198
|
-
* // render a type-switcher using the raw Zod variants
|
|
199
|
-
* }
|
|
200
|
-
* return <input ... />
|
|
201
|
-
* }
|
|
202
620
|
*/
|
|
203
621
|
schema: z.$ZodType;
|
|
204
622
|
};
|
|
@@ -249,7 +667,7 @@ type FieldConfig = FieldConfigBase & ({
|
|
|
249
667
|
* value, change/blur handlers, and all resolved UI metadata needed to render
|
|
250
668
|
* a single field.
|
|
251
669
|
*/
|
|
252
|
-
|
|
670
|
+
interface FieldProps {
|
|
253
671
|
/** Dot-notated field path (e.g. `"address.street"`). */
|
|
254
672
|
name: string;
|
|
255
673
|
/** The current field value. */
|
|
@@ -282,166 +700,7 @@ type FieldProps = {
|
|
|
282
700
|
* exposes — e.g. inspecting union variants, accessing custom Zod refinements, etc.
|
|
283
701
|
*/
|
|
284
702
|
schema: z.$ZodType;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* A map of field type keys to React components used to render them.
|
|
288
|
-
* Built-in keys (`string`, `number`, `boolean`, `date`, `select`, `textarea`)
|
|
289
|
-
* are pre-typed. Additional custom keys can be added via the index signature
|
|
290
|
-
* and registered through `createAutoForm` or the `components` prop.
|
|
291
|
-
*/
|
|
292
|
-
type ComponentRegistry = {
|
|
293
|
-
string?: React.ComponentType<FieldProps>;
|
|
294
|
-
number?: React.ComponentType<FieldProps>;
|
|
295
|
-
boolean?: React.ComponentType<FieldProps>;
|
|
296
|
-
date?: React.ComponentType<FieldProps>;
|
|
297
|
-
select?: React.ComponentType<FieldProps>;
|
|
298
|
-
textarea?: React.ComponentType<FieldProps>;
|
|
299
|
-
[key: string]: React.ComponentType<FieldProps> | undefined;
|
|
300
|
-
};
|
|
301
|
-
/**
|
|
302
|
-
* Props passed to the field wrapper component that surrounds every rendered
|
|
303
|
-
* field. Used to render the label, description, error message, and grid span.
|
|
304
|
-
*/
|
|
305
|
-
type FieldWrapperProps = {
|
|
306
|
-
/** The field input component to wrap. */
|
|
307
|
-
children: React.ReactNode;
|
|
308
|
-
/** The fully resolved field configuration. */
|
|
309
|
-
field: FieldConfig;
|
|
310
|
-
/** Validation error message for the field. */
|
|
311
|
-
error?: string;
|
|
312
|
-
/** Grid column span override (takes precedence over `field.meta.span`). */
|
|
313
|
-
span?: number;
|
|
314
|
-
/**
|
|
315
|
-
* Zero-based render index of this field within its parent container
|
|
316
|
-
* (form root or section). Exposed as the `--field-index` CSS custom property.
|
|
317
|
-
*/
|
|
318
|
-
index?: number;
|
|
319
|
-
/**
|
|
320
|
-
* Nesting depth of this field (0 = top-level, 1 = inside object, etc.).
|
|
321
|
-
* Exposed as the `--field-depth` CSS custom property.
|
|
322
|
-
*/
|
|
323
|
-
depth?: number;
|
|
324
|
-
};
|
|
325
|
-
/**
|
|
326
|
-
* Props passed to the component that renders a single row inside an array field,
|
|
327
|
-
* including the row's content and action buttons (move, duplicate, remove, collapse).
|
|
328
|
-
*/
|
|
329
|
-
type ArrayRowLayoutProps = {
|
|
330
|
-
/** The rendered fields for this array item. */
|
|
331
|
-
children: React.ReactNode;
|
|
332
|
-
/** Action button nodes for the row. */
|
|
333
|
-
buttons: {
|
|
334
|
-
/** Button to move the row up, or `null` if already first. */
|
|
335
|
-
moveUp: React.ReactNode | null;
|
|
336
|
-
/** Button to move the row down, or `null` if already last. */
|
|
337
|
-
moveDown: React.ReactNode | null;
|
|
338
|
-
/** Button to duplicate the row, or `null` if at max items. */
|
|
339
|
-
duplicate: React.ReactNode | null;
|
|
340
|
-
/** Button to remove the row. */
|
|
341
|
-
remove: React.ReactNode;
|
|
342
|
-
/** Button to collapse/expand the row, or `null` if collapsing is disabled. */
|
|
343
|
-
collapse: React.ReactNode | null;
|
|
344
|
-
};
|
|
345
|
-
/** Zero-based index of this row within the array. */
|
|
346
|
-
index: number;
|
|
347
|
-
/** Total number of rows currently in the array. */
|
|
348
|
-
rowCount: number;
|
|
349
|
-
};
|
|
350
|
-
/**
|
|
351
|
-
* Per-section styling overrides forwarded to the `sectionWrapper` component.
|
|
352
|
-
* Keys are section titles; values control how that section wrapper is styled.
|
|
353
|
-
*/
|
|
354
|
-
type SectionConfig = {
|
|
355
|
-
/** CSS class name(s) applied to the section wrapper. */
|
|
356
|
-
className?: string;
|
|
357
|
-
/** Replaces the section wrapper component entirely for this section. */
|
|
358
|
-
component?: React.ComponentType<{
|
|
359
|
-
children: React.ReactNode;
|
|
360
|
-
title: string;
|
|
361
|
-
className?: string;
|
|
362
|
-
}>;
|
|
363
|
-
};
|
|
364
|
-
/**
|
|
365
|
-
* Optional layout slot overrides for top-level structural components of the
|
|
366
|
-
* form. Provide only the slots you want to replace; omitted slots fall back
|
|
367
|
-
* to the built-in defaults.
|
|
368
|
-
*/
|
|
369
|
-
type LayoutSlots = {
|
|
370
|
-
/** Wrapper rendered around the entire form. */
|
|
371
|
-
formWrapper?: React.ComponentType<{
|
|
372
|
-
children: React.ReactNode;
|
|
373
|
-
}>;
|
|
374
|
-
/** Wrapper rendered around each named field section. */
|
|
375
|
-
sectionWrapper?: React.ComponentType<{
|
|
376
|
-
children: React.ReactNode;
|
|
377
|
-
title: string;
|
|
378
|
-
className?: string;
|
|
379
|
-
}>;
|
|
380
|
-
/** Custom submit button component. */
|
|
381
|
-
submitButton?: React.ComponentType<{
|
|
382
|
-
isSubmitting: boolean;
|
|
383
|
-
label: string;
|
|
384
|
-
}>;
|
|
385
|
-
/** Custom layout component for individual rows in array fields. */
|
|
386
|
-
arrayRowLayout?: React.ComponentType<ArrayRowLayoutProps>;
|
|
387
|
-
/**
|
|
388
|
-
* Content rendered while async `defaultValues` are loading.
|
|
389
|
-
* Defaults to a simple `<p>Loading…</p>` when not provided.
|
|
390
|
-
*/
|
|
391
|
-
loadingFallback?: React.ReactNode;
|
|
392
|
-
/**
|
|
393
|
-
* Per-section config keyed by section title.
|
|
394
|
-
* Forwarded to the `sectionWrapper` component as a `className` prop.
|
|
395
|
-
*/
|
|
396
|
-
sections?: Record<string, SectionConfig>;
|
|
397
|
-
};
|
|
398
|
-
/**
|
|
399
|
-
* The resolved version of `LayoutSlots` used internally, where all slots are
|
|
400
|
-
* guaranteed to be defined (falling back to built-in defaults).
|
|
401
|
-
*/
|
|
402
|
-
type ResolvedLayoutSlots = {
|
|
403
|
-
formWrapper: React.ComponentType<{
|
|
404
|
-
children: React.ReactNode;
|
|
405
|
-
}>;
|
|
406
|
-
sectionWrapper: React.ComponentType<{
|
|
407
|
-
children: React.ReactNode;
|
|
408
|
-
title: string;
|
|
409
|
-
className?: string;
|
|
410
|
-
}>;
|
|
411
|
-
submitButton: React.ComponentType<{
|
|
412
|
-
isSubmitting: boolean;
|
|
413
|
-
label: string;
|
|
414
|
-
}>;
|
|
415
|
-
arrayRowLayout: React.ComponentType<ArrayRowLayoutProps>;
|
|
416
|
-
loadingFallback: React.ReactNode;
|
|
417
|
-
};
|
|
418
|
-
/**
|
|
419
|
-
* CSS class name overrides for the various structural elements of the form.
|
|
420
|
-
* Only the keys you provide will be applied; omitted keys use the built-in
|
|
421
|
-
* default class names (or none, if the default components don't apply any).
|
|
422
|
-
*/
|
|
423
|
-
type FormClassNames = {
|
|
424
|
-
/** Class applied to the `<form>` element. */
|
|
425
|
-
form?: string;
|
|
426
|
-
/** Class applied to each field wrapper. */
|
|
427
|
-
fieldWrapper?: string;
|
|
428
|
-
/** Class applied to each field label. */
|
|
429
|
-
label?: string;
|
|
430
|
-
/** Class applied to each field description. */
|
|
431
|
-
description?: string;
|
|
432
|
-
/** Class applied to each field error message. */
|
|
433
|
-
error?: string;
|
|
434
|
-
/** Class applied to the "add item" button in array fields. */
|
|
435
|
-
arrayAdd?: string;
|
|
436
|
-
/** Class applied to the "remove item" button in array fields. */
|
|
437
|
-
arrayRemove?: string;
|
|
438
|
-
/** Class applied to the "move item" buttons in array fields. */
|
|
439
|
-
arrayMove?: string;
|
|
440
|
-
/** Class applied to the "duplicate item" button in array fields. */
|
|
441
|
-
arrayDuplicate?: string;
|
|
442
|
-
/** Class applied to the "collapse item" button in array fields. */
|
|
443
|
-
arrayCollapse?: string;
|
|
444
|
-
};
|
|
703
|
+
}
|
|
445
704
|
/**
|
|
446
705
|
* A per-field override entry used in the AutoFormProps `fields` prop.
|
|
447
706
|
* The `onChange` callback is typed to the specific schema's inferred value
|
|
@@ -454,131 +713,6 @@ type FieldOverride<TSchema extends z.$ZodObject = z.$ZodObject, TValue = unknown
|
|
|
454
713
|
onChange?: (value: TValue, form: FormMethods<z.infer<TSchema>>) => void | Promise<void>;
|
|
455
714
|
[key: string]: unknown;
|
|
456
715
|
};
|
|
457
|
-
type FormLabels = {
|
|
458
|
-
/** Submit button text — default: "Submit" */
|
|
459
|
-
submit?: string;
|
|
460
|
-
/** Array "Add item" button — default: "Add" */
|
|
461
|
-
arrayAdd?: string;
|
|
462
|
-
/** Array "Remove row" button — default: "Remove" */
|
|
463
|
-
arrayRemove?: string;
|
|
464
|
-
/** Array "Move row up" button — default: "↑" */
|
|
465
|
-
arrayMoveUp?: string;
|
|
466
|
-
/** Array "Move row down" button — default: "↓" */
|
|
467
|
-
arrayMoveDown?: string;
|
|
468
|
-
/** Array "Duplicate row" button — default: "Duplicate" */
|
|
469
|
-
arrayDuplicate?: string;
|
|
470
|
-
/** Array row toggle shown when the row is expanded (clicking collapses it) — default: "▼" */
|
|
471
|
-
arrayCollapse?: string;
|
|
472
|
-
/** Array row toggle shown when the row is collapsed (clicking expands it) — default: "▶" */
|
|
473
|
-
arrayExpand?: string;
|
|
474
|
-
};
|
|
475
|
-
/**
|
|
476
|
-
* A map of field names to coercion functions. Each function receives the raw
|
|
477
|
-
* field value and returns the coerced value before Zod validation is applied.
|
|
478
|
-
* Useful for transforming string inputs (e.g. from native `<input>`) into the
|
|
479
|
-
* types expected by the schema (e.g. numbers, dates).
|
|
480
|
-
*/
|
|
481
|
-
type CoercionMap$1 = Record<string, (value: unknown) => unknown>;
|
|
482
|
-
/**
|
|
483
|
-
* Custom validation error message overrides. Use `required` to override the
|
|
484
|
-
* global "required field" message, or provide a field name key to override
|
|
485
|
-
* messages for a specific field (supports nested dot-notated paths).
|
|
486
|
-
*/
|
|
487
|
-
type ValidationMessages = {
|
|
488
|
-
required?: string;
|
|
489
|
-
[fieldName: string]: string | Record<string, string> | undefined;
|
|
490
|
-
};
|
|
491
|
-
/**
|
|
492
|
-
* A minimal storage adapter interface compatible with `localStorage` and
|
|
493
|
-
* `sessionStorage`. Provide a custom implementation to persist form values
|
|
494
|
-
* to any backing store (e.g. IndexedDB, AsyncStorage).
|
|
495
|
-
*/
|
|
496
|
-
type PersistStorage = {
|
|
497
|
-
getItem: (key: string) => string | null;
|
|
498
|
-
setItem: (key: string, value: string) => void;
|
|
499
|
-
removeItem: (key: string) => void;
|
|
500
|
-
};
|
|
501
|
-
/**
|
|
502
|
-
* The imperative handle exposed via `ref` on `<AutoForm>`. Provides methods
|
|
503
|
-
* to programmatically control the form from a parent component.
|
|
504
|
-
*
|
|
505
|
-
* @template TSchema - The Zod object schema that defines the form shape.
|
|
506
|
-
*/
|
|
507
|
-
type AutoFormHandle<TSchema extends z.$ZodObject = z.$ZodObject> = FormMethods<z.infer<TSchema>> & {
|
|
508
|
-
/** `true` while an async `onSubmit` handler is in flight. */
|
|
509
|
-
isSubmitting: boolean;
|
|
510
|
-
};
|
|
511
|
-
/**
|
|
512
|
-
* Static configuration provided to `createAutoForm`. These options become the
|
|
513
|
-
* default for every form instance created by the factory, and can be
|
|
514
|
-
* overridden per-instance via the corresponding `<AutoForm>` props.
|
|
515
|
-
*/
|
|
516
|
-
type AutoFormConfig = {
|
|
517
|
-
/** Default component registry for all form instances. */
|
|
518
|
-
components?: ComponentRegistry;
|
|
519
|
-
/** Default field wrapper component for all form instances. */
|
|
520
|
-
fieldWrapper?: React.ComponentType<FieldWrapperProps>;
|
|
521
|
-
/** Default layout slot overrides for all form instances. */
|
|
522
|
-
layout?: LayoutSlots;
|
|
523
|
-
/** Default CSS class name overrides for all form instances. */
|
|
524
|
-
classNames?: FormClassNames;
|
|
525
|
-
/** When `true`, all fields in every form instance are disabled by default. */
|
|
526
|
-
disabled?: boolean;
|
|
527
|
-
/** Default coercion map applied to all form instances. */
|
|
528
|
-
coercions?: CoercionMap$1;
|
|
529
|
-
/** Default validation message overrides for all form instances. */
|
|
530
|
-
messages?: ValidationMessages;
|
|
531
|
-
/** Default label strings; overridden per-instance by the `labels` prop */
|
|
532
|
-
labels?: FormLabels;
|
|
533
|
-
};
|
|
534
|
-
/**
|
|
535
|
-
* Props for the `<AutoForm>` component. Drives schema introspection, field
|
|
536
|
-
* rendering, validation, and submission.
|
|
537
|
-
*
|
|
538
|
-
* @template TSchema - The Zod object schema that defines the form shape.
|
|
539
|
-
*/
|
|
540
|
-
type AutoFormProps<TSchema extends z.$ZodObject> = {
|
|
541
|
-
/** A UniForm instance carrying the schema and typed onChange handlers. */
|
|
542
|
-
form: {
|
|
543
|
-
readonly schema: TSchema;
|
|
544
|
-
};
|
|
545
|
-
/** Called with the validated form values when the form is submitted successfully. */
|
|
546
|
-
onSubmit: (values: z.infer<TSchema>) => void | Promise<void>;
|
|
547
|
-
/**
|
|
548
|
-
* Initial values to pre-populate the form with.
|
|
549
|
-
* When an async function is provided, the form shows `loadingFallback` until the
|
|
550
|
-
* promise resolves, then resets the form with the loaded values.
|
|
551
|
-
*/
|
|
552
|
-
defaultValues?: Partial<z.infer<TSchema>> | (() => Promise<Partial<z.infer<TSchema>>>);
|
|
553
|
-
/** Component registry overrides for this form instance. */
|
|
554
|
-
components?: ComponentRegistry;
|
|
555
|
-
/** Per-field UI metadata overrides (label, placeholder, options, etc.). */
|
|
556
|
-
fields?: {
|
|
557
|
-
[K in DeepKeys<z.infer<TSchema>>]?: FieldOverride<TSchema, DeepFieldValue<z.infer<TSchema>, K>>;
|
|
558
|
-
};
|
|
559
|
-
/** Field wrapper component override for this form instance. */
|
|
560
|
-
fieldWrapper?: React.ComponentType<FieldWrapperProps>;
|
|
561
|
-
/** Layout slot overrides for this form instance. */
|
|
562
|
-
layout?: LayoutSlots;
|
|
563
|
-
/** CSS class name overrides for this form instance. */
|
|
564
|
-
classNames?: FormClassNames;
|
|
565
|
-
/** When `true`, all fields are rendered in a disabled (non-interactive) state. */
|
|
566
|
-
disabled?: boolean;
|
|
567
|
-
/** Coercion map applied before Zod validation for this form instance. */
|
|
568
|
-
coercions?: CoercionMap$1;
|
|
569
|
-
/** Validation message overrides for this form instance. */
|
|
570
|
-
messages?: ValidationMessages;
|
|
571
|
-
/** When set, form values are auto-saved to storage under this key */
|
|
572
|
-
persistKey?: string;
|
|
573
|
-
/** Debounce interval in ms for persistence writes (default: 300) */
|
|
574
|
-
persistDebounce?: number;
|
|
575
|
-
/** Custom storage adapter (default: localStorage) */
|
|
576
|
-
persistStorage?: PersistStorage;
|
|
577
|
-
/** Called on every value change with the current form values */
|
|
578
|
-
onValuesChange?: (values: z.infer<TSchema>) => void;
|
|
579
|
-
/** Customize hard-coded UI text (submit button, array buttons, etc.) */
|
|
580
|
-
labels?: FormLabels;
|
|
581
|
-
};
|
|
582
716
|
|
|
583
717
|
// zod@3.25+ — import from 'zod/v4'
|
|
584
718
|
declare module 'zod/v4/core' {
|
|
@@ -633,7 +767,7 @@ declare function introspectObjectSchema(schema: z.$ZodObject): FieldConfig[];
|
|
|
633
767
|
* <AutoForm form={myForm} onSubmit={(values) => console.log(values)} />
|
|
634
768
|
*/
|
|
635
769
|
declare function AutoForm<TSchema extends z.$ZodObject>(props: AutoFormProps<TSchema> & {
|
|
636
|
-
ref?: React.Ref<AutoFormHandle<TSchema>>;
|
|
770
|
+
ref?: React$1.Ref<AutoFormHandle<TSchema>>;
|
|
637
771
|
}): react_jsx_runtime.JSX.Element;
|
|
638
772
|
|
|
639
773
|
type FieldRendererProps = {
|
|
@@ -669,6 +803,18 @@ type DefaultSubmitButtonProps = {
|
|
|
669
803
|
};
|
|
670
804
|
declare function DefaultSubmitButton({ isSubmitting, }: DefaultSubmitButtonProps): react_jsx_runtime.JSX.Element;
|
|
671
805
|
|
|
806
|
+
declare function DefaultArrayButton(props: ArrayButtonProps): react_jsx_runtime.JSX.Element;
|
|
807
|
+
|
|
808
|
+
declare function DefaultArrayCollapseButton({ isCollapsed: _isCollapsed, ...props }: ArrayCollapseButtonProps): react_jsx_runtime.JSX.Element;
|
|
809
|
+
|
|
810
|
+
declare function DefaultArrayFieldLayout({ rows, addButton, }: ArrayFieldLayoutProps): react_jsx_runtime.JSX.Element;
|
|
811
|
+
|
|
812
|
+
declare function DefaultArrayRowLayout({ children, buttons, }: ArrayRowLayoutProps): react_jsx_runtime.JSX.Element;
|
|
813
|
+
|
|
814
|
+
declare function DefaultObjectWrapper({ children, label, className, labelClassName, }: ObjectWrapperProps): react_jsx_runtime.JSX.Element;
|
|
815
|
+
|
|
816
|
+
declare function DefaultArrayWrapper({ children, label, className, labelClassName, }: ArrayWrapperProps): react_jsx_runtime.JSX.Element;
|
|
817
|
+
|
|
672
818
|
declare const defaultRegistry: ComponentRegistry;
|
|
673
819
|
|
|
674
820
|
/**
|
|
@@ -708,7 +854,7 @@ declare function mergeRegistries(base: ComponentRegistry, overrides?: ComponentR
|
|
|
708
854
|
*/
|
|
709
855
|
declare function createAutoForm(config: AutoFormConfig): {
|
|
710
856
|
<TSchema extends z.$ZodObject>(props: AutoFormProps<TSchema> & {
|
|
711
|
-
ref?: React.Ref<AutoFormHandle<TSchema>>;
|
|
857
|
+
ref?: React$1.Ref<AutoFormHandle<TSchema>>;
|
|
712
858
|
}): react_jsx_runtime.JSX.Element;
|
|
713
859
|
displayName: string;
|
|
714
860
|
};
|
|
@@ -890,7 +1036,7 @@ declare function useFormPersistence(options: {
|
|
|
890
1036
|
type AutoFormContextValue = {
|
|
891
1037
|
registry: ComponentRegistry;
|
|
892
1038
|
fieldOverrides: Record<string, unknown>;
|
|
893
|
-
fieldWrapper: React.ComponentType<FieldWrapperProps>;
|
|
1039
|
+
fieldWrapper: React$1.ComponentType<FieldWrapperProps>;
|
|
894
1040
|
layout: ResolvedLayoutSlots;
|
|
895
1041
|
classNames: FormClassNames;
|
|
896
1042
|
disabled: boolean;
|
|
@@ -901,4 +1047,4 @@ type AutoFormContextValue = {
|
|
|
901
1047
|
};
|
|
902
1048
|
declare function useAutoFormContext(): AutoFormContextValue;
|
|
903
1049
|
|
|
904
|
-
export { type ArrayRowLayoutProps, AutoForm, type AutoFormConfig, type AutoFormContextValue, type AutoFormHandle, type AutoFormProps, type CoercionMap$1 as CoercionMap, type ComponentRegistry, DefaultCheckbox, DefaultFieldWrapper, DefaultInput, DefaultSelect, DefaultSubmitButton, type FieldCondition, type FieldConfig, type FieldDependencyResult, type FieldMeta, type FieldMetaBase, type FieldOverride, type FieldProps, FieldRenderer, type FieldType, type FieldWrapperProps, type FormClassNames, type FormLabels, type FormMethods, type LayoutSlots, type PersistStorage, type ResolvedLayoutSlots, type SectionGroup, type SelectOption, UniForm, type UniFormContext, type ValidationMessages, coerceValue, createAutoForm, createForm, defaultCoercionMap, defaultRegistry, introspectObjectSchema, introspectSchema, mergeRegistries, useAutoFormContext, useConditionalFields, useFormPersistence, useSectionGrouping };
|
|
1050
|
+
export { type ArrayButtonProps, type ArrayButtonSlots, type ArrayCollapseButtonProps, type ArrayFieldLayoutProps, type ArrayRowLayoutProps, type ArrayWrapperProps, AutoForm, type AutoFormConfig, type AutoFormContextValue, type AutoFormHandle, type AutoFormProps, type CoercionMap$1 as CoercionMap, type ComponentRegistry, DefaultArrayButton, DefaultArrayCollapseButton, DefaultArrayFieldLayout, DefaultArrayRowLayout, DefaultArrayWrapper, DefaultCheckbox, DefaultFieldWrapper, DefaultInput, DefaultObjectWrapper, DefaultSelect, DefaultSubmitButton, type FieldCondition, type FieldConfig, type FieldDependencyResult, type FieldMeta, type FieldMetaBase, type FieldOverride, type FieldProps, FieldRenderer, type FieldType, type FieldWrapperProps, type FormClassNames, type FormLabels, type FormMethods, type FormWrapperProps, type LayoutSlots, type ObjectWrapperProps, type PersistStorage, type ResolvedArrayButtonSlots, type ResolvedLayoutSlots, type SectionConfig, type SectionGroup, type SectionWrapperProps, type SelectOption, type SubmitButtonProps, UniForm, type UniFormContext, type ValidationMessages, coerceValue, createAutoForm, createForm, defaultCoercionMap, defaultRegistry, introspectObjectSchema, introspectSchema, mergeRegistries, useAutoFormContext, useConditionalFields, useFormPersistence, useSectionGrouping };
|