@planeasyinc/le-angular 0.0.18 → 0.0.20

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,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, signal, Injectable, computed, effect, untracked, Directive, input, ChangeDetectionStrategy, Component, output, forwardRef, ViewContainerRef, Injector, Renderer2, ElementRef, DestroyRef, ChangeDetectorRef, viewChild } from '@angular/core';
2
+ import { InjectionToken, inject, signal, Injectable, computed, effect, untracked, Directive, input, ChangeDetectionStrategy, Component, output, forwardRef, ViewContainerRef, Injector, Renderer2, ElementRef, DestroyRef, viewChild } from '@angular/core';
3
3
  import { HttpContextToken, HttpClient, HttpContext, HttpRequest, HttpEventType } from '@angular/common/http';
4
4
  import { map, filter, distinctUntilChanged, BehaviorSubject, Subject, takeUntil, firstValueFrom, of, tap, catchError, from, concatMap, finalize, fromEvent, startWith } from 'rxjs';
5
5
  import { decodeJwt, UrlFragmentBuilder, normalizeConfig } from '@planeasyinc/le-core';
@@ -1725,13 +1725,27 @@ const traverse = (entity, path, cb) => {
1725
1725
  const isTabJSON = (control) => {
1726
1726
  return control.name.toLowerCase().includes('json');
1727
1727
  };
1728
- const getTabFormValues = (control, engine) => {
1728
+ /**
1729
+ *
1730
+ * @param source Control Config with nested controls
1731
+ * @param target Control Config with json value
1732
+ * @param engine Form Engine
1733
+ *
1734
+ * @description
1735
+ * Traverse source Control Config tree, get latest value from state.
1736
+ * If no value found in state, set target Control Config initial value
1737
+ */
1738
+ const getTabFormValues = (source, target, engine) => {
1729
1739
  const result = {};
1730
- traverse(control, ['meta', 'controls'], (ctrl) => {
1740
+ const targetValueObject = mapJSONToFormValues(target.value);
1741
+ traverse(source, ['meta', 'controls'], (ctrl) => {
1731
1742
  if (!ctrl.id) {
1732
1743
  return;
1733
1744
  }
1734
- const value = engine.values.get(ctrl.id);
1745
+ let value = engine.values.get(ctrl.id);
1746
+ if (value === undefined) {
1747
+ value = targetValueObject[ctrl.id];
1748
+ }
1735
1749
  if (value === undefined) {
1736
1750
  return;
1737
1751
  }
@@ -1743,7 +1757,10 @@ const mapFormValuesToJSON = (values) => {
1743
1757
  return JSON.stringify(values, null, 2);
1744
1758
  };
1745
1759
  const mapJSONToFormValues = (json) => {
1746
- return JSON.parse(json);
1760
+ if (typeof json === 'string') {
1761
+ return JSON.parse(json);
1762
+ }
1763
+ throw new Error('The `json` parameter is not a valid JSON');
1747
1764
  };
1748
1765
  const getTabJSONControl = (control, engine) => {
1749
1766
  let result;
@@ -2018,7 +2035,6 @@ class FormViewComponent {
2018
2035
  attachmentService = inject(FormViewAttachmentService);
2019
2036
  viewportScroller = inject(ViewportScroller);
2020
2037
  toastService = inject(LeToastService);
2021
- cdr = inject(ChangeDetectorRef);
2022
2038
  _isLoading = signal(false);
2023
2039
  _form = signal(null);
2024
2040
  _sections = signal([]);
@@ -2121,8 +2137,8 @@ class FormViewComponent {
2121
2137
  });
2122
2138
  }
2123
2139
  else {
2124
- const value = mapFormValuesToJSON(getTabFormValues(action.source, engine));
2125
2140
  const target = getTabJSONControl(action.target, engine);
2141
+ const value = mapFormValuesToJSON(getTabFormValues(action.source, target, engine));
2126
2142
  engine.values.set(target.id, value);
2127
2143
  }
2128
2144
  }