UNPKG

@scalar/api-client

Version:

the open source API testing client

114 lines (113 loc) 4.28 kB
import { defineComponent as B, computed as E, watch as h, onMounted as D, createBlock as v, openBlock as s, unref as n, withCtx as r, createVNode as l, createElementVNode as d, toDisplayString as g, createElementBlock as L, createCommentVNode as M, Fragment as V, renderList as j, withModifiers as w, createTextVNode as k } from "vue"; import { ScalarDropdown as W, ScalarButton as T, ScalarDropdownItem as p, ScalarListboxCheckbox as _, ScalarDropdownDivider as $, ScalarIcon as z } from "@scalar/components"; import { useRouter as A } from "vue-router"; import { PathId as F } from "../../routes.js"; import { useActiveEntities as O } from "../../store/active-entities.js"; import { useWorkspace as P } from "../../store/store.js"; import { useLayout as R } from "../../hooks/useLayout.js"; const q = { class: "m-0 flex items-center gap-1.5 font-medium whitespace-nowrap" }, G = { class: "flex h-4 w-4 items-center justify-center" }, ee = /* @__PURE__ */ B({ __name: "EnvironmentSelector", setup(H) { const { activeCollection: o, activeWorkspace: i, activeEnvironment: c } = O(), { collectionMutators: S } = P(), { layout: C } = R(), y = A(), m = (t) => { o.value && i.value && (S.edit( o.value.uid, "x-scalar-active-environment", t ), i.value.activeEnvironmentId = t); }, I = () => y.push({ name: "environment.default", params: { [F.Workspace]: i.value?.uid } }), N = E(() => { const { value: t } = c, { value: e } = o; return t?.name || e?.["x-scalar-active-environment"] || "No Environment"; }), u = E(() => { const { value: t } = o, e = t?.["x-scalar-environments"]; return e ? Object.entries(e).map(([a, x]) => ({ ...x, uid: a, name: a })) : []; }), b = () => { const t = u.value; if (t.length > 0) { const e = t[t.length - 1]; e?.uid && m(e.uid); } }; h(u, (t, e) => { t.length > e.length && b(); }); const f = (t) => { const e = t["x-scalar-active-environment"]; e && o.value && i.value ? (o.value["x-scalar-active-environment"] = e, i.value.activeEnvironmentId = e) : i.value && (i.value.activeEnvironmentId = ""); }; return h( o, (t) => t && f(t) ), D(() => { o.value && f(o.value); }), (t, e) => (s(), v(n(W), { teleport: "" }, { items: r(() => [ (s(!0), L(V, null, j(u.value, (a) => (s(), v(n(p), { key: a.uid, class: "group/item flex items-center gap-1.5 overflow-hidden text-ellipsis whitespace-nowrap", onClick: w((x) => m(a.uid), ["stop"]) }, { default: r(() => [ l(n(_), { selected: n(o)?.["x-scalar-active-environment"] === a.uid }, null, 8, ["selected"]), k(" " + g(a.name), 1) ]), _: 2 }, 1032, ["onClick"]))), 128)), l(n(p), { class: "group/item flex items-center gap-1.5 overflow-hidden text-ellipsis whitespace-nowrap", onClick: e[0] || (e[0] = w((a) => m(""), ["stop"])) }, { default: r(() => [ l(n(_), { selected: n(c)?.uid === "" && n(o)?.["x-scalar-active-environment"] === "" || n(c)?.name === "No Environment" }, null, 8, ["selected"]), e[1] || (e[1] = k(" No Environment ", -1)) ]), _: 1 }), l(n($)), n(C) !== "modal" ? (s(), v(n(p), { key: 0, class: "flex items-center gap-1.5", onClick: I }, { default: r(() => [ d("div", G, [ l(n(z), { icon: "Brackets", size: "sm" }) ]), e[2] || (e[2] = d("span", { class: "leading-none" }, "Manage Environments", -1)) ]), _: 1 })) : M("", !0) ]), default: r(() => [ l(n(T), { class: "text-c-1 hover:bg-b-2 line-clamp-1 h-auto w-fit justify-start px-1.5 py-1.5 font-normal", variant: "ghost" }, { default: r(() => [ d("h2", q, g(N.value), 1) ]), _: 1 }) ]), _: 1 })); } }); export { ee as default };