dolfo-angular 1.208.0 → 1.210.0

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,13 +1,14 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, Input, ChangeDetectionStrategy, Component, InjectionToken, Injectable, inject, Inject, Pipe, EventEmitter, Output, ViewChild, signal, forwardRef, booleanAttribute, ChangeDetectorRef, ViewChildren, TemplateRef, ContentChild, EnvironmentInjector, createComponent, Injector, NgModule } from '@angular/core';
2
+ import { Directive, Input, ChangeDetectionStrategy, Component, InjectionToken, Injectable, inject, Inject, signal, Pipe, EventEmitter, Output, ViewChild, forwardRef, booleanAttribute, ChangeDetectorRef, ViewChildren, TemplateRef, ContentChild, EnvironmentInjector, createComponent, Injector, NgModule } from '@angular/core';
3
3
  import * as i1$1 from '@angular/forms';
4
4
  import { ControlContainer, FormControl, Validators, NG_VALUE_ACCESSOR, NG_VALIDATORS, FormGroupDirective, FormGroup, ReactiveFormsModule } from '@angular/forms';
5
- import { BehaviorSubject, map, tap, distinctUntilChanged, filter, fromEvent, delay, mergeMap, catchError, of, race, zip } from 'rxjs';
5
+ import { BehaviorSubject, map, tap, distinctUntilChanged, filter, mergeMap, of, delay, catchError, throwError, zip, fromEvent, race } from 'rxjs';
6
6
  import * as i1 from '@angular/common';
7
- import { formatDate, DecimalPipe, CommonModule } from '@angular/common';
8
- import { HttpClient } from '@angular/common/http';
7
+ import { formatDate, DecimalPipe, APP_BASE_HREF, CommonModule } from '@angular/common';
8
+ import { HttpClient, HttpErrorResponse } from '@angular/common/http';
9
9
  import * as i1$2 from '@angular/platform-browser';
10
10
  import { DomSanitizer } from '@angular/platform-browser';
11
+ import * as i2 from '@angular/router';
11
12
 
12
13
  class Subscriptable {
13
14
  subs = [];
@@ -126,6 +127,25 @@ const ICON_COMPONENT = new InjectionToken("ICON_COMPONENT", {
126
127
  factory: () => IconComponent
127
128
  });
128
129
 
130
+ const ROUTE_CHECK_SERVICE = new InjectionToken("ROUTE_CHECK_SERVICE", {
131
+ providedIn: "root",
132
+ factory: () => {
133
+ throw new Error("RouteCheckService not provided");
134
+ }
135
+ });
136
+
137
+ var StoreLists;
138
+ (function (StoreLists) {
139
+ StoreLists[StoreLists["EMPTY"] = 0] = "EMPTY";
140
+ })(StoreLists || (StoreLists = {}));
141
+ var StorageValues;
142
+ (function (StorageValues) {
143
+ StorageValues["TOKEN"] = "token";
144
+ StorageValues["LANG"] = "lang";
145
+ })(StorageValues || (StorageValues = {}));
146
+ const MAX_DEVICE_SIZE = 750;
147
+ const MAX_SMALL_DEVICE = 500;
148
+
129
149
  const TRANSLATE_STORAGE_KEY = "dolfo-lang-stored";
130
150
  const LANGUAGE_TOKEN = new InjectionToken("LANGUAGE_TOKEN");
131
151
  const provideDolfoLanguages = (langs, defaultLanguage) => ({
@@ -273,6 +293,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
273
293
  }]
274
294
  }], ctorParameters: () => [{ type: TranslateService }] });
275
295
 
