UNPKG

@scalar/api-client

Version:

the open source API testing client

183 lines (182 loc) 6.9 kB
import { defineComponent as A, computed as L, ref as W, createElementBlock as y, openBlock as f, createElementVNode as l, createVNode as s, unref as e, withCtx as n, toDisplayString as C, Fragment as V, renderList as I, createBlock as D, withModifiers as v, createCommentVNode as O } from "vue"; import { useModal as S, ScalarDropdown as $, ScalarButton as N, ScalarDropdownItem as h, ScalarListboxCheckbox as U, ScalarIcon as k, ScalarDropdownDivider as q, ScalarModal as z } from "@scalar/components"; import { useRouter as F } from "vue-router"; import P from "../../../components/Sidebar/Actions/DeleteSidebarListElement.vue.js"; import Y from "../../../components/Sidebar/Actions/EditSidebarListElement.vue.js"; import { useActiveEntities as G } from "../../../store/active-entities.js"; import { useWorkspace as H } from "../../../store/store.js"; const J = { class: "flex w-[inherit] items-center text-base" }, K = { class: "m-0 flex items-center gap-1.5 font-bold" }, Q = { class: "line-clamp-1 text-left" }, X = { class: "overflow-hidden text-ellipsis" }, Z = { class: "flex h-4 w-4 items-center justify-center" }, re = /* @__PURE__ */ A({ __name: "WorkspaceDropdown", setup(ee) { const { activeWorkspace: c } = G(), { workspaces: r, workspaceMutators: w, events: E } = H(), { push: x } = F(), T = (o) => { o !== c.value?.uid && x({ name: "workspace", params: { workspace: o } }); }, _ = L(() => Object.keys(r).length === 1), j = () => E.commandPalette.emit({ commandName: "Create Workspace" }), d = W(""), i = W(""), u = S(), p = S(), g = (o) => { const t = r[o]; t && (d.value = t.name, i.value = o, u.show()); }, B = (o) => { o.trim() && (w.edit(i.value, "name", o.trim()), u.hide()); }, b = (o) => { const t = r[o]; t && (d.value = t.name, i.value = o, p.show()); }, R = async () => { if (!_.value) { const o = c.value?.uid === i.value, t = { ...r }; if (delete t[i.value], w.delete(i.value), o) { const a = Object.keys(t)[0]; await x({ name: "workspace", params: { workspace: a } }); } } p.hide(); }; return (o, t) => (f(), y("div", null, [ l("div", J, [ s(e($), null, { items: n(() => [ (f(!0), y(V, null, I(e(r), (a, M) => (f(), D(e(h), { key: M, class: "group/item flex w-full items-center gap-1.5 overflow-hidden text-ellipsis whitespace-nowrap", onClick: v((m) => T(a.uid), ["stop"]) }, { default: n(() => [ s(e(U), { selected: e(c)?.uid === M }, null, 8, ["selected"]), l("span", X, C(a.name), 1), s(e($), { placement: "right-start", teleport: "" }, { items: n(() => [ s(e(h), { class: "flex gap-2", onMousedown: (m) => g(a.uid), onTouchend: v((m) => g(a.uid), ["prevent"]) }, { default: n(() => [ s(e(k), { class: "inline-flex", icon: "Edit", size: "md", thickness: "1.5" }), t[2] || (t[2] = l("span", null, "Rename", -1)) ]), _: 1 }, 8, ["onMousedown", "onTouchend"]), _.value ? O("", !0) : (f(), D(e(h), { key: 0, class: "flex gap-2", onMousedown: v((m) => b(a.uid), ["prevent"]), onTouchend: v((m) => b(a.uid), ["prevent"]) }, { default: n(() => [ s(e(k), { class: "inline-flex", icon: "Delete", size: "md", thickness: "1.5" }), t[3] || (t[3] = l("span", null, "Delete", -1)) ]), _: 1 }, 8, ["onMousedown", "onTouchend"])) ]), default: n(() => [ s(e(N), { class: "hover:bg-b-3 -mr-1 ml-auto aspect-square h-fit px-0.5 py-0 group-hover/item:flex", size: "sm", type: "button", variant: "ghost" }, { default: n(() => [ s(e(k), { icon: "Ellipses", size: "sm" }) ]), _: 1 }) ]), _: 2 }, 1024) ]), _: 2 }, 1032, ["onClick"]))), 128)), s(e(q)), s(e(h), { class: "flex items-center gap-1.5", onClick: j }, { default: n(() => [ l("div", Z, [ s(e(k), { icon: "Add", size: "sm" }) ]), t[4] || (t[4] = l("span", null, "Create Workspace", -1)) ]), _: 1 }) ]), default: n(() => [ s(e(N), { class: "text-c-1 hover:bg-b-2 line-clamp-1 h-full w-fit justify-start px-1.5 py-1.5 font-normal", variant: "ghost" }, { default: n(() => [ l("div", K, [ l("h2", Q, C(e(c)?.name), 1) ]) ]), _: 1 }) ]), _: 1 }) ]), s(e(z), { size: "xxs", state: e(p), title: "Delete workspace" }, { default: n(() => [ s(P, { variableName: d.value, warningMessage: "This cannot be undone. You're about to delete the workspace and everything inside it.", onClose: t[0] || (t[0] = (a) => e(p).hide()), onDelete: R }, null, 8, ["variableName"]) ]), _: 1 }, 8, ["state"]), s(e(z), { size: "xxs", state: e(u), title: "Rename Workspace" }, { default: n(() => [ s(Y, { name: d.value, onClose: t[1] || (t[1] = (a) => e(u).hide()), onEdit: B }, null, 8, ["name"]) ]), _: 1 }, 8, ["state"]) ])); } }); export { re as default };