export const stopEventPropagation = (event) => {
    const e = event;
    e.preventDefault?.();
    e.stopPropagation?.();
    e.stopImmediatePropagation?.();
};
export const attachCloseToEscape = (handleClose) => {
    const closeOnEscape = (e) => {
        if (e.key === "Escape" || e.code === "Escape") {
            stopEventPropagation(e);
            handleClose();
        }
    };
    // Capture phase makes this resilient if inner components stopPropagation() on Escape.
    window.addEventListener("keydown", closeOnEscape, { capture: true });
    return () => window.removeEventListener("keydown", closeOnEscape, { capture: true });
};
