tinky-keypress 1.0.2 → 1.3.0

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.
package/README.ja-JP.md CHANGED
@@ -84,7 +84,7 @@ const instance = render(
84
84
 
85
85
  ```typescript
86
86
  useKeypress(
87
- handler: (key: Key) => void,
87
+ handler: (key: Key, raw: string) => void,
88
88
  options: { isActive: boolean }
89
89
  ): void
90
90
  ```
package/README.md CHANGED
@@ -84,7 +84,7 @@ Hook to subscribe to keypress events.
84
84
 
85
85
  ```typescript
86
86
  useKeypress(
87
- handler: (key: Key) => void,
87
+ handler: (key: Key, raw: string) => void,
88
88
  options: { isActive: boolean }
89
89
  ): void
90
90
  ```
package/README.zh-CN.md CHANGED
@@ -84,7 +84,7 @@ const instance = render(
84
84
 
85
85
  ```typescript
86
86
  useKeypress(
87
- handler: (key: Key) => void,
87
+ handler: (key: Key, raw: string) => void,
88
88
  options: { isActive: boolean }
89
89
  ): void
90
90
  ```
@@ -1,41 +1,26 @@
1
- /** Timeout for waiting for a return after a backslash to detect escaped newlines */
2
- export declare const BACKSLASH_ENTER_TIMEOUT = 5;
3
- /** Timeout for waiting for more characters in an escape sequence */
4
- export declare const ESC_TIMEOUT = 50;
5
- /** Timeout for waiting for paste end sequence */
6
- export declare const PASTE_TIMEOUT = 30000;
7
- /** Timeout for discriminating between a fast return key and a pasted newline */
8
- export declare const FAST_RETURN_TIMEOUT = 30;
9
- /** Focus event sequences */
10
- export declare const FOCUS_IN = "\u001B[I";
11
- export declare const FOCUS_OUT = "\u001B[O";
1
+ import { type Key, type KeypressHandler } from "../utils/keypress.js";
2
+ export type { Key, KeypressHandler };
12
3
  /**
13
- * Represents a parsed key press event.
4
+ * Interface defining the shape of the Keypress context value.
5
+ * Used for subscribing to and unsubscribing from keypress events.
14
6
  */
15
- export interface Key {
16
- name: string;
17
- ctrl: boolean;
18
- meta: boolean;
19
- shift: boolean;
20
- insertable: boolean;
21
- sequence: string;
22
- }
23
- /**
24
- * Handler function type for keypress events.
25
- */
26
- export type KeypressHandler = (key: Key) => void;
27
7
  export interface KeypressContextValue {
8
+ /**
9
+ * Registers a handler function to be called when a keypress event occurs.
10
+ * @param handler - The function to call with the parsed Key object and raw sequence.
11
+ */
28
12
  subscribe: (handler: KeypressHandler) => void;
13
+ /**
14
+ * Unregisters a previously registered handler function.
15
+ * @param handler - The handler function to remove.
16
+ */
29
17
  unsubscribe: (handler: KeypressHandler) => void;
30
18
  }
31
19
  /**
32
- * Hook to access the Keypress context.
33
- * Allows components to subscribe and unsubscribe to keypress events.
34
- *
35
- * @returns The Keypress context value containing subscribe and unsubscribe methods.
36
- * @throws Error if used outside of a KeypressProvider.
20
+ * React Context for handling keypress events.
21
+ * Provides mechanisms to subscribe to global key input events processed from stdin.
37
22
  */
38
- export declare function useKeypressContext(): KeypressContextValue;
23
+ export declare const KeypressContext: import("react").Context<KeypressContextValue | undefined>;
39
24
  /**
40
25
  * Provider component for the Keypress context.
41
26
  * Manages stdin data listening and parsing, and broadcasts key events to subscribers.