UNPKG

@scalar/api-client

Version:

the open source API testing client

144 lines (143 loc) 5.49 kB
import { defineComponent as N, ref as I, computed as A, createElementBlock as G, openBlock as H, Fragment as T, createElementVNode as r, createVNode as n, withCtx as d, toDisplayString as f, unref as v, normalizeClass as X } from "vue"; import { ScalarListbox as $, ScalarButton as J, ScalarIcon as K } from "@scalar/components"; import { REGEX as Q } from "@scalar/oas-utils/helpers"; import { useRouter as Y } from "vue-router"; import Z from "./CommandActionForm.vue.js"; import _ from "../HttpMethod/HttpMethod.vue.js"; import { useActiveEntities as ee } from "../../store/active-entities.js"; import { PathId as C } from "../../routes.js"; import { useWorkspace as te } from "../../store/store.js"; const ae = { class: "flex h-9 flex-row items-center gap-2 rounded border p-[3px] text-sm" }, le = { class: "flex h-full" }, re = { class: "scroll-timeline-x whitespace-nowrap" }, se = { class: "flex" }, ve = /* @__PURE__ */ N({ __name: "CommandPaletteImportCurl", props: { metaData: {} }, emits: ["close", "back"], setup(a, { emit: B }) { const V = B, O = te(), { activeWorkspaceCollections: h, activeCollection: W, activeWorkspace: D } = ee(), { requestMutators: L, serverMutators: M, servers: P } = O, c = I(""), j = Y(), p = A( () => h.value.map((t) => { var e; return { id: t.uid, label: ((e = t.info) == null ? void 0 : e.title) ?? "Unititled Collection" }; }) ), s = I( a.metaData.collectionUid ? p.value.find( (t) => t.id === a.metaData.collectionUid ) : p.value.find( (t) => { var e; return t.id === ((e = W.value) == null ? void 0 : e.uid); } ) ); function z({ collectionUid: t }) { var i, u, b, w, k, S, q, R, U, g; if (!a.metaData.parsedCurl) return; const e = h.value.find( (m) => m.uid === t ); if (!e) return; const l = ((i = e == null ? void 0 : e.info) == null ? void 0 : i.title) === "Drafts"; if (!l && a.metaData.parsedCurl.servers) { const m = Object.values(P).find( (F) => { var y, E; return F.url === ((E = (y = a.metaData.parsedCurl) == null ? void 0 : y.servers) == null ? void 0 : E[0]); } ); m ? c.value = m.uid : c.value = M.add( { url: a.metaData.parsedCurl.servers[0] ?? "/" }, e.uid ).uid; } const o = L.add( { summary: l ? (b = (u = a.metaData.parsedCurl) == null ? void 0 : u.url) == null ? void 0 : b.replace(Q.PROTOCOL, "") : (w = a.metaData.parsedCurl) == null ? void 0 : w.path, path: l ? (k = a.metaData.parsedCurl) == null ? void 0 : k.url : (S = a.metaData.parsedCurl) == null ? void 0 : S.path, method: (q = a.metaData.parsedCurl) == null ? void 0 : q.method, parameters: (R = a.metaData.parsedCurl) == null ? void 0 : R.parameters, selectedServerUid: l ? void 0 : c.value, requestBody: (U = a.metaData.parsedCurl) == null ? void 0 : U.requestBody }, e.uid ); o && ((g = D.value) != null && g.uid) && j.push({ name: "request", params: { [C.Workspace]: D.value.uid, [C.Collection]: e.uid, [C.Request]: o.uid } }), V("close"); } const x = () => { var t; z({ collectionUid: ((t = s.value) == null ? void 0 : t.id) ?? "" }); }; return (t, e) => (H(), G(T, null, [ e[1] || (e[1] = r("div", { class: "text-c-2 flex-center py-1.5 text-sm" }, "Import cURL", -1)), n(Z, { class: "mt-1.5 min-h-fit", onSubmit: x }, { options: d(() => [ r("div", se, [ n(v($), { modelValue: s.value, "onUpdate:modelValue": e[0] || (e[0] = (l) => s.value = l), options: p.value }, { default: d(() => [ n(v(J), { class: "hover:bg-b-2 max-h-8 w-full justify-between gap-1 p-2 text-xs", variant: "outlined" }, { default: d(() => [ r("span", { class: X(["whitespace-nowrap", s.value ? "text-c-1" : "text-c-3"]) }, f(s.value ? s.value.label : "Select Collection"), 3), n(v(K), { class: "text-c-3", icon: "ChevronDown", size: "md" }) ]), _: 1 }) ]), _: 1 }, 8, ["modelValue", "options"]) ]) ]), submit: d(() => [ r("span", { onClick: x }, "Import Request") ]), default: d(() => { var l, o, i, u; return [ r("div", ae, [ r("div", le, [ n(_, { isEditable: !1, isSquare: "", method: ((l = t.metaData.parsedCurl) == null ? void 0 : l.method) || "get" }, null, 8, ["method"]) ]), r("span", re, f(((i = (o = t.metaData.parsedCurl) == null ? void 0 : o.servers) == null ? void 0 : i[0]) || "") + f(((u = t.metaData.parsedCurl) == null ? void 0 : u.path) || ""), 1) ]) ]; }), _: 1 }) ], 64)); } }); export { ve as default };