@stemy/ngx-utils 19.5.20 → 19.5.21

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 'zone.js';
2
2
  import 'reflect-metadata';
3
3
  import * as i0 from '@angular/core';
4
- import { InjectionToken, PLATFORM_ID, Inject, Injectable, Optional, Injector, EventEmitter, isDevMode, ErrorHandler, createComponent, NgZone, Pipe, signal, input, output, inject, ChangeDetectorRef, Renderer2, ElementRef, effect, HostListener, Directive, Input, HostBinding, Output, computed, ChangeDetectionStrategy, ViewEncapsulation, Component, ViewChild, forwardRef, ContentChild, ContentChildren, model, contentChildren, APP_INITIALIZER, makeEnvironmentProviders, NgModule } from '@angular/core';
4
+ import { InjectionToken, PLATFORM_ID, Inject, Injectable, Optional, Injector, untracked, computed, EventEmitter, isDevMode, ErrorHandler, createComponent, NgZone, Pipe, signal, input, output, inject, ChangeDetectorRef, ElementRef, effect, HostListener, Directive, Input, HostBinding, Output, ChangeDetectionStrategy, ViewEncapsulation, Component, ViewChild, forwardRef, ContentChild, ContentChildren, model, contentChildren, Renderer2, APP_INITIALIZER, makeEnvironmentProviders, NgModule } from '@angular/core';
5
5
  import * as i2 from '@angular/router';
6
6
  import { ActivatedRouteSnapshot, Scroll, NavigationEnd, Router, DefaultUrlSerializer, UrlTree, UrlSegmentGroup, UrlSegment, UrlSerializer, ROUTES } from '@angular/router';
7
7
  import { BehaviorSubject, Observable, firstValueFrom, Subject, Subscription, from, TimeoutError, combineLatest, lastValueFrom } from 'rxjs';
@@ -2029,6 +2029,16 @@ class MathUtils {
2029
2029
  }
2030
2030
  }
2031
2031
 
