diff --git a/frontend/src/screens/App/screens/ViewerPane/shared/utils/useEventForwarding.ts b/frontend/src/screens/App/screens/ViewerPane/shared/utils/useEventForwarding.ts deleted file mode 100644 index 2c5ec23a..00000000 --- a/frontend/src/screens/App/screens/ViewerPane/shared/utils/useEventForwarding.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { useEffect } from 'react'; - -type EventConstructor = new ( - type: string, - eventInitDict?: EventInit -) => T; - -type EventNames = keyof GlobalEventHandlersEventMap; - -/** - * Custom hook to forward specified events from an overlay element to a target element. - * @param overlayRef - Ref to the overlay element - * @param targetRef - Ref to the target element - * @param events - List of event names to forward - */ -const useEventForwarding = ( - sourceEl: HTMLElement, - targetEl: HTMLElement, - events: readonly EventNames[] -): void => { - useEffect(() => { - if (!sourceEl || !targetEl) return; - - const reDispatchEvent = ( - event: GlobalEventHandlersEventMap[keyof GlobalEventHandlersEventMap] - ): void => { - const newEvent = new (event.constructor as EventConstructor)( - event.type, - event - ); - - targetEl.dispatchEvent(newEvent); - }; - - // Attach listeners to the overlay - events.forEach((eventName) => { - sourceEl.addEventListener(eventName, reDispatchEvent, { passive: true }); - }); - - return () => { - // Clean up listeners on unmount - events.forEach((eventName) => { - sourceEl.removeEventListener(eventName, reDispatchEvent); - }); - }; - }, [sourceEl, targetEl, events]); -}; - -export default useEventForwarding;