@scalar/api-client
Version:
the open source API testing client
75 lines (74 loc) • 2.45 kB
JavaScript
import { defineComponent as y, ref as i, watch as _, nextTick as w, onMounted as h, onBeforeUnmount as k, createBlock as L, openBlock as s, withCtx as p, createElementVNode as l, createElementBlock as d, createCommentVNode as c, toDisplayString as g, unref as u, createVNode as B } from "vue";
import { useLoadingState as S, ScalarLoading as b } from "@scalar/components";
import C from "../../../components/ViewLayout/ViewLayoutCollapse.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 = i(""), a = i(null), m = new TextDecoder(), r = i(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(C, { class: "max-h-content overflow-y-hidden" }, {
title: p(() => [
l("div", T, [
t[1] || (t[1] = l("div", null, "Body", -1)),
u(e).isLoading ? (s(), d("div", E, [
B(u(b), {
loadingState: u(e),
size: "xs"
}, null, 8, ["loadingState"]),
t[0] || (t[0] = l("span", { class: "text-c-2" }, " Listening… ", -1))
])) : c("", !0)
])
]),
default: p(() => [
l("div", {
ref_key: "contentContainer",
ref: r,
class: "text-xxs font-code h-full overflow-auto leading-2 whitespace-pre-wrap"
}, [
a.value ? (s(), d("div", N, g(a.value.message), 1)) : c("", !0),
o.value ? (s(), d("div", V, g(o.value), 1)) : c("", !0)
], 512)
]),
_: 1
}));
}
});
export {
z as default
};