UNPKG

@scalar/api-client

Version:

the open source API testing client

117 lines (116 loc) 4.41 kB
import { defineComponent as A, ref as h, computed as p, watch as v, createElementBlock as s, openBlock as o, withModifiers as z, createCommentVNode as f, createBlock as C, createVNode as b, normalizeClass as a, Fragment as V, renderList as $, createElementVNode as y, toDisplayString as O, unref as u, withCtx as S, renderSlot as B } from "vue"; import { useModal as M } from "@scalar/components"; import { isDefined as N } from "@scalar/helpers/array/is-defined"; import D from "./DeleteRequestAuthModal.vue.js"; import E from "./RequestAuthTab.vue.js"; import U from "../../../../components/DataTable/DataTable.vue.js"; import { useWorkspace as j } from "../../../../store/store.js"; const q = ["onClick"], F = { class: "relative z-10 font-medium whitespace-nowrap" }, I = { key: 0, class: "absolute inset-x-1 bottom-[var(--scalar-border-width)] left-1/2 z-1 h-px w-full -translate-x-1/2 bg-current" }, P = /* @__PURE__ */ A({ __name: "RequestAuthDataTable", props: { collection: {}, environment: {}, envVariables: {}, layout: { default: "client" }, persistAuth: { type: Boolean, default: !1 }, selectedSchemeOptions: { default: () => [] }, server: {}, workspace: {} }, emits: ["authorized", "activeSchemes"], setup(n, { emit: k }) { const m = k, { securitySchemes: g } = j(), d = M(), w = h( null ), r = h(0), i = p(() => { if (!n.selectedSchemeOptions || n.selectedSchemeOptions.length === 0) return []; const e = n.selectedSchemeOptions[r.value]; if (!e) return []; const t = e.id.split(",").filter(Boolean); return t.length > 1 ? t : [e.id]; }); v( i, (e) => { m( "activeSchemes", e.map((t) => g[t]).filter(N) ); }, { immediate: !0 } ); const x = p(() => i.value.length > 0); return v( () => n.selectedSchemeOptions, (e) => { (!e || !e[r.value]) && (r.value = Math.max(0, r.value - 1)); } ), (e, t) => (o(), s("form", { onSubmit: t[2] || (t[2] = z(() => { }, ["prevent"])) }, [ e.selectedSchemeOptions.length > 1 ? (o(), s("div", { key: 0, class: a(["box-content flex flex-wrap gap-x-2.5 overflow-hidden border border-b-0 px-3", e.layout === "client" && "border-x-0"]) }, [ (o(!0), s(V, null, $(e.selectedSchemeOptions, (l, c) => (o(), s("div", { key: l.id, class: a(["relative z-1 -mb-[var(--scalar-border-width)] flex h-8 cursor-pointer", [r.value === c ? "text-c-1" : "text-c-3"]]) }, [ y("button", { class: "floating-bg relative cursor-pointer border-b-[1px] border-transparent py-1 text-sm font-medium", type: "button", onClick: (L) => r.value = c }, [ y("span", F, O(l.label), 1) ], 8, q), r.value === c ? (o(), s("div", I)) : f("", !0) ], 2))), 128)) ], 2)) : f("", !0), x.value ? (o(), C(u(U), { key: 1, class: a(["flex-1", e.layout === "reference" && "bg-b-1 rounded-b-lg border border-t-0"]), columns: [""], presentational: "" }, { default: S(() => [ b(E, { collection: e.collection, envVariables: e.envVariables, environment: e.environment, layout: e.layout, persistAuth: e.persistAuth, securitySchemeUids: i.value, server: e.server, workspace: e.workspace, onAuthorized: t[0] || (t[0] = (l) => m("authorized")) }, { "oauth-actions": S(() => [ B(e.$slots, "oauth-actions", {}, void 0, !0) ]), _: 3 }, 8, ["collection", "envVariables", "environment", "layout", "persistAuth", "securitySchemeUids", "server", "workspace"]) ]), _: 3 }, 8, ["class"])) : (o(), s("div", { key: 2, class: a([ "text-c-3 bg-b-1 flex min-h-16 items-center justify-center border-t px-4 text-sm", e.layout === "reference" && "min-h-[calc(4rem+0.5px)] rounded-b-lg border" ]) }, " No authentication selected ", 2)), b(D, { scheme: w.value, state: u(d), onClose: t[1] || (t[1] = (l) => u(d).hide()) }, null, 8, ["scheme", "state"]) ], 32)); } }); export { P as default };