Skip to content

Components Reference

registerComponents()

Register all web components. Call once at startup.

ts
function registerComponents(): void
js
import { registerComponents } from 'keybinds'
registerComponents()

CommandPalette

Custom element: <command-palette>

Properties

PropertyTypeDescription
commandsCommand[]Commands to display and execute
contextobjectContext for when evaluation
openbooleanVisibility state

Attributes

AttributeTypeDescription
openbooleanWhen present, palette is visible
auto-triggerbooleanEnable $mod+K keyboard trigger
placeholderstringInput placeholder text (default: "Type a command...")

Events

EventDetailDescription
execute{ command: Command }Command was executed
close-Palette was dismissed

CSS Parts

PartElement
paletteRoot .palette div
backdropOverlay div
dialogMain dialog container
inputSearch input
listResults ul
itemResult li
item-activeSelected result
item-disabledInactive result
item-labelLabel span
item-descriptionDescription span
item-categoryCategory span
item-keyShortcut kbd
emptyNo results message

Keyboard Navigation

KeyAction
/ Navigate results (wraps around)
Home / EndJump to first / last result
EnterExecute selected
EscapeClose palette

Keyboard and pointer input are tracked separately — moving the mouse won't hijack an in-progress keyboard selection until the pointer deliberately moves again.


KeybindCheatsheet

Custom element: <keybind-cheatsheet>

Properties

PropertyTypeDescription
commandsCommand[]Commands to display
contextobjectContext for when evaluation
openbooleanVisibility state

Attributes

AttributeTypeDescription
openbooleanWhen present, cheatsheet is visible
auto-triggerbooleanEnable hold-Control trigger (200ms)

Events

EventDescription
closeCheatsheet was dismissed

CSS Parts

PartElement
cheatsheetRoot div
backdropOverlay div
dialogMain dialog container
groupCategory group div
group-titleCategory heading
listCommands ul
itemCommand li
item-disabledInactive command
item-labelLabel span
item-keysKeys container span
item-keyIndividual kbd

KeybindSettings

Custom element: <keybind-settings>

Properties

PropertyTypeDescription
storeBindingsStoreReactive bindings store instance
openbooleanVisibility state

Attributes

AttributeTypeDescription
openbooleanWhen present, settings panel is visible

Events

EventDetailDescription
close-Settings panel was dismissed
change{ commandId, keys?, mouse? }A binding was changed
reset{ commandId? }Bindings were reset (per-command or all)

CSS Parts

PartElement
settingsRoot .settings div
backdropOverlay div
dialogMain dialog container
headerHeader container
titleTitle text
reset-allReset All button
groupCategory group div
group-titleCategory heading
listCommands ul
itemCommand li
item-labelLabel span
item-bindingsBindings container span
item-resetPer-command reset button
bindingIndividual binding span
binding-recordingBinding in recording state
binding-keysKey display container
binding-keyIndividual kbd
binding-removeRemove (×) button
item-addAdd binding container
add-keyAdd Key button
add-mouseAdd Mouse button
recording-overlayRecording prompt text
conflictConflict warning
conflict-acceptReplace button
conflict-cancelCancel button

Keyboard Navigation

KeyAction
EscapeCancel recording, or close panel

ContextMenu

Custom element: <context-menu>

Properties

PropertyTypeDescription
commandsCommand[]Commands to display and execute
contextobjectContext for when evaluation
menustringFilter to commands with matching menu tag
position{ x: number, y: number }Menu position in viewport coordinates
openbooleanVisibility state

Attributes

AttributeTypeDescription
openbooleanWhen present, menu is visible
auto-triggerbooleanListen for contextmenu on parent or target element
menustringFilter commands by menu tag
targetstringCSS selector for trigger element (defaults to parent)

Events

EventDetailDescription
execute{ command: Command }Command was executed
close-Menu was dismissed

CSS Parts

PartElement
context-menuRoot div
backdropOverlay div
listMenu ul
itemMenu item li
item-activeHighlighted item
item-disabledInactive item
separatorCategory separator
item-labelLabel span
item-keysKeys container span
item-keyIndividual kbd

Keyboard Navigation

KeyAction
/ Navigate items (wraps around)
Home / EndJump to first / last item
EnterExecute selected
EscapeClose menu

Keyboard and pointer input are tracked separately — moving the mouse won't hijack an in-progress keyboard selection until the pointer deliberately moves again.


eventToBindingString(event)

Convert a KeyboardEvent to a canonical binding string.

ts
function eventToBindingString(event: KeyboardEvent): string | null

Returns null for bare modifier presses and unknown keys. Uses $mod for the platform modifier (Meta on Mac, Ctrl elsewhere).


eventToMouseBindingString(event)

Convert a MouseEvent to a canonical binding string.

ts
function eventToMouseBindingString(event: MouseEvent): string | null

Maps button numbers to canonical names (0=click, 1=middle, 2=right).


findConflict(schema, bindingStr, type, excludeId?)

Check if a binding string conflicts with any command in a schema.

ts
function findConflict(
  schema: Schema,
  bindingStr: string,
  type: 'keys' | 'mouse',
  excludeId?: string
): { commandId: string, label: string } | null

Normalizes through parse → lookup for accurate cross-format comparison.


formatMouseParts(binding)

Format a mouse/scroll binding string into an array of display-ready parts.

ts
function formatMouseParts(binding: string): string[]
js
formatMouseParts('$mod+click')      // ["⌘", "Click"] on Mac, ["Ctrl", "Click"] elsewhere
formatMouseParts('scrollup')        // ["Scroll ↑"]
formatMouseParts('ctrl+scrolldown') // ["Ctrl", "Scroll ↓"] on Mac, ["Ctrl", "Scroll ↓"] elsewhere

filterByMenu(commands, menu, context?)

Filter commands by their menu tag for context menu display.

ts
function filterByMenu(
  commands: Command[],
  menu: string,
  context?: Record<string, unknown>
): (Command & { active: boolean })[]

Returns commands whose menu property matches (string match or array includes). Each result includes an active boolean from when evaluation. Hidden commands are excluded.

js
const items = filterByMenu(commands, 'editor', { hasSelection: true })

onModifierHold(modifiers, callback, options?)

Utility for hold-to-show behavior.

ts
function onModifierHold(
  modifiers: string | string[],
  callback: (held: boolean) => void,
  options?: { delay?: number, target?: EventTarget }
): () => void

Parameters:

ParameterTypeDefaultDescription
modifiersstring | string[]-Modifier key(s): 'Control', 'Alt', 'Shift', 'Meta'
callback(held: boolean) => void-Called with true when held, false on release
options.delaynumber200Hold duration in ms
options.targetEventTargetwindowElement to listen on

Returns: Cleanup function.

js
const cleanup = onModifierHold('Control', (held) => {
  cheatsheet.open = held
})

// Multiple modifiers (either triggers)
onModifierHold(['Control', 'Meta'], callback)

// Custom delay
onModifierHold('Alt', callback, { delay: 300 })