@bolttech/form-engine-core 1.0.0-beta.6 → 1.0.0-beta.8
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 +83 -60
- package/package.json +1 -1
- package/src/managers/field.d.ts +19 -0
- package/src/managers/form.d.ts +44 -1
package/index.esm.js
CHANGED
|
@@ -2563,6 +2563,8 @@ class FormField {
|
|
|
2563
2563
|
}
|
|
2564
2564
|
/**
|
|
2565
2565
|
* method to initialize all recycled Subjects and initialize Observers on field instance creation or rerender
|
|
2566
|
+
* due to some visibility conditions unmounts the field from the adapter if they are children of it and avoid
|
|
2567
|
+
* emissions to unsubscribed fields
|
|
2566
2568
|
*/
|
|
2567
2569
|
initializeObservers() {
|
|
2568
2570
|
var _a;
|
|
@@ -2624,6 +2626,12 @@ class FormField {
|
|
|
2624
2626
|
event: 'ON_PROPS'
|
|
2625
2627
|
});
|
|
2626
2628
|
}
|
|
2629
|
+
/**
|
|
2630
|
+
* Static function to remove templates form the component props that will be shown when
|
|
2631
|
+
* the field mounts and the template routine executes, to be used on the adapter
|
|
2632
|
+
*
|
|
2633
|
+
* @param {unknown} props - the properties from the adapter components.
|
|
2634
|
+
*/
|
|
2627
2635
|
static filterProps(props) {
|
|
2628
2636
|
if (Array.isArray(props)) {
|
|
2629
2637
|
return props.filter(el => typeof el === 'string' && el.includes('${') ? false : true).map(el => FormField.filterProps(el));
|
|
@@ -2804,9 +2812,20 @@ class FormField {
|
|
|
2804
2812
|
event: 'ON_API_FIELD_RESPONSE'
|
|
2805
2813
|
});
|
|
2806
2814
|
}
|
|
2815
|
+
/**
|
|
2816
|
+
* Retrieves the mounted status of the field.
|
|
2817
|
+
*
|
|
2818
|
+
* @returns {boolean} - the mounted status of the field.
|
|
2819
|
+
*/
|
|
2807
2820
|
get mounted() {
|
|
2808
2821
|
return this._mounted;
|
|
2809
2822
|
}
|
|
2823
|
+
/**
|
|
2824
|
+
* sets the mountedStatus and notifies the form that the field was mounted on the adapter
|
|
2825
|
+
* and it's ready to be handled by the form instance
|
|
2826
|
+
*
|
|
2827
|
+
* @param {boolean} mountedStatus - the mounted status to be set from the mountField function.
|
|
2828
|
+
*/
|
|
2810
2829
|
set mounted(mountedStatus) {
|
|
2811
2830
|
if (typeof mountedStatus === 'undefined' || mountedStatus === this.mounted) return;
|
|
2812
2831
|
this._mounted = mountedStatus;
|
|
@@ -2827,15 +2846,14 @@ class FormField {
|
|
|
2827
2846
|
valueSubscription,
|
|
2828
2847
|
propsSubscription
|
|
2829
2848
|
}) {
|
|
2830
|
-
var _a, _b;
|
|
2831
2849
|
this.subscribeValue(valueSubscription);
|
|
2832
2850
|
this.subscribeState(propsSubscription);
|
|
2833
2851
|
this.mounted = true;
|
|
2834
2852
|
this.valueSubject$.next(this.stateValue);
|
|
2835
2853
|
this.propsSubject$.next(this.props);
|
|
2836
2854
|
this.visibilitySubject$.next(this.visibility);
|
|
2837
|
-
|
|
2838
|
-
|
|
2855
|
+
this.setFieldValidity({
|
|
2856
|
+
event: 'ON_FIELD_MOUNT'
|
|
2839
2857
|
});
|
|
2840
2858
|
}
|
|
2841
2859
|
/**
|
|
@@ -3126,7 +3144,7 @@ class FormCore {
|
|
|
3126
3144
|
* @param {((payload: {field: string;data: TFormValues;}) => void) | undefined} [entry.onData] - A callback function to handle data emission.
|
|
3127
3145
|
*/
|
|
3128
3146
|
constructor(entry) {
|
|
3129
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
3147
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
3130
3148
|
this.templateSubscription$ = new Subscription();
|
|
3131
3149
|
this.mappers = new Map();
|
|
3132
3150
|
this.queuedFieldVisibilityEvents = new Map();
|
|
@@ -3137,13 +3155,12 @@ class FormCore {
|
|
|
3137
3155
|
this.fields = new Map();
|
|
3138
3156
|
this.action = entry.action || ((_a = entry.schema) === null || _a === void 0 ? void 0 : _a.action);
|
|
3139
3157
|
this.method = entry.method || ((_b = entry.schema) === null || _b === void 0 ? void 0 : _b.method);
|
|
3140
|
-
this._iVars = entry.iVars || ((_c = entry.schema) === null || _c === void 0 ? void 0 : _c.iVars) || {};
|
|
3141
3158
|
this.config = {
|
|
3142
|
-
defaultAPIdebounceTimeMS: Number((
|
|
3143
|
-
defaultStateRefreshTimeMS: Number((
|
|
3144
|
-
defaultLogVerbose: ((
|
|
3159
|
+
defaultAPIdebounceTimeMS: Number((_c = entry.config) === null || _c === void 0 ? void 0 : _c.defaultAPIdebounceTimeMS) ? Number((_d = entry.config) === null || _d === void 0 ? void 0 : _d.defaultAPIdebounceTimeMS) : DEFAULT_API_DEBOUNCE_TIME,
|
|
3160
|
+
defaultStateRefreshTimeMS: Number((_e = entry.config) === null || _e === void 0 ? void 0 : _e.defaultStateRefreshTimeMS) ? Number((_f = entry.config) === null || _f === void 0 ? void 0 : _f.defaultStateRefreshTimeMS) : DEFAULT_STATE_REFRESH_TIME,
|
|
3161
|
+
defaultLogVerbose: ((_g = entry.config) === null || _g === void 0 ? void 0 : _g.defaultLogVerbose) ? entry.config.defaultLogVerbose : DEFAULT_LOG_VERBOSE
|
|
3145
3162
|
};
|
|
3146
|
-
(
|
|
3163
|
+
(_h = entry.mappers) === null || _h === void 0 ? void 0 : _h.map(mapper => {
|
|
3147
3164
|
this.mappers.set(mapper.componentName, mapper);
|
|
3148
3165
|
});
|
|
3149
3166
|
this.schema && FormCore.checkIndexes(this.schema.components);
|
|
@@ -3154,41 +3171,34 @@ class FormCore {
|
|
|
3154
3171
|
this.mountSubject$ = new Subject();
|
|
3155
3172
|
this.formValidNotification$ = new Subject();
|
|
3156
3173
|
this.subscribedTemplates = [];
|
|
3157
|
-
// this.schema && this.serializeStructure(this.schema.components);
|
|
3158
|
-
// this.schema && this.subscribeTemplates();
|
|
3159
3174
|
this.templateSubscription$ = this.templateSubject$.subscribe(this.refreshTemplates.bind(this));
|
|
3160
3175
|
this.mountSubject$.subscribe(this.mountActions.bind(this));
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
// const propValue = field?.props?.[field?.valuePropName || ''];
|
|
3176
|
-
// !field?.value &&
|
|
3177
|
-
// field?.emitValue({
|
|
3178
|
-
// value:
|
|
3179
|
-
// typeof propValue === 'string' && !propValue.includes('${')
|
|
3180
|
-
// ? propValue
|
|
3181
|
-
// : '',
|
|
3182
|
-
// event: 'ON_FIELD_MOUNT',
|
|
3183
|
-
// });
|
|
3184
|
-
// }
|
|
3185
|
-
// this.refreshTemplates({ scope: 'fields', key, event: 'ON_FIELDS' });
|
|
3186
|
-
// });
|
|
3187
|
-
// this.setInitialValues(initialValues);
|
|
3176
|
+
this.initialValues = entry.initialValues || ((_j = entry.schema) === null || _j === void 0 ? void 0 : _j.initialValues);
|
|
3177
|
+
this.iVars = entry.iVars || ((_k = entry.schema) === null || _k === void 0 ? void 0 : _k.iVars) || {};
|
|
3178
|
+
}
|
|
3179
|
+
/**
|
|
3180
|
+
* mock function to simulate form mount onto the adapter
|
|
3181
|
+
*/
|
|
3182
|
+
generateFields() {
|
|
3183
|
+
this.schema && this.serializeStructure(this.schema.components);
|
|
3184
|
+
this.fields.forEach(field => {
|
|
3185
|
+
field.mountField({
|
|
3186
|
+
valueSubscription: () => null,
|
|
3187
|
+
propsSubscription: () => null
|
|
3188
|
+
});
|
|
3189
|
+
});
|
|
3188
3190
|
}
|
|
3191
|
+
/**
|
|
3192
|
+
* callback function passed to field instance to notify field adapter mount status
|
|
3193
|
+
* once the field has all field instance properties set, this function will handle all
|
|
3194
|
+
* field routines
|
|
3195
|
+
*
|
|
3196
|
+
* @param { string } entry.key field unique identifier
|
|
3197
|
+
* @param { boolean } entry.status mount status notified from field
|
|
3198
|
+
*/
|
|
3189
3199
|
mountActions({
|
|
3190
|
-
|
|
3191
|
-
|
|
3200
|
+
key,
|
|
3201
|
+
status
|
|
3192
3202
|
}) {
|
|
3193
3203
|
var _a;
|
|
3194
3204
|
if (status) {
|
|
@@ -3214,6 +3224,11 @@ class FormCore {
|
|
|
3214
3224
|
this.checkFieldEventQueues(key);
|
|
3215
3225
|
}
|
|
3216
3226
|
}
|
|
3227
|
+
/**
|
|
3228
|
+
* initialValues setter to handle field values set externally from the adapter
|
|
3229
|
+
*
|
|
3230
|
+
* @param { Record<string, unknown> | undefined } payload initialValues to set onto fields
|
|
3231
|
+
*/
|
|
3217
3232
|
set initialValues(payload) {
|
|
3218
3233
|
if (payload) {
|
|
3219
3234
|
Object.keys(payload).forEach(key => {
|
|
@@ -3816,25 +3831,12 @@ class FormCore {
|
|
|
3816
3831
|
submitEvent: this.submit.bind(this),
|
|
3817
3832
|
visibility: fieldSchema.visibility
|
|
3818
3833
|
}));
|
|
3819
|
-
// this.subscribeTemplates();
|
|
3820
|
-
// this.refreshTemplates({
|
|
3821
|
-
// scope: 'fields',
|
|
3822
|
-
// event: 'ON_FIELDS',
|
|
3823
|
-
// });
|
|
3824
|
-
// // if (!this.queuedInitialValues.has(fieldSchema.name)) {
|
|
3825
|
-
// // const field = this.fields.get(fieldSchema.name);
|
|
3826
|
-
// // const propValue = field?.props?.[field?.valuePropName || ''];
|
|
3827
|
-
// // !field?.value &&
|
|
3828
|
-
// // field?.emitValue({
|
|
3829
|
-
// // value:
|
|
3830
|
-
// // typeof propValue === 'string' && !propValue.includes('${')
|
|
3831
|
-
// // ? propValue
|
|
3832
|
-
// // : '',
|
|
3833
|
-
// // event: 'ON_FIELD_MOUNT',
|
|
3834
|
-
// // });
|
|
3835
|
-
// // }
|
|
3836
|
-
// this.checkFieldEventQueues(fieldSchema.name);
|
|
3837
3834
|
}
|
|
3835
|
+
/**
|
|
3836
|
+
* function to be called from the adapter to remove a field when a field is removed from it
|
|
3837
|
+
*
|
|
3838
|
+
* @param {{ key: string }} entry.key
|
|
3839
|
+
*/
|
|
3838
3840
|
removeField({
|
|
3839
3841
|
key
|
|
3840
3842
|
}) {
|
|
@@ -3981,6 +3983,12 @@ class FormCore {
|
|
|
3981
3983
|
isValid: this.isValid
|
|
3982
3984
|
};
|
|
3983
3985
|
}
|
|
3986
|
+
/**
|
|
3987
|
+
* function to be called to events sent from the adapter
|
|
3988
|
+
*
|
|
3989
|
+
* @param {{callback: (payload: TFieldEvent) => void}} entry.callback callback function from the adapter
|
|
3990
|
+
* @returns
|
|
3991
|
+
*/
|
|
3984
3992
|
subscribeFieldEvent({
|
|
3985
3993
|
callback
|
|
3986
3994
|
}) {
|
|
@@ -3989,6 +3997,12 @@ class FormCore {
|
|
|
3989
3997
|
});
|
|
3990
3998
|
return sub;
|
|
3991
3999
|
}
|
|
4000
|
+
/**
|
|
4001
|
+
* to be called from the adapter when the form mounts
|
|
4002
|
+
*
|
|
4003
|
+
* @param {(payload: TFormValues<T>) => void} callback
|
|
4004
|
+
* @returns Subscription
|
|
4005
|
+
*/
|
|
3992
4006
|
subscribeOnMount(callback) {
|
|
3993
4007
|
const sub = this.mountSubject$.pipe(map(() => this.getFormValues())).subscribe({
|
|
3994
4008
|
next: callback
|
|
@@ -4010,13 +4024,19 @@ class FormCore {
|
|
|
4010
4024
|
});
|
|
4011
4025
|
return sub;
|
|
4012
4026
|
}
|
|
4027
|
+
/**
|
|
4028
|
+
* method to register a callback function to be called when the form is valid
|
|
4029
|
+
*
|
|
4030
|
+
* @param {(payload: TFormValues<T>) => void} callback callback function to call when the submit action occurs
|
|
4031
|
+
*/
|
|
4013
4032
|
subscribeOnSubmit(callback) {
|
|
4014
|
-
const sub = this.submitSubject$.
|
|
4033
|
+
const sub = this.submitSubject$.subscribe({
|
|
4015
4034
|
next: callback
|
|
4016
4035
|
});
|
|
4017
4036
|
return sub;
|
|
4018
4037
|
}
|
|
4019
4038
|
/**
|
|
4039
|
+
* method to check whenever the validity status of the form changes, only emits on status change
|
|
4020
4040
|
*
|
|
4021
4041
|
* @param {(payload: TFormValidationPayload) => void} callback callback function to call onValid
|
|
4022
4042
|
*/
|
|
@@ -4039,13 +4059,16 @@ class FormCore {
|
|
|
4039
4059
|
field.emitEvents({
|
|
4040
4060
|
event: 'ON_FIELD_VALIDATION'
|
|
4041
4061
|
});
|
|
4062
|
+
console.log(`${field.name} is ${field.valid}`);
|
|
4042
4063
|
});
|
|
4043
4064
|
if (!this.isValid) return;
|
|
4044
4065
|
const values = this.getFormValues();
|
|
4045
4066
|
this.submitSubject$.next(values);
|
|
4046
4067
|
}
|
|
4068
|
+
/**
|
|
4069
|
+
* recycles all the Suscriptions, to be called from the adapter when the form leaves the page
|
|
4070
|
+
*/
|
|
4047
4071
|
destroy() {
|
|
4048
|
-
console.log('removing form');
|
|
4049
4072
|
this.submitSubject$.unsubscribe();
|
|
4050
4073
|
this.templateSubscription$.unsubscribe();
|
|
4051
4074
|
this.fieldEventSubject$.unsubscribe();
|
package/package.json
CHANGED
package/src/managers/field.d.ts
CHANGED
|
@@ -129,6 +129,8 @@ declare class FormField {
|
|
|
129
129
|
});
|
|
130
130
|
/**
|
|
131
131
|
* method to initialize all recycled Subjects and initialize Observers on field instance creation or rerender
|
|
132
|
+
* due to some visibility conditions unmounts the field from the adapter if they are children of it and avoid
|
|
133
|
+
* emissions to unsubscribed fields
|
|
132
134
|
*/
|
|
133
135
|
initializeObservers(): void;
|
|
134
136
|
/**
|
|
@@ -143,6 +145,12 @@ declare class FormField {
|
|
|
143
145
|
* @param {Record<string, unknown>} props - The new properties to be set.
|
|
144
146
|
*/
|
|
145
147
|
set props(props: Record<string, unknown>);
|
|
148
|
+
/**
|
|
149
|
+
* Static function to remove templates form the component props that will be shown when
|
|
150
|
+
* the field mounts and the template routine executes, to be used on the adapter
|
|
151
|
+
*
|
|
152
|
+
* @param {unknown} props - the properties from the adapter components.
|
|
153
|
+
*/
|
|
146
154
|
static filterProps(props: unknown): unknown;
|
|
147
155
|
/**
|
|
148
156
|
* Retrieves the current state value of the form field.
|
|
@@ -209,7 +217,18 @@ declare class FormField {
|
|
|
209
217
|
* @param {TApiResponse} response - The new API response data to be set.
|
|
210
218
|
*/
|
|
211
219
|
set api(response: TApiResponse);
|
|
220
|
+
/**
|
|
221
|
+
* Retrieves the mounted status of the field.
|
|
222
|
+
*
|
|
223
|
+
* @returns {boolean} - the mounted status of the field.
|
|
224
|
+
*/
|
|
212
225
|
get mounted(): boolean;
|
|
226
|
+
/**
|
|
227
|
+
* sets the mountedStatus and notifies the form that the field was mounted on the adapter
|
|
228
|
+
* and it's ready to be handled by the form instance
|
|
229
|
+
*
|
|
230
|
+
* @param {boolean} mountedStatus - the mounted status to be set from the mountField function.
|
|
231
|
+
*/
|
|
213
232
|
set mounted(mountedStatus: boolean);
|
|
214
233
|
/**
|
|
215
234
|
* Mounts the form field by initializing necessary subjects and combining their streams.
|
package/src/managers/form.d.ts
CHANGED
|
@@ -57,10 +57,27 @@ declare class FormCore {
|
|
|
57
57
|
* @param {((payload: {field: string;data: TFormValues;}) => void) | undefined} [entry.onData] - A callback function to handle data emission.
|
|
58
58
|
*/
|
|
59
59
|
constructor(entry: TFormEntry & Omit<IFormSchema, 'components'>);
|
|
60
|
-
|
|
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 }: {
|
|
61
73
|
key: string;
|
|
62
74
|
status: boolean;
|
|
63
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
|
+
*/
|
|
64
81
|
set initialValues(payload: Record<string, unknown> | undefined);
|
|
65
82
|
/**
|
|
66
83
|
* Retrieves the internal variables (iVars) of the form.
|
|
@@ -237,6 +254,11 @@ declare class FormCore {
|
|
|
237
254
|
fieldSchema: IComponentSchema;
|
|
238
255
|
mapperElement?: TMapper<unknown>;
|
|
239
256
|
}): void;
|
|
257
|
+
/**
|
|
258
|
+
* function to be called from the adapter to remove a field when a field is removed from it
|
|
259
|
+
*
|
|
260
|
+
* @param {{ key: string }} entry.key
|
|
261
|
+
*/
|
|
240
262
|
removeField({ key }: {
|
|
241
263
|
key: string;
|
|
242
264
|
}): void;
|
|
@@ -273,9 +295,21 @@ declare class FormCore {
|
|
|
273
295
|
* @returns {TFormValues} The current form values.
|
|
274
296
|
*/
|
|
275
297
|
getFormValues<T>(): TFormValues<T>;
|
|
298
|
+
/**
|
|
299
|
+
* function to be called to events sent from the adapter
|
|
300
|
+
*
|
|
301
|
+
* @param {{callback: (payload: TFieldEvent) => void}} entry.callback callback function from the adapter
|
|
302
|
+
* @returns
|
|
303
|
+
*/
|
|
276
304
|
subscribeFieldEvent({ callback, }: {
|
|
277
305
|
callback: (payload: TFieldEvent) => void;
|
|
278
306
|
}): Subscription;
|
|
307
|
+
/**
|
|
308
|
+
* to be called from the adapter when the form mounts
|
|
309
|
+
*
|
|
310
|
+
* @param {(payload: TFormValues<T>) => void} callback
|
|
311
|
+
* @returns Subscription
|
|
312
|
+
*/
|
|
279
313
|
subscribeOnMount<T>(callback: (payload: TFormValues<T>) => void): Subscription;
|
|
280
314
|
/**
|
|
281
315
|
*
|
|
@@ -285,8 +319,14 @@ declare class FormCore {
|
|
|
285
319
|
field: string;
|
|
286
320
|
data: TFormValues<T>;
|
|
287
321
|
}) => void): Subscription;
|
|
322
|
+
/**
|
|
323
|
+
* method to register a callback function to be called when the form is valid
|
|
324
|
+
*
|
|
325
|
+
* @param {(payload: TFormValues<T>) => void} callback callback function to call when the submit action occurs
|
|
326
|
+
*/
|
|
288
327
|
subscribeOnSubmit<T>(callback: (payload: TFormValues<T>) => void): Subscription;
|
|
289
328
|
/**
|
|
329
|
+
* method to check whenever the validity status of the form changes, only emits on status change
|
|
290
330
|
*
|
|
291
331
|
* @param {(payload: TFormValidationPayload) => void} callback callback function to call onValid
|
|
292
332
|
*/
|
|
@@ -295,6 +335,9 @@ declare class FormCore {
|
|
|
295
335
|
* Submits the form by triggering form field events and invoking the onSubmit callback.
|
|
296
336
|
*/
|
|
297
337
|
submit<T>(): void;
|
|
338
|
+
/**
|
|
339
|
+
* recycles all the Suscriptions, to be called from the adapter when the form leaves the page
|
|
340
|
+
*/
|
|
298
341
|
destroy(): void;
|
|
299
342
|
}
|
|
300
343
|
type TFormCore = FormCore;
|