@stemy/ngx-dynamic-form 13.1.19 → 13.1.21

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.
@@ -4,11 +4,11 @@ import { __decorate, __awaiter } from 'tslib';
4
4
  import * as i1 from '@ng-dynamic-forms/core';
5
5
  import { DynamicInputControlModel, DYNAMIC_FORM_CONTROL_TYPE_EDITOR, serializable, DynamicFormArrayGroupModel as DynamicFormArrayGroupModel$1, DynamicFormArrayModel as DynamicFormArrayModel$1, DynamicFormOption as DynamicFormOption$1, DynamicSelectModel as DynamicSelectModel$1, DynamicFormService as DynamicFormService$1, DynamicDatePickerModel, DynamicFormGroupModel, DynamicInputModel, DynamicFormValueControlModel, DynamicFileUploadModel, DynamicCheckboxModel, DynamicTextAreaModel, DynamicFormComponent, DynamicTemplateDirective, DynamicFormControlContainerComponent, DYNAMIC_FORM_CONTROL_TYPE_ARRAY, DynamicFormArrayComponent, DynamicFormControlComponent, DynamicFormGroupComponent, DYNAMIC_FORM_CONTROL_MAP_FN, DYNAMIC_VALIDATORS } from '@ng-dynamic-forms/core';
6
6
  export { DYNAMIC_FORM_CONTROL_TYPE_ARRAY, DYNAMIC_FORM_CONTROL_TYPE_CHECKBOX, DYNAMIC_FORM_CONTROL_TYPE_CHECKBOX_GROUP, DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER, DYNAMIC_FORM_CONTROL_TYPE_EDITOR, DYNAMIC_FORM_CONTROL_TYPE_FILE_UPLOAD, DYNAMIC_FORM_CONTROL_TYPE_GROUP, DYNAMIC_FORM_CONTROL_TYPE_INPUT, DYNAMIC_FORM_CONTROL_TYPE_RADIO_GROUP, DYNAMIC_FORM_CONTROL_TYPE_SELECT, DYNAMIC_FORM_CONTROL_TYPE_TEXTAREA, DynamicCheckboxGroupModel, DynamicCheckboxModel, DynamicDatePickerModel, DynamicFileUploadModel, DynamicFormControlComponent, DynamicFormGroupModel, DynamicFormsCoreModule, DynamicInputModel, DynamicListDirective, DynamicRadioGroupModel, DynamicTemplateDirective, DynamicTextAreaModel } from '@ng-dynamic-forms/core';
7
- import { BehaviorSubject, of, isObservable, map, Subject, firstValueFrom, Subscription, debounceTime as debounceTime$1, groupBy, mergeMap } from 'rxjs';
7
+ import { BehaviorSubject, of, isObservable, Subject, firstValueFrom, Subscription } from 'rxjs';
8
+ import { map, debounceTime, groupBy, mergeMap, first } from 'rxjs/operators';
8
9
  import * as i0 from '@angular/core';
9
10
  import { Injector, Injectable, Inject, EventEmitter, Directive, Input, Output, HostBinding, HostListener, QueryList, Component, ChangeDetectionStrategy, ContentChildren, ViewChildren, ViewContainerRef, ViewChild, forwardRef, NgModule } from '@angular/core';
10
11
  import { FormGroup, FormArray, FormsModule, ReactiveFormsModule, NG_VALIDATORS } from '@angular/forms';
11
- import { debounceTime, first } from 'rxjs/operators';
12
12
  import { CommonModule } from '@angular/common';
13
13
 
14
14
  // --- Decorator functions ---
