UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

76 lines (75 loc) 2.57 kB
import { defineComponent as S, computed as l, createBlock as w, createElementBlock as b, openBlock as d, unref as u, withCtx as c, createVNode as v, createElementVNode as o, toDisplayString as m } from "vue"; import { ScalarListbox as h, ScalarButton as y } from "@scalar/components"; import { ScalarIconCaretDown as V } from "@scalar/icons"; const k = { class: "overflow-x-auto" }, B = { 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" }, C = { class: "overflow-x-auto" }, N = /* @__PURE__ */ S({ __name: "Selector", props: { xSelectedServer: {}, servers: {}, target: {} }, emits: ["update:modelValue"], setup(t, { expose: p, emit: f }) { const x = f, a = l( () => t.servers.map((e) => ({ id: e.url, label: e.url })) ), i = l(() => t.servers.find((e) => e.url === t.xSelectedServer)), s = l( () => i.value?.url?.replace(/\/$/, "") || "" ), n = l({ get: () => { if (t.xSelectedServer && a.value.length > 0) return a.value.find((e) => e.id === t.xSelectedServer); }, set: (e) => { e && x("update:modelValue", e.id); } }); return p({ server: i, servers: t.servers, serverUrlWithoutTrailingSlash: s, serverOptions: a, selectedServer: n }), (e, r) => a.value.length > 1 ? (d(), w(u(h), { key: 0, ref: "elem", modelValue: n.value, "onUpdate:modelValue": r[0] || (r[0] = (g) => n.value = g), class: "group", options: a.value, placement: "bottom-start", resize: "", target: e.target }, { default: c(() => [ v(u(y), { 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: c(() => [ r[1] || (r[1] = o("span", { class: "sr-only" }, "Server:", -1)), o("span", k, m(s.value), 1), v(u(V), { class: "text-c-2 ui-open:rotate-180 mt-0.25 size-3 transition-transform duration-100", weight: "bold" }) ]), _: 1, __: [1] }) ]), _: 1 }, 8, ["modelValue", "options", "target"])) : (d(), b("div", B, [ r[2] || (r[2] = o("span", { class: "sr-only" }, "Server:", -1)), o("span", C, m(s.value), 1) ])); } }); export { N as default };