@scalar/api-client
Version:
the open source API testing client
76 lines (75 loc) • 2.61 kB
JavaScript
import { defineComponent as _, computed as c, watch as h, createElementBlock as u, openBlock as o, normalizeClass as k, createCommentVNode as n, Fragment as x, createVNode as y, createBlock as U } from "vue";
import { REGEX as C } from "@scalar/oas-utils/helpers";
import E from "../../components/Form/Form.vue.js";
import g 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"
}
], e = c(() => {
const r = s.value.find(
(a) => a.uid === l.collectionId
);
return d[r && typeof l.serverUid == "string" && l.serverUid === "default" ? r.servers[0] ?? "" : r?.servers.find((a) => a === l.serverUid) ?? ""];
}), f = c(() => e.value?.url ? e.value.url.match(C.PATH)?.map((r) => r.slice(1, -1)) ?? [] : []);
h(
f,
(r) => {
if (!e.value)
return;
const a = e.value.variables ? { ...e.value.variables } : {};
Object.keys(a).forEach((t) => {
r.includes(t) || delete a[t];
}), r.forEach((t) => {
a[t] || (a[t] = { default: "" });
}), i.edit(e.value.uid, "variables", a);
},
{ immediate: !0 }
);
const m = (r, a) => {
!s.value || !e.value || i.edit(e.value.uid, r, a);
}, b = (r, a) => {
if (!e.value)
return;
const t = e.value.variables || {};
t[r] = { ...t[r], default: a }, i.edit(e.value.uid, "variables", t);
};
return (r, a) => (o(), u("div", {
class: k(["divide-0.5 flex w-full flex-col divide-y rounded-b-lg text-sm", e.value?.variables && "bg-b-1"])
}, [
e.value ? (o(), u(x, { key: 0 }, [
y(E, {
data: e.value,
onUpdate: m,
options: p
}, null, 8, ["data"]),
e.value.variables ? (o(), U(g, {
key: 0,
variables: e.value.variables,
"onUpdate:variable": b
}, null, 8, ["variables"])) : n("", !0)
], 64)) : n("", !0)
], 2));
}
});
export {
W as default
};