296
+ class DialogUtilsService {
297
+ dialogService;
298
+ translateService;
299
+ constructor(dialogService, translateService) {
300
+ this.dialogService = dialogService;
301
+ this.translateService = translateService;
302
+ }
303
+ showLoading$ = (obs) => mergeMap(res => of(res).pipe(delay(0), tap(() => this.dialogService.showLoading().subscribe()), mergeMap(res => obs(res)), catchError(err => {
304
+ this.closeLatestDialog();
305
+ return throwError(() => err);
306
+ })));
307
+ hideLoading = () => this.closeLatestDialog();
308
+ closeLatestDialog = () => this.dialogService.close();
309
+ closeWithAction = (data) => {
310
+ this.dialogService.action({ type: DialogActionType.OK, data });
311
+ this.closeLatestDialog();
312
+ };
313
+ openDialogComponent = (component) => this.dialogService.openDialogComponent(component);
314
+ openDialog = (input) => this.dialogService.openDialog(input);
315
+ askConfirmAndLoad = (input, obs, getDialogResp = false) => this.dialogService.openDialog({
316
+ title: this.translateService.translate(input.title),
317
+ message: this.translateService.translate(input.message),
318
+ type: "confirm",
319
+ hideCloseX: input.hideCloseX,
320
+ width: input.width
321
+ }).pipe(filter(res => res.type === DialogActionType.OK || getDialogResp), this.showLoading$(res => obs(res.type)), tap(() => this.hideLoading()));
322
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DialogUtilsService, deps: [{ token: DialogService }, { token: TranslateService }], target: i0.ɵɵFactoryTarget.Injectable });
323
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DialogUtilsService, providedIn: "root" });
324
+ }
325
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DialogUtilsService, decorators: [{
326
+ type: Injectable,
327
+ args: [{
328
+ providedIn: "root"
329
+ }]
330
+ }], ctorParameters: () => [{ type: DialogService }, { type: TranslateService }] });
331
+
276
332
  class NotificationService {
277
333
  notification$ = new BehaviorSubject(null);
278
334
  history$ = new BehaviorSubject([]);
@@ -309,6 +365,72 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
309
365
  }]
310
366
  }] });
311
367
 
368
+ class RouteCheckService {
369
+ storeService = inject(StoreService);
370
+ routeService = inject(ROUTE_CHECK_SERVICE);
371
+ canActivate({ routeConfig }) {
372
+ if (!this.storeService.isInitialized())
373
+ return false;
374
+ return this.routeService.load$().pipe(catchError(() => of(null)), mergeMap(() => this.routeService.checkRoute(routeConfig.path)));
375
+ }
376
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RouteCheckService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
377
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RouteCheckService, providedIn: "root" });
378
+ }
379
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: RouteCheckService, decorators: [{
380
+ type: Injectable,
381
+ args: [{
382
+ providedIn: "root"
383
+ }]
384
+ }] });
385
+
386
+ class StoreService extends Subscriptable {
387
+ appInitialized = signal(false, ...(ngDevMode ? [{ debugName: "appInitialized" }] : /* istanbul ignore next */ []));
388
+ constructor() {
389
+ super();
390
+ this.addSubscription(zip([
391
+ fromEvent(window, "keydown").pipe(filter(e => !this.isPressingCtrl() && e.ctrlKey), tap(() => this.setCtrlKey(true))),
392
+ fromEvent(window, "keyup").pipe(filter(e => this.isPressingCtrl() && e.key === "Control"), tap(() => this.setCtrlKey(false))),
393
+ fromEvent(window, "blur").pipe(filter(() => this.isPressingCtrl()), tap(() => this.setCtrlKey(false)))
394
+ ]).subscribe());
395
+ }
396
+ store$ = new BehaviorSubject({
397
+ lists: {},
398
+ entities: {},
399
+ pressingCtrl: false
400
+ });
401
+ addList = (key, list) => this.store$.next({
402
+ ...this.store$.getValue(),
403
+ lists: {
404
+ ...this.store$.getValue().lists,
405
+ [key]: list
406
+ }
407
+ });
408
+ getList = (key) => this.store$.getValue().lists[key];
409
+ addEntity = (key, entity) => this.store$.next({
410
+ ...this.store$.getValue(),
411
+ entities: {
412
+ ...this.store$.getValue().entities,
413
+ [key]: entity
414
+ }
415
+ });
416
+ getEntity = (key) => this.store$.getValue().entities[key];
417
+ setCtrlKey = (pressingCtrl) => this.store$.next({
418
+ ...this.store$.getValue(),
419
+ pressingCtrl
420
+ });
421
+ isPressingCtrl = () => this.store$.getValue().pressingCtrl;
422
+ isInitialized = () => this.appInitialized();
423
+ initialize = () => this.appInitialized.set(true);
424
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: StoreService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
425
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: StoreService, providedIn: "root" });
426
+ }
427
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: StoreService, decorators: [{
428
+ type: Injectable,
429
+ args: [{
430
+ providedIn: "root"
431
+ }]
432
+ }], ctorParameters: () => [] });
433
+
312
434
  class TooltipService {
313
435
  tooltip$ = new BehaviorSubject(null);
314
436
  showTooltip = (input) => this.tooltip$.next(input);
@@ -987,7 +1109,7 @@ class Formable extends Subscriptable {
987
1109
  control.markAsTouched();
988
1110
  control.updateValueAndValidity();
989
1111
  if (control.invalid && !focused) {
990
- this.inputs.toArray().find(i => i.formControlName === key).container.focus();
1112
+ this.inputs.toArray().find(i => i.formControlName === key).container?.focus();
991
1113
  focused = true;
992
1114
  }
993
1115
  });
