@stemy/ngx-dynamic-form 13.1.18 → 13.1.20

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.
@@ -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,12 @@ 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)),
739
+ initialCount: property.initialCount || 0,
732
740
  sortable: property.sortable || false,
733
741
  useTabs: property.useTabs || false,
734
742
  addItem: property.addItem !== false,
@@ -739,10 +747,11 @@ class DynamicFormService extends DynamicFormService$1 {
739
747
  clearItems: property.clearItems !== false
740
748
  });
741
749
  }
742
- getFormGroupConfig(property, schema, customizeModels) {
750
+ async getFormGroupConfig(property, schema, customizeModels) {
743
751
  const subSchemas = findRefs(property).map(ref => this.schemas[ref]);
752
+ const subModels = await Promise.all(subSchemas.map(s => this.getFormModelForSchemaDef(s, customizeModels)));
744
753
  return Object.assign(this.getFormControlConfig(property, schema), {
745
- group: mergeFormModels(subSchemas.map(s => this.getFormModelForSchemaDef(s, customizeModels)))
754
+ group: mergeFormModels(subModels)
746
755
  });
747
756
  }
748
757
  getFormInputConfig(property, schema) {
@@ -853,10 +862,14 @@ class DynamicFormService extends DynamicFormService$1 {
853
862
  }
854
863
  return new FormSelectSubject(async (selectModel, control) => {
855
864
  this.api.cache[property.endpoint] = this.api.cache[property.endpoint] || this.api.list(property.endpoint, this.api.makeListParams(1, -1)).then(result => {
856
- return result.items.map(i => {
865
+ const items = ObjectUtils.isArray(result)
866
+ ? result
867
+ : (ObjectUtils.isArray(result.items) ? result.items : []);
868
+ return items.map(i => {
869
+ const item = ObjectUtils.isObject(i) ? i : { id: i };
857
870
  return {
858
- ...i,
859
- value: i.id || i._id, label: i[property.labelField] || i.label || i.id || i._id
871
+ ...item,
872
+ value: item.id || item._id, label: item[property.labelField] || item.label || item.id || item._id
860
873
  };
861
874
  });
862
875
  });