adb-shared 2.0.32 → 2.0.35

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.
@@ -4,13 +4,14 @@ import * as i0 from '@angular/core';
4
4
  import { Injectable, Inject, EventEmitter, Component, Output, Input, Directive, HostListener, NgModule, HostBinding, Pipe, forwardRef } from '@angular/core';
5
5
  import * as i1$1 from '@ngx-translate/core';
6
6
  import { TranslateModule } from '@ngx-translate/core';
7
- import { Subscription, Subject } from 'rxjs';
7
+ import { Subscription, Subject, of } from 'rxjs';
8
8
  import * as i1 from '@angular/common/http';
9
9
  import { HttpClientModule } from '@angular/common/http';
10
10
  import * as i1$2 from '@angular/router';
11
11
  import { RouterModule } from '@angular/router';
12
12
  import { isValid, parseISO, startOfDay, subYears, endOfDay, addYears, getMonth, subMonths, addMonths, isSameYear, startOfMonth, endOfMonth, eachWeekOfInterval, getISOWeek, addDays, eachDayOfInterval, getHours, getMinutes, isSameDay, isSameMonth, isWithinInterval } from 'date-fns';
13
13
  import { NG_VALUE_ACCESSOR } from '@angular/forms';
14
+ import { delay } from 'rxjs/operators';
14
15
 
15
16
  class EnvironmentService {
16
17
  constructor(environment) {
@@ -499,6 +500,7 @@ class AdbDatePickerDirective {
499
500
  this.subscriptions = new Subscription();
500
501
  this.format = 'yyyy-MM-dd';
501
502
  this.settings = null;
503
+ this.pickOnly = true;
502
504
  //ControlValueAccessor
503
505
  this.onChange = () => { };
504
506
  this.onTouched = () => { };
@@ -516,6 +518,7 @@ class AdbDatePickerDirective {
516
518
  this.id = this.getId();
517
519
  viewRef.instance.id = this.id;
518
520
  viewRef.instance.selectDate.subscribe((date) => {
521
+ this.elementRef.nativeElement.classList.remove('ng-invalid');
519
522
  this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatDate(date, this.format, this.translate.currentLang));
520
523
  this.onChange(date);
521
524
  this.initialDate = date;
@@ -526,22 +529,32 @@ class AdbDatePickerDirective {
526
529
  });
527
530
  this.adbDatePickerService.viewRef = viewRef;
528
531
  }
532
+ onKeyup(event) {
533
+ const date = AdbDatePickerDirective.tryParse(event.target.value, this.format);
534
+ if (date) {
535
+ this.onChange(date);
536
+ this.initialDate = date;
537
+ }
538
+ }
529
539
  onHide() {
530
540
  this.adbDatePickerService.viewRef = null;
531
541
  this.viewContainerRef.detach();
532
542
  this.viewContainerRef.clear();
533
543
  }
544
+ onBlur() {
545
+ const date = AdbDatePickerDirective.tryParse(this.elementRef.nativeElement.value, this.format);
546
+ if (!date) {
547
+ this.elementRef.nativeElement.classList.add('ng-invalid');
548
+ }
549
+ else {
550
+ this.elementRef.nativeElement.classList.remove('ng-invalid');
551
+ }
552
+ }
534
553
  handleKeyboardEvent(event) {
535
554
  if (event.key === 'Tab') {
536
555
  this.onHide();
537
556
  }
538
- else if (event.key === 'Backspace') {
539
- this.initialDate = null;
540
- this.renderer.setProperty(this.elementRef.nativeElement, 'value', null);
541
- this.onChange();
542
- this.onHide();
543
- }
544
- else {
557
+ else if (this.pickOnly) {
545
558
  event.preventDefault();
546
559
  }
547
560
  }
@@ -598,12 +611,16 @@ class AdbDatePickerDirective {
598
611
  return null;
599
612
  }
600
613
  }
614
+ static tryParse(dateString, format) {
615
+ const parsed = parseISO(dateString);
616
+ return isValid(parsed) && dateString?.length === 10 ? parsed : null;
617
+ }
601
618
  getId() {
602
619
  return '' + Math.floor(Math.random() * Date.now());
603
620
  }
604
621
  }
605
622
  /** @nocollapse */ AdbDatePickerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbDatePickerDirective, deps: [{ token: i0.ViewContainerRef }, { token: i0.Renderer2 }, { token: i0.ElementRef }, { token: AdbDatePickerService }, { token: i1$1.TranslateService }], target: i0.ɵɵFactoryTarget.Directive });
