UNPKG

@mitcsutt/kiln-forms

Version:

Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui

41 lines (40 loc) • 1.99 kB
import { type ReactNode } from 'react'; /** A layout region that knows which fields it contains (§9.0). */ export interface ScopeHandle { id: string; /** Static names (schema) ∪ every name ever mounted inside (remembered after it hides). */ names(): readonly string[]; /** Called when `names()` changes. */ subscribe: (cb: () => void) => () => void; /** Makes the region visible (selects the tab, opens the item, goes to the step). */ reveal?: () => void; } /** Internal scope node: a handle plus registration and its parent. */ export interface ScopeNode extends ScopeHandle { parent: ScopeNode | null; /** Registers a mounted field name; returns the unregister function. */ register(name: string): () => void; /** Names of fields currently mounted inside. */ mountedNames(): readonly string[]; /** @internal */ setStatic(names: readonly string[] | undefined): void; /** @internal */ setReveal(reveal: (() => void) | undefined): void; } export interface FieldScopeProps { /** Makes this region visible; focus management calls it before focusing a field inside. */ reveal?: () => void; /** Static names (schema mode) governed even before their fields mount. */ names?: readonly string[]; /** Called whenever the set of names changes. */ onNamesChange?: (names: readonly string[]) => void; children: ReactNode; } /** Collects the names of fields mounted inside it; nested scopes form the reveal chain (§5.6). */ export declare function FieldScope({ reveal, names, onNamesChange, children }: FieldScopeProps): import("react").JSX.Element; /** The nearest scope, or `null`. */ export declare function useFieldScope(): ScopeHandle | null; /** The nearest scope node (internal: bindings register through it). */ export declare function useScopeNode(): ScopeNode | null; /** The scope chain from the outermost scope to `node`. */ export declare function scopeChain(node: ScopeNode | null): ScopeNode[];