@acvl/frontend-components 0.0.52 → 0.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
1
  export { useHasPermission } from './users';
2
2
  export { useAPI } from './api';
3
3
  export { useNavigation } from './navigation';
4
+ export { useKeyboardShortcut, type KeyboardShortcut } from './useKeyboardShortcut';
@@ -0,0 +1,42 @@
1
+ export interface KeyboardShortcut {
2
+ /** Tecla objetivo. Se compara con `event.key` sin distinguir mayúsculas (p. ej. "f", "e", "Escape"). */
3
+ key: string;
4
+ /** Requiere Ctrl. Si se omite, la tecla Ctrl debe estar ausente. */
5
+ ctrl?: boolean;
6
+ /** Requiere Shift. Si se omite, la tecla Shift debe estar ausente. */
7
+ shift?: boolean;
8
+ /** Requiere Alt. Si se omite, la tecla Alt debe estar ausente. */
9
+ alt?: boolean;
10
+ /** Requiere Meta/Cmd. Si se omite, la tecla Meta debe estar ausente. */
11
+ meta?: boolean;
12
+ /**
13
+ * No dispara el atajo mientras el foco está en un campo editable
14
+ * (`input`, `textarea`, `select` o `contentEditable`). Evita que atajos de
15
+ * una sola letra (p. ej. `Shift+F`) se traguen la tecla al escribir.
16
+ * Por defecto `true`.
17
+ */
18
+ ignoreWhenTyping?: boolean;
19
+ /** Llama a `event.preventDefault()` al coincidir. Por defecto `true`. */
20
+ preventDefault?: boolean;
21
+ /** Permite desactivar el atajo sin desmontar el componente. Por defecto `true`. */
22
+ enabled?: boolean;
23
+ }
24
+ /**
25
+ * Registra un atajo de teclado global (listener en `document`) y ejecuta
26
+ * `handler` cuando la combinación coincide.
27
+ *
28
+ * - Compara la tecla sin distinguir mayúsculas y exige el estado exacto de los
29
+ * modificadores, de modo que `Ctrl+E` y `Ctrl+Shift+E` no colisionan entre sí.
30
+ * - Por defecto ignora el atajo mientras se escribe en un campo editable.
31
+ * - `handler` se lee siempre en su versión más reciente, así que no hace falta
32
+ * memoizarlo con `useCallback` en el componente que lo usa.
33
+ *
34
+ * Llama al hook varias veces para registrar varios atajos en un mismo componente.
35
+ *
36
+ * @example
37
+ * useKeyboardShortcut({ key: "f", shift: true }, () => setFullScreen((p) => !p));
38
+ * useKeyboardShortcut({ key: "e", ctrl: true }, () => navigate("editar"));
39
+ * useKeyboardShortcut({ key: "Escape", shift: true, enabled: edit }, cancelEdit);
40
+ */
41
+ export declare function useKeyboardShortcut(shortcut: KeyboardShortcut, handler: (event: KeyboardEvent) => void): void;
42
+ export default useKeyboardShortcut;