@stemy/ngx-dynamic-form 19.9.38 → 19.9.40

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.
@@ -1,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, inject, Inject, Injectable, untracked, input, Renderer2, ElementRef, computed, signal, effect, HostBinding, Directive, Input, Optional, Pipe, Type, Component, Injector, output, ChangeDetectionStrategy, ViewEncapsulation, viewChild, makeEnvironmentProviders, NgModule } from '@angular/core';
3
3
  import * as i2 from '@stemy/ngx-utils';
4
- import { cachedFactory, ReflectUtils, ObjectUtils, convertToDateFormat, LANGUAGE_SERVICE, convertToDate, ForbiddenZone, SetUtils, ArrayUtils, API_SERVICE, StringUtils, Enum, AsyncMethodBase, EventsService, NgxUtilsModule } from '@stemy/ngx-utils';
4
+ import { cachedFactory, ReflectUtils, ObjectUtils, convertToDateFormat, LANGUAGE_SERVICE, convertToDate, ForbiddenZone, SetUtils, ArrayUtils, API_SERVICE, ROOT_ELEMENT, StringUtils, Enum, AsyncMethodBase, EventsService, NgxUtilsModule } from '@stemy/ngx-utils';
5
5
  import { of, merge, Observable, firstValueFrom, BehaviorSubject, combineLatestWith, switchMap, distinctUntilChanged, first, Subject, map, filter } from 'rxjs';
6
6
  import { debounceTime } from 'rxjs/operators';
7
7
  import * as i1 from '@angular/forms';
@@ -16,8 +16,13 @@ import { FormlySelectModule } from '@ngx-formly/core/select';
16
16
 
17
17
  // --- Basic frm constants ---
18
18
  const FORM_ROOT_ID = "__root";
19
+ function formSchemaNotFound(name) {
20
+ console.warn(`Schema with name "${name}" not found.`);
21
+ return [];
22
+ }
19
23
  // --- Module Configuration ---
20
24
  const DEFAULT_NUMERIC_STEP = new InjectionToken("DEFAULT_NUMERIC_STEP");
25
+ const FORM_SCHEMA_NOT_FOUND = new InjectionToken("FORM_SCHEMA_NOT_FOUND");
21
26
 
22
27
  function customizeFormField(...providers) {
23
28
  const factory = cachedFactory(providers);
@@ -337,7 +342,6 @@ function isFieldHidden(field) {
337
342
  const MIN_INPUT_NUM = -1999999999;
338
343
  const MAX_INPUT_NUM = 1999999999;
339
344
  const EDITOR_TYPES = ["php", "json", "html", "css", "scss"];
340
- const CUSTOM_INPUT_TYPES = ["checkbox", "textarea", "wysiwyg", "date", "password"];
341
345
 
342
346
  function validationMessage(errorKey) {
343
347
  const key = `form.error.${errorKey}`;
@@ -671,12 +675,15 @@ function getFormValidationErrors(controls, parentPath = "") {
671
675
  });
672
676
  return errors;
673
677
  }
678
+ const CUSTOM_INPUT_TYPES = ["checkbox", "textarea", "wysiwyg", "date", "password"];
674
679
 
675
680
  class DynamicFormBuilderService {
676
- constructor(injector, events, api, languages, defaultNumericStep) {
681
+ constructor(injector, events, universal, api, rootElement, languages, defaultNumericStep) {
677
682
  this.injector = injector;
678
683
  this.events = events;
684
+ this.universal = universal;
679
685
  this.api = api;
686
+ this.rootElement = rootElement;
680
687
  this.languages = languages;
681
688
  this.defaultNumericStep = defaultNumericStep;
682
689
  const lang = new BehaviorSubject(this.languages.currentLanguage);
@@ -793,13 +800,25 @@ class DynamicFormBuilderService {
793
800
  case "checkbox":
794
801
  data.defaultValue = data.defaultValue ?? false;
795
802
  break;
803
+ case "color":
804
+ const styles = this.rootElement && this.universal.isBrowser
805
+ ? getComputedStyle(this.rootElement)
806
+ : null;
807
+ const value = (!styles ? "#DEDEDE" : null)
808
+ || styles.getPropertyValue("--primary-color")
809
+ || styles.getPropertyValue("--mat-sys-primary")
810
+ || "#DEDEDE";
811
+ data.defaultValue = data.defaultValue ?? value;
812
+ break;
796
813
  case "number":
797
814
  case "integer":
815
+ data.defaultValue = 0;
798
816
  props.min = convertToNumber(data.min, MIN_INPUT_NUM);
799
817
  props.max = convertToNumber(data.max, MAX_INPUT_NUM);
800
818
  break;
801
819
  case "date":
802
820
  case "datetime-local":
821
+ data.defaultValue = data.defaultValue ?? convertToDateFormat(new Date(), type);
803
822
  props.min = convertToDateFormat(data.min, type);
804
823
  props.max = convertToDateFormat(data.max, type);
805
824
  break;
@@ -1153,14 +1172,17 @@ class DynamicFormBuilderService {
1153
1172
  });
1154
1173
  return field;
1155
1174
  }
1156
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormBuilderService, deps: [{ token: i0.Injector }, { token: i2.EventsService }, { token: API_SERVICE }, { token: LANGUAGE_SERVICE }, { token: DEFAULT_NUMERIC_STEP }], target: i0.ɵɵFactoryTarget.Injectable }); }
1175
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormBuilderService, deps: [{ token: i0.Injector }, { token: i2.EventsService }, { token: i2.UniversalService }, { token: API_SERVICE }, { token: ROOT_ELEMENT }, { token: LANGUAGE_SERVICE }, { token: DEFAULT_NUMERIC_STEP }], target: i0.ɵɵFactoryTarget.Injectable }); }
1157
1176
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormBuilderService }); }
1158
1177
  }
