@scalar/api-client
Version:
the open source API testing client
88 lines (87 loc) • 3.26 kB
JavaScript
import { defineComponent as y, computed as m, createBlock as c, openBlock as t, unref as o, withCtx as l, createVNode as n, createElementBlock as d, Fragment as v, createElementVNode as s, createTextVNode as h, toDisplayString as w, createCommentVNode as C, renderList as B } from "vue";
import { ScalarPopover as z, ScalarButton as A, ScalarIcon as f, ScalarFloatingBackdrop as N } from "@scalar/components";
import U from "./ServerDropdownItem.vue.js";
const V = ["onClick"], D = { class: "flex h-4 w-4 items-center justify-center" }, I = /* @__PURE__ */ y({
__name: "ServerDropdown",
props: {
servers: {},
server: {},
target: {},
layout: {}
},
emits: ["update:selectedServer", "update:variable", "addServer"],
setup(a, { emit: b }) {
const i = b, g = m(
() => a.servers.map((r) => ({
id: r.url,
label: r.url ?? "Unknown server"
}))
), S = m(() => a.server?.url?.endsWith("/") ? a.server.url.slice(0, -1) : a.server?.url || "");
return (r, e) => (t(), c(o(z), {
class: "max-h-[inherit] p-0 text-base",
focus: "",
offset: 0,
placement: "bottom-start",
resize: "",
target: r.target,
teleport: `#${r.target}`
}, {
popover: l(({ close: x }) => [
s("div", {
class: "custom-scroll flex max-h-[inherit] flex-col gap-1 border-t p-1",
onClick: x
}, [
(t(!0), d(v, null, B(g.value, (u) => (t(), c(U, {
key: u.id,
server: r.server,
serverOption: u,
type: "request",
"onUpdate:selectedServer": e[0] || (e[0] = (p) => i("update:selectedServer", p)),
"onUpdate:variable": e[1] || (e[1] = (p, k) => i("update:variable", { key: p, value: k }))
}, null, 8, ["server", "serverOption"]))), 128)),
r.layout !== "modal" ? (t(), d("button", {
key: 0,
class: "text-xxs hover:bg-b-2 flex cursor-pointer items-center gap-1.5 rounded p-1.75",
type: "button",
onClick: e[2] || (e[2] = (u) => i("addServer"))
}, [
s("div", D, [
n(o(f), {
icon: "Add",
size: "sm"
})
]),
e[5] || (e[5] = s("span", null, "Add Server", -1))
])) : C("", !0)
], 8, V)
]),
backdrop: l(() => [
n(o(N), { class: "-top-(--scalar-address-bar-height) rounded-lg" })
]),
default: l(() => [
n(o(A), {
class: "z-context-plus hover:bg-b-2 font-code text-c-2 ml-0.75 h-auto gap-0.75 rounded border px-1.5 text-base whitespace-nowrap",
variant: "ghost"
}, {
default: l(() => [
r.server ? (t(), d(v, { key: 0 }, [
e[3] || (e[3] = s("span", { class: "sr-only" }, "Server:", -1)),
h(" " + w(S.value), 1)
], 64)) : (t(), d(v, { key: 1 }, [
e[4] || (e[4] = s("span", { class: "sr-only" }, "Add Server", -1)),
n(o(f), {
icon: "Add",
size: "xs"
})
], 64))
]),
_: 1
})
]),
_: 1
}, 8, ["target", "teleport"]));
}
});
export {
I as default
};