{"version":3,"file":"ClickOutside.cjs","names":[],"sources":["../../../src/components/ClickOutside/ClickOutside.tsx"],"sourcesContent":["import { useEffect, useRef, type HTMLAttributes, type ReactNode } from \"react\";\nimport { useLatestRef } from \"@/hooks/use-latest-ref\";\n\nexport interface ClickOutsideProps extends HTMLAttributes<HTMLDivElement> {\n    /** Called when a pointer event lands outside the wrapped subtree. */\n    onOutside: (event: MouseEvent | TouchEvent) => void;\n    /** Content wrapped by the outside-click boundary. */\n    children: ReactNode;\n}\n\n/**\n * Wraps its children in a `<div>` and invokes `onOutside` whenever a\n * `mousedown` or `touchstart` event occurs outside that subtree.\n *\n * Useful for dismissing popovers, dropdowns and menus on outside interaction.\n * Listeners are attached to `document` on mount and removed on unmount.\n *\n * @param props - The click-outside props, plus any `<div>` attributes.\n * @returns The wrapper element containing the children.\n */\nexport function ClickOutside({ onOutside, children, ...props }: ClickOutsideProps): ReactNode {\n    const ref = useRef<HTMLDivElement>(null);\n    const handlerRef = useLatestRef(onOutside);\n\n    useEffect(() => {\n        if (typeof document === \"undefined\") {\n            return;\n        }\n\n        function handle(event: MouseEvent | TouchEvent): void {\n            const node = ref.current;\n            const target = event.target as Node | null;\n            if (node && target && !node.contains(target)) {\n                handlerRef.current(event);\n            }\n        }\n\n        document.addEventListener(\"mousedown\", handle);\n        document.addEventListener(\"touchstart\", handle);\n        return () => {\n            document.removeEventListener(\"mousedown\", handle);\n            document.removeEventListener(\"touchstart\", handle);\n        };\n    }, [handlerRef]);\n\n    return (\n        <div ref={ref} {...props}>\n            {children}\n        </div>\n    );\n}\n"],"mappings":"wGAoBA,SAAgB,EAAa,CAAE,YAAW,WAAU,GAAG,GAAuC,CAC1F,IAAM,GAAA,EAAM,EAAA,OAAA,CAAuB,IAAI,EACjC,EAAa,EAAA,aAAa,CAAS,EAuBzC,OArBA,EAAA,EAAA,UAAA,KAAgB,CACZ,GAAI,OAAO,SAAa,IACpB,OAGJ,SAAS,EAAO,EAAsC,CAClD,IAAM,EAAO,EAAI,QACX,EAAS,EAAM,OACjB,GAAQ,GAAU,CAAC,EAAK,SAAS,CAAM,GACvC,EAAW,QAAQ,CAAK,CAEhC,CAIA,OAFA,SAAS,iBAAiB,YAAa,CAAM,EAC7C,SAAS,iBAAiB,aAAc,CAAM,MACjC,CACT,SAAS,oBAAoB,YAAa,CAAM,EAChD,SAAS,oBAAoB,aAAc,CAAM,CACrD,CACJ,EAAG,CAAC,CAAU,CAAC,GAGX,EAAA,EAAA,IAAA,CAAC,MAAD,CAAU,MAAK,GAAI,EACd,UACA,CAAA,CAEb"}