@stemy/ngx-dynamic-form 10.2.25 → 10.2.28

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.
Files changed (32) hide show
  1. package/bundles/stemy-ngx-dynamic-form.umd.js +213 -64
  2. package/bundles/stemy-ngx-dynamic-form.umd.js.map +1 -1
  3. package/bundles/stemy-ngx-dynamic-form.umd.min.js +1 -1
  4. package/bundles/stemy-ngx-dynamic-form.umd.min.js.map +1 -1
  5. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form-array.component.js +53 -0
  6. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form-control-container.component.js +13 -2
  7. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form-group.component.js +53 -0
  8. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form.component.js +12 -2
  9. package/esm2015/ngx-dynamic-form/ngx-dynamic-form.module.js +8 -10
  10. package/esm2015/ngx-dynamic-form/services/dynamic-form.service.js +24 -24
  11. package/esm2015/ngx-dynamic-form/utils/form-select-subject.js +22 -0
  12. package/esm2015/ngx-dynamic-form/utils/form-subject.js +13 -9
  13. package/esm2015/ngx-dynamic-form/utils/misc.js +18 -0
  14. package/esm2015/public_api.js +5 -2
  15. package/esm2015/stemy-ngx-dynamic-form.js +2 -4
  16. package/fesm2015/stemy-ngx-dynamic-form.js +194 -45
  17. package/fesm2015/stemy-ngx-dynamic-form.js.map +1 -1
  18. package/ngx-dynamic-form/components/base/dynamic-base-form-array.component.d.ts +20 -0
  19. package/ngx-dynamic-form/components/base/dynamic-base-form-control-container.component.d.ts +1 -0
  20. package/ngx-dynamic-form/components/base/dynamic-base-form-group.component.d.ts +20 -0
  21. package/ngx-dynamic-form/components/base/dynamic-base-form.component.d.ts +2 -1
  22. package/ngx-dynamic-form/ngx-dynamic-form.module.d.ts +3 -1
  23. package/ngx-dynamic-form/services/dynamic-form.service.d.ts +2 -2
  24. package/ngx-dynamic-form/utils/form-select-subject.d.ts +6 -0
  25. package/ngx-dynamic-form/utils/form-subject.d.ts +3 -2
  26. package/ngx-dynamic-form/utils/misc.d.ts +3 -0
  27. package/package.json +1 -1
  28. package/public_api.d.ts +4 -1
  29. package/stemy-ngx-dynamic-form.d.ts +1 -3
  30. package/stemy-ngx-dynamic-form.metadata.json +1 -1
  31. package/esm2015/ngx-dynamic-form/services/dynamic-form-validation.service.js +0 -11
  32. package/ngx-dynamic-form/services/dynamic-form-validation.service.d.ts +0 -5
@@ -527,28 +527,69 @@
527
527
  _this.notifyCallback = notifyCallback;
528
528
  return _this;
529
529
  }
530
+ FormSubject.prototype.handleNotifiedValue = function (controlModel, control, val) {
531
+ var _this = this;
532
+ val.then(function (v) { return _this.next(v); });
533
+ };
530
534
  FormSubject.prototype.notify = function (controlModel, control) {
531
- return __awaiter(this, void 0, void 0, function () {
532
- var value;
533
- return __generator(this, function (_a) {
534
- switch (_a.label) {
535
- case 0:
536
- value = this.notifyCallback(controlModel, control);
537
- if (!(value instanceof Promise)) return [3 /*break*/, 2];
538
- return [4 /*yield*/, value];
539
- case 1:
540
- value = _a.sent();
541
- _a.label = 2;
542
- case 2:
543
- this.next(value);
544
- return [2 /*return*/];
545
- }
546
- });
547
- });
535
+ var path = controlModel;
536
+ while (path && isNaN(path.index)) {
537
+ path = path.parent;
538
+ }
539
+ var value = this.notifyCallback(controlModel, control, path === null || path === void 0 ? void 0 : path.index);
540
+ if (!(value instanceof Promise)) {
541
+ value = Promise.resolve(value);
542
+ }
543
+ this.handleNotifiedValue(controlModel, control, value);
548
544
  };
