@bolttech/form-engine-core 0.0.1-beta.31 → 0.0.1-beta.33
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 +23 -0
- package/package.json +1 -1
- package/src/managers/form.d.ts +12 -6
- package/src/types/event.d.ts +1 -1
package/index.esm.js
CHANGED
|
@@ -3032,6 +3032,7 @@ class FormCore {
|
|
|
3032
3032
|
this.submitSubject$ = new Subject();
|
|
3033
3033
|
this.fieldEventSubject$ = new Subject();
|
|
3034
3034
|
this.dataSubject$ = new Subject();
|
|
3035
|
+
this.mountSubject$ = new Subject();
|
|
3035
3036
|
this.subscribedTemplates = [];
|
|
3036
3037
|
this.schema && this.serializeStructure(this.schema.components);
|
|
3037
3038
|
this.schema && this.subscribeTemplates();
|
|
@@ -3339,6 +3340,10 @@ class FormCore {
|
|
|
3339
3340
|
*/
|
|
3340
3341
|
setFieldVisibility(field, hasError, showOnlyIfTrue) {
|
|
3341
3342
|
if (!this.fields.has(field)) {
|
|
3343
|
+
/*
|
|
3344
|
+
* check with João the need for a global mount event for the form
|
|
3345
|
+
* to avoid not displaying this message in some cases
|
|
3346
|
+
*/
|
|
3342
3347
|
console.warn(`failed to update visibility onto field ${field}`);
|
|
3343
3348
|
} else {
|
|
3344
3349
|
this.fields.get(field).visibility = showOnlyIfTrue ? hasError : !hasError;
|
|
@@ -3591,6 +3596,12 @@ class FormCore {
|
|
|
3591
3596
|
});
|
|
3592
3597
|
return sub;
|
|
3593
3598
|
}
|
|
3599
|
+
subscribeOnMount(callback) {
|
|
3600
|
+
const sub = this.mountSubject$.pipe(map(() => this.getFormValues())).subscribe({
|
|
3601
|
+
next: callback
|
|
3602
|
+
});
|
|
3603
|
+
return sub;
|
|
3604
|
+
}
|
|
3594
3605
|
/**
|
|
3595
3606
|
*
|
|
3596
3607
|
* @param {(payload: { field: string; data: TFormValues }) => void} callback callback function to call on data
|
|
@@ -3612,6 +3623,18 @@ class FormCore {
|
|
|
3612
3623
|
});
|
|
3613
3624
|
return sub;
|
|
3614
3625
|
}
|
|
3626
|
+
/**
|
|
3627
|
+
* Submits the form by triggering form field events and invoking the onSubmit callback.
|
|
3628
|
+
*/
|
|
3629
|
+
mounted() {
|
|
3630
|
+
this.fields.forEach(field => {
|
|
3631
|
+
field.emitEvents({
|
|
3632
|
+
event: 'ON_FORM_MOUNT'
|
|
3633
|
+
});
|
|
3634
|
+
});
|
|
3635
|
+
const values = this.getFormValues();
|
|
3636
|
+
this.mountSubject$.next(values);
|
|
3637
|
+
}
|
|
3615
3638
|
/**
|
|
3616
3639
|
* Submits the form by triggering form field events and invoking the onSubmit callback.
|
|
3617
3640
|
*/
|
package/package.json
CHANGED
package/src/managers/form.d.ts
CHANGED
|
@@ -18,7 +18,8 @@ declare class FormCore {
|
|
|
18
18
|
key: string;
|
|
19
19
|
event: TMutationEvents;
|
|
20
20
|
}>;
|
|
21
|
-
submitSubject$: Subject<TFormValues<
|
|
21
|
+
submitSubject$: Subject<TFormValues<any>>;
|
|
22
|
+
mountSubject$: Subject<TFormValues<any>>;
|
|
22
23
|
fieldEventSubject$: Subject<TFieldEvent>;
|
|
23
24
|
dataSubject$: Subject<{
|
|
24
25
|
key: string;
|
|
@@ -215,23 +216,28 @@ declare class FormCore {
|
|
|
215
216
|
*
|
|
216
217
|
* @returns {TFormValues} The current form values.
|
|
217
218
|
*/
|
|
218
|
-
getFormValues(): TFormValues<
|
|
219
|
+
getFormValues<T>(): TFormValues<T>;
|
|
219
220
|
subscribeFieldEvent({ callback, }: {
|
|
220
221
|
callback: (payload: TFieldEvent) => void;
|
|
221
222
|
}): Subscription;
|
|
223
|
+
subscribeOnMount<T>(callback: (payload: TFormValues<T>) => void): Subscription;
|
|
222
224
|
/**
|
|
223
225
|
*
|
|
224
226
|
* @param {(payload: { field: string; data: TFormValues }) => void} callback callback function to call on data
|
|
225
227
|
*/
|
|
226
|
-
subscribeData(callback: (payload: {
|
|
228
|
+
subscribeData<T>(callback: (payload: {
|
|
227
229
|
field: string;
|
|
228
|
-
data: TFormValues<
|
|
230
|
+
data: TFormValues<T>;
|
|
229
231
|
}) => void): Subscription;
|
|
230
|
-
subscribeOnSubmit(callback: (payload: TFormValues<
|
|
232
|
+
subscribeOnSubmit<T>(callback: (payload: TFormValues<T>) => void): Subscription;
|
|
231
233
|
/**
|
|
232
234
|
* Submits the form by triggering form field events and invoking the onSubmit callback.
|
|
233
235
|
*/
|
|
234
|
-
|
|
236
|
+
mounted<T>(): void;
|
|
237
|
+
/**
|
|
238
|
+
* Submits the form by triggering form field events and invoking the onSubmit callback.
|
|
239
|
+
*/
|
|
240
|
+
submit<T>(): void;
|
|
235
241
|
destroy(): void;
|
|
236
242
|
}
|
|
237
243
|
type TFormCore = FormCore;
|
package/src/types/event.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { IFormField } from '../managers';
|
|
|
8
8
|
* const event: TEvents = 'ON_FIELD_CHANGE';
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
|
-
type TEvents = 'ON_FIELD_MOUNT' | 'ON_FIELD_CHANGE' | 'ON_FIELD_BLUR' | 'ON_FIELD_FOCUS' | 'ON_FIELD_CLICK' | 'ON_FIELD_KEYUP' | 'ON_FIELD_KEYDOWN' | 'ON_FORM_SUBMIT' | 'ON_API_FIELD_RESPONSE';
|
|
11
|
+
type TEvents = 'ON_FIELD_MOUNT' | 'ON_FIELD_CHANGE' | 'ON_FIELD_BLUR' | 'ON_FIELD_FOCUS' | 'ON_FIELD_CLICK' | 'ON_FIELD_KEYUP' | 'ON_FIELD_KEYDOWN' | 'ON_FORM_SUBMIT' | 'ON_FORM_MOUNT' | 'ON_API_FIELD_RESPONSE';
|
|
12
12
|
/**
|
|
13
13
|
* @type TMutationEvents
|
|
14
14
|
* Represents the different types of events that can occur internally that triggers templating.
|