@fictjs/hooks 0.1.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/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/index.cjs +2548 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +744 -0
- package/dist/index.d.ts +744 -0
- package/dist/index.js +2483 -0
- package/dist/index.js.map +1 -0
- package/package.json +88 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,744 @@
|
|
|
1
|
+
import { Cleanup } from '@fictjs/runtime';
|
|
2
|
+
|
|
3
|
+
type MountCallback = () => void | Cleanup;
|
|
4
|
+
/**
|
|
5
|
+
* Register a callback that runs after the current root mounts.
|
|
6
|
+
*
|
|
7
|
+
* @fictReturn {}
|
|
8
|
+
*/
|
|
9
|
+
declare function useMount(callback: MountCallback): void;
|
|
10
|
+
|
|
11
|
+
type UnmountCallback = () => void | Cleanup;
|
|
12
|
+
/**
|
|
13
|
+
* Register cleanup logic for root disposal.
|
|
14
|
+
*
|
|
15
|
+
* @fictReturn {}
|
|
16
|
+
*/
|
|
17
|
+
declare function useUnmount(callback: UnmountCallback): void;
|
|
18
|
+
|
|
19
|
+
interface UseAsyncStateOptions {
|
|
20
|
+
immediate?: boolean;
|
|
21
|
+
resetOnExecute?: boolean;
|
|
22
|
+
onError?: (error: unknown) => void;
|
|
23
|
+
}
|
|
24
|
+
interface UseAsyncStateReturn<T, Args extends unknown[]> {
|
|
25
|
+
state: () => T;
|
|
26
|
+
isLoading: () => boolean;
|
|
27
|
+
error: () => unknown;
|
|
28
|
+
execute: (...args: Args) => Promise<T>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Lightweight async state manager with race protection.
|
|
32
|
+
*
|
|
33
|
+
* @fictReturn { state: 'signal', isLoading: 'signal', error: 'signal' }
|
|
34
|
+
*/
|
|
35
|
+
declare function useAsyncState<T, Args extends unknown[] = []>(executor: (...args: Args) => Promise<T>, initialState: T, options?: UseAsyncStateOptions): UseAsyncStateReturn<T, Args>;
|
|
36
|
+
|
|
37
|
+
type MaybeAccessor<T> = T | (() => T);
|
|
38
|
+
|
|
39
|
+
interface UseFetchOptions<T> {
|
|
40
|
+
immediate?: boolean;
|
|
41
|
+
initialData?: T | null;
|
|
42
|
+
fetch?: typeof fetch;
|
|
43
|
+
parse?: (response: Response) => Promise<T>;
|
|
44
|
+
onError?: (error: unknown) => void;
|
|
45
|
+
init?: RequestInit;
|
|
46
|
+
}
|
|
47
|
+
interface UseFetchReturn<T> {
|
|
48
|
+
data: () => T | null;
|
|
49
|
+
error: () => unknown;
|
|
50
|
+
isLoading: () => boolean;
|
|
51
|
+
status: () => number | null;
|
|
52
|
+
aborted: () => boolean;
|
|
53
|
+
execute: (init?: RequestInit) => Promise<T | null>;
|
|
54
|
+
abort: () => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Fetch helper with loading/error/abort state.
|
|
58
|
+
*
|
|
59
|
+
* @fictReturn { data: 'signal', error: 'signal', isLoading: 'signal', status: 'signal', aborted: 'signal' }
|
|
60
|
+
*/
|
|
61
|
+
declare function useFetch<T = unknown>(input: RequestInfo | URL | MaybeAccessor<RequestInfo | URL>, options?: UseFetchOptions<T>): UseFetchReturn<T>;
|
|
62
|
+
|
|
63
|
+
interface UseRequestOptions<TData, TParams extends unknown[]> {
|
|
64
|
+
manual?: boolean;
|
|
65
|
+
defaultParams?: TParams;
|
|
66
|
+
retryCount?: number;
|
|
67
|
+
retryInterval?: number;
|
|
68
|
+
pollingInterval?: number;
|
|
69
|
+
cacheKey?: string;
|
|
70
|
+
staleTime?: number;
|
|
71
|
+
onSuccess?: (data: TData, params: TParams) => void;
|
|
72
|
+
onError?: (error: unknown, params: TParams) => void;
|
|
73
|
+
onFinally?: (params: TParams, data?: TData, error?: unknown) => void;
|
|
74
|
+
}
|
|
75
|
+
interface UseRequestReturn<TData, TParams extends unknown[]> {
|
|
76
|
+
data: () => TData | undefined;
|
|
77
|
+
error: () => unknown;
|
|
78
|
+
loading: () => boolean;
|
|
79
|
+
params: () => TParams | undefined;
|
|
80
|
+
run: (...params: TParams) => void;
|
|
81
|
+
runAsync: (...params: TParams) => Promise<TData | undefined>;
|
|
82
|
+
cancel: () => void;
|
|
83
|
+
refresh: () => Promise<TData | undefined>;
|
|
84
|
+
mutate: (value: TData | ((prev: TData | undefined) => TData)) => void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Lightweight request manager with retry, polling and cache.
|
|
88
|
+
*
|
|
89
|
+
* @fictReturn { data: 'signal', error: 'signal', loading: 'signal', params: 'signal' }
|
|
90
|
+
*/
|
|
91
|
+
declare function useRequest<TData, TParams extends unknown[] = []>(service: (...params: TParams) => Promise<TData>, options?: UseRequestOptions<TData, TParams>): UseRequestReturn<TData, TParams>;
|
|
92
|
+
|
|
93
|
+
type NavigatorClipboardLike = {
|
|
94
|
+
clipboard?: {
|
|
95
|
+
writeText: (text: string) => Promise<void>;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
interface UseClipboardOptions {
|
|
99
|
+
navigator?: NavigatorClipboardLike | null;
|
|
100
|
+
document?: Document | null;
|
|
101
|
+
window?: Window | null;
|
|
102
|
+
copiedDuring?: number;
|
|
103
|
+
}
|
|
104
|
+
interface UseClipboardReturn {
|
|
105
|
+
text: () => string;
|
|
106
|
+
copied: () => boolean;
|
|
107
|
+
isSupported: () => boolean;
|
|
108
|
+
copy: (value: string) => Promise<boolean>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Clipboard write helper with copied state.
|
|
112
|
+
*
|
|
113
|
+
* @fictReturn { text: 'signal', copied: 'signal', isSupported: 'signal' }
|
|
114
|
+
*/
|
|
115
|
+
declare function useClipboard(options?: UseClipboardOptions): UseClipboardReturn;
|
|
116
|
+
|
|
117
|
+
interface RefLike<T> {
|
|
118
|
+
current: T | null | undefined;
|
|
119
|
+
}
|
|
120
|
+
type MaybeRefOrAccessor<T> = T | null | undefined | RefLike<T> | (() => T | null | undefined);
|
|
121
|
+
type MaybeTarget<T> = MaybeRefOrAccessor<T> | MaybeAccessor<MaybeRefOrAccessor<T>>;
|
|
122
|
+
type MaybeElement = MaybeTarget<Element>;
|
|
123
|
+
type IgnoreTarget = MaybeElement | string;
|
|
124
|
+
|
|
125
|
+
interface UseClickOutsideOptions {
|
|
126
|
+
window?: Window | null;
|
|
127
|
+
document?: Document | null;
|
|
128
|
+
ignore?: IgnoreTarget | IgnoreTarget[];
|
|
129
|
+
capture?: boolean;
|
|
130
|
+
}
|
|
131
|
+
interface UseClickOutsideControls {
|
|
132
|
+
start: () => void;
|
|
133
|
+
stop: () => void;
|
|
134
|
+
active: () => boolean;
|
|
135
|
+
trigger: (event?: Event) => void;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Trigger handler when pointer interaction happens outside target elements.
|
|
139
|
+
*
|
|
140
|
+
* @fictReturn { active: 'signal' }
|
|
141
|
+
*/
|
|
142
|
+
declare function useClickOutside(target: MaybeElement | MaybeElement[], handler: (event: Event) => void, options?: UseClickOutsideOptions): UseClickOutsideControls;
|
|
143
|
+
|
|
144
|
+
type EventName = string | string[];
|
|
145
|
+
interface UseEventListenerOptions extends AddEventListenerOptions {
|
|
146
|
+
immediate?: boolean;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface UseEventListenerControls {
|
|
150
|
+
start: () => void;
|
|
151
|
+
stop: () => void;
|
|
152
|
+
active: () => boolean;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Bind event listeners with automatic teardown.
|
|
156
|
+
*
|
|
157
|
+
* @fictReturn { active: 'signal' }
|
|
158
|
+
*/
|
|
159
|
+
declare function useEventListener<E extends Event = Event>(target: MaybeTarget<EventTarget> | Array<MaybeTarget<EventTarget>>, event: EventName | MaybeAccessor<EventName>, handler: (event: E) => void, options?: UseEventListenerOptions): UseEventListenerControls;
|
|
160
|
+
|
|
161
|
+
interface UseFocusWithinOptions {
|
|
162
|
+
initialValue?: boolean;
|
|
163
|
+
}
|
|
164
|
+
interface UseFocusWithinReturn {
|
|
165
|
+
focused: () => boolean;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Track whether focus is currently inside a target element.
|
|
169
|
+
*
|
|
170
|
+
* @fictReturn { focused: 'signal' }
|
|
171
|
+
*/
|
|
172
|
+
declare function useFocusWithin(target: MaybeElement, options?: UseFocusWithinOptions): UseFocusWithinReturn;
|
|
173
|
+
|
|
174
|
+
interface UseHoverOptions {
|
|
175
|
+
initialValue?: boolean;
|
|
176
|
+
}
|
|
177
|
+
interface UseHoverReturn {
|
|
178
|
+
hovered: () => boolean;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Track hover state for an element target.
|
|
182
|
+
*
|
|
183
|
+
* @fictReturn { hovered: 'signal' }
|
|
184
|
+
*/
|
|
185
|
+
declare function useHover(target: MaybeElement, options?: UseHoverOptions): UseHoverReturn;
|
|
186
|
+
|
|
187
|
+
type KeyEventName = 'keydown' | 'keyup' | 'keypress';
|
|
188
|
+
type KeyFilter = string | string[] | ((event: KeyboardEvent) => boolean);
|
|
189
|
+
interface UseKeyPressOptions {
|
|
190
|
+
target?: MaybeTarget<EventTarget> | Array<MaybeTarget<EventTarget>> | null;
|
|
191
|
+
events?: KeyEventName | KeyEventName[];
|
|
192
|
+
exactMatch?: boolean;
|
|
193
|
+
passive?: boolean;
|
|
194
|
+
capture?: boolean;
|
|
195
|
+
preventDefault?: boolean;
|
|
196
|
+
immediate?: boolean;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Listen to keyboard events with key-filter matching.
|
|
200
|
+
*
|
|
201
|
+
* @fictReturn { active: 'signal' }
|
|
202
|
+
*/
|
|
203
|
+
declare function useKeyPress(filter: KeyFilter, handler: (event: KeyboardEvent) => void, options?: UseKeyPressOptions): UseEventListenerControls;
|
|
204
|
+
|
|
205
|
+
type Procedure = (...args: unknown[]) => void;
|
|
206
|
+
interface ControlledFn<T extends Procedure> {
|
|
207
|
+
run: (...args: Parameters<T>) => void;
|
|
208
|
+
cancel: () => void;
|
|
209
|
+
flush: () => void;
|
|
210
|
+
pending: () => boolean;
|
|
211
|
+
}
|
|
212
|
+
interface DebounceOptions {
|
|
213
|
+
leading?: boolean;
|
|
214
|
+
trailing?: boolean;
|
|
215
|
+
maxWait?: number;
|
|
216
|
+
}
|
|
217
|
+
interface ThrottleOptions {
|
|
218
|
+
leading?: boolean;
|
|
219
|
+
trailing?: boolean;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
type UseDebounceFnOptions = DebounceOptions;
|
|
223
|
+
/**
|
|
224
|
+
* Debounced function wrapper with lifecycle-aware cleanup.
|
|
225
|
+
*
|
|
226
|
+
* @fictReturn {}
|
|
227
|
+
*/
|
|
228
|
+
declare function useDebounceFn<T extends Procedure>(fn: T, wait: number, options?: UseDebounceFnOptions): ControlledFn<T>;
|
|
229
|
+
|
|
230
|
+
interface UseIntervalFnControls {
|
|
231
|
+
run: () => void;
|
|
232
|
+
cancel: () => void;
|
|
233
|
+
flush: () => void;
|
|
234
|
+
pending: () => boolean;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Create a managed interval with pause and resume controls.
|
|
238
|
+
*
|
|
239
|
+
* @fictReturn { pending: 'signal' }
|
|
240
|
+
*/
|
|
241
|
+
declare function useIntervalFn(callback: () => void, interval: number | MaybeAccessor<number>): UseIntervalFnControls;
|
|
242
|
+
|
|
243
|
+
interface UseRafFnOptions {
|
|
244
|
+
immediate?: boolean;
|
|
245
|
+
window?: Window | null;
|
|
246
|
+
}
|
|
247
|
+
interface UseRafFnReturn {
|
|
248
|
+
active: () => boolean;
|
|
249
|
+
start: () => void;
|
|
250
|
+
stop: () => void;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* requestAnimationFrame loop helper.
|
|
254
|
+
*
|
|
255
|
+
* @fictReturn { active: 'signal' }
|
|
256
|
+
*/
|
|
257
|
+
declare function useRafFn(callback: (delta: number, timestamp: number) => void, options?: UseRafFnOptions): UseRafFnReturn;
|
|
258
|
+
|
|
259
|
+
type UseThrottleFnOptions = ThrottleOptions;
|
|
260
|
+
/**
|
|
261
|
+
* Throttled function wrapper with lifecycle-aware cleanup.
|
|
262
|
+
*
|
|
263
|
+
* @fictReturn {}
|
|
264
|
+
*/
|
|
265
|
+
declare function useThrottleFn<T extends Procedure>(fn: T, wait: number, options?: UseThrottleFnOptions): ControlledFn<T>;
|
|
266
|
+
|
|
267
|
+
interface UseTimeoutFnControls {
|
|
268
|
+
run: () => void;
|
|
269
|
+
cancel: () => void;
|
|
270
|
+
flush: () => void;
|
|
271
|
+
pending: () => boolean;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Schedule a callback with timeout controls.
|
|
275
|
+
*
|
|
276
|
+
* @fictReturn { pending: 'signal' }
|
|
277
|
+
*/
|
|
278
|
+
declare function useTimeoutFn(callback: () => void, delay: number | MaybeAccessor<number>): UseTimeoutFnControls;
|
|
279
|
+
|
|
280
|
+
interface Serializer<T> {
|
|
281
|
+
read: (raw: string) => T;
|
|
282
|
+
write: (value: T) => string;
|
|
283
|
+
}
|
|
284
|
+
interface UseStorageOptions<T> {
|
|
285
|
+
window?: Window;
|
|
286
|
+
listenToStorageChanges?: boolean;
|
|
287
|
+
writeDefaults?: boolean;
|
|
288
|
+
serializer?: Serializer<T>;
|
|
289
|
+
onError?: (error: unknown) => void;
|
|
290
|
+
}
|
|
291
|
+
interface UseStorageReturn<T> {
|
|
292
|
+
value: () => T;
|
|
293
|
+
set: (next: T | ((prev: T) => T)) => void;
|
|
294
|
+
remove: () => void;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* localStorage-backed state.
|
|
299
|
+
*
|
|
300
|
+
* @fictReturn { value: 'signal' }
|
|
301
|
+
*/
|
|
302
|
+
declare function useLocalStorage<T>(key: string, initial: T, options?: UseStorageOptions<T>): UseStorageReturn<T>;
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* sessionStorage-backed state.
|
|
306
|
+
*
|
|
307
|
+
* @fictReturn { value: 'signal' }
|
|
308
|
+
*/
|
|
309
|
+
declare function useSessionStorage<T>(key: string, initial: T, options?: UseStorageOptions<T>): UseStorageReturn<T>;
|
|
310
|
+
|
|
311
|
+
interface UseStorageHookOptions<T> extends UseStorageOptions<T> {
|
|
312
|
+
storage?: Storage | null;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Generic storage-backed state.
|
|
316
|
+
*
|
|
317
|
+
* @fictReturn { value: 'signal' }
|
|
318
|
+
*/
|
|
319
|
+
declare function useStorage<T>(key: string, initial: T, options?: UseStorageHookOptions<T>): UseStorageReturn<T>;
|
|
320
|
+
|
|
321
|
+
interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {
|
|
322
|
+
window?: Window | null;
|
|
323
|
+
root?: MaybeTarget<Element>;
|
|
324
|
+
}
|
|
325
|
+
interface UseIntersectionObserverReturn {
|
|
326
|
+
entries: () => IntersectionObserverEntry[];
|
|
327
|
+
isSupported: () => boolean;
|
|
328
|
+
start: () => void;
|
|
329
|
+
stop: () => void;
|
|
330
|
+
active: () => boolean;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Observe element intersection changes.
|
|
334
|
+
*
|
|
335
|
+
* @fictReturn { entries: 'signal', isSupported: 'signal', active: 'signal' }
|
|
336
|
+
*/
|
|
337
|
+
declare function useIntersectionObserver(target: MaybeElement | MaybeElement[], callback?: (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void, options?: UseIntersectionObserverOptions): UseIntersectionObserverReturn;
|
|
338
|
+
|
|
339
|
+
interface UseMutationObserverOptions extends MutationObserverInit {
|
|
340
|
+
window?: Window | null;
|
|
341
|
+
}
|
|
342
|
+
interface UseMutationObserverReturn {
|
|
343
|
+
records: () => MutationRecord[];
|
|
344
|
+
isSupported: () => boolean;
|
|
345
|
+
active: () => boolean;
|
|
346
|
+
start: () => void;
|
|
347
|
+
stop: () => void;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Observe DOM mutations for target elements.
|
|
351
|
+
*
|
|
352
|
+
* @fictReturn { records: 'signal', isSupported: 'signal', active: 'signal' }
|
|
353
|
+
*/
|
|
354
|
+
declare function useMutationObserver(target: MaybeElement | MaybeElement[], callback?: (records: MutationRecord[], observer: MutationObserver) => void, options?: UseMutationObserverOptions): UseMutationObserverReturn;
|
|
355
|
+
|
|
356
|
+
interface UseResizeObserverOptions {
|
|
357
|
+
box?: ResizeObserverBoxOptions;
|
|
358
|
+
window?: Window | null;
|
|
359
|
+
}
|
|
360
|
+
interface UseResizeObserverReturn {
|
|
361
|
+
entries: () => ResizeObserverEntry[];
|
|
362
|
+
isSupported: () => boolean;
|
|
363
|
+
active: () => boolean;
|
|
364
|
+
start: () => void;
|
|
365
|
+
stop: () => void;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Observe element resize changes.
|
|
369
|
+
*
|
|
370
|
+
* @fictReturn { entries: 'signal', isSupported: 'signal', active: 'signal' }
|
|
371
|
+
*/
|
|
372
|
+
declare function useResizeObserver(target: MaybeElement | MaybeElement[], callback?: (entries: ResizeObserverEntry[], observer: ResizeObserver) => void, options?: UseResizeObserverOptions): UseResizeObserverReturn;
|
|
373
|
+
|
|
374
|
+
interface UseCounterOptions {
|
|
375
|
+
min?: number;
|
|
376
|
+
max?: number;
|
|
377
|
+
}
|
|
378
|
+
interface UseCounterReturn {
|
|
379
|
+
count: () => number;
|
|
380
|
+
set: (next: number) => void;
|
|
381
|
+
inc: (delta?: number) => void;
|
|
382
|
+
dec: (delta?: number) => void;
|
|
383
|
+
reset: () => void;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Number state helper with optional min/max bounds.
|
|
387
|
+
*
|
|
388
|
+
* @fictReturn { count: 'signal' }
|
|
389
|
+
*/
|
|
390
|
+
declare function useCounter(initial?: number, options?: UseCounterOptions): UseCounterReturn;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Track the previous value of a reactive source.
|
|
394
|
+
*
|
|
395
|
+
* @fictReturn 'signal'
|
|
396
|
+
*/
|
|
397
|
+
declare function usePrevious<T>(value: T | MaybeAccessor<T>): () => T | undefined;
|
|
398
|
+
|
|
399
|
+
interface UseToggleReturn {
|
|
400
|
+
value: () => boolean;
|
|
401
|
+
toggle: () => void;
|
|
402
|
+
set: (next: boolean) => void;
|
|
403
|
+
setTrue: () => void;
|
|
404
|
+
setFalse: () => void;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Boolean state helper.
|
|
408
|
+
*
|
|
409
|
+
* @fictReturn { value: 'signal' }
|
|
410
|
+
*/
|
|
411
|
+
declare function useToggle(initial?: boolean): UseToggleReturn;
|
|
412
|
+
|
|
413
|
+
interface VirtualItem<T> {
|
|
414
|
+
index: number;
|
|
415
|
+
data: T;
|
|
416
|
+
start: number;
|
|
417
|
+
end: number;
|
|
418
|
+
}
|
|
419
|
+
interface UseVirtualListOptions {
|
|
420
|
+
itemHeight: number;
|
|
421
|
+
containerHeight: number | MaybeAccessor<number>;
|
|
422
|
+
overscan?: number;
|
|
423
|
+
initialScrollTop?: number;
|
|
424
|
+
}
|
|
425
|
+
interface UseVirtualListReturn<T> {
|
|
426
|
+
list: () => VirtualItem<T>[];
|
|
427
|
+
totalHeight: () => number;
|
|
428
|
+
start: () => number;
|
|
429
|
+
end: () => number;
|
|
430
|
+
scrollTop: () => number;
|
|
431
|
+
setScrollTop: (value: number) => void;
|
|
432
|
+
scrollTo: (index: number) => void;
|
|
433
|
+
onScroll: (event: Event) => void;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Fixed-height virtual list state helper.
|
|
437
|
+
*
|
|
438
|
+
* @fictReturn { list: 'memo', totalHeight: 'memo', start: 'memo', end: 'memo', scrollTop: 'signal' }
|
|
439
|
+
*/
|
|
440
|
+
declare function useVirtualList<T>(source: T[] | MaybeAccessor<T[]>, options: UseVirtualListOptions): UseVirtualListReturn<T>;
|
|
441
|
+
|
|
442
|
+
interface UseDocumentVisibilityOptions {
|
|
443
|
+
document?: Document | null;
|
|
444
|
+
initialVisibility?: DocumentVisibilityState;
|
|
445
|
+
}
|
|
446
|
+
interface UseDocumentVisibilityReturn {
|
|
447
|
+
visibility: () => DocumentVisibilityState;
|
|
448
|
+
hidden: () => boolean;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Track page visibility state.
|
|
452
|
+
*
|
|
453
|
+
* @fictReturn { visibility: 'signal', hidden: 'memo' }
|
|
454
|
+
*/
|
|
455
|
+
declare function useDocumentVisibility(options?: UseDocumentVisibilityOptions): UseDocumentVisibilityReturn;
|
|
456
|
+
|
|
457
|
+
interface UseMediaQueryOptions {
|
|
458
|
+
window?: Window | null;
|
|
459
|
+
initialValue?: boolean;
|
|
460
|
+
}
|
|
461
|
+
interface UseMediaQueryReturn {
|
|
462
|
+
matches: () => boolean;
|
|
463
|
+
query: () => string;
|
|
464
|
+
isSupported: () => boolean;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Reactive media query matching state.
|
|
468
|
+
*
|
|
469
|
+
* @fictReturn { matches: 'signal', query: 'signal', isSupported: 'signal' }
|
|
470
|
+
*/
|
|
471
|
+
declare function useMediaQuery(mediaQuery: string | MaybeAccessor<string>, options?: UseMediaQueryOptions): UseMediaQueryReturn;
|
|
472
|
+
|
|
473
|
+
interface NetworkConnectionLike extends EventTarget {
|
|
474
|
+
downlink?: number;
|
|
475
|
+
effectiveType?: string;
|
|
476
|
+
rtt?: number;
|
|
477
|
+
saveData?: boolean;
|
|
478
|
+
type?: string;
|
|
479
|
+
}
|
|
480
|
+
interface NavigatorWithConnection extends Navigator {
|
|
481
|
+
connection?: NetworkConnectionLike;
|
|
482
|
+
mozConnection?: NetworkConnectionLike;
|
|
483
|
+
webkitConnection?: NetworkConnectionLike;
|
|
484
|
+
}
|
|
485
|
+
interface UseNetworkOptions {
|
|
486
|
+
window?: Window | null;
|
|
487
|
+
navigator?: NavigatorWithConnection | null;
|
|
488
|
+
}
|
|
489
|
+
interface UseNetworkReturn {
|
|
490
|
+
online: () => boolean;
|
|
491
|
+
downlink: () => number | null;
|
|
492
|
+
effectiveType: () => string | null;
|
|
493
|
+
rtt: () => number | null;
|
|
494
|
+
saveData: () => boolean;
|
|
495
|
+
type: () => string | null;
|
|
496
|
+
isSupported: () => boolean;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Reactive network status state.
|
|
500
|
+
*
|
|
501
|
+
* @fictReturn { online: 'signal', downlink: 'signal', effectiveType: 'signal', rtt: 'signal', saveData: 'signal', type: 'signal', isSupported: 'signal' }
|
|
502
|
+
*/
|
|
503
|
+
declare function useNetwork(options?: UseNetworkOptions): UseNetworkReturn;
|
|
504
|
+
|
|
505
|
+
interface ScrollPosition {
|
|
506
|
+
x: number;
|
|
507
|
+
y: number;
|
|
508
|
+
}
|
|
509
|
+
interface UseScrollOptions {
|
|
510
|
+
target?: MaybeTarget<Element | Document | Window> | null;
|
|
511
|
+
window?: Window | null;
|
|
512
|
+
initialX?: number;
|
|
513
|
+
initialY?: number;
|
|
514
|
+
shouldUpdate?: (next: ScrollPosition, prev: ScrollPosition) => boolean;
|
|
515
|
+
passive?: boolean;
|
|
516
|
+
capture?: boolean;
|
|
517
|
+
}
|
|
518
|
+
interface UseScrollReturn {
|
|
519
|
+
x: () => number;
|
|
520
|
+
y: () => number;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Track scroll position for window, document or element targets.
|
|
524
|
+
*
|
|
525
|
+
* @fictReturn { x: 'signal', y: 'signal' }
|
|
526
|
+
*/
|
|
527
|
+
declare function useScroll(options?: UseScrollOptions): UseScrollReturn;
|
|
528
|
+
|
|
529
|
+
interface PermissionNavigator {
|
|
530
|
+
permissions?: {
|
|
531
|
+
query: (permissionDesc: PermissionDescriptor) => Promise<PermissionStatus>;
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
type PermissionInput = PermissionDescriptor | string;
|
|
535
|
+
interface UsePermissionOptions {
|
|
536
|
+
navigator?: PermissionNavigator | null;
|
|
537
|
+
initialState?: PermissionState;
|
|
538
|
+
immediate?: boolean;
|
|
539
|
+
}
|
|
540
|
+
interface UsePermissionReturn {
|
|
541
|
+
state: () => PermissionState;
|
|
542
|
+
isSupported: () => boolean;
|
|
543
|
+
query: () => Promise<PermissionStatus | null>;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Reactive Permissions API helper.
|
|
547
|
+
*
|
|
548
|
+
* @fictReturn { state: 'signal', isSupported: 'signal' }
|
|
549
|
+
*/
|
|
550
|
+
declare function usePermission(permission: PermissionInput | MaybeAccessor<PermissionInput>, options?: UsePermissionOptions): UsePermissionReturn;
|
|
551
|
+
|
|
552
|
+
interface GeolocationNavigator {
|
|
553
|
+
geolocation?: {
|
|
554
|
+
watchPosition: (success: PositionCallback, error?: PositionErrorCallback, options?: PositionOptions) => number;
|
|
555
|
+
clearWatch: (watchId: number) => void;
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
interface GeolocationCoordsState {
|
|
559
|
+
accuracy: number;
|
|
560
|
+
latitude: number;
|
|
561
|
+
longitude: number;
|
|
562
|
+
altitude: number | null;
|
|
563
|
+
altitudeAccuracy: number | null;
|
|
564
|
+
heading: number | null;
|
|
565
|
+
speed: number | null;
|
|
566
|
+
}
|
|
567
|
+
interface UseGeolocationOptions extends PositionOptions {
|
|
568
|
+
navigator?: GeolocationNavigator | null;
|
|
569
|
+
immediate?: boolean;
|
|
570
|
+
}
|
|
571
|
+
interface UseGeolocationReturn {
|
|
572
|
+
isSupported: () => boolean;
|
|
573
|
+
coords: () => GeolocationCoordsState;
|
|
574
|
+
locatedAt: () => number | null;
|
|
575
|
+
error: () => GeolocationPositionError | null;
|
|
576
|
+
active: () => boolean;
|
|
577
|
+
resume: () => void;
|
|
578
|
+
pause: () => void;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Reactive Geolocation API wrapper.
|
|
582
|
+
*
|
|
583
|
+
* @fictReturn { isSupported: 'signal', coords: 'signal', locatedAt: 'signal', error: 'signal', active: 'signal' }
|
|
584
|
+
*/
|
|
585
|
+
declare function useGeolocation(options?: UseGeolocationOptions): UseGeolocationReturn;
|
|
586
|
+
|
|
587
|
+
declare const DEFAULT_IDLE_EVENTS: readonly ["mousemove", "mousedown", "resize", "keydown", "touchstart", "wheel", "pointerdown"];
|
|
588
|
+
interface UseIdleOptions {
|
|
589
|
+
timeout?: number;
|
|
590
|
+
window?: Window | null;
|
|
591
|
+
document?: Document | null;
|
|
592
|
+
events?: Array<(typeof DEFAULT_IDLE_EVENTS)[number] | string>;
|
|
593
|
+
listenForVisibilityChange?: boolean;
|
|
594
|
+
immediate?: boolean;
|
|
595
|
+
initialState?: boolean;
|
|
596
|
+
}
|
|
597
|
+
interface UseIdleReturn {
|
|
598
|
+
idle: () => boolean;
|
|
599
|
+
lastActive: () => number | null;
|
|
600
|
+
isSupported: () => boolean;
|
|
601
|
+
active: () => boolean;
|
|
602
|
+
reset: () => void;
|
|
603
|
+
pause: () => void;
|
|
604
|
+
resume: () => void;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Track user idle state using activity events + timer.
|
|
608
|
+
*
|
|
609
|
+
* @fictReturn { idle: 'signal', lastActive: 'signal', isSupported: 'signal', active: 'signal' }
|
|
610
|
+
*/
|
|
611
|
+
declare function useIdle(options?: UseIdleOptions): UseIdleReturn;
|
|
612
|
+
|
|
613
|
+
interface UseSizeOptions {
|
|
614
|
+
window?: Window | null;
|
|
615
|
+
box?: ResizeObserverBoxOptions;
|
|
616
|
+
initialWidth?: number;
|
|
617
|
+
initialHeight?: number;
|
|
618
|
+
initialTop?: number;
|
|
619
|
+
initialLeft?: number;
|
|
620
|
+
initialX?: number;
|
|
621
|
+
initialY?: number;
|
|
622
|
+
immediate?: boolean;
|
|
623
|
+
}
|
|
624
|
+
interface UseSizeReturn {
|
|
625
|
+
width: () => number;
|
|
626
|
+
height: () => number;
|
|
627
|
+
top: () => number;
|
|
628
|
+
left: () => number;
|
|
629
|
+
x: () => number;
|
|
630
|
+
y: () => number;
|
|
631
|
+
isSupported: () => boolean;
|
|
632
|
+
active: () => boolean;
|
|
633
|
+
update: () => void;
|
|
634
|
+
start: () => void;
|
|
635
|
+
stop: () => void;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Track element size/position reactively.
|
|
639
|
+
*
|
|
640
|
+
* @fictReturn { width: 'signal', height: 'signal', top: 'signal', left: 'signal', x: 'signal', y: 'signal', isSupported: 'signal', active: 'signal' }
|
|
641
|
+
*/
|
|
642
|
+
declare function useSize(target: MaybeElement | null, options?: UseSizeOptions): UseSizeReturn;
|
|
643
|
+
|
|
644
|
+
type WebSocketStatus = 'CONNECTING' | 'OPEN' | 'CLOSING' | 'CLOSED';
|
|
645
|
+
interface UseWebSocketReconnectOptions {
|
|
646
|
+
retries?: number;
|
|
647
|
+
delay?: number | ((attempt: number) => number);
|
|
648
|
+
}
|
|
649
|
+
type SerializablePayload = string | ArrayBufferLike | Blob | ArrayBufferView;
|
|
650
|
+
type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'close' | 'readyState' | 'binaryType' | 'OPEN' | 'CONNECTING' | 'CLOSING' | 'CLOSED'>;
|
|
651
|
+
type WebSocketConstructor = new (url: string | URL, protocols?: string | string[]) => WebSocketLike;
|
|
652
|
+
interface UseWebSocketOptions<TIncoming = unknown, TOutgoing = SerializablePayload> {
|
|
653
|
+
window?: Window | null;
|
|
654
|
+
webSocket?: WebSocketConstructor | null;
|
|
655
|
+
protocols?: string | string[];
|
|
656
|
+
immediate?: boolean;
|
|
657
|
+
autoReconnect?: boolean | UseWebSocketReconnectOptions;
|
|
658
|
+
binaryType?: BinaryType;
|
|
659
|
+
initialData?: TIncoming | null;
|
|
660
|
+
serialize?: (payload: TOutgoing) => SerializablePayload;
|
|
661
|
+
deserialize?: (event: MessageEvent) => TIncoming;
|
|
662
|
+
onOpen?: (event: Event) => void;
|
|
663
|
+
onMessage?: (data: TIncoming, event: MessageEvent) => void;
|
|
664
|
+
onError?: (event: Event) => void;
|
|
665
|
+
onClose?: (event: CloseEvent) => void;
|
|
666
|
+
}
|
|
667
|
+
interface UseWebSocketReturn<TIncoming = unknown, TOutgoing = SerializablePayload> {
|
|
668
|
+
data: () => TIncoming | null;
|
|
669
|
+
error: () => Event | null;
|
|
670
|
+
status: () => WebSocketStatus;
|
|
671
|
+
isSupported: () => boolean;
|
|
672
|
+
reconnectCount: () => number;
|
|
673
|
+
open: () => boolean;
|
|
674
|
+
close: (code?: number, reason?: string) => void;
|
|
675
|
+
reconnect: () => boolean;
|
|
676
|
+
send: (payload: TOutgoing) => boolean;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Reactive WebSocket connection helper.
|
|
680
|
+
*
|
|
681
|
+
* @fictReturn { data: 'signal', error: 'signal', status: 'signal', isSupported: 'signal', reconnectCount: 'signal' }
|
|
682
|
+
*/
|
|
683
|
+
declare function useWebSocket<TIncoming = unknown, TOutgoing = SerializablePayload>(url: MaybeAccessor<string | URL | null | undefined>, options?: UseWebSocketOptions<TIncoming, TOutgoing>): UseWebSocketReturn<TIncoming, TOutgoing>;
|
|
684
|
+
|
|
685
|
+
interface UseWindowSizeOptions {
|
|
686
|
+
window?: Window | null;
|
|
687
|
+
initialWidth?: number;
|
|
688
|
+
initialHeight?: number;
|
|
689
|
+
}
|
|
690
|
+
interface UseWindowSizeReturn {
|
|
691
|
+
width: () => number;
|
|
692
|
+
height: () => number;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Reactive window size state.
|
|
696
|
+
*
|
|
697
|
+
* @fictReturn { width: 'signal', height: 'signal' }
|
|
698
|
+
*/
|
|
699
|
+
declare function useWindowSize(options?: UseWindowSizeOptions): UseWindowSizeReturn;
|
|
700
|
+
|
|
701
|
+
interface UseWindowScrollOptions extends Omit<UseScrollOptions, 'target'> {
|
|
702
|
+
window?: Window | null;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Track scroll position for window only.
|
|
706
|
+
*
|
|
707
|
+
* @fictReturn { x: 'signal', y: 'signal' }
|
|
708
|
+
*/
|
|
709
|
+
declare function useWindowScroll(options?: UseWindowScrollOptions): UseScrollReturn;
|
|
710
|
+
|
|
711
|
+
interface UseTitleOptions {
|
|
712
|
+
document?: Document | null;
|
|
713
|
+
restoreOnUnmount?: boolean;
|
|
714
|
+
}
|
|
715
|
+
interface UseTitleReturn {
|
|
716
|
+
title: () => string;
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Reactive document title helper.
|
|
720
|
+
*
|
|
721
|
+
* @fictReturn { title: 'signal' }
|
|
722
|
+
*/
|
|
723
|
+
declare function useTitle(value: string | MaybeAccessor<string>, options?: UseTitleOptions): UseTitleReturn;
|
|
724
|
+
|
|
725
|
+
interface UseFullscreenOptions {
|
|
726
|
+
target?: MaybeElement | null;
|
|
727
|
+
document?: Document | null;
|
|
728
|
+
autoExit?: boolean;
|
|
729
|
+
}
|
|
730
|
+
interface UseFullscreenReturn {
|
|
731
|
+
isSupported: () => boolean;
|
|
732
|
+
isFullscreen: () => boolean;
|
|
733
|
+
enter: () => Promise<boolean>;
|
|
734
|
+
exit: () => Promise<boolean>;
|
|
735
|
+
toggle: () => Promise<boolean>;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Fullscreen API wrapper for target elements.
|
|
739
|
+
*
|
|
740
|
+
* @fictReturn { isSupported: 'signal', isFullscreen: 'signal' }
|
|
741
|
+
*/
|
|
742
|
+
declare function useFullscreen(options?: UseFullscreenOptions): UseFullscreenReturn;
|
|
743
|
+
|
|
744
|
+
export { type GeolocationCoordsState, type KeyEventName, type KeyFilter, type MountCallback, type PermissionInput, type ScrollPosition, type UnmountCallback, type UseAsyncStateOptions, type UseAsyncStateReturn, type UseClickOutsideControls, type UseClickOutsideOptions, type UseClipboardOptions, type UseClipboardReturn, type UseCounterOptions, type UseCounterReturn, type UseDebounceFnOptions, type UseDocumentVisibilityOptions, type UseDocumentVisibilityReturn, type UseEventListenerControls, type UseFetchOptions, type UseFetchReturn, type UseFocusWithinOptions, type UseFocusWithinReturn, type UseFullscreenOptions, type UseFullscreenReturn, type UseGeolocationOptions, type UseGeolocationReturn, type UseHoverOptions, type UseHoverReturn, type UseIdleOptions, type UseIdleReturn, type UseIntersectionObserverOptions, type UseIntersectionObserverReturn, type UseIntervalFnControls, type UseKeyPressOptions, type UseMediaQueryOptions, type UseMediaQueryReturn, type UseMutationObserverOptions, type UseMutationObserverReturn, type UseNetworkOptions, type UseNetworkReturn, type UsePermissionOptions, type UsePermissionReturn, type UseRafFnOptions, type UseRafFnReturn, type UseRequestOptions, type UseRequestReturn, type UseResizeObserverOptions, type UseResizeObserverReturn, type UseScrollOptions, type UseScrollReturn, type UseSizeOptions, type UseSizeReturn, type UseStorageHookOptions, type UseThrottleFnOptions, type UseTimeoutFnControls, type UseTitleOptions, type UseTitleReturn, type UseToggleReturn, type UseVirtualListOptions, type UseVirtualListReturn, type UseWebSocketOptions, type UseWebSocketReconnectOptions, type UseWebSocketReturn, type UseWindowScrollOptions, type UseWindowSizeOptions, type UseWindowSizeReturn, type VirtualItem, type WebSocketStatus, useAsyncState, useClickOutside, useClipboard, useCounter, useDebounceFn, useDocumentVisibility, useEventListener, useFetch, useFocusWithin, useFullscreen, useGeolocation, useHover, useIdle, useIntersectionObserver, useIntervalFn, useKeyPress, useLocalStorage, useMediaQuery, useMount, useMutationObserver, useNetwork, usePermission, usePrevious, useRafFn, useRequest, useResizeObserver, useScroll, useSessionStorage, useSize, useStorage, useThrottleFn, useTimeoutFn, useTitle, useToggle, useUnmount, useVirtualList, useWebSocket, useWindowScroll, useWindowSize };
|