@stemy/ngx-utils 17.0.0 → 17.1.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,10 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, PLATFORM_ID, Injectable, Inject, Optional, Injector, EventEmitter, isDevMode, ErrorHandler, NgZone, Pipe, Directive, Input, Output, HostBinding, HostListener, Component, ContentChildren, ViewChild, ContentChild, APP_INITIALIZER, NgModule } from '@angular/core';
2
+ import { InjectionToken, PLATFORM_ID, Injectable, Inject, Optional, Injector, EventEmitter, isDevMode, ErrorHandler, NgZone, Pipe, Directive, Input, Output, HostBinding, HostListener, Component, ContentChildren, ViewChild, ContentChild, APP_INITIALIZER, makeEnvironmentProviders, NgModule } from '@angular/core';
3
3
  import 'reflect-metadata';
4
4
  import * as i2 from '@angular/router';
5
- import { ActivatedRouteSnapshot, NavigationEnd, DefaultUrlSerializer, UrlTree, UrlSegmentGroup, UrlSegment, UrlSerializer } from '@angular/router';
6
- import { BehaviorSubject, Observable, Subject, Subscription, from, TimeoutError, combineLatest } from 'rxjs';
7
- import { distinctUntilChanged, delay, skipWhile, first, mergeMap, timeout, map } from 'rxjs/operators';
5
+ import { ActivatedRouteSnapshot, Scroll, NavigationEnd, DefaultUrlSerializer, UrlTree, UrlSegmentGroup, UrlSegment, UrlSerializer } from '@angular/router';
6
+ import { BehaviorSubject, Observable, firstValueFrom, Subject, Subscription, from, TimeoutError, combineLatest } from 'rxjs';
7
+ import { distinctUntilChanged, map, filter, skipWhile, debounceTime, first, mergeMap, timeout } from 'rxjs/operators';
8
8
  import * as i1$3 from '@angular/common';
9
9
  import { isPlatformBrowser, isPlatformServer, DOCUMENT, APP_BASE_HREF, CommonModule } from '@angular/common';
10
10
  import * as i1 from 'ngx-device-detector';
@@ -486,7 +486,6 @@ const ROOT_ELEMENT = new InjectionToken("app-root-element");
486
486
  const RESIZE_DELAY = new InjectionToken("resize-event-delay");
487
487
  const RESIZE_STRATEGY = new InjectionToken("resize-event-strategy");
488
488
  const ERROR_HANDLER = new InjectionToken("error-handler-callback");
489
- const GLOBAL_TEMPLATES = new InjectionToken("global-templates");
490
489
  // --- Valued promise ---
491
490
  class ValuedPromise extends Promise {
492
491
  }
@@ -718,7 +717,7 @@ const emptyData = { id: "" };
718
717
  const emptyParams = {};
719
718
  const emptySegments = [];
720
719
  const emptyComponents = [];
