@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
119 lines (118 loc) • 4.55 kB
JavaScript
import { defineComponent as T, createElementBlock as n, openBlock as o, createElementVNode as a, renderSlot as c, createCommentVNode as s, normalizeClass as B, createTextVNode as p, withModifiers as A, createVNode as g, unref as h, withCtx as f, toDisplayString as l, createBlock as O, normalizeStyle as $ } from "vue";
import { ScalarSidebarGroupToggle as E } from "@scalar/components";
import { scrollToId as N } from "@scalar/helpers/dom/scroll-to-id";
import { getHttpMethodInfo as V } from "@scalar/helpers/http/http-info";
import { sleep as b } from "@scalar/helpers/testing/sleep";
import { ScalarIconWebhooksLogo as H } from "@scalar/icons";
import { combineUrlAndPath as I } from "@scalar/oas-utils/helpers";
import { useNavState as P } from "../../../../hooks/useNavState.js";
import R from "./SidebarHttpBadge.vue.js";
const U = ["id"], D = {
key: 0,
class: "sidebar-heading-chevron"
}, L = ["aria-expanded"], M = ["href", "tabindex"], z = { class: "sidebar-heading-link-title" }, j = {
key: 0,
class: "hanging-indent"
}, F = { key: 1 }, G = {
key: 0,
class: "sidebar-heading-link-method"
}, W = {
key: 1,
class: "action-menu"
}, ee = /* @__PURE__ */ T({
__name: "SidebarElement",
props: {
id: {},
item: {},
isActive: { type: Boolean },
hasChildren: { type: Boolean },
open: { type: Boolean },
options: {}
},
emits: ["toggleOpen"],
setup(k, { emit: y }) {
const t = k, d = y, { getFullHash: m, isIntersectionEnabled: r, replaceUrlState: C } = P(), v = (e) => "path" in e ? e.path.replace(/\//g, "/") : e.title, u = async () => {
r.value = !1, t.hasChildren && d("toggleOpen"), await b(100), r.value = !0;
}, w = () => {
if (t.options.pathRouting)
return I(
t.options.pathRouting?.basePath ?? "",
t.item.id
);
if (typeof window < "u") {
const e = new URL(window.location.href);
return e.hash = m(t.item.id), `${e.search}${e.hash}`;
}
return `#${m(t.item.id)}`;
}, S = async (e) => {
t.options.onSidebarClick?.(t.item.id), t.options.pathRouting && (e.preventDefault(), t.hasChildren && d("toggleOpen"), d("toggleOpen"), r.value = !1, C(t.item.id), N(t.item.id), await b(100), r.value = !0);
};
return (e, i) => (o(), n("li", {
id: e.id,
class: "sidebar-group-item"
}, [
a("div", {
class: B(["sidebar-heading", {
"sidebar-group-item__folder": e.hasChildren,
active_page: e.isActive,
deprecated: e.item.type === "operation" && e.item.isDeprecated
}]),
onClick: u
}, [
e.hasChildren && !e.options.defaultOpenAllTags ? (o(), n("p", D, [
a("button", {
"aria-expanded": e.open,
class: "toggle-nested-icon",
type: "button",
onClick: A(u, ["stop"])
}, [
g(h(E), { open: e.open }, {
label: f(() => [
p(l(e.open ? "Collapse" : "Expand") + " " + l(e.item.title), 1)
]),
_: 1
}, 8, ["open"])
], 8, L),
i[0] || (i[0] = p(" "))
])) : s("", !0),
a("a", {
class: "sidebar-heading-link",
href: w(),
tabindex: e.hasChildren ? -1 : 0,
onClick: S
}, [
a("p", z, [
e.options.operationTitleSource === "path" ? (o(), n("span", j, l(v(e.item)), 1)) : (o(), n("span", F, l(e.item.title), 1))
]),
"method" in e.item && !e.hasChildren ? (o(), n("p", G, [
i[1] || (i[1] = p(" ")),
i[2] || (i[2] = a("span", { class: "sr-only" }, "HTTP Method: ", -1)),
g(R, {
active: e.isActive,
class: "min-w-9.75 justify-end text-right",
method: e.item.method
}, {
default: f(() => [
e.item.type === "webhook" ? (o(), O(h(H), {
key: 0,
style: $({
color: h(V)(e.item.method).colorVar
}),
weight: "bold"
}, null, 8, ["style"])) : s("", !0)
]),
_: 1
}, 8, ["active", "method"])
])) : s("", !0)
], 8, M)
], 2),
e.open ? c(e.$slots, "default", { key: 0 }, void 0, !0) : s("", !0),
e.$slots["action-menu"] ? (o(), n("div", W, [
c(e.$slots, "action-menu", {}, void 0, !0)
])) : s("", !0)
], 8, U));
}
});
export {
ee as default
};