blob: 0079ef354c4ff98be78767b1596c9cc381cd1b98 [file] [log] [blame]
/*!
* @license
* Copyright 2019-2020 The Go Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/import{track as n}from"../analytics/analytics";class s{constructor(){this.handlers={},document.addEventListener("keydown",e=>this.handleKeyPress(e))}on(e,t,r,a){return this.handlers[e]??=new Set,this.handlers[e].add({description:t,callback:r,...a}),this}handleKeyPress(e){for(const t of this.handlers[e.key.toLowerCase()]??new Set){if(t.target&&t.target!==e.target)return;const r=e.target;if(!t.target&&(r?.tagName==="INPUT"||r?.tagName==="SELECT"||r?.tagName==="TEXTAREA")||r?.isContentEditable||t.withMeta&&!(e.ctrlKey||e.metaKey)||!t.withMeta&&(e.ctrlKey||e.metaKey))return;n("keypress","hotkeys",`${e.key} pressed`,t.description),t.callback(e)}}}export const keyboard=new s;
//# sourceMappingURL=keyboard.js.map