/** * Schema field types used by DataTable, DataPreview, useSchemaField and elementUtils. * (The BagelForm form-rendering system was removed — use FormFlow with defineSchema.) */ import type { Paths, Get, OmitIndexSignature } from 'type-fest' import type { ToString } from 'type-fest/source/internal' import type { LiteralStringUnion } from 'type-fest/source/literal-union' import type { PathsOptions, DefaultPathsOptions } from 'type-fest/source/paths' import type { VNode } from 'vue' // BagelInputShellProps is exported from components/form/inputs/bagelInputShell.ts // Do not re-export here to avoid duplicate export in src/index.ts import type { BagelInputShellProps } from '../components/form/inputs/bagelInputShell' interface Option { label: string, value: any } // ---------- Path resolution ---------- export type _Path< T, PO extends PathsOptions = DefaultPathsOptions, > = ToString, PO>> // Helper type to get paths for index signature properties type IndexSignaturePaths = { [K in keyof T]: T[K] extends { [key: string]: any } ? `${K & string}.${string}` : never }[keyof T] // Enhanced Path type that allows flexibility for nested open-ended objects export type Path = FieldVal> extends Array ? LiteralStringUnion<_Path> : _Path | IndexSignaturePaths | `${keyof T & string}.more_info.${string}` /** The value type at path P in object T. Falls back to unknown if resolution fails. */ export type FieldVal> = unknown extends Get ? unknown : Get /** Field value type that preserves type information when possible. */ export type SmartFieldVal> = P extends string ? P extends keyof T ? T[P] : any : FieldVal // ---------- Field callbacks & attributes ---------- export type AttributeValue = | string | number | boolean | undefined | { [key: string]: any } export type AttributeFn> = ( field: SmartFieldVal, row?: T ) => AttributeValue export interface Attributes> { [key: string]: AttributeValue | AttributeFn } export type FieldOptions> = | string | ( | { label?: string value: string | number } | string | number | boolean | { [key: string]: any } )[] | ((val?: SmartFieldVal, rowData?: T) => Option[] | ((query: string) => Promise)) | ((query: string, val?: SmartFieldVal, rowData?: T) => Promise) export type VIfType> = | string | boolean | ((val?: SmartFieldVal, rowData?: T) => boolean) export type ValidationFn> = ( val?: SmartFieldVal, rowData?: T ) => string | undefined export type TransformFn> = ( val?: SmartFieldVal, rowData?: T ) => any export type UpdateFn> = ( val?: SmartFieldVal, rowData?: T ) => unknown // ---------- Schema fields ---------- export type VNodeFn> = (props: { row?: T field: BaseBagelField }) => VNode export interface ElementField< T, PO extends PathsOptions = DefaultPathsOptions, > { $el: any id?: Path | string class?: any vIf?: any style?: Record attrs?: Record onClick?: (val?: any, rowData?: T) => void transform?: (val?: any, rowData?: T) => any children?: ElementField[] } // Helper type to extract all possible BaseBagelField types for valid paths type ValidBaseBagelField = { [P in Path]: BaseBagelField }[Path] export type SchemaChild< T, P extends Path, PO extends PathsOptions = DefaultPathsOptions, > = Field | ElementField | VNode | VNodeFn | string | ValidBaseBagelField export interface BaseBagelField< T, P extends Path, PO extends PathsOptions = DefaultPathsOptions, > { '$el'?: string | any 'id'?: P 'label'?: string 'placeholder'?: string 'class'?: AttributeValue | AttributeFn 'attrs'?: Attributes 'required'?: boolean 'disabled'?: boolean 'helptext'?: string 'options'?: FieldOptions 'children'?: SchemaChild, PO>[] 'slots'?: { [key: string]: SchemaChild, PO>[] } 'defaultValue'?: any 'vIf'?: VIfType 'v-if'?: VIfType 'transform'?: TransformFn 'onUpdate'?: UpdateFn 'validate'?: ValidationFn } export type Field< T, PO extends PathsOptions = DefaultPathsOptions, > = ValidBaseBagelField export type SchemaField< T, PO extends PathsOptions = DefaultPathsOptions, > = Field | ElementField export type BglFormSchemaT< T, PO extends PathsOptions = DefaultPathsOptions, > = (SchemaField | BaseBagelField, PO>)[] // ---------- Input component contracts ---------- export interface ValidateInputBaseT { validate?: ValidationFn<{ [key: string]: unknown }, string> getFormData?: () => any } export interface UploadInputProps extends BagelInputShellProps { id?: string name?: string label?: string multiple?: boolean modelValue?: string | string[] width?: string height?: string | 'auto' dirPath?: string fill?: boolean oval?: boolean theme?: 'dropzone' | 'basic' accept?: string capture?: boolean | 'user' | 'environment' required?: boolean disabled?: boolean baseURL?: string placeholder?: string /** Alias for dropzone placeholder text (same as `placeholder` when theme is dropzone). */ dropPlaceholder?: string noFilePlaceholder?: string btnPlaceholder?: string error?: string showIcon?: boolean icon?: string iconSize?: number | string iconMobileSize?: number | string }