UNPKG

@scalar/api-client

Version:

the open source API testing client

96 lines (95 loc) 3.32 kB
import { defineComponent as h, computed as c, watch as k, useTemplateRef as x, createElementBlock as v, openBlock as s, normalizeClass as C, createCommentVNode as n, Fragment as E, createVNode as S, createBlock as y } from "vue"; import { REGEX as g } from "@scalar/oas-utils/helpers"; import { emitCustomEvent as u } from "@scalar/workspace-store/events"; import w from "../../components/Form/Form.vue.js"; import O from "../../components/Server/ServerVariablesForm.vue.js"; import { useActiveEntities as B } from "../../store/active-entities.js"; import { useWorkspace as R } from "../../store/store.js"; const $ = /* @__PURE__ */ h({ __name: "CollectionServerForm", props: { collectionId: { default: "" }, serverUid: { default: "" } }, setup(p) { const l = p, { activeWorkspaceCollections: d } = B(), { servers: f, serverMutators: o } = R(), m = [ { label: "URL", key: "url", placeholder: "https://void.scalar.com", type: "text" }, { label: "Description", key: "description", placeholder: "Production", type: "text" } ], r = c(() => { const e = d.value.find( (t) => t.uid === l.collectionId ); return f[e && typeof l.serverUid == "string" && l.serverUid === "default" ? e.servers[0] ?? "" : e?.servers.find((t) => t === l.serverUid) ?? ""]; }), b = c(() => r.value?.url ? r.value.url.match(g.PATH)?.map((e) => e.slice(1, -1)) ?? [] : []); k( b, (e) => { if (!r.value) return; const t = r.value.variables ? { ...r.value.variables } : {}; Object.keys(t).forEach((a) => { e.includes(a) || delete t[a]; }), e.forEach((a) => { t[a] || (t[a] = { default: "" }); }), o.edit(r.value.uid, "variables", t), u(i.value, "store-update-selected-server-properties", { key: "variables", value: t, options: { disableOldStoreUpdate: !0 } }); }, { immediate: !0 } ); const U = (e, t) => { !d.value || !r.value || (o.edit(r.value.uid, e, t), (e === "url" || e === "description") && u(i.value, "store-update-selected-server-properties", { key: e, value: t, options: { disableOldStoreUpdate: !0 } })); }, _ = (e, t) => { if (!r.value) return; const a = r.value.variables || {}; a[e] = { ...a[e], default: t }, o.edit(r.value.uid, "variables", a), u(i.value, "store-update-selected-server-properties", { key: "variables", value: a, options: { disableOldStoreUpdate: !0 } }); }, i = x("wrapper-ref"); return (e, t) => (s(), v("div", { ref: "wrapper-ref", class: C(["divide-0.5 flex w-full flex-col divide-y rounded-b-lg text-sm", r.value?.variables && "bg-b-1"]) }, [ r.value ? (s(), v(E, { key: 0 }, [ S(w, { data: r.value, onUpdate: U, options: m }, null, 8, ["data"]), r.value.variables ? (s(), y(O, { key: 0, variables: r.value.variables, "onUpdate:variable": _ }, null, 8, ["variables"])) : n("", !0) ], 64)) : n("", !0) ], 2)); } }); export { $ as default };