@uniform-ts/core 0.0.7 → 0.0.8

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 CHANGED
@@ -45,7 +45,9 @@ UniForm introspects the schema, renders appropriate inputs, validates with Zod,
45
45
 
46
46
  **`createAutoForm(defaults)`** — factory that bakes in your design system defaults (components, classNames, fieldWrapper) once, so you don't repeat them on every form.
47
47
 
48
- **`components`** — a registry mapping Zod types (`string`, `number`, `boolean`, etc.) to your own input components. Pass a component directly on a field via `fields` for one-off overrides.
48
+ **`useArrayField(fieldName)`** — a React hook for external array controls (toolbars, section headers, sticky footers) inside the `<AutoForm>` tree. It returns `append/remove/move/...` from `useFieldArray` plus `rowCount`, `canAdd`, and `atMin` derived from the array's `minItems`/`maxItems`.
49
+
50
+ **`components`** — a registry mapping Zod types (`string`, `number`, `boolean`, etc.) to your own input components. Pass a component directly on a field via `fields` for one-off overrides. For custom components, type field values precisely with `FieldProps<Value>` (for example, `FieldProps<number>` for a rating widget).
49
51
 
50
52
  **`fields`** — per-field overrides using dot-notated paths. Control labels, descriptions, ordering, sections, conditions, and custom components without touching the schema.
51
53
 
@@ -64,27 +66,28 @@ UniForm introspects the schema, renders appropriate inputs, validates with Zod,
64
66
 
65
67
  ## Core Props
66
68
 
67
- | Prop | Type | Description |
68
- | --------------- | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
69
- | `form` | `UniForm<TSchema>` | Schema + onChange handlers from `createForm()` |
70
- | `onSubmit` | `(values) => void \| Promise<void>` | Called with typed values after successful validation |
71
- | `defaultValues` | `Partial<...>` or `() => Promise<...>` | Initial values; async function shows `loadingFallback` |
72
- | `components` | `ComponentRegistry` | Map Zod types to your input components |
73
- | `fields` | `Record<string, FieldOverride>` | Per-field label, description, order, section, condition |
74
- | `fieldWrapper` | `React.ComponentType<FieldWrapperProps>` | Custom wrapper around every scalar field |
75
- | `layout` | `LayoutSlots` | Replace form/section/object/array wrappers, submit button, array rows |
76
- | `classNames` | `FormClassNames` | CSS classes for form, fields, labels, errors, fieldset/legend wrappers |
77
- | `ref` | `React.Ref<AutoFormHandle>` | Imperative `reset`, `submit`, `setValues`, `getValues` |
78
- | `persistKey` | `string` | Auto-save form state to `localStorage` under this key |
79
- | `labels` | `FormLabels` | Override built-in UI strings for i18n; import a ready-made locale pack from `@uniform-ts/core/locales/{en,he,es}` |
69
+ | Prop | Type | Description |
70
+ | --------------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
71
+ | `form` | `UniForm<TSchema>` | Schema + onChange handlers from `createForm()` |
72
+ | `onSubmit` | `(values) => void \| Promise<void>` | Called with typed values after successful validation |
73
+ | `defaultValues` | `Partial<...>` or `() => Promise<...>` | Initial values; async function shows `loadingFallback` |
74
+ | `components` | `ComponentRegistry` | Map Zod types to your input components |
75
+ | `fields` | `Record<string, FieldOverride>` | Per-field label, description, order, section, condition |
76
+ | `fieldWrapper` | `React.ComponentType<FieldWrapperProps>` | Custom wrapper around every scalar field |
77
+ | `layout` | `LayoutSlots` | Replace form/section/object/array wrappers, submit button, array rows. Set `null` on omittable slots (submit/array buttons) to hide them |
78
+ | `classNames` | `FormClassNames` | CSS classes for form, fields, labels, errors, fieldset/legend wrappers |
79
+ | `ref` | `React.Ref<AutoFormHandle>` | Imperative `reset`, `submit`, `setValues`, `getValues` |
80
+ | `persistKey` | `string` | Auto-save form state to `localStorage` under this key |
81
+ | `labels` | `FormLabels` | Override built-in UI strings for i18n; import a ready-made locale pack from `@uniform-ts/core/locales/{en,he,es}` |
80
82
 
81
83
  ## Features
82
84
 
83
85
  - **Full Zod V4 support** — scalars, enums, objects, arrays, optionals, defaults, unions, discriminated unions
84
86
  - **react-hook-form** under the hood — performant, uncontrolled forms with `zodResolver`
85
87
  - **Section grouping** — group fields into named sections via `meta.section`
86
- - **Conditional fields** — show/hide fields based on form values; hidden fields reset to default
87
- - **Array fields** — movable, duplicable, collapsible rows; `minItems`/`maxItems` from Zod schema
88
+ - **Conditional fields** — show/hide fields based on form values; `hidden` and row-local sibling conditions work inside array rows too
89
+ - **Array fields** — movable, duplicable, collapsible rows; `minItems`/`maxItems` from Zod schema; per-row conditional fields
90
+ - **External array controls** — use `useArrayField('path.to.array')` to place Add/Remove controls outside the default array block while staying in sync with schema limits
88
91
  - **Programmatic control** — `reset()`, `submit()`, `setValues()`, `getValues()`, `setErrors()`, `focus()` via ref
89
92
  - **Form persistence** — auto-save to `localStorage` (or custom storage) with configurable debounce
90
93
  - **Pluggable coercion** — automatic `string → number`, `string → Date` with customizable coercion map
