@scalar/api-client
Version:
the open source API testing client
117 lines (116 loc) • 4.11 kB
JavaScript
import { defineComponent as q, ref as v, computed as R, createBlock as x, createCommentVNode as B, openBlock as n, withCtx as l, createVNode as r, createTextVNode as u, unref as m, createElementVNode as b, toDisplayString as k, createElementBlock as P, Fragment as W, renderList as $ } from "vue";
import { ScalarDropdown as I, ScalarButton as j, ScalarIcon as z, ScalarDropdownItem as M } from "@scalar/components";
import { isDefined as T } from "@scalar/oas-utils/helpers";
import { useToasts as U } from "@scalar/use-toasts";
import { useRouter as A } from "vue-router";
import h from "../HttpMethod/HttpMethod.vue.js";
import { PathId as i } from "../../routes.js";
import { useActiveEntities as F } from "../../store/active-entities.js";
import H from "./CommandActionForm.vue.js";
import L from "./CommandActionInput.vue.js";
import { useWorkspace as O } from "../../store/store.js";
const G = { class: "flex items-center gap-2" }, J = { class: "custom-scroll max-h-40" }, me = /* @__PURE__ */ q({
__name: "CommandPaletteExample",
props: {
metaData: {}
},
emits: ["close", "back"],
setup(_, { emit: C }) {
const E = _, c = C, { push: w } = A(), { activeRequest: D, activeWorkspace: S, activeWorkspaceRequests: g } = F(), { requests: p, requestExampleMutators: y } = O(), { toast: d } = U(), s = v(""), t = v(
// Ensure we pre-select the correct request
p[E.metaData?.itemUid ?? ""] ?? D.value
), f = (o) => t.value = o, N = () => {
if (!s.value) {
d("Please enter a name before creating an example.", "error");
return;
}
if (!t.value) {
d("Please select a request before creating an example.", "error");
return;
}
const o = y.add(
t.value,
s.value
);
o && (w({
name: "request.examples",
params: {
[i.Workspace]: S.value?.uid,
[i.Request]: t.value.uid,
[i.Examples]: o.uid
}
}), c("close"));
}, V = R(
() => g.value.map((o) => p?.[o]).filter(T)
);
return (o, a) => t.value ? (n(), x(H, {
key: 0,
disabled: !s.value.trim(),
onSubmit: N
}, {
options: l(() => [
r(m(I), {
placement: "bottom",
resize: ""
}, {
items: l(() => [
b("div", J, [
(n(!0), P(W, null, $(V.value, (e) => (n(), x(m(M), {
key: e.uid,
class: "flex h-7 w-full items-center justify-between px-1 pr-[26px]",
onClick: (K) => f(e)
}, {
default: l(() => [
u(k(e.summary) + " ", 1),
r(h, {
method: e.method
}, null, 8, ["method"])
]),
_: 2
}, 1032, ["onClick"]))), 128))
])
]),
default: l(() => [
r(m(j), {
class: "hover:bg-b-2 max-h-8 w-full justify-between gap-1 p-2 text-xs",
variant: "outlined",
onClick: a[2] || (a[2] = (e) => f(t.value))
}, {
default: l(() => [
u(k(t.value.summary) + " ", 1),
b("div", G, [
r(h, {
method: t.value.method
}, null, 8, ["method"]),
r(m(z), {
class: "text-c-3",
icon: "ChevronDown",
size: "md"
})
])
]),
_: 1
})
]),
_: 1
})
]),
submit: l(() => [...a[3] || (a[3] = [
u("Create Example", -1)
])]),
default: l(() => [
r(L, {
modelValue: s.value,
"onUpdate:modelValue": a[0] || (a[0] = (e) => s.value = e),
label: "Example Name",
placeholder: "Example Name",
onOnDelete: a[1] || (a[1] = (e) => c("back", e))
}, null, 8, ["modelValue"])
]),
_: 1
}, 8, ["disabled"])) : B("", !0);
}
});
export {
me as default
};