@dragonmastery/zinia-forms-core 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -139,6 +139,422 @@ interface CheckboxFieldProps<FormType> {
139
139
  variant?: string;
140
140
  }
141
141
 
142
+ interface DateFieldProps<FormType> {
143
+ name: FlexiblePath<FormType>;
144
+ label?: string;
145
+ hideLabel?: boolean;
146
+ description?: string;
147
+ required?: boolean;
148
+ placeholder?: string;
149
+ disabled?: boolean;
150
+ readonly?: boolean;
151
+ class?: string | string[];
152
+ size?: string;
153
+ variant?: string;
154
+ min?: string;
155
+ max?: string;
156
+ formatter?: (date: string) => unknown;
157
+ }
158
+
159
+ interface NumberFieldProps<FormType> {
160
+ name: FlexiblePath<FormType>;
161
+ label?: string;
162
+ hideLabel?: boolean;
163
+ description?: string;
164
+ required?: boolean;
165
+ placeholder?: string;
166
+ disabled?: boolean;
167
+ readonly?: boolean;
168
+ class?: string | string[];
169
+ size?: string;
170
+ variant?: string;
171
+ min?: number;
172
+ max?: number;
173
+ step?: number;
174
+ }
175
+
176
+ /**
177
+ * Option item for select fields
178
+ * @template TData - Type of the optional data object for storing additional metadata
179
+ * Useful for cascading dropdowns where options need to be filtered by parent field values
180
+ *
181
+ * @example
182
+ * // With typed data
183
+ * interface CityData {
184
+ * country: string;
185
+ * population: number;
186
+ * }
187
+ * const options: SelectOption<CityData>[] = [
188
+ * { value: 'nyc', label: 'New York', data: { country: 'usa', population: 8000000 } }
189
+ * ];
190
+ *
191
+ * @example
192
+ * // Without data (backward compatible)
193
+ * const options: SelectOption[] = [
194
+ * { value: 'option1', label: 'Option 1' }
195
+ * ];
196
+ */
197
+ interface SelectOption<TData = Record<string, any>> {
198
+ value: string;
199
+ label: string;
200
+ /**
201
+ * Optional data object for storing additional metadata
202
+ * Useful for cascading dropdowns where options need to be filtered by parent field values
203
+ */
204
+ data?: TData;
205
+ }
206
+ /**
207
+ * Extract enum values from a Zod enum schema
208
+ */
209
+ type ZodEnumValues<T extends z.ZodEnum<[string, ...string[]]>> = T['_def']['values'][number];
210
+ /**
211
+ * Type for a mapping of enum values to labels
212
+ */
213
+ type EnumValueToLabelMap<T extends string> = Record<T, string>;
214
+ /**
215
+ * Type for a value-to-label mapping that can be either a function or an object map
216
+ */
217
+ type ValueToLabelMapping<T extends string = string> = ((value: string) => string) | EnumValueToLabelMap<T>;
218
+ /**
219
+ * Helper type to extract the type of a field at a given path
220
+ */
221
+ type FieldType<T, P extends string> = P extends keyof T ? T[P] : P extends `${infer A}.${infer B}` ? A extends keyof T ? FieldType<T[A], B> : never : never;
222
+ /**
223
+ * Helper type to extract enum values from a field type
224
+ */
225
+ type EnumValuesFromField<T> = T extends string ? T : never;
226
+ /**
227
+ * Type that maps field paths to their corresponding enum types
228
+ */
229
+ type FieldPathToEnum$1<T, P extends Path<T>> = EnumValuesFromField<FieldType<T, P & string>>;
230
+ /**
231
+ * Props for the SelectField component
232
+ * @template FormType - The form type
233
+ * @template P - The field path in the form
234
+ * @template TData - The type of the data property in SelectOption (for cascading dropdowns)
235
+ */
236
+ interface SelectFieldProps<FormType, P extends Path<FormType> = Path<FormType>, TData = any> {
237
+ /**
238
+ * Field name (path in the form state)
239
+ * Accepts both static paths and dynamic paths for use in array fields
240
+ */
241
+ name: FlexiblePath<FormType>;
242
+ /**
243
+ * Field label
244
+ */
245
+ label?: string;
246
+ /**
247
+ * Whether to hide the label
248
+ */
249
+ hideLabel?: boolean;
250
+ /**
251
+ * Field description
252
+ */
253
+ description?: string;
254
+ /**
255
+ * Whether the field is required
256
+ */
257
+ required?: boolean;
258
+ /**
259
+ * Placeholder text
260
+ */
261
+ placeholder?: string;
262
+ /**
263
+ * Whether the field is disabled
264
+ */
265
+ disabled?: boolean;
266
+ /**
267
+ * Whether the field is readonly
268
+ */
269
+ readonly?: boolean;
270
+ /**
271
+ * CSS classes to apply to the field
272
+ */
273
+ class?: string | string[];
274
+ /**
275
+ * Field size
276
+ */
277
+ size?: string;
278
+ /**
279
+ * Field variant
280
+ */
281
+ variant?: string;
282
+ /**
283
+ * Select options (overrides options from schema)
284
+ * Using selectOptions instead of options to avoid conflicts with HTML select element
285
+ *
286
+ * @example
287
+ * // With typed data
288
+ * interface CityData { country: string; }
289
+ * const options: SelectOption<CityData>[] = [
290
+ * { value: 'nyc', label: 'New York', data: { country: 'usa' } }
291
+ * ];
292
+ */
293
+ selectOptions?: SelectOption<TData>[];
294
+ /**
295
+ * Custom mapping function to convert values to labels
296
+ * This is useful when you want to customize how labels are displayed
297
+ * without providing a full options array
298
+ *
299
+ * Can be provided as either:
300
+ * 1. A function that takes a value and returns a label
301
+ * 2. An object map where keys are enum values and values are labels
302
+ */
303
+ valueToLabel?: ValueToLabelMapping<FieldPathToEnum$1<FormType, P>>;
304
+ /**
305
+ * Whether to use options from the schema (default: true)
306
+ * Set to false to ignore schema options even when no options prop is provided
307
+ */
308
+ useSchemaOptions?: boolean;
309
+ /**
310
+ * Field path that this field depends on for cascading dropdowns
311
+ * When the parent field changes, this field's options will be filtered
312
+ * and the field will be reset (unless autoReset is false)
313
+ *
314
+ * @example
315
+ * // City field depends on country field
316
+ * <SelectField name="city" dependsOn="country" :optionFilterFn="filterCitiesByCountry" />
317
+ */
318
+ dependsOn?: FlexiblePath<FormType>;
319
+ /**
320
+ * Function to filter options based on the parent field's value
321
+ * Receives the parent field value and all available options
322
+ * Should return the filtered options array
323
+ *
324
+ * The function signature is tied to the TData type parameter, ensuring type safety
325
+ * between selectOptions and optionFilterFn
326
+ *
327
+ * @example
328
+ * // With typed data - both props must use the same data type
329
+ * interface CityData { country: string; }
330
+ * const filterCitiesByCountry = (
331
+ * countryValue: string,
332
+ * allOptions: SelectOption<CityData>[]
333
+ * ): SelectOption<CityData>[] => {
334
+ * return allOptions.filter(opt => opt.data?.country === countryValue);
335
+ * };
336
+ *
337
+ * @example
338
+ * // Without typed data (backward compatible)
339
+ * const filterCitiesByCountry = (
340
+ * countryValue: string,
341
+ * allOptions: SelectOption[]
342
+ * ): SelectOption[] => {
343
+ * return allOptions.filter(opt => opt.value.startsWith(countryValue));
344
+ * };
345
+ */
346
+ optionFilterFn?: (parentValue: any, allOptions: SelectOption<TData>[]) => SelectOption<TData>[];
347
+ /**
348
+ * Whether to automatically reset this field when the parent field changes (default: true)
349
+ * Set to false if you want to preserve the value when parent changes
350
+ */
351
+ autoReset?: boolean;
352
+ }
353
+ /**
354
+ * Array of prop names for SelectField component.
355
+ * This is derived from SelectFieldProps interface and ensures type safety.
356
+ * Used for prop normalization and filtering in component implementations.
357
+ *
358
+ * TypeScript ensures all entries are valid keys of SelectFieldProps.
359
+ */
360
+ declare const SELECT_FIELD_PROP_NAMES: readonly ["name", "selectOptions", "placeholder", "disabled", "readonly", "class", "label", "hideLabel", "description", "required", "size", "variant", "valueToLabel", "useSchemaOptions", "dependsOn", "optionFilterFn", "autoReset"];
361
+
362
+ /**
363
+ * Type to convert underscores to PascalCase
364
+ * This helper type processes a single segment by capitalizing after underscores
365
+ */
366
+ type SegmentToPascalCase<S extends string> = S extends `${infer First}_${infer Rest}` ? `${Capitalize<First>}${SegmentToPascalCase<Rest>}` : Capitalize<S>;
367
+ /**
368
+ * Type to convert a dot-separated path to PascalCase
369
+ * This uses recursion to handle any level of nesting
370
+ * Also handles underscores by removing them and capitalizing each segment
371
+ */
372
+ type PathToPascalCase<P extends string> = P extends `${infer A}.${infer B}` ? `${SegmentToPascalCase<A>}${PathToPascalCase<B>}` : `${SegmentToPascalCase<P>}Field`;
373
+ /**
374
+ * Type that maps field paths to their corresponding enum types
375
+ */
376
+ type FieldPathToEnum<T, P extends Path<T>> = P extends keyof T ? T[P] extends string ? T[P] : string : string;
377
+ /**
378
+ * Type that extracts the array element type from a field path
379
+ * If the path points to an array, it extracts the element type
380
+ * @example
381
+ * ArrayItemType<{users: User[]}, 'users'> = User
382
+ * ArrayItemType<{tasks: Task[]}, 'tasks'> = Task
383
+ */
384
+ type ArrayItemType<T, P extends Path<T>> = P extends keyof T ? T[P] extends ReadonlyArray<infer Item> ? Item : T[P] extends Array<infer Item> ? Item : never : never;
385
+ /**
386
+ * Type for array field components with properly typed slots
387
+ */
388
+ type ArrayFieldComponent<T, P extends Path<T>> = vue.FunctionalComponent<Omit<ArrayFieldProps<T, ArrayItemType<T, P>>, 'name'>, {}, {
389
+ itemRenderer: (props: {
390
+ item: ArrayItemType<T, P>;
391
+ index: number;
392
+ getFieldName: (fieldPath: string) => string;
393
+ }) => any;
394
+ availableItemRenderer: (props: {
395
+ item: ArrayItemType<T, P>;
396
+ index: number;
397
+ }) => any;
398
+ default: () => any;
399
+ }, {}>;
400
+ /**
401
+ * Type for enum field components that require valueToLabel
402
+ */
403
+ type EnumFieldComponent<T, P extends Path<T>> = (props: Omit<SelectFieldProps<T>, 'name' | 'valueToLabel'> & {
404
+ valueToLabel: Record<FieldPathToEnum<T, P>, string>;
405
+ }, context?: any) => any;
406
+ /**
407
+ * Type for select field components (can work with string or enum fields)
408
+ * Uses SelectFieldProps<T, P, TData> to preserve path-specific typing for props like dependsOn
409
+ * and ensure type safety between selectOptions and optionFilterFn
410
+ */
411
+ type SelectFieldComponent<T, P extends Path<T>> = <TData = any>(props: Omit<SelectFieldProps<T, P, TData>, 'name'>, context?: any) => any;
412
+ /**
413
+ * Type for number field components
414
+ */
415
+ type NumberFieldComponent<T> = (props: Omit<NumberFieldProps<T>, 'name'>, context?: any) => any;
416
+ /**
417
+ * Type for checkbox field components
418
+ */
419
+ type CheckboxFieldComponent<T> = (props: Omit<CheckboxFieldProps<T>, 'name'>, context?: any) => any;
420
+ /**
421
+ * Type for date field components
422
+ */
423
+ type DateFieldComponent<T> = (props: Omit<DateFieldProps<T>, 'name'>, context?: any) => any;
424
+ /**
425
+ * Generic field component type - fallback for any other field types
426
+ */
427
+ type GenericFieldComponent = (props: any, context?: any) => any;
428
+ /**
429
+ * Helper to unwrap optional/nullable types
430
+ * Removes undefined and null from union types
431
+ * Examples:
432
+ * string | undefined → string
433
+ * string | null → string
434
+ * string | undefined | null → string
435
+ */
436
+ type UnwrapOptional<T> = Exclude<T, undefined | null>;
437
+ /**
438
+ * Maps a field path to its component type based on the field's actual type
439
+ * Enums are explicitly passed as FieldType = 'enum' since they can't be auto-detected
440
+ * Everything else is inferred from the actual TypeScript type at the path
441
+ *
442
+ * For string fields, we use SelectFieldComponent<T, P> which is a superset that includes
443
+ * all TextField functionality plus additional props like dependsOn for cascading dropdowns.
444
+ * This provides better type safety and autocomplete.
445
+ */
446
+ type FieldComponentType<T, P extends Path<T>, FieldType extends string = 'string'> = FieldType extends 'enum' ? EnumFieldComponent<T, P> : P extends keyof T ? UnwrapOptional<T[P]> extends Array<any> | ReadonlyArray<any> ? ArrayFieldComponent<T, P> : UnwrapOptional<T[P]> extends number ? NumberFieldComponent<T> : UnwrapOptional<T[P]> extends boolean ? CheckboxFieldComponent<T> : UnwrapOptional<T[P]> extends Date ? DateFieldComponent<T> : UnwrapOptional<T[P]> extends string ? SelectFieldComponent<T, P> : GenericFieldComponent : GenericFieldComponent;
447
+ /**
448
+ * Type for the components object with PascalCase keys derived from field paths
449
+ * Each component gets the right type based on what the field actually is
450
+ */
451
+ type ComponentsType<T> = {
452
+ [K in Path<T> as PathToPascalCase<K & string>]: FieldComponentType<T, K>;
453
+ };
454
+
455
+ /**
456
+ * Types for field metadata in the form system
457
+ */
458
+ /**
459
+ * Metadata about a form field
460
+ * This interface defines all the properties that describe a field's behavior and appearance
461
+ */
462
+ interface FieldMetadata {
463
+ /** The full path to the field (e.g., 'user.firstName') */
464
+ path: string;
465
+ /** Whether the field is required (false if optional) */
466
+ isRequired: boolean;
467
+ /** The data type of the field */
468
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'enum' | 'date' | 'union';
469
+ /** The input type for rendering the field */
470
+ inputType?: 'text' | 'email' | 'url' | 'tel' | 'number' | 'select' | 'checkbox' | 'radio' | 'textarea' | 'password' | 'array' | 'currency' | 'date' | 'time' | 'datetime-local' | 'file' | 'range' | 'search' | 'combobox';
471
+ /** The display label for the field */
472
+ label?: string;
473
+ /** Placeholder text for the field */
474
+ placeholder?: string;
475
+ /** Minimum value (for number fields) or length (for string/array fields) */
476
+ min?: number;
477
+ /** Maximum value (for number fields) or length (for string/array fields) */
478
+ max?: number;
479
+ /** Regular expression pattern for validation */
480
+ pattern?: RegExp;
481
+ /** Options for enum fields */
482
+ options?: Array<{
483
+ value: string;
484
+ label: string;
485
+ }>;
486
+ /** Default value for the field */
487
+ defaultValue?: any;
488
+ /** Whether the field is an array */
489
+ isArray?: boolean;
490
+ /** Metadata for array element type */
491
+ arrayOf?: FieldMetadata;
492
+ /** Child field metadata for object types */
493
+ children?: Record<string, FieldMetadata>;
494
+ /** Available items for array fields */
495
+ availableItems?: any[];
496
+ /** Help text to display with the field */
497
+ helpText?: string;
498
+ /** For textarea fields, number of rows to display */
499
+ rows?: number;
500
+ /** For textarea fields, number of columns to display */
501
+ cols?: number;
502
+ /** For enum fields, map values to display labels */
503
+ valueToLabel?: Record<string, string>;
504
+ /** Whether the field should be disabled */
505
+ disabled?: boolean;
506
+ /** Whether the field should be hidden */
507
+ hidden?: boolean;
508
+ /** CSS class to apply to the field */
509
+ className?: string;
510
+ /** Whether the field should be focused on load */
511
+ autofocus?: boolean;
512
+ /** For number fields, the step value */
513
+ step?: number;
514
+ /** Autocomplete attribute for the field */
515
+ autocomplete?: string;
516
+ }
517
+
518
+ /**
519
+ * Types for schema metadata in the form system
520
+ */
521
+
522
+ /**
523
+ * Additional metadata that can be associated with schema fields
524
+ * This interface defines properties that can be attached to schema fields
525
+ * to customize their behavior and appearance
526
+ */
527
+ interface SchemaFieldMetadata {
528
+ /** The input type for rendering the field */
529
+ inputType?: 'text' | 'email' | 'tel' | 'number' | 'select' | 'checkbox' | 'radio' | 'textarea' | 'password' | 'currency' | 'date' | 'time' | 'datetime-local' | 'combobox';
530
+ /** Placeholder text for the field */
531
+ placeholder?: string;
532
+ /** The display label for the field */
533
+ label?: string;
534
+ /** Help text to display with the field */
535
+ helpText?: string;
536
+ /** For textarea fields, number of rows to display */
537
+ rows?: number;
538
+ /** For textarea fields, number of columns to display */
539
+ cols?: number;
540
+ /** For enum fields, map values to display labels */
541
+ valueToLabel?: Record<string, string>;
542
+ /** Whether to hide validation errors */
543
+ hideError?: boolean;
544
+ /** Step value for numeric fields */
545
+ step?: number;
546
+ /** Any other custom properties */
547
+ [key: string]: any;
548
+ }
549
+ /**
550
+ * Type for the registry mapping field paths to their metadata
551
+ */
552
+ type MetadataRegistry = Record<string, SchemaFieldMetadata>;
553
+ /**
554
+ * Type helper to extract all possible paths from a Zod schema
555
+ */
556
+ type PathsOf<T extends z.ZodTypeAny> = Path<z.infer<T>>;
557
+
142
558
  /**
143
559
  * Option item for combobox fields - can be a string or label/value object
144
560
  */
