UNPKG

@scalar/api-client

Version:

the open source API testing client

75 lines (74 loc) 2.45 kB
import { defineComponent as y, ref as d, watch as _, nextTick as w, onMounted as h, onBeforeUnmount as k, createBlock as L, openBlock as s, unref as l, withCtx as p, createElementVNode as i, createElementBlock as c, createCommentVNode as u, toDisplayString as g, createVNode as B } from "vue"; import { useLoadingState as S, ScalarLoading as b } from "@scalar/components"; import C from "../../../components/layout/CollapsibleSection.vue.js"; const T = { class: "flex w-full items-center justify-between" }, E = { key: 0, class: "mr-2 flex items-center gap-2" }, N = { key: 0, class: "text-red bg-b-danger sticky top-0 border-b p-2" }, V = { key: 1, class: "p-2" }, z = /* @__PURE__ */ y({ __name: "ResponseBodyStreaming", props: { reader: {} }, setup(f) { const e = S(), o = d(""), a = d(null), m = new TextDecoder(), r = d(null), v = () => { r.value && (r.value.scrollTop = r.value.scrollHeight); }; _(o, () => { w(v); }); async function x() { try { for (; e.isLoading; ) { const { done: n, value: t } = await f.reader.read(); if (n) { e.stopLoading(); break; } t && (o.value += m.decode(t, { stream: !0 })); } } catch (n) { console.error("Error reading stream:", n), e.stopLoading(), a.value = n; } finally { o.value += m.decode(); } } return h(() => { e.startLoading(), x(), a.value = null; }), k(() => { f.reader.cancel(), e.stopLoading(); }), (n, t) => (s(), L(l(C), { class: "max-h-content overflow-y-hidden" }, { title: p(() => [ i("div", T, [ t[1] || (t[1] = i("div", null, "Body", -1)), l(e).isLoading ? (s(), c("div", E, [ B(l(b), { loadingState: l(e), size: "xs" }, null, 8, ["loadingState"]), t[0] || (t[0] = i("span", { class: "text-c-2" }, " Listening… ", -1)) ])) : u("", !0) ]) ]), default: p(() => [ i("div", { ref_key: "contentContainer", ref: r, class: "text-xxs font-code h-full overflow-auto leading-2 whitespace-pre-wrap" }, [ a.value ? (s(), c("div", N, g(a.value.message), 1)) : u("", !0), o.value ? (s(), c("div", V, g(o.value), 1)) : u("", !0) ], 512) ]), _: 1 })); } }); export { z as default };