2032
+ function switchClass(elem, className, status) {
2033
+ if (!elem?.classList)
2034
+ return;
2035
+ status = status ?? !elem.classList.contains(className);
2036
+ if (status) {
2037
+ elem.classList.add(className);
2038
+ return;
2039
+ }
2040
+ elem.classList.remove(className);
2041
+ }
2032
2042
  function getCssVariables(elem) {
2033
2043
  if ("computedStyleMap" in elem) {
2034
2044
  const styles = Array.from(elem.computedStyleMap());
@@ -2335,6 +2345,51 @@ class SetUtils {
2335
2345
  }
2336
2346
  }
2337
2347
 
2348
+ /**
2349
+ * Returns a signal that emits the previous value of the given signal.
2350
+ * The first time the signal is emitted, the previous value will be the same as the current value.
2351
+ *
2352
+ * @example
2353
+ * ```ts
2354
+ * const value = signal(0);
2355
+ * const previous = computedPrevious(value);
2356
+ *
2357
+ * effect(() => {
2358
+ * console.log("Current value:", value());
2359
+ * console.log("Previous value:", previous());
2360
+ * });
2361
+ *
2362
+ * Logs:
2363
+ * // Current value: 0
2364
+ * // Previous value: 0
2365
+ *
2366
+ * value.set(1);
2367
+ *
2368
+ * Logs:
2369
+ * // Current value: 1
2370
+ * // Previous value: 0
2371
+ *
2372
+ * value.set(2);
2373
+ *
2374
+ * Logs:
2375
+ * // Current value: 2
2376
+ * // Previous value: 1
2377
+ *```
2378
+ *
2379
+ * @param s Signal to compute previous value for
2380
+ * @returns Signal that emits previous value of `s`
2381
+ */
2382
+ function computedPrevious(s) {
2383
+ let current = null;
2384
+ let previous = untracked(() => s()); // initial value is the current value
2385
+ return computed(() => {
2386
+ current = s();
2387
+ const result = previous;
2388
+ previous = current;
2389
+ return result;
2390
+ });
2391
+ }
2392
+
2338
2393
  function uuid() {
2339
2394
  if (typeof window !== "undefined" && typeof window.crypto !== "undefined" && typeof window.crypto.getRandomValues !== "undefined") {
2340
2395
  const buf = new Uint16Array(8);
@@ -5287,28 +5342,25 @@ class AsyncMethodBase {
5287
5342
  this.onError = output();
5288
5343
  this.toaster = inject(TOASTER_SERVICE);
5289
5344
  this.cdr = inject(ChangeDetectorRef);
5290
- this.renderer = inject(Renderer2);
5291
5345
  this.element = inject(ElementRef);
5292
5346
  this.loading = signal(false);
5293
5347
  this.target = signal(this.element.nativeElement);
5348
+ this.previousTarget = computedPrevious(this.target);
5294
5349
  effect(() => {
5295
- const disabled = this.disabled();
5296
- const loading = this.loading();
5297
5350
  const target = this.target();
5298
5351
  if (!target)
5299
5352
  return;
5300
- if (disabled) {
5301
- this.renderer.addClass(target, "disabled");
5302
- }
5303
- else {
5304
- this.renderer.removeClass(target, "disabled");
5305
- }
5306
- if (loading) {
5307
- this.renderer.addClass(target, "loading");
5308
- }
5309
- else {
5310
- this.renderer.removeClass(target, "loading");
5311
- }
5353
+ switchClass(target, "async-target", true);
5354
+ switchClass(target, "disabled", this.disabled());
5355
+ switchClass(target, "loading", this.loading());
5356
+ });
5357
+ effect(() => {
5358
+ const previous = this.previousTarget();
5359
+ if (!previous)
5360
+ return;
5361
+ switchClass(previous, "async-target", false);
5362
+ switchClass(previous, "disabled", false);
5363
+ switchClass(previous, "loading", false);
5312
5364
  });
5313
5365
  }
5314
5366
  getMethod() {
@@ -5396,8 +5448,10 @@ class AsyncMethodTargetDirective {
5396
5448
  constructor(element, asyncMethod) {
5397
5449
  this.element = element;
5398
5450
  this.asyncMethod = asyncMethod;
5399
- if (!asyncMethod)
5451
+ if (!asyncMethod) {
5452
+ switchClass(this.element.nativeElement, "async-target", true);
5400
5453
  return;
5454
+ }
5401
5455
  asyncMethod.target.set(element.nativeElement);
5402
5456
  }
5403
5457
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: AsyncMethodTargetDirective, deps: [{ token: i0.ElementRef }, { token: AsyncMethodBase, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
@@ -6511,11 +6565,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
6511
6565
 
6512
6566
  class BtnDefaultComponent {
6513
6567
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: BtnDefaultComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
6514
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.14", type: BtnDefaultComponent, isStandalone: false, selector: "btn-default", inputs: { label: "label", tooltip: "tooltip", icon: "icon", disabled: "disabled", type: "type", size: "size" }, ngImport: i0, template: "<div class=\"default-btn btn\"\n [title]=\"!tooltip ? '' : tooltip | translate\"\n [ngClass]=\"['btn-' + type, 'btn-' + size]\">\n <icon [name]=\"icon\" *ngIf=\"icon\"></icon>\n <span *ngIf=\"label\">{{ label | translate }}</span>\n</div>\n", styles: [".default-btn{display:flex;gap:5px}\n"], dependencies: [{ kind: "directive", type: i1$3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1$3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: IconComponent, selector: "icon", inputs: ["name"] }, { kind: "pipe", type: TranslatePipe, name: "translate" }], encapsulation: i0.ViewEncapsulation.None }); }
6568
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.14", type: BtnDefaultComponent, isStandalone: false, selector: "btn-default", inputs: { label: "label", tooltip: "tooltip", icon: "icon", disabled: "disabled", type: "type", size: "size" }, ngImport: i0, template: "<div class=\"default-btn btn\"\n async-method-target\n [title]=\"!tooltip ? '' : tooltip | translate\"\n [ngClass]=\"['btn-' + type, 'btn-' + size]\">\n <icon [name]=\"icon\" *ngIf=\"icon\"></icon>\n <span *ngIf=\"label\">{{ label | translate }}</span>\n</div>\n", styles: [".default-btn{display:flex;gap:5px}\n"], dependencies: [{ kind: "directive", type: i1$3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1$3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: AsyncMethodTargetDirective, selector: "[async-method-target]" }, { kind: "component", type: IconComponent, selector: "icon", inputs: ["name"] }, { kind: "pipe", type: TranslatePipe, name: "translate" }], encapsulation: i0.ViewEncapsulation.None }); }
6515
6569
  }
6516
6570
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: BtnDefaultComponent, decorators: [{
6517
6571
  type: Component,
6518
- args: [{ standalone: false, encapsulation: ViewEncapsulation.None, selector: "btn-default", template: "<div class=\"default-btn btn\"\n [title]=\"!tooltip ? '' : tooltip | translate\"\n [ngClass]=\"['btn-' + type, 'btn-' + size]\">\n <icon [name]=\"icon\" *ngIf=\"icon\"></icon>\n <span *ngIf=\"label\">{{ label | translate }}</span>\n</div>\n", styles: [".default-btn{display:flex;gap:5px}\n"] }]
6572
+ args: [{ standalone: false, encapsulation: ViewEncapsulation.None, selector: "btn-default", template: "<div class=\"default-btn btn\"\n async-method-target\n [title]=\"!tooltip ? '' : tooltip | translate\"\n [ngClass]=\"['btn-' + type, 'btn-' + size]\">\n <icon [name]=\"icon\" *ngIf=\"icon\"></icon>\n <span *ngIf=\"label\">{{ label | translate }}</span>\n</div>\n", styles: [".default-btn{display:flex;gap:5px}\n"] }]
6519
6573
  }], propDecorators: { label: [{
6520
6574
  type: Input
6521
6575
  }], tooltip: [{
@@ -8670,5 +8724,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
8670
8724
  * Generated bundle index. Do not edit.
8671
8725
  */
8672
8726
 
8673
- export { API_SERVICE, APP_BASE_URL, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AsyncMethodTargetDirective, AuthGuard, BASE_CONFIG, BUTTON_TYPE, BackgroundDirective, BaseDialogService, BaseHttpClient, BaseHttpService, BaseToasterService, BtnComponent, BtnDefaultComponent, CONFIG_SERVICE, CanvasColor, CanvasUtils, ChipsComponent, ChunkPipe, Circle, ComponentLoaderDirective, ComponentLoaderService, ConfigService, DIALOG_SERVICE, DateUtils, DragDropEventPlugin, DropListComponent, DropdownBoxComponent, DropdownContentDirective, DropdownDirective, DropdownToggleDirective, DynamicTableComponent, DynamicTableTemplateDirective, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExtraItemPropertiesPipe, FactoryDependencies, FakeModuleComponent, FileSystemEntry, FileUtils, FilterPipe, FindPipe, ForbiddenZone, FormatNumberPipe, FormatterService, GenericValue, GetOffsetPipe, GetTypePipe, GetValuePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, HttpPromise, ICON_MAP, ICON_SERVICE, ICON_TYPE, IConfiguration, IconComponent, IconDefaultComponent, IconDirective, IconService, IncludesPipe, Initializer, InteractiveCanvasComponent, InteractiveCircleComponent, InteractiveItemComponent, InteractiveRectComponent, 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, SocketClient, SocketService, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyClassDirective, StickyDirective, StorageMode, StorageService, StringUtils, TOASTER_SERVICE, TabsComponent, TabsItemDirective, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, UploadComponent, ValuedPromise, ValuesPipe, Vector, WASI_IMPLEMENTATION, WasmService, cachedFactory, cancelablePromise, checkTransitions, getComponentDef, hashCode, impatientPromise, parseSelector, provideEntryComponents, provideWithOptions, selectorMatchesList };
8727
+ export { API_SERVICE, APP_BASE_URL, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AsyncMethodTargetDirective, AuthGuard, BASE_CONFIG, BUTTON_TYPE, BackgroundDirective, BaseDialogService, BaseHttpClient, BaseHttpService, BaseToasterService, BtnComponent, BtnDefaultComponent, CONFIG_SERVICE, CanvasColor, CanvasUtils, ChipsComponent, ChunkPipe, Circle, ComponentLoaderDirective, ComponentLoaderService, ConfigService, DIALOG_SERVICE, DateUtils, DragDropEventPlugin, DropListComponent, DropdownBoxComponent, DropdownContentDirective, DropdownDirective, DropdownToggleDirective, DynamicTableComponent, DynamicTableTemplateDirective, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExtraItemPropertiesPipe, FactoryDependencies, FakeModuleComponent, FileSystemEntry, FileUtils, FilterPipe, FindPipe, ForbiddenZone, FormatNumberPipe, FormatterService, GenericValue, GetOffsetPipe, GetTypePipe, GetValuePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, HttpPromise, ICON_MAP, ICON_SERVICE, ICON_TYPE, IConfiguration, IconComponent, IconDefaultComponent, IconDirective, IconService, IncludesPipe, Initializer, InteractiveCanvasComponent, InteractiveCircleComponent, InteractiveItemComponent, InteractiveRectComponent, 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, SocketClient, SocketService, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyClassDirective, StickyDirective, StorageMode, StorageService, StringUtils, TOASTER_SERVICE, TabsComponent, TabsItemDirective, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, UploadComponent, ValuedPromise, ValuesPipe, Vector, WASI_IMPLEMENTATION, WasmService, cachedFactory, cancelablePromise, checkTransitions, computedPrevious, getComponentDef, getCssVariables, hashCode, impatientPromise, parseSelector, provideEntryComponents, provideWithOptions, selectorMatchesList, switchClass };
8674
8728
  //# sourceMappingURL=stemy-ngx-utils.mjs.map