1
1
import { tryOnUnmounted } from '@vueuse/core'
2
- import type { Component } from 'vue'
3
2
import { computed , inject , markRaw , reactive , useAttrs } from 'vue'
4
3
import type CoreModal from './components/CoreModal/CoreModal.vue'
5
4
import { internalVfmSymbol , vfmSymbol } from './injectionSymbols'
6
- import type { ComponentProps , InternalVfm , UseModalOptions , UseModalOptionsPrivate , UseModalReturnType , Vfm } from './Modal'
5
+ import type { ComponentProps , InternalVfm , ModalSlot , UseModalOptions , UseModalOptionsPrivate , UseModalReturnType , Vfm } from './Modal'
7
6
import { isString } from './utils'
8
7
9
8
/**
@@ -21,47 +20,46 @@ export function useInternalVfm(): InternalVfm {
21
20
return inject ( internalVfmSymbol ) !
22
21
}
23
22
23
+ function withMarkRaw <
24
+ ModalProps extends ComponentProps ,
25
+ DefaultSlotProps extends ComponentProps = { } ,
26
+ > ( options : UseModalOptions < ModalProps , DefaultSlotProps > ) {
27
+ const { component, slots : innerSlots , ...rest } = options
28
+
29
+ const slots = typeof innerSlots === 'undefined'
30
+ ? undefined
31
+ : Object . fromEntries < ModalSlot > ( Object . entries ( innerSlots ) . map ( ( [ name , maybeComponent ] ) => {
32
+ if ( isString ( maybeComponent ) )
33
+ return [ name , maybeComponent ] as const
34
+
35
+ if ( 'component' in maybeComponent ) {
36
+ return [ name , {
37
+ ...maybeComponent ,
38
+ component : markRaw ( maybeComponent . component ) ,
39
+ } ]
40
+ }
41
+
42
+ return [ name , markRaw ( maybeComponent ) ]
43
+ } ) )
44
+
45
+ return {
46
+ ...rest ,
47
+ component : markRaw ( component ) ,
48
+ slots,
49
+ }
50
+ }
51
+
24
52
/**
25
53
* Define a dynamic modal.
26
54
*/
27
55
function defineModal <
28
56
ModalProps extends ComponentProps ,
29
57
DefaultSlotProps extends ComponentProps = { } ,
30
58
> ( _options : UseModalOptions < ModalProps , DefaultSlotProps > ) : UseModalReturnType < ModalProps , DefaultSlotProps > {
31
- const { component, slots : innerSlots , ...rest } = _options
32
-
33
- const slots = typeof innerSlots !== 'undefined'
34
- ? Object . fromEntries < string | {
35
- component : Component
36
- attrs ?: any
37
- } > (
38
- Object . entries ( innerSlots ) . map ( ( [ name , maybeComponent ] ) => {
39
- if ( isString ( maybeComponent ) )
40
- return [ name , maybeComponent ]
41
-
42
- if ( 'component' in maybeComponent ) {
43
- return [ name , {
44
- component : markRaw ( maybeComponent . component ) ,
45
- attrs : maybeComponent . attrs ,
46
- } ] as const
47
- }
48
-
49
- return [
50
- name ,
51
- {
52
- component : markRaw ( maybeComponent ) ,
53
- } ,
54
- ] as const
55
- } ) ,
56
- )
57
- : undefined
58
-
59
59
const options = reactive ( {
60
60
id : Symbol ( 'useModal' ) ,
61
61
modelValue : false ,
62
- component : markRaw ( component ) ,
63
- slots,
64
- ...rest ,
62
+ ...withMarkRaw ( _options ) ,
65
63
} ) as UseModalOptionsPrivate < ModalProps , DefaultSlotProps >
66
64
67
65
if ( ! options . context )
0 commit comments