@stemy/ngx-dynamic-form 19.7.6 → 19.7.7

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.
@@ -90,6 +90,12 @@ function FormFile(data) {
90
90
  console.warn(`@FormFile decorator is deprecated, use @FormUpload instead`);
91
91
  return FormUpload(data);
92
92
  }
93
+ function FormStatic(data) {
94
+ data = data || {};
95
+ return (target, key) => {
96
+ defineFormControl(target, key, (fb, path, options) => fb.createFormStatic(key, data, path, options));
97
+ };
98
+ }
93
99
  function FormGroup(data) {
94
100
  data = data || {};
95
101
  return (target, key) => {
@@ -281,7 +287,7 @@ function convertToDateFormat(value, format) {
281
287
  }
282
288
  /**
283
289
  * Convert value to date object with format (date, date-time)
284
- * @param value Value to convert to date string
290
+ * @param value Value to convert to date
285
291
  * @param format Expected date format (date, date-time)
286
292
  */
287
293
  function convertToDate(value, format) {
@@ -289,6 +295,15 @@ function convertToDate(value, format) {
289
295
  ? value
290
296
  : new Date(convertToDateFormat(value, format));
291
297
  }
298
+ /**
299
+ * Convert potential number value to an actual number
300
+ * @param value Value to convert to number
301
+ * @param defaultVal Default value if original is not a number
302
+ */
303
+ function convertToNumber(value, defaultVal) {
304
+ const num = Number(value);
305
+ return isNaN(num) ? defaultVal ?? value : num;
306
+ }
292
307
  function getFieldByPath(field, path) {
293
308
  if (field.path === path) {
294
309
  return field;
@@ -596,13 +611,13 @@ class DynamicFormBuilderService {
596
611
  switch (type) {
597
612
  case "number":
598
613
  case "integer":
599
- props.min = isNaN(data.min) ? MIN_INPUT_NUM : data.min;
600
- props.max = isNaN(data.max) ? MAX_INPUT_NUM : data.max;
614
+ props.min = convertToNumber(data.min, MIN_INPUT_NUM);
615
+ props.max = convertToNumber(data.max, MAX_INPUT_NUM);
601
616
  break;
602
617
  case "date":
603
618
  case "datetime-local":
604
- props.min = data.min;
605
- props.max = data.max;
619
+ props.min = convertToDateFormat(data.min, type);
620
+ props.max = convertToDateFormat(data.max, type);
606
621
  break;
607
622
  case "string":
608
623
  case "text":
@@ -611,7 +626,7 @@ class DynamicFormBuilderService {
611
626
  props.maxLength = isNaN(data.maxLength) ? MAX_INPUT_NUM : data.maxLength;
612
627
  break;
613
628
  }
614
- return this.createFormField(key, type === "checkbox" || type === "textarea" ? type : "input", data, props, parent, options);
629
+ return this.createFormField(key, type === "checkbox" || type === "textarea" || type === "wysiwyg" ? type : "input", data, props, parent, options);
615
630
  }
616
631
  createFormSelect(key, data, parent, options) {
617
632
  data = data || {};
@@ -640,6 +655,13 @@ class DynamicFormBuilderService {
640
655
  });
641
656
  return field;
642
657
  }
658
+ createFormStatic(key, data, parent, options) {
659
+ data = data || {};
660
+ return this.createFormField(key, "static", data, {
661
+ properties: Array.isArray(data.properties) ? data.properties : null,
662
+ style: data.style === "list" ? "list" : "table"
663
+ }, parent, options);
664
+ }
643
665
  createFormUpload(key, data, parent, options) {
644
666
  data = data || {};
645
667
  if (data.asFile) {
@@ -1607,6 +1629,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
1607
1629
  }] });
1608
1630
 
1609
1631
  class DynamicFormComponent {
1632
+ forms;
1610
1633
  builder = inject(DynamicFormBuilderService);
1611
1634
  events = inject(EventsService);
1612
1635
  languages = inject(LANGUAGE_SERVICE);
@@ -1657,7 +1680,8 @@ class DynamicFormComponent {
1657
1680
  injector: inject(Injector)
1658
1681
  }
1659
1682
  };
1660
- constructor() {
1683
+ constructor(forms) {
1684
+ this.forms = forms;
1661
1685
  effect(() => {
1662
1686
  this.language();
1663
1687
  this.enableTranslations();
@@ -1674,13 +1698,24 @@ class DynamicFormComponent {
1674
1698
  reset() {
1675
1699
  this.options?.resetModel?.();
1676
1700
  }
1677
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DynamicFormComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1701
+ serialize(validate = true) {
1702
+ return this.forms.serializeForm(this, validate);
1703
+ }
1704
+ getField(path) {
1705
+ const config = untracked(() => this.config());
1706
+ return getFieldByPath(config[0], path);
1707
+ }
1708
+ getControl(path) {
1709
+ const field = this.getField(path);
1710
+ return field?.formControl ?? null;
1711
+ }
1712
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DynamicFormComponent, deps: [{ token: DynamicFormService }], target: i0.ɵɵFactoryTarget.Component });
1678
1713
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.14", type: DynamicFormComponent, isStandalone: false, selector: "dynamic-form", inputs: { labelPrefix: { classPropertyName: "labelPrefix", publicName: "labelPrefix", isSignal: true, isRequired: false, transformFunction: null }, labelCustomizer: { classPropertyName: "labelCustomizer", publicName: "labelCustomizer", isSignal: true, isRequired: false, transformFunction: null }, testId: { classPropertyName: "testId", publicName: "testId", isSignal: true, isRequired: false, transformFunction: null }, useTabs: { classPropertyName: "useTabs", publicName: "useTabs", isSignal: true, isRequired: false, transformFunction: null }, data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null }, fields: { classPropertyName: "fields", publicName: "fields", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { onSubmit: "onSubmit", onChanges: "onChanges" }, ngImport: i0, template: "@if (config() && group()) {\n <form [formGroup]=\"group()\" (ngSubmit)=\"submit()\" autocomplete=\"off\" role=\"presentation\">\n <input type=\"submit\" [hidden]=\"true\" />\n <formly-form [model]=\"data()\"\n [fields]=\"config()\"\n [form]=\"group()\"\n [options]=\"options\"></formly-form>\n <ng-content></ng-content>\n </form>\n}\n", styles: [".dynamic-form-field.dynamic-form-hidden{display:none}\n"], dependencies: [{ kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "component", type: i3.LegacyFormlyForm, selector: "formly-form" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1679
1714
  }
1680
1715
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DynamicFormComponent, decorators: [{
1681
1716
  type: Component,
1682
1717
  args: [{ standalone: false, selector: "dynamic-form", encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (config() && group()) {\n <form [formGroup]=\"group()\" (ngSubmit)=\"submit()\" autocomplete=\"off\" role=\"presentation\">\n <input type=\"submit\" [hidden]=\"true\" />\n <formly-form [model]=\"data()\"\n [fields]=\"config()\"\n [form]=\"group()\"\n [options]=\"options\"></formly-form>\n <ng-content></ng-content>\n </form>\n}\n", styles: [".dynamic-form-field.dynamic-form-hidden{display:none}\n"] }]
1683
- }], ctorParameters: () => [] });
1718
+ }], ctorParameters: () => [{ type: DynamicFormService }] });
1684
1719
 
1685
1720
  class DynamicFormArrayComponent extends FieldArrayType {
1686
1721
  currentTab = signal(0);
@@ -1718,6 +1753,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
1718
1753
  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" }]
1719
1754
  }] });
