@scalar/api-client
Version:
the open source API testing client
45 lines (44 loc) • 1.34 kB
JavaScript
import { isMacOS as a } from "@scalar/helpers/general/is-mac-os";
const f = [
"Escape",
"ArrowDown",
"ArrowUp",
"Enter",
"F1",
"F2",
"F3",
"F4",
"F5",
"F6",
"F7",
"F8",
"F9",
"F10",
"F11",
"F12"
], d = {
Escape: { event: "closeModal" },
Enter: { event: "executeRequest", modifiers: ["default"] },
b: { event: "toggleSidebar", modifiers: ["default"] },
k: { event: "openCommandPalette", modifiers: ["default"] },
l: { event: "focusAddressBar", modifiers: ["default"] }
}, c = (e) => {
if (!(e.target instanceof HTMLElement))
return !1;
const t = e.target;
return t.tagName === "INPUT" ? !f.includes(e.key) : !!(t.tagName === "TEXTAREA" || t.getAttribute("contenteditable") || t.contentEditable === "true");
}, l = {
Alt: "altKey",
Control: "ctrlKey",
Shift: "shiftKey",
Meta: "metaKey"
}, u = (e) => e.map((t) => t === "default" ? a() ? "metaKey" : "ctrlKey" : l[t]), E = (e, t, { hotKeys: o = d, modifiers: n = ["default"] } = {}) => {
const i = e.key === " " ? "Space" : e.key, r = o[i];
r && (i === "Escape" ? t.emit({ [r.event]: e }) : u(r.modifiers || n).every((s) => e[s] === !0) ? t.emit({ [r.event]: e }) : !c(e) && r.modifiers === void 0 && t.emit({ [r.event]: e }));
};
export {
d as DEFAULT_HOTKEYS,
u as getModifiers,
E as handleHotKeyDown,
c as isInput
};