@ibragim-dev-org/ui-forge-library 1.4.34 → 1.4.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.
|
@@ -5,7 +5,7 @@ import * as i0 from '@angular/core';
|
|
|
5
5
|
import { model, effect, Directive, Injectable, output, Input, input, PLATFORM_ID, Inject, EventEmitter, Output, Pipe, Attribute, ChangeDetectionStrategy, Component, signal, computed, viewChild, untracked, Injector, afterRenderEffect, contentChildren, contentChild, ViewChildren } from '@angular/core';
|
|
6
6
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
7
7
|
import { isPlatformBrowser, DOCUMENT, NgStyle } from '@angular/common';
|
|
8
|
-
import { throttleTime, tap as tap$1, takeUntil } from 'rxjs/operators';
|
|
8
|
+
import { throttleTime, tap as tap$1, takeUntil, debounceTime as debounceTime$1 } from 'rxjs/operators';
|
|
9
9
|
import * as i2 from '@angular/platform-browser';
|
|
10
10
|
import { PhoneNumberUtil, AsYouTypeFormatter } from 'google-libphonenumber';
|
|
11
11
|
import { ulid } from 'ulid';
|
|
@@ -791,6 +791,12 @@ class StableScrollDirective {
|
|
|
791
791
|
destroy$ = new Subject();
|
|
792
792
|
scrolling$ = new Subject();
|
|
793
793
|
_isScrolling = false;
|
|
794
|
+
// ---- thresholds ----
|
|
795
|
+
$topThreshold = input(0, ...(ngDevMode ? [{ debugName: "$topThreshold" }] : []));
|
|
796
|
+
$bottomThreshold = input(0, ...(ngDevMode ? [{ debugName: "$bottomThreshold" }] : []));
|
|
797
|
+
reachedTop = output();
|
|
798
|
+
reachedBottom = output();
|
|
799
|
+
// ---- anchor ----
|
|
794
800
|
anchorElement = null;
|
|
795
801
|
anchorOffset = 0;
|
|
796
802
|
constructor(elRef) {
|
|
@@ -805,8 +811,13 @@ class StableScrollDirective {
|
|
|
805
811
|
.pipe(throttleTime(50), tap$1(() => {
|
|
806
812
|
this._isScrolling = true;
|
|
807
813
|
this.scrolling$.next();
|
|
814
|
+
this.checkThresholds();
|
|
808
815
|
}), takeUntil(this.destroy$))
|
|
809
816
|
.subscribe();
|
|
817
|
+
// scroll end detection
|
|
818
|
+
this.scrolling$
|
|
819
|
+
.pipe(debounceTime$1(120), tap$1(() => (this._isScrolling = false)), takeUntil(this.destroy$))
|
|
820
|
+
.subscribe();
|
|
810
821
|
// element resize
|
|
811
822
|
this.resizeObserver = new ResizeObserver(() => {
|
|
812
823
|
if (!this._isScrolling) {
|
|
@@ -832,14 +843,30 @@ class StableScrollDirective {
|
|
|
832
843
|
this.resizeObserver.disconnect();
|
|
833
844
|
}
|
|
834
845
|
}
|
|
835
|
-
/** Call
|
|
846
|
+
/** Call BEFORE data changes */
|
|
836
847
|
captureBeforeChange() {
|
|
837
848
|
this.captureAnchor();
|
|
838
849
|
}
|
|
839
|
-
/** Call
|
|
850
|
+
/** Call AFTER render */
|
|
840
851
|
restoreScrollPosition() {
|
|
841
852
|
this.restoreAnchor();
|
|
842
853
|
}
|
|
854
|
+
// ---- threshold logic ----
|
|
855
|
+
checkThresholds() {
|
|
856
|
+
const { scrollTop, scrollHeight, clientHeight } = this.el;
|
|
857
|
+
// top threshold
|
|
858
|
+
const topThreshold = this.$topThreshold();
|
|
859
|
+
const topPx = topThreshold <= 1 ? scrollHeight * topThreshold : topThreshold;
|
|
860
|
+
if (scrollTop <= topPx) {
|
|
861
|
+
this.reachedTop.emit();
|
|
862
|
+
}
|
|
863
|
+
// bottom threshold
|
|
864
|
+
const bottomThreshold = this.$bottomThreshold();
|
|
865
|
+
const bottomPx = bottomThreshold <= 1 ? scrollHeight * bottomThreshold : bottomThreshold;
|
|
866
|
+
if (scrollTop + clientHeight >= scrollHeight - bottomPx) {
|
|
867
|
+
this.reachedBottom.emit();
|
|
868
|
+
}
|
|
869
|
+
}
|
|
843
870
|
// ---- anchor logic ----
|
|
844
871
|
captureAnchor() {
|
|
845
872
|
const el = this.el;
|
|
@@ -867,15 +894,14 @@ class StableScrollDirective {
|
|
|
867
894
|
this.anchorElement = null;
|
|
868
895
|
}
|
|
869
896
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
870
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "
|
|
897
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: StableScrollDirective, isStandalone: true, selector: "[stableScroll]", inputs: { $topThreshold: { classPropertyName: "$topThreshold", publicName: "$topThreshold", isSignal: true, isRequired: false, transformFunction: null }, $bottomThreshold: { classPropertyName: "$bottomThreshold", publicName: "$bottomThreshold", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { reachedTop: "reachedTop", reachedBottom: "reachedBottom" }, ngImport: i0 });
|
|
871
898
|
}
|
|
872
899
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StableScrollDirective, decorators: [{
|
|
873
900
|
type: Directive,
|
|
874
901
|
args: [{
|
|
875
902
|
selector: '[stableScroll]',
|
|
876
|
-
standalone: true,
|
|
877
903
|
}]
|
|
878
|
-
}], ctorParameters: () => [{ type: i0.ElementRef }] });
|
|
904
|
+
}], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { $topThreshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "$topThreshold", required: false }] }], $bottomThreshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "$bottomThreshold", required: false }] }], reachedTop: [{ type: i0.Output, args: ["reachedTop"] }], reachedBottom: [{ type: i0.Output, args: ["reachedBottom"] }] } });
|
|
879
905
|
|
|
880
906
|
class CenterEllipsisPipe {
|
|
881
907
|
transform(value, visibleStart = 4, visibleEnd = 4) {
|