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

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
@@ -3281,6 +3281,36 @@ class FormCore {
3281
3281
  });
3282
3282
  });
3283
3283
  }
3284
+ /**
3285
+ * Adds a field onto the form instance regardless there is a schema or not
3286
+ *
3287
+ * @param fieldSchema
3288
+ */
3289
+ addField(fieldSchema) {
3290
+ var _a;
3291
+ if (this.fields.has(fieldSchema.name)) {
3292
+ throw new Error(`field name ${fieldSchema.name} already defined`);
3293
+ }
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`);
3296
+ this.fields.set(fieldSchema.name, new FormField({
3297
+ schemaComponent: fieldSchema,
3298
+ mapper,
3299
+ children: fieldSchema.children ? fieldSchema.children.map(el => el.name) : [],
3300
+ validateVisibility: this.validateVisibility.bind(this),
3301
+ resetValue: this.resetValue.bind(this),
3302
+ initialValue: (_a = this.initialValues) === null || _a === void 0 ? void 0 : _a[fieldSchema.name],
3303
+ templateSubject$: this.templateSubject$,
3304
+ apiResponseSubject$: this.apiResponseSubject$,
3305
+ dataSubject$: this.dataSubject$,
3306
+ config: this.config
3307
+ }));
3308
+ this.subscribeTemplates();
3309
+ this.refreshTemplates({
3310
+ event: 'ON_FIELDS',
3311
+ key: fieldSchema.name
3312
+ });
3313
+ }
3284
3314
  /**
3285
3315
  * Serializes the schema structure to create form fields.
3286
3316
  *
@@ -3454,6 +3484,25 @@ class FormGroup {
3454
3484
  constructor() {
3455
3485
  this.forms = new Map();
3456
3486
  }
3487
+ /**
3488
+ * Creates an empty form with given index
3489
+ *
3490
+ * @param {string} options.index
3491
+ * @param {TMapper<unknown>} options.mappers
3492
+ */
3493
+ createFormWithIndex({
3494
+ index,
3495
+ mappers
3496
+ }) {
3497
+ const formInstance = new FormCore({
3498
+ index,
3499
+ mappers
3500
+ });
3501
+ this.addForm({
3502
+ key: index,
3503
+ formInstance
3504
+ });
3505
+ }
3457
3506
  /**
3458
3507
  * Adds a form instance to the form group.
3459
3508
  *
@@ -3496,6 +3545,20 @@ class FormGroup {
3496
3545
  (_a = this.forms.get(key)) === null || _a === void 0 ? void 0 : _a.destroy();
3497
3546
  this.forms.delete(key);
3498
3547
  }
3548
+ /**
3549
+ * removes a field given a form and field index
3550
+ *
3551
+ * @param {string} options.formIndex
3552
+ * @param {string} options.fieldIndex
3553
+ */
3554
+ removeField({
3555
+ formIndex,
3556
+ fieldIndex
3557
+ }) {
3558
+ var _a, _b, _c;
3559
+ (_b = (_a = this.forms.get(formIndex)) === null || _a === void 0 ? void 0 : _a.fields.get(fieldIndex)) === null || _b === void 0 ? void 0 : _b.destroyField();
3560
+ (_c = this.forms.get(formIndex)) === null || _c === void 0 ? void 0 : _c.fields.delete(fieldIndex);
3561
+ }
3499
3562
  /**
3500
3563
  * Checks if the specified key already exists in the form group.
3501
3564
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.3",
4
4
  "module": "./index.esm.js",
5
5
  "type": "module",
6
6
  "main": "./index.esm.js",
@@ -11,7 +11,7 @@ declare class FormField {
11
11
  name: string;
12
12
  component: string;
13
13
  path?: string;
14
- children: string[];
14
+ children?: string[];
15
15
  validations?: TEvent<TValidationMethods>;
16
16
  visibilityConditions?: TVisibility[];
17
17
  resetValues?: TResetValueMethods[];
@@ -80,7 +80,7 @@ declare class FormField {
80
80
  schemaComponent: IComponentSchema;
81
81
  config?: TSchemaFormConfig;
82
82
  path?: string;
83
- children: string[];
83
+ children?: string[];
84
84
  validateVisibility: (payload: {
85
85
  event: TEvents;
86
86
  key: string;
@@ -183,6 +183,12 @@ declare class FormCore {
183
183
  event: TEvents;
184
184
  key: string;
185
185
  }): void;
186
+ /**
187
+ * Adds a field onto the form instance regardless there is a schema or not
188
+ *
189
+ * @param fieldSchema
190
+ */
191
+ addField(fieldSchema: IComponentSchema): void;
186
192
  /**
187
193
  * Serializes the schema structure to create form fields.
188
194
  *
@@ -1,5 +1,6 @@
1
1
  import { TFormValues } from '../types/form';
2
- import { TFormCore } from './form';
2
+ import { TMapper } from '../types/mapper';
3
+ import { FormCore, TFormCore } from './form';
3
4
  /**
4
5
  * Represents a group that manages multiple forms.
5
6
  */
@@ -9,6 +10,16 @@ declare class FormGroup {
9
10
  * Creates an instance of FormGroup.
10
11
  */
11
12
  constructor();
13
+ /**
14
+ * Creates an empty form with given index
15
+ *
16
+ * @param {string} options.index
17
+ * @param {TMapper<unknown>} options.mappers
18
+ */
19
+ createFormWithIndex({ index, mappers, }: {
20
+ index: string;
21
+ mappers: TMapper<unknown>[];
22
+ }): void;
12
23
  /**
13
24
  * Adds a form instance to the form group.
14
25
  *
@@ -29,7 +40,7 @@ declare class FormGroup {
29
40
  */
30
41
  getForm({ key }: {
31
42
  key: string;
32
- }): import("./form").FormCore | undefined;
43
+ }): FormCore | undefined;
33
44
  /**
34
45
  * Removes a form instance from the form group.
35
46
  *
@@ -39,6 +50,16 @@ declare class FormGroup {
39
50
  removeForm({ key }: {
40
51
  key: string;
41
52
  }): void;
53
+ /**
54
+ * removes a field given a form and field index
55
+ *
56
+ * @param {string} options.formIndex
57
+ * @param {string} options.fieldIndex
58
+ */
59
+ removeField({ formIndex, fieldIndex }: {
60
+ formIndex: string;
61
+ fieldIndex: string;
62
+ }): void;
42
63
  /**
43
64
  * Checks if the specified key already exists in the form group.
44
65
  *