11import { tryOnUnmounted } from '@vueuse/core'
2- import type { Component } from 'vue'
32import { computed , inject , markRaw , reactive , useAttrs } from 'vue'
43import type CoreModal from './components/CoreModal/CoreModal.vue'
54import { 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'
76import { isString } from './utils'
87
98/**
@@ -21,47 +20,46 @@ export function useInternalVfm(): InternalVfm {
2120 return inject ( internalVfmSymbol ) !
2221}
2322
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+
2452/**
2553 * Define a dynamic modal.
2654 */
2755function defineModal <
2856 ModalProps extends ComponentProps ,
2957 DefaultSlotProps extends ComponentProps = { } ,
3058 > ( _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-
5959 const options = reactive ( {
6060 id : Symbol ( 'useModal' ) ,
6161 modelValue : false ,
62- component : markRaw ( component ) ,
63- slots,
64- ...rest ,
62+ ...withMarkRaw ( _options ) ,
6563 } ) as UseModalOptionsPrivate < ModalProps , DefaultSlotProps >
6664
6765 if ( ! options . context )
0 commit comments