1159
1178
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormBuilderService, decorators: [{
1160
1179
  type: Injectable
1161
- }], ctorParameters: () => [{ type: i0.Injector }, { type: i2.EventsService }, { type: undefined, decorators: [{
1180
+ }], ctorParameters: () => [{ type: i0.Injector }, { type: i2.EventsService }, { type: i2.UniversalService }, { type: undefined, decorators: [{
1162
1181
  type: Inject,
1163
1182
  args: [API_SERVICE]
1183
+ }] }, { type: HTMLElement, decorators: [{
1184
+ type: Inject,
1185
+ args: [ROOT_ELEMENT]
1164
1186
  }] }, { type: undefined, decorators: [{
1165
1187
  type: Inject,
1166
1188
  args: [LANGUAGE_SERVICE]
@@ -1602,11 +1624,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.22", ngImpo
1602
1624
  }], ctorParameters: () => [{ type: i2.OpenApiService }, { type: i0.Injector }, { type: DynamicFormBuilderService }] });
1603
1625
 
1604
1626
  class DynamicFormService {
1605
- constructor(fs, fb, injector, api) {
1627
+ constructor(fs, fb, injector, schemaNotFound) {
1606
1628
  this.fs = fs;
1607
1629
  this.fb = fb;
1608
1630
  this.injector = injector;
1609
- this.api = api;
1631
+ this.schemaNotFound = schemaNotFound;
1610
1632
  }
1611
1633
  async getFormFieldsForSchema(name, customizeOrOptions) {
1612
1634
  const group = await this.getFormFieldGroupBySchemaName(name, customizeOrOptions, "getFormFieldsForSchema");
@@ -1617,26 +1639,23 @@ class DynamicFormService {
1617
1639
  }
1618
1640
  async getFormFieldGroupBySchemaName(name, customizeOrOptions, restrictedMethod) {
1619
1641
  const schema = await this.fs.getSchema(name);
1620
- if (!schema) {
1621
- console.warn(`Schema with name "${name}" not found.`);
1622
- return {
1623
- id: FORM_ROOT_ID,
1624
- path: "",
1625
- wrappers: ["form-group"],
1626
- fieldGroup: [],
1627
- props: {},
1628
- hooks: {},
1629
- expressions: {}
1630
- };
1631
- }
1632
1642
  const wrapOptions = await toWrapOptions(customizeOrOptions, this.injector, schema, `"DynamicFormService.${restrictedMethod}" is called from a customizer, which is not allowed. Please use DynamicFormSchemaService instead!`);
1633
- const config = await this.fb.createFormGroup(null, parent => {
1634
- return this.fs.getFormFieldsForSchema(schema, parent, wrapOptions);
1635
- }, {
1643
+ const rootData = {
1636
1644
  label: "",
1637
1645
  hidden: false,
1638
1646
  className: "dynamic-form-root-group"
1639
- }, null, wrapOptions);
1647
+ };
1648
+ let config;
1649
+ if (!schema) {
1650
+ config = await this.fb.createFormGroup(null, async (parent) => {
1651
+ return this.schemaNotFound(name, parent, wrapOptions, this.injector);
1652
+ }, rootData, null, wrapOptions);
1653
+ }
1654
+ else {
1655
+ config = await this.fb.createFormGroup(null, parent => {
1656
+ return this.fs.getFormFieldsForSchema(schema, parent, wrapOptions);
1657
+ }, rootData, null, wrapOptions);
1658
+ }
1640
1659
  const fields = config.fieldGroup || [];
1641
1660
  const fieldGroup = [...fields];
1642
1661
  config.id = FORM_ROOT_ID;
@@ -1757,14 +1776,14 @@ class DynamicFormService {
1757
1776
  }
1758
1777
  });
1759
1778
  }
1760
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormService, deps: [{ token: DynamicFormSchemaService }, { token: DynamicFormBuilderService }, { token: i0.Injector }, { token: API_SERVICE }], target: i0.ɵɵFactoryTarget.Injectable }); }
1779
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormService, deps: [{ token: DynamicFormSchemaService }, { token: DynamicFormBuilderService }, { token: i0.Injector }, { token: FORM_SCHEMA_NOT_FOUND }], target: i0.ɵɵFactoryTarget.Injectable }); }
1761
1780
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormService }); }
1762
1781
  }
