@bolttech/form-engine-core 1.0.0-beta.2 → 1.0.0-beta.20
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 +436 -240
- package/package.json +1 -1
- package/src/constants/constants.d.ts +1 -1
- package/src/interfaces/schema.d.ts +1 -0
- package/src/managers/field.d.ts +47 -12
- package/src/managers/form.d.ts +61 -14
- package/src/managers/formGroup.d.ts +8 -4
- package/src/types/event.d.ts +28 -4
- package/src/types/form.d.ts +9 -0
- package/src/types/schema.d.ts +5 -1
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ declare const TEMPLATE_REGEX_STRING_CONCATENATION_DETECTOR: RegExp;
|
|
|
4
4
|
declare const TEMPLATE_REGEX_DELIMITATOR: RegExp;
|
|
5
5
|
declare const TEMPLATE_REGEX_OPERATOR_SPLITTER: RegExp;
|
|
6
6
|
declare const TEMPLATE_REGEX_OPERATOR_MATCHER: RegExp;
|
|
7
|
-
declare const TEMPLATE_AVALIABLE_SCOPES: readonly ["fields", "iVars"];
|
|
7
|
+
declare const TEMPLATE_AVALIABLE_SCOPES: readonly ["fields", "iVars", "form"];
|
|
8
8
|
declare const ALLOWED_RESET_PROPS_MUTATIONS: ("api" | "apiSchema" | "props" | "validations" | "visibilityConditions" | "resetValues")[];
|
|
9
9
|
declare const DEFAULT_LOG_VERBOSE = false;
|
|
10
10
|
export { DEFAULT_API_DEBOUNCE_TIME, DEFAULT_STATE_REFRESH_TIME, DEFAULT_LOG_VERBOSE, TEMPLATE_REGEX_STRING_CONCATENATION_DETECTOR, TEMPLATE_REGEX_DELIMITATOR, TEMPLATE_REGEX_OPERATOR_SPLITTER, TEMPLATE_REGEX_OPERATOR_MATCHER, TEMPLATE_AVALIABLE_SCOPES, ALLOWED_RESET_PROPS_MUTATIONS, };
|
package/src/managers/field.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Subject, Subscription } from 'rxjs';
|
|
2
2
|
import { TApiConfig, TApiEvent, TApiResponse, TErrorMessages, TFormatters, TMasks, TResetPathMethods, TResetValueMethods, TSchemaFormConfig, TValidations, TVisibility } from '../types/schema';
|
|
3
3
|
import { IComponentSchema, IComponentSchemaAsFormField } from '../interfaces/schema';
|
|
4
4
|
import { IState } from '../interfaces/state';
|
|
5
|
-
import { TEvents, TFieldEvent,
|
|
5
|
+
import { TEvents, TFieldEvent, TFieldValidationPayload, TFormDataPayload, TValueChangeEvent } from '../types/event';
|
|
6
6
|
import { TMapper } from '../types/mapper';
|
|
7
7
|
import { SafeSubject } from '../helpers/SafeSubject';
|
|
8
8
|
import { TTemplateEvent } from '../types/template';
|
|
@@ -11,6 +11,7 @@ import { TFormValues } from '../types/form';
|
|
|
11
11
|
* Represents a form field with observables for managing form state, validations, and API requests.
|
|
12
12
|
*/
|
|
13
13
|
declare class FormField {
|
|
14
|
+
formIndex: string;
|
|
14
15
|
name: string;
|
|
15
16
|
nameToSubmit?: string;
|
|
16
17
|
component: string;
|
|
@@ -21,7 +22,6 @@ declare class FormField {
|
|
|
21
22
|
visibilityConditions?: TVisibility[];
|
|
22
23
|
resetValues?: TResetValueMethods[];
|
|
23
24
|
resetPropertyValues?: TResetPathMethods[];
|
|
24
|
-
errorMessages?: TErrorMessages;
|
|
25
25
|
apiSchema?: TApiEvent;
|
|
26
26
|
formatters?: TFormatters;
|
|
27
27
|
masks?: TMasks;
|
|
@@ -44,19 +44,18 @@ declare class FormField {
|
|
|
44
44
|
valueSubject$: SafeSubject<Record<string, unknown>>;
|
|
45
45
|
valueSubscription$: Subscription;
|
|
46
46
|
visibilitySubject$: SafeSubject<boolean>;
|
|
47
|
-
apiSubject$: SafeSubject<TApiResponse>;
|
|
48
47
|
fieldEventSubject$: Subject<TFieldEvent>;
|
|
49
48
|
apiEventQueueSubject$: SafeSubject<{
|
|
50
49
|
event: TEvents;
|
|
51
50
|
}>;
|
|
52
|
-
fieldState$: Observable<IState>;
|
|
53
51
|
fieldStateSubscription$: Subscription;
|
|
54
52
|
templateSubject$: Subject<TTemplateEvent>;
|
|
55
|
-
dataSubject$: Subject<
|
|
53
|
+
dataSubject$: Subject<TFormDataPayload>;
|
|
54
|
+
fieldValidNotification$: Subject<TFieldValidationPayload>;
|
|
55
|
+
mountSubject$: Subject<{
|
|
56
56
|
key: string;
|
|
57
|
-
|
|
57
|
+
status: boolean;
|
|
58
58
|
}>;
|
|
59
|
-
formValidNotification$: Subject<Pick<TFormValidationPayload, 'fieldTrigger'>>;
|
|
60
59
|
validateVisibility: (payload: {
|
|
61
60
|
event: TEvents;
|
|
62
61
|
key: string;
|
|
@@ -90,7 +89,8 @@ declare class FormField {
|
|
|
90
89
|
* @param {TMapper<unknown>} options.mapper, - component generic mapper containing render parameters for adapters
|
|
91
90
|
* @param {() => TFormValues<unknown>} options.getFormValues, - form instance function that builds onData parameter payload from fields
|
|
92
91
|
*/
|
|
93
|
-
constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, resetProperty, templateSubject$, fieldEventSubject$, dataSubject$,
|
|
92
|
+
constructor({ formIndex, schemaComponent, config, path, children, validateVisibility, resetValue, resetProperty, templateSubject$, fieldEventSubject$, dataSubject$, fieldValidNotification$, mountSubject$, mapper, getFormValues, submitEvent, visibility, }: {
|
|
93
|
+
formIndex: string;
|
|
94
94
|
schemaComponent: IComponentSchema;
|
|
95
95
|
config?: TSchemaFormConfig;
|
|
96
96
|
path?: string;
|
|
@@ -110,16 +110,20 @@ declare class FormField {
|
|
|
110
110
|
submitEvent: () => void;
|
|
111
111
|
templateSubject$: Subject<TTemplateEvent>;
|
|
112
112
|
fieldEventSubject$: Subject<TFieldEvent>;
|
|
113
|
-
dataSubject$: Subject<
|
|
113
|
+
dataSubject$: Subject<TFormDataPayload>;
|
|
114
|
+
fieldValidNotification$: Subject<TFieldValidationPayload>;
|
|
115
|
+
mountSubject$: Subject<{
|
|
114
116
|
key: string;
|
|
115
|
-
|
|
117
|
+
status: boolean;
|
|
116
118
|
}>;
|
|
117
|
-
formValidNotification$: Subject<Pick<TFormValidationPayload, 'fieldTrigger'>>;
|
|
118
119
|
mapper: TMapper<unknown>;
|
|
119
120
|
getFormValues: () => TFormValues<unknown>;
|
|
121
|
+
visibility?: boolean;
|
|
120
122
|
});
|
|
121
123
|
/**
|
|
122
124
|
* method to initialize all recycled Subjects and initialize Observers on field instance creation or rerender
|
|
125
|
+
* due to some visibility conditions unmounts the field from the adapter if they are children of it and avoid
|
|
126
|
+
* emissions to unsubscribed fields
|
|
123
127
|
*/
|
|
124
128
|
initializeObservers(): void;
|
|
125
129
|
/**
|
|
@@ -134,6 +138,13 @@ declare class FormField {
|
|
|
134
138
|
* @param {Record<string, unknown>} props - The new properties to be set.
|
|
135
139
|
*/
|
|
136
140
|
set props(props: Record<string, unknown>);
|
|
141
|
+
/**
|
|
142
|
+
* Static function to remove templates form the component props that will be shown when
|
|
143
|
+
* the field mounts and the template routine executes, to be used on the adapter
|
|
144
|
+
*
|
|
145
|
+
* @param {unknown} props - the properties from the adapter components.
|
|
146
|
+
*/
|
|
147
|
+
static filterProps(props: unknown): unknown;
|
|
137
148
|
/**
|
|
138
149
|
* Retrieves the current state value of the form field.
|
|
139
150
|
*
|
|
@@ -175,6 +186,14 @@ declare class FormField {
|
|
|
175
186
|
* @returns {boolean} - The validity status of the form field.
|
|
176
187
|
*/
|
|
177
188
|
get valid(): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* triggers field valid notification to handle the form instance valid notification
|
|
191
|
+
*
|
|
192
|
+
* Note: since form unmount can occur before field unmount, this subject might already be closed by form instance
|
|
193
|
+
* quick workaround is to check if the subject is already closed before emitting
|
|
194
|
+
* if form instance onValid or template form.valid doesn't work properly, might be due to this workaround
|
|
195
|
+
*/
|
|
196
|
+
triggerFieldValidNotification(): void;
|
|
178
197
|
/**
|
|
179
198
|
* Retrieves the error messages associated with the form field.
|
|
180
199
|
*
|
|
@@ -199,6 +218,22 @@ declare class FormField {
|
|
|
199
218
|
* @param {TApiResponse} response - The new API response data to be set.
|
|
200
219
|
*/
|
|
201
220
|
set api(response: TApiResponse);
|
|
221
|
+
/**
|
|
222
|
+
* notifies templates and event binded field configurations that a request starts it's processing
|
|
223
|
+
*/
|
|
224
|
+
notifyApiRequest(): void;
|
|
225
|
+
/** Retrieves the mounted status of the field.
|
|
226
|
+
*
|
|
227
|
+
* @returns {boolean} - the mounted status of the field.
|
|
228
|
+
*/
|
|
229
|
+
get mounted(): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* sets the mountedStatus and notifies the form that the field was mounted on the adapter
|
|
232
|
+
* and it's ready to be handled by the form instance
|
|
233
|
+
*
|
|
234
|
+
* @param {boolean} mountedStatus - the mounted status to be set from the mountField function.
|
|
235
|
+
*/
|
|
236
|
+
set mounted(mountedStatus: boolean);
|
|
202
237
|
/**
|
|
203
238
|
* Mounts the form field by initializing necessary subjects and combining their streams.
|
|
204
239
|
*
|
package/src/managers/form.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Subject, Subscription } from 'rxjs';
|
|
|
3
3
|
import { IComponentSchema, IComponentSchemaAsFormField, IFormSchema } from '../interfaces/schema';
|
|
4
4
|
import { TSchemaFormConfig } from '../types/schema';
|
|
5
5
|
import { TSubscribedTemplates, TTemplateEvent } from '../types/template';
|
|
6
|
-
import { TEvents, TFieldEvent, TFormValidationPayload, TMutationEvents } from '../types/event';
|
|
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
9
|
import { TEMPLATE_AVALIABLE_SCOPES } from '../constants/constants';
|
|
@@ -11,19 +11,21 @@ import { TEMPLATE_AVALIABLE_SCOPES } from '../constants/constants';
|
|
|
11
11
|
* Represents the core logic for managing a form, including field management, validation, and submission.
|
|
12
12
|
*/
|
|
13
13
|
declare class FormCore {
|
|
14
|
+
index: string;
|
|
14
15
|
schema?: IFormSchema;
|
|
15
16
|
fields: Map<string, IFormField>;
|
|
16
17
|
private _iVars;
|
|
17
18
|
templateSubject$: Subject<TTemplateEvent>;
|
|
18
19
|
templateSubscription$: Subscription;
|
|
19
|
-
submitSubject$: Subject<
|
|
20
|
-
mountSubject$: Subject<
|
|
21
|
-
fieldEventSubject$: Subject<TFieldEvent>;
|
|
22
|
-
dataSubject$: Subject<{
|
|
20
|
+
submitSubject$: Subject<TFormSubmitPayload<unknown>>;
|
|
21
|
+
mountSubject$: Subject<{
|
|
23
22
|
key: string;
|
|
24
|
-
|
|
23
|
+
status: boolean;
|
|
25
24
|
}>;
|
|
26
|
-
|
|
25
|
+
fieldEventSubject$: Subject<TFieldEvent>;
|
|
26
|
+
dataSubject$: Subject<TFormDataPayload>;
|
|
27
|
+
formValidSubject$: Subject<TFormValidationPayload>;
|
|
28
|
+
fieldValidNotification$: Subject<TFieldValidationPayload>;
|
|
27
29
|
subscribedTemplates: TSubscribedTemplates[];
|
|
28
30
|
action?: string;
|
|
29
31
|
method?: string;
|
|
@@ -42,6 +44,7 @@ declare class FormCore {
|
|
|
42
44
|
value: unknown;
|
|
43
45
|
}>;
|
|
44
46
|
queuedInitialValues: Map<string, unknown>;
|
|
47
|
+
_valid: boolean;
|
|
45
48
|
/**
|
|
46
49
|
* Creates an instance of FormCore.
|
|
47
50
|
*
|
|
@@ -54,7 +57,28 @@ declare class FormCore {
|
|
|
54
57
|
* @param {((payload: {field: string;data: TFormValues;}) => void) | undefined} [entry.onData] - A callback function to handle data emission.
|
|
55
58
|
*/
|
|
56
59
|
constructor(entry: TFormEntry & Omit<IFormSchema, 'components'>);
|
|
57
|
-
|
|
60
|
+
/**
|
|
61
|
+
* mock function to simulate form mount onto the adapter
|
|
62
|
+
*/
|
|
63
|
+
generateFields(): void;
|
|
64
|
+
/**
|
|
65
|
+
* callback function passed to field instance to notify field adapter mount status
|
|
66
|
+
* once the field has all field instance properties set, this function will handle all
|
|
67
|
+
* field routines
|
|
68
|
+
*
|
|
69
|
+
* @param { string } entry.key field unique identifier
|
|
70
|
+
* @param { boolean } entry.status mount status notified from field
|
|
71
|
+
*/
|
|
72
|
+
mountActions({ key, status }: {
|
|
73
|
+
key: string;
|
|
74
|
+
status: boolean;
|
|
75
|
+
}): void;
|
|
76
|
+
/**
|
|
77
|
+
* initialValues setter to handle field values set externally from the adapter
|
|
78
|
+
*
|
|
79
|
+
* @param { Record<string, unknown> | undefined } payload initialValues to set onto fields
|
|
80
|
+
*/
|
|
81
|
+
set initialValues(payload: Record<string, unknown> | undefined);
|
|
58
82
|
/**
|
|
59
83
|
* Retrieves the internal variables (iVars) of the form.
|
|
60
84
|
*
|
|
@@ -68,11 +92,12 @@ declare class FormCore {
|
|
|
68
92
|
*/
|
|
69
93
|
set iVars(payload: Record<string, unknown>);
|
|
70
94
|
/**
|
|
71
|
-
*
|
|
95
|
+
* Validates all form fields and sets the form valid flag
|
|
72
96
|
*
|
|
73
|
-
* @returns {boolean} True if the form is valid; otherwise, false.
|
|
74
97
|
*/
|
|
75
|
-
|
|
98
|
+
validateForm(): boolean;
|
|
99
|
+
get valid(): boolean;
|
|
100
|
+
set valid(valid: boolean);
|
|
76
101
|
/**
|
|
77
102
|
* Subscribes to templates for dynamic updates.
|
|
78
103
|
*/
|
|
@@ -230,6 +255,11 @@ declare class FormCore {
|
|
|
230
255
|
fieldSchema: IComponentSchema;
|
|
231
256
|
mapperElement?: TMapper<unknown>;
|
|
232
257
|
}): void;
|
|
258
|
+
/**
|
|
259
|
+
* function to be called from the adapter to remove a field when a field is removed from it
|
|
260
|
+
*
|
|
261
|
+
* @param {{ key: string }} entry.key
|
|
262
|
+
*/
|
|
233
263
|
removeField({ key }: {
|
|
234
264
|
key: string;
|
|
235
265
|
}): void;
|
|
@@ -266,9 +296,21 @@ declare class FormCore {
|
|
|
266
296
|
* @returns {TFormValues} The current form values.
|
|
267
297
|
*/
|
|
268
298
|
getFormValues<T>(): TFormValues<T>;
|
|
299
|
+
/**
|
|
300
|
+
* function to be called to events sent from the adapter
|
|
301
|
+
*
|
|
302
|
+
* @param {{callback: (payload: TFieldEvent) => void}} entry.callback callback function from the adapter
|
|
303
|
+
* @returns
|
|
304
|
+
*/
|
|
269
305
|
subscribeFieldEvent({ callback, }: {
|
|
270
306
|
callback: (payload: TFieldEvent) => void;
|
|
271
307
|
}): Subscription;
|
|
308
|
+
/**
|
|
309
|
+
* to be called from the adapter when the form mounts
|
|
310
|
+
*
|
|
311
|
+
* @param {(payload: TFormValues<T>) => void} callback
|
|
312
|
+
* @returns Subscription
|
|
313
|
+
*/
|
|
272
314
|
subscribeOnMount<T>(callback: (payload: TFormValues<T>) => void): Subscription;
|
|
273
315
|
/**
|
|
274
316
|
*
|
|
@@ -278,8 +320,14 @@ declare class FormCore {
|
|
|
278
320
|
field: string;
|
|
279
321
|
data: TFormValues<T>;
|
|
280
322
|
}) => void): Subscription;
|
|
323
|
+
/**
|
|
324
|
+
* method to register a callback function to be called when the form is valid
|
|
325
|
+
*
|
|
326
|
+
* @param {(payload: TFormValues<T>) => void} callback callback function to call when the submit action occurs
|
|
327
|
+
*/
|
|
281
328
|
subscribeOnSubmit<T>(callback: (payload: TFormValues<T>) => void): Subscription;
|
|
282
329
|
/**
|
|
330
|
+
* method to check whenever the validity status of the form changes, only emits on status change
|
|
283
331
|
*
|
|
284
332
|
* @param {(payload: TFormValidationPayload) => void} callback callback function to call onValid
|
|
285
333
|
*/
|
|
@@ -287,11 +335,10 @@ declare class FormCore {
|
|
|
287
335
|
/**
|
|
288
336
|
* Submits the form by triggering form field events and invoking the onSubmit callback.
|
|
289
337
|
*/
|
|
290
|
-
|
|
338
|
+
submit<T>(): void;
|
|
291
339
|
/**
|
|
292
|
-
*
|
|
340
|
+
* recycles all the Suscriptions, to be called from the adapter when the form leaves the page
|
|
293
341
|
*/
|
|
294
|
-
submit<T>(): void;
|
|
295
342
|
destroy(): void;
|
|
296
343
|
}
|
|
297
344
|
type TFormCore = FormCore;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
2
|
+
import { TFormEntry, TFormValues } from '../types/form';
|
|
2
3
|
import { TMapper } from '../types/mapper';
|
|
3
4
|
import { TFormCore } from './form';
|
|
4
5
|
import { TSchemaFormConfig } from '../types/schema';
|
|
5
|
-
import { TFormGroupOnDataEventPayload, TFormGroupOnSubmitEventPayload, TFormGroupOnValidEventPayload } from '../types/event';
|
|
6
|
+
import { TFormDataPayload, TFormGroupOnDataEventPayload, TFormGroupOnSubmitEventPayload, TFormGroupOnValidEventPayload, TFormSubmitPayload, TFormValidationPayload } from '../types/event';
|
|
6
7
|
/**
|
|
7
8
|
* Represents a group that manages multiple forms.
|
|
8
9
|
*/
|
|
9
10
|
declare class FormGroup {
|
|
10
11
|
forms: Map<string, TFormCore>;
|
|
11
12
|
config: Required<TSchemaFormConfig>;
|
|
13
|
+
dataSubject$: Subject<TFormDataPayload>;
|
|
14
|
+
formValidSubject$: Subject<TFormValidationPayload>;
|
|
15
|
+
submitSubject$: Subject<TFormSubmitPayload<unknown>>;
|
|
12
16
|
/**
|
|
13
17
|
* Creates an instance of FormGroup.
|
|
14
18
|
*/
|
|
@@ -32,9 +36,9 @@ declare class FormGroup {
|
|
|
32
36
|
* @param {string} options.key - The key associated with the form instance.
|
|
33
37
|
* @param {TFormCore} options.formInstance - The instance of the form to add.
|
|
34
38
|
*/
|
|
35
|
-
addForm({ key,
|
|
39
|
+
addForm({ key, params }: {
|
|
36
40
|
key: string;
|
|
37
|
-
|
|
41
|
+
params: TFormEntry;
|
|
38
42
|
}): void;
|
|
39
43
|
/**
|
|
40
44
|
* Retrieves a form instance from the form group.
|
package/src/types/event.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { TFormValues } from './form';
|
|
|
9
9
|
* const event: TEvents = 'ON_FIELD_CHANGE';
|
|
10
10
|
* ```
|
|
11
11
|
*/
|
|
12
|
-
type TEvents = 'ON_FIELD_MOUNT' | 'ON_FIELD_CHANGE' | 'ON_FIELD_BLUR' | 'ON_FIELD_FOCUS' | 'ON_FIELD_CLICK' | 'ON_FIELD_KEYUP' | 'ON_FIELD_KEYDOWN' | 'ON_FIELD_CLEARED' | 'ON_FORM_SUBMIT' | 'ON_FIELD_VALIDATION' | 'ON_FORM_MOUNT' | 'ON_API_FIELD_RESPONSE';
|
|
12
|
+
type TEvents = 'ON_FIELD_MOUNT' | 'ON_FIELD_UNMOUNT' | 'ON_FIELD_CHANGE' | 'ON_FIELD_BLUR' | 'ON_FIELD_FOCUS' | 'ON_FIELD_CLICK' | 'ON_FIELD_KEYUP' | 'ON_FIELD_KEYDOWN' | 'ON_FIELD_CLEARED' | 'ON_FORM_SUBMIT' | 'ON_FIELD_VALIDATION' | 'ON_FORM_MOUNT' | 'ON_API_FIELD_REQUEST' | 'ON_API_FIELD_RESPONSE';
|
|
13
13
|
/**
|
|
14
14
|
* @type TMutationEvents
|
|
15
15
|
* Represents the different types of events that can occur internally that triggers templating.
|
|
@@ -19,7 +19,7 @@ type TEvents = 'ON_FIELD_MOUNT' | 'ON_FIELD_CHANGE' | 'ON_FIELD_BLUR' | 'ON_FIEL
|
|
|
19
19
|
* const event: TMutationEvents = 'ON_VALUE';
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
type TMutationEvents = 'ON_VALUE' | 'ON_PROPS' | 'ON_VISIBILITY' | '
|
|
22
|
+
type TMutationEvents = 'ON_VALUE' | 'ON_PROPS' | 'ON_VISIBILITY' | 'ON_API_REQUEST' | 'ON_API_RESPONSE' | 'ON_IVARS' | 'ON_FIELDS' | 'ON_RESET' | 'ON_FORM';
|
|
23
23
|
declare enum TMutationEnum {
|
|
24
24
|
ON_VALUE = "value",
|
|
25
25
|
ON_PROPS = "props",
|
|
@@ -51,14 +51,38 @@ type TFieldEvent = {
|
|
|
51
51
|
fieldName: string;
|
|
52
52
|
fieldInstance?: IFormField;
|
|
53
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* @type TFormDataPayload
|
|
56
|
+
* Event emitted to formGroup instance to capture onData form events
|
|
57
|
+
*/
|
|
58
|
+
type TFormDataPayload = {
|
|
59
|
+
formIndex: string;
|
|
60
|
+
fieldIndex: string;
|
|
61
|
+
event: TEvents;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* @type TFormSubmitPayload
|
|
65
|
+
* Event emitted to formGroup instance to capture onSubmit form events
|
|
66
|
+
*/
|
|
67
|
+
type TFormSubmitPayload<T> = {
|
|
68
|
+
formIndex: string;
|
|
69
|
+
values: TFormValues<T>;
|
|
70
|
+
};
|
|
54
71
|
/**
|
|
55
72
|
* @type TFormValidationPayload
|
|
56
73
|
* Form onValid event emmited payload on callback function parameter
|
|
57
74
|
*/
|
|
58
75
|
type TFormValidationPayload = {
|
|
59
|
-
|
|
76
|
+
formIndex: string;
|
|
60
77
|
valid: boolean;
|
|
61
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* @type TFieldValidationPayload
|
|
81
|
+
* field event emmited payload on field validation
|
|
82
|
+
*/
|
|
83
|
+
type TFieldValidationPayload = {
|
|
84
|
+
fieldTrigger: string;
|
|
85
|
+
};
|
|
62
86
|
/**
|
|
63
87
|
* @type TFormGroupOnDataEventPayload
|
|
64
88
|
* Form Group onData event emitted payload on callback function parameter
|
|
@@ -81,4 +105,4 @@ type TFormGroupOnValidEventPayload = {
|
|
|
81
105
|
* Form Group onSubmit event emitted payload on callback function parameter
|
|
82
106
|
*/
|
|
83
107
|
type TFormGroupOnSubmitEventPayload<T> = Record<string, TFormValues<T> | undefined>;
|
|
84
|
-
export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent, TFormGroupOnDataEventPayload, TFormGroupOnValidEventPayload, TFormGroupOnSubmitEventPayload, TFormValidationPayload, };
|
|
108
|
+
export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent, TFormDataPayload, TFormSubmitPayload, TFormGroupOnDataEventPayload, TFormGroupOnValidEventPayload, TFormGroupOnSubmitEventPayload, TFormValidationPayload, TFieldValidationPayload, };
|
package/src/types/form.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
1
2
|
import { IFormSchema } from '../interfaces/schema';
|
|
2
3
|
import { TMapper } from './mapper';
|
|
4
|
+
import { TFormDataPayload, TFormSubmitPayload, TFormValidationPayload } from './event';
|
|
3
5
|
/**
|
|
4
6
|
* @type TFormValues<T>
|
|
5
7
|
* 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.
|
|
@@ -19,6 +21,7 @@ import { TMapper } from './mapper';
|
|
|
19
21
|
*/
|
|
20
22
|
type TFormValues<T> = {
|
|
21
23
|
values: T;
|
|
24
|
+
metadata: unknown;
|
|
22
25
|
erroredFields: string[];
|
|
23
26
|
isValid: boolean;
|
|
24
27
|
};
|
|
@@ -29,6 +32,9 @@ type TFormValues<T> = {
|
|
|
29
32
|
* @property {IFormSchema} [schema] - The schema defining the structure and behavior of the form.
|
|
30
33
|
* @property {Record<string, unknown>} [initialValues] - The initial values for the form fields.
|
|
31
34
|
* @property {(data: TFormValues) => void} [onSubmit] - Callback function to handle form submission.
|
|
35
|
+
* @property {Subject<TFormDataPayload>} [dataSubject$] - data subject passed from formGroup instance
|
|
36
|
+
* @property {Subject<TFormValidationPayload>} [formValidSubject$] - formValid subject passed from formGroup instance
|
|
37
|
+
* @property {Subject<TFormSubmitPayload<unknown>>} [submitSubject$] - submit subject passed from formGroup instance
|
|
32
38
|
*
|
|
33
39
|
* @example
|
|
34
40
|
* ```typescript
|
|
@@ -42,5 +48,8 @@ type TFormValues<T> = {
|
|
|
42
48
|
type TFormEntry = Omit<IFormSchema, 'components'> & {
|
|
43
49
|
schema?: IFormSchema;
|
|
44
50
|
mappers?: TMapper<unknown>[];
|
|
51
|
+
dataSubject$?: Subject<TFormDataPayload>;
|
|
52
|
+
formValidSubject$?: Subject<TFormValidationPayload>;
|
|
53
|
+
submitSubject$?: Subject<TFormSubmitPayload<unknown>>;
|
|
45
54
|
};
|
|
46
55
|
export { TFormValues, TFormEntry };
|
package/src/types/schema.d.ts
CHANGED
|
@@ -667,7 +667,7 @@ type TResetValueMethods = Omit<TVisibility, 'showOnlyIfTrue' | 'validations'> &
|
|
|
667
667
|
validations?: TSchemaValidation;
|
|
668
668
|
};
|
|
669
669
|
type TResetPathMethods = {
|
|
670
|
-
property: typeof ALLOWED_RESET_PROPS_MUTATIONS[number];
|
|
670
|
+
property: (typeof ALLOWED_RESET_PROPS_MUTATIONS)[number];
|
|
671
671
|
path: string;
|
|
672
672
|
field: string;
|
|
673
673
|
resettledValue: unknown;
|
|
@@ -816,6 +816,10 @@ type TApiResponsePayload = {
|
|
|
816
816
|
type TApiResponse = {
|
|
817
817
|
default: TApiResponsePayload;
|
|
818
818
|
named?: Record<string, TApiResponsePayload>;
|
|
819
|
+
apiState: {
|
|
820
|
+
loading: boolean;
|
|
821
|
+
lastEvent?: TEvents;
|
|
822
|
+
};
|
|
819
823
|
};
|
|
820
824
|
/**
|
|
821
825
|
* Represents the schema config structure
|