@progress/kendo-angular-common
Version:
Kendo UI for Angular - Utility Package
71 lines (70 loc) • 2.72 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2020 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import * as tslib_1 from "tslib";
import { Component, EventEmitter, Input, Output, ElementRef, NgZone } from '@angular/core';
import { auditTime } from 'rxjs/operators';
import { ResizeCompatService } from './compat.service';
import { ResizeObserverService } from './observer.service';
import { ResizeBatchService } from './resize-batch.service';
/**
* Emit up to 10 resize events per second by default.
* Chosen as a compromise between responsiveness and performance.
*/
const DEFAULT_RATE_LIMIT = 10;
/**
* Resize Sensor Component
*
* Triggers a "resize" event whenever the parent DOM element size changes.
*/
let ResizeSensorComponent = class ResizeSensorComponent {
constructor(resizeBatchService, element, ngZone) {
/**
* The maximum number of resize events to emit per second.
*
* Defaults to 10.
*/
this.rateLimit = DEFAULT_RATE_LIMIT;
/**
* Fires when the parent DOM element has been resized.
*/
this.resize = new EventEmitter();
const serviceType = ResizeObserverService.supported() ? ResizeObserverService : ResizeCompatService;
this.resizeService = new serviceType(resizeBatchService, element, ngZone);
const throttleTime = 1000 / (this.rateLimit || DEFAULT_RATE_LIMIT);
this.subscription = this.resizeService.resize
.pipe(auditTime(throttleTime))
.subscribe(() => {
if (!this.resizeService.acceptedSize) {
this.resize.emit();
}
});
}
ngAfterViewChecked() {
this.resizeService.checkChanges();
}
ngOnDestroy() {
this.subscription.unsubscribe();
this.resizeService.destroy();
}
acceptSize(size) {
this.resizeService.acceptSize(size);
}
};
tslib_1.__decorate([
Input(),
tslib_1.__metadata("design:type", Number)
], ResizeSensorComponent.prototype, "rateLimit", void 0);
tslib_1.__decorate([
Output(),
tslib_1.__metadata("design:type", EventEmitter)
], ResizeSensorComponent.prototype, "resize", void 0);
ResizeSensorComponent = tslib_1.__decorate([
Component({
selector: 'kendo-resize-sensor',
template: ''
}),
tslib_1.__metadata("design:paramtypes", [ResizeBatchService, ElementRef, NgZone])
], ResizeSensorComponent);
export { ResizeSensorComponent };