@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
29 lines (28 loc) • 1.77 kB
TypeScript
import type { UntypedFormSchema, UntypedNode, UntypedRepeaterNode } from './types.js';
/** Static facts about a schema, computed once per schema identity (§10.6). */
export interface SchemaAnalysis {
/**
* Field names in a node's subtree, for static scope lists and hidden-subtree pruning. A repeater
* contributes its array name (its items live under it). Names are relative to the node's scope:
* absolute at the root, item-relative inside a repeater item — pass the item path
* (`'guests[2]'`) as `prefix` to make them absolute.
*/
names: (node: UntypedNode, prefix?: string) => readonly string[];
/** Value paths the node's own conditions read (`when`, `disabledWhen`, `readOnlyWhen`, `excludeWhen`, `requiredWhen`). */
deps: (node: UntypedNode) => readonly string[];
/** Nodes by `id` (first wins; `parseFormSchema` rejects duplicates). */
nodeById: Map<string, UntypedNode>;
/** Field-level `defaultValue`s of root-scope fields, by name. */
defaults: Record<string, unknown>;
/** The repeater whose `item` template a node sits in (nearest), if any. */
repeaterOf: (node: UntypedNode) => UntypedRepeaterNode | undefined;
}
/** Static analysis of a schema (names per subtree, condition deps, ids, defaults). Cached per schema object. */
export declare function analyseSchema(schema: UntypedFormSchema): SchemaAnalysis;
/**
* Initial values for a schema of unknown shape (server-driven forms): each root-scope field
* gets its `defaultValue`, else `empties[kind]` when given; each repeater gets `[]`.
*
* @privateRemarks Design reference §10.8.
*/
export declare function schemaDefaultValues(schema: UntypedFormSchema, empties?: Readonly<Record<string, unknown>>): Record<string, unknown>;