@scalar/api-client
Version:
the open source API testing client
190 lines (189 loc) • 6.44 kB
JavaScript
import { defineComponent as y, computed as T, createBlock as p, openBlock as c, unref as a, withCtx as n, createVNode as o, createElementBlock as D, createTextVNode as s, Fragment as h, renderList as B, createCommentVNode as N } from "vue";
import { ScalarButton as U } from "@scalar/components";
import { ScalarIconTrash as I } from "@scalar/icons";
import $ from "../../../components/data-table/DataTable.vue.js";
import k from "../../../components/data-table/DataTableRow.vue.js";
import m from "../../../components/data-table/DataTableHeader.vue.js";
import R from "../../../components/data-table/DataTableCheckbox.vue.js";
import f from "../../../components/data-table/DataTableCell.vue.js";
import b from "../../../components/code-input/CodeInput.vue.js";
const M = /* @__PURE__ */ y({
__name: "CookiesTable",
props: {
cookies: {},
eventBus: {},
collectionType: {}
},
setup(i) {
const v = ["32px", "1fr", "1fr", "1fr", "36px"], V = T(() => {
const d = i.cookies.map((t) => ({
name: t.name,
value: t.value,
domain: t.domain ?? "",
isDisabled: t.isDisabled ?? !1
})), l = i.cookies.at(-1), e = l && (l.name !== "" || l.value !== "" || l.domain !== "");
return !l || e ? [
...d,
{ name: "", value: "", domain: "", isDisabled: !0 }
] : d;
}), r = (d, l, e, t, u) => {
const g = u >= i.cookies.length;
if (!(!d && g)) {
if (u >= i.cookies.length) {
i.eventBus.emit("cookie:upsert:cookie", {
payload: { name: d, value: l, domain: e, isDisabled: !1 },
collectionType: i.collectionType
});
return;
}
i.eventBus.emit("cookie:upsert:cookie", {
payload: { name: d, value: l, domain: e, isDisabled: t },
collectionType: i.collectionType,
index: u
});
}
}, C = (d) => i.eventBus.emit("cookie:delete:cookie", {
cookieName: i.cookies[d]?.name ?? "",
index: d,
collectionType: i.collectionType
});
return (d, l) => (c(), p(a($), {
class: "group/table data-table h-min flex-1 rounded border border-t-0",
columns: v
}, {
default: n(() => [
o(a(k), { class: "sr-only !block" }, {
default: n(() => [
o(a(m), null, {
default: n(() => [...l[0] || (l[0] = [
s("Enabled", -1)
])]),
_: 1
}),
o(a(m), null, {
default: n(() => [...l[1] || (l[1] = [
s("Name", -1)
])]),
_: 1
}),
o(a(m), null, {
default: n(() => [...l[2] || (l[2] = [
s("Value", -1)
])]),
_: 1
}),
o(a(m), null, {
default: n(() => [...l[3] || (l[3] = [
s("Domain", -1)
])]),
_: 1
}),
o(a(m), null, {
default: n(() => [...l[4] || (l[4] = [
s("Actions", -1)
])]),
_: 1
})
]),
_: 1
}),
(c(!0), D(h, null, B(V.value, (e, t) => (c(), p(a(k), {
key: t,
class: "group/row"
}, {
default: n(() => [
o(a(R), {
class: "!border-r",
modelValue: !e.isDisabled,
"onUpdate:modelValue": (u) => r(e.name, e.value, e.domain, !u, t)
}, null, 8, ["modelValue", "onUpdate:modelValue"]),
o(a(f), null, {
default: n(() => [
o(a(b), {
"aria-label": "Cookie Name",
disableCloseBrackets: "",
disableTabIndent: "",
environment: void 0,
lineWrapping: "",
modelValue: e.name,
placeholder: "Name",
"onUpdate:modelValue": (u) => r(
u,
e.value,
e.domain,
e.isDisabled,
t
)
}, null, 8, ["modelValue", "onUpdate:modelValue"])
]),
_: 2
}, 1024),
o(a(f), null, {
default: n(() => [
o(a(b), {
"aria-label": "Cookie Value",
disableTabIndent: "",
environment: void 0,
lineWrapping: "",
modelValue: e.value,
placeholder: "Value",
"onUpdate:modelValue": (u) => r(
e.name,
u,
e.domain,
e.isDisabled,
t
)
}, null, 8, ["modelValue", "onUpdate:modelValue"])
]),
_: 2
}, 1024),
o(a(f), null, {
default: n(() => [
o(a(b), {
"aria-label": "Cookie Domain",
disableCloseBrackets: "",
disableTabIndent: "",
environment: void 0,
lineWrapping: "",
modelValue: e.domain,
placeholder: "Domain",
"onUpdate:modelValue": (u) => r(
e.name,
e.value,
u,
e.isDisabled,
t
)
}, null, 8, ["modelValue", "onUpdate:modelValue"])
]),
_: 2
}, 1024),
o(a(f), { class: "flex items-center justify-center" }, {
default: n(() => [
t < i.cookies.length ? (c(), p(a(U), {
key: 0,
class: "text-c-2 hover:text-c-1 hover:bg-b-2 hidden h-fit rounded p-1 group-focus-within:flex group-hover/row:flex",
size: "sm",
variant: "ghost",
onClick: (u) => C(t)
}, {
default: n(() => [
o(a(I), { class: "size-3.5" })
]),
_: 1
}, 8, ["onClick"])) : N("", !0)
]),
_: 2
}, 1024)
]),
_: 2
}, 1024))), 128))
]),
_: 1
}));
}
});
export {
M as default
};