@scalar/api-client
Version:
the open source API testing client
212 lines (211 loc) • 6.97 kB
JavaScript
import { defineComponent as U, computed as p, ref as S, watch as L, createBlock as f, openBlock as i, withCtx as m, createVNode as u, createTextVNode as V, toDisplayString as h, createElementBlock as b, unref as s, createElementVNode as k, normalizeClass as T, createCommentVNode as A, Fragment as F, renderList as K } from "vue";
import { ScalarListbox as M, ScalarButton as C, ScalarIcon as B, ScalarDropdown as P, ScalarDropdownItem as q } from "@scalar/components";
import E from "../../../blocks/operation-code-sample/components/HttpMethod.vue.js";
import G from "./CommandActionForm.vue.js";
import H from "./CommandActionInput.vue.js";
const J = {
key: 0,
class: "flex flex-1 gap-1"
}, Q = {
key: 0,
class: "text-c-1 truncate"
}, R = {
key: 1,
class: "text-c-3"
}, W = { class: "flex items-center gap-2" }, X = { class: "custom-scroll max-h-40" }, Y = { class: "truncate" }, Z = {
name: "CommandPaletteExample"
}, ne = /* @__PURE__ */ U({
...Z,
props: {
workspaceStore: {},
eventBus: {},
documentName: {},
operationId: {},
example: {}
},
emits: ["close", "back"],
setup(a, { emit: I }) {
const x = I, d = p(() => a.example !== void 0), w = S(a.example?.name ?? ""), r = p(() => w.value.trim()), N = p(
() => Object.entries(a.workspaceStore.workspace.documents).map(
([e, l]) => ({
id: e,
label: l.info.title || e
})
)
), o = S(
a.documentName ? N.value.find((e) => e.id === a.documentName) : N.value[0] ?? void 0
), g = (e) => {
const l = [];
for (const t of e)
t.type === "operation" && l.push(t), "children" in t && t.children && l.push(...g(t.children));
return l;
}, v = p(() => {
if (!o.value)
return [];
const e = a.workspaceStore.workspace.documents[o.value.id];
if (!e || !e["x-scalar-navigation"])
return [];
const l = e["x-scalar-navigation"];
return g(l.children ?? []).map((c) => ({
id: c.id,
label: `${c.method.toUpperCase()} ${c.path}`,
path: c.path,
method: c.method,
exampleNames: c.children?.filter((y) => y.type === "example").map((y) => y.name) ?? []
}));
}), n = S(
a.operationId ? v.value.find(
(e) => e.id === a.operationId
) : void 0
);
L(
o,
() => {
n.value = a.operationId ? v.value.find(
(e) => e.id === a.operationId
) : v.value[0] ?? void 0;
},
{ immediate: !0 }
);
const $ = (e) => {
e && (n.value = e);
}, D = p(() => !!(!r.value || !o.value || !n.value || d.value && a.example && r.value === a.example.name || n.value.exampleNames.some(
(e) => e === r.value && e !== a.example?.name
))), O = () => {
if (!(D.value || !o.value || !n.value)) {
if (d.value && a.example) {
a.eventBus.emit("operation:rename:example", {
documentName: o.value.id,
meta: {
path: n.value.path,
method: n.value.method,
exampleKey: a.example.name
},
payload: {
name: r.value
}
}), x("close");
return;
}
a.eventBus.emit("operation:create:draft-example", {
documentName: o.value.id,
meta: {
path: n.value.path,
method: n.value.method
},
exampleName: r.value
}), x("close");
}
}, j = (e) => {
d.value || x("back", e);
}, z = () => {
x("close");
};
return (e, l) => (i(), f(G, {
disabled: D.value,
onSubmit: O
}, {
options: m(() => [
d.value ? (i(), f(s(C), {
key: 1,
class: "max-h-8 px-3 text-xs",
variant: "outlined",
onClick: z
}, {
default: m(() => [...l[2] || (l[2] = [
V(" Cancel ", -1)
])]),
_: 1
})) : (i(), b("div", J, [
u(s(M), {
modelValue: o.value,
"onUpdate:modelValue": l[1] || (l[1] = (t) => o.value = t),
options: N.value
}, {
default: m(() => [
u(s(C), {
class: "hover:bg-b-2 max-h-8 w-[150px] min-w-[150px] justify-between gap-1 p-2 text-xs",
variant: "outlined"
}, {
default: m(() => [
k("span", {
class: T(o.value ? "text-c-1 truncate" : "text-c-3")
}, h(o.value ? o.value.label : "Select Document"), 3),
u(s(B), {
class: "text-c-3",
icon: "ChevronDown",
size: "md"
})
]),
_: 1
})
]),
_: 1
}, 8, ["modelValue", "options"]),
u(s(P), {
placement: "bottom",
resize: ""
}, {
items: m(() => [
k("div", X, [
(i(!0), b(F, null, K(v.value, (t) => (i(), f(s(q), {
key: t.id,
class: "flex h-7 w-full items-center justify-between px-1 pr-[26px]",
onClick: (c) => $(t)
}, {
default: m(() => [
k("span", Y, h(t.path), 1),
u(E, {
method: t.method
}, null, 8, ["method"])
]),
_: 2
}, 1032, ["onClick"]))), 128))
])
]),
default: m(() => [
u(s(C), {
class: "hover:bg-b-2 max-h-8 w-full justify-between gap-1 p-2 text-xs",
disabled: !v.value.length,
variant: "outlined"
}, {
default: m(() => [
n.value ? (i(), b("span", Q, h(n.value.path), 1)) : (i(), b("span", R, " Select Operation ")),
k("div", W, [
n.value ? (i(), f(E, {
key: 0,
method: n.value.method
}, null, 8, ["method"])) : A("", !0),
u(s(B), {
class: "text-c-3",
icon: "ChevronDown",
size: "md"
})
])
]),
_: 1
}, 8, ["disabled"])
]),
_: 1
})
]))
]),
submit: m(() => [
V(h(d.value ? "Save" : "Create Example"), 1)
]),
default: m(() => [
u(H, {
modelValue: w.value,
"onUpdate:modelValue": l[0] || (l[0] = (t) => w.value = t),
label: "Example Name",
placeholder: "Example Name",
onDelete: j
}, null, 8, ["modelValue"])
]),
_: 1
}, 8, ["disabled"]));
}
});
export {
ne as default
};