@@ -35,6 +35,23 @@ type DeepKeys<T> = T extends object ? {
35
35
  * // DeepFieldValue<{ name: string; items: { qty: number }[] }, 'items.qty'> → number
36
36
  */
37
37
  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;
38
+ /**
39
+ * Resolves the values type that a `setCondition` predicate receives for a
40
+ * given field key `K` within form values type `TValues`.
41
+ *
42
+ * - **Array item fields** (e.g. `"tasks.note"`): the predicate receives the
43
+ * array item type (`{ title, priority, note }`), enabling row-local sibling
44
+ * conditions like `(row) => row.priority === 'high'`.
45
+ * - **All other fields**: the predicate receives the full form values type.
46
+ *
47
+ * @example
48
+ * // ConditionValues<{ name: string; tasks: { priority: string; note: string }[] }, 'tasks.note'>
49
+ * // → { priority: string; note: string }
50
+ *
51
+ * // ConditionValues<{ name: string; address: { street: string } }, 'address.street'>
52
+ * // → { name: string; address: { street: string } } (full form — not an array)
53
+ */
54
+ type ConditionValues<TValues, K extends string> = K extends `${infer Head}.${string}` ? Head extends keyof TValues ? TValues[Head] extends readonly (infer Item)[] ? Item : TValues : TValues : TValues;
38
55
 
39
56
  /**
40
57
  * A single option entry used in `select` / enum fields.
@@ -140,8 +157,8 @@ interface ArrayRowLayoutProps {
140
157
  moveDown: React$1.ReactNode | null;
141
158
  /** Button to duplicate the row, or `null` if at max items. */
142
159
  duplicate: React$1.ReactNode | null;
143
- /** Button to remove the row. */
144
- remove: React$1.ReactNode;
160
+ /** Button to remove the row, or `null` when omitted via layout slot. */
161
+ remove: React$1.ReactNode | null;
145
162
  /** Button to collapse/expand the row, or `null` if collapsing is disabled. */
146
163
  collapse: React$1.ReactNode | null;
147
164
  };
@@ -195,6 +212,7 @@ interface SubmitButtonProps {
195
212
  isSubmitting: boolean;
196
213
  label: string;
197
214
  }
215
+ type OptionalSlotComponent<TProps> = React$1.ComponentType<TProps> | null;
198
216
  /**
199
217
  * Per-section styling overrides forwarded to the `sectionWrapper` component.
200
218
  * Keys are section titles; values control how that section wrapper is styled.
@@ -212,35 +230,35 @@ type SectionConfig = {
212
230
  * itself falls back to a plain `<button>`.
213
231
  */
214
232
  type ArrayButtonSlots = {
215
- /** Used for every array button that has no specific override. */
216
- base?: React$1.ComponentType<ArrayButtonProps>;
217
- /** Override for the add-row button only. */
218
- add?: React$1.ComponentType<ArrayButtonProps>;
219
- /** Override for the remove-row button only. */
220
- remove?: React$1.ComponentType<ArrayButtonProps>;
221
- /** Override for the move-up button only. */
222
- moveUp?: React$1.ComponentType<ArrayButtonProps>;
223
- /** Override for the move-down button only. */
224
- moveDown?: React$1.ComponentType<ArrayButtonProps>;
225
- /** Override for the duplicate-row button only. */
226
- duplicate?: React$1.ComponentType<ArrayButtonProps>;
233
+ /** Used for every array button that has no specific override. Set to `null` to omit all unspecified buttons. */
234
+ base?: OptionalSlotComponent<ArrayButtonProps>;
235
+ /** Override for the add-row button only. Set to `null` to omit. */
236
+ add?: OptionalSlotComponent<ArrayButtonProps>;
237
+ /** Override for the remove-row button only. Set to `null` to omit. */
238
+ remove?: OptionalSlotComponent<ArrayButtonProps>;
239
+ /** Override for the move-up button only. Set to `null` to omit. */
240
+ moveUp?: OptionalSlotComponent<ArrayButtonProps>;
241
+ /** Override for the move-down button only. Set to `null` to omit. */
242
+ moveDown?: OptionalSlotComponent<ArrayButtonProps>;
243
+ /** Override for the duplicate-row button only. Set to `null` to omit. */
244
+ duplicate?: OptionalSlotComponent<ArrayButtonProps>;
227
245
  /**
228
246
  * Override for the collapse/expand toggle button only.
229
247
  * Receives `isCollapsed` in addition to standard `ArrayButtonProps`.
230
248
  */
231
- collapse?: React$1.ComponentType<ArrayCollapseButtonProps>;
249
+ collapse?: OptionalSlotComponent<ArrayCollapseButtonProps>;
232
250
  };
233
251
  /**
234
252
  * Resolved button slots where every entry is guaranteed to be defined.
235
253
  */
236
254
  type ResolvedArrayButtonSlots = {
237
- base: React$1.ComponentType<ArrayButtonProps>;
238
- add: React$1.ComponentType<ArrayButtonProps>;
239
- remove: React$1.ComponentType<ArrayButtonProps>;
240
- moveUp: React$1.ComponentType<ArrayButtonProps>;
241
- moveDown: React$1.ComponentType<ArrayButtonProps>;
242
- duplicate: React$1.ComponentType<ArrayButtonProps>;
243
- collapse: React$1.ComponentType<ArrayCollapseButtonProps>;
255
+ base: OptionalSlotComponent<ArrayButtonProps>;
256
+ add: OptionalSlotComponent<ArrayButtonProps>;
257
+ remove: OptionalSlotComponent<ArrayButtonProps>;
258
+ moveUp: OptionalSlotComponent<ArrayButtonProps>;
259
+ moveDown: OptionalSlotComponent<ArrayButtonProps>;
260
+ duplicate: OptionalSlotComponent<ArrayButtonProps>;
261
+ collapse: OptionalSlotComponent<ArrayCollapseButtonProps>;
244
262
  };
245
263
  /**
246
264
  * Optional layout slot overrides for top-level structural components of the
@@ -252,8 +270,8 @@ type LayoutSlots = {
252
270
  formWrapper?: React$1.ComponentType<FormWrapperProps>;
253
271
  /** Wrapper rendered around each named field section. */
254
272
  sectionWrapper?: React$1.ComponentType<SectionWrapperProps>;