606
- /** @nocollapse */ AdbDatePickerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.8", type: AdbDatePickerDirective, selector: "input[adbDatepicker]", inputs: { format: "format", toLeft: "toLeft", settings: "settings" }, host: { listeners: { "click": "onClick()", "keyup.esc": "onHide()", "keydown": "handleKeyboardEvent($event)", "document:click": "onCheckOutSideClick($event.target)" }, properties: { "autocomplete": "this.autocomplete" } }, providers: [{
623
+ /** @nocollapse */ AdbDatePickerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.8", type: AdbDatePickerDirective, selector: "input[adbDatepicker]", inputs: { format: "format", toLeft: "toLeft", settings: "settings", pickOnly: "pickOnly" }, host: { listeners: { "click": "onClick()", "keyup": "onKeyup($event)", "keyup.esc": "onHide()", "blur": "onBlur()", "keydown": "handleKeyboardEvent($event)", "document:click": "onCheckOutSideClick($event.target)" }, properties: { "autocomplete": "this.autocomplete" } }, providers: [{
607
624
  provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((() => AdbDatePickerDirective)),
608
625
  multi: true
609
626
  }], ngImport: i0 });
@@ -625,12 +642,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
625
642
  type: Input
626
643
  }], settings: [{
627
644
  type: Input
645
+ }], pickOnly: [{
646
+ type: Input
628
647
  }], onClick: [{
629
648
  type: HostListener,
630
649
  args: ['click']
650
+ }], onKeyup: [{
651
+ type: HostListener,
652
+ args: ['keyup', ['$event']]
631
653
  }], onHide: [{
632
654
  type: HostListener,
633
655
  args: ['keyup.esc']
656
+ }], onBlur: [{
657
+ type: HostListener,
658
+ args: ['blur']
634
659
  }], handleKeyboardEvent: [{
635
660
  type: HostListener,
636
661
  args: ['keydown', ['$event']]
@@ -996,53 +1021,70 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
996
1021
  class AdbToastService {
997
1022
  constructor(componentFactoryResolver, rendererFactory, appRef, injector) {
998
1023
  this.componentFactoryResolver = componentFactoryResolver;
1024
+ this.rendererFactory = rendererFactory;
999
1025
  this.appRef = appRef;
1000
1026
  this.injector = injector;
1001
- this.renderer = rendererFactory.createRenderer(null, null);
1027
+ this.toasts = new Array();
1028
+ this.toastsSubject = new Subject();
1029
+ this.$toasts = this.toastsSubject.asObservable();
1030
+ }
1031
+ add(toastMessage, time = 4000) {
1032
+ this.addContainer();
1033
+ toastMessage.type = toastMessage.type ? toastMessage.type : ToastType.Success;
1034
+ toastMessage.index = this.toasts.length;
1035
+ toastMessage.delay = of(toastMessage).pipe(delay(time)).subscribe(toast => {
1036
+ this.remove(toast);
1037
+ });
1038
+ this.toasts.push(toastMessage);
1039
+ this.toastsSubject.next(this.toasts);
1040
+ }
1041
+ remove(toast) {
1042
+ this.toasts = this.toasts?.filter(x => x.index !== toast.index);
1043
+ this.toastsSubject.next(this.toasts);
1002
1044
  }
1003
- show(model) {
1045
+ addContainer() {
1004
1046
  if (!this.container) {
1047
+ this.renderer = this.rendererFactory.createRenderer(null, null);
1048
+ //create container i top
1005
1049
  this.container = this.renderer.createElement('div');
1006
- this.container.setAttribute('adb-toast-container', '');
1007
- this.container.classList.add('position-fixed', 'bottom-0', 'end-0');
1008
1050
  this.renderer.appendChild(document.body, this.container);
1051
+ let componentRef = this.componentFactoryResolver.resolveComponentFactory(AdbToast).create(this.injector);
1052
+ this.appRef.attachView(componentRef.hostView);
1053
+ const element = componentRef.hostView.rootNodes[0];
1054
+ this.container.prepend(element);
1009
1055
  }
1010
- this.createToast(model);
1011
- }
1012
- createToast(model) {
1013
- if (!model.state)
1014
- model.state = 'info';
1015
- if (!model.timeInMs)
1016
- model.timeInMs = 4000;
1017
- let componentRef = this.componentFactoryResolver.resolveComponentFactory(AdbToast).create(this.injector);
1018
- componentRef.instance.model = model;
1019
- this.appRef.attachView(componentRef.hostView);
1020
- const element = componentRef.hostView.rootNodes[0];
1021
- this.container.prepend(element);
1022
- setTimeout(() => {
1023
- // element.remove();
1024
- }, model.timeInMs);
1025
1056
  }
1026
1057
  }
1027
1058
  /** @nocollapse */ AdbToastService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbToastService, deps: [{ token: i0.ComponentFactoryResolver }, { token: i0.RendererFactory2 }, { token: i0.ApplicationRef }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
1028
1059
  /** @nocollapse */ AdbToastService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbToastService });
1029
1060
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbToastService, decorators: [{
1030
1061
  type: Injectable
1031
- }], ctorParameters: function () { return [{ type: i0.ComponentFactoryResolver }, { type: i0.RendererFactory2 }, { type: i0.ApplicationRef }, { type: i0.Injector }]; } });
1062
+ }], ctorParameters: function () { return [{ type: i0.ComponentFactoryResolver }, { type: i0.RendererFactory2 }, { type: i0.ApplicationRef }, { type: i0.Injector }]; } });
1063
+ var ToastType;
1064
+ (function (ToastType) {
1065
+ ToastType[ToastType["Info"] = 1] = "Info";
1066
+ ToastType[ToastType["Success"] = 2] = "Success";
1067
+ ToastType[ToastType["Warn"] = 3] = "Warn";
1068
+ })(ToastType || (ToastType = {}));
1032
1069
 
