@@ -39,7 +39,7 @@ export { type IPlugin };
39
39
* UI applications with the ability to be safely extended by third
40
40
* party code via plugins.
41
41
*/
42
- export class Application < T extends Widget = Widget > {
42
+ export class Application < T extends Widget | HTMLElement = Widget > {
43
43
/**
44
44
* Construct a new application.
45
45
*
@@ -57,6 +57,7 @@ export class Application<T extends Widget = Widget> {
57
57
renderer : options . contextMenuRenderer
58
58
} ) ;
59
59
this . shell = options . shell ;
60
+ this . _hasShellWidget = this . shell instanceof Widget ;
60
61
}
61
62
62
63
/**
@@ -196,7 +197,7 @@ export class Application<T extends Widget = Widget> {
196
197
* If the plugin provides a service which has already been provided
197
198
* by another plugin, the new service will override the old service.
198
199
*/
199
- registerPlugin ( plugin : IPlugin < this , any > ) : void {
200
+ registerPlugin ( plugin : IPlugin < Application < Widget | HTMLElement > , any > ) : void {
200
201
this . pluginRegistry . registerPlugin ( plugin ) ;
201
202
}
202
203
@@ -208,7 +209,7 @@ export class Application<T extends Widget = Widget> {
208
209
* #### Notes
209
210
* This calls `registerPlugin()` for each of the given plugins.
210
211
*/
211
- registerPlugins ( plugins : IPlugin < this , any > [ ] ) : void {
212
+ registerPlugins ( plugins : IPlugin < Application < Widget | HTMLElement > , any > [ ] ) : void {
212
213
this . pluginRegistry . registerPlugins ( plugins ) ;
213
214
}
214
215
@@ -339,10 +340,16 @@ export class Application<T extends Widget = Widget> {
339
340
* A subclass may reimplement this method as needed.
340
341
*/
341
342
protected attachShell ( id : string ) : void {
343
+ if ( this . _hasShellWidget ) {
342
344
Widget . attach (
343
- this . shell ,
345
+ this . shell as Widget ,
344
346
( id && document . getElementById ( id ) ) || document . body
345
- ) ;
347
+ ) ; } else {
348
+ const host = ( id && document . getElementById ( id ) ) || document . body ;
349
+ if ( ! host . contains ( this . shell as HTMLElement ) ) {
350
+ host . appendChild ( this . shell as HTMLElement )
351
+ }
352
+ }
346
353
}
347
354
348
355
/**
@@ -419,7 +426,7 @@ export class Application<T extends Widget = Widget> {
419
426
* A subclass may reimplement this method as needed.
420
427
*/
421
428
protected evtResize ( event : Event ) : void {
422
- this . shell . update ( ) ;
429
+ if ( this . _hasShellWidget ) { ( this . shell as Widget ) . update ( ) }
423
430
}
424
431
425
432
/**
@@ -429,6 +436,7 @@ export class Application<T extends Widget = Widget> {
429
436
private _delegate = new PromiseDelegate < void > ( ) ;
430
437
private _started = false ;
431
438
private _bubblingKeydown = false ;
439
+ private _hasShellWidget = true ;
432
440
}
433
441
434
442
/**
@@ -438,13 +446,12 @@ export namespace Application {
438
446
/**
439
447
* An options object for creating an application.
440
448
*/
441
- export interface IOptions < T extends Widget > extends PluginRegistry . IOptions {
449
+ export interface IOptions < T extends Widget | HTMLElement > extends PluginRegistry . IOptions {
442
450
/**
443
- * The shell widget to use for the application.
444
- *
445
- * This should be a newly created and initialized widget.
451
+ * The shell element to use for the application.
446
452
*
447
- * The application will attach the widget to the DOM.
453
+ * If it is a {@link Widget}, this should be a newly created and initialized widget.
454
+ * and the application will attach the widget to the DOM.
448
455
*/
449
456
shell : T ;
450
457
0 commit comments