UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 1.31 kB
import*as UI from"../../ui/legacy/legacy.js";import*as i18n from"../../core/i18n/i18n.js";const UIStrings={genericMenuLabel:"Menu"},str_=i18n.i18n.registerUIStrings("panels/issues/ComboBoxOfCheckBoxes.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class ComboBoxOfCheckBoxes extends UI.Toolbar.ToolbarButton{#e=new Array;#t=new Array;#n=()=>{};constructor(e){super(e),this.turnIntoSelect(),this.addEventListener(UI.Toolbar.ToolbarButton.Events.Click,this.#i.bind(this)),UI.ARIAUtils.markAsMenuButton(this.element)}addOption(e,t,n){this.#e.push({title:e,value:t,default:n,enabled:n})}setOptionEnabled(e,t){const n=this.#e[e];n&&(n.enabled=t,this.#n())}addHeader(e,t){this.#t.push({title:e,callback:t})}setOnOptionClicked(e){this.#n=e}getOptions(){return this.#e}async#i({data:e}){const t=new UI.ContextMenu.ContextMenu(e,{useSoftMenu:!0,x:this.element.getBoundingClientRect().left,y:this.element.getBoundingClientRect().top+this.element.offsetHeight});for(const{title:e,callback:n}of this.#t)t.headerSection().appendItem(e,(()=>n()));for(const[e,{title:n,enabled:i}]of this.#e.entries())t.defaultSection().appendCheckboxItem(n,(()=>{this.setOptionEnabled(e,!i)}),i);t.setContextMenuLabel(this.title??i18nString(UIStrings.genericMenuLabel)),await t.show(),t.markAsMenuItemCheckBox()}}