@apia/validations 0.0.9-alpha.0 → 0.1.0

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/cleanDist.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "cleanDist": 0.7200462826014478
3
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as theme_ui_jsx_runtime from 'theme-ui/jsx-runtime';
2
2
  import React from 'react';
3
- import { TModify, TId } from '@apia/util';
3
+ import { TModify, TPropsSelector, TPropsComparator, TPropsConfiguration } from '@apia/util';
4
4
  import { BoxProps, ButtonProps, InputProps, LabelProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from 'theme-ui';
5
5
  import { TNumberInput } from '@apia/components';
6
6
 
@@ -192,56 +192,6 @@ interface IForm<ValueType extends Record<string, unknown>, SubmitValueType exten
192
192
  */
193
193
  unregisterOnUnmount?: boolean;
194
194
  }
195
- /**
196
- * Cuando se desea usar el sistema de validación,
197
- * se debe utilizar este componente como form contenedor
198
- * de todos los campos que quieran validarse.
199
- *
200
- * Es importante que no se coloquen formularios dentro
201
- * de formularios ya que esto podría afectar negativamente
202
- * el proceso de validación.
203
- *
204
- * @props
205
- * *name:* Se puede pasar un nombre para identificar
206
- * el form. Este nombre será utilizado para almacenar
207
- * la información en Redux, por lo que si se desea
208
- * acceder a la información recolectada por la librería,
209
- * es conveniente pasar un nombre conocido y único. En
210
- * caso de no se pase ningún nombre, la aplicación
211
- * generará un nombre único automaticamente.
212
- *
213
- * *onValidate:* Un callback que será llamado cuando
214
- * se invoque el método validateForm del store o cuando
215
- * se lance el evento de submit del elemento form (por
216
- * ejemplo mediante un click en un botón que no tenga
217
- * type="button"), con el resultado de la validación.
218
- *
219
- * @see useField
220
- * @see useForm
221
- *
222
- * @important Debido a que este hook renderiza un elemento
223
- * form en el DOM, es importante agregar el atributo
224
- * type="button" a todos los botones dentro del formulario
225
- * que no se desea que disparen la validación.
226
- *
227
- * @example
228
- * Para ver un ejemplo funcional, mira el componente
229
- * Invitations.tsx
230
- *
231
- * // IMPORTANTE: El tipado del componente Form es genérico
232
- * // por lo que es posible instanciarlo como se muestra a
233
- * // continuación, lo que nos da el tipado correcto en el
234
- * // callback onValidate.
235
- * <Form<FormDataType> onValidate={(res) => {
236
- * if(hasSucceedValidation(res)) {
237
- * // Do something with submitValues
238
- * } else {
239
- * // Do something with errors
240
- * }
241
- * }}>
242
- * ...{children}
243
- * </Form>
244
- */
245
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;
246
196
 
