diff --git a/packages/openscd/src/addons/Layout.ts b/packages/openscd/src/addons/Layout.ts index 1a8db74e9..68055f25f 100644 --- a/packages/openscd/src/addons/Layout.ts +++ b/packages/openscd/src/addons/Layout.ts @@ -63,6 +63,7 @@ export class OscdLayout extends LitElement {
this.pluginDownloadUI.show()} @oscd-activate-editor=${this.handleActivateEditorByEvent} + @oscd-run-menu=${this.handleRunMenuByEvent} > ${this.renderHeader()} ${this.renderAside()} ${this.renderContent()} @@ -331,9 +332,6 @@ export class OscdLayout extends LitElement { icon: plugin.icon || pluginIcons['menu'], name: plugin.name, action: ae => { - const targetMenuElement = (ae.target).items[ae.detail.index]; - const nextElement = targetMenuElement.nextElementSibling; - this.dispatchEvent( newPendingStateEvent( (( @@ -347,7 +345,7 @@ export class OscdLayout extends LitElement { disabled: (): boolean => plugin.requireDoc! && this.doc === null, content: () => { if(plugin.content){ return plugin.content(); } - return nothing + return html``; }, kind: kind, } @@ -390,6 +388,7 @@ export class OscdLayout extends LitElement { class="${me.kind}" iconid="${me.icon}" graphic="icon" + data-name="${me.name}" .disabled=${me.disabled?.() || !me.action} >${me.icon} ${get(me.name)} @@ -534,6 +533,17 @@ export class OscdLayout extends LitElement { this.activeTab = index; } + private handleRunMenuByEvent(e: CustomEvent<{name: string}>): void { + + // TODO: this is a workaround, fix it + this.menuUI.open = true; + const menuEntry = this.menuUI.querySelector(`[data-name="${e.detail.name}"]`) as HTMLElement + const menuElement = menuEntry.nextElementSibling + if(!menuElement){ return; } // TODO: log error + + (menuElement as unknown as MenuPlugin).run() + } + /** * Renders the landing buttons (open project and new project) * it no document loaded we display the menu item that are in the position