UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

66 lines (65 loc) 2.47 kB
import { defineComponent as h, ref as S, watch as k, nextTick as w, onMounted as C, onBeforeUnmount as M, createElementBlock as a, openBlock as r, Fragment as s, createVNode as u, unref as l, normalizeClass as v, withCtx as m, createElementVNode as n, createTextVNode as B, toDisplayString as K } from "vue"; import { useModal as b, ScalarSidebarSearchButton as E } from "@scalar/components"; import { isMacOS as p } from "@scalar/helpers/general/is-mac-os"; import H from "./SearchModal.vue.js"; import { useApiClient as g } from "../../api-client-modal/useApiClient.js"; const O = /* @__PURE__ */ h({ __name: "SearchButton", props: { searchHotKey: { default: "k" }, hideModels: { type: Boolean, default: !1 }, document: {} }, setup(f) { const d = S(), t = b(), { client: c } = g(), i = (o) => { (p() ? o.metaKey : o.ctrlKey) && o.key === f.searchHotKey && !c.value?.modalState.open && (o.preventDefault(), o.stopPropagation(), t.open ? t.hide() : t.show()); }; k( () => t.open, (o, e) => { !o && e && w(() => { d.value?.$el.focus(); }); } ), C(() => window.addEventListener("keydown", i)), M(() => window.removeEventListener("keydown", i)); function y() { t.show(); } return (o, e) => (r(), a(s, null, [ u(l(E), { ref_key: "button", ref: d, class: v(["w-full", o.$attrs.class]), onClick: y }, { shortcut: m(() => [ l(p)() ? (r(), a(s, { key: 0 }, [ e[0] || (e[0] = n("span", { class: "sr-only" }, "Command", -1)), e[1] || (e[1] = n("span", { "aria-hidden": "true" }, "⌘", -1)) ], 64)) : (r(), a(s, { key: 1 }, [ e[2] || (e[2] = n("span", { class: "sr-only" }, "CTRL", -1)), e[3] || (e[3] = n("span", { "aria-hidden": "true" }, "⌃", -1)) ], 64)), B(" " + K(o.searchHotKey), 1) ]), default: m(() => [ e[4] || (e[4] = n("span", { class: "sr-only" }, "Open Search", -1)), e[5] || (e[5] = n("span", { "aria-hidden": "true", class: "sidebar-search-placeholder" }, " Search ", -1)) ]), _: 1, __: [4, 5] }, 8, ["class"]), u(H, { document: o.document, hideModels: o.hideModels, modalState: l(t) }, null, 8, ["document", "hideModels", "modalState"]) ], 64)); } }); export { O as default };