@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
73 lines (72 loc) • 2.85 kB
JavaScript
import { defineComponent as I, computed as u, ref as A, createElementBlock as c, createCommentVNode as v, openBlock as a, createElementVNode as C, Fragment as p, renderList as g, createBlock as h, createVNode as y, unref as S, withCtx as L, createTextVNode as V, normalizeClass as D, toDisplayString as B } from "vue";
import { ScalarButton as T } from "@scalar/components";
import { ScalarIconPlus as H } from "@scalar/icons";
import { getResolvedRef as P } from "@scalar/workspace-store/helpers/get-resolved-ref";
import { isArraySchema as _ } from "@scalar/workspace-store/schemas/v3.1/strict/type-guards";
import E from "./SchemaEnumPropertyItem.vue.js";
const $ = {
key: 0,
class: "property-enum"
}, w = { class: "property-enum-values" }, R = { key: 1 }, U = 9, O = 5, N = " ", q = /* @__PURE__ */ I({
__name: "SchemaEnumValues",
props: {
value: {}
},
setup(t) {
const n = u(() => t.value ? t.value.enum || _(t.value) && P(t.value.items)?.enum || [] : []), m = u(
() => n.value.length > U
), s = u(
() => m.value ? O : n.value.length
), b = u(
() => n.value.slice(0, s.value)
), k = u(
() => n.value.slice(s.value)
), d = (o, i) => {
const e = t.value?.["x-enumDescriptions"] ?? t.value?.["x-enum-descriptions"];
if (e) {
if (Array.isArray(e))
return e[i];
if (typeof e == "object" && e !== null)
return e[String(o)];
}
}, f = (o, i) => {
const e = t.value?.["x-enum-varnames"] ?? t.value?.["x-enumNames"], l = Array.isArray(e) ? e[i] : void 0;
return l ? `${o}${N}=${N}${l}` : String(o);
}, r = A(!1), x = () => {
r.value = !r.value;
};
return (o, i) => n.value.length > 0 ? (a(), c("div", $, [
C("ul", w, [
(a(!0), c(p, null, g(b.value, (e, l) => (a(), h(E, {
key: String(e),
description: d(e, l),
label: f(e, l)
}, null, 8, ["description", "label"]))), 128)),
m.value && r.value ? (a(!0), c(p, { key: 0 }, g(k.value, (e, l) => (a(), h(E, {
key: String(e),
description: d(e, s.value + l),
label: f(e, s.value + l)
}, null, 8, ["description", "label"]))), 128)) : v("", !0),
m.value ? (a(), c("li", R, [
y(S(T), {
class: "enum-toggle-button my-2 flex h-fit gap-1 rounded-full border py-1.5 pr-2.5 pl-2 leading-none",
variant: "ghost",
onClick: x
}, {
default: L(() => [
y(S(H), {
class: D({ "rotate-45": r.value }),
weight: "bold"
}, null, 8, ["class"]),
V(" " + B(r.value ? "Hide values" : "Show all values"), 1)
]),
_: 1
})
])) : v("", !0)
])
])) : v("", !0);
}
});
export {
q as default
};