@bolttech/form-engine-core 0.0.3-beta.5 → 0.0.3-beta.7

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,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';
@@ -3882,10 +3882,12 @@ class FormCore {
3882
3882
  */
3883
3883
  getFormValues() {
3884
3884
  const values = {};
3885
+ const metadata = {};
3885
3886
  const erroredFields = [];
3886
3887
  this.fields.forEach((val, key) => {
3887
3888
  if (val.value) {
3888
3889
  set(values, val.nameToSubmit || key, val.value);
3890
+ metadata[key] = val.metadata;
3889
3891
  }
3890
3892
  if (!val.valid) {
3891
3893
  erroredFields.push(key);
@@ -3893,6 +3895,7 @@ class FormCore {
3893
3895
  });
3894
3896
  return {
3895
3897
  values,
3898
+ metadata,
3896
3899
  erroredFields,
3897
3900
  isValid: this.isValid
3898
3901
  };
@@ -4130,11 +4133,13 @@ class FormGroup {
4130
4133
  /**
4131
4134
  * Prototype submit function to multiple forms
4132
4135
  * @param {string[]} indexes form indexes to be submitted
4136
+ * @param callback
4133
4137
  * @returns
4134
4138
  */
4135
4139
  submitMultipleFormsByIndex(indexes, callback) {
4136
4140
  let isValid = true;
4137
4141
  let values = {};
4142
+ let metadata = {};
4138
4143
  let erroredFields = [];
4139
4144
  indexes.forEach(index => {
4140
4145
  var _a, _b;
@@ -4142,12 +4147,14 @@ class FormGroup {
4142
4147
  const res = (_b = this.forms.get(index)) === null || _b === void 0 ? void 0 : _b.getFormValues();
4143
4148
  isValid = isValid && ((res === null || res === void 0 ? void 0 : res.isValid) || false);
4144
4149
  values = Object.assign(Object.assign({}, values), (res === null || res === void 0 ? void 0 : res.values) || {});
4150
+ metadata = Object.assign(Object.assign({}, metadata), (res === null || res === void 0 ? void 0 : res.metadata) || {});
4145
4151
  erroredFields = [...erroredFields, ...((res === null || res === void 0 ? void 0 : res.erroredFields) || [])];
4146
4152
  });
4147
4153
  isValid && callback && callback({
4148
4154
  erroredFields,
4149
4155
  isValid,
4150
- values
4156
+ values,
4157
+ metadata
4151
4158
  });
4152
4159
  }
4153
4160
  onDataSubscription({
@@ -4203,6 +4210,23 @@ class FormGroup {
4203
4210
  }))).subscribe(callback);
4204
4211
  return sub;
4205
4212
  }
4213
+ onSubmitSubscription({
4214
+ ids,
4215
+ callback
4216
+ }) {
4217
+ const subs = ids.reduce((acc, formId) => {
4218
+ const form = this.forms.get(formId);
4219
+ const sub = form === null || form === void 0 ? void 0 : form.submitSubject$.pipe(map(() => form === null || form === void 0 ? void 0 : form.getFormValues()), startWith(undefined));
4220
+ if (sub) {
4221
+ acc[formId] = sub;
4222
+ } else {
4223
+ this.config.defaultLogVerbose && console.warn(`failed to register form id ${formId}`);
4224
+ }
4225
+ return acc;
4226
+ }, {});
4227
+ const sub = combineLatest(subs).pipe(skip(1)).subscribe(callback);
4228
+ return sub;
4229
+ }
4206
4230
  }
4207
4231
 
4208
4232
  export { FormCore, FormField, FormGroup, TMutationEnum };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "0.0.3-beta.5",
3
+ "version": "0.0.3-beta.7",
4
4
  "module": "./index.esm.js",
5
5
  "type": "module",
6
6
  "main": "./index.esm.js",
@@ -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;
@@ -76,4 +76,9 @@ type TFormGroupOnValidEventPayload = {
76
76
  groupValid: boolean;
77
77
  forms: Record<string, boolean>;
78
78
  };
79
- export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent, TFormGroupOnDataEventPayload, TFormGroupOnValidEventPayload, TFormValidationPayload, };
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, };
@@ -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
  };