UNPKG

@scalar/api-client

Version:

the open source API testing client

56 lines (55 loc) 2.33 kB
import { defineComponent as f, ref as v, useId as h, watch as w, nextTick as y, onBeforeMount as _, onMounted as k, onBeforeUnmount as C, withDirectives as E, createElementBlock as T, openBlock as x, createElementVNode as n, unref as t, createVNode as d, withCtx as K, vShow as F } from "vue"; import { addScalarClassesToHeadless as M, ScalarTeleportRoot as B } from "@scalar/components"; import { useFocusTrap as P } from "@vueuse/integrations/useFocusTrap"; import { RouterView as S } from "vue-router"; import { useActiveEntities as b } from "../../store/active-entities.js"; import { useWorkspace as A } from "../../store/store.js"; import { handleHotKeyDown as D } from "../../libs/hot-keys.js"; const V = { class: "scalar scalar-app" }, $ = { class: "scalar-container" }, g = ["id"], q = /* @__PURE__ */ f({ __name: "ApiClientModal", setup(H) { const { activeWorkspace: m } = b(), { modalState: o, events: a } = A(), r = v(null), l = h(), { activate: u, deactivate: p } = P(r, { allowOutsideClick: !0, fallbackFocus: `#${l}` }), s = (e) => D(e, a.hotKeys, m.value?.hotKeyConfig); w( () => o.open, (e) => { e ? (window.addEventListener("keydown", s), document.documentElement.style.overflow = "hidden", u({ checkCanFocusTrap: () => y() })) : (window.removeEventListener("keydown", s), document.documentElement.style.removeProperty("overflow"), p()); } ), _(() => M()); const c = (e) => e?.closeModal && o.open && o.hide(); return k(() => a.hotKeys.on(c)), C(() => { document.documentElement.style.removeProperty("overflow"), a.hotKeys.off(c); }), (e, i) => E((x(), T("div", V, [ n("div", $, [ n("div", { id: t(l), ref_key: "client", ref: r, "aria-label": "API Client", "aria-modal": "true", class: "scalar-app-layout scalar-client", role: "dialog", tabindex: "-1" }, [ d(t(B), null, { default: K(() => [ d(t(S), { key: "$route.fullPath" }) ]), _: 1 }) ], 8, g), n("div", { class: "scalar-app-exit", onClick: i[0] || (i[0] = (I) => t(o).hide()) }) ]) ], 512)), [ [F, t(o).open] ]); } }); export { q as default };