UNPKG

@scalar/api-client

Version:

the open source API testing client

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