@@ -219,6 +635,14 @@ interface ComboboxFieldProps<FormType, P extends Path<FormType> = Path<FormType>
219
635
  */
220
636
  filterFn?: (query: string, option: ComboboxOption) => boolean;
221
637
  }
638
+ /**
639
+ * Array of prop names for ComboboxField component.
640
+ * This is derived from ComboboxFieldProps interface and ensures type safety.
641
+ * Used for prop normalization and filtering in component implementations.
642
+ *
643
+ * TypeScript ensures all entries are valid keys of ComboboxFieldProps.
644
+ */
645
+ declare const COMBOBOX_FIELD_PROP_NAMES: readonly ["name", "options", "placeholder", "disabled", "readonly", "class", "label", "hideLabel", "description", "required", "size", "variant", "allowCreate", "filterFn"];
222
646
 
223
647
  interface CurrencyFieldProps<FormType> {
224
648
  name: FlexiblePath<FormType>;
@@ -237,23 +661,6 @@ interface CurrencyFieldProps<FormType> {
237
661
  step?: number;
238
662
  }
239
663
 
240
- interface DateFieldProps<FormType> {
241
- name: FlexiblePath<FormType>;
242
- label?: string;
243
- hideLabel?: boolean;
244
- description?: string;
245
- required?: boolean;
246
- placeholder?: string;
247
- disabled?: boolean;
248
- readonly?: boolean;
249
- class?: string | string[];
250
- size?: string;
251
- variant?: string;
252
- min?: string;
253
- max?: string;
254
- formatter?: (date: string) => unknown;
255
- }
256
-
257
664
  interface DateTimeLocalFieldProps<FormType> {
258
665
  name: FlexiblePath<FormType>;
259
666
  label?: string;
@@ -342,23 +749,6 @@ interface FormProps<FormType> {
342
749
  children?: any;
343
750
  }
344
751
 
345
- interface NumberFieldProps<FormType> {
346
- name: FlexiblePath<FormType>;
347
- label?: string;
348
- hideLabel?: boolean;
349
- description?: string;
350
- required?: boolean;
351
- placeholder?: string;
352
- disabled?: boolean;
353
- readonly?: boolean;
354
- class?: string | string[];
355
- size?: string;
356
- variant?: string;
357
- min?: number;
358
- max?: number;
359
- step?: number;
360
- }
361
-
362
752
  interface PasswordFieldProps<FormType> {
363
753
  name: FlexiblePath<FormType>;
364
754
  label?: string;
@@ -398,135 +788,37 @@ interface RangeFieldProps<FormType> {
398
788
  hideLabel?: boolean;
399
789
  description?: string;
400
790
  required?: boolean;
401
- disabled?: boolean;
402
- readonly?: boolean;
403
- class?: string | string[];
404
- size?: string;
405
- variant?: string;
406
- min?: number;
407
- max?: number;
408
- step?: number;
409
- showValue?: boolean;
410
- }
411
-
412
- interface ResetButtonProps<FormType> {
413
- resetText?: string;
414
- className?: string;
415
- disabled?: boolean;
416
- onReset?: () => void;
417
- }
418
-
419
- interface SearchFieldProps<FormType> {
420
- name: FlexiblePath<FormType>;
421
- label?: string;
422
- hideLabel?: boolean;
423
- description?: string;
424
- required?: boolean;
425
- placeholder?: string;
426
- disabled?: boolean;
427
- readonly?: boolean;
428
- autocomplete?: string;
429
- class?: string | string[];
430
- size?: string;
431
- variant?: string;
432
- }
433
-
434
- /**
435
- * Option item for select fields
436
- */
437
- interface SelectOption {
438
- value: string;
439
- label: string;
440
- }
441
- /**
442
- * Type for a mapping of enum values to labels
443
- */
444
- type EnumValueToLabelMap<T extends string> = Record<T, string>;
445
- /**
446
- * Type for a value-to-label mapping that can be either a function or an object map
447
- */
448
- type ValueToLabelMapping<T extends string = string> = ((value: string) => string) | EnumValueToLabelMap<T>;
449
- /**
450
- * Helper type to extract the type of a field at a given path
451
- */
452
- type FieldType<T, P extends string> = P extends keyof T ? T[P] : P extends `${infer A}.${infer B}` ? A extends keyof T ? FieldType<T[A], B> : never : never;
453
- /**
454
- * Helper type to extract enum values from a field type
455
- */
456
- type EnumValuesFromField<T> = T extends string ? T : never;
457
- /**
458
- * Type that maps field paths to their corresponding enum types
459
- */
460
- type FieldPathToEnum$1<T, P extends Path<T>> = EnumValuesFromField<FieldType<T, P & string>>;
461
- /**
462
- * Props for the SelectField component
463
- */
464
- interface SelectFieldProps<FormType, P extends Path<FormType> = Path<FormType>> {
465
- /**
466
- * Field name (path in the form state)
467
- * Accepts both static paths and dynamic paths for use in array fields
468
- */
469
- name: FlexiblePath<FormType>;
470
- /**
471
- * Field label
472
- */
473
- label?: string;
474
- /**
475
- * Whether to hide the label
476
- */
477
- hideLabel?: boolean;
478
- /**
479
- * Field description
480
- */
481
- description?: string;
482
- /**
483
- * Whether the field is required
484
- */
485
- required?: boolean;
486
- /**
487
- * Placeholder text
488
- */
791
+ disabled?: boolean;
792
+ readonly?: boolean;
793
+ class?: string | string[];
794
+ size?: string;
795
+ variant?: string;
796
+ min?: number;
797
+ max?: number;
798
+ step?: number;
799
+ showValue?: boolean;
800
+ }
801
+
802
+ interface ResetButtonProps<FormType> {
803
+ resetText?: string;
804
+ className?: string;
805
+ disabled?: boolean;
806
+ onReset?: () => void;
807
+ }
808
+
809
+ interface SearchFieldProps<FormType> {
810
+ name: FlexiblePath<FormType>;
811
+ label?: string;
812
+ hideLabel?: boolean;
813
+ description?: string;
814
+ required?: boolean;
489
815
  placeholder?: string;
490
- /**
491
- * Whether the field is disabled
492
- */
493
816
  disabled?: boolean;
494
- /**
495
- * Whether the field is readonly
496
- */
497
817
  readonly?: boolean;
498
- /**
499
- * CSS classes to apply to the field
500
- */
818
+ autocomplete?: string;
501
819
  class?: string | string[];
502
- /**
503
- * Field size
504
- */
505
820
  size?: string;
506
- /**
507
- * Field variant
508
- */
509
821
  variant?: string;
510
- /**
511
- * Select options (overrides options from schema)
512
- * Using selectOptions instead of options to avoid conflicts with HTML select element
513
- */
514
- selectOptions?: SelectOption[];
515
- /**
516
- * Custom mapping function to convert values to labels
517
- * This is useful when you want to customize how labels are displayed
518
- * without providing a full options array
519
- *
520
- * Can be provided as either:
521
- * 1. A function that takes a value and returns a label
522
- * 2. An object map where keys are enum values and values are labels
523
- */
524
- valueToLabel?: ValueToLabelMapping<FieldPathToEnum$1<FormType, P>>;
525
- /**
526
- * Whether to use options from the schema (default: true)
527
- * Set to false to ignore schema options even when no options prop is provided
528
- */
529
- useSchemaOptions?: boolean;
530
822
  }
531
823
 
532
824
  interface SubmitButtonProps<FormType> {
@@ -791,195 +1083,6 @@ interface DataTableProps<FormType> {
791
1083
  name?: string;
792
1084
  }
793
1085
 
794
- /**
795
- * Type to convert underscores to PascalCase
796
- * This helper type processes a single segment by capitalizing after underscores
797
- */
798
- type SegmentToPascalCase<S extends string> = S extends `${infer First}_${infer Rest}` ? `${Capitalize<First>}${SegmentToPascalCase<Rest>}` : Capitalize<S>;
799
- /**
800
- * Type to convert a dot-separated path to PascalCase
801
- * This uses recursion to handle any level of nesting
802
- * Also handles underscores by removing them and capitalizing each segment
803
- */
804
- type PathToPascalCase<P extends string> = P extends `${infer A}.${infer B}` ? `${SegmentToPascalCase<A>}${PathToPascalCase<B>}` : `${SegmentToPascalCase<P>}Field`;
805
- /**
806
- * Type that maps field paths to their corresponding enum types
807
- */
808
- type FieldPathToEnum<T, P extends Path<T>> = P extends keyof T ? T[P] extends string ? T[P] : string : string;
809
- /**
810
- * Type that extracts the array element type from a field path
811
- * If the path points to an array, it extracts the element type
812
- * @example
813
- * ArrayItemType<{users: User[]}, 'users'> = User
814
- * ArrayItemType<{tasks: Task[]}, 'tasks'> = Task
815
- */
816
- type ArrayItemType<T, P extends Path<T>> = P extends keyof T ? T[P] extends ReadonlyArray<infer Item> ? Item : T[P] extends Array<infer Item> ? Item : never : never;
817
- /**
818
- * Type for array field components with properly typed slots
819
- */
820
- type ArrayFieldComponent<T, P extends Path<T>> = vue.FunctionalComponent<Omit<ArrayFieldProps<T, ArrayItemType<T, P>>, 'name'>, {}, {
821
- itemRenderer: (props: {
822
- item: ArrayItemType<T, P>;
823
- index: number;
824
- getFieldName: (fieldPath: string) => string;
825
- }) => any;
826
- availableItemRenderer: (props: {
827
- item: ArrayItemType<T, P>;
828
- index: number;
829
- }) => any;
830
- default: () => any;
831
- }, {}>;
832
- /**
833
- * Type for enum field components that require valueToLabel
834
- */
835
- type EnumFieldComponent<T, P extends Path<T>> = (props: Omit<SelectFieldProps<T>, 'name' | 'valueToLabel'> & {
836
- valueToLabel: Record<FieldPathToEnum<T, P>, string>;
837
- }, context?: any) => any;
838
- /**
839
- * Type for text field components
840
- */
841
- type TextFieldComponent<T> = (props: Omit<TextFieldProps<T>, 'name'>, context?: any) => any;
842
- /**
843
- * Type for select field components (can work with string or enum fields)
844
- */
845
- type SelectFieldComponent<T, P extends Path<T>> = (props: Omit<SelectFieldProps<T>, 'name'>, context?: any) => any;
846
- /**
847
- * Type for number field components
848
- */
849
- type NumberFieldComponent<T> = (props: Omit<NumberFieldProps<T>, 'name'>, context?: any) => any;
850
- /**
851
- * Type for checkbox field components
852
- */
853
- type CheckboxFieldComponent<T> = (props: Omit<CheckboxFieldProps<T>, 'name'>, context?: any) => any;
854
- /**
855
- * Type for date field components
856
- */
857
- type DateFieldComponent<T> = (props: Omit<DateFieldProps<T>, 'name'>, context?: any) => any;
858
- /**
859
- * Generic field component type - fallback for any other field types
860
- */
861
- type GenericFieldComponent = (props: any, context?: any) => any;
862
- /**
863
- * Maps a field path to its component type based on the field's actual type
864
- * Enums are explicitly passed as FieldType = 'enum' since they can't be auto-detected
865
- * Everything else is inferred from the actual TypeScript type at the path
866
- *
867
- * For string fields, we allow both TextFieldComponent and SelectFieldComponent
868
- * because string fields can use inputType: 'select' in metadata to become SelectFields
869
- */
870
- type FieldComponentType<T, P extends Path<T>, FieldType extends string = 'string'> = FieldType extends 'enum' ? EnumFieldComponent<T, P> : P extends keyof T ? T[P] extends Array<any> | ReadonlyArray<any> ? ArrayFieldComponent<T, P> : T[P] extends number ? NumberFieldComponent<T> : T[P] extends boolean ? CheckboxFieldComponent<T> : T[P] extends Date ? DateFieldComponent<T> : T[P] extends string ? // String fields can be either TextField or SelectField depending on inputType metadata
871
- TextFieldComponent<T> | SelectFieldComponent<T, P> : GenericFieldComponent : GenericFieldComponent;
872
- /**
873
- * Type for the components object with PascalCase keys derived from field paths
874
- * Each component gets the right type based on what the field actually is
875
- */
876
- type ComponentsType<T> = {
877
- [K in Path<T> as PathToPascalCase<K & string>]: FieldComponentType<T, K>;
878
- };
879
-
880
- /**
881
- * Types for field metadata in the form system
882
- */
883
- /**
884
- * Metadata about a form field
885
- * This interface defines all the properties that describe a field's behavior and appearance
886
- */
887
- interface FieldMetadata {
888
- /** The full path to the field (e.g., 'user.firstName') */
889
- path: string;
890
- /** Whether the field is required (false if optional) */
891
- isRequired: boolean;
892
- /** The data type of the field */
893
- type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'enum' | 'date' | 'union';
894
- /** The input type for rendering the field */
895
- inputType?: 'text' | 'email' | 'url' | 'tel' | 'number' | 'select' | 'checkbox' | 'radio' | 'textarea' | 'password' | 'array' | 'currency' | 'date' | 'time' | 'datetime-local' | 'file' | 'range' | 'search' | 'combobox';
896
- /** The display label for the field */
897
- label?: string;
898
- /** Placeholder text for the field */
899
- placeholder?: string;
900
- /** Minimum value (for number fields) or length (for string/array fields) */
901
- min?: number;
902
- /** Maximum value (for number fields) or length (for string/array fields) */
903
- max?: number;
904
- /** Regular expression pattern for validation */
905
- pattern?: RegExp;
906
- /** Options for enum fields */
907
- options?: Array<{
908
- value: string;
909
- label: string;
910
- }>;
911
- /** Default value for the field */
912
- defaultValue?: any;
913
- /** Whether the field is an array */
914
- isArray?: boolean;
915
- /** Metadata for array element type */
916
- arrayOf?: FieldMetadata;
917
- /** Child field metadata for object types */
918
- children?: Record<string, FieldMetadata>;
919
- /** Available items for array fields */
920
- availableItems?: any[];
921
- /** Help text to display with the field */
922
- helpText?: string;
923
- /** For textarea fields, number of rows to display */
924
- rows?: number;
925
- /** For textarea fields, number of columns to display */
926
- cols?: number;
927
- /** For enum fields, map values to display labels */
928
- valueToLabel?: Record<string, string>;
929
- /** Whether the field should be disabled */
930
- disabled?: boolean;
931
- /** Whether the field should be hidden */
932
- hidden?: boolean;
933
- /** CSS class to apply to the field */
934
- className?: string;
935
- /** Whether the field should be focused on load */
936
- autofocus?: boolean;
937
- /** For number fields, the step value */
938
- step?: number;
939
- /** Autocomplete attribute for the field */
940
- autocomplete?: string;
941
- }
942
-
943
- /**
944
- * Types for schema metadata in the form system
945
- */
946
-
947
- /**
948
- * Additional metadata that can be associated with schema fields
949
- * This interface defines properties that can be attached to schema fields
950
- * to customize their behavior and appearance
951
- */
952
- interface SchemaFieldMetadata {
953
- /** The input type for rendering the field */
954
- inputType?: 'text' | 'email' | 'tel' | 'number' | 'select' | 'checkbox' | 'radio' | 'textarea' | 'password' | 'currency' | 'date' | 'time' | 'datetime-local' | 'combobox';
955
- /** Placeholder text for the field */
956
- placeholder?: string;
957
- /** The display label for the field */
958
- label?: string;
959
- /** Help text to display with the field */
960
- helpText?: string;
961
- /** For textarea fields, number of rows to display */
962
- rows?: number;
963
- /** For textarea fields, number of columns to display */
964
- cols?: number;
965
- /** For enum fields, map values to display labels */
966
- valueToLabel?: Record<string, string>;
967
- /** Whether to hide validation errors */
968
- hideError?: boolean;
969
- /** Step value for numeric fields */
970
- step?: number;
971
- /** Any other custom properties */
972
- [key: string]: any;
973
- }
974
- /**
975
- * Type for the registry mapping field paths to their metadata
976
- */
977
- type MetadataRegistry = Record<string, SchemaFieldMetadata>;
978
- /**
979
- * Type helper to extract all possible paths from a Zod schema
980
- */
981
- type PathsOf<T extends z.ZodTypeAny> = Path<z.infer<T>>;
982
-
983
1086
  /**
984
1087
  * Types for style creators in the form system
985
1088
  */
@@ -1204,7 +1307,7 @@ declare function useForm<T extends z.ZodObject<any>, CalcType = (values: z.infer
1204
1307
  ziniaGeneric: {
1205
1308
  TextField: vue.FunctionalComponent<TextFieldProps<z.TypeOf<T>>, {}, any, {}>;
1206
1309
  NumberField: vue.FunctionalComponent<NumberFieldProps<z.TypeOf<T>>, {}, any, {}>;
1207
- SelectField: vue.FunctionalComponent<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>>, {}, any, {}>;
1310
+ SelectField: vue.FunctionalComponent<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>, any>, {}, any, {}>;
1208
1311
  CheckboxField: vue.FunctionalComponent<CheckboxFieldProps<z.TypeOf<T>>, {}, any, {}>;
1209
1312
  TextareaField: vue.FunctionalComponent<TextareaFieldProps<z.TypeOf<T>>, {}, any, {}>;
1210
1313
  RadioField: vue.FunctionalComponent<RadioFieldProps<z.TypeOf<T>>, {}, any, {}>;
@@ -1265,10 +1368,10 @@ declare function useForm<T extends z.ZodObject<any>, CalcType = (values: z.infer
1265
1368
  }) => any;
1266
1369
  default: () => any;
1267
1370
  }, {}>;
1268
- createTypedSelectField: <P extends Path<z.TypeOf<T>>>(fieldPath: P) => <E extends FieldPathToEnum<z.TypeOf<T>, P> = FieldPathToEnum<z.TypeOf<T>, P>>(props: Omit<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>>, "name" | "valueToLabel"> & {
1371
+ createTypedSelectField: <P extends Path<z.TypeOf<T>>>(fieldPath: P) => <E extends FieldPathToEnum<z.TypeOf<T>, P> = FieldPathToEnum<z.TypeOf<T>, P>>(props: Omit<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>, any>, "name" | "valueToLabel"> & {
1269
1372
  valueToLabel: Record<E, string>;
1270
1373
  }, context?: any) => any;
1271
- typedSelectFields: { [K in Path<z.TypeOf<T>>]?: (<E extends FieldPathToEnum<z.TypeOf<T>, K> = FieldPathToEnum<z.TypeOf<T>, K>>(props: Omit<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>>, "name" | "valueToLabel"> & {
1374
+ typedSelectFields: { [K in Path<z.TypeOf<T>>]?: (<E extends FieldPathToEnum<z.TypeOf<T>, K> = FieldPathToEnum<z.TypeOf<T>, K>>(props: Omit<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>, any>, "name" | "valueToLabel"> & {
1272
1375
  valueToLabel: Record<E, string>;
1273
1376
  }, context?: any) => any) | undefined; };
1274
1377
  fields: Record<Path<z.TypeOf<T>>, any>;
@@ -1362,7 +1465,7 @@ declare function generateFieldComponents<T extends z.ZodObject<any>>(schema: T,
1362
1465
  generic: {
1363
1466
  TextField: vue.FunctionalComponent<TextFieldProps<z.TypeOf<T>>, {}, any, {}>;
1364
1467
  NumberField: vue.FunctionalComponent<NumberFieldProps<z.TypeOf<T>>, {}, any, {}>;
1365
- SelectField: vue.FunctionalComponent<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>>, {}, any, {}>;
1468
+ SelectField: vue.FunctionalComponent<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>, any>, {}, any, {}>;
1366
1469
  CheckboxField: vue.FunctionalComponent<CheckboxFieldProps<z.TypeOf<T>>, {}, any, {}>;
1367
1470
  TextareaField: vue.FunctionalComponent<TextareaFieldProps<z.TypeOf<T>>, {}, any, {}>;
1368
1471
  RadioField: vue.FunctionalComponent<RadioFieldProps<z.TypeOf<T>>, {}, any, {}>;
@@ -1423,10 +1526,10 @@ declare function generateFieldComponents<T extends z.ZodObject<any>>(schema: T,
1423
1526
  }) => any;
1424
1527
  default: () => any;
1425
1528
  }, {}>;
1426
- createTypedSelectField: <P extends Path<z.TypeOf<T>>>(fieldPath: P) => <E extends FieldPathToEnum<z.TypeOf<T>, P> = FieldPathToEnum<z.TypeOf<T>, P>>(props: Omit<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>>, "name" | "valueToLabel"> & {
1529
+ createTypedSelectField: <P extends Path<z.TypeOf<T>>>(fieldPath: P) => <E extends FieldPathToEnum<z.TypeOf<T>, P> = FieldPathToEnum<z.TypeOf<T>, P>>(props: Omit<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>, any>, "name" | "valueToLabel"> & {
1427
1530
  valueToLabel: Record<E, string>;
1428
1531
  }, context?: any) => any;
1429
- typedSelectFields: { [K in Path<z.TypeOf<T>>]?: (<E extends FieldPathToEnum<z.TypeOf<T>, K> = FieldPathToEnum<z.TypeOf<T>, K>>(props: Omit<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>>, "name" | "valueToLabel"> & {
1532
+ typedSelectFields: { [K in Path<z.TypeOf<T>>]?: (<E extends FieldPathToEnum<z.TypeOf<T>, K> = FieldPathToEnum<z.TypeOf<T>, K>>(props: Omit<SelectFieldProps<z.TypeOf<T>, Path<z.TypeOf<T>>, any>, "name" | "valueToLabel"> & {
1430
1533
  valueToLabel: Record<E, string>;
1431
1534
  }, context?: any) => any) | undefined; };
1432
1535
  fields: Record<Path<z.TypeOf<T>>, any>;
@@ -2252,4 +2355,4 @@ declare const ActionIcons: {
2252
2355
  readonly dotsHorizontal: "<svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z\" /></svg>";
2253
2356
  };
2254
2357
 
2255
- export { ActionIcons, type ActionItem, type ActionsConfig, type ButtonActionItem, type ColumnDefinition, type CursorDataTableOptions, type CursorFetchParams, type CursorFetchResult, type DataTableColumns, type DataTableOptions, type DisplayComponentsType, type DisplayFieldComponent, ErrorDisplay, type FetchDataParams, type FetchDataResult, type FilterOptionItem, type FilterValue, type LinkActionItem, LoadingDisplay, NoDataDisplay, SCHEMA_ID_SYMBOL, type TypedSelectFieldComponent, type UseCursorDataTableType, type UseDataTableType, type UseDeleteModalType, type UseDisplayType, type UseFormType, type UseFormTyped, ZINIA_DATA_TABLE_ACTIONS_KEY, ZINIA_DATA_TABLE_COLUMNS_KEY, ZINIA_DATA_TABLE_FILTER_INPUTS_KEY, ZINIA_DATA_TABLE_FILTER_OPERATORS_KEY, ZINIA_DATA_TABLE_FILTER_OPTIONS_LOADING_KEY, ZINIA_DATA_TABLE_FILTER_OPTIONS_STATE_KEY, ZINIA_DATA_TABLE_KEY, ZINIA_DATA_TABLE_NAME_KEY, ZINIA_DATA_TABLE_OPTIONS_KEY, ZINIA_DATA_TABLE_SEARCH_INPUT_KEY, ZINIA_DELETE_MODAL_FIELDS_GENERIC_KEY, ZINIA_DELETE_MODAL_FIELDS_KEY, ZINIA_DELETE_MODAL_KEY, ZINIA_DELETE_MODAL_SCHEMA_KEY, ZINIA_DISPLAY_FIELDS_GENERIC_KEY, ZINIA_DISPLAY_FIELDS_KEY, ZINIA_DISPLAY_KEY, ZINIA_DISPLAY_SCHEMA_KEY, ZINIA_FIELDS_GENERIC_KEY, ZINIA_FIELDS_KEY, ZINIA_FORM_KEY, ZINIA_FORM_SCHEMA_KEY, type ZiniaDataTable, type ZiniaDeleteModal, type ZiniaDeleteModalFields, type ZiniaDeleteModalGenericFields, type ZiniaDisplay, type ZiniaDisplayFields, type ZiniaDisplayGenericFields, type ZiniaForm, type ZiniaFormFields, type ZiniaFormGenericFields, ZiniaPlugin, type ZiniaPluginOptions, clearAllMetadata, clearSchemaMetadata, createBaseComponents, createBaseDisplayComponents, createPartialStyle, createStyleTemplate, createTypedArrayField, createTypedSelectField, daisyUIStyle, extendStyle, generateDisplayComponents, generateFieldComponents, getAllSchemaMetadata, getDefaultStyle, getFieldMetadata, getRegisteredStyle, getRegisteredStyleNames, getSchemaId, hasRegisteredStyle, hasSchemaMetadata, mergeStyles, plainStyle, registerSchemaMetadata, registerStyle, setSchemaMetadata, useCursorDataTable, useDataTable, useDeleteModal, useDisplay, useForm, withMetadata };
2358
+ export { ActionIcons, type ActionItem, type ActionsConfig, type ArrayFieldProps, type ButtonActionItem, COMBOBOX_FIELD_PROP_NAMES, type CheckboxFieldProps, type ColumnDefinition, type ComboboxFieldProps, type ComboboxOption, type CurrencyFieldProps, type CursorDataTableOptions, type CursorFetchParams, type CursorFetchResult, type DataTableColumns, type DataTableOptions, type DataTableProps, type DateFieldProps, type DateTimeLocalFieldProps, type DeleteModalProps, type DisplayComponentsType, type DisplayFieldComponent, type DisplayFieldProps, type DisplayProps, type EmailFieldProps, type EnumValueToLabelMap, type EnumValuesFromField, ErrorDisplay, type FetchDataParams, type FetchDataResult, type FieldPathToEnum$1 as FieldPathToEnum, type FieldType, type FileFieldProps, type FilterOptionItem, type FilterValue, type FormErrorsSummaryProps, type FormProps, type LinkActionItem, LoadingDisplay, NoDataDisplay, type NumberFieldProps, type PasswordFieldProps, type RadioFieldProps, type RangeFieldProps, type ResetButtonProps, SCHEMA_ID_SYMBOL, SELECT_FIELD_PROP_NAMES, type SearchFieldProps, type SelectFieldProps, type SelectOption, type SubmitButtonProps, type TelFieldProps, type TextFieldProps, type TextareaFieldProps, type TimeFieldProps, type ToppingsFieldProps, type TransferListFieldProps, type TypedSelectFieldComponent, type UrlFieldProps, type UseCursorDataTableType, type UseDataTableType, type UseDeleteModalType, type UseDisplayType, type UseFormType, type UseFormTyped, type ValueToLabelMapping, ZINIA_DATA_TABLE_ACTIONS_KEY, ZINIA_DATA_TABLE_COLUMNS_KEY, ZINIA_DATA_TABLE_FILTER_INPUTS_KEY, ZINIA_DATA_TABLE_FILTER_OPERATORS_KEY, ZINIA_DATA_TABLE_FILTER_OPTIONS_LOADING_KEY, ZINIA_DATA_TABLE_FILTER_OPTIONS_STATE_KEY, ZINIA_DATA_TABLE_KEY, ZINIA_DATA_TABLE_NAME_KEY, ZINIA_DATA_TABLE_OPTIONS_KEY, ZINIA_DATA_TABLE_SEARCH_INPUT_KEY, ZINIA_DELETE_MODAL_FIELDS_GENERIC_KEY, ZINIA_DELETE_MODAL_FIELDS_KEY, ZINIA_DELETE_MODAL_KEY, ZINIA_DELETE_MODAL_SCHEMA_KEY, ZINIA_DISPLAY_FIELDS_GENERIC_KEY, ZINIA_DISPLAY_FIELDS_KEY, ZINIA_DISPLAY_KEY, ZINIA_DISPLAY_SCHEMA_KEY, ZINIA_FIELDS_GENERIC_KEY, ZINIA_FIELDS_KEY, ZINIA_FORM_KEY, ZINIA_FORM_SCHEMA_KEY, type ZiniaDataTable, type ZiniaDeleteModal, type ZiniaDeleteModalFields, type ZiniaDeleteModalGenericFields, type ZiniaDisplay, type ZiniaDisplayFields, type ZiniaDisplayGenericFields, type ZiniaForm, type ZiniaFormFields, type ZiniaFormGenericFields, ZiniaPlugin, type ZiniaPluginOptions, type ZodEnumValues, clearAllMetadata, clearSchemaMetadata, createBaseComponents, createBaseDisplayComponents, createPartialStyle, createStyleTemplate, createTypedArrayField, createTypedSelectField, daisyUIStyle, extendStyle, generateDisplayComponents, generateFieldComponents, getAllSchemaMetadata, getDefaultStyle, getFieldMetadata, getRegisteredStyle, getRegisteredStyleNames, getSchemaId, hasRegisteredStyle, hasSchemaMetadata, mergeStyles, plainStyle, registerSchemaMetadata, registerStyle, setSchemaMetadata, useCursorDataTable, useDataTable, useDeleteModal, useDisplay, useForm, withMetadata };