@scalar/api-client
Version:
the open source API testing client
136 lines (135 loc) • 5.52 kB
JavaScript
import { defineComponent as V, computed as f, createBlock as u, openBlock as n, unref as l, withCtx as c, createElementVNode as a, createVNode as i, normalizeClass as $, toDisplayString as d, createCommentVNode as m, withModifiers as w, createTextVNode as p, createElementBlock as x, Fragment as A, renderList as B } from "vue";
import { Disclosure as O, DisclosureButton as j, DisclosurePanel as z } from "@headlessui/vue";
import { ScalarButton as v, ScalarIcon as N } from "@scalar/components";
import g from "../../../../components/DataTable/DataTableCell.vue.js";
import T from "../../../../components/DataTable/DataTableRow.vue.js";
import E from "../../../../components/DataTable/DataTableCheckbox.vue.js";
const F = { class: "flex h-fit w-full" }, I = { class: "flex-1" }, R = { class: "flex items-center gap-1.75" }, L = {
class: "grid auto-rows-auto",
style: { gridTemplateColumns: "1fr auto" }
}, M = { key: 0 }, P = { class: "font-code text-xs" }, W = /* @__PURE__ */ V({
__name: "OAuthScopesInput",
props: {
flow: {},
updateScheme: { type: Function }
},
setup(e) {
const y = f(
() => Object.entries(e.flow?.scopes ?? {}).map(([o, t]) => ({
id: o,
label: o,
description: t
}))
), r = f(() => e.flow?.selectedScopes || []);
function k(o, t) {
t ? e.updateScheme(`flows.${e.flow.type}.selectedScopes`, [
...r.value,
o
]) : e.updateScheme(
`flows.${e.flow.type}.selectedScopes`,
r.value.filter((s) => s !== o)
);
}
const h = f(
() => e.flow?.selectedScopes?.length === Object.keys(e.flow?.scopes ?? {}).length
), C = () => {
e.updateScheme(
`flows.${e.flow.type}.selectedScopes`,
Object.keys(e.flow?.scopes ?? {})
);
}, b = () => {
e.updateScheme(`flows.${e.flow.type}.selectedScopes`, []);
};
return (o, t) => (n(), u(l(g), { class: "h-auto !max-h-[initial] min-h-8 items-center" }, {
default: c(() => [
a("div", F, [
t[2] || (t[2] = a("div", { class: "text-c-1 h-full items-center" }, null, -1)),
i(l(O), {
as: "div",
class: "bl flex w-full flex-col"
}, {
default: c(() => [
i(l(j), {
class: $([
"group/scopes-accordion hover:text-c-1 flex h-auto min-h-8 cursor-pointer items-center gap-1.5 pr-2.25 pl-3 text-left",
(o.flow?.selectedScopes?.length || 0) > 0 ? "text-c-1" : "text-c-3"
])
}, {
default: c(({ open: s }) => [
a("div", I, " Scopes Selected " + d(o.flow?.selectedScopes?.length || 0) + " / " + d(Object.keys(o.flow?.scopes ?? {}).length || 0), 1),
a("div", R, [
h.value ? (n(), u(l(v), {
key: 0,
class: "pr-0.75 pl-1 transition-none",
size: "sm",
variant: "ghost",
onClick: w(b, ["stop"])
}, {
default: c(() => [...t[0] || (t[0] = [
p(" Deselect All ", -1)
])]),
_: 1
})) : m("", !0),
h.value ? m("", !0) : (n(), u(l(v), {
key: 1,
class: "pr-0.75 pl-1 transition-none",
size: "sm",
variant: "ghost",
onClick: w(C, ["stop"])
}, {
default: c(() => [...t[1] || (t[1] = [
p(" Select All ", -1)
])]),
_: 1
})),
i(l(N), {
class: "text-c-3 group-hover/scopes-accordion:text-c-2",
icon: s ? "ChevronDown" : "ChevronRight",
size: "md"
}, null, 8, ["icon"])
])
]),
_: 1
}, 8, ["class"]),
i(l(z), { as: "template" }, {
default: c(() => [
a("table", L, [
(n(!0), x(A, null, B(y.value, ({ id: s, label: D, description: S }) => (n(), u(l(T), {
key: s,
class: "text-c-2",
onClick: (U) => k(s, !r.value.includes(s))
}, {
default: c(() => [
i(l(g), { class: "hover:text-c-1 box-border !max-h-[initial] w-full cursor-pointer px-3 py-1.5" }, {
default: c(() => [
S ? (n(), x("div", M, [
a("span", P, d(D), 1),
p(" – " + d(S), 1)
])) : m("", !0)
]),
_: 2
}, 1024),
i(l(E), {
modelValue: r.value.includes(s),
"onUpdate:modelValue": () => {
}
}, null, 8, ["modelValue"])
]),
_: 2
}, 1032, ["onClick"]))), 128))
])
]),
_: 1
})
]),
_: 1
})
])
]),
_: 1
}));
}
});
export {
W as default
};