@@ -7,7 +7,7 @@ import type { System } from "..";
7
7
import { modalState } from "./state" ;
8
8
import type { FullModal , IndexedModal , Modal , ModalIndex } from "./types" ;
9
9
10
- const { mutableReactive : $ } = modalState ;
10
+ const { mutableReactive : $ , raw } = modalState ;
11
11
12
12
function isComponent ( x : Component | { component : Component } ) : x is Component {
13
13
return ! ( "component" in x ) ;
@@ -36,13 +36,14 @@ class ModalSystem implements System {
36
36
}
37
37
38
38
focus ( index : ModalIndex ) : void {
39
- const orderId = modalState . raw . modalOrder . findIndex ( ( m ) => m === index ) ;
39
+ if ( raw . modalOrder . at ( - 1 ) === index ) return ;
40
+ const orderId = raw . modalOrder . findIndex ( ( m ) => m === index ) ;
40
41
if ( orderId === undefined ) {
41
42
console . log ( "Error in modal focussing" ) ;
42
43
return ;
43
44
}
44
45
// Doing it like this prevents a double update
45
- $ . modalOrder = [ ...modalState . raw . modalOrder . filter ( ( m ) => m !== index ) , index ] ;
46
+ $ . modalOrder = [ ...raw . modalOrder . filter ( ( m ) => m !== index ) , index ] ;
46
47
$ . openModals . add ( index ) ;
47
48
}
48
49
@@ -53,15 +54,15 @@ class ModalSystem implements System {
53
54
$ . openModals . delete ( modalId ) ;
54
55
if ( remove && modalId >= extraStartIndex ) {
55
56
delete $ . extraModals [ modalId - extraStartIndex ] ;
56
- $ . modalOrder . splice ( modalState . raw . modalOrder . indexOf ( modalId ) , 1 ) ;
57
+ $ . modalOrder . splice ( raw . modalOrder . indexOf ( modalId ) , 1 ) ;
57
58
}
58
59
}
59
60
60
61
addModal ( modal : FullModal ) : ModalIndex {
61
62
// First see if we can fill up a hole
62
- let extraIndex = modalState . raw . extraModals . findIndex ( ( m ) => m === undefined ) ;
63
+ let extraIndex = raw . extraModals . findIndex ( ( m ) => m === undefined ) ;
63
64
if ( extraIndex === - 1 ) {
64
- extraIndex = modalState . raw . extraModals . length ;
65
+ extraIndex = raw . extraModals . length ;
65
66
}
66
67
const modalIndex = ( extraIndex + modalState . readonly . fixedModals . length ) as ModalIndex ;
67
68
const indexedModal = { ...modal , props : { ...modal . props , modalIndex } } ;
0 commit comments