@@ -44,7 +44,7 @@ import { OscdPluginManager } from '@openscd/open-scd/src/addons/plugin-manager/p
4444import '@openscd/open-scd/src/addons/plugin-manager/plugin-manager' ;
4545import { OscdCustomPluginDialog } from '@openscd/open-scd/src/addons/plugin-manager/custom-plugin-dialog' ;
4646import '@openscd/open-scd/src/addons/plugin-manager/custom-plugin-dialog' ;
47- import { nothing } from 'lit ' ;
47+ import { pluginTag } from '../plugin-tag.js ' ;
4848
4949// TODO: What happens with this?
5050export function compasOpenMenuEvent ( ) : CustomEvent < void > {
@@ -77,6 +77,7 @@ export class CompasLayout extends LitElement {
7777 @state ( ) shouldValidate = false ;
7878
7979 @query ( '#menu' ) menuUI ! : Drawer ;
80+ @query ( '#menuContent' ) menuContent ! : List ;
8081 @query ( '#pluginManager' ) pluginUI ! : OscdPluginManager ;
8182 @query ( '#pluginList' ) pluginList ! : List ;
8283 @query ( '#pluginAdd' ) pluginDownloadUI ! : OscdCustomPluginDialog ;
@@ -89,8 +90,8 @@ export class CompasLayout extends LitElement {
8990 @oscd-run-menu = ${ this . handleRunMenuByEvent }
9091 >
9192 <slot> </ slot>
92- ${ this . renderHeader ( ) } ${ this . renderAside ( ) } ${ this . renderContent ( ) }
93- ${ this . renderLanding ( ) } ${ this . renderPlugging ( ) }
93+ ${ this . renderHeader ( ) } ${ this . renderAside ( ) } ${ this . renderMenuContent ( ) }
94+ ${ this . renderContent ( ) } ${ this . renderLanding ( ) } ${ this . renderPlugging ( ) }
9495 </ div>
9596 ` ;
9697 }
@@ -99,6 +100,11 @@ export class CompasLayout extends LitElement {
99100 return html ` ${ this . renderPluginUI ( ) } ${ this . renderDownloadUI ( ) } ` ;
100101 }
101102
103+ private getMenuContent ( src : string ) {
104+ const tag = pluginTag ( src ) ;
105+ return this . menuContent . querySelector ( tag ) ;
106+ }
107+
102108 /** Renders the "Add Custom Plug-in" UI*/
103109 protected renderDownloadUI ( ) : TemplateResult {
104110 return html `
@@ -271,8 +277,17 @@ export class CompasLayout extends LitElement {
271277 this . menuUI
272278 . querySelector ( 'mwc-list' ) !
273279 . items . filter ( item => item . className === 'validator' )
274- . map ( item =>
275- ( < Validator > ( < unknown > item . nextElementSibling ) ) . validate ( )
280+ . map ( item => {
281+ const src = item . dataset . src ?? '' ;
282+
283+ const menuContentElement = this . getMenuContent ( src ) ;
284+
285+ if ( ! menuContentElement ) {
286+ return ;
287+ }
288+
289+ return ( menuContentElement as unknown as Validator ) . validate ( )
290+ }
276291 )
277292 ) . then ( ) ;
278293 this . dispatchEvent ( newPendingStateEvent ( this . validated ) ) ;
@@ -293,16 +308,14 @@ export class CompasLayout extends LitElement {
293308 return {
294309 icon : plugin . icon || pluginIcons [ 'menu' ] ,
295310 name : plugin . name ,
311+ src : plugin . src ,
296312 action : ae => {
297- this . dispatchEvent (
298- newPendingStateEvent (
299- ( < MenuPlugin > (
300- ( < unknown > (
301- ( < List > ae . target ) . items [ ae . detail . index ] . nextElementSibling
302- ) )
303- ) ) . run ( )
304- )
305- ) ;
313+ const menuContentElement = this . getMenuContent ( plugin . src ) ;
314+ if ( ! menuContentElement ) {
315+ return ;
316+ }
317+
318+ this . dispatchEvent ( newPendingStateEvent ( ( menuContentElement as unknown as MenuPlugin ) . run ( ) ) )
306319 } ,
307320 disabled : ( ) : boolean => plugin . requireDoc ! && this . doc === null ,
308321 content : ( ) => {
@@ -319,18 +332,16 @@ export class CompasLayout extends LitElement {
319332 return {
320333 icon : plugin . icon || pluginIcons [ 'validator' ] ,
321334 name : plugin . name ,
335+ src : plugin . src ,
322336 action : ae => {
323337 this . dispatchEvent ( newEmptyIssuesEvent ( plugin . src ) ) ;
324338
325- this . dispatchEvent (
326- newPendingStateEvent (
327- ( < Validator > (
328- ( < unknown > (
329- ( < List > ae . target ) . items [ ae . detail . index ] . nextElementSibling
330- ) )
331- ) ) . validate ( )
332- )
333- ) ;
339+ const menuContentElement = this . getMenuContent ( plugin . src ) ;
340+ if ( ! menuContentElement ) {
341+ return ;
342+ }
343+
344+ this . dispatchEvent ( newPendingStateEvent ( ( menuContentElement as unknown as Validator ) . validate ( ) ) )
334345 } ,
335346 disabled : ( ) : boolean => this . doc === null ,
336347 content : plugin . content ?? ( ( ) => html `` ) ,
@@ -347,21 +358,30 @@ export class CompasLayout extends LitElement {
347358 const hasActionItem = me !== 'divider' && me . actionItem ;
348359
349360 if ( isDivider ( me ) ) { return html `<li divider padded role= "separator" > </ li> ` ; }
350- if ( hasActionItem ) { return html `` ; }
361+ if ( hasActionItem ) {
362+ return html `` ;
363+ }
364+
365+ /*
366+ if (me.kind === 'validator') {
367+ console.log('rendering validator with data')
368+ console.log(me)
369+ }
370+ */
351371 return html `
352372 <mwc- lis t- item
353373 class= "${ me . kind } "
354374 iconid = "${ me . icon } "
355375 graphic= "icon"
356376 data- name= "${ me . name } "
377+ data- src= "${ me . src ?? '' } "
357378 .disabled = ${ me . disabled ?.( ) || ! me . action }
358379 > <mwc- icon slot= "graphic" > ${ me . icon } </ mwc- icon>
359380 <span> ${ get ( me . name ) } </ span>
360381 ${ me . hint
361382 ? html `<span slot= "secondary" > <tt> ${ me . hint } </ tt> </ span> `
362383 : '' }
363384 </ mwc- lis t- item>
364- ${ me . content ? me . content ( ) : nothing }
365385 ` ;
366386 }
367387
@@ -406,6 +426,18 @@ export class CompasLayout extends LitElement {
406426 </ mwc- to p- app- bar- fixed> ` ;
407427 }
408428
429+ protected renderMenuContent ( ) : TemplateResult {
430+ return html `
431+ <div id= "menuContent" >
432+ ${
433+ this . menu
434+ . filter ( p => ( p as MenuItem ) . content )
435+ . map ( p => ( p as MenuItem ) . content ( ) )
436+ }
437+ </ div>
438+ ` ;
439+ }
440+
409441 /**
410442 * Renders a drawer toolbar featuring the scl filename, enabled menu plugins,
411443 * settings, help, scl history and plug-ins management
@@ -505,14 +537,16 @@ export class CompasLayout extends LitElement {
505537 }
506538
507539 private handleRunMenuByEvent ( e : CustomEvent < { name : string } > ) : void {
508-
509540 // TODO: this is a workaround, fix it
510541 this . menuUI . open = true ;
511542 const menuEntry = this . menuUI . querySelector ( `[data-name="${ e . detail . name } "]` ) as HTMLElement
512- const menuElement = menuEntry . nextElementSibling
513- if ( ! menuElement ) { return ; } // TODO: log error
514543
515- ( menuElement as unknown as MenuPlugin ) . run ( )
544+ const menuContentElement = this . getMenuContent ( menuEntry . dataset . src ?? '' ) ;
545+ if ( ! menuContentElement ) {
546+ return ;
547+ }
548+
549+ ( menuContentElement as unknown as MenuPlugin ) . run ( )
516550 }
517551
518552 /**
0 commit comments