Something went wrong. Try again.
A local-first note taking app
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445import { 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<ActionProviderValue | null>(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;}