1033
1070
  class AdbToast {
1034
- constructor(toastRef) {
1035
- this.toastRef = toastRef;
1071
+ constructor(toastService) {
1072
+ this.toastService = toastService;
1073
+ this.toastType = ToastType;
1074
+ this.toastService.$toasts.subscribe(toasts => {
1075
+ this.toasts = toasts;
1076
+ });
1077
+ }
1078
+ onRemoveToast(toast) {
1079
+ this.toastService.remove(toast);
1036
1080
  }
1037
1081
  }
1038
1082
  /** @nocollapse */ AdbToast.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbToast, deps: [{ token: AdbToastService }], target: i0.ɵɵFactoryTarget.Component });
1039
- /** @nocollapse */ AdbToast.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.8", type: AdbToast, selector: "ng-component", inputs: { model: "model" }, ngImport: i0, template: " <div #toast (click)=\"toast.remove()\" adb-toast class=\"text-white px-3 pb-3 pt-2 mb-2\" style=\"z-index: 50000;min-width: 15rem;\" [class]=\"'bg-' + model.state\">\r\n <div *ngIf=\"model.header\" class=\"d-flex align-items-center justify-content-between pb-1\">\r\n <div class=\"fw-bold\">{{model.header|translate}}</div>\r\n <button class=\"btn p-0 ms-2 text-white\" (click)=\"toast.remove()\"><i class=\"fas fa-times\"></i></button>\r\n </div>\r\n <div class=\"d-flex align-items-center justify-content-between mt-1\">\r\n <div> {{model.body|translate}}</div>\r\n <button *ngIf=\"!model.header\" class=\"btn p-0 ms-2 text-white\" (click)=\"toast.remove()\"><i class=\"fas fa-times\"></i></button>\r\n </div>\r\n </div>", directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "translate": i1$1.TranslatePipe } });
1083
+ /** @nocollapse */ AdbToast.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.8", type: AdbToast, selector: "ng-component", ngImport: i0, template: "<div class=\"position-fixed bottom-0 end-0\" style=\"z-index: 50000;min-width: 15rem;\">\r\n <div class=\"text-white px-3 pb-3 pt-2 mb-2\" *ngFor=\"let toast of toasts\"\r\n [class.bg-success]=\"toast.type===toastType.Success\" [class.bg-info]=\"toast.type===toastType.Info\" [class.bg-danger]=\"toast.type===toastType.Warn\">\r\n <div class=\"d-flex align-items-center justify-content-between pb-1\" *ngIf=\"toast.header\">\r\n <div class=\"fw-bold pb-1\">{{toast.header|translate}}</div>\r\n <button class=\"btn top-0 end-0 btn p-0 ms-2 text-white\" (click)=\"onRemoveToast(toast)\"><i class=\"fas fa-times\"></i></button>\r\n </div>\r\n <div class=\"d-flex align-items-center justify-content-between mt-1\">\r\n <div>{{toast.message|translate}}</div>\r\n <button *ngIf=\"!toast.header\" class=\"btn p-0 ms-2 text-white\" (click)=\"onRemoveToast(toast)\"><i class=\"fas fa-times\"></i></button>\r\n </div>\r\n </div>\r\n</div>", directives: [{ type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "translate": i1$1.TranslatePipe } });
1040
1084
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImport: i0, type: AdbToast, decorators: [{
1041
1085
  type: Component,
1042
- args: [{ template: " <div #toast (click)=\"toast.remove()\" adb-toast class=\"text-white px-3 pb-3 pt-2 mb-2\" style=\"z-index: 50000;min-width: 15rem;\" [class]=\"'bg-' + model.state\">\r\n <div *ngIf=\"model.header\" class=\"d-flex align-items-center justify-content-between pb-1\">\r\n <div class=\"fw-bold\">{{model.header|translate}}</div>\r\n <button class=\"btn p-0 ms-2 text-white\" (click)=\"toast.remove()\"><i class=\"fas fa-times\"></i></button>\r\n </div>\r\n <div class=\"d-flex align-items-center justify-content-between mt-1\">\r\n <div> {{model.body|translate}}</div>\r\n <button *ngIf=\"!model.header\" class=\"btn p-0 ms-2 text-white\" (click)=\"toast.remove()\"><i class=\"fas fa-times\"></i></button>\r\n </div>\r\n </div>" }]
1043
- }], ctorParameters: function () { return [{ type: AdbToastService }]; }, propDecorators: { model: [{
1044
- type: Input
1045
- }] } });
1086
+ args: [{ template: "<div class=\"position-fixed bottom-0 end-0\" style=\"z-index: 50000;min-width: 15rem;\">\r\n <div class=\"text-white px-3 pb-3 pt-2 mb-2\" *ngFor=\"let toast of toasts\"\r\n [class.bg-success]=\"toast.type===toastType.Success\" [class.bg-info]=\"toast.type===toastType.Info\" [class.bg-danger]=\"toast.type===toastType.Warn\">\r\n <div class=\"d-flex align-items-center justify-content-between pb-1\" *ngIf=\"toast.header\">\r\n <div class=\"fw-bold pb-1\">{{toast.header|translate}}</div>\r\n <button class=\"btn top-0 end-0 btn p-0 ms-2 text-white\" (click)=\"onRemoveToast(toast)\"><i class=\"fas fa-times\"></i></button>\r\n </div>\r\n <div class=\"d-flex align-items-center justify-content-between mt-1\">\r\n <div>{{toast.message|translate}}</div>\r\n <button *ngIf=\"!toast.header\" class=\"btn p-0 ms-2 text-white\" (click)=\"onRemoveToast(toast)\"><i class=\"fas fa-times\"></i></button>\r\n </div>\r\n </div>\r\n</div>" }]
1087
+ }], ctorParameters: function () { return [{ type: AdbToastService }]; } });
1046
1088
 
