{"version":3,"file":"ng-mat-select-infinite-scroll.mjs","sources":["../../../projects/ng-mat-select-infinite-scroll/src/lib/mat-select-infinite-scroll.directive.ts","../../../projects/ng-mat-select-infinite-scroll/src/lib/mat-select-infinite-scroll.module.ts","../../../projects/ng-mat-select-infinite-scroll/src/public-api.ts","../../../projects/ng-mat-select-infinite-scroll/src/ng-mat-select-infinite-scroll.ts"],"sourcesContent":["import {AfterViewInit, Directive, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output} from '@angular/core';\nimport {MatSelect} from '@angular/material/select';\nimport {debounceTime, takeUntil, tap} from 'rxjs/operators';\nimport {fromEvent, Subject} from 'rxjs';\n\n/** The height of the select items in `em` units. */\nconst SELECT_ITEM_HEIGHT_EM = 3;\n\n@Directive({\n selector: '[msInfiniteScroll]'\n})\nexport class MatSelectInfiniteScrollDirective implements OnInit, OnDestroy, AfterViewInit {\n\n @Input() threshold = '15%';\n @Input() debounceTime = 150;\n @Input() complete!: boolean;\n @Output() infiniteScroll = new EventEmitter();\n\n private panel!: Element;\n private thrPx = 0;\n private thrPc = 0;\n private singleOptionHeight = SELECT_ITEM_HEIGHT_EM;\n\n private destroyed$ = new Subject();\n\n constructor(private matSelect: MatSelect, private ngZone: NgZone) {\n }\n\n ngOnInit() {\n this.evaluateThreshold();\n }\n\n ngAfterViewInit() {\n this.matSelect.openedChange.pipe(\n takeUntil(this.destroyed$)\n ).subscribe((opened) => {\n if (opened) {\n this.panel = this.matSelect.panel.nativeElement;\n this.singleOptionHeight = this.getSelectItemHeightPx();\n this.registerScrollListener();\n }\n });\n }\n\n ngOnDestroy() {\n this.destroyed$.next(true);\n this.destroyed$.complete();\n }\n\n evaluateThreshold() {\n if (this.threshold.lastIndexOf('%') > -1) {\n this.thrPx = 0;\n this.thrPc = (parseFloat(this.threshold) / 100);\n\n } else {\n this.thrPx = parseFloat(this.threshold);\n this.thrPc = 0;\n }\n }\n\n registerScrollListener() {\n fromEvent(this.panel, 'scroll').pipe(\n takeUntil(this.destroyed$),\n debounceTime(this.debounceTime),\n tap((event) => {\n this.handleScrollEvent(event);\n })\n ).subscribe();\n }\n\n handleScrollEvent(event: any) {\n this.ngZone.runOutsideAngular(() => {\n if (this.complete) {\n return;\n }\n const countOfRenderedOptions = this.matSelect.options.length;\n const infiniteScrollDistance = this.singleOptionHeight * countOfRenderedOptions;\n const threshold = this.thrPc !== 0 ? (infiniteScrollDistance * this.thrPc) : this.thrPx;\n\n const scrolledDistance = this.panel.clientHeight + event.target.scrollTop;\n\n if ((scrolledDistance + threshold) >= infiniteScrollDistance) {\n this.ngZone.run(() => this.infiniteScroll.emit());\n }\n });\n }\n\n getSelectItemHeightPx(): number {\n return parseFloat(getComputedStyle(this.panel).fontSize) * SELECT_ITEM_HEIGHT_EM;\n }\n\n}\n","import {NgModule} from '@angular/core';\nimport {MatSelectInfiniteScrollDirective} from './mat-select-infinite-scroll.directive';\nimport {MatSelectModule} from '@angular/material/select';\n\n@NgModule({\n declarations: [MatSelectInfiniteScrollDirective],\n imports: [\n MatSelectModule\n ],\n exports: [MatSelectInfiniteScrollDirective]\n})\nexport class MatSelectInfiniteScrollModule {\n}\n","/*\n * Public API Surface of ng-mat-select-infinite-scroll\n */\n\nexport * from './lib/mat-select-infinite-scroll.directive';\nexport * from './lib/mat-select-infinite-scroll.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAKA;AACA,MAAM,qBAAqB,GAAG,CAAC,CAAC;MAKnB,gCAAgC,CAAA;IAc3C,WAAoB,CAAA,SAAoB,EAAU,MAAc,EAAA;QAA5C,IAAS,CAAA,SAAA,GAAT,SAAS,CAAW;QAAU,IAAM,CAAA,MAAA,GAAN,MAAM,CAAQ;QAZvD,IAAS,CAAA,SAAA,GAAG,KAAK,CAAC;QAClB,IAAY,CAAA,YAAA,GAAG,GAAG,CAAC;AAElB,QAAA,IAAA,CAAA,cAAc,GAAG,IAAI,YAAY,EAAQ,CAAC;QAG5C,IA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