@apia/validations 0.3.6 → 1.0.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 +1 -1
- package/dist/index.d.ts +73 -5
- package/dist/index.js +468 -292
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/cleanDist.json
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default from 'react';
|
|
3
|
-
import { TModify, TPropsSelector, TPropsComparator, TPropsConfiguration } from '@apia/util';
|
|
2
|
+
import React__default, { FC } from 'react';
|
|
3
|
+
import { TModify, TPropsSelector, TPropsComparator, TPropsConfiguration, EventEmitter } from '@apia/util';
|
|
4
|
+
import { TOpenModal, TNumberInput } from '@apia/components';
|
|
4
5
|
import { BoxProps, ButtonProps, InputProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from '@apia/theme';
|
|
5
|
-
import { TNumberInput } from '@apia/components';
|
|
6
6
|
|
|
7
7
|
declare const formcheckLanguage: {
|
|
8
8
|
required: string;
|
|
@@ -84,6 +84,7 @@ type TFieldValidationResult = true | string;
|
|
|
84
84
|
type TValidationFunction<ValueType> = (value: ValueType, formName: string) => TPromiseOrNot<TFieldValidationResult>;
|
|
85
85
|
type TValidationSubmitValueParser<ValueType = unknown, SubmitValueType = ValueType> = (value: ValueType) => SubmitValueType;
|
|
86
86
|
type TValidationValueParser<ValueType = unknown, ValidationValueType = unknown> = (value: ValueType) => ValidationValueType;
|
|
87
|
+
type TValidationRules = IFieldDefinition['validate'];
|
|
87
88
|
/**
|
|
88
89
|
* Esta interfaz representa el estado de un campo dentro
|
|
89
90
|
* del hook de validación.
|
|
@@ -131,7 +132,7 @@ type TValidationField<ValueType = any, SubmitValueType = ValueType> = {
|
|
|
131
132
|
* Permite pasar una serie de reglas que el campo debe cumplir
|
|
132
133
|
* al validar.
|
|
133
134
|
*/
|
|
134
|
-
validationRules?:
|
|
135
|
+
validationRules?: TValidationRules;
|
|
135
136
|
validationValueParser?: TValidationValueParser<ValueType>;
|
|
136
137
|
value: ValueType;
|
|
137
138
|
};
|
|
@@ -388,6 +389,11 @@ declare function hasSucceedFieldValidation(result: TFieldValidationResult): resu
|
|
|
388
389
|
* onValidate de Form o en la acción validationsActions.validateForm
|
|
389
390
|
*/
|
|
390
391
|
declare function hasSucceedFormValidation<ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType>(result: TValidationResult<ValueType, SubmitValueType>): result is TSuccessfulValidation<ValueType, SubmitValueType>;
|
|
392
|
+
/**
|
|
393
|
+
* Devuelve la cadena correspondiente a un código
|
|
394
|
+
* de error, realizando los reemplazos correspondientes.
|
|
395
|
+
*/
|
|
396
|
+
declare function lang(errorCode: keyof typeof formcheckLanguage, ...replacements: (string | number)[]): string;
|
|
391
397
|
declare function classToValidationFunction<T = string>(className: string): TValidationField<T>['validationFunction'];
|
|
392
398
|
declare function classToValidate(className: string): IFieldDefinition['validate'];
|
|
393
399
|
/**
|
|
@@ -397,6 +403,68 @@ declare function classToValidate(className: string): IFieldDefinition['validate'
|
|
|
397
403
|
*/
|
|
398
404
|
declare function initValidations(): Promise<void>;
|
|
399
405
|
|
|
406
|
+
declare abstract class CollectorField<ValueType = any> extends EventEmitter<{
|
|
407
|
+
rulesUpdate: TValidationRules;
|
|
408
|
+
}> {
|
|
409
|
+
#private;
|
|
410
|
+
protected _name: string;
|
|
411
|
+
protected label: string;
|
|
412
|
+
abstract Component: FC;
|
|
413
|
+
abstract type: string;
|
|
414
|
+
constructor(_name: string, label: string);
|
|
415
|
+
get name(): string;
|
|
416
|
+
protected initialValue: ValueType;
|
|
417
|
+
setInitialValue: (newValue: ValueType) => void;
|
|
418
|
+
setValidationRules: (newRules: TValidationRules) => void;
|
|
419
|
+
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"> & {
|
|
420
|
+
digitmin: number;
|
|
421
|
+
digitltd: [number, number];
|
|
422
|
+
confirm: string;
|
|
423
|
+
differs: string;
|
|
424
|
+
length_str: [number, number];
|
|
425
|
+
length_fix: number;
|
|
426
|
+
words_min: number;
|
|
427
|
+
words_max: number;
|
|
428
|
+
words_range: [number, number];
|
|
429
|
+
checkboxes_group: number;
|
|
430
|
+
} & {
|
|
431
|
+
patternMessage: string;
|
|
432
|
+
pattern: string | RegExp;
|
|
433
|
+
digitmax: number;
|
|
434
|
+
validName?: string | undefined;
|
|
435
|
+
maxLength: number;
|
|
436
|
+
minLength: number;
|
|
437
|
+
min: number;
|
|
438
|
+
max: number;
|
|
439
|
+
}> | undefined;
|
|
440
|
+
}
|
|
441
|
+
declare class CollectorInput extends CollectorField<string> {
|
|
442
|
+
type: string;
|
|
443
|
+
Component: () => React.JSX.Element;
|
|
444
|
+
}
|
|
445
|
+
declare class CollectorLabel extends CollectorField {
|
|
446
|
+
private kind;
|
|
447
|
+
private static maxId;
|
|
448
|
+
type: string;
|
|
449
|
+
constructor(label: string, kind?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'label');
|
|
450
|
+
Component: () => React.JSX.Element;
|
|
451
|
+
}
|
|
452
|
+
declare class CollectorTextarea extends CollectorField<string> {
|
|
453
|
+
type: string;
|
|
454
|
+
Component: () => React.JSX.Element;
|
|
455
|
+
}
|
|
456
|
+
declare class Collector {
|
|
457
|
+
#private;
|
|
458
|
+
fields: {
|
|
459
|
+
input: typeof CollectorInput;
|
|
460
|
+
label: typeof CollectorLabel;
|
|
461
|
+
textarea: typeof CollectorTextarea;
|
|
462
|
+
};
|
|
463
|
+
private id;
|
|
464
|
+
add: (field: CollectorField) => void;
|
|
465
|
+
show: <FormValues extends Record<string, unknown>>(modalProps?: Partial<Omit<TOpenModal, 'children'>>) => Promise<FormValues>;
|
|
466
|
+
}
|
|
467
|
+
|
|
400
468
|
type TUseField<ValueType = unknown, SubmitValueType = ValueType> = Omit<TValidationField<ValueType, SubmitValueType>, 'error' | 'value' | 'isTouched'> & {
|
|
401
469
|
/**
|
|
402
470
|
* Con esta propiedad es posible evitar que el campo
|
|
@@ -608,4 +676,4 @@ declare function useValidationClass<T>({ customValidation, formName, name, valid
|
|
|
608
676
|
};
|
|
609
677
|
};
|
|
610
678
|
|
|
611
|
-
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 };
|
|
679
|
+
export { InnerCaptcha as Captcha, Checkbox, Collector, DeletableInput, FieldWrapper, FileInput, Form, FormContext, IWrapper, Input, NumberInputf, Radio, Select, Switchbox, TCheckbox, TDefaultFieldType, TInput$1 as TInput, TOnValidate, TRadio, TSelect, TSwitchbox, TUseField, TValidationResult, TValidationRules, Textarea, ValidationError, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, lang, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidationClass, validationsStore };
|