@uniform-ts/core 0.0.7 → 0.0.9

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/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 DeepKeysIndexed, k as FormMethods, l as DeepKeys, m as FieldDependencyResult, n as DeepFieldValue, o as ConditionValues, P as PersistStorage, R as ResolvedLayoutSlots, p as FormClassNames, q as CoercionMap$1, V as ValidationMessages, r as FormLabels } from './field-Cogi7eQc.js';
2
+ export { s as ArrayButtonSlots, t as FieldCondition, u as FieldMeta, v as FieldOverride, w as FieldType, x as FormWrapperProps, L as LayoutSlots, y as ResolvedArrayButtonSlots, S as SectionConfig, z as SectionWrapperProps, B as SelectOption, E as SubmitButtonProps } from './field-Cogi7eQc.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
@@ -226,22 +227,26 @@ declare class UniForm<TSchema extends z.$ZodObject, TRegistered extends string =
226
227
  * Replaces any previously registered handler for that field — only one
227
228
  * handler per field is kept. This prevents accidental handler accumulation
228
229
  * when called inside a React render cycle.
230
+ *
231
+ * Supports both generic array paths (`"tasks.priority"` — fires for all rows)
232
+ * and indexed paths (`"tasks.0.priority"` — fires only for row 0).
233
+ *
229
234
  * Returns `this` for fluent chaining.
230
235
  */
231
- setOnChange<K extends Exclude<DeepKeys<z.infer<TSchema>>, TRegistered>>(field: K, handler: Handler<TSchema, DeepFieldValue<z.infer<TSchema>, K>>): UniForm<TSchema, TRegistered | K>;
236
+ setOnChange<K extends Exclude<DeepKeysIndexed<z.infer<TSchema>>, TRegistered>>(field: K, handler: Handler<TSchema, DeepFieldValue<z.infer<TSchema>, K>>): UniForm<TSchema, TRegistered | K>;
232
237
  /**
233
238
  * Attach a typed condition for a specific field.
234
239
  * The field is shown when the predicate returns `true`, hidden when `false`.
235
240
  * Composes with any `condition` set via the `fields` prop (UniForm takes precedence).
236
241
  * Returns `this` for fluent chaining.
237
242
  */
238
- setCondition<K extends DeepKeys<z.infer<TSchema>>>(field: K, predicate: Condition<TSchema>): this;
243
+ setCondition<K extends DeepKeys<z.infer<TSchema>>>(field: K, predicate: (values: ConditionValues<z.infer<TSchema>, K>) => boolean): this;
239
244
  /** @internal Called by AutoForm to fire the handler registered for a field. */
240
245
  _fireHandler(field: string, value: unknown, ctx: UniFormContext<TSchema>): void | Promise<void>;
241
246
  /** @internal Returns all field names that have registered onChange handlers. */
242
247
  _getWatchedFields(): string[];
243
248
  /** @internal Returns a copy of the conditions map for AutoForm to inject into field meta. */
244
- _getConditions(): Map<string, Condition<TSchema>>;
249
+ _getConditions(): Map<string, Condition>;
245
250
  }
246
251
  /**
247
252
  * Creates a new `UniForm` instance for the given Zod object schema.
@@ -278,9 +283,12 @@ declare function createForm(schema: z.$ZodDiscriminatedUnion): UniForm<z.$ZodObj
278
283
  *
279
284
  * @param fields - The full list of field configs to filter and sort.
280
285
  * @param control - The RHF `control` object from the parent form.
286
+ * @param scopeName - When provided, conditions receive only the values at this
287
+ * path (e.g. `"tasks.0"` for an array row) rather than the full form values.
288
+ * This enables row-local sibling conditions inside arrays.
281
289
  * @returns The filtered and ordered subset of `fields`.
282
290
  */
283
- declare function useConditionalFields(fields: FieldConfig[], control: Control): FieldConfig[];
291
+ declare function useConditionalFields(fields: FieldConfig[], control: Control, scopeName?: string): FieldConfig[];
284
292
 
285
293
  type SectionGroup = {
286
294
  title: string | null;
@@ -324,8 +332,44 @@ declare function useFormPersistence(options: {
324
332
  clearPersistedData: () => void;
325
333
  };
326
334
 
335
+ /**
336
+ * Access the operations and reactive state of a named array field from
337
+ * anywhere inside an `<AutoForm>` tree.
338
+ *
339
+ * Useful for rendering action buttons (e.g. "Add Row") outside the array
340
+ * field's own wrapper — in a toolbar, section header, or custom form layout.
341
+ * `minItems` / `maxItems` are derived automatically from the Zod schema.
342
+ *
343
+ * @param fieldName - Dot-notated path to the array field (e.g. `"lineItems"`).
344
+ *
345
+ * @example
346
+ * function AddRowButton() {
347
+ * const { append, canAdd, rowCount } = useArrayField('lineItems')
348
+ * return (
349
+ * <button disabled={!canAdd} onClick={() => append({})}>
350
+ * Add Item ({rowCount})
351
+ * </button>
352
+ * )
353
+ * }
354
+ */
355
+ declare function useArrayField(fieldName: string): {
356
+ rowCount: number;
357
+ canAdd: boolean;
358
+ atMin: boolean;
359
+ swap: react_hook_form.UseFieldArraySwap;
360
+ move: react_hook_form.UseFieldArrayMove;
361
+ prepend: react_hook_form.UseFieldArrayPrepend<react_hook_form.FieldValues, never>;
362
+ append: react_hook_form.UseFieldArrayAppend<react_hook_form.FieldValues, never>;
363
+ remove: react_hook_form.UseFieldArrayRemove;
364
+ insert: react_hook_form.UseFieldArrayInsert<react_hook_form.FieldValues, never>;
365
+ update: react_hook_form.UseFieldArrayUpdate<react_hook_form.FieldValues, never>;
366
+ replace: react_hook_form.UseFieldArrayReplace<react_hook_form.FieldValues, never>;
367
+ fields: Record<"id", string>[];
368
+ };
369
+
327
370
  type AutoFormContextValue = {
328
371
  registry: ComponentRegistry;
372
+ fieldConfigs: FieldConfig[];
329
373
  fieldOverrides: Record<string, unknown>;
330
374
  fieldWrapper: React.ComponentType<FieldWrapperProps>;
331
375
  layout: ResolvedLayoutSlots;
@@ -335,7 +379,9 @@ type AutoFormContextValue = {
335
379
  messages?: ValidationMessages;
336
380
  labels: FormLabels;
337
381
  formMethods: FormMethods;
382
+ control: Control;
383
+ setDynamicMeta: React.Dispatch<React.SetStateAction<Record<string, Partial<FieldDependencyResult>>>>;
338
384
  };
339
385
  declare function useAutoFormContext(): AutoFormContextValue;
340
386
 
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 };
387
+ 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 };