@geekmidas/ui 0.1.0 → 0.2.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.
@@ -0,0 +1,113 @@
1
+ //#region src/hooks/use-debounce.d.ts
2
+ /**
3
+ * Debounces a value by delaying updates until after a specified delay.
4
+ *
5
+ * @example
6
+ * ```tsx
7
+ * const [search, setSearch] = useState('');
8
+ * const debouncedSearch = useDebounce(search, 300);
9
+ *
10
+ * useEffect(() => {
11
+ * // Only fires 300ms after user stops typing
12
+ * fetchResults(debouncedSearch);
13
+ * }, [debouncedSearch]);
14
+ * ```
15
+ */
16
+ declare function useDebounce<T>(value: T, delay: number): T;
17
+ //#endregion
18
+ //#region src/hooks/use-local-storage.d.ts
19
+ /**
20
+ * Syncs state with localStorage, with SSR support.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const [theme, setTheme] = useLocalStorage('theme', 'dark');
25
+ *
26
+ * // Value persists across page reloads
27
+ * setTheme('light');
28
+ * ```
29
+ */
30
+ declare function useLocalStorage<T>(key: string, initialValue: T): [T, (value: T | ((prev: T) => T)) => void, () => void];
31
+ //#endregion
32
+ //#region src/hooks/use-websocket.d.ts
33
+ type WebSocketStatus = 'connecting' | 'connected' | 'disconnected';
34
+ interface UseWebSocketOptions {
35
+ /**
36
+ * Automatically reconnect on disconnect.
37
+ * @default true
38
+ */
39
+ reconnect?: boolean;
40
+ /**
41
+ * Reconnection delay in milliseconds.
42
+ * @default 3000
43
+ */
44
+ reconnectDelay?: number;
45
+ /**
46
+ * Maximum reconnection attempts.
47
+ * @default 5
48
+ */
49
+ maxReconnectAttempts?: number;
50
+ /**
51
+ * Callback when connection opens.
52
+ */
53
+ onOpen?: (event: Event) => void;
54
+ /**
55
+ * Callback when connection closes.
56
+ */
57
+ onClose?: (event: CloseEvent) => void;
58
+ /**
59
+ * Callback when an error occurs.
60
+ */
61
+ onError?: (event: Event) => void;
62
+ /**
63
+ * Callback when a message is received.
64
+ */
65
+ onMessage?: (event: MessageEvent) => void;
66
+ }
67
+ interface UseWebSocketReturn<T = unknown> {
68
+ /**
69
+ * Current connection status.
70
+ */
71
+ status: WebSocketStatus;
72
+ /**
73
+ * Last received message (parsed as JSON if possible).
74
+ */
75
+ lastMessage: T | null;
76
+ /**
77
+ * Send a message through the WebSocket.
78
+ */
79
+ send: (data: string | object) => void;
80
+ /**
81
+ * Manually connect to the WebSocket.
82
+ */
83
+ connect: () => void;
84
+ /**
85
+ * Manually disconnect from the WebSocket.
86
+ */
87
+ disconnect: () => void;
88
+ }
89
+ /**
90
+ * Hook for managing WebSocket connections with auto-reconnect.
91
+ *
92
+ * @example
93
+ * ```tsx
94
+ * const { status, lastMessage, send } = useWebSocket<LogEntry>(
95
+ * 'ws://localhost:3000/ws',
96
+ * {
97
+ * onMessage: (event) => console.log('Received:', event.data),
98
+ * }
99
+ * );
100
+ *
101
+ * // Send a message
102
+ * send({ type: 'subscribe', channel: 'logs' });
103
+ *
104
+ * // Check connection status
105
+ * if (status === 'connected') {
106
+ * // ...
107
+ * }
108
+ * ```
109
+ */
110
+ declare function useWebSocket<T = unknown>(url: string | null, options?: UseWebSocketOptions): UseWebSocketReturn<T>;
111
+ //#endregion
112
+ export { UseWebSocketOptions, UseWebSocketReturn, WebSocketStatus, useDebounce, useLocalStorage, useWebSocket };
113
+ //# sourceMappingURL=index-QNnnyGjB.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-QNnnyGjB.d.cts","names":[],"sources":["../src/hooks/use-debounce.ts","../src/hooks/use-local-storage.ts","../src/hooks/use-websocket.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;AAA0D;;;;ACH1D;;;;;AAG2B,iBDAX,WCAW,CAAA,CAAA,CAAA,CAAA,KAAA,EDAW,CCAX,EAAA,KAAA,EAAA,MAAA,CAAA,EDA8B,CCA9B;;;;ADA3B;;;;AAA0D;;;;ACH1D;;AAEe,iBAFC,eAED,CAAA,CAAA,CAAA,CAAA,GAAA,EAAA,MAAA,EAAA,YAAA,EAAA,CAAA,CAAA,EAAA,CACX,CADW,EAAA,CAAA,KAAA,EACA,CADA,GAAA,CAAA,CAAA,IAAA,EACY,CADZ,EAAA,GACkB,CADlB,CAAA,EAAA,GAAA,IAAA,EAAA,GAAA,GAAA,IAAA,CAAA;;;KCbH,eAAA;AFcI,UEZC,mBAAA,CFYU;EAAA;;;AAA+B;;;;ACH1D;;EAA+B,cAEhB,CAAA,EAAA,MAAA;EAAC;;;;EACkB,oBAAA,CAAA,EAAA,MAAA;;;;ECdtB,MAAA,CAAA,EAAA,CAAA,KAAA,EAqBM,KArBS,EAAA,GAAA,IAAA;EAEV;;;EAmBM,OAIJ,CAAA,EAAA,CAAA,KAAA,EAAA,UAAA,EAAA,GAAA,IAAA;EAAU;;AAQI;EAGhB,OAAA,CAAA,EAAA,CAAA,KAAA,EAPE,KAOgB,EAAA,GAAA,IAAA;EAAA;;;EAQpB,SAAA,CAAA,EAAA,CAAA,KAAA,EAXM,YAWN,EAAA,GAAA,IAAA;AAoCf;AAA4B,UA5CX,kBA4CW,CAAA,IAAA,OAAA,CAAA,CAAA;EAAA;;;EAGP,MAAA,EA3CZ,eA2CY;;;;eAvCP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoCE,wDAEN,sBACP,mBAAmB"}