@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
31 lines (30 loc) • 1.84 kB
TypeScript
import type { AnyFieldApi } from '@tanstack/react-form';
import type { NormalisedError } from '../../runtime/errors.js';
import type { AnyKitForm } from '../../kit/types.js';
import { type CompiledRules } from '../core/rules.js';
import type { NamedValidator, UntypedRule } from '../core/types.js';
/** Async custom validators are debounced (§10.4). */
export declare const ASYNC_RULE_DEBOUNCE_MS = 300;
/** The compiled rules for a rules array, in the messages the form uses right now. */
export declare function compiledRules(rules: readonly UntypedRule[], kind: string | undefined, form: AnyKitForm, validators: Readonly<Record<string, NamedValidator>>): CompiledRules;
interface SyncProps {
value: unknown;
fieldApi: AnyFieldApi;
}
interface AsyncProps extends SyncProps {
signal: AbortSignal;
}
/** TanStack field validators: one `onDynamic` (sync rules) + one `onDynamicAsync` (async validators). */
export interface RuleValidators {
onDynamic?: (props: SyncProps) => NormalisedError | undefined;
onDynamicAsync?: (props: AsyncProps) => Promise<NormalisedError | undefined>;
onDynamicAsyncDebounceMs?: number;
}
/**
* Field-level validators for JSON rules. They mount and unmount with the field (§10.4), so a
* hidden field never validates. `undefined` when there are no rules.
*/
export declare function ruleValidators(rules: readonly UntypedRule[], kind: string | undefined, form: AnyKitForm, validators: Readonly<Record<string, NamedValidator>>): RuleValidators | undefined;
/** `warnRules` → the binding's `warn` prop (non-blocking, sync rules only). */
export declare function ruleWarning(rules: readonly UntypedRule[], kind: string, form: AnyKitForm, values: () => unknown, validators: Readonly<Record<string, NamedValidator>>): ((value: unknown) => string | undefined) | undefined;
export {};