@scalar/api-client
Version:
the open source API testing client
58 lines (57 loc) • 4.03 kB
JavaScript
import { mergeObjects as d } from "@scalar/workspace-store/helpers/merge-object";
import { updateActiveProxy as u, updateColorMode as c, updateTheme as v, updateDocumentIcon as s, toggleSecurity as y, updateWatchMode as m, upsertEnvironment as h, upsertEnvironmentVariable as w, upsertCookie as O, deleteCookie as S, deleteSecurityScheme as R, updateSelectedAuthTab as f, updateSecurityScheme as k, updateSelectedScopes as q, updateSelectedSecuritySchemes as b, addServer as g, updateServer as x, deleteServer as T, updateServerVariables as C, updateSelectedServer as P, updateOperationMethod as E, updateOperationPath as A, updateOperationSummary as F, addOperationParameter as M, updateOperationParameter as V, deleteOperationParameter as W, deleteAllOperationParameters as j, updateOperationRequestBodyContentType as D, updateOperationRequestBodyExample as I, addOperationRequestBodyFormRow as z, updateOperationRequestBodyFormRow as G, deleteOperationRequestBodyFormRow as H } from "@scalar/workspace-store/mutators";
import { toValue as J } from "vue";
const Q = ({
eventBus: a,
document: o,
workspaceStore: t,
navigateTo: n,
isSidebarOpen: i
}) => {
const l = (e, r) => {
const p = J(t);
return p ? r === "document" ? e.value : p.workspace : null;
};
a.on(
"workspace:update:active-proxy",
(e) => u(t.value?.workspace ?? null, e)
), a.on(
"workspace:update:color-mode",
(e) => c(t.value?.workspace ?? null, e)
), a.on("workspace:update:theme", (e) => v(t.value?.workspace ?? null, e)), a.on("document:update:icon", (e) => s(o.value, e)), a.on("document:update:info", (e) => o.value && d(o.value.info, e)), a.on("document:toggle:security", () => y(o.value)), a.on("document:update:watch-mode", (e) => m(o.value, e)), a.on("scroll-to:nav-item", async ({ id: e }) => await n(e)), a.on("environment:upsert:environment", (e) => {
t.value && h(o.value, t.value.workspace, e);
}), a.on(
"environment:delete:environment",
({ environmentName: e, collectionType: r }) => delete l(o, r)?.["x-scalar-environments"]?.[e]
), a.on("environment:upsert:environment-variable", (e) => {
const r = l(o, e.collectionType);
w(r, e);
}), a.on(
"environment:delete:environment-variable",
({ environmentName: e, index: r, collectionType: p }) => l(o, p)?.["x-scalar-environments"]?.[e]?.variables?.splice(r, 1)
), a.on("cookie:upsert:cookie", (e) => {
const r = l(o, e.collectionType);
O(r, e);
}), a.on("cookie:delete:cookie", (e) => {
const r = l(o, e.collectionType);
S(r, e);
}), a.on("auth:delete:security-scheme", (e) => R(o.value, e)), a.on("auth:update:active-index", (e) => f(o.value, e)), a.on("auth:update:security-scheme", (e) => k(o.value, e)), a.on("auth:update:selected-scopes", (e) => q(o.value, e)), a.on(
"auth:update:selected-security-schemes",
async (e) => await b(o.value, e)
), a.on("server:add:server", () => g(o.value)), a.on("server:update:server", (e) => x(o.value, e)), a.on("server:delete:server", (e) => T(o.value, e)), a.on("server:update:variables", (e) => C(o.value, e)), a.on("server:update:selected", (e) => P(o.value, e)), a.on("operation:update:method", (e) => E(o.value, e)), a.on("operation:update:path", (e) => A(o.value, e)), a.on("operation:update:summary", (e) => F(o.value, e)), a.on("operation:add:parameter", (e) => M(o.value, e)), a.on("operation:update:parameter", (e) => V(o.value, e)), a.on("operation:delete:parameter", (e) => W(o.value, e)), a.on("operation:delete-all:parameters", (e) => j(o.value, e)), a.on(
"operation:update:requestBody:contentType",
(e) => D(o.value, e)
), a.on(
"operation:update:requestBody:value",
(e) => I(o.value, e)
), a.on("operation:add:requestBody:formRow", (e) => z(o.value, e)), a.on(
"operation:update:requestBody:formRow",
(e) => G(o.value, e)
), a.on(
"operation:delete:requestBody:formRow",
(e) => H(o.value, e)
), a.on("ui:toggle:sidebar", () => i.value = !i.value);
};
export {
Q as useWorkspaceClientEvents
};