@ibragim-dev-org/ui-forge-library 1.4.68 → 1.4.70
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.
|
@@ -617,11 +617,16 @@ class StickyObserverDirective {
|
|
|
617
617
|
elementRef;
|
|
618
618
|
renderer;
|
|
619
619
|
$isStuck = signal(false, ...(ngDevMode ? [{ debugName: "$isStuck" }] : []));
|
|
620
|
+
isStuck = output();
|
|
620
621
|
observer;
|
|
621
622
|
sentinel;
|
|
622
623
|
constructor(elementRef, renderer) {
|
|
623
624
|
this.elementRef = elementRef;
|
|
624
625
|
this.renderer = renderer;
|
|
626
|
+
effect(() => {
|
|
627
|
+
const isStuck = this.$isStuck();
|
|
628
|
+
this.isStuck.emit(isStuck);
|
|
629
|
+
});
|
|
625
630
|
}
|
|
626
631
|
ngAfterViewInit() {
|
|
627
632
|
const stickyEl = this.elementRef.nativeElement;
|
|
@@ -632,17 +637,33 @@ class StickyObserverDirective {
|
|
|
632
637
|
this.renderer.setStyle(this.sentinel, 'opacity', '0');
|
|
633
638
|
const parent = stickyEl.parentElement;
|
|
634
639
|
parent.insertBefore(this.sentinel, stickyEl);
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
640
|
+
const root = this.findScrollParent(stickyEl);
|
|
641
|
+
const stickyTop = parseFloat(getComputedStyle(stickyEl).top) || 0;
|
|
642
|
+
// The sentinel is "stuck" once it leaves the scroll root through the sticky offset line.
|
|
643
|
+
this.observer = new IntersectionObserver((entries) => {
|
|
644
|
+
const entry = entries[entries.length - 1];
|
|
645
|
+
const rootTop = entry.rootBounds?.top ?? 0;
|
|
646
|
+
this.$isStuck.set(!entry.isIntersecting && entry.boundingClientRect.top < rootTop);
|
|
647
|
+
}, { root, rootMargin: `-${Math.ceil(stickyTop)}px 0px 0px 0px`, threshold: [0, 1] });
|
|
638
648
|
this.observer.observe(this.sentinel);
|
|
639
649
|
}
|
|
650
|
+
findScrollParent(el) {
|
|
651
|
+
let node = el.parentElement;
|
|
652
|
+
while (node) {
|
|
653
|
+
const overflowY = getComputedStyle(node).overflowY;
|
|
654
|
+
if (overflowY === 'auto' || overflowY === 'scroll') {
|
|
655
|
+
return node;
|
|
656
|
+
}
|
|
657
|
+
node = node.parentElement;
|
|
658
|
+
}
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
640
661
|
ngOnDestroy() {
|
|
641
662
|
this.observer?.disconnect();
|
|
642
663
|
this.sentinel?.remove();
|
|
643
664
|
}
|
|
644
665
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StickyObserverDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
|
|
645
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: StickyObserverDirective, isStandalone: true, selector: "[appStickyObserver]", host: { properties: { "class.sticked": "$isStuck()" } }, ngImport: i0 });
|
|
666
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: StickyObserverDirective, isStandalone: true, selector: "[appStickyObserver]", outputs: { isStuck: "isStuck" }, host: { properties: { "class.sticked": "$isStuck()" } }, ngImport: i0 });
|
|
646
667
|
}
|
|
647
668
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: StickyObserverDirective, decorators: [{
|
|
648
669
|
type: Directive,
|
|
@@ -652,7 +673,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
|
|
|
652
673
|
'[class.sticked]': '$isStuck()',
|
|
653
674
|
},
|
|
654
675
|
}]
|
|
655
|
-
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }] });
|
|
676
|
+
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }], propDecorators: { isStuck: [{ type: i0.Output, args: ["isStuck"] }] } });
|
|
656
677
|
|
|
657
678
|
const isBrowser = () => typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
658
679
|
|