@apia/validations 0.1.3 → 0.2.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.
package/LICENSE.md CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) [year] [fullname]
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,28 +1,28 @@
1
- # Initiator
2
-
3
- Este package se creó con la única utilidad de copiarlo entero y pegarlo a la hora de crear un nuevo package.
4
-
5
- Este iniciador permite crear un paquete que compila typescript y puede ser importado desde otros packages.
6
-
7
- ## IMPORTANTE
8
-
9
- Los archivos **tsconfig.json** y **tsup.config.ts** no son archivos únicos sino symlinks a archivos de configuración comunes a todos los packages. En caso de que sea necesario modificar alguno de ellos **que en la gran mayoría de los casos no sería necesario**, es necesario eliminar el archivo a modificar y crear uno nuevo.
10
-
11
- ## Procedimiento
12
-
13
- - Copiar la carpeta initiator y pegarla con otro nombre dentro de packages.
14
- - Modificar el package.json:
15
- - Eliminar la línea ```private: true```.
16
- - Cambiar la ocurrencia `initiator` por el nombre del nuevo paquete.
17
- - Agregar los scripts convenientes: dev, build, etc.
18
- - Ejecutar el comando lerna bootstrap desde la carpeta raíz.
19
-
20
- Luego de ejecutar estos pasos, el package estaría listo para comenzar a usarse.
21
-
22
- Este package trae como dependencias por defecto theme-ui y react. Si se desea agregar más dependencias se debe ejecutar el comando ```lerna add --scope="@apia/packageName" dependencyName```. Ejemplo, si creamos un paquete con el nombre @apia/myPackage y queremos agregar lodash como dependencia, ejecutamos el comando ```lerna add --scope="@apia/myPackage" lodash```.
23
-
24
- **Importante 1**: Dado que estamos desarrollando packages, es importante determinar si las dependencias que vamos a agregar son de tipo dependency o de tipo peerDependency.
25
-
26
- **Importante 2**: lerna no permite instalar de a varias dependencias a la vez como lo hace npm, por lo tanto, si se desea agregar varias dependencias se debe ejecutar el comando anterior tantas veces como dependencias se quiera agregar.
27
-
1
+ # Initiator
2
+
3
+ Este package se creó con la única utilidad de copiarlo entero y pegarlo a la hora de crear un nuevo package.
4
+
5
+ Este iniciador permite crear un paquete que compila typescript y puede ser importado desde otros packages.
6
+
7
+ ## IMPORTANTE
8
+
9
+ Los archivos **tsconfig.json** y **tsup.config.ts** no son archivos únicos sino symlinks a archivos de configuración comunes a todos los packages. En caso de que sea necesario modificar alguno de ellos **que en la gran mayoría de los casos no sería necesario**, es necesario eliminar el archivo a modificar y crear uno nuevo.
10
+
11
+ ## Procedimiento
12
+
13
+ - Copiar la carpeta initiator y pegarla con otro nombre dentro de packages.
14
+ - Modificar el package.json:
15
+ - Eliminar la línea ```private: true```.
16
+ - Cambiar la ocurrencia `initiator` por el nombre del nuevo paquete.
17
+ - Agregar los scripts convenientes: dev, build, etc.
18
+ - Ejecutar el comando lerna bootstrap desde la carpeta raíz.
19
+
20
+ Luego de ejecutar estos pasos, el package estaría listo para comenzar a usarse.
21
+
22
+ Este package trae como dependencias por defecto theme-ui y react. Si se desea agregar más dependencias se debe ejecutar el comando ```lerna add --scope="@apia/packageName" dependencyName```. Ejemplo, si creamos un paquete con el nombre @apia/myPackage y queremos agregar lodash como dependencia, ejecutamos el comando ```lerna add --scope="@apia/myPackage" lodash```.
23
+
24
+ **Importante 1**: Dado que estamos desarrollando packages, es importante determinar si las dependencias que vamos a agregar son de tipo dependency o de tipo peerDependency.
25
+
26
+ **Importante 2**: lerna no permite instalar de a varias dependencias a la vez como lo hace npm, por lo tanto, si se desea agregar varias dependencias se debe ejecutar el comando anterior tantas veces como dependencias se quiera agregar.
27
+
28
28
  **Importante 3**: React y theme-ui vienen instalados como peerDependencies. En caso de no ser necesarios pueden ser removidos, pero en cualquier caso asegurarse de que estas dependencias no sean instaladas como dependencies puesto que esto causaría comportamientos indeseados en la aplicación.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import * as theme_ui_jsx_runtime from 'theme-ui/jsx-runtime';
