UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 2.17 kB
import*as i18n from"../../core/i18n/i18n.js";import*as TextUtils from"../../models/text_utils/text_utils.js";import*as SourceFrame from"../../ui/legacy/components/source_frame/source_frame.js";import*as UI from"../../ui/legacy/legacy.js";import*as LegacyWrapper from"../../ui/components/legacy_wrapper/legacy_wrapper.js";import{RequestHTMLView}from"./RequestHTMLView.js";import{RequestResponseView}from"./RequestResponseView.js";import{SignedExchangeInfoView}from"./SignedExchangeInfoView.js";import{WebBundleInfoView}from"./components/WebBundleInfoView.js";const UIStrings={failedToLoadResponseData:"Failed to load response data",previewNotAvailable:"Preview not available"},str_=i18n.i18n.registerUIStrings("panels/network/RequestPreviewView.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class RequestPreviewView extends RequestResponseView{constructor(e){super(e)}async showPreview(){const e=await super.showPreview();if(!(e instanceof UI.View.SimpleView))return e;const t=new UI.Toolbar.Toolbar("network-item-preview-toolbar",this.element);return e.toolbarItems().then((e=>{e.map((e=>t.appendToolbarItem(e)))})),e}async htmlPreview(){const e=await this.request.contentData();if(e.error)return new UI.EmptyWidget.EmptyWidget(i18nString(UIStrings.failedToLoadResponseData)+": "+e.error);if(!new Set(["text/html","text/plain","application/xhtml+xml"]).has(this.request.mimeType))return null;const t=e.encoded?window.atob(e.content):e.content,r=await SourceFrame.JSONView.JSONView.createView(t);if(r)return r;const i=TextUtils.ContentProvider.contentAsDataURL(e.content,this.request.mimeType,e.encoded,this.request.charset());return i?new RequestHTMLView(i):null}async createPreview(){if(this.request.signedExchangeInfo())return new SignedExchangeInfoView(this.request);if(this.request.webBundleInfo())return LegacyWrapper.LegacyWrapper.legacyWrapper(UI.Widget.VBox,new WebBundleInfoView(this.request));const e=await this.htmlPreview();if(e)return e;const t=await SourceFrame.PreviewFactory.PreviewFactory.createPreview(this.request,this.request.mimeType);return t||new UI.EmptyWidget.EmptyWidget(i18nString(UIStrings.previewNotAvailable))}}