/** * Structure builder functions for organizing form elements. * * These functions create layout and conditional structures: * - `group()` - Visual grouping of fields * - `when()` - Conditional visibility based on field values * - `formspec()` - Top-level form specification */ import type { FormElement, Group, Conditional, FormSpec, Predicate } from "@formspec/core"; /** * Options for creating a form specification. * * @public */ export interface FormSpecOptions { /** * Whether to validate the form structure. * - `true` or `"warn"`: Validate and log warnings/errors to console * - `"throw"`: Validate and throw an error if validation fails * - `false`: Skip validation (default in production for performance) * * @defaultValue false */ validate?: boolean | "warn" | "throw"; /** * Optional name for the form (used in validation messages). */ name?: string; } /** * Creates a visual group of form elements. * * Groups provide visual organization and can be rendered as fieldsets or sections. * The nesting of groups defines the visual hierarchy of the form. * * @example * ```typescript * group("Customer Information", * field.text("name", { label: "Name" }), * field.text("email", { label: "Email" }), * ) * ``` * * @param label - The group's display label * @param elements - The form elements contained in this group * @returns A Group descriptor * * @public */ export declare function group(label: string, ...elements: Elements): Group; /** * Creates a conditional wrapper that shows elements based on a predicate. * * When the predicate evaluates to true, the contained elements are shown. * Otherwise, they are hidden (but still part of the schema). * * @example * ```typescript * import { is } from "@formspec/dsl"; * * field.enum("status", ["draft", "sent", "paid"] as const), * when(is("status", "draft"), * field.text("internalNotes", { label: "Internal Notes" }), * ) * ``` * * @param predicate - The condition to evaluate (use `is()` to create) * @param elements - The form elements to show when condition is met * @returns A Conditional descriptor * * @public */ export declare function when(predicate: Predicate, ...elements: Elements): Conditional; /** * Creates a complete form specification. * * The structure IS the definition: * - Nesting with `group()` defines visual layout * - Nesting with `when()` defines conditional visibility * - Field type implies control type (text field → text input) * - Array position implies field ordering * * Schema is automatically inferred from all fields in the structure. * * @example * ```typescript * const InvoiceForm = formspec( * group("Customer", * field.text("customerName", { label: "Customer Name" }), * field.dynamicEnum("country", "fetch_countries", { label: "Country" }), * ), * group("Invoice Details", * field.number("amount", { label: "Amount", min: 0 }), * field.enum("status", ["draft", "sent", "paid"] as const), * when(is("status", "draft"), * field.text("internalNotes", { label: "Internal Notes" }), * ), * ), * ); * ``` * * @param elements - The top-level form elements * @returns A FormSpec descriptor * * @public */ export declare function formspec(...elements: Elements): FormSpec; /** * Creates a complete form specification with validation options. * * @example * ```typescript * const form = formspecWithValidation( * { validate: true, name: "MyForm" }, * field.text("name"), * field.enum("status", ["draft", "sent"] as const), * when(is("status", "draft"), * field.text("notes"), * ), * ); * ``` * * @param options - Validation options * @param elements - The top-level form elements * @returns A FormSpec descriptor * * @public */ export declare function formspecWithValidation(options: FormSpecOptions, ...elements: Elements): FormSpec; //# sourceMappingURL=structure.d.ts.map