UNPKG

@scalar/api-client

Version:

the open source API testing client

130 lines (129 loc) 4.21 kB
import { defineComponent as S, ref as C, watch as E, nextTick as b, createBlock as i, openBlock as a, unref as n, withCtx as m, createCommentVNode as l, createElementVNode as r, createVNode as u, createTextVNode as c } from "vue"; import { ScalarDropdown as M, ScalarDropdownItem as s, ScalarIcon as y, ScalarDropdownDivider as T } from "@scalar/components"; import { getParentEntry as p } from "@scalar/workspace-store/navigation"; const z = { class: "flex items-center gap-2" }, N = { class: "flex items-center gap-2" }, V = { class: "flex items-center gap-2" }, $ = { class: "text-red flex items-center gap-2" }, W = /* @__PURE__ */ S({ __name: "SidebarItemMenu", props: { item: {}, eventBus: {}, sidebarState: {}, target: {} }, emits: ["closeMenu", "showDeleteModal"], setup(e, { emit: I }) { const g = I, f = C(!1); E(f, async (d, t) => { !d && t && (await b(), g("closeMenu")); }); const v = () => e.item.type === "document" || e.item.type === "tag", x = () => e.item.type === "document", k = () => e.item.type === "operation", A = () => e.item.type === "document" && e.item.id !== "drafts" || e.item.type === "tag" || e.item.type === "operation" || e.item.type === "example", B = () => { if (e.item.type === "document" && e.eventBus.emit("ui:open:command-palette", { action: "create-request", payload: { documentId: e.item.id } }), e.item.type === "tag") { const d = e.sidebarState.getEntryById(e.item.id); e.eventBus.emit("ui:open:command-palette", { action: "create-request", payload: { documentId: p("document", d)?.id, tagId: e.item.name } }); } }, D = () => { e.item.type === "document" && e.eventBus.emit("ui:open:command-palette", { action: "add-tag", payload: { documentId: e.item.id } }); }, w = () => { if (e.item.type === "operation") { const d = e.sidebarState.getEntryById(e.item.id); e.eventBus.emit("ui:open:command-palette", { action: "add-example", payload: { documentId: p("document", d)?.id, operationId: e.item.id } }); } }; return (d, t) => (a(), i(n(M), { open: f.value, "onUpdate:open": t[4] || (t[4] = (o) => f.value = o), placement: "bottom-end", target: d.target, teleport: "" }, { items: m(() => [ v() ? (a(), i(n(s), { key: 0, onClick: t[0] || (t[0] = (o) => B()) }, { default: m(() => [ r("div", z, [ u(n(y), { icon: "Add", size: "sm" }), t[5] || (t[5] = c(" Add Operation ", -1)) ]) ]), _: 1 })) : l("", !0), x() ? (a(), i(n(s), { key: 1, onClick: t[1] || (t[1] = (o) => D()) }, { default: m(() => [ r("div", N, [ u(n(y), { icon: "Add", size: "sm" }), t[6] || (t[6] = c(" Add Tag ", -1)) ]) ]), _: 1 })) : l("", !0), k() ? (a(), i(n(s), { key: 2, onClick: t[2] || (t[2] = (o) => w()) }, { default: m(() => [ r("div", V, [ u(n(y), { icon: "Add", size: "sm" }), t[7] || (t[7] = c(" Add Example ", -1)) ]) ]), _: 1 })) : l("", !0), (k() || v() || x()) && A() ? (a(), i(n(T), { key: 3 })) : l("", !0), A() ? (a(), i(n(s), { key: 4, onClick: t[3] || (t[3] = (o) => g("showDeleteModal")) }, { default: m(() => [ r("div", $, [ u(n(y), { icon: "Delete", size: "sm" }), t[8] || (t[8] = c(" Delete ", -1)) ]) ]), _: 1 })) : l("", !0) ]), _: 1 }, 8, ["open", "target"])); } }); export { W as default };