@@ -4,7 +4,7 @@ import { useStore } from '@/lib/store';
44import { presets } from '@/lib/presets' ;
55import { appCatalog } from '@/lib/apps' ;
66import { X , Clock , Layers , Check } from 'lucide-react' ;
7- import { useState , useEffect } from 'react' ;
7+ import { useState , useEffect , useRef } from 'react' ;
88import { estimateInstallTime } from '@/lib/script-generator' ;
99import { Package } from '@/types' ;
1010
@@ -15,13 +15,26 @@ interface PresetsModalProps {
1515export function PresetsModal ( { onClose } : PresetsModalProps ) {
1616 const { loadPreset, bucket, os } = useStore ( ) ;
1717 const [ applied , setApplied ] = useState < string | null > ( null ) ;
18+ const modalRef = useRef < HTMLDivElement > ( null ) ;
1819
1920 useEffect ( ( ) => {
2021 const handleKey = ( e : KeyboardEvent ) => {
2122 if ( e . key === 'Escape' ) onClose ( ) ;
2223 } ;
24+
25+ const handleClickOutside = ( e : MouseEvent ) => {
26+ if ( modalRef . current && ! modalRef . current . contains ( e . target as Node ) ) {
27+ onClose ( ) ;
28+ }
29+ } ;
30+
2331 window . addEventListener ( 'keydown' , handleKey ) ;
24- return ( ) => window . removeEventListener ( 'keydown' , handleKey ) ;
32+ document . addEventListener ( 'mousedown' , handleClickOutside ) ;
33+
34+ return ( ) => {
35+ window . removeEventListener ( 'keydown' , handleKey ) ;
36+ document . removeEventListener ( 'mousedown' , handleClickOutside ) ;
37+ } ;
2538 } , [ onClose ] ) ;
2639
2740 const handleApply = ( presetId : string , packageIds : string [ ] ) => {
@@ -34,9 +47,11 @@ export function PresetsModal({ onClose }: PresetsModalProps) {
3447
3548 return (
3649 < >
37- < div className = "fixed inset-0 z-40 bg-black/60 backdrop-blur-sm" onClick = { onClose } />
50+ < div className = "fixed inset-0 z-40 bg-black/60 backdrop-blur-sm" />
3851 < div className = "fixed inset-0 z-50 flex items-center justify-center p-4" >
39- < div className = "w-full max-w-3xl terminal-card rounded-xl overflow-hidden shadow-2xl"
52+ < div
53+ ref = { modalRef }
54+ className = "w-full max-w-3xl terminal-card rounded-xl overflow-hidden shadow-2xl"
4055 style = { { boxShadow : '0 0 60px rgba(0,255,128,0.15)' } } >
4156 { /* Header */ }
4257 < div className = "flex items-center justify-between p-5 border-b border-border bg-card" >
0 commit comments