@@ -52,7 +52,7 @@ import '@material/mwc-dialog';
52
52
import '@material/mwc-switch' ;
53
53
import '@material/mwc-select' ;
54
54
import '@material/mwc-textfield' ;
55
- import { nothing } from 'lit ' ;
55
+ import { pluginTag } from '../plugin-tag.js ' ;
56
56
57
57
import { OscdPluginManager } from "./plugin-manager/plugin-manager.js" ;
58
58
import "./plugin-manager/plugin-manager.js" ;
@@ -85,6 +85,7 @@ export class OscdLayout extends LitElement {
85
85
@state ( ) activeEditor : Plugin | undefined = this . calcActiveEditors ( ) [ 0 ] ;
86
86
87
87
@query ( '#menu' ) menuUI ! : Drawer ;
88
+ @query ( '#menuContent' ) menuContent ! : List ;
88
89
@query ( '#pluginManager' ) pluginUI ! : OscdPluginManager ;
89
90
@query ( '#pluginList' ) pluginList ! : List ;
90
91
@query ( '#pluginAdd' ) pluginDownloadUI ! : OscdCustomPluginDialog ;
@@ -98,8 +99,8 @@ export class OscdLayout extends LitElement {
98
99
@oscd-run-menu = ${ this . handleRunMenuByEvent }
99
100
>
100
101
<slot> </ slot>
101
- ${ this . renderHeader ( ) } ${ this . renderAside ( ) } ${ this . renderContent ( ) }
102
- ${ this . renderLanding ( ) } ${ this . renderPlugging ( ) }
102
+ ${ this . renderHeader ( ) } ${ this . renderAside ( ) } ${ this . renderMenuContent ( ) }
103
+ ${ this . renderContent ( ) } ${ this . renderLanding ( ) } ${ this . renderPlugging ( ) }
103
104
</ div>
104
105
` ;
105
106
}
@@ -109,6 +110,11 @@ export class OscdLayout extends LitElement {
109
110
return html ` ${ this . renderPluginUI ( ) } ${ this . renderDownloadUI ( ) } ` ;
110
111
}
111
112
113
+ private getMenuContent ( src : string ) {
114
+ const tag = pluginTag ( src ) ;
115
+ return this . menuContent . querySelector ( tag ) ;
116
+ }
117
+
112
118
/** Renders the "Add Custom Plug-in" UI*/
113
119
protected renderDownloadUI ( ) : TemplateResult {
114
120
return html `
@@ -280,9 +286,16 @@ export class OscdLayout extends LitElement {
280
286
this . menuUI
281
287
. querySelector ( 'mwc-list' ) !
282
288
. items . filter ( item => item . className === 'validator' )
283
- . map ( item =>
284
- ( < Validator > ( < unknown > item . nextElementSibling ) ) . validate ( )
285
- )
289
+ . map ( item => {
290
+ const src = item . dataset . src ?? '' ;
291
+ const menuContentElement = this . getMenuContent ( src ) ;
292
+
293
+ if ( ! menuContentElement ) {
294
+ return ;
295
+ }
296
+
297
+ return ( menuContentElement as unknown as Validator ) . validate ( )
298
+ } )
286
299
) . then ( ) ;
287
300
this . dispatchEvent ( newPendingStateEvent ( this . validated ) ) ;
288
301
} ) ;
@@ -300,16 +313,14 @@ export class OscdLayout extends LitElement {
300
313
return {
301
314
icon : plugin . icon || pluginIcons [ 'menu' ] ,
302
315
name : plugin . name ,
316
+ src : plugin . src ,
303
317
action : ae => {
304
- this . dispatchEvent (
305
- newPendingStateEvent (
306
- ( < MenuPlugin > (
307
- ( < unknown > (
308
- ( < List > ae . target ) . items [ ae . detail . index ] . nextElementSibling
309
- ) )
310
- ) ) . run ( )
311
- )
312
- ) ;
318
+ const menuContentElement = this . getMenuContent ( plugin . src ) ;
319
+ if ( ! menuContentElement ) {
320
+ return ;
321
+ }
322
+
323
+ this . dispatchEvent ( newPendingStateEvent ( ( menuContentElement as unknown as MenuPlugin ) . run ( ) ) )
313
324
} ,
314
325
disabled : ( ) : boolean => plugin . requireDoc ! && this . doc === null ,
315
326
content : ( ) => {
@@ -326,18 +337,16 @@ export class OscdLayout extends LitElement {
326
337
return {
327
338
icon : plugin . icon || pluginIcons [ 'validator' ] ,
328
339
name : plugin . name ,
340
+ src : plugin . src ,
329
341
action : ae => {
330
342
this . dispatchEvent ( newEmptyIssuesEvent ( plugin . src ) ) ;
331
343
332
- this . dispatchEvent (
333
- newPendingStateEvent (
334
- ( < Validator > (
335
- ( < unknown > (
336
- ( < List > ae . target ) . items [ ae . detail . index ] . nextElementSibling
337
- ) )
338
- ) ) . validate ( )
339
- )
340
- ) ;
344
+ const menuContentElement = this . getMenuContent ( plugin . src ) ;
345
+ if ( ! menuContentElement ) {
346
+ return ;
347
+ }
348
+
349
+ this . dispatchEvent ( newPendingStateEvent ( ( menuContentElement as unknown as Validator ) . validate ( ) ) )
341
350
} ,
342
351
disabled : ( ) : boolean => this . doc === null ,
343
352
content : plugin . content ?? ( ( ) => html `` ) ,
@@ -358,14 +367,14 @@ export class OscdLayout extends LitElement {
358
367
iconid = "${ me . icon } "
359
368
graphic= "icon"
360
369
data- name= "${ me . name } "
370
+ data- src= "${ me . src ?? '' } "
361
371
.disabled = ${ me . disabled ?.( ) || ! me . action }
362
372
> <mwc- icon slot= "graphic" > ${ me . icon } </ mwc- icon>
363
373
<span> ${ get ( me . name ) } </ span>
364
374
${ me . hint
365
375
? html `<span slot= "secondary" > <tt> ${ me . hint } </ tt> </ span> `
366
376
: '' }
367
377
</ mwc- lis t- item>
368
- ${ me . content ? me . content ( ) : nothing }
369
378
` ;
370
379
}
371
380
@@ -400,6 +409,18 @@ export class OscdLayout extends LitElement {
400
409
</ mwc- to p- app- bar- fixed> ` ;
401
410
}
402
411
412
+ protected renderMenuContent ( ) : TemplateResult {
413
+ return html `
414
+ <div id= "menuContent" >
415
+ ${
416
+ this . menu
417
+ . filter ( p => ( p as MenuItem ) . content )
418
+ . map ( p => ( p as MenuItem ) . content ( ) )
419
+ }
420
+ </ div>
421
+ ` ;
422
+ }
423
+
403
424
/**
404
425
* Renders a drawer toolbar featuring the scl filename, enabled menu plugins,
405
426
* settings, help, scl history and plug-ins management
@@ -502,10 +523,13 @@ export class OscdLayout extends LitElement {
502
523
// TODO: this is a workaround, fix it
503
524
this . menuUI . open = true ;
504
525
const menuEntry = this . menuUI . querySelector ( `[data-name="${ e . detail . name } "]` ) as HTMLElement
505
- const menuElement = menuEntry . nextElementSibling
506
- if ( ! menuElement ) { return ; } // TODO: log error
507
526
508
- ( menuElement as unknown as MenuPlugin ) . run ( )
527
+ const menuContentElement = this . getMenuContent ( menuEntry . dataset . src ?? '' ) ;
528
+ if ( ! menuContentElement ) {
529
+ return ;
530
+ }
531
+
532
+ ( menuContentElement as unknown as MenuPlugin ) . run ( ) ;
509
533
}
510
534
511
535
/**
0 commit comments