@bolttech/form-engine-core 1.0.0-beta.3 → 1.0.0-beta.5
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 +58 -0
- package/package.json +1 -1
- package/src/managers/form.d.ts +6 -0
package/index.esm.js
CHANGED
|
@@ -3769,6 +3769,64 @@ class FormCore {
|
|
|
3769
3769
|
event: 'ON_FIELDS'
|
|
3770
3770
|
});
|
|
3771
3771
|
}
|
|
3772
|
+
static serializeStructure({
|
|
3773
|
+
struct,
|
|
3774
|
+
path,
|
|
3775
|
+
fields = new Map(),
|
|
3776
|
+
mappers
|
|
3777
|
+
}) {
|
|
3778
|
+
if (!struct) return fields;
|
|
3779
|
+
struct.forEach(structElement => {
|
|
3780
|
+
var _a;
|
|
3781
|
+
const currField = fields.get(structElement.name);
|
|
3782
|
+
if (!currField) {
|
|
3783
|
+
let mapper;
|
|
3784
|
+
if (structElement === null || structElement === void 0 ? void 0 : structElement.mapper) {
|
|
3785
|
+
mapper = structElement === null || structElement === void 0 ? void 0 : structElement.mapper;
|
|
3786
|
+
} else {
|
|
3787
|
+
mapper = mappers === null || mappers === void 0 ? void 0 : mappers.find(el => el.componentName === structElement.component);
|
|
3788
|
+
}
|
|
3789
|
+
if (!mapper) throw new Error(`mapper not found for ${structElement.component}, add it to the mappers configuration`);
|
|
3790
|
+
fields.set(structElement.name, new FormField({
|
|
3791
|
+
schemaComponent: structElement,
|
|
3792
|
+
mapper,
|
|
3793
|
+
path,
|
|
3794
|
+
children: structElement.children ? structElement.children.map(el => el.name) : [],
|
|
3795
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
3796
|
+
validateVisibility: () => {},
|
|
3797
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
3798
|
+
resetValue: () => {},
|
|
3799
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
3800
|
+
resetProperty: () => {},
|
|
3801
|
+
templateSubject$: new Subject(),
|
|
3802
|
+
fieldEventSubject$: new Subject(),
|
|
3803
|
+
dataSubject$: new Subject(),
|
|
3804
|
+
formValidNotification$: new Subject(),
|
|
3805
|
+
getFormValues: () => ({
|
|
3806
|
+
erroredFields: [],
|
|
3807
|
+
isValid: false,
|
|
3808
|
+
values: []
|
|
3809
|
+
}),
|
|
3810
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
3811
|
+
submitEvent: () => {}
|
|
3812
|
+
}));
|
|
3813
|
+
} else {
|
|
3814
|
+
currField.children = ((_a = structElement === null || structElement === void 0 ? void 0 : structElement.children) === null || _a === void 0 ? void 0 : _a.map(el => el.name)) || (currField === null || currField === void 0 ? void 0 : currField.children) || [];
|
|
3815
|
+
currField.path = path;
|
|
3816
|
+
currField.originalSchema = structElement;
|
|
3817
|
+
currField.templateSubject$ = new Subject();
|
|
3818
|
+
}
|
|
3819
|
+
if (structElement.children) {
|
|
3820
|
+
this.serializeStructure({
|
|
3821
|
+
fields,
|
|
3822
|
+
path: `${path ? `${path}.` : ``}${structElement.name}`,
|
|
3823
|
+
mappers: mappers,
|
|
3824
|
+
struct: structElement.children
|
|
3825
|
+
});
|
|
3826
|
+
}
|
|
3827
|
+
});
|
|
3828
|
+
return fields;
|
|
3829
|
+
}
|
|
3772
3830
|
/**
|
|
3773
3831
|
* Serializes the schema structure to create form fields.
|
|
3774
3832
|
*
|
package/package.json
CHANGED
package/src/managers/form.d.ts
CHANGED
|
@@ -233,6 +233,12 @@ declare class FormCore {
|
|
|
233
233
|
removeField({ key }: {
|
|
234
234
|
key: string;
|
|
235
235
|
}): void;
|
|
236
|
+
static serializeStructure({ struct, path, fields, mappers, }: {
|
|
237
|
+
struct?: IComponentSchemaAsFormField<unknown>[];
|
|
238
|
+
path?: string;
|
|
239
|
+
fields?: Map<string, IFormField>;
|
|
240
|
+
mappers: TMapper<unknown>[];
|
|
241
|
+
}): Map<string, IFormField>;
|
|
236
242
|
/**
|
|
237
243
|
* Serializes the schema structure to create form fields.
|
|
238
244
|
*
|