UNPKG

@scalar/api-client

Version:

the open source API testing client

135 lines (134 loc) 4.92 kB
import { defineComponent as S, ref as D, createElementBlock as x, openBlock as d, Fragment as w, createElementVNode as t, createVNode as s, unref as e, withCtx as o, toDisplayString as k, renderList as W, createBlock as z, withModifiers as v, normalizeClass as N, withDirectives as M, vModelText as B, createTextVNode as V } from "vue"; import { useModal as j, ScalarDropdown as E, ScalarButton as h, ScalarIcon as m, ScalarDropdownItem as _, ScalarDropdownDivider as T, ScalarModal as $ } from "@scalar/components"; import { useToasts as A } from "@scalar/use-toasts"; import { useRouter as I } from "vue-router"; import { useActiveEntities as F } from "../../store/active-entities.js"; import { useWorkspace as L } from "../../store/store.js"; const P = { class: "flex w-[inherit] items-center text-base" }, R = { class: "m-0 flex items-center gap-1 text-sm font-medium" }, U = { class: "line-clamp-1 w-[calc(100%-10px)] text-left text-xs" }, q = { class: "overflow-hidden text-ellipsis" }, G = { class: "flex h-4 w-4 items-center justify-center" }, ee = /* @__PURE__ */ S({ __name: "WorkspaceSelector", setup(H) { const { activeWorkspace: i } = F(), { workspaces: b, workspaceMutators: g } = L(), { push: u } = I(), c = j(), { toast: f } = A(), r = D(""), C = (n) => { n !== i.value?.uid && u({ name: "workspace", params: { workspace: n } }); }, y = () => { if (!r.value.trim()) { f("Please enter a name before creating a workspace.", "error"); return; } const n = g.add({ name: r.value }); f(`Created new workspace '${n.name}'`), u({ name: "workspace", params: { workspace: n.uid } }), r.value = "", c.hide(); }; return (n, a) => (d(), x(w, null, [ t("div", P, [ s(e(E), null, { items: o(() => [ (d(!0), x(w, null, W(e(b), (l, p) => (d(), z(e(_), { key: p, class: "group/item flex w-full items-center gap-1.5 overflow-hidden text-ellipsis whitespace-nowrap", onClick: v((J) => C(p), ["stop"]) }, { default: o(() => [ t("div", { class: N([ "flex h-4 w-4 items-center justify-center rounded-full p-[3px]", e(i)?.uid === p ? "bg-c-accent text-b-1" : "shadow-border text-transparent" ]) }, [ s(e(m), { class: "size-2.5", icon: "Checkmark", thickness: "3" }) ], 2), t("span", q, k(l.name), 1) ]), _: 2 }, 1032, ["onClick"]))), 128)), s(e(T)), s(e(_), { class: "flex items-center gap-1.5", onClick: a[0] || (a[0] = (l) => e(c).show()) }, { default: o(() => [ t("div", G, [ s(e(m), { icon: "Add", size: "sm" }) ]), a[2] || (a[2] = t("span", null, "New Workspace", -1)) ]), _: 1 }) ]), default: o(() => [ s(e(h), { class: "hover:bg-b-2 text-c-3 line-clamp-1 h-full w-fit justify-start px-1.5 py-1 font-normal", variant: "ghost" }, { default: o(() => [ t("div", R, [ t("h2", U, k(e(i)?.name), 1), s(e(m), { icon: "ChevronDown", size: "md" }) ]) ]), _: 1 }) ]), _: 1 }) ]), s(e($), { bodyClass: "m-0 p-1 rounded-lg border-t-0", class: "z-overlay absolute", size: "xxs", state: e(c), variant: "form" }, { default: o(() => [ t("form", { class: "flex gap-1", onSubmit: v(y, ["prevent"]) }, [ M(t("input", { "onUpdate:modelValue": a[1] || (a[1] = (l) => r.value = l), class: "min-h-8 w-full flex-1 border-none p-1.5 text-sm outline-none", placeholder: "New Workspace", type: "text" }, null, 512), [ [B, r.value] ]), s(e(h), { class: "max-h-8 p-0 px-3 text-xs", disabled: !r.value.trim(), type: "submit" }, { default: o(() => [...a[3] || (a[3] = [ V(" Continue ", -1) ])]), _: 1 }, 8, ["disabled"]) ], 32) ]), _: 1 }, 8, ["state"]) ], 64)); } }); export { ee as default };