@apia/validations 4.0.58 → 4.0.63

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
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
- import React__default, { ReactNode, FC, ChangeEvent } from 'react';
3
- import { TModify, TPropsSelector, TPropsComparator, TPropsConfiguration, TId, EventEmitter } from '@apia/util';
4
- import { TNumberInput, ApiaUtilModalHandler, TOpenModal, TFieldLabel } from '@apia/components';
2
+ import React__default, { FC, ChangeEvent, ReactNode } from 'react';
3
+ import { TModify, TPropsSelector, TPropsComparator, TPropsConfiguration, TId, EventEmitter, TLabel } from '@apia/util';
4
+ import { TNumberInput, SwitchMultipleOption, ApiaUtilModalHandler, TOpenModal, TFieldLabel } from '@apia/components';
5
5
  import { BoxProps, ButtonProps, InputProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from '@apia/theme';
6
6
  import { TModalContext } from '@apia/components/src/components/modals/ModalContext';
7
7
 
@@ -553,9 +553,7 @@ type TSelect = TSelectProps & TDefaultFieldType & {
553
553
  };
554
554
  declare const Select: React__default.ForwardRefExoticComponent<Omit<TSelect, "ref"> & React__default.RefAttributes<HTMLSelectElement>>;
555
555
 
556
- type TSwitchbox = Omit<SwitchProps, 'onChange'> & Pick<InputProps, 'onChange'> & TDefaultFieldType & {
557
- reverse?: boolean;
558
- };
556
+ type TSwitchbox = Omit<SwitchProps, 'onChange' | 'defaultChecked' | 'defaultValue'> & Pick<InputProps, 'onChange'> & TDefaultFieldType<boolean>;
559
557
  declare const Switchbox: React__default.ForwardRefExoticComponent<Omit<TSwitchbox, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
560
558
 
561
559
  type TTextarea = TextareaProps & TDefaultFieldType;
@@ -583,14 +581,16 @@ declare abstract class CollectorField<ValueType = any, FieldProps = any> extends
583
581
  }> {
584
582
  #private;
585
583
  readonly name: string;
586
- protected label: ReactNode;
584
+ protected label: string | TLabel;
587
585
  /**
588
586
  * Este es el componente de implementación de cada campo particular
589
587
  */
590
588
  abstract Component: FC;
591
589
  abstract type: string;
592
- constructor(name: string, label: ReactNode, properties?: Partial<FieldProps>);
593
- collector: Collector;
590
+ constructor(name: string, label: string | TLabel, properties?: Partial<FieldProps>);
591
+ protected _collector: Collector;
592
+ get collector(): Collector;
593
+ set collector(c: Collector);
594
594
  isHidden: () => boolean;
595
595
  setIsHidden: (isHidden: boolean) => void;
596
596
  protected properties: Partial<FieldProps>;
@@ -605,25 +605,27 @@ declare abstract class CollectorField<ValueType = any, FieldProps = any> extends
605
605
 
606
606
  declare abstract class ValidatedCollectorField<ValueType = any, FieldProps = any> extends CollectorField<ValueType, FieldProps> {
607
607
  readonly name: string;
608
- protected label: string;
608
+ protected label: string | TLabel;
609
609
  protected config: Partial<{
610
610
  initialValue: ValueType;
611
611
  properties: Partial<FieldProps>;
612
612
  validationFunction: TValidationFunction<ValueType>;
613
613
  validationRules: TValidationRules;
614
614
  }>;
615
- constructor(name: string, label: string, config?: Partial<{
615
+ constructor(name: string, label: string | TLabel, config?: Partial<{
616
616
  initialValue: ValueType;
617
617
  properties: Partial<FieldProps>;
618
618
  validationFunction: TValidationFunction<ValueType>;
619
619
  validationRules: TValidationRules;
620
620
  }>);
621
+ set collector(c: Collector);
621
622
  get initialValue(): ValueType | undefined;
622
- get value(): any;
623
+ get value(): ValueType;
623
624
  setInitialValue: (newValue: ValueType) => void;
624
625
  setValidationFunction: (newFunction: TValidationFunction<ValueType>) => void;
625
626
  setValidationRules: (newRules: TValidationRules) => void;
626
- setValue: (newValue: ValueType) => void;
627
+ setValue(newValue: ValueType): void;
628
+ toggleRequired: (isReq?: boolean) => void;
627
629
  protected useValidationFunction: () => TValidationFunction<ValueType> | undefined;
628
630
  protected useValidationRules: () => Partial<Omit<Record<"number" | "required" | "alpha" | "alphanum" | "nodigit" | "digit" | "digitmin" | "digitltd" | "email" | "image" | "phone" | "url" | "confirm" | "differs" | "length_str" | "length_fix" | "lengthmax" | "lengthmin" | "words_min" | "words_max" | "words_range" | "checkbox" | "checkboxes_group" | "radios" | "select" | "select_multiple" | "errorsTitle", boolean>, "digitmin" | "digitltd" | "confirm" | "differs" | "length_str" | "length_fix" | "words_min" | "words_max" | "words_range" | "checkboxes_group"> & {
629
631
  digitmin: number;
@@ -684,20 +686,59 @@ declare class CollectorLabel extends CollectorField {
684
686
  private kind;
685
687
  private static maxId;
686
688
  type: string;
687
- constructor(label: ReactNode, kind?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'label');
689
+ constructor(label: string | TLabel, kind?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'label');
688
690
  Component: () => React.JSX.Element;
689
691
  }
690
692
 
691
693
  declare class CollectorButton extends CollectorField<null, Omit<ButtonProps, 'children'>> {
692
- protected label: string;
694
+ protected label: string | TLabel;
695
+ type: string;
696
+ constructor(label: string | TLabel, properties?: Omit<ButtonProps, 'children'>);
697
+ Component: () => React.JSX.Element;
698
+ }
699
+
700
+ declare class CollectorSwitch extends ValidatedCollectorField<boolean, Omit<TSwitchbox, 'name'>> {
701
+ type: string;
702
+ Component: () => React.JSX.Element;
703
+ }
704
+
705
+ declare class CollectorTitle extends CollectorLabel {
706
+ constructor(label: string | TLabel, level: number);
707
+ }
708
+
709
+ declare class CollectorSeparator extends CollectorField {
710
+ private static maxId;
711
+ type: string;
712
+ constructor();
713
+ Component: () => React.JSX.Element;
714
+ }
715
+
716
+ declare class CollectorAutogrowTextarea extends ValidatedCollectorField<string, Omit<TextareaProps, 'name'>> {
717
+ type: string;
718
+ Component: () => React.JSX.Element;
719
+ }
720
+
721
+ type SwitchInputProps<T extends string> = {
722
+ name: string;
723
+ label?: string;
724
+ title?: string;
725
+ options: SwitchMultipleOption<T>[];
726
+ formName?: string;
727
+ initialValue?: T;
728
+ removeOnUnmount?: boolean;
729
+ validationFunction?: any;
730
+ validationRules?: any;
731
+ onChange?: (ev: T) => void;
732
+ };
733
+ declare class CollectorSwitchMultiple<T extends string = string> extends ValidatedCollectorField<T, Omit<InputProps, 'name' | 'onChange'> & SwitchInputProps<T>> {
693
734
  type: string;
694
- constructor(label: string, properties?: Omit<ButtonProps, 'children'>);
695
735
  Component: () => React.JSX.Element;
696
736
  }
697
737
 
698
738
  declare class Collector {
699
739
  #private;
700
740
  fields: {
741
+ autogrowTextarea: typeof CollectorAutogrowTextarea;
701
742
  button: typeof CollectorButton;
702
743
  checkbox: typeof CollectorCheckbox;
703
744
  input: typeof CollectorInput;
@@ -707,26 +748,44 @@ declare class Collector {
707
748
  */
708
749
  label: typeof CollectorLabel;
709
750
  select: typeof CollectorSelect;
751
+ separator: typeof CollectorSeparator;
752
+ switch: typeof CollectorSwitch;
710
753
  textarea: typeof CollectorTextarea;
754
+ title: typeof CollectorTitle;
755
+ switchMultiple: typeof CollectorSwitchMultiple;
711
756
  };
712
757
  private private__id;
713
758
  get id(): string;
714
759
  modal: ApiaUtilModalHandler | null;
715
- add: (...fields: CollectorField[]) => this;
716
- forEach: (cb: (field: CollectorField, i: number) => void) => void;
760
+ protected fieldsStore: Record<string, CollectorField>;
761
+ add(...fields: CollectorField[]): this;
762
+ forEach(cb: (field: CollectorField, i: number) => void): void;
763
+ getByName<T extends CollectorField = CollectorField>(name: string): T;
717
764
  readonly Render: ({ hideConfirm, modal, resolve, className, }: {
718
765
  className?: string;
719
766
  hideConfirm?: boolean;
720
767
  modal?: TModalContext;
721
768
  resolve: (v: Record<string, unknown>) => boolean;
722
769
  }) => React.JSX.Element;
723
- show: <FormValues extends Record<string, unknown>>(modalProps?: Partial<Omit<TOpenModal, "children" | "onConfirm" | "onCancel" | "confirmProps">> & Partial<{
770
+ show<FormValues extends Record<string, unknown>>(modalProps?: Partial<Omit<TOpenModal, 'children' | 'onConfirm' | 'onCancel' | 'confirmProps'>> & Partial<{
724
771
  hideConfirm: boolean;
725
772
  /**
726
773
  * Si este método devuelve false, el modal no se cerrará
727
774
  */
728
775
  onConfirm?: (res: FormValues | null) => boolean;
729
- }>) => Promise<FormValues | null>;
776
+ }>): Promise<FormValues | null>;
777
+ }
778
+
779
+ declare class WithMemoryCollector extends Collector {
780
+ protected prefix: string;
781
+ constructor(prefix: string);
782
+ private memoized;
783
+ private getKey;
784
+ addMemoized(...fields: CollectorField[]): this;
785
+ show<FormValues extends Record<string, unknown>>(modalProps?: Partial<Omit<TOpenModal, 'children' | 'onConfirm' | 'onCancel' | 'confirmProps'>> & Partial<{
786
+ hideConfirm: boolean;
787
+ onConfirm?: (res: FormValues | null) => boolean;
788
+ }>): Promise<FormValues | null>;
730
789
  }
731
790
 
732
791
  declare function useFieldStatesClassNames<T = unknown>(name: string, formName?: string): string;
@@ -914,5 +973,5 @@ declare abstract class Validable<T extends object> {
914
973
  validate(): Promise<true | Record<string, string>>;
915
974
  }
916
975
 
917
- export { InnerCaptcha as Captcha, Checkbox, Collector, CollectorField, DeletableInput, FieldWrapper, FileInput, Form, FormContext, type IWrapper, Input, NumberInputf, Radio, Select, Switchbox, type TCheckbox, type TCheckboxProps, type TDefaultFieldType, type TInput$1 as TInput, type TObjectInspection, type TOnValidate, type TOption, type TRadio, type TSelect, type TSelectProps, type TSwitchbox, type TUseField, type TValidationFunction, type TValidationResult, type TValidationRules, Textarea, Validable, ValidableCheck, ValidableContext, ValidableField, ValidableInput, ValidableSelect, ValidableTextarea, ValidatedCollectorField, ValidationError, type ValidationRules, type ValidationsMap, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, lang, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidableContext, useValidationClass, validate, validationsStore };
976
+ export { InnerCaptcha as Captcha, Checkbox, Collector, CollectorAutogrowTextarea, CollectorButton, CollectorCheckbox, CollectorField, CollectorInput, CollectorLabel, CollectorSelect, CollectorSeparator, CollectorSwitch, CollectorSwitchMultiple, CollectorTextarea, CollectorTitle, DeletableInput, FieldWrapper, FileInput, Form, FormContext, type IWrapper, Input, NumberInputf, Radio, Select, Switchbox, type TCheckbox, type TCheckboxProps, type TDefaultFieldType, type TInput$1 as TInput, type TObjectInspection, type TOnValidate, type TOption, type TRadio, type TSelect, type TSelectProps, type TSwitchbox, type TUseField, type TValidationFunction, type TValidationResult, type TValidationRules, Textarea, Validable, ValidableCheck, ValidableContext, ValidableField, ValidableInput, ValidableSelect, ValidableTextarea, ValidatedCollectorField, ValidationError, type ValidationRules, type ValidationsMap, WithMemoryCollector, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, lang, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidableContext, useValidationClass, validate, validationsStore };
918
977
  //# sourceMappingURL=index.d.ts.map