@@ -142,7 +142,7 @@ export type WizardInput =
142
142
| Select
143
143
| WizardSelect ;
144
144
145
- export type WizardAction = EditorAction | ( ( ) => Wizard ) ;
145
+ export type WizardAction = EditorAction | WizardFactory ;
146
146
147
147
/** @returns [[`EditorAction`]]s to dispatch on [[`WizardDialog`]] commit. */
148
148
export type WizardActor = (
@@ -151,10 +151,10 @@ export type WizardActor = (
151
151
list ?: List | null
152
152
) => WizardAction [ ] ;
153
153
154
- export function isWizard (
155
- wizardAction : WizardAction
156
- ) : wizardAction is ( ) => Wizard {
157
- return typeof wizardAction === 'function' ;
154
+ export function isWizardFactory (
155
+ maybeFactory : WizardAction | Wizard | null
156
+ ) : maybeFactory is WizardFactory {
157
+ return typeof maybeFactory === 'function' ;
158
158
}
159
159
160
160
/** @returns the validity of `input` depending on type. */
@@ -203,17 +203,30 @@ export interface WizardPage {
203
203
element ?: Element ;
204
204
}
205
205
export type Wizard = WizardPage [ ] ;
206
+ export type WizardFactory = ( ) => Wizard ;
206
207
207
208
/** If `wizard === null`, close the current wizard, else queue `wizard`. */
208
209
export interface WizardDetail {
209
- wizard : Wizard | null ;
210
+ wizard : WizardFactory | null ;
210
211
subwizard ?: boolean ;
211
212
}
212
213
export type WizardEvent = CustomEvent < WizardDetail > ;
213
214
export function newWizardEvent (
214
- wizard : Wizard | null = null ,
215
+ wizardOrFactory ? : Wizard | WizardFactory ,
215
216
eventInitDict ?: CustomEventInit < Partial < WizardDetail > >
216
217
) : WizardEvent {
218
+ if ( ! wizardOrFactory )
219
+ return new CustomEvent < WizardDetail > ( 'wizard' , {
220
+ bubbles : true ,
221
+ composed : true ,
222
+ ...eventInitDict ,
223
+ detail : { wizard : null , ...eventInitDict ?. detail } ,
224
+ } ) ;
225
+
226
+ const wizard = isWizardFactory ( wizardOrFactory )
227
+ ? wizardOrFactory
228
+ : ( ) => wizardOrFactory ;
229
+
217
230
return new CustomEvent < WizardDetail > ( 'wizard' , {
218
231
bubbles : true ,
219
232
composed : true ,
0 commit comments