@bolttech/form-engine-core 1.0.8 → 1.0.9

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.d.ts CHANGED
@@ -330,7 +330,7 @@ type TLengthValidation = {
330
330
  * const callbackValidation: TCallbackValidation = (value) => typeof value === 'string';
331
331
  * ```
332
332
  */
333
- type TCallbackValidation = (value: unknown, formValues: TFormValues<unknown>) => boolean;
333
+ type TCallbackValidation = (value: unknown, formValues: Pick<TFormValues<unknown>, 'values' | 'metadata'>) => boolean;
334
334
  /**
335
335
  * @type TBetweenValidation
336
336
  * Represents validation rules that check if a value is between a range.
package/index.esm.js CHANGED
@@ -1594,6 +1594,7 @@ const repeated = (value, validations) => {
1594
1594
  *
1595
1595
  * @param value - The value to be validated.
1596
1596
  * @param validations - An object containing validation methods, including a custom callback function.
1597
+ * @param formValues - An object containing the form state, NOTE: validations might be dirty here
1597
1598
  * @returns `true` if the custom callback validation function returns `true`, otherwise `false`.
1598
1599
  *
1599
1600
  * @example
@@ -1612,9 +1613,20 @@ const repeated = (value, validations) => {
1612
1613
  * };
1613
1614
  * ```
1614
1615
  */
1615
- const callback = (value, validations, formValues) => {
1616
+ const callback = (value, validations, {
1617
+ values = [],
1618
+ metadata = []
1619
+ } = {
1620
+ values: [],
1621
+ metadata: [],
1622
+ erroredFields: [],
1623
+ isValid: true
1624
+ }) => {
1616
1625
  if (!validations.callback || !((validations === null || validations === void 0 ? void 0 : validations.callback) instanceof Function)) return false;
1617
- return validations.callback(value, formValues);
1626
+ return validations.callback(value, {
1627
+ values,
1628
+ metadata
1629
+ });
1618
1630
  };
1619
1631
 
1620
1632
  /**
@@ -2913,14 +2925,20 @@ class FormField {
2913
2925
  valueSubscription,
2914
2926
  propsSubscription
2915
2927
  }) {
2928
+ /*
2929
+ NOTE: using emitEvents here will make ON_FIELD_MOUNT emit twice
2930
+ mount logic is managed on form.ts mountActions on first render
2931
+ */
2916
2932
  this.mounted = true;
2917
2933
  this.subscribeValue(valueSubscription);
2918
2934
  this.subscribeState(propsSubscription);
2919
2935
  this.valueSubject$.next(this.stateValue);
2920
2936
  this.propsSubject$.next(this.props);
2921
2937
  this.visibilitySubject$.next(this.visibility);
2922
- this.emitEvents({
2923
- event: 'ON_FIELD_MOUNT'
2938
+ this.fieldEventSubject$.next({
2939
+ event: 'ON_FIELD_MOUNT',
2940
+ fieldName: this.name,
2941
+ fieldInstance: this
2924
2942
  });
2925
2943
  }
2926
2944
  /**
@@ -3291,9 +3309,19 @@ class FormCore {
3291
3309
  this.fieldValidNotification$.subscribe(() => {
3292
3310
  this.validateForm();
3293
3311
  });
3312
+ /*
3313
+ @TODO check if this emissions can be merged
3314
+ every value update needs to occur after and before validations on field emitValue change
3315
+ so both callback validation and onData values are synced and fields and validations are correct
3316
+
3317
+ check field.ts emitValue and emitEvents
3318
+ */
3294
3319
  this.fieldEventSubject$.subscribe(() => {
3295
3320
  this.formValuesStateSubject$.next(this.getFormState());
3296
3321
  });
3322
+ this.dataSubject$.subscribe(() => {
3323
+ this.formValuesStateSubject$.next(this.getFormState());
3324
+ });
3297
3325
  this.mountSubject$.subscribe(this.mountActions.bind(this));
3298
3326
  this.initialValues = entry.initialValues || ((_j = entry.schema) === null || _j === void 0 ? void 0 : _j.initialValues);
3299
3327
  this.iVars = entry.iVars || ((_k = entry.schema) === null || _k === void 0 ? void 0 : _k.iVars) || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "dependencies": {
5
5
  "@gaignoux/currency": "^1.1.0",
6
6
  "credit-card-type": "^10.0.0",