@stemy/ngx-dynamic-form 13.1.19 → 13.1.20
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/esm2020/ngx-dynamic-form/common-types.mjs +1 -1
- package/esm2020/ngx-dynamic-form/services/dynamic-form.service.mjs +20 -12
- package/fesm2015/stemy-ngx-dynamic-form.mjs +79 -63
- package/fesm2015/stemy-ngx-dynamic-form.mjs.map +1 -1
- package/fesm2020/stemy-ngx-dynamic-form.mjs +19 -11
- package/fesm2020/stemy-ngx-dynamic-form.mjs.map +1 -1
- package/ngx-dynamic-form/common-types.d.ts +3 -2
- package/ngx-dynamic-form/services/dynamic-form.service.d.ts +4 -4
- package/package.json +1 -1
|
@@ -634,7 +634,7 @@ class DynamicFormService extends DynamicFormService$1 {
|
|
|
634
634
|
return __awaiter(this, void 0, void 0, function* () {
|
|
635
635
|
this.api.cache = {};
|
|
636
636
|
this.schemas = yield this.openApi.getSchemas();
|
|
637
|
-
const customizeModels = (property, schema, modelType, config) => {
|
|
637
|
+
const customizeModels = (property, schema, modelType, config) => __awaiter(this, void 0, void 0, function* () {
|
|
638
638
|
const model = new modelType(config);
|
|
639
639
|
if (model instanceof DynamicFormValueControlModel) {
|
|
640
640
|
model.value = (model instanceof DynamicDatePickerModel)
|
|
@@ -642,22 +642,30 @@ class DynamicFormService extends DynamicFormService$1 {
|
|
|
642
642
|
}
|
|
643
643
|
if (!ObjectUtils.isFunction(customizeModel))
|
|
644
644
|
return [model];
|
|
645
|
-
|
|
645
|
+
let res = customizeModel(property, schema, model, config, this.injector);
|
|
646
|
+
if (!res)
|
|
647
|
+
return [model];
|
|
648
|
+
if (res instanceof Promise) {
|
|
649
|
+
res = yield res;
|
|
650
|
+
}
|
|
646
651
|
return Array.isArray(res) ? res : [res];
|
|
647
|
-
};
|
|
652
|
+
});
|
|
648
653
|
return this.getFormModelForSchemaDef(this.schemas[name], customizeModels);
|
|
649
654
|
});
|
|
650
655
|
}
|
|
651
656
|
getFormModelForSchemaDef(schema, customizeModels) {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
657
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
658
|
+
if (!schema)
|
|
659
|
+
return [];
|
|
660
|
+
const keys = Object.keys(schema.properties || {});
|
|
661
|
+
const controls = [];
|
|
662
|
+
for (const p of keys) {
|
|
663
|
+
const property = schema.properties[p];
|
|
664
|
+
const models = yield this.getFormControlModels(property, schema, customizeModels);
|
|
665
|
+
controls.push(...models);
|
|
666
|
+
}
|
|
667
|
+
return controls.filter(t => null !== t);
|
|
668
|
+
});
|
|
661
669
|
}
|
|
662
670
|
checkIsEditorProperty(property) {
|
|
663
671
|
if (!property.format)
|
|
@@ -666,43 +674,45 @@ class DynamicFormService extends DynamicFormService$1 {
|
|
|
666
674
|
}
|
|
667
675
|
getFormControlModels(property, schema, customizeModels) {
|
|
668
676
|
var _a;
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
case "object":
|
|
689
|
-
return customizeModels(property, schema, DynamicEditorModel, this.getFormEditorConfig(property, schema));
|
|
690
|
-
case "boolean":
|
|
691
|
-
return customizeModels(property, schema, DynamicCheckboxModel, this.getFormCheckboxConfig(property, schema));
|
|
692
|
-
case "array":
|
|
693
|
-
if (findRefs(property).length > 0) {
|
|
694
|
-
return customizeModels(property, schema, DynamicFormArrayModel, this.getFormArrayConfig(property, schema, customizeModels));
|
|
695
|
-
}
|
|
696
|
-
else {
|
|
677
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
678
|
+
const $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
|
|
679
|
+
if (Array.isArray($enum) || isStringWithVal(property.optionsPath) || isStringWithVal(property.endpoint)) {
|
|
680
|
+
return customizeModels(property, schema, DynamicSelectModel, this.getFormSelectConfig(property, schema));
|
|
681
|
+
}
|
|
682
|
+
switch (property.type) {
|
|
683
|
+
case "string":
|
|
684
|
+
case "number":
|
|
685
|
+
case "integer":
|
|
686
|
+
case "textarea":
|
|
687
|
+
if (this.checkIsEditorProperty(property)) {
|
|
688
|
+
return customizeModels(property, schema, DynamicEditorModel, this.getFormEditorConfig(property, schema));
|
|
689
|
+
}
|
|
690
|
+
if (property.format == "textarea") {
|
|
691
|
+
return customizeModels(property, schema, DynamicTextAreaModel, this.getFormTextareaConfig(property, schema));
|
|
692
|
+
}
|
|
693
|
+
if (property.format == "date") {
|
|
694
|
+
return customizeModels(property, schema, DynamicDatePickerModel, this.getFormDatepickerConfig(property, schema));
|
|
695
|
+
}
|
|
697
696
|
return customizeModels(property, schema, DynamicInputModel, this.getFormInputConfig(property, schema));
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
697
|
+
case "object":
|
|
698
|
+
return customizeModels(property, schema, DynamicEditorModel, this.getFormEditorConfig(property, schema));
|
|
699
|
+
case "boolean":
|
|
700
|
+
return customizeModels(property, schema, DynamicCheckboxModel, this.getFormCheckboxConfig(property, schema));
|
|
701
|
+
case "array":
|
|
702
|
+
if (findRefs(property).length > 0) {
|
|
703
|
+
return customizeModels(property, schema, DynamicFormArrayModel, yield this.getFormArrayConfig(property, schema, customizeModels));
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
return customizeModels(property, schema, DynamicInputModel, this.getFormInputConfig(property, schema));
|
|
707
|
+
}
|
|
708
|
+
case "file":
|
|
709
|
+
return customizeModels(property, schema, DynamicFileUploadModel, this.getFormUploadConfig(property, schema));
|
|
710
|
+
}
|
|
711
|
+
if (findRefs(property).length > 0) {
|
|
712
|
+
return customizeModels(property, schema, DynamicFormGroupModel, yield this.getFormGroupConfig(property, schema, customizeModels));
|
|
713
|
+
}
|
|
714
|
+
return [];
|
|
715
|
+
});
|
|
706
716
|
}
|
|
707
717
|
findModelByPath(parent, path) {
|
|
708
718
|
if (path.length == 0)
|
|
@@ -736,24 +746,30 @@ class DynamicFormService extends DynamicFormService$1 {
|
|
|
736
746
|
};
|
|
737
747
|
}
|
|
738
748
|
getFormArrayConfig(property, schema, customizeModels) {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
749
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
750
|
+
const subSchemas = findRefs(property).map(ref => this.schemas[ref]);
|
|
751
|
+
const subModels = yield Promise.all(subSchemas.map(s => this.getFormModelForSchemaDef(s, customizeModels)));
|
|
752
|
+
return Object.assign(this.getFormControlConfig(property, schema), {
|
|
753
|
+
groupFactory: () => mergeFormModels(ObjectUtils.copy(subModels)),
|
|
754
|
+
initialCount: property.initialCount || 0,
|
|
755
|
+
sortable: property.sortable || false,
|
|
756
|
+
useTabs: property.useTabs || false,
|
|
757
|
+
addItem: property.addItem !== false,
|
|
758
|
+
insertItem: property.insertItem !== false,
|
|
759
|
+
cloneItem: property.cloneItem !== false,
|
|
760
|
+
moveItem: property.moveItem !== false,
|
|
761
|
+
removeItem: property.removeItem !== false,
|
|
762
|
+
clearItems: property.clearItems !== false
|
|
763
|
+
});
|
|
751
764
|
});
|
|
752
765
|
}
|
|
753
766
|
getFormGroupConfig(property, schema, customizeModels) {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
767
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
768
|
+
const subSchemas = findRefs(property).map(ref => this.schemas[ref]);
|
|
769
|
+
const subModels = yield Promise.all(subSchemas.map(s => this.getFormModelForSchemaDef(s, customizeModels)));
|
|
770
|
+
return Object.assign(this.getFormControlConfig(property, schema), {
|
|
771
|
+
group: mergeFormModels(subModels)
|
|
772
|
+
});
|
|
757
773
|
});
|
|
758
774
|
}
|
|
759
775
|
getFormInputConfig(property, schema) {
|