@ethlete/core 1.0.0 → 1.1.1

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
- import { inject, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, HostBinding, InjectionToken, Injectable, ElementRef, Inject, Optional, Directive, isDevMode, EventEmitter, Output, NgZone, Pipe, QueryList } from '@angular/core';
2
+ import { inject, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, HostBinding, InjectionToken, Injectable, ElementRef, Inject, Optional, isDevMode, Directive, EventEmitter, Output, NgZone, Pipe, QueryList } from '@angular/core';
3
3
  import { DomSanitizer, Meta, Title } from '@angular/platform-browser';
4
- import { fromEvent, Observable, Subject, startWith, map, takeUntil, distinctUntilChanged, BehaviorSubject, filter, combineLatest, pairwise, debounceTime, shareReplay, merge, tap, switchMap, take } from 'rxjs';
4
+ import { fromEvent, Observable, Subject, startWith, map, takeUntil, distinctUntilChanged, BehaviorSubject, filter, combineLatest, pairwise, debounceTime, shareReplay, tap, merge, skip, switchMap, take } from 'rxjs';
5
5
  import { coerceElement, coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
6
6
  import { DOCUMENT } from '@angular/common';
7
7
  import { Router, NavigationEnd } from '@angular/router';
@@ -1024,25 +1024,58 @@ class AnimatableDirective {
1024
1024
  this._elementRef = inject(ElementRef);
1025
1025
  this._animationStart$ = new Subject();
1026
1026
  this._animationEnd$ = new Subject();
1027
+ this._animatedElement$ = new BehaviorSubject(this._elementRef.nativeElement);
1027
1028
  this.animationStart$ = this._animationStart$.asObservable().pipe(debounceTime(0));
1028
1029
  this.animationEnd$ = this._animationEnd$.asObservable().pipe(debounceTime(0));
1029
1030
  this._hostActiveAnimationCount$ = new BehaviorSubject(0);
1030
1031
  this._totalActiveAnimationCount$ = new BehaviorSubject(0);
1031
1032
  this.isAnimating$ = this._totalActiveAnimationCount$.pipe(map((count) => count > 0), debounceTime(0));
1032
1033
  }
1034
+ set animatedElement(value) {
1035
+ let newElement = null;
1036
+ if (value === null || value === undefined) {
1037
+ newElement = this._elementRef.nativeElement;
1038
+ }
1039
+ else if (typeof value === 'string') {
1040
+ const el = document.querySelector(value);
1041
+ if (el) {
1042
+ newElement = el;
1043
+ }
1044
+ else {
1045
+ if (isDevMode()) {
1046
+ console.warn(`Element with selector ${value} not found. Animatable directive will use host element.`);
1047
+ }
1048
+ newElement = this._elementRef.nativeElement;
1049
+ }
1050
+ }
1051
+ else {
1052
+ newElement = value;
1053
+ }
1054
+ if (this._animatedElement$.value !== newElement) {
1055
+ this._animatedElement$.next(newElement);
1056
+ }
1057
+ }
1033
1058
  ngOnInit() {
1034
- merge(fromEvent(this._elementRef.nativeElement, 'animationstart'), fromEvent(this._elementRef.nativeElement, 'transitionstart'))
1035
- .pipe(tap(() => {
1036
- const count = this._hostActiveAnimationCount$.value + 1;
1037
- this._hostActiveAnimationCount$.next(count);
1038
- this._totalActiveAnimationCount$.next(count);
1039
- }), takeUntil(this._destroy$))
1040
- .subscribe();
1041
- merge(fromEvent(this._elementRef.nativeElement, 'animationend'), fromEvent(this._elementRef.nativeElement, 'animationcancel'), fromEvent(this._elementRef.nativeElement, 'transitionend'), fromEvent(this._elementRef.nativeElement, 'transitioncancel'))
1042
- .pipe(tap(() => {
1043
- const count = this._hostActiveAnimationCount$.value - 1;
1044
- this._hostActiveAnimationCount$.next(count);
1045
- this._totalActiveAnimationCount$.next(count);
1059
+ this._animatedElement$
1060
+ .pipe(tap((el) => {
1061
+ this._totalActiveAnimationCount$.next(this._totalActiveAnimationCount$.value - this._hostActiveAnimationCount$.value);
1062
+ this._hostActiveAnimationCount$.next(0);
1063
+ merge(fromEvent(el, 'animationstart'), fromEvent(el, 'transitionstart'))
1064
+ .pipe(filter((e) => e.target === el), // skip events from children
1065
+ tap(() => {
1066
+ const count = this._hostActiveAnimationCount$.value + 1;
1067
+ this._hostActiveAnimationCount$.next(count);
1068
+ this._totalActiveAnimationCount$.next(count);
1069
+ }), takeUntil(this._destroy$), takeUntil(this._animatedElement$.pipe(skip(1))))
1070
+ .subscribe();
1071
+ merge(fromEvent(el, 'animationend'), fromEvent(el, 'animationcancel'), fromEvent(el, 'transitionend'), fromEvent(el, 'transitioncancel'))
1072
+ .pipe(filter((e) => e.target === el), // skip events from children
1073
+ tap(() => {
1074
+ const count = this._hostActiveAnimationCount$.value - 1;
1075
+ this._hostActiveAnimationCount$.next(count);
1076
+ this._totalActiveAnimationCount$.next(count);
1077
+ }), takeUntil(this._destroy$), takeUntil(this._animatedElement$.pipe(skip(1))))
1078
+ .subscribe();
1046
1079
  }), takeUntil(this._destroy$))
1047
1080
  .subscribe();
1048
1081
  this._totalActiveAnimationCount$
@@ -1067,7 +1100,7 @@ class AnimatableDirective {
1067
1100
  }
1068
1101
  }
1069
1102
  AnimatableDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.4", ngImport: i0, type: AnimatableDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1070
- AnimatableDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.4", type: AnimatableDirective, isStandalone: true, selector: "[etAnimatable]", providers: [
1103
+ AnimatableDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.1.4", type: AnimatableDirective, isStandalone: true, selector: "[etAnimatable]", inputs: { animatedElement: ["etAnimatable", "animatedElement"] }, providers: [
1071
1104
  {
1072
1105
  provide: ANIMATABLE_TOKEN,
1073
1106
  useExisting: AnimatableDirective,
@@ -1088,7 +1121,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.4", ngImpor
1088
1121
  DestroyService,
1089
1122
  ],
1090
1123
  }]
1091
- }] });
1124
+ }], propDecorators: { animatedElement: [{
1125
+ type: Input,
1126
+ args: ['etAnimatable']
1127
+ }] } });
1092
1128
 
1093
1129
  const ANIMATED_LIFECYCLE_TOKEN = new InjectionToken('ANIMATED_LIFECYCLE_DIRECTIVE_TOKEN');
1094
1130
  const ANIMATION_CLASSES = {
@@ -1117,7 +1153,7 @@ class AnimatedLifecycleDirective {
1117
1153
  }
1118
1154
  enter(config) {
1119
1155
  if (this.state !== 'init' && this.state !== 'left' && isDevMode()) {
1120
- throw new Error('Tried to enter but the element is not in the initial state.');
1156
+ console.warn('Tried to enter but the element is not in the initial state. This may result in unexpected behavior.', this);
1121
1157
  }
1122
1158
  this._state$.next('entering');
1123
1159
  if (!config?.onlyTransition) {
@@ -1142,7 +1178,7 @@ class AnimatedLifecycleDirective {
1142
1178
  }
1143
1179
  leave(config) {
1144
1180
  if (this.state !== 'entered' && this.state !== 'entering' && isDevMode()) {
1145
- throw new Error('Tried to leave while already leaving or left');
1181
+ console.warn('Tried to leave while already leaving or left. This may result in unexpected behavior.', this);
1146
1182
  }
1147
1183
  if (this._classList.contains(ANIMATION_CLASSES.enterFrom) ||
1148
1184
  this._classList.contains(ANIMATION_CLASSES.enterActive) ||