@bolttech/form-engine-core 1.0.0-beta.7 → 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 +81 -57
- 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;
|
|
@@ -3125,7 +3144,7 @@ class FormCore {
|
|
|
3125
3144
|
* @param {((payload: {field: string;data: TFormValues;}) => void) | undefined} [entry.onData] - A callback function to handle data emission.
|
|
3126
3145
|
*/
|
|
3127
3146
|
constructor(entry) {
|
|
3128
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
3147
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
3129
3148
|
this.templateSubscription$ = new Subscription();
|
|
3130
3149
|
this.mappers = new Map();
|
|
3131
3150
|
this.queuedFieldVisibilityEvents = new Map();
|
|
@@ -3136,13 +3155,12 @@ class FormCore {
|
|
|
3136
3155
|
this.fields = new Map();
|
|
3137
3156
|
this.action = entry.action || ((_a = entry.schema) === null || _a === void 0 ? void 0 : _a.action);
|
|
3138
3157
|
this.method = entry.method || ((_b = entry.schema) === null || _b === void 0 ? void 0 : _b.method);
|
|
3139
|
-
this._iVars = entry.iVars || ((_c = entry.schema) === null || _c === void 0 ? void 0 : _c.iVars) || {};
|
|
3140
3158
|
this.config = {
|
|
3141
|
-
defaultAPIdebounceTimeMS: Number((
|
|
3142
|
-
defaultStateRefreshTimeMS: Number((
|
|
3143
|
-
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
|
|
3144
3162
|
};
|
|
3145
|
-
(
|
|
3163
|
+
(_h = entry.mappers) === null || _h === void 0 ? void 0 : _h.map(mapper => {
|
|
3146
3164
|
this.mappers.set(mapper.componentName, mapper);
|
|
3147
3165
|
});
|
|
3148
3166
|
this.schema && FormCore.checkIndexes(this.schema.components);
|
|
@@ -3153,41 +3171,34 @@ class FormCore {
|
|
|
3153
3171
|
this.mountSubject$ = new Subject();
|
|
3154
3172
|
this.formValidNotification$ = new Subject();
|
|
3155
3173
|
this.subscribedTemplates = [];
|
|
3156
|
-
// this.schema && this.serializeStructure(this.schema.components);
|
|
3157
|
-
// this.schema && this.subscribeTemplates();
|
|
3158
3174
|
this.templateSubscription$ = this.templateSubject$.subscribe(this.refreshTemplates.bind(this));
|
|
3159
3175
|
this.mountSubject$.subscribe(this.mountActions.bind(this));
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
// event: 'ON_IVARS',
|
|
3163
|
-
// });
|
|
3164
|
-
/*
|
|
3165
|
-
only emits event ON_FIELD_MOUNT if does not have initialValue, if has initialValue, initialValues class property setter will
|
|
3166
|
-
emit the value along with ON_FIELD_MOUNT event
|
|
3167
|
-
*/
|
|
3168
|
-
// const initialValues = entry.initialValues || entry.schema?.initialValues;
|
|
3169
|
-
// this.fields.forEach((field, key) => {
|
|
3170
|
-
// if (
|
|
3171
|
-
// !initialValues ||
|
|
3172
|
-
// (initialValues && !Object.keys(initialValues).includes(key))
|
|
3173
|
-
// ) {
|
|
3174
|
-
// const propValue = field?.props?.[field?.valuePropName || ''];
|
|
3175
|
-
// !field?.value &&
|
|
3176
|
-
// field?.emitValue({
|
|
3177
|
-
// value:
|
|
3178
|
-
// typeof propValue === 'string' && !propValue.includes('${')
|
|
3179
|
-
// ? propValue
|
|
3180
|
-
// : '',
|
|
3181
|
-
// event: 'ON_FIELD_MOUNT',
|
|
3182
|
-
// });
|
|
3183
|
-
// }
|
|
3184
|
-
// this.refreshTemplates({ scope: 'fields', key, event: 'ON_FIELDS' });
|
|
3185
|
-
// });
|
|
3186
|
-
// 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) || {};
|
|
3187
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
|
+
});
|
|
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
|
+
*/
|
|
3188
3199
|
mountActions({
|
|
3189
|
-
|
|
3190
|
-
|
|
3200
|
+
key,
|
|
3201
|
+
status
|
|
3191
3202
|
}) {
|
|
3192
3203
|
var _a;
|
|
3193
3204
|
if (status) {
|
|
@@ -3213,6 +3224,11 @@ class FormCore {
|
|
|
3213
3224
|
this.checkFieldEventQueues(key);
|
|
3214
3225
|
}
|
|
3215
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
|
+
*/
|
|
3216
3232
|
set initialValues(payload) {
|
|
3217
3233
|
if (payload) {
|
|
3218
3234
|
Object.keys(payload).forEach(key => {
|
|
@@ -3815,25 +3831,12 @@ class FormCore {
|
|
|
3815
3831
|
submitEvent: this.submit.bind(this),
|
|
3816
3832
|
visibility: fieldSchema.visibility
|
|
3817
3833
|
}));
|
|
3818
|
-
// this.subscribeTemplates();
|
|
3819
|
-
// this.refreshTemplates({
|
|
3820
|
-
// scope: 'fields',
|
|
3821
|
-
// event: 'ON_FIELDS',
|
|
3822
|
-
// });
|
|
3823
|
-
// // if (!this.queuedInitialValues.has(fieldSchema.name)) {
|
|
3824
|
-
// // const field = this.fields.get(fieldSchema.name);
|
|
3825
|
-
// // const propValue = field?.props?.[field?.valuePropName || ''];
|
|
3826
|
-
// // !field?.value &&
|
|
3827
|
-
// // field?.emitValue({
|
|
3828
|
-
// // value:
|
|
3829
|
-
// // typeof propValue === 'string' && !propValue.includes('${')
|
|
3830
|
-
// // ? propValue
|
|
3831
|
-
// // : '',
|
|
3832
|
-
// // event: 'ON_FIELD_MOUNT',
|
|
3833
|
-
// // });
|
|
3834
|
-
// // }
|
|
3835
|
-
// this.checkFieldEventQueues(fieldSchema.name);
|
|
3836
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
|
+
*/
|
|
3837
3840
|
removeField({
|
|
3838
3841
|
key
|
|
3839
3842
|
}) {
|
|
@@ -3980,6 +3983,12 @@ class FormCore {
|
|
|
3980
3983
|
isValid: this.isValid
|
|
3981
3984
|
};
|
|
3982
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
|
+
*/
|
|
3983
3992
|
subscribeFieldEvent({
|
|
3984
3993
|
callback
|
|
3985
3994
|
}) {
|
|
@@ -3988,6 +3997,12 @@ class FormCore {
|
|
|
3988
3997
|
});
|
|
3989
3998
|
return sub;
|
|
3990
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
|
+
*/
|
|
3991
4006
|
subscribeOnMount(callback) {
|
|
3992
4007
|
const sub = this.mountSubject$.pipe(map(() => this.getFormValues())).subscribe({
|
|
3993
4008
|
next: callback
|
|
@@ -4009,13 +4024,19 @@ class FormCore {
|
|
|
4009
4024
|
});
|
|
4010
4025
|
return sub;
|
|
4011
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
|
+
*/
|
|
4012
4032
|
subscribeOnSubmit(callback) {
|
|
4013
|
-
const sub = this.submitSubject$.
|
|
4033
|
+
const sub = this.submitSubject$.subscribe({
|
|
4014
4034
|
next: callback
|
|
4015
4035
|
});
|
|
4016
4036
|
return sub;
|
|
4017
4037
|
}
|
|
4018
4038
|
/**
|
|
4039
|
+
* method to check whenever the validity status of the form changes, only emits on status change
|
|
4019
4040
|
*
|
|
4020
4041
|
* @param {(payload: TFormValidationPayload) => void} callback callback function to call onValid
|
|
4021
4042
|
*/
|
|
@@ -4038,13 +4059,16 @@ class FormCore {
|
|
|
4038
4059
|
field.emitEvents({
|
|
4039
4060
|
event: 'ON_FIELD_VALIDATION'
|
|
4040
4061
|
});
|
|
4062
|
+
console.log(`${field.name} is ${field.valid}`);
|
|
4041
4063
|
});
|
|
4042
4064
|
if (!this.isValid) return;
|
|
4043
4065
|
const values = this.getFormValues();
|
|
4044
4066
|
this.submitSubject$.next(values);
|
|
4045
4067
|
}
|
|
4068
|
+
/**
|
|
4069
|
+
* recycles all the Suscriptions, to be called from the adapter when the form leaves the page
|
|
4070
|
+
*/
|
|
4046
4071
|
destroy() {
|
|
4047
|
-
console.log('removing form');
|
|
4048
4072
|
this.submitSubject$.unsubscribe();
|
|
4049
4073
|
this.templateSubscription$.unsubscribe();
|
|
4050
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;
|