UNPKG

@scalar/api-client

Version:

the open source API testing client

190 lines (189 loc) 6.43 kB
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 b 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 k from "../../../components/code-input/CodeInput.vue.js"; const M = /* @__PURE__ */ y({ __name: "CookiesTable", props: { cookies: {}, eventBus: {}, collectionType: {} }, setup(u) { const v = ["32px", "1fr", "1fr", "1fr", "36px"], V = T(() => { const d = u.cookies.map((t) => ({ name: t.name, value: t.value, domain: t.domain ?? "", isDisabled: t.isDisabled ?? !1 })), l = u.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, i) => { const g = i >= u.cookies.length; if (!(!d && g)) { if (i >= u.cookies.length) { u.eventBus.emit("cookie:upsert:cookie", { payload: { name: d, value: l, domain: e, isDisabled: !1 }, collectionType: u.collectionType }); return; } u.eventBus.emit("cookie:upsert:cookie", { payload: { name: d, value: l, domain: e, isDisabled: t }, collectionType: u.collectionType, index: i }); } }, C = (d) => u.eventBus.emit("cookie:delete:cookie", { cookieName: u.cookies[d]?.name ?? "", index: d, collectionType: u.collectionType }); return (d, l) => (c(), p(a($), { class: "group/table data-table h-min flex-1 rounded border", columns: v }, { default: n(() => [ o(a(b), { 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(b), { key: t, class: "group/row" }, { default: n(() => [ o(a(R), { class: "!border-r", modelValue: !e.isDisabled, "onUpdate:modelValue": (i) => r(e.name, e.value, e.domain, !i, t) }, null, 8, ["modelValue", "onUpdate:modelValue"]), o(a(f), null, { default: n(() => [ o(a(k), { "aria-label": "Cookie Name", disableCloseBrackets: "", disableTabIndent: "", environment: void 0, lineWrapping: "", modelValue: e.name, placeholder: "Name", "onUpdate:modelValue": (i) => r( i, e.value, e.domain, e.isDisabled, t ) }, null, 8, ["modelValue", "onUpdate:modelValue"]) ]), _: 2 }, 1024), o(a(f), null, { default: n(() => [ o(a(k), { "aria-label": "Cookie Value", disableTabIndent: "", environment: void 0, lineWrapping: "", modelValue: e.value, placeholder: "Value", "onUpdate:modelValue": (i) => r( e.name, i, e.domain, e.isDisabled, t ) }, null, 8, ["modelValue", "onUpdate:modelValue"]) ]), _: 2 }, 1024), o(a(f), null, { default: n(() => [ o(a(k), { "aria-label": "Cookie Domain", disableCloseBrackets: "", disableTabIndent: "", environment: void 0, lineWrapping: "", modelValue: e.domain, placeholder: "Domain", "onUpdate:modelValue": (i) => r( e.name, e.value, i, e.isDisabled, t ) }, null, 8, ["modelValue", "onUpdate:modelValue"]) ]), _: 2 }, 1024), o(a(f), { class: "flex items-center justify-center" }, { default: n(() => [ t < d.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: (i) => 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 };