UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

41 lines (40 loc) 1.89 kB
import { safeLocalStorage as v, REFERENCE_LS_KEYS as d } from "@scalar/helpers/object/local-storage"; import { generateClientMutators as u } from "@scalar/workspace-store/client"; import { onCustomEvent as c } from "@scalar/workspace-store/events"; const p = (r, t) => { const i = u(r); c(t, "scalar-update-dark-mode", (e) => { r.update("x-scalar-dark-mode", e.detail.value); }), c(t, "scalar-update-active-document", (e) => { r.update("x-scalar-active-document", e.detail.value); }), c(t, "scalar-update-selected-client", (e) => { r.update("x-scalar-default-client", e.detail), v().setItem(d.SELECTED_CLIENT, e.detail); }), c(t, "scalar-replace-servers", (e) => { const a = r.workspace.activeDocument; a && (a.servers = e.detail.servers, a["x-scalar-active-server"] = e.detail.servers.at(-1)?.url); }), c(t, "scalar-update-selected-server", (e) => { const a = r.workspace.activeDocument; a && (a["x-scalar-active-server"] = e.detail.value); }), c(t, "store-update-selected-server-properties", (e) => { const a = r.workspace.activeDocument; if (!a) return; const s = a.servers?.find((l) => l.url === a["x-scalar-active-server"]); s && (s[e.detail.key] = e.detail.value); }), c(t, "scalar-update-selected-server-variables", (e) => { const a = r.workspace.activeDocument; if (!a) return; const s = a.servers?.find((l) => l.url === a["x-scalar-active-server"]); s && s.variables?.[e.detail.key] && (s.variables[e.detail.key].default = e.detail.value); }), c(t, "scalar-add-server", (e) => { i.active().serverMutators.addServer(e.detail.server); const a = r.workspace.activeDocument; a && (a["x-scalar-active-server"] = e.detail.server.url); }), c(t, "scalar-delete-server", (e) => { i.active().serverMutators.deleteServer(e.detail.url); }); }; export { p as useWorkspaceStoreEvents };