721
- class StateService extends BehaviorSubject {
720
+ class StateService {
722
721
  static toPath(route, params) {
723
722
  let path = route.path || "";
724
723
  ObjectUtils.iterate(params, (value, key) => {
@@ -726,11 +725,11 @@ class StateService extends BehaviorSubject {
726
725
  });
727
726
  return path;
728
727
  }
729
- get component() {
730
- return this.comp;
731
- }
732
728
  get snapshot() {
733
- return this.shot || emptySnapshot;
729
+ return this.$snapshot.value;
730
+ }
731
+ get component() {
732
+ return this.$component.value;
734
733
  }
735
734
  get route() {
736
735
  return this.snapshot.routeConfig;
@@ -757,15 +756,29 @@ class StateService extends BehaviorSubject {
757
756
  return this.router.config;
758
757
  }
759
758
  constructor(injector, zone, universal, router = null, contexts = null) {
760
- super(null);
761
759
  this.injector = injector;
762
760
  this.zone = zone;
763
761
  this.universal = universal;
764
762
  this.router = router;
765
763
  this.contexts = contexts;
766
- this.handleRouterEvent = (event) => {
767
- if (!(event instanceof NavigationEnd))
768
- return;
764
+ this.globalExtras = {
765
+ queryParamsHandling: "merge"
766
+ };
767
+ this.$snapshot = new BehaviorSubject(emptySnapshot);
768
+ this.$component = new BehaviorSubject(null);
769
+ this.stateInfo = {
770
+ url: "",
771
+ segments: [],
772
+ components: []
773
+ };
774
+ this.router?.events
775
+ .pipe(distinctUntilChanged(), map(event => {
776
+ if (event instanceof Scroll) {
777
+ return event.routerEvent;
778
+ }
779
+ return event;
780
+ }), filter(e => e instanceof NavigationEnd))
781
+ .subscribe(() => {
769
782
  const routerStateSnapshot = this.router.routerState.snapshot;
770
783
  let snapshot = routerStateSnapshot.root;
771
784
  let context = this.contexts?.getContext("primary");
@@ -782,28 +795,14 @@ class StateService extends BehaviorSubject {
782
795
  }
783
796
  snapshot = snapshot.firstChild;
784
797
  }
785
- this.comp = components[components.length - 1];
786
- this.shot = snapshots[snapshots.length - 1];
787
798
  this.stateInfo = {
788
799
  url: routerStateSnapshot.url,
789
800
  segments: segments,
790
801
  components: components
791
802
  };
792
- this.next(this.shot);
793
- };
794
- if (!this.router)
795
- return;
796
- this.globalExtras = {
797
- queryParamsHandling: "merge"
798
- };
799
- this.router.events
800
- .pipe(distinctUntilChanged(), delay(10))
801
- .subscribe(this.handleRouterEvent);
802
- this.stateInfo = {
803
- url: "",
804
- segments: [],
805
- components: []
806
- };
803
+ this.$snapshot.next(snapshots[snapshots.length - 1]);
804
+ this.$component.next(components[components.length - 1]);
805
+ });
807
806
  }
808
807
  async reload() {
809
808
  const routerStateSnapshot = this.router.routerState.snapshot;
@@ -813,7 +812,7 @@ class StateService extends BehaviorSubject {
813
812
  const resolver = this.injector.get(resolvers[key]);
814
813
  let resolved = resolver.resolve(this.snapshot, routerStateSnapshot);
815
814
  if (resolved instanceof Observable) {
816
- resolved = resolved.toPromise();
815
+ resolved = firstValueFrom(resolved);
817
816
  }
818
817
  if (resolved instanceof Promise) {
819
818
  resolved = await resolved;
@@ -840,8 +839,13 @@ class StateService extends BehaviorSubject {
840
839
  return this.openInNewWindow(tree, target) || this.router.navigateByUrl(tree, extras);
841
840
  });
842
841
  }
843
- subscribeImmediately(next, error, complete) {
844
- return this.pipe(skipWhile(v => v == null)).subscribe(next, error, complete);
842
+ subscribeImmediately(next, error) {
843
+ return this.subscribe({
844
+ next, error
845
+ });
846
+ }
847
+ subscribe(osOrNext) {
848
+ return this.$snapshot.pipe(skipWhile(snapshot => snapshot === emptySnapshot), debounceTime(25)).subscribe(osOrNext);
845
849
  }
846
850
  openInNewWindow(tree, target) {
847
851
  if (!this.universal.isBrowser)
@@ -3967,7 +3971,7 @@ class GlobalTemplatePipe {
3967
3971
  }
3968
3972
  return this.cachedTemplate;
3969
3973
  }
3970
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: GlobalTemplatePipe, deps: [{ token: GLOBAL_TEMPLATES }], target: i0.ɵɵFactoryTarget.Pipe }); }
3974
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: GlobalTemplatePipe, deps: [{ token: GlobalTemplateService }], target: i0.ɵɵFactoryTarget.Pipe }); }
3971
3975
  static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: GlobalTemplatePipe, name: "globalTemplate", pure: false }); }
3972
3976
  }
3973
3977
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: GlobalTemplatePipe, decorators: [{
@@ -3976,10 +3980,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
3976
3980
  pure: false,
3977
3981
  name: "globalTemplate"
3978
3982
  }]
