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