@apia/validations 3.0.1 → 3.0.2

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.
Files changed (117) hide show
  1. package/dist/{da.js → da-DqVKtoV2.js} +1 -1
  2. package/dist/da-DqVKtoV2.js.map +1 -0
  3. package/dist/{de.js → de-CcX9-Rq3.js} +1 -1
  4. package/dist/de-CcX9-Rq3.js.map +1 -0
  5. package/dist/{en.js → en-DCSKN2q5.js} +1 -1
  6. package/dist/en-DCSKN2q5.js.map +1 -0
  7. package/dist/{es.js → es-C-AXrgsF.js} +1 -1
  8. package/dist/es-C-AXrgsF.js.map +1 -0
  9. package/dist/{fa.js → fa-CpOxXp-C.js} +1 -1
  10. package/dist/fa-CpOxXp-C.js.map +1 -0
  11. package/dist/{fr.js → fr-cmPfrK5Y.js} +1 -1
  12. package/dist/fr-cmPfrK5Y.js.map +1 -0
  13. package/dist/{gr.js → gr-CmqXMJsZ.js} +1 -1
  14. package/dist/gr-CmqXMJsZ.js.map +1 -0
  15. package/dist/{hr.js → hr-DIdEoOl4.js} +1 -1
  16. package/dist/hr-DIdEoOl4.js.map +1 -0
  17. package/dist/{hu.js → hu-VYwXwEzb.js} +1 -1
  18. package/dist/hu-VYwXwEzb.js.map +1 -0
  19. package/dist/index.d.ts +785 -25
  20. package/dist/index.js +195 -123
  21. package/dist/index.js.map +1 -1
  22. package/dist/{it.js → it-CZNo0Ds3.js} +1 -1
  23. package/dist/it-CZNo0Ds3.js.map +1 -0
  24. package/dist/{ja.js → ja-CK5iBGzP.js} +1 -1
  25. package/dist/ja-CK5iBGzP.js.map +1 -0
  26. package/dist/{jp.js → jp-CK5iBGzP.js} +1 -1
  27. package/dist/jp-CK5iBGzP.js.map +1 -0
  28. package/dist/{nl.js → nl-BSU5Z9PJ.js} +1 -1
  29. package/dist/nl-BSU5Z9PJ.js.map +1 -0
  30. package/dist/{pl.js → pl-BSq2_6nm.js} +1 -1
  31. package/dist/pl-BSq2_6nm.js.map +1 -0
  32. package/dist/{pt.js → pt-DJTrqO4_.js} +1 -1
  33. package/dist/pt-DJTrqO4_.js.map +1 -0
  34. package/dist/{ro.js → ro-CAAZmoW6.js} +1 -1
  35. package/dist/ro-CAAZmoW6.js.map +1 -0
  36. package/package.json +6 -6
  37. package/rollup.validations.mjs +68 -68
  38. package/dist/collector/Collector.d.ts +0 -34
  39. package/dist/collector/Collector.d.ts.map +0 -1
  40. package/dist/collector/CollectorField.d.ts +0 -41
  41. package/dist/collector/CollectorField.d.ts.map +0 -1
  42. package/dist/collector/ValidatedCollectorField.d.ts +0 -44
  43. package/dist/collector/ValidatedCollectorField.d.ts.map +0 -1
  44. package/dist/collector/fields/Button.d.ts +0 -13
  45. package/dist/collector/fields/Button.d.ts.map +0 -1
  46. package/dist/collector/fields/Checkbox.d.ts +0 -13
  47. package/dist/collector/fields/Checkbox.d.ts.map +0 -1
  48. package/dist/collector/fields/Input.d.ts +0 -11
  49. package/dist/collector/fields/Input.d.ts.map +0 -1
  50. package/dist/collector/fields/Label.d.ts +0 -13
  51. package/dist/collector/fields/Label.d.ts.map +0 -1
  52. package/dist/collector/fields/Select.d.ts +0 -26
  53. package/dist/collector/fields/Select.d.ts.map +0 -1
  54. package/dist/collector/fields/Textarea.d.ts +0 -11
  55. package/dist/collector/fields/Textarea.d.ts.map +0 -1
  56. package/dist/components/Captcha.d.ts +0 -13
  57. package/dist/components/Captcha.d.ts.map +0 -1
  58. package/dist/components/Checkbox.d.ts +0 -12
  59. package/dist/components/Checkbox.d.ts.map +0 -1
  60. package/dist/components/DeletableInput.d.ts +0 -9
  61. package/dist/components/DeletableInput.d.ts.map +0 -1
  62. package/dist/components/FieldWrapper.d.ts +0 -20
  63. package/dist/components/FieldWrapper.d.ts.map +0 -1
  64. package/dist/components/FileInput.d.ts +0 -11
  65. package/dist/components/FileInput.d.ts.map +0 -1
  66. package/dist/components/Input.d.ts +0 -9
  67. package/dist/components/Input.d.ts.map +0 -1
  68. package/dist/components/NumberInput.d.ts +0 -14
  69. package/dist/components/NumberInput.d.ts.map +0 -1
  70. package/dist/components/Radio.d.ts +0 -14
  71. package/dist/components/Radio.d.ts.map +0 -1
  72. package/dist/components/Select.d.ts +0 -17
  73. package/dist/components/Select.d.ts.map +0 -1
  74. package/dist/components/Switchbox.d.ts +0 -11
  75. package/dist/components/Switchbox.d.ts.map +0 -1
  76. package/dist/components/Textarea.d.ts +0 -9
  77. package/dist/components/Textarea.d.ts.map +0 -1
  78. package/dist/components/ValidationError.d.ts +0 -17
  79. package/dist/components/ValidationError.d.ts.map +0 -1
  80. package/dist/components/types.d.ts +0 -11
  81. package/dist/components/types.d.ts.map +0 -1
  82. package/dist/da.js.map +0 -1
  83. package/dist/de.js.map +0 -1
  84. package/dist/en.js.map +0 -1
  85. package/dist/es.js.map +0 -1
  86. package/dist/fa.js.map +0 -1
  87. package/dist/form/Form.d.ts +0 -89
  88. package/dist/form/Form.d.ts.map +0 -1
  89. package/dist/form/FormContext.d.ts +0 -27
  90. package/dist/form/FormContext.d.ts.map +0 -1
  91. package/dist/fr.js.map +0 -1
  92. package/dist/gr.js.map +0 -1
  93. package/dist/hooks/useField.d.ts +0 -76
  94. package/dist/hooks/useField.d.ts.map +0 -1
  95. package/dist/hooks/useFieldStatesClassNames.d.ts +0 -4
  96. package/dist/hooks/useFieldStatesClassNames.d.ts.map +0 -1
  97. package/dist/hooks/useFieldValue.d.ts +0 -8
  98. package/dist/hooks/useFieldValue.d.ts.map +0 -1
  99. package/dist/hooks/useValidationClass.d.ts +0 -49
  100. package/dist/hooks/useValidationClass.d.ts.map +0 -1
  101. package/dist/hr.js.map +0 -1
  102. package/dist/hu.js.map +0 -1
  103. package/dist/it.js.map +0 -1
  104. package/dist/ja.js.map +0 -1
  105. package/dist/jp.js.map +0 -1
  106. package/dist/lang/es.d.ts +0 -32
  107. package/dist/lang/es.d.ts.map +0 -1
  108. package/dist/nl.js.map +0 -1
  109. package/dist/pl.js.map +0 -1
  110. package/dist/pt.js.map +0 -1
  111. package/dist/ro.js.map +0 -1
  112. package/dist/types.d.ts +0 -130
  113. package/dist/types.d.ts.map +0 -1
  114. package/dist/util.d.ts +0 -36
  115. package/dist/util.d.ts.map +0 -1
  116. package/dist/validationStore.d.ts +0 -112
  117. package/dist/validationStore.d.ts.map +0 -1
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
@@ -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
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,112 +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
- registerField: (formName: string, registerData: TRegisterField, options?: TRegisterFieldOptions) => void;
21
- /**
22
- * Inicializa el estado de un nuevo formulario
23
- */
24
- registerForm: (formName: string, props?: Partial<{
25
- avoidFieldsOverride: boolean;
26
- initialValues: Record<string, unknown>;
27
- }>) => void;
28
- /**
29
- * Setea el valor del campo con el nombre provisto. Si el campo no existe
30
- * en el formulario lo crea.
31
- */
32
- setFieldValue: (formName: string, fieldName: string, newValue: unknown, options?: Partial<{
33
- avoidPropagation?: boolean | undefined;
34
- markFormAsTouched: boolean;
35
- }> | undefined) => void;
36
- setFormIsTouched: (formName: string, isTouched?: boolean) => void;
37
- /**
38
- * Elimina un campo del registro de validación de un formulario. De esta
39
- * forma cualquier validación que pudiera aplicarse sobre el mismo, ya no se
40
- * aplicará.
41
- */
42
- unregisterField: (formName: string, fieldName: string) => void;
43
- /**
44
- * Elimina un formulario del store de validación junto con todos los campos
45
- * asociados al mismo.
46
- */
47
- unregisterForm: (formName: string) => void;
48
- /**
49
- * Actualiza las propiedades de un campo, si no existe, lo registra en el
50
- * formulario.
51
- */
52
- updateField: (formName: string, field: Partial<TValidationField> & Pick<TValidationField, 'name'>, options?: Partial<{
53
- avoidPropagation?: boolean | undefined;
54
- markFormAsTouched: boolean;
55
- }> | undefined) => void;
56
- /**
57
- * Actualiza múltiples campos al mismo tiempo.
58
- */
59
- updateMultipleFields: (formName: string, fields: (Partial<TValidationField> & Pick<TValidationField, 'name'>)[], options?: Partial<{
60
- avoidPropagation?: boolean | undefined;
61
- markFormAsTouched: boolean;
62
- }> | undefined) => void;
63
- /**
64
- * Ejecuta la validación sobre un formulario. En caso de que la validación
65
- * falle, se intenta hacer foco sobre el campo que no pudo validar.
66
- * Es importante notar que en caso de que un campo requiera validación,
67
- * debería estar presente en el DOM.
68
- *
69
- * No es necesario que el campo esté visible, ya que en caso de estar oculto
70
- * (por ejemplo por ser hijo de un acordeón), se emitirá un evento para
71
- * expandir al elemento padre que lo estuviera ocultando.
72
- *
73
- * @returns Devuelve una promesa que al ser resuelta otorga un objeto de tipo
74
- * TValidationResult. Este tipo está pensado para ser usado en conjunto con
75
- * el método hasSucceedFormValidation, que determinará si la validación fue
76
- * exitosa o hubo errores.
77
- *
78
- * @example
79
- *
80
- * const result = await validationStore.validateForm('myForm');
81
- * if(hasSucceedValidation(result)) {
82
- * console.log('Success!', result);
83
- * } else {
84
- * console.error('Validation error', result);
85
- * }
86
- */
87
- validateForm: <ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType>(formName: string) => Promise<TValidationResult<ValueType, SubmitValueType>>;
88
- };
89
- /**
90
- * Este hook permite suscribirse a los cambios realizados en el
91
- * store de validación de un formulario. Funciona igual a un
92
- * useAppSelector en cuanto a la función selectora y comparadora.
93
- *
94
- * @param selector
95
- * @param comparator
96
- * @returns
97
- */
98
- declare function useFormSelector<Selected = any>(formName: string, selector: TPropsSelector<Selected, TFormState>, comparator?: TPropsComparator<Selected>): Selected;
99
- /**
100
- * Este hook permite suscribirse a los cambios realizados en el
101
- * store de validación de un campo de formulario. Funciona igual a un
102
- * useAppSelector en cuanto a la función selectora y comparadora.
103
- *
104
- * @param selector
105
- * @param comparator
106
- * @returns
107
- */
108
- declare function useFieldSelector<ValueType = unknown, SubmitValueType = unknown, Selected = any>(formName: string, fieldName: string, selector?: TPropsSelector<Selected, TValidationField<ValueType, SubmitValueType>>, comparator?: TPropsComparator<Selected>): Selected;
109
- declare function useFieldSelector<ValueType = unknown, SubmitValueType = unknown, Selected = any>(formName: string, fieldName: string, configurator?: TPropsConfiguration<Selected, TValidationField<ValueType, SubmitValueType>>): Selected;
110
-
111
- export { useFieldSelector, useFormSelector, validationsStore };
112
- //# sourceMappingURL=validationStore.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validationStore.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}