@scalar/api-client
Version:
the open source API testing client
163 lines (162 loc) • 5.36 kB
JavaScript
import { defineComponent as B, onMounted as K, onBeforeUnmount as L, computed as _, watch as V, createBlock as c, openBlock as s, withCtx as i, createVNode as a, unref as l, createTextVNode as b, createElementVNode as y, createElementBlock as w, Fragment as j, renderList as A, withModifiers as O } from "vue";
import { useModal as H } from "@scalar/components";
import { cookieSchema as I } from "@scalar/oas-utils/entities/cookie";
import { useRouter as R, useRoute as W } from "vue-router";
import q from "../../components/EmptyState.vue.js";
import D from "../../components/Sidebar/SidebarButton.vue.js";
import F from "../../components/Sidebar/SidebarList.vue.js";
import P from "../../components/Sidebar/SidebarListElement.vue.js";
import T from "../../components/ViewLayout/ViewLayout.vue.js";
import U from "../../components/ViewLayout/ViewLayoutContent.vue.js";
import z from "../../components/ViewLayout/ViewLayoutSection.vue.js";
import { PathId as x } from "../../routes.js";
import G from "./CookieForm.vue.js";
import J from "./CookieModal.vue.js";
import { useActiveEntities as Q } from "../../store/active-entities.js";
import { useWorkspace as X } from "../../store/store.js";
import Y from "../../components/Sidebar/Sidebar.vue.js";
const Z = { class: "flex-1" }, ee = { class: "relative mb-[.5px] last:mb-0" }, _e = /* @__PURE__ */ B({
__name: "Cookies",
setup(oe) {
const { cookies: m, cookieMutators: p, events: k, workspaceMutators: v } = X(), { activeWorkspace: n, activeCookieId: M } = Q(), r = R(), C = W(), d = H(), g = (t) => {
const o = I.parse({
name: t.name,
value: t.value,
domain: t.domain,
path: "/"
});
p.add(o), v.edit(n.value?.uid, "cookies", [
...n.value?.cookies ?? [],
o.uid
]), r.push({
name: "cookies",
params: {
cookies: o.uid
}
});
}, E = (t) => {
p.delete(t), v.edit(n.value?.uid, "cookies", [
...(n.value?.cookies ?? []).filter((e) => e !== t)
]);
const o = Object.values(m).filter(
(e) => e.uid !== t
);
if (o.length > 0) {
const e = o[o.length - 1];
e && r.push(e.uid);
} else
r.push({
name: "cookies",
params: {
[x.Cookies]: "default"
}
});
}, f = () => {
d.show();
}, h = (t) => {
t?.createNew && C.name === "cookies" && f();
}, N = (t, o) => {
const e = {
name: "cookies",
params: {
workspace: n.value?.uid ?? "default",
cookies: o
}
};
if (t.metaKey) {
const u = r.resolve(e).href;
window.open(u, "_blank");
return;
}
r.push(e);
};
K(() => k.hotKeys.on(h)), L(() => k.hotKeys.off(h));
const S = _(
() => m[M.value]
), $ = _(
() => Object.keys(m).length > 0 && S.value
);
return V(
() => C.query.openCookieModal,
(t) => {
t === "true" && f();
},
{ immediate: !0 }
), (t, o) => (s(), c(T, null, {
default: i(() => [
a(l(Y), { title: "Cookies" }, {
content: i(() => [
y("div", Z, [
a(F, null, {
default: i(() => [
(s(!0), w(j, null, A(Object.values(l(m)), (e) => (s(), w("li", {
key: e.uid,
class: "gap-1/2 flex flex-col"
}, [
y("div", ee, [
(s(), c(P, {
key: e.uid,
class: "text-xs",
isDeletable: "",
to: {
name: "cookies",
params: {
[l(x).Cookies]: e.uid
}
},
type: "cookies",
variable: { name: e.name, uid: e.uid },
warningMessage: "Are you sure you want to delete this cookie?",
onClick: O((u) => N(u, e.uid), ["prevent"]),
onDelete: (u) => E(e.uid)
}, null, 8, ["to", "variable", "onClick", "onDelete"]))
])
]))), 128))
]),
_: 1
})
])
]),
button: i(() => [
a(D, {
click: f,
hotkey: "N"
}, {
title: i(() => [...o[1] || (o[1] = [
b(" Add Cookie ", -1)
])]),
_: 1
})
]),
_: 1
}),
a(U, { class: "flex-1" }, {
default: i(() => [
$.value ? (s(), c(z, {
key: 0,
class: "*:border-b-0"
}, {
title: i(() => [...o[2] || (o[2] = [
b("Edit Cookie", -1)
])]),
default: i(() => [
a(G)
]),
_: 1
})) : (s(), c(q, { key: 1 }))
]),
_: 1
}),
a(J, {
state: l(d),
onCancel: o[0] || (o[0] = (e) => l(d).hide()),
onSubmit: g
}, null, 8, ["state"])
]),
_: 1
}));
}
});
export {
_e as default
};