|
| 1 | +/** |
| 2 | + * @object-ui/core - Schema Builder |
| 3 | + * |
| 4 | + * Fluent API for building schemas programmatically. |
| 5 | + * Provides type-safe builder functions for common schema patterns. |
| 6 | + * |
| 7 | + * @module builder |
| 8 | + * @packageDocumentation |
| 9 | + */ |
| 10 | +import type { BaseSchema, FormSchema, FormField, CRUDSchema, TableColumn, ActionSchema, ButtonSchema, InputSchema, CardSchema, GridSchema, FlexSchema } from '@object-ui/types'; |
| 11 | +/** |
| 12 | + * Base builder class |
| 13 | + */ |
| 14 | +declare class SchemaBuilder<T extends BaseSchema> { |
| 15 | + protected schema: any; |
| 16 | + constructor(type: string); |
| 17 | + /** |
| 18 | + * Set the ID |
| 19 | + */ |
| 20 | + id(id: string): this; |
| 21 | + /** |
| 22 | + * Set the className |
| 23 | + */ |
| 24 | + className(className: string): this; |
| 25 | + /** |
| 26 | + * Set visibility |
| 27 | + */ |
| 28 | + visible(visible: boolean): this; |
| 29 | + /** |
| 30 | + * Set conditional visibility |
| 31 | + */ |
| 32 | + visibleOn(expression: string): this; |
| 33 | + /** |
| 34 | + * Set disabled state |
| 35 | + */ |
| 36 | + disabled(disabled: boolean): this; |
| 37 | + /** |
| 38 | + * Set test ID |
| 39 | + */ |
| 40 | + testId(testId: string): this; |
| 41 | + /** |
| 42 | + * Build the final schema |
| 43 | + */ |
| 44 | + build(): T; |
| 45 | +} |
| 46 | +/** |
| 47 | + * Form builder |
| 48 | + */ |
| 49 | +export declare class FormBuilder extends SchemaBuilder<FormSchema> { |
| 50 | + constructor(); |
| 51 | + /** |
| 52 | + * Add a field to the form |
| 53 | + */ |
| 54 | + field(field: FormField): this; |
| 55 | + /** |
| 56 | + * Add multiple fields |
| 57 | + */ |
| 58 | + fields(fields: FormField[]): this; |
| 59 | + /** |
| 60 | + * Set default values |
| 61 | + */ |
| 62 | + defaultValues(values: Record<string, any>): this; |
| 63 | + /** |
| 64 | + * Set submit label |
| 65 | + */ |
| 66 | + submitLabel(label: string): this; |
| 67 | + /** |
| 68 | + * Set form layout |
| 69 | + */ |
| 70 | + layout(layout: 'vertical' | 'horizontal'): this; |
| 71 | + /** |
| 72 | + * Set number of columns |
| 73 | + */ |
| 74 | + columns(columns: number): this; |
| 75 | + /** |
| 76 | + * Set submit handler |
| 77 | + */ |
| 78 | + onSubmit(handler: (data: Record<string, any>) => void | Promise<void>): this; |
| 79 | +} |
| 80 | +/** |
| 81 | + * CRUD builder |
| 82 | + */ |
| 83 | +export declare class CRUDBuilder extends SchemaBuilder<CRUDSchema> { |
| 84 | + constructor(); |
| 85 | + /** |
| 86 | + * Set resource name |
| 87 | + */ |
| 88 | + resource(resource: string): this; |
| 89 | + /** |
| 90 | + * Set API endpoint |
| 91 | + */ |
| 92 | + api(api: string): this; |
| 93 | + /** |
| 94 | + * Set title |
| 95 | + */ |
| 96 | + title(title: string): this; |
| 97 | + /** |
| 98 | + * Set description |
| 99 | + */ |
| 100 | + description(description: string): this; |
| 101 | + /** |
| 102 | + * Add a column |
| 103 | + */ |
| 104 | + column(column: TableColumn): this; |
| 105 | + /** |
| 106 | + * Set all columns |
| 107 | + */ |
| 108 | + columns(columns: TableColumn[]): this; |
| 109 | + /** |
| 110 | + * Set form fields |
| 111 | + */ |
| 112 | + fields(fields: FormField[]): this; |
| 113 | + /** |
| 114 | + * Enable create operation |
| 115 | + */ |
| 116 | + enableCreate(label?: string): this; |
| 117 | + /** |
| 118 | + * Enable update operation |
| 119 | + */ |
| 120 | + enableUpdate(label?: string): this; |
| 121 | + /** |
| 122 | + * Enable delete operation |
| 123 | + */ |
| 124 | + enableDelete(label?: string, confirmText?: string): this; |
| 125 | + /** |
| 126 | + * Set pagination |
| 127 | + */ |
| 128 | + pagination(pageSize?: number): this; |
| 129 | + /** |
| 130 | + * Enable row selection |
| 131 | + */ |
| 132 | + selectable(mode?: 'single' | 'multiple'): this; |
| 133 | + /** |
| 134 | + * Add a batch action |
| 135 | + */ |
| 136 | + batchAction(action: ActionSchema): this; |
| 137 | + /** |
| 138 | + * Add a row action |
| 139 | + */ |
| 140 | + rowAction(action: ActionSchema): this; |
| 141 | +} |
| 142 | +/** |
| 143 | + * Button builder |
| 144 | + */ |
| 145 | +export declare class ButtonBuilder extends SchemaBuilder<ButtonSchema> { |
| 146 | + constructor(); |
| 147 | + /** |
| 148 | + * Set button label |
| 149 | + */ |
| 150 | + label(label: string): this; |
| 151 | + /** |
| 152 | + * Set button variant |
| 153 | + */ |
| 154 | + variant(variant: 'default' | 'secondary' | 'destructive' | 'outline' | 'ghost' | 'link'): this; |
| 155 | + /** |
| 156 | + * Set button size |
| 157 | + */ |
| 158 | + size(size: 'default' | 'sm' | 'lg' | 'icon'): this; |
| 159 | + /** |
| 160 | + * Set button icon |
| 161 | + */ |
| 162 | + icon(icon: string): this; |
| 163 | + /** |
| 164 | + * Set click handler |
| 165 | + */ |
| 166 | + onClick(handler: () => void | Promise<void>): this; |
| 167 | + /** |
| 168 | + * Set loading state |
| 169 | + */ |
| 170 | + loading(loading: boolean): this; |
| 171 | +} |
| 172 | +/** |
| 173 | + * Input builder |
| 174 | + */ |
| 175 | +export declare class InputBuilder extends SchemaBuilder<InputSchema> { |
| 176 | + constructor(); |
| 177 | + /** |
| 178 | + * Set field name |
| 179 | + */ |
| 180 | + name(name: string): this; |
| 181 | + /** |
| 182 | + * Set label |
| 183 | + */ |
| 184 | + label(label: string): this; |
| 185 | + /** |
| 186 | + * Set placeholder |
| 187 | + */ |
| 188 | + placeholder(placeholder: string): this; |
| 189 | + /** |
| 190 | + * Set input type |
| 191 | + */ |
| 192 | + inputType(type: 'text' | 'email' | 'password' | 'number' | 'tel' | 'url'): this; |
| 193 | + /** |
| 194 | + * Mark as required |
| 195 | + */ |
| 196 | + required(required?: boolean): this; |
| 197 | + /** |
| 198 | + * Set default value |
| 199 | + */ |
| 200 | + defaultValue(value: string | number): this; |
| 201 | +} |
| 202 | +/** |
| 203 | + * Card builder |
| 204 | + */ |
| 205 | +export declare class CardBuilder extends SchemaBuilder<CardSchema> { |
| 206 | + constructor(); |
| 207 | + /** |
| 208 | + * Set card title |
| 209 | + */ |
| 210 | + title(title: string): this; |
| 211 | + /** |
| 212 | + * Set card description |
| 213 | + */ |
| 214 | + description(description: string): this; |
| 215 | + /** |
| 216 | + * Set card content |
| 217 | + */ |
| 218 | + content(content: BaseSchema | BaseSchema[]): this; |
| 219 | + /** |
| 220 | + * Set card variant |
| 221 | + */ |
| 222 | + variant(variant: 'default' | 'outline' | 'ghost'): this; |
| 223 | + /** |
| 224 | + * Make card hoverable |
| 225 | + */ |
| 226 | + hoverable(hoverable?: boolean): this; |
| 227 | +} |
| 228 | +/** |
| 229 | + * Grid builder |
| 230 | + */ |
| 231 | +export declare class GridBuilder extends SchemaBuilder<GridSchema> { |
| 232 | + constructor(); |
| 233 | + /** |
| 234 | + * Set number of columns |
| 235 | + */ |
| 236 | + columns(columns: number): this; |
| 237 | + /** |
| 238 | + * Set gap |
| 239 | + */ |
| 240 | + gap(gap: number): this; |
| 241 | + /** |
| 242 | + * Add a child |
| 243 | + */ |
| 244 | + child(child: BaseSchema): this; |
| 245 | + /** |
| 246 | + * Set all children |
| 247 | + */ |
| 248 | + children(children: BaseSchema[]): this; |
| 249 | +} |
| 250 | +/** |
| 251 | + * Flex builder |
| 252 | + */ |
| 253 | +export declare class FlexBuilder extends SchemaBuilder<FlexSchema> { |
| 254 | + constructor(); |
| 255 | + /** |
| 256 | + * Set flex direction |
| 257 | + */ |
| 258 | + direction(direction: 'row' | 'col' | 'row-reverse' | 'col-reverse'): this; |
| 259 | + /** |
| 260 | + * Set justify content |
| 261 | + */ |
| 262 | + justify(justify: 'start' | 'end' | 'center' | 'between' | 'around' | 'evenly'): this; |
| 263 | + /** |
| 264 | + * Set align items |
| 265 | + */ |
| 266 | + align(align: 'start' | 'end' | 'center' | 'baseline' | 'stretch'): this; |
| 267 | + /** |
| 268 | + * Set gap |
| 269 | + */ |
| 270 | + gap(gap: number): this; |
| 271 | + /** |
| 272 | + * Add a child |
| 273 | + */ |
| 274 | + child(child: BaseSchema): this; |
| 275 | + /** |
| 276 | + * Set all children |
| 277 | + */ |
| 278 | + children(children: BaseSchema[]): this; |
| 279 | +} |
| 280 | +export declare const form: () => FormBuilder; |
| 281 | +export declare const crud: () => CRUDBuilder; |
| 282 | +export declare const button: () => ButtonBuilder; |
| 283 | +export declare const input: () => InputBuilder; |
| 284 | +export declare const card: () => CardBuilder; |
| 285 | +export declare const grid: () => GridBuilder; |
| 286 | +export declare const flex: () => FlexBuilder; |
| 287 | +export {}; |
0 commit comments