tinky-mouse 0.1.0 → 1.0.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.
@@ -24,10 +24,22 @@ export interface MouseContextValue {
24
24
  */
25
25
  unsubscribe: (handler: MouseHandler) => void;
26
26
  }
27
+ /**
28
+ * Context for managing mouse events.
29
+ */
27
30
  /**
28
31
  * Context for managing mouse events.
29
32
  */
30
33
  export declare const MouseContext: React.Context<MouseContextValue | undefined>;
34
+ /**
35
+ * Props for the MouseProvider component.
36
+ */
37
+ export interface MouseProviderProps {
38
+ /** The child components that will have access to the mouse context. */
39
+ children: React.ReactNode;
40
+ /** Whether to enable mouse event reporting. */
41
+ mouseEventsEnabled?: boolean;
42
+ }
31
43
  /**
32
44
  * Provider component that sets up mouse event listening and distribution.
33
45
  *
@@ -42,12 +54,5 @@ export declare const MouseContext: React.Context<MouseContextValue | undefined>;
42
54
  * ```
43
55
  *
44
56
  * @param props - The component props.
45
- * @param props.children - The child components.
46
- * @param props.mouseEventsEnabled - Whether to enable mouse event reporting. Defaults to `false` (implicit).
47
57
  */
48
- export declare function MouseProvider({ children, mouseEventsEnabled, }: {
49
- /** The child components that will have access to the mouse context. */
50
- children: React.ReactNode;
51
- /** Whether to enable mouse event reporting. */
52
- mouseEventsEnabled?: boolean;
53
- }): import("react/jsx-runtime").JSX.Element;
58
+ export declare function MouseProvider(props: MouseProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -72,6 +72,9 @@ function disableMouseEvents() {
72
72
  finally { if (e_2) throw e_2.error; }
73
73
  }
74
74
  }
75
+ /**
76
+ * Context for managing mouse events.
77
+ */
75
78
  /**
76
79
  * Context for managing mouse events.
77
80
  */