1047
1089
  class AdbToastModule {
1048
1090
  }
@@ -1067,5 +1109,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
1067
1109
  * Generated bundle index. Do not edit.
1068
1110
  */
1069
1111
 
1070
- export { ADBHeaderComponent, ADBHeaderModule, AdbConfirmModal, AdbDatePickerComponent, AdbDatePickerDirective, AdbDatePickerModule, AdbDirectivesModule, AdbDropdownDirective, AdbDropdownModule, AdbModalModule, AdbModalService, AdbPagersModule, AdbPipesModule, AdbToast, AdbToastModule, AdbToastService, ClickOutsideDirective, FileUploadDirective, FocusDirective, HighlightPipe, InfiniteScrollComponent, LocaleDatePipe, NumberSpacingPipe, PagerComponent };
1112
+ export { ADBHeaderComponent, ADBHeaderModule, AdbConfirmModal, AdbDatePickerComponent, AdbDatePickerDirective, AdbDatePickerModule, AdbDirectivesModule, AdbDropdownDirective, AdbDropdownModule, AdbModalModule, AdbModalService, AdbPagersModule, AdbPipesModule, AdbToast, AdbToastModule, AdbToastService, ClickOutsideDirective, FileUploadDirective, FocusDirective, HighlightPipe, InfiniteScrollComponent, LocaleDatePipe, NumberSpacingPipe, PagerComponent, ToastType };
1071
1113
  //# sourceMappingURL=adb-shared.mjs.map