@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 4.75 kB
JavaScript
import*as Common from"../../../../core/common/common.js";import*as i18n from"../../../../core/i18n/i18n.js";import*as SDK from"../../../../core/sdk/sdk.js";import*as Bindings from"../../../../models/bindings/bindings.js";import*as UI from"../../legacy.js";import{Linkifier}from"./Linkifier.js";import jsUtilsStyles from"./jsUtils.css.js";const UIStrings={removeFromIgnore:"Remove from ignore list",addToIgnore:"Add script to ignore list",showSMoreFrames:"{n, plural, =1 {Show # more frame} other {Show # more frames}}",showLess:"Show less",unknownSource:"unknown"},str_=i18n.i18n.registerUIStrings("ui/legacy/components/utils/JSPresentationUtils.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);function populateContextMenu(e,n){const t=new UI.ContextMenu.ContextMenu(n);n.consume(!0);const i=Linkifier.uiLocation(e);i&&Bindings.IgnoreListManager.IgnoreListManager.instance().canIgnoreListUISourceCode(i.uiSourceCode)&&(Bindings.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(i.uiSourceCode.url())?t.debugSection().appendItem(i18nString(UIStrings.removeFromIgnore),(()=>Bindings.IgnoreListManager.IgnoreListManager.instance().unIgnoreListUISourceCode(i.uiSourceCode))):t.debugSection().appendItem(i18nString(UIStrings.addToIgnore),(()=>Bindings.IgnoreListManager.IgnoreListManager.instance().ignoreListUISourceCode(i.uiSourceCode)))),t.appendApplicableItems(n),t.show()}export function buildStackTraceRows(e,n,t,i,o){const r=[];if(o){const e=new Common.Throttler.Throttler(100);t.setLiveLocationUpdateCallback((()=>e.schedule((async()=>updateHiddenRows(o,r)))))}function s(e,o=void 0){let s=null;o&&(s={asyncDescription:UI.UIUtils.asyncStackTraceLabel(e.description,o),ignoreListHide:!1},r.push(s));let a=0,c=!1;for(const o of e.callFrames){let e=!1;const s=UI.UIUtils.beautifyFunctionName(o.functionName),l=t.maybeLinkifyConsoleCallFrame(n,o,{tabStop:Boolean(i),inlineFrameIndex:0,revealBreakpoint:c});if(l){l.addEventListener("contextmenu",populateContextMenu.bind(null,l));const n=Linkifier.uiLocation(l);n&&Bindings.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(n.uiSourceCode)&&(e=!0),l.textContent||(l.textContent=i18nString(UIStrings.unknownSource))}e&&++a,r.push({functionName:s,link:l,ignoreListHide:e}),c=[SDK.DebuggerModel.COND_BREAKPOINT_SOURCE_URL,SDK.DebuggerModel.LOGPOINT_SOURCE_URL].includes(o.url)}s&&a>0&&a===e.callFrames.length&&(s.ignoreListHide=!0)}s(e);let a=e.callFrames;for(let n=e.parent;n;n=n.parent)n.callFrames.length&&s(n,a),a=n.callFrames;return r}function updateHiddenRows(e,n){let t=0,i=n.length;for(let e=n.length-1;e>=0;e--){const o=n[e];if("link"in o&&o.link){const e=Linkifier.uiLocation(o.link);e&&Bindings.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(e.uiSourceCode)&&(o.ignoreListHide=!0),o.ignoreListHide&&t++}"asyncDescription"in o&&(t>0&&t===i-e-1&&(o.ignoreListHide=!0),i=e,t=0)}e(n)}export function buildStackTracePreviewContents(e,n,t={stackTrace:void 0,tabStops:void 0}){const{stackTrace:i,tabStops:o}=t,r=document.createElement("span");r.classList.add("monospace"),r.style.display="inline-block";const s=UI.Utils.createShadowRootWithCoreStyles(r,{cssFile:[jsUtilsStyles],delegatesFocus:void 0}).createChild("table","stack-preview-container");if(!i)return{element:r,links:[]};const a=renderStackTraceTable.bind(null,s);return{element:r,links:renderStackTraceTable(s,buildStackTraceRows(i,e,n,o,a))}}function renderStackTraceTable(e,n){e.removeChildren();let t=0;const i=[];for(const o of n){const n=e.createChild("tr");"asyncDescription"in o?(n.createChild("td").textContent="\n",n.createChild("td","stack-preview-async-description").textContent=o.asyncDescription,n.createChild("td"),n.createChild("td")):(n.createChild("td").textContent="\n",n.createChild("td","function-name").textContent=o.functionName,n.createChild("td").textContent=" @ ",o.link&&(n.createChild("td").appendChild(o.link),i.push(o.link)),o.ignoreListHide&&++t),o.ignoreListHide&&n.classList.add("hidden-row"),e.appendChild(n)}if(t){const n=e.createChild("tr","show-all-link");n.createChild("td").textContent="\n";const i=n.createChild("td");i.colSpan=4;const o=i.createChild("span","link");o.textContent=i18nString(UIStrings.showSMoreFrames,{n:t}),o.addEventListener("click",(()=>{e.classList.add("show-hidden-rows"),UI.GlassPane.GlassPane.containerMoved(e)}),!1);const r=e.createChild("tr","show-less-link");r.createChild("td").textContent="\n";const s=r.createChild("td");s.colSpan=4;const a=s.createChild("span","link");a.textContent=i18nString(UIStrings.showLess),a.addEventListener("click",(()=>{e.classList.remove("show-hidden-rows"),UI.GlassPane.GlassPane.containerMoved(e)}),!1)}return i}