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