1720
1755
 
1756
+ class DynamicFormStaticComponent extends DynamicFieldType {
1757
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DynamicFormStaticComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
1758
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.14", type: DynamicFormStaticComponent, isStandalone: false, selector: "dynamic-form-chips", usesInheritance: true, ngImport: i0, template: "<unordered-list [listStyle]=\"props.style\" [ngClass]=\"{disabled: props.disabled}\"\n [data]=\"!props.properties ? {value: value} : props.properties | remap: value\">\n <ng-template [type]=\"!props.properties ? 'key' : null\" selector=\"level == 0\" let-item=\"item\"></ng-template>\n <ng-template type=\"value\" selector=\"valueType == 'date'\" let-item=\"item\">\n {{ item.value | date }}\n </ng-template>\n</unordered-list>\n", dependencies: [{ kind: "directive", type: i1$1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.UnorderedListTemplateDirective, selector: "ng-template[type][selector]", inputs: ["type", "selector"] }, { kind: "component", type: i2.UnorderedListComponent, selector: "unordered-list", inputs: ["data", "keyPrefix", "listStyle", "path", "level", "templates"] }, { kind: "pipe", type: i1$1.DatePipe, name: "date" }, { kind: "pipe", type: i2.RemapPipe, name: "remap" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1759
+ }
1760
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DynamicFormStaticComponent, decorators: [{
1761
+ type: Component,
1762
+ args: [{ standalone: false, selector: "dynamic-form-chips", encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "<unordered-list [listStyle]=\"props.style\" [ngClass]=\"{disabled: props.disabled}\"\n [data]=\"!props.properties ? {value: value} : props.properties | remap: value\">\n <ng-template [type]=\"!props.properties ? 'key' : null\" selector=\"level == 0\" let-item=\"item\"></ng-template>\n <ng-template type=\"value\" selector=\"valueType == 'date'\" let-item=\"item\">\n {{ item.value | date }}\n </ng-template>\n</unordered-list>\n" }]
1763
+ }] });
1764
+
1721
1765
  class DynamicFormUploadComponent extends DynamicFieldType {
1722
1766
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DynamicFormUploadComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
1723
1767
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.14", type: DynamicFormUploadComponent, isStandalone: false, selector: "dynamic-form-upload", usesInheritance: true, ngImport: i0, template: "<upload [formControl]=\"formControl\"\n [multiple]=\"props.multiple\"\n [inline]=\"props.inline\"\n [accept]=\"props.accept\"\n [baseUrl]=\"props.url\"\n [makeUpload]=\"props.createUploadData\"\n [formlyAttributes]=\"field\">\n</upload>\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.UploadComponent, selector: "upload", inputs: ["value", "disabled", "inline", "accept", "baseUrl", "message", "multiple", "buttonText", "makeUpload", "preProcess"], outputs: ["onUploaded", "onRemove"] }, { kind: "directive", type: i3.LegacyFormlyAttributes, selector: "[formlyAttributes]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
@@ -1727,6 +1771,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
1727
1771
  args: [{ standalone: false, selector: "dynamic-form-upload", encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "<upload [formControl]=\"formControl\"\n [multiple]=\"props.multiple\"\n [inline]=\"props.inline\"\n [accept]=\"props.accept\"\n [baseUrl]=\"props.url\"\n [makeUpload]=\"props.createUploadData\"\n [formlyAttributes]=\"field\">\n</upload>\n" }]
1728
1772
  }] });
