@reactuses/core 1.0.1
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 +24 -0
- package/README.md +73 -0
- package/index.cjs +2215 -0
- package/index.d.ts +588 -0
- package/index.mjs +2147 -0
- package/package.json +42 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { useEffect, useLayoutEffect, Dispatch, SetStateAction, MutableRefObject, DependencyList, EffectCallback, RefObject, CSSProperties } from 'react';
|
|
3
|
+
import * as lodash from 'lodash';
|
|
4
|
+
|
|
5
|
+
declare function usePrevious<T>(state: T): T | undefined;
|
|
6
|
+
|
|
7
|
+
declare function useMarkdown(filepath: string): string;
|
|
8
|
+
|
|
9
|
+
declare function useLatest<T>(value: T): React.MutableRefObject<T>;
|
|
10
|
+
|
|
11
|
+
declare function useFirstMountState(): boolean;
|
|
12
|
+
|
|
13
|
+
declare const _default$3: typeof useEffect | typeof react.useLayoutEffect;
|
|
14
|
+
|
|
15
|
+
declare const _default$2: typeof react.useEffect | typeof useLayoutEffect;
|
|
16
|
+
|
|
17
|
+
interface Serializer<T> {
|
|
18
|
+
read(raw: string): T;
|
|
19
|
+
write(value: T): string;
|
|
20
|
+
}
|
|
21
|
+
interface UseStorageOptions<T> {
|
|
22
|
+
/**
|
|
23
|
+
* Custom data serialization
|
|
24
|
+
*/
|
|
25
|
+
serializer?: Serializer<T>;
|
|
26
|
+
/**
|
|
27
|
+
* On error callback
|
|
28
|
+
*
|
|
29
|
+
* Default log error to `console.error`
|
|
30
|
+
*/
|
|
31
|
+
onError?: (error: unknown) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare function useLocalStorage(key: string, defaults: string, options?: UseStorageOptions<string>): readonly [string | null, Dispatch<SetStateAction<string | null>>];
|
|
35
|
+
declare function useLocalStorage(key: string, defaults: number, options?: UseStorageOptions<number>): readonly [number | null, Dispatch<SetStateAction<number | null>>];
|
|
36
|
+
declare function useLocalStorage(key: string, defaults: boolean, options?: UseStorageOptions<boolean>): readonly [boolean | null, Dispatch<SetStateAction<boolean | null>>];
|
|
37
|
+
declare function useLocalStorage<T>(key: string, defaults: T, options?: UseStorageOptions<T>): readonly [T | null, Dispatch<SetStateAction<T | null>>];
|
|
38
|
+
declare function useLocalStorage<T = unknown>(key: string, defaults: null, options?: UseStorageOptions<T>): readonly [T | null, Dispatch<SetStateAction<T | null>>];
|
|
39
|
+
|
|
40
|
+
declare function useSessionStorage(key: string, defaults: string, options?: UseStorageOptions<string>): readonly [string | null, Dispatch<SetStateAction<string | null>>];
|
|
41
|
+
declare function useSessionStorage(key: string, defaults: number, options?: UseStorageOptions<number>): readonly [number | null, Dispatch<SetStateAction<number | null>>];
|
|
42
|
+
declare function useSessionStorage(key: string, defaults: boolean, options?: UseStorageOptions<boolean>): readonly [boolean | null, Dispatch<SetStateAction<boolean | null>>];
|
|
43
|
+
declare function useSessionStorage<T>(key: string, defaults: T, options?: UseStorageOptions<T>): readonly [T | null, Dispatch<SetStateAction<T | null>>];
|
|
44
|
+
declare function useSessionStorage<T = unknown>(key: string, defaults: null, options?: UseStorageOptions<T>): readonly [T | null, Dispatch<SetStateAction<T | null>>];
|
|
45
|
+
|
|
46
|
+
declare type Fn = (this: any, ...args: any[]) => any;
|
|
47
|
+
declare type Stoppable = [boolean, Fn, Fn];
|
|
48
|
+
|
|
49
|
+
declare function useEvent<T extends Fn>(fn: T): T;
|
|
50
|
+
|
|
51
|
+
declare function useToggle(initialValue: boolean): [boolean, (nextValue?: any) => void];
|
|
52
|
+
|
|
53
|
+
declare function useInterval(callback: () => void, delay?: number | null, options?: {
|
|
54
|
+
immediate?: boolean;
|
|
55
|
+
}): void;
|
|
56
|
+
|
|
57
|
+
interface UseDarkOptions<T> {
|
|
58
|
+
/**
|
|
59
|
+
* CSS Selector for the target element applying to
|
|
60
|
+
*
|
|
61
|
+
* @default 'html'
|
|
62
|
+
*/
|
|
63
|
+
selector?: string;
|
|
64
|
+
/**
|
|
65
|
+
* HTML attribute applying the target element
|
|
66
|
+
*
|
|
67
|
+
* @default 'class'
|
|
68
|
+
*/
|
|
69
|
+
attribute?: string;
|
|
70
|
+
/**
|
|
71
|
+
* The initial value write the target element
|
|
72
|
+
* @default 'light | dark'
|
|
73
|
+
*/
|
|
74
|
+
initialValue?: T;
|
|
75
|
+
/**
|
|
76
|
+
* Key to persist the data into localStorage/sessionStorage.
|
|
77
|
+
*
|
|
78
|
+
* @default 'reactuses-color-scheme'
|
|
79
|
+
*/
|
|
80
|
+
storageKey?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Storage object, can be localStorage or sessionStorage
|
|
83
|
+
*
|
|
84
|
+
* @default localStorage
|
|
85
|
+
*/
|
|
86
|
+
storage?: () => Storage;
|
|
87
|
+
}
|
|
88
|
+
declare function useDarkMode<T extends string | "light" | "dark">(options?: UseDarkOptions<T>): readonly [T | null, react.Dispatch<react.SetStateAction<T | null>>];
|
|
89
|
+
|
|
90
|
+
declare function useMediaQuery(query: string, defaultState?: boolean): boolean;
|
|
91
|
+
|
|
92
|
+
declare function usePreferredDark(defaultState?: boolean): boolean;
|
|
93
|
+
|
|
94
|
+
declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
95
|
+
|
|
96
|
+
declare function useMount(fn: () => void): void;
|
|
97
|
+
|
|
98
|
+
declare function useUnmount(fn: () => void): void;
|
|
99
|
+
|
|
100
|
+
interface ThrottleSettings {
|
|
101
|
+
leading?: boolean | undefined;
|
|
102
|
+
trailing?: boolean | undefined;
|
|
103
|
+
}
|
|
104
|
+
interface DebounceSettings {
|
|
105
|
+
leading?: boolean;
|
|
106
|
+
trailing?: boolean;
|
|
107
|
+
maxWait?: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
declare function useThrottle<T>(value: T, wait?: number, options?: ThrottleSettings): T;
|
|
111
|
+
|
|
112
|
+
declare function useThrottleFn<T extends (...args: any) => any>(fn: T, wait?: number, options?: ThrottleSettings): {
|
|
113
|
+
run: lodash.DebouncedFunc<(...args_0: Parameters<T>) => ReturnType<T>>;
|
|
114
|
+
cancel: () => void;
|
|
115
|
+
flush: () => ReturnType<T> | undefined;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
declare function useDebounce<T>(value: T, wait?: number, options?: DebounceSettings): T;
|
|
119
|
+
|
|
120
|
+
declare function useDebounceFn<T extends (...args: any) => any>(fn: T, wait?: number, options?: DebounceSettings): {
|
|
121
|
+
run: lodash.DebouncedFunc<(...args_0: Parameters<T>) => ReturnType<T>>;
|
|
122
|
+
cancel: () => void;
|
|
123
|
+
flush: () => ReturnType<T> | undefined;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
declare function useRafState<S>(initialState: S | (() => S)): readonly [S, Dispatch<SetStateAction<S>>];
|
|
127
|
+
|
|
128
|
+
declare function useUpdate(): () => void;
|
|
129
|
+
|
|
130
|
+
interface UseTimeoutFnOptions {
|
|
131
|
+
/**
|
|
132
|
+
* Start the timer immediate after calling this function
|
|
133
|
+
*
|
|
134
|
+
* @default false
|
|
135
|
+
*/
|
|
136
|
+
immediate?: boolean;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Wrapper for `setTimeout` with controls.
|
|
140
|
+
*
|
|
141
|
+
* @param cb
|
|
142
|
+
* @param interval
|
|
143
|
+
* @param options
|
|
144
|
+
*/
|
|
145
|
+
declare function useTimeoutFn(cb: (...args: unknown[]) => any, interval: number, options?: UseTimeoutFnOptions): Stoppable;
|
|
146
|
+
|
|
147
|
+
declare function useTimeout(ms?: number, options?: UseTimeoutFnOptions): Stoppable;
|
|
148
|
+
|
|
149
|
+
declare function useMountedState(): () => boolean;
|
|
150
|
+
|
|
151
|
+
declare type TargetValue<T> = T | undefined | null;
|
|
152
|
+
declare type TargetType = HTMLElement | Element | Window | Document | EventTarget;
|
|
153
|
+
declare type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
|
|
154
|
+
|
|
155
|
+
declare type Target = BasicTarget<HTMLElement | Element | Window | Document | EventTarget>;
|
|
156
|
+
declare function useEventListener<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, element?: Window, options?: boolean | AddEventListenerOptions): void;
|
|
157
|
+
declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, element: Document, options?: boolean | AddEventListenerOptions): void;
|
|
158
|
+
declare function useEventListener<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLDivElement>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void, element: T, options?: boolean | AddEventListenerOptions): void;
|
|
159
|
+
declare function useEventListener<K extends keyof ElementEventMap>(eventName: K, handler: (event: ElementEventMap[K]) => void, element: Element, options?: boolean | AddEventListenerOptions): void;
|
|
160
|
+
declare function useEventListener<K = Event>(eventName: string, handler: (event: K) => void, element: EventTarget | null | undefined, options?: boolean | AddEventListenerOptions): void;
|
|
161
|
+
declare function useEventListener(eventName: string, handler: (...p: any) => void, element?: Target, options?: boolean | AddEventListenerOptions): void;
|
|
162
|
+
|
|
163
|
+
declare function useCounter(initialValue?: number | (() => number), max?: number | null, min?: number | null): readonly [number, (newState: number | ((prev: number) => number) | (() => number)) => void, (delta?: number) => void, (delta?: number) => void, () => void];
|
|
164
|
+
|
|
165
|
+
declare type RafLoopReturns = readonly [() => void, () => void, () => boolean];
|
|
166
|
+
declare function useRafFn(callback: FrameRequestCallback, initiallyActive?: boolean): RafLoopReturns;
|
|
167
|
+
|
|
168
|
+
interface IDisposable {
|
|
169
|
+
dispose(): void;
|
|
170
|
+
}
|
|
171
|
+
interface IEvent<T, U = void> {
|
|
172
|
+
(listener: (arg1: T, arg2: U) => any): IDisposable;
|
|
173
|
+
}
|
|
174
|
+
declare function useEventEmitter<T, U = void>(): readonly [IEvent<T, U>, (arg1: T, arg2: U) => void, () => void];
|
|
175
|
+
|
|
176
|
+
declare function useFavicon(href: string, baseUrl?: string, rel?: string): void;
|
|
177
|
+
|
|
178
|
+
declare function useMutationObserver(callback: MutationCallback, target: BasicTarget, options?: MutationObserverInit): () => void;
|
|
179
|
+
|
|
180
|
+
declare type DepsEqualFnType<TDeps extends DependencyList> = (prevDeps: TDeps, nextDeps: TDeps) => boolean;
|
|
181
|
+
declare function useCustomCompareEffect<TDeps extends DependencyList>(effect: EffectCallback, deps: TDeps, depsEqual: DepsEqualFnType<TDeps>): void;
|
|
182
|
+
|
|
183
|
+
declare function useDeepCompareEffect(effect: EffectCallback, deps: DependencyList): void;
|
|
184
|
+
|
|
185
|
+
declare function useTitle(title: string): void;
|
|
186
|
+
|
|
187
|
+
interface UseScriptTagOptions {
|
|
188
|
+
/**
|
|
189
|
+
* Load the script immediately
|
|
190
|
+
*
|
|
191
|
+
* @default true
|
|
192
|
+
*/
|
|
193
|
+
immediate?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Add `async` attribute to the script tag
|
|
196
|
+
*
|
|
197
|
+
* @default true
|
|
198
|
+
*/
|
|
199
|
+
async?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Script type
|
|
202
|
+
*
|
|
203
|
+
* @default 'text/javascript'
|
|
204
|
+
*/
|
|
205
|
+
type?: string;
|
|
206
|
+
/**
|
|
207
|
+
* Manual controls the timing of loading and unloading
|
|
208
|
+
*
|
|
209
|
+
* @default false
|
|
210
|
+
*/
|
|
211
|
+
manual?: boolean;
|
|
212
|
+
crossOrigin?: "anonymous" | "use-credentials";
|
|
213
|
+
referrerPolicy?: "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
|
|
214
|
+
noModule?: boolean;
|
|
215
|
+
defer?: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Add custom attribute to the script tag
|
|
218
|
+
*
|
|
219
|
+
*/
|
|
220
|
+
attrs?: Record<string, string>;
|
|
221
|
+
}
|
|
222
|
+
declare type Status = "idle" | "loading" | "ready" | "error";
|
|
223
|
+
declare function useScriptTag(src: string, onLoaded?: (el: HTMLScriptElement) => void, options?: UseScriptTagOptions): readonly [HTMLScriptElement | null, Status, (waitForScriptLoad?: boolean) => Promise<HTMLScriptElement | boolean>, () => void];
|
|
224
|
+
|
|
225
|
+
declare type IState = PermissionState | "";
|
|
226
|
+
declare type DescriptorNamePolyfill = "accelerometer" | "accessibility-events" | "ambient-light-sensor" | "background-sync" | "camera" | "clipboard-read" | "clipboard-write" | "gyroscope" | "magnetometer" | "microphone" | "notifications" | "payment-handler" | "persistent-storage" | "push" | "speaker";
|
|
227
|
+
declare type GeneralPermissionDescriptor = PermissionDescriptor | {
|
|
228
|
+
name: DescriptorNamePolyfill;
|
|
229
|
+
};
|
|
230
|
+
declare function usePermission(permissionDesc: GeneralPermissionDescriptor | GeneralPermissionDescriptor["name"]): IState;
|
|
231
|
+
|
|
232
|
+
interface Options$1 {
|
|
233
|
+
isPreventDefault?: boolean;
|
|
234
|
+
delay?: number;
|
|
235
|
+
}
|
|
236
|
+
declare function useLongPress(callback: (e: TouchEvent | MouseEvent) => void, { isPreventDefault, delay }?: Options$1): {
|
|
237
|
+
readonly onMouseDown: (e: any) => void;
|
|
238
|
+
readonly onTouchStart: (e: any) => void;
|
|
239
|
+
readonly onMouseUp: () => void;
|
|
240
|
+
readonly onMouseLeave: () => void;
|
|
241
|
+
readonly onTouchEnd: () => void;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
declare function useObjectUrl(object: Blob | MediaSource | undefined): string | undefined;
|
|
245
|
+
|
|
246
|
+
declare function useIdle(ms?: number, initialState?: boolean, events?: (keyof WindowEventMap)[]): boolean;
|
|
247
|
+
|
|
248
|
+
declare const _default$1: () => {};
|
|
249
|
+
|
|
250
|
+
declare type UseTextDirectionValue = "ltr" | "rtl" | "auto";
|
|
251
|
+
interface UseTextDirectionOptions {
|
|
252
|
+
/**
|
|
253
|
+
* CSS Selector for the target element applying to
|
|
254
|
+
*
|
|
255
|
+
* @default 'html'
|
|
256
|
+
*/
|
|
257
|
+
selector?: string;
|
|
258
|
+
/**
|
|
259
|
+
* Initial value
|
|
260
|
+
*
|
|
261
|
+
* @default 'ltr'
|
|
262
|
+
*/
|
|
263
|
+
initialValue?: UseTextDirectionValue;
|
|
264
|
+
}
|
|
265
|
+
declare function useTextDirection(options?: UseTextDirectionOptions): readonly [UseTextDirectionValue, (value: UseTextDirectionValue) => void];
|
|
266
|
+
|
|
267
|
+
interface CursorState {
|
|
268
|
+
screenX: number;
|
|
269
|
+
screenY: number;
|
|
270
|
+
clientX: number;
|
|
271
|
+
clientY: number;
|
|
272
|
+
pageX: number;
|
|
273
|
+
pageY: number;
|
|
274
|
+
elementX: number;
|
|
275
|
+
elementY: number;
|
|
276
|
+
elementH: number;
|
|
277
|
+
elementW: number;
|
|
278
|
+
elementPosX: number;
|
|
279
|
+
elementPosY: number;
|
|
280
|
+
}
|
|
281
|
+
declare function useMouse(target?: BasicTarget): CursorState;
|
|
282
|
+
|
|
283
|
+
interface UseFpsOptions {
|
|
284
|
+
/**
|
|
285
|
+
* Calculate the FPS on every x frames.
|
|
286
|
+
* @default 10
|
|
287
|
+
*/
|
|
288
|
+
every?: number;
|
|
289
|
+
}
|
|
290
|
+
declare const _default: (options?: UseFpsOptions | undefined) => number;
|
|
291
|
+
|
|
292
|
+
declare function useGeolocation(options?: Partial<PositionOptions>): {
|
|
293
|
+
readonly coordinates: GeolocationCoordinates;
|
|
294
|
+
readonly locatedAt: number | null;
|
|
295
|
+
readonly error: GeolocationPositionError | null;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
interface Options {
|
|
299
|
+
onExit?: () => void;
|
|
300
|
+
onEnter?: () => void;
|
|
301
|
+
}
|
|
302
|
+
declare function useFullscreen(target: BasicTarget, options?: Options): readonly [boolean, {
|
|
303
|
+
readonly enterFullscreen: () => void;
|
|
304
|
+
readonly exitFullscreen: () => void;
|
|
305
|
+
readonly toggleFullscreen: () => void;
|
|
306
|
+
readonly isEnabled: true;
|
|
307
|
+
}];
|
|
308
|
+
|
|
309
|
+
interface INetworkInformation extends EventTarget {
|
|
310
|
+
readonly downlink: number;
|
|
311
|
+
readonly downlinkMax: number;
|
|
312
|
+
readonly effectiveType: "slow-2g" | "2g" | "3g" | "4g";
|
|
313
|
+
readonly rtt: number;
|
|
314
|
+
readonly saveData: boolean;
|
|
315
|
+
readonly type: "bluetooth" | "cellular" | "ethernet" | "none" | "wifi" | "wimax" | "other" | "unknown";
|
|
316
|
+
onChange: (event: Event) => void;
|
|
317
|
+
}
|
|
318
|
+
interface IUseNetworkState {
|
|
319
|
+
/**
|
|
320
|
+
* @desc Whether browser connected to the network or not.
|
|
321
|
+
*/
|
|
322
|
+
online: boolean | undefined;
|
|
323
|
+
/**
|
|
324
|
+
* @desc Previous value of `online` property. Helps to identify if browser
|
|
325
|
+
* just connected or lost connection.
|
|
326
|
+
*/
|
|
327
|
+
previous: boolean | undefined;
|
|
328
|
+
/**
|
|
329
|
+
* @desc The {Date} object pointing to the moment when state change occurred.
|
|
330
|
+
*/
|
|
331
|
+
since: Date | undefined;
|
|
332
|
+
/**
|
|
333
|
+
* @desc Effective bandwidth estimate in megabits per second, rounded to the
|
|
334
|
+
* nearest multiple of 25 kilobits per seconds.
|
|
335
|
+
*/
|
|
336
|
+
downlink: INetworkInformation["downlink"] | undefined;
|
|
337
|
+
/**
|
|
338
|
+
* @desc Maximum downlink speed, in megabits per second (Mbps), for the
|
|
339
|
+
* underlying connection technology
|
|
340
|
+
*/
|
|
341
|
+
downlinkMax: INetworkInformation["downlinkMax"] | undefined;
|
|
342
|
+
/**
|
|
343
|
+
* @desc Effective type of the connection meaning one of 'slow-2g', '2g', '3g', or '4g'.
|
|
344
|
+
* This value is determined using a combination of recently observed round-trip time
|
|
345
|
+
* and downlink values.
|
|
346
|
+
*/
|
|
347
|
+
effectiveType: INetworkInformation["effectiveType"] | undefined;
|
|
348
|
+
/**
|
|
349
|
+
* @desc Estimated effective round-trip time of the current connection, rounded
|
|
350
|
+
* to the nearest multiple of 25 milliseconds
|
|
351
|
+
*/
|
|
352
|
+
rtt: INetworkInformation["rtt"] | undefined;
|
|
353
|
+
/**
|
|
354
|
+
* @desc {true} if the user has set a reduced data usage option on the user agent.
|
|
355
|
+
*/
|
|
356
|
+
saveData: INetworkInformation["saveData"] | undefined;
|
|
357
|
+
/**
|
|
358
|
+
* @desc The type of connection a device is using to communicate with the network.
|
|
359
|
+
* It will be one of the following values:
|
|
360
|
+
* - bluetooth
|
|
361
|
+
* - cellular
|
|
362
|
+
* - ethernet
|
|
363
|
+
* - none
|
|
364
|
+
* - wifi
|
|
365
|
+
* - wimax
|
|
366
|
+
* - other
|
|
367
|
+
* - unknown
|
|
368
|
+
*/
|
|
369
|
+
type: INetworkInformation["type"] | undefined;
|
|
370
|
+
}
|
|
371
|
+
declare function useNetwork(): IUseNetworkState;
|
|
372
|
+
|
|
373
|
+
declare function useOnline(): boolean | undefined;
|
|
374
|
+
|
|
375
|
+
interface OrientationState {
|
|
376
|
+
angle: number;
|
|
377
|
+
type: string;
|
|
378
|
+
}
|
|
379
|
+
declare function useOrientation(initialState?: OrientationState): readonly [OrientationState, (type: OrientationLockType) => Promise<void> | undefined, () => void];
|
|
380
|
+
|
|
381
|
+
declare function useIntersectionObserver(target: BasicTarget, callback: IntersectionObserverCallback, options?: IntersectionObserverInit): () => void;
|
|
382
|
+
|
|
383
|
+
declare function usePageLeave(): boolean;
|
|
384
|
+
|
|
385
|
+
declare function useDocumentVisibility(): DocumentVisibilityState;
|
|
386
|
+
|
|
387
|
+
declare function useResizeObserver(target: BasicTarget, callback: ResizeObserverCallback, options?: ResizeObserverOptions): () => void;
|
|
388
|
+
|
|
389
|
+
declare function useDropZone(target: BasicTarget<HTMLElement>, onDrop?: (files: File[] | null) => void): boolean;
|
|
390
|
+
|
|
391
|
+
interface UseFileDialogOptions {
|
|
392
|
+
/**
|
|
393
|
+
* @default true
|
|
394
|
+
*/
|
|
395
|
+
multiple?: boolean;
|
|
396
|
+
/**
|
|
397
|
+
* @default '*'
|
|
398
|
+
*/
|
|
399
|
+
accept?: string;
|
|
400
|
+
/**
|
|
401
|
+
* Select the input source for the capture file.
|
|
402
|
+
* @see [HTMLInputElement Capture](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture)
|
|
403
|
+
*/
|
|
404
|
+
capture?: string;
|
|
405
|
+
}
|
|
406
|
+
declare function useFileDialog(options?: UseFileDialogOptions): readonly [
|
|
407
|
+
FileList | null,
|
|
408
|
+
(localOptions?: Partial<UseFileDialogOptions>) => void,
|
|
409
|
+
() => void
|
|
410
|
+
];
|
|
411
|
+
|
|
412
|
+
interface UseScrollOptions {
|
|
413
|
+
/**
|
|
414
|
+
* Throttle time for scroll event, it’s disabled by default.
|
|
415
|
+
*
|
|
416
|
+
* @default 0
|
|
417
|
+
*/
|
|
418
|
+
throttle?: number;
|
|
419
|
+
/**
|
|
420
|
+
* The check time when scrolling ends.
|
|
421
|
+
* This configuration will be setting to (throttle + idle) when the `throttle` is configured.
|
|
422
|
+
*
|
|
423
|
+
* @default 200
|
|
424
|
+
*/
|
|
425
|
+
idle?: number;
|
|
426
|
+
/**
|
|
427
|
+
* Offset arrived states by x pixels
|
|
428
|
+
*
|
|
429
|
+
*/
|
|
430
|
+
offset?: {
|
|
431
|
+
left?: number;
|
|
432
|
+
right?: number;
|
|
433
|
+
top?: number;
|
|
434
|
+
bottom?: number;
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* Trigger it when scrolling.
|
|
438
|
+
*
|
|
439
|
+
*/
|
|
440
|
+
onScroll?: (e: Event) => void;
|
|
441
|
+
/**
|
|
442
|
+
* Trigger it when scrolling ends.
|
|
443
|
+
*
|
|
444
|
+
*/
|
|
445
|
+
onStop?: (e: Event) => void;
|
|
446
|
+
/**
|
|
447
|
+
* Listener options for scroll event.
|
|
448
|
+
*
|
|
449
|
+
* @default {capture: false, passive: true}
|
|
450
|
+
*/
|
|
451
|
+
eventListenerOptions?: boolean | AddEventListenerOptions;
|
|
452
|
+
}
|
|
453
|
+
declare function useScroll(target: BasicTarget<HTMLElement | SVGElement | Window | Document>, options?: UseScrollOptions): readonly [
|
|
454
|
+
number,
|
|
455
|
+
number,
|
|
456
|
+
boolean,
|
|
457
|
+
{
|
|
458
|
+
left: boolean;
|
|
459
|
+
right: boolean;
|
|
460
|
+
top: boolean;
|
|
461
|
+
bottom: boolean;
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
left: boolean;
|
|
465
|
+
right: boolean;
|
|
466
|
+
top: boolean;
|
|
467
|
+
bottom: boolean;
|
|
468
|
+
}
|
|
469
|
+
];
|
|
470
|
+
|
|
471
|
+
interface UseInfiniteScrollOptions extends UseScrollOptions {
|
|
472
|
+
/**
|
|
473
|
+
* The minimum distance between the bottom of the element and the bottom of the viewport
|
|
474
|
+
*
|
|
475
|
+
* @default 0
|
|
476
|
+
*/
|
|
477
|
+
distance?: number;
|
|
478
|
+
/**
|
|
479
|
+
* The direction in which to listen the scroll.
|
|
480
|
+
*
|
|
481
|
+
* @default 'bottom'
|
|
482
|
+
*/
|
|
483
|
+
direction?: "top" | "bottom" | "left" | "right";
|
|
484
|
+
/**
|
|
485
|
+
* Whether to preserve the current scroll position when loading more items.
|
|
486
|
+
*
|
|
487
|
+
* @default false
|
|
488
|
+
*/
|
|
489
|
+
preserveScrollPosition?: boolean;
|
|
490
|
+
}
|
|
491
|
+
declare function useInfiniteScroll(target: BasicTarget<HTMLElement | SVGElement | Window | Document>, onLoadMore: (state: ReturnType<typeof useScroll>) => void | Promise<void>, options?: UseInfiniteScrollOptions): void;
|
|
492
|
+
|
|
493
|
+
declare type KeyModifier = "Alt" | "AltGraph" | "CapsLock" | "Control" | "Fn" | "FnLock" | "Meta" | "NumLock" | "ScrollLock" | "Shift" | "Symbol" | "SymbolLock";
|
|
494
|
+
interface UseModifierOptions {
|
|
495
|
+
/**
|
|
496
|
+
* Event names that will prompt update to modifier states
|
|
497
|
+
*
|
|
498
|
+
* @default ['mousedown', 'mouseup', 'keydown', 'keyup']
|
|
499
|
+
*/
|
|
500
|
+
events?: (keyof WindowEventMap)[];
|
|
501
|
+
/**
|
|
502
|
+
* Initial value of the returned ref
|
|
503
|
+
*
|
|
504
|
+
* @default false
|
|
505
|
+
*/
|
|
506
|
+
initial?: boolean;
|
|
507
|
+
}
|
|
508
|
+
declare function useKeyModifier(modifier: KeyModifier, options?: UseModifierOptions): boolean;
|
|
509
|
+
|
|
510
|
+
declare type IHookStateInitialSetter<S> = () => S;
|
|
511
|
+
declare type IHookStateInitAction<S> = S | IHookStateInitialSetter<S>;
|
|
512
|
+
|
|
513
|
+
interface MousePressedOptions {
|
|
514
|
+
/**
|
|
515
|
+
* Listen to `touchstart` `touchend` events
|
|
516
|
+
*
|
|
517
|
+
* @default true
|
|
518
|
+
*/
|
|
519
|
+
touch?: boolean;
|
|
520
|
+
/**
|
|
521
|
+
* Listen to `dragstart` `drop` and `dragend` events
|
|
522
|
+
*
|
|
523
|
+
* @default true
|
|
524
|
+
*/
|
|
525
|
+
drag?: boolean;
|
|
526
|
+
/**
|
|
527
|
+
* Initial values
|
|
528
|
+
*
|
|
529
|
+
* @default false
|
|
530
|
+
*/
|
|
531
|
+
initialValue?: IHookStateInitAction<boolean>;
|
|
532
|
+
}
|
|
533
|
+
declare type MouseSourceType = "mouse" | "touch" | null;
|
|
534
|
+
declare function useMousePressed(target?: BasicTarget, options?: MousePressedOptions): readonly [boolean, MouseSourceType];
|
|
535
|
+
|
|
536
|
+
declare function useScrollLock(target: BasicTarget<HTMLElement | SVGElement | Window | Document>, initialState?: boolean): readonly [boolean, (flag: boolean) => void];
|
|
537
|
+
|
|
538
|
+
declare function useElementSize(target: BasicTarget, options?: ResizeObserverOptions): readonly [number, number];
|
|
539
|
+
|
|
540
|
+
interface UseVirtualListOptions {
|
|
541
|
+
/**
|
|
542
|
+
* container default height
|
|
543
|
+
*
|
|
544
|
+
* @default 300
|
|
545
|
+
*/
|
|
546
|
+
containerHeight?: number;
|
|
547
|
+
/**
|
|
548
|
+
* item height, accept a pixel value or a function that returns the height
|
|
549
|
+
*/
|
|
550
|
+
itemHeight: number | ((index: number) => number);
|
|
551
|
+
/**
|
|
552
|
+
* the extra buffer items outside of the view area
|
|
553
|
+
*
|
|
554
|
+
* @default 5
|
|
555
|
+
*/
|
|
556
|
+
overscan?: number;
|
|
557
|
+
}
|
|
558
|
+
interface UseVirtualListItem<T> {
|
|
559
|
+
data: T;
|
|
560
|
+
index: number;
|
|
561
|
+
}
|
|
562
|
+
interface UseVirtualListReturn<T> {
|
|
563
|
+
list: UseVirtualListItem<T>[];
|
|
564
|
+
scrollTo: (index: number) => void;
|
|
565
|
+
containerProps: {
|
|
566
|
+
ref: RefObject<any>;
|
|
567
|
+
onScroll: () => void;
|
|
568
|
+
style: Partial<CSSProperties>;
|
|
569
|
+
};
|
|
570
|
+
wrapperProps: {
|
|
571
|
+
style: {
|
|
572
|
+
width: string;
|
|
573
|
+
height: string;
|
|
574
|
+
marginTop: string;
|
|
575
|
+
};
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
declare function useVirtualList<T = any>(list: T[] | undefined, options: UseVirtualListOptions): UseVirtualListReturn<T>;
|
|
579
|
+
|
|
580
|
+
declare type ColorScheme = "dark" | "light" | "no-preference";
|
|
581
|
+
declare function usePreferredColorScheme(defaultState?: ColorScheme): ColorScheme;
|
|
582
|
+
|
|
583
|
+
declare type Contrast = "more" | "less" | "custom" | "no-preference";
|
|
584
|
+
declare function usePreferredContrast(defaultState?: Contrast): Contrast;
|
|
585
|
+
|
|
586
|
+
declare function useActiveElement<T extends Element>(): T | null;
|
|
587
|
+
|
|
588
|
+
export { useActiveElement, useCounter, useCustomCompareEffect, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDropZone, useElementSize, useEvent, useEventEmitter, useEventListener, useFavicon, useFileDialog, useFirstMountState, _default as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, useMarkdown, _default$1 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useResizeObserver, useScriptTag, useScroll, useScrollLock, useSessionStorage, useTextDirection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, _default$3 as useUpdateEffect, _default$2 as useUpdateLayoutEffect, useVirtualList };
|