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