@@ -2064,6 +2186,49 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
2064
2186
  type: Input
2065
2187
  }] } });
2066
2188
 
2189
+ class NavigateDirective extends Subscriptable {
2190
+ elementRef;
2191
+ url;
2192
+ isLink;
2193
+ publicUrl = inject(APP_BASE_HREF);
2194
+ constructor(storeService, router, elementRef) {
2195
+ super();
2196
+ this.elementRef = elementRef;
2197
+ this.isLink = elementRef.nativeElement.tagName.toLocaleLowerCase() === "a";
2198
+ this.addSubscription(fromEvent(elementRef.nativeElement, "click").subscribe(e => {
2199
+ if (this.isLink)
2200
+ e.preventDefault();
2201
+ if (storeService.isPressingCtrl())
2202
+ this.openBlank();
2203
+ else
2204
+ router.navigateByUrl(this.url);
2205
+ }));
2206
+ this.addSubscription(fromEvent(elementRef.nativeElement, "mousedown").pipe(filter(e => e.button === 1)).subscribe(e => {
2207
+ if (this.isLink)
2208
+ e.stopPropagation();
2209
+ else
2210
+ this.openBlank();
2211
+ }));
2212
+ }
2213
+ ngOnChanges(changes) {
2214
+ if ((this.isLink || (changes.url && changes.url.currentValue !== this.url)) && !!this.url)
2215
+ this.elementRef.nativeElement.setAttribute("href", this.url);
2216
+ }
2217
+ openBlank = () => window.open(this.publicUrl + this.url, "_blank");
2218
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NavigateDirective, deps: [{ token: StoreService }, { token: i2.Router }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
2219
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.9", type: NavigateDirective, isStandalone: false, selector: "[dolfoNavigate]", inputs: { url: ["dolfoNavigate", "url"] }, usesInheritance: true, usesOnChanges: true, ngImport: i0 });
2220
+ }
2221
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NavigateDirective, decorators: [{
2222
+ type: Directive,
2223
+ args: [{
2224
+ selector: "[dolfoNavigate]",
2225
+ standalone: false
2226
+ }]
2227
+ }], ctorParameters: () => [{ type: StoreService }, { type: i2.Router }, { type: i0.ElementRef }], propDecorators: { url: [{
2228
+ type: Input,
2229
+ args: [{ required: true, alias: "dolfoNavigate" }]
2230
+ }] } });
2231
+
2067
2232
  class PopoverDirective extends Subscriptable {
2068
2233
  el;
2069
2234
  ps;
@@ -2156,14 +2321,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
2156
2321
 
2157
2322
  class DirectivesModule {
2158
2323
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DirectivesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2159
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type: DirectivesModule, declarations: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective], exports: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective] });
2324
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type: DirectivesModule, declarations: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective, NavigateDirective], exports: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective, NavigateDirective] });
2160
2325
  static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DirectivesModule });
2161
2326
  }
2162
2327
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DirectivesModule, decorators: [{
2163
2328
  type: NgModule,
2164
2329
  args: [{
2165
- declarations: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective],
2166
- exports: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective]
2330
+ declarations: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective, NavigateDirective],
2331
+ exports: [ContextMenuDirective, ScrollDragDirective, TooltipDirective, PopoverDirective, NavigateDirective]
2167
2332
  }]
2168
2333
  }] });
2169
2334
 
@@ -2311,6 +2476,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
2311
2476
  }]
2312
2477
  }] });
2313
2478
 
