mokeys
v0.3.0
Published
> Shortcuts everywhere, > Mokeys brings order with ease— > Harmony through keys.
Downloads
491
Readme
mokeys
Shortcuts everywhere, Mokeys brings order with ease— Harmony through keys.
A small library for managing modal keyboard shortcuts.
Features:
- manage modal keyboard shortcuts
- global shortcuts
- support for combos
- easy config via POJO
- simple to provide custom shortcuts for users
- trigger functions via string identifiers
- composable
- library/framework agnostic
Profile
- small (~5kb, <2kb gzipped)
- fully typesafe
- 0 dependencies
- hand crafted
Kitchen Sink
All features in a single example
import { createKeymap } from "https://esm.sh/mokeys"
const keymap = createKeymap({
actions: {
next_item() { },
prev_item() { },
delete_item() { },
},
global: {
'ctrl+n': 'increment',
},
mode: {
normal: {
j: 'next_item',
k: 'prev_item',
d: 'delete_item',
v: ['mark_item', '::mode:select']
},
select: {
j: ['next_item', 'toggle_item_select'],
k: ['toggle_item_select', 'prev_item'],
d: ['delete_selection', '::mode:normal'],
}
}
}).listen(globalThis)
keymap.add('normal', 'X', () => alert('tbd'))
TODO: globals
keymap.add('a', 'action')
keymap.add({ "ctrl+b": 'action' })
// TODO: use display-name:
actions.add(function increase() {
})
actions.call('increase') // should work
// TODO
actions.call('bar', 1, 2, 3)
TODO: create add method:
keymap.add('mode', 'keys', 'action')
keymap.remove('mode', 'keys')
keymap.list()
keymap.list('mode')