@@ -13,7 +13,9 @@ export function useModalManager(): ModalManager {
1313 const [ action , setAction ] = useState < ModalAction > ( "none" ) ;
1414 const [ isLoading , setIsLoading ] = useState ( false ) ;
1515 const nextId = useRef ( 0 ) ;
16- const beforeCloseCallbacks = useRef < Map < string , ( ) => boolean > > ( new Map ( ) ) ;
16+ const beforeCloseCallbacks = useRef <
17+ Map < string , ( value ?: unknown ) => boolean >
18+ > ( new Map ( ) ) ;
1719
1820 const generateId = useCallback ( ( ) => {
1921 return `modal-${ nextId . current ++ } ` ;
@@ -27,9 +29,9 @@ export function useModalManager(): ModalManager {
2729 } ) ) ;
2830 } , [ ] ) ;
2931
30- const canClose = useCallback ( ( id : string ) : boolean => {
32+ const canClose = useCallback ( ( id : string , value ?: unknown ) : boolean => {
3133 const callback = beforeCloseCallbacks . current . get ( id ) ;
32- return callback ? callback ( ) : true ;
34+ return callback ? callback ( value ) : true ;
3335 } , [ ] ) ;
3436
3537 const closeById = useCallback (
@@ -56,12 +58,12 @@ export function useModalManager(): ModalManager {
5658
5759 return wasClosed ;
5860 } ,
59- [ updateModalStack , canClose ]
61+ [ updateModalStack ]
6062 ) ;
6163
6264 const closeCurrent = useCallback (
6365 ( id : string ) : boolean => {
64- let wasClosed = false ;
66+ const wasClosed = true ;
6567
6668 setStack ( ( prev ) => {
6769 const newStack = prev . filter ( ( m ) => m . id !== id ) ;
@@ -71,7 +73,7 @@ export function useModalManager(): ModalManager {
7173
7274 return wasClosed ;
7375 } ,
74- [ updateModalStack , canClose ]
76+ [ updateModalStack ]
7577 ) ;
7678
7779 const open = useCallback (
@@ -93,10 +95,10 @@ export function useModalManager(): ModalManager {
9395 if ( isLazyImport ) {
9496 setIsLoading ( true ) ;
9597 try {
96- const module = await (
98+ const lazyModule = await (
9799 component as ( ) => Promise < { default : ModalComponent < T , R > } >
98100 ) ( ) ;
99- actualComponent = module . default ;
101+ actualComponent = lazyModule . default ;
100102 } catch ( error ) {
101103 setIsLoading ( false ) ;
102104 throw error ;
@@ -110,11 +112,14 @@ export function useModalManager(): ModalManager {
110112 component : actualComponent ,
111113 id,
112114 isOpen : false ,
113- onBeforeClose : ( callback : ( ) => boolean ) => {
114- beforeCloseCallbacks . current . set ( id , callback ) ;
115+ onBeforeClose : ( callback : ( value ?: R ) => boolean ) => {
116+ beforeCloseCallbacks . current . set (
117+ id ,
118+ callback as ( value ?: unknown ) => boolean
119+ ) ;
115120 } ,
116121 close : ( value ?: R ) => {
117- if ( canClose ( id ) ) {
122+ if ( canClose ( id , value ) ) {
118123 resolve ( value as R ) ;
119124 closeCurrent ( id ) ;
120125 }
@@ -145,7 +150,7 @@ export function useModalManager(): ModalManager {
145150 } ) ;
146151 } ) ;
147152 } ,
148- [ generateId , updateModalStack , closeById , canClose ]
153+ [ generateId , updateModalStack , closeCurrent , canClose ]
149154 ) ;
150155
151156 const close = useCallback (
0 commit comments