@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 } 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 ---
@@ -626,7 +626,7 @@ class DynamicFormService extends DynamicFormService$1 {
626
626
  async getFormModelForSchema(name, customizeModel) {
627
627
  this.api.cache = {};
628
628
  this.schemas = await this.openApi.getSchemas();
629
- const customizeModels = (property, schema, modelType, config) => {
629
+ const customizeModels = async (property, schema, modelType, config) => {
630
630
  const model = new modelType(config);
631
631
  if (model instanceof DynamicFormValueControlModel) {
632
632
  model.value = (model instanceof DynamicDatePickerModel)
@@ -634,19 +634,25 @@ class DynamicFormService extends DynamicFormService$1 {
634
634
  }
635
635
  if (!ObjectUtils.isFunction(customizeModel))
636
636
  return [model];
637
- const res = customizeModel(property, schema, model, config, this.injector);
637
+ let res = customizeModel(property, schema, model, config, this.injector);
638
+ if (!res)
639
+ return [model];
640
+ if (res instanceof Promise) {
641
+ res = await res;
642
+ }
638
643
  return Array.isArray(res) ? res : [res];
639
644
  };
640
645
  return this.getFormModelForSchemaDef(this.schemas[name], customizeModels);
641
646
  }
642
- getFormModelForSchemaDef(schema, customizeModels) {
647
+ async getFormModelForSchemaDef(schema, customizeModels) {
643
648
  if (!schema)
644
649
  return [];
645
650
  const keys = Object.keys(schema.properties || {});
646
651
  const controls = [];
647
652
  for (const p of keys) {
648
653
  const property = schema.properties[p];
649
- controls.push(...this.getFormControlModels(property, schema, customizeModels));
654
+ const models = await this.getFormControlModels(property, schema, customizeModels);
655
+ controls.push(...models);
650
656
  }
651
657
  return controls.filter(t => null !== t);
652
658
  }
@@ -655,7 +661,7 @@ class DynamicFormService extends DynamicFormService$1 {
655
661
  return false;
656
662
  return EDITOR_FORMATS.indexOf(property.format) >= 0 || property.format.endsWith("script");
657
663
  }
658
- getFormControlModels(property, schema, customizeModels) {
664
+ async getFormControlModels(property, schema, customizeModels) {
659
665
  const $enum = property.items?.enum || property.enum;
660
666
  if (Array.isArray($enum) || isStringWithVal(property.optionsPath) || isStringWithVal(property.endpoint)) {
661
667
  return customizeModels(property, schema, DynamicSelectModel, this.getFormSelectConfig(property, schema));
@@ -681,7 +687,7 @@ class DynamicFormService extends DynamicFormService$1 {
681
687
  return customizeModels(property, schema, DynamicCheckboxModel, this.getFormCheckboxConfig(property, schema));
682
688
  case "array":
683
689
  if (findRefs(property).length > 0) {
684
- return customizeModels(property, schema, DynamicFormArrayModel, this.getFormArrayConfig(property, schema, customizeModels));
690
+ return customizeModels(property, schema, DynamicFormArrayModel, await this.getFormArrayConfig(property, schema, customizeModels));
685
691
  }
686
692
  else {
687
693
  return customizeModels(property, schema, DynamicInputModel, this.getFormInputConfig(property, schema));
@@ -690,7 +696,7 @@ class DynamicFormService extends DynamicFormService$1 {
690
696
  return customizeModels(property, schema, DynamicFileUploadModel, this.getFormUploadConfig(property, schema));
691
697
  }
692
698
  if (findRefs(property).length > 0) {
693
- return customizeModels(property, schema, DynamicFormGroupModel, this.getFormGroupConfig(property, schema, customizeModels));
699
+ return customizeModels(property, schema, DynamicFormGroupModel, await this.getFormGroupConfig(property, schema, customizeModels));
694
700
  }
695
701
  return [];
696
702
  }
@@ -725,10 +731,11 @@ class DynamicFormService extends DynamicFormService$1 {
725
731
  additional: Object.assign({}, property)
726
732
  };
727
733
  }
728
- getFormArrayConfig(property, schema, customizeModels) {
734
+ async getFormArrayConfig(property, schema, customizeModels) {
729
735
  const subSchemas = findRefs(property).map(ref => this.schemas[ref]);
736
+ const subModels = await Promise.all(subSchemas.map(s => this.getFormModelForSchemaDef(s, customizeModels)));
730
737
  return Object.assign(this.getFormControlConfig(property, schema), {
731
- groupFactory: () => mergeFormModels(subSchemas.map(s => this.getFormModelForSchemaDef(s, customizeModels))),
738
+ groupFactory: () => mergeFormModels(ObjectUtils.copy(subModels)),
732
739
  initialCount: property.initialCount || 0,
733
740
  sortable: property.sortable || false,
734
741
  useTabs: property.useTabs || false,
@@ -740,10 +747,11 @@ class DynamicFormService extends DynamicFormService$1 {
740
747
  clearItems: property.clearItems !== false
741
748
  });
742
749
  }
743
- getFormGroupConfig(property, schema, customizeModels) {
750
+ async getFormGroupConfig(property, schema, customizeModels) {
744
751
  const subSchemas = findRefs(property).map(ref => this.schemas[ref]);
752
+ const subModels = await Promise.all(subSchemas.map(s => this.getFormModelForSchemaDef(s, customizeModels)));
745
753
  return Object.assign(this.getFormControlConfig(property, schema), {
746
- group: mergeFormModels(subSchemas.map(s => this.getFormModelForSchemaDef(s, customizeModels)))
754
+ group: mergeFormModels(subModels)
747
755
  });
748
756
  }
749
757
  getFormInputConfig(property, schema) {
@@ -1134,10 +1142,10 @@ class DynamicBaseFormComponent extends DynamicFormComponent {
1134
1142
  if (this.group) {
1135
1143
  this.groupSubscription = ObservableUtils.multiSubscription(this.group.statusChanges.subscribe(() => {
1136
1144
  this.onStatusChange.emit(this);
1137
- }), this.group.valueChanges.pipe(debounceTime$1(500)).subscribe(() => {
1145
+ }), this.group.valueChanges.pipe(debounceTime(500)).subscribe(() => {
1138
1146
  this.formService.notifyChanges(this.model, this.group);
1139
1147
  }), this.change.pipe(groupBy(ev => ev.model))
1140
- .pipe(mergeMap(t => t.pipe(debounceTime$1(500))))
1148
+ .pipe(mergeMap(t => t.pipe(debounceTime(500))))
1141
1149
  .subscribe(ev => {
1142
1150
  this.onValueChange.emit({ ...ev, form: this });
1143
1151
  }));
@@ -1490,7 +1498,7 @@ class DynamicBaseFormControlComponent extends DynamicFormControlComponent {
1490
1498
  this.focus = new EventEmitter();
1491
1499
  }
1492
1500
  ngAfterViewInit() {
1493
- this.subscription = this.control.valueChanges.pipe(debounceTime$1(500)).subscribe(value => {
1501
+ this.subscription = this.control.valueChanges.pipe(debounceTime(500)).subscribe(value => {
1494
1502
  this.onValueChanged(value);
1495
1503
  });
1496
1504
  }