11<script setup lang="ts">
2- import { computed , onBeforeUnmount , shallowRef , watch } from ' vue'
2+ import { computed , onBeforeUnmount } from ' vue'
33import { isString } from ' @vueuse/core'
4- import type { Ref } from ' vue'
5- import type { UseModalOptions , UseModalOptionsPrivate } from ' ../Modal'
64import { useInternalVfm , useVfm } from ' ~/useApi'
75
86const vfm = useVfm ()
@@ -11,39 +9,6 @@ const _vfm = useInternalVfm()
119const uid = Symbol (' ModalsContainer' )
1210const shouldMount = computed (() => uid === vfm .modalsContainers .value ?.[0 ])
1311
14- const openedDynamicModals: Ref <(UseModalOptions <any > & UseModalOptionsPrivate )[]> = shallowRef ([])
15-
16- function syncOpenDynamicModals() {
17- openedDynamicModals .value = vfm .dynamicModals .filter (modal => modal .modelValue )
18- }
19-
20- function withSyncOpenDynamicModals(callbackFn ? : () => void ) {
21- callbackFn ?.()
22- syncOpenDynamicModals ()
23- }
24-
25- watch (() => vfm .dynamicModals ?.map (modal => modal .modelValue ), (value , oldValue ) => {
26- if (! oldValue || value .length !== oldValue .length ) {
27- syncOpenDynamicModals ()
28- return
29- }
30-
31- let index = value .length
32- let shouldUpdate = false
33-
34- while (! shouldUpdate && index -- ) {
35- if (value [index ] === true && oldValue [index ] === false )
36- shouldUpdate = true
37- }
38-
39- if (! shouldUpdate )
40- return
41-
42- syncOpenDynamicModals ()
43- }, {
44- immediate: true ,
45- })
46-
4712vfm .modalsContainers .value .push (uid )
4813onBeforeUnmount (() => {
4914 vfm .modalsContainers .value = vfm .modalsContainers .value .filter (i => i !== uid )
@@ -54,11 +19,11 @@ onBeforeUnmount(() => {
5419 <template v-if =" shouldMount " >
5520 <component
5621 :is =" modal.component"
57- v-for =" (modal, index) in openedDynamicModals "
22+ v-for =" (modal, index) in vfm.dynamicModals "
5823 :key =" modal.id"
5924 v-bind =" modal.attrs"
6025 v-model =" modal.modelValue"
61- @closed =" () => withSyncOpenDynamicModals(() => _vfm.resolvedClosed?.(index) )"
26+ @closed =" () => _vfm.resolvedClosed?.(index)"
6227 @opened =" () => _vfm.resolvedOpened?.(index)"
6328 >
6429 <template v-for =" (slot , key ) in modal .slots " #[key ] :key =" key " >
0 commit comments