@bolttech/form-engine-core 0.0.1-beta.1 → 0.0.1-beta.2

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 { Subscription, Subject, combineLatest, startWith, groupBy, mergeMap, debounceTime, map } from 'rxjs';
1
+ import { Subscription, Subject, combineLatest, startWith, filter, groupBy, mergeMap, debounceTime, map } from 'rxjs';
2
2
  import creditCardType from 'credit-card-type';
3
3
  import { isNumber as isNumber$1, isNil, isEqual, get, set } from 'lodash';
4
4
  import { getCurrencySymbol } from '@gaignoux/currency';
@@ -2265,6 +2265,7 @@ class FormField {
2265
2265
  *
2266
2266
  * @param {object} options - Configuration options for the form field.
2267
2267
  * @param {IComponentSchema} options.schemaComponent - The schema definition for the form field.
2268
+ * @param {TSchemaFormConfig} options.config - The schema default configuration for debounced actions.
2268
2269
  * @param {string} [options.path] - The path within the form field (used internally during recursion).
2269
2270
  * @param {string[]} options.children - An array of children fields names.
2270
2271
  * @param {Function} options.validateVisibility - A function to validate the visibility of the field.
@@ -2274,6 +2275,7 @@ class FormField {
2274
2275
  */
2275
2276
  constructor({
2276
2277
  schemaComponent,
2278
+ config,
2277
2279
  path,
2278
2280
  children,
2279
2281
  validateVisibility,
@@ -2286,6 +2288,10 @@ class FormField {
2286
2288
  }) {
2287
2289
  var _a, _b, _c, _d, _e, _f, _g;
2288
2290
  this.fieldStateSubscription$ = new Subscription();
2291
+ this.config = {
2292
+ defaultAPIdebounceTimeMS: Number(config === null || config === void 0 ? void 0 : config.defaultAPIdebounceTimeMS) ? Number(config === null || config === void 0 ? void 0 : config.defaultAPIdebounceTimeMS) : 1000,
2293
+ defaultStateRefreshTimeMS: Number(config === null || config === void 0 ? void 0 : config.defaultStateRefreshTimeMS) ? Number(config === null || config === void 0 ? void 0 : config.defaultStateRefreshTimeMS) : 100
2294
+ };
2289
2295
  this.name = schemaComponent.name;
2290
2296
  this.component = schemaComponent.component;
2291
2297
  this.path = path;
@@ -2324,6 +2330,7 @@ class FormField {
2324
2330
  return acc;
2325
2331
  }, {})
2326
2332
  };
2333
+ this._errors = {};
2327
2334
  this._errorsString = '';
2328
2335
  this._valid = false;
2329
2336
  this.initializeObservers();
@@ -2332,6 +2339,7 @@ class FormField {
2332
2339
  * method to initialize all recycled Subjects and initialize Observers on field instance creation or rerender
2333
2340
  */
2334
2341
  initializeObservers() {
2342
+ var _a;
2335
2343
  if (!this.valueSubject$ || this.valueSubject$.closed) {
2336
2344
  this.valueSubject$ = new Subject();
2337
2345
  }
@@ -2361,7 +2369,7 @@ class FormField {
2361
2369
  });
2362
2370
  !this.apiEventQueueSubject$.observed && this.apiEventQueueSubject$.pipe(this.debounceDistinct(({
2363
2371
  event
2364
- }) => event, 1000)).subscribe(payload => {
2372
+ }) => event, (_a = this.config) === null || _a === void 0 ? void 0 : _a.defaultAPIdebounceTimeMS), filter(() => this.apiSubject$ && !this.apiSubject$.closed)).subscribe(payload => {
2365
2373
  this.apiRequest(payload);
2366
2374
  });
2367
2375
  if (!isNil(this.initialValue)) {
@@ -2659,6 +2667,19 @@ class FormField {
2659
2667
  [this.errorMessagePropName]: this.errorsString
2660
2668
  });
2661
2669
  }
2670
+ /**
2671
+ * WIP expensive function to get updated field validity on each event
2672
+ */
2673
+ updateValidityFlag() {
2674
+ var _a;
2675
+ let valid = true;
2676
+ const schemaValidations = (_a = this.validations) === null || _a === void 0 ? void 0 : _a.config;
2677
+ schemaValidations && Object.keys(schemaValidations).forEach(validationKey => {
2678
+ const error = validations[validationKey](this.value, schemaValidations);
2679
+ valid = !error && valid;
2680
+ });
2681
+ this._valid = valid;
2682
+ }
2662
2683
  /**
2663
2684
  * Formats the field value using the specified formatters, if available.
2664
2685
  *
@@ -2802,7 +2823,7 @@ class FormField {
2802
2823
  * @returns {void}
2803
2824
  */