2479
+ const authInterceptor = (req, next) => {
2480
+ const translateService = inject(TranslateService), clone = req.clone({
2481
+ headers: req.headers.set("Client-lang", translateService.getLang().name)
2482
+ });
2483
+ if (!!localStorage.getItem(StorageValues.TOKEN)) {
2484
+ return next(clone.clone({
2485
+ headers: clone.headers.set("Authorization", "Bearer " + localStorage.getItem(StorageValues.TOKEN))
2486
+ }));
2487
+ }
2488
+ return next(clone);
2489
+ };
2490
+
2491
+ const errorInterceptor = (req, next) => {
2492
+ const notificationService = inject(NotificationService), translateService = inject(TranslateService);
2493
+ return next(req).pipe(catchError(err => {
2494
+ if (err instanceof HttpErrorResponse) {
2495
+ if (err.status === 401)
2496
+ localStorage.removeItem(StorageValues.TOKEN);
2497
+ notificationService.show({
2498
+ type: "error",
2499
+ title: translateService.translate("dialog.errorApi"),
2500
+ message: typeof err.error === "string" ? err.error : err.message
2501
+ });
2502
+ }
2503
+ return throwError(() => err);
2504
+ }));
2505
+ };
2506
+
2314
2507
  /*
2315
2508
  * Public API Surface of dolfo-angular
2316
2509
  */
@@ -2320,5 +2513,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImpor
2320
2513
  * Generated bundle index. Do not edit.
2321
2514
  */
2322
2515
 
2323
- export { AutocompleteComponent, BaseFormInput, ButtonComponent, CONTEXT_MENU_DESTROY_TOKEN, ColumnAlign, ColumnDataType, ComboboxComponent, ContextMenuComponent, ContextMenuDirective, ContextMenuService, DatepickerComponent, DialogActionType, DialogComponent, DialogContentComponent, DialogFooterComponent, DialogHeaderComponent, DialogLayoutComponent, DialogLayoutModule, DialogService, DirectivesModule, FormComponent, FormModule, Formable, GridComponent, GridConfig, GridModule, ICON_COMPONENT, IconComponent, IconWrapperComponent, InputCheckboxComponent, InputContainerComponent, InputRadioComponent, InputTextComponent, LANGUAGE_TOKEN, LayoutModule, LoaderComponent, NotificationComponent, NotificationService, OverlayManager, POPOVER_DESTROY_TOKEN, PopoverComponent, PopoverDirective, PopoverService, ScrollDragDirective, Subscriptable, TOOLTIP_DESTROY_TOKEN, TRANSLATE_STORAGE_KEY, TooltipComponent, TooltipDirective, TooltipService, TranslatePipe, TranslateService, isDeepEqual, passwordValidator, provideDolfoLanguages };
2516
+ export { AutocompleteComponent, BaseFormInput, ButtonComponent, CONTEXT_MENU_DESTROY_TOKEN, ColumnAlign, ColumnDataType, ComboboxComponent, ContextMenuComponent, ContextMenuDirective, ContextMenuService, DatepickerComponent, DialogActionType, DialogComponent, DialogContentComponent, DialogFooterComponent, DialogHeaderComponent, DialogLayoutComponent, DialogLayoutModule, DialogService, DialogUtilsService, DirectivesModule, FormComponent, FormModule, Formable, GridComponent, GridConfig, GridModule, ICON_COMPONENT, IconComponent, IconWrapperComponent, InputCheckboxComponent, InputContainerComponent, InputRadioComponent, InputTextComponent, LANGUAGE_TOKEN, LayoutModule, LoaderComponent, MAX_DEVICE_SIZE, MAX_SMALL_DEVICE, NavigateDirective, NotificationComponent, NotificationService, OverlayManager, POPOVER_DESTROY_TOKEN, PopoverComponent, PopoverDirective, PopoverService, ROUTE_CHECK_SERVICE, RouteCheckService, ScrollDragDirective, StorageValues, StoreLists, StoreService, Subscriptable, TOOLTIP_DESTROY_TOKEN, TRANSLATE_STORAGE_KEY, TooltipComponent, TooltipDirective, TooltipService, TranslatePipe, TranslateService, authInterceptor, errorInterceptor, isDeepEqual, passwordValidator, provideDolfoLanguages };
2324
2517
  //# sourceMappingURL=dolfo-angular.mjs.map