255
- /** Custom submit button component. */
256
- submitButton?: React$1.ComponentType<SubmitButtonProps>;
273
+ /** Custom submit button component. Set to `null` to omit rendering it. */
274
+ submitButton?: OptionalSlotComponent<SubmitButtonProps>;
257
275
  /** Custom layout component for individual rows in array fields. */
258
276
  arrayRowLayout?: React$1.ComponentType<ArrayRowLayoutProps>;
259
277
  /**
@@ -295,7 +313,7 @@ type LayoutSlots = {
295
313
  type ResolvedLayoutSlots = {
296
314
  formWrapper: React$1.ComponentType<FormWrapperProps>;
297
315
  sectionWrapper: React$1.ComponentType<SectionWrapperProps>;
298
- submitButton: React$1.ComponentType<SubmitButtonProps>;
316
+ submitButton: OptionalSlotComponent<SubmitButtonProps>;
299
317
  arrayRowLayout: React$1.ComponentType<ArrayRowLayoutProps>;
300
318
  arrayFieldLayout: React$1.ComponentType<ArrayFieldLayoutProps>;
301
319
  objectWrapper: React$1.ComponentType<ObjectWrapperProps>;
@@ -680,13 +698,13 @@ type FieldConfig = FieldConfigBase & ({
680
698
  * value, change/blur handlers, and all resolved UI metadata needed to render
681
699
  * a single field.
682
700
  */