2
- import React from 'react';
1
+ import * as React from 'react';
2
+ import React__default from 'react';
3
3
  import { TModify, TPropsSelector, TPropsComparator, TPropsConfiguration } from '@apia/util';
4
- import { BoxProps, ButtonProps, InputProps, LabelProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from 'theme-ui';
4
+ import { BoxProps, ButtonProps, InputProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from '@apia/theme';
5
5
  import { TNumberInput } from '@apia/components';
6
6
 
7
7
  declare const formcheckLanguage: {
@@ -34,11 +34,6 @@ declare const formcheckLanguage: {
34
34
  errorsTitle: string;
35
35
  };
36
36
 
37
- declare global {
38
- interface Window {
39
- [key: string]: string;
40
- }
41
- }
42
37
  type TValidate = Partial<TModify<Record<keyof typeof formcheckLanguage, boolean>, {
43
38
  digitmin: number;
44
39
  digitltd: [number, number];
@@ -175,7 +170,7 @@ interface IForm<ValueType extends Record<string, unknown>, SubmitValueType exten
175
170
  * Impide que se apliquen los estilos que indican que un campo fue alterado.
176
171
  */
177
172
  avoidFieldsTouch?: boolean;
178
- children: React.ReactNode;
173
+ children: React__default.ReactNode;
179
174
  className?: string;
180
175
  initialValues?: Partial<ValueType>;
181
176
  name?: string;
@@ -192,14 +187,67 @@ interface IForm<ValueType extends Record<string, unknown>, SubmitValueType exten
192
187
  */
193
188
  unregisterOnUnmount?: boolean;
194
189
  }
195
- declare const Form: <ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType>({ avoidFieldsOverride, avoidFieldsTouch, children, className, name, initialValues, onUnmount, onValidate, unregisterOnUnmount, }: IForm<ValueType, SubmitValueType>) => theme_ui_jsx_runtime.JSX.Element | null;
190
+ /**
191
+ * Cuando se desea usar el sistema de validación,
192
+ * se debe utilizar este componente como form contenedor
193
+ * de todos los campos que quieran validarse.
194
+ *
195
+ * Es importante que no se coloquen formularios dentro
196
+ * de formularios ya que esto podría afectar negativamente
197
+ * el proceso de validación.
198
+ *
199
+ * @props
200
+ * *name:* Se puede pasar un nombre para identificar
201
+ * el form. Este nombre será utilizado para almacenar
202
+ * la información en Redux, por lo que si se desea
203
+ * acceder a la información recolectada por la librería,
204
+ * es conveniente pasar un nombre conocido y único. En
205
+ * caso de no se pase ningún nombre, la aplicación
206
+ * generará un nombre único automaticamente.
207
+ *
208
+ * *onValidate:* Un callback que será llamado cuando
209
+ * se invoque el método validateForm del store o cuando
210
+ * se lance el evento de submit del elemento form (por
211
+ * ejemplo mediante un click en un botón que no tenga
212
+ * type="button"), con el resultado de la validación.
213
+ *
214
+ * avoidFieldsOverride
215
+ * avoidFieldsTouch
216
+ *
217
+ * @see useField
218
+ * @see useForm
219
+ *
220
+ * @important Debido a que este hook renderiza un elemento
221
+ * form en el DOM, es importante agregar el atributo
222
+ * type="button" a todos los botones dentro del formulario
223
+ * que no se desea que disparen la validación.
224
+ *
225
+ * @example
226
+ * Para ver un ejemplo funcional, mira el componente
227
+ * Invitations.tsx
228
+ *
229
+ * // IMPORTANTE: El tipado del componente Form es genérico
230
+ * // por lo que es posible instanciarlo como se muestra a
231
+ * // continuación, lo que nos da el tipado correcto en el
232
+ * // callback onValidate.
233
+ * <Form<FormDataType> onValidate={(res) => {
234
+ * if(hasSucceedValidation(res)) {
235
+ * // Do something with submitValues
236
+ * } else {
237
+ * // Do something with errors
238
+ * }
239
+ * }}>
240
+ * ...{children}
241
+ * </Form>
242
+ */
243
+ declare const Form: <ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType>({ avoidFieldsOverride, avoidFieldsTouch, children, className, name, initialValues, onUnmount, onValidate, unregisterOnUnmount, }: IForm<ValueType, SubmitValueType>) => React__default.JSX.Element | null;
196
244
 
197
245
  interface IFormContext<ValueType extends Record<string, unknown> = Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType> {
198
246
  avoidFieldsTouch?: boolean;
199
247
  name: string;
200
248
  validate: () => Promise<TValidationResult<ValueType, SubmitValueType>>;
201
249
  }
202
- declare const FormContext: React.Context<IFormContext<Record<string, unknown>, Record<string, unknown>>>;
250
+ declare const FormContext: React__default.Context<IFormContext<Record<string, unknown>, Record<string, unknown>>>;
203
251
  /**
204
252
  * Provee acceso de forma sencilla al contexto de
205
253
  * validación, que básicamente posee el nombre del
@@ -216,6 +264,11 @@ declare const FormContext: React.Context<IFormContext<Record<string, unknown>, R
216
264
  */
217
265
  declare function useFormContext(): IFormContext<Record<string, unknown>, Record<string, unknown>>;
218
266
 
267
+ declare global {
268
+ interface Window {
269
+ MSG_WRONG_VALIDATION_NO_FOCUSED_FILE: string;
270
+ }
271
+ }
219
272
  declare const validationsStore: {
220
273
  activeForms: string[];
221
274
  timeouts: Record<string, ReturnType<typeof setTimeout> | true>;
@@ -318,6 +371,13 @@ declare function useFormSelector<Selected = any>(formName: string, selector: TPr
318
371
  declare function useFieldSelector<ValueType = unknown, SubmitValueType = unknown, Selected = any>(formName: string, fieldName: string, selector?: TPropsSelector<Selected, TValidationField<ValueType, SubmitValueType>>, comparator?: TPropsComparator<Selected>): Selected;
319
372
  declare function useFieldSelector<ValueType = unknown, SubmitValueType = unknown, Selected = any>(formName: string, fieldName: string, configurator?: TPropsConfiguration<Selected, TValidationField<ValueType, SubmitValueType>>): Selected;
320
373
 
374
+ declare global {
375
+ interface Window {
376
+ NO_LANGUAGE_EXCEPTION: string;
377
+ MSG_INVALID_REG_EXP: string;
378
+ GNR_INVALID_NAME: string;
379
+ }
380
+ }
321
381
  /**
322
382
  * Determina si la validación de un campo resultó exitosa.
323
383
  */
@@ -403,20 +463,25 @@ declare function useField<ValueType = unknown, SubmitValueType = ValueType>(fiel
403
463
  error: string | null | undefined;
404
464
  isTouched: boolean;
405
465
  name: string;
406
- onChange: (ev: React.ChangeEvent | ValueType) => void;
466
+ onChange: (ev: React__default.ChangeEvent | ValueType) => void;
407
467
  updateValidations: ({ validationFunction, validationRules, }: Pick<TValidationField, 'validationRules' | 'validationFunction'>) => void;
408
468
  value: ValueType;
409
469
  };
410
470
 
471
+ declare global {
472
+ interface Window {
473
+ SHOW_REQUIRED_POSITION: string;
474
+ }
475
+ }
411
476
  interface IWrapper extends BoxProps {
412
477
  avoidSemicolon?: boolean;
413
- children: React.ReactNode;
478
+ children: React__default.ReactNode;
414
479
  label?: string;
415
480
  name: string;
416
481
  required?: boolean;
417
482
  type?: 'checkbox';
418
483
  }
419
- declare const FieldWrapper: ({ name, label, avoidSemicolon, children, className, as, type, ...props }: IWrapper) => theme_ui_jsx_runtime.JSX.Element;
484
+ declare const FieldWrapper: ({ name, label, avoidSemicolon, children, className, as, type, ...props }: IWrapper) => React__default.JSX.Element;
420
485
 
421
486
  type TDefaultFieldType<ValueType = string> = Omit<TUseField<ValueType>, 'error' | 'value' | 'isTouched'> & {
422
487
  label?: string;
@@ -430,31 +495,29 @@ type TCaptchaProps = {
430
495
  className?: string;
431
496
  };
432
497
  type TCaptcha = TCaptchaProps & Omit<TDefaultFieldType, 'validationFunction' | 'validationRules' | 'validationClass'>;
433
- declare const InnerCaptcha: ({ className, name, imageUrl, avoidRegisterIfExists, avoidSemicolon, formName, label, removeOnUnmount, submitName, submitValueParser, validationValueParser, }: TCaptcha) => theme_ui_jsx_runtime.JSX.Element;
498
+ declare const InnerCaptcha: ({ className, name, imageUrl, avoidRegisterIfExists, avoidSemicolon, formName, label, removeOnUnmount, submitName, submitValueParser, validationValueParser, }: TCaptcha) => React__default.JSX.Element;
434
499
 
435
500
  type TCheckbox = Omit<ButtonProps, 'onChange'> & Omit<Pick<InputProps, 'onChange'>, 'value'> & TDefaultFieldType<boolean | string> & {
436
501
  native?: boolean;
437
502
  };
438
- declare const Checkbox: React.ForwardRefExoticComponent<Omit<TCheckbox, "ref"> & React.RefAttributes<HTMLButtonElement>>;
503
+ declare const Checkbox: React__default.ForwardRefExoticComponent<Omit<TCheckbox, "ref"> & React__default.RefAttributes<HTMLButtonElement>>;
439
504
 
440
505
  type TDeletableInput = InputProps & TDefaultFieldType;
441
- declare const DeletableInput: React.ForwardRefExoticComponent<Omit<TDeletableInput, "ref"> & React.RefAttributes<HTMLInputElement>>;
442
-
443
- type TFieldLabel = LabelProps & {
444
- avoidSemicolon?: boolean;
445
- children?: React.ReactNode;
446
- required?: boolean;
447
- };
448
- declare const FieldLabel: ({ avoidSemicolon, children, required, ...props }: TFieldLabel) => theme_ui_jsx_runtime.JSX.Element;
506
+ declare const DeletableInput: React__default.ForwardRefExoticComponent<Omit<TDeletableInput, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
449
507
 
450
508
  type TFileInput = Omit<InputProps, 'onChange' | 'type' | 'value' | 'multiple'> & TDefaultFieldType<File | null> & Pick<TUseField, 'removeOnUnmount'> & Pick<IWrapper, 'avoidSemicolon'>;
451
- declare const FileInput: React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<TFileInput, "ref"> & React.RefAttributes<HTMLInputElement>>>;
509
+ declare const FileInput: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<Omit<TFileInput, "ref"> & React__default.RefAttributes<HTMLInputElement>>>;
452
510
 
453
511
  type TInput$1 = InputProps & TDefaultFieldType;
454
- declare const Input: React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<TInput$1, "ref"> & React.RefAttributes<HTMLInputElement>>>;
512
+ declare const Input: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<Omit<TInput$1, "ref"> & React__default.RefAttributes<HTMLInputElement>>>;
455
513
 
514
+ declare global {
515
+ interface Window {
516
+ GNR_NUMERIC: string;
517
+ }
518
+ }
456
519
  type TInput = TNumberInput & TDefaultFieldType;
457
- declare const NumberInputf: React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<TInput, "ref"> & React.RefAttributes<HTMLInputElement>>>;
520
+ declare const NumberInputf: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<Omit<TInput, "ref"> & React__default.RefAttributes<HTMLInputElement>>>;
458
521
 
459
522
  type TRadio = RadioProps & TDefaultFieldType & {
460
523
  options: {
@@ -462,7 +525,7 @@ type TRadio = RadioProps & TDefaultFieldType & {
462
525
  label: string;
463
526
  }[];
464
527
  };
465
- declare const Radio: React.ForwardRefExoticComponent<Omit<TRadio, "ref"> & React.RefAttributes<HTMLInputElement>>;
528
+ declare const Radio: React__default.ForwardRefExoticComponent<Omit<TRadio, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
466
529
 
467
530
  type TSelect = Omit<SelectProps, 'defaultValue'> & TDefaultFieldType & {
468
531
  options: {
@@ -470,15 +533,15 @@ type TSelect = Omit<SelectProps, 'defaultValue'> & TDefaultFieldType & {
470
533
  label: string;
471
534
  }[];
472
535
  };
473
- declare const Select: React.ForwardRefExoticComponent<Omit<TSelect, "ref"> & React.RefAttributes<HTMLSelectElement>>;
536
+ declare const Select: React__default.ForwardRefExoticComponent<Omit<TSelect, "ref"> & React__default.RefAttributes<HTMLSelectElement>>;
474
537
 
475
538
  type TSwitchbox = Omit<SwitchProps, 'onChange'> & Pick<InputProps, 'onChange'> & TDefaultFieldType & {
476
539
  reverse?: boolean;
477
540
  };
478
- declare const Switchbox: React.ForwardRefExoticComponent<Omit<TSwitchbox, "ref"> & React.RefAttributes<HTMLInputElement>>;
541
+ declare const Switchbox: React__default.ForwardRefExoticComponent<Omit<TSwitchbox, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
479
542
 
480
543
  type TTextarea = TextareaProps & TDefaultFieldType;
481
- declare const Textarea: React.ForwardRefExoticComponent<Omit<TTextarea, "ref"> & React.RefAttributes<HTMLTextAreaElement>>;
544
+ declare const Textarea: React__default.ForwardRefExoticComponent<Omit<TTextarea, "ref"> & React__default.RefAttributes<HTMLTextAreaElement>>;
482
545
 
483
546
  /**
484
547
  * Renderiza los errores del campo con el nombre pasado
@@ -491,7 +554,7 @@ declare const Textarea: React.ForwardRefExoticComponent<Omit<TTextarea, "ref"> &
491
554
  */
492
555
  declare const ValidationError: ({ name }: {
493
556
  name: string;
494
- }) => theme_ui_jsx_runtime.JSX.Element | null;
557
+ }) => React.JSX.Element | null;
495
558
 
496
559
  declare function useFieldStatesClassNames<T = unknown>(name: string, formName?: string): string;
497
560
 
@@ -544,4 +607,4 @@ declare function useValidationClass<T>({ customValidation, validationClass, vali
544
607
  };
545
608
  };
546
609
 
547
- export { InnerCaptcha as Captcha, Checkbox, DeletableInput, FieldLabel, FieldWrapper, FileInput, Form, FormContext, IWrapper, Input, NumberInputf, Radio, Select, Switchbox, TCheckbox, TDefaultFieldType, TFieldLabel, TInput$1 as TInput, TOnValidate, TRadio, TSelect, TSwitchbox, TUseField, TValidationResult, Textarea, ValidationError, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidationClass, validationsStore };
610
+ export { InnerCaptcha as Captcha, Checkbox, DeletableInput, FieldWrapper, FileInput, Form, FormContext, IWrapper, Input, NumberInputf, Radio, Select, Switchbox, TCheckbox, TDefaultFieldType, TInput$1 as TInput, TOnValidate, TRadio, TSelect, TSwitchbox, TUseField, TValidationResult, Textarea, ValidationError, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidationClass, validationsStore };