import type { JSONSchema } from './json-schema.js'; /** What kind of control a field wants. The component maps this to elements. */ export type FieldKind = 'string' | 'number' | 'integer' | 'boolean' | 'enum' | 'const' | 'unsupported'; /** A nested object: its own label, and the fields inside it. */ export interface FieldGroup { /** keywords in this property's schema the validator ignores — see `unenforced.ts` */ unvalidated?: string[]; kind: 'group'; path: string; label: string; required: boolean; schema: JSONSchema; children: Node[]; /** A curated section, not a property: its id. `path` is then empty. See `curate.ts`. */ section?: string; /** The panel starts closed. */ collapsed?: boolean; } /** An array property: its item schema, and the fields for each current element. */ export interface FieldArray { /** keywords in this property's schema the validator ignores — see `unenforced.ts` */ unvalidated?: string[]; kind: 'array'; path: string; label: string; required: boolean; schema: JSONSchema; itemSchema: JSONSchema; } /** One branch of a variant union — a shape the value may take. */ export interface UnionBranch { label: string; schema: JSONSchema; /** the `const`-valued properties that identify this branch, e.g. `{kind: 'circle'}` */ marks: Record; } /** A property whose value may take one of several object shapes. */ export interface FieldUnion { kind: 'union'; path: string; label: string; required: boolean; schema: JSONSchema; branches: UnionBranch[]; /** the property whose `const` distinguishes the branches, when there is one */ discriminator?: string; /** keywords in this property's schema that the validator ignores — see `unenforced.ts` */ unvalidated?: string[]; } export type Node = Field | FieldGroup | FieldArray | FieldUnion; export interface Field { /** dotted path into the value object, e.g. `email` or `address.city` */ path: string; /** keywords in this field's schema that the validator ignores — see `unenforced.ts` */ unvalidated?: string[]; /** the label a human sees — `title`, else the last path segment, humanised */ label: string; kind: FieldKind; schema: JSONSchema; required: boolean; /** `` for a string field, from `format`; undefined for other kinds */ inputType?: string; /** enum choices, already coerced to strings for the DOM */ options?: Array<{ value: unknown; label: string; }>; /** why this field cannot be rendered — set only when `kind` is 'unsupported' */ reason?: string; } /** `firstName` / `first_name` / `first-name` → `first name`. */ export declare function humanise(key: string): string; /** * A schema's `title`, when it is one. Only a non-empty string counts: a schema can come from * anywhere, and tosijs reads an object handed to an element creator as properties, * `innerHTML` included (tosijs#43). Every label the model produces goes through here. */ export declare function titleOf(schema: unknown): string | undefined; /** Build the leaf field for a scalar / enum / const schema. Shared by objects and array items. */ export declare function scalarField(schema: JSONSchema, path: string, label: string, required: boolean): Field; /** * Which branch does `value` currently look like? `-1` when nothing matches. * * Marks first: a discriminator is an exact answer, and it is the reason schemas carry one. * Otherwise score by how many of the branch's own required keys are present — the component * this design learned from demanded that **every** key match (its SF-10), so a * half-filled object matched no branch at all and the editor showed the user nothing. */ export declare function matchBranch(branches: UnionBranch[], value: any): number; /** * The fields a schema describes, in declaration order. * * Slice 1 handles a flat object of scalars. Anything else — nested objects, arrays, unions — * comes back as `kind: 'unsupported'` **with a reason**, rather than being skipped. A field * that silently vanishes is indistinguishable from a schema that never mentioned it, and * that is precisely how an editor loses data. */ export declare function fieldsFor(schema: JSONSchema, prefix?: string): Node[]; /** Every leaf field in a tree, depth-first — what the component syncs values and errors for. */ export declare function leafFields(nodes: Node[]): Field[]; /** * The fields of the branch `value` currently matches, at the union's own path. * * The discriminator is dropped: the variant `