@bolttech/form-engine-core 0.0.1-beta.4 → 0.0.1-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
@@ -2282,7 +2282,7 @@ class FormField {
2282
2282
  resetValue,
2283
2283
  initialValue,
2284
2284
  templateSubject$,
2285
- apiResponseSubject$,
2285
+ fieldEventSubject$,
2286
2286
  dataSubject$,
2287
2287
  mapper
2288
2288
  }) {
@@ -2310,7 +2310,7 @@ class FormField {
2310
2310
  this.validateVisibility = validateVisibility;
2311
2311
  this.resetValue = resetValue;
2312
2312
  this.templateSubject$ = templateSubject$;
2313
- this.apiResponseSubject$ = apiResponseSubject$;
2313
+ this.fieldEventSubject$ = fieldEventSubject$;
2314
2314
  this.dataSubject$ = dataSubject$;
2315
2315
  this._props = schemaComponent.props || {};
2316
2316
  this._value = '';
@@ -2622,6 +2622,11 @@ class FormField {
2622
2622
  this.apiEventQueueSubject$.next({
2623
2623
  event
2624
2624
  });
2625
+ this.fieldEventSubject$.next({
2626
+ event,
2627
+ fieldName: this.name,
2628
+ fieldInstance: this
2629
+ });
2625
2630
  }
2626
2631
  /**
2627
2632
  * Sets the validity state of the field based on the provided validation rules and triggers error message updates.
@@ -2871,7 +2876,7 @@ class FormCore {
2871
2876
  this.schema && FormCore.checkIndexes(this.schema.components);
2872
2877
  this.templateSubject$ = new Subject();
2873
2878
  this.submitSubject$ = new Subject();
2874
- this.apiResponseSubject$ = new Subject();
2879
+ this.fieldEventSubject$ = new Subject();
2875
2880
  this.dataSubject$ = new Subject();
2876
2881
  this.dataCallbackSubscription$ = new Subscription();
2877
2882
  this.subscribedTemplates = [];
@@ -2882,7 +2887,7 @@ class FormCore {
2882
2887
  key: IVARPROPNAME,
2883
2888
  event: 'ON_IVARS'
2884
2889
  });
2885
- this.apiResponseSubject$.subscribe(this.refreshApi.bind(this));
2890
+ // this.fieldEventsSubject$.subscribe(this.refreshApi.bind(this));
2886
2891
  entry.onData && this.subscribeData(entry.onData);
2887
2892
  /*
2888
2893
  mount events needs to occur on form level, only when all the fields are instantiated
@@ -3286,22 +3291,22 @@ class FormCore {
3286
3291
  *
3287
3292
  * @param fieldSchema
3288
3293
  */
3289
- addField(fieldSchema) {
3294
+ addField(fieldSchema, mapper) {
3290
3295
  var _a;
3291
3296
  if (this.fields.has(fieldSchema.name)) {
3292
3297
  throw new Error(`field name ${fieldSchema.name} already defined`);
3293
3298
  }
3294
- const mapper = this.mappers.find(mapEl => mapEl.componentName === fieldSchema.component);
3295
- if (!mapper) throw new Error(`mapper not found for ${fieldSchema.component}, add it to the mappers configuration`);
3299
+ const mapperConfig = mapper || this.mappers.find(mapEl => mapEl.componentName === fieldSchema.component);
3300
+ if (!mapperConfig) throw new Error(`mapper not found for ${fieldSchema.component}, add it to the mappers configuration`);
3296
3301
  this.fields.set(fieldSchema.name, new FormField({
3297
3302
  schemaComponent: fieldSchema,
3298
- mapper,
3303
+ mapper: mapperConfig,
3299
3304
  children: fieldSchema.children ? fieldSchema.children.map(el => el.name) : [],
3300
3305
  validateVisibility: this.validateVisibility.bind(this),
3301
3306
  resetValue: this.resetValue.bind(this),
3302
3307
  initialValue: (_a = this.initialValues) === null || _a === void 0 ? void 0 : _a[fieldSchema.name],
3303
3308
  templateSubject$: this.templateSubject$,
3304
- apiResponseSubject$: this.apiResponseSubject$,
3309
+ fieldEventSubject$: this.fieldEventSubject$,
3305
3310
  dataSubject$: this.dataSubject$,
3306
3311
  config: this.config
3307
3312
  }));
@@ -3334,7 +3339,7 @@ class FormCore {
3334
3339
  resetValue: this.resetValue.bind(this),
3335
3340
  initialValue: (_a = this.initialValues) === null || _a === void 0 ? void 0 : _a[structElement.name],
3336
3341
  templateSubject$: this.templateSubject$,
3337
- apiResponseSubject$: this.apiResponseSubject$,
3342
+ fieldEventSubject$: this.fieldEventSubject$,
3338
3343
  dataSubject$: this.dataSubject$,
3339
3344
  config: this.config
3340
3345
  }));
@@ -3428,6 +3433,15 @@ class FormCore {
3428
3433
  isValid: this.isValid
3429
3434
  };
3430
3435
  }
3436
+ subscribeFieldEvent({
3437
+ event,
3438
+ callback
3439
+ }) {
3440
+ const sub = this.fieldEventSubject$.pipe(filter(payload => payload.event === event)).subscribe({
3441
+ next: callback
3442
+ });
3443
+ return sub;
3444
+ }
3431
3445
  /**
3432
3446
  * Submits the form by triggering form field events and invoking the onSubmit callback.
3433
3447
  */
@@ -3445,7 +3459,7 @@ class FormCore {
3445
3459
  destroy() {
3446
3460
  this.submitSubject$.unsubscribe();
3447
3461
  this.templateSubject$.unsubscribe();
3448
- this.apiResponseSubject$.unsubscribe();
3462
+ this.fieldEventSubject$.unsubscribe();
3449
3463
  this.dataSubject$.unsubscribe();
3450
3464
  this.fields.forEach(field => field.destroyField());
3451
3465
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "0.0.1-beta.4",
3
+ "version": "0.0.1-beta.6",
4
4
  "module": "./index.esm.js",
5
5
  "type": "module",
6
6
  "main": "./index.esm.js",
@@ -2,7 +2,7 @@ import { Observable, Subject, Subscription } from 'rxjs';
2
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
- import { TEvents, TMutationEvents, TValueChangeEvent } from '../types/event';
5
+ import { TEvents, TFieldEvent, TMutationEvents, TValueChangeEvent } from '../types/event';
6
6
  import { TMapper } from '../types/mapper';
7
7
  /**
8
8
  * Represents a form field with observables for managing form state, validations, and API requests.
@@ -38,9 +38,7 @@ declare class FormField {
38
38
  valueSubject$: Subject<unknown>;
39
39
  visibilitySubject$: Subject<boolean>;
40
40
  apiSubject$: Subject<TApiResponse>;
41
- apiResponseSubject$: Subject<{
42
- key: string;
43
- }>;
41
+ fieldEventSubject$: Subject<TFieldEvent>;
44
42
  apiEventQueueSubject$: Subject<{
45
43
  event: TEvents;
46
44
  }>;
@@ -76,7 +74,7 @@ declare class FormField {
76
74
  * @param {unknown} [options.initialValue] - The initial value of the form field.
77
75
  * @param {Subject<{ key: string }>} options.templateSubject$ - A subject for template updates.
78
76
  */
79
- constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, initialValue, templateSubject$, apiResponseSubject$, dataSubject$, mapper, }: {
77
+ constructor({ schemaComponent, config, path, children, validateVisibility, resetValue, initialValue, templateSubject$, fieldEventSubject$, dataSubject$, mapper, }: {
80
78
  schemaComponent: IComponentSchema;
81
79
  config?: TSchemaFormConfig;
82
80
  path?: string;
@@ -94,9 +92,7 @@ declare class FormField {
94
92
  key: string;
95
93
  event: TMutationEvents;
96
94
  }>;
97
- apiResponseSubject$: Subject<{
98
- key: string;
99
- }>;
95
+ fieldEventSubject$: Subject<TFieldEvent>;
100
96
  dataSubject$: Subject<{
101
97
  key: string;
102
98
  event: TEvents;
@@ -3,7 +3,7 @@ import { Subject, Subscription } from 'rxjs';
3
3
  import { IComponentSchema, IFormSchema } from '../interfaces/schema';
4
4
  import { TSchemaFormConfig } from '../types/schema';
5
5
  import { TSubscribedTemplates } from '../types/template';
6
- import { TEvents, TMutationEvents } from '../types/event';
6
+ import { TEvents, TFieldEvent, TMutationEvents } from '../types/event';
7
7
  import { TFormEntry, TFormValues } from '../types/form';
8
8
  import { TMapper } from '../types/mapper';
9
9
  /**
@@ -19,9 +19,7 @@ declare class FormCore {
19
19
  event: TMutationEvents;
20
20
  }>;
21
21
  submitSubject$: Subject<TFormValues>;
22
- apiResponseSubject$: Subject<{
23
- key: string;
24
- }>;
22
+ fieldEventSubject$: Subject<TFieldEvent>;
25
23
  dataSubject$: Subject<{
26
24
  key: string;
27
25
  event: TEvents;
@@ -188,7 +186,7 @@ declare class FormCore {
188
186
  *
189
187
  * @param fieldSchema
190
188
  */
191
- addField(fieldSchema: IComponentSchema): void;
189
+ addField(fieldSchema: IComponentSchema, mapper?: TMapper<unknown>): void;
192
190
  /**
193
191
  * Serializes the schema structure to create form fields.
194
192
  *
@@ -222,6 +220,10 @@ declare class FormCore {
222
220
  * @returns {TFormValues} The current form values.
223
221
  */
224
222
  getFormValues(): TFormValues;
223
+ subscribeFieldEvent({ event, callback, }: {
224
+ event: TEvents;
225
+ callback: (payload: TFieldEvent) => void;
226
+ }): Subscription;
225
227
  /**
226
228
  * Submits the form by triggering form field events and invoking the onSubmit callback.
227
229
  */
@@ -1,6 +1,6 @@
1
1
  import { TFormValues } from '../types/form';
2
2
  import { TMapper } from '../types/mapper';
3
- import { FormCore, TFormCore } from './form';
3
+ import { TFormCore } from './form';
4
4
  /**
5
5
  * Represents a group that manages multiple forms.
6
6
  */
@@ -40,7 +40,7 @@ declare class FormGroup {
40
40
  */
41
41
  getForm({ key }: {
42
42
  key: string;
43
- }): FormCore | undefined;
43
+ }): TFormCore | undefined;
44
44
  /**
45
45
  * Removes a form instance from the form group.
46
46
  *
@@ -1,3 +1,4 @@
1
+ import { IFormField } from '../managers';
1
2
  /**
2
3
  * @type TEvents
3
4
  * Represents the different types of events that can occur on form fields.
@@ -40,4 +41,9 @@ declare enum TMutationEnum {
40
41
  type TValueChangeEvent = (value: unknown, opts?: {
41
42
  props: Record<string, unknown>;
42
43
  }) => void;
43
- export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent };
44
+ type TFieldEvent = {
45
+ event: TEvents;
46
+ fieldName: string;
47
+ fieldInstance?: IFormField;
48
+ };
49
+ export { TEvents, TMutationEvents, TMutationEnum, TValueChangeEvent, TFieldEvent };