@planeasyinc/le-angular 0.0.21 → 0.0.22

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, 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
- import { map, filter, distinctUntilChanged, Subject, takeUntil, BehaviorSubject, firstValueFrom, of, tap, catchError, from, concatMap, finalize, fromEvent, startWith } from 'rxjs';
4
+ import { map, filter, distinctUntilChanged, Subject, takeUntil, BehaviorSubject, firstValueFrom, of, tap, catchError, switchMap, from, concatMap, finalize, fromEvent, startWith } from 'rxjs';
5
5
  import { decodeJwt, UrlFragmentBuilder, normalizeConfig } from '@planeasyinc/le-core';
6
6
  import { Location, UpperCasePipe, JsonPipe, DatePipe, ViewportScroller } from '@angular/common';
7
7
  import { CdkDrag } from '@angular/cdk/drag-drop';
@@ -1784,19 +1784,69 @@ const getTabJSONControl = (control, engine) => {
1784
1784
  });
1785
1785
  return result;
1786
1786
  };
1787
+ const mapValueToString = (value) => {
1788
+ if (typeof value === 'object' && value !== null) {
1789
+ if (Array.isArray(value)) {
1790
+ return value.map((chunk) => mapValueToString(chunk)).join('\n');
1791
+ }
1792
+ else {
1793
+ return mapValueToString(Object.entries(value));
1794
+ }
1795
+ }
1796
+ return `${value}`;
1797
+ };
1798
+
1799
+ class ToastListItemComponent {
1800
+ _engine = signal(null);
1801
+ _sections = signal([]);
1802
+ controls = input.required();
1803
+ actions = output();
1804
+ engine = this._engine.asReadonly();
1805
+ sections = this._sections.asReadonly();
1806
+ constructor() {
1807
+ effect((onCleanup) => {
1808
+ const controls = this.controls();
1809
+ const form = adaptForm(controls);
1810
+ const engine = createEngine(form);
1811
+ let cleanup = () => { };
1812
+ untracked(() => {
1813
+ this._engine.set(engine);
1814
+ this._sections.set(form.sections ?? []);
1815
+ cleanup = engine.on('action', ({ action }) => {
1816
+ const actionObj = action;
1817
+ this.actions.emit(actionObj.actions);
1818
+ });
1819
+ });
1820
+ onCleanup(() => {
1821
+ cleanup();
1822
+ });
1823
+ });
1824
+ }
1825
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: ToastListItemComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1826
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.21", type: ToastListItemComponent, isStandalone: true, selector: "le-toast-list-item", inputs: { controls: { classPropertyName: "controls", publicName: "controls", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { actions: "actions" }, ngImport: i0, template: "@if (engine(); as engine) {\n @for (section of sections(); track section) {\n @for (control of section.controls; track control) {\n <fe-field [engine]=\"engine\" [control]=\"control\"></fe-field>\n }\n }\n}\n", dependencies: [{ kind: "component", type: FeFieldHost, selector: "fe-field", inputs: ["engine", "control"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1827
+ }
1828
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: ToastListItemComponent, decorators: [{
1829
+ type: Component,
1830
+ args: [{ selector: 'le-toast-list-item', imports: [FeFieldHost], changeDetection: ChangeDetectionStrategy.OnPush, template: "@if (engine(); as engine) {\n @for (section of sections(); track section) {\n @for (control of section.controls; track control) {\n <fe-field [engine]=\"engine\" [control]=\"control\"></fe-field>\n }\n }\n}\n" }]
1831
+ }], ctorParameters: () => [] });
1787
1832
 
1788
1833
  class ToastListComponent {
1789
1834
  toastService = inject(LeToastService);
1790
1835
  toasts = this.toastService.toasts;
1791
- onButtonClick(actions) {
1792
- actions.forEach((action) => this.toastService.processAction(action));
1836
+ onActions(actions) {
1837
+ actions.forEach((action) => {
1838
+ this.toastService.action$.next(action);
1839
+ if (action.type === 'close_popup') {
1840
+ this.toastService.remove(action.target_id);
1841
+ }
1842
+ });
1793
1843
  }
1794
1844
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: ToastListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1795
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.21", type: ToastListComponent, isStandalone: true, selector: "ng-component", ngImport: i0, template: "@if (toasts().length) {\n <div class=\"le-toast-list\">\n @for (toast of toasts(); track toast.id) {\n <div\n class=\"le-toast\"\n [class.le-toast--success]=\"toast.type === 'success'\"\n [class.le-toast--info]=\"toast.type === 'info'\"\n [class.le-toast--warning]=\"toast.type === 'warning'\"\n [class.le-toast--error]=\"toast.type === 'error'\"\n >\n <div class=\"le-toast-text-list\">\n @for (control of toast.controls; track control) {\n @if (control.type === 'text') {\n <p class=\"le-toast-text\">\n {{ control.value }}\n </p>\n }\n }\n </div>\n\n <div class=\"le-toast-button-list\">\n @for (control of toast.controls; track control) {\n @if (control.type === 'button') {\n <button\n class=\"le-button le-button-stroked\"\n [class.le-button--success]=\"toast.type === 'success'\"\n [class.le-button--info]=\"toast.type === 'info'\"\n [class.le-button--warning]=\"toast.type === 'warning'\"\n [class.le-button--error]=\"toast.type === 'error'\"\n (click)=\"onButtonClick(control.actions)\"\n >\n {{ control.label }}\n </button>\n }\n }\n </div>\n </div>\n }\n </div>\n}\n" });
1845
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.21", type: ToastListComponent, isStandalone: true, selector: "ng-component", ngImport: i0, template: "@if (toasts().length) {\n <div class=\"le-toast-list\">\n @for (toast of toasts(); track toast.id) {\n <div\n class=\"le-toast\"\n [class.le-toast--success]=\"toast.type === 'success'\"\n [class.le-toast--info]=\"toast.type === 'info'\"\n [class.le-toast--warning]=\"toast.type === 'warning'\"\n [class.le-toast--error]=\"toast.type === 'error'\"\n >\n <le-toast-list-item\n [controls]=\"toast.controls\"\n (actions)=\"onActions($event)\"\n ></le-toast-list-item>\n </div>\n }\n </div>\n}\n", dependencies: [{ kind: "component", type: ToastListItemComponent, selector: "le-toast-list-item", inputs: ["controls"], outputs: ["actions"] }] });
1796
1846
  }
1797
1847
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: ToastListComponent, decorators: [{
1798
1848
  type: Component,
1799
- args: [{ template: "@if (toasts().length) {\n <div class=\"le-toast-list\">\n @for (toast of toasts(); track toast.id) {\n <div\n class=\"le-toast\"\n [class.le-toast--success]=\"toast.type === 'success'\"\n [class.le-toast--info]=\"toast.type === 'info'\"\n [class.le-toast--warning]=\"toast.type === 'warning'\"\n [class.le-toast--error]=\"toast.type === 'error'\"\n >\n <div class=\"le-toast-text-list\">\n @for (control of toast.controls; track control) {\n @if (control.type === 'text') {\n <p class=\"le-toast-text\">\n {{ control.value }}\n </p>\n }\n }\n </div>\n\n <div class=\"le-toast-button-list\">\n @for (control of toast.controls; track control) {\n @if (control.type === 'button') {\n <button\n class=\"le-button le-button-stroked\"\n [class.le-button--success]=\"toast.type === 'success'\"\n [class.le-button--info]=\"toast.type === 'info'\"\n [class.le-button--warning]=\"toast.type === 'warning'\"\n [class.le-button--error]=\"toast.type === 'error'\"\n (click)=\"onButtonClick(control.actions)\"\n >\n {{ control.label }}\n </button>\n }\n }\n </div>\n </div>\n }\n </div>\n}\n" }]
1849
+ args: [{ imports: [ToastListItemComponent], template: "@if (toasts().length) {\n <div class=\"le-toast-list\">\n @for (toast of toasts(); track toast.id) {\n <div\n class=\"le-toast\"\n [class.le-toast--success]=\"toast.type === 'success'\"\n [class.le-toast--info]=\"toast.type === 'info'\"\n [class.le-toast--warning]=\"toast.type === 'warning'\"\n [class.le-toast--error]=\"toast.type === 'error'\"\n >\n <le-toast-list-item\n [controls]=\"toast.controls\"\n (actions)=\"onActions($event)\"\n ></le-toast-list-item>\n </div>\n }\n </div>\n}\n" }]
1800
1850
  }] });
1801
1851
 
1802
1852
  let ID = 100_000_000;
@@ -1805,6 +1855,7 @@ class LeToastService {
1805
1855
  overlay = inject(Overlay);
1806
1856
  _toasts = signal([]);
1807
1857
  toasts = this._toasts.asReadonly();
1858
+ action$ = new Subject();
1808
1859
  constructor() {
1809
1860
  effect(() => {
1810
1861
  const toasts = this._toasts();
@@ -1834,11 +1885,6 @@ class LeToastService {
1834
1885
  remove(id) {
1835
1886
  this._toasts.update((toasts) => toasts.filter((toast) => toast.id !== id));
1836
1887
  }
1837
- processAction(action) {
1838
- if (action.type === 'close_popup') {
1839
- this.remove(action.target);
1840
- }
1841
- }
1842
1888
  show() {
1843
1889
  if (this.overlayRef)
1844
1890
  return;
@@ -1854,19 +1900,26 @@ class LeToastService {
1854
1900
  }
1855
1901
  buildToast(type, messages) {
1856
1902
  const id = `${type}_${ID++}`;
1857
- const textControls = messages.map((message) => ({
1858
- type: 'text',
1903
+ return {
1904
+ id,
1905
+ type,
1906
+ controls: [...this.buildTextControls(id, messages), this.buildButtonControl(id)],
1907
+ };
1908
+ }
1909
+ buildTextControls(id, messages) {
1910
+ return messages.map((message, index) => ({
1911
+ type: 'paragraph',
1859
1912
  value: message,
1913
+ name: `${id}_${index}`
1860
1914
  }));
1861
- const buttonControl = {
1915
+ }
1916
+ buildButtonControl(id) {
1917
+ return {
1862
1918
  type: 'button',
1863
1919
  label: 'Ok',
1864
- actions: [{ type: 'close_popup', target: id }],
1865
- };
1866
- return {
1867
- id,
1868
- type,
1869
- controls: [...textControls, buttonControl],
1920
+ hideLabel: true,
1921
+ name: `${id}_button`,
1922
+ actions: [{ type: 'close_popup', target_id: id }],
1870
1923
  };
1871
1924
  }
1872
1925
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: LeToastService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
@@ -2118,13 +2171,18 @@ class FormViewComponent {
2118
2171
  this.viewportScroller.scrollToPosition([0, 0]);
2119
2172
  return of(null);
2120
2173
  },
2121
- show_popup: (action) => {
2174
+ show_popup: (action, response) => {
2122
2175
  this.toastService.notify({
2123
- ...action.item,
2176
+ controls: this.populatePopupControlsWithResponse(action.controls, response),
2177
+ id: action.id,
2124
2178
  type: 'success',
2125
2179
  });
2126
2180
  return of(null);
2127
2181
  },
2182
+ close_popup: (action) => {
2183
+ this.toastService.remove(action.target_id);
2184
+ return of(null);
2185
+ },
2128
2186
  open_url: (action) => {
2129
2187
  window.open(action.url, '_blank');
2130
2188
  return of(null);
@@ -2199,6 +2257,9 @@ class FormViewComponent {
2199
2257
  this.init(form);
2200
2258
  });
2201
2259
  });
2260
+ this.toastService.action$
2261
+ .pipe(switchMap((action) => this.processAction(action)), takeUntilDestroyed())
2262
+ .subscribe();
2202
2263
  }
2203
2264
  init(form) {
2204
2265
  this._sections.set(this.sortSections(form.sections));
@@ -2294,6 +2355,19 @@ class FormViewComponent {
2294
2355
  }))
2295
2356
  .subscribe();
2296
2357
  }
2358
+ populatePopupControlsWithResponse(controls, response) {
2359
+ return controls.map((control) => {
2360
+ if (isPlaceholder(control.value)) {
2361
+ const path = getPlaceholderValue(control.value);
2362
+ const value = mapValueToString(getValueByPath({ response }, path));
2363
+ return {
2364
+ ...control,
2365
+ value,
2366
+ };
2367
+ }
2368
+ return control;
2369
+ });
2370
+ }
2297
2371
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: FormViewComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2298
2372
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.21", type: FormViewComponent, isStandalone: true, selector: "form-view", inputs: { node: { classPropertyName: "node", publicName: "node", isSignal: true, isRequired: true, transformFunction: null }, config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { event: "event" }, providers: [FormViewAttachmentService], ngImport: i0, template: "<h2>{{ node()?.title }}</h2>\n\n@if (isLoading()) {\n <app-loading-view [rowCount]=\"5\"></app-loading-view>\n} @else {\n @if (data(); as data) {\n <le-form-renderer\n [config]=\"config()\"\n [engine]=\"data.engine\"\n [sections]=\"data.sections\"\n [customCss]=\"data.customCss\"\n [topLevelControls]=\"data.topLevelControls\"\n (event)=\"event.emit($event)\"\n ></le-form-renderer>\n }\n}\n", dependencies: [{ kind: "component", type: LoadingViewComponent, selector: "app-loading-view", inputs: ["headerHeight", "rowHeight", "rowCount"] }, { kind: "component", type: FormRendererComponent, selector: "le-form-renderer", inputs: ["engine", "sections", "topLevelControls", "customCss", "config"], outputs: ["event"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2299
2373
  }