UNPKG

@scalar/api-client

Version:

the open source API testing client

116 lines (115 loc) 4.02 kB
import { defineComponent as y, ref as b, computed as i, createBlock as B, openBlock as N, withCtx as r, createVNode as n, createElementVNode as m, unref as l, toDisplayString as d, createTextVNode as D, normalizeClass as I } from "vue"; import { ScalarListbox as $, ScalarButton as K, ScalarIcon as R } from "@scalar/components"; import { useRouter as U } from "vue-router"; import j from "../../../blocks/operation-code-sample/components/HttpMethod.vue.js"; import z from "./CommandActionForm.vue.js"; import E from "./CommandActionInput.vue.js"; import { getOperationFromCurl as k } from "../helpers/get-operation-from-curl.js"; const O = { class: "flex flex-1 flex-col gap-2" }, T = { class: "flex h-9 flex-row items-center gap-2 rounded border p-[3px] text-sm" }, q = { class: "scroll-timeline-x whitespace-nowrap" }, F = { class: "flex items-center gap-2" }, L = { name: "CommandPaletteImportCurl" }, Q = /* @__PURE__ */ y({ ...L, props: { workspaceStore: {}, eventBus: {}, curl: {} }, emits: ["close", "back"], setup(a, { emit: w }) { const p = w, S = U(), u = b(""), c = i(() => u.value.trim()), { path: f, method: v, operation: C } = k(a.curl), x = i( () => Object.keys(a.workspaceStore.workspace.documents).map((t) => ({ id: t, label: t })) ), o = b( x.value[0] ), h = i(() => !!(!c.value || !o.value || a.workspaceStore.workspace.documents[o.value.id]?.paths?.[f]?.[v])), g = () => { const t = o.value; if (h.value || !t) return; const e = k(a.curl, c.value); a.eventBus.emit("operation:create:operation", { documentName: t.id, path: e.path, method: e.method, operation: e.operation, exampleKey: c.value, callback: (s) => { if (s) { a.workspaceStore.buildSidebar(t.id); const _ = e.path.startsWith("/") ? e.path : `/${e.path}`; S.push({ name: "example", params: { documentSlug: t.id, pathEncoded: encodeURIComponent(_), method: e.method, exampleName: c.value } }); } } }), p("close"); }, V = (t) => { p("back", t); }; return (t, e) => (N(), B(z, { disabled: h.value, onSubmit: g }, { options: r(() => [ m("div", F, [ n(l($), { modelValue: o.value, "onUpdate:modelValue": e[1] || (e[1] = (s) => o.value = s), options: x.value }, { default: r(() => [ n(l(K), { class: "hover:bg-b-2 max-h-8 w-full justify-between gap-1 p-2 text-xs", variant: "outlined" }, { default: r(() => [ m("span", { class: I(["whitespace-nowrap", o.value ? "text-c-1" : "text-c-3"]) }, d(o.value ? o.value.label : "Select Collection"), 3), n(l(R), { class: "text-c-3", icon: "ChevronDown", size: "md" }) ]), _: 1 }) ]), _: 1 }, 8, ["modelValue", "options"]) ]) ]), submit: r(() => [...e[2] || (e[2] = [ D("Import Request", -1) ])]), default: r(() => [ n(E, { modelValue: u.value, "onUpdate:modelValue": e[0] || (e[0] = (s) => u.value = s), placeholder: "Curl example key (e.g., example-1)", onDelete: V }, null, 8, ["modelValue"]), m("div", O, [ m("div", T, [ n(j, { class: "border-r-1 px-1", method: l(v) }, null, 8, ["method"]), m("span", q, d(l(C).servers?.[0]?.url || "") + d(l(f)), 1) ]) ]) ]), _: 1 }, 8, ["disabled"])); } }); export { Q as default };