import { createHotkeyBindings, prepareHotkeyDefinitions, } from '@tanstack/hotkeys/adapter' import { read } from './scope' import type { HotkeysScope } from './scope' import type { AlpineHotkeyCommonOptions, AlpineHotkeyDefinition, MaybeGetter, } from './types' export function createHotkeys( scope: HotkeysScope, definitions: MaybeGetter>, options: MaybeGetter = {}, ) { scope.assertActive() const bindings = createHotkeyBindings() scope.addCleanup(bindings.destroy) scope.effect(() => bindings.update( prepareHotkeyDefinitions(read(definitions), { appHotkeysStore: scope.appHotkeys(), defaults: scope.defaultOptions().hotkey, commonOptions: read(options), // A null target skips registration until it is set. resolveTarget: (target) => target, }), ), ) }