@@ -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 } from 'react' ;
7+ import { useState , useEffect , useRef } from 'react' ;
88import { estimateInstallTime } from '@/lib/script-generator' ;
99import { Package } from '@/types' ;
1010
@@ -15,6 +15,27 @@ 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 ) ;
19+
20+ useEffect ( ( ) => {
21+ const handleKey = ( e : KeyboardEvent ) => {
22+ if ( e . key === 'Escape' ) onClose ( ) ;
23+ } ;
24+
25+ const handleClickOutside = ( e : MouseEvent ) => {
26+ if ( modalRef . current && ! modalRef . current . contains ( e . target as Node ) ) {
27+ onClose ( ) ;
28+ }
29+ } ;
30+
31+ window . addEventListener ( 'keydown' , handleKey ) ;
32+ document . addEventListener ( 'mousedown' , handleClickOutside ) ;
33+
34+ return ( ) => {
35+ window . removeEventListener ( 'keydown' , handleKey ) ;
36+ document . removeEventListener ( 'mousedown' , handleClickOutside ) ;
37+ } ;
38+ } , [ onClose ] ) ;
1839
1940 const handleApply = ( presetId : string , packageIds : string [ ] ) => {
2041 loadPreset ( packageIds ) ;
@@ -26,9 +47,11 @@ export function PresetsModal({ onClose }: PresetsModalProps) {
2647
2748 return (
2849 < >
29- < 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" />
3051 < div className = "fixed inset-0 z-50 flex items-center justify-center p-4" >
31- < 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"
3255 style = { { boxShadow : '0 0 60px rgba(0,255,128,0.15)' } } >
3356 { /* Header */ }
3457 < div className = "flex items-center justify-between p-5 border-b border-border bg-card" >
0 commit comments