@bolttech/form-engine-core 1.0.1-beta.3 → 1.0.1
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/index.esm.js +134 -84
- package/package.json +9 -9
- package/src/constants/constants.d.ts +2 -1
- package/src/formatters/string.d.ts +2 -2
- package/src/helpers/creditCard.d.ts +1 -1
- package/src/helpers/helpers.d.ts +2 -4
- package/src/index.d.ts +1 -0
- package/src/interfaces/schema.d.ts +28 -6
- package/src/managers/field.d.ts +0 -1
- package/src/managers/form.d.ts +9 -3
- package/src/managers/formGroup.d.ts +4 -2
- package/src/masks/generic.d.ts +1 -1
- package/src/masks/handler.d.ts +1 -1
- package/src/types/event.d.ts +75 -8
- package/src/types/mapper.d.ts +12 -20
- package/src/types/schema.d.ts +204 -37
- package/src/types/template.d.ts +21 -6
- package/src/validations/date.d.ts +1 -1
- package/src/validations/list.d.ts +1 -1
- package/src/validations/logical.d.ts +1 -1
- package/src/validations/string.d.ts +1 -1
- /package/{index.esm.d.ts → index.d.ts} +0 -0
|
@@ -44,7 +44,12 @@ import { TApiEvent, TFormatters, TMasks, TProps, TResetPathMethods, TResetValueM
|
|
|
44
44
|
* },
|
|
45
45
|
* visibilityConditions: [{ conditions: { field: 'age', value: 18 } }],
|
|
46
46
|
* resetValues: [{ field: 'age', resetTo: '' }],
|
|
47
|
-
* api: {
|
|
47
|
+
* api: {
|
|
48
|
+
* defaultConfig: {
|
|
49
|
+
* config: { method: 'POST', url: 'https://api.example.com/submit' },
|
|
50
|
+
* events: [{ eventName: 'ON_FIELD_BLUR' }]
|
|
51
|
+
* }
|
|
52
|
+
* },
|
|
48
53
|
* formatters: { capitalize: true },
|
|
49
54
|
* masks: { currency: { align: 'left', decimal: '.', precision: 2, prefix: '$', thousands: ',' } },
|
|
50
55
|
* children: [],
|
|
@@ -54,24 +59,37 @@ import { TApiEvent, TFormatters, TMasks, TProps, TResetPathMethods, TResetValueM
|
|
|
54
59
|
* ```
|
|
55
60
|
*/
|
|
56
61
|
interface IComponentSchema {
|
|
62
|
+
/** The type of component (e.g., 'input', 'button'). */
|
|
57
63
|
component: string;
|
|
64
|
+
/** The properties of the component. */
|
|
58
65
|
props?: TProps;
|
|
66
|
+
/** The name of the component. */
|
|
59
67
|
name: string;
|
|
68
|
+
/** The name of the field when submit values. */
|
|
60
69
|
nameToSubmit?: string;
|
|
70
|
+
/** The validation methods for the component. */
|
|
61
71
|
validations?: TValidations;
|
|
72
|
+
/** The API configuration for the component. */
|
|
62
73
|
api?: TApiEvent;
|
|
74
|
+
/** The visibility conditions for the component. */
|
|
63
75
|
visibilityConditions?: TVisibility[];
|
|
76
|
+
/** The reset value methods for the component. */
|
|
64
77
|
resetValues?: TResetValueMethods[];
|
|
78
|
+
/** The reset property values for the component. */
|
|
65
79
|
resetPropertyValues?: TResetPathMethods[];
|
|
80
|
+
/** The formatters for the component. */
|
|
66
81
|
formatters?: TFormatters;
|
|
82
|
+
/** The masks for the component. */
|
|
67
83
|
masks?: TMasks;
|
|
84
|
+
/** The child components. */
|
|
68
85
|
children?: IComponentSchema[];
|
|
86
|
+
/** Visibility status the component will mount (to avoid SSR blinking) */
|
|
69
87
|
visibility?: boolean;
|
|
88
|
+
/** Check this if you want the last visible value to be restored after a visiblity schema rule applied */
|
|
70
89
|
persistValue?: boolean;
|
|
71
90
|
}
|
|
72
91
|
interface IComponentSchemaAsFormField<T> extends IComponentSchema {
|
|
73
92
|
mapper?: TMapper<T>;
|
|
74
|
-
order?: number;
|
|
75
93
|
children?: IComponentSchemaAsFormField<T>[];
|
|
76
94
|
}
|
|
77
95
|
/**
|
|
@@ -79,20 +97,23 @@ interface IComponentSchemaAsFormField<T> extends IComponentSchema {
|
|
|
79
97
|
* Represents the schema for a form.
|
|
80
98
|
*
|
|
81
99
|
* @property {string} index - The unique index or identifier for the form.
|
|
82
|
-
* @property {string} [action] - The URL to which the form data will be submitted.
|
|
83
|
-
* @property {string} [method] - The HTTP method used to submit the form (e.g., 'POST', 'GET').
|
|
100
|
+
* @property {string} [action] - The URL to which the form data will be submitted. (experimental)
|
|
101
|
+
* @property {string} [method] - The HTTP method used to submit the form (e.g., 'POST', 'GET') (experimental).
|
|
84
102
|
* @property {Record<string, unknown>} [initialValues] - The initial values for the form fields.
|
|
85
103
|
* @property {Record<string, unknown>} [iVars] - Dynamic key value pairs that change from any external source
|
|
86
104
|
* @property {IComponentSchema[]} [components] - The list of components included in the form.
|
|
105
|
+
* @property {boolean} [stopEventsOnSubmit] - stop all the events declared as callback on useForm/Form once form is submitted
|
|
106
|
+
* @property {TSchemaFormConfig} [config] - form configurations to change event debouncers and debugging tools
|
|
87
107
|
*
|
|
88
108
|
* @example
|
|
89
109
|
* ```typescript
|
|
90
110
|
* const formSchema: IFormSchema = {
|
|
91
111
|
* index: 'userForm',
|
|
92
|
-
* action: 'https://api.example.com/submit',
|
|
93
|
-
* method: 'POST',
|
|
94
112
|
* initialValues: { name: '', email: '' },
|
|
95
113
|
* iVars: iVarsState,
|
|
114
|
+
* config: {
|
|
115
|
+
* defaultLogVerbose: true
|
|
116
|
+
* },
|
|
96
117
|
* components: [
|
|
97
118
|
* { component: 'input', name: 'name', props: { placeholder: 'Enter your name' } },
|
|
98
119
|
* { component: 'input', name: 'email', props: { placeholder: 'Enter your email' } }
|
|
@@ -108,5 +129,6 @@ interface IFormSchema {
|
|
|
108
129
|
initialValues?: Record<string, unknown>;
|
|
109
130
|
iVars?: Record<string, unknown>;
|
|
110
131
|
components?: IComponentSchema[];
|
|
132
|
+
stopEventsOnSubmit?: boolean;
|
|
111
133
|
}
|
|
112
134
|
export { IFormSchema, IComponentSchema, IComponentSchemaAsFormField };
|
package/src/managers/field.d.ts
CHANGED
package/src/managers/form.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ import { IFormField } from './field';
|
|
|
2
2
|
import { Subject, Subscription } from 'rxjs';
|
|
3
3
|
import { IComponentSchema, IComponentSchemaAsFormField, IFormSchema } from '../interfaces/schema';
|
|
4
4
|
import { TSchemaFormConfig } from '../types/schema';
|
|
5
|
-
import { TSubscribedTemplates, TTemplateEvent } from '../types/template';
|
|
5
|
+
import { TSubscribedTemplates, TTemplateAvaliableScopes, TTemplateEvent } from '../types/template';
|
|
6
6
|
import { TEvents, TFieldEvent, TFieldValidationPayload, TFormDataPayload, TFormSubmitPayload, TFormValidationPayload, TMutationEvents } from '../types/event';
|
|
7
7
|
import { TFormEntry, TFormValues } from '../types/form';
|
|
8
8
|
import { TMapper } from '../types/mapper';
|
|
9
|
-
import { TEMPLATE_AVALIABLE_SCOPES } from '../constants/constants';
|
|
10
9
|
/**
|
|
11
10
|
* Represents the core logic for managing a form, including field management, validation, and submission.
|
|
12
11
|
*/
|
|
@@ -45,6 +44,8 @@ declare class FormCore {
|
|
|
45
44
|
}>;
|
|
46
45
|
queuedInitialValues: Map<string, unknown>;
|
|
47
46
|
_valid: boolean;
|
|
47
|
+
stopEventsOnSubmit: boolean;
|
|
48
|
+
submitted: boolean;
|
|
48
49
|
/**
|
|
49
50
|
* Creates an instance of FormCore.
|
|
50
51
|
*
|
|
@@ -61,6 +62,11 @@ declare class FormCore {
|
|
|
61
62
|
* mock function to simulate form mount onto the adapter
|
|
62
63
|
*/
|
|
63
64
|
generateFields(): void;
|
|
65
|
+
/**
|
|
66
|
+
*flag utility to prevent Subjects from emitting after form submission and stopEventsOnSubmit
|
|
67
|
+
* @returns {boolean} - result of the flag utility.
|
|
68
|
+
*/
|
|
69
|
+
private submitChecker;
|
|
64
70
|
/**
|
|
65
71
|
* callback function passed to field instance to notify field adapter mount status
|
|
66
72
|
* once the field has all field instance properties set, this function will handle all
|
|
@@ -112,7 +118,7 @@ declare class FormCore {
|
|
|
112
118
|
* @returns {unknown | undefined} The value of the property, or undefined if the field doesn't exist.
|
|
113
119
|
*/
|
|
114
120
|
getValue({ scope, key, property, path, }: {
|
|
115
|
-
scope:
|
|
121
|
+
scope: TTemplateAvaliableScopes;
|
|
116
122
|
key: string;
|
|
117
123
|
property: string;
|
|
118
124
|
path: string[];
|
|
@@ -7,16 +7,18 @@ import { TFormDataPayload, TFormGroupOnDataEventPayload, TFormGroupOnSubmitEvent
|
|
|
7
7
|
/**
|
|
8
8
|
* Represents a group that manages multiple forms.
|
|
9
9
|
*/
|
|
10
|
-
declare class FormGroup {
|
|
10
|
+
declare class FormGroup<ComponentElementType> {
|
|
11
11
|
forms: Map<string, TFormCore>;
|
|
12
12
|
config: Required<TSchemaFormConfig>;
|
|
13
13
|
dataSubject$: Subject<TFormDataPayload>;
|
|
14
14
|
formValidSubject$: Subject<TFormValidationPayload>;
|
|
15
15
|
submitSubject$: Subject<TFormSubmitPayload<unknown>>;
|
|
16
|
+
mappers?: TMapper<ComponentElementType>[];
|
|
16
17
|
/**
|
|
17
18
|
* Creates an instance of FormGroup.
|
|
18
19
|
*/
|
|
19
20
|
constructor(entry?: {
|
|
21
|
+
mappers?: TMapper<ComponentElementType>[];
|
|
20
22
|
config?: TSchemaFormConfig;
|
|
21
23
|
});
|
|
22
24
|
/**
|
|
@@ -104,5 +106,5 @@ declare class FormGroup {
|
|
|
104
106
|
}): import("rxjs").Subscription;
|
|
105
107
|
destroy: () => void;
|
|
106
108
|
}
|
|
107
|
-
type TFormGroup = FormGroup
|
|
109
|
+
type TFormGroup<T> = FormGroup<T>;
|
|
108
110
|
export { TFormGroup, FormGroup };
|
package/src/masks/generic.d.ts
CHANGED
|
@@ -35,5 +35,5 @@ import { TMasks } from '../types/schema';
|
|
|
35
35
|
* console.log(maskedValue); // Output: 'ab***gh###'
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
declare const _default: (value: string, masks: TMasks) => string;
|
|
38
|
+
declare const _default: (value: string, masks: TMasks | null) => string;
|
|
39
39
|
export default _default;
|
package/src/masks/handler.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { TMasks } from '../types/schema';
|
|
2
|
-
export declare const masks: Record<keyof TMasks, (value: unknown, masks?: TMasks) => unknown>;
|
|
2
|
+
export declare const masks: Record<keyof TMasks, (value: unknown, masks?: TMasks | null) => unknown>;
|
package/src/types/event.d.ts
CHANGED
|
@@ -1,15 +1,81 @@
|
|
|
1
1
|
import { IFormField } from '../managers';
|
|
2
2
|
import { TFormValues } from './form';
|
|
3
3
|
/**
|
|
4
|
-
* @type
|
|
4
|
+
* @type TEventEnum
|
|
5
5
|
* Represents the different types of events that can occur on form fields.
|
|
6
|
+
* @property {never} ON_FIELD_MOUNT - when field mounts on page
|
|
7
|
+
* @property {never} ON_FIELD_UNMOUNT - when field unmounts on page (also triggered when form is unmounted from page)
|
|
8
|
+
* @property {never} ON_FIELD_CHANGE - when field changes value by user inout
|
|
9
|
+
* @property {never} ON_FIELD_BLUR - when field is blurred
|
|
10
|
+
* @property {never} ON_FIELD_FOCUS - when field is focused
|
|
11
|
+
* @property {never} ON_FIELD_CLICK - when field is clicked
|
|
12
|
+
* @property {never} ON_FIELD_KEYUP - when the pressing key button on field is lifted up
|
|
13
|
+
* @property {never} ON_FIELD_KEYDOWN - when a key button on field is pressed down
|
|
14
|
+
* @property {never} ON_FIELD_CLEARED - when a field was changed with a resetValues rule
|
|
15
|
+
* @property {never} ON_FORM_SUBMIT - when the form is submitted (only type="submit" buttons)
|
|
16
|
+
* @property {never} ON_FIELD_VALIDATION - when a field is validaded by a validation rule
|
|
17
|
+
* @property {never} ON_FORM_MOUNT - emitted when the form mounts
|
|
18
|
+
* @property {never} ON_API_FIELD_REQUEST - emitted when an api request from schema is called
|
|
19
|
+
* @property {never} ON_API_FIELD_RESPONSE - emitted when an api response from schema is received
|
|
6
20
|
*
|
|
7
21
|
* @example
|
|
8
22
|
* ```typescript
|
|
9
23
|
* const event: TEvents = 'ON_FIELD_CHANGE';
|
|
10
24
|
* ```
|
|
11
25
|
*/
|
|
12
|
-
type
|
|
26
|
+
type TEventEnum = {
|
|
27
|
+
ON_FIELD_MOUNT: never;
|
|
28
|
+
ON_FIELD_UNMOUNT: never;
|
|
29
|
+
ON_FIELD_CHANGE: never;
|
|
30
|
+
ON_FIELD_BLUR: never;
|
|
31
|
+
ON_FIELD_FOCUS: never;
|
|
32
|
+
ON_FIELD_CLICK: never;
|
|
33
|
+
ON_FIELD_KEYUP: never;
|
|
34
|
+
ON_FIELD_KEYDOWN: never;
|
|
35
|
+
ON_FIELD_CLEARED: never;
|
|
36
|
+
ON_FORM_SUBMIT: never;
|
|
37
|
+
ON_FIELD_VALIDATION: never;
|
|
38
|
+
ON_FORM_MOUNT: never;
|
|
39
|
+
ON_API_FIELD_REQUEST: never;
|
|
40
|
+
ON_API_FIELD_RESPONSE: never;
|
|
41
|
+
};
|
|
42
|
+
type TEvents = keyof TEventEnum;
|
|
43
|
+
/**
|
|
44
|
+
* Represents the possible event properties for form fields callbacks.
|
|
45
|
+
* * Represents a mapping of event properties to their corresponding callback functions.
|
|
46
|
+
* @property {string} onChange - trigger bind component change event
|
|
47
|
+
* @property {string} onBlur - trigger bind component blur event
|
|
48
|
+
* @property {string} onFocus - trigger bind component focus event
|
|
49
|
+
* @property {string} onKeyDown - trigger bind component keydown event
|
|
50
|
+
* @property {string} onKeyUp - trigger bind component keyup event
|
|
51
|
+
* @property {string} onMount - triggered on field mount
|
|
52
|
+
* @property {string} onApiResponse - triggered when schema api call is completed
|
|
53
|
+
* @property {string} onApiRequest - triggered when schema api call starts
|
|
54
|
+
* @property {string} onClick - trigger bind component keyup event
|
|
55
|
+
* @property {string} onCleared - triggered when a resetValue rule apply on the target field
|
|
56
|
+
* @property {string} onUnmount - triggered when a field unmounts
|
|
57
|
+
*/
|
|
58
|
+
type TEventPropsEnum = {
|
|
59
|
+
onChange: never;
|
|
60
|
+
onBlur: never;
|
|
61
|
+
onFocus: never;
|
|
62
|
+
onKeyDown: never;
|
|
63
|
+
onKeyUp: never;
|
|
64
|
+
onMount: never;
|
|
65
|
+
onApiResponse: never;
|
|
66
|
+
onApiRequest: never;
|
|
67
|
+
onClick: never;
|
|
68
|
+
onCleared: never;
|
|
69
|
+
onUnmount: never;
|
|
70
|
+
};
|
|
71
|
+
type TEventProps = keyof TEventPropsEnum;
|
|
72
|
+
type TEventDataPropsEnum = {
|
|
73
|
+
onFormMount: never;
|
|
74
|
+
onData: never;
|
|
75
|
+
onSubmit: never;
|
|
76
|
+
onValid: never;
|
|
77
|
+
};
|
|
78
|
+
type TEventDataProps = keyof TEventDataPropsEnum;
|
|
13
79
|
/**
|
|
14
80
|
* @type TMutationEvents
|
|
15
81
|
* Represents the different types of events that can occur internally that triggers templating.
|
|
@@ -83,15 +149,16 @@ type TFormValidationPayload = {
|
|
|
83
149
|
type TFieldValidationPayload = {
|
|
84
150
|
fieldTrigger: string;
|
|
85
151
|
};
|
|
152
|
+
type TFormDataValues<T> = {
|
|
153
|
+
formId: string;
|
|
154
|
+
formField: string;
|
|
155
|
+
values?: TFormValues<T>;
|
|
156
|
+
};
|
|
86
157
|
/**
|
|
87
158
|
* @type TFormGroupOnDataEventPayload
|
|
88
159
|
* Form Group onData event emitted payload on callback function parameter
|
|
89
160
|
*/
|
|
90
|
-
type TFormGroupOnDataEventPayload<T> = Record<string,
|
|
91
|
-
formId: string;
|
|
92
|
-
formField: string;
|
|
93
|
-
values?: TFormValues<T>;
|
|
94
|
-
}>;
|
|
161
|
+
type TFormGroupOnDataEventPayload<T> = Record<string, TFormDataValues<T>>;
|
|
95
162
|
/**
|
|
96
163
|
* @type TFormGroupOnValidEventPayload
|
|
97
164
|
* Form Group onValid event emitted payload on callback function parameter
|
|
@@ -105,4 +172,4 @@ type TFormGroupOnValidEventPayload = {
|
|
|
105
172
|
* Form Group onSubmit event emitted payload on callback function parameter
|
|
106
173
|
*/
|
|
107
174
|
type TFormGroupOnSubmitEventPayload<T> = Record<string, TFormValues<T> | undefined>;
|
|
108
|
-
export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent, TFormDataPayload, TFormSubmitPayload, TFormGroupOnDataEventPayload, TFormGroupOnValidEventPayload, TFormGroupOnSubmitEventPayload, TFormValidationPayload, TFieldValidationPayload, };
|
|
175
|
+
export { TEvents, TEventEnum, TEventProps, TEventPropsEnum, TEventDataProps, TEventDataPropsEnum, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent, TFormDataPayload, TFormDataValues, TFormSubmitPayload, TFormGroupOnDataEventPayload, TFormGroupOnValidEventPayload, TFormGroupOnSubmitEventPayload, TFormValidationPayload, TFieldValidationPayload, };
|
package/src/types/mapper.d.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import { TValueChangeEvent } from './event';
|
|
1
|
+
import { TEventDataPropsEnum, TEventPropsEnum, TValueChangeEvent } from './event';
|
|
2
2
|
import { OneOf } from './utility';
|
|
3
|
+
type TComponentPropsMappingSubset = keyof (Pick<TEventPropsEnum, 'onBlur' | 'onChange' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'onClick'> & Pick<TEventDataPropsEnum, 'onSubmit'>);
|
|
3
4
|
/**
|
|
4
5
|
* @type TComponentPropsMapping
|
|
5
6
|
* Represents the mapping of component properties for various events and actions.
|
|
6
|
-
*
|
|
7
|
-
* @property {string} [
|
|
8
|
-
* @property {string} [
|
|
9
|
-
* @property {string} [
|
|
10
|
-
* @property {string} [onClick] - Function to handle the click event.
|
|
11
|
-
* @property {string} [onFocus] - Function to handle the focus event.
|
|
12
|
-
* @property {string} [onKeyUp] - Function to handle the keyup event.
|
|
13
|
-
* @property {string} [onKeyDown] - Function to handle the keydown event.
|
|
14
|
-
* @property {string} [setErrorMessage] - Function to set the error message.
|
|
15
|
-
* @property {string} [setErrorState] - Function to set the error state.
|
|
7
|
+
* @property {string} [getValue] - component function name to get the value.
|
|
8
|
+
* @property {string} [setValue] - component function name to set the value.
|
|
9
|
+
* @property {string} [setErrorMessage] - component function name to set the error message.
|
|
10
|
+
* @property {string} [setErrorState] - component function name to set the error state.
|
|
16
11
|
*
|
|
17
12
|
* @example
|
|
18
13
|
* ```typescript
|
|
@@ -28,16 +23,11 @@ import { OneOf } from './utility';
|
|
|
28
23
|
* setErrorState: 'setErrorStateFunction'
|
|
29
24
|
* };
|
|
30
25
|
* ```
|
|
26
|
+
* @interface
|
|
31
27
|
*/
|
|
32
|
-
type TComponentPropsMapping = {
|
|
28
|
+
type TComponentPropsMapping = Partial<Record<TComponentPropsMappingSubset, string>> & {
|
|
33
29
|
getValue?: string;
|
|
34
30
|
setValue?: string;
|
|
35
|
-
onBlur?: string;
|
|
36
|
-
onClick?: string;
|
|
37
|
-
onSubmit?: string;
|
|
38
|
-
onFocus?: string;
|
|
39
|
-
onKeyUp?: string;
|
|
40
|
-
onKeyDown?: string;
|
|
41
31
|
setErrorMessage?: string;
|
|
42
32
|
setErrorState?: string;
|
|
43
33
|
};
|
|
@@ -46,14 +36,15 @@ type TComponentPropsMapping = {
|
|
|
46
36
|
* Represents the mapping of a component, including the component type,
|
|
47
37
|
* name, events, and an optional function to handle value changes.
|
|
48
38
|
*
|
|
49
|
-
* @property {ElementType} component - The
|
|
39
|
+
* @property {ElementType} component - The component that will represent the input.
|
|
40
|
+
* * @property {ElementType} asynccomponent - The component that will represent the input but dynamically imported (suspense/lazy).
|
|
50
41
|
* @property {string} componentName - The name of the component.
|
|
51
42
|
* @property {TComponentPropsMapping} [events] - Mapping event properties for the component.
|
|
52
43
|
* @property {TValueChangeEvent} [valueChangeEvent] - Optional function to handle value changes.
|
|
53
44
|
*
|
|
54
45
|
* @example
|
|
55
46
|
* ```typescript
|
|
56
|
-
* const mappers: TMapper[] = [
|
|
47
|
+
* const mappers: TMapper<ElementType>[] = [
|
|
57
48
|
* {
|
|
58
49
|
* component: InputElement,
|
|
59
50
|
* componentName: 'input',
|
|
@@ -83,6 +74,7 @@ type TComponentPropsMapping = {
|
|
|
83
74
|
* },
|
|
84
75
|
* ];
|
|
85
76
|
* ```
|
|
77
|
+
* @interface
|
|
86
78
|
*/
|
|
87
79
|
type TMapper<T> = {
|
|
88
80
|
componentName: string;
|