11import { isString , tryOnUnmounted } from '@vueuse/core'
22import { computed , getCurrentInstance , inject , markRaw , reactive , useAttrs } from 'vue'
3- import type { Component , Raw } from 'vue'
3+ import type { Component } from 'vue'
44import VueFinalModal from './components/VueFinalModal/VueFinalModal.vue'
55import type CoreModal from './components/CoreModal/CoreModal.vue'
66import { internalVfmSymbol , vfmSymbol } from './injectionSymbols'
77
8- import type { ComponentProps , IOverloadedUseModalFn , InternalVfm , ModalSlot , ModalSlotOptions , UseModalOptions , UseModalOptionsPrivate , UseModalReturnType , Vfm } from './Modal'
8+ import type { ComponentProps , Constructor , InternalVfm , ModalSlot , ModalSlotOptions , RawProps , UseModalOptions , UseModalOptionsPrivate , UseModalReturnType , Vfm } from './Modal'
99
1010/**
1111 * Returns the vfm instance. Equivalent to using `$vfm` inside
@@ -22,7 +22,7 @@ export function useInternalVfm(): InternalVfm {
2222 return inject ( internalVfmSymbol ) !
2323}
2424
25- function withMarkRaw ( options : Partial < UseModalOptions > , DefaultComponent : Component = VueFinalModal ) {
25+ function withMarkRaw < P > ( options : Partial < UseModalOptions < P > > , DefaultComponent : Component = VueFinalModal ) {
2626 const { component, slots : innerSlots , ...rest } = options
2727
2828 const slots = typeof innerSlots === 'undefined'
@@ -43,23 +43,23 @@ function withMarkRaw(options: Partial<UseModalOptions>, DefaultComponent: Compon
4343
4444 return {
4545 ...rest ,
46- component : markRaw ( component || DefaultComponent ) ,
46+ component : markRaw ( component || DefaultComponent ) as Constructor < P > ,
4747 slots,
4848 }
4949}
5050
5151/**
5252 * Create a dynamic modal.
5353 */
54- export const useModal : IOverloadedUseModalFn = function ( _options : UseModalOptions ) : UseModalReturnType {
54+ export function useModal < P = InstanceType < typeof VueFinalModal > [ '$props' ] > ( _options : UseModalOptions < P > ) : UseModalReturnType < P > {
5555 const options = reactive ( {
5656 id : Symbol ( 'useModal' ) ,
5757 modelValue : ! ! _options ?. defaultModelValue ,
58- resolveOpened : ( ) => { } ,
59- resolveClosed : ( ) => { } ,
58+ resolveOpened : ( ) => { } ,
59+ resolveClosed : ( ) => { } ,
6060 attrs : { } ,
61- ...withMarkRaw ( _options ) ,
62- } ) as UseModalOptions & UseModalOptionsPrivate
61+ ...withMarkRaw < P > ( _options ) ,
62+ } ) as UseModalOptions < P > & UseModalOptionsPrivate
6363
6464 if ( ! options . context ) {
6565 const currentInstance = getCurrentInstance ( )
@@ -89,7 +89,7 @@ export const useModal: IOverloadedUseModalFn = function (_options: UseModalOptio
8989 } )
9090 }
9191
92- function patchOptions ( _options : Partial < UseModalOptions > ) {
92+ function patchOptions ( _options : Partial < Omit < UseModalOptions < P > , 'defaultModelValue' | 'context' > > ) {
9393 const { slots, ...rest } = withMarkRaw ( _options , options . component )
9494
9595 // patch options.component and options.attrs
@@ -132,6 +132,13 @@ export const useModal: IOverloadedUseModalFn = function (_options: UseModalOptio
132132 return modal
133133}
134134
135+ export function useModalSlot < P > ( options : {
136+ component : Constructor < P >
137+ attrs ?: ( RawProps & P ) | ( { } extends P ? null : never )
138+ } ) {
139+ return options
140+ }
141+
135142function patchAttrs < T extends Record < string , any > > ( attrs : T , newAttrs : Partial < T > ) : T {
136143 Object . entries ( newAttrs ) . forEach ( ( [ key , value ] ) => {
137144 attrs [ key as keyof T ] = value
@@ -140,12 +147,10 @@ function patchAttrs<T extends Record<string, any>>(attrs: T, newAttrs: Partial<T
140147 return attrs
141148}
142149
143- type ComponentOptions = {
144- component ?: Raw < Component >
145- attrs ?: Record < string , any >
146- }
147-
148- function patchComponentOptions ( options : ComponentOptions | ModalSlotOptions , newOptions : ComponentOptions | ModalSlotOptions ) {
150+ function patchComponentOptions < P > (
151+ options : Omit < UseModalOptions < P > , 'defaultModelValue' | 'context' > | ModalSlotOptions ,
152+ newOptions : Partial < Omit < UseModalOptions < P > , 'defaultModelValue' | 'context' > > | ModalSlotOptions ,
153+ ) {
149154 if ( newOptions . component )
150155 options . component = newOptions . component
151156
0 commit comments