mirror of
https://github.com/plausible/analytics.git
synced 2024-12-19 07:31:50 +03:00
46048e50f7
* Wrap Plausible.Stats.Filters with unit tests * Parse `member` filter type * Support for `member` filter in `aggregate_time_on_page` * Support `not_member` filter type * Support `matches_member` and `not_matches_member` filters * Extract util module for React filters * Implement Combobox from scratch with no libs * Support multple filter clauses in combobox * Don't use browser / os in version label * Show highlighted option in combobox * WIP * Fix location filters outside filter modal * Align open/close behaviour with react-select * Styling updates for combobox * Add support for wildcards in Combobox * Implement keybindings for combobox * Allow free choice inputs in combobox * Rename 'Save filter' -> Apply filter * Remove TODO comment * Clean up some rebase mistakes * Rename `allowWildcard` -> `freeChoice` * Dark mode fixes * Remove hint from filter modal * Escape pipe character in filter modal * Do not allow selecting duplicate options in combobox * Escape brackets in `page_regex/1` * Fix disabled style in dark mode * Add regex fallback for safari * Show no matches found when visibleOptions is empty * Disable enter key when no visible options * Do not submit empty form fields * Remove unnecessary setOpen(true)
35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
/**
|
|
* Returns whether a keydown or keyup event should be ignored or not.
|
|
*
|
|
* Keybindings are ignored when a modifier key is pressed, for example, if the
|
|
* keybinding is <i>, but the user pressed <Ctrl-i> or <Meta-i>, the event
|
|
* should be discarded.
|
|
*
|
|
* Another case for ignoring a keybinding, is when the user is typing into a
|
|
* form, and presses the keybinding. For example, if the keybinding is <p> and
|
|
* the user types <apple>, the event should also be discarded.
|
|
*
|
|
* @param {*} event - Captured HTML DOM event
|
|
* @return {boolean} Whether the event should be ignored or not.
|
|
*
|
|
*/
|
|
export function shouldIgnoreKeypress(event) {
|
|
const modifierPressed = event.ctrlKey || event.metaKey || event.altKey || event.keyCode == 229
|
|
const isTyping = event.isComposing || event.target.tagName == "INPUT" || event.target.tagName == "TEXTAREA"
|
|
|
|
return modifierPressed || isTyping
|
|
}
|
|
|
|
/**
|
|
* Returns whether the given keybinding has been pressed and should be
|
|
* processed. Events can be ignored based on `shouldIgnoreKeypress(event)`.
|
|
*
|
|
* @param {string} keybinding - The target key to checked, e.g. `"i"`.
|
|
* @return {boolean} Whether the event should be processed or not.
|
|
*
|
|
*/
|
|
export function isKeyPressed(event, keybinding) {
|
|
const keyPressed = event.key.toLowerCase() == keybinding.toLowerCase()
|
|
return keyPressed && !shouldIgnoreKeypress(event)
|
|
}
|