Repository navigation
Releases
Releases · mrpiotr-dev/shortcutter
shortcutter 0.4.0
Minor Changes
-
Key labels, type-checked shortcuts and pressed-keys hooks.
New
shortcutter/format:formatShortcut()andformatKeys()turn a shortcut or thekeysof ashortcuts()entry into the labels people expect:⇧⌘Kon macOS,Ctrl+Shift+Kelsewhere. Arrows, punctuation, numpad keys and wildcards get readable labels, andlabels/separatorcustomise them. An optional entry (about 0.7 kB gzipped), also asdist/format.iife.js(window.ShortcutterFormat).- Literal shortcut strings are type-checked:
listen('Ctlr+K', …)orlisten('Control+/', …)(the key isSlash) is a TypeScript error naming the unknown key, instead of a shortcut that never fires. This coverslisten,unlisten,isPressed,resolve,sequences.listen, the formatters and every adapter hook and attachment. Shortcuts instringvariables are not checked. New types:ShortcutString<S>,SequenceString<S>andKeyName. - Pressed-keys hooks:
usePressedKeys()in@shortcutter/react,@shortcutter/vueand@shortcutter/svelte, andcreatePressedKeys()in@shortcutter/solid, for HUDs, key visualizers and games.
Upgrading
Code that passes an invalid literal shortcut now fails to type-check. Such shortcuts never fired, so fix the key name (the error says which one) or pass a
string.
Packages (all 0.4.0, released together)
shortcutter 0.3.0
Minor Changes
-
A rewrite of the API, with framework adapters, optional sequences and a new toolchain. Breaking: see "Migrating from 0.2" in the README.
Breaking changes
useShortcutter()is replaced bycreateShortcutter(), andeventTargetbytarget.- Shortcuts are strings such as
'ControlOrMeta+K'instead of key arrays:listen('Control+K', handler, { context, phases })instead oflisten('ctx', ['controlleft', 'k'], handler, PHASES.DOWN). PHASESis removed: phases are'down','press'and'up', or an array of them. The default is now'down'only (was down and press).- Handlers get
(event, { phase, shortcut, pattern, context, description })instead of(event, phase). setActiveContext()/getActiveContext()are replaced bycontexts.activate(...names),contexts.active()andcontexts.isActive(name).- Listeners are no longer removed on
unload: calldestroy()or pass asignal. 'down'no longer fires again for the keys left after one is released.
New
- Case- and order-insensitive shortcut strings with aliases (
Ctrl,Cmd,Option,Esc, …), left/right modifiers matched alike, andControlOrMeta(⌘ on macOS, Ctrl elsewhere). - Wildcards:
'Shift+Arrow*','Digit*','Key*','F*','Control+*'. descriptionon shortcuts andshortcuts()to build keyboard help screens;resolve()for platform keys.isPressed(),pressed(),subscribe()andobserve()for held keys and every key phase (key visualizers, games).- Optional key sequences (
'G I') fromshortcutter/sequences, also asdist/sequences.iife.js. - Input guard (form fields, contenteditable, IME),
preventDefaultoption, SSR-safe import,destroy()andsignal. - Framework adapters:
@shortcutter/react,@shortcutter/vue,@shortcutter/svelteand@shortcutter/solid, with sequence hooks.
Fixes
- Keys no longer stay pressed after Cmd on macOS, after switching windows or tabs, or after leaving the page; modifiers pressed or released outside the page are corrected from the event flags.
listen()no longer sorts the caller's key array in place.
Package
- ESM, CommonJS and a minified
<script>build (window.Shortcutter), with types for both module systems; zero dependencies, tree-shakeable, under 3 kB gzipped.
Packages (all 0.3.0, released together)