|  | 
|  | 1 | +import { | 
|  | 2 | +  KEYBOARD_SHORTCUTS_IDS, | 
|  | 3 | +  SpectacleMode, | 
|  | 4 | +  SPECTACLE_MODES | 
|  | 5 | +} from '../../utils/constants'; | 
|  | 6 | +import useModes from '../../hooks/use-modes'; | 
|  | 7 | + | 
|  | 8 | +/** | 
|  | 9 | + * Kbar default actions, those that do not depend on dynamic logic, can be added here. | 
|  | 10 | + * To register actions dynamically use 'useRegisterActions' and make sure the action | 
|  | 11 | + * is registed within the KBarProvider. | 
|  | 12 | + * @see https://kbar.vercel.app/docs/concepts/actions | 
|  | 13 | + * Kbar action shortcuts dont seem to support all keybindings. If you need to utilize | 
|  | 14 | + * keybindings that are not supported you'll have to implement the keybinding seperately. | 
|  | 15 | + * @see useMousetrap | 
|  | 16 | + * To display keybindings that are not supported in the Kbar results, please use | 
|  | 17 | + * KEYBOARD_SHORTCUTS instead of Kbar actions 'shortcut' property. | 
|  | 18 | + * @see CommandBarResults getShortcutKeys | 
|  | 19 | + */ | 
|  | 20 | + | 
|  | 21 | +const spectacleModeDisplay = { | 
|  | 22 | +  [SPECTACLE_MODES.DEFAULT_MODE]: 'Default Mode', | 
|  | 23 | +  [SPECTACLE_MODES.PRESENTER_MODE]: 'Presenter Mode', | 
|  | 24 | +  [SPECTACLE_MODES.OVERVIEW_MODE]: 'Overview Mode', | 
|  | 25 | +  [SPECTACLE_MODES.PRINT_MODE]: 'Print Mode', | 
|  | 26 | +  [SPECTACLE_MODES.EXPORT_MODE]: 'Export Mode' | 
|  | 27 | +}; | 
|  | 28 | + | 
|  | 29 | +const getName = (currentMode: string, mode: SpectacleMode) => { | 
|  | 30 | +  const defaultMode = SPECTACLE_MODES.DEFAULT_MODE; | 
|  | 31 | + | 
|  | 32 | +  return currentMode === mode | 
|  | 33 | +    ? `← Back to ${spectacleModeDisplay[defaultMode]}` | 
|  | 34 | +    : spectacleModeDisplay[mode]; | 
|  | 35 | +}; | 
|  | 36 | + | 
|  | 37 | +const useCommandBarActions = () => { | 
|  | 38 | +  const { toggleMode, getCurrentMode } = useModes(); | 
|  | 39 | +  const currentMode = getCurrentMode(); | 
|  | 40 | +  return [ | 
|  | 41 | +    { | 
|  | 42 | +      id: KEYBOARD_SHORTCUTS_IDS.PRESENTER_MODE, | 
|  | 43 | +      name: getName(currentMode, SPECTACLE_MODES.PRESENTER_MODE), | 
|  | 44 | +      keywords: 'presenter', | 
|  | 45 | +      perform: () => toggleMode({ newMode: SPECTACLE_MODES.PRESENTER_MODE }), | 
|  | 46 | +      section: 'Mode' | 
|  | 47 | +    }, | 
|  | 48 | +    { | 
|  | 49 | +      id: KEYBOARD_SHORTCUTS_IDS.OVERVIEW_MODE, | 
|  | 50 | +      name: getName(currentMode, SPECTACLE_MODES.OVERVIEW_MODE), | 
|  | 51 | +      keywords: 'overview', | 
|  | 52 | +      perform: () => toggleMode({ newMode: SPECTACLE_MODES.OVERVIEW_MODE }), | 
|  | 53 | +      section: 'Mode' | 
|  | 54 | +    }, | 
|  | 55 | +    { | 
|  | 56 | +      id: KEYBOARD_SHORTCUTS_IDS.PRINT_MODE, | 
|  | 57 | +      name: getName(currentMode, SPECTACLE_MODES.PRINT_MODE), | 
|  | 58 | +      keywords: 'export', | 
|  | 59 | +      perform: () => toggleMode({ newMode: SPECTACLE_MODES.PRINT_MODE }), | 
|  | 60 | +      section: 'Mode' | 
|  | 61 | +    }, | 
|  | 62 | +    { | 
|  | 63 | +      id: KEYBOARD_SHORTCUTS_IDS.EXPORT_MODE, | 
|  | 64 | +      name: getName(currentMode, SPECTACLE_MODES.EXPORT_MODE), | 
|  | 65 | +      keywords: 'export', | 
|  | 66 | +      perform: () => toggleMode({ newMode: SPECTACLE_MODES.EXPORT_MODE }), | 
|  | 67 | +      section: 'Mode' | 
|  | 68 | +    } | 
|  | 69 | +  ]; | 
|  | 70 | +}; | 
|  | 71 | + | 
|  | 72 | +export default useCommandBarActions; | 
0 commit comments