UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 33.1 kB
import*as Common from"../../core/common/common.js";import*as Host from"../../core/host/host.js";import*as i18n from"../../core/i18n/i18n.js";import*as Platform from"../../core/platform/platform.js";import*as Root from"../../core/root/root.js";import*as SDK from"../../core/sdk/sdk.js";import*as Bindings from"../../models/bindings/bindings.js";import*as Breakpoints from"../../models/breakpoints/breakpoints.js";import*as Extensions from"../../models/extensions/extensions.js";import*as Workspace from"../../models/workspace/workspace.js";import*as IconButton from"../../ui/components/icon_button/icon_button.js";import*as ObjectUI from"../../ui/legacy/components/object_ui/object_ui.js";import*as UI from"../../ui/legacy/legacy.js";import*as Snippets from"../snippets/snippets.js";import{CallStackSidebarPane}from"./CallStackSidebarPane.js";import{DebuggerPausedMessage}from"./DebuggerPausedMessage.js";import sourcesPanelStyles from"./sourcesPanel.css.js";import{ContentScriptsNavigatorView,FilesNavigatorView,NetworkNavigatorView,OverridesNavigatorView,SnippetsNavigatorView}from"./SourcesNavigator.js";import{Events,SourcesView}from"./SourcesView.js";import{ThreadsSidebarPane}from"./ThreadsSidebarPane.js";import{UISourceCodeFrame}from"./UISourceCodeFrame.js";const UIStrings={dropWorkspaceFolderHere:"Drop workspace folder here",moreOptions:"More options",showNavigator:"Show navigator",hideNavigator:"Hide navigator",navigatorShown:"Navigator sidebar shown",navigatorHidden:"Navigator sidebar hidden",debuggerShown:"Debugger sidebar shown",debuggerHidden:"Debugger sidebar hidden",showDebugger:"Show debugger",hideDebugger:"Hide debugger",groupByFolder:"Group by folder",groupByAuthored:"Group by Authored/Deployed",hideIgnoreListed:"Hide ignore-listed sources",resumeWithAllPausesBlockedForMs:"Resume with all pauses blocked for 500 ms",terminateCurrentJavascriptCall:"Terminate current JavaScript call",pauseOnCaughtExceptions:"Pause on caught exceptions",revealInSidebar:"Reveal in sidebar",continueToHere:"Continue to here",storeSAsGlobalVariable:"Store {PH1} as global variable",copyS:"Copy {PH1}",copyStringContents:"Copy string contents",copyStringAsJSLiteral:"Copy string as JavaScript literal",copyStringAsJSONLiteral:"Copy string as JSON literal",showFunctionDefinition:"Show function definition",openInSourcesPanel:"Open in Sources panel"},str_=i18n.i18n.registerUIStrings("panels/sources/SourcesPanel.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_),primitiveRemoteObjectTypes=new Set(["number","boolean","bigint","undefined"]);let sourcesPanelInstance,wrapperViewInstance,uILocationRevealerInstance,debuggerLocationRevealerInstance,uISourceCodeRevealerInstance,debuggerPausedDetailsRevealerInstance,revealingActionDelegateInstance,actionDelegateInstance;export class SourcesPanel extends UI.Panel.Panel{workspace;togglePauseAction;stepOverAction;stepIntoAction;stepOutAction;stepAction;toggleBreakpointsActiveAction;debugToolbar;debugToolbarDrawer;debuggerPausedMessage;splitWidget;editorView;navigatorTabbedLocation;sourcesViewInternal;toggleNavigatorSidebarButton;toggleDebuggerSidebarButton;threadsSidebarPane;watchSidebarPane;callstackPane;liveLocationPool;lastModificationTime;pausedInternal;switchToPausedTargetTimeout;ignoreExecutionLineEvents;executionLineLocation;pauseOnExceptionButton;sidebarPaneStack;tabbedLocationHeader;extensionSidebarPanesContainer;sidebarPaneView;constructor(){super("sources"),new UI.DropTarget.DropTarget(this.element,[UI.DropTarget.Type.Folder],i18nString(UIStrings.dropWorkspaceFolderHere),this.handleDrop.bind(this)),this.workspace=Workspace.Workspace.WorkspaceImpl.instance(),this.togglePauseAction=UI.ActionRegistry.ActionRegistry.instance().action("debugger.toggle-pause"),this.stepOverAction=UI.ActionRegistry.ActionRegistry.instance().action("debugger.step-over"),this.stepIntoAction=UI.ActionRegistry.ActionRegistry.instance().action("debugger.step-into"),this.stepOutAction=UI.ActionRegistry.ActionRegistry.instance().action("debugger.step-out"),this.stepAction=UI.ActionRegistry.ActionRegistry.instance().action("debugger.step"),this.toggleBreakpointsActiveAction=UI.ActionRegistry.ActionRegistry.instance().action("debugger.toggle-breakpoints-active"),this.debugToolbar=this.createDebugToolbar(),this.debugToolbarDrawer=this.createDebugToolbarDrawer(),this.debuggerPausedMessage=new DebuggerPausedMessage;this.splitWidget=new UI.SplitWidget.SplitWidget(!0,!0,"sourcesPanelSplitViewState",225),this.splitWidget.enableShowModeSaving(),this.splitWidget.show(this.element);this.editorView=new UI.SplitWidget.SplitWidget(!0,!1,"sourcesPanelNavigatorSplitViewState",225),this.editorView.enableShowModeSaving(),this.splitWidget.setMainWidget(this.editorView),this.navigatorTabbedLocation=UI.ViewManager.ViewManager.instance().createTabbedLocation(this.revealNavigatorSidebar.bind(this),"navigator-view",!0,!0);const e=this.navigatorTabbedLocation.tabbedPane();e.setMinimumSize(100,25),e.element.classList.add("navigator-tabbed-pane");const t=new UI.Toolbar.ToolbarMenuButton(this.populateNavigatorMenu.bind(this),!0);if(t.setTitle(i18nString(UIStrings.moreOptions)),e.rightToolbar().appendToolbarItem(t),e.addEventListener(UI.TabbedPane.Events.TabSelected,(({data:{tabId:e}})=>Host.userMetrics.sourcesSidebarTabShown(e))),UI.ViewManager.ViewManager.instance().hasViewsForLocation("run-view-sidebar")){const t=new UI.SplitWidget.SplitWidget(!1,!0,"sourcePanelNavigatorSidebarSplitViewState");t.setMainWidget(e);const i=UI.ViewManager.ViewManager.instance().createTabbedLocation(this.revealNavigatorSidebar.bind(this),"run-view-sidebar").tabbedPane();t.setSidebarWidget(i),t.installResizer(i.headerElement()),this.editorView.setSidebarWidget(t)}else this.editorView.setSidebarWidget(e);this.sourcesViewInternal=new SourcesView,this.sourcesViewInternal.addEventListener(Events.EditorSelected,this.editorSelected.bind(this)),this.toggleNavigatorSidebarButton=this.editorView.createShowHideSidebarButton(i18nString(UIStrings.showNavigator),i18nString(UIStrings.hideNavigator),i18nString(UIStrings.navigatorShown),i18nString(UIStrings.navigatorHidden)),this.toggleDebuggerSidebarButton=this.splitWidget.createShowHideSidebarButton(i18nString(UIStrings.showDebugger),i18nString(UIStrings.hideDebugger),i18nString(UIStrings.debuggerShown),i18nString(UIStrings.debuggerHidden)),this.editorView.setMainWidget(this.sourcesViewInternal),this.threadsSidebarPane=null,this.watchSidebarPane=UI.ViewManager.ViewManager.instance().view("sources.watch"),this.callstackPane=CallStackSidebarPane.instance(),Common.Settings.Settings.instance().moduleSetting("sidebarPosition").addChangeListener(this.updateSidebarPosition.bind(this)),this.updateSidebarPosition(),this.updateDebuggerButtonsAndStatus(),this.liveLocationPool=new Bindings.LiveLocation.LiveLocationPool,this.setTarget(UI.Context.Context.instance().flavor(SDK.Target.Target)),Common.Settings.Settings.instance().moduleSetting("breakpointsActive").addChangeListener(this.breakpointsActiveStateChanged,this),UI.Context.Context.instance().addFlavorChangeListener(SDK.Target.Target,this.onCurrentTargetChanged,this),UI.Context.Context.instance().addFlavorChangeListener(SDK.DebuggerModel.CallFrame,this.callFrameChanged,this),SDK.TargetManager.TargetManager.instance().addModelListener(SDK.DebuggerModel.DebuggerModel,SDK.DebuggerModel.Events.DebuggerWasEnabled,this.debuggerWasEnabled,this),SDK.TargetManager.TargetManager.instance().addModelListener(SDK.DebuggerModel.DebuggerModel,SDK.DebuggerModel.Events.DebuggerPaused,this.debuggerPaused,this),SDK.TargetManager.TargetManager.instance().addModelListener(SDK.DebuggerModel.DebuggerModel,SDK.DebuggerModel.Events.DebugInfoAttached,this.debugInfoAttached,this),SDK.TargetManager.TargetManager.instance().addModelListener(SDK.DebuggerModel.DebuggerModel,SDK.DebuggerModel.Events.DebuggerResumed,(e=>this.debuggerResumed(e.data))),SDK.TargetManager.TargetManager.instance().addModelListener(SDK.DebuggerModel.DebuggerModel,SDK.DebuggerModel.Events.GlobalObjectCleared,(e=>this.debuggerResumed(e.data))),Extensions.ExtensionServer.ExtensionServer.instance().addEventListener(Extensions.ExtensionServer.Events.SidebarPaneAdded,this.extensionSidebarPaneAdded,this),SDK.TargetManager.TargetManager.instance().observeTargets(this),this.lastModificationTime=-1/0}static instance(e={forceNew:null}){const{forceNew:t}=e;return sourcesPanelInstance&&!t||(sourcesPanelInstance=new SourcesPanel),sourcesPanelInstance}static updateResizerAndSidebarButtons(e){e.sourcesViewInternal.leftToolbar().removeToolbarItems(),e.sourcesViewInternal.rightToolbar().removeToolbarItems(),e.sourcesViewInternal.bottomToolbar().removeToolbarItems();const t=WrapperView.isShowing()&&!UI.InspectorView.InspectorView.instance().isDrawerMinimized();e.splitWidget.isVertical()||t?e.splitWidget.uninstallResizer(e.sourcesViewInternal.toolbarContainerElement()):e.splitWidget.installResizer(e.sourcesViewInternal.toolbarContainerElement()),t||(e.sourcesViewInternal.leftToolbar().appendToolbarItem(e.toggleNavigatorSidebarButton),e.splitWidget.isVertical()?e.sourcesViewInternal.rightToolbar().appendToolbarItem(e.toggleDebuggerSidebarButton):e.sourcesViewInternal.bottomToolbar().appendToolbarItem(e.toggleDebuggerSidebarButton))}targetAdded(e){this.showThreadsIfNeeded()}targetRemoved(e){}showThreadsIfNeeded(){ThreadsSidebarPane.shouldBeShown()&&!this.threadsSidebarPane&&(this.threadsSidebarPane=UI.ViewManager.ViewManager.instance().view("sources.threads"),this.sidebarPaneStack&&this.threadsSidebarPane&&this.sidebarPaneStack.appendView(this.threadsSidebarPane,this.splitWidget.isVertical()?this.watchSidebarPane:this.callstackPane))}setTarget(e){if(!e)return;const t=e.model(SDK.DebuggerModel.DebuggerModel);t&&(t.isPaused()?this.showDebuggerPausedDetails(t.debuggerPausedDetails()):(this.pausedInternal=!1,this.clearInterface(),this.toggleDebuggerSidebarButton.setEnabled(!0)))}onCurrentTargetChanged({data:e}){this.setTarget(e)}paused(){return this.pausedInternal||!1}wasShown(){UI.Context.Context.instance().setFlavor(SourcesPanel,this),this.registerCSSFiles([sourcesPanelStyles]),super.wasShown();const e=WrapperView.instance();e&&e.isShowing()&&(UI.InspectorView.InspectorView.instance().setDrawerMinimized(!0),SourcesPanel.updateResizerAndSidebarButtons(this)),this.editorView.setMainWidget(this.sourcesViewInternal)}willHide(){super.willHide(),UI.Context.Context.instance().setFlavor(SourcesPanel,null),WrapperView.isShowing()&&(WrapperView.instance().showViewInWrapper(),UI.InspectorView.InspectorView.instance().setDrawerMinimized(!1),SourcesPanel.updateResizerAndSidebarButtons(this))}resolveLocation(e){return"sources.sidebar-top"===e||"sources.sidebar-bottom"===e||"sources.sidebar-tabs"===e?this.sidebarPaneStack||null:this.navigatorTabbedLocation}ensureSourcesViewVisible(){return!!WrapperView.isShowing()||!!UI.InspectorView.InspectorView.instance().canSelectPanel("sources")&&(UI.ViewManager.ViewManager.instance().showView("sources"),!0)}onResize(){"auto"===Common.Settings.Settings.instance().moduleSetting("sidebarPosition").get()&&this.element.window().requestAnimationFrame(this.updateSidebarPosition.bind(this))}searchableView(){return this.sourcesViewInternal.searchableView()}toggleNavigatorSidebar(){this.editorView.toggleSidebar()}toggleDebuggerSidebar(){this.splitWidget.toggleSidebar()}debuggerPaused(e){const t=e.data,i=t.debuggerPausedDetails();!this.pausedInternal&&Common.Settings.Settings.instance().moduleSetting("autoFocusOnDebuggerPausedEnabled").get()&&this.setAsCurrentPanel(),UI.Context.Context.instance().flavor(SDK.Target.Target)===t.target()?this.showDebuggerPausedDetails(i):this.pausedInternal||UI.Context.Context.instance().setFlavor(SDK.Target.Target,t.target())}debugInfoAttached(e){const{debuggerModel:t}=e.data;if(!t.isPaused())return;const i=t.debuggerPausedDetails();i&&UI.Context.Context.instance().flavor(SDK.Target.Target)===t.target()&&this.showDebuggerPausedDetails(i)}showDebuggerPausedDetails(e){this.pausedInternal=!0,this.updateDebuggerButtonsAndStatus(),UI.Context.Context.instance().setFlavor(SDK.DebuggerModel.DebuggerPausedDetails,e),this.toggleDebuggerSidebarButton.setEnabled(!1),this.revealDebuggerSidebar(),window.focus(),Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront()}debuggerResumed(e){const t=e.target();UI.Context.Context.instance().flavor(SDK.Target.Target)===t&&(this.pausedInternal=!1,this.clearInterface(),this.toggleDebuggerSidebarButton.setEnabled(!0),this.switchToPausedTargetTimeout=window.setTimeout(this.switchToPausedTarget.bind(this,e),500))}debuggerWasEnabled(e){const t=e.data;UI.Context.Context.instance().flavor(SDK.Target.Target)===t.target()&&this.updateDebuggerButtonsAndStatus()}get visibleView(){return this.sourcesViewInternal.visibleView()}showUISourceCode(e,t,i,n){if(n){const e=WrapperView.isShowing();if(!this.isShowing()&&!e)return}else this.showEditor();this.sourcesViewInternal.showSourceLocation(e,void 0===t?void 0:{lineNumber:t,columnNumber:i},n)}showEditor(){WrapperView.isShowing()||this.setAsCurrentPanel()}showUILocation(e,t){this.showUISourceCode(e.uiSourceCode,e.lineNumber,e.columnNumber,t)}revealInNavigator(e,t){for(const i of registeredNavigatorViews){const n=i.navigatorView(),a=i.viewId;a&&n.acceptProject(e.project())&&(n.revealUISourceCode(e,!0),t?this.navigatorTabbedLocation.tabbedPane().selectTab(a):UI.ViewManager.ViewManager.instance().showView(a))}}addExperimentMenuItem(e,t,i){const n=new IconButton.Icon.Icon;n.data={iconName:"experiment",color:"var(--icon-default)",width:"16px"},n.style.minHeight="16px",n.style.minWidth="16px",e.appendCheckboxItem(i,(function(){const e=Root.Runtime.experiments.isEnabled(t);Root.Runtime.experiments.setEnabled(t,!e),Host.userMetrics.experimentChanged(t,e);const i=Common.Settings.Settings.instance().moduleSetting("navigatorGroupByFolder");i.set(i.get())}),Root.Runtime.experiments.isEnabled(t),!1,n)}populateNavigatorMenu(e){const t=Common.Settings.Settings.instance().moduleSetting("navigatorGroupByFolder");e.appendItemsAtLocation("navigatorMenu"),e.viewSection().appendCheckboxItem(i18nString(UIStrings.groupByFolder),(()=>t.set(!t.get())),t.get()),this.addExperimentMenuItem(e.viewSection(),Root.Runtime.ExperimentName.AUTHORED_DEPLOYED_GROUPING,i18nString(UIStrings.groupByAuthored)),this.addExperimentMenuItem(e.viewSection(),Root.Runtime.ExperimentName.JUST_MY_CODE,i18nString(UIStrings.hideIgnoreListed))}setIgnoreExecutionLineEvents(e){this.ignoreExecutionLineEvents=e}updateLastModificationTime(){this.lastModificationTime=window.performance.now()}async executionLineChanged(e){const t=await e.uiLocation();e.isDisposed()||t&&(window.performance.now()-this.lastModificationTime<lastModificationTimeout||this.sourcesViewInternal.showSourceLocation(t.uiSourceCode,t,void 0,!0))}lastModificationTimeoutPassedForTest(){lastModificationTimeout=Number.MIN_VALUE}updateLastModificationTimeForTest(){lastModificationTimeout=Number.MAX_VALUE}async callFrameChanged(){const e=UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame);e&&(this.executionLineLocation&&this.executionLineLocation.dispose(),this.executionLineLocation=await Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createCallFrameLiveLocation(e.location(),this.executionLineChanged.bind(this),this.liveLocationPool))}async updateDebuggerButtonsAndStatus(){const e=UI.Context.Context.instance().flavor(SDK.Target.Target),t=e?e.model(SDK.DebuggerModel.DebuggerModel):null;t?this.pausedInternal?(this.togglePauseAction.setToggled(!0),this.togglePauseAction.setEnabled(!0),this.stepOverAction.setEnabled(!0),this.stepIntoAction.setEnabled(!0),this.stepOutAction.setEnabled(!0),this.stepAction.setEnabled(!0)):(this.togglePauseAction.setToggled(!1),this.togglePauseAction.setEnabled(!t.isPausing()),this.stepOverAction.setEnabled(!1),this.stepIntoAction.setEnabled(!1),this.stepOutAction.setEnabled(!1),this.stepAction.setEnabled(!1)):(this.togglePauseAction.setEnabled(!1),this.stepOverAction.setEnabled(!1),this.stepIntoAction.setEnabled(!1),this.stepOutAction.setEnabled(!1),this.stepAction.setEnabled(!1));const i=t?t.debuggerPausedDetails():null;await this.debuggerPausedMessage.render(i,Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(),Breakpoints.BreakpointManager.BreakpointManager.instance()),i&&this.updateDebuggerButtonsAndStatusForTest()}updateDebuggerButtonsAndStatusForTest(){}clearInterface(){this.updateDebuggerButtonsAndStatus(),UI.Context.Context.instance().setFlavor(SDK.DebuggerModel.DebuggerPausedDetails,null),this.switchToPausedTargetTimeout&&clearTimeout(this.switchToPausedTargetTimeout),this.liveLocationPool.disposeAll()}switchToPausedTarget(e){if(delete this.switchToPausedTargetTimeout,!this.pausedInternal&&!e.isPaused())for(const e of SDK.TargetManager.TargetManager.instance().models(SDK.DebuggerModel.DebuggerModel))if(e.isPaused()){UI.Context.Context.instance().setFlavor(SDK.Target.Target,e.target());break}}runSnippet(){const e=this.sourcesViewInternal.currentUISourceCode();e&&Snippets.ScriptSnippetFileSystem.evaluateScriptSnippet(e)}editorSelected(e){const t=e.data;this.editorView.mainWidget()&&Common.Settings.Settings.instance().moduleSetting("autoRevealInNavigator").get()&&this.revealInNavigator(t,!0)}togglePause(){const e=UI.Context.Context.instance().flavor(SDK.Target.Target);if(!e)return!0;const t=e.model(SDK.DebuggerModel.DebuggerModel);return!t||(this.pausedInternal?(this.pausedInternal=!1,t.resume()):t.pause(),this.clearInterface(),!0)}prepareToResume(){if(!this.pausedInternal)return null;this.pausedInternal=!1,this.clearInterface();const e=UI.Context.Context.instance().flavor(SDK.Target.Target);return e?e.model(SDK.DebuggerModel.DebuggerModel):null}longResume(){const e=this.prepareToResume();e&&(e.skipAllPausesUntilReloadOrTimeout(500),e.resume())}terminateExecution(){const e=this.prepareToResume();e&&(e.runtimeModel().terminateExecution(),e.resume())}stepOver(){const e=this.prepareToResume();return e&&e.stepOver(),!0}stepInto(){const e=this.prepareToResume();return e&&e.stepInto(),!0}stepIntoAsync(){const e=this.prepareToResume();return e&&e.scheduleStepIntoAsync(),!0}stepOut(){const e=this.prepareToResume();return e&&e.stepOut(),!0}async continueToLocation(e){const t=UI.Context.Context.instance().flavor(SDK.RuntimeModel.ExecutionContext);if(!t)return;const i=(await Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().uiLocationToRawLocations(e.uiSourceCode,e.lineNumber,0)).find((e=>e.debuggerModel===t.debuggerModel));i&&this.prepareToResume()&&i.continueToLocation()}toggleBreakpointsActive(){Common.Settings.Settings.instance().moduleSetting("breakpointsActive").set(!Common.Settings.Settings.instance().moduleSetting("breakpointsActive").get())}breakpointsActiveStateChanged(){const e=Common.Settings.Settings.instance().moduleSetting("breakpointsActive").get();this.toggleBreakpointsActiveAction.setToggled(!e),this.sourcesViewInternal.toggleBreakpointsActiveState(e)}createDebugToolbar(){const e=new UI.Toolbar.Toolbar("scripts-debug-toolbar"),t=new UI.Toolbar.ToolbarButton(i18nString(UIStrings.resumeWithAllPausesBlockedForMs),"play");t.addEventListener(UI.Toolbar.ToolbarButton.Events.Click,this.longResume,this);const i=new UI.Toolbar.ToolbarButton(i18nString(UIStrings.terminateCurrentJavascriptCall),"stop");return i.addEventListener(UI.Toolbar.ToolbarButton.Events.Click,this.terminateExecution,this),e.appendToolbarItem(UI.Toolbar.Toolbar.createLongPressActionButton(this.togglePauseAction,[i,t],[])),e.appendToolbarItem(UI.Toolbar.Toolbar.createActionButton(this.stepOverAction)),e.appendToolbarItem(UI.Toolbar.Toolbar.createActionButton(this.stepIntoAction)),e.appendToolbarItem(UI.Toolbar.Toolbar.createActionButton(this.stepOutAction)),e.appendToolbarItem(UI.Toolbar.Toolbar.createActionButton(this.stepAction)),e.appendSeparator(),e.appendToolbarItem(UI.Toolbar.Toolbar.createActionButton(this.toggleBreakpointsActiveAction)),e}createDebugToolbarDrawer(){const e=document.createElement("div");e.classList.add("scripts-debug-toolbar-drawer");const t=i18nString(UIStrings.pauseOnCaughtExceptions),i=Common.Settings.Settings.instance().moduleSetting("pauseOnCaughtException");return e.appendChild(UI.SettingsUI.createSettingCheckbox(t,i,!0)),e}appendApplicableItems(e,t,i){this.appendUISourceCodeItems(e,t,i),this.appendUISourceCodeFrameItems(e,t,i),this.appendUILocationItems(t,i),this.appendRemoteObjectItems(t,i),this.appendNetworkRequestItems(t,i)}appendUISourceCodeItems(e,t,i){if(!(i instanceof Workspace.UISourceCode.UISourceCode&&e.target))return;const n=i,a=e.target;n.project().isServiceProject()||a.isSelfOrDescendant(this.navigatorTabbedLocation.widget().element)||Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.JUST_MY_CODE)&&Bindings.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(n)||t.revealSection().appendItem(i18nString(UIStrings.revealInSidebar),this.handleContextMenuReveal.bind(this,n)),n.contentType().hasScripts()&&Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().scriptsForUISourceCode(n).every((e=>e.isJavaScript()))&&this.callstackPane.appendIgnoreListURLContextMenuItems(t,n)}appendUISourceCodeFrameItems(e,t,i){i instanceof UISourceCodeFrame&&(i.uiSourceCode().contentType().isFromSourceMap()||i.textEditor.state.selection.main.empty||t.debugSection().appendAction("debugger.evaluate-selection"))}appendUILocationItems(e,t){if(!(t instanceof Workspace.UISourceCode.UILocation))return;const i=t,n=i.uiSourceCode;if(!Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().scriptsForUISourceCode(n).every((e=>e.isJavaScript())))return;if(n.contentType().hasScripts()){const t=UI.Context.Context.instance().flavor(SDK.Target.Target),a=t?t.model(SDK.DebuggerModel.DebuggerModel):null;a&&a.isPaused()&&e.debugSection().appendItem(i18nString(UIStrings.continueToHere),this.continueToLocation.bind(this,i)),this.callstackPane.appendIgnoreListURLContextMenuItems(e,n)}}handleContextMenuReveal(e){this.editorView.showBoth(),this.revealInNavigator(e)}appendRemoteObjectItems(e,t){if(!(t instanceof SDK.RemoteObject.RemoteObject))return;const i=Common.Settings.Settings.instance().moduleSetting("textEditorIndent").get(),n=t,a=UI.Context.Context.instance().flavor(SDK.RuntimeModel.ExecutionContext);const s="wasm"===n.type?n.subtype:"node"===n.subtype?"outerHTML":n.type;e.debugSection().appendItem(i18nString(UIStrings.storeSAsGlobalVariable,{PH1:String(s)}),(()=>a?.target().model(SDK.ConsoleModel.ConsoleModel)?.saveToTempVariable(a,n)));const o=e.clipboardSection(),r=Host.InspectorFrontendHost.InspectorFrontendHostInstance;if("string"===n.type)o.appendItem(i18nString(UIStrings.copyStringContents),(()=>{r.copyText(n.value)})),o.appendItem(i18nString(UIStrings.copyStringAsJSLiteral),(()=>{r.copyText(Platform.StringUtilities.formatAsJSLiteral(n.value))})),o.appendItem(i18nString(UIStrings.copyStringAsJSONLiteral),(()=>{r.copyText(JSON.stringify(n.value))}));else if(primitiveRemoteObjectTypes.has(n.type))o.appendItem(i18nString(UIStrings.copyS,{PH1:String(s)}),(()=>{r.copyText(n.description)}));else if("object"===n.type){const e=async()=>{const e=await n.callFunctionJSON(c,[{value:{subtype:n.subtype,indent:i}}]);r.copyText(e)};o.appendItem(i18nString(UIStrings.copyS,{PH1:String(s)}),e)}else"function"===n.type&&e.debugSection().appendItem(i18nString(UIStrings.showFunctionDefinition),this.showFunctionDefinition.bind(this,n));function c(e){const t=e.subtype,i=e.indent;if("map"!==t){if("set"!==t){if("node"===t)return this instanceof Element?this.outerHTML:void 0;if(t&&void 0===this)return String(t);try{return JSON.stringify(this,null,i)}catch(e){return String(this)}}else if(this instanceof Set){const e=Array.from(this.values());return`new Set(${0===e.length?"":JSON.stringify(e,null,i)})`}}else if(this instanceof Map){const e=Array.from(this.entries());return`new Map(${0===e.length?"":JSON.stringify(e,null,i)})`}}}appendNetworkRequestItems(e,t){if(!(t instanceof SDK.NetworkRequest.NetworkRequest))return;const i=t,n=this.workspace.uiSourceCodeForURL(i.url());if(!n)return;const a=i18nString(UIStrings.openInSourcesPanel),s=this.showUILocation.bind(this,n.uiLocation(0,0));e.revealSection().appendItem(a,s)}showFunctionDefinition(e){SDK.RemoteObject.RemoteFunction.objectAsFunction(e).targetFunction().then((e=>e.debuggerModel().functionDetailsPromise(e).then(this.didGetFunctionDetails.bind(this))))}async didGetFunctionDetails(e){if(!e||!e.location)return;const t=await Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().rawLocationToUILocation(e.location);t&&this.showUILocation(t)}revealNavigatorSidebar(){this.setAsCurrentPanel(),this.editorView.showBoth(!0)}revealDebuggerSidebar(){Common.Settings.Settings.instance().moduleSetting("autoFocusOnDebuggerPausedEnabled").get()&&(this.setAsCurrentPanel(),this.splitWidget.showBoth(!0))}updateSidebarPosition(){let e;const t=Common.Settings.Settings.instance().moduleSetting("sidebarPosition").get();if(e="right"!==t&&("bottom"===t||UI.InspectorView.InspectorView.instance().element.offsetWidth<680),this.sidebarPaneView&&e===!this.splitWidget.isVertical())return;if(this.sidebarPaneView&&this.sidebarPaneView.shouldHideOnDetach())return;this.sidebarPaneView&&this.sidebarPaneView.detach(),this.splitWidget.setVertical(!e),this.splitWidget.element.classList.toggle("sources-split-view-vertical",e),SourcesPanel.updateResizerAndSidebarButtons(this);const i=new UI.Widget.VBox;i.element.appendChild(this.debugToolbar.element),i.element.appendChild(this.debugToolbarDrawer),i.setMinimumAndPreferredSizes(minToolbarWidth,25,minToolbarWidth,100),this.sidebarPaneStack=UI.ViewManager.ViewManager.instance().createStackLocation(this.revealDebuggerSidebar.bind(this)),this.sidebarPaneStack.widget().element.classList.add("overflow-auto"),this.sidebarPaneStack.widget().show(i.element),this.sidebarPaneStack.widget().element.appendChild(this.debuggerPausedMessage.element()),this.sidebarPaneStack.appendApplicableItems("sources.sidebar-top"),this.threadsSidebarPane&&this.sidebarPaneStack.appendView(this.threadsSidebarPane);const n=UI.ViewManager.ViewManager.instance().view("sources.jsBreakpoints"),a=UI.ViewManager.ViewManager.instance().view("sources.scopeChain");if(this.tabbedLocationHeader&&(this.splitWidget.uninstallResizer(this.tabbedLocationHeader),this.tabbedLocationHeader=null),e){const e=new UI.SplitWidget.SplitWidget(!0,!0,"sourcesPanelDebuggerSidebarSplitViewState",.5);e.setMainWidget(i),this.sidebarPaneStack.showView(n),this.sidebarPaneStack.showView(this.callstackPane);const t=UI.ViewManager.ViewManager.instance().createTabbedLocation(this.revealDebuggerSidebar.bind(this));e.setSidebarWidget(t.tabbedPane()),this.tabbedLocationHeader=t.tabbedPane().headerElement(),this.splitWidget.installResizer(this.tabbedLocationHeader),this.splitWidget.installResizer(this.debugToolbar.gripElementForResize()),t.appendView(a),t.appendView(this.watchSidebarPane),t.appendApplicableItems("sources.sidebar-tabs"),this.extensionSidebarPanesContainer=t,this.sidebarPaneView=e}else this.sidebarPaneStack.appendView(this.watchSidebarPane),this.sidebarPaneStack.showView(n),this.sidebarPaneStack.showView(a),this.sidebarPaneStack.showView(this.callstackPane),this.extensionSidebarPanesContainer=this.sidebarPaneStack,this.sidebarPaneView=i,this.splitWidget.uninstallResizer(this.debugToolbar.gripElementForResize());this.sidebarPaneStack.appendApplicableItems("sources.sidebar-bottom");const s=Extensions.ExtensionServer.ExtensionServer.instance().sidebarPanes();for(let e=0;e<s.length;++e)this.addExtensionSidebarPane(s[e]);this.splitWidget.setSidebarWidget(this.sidebarPaneView)}setAsCurrentPanel(){return UI.ViewManager.ViewManager.instance().showView("sources")}extensionSidebarPaneAdded(e){this.addExtensionSidebarPane(e.data)}addExtensionSidebarPane(e){e.panelName()===this.name&&this.extensionSidebarPanesContainer.appendView(e)}sourcesView(){return this.sourcesViewInternal}handleDrop(e){const t=e.items;if(!t.length)return;const i=t[0].webkitGetAsEntry();i&&i.isDirectory&&Host.InspectorFrontendHost.InspectorFrontendHostInstance.upgradeDraggedFileSystemPermissions(i.filesystem)}}export let lastModificationTimeout=200;export const minToolbarWidth=215;export class UILocationRevealer{static instance(e={forceNew:null}){const{forceNew:t}=e;return uILocationRevealerInstance&&!t||(uILocationRevealerInstance=new UILocationRevealer),uILocationRevealerInstance}async reveal(e,t){if(!(e instanceof Workspace.UISourceCode.UILocation))throw new Error("Internal error: not a ui location");SourcesPanel.instance().showUILocation(e,t)}}export class DebuggerLocationRevealer{static instance(e={forceNew:null}){const{forceNew:t}=e;return debuggerLocationRevealerInstance&&!t||(debuggerLocationRevealerInstance=new DebuggerLocationRevealer),debuggerLocationRevealerInstance}async reveal(e,t){if(!(e instanceof SDK.DebuggerModel.Location))throw new Error("Internal error: not a debugger location");const i=await Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().rawLocationToUILocation(e);i&&SourcesPanel.instance().showUILocation(i,t)}}export class UISourceCodeRevealer{static instance(e={forceNew:null}){const{forceNew:t}=e;return uISourceCodeRevealerInstance&&!t||(uISourceCodeRevealerInstance=new UISourceCodeRevealer),uISourceCodeRevealerInstance}async reveal(e,t){if(!(e instanceof Workspace.UISourceCode.UISourceCode))throw new Error("Internal error: not a ui source code");SourcesPanel.instance().showUISourceCode(e,void 0,void 0,t)}}export class DebuggerPausedDetailsRevealer{static instance(e={forceNew:null}){const{forceNew:t}=e;return debuggerPausedDetailsRevealerInstance&&!t||(debuggerPausedDetailsRevealerInstance=new DebuggerPausedDetailsRevealer),debuggerPausedDetailsRevealerInstance}async reveal(e){if(Common.Settings.Settings.instance().moduleSetting("autoFocusOnDebuggerPausedEnabled").get())return SourcesPanel.instance().setAsCurrentPanel()}}export class RevealingActionDelegate{static instance(e={forceNew:null}){const{forceNew:t}=e;return revealingActionDelegateInstance&&!t||(revealingActionDelegateInstance=new RevealingActionDelegate),revealingActionDelegateInstance}handleAction(e,t){const i=SourcesPanel.instance();if(!i.ensureSourcesViewVisible())return!1;if("debugger.toggle-pause"===t){return e.flavor(UI.ShortcutRegistry.ForwardedShortcut)&&!Common.Settings.Settings.instance().moduleSetting("disablePausedStateOverlay").get()||i.togglePause(),!0}return!1}}export class ActionDelegate{static instance(e={forceNew:null}){const{forceNew:t}=e;return actionDelegateInstance&&!t||(actionDelegateInstance=new ActionDelegate),actionDelegateInstance}handleAction(e,t){const i=SourcesPanel.instance();switch(t){case"debugger.step-over":return i.stepOver(),!0;case"debugger.step-into":return i.stepIntoAsync(),!0;case"debugger.step":return i.stepInto(),!0;case"debugger.step-out":return i.stepOut(),!0;case"debugger.run-snippet":return i.runSnippet(),!0;case"debugger.toggle-breakpoints-active":return i.toggleBreakpointsActive(),!0;case"debugger.evaluate-selection":{const e=UI.Context.Context.instance().flavor(UISourceCodeFrame);if(e){const{state:t}=e.textEditor;let i=t.sliceDoc(t.selection.main.from,t.selection.main.to);const n=UI.Context.Context.instance().flavor(SDK.RuntimeModel.ExecutionContext),a=n?.target().model(SDK.ConsoleModel.ConsoleModel);if(n&&a){const e=a.addCommandMessage(n,i);i=ObjectUI.JavaScriptREPL.JavaScriptREPL.wrapObjectLiteral(i),a.evaluateCommandInConsole(n,e,i,!0)}}return!0}case"sources.toggle-navigator-sidebar":return i.toggleNavigatorSidebar(),!0;case"sources.toggle-debugger-sidebar":return i.toggleDebuggerSidebar(),!0}return!1}}export class WrapperView extends UI.Widget.VBox{view;constructor(){super(),this.element.classList.add("sources-view-wrapper"),this.view=SourcesPanel.instance().sourcesView()}static instance(){return wrapperViewInstance||(wrapperViewInstance=new WrapperView),wrapperViewInstance}static isShowing(){return Boolean(wrapperViewInstance)&&wrapperViewInstance.isShowing()}wasShown(){SourcesPanel.instance().isShowing()?UI.InspectorView.InspectorView.instance().setDrawerMinimized(!0):this.showViewInWrapper(),SourcesPanel.updateResizerAndSidebarButtons(SourcesPanel.instance())}willHide(){UI.InspectorView.InspectorView.instance().setDrawerMinimized(!1),queueMicrotask((()=>{SourcesPanel.updateResizerAndSidebarButtons(SourcesPanel.instance())}))}showViewInWrapper(){this.view.show(this.element)}}const registeredNavigatorViews=[{viewId:"navigator-network",navigatorView:NetworkNavigatorView.instance,experiment:void 0},{viewId:"navigator-files",navigatorView:FilesNavigatorView.instance,experiment:void 0},{viewId:"navigator-snippets",navigatorView:SnippetsNavigatorView.instance,experiment:void 0},{viewId:"navigator-overrides",navigatorView:OverridesNavigatorView.instance,experiment:void 0},{viewId:"navigator-contentScripts",navigatorView:ContentScriptsNavigatorView.instance,experiment:void 0}];