@@ -90,11 +93,9 @@ exports.MouseContext = (0, react_1.createContext)(undefined);
90
93
  * ```
91
94
  *
92
95
  * @param props - The component props.
93
- * @param props.children - The child components.
94
- * @param props.mouseEventsEnabled - Whether to enable mouse event reporting. Defaults to `false` (implicit).
95
96
  */
96
- function MouseProvider(_a) {
97
- var children = _a.children, mouseEventsEnabled = _a.mouseEventsEnabled;
97
+ function MouseProvider(props) {
98
+ var children = props.children, mouseEventsEnabled = props.mouseEventsEnabled;
98
99
  var stdin = (0, tinky_1.useStdin)().stdin;
99
100
  var subscribers = (0, react_1.useRef)(new Set()).current;
100
101
  var subscribe = (0, react_1.useCallback)(function (handler) {
package/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { MouseProvider, enableMouseEvents, disableMouseEvents, type MouseEvent, type MouseEventName, type MouseHandler, type MouseContextValue, } from "./contexts/MouseContext.js";
1
+ export { MouseProvider, enableMouseEvents, disableMouseEvents, type MouseEvent, type MouseEventName, type MouseHandler, type MouseContextValue, type MouseProviderProps, } from "./contexts/MouseContext.js";
2
2
  export { useMouseContext } from "./hooks/use-mouse-context.js";
3
3
  export { useMouse } from "./hooks/use-mouse.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinky-mouse",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "Mouse event handling for tinky applications",
5
5
  "keywords": [
6
6
  "tinky",
@@ -1,4 +0,0 @@
1
- import type { MouseHandler } from "../utils/mouse.js";
2
- export declare function useMouse(handler: MouseHandler, { isActive }?: {
3
- isActive?: boolean | undefined;
4
- }): void;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMouse = useMouse;
4
- var react_1 = require("react");
5
- var useMouseContext_js_1 = require("./useMouseContext.js");
6
- function useMouse(handler, _a) {
7
- var _b = _a === void 0 ? {} : _a, _c = _b.isActive, isActive = _c === void 0 ? true : _c;
8
- var _d = (0, useMouseContext_js_1.useMouseContext)(), subscribe = _d.subscribe, unsubscribe = _d.unsubscribe;
9
- (0, react_1.useEffect)(function () {
10
- if (!isActive) {
11
- return;
12
- }
13
- subscribe(handler);
14
- return function () { return unsubscribe(handler); };
15
- }, [isActive, handler, subscribe, unsubscribe]);
16
- }
@@ -1 +0,0 @@
1
- export declare function useMouseContext(): import("../contexts/MouseContext.js").MouseContextValue;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMouseContext = useMouseContext;
4
- var react_1 = require("react");
5
- var MouseContext_js_1 = require("../contexts/MouseContext.js");
6
- function useMouseContext() {
7
- var context = (0, react_1.useContext)(MouseContext_js_1.MouseContext);
8
- if (!context) {
9
- throw new Error("useMouseContext must be used within a MouseProvider");
10
- }
11
- return context;
12
- }
@@ -1,17 +0,0 @@
1
- import { EventEmitter } from "node:events";
2
- export declare enum AppEvent {
3
- OpenDebugConsole = "open-debug-console",
4
- OauthDisplayMessage = "oauth-display-message",
5
- Flicker = "flicker",
6
- McpClientUpdate = "mcp-client-update",
7
- SelectionWarning = "selection-warning",
8
- PasteTimeout = "paste-timeout"
9
- }
10
- export interface AppEvents {
11
- [AppEvent.OpenDebugConsole]: never[];
12
- [AppEvent.OauthDisplayMessage]: string[];
13
- [AppEvent.Flicker]: never[];
14
- [AppEvent.SelectionWarning]: never[];
15
- [AppEvent.PasteTimeout]: never[];
16
- }
17
- export declare const appEvents: EventEmitter<AppEvents>;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.appEvents = exports.AppEvent = void 0;
4
- var node_events_1 = require("node:events");
5
- var AppEvent;
6
- (function (AppEvent) {
7
- AppEvent["OpenDebugConsole"] = "open-debug-console";
8
- AppEvent["OauthDisplayMessage"] = "oauth-display-message";
9
- AppEvent["Flicker"] = "flicker";
10
- AppEvent["McpClientUpdate"] = "mcp-client-update";
11
- AppEvent["SelectionWarning"] = "selection-warning";
12
- AppEvent["PasteTimeout"] = "paste-timeout";
13
- })(AppEvent || (exports.AppEvent = AppEvent = {}));
14
- exports.appEvents = new node_events_1.EventEmitter();
@@ -1,12 +0,0 @@
1
- export declare const ESC = "\u001B";
2
- export declare const SGR_EVENT_PREFIX = "\u001B[<";
3
- export declare const X11_EVENT_PREFIX = "\u001B[M";
4
- export declare const SGR_MOUSE_REGEX: RegExp;
5
- export declare const X11_MOUSE_REGEX: RegExp;
6
- export declare function couldBeSGRMouseSequence(buffer: string): boolean;
7
- export declare function couldBeMouseSequence(buffer: string): boolean;
8
- /**
9
- * Checks if the buffer *starts* with a complete mouse sequence.
10
- * Returns the length of the sequence if matched, or 0 if not.
11
- */
12
- export declare function getMouseSequenceLength(buffer: string): number;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.X11_MOUSE_REGEX = exports.SGR_MOUSE_REGEX = exports.X11_EVENT_PREFIX = exports.SGR_EVENT_PREFIX = exports.ESC = void 0;
4
- exports.couldBeSGRMouseSequence = couldBeSGRMouseSequence;
5
- exports.couldBeMouseSequence = couldBeMouseSequence;
6
- exports.getMouseSequenceLength = getMouseSequenceLength;
7
- exports.ESC = "\u001B";
8
- exports.SGR_EVENT_PREFIX = "".concat(exports.ESC, "[<");
9
- exports.X11_EVENT_PREFIX = "".concat(exports.ESC, "[M");
10
- // eslint-disable-next-line no-control-regex
11
- exports.SGR_MOUSE_REGEX = /^\x1b\[<(\d+);(\d+);(\d+)([mM])/; // SGR mouse events
12
- // X11 is ESC [ M followed by 3 bytes.
13
- // eslint-disable-next-line no-control-regex
14
- exports.X11_MOUSE_REGEX = /^\x1b\[M([\s\S]{3})/;
15
- function couldBeSGRMouseSequence(buffer) {
16
- if (buffer.length === 0)
17
- return true;
18
- // Check if buffer is a prefix of a mouse sequence starter
19
- if (exports.SGR_EVENT_PREFIX.startsWith(buffer))
20
- return true;
21
- // Check if buffer is a mouse sequence prefix
22
- if (buffer.startsWith(exports.SGR_EVENT_PREFIX))
23
- return true;
24
- return false;
25
- }
26
- function couldBeMouseSequence(buffer) {
27
- if (buffer.length === 0)
28
- return true;
29
- // Check SGR prefix
30
- if (exports.SGR_EVENT_PREFIX.startsWith(buffer) ||
31
- buffer.startsWith(exports.SGR_EVENT_PREFIX))
32
- return true;
33
- // Check X11 prefix
34
- if (exports.X11_EVENT_PREFIX.startsWith(buffer) ||
35
- buffer.startsWith(exports.X11_EVENT_PREFIX))
36
- return true;
37
- return false;
38
- }
39
- /**
40
- * Checks if the buffer *starts* with a complete mouse sequence.
41
- * Returns the length of the sequence if matched, or 0 if not.
42
- */
43
- function getMouseSequenceLength(buffer) {
44
- var sgrMatch = buffer.match(exports.SGR_MOUSE_REGEX);
45
- if (sgrMatch)
46
- return sgrMatch[0].length;
47
- var x11Match = buffer.match(exports.X11_MOUSE_REGEX);
48
- if (x11Match)
49
- return x11Match[0].length;
50
- return 0;
51
- }