@stemy/ngx-dynamic-form 19.8.13 → 19.8.15

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,6 +1,6 @@
1
1
  import * as i2 from '@stemy/ngx-utils';
2
2
  import { cachedFactory, ReflectUtils, ObjectUtils, LANGUAGE_SERVICE, FactoryDependencies, ForbiddenZone, ArrayUtils, API_SERVICE, StringUtils, AsyncMethodBase, EventsService, NgxUtilsModule } from '@stemy/ngx-utils';
3
- import { of, merge, Observable, firstValueFrom, BehaviorSubject, combineLatestWith, switchMap, distinctUntilChanged, first, Subject } from 'rxjs';
3
+ import { of, merge, Observable, firstValueFrom, BehaviorSubject, combineLatestWith, switchMap, distinctUntilChanged, first, Subject, filter } from 'rxjs';
4
4
  import { debounceTime } from 'rxjs/operators';
5
5
  import { __decorate } from 'tslib';
6
6
  import * as i0 from '@angular/core';
@@ -256,6 +256,9 @@ function setFieldProps(field, values) {
256
256
  function setFieldProp(field, prop, value) {
257
257
  return setFieldProps(field, { [prop]: value });
258
258
  }
259
+ function setFieldSerialize(field, serialize = true) {
260
+ field.serialize = ObjectUtils.isFunction(serialize) ? serialize : () => serialize;
261
+ }
259
262
  function setFieldHidden(field, hidden = true) {
260
263
  setFieldProp(field, "__hidden", ObjectUtils.isFunction(hidden) ? hidden : () => hidden);
261
264
  }
@@ -541,11 +544,15 @@ async function toWrapOptions(customizeOrOptions, injector, schema, errorMsg) {
541
544
  let schemaOptions = customizeOrOptions;
542
545
  if (!ObjectUtils.isObject(schemaOptions)) {
543
546
  schemaOptions = {
547
+ context: {},
544
548
  fieldCustomizer: customizeOrOptions
545
549
  };
546
550
  }
547
551
  return new ConfigForSchemaWrap(schemaOptions, "wrap", injector, schema);
548
552
  }
553
+ function toStringArray(value) {
554
+ return (Array.isArray(value) ? value : String(value || "").split(",")).filter(ObjectUtils.isStringWithValue);
555
+ }
549
556
  function handleConfigs(configs) {
550
557
  return Array.isArray(configs) ? configs : [configs];
551
558
  }
@@ -838,8 +845,8 @@ class DynamicFormBuilderService {
838
845
  if (lang && translation) {
839
846
  // Use translation component if the sub items are correct
840
847
  array.type = "translation";
841
- lang.serialize = () => true;
842
848
  setFieldHidden(lang);
849
+ setFieldSerialize(lang);
843
850
  setFieldProp(translation, "label", "");
844
851
  }
845
852
  this.setExpressions(array.fieldArray, options);
@@ -939,6 +946,7 @@ class DynamicFormBuilderService {
939
946
  const field = {
940
947
  ...this.createFormSerializer(key, data),
941
948
  fieldSet: String(data.fieldSet || ""),
949
+ purposes: toStringArray(data.purposes),
942
950
  priority: isNaN(data.priority) ? Number.MAX_SAFE_INTEGER : Number(data.priority),
943
951
  wrappers: wrappers.filter(ObjectUtils.isDefined),
944
952
  type: data.componentType || type,
@@ -1145,6 +1153,7 @@ class DynamicFormSchemaService {
1145
1153
  layout: property.layout,
1146
1154
  serialize: property.serialize,
1147
1155
  fieldSet: property.fieldSet,
1156
+ purposes: property.purposes || property.purpose,
1148
1157
  priority: property.priority,
1149
1158
  componentType: property.componentType,
1150
1159
  wrappers: wrappers.filter(ObjectUtils.isStringWithValue),
@@ -1508,24 +1517,26 @@ class DynamicFormService {
1508
1517
  group.updateValueAndValidity();
1509
1518
  });
1510
1519
  }
1511
- async serializeForm(form, validate = true) {
1520
+ async serializeForm(form, validate = true, ...purposes) {
1512
1521
  const fields = untracked(() => form.config());
1513
1522
  if (!fields)
1514
1523
  return null;
1515
1524
  if (validate) {
1516
1525
  await this.validateForm(form);
1517
1526
  }
1518
- return this.serialize(fields);
1527
+ return this.serialize(fields, purposes);
1519
1528
  }
1520
- async serialize(fields) {
1529
+ async serialize(fields, purposes = []) {
1521
1530
  const result = {};
1531
+ purposes = purposes ?? [];
1522
1532
  if (!fields)
1523
1533
  return result;
1524
1534
  for (const field of fields) {
1525
1535
  const serializer = field.serializer;
1526
1536
  const key = `${field.key}`;
1527
1537
  const shouldSerialize = field.serialize?.(field, this.injector) ?? field.props?.hidden !== true;
1528
- if (!shouldSerialize) {
1538
+ const includes = purposes.length > 0 ? Array.prototype.includes.bind(field.purposes ?? []) : null;
1539
+ if (!shouldSerialize || (includes && !includes(purposes))) {
1529
1540
  continue;
1530
1541
  }
1531
1542
  if (ObjectUtils.isFunction(serializer)) {
@@ -1534,7 +1545,7 @@ class DynamicFormService {
1534
1545
  }
1535
1546
  const control = field.formControl;
1536
1547
  if (field.fieldGroup) {
1537
- const group = await this.serialize(field.fieldGroup);
1548
+ const group = await this.serialize(field.fieldGroup, purposes);
1538
1549
  if (field.key && !field.asFieldSet) {
1539
1550
  result[key] = !field.fieldArray ? group : Object.values(group);
1540
1551
  continue;
@@ -1778,6 +1789,8 @@ class DynamicFormComponent {
1778
1789
  data = input({});
1779
1790
  fields = input(null);
1780
1791
  fieldChanges = new Subject();
1792
+ init = this.fieldChanges.pipe(first());
1793
+ valueChanges = this.fieldChanges.pipe(filter(c => c.type === "valueChanges"));
1781
1794
  language = toSignal(this.events.languageChanged, {
1782
1795
  initialValue: this.languages.currentLanguage
1783
1796
  });
@@ -1814,7 +1827,9 @@ class DynamicFormComponent {
1814
1827
  });
1815
1828
  status = computed(() => this.status$.value());
1816
1829
  onSubmit = output();
1817
- onChanges = outputFromObservable(this.fieldChanges);
1830
+ onFieldChanges = outputFromObservable(this.fieldChanges);
1831
+ onValueChanges = outputFromObservable(this.valueChanges);
1832
+ onInit = outputFromObservable(this.init);
1818
1833
  options = {
1819
1834
  fieldChanges: this.fieldChanges,
1820
1835
  formState: {
@@ -1839,8 +1854,8 @@ class DynamicFormComponent {
1839
1854
  reset() {
1840
1855
  this.options?.resetModel?.();
1841
1856
  }
1842
- serialize(validate = true) {
1843
- return this.forms.serializeForm(this, validate);
1857
+ serialize(validate = true, ...purposes) {
1858
+ return this.forms.serializeForm(this, validate, ...purposes);
1844
1859
  }
1845
1860
  getField(path) {
1846
1861
  const config = untracked(() => this.config());
@@ -1851,7 +1866,7 @@ class DynamicFormComponent {
1851
1866
  return field?.formControl ?? null;
1852
1867
  }
1853
1868
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormComponent, deps: [{ token: DynamicFormService }], target: i0.ɵɵFactoryTarget.Component });
1854
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.19", 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 }, legacyLabels: { classPropertyName: "legacyLabels", publicName: "legacyLabels", 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 });
1869
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.19", 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 }, legacyLabels: { classPropertyName: "legacyLabels", publicName: "legacyLabels", 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", onFieldChanges: "onFieldChanges", onValueChanges: "onValueChanges", onInit: "onInit" }, 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 });
1855
1870
  }
1856
1871
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImport: i0, type: DynamicFormComponent, decorators: [{
1857
1872
  type: Component,
@@ -2121,5 +2136,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImpo
2121
2136
  * Generated bundle index. Do not edit.
2122
2137
  */
2123
2138
 
2124
- export { AsyncSubmitDirective, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormTranslationComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, EDITOR_FORMATS, FORM_ROOT_ID, FormArray, FormFieldSet, FormGroup, FormInput, FormSelect, FormSerializable, FormStatic, FormUpload, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, RichTranslationModel, TranslationModel, addFieldValidators, arrayLengthValidation, clearFieldArray, controlStatus, controlValues, convertToDate, convertToDateFormat, convertToNumber, customizeFormField, emailValidation, getFieldByPath, getFieldsByKey, getFieldsByPredicate, getSelectOptions, insertToFieldArray, isFieldHidden, isFieldVisible, jsonValidation, maxLengthValidation, maxValueValidation, minLengthValidation, minValueValidation, phoneValidation, removeFieldValidators, removeFromFieldArray, replaceFieldArray, replaceSpecialChars, requiredValidation, setFieldDefault, setFieldDisabled, setFieldHidden, setFieldHooks, setFieldProp, setFieldProps, setFieldValue, translationValidation };
2139
+ export { AsyncSubmitDirective, DynamicFieldType, DynamicFormAlertComponent, DynamicFormArrayComponent, DynamicFormBuilderService, DynamicFormChipsComponent, DynamicFormComponent, DynamicFormFieldComponent, DynamicFormFieldsetComponent, DynamicFormGroupComponent, DynamicFormSchemaService, DynamicFormService, DynamicFormStaticComponent, DynamicFormTranslationComponent, DynamicFormUploadComponent, DynamicFormWysiwygComponent, EDITOR_FORMATS, FORM_ROOT_ID, FormArray, FormFieldSet, FormGroup, FormInput, FormSelect, FormSerializable, FormStatic, FormUpload, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, RichTranslationModel, TranslationModel, addFieldValidators, arrayLengthValidation, clearFieldArray, controlStatus, controlValues, convertToDate, convertToDateFormat, convertToNumber, customizeFormField, emailValidation, getFieldByPath, getFieldsByKey, getFieldsByPredicate, getSelectOptions, insertToFieldArray, isFieldHidden, isFieldVisible, jsonValidation, maxLengthValidation, maxValueValidation, minLengthValidation, minValueValidation, phoneValidation, removeFieldValidators, removeFromFieldArray, replaceFieldArray, replaceSpecialChars, requiredValidation, setFieldDefault, setFieldDisabled, setFieldHidden, setFieldHooks, setFieldProp, setFieldProps, setFieldSerialize, setFieldValue, translationValidation };
2125
2140
  //# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map