@bolttech/form-engine-core 0.0.3-beta.4 → 0.0.3-beta.6
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 +31 -6
- package/package.json +1 -1
- package/src/managers/field.d.ts +3 -1
- package/src/managers/formGroup.d.ts +6 -1
- package/src/types/event.d.ts +7 -2
- package/src/types/mapper.d.ts +1 -0
package/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Subject, Subscription, combineLatest, startWith, groupBy, mergeMap, debounceTime, filter, map, distinctUntilKeyChanged, distinctUntilChanged } from 'rxjs';
|
|
1
|
+
import { Subject, Subscription, combineLatest, startWith, groupBy, mergeMap, debounceTime, filter, map, distinctUntilKeyChanged, distinctUntilChanged, skip } from 'rxjs';
|
|
2
2
|
import creditCardType from 'credit-card-type';
|
|
3
3
|
import { isNumber as isNumber$1, isFunction, cloneDeep, isEqual, get, isNil, set } from 'lodash';
|
|
4
4
|
import { getCurrencySymbol } from '@gaignoux/currency';
|
|
@@ -2497,7 +2497,8 @@ class FormField {
|
|
|
2497
2497
|
dataSubject$,
|
|
2498
2498
|
formValidNotification$,
|
|
2499
2499
|
mapper,
|
|
2500
|
-
getFormValues
|
|
2500
|
+
getFormValues,
|
|
2501
|
+
submitEvent
|
|
2501
2502
|
}) {
|
|
2502
2503
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
2503
2504
|
this.valueSubscription$ = new Subscription();
|
|
@@ -2528,6 +2529,7 @@ class FormField {
|
|
|
2528
2529
|
this.resetValue = resetValue;
|
|
2529
2530
|
this.resetProperty = resetProperty;
|
|
2530
2531
|
this.getFormValues = getFormValues;
|
|
2532
|
+
this.submitEvent = submitEvent;
|
|
2531
2533
|
this.templateSubject$ = templateSubject$;
|
|
2532
2534
|
this.fieldEventSubject$ = fieldEventSubject$;
|
|
2533
2535
|
this.dataSubject$ = dataSubject$;
|
|
@@ -2826,6 +2828,9 @@ class FormField {
|
|
|
2826
2828
|
emitEvents({
|
|
2827
2829
|
event
|
|
2828
2830
|
}) {
|
|
2831
|
+
if (event === 'ON_FORM_SUBMIT') {
|
|
2832
|
+
return this.submitEvent();
|
|
2833
|
+
}
|
|
2829
2834
|
this.setFieldValidity({
|
|
2830
2835
|
event
|
|
2831
2836
|
});
|
|
@@ -2893,7 +2898,7 @@ class FormField {
|
|
|
2893
2898
|
}
|
|
2894
2899
|
});
|
|
2895
2900
|
this.errors = eventMessages;
|
|
2896
|
-
} else if (event === '
|
|
2901
|
+
} else if (event === 'ON_FIELD_VALIDATION') {
|
|
2897
2902
|
this.errors = errors;
|
|
2898
2903
|
}
|
|
2899
2904
|
}
|
|
@@ -3733,7 +3738,8 @@ class FormCore {
|
|
|
3733
3738
|
fieldEventSubject$: this.fieldEventSubject$,
|
|
3734
3739
|
dataSubject$: this.dataSubject$,
|
|
3735
3740
|
formValidNotification$: this.formValidNotification$,
|
|
3736
|
-
config: this.config
|
|
3741
|
+
config: this.config,
|
|
3742
|
+
submitEvent: this.submit.bind(this)
|
|
3737
3743
|
}));
|
|
3738
3744
|
this.subscribeTemplates();
|
|
3739
3745
|
this.refreshTemplates({
|
|
@@ -3795,7 +3801,8 @@ class FormCore {
|
|
|
3795
3801
|
dataSubject$: this.dataSubject$,
|
|
3796
3802
|
formValidNotification$: this.formValidNotification$,
|
|
3797
3803
|
config: this.config,
|
|
3798
|
-
getFormValues: this.getFormValues.bind(this)
|
|
3804
|
+
getFormValues: this.getFormValues.bind(this),
|
|
3805
|
+
submitEvent: this.submit.bind(this)
|
|
3799
3806
|
}));
|
|
3800
3807
|
} else {
|
|
3801
3808
|
currField.children = ((_b = structElement === null || structElement === void 0 ? void 0 : structElement.children) === null || _b === void 0 ? void 0 : _b.map(el => el.name)) || (currField === null || currField === void 0 ? void 0 : currField.children) || [];
|
|
@@ -3958,7 +3965,7 @@ class FormCore {
|
|
|
3958
3965
|
submit() {
|
|
3959
3966
|
this.fields.forEach(field => {
|
|
3960
3967
|
field.emitEvents({
|
|
3961
|
-
event: '
|
|
3968
|
+
event: 'ON_FIELD_VALIDATION'
|
|
3962
3969
|
});
|
|
3963
3970
|
});
|
|
3964
3971
|
if (!this.isValid) return;
|
|
@@ -4123,6 +4130,7 @@ class FormGroup {
|
|
|
4123
4130
|
/**
|
|
4124
4131
|
* Prototype submit function to multiple forms
|
|
4125
4132
|
* @param {string[]} indexes form indexes to be submitted
|
|
4133
|
+
* @param callback
|
|
4126
4134
|
* @returns
|
|
4127
4135
|
*/
|
|
4128
4136
|
submitMultipleFormsByIndex(indexes, callback) {
|
|
@@ -4196,6 +4204,23 @@ class FormGroup {
|
|
|
4196
4204
|
}))).subscribe(callback);
|
|
4197
4205
|
return sub;
|
|
4198
4206
|
}
|
|
4207
|
+
onSubmitSubscription({
|
|
4208
|
+
ids,
|
|
4209
|
+
callback
|
|
4210
|
+
}) {
|
|
4211
|
+
const subs = ids.reduce((acc, formId) => {
|
|
4212
|
+
const form = this.forms.get(formId);
|
|
4213
|
+
const sub = form === null || form === void 0 ? void 0 : form.submitSubject$.pipe(map(() => form === null || form === void 0 ? void 0 : form.getFormValues()), startWith(undefined));
|
|
4214
|
+
if (sub) {
|
|
4215
|
+
acc[formId] = sub;
|
|
4216
|
+
} else {
|
|
4217
|
+
this.config.defaultLogVerbose && console.warn(`failed to register form id ${formId}`);
|
|
4218
|
+
}
|
|
4219
|
+
return acc;
|
|
4220
|
+
}, {});
|
|
4221
|
+
const sub = combineLatest(subs).pipe(skip(1)).subscribe(callback);
|
|
4222
|
+
return sub;
|
|
4223
|
+
}
|
|
4199
4224
|
}
|
|
4200
4225
|
|
|
4201
4226
|
export { FormCore, FormField, FormGroup, TMutationEnum };
|
package/package.json
CHANGED
package/src/managers/field.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ declare class FormField {
|
|
|
71
71
|
}) => void;
|
|
72
72
|
getFormValues: () => TFormValues<unknown>;
|
|
73
73
|
valueChangeEvent: TValueChangeEvent;
|
|
74
|
+
submitEvent: () => void;
|
|
74
75
|
/**
|
|
75
76
|
* Creates an instance of FormField.
|
|
76
77
|
*
|
|
@@ -89,7 +90,7 @@ declare class FormField {
|
|
|
89
90
|
* @param {TMapper<unknown>} options.mapper, - component generic mapper containing render parameters for adapters
|
|
90
91
|
* @param {() => TFormValues<unknown>} options.getFormValues, - form instance function that builds onData parameter payload from fields
|
|
91
92
|
*/
|
|
92
|
-
constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, resetProperty, templateSubject$, fieldEventSubject$, dataSubject$, formValidNotification$, mapper, getFormValues, }: {
|
|
93
|
+
constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, resetProperty, templateSubject$, fieldEventSubject$, dataSubject$, formValidNotification$, mapper, getFormValues, submitEvent, }: {
|
|
93
94
|
schemaComponent: IComponentSchema;
|
|
94
95
|
config?: TSchemaFormConfig;
|
|
95
96
|
path?: string;
|
|
@@ -106,6 +107,7 @@ declare class FormField {
|
|
|
106
107
|
event: TEvents;
|
|
107
108
|
key: string;
|
|
108
109
|
}) => void;
|
|
110
|
+
submitEvent: () => void;
|
|
109
111
|
templateSubject$: Subject<TTemplateEvent>;
|
|
110
112
|
fieldEventSubject$: Subject<TFieldEvent>;
|
|
111
113
|
dataSubject$: Subject<{
|
|
@@ -2,7 +2,7 @@ import { TFormValues } from '../types/form';
|
|
|
2
2
|
import { TMapper } from '../types/mapper';
|
|
3
3
|
import { TFormCore } from './form';
|
|
4
4
|
import { TSchemaFormConfig } from '../types/schema';
|
|
5
|
-
import { TFormGroupOnDataEventPayload, TFormGroupOnValidEventPayload } from '../types/event';
|
|
5
|
+
import { TFormGroupOnDataEventPayload, TFormGroupOnSubmitEventPayload, TFormGroupOnValidEventPayload } from '../types/event';
|
|
6
6
|
/**
|
|
7
7
|
* Represents a group that manages multiple forms.
|
|
8
8
|
*/
|
|
@@ -82,6 +82,7 @@ declare class FormGroup {
|
|
|
82
82
|
/**
|
|
83
83
|
* Prototype submit function to multiple forms
|
|
84
84
|
* @param {string[]} indexes form indexes to be submitted
|
|
85
|
+
* @param callback
|
|
85
86
|
* @returns
|
|
86
87
|
*/
|
|
87
88
|
submitMultipleFormsByIndex<T>(indexes: string[], callback?: (payload: TFormValues<T>) => void): void;
|
|
@@ -93,6 +94,10 @@ declare class FormGroup {
|
|
|
93
94
|
ids: string[];
|
|
94
95
|
callback: (payload: TFormGroupOnValidEventPayload) => void;
|
|
95
96
|
}): import("rxjs").Subscription;
|
|
97
|
+
onSubmitSubscription<T>({ ids, callback, }: {
|
|
98
|
+
ids: string[];
|
|
99
|
+
callback: (payload: TFormGroupOnSubmitEventPayload<T>) => void;
|
|
100
|
+
}): import("rxjs").Subscription;
|
|
96
101
|
destroy: () => void;
|
|
97
102
|
}
|
|
98
103
|
type TFormGroup = FormGroup;
|
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_FORM_MOUNT' | 'ON_API_FIELD_RESPONSE';
|
|
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';
|
|
13
13
|
/**
|
|
14
14
|
* @type TMutationEvents
|
|
15
15
|
* Represents the different types of events that can occur internally that triggers templating.
|
|
@@ -76,4 +76,9 @@ type TFormGroupOnValidEventPayload = {
|
|
|
76
76
|
groupValid: boolean;
|
|
77
77
|
forms: Record<string, boolean>;
|
|
78
78
|
};
|
|
79
|
-
|
|
79
|
+
/**
|
|
80
|
+
* @type TFormGroupOnSubmitEventPayload
|
|
81
|
+
* Form Group onSubmit event emitted payload on callback function parameter
|
|
82
|
+
*/
|
|
83
|
+
type TFormGroupOnSubmitEventPayload<T> = Record<string, TFormValues<T> | undefined>;
|
|
84
|
+
export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent, TFormGroupOnDataEventPayload, TFormGroupOnValidEventPayload, TFormGroupOnSubmitEventPayload, TFormValidationPayload, };
|