UNPKG

@scalar/api-client

Version:

the open source API testing client

83 lines (82 loc) 2.9 kB
import { defineComponent as x, computed as a, watch as w, createBlock as b, createElementBlock as h, openBlock as v, unref as n, withCtx as f, createVNode as m, createElementVNode as l, toDisplayString as p } from "vue"; import { ScalarListbox as y, ScalarButton as k } from "@scalar/components"; import { ScalarIconCaretDown as U } from "@scalar/icons"; import { useWorkspace as V } from "../../store/store.js"; const B = { class: "overflow-x-auto" }, W = { key: 1, class: "text-c-1 flex h-auto w-full items-center gap-0.75 rounded-b-lg px-3 py-1.5 text-base leading-[20px] whitespace-nowrap" }, z = { class: "overflow-x-auto" }, j = /* @__PURE__ */ x({ __name: "ServerSelector", props: { collection: {}, server: {}, target: {} }, emits: ["updateServer"], setup(r, { emit: g }) { const i = g, { servers: o, collectionMutators: u } = V(), s = a( () => r.collection?.servers.map((e) => ({ id: e, label: o[e]?.url ?? "Unknown server" })) ), c = a({ get: () => r.server ? s.value.find((e) => e.id === r.server.uid) : void 0, set: (e) => { if (!e) return; u.edit( r.collection.uid, "selectedServerUid", e.id ); const t = o[e.id]?.url; t && i("updateServer", t); } }); w( () => r.collection, (e) => { if (!e || e.selectedServerUid) return; const t = r.collection.servers?.[0]; t && (u.edit(r.collection.uid, "selectedServerUid", t), o[t]?.url && i("updateServer", o[t].url)); } ); const d = a(() => r.server?.url?.endsWith("/") ? r.server.url.slice(0, -1) : r.server?.url || ""); return (e, t) => s.value.length > 1 ? (v(), b(n(y), { key: 0, modelValue: c.value, "onUpdate:modelValue": t[0] || (t[0] = (S) => c.value = S), options: s.value, placement: "bottom-start", resize: "", target: e.target, teleport: `#${e.target}`, class: "group" }, { default: f(() => [ m(n(k), { class: "bg-b-1 text-c-1 h-auto w-full justify-start gap-1.5 overflow-x-auto rounded-t-none rounded-b-lg px-3 py-1.5 text-base font-normal whitespace-nowrap -outline-offset-1", variant: "ghost" }, { default: f(() => [ t[1] || (t[1] = l("span", { class: "sr-only" }, "Server:", -1)), l("span", B, p(d.value), 1), m(n(U), { weight: "bold", class: "text-c-2 ui-open:rotate-180 mt-0.25 size-3 transition-transform duration-100" }) ]), _: 1 }) ]), _: 1 }, 8, ["modelValue", "options", "target", "teleport"])) : (v(), h("div", W, [ t[2] || (t[2] = l("span", { class: "sr-only" }, "Server:", -1)), l("span", z, p(d.value), 1) ])); } }); export { j as default };