@bolttech/form-engine-core 0.0.1-beta.1 → 0.0.1-beta.11
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/README.md +1616 -0
- package/index.esm.js +229 -137
- package/package.json +2 -2
- package/src/constants/constants.d.ts +3 -0
- package/src/interfaces/schema.d.ts +12 -2
- package/src/interfaces/state.d.ts +1 -6
- package/src/managers/field.d.ts +25 -47
- package/src/managers/form.d.ts +29 -23
- package/src/managers/formGroup.d.ts +23 -2
- package/src/managers/index.d.ts +3 -0
- package/src/types/event.d.ts +7 -1
- package/src/types/form.d.ts +9 -9
- package/src/types/schema.d.ts +13 -2
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/form-engine-core",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.11",
|
|
4
4
|
"module": "./index.esm.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.esm.js",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@gaignoux/currency": "1.1.0",
|
|
9
|
-
"credit-card-type": "10.0.
|
|
9
|
+
"credit-card-type": "10.0.1",
|
|
10
10
|
"lodash": "4.17.21",
|
|
11
11
|
"rxjs": "7.8.1"
|
|
12
12
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TMapper } from '../types/mapper';
|
|
2
|
+
import { TApiEvent, TErrorMessages, TEvent, TFormatters, TMasks, TProps, TResetValueMethods, TSchemaFormConfig, TValidationMethods, TVisibility } from '../types/schema';
|
|
2
3
|
/**
|
|
3
4
|
* @interface IComponentSchema
|
|
4
5
|
* Represents the schema for a component within a form.
|
|
@@ -6,6 +7,7 @@ import { TApiEvent, TErrorMessages, TEvent, TFormatters, TMasks, TProps, TResetV
|
|
|
6
7
|
* @property {string} component - The type of component (e.g., 'input', 'button').
|
|
7
8
|
* @property {TProps} props - The properties of the component.
|
|
8
9
|
* @property {string} name - The name of the component.
|
|
10
|
+
* @property {string} nameToSubmit - The name of the field when submit values (optional).
|
|
9
11
|
* @property {TEvent<TValidationMethods>} [validations] - The validation methods for the component.
|
|
10
12
|
* @property {TVisibility[]} [visibilityConditions] - The visibility conditions for the component.
|
|
11
13
|
* @property {TResetValueMethods[]} [resetValues] - The reset value methods for the component.
|
|
@@ -21,6 +23,7 @@ import { TApiEvent, TErrorMessages, TEvent, TFormatters, TMasks, TProps, TResetV
|
|
|
21
23
|
* component: 'input',
|
|
22
24
|
* props: { type: 'text', placeholder: 'Enter your name' },
|
|
23
25
|
* name: 'name',
|
|
26
|
+
* nameToSubmit: 'applicant.firstName',
|
|
24
27
|
* validations: { config: { required: true }, events: [{ eventName: 'ON_FIELD_BLUR' }] },
|
|
25
28
|
* visibilityConditions: [{ conditions: { field: 'age', value: 18 } }],
|
|
26
29
|
* resetValues: [{ field: 'age', resetTo: '' }],
|
|
@@ -36,6 +39,7 @@ interface IComponentSchema {
|
|
|
36
39
|
component: string;
|
|
37
40
|
props?: TProps;
|
|
38
41
|
name: string;
|
|
42
|
+
nameToSubmit?: string;
|
|
39
43
|
validations?: TEvent<TValidationMethods>;
|
|
40
44
|
api?: TApiEvent;
|
|
41
45
|
visibilityConditions?: TVisibility[];
|
|
@@ -45,6 +49,11 @@ interface IComponentSchema {
|
|
|
45
49
|
masks?: TMasks;
|
|
46
50
|
children?: IComponentSchema[];
|
|
47
51
|
}
|
|
52
|
+
interface IComponentSchemaAsFormField<T> extends IComponentSchema {
|
|
53
|
+
mapper?: TMapper<T>;
|
|
54
|
+
order?: number;
|
|
55
|
+
children?: IComponentSchemaAsFormField<T>[];
|
|
56
|
+
}
|
|
48
57
|
/**
|
|
49
58
|
* @interface IFormSchema
|
|
50
59
|
* Represents the schema for a form.
|
|
@@ -75,8 +84,9 @@ interface IFormSchema {
|
|
|
75
84
|
index: string;
|
|
76
85
|
action?: string;
|
|
77
86
|
method?: string;
|
|
87
|
+
config?: TSchemaFormConfig;
|
|
78
88
|
initialValues?: Record<string, unknown>;
|
|
79
89
|
iVars?: Record<string, unknown>;
|
|
80
90
|
components?: IComponentSchema[];
|
|
81
91
|
}
|
|
82
|
-
export { IFormSchema, IComponentSchema };
|
|
92
|
+
export { IFormSchema, IComponentSchema, IComponentSchemaAsFormField };
|
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
import { TApiResponse } from '../types/schema';
|
|
2
1
|
/**
|
|
3
2
|
* @interface IState
|
|
4
3
|
* Represents the state of a form component.
|
|
5
4
|
*
|
|
6
5
|
* @property {string[]} errors - The list of error messages.
|
|
7
6
|
* @property {boolean} visibility - The visibility state of the component.
|
|
8
|
-
* @property {TApiResponse} apiResponse - The API response data.
|
|
9
7
|
* @property {Record<string, unknown>} props - The properties of the component.
|
|
10
8
|
*
|
|
11
9
|
* @example
|
|
12
10
|
* ```typescript
|
|
13
11
|
* const state: IState = {
|
|
14
|
-
* errors: ['This field is required.'],
|
|
15
12
|
* visibility: true,
|
|
16
|
-
* apiResponse: { default: { response: null } },
|
|
17
13
|
* props: { type: 'text', value: 'John' }
|
|
18
14
|
* };
|
|
19
15
|
* ```
|
|
20
16
|
*/
|
|
21
17
|
interface IState {
|
|
22
|
-
errors: string[];
|
|
23
18
|
visibility: boolean;
|
|
24
|
-
apiResponse: TApiResponse;
|
|
25
19
|
props: Record<string, unknown>;
|
|
20
|
+
errors: Record<string, unknown>;
|
|
26
21
|
}
|
|
27
22
|
export { IState };
|
package/src/managers/field.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { Observable, Subject, Subscription } from 'rxjs';
|
|
2
|
-
import { TApiConfig, TApiEvent, TApiResponse, TErrorMessages, TEvent, TFormatters, TMasks, TResetValueMethods, TValidationMethods, TVisibility } from '../types/schema';
|
|
3
|
-
import { IComponentSchema } from '../interfaces/schema';
|
|
2
|
+
import { TApiConfig, TApiEvent, TApiResponse, TErrorMessages, TEvent, TFormatters, TMasks, TResetValueMethods, TSchemaFormConfig, TValidationMethods, TVisibility } from '../types/schema';
|
|
3
|
+
import { IComponentSchema, IComponentSchemaAsFormField } from '../interfaces/schema';
|
|
4
4
|
import { IState } from '../interfaces/state';
|
|
5
|
-
import { TEvents, TMutationEvents, TValueChangeEvent } from '../types/event';
|
|
5
|
+
import { TEvents, TFieldEvent, TMutationEvents, TValueChangeEvent } from '../types/event';
|
|
6
6
|
import { TMapper } from '../types/mapper';
|
|
7
7
|
/**
|
|
8
8
|
* Represents a form field with observables for managing form state, validations, and API requests.
|
|
9
9
|
*/
|
|
10
10
|
declare class FormField {
|
|
11
11
|
name: string;
|
|
12
|
+
nameToSubmit?: string;
|
|
12
13
|
component: string;
|
|
13
14
|
path?: string;
|
|
14
|
-
children
|
|
15
|
+
children?: string[];
|
|
16
|
+
originalSchema: IComponentSchemaAsFormField<unknown>;
|
|
15
17
|
validations?: TEvent<TValidationMethods>;
|
|
16
18
|
visibilityConditions?: TVisibility[];
|
|
17
19
|
resetValues?: TResetValueMethods[];
|
|
@@ -20,26 +22,25 @@ declare class FormField {
|
|
|
20
22
|
formatters?: TFormatters;
|
|
21
23
|
masks?: TMasks;
|
|
22
24
|
valuePropName?: string;
|
|
23
|
-
errorMessagePropName?: string;
|
|
24
25
|
initialValue?: unknown;
|
|
26
|
+
config: Required<TSchemaFormConfig>;
|
|
25
27
|
mapper: TMapper<unknown>;
|
|
28
|
+
errorsString: string;
|
|
29
|
+
errorsList: string[];
|
|
26
30
|
private _props;
|
|
27
31
|
private _value;
|
|
28
32
|
private _stateValue;
|
|
29
33
|
private _metadata;
|
|
30
34
|
private _visibility;
|
|
31
35
|
private _errors;
|
|
32
|
-
private _errorsString;
|
|
33
36
|
private _api;
|
|
34
37
|
private _valid;
|
|
35
38
|
propsSubject$: Subject<Record<string, unknown>>;
|
|
36
|
-
errorSubject$: Subject<string
|
|
37
|
-
valueSubject$: Subject<unknown
|
|
39
|
+
errorSubject$: Subject<Record<string, unknown>>;
|
|
40
|
+
valueSubject$: Subject<Record<string, unknown>>;
|
|
38
41
|
visibilitySubject$: Subject<boolean>;
|
|
39
42
|
apiSubject$: Subject<TApiResponse>;
|
|
40
|
-
|
|
41
|
-
key: string;
|
|
42
|
-
}>;
|
|
43
|
+
fieldEventSubject$: Subject<TFieldEvent>;
|
|
43
44
|
apiEventQueueSubject$: Subject<{
|
|
44
45
|
event: TEvents;
|
|
45
46
|
}>;
|
|
@@ -67,6 +68,7 @@ declare class FormField {
|
|
|
67
68
|
*
|
|
68
69
|
* @param {object} options - Configuration options for the form field.
|
|
69
70
|
* @param {IComponentSchema} options.schemaComponent - The schema definition for the form field.
|
|
71
|
+
* @param {TSchemaFormConfig} options.config - The schema default configuration for debounced actions.
|
|
70
72
|
* @param {string} [options.path] - The path within the form field (used internally during recursion).
|
|
71
73
|
* @param {string[]} options.children - An array of children fields names.
|
|
72
74
|
* @param {Function} options.validateVisibility - A function to validate the visibility of the field.
|
|
@@ -74,10 +76,11 @@ declare class FormField {
|
|
|
74
76
|
* @param {unknown} [options.initialValue] - The initial value of the form field.
|
|
75
77
|
* @param {Subject<{ key: string }>} options.templateSubject$ - A subject for template updates.
|
|
76
78
|
*/
|
|
77
|
-
constructor({ schemaComponent, path, children, validateVisibility, resetValue, initialValue, templateSubject$,
|
|
79
|
+
constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, initialValue, templateSubject$, fieldEventSubject$, dataSubject$, mapper, }: {
|
|
78
80
|
schemaComponent: IComponentSchema;
|
|
81
|
+
config?: TSchemaFormConfig;
|
|
79
82
|
path?: string;
|
|
80
|
-
children
|
|
83
|
+
children?: string[];
|
|
81
84
|
validateVisibility: (payload: {
|
|
82
85
|
event: TEvents;
|
|
83
86
|
key: string;
|
|
@@ -91,9 +94,7 @@ declare class FormField {
|
|
|
91
94
|
key: string;
|
|
92
95
|
event: TMutationEvents;
|
|
93
96
|
}>;
|
|
94
|
-
|
|
95
|
-
key: string;
|
|
96
|
-
}>;
|
|
97
|
+
fieldEventSubject$: Subject<TFieldEvent>;
|
|
97
98
|
dataSubject$: Subject<{
|
|
98
99
|
key: string;
|
|
99
100
|
event: TEvents;
|
|
@@ -104,21 +105,6 @@ declare class FormField {
|
|
|
104
105
|
* method to initialize all recycled Subjects and initialize Observers on field instance creation or rerender
|
|
105
106
|
*/
|
|
106
107
|
initializeObservers(): void;
|
|
107
|
-
/**
|
|
108
|
-
* Observable function to emit api events debounced and distinct for each event type,
|
|
109
|
-
* avoiding previous events being cancelled by new events if they occur inside the debounce time interval
|
|
110
|
-
*
|
|
111
|
-
* @param {(event: { event: TEvents }) => TEvents} keyExtractor function that will pass the event key to the groupBy operator
|
|
112
|
-
* @param {number} debounceTimeMs time to wait for each individual event emmited
|
|
113
|
-
* @returns
|
|
114
|
-
*/
|
|
115
|
-
debounceDistinct(keyExtractor: (event: {
|
|
116
|
-
event: TEvents;
|
|
117
|
-
}) => TEvents, debounceTimeMs: number): (source$: Observable<{
|
|
118
|
-
event: TEvents;
|
|
119
|
-
}>) => Observable<{
|
|
120
|
-
event: TEvents;
|
|
121
|
-
}>;
|
|
122
108
|
/**
|
|
123
109
|
* Retrieves the properties associated with the form field.
|
|
124
110
|
*
|
|
@@ -134,16 +120,10 @@ declare class FormField {
|
|
|
134
120
|
/**
|
|
135
121
|
* Retrieves the current state value of the form field.
|
|
136
122
|
*
|
|
137
|
-
* @returns {unknown} - The current state value of the form field.
|
|
123
|
+
* @returns {Record<string,unknown>} - The current state value of the form field.
|
|
138
124
|
*/
|
|
139
|
-
get stateValue(): unknown
|
|
125
|
+
get stateValue(): Record<string, unknown>;
|
|
140
126
|
get metadata(): unknown;
|
|
141
|
-
/**
|
|
142
|
-
* Retrieves the concatenated string of errors associated with the form field.
|
|
143
|
-
*
|
|
144
|
-
* @returns {string} - The concatenated string of errors.
|
|
145
|
-
*/
|
|
146
|
-
get errorsString(): string;
|
|
147
127
|
/**
|
|
148
128
|
* Retrieves the current value of the form field.
|
|
149
129
|
*
|
|
@@ -202,15 +182,12 @@ declare class FormField {
|
|
|
202
182
|
* Mounts the form field by initializing necessary subjects and combining their streams.
|
|
203
183
|
*
|
|
204
184
|
* @param {object} mountOpts - Adapter mount options.
|
|
205
|
-
* @param {string} prop.valuePropName - Adapter value property name.
|
|
206
|
-
* @param {(event: unknown) => unknown} prop.valueChangeEvent - Adapter change event handler function
|
|
207
185
|
* @param {(value: unknown) => unknown} prop.valueSubscription - Adapter value change function
|
|
208
186
|
* @param {(payload: Partial<IState>) => unknown} prop.propsSubscription - Adapter prop change function
|
|
209
|
-
* @param {string} prop.errorMessagePropName - error message property name to set errors onto component
|
|
210
187
|
* @returns {void}
|
|
211
188
|
*/
|
|
212
189
|
mountField({ valueSubscription, propsSubscription, }: {
|
|
213
|
-
valueSubscription: (value: unknown) => void;
|
|
190
|
+
valueSubscription: (value: Record<string, unknown>) => void;
|
|
214
191
|
propsSubscription: (payload: Partial<IState>) => void;
|
|
215
192
|
}): void;
|
|
216
193
|
/**
|
|
@@ -221,10 +198,7 @@ declare class FormField {
|
|
|
221
198
|
* @returns {void}
|
|
222
199
|
*/
|
|
223
200
|
emitValue(prop: {
|
|
224
|
-
value: unknown
|
|
225
|
-
_value: unknown;
|
|
226
|
-
_stateValue: unknown;
|
|
227
|
-
};
|
|
201
|
+
value: unknown;
|
|
228
202
|
event: TEvents;
|
|
229
203
|
}): void;
|
|
230
204
|
/**
|
|
@@ -245,6 +219,10 @@ declare class FormField {
|
|
|
245
219
|
setFieldValidity({ event }: {
|
|
246
220
|
event: TEvents;
|
|
247
221
|
}): void;
|
|
222
|
+
/**
|
|
223
|
+
* WIP expensive function to get updated field validity on each event
|
|
224
|
+
*/
|
|
225
|
+
updateValidityFlag(): void;
|
|
248
226
|
/**
|
|
249
227
|
* Formats the field value using the specified formatters, if available.
|
|
250
228
|
*
|
package/src/managers/form.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { IFormField } from './field';
|
|
2
2
|
import { Subject, Subscription } from 'rxjs';
|
|
3
|
-
import { IComponentSchema, IFormSchema } from '../interfaces/schema';
|
|
3
|
+
import { IComponentSchema, IComponentSchemaAsFormField, IFormSchema } from '../interfaces/schema';
|
|
4
|
+
import { TSchemaFormConfig } from '../types/schema';
|
|
4
5
|
import { TSubscribedTemplates } from '../types/template';
|
|
5
|
-
import { TEvents, TMutationEvents } from '../types/event';
|
|
6
|
+
import { TEvents, TFieldEvent, TMutationEvents } from '../types/event';
|
|
6
7
|
import { TFormEntry, TFormValues } from '../types/form';
|
|
7
8
|
import { TMapper } from '../types/mapper';
|
|
8
9
|
/**
|
|
@@ -17,10 +18,8 @@ declare class FormCore {
|
|
|
17
18
|
key: string;
|
|
18
19
|
event: TMutationEvents;
|
|
19
20
|
}>;
|
|
20
|
-
submitSubject$: Subject<TFormValues
|
|
21
|
-
|
|
22
|
-
key: string;
|
|
23
|
-
}>;
|
|
21
|
+
submitSubject$: Subject<TFormValues<Record<string, unknown>>>;
|
|
22
|
+
fieldEventSubject$: Subject<TFieldEvent>;
|
|
24
23
|
dataSubject$: Subject<{
|
|
25
24
|
key: string;
|
|
26
25
|
event: TEvents;
|
|
@@ -29,8 +28,9 @@ declare class FormCore {
|
|
|
29
28
|
subscribedTemplates: TSubscribedTemplates[];
|
|
30
29
|
action?: string;
|
|
31
30
|
method?: string;
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
config: Required<TSchemaFormConfig>;
|
|
32
|
+
mappers: Map<string, TMapper<unknown>>;
|
|
33
|
+
onSubmit?: (data: TFormValues<Record<string, unknown>>) => void;
|
|
34
34
|
/**
|
|
35
35
|
* Creates an instance of FormCore.
|
|
36
36
|
*
|
|
@@ -72,7 +72,7 @@ declare class FormCore {
|
|
|
72
72
|
*/
|
|
73
73
|
subscribeData(callback: (payload: {
|
|
74
74
|
field: string;
|
|
75
|
-
data: TFormValues
|
|
75
|
+
data: TFormValues<Record<string, unknown>>;
|
|
76
76
|
}) => void): void;
|
|
77
77
|
/**
|
|
78
78
|
* Gets the value of a property from a field.
|
|
@@ -113,7 +113,7 @@ declare class FormCore {
|
|
|
113
113
|
* @param {string} expression - The expression containing parameters.
|
|
114
114
|
* @returns {string[]} An array of extracted parameters.
|
|
115
115
|
*/
|
|
116
|
-
extractParams(expression: string):
|
|
116
|
+
extractParams(expression: string): unknown[];
|
|
117
117
|
/**
|
|
118
118
|
* Replaces expressions marked by ${...} in the expression string with the provided values.
|
|
119
119
|
*
|
|
@@ -121,7 +121,7 @@ declare class FormCore {
|
|
|
121
121
|
* @param {string[]} values - The values to be inserted into the marked expressions.
|
|
122
122
|
* @returns {string} The expression string with the replacements made.
|
|
123
123
|
*/
|
|
124
|
-
replaceExpression(expression: string, values:
|
|
124
|
+
replaceExpression(expression: string, values: unknown[]): string;
|
|
125
125
|
/**
|
|
126
126
|
* Checks if an expression string contains string concatenation within a marked expression.
|
|
127
127
|
*
|
|
@@ -140,15 +140,6 @@ declare class FormCore {
|
|
|
140
140
|
key: string;
|
|
141
141
|
event: TMutationEvents;
|
|
142
142
|
}): void;
|
|
143
|
-
/**
|
|
144
|
-
* Refreshes api observed fields.
|
|
145
|
-
*
|
|
146
|
-
* @param {object} options - Options for refreshing api.
|
|
147
|
-
* @param {string} options.key - The key of the field triggering the update.
|
|
148
|
-
*/
|
|
149
|
-
refreshApi({ key }: {
|
|
150
|
-
key: string;
|
|
151
|
-
}): string;
|
|
152
143
|
/**
|
|
153
144
|
* Validates and collects the names of form fields in the provided schema structure.
|
|
154
145
|
*
|
|
@@ -181,19 +172,31 @@ declare class FormCore {
|
|
|
181
172
|
event: TEvents;
|
|
182
173
|
key: string;
|
|
183
174
|
}): void;
|
|
175
|
+
/**
|
|
176
|
+
* Adds a field onto the form instance regardless there is a schema or not
|
|
177
|
+
*
|
|
178
|
+
* @param fieldSchema
|
|
179
|
+
*/
|
|
180
|
+
addField({ fieldSchema, mapperElement, }: {
|
|
181
|
+
fieldSchema: IComponentSchema;
|
|
182
|
+
mapperElement?: TMapper<unknown>;
|
|
183
|
+
}): void;
|
|
184
|
+
removeField({ key }: {
|
|
185
|
+
key: string;
|
|
186
|
+
}): void;
|
|
184
187
|
/**
|
|
185
188
|
* Serializes the schema structure to create form fields.
|
|
186
189
|
*
|
|
187
190
|
* @param {IComponentSchema[]} [struct] - The schema structure to serialize.
|
|
188
191
|
* @param {string} [path] - The path of the parent component.
|
|
189
192
|
*/
|
|
190
|
-
serializeStructure(struct?:
|
|
193
|
+
serializeStructure(struct?: IComponentSchemaAsFormField<unknown>[], path?: string): void;
|
|
191
194
|
/**
|
|
192
195
|
* Refreshes form fields based on changes in the schema structure.
|
|
193
196
|
*
|
|
194
197
|
* @param {IComponentSchema[]} struct - The updated schema structure.
|
|
195
198
|
*/
|
|
196
|
-
refreshFields(struct:
|
|
199
|
+
refreshFields(struct: IComponentSchemaAsFormField<unknown>[]): void;
|
|
197
200
|
/**
|
|
198
201
|
* Gets a form field by its key.
|
|
199
202
|
*
|
|
@@ -213,7 +216,10 @@ declare class FormCore {
|
|
|
213
216
|
*
|
|
214
217
|
* @returns {TFormValues} The current form values.
|
|
215
218
|
*/
|
|
216
|
-
getFormValues(): TFormValues
|
|
219
|
+
getFormValues(): TFormValues<Record<string, unknown>>;
|
|
220
|
+
subscribeFieldEvent({ callback, }: {
|
|
221
|
+
callback: (payload: TFieldEvent) => void;
|
|
222
|
+
}): Subscription;
|
|
217
223
|
/**
|
|
218
224
|
* Submits the form by triggering form field events and invoking the onSubmit callback.
|
|
219
225
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TFormValues } from '../types/form';
|
|
2
|
+
import { TMapper } from '../types/mapper';
|
|
2
3
|
import { TFormCore } from './form';
|
|
3
4
|
/**
|
|
4
5
|
* Represents a group that manages multiple forms.
|
|
@@ -9,6 +10,16 @@ declare class FormGroup {
|
|
|
9
10
|
* Creates an instance of FormGroup.
|
|
10
11
|
*/
|
|
11
12
|
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Creates an empty form with given index
|
|
15
|
+
*
|
|
16
|
+
* @param {string} options.index
|
|
17
|
+
* @param {TMapper<unknown>} options.mappers
|
|
18
|
+
*/
|
|
19
|
+
createFormWithIndex({ index, mappers, }: {
|
|
20
|
+
index: string;
|
|
21
|
+
mappers?: TMapper<unknown>[];
|
|
22
|
+
}): void;
|
|
12
23
|
/**
|
|
13
24
|
* Adds a form instance to the form group.
|
|
14
25
|
*
|
|
@@ -29,7 +40,7 @@ declare class FormGroup {
|
|
|
29
40
|
*/
|
|
30
41
|
getForm({ key }: {
|
|
31
42
|
key: string;
|
|
32
|
-
}):
|
|
43
|
+
}): TFormCore | undefined;
|
|
33
44
|
/**
|
|
34
45
|
* Removes a form instance from the form group.
|
|
35
46
|
*
|
|
@@ -39,6 +50,16 @@ declare class FormGroup {
|
|
|
39
50
|
removeForm({ key }: {
|
|
40
51
|
key: string;
|
|
41
52
|
}): void;
|
|
53
|
+
/**
|
|
54
|
+
* removes a field given a form and field index
|
|
55
|
+
*
|
|
56
|
+
* @param {string} options.formIndex
|
|
57
|
+
* @param {string} options.fieldIndex
|
|
58
|
+
*/
|
|
59
|
+
removeField({ formIndex, fieldIndex, }: {
|
|
60
|
+
formIndex: string;
|
|
61
|
+
fieldIndex: string;
|
|
62
|
+
}): void;
|
|
42
63
|
/**
|
|
43
64
|
* Checks if the specified key already exists in the form group.
|
|
44
65
|
*
|
|
@@ -58,7 +79,7 @@ declare class FormGroup {
|
|
|
58
79
|
* @param {string[]} indexes form indexes to be submitted
|
|
59
80
|
* @returns
|
|
60
81
|
*/
|
|
61
|
-
submitMultipleFormsByIndex(indexes: string[]): TFormValues
|
|
82
|
+
submitMultipleFormsByIndex<T>(indexes: string[]): TFormValues<T>;
|
|
62
83
|
}
|
|
63
84
|
type TFormGroup = FormGroup;
|
|
64
85
|
export { TFormGroup, FormGroup };
|
package/src/types/event.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IFormField } from '../managers';
|
|
1
2
|
/**
|
|
2
3
|
* @type TEvents
|
|
3
4
|
* Represents the different types of events that can occur on form fields.
|
|
@@ -40,4 +41,9 @@ declare enum TMutationEnum {
|
|
|
40
41
|
type TValueChangeEvent = (value: unknown, opts?: {
|
|
41
42
|
props: Record<string, unknown>;
|
|
42
43
|
}) => void;
|
|
43
|
-
|
|
44
|
+
type TFieldEvent = {
|
|
45
|
+
event: TEvents;
|
|
46
|
+
fieldName: string;
|
|
47
|
+
fieldInstance?: IFormField;
|
|
48
|
+
};
|
|
49
|
+
export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent };
|
package/src/types/form.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IFormSchema } from '../interfaces/schema';
|
|
2
2
|
import { TMapper } from './mapper';
|
|
3
3
|
/**
|
|
4
|
-
* @type TFormValues
|
|
5
|
-
* Represents the values and state of a form.
|
|
4
|
+
* @type TFormValues<T>
|
|
5
|
+
* Represents the values and state of a form. It has a generic type that allows the importer to determine which type values key will return.
|
|
6
6
|
*
|
|
7
|
-
* @property {
|
|
7
|
+
* @property {Generic Type} values - The current values of the form fields.
|
|
8
8
|
* @property {string[]} erroredFields - A list of field names that have errors.
|
|
9
9
|
* @property {boolean} isValid - Indicates whether the form is valid.
|
|
10
10
|
*
|
|
@@ -17,8 +17,8 @@ import { TMapper } from './mapper';
|
|
|
17
17
|
* };
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
type TFormValues = {
|
|
21
|
-
values:
|
|
20
|
+
type TFormValues<T> = {
|
|
21
|
+
values: T;
|
|
22
22
|
erroredFields: string[];
|
|
23
23
|
isValid: boolean;
|
|
24
24
|
};
|
|
@@ -41,11 +41,11 @@ type TFormValues = {
|
|
|
41
41
|
*/
|
|
42
42
|
type TFormEntry = Omit<IFormSchema, 'components'> & {
|
|
43
43
|
schema?: IFormSchema;
|
|
44
|
-
onSubmit?: (data: TFormValues) => void;
|
|
45
|
-
onData?: (payload: {
|
|
44
|
+
onSubmit?: <T>(data: TFormValues<T>) => void;
|
|
45
|
+
onData?: <T>(payload: {
|
|
46
46
|
field: string;
|
|
47
|
-
data: TFormValues
|
|
47
|
+
data: TFormValues<T>;
|
|
48
48
|
}) => void;
|
|
49
|
-
mappers
|
|
49
|
+
mappers?: TMapper<unknown>[];
|
|
50
50
|
};
|
|
51
51
|
export { TFormValues, TFormEntry };
|
package/src/types/schema.d.ts
CHANGED
|
@@ -700,10 +700,11 @@ type TResetValues = Partial<Record<TEvents, TResetValueMethods[]>>;
|
|
|
700
700
|
* const errorMessages: TErrorMessages = {
|
|
701
701
|
* required: 'This field is required.',
|
|
702
702
|
* max: 'The value cannot exceed the maximum limit.'
|
|
703
|
+
* default: 'Default error message'
|
|
703
704
|
* };
|
|
704
705
|
* ```
|
|
705
706
|
*/
|
|
706
|
-
type TErrorMessages = Partial<Record<keyof TValidationMethods, string>>;
|
|
707
|
+
type TErrorMessages = Partial<Record<keyof TValidationMethods & 'default', string>>;
|
|
707
708
|
/**
|
|
708
709
|
* Represents an event configuration with a specific type.
|
|
709
710
|
*
|
|
@@ -739,4 +740,14 @@ type TApiResponse = {
|
|
|
739
740
|
response: unknown;
|
|
740
741
|
}>;
|
|
741
742
|
};
|
|
742
|
-
|
|
743
|
+
/**
|
|
744
|
+
* Represents the schema config structure
|
|
745
|
+
*
|
|
746
|
+
* @property {number} defaultAPIdebounceTimeMS - default API debounce time between request events.
|
|
747
|
+
* @property {number} [defaultStateRefreshTimeMS] - default state refresh between events side effects.
|
|
748
|
+
*/
|
|
749
|
+
type TSchemaFormConfig = {
|
|
750
|
+
defaultAPIdebounceTimeMS?: number;
|
|
751
|
+
defaultStateRefreshTimeMS?: number;
|
|
752
|
+
};
|
|
753
|
+
export { TApiConfig, TErrorMessages, TResetValues, TVisibilityConditions, TValidations, TMasks, TProps, TResetValueMethods, TFormatters, TValidationMethods, TEvent, TVisibility, TApiEvent, TApiResponse, TSchemaFormConfig, TLengthValidation, TCreditCardMatch, TDocumentValidation, TCallbackValidation, TBetweenValidation, TMaskGeneric, TSplitterFormatterValue, TCurrencyMask, TDateOperatorsValidation, TConditionsValidationSet, TConditionsValidation, TMultipleValidation, TAvailableValidations, TDateValidation, TBetweenDatesValidation, TDateFormatsValidation, TDateInterval, };
|