UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 4.26 kB
import nodeConnectionsPanelStyles from"./nodeConnectionsPanel.css.js";import*as Host from"../../core/host/host.js";import*as i18n from"../../core/i18n/i18n.js";import*as UI from"../../ui/legacy/legacy.js";const UIStrings={nodejsDebuggingGuide:"Node.js debugging guide",specifyNetworkEndpointAnd:"Specify network endpoint and DevTools will connect to it automatically. Read {PH1} to learn more.",noConnectionsSpecified:"No connections specified",addConnection:"Add connection",networkAddressEgLocalhost:"Network address (e.g. localhost:9229)"},str_=i18n.i18n.registerUIStrings("entrypoints/node_app/NodeConnectionsPanel.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);let nodeConnectionsPanelInstance;export class NodeConnectionsPanel extends UI.Panel.Panel{#e;#t;constructor(){super("node-connection"),this.contentElement.classList.add("node-panel");const e=this.contentElement.createChild("div","node-panel-center");e.createChild("img","node-panel-logo").src="https://nodejs.org/static/images/logos/nodejs-new-pantone-black.svg",Host.InspectorFrontendHost.InspectorFrontendHostInstance.events.addEventListener(Host.InspectorFrontendHostAPI.Events.DevicesDiscoveryConfigChanged,this.#n,this),this.contentElement.tabIndex=0,this.setDefaultFocusedElement(this.contentElement),Host.InspectorFrontendHost.InspectorFrontendHostInstance.setDevicesUpdatesEnabled(!1),Host.InspectorFrontendHost.InspectorFrontendHostInstance.setDevicesUpdatesEnabled(!0),this.#t=new NodeConnectionsView((e=>{this.#e.networkDiscoveryConfig=e,Host.InspectorFrontendHost.InspectorFrontendHostInstance.setDevicesDiscoveryConfig(this.#e)})),this.#t.show(e)}static instance(e={forceNew:null}){const{forceNew:t}=e;return nodeConnectionsPanelInstance&&!t||(nodeConnectionsPanelInstance=new NodeConnectionsPanel),nodeConnectionsPanelInstance}#n({data:e}){this.#e=e,this.#t.discoveryConfigChanged(this.#e.networkDiscoveryConfig)}wasShown(){super.wasShown(),this.registerCSSFiles([nodeConnectionsPanelStyles])}}export class NodeConnectionsView extends UI.Widget.VBox{#s;#o;#i;#r;constructor(e){super(),this.#s=e,this.element.classList.add("network-discovery-view");const t=this.element.createChild("div","network-discovery-footer"),n=UI.XLink.XLink.create("https://nodejs.org/en/docs/inspector/",i18nString(UIStrings.nodejsDebuggingGuide));t.appendChild(i18n.i18n.getFormatLocalizedString(str_,UIStrings.specifyNetworkEndpointAnd,{PH1:n})),this.#o=new UI.ListWidget.ListWidget(this),this.#o.element.classList.add("network-discovery-list");const s=document.createElement("div");s.classList.add("network-discovery-list-empty"),s.textContent=i18nString(UIStrings.noConnectionsSpecified),this.#o.setEmptyPlaceholder(s),this.#o.show(this.element),this.#i=null;const o=UI.UIUtils.createTextButton(i18nString(UIStrings.addConnection),this.#d.bind(this),"add-network-target-button",!0);this.element.appendChild(o),this.#r=[],this.element.classList.add("node-frontend")}#c(){const e=this.#r.map((e=>e.address));this.#s.call(null,e)}#d(){this.#o.addNewItem(this.#r.length,{address:"",port:""})}discoveryConfigChanged(e){this.#r=[],this.#o.clear();for(const t of e){const e={address:t,port:""};this.#r.push(e),this.#o.appendItem(e,!0)}}renderItem(e,t){const n=document.createElement("div");return n.classList.add("network-discovery-list-item"),n.createChild("div","network-discovery-value network-discovery-address").textContent=e.address,n}removeItemRequested(e,t){this.#r.splice(t,1),this.#o.removeItem(t),this.#c()}commitEdit(e,t,n){e.address=t.control("address").value.trim(),n&&this.#r.push(e),this.#c()}beginEdit(e){const t=this.#a();return t.control("address").value=e.address,t}#a(){if(this.#i)return this.#i;const e=new UI.ListWidget.Editor;this.#i=e;const t=e.contentElement().createChild("div","network-discovery-edit-row"),n=e.createInput("address","text",i18nString(UIStrings.networkAddressEgLocalhost),(function(e,t,n){const s=n.value.trim().match(/^([a-zA-Z0-9\.\-_]+):(\d+)$/);if(!s)return{valid:!1,errorMessage:void 0};return{valid:parseInt(s[2],10)<=65535,errorMessage:void 0}}));return t.createChild("div","network-discovery-value network-discovery-address").appendChild(n),e}wasShown(){super.wasShown(),this.#o.registerCSSFiles([nodeConnectionsPanelStyles])}}