683
- interface FieldProps {
701
+ interface FieldProps<Value = unknown> {
684
702
  /** Dot-notated field path (e.g. `"address.street"`). */
685
703
  name: string;
686
704
  /** The current field value. */
687
- value: unknown;
705
+ value: Value;
688
706
  /** Callback to update the field value. */
689
- onChange: (value: unknown) => void;
707
+ onChange: (value: Value) => void;
690
708
  /** Callback fired when the field loses focus. */
691
709
  onBlur: () => void;
692
710
  /** Ref callback for registering the DOM element with `react-hook-form`. */
@@ -727,4 +745,4 @@ type FieldOverride<TSchema extends z.$ZodObject = z.$ZodObject, TValue = unknown
727
745
  [key: string]: unknown;
728
746
  };
729
747
 
730
- export type { AutoFormProps as A, ComponentRegistry as C, DeepKeys as D, FieldMetaBase as F, LayoutSlots as L, ObjectWrapperProps as O, PersistStorage as P, ResolvedLayoutSlots as R, SectionConfig as S, ValidationMessages as V, FieldConfig as a, AutoFormHandle as b, FieldProps as c, FieldWrapperProps as d, ArrayButtonProps as e, ArrayCollapseButtonProps as f, ArrayFieldLayoutProps as g, ArrayRowLayoutProps as h, ArrayWrapperProps as i, AutoFormConfig as j, FormMethods as k, FieldDependencyResult as l, DeepFieldValue as m, FormClassNames as n, CoercionMap as o, FormLabels as p, ArrayButtonSlots as q, FieldCondition as r, FieldMeta as s, FieldOverride as t, FieldType as u, FormWrapperProps as v, ResolvedArrayButtonSlots as w, SectionWrapperProps as x, SelectOption as y, SubmitButtonProps as z };
748
+ export type { AutoFormProps as A, SubmitButtonProps as B, ComponentRegistry as C, DeepKeys as D, FieldMetaBase as F, LayoutSlots as L, ObjectWrapperProps as O, PersistStorage as P, ResolvedLayoutSlots as R, SectionConfig as S, ValidationMessages as V, FieldConfig as a, AutoFormHandle as b, FieldProps as c, FieldWrapperProps as d, ArrayButtonProps as e, ArrayCollapseButtonProps as f, ArrayFieldLayoutProps as g, ArrayRowLayoutProps as h, ArrayWrapperProps as i, AutoFormConfig as j, FormMethods as k, FieldDependencyResult as l, DeepFieldValue as m, ConditionValues as n, FormClassNames as o, CoercionMap as p, FormLabels as q, ArrayButtonSlots as r, FieldCondition as s, FieldMeta as t, FieldOverride as u, FieldType as v, FormWrapperProps as w, ResolvedArrayButtonSlots as x, SectionWrapperProps as y, SelectOption as z };
@@ -35,6 +35,23 @@ type DeepKeys<T> = T extends object ? {
35
35
  * // DeepFieldValue<{ name: string; items: { qty: number }[] }, 'items.qty'> → number
36
36
  */
37
37
  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;
38
+ /**
39
+ * Resolves the values type that a `setCondition` predicate receives for a
40
+ * given field key `K` within form values type `TValues`.
41
+ *
42
+ * - **Array item fields** (e.g. `"tasks.note"`): the predicate receives the
43
+ * array item type (`{ title, priority, note }`), enabling row-local sibling
44
+ * conditions like `(row) => row.priority === 'high'`.
45
+ * - **All other fields**: the predicate receives the full form values type.
46
+ *
47
+ * @example
48
+ * // ConditionValues<{ name: string; tasks: { priority: string; note: string }[] }, 'tasks.note'>
49
+ * // → { priority: string; note: string }
50
+ *
51
+ * // ConditionValues<{ name: string; address: { street: string } }, 'address.street'>
52
+ * // → { name: string; address: { street: string } } (full form — not an array)
53
+ */
54
+ type ConditionValues<TValues, K extends string> = K extends `${infer Head}.${string}` ? Head extends keyof TValues ? TValues[Head] extends readonly (infer Item)[] ? Item : TValues : TValues : TValues;
38
55
 
39
56
  /**
40
57
  * A single option entry used in `select` / enum fields.
@@ -140,8 +157,8 @@ interface ArrayRowLayoutProps {
140
157
  moveDown: React$1.ReactNode | null;
141
158
  /** Button to duplicate the row, or `null` if at max items. */
142
159
  duplicate: React$1.ReactNode | null;
143
- /** Button to remove the row. */
144
- remove: React$1.ReactNode;
160
+ /** Button to remove the row, or `null` when omitted via layout slot. */
161
+ remove: React$1.ReactNode | null;
145
162
  /** Button to collapse/expand the row, or `null` if collapsing is disabled. */
146
163
  collapse: React$1.ReactNode | null;
147
164
  };
@@ -195,6 +212,7 @@ interface SubmitButtonProps {
195
212
  isSubmitting: boolean;
196
213
  label: string;
197
214
  }
215
+ type OptionalSlotComponent<TProps> = React$1.ComponentType<TProps> | null;
198
216
  /**
199
217
  * Per-section styling overrides forwarded to the `sectionWrapper` component.
200
218
  * Keys are section titles; values control how that section wrapper is styled.
@@ -212,35 +230,35 @@ type SectionConfig = {
212
230
  * itself falls back to a plain `<button>`.
213
231
  */
214
232
  type ArrayButtonSlots = {
215
- /** Used for every array button that has no specific override. */
216
- base?: React$1.ComponentType<ArrayButtonProps>;
217
- /** Override for the add-row button only. */
218
- add?: React$1.ComponentType<ArrayButtonProps>;
219
- /** Override for the remove-row button only. */
220
- remove?: React$1.ComponentType<ArrayButtonProps>;
221
- /** Override for the move-up button only. */
222
- moveUp?: React$1.ComponentType<ArrayButtonProps>;
223
- /** Override for the move-down button only. */
224
- moveDown?: React$1.ComponentType<ArrayButtonProps>;
225
- /** Override for the duplicate-row button only. */
226
- duplicate?: React$1.ComponentType<ArrayButtonProps>;
233
+ /** Used for every array button that has no specific override. Set to `null` to omit all unspecified buttons. */
234
+ base?: OptionalSlotComponent<ArrayButtonProps>;
235
+ /** Override for the add-row button only. Set to `null` to omit. */
236
+ add?: OptionalSlotComponent<ArrayButtonProps>;
237
+ /** Override for the remove-row button only. Set to `null` to omit. */
238
+ remove?: OptionalSlotComponent<ArrayButtonProps>;
239
+ /** Override for the move-up button only. Set to `null` to omit. */
240
+ moveUp?: OptionalSlotComponent<ArrayButtonProps>;
241
+ /** Override for the move-down button only. Set to `null` to omit. */
242
+ moveDown?: OptionalSlotComponent<ArrayButtonProps>;
243
+ /** Override for the duplicate-row button only. Set to `null` to omit. */
244
+ duplicate?: OptionalSlotComponent<ArrayButtonProps>;
227
245
  /**
228
246
  * Override for the collapse/expand toggle button only.
229
247
  * Receives `isCollapsed` in addition to standard `ArrayButtonProps`.
230
248
  */
231
- collapse?: React$1.ComponentType<ArrayCollapseButtonProps>;
249
+ collapse?: OptionalSlotComponent<ArrayCollapseButtonProps>;
232
250
  };
233
251
  /**
234
252
  * Resolved button slots where every entry is guaranteed to be defined.
235
253
  */
236
254
  type ResolvedArrayButtonSlots = {
237
- base: React$1.ComponentType<ArrayButtonProps>;
238
- add: React$1.ComponentType<ArrayButtonProps>;
239
- remove: React$1.ComponentType<ArrayButtonProps>;
240
- moveUp: React$1.ComponentType<ArrayButtonProps>;
241
- moveDown: React$1.ComponentType<ArrayButtonProps>;
242
- duplicate: React$1.ComponentType<ArrayButtonProps>;
243
- collapse: React$1.ComponentType<ArrayCollapseButtonProps>;
255
+ base: OptionalSlotComponent<ArrayButtonProps>;
256
+ add: OptionalSlotComponent<ArrayButtonProps>;
257
+ remove: OptionalSlotComponent<ArrayButtonProps>;
258
+ moveUp: OptionalSlotComponent<ArrayButtonProps>;
259
+ moveDown: OptionalSlotComponent<ArrayButtonProps>;
260
+ duplicate: OptionalSlotComponent<ArrayButtonProps>;
261
+ collapse: OptionalSlotComponent<ArrayCollapseButtonProps>;
244
262
  };
245
263
  /**
246
264
  * Optional layout slot overrides for top-level structural components of the
@@ -252,8 +270,8 @@ type LayoutSlots = {
252
270
  formWrapper?: React$1.ComponentType<FormWrapperProps>;
253
271
  /** Wrapper rendered around each named field section. */
254
272
  sectionWrapper?: React$1.ComponentType<SectionWrapperProps>;
255
- /** Custom submit button component. */
256
- submitButton?: React$1.ComponentType<SubmitButtonProps>;
273
+ /** Custom submit button component. Set to `null` to omit rendering it. */
274
+ submitButton?: OptionalSlotComponent<SubmitButtonProps>;
257
275
  /** Custom layout component for individual rows in array fields. */
258
276
  arrayRowLayout?: React$1.ComponentType<ArrayRowLayoutProps>;
259
277
  /**
@@ -295,7 +313,7 @@ type LayoutSlots = {
295
313
  type ResolvedLayoutSlots = {
296
314
  formWrapper: React$1.ComponentType<FormWrapperProps>;
297
315
  sectionWrapper: React$1.ComponentType<SectionWrapperProps>;
298
- submitButton: React$1.ComponentType<SubmitButtonProps>;
316
+ submitButton: OptionalSlotComponent<SubmitButtonProps>;
299
317
  arrayRowLayout: React$1.ComponentType<ArrayRowLayoutProps>;
300
318
  arrayFieldLayout: React$1.ComponentType<ArrayFieldLayoutProps>;
301
319
  objectWrapper: React$1.ComponentType<ObjectWrapperProps>;
@@ -680,13 +698,13 @@ type FieldConfig = FieldConfigBase & ({
680
698
  * value, change/blur handlers, and all resolved UI metadata needed to render
681
699
  * a single field.
682
700
  */
683
- interface FieldProps {
701
+ interface FieldProps<Value = unknown> {
684
702
  /** Dot-notated field path (e.g. `"address.street"`). */
685
703
  name: string;
686
704
  /** The current field value. */
687
- value: unknown;
705
+ value: Value;
688
706
  /** Callback to update the field value. */
689
- onChange: (value: unknown) => void;
707
+ onChange: (value: Value) => void;
690
708
  /** Callback fired when the field loses focus. */
691
709
  onBlur: () => void;
692
710
  /** Ref callback for registering the DOM element with `react-hook-form`. */
@@ -727,4 +745,4 @@ type FieldOverride<TSchema extends z.$ZodObject = z.$ZodObject, TValue = unknown
727
745
  [key: string]: unknown;
728
746
  };
729
747
 
730
- export type { AutoFormProps as A, ComponentRegistry as C, DeepKeys as D, FieldMetaBase as F, LayoutSlots as L, ObjectWrapperProps as O, PersistStorage as P, ResolvedLayoutSlots as R, SectionConfig as S, ValidationMessages as V, FieldConfig as a, AutoFormHandle as b, FieldProps as c, FieldWrapperProps as d, ArrayButtonProps as e, ArrayCollapseButtonProps as f, ArrayFieldLayoutProps as g, ArrayRowLayoutProps as h, ArrayWrapperProps as i, AutoFormConfig as j, FormMethods as k, FieldDependencyResult as l, DeepFieldValue as m, FormClassNames as n, CoercionMap as o, FormLabels as p, ArrayButtonSlots as q, FieldCondition as r, FieldMeta as s, FieldOverride as t, FieldType as u, FormWrapperProps as v, ResolvedArrayButtonSlots as w, SectionWrapperProps as x, SelectOption as y, SubmitButtonProps as z };
748
+ export type { AutoFormProps as A, SubmitButtonProps as B, ComponentRegistry as C, DeepKeys as D, FieldMetaBase as F, LayoutSlots as L, ObjectWrapperProps as O, PersistStorage as P, ResolvedLayoutSlots as R, SectionConfig as S, ValidationMessages as V, FieldConfig as a, AutoFormHandle as b, FieldProps as c, FieldWrapperProps as d, ArrayButtonProps as e, ArrayCollapseButtonProps as f, ArrayFieldLayoutProps as g, ArrayRowLayoutProps as h, ArrayWrapperProps as i, AutoFormConfig as j, FormMethods as k, FieldDependencyResult as l, DeepFieldValue as m, ConditionValues as n, FormClassNames as o, CoercionMap as p, FormLabels as q, ArrayButtonSlots as r, FieldCondition as s, FieldMeta as t, FieldOverride as u, FieldType as v, FormWrapperProps as w, ResolvedArrayButtonSlots as x, SectionWrapperProps as y, SelectOption as z };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,9 @@
1
- import { F as FieldMetaBase, a as FieldConfig, A as AutoFormProps, b as AutoFormHandle, c as FieldProps, d as FieldWrapperProps, e as ArrayButtonProps, f as ArrayCollapseButtonProps, g as ArrayFieldLayoutProps, h as ArrayRowLayoutProps, O as ObjectWrapperProps, i as ArrayWrapperProps, C as ComponentRegistry, j as AutoFormConfig, D as DeepKeys, k as FormMethods, l as FieldDependencyResult, m as DeepFieldValue, P as PersistStorage, R as ResolvedLayoutSlots, n as FormClassNames, o as CoercionMap$1, V as ValidationMessages, p as FormLabels } from './field-DPgaGkOL.mjs';
2
- export { q as ArrayButtonSlots, r as FieldCondition, s as FieldMeta, t as FieldOverride, u as FieldType, v as FormWrapperProps, L as LayoutSlots, w as ResolvedArrayButtonSlots, S as SectionConfig, x as SectionWrapperProps, y as SelectOption, z as SubmitButtonProps } from './field-DPgaGkOL.mjs';
1
+ import { F as FieldMetaBase, a as FieldConfig, A as AutoFormProps, b as AutoFormHandle, c as FieldProps, d as FieldWrapperProps, e as ArrayButtonProps, f as ArrayCollapseButtonProps, g as ArrayFieldLayoutProps, h as ArrayRowLayoutProps, O as ObjectWrapperProps, i as ArrayWrapperProps, C as ComponentRegistry, j as AutoFormConfig, D as DeepKeys, k as FormMethods, l as FieldDependencyResult, m as DeepFieldValue, n as ConditionValues, P as PersistStorage, R as ResolvedLayoutSlots, o as FormClassNames, p as CoercionMap$1, V as ValidationMessages, q as FormLabels } from './field-KKjnXn-d.mjs';
2
+ export { r as ArrayButtonSlots, s as FieldCondition, t as FieldMeta, u as FieldOverride, v as FieldType, w as FormWrapperProps, L as LayoutSlots, x as ResolvedArrayButtonSlots, S as SectionConfig, y as SectionWrapperProps, z as SelectOption, B as SubmitButtonProps } from './field-KKjnXn-d.mjs';
3
3
  import * as z from 'zod/v4/core';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
  import * as React from 'react';
6
+ import * as react_hook_form from 'react-hook-form';
6
7
  import { Control } from 'react-hook-form';
7
8
 
8
9
  // zod@3.25+ — import from 'zod/v4'
@@ -192,7 +193,7 @@ type UniFormContext<TSchema extends z.$ZodObject = z.$ZodObject> = FormMethods<z
192
193
  setFieldMeta: <K extends DeepKeys<z.infer<TSchema>>>(field: K, meta: Partial<FieldDependencyResult>) => void;
193
194
  };
194
195
  type Handler<TSchema extends z.$ZodObject, TValue> = (value: TValue, ctx: UniFormContext<TSchema>) => void | Promise<void>;
195
- type Condition<TSchema extends z.$ZodObject> = (values: z.infer<TSchema>) => boolean;
196
+ type Condition = (values: unknown) => boolean;
196
197
  /**
197
198
  * A type-safe form definition that lives outside React components.
198
199
  * Wraps a Zod schema and lets you attach typed `setOnChange` callbacks that fire
@@ -235,13 +236,13 @@ declare class UniForm<TSchema extends z.$ZodObject, TRegistered extends string =
235
236
  * Composes with any `condition` set via the `fields` prop (UniForm takes precedence).
236
237
  * Returns `this` for fluent chaining.
237
238
  */
238
- setCondition<K extends DeepKeys<z.infer<TSchema>>>(field: K, predicate: Condition<TSchema>): this;
239
+ setCondition<K extends DeepKeys<z.infer<TSchema>>>(field: K, predicate: (values: ConditionValues<z.infer<TSchema>, K>) => boolean): this;
239
240
  /** @internal Called by AutoForm to fire the handler registered for a field. */
240
241
  _fireHandler(field: string, value: unknown, ctx: UniFormContext<TSchema>): void | Promise<void>;
241
242
  /** @internal Returns all field names that have registered onChange handlers. */
242
243
  _getWatchedFields(): string[];
243
244
  /** @internal Returns a copy of the conditions map for AutoForm to inject into field meta. */
244
- _getConditions(): Map<string, Condition<TSchema>>;
245
+ _getConditions(): Map<string, Condition>;
245
246
  }
