本页还没有译文
本页 68 段还没译成Português (BR),下面显示的是英文原文。HotkeyRecorderController
还没翻译译自英文(tanstack.com)本页 68 段都还没译
Defined in: controllers/hotkey-recorder.ts:40
A Lit ReactiveController that records keyboard shortcuts.
Wraps the framework-agnostic HotkeyRecorder class, managing all the
complexity of capturing keyboard events, converting them to hotkey strings,
and handling edge cases like Escape to cancel or Backspace/Delete to clear.
Example
class ShortcutSettings extends LitElement {
private recorder = new HotkeyRecorderController(this, {
onRecord: (hotkey) => {
this.shortcut = hotkey
this.requestUpdate()
},
onCancel: () => {
console.log('Recording cancelled')
},
})
private shortcut: Hotkey | null = null
render() {
return html`
<button @click=${() => this.recorder.startRecording()}>
${this.recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}
</button>
${this.recorder.recordedHotkey
? html`<div>Recording: ${this.recorder.recordedHotkey}</div>`
: nothing}
`
}
}Implements
ReactiveController
Constructors
Constructor
new HotkeyRecorderController(_host, _options): HotkeyRecorderController;Defined in: controllers/hotkey-recorder.ts:65
Parameters
_host
ReactiveControllerHost
The Lit component that owns this controller.
_options
HotkeyRecorderOptions | (() => HotkeyRecorderOptions)
Options or a getter, read during recording.
Returns
HotkeyRecorderController
Accessors
isRecording
Get Signature
get isRecording(): boolean;Defined in: controllers/hotkey-recorder.ts:52
Whether recording is currently active.
Returns
boolean
recordedHotkey
Get Signature
get recordedHotkey(): Hotkey | null;Defined in: controllers/hotkey-recorder.ts:57
The currently recorded hotkey (for live preview).
Returns
Hotkey | null
Methods
cancelRecording()
cancelRecording(): void;Defined in: controllers/hotkey-recorder.ts:122
Cancel recording without saving.
Returns
void
hostConnected()
hostConnected(): void;Defined in: controllers/hotkey-recorder.ts:79
Subscribes to the recorder store and updates the internal state when changes occur.
Returns
void
Implementation of
ReactiveController.hostConnectedhostDisconnected()
hostDisconnected(): void;Defined in: controllers/hotkey-recorder.ts:98
Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks.
Returns
void
Implementation of
ReactiveController.hostDisconnectedsetOptions()
setOptions(options): void;Defined in: controllers/hotkey-recorder.ts:107
Updates the recorder options (e.g. callbacks).
Parameters
options
Partial<HotkeyRecorderOptions>
Returns
void
startRecording()
startRecording(): void;Defined in: controllers/hotkey-recorder.ts:112
Start recording a new hotkey.
Returns
void
stopRecording()
stopRecording(): void;Defined in: controllers/hotkey-recorder.ts:117
Stop recording (same as cancel but without calling onCancel).
Returns
void