UNPKG

@progress/kendo-angular-dateinputs

Version:

Kendo UI for Angular Date Inputs Package - Everything you need to add date selection functionality to apps (DatePicker, TimePicker, DateInput, DateRangePicker, DateTimePicker, Calendar, and MultiViewCalendar).

90 lines (89 loc) 3.6 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Injectable, NgZone } from '@angular/core'; import { CalendarDOMService } from './dom.service'; import * as i0 from "@angular/core"; import * as i1 from "./dom.service"; const divideByMagnitude = (magnitude) => x => Math.floor(x / magnitude); const powerByMagnitude = (magnitude) => x => x * magnitude; /** * @hidden */ export class ScrollSyncService { dom; zone; divideByMagnitude; powerByMagnitude; navSubscription; viewSubscription; navigator; view; constructor(dom, zone) { this.dom = dom; this.zone = zone; } configure(activeView) { const magnitude = Math.max(this.dom.viewHeight(activeView) / this.dom.navigationItemHeight, 1); this.divideByMagnitude = divideByMagnitude(magnitude); this.powerByMagnitude = powerByMagnitude(magnitude); } sync(navigator, view) { this.unsubscribe(); if (!navigator || !view) { return; } this.navigator = navigator; this.view = view; this.zone.runOutsideAngular(() => { let navScrolled, monthScrolled; this.navSubscription = navigator.scroll$() .subscribe((e) => { if (monthScrolled) { monthScrolled = false; return; } navScrolled = true; this.scrollSiblingOf(e.target); }); this.viewSubscription = view.scroll$() .subscribe((e) => { if (navScrolled) { navScrolled = false; return; } monthScrolled = true; this.scrollSiblingOf(e.target); }); }); } scrollSiblingOf(scrolledElement) { const component = this.siblingComponent(scrolledElement); const scrollTop = this.calculateScroll(component, scrolledElement.scrollTop); component.scrollTo(scrollTop); } siblingComponent(scrollableElement) { return this.navigator.container.nativeElement === scrollableElement ? this.view : this.navigator; } calculateScroll(component, scrollTop) { const modifier = component === this.navigator ? this.divideByMagnitude : this.powerByMagnitude; return modifier(scrollTop); } destroy() { this.unsubscribe(); } unsubscribe() { if (this.navSubscription) { this.navSubscription.unsubscribe(); } if (this.viewSubscription) { this.viewSubscription.unsubscribe(); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ScrollSyncService, deps: [{ token: i1.CalendarDOMService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ScrollSyncService }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ScrollSyncService, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: i1.CalendarDOMService }, { type: i0.NgZone }]; } });