@stemy/ngx-dynamic-form 10.2.28 → 10.2.29
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/bundles/stemy-ngx-dynamic-form.umd.js +76 -92
- package/bundles/stemy-ngx-dynamic-form.umd.js.map +1 -1
- package/bundles/stemy-ngx-dynamic-form.umd.min.js +1 -1
- package/bundles/stemy-ngx-dynamic-form.umd.min.js.map +1 -1
- package/esm2015/ngx-dynamic-form/common-types.js +26 -63
- package/esm2015/ngx-dynamic-form/services/dynamic-form.service.js +32 -22
- package/esm2015/ngx-dynamic-form/utils/form-select-subject.js +3 -1
- package/esm2015/public_api.js +2 -2
- package/fesm2015/stemy-ngx-dynamic-form.js +60 -84
- package/fesm2015/stemy-ngx-dynamic-form.js.map +1 -1
- package/ngx-dynamic-form/common-types.d.ts +25 -95
- package/ngx-dynamic-form/services/dynamic-form.service.d.ts +6 -5
- package/package.json +1 -1
- package/public_api.d.ts +1 -1
- package/stemy-ngx-dynamic-form.metadata.json +1 -1
|
@@ -5,11 +5,6 @@
|
|
|
5
5
|
}(this, (function (exports, ngxUtils, rxjs, core$1, forms, core, operators, common) { 'use strict';
|
|
6
6
|
|
|
7
7
|
// --- Decorator functions ---
|
|
8
|
-
var emptyArray = [];
|
|
9
|
-
var emptyTester = function () {
|
|
10
|
-
return Promise.resolve(false);
|
|
11
|
-
};
|
|
12
|
-
var ɵ0 = emptyTester;
|
|
13
8
|
function defaultSerializer(id, parent) {
|
|
14
9
|
var control = parent.get(id);
|
|
15
10
|
return !control ? null : control.value;
|
|
@@ -55,85 +50,54 @@
|
|
|
55
50
|
defineFormControl(target, propertyKey, createFormFile(propertyKey, data));
|
|
56
51
|
};
|
|
57
52
|
}
|
|
58
|
-
function FormFieldSet(data) {
|
|
59
|
-
return function (target) {
|
|
60
|
-
var sets = getFormFieldSets(target);
|
|
61
|
-
data.classes = data.classes || "";
|
|
62
|
-
sets[data.id] = data;
|
|
63
|
-
ngxUtils.ReflectUtils.defineMetadata("dynamicFormFieldSets", sets, target);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
53
|
function defineFormControl(target, propertyKey, control) {
|
|
67
54
|
ngxUtils.ReflectUtils.defineMetadata("dynamicFormControl", control, target, propertyKey);
|
|
68
55
|
}
|
|
69
|
-
function getFormFieldSets(target) {
|
|
70
|
-
return ngxUtils.ReflectUtils.getMetadata("dynamicFormFieldSets", target) || {};
|
|
71
|
-
}
|
|
72
56
|
function getFormControl(target, propertyKey) {
|
|
73
57
|
return ngxUtils.ReflectUtils.getMetadata("dynamicFormControl", target, propertyKey);
|
|
74
58
|
}
|
|
75
59
|
function getFormSerializer(target, propertyKey) {
|
|
76
60
|
return ngxUtils.ReflectUtils.getMetadata("dynamicFormSerializer", target, propertyKey);
|
|
77
61
|
}
|
|
78
|
-
function createFormControl(id, type,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
data.hidden = data.hidden || emptyTester;
|
|
86
|
-
data.validators = data.validators || emptyArray;
|
|
87
|
-
return {
|
|
88
|
-
id: id,
|
|
89
|
-
type: type,
|
|
90
|
-
data: data
|
|
91
|
-
};
|
|
62
|
+
function createFormControl(id, type, config) {
|
|
63
|
+
config = config || { id: id };
|
|
64
|
+
config.id = id;
|
|
65
|
+
config.label = ngxUtils.ObjectUtils.isNullOrUndefined(config.label) ? id : config.label;
|
|
66
|
+
config.disabled = config.disabled || false;
|
|
67
|
+
config.hidden = config.hidden || false;
|
|
68
|
+
return { id: id, type: type, config: config };
|
|
92
69
|
}
|
|
93
|
-
function createFormInput(id,
|
|
70
|
+
function createFormInput(id, config, type) {
|
|
94
71
|
if (type === void 0) { type = "text"; }
|
|
95
|
-
var control = createFormControl(id, "input",
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
data.mask = data.mask || [/\w*/gi];
|
|
72
|
+
var control = createFormControl(id, "input", config);
|
|
73
|
+
config = control.config;
|
|
74
|
+
config.inputType = config.inputType || type;
|
|
75
|
+
config.placeholder = config.placeholder || (config.inputType == "mask" ? "_" : "");
|
|
76
|
+
config.step = config.step || 1;
|
|
77
|
+
config.mask = config.mask || [/\w*/gi];
|
|
102
78
|
return control;
|
|
103
79
|
}
|
|
104
80
|
function createFormSelect(id, data) {
|
|
105
81
|
var control = createFormControl(id, "select", data);
|
|
106
|
-
data = control.
|
|
82
|
+
data = control.config;
|
|
107
83
|
data.options = data.options || [];
|
|
108
|
-
data.type = data.type || "select";
|
|
109
|
-
var classType = data.type == "select" ? "select" : "select-" + data.type;
|
|
110
|
-
data.classes = !data.classes ? "form-group-" + classType : data.classes + " form-group-" + classType;
|
|
111
84
|
return control;
|
|
112
85
|
}
|
|
113
|
-
function createFormStatic(id,
|
|
114
|
-
|
|
115
|
-
data = control.data;
|
|
116
|
-
data.style = data.style || "table";
|
|
117
|
-
return control;
|
|
86
|
+
function createFormStatic(id, config) {
|
|
87
|
+
return createFormControl(id, "static", config);
|
|
118
88
|
}
|
|
119
89
|
function createFormModel(id, data) {
|
|
120
|
-
var control = createFormControl(id, "
|
|
121
|
-
data = control.
|
|
90
|
+
var control = createFormControl(id, "group", data);
|
|
91
|
+
data = control.config;
|
|
122
92
|
data.name = data.name || "";
|
|
123
93
|
return control;
|
|
124
94
|
}
|
|
125
95
|
function createFormFile(id, data) {
|
|
126
96
|
var control = createFormControl(id, "file", data);
|
|
127
|
-
data = control.
|
|
128
|
-
data.accept = data.accept || "
|
|
129
|
-
data.
|
|
130
|
-
data.
|
|
131
|
-
data.uploadUrl = ngxUtils.ObjectUtils.isString(data.uploadUrl) ? data.uploadUrl : "assets";
|
|
132
|
-
data.createUploadData = data.createUploadData || (function (file) {
|
|
133
|
-
var form = new FormData();
|
|
134
|
-
form.append("file", file);
|
|
135
|
-
return form;
|
|
136
|
-
});
|
|
97
|
+
data = control.config;
|
|
98
|
+
data.accept = data.accept || ["jpg", "jpeg", "png"];
|
|
99
|
+
data.multiple = data.multiple || false;
|
|
100
|
+
data.url = ngxUtils.ObjectUtils.isString(data.url) ? data.url : "assets";
|
|
137
101
|
return control;
|
|
138
102
|
}
|
|
139
103
|
|
|
@@ -555,6 +519,8 @@
|
|
|
555
519
|
val.then(function (options) {
|
|
556
520
|
var _a, _b;
|
|
557
521
|
_this.next(options);
|
|
522
|
+
if (options.length == 0)
|
|
523
|
+
return;
|
|
558
524
|
var currentVal = control.value;
|
|
559
525
|
if (controlModel.multiple) {
|
|
560
526
|
var correctVal = (currentVal || []).filter(function (t) { return options.findIndex(function (o) { return o.value == t; }) >= 0; });
|
|
@@ -808,9 +774,9 @@
|
|
|
808
774
|
}
|
|
809
775
|
});
|
|
810
776
|
};
|
|
811
|
-
DynamicFormService.prototype.getFormModelForSchema = function (name) {
|
|
777
|
+
DynamicFormService.prototype.getFormModelForSchema = function (name, customizeModel) {
|
|
812
778
|
return __awaiter(this, void 0, void 0, function () {
|
|
813
|
-
var _c;
|
|
779
|
+
var _c, customizeModels;
|
|
814
780
|
return __generator(this, function (_d) {
|
|
815
781
|
switch (_d.label) {
|
|
816
782
|
case 0:
|
|
@@ -819,49 +785,69 @@
|
|
|
819
785
|
return [4 /*yield*/, this.openApi.getSchemas()];
|
|
820
786
|
case 1:
|
|
821
787
|
_c.schemas = _d.sent();
|
|
822
|
-
|
|
788
|
+
customizeModels = function (property, schema, modelType, config) {
|
|
789
|
+
var model = new modelType(config);
|
|
790
|
+
if (!ngxUtils.ObjectUtils.isFunction(customizeModel))
|
|
791
|
+
return [model];
|
|
792
|
+
var res = customizeModel(property, schema, model, config);
|
|
793
|
+
return Array.isArray(res) ? res : [res];
|
|
794
|
+
};
|
|
795
|
+
return [2 /*return*/, this.getFormModelForSchemaDef(this.schemas[name], customizeModels)];
|
|
823
796
|
}
|
|
824
797
|
});
|
|
825
798
|
});
|
|
826
799
|
};
|
|
827
|
-
DynamicFormService.prototype.getFormModelForSchemaDef = function (schema) {
|
|
828
|
-
var
|
|
800
|
+
DynamicFormService.prototype.getFormModelForSchemaDef = function (schema, customizeModels) {
|
|
801
|
+
var e_1, _c;
|
|
829
802
|
if (!schema)
|
|
830
803
|
return [];
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
804
|
+
var keys = Object.keys(schema.properties || {});
|
|
805
|
+
var controls = [];
|
|
806
|
+
try {
|
|
807
|
+
for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
|
|
808
|
+
var p = keys_1_1.value;
|
|
809
|
+
var property = schema.properties[p];
|
|
810
|
+
controls.push.apply(controls, __spread(this.getFormControlModels(property, schema, customizeModels)));
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
814
|
+
finally {
|
|
815
|
+
try {
|
|
816
|
+
if (keys_1_1 && !keys_1_1.done && (_c = keys_1.return)) _c.call(keys_1);
|
|
817
|
+
}
|
|
818
|
+
finally { if (e_1) throw e_1.error; }
|
|
819
|
+
}
|
|
820
|
+
return controls.filter(function (t) { return null !== t; });
|
|
835
821
|
};
|
|
836
|
-
DynamicFormService.prototype.
|
|
822
|
+
DynamicFormService.prototype.getFormControlModels = function (property, schema, customizeModels) {
|
|
837
823
|
var _a, _b;
|
|
838
824
|
var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
|
|
839
825
|
if (Array.isArray($enum) || isStringWithVal(property.optionsPath) || isStringWithVal(property.endpoint)) {
|
|
840
|
-
return
|
|
826
|
+
return customizeModels(property, schema, core.DynamicSelectModel, this.getFormSelectConfig(property, schema));
|
|
841
827
|
}
|
|
842
828
|
switch (property.type) {
|
|
843
829
|
case "string":
|
|
844
830
|
case "number":
|
|
845
831
|
case "integer":
|
|
846
|
-
return
|
|
832
|
+
return customizeModels(property, schema, core.DynamicInputModel, this.getFormInputConfig(property, schema));
|
|
847
833
|
case "textarea":
|
|
848
|
-
return
|
|
834
|
+
return customizeModels(property, schema, core.DynamicTextAreaModel, this.getFormTextareaConfig(property, schema));
|
|
849
835
|
case "boolean":
|
|
850
|
-
return
|
|
836
|
+
return customizeModels(property, schema, core.DynamicCheckboxModel, this.getFormCheckboxConfig(property, schema));
|
|
851
837
|
case "array":
|
|
852
838
|
if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.$ref) || property.$ref) {
|
|
853
|
-
return
|
|
839
|
+
return customizeModels(property, schema, DynamicFormArrayModel, this.getFormArrayConfig(property, schema, customizeModels));
|
|
854
840
|
}
|
|
855
841
|
else {
|
|
856
|
-
return
|
|
842
|
+
return customizeModels(property, schema, core.DynamicInputModel, this.getFormInputConfig(property, schema));
|
|
857
843
|
}
|
|
858
844
|
case "file":
|
|
859
|
-
return
|
|
845
|
+
return customizeModels(property, schema, core.DynamicFileUploadModel, this.getFormUploadConfig(property, schema));
|
|
860
846
|
}
|
|
861
847
|
if (property.$ref) {
|
|
862
|
-
return
|
|
848
|
+
return customizeModels(property, schema, core.DynamicFormGroupModel, this.getFormGroupConfig(property, schema, customizeModels));
|
|
863
849
|
}
|
|
864
|
-
return
|
|
850
|
+
return [];
|
|
865
851
|
};
|
|
866
852
|
DynamicFormService.prototype.getFormControlConfig = function (property, schema) {
|
|
867
853
|
var validators = this.getValidators(property, schema);
|
|
@@ -879,17 +865,17 @@
|
|
|
879
865
|
additional: Object.assign({}, property)
|
|
880
866
|
};
|
|
881
867
|
};
|
|
882
|
-
DynamicFormService.prototype.getFormArrayConfig = function (property, schema) {
|
|
868
|
+
DynamicFormService.prototype.getFormArrayConfig = function (property, schema, customizeModels) {
|
|
883
869
|
var _this = this;
|
|
884
870
|
var _a;
|
|
885
871
|
var ref = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref) || property.$ref || "";
|
|
886
872
|
var subSchema = this.schemas[ref.split("/").pop()];
|
|
887
|
-
return Object.assign(this.getFormControlConfig(property, schema), { groupFactory: function () { return _this.getFormModelForSchemaDef(subSchema); } });
|
|
873
|
+
return Object.assign(this.getFormControlConfig(property, schema), { groupFactory: function () { return _this.getFormModelForSchemaDef(subSchema, customizeModels); } });
|
|
888
874
|
};
|
|
889
|
-
DynamicFormService.prototype.getFormGroupConfig = function (property, schema) {
|
|
875
|
+
DynamicFormService.prototype.getFormGroupConfig = function (property, schema, customizeModels) {
|
|
890
876
|
var ref = property.$ref || "";
|
|
891
877
|
var subSchema = this.schemas[ref.split("/").pop()];
|
|
892
|
-
return Object.assign(this.getFormControlConfig(property, schema), { group: this.getFormModelForSchemaDef(subSchema) });
|
|
878
|
+
return Object.assign(this.getFormControlConfig(property, schema), { group: this.getFormModelForSchemaDef(subSchema, customizeModels) });
|
|
893
879
|
};
|
|
894
880
|
DynamicFormService.prototype.getFormInputConfig = function (property, schema) {
|
|
895
881
|
var _a;
|
|
@@ -942,8 +928,8 @@
|
|
|
942
928
|
};
|
|
943
929
|
DynamicFormService.prototype.translateOptions = function (options) {
|
|
944
930
|
return __awaiter(this, void 0, void 0, function () {
|
|
945
|
-
var options_1, options_1_1, option, _c,
|
|
946
|
-
var
|
|
931
|
+
var options_1, options_1_1, option, _c, e_2_1;
|
|
932
|
+
var e_2, _d;
|
|
947
933
|
return __generator(this, function (_e) {
|
|
948
934
|
switch (_e.label) {
|
|
949
935
|
case 0:
|
|
@@ -967,14 +953,14 @@
|
|
|
967
953
|
return [3 /*break*/, 2];
|
|
968
954
|
case 5: return [3 /*break*/, 8];
|
|
969
955
|
case 6:
|
|
970
|
-
|
|
971
|
-
|
|
956
|
+
e_2_1 = _e.sent();
|
|
957
|
+
e_2 = { error: e_2_1 };
|
|
972
958
|
return [3 /*break*/, 8];
|
|
973
959
|
case 7:
|
|
974
960
|
try {
|
|
975
961
|
if (options_1_1 && !options_1_1.done && (_d = options_1.return)) _d.call(options_1);
|
|
976
962
|
}
|
|
977
|
-
finally { if (
|
|
963
|
+
finally { if (e_2) throw e_2.error; }
|
|
978
964
|
return [7 /*endfinally*/];
|
|
979
965
|
case 8: return [2 /*return*/, options];
|
|
980
966
|
}
|
|
@@ -988,7 +974,7 @@
|
|
|
988
974
|
if (Array.isArray($enum)) {
|
|
989
975
|
return new FormSelectSubject(function () {
|
|
990
976
|
var options = $enum.map(function (value) {
|
|
991
|
-
var label = property.translatable ? property.id + "." + value : value;
|
|
977
|
+
var label = property.translatable ? property.id + "." + value : "" + value;
|
|
992
978
|
return { value: value, label: label };
|
|
993
979
|
});
|
|
994
980
|
return _this.translateOptions(options);
|
|
@@ -1598,7 +1584,7 @@
|
|
|
1598
1584
|
];
|
|
1599
1585
|
// --- Pipes ---
|
|
1600
1586
|
var pipes = [];
|
|
1601
|
-
var ɵ0
|
|
1587
|
+
var ɵ0 = validateJSON, ɵ1 = validateRequiredTranslation, ɵ2 = validateItemsMinLength, ɵ3 = validateItemsMaxLength, ɵ4 = validateItemsMinValue, ɵ5 = validateItemsMaxValue, ɵ6 = new Map([
|
|
1602
1588
|
["json", validateJSON],
|
|
1603
1589
|
["requiredTranslation", validateRequiredTranslation],
|
|
1604
1590
|
["phone", validatePhone],
|
|
@@ -1640,7 +1626,7 @@
|
|
|
1640
1626
|
]),
|
|
1641
1627
|
entryComponents: components,
|
|
1642
1628
|
providers: __spread(pipes, [
|
|
1643
|
-
{ provide: forms.NG_VALIDATORS, useValue: ɵ0
|
|
1629
|
+
{ provide: forms.NG_VALIDATORS, useValue: ɵ0, multi: true },
|
|
1644
1630
|
{ provide: forms.NG_VALIDATORS, useValue: ɵ1, multi: true },
|
|
1645
1631
|
{ provide: forms.NG_VALIDATORS, useValue: ɵ2, multi: true },
|
|
1646
1632
|
{ provide: forms.NG_VALIDATORS, useValue: ɵ3, multi: true },
|
|
@@ -1664,7 +1650,6 @@
|
|
|
1664
1650
|
exports.DynamicBaseFormControlContainerComponent = DynamicBaseFormControlContainerComponent;
|
|
1665
1651
|
exports.DynamicBaseFormGroupComponent = DynamicBaseFormGroupComponent;
|
|
1666
1652
|
exports.DynamicFormService = DynamicFormService;
|
|
1667
|
-
exports.FormFieldSet = FormFieldSet;
|
|
1668
1653
|
exports.FormFile = FormFile;
|
|
1669
1654
|
exports.FormInput = FormInput;
|
|
1670
1655
|
exports.FormModel = FormModel;
|
|
@@ -1682,7 +1667,6 @@
|
|
|
1682
1667
|
exports.defaultSerializer = defaultSerializer;
|
|
1683
1668
|
exports.defineFormControl = defineFormControl;
|
|
1684
1669
|
exports.getFormControl = getFormControl;
|
|
1685
|
-
exports.getFormFieldSets = getFormFieldSets;
|
|
1686
1670
|
exports.getFormSerializer = getFormSerializer;
|
|
1687
1671
|
exports.validateItemsMaxLength = validateItemsMaxLength;
|
|
1688
1672
|
exports.validateItemsMaxValue = validateItemsMaxValue;
|