@stemy/ngx-dynamic-form 10.2.32 → 10.2.33

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 (29) hide show
  1. package/bundles/stemy-ngx-dynamic-form.umd.js +123 -38
  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/common-types.js +1 -1
  6. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form-array.component.js +32 -6
  7. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form-control-container.component.js +2 -2
  8. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form-group.component.js +14 -2
  9. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form.component.js +6 -5
  10. package/esm2015/ngx-dynamic-form/directives/async-submit.directive.js +1 -1
  11. package/esm2015/ngx-dynamic-form/services/dynamic-form.service.js +43 -14
  12. package/esm2015/ngx-dynamic-form/utils/dynamic-form-array.model.js +9 -1
  13. package/esm2015/ngx-dynamic-form/utils/form-subject.js +11 -4
  14. package/esm2015/ngx-dynamic-form/utils/misc.js +1 -1
  15. package/esm2015/public_api.js +2 -1
  16. package/fesm2015/stemy-ngx-dynamic-form.js +113 -33
  17. package/fesm2015/stemy-ngx-dynamic-form.js.map +1 -1
  18. package/ngx-dynamic-form/common-types.d.ts +9 -8
  19. package/ngx-dynamic-form/components/base/dynamic-base-form-array.component.d.ts +9 -3
  20. package/ngx-dynamic-form/components/base/dynamic-base-form-group.component.d.ts +1 -0
  21. package/ngx-dynamic-form/components/base/dynamic-base-form.component.d.ts +4 -4
  22. package/ngx-dynamic-form/directives/async-submit.directive.d.ts +2 -2
  23. package/ngx-dynamic-form/services/dynamic-form.service.d.ts +5 -3
  24. package/ngx-dynamic-form/utils/dynamic-form-array.model.d.ts +10 -0
  25. package/ngx-dynamic-form/utils/form-subject.d.ts +4 -3
  26. package/ngx-dynamic-form/utils/misc.d.ts +1 -1
  27. package/package.json +1 -1
  28. package/public_api.d.ts +2 -1
  29. package/stemy-ngx-dynamic-form.metadata.json +1 -1
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@stemy/ngx-utils'), require('rxjs'), require('@angular/core'), require('@angular/forms'), require('@ng-dynamic-forms/core'), require('rxjs/operators'), require('@angular/common')) :
3
- typeof define === 'function' && define.amd ? define('@stemy/ngx-dynamic-form', ['exports', '@stemy/ngx-utils', 'rxjs', '@angular/core', '@angular/forms', '@ng-dynamic-forms/core', 'rxjs/operators', '@angular/common'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy['ngx-dynamic-form'] = {}), global.ngxUtils, global.rxjs, global.ng.core, global.ng.forms, global.core, global.rxjs.operators, global.ng.common));
5
- }(this, (function (exports, ngxUtils, rxjs, core$1, forms, core, operators, common) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@stemy/ngx-utils'), require('@ng-dynamic-forms/core'), require('rxjs'), require('@angular/core'), require('@angular/forms'), require('rxjs/operators'), require('@angular/common')) :
3
+ typeof define === 'function' && define.amd ? define('@stemy/ngx-dynamic-form', ['exports', '@stemy/ngx-utils', '@ng-dynamic-forms/core', 'rxjs', '@angular/core', '@angular/forms', 'rxjs/operators', '@angular/common'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy['ngx-dynamic-form'] = {}), global.ngxUtils, global.core, global.rxjs, global.ng.core, global.ng.forms, global.rxjs.operators, global.ng.common));
5
+ }(this, (function (exports, ngxUtils, core, rxjs, core$1, forms, operators, common) { 'use strict';
6
6
 
7
7
  // --- Decorator functions ---
8
8
  function defaultSerializer(id, parent) {
@@ -484,6 +484,24 @@
484
484
  return typeof state === "function" ? receiver === state : state.has(receiver);
485
485
  }
486
486
 
487
+ var DynamicFormArrayModel = /** @class */ (function (_super) {
488
+ __extends(DynamicFormArrayModel, _super);
489
+ function DynamicFormArrayModel(config, layout) {
490
+ var _this = _super.call(this, config, layout) || this;
491
+ _this.useTabs = config.useTabs || false;
492
+ _this.saveTab = ngxUtils.ObjectUtils.isFunction(config.saveTab) ? config.saveTab : (function (index, model) {
493
+ model.tabIndex = index;
494
+ });
495
+ _this.restoreTab = ngxUtils.ObjectUtils.isFunction(config.restoreTab) ? config.restoreTab : (function (model) {
496
+ return model.tabIndex;
497
+ });
498
+ _this.additional = config.additional || {};
499
+ return _this;
500
+ }
501
+ return DynamicFormArrayModel;
502
+ }(core.DynamicFormArrayModel));
503
+
504
+ var indexLabels = ["$ix", "$pix"];
487
505
  var FormSubject = /** @class */ (function (_super) {
488
506
  __extends(FormSubject, _super);
489
507
  function FormSubject(notifyCallback) {
@@ -495,12 +513,18 @@
495
513
  var _this = this;
496
514
  val.then(function (v) { return _this.next(v); });
497
515
  };
498
- FormSubject.prototype.notify = function (controlModel, control) {
516
+ FormSubject.prototype.notify = function (controlModel, control, root) {
517
+ var indexes = {};
499
518
  var path = controlModel;
500
- while (path && isNaN(path.index)) {
519
+ var ix = 0;
520
+ while (path) {
521
+ if (!isNaN(path.index)) {
522
+ var key = indexLabels[ix++] || "$pix" + ix;
523
+ indexes[key] = path.index;
524
+ }
501
525
  path = path.parent;
502
526
  }
503
- var value = this.notifyCallback(controlModel, control, path === null || path === void 0 ? void 0 : path.index);
527
+ var value = this.notifyCallback(controlModel, control, root, indexes);
504
528
  if (!(value instanceof Promise)) {
505
529
  value = Promise.resolve(value);
506
530
  }
@@ -556,16 +580,6 @@
556
580
  return parts;
557
581
  }
558
582
 
559
- var DynamicFormArrayModel = /** @class */ (function (_super) {
560
- __extends(DynamicFormArrayModel, _super);
561
- function DynamicFormArrayModel(config, layout) {
562
- var _this = _super.call(this, config, layout) || this;
563
- _this.additional = config.additional || {};
564
- return _this;
565
- }
566
- return DynamicFormArrayModel;
567
- }(core.DynamicFormArrayModel));
568
-
569
583
  var DynamicFormService = /** @class */ (function (_super) {
570
584
  __extends(DynamicFormService, _super);
571
585
  function DynamicFormService(cs, vs, openApi, injector) {
@@ -602,20 +616,20 @@
602
616
  DynamicFormService.prototype.serialize = function (formModel, formGroup) {
603
617
  return this.serializeRecursive(formModel, formGroup);
604
618
  };
605
- DynamicFormService.prototype.notifyChanges = function (formModel, formGroup) {
606
- this.notifyChangesRecursive(formModel, formGroup);
619
+ DynamicFormService.prototype.notifyChanges = function (formModel, formGroup, root) {
620
+ this.notifyChangesRecursive(formModel, formGroup, root);
607
621
  };
608
- DynamicFormService.prototype.updateSelectOptions = function (formControlModel, formControl) {
622
+ DynamicFormService.prototype.updateSelectOptions = function (formControlModel, formControl, root) {
609
623
  if (formControlModel instanceof core.DynamicSelectModel) {
610
624
  var options = formControlModel.options$;
611
625
  if (options instanceof FormSubject) {
612
- options.notify(formControlModel, formControl);
626
+ options.notify(formControlModel, formControl, root);
613
627
  return;
614
628
  }
615
629
  while (options instanceof rxjs.Subject && options.source) {
616
630
  options = options.source;
617
631
  if (options instanceof FormSubject) {
618
- options.notify(formControlModel, formControl);
632
+ options.notify(formControlModel, formControl, root);
619
633
  }
620
634
  }
621
635
  }
@@ -733,7 +747,7 @@
733
747
  });
734
748
  });
735
749
  };
736
- DynamicFormService.prototype.notifyChangesRecursive = function (formModel, formGroup) {
750
+ DynamicFormService.prototype.notifyChangesRecursive = function (formModel, formGroup, root) {
737
751
  if (!formModel || !formGroup)
738
752
  return;
739
753
  for (var i in formModel) {
@@ -744,15 +758,15 @@
744
758
  var subArray = subControl;
745
759
  for (var i_2 = 0; i_2 < length; i_2++) {
746
760
  var itemModel = subModel.get(i_2);
747
- this.notifyChangesRecursive(itemModel.group, subArray.at(i_2));
761
+ this.notifyChangesRecursive(itemModel.group, subArray.at(i_2), root);
748
762
  }
749
763
  continue;
750
764
  }
751
765
  if (subModel instanceof core.DynamicFormGroupModel) {
752
- this.notifyChangesRecursive(subModel.group, subControl);
766
+ this.notifyChangesRecursive(subModel.group, subControl, root);
753
767
  continue;
754
768
  }
755
- this.updateSelectOptions(subModel, subControl);
769
+ this.updateSelectOptions(subModel, subControl, root);
756
770
  }
757
771
  };
758
772
  DynamicFormService.prototype.showErrorsForGroup = function (formGroup) {
@@ -851,6 +865,21 @@
851
865
  }
852
866
  return [];
853
867
  };
868
+ DynamicFormService.prototype.findModelByPath = function (parent, path) {
869
+ if (path.length == 0)
870
+ return parent;
871
+ var next = path.shift();
872
+ if (Array.isArray(parent)) {
873
+ return this.findModelByPath(parent.find(function (t) { return t.id == next; }), path);
874
+ }
875
+ if (parent instanceof core.DynamicFormGroupModel) {
876
+ return this.findModelByPath(parent.group.find(function (t) { return t.id == next; }), path);
877
+ }
878
+ if (parent instanceof DynamicFormArrayModel) {
879
+ return this.findModelByPath(parent.groups.find(function (t) { return t.index == next; }), path);
880
+ }
881
+ return parent;
882
+ };
854
883
  DynamicFormService.prototype.getFormControlConfig = function (property, schema) {
855
884
  var validators = this.getValidators(property, schema);
856
885
  var errorMessages = Object.keys(validators).reduce(function (res, key) {
@@ -872,7 +901,10 @@
872
901
  var _a;
873
902
  var ref = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref) || property.$ref || "";
874
903
  var subSchema = this.schemas[ref.split("/").pop()];
875
- return Object.assign(this.getFormControlConfig(property, schema), { groupFactory: function () { return _this.getFormModelForSchemaDef(subSchema, customizeModels); } });
904
+ return Object.assign(this.getFormControlConfig(property, schema), {
905
+ groupFactory: function () { return _this.getFormModelForSchemaDef(subSchema, customizeModels); },
906
+ useTabs: property.useTabs || false
907
+ });
876
908
  };
877
909
  DynamicFormService.prototype.getFormGroupConfig = function (property, schema, customizeModels) {
878
910
  var ref = property.$ref || "";
@@ -984,23 +1016,34 @@
984
1016
  });
985
1017
  }
986
1018
  if (isStringWithVal(property.optionsPath)) {
987
- return new FormSelectSubject(function (formModel, control, index) {
1019
+ return new FormSelectSubject(function (formModel, control, root, indexes) {
988
1020
  var path = property.optionsPath;
989
1021
  var target = control;
1022
+ var model = formModel;
990
1023
  if (path.startsWith("$root")) {
991
1024
  path = path.substr(5);
992
1025
  while (target.parent) {
993
1026
  target = target.parent;
994
1027
  }
1028
+ model = root;
995
1029
  }
996
1030
  while (path.startsWith(".")) {
997
1031
  path = path.substr(1);
998
1032
  if (target.parent) {
999
1033
  target = target.parent;
1000
1034
  }
1035
+ model = model.parent || root;
1001
1036
  }
1002
- var value = ngxUtils.ObjectUtils.getValue(target.value, path.replace(/\$ix/gi, index));
1003
- var options = (!ngxUtils.ObjectUtils.isArray(value) ? [] : value).map(function (value) { return ({ value: value, label: value }); });
1037
+ Object.keys(indexes).forEach(function (key) {
1038
+ path = path.replace(key, indexes[key]);
1039
+ });
1040
+ model = _this.findModelByPath(model, path.split("."));
1041
+ var modelOptions = (model instanceof core.DynamicSelectModel ? model.options : []);
1042
+ var value = ngxUtils.ObjectUtils.getValue(target.value, path);
1043
+ var options = (!ngxUtils.ObjectUtils.isArray(value) ? [] : value).map(function (value) {
1044
+ var modelOption = modelOptions.find(function (t) { return t.value == value; });
1045
+ return { value: value, label: (modelOption === null || modelOption === void 0 ? void 0 : modelOption.label) || value };
1046
+ });
1004
1047
  return _this.translateOptions(options);
1005
1048
  });
1006
1049
  }
@@ -1212,8 +1255,8 @@
1212
1255
  _this.blur = new core$1.EventEmitter();
1213
1256
  _this.change = new core$1.EventEmitter();
1214
1257
  _this.focus = new core$1.EventEmitter();
1215
- _this.onStatusChange = new core$1.EventEmitter();
1216
1258
  _this.onValueChange = new core$1.EventEmitter();
1259
+ _this.onStatusChange = new core$1.EventEmitter();
1217
1260
  _this.onSubmit = new core$1.EventEmitter();
1218
1261
  _this.templates = new core$1.QueryList();
1219
1262
  _this.subscription = new rxjs.Subscription();
@@ -1235,8 +1278,9 @@
1235
1278
  this.groupSubscription = ngxUtils.ObservableUtils.multiSubscription(this.group.statusChanges.subscribe(function () {
1236
1279
  _this.onStatusChange.emit(_this);
1237
1280
  }), this.group.valueChanges.subscribe(function () {
1238
- _this.onValueChange.emit(_this);
1239
- _this.formService.notifyChanges(_this.model, _this.group);
1281
+ _this.formService.notifyChanges(_this.model, _this.group, _this.model);
1282
+ }), this.change.subscribe(function (ev) {
1283
+ _this.onValueChange.emit(Object.assign(Object.assign({}, ev), { form: _this }));
1240
1284
  }));
1241
1285
  }
1242
1286
  };
@@ -1346,28 +1390,46 @@
1346
1390
  focus: [{ type: core$1.Output }],
1347
1391
  contentTemplates: [{ type: core$1.ContentChildren, args: [core.DynamicTemplateDirective,] }],
1348
1392
  viewTemplates: [{ type: core$1.ViewChildren, args: [core.DynamicTemplateDirective,] }],
1349
- onStatusChange: [{ type: core$1.Output }],
1350
1393
  onValueChange: [{ type: core$1.Output }],
1394
+ onStatusChange: [{ type: core$1.Output }],
1351
1395
  onSubmit: [{ type: core$1.Output }],
1352
1396
  ngForm: [{ type: core$1.ViewChild, args: [forms.NgForm,] }]
1353
1397
  };
1354
1398
 
1355
1399
  var DynamicBaseFormArrayComponent = /** @class */ (function (_super) {
1356
1400
  __extends(DynamicBaseFormArrayComponent, _super);
1357
- function DynamicBaseFormArrayComponent(layoutService, validationService) {
1401
+ function DynamicBaseFormArrayComponent(layoutService, validationService, injector) {
1358
1402
  var _this = _super.call(this, layoutService, validationService) || this;
1359
1403
  _this.layoutService = layoutService;
1360
1404
  _this.validationService = validationService;
1405
+ _this.injector = injector;
1361
1406
  _this.blur = new core$1.EventEmitter();
1362
1407
  _this.change = new core$1.EventEmitter();
1363
1408
  _this.customEvent = new core$1.EventEmitter();
1364
1409
  _this.focus = new core$1.EventEmitter();
1365
1410
  return _this;
1366
1411
  }
1412
+ Object.defineProperty(DynamicBaseFormArrayComponent.prototype, "useTabs", {
1413
+ get: function () {
1414
+ var _a;
1415
+ return (_a = this.model) === null || _a === void 0 ? void 0 : _a.useTabs;
1416
+ },
1417
+ enumerable: false,
1418
+ configurable: true
1419
+ });
1420
+ DynamicBaseFormArrayComponent.prototype.saveTab = function (index) {
1421
+ this.model.saveTab(index, this.model, this.injector);
1422
+ };
1423
+ DynamicBaseFormArrayComponent.prototype.restoreTab = function () {
1424
+ return this.model.restoreTab(this.model, this.injector);
1425
+ };
1367
1426
  DynamicBaseFormArrayComponent.prototype.getClass = function (context, place, model) {
1427
+ var _a;
1368
1428
  return [
1369
1429
  context == "element" ? this.getModelClass(model) : null,
1370
- _super.prototype.getClass.call(this, context, place, model)
1430
+ context == "element" ? this.getAdditionalClass(model) : null,
1431
+ _super.prototype.getClass.call(this, context, place, model),
1432
+ model instanceof core.DynamicFormValueControlModel ? (_a = model.additional) === null || _a === void 0 ? void 0 : _a.classes : null
1371
1433
  ].filter(function (cls) { return !!cls; }).join(" ");
1372
1434
  };
1373
1435
  DynamicBaseFormArrayComponent.prototype.getModelClass = function (model) {
@@ -1379,6 +1441,16 @@
1379
1441
  }
1380
1442
  return "form-control-" + parts.join("-");
1381
1443
  };
1444
+ DynamicBaseFormArrayComponent.prototype.getAdditionalClass = function (model) {
1445
+ var _a, _b;
1446
+ if (model instanceof DynamicFormArrayModel) {
1447
+ return (_a = model.additional) === null || _a === void 0 ? void 0 : _a.classes;
1448
+ }
1449
+ if (model instanceof core.DynamicFormValueControlModel) {
1450
+ return (_b = model.additional) === null || _b === void 0 ? void 0 : _b.classes;
1451
+ }
1452
+ return null;
1453
+ };
1382
1454
  return DynamicBaseFormArrayComponent;
1383
1455
  }(core.DynamicFormArrayComponent));
1384
1456
  DynamicBaseFormArrayComponent.decorators = [
@@ -1390,7 +1462,8 @@
1390
1462
  ];
1391
1463
  DynamicBaseFormArrayComponent.ctorParameters = function () { return [
1392
1464
  { type: core.DynamicFormLayoutService },
1393
- { type: core.DynamicFormValidationService }
1465
+ { type: core.DynamicFormValidationService },
1466
+ { type: core$1.Injector }
1394
1467
  ]; };
1395
1468
  DynamicBaseFormArrayComponent.propDecorators = {
1396
1469
  formLayout: [{ type: core$1.Input }],
@@ -1461,7 +1534,7 @@
1461
1534
  if (form !== _this.form)
1462
1535
  return;
1463
1536
  _this.changeDetectorRef.detectChanges();
1464
- _this.formService.updateSelectOptions(_this.model, _this.control);
1537
+ _this.formService.updateSelectOptions(_this.model, _this.control, _this.form.model);
1465
1538
  });
1466
1539
  };
1467
1540
  DynamicBaseFormControlContainerComponent.prototype.ngOnDestroy = function () {
@@ -1537,6 +1610,7 @@
1537
1610
  DynamicBaseFormGroupComponent.prototype.getClass = function (context, place, model) {
1538
1611
  return [
1539
1612
  context == "element" ? this.getModelClass(model) : null,
1613
+ context == "element" ? this.getAdditionalClass(model) : null,
1540
1614
  _super.prototype.getClass.call(this, context, place, model)
1541
1615
  ].filter(function (cls) { return !!cls; }).join(" ");
1542
1616
  };
@@ -1549,6 +1623,16 @@
1549
1623
  }
1550
1624
  return "form-control-" + parts.join("-");
1551
1625
  };
1626
+ DynamicBaseFormGroupComponent.prototype.getAdditionalClass = function (model) {
1627
+ var _a, _b;
1628
+ if (model instanceof DynamicFormArrayModel) {
1629
+ return (_a = model.additional) === null || _a === void 0 ? void 0 : _a.classes;
1630
+ }
1631
+ if (model instanceof core.DynamicFormValueControlModel) {
1632
+ return (_b = model.additional) === null || _b === void 0 ? void 0 : _b.classes;
1633
+ }
1634
+ return null;
1635
+ };
1552
1636
  return DynamicBaseFormGroupComponent;
1553
1637
  }(core.DynamicFormGroupComponent));
1554
1638
  DynamicBaseFormGroupComponent.decorators = [
@@ -1653,6 +1737,7 @@
1653
1737
  exports.DynamicBaseFormComponent = DynamicBaseFormComponent;
1654
1738
  exports.DynamicBaseFormControlContainerComponent = DynamicBaseFormControlContainerComponent;
1655
1739
  exports.DynamicBaseFormGroupComponent = DynamicBaseFormGroupComponent;
1740
+ exports.DynamicFormArrayModel = DynamicFormArrayModel;
1656
1741
  exports.DynamicFormService = DynamicFormService;
1657
1742
  exports.FormFile = FormFile;
1658
1743
  exports.FormInput = FormInput;