1729
1773
 
1774
+ class DynamicFormWysiwygComponent extends DynamicFieldType {
1775
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DynamicFormWysiwygComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
1776
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.14", type: DynamicFormWysiwygComponent, isStandalone: false, selector: "dynamic-form-wysiwyg", usesInheritance: true, ngImport: i0, template: "<wysiwyg [formControl]=\"formControl\"\n [formlyAttributes]=\"field\">\n</wysiwyg>\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.WysiwygComponent, selector: "wysiwyg", inputs: ["value", "disabled"], outputs: ["valueChange"] }, { kind: "directive", type: i3.LegacyFormlyAttributes, selector: "[formlyAttributes]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1777
+ }
1778
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DynamicFormWysiwygComponent, decorators: [{
1779
+ type: Component,
1780
+ args: [{ standalone: false, selector: "dynamic-form-wysiwyg", encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "<wysiwyg [formControl]=\"formControl\"\n [formlyAttributes]=\"field\">\n</wysiwyg>\n" }]
1781
+ }] });
1782
+
1730
1783
  /**
1731
1784
  * This is just a test wrapper component
1732
1785
  */
@@ -1772,7 +1825,9 @@ const components = [
1772
1825
  DynamicFormComponent,
1773
1826
  DynamicFormArrayComponent,
1774
1827
  DynamicFormChipsComponent,
1828
+ DynamicFormStaticComponent,
1775
1829
  DynamicFormUploadComponent,
1830
+ DynamicFormWysiwygComponent,
1776
1831
  DynamicFormAlertComponent,
1777
1832
  DynamicFormFieldComponent,
1778
1833
  DynamicFormFieldsetComponent,
@@ -1793,7 +1848,9 @@ class NgxDynamicFormModule {
1793
1848
  types: [
1794
1849
  { name: "array", component: DynamicFormArrayComponent },
1795
1850
  { name: "chips", component: DynamicFormChipsComponent },
1796
- { name: "upload", component: DynamicFormUploadComponent }
1851
+ { name: "static", component: DynamicFormStaticComponent },
1852
+ { name: "upload", component: DynamicFormUploadComponent },
1853
+ { name: "wysiwyg", component: DynamicFormWysiwygComponent },
1797
1854
  ],
1798
1855
  wrappers: [
1799
1856
  { name: "form-alert", component: DynamicFormAlertComponent },
@@ -1822,12 +1879,12 @@ class NgxDynamicFormModule {
1822
1879
  return makeEnvironmentProviders(NgxDynamicFormModule.getProviders(config));
1823
1880
  }
1824
1881
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: NgxDynamicFormModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1825
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: NgxDynamicFormModule, declarations: [DynamicFieldType, DynamicFormComponent, DynamicFormArrayComponent, DynamicFormChipsComponent, DynamicFormUploadComponent, DynamicFormAlertComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, AsyncSubmitDirective], imports: [CommonModule,
1882
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: NgxDynamicFormModule, declarations: [DynamicFieldType, DynamicFormComponent, DynamicFormArrayComponent, DynamicFormChipsComponent, DynamicFormStaticComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, DynamicFormAlertComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, AsyncSubmitDirective], imports: [CommonModule,
1826
1883
  FormsModule,
1827
1884
  ReactiveFormsModule,
1828
1885
  NgxUtilsModule,
1829
1886
  FormlyModule,
1830
- FormlySelectModule], exports: [DynamicFieldType, DynamicFormComponent, DynamicFormArrayComponent, DynamicFormChipsComponent, DynamicFormUploadComponent, DynamicFormAlertComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, AsyncSubmitDirective, FormsModule,
1887
+ FormlySelectModule], exports: [DynamicFieldType, DynamicFormComponent, DynamicFormArrayComponent, DynamicFormChipsComponent, DynamicFormStaticComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, DynamicFormAlertComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, AsyncSubmitDirective, FormsModule,
1831
1888
  ReactiveFormsModule,
1832
1889
  NgxUtilsModule,
1833
1890
  FormlyModule,
@@ -1881,5 +1938,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
1881
1938
  * Generated bundle index. Do not edit.
1882
1939
  */
1883
1940
 
1884
- export { AsyncSubmitDirective, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormUploadComponent, EDITOR_FORMATS, FORM_ROOT_ID, FormArray, FormFile, FormGroup, FormInput, FormModel, FormSelect, FormSerializable, FormUpload, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, addFieldValidators, arrayLengthValidation, clearFieldArray, controlStatus, controlValues, convertToDate, convertToDateFormat, customizeFormField, emailValidation, getFieldByPath, getFieldsByKey, getFieldsByPredicate, getSelectOptions, insertToFieldArray, jsonValidation, maxLengthValidation, maxValueValidation, minLengthValidation, minValueValidation, phoneValidation, removeFieldValidators, removeFromFieldArray, replaceFieldArray, replaceSpecialChars, requiredValidation, setFieldDefault, setFieldDisabled, setFieldHidden, setFieldHooks, setFieldProp, setFieldProps, translationValidation };
1941
+ export { AsyncSubmitDirective, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, EDITOR_FORMATS, FORM_ROOT_ID, FormArray, FormFile, FormGroup, FormInput, FormModel, FormSelect, FormSerializable, FormStatic, FormUpload, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, addFieldValidators, arrayLengthValidation, clearFieldArray, controlStatus, controlValues, convertToDate, convertToDateFormat, convertToNumber, customizeFormField, emailValidation, getFieldByPath, getFieldsByKey, getFieldsByPredicate, getSelectOptions, insertToFieldArray, jsonValidation, maxLengthValidation, maxValueValidation, minLengthValidation, minValueValidation, phoneValidation, removeFieldValidators, removeFromFieldArray, replaceFieldArray, replaceSpecialChars, requiredValidation, setFieldDefault, setFieldDisabled, setFieldHidden, setFieldHooks, setFieldProp, setFieldProps, translationValidation };
1885
1942
  //# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map