import { type Accessor } from "solid-js"; import type { FieldValidationMode, FieldValidityData, MutableRef } from "./field-context.js"; /** * Mapping of field name → error(s). Populated by `
` after server-side * validation or external submission feedback. */ export type FormErrors = Record; /** * Registration record that field controls push into `` so that `` * can orchestrate cross-field validation / submission. */ export interface FormFieldEntry { name: string | undefined; /** * Imperatively validate the field's currently-registered control. Returns * a Promise when the field has an async validator in flight; otherwise * returns synchronously. Form-level submit awaits the Promise (when * present) before reading `validityData`, so async validators * (`zod.parseAsync`, async refinements, server-side checks) block submit. */ validate: (flushSync?: boolean) => Promise | void; validityData: FieldValidityData; getValue: () => unknown; controlRef: MutableRef; } /** * Opaque handle held by `` so field controls have a stable place to * register without going through the reactive graph. The `fields` map is * mutated directly by field controls — do NOT put it in a signal or store. */ export interface FormRefState { fields: Map; } export interface FormContextValue { /** Ref holding the mutable fields map. */ readonly formRef: MutableRef; /** External errors (e.g. from server validation). */ errors: Accessor; /** Replace the entire errors map. */ setErrors: (next: FormErrors) => void; /** Clear errors for a single field name (or the whole map if undefined). */ clearErrors: (name: string | undefined) => void; /** Validation mode used when children don't override via ``. */ validationMode: Accessor; /** Whether the user has attempted a submit at least once. */ submitAttemptedRef: MutableRef; /** Marker — `true` when this context was provided by a real ``. */ readonly present: boolean; } /** * Factory for a fresh noop form context. Each call builds a new `fields` * map so tests (and real code paths) that imperatively mutate * `formRef.current.fields` can't leak state across runs via a shared * module-load singleton. * * `useFormContext` calls this when no `` provider is above, so every * consumer receives its own noop instance. */ export declare function createNoopFormContext(): FormContextValue; /** * Identity-only sentinel. `useFormContext` compares against this to detect * "no `` provider above" and return a fresh noop instead of the * shared default — preventing cross-call state leaks via `fields` * mutations. The sentinel itself is never returned from the hook. * * Exported as `NOOP_FORM_CONTEXT` for barrel / compat only; application * code should call `useFormContext()` and branch on `.present`. */ export declare const NOOP_FORM_CONTEXT: FormContextValue; /** * Context carrying `` state. Provided via ``. * Default value is the shared sentinel — `useFormContext` detects it by * identity and substitutes a fresh noop. */ export declare const FormContext: import("solid-js").Context; /** * Read the current `` context. When unwrapped (no `` ancestor), * returns a fresh noop so callers that mutate `formRef.current.fields` can't * inadvertently share state with other roots. Callers can branch on * `.present` to detect "no form". */ export declare function useFormContext(): FormContextValue; //# sourceMappingURL=form-context.d.ts.map