3979
- }], ctorParameters: () => [{ type: undefined, decorators: [{
3980
- type: Inject,
3981
- args: [GLOBAL_TEMPLATES]
3982
- }] }] });
3983
+ }], ctorParameters: () => [{ type: GlobalTemplateService }] });
3983
3984
 
3984
3985
  class GroupByPipe {
3985
3986
  transform(records, column, map = null) {
@@ -4575,7 +4576,7 @@ class GlobalTemplateDirective {
4575
4576
  ngOnDestroy() {
4576
4577
  this.globalTemplates.remove(this.id);
4577
4578
  }
4578
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: GlobalTemplateDirective, deps: [{ token: GLOBAL_TEMPLATES }, { token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive }); }
4579
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: GlobalTemplateDirective, deps: [{ token: GlobalTemplateService }, { token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive }); }
4579
4580
  static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.12", type: GlobalTemplateDirective, selector: "[globalTemplate]", inputs: { id: ["globalTemplate", "id"] }, ngImport: i0 }); }
4580
4581
  }
4581
4582
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: GlobalTemplateDirective, decorators: [{
@@ -4583,10 +4584,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
4583
4584
  args: [{
4584
4585
  selector: "[globalTemplate]"
4585
4586
  }]
4586
- }], ctorParameters: () => [{ type: undefined, decorators: [{
4587
- type: Inject,
4588
- args: [GLOBAL_TEMPLATES]
4589
- }] }, { type: i0.TemplateRef }], propDecorators: { id: [{
4587
+ }], ctorParameters: () => [{ type: GlobalTemplateService }, { type: i0.TemplateRef }], propDecorators: { id: [{
4590
4588
  type: Input,
4591
4589
  args: ["globalTemplate"]
4592
4590
  }] } });
