1
1
import { isString , tryOnUnmounted } from '@vueuse/core'
2
2
import { computed , inject , markRaw , reactive , useAttrs } from 'vue'
3
+ import VueFinalModal from './components/VueFinalModal/VueFinalModal.vue'
3
4
import type CoreModal from './components/CoreModal/CoreModal.vue'
4
5
import { internalVfmSymbol , vfmSymbol } from './injectionSymbols'
5
6
import type { ComponentProps , InternalVfm , ModalSlot , UseModalOptions , UseModalOptionsPrivate , UseModalReturnType , Vfm } from './Modal'
@@ -26,7 +27,7 @@ function withMarkRaw<
26
27
const { component, slots : innerSlots , ...rest } = options
27
28
28
29
const slots = typeof innerSlots === 'undefined'
29
- ? undefined
30
+ ? { }
30
31
: Object . fromEntries < ModalSlot > ( Object . entries ( innerSlots ) . map ( ( [ name , maybeComponent ] ) => {
31
32
if ( isString ( maybeComponent ) )
32
33
return [ name , maybeComponent ] as const
@@ -43,7 +44,7 @@ function withMarkRaw<
43
44
44
45
return {
45
46
...rest ,
46
- component : markRaw ( component ) ,
47
+ component : markRaw ( component || VueFinalModal ) ,
47
48
slots,
48
49
}
49
50
}
@@ -58,6 +59,7 @@ function defineModal<
58
59
const options = reactive ( {
59
60
id : Symbol ( 'useModal' ) ,
60
61
modelValue : ! ! _options ?. defaultModelValue ,
62
+ attrs : { } ,
61
63
...withMarkRaw ( _options ) ,
62
64
} ) as UseModalOptionsPrivate < ModalProps , DefaultSlotProps >
63
65
@@ -84,10 +86,14 @@ function defineModal<
84
86
} )
85
87
}
86
88
87
- function patchOptions ( _options : UseModalOptions < ModalProps , DefaultSlotProps > ) {
88
- Object . assign ( options ?. attrs || { } , _options ?. attrs || { } )
89
- Object . assign ( options ?. component || { } , _options ?. component || { } )
90
- Object . assign ( options ?. slots || { } , _options ?. slots || { } )
89
+ function patchOptions ( _options : Partial < UseModalOptions < ModalProps , DefaultSlotProps > > ) {
90
+ const _patchOptions = withMarkRaw ( _options )
91
+ if ( _patchOptions ?. attrs )
92
+ Object . assign ( options . attrs || { } , _patchOptions . attrs )
93
+ if ( _patchOptions ?. component )
94
+ Object . assign ( options . component || { } , _patchOptions . component )
95
+ if ( _patchOptions ?. slots )
96
+ Object . assign ( options . slots || { } , _patchOptions . slots )
91
97
}
92
98
93
99
function destroy ( ) : void {
0 commit comments