UNPKG

@tanstack/hotkeys

Version:

Type-safe, framework-agnostic keyboard hotkey management for the browser

53 lines • 2.28 kB
import { PlatformHotkeyEntries } from "./hotkey.types.js"; import { HotkeyPlatform } from "./platform.js"; /** * Resolves every hotkey of a hotkey for one platform, in order: its entry * for the platform, then its alternates. The first one is the hotkey that * labels show. An alternate without a hotkey on the platform is left out, * and so is one equal to an earlier hotkey. A chord or a sequence returns * itself, and no hotkey returns an empty array. * * Registration and formatting resolve hotkey objects themselves. Call this * to read the hotkeys yourself, such as to check each one for conflicts. * * @param hotkey - A hotkey object, or any other hotkey * @param platform - The target platform. Defaults to auto-detection. * * @example * ```ts * const redo = { * default: 'Mod+Y', * mac: 'Mod+Shift+Z', * alternates: [{ default: 'Mod+Shift+Z', mac: null }], * } as const * resolveHotkeys(redo, 'windows') // ['Mod+Y', 'Mod+Shift+Z'] * resolveHotkeys(redo, 'mac') // ['Mod+Shift+Z'] * resolveHotkeys({ default: null, alternates: ['F1', 'F2'] }, 'mac') // ['F1', 'F2'] * ``` */ export declare function resolveHotkeys<const T>(hotkey: T, platform?: HotkeyPlatform): Array<PlatformHotkeyEntries<NonNullable<T>>>; /** * Resolves the hotkeys of a hotkey object for one platform that come after * the one labels show: `resolveHotkeys` without its first hotkey. A hotkey * without alternates returns an empty array. * * Call this to list the alternates next to a label, such as in a cheat * sheet. Where the platform has only alternates, the first of them is the * label, so it is not in this list. * * @param hotkey - A hotkey object, or any other hotkey * @param platform - The target platform. Defaults to auto-detection. * * @example * ```ts * const redo = { * default: 'Mod+Y', * mac: 'Mod+Shift+Z', * alternates: [{ default: 'Mod+Shift+Z', mac: null }], * } as const * resolveHotkeyAlternates(redo, 'windows') // ['Mod+Shift+Z'] * resolveHotkeyAlternates(redo, 'mac') // [] * resolveHotkeyAlternates({ default: null, alternates: ['F1', 'F2'] }, 'mac') // ['F2'] * ``` */ export declare function resolveHotkeyAlternates<const T>(hotkey: T, platform?: HotkeyPlatform): Array<PlatformHotkeyEntries<NonNullable<T>>>;