@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 2.52 kB
JavaScript
import*as Common from"../../core/common/common.js";import*as i18n from"../../core/i18n/i18n.js";import*as UI from"../../ui/legacy/legacy.js";const UIStrings={reports:"Reports",newReport:"(new report)"},str_=i18n.i18n.registerUIStrings("panels/lighthouse/LighthouseReportSelector.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class ReportSelector{renderNewLighthouseView;newLighthouseItem;comboBoxInternal;itemByOptionElement;constructor(e){this.renderNewLighthouseView=e,this.newLighthouseItem=document.createElement("option"),this.comboBoxInternal=new UI.Toolbar.ToolbarComboBox(this.handleChange.bind(this),i18nString(UIStrings.reports),"lighthouse-report"),this.comboBoxInternal.setMaxWidth(180),this.comboBoxInternal.setMinWidth(140),this.itemByOptionElement=new Map,this.setEmptyState()}setEmptyState(){this.comboBoxInternal.selectElement().removeChildren(),this.comboBoxInternal.setEnabled(!1),this.newLighthouseItem=document.createElement("option"),this.newLighthouseItem.label=i18nString(UIStrings.newReport),this.comboBoxInternal.selectElement().appendChild(this.newLighthouseItem),this.comboBoxInternal.select(this.newLighthouseItem)}handleChange(e){const t=this.selectedItem();t?t.select():this.renderNewLighthouseView()}selectedItem(){const e=this.comboBoxInternal.selectedOption();return this.itemByOptionElement.get(e)}hasCurrentSelection(){return Boolean(this.selectedItem())}hasItems(){return this.itemByOptionElement.size>0}comboBox(){return this.comboBoxInternal}prepend(e){const t=e.optionElement(),n=this.comboBoxInternal.selectElement();this.itemByOptionElement.set(t,e),n.insertBefore(t,n.firstElementChild),this.comboBoxInternal.setEnabled(!0),this.comboBoxInternal.select(t),e.select()}clearAll(){for(const e of this.comboBoxInternal.options())e!==this.newLighthouseItem&&(this.itemByOptionElement.get(e)?.delete(),this.itemByOptionElement.delete(e));this.setEmptyState()}selectNewReport(){this.comboBoxInternal.select(this.newLighthouseItem)}}export class Item{lighthouseResult;renderReport;showLandingCallback;element;constructor(e,t,n){this.lighthouseResult=e,this.renderReport=t,this.showLandingCallback=n;const o=e.finalDisplayedUrl||e.finalUrl||"",i=new Common.ParsedURL.ParsedURL(o),s=e.fetchTime;this.element=document.createElement("option"),this.element.label=`${new Date(s).toLocaleTimeString()} - ${i.domain()}`}select(){this.renderReport()}optionElement(){return this.element}delete(){this.element&&this.element.remove(),this.showLandingCallback()}}