@apia/validations 2.0.8 → 2.0.9
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 +771 -25
- package/dist/index.js +111 -31
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/collector/Collector.d.ts +0 -32
- package/dist/collector/Collector.d.ts.map +0 -1
- package/dist/collector/CollectorField.d.ts +0 -41
- package/dist/collector/CollectorField.d.ts.map +0 -1
- package/dist/collector/ValidatedCollectorField.d.ts +0 -44
- package/dist/collector/ValidatedCollectorField.d.ts.map +0 -1
- package/dist/collector/fields/Button.d.ts +0 -13
- package/dist/collector/fields/Button.d.ts.map +0 -1
- package/dist/collector/fields/Checkbox.d.ts +0 -13
- package/dist/collector/fields/Checkbox.d.ts.map +0 -1
- package/dist/collector/fields/Input.d.ts +0 -11
- package/dist/collector/fields/Input.d.ts.map +0 -1
- package/dist/collector/fields/Label.d.ts +0 -13
- package/dist/collector/fields/Label.d.ts.map +0 -1
- package/dist/collector/fields/Select.d.ts +0 -26
- package/dist/collector/fields/Select.d.ts.map +0 -1
- package/dist/collector/fields/Textarea.d.ts +0 -11
- package/dist/collector/fields/Textarea.d.ts.map +0 -1
- package/dist/components/Captcha.d.ts +0 -13
- package/dist/components/Captcha.d.ts.map +0 -1
- package/dist/components/Checkbox.d.ts +0 -12
- package/dist/components/Checkbox.d.ts.map +0 -1
- package/dist/components/DeletableInput.d.ts +0 -9
- package/dist/components/DeletableInput.d.ts.map +0 -1
- package/dist/components/FieldWrapper.d.ts +0 -20
- package/dist/components/FieldWrapper.d.ts.map +0 -1
- package/dist/components/FileInput.d.ts +0 -11
- package/dist/components/FileInput.d.ts.map +0 -1
- package/dist/components/Input.d.ts +0 -9
- package/dist/components/Input.d.ts.map +0 -1
- package/dist/components/NumberInput.d.ts +0 -14
- package/dist/components/NumberInput.d.ts.map +0 -1
- package/dist/components/Radio.d.ts +0 -14
- package/dist/components/Radio.d.ts.map +0 -1
- package/dist/components/Select.d.ts +0 -17
- package/dist/components/Select.d.ts.map +0 -1
- package/dist/components/Switchbox.d.ts +0 -11
- package/dist/components/Switchbox.d.ts.map +0 -1
- package/dist/components/Textarea.d.ts +0 -9
- package/dist/components/Textarea.d.ts.map +0 -1
- package/dist/components/ValidationError.d.ts +0 -17
- package/dist/components/ValidationError.d.ts.map +0 -1
- package/dist/components/types.d.ts +0 -11
- package/dist/components/types.d.ts.map +0 -1
- package/dist/form/Form.d.ts +0 -89
- package/dist/form/Form.d.ts.map +0 -1
- package/dist/form/FormContext.d.ts +0 -27
- package/dist/form/FormContext.d.ts.map +0 -1
- package/dist/hooks/useField.d.ts +0 -76
- package/dist/hooks/useField.d.ts.map +0 -1
- package/dist/hooks/useFieldStatesClassNames.d.ts +0 -4
- package/dist/hooks/useFieldStatesClassNames.d.ts.map +0 -1
- package/dist/hooks/useFieldValue.d.ts +0 -8
- package/dist/hooks/useFieldValue.d.ts.map +0 -1
- package/dist/hooks/useValidationClass.d.ts +0 -49
- package/dist/hooks/useValidationClass.d.ts.map +0 -1
- package/dist/lang/es.d.ts +0 -32
- package/dist/lang/es.d.ts.map +0 -1
- package/dist/types.d.ts +0 -130
- package/dist/types.d.ts.map +0 -1
- package/dist/util.d.ts +0 -36
- package/dist/util.d.ts.map +0 -1
- package/dist/validationStore.d.ts +0 -113
- package/dist/validationStore.d.ts.map +0 -1
package/dist/hooks/useField.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import React__default from 'react';
|
|
2
|
-
import { TValidationField } from '../types.js';
|
|
3
|
-
|
|
4
|
-
type TUseField<ValueType = unknown, SubmitValueType = ValueType> = Omit<TValidationField<ValueType, SubmitValueType>, 'error' | 'value' | 'isTouched'> & {
|
|
5
|
-
/**
|
|
6
|
-
* Con esta propiedad es posible evitar que el campo
|
|
7
|
-
* se registre cuando ya fue registrado previamente en
|
|
8
|
-
* el store. De esta forma, se evitaría escribir sobre
|
|
9
|
-
* un valor que ya estaba seteado anteriormente.
|
|
10
|
-
*/
|
|
11
|
-
avoidRegisterIfExists?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Si se está fuera de contexto de validación, se puede pasar un formName
|
|
14
|
-
* para evitar que el hook lo intente tomar de contexto.
|
|
15
|
-
*/
|
|
16
|
-
formName?: string;
|
|
17
|
-
initialValue?: ValueType;
|
|
18
|
-
removeOnUnmount?: boolean;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Este hook permite registrar un field para ser validado,
|
|
22
|
-
* o simplemente para recolectar su valor, e incluso aplicar
|
|
23
|
-
* una función de transformación de dicho valor antes de
|
|
24
|
-
* hacer submit.
|
|
25
|
-
*
|
|
26
|
-
* @returns
|
|
27
|
-
* *error:* Es null mientras que no haya errores de
|
|
28
|
-
* validación, y un string en caso de que si lo haya.
|
|
29
|
-
*
|
|
30
|
-
* *value:* Es el valor actual del campo.
|
|
31
|
-
*
|
|
32
|
-
* *name:* Debería utilizarse para dar * valor al atributo
|
|
33
|
-
* name o id del contenedor que debe recibir el foco en caso
|
|
34
|
-
* de que la validación fallara. (Esto es, cuando se deba
|
|
35
|
-
* realizar foco porque la validación falló, la librería
|
|
36
|
-
* intentará encontrar un campo con el selector
|
|
37
|
-
* [name=${name}, #${name}] dentro del formulario).
|
|
38
|
-
*
|
|
39
|
-
* *onChange:* Se utiliza para setear el valor del campo,
|
|
40
|
-
* puede utilizarse directamente como callback para la
|
|
41
|
-
* propiedad onChange que aceptan la mayoría de los campos,
|
|
42
|
-
* ya que intentará setear el valor con ev.target.value
|
|
43
|
-
* y si esa propiedad no está definida, lo hará directamente
|
|
44
|
-
* con ev.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* // Si se desea un ejemplo más complejo, vea el componente
|
|
48
|
-
* // Invitations.tsx que se encuentra dentro del directorio
|
|
49
|
-
* // de la librería.
|
|
50
|
-
*
|
|
51
|
-
* const inputProps = useField<string>({
|
|
52
|
-
name: 'name',
|
|
53
|
-
validationRules: {
|
|
54
|
-
required: true,
|
|
55
|
-
minLength: 5,
|
|
56
|
-
maxLength: 10
|
|
57
|
-
},
|
|
58
|
-
initialValue: metadata.value,
|
|
59
|
-
* });
|
|
60
|
-
|
|
61
|
-
return <Box>
|
|
62
|
-
<Input {...inputProps} />
|
|
63
|
-
<ValidationError name="name" />
|
|
64
|
-
</Box>
|
|
65
|
-
*/
|
|
66
|
-
declare function useField<ValueType = unknown, SubmitValueType = ValueType>(fieldDefinition: TUseField<ValueType, SubmitValueType>): {
|
|
67
|
-
error: string | null | undefined;
|
|
68
|
-
isTouched: boolean;
|
|
69
|
-
name: string;
|
|
70
|
-
onChange: (ev: React__default.ChangeEvent | ValueType) => void;
|
|
71
|
-
updateValidations: ({ validationFunction, validationRules, }: Pick<TValidationField, 'validationRules' | 'validationFunction'>) => void;
|
|
72
|
-
value: ValueType;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export { type TUseField, useField };
|
|
76
|
-
//# sourceMappingURL=useField.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useField.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldStatesClassNames.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldValue.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { TDefaultFieldType } from '../components/types.js';
|
|
2
|
-
import { TValidationFunction } from '../types.js';
|
|
3
|
-
|
|
4
|
-
declare function useValidationClass<T>({ customValidation, formName, name, validationClass, validationFunction, validationRules, }: Pick<TDefaultFieldType<T>, 'validationClass' | 'validationFunction' | 'validationRules' | 'name'> & {
|
|
5
|
-
customValidation?: TValidationFunction<T>;
|
|
6
|
-
formName?: string;
|
|
7
|
-
}): {
|
|
8
|
-
actualValidationFunction: TValidationFunction<T>;
|
|
9
|
-
actualValidationRules: {
|
|
10
|
-
number?: boolean | undefined;
|
|
11
|
-
required?: boolean | undefined;
|
|
12
|
-
alpha?: boolean | undefined;
|
|
13
|
-
alphanum?: boolean | undefined;
|
|
14
|
-
nodigit?: boolean | undefined;
|
|
15
|
-
digit?: boolean | undefined;
|
|
16
|
-
email?: boolean | undefined;
|
|
17
|
-
image?: boolean | undefined;
|
|
18
|
-
phone?: boolean | undefined;
|
|
19
|
-
url?: boolean | undefined;
|
|
20
|
-
lengthmax?: boolean | undefined;
|
|
21
|
-
lengthmin?: boolean | undefined;
|
|
22
|
-
checkbox?: boolean | undefined;
|
|
23
|
-
radios?: boolean | undefined;
|
|
24
|
-
select?: boolean | undefined;
|
|
25
|
-
select_multiple?: boolean | undefined;
|
|
26
|
-
errorsTitle?: boolean | undefined;
|
|
27
|
-
digitmin?: number | undefined;
|
|
28
|
-
digitltd?: [number, number] | undefined;
|
|
29
|
-
confirm?: string | undefined;
|
|
30
|
-
differs?: string | undefined;
|
|
31
|
-
length_str?: [number, number] | undefined;
|
|
32
|
-
length_fix?: number | undefined;
|
|
33
|
-
words_min?: number | undefined;
|
|
34
|
-
words_max?: number | undefined;
|
|
35
|
-
words_range?: [number, number] | undefined;
|
|
36
|
-
checkboxes_group?: number | undefined;
|
|
37
|
-
patternMessage?: string | undefined;
|
|
38
|
-
pattern?: string | RegExp | undefined;
|
|
39
|
-
digitmax?: number | undefined;
|
|
40
|
-
validName?: string | undefined;
|
|
41
|
-
maxLength?: number | undefined;
|
|
42
|
-
minLength?: number | undefined;
|
|
43
|
-
min?: number | undefined;
|
|
44
|
-
max?: number | undefined;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export { useValidationClass };
|
|
49
|
-
//# sourceMappingURL=useValidationClass.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useValidationClass.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/lang/es.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
declare const formcheckLanguage: {
|
|
2
|
-
required: string;
|
|
3
|
-
alpha: string;
|
|
4
|
-
alphanum: string;
|
|
5
|
-
nodigit: string;
|
|
6
|
-
digit: string;
|
|
7
|
-
digitmin: string;
|
|
8
|
-
digitltd: string;
|
|
9
|
-
number: string;
|
|
10
|
-
email: string;
|
|
11
|
-
image: string;
|
|
12
|
-
phone: string;
|
|
13
|
-
url: string;
|
|
14
|
-
confirm: string;
|
|
15
|
-
differs: string;
|
|
16
|
-
length_str: string;
|
|
17
|
-
length_fix: string;
|
|
18
|
-
lengthmax: string;
|
|
19
|
-
lengthmin: string;
|
|
20
|
-
words_min: string;
|
|
21
|
-
words_max: string;
|
|
22
|
-
words_range: string;
|
|
23
|
-
checkbox: string;
|
|
24
|
-
checkboxes_group: string;
|
|
25
|
-
radios: string;
|
|
26
|
-
select: string;
|
|
27
|
-
select_multiple: string;
|
|
28
|
-
errorsTitle: string;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export { formcheckLanguage as default };
|
|
32
|
-
//# sourceMappingURL=es.d.ts.map
|
package/dist/lang/es.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"es.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/types.d.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { TModify } from '@apia/util';
|
|
2
|
-
import formcheckLanguage from './lang/es.js';
|
|
3
|
-
|
|
4
|
-
type TValidate = Partial<TModify<Record<keyof typeof formcheckLanguage, boolean>, {
|
|
5
|
-
digitmin: number;
|
|
6
|
-
digitltd: [number, number];
|
|
7
|
-
confirm: string;
|
|
8
|
-
differs: string;
|
|
9
|
-
length_str: [number, number];
|
|
10
|
-
length_fix: number;
|
|
11
|
-
words_min: number;
|
|
12
|
-
words_max: number;
|
|
13
|
-
words_range: [number, number];
|
|
14
|
-
checkboxes_group: number;
|
|
15
|
-
}> & {
|
|
16
|
-
patternMessage: string;
|
|
17
|
-
pattern: RegExp | string;
|
|
18
|
-
digitmax: number;
|
|
19
|
-
validName?: string;
|
|
20
|
-
maxLength: number;
|
|
21
|
-
minLength: number;
|
|
22
|
-
min: number;
|
|
23
|
-
max: number;
|
|
24
|
-
}>;
|
|
25
|
-
interface IFieldDefinition<ValueType = string> {
|
|
26
|
-
toolTip: string;
|
|
27
|
-
label: string;
|
|
28
|
-
name: string;
|
|
29
|
-
validate?: TValidate;
|
|
30
|
-
value: ValueType;
|
|
31
|
-
options?: {
|
|
32
|
-
label: string;
|
|
33
|
-
value: number | number;
|
|
34
|
-
selected?: boolean;
|
|
35
|
-
}[];
|
|
36
|
-
}
|
|
37
|
-
type TPromiseOrNot<Type> = Promise<Type> | Type;
|
|
38
|
-
type TSuccessfulValidation<ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType> = {
|
|
39
|
-
values: ValueType;
|
|
40
|
-
submitValues: SubmitValueType;
|
|
41
|
-
};
|
|
42
|
-
type TWrongValidation = {
|
|
43
|
-
errors: Record<string, string>;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Esta interfaz representa el resultado de la validación
|
|
47
|
-
* de un formulario.
|
|
48
|
-
*/
|
|
49
|
-
type TValidationResult<ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType> = TSuccessfulValidation<ValueType, SubmitValueType> | TWrongValidation;
|
|
50
|
-
type TFieldValidationResult = true | string;
|
|
51
|
-
type TValidationFunction<ValueType> = (value: ValueType, formName: string) => TPromiseOrNot<TFieldValidationResult>;
|
|
52
|
-
type TValidationSubmitValueParser<ValueType = unknown, SubmitValueType = ValueType> = (value: ValueType) => SubmitValueType;
|
|
53
|
-
type TValidationValueParser<ValueType = unknown, ValidationValueType = unknown> = (value: ValueType) => ValidationValueType;
|
|
54
|
-
type TValidationRules = IFieldDefinition['validate'];
|
|
55
|
-
/**
|
|
56
|
-
* Esta interfaz representa el estado de un campo dentro
|
|
57
|
-
* del hook de validación.
|
|
58
|
-
*
|
|
59
|
-
* Las funcionalidades contempladas hasta el momento son:
|
|
60
|
-
*
|
|
61
|
-
* - Contener los valores del formulario.
|
|
62
|
-
* - Foco: Se hará querySelector sobre el form que lo contiene
|
|
63
|
-
* con el nombre provisto.
|
|
64
|
-
* - Función de validación o lista de reglas.
|
|
65
|
-
* - Manejo de errores.
|
|
66
|
-
* - Parsearlos para hacer submit.
|
|
67
|
-
*/
|
|
68
|
-
type TValidationField<ValueType = any, SubmitValueType = ValueType> = {
|
|
69
|
-
error?: string | null;
|
|
70
|
-
isTouched: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* El nombre se utilizará para hacer foco en el campo en caso
|
|
73
|
-
* de que la validación del mismo fallara. Para ello se
|
|
74
|
-
* intenta recuperar un campo con el selector
|
|
75
|
-
* [name=${name}, #${name}], en caso de que el selector no
|
|
76
|
-
* encontrar ningún campo, se intentará hacer foco en el
|
|
77
|
-
* siguiente campo con error.
|
|
78
|
-
*/
|
|
79
|
-
name: string;
|
|
80
|
-
/**
|
|
81
|
-
* Como dice el nombre, es posible cambiar el nombre de un
|
|
82
|
-
* campo al hacer submit.
|
|
83
|
-
*/
|
|
84
|
-
submitName?: string;
|
|
85
|
-
/**
|
|
86
|
-
* Es posible recibir un valor ya parseado en el callback
|
|
87
|
-
* onValidate del Form, para ello se puede proveer este
|
|
88
|
-
* callback, que será llamado previo a llamar a onValidate.
|
|
89
|
-
*/
|
|
90
|
-
submitValueParser?: TValidationSubmitValueParser<ValueType, SubmitValueType | Promise<SubmitValueType> | undefined>;
|
|
91
|
-
/**
|
|
92
|
-
* Es posible pasar una función de validación personalizada
|
|
93
|
-
* para casos en los que la validación es significativamente
|
|
94
|
-
* compleja. En la mayoría de los casos debería bastar con
|
|
95
|
-
* la propiedad validationRules.
|
|
96
|
-
*/
|
|
97
|
-
validationFunction?: TValidationFunction<ValueType>;
|
|
98
|
-
/**
|
|
99
|
-
* Permite pasar una serie de reglas que el campo debe cumplir
|
|
100
|
-
* al validar.
|
|
101
|
-
*/
|
|
102
|
-
validationRules?: TValidationRules;
|
|
103
|
-
validationValueParser?: TValidationValueParser<ValueType>;
|
|
104
|
-
value: ValueType;
|
|
105
|
-
};
|
|
106
|
-
type TRegisterFormOptions = Partial<{
|
|
107
|
-
/**
|
|
108
|
-
* Si esta propiedad está seteada en true, el formulario se registrará y
|
|
109
|
-
* aquellos campos que ya tuvieran valor en el store no se volverán a
|
|
110
|
-
* registrar. En caso de que se incluyera initialValue, se hará updateValue de
|
|
111
|
-
* estos campos.
|
|
112
|
-
*/
|
|
113
|
-
avoidFieldsOverride: boolean;
|
|
114
|
-
initialValues: Record<string, unknown>;
|
|
115
|
-
}>;
|
|
116
|
-
type TRegisterFieldOptions = {
|
|
117
|
-
avoidPropagation?: boolean;
|
|
118
|
-
registerIfExists?: boolean;
|
|
119
|
-
};
|
|
120
|
-
type TRegisterField = Partial<TValidationField> & Pick<TValidationField, 'name'>;
|
|
121
|
-
type TFormState = {
|
|
122
|
-
fields: string[];
|
|
123
|
-
name: string;
|
|
124
|
-
isTouched: boolean;
|
|
125
|
-
isValid: boolean;
|
|
126
|
-
validationResult: TValidationResult<Record<string, unknown>> | null;
|
|
127
|
-
} & Pick<TRegisterFormOptions, 'avoidFieldsOverride'>;
|
|
128
|
-
|
|
129
|
-
export type { IFieldDefinition, TFieldValidationResult, TFormState, TPromiseOrNot, TRegisterField, TRegisterFieldOptions, TRegisterFormOptions, TSuccessfulValidation, TValidate, TValidationField, TValidationFunction, TValidationResult, TValidationRules, TValidationSubmitValueParser, TValidationValueParser, TWrongValidation };
|
|
130
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/util.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { TFieldValidationResult, TValidationResult, TSuccessfulValidation, TValidationField, IFieldDefinition } from './types.js';
|
|
2
|
-
import formcheckLanguage from './lang/es.js';
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
interface Window {
|
|
6
|
-
NO_LANGUAGE_EXCEPTION: string;
|
|
7
|
-
MSG_INVALID_REG_EXP: string;
|
|
8
|
-
GNR_INVALID_NAME: string;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Determina si la validación de un campo resultó exitosa.
|
|
13
|
-
*/
|
|
14
|
-
declare function hasSucceedFieldValidation(result: TFieldValidationResult): result is true;
|
|
15
|
-
/**
|
|
16
|
-
* Determina si la validación de un formulario resultó
|
|
17
|
-
* exitosa. Está pensada para utilizar en el callback
|
|
18
|
-
* onValidate de Form o en la acción validationsActions.validateForm
|
|
19
|
-
*/
|
|
20
|
-
declare function hasSucceedFormValidation<ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType>(result: TValidationResult<ValueType, SubmitValueType>): result is TSuccessfulValidation<ValueType, SubmitValueType>;
|
|
21
|
-
/**
|
|
22
|
-
* Devuelve la cadena correspondiente a un código
|
|
23
|
-
* de error, realizando los reemplazos correspondientes.
|
|
24
|
-
*/
|
|
25
|
-
declare function lang(errorCode: keyof typeof formcheckLanguage, ...replacements: (string | number)[]): string;
|
|
26
|
-
declare function classToValidationFunction<T = string>(className: string): TValidationField<T>['validationFunction'];
|
|
27
|
-
declare function classToValidate(className: string): IFieldDefinition['validate'];
|
|
28
|
-
/**
|
|
29
|
-
* Realiza la carga de los mensajes de errores para el lenguaje
|
|
30
|
-
* especificado. Este método debe llamarse antes de utilizar
|
|
31
|
-
* las validaciones.
|
|
32
|
-
*/
|
|
33
|
-
declare function initValidations(): Promise<void>;
|
|
34
|
-
|
|
35
|
-
export { classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, lang };
|
|
36
|
-
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { TPropsSelector, TPropsComparator, TPropsConfiguration } from '@apia/util';
|
|
2
|
-
import { TValidationField, TFormState, TRegisterField, TRegisterFieldOptions, TValidationResult } from './types.js';
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
interface Window {
|
|
6
|
-
MSG_WRONG_VALIDATION_NO_FOCUSED_FILE: string;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
declare const validationsStore: {
|
|
10
|
-
activeForms: string[];
|
|
11
|
-
timeouts: Record<string, ReturnType<typeof setTimeout> | true>;
|
|
12
|
-
getFieldStore(formName: string, fieldName: string): TValidationField;
|
|
13
|
-
getFormStore(formName: string): TFormState;
|
|
14
|
-
updateFieldStore(formName: string, fieldName: string, props: Partial<TValidationField>, noEmit?: boolean): void;
|
|
15
|
-
updateFormStore(formName: string, newState: Partial<TFormState>): void;
|
|
16
|
-
enableFormTouch(formName: string): void;
|
|
17
|
-
existsField: (formName: string, fieldName: string) => boolean;
|
|
18
|
-
makeFieldName(formName: string, fieldName: string): string;
|
|
19
|
-
makeFormName(formName: string): string;
|
|
20
|
-
resetForm(formName: string): void;
|
|
21
|
-
registerField: (formName: string, registerData: TRegisterField, options?: TRegisterFieldOptions) => void;
|
|
22
|
-
/**
|
|
23
|
-
* Inicializa el estado de un nuevo formulario
|
|
24
|
-
*/
|
|
25
|
-
registerForm: (formName: string, props?: Partial<{
|
|
26
|
-
avoidFieldsOverride: boolean;
|
|
27
|
-
initialValues: Record<string, unknown>;
|
|
28
|
-
}>) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Setea el valor del campo con el nombre provisto. Si el campo no existe
|
|
31
|
-
* en el formulario lo crea.
|
|
32
|
-
*/
|
|
33
|
-
setFieldValue: (formName: string, fieldName: string, newValue: unknown, options?: Partial<{
|
|
34
|
-
avoidPropagation?: boolean | undefined;
|
|
35
|
-
markFormAsTouched: boolean;
|
|
36
|
-
}> | undefined) => void;
|
|
37
|
-
setFormIsTouched: (formName: string, isTouched?: boolean) => void;
|
|
38
|
-
/**
|
|
39
|
-
* Elimina un campo del registro de validación de un formulario. De esta
|
|
40
|
-
* forma cualquier validación que pudiera aplicarse sobre el mismo, ya no se
|
|
41
|
-
* aplicará.
|
|
42
|
-
*/
|
|
43
|
-
unregisterField: (formName: string, fieldName: string) => void;
|
|
44
|
-
/**
|
|
45
|
-
* Elimina un formulario del store de validación junto con todos los campos
|
|
46
|
-
* asociados al mismo.
|
|
47
|
-
*/
|
|
48
|
-
unregisterForm: (formName: string) => void;
|
|
49
|
-
/**
|
|
50
|
-
* Actualiza las propiedades de un campo, si no existe, lo registra en el
|
|
51
|
-
* formulario.
|
|
52
|
-
*/
|
|
53
|
-
updateField: (formName: string, field: Partial<TValidationField> & Pick<TValidationField, 'name'>, options?: Partial<{
|
|
54
|
-
avoidPropagation?: boolean | undefined;
|
|
55
|
-
markFormAsTouched: boolean;
|
|
56
|
-
}> | undefined) => void;
|
|
57
|
-
/**
|
|
58
|
-
* Actualiza múltiples campos al mismo tiempo.
|
|
59
|
-
*/
|
|
60
|
-
updateMultipleFields: (formName: string, fields: (Partial<TValidationField> & Pick<TValidationField, 'name'>)[], options?: Partial<{
|
|
61
|
-
avoidPropagation?: boolean | undefined;
|
|
62
|
-
markFormAsTouched: boolean;
|
|
63
|
-
}> | undefined) => void;
|
|
64
|
-
/**
|
|
65
|
-
* Ejecuta la validación sobre un formulario. En caso de que la validación
|
|
66
|
-
* falle, se intenta hacer foco sobre el campo que no pudo validar.
|
|
67
|
-
* Es importante notar que en caso de que un campo requiera validación,
|
|
68
|
-
* debería estar presente en el DOM.
|
|
69
|
-
*
|
|
70
|
-
* No es necesario que el campo esté visible, ya que en caso de estar oculto
|
|
71
|
-
* (por ejemplo por ser hijo de un acordeón), se emitirá un evento para
|
|
72
|
-
* expandir al elemento padre que lo estuviera ocultando.
|
|
73
|
-
*
|
|
74
|
-
* @returns Devuelve una promesa que al ser resuelta otorga un objeto de tipo
|
|
75
|
-
* TValidationResult. Este tipo está pensado para ser usado en conjunto con
|
|
76
|
-
* el método hasSucceedFormValidation, que determinará si la validación fue
|
|
77
|
-
* exitosa o hubo errores.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
*
|
|
81
|
-
* const result = await validationStore.validateForm('myForm');
|
|
82
|
-
* if(hasSucceedValidation(result)) {
|
|
83
|
-
* console.log('Success!', result);
|
|
84
|
-
* } else {
|
|
85
|
-
* console.error('Validation error', result);
|
|
86
|
-
* }
|
|
87
|
-
*/
|
|
88
|
-
validateForm: <ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType>(formName: string) => Promise<TValidationResult<ValueType, SubmitValueType>>;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Este hook permite suscribirse a los cambios realizados en el
|
|
92
|
-
* store de validación de un formulario. Funciona igual a un
|
|
93
|
-
* useAppSelector en cuanto a la función selectora y comparadora.
|
|
94
|
-
*
|
|
95
|
-
* @param selector
|
|
96
|
-
* @param comparator
|
|
97
|
-
* @returns
|
|
98
|
-
*/
|
|
99
|
-
declare function useFormSelector<Selected = any>(formName: string, selector: TPropsSelector<Selected, TFormState>, comparator?: TPropsComparator<Selected>): Selected;
|
|
100
|
-
/**
|
|
101
|
-
* Este hook permite suscribirse a los cambios realizados en el
|
|
102
|
-
* store de validación de un campo de formulario. Funciona igual a un
|
|
103
|
-
* useAppSelector en cuanto a la función selectora y comparadora.
|
|
104
|
-
*
|
|
105
|
-
* @param selector
|
|
106
|
-
* @param comparator
|
|
107
|
-
* @returns
|
|
108
|
-
*/
|
|
109
|
-
declare function useFieldSelector<ValueType = unknown, SubmitValueType = unknown, Selected = any>(formName: string, fieldName: string, selector?: TPropsSelector<Selected, TValidationField<ValueType, SubmitValueType>>, comparator?: TPropsComparator<Selected>): Selected;
|
|
110
|
-
declare function useFieldSelector<ValueType = unknown, SubmitValueType = unknown, Selected = any>(formName: string, fieldName: string, configurator?: TPropsConfiguration<Selected, TValidationField<ValueType, SubmitValueType>>): Selected;
|
|
111
|
-
|
|
112
|
-
export { useFieldSelector, useFormSelector, validationsStore };
|
|
113
|
-
//# sourceMappingURL=validationStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validationStore.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|