@@ -8,10 +8,10 @@ import { useFocusTrap } from './useFocusTrap'
8
8
import { useLockScroll } from ' ./useBodyScrollLock'
9
9
import { useZIndex } from ' ./useZIndex'
10
10
import { vVisible } from ' ./vVisible'
11
- import { noop , once } from ' ~/utils'
11
+ import { arrayMoveItemToLast , arrayRemoveItem , noop , once } from ' ~/utils'
12
12
import { type Modal } from ' ~/Modal'
13
13
import { useSwipeToClose } from ' ~/useSwipeToClose'
14
- import { useInternalVfm , useVfm } from ' ~/useApi'
14
+ import { useVfm } from ' ~/useApi'
15
15
16
16
export interface VueFinalModalEmits {
17
17
(e : ' update:modelValue' , modelValue : boolean ): void
@@ -26,30 +26,17 @@ export interface VueFinalModalEmits {
26
26
}
27
27
28
28
const props = defineProps (vueFinalModalProps )
29
-
30
29
const emit = defineEmits <VueFinalModalEmits >()
31
-
32
30
const attrs = useAttrs ()
33
31
34
- defineOptions ({
35
- inheritAttrs: false ,
36
- })
32
+ defineOptions ({ inheritAttrs: false })
37
33
38
34
defineSlots <{
39
35
' default' (): void
40
36
' swipe-banner' (): void
41
37
}>()
42
38
43
- const { modals, openedModals } = useVfm ()
44
-
45
- const {
46
- openLastOverlay,
47
- moveToLastOpenedModals,
48
- deleteFromOpenedModals,
49
- moveToLastOpenedModalOverlays,
50
- deleteFromOpenedModalOverlays,
51
- deleteFromModals,
52
- } = useInternalVfm ()
39
+ const { modals, openedModals, openedModalOverlays } = useVfm ()
53
40
54
41
const vfmRootEl = ref <HTMLDivElement >()
55
42
const vfmContentEl = ref <HTMLDivElement >()
@@ -90,7 +77,7 @@ const {
90
77
resolveToggle (' opened' )
91
78
},
92
79
onLeave() {
93
- deleteFromOpenedModals ( getModalInstance () )
80
+ arrayRemoveItem ( openedModals , modalInstance )
94
81
resetZIndex ()
95
82
enableBodyScroll ()
96
83
emit (' closed' )
@@ -107,35 +94,32 @@ const {
107
94
} = useSwipeToClose (props , { vfmContentEl , modelValueLocal })
108
95
109
96
const hideOverlay = toRef (props , ' hideOverlay' )
97
+ const overlayBehavior = toRef (props , ' overlayBehavior' )
110
98
const modalInstance = computed <Modal >(() => ({
111
99
modalId: props .modalId ,
112
100
hideOverlay ,
101
+ overlayBehavior ,
113
102
overlayVisible ,
114
- focus ,
115
103
toggle(show ? : boolean ): Promise <string > {
116
104
return new Promise ((resolve ) => {
117
105
resolveToggle = once ((res : string ) => resolve (res ))
118
106
119
107
const value = typeof show === ' boolean' ? show : ! modelValueLocal .value
120
108
modelValueLocal .value = value
121
- emit (' update:modelValue' , value )
122
109
})
123
110
},
124
111
}))
125
112
126
- function getModalInstance() {
127
- return modalInstance
128
- }
129
-
130
113
const index = computed (() => openedModals .indexOf (modalInstance ))
131
114
132
115
watch ([() => props .zIndexFn , index ], () => {
133
- if (visible .value )
134
- refreshZIndex (index .value )
116
+ if (! visible .value )
117
+ return
118
+ refreshZIndex (index .value )
135
119
})
136
120
137
121
onMounted (() => {
138
- modals . push ( modalInstance )
122
+ arrayMoveItemToLast ( modals , modalInstance )
139
123
})
140
124
141
125
if (props .modelValue )
@@ -146,9 +130,8 @@ function open(): boolean {
146
130
emit (' beforeOpen' , { stop : () => shouldStop = true })
147
131
if (shouldStop )
148
132
return false
149
- moveToLastOpenedModals (modalInstance )
150
- moveToLastOpenedModalOverlays (modalInstance )
151
- refreshZIndex (index .value )
133
+ arrayMoveItemToLast (openedModals , modalInstance )
134
+ arrayMoveItemToLast (openedModalOverlays , modalInstance )
152
135
openLastOverlay ()
153
136
enterTransition ()
154
137
return true
@@ -159,7 +142,7 @@ function close(): boolean {
159
142
emit (' beforeClose' , { stop : () => shouldStop = true })
160
143
if (shouldStop )
161
144
return false
162
- deleteFromOpenedModalOverlays ( getModalInstance () )
145
+ arrayRemoveItem ( openedModalOverlays , modalInstance )
163
146
openLastOverlay ()
164
147
blur ()
165
148
leaveTransition ()
@@ -168,12 +151,21 @@ function close(): boolean {
168
151
169
152
onBeforeUnmount (() => {
170
153
enableBodyScroll ()
171
- deleteFromModals (modalInstance )
172
- deleteFromOpenedModals (modalInstance )
173
- deleteFromOpenedModalOverlays (modalInstance )
154
+ arrayRemoveItem (modals , modalInstance )
155
+ arrayRemoveItem (openedModals , modalInstance )
174
156
blur ()
175
157
openLastOverlay ()
176
158
})
159
+
160
+ async function openLastOverlay() {
161
+ await nextTick ()
162
+ // Found the modals which has overlay and has `auto` overlayBehavior
163
+ const openedModalsOverlaysAuto = openedModalOverlays .filter (modal => modal .value .overlayBehavior .value === ' auto' && ! modal .value .hideOverlay ?.value )
164
+ // Only keep the last overlay open
165
+ openedModalsOverlaysAuto .forEach ((modal , index ) => {
166
+ modal .value .overlayVisible .value = index === openedModalsOverlaysAuto .length - 1
167
+ })
168
+ }
177
169
</script >
178
170
179
171
<template >
@@ -193,7 +185,7 @@ onBeforeUnmount(() => {
193
185
@mouseup.self =" () => onMouseupRoot()"
194
186
@mousedown.self =" e => onMousedown(e)"
195
187
>
196
- <Transition v-if =" !hideOverlay" v-bind =" overlayTransition" :appear = " true " v-on =" overlayListeners" >
188
+ <Transition v-if =" !hideOverlay" v-bind =" ( overlayTransition as object) " v-on =" overlayListeners" >
197
189
<div
198
190
v-if =" displayDirective !== 'if' || overlayVisible"
199
191
v-show =" displayDirective !== 'show' || overlayVisible"
@@ -204,7 +196,7 @@ onBeforeUnmount(() => {
204
196
aria-hidden =" true"
205
197
/>
206
198
</Transition >
207
- <Transition v-bind =" contentTransition" :appear = " true " v-on =" contentListeners" >
199
+ <Transition v-bind =" ( contentTransition as object) " v-on =" contentListeners" >
208
200
<div
209
201
v-if =" displayDirective !== 'if' || contentVisible"
210
202
v-show =" displayDirective !== 'show' || contentVisible"
0 commit comments