easy-forms-core 1.0.0 → 1.0.1

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
@@ -6,6 +6,10 @@ type FieldType = 'text' | 'email' | 'number' | 'password' | 'textarea' | 'select
6
6
  * Tipos de validaciones soportadas
7
7
  */
8
8
  type ValidationType = 'required' | 'email' | 'minLength' | 'maxLength' | 'min' | 'max' | 'pattern' | 'custom';
9
+ /**
10
+ * Operadores de condición
11
+ */
12
+ type ConditionOperator = 'equals' | 'notEquals' | 'contains' | 'notContains' | 'greaterThan' | 'lessThan' | 'greaterThanOrEqual' | 'lessThanOrEqual' | 'in' | 'notIn' | 'isEmpty' | 'isNotEmpty' | 'regex';
9
13
  /**
10
14
  * Validación base
11
15
  */
@@ -50,6 +54,47 @@ interface CustomValidation extends BaseValidation {
50
54
  * Unión de todas las validaciones
51
55
  */
52
56
  type Validation = RequiredValidation | EmailValidation | MinLengthValidation | MaxLengthValidation | MinValidation | MaxValidation | PatternValidation | CustomValidation;
57
+ /**
58
+ * Condición individual para campos
59
+ */
60
+ interface FieldCondition {
61
+ field: string;
62
+ operator: ConditionOperator;
63
+ value: any;
64
+ }
65
+ /**
66
+ * Dependencias de un campo
67
+ */
68
+ interface FieldDependencies {
69
+ show?: FieldCondition | FieldCondition[];
70
+ hide?: FieldCondition | FieldCondition[];
71
+ enable?: FieldCondition | FieldCondition[];
72
+ disable?: FieldCondition | FieldCondition[];
73
+ required?: FieldCondition | FieldCondition[];
74
+ optional?: FieldCondition | FieldCondition[];
75
+ }
76
+ /**
77
+ * Tipos de máscaras predefinidas
78
+ */
79
+ type PredefinedMask = 'phone' | 'phone-us' | 'phone-international' | 'date' | 'date-us' | 'date-eu' | 'credit-card' | 'ssn' | 'zip-code' | 'currency' | 'percentage' | 'time' | 'datetime';
80
+ /**
81
+ * Máscara personalizada con patrón
82
+ */
83
+ interface CustomMask {
84
+ pattern: string;
85
+ placeholder?: string;
86
+ transform?: (value: string) => string;
87
+ }
88
+ /**
89
+ * Configuración de máscara
90
+ */
91
+ interface MaskConfig {
92
+ type?: PredefinedMask;
93
+ custom?: CustomMask;
94
+ keepFormat?: boolean;
95
+ showMaskOnFocus?: boolean;
96
+ showMaskOnHover?: boolean;
97
+ }
53
98
  /**
54
99
  * Campo base
55
100
  */
@@ -64,6 +109,12 @@ interface BaseField {
64
109
  disabled?: boolean;
65
110
  hidden?: boolean;
66
111
  description?: string;
112
+ dependencies?: FieldDependencies;
113
+ conditionalValidations?: Array<{
114
+ condition: FieldCondition | FieldCondition[];
115
+ validations: Validation[];
116
+ }>;
117
+ mask?: MaskConfig;
67
118
  }
68
119
  /**
69
120
  * Campo de texto
@@ -334,6 +385,15 @@ declare class EasyForm extends BrowserHTMLElement {
334
385
  * Maneja el cambio de un campo
335
386
  */
336
387
  private handleFieldChange;
388
+ private dependencyRenderTimeout;
389
+ /**
390
+ * Re-renderiza campos dependientes
391
+ */
392
+ private renderDependentFields;
393
+ /**
394
+ * Emite evento de cambio de dependencia
395
+ */
396
+ private emitDependencyChange;
337
397
  /**
338
398
  * Maneja el blur de un campo
339
399
  */
@@ -393,6 +453,9 @@ declare class StateManager {
393
453
  private schema;
394
454
  private parser;
395
455
  private validator;
456
+ private conditionEngine;
457
+ private dependencyCache;
458
+ private fieldDependencies;
396
459
  constructor();
397
460
  /**
398
461
  * Crea el estado inicial
@@ -402,6 +465,14 @@ declare class StateManager {
402
465
  * Inicializa el schema
403
466
  */
404
467
  initializeSchema(schema: FormSchema): void;
468
+ /**
469
+ * Construye el mapa de dependencias para optimizar re-evaluaciones
470
+ */
471
+ private buildDependencyMap;
472
+ /**
473
+ * Extrae los nombres de campos observados de las dependencias
474
+ */
475
+ private extractObservedFields;
405
476
  /**
406
477
  * Inicializa los valores por defecto
407
478
  */
@@ -430,6 +501,10 @@ declare class StateManager {
430
501
  * Establece un valor
431
502
  */
432
503
  setValue(fieldName: string, value: any): Promise<void>;
504
+ /**
505
+ * Invalida el cache de dependencias para campos dependientes
506
+ */
507
+ private invalidateDependencyCache;
433
508
  /**
434
509
  * Establece un valor sin validar (útil para preservar valores durante re-renderizado)
435
510
  */
@@ -438,6 +513,10 @@ declare class StateManager {
438
513
  * Valida un campo específico
439
514
  */
440
515
  validateField(fieldName: string): Promise<void>;
516
+ /**
517
+ * Obtiene las validaciones activas para un campo (incluyendo condicionales)
518
+ */
519
+ private getActiveValidations;
441
520
  /**
442
521
  * Valida todo el formulario
443
522
  */
@@ -486,6 +565,22 @@ declare class StateManager {
486
565
  * Obtiene los campos del step actual
487
566
  */
488
567
  getCurrentStepFields(): Field[];
568
+ /**
569
+ * Obtiene la visibilidad de un campo basándose en dependencias
570
+ */
571
+ getFieldVisibility(fieldName: string): boolean;
572
+ /**
573
+ * Obtiene si un campo está habilitado basándose en dependencias
574
+ */
575
+ getFieldEnabled(fieldName: string): boolean;
576
+ /**
577
+ * Obtiene si un campo es requerido basándose en dependencias
578
+ */
579
+ getFieldRequired(fieldName: string): boolean;
580
+ /**
581
+ * Obtiene los campos que dependen de un campo específico
582
+ */
583
+ getDependentFields(fieldName: string): string[];
489
584
  }
490
585
 
491
586
  /**
@@ -496,6 +591,10 @@ declare class ValidationEngine {
496
591
  * Valida un campo con todas sus validaciones
497
592
  */
498
593
  validateField(field: Field, value: any): Promise<string[]>;
594
+ /**
595
+ * Valida un campo con validaciones específicas
596
+ */
597
+ validateFieldWithValidations(_field: Field, value: any, validations: Validation[]): Promise<string[]>;
499
598
  /**
500
599
  * Valida un valor con una validación específica
501
600
  */
@@ -576,6 +675,89 @@ interface ParsedSchema {
576
675
  isWizard: boolean;
577
676
  }
578
677
 
678
+ /**
679
+ * Motor de evaluación de condiciones
680
+ */
681
+ declare class ConditionEngine {
682
+ /**
683
+ * Evalúa una condición individual
684
+ */
685
+ evaluateCondition(condition: FieldCondition, formValues: Record<string, any>): boolean;
686
+ /**
687
+ * Evalúa múltiples condiciones (AND por defecto, soportar OR)
688
+ */
689
+ evaluateConditions(conditions: FieldCondition | FieldCondition[], formValues: Record<string, any>, logic?: 'and' | 'or'): boolean;
690
+ /**
691
+ * Evalúa dependencias de un campo
692
+ */
693
+ evaluateDependencies(dependencies: FieldDependencies, formValues: Record<string, any>): {
694
+ visible: boolean;
695
+ enabled: boolean;
696
+ required: boolean;
697
+ };
698
+ /**
699
+ * Obtiene el valor de un campo (soporta nested paths)
700
+ */
701
+ private getFieldValue;
702
+ /**
703
+ * Compara valores según el operador
704
+ */
705
+ private compareValues;
706
+ /**
707
+ * Comparación profunda de valores
708
+ */
709
+ private deepEqual;
710
+ /**
711
+ * Convierte un valor a número
712
+ */
713
+ private toNumber;
714
+ }
715
+
716
+ /**
717
+ * Motor de máscaras
718
+ */
719
+ declare class MaskEngine {
720
+ private tokenCache;
721
+ /**
722
+ * Obtiene la configuración de máscara personalizada
723
+ */
724
+ private getCustomMask;
725
+ /**
726
+ * Obtiene los tokens parseados de una máscara (con cache)
727
+ */
728
+ private getTokens;
729
+ /**
730
+ * Aplica máscara a un valor
731
+ */
732
+ applyMask(value: string, mask: MaskConfig): string;
733
+ /**
734
+ * Remueve máscara de un valor (obtiene valor raw)
735
+ */
736
+ removeMask(value: string, mask: MaskConfig): string;
737
+ /**
738
+ * Obtiene el placeholder para una máscara
739
+ */
740
+ getMaskPlaceholder(mask: MaskConfig): string;
741
+ /**
742
+ * Valida si un carácter puede ser insertado en una posición
743
+ */
744
+ canInsertChar(char: string, position: number, mask: MaskConfig): boolean;
745
+ /**
746
+ * Procesa entrada del usuario aplicando máscara en tiempo real
747
+ */
748
+ processInput(input: string, previousValue: string, mask: MaskConfig, cursorPosition: number): {
749
+ value: string;
750
+ cursorPosition: number;
751
+ };
752
+ /**
753
+ * Procesa entrada con manejo de backspace/delete
754
+ */
755
+ processKeyInput(key: string, currentValue: string, cursorPosition: number, mask: MaskConfig, isBackspace?: boolean): {
756
+ value: string;
757
+ cursorPosition: number;
758
+ };
759
+ }
760
+
579
761
  /**
580
762
  * Obtiene los colores con valores por defecto
581
763
  */
@@ -585,6 +767,15 @@ declare function getColors(colors?: FormColors): Required<FormColors>;
585
767
  */
586
768
  declare function getThemeStyles(theme: FormTheme, colors: Required<FormColors>): string;
587
769
 
770
+ /**
771
+ * Máscaras predefinidas
772
+ */
773
+ declare const PREDEFINED_MASKS: Record<PredefinedMask, CustomMask>;
774
+ /**
775
+ * Obtiene una máscara predefinida
776
+ */
777
+ declare function getPredefinedMask(type: PredefinedMask): CustomMask;
778
+
588
779
  /**
589
780
  * Utilidades generales
590
781
  */
@@ -634,4 +825,4 @@ declare function registerComponents(components: Record<string, CustomComponent>)
634
825
  */
635
826
  declare function getCustomComponent(type: string): CustomComponent | undefined;
636
827
 
637
- export { type ArrayField, type BaseField, type BaseValidation, type ChangeEventDetail, type CheckboxField, type ComponentRegistry, type CustomComponent, type CustomField, type CustomValidation, type DateField, EasyForm, type EmailValidation, type ErrorEventDetail, type Field, type FieldType, type FileField, type FormColors, type FormSchema, type FormState, type FormTheme, type GroupField, type MaxLengthValidation, type MaxValidation, type MinLengthValidation, type MinValidation, type NumberField, type PatternValidation, type RadioField, type RequiredValidation, SchemaParser, type SelectField, StateManager, type Step, type StepChangeEventDetail, type SubmitEventDetail, type SwitchField, type TextField, type TextareaField, type Validation, ValidationEngine, type ValidationType, type WizardState, attributeValue, createInput, generateId, getColors, getCustomComponent, getNestedValue, getThemeStyles, isValidEmail, parseAttributeValue, registerComponent, registerComponents, sanitizeId, setNestedValue };
828
+ export { type ArrayField, type BaseField, type BaseValidation, type ChangeEventDetail, type CheckboxField, type ComponentRegistry, ConditionEngine, type ConditionOperator, type CustomComponent, type CustomField, type CustomMask, type CustomValidation, type DateField, EasyForm, type EmailValidation, type ErrorEventDetail, type Field, type FieldCondition, type FieldDependencies, type FieldType, type FileField, type FormColors, type FormSchema, type FormState, type FormTheme, type GroupField, type MaskConfig, MaskEngine, type MaxLengthValidation, type MaxValidation, type MinLengthValidation, type MinValidation, type NumberField, PREDEFINED_MASKS, type PatternValidation, type PredefinedMask, type RadioField, type RequiredValidation, SchemaParser, type SelectField, StateManager, type Step, type StepChangeEventDetail, type SubmitEventDetail, type SwitchField, type TextField, type TextareaField, type Validation, ValidationEngine, type ValidationType, type WizardState, attributeValue, createInput, generateId, getColors, getCustomComponent, getNestedValue, getPredefinedMask, getThemeStyles, isValidEmail, parseAttributeValue, registerComponent, registerComponents, sanitizeId, setNestedValue };