247
197
  interface IFormContext<ValueType extends Record<string, unknown> = Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType> {
@@ -266,61 +216,6 @@ declare const FormContext: React.Context<IFormContext<Record<string, unknown>, R
266
216
  */
267
217
  declare function useFormContext(): IFormContext<Record<string, unknown>, Record<string, unknown>>;
268
218
 
269
- interface IPropsStoreConf {
270
- logCommands: {
271
- propsStore?: string;
272
- updateProp?: string;
273
- propsSuscriptors?: string;
274
- propsLog?: string;
275
- };
276
- }
277
- declare class PropsStore<PropsType extends Record<TId, unknown> = Record<TId, unknown>> {
278
- private configuration?;
279
- log: unknown;
280
- fields: Record<TId, PropsType>;
281
- suscriptors: Record<TId, TPropsSuscriptor<PropsType>[]>;
282
- loggers: Record<string, (props: unknown[]) => void>;
283
- constructor(configuration?: IPropsStoreConf | undefined);
284
- destructor(): void;
285
- getAllFields(): Record<TId, PropsType>;
286
- /**
287
- * Devuelve los props actuales de un campo.
288
- */
289
- getFieldProps<ParsedPropsType = PropsType>(fieldId: TId): ParsedPropsType;
290
- removeField(fieldId: TId): void;
291
- /**
292
- * Permite establecer un suscriptor que será llamado
293
- * cada vez que las props del campo especificado cambien.
294
- */
295
- suscribe(fieldId: TId, callback: TPropsSuscriptor<PropsType>): () => void;
296
- /**
297
- * Actualiza o crea las props de un campo.
298
- *
299
- * La tercera prop está relacionada
300
- */
301
- updateField<NewPropsType extends Record<TId, unknown> = Partial<PropsType>>(fieldId: TId, props: Partial<NewPropsType>, conf?: TUpdateFieldConfiguration): void;
302
- }
303
-
304
- type TProperties = Record<string, unknown>;
305
- type TPropsSuscriptor<PropsType extends Record<string, unknown> = TProperties> = (props: PropsType, urgent?: boolean) => unknown;
306
- type TPropsSelector<Selected = any, PropsType = TProperties> = (props: PropsType) => Selected;
307
- /**
308
- * La función comparadora debe devolver true cuando
309
- * los elementos son iguales o false cuando son
310
- * distintos.
311
- */
312
- type TPropsComparator<Selected> = (prevProps: Selected | undefined, newProps: Selected | undefined) => boolean;
313
- type TPropsConfiguration<Selected, PropsType extends Record<string, unknown> = TProperties> = {
314
- selector?: TPropsSelector<Selected, PropsType>;
315
- comparator?: TPropsComparator<Selected>;
316
- initialValue?: Selected;
317
- propsStore?: PropsStore<PropsType>;
318
- };
319
- type TUpdateFieldConfiguration = Partial<{
320
- noEmit: boolean;
321
- isUrgent: boolean;
322
- }>;
323
-
324
219
  declare const validationsStore: {
325
220
  activeForms: string[];
326
221
  timeouts: Record<string, ReturnType<typeof setTimeout> | true>;
@@ -514,13 +409,14 @@ declare function useField<ValueType = unknown, SubmitValueType = ValueType>(fiel
514
409
  };
515
410
 
516
411
  interface IWrapper extends BoxProps {
517
- name: string;
518
- label?: string;
412
+ avoidSemicolon?: boolean;
519
413
  children: React.ReactNode;
414
+ label?: string;
415
+ name: string;
520
416
  required?: boolean;
521
- avoidSemicolon?: boolean;
417
+ type?: 'checkbox';
522
418
  }
523
- declare const FieldWrapper: ({ name, label, avoidSemicolon, children, className, as, ...props }: IWrapper) => theme_ui_jsx_runtime.JSX.Element;
419
+ declare const FieldWrapper: ({ name, label, avoidSemicolon, children, className, as, type, ...props }: IWrapper) => theme_ui_jsx_runtime.JSX.Element;
524
420
 
525
421
  type TDefaultFieldType<ValueType = string> = Omit<TUseField<ValueType>, 'error' | 'value' | 'isTouched'> & {
526
422
  label?: string;
@@ -528,7 +424,15 @@ type TDefaultFieldType<ValueType = string> = Omit<TUseField<ValueType>, 'error'
528
424
  validationClass?: string;
529
425
  } & Pick<IWrapper, 'avoidSemicolon'>;
530
426
 
531
- type TCheckbox = Omit<ButtonProps, 'onChange'> & Pick<InputProps, 'onChange'> & TDefaultFieldType & {
427
+ type TCaptchaProps = {
428
+ name: string;
429
+ imageUrl: string;
430
+ className?: string;
431
+ };
432
+ 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;
434
+
435
+ type TCheckbox = Omit<ButtonProps, 'onChange'> & Omit<Pick<InputProps, 'onChange'>, 'value'> & TDefaultFieldType<boolean | string> & {
532
436
  native?: boolean;
533
437
  };
534
438
  declare const Checkbox: React.ForwardRefExoticComponent<Omit<TCheckbox, "ref"> & React.RefAttributes<HTMLButtonElement>>;
@@ -560,7 +464,7 @@ type TRadio = RadioProps & TDefaultFieldType & {
560
464
  };
561
465
  declare const Radio: React.ForwardRefExoticComponent<Omit<TRadio, "ref"> & React.RefAttributes<HTMLInputElement>>;
562
466
 
563
- type TSelect = SelectProps & TDefaultFieldType & {
467
+ type TSelect = Omit<SelectProps, 'defaultValue'> & TDefaultFieldType & {
564
468
  options: {
565
469
  value: string;
566
470
  label: string;
@@ -640,4 +544,5 @@ declare function useValidationClass<T>({ customValidation, validationClass, vali
640
544
  };
641
545
  };
642
546
 
643
- export { Checkbox, DeletableInput, FieldLabel, FieldWrapper, FileInput, Form, FormContext, IWrapper, Input, NumberInputf, Radio, Select, Switchbox, TCheckbox, TDefaultFieldType, TFieldLabel, TInput$1 as TInput, TRadio, TSelect, TSwitchbox, TUseField, Textarea, ValidationError, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidationClass, validationsStore };
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 };
548
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}