1763
1782
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormService, decorators: [{
1764
1783
  type: Injectable
1765
1784
  }], ctorParameters: () => [{ type: DynamicFormSchemaService }, { type: DynamicFormBuilderService }, { type: i0.Injector }, { type: undefined, decorators: [{
1766
1785
  type: Inject,
1767
- args: [API_SERVICE]
1786
+ args: [FORM_SCHEMA_NOT_FOUND]
1768
1787
  }] }] });
1769
1788
 
1770
1789
  const templateTypes = ["control", "label", "input", "prefix", "suffix"];
@@ -2475,6 +2494,10 @@ class NgxDynamicFormModule {
2475
2494
  {
2476
2495
  provide: DEFAULT_NUMERIC_STEP,
2477
2496
  useValue: (config?.defaultNumericStep ?? 1)
2497
+ },
2498
+ {
2499
+ provide: FORM_SCHEMA_NOT_FOUND,
2500
+ useValue: (config?.schemaNotFound ?? formSchemaNotFound)
2478
2501
  }
2479
2502
  ];
2480
2503
  }
@@ -2547,5 +2570,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.22", ngImpo
2547
2570
  * Generated bundle index. Do not edit.
2548
2571
  */
2549
2572
 
2550
- export { AsyncSubmitDirective, DEFAULT_NUMERIC_STEP, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormDateComponent, DynamicFormEditorComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormPasswordComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormTemplateDirective, DynamicFormTemplatePipe, DynamicFormTemplateService, DynamicFormTranslationComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, EDITOR_TYPES, FORM_ROOT_ID, FormArray, FormDate, FormFieldSet, FormGroup, FormInput, FormSelect, FormSerializable, FormStatic, FormUpload, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, RichTranslationModel, TranslationModel, addFieldValidators, arrayLengthValidation, clearFieldArray, controlStatus, controlValues, convertToNumber, customizeFormField, emailValidation, enumValidation, equalsValidation, getFieldByPath, getFieldsByKey, getFieldsByPredicate, getSelectOptions, insertToFieldArray, isFieldHidden, isFieldVisible, jsonValidation, maxLengthValidation, maxValueValidation, minLengthValidation, minValueValidation, phoneValidation, removeFieldValidators, removeFromFieldArray, replaceFieldArray, replaceSpecialChars, requiredValidation, setFieldDefault, setFieldDisabled, setFieldHidden, setFieldHooks, setFieldMinDate, setFieldProp, setFieldProps, setFieldSerialize, setFieldValue, translationValidation };
2573
+ export { AsyncSubmitDirective, DEFAULT_NUMERIC_STEP, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormDateComponent, DynamicFormEditorComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormPasswordComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormTemplateDirective, DynamicFormTemplatePipe, DynamicFormTemplateService, DynamicFormTranslationComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, EDITOR_TYPES, FORM_ROOT_ID, FORM_SCHEMA_NOT_FOUND, FormArray, FormDate, FormFieldSet, FormGroup, FormInput, FormSelect, FormSerializable, FormStatic, FormUpload, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, RichTranslationModel, TranslationModel, addFieldValidators, arrayLengthValidation, clearFieldArray, controlStatus, controlValues, convertToNumber, customizeFormField, emailValidation, enumValidation, equalsValidation, formSchemaNotFound, getFieldByPath, getFieldsByKey, getFieldsByPredicate, getSelectOptions, insertToFieldArray, isFieldHidden, isFieldVisible, jsonValidation, maxLengthValidation, maxValueValidation, minLengthValidation, minValueValidation, phoneValidation, removeFieldValidators, removeFromFieldArray, replaceFieldArray, replaceSpecialChars, requiredValidation, setFieldDefault, setFieldDisabled, setFieldHidden, setFieldHooks, setFieldMinDate, setFieldProp, setFieldProps, setFieldSerialize, setFieldValue, translationValidation };
2551
2574
  //# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map