UNPKG

@revolist/revogrid

Version:

Virtual reactive data grid spreadsheet component - RevoGrid.

44 lines (43 loc) 1.34 kB
/*! * Built by Revolist OU ❤️ */ import throttle from "lodash/throttle"; import { resizeObserver } from "../../utils/resize-observer.polifill"; export default class GridResizeService { constructor(el, resize) { this.resize = resize; this.resizeObserver = null; this.previousSize = { width: 0, height: 0, }; this.apply = throttle((e) => { var _a; if (!e.length) { return; } const entry = { width: e[0].contentRect.width, height: e[0].contentRect.height, }; (_a = this.resize) === null || _a === void 0 ? void 0 : _a.call(this, entry, this.previousSize); this.previousSize = entry; }, 40, { leading: false, trailing: true, }); this.init(el); } async init(el) { var _a; await resizeObserver(); this.resizeObserver = new ResizeObserver(this.apply); (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(el); } destroy() { var _a; (_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect(); this.resizeObserver = null; } } //# sourceMappingURL=viewport.resize.service.js.map