import type { IMenuPanel } from '../IMenuPanel' ; import { ComputedMenuItemModel , IComputedMenuItemOptions } from '../models/ComputedMenuItemModel' ; import { ComputedMenuPanelModel } from '../models/ComputedMenuPanelModel' ; import { MenuOptionsStore } from '../models/MenuOptionsStore' ; /**
 * this class allows to store IComputedMenuItemOptions in a tree structure
 * and create IMenuPanel from this tree
 */ export class StaticMenu { private menuStore = new MenuOptionsStore < IComputedMenuItemOptions > ( ) ; private menuModels = new Map < string , IMenuPanel > ( ) ; addRootPanel ( panelId ) { this . menuStore . addRootPanel ( panelId ) ; } addMenuItem ( panelId , params ) { this . menuStore . addMenuItem ( panelId , params ) ; } getMenu ( panelId ) { if ( ! this . menuModels . has ( panelId ) ) { const menuModel = this . constructMenuPanel ( panelId ) ; this . menuModels . set ( panelId , menuModel ) ; } return this . menuModels . get ( panelId ) ! ; } private constructMenuPanel ( panelId ) { return new ComputedMenuPanelModel ( { id : `${ panelId }-panel` , menuItemsGetter : ( ) => this . constructMenuItems ( panelId ) , } ) ; } private constructMenuItems ( panelId ) { const panel = this . menuStore . getPanel ( panelId ) ; return panel . menuItems . values . map ( item => this . constructMenuItem ( item ) ) ; } private constructMenuItem ( options ) { const model = new ComputedMenuItemModel ( options ) ; if ( options . isPanel ) { model . panel = this . constructMenuPanel ( options . id ) ; } return model ; } }