1
1
<script setup lang="ts">
2
- import { computed , onBeforeUnmount , shallowRef , watch } from ' vue'
2
+ import { computed , onBeforeUnmount } from ' vue'
3
3
import { isString } from ' @vueuse/core'
4
- import type { Ref } from ' vue'
5
- import type { UseModalOptions , UseModalOptionsPrivate } from ' ../Modal'
6
4
import { useInternalVfm , useVfm } from ' ~/useApi'
7
5
8
6
const vfm = useVfm ()
@@ -11,39 +9,6 @@ const _vfm = useInternalVfm()
11
9
const uid = Symbol (' ModalsContainer' )
12
10
const shouldMount = computed (() => uid === vfm .modalsContainers .value ?.[0 ])
13
11
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
-
47
12
vfm .modalsContainers .value .push (uid )
48
13
onBeforeUnmount (() => {
49
14
vfm .modalsContainers .value = vfm .modalsContainers .value .filter (i => i !== uid )
@@ -54,11 +19,11 @@ onBeforeUnmount(() => {
54
19
<template v-if =" shouldMount " >
55
20
<component
56
21
:is =" modal.component"
57
- v-for =" (modal, index) in openedDynamicModals "
22
+ v-for =" (modal, index) in vfm.dynamicModals "
58
23
:key =" modal.id"
59
24
v-bind =" modal.attrs"
60
25
v-model =" modal.modelValue"
61
- @closed =" () => withSyncOpenDynamicModals(() => _vfm.resolvedClosed?.(index) )"
26
+ @closed =" () => _vfm.resolvedClosed?.(index)"
62
27
@opened =" () => _vfm.resolvedOpened?.(index)"
63
28
>
64
29
<template v-for =" (slot , key ) in modal .slots " #[key ] :key =" key " >
0 commit comments