549
545
  return FormSubject;
550
546
  }(rxjs.Subject));
551
547
 
548
+ var FormSelectSubject = /** @class */ (function (_super) {
549
+ __extends(FormSelectSubject, _super);
550
+ function FormSelectSubject() {
551
+ return _super !== null && _super.apply(this, arguments) || this;
552
+ }
553
+ FormSelectSubject.prototype.handleNotifiedValue = function (controlModel, control, val) {
554
+ var _this = this;
555
+ val.then(function (options) {
556
+ var _a, _b;
557
+ _this.next(options);
558
+ var currentVal = control.value;
559
+ if (controlModel.multiple) {
560
+ var correctVal = (currentVal || []).filter(function (t) { return options.findIndex(function (o) { return o.value == t; }) >= 0; });
561
+ if (correctVal.length !== (currentVal === null || currentVal === void 0 ? void 0 : currentVal.length)) {
562
+ control.setValue(correctVal, { onlySelf: true, emitEvent: false });
563
+ }
564
+ return;
565
+ }
566
+ var option = options.find(function (t) { return t.value == currentVal; });
567
+ if (!option) {
568
+ control.setValue((_b = (_a = options[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null, { onlySelf: true, emitEvent: false });
569
+ }
570
+ });
571
+ };
572
+ return FormSelectSubject;
573
+ }(FormSubject));
574
+
575
+ function isStringWithVal(val) {
576
+ return typeof val == "string" && val.length > 0;
577
+ }
578
+ function collectPathAble(start, getter) {
579
+ if (!start || !getter(start))
580
+ return [];
581
+ var parts = [];
582
+ var currentPath = start;
583
+ while (currentPath) {
584
+ var val = getter(currentPath);
585
+ if (val) {
586
+ parts.unshift(val);
587
+ }
588
+ currentPath = currentPath.parent;
589
+ }
590
+ return parts;
591
+ }
592
+
552
593
  var DynamicFormArrayModel = /** @class */ (function (_super) {
553
594
  __extends(DynamicFormArrayModel, _super);
554
595
  function DynamicFormArrayModel(config, layout) {
@@ -794,7 +835,8 @@
794
835
  };
795
836
  DynamicFormService.prototype.getFormControlModel = function (property, schema) {
796
837
  var _a, _b;
797
- if (Array.isArray(property.enum) || ngxUtils.ObjectUtils.isString(property.optionsPath)) {
838
+ var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
839
+ if (Array.isArray($enum) || isStringWithVal(property.optionsPath) || isStringWithVal(property.endpoint)) {
798
840
  return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
799
841
  }
800
842
  switch (property.type) {
@@ -806,15 +848,10 @@
806
848
  return new core.DynamicTextAreaModel(this.getFormTextareaConfig(property, schema));
807
849
  case "boolean":
808
850
  return new core.DynamicCheckboxModel(this.getFormCheckboxConfig(property, schema));
809
- case "list":
810
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
811
851
  case "array":
812
- if (((_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref) || property.$ref) {
852
+ if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.$ref) || property.$ref) {
813
853
  return new DynamicFormArrayModel(this.getFormArrayConfig(property, schema));
814
854
  }
815
- else if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.enum) || property.enum) {
816
- return new core.DynamicSelectModel(this.getFormSelectConfig(property, schema));
817
- }
818
855
  else {
819
856
  return new core.DynamicInputModel(this.getFormInputConfig(property, schema));
820
857
  }
@@ -877,8 +914,10 @@
877
914
  mask: ngxUtils.ObjectUtils.isString(property.mask) ? property.mask : null,
878
915
  pattern: ngxUtils.ObjectUtils.isString(property.pattern) ? property.pattern : null,
879
916
  step: isNaN(sub.step) ? (isNaN(property.step) ? 1 : property.step) : sub.step,
880
- min: isNaN(sub.minimum) ? (isNaN(sub.minLength) ? Number.MIN_SAFE_INTEGER : sub.minLength) : sub.minimum,
881
- max: isNaN(sub.maximum) ? (isNaN(sub.maxLength) ? Number.MAX_SAFE_INTEGER : sub.maxLength) : sub.maximum
917
+ min: isNaN(sub.minimum) ? Number.MIN_SAFE_INTEGER : sub.minimum,
918
+ max: isNaN(sub.maximum) ? Number.MAX_SAFE_INTEGER : sub.maximum,
919
+ minLength: isNaN(sub.minLength) ? Number.MIN_SAFE_INTEGER : sub.minLength,
920
+ maxLength: isNaN(sub.maxLength) ? Number.MAX_SAFE_INTEGER : sub.maxLength,
882
921
  });
883
922
  };
884
923
  DynamicFormService.prototype.getFormTextareaConfig = function (property, schema) {
@@ -946,8 +985,17 @@
946
985
  var _this = this;
947
986
  var _a;
948
987
  var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
949
- if (property.optionsPath) {
950
- return new FormSubject(function (formModel, control) {
988
+ if (Array.isArray($enum)) {
989
+ return new FormSelectSubject(function () {
990
+ var options = $enum.map(function (value) {
991
+ var label = property.translatable ? property.id + "." + value : value;
992
+ return { value: value, label: label };
993
+ });
994
+ return _this.translateOptions(options);
995
+ });
996
+ }
997
+ if (isStringWithVal(property.optionsPath)) {
998
+ return new FormSelectSubject(function (formModel, control, index) {
951
999
  var path = property.optionsPath;
952
1000
  var target = control;
953
1001
  if (path.startsWith("$root")) {
@@ -962,21 +1010,12 @@
962
1010
  target = target.parent;
963
1011
  }
964
1012
  }
965
- var value = ngxUtils.ObjectUtils.getValue(target.value, path);
1013
+ var value = ngxUtils.ObjectUtils.getValue(target.value, path.replace(/\$ix/gi, index));
966
1014
  var options = (!ngxUtils.ObjectUtils.isArray(value) ? [] : value).map(function (value) { return ({ value: value, label: value }); });
967
1015
  return _this.translateOptions(options);
968
1016
  });
969
1017
  }
970
- if (ngxUtils.ObjectUtils.isArray($enum)) {
971
- return new FormSubject(function () {
972
- var options = $enum.map(function (value) {
973
- var label = property.translatable ? property.id + "." + value : value;
974
- return { value: value, label: label };
975
- });
976
- return _this.translateOptions(options);
977
- });
978
- }
979
- return new FormSubject(function () { return __awaiter(_this, void 0, void 0, function () {
1018
+ return new FormSelectSubject(function () { return __awaiter(_this, void 0, void 0, function () {
980
1019
  var options;
981
1020
  return __generator(this, function (_c) {
982
1021
  switch (_c.label) {
@@ -1246,6 +1285,15 @@
1246
1285
  this.formService.clearFormArray(formArray, formArrayModel);
1247
1286
  this.changeDetectorRef.detectChanges();
1248
1287
  };
1288
+ DynamicBaseFormComponent.prototype.getClass = function (model) {
1289
+ var parts = collectPathAble(model, function (p) { return p.id; });
1290
+ if (parts.length == 0)
1291
+ return "";
1292
+ if (model instanceof core.DynamicFormGroupModel) {
1293
+ return "form-group-" + parts.join("-");
1294
+ }
1295
+ return "form-control-" + parts.join("-");
1296
+ };
1249
1297
  DynamicBaseFormComponent.prototype.validate = function (showErrors) {
1250
1298
  var _this = this;
1251
1299
  if (showErrors === void 0) { showErrors = true; }
@@ -1314,6 +1362,59 @@
1314
1362
  ngForm: [{ type: core$1.ViewChild, args: [forms.NgForm,] }]
1315
1363
  };
1316
1364
 
1365
+ var DynamicBaseFormArrayComponent = /** @class */ (function (_super) {
1366
+ __extends(DynamicBaseFormArrayComponent, _super);
1367
+ function DynamicBaseFormArrayComponent(layoutService, validationService) {
1368
+ var _this = _super.call(this, layoutService, validationService) || this;
1369
+ _this.layoutService = layoutService;
1370
+ _this.validationService = validationService;
1371
+ _this.blur = new core$1.EventEmitter();
1372
+ _this.change = new core$1.EventEmitter();
1373
+ _this.customEvent = new core$1.EventEmitter();
1374
+ _this.focus = new core$1.EventEmitter();
1375
+ return _this;
1376
+ }
1377
+ DynamicBaseFormArrayComponent.prototype.getClass = function (context, place, model) {
1378
+ return [
1379
+ context == "element" ? this.getModelClass(model) : null,
1380
+ _super.prototype.getClass.call(this, context, place, model)
1381
+ ].filter(function (cls) { return !!cls; }).join(" ");
1382
+ };
1383
+ DynamicBaseFormArrayComponent.prototype.getModelClass = function (model) {
1384
+ var parts = collectPathAble(model, function (p) { return p.id; });
1385
+ if (parts.length == 0)
1386
+ return "";
1387
+ if (model instanceof core.DynamicFormGroupModel) {
1388
+ return "form-group-" + parts.join("-");
1389
+ }
1390
+ return "form-control-" + parts.join("-");
1391
+ };
1392
+ return DynamicBaseFormArrayComponent;
1393
+ }(core.DynamicFormArrayComponent));
1394
+ DynamicBaseFormArrayComponent.decorators = [
1395
+ { type: core$1.Component, args: [{
1396
+ selector: "dynamic-base-form-array",
1397
+ template: "",
1398
+ changeDetection: core$1.ChangeDetectionStrategy.OnPush
1399
+ },] }
1400
+ ];
1401
+ DynamicBaseFormArrayComponent.ctorParameters = function () { return [
1402
+ { type: core.DynamicFormLayoutService },
1403
+ { type: core.DynamicFormValidationService }
1404
+ ]; };
1405
+ DynamicBaseFormArrayComponent.propDecorators = {
1406
+ formLayout: [{ type: core$1.Input }],
1407
+ group: [{ type: core$1.Input }],
1408
+ layout: [{ type: core$1.Input }],
1409
+ model: [{ type: core$1.Input }],
1410
+ templates: [{ type: core$1.Input }],
1411
+ blur: [{ type: core$1.Output }],
1412
+ change: [{ type: core$1.Output }],
1413
+ customEvent: [{ type: core$1.Output }],
1414
+ focus: [{ type: core$1.Output }],
1415
+ components: [{ type: core$1.ViewChildren, args: [core$1.forwardRef(function () { return core.DynamicFormControlContainerComponent; }),] }]
1416
+ };
1417
+
1317
1418
  var DynamicBaseFormControlContainerComponent = /** @class */ (function (_super) {
1318
1419
  __extends(DynamicBaseFormControlContainerComponent, _super);
1319
1420
  function DynamicBaseFormControlContainerComponent(form, changeDetectorRef, componentFactoryResolver, layoutService, validationService, componentService, relationService) {
@@ -1377,6 +1478,16 @@
1377
1478
  _super.prototype.ngOnDestroy.call(this);
1378
1479
  this.onDetectChanges.unsubscribe();
1379
1480
  };
1481
+ DynamicBaseFormControlContainerComponent.prototype.getLabel = function () {
1482
+ var _a;
1483
+ var label = collectPathAble(this.model, function (p) { return p.label; });
1484
+ if (label.length == 0)
1485
+ return "";
1486
+ if ((_a = this.form) === null || _a === void 0 ? void 0 : _a.labelPrefix) {
1487
+ label.unshift(this.form.labelPrefix);
1488
+ }
1489
+ return label.join(".");
1490
+ };
1380
1491
  DynamicBaseFormControlContainerComponent.prototype.createFormControlComponent = function () {
1381
1492
  var _a;
1382
1493
  _super.prototype.createFormControlComponent.call(this);
@@ -1421,24 +1532,65 @@
1421
1532
  componentViewContainerRef: [{ type: core$1.ViewChild, args: ["componentViewContainer", { read: core$1.ViewContainerRef, static: true },] }]
1422
1533
  };
1423
1534
 
1424
- var DynamicFormValidationService = /** @class */ (function (_super) {
1425
- __extends(DynamicFormValidationService, _super);
1426
- function DynamicFormValidationService() {
1427
- return _super !== null && _super.apply(this, arguments) || this;
1535
+ var DynamicBaseFormGroupComponent = /** @class */ (function (_super) {
1536
+ __extends(DynamicBaseFormGroupComponent, _super);
1537
+ function DynamicBaseFormGroupComponent(layoutService, validationService) {
1538
+ var _this = _super.call(this, layoutService, validationService) || this;
1539
+ _this.layoutService = layoutService;
1540
+ _this.validationService = validationService;
1541
+ _this.blur = new core$1.EventEmitter();
1542
+ _this.change = new core$1.EventEmitter();
1543
+ _this.customEvent = new core$1.EventEmitter();
1544
+ _this.focus = new core$1.EventEmitter();
1545
+ return _this;
1428
1546
  }
1429
- DynamicFormValidationService.prototype.showErrorMessages = function (control, model, hasFocus) {
1430
- return _super.prototype.showErrorMessages.call(this, control, model, hasFocus);
1547
+ DynamicBaseFormGroupComponent.prototype.getClass = function (context, place, model) {
1548
+ return [
1549
+ context == "element" ? this.getModelClass(model) : null,
1550
+ _super.prototype.getClass.call(this, context, place, model)
1551
+ ].filter(function (cls) { return !!cls; }).join(" ");
1431
1552
  };
1432
- return DynamicFormValidationService;
1433
- }(core.DynamicFormValidationService));
1434
- DynamicFormValidationService.decorators = [
1435
- { type: core$1.Injectable }
1436
- ];
1553
+ DynamicBaseFormGroupComponent.prototype.getModelClass = function (model) {
1554
+ var parts = collectPathAble(model, function (p) { return p.id; });
1555
+ if (parts.length == 0)
1556
+ return "";
1557
+ if (model instanceof core.DynamicFormGroupModel) {
1558
+ return "form-group-" + parts.join("-");
1559
+ }
1560
+ return "form-control-" + parts.join("-");
1561
+ };
1562
+ return DynamicBaseFormGroupComponent;
1563
+ }(core.DynamicFormGroupComponent));
1564
+ DynamicBaseFormGroupComponent.decorators = [
1565
+ { type: core$1.Component, args: [{
1566
+ selector: "dynamic-base-form-group",
1567
+ template: "",
1568
+ changeDetection: core$1.ChangeDetectionStrategy.OnPush
1569
+ },] }
1570
+ ];
1571
+ DynamicBaseFormGroupComponent.ctorParameters = function () { return [
1572
+ { type: core.DynamicFormLayoutService },
1573
+ { type: core.DynamicFormValidationService }
1574
+ ]; };
1575
+ DynamicBaseFormGroupComponent.propDecorators = {
1576
+ formLayout: [{ type: core$1.Input }],
1577
+ group: [{ type: core$1.Input }],
1578
+ layout: [{ type: core$1.Input }],
1579
+ model: [{ type: core$1.Input }],
1580
+ templates: [{ type: core$1.Input }],
1581
+ blur: [{ type: core$1.Output }],
1582
+ change: [{ type: core$1.Output }],
1583
+ customEvent: [{ type: core$1.Output }],
1584
+ focus: [{ type: core$1.Output }],
1585
+ components: [{ type: core$1.ViewChildren, args: [core$1.forwardRef(function () { return core.DynamicFormControlContainerComponent; }),] }]
1586
+ };
1437
1587
 
1438
1588
  // --- Components ---
1439
1589
  var components = [
1440
1590
  DynamicBaseFormComponent,
1441
- DynamicBaseFormControlContainerComponent
1591
+ DynamicBaseFormArrayComponent,
1592
+ DynamicBaseFormControlContainerComponent,
1593
+ DynamicBaseFormGroupComponent
1442
1594
  ];
1443
1595
  // --- Directives ---
1444
1596
  var directives = [
@@ -1463,14 +1615,9 @@
1463
1615
  ngModule: NgxDynamicFormModule,
1464
1616
  providers: [
1465
1617
  DynamicFormService,
1466
- DynamicFormValidationService,
1467
1618
  {
1468
1619
  provide: core.DynamicFormService,
1469
1620
  useExisting: DynamicFormService
1470
- },
1471
- {
1472
- provide: core.DynamicFormValidationService,
1473
- useExisting: DynamicFormValidationService
1474
1621
  }
1475
1622
  ]
1476
1623
  };
@@ -1512,14 +1659,17 @@
1512
1659
  */
1513
1660
 
1514
1661
  exports.AsyncSubmitDirective = AsyncSubmitDirective;
1662
+ exports.DynamicBaseFormArrayComponent = DynamicBaseFormArrayComponent;
1515
1663
  exports.DynamicBaseFormComponent = DynamicBaseFormComponent;
1516
1664
  exports.DynamicBaseFormControlContainerComponent = DynamicBaseFormControlContainerComponent;
1665
+ exports.DynamicBaseFormGroupComponent = DynamicBaseFormGroupComponent;
1517
1666
  exports.DynamicFormService = DynamicFormService;
1518
1667
  exports.FormFieldSet = FormFieldSet;
1519
1668
  exports.FormFile = FormFile;
1520
1669
  exports.FormInput = FormInput;
1521
1670
  exports.FormModel = FormModel;
1522
1671
  exports.FormSelect = FormSelect;
1672
+ exports.FormSelectSubject = FormSelectSubject;
1523
1673
  exports.FormSerializable = FormSerializable;
1524
1674
  exports.FormStatic = FormStatic;
1525
1675
  exports.FormSubject = FormSubject;
@@ -1534,17 +1684,16 @@
1534
1684
  exports.getFormControl = getFormControl;
1535
1685
  exports.getFormFieldSets = getFormFieldSets;
1536
1686
  exports.getFormSerializer = getFormSerializer;
1687
+ exports.validateItemsMaxLength = validateItemsMaxLength;
1688
+ exports.validateItemsMaxValue = validateItemsMaxValue;
1689
+ exports.validateItemsMinLength = validateItemsMinLength;
1690
+ exports.validateItemsMinValue = validateItemsMinValue;
1537
1691
  exports.validateJSON = validateJSON;
1538
1692
  exports.validatePhone = validatePhone;
1539
1693
  exports.validateRequiredTranslation = validateRequiredTranslation;
1540
- exports.ɵa = validateItemsMinLength;
1541
- exports.ɵb = validateItemsMaxLength;
1542
- exports.ɵc = validateItemsMinValue;
1543
- exports.ɵd = validateItemsMaxValue;
1544
- exports.ɵe = components;
1545
- exports.ɵf = directives;
1546
- exports.ɵg = pipes;
1547
- exports.ɵh = DynamicFormValidationService;
1694
+ exports.ɵa = components;
1695
+ exports.ɵb = directives;
1696
+ exports.ɵc = pipes;
1548
1697
 
1549
1698
  Object.defineProperty(exports, '__esModule', { value: true });
1550
1699