246
247
  /**
247
248
  * Creates a new `UniForm` instance for the given Zod object schema.
@@ -278,9 +279,12 @@ declare function createForm(schema: z.$ZodDiscriminatedUnion): UniForm<z.$ZodObj
278
279
  *
279
280
  * @param fields - The full list of field configs to filter and sort.
280
281
  * @param control - The RHF `control` object from the parent form.
282
+ * @param scopeName - When provided, conditions receive only the values at this
283
+ * path (e.g. `"tasks.0"` for an array row) rather than the full form values.
284
+ * This enables row-local sibling conditions inside arrays.
281
285
  * @returns The filtered and ordered subset of `fields`.
282
286
  */
283
- declare function useConditionalFields(fields: FieldConfig[], control: Control): FieldConfig[];
287
+ declare function useConditionalFields(fields: FieldConfig[], control: Control, scopeName?: string): FieldConfig[];
284
288
 
285
289
  type SectionGroup = {
286
290
  title: string | null;
@@ -324,8 +328,44 @@ declare function useFormPersistence(options: {
324
328
  clearPersistedData: () => void;
325
329
  };
326
330
 
331
+ /**
332
+ * Access the operations and reactive state of a named array field from
333
+ * anywhere inside an `<AutoForm>` tree.
334
+ *
335
+ * Useful for rendering action buttons (e.g. "Add Row") outside the array
336
+ * field's own wrapper — in a toolbar, section header, or custom form layout.
337
+ * `minItems` / `maxItems` are derived automatically from the Zod schema.
338
+ *
339
+ * @param fieldName - Dot-notated path to the array field (e.g. `"lineItems"`).
340
+ *
341
+ * @example
342
+ * function AddRowButton() {
343
+ * const { append, canAdd, rowCount } = useArrayField('lineItems')
344
+ * return (
345
+ * <button disabled={!canAdd} onClick={() => append({})}>
346
+ * Add Item ({rowCount})
347
+ * </button>
348
+ * )
349
+ * }
350
+ */
351
+ declare function useArrayField(fieldName: string): {
352
+ rowCount: number;
353
+ canAdd: boolean;
354
+ atMin: boolean;
355
+ swap: react_hook_form.UseFieldArraySwap;
356
+ move: react_hook_form.UseFieldArrayMove;
357
+ prepend: react_hook_form.UseFieldArrayPrepend<react_hook_form.FieldValues, never>;
358
+ append: react_hook_form.UseFieldArrayAppend<react_hook_form.FieldValues, never>;
359
+ remove: react_hook_form.UseFieldArrayRemove;
360
+ insert: react_hook_form.UseFieldArrayInsert<react_hook_form.FieldValues, never>;
361
+ update: react_hook_form.UseFieldArrayUpdate<react_hook_form.FieldValues, never>;
362
+ replace: react_hook_form.UseFieldArrayReplace<react_hook_form.FieldValues, never>;
363
+ fields: Record<"id", string>[];
364
+ };
365
+
327
366
  type AutoFormContextValue = {
328
367
  registry: ComponentRegistry;
368
+ fieldConfigs: FieldConfig[];
329
369
  fieldOverrides: Record<string, unknown>;
330
370
  fieldWrapper: React.ComponentType<FieldWrapperProps>;
331
371
  layout: ResolvedLayoutSlots;
@@ -335,7 +375,8 @@ type AutoFormContextValue = {
335
375
  messages?: ValidationMessages;
336
376
  labels: FormLabels;
337
377
  formMethods: FormMethods;
378
+ control: Control;
338
379
  };
339
380
  declare function useAutoFormContext(): AutoFormContextValue;
340
381
 
341
- export { ArrayButtonProps, ArrayCollapseButtonProps, ArrayFieldLayoutProps, ArrayRowLayoutProps, ArrayWrapperProps, AutoForm, AutoFormConfig, type AutoFormContextValue, AutoFormHandle, AutoFormProps, CoercionMap$1 as CoercionMap, ComponentRegistry, DefaultArrayButton, DefaultArrayCollapseButton, DefaultArrayFieldLayout, DefaultArrayRowLayout, DefaultArrayWrapper, DefaultCheckbox, DefaultFieldWrapper, DefaultInput, DefaultObjectWrapper, DefaultSelect, DefaultSubmitButton, FieldConfig, FieldDependencyResult, FieldMetaBase, FieldProps, FieldRenderer, FieldWrapperProps, FormClassNames, FormLabels, FormMethods, ObjectWrapperProps, PersistStorage, ResolvedLayoutSlots, type SectionGroup, UniForm, type UniFormContext, ValidationMessages, coerceValue, createAutoForm, createForm, defaultCoercionMap, defaultRegistry, introspectObjectSchema, introspectSchema, mergeRegistries, useAutoFormContext, useConditionalFields, useFormPersistence, useSectionGrouping };
382
+ export { ArrayButtonProps, ArrayCollapseButtonProps, ArrayFieldLayoutProps, ArrayRowLayoutProps, ArrayWrapperProps, AutoForm, AutoFormConfig, type AutoFormContextValue, AutoFormHandle, AutoFormProps, CoercionMap$1 as CoercionMap, ComponentRegistry, DefaultArrayButton, DefaultArrayCollapseButton, DefaultArrayFieldLayout, DefaultArrayRowLayout, DefaultArrayWrapper, DefaultCheckbox, DefaultFieldWrapper, DefaultInput, DefaultObjectWrapper, DefaultSelect, DefaultSubmitButton, FieldConfig, FieldDependencyResult, FieldMetaBase, FieldProps, FieldRenderer, FieldWrapperProps, FormClassNames, FormLabels, FormMethods, ObjectWrapperProps, PersistStorage, ResolvedLayoutSlots, type SectionGroup, UniForm, type UniFormContext, ValidationMessages, coerceValue, createAutoForm, createForm, defaultCoercionMap, defaultRegistry, introspectObjectSchema, introspectSchema, mergeRegistries, useArrayField, useAutoFormContext, useConditionalFields, useFormPersistence, useSectionGrouping };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { F as FieldMetaBase, a as FieldConfig, A as AutoFormProps, b as AutoFormHandle, c as FieldProps, d as FieldWrapperProps, e as ArrayButtonProps, f as ArrayCollapseButtonProps, g as ArrayFieldLayoutProps, h as ArrayRowLayoutProps, O as ObjectWrapperProps, i as ArrayWrapperProps, C as ComponentRegistry, j as AutoFormConfig, D as DeepKeys, k as FormMethods, l as FieldDependencyResult, m as DeepFieldValue, P as PersistStorage, R as ResolvedLayoutSlots, n as FormClassNames, o as CoercionMap$1, V as ValidationMessages, p as FormLabels } from './field-DPgaGkOL.js';
2
- export { q as ArrayButtonSlots, r as FieldCondition, s as FieldMeta, t as FieldOverride, u as FieldType, v as FormWrapperProps, L as LayoutSlots, w as ResolvedArrayButtonSlots, S as SectionConfig, x as SectionWrapperProps, y as SelectOption, z as SubmitButtonProps } from './field-DPgaGkOL.js';
1
+ import { F as FieldMetaBase, a as FieldConfig, A as AutoFormProps, b as AutoFormHandle, c as FieldProps, d as FieldWrapperProps, e as ArrayButtonProps, f as ArrayCollapseButtonProps, g as ArrayFieldLayoutProps, h as ArrayRowLayoutProps, O as ObjectWrapperProps, i as ArrayWrapperProps, C as ComponentRegistry, j as AutoFormConfig, D as DeepKeys, k as FormMethods, l as FieldDependencyResult, m as DeepFieldValue, n as ConditionValues, P as PersistStorage, R as ResolvedLayoutSlots, o as FormClassNames, p as CoercionMap$1, V as ValidationMessages, q as FormLabels } from './field-KKjnXn-d.js';
2
+ export { r as ArrayButtonSlots, s as FieldCondition, t as FieldMeta, u as FieldOverride, v as FieldType, w as FormWrapperProps, L as LayoutSlots, x as ResolvedArrayButtonSlots, S as SectionConfig, y as SectionWrapperProps, z as SelectOption, B as SubmitButtonProps } from './field-KKjnXn-d.js';
3
3
  import * as z from 'zod/v4/core';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
  import * as React from 'react';
6
+ import * as react_hook_form from 'react-hook-form';
6
7
  import { Control } from 'react-hook-form';
7
8
 
8
9
  // zod@3.25+ — import from 'zod/v4'
@@ -192,7 +193,7 @@ type UniFormContext<TSchema extends z.$ZodObject = z.$ZodObject> = FormMethods<z
192
193
  setFieldMeta: <K extends DeepKeys<z.infer<TSchema>>>(field: K, meta: Partial<FieldDependencyResult>) => void;
193
194
  };
194
195
  type Handler<TSchema extends z.$ZodObject, TValue> = (value: TValue, ctx: UniFormContext<TSchema>) => void | Promise<void>;
195
- type Condition<TSchema extends z.$ZodObject> = (values: z.infer<TSchema>) => boolean;
196
+ type Condition = (values: unknown) => boolean;
196
197
  /**
197
198
  * A type-safe form definition that lives outside React components.
198
199
  * Wraps a Zod schema and lets you attach typed `setOnChange` callbacks that fire
@@ -235,13 +236,13 @@ declare class UniForm<TSchema extends z.$ZodObject, TRegistered extends string =
235
236
  * Composes with any `condition` set via the `fields` prop (UniForm takes precedence).
236
237
  * Returns `this` for fluent chaining.
237
238
  */
238
- setCondition<K extends DeepKeys<z.infer<TSchema>>>(field: K, predicate: Condition<TSchema>): this;
239
+ setCondition<K extends DeepKeys<z.infer<TSchema>>>(field: K, predicate: (values: ConditionValues<z.infer<TSchema>, K>) => boolean): this;
239
240
  /** @internal Called by AutoForm to fire the handler registered for a field. */
240
241
  _fireHandler(field: string, value: unknown, ctx: UniFormContext<TSchema>): void | Promise<void>;
241
242
  /** @internal Returns all field names that have registered onChange handlers. */
242
243
  _getWatchedFields(): string[];
243
244
  /** @internal Returns a copy of the conditions map for AutoForm to inject into field meta. */
244
- _getConditions(): Map<string, Condition<TSchema>>;
245
+ _getConditions(): Map<string, Condition>;
245
246
  }
246
247
  /**
247
248
  * Creates a new `UniForm` instance for the given Zod object schema.
@@ -278,9 +279,12 @@ declare function createForm(schema: z.$ZodDiscriminatedUnion): UniForm<z.$ZodObj
278
279
  *
279
280
  * @param fields - The full list of field configs to filter and sort.
280
281
  * @param control - The RHF `control` object from the parent form.
282
+ * @param scopeName - When provided, conditions receive only the values at this
283
+ * path (e.g. `"tasks.0"` for an array row) rather than the full form values.
284
+ * This enables row-local sibling conditions inside arrays.
281
285
  * @returns The filtered and ordered subset of `fields`.
282
286
  */
283
- declare function useConditionalFields(fields: FieldConfig[], control: Control): FieldConfig[];
287
+ declare function useConditionalFields(fields: FieldConfig[], control: Control, scopeName?: string): FieldConfig[];
284
288
 
285
289
  type SectionGroup = {
286
290
  title: string | null;
@@ -324,8 +328,44 @@ declare function useFormPersistence(options: {
324
328
  clearPersistedData: () => void;
325
329
  };
326
330
 
331
+ /**
332
+ * Access the operations and reactive state of a named array field from
333
+ * anywhere inside an `<AutoForm>` tree.
334
+ *
335
+ * Useful for rendering action buttons (e.g. "Add Row") outside the array
336
+ * field's own wrapper — in a toolbar, section header, or custom form layout.
337
+ * `minItems` / `maxItems` are derived automatically from the Zod schema.
338
+ *
339
+ * @param fieldName - Dot-notated path to the array field (e.g. `"lineItems"`).
340
+ *
341
+ * @example
342
+ * function AddRowButton() {
343
+ * const { append, canAdd, rowCount } = useArrayField('lineItems')
344
+ * return (
345
+ * <button disabled={!canAdd} onClick={() => append({})}>
346
+ * Add Item ({rowCount})
347
+ * </button>
348
+ * )
349
+ * }
350
+ */
351
+ declare function useArrayField(fieldName: string): {
352
+ rowCount: number;
353
+ canAdd: boolean;
354
+ atMin: boolean;
355
+ swap: react_hook_form.UseFieldArraySwap;
356
+ move: react_hook_form.UseFieldArrayMove;
357
+ prepend: react_hook_form.UseFieldArrayPrepend<react_hook_form.FieldValues, never>;
358
+ append: react_hook_form.UseFieldArrayAppend<react_hook_form.FieldValues, never>;
359
+ remove: react_hook_form.UseFieldArrayRemove;
360
+ insert: react_hook_form.UseFieldArrayInsert<react_hook_form.FieldValues, never>;
361
+ update: react_hook_form.UseFieldArrayUpdate<react_hook_form.FieldValues, never>;
362
+ replace: react_hook_form.UseFieldArrayReplace<react_hook_form.FieldValues, never>;
363
+ fields: Record<"id", string>[];
364
+ };
365
+
327
366
  type AutoFormContextValue = {
328
367
  registry: ComponentRegistry;
368
+ fieldConfigs: FieldConfig[];
329
369
  fieldOverrides: Record<string, unknown>;
330
370
  fieldWrapper: React.ComponentType<FieldWrapperProps>;
331
371
  layout: ResolvedLayoutSlots;
@@ -335,7 +375,8 @@ type AutoFormContextValue = {
335
375
  messages?: ValidationMessages;
336
376
  labels: FormLabels;
337
377
  formMethods: FormMethods;
378
+ control: Control;
338
379
  };
339
380
  declare function useAutoFormContext(): AutoFormContextValue;
340
381
 
341
- export { ArrayButtonProps, ArrayCollapseButtonProps, ArrayFieldLayoutProps, ArrayRowLayoutProps, ArrayWrapperProps, AutoForm, AutoFormConfig, type AutoFormContextValue, AutoFormHandle, AutoFormProps, CoercionMap$1 as CoercionMap, ComponentRegistry, DefaultArrayButton, DefaultArrayCollapseButton, DefaultArrayFieldLayout, DefaultArrayRowLayout, DefaultArrayWrapper, DefaultCheckbox, DefaultFieldWrapper, DefaultInput, DefaultObjectWrapper, DefaultSelect, DefaultSubmitButton, FieldConfig, FieldDependencyResult, FieldMetaBase, FieldProps, FieldRenderer, FieldWrapperProps, FormClassNames, FormLabels, FormMethods, ObjectWrapperProps, PersistStorage, ResolvedLayoutSlots, type SectionGroup, UniForm, type UniFormContext, ValidationMessages, coerceValue, createAutoForm, createForm, defaultCoercionMap, defaultRegistry, introspectObjectSchema, introspectSchema, mergeRegistries, useAutoFormContext, useConditionalFields, useFormPersistence, useSectionGrouping };
382
+ export { ArrayButtonProps, ArrayCollapseButtonProps, ArrayFieldLayoutProps, ArrayRowLayoutProps, ArrayWrapperProps, AutoForm, AutoFormConfig, type AutoFormContextValue, AutoFormHandle, AutoFormProps, CoercionMap$1 as CoercionMap, ComponentRegistry, DefaultArrayButton, DefaultArrayCollapseButton, DefaultArrayFieldLayout, DefaultArrayRowLayout, DefaultArrayWrapper, DefaultCheckbox, DefaultFieldWrapper, DefaultInput, DefaultObjectWrapper, DefaultSelect, DefaultSubmitButton, FieldConfig, FieldDependencyResult, FieldMetaBase, FieldProps, FieldRenderer, FieldWrapperProps, FormClassNames, FormLabels, FormMethods, ObjectWrapperProps, PersistStorage, ResolvedLayoutSlots, type SectionGroup, UniForm, type UniFormContext, ValidationMessages, coerceValue, createAutoForm, createForm, defaultCoercionMap, defaultRegistry, introspectObjectSchema, introspectSchema, mergeRegistries, useArrayField, useAutoFormContext, useConditionalFields, useFormPersistence, useSectionGrouping };