UNPKG

@ng-doc/app

Version:

<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>

91 lines (87 loc) 3.58 kB
import { __decorate, __metadata } from 'tslib'; import { DOCUMENT } from '@angular/common'; import * as i0 from '@angular/core'; import { inject, Injectable } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { Router, NavigationEnd } from '@angular/router'; import { ngDocZoneOptimize } from '@ng-doc/ui-kit'; import { NgDocScrollService } from '@ng-doc/ui-kit/services/scroll'; import { WINDOW } from '@ng-web-apis/common'; import { UntilDestroy } from '@ngneat/until-destroy'; import { BehaviorSubject, fromEvent, share } from 'rxjs'; import { startWith, filter } from 'rxjs/operators'; /** * Service for sidebar, it can be used to hide/show sidebar or to check if sidebar is collapsable. */ let NgDocSidebarService = class NgDocSidebarService { constructor() { this.expanded = new BehaviorSubject(false); this.document = inject(DOCUMENT); this.window = inject(WINDOW); this.router = inject(Router); this.scroll = inject(NgDocScrollService); const windowResize = fromEvent(this.window, 'resize').pipe(takeUntilDestroyed(), startWith(null), share()); windowResize .pipe(filter(() => this.expanded.value && this.isMobile), ngDocZoneOptimize(), takeUntilDestroyed()) .subscribe(() => this.hide()); windowResize .pipe(filter(() => !this.expanded.value && !this.isMobile), ngDocZoneOptimize(), takeUntilDestroyed()) .subscribe(() => this.show()); windowResize .pipe(filter(() => this.expanded.value && !this.isMobile), ngDocZoneOptimize(), takeUntilDestroyed()) .subscribe(() => this.scroll.unblock()); this.router.events .pipe(filter((event) => event instanceof NavigationEnd && this.expanded.value && this.isMobile), takeUntilDestroyed()) .subscribe(() => this.hide()); } get isMobile() { return this.window.innerWidth < 1024; } /** * Indicates if sidebar is visible, based on the show/hide methods. */ isExpanded() { return this.expanded.asObservable(); } /** * Show sidebar, and block scrolling. */ show() { if (!this.expanded.value) { this.expanded.next(true); this.isMobile && this.scroll.block(); } } /** * Hide sidebar, and unblock scrolling. */ hide() { if (this.expanded.value) { this.expanded.next(false); this.isMobile && this.scroll.unblock(); } } /** * Toggle sidebar visibility. */ toggle() { this.expanded.value ? this.hide() : this.show(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgDocSidebarService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgDocSidebarService, providedIn: 'root' }); } }; NgDocSidebarService = __decorate([ UntilDestroy(), __metadata("design:paramtypes", []) ], NgDocSidebarService); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgDocSidebarService, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: () => [] }); /** * Generated bundle index. Do not edit. */ export { NgDocSidebarService }; //# sourceMappingURL=ng-doc-app-services-sidebar.mjs.map