@stemy/ngx-dynamic-form 19.6.8 → 19.7.0

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.
@@ -11,6 +11,8 @@ import * as i3 from '@ngx-formly/core';
11
11
  import { FieldType, ɵobserve as _observe, FieldArrayType, FieldWrapper, provideFormlyConfig, provideFormlyCore, FormlyModule } from '@ngx-formly/core';
12
12
  import * as i1$1 from '@angular/common';
13
13
  import { CommonModule } from '@angular/common';
14
+ import * as i5 from '@ngx-formly/core/select';
15
+ import { FormlySelectModule } from '@ngx-formly/core/select';
14
16
 
15
17
  // --- Basic frm constants ---
16
18
  const FORM_ROOT_ID = "__root";
@@ -35,10 +37,12 @@ function customizeFormField(...providers) {
35
37
  function defineFormControl(target, propertyKey, cb) {
36
38
  const fields = ReflectUtils.getMetadata("dynamicFormFields", target) || new Set();
37
39
  const existing = ReflectUtils.getMetadata("dynamicFormField", target, propertyKey);
38
- const builder = !ObjectUtils.isFunction(existing) ? cb : ((fb, opts, path) => {
39
- const data = existing(fb, opts, path);
40
- return ObjectUtils.assign(data || {}, cb(fb, opts, path) || {});
41
- });
40
+ const builder = (fb, opts, path) => {
41
+ const data = ObjectUtils.isFunction(existing) ? existing(fb, opts, path) : {
42
+ priority: Number.MAX_SAFE_INTEGER
43
+ };
44
+ return ObjectUtils.assign(data, cb(fb, opts, path) || {});
45
+ };
42
46
  fields.add(propertyKey);
43
47
  ReflectUtils.defineMetadata("dynamicFormField", builder, target, propertyKey);
44
48
  ReflectUtils.defineMetadata("dynamicFormFields", fields, target);
@@ -426,7 +430,7 @@ async function toWrapOptions(customizeOrOptions, injector, schema, errorMsg) {
426
430
  throw new Error(errorMsg);
427
431
  }
428
432
  if (customizeOrOptions instanceof ConfigForSchemaWrap) {
429
- return customizeOrOptions;
433
+ return customizeOrOptions.forSchema(schema);
430
434
  }
431
435
  let schemaOptions = customizeOrOptions;
432
436
  if (!ObjectUtils.isObject(schemaOptions)) {
@@ -524,48 +528,48 @@ class DynamicFormBuilderService {
524
528
  }, data, parent, options);
525
529
  }
526
530
  createFieldSets(fields, parent, options) {
527
- const others = [];
531
+ const result = [];
528
532
  const groups = {};
529
- fields = fields.filter(f => {
533
+ fields = Array.from(fields || [])
534
+ .sort((a, b) => a.priority - b.priority);
535
+ fields.forEach(f => {
530
536
  if (Array.isArray(f.fieldGroup) && Array.isArray(f.wrappers) && f.wrappers[0] === "form-fieldset") {
531
537
  // This field is an already existing set
532
538
  groups[f.id] = f.fieldGroup;
533
- return false;
534
539
  }
535
- return true;
536
540
  });
537
541
  for (const field of fields) {
538
542
  const fsName = String(field.fieldSet || "");
539
543
  // If we have a fieldset name defined, then push the property fields into a group
540
544
  if (fsName) {
541
- const fsId = !parent?.path ? fsName : `${parent.path}.${fsName}`;
542
- const group = groups[fsId] || [];
543
- groups[fsId] = group;
544
- group.push(field);
545
+ const id = !parent?.path ? fsName : `${parent.path}.${fsName}`;
546
+ let fieldGroup = groups[id];
547
+ if (!fieldGroup) {
548
+ fieldGroup = [];
549
+ const fieldSet = {
550
+ id,
551
+ parent,
552
+ fieldGroup,
553
+ wrappers: ["form-fieldset"],
554
+ props: {
555
+ label: this.getLabel(fsName, fsName, parent, options),
556
+ hidden: false,
557
+ className: `dynamic-form-fieldset dynamic-form-fieldset-${id}`
558
+ },
559
+ hooks: {},
560
+ expressions: {}
561
+ };
562
+ this.setExpressions(fieldSet, options);
563
+ groups[id] = fieldGroup;
564
+ result.push(fieldSet);
565
+ }
566
+ fieldGroup.push(field);
545
567
  continue;
546
568
  }
547
- // Otherwise, push the fields to the others
548
- others.push(field);
569
+ // Otherwise just push to result
570
+ result.push(field);
549
571
  }
550
- // Create a field-set wrapper for each group and concat the other fields to the end
551
- return Object.keys(groups).map(id => {
552
- const key = id.split(".").pop();
553
- const fieldSet = {
554
- id,
555
- parent,
556
- fieldGroup: groups[id],
557
- wrappers: ["form-fieldset"],
558
- props: {
559
- label: this.getLabel(key, key, parent, options),
560
- hidden: false,
561
- className: `dynamic-form-fieldset dynamic-form-fieldset-${id}`
562
- },
563
- hooks: {},
564
- expressions: {}
565
- };
566
- this.setExpressions(fieldSet, options);
567
- return fieldSet;
568
- }).concat(others);
572
+ return result;
569
573
  }
570
574
  createFormInput(key, data, parent, options) {
571
575
  data = data || {};
@@ -608,9 +612,11 @@ class DynamicFormBuilderService {
608
612
  createFormSelect(key, data, parent, options) {
609
613
  data = data || {};
610
614
  const type = `${data.type || "select"}`;
611
- const field = this.createFormField(key, type === "radio" ? type : "select", data, {
615
+ const fieldType = type === "radio" ? type : (data.strict === false ? "chips" : "select");
616
+ const field = this.createFormField(key, fieldType, data, {
612
617
  type,
613
618
  multiple: data.multiple === true,
619
+ strict: data.strict !== false,
614
620
  allowEmpty: data.allowEmpty === true,
615
621
  groupBy: data.groupBy,
616
622
  invert: data.invert === true
@@ -762,10 +768,11 @@ class DynamicFormBuilderService {
762
768
  const disabled = ReflectUtils.resolve(data.disabled, this.injector);
763
769
  const hidden = ReflectUtils.resolve(data.hidden, this.injector);
764
770
  const field = {
765
- key,
766
- wrappers,
767
- type: data.componentType || type,
771
+ serializer: data.serializer,
772
+ serialize: data.serialize || false,
768
773
  fieldSet: String(data.fieldSet || ""),
774
+ priority: isNaN(data.priority) ? Number.MAX_SAFE_INTEGER : Number(data.priority),
775
+ type: data.componentType || type,
769
776
  resetOnHide: false,
770
777
  validators: {},
771
778
  validation: {},
@@ -789,8 +796,6 @@ class DynamicFormBuilderService {
789
796
  },
790
797
  hooks: {},
791
798
  expressions: {
792
- serializer: () => data.serializer,
793
- serialize: () => data.serialize,
794
799
  "props.hideRequiredMarker": target => target.type === "checkbox",
795
800
  "props.required": target => !!target.validators?.required,
796
801
  "props.disabled": target => {
@@ -801,7 +806,9 @@ class DynamicFormBuilderService {
801
806
  const hidden = target.props?.__hidden;
802
807
  return !!hidden(target, this.injector);
803
808
  }
804
- }
809
+ },
810
+ key,
811
+ wrappers,
805
812
  };
806
813
  // Parent object will be available for customizers as a property, until it gets redefined by formly
807
814
  Object.defineProperty(field, "parent", {
@@ -964,6 +971,7 @@ class DynamicFormSchemaService {
964
971
  layout: property.layout,
965
972
  serialize: property.serialize === true,
966
973
  fieldSet: property.fieldSet,
974
+ priority: property.priority,
967
975
  componentType: property.componentType,
968
976
  wrappers: property.wrappers,
969
977
  props: property,
@@ -1079,6 +1087,7 @@ class DynamicFormSchemaService {
1079
1087
  options: field => this.getFormSelectOptions($enum, property, options, field),
1080
1088
  type: property.format || "select",
1081
1089
  multiple: property.type == "array",
1090
+ strict: property.strict,
1082
1091
  groupBy: property.groupBy,
1083
1092
  invert: property.invert,
1084
1093
  allowEmpty: property.allowEmpty
@@ -1703,11 +1712,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
1703
1712
 
1704
1713
  class DynamicFormChipsComponent extends DynamicFieldType {
1705
1714
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DynamicFormChipsComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
1706
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.14", type: DynamicFormChipsComponent, isStandalone: false, selector: "dynamic-form-chips", usesInheritance: true, ngImport: i0, template: "<chips [formControl]=\"formControl\"\n [type]=\"props.type\"\n [step]=\"props.step\"\n [minLength]=\"props.minLength\"\n [maxLength]=\"props.maxLength\"\n [min]=\"props.min\"\n [max]=\"props.max\"\n [multiple]=\"props.multiple\"\n [formlyAttributes]=\"field\">\n</chips>\n", dependencies: [{ kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: i2.ChipsComponent, selector: "chips", inputs: ["value", "multiple", "disabled", "type", "min", "max", "minLength", "maxLength", "step", "placeholder", "unique", "options"], outputs: ["valueChange"] }, { kind: "directive", type: i3.LegacyFormlyAttributes, selector: "[formlyAttributes]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1715
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.14", type: DynamicFormChipsComponent, isStandalone: false, selector: "dynamic-form-chips", usesInheritance: true, ngImport: i0, template: "<chips [formControl]=\"formControl\"\n [type]=\"props.type\"\n [step]=\"props.step\"\n [minLength]=\"props.minLength\"\n [maxLength]=\"props.maxLength\"\n [min]=\"props.min\"\n [max]=\"props.max\"\n [multiple]=\"props.multiple\"\n [strict]=\"props.strict\"\n [options]=\"props.options | formlySelectOptions | async\"\n [testId]=\"field.testId\"\n [formlyAttributes]=\"field\">\n</chips>\n", dependencies: [{ kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "component", type: i2.ChipsComponent, selector: "chips", inputs: ["testId", "value", "multiple", "disabled", "type", "min", "max", "minLength", "maxLength", "step", "placeholder", "unique", "strict", "options"], outputs: ["valueChange"] }, { kind: "directive", type: i3.LegacyFormlyAttributes, selector: "[formlyAttributes]" }, { kind: "pipe", type: i1$1.AsyncPipe, name: "async" }, { kind: "pipe", type: i5.LegacyFormlySelectOptionsPipe, name: "formlySelectOptions" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1707
1716
  }
1708
1717
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DynamicFormChipsComponent, decorators: [{
1709
1718
  type: Component,
1710
- args: [{ standalone: false, selector: "dynamic-form-chips", encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "<chips [formControl]=\"formControl\"\n [type]=\"props.type\"\n [step]=\"props.step\"\n [minLength]=\"props.minLength\"\n [maxLength]=\"props.maxLength\"\n [min]=\"props.min\"\n [max]=\"props.max\"\n [multiple]=\"props.multiple\"\n [formlyAttributes]=\"field\">\n</chips>\n" }]
1719
+ args: [{ standalone: false, selector: "dynamic-form-chips", encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "<chips [formControl]=\"formControl\"\n [type]=\"props.type\"\n [step]=\"props.step\"\n [minLength]=\"props.minLength\"\n [maxLength]=\"props.maxLength\"\n [min]=\"props.min\"\n [max]=\"props.max\"\n [multiple]=\"props.multiple\"\n [strict]=\"props.strict\"\n [options]=\"props.options | formlySelectOptions | async\"\n [testId]=\"field.testId\"\n [formlyAttributes]=\"field\">\n</chips>\n" }]
1711
1720
  }] });
1712
1721
 
1713
1722
  class DynamicFormUploadComponent extends DynamicFieldType {
@@ -1818,20 +1827,24 @@ class NgxDynamicFormModule {
1818
1827
  FormsModule,
1819
1828
  ReactiveFormsModule,
1820
1829
  NgxUtilsModule,
1821
- FormlyModule], exports: [DynamicFieldType, DynamicFormComponent, DynamicFormArrayComponent, DynamicFormChipsComponent, DynamicFormUploadComponent, DynamicFormAlertComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, AsyncSubmitDirective, FormsModule,
1830
+ FormlyModule,
1831
+ FormlySelectModule], exports: [DynamicFieldType, DynamicFormComponent, DynamicFormArrayComponent, DynamicFormChipsComponent, DynamicFormUploadComponent, DynamicFormAlertComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, AsyncSubmitDirective, FormsModule,
1822
1832
  ReactiveFormsModule,
1823
1833
  NgxUtilsModule,
1824
- FormlyModule] });
1834
+ FormlyModule,
1835
+ FormlySelectModule] });
1825
1836
  static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: NgxDynamicFormModule, providers: [
1826
1837
  ...pipes
1827
1838
  ], imports: [CommonModule,
1828
1839
  FormsModule,
1829
1840
  ReactiveFormsModule,
1830
1841
  NgxUtilsModule,
1831
- FormlyModule, FormsModule,
1842
+ FormlyModule,
1843
+ FormlySelectModule, FormsModule,
1832
1844
  ReactiveFormsModule,
1833
1845
  NgxUtilsModule,
1834
- FormlyModule] });
1846
+ FormlyModule,
1847
+ FormlySelectModule] });
1835
1848
  }
1836
1849
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: NgxDynamicFormModule, decorators: [{
1837
1850
  type: NgModule,
@@ -1846,7 +1859,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
1846
1859
  FormsModule,
1847
1860
  ReactiveFormsModule,
1848
1861
  NgxUtilsModule,
1849
- FormlyModule
1862
+ FormlyModule,
1863
+ FormlySelectModule
1850
1864
  ],
1851
1865
  exports: [
1852
1866
  ...components,
@@ -1855,7 +1869,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
1855
1869
  FormsModule,
1856
1870
  ReactiveFormsModule,
1857
1871
  NgxUtilsModule,
1858
- FormlyModule
1872
+ FormlyModule,
1873
+ FormlySelectModule
1859
1874
  ],
1860
1875
  providers: [
1861
1876
  ...pipes