@tanstack/lit-virtual
Version:
Headless UI for virtualizing scrollable elements in Lit
57 lines (56 loc) • 1.65 kB
JavaScript
import { elementScroll, observeElementOffset, observeElementRect, windowScroll, observeWindowOffset, observeWindowRect, Virtualizer } from "@tanstack/virtual-core";
class VirtualizerControllerBase {
constructor(host, options) {
this.cleanup = () => {
};
const resolvedOptions = {
...options,
onChange: (instance, sync) => {
var _a;
this.host.updateComplete.then(() => this.host.requestUpdate());
(_a = options.onChange) == null ? void 0 : _a.call(options, instance, sync);
}
};
this.virtualizer = new Virtualizer(resolvedOptions);
(this.host = host).addController(this);
}
getVirtualizer() {
return this.virtualizer;
}
hostConnected() {
this.cleanup = this.virtualizer._didMount();
}
hostUpdated() {
this.virtualizer._willUpdate();
}
hostDisconnected() {
this.cleanup();
}
}
class VirtualizerController extends VirtualizerControllerBase {
constructor(host, options) {
super(host, {
observeElementRect,
observeElementOffset,
scrollToFn: elementScroll,
...options
});
}
}
class WindowVirtualizerController extends VirtualizerControllerBase {
constructor(host, options) {
super(host, {
getScrollElement: () => typeof document !== "undefined" ? window : null,
observeElementRect: observeWindowRect,
observeElementOffset: observeWindowOffset,
scrollToFn: windowScroll,
initialOffset: () => typeof document !== "undefined" ? window.scrollY : 0,
...options
});
}
}
export {
VirtualizerController,
WindowVirtualizerController
};
//# sourceMappingURL=index.js.map