@tldraw/editor
Version:
tldraw infinite canvas SDK (editor).
33 lines (32 loc) • 1.06 kB
JavaScript
import { useEffect } from "react";
import { preventDefault } from "../utils/dom.mjs";
import { useContainer } from "./useContainer.mjs";
function usePassThroughWheelEvents(ref) {
if (!ref) throw Error("usePassThroughWheelEvents must be passed a ref");
const container = useContainer();
useEffect(() => {
function onWheel(e) {
if (e.isSpecialRedispatchedEvent) return;
const elm2 = ref.current;
if (elm2 && elm2.scrollHeight > elm2.clientHeight) {
return;
}
preventDefault(e);
const cvs = container.querySelector(".tl-canvas");
if (!cvs) return;
const newEvent = new WheelEvent("wheel", e);
newEvent.isSpecialRedispatchedEvent = true;
cvs.dispatchEvent(newEvent);
}
const elm = ref.current;
if (!elm) return;
elm.addEventListener("wheel", onWheel, { passive: false });
return () => {
elm.removeEventListener("wheel", onWheel);
};
}, [container, ref]);
}
export {
usePassThroughWheelEvents
};
//# sourceMappingURL=usePassThroughWheelEvents.mjs.map