preact-missing-hooks 4.1.0 → 4.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.
- package/Readme.md +4 -1
- package/dist/react.js +1708 -1
- package/llm.package.json +393 -0
- package/llm.package.txt +103 -0
- package/package.json +7 -3
- package/scripts/rollup.react.config.cjs +34 -0
package/llm.package.json
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "preact-missing-hooks",
|
|
3
|
+
"version": "4.1.0",
|
|
4
|
+
"description": "A lightweight, extendable collection of missing React-like hooks for Preact — plus fresh, powerful new ones designed specifically for modern Preact apps.",
|
|
5
|
+
"exports": {
|
|
6
|
+
"useTransition": {
|
|
7
|
+
"type": "function",
|
|
8
|
+
"description": "A custom hook that wraps React's useTransition API, providing a way to mark updates as transitions to allow the browser to prioritize updates. It returns a tuple containing a boolean indicating if the transition is pending and a startTransition function to wrap state updates.",
|
|
9
|
+
"hook": true,
|
|
10
|
+
"params": "config?: { timeoutMs?: number }",
|
|
11
|
+
"returns": "[isPending: boolean, startTransition: (callback: () => void) => void]",
|
|
12
|
+
"sideEffect": false
|
|
13
|
+
},
|
|
14
|
+
"useMutationObserver": {
|
|
15
|
+
"type": "function",
|
|
16
|
+
"description": "A hook that creates and manages a MutationObserver to watch for changes in the DOM. It accepts a target element and a callback to execute when mutations are observed, returning a ref to attach to the target element.",
|
|
17
|
+
"hook": true,
|
|
18
|
+
"params": "target: Element | null, callback: MutationCallback, options?: MutationObserverInit",
|
|
19
|
+
"returns": "ref: { current: Element | null }",
|
|
20
|
+
"sideEffect": false
|
|
21
|
+
},
|
|
22
|
+
"UseMutationObserverOptions": {
|
|
23
|
+
"type": "type",
|
|
24
|
+
"description": "A TypeScript type defining the options object for the useMutationObserver hook, extending MutationObserverInit to include optional configuration for observing DOM mutations.",
|
|
25
|
+
"hook": false,
|
|
26
|
+
"params": "extends MutationObserverInit",
|
|
27
|
+
"returns": "N/A"
|
|
28
|
+
},
|
|
29
|
+
"useEventBus": {
|
|
30
|
+
"type": "function",
|
|
31
|
+
"description": "A hook that provides access to a global event bus for publishing and subscribing to events across components. It returns an object with methods to subscribe, unsubscribe, and publish events.",
|
|
32
|
+
"hook": true,
|
|
33
|
+
"params": "none",
|
|
34
|
+
"returns": "{ subscribe: (event: string, callback: Function) => void, unsubscribe: (event: string, callback: Function) => void, publish: (event: string, data: any) => void }",
|
|
35
|
+
"sideEffect": false
|
|
36
|
+
},
|
|
37
|
+
"useWrappedChildren": {
|
|
38
|
+
"type": "function",
|
|
39
|
+
"description": "A hook that wraps the children of a component with a specified wrapper component or element. It takes children and a wrapper as arguments and returns the wrapped children.",
|
|
40
|
+
"hook": true,
|
|
41
|
+
"params": "children: ReactNode, wrapper: ComponentType | string",
|
|
42
|
+
"returns": "ReactNode",
|
|
43
|
+
"sideEffect": false
|
|
44
|
+
},
|
|
45
|
+
"InjectableProps": {
|
|
46
|
+
"type": "type",
|
|
47
|
+
"description": "A TypeScript type that defines the shape of props that can be injected into a component, typically used for dependency injection or prop forwarding.",
|
|
48
|
+
"hook": false,
|
|
49
|
+
"params": "Generic type extending React.PropsWithChildren",
|
|
50
|
+
"returns": "N/A"
|
|
51
|
+
},
|
|
52
|
+
"usePreferredTheme": {
|
|
53
|
+
"type": "function",
|
|
54
|
+
"description": "A hook that detects and returns the user's preferred color scheme (light or dark) based on the operating system or browser settings. It returns the current preferred theme.",
|
|
55
|
+
"hook": true,
|
|
56
|
+
"params": "none",
|
|
57
|
+
"returns": "'light' | 'dark' | 'no-preference'",
|
|
58
|
+
"sideEffect": false
|
|
59
|
+
},
|
|
60
|
+
"PreferredTheme": {
|
|
61
|
+
"type": "type",
|
|
62
|
+
"description": "A TypeScript type that defines the possible values for a preferred theme, typically 'light', 'dark', or 'no-preference'.",
|
|
63
|
+
"hook": false,
|
|
64
|
+
"params": "N/A",
|
|
65
|
+
"returns": "'light' | 'dark' | 'no-preference'"
|
|
66
|
+
},
|
|
67
|
+
"useNetworkState": {
|
|
68
|
+
"type": "function",
|
|
69
|
+
"description": "React hook that returns the current network state of the browser, including connection type, effective connection type, and whether the device is online or offline. Useful for adapting application behavior based on network conditions, such as reducing data usage or showing offline indicators.",
|
|
70
|
+
"hook": true,
|
|
71
|
+
"params": "none",
|
|
72
|
+
"returns": "NetworkState object with online, since, downlink, downlinkMax, effectiveType, rtt, type properties",
|
|
73
|
+
"example": "const network = useNetworkState(); if (!network.online) { /* show offline message */ }"
|
|
74
|
+
},
|
|
75
|
+
"EffectiveConnectionType": {
|
|
76
|
+
"type": "type",
|
|
77
|
+
"description": "TypeScript type representing the effective connection type as defined by the Network Information API. Represents the effective connection type ('slow-2g', '2g', '3g', '4g') that the browser uses to optimize content delivery based on the user's network conditions.",
|
|
78
|
+
"hook": false
|
|
79
|
+
},
|
|
80
|
+
"ConnectionType": {
|
|
81
|
+
"type": "type",
|
|
82
|
+
"description": "TypeScript type representing the physical connection type of the device (e.g., 'wifi', 'cellular', 'ethernet', 'none', 'unknown'). Used to determine how the device is connected to the network, which can inform decisions about data usage and performance optimizations.",
|
|
83
|
+
"hook": false
|
|
84
|
+
},
|
|
85
|
+
"NetworkState": {
|
|
86
|
+
"type": "type",
|
|
87
|
+
"description": "TypeScript interface defining the structure of network state information returned by useNetworkState hook. Includes properties like online (boolean), since (Date), downlink (number), downlinkMax (number), effectiveType (EffectiveConnectionType), rtt (number), and type (ConnectionType).",
|
|
88
|
+
"hook": false
|
|
89
|
+
},
|
|
90
|
+
"useClipboard": {
|
|
91
|
+
"type": "function",
|
|
92
|
+
"description": "React hook that provides access to the system clipboard, allowing reading and writing of text content. Useful for implementing copy-to-clipboard functionality in components without requiring direct DOM manipulation or event handling.",
|
|
93
|
+
"hook": true,
|
|
94
|
+
"params": "options?: UseClipboardOptions",
|
|
95
|
+
"returns": "UseClipboardReturn object with read and write methods",
|
|
96
|
+
"example": "const { write } = useClipboard(); write('Hello World');"
|
|
97
|
+
},
|
|
98
|
+
"UseClipboardOptions": {
|
|
99
|
+
"type": "type",
|
|
100
|
+
"description": "TypeScript type defining optional configuration for the useClipboard hook, such as specifying the target element for clipboard operations or setting permissions for clipboard access.",
|
|
101
|
+
"hook": false
|
|
102
|
+
},
|
|
103
|
+
"UseClipboardReturn": {
|
|
104
|
+
"type": "type",
|
|
105
|
+
"description": "TypeScript interface defining the return value of useClipboard hook, which includes read and write methods for interacting with the system clipboard. The read method returns the current clipboard content as a string, while the write method sets new content to the clipboard.",
|
|
106
|
+
"hook": false
|
|
107
|
+
},
|
|
108
|
+
"useRageClick": {
|
|
109
|
+
"type": "function",
|
|
110
|
+
"description": "React hook that detects rapid, repeated clicking (rage clicking) on an element, typically indicating user frustration or confusion. Useful for identifying problematic UI elements that may need redesign or additional feedback to improve user experience.",
|
|
111
|
+
"hook": true,
|
|
112
|
+
"params": "options?: { threshold?: number, timeout?: number }",
|
|
113
|
+
"returns": "{ isRageClicking: boolean, reset: () => void }",
|
|
114
|
+
"example": "const { isRageClicking } = useRageClick(); if (isRageClicking) { /* show help tooltip */ }"
|
|
115
|
+
},
|
|
116
|
+
"RageClickPayload": {
|
|
117
|
+
"type": "type",
|
|
118
|
+
"description": "TypeScript type defining the shape of a rage click event payload. Contains properties like target element, coordinates, and timestamp to identify rapid repeated clicks on the same element.",
|
|
119
|
+
"hook": false,
|
|
120
|
+
"params": "Optional: { target: Element, x: number, y: number, timestamp: number }",
|
|
121
|
+
"returns": "N/A",
|
|
122
|
+
"sideEffect": false
|
|
123
|
+
},
|
|
124
|
+
"UseRageClickOptions": {
|
|
125
|
+
"type": "type",
|
|
126
|
+
"description": "TypeScript type defining configuration options for the useRageClick hook. Allows customizing detection threshold, debounce delay, and callback behavior for rage click detection.",
|
|
127
|
+
"hook": false,
|
|
128
|
+
"params": "Optional: { threshold?: number, debounce?: number, callback?: (payload: RageClickPayload) => void }",
|
|
129
|
+
"returns": "N/A",
|
|
130
|
+
"sideEffect": false
|
|
131
|
+
},
|
|
132
|
+
"useThreadedWorker": {
|
|
133
|
+
"type": "function",
|
|
134
|
+
"description": "React hook that manages communication with a web worker thread. Enables offloading heavy computations to a separate thread while maintaining React state synchronization.",
|
|
135
|
+
"hook": true,
|
|
136
|
+
"params": "options: UseThreadedWorkerOptions",
|
|
137
|
+
"returns": "UseThreadedWorkerReturn",
|
|
138
|
+
"sideEffect": false,
|
|
139
|
+
"example": "const { data, error, isLoading } = useThreadedWorker({ worker: myWorker, input: someData })"
|
|
140
|
+
},
|
|
141
|
+
"ThreadedWorkerMode": {
|
|
142
|
+
"type": "type",
|
|
143
|
+
"description": "TypeScript enum defining operational modes for threaded workers. Specifies whether worker runs in dedicated, shared, or service worker context for different threading strategies.",
|
|
144
|
+
"hook": false,
|
|
145
|
+
"params": "Optional: { DEDICATED, SHARED, SERVICE_WORKER }",
|
|
146
|
+
"returns": "N/A",
|
|
147
|
+
"sideEffect": false
|
|
148
|
+
},
|
|
149
|
+
"UseThreadedWorkerOptions": {
|
|
150
|
+
"type": "type",
|
|
151
|
+
"description": "TypeScript type defining configuration options for useThreadedWorker hook. Includes worker instance, input data, transfer options, and error handling callbacks.",
|
|
152
|
+
"hook": false,
|
|
153
|
+
"params": "Optional: { worker: Worker, input?: any, transfer?: Transferable[], onError?: (error: Error) => void }",
|
|
154
|
+
"returns": "N/A",
|
|
155
|
+
"sideEffect": false
|
|
156
|
+
},
|
|
157
|
+
"RunOptions": {
|
|
158
|
+
"type": "type",
|
|
159
|
+
"description": "TypeScript type defining options for running threaded operations. Controls execution behavior like cancellation, timeout, and result handling for worker tasks.",
|
|
160
|
+
"hook": false,
|
|
161
|
+
"params": "Optional: { cancelable?: boolean, timeout?: number, onResult?: (result: any) => void }",
|
|
162
|
+
"returns": "N/A",
|
|
163
|
+
"sideEffect": false
|
|
164
|
+
},
|
|
165
|
+
"UseThreadedWorkerReturn": {
|
|
166
|
+
"type": "type",
|
|
167
|
+
"description": "TypeScript type defining the return value shape from useThreadedWorker hook. Contains data, error state, loading status, and control methods for worker communication.",
|
|
168
|
+
"hook": false,
|
|
169
|
+
"params": "Optional: { data: any, error: Error | null, isLoading: boolean, cancel: () => void, postMessage: (message: any) => void }",
|
|
170
|
+
"returns": "N/A",
|
|
171
|
+
"sideEffect": false
|
|
172
|
+
},
|
|
173
|
+
"useIndexedDB": {
|
|
174
|
+
"type": "function",
|
|
175
|
+
"description": "React hook providing simplified IndexedDB access with React state management. Enables reading and writing to IndexedDB with automatic change detection and error handling.",
|
|
176
|
+
"hook": true,
|
|
177
|
+
"params": "databaseName: string, storeName: string, options?: { version?: number, keyPath?: string }",
|
|
178
|
+
"returns": "UseIndexedDBReturn",
|
|
179
|
+
"sideEffect": false,
|
|
180
|
+
"example": "const { data, error, isLoading, add, get } = useIndexedDB('myDB', 'store')"
|
|
181
|
+
},
|
|
182
|
+
"IndexedDBConfig": {
|
|
183
|
+
"type": "type",
|
|
184
|
+
"description": "Configuration object for setting up an IndexedDB connection, including database name, version, and optional upgrade callback. Used to customize the IndexedDB environment for use with the IDBController.",
|
|
185
|
+
"hook": false,
|
|
186
|
+
"params": "{ name: string, version?: number, upgradeCallback?: (db: IDBDatabase) => void }",
|
|
187
|
+
"returns": "None (type definition)",
|
|
188
|
+
"sideEffect": false
|
|
189
|
+
},
|
|
190
|
+
"IDBController": {
|
|
191
|
+
"type": "class",
|
|
192
|
+
"description": "A class that manages IndexedDB connections and operations, providing methods to open, close, and interact with IndexedDB databases. Used for encapsulating IndexedDB logic and handling database lifecycle.",
|
|
193
|
+
"hook": false,
|
|
194
|
+
"params": "config: IndexedDBConfig",
|
|
195
|
+
"returns": "Instance of IDBController",
|
|
196
|
+
"sideEffect": false,
|
|
197
|
+
"example": "const db = new IDBController({ name: 'my-db' })"
|
|
198
|
+
},
|
|
199
|
+
"UseIndexedDBReturn": {
|
|
200
|
+
"type": "type",
|
|
201
|
+
"description": "Return type for the useIndexedDB hook, containing the database instance and a loading/error state. Used to provide the current IndexedDB state and data to React components.",
|
|
202
|
+
"hook": false,
|
|
203
|
+
"params": "{ db: IDBDatabase | null, loading: boolean, error: Error | null }",
|
|
204
|
+
"returns": "None (type definition)",
|
|
205
|
+
"sideEffect": false
|
|
206
|
+
},
|
|
207
|
+
"useWebRTCIP": {
|
|
208
|
+
"type": "function",
|
|
209
|
+
"description": "A React hook that retrieves the local IP address using WebRTC by creating a peer connection and extracting the IP from ICE candidates. Used for obtaining the client's IP address in a browser environment.",
|
|
210
|
+
"hook": true,
|
|
211
|
+
"params": "options?: UseWebRTCIPOptions",
|
|
212
|
+
"returns": "UseWebRTCIPReturn",
|
|
213
|
+
"sideEffect": false,
|
|
214
|
+
"example": "const { ip, loading, error } = useWebRTCIP()"
|
|
215
|
+
},
|
|
216
|
+
"UseWebRTCIPOptions": {
|
|
217
|
+
"type": "type",
|
|
218
|
+
"description": "Options object for configuring the useWebRTCIP hook, such as disabling IPv6 or setting a timeout. Used to customize the behavior of the WebRTC IP discovery process.",
|
|
219
|
+
"hook": false,
|
|
220
|
+
"params": "{ disableIPv6?: boolean, timeout?: number }",
|
|
221
|
+
"returns": "None (type definition)",
|
|
222
|
+
"sideEffect": false
|
|
223
|
+
},
|
|
224
|
+
"UseWebRTCIPReturn": {
|
|
225
|
+
"type": "type",
|
|
226
|
+
"description": "Return type for the useWebRTCIP hook, containing the discovered IP address and loading/error state. Used to provide the WebRTC IP discovery result to React components.",
|
|
227
|
+
"hook": false,
|
|
228
|
+
"params": "{ ip: string | null, loading: boolean, error: Error | null }",
|
|
229
|
+
"returns": "None (type definition)",
|
|
230
|
+
"sideEffect": false
|
|
231
|
+
},
|
|
232
|
+
"useWasmCompute": {
|
|
233
|
+
"type": "function",
|
|
234
|
+
"description": "A React hook that loads and executes WebAssembly modules for computationally intensive tasks, providing a way to run WASM code in the browser. Used for offloading heavy computations to WASM for performance gains.",
|
|
235
|
+
"hook": true,
|
|
236
|
+
"params": "options: UseWasmComputeOptions",
|
|
237
|
+
"returns": "function that executes the WASM module with input data",
|
|
238
|
+
"sideEffect": false,
|
|
239
|
+
"example": "const compute = useWasmCompute({ modulePath: '/compute.wasm' }); const result = compute(inputData)"
|
|
240
|
+
},
|
|
241
|
+
"UseWasmComputeOptions": {
|
|
242
|
+
"type": "type",
|
|
243
|
+
"description": "Options object for configuring the useWasmCompute hook, including the path to the WASM module and optional initialization parameters. Used to specify which WASM module to load and how to initialize it.",
|
|
244
|
+
"hook": false,
|
|
245
|
+
"params": "{ modulePath: string, initParams?: any }",
|
|
246
|
+
"returns": "None (type definition)",
|
|
247
|
+
"sideEffect": false
|
|
248
|
+
},
|
|
249
|
+
"UseWasmComputeReturn": {
|
|
250
|
+
"type": "type",
|
|
251
|
+
"description": "Type definition for the return value of Wasm compute functions, typically containing status and result fields.",
|
|
252
|
+
"hook": false,
|
|
253
|
+
"params": "N/A",
|
|
254
|
+
"returns": "N/A"
|
|
255
|
+
},
|
|
256
|
+
"useWorkerNotifications": {
|
|
257
|
+
"type": "function",
|
|
258
|
+
"description": "React hook that subscribes to worker notifications and manages their lifecycle within a component.",
|
|
259
|
+
"hook": true,
|
|
260
|
+
"params": "options: UseWorkerNotificationsOptions",
|
|
261
|
+
"returns": "UseWorkerNotificationsReturn",
|
|
262
|
+
"example": "const { notifications, error } = useWorkerNotifications({ worker: myWorker });"
|
|
263
|
+
},
|
|
264
|
+
"WorkerEventType": {
|
|
265
|
+
"type": "type",
|
|
266
|
+
"description": "Enumeration type defining the different types of events that can be emitted by a worker.",
|
|
267
|
+
"hook": false,
|
|
268
|
+
"params": "N/A",
|
|
269
|
+
"returns": "N/A"
|
|
270
|
+
},
|
|
271
|
+
"WorkerNotificationEvent": {
|
|
272
|
+
"type": "type",
|
|
273
|
+
"description": "Type definition for worker notification events, containing event data and metadata.",
|
|
274
|
+
"hook": false,
|
|
275
|
+
"params": "N/A",
|
|
276
|
+
"returns": "N/A"
|
|
277
|
+
},
|
|
278
|
+
"UseWorkerNotificationsOptions": {
|
|
279
|
+
"type": "type",
|
|
280
|
+
"description": "Configuration options for the useWorkerNotifications hook, including worker instance and event filters.",
|
|
281
|
+
"hook": false,
|
|
282
|
+
"params": "N/A",
|
|
283
|
+
"returns": "N/A"
|
|
284
|
+
},
|
|
285
|
+
"UseWorkerNotificationsReturn": {
|
|
286
|
+
"type": "type",
|
|
287
|
+
"description": "Return type for useWorkerNotifications hook, providing notifications array and error state.",
|
|
288
|
+
"hook": false,
|
|
289
|
+
"params": "N/A",
|
|
290
|
+
"returns": "N/A"
|
|
291
|
+
},
|
|
292
|
+
"useLLMMetadata": {
|
|
293
|
+
"type": "function",
|
|
294
|
+
"description": "React hook for fetching and managing LLM metadata within a component's lifecycle.",
|
|
295
|
+
"hook": true,
|
|
296
|
+
"params": "options?: { modelId?: string }",
|
|
297
|
+
"returns": "{ metadata: LLMData | null, loading: boolean, error: Error | null }",
|
|
298
|
+
"example": "const { metadata, loading } = useLLMMetadata({ modelId: 'gpt-4' });"
|
|
299
|
+
},
|
|
300
|
+
"OGType": {
|
|
301
|
+
"type": "type",
|
|
302
|
+
"description": "Type definition for Open Graph metadata types used in social media sharing.",
|
|
303
|
+
"hook": false,
|
|
304
|
+
"params": "N/A",
|
|
305
|
+
"returns": "N/A"
|
|
306
|
+
},
|
|
307
|
+
"LLMConfig": {
|
|
308
|
+
"type": "type",
|
|
309
|
+
"description": "Configuration object type for LLM integrations, defining required settings like model, API key, and optional parameters. Used to initialize and configure LLM client instances with consistent type safety.",
|
|
310
|
+
"hook": false,
|
|
311
|
+
"params": "{ model: string, apiKey: string, temperature?: number, maxTokens?: number }",
|
|
312
|
+
"returns": "LLMConfig object with typed properties for LLM initialization"
|
|
313
|
+
},
|
|
314
|
+
"LLMPayload": {
|
|
315
|
+
"type": "type",
|
|
316
|
+
"description": "Payload type for LLM requests, encapsulating the user message and optional context for AI model interactions. Used to structure input data sent to LLM endpoints for processing and response generation.",
|
|
317
|
+
"hook": false,
|
|
318
|
+
"params": "{ message: string, context?: string[] }",
|
|
319
|
+
"returns": "LLMPayload object containing message and optional context array for LLM processing"
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
"hooks": [
|
|
323
|
+
"useTransition",
|
|
324
|
+
"useMutationObserver",
|
|
325
|
+
"useEventBus",
|
|
326
|
+
"useWrappedChildren",
|
|
327
|
+
"usePreferredTheme",
|
|
328
|
+
"useNetworkState",
|
|
329
|
+
"useClipboard",
|
|
330
|
+
"useRageClick",
|
|
331
|
+
"useThreadedWorker",
|
|
332
|
+
"useIndexedDB",
|
|
333
|
+
"useWebRTCIP",
|
|
334
|
+
"useWasmCompute",
|
|
335
|
+
"useWorkerNotifications",
|
|
336
|
+
"useLLMMetadata"
|
|
337
|
+
],
|
|
338
|
+
"frameworks": [
|
|
339
|
+
"preact",
|
|
340
|
+
"react"
|
|
341
|
+
],
|
|
342
|
+
"generatedBy": "hayagriva-llm@1.2.0",
|
|
343
|
+
"mode": "ai",
|
|
344
|
+
"summary": "Preact-Missing-Hooks is a lightweight, extendable collection of missing React-like hooks for Preact, offering both familiar hooks and fresh, powerful new ones designed specifically for modern Preact apps.",
|
|
345
|
+
"sideEffects": [],
|
|
346
|
+
"keywords": [
|
|
347
|
+
"preact",
|
|
348
|
+
"hooks",
|
|
349
|
+
"react-hooks",
|
|
350
|
+
"useTransition",
|
|
351
|
+
"useMutationObserver",
|
|
352
|
+
"useEventBus",
|
|
353
|
+
"useWrappedChildren",
|
|
354
|
+
"usePreferredTheme",
|
|
355
|
+
"useNetworkState",
|
|
356
|
+
"useClipboard",
|
|
357
|
+
"useRageClick",
|
|
358
|
+
"useThreadedWorker",
|
|
359
|
+
"useIndexedDB",
|
|
360
|
+
"useWebRTCIP",
|
|
361
|
+
"useWasmCompute",
|
|
362
|
+
"useWorkerNotifications",
|
|
363
|
+
"typescript",
|
|
364
|
+
"modern-web"
|
|
365
|
+
],
|
|
366
|
+
"whenToUse": "Choose Preact-Missing-Hooks when building modern Preact applications that need advanced, React-like hooks not natively available in Preact, or when you want to leverage powerful new hooks for tasks like clipboard management, WebRTC IP detection, WebAssembly computation, IndexedDB access, or rage-click detection. It's ideal for developers seeking a lightweight, extendable hook library that works seamlessly with both Preact and React.",
|
|
367
|
+
"reasonToUse": [
|
|
368
|
+
"Provides missing React-like hooks for Preact",
|
|
369
|
+
"Offers powerful new hooks for modern web features",
|
|
370
|
+
"Lightweight and extendable",
|
|
371
|
+
"Framework-agnostic (works with Preact and React)",
|
|
372
|
+
"Production-ready with TypeScript support"
|
|
373
|
+
],
|
|
374
|
+
"useCases": [
|
|
375
|
+
"Building a Preact app that needs React's useTransition functionality",
|
|
376
|
+
"Managing clipboard operations in a Preact component",
|
|
377
|
+
"Detecting user rage clicks and reporting to error tracking tools",
|
|
378
|
+
"Running WebAssembly computations in a Web Worker",
|
|
379
|
+
"Accessing IndexedDB with a clean, React-like hook API",
|
|
380
|
+
"Observing DOM mutations reactively",
|
|
381
|
+
"Wrapping children components to inject additional props",
|
|
382
|
+
"Detecting user's preferred theme for dark/light mode support",
|
|
383
|
+
"Monitoring network state changes for offline/online handling",
|
|
384
|
+
"Tracking worker notifications and task execution in real-time"
|
|
385
|
+
],
|
|
386
|
+
"documentation": "See README",
|
|
387
|
+
"relatedPackages": [
|
|
388
|
+
"preact",
|
|
389
|
+
"react",
|
|
390
|
+
"react-hooks",
|
|
391
|
+
"preact/hooks"
|
|
392
|
+
]
|
|
393
|
+
}
|
package/llm.package.txt
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Package: preact-missing-hooks
|
|
2
|
+
Version: 4.1.0
|
|
3
|
+
|
|
4
|
+
Description:
|
|
5
|
+
A lightweight, extendable collection of missing React-like hooks for Preact — plus fresh, powerful new ones designed specifically for modern Preact apps.
|
|
6
|
+
|
|
7
|
+
Summary:
|
|
8
|
+
Preact-Missing-Hooks is a lightweight, extendable collection of missing React-like hooks for Preact, offering both familiar hooks and fresh, powerful new ones designed specifically for modern Preact apps.
|
|
9
|
+
|
|
10
|
+
When to use:
|
|
11
|
+
Choose Preact-Missing-Hooks when building modern Preact applications that need advanced, React-like hooks not natively available in Preact, or when you want to leverage powerful new hooks for tasks like clipboard management, WebRTC IP detection, WebAssembly computation, IndexedDB access, or rage-click detection. It's ideal for developers seeking a lightweight, extendable hook library that works seamlessly with both Preact and React.
|
|
12
|
+
|
|
13
|
+
Reason to use:
|
|
14
|
+
- Provides missing React-like hooks for Preact
|
|
15
|
+
- Offers powerful new hooks for modern web features
|
|
16
|
+
- Lightweight and extendable
|
|
17
|
+
- Framework-agnostic (works with Preact and React)
|
|
18
|
+
- Production-ready with TypeScript support
|
|
19
|
+
|
|
20
|
+
Use cases:
|
|
21
|
+
- Building a Preact app that needs React's useTransition functionality
|
|
22
|
+
- Managing clipboard operations in a Preact component
|
|
23
|
+
- Detecting user rage clicks and reporting to error tracking tools
|
|
24
|
+
- Running WebAssembly computations in a Web Worker
|
|
25
|
+
- Accessing IndexedDB with a clean, React-like hook API
|
|
26
|
+
- Observing DOM mutations reactively
|
|
27
|
+
- Wrapping children components to inject additional props
|
|
28
|
+
- Detecting user's preferred theme for dark/light mode support
|
|
29
|
+
- Monitoring network state changes for offline/online handling
|
|
30
|
+
- Tracking worker notifications and task execution in real-time
|
|
31
|
+
|
|
32
|
+
Keywords:
|
|
33
|
+
preact, hooks, react-hooks, useTransition, useMutationObserver, useEventBus, useWrappedChildren, usePreferredTheme, useNetworkState, useClipboard, useRageClick, useThreadedWorker, useIndexedDB, useWebRTCIP, useWasmCompute, useWorkerNotifications, typescript, modern-web
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
Documentation:
|
|
37
|
+
See README
|
|
38
|
+
|
|
39
|
+
Related packages:
|
|
40
|
+
preact, react, react-hooks, preact/hooks
|
|
41
|
+
|
|
42
|
+
Exports:
|
|
43
|
+
- ConnectionType : TypeScript type representing the physical connection type of the device (e.g., 'wifi', 'cellular', 'ethernet', 'none', 'unknown'). Used to determine how the device is connected to the network, which can inform decisions about data usage and performance optimizations.
|
|
44
|
+
- EffectiveConnectionType : TypeScript type representing the effective connection type as defined by the Network Information API. Represents the effective connection type ('slow-2g', '2g', '3g', '4g') that the browser uses to optimize content delivery based on the user's network conditions.
|
|
45
|
+
- IDBController : A class that manages IndexedDB connections and operations, providing methods to open, close, and interact with IndexedDB databases. Used for encapsulating IndexedDB logic and handling database lifecycle. — params: config: IndexedDBConfig — returns: Instance of IDBController — e.g. const db = new IDBController({ name: 'my-db' })
|
|
46
|
+
- IndexedDBConfig : Configuration object for setting up an IndexedDB connection, including database name, version, and optional upgrade callback. Used to customize the IndexedDB environment for use with the IDBController. — params: { name: string, version?: number, upgradeCallback?: (db: IDBDatabase) => void } — returns: None (type definition)
|
|
47
|
+
- InjectableProps : A TypeScript type that defines the shape of props that can be injected into a component, typically used for dependency injection or prop forwarding. — params: Generic type extending React.PropsWithChildren — returns: N/A
|
|
48
|
+
- LLMConfig : Configuration object type for LLM integrations, defining required settings like model, API key, and optional parameters. Used to initialize and configure LLM client instances with consistent type safety. — params: { model: string, apiKey: string, temperature?: number, maxTokens?: number } — returns: LLMConfig object with typed properties for LLM initialization
|
|
49
|
+
- LLMPayload : Payload type for LLM requests, encapsulating the user message and optional context for AI model interactions. Used to structure input data sent to LLM endpoints for processing and response generation. — params: { message: string, context?: string[] } — returns: LLMPayload object containing message and optional context array for LLM processing
|
|
50
|
+
- NetworkState : TypeScript interface defining the structure of network state information returned by useNetworkState hook. Includes properties like online (boolean), since (Date), downlink (number), downlinkMax (number), effectiveType (EffectiveConnectionType), rtt (number), and type (ConnectionType).
|
|
51
|
+
- OGType : Type definition for Open Graph metadata types used in social media sharing. — params: N/A — returns: N/A
|
|
52
|
+
- PreferredTheme : A TypeScript type that defines the possible values for a preferred theme, typically 'light', 'dark', or 'no-preference'. — params: N/A — returns: 'light' | 'dark' | 'no-preference'
|
|
53
|
+
- RageClickPayload : TypeScript type defining the shape of a rage click event payload. Contains properties like target element, coordinates, and timestamp to identify rapid repeated clicks on the same element. — params: Optional: { target: Element, x: number, y: number, timestamp: number } — returns: N/A
|
|
54
|
+
- RunOptions : TypeScript type defining options for running threaded operations. Controls execution behavior like cancellation, timeout, and result handling for worker tasks. — params: Optional: { cancelable?: boolean, timeout?: number, onResult?: (result: any) => void } — returns: N/A
|
|
55
|
+
- ThreadedWorkerMode : TypeScript enum defining operational modes for threaded workers. Specifies whether worker runs in dedicated, shared, or service worker context for different threading strategies. — params: Optional: { DEDICATED, SHARED, SERVICE_WORKER } — returns: N/A
|
|
56
|
+
- useClipboard (Hook) : React hook that provides access to the system clipboard, allowing reading and writing of text content. Useful for implementing copy-to-clipboard functionality in components without requiring direct DOM manipulation or event handling. — params: options?: UseClipboardOptions — returns: UseClipboardReturn object with read and write methods — e.g. const { write } = useClipboard(); write('Hello World');
|
|
57
|
+
- UseClipboardOptions : TypeScript type defining optional configuration for the useClipboard hook, such as specifying the target element for clipboard operations or setting permissions for clipboard access.
|
|
58
|
+
- UseClipboardReturn : TypeScript interface defining the return value of useClipboard hook, which includes read and write methods for interacting with the system clipboard. The read method returns the current clipboard content as a string, while the write method sets new content to the clipboard.
|
|
59
|
+
- useEventBus (Hook) : A hook that provides access to a global event bus for publishing and subscribing to events across components. It returns an object with methods to subscribe, unsubscribe, and publish events. — params: none — returns: { subscribe: (event: string, callback: Function) => void, unsubscribe: (event: string, callback: Function) => void, publish: (event: string, data: any) => void }
|
|
60
|
+
- useIndexedDB (Hook) : React hook providing simplified IndexedDB access with React state management. Enables reading and writing to IndexedDB with automatic change detection and error handling. — params: databaseName: string, storeName: string, options?: { version?: number, keyPath?: string } — returns: UseIndexedDBReturn — e.g. const { data, error, isLoading, add, get } = useIndexedDB('myDB', 'store')
|
|
61
|
+
- UseIndexedDBReturn : Return type for the useIndexedDB hook, containing the database instance and a loading/error state. Used to provide the current IndexedDB state and data to React components. — params: { db: IDBDatabase | null, loading: boolean, error: Error | null } — returns: None (type definition)
|
|
62
|
+
- useLLMMetadata (Hook) : React hook for fetching and managing LLM metadata within a component's lifecycle. — params: options?: { modelId?: string } — returns: { metadata: LLMData | null, loading: boolean, error: Error | null } — e.g. const { metadata, loading } = useLLMMetadata({ modelId: 'gpt-4' });
|
|
63
|
+
- useMutationObserver (Hook) : A hook that creates and manages a MutationObserver to watch for changes in the DOM. It accepts a target element and a callback to execute when mutations are observed, returning a ref to attach to the target element. — params: target: Element | null, callback: MutationCallback, options?: MutationObserverInit — returns: ref: { current: Element | null }
|
|
64
|
+
- UseMutationObserverOptions : A TypeScript type defining the options object for the useMutationObserver hook, extending MutationObserverInit to include optional configuration for observing DOM mutations. — params: extends MutationObserverInit — returns: N/A
|
|
65
|
+
- useNetworkState (Hook) : React hook that returns the current network state of the browser, including connection type, effective connection type, and whether the device is online or offline. Useful for adapting application behavior based on network conditions, such as reducing data usage or showing offline indicators. — params: none — returns: NetworkState object with online, since, downlink, downlinkMax, effectiveType, rtt, type properties — e.g. const network = useNetworkState(); if (!network.online) { /* show offline message */ }
|
|
66
|
+
- usePreferredTheme (Hook) : A hook that detects and returns the user's preferred color scheme (light or dark) based on the operating system or browser settings. It returns the current preferred theme. — params: none — returns: 'light' | 'dark' | 'no-preference'
|
|
67
|
+
- useRageClick (Hook) : React hook that detects rapid, repeated clicking (rage clicking) on an element, typically indicating user frustration or confusion. Useful for identifying problematic UI elements that may need redesign or additional feedback to improve user experience. — params: options?: { threshold?: number, timeout?: number } — returns: { isRageClicking: boolean, reset: () => void } — e.g. const { isRageClicking } = useRageClick(); if (isRageClicking) { /* show help tooltip */ }
|
|
68
|
+
- UseRageClickOptions : TypeScript type defining configuration options for the useRageClick hook. Allows customizing detection threshold, debounce delay, and callback behavior for rage click detection. — params: Optional: { threshold?: number, debounce?: number, callback?: (payload: RageClickPayload) => void } — returns: N/A
|
|
69
|
+
- useThreadedWorker (Hook) : React hook that manages communication with a web worker thread. Enables offloading heavy computations to a separate thread while maintaining React state synchronization. — params: options: UseThreadedWorkerOptions — returns: UseThreadedWorkerReturn — e.g. const { data, error, isLoading } = useThreadedWorker({ worker: myWorker, input: someData })
|
|
70
|
+
- UseThreadedWorkerOptions : TypeScript type defining configuration options for useThreadedWorker hook. Includes worker instance, input data, transfer options, and error handling callbacks. — params: Optional: { worker: Worker, input?: any, transfer?: Transferable[], onError?: (error: Error) => void } — returns: N/A
|
|
71
|
+
- UseThreadedWorkerReturn : TypeScript type defining the return value shape from useThreadedWorker hook. Contains data, error state, loading status, and control methods for worker communication. — params: Optional: { data: any, error: Error | null, isLoading: boolean, cancel: () => void, postMessage: (message: any) => void } — returns: N/A
|
|
72
|
+
- useTransition (Hook) : A custom hook that wraps React's useTransition API, providing a way to mark updates as transitions to allow the browser to prioritize updates. It returns a tuple containing a boolean indicating if the transition is pending and a startTransition function to wrap state updates. — params: config?: { timeoutMs?: number } — returns: [isPending: boolean, startTransition: (callback: () => void) => void]
|
|
73
|
+
- useWasmCompute (Hook) : A React hook that loads and executes WebAssembly modules for computationally intensive tasks, providing a way to run WASM code in the browser. Used for offloading heavy computations to WASM for performance gains. — params: options: UseWasmComputeOptions — returns: function that executes the WASM module with input data — e.g. const compute = useWasmCompute({ modulePath: '/compute.wasm' }); const result = compute(inputData)
|
|
74
|
+
- UseWasmComputeOptions : Options object for configuring the useWasmCompute hook, including the path to the WASM module and optional initialization parameters. Used to specify which WASM module to load and how to initialize it. — params: { modulePath: string, initParams?: any } — returns: None (type definition)
|
|
75
|
+
- UseWasmComputeReturn : Type definition for the return value of Wasm compute functions, typically containing status and result fields. — params: N/A — returns: N/A
|
|
76
|
+
- useWebRTCIP (Hook) : A React hook that retrieves the local IP address using WebRTC by creating a peer connection and extracting the IP from ICE candidates. Used for obtaining the client's IP address in a browser environment. — params: options?: UseWebRTCIPOptions — returns: UseWebRTCIPReturn — e.g. const { ip, loading, error } = useWebRTCIP()
|
|
77
|
+
- UseWebRTCIPOptions : Options object for configuring the useWebRTCIP hook, such as disabling IPv6 or setting a timeout. Used to customize the behavior of the WebRTC IP discovery process. — params: { disableIPv6?: boolean, timeout?: number } — returns: None (type definition)
|
|
78
|
+
- UseWebRTCIPReturn : Return type for the useWebRTCIP hook, containing the discovered IP address and loading/error state. Used to provide the WebRTC IP discovery result to React components. — params: { ip: string | null, loading: boolean, error: Error | null } — returns: None (type definition)
|
|
79
|
+
- useWorkerNotifications (Hook) : React hook that subscribes to worker notifications and manages their lifecycle within a component. — params: options: UseWorkerNotificationsOptions — returns: UseWorkerNotificationsReturn — e.g. const { notifications, error } = useWorkerNotifications({ worker: myWorker });
|
|
80
|
+
- UseWorkerNotificationsOptions : Configuration options for the useWorkerNotifications hook, including worker instance and event filters. — params: N/A — returns: N/A
|
|
81
|
+
- UseWorkerNotificationsReturn : Return type for useWorkerNotifications hook, providing notifications array and error state. — params: N/A — returns: N/A
|
|
82
|
+
- useWrappedChildren (Hook) : A hook that wraps the children of a component with a specified wrapper component or element. It takes children and a wrapper as arguments and returns the wrapped children. — params: children: ReactNode, wrapper: ComponentType | string — returns: ReactNode
|
|
83
|
+
- WorkerEventType : Enumeration type defining the different types of events that can be emitted by a worker. — params: N/A — returns: N/A
|
|
84
|
+
- WorkerNotificationEvent : Type definition for worker notification events, containing event data and metadata. — params: N/A — returns: N/A
|
|
85
|
+
|
|
86
|
+
Hooks:
|
|
87
|
+
- useTransition
|
|
88
|
+
- useMutationObserver
|
|
89
|
+
- useEventBus
|
|
90
|
+
- useWrappedChildren
|
|
91
|
+
- usePreferredTheme
|
|
92
|
+
- useNetworkState
|
|
93
|
+
- useClipboard
|
|
94
|
+
- useRageClick
|
|
95
|
+
- useThreadedWorker
|
|
96
|
+
- useIndexedDB
|
|
97
|
+
- useWebRTCIP
|
|
98
|
+
- useWasmCompute
|
|
99
|
+
- useWorkerNotifications
|
|
100
|
+
- useLLMMetadata
|
|
101
|
+
|
|
102
|
+
Frameworks:
|
|
103
|
+
preact, react
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-missing-hooks",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "A lightweight, extendable collection of missing React-like hooks for Preact — plus fresh, powerful new ones designed specifically for modern Preact apps.",
|
|
5
5
|
"author": "Prakhar Dubey",
|
|
6
6
|
"license": "MIT",
|
|
@@ -90,7 +90,8 @@
|
|
|
90
90
|
},
|
|
91
91
|
"scripts": {
|
|
92
92
|
"build": "microbundle --alias react=preact/compat && npm run build:react && node scripts/generate-entry.cjs",
|
|
93
|
-
"
|
|
93
|
+
"llm:generate": "hayagriva-llm generate",
|
|
94
|
+
"build:react": "rollup -c scripts/rollup.react.config.cjs",
|
|
94
95
|
"dev": "microbundle watch",
|
|
95
96
|
"prepublishOnly": "npm run build",
|
|
96
97
|
"test": "vitest run",
|
|
@@ -102,7 +103,8 @@
|
|
|
102
103
|
"format": "prettier --write \"src/**/*.{ts,tsx,json,md}\"",
|
|
103
104
|
"format:check": "prettier --check \"src/**/*.{ts,tsx,json,md}\"",
|
|
104
105
|
"prepare": "husky",
|
|
105
|
-
"
|
|
106
|
+
"clean:cache": "node -e \"try{require('fs').rmSync('node_modules/.cache',{recursive:true,force:true});console.log('Cache cleared');}catch(e){}\"",
|
|
107
|
+
"size": "npm run clean:cache && npm run build && size-limit"
|
|
106
108
|
},
|
|
107
109
|
"size-limit": [
|
|
108
110
|
{
|
|
@@ -154,9 +156,11 @@
|
|
|
154
156
|
"@testing-library/preact": "^3.2.4",
|
|
155
157
|
"@testing-library/react": "^16.0.1",
|
|
156
158
|
"@types/jest": "^29.5.14",
|
|
159
|
+
"@types/react": "^18.3.0",
|
|
157
160
|
"eslint": "^9.15.0",
|
|
158
161
|
"eslint-config-prettier": "^9.1.0",
|
|
159
162
|
"fake-indexeddb": "^6.0.2",
|
|
163
|
+
"hayagriva-llm": "^1.2.0",
|
|
160
164
|
"husky": "^9.1.7",
|
|
161
165
|
"jsdom": "^26.1.0",
|
|
162
166
|
"microbundle": "^0.15.1",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rollup config for the React build (preact aliased to react).
|
|
3
|
+
* Uses rollup-plugin-typescript2 with clean: true to avoid EPERM cache
|
|
4
|
+
* rename issues on Windows.
|
|
5
|
+
*/
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const alias = require("@rollup/plugin-alias");
|
|
8
|
+
const { nodeResolve } = require("@rollup/plugin-node-resolve");
|
|
9
|
+
const commonjs = require("@rollup/plugin-commonjs");
|
|
10
|
+
const typescript = require("rollup-plugin-typescript2");
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
input: path.join(__dirname, "..", "src", "index.ts"),
|
|
14
|
+
output: {
|
|
15
|
+
file: path.join(__dirname, "..", "dist", "react.js"),
|
|
16
|
+
format: "cjs",
|
|
17
|
+
sourcemap: false,
|
|
18
|
+
},
|
|
19
|
+
external: ["react", "react-dom"],
|
|
20
|
+
plugins: [
|
|
21
|
+
alias({
|
|
22
|
+
entries: [
|
|
23
|
+
{ find: "preact/hooks", replacement: "react" },
|
|
24
|
+
{ find: "preact", replacement: "react" },
|
|
25
|
+
],
|
|
26
|
+
}),
|
|
27
|
+
nodeResolve(),
|
|
28
|
+
commonjs(),
|
|
29
|
+
typescript({
|
|
30
|
+
clean: true,
|
|
31
|
+
tsconfig: path.join(__dirname, "..", "tsconfig.json"),
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
};
|