2804
2825
  subscribeState(callback) {
2805
- this.fieldStateSubscription$ = this.fieldState$.pipe(debounceTime(100)).subscribe({
2826
+ this.fieldStateSubscription$ = this.fieldState$.pipe(debounceTime(this.config.defaultStateRefreshTimeMS)).subscribe({
2806
2827
  next: callback
2807
2828
  });
2808
2829
  }
@@ -2845,6 +2866,7 @@ class FormCore {
2845
2866
  this.method = entry.method || ((_c = entry.schema) === null || _c === void 0 ? void 0 : _c.method);
2846
2867
  this._iVars = entry.iVars || ((_d = entry.schema) === null || _d === void 0 ? void 0 : _d.iVars) || {};
2847
2868
  this.onSubmit = entry.onSubmit;
2869
+ this.config = entry.config;
2848
2870
  this.mappers = entry.mappers;
2849
2871
  this.schema && FormCore.checkIndexes(this.schema.components);
2850
2872
  this.templateSubject$ = new Subject();
@@ -2947,7 +2969,8 @@ class FormCore {
2947
2969
  * @param {(payload: { field: string; data: TFormValues }) => void} callback callback function to call on data
2948
2970
  */
2949
2971
  subscribeData(callback) {
2950
- this.dataCallbackSubscription$ = this.dataSubject$.pipe(debounceTime(100), map(({
2972
+ var _a, _b;
2973
+ this.dataCallbackSubscription$ = this.dataSubject$.pipe(debounceTime(Number((_a = this.config) === null || _a === void 0 ? void 0 : _a.defaultStateRefreshTimeMS) ? Number((_b = this.config) === null || _b === void 0 ? void 0 : _b.defaultStateRefreshTimeMS) : 100), map(({
2951
2974
  key
2952
2975
  }) => ({
2953
2976
  field: key,
@@ -3282,7 +3305,8 @@ class FormCore {
3282
3305
  initialValue: (_a = this.initialValues) === null || _a === void 0 ? void 0 : _a[structElement.name],
3283
3306
  templateSubject$: this.templateSubject$,
3284
3307
  apiResponseSubject$: this.apiResponseSubject$,
3285
- dataSubject$: this.dataSubject$
3308
+ dataSubject$: this.dataSubject$,
3309
+ config: this.config
3286
3310
  }));
3287
3311
  } else {
3288
3312
  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) || [];
@@ -3393,6 +3417,7 @@ class FormCore {
3393
3417
  this.templateSubject$.unsubscribe();
3394
3418
  this.apiResponseSubject$.unsubscribe();
3395
3419
  this.dataSubject$.unsubscribe();
3420
+ this.fields.forEach(field => field.destroyField());
3396
3421
  }
3397
3422
  }
3398
3423
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.1-beta.2",
4
4
  "module": "./index.esm.js",
5
5
  "type": "module",
6
6
  "main": "./index.esm.js",
@@ -1,4 +1,4 @@
1
- import { TApiEvent, TErrorMessages, TEvent, TFormatters, TMasks, TProps, TResetValueMethods, TValidationMethods, TVisibility } from '../types/schema';
1
+ import { TApiEvent, TErrorMessages, TEvent, TFormatters, TMasks, TProps, TResetValueMethods, TSchemaFormConfig, TValidationMethods, TVisibility } from '../types/schema';
2
2
  /**
3
3
  * @interface IComponentSchema
4
4
  * Represents the schema for a component within a form.
@@ -75,6 +75,7 @@ interface IFormSchema {
75
75
  index: string;
76
76
  action?: string;
77
77
  method?: string;
78
+ config?: TSchemaFormConfig;
78
79
  initialValues?: Record<string, unknown>;
79
80
  iVars?: Record<string, unknown>;
80
81
  components?: IComponentSchema[];
@@ -1,5 +1,5 @@
1
1
  import { Observable, Subject, Subscription } from 'rxjs';
2
- import { TApiConfig, TApiEvent, TApiResponse, TErrorMessages, TEvent, TFormatters, TMasks, TResetValueMethods, TValidationMethods, TVisibility } from '../types/schema';
2
+ import { TApiConfig, TApiEvent, TApiResponse, TErrorMessages, TEvent, TFormatters, TMasks, TResetValueMethods, TSchemaFormConfig, TValidationMethods, TVisibility } from '../types/schema';
3
3
  import { IComponentSchema } from '../interfaces/schema';
4
4
  import { IState } from '../interfaces/state';
5
5
  import { TEvents, TMutationEvents, TValueChangeEvent } from '../types/event';
@@ -22,6 +22,7 @@ declare class FormField {
22
22
  valuePropName?: string;
23
23
  errorMessagePropName?: string;
24
24
  initialValue?: unknown;
25
+ config: Required<TSchemaFormConfig>;
25
26
  mapper: TMapper<unknown>;
26
27
  private _props;
27
28
  private _value;
@@ -67,6 +68,7 @@ declare class FormField {
67
68
  *
68
69
  * @param {object} options - Configuration options for the form field.
69
70
  * @param {IComponentSchema} options.schemaComponent - The schema definition for the form field.
71
+ * @param {TSchemaFormConfig} options.config - The schema default configuration for debounced actions.
70
72
  * @param {string} [options.path] - The path within the form field (used internally during recursion).
71
73
  * @param {string[]} options.children - An array of children fields names.
72
74
  * @param {Function} options.validateVisibility - A function to validate the visibility of the field.
@@ -74,8 +76,9 @@ declare class FormField {
74
76
  * @param {unknown} [options.initialValue] - The initial value of the form field.
75
77
  * @param {Subject<{ key: string }>} options.templateSubject$ - A subject for template updates.
76
78
  */
77
- constructor({ schemaComponent, path, children, validateVisibility, resetValue, initialValue, templateSubject$, apiResponseSubject$, dataSubject$, mapper, }: {
79
+ constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, initialValue, templateSubject$, apiResponseSubject$, dataSubject$, mapper, }: {
78
80
  schemaComponent: IComponentSchema;
81
+ config?: TSchemaFormConfig;
79
82
  path?: string;
80
83
  children: string[];
81
84
  validateVisibility: (payload: {
@@ -245,6 +248,10 @@ declare class FormField {
245
248
  setFieldValidity({ event }: {
246
249
  event: TEvents;
247
250
  }): void;
251
+ /**
252
+ * WIP expensive function to get updated field validity on each event
253
+ */
254
+ updateValidityFlag(): void;
248
255
  /**
249
256
  * Formats the field value using the specified formatters, if available.
250
257
  *
@@ -1,6 +1,7 @@
1
1
  import { IFormField } from './field';
2
2
  import { Subject, Subscription } from 'rxjs';
3
3
  import { IComponentSchema, IFormSchema } from '../interfaces/schema';
4
+ import { TSchemaFormConfig } from '../types/schema';
4
5
  import { TSubscribedTemplates } from '../types/template';
5
6
  import { TEvents, TMutationEvents } from '../types/event';
6
7
  import { TFormEntry, TFormValues } from '../types/form';
@@ -29,6 +30,7 @@ declare class FormCore {
29
30
  subscribedTemplates: TSubscribedTemplates[];
30
31
  action?: string;
31
32
  method?: string;
33
+ config?: TSchemaFormConfig;
32
34
  mappers: TMapper<unknown>[];
33
35
  onSubmit?: (data: TFormValues) => void;
34
36
  /**
@@ -0,0 +1,3 @@
1
+ export * from './form';
2
+ export * from './field';
3
+ export * from './formGroup';
@@ -739,4 +739,14 @@ type TApiResponse = {
739
739
  response: unknown;
740
740
  }>;
741
741
  };
742
- export { TApiConfig, TErrorMessages, TResetValues, TVisibilityConditions, TValidations, TMasks, TProps, TResetValueMethods, TFormatters, TValidationMethods, TEvent, TVisibility, TApiEvent, TApiResponse, TLengthValidation, TCreditCardMatch, TDocumentValidation, TCallbackValidation, TBetweenValidation, TMaskGeneric, TSplitterFormatterValue, TCurrencyMask, TDateOperatorsValidation, TConditionsValidationSet, TConditionsValidation, TMultipleValidation, TAvailableValidations, TDateValidation, TBetweenDatesValidation, TDateFormatsValidation, TDateInterval, };
742
+ /**
743
+ * Represents the schema config structure
744
+ *
745
+ * @property {number} defaultAPIdebounceTimeMS - default API debounce time between request events.
746
+ * @property {number} [defaultStateRefreshTimeMS] - default state refresh between events side effects.
747
+ */
748
+ type TSchemaFormConfig = {
749
+ defaultAPIdebounceTimeMS?: number;
750
+ defaultStateRefreshTimeMS?: number;
751
+ };
752
+ export { TApiConfig, TErrorMessages, TResetValues, TVisibilityConditions, TValidations, TMasks, TProps, TResetValueMethods, TFormatters, TValidationMethods, TEvent, TVisibility, TApiEvent, TApiResponse, TSchemaFormConfig, TLengthValidation, TCreditCardMatch, TDocumentValidation, TCallbackValidation, TBetweenValidation, TMaskGeneric, TSplitterFormatterValue, TCurrencyMask, TDateOperatorsValidation, TConditionsValidationSet, TConditionsValidation, TMultipleValidation, TAvailableValidations, TDateValidation, TBetweenDatesValidation, TDateFormatsValidation, TDateInterval, };