@dragonmastery/zinia-forms-core 0.3.12 → 0.3.15
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 +316 -190
- package/dist/index.js +760 -281
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -148,40 +148,6 @@ interface CheckboxFieldProps<FormType> {
|
|
|
148
148
|
variant?: string;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
interface DateFieldProps<FormType> {
|
|
152
|
-
name: FlexiblePath<FormType>;
|
|
153
|
-
label?: string;
|
|
154
|
-
hideLabel?: boolean;
|
|
155
|
-
description?: string;
|
|
156
|
-
required?: boolean;
|
|
157
|
-
placeholder?: string;
|
|
158
|
-
disabled?: boolean;
|
|
159
|
-
readonly?: boolean;
|
|
160
|
-
class?: string | string[];
|
|
161
|
-
size?: string;
|
|
162
|
-
variant?: string;
|
|
163
|
-
min?: string;
|
|
164
|
-
max?: string;
|
|
165
|
-
formatter?: (date: string) => unknown;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
interface NumberFieldProps<FormType> {
|
|
169
|
-
name: FlexiblePath<FormType>;
|
|
170
|
-
label?: string;
|
|
171
|
-
hideLabel?: boolean;
|
|
172
|
-
description?: string;
|
|
173
|
-
required?: boolean;
|
|
174
|
-
placeholder?: string;
|
|
175
|
-
disabled?: boolean;
|
|
176
|
-
readonly?: boolean;
|
|
177
|
-
class?: string | string[];
|
|
178
|
-
size?: string;
|
|
179
|
-
variant?: string;
|
|
180
|
-
min?: number;
|
|
181
|
-
max?: number;
|
|
182
|
-
step?: number;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
151
|
/**
|
|
186
152
|
* Option item for select fields
|
|
187
153
|
* @template TData - Type of the optional data object for storing additional metadata
|
|
@@ -368,6 +334,186 @@ interface SelectFieldProps<FormType, P extends Path<FormType> = Path<FormType>,
|
|
|
368
334
|
*/
|
|
369
335
|
declare const SELECT_FIELD_PROP_NAMES: readonly ["name", "selectOptions", "placeholder", "disabled", "readonly", "class", "label", "hideLabel", "description", "required", "size", "variant", "valueToLabel", "useSchemaOptions", "dependsOn", "optionFilterFn", "autoReset"];
|
|
370
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Props for the ComboboxField component
|
|
339
|
+
* @template FormType - The form type
|
|
340
|
+
* @template P - The field path in the form
|
|
341
|
+
* @template TData - The type of the data property in SelectOption (for cascading dropdowns)
|
|
342
|
+
*/
|
|
343
|
+
interface ComboboxFieldProps<FormType, P extends Path<FormType> = Path<FormType>, TData = any> {
|
|
344
|
+
/**
|
|
345
|
+
* Field name (path in the form state)
|
|
346
|
+
* Accepts both static paths and dynamic paths for use in array fields
|
|
347
|
+
*/
|
|
348
|
+
name: FlexiblePath<FormType>;
|
|
349
|
+
/**
|
|
350
|
+
* Field label
|
|
351
|
+
*/
|
|
352
|
+
label?: string;
|
|
353
|
+
/**
|
|
354
|
+
* Whether to hide the label
|
|
355
|
+
*/
|
|
356
|
+
hideLabel?: boolean;
|
|
357
|
+
/**
|
|
358
|
+
* Field description
|
|
359
|
+
*/
|
|
360
|
+
description?: string;
|
|
361
|
+
/**
|
|
362
|
+
* Whether the field is required
|
|
363
|
+
*/
|
|
364
|
+
required?: boolean;
|
|
365
|
+
/**
|
|
366
|
+
* Placeholder text
|
|
367
|
+
*/
|
|
368
|
+
placeholder?: string;
|
|
369
|
+
/**
|
|
370
|
+
* Whether the field is disabled
|
|
371
|
+
*/
|
|
372
|
+
disabled?: boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Whether the field is readonly
|
|
375
|
+
*/
|
|
376
|
+
readonly?: boolean;
|
|
377
|
+
/**
|
|
378
|
+
* CSS classes to apply to the field
|
|
379
|
+
*/
|
|
380
|
+
class?: string | string[];
|
|
381
|
+
/**
|
|
382
|
+
* Field size
|
|
383
|
+
*/
|
|
384
|
+
size?: string;
|
|
385
|
+
/**
|
|
386
|
+
* Field variant
|
|
387
|
+
*/
|
|
388
|
+
variant?: string;
|
|
389
|
+
/**
|
|
390
|
+
* Combobox options (overrides options from schema)
|
|
391
|
+
* Using selectOptions instead of options to avoid conflicts with HTML select element
|
|
392
|
+
*
|
|
393
|
+
* For async loading, use form-level dataLoaders and pass options via extraData:
|
|
394
|
+
* ```ts
|
|
395
|
+
* useForm(schema, {
|
|
396
|
+
* dataLoaders: { products: loadProducts },
|
|
397
|
+
* });
|
|
398
|
+
* // Then: :selectOptions="form.extraData.products || []"
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* // With typed data
|
|
403
|
+
* interface CityData { country: string; }
|
|
404
|
+
* const options: SelectOption<CityData>[] = [
|
|
405
|
+
* { value: 'nyc', label: 'New York', data: { country: 'usa' } }
|
|
406
|
+
* ];
|
|
407
|
+
*/
|
|
408
|
+
selectOptions?: SelectOption<TData>[];
|
|
409
|
+
/**
|
|
410
|
+
* Custom mapping function to convert values to labels
|
|
411
|
+
* This is useful when you want to customize how labels are displayed
|
|
412
|
+
* without providing a full options array
|
|
413
|
+
*
|
|
414
|
+
* Can be provided as either:
|
|
415
|
+
* 1. A function that takes a value and returns a label
|
|
416
|
+
* 2. An object map where keys are enum values and values are labels
|
|
417
|
+
*/
|
|
418
|
+
valueToLabel?: ValueToLabelMapping<FieldPathToEnum$1<FormType, P>>;
|
|
419
|
+
/**
|
|
420
|
+
* Whether to use options from the schema (default: true)
|
|
421
|
+
* Set to false to ignore schema options even when no options prop is provided
|
|
422
|
+
*/
|
|
423
|
+
useSchemaOptions?: boolean;
|
|
424
|
+
/**
|
|
425
|
+
* Field path that this field depends on for cascading dropdowns
|
|
426
|
+
* When the parent field changes, this field's options will be filtered
|
|
427
|
+
* and the field will be reset (unless autoReset is false)
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* // City field depends on country field
|
|
431
|
+
* <ComboboxField name="city" dependsOn="country" :optionFilterFn="filterCitiesByCountry" />
|
|
432
|
+
*/
|
|
433
|
+
dependsOn?: FlexiblePath<FormType>;
|
|
434
|
+
/**
|
|
435
|
+
* Function to filter options based on the parent field's value
|
|
436
|
+
* Receives the parent field value and all available options
|
|
437
|
+
* Should return the filtered options array
|
|
438
|
+
*
|
|
439
|
+
* The function signature is tied to the TData type parameter, ensuring type safety
|
|
440
|
+
* between selectOptions and optionFilterFn
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* // With typed data - both props must use the same data type
|
|
444
|
+
* interface CityData { country: string; }
|
|
445
|
+
* const filterCitiesByCountry = (
|
|
446
|
+
* countryValue: string,
|
|
447
|
+
* allOptions: SelectOption<CityData>[]
|
|
448
|
+
* ): SelectOption<CityData>[] => {
|
|
449
|
+
* return allOptions.filter(opt => opt.data?.country === countryValue);
|
|
450
|
+
* };
|
|
451
|
+
*/
|
|
452
|
+
optionFilterFn?: (parentValue: any, allOptions: SelectOption<TData>[]) => SelectOption<TData>[];
|
|
453
|
+
/**
|
|
454
|
+
* Whether to automatically reset this field when the parent field changes (default: true)
|
|
455
|
+
* Set to false if you want to preserve the value when parent changes
|
|
456
|
+
*/
|
|
457
|
+
autoReset?: boolean;
|
|
458
|
+
/**
|
|
459
|
+
* Whether to allow creating new values that don't exist in the options
|
|
460
|
+
* Default: false (must be explicitly set to true to allow creation)
|
|
461
|
+
*
|
|
462
|
+
* Note: This is specific to ComboboxField and not available in SelectField
|
|
463
|
+
*/
|
|
464
|
+
allowCreate?: boolean;
|
|
465
|
+
/**
|
|
466
|
+
* Custom filter function for filtering options as user types
|
|
467
|
+
* Default: filters by case-insensitive substring match
|
|
468
|
+
*
|
|
469
|
+
* Note: This is specific to ComboboxField and not available in SelectField
|
|
470
|
+
* This is different from optionFilterFn which filters based on parent field values
|
|
471
|
+
*/
|
|
472
|
+
filterFn?: (query: string, option: SelectOption<TData>) => boolean;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Array of prop names for ComboboxField component.
|
|
476
|
+
* This is derived from ComboboxFieldProps interface and ensures type safety.
|
|
477
|
+
* Used for prop normalization and filtering in component implementations.
|
|
478
|
+
*
|
|
479
|
+
* TypeScript ensures all entries are valid keys of ComboboxFieldProps.
|
|
480
|
+
*/
|
|
481
|
+
declare const COMBOBOX_FIELD_PROP_NAMES: readonly ["name", "selectOptions", "placeholder", "disabled", "readonly", "class", "label", "hideLabel", "description", "required", "size", "variant", "valueToLabel", "useSchemaOptions", "dependsOn", "optionFilterFn", "autoReset", "allowCreate", "filterFn"];
|
|
482
|
+
|
|
483
|
+
interface DateFieldProps<FormType> {
|
|
484
|
+
name: FlexiblePath<FormType>;
|
|
485
|
+
label?: string;
|
|
486
|
+
hideLabel?: boolean;
|
|
487
|
+
description?: string;
|
|
488
|
+
required?: boolean;
|
|
489
|
+
placeholder?: string;
|
|
490
|
+
disabled?: boolean;
|
|
491
|
+
readonly?: boolean;
|
|
492
|
+
class?: string | string[];
|
|
493
|
+
size?: string;
|
|
494
|
+
variant?: string;
|
|
495
|
+
min?: string;
|
|
496
|
+
max?: string;
|
|
497
|
+
formatter?: (date: string) => unknown;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
interface NumberFieldProps<FormType> {
|
|
501
|
+
name: FlexiblePath<FormType>;
|
|
502
|
+
label?: string;
|
|
503
|
+
hideLabel?: boolean;
|
|
504
|
+
description?: string;
|
|
505
|
+
required?: boolean;
|
|
506
|
+
placeholder?: string;
|
|
507
|
+
disabled?: boolean;
|
|
508
|
+
readonly?: boolean;
|
|
509
|
+
class?: string | string[];
|
|
510
|
+
size?: string;
|
|
511
|
+
variant?: string;
|
|
512
|
+
min?: number;
|
|
513
|
+
max?: number;
|
|
514
|
+
step?: number;
|
|
515
|
+
}
|
|
516
|
+
|
|
371
517
|
/**
|
|
372
518
|
* Type to convert underscores to PascalCase
|
|
373
519
|
* This helper type processes a single segment by capitalizing after underscores
|
|
@@ -429,11 +575,11 @@ type EnumFieldComponent<T, P extends Path<T>> = (props: Omit<SelectFieldProps<T>
|
|
|
429
575
|
valueToLabel: Record<FieldPathToEnum<T, P>, string>;
|
|
430
576
|
}, context?: any) => any;
|
|
431
577
|
/**
|
|
432
|
-
* Type for
|
|
433
|
-
* Uses
|
|
434
|
-
*
|
|
578
|
+
* Type for combobox field components (searchable select with optional creation)
|
|
579
|
+
* Uses ComboboxFieldProps<T, P, TData> which extends SelectFieldProps with allowCreate and filterFn
|
|
580
|
+
* Preserves path-specific typing for props like dependsOn and ensures type safety
|
|
435
581
|
*/
|
|
436
|
-
type
|
|
582
|
+
type ComboboxFieldComponent<T, P extends Path<T>> = <TData = any>(props: Omit<ComboboxFieldProps<T, P, TData>, 'name'>, context?: any) => any;
|
|
437
583
|
/**
|
|
438
584
|
* Type for number field components
|
|
439
585
|
*/
|
|
@@ -461,14 +607,19 @@ type GenericFieldComponent = (props: any, context?: any) => any;
|
|
|
461
607
|
type UnwrapOptional<T> = Exclude<T, undefined | null>;
|
|
462
608
|
/**
|
|
463
609
|
* Maps a field path to its component type based on the field's actual type
|
|
464
|
-
*
|
|
465
|
-
*
|
|
610
|
+
* FieldType can be 'enum', 'combobox', or 'string' (default)
|
|
611
|
+
* - 'enum': Uses EnumFieldComponent (requires valueToLabel)
|
|
612
|
+
* - 'combobox': Uses ComboboxFieldComponent (includes allowCreate and filterFn)
|
|
613
|
+
* - 'string': Uses ComboboxFieldComponent (superset of SelectField with allowCreate and filterFn)
|
|
466
614
|
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
* This
|
|
615
|
+
* We use ComboboxFieldComponent for all string fields because:
|
|
616
|
+
* 1. ComboboxFieldProps includes all SelectFieldProps (it's a superset)
|
|
617
|
+
* 2. This allows allowCreate to be available in types even if the field uses SelectField at runtime
|
|
618
|
+
* 3. ComboboxField can handle all SelectField use cases, so it's safe to use as the default
|
|
619
|
+
*
|
|
620
|
+
* Everything else is inferred from the actual TypeScript type at the path
|
|
470
621
|
*/
|
|
471
|
-
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 ?
|
|
622
|
+
type FieldComponentType<T, P extends Path<T>, FieldType extends string = 'string'> = FieldType extends 'enum' ? EnumFieldComponent<T, P> : FieldType extends 'combobox' ? ComboboxFieldComponent<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 ? ComboboxFieldComponent<T, P> : GenericFieldComponent : GenericFieldComponent;
|
|
472
623
|
/**
|
|
473
624
|
* Type for the components object with PascalCase keys derived from field paths
|
|
474
625
|
* Each component gets the right type based on what the field actually is
|
|
@@ -580,152 +731,6 @@ type MetadataRegistry = Record<string, SchemaFieldMetadata>;
|
|
|
580
731
|
*/
|
|
581
732
|
type PathsOf<T extends z.ZodTypeAny> = Path<z.infer<T>>;
|
|
582
733
|
|
|
583
|
-
/**
|
|
584
|
-
* Props for the ComboboxField component
|
|
585
|
-
* @template FormType - The form type
|
|
586
|
-
* @template P - The field path in the form
|
|
587
|
-
* @template TData - The type of the data property in SelectOption (for cascading dropdowns)
|
|
588
|
-
*/
|
|
589
|
-
interface ComboboxFieldProps<FormType, P extends Path<FormType> = Path<FormType>, TData = any> {
|
|
590
|
-
/**
|
|
591
|
-
* Field name (path in the form state)
|
|
592
|
-
* Accepts both static paths and dynamic paths for use in array fields
|
|
593
|
-
*/
|
|
594
|
-
name: FlexiblePath<FormType>;
|
|
595
|
-
/**
|
|
596
|
-
* Field label
|
|
597
|
-
*/
|
|
598
|
-
label?: string;
|
|
599
|
-
/**
|
|
600
|
-
* Whether to hide the label
|
|
601
|
-
*/
|
|
602
|
-
hideLabel?: boolean;
|
|
603
|
-
/**
|
|
604
|
-
* Field description
|
|
605
|
-
*/
|
|
606
|
-
description?: string;
|
|
607
|
-
/**
|
|
608
|
-
* Whether the field is required
|
|
609
|
-
*/
|
|
610
|
-
required?: boolean;
|
|
611
|
-
/**
|
|
612
|
-
* Placeholder text
|
|
613
|
-
*/
|
|
614
|
-
placeholder?: string;
|
|
615
|
-
/**
|
|
616
|
-
* Whether the field is disabled
|
|
617
|
-
*/
|
|
618
|
-
disabled?: boolean;
|
|
619
|
-
/**
|
|
620
|
-
* Whether the field is readonly
|
|
621
|
-
*/
|
|
622
|
-
readonly?: boolean;
|
|
623
|
-
/**
|
|
624
|
-
* CSS classes to apply to the field
|
|
625
|
-
*/
|
|
626
|
-
class?: string | string[];
|
|
627
|
-
/**
|
|
628
|
-
* Field size
|
|
629
|
-
*/
|
|
630
|
-
size?: string;
|
|
631
|
-
/**
|
|
632
|
-
* Field variant
|
|
633
|
-
*/
|
|
634
|
-
variant?: string;
|
|
635
|
-
/**
|
|
636
|
-
* Combobox options (overrides options from schema)
|
|
637
|
-
* Using selectOptions instead of options to avoid conflicts with HTML select element
|
|
638
|
-
*
|
|
639
|
-
* For async loading, use form-level dataLoaders and pass options via extraData:
|
|
640
|
-
* ```ts
|
|
641
|
-
* useForm(schema, {
|
|
642
|
-
* dataLoaders: { products: loadProducts },
|
|
643
|
-
* });
|
|
644
|
-
* // Then: :selectOptions="form.extraData.products || []"
|
|
645
|
-
* ```
|
|
646
|
-
*
|
|
647
|
-
* @example
|
|
648
|
-
* // With typed data
|
|
649
|
-
* interface CityData { country: string; }
|
|
650
|
-
* const options: SelectOption<CityData>[] = [
|
|
651
|
-
* { value: 'nyc', label: 'New York', data: { country: 'usa' } }
|
|
652
|
-
* ];
|
|
653
|
-
*/
|
|
654
|
-
selectOptions?: SelectOption<TData>[];
|
|
655
|
-
/**
|
|
656
|
-
* Custom mapping function to convert values to labels
|
|
657
|
-
* This is useful when you want to customize how labels are displayed
|
|
658
|
-
* without providing a full options array
|
|
659
|
-
*
|
|
660
|
-
* Can be provided as either:
|
|
661
|
-
* 1. A function that takes a value and returns a label
|
|
662
|
-
* 2. An object map where keys are enum values and values are labels
|
|
663
|
-
*/
|
|
664
|
-
valueToLabel?: ValueToLabelMapping<FieldPathToEnum$1<FormType, P>>;
|
|
665
|
-
/**
|
|
666
|
-
* Whether to use options from the schema (default: true)
|
|
667
|
-
* Set to false to ignore schema options even when no options prop is provided
|
|
668
|
-
*/
|
|
669
|
-
useSchemaOptions?: boolean;
|
|
670
|
-
/**
|
|
671
|
-
* Field path that this field depends on for cascading dropdowns
|
|
672
|
-
* When the parent field changes, this field's options will be filtered
|
|
673
|
-
* and the field will be reset (unless autoReset is false)
|
|
674
|
-
*
|
|
675
|
-
* @example
|
|
676
|
-
* // City field depends on country field
|
|
677
|
-
* <ComboboxField name="city" dependsOn="country" :optionFilterFn="filterCitiesByCountry" />
|
|
678
|
-
*/
|
|
679
|
-
dependsOn?: FlexiblePath<FormType>;
|
|
680
|
-
/**
|
|
681
|
-
* Function to filter options based on the parent field's value
|
|
682
|
-
* Receives the parent field value and all available options
|
|
683
|
-
* Should return the filtered options array
|
|
684
|
-
*
|
|
685
|
-
* The function signature is tied to the TData type parameter, ensuring type safety
|
|
686
|
-
* between selectOptions and optionFilterFn
|
|
687
|
-
*
|
|
688
|
-
* @example
|
|
689
|
-
* // With typed data - both props must use the same data type
|
|
690
|
-
* interface CityData { country: string; }
|
|
691
|
-
* const filterCitiesByCountry = (
|
|
692
|
-
* countryValue: string,
|
|
693
|
-
* allOptions: SelectOption<CityData>[]
|
|
694
|
-
* ): SelectOption<CityData>[] => {
|
|
695
|
-
* return allOptions.filter(opt => opt.data?.country === countryValue);
|
|
696
|
-
* };
|
|
697
|
-
*/
|
|
698
|
-
optionFilterFn?: (parentValue: any, allOptions: SelectOption<TData>[]) => SelectOption<TData>[];
|
|
699
|
-
/**
|
|
700
|
-
* Whether to automatically reset this field when the parent field changes (default: true)
|
|
701
|
-
* Set to false if you want to preserve the value when parent changes
|
|
702
|
-
*/
|
|
703
|
-
autoReset?: boolean;
|
|
704
|
-
/**
|
|
705
|
-
* Whether to allow creating new values that don't exist in the options
|
|
706
|
-
* Default: true
|
|
707
|
-
*
|
|
708
|
-
* Note: This is specific to ComboboxField and not available in SelectField
|
|
709
|
-
*/
|
|
710
|
-
allowCreate?: boolean;
|
|
711
|
-
/**
|
|
712
|
-
* Custom filter function for filtering options as user types
|
|
713
|
-
* Default: filters by case-insensitive substring match
|
|
714
|
-
*
|
|
715
|
-
* Note: This is specific to ComboboxField and not available in SelectField
|
|
716
|
-
* This is different from optionFilterFn which filters based on parent field values
|
|
717
|
-
*/
|
|
718
|
-
filterFn?: (query: string, option: SelectOption<TData>) => boolean;
|
|
719
|
-
}
|
|
720
|
-
/**
|
|
721
|
-
* Array of prop names for ComboboxField component.
|
|
722
|
-
* This is derived from ComboboxFieldProps interface and ensures type safety.
|
|
723
|
-
* Used for prop normalization and filtering in component implementations.
|
|
724
|
-
*
|
|
725
|
-
* TypeScript ensures all entries are valid keys of ComboboxFieldProps.
|
|
726
|
-
*/
|
|
727
|
-
declare const COMBOBOX_FIELD_PROP_NAMES: readonly ["name", "selectOptions", "placeholder", "disabled", "readonly", "class", "label", "hideLabel", "description", "required", "size", "variant", "valueToLabel", "useSchemaOptions", "dependsOn", "optionFilterFn", "autoReset", "allowCreate", "filterFn"];
|
|
728
|
-
|
|
729
734
|
interface CurrencyFieldProps<FormType> {
|
|
730
735
|
name: FlexiblePath<FormType>;
|
|
731
736
|
label?: string;
|
|
@@ -1274,6 +1279,118 @@ interface StyleCreators {
|
|
|
1274
1279
|
}, {}>;
|
|
1275
1280
|
}
|
|
1276
1281
|
|
|
1282
|
+
/**
|
|
1283
|
+
* Form state management hook
|
|
1284
|
+
* Provides reactive form state with proper reactivity handling
|
|
1285
|
+
*/
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* Form state interface
|
|
1289
|
+
*/
|
|
1290
|
+
interface FormState<T, CalcType = any, ExtraDataType = any> {
|
|
1291
|
+
data: T;
|
|
1292
|
+
calculatedValues: CalcType;
|
|
1293
|
+
touched: Record<string, boolean>;
|
|
1294
|
+
dirty: Record<string, boolean>;
|
|
1295
|
+
errors: Record<string, string>;
|
|
1296
|
+
focused: Record<string, boolean>;
|
|
1297
|
+
displayText: Record<string, string>;
|
|
1298
|
+
selectedIndex: Record<string, number>;
|
|
1299
|
+
collapsedFields: Record<string, {
|
|
1300
|
+
isFieldCollapsed: boolean;
|
|
1301
|
+
collapsedItems: number[];
|
|
1302
|
+
defaultCollapsedInitialized: boolean;
|
|
1303
|
+
}>;
|
|
1304
|
+
undoHistory: Record<string, {
|
|
1305
|
+
type: 'add' | 'remove' | 'swap';
|
|
1306
|
+
previousState: any;
|
|
1307
|
+
currentState: any;
|
|
1308
|
+
timestamp: number;
|
|
1309
|
+
}[]>;
|
|
1310
|
+
redoHistory: Record<string, {
|
|
1311
|
+
type: 'add' | 'remove' | 'swap';
|
|
1312
|
+
previousState: any;
|
|
1313
|
+
currentState: any;
|
|
1314
|
+
timestamp: number;
|
|
1315
|
+
}[]>;
|
|
1316
|
+
pendingOperations: Record<string, {
|
|
1317
|
+
type: 'add' | 'remove' | 'swap';
|
|
1318
|
+
index?: number;
|
|
1319
|
+
indexA?: number;
|
|
1320
|
+
indexB?: number;
|
|
1321
|
+
item?: any;
|
|
1322
|
+
previousState: any;
|
|
1323
|
+
currentState: any;
|
|
1324
|
+
timestamp: number;
|
|
1325
|
+
timeoutId?: number;
|
|
1326
|
+
}[]>;
|
|
1327
|
+
arrayItemIds: Record<string, string[]>;
|
|
1328
|
+
isSubmitting: boolean;
|
|
1329
|
+
hasAttemptedSubmit: boolean;
|
|
1330
|
+
submitAttemptsCount: number;
|
|
1331
|
+
submitError: string | null;
|
|
1332
|
+
isReady: boolean;
|
|
1333
|
+
isLoading: boolean;
|
|
1334
|
+
loadError: string | null;
|
|
1335
|
+
extraData: ExtraDataType;
|
|
1336
|
+
fetchedOptions: Record<string, any[]>;
|
|
1337
|
+
loadingOptions: Record<string, boolean>;
|
|
1338
|
+
asyncCascadingParents: Record<string, string>;
|
|
1339
|
+
loadingAutoPopulate: Record<string, boolean>;
|
|
1340
|
+
populatingFields: Record<string, boolean>;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
/**
|
|
1344
|
+
* Type definitions for async cascading selection and auto-population
|
|
1345
|
+
*/
|
|
1346
|
+
|
|
1347
|
+
/**
|
|
1348
|
+
* Helper type to get the value type of a field path
|
|
1349
|
+
*/
|
|
1350
|
+
type FieldValue<FormType, P extends Path<FormType>> = P extends keyof FormType ? FormType[P] : P extends `${infer K}.${infer Rest}` ? K extends keyof FormType ? FormType[K] extends Record<string, any> ? FieldValue<FormType[K], Rest & Path<FormType[K]>> : never : never : never;
|
|
1351
|
+
/**
|
|
1352
|
+
* Configuration for async cascading selection (parent → child options fetching via API)
|
|
1353
|
+
*/
|
|
1354
|
+
interface AsyncCascadingSelectConfig<FormType, ParentField extends Path<FormType> = Path<FormType>, ChildField extends Path<FormType> = Path<FormType>> {
|
|
1355
|
+
/** Parent field that triggers child options fetch */
|
|
1356
|
+
parentField: ParentField;
|
|
1357
|
+
/** Child field that will be populated with fetched options */
|
|
1358
|
+
childField: ChildField;
|
|
1359
|
+
/** Async function to fetch child options based on parent value */
|
|
1360
|
+
fetchOptionsFn: (parentValue: FieldValue<FormType, ParentField>) => Promise<Array<SelectOption>>;
|
|
1361
|
+
/** Whether to clear child field when parent changes (default: true) */
|
|
1362
|
+
clearOnParentChange?: boolean;
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Type for the async cascading selects configuration object
|
|
1366
|
+
* Uses a mapped type to preserve field path type safety
|
|
1367
|
+
*/
|
|
1368
|
+
type AsyncCascadingSelectsConfig<FormType> = {
|
|
1369
|
+
[K in string]: AsyncCascadingSelectConfig<FormType, Path<FormType>, Path<FormType>>;
|
|
1370
|
+
};
|
|
1371
|
+
/**
|
|
1372
|
+
* Configuration for auto-population (select/combobox → other fields)
|
|
1373
|
+
*/
|
|
1374
|
+
interface AutoPopulateConfig<FormType, TData = any, SourceField extends Path<FormType> = Path<FormType>> {
|
|
1375
|
+
/**
|
|
1376
|
+
* Optional async function to fetch data when option is selected.
|
|
1377
|
+
* If provided, this will be called instead of using option.data.
|
|
1378
|
+
* Receives the selected option value and returns the data object.
|
|
1379
|
+
*/
|
|
1380
|
+
fetchDataFn?: (selectedValue: FieldValue<FormType, SourceField>) => Promise<TData>;
|
|
1381
|
+
/** Mapping of form fields to data properties for auto-population */
|
|
1382
|
+
fields: {
|
|
1383
|
+
[TargetField in Path<FormType>]?: string | ((data: TData) => FieldValue<FormType, TargetField>);
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Type for the auto-populate configuration object
|
|
1388
|
+
* Key is the select/combobox field name, value is the auto-populate config
|
|
1389
|
+
*/
|
|
1390
|
+
type AutoPopulateConfigs<FormType> = Partial<{
|
|
1391
|
+
[SourceField in Path<FormType>]: AutoPopulateConfig<FormType, any>;
|
|
1392
|
+
}>;
|
|
1393
|
+
|
|
1277
1394
|
/**
|
|
1278
1395
|
* Options for merging server data with local changes
|
|
1279
1396
|
*/
|
|
@@ -1337,6 +1454,8 @@ declare function useForm<T extends z.ZodObject<any>, CalcType = (values: z.infer
|
|
|
1337
1454
|
[K in keyof ExtraDataType]?: () => Promise<ExtraDataType[K]>;
|
|
1338
1455
|
};
|
|
1339
1456
|
fetchData?: () => Promise<z.infer<typeof schema>>;
|
|
1457
|
+
asyncCascadingSelects?: AsyncCascadingSelectsConfig<z.infer<T>>;
|
|
1458
|
+
autoPopulate?: AutoPopulateConfigs<z.infer<T>>;
|
|
1340
1459
|
calculationFn?: (values: z.infer<T>, extraData?: ExtraDataType) => CalcType;
|
|
1341
1460
|
debug?: {
|
|
1342
1461
|
all?: boolean;
|
|
@@ -1350,6 +1469,7 @@ declare function useForm<T extends z.ZodObject<any>, CalcType = (values: z.infer
|
|
|
1350
1469
|
form: {
|
|
1351
1470
|
storeName: string;
|
|
1352
1471
|
values: z.TypeOf<T>;
|
|
1472
|
+
state: FormState<z.TypeOf<T>, CalcType, ExtraDataType>;
|
|
1353
1473
|
readonly calculatedValues: CalcType;
|
|
1354
1474
|
readonly extraData: ExtraDataType;
|
|
1355
1475
|
readonly isValid: boolean;
|
|
@@ -2051,6 +2171,9 @@ declare function useDataTable<TSchema extends z.ZodObject<any>>(schema: TSchema,
|
|
|
2051
2171
|
sortDrawerOpen: vue.Ref<boolean, boolean>;
|
|
2052
2172
|
openSortDrawer: () => boolean;
|
|
2053
2173
|
closeSortDrawer: () => boolean;
|
|
2174
|
+
filterDrawerOpen: vue.Ref<boolean, boolean>;
|
|
2175
|
+
openFilterDrawer: () => boolean;
|
|
2176
|
+
closeFilterDrawer: () => boolean;
|
|
2054
2177
|
};
|
|
2055
2178
|
fieldsMetadata: Record<string, FieldMetadata>;
|
|
2056
2179
|
columns: (z.TypeOf<TSchema> extends infer T ? { [K in keyof T]?: ColumnDefinition<z.TypeOf<TSchema>, K> | undefined; } : never) & {
|
|
@@ -2216,6 +2339,9 @@ declare function useCursorDataTable<TSchema extends z.ZodObject<any>>(schema: TS
|
|
|
2216
2339
|
sortDrawerOpen: vue.Ref<boolean, boolean>;
|
|
2217
2340
|
openSortDrawer: () => boolean;
|
|
2218
2341
|
closeSortDrawer: () => boolean;
|
|
2342
|
+
filterDrawerOpen: vue.Ref<boolean, boolean>;
|
|
2343
|
+
openFilterDrawer: () => boolean;
|
|
2344
|
+
closeFilterDrawer: () => boolean;
|
|
2219
2345
|
};
|
|
2220
2346
|
fieldsMetadata: Record<string, FieldMetadata>;
|
|
2221
2347
|
columns: (z.TypeOf<TSchema> extends infer T ? { [K in keyof T]?: ColumnDefinition<z.TypeOf<TSchema>, K> | undefined; } : never) & {
|