UNPKG

@scalar/api-client

Version:

the open source API testing client

85 lines (84 loc) 3.77 kB
import { defineComponent as O, useId as U, computed as b, useTemplateRef as C, createElementBlock as a, openBlock as n, normalizeClass as V, createElementVNode as d, createCommentVNode as S, mergeProps as q, unref as s, createVNode as p, toDisplayString as E, withModifiers as M } from "vue"; import { ScalarListboxCheckbox as I, ScalarMarkdown as N } from "@scalar/components"; import { emitCustomEvent as y } from "@scalar/workspace-store/events"; import B from "./ServerVariablesForm.vue.js"; import { useWorkspace as D } from "../../store/store.js"; const P = ["aria-expanded"], j = { class: "overflow-hidden text-ellipsis whitespace-nowrap" }, z = ["id"], L = { key: 0 }, R = { class: "description text-c-3 px-3 py-1.5" }, G = /* @__PURE__ */ O({ __name: "ServerDropdownItem", props: { collection: {}, operation: {}, server: {}, serverOption: {}, type: {} }, emits: ["update:variable"], setup(h, { emit: g }) { const e = h, k = g, c = U(), { collectionMutators: u, requestMutators: i, servers: v } = D(), x = (r, t) => { if (f(r) && t?.stopPropagation(), o.value) { e.operation?.servers?.length && i.edit(e.operation.uid, "selectedServerUid", null), e.type === "collection" ? (u.edit( e.collection.uid, "selectedServerUid", void 0 ), y(m.value, "scalar-update-selected-server", { value: void 0, options: { disableOldStoreUpdate: !0 } })) : e.type === "request" && e.operation && i.edit(e.operation.uid, "selectedServerUid", null); return; } e.type === "collection" && e.collection ? (e.operation?.servers?.length && i.edit(e.operation.uid, "selectedServerUid", null), u.edit( e.collection.uid, "selectedServerUid", r ), y(m.value, "scalar-update-selected-server", { value: v[r]?.url, options: { disableOldStoreUpdate: !0 } })) : e.type === "request" && e.operation && i.edit(e.operation.uid, "selectedServerUid", r); }, o = b(() => e.type === "collection" ? e.collection.selectedServerUid === e.serverOption.id && !e.operation?.selectedServerUid : e.type === "request" && e.operation ? e.operation.selectedServerUid === e.serverOption.id : !1), f = (r) => { if (!r) return !1; const t = v[r]; return Object.keys(t?.variables ?? {}).length > 0; }, l = b( () => o.value && f(e.server?.uid ?? "") ), w = (r, t) => { k("update:variable", r, t); }, m = C("wrapper-ref"); return (r, t) => (n(), a("div", { ref: "wrapper-ref", class: V(["group/item flex min-h-fit flex-col rounded border", { "border-transparent": !o.value }]) }, [ d("button", q(l.value ? { "aria-controls": s(c) } : {}, { "aria-expanded": l.value, class: ["flex min-h-8 cursor-pointer items-center gap-1.5 rounded px-1.5", o.value ? "text-c-1 bg-b-2" : "hover:bg-b-2"], type: "button", onClick: t[0] || (t[0] = (_) => x(r.serverOption.id, _)) }), [ p(s(I), { selected: o.value }, null, 8, ["selected"]), d("span", j, E(r.serverOption.label), 1) ], 16, P), l.value ? (n(), a("div", { key: 0, id: s(c), class: "bg-b-2 divide divide-y rounded-b border-t *:pl-4", onClick: t[1] || (t[1] = M(() => { }, ["stop"])) }, [ p(B, { variables: r.server?.variables, "onUpdate:variable": w }, null, 8, ["variables"]), r.server?.description ? (n(), a("div", L, [ d("div", R, [ p(s(N), { value: r.server.description }, null, 8, ["value"]) ]) ])) : S("", !0) ], 8, z)) : S("", !0) ], 2)); } }); export { G as default };