@@ -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
- const res = customizeModel(property, schema, model, config, this.injector);
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
- if (!schema)
653
- return [];
654
- const keys = Object.keys(schema.properties || {});
655
- const controls = [];
656
- for (const p of keys) {
657
- const property = schema.properties[p];
658
- controls.push(...this.getFormControlModels(property, schema, customizeModels));
659
- }
660
- return controls.filter(t => null !== t);
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
- const $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
670
- if (Array.isArray($enum) || isStringWithVal(property.optionsPath) || isStringWithVal(property.endpoint)) {
671
- return customizeModels(property, schema, DynamicSelectModel, this.getFormSelectConfig(property, schema));
672
- }
673
- switch (property.type) {
674
- case "string":
675
- case "number":
676
- case "integer":
677
- case "textarea":
678
- if (this.checkIsEditorProperty(property)) {
679
- return customizeModels(property, schema, DynamicEditorModel, this.getFormEditorConfig(property, schema));
680
- }
681
- if (property.format == "textarea") {
682
- return customizeModels(property, schema, DynamicTextAreaModel, this.getFormTextareaConfig(property, schema));
683
- }
684
- if (property.format == "date") {
685
- return customizeModels(property, schema, DynamicDatePickerModel, this.getFormDatepickerConfig(property, schema));
686
- }
687
- return customizeModels(property, schema, DynamicInputModel, this.getFormInputConfig(property, schema));
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
- case "file":
700
- return customizeModels(property, schema, DynamicFileUploadModel, this.getFormUploadConfig(property, schema));
701
- }
702
- if (findRefs(property).length > 0) {
703
- return customizeModels(property, schema, DynamicFormGroupModel, this.getFormGroupConfig(property, schema, customizeModels));
704
- }
705
- return [];
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
- const subSchemas = findRefs(property).map(ref => this.schemas[ref]);
740
- return Object.assign(this.getFormControlConfig(property, schema), {
741
- groupFactory: () => mergeFormModels(subSchemas.map(s => this.getFormModelForSchemaDef(s, customizeModels))),
742
- initialCount: property.initialCount || 0,
743
- sortable: property.sortable || false,
744
- useTabs: property.useTabs || false,
745
- addItem: property.addItem !== false,
746
- insertItem: property.insertItem !== false,
747
- cloneItem: property.cloneItem !== false,
748
- moveItem: property.moveItem !== false,
749
- removeItem: property.removeItem !== false,
750
- clearItems: property.clearItems !== false
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
- const subSchemas = findRefs(property).map(ref => this.schemas[ref]);
755
- return Object.assign(this.getFormControlConfig(property, schema), {
756
- group: mergeFormModels(subSchemas.map(s => this.getFormModelForSchemaDef(s, customizeModels)))
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) {
@@ -1149,10 +1165,10 @@ class DynamicBaseFormComponent extends DynamicFormComponent {
1149
1165
  if (this.group) {
1150
1166
  this.groupSubscription = ObservableUtils.multiSubscription(this.group.statusChanges.subscribe(() => {
1151
1167
  this.onStatusChange.emit(this);
1152
- }), this.group.valueChanges.pipe(debounceTime$1(500)).subscribe(() => {
1168
+ }), this.group.valueChanges.pipe(debounceTime(500)).subscribe(() => {
1153
1169
  this.formService.notifyChanges(this.model, this.group);
1154
1170
  }), this.change.pipe(groupBy(ev => ev.model))
1155
- .pipe(mergeMap(t => t.pipe(debounceTime$1(500))))
1171
+ .pipe(mergeMap(t => t.pipe(debounceTime(500))))
1156
1172
  .subscribe(ev => {
1157
1173
  this.onValueChange.emit(Object.assign(Object.assign({}, ev), { form: this }));
1158
1174
  }));
@@ -1515,7 +1531,7 @@ class DynamicBaseFormControlComponent extends DynamicFormControlComponent {
1515
1531
  this.focus = new EventEmitter();
1516
1532
  }
1517
1533
  ngAfterViewInit() {
1518
- this.subscription = this.control.valueChanges.pipe(debounceTime$1(500)).subscribe(value => {
1534
+ this.subscription = this.control.valueChanges.pipe(debounceTime(500)).subscribe(value => {
1519
1535
  this.onValueChanged(value);
1520
1536
  });
1521
1537
  }