import type { ComputedRef, InjectionKey, Ref } from "vue"; export type ValidationBehavior = "native" | "aria"; export type ValidationErrors = Record; export type ValidateResult = string | string[] | true | null | undefined; export type FieldPart = "description" | "error" | "label"; export interface FieldContext { controlId: ComputedRef; kind: "text" | "toggle" | "group"; disabled: ComputedRef; readOnly: ComputedRef; required: ComputedRef; invalid: ComputedRef; errors: ComputedRef; validationDetails?: ComputedRef; labelIds?: Ref; descriptionIds: Ref; errorIds: Ref; } export const fieldContextKey: InjectionKey = Symbol("HeroUIVue.Field"); export interface FormContext { validationBehavior: ComputedRef; validationErrors: ComputedRef; } export const formContextKey: InjectionKey = Symbol("HeroUIVue.Form"); export function mergeIds(...values: (string | string[] | undefined)[]) { const ids = values .flatMap((value) => typeof value === "string" ? value.split(/\s+/) : (value ?? []), ) .filter(Boolean); return [...new Set(ids)].join(" ") || undefined; } export function errorMessages(result: ValidateResult | false): string[] { return ( typeof result === "string" ? [result] : Array.isArray(result) ? result : [] ).filter(Boolean); }