@@ -44,7 +44,7 @@ import { OscdPluginManager } from '@openscd/open-scd/src/addons/plugin-manager/p
44
44
import '@openscd/open-scd/src/addons/plugin-manager/plugin-manager' ;
45
45
import { OscdCustomPluginDialog } from '@openscd/open-scd/src/addons/plugin-manager/custom-plugin-dialog' ;
46
46
import '@openscd/open-scd/src/addons/plugin-manager/custom-plugin-dialog' ;
47
- import { nothing } from 'lit ' ;
47
+ import { pluginTag } from '../plugin-tag.js ' ;
48
48
49
49
// TODO: What happens with this?
50
50
export function compasOpenMenuEvent ( ) : CustomEvent < void > {
@@ -77,6 +77,7 @@ export class CompasLayout extends LitElement {
77
77
@state ( ) shouldValidate = false ;
78
78
79
79
@query ( '#menu' ) menuUI ! : Drawer ;
80
+ @query ( '#menuContent' ) menuContent ! : List ;
80
81
@query ( '#pluginManager' ) pluginUI ! : OscdPluginManager ;
81
82
@query ( '#pluginList' ) pluginList ! : List ;
82
83
@query ( '#pluginAdd' ) pluginDownloadUI ! : OscdCustomPluginDialog ;
@@ -89,8 +90,8 @@ export class CompasLayout extends LitElement {
89
90
@oscd-run-menu = ${ this . handleRunMenuByEvent }
90
91
>
91
92
<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 ( ) }
94
95
</ div>
95
96
` ;
96
97
}
@@ -99,6 +100,11 @@ export class CompasLayout extends LitElement {
99
100
return html ` ${ this . renderPluginUI ( ) } ${ this . renderDownloadUI ( ) } ` ;
100
101
}
101
102
103
+ private getMenuContent ( src : string ) {
104
+ const tag = pluginTag ( src ) ;
105
+ return this . menuContent . querySelector ( tag ) ;
106
+ }
107
+
102
108
/** Renders the "Add Custom Plug-in" UI*/
103
109
protected renderDownloadUI ( ) : TemplateResult {
104
110
return html `
@@ -271,8 +277,17 @@ export class CompasLayout extends LitElement {
271
277
this . menuUI
272
278
. querySelector ( 'mwc-list' ) !
273
279
. 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
+ }
276
291
)
277
292
) . then ( ) ;
278
293
this . dispatchEvent ( newPendingStateEvent ( this . validated ) ) ;
@@ -293,16 +308,14 @@ export class CompasLayout extends LitElement {
293
308
return {
294
309
icon : plugin . icon || pluginIcons [ 'menu' ] ,
295
310
name : plugin . name ,
311
+ src : plugin . src ,
296
312
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 ( ) ) )
306
319
} ,
307
320
disabled : ( ) : boolean => plugin . requireDoc ! && this . doc === null ,
308
321
content : ( ) => {
@@ -319,18 +332,16 @@ export class CompasLayout extends LitElement {
319
332
return {
320
333
icon : plugin . icon || pluginIcons [ 'validator' ] ,
321
334
name : plugin . name ,
335
+ src : plugin . src ,
322
336
action : ae => {
323
337
this . dispatchEvent ( newEmptyIssuesEvent ( plugin . src ) ) ;
324
338
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 ( ) ) )
334
345
} ,
335
346
disabled : ( ) : boolean => this . doc === null ,
336
347
content : plugin . content ?? ( ( ) => html `` ) ,
@@ -347,21 +358,30 @@ export class CompasLayout extends LitElement {
347
358
const hasActionItem = me !== 'divider' && me . actionItem ;
348
359
349
360
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
+ */
351
371
return html `
352
372
<mwc- lis t- item
353
373
class= "${ me . kind } "
354
374
iconid = "${ me . icon } "
355
375
graphic= "icon"
356
376
data- name= "${ me . name } "
377
+ data- src= "${ me . src ?? '' } "
357
378
.disabled = ${ me . disabled ?.( ) || ! me . action }
358
379
> <mwc- icon slot= "graphic" > ${ me . icon } </ mwc- icon>
359
380
<span> ${ get ( me . name ) } </ span>
360
381
${ me . hint
361
382
? html `<span slot= "secondary" > <tt> ${ me . hint } </ tt> </ span> `
362
383
: '' }
363
384
</ mwc- lis t- item>
364
- ${ me . content ? me . content ( ) : nothing }
365
385
` ;
366
386
}
367
387
@@ -406,6 +426,18 @@ export class CompasLayout extends LitElement {
406
426
</ mwc- to p- app- bar- fixed> ` ;
407
427
}
408
428
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
+
409
441
/**
410
442
* Renders a drawer toolbar featuring the scl filename, enabled menu plugins,
411
443
* settings, help, scl history and plug-ins management
@@ -505,14 +537,16 @@ export class CompasLayout extends LitElement {
505
537
}
506
538
507
539
private handleRunMenuByEvent ( e : CustomEvent < { name : string } > ) : void {
508
-
509
540
// TODO: this is a workaround, fix it
510
541
this . menuUI . open = true ;
511
542
const menuEntry = this . menuUI . querySelector ( `[data-name="${ e . detail . name } "]` ) as HTMLElement
512
- const menuElement = menuEntry . nextElementSibling
513
- if ( ! menuElement ) { return ; } // TODO: log error
514
543
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 ( )
516
550
}
517
551
518
552
/**
0 commit comments