@bolttech/form-engine 0.11.1 → 0.11.3
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/CHANGELOG.md +15 -0
- package/README.md +33 -7
- package/{asFormField-c36e1d6e.js → asFormField-51a4f002.js} +2 -2
- package/asFormField-51a4f002.js.map +1 -0
- package/index.js +1 -1
- package/package.json +1 -1
- package/react.js +1 -1
- package/react.js.map +1 -1
- package/src/adapters/react/asFormField.d.ts +2 -2
- package/src/adapters/react/types.d.ts +15 -3
- package/src/adapters/react/useForm.d.ts +1 -1
- package/src/adapters/react/useFormGroup.d.ts +1 -1
- package/src/core/types/index.d.ts +9 -1
- package/types.js.map +1 -1
- package/asFormField-c36e1d6e.js.map +0 -1
package/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sources":["../../../libs/form-engine/src/adapters/react/useFormGroup.tsx"],"sourcesContent":["import { useEffect, useCallback, useState } from 'react';\n\nimport { TFormValues, THookReturn, TUseFormGroupProps } from '@react/types';\n\nimport { CoreEvents, ALL_NAMESPACE_EVENTS } from '@core';\nimport { getFormInstance, getGroupFormsIds } from '@core/managers';\nimport { EEVents } from '@core/constants';\n\nconst useFormGroup = ({\n group,\n onData,\n onSubmit,\n ids = [],\n}: TUseFormGroupProps): THookReturn => {\n const [formIds, setFormIds] = useState(group ? getGroupFormsIds(group) : ids);\n\n const onDataChange = useCallback(() => {\n const data = formIds.reduce(\n (acc, formId) => ({\n ...acc,\n [formId]: getFormInstance(formId).formData,\n }),\n {},\n );\n\n onData && onData(data);\n }, [onData]);\n\n const extractFormsData = (opts) => {\n return formIds.reduce(\n (acc, formId) => {\n if (opts?.aggregate) {\n return Object.keys(acc).reduce(\n (innerAcc, key) => ({\n ...innerAcc,\n [key]: {\n ...acc[key],\n ...getFormInstance(formId, opts).formData[key],\n },\n }),\n {},\n );\n }\n\n return { ...acc, [formId]: getFormInstance(formId, opts).formData };\n },\n {\n formatted: {},\n erroredFields: {},\n fields: {},\n form: {},\n predictableErroredFields: {},\n filteredFields: {},\n } as TFormValues,\n );\n };\n\n useEffect(() => {\n if (formIds.length || !group) return;\n setFormIds(getGroupFormsIds(group));\n }, [formIds]);\n\n useEffect(() => {\n formIds.map((formId) =>\n getFormInstance(formId).subscribe(EEVents.ON_FIELD_CHANGE, onDataChange),\n );\n }, [onData, formIds]);\n\n useEffect(() => {\n formIds.map((formId) =>\n getFormInstance(formId).subscribe(EEVents.ON_SCOPE_CHANGE, onDataChange),\n );\n }, [onData, formIds]);\n\n useEffect(() => {\n formIds.map((formId) =>\n getFormInstance(formId).subscribe(\n ALL_NAMESPACE_EVENTS(CoreEvents.ON_FIELD_REHYDRATE),\n onDataChange,\n ),\n );\n }, [onData, formIds]);\n\n useEffect(() => {\n formIds.map((formId) =>\n getFormInstance(formId).subscribe(\n CoreEvents.ON_FORM_SUBMIT,\n () => onSubmit && onSubmit(extractFormsData({})),\n ),\n );\n }, [onSubmit, formIds]);\n\n const submitForm = () =>\n formIds.map((formId) =>\n getFormInstance(formId).publish(CoreEvents.ON_FORM_SUBMIT),\n );\n\n return {\n submitForm,\n formData: extractFormsData,\n };\n};\n\nexport { useFormGroup };\n"],"names":["useFormGroup","group","onData","onSubmit","ids","formIds","setFormIds","useState","getGroupFormsIds","onDataChange","useCallback","data","reduce","acc","formId","Object","assign","getFormInstance","formData","extractFormsData","opts","aggregate","keys","innerAcc","key","formatted","erroredFields","fields","form","predictableErroredFields","filteredFields","useEffect","length","map","subscribe","ALL_NAMESPACE_EVENTS","CoreEvents","ON_FIELD_REHYDRATE","ON_FORM_SUBMIT","submitForm","publish"],"mappings":"iWAQqBA,EACnBC,QACAC,SACAC,WACAC,MAAM,OAEN,MAAOC,EAASC,GAAcC,EAAQA,
|
|
1
|
+
{"version":3,"file":"react.js","sources":["../../../libs/form-engine/src/adapters/react/useFormGroup.tsx"],"sourcesContent":["import { useEffect, useCallback, useState } from 'react';\n\nimport { TFormValues, THookReturn, TUseFormGroupProps } from '@react/types';\n\nimport { CoreEvents, ALL_NAMESPACE_EVENTS } from '@core';\nimport { getFormInstance, getGroupFormsIds } from '@core/managers';\nimport { EEVents } from '@core/constants';\n\nconst useFormGroup = ({\n group,\n onData,\n onClick,\n onSubmit,\n ids = [],\n}: TUseFormGroupProps): THookReturn => {\n const [formIds, setFormIds] = useState(group ? getGroupFormsIds(group) : ids);\n\n const onDataChange = useCallback(() => {\n const data = formIds.reduce(\n (acc, formId) => ({\n ...acc,\n [formId]: getFormInstance(formId).formData,\n }),\n {},\n );\n\n onData && onData(data);\n }, [onData]);\n\n const extractFormsData = (opts) => {\n return formIds.reduce(\n (acc, formId) => {\n if (opts?.aggregate) {\n return Object.keys(acc).reduce(\n (innerAcc, key) => ({\n ...innerAcc,\n [key]: {\n ...acc[key],\n ...getFormInstance(formId, opts).formData[key],\n },\n }),\n {},\n );\n }\n\n return { ...acc, [formId]: getFormInstance(formId, opts).formData };\n },\n {\n formatted: {},\n erroredFields: {},\n fields: {},\n form: {},\n predictableErroredFields: {},\n filteredFields: {},\n } as TFormValues,\n );\n };\n\n useEffect(() => {\n if (formIds.length || !group) return;\n setFormIds(getGroupFormsIds(group));\n }, [formIds]);\n\n useEffect(() => {\n formIds.map((formId) =>\n getFormInstance(formId).subscribe(EEVents.ON_FIELD_CHANGE, onDataChange),\n );\n }, [onData, formIds]);\n\n useEffect(() => {\n formIds.map((formId) =>\n getFormInstance(formId).subscribe(EEVents.ON_SCOPE_CHANGE, onDataChange),\n );\n }, [onData, formIds]);\n\n useEffect(() => {\n formIds.map((formId) =>\n getFormInstance(formId).subscribe(\n ALL_NAMESPACE_EVENTS(CoreEvents.ON_FIELD_REHYDRATE),\n onDataChange,\n ),\n );\n }, [onData, formIds]);\n\n useEffect(() => {\n formIds.map((formId) =>\n getFormInstance(formId).subscribe(\n ALL_NAMESPACE_EVENTS(CoreEvents.ON_FIELD_CLICK),\n onClick,\n ),\n );\n }, [onClick, formIds]);\n\n useEffect(() => {\n formIds.map((formId) =>\n getFormInstance(formId).subscribe(\n CoreEvents.ON_FORM_SUBMIT,\n () => onSubmit && onSubmit(extractFormsData({})),\n ),\n );\n }, [onSubmit, formIds]);\n\n const submitForm = () =>\n formIds.map((formId) =>\n getFormInstance(formId).publish(CoreEvents.ON_FORM_SUBMIT),\n );\n\n return {\n submitForm,\n formData: extractFormsData,\n };\n};\n\nexport { useFormGroup };\n"],"names":["useFormGroup","group","onData","onClick","onSubmit","ids","formIds","setFormIds","useState","getGroupFormsIds","onDataChange","useCallback","data","reduce","acc","formId","Object","assign","getFormInstance","formData","extractFormsData","opts","aggregate","keys","innerAcc","key","formatted","erroredFields","fields","form","predictableErroredFields","filteredFields","useEffect","length","map","subscribe","ALL_NAMESPACE_EVENTS","CoreEvents","ON_FIELD_REHYDRATE","ON_FIELD_CLICK","ON_FORM_SUBMIT","submitForm","publish"],"mappings":"iWAQqBA,EACnBC,QACAC,SACAC,UACAC,WACAC,MAAM,OAEN,MAAOC,EAASC,GAAcC,EAAQA,SAACP,EAAQQ,mBAAiBR,GAASI,GAEnEK,EAAeC,EAAAA,aAAY,KAC/B,MAAMC,EAAON,EAAQO,QACnB,CAACC,EAAKC,IACDC,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAAAH,GACH,CAAAC,CAACA,GAASG,EAAAA,gBAAgBH,GAAQI,YAEpC,CAAE,GAGJjB,GAAUA,EAAOU,EAAK,GACrB,CAACV,IAEEkB,EAAoBC,GACjBf,EAAQO,QACb,CAACC,EAAKC,KACAM,eAAAA,EAAMC,WACDN,OAAOO,KAAKT,GAAKD,QACtB,CAACW,EAAUC,IACNT,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAAAO,IACHC,CAACA,GACIT,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAAAH,EAAIW,IACJP,EAAeA,gBAACH,EAAQM,GAAMF,SAASM,OAG9C,CAAE,GAINT,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAAYH,GAAG,CAAEC,CAACA,GAASG,EAAeA,gBAACH,EAAQM,GAAMF,YAE3D,CACEO,UAAW,CAAE,EACbC,cAAe,CAAE,EACjBC,OAAQ,CAAE,EACVC,KAAM,CAAE,EACRC,yBAA0B,CAAE,EAC5BC,eAAgB,CAAE,IAKxBC,EAAAA,WAAU,MACJ1B,EAAQ2B,QAAWhC,GACvBM,EAAWE,EAAAA,iBAAiBR,GAAO,GAClC,CAACK,IAEJ0B,EAAAA,WAAU,KACR1B,EAAQ4B,KAAKnB,GACXG,kBAAgBH,GAAQoB,4BAAmCzB,IAC5D,GACA,CAACR,EAAQI,IAEZ0B,EAAAA,WAAU,KACR1B,EAAQ4B,KAAKnB,GACXG,kBAAgBH,GAAQoB,4BAAmCzB,IAC5D,GACA,CAACR,EAAQI,IAEZ0B,EAAAA,WAAU,KACR1B,EAAQ4B,KAAKnB,GACXG,EAAAA,gBAAgBH,GAAQoB,UACtBC,EAAAA,qBAAqBC,EAAAA,WAAWC,oBAChC5B,IAEH,GACA,CAACR,EAAQI,IAEZ0B,EAAAA,WAAU,KACR1B,EAAQ4B,KAAKnB,GACXG,EAAAA,gBAAgBH,GAAQoB,UACtBC,EAAAA,qBAAqBC,EAAAA,WAAWE,gBAChCpC,IAEH,GACA,CAACA,EAASG,IAEb0B,EAAAA,WAAU,KACR1B,EAAQ4B,KAAKnB,GACXG,EAAeA,gBAACH,GAAQoB,UACtBE,EAAAA,WAAWG,gBACX,IAAMpC,GAAYA,EAASgB,EAAiB,CAAE,OAEjD,GACA,CAAChB,EAAUE,IAOd,MAAO,CACLmC,WANiBA,IACjBnC,EAAQ4B,KAAKnB,GACXG,EAAAA,gBAAgBH,GAAQ2B,QAAQL,aAAWG,kBAK7CrB,SAAUC,EACX"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { TAsFormFieldProps, TDecoratorProps } from '
|
|
3
|
-
declare const asFormField: <OriginalComponentProps>({ Comp, propsMapping }: TAsFormFieldProps) => ({ name, validations, errorMessages, masks, filter, formatters, visibilityConditions, formId, visibility, value, ...props }: TDecoratorProps<OriginalComponentProps>) => ReactElement;
|
|
2
|
+
import { TAsFormFieldProps, TDecoratorProps } from '../react/types';
|
|
3
|
+
declare const asFormField: <OriginalComponentProps>({ Comp, propsMapping }: TAsFormFieldProps) => ({ name, validations, errorMessages, masks, clearFields, api, filter, formatters, visibilityConditions, formId, visibility, value, ...props }: TDecoratorProps<OriginalComponentProps>) => ReactElement;
|
|
4
4
|
export default asFormField;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactElement } from 'react';
|
|
2
|
-
import { TComponent, TErrorMessages, TSchemaValidation, TSchemaValidations, TSchema, THooks, TIVars, TFormValues, TField, TChildrenOptions, TPropsMapping, TComponentPropsMapping, TScope } from '
|
|
2
|
+
import { TComponent, TErrorMessages, TSchemaValidation, TSchemaValidations, TSchema, THooks, TIVars, TFormValues, TField, TChildrenOptions, TPropsMapping, TComponentPropsMapping, TScope } from '../../core/types';
|
|
3
3
|
import { TLoggingEvent } from '@core/events/events.types';
|
|
4
4
|
declare type TFormProps = {
|
|
5
5
|
/**
|
|
@@ -226,6 +226,12 @@ declare type TUseFormProps = {
|
|
|
226
226
|
* @param data All the available form data
|
|
227
227
|
*/
|
|
228
228
|
onData?(data: TFormValues | Record<string, TFormValues>): void;
|
|
229
|
+
/**
|
|
230
|
+
* Callback to be called when the form generates some new data
|
|
231
|
+
* @param data All the available form data
|
|
232
|
+
* @param field Current field which has clicked
|
|
233
|
+
*/
|
|
234
|
+
onClick?(data: TFormValues | Record<string, TFormValues>, field: TField): void;
|
|
229
235
|
/**
|
|
230
236
|
* Callback to be called when the form submits
|
|
231
237
|
* @param data All the available form data
|
|
@@ -246,6 +252,12 @@ declare type TUseFormGroupProps = {
|
|
|
246
252
|
* @param data All the available form data
|
|
247
253
|
*/
|
|
248
254
|
onData?(data: Record<string, TFormValues>): void;
|
|
255
|
+
/**
|
|
256
|
+
* Callback to be called when the form generates some new data
|
|
257
|
+
* @param data All the available form data
|
|
258
|
+
* @param field Current field which has clicked
|
|
259
|
+
*/
|
|
260
|
+
onClick?(data: Record<string, TFormValues>, field: TField): void;
|
|
249
261
|
/**
|
|
250
262
|
* Callback to be called when the form submits
|
|
251
263
|
* @param data All the available form data
|
|
@@ -272,9 +284,9 @@ interface TAsFormFieldProps {
|
|
|
272
284
|
*/
|
|
273
285
|
Comp: (new () => React.Component) | any;
|
|
274
286
|
/**
|
|
275
|
-
* Link for the
|
|
287
|
+
* Link for the TComponentPropsMapping likely props mapper from default form.
|
|
276
288
|
*/
|
|
277
|
-
propsMapping:
|
|
289
|
+
propsMapping: TComponentPropsMapping;
|
|
278
290
|
}
|
|
279
291
|
declare type TDecorator = {
|
|
280
292
|
/**
|
|
@@ -8,5 +8,5 @@ import { THookReturn, TUseFormProps } from '@react/types';
|
|
|
8
8
|
* - A group of forms
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
|
-
declare const useForm: ({ onValid, onData, onSubmit, id, ids, }: TUseFormProps) => THookReturn;
|
|
11
|
+
declare const useForm: ({ onValid, onData, onClick, onSubmit, id, ids, }: TUseFormProps) => THookReturn;
|
|
12
12
|
export default useForm;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { THookReturn, TUseFormGroupProps } from '@react/types';
|
|
2
|
-
declare const useFormGroup: ({ group, onData, onSubmit, ids, }: TUseFormGroupProps) => THookReturn;
|
|
2
|
+
declare const useFormGroup: ({ group, onData, onClick, onSubmit, ids, }: TUseFormGroupProps) => THookReturn;
|
|
3
3
|
export { useFormGroup };
|
|
@@ -589,7 +589,7 @@ export declare type TClearField = {
|
|
|
589
589
|
/**
|
|
590
590
|
* Validations to run for the target field
|
|
591
591
|
*/
|
|
592
|
-
validations?: TSchemaValidation;
|
|
592
|
+
validations?: TSchemaValidation | TSchemaValidation[];
|
|
593
593
|
/**
|
|
594
594
|
* target fields that will be used in the validation specified
|
|
595
595
|
*/
|
|
@@ -602,6 +602,14 @@ export declare type TClearField = {
|
|
|
602
602
|
* The cleared props from each component field on target fields array
|
|
603
603
|
*/
|
|
604
604
|
clearedProps?: Record<string, unknown> | Record<string, unknown>[];
|
|
605
|
+
/**
|
|
606
|
+
* The cleared values on the fields in case they do pass the validation
|
|
607
|
+
*/
|
|
608
|
+
defaultClearedValue?: TClearFieldValue | TClearFieldValue[];
|
|
609
|
+
/**
|
|
610
|
+
* The cleared props from each component field on target fields array if they pass validation
|
|
611
|
+
*/
|
|
612
|
+
defaultClearedProps?: Record<string, unknown> | Record<string, unknown>[];
|
|
605
613
|
};
|
|
606
614
|
export declare type TSchemaClearFields = TClearField[];
|
|
607
615
|
export declare type TSchemaApi = {
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../libs/form-engine/src/core/types/index.ts"],"sourcesContent":["import { ICustomValidationValue } from '@core/apis/validations';\nimport { EEVents } from '@core/constants';\nimport { TEventInformation } from '@core/events';\nimport Field from \"@core/managers/Field\";\n\nexport type TObserverData<T> = {\n data: any;\n event: TEventsKeys;\n namespace: string;\n payload: T;\n};\n\nexport type TObservable = (data: any, unsubscribe: () => void) => any;\n\nexport type TEvents = Record<string, TObservable[]>;\n\nexport interface IObservable {\n events: TEvents;\n}\n\nexport type TScopeNamespaces =\n | 'global'\n | 'api'\n | 'hooks'\n | 'fields'\n | 'configs';\n\nexport type TSetGlobalScope = {\n namespace: TScopeNamespaces;\n key?: string;\n data: any;\n merge?: boolean;\n};\nexport type TScope = {\n global?: any;\n api?: any;\n hooks?: any;\n configs?: TConfigs & {\n disable?: boolean;\n enableLogging?: boolean;\n };\n fields?: any;\n};\n\nexport type TMapper = Record<string, Record<string, unknown>>;\n\nexport type TMaskGeneric = {\n to: number;\n from: number;\n mask: string;\n}[];\n\ntype TCurrencyMask = {\n locale: string;\n currency: string;\n};\n\nexport type TComponentMasks = {\n generic?: TMaskGeneric;\n cardNumber?: boolean;\n hideCardNumber?: boolean;\n cardMask?: boolean;\n cardDate?: boolean;\n currencyMask?: TCurrencyMask;\n feinMask?: boolean;\n replaceAll?: string | number;\n};\n\ntype TFormMessages = Record<\n string,\n { name: string; value?: any; values?: string[]; required?: boolean }\n>;\n\nexport type TChildrenOptions = {\n childrenScope?: string[];\n blurredChildren?: string[];\n changedChildren?: string[];\n scopeBlurredChildren?: boolean;\n scopeChangedChildren?: boolean;\n};\n\nexport type TFieldData = Record<string, TField>;\nexport type TFields = { [x in string]: Field };\n\nexport type TSubmitValueData = Record<string, {\n value?: unknown,\n props?: Record<string,unknown>,\n}>\n\nexport type TFormRefActions = {\n submit(): void;\n step(index: number | string): TFormValues;\n stepForward(index?: number | string): TFormValues;\n stepBack(index?: number | string): TFormValues;\n validateForm(opts?: TChildrenOptions): Promise<TFormValues>;\n bindFields(payload: TSubmitValueData): void;\n values(\n opts: Pick<\n TChildrenOptions,\n 'scopeBlurredChildren' | 'scopeChangedChildren' | 'childrenScope'\n >,\n ): TFormValues;\n};\n\nexport type THookPayload = {\n setScope(data: TSetGlobalScope): void;\n};\n\nexport type THooks = {\n preMount?: () => Record<string, unknown>;\n preUnmount?: () => Record<string, unknown>;\n preSubmit?: (formData: TFormValues) => Record<string, unknown>;\n posSubmit?: (formData: TFormValues) => Record<string, unknown>;\n};\n\nexport type TIVars = Record<string, unknown>;\n\nexport type TEventsKeys = keyof typeof EEVents;\nexport enum TAvailableHooks {\n 'preMount' = 'preMount',\n 'preUnmount' = 'preUnmount',\n 'preSubmit' = 'preSubmit',\n 'postSubmit' = 'postSubmit',\n}\nexport type TField = {\n value?: string | number | boolean;\n errors?: TErrors;\n visible?: boolean;\n failedErrorMessages?: string[];\n mask?: string;\n changed?: boolean;\n keyup?: boolean;\n keydown?: boolean;\n blured?: boolean;\n focused?: boolean;\n name: string;\n mounted: boolean;\n metadata?: any;\n ignore?: boolean;\n schemaLocation?: {\n step: number;\n depth: number;\n index: number;\n };\n};\n\ntype TPathError = Omit<TSchemaValidation, 'path'> & {\n path?: string;\n paths?: string[];\n preventUnMountValidation?: boolean;\n};\n\nexport type TValidationDateFormats =\n | 'MMDDYYYY'\n | 'DDMMYYYY'\n | 'YYYYMMDD'\n | 'YYYYDDMM'\n | 'timestamp';\nexport type TValidationDateOperators = '<' | '>' | '===' | '>=' | '<=' | '!==';\n\nexport type TVAvailableValidationConditionsSet = {\n forceDefinedOrigin?: boolean;\n forceDefinedTarget?: boolean;\n origin?: string | number | boolean;\n condition: TValidationDateOperators;\n target?: string | number | boolean;\n};\n\nexport type TVAvailableValidationConditions = {\n rule: 'and' | 'or';\n set: TVAvailableValidationConditionsSet[];\n conditions?: TVAvailableValidationConditions;\n};\n\nexport type TVAvailableValidations = {\n /**\n * The bool function is a validation function that checks if a given value indicating whether the validation has failed or not.\n *\n * @example - in a test environment\n * ```\n * const result = bool({\n * validationValue: false,\n * });\n * console.log(result); // { fail: false }\n * ```\n *\n * @example - real json usage with field value\n * ```\n * {\n * validations: {\n * bool: '${fields.input.value}'\n * },\n * },\n * ```\n *\n * @example - real json usage with iVar value\n * ```\n * {\n * validations: {\n * bool: '${global.validation}'\n * },\n * },\n * ```\n */\n bool?: string | boolean;\n /**\n * Validation based on conditions\n *\n * @example - Compare own field to two. Origin and target default to field value\n * ```\n * conditions: {\n * rule: 'and',\n * set: [\n * {\n * condition: '===',\n * target: '2',\n * },\n * {\n * origin: '2',\n * condition: '===',\n * },\n * ],\n * },\n * ```\n * @example - Binded to Postcode field value. Must be greater than or equal two\n * ```\n * conditions: {\n * rule: 'or',\n * set: [\n * {\n * origin: '${fields.postcode.value}',\n * condition: '>',\n * target: '2',\n * },\n * {\n * origin: '${fields.postcode.value}',\n * condition: '===',\n * target: '2',\n * },\n * ],\n * },\n * ```\n * @example - Binded to Postcode field value. Must be equal to two\n * ```\n * conditions: {\n * rule: 'or',\n * set: [\n * {\n * origin: '${fields.postcode.value}',\n * condition: '===',\n * target: '2',\n * },\n * ],\n * },\n * ```\n */\n conditions?: TVAvailableValidationConditions;\n /**\n * Between validations\n *\n * @example - Between ages\n * ``` type teste = Pick<TVAvailableValidations, 'date'>\n * between: {\n * dates: [\n * {\n * operator: '>=',\n * origin: {\n * format: 'YYYYMMDD',\n * intervals: {\n * years: 18,\n * },\n * },\n * },\n * {\n * operator: '<=',\n * origin: {\n * format: 'YYYYMMDD',\n * intervals: {\n * years: 75,\n * },\n * },\n * }\n * ]\n * }\n * ```\n *\n * @example - Between numbers\n * ```\n * between: {\n * start: '3',\n * end: '4',\n * isIncludedBoundaries: true\n * },\n * ```\n *\n */\n between?: {\n /**\n * Array of date validations. To make it possible, ensure that the conditions is > and < in both date validations.\n */\n dates?: TVAvailableValidations['date'][];\n /**\n * The first number of the validation. If the current value is grater than this number, the validation will pass.\n */\n start?: number;\n /**\n * The second number of the validation. If the current value is lower than this number, the validation will pass.\n */\n end?: number;\n /**\n * If it's true, the comparision is transformed to >= and <=. So, the numbers that were passed are included in the validation.\n */\n isIncludedBoundaries?: boolean;\n };\n /**\n * Dates validations\n *\n * @example - Dates should be different\n * ```\n * date: {\n * operator: '!==',\n * origin: {\n * format: 'DDMMYYYY',\n * },\n * target: {\n * format: 'DDMMYYYY',\n * value: '10/10/2001',\n * },\n * },*\n * ```\n *\n * @example - Compare only valid dates using intervals\n * ```\n * date: {\n * onlyValidDate: true,\n * operator: '<',\n * origin: {\n * format: 'DD/MM/YYYY',\n * intervals: {\n * years: 1,\n * },\n * },\n * },\n * ```\n *\n * @example - Should have at max 85 years\n * ```\n * {\n * operator: '>',\n * origin: {\n * format: 'DDMMYYYY',\n * value: eightyFiveYearsDate,\n * intervals: {\n * years: 85,\n * },\n * },\n * }\n * }\n *\n * ```\n */\n date?: {\n /**\n * Flag to force only valid dates. Valid dates must be of min length of 8\n */\n onlyValidDate?: boolean;\n /**\n * List of operations you can do\n * - between origin and target dates\n * - between origin and intervals\n */\n operator: TValidationDateOperators;\n /**\n * The origin configurations\n */\n origin: {\n /**\n * Origin date value\n */\n value?: string | number;\n /**\n * The available date formats\n */\n format: TValidationDateFormats;\n /**\n * Intervals to compare with the original date.\n *\n * It will use todays date for comparison.\n *\n * @example\n *\n * origin date = 10/10/2022\n * interval.year = 1\n * operator = '==='\n *\n * It will compare (10/10/2022 + 1) with the current date and check if they are the same\n */\n intervals?: {\n years?: number;\n months?: number;\n days?: number;\n };\n };\n target?: {\n value: string | number;\n format: TValidationDateFormats;\n };\n };\n /**\n * Allow to define a maximum length for the input to have no error\n */\n length?: number;\n /**\n * Will look into the input length and send an error if if not greater than this value\n */\n greaterThan?: number | string;\n\n /**\n * Specifies a regular expression pattern that the value should match.\n */\n regex?: string;\n\n /**\n * Specifies the maximum length of the value (if it's a string).\n */\n maxLength?: number;\n\n /**\n * Specifies the minimum length of the value (if it's a string).\n */\n minLength?: number;\n\n /**\n * Specifies whether the field is required.\n */\n required?: boolean;\n\n /**\n * Specifies that the value should contain only letters.\n */\n onlyLetters?: boolean;\n\n /**\n * Specifies a value that the field should match.\n */\n value?: string | number | boolean;\n\n /**\n * Specifies that the field should not be empty.\n */\n notEmpty?: boolean;\n\n /**\n * A callback function that performs custom validation on the value.\n * @param value - The value to be validated.\n * @returns An object with validation results.\n */\n callback?(value: string | number): { fail: boolean; errorMessage?: string };\n\n /**\n * Specifies a numeric range for the value.\n */\n numericRange?: { start: number | string; end: number | string };\n\n /**\n * Specifies whether the value should be a number.\n */\n isNumber?: boolean;\n\n /**\n * Specifies that the field should not have extra spaces.\n */\n hasNoExtraSpaces?: boolean;\n\n /**\n * Specifies that the value should be an email address.\n */\n email?: boolean;\n\n /**\n * Specifies that the value should be less than a given number or string.\n */\n lessThan?: number | string;\n\n /**\n * Specifies that the value should be a sequential number.\n */\n sequentialNumber?: boolean;\n\n /**\n * Specifies that the value should not contain repeated numbers.\n */\n repeatedNumbers?: boolean;\n\n /**\n * Specifies that the value should be a URL.\n */\n url?: boolean;\n\n /**\n * Specifies a path error type.\n */\n path?: TPathError;\n\n /**\n * Specifies that the value should be a valid credit card number.\n */\n isCreditCard?: string[];\n\n /**\n * Specifies that the value should be a valid credit card number with a specific length.\n */\n isCreditCardAndLength?: string[];\n\n /**\n * Specifies that the value should match a credit card code with available options.\n */\n isCreditCodeMatch?: { numberCard: string; availableOptions: string[] };\n\n /**\n * Specifies custom validation options for the field.\n */\n customValidation?: ICustomValidationValue[];\n\n /**\n * Specifies that spaces are not allowed in the field.\n */\n notAllowSpaces?: true;\n\n /**\n * Specifies that the value should be in a predefined list of values.\n */\n isInTheList?: string[] | number[] | string;\n\n /**\n * Specifies field validation rules for nested fields.\n */\n fields?: {\n /**\n * The rule for validating nested fields (e.g., 'every').\n */\n rule: 'every';\n\n /**\n * An array of nested field validation configurations.\n */\n set: {\n /**\n * The binding for the nested field.\n */\n bind: string;\n\n /**\n * The field name for the nested field.\n */\n fieldName: string;\n\n /**\n * Validation options for the nested field, excluding the 'fields' property.\n */\n validations: Omit<TVAvailableValidations, 'fields'>;\n }[];\n };\n\n /**\n * Specifies that the value should be existed.\n */\n exists?: string | number;\n};\n\nexport type TGenericValidationRule = {\n [key: string]: TVAvailableValidations;\n};\n\nexport type TSchemaValidation = TVAvailableValidations | TGenericValidationRule;\n\nexport type TStepData = {\n navigated: boolean;\n index: number;\n data: Record<\n number,\n Pick<\n TFormValues,\n 'fields' | 'erroredFields' | 'formatted' | 'filteredFields'\n >\n >;\n currentStepSchema?: TComponent;\n isValid: boolean;\n numSteps?: number;\n};\n\nexport type TFormValues = {\n predictableErroredFields: string[];\n erroredFields: string[];\n fields: TFieldData;\n formatted: Record<string, unknown>;\n filteredFields?: Record<string, unknown>;\n form: {\n steps: TStepData;\n isValid: boolean;\n messages: string[];\n scope: TScope;\n };\n};\n\nexport type TError = {\n value: unknown;\n message?: string;\n fail: boolean;\n};\n\nexport type TErrors = Record<string, TError> | undefined;\n\n// TODO - object with the available errors has props\nexport type TErrorMessages = Record<string, string>;\n\nexport type TSchemaValidations = TSchemaHandler<TSchemaValidation>;\n\ntype TFormLevelSchemaHandler<T> = Partial<\n Record<\n | EEVents.AFTER_FIELD_API_CALL\n | EEVents.ON_FIELD_CHANGE\n | EEVents.ON_FIELD_KEYUP\n | EEVents.ON_FIELD_KEYDOWN\n | EEVents.ON_FORM_REHYDRATE\n | EEVents.ON_FORM_MOUNT\n | EEVents.ON_SCOPE_CHANGE,\n T\n >\n>;\n\ntype TSchemaHandler<T> = Partial<\n Record<\n | EEVents.AFTER_FIELD_API_CALL\n | EEVents.ON_FIELD_REHYDRATE\n | EEVents.ON_FIELD_CLEARED\n | EEVents.ON_FIELD_BINDED\n | EEVents.ON_FIELD_CHANGE\n | EEVents.ON_FIELD_KEYUP\n | EEVents.ON_FIELD_KEYDOWN\n | EEVents.ON_FIELD_BLUR\n | EEVents.ON_FIELD_MOUNT\n | EEVents.ON_FIELD_FOCUS\n | EEVents.ON_FIELD_CLICK,\n T\n >\n>;\n\nexport type TSchemaVisibilityConditions = {\n /**\n * Enables visibility of fields only if any or all validation conditions are positive.\n *\n * The default is false, so if all validations are false, the field will display, if any are positive,\n * the field will hide, as well as if all are positive.\n */\n showOnlyIfTrue?: boolean;\n /**\n * Allows you to choose the type of chain for validations.\n *\n * The default is OR, where at least one validation needs to be true to work. In the case of AND,\n * all validations must be true.\n */\n rule?: 'or' | 'and';\n /**\n * The validations that will say if the target field will be visible or not\n *\n * Those validations will run against your field (the one that has this directive)\n */\n validations: TSchemaValidation;\n /**\n * Target field that will have the visibility toggled\n */\n fieldName?: string;\n /**\n * Target fields that will have the visibility toggled\n */\n fieldNames?: string[];\n}[];\n\nexport type TClearFieldValue = string | number | boolean;\n\nexport type TClearField = {\n /**\n * The clearValues runs validations on the target field and not on the field it is declaring.\n * Therefore, set this prop with true if you want validations to be performed on the current field.\n */\n useCurrentFieldValidation?: boolean;\n /**\n * Validations to run for the target field\n */\n validations?: TSchemaValidation;\n /**\n * target fields that will be used in the validation specified\n */\n fields: string[];\n /**\n * The cleared values on the fields in case they do not pass the validation\n */\n clearedValue: TClearFieldValue | TClearFieldValue[];\n /**\n * The cleared props from each component field on target fields array\n */\n clearedProps?: Record<string, unknown> | Record<string, unknown>[];\n};\n\nexport type TSchemaClearFields = TClearField[];\n\nexport type TSchemaApi = {\n /**\n * Specify a debounce time in miliseconds for your call\n */\n debounceTime?: number;\n method: 'GET' | 'POST' | 'PUT' | 'PATCH';\n url: string;\n headers?: HeadersInit | undefined;\n body?: Record<string, any>;\n fieldValueAsParams?: Record<string, string>;\n fieldValueAsPathParams?: string[];\n scope?: string;\n blockRequestWhenInvalid?: boolean;\n preConditions?: TSchemaValidation;\n}[];\n\nexport type TSchemaMasks = { cleanMask?: boolean } & TComponentMasks;\n\nexport type TFormEventDirectives = {\n visibilityConditions: TSchemaVisibilityConditions;\n};\n\nexport type TComponent = {\n /**\n * This name will be used later to correlate the field with the value, and you will be able to read it.\n *\n * You can also mount here complex objects like\n *\n * name={a.b.c}\n *\n * that will result in\n * a: {\n * b: {\n * c: 'field_value'\n * }\n * }\n */\n name: string;\n /**\n * A component name that should map to the one you gave in the form mappings\n *\n * @example - For React\n * ```\n * const mappings: TMapper = {\n * input: { component: Input },\n * formGroup: { component: FormGroup },\n * };\n * ```\n *\n * The component name for the Input element will be \"input\" ending up like\n * ```\n * {\n * component: 'input'\n * }\n * ```\n */\n component: string;\n /**\n * You can attach metadata to your component that will be forwarded to you after on your frontend\n * callback methods link `onData`, `onBlur` etc\n */\n metadata?: Record<string, any>;\n /**\n * This property allows you to specify a virtual fieldName that can be in several fields\n *\n * USAGE - You have two fields but you want to have the value stored only under one name\n *\n */\n group?: string;\n wrapper?: new () => React.Component;\n children?: TComponent[];\n /**\n * Field error messages in case any validation fails\n *\n * @example - Set a default error message for all the validations\n *\n * ```\n * {\n * errorMessages: {\n * default: 'default error message'\n * }\n * }\n * ```\n *\n * @example - Set error message for a given validation\n *\n * ```\n * {\n * validations: {\n * ON_FIELD_CHANGE: {\n * required: true\n * }\n * },\n * errorMessages: {\n * required: 'This field is required'\n * }\n * }\n * ```\n *\n */\n errorMessages?: TErrorMessages;\n type?: 'text' | 'number' | string;\n /**\n * Allow you to set a initial state for this field\n */\n state?: {\n /**\n * Hide the field\n */\n hidden?: boolean;\n /**\n * Ignore value from field\n */\n ignoreValue?: boolean;\n };\n /**\n * This key lets you inject props directly into the component\n */\n props?: Record<string, unknown>;\n /**\n * Setup validations to be used in the field.\n *\n * You can setup validations in several life-cycle methods\n *\n * @example - Required validation\n * ```\n * validations: {\n ON_FIELD_CHANGE: {\n required: true,\n },\n },\n * ```\n */\n validations?: TSchemaHandler<\n Pick<TEventReducedSchema, 'validations'>['validations']\n >;\n /**\n * Filters the component value based on a validation.\n */\n filter?: Pick<TEventReducedSchema, 'validations'>['validations'];\n /**\n * Allows you to specify the conditions a given field will be visible\n * what will run when this field meets the specified life-cycle\n */\n visibilityConditions?: Omit<\n TSchemaHandler<\n Pick<TEventReducedSchema, 'visibilityConditions'>['visibilityConditions']\n >,\n 'ON_FIELD_REHYDRATE' | 'ON_FIELD_CLEARED' | 'ON_FIELD_FOCUS'\n >;\n /**\n * Will clear target fields in case they do not pass with the specified validations\n */\n clearFields?: Omit<\n TSchemaHandler<Pick<TEventReducedSchema, 'clearFields'>['clearFields']>,\n 'ON_FIELD_REHYDRATE' | 'ON_FIELD_CLEARED' | 'ON_FIELD_FOCUS'\n >;\n /**\n * Allows you to make api calls using events emitted by the component.\n */\n api?: Omit<\n TSchemaHandler<Pick<TEventReducedSchema, 'api'>['api']>,\n 'ON_FIELD_REHYDRATE' | 'ON_FIELD_FOCUS' | 'AFTER_FIELD_API_CALL'\n >;\n /**\n * Allows you to display the value of the masked component by events\n */\n masks?: Partial<\n Record<\n | EEVents.ON_FIELD_BLUR\n | EEVents.ON_FIELD_MOUNT\n | EEVents.ON_FIELD_FOCUS\n | EEVents.ON_FIELD_CHANGE\n | EEVents.ON_FIELD_KEYUP\n | EEVents.ON_FIELD_KEYDOWN,\n Pick<TEventReducedSchema, 'masks'>['masks']\n >\n >;\n /**\n * Allows you to format the value that the field will receive for each event issuance\n */\n formatters?: Omit<\n TSchemaHandler<Pick<TEventReducedSchema, 'formatters'>['formatters']>,\n 'ON_FIELD_REHYDRATE' | 'ON_FIELD_FOCUS'\n >;\n};\n\nexport type TEventReducedSchema = {\n api: TSchemaApi;\n clearFields: TSchemaClearFields;\n formatters: TSchemaFormatters;\n masks: TSchemaMasks;\n validations: TSchemaValidation;\n visibilityConditions: TSchemaVisibilityConditions;\n};\n\nexport type TStep = {\n component: string;\n name: string;\n children: TComponent[];\n props?: Record<string, string>;\n};\n\nexport type TComponentPropsMapping = {\n getValue?: string;\n setValue?: string;\n onBlur?: string;\n onClick?: string;\n onFocus?: string;\n onKeyUp?: string;\n onKeyDown?: string;\n setErrorMessage?: string;\n setErrorState?: string;\n};\n\nexport type TPropsMapping = Record<string, TComponentPropsMapping>;\n\nexport type TSchema = {\n /**\n * Used to disable form submit input and prevent to submit form using enter event.\n * Default is false.\n */\n disableFormSubmit?: boolean;\n action?: string;\n method?: string;\n /**\n * Give some configurations to the form\n */\n configs?: TConfigs;\n /**\n * Allows you to expose some messages to the outside world when something happen\n */\n messages?: TFormMessages;\n /**\n * Specify some static field defaults before rendereing the form.\n *\n * If you have initialValues in the frontend setted, those will ovewride this\n */\n formattedDataDefaults?: Record<string, unknown>;\n /**\n * Form level props mapping\n */\n propsMapping?: TPropsMapping;\n visibilityConditions?: TFormLevelSchemaHandler<TSchemaVisibilityConditions>;\n /**\n * Entry point for the form should be a step (even if you have only one)\n */\n components: TStep[];\n /**\n * You can have many fields in the form, but be interested only in some\n *\n * You can put here the fields you want to read onSubmit for example\n *\n * You will receive those in TFormValues.filteredFields\n */\n filteredFields?: string[];\n /**\n * Schema level iVars.\n *\n * These iVars will go to the global scope namespace\n */\n iVars?: TIVars;\n};\n\nexport type TSplitterFormatterValue = {\n value: string;\n position: number;\n}[];\n\nexport type TSchemaFormatters = {\n splitter?: TSplitterFormatterValue;\n capitalize?: boolean;\n upperCase?: boolean;\n gapsCreditCard?: string[];\n onlyNumbers?: boolean;\n onlyLetters?: boolean;\n regex?: string;\n};\n\nexport type TConfigs = {\n observables?: { templates?: { exclude?: string[] } };\n};\n\nexport type TFlowType = {\n [x: string]: {\n events: (component?: TComponent) => EEVents[];\n handler: (args: TEventInformation<unknown>) => void;\n }[];\n};\n"],"names":["TAvailableHooks"],"mappings":"aAsHA,IAAYA,yDAAAA,QAKXA,qBAAA,GALWA,EAAAA,QAAeA,kBAAfA,wBAKX,CAAA,IAJC,SAAA,WACAA,EAAA,WAAA,aACAA,EAAA,UAAA,YACAA,EAAA,WAAA"}
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../libs/form-engine/src/core/types/index.ts"],"sourcesContent":["import { ICustomValidationValue } from '@core/apis/validations';\nimport { EEVents } from '@core/constants';\nimport { TEventInformation } from '@core/events';\nimport Field from \"@core/managers/Field\";\n\nexport type TObserverData<T> = {\n data: any;\n event: TEventsKeys;\n namespace: string;\n payload: T;\n};\n\nexport type TObservable = (data: any, unsubscribe: () => void) => any;\n\nexport type TEvents = Record<string, TObservable[]>;\n\nexport interface IObservable {\n events: TEvents;\n}\n\nexport type TScopeNamespaces =\n | 'global'\n | 'api'\n | 'hooks'\n | 'fields'\n | 'configs';\n\nexport type TSetGlobalScope = {\n namespace: TScopeNamespaces;\n key?: string;\n data: any;\n merge?: boolean;\n};\nexport type TScope = {\n global?: any;\n api?: any;\n hooks?: any;\n configs?: TConfigs & {\n disable?: boolean;\n enableLogging?: boolean;\n };\n fields?: any;\n};\n\nexport type TMapper = Record<string, Record<string, unknown>>;\n\nexport type TMaskGeneric = {\n to: number;\n from: number;\n mask: string;\n}[];\n\ntype TCurrencyMask = {\n locale: string;\n currency: string;\n};\n\nexport type TComponentMasks = {\n generic?: TMaskGeneric;\n cardNumber?: boolean;\n hideCardNumber?: boolean;\n cardMask?: boolean;\n cardDate?: boolean;\n currencyMask?: TCurrencyMask;\n feinMask?: boolean;\n replaceAll?: string | number;\n};\n\ntype TFormMessages = Record<\n string,\n { name: string; value?: any; values?: string[]; required?: boolean }\n>;\n\nexport type TChildrenOptions = {\n childrenScope?: string[];\n blurredChildren?: string[];\n changedChildren?: string[];\n scopeBlurredChildren?: boolean;\n scopeChangedChildren?: boolean;\n};\n\nexport type TFieldData = Record<string, TField>;\nexport type TFields = { [x in string]: Field };\n\nexport type TSubmitValueData = Record<string, {\n value?: unknown,\n props?: Record<string,unknown>,\n}>\n\nexport type TFormRefActions = {\n submit(): void;\n step(index: number | string): TFormValues;\n stepForward(index?: number | string): TFormValues;\n stepBack(index?: number | string): TFormValues;\n validateForm(opts?: TChildrenOptions): Promise<TFormValues>;\n bindFields(payload: TSubmitValueData): void;\n values(\n opts: Pick<\n TChildrenOptions,\n 'scopeBlurredChildren' | 'scopeChangedChildren' | 'childrenScope'\n >,\n ): TFormValues;\n};\n\nexport type THookPayload = {\n setScope(data: TSetGlobalScope): void;\n};\n\nexport type THooks = {\n preMount?: () => Record<string, unknown>;\n preUnmount?: () => Record<string, unknown>;\n preSubmit?: (formData: TFormValues) => Record<string, unknown>;\n posSubmit?: (formData: TFormValues) => Record<string, unknown>;\n};\n\nexport type TIVars = Record<string, unknown>;\n\nexport type TEventsKeys = keyof typeof EEVents;\nexport enum TAvailableHooks {\n 'preMount' = 'preMount',\n 'preUnmount' = 'preUnmount',\n 'preSubmit' = 'preSubmit',\n 'postSubmit' = 'postSubmit',\n}\nexport type TField = {\n value?: string | number | boolean;\n errors?: TErrors;\n visible?: boolean;\n failedErrorMessages?: string[];\n mask?: string;\n changed?: boolean;\n keyup?: boolean;\n keydown?: boolean;\n blured?: boolean;\n focused?: boolean;\n name: string;\n mounted: boolean;\n metadata?: any;\n ignore?: boolean;\n schemaLocation?: {\n step: number;\n depth: number;\n index: number;\n };\n};\n\ntype TPathError = Omit<TSchemaValidation, 'path'> & {\n path?: string;\n paths?: string[];\n preventUnMountValidation?: boolean;\n};\n\nexport type TValidationDateFormats =\n | 'MMDDYYYY'\n | 'DDMMYYYY'\n | 'YYYYMMDD'\n | 'YYYYDDMM'\n | 'timestamp';\nexport type TValidationDateOperators = '<' | '>' | '===' | '>=' | '<=' | '!==';\n\nexport type TVAvailableValidationConditionsSet = {\n forceDefinedOrigin?: boolean;\n forceDefinedTarget?: boolean;\n origin?: string | number | boolean;\n condition: TValidationDateOperators;\n target?: string | number | boolean;\n};\n\nexport type TVAvailableValidationConditions = {\n rule: 'and' | 'or';\n set: TVAvailableValidationConditionsSet[];\n conditions?: TVAvailableValidationConditions;\n};\n\nexport type TVAvailableValidations = {\n /**\n * The bool function is a validation function that checks if a given value indicating whether the validation has failed or not.\n *\n * @example - in a test environment\n * ```\n * const result = bool({\n * validationValue: false,\n * });\n * console.log(result); // { fail: false }\n * ```\n *\n * @example - real json usage with field value\n * ```\n * {\n * validations: {\n * bool: '${fields.input.value}'\n * },\n * },\n * ```\n *\n * @example - real json usage with iVar value\n * ```\n * {\n * validations: {\n * bool: '${global.validation}'\n * },\n * },\n * ```\n */\n bool?: string | boolean;\n /**\n * Validation based on conditions\n *\n * @example - Compare own field to two. Origin and target default to field value\n * ```\n * conditions: {\n * rule: 'and',\n * set: [\n * {\n * condition: '===',\n * target: '2',\n * },\n * {\n * origin: '2',\n * condition: '===',\n * },\n * ],\n * },\n * ```\n * @example - Binded to Postcode field value. Must be greater than or equal two\n * ```\n * conditions: {\n * rule: 'or',\n * set: [\n * {\n * origin: '${fields.postcode.value}',\n * condition: '>',\n * target: '2',\n * },\n * {\n * origin: '${fields.postcode.value}',\n * condition: '===',\n * target: '2',\n * },\n * ],\n * },\n * ```\n * @example - Binded to Postcode field value. Must be equal to two\n * ```\n * conditions: {\n * rule: 'or',\n * set: [\n * {\n * origin: '${fields.postcode.value}',\n * condition: '===',\n * target: '2',\n * },\n * ],\n * },\n * ```\n */\n conditions?: TVAvailableValidationConditions;\n /**\n * Between validations\n *\n * @example - Between ages\n * ``` type teste = Pick<TVAvailableValidations, 'date'>\n * between: {\n * dates: [\n * {\n * operator: '>=',\n * origin: {\n * format: 'YYYYMMDD',\n * intervals: {\n * years: 18,\n * },\n * },\n * },\n * {\n * operator: '<=',\n * origin: {\n * format: 'YYYYMMDD',\n * intervals: {\n * years: 75,\n * },\n * },\n * }\n * ]\n * }\n * ```\n *\n * @example - Between numbers\n * ```\n * between: {\n * start: '3',\n * end: '4',\n * isIncludedBoundaries: true\n * },\n * ```\n *\n */\n between?: {\n /**\n * Array of date validations. To make it possible, ensure that the conditions is > and < in both date validations.\n */\n dates?: TVAvailableValidations['date'][];\n /**\n * The first number of the validation. If the current value is grater than this number, the validation will pass.\n */\n start?: number;\n /**\n * The second number of the validation. If the current value is lower than this number, the validation will pass.\n */\n end?: number;\n /**\n * If it's true, the comparision is transformed to >= and <=. So, the numbers that were passed are included in the validation.\n */\n isIncludedBoundaries?: boolean;\n };\n /**\n * Dates validations\n *\n * @example - Dates should be different\n * ```\n * date: {\n * operator: '!==',\n * origin: {\n * format: 'DDMMYYYY',\n * },\n * target: {\n * format: 'DDMMYYYY',\n * value: '10/10/2001',\n * },\n * },*\n * ```\n *\n * @example - Compare only valid dates using intervals\n * ```\n * date: {\n * onlyValidDate: true,\n * operator: '<',\n * origin: {\n * format: 'DD/MM/YYYY',\n * intervals: {\n * years: 1,\n * },\n * },\n * },\n * ```\n *\n * @example - Should have at max 85 years\n * ```\n * {\n * operator: '>',\n * origin: {\n * format: 'DDMMYYYY',\n * value: eightyFiveYearsDate,\n * intervals: {\n * years: 85,\n * },\n * },\n * }\n * }\n *\n * ```\n */\n date?: {\n /**\n * Flag to force only valid dates. Valid dates must be of min length of 8\n */\n onlyValidDate?: boolean;\n /**\n * List of operations you can do\n * - between origin and target dates\n * - between origin and intervals\n */\n operator: TValidationDateOperators;\n /**\n * The origin configurations\n */\n origin: {\n /**\n * Origin date value\n */\n value?: string | number;\n /**\n * The available date formats\n */\n format: TValidationDateFormats;\n /**\n * Intervals to compare with the original date.\n *\n * It will use todays date for comparison.\n *\n * @example\n *\n * origin date = 10/10/2022\n * interval.year = 1\n * operator = '==='\n *\n * It will compare (10/10/2022 + 1) with the current date and check if they are the same\n */\n intervals?: {\n years?: number;\n months?: number;\n days?: number;\n };\n };\n target?: {\n value: string | number;\n format: TValidationDateFormats;\n };\n };\n /**\n * Allow to define a maximum length for the input to have no error\n */\n length?: number;\n /**\n * Will look into the input length and send an error if if not greater than this value\n */\n greaterThan?: number | string;\n\n /**\n * Specifies a regular expression pattern that the value should match.\n */\n regex?: string;\n\n /**\n * Specifies the maximum length of the value (if it's a string).\n */\n maxLength?: number;\n\n /**\n * Specifies the minimum length of the value (if it's a string).\n */\n minLength?: number;\n\n /**\n * Specifies whether the field is required.\n */\n required?: boolean;\n\n /**\n * Specifies that the value should contain only letters.\n */\n onlyLetters?: boolean;\n\n /**\n * Specifies a value that the field should match.\n */\n value?: string | number | boolean;\n\n /**\n * Specifies that the field should not be empty.\n */\n notEmpty?: boolean;\n\n /**\n * A callback function that performs custom validation on the value.\n * @param value - The value to be validated.\n * @returns An object with validation results.\n */\n callback?(value: string | number): { fail: boolean; errorMessage?: string };\n\n /**\n * Specifies a numeric range for the value.\n */\n numericRange?: { start: number | string; end: number | string };\n\n /**\n * Specifies whether the value should be a number.\n */\n isNumber?: boolean;\n\n /**\n * Specifies that the field should not have extra spaces.\n */\n hasNoExtraSpaces?: boolean;\n\n /**\n * Specifies that the value should be an email address.\n */\n email?: boolean;\n\n /**\n * Specifies that the value should be less than a given number or string.\n */\n lessThan?: number | string;\n\n /**\n * Specifies that the value should be a sequential number.\n */\n sequentialNumber?: boolean;\n\n /**\n * Specifies that the value should not contain repeated numbers.\n */\n repeatedNumbers?: boolean;\n\n /**\n * Specifies that the value should be a URL.\n */\n url?: boolean;\n\n /**\n * Specifies a path error type.\n */\n path?: TPathError;\n\n /**\n * Specifies that the value should be a valid credit card number.\n */\n isCreditCard?: string[];\n\n /**\n * Specifies that the value should be a valid credit card number with a specific length.\n */\n isCreditCardAndLength?: string[];\n\n /**\n * Specifies that the value should match a credit card code with available options.\n */\n isCreditCodeMatch?: { numberCard: string; availableOptions: string[] };\n\n /**\n * Specifies custom validation options for the field.\n */\n customValidation?: ICustomValidationValue[];\n\n /**\n * Specifies that spaces are not allowed in the field.\n */\n notAllowSpaces?: true;\n\n /**\n * Specifies that the value should be in a predefined list of values.\n */\n isInTheList?: string[] | number[] | string;\n\n /**\n * Specifies field validation rules for nested fields.\n */\n fields?: {\n /**\n * The rule for validating nested fields (e.g., 'every').\n */\n rule: 'every';\n\n /**\n * An array of nested field validation configurations.\n */\n set: {\n /**\n * The binding for the nested field.\n */\n bind: string;\n\n /**\n * The field name for the nested field.\n */\n fieldName: string;\n\n /**\n * Validation options for the nested field, excluding the 'fields' property.\n */\n validations: Omit<TVAvailableValidations, 'fields'>;\n }[];\n };\n\n /**\n * Specifies that the value should be existed.\n */\n exists?: string | number;\n};\n\nexport type TGenericValidationRule = {\n [key: string]: TVAvailableValidations;\n};\n\nexport type TSchemaValidation = TVAvailableValidations | TGenericValidationRule;\n\nexport type TStepData = {\n navigated: boolean;\n index: number;\n data: Record<\n number,\n Pick<\n TFormValues,\n 'fields' | 'erroredFields' | 'formatted' | 'filteredFields'\n >\n >;\n currentStepSchema?: TComponent;\n isValid: boolean;\n numSteps?: number;\n};\n\nexport type TFormValues = {\n predictableErroredFields: string[];\n erroredFields: string[];\n fields: TFieldData;\n formatted: Record<string, unknown>;\n filteredFields?: Record<string, unknown>;\n form: {\n steps: TStepData;\n isValid: boolean;\n messages: string[];\n scope: TScope;\n };\n};\n\nexport type TError = {\n value: unknown;\n message?: string;\n fail: boolean;\n};\n\nexport type TErrors = Record<string, TError> | undefined;\n\n// TODO - object with the available errors has props\nexport type TErrorMessages = Record<string, string>;\n\nexport type TSchemaValidations = TSchemaHandler<TSchemaValidation>;\n\ntype TFormLevelSchemaHandler<T> = Partial<\n Record<\n | EEVents.AFTER_FIELD_API_CALL\n | EEVents.ON_FIELD_CHANGE\n | EEVents.ON_FIELD_KEYUP\n | EEVents.ON_FIELD_KEYDOWN\n | EEVents.ON_FORM_REHYDRATE\n | EEVents.ON_FORM_MOUNT\n | EEVents.ON_SCOPE_CHANGE,\n T\n >\n>;\n\ntype TSchemaHandler<T> = Partial<\n Record<\n | EEVents.AFTER_FIELD_API_CALL\n | EEVents.ON_FIELD_REHYDRATE\n | EEVents.ON_FIELD_CLEARED\n | EEVents.ON_FIELD_BINDED\n | EEVents.ON_FIELD_CHANGE\n | EEVents.ON_FIELD_KEYUP\n | EEVents.ON_FIELD_KEYDOWN\n | EEVents.ON_FIELD_BLUR\n | EEVents.ON_FIELD_MOUNT\n | EEVents.ON_FIELD_FOCUS\n | EEVents.ON_FIELD_CLICK,\n T\n >\n>;\n\nexport type TSchemaVisibilityConditions = {\n /**\n * Enables visibility of fields only if any or all validation conditions are positive.\n *\n * The default is false, so if all validations are false, the field will display, if any are positive,\n * the field will hide, as well as if all are positive.\n */\n showOnlyIfTrue?: boolean;\n /**\n * Allows you to choose the type of chain for validations.\n *\n * The default is OR, where at least one validation needs to be true to work. In the case of AND,\n * all validations must be true.\n */\n rule?: 'or' | 'and';\n /**\n * The validations that will say if the target field will be visible or not\n *\n * Those validations will run against your field (the one that has this directive)\n */\n validations: TSchemaValidation;\n /**\n * Target field that will have the visibility toggled\n */\n fieldName?: string;\n /**\n * Target fields that will have the visibility toggled\n */\n fieldNames?: string[];\n}[];\n\nexport type TClearFieldValue = string | number | boolean;\n\nexport type TClearField = {\n /**\n * The clearValues runs validations on the target field and not on the field it is declaring.\n * Therefore, set this prop with true if you want validations to be performed on the current field.\n */\n useCurrentFieldValidation?: boolean;\n /**\n * Validations to run for the target field\n */\n validations?: TSchemaValidation | TSchemaValidation[];\n /**\n * target fields that will be used in the validation specified\n */\n fields: string[];\n /**\n * The cleared values on the fields in case they do not pass the validation\n */\n clearedValue: TClearFieldValue | TClearFieldValue[];\n /**\n * The cleared props from each component field on target fields array\n */\n clearedProps?: Record<string, unknown> | Record<string, unknown>[];\n /**\n * The cleared values on the fields in case they do pass the validation\n */\n defaultClearedValue?: TClearFieldValue | TClearFieldValue[];\n /**\n * The cleared props from each component field on target fields array if they pass validation\n */\n defaultClearedProps?: Record<string, unknown> | Record<string, unknown>[];\n};\n\nexport type TSchemaClearFields = TClearField[];\n\nexport type TSchemaApi = {\n /**\n * Specify a debounce time in miliseconds for your call\n */\n debounceTime?: number;\n method: 'GET' | 'POST' | 'PUT' | 'PATCH';\n url: string;\n headers?: HeadersInit | undefined;\n body?: Record<string, any>;\n fieldValueAsParams?: Record<string, string>;\n fieldValueAsPathParams?: string[];\n scope?: string;\n blockRequestWhenInvalid?: boolean;\n preConditions?: TSchemaValidation;\n}[];\n\nexport type TSchemaMasks = { cleanMask?: boolean } & TComponentMasks;\n\nexport type TFormEventDirectives = {\n visibilityConditions: TSchemaVisibilityConditions;\n};\n\nexport type TComponent = {\n /**\n * This name will be used later to correlate the field with the value, and you will be able to read it.\n *\n * You can also mount here complex objects like\n *\n * name={a.b.c}\n *\n * that will result in\n * a: {\n * b: {\n * c: 'field_value'\n * }\n * }\n */\n name: string;\n /**\n * A component name that should map to the one you gave in the form mappings\n *\n * @example - For React\n * ```\n * const mappings: TMapper = {\n * input: { component: Input },\n * formGroup: { component: FormGroup },\n * };\n * ```\n *\n * The component name for the Input element will be \"input\" ending up like\n * ```\n * {\n * component: 'input'\n * }\n * ```\n */\n component: string;\n /**\n * You can attach metadata to your component that will be forwarded to you after on your frontend\n * callback methods link `onData`, `onBlur` etc\n */\n metadata?: Record<string, any>;\n /**\n * This property allows you to specify a virtual fieldName that can be in several fields\n *\n * USAGE - You have two fields but you want to have the value stored only under one name\n *\n */\n group?: string;\n wrapper?: new () => React.Component;\n children?: TComponent[];\n /**\n * Field error messages in case any validation fails\n *\n * @example - Set a default error message for all the validations\n *\n * ```\n * {\n * errorMessages: {\n * default: 'default error message'\n * }\n * }\n * ```\n *\n * @example - Set error message for a given validation\n *\n * ```\n * {\n * validations: {\n * ON_FIELD_CHANGE: {\n * required: true\n * }\n * },\n * errorMessages: {\n * required: 'This field is required'\n * }\n * }\n * ```\n *\n */\n errorMessages?: TErrorMessages;\n type?: 'text' | 'number' | string;\n /**\n * Allow you to set a initial state for this field\n */\n state?: {\n /**\n * Hide the field\n */\n hidden?: boolean;\n /**\n * Ignore value from field\n */\n ignoreValue?: boolean;\n };\n /**\n * This key lets you inject props directly into the component\n */\n props?: Record<string, unknown>;\n /**\n * Setup validations to be used in the field.\n *\n * You can setup validations in several life-cycle methods\n *\n * @example - Required validation\n * ```\n * validations: {\n ON_FIELD_CHANGE: {\n required: true,\n },\n },\n * ```\n */\n validations?: TSchemaHandler<\n Pick<TEventReducedSchema, 'validations'>['validations']\n >;\n /**\n * Filters the component value based on a validation.\n */\n filter?: Pick<TEventReducedSchema, 'validations'>['validations'];\n /**\n * Allows you to specify the conditions a given field will be visible\n * what will run when this field meets the specified life-cycle\n */\n visibilityConditions?: Omit<\n TSchemaHandler<\n Pick<TEventReducedSchema, 'visibilityConditions'>['visibilityConditions']\n >,\n 'ON_FIELD_REHYDRATE' | 'ON_FIELD_CLEARED' | 'ON_FIELD_FOCUS'\n >;\n /**\n * Will clear target fields in case they do not pass with the specified validations\n */\n clearFields?: Omit<\n TSchemaHandler<Pick<TEventReducedSchema, 'clearFields'>['clearFields']>,\n 'ON_FIELD_REHYDRATE' | 'ON_FIELD_CLEARED' | 'ON_FIELD_FOCUS'\n >;\n /**\n * Allows you to make api calls using events emitted by the component.\n */\n api?: Omit<\n TSchemaHandler<Pick<TEventReducedSchema, 'api'>['api']>,\n 'ON_FIELD_REHYDRATE' | 'ON_FIELD_FOCUS' | 'AFTER_FIELD_API_CALL'\n >;\n /**\n * Allows you to display the value of the masked component by events\n */\n masks?: Partial<\n Record<\n | EEVents.ON_FIELD_BLUR\n | EEVents.ON_FIELD_MOUNT\n | EEVents.ON_FIELD_FOCUS\n | EEVents.ON_FIELD_CHANGE\n | EEVents.ON_FIELD_KEYUP\n | EEVents.ON_FIELD_KEYDOWN,\n Pick<TEventReducedSchema, 'masks'>['masks']\n >\n >;\n /**\n * Allows you to format the value that the field will receive for each event issuance\n */\n formatters?: Omit<\n TSchemaHandler<Pick<TEventReducedSchema, 'formatters'>['formatters']>,\n 'ON_FIELD_REHYDRATE' | 'ON_FIELD_FOCUS'\n >;\n};\n\nexport type TEventReducedSchema = {\n api: TSchemaApi;\n clearFields: TSchemaClearFields;\n formatters: TSchemaFormatters;\n masks: TSchemaMasks;\n validations: TSchemaValidation;\n visibilityConditions: TSchemaVisibilityConditions;\n};\n\nexport type TStep = {\n component: string;\n name: string;\n children: TComponent[];\n props?: Record<string, string>;\n};\n\nexport type TComponentPropsMapping = {\n getValue?: string;\n setValue?: string;\n onBlur?: string;\n onClick?: string;\n onFocus?: string;\n onKeyUp?: string;\n onKeyDown?: string;\n setErrorMessage?: string;\n setErrorState?: string;\n};\n\nexport type TPropsMapping = Record<string, TComponentPropsMapping>;\n\nexport type TSchema = {\n /**\n * Used to disable form submit input and prevent to submit form using enter event.\n * Default is false.\n */\n disableFormSubmit?: boolean;\n action?: string;\n method?: string;\n /**\n * Give some configurations to the form\n */\n configs?: TConfigs;\n /**\n * Allows you to expose some messages to the outside world when something happen\n */\n messages?: TFormMessages;\n /**\n * Specify some static field defaults before rendereing the form.\n *\n * If you have initialValues in the frontend setted, those will ovewride this\n */\n formattedDataDefaults?: Record<string, unknown>;\n /**\n * Form level props mapping\n */\n propsMapping?: TPropsMapping;\n visibilityConditions?: TFormLevelSchemaHandler<TSchemaVisibilityConditions>;\n /**\n * Entry point for the form should be a step (even if you have only one)\n */\n components: TStep[];\n /**\n * You can have many fields in the form, but be interested only in some\n *\n * You can put here the fields you want to read onSubmit for example\n *\n * You will receive those in TFormValues.filteredFields\n */\n filteredFields?: string[];\n /**\n * Schema level iVars.\n *\n * These iVars will go to the global scope namespace\n */\n iVars?: TIVars;\n};\n\nexport type TSplitterFormatterValue = {\n value: string;\n position: number;\n}[];\n\nexport type TSchemaFormatters = {\n splitter?: TSplitterFormatterValue;\n capitalize?: boolean;\n upperCase?: boolean;\n gapsCreditCard?: string[];\n onlyNumbers?: boolean;\n onlyLetters?: boolean;\n regex?: string;\n};\n\nexport type TConfigs = {\n observables?: { templates?: { exclude?: string[] } };\n};\n\nexport type TFlowType = {\n [x: string]: {\n events: (component?: TComponent) => EEVents[];\n handler: (args: TEventInformation<unknown>) => void;\n }[];\n};\n"],"names":["TAvailableHooks"],"mappings":"aAsHA,IAAYA,yDAAAA,QAKXA,qBAAA,GALWA,EAAAA,QAAeA,kBAAfA,wBAKX,CAAA,IAJC,SAAA,WACAA,EAAA,WAAA,aACAA,EAAA,UAAA,YACAA,EAAA,WAAA"}
|