@@ -77,7 +77,9 @@ export function useModal<P = InstanceType<typeof VueFinalModal>['$props']>(_opti
77
77
if ( options . modelValue === true )
78
78
options . context ?. dynamicModals . push ( options )
79
79
80
- function open ( ) : Promise < string > {
80
+ function open ( opt ?: { context : Vfm } ) : Promise < string > {
81
+ if ( opt ?. context )
82
+ options . context = opt . context
81
83
if ( ! options ?. context )
82
84
return Promise . resolve ( '[Vue Final Modal] options.context is not exist.' )
83
85
if ( options . modelValue )
@@ -106,9 +108,16 @@ export function useModal<P = InstanceType<typeof VueFinalModal>['$props']>(_opti
106
108
} )
107
109
}
108
110
109
- function patchOptions ( _options : Partial < Omit < UseModalOptions < P > , 'defaultModelValue' | 'context' > > ) {
111
+ function patchOptions ( _options : Partial < UseModalOptions < P > > ) {
110
112
const { slots, ...rest } = withMarkRaw ( _options , options . component )
111
113
114
+ if ( _options . defaultModelValue !== undefined )
115
+ options . defaultModelValue = _options . defaultModelValue
116
+ if ( _options . keepAlive !== undefined )
117
+ options . keepAlive = _options . keepAlive
118
+ if ( _options . context )
119
+ options . context = _options . context
120
+
112
121
// patch options.component and options.attrs
113
122
patchComponentOptions ( options , rest )
114
123
@@ -126,6 +135,25 @@ export function useModal<P = InstanceType<typeof VueFinalModal>['$props']>(_opti
126
135
}
127
136
}
128
137
138
+ function patchComponentOptions < P > (
139
+ options : UseModalOptions < P > | ModalSlotOptions ,
140
+ newOptions : Partial < UseModalOptions < P > > | ModalSlotOptions ,
141
+ ) {
142
+ if ( newOptions . component )
143
+ options . component = newOptions . component
144
+
145
+ if ( newOptions . attrs )
146
+ patchAttrs ( options . attrs ! , newOptions . attrs )
147
+ }
148
+
149
+ function patchAttrs < T extends Record < string , any > > ( attrs : T , newAttrs : Partial < T > ) : T {
150
+ Object . entries ( newAttrs ) . forEach ( ( [ key , value ] ) => {
151
+ attrs [ key as keyof T ] = value
152
+ } )
153
+
154
+ return attrs
155
+ }
156
+
129
157
function destroy ( ) : void {
130
158
if ( ! options . context )
131
159
return
@@ -150,25 +178,6 @@ export function useModalSlot<P>(options: {
150
178
return options
151
179
}
152
180
153
- function patchAttrs < T extends Record < string , any > > ( attrs : T , newAttrs : Partial < T > ) : T {
154
- Object . entries ( newAttrs ) . forEach ( ( [ key , value ] ) => {
155
- attrs [ key as keyof T ] = value
156
- } )
157
-
158
- return attrs
159
- }
160
-
161
- function patchComponentOptions < P > (
162
- options : Omit < UseModalOptions < P > , 'defaultModelValue' | 'context' > | ModalSlotOptions ,
163
- newOptions : Partial < Omit < UseModalOptions < P > , 'defaultModelValue' | 'context' > > | ModalSlotOptions ,
164
- ) {
165
- if ( newOptions . component )
166
- options . component = newOptions . component
167
-
168
- if ( newOptions . attrs )
169
- patchAttrs ( options . attrs ! , newOptions . attrs )
170
- }
171
-
172
181
function isModalSlotOptions ( value : any ) : value is ModalSlotOptions {
173
182
return 'component' in value || 'attrs' in value
174
183
}
0 commit comments