@bolttech/form-engine-core 1.0.0-beta.5 → 1.0.0-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 CHANGED
@@ -1,6 +1,6 @@
1
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
- import { isNumber as isNumber$1, isFunction, cloneDeep, isEqual, get, isNil, set } from 'lodash';
3
+ import { isNumber as isNumber$1, isFunction, cloneDeep, merge, isEqual, get, isNil, set } from 'lodash';
4
4
  import { getCurrencySymbol } from '@gaignoux/currency';
5
5
 
6
6
  var TMutationEnum;
@@ -2496,9 +2496,11 @@ class FormField {
2496
2496
  fieldEventSubject$,
2497
2497
  dataSubject$,
2498
2498
  formValidNotification$,
2499
+ mountSubject$,
2499
2500
  mapper,
2500
2501
  getFormValues,
2501
- submitEvent
2502
+ submitEvent,
2503
+ visibility
2502
2504
  }) {
2503
2505
  var _a, _b, _c, _d, _e, _f, _g;
2504
2506
  this.valueSubscription$ = new Subscription();
@@ -2534,11 +2536,12 @@ class FormField {
2534
2536
  this.fieldEventSubject$ = fieldEventSubject$;
2535
2537
  this.dataSubject$ = dataSubject$;
2536
2538
  this.formValidNotification$ = formValidNotification$;
2537
- this._props = cloneDeep(schemaComponent.props || {});
2539
+ this.mountSubject$ = mountSubject$;
2540
+ this._props = FormField.filterProps(cloneDeep(schemaComponent.props || {}));
2538
2541
  this._metadata = '';
2539
2542
  this.errorsString = '';
2540
2543
  this.errorsList = [];
2541
- this._visibility = true;
2544
+ this._visibility = typeof visibility === 'boolean' ? visibility : true;
2542
2545
  this._api = {
2543
2546
  default: {
2544
2547
  response: ((_e = (_d = (_c = this.apiSchema) === null || _c === void 0 ? void 0 : _c.defaultConfig) === null || _d === void 0 ? void 0 : _d.config) === null || _e === void 0 ? void 0 : _e.fallbackValue) || '',
@@ -2554,7 +2557,7 @@ class FormField {
2554
2557
  }, {})
2555
2558
  };
2556
2559
  this._errors = {};
2557
- this._mounted = true;
2560
+ this._mounted = false;
2558
2561
  this._valid = false;
2559
2562
  this.initializeObservers();
2560
2563
  }
@@ -2564,25 +2567,25 @@ class FormField {
2564
2567
  initializeObservers() {
2565
2568
  var _a;
2566
2569
  if (!this.valueSubject$ || this.valueSubject$.closed) {
2567
- this.valueSubject$ = new SafeSubject(() => this._mounted);
2570
+ this.valueSubject$ = new SafeSubject(() => this.mounted);
2568
2571
  }
2569
2572
  if (!this.errorSubject$ || this.errorSubject$.closed) {
2570
- this.errorSubject$ = new SafeSubject(() => this._mounted);
2573
+ this.errorSubject$ = new SafeSubject(() => this.mounted);
2571
2574
  }
2572
2575
  if (!this.visibilitySubject$ || this.visibilitySubject$.closed) {
2573
- this.visibilitySubject$ = new SafeSubject(() => this._mounted);
2576
+ this.visibilitySubject$ = new SafeSubject(() => this.mounted);
2574
2577
  }
2575
2578
  if (!this.apiSubject$ || this.apiSubject$.closed) {
2576
- this.apiSubject$ = new SafeSubject(() => this._mounted);
2579
+ this.apiSubject$ = new SafeSubject(() => this.mounted);
2577
2580
  }
2578
2581
  if (!this.propsSubject$ || this.propsSubject$.closed) {
2579
- this.propsSubject$ = new SafeSubject(() => this._mounted);
2582
+ this.propsSubject$ = new SafeSubject(() => this.mounted);
2580
2583
  }
2581
2584
  if (!this.fieldStateSubscription$ || this.fieldStateSubscription$.closed) {
2582
2585
  this.fieldStateSubscription$ = new Subscription();
2583
2586
  }
2584
2587
  if (!this.apiEventQueueSubject$ || this.apiEventQueueSubject$.closed) {
2585
- this.apiEventQueueSubject$ = new SafeSubject(() => this._mounted);
2588
+ this.apiEventQueueSubject$ = new SafeSubject(() => this.mounted);
2586
2589
  }
2587
2590
  this.fieldState$ = combineLatest({
2588
2591
  visibility: this.visibilitySubject$.pipe(startWith(this._visibility)),
@@ -2611,8 +2614,9 @@ class FormField {
2611
2614
  * @param {Record<string, unknown>} props - The new properties to be set.
2612
2615
  */
2613
2616
  set props(props) {
2614
- if (typeof props === 'undefined' || isEqual(props, this.props)) return;
2615
- this._props = props;
2617
+ const diffProps = merge(cloneDeep(this.props), props);
2618
+ if (typeof diffProps === 'undefined' || isEqual(diffProps, this.props)) return;
2619
+ this._props = diffProps;
2616
2620
  this.propsSubject$.next(this.props);
2617
2621
  this.templateSubject$.next({
2618
2622
  scope: 'fields',
@@ -2620,6 +2624,22 @@ class FormField {
2620
2624
  event: 'ON_PROPS'
2621
2625
  });
2622
2626
  }
2627
+ static filterProps(props) {
2628
+ if (Array.isArray(props)) {
2629
+ return props.filter(el => typeof el === 'string' && el.includes('${') ? false : true).map(el => FormField.filterProps(el));
2630
+ }
2631
+ if (typeof props === 'object' && props !== null) {
2632
+ return Object.keys(props).reduce((acc, curr) => {
2633
+ const propValue = props[curr];
2634
+ if (typeof propValue === 'string' && propValue.includes('${')) {
2635
+ return acc;
2636
+ }
2637
+ acc[curr] = FormField.filterProps(props[curr]);
2638
+ return acc;
2639
+ }, {});
2640
+ }
2641
+ return props;
2642
+ }
2623
2643
  /**
2624
2644
  * Retrieves the current state value of the form field.
2625
2645
  *
@@ -2784,6 +2804,17 @@ class FormField {
2784
2804
  event: 'ON_API_FIELD_RESPONSE'
2785
2805
  });
2786
2806
  }
2807
+ get mounted() {
2808
+ return this._mounted;
2809
+ }
2810
+ set mounted(mountedStatus) {
2811
+ if (typeof mountedStatus === 'undefined' || mountedStatus === this.mounted) return;
2812
+ this._mounted = mountedStatus;
2813
+ this.mountSubject$.next({
2814
+ key: this.name,
2815
+ status: this.mounted
2816
+ });
2817
+ }
2787
2818
  /**
2788
2819
  * Mounts the form field by initializing necessary subjects and combining their streams.
2789
2820
  *
@@ -2796,10 +2827,16 @@ class FormField {
2796
2827
  valueSubscription,
2797
2828
  propsSubscription
2798
2829
  }) {
2799
- this.initializeObservers();
2830
+ var _a, _b;
2800
2831
  this.subscribeValue(valueSubscription);
2801
2832
  this.subscribeState(propsSubscription);
2802
- this._mounted = true;
2833
+ this.mounted = true;
2834
+ this.valueSubject$.next(this.stateValue);
2835
+ this.propsSubject$.next(this.props);
2836
+ this.visibilitySubject$.next(this.visibility);
2837
+ ((_b = (_a = this.mapper) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.setErrorMessage) && this.errorSubject$.next({
2838
+ [this.mapper.events.setErrorMessage]: this.errorsString
2839
+ });
2803
2840
  }
2804
2841
  /**
2805
2842
  * Sets the value of the form field and emits associated events.
@@ -2809,7 +2846,7 @@ class FormField {
2809
2846
  * @returns {void}
2810
2847
  */
2811
2848
  emitValue(prop) {
2812
- if (!this.visibility) return;
2849
+ if (!this.visibility || !this.mounted) return;
2813
2850
  this.value = prop.value;
2814
2851
  this.emitEvents({
2815
2852
  event: prop.event
@@ -2831,13 +2868,13 @@ class FormField {
2831
2868
  if (event === 'ON_FORM_SUBMIT') {
2832
2869
  return this.submitEvent();
2833
2870
  }
2834
- this.setFieldValidity({
2835
- event
2836
- });
2837
2871
  this.validateVisibility({
2838
2872
  event,
2839
2873
  key: this.name
2840
2874
  });
2875
+ this.setFieldValidity({
2876
+ event
2877
+ });
2841
2878
  this.resetValue({
2842
2879
  event,
2843
2880
  key: this.name
@@ -3037,7 +3074,7 @@ class FormField {
3037
3074
  * @returns {void}
3038
3075
  */
3039
3076
  destroyField() {
3040
- this._mounted = false;
3077
+ this.mounted = false;
3041
3078
  this.valueSubscription$.unsubscribe();
3042
3079
  this.visibilitySubject$.unsubscribe();
3043
3080
  this.fieldStateSubscription$.unsubscribe();
@@ -3089,7 +3126,7 @@ class FormCore {
3089
3126
  * @param {((payload: {field: string;data: TFormValues;}) => void) | undefined} [entry.onData] - A callback function to handle data emission.
3090
3127
  */
3091
3128
  constructor(entry) {
3092
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
3129
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
3093
3130
  this.templateSubscription$ = new Subscription();
3094
3131
  this.mappers = new Map();
3095
3132
  this.queuedFieldVisibilityEvents = new Map();
@@ -3117,40 +3154,71 @@ class FormCore {
3117
3154
  this.mountSubject$ = new Subject();
3118
3155
  this.formValidNotification$ = new Subject();
3119
3156
  this.subscribedTemplates = [];
3120
- this.schema && this.serializeStructure(this.schema.components);
3121
- this.schema && this.subscribeTemplates();
3157
+ // this.schema && this.serializeStructure(this.schema.components);
3158
+ // this.schema && this.subscribeTemplates();
3122
3159
  this.templateSubscription$ = this.templateSubject$.subscribe(this.refreshTemplates.bind(this));
3123
- this.templateSubject$.next({
3124
- scope: 'iVars',
3125
- event: 'ON_IVARS'
3126
- });
3160
+ this.mountSubject$.subscribe(this.mountActions.bind(this));
3161
+ // this.templateSubject$.next({
3162
+ // scope: 'iVars',
3163
+ // event: 'ON_IVARS',
3164
+ // });
3127
3165
  /*
3128
3166
  only emits event ON_FIELD_MOUNT if does not have initialValue, if has initialValue, initialValues class property setter will
3129
3167
  emit the value along with ON_FIELD_MOUNT event
3130
3168
  */
3131
- const initialValues = entry.initialValues || ((_k = entry.schema) === null || _k === void 0 ? void 0 : _k.initialValues);
3132
- this.fields.forEach((field, key) => {
3133
- var _a;
3134
- if (!initialValues || initialValues && !Object.keys(initialValues).includes(key)) {
3135
- const propValue = (_a = field === null || field === void 0 ? void 0 : field.props) === null || _a === void 0 ? void 0 : _a[(field === null || field === void 0 ? void 0 : field.valuePropName) || ''];
3136
- !(field === null || field === void 0 ? void 0 : field.value) && (field === null || field === void 0 ? void 0 : field.emitValue({
3137
- value: typeof propValue === 'string' && !propValue.includes('${') ? propValue : '',
3138
- event: 'ON_FIELD_MOUNT'
3139
- }));
3140
- }
3169
+ // const initialValues = entry.initialValues || entry.schema?.initialValues;
3170
+ // this.fields.forEach((field, key) => {
3171
+ // if (
3172
+ // !initialValues ||
3173
+ // (initialValues && !Object.keys(initialValues).includes(key))
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);
3188
+ }
3189
+ mountActions({
3190
+ status,
3191
+ key
3192
+ }) {
3193
+ var _a;
3194
+ if (status) {
3195
+ this.subscribeTemplates();
3141
3196
  this.refreshTemplates({
3142
3197
  scope: 'fields',
3143
- key,
3144
3198
  event: 'ON_FIELDS'
3145
3199
  });
3146
- });
3147
- this.setInitialValues(initialValues);
3200
+ this.templateSubject$.next({
3201
+ scope: 'iVars',
3202
+ event: 'ON_IVARS'
3203
+ });
3204
+ if (!this.queuedInitialValues.has(key)) {
3205
+ const field = this.fields.get(key);
3206
+ const propValue = (_a = field === null || field === void 0 ? void 0 : field.props) === null || _a === void 0 ? void 0 : _a[(field === null || field === void 0 ? void 0 : field.valuePropName) || ''];
3207
+ !(field === null || field === void 0 ? void 0 : field.value) ? field.emitValue({
3208
+ value: typeof propValue === 'string' && !propValue.includes('${') ? propValue : '',
3209
+ event: 'ON_FIELD_MOUNT'
3210
+ }) : field.emitEvents({
3211
+ event: 'ON_FIELD_MOUNT'
3212
+ });
3213
+ }
3214
+ this.checkFieldEventQueues(key);
3215
+ }
3148
3216
  }
3149
- setInitialValues(payload) {
3217
+ set initialValues(payload) {
3150
3218
  if (payload) {
3151
3219
  Object.keys(payload).forEach(key => {
3152
3220
  const field = this.fields.get(key);
3153
- if (!field || !(field === null || field === void 0 ? void 0 : field.visibility)) {
3221
+ if (!field || !(field === null || field === void 0 ? void 0 : field.visibility) || !(field === null || field === void 0 ? void 0 : field.mounted)) {
3154
3222
  this.queuedInitialValues.set(key, payload === null || payload === void 0 ? void 0 : payload[key]);
3155
3223
  } else {
3156
3224
  field.emitValue({
@@ -3187,6 +3255,7 @@ class FormCore {
3187
3255
  * @returns {boolean} True if the form is valid; otherwise, false.
3188
3256
  */
3189
3257
  get isValid() {
3258
+ if (this.fields.size === 0) return false;
3190
3259
  for (const [, field] of this.fields) {
3191
3260
  if (!field.valid) return false;
3192
3261
  }
@@ -3293,10 +3362,8 @@ class FormCore {
3293
3362
  }
3294
3363
  const fieldProp = field[property];
3295
3364
  let propState;
3296
- if (Array.isArray(fieldProp)) {
3297
- propState = [...fieldProp];
3298
- } else if (typeof fieldProp === 'object' && !isNil(fieldProp)) {
3299
- propState = Object.assign({}, fieldProp);
3365
+ if (Array.isArray(fieldProp) || typeof fieldProp === 'object' && !isNil(fieldProp)) {
3366
+ propState = cloneDeep(fieldProp);
3300
3367
  } else {
3301
3368
  this.config.defaultLogVerbose && console.warn(`invalid template property, skipping evaluation of ${field.name} with ${fieldProp}`);
3302
3369
  return;
@@ -3466,6 +3533,8 @@ class FormCore {
3466
3533
  * @param {string} field field to check
3467
3534
  */
3468
3535
  checkFieldEventQueues(field) {
3536
+ var _a;
3537
+ if (!((_a = this.fields.get(field)) === null || _a === void 0 ? void 0 : _a.mounted)) return;
3469
3538
  if (this.queuedFieldVisibilityEvents.has(field)) {
3470
3539
  this.setFieldVisibility(Object.assign({
3471
3540
  field: field
@@ -3473,10 +3542,11 @@ class FormCore {
3473
3542
  this.queuedFieldVisibilityEvents.delete(field);
3474
3543
  }
3475
3544
  if (this.queuedInitialValues.has(field)) {
3476
- this.setInitialValues({
3477
- [field]: this.queuedInitialValues.get(field)
3478
- });
3545
+ const value = this.queuedInitialValues.get(field);
3479
3546
  this.queuedInitialValues.delete(field);
3547
+ this.initialValues = {
3548
+ [field]: value
3549
+ };
3480
3550
  }
3481
3551
  if (this.queuedFieldResetValuesEvents.has(field)) {
3482
3552
  this.setResetFieldValue(Object.assign({
@@ -3506,14 +3576,16 @@ class FormCore {
3506
3576
  showOnlyIfTrue
3507
3577
  }) {
3508
3578
  const fieldInstance = this.fields.get(field);
3509
- if (!fieldInstance) {
3579
+ if (!fieldInstance || !fieldInstance.mounted) {
3510
3580
  this.queuedFieldVisibilityEvents.set(field, {
3511
3581
  hasError,
3512
3582
  showOnlyIfTrue
3513
3583
  });
3514
3584
  } else {
3585
+ const currentVisibility = fieldInstance.visibility;
3515
3586
  const visibility = showOnlyIfTrue ? hasError : !hasError;
3516
3587
  fieldInstance.visibility = visibility;
3588
+ if (currentVisibility === visibility) return;
3517
3589
  /**
3518
3590
  * I was sure I would not require to gambiarra, but..
3519
3591
  * in order to ignore an hidden value on a form submit
@@ -3585,12 +3657,12 @@ class FormCore {
3585
3657
  key,
3586
3658
  value
3587
3659
  }) {
3588
- if (!this.fields.has(key)) {
3660
+ const field = this.fields.get(key);
3661
+ if (!field || !(field === null || field === void 0 ? void 0 : field.mounted)) {
3589
3662
  this.queuedFieldResetValuesEvents.set(key, {
3590
3663
  value
3591
3664
  });
3592
3665
  } else {
3593
- const field = this.fields.get(key);
3594
3666
  field.emitValue({
3595
3667
  value: value,
3596
3668
  event: 'ON_FIELD_CLEARED'
@@ -3656,7 +3728,8 @@ class FormCore {
3656
3728
  path,
3657
3729
  value
3658
3730
  }) {
3659
- if (!this.fields.has(key)) {
3731
+ const field = this.fields.get(key);
3732
+ if (!field || field.mounted) {
3660
3733
  this.queuedFieldResetPropertyEvents.set(key, {
3661
3734
  property,
3662
3735
  path,
@@ -3720,7 +3793,7 @@ class FormCore {
3720
3793
  fieldSchema,
3721
3794
  mapperElement
3722
3795
  }) {
3723
- var _a, _b;
3796
+ var _a;
3724
3797
  if (this.fields.has(fieldSchema.name)) {
3725
3798
  throw new Error(`field name ${fieldSchema.name} already defined`);
3726
3799
  }
@@ -3738,23 +3811,29 @@ class FormCore {
3738
3811
  fieldEventSubject$: this.fieldEventSubject$,
3739
3812
  dataSubject$: this.dataSubject$,
3740
3813
  formValidNotification$: this.formValidNotification$,
3814
+ mountSubject$: this.mountSubject$,
3741
3815
  config: this.config,
3742
- submitEvent: this.submit.bind(this)
3816
+ submitEvent: this.submit.bind(this),
3817
+ visibility: fieldSchema.visibility
3743
3818
  }));
3744
- this.subscribeTemplates();
3745
- this.refreshTemplates({
3746
- scope: 'fields',
3747
- event: 'ON_FIELDS'
3748
- });
3749
- if (!this.queuedInitialValues.has(fieldSchema.name)) {
3750
- const field = this.fields.get(fieldSchema.name);
3751
- const propValue = (_b = field === null || field === void 0 ? void 0 : field.props) === null || _b === void 0 ? void 0 : _b[(field === null || field === void 0 ? void 0 : field.valuePropName) || ''];
3752
- !(field === null || field === void 0 ? void 0 : field.value) && (field === null || field === void 0 ? void 0 : field.emitValue({
3753
- value: typeof propValue === 'string' && !propValue.includes('${') ? propValue : '',
3754
- event: 'ON_FIELD_MOUNT'
3755
- }));
3756
- }
3757
- this.checkFieldEventQueues(fieldSchema.name);
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);
3758
3837
  }
3759
3838
  removeField({
3760
3839
  key
@@ -3769,64 +3848,6 @@ class FormCore {
3769
3848
  event: 'ON_FIELDS'
3770
3849
  });
3771
3850
  }
3772
- static serializeStructure({
3773
- struct,
3774
- path,
3775
- fields = new Map(),
3776
- mappers
3777
- }) {
3778
- if (!struct) return fields;
3779
- struct.forEach(structElement => {
3780
- var _a;
3781
- const currField = fields.get(structElement.name);
3782
- if (!currField) {
3783
- let mapper;
3784
- if (structElement === null || structElement === void 0 ? void 0 : structElement.mapper) {
3785
- mapper = structElement === null || structElement === void 0 ? void 0 : structElement.mapper;
3786
- } else {
3787
- mapper = mappers === null || mappers === void 0 ? void 0 : mappers.find(el => el.componentName === structElement.component);
3788
- }
3789
- if (!mapper) throw new Error(`mapper not found for ${structElement.component}, add it to the mappers configuration`);
3790
- fields.set(structElement.name, new FormField({
3791
- schemaComponent: structElement,
3792
- mapper,
3793
- path,
3794
- children: structElement.children ? structElement.children.map(el => el.name) : [],
3795
- // eslint-disable-next-line @typescript-eslint/no-empty-function
3796
- validateVisibility: () => {},
3797
- // eslint-disable-next-line @typescript-eslint/no-empty-function
3798
- resetValue: () => {},
3799
- // eslint-disable-next-line @typescript-eslint/no-empty-function
3800
- resetProperty: () => {},
3801
- templateSubject$: new Subject(),
3802
- fieldEventSubject$: new Subject(),
3803
- dataSubject$: new Subject(),
3804
- formValidNotification$: new Subject(),
3805
- getFormValues: () => ({
3806
- erroredFields: [],
3807
- isValid: false,
3808
- values: []
3809
- }),
3810
- // eslint-disable-next-line @typescript-eslint/no-empty-function
3811
- submitEvent: () => {}
3812
- }));
3813
- } else {
3814
- currField.children = ((_a = structElement === null || structElement === void 0 ? void 0 : structElement.children) === null || _a === void 0 ? void 0 : _a.map(el => el.name)) || (currField === null || currField === void 0 ? void 0 : currField.children) || [];
3815
- currField.path = path;
3816
- currField.originalSchema = structElement;
3817
- currField.templateSubject$ = new Subject();
3818
- }
3819
- if (structElement.children) {
3820
- this.serializeStructure({
3821
- fields,
3822
- path: `${path ? `${path}.` : ``}${structElement.name}`,
3823
- mappers: mappers,
3824
- struct: structElement.children
3825
- });
3826
- }
3827
- });
3828
- return fields;
3829
- }
3830
3851
  /**
3831
3852
  * Serializes the schema structure to create form fields.
3832
3853
  *
@@ -3858,9 +3879,11 @@ class FormCore {
3858
3879
  fieldEventSubject$: this.fieldEventSubject$,
3859
3880
  dataSubject$: this.dataSubject$,
3860
3881
  formValidNotification$: this.formValidNotification$,
3882
+ mountSubject$: this.mountSubject$,
3861
3883
  config: this.config,
3862
3884
  getFormValues: this.getFormValues.bind(this),
3863
- submitEvent: this.submit.bind(this)
3885
+ submitEvent: this.submit.bind(this),
3886
+ visibility: structElement.visibility
3864
3887
  }));
3865
3888
  } else {
3866
3889
  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) || [];
@@ -3940,10 +3963,12 @@ class FormCore {
3940
3963
  */
3941
3964
  getFormValues() {
3942
3965
  const values = {};
3966
+ const metadata = {};
3943
3967
  const erroredFields = [];
3944
3968
  this.fields.forEach((val, key) => {
3945
3969
  if (val.value) {
3946
3970
  set(values, val.nameToSubmit || key, val.value);
3971
+ metadata[key] = val.metadata;
3947
3972
  }
3948
3973
  if (!val.valid) {
3949
3974
  erroredFields.push(key);
@@ -3951,6 +3976,7 @@ class FormCore {
3951
3976
  });
3952
3977
  return {
3953
3978
  values,
3979
+ metadata,
3954
3980
  erroredFields,
3955
3981
  isValid: this.isValid
3956
3982
  };
@@ -4005,18 +4031,6 @@ class FormCore {
4005
4031
  });
4006
4032
  return sub;
4007
4033
  }
4008
- /**
4009
- * Submits the form by triggering form field events and invoking the onSubmit callback.
4010
- */
4011
- mounted() {
4012
- this.fields.forEach(field => {
4013
- field.emitEvents({
4014
- event: 'ON_FORM_MOUNT'
4015
- });
4016
- });
4017
- const values = this.getFormValues();
4018
- this.mountSubject$.next(values);
4019
- }
4020
4034
  /**
4021
4035
  * Submits the form by triggering form field events and invoking the onSubmit callback.
4022
4036
  */
@@ -4031,6 +4045,7 @@ class FormCore {
4031
4045
  this.submitSubject$.next(values);
4032
4046
  }
4033
4047
  destroy() {
4048
+ console.log('removing form');
4034
4049
  this.submitSubject$.unsubscribe();
4035
4050
  this.templateSubscription$.unsubscribe();
4036
4051
  this.fieldEventSubject$.unsubscribe();
@@ -4161,9 +4176,15 @@ class FormGroup {
4161
4176
  formIndex,
4162
4177
  fieldIndex
4163
4178
  }) {
4164
- var _a, _b, _c;
4165
- (_b = (_a = this.forms.get(formIndex)) === null || _a === void 0 ? void 0 : _a.fields.get(fieldIndex)) === null || _b === void 0 ? void 0 : _b.destroyField();
4166
- (_c = this.forms.get(formIndex)) === null || _c === void 0 ? void 0 : _c.fields.delete(fieldIndex);
4179
+ var _a;
4180
+ const form = this.forms.get(formIndex);
4181
+ (_a = form === null || form === void 0 ? void 0 : form.fields.get(fieldIndex)) === null || _a === void 0 ? void 0 : _a.destroyField();
4182
+ form === null || form === void 0 ? void 0 : form.fields.delete(fieldIndex);
4183
+ if ((form === null || form === void 0 ? void 0 : form.fields.size) === 0) {
4184
+ this.removeForm({
4185
+ key: formIndex
4186
+ });
4187
+ }
4167
4188
  }
4168
4189
  /**
4169
4190
  * Checks if the specified key already exists in the form group.
@@ -4194,6 +4215,7 @@ class FormGroup {
4194
4215
  submitMultipleFormsByIndex(indexes, callback) {
4195
4216
  let isValid = true;
4196
4217
  let values = {};
4218
+ let metadata = {};
4197
4219
  let erroredFields = [];
4198
4220
  indexes.forEach(index => {
4199
4221
  var _a, _b;
@@ -4201,12 +4223,14 @@ class FormGroup {
4201
4223
  const res = (_b = this.forms.get(index)) === null || _b === void 0 ? void 0 : _b.getFormValues();
4202
4224
  isValid = isValid && ((res === null || res === void 0 ? void 0 : res.isValid) || false);
4203
4225
  values = Object.assign(Object.assign({}, values), (res === null || res === void 0 ? void 0 : res.values) || {});
4226
+ metadata = Object.assign(Object.assign({}, metadata), (res === null || res === void 0 ? void 0 : res.metadata) || {});
4204
4227
  erroredFields = [...erroredFields, ...((res === null || res === void 0 ? void 0 : res.erroredFields) || [])];
4205
4228
  });
4206
4229
  isValid && callback && callback({
4207
4230
  erroredFields,
4208
4231
  isValid,
4209
- values
4232
+ values,
4233
+ metadata
4210
4234
  });
4211
4235
  }
4212
4236
  onDataSubscription({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.6",
4
4
  "module": "./index.esm.js",
5
5
  "type": "module",
6
6
  "main": "./index.esm.js",
@@ -62,6 +62,7 @@ interface IComponentSchema {
62
62
  formatters?: TFormatters;
63
63
  masks?: TMasks;
64
64
  children?: IComponentSchema[];
65
+ visibility?: boolean;
65
66
  }
66
67
  interface IComponentSchemaAsFormField<T> extends IComponentSchema {
67
68
  mapper?: TMapper<T>;
@@ -57,6 +57,10 @@ declare class FormField {
57
57
  event: TEvents;
58
58
  }>;
59
59
  formValidNotification$: Subject<Pick<TFormValidationPayload, 'fieldTrigger'>>;
60
+ mountSubject$: Subject<{
61
+ key: string;
62
+ status: boolean;
63
+ }>;
60
64
  validateVisibility: (payload: {
61
65
  event: TEvents;
62
66
  key: string;
@@ -90,7 +94,7 @@ declare class FormField {
90
94
  * @param {TMapper<unknown>} options.mapper, - component generic mapper containing render parameters for adapters
91
95
  * @param {() => TFormValues<unknown>} options.getFormValues, - form instance function that builds onData parameter payload from fields
92
96
  */
93
- constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, resetProperty, templateSubject$, fieldEventSubject$, dataSubject$, formValidNotification$, mapper, getFormValues, submitEvent, }: {
97
+ constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, resetProperty, templateSubject$, fieldEventSubject$, dataSubject$, formValidNotification$, mountSubject$, mapper, getFormValues, submitEvent, visibility, }: {
94
98
  schemaComponent: IComponentSchema;
95
99
  config?: TSchemaFormConfig;
96
100
  path?: string;
@@ -115,8 +119,13 @@ declare class FormField {
115
119
  event: TEvents;
116
120
  }>;
117
121
  formValidNotification$: Subject<Pick<TFormValidationPayload, 'fieldTrigger'>>;
122
+ mountSubject$: Subject<{
123
+ key: string;
124
+ status: boolean;
125
+ }>;
118
126
  mapper: TMapper<unknown>;
119
127
  getFormValues: () => TFormValues<unknown>;
128
+ visibility?: boolean;
120
129
  });
121
130
  /**
122
131
  * method to initialize all recycled Subjects and initialize Observers on field instance creation or rerender
@@ -134,6 +143,7 @@ declare class FormField {
134
143
  * @param {Record<string, unknown>} props - The new properties to be set.
135
144
  */
136
145
  set props(props: Record<string, unknown>);
146
+ static filterProps(props: unknown): unknown;
137
147
  /**
138
148
  * Retrieves the current state value of the form field.
139
149
  *
@@ -199,6 +209,8 @@ declare class FormField {
199
209
  * @param {TApiResponse} response - The new API response data to be set.
200
210
  */
201
211
  set api(response: TApiResponse);
212
+ get mounted(): boolean;
213
+ set mounted(mountedStatus: boolean);
202
214
  /**
203
215
  * Mounts the form field by initializing necessary subjects and combining their streams.
204
216
  *
@@ -17,7 +17,10 @@ declare class FormCore {
17
17
  templateSubject$: Subject<TTemplateEvent>;
18
18
  templateSubscription$: Subscription;
19
19
  submitSubject$: Subject<TFormValues<any>>;
20
- mountSubject$: Subject<TFormValues<any>>;
20
+ mountSubject$: Subject<{
21
+ key: string;
22
+ status: boolean;
23
+ }>;
21
24
  fieldEventSubject$: Subject<TFieldEvent>;
22
25
  dataSubject$: Subject<{
23
26
  key: string;
@@ -54,7 +57,11 @@ 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
- setInitialValues(payload: Record<string, unknown> | undefined): void;
60
+ mountActions({ status, key }: {
61
+ key: string;
62
+ status: boolean;
63
+ }): void;
64
+ set initialValues(payload: Record<string, unknown> | undefined);
58
65
  /**
59
66
  * Retrieves the internal variables (iVars) of the form.
60
67
  *
@@ -233,12 +240,6 @@ declare class FormCore {
233
240
  removeField({ key }: {
234
241
  key: string;
235
242
  }): void;
236
- static serializeStructure({ struct, path, fields, mappers, }: {
237
- struct?: IComponentSchemaAsFormField<unknown>[];
238
- path?: string;
239
- fields?: Map<string, IFormField>;
240
- mappers: TMapper<unknown>[];
241
- }): Map<string, IFormField>;
242
243
  /**
243
244
  * Serializes the schema structure to create form fields.
244
245
  *
@@ -290,10 +291,6 @@ declare class FormCore {
290
291
  * @param {(payload: TFormValidationPayload) => void} callback callback function to call onValid
291
292
  */
292
293
  subscribeFormValidation(callback: (payload: TFormValidationPayload) => void): Subscription;
293
- /**
294
- * Submits the form by triggering form field events and invoking the onSubmit callback.
295
- */
296
- mounted<T>(): void;
297
294
  /**
298
295
  * Submits the form by triggering form field events and invoking the onSubmit callback.
299
296
  */
@@ -19,6 +19,7 @@ import { TMapper } from './mapper';
19
19
  */
20
20
  type TFormValues<T> = {
21
21
  values: T;
22
+ metadata: unknown;
22
23
  erroredFields: string[];
23
24
  isValid: boolean;
24
25
  };