@stemy/ngx-dynamic-form 19.9.39 → 19.9.41

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.
@@ -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}`;
@@ -611,6 +615,12 @@ class ConfigForSchemaWrap {
611
615
  const res = await ForbiddenZone.run("customizer", () => this.fieldCustomizer(field, this.forCustomizer(), this.injector, property, schema));
612
616
  return !res ? [field] : handleConfigs(res);
613
617
  }
618
+ options(opts) {
619
+ return new ConfigForSchemaWrap({
620
+ ...this.opts,
621
+ ...opts
622
+ }, this.mode, this.injector, this.schema);
623
+ }
614
624
  forCustomizer() {
615
625
  return new ConfigForSchemaWrap(this.opts, "customizer", this.injector, this.schema);
616
626
  }
@@ -618,7 +628,7 @@ class ConfigForSchemaWrap {
618
628
  return new ConfigForSchemaWrap(this.opts, this.mode, this.injector, schema);
619
629
  }
620
630
  }
621
- async function toWrapOptions(customizeOrOptions, injector, schema, errorMsg) {
631
+ function toWrapOptions(customizeOrOptions, injector, schema, errorMsg) {
622
632
  if (errorMsg && ForbiddenZone.isForbidden("customizer")) {
623
633
  throw new Error(errorMsg);
624
634
  }
@@ -671,6 +681,7 @@ function getFormValidationErrors(controls, parentPath = "") {
671
681
  });
672
682
  return errors;
673
683
  }
684
+ const CUSTOM_INPUT_TYPES = ["checkbox", "textarea", "wysiwyg", "date", "password"];
674
685
 
675
686
  class DynamicFormBuilderService {
676
687
  constructor(injector, events, universal, api, rootElement, languages, defaultNumericStep) {
@@ -685,7 +696,7 @@ class DynamicFormBuilderService {
685
696
  this.events.languageChanged.subscribe(value => lang.next(value));
686
697
  this.language = lang;
687
698
  }
688
- resolveFormFields(type, parent, options) {
699
+ resolveFormFields(type, parent, options, fieldSet) {
689
700
  const target = type || { prototype: null };
690
701
  const prototype = target.prototype || target;
691
702
  const fields = ReflectUtils.getMetadata("dynamicFormFields", prototype) || new Set();
@@ -695,6 +706,7 @@ class DynamicFormBuilderService {
695
706
  const builder = ReflectUtils.getMetadata("dynamicFormField", prototype, key);
696
707
  const field = builder(this, parent, options);
697
708
  if (field) {
709
+ field.fieldSet = field.fieldSet || fieldSet;
698
710
  result.push(field);
699
711
  }
700
712
  }
@@ -1619,11 +1631,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.22", ngImpo
1619
1631
  }], ctorParameters: () => [{ type: i2.OpenApiService }, { type: i0.Injector }, { type: DynamicFormBuilderService }] });
1620
1632
 
1621
1633
  class DynamicFormService {
1622
- constructor(fs, fb, injector, api) {
1634
+ constructor(fs, fb, injector, schemaNotFound) {
1623
1635
  this.fs = fs;
1624
1636
  this.fb = fb;
1625
1637
  this.injector = injector;
1626
- this.api = api;
1638
+ this.schemaNotFound = schemaNotFound;
1627
1639
  }
1628
1640
  async getFormFieldsForSchema(name, customizeOrOptions) {
1629
1641
  const group = await this.getFormFieldGroupBySchemaName(name, customizeOrOptions, "getFormFieldsForSchema");
@@ -1634,26 +1646,23 @@ class DynamicFormService {
1634
1646
  }
1635
1647
  async getFormFieldGroupBySchemaName(name, customizeOrOptions, restrictedMethod) {
1636
1648
  const schema = await this.fs.getSchema(name);
1637
- if (!schema) {
1638
- console.warn(`Schema with name "${name}" not found.`);
1639
- return {
1640
- id: FORM_ROOT_ID,
1641
- path: "",
1642
- wrappers: ["form-group"],
1643
- fieldGroup: [],
1644
- props: {},
1645
- hooks: {},
1646
- expressions: {}
1647
- };
1648
- }
1649
1649
  const wrapOptions = await toWrapOptions(customizeOrOptions, this.injector, schema, `"DynamicFormService.${restrictedMethod}" is called from a customizer, which is not allowed. Please use DynamicFormSchemaService instead!`);
1650
- const config = await this.fb.createFormGroup(null, parent => {
1651
- return this.fs.getFormFieldsForSchema(schema, parent, wrapOptions);
1652
- }, {
1650
+ const rootData = {
1653
1651
  label: "",
1654
1652
  hidden: false,
1655
1653
  className: "dynamic-form-root-group"
1656
- }, null, wrapOptions);
1654
+ };
1655
+ let config;
1656
+ if (!schema) {
1657
+ config = await this.fb.createFormGroup(null, async (parent) => {
1658
+ return this.schemaNotFound(name, parent, wrapOptions, this.injector);
1659
+ }, rootData, null, wrapOptions);
1660
+ }
1661
+ else {
1662
+ config = await this.fb.createFormGroup(null, parent => {
1663
+ return this.fs.getFormFieldsForSchema(schema, parent, wrapOptions);
1664
+ }, rootData, null, wrapOptions);
1665
+ }
1657
1666
  const fields = config.fieldGroup || [];
1658
1667
  const fieldGroup = [...fields];
1659
1668
  config.id = FORM_ROOT_ID;
@@ -1774,14 +1783,14 @@ class DynamicFormService {
1774
1783
  }
1775
1784
  });
1776
1785
  }
1777
- 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 }); }
1786
+ 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 }); }
1778
1787
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormService }); }
1779
1788
  }
1780
1789
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.22", ngImport: i0, type: DynamicFormService, decorators: [{
1781
1790
  type: Injectable
1782
1791
  }], ctorParameters: () => [{ type: DynamicFormSchemaService }, { type: DynamicFormBuilderService }, { type: i0.Injector }, { type: undefined, decorators: [{
1783
1792
  type: Inject,
1784
- args: [API_SERVICE]
1793
+ args: [FORM_SCHEMA_NOT_FOUND]
1785
1794
  }] }] });
1786
1795
 
1787
1796
  const templateTypes = ["control", "label", "input", "prefix", "suffix"];
@@ -2492,6 +2501,10 @@ class NgxDynamicFormModule {
2492
2501
  {
2493
2502
  provide: DEFAULT_NUMERIC_STEP,
2494
2503
  useValue: (config?.defaultNumericStep ?? 1)
2504
+ },
2505
+ {
2506
+ provide: FORM_SCHEMA_NOT_FOUND,
2507
+ useValue: (config?.schemaNotFound ?? formSchemaNotFound)
2495
2508
  }
2496
2509
  ];
2497
2510
  }
@@ -2564,5 +2577,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.22", ngImpo
2564
2577
  * Generated bundle index. Do not edit.
2565
2578
  */
2566
2579
 
2567
- 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 };
2580
+ 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 };
2568
2581
  //# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map