UNPKG

@scalar/api-client

Version:

the open source API testing client

181 lines (180 loc) 7.62 kB
import { defineComponent as T, computed as i, ref as $, useId as S, createBlock as r, openBlock as o, withCtx as u, createElementVNode as c, normalizeClass as R, createElementBlock as p, createVNode as A, Fragment as y, createCommentVNode as d, createTextVNode as q, renderList as g, unref as I, withDirectives as P, resolveDynamicComponent as E, mergeProps as O, vShow as z } from "vue"; import { ScalarErrorBoundary as N } from "@scalar/components"; import { isDefined as D } from "@scalar/helpers/array/is-defined"; import L from "../../../components/SectionFilter.vue.js"; import j from "../../../components/ViewLayout/ViewLayoutSection.vue.js"; import V from "./components/Headers.vue.js"; import w from "./components/ResponseBody.vue.js"; import F from "./components/ResponseBodyStreaming.vue.js"; import U from "./components/ResponseBodyVirtual.vue.js"; /* empty css */ import K from "./components/ResponseCookies.vue.js"; import M from "./components/ResponseEmpty.vue.js"; import Z from "./components/ResponseLoadingOverlay.vue.js"; import G from "./components/ResponseMetaInformation.vue.js"; import { textMediaTypes as J } from "./helpers/media-types.js"; import { parseSetCookie as Q } from "./helpers/parse-set-cookie.js"; const W = { class: "flex h-8 flex-1 items-center" }, X = ["id", "role"], b = 2e5, ve = /* @__PURE__ */ T({ __name: "ResponseBlock", props: { response: {}, request: {}, layout: {}, totalPerformedRequests: {}, appVersion: {}, plugins: {}, eventBus: {} }, setup(e, { expose: x }) { const m = i(() => { const s = e.response?.headers; return s ? Object.keys(s).map((t) => ({ name: t, value: s[t] ?? "" })) : []; }), k = i( () => e.response?.cookieHeaderKeys.map((s) => Q(s)).filter(D) ?? [] ), C = ["Cookies", "Headers", "Body"], n = $("All"), f = i(() => ["All", ...C]), a = i( () => Object.fromEntries( f.value.map((s) => [s, S()]) ) ), B = i(() => { if (!e.response || !("size" in e.response)) return !1; const s = e.response.headers?.["content-type"] || e.response.headers?.["Content-Type"]; return !s || (e.response.size ?? 0) <= b || s.includes("text/html") ? !1 : J.some((l) => s.includes(l)) && (e.response.size ?? 0) > b; }), h = i( () => e.request?.headers ? [...e.request.headers].map((s) => ({ name: s[0], value: s[1], required: !1 })) : [] ), v = (s) => n.value === "All" || n.value === s; return x({ responseHeaders: m, responseCookies: k, requestHeaders: h, shouldVirtualize: B, activeFilter: n, filters: f }), (s, t) => (o(), r(j, { "aria-label": "Response" }, { title: u(() => [ c("div", W, [ c("div", { "aria-live": "polite", class: R(["flex items-center", { "animate-response-heading": e.response }]) }, [ t[4] || (t[4] = c("span", { class: "response-heading pointer-events-none absolute" }, " Response ", -1)), e.response ? (o(), r(G, { key: 0, class: "animate-response-children", eventBus: e.eventBus, response: e.response }, null, 8, ["eventBus", "response"])) : d("", !0) ], 2), A(L, { modelValue: n.value, "onUpdate:modelValue": t[0] || (t[0] = (l) => n.value = l), filterIds: a.value, filters: f.value }, null, 8, ["modelValue", "filterIds", "filters"]) ]) ]), default: u(() => [ c("div", { id: a.value.All, class: R(["custom-scroll response-section-content relative grid h-full justify-stretch", { "content-start": e.response }]), role: n.value === "All" && e.response ? "tabpanel" : "none" }, [ e.response ? (o(), p(y, { key: 1 }, [ v("Cookies") ? (o(), r(K, { key: 0, id: a.value.Cookies, class: "response-section-content-cookies", cookies: k.value, role: n.value === "All" ? "none" : "tabpanel" }, null, 8, ["id", "cookies", "role"])) : d("", !0), v("Headers") ? (o(), r(V, { key: 1, id: a.value.Headers, class: "response-section-content-headers", headers: h.value, role: n.value === "All" ? "none" : "tabpanel" }, { title: u(() => [...t[5] || (t[5] = [ q("Request Headers", -1) ])]), _: 1 }, 8, ["id", "headers", "role"])) : d("", !0), v("Headers") ? (o(), r(V, { key: 2, id: a.value.Headers, class: "response-section-content-headers", headers: m.value, role: n.value === "All" ? "none" : "tabpanel" }, { title: u(() => [...t[6] || (t[6] = [ q("Response Headers", -1) ])]), _: 1 }, 8, ["id", "headers", "role"])) : d("", !0), (o(!0), p(y, null, g(e.plugins, (l, H) => (o(), r(I(N), { key: H }, { default: u(() => [ l?.components?.response ? P((o(), r(E(l.components.response.component), O({ key: 0, ref_for: !0 }, l.components.response.additionalProps), null, 16)), [ [z, n.value === "All"] ]) : d("", !0) ]), _: 2 }, 1024))), 128)), n.value === "All" || n.value === "Body" ? (o(), p(y, { key: 3 }, [ "reader" in e.response ? (o(), r(F, { key: 0, id: a.value.Body, class: "response-section-content-body", reader: e.response.reader }, null, 8, ["id", "reader"])) : B.value && typeof e.response?.data == "string" ? (o(), r(U, { key: 1, id: a.value.Body, content: e.response.data, data: e.response?.data, headers: m.value, role: n.value === "All" ? "none" : "tabpanel" }, null, 8, ["id", "content", "data", "headers", "role"])) : (o(), r(w, { key: 2, id: a.value.Body, active: !0, class: "response-section-content-body", data: e.response?.data, headers: m.value, layout: "client", role: n.value === "All" ? "none" : "tabpanel", title: "Body" }, null, 8, ["id", "data", "headers", "role"])) ], 64)) : d("", !0) ], 64)) : (o(), r(M, { key: 0, appVersion: e.appVersion, layout: e.layout, totalPerformedRequests: e.totalPerformedRequests, onAddRequest: t[1] || (t[1] = (l) => e.eventBus.emit("ui:open:command-palette", { action: "create-request", payload: void 0 })), onOpenCommandPalette: t[2] || (t[2] = (l) => e.eventBus.emit("ui:open:command-palette")), onSendRequest: t[3] || (t[3] = (l) => e.eventBus.emit("operation:send:request:hotkey")) }, null, 8, ["appVersion", "layout", "totalPerformedRequests"])), A(Z, { eventBus: e.eventBus }, null, 8, ["eventBus"]) ], 10, X) ]), _: 1 })); } }); export { ve as default };