import { Component, Ref } from "vue"; import { FormFieldDef, FormUnionVariant, TFormAction, TFormEntryOptions, ValueHelpInfo } from "@atscript/ui"; //#region src/components/types.d.ts /** * Shared base props available to all custom form components. */ interface TAsBaseComponentProps { /** Whether this component is disabled. */ disabled?: boolean; /** Whether this component is hidden. */ hidden?: boolean; } /** * Props contract for custom field components used with `AsForm` / `AsField`. * * Implement this interface in your UI components so that `AsField` can pass * all resolved field state (value, label, validation errors, etc.) as props. * * @typeParam V - The field value type * @typeParam TFormData - The full form data object type * @typeParam TFormContext - The external context object type */ interface TAsComponentProps extends TAsBaseComponentProps { /** Called on field blur — triggers validation. */ onBlur: () => void; /** Validation error message for this field, if any. */ error?: string; /** Reactive model wrapping the field value. Bind with `v-model="model.value"`. */ model: { value: V; }; /** Phantom field display value from `@meta.default` / `@ui.form.fn.value` (paragraphs, actions). `undefined` for data fields. */ value?: unknown; /** Resolved field label from `@meta.label` or `@ui.form.fn.label`. */ label?: string; /** Resolved field description from `@meta.description` or `@ui.form.fn.description`. */ description?: string; /** Resolved hint text from `@ui.form.hint` or `@ui.form.fn.hint`. */ hint?: string; /** Resolved placeholder from `@ui.form.placeholder` or `@ui.form.fn.placeholder`. */ placeholder?: string; /** Resolved CSS class painting the prefix icon glyph from `@ui.form.prefix.icon`. Consumer manages safelist / preset coverage. Rendered as the leftmost adornment, before the `prefix` text. */ prefixIcon?: string; /** Resolved CSS class painting the suffix icon glyph from `@ui.form.suffix.icon`. Consumer manages safelist / preset coverage. Rendered as the rightmost adornment, after the `suffix` text. */ suffixIcon?: string; /** CSS class(es) from `@ui.form.classes` or `@ui.form.fn.classes`. */ class?: Record | string; /** Inline styles from `@ui.form.styles` or `@ui.form.fn.styles`. */ style?: Record | string; /** Whether the field is optional (not required). */ optional?: boolean | undefined; /** Toggle an optional field on/off. `true` sets default value; `false` sets `undefined`. Only present when `optional` is true. */ onToggleOptional?: (enabled: boolean) => void; /** Whether the field is required (inverse of optional). */ required?: boolean | undefined; /** Whether the field is read-only. */ readonly?: boolean | undefined; /** The resolved field input type (e.g., `'text'`, `'select'`, `'checkbox'`). */ type: string; /** Form action from `@ui.form.action`. Contains the action id and display label. */ formAction?: TFormAction; /** The field name (last segment of the dot-separated path). */ name?: string; /** The full FormFieldDef for advanced use cases. */ field?: FormFieldDef; /** Resolved options for select/radio/checkbox fields. */ options?: TFormEntryOptions[]; /** Max length constraint from `@expect.maxLength`. */ maxLength?: number; /** Autocomplete hint from `@ui.form.autocomplete`. */ autocomplete?: string; /** Resolved title from `@ui.form.fn.title` / `@meta.label` for structure/array fields. */ title?: string; /** Nesting level for structure/array fields. Root structure is 0, each nested structure/array increments by 1. */ level?: number; /** Callback to remove this item from its parent array. Present when rendered inside an array. */ onRemove?: () => void; /** Whether removal is allowed (respects minLength constraints). */ canRemove?: boolean; /** Label for the remove button (from `@ui.array.remove.label`). */ removeLabel?: string; /** Zero-based index when rendered as a direct array item. `undefined` otherwise. */ arrayIndex?: number; /** Absolute dotted path to this field inside the form data. Empty string at the root. */ path: string; /** Resolved value-help descriptor for FK ref fields (`@db.rel.FK` → `@db.http.path`). */ valueHelp?: ValueHelpInfo; /** Singular label for array fields (`@ui.form.label.singular`) — used in "Add " affordances. */ singularLabel?: string; /** Stable input element id, suitable for `