1+ import type { Component } from 'vue'
12import { computed , markRaw , nextTick , reactive , useAttrs } from 'vue'
23import { tryOnUnmounted } from '@vueuse/core'
34import VueFinalModal from './components/VueFinalModal/VueFinalModal.vue'
4- import type { ComponentProps , ComponentType , ModalSlot , ModalSlotOptions , UseModalOptions , UseModalOptionsPrivate , UseModalReturnType , Vfm } from './Modal'
5+ import type { ModalSlotOptions , UseModalOptions , UseModalOptionsPrivate , UseModalReturnType , Vfm } from './Modal'
56import { activeVfm , getActiveVfm } from './plugin'
6- import { isString } from '~/utils'
7+ import type { ComponentProps } from './Component'
8+ import { isString , objectEntries } from '~/utils'
79
810/**
911 * Returns the vfm instance. Equivalent to using `$vfm` inside
@@ -23,24 +25,24 @@ export function useVfm(): Vfm {
2325 return vfm !
2426}
2527
26- function withMarkRaw < T extends ComponentType > ( options : Partial < UseModalOptions < T > > , DefaultComponent : ComponentType = VueFinalModal ) {
28+ function withMarkRaw < T extends Component > ( options : Partial < UseModalOptions < T > > , DefaultComponent : Component = VueFinalModal ) {
2729 const { component, slots : innerSlots , ...rest } = options
2830
29- const slots = typeof innerSlots === 'undefined'
31+ const slots : UseModalOptions < T > [ 'slots' ] = typeof innerSlots === 'undefined'
3032 ? { }
31- : Object . fromEntries < ModalSlot > ( Object . entries ( innerSlots ) . map ( ( [ name , maybeComponent ] ) => {
33+ : Object . fromEntries ( objectEntries ( innerSlots ) . map ( ( [ name , maybeComponent ] ) => {
3234 if ( isString ( maybeComponent ) )
3335 return [ name , maybeComponent ] as const
3436
35- if ( 'component' in maybeComponent ) {
37+ if ( isModalSlotOptions ( maybeComponent ) ) {
3638 return [ name , {
3739 ...maybeComponent ,
3840 component : markRaw ( maybeComponent . component ) ,
3941 } ]
4042 }
4143
42- return [ name , markRaw ( maybeComponent ) ]
43- } ) )
44+ return [ name , markRaw ( maybeComponent as Component ) ]
45+ } ) ) as UseModalOptions < T > [ 'slots' ]
4446
4547 return {
4648 ...rest ,
@@ -52,7 +54,7 @@ function withMarkRaw<T extends ComponentType>(options: Partial<UseModalOptions<T
5254/**
5355 * Create a dynamic modal.
5456 */
55- export function useModal < T extends ComponentType = typeof VueFinalModal > ( _options : UseModalOptions < T > ) : UseModalReturnType < T > {
57+ export function useModal < T extends Component = typeof VueFinalModal > ( _options : UseModalOptions < T > ) : UseModalReturnType < T > {
5658 const options = reactive ( {
5759 id : Symbol ( __DEV__ ? 'useModal' : '' ) ,
5860 modelValue : ! ! _options ?. defaultModelValue ,
@@ -124,7 +126,7 @@ export function useModal<T extends ComponentType = typeof VueFinalModal>(_option
124126
125127 // patch options.slots
126128 if ( slots ) {
127- Object . entries ( slots ) . forEach ( ( [ name , slot ] ) => {
129+ objectEntries ( slots ) . forEach ( ( [ name , slot ] ) => {
128130 const originSlot = options . slots ! [ name ]
129131 if ( isString ( originSlot ) )
130132 options . slots ! [ name ] = slot
@@ -136,7 +138,7 @@ export function useModal<T extends ComponentType = typeof VueFinalModal>(_option
136138 }
137139 }
138140
139- function patchComponentOptions < T extends ComponentType > (
141+ function patchComponentOptions < T extends Component > (
140142 options : UseModalOptions < T > | ModalSlotOptions ,
141143 newOptions : Partial < UseModalOptions < T > > | ModalSlotOptions ,
142144 ) {
@@ -171,15 +173,18 @@ export function useModal<T extends ComponentType = typeof VueFinalModal>(_option
171173 }
172174}
173175
174- export function useModalSlot < T extends ComponentType > ( options : {
176+ export function useModalSlot < T extends Component > ( options : {
175177 component : T
176178 attrs ?: ComponentProps < T >
177179} ) {
178180 return options
179181}
180182
181- function isModalSlotOptions ( value : any ) : value is ModalSlotOptions {
182- return 'component' in value || 'attrs' in value
183+ export function isModalSlotOptions ( value : unknown ) : value is ModalSlotOptions {
184+ if ( typeof value === 'object' && value !== null )
185+ return 'component' in value
186+ else
187+ return false
183188}
184189
185190export function pickModalProps ( props : any , modalProps : any ) {
0 commit comments