@@ -5490,6 +5488,7 @@ const providers = [
5490
5488
  UniversalService,
5491
5489
  WasmService,
5492
5490
  DeviceDetectorService,
5491
+ GlobalTemplateService,
5493
5492
  {
5494
5493
  provide: EVENT_MANAGER_PLUGINS,
5495
5494
  useClass: ResizeEventPlugin,
@@ -5711,78 +5710,80 @@ function loadBaseHref(baseUrl) {
5711
5710
  }
5712
5711
  }
5713
5712
  class NgxUtilsModule {
5713
+ static getProviders(config) {
5714
+ return [
5715
+ ...providers,
5716
+ {
5717
+ provide: API_SERVICE,
5718
+ useExisting: (!config ? null : config.apiService) || ApiService
5719
+ },
5720
+ {
5721
+ provide: AUTH_SERVICE,
5722
+ useExisting: (!config ? null : config.authService) || StaticAuthService
5723
+ },
5724
+ {
5725
+ provide: ICON_SERVICE,
5726
+ useExisting: (!config ? null : config.iconService) || IconService
5727
+ },
5728
+ {
5729
+ provide: LANGUAGE_SERVICE,
5730
+ useExisting: (!config ? null : config.languageService) || StaticLanguageService
5731
+ },
5732
+ {
5733
+ provide: TOASTER_SERVICE,
5734
+ useExisting: (!config ? null : config.toasterService) || ConsoleToasterService
5735
+ },
5736
+ {
5737
+ provide: PROMISE_SERVICE,
5738
+ useExisting: (!config ? null : config.promiseService) || PromiseService
5739
+ },
5740
+ {
5741
+ provide: CONFIG_SERVICE,
5742
+ useExisting: (!config ? null : config.configService) || ConfigService
5743
+ },
5744
+ {
5745
+ provide: WASI_IMPLEMENTATION,
5746
+ useExisting: (!config ? null : config.wasiImplementation) || Wasi
5747
+ },
5748
+ {
5749
+ provide: APP_BASE_URL,
5750
+ useFactory: (!config ? null : config.baseUrl) || loadBaseUrl,
5751
+ deps: [Injector]
5752
+ },
5753
+ {
5754
+ provide: ROOT_ELEMENT,
5755
+ useValue: null
5756
+ },
5757
+ {
5758
+ provide: RESIZE_DELAY,
5759
+ useValue: (!config ? null : config.resizeDelay) ?? 50,
5760
+ },
5761
+ {
5762
+ provide: RESIZE_STRATEGY,
5763
+ useValue: (!config ? null : config.resizeStrategy) ?? "object",
5764
+ },
5765
+ {
5766
+ provide: APP_INITIALIZER,
5767
+ useFactory: (!config ? null : config.initializeApp) || loadConfig,
5768
+ multi: true,
5769
+ deps: [(!config ? null : config.initializeApp) ? Injector : CONFIG_SERVICE]
5770
+ },
5771
+ {
5772
+ provide: APP_BASE_HREF,
5773
+ useFactory: loadBaseHref,
5774
+ deps: [APP_BASE_URL]
5775
+ }
5776
+ ];
5777
+ }
5714
5778
  static forRoot(config) {
5715
5779
  return {
5716
5780
  ngModule: NgxUtilsModule,
5717
- providers: [
5718
- ...providers,
5719
- {
5720
- provide: API_SERVICE,
5721
- useExisting: (!config ? null : config.apiService) || ApiService
5722
- },
5723
- {
5724
- provide: AUTH_SERVICE,
5725
- useExisting: (!config ? null : config.authService) || StaticAuthService
5726
- },
5727
- {
5728
- provide: ICON_SERVICE,
5729
- useExisting: (!config ? null : config.iconService) || IconService
5730
- },
5731
- {
5732
- provide: LANGUAGE_SERVICE,
5733
- useExisting: (!config ? null : config.languageService) || StaticLanguageService
5734
- },
5735
- {
5736
- provide: TOASTER_SERVICE,
5737
- useExisting: (!config ? null : config.toasterService) || ConsoleToasterService
5738
- },
5739
- {
5740
- provide: PROMISE_SERVICE,
5741
- useExisting: (!config ? null : config.promiseService) || PromiseService
5742
- },
5743
- {
5744
- provide: CONFIG_SERVICE,
5745
- useExisting: (!config ? null : config.configService) || ConfigService
5746
- },
5747
- {
5748
- provide: GLOBAL_TEMPLATES,
5749
- useExisting: (!config ? null : config.globalTemplates) || GlobalTemplateService
5750
- },
5751
- {
5752
- provide: WASI_IMPLEMENTATION,
5753
- useExisting: (!config ? null : config.wasiImplementation) || Wasi
5754
- },
5755
- {
5756
- provide: APP_BASE_URL,
5757
- useFactory: (!config ? null : config.baseUrl) || loadBaseUrl,
5758
- deps: [Injector]
5759
- },
5760
- {
5761
- provide: ROOT_ELEMENT,
5762
- useValue: null
5763
- },
5764
- {
5765
- provide: RESIZE_DELAY,
5766
- useValue: (!config ? null : config.resizeDelay) ?? 50,
5767
- },
5768
- {
5769
- provide: RESIZE_STRATEGY,
5770
- useValue: (!config ? null : config.resizeStrategy) ?? "object",
5771
- },
5772
- {
5773
- provide: APP_INITIALIZER,
5774
- useFactory: (!config ? null : config.initializeApp) || loadConfig,
5775
- multi: true,
5776
- deps: [(!config ? null : config.initializeApp) ? Injector : CONFIG_SERVICE]
5777
- },
5778
- {
5779
- provide: APP_BASE_HREF,
5780
- useFactory: loadBaseHref,
5781
- deps: [APP_BASE_URL]
5782
- }
5783
- ]
5781
+ providers: NgxUtilsModule.getProviders(config)
5784
5782
  };
5785
5783
  }
5784
+ static provideUtils(config) {
5785
+ return makeEnvironmentProviders(NgxUtilsModule.getProviders(config));
5786
+ }
5786
5787
  constructor() {
5787
5788
  }
5788
5789
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxUtilsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
@@ -5817,5 +5818,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
5817
5818
  * Generated bundle index. Do not edit.
5818
5819
  */
5819
5820
 
5820
- export { API_SERVICE, APP_BASE_URL, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AuthGuard, BASE_CONFIG, BackgroundDirective, BaseHttpClient, BaseHttpService, CONFIG_SERVICE, CanvasColor, CanvasUtils, ChunkPipe, Circle, ConfigService, ConsoleToasterService, DateUtils, DynamicTableComponent, DynamicTableTemplateDirective, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExtraItemPropertiesPipe, FactoryDependencies, FileSystemEntry, FileUtils, FilterPipe, FindPipe, FormatNumberPipe, FormatterService, GLOBAL_TEMPLATES, GenericValue, GetOffsetPipe, GetTypePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, HttpPromise, ICON_SERVICE, IConfiguration, IconDirective, IconService, Initializer, IsTypePipe, JSONfn, JoinPipe, KeysPipe, LANGUAGE_SERVICE, LanguageService, LoaderUtils, LocalHttpService, MapPipe, MathUtils, MaxPipe, MinPipe, NgxTemplateOutletDirective, NgxUtilsModule, OPTIONS_TOKEN, ObjectType, ObjectUtils, ObservableUtils, OpenApiService, PROMISE_SERVICE, PaginationDirective, PaginationItemContext, PaginationItemDirective, PaginationMenuComponent, Point, PopPipe, PromiseService, RESIZE_DELAY, RESIZE_STRATEGY, ROOT_ELEMENT, Rect, ReducePipe, ReflectUtils, RemapPipe, ReplacePipe, ResizeEventPlugin, ResourceIfContext, ResourceIfDirective, ReversePipe, RoundPipe, SCRIPT_PARAMS, SafeHtmlPipe, ScrollEventPlugin, SetUtils, ShiftPipe, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyClassDirective, StickyDirective, StorageMode, StorageService, StringUtils, TOASTER_SERVICE, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, ValuedPromise, ValuesPipe, Vector, WASI_IMPLEMENTATION, WasmService, cachedFactory, provideWithOptions };
5821
+ export { API_SERVICE, APP_BASE_URL, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AuthGuard, BASE_CONFIG, BackgroundDirective, BaseHttpClient, BaseHttpService, CONFIG_SERVICE, CanvasColor, CanvasUtils, ChunkPipe, Circle, ConfigService, ConsoleToasterService, DateUtils, DynamicTableComponent, DynamicTableTemplateDirective, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExtraItemPropertiesPipe, FactoryDependencies, FileSystemEntry, FileUtils, FilterPipe, FindPipe, FormatNumberPipe, FormatterService, GenericValue, GetOffsetPipe, GetTypePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, HttpPromise, ICON_SERVICE, IConfiguration, IconDirective, IconService, Initializer, IsTypePipe, JSONfn, JoinPipe, KeysPipe, LANGUAGE_SERVICE, LanguageService, LoaderUtils, LocalHttpService, MapPipe, MathUtils, MaxPipe, MinPipe, NgxTemplateOutletDirective, NgxUtilsModule, OPTIONS_TOKEN, ObjectType, ObjectUtils, ObservableUtils, OpenApiService, PROMISE_SERVICE, PaginationDirective, PaginationItemContext, PaginationItemDirective, PaginationMenuComponent, Point, PopPipe, PromiseService, RESIZE_DELAY, RESIZE_STRATEGY, ROOT_ELEMENT, Rect, ReducePipe, ReflectUtils, RemapPipe, ReplacePipe, ResizeEventPlugin, ResourceIfContext, ResourceIfDirective, ReversePipe, RoundPipe, SCRIPT_PARAMS, SafeHtmlPipe, ScrollEventPlugin, SetUtils, ShiftPipe, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyClassDirective, StickyDirective, StorageMode, StorageService, StringUtils, TOASTER_SERVICE, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, ValuedPromise, ValuesPipe, Vector, WASI_IMPLEMENTATION, WasmService, cachedFactory, provideWithOptions };
5821
5822
  //# sourceMappingURL=stemy-ngx-utils.mjs.map