UNPKG

@scalar/api-client

Version:

the open source API testing client

190 lines (189 loc) 7.52 kB
import { defineComponent as H, computed as i, ref as V, useId as j, createBlock as n, openBlock as o, withCtx as d, createElementVNode as u, normalizeClass as y, createElementBlock as m, createVNode as k, Fragment as f, createCommentVNode as p, renderList as w, unref as h, withDirectives as T, resolveDynamicComponent as x, mergeProps as I, vShow as S } from "vue"; import { ScalarErrorBoundary as $ } from "@scalar/components"; import E from "../../../components/SectionFilter.vue.js"; import z from "../../../components/ViewLayout/ViewLayoutSection.vue.js"; import O from "./RequestHeaders.vue.js"; import L from "./ResponseBody.vue.js"; import M from "./ResponseBodyStreaming.vue.js"; import N from "./ResponseBodyVirtual.vue.js"; /* empty css */ import W from "./ResponseCookies.vue.js"; import D from "./ResponseEmpty.vue.js"; import F from "./ResponseHeaders.vue.js"; import P from "./ResponseLoadingOverlay.vue.js"; import U from "./ResponseMetaInformation.vue.js"; import { usePluginManager as K } from "../../../plugins/hooks/usePluginManager.js"; const Z = { class: "flex h-8 flex-1 items-center" }, G = ["id", "role"], b = 2e5, ce = /* @__PURE__ */ H({ __name: "ResponseSection", props: { collection: {}, operation: {}, workspace: {}, numWorkspaceRequests: {}, response: {}, requestResult: {} }, setup(l) { const A = K().getViewComponents("response.section"), c = i(() => { const e = l.response?.headers; return e ? Object.keys(e).map((a) => ({ name: a, value: e[a] ?? "", required: !1 })) : []; }), B = i( () => l.response?.cookieHeaderKeys.flatMap((e) => { const a = l.response?.headers?.[e]; return a ? { name: e, value: a, required: !1 } : []; }) ?? [] ), g = ["Cookies", "Headers", "Body"], s = V("All"), v = i(() => ["All", ...g]), r = i( () => Object.fromEntries( v.value.map((e) => [e, j()]) ) ), R = i(() => { if (!l.response || !("size" in l.response)) return !1; const e = l.response.headers?.["content-type"] || l.response.headers?.["Content-Type"]; return !e || (l.response.size ?? 0) <= b || e.includes("text/html") ? !1 : [ // Text types "text/", // JSON types "application/json", "application/ld+json", "application/problem+json", "application/vnd.api+json", // XML types "application/xml", "application/atom+xml", "application/rss+xml", "application/problem+xml", // Other structured text "application/javascript", "application/ecmascript", "application/x-yaml", "application/yaml", // Source code "application/x-httpd-php", "application/x-sh", "application/x-perl", "application/x-python", "application/x-ruby", "application/x-java-source", // Form data "application/x-www-form-urlencoded" ].some((C) => e.includes(C)) && (l.response.size ?? 0) > b; }), q = i( () => l.requestResult?.request.parameters.headers.filter((e) => e.enabled).map((e) => ({ name: e.key, value: e.value, required: !0 })) ?? [] ); return (e, a) => (o(), n(z, { "aria-label": "Response" }, { title: d(() => [ u("div", Z, [ u("div", { "aria-live": "polite", class: y(["flex items-center", { "animate-response-heading": e.response }]) }, [ a[1] || (a[1] = u("span", { class: "response-heading pointer-events-none absolute" }, " Response ", -1)), e.response ? (o(), n(U, { key: 0, class: "animate-response-children", response: e.response }, null, 8, ["response"])) : p("", !0) ], 2), k(E, { modelValue: s.value, "onUpdate:modelValue": a[0] || (a[0] = (t) => s.value = t), filterIds: r.value, filters: v.value }, null, 8, ["modelValue", "filterIds", "filters"]) ]) ]), default: d(() => [ u("div", { id: r.value.All, class: y(["custom-scroll response-section-content relative grid h-full justify-stretch", { "content-start": e.response }]), role: s.value === "All" && e.response ? "tabpanel" : "none" }, [ e.response ? (o(), m(f, { key: 1 }, [ s.value === "All" || s.value === "Cookies" ? (o(), n(W, { key: 0, class: "response-section-content-cookies", id: r.value.Cookies, cookies: B.value, role: s.value === "All" ? "none" : "tabpanel" }, null, 8, ["id", "cookies", "role"])) : p("", !0), s.value === "All" || s.value === "Headers" ? (o(), n(O, { key: 1, class: "response-section-content-headers", id: r.value.Headers, headers: q.value, role: s.value === "All" ? "none" : "tabpanel" }, null, 8, ["id", "headers", "role"])) : p("", !0), s.value === "All" || s.value === "Headers" ? (o(), n(F, { key: 2, class: "response-section-content-headers", id: r.value.Headers, headers: c.value, role: s.value === "All" ? "none" : "tabpanel" }, null, 8, ["id", "headers", "role"])) : p("", !0), (o(!0), m(f, null, w(h(A), (t) => (o(), n(h($), { key: t.component }, { default: d(() => [ T((o(), n(x(t.component), I({ ref_for: !0 }, t.props ?? {}), null, 16)), [ [S, s.value === "All" || s.value === t.title] ]) ]), _: 2 }, 1024))), 128)), s.value === "All" || s.value === "Body" ? (o(), m(f, { key: 3 }, [ "reader" in e.response ? (o(), n(M, { key: 0, class: "response-section-content-body", id: r.value.Body, reader: e.response.reader }, null, 8, ["id", "reader"])) : R.value && typeof e.response?.data == "string" ? (o(), n(N, { key: 1, id: r.value.Body, content: e.response.data, data: e.response?.data, headers: c.value, role: s.value === "All" ? "none" : "tabpanel" }, null, 8, ["id", "content", "data", "headers", "role"])) : (o(), n(L, { key: 2, class: "response-section-content-body", id: r.value.Body, layout: "client", active: !0, data: e.response?.data, headers: c.value, role: s.value === "All" ? "none" : "tabpanel", title: "Body" }, null, 8, ["id", "data", "headers", "role"])) ], 64)) : p("", !0) ], 64)) : (o(), n(D, { key: 0, collection: e.collection, operation: e.operation, workspace: e.workspace, numWorkspaceRequests: e.numWorkspaceRequests }, null, 8, ["collection", "operation", "workspace", "numWorkspaceRequests"])), k(P) ], 10, G) ]), _: 1 })); } }); export { ce as default };