import { createContext, useContext } from 'react'; import type { ActionRegistry } from './registry'; import type { HotkeyStore } from './hotkeyStore'; /** * React context providing the action registry and hotkey store. * Used by components that need to register, search, execute, or edit actions. */ export interface ActionProviderValue { /** The action registry for registering and looking up actions */ registry: ActionRegistry; /** The hotkey store for reading and editing user overrides */ hotkeyStore: HotkeyStore; } export const ActionContext = createContext(null); /** * Hook to access the action registry and hotkey store. * Must be used within an ActionProvider. */ export function useActions(): ActionProviderValue { const ctx = useContext(ActionContext); if (!ctx) { throw new Error('useActions must be used within an ActionProvider'); } return ctx; } /** * Hook to access just the action registry. * Must be used within an ActionProvider. */ export function useActionRegistry(): ActionRegistry { return useActions().registry; } /** * Hook to access the hotkey store. * Must be used within an ActionProvider. */ export function useHotkeyStore(): HotkeyStore { return useActions().hotkeyStore; }