UNPKG

@scalar/api-client

Version:

the open source API testing client

202 lines (201 loc) 8.13 kB
import { defineComponent as j, computed as c, ref as w, useId as T, createBlock as l, openBlock as a, withCtx as v, createElementVNode as m, normalizeClass as b, createElementBlock as y, createVNode as A, Fragment as k, createCommentVNode as d, renderList as x, unref as B, withDirectives as I, resolveDynamicComponent as S, mergeProps as $, vShow as E } from "vue"; import { ScalarErrorBoundary as z } from "@scalar/components"; import O from "../../../components/SectionFilter.vue.js"; import L from "../../../components/ViewLayout/ViewLayoutSection.vue.js"; import M from "./RequestHeaders.vue.js"; import N from "./ResponseBody.vue.js"; import W from "./ResponseBodyStreaming.vue.js"; import D from "./ResponseBodyVirtual.vue.js"; import "./ResponseBodyVirtual.vue2.js"; import F from "./ResponseCookies.vue.js"; import P from "./ResponseEmpty.vue.js"; import U from "./ResponseHeaders.vue.js"; import K from "./ResponseLoadingOverlay.vue.js"; import Z from "./ResponseMetaInformation.vue.js"; import { usePluginManager as G } from "../../../plugins/hooks/usePluginManager.js"; const J = { class: "flex h-8 flex-1 items-center" }, Q = ["id", "role"], g = 2e5, me = /* @__PURE__ */ j({ __name: "ResponseSection", props: { collection: {}, operation: {}, workspace: {}, numWorkspaceRequests: {}, response: {}, requestResult: {} }, setup(r) { const R = G().getViewComponents("response.section"), f = c(() => { var o; const e = (o = r.response) == null ? void 0 : o.headers; return e ? Object.keys(e).map((n) => ({ name: n, value: e[n] ?? "", required: !1 })) : []; }), q = c( () => { var e; return ((e = r.response) == null ? void 0 : e.cookieHeaderKeys.flatMap((o) => { var i, p; const n = (p = (i = r.response) == null ? void 0 : i.headers) == null ? void 0 : p[o]; return n ? { name: o, value: n, required: !1 } : []; })) ?? []; } ), C = ["Cookies", "Headers", "Body"], s = w("All"), h = c(() => ["All", ...C]), t = c( () => Object.fromEntries( h.value.map((e) => [e, T()]) ) ), H = c(() => { var i, p; if (!r.response || !("size" in r.response)) return !1; const e = ((i = r.response.headers) == null ? void 0 : i["content-type"]) || ((p = r.response.headers) == null ? void 0 : p["Content-Type"]); return !e || (r.response.size ?? 0) <= g || 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((u) => e.includes(u)) && (r.response.size ?? 0) > g; }), V = c( () => { var e; return ((e = r.requestResult) == null ? void 0 : e.request.parameters.headers.filter((o) => o.enabled).map((o) => ({ name: o.key, value: o.value, required: !0 }))) ?? []; } ); return (e, o) => (a(), l(L, { "aria-label": "Response" }, { title: v(() => [ m("div", J, [ m("div", { "aria-live": "polite", class: b(["flex items-center", { "animate-response-heading": e.response }]) }, [ o[1] || (o[1] = m("span", { class: "response-heading pointer-events-none absolute" }, " Response ", -1)), e.response ? (a(), l(Z, { key: 0, class: "animate-response-children", response: e.response }, null, 8, ["response"])) : d("", !0) ], 2), A(O, { modelValue: s.value, "onUpdate:modelValue": o[0] || (o[0] = (n) => s.value = n), filterIds: t.value, filters: h.value }, null, 8, ["modelValue", "filterIds", "filters"]) ]) ]), default: v(() => { var n, i, p; return [ m("div", { id: t.value.All, class: b(["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 ? (a(), y(k, { key: 1 }, [ s.value === "All" || s.value === "Cookies" ? (a(), l(F, { key: 0, class: "response-section-content-cookies", id: t.value.Cookies, cookies: q.value, role: s.value === "All" ? "none" : "tabpanel" }, null, 8, ["id", "cookies", "role"])) : d("", !0), s.value === "All" || s.value === "Headers" ? (a(), l(M, { key: 1, class: "response-section-content-headers", id: t.value.Headers, headers: V.value, role: s.value === "All" ? "none" : "tabpanel" }, null, 8, ["id", "headers", "role"])) : d("", !0), s.value === "All" || s.value === "Headers" ? (a(), l(U, { key: 2, class: "response-section-content-headers", id: t.value.Headers, headers: f.value, role: s.value === "All" ? "none" : "tabpanel" }, null, 8, ["id", "headers", "role"])) : d("", !0), (a(!0), y(k, null, x(B(R), (u) => (a(), l(B(z), { key: u.component }, { default: v(() => [ I((a(), l(S(u.component), $({ ref_for: !0 }, u.props ?? {}), null, 16)), [ [E, s.value === "All" || s.value === u.title] ]) ]), _: 2 }, 1024))), 128)), s.value === "All" || s.value === "Body" ? (a(), y(k, { key: 3 }, [ "reader" in e.response ? (a(), l(W, { key: 0, class: "response-section-content-body", id: t.value.Body, reader: e.response.reader }, null, 8, ["id", "reader"])) : H.value && typeof ((n = e.response) == null ? void 0 : n.data) == "string" ? (a(), l(D, { key: 1, id: t.value.Body, content: e.response.data, data: (i = e.response) == null ? void 0 : i.data, headers: f.value, role: s.value === "All" ? "none" : "tabpanel" }, null, 8, ["id", "content", "data", "headers", "role"])) : (a(), l(N, { key: 2, class: "response-section-content-body", id: t.value.Body, layout: "client", active: !0, data: (p = e.response) == null ? void 0 : p.data, headers: f.value, role: s.value === "All" ? "none" : "tabpanel", title: "Body" }, null, 8, ["id", "data", "headers", "role"])) ], 64)) : d("", !0) ], 64)) : (a(), l(P, { key: 0, collection: e.collection, operation: e.operation, workspace: e.workspace, numWorkspaceRequests: e.numWorkspaceRequests }, null, 8, ["collection", "operation", "workspace", "numWorkspaceRequests"])), A(K) ], 10, Q) ]; }), _: 1 })); } }); export { me as default };