react-hook-toolkit 1.0.23 → 1.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.
@@ -1,70 +1,10 @@
1
1
  import React, { FC } from 'react';
2
+ import { FileComponentProps, AlertPropsType, DetailsCardProps, UploadButtonProps, DownloadFileProps, ContextMenuProps } from '../type';
2
3
  export declare const DynamicLoader: (Component: any) => (props: any) => import("react/jsx-runtime").JSX.Element;
3
- interface PropsType {
4
- type: string;
5
- msg: string;
6
- duration?: number;
7
- }
8
- export declare const AlertMessage: FC<PropsType>;
9
- interface DetailsCardProps {
10
- isLoading?: boolean;
11
- title: string;
12
- details: any[];
13
- spacing?: number;
14
- boxShadow?: string;
15
- background?: string;
16
- loaderType?: 'skeleton' | 'circular';
17
- displayType?: 'flex' | 'block';
18
- }
4
+ export declare const AlertMessage: FC<AlertPropsType>;
19
5
  export declare const DetailsCard: ({ isLoading, title, details, spacing, boxShadow, background, loaderType, displayType, }: DetailsCardProps) => import("react/jsx-runtime").JSX.Element;
20
6
  export declare const LabeledValue: ({ label, value, style }: any) => import("react/jsx-runtime").JSX.Element;
21
- interface FileComponentProps {
22
- primaryKey: string | number;
23
- filename: string;
24
- size: string | number;
25
- onDownload?: any;
26
- width?: number;
27
- borderColor?: string;
28
- fileColor?: 'inherit' | 'primary' | 'secondary' | 'error' | 'disabled' | 'action';
29
- isDownloading: boolean;
30
- }
31
7
  export declare const FilePreview: ({ primaryKey, filename, size, onDownload, width, borderColor, fileColor, isDownloading, }: FileComponentProps) => import("react/jsx-runtime").JSX.Element;
32
- interface UploadButtonProps {
33
- isUpload?: boolean;
34
- color?: 'inherit' | 'primary' | 'secondary' | 'success' | 'error' | 'info' | 'warning';
35
- state?: {
36
- isUploaded?: boolean;
37
- isUploadError?: boolean;
38
- isLoadingUpload?: boolean;
39
- };
40
- onFileSelect: (file: File) => void;
41
- }
42
8
  export declare const UploadFile: React.FC<UploadButtonProps>;
43
- interface DownloadButtonState {
44
- isDownloaded?: boolean;
45
- isDownloadError?: boolean;
46
- isLoadingDownload?: boolean;
47
- }
48
- interface DownloadFileProps {
49
- isDownload?: boolean;
50
- color?: 'inherit' | 'primary' | 'secondary' | 'success' | 'error' | 'info' | 'warning';
51
- state?: DownloadButtonState;
52
- onDownload: () => void;
53
- }
54
9
  export declare const DownloadFile: React.FC<DownloadFileProps>;
55
- type MenuPosition = 'auto' | 'fixed';
56
- type ThemeMode = 'light' | 'dark';
57
- interface ContextMenuProps {
58
- options: any;
59
- children: React.ReactNode;
60
- disabled?: boolean;
61
- className?: string;
62
- menuClassName?: string;
63
- position?: MenuPosition;
64
- onShow?: () => void;
65
- onHide?: () => void;
66
- currentInstance?: any;
67
- theme?: ThemeMode;
68
- }
69
10
  export declare const ContextMenuWrapper: React.FC<ContextMenuProps>;
70
- export {};
@@ -1,3 +1,5 @@
1
+ import { RefObject } from "react";
2
+ import { UseRecentSearchOptions, ISpeechOptions, ISpeechState, MotionSensorState, IPermissionDescriptor, IState } from "../type";
1
3
  export declare function useHistoryState<T>(initialPresent: T): {
2
4
  state: T;
3
5
  set: (newPresent: T) => void;
@@ -37,16 +39,20 @@ export declare function useLongPress(callback: (event: Event) => void, options?:
37
39
  onTouchStart: any;
38
40
  onTouchEnd: any;
39
41
  };
40
- type UseRecentSearchOptions = {
41
- key?: string;
42
- limit?: number;
43
- uniqueKey?: string;
44
- excludeEmpty?: boolean;
45
- };
46
42
  export declare const useRecentSearch: (options?: UseRecentSearchOptions) => {
47
43
  recentSearches: any;
48
44
  addSearch: (item: any) => void;
49
45
  clearSearch: () => void;
50
46
  hasSearch: (value: string) => any;
51
47
  };
48
+ export declare const useUnmountedRef: () => import("react").MutableRefObject<boolean>;
49
+ export declare function configResponsive(config: any): void;
50
+ export declare const useResponsive: () => any;
51
+ export declare const useClickAway: <E extends Event = Event>(ref: RefObject<HTMLElement | null>, onClickAway: (event: E) => void, events?: string[]) => void;
52
+ export declare const useBeforeUnload: (enabled?: boolean | (() => boolean), message?: string) => void;
53
+ export declare const useHoverDirty: (ref: RefObject<Element>, enabled?: boolean) => boolean;
54
+ export declare const useMotion: (initialState?: MotionSensorState) => MotionSensorState;
55
+ export declare const usePageLeave: (onPageLeave: any, args?: never[]) => void;
56
+ export declare const usePermission: (permissionDesc: IPermissionDescriptor) => IState;
57
+ export declare const useSpeech: (text: string, options: ISpeechOptions) => ISpeechState;
52
58
  export {};
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
13
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
14
  if (ar || !(i in from)) {
@@ -8,7 +19,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
8
19
  return to.concat(ar || Array.prototype.slice.call(from));
9
20
  };
10
21
  import { useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
11
- import { throttle } from '../utils';
22
+ import { isBrowser, noop, off, on, throttle } from '../utils';
23
+ import { VoiceStatus } from "../type";
12
24
  function historyReducer(state, action) {
13
25
  switch (action.type) {
14
26
  case 'UNDO':
@@ -307,3 +319,303 @@ export var useRecentSearch = function (options) {
307
319
  };
308
320
  return { recentSearches: recentSearches, addSearch: addSearch, clearSearch: clearSearch, hasSearch: hasSearch };
309
321
  };
322
+ export var useUnmountedRef = function () {
323
+ var unmountedRef = useRef(false);
324
+ useEffect(function () {
325
+ unmountedRef.current = false;
326
+ return function () {
327
+ unmountedRef.current = true;
328
+ };
329
+ }, []);
330
+ return unmountedRef;
331
+ };
332
+ var info;
333
+ var responsiveConfig = {
334
+ xs: 0,
335
+ sm: 576,
336
+ md: 768,
337
+ lg: 992,
338
+ xl: 1200,
339
+ };
340
+ var subscribers = new Set();
341
+ function handleResize() {
342
+ var oldInfo = info;
343
+ calculate();
344
+ if (oldInfo === info)
345
+ return;
346
+ for (var _i = 0, _a = subscribers; _i < _a.length; _i++) {
347
+ var subscriber = _a[_i];
348
+ subscriber();
349
+ }
350
+ }
351
+ var listening = false;
352
+ function calculate() {
353
+ var width = window.innerWidth;
354
+ var newInfo = {};
355
+ var shouldUpdate = false;
356
+ for (var _i = 0, _a = Object.keys(responsiveConfig); _i < _a.length; _i++) {
357
+ var key = _a[_i];
358
+ newInfo[key] = width >= responsiveConfig[key];
359
+ if (newInfo[key] !== info[key]) {
360
+ shouldUpdate = true;
361
+ }
362
+ }
363
+ if (shouldUpdate) {
364
+ info = newInfo;
365
+ }
366
+ }
367
+ export function configResponsive(config) {
368
+ responsiveConfig = config;
369
+ if (info)
370
+ calculate();
371
+ }
372
+ export var useResponsive = function () {
373
+ if (isBrowser && !listening) {
374
+ info = {};
375
+ calculate();
376
+ window.addEventListener('resize', handleResize);
377
+ listening = true;
378
+ }
379
+ var _a = useState(info), state = _a[0], setState = _a[1];
380
+ useEffect(function () {
381
+ if (!isBrowser)
382
+ return;
383
+ if (!listening) {
384
+ window.addEventListener('resize', handleResize);
385
+ }
386
+ var subscriber = function () {
387
+ setState(info);
388
+ };
389
+ subscribers.add(subscriber);
390
+ return function () {
391
+ subscribers.delete(subscriber);
392
+ if (subscribers.size === 0) {
393
+ window.removeEventListener('resize', handleResize);
394
+ listening = false;
395
+ }
396
+ };
397
+ }, []);
398
+ return state;
399
+ };
400
+ var defaultEvents = ['mousedown', 'touchstart'];
401
+ export var useClickAway = function (ref, onClickAway, events) {
402
+ if (events === void 0) { events = defaultEvents; }
403
+ var savedCallback = useRef(onClickAway);
404
+ useEffect(function () {
405
+ savedCallback.current = onClickAway;
406
+ }, [onClickAway]);
407
+ useEffect(function () {
408
+ var handler = function (event) {
409
+ var el = ref.current;
410
+ el && !el.contains(event.target) && savedCallback.current(event);
411
+ };
412
+ for (var _i = 0, events_1 = events; _i < events_1.length; _i++) {
413
+ var eventName = events_1[_i];
414
+ on(document, eventName, handler);
415
+ }
416
+ return function () {
417
+ for (var _i = 0, events_2 = events; _i < events_2.length; _i++) {
418
+ var eventName = events_2[_i];
419
+ off(document, eventName, handler);
420
+ }
421
+ };
422
+ }, [events, ref]);
423
+ };
424
+ export var useBeforeUnload = function (enabled, message) {
425
+ if (enabled === void 0) { enabled = true; }
426
+ var handler = useCallback(function (event) {
427
+ var finalEnabled = typeof enabled === 'function' ? enabled() : true;
428
+ if (!finalEnabled) {
429
+ return;
430
+ }
431
+ event.preventDefault();
432
+ if (message) {
433
+ event.returnValue = message;
434
+ }
435
+ return message;
436
+ }, [enabled, message]);
437
+ useEffect(function () {
438
+ if (!enabled) {
439
+ return;
440
+ }
441
+ on(window, 'beforeunload', handler);
442
+ return function () { return off(window, 'beforeunload', handler); };
443
+ }, [enabled, handler]);
444
+ };
445
+ export var useHoverDirty = function (ref, enabled) {
446
+ if (enabled === void 0) { enabled = true; }
447
+ if (process.env.NODE_ENV === 'development') {
448
+ if (typeof ref !== 'object' || typeof ref.current === 'undefined') {
449
+ console.error('useHoverDirty expects a single ref argument.');
450
+ }
451
+ }
452
+ var _a = useState(false), value = _a[0], setValue = _a[1];
453
+ useEffect(function () {
454
+ var onMouseOver = function () { return setValue(true); };
455
+ var onMouseOut = function () { return setValue(false); };
456
+ if (enabled && ref && ref.current) {
457
+ on(ref.current, 'mouseover', onMouseOver);
458
+ on(ref.current, 'mouseout', onMouseOut);
459
+ }
460
+ var current = ref.current;
461
+ return function () {
462
+ if (enabled && current) {
463
+ off(current, 'mouseover', onMouseOver);
464
+ off(current, 'mouseout', onMouseOut);
465
+ }
466
+ };
467
+ }, [enabled, ref]);
468
+ return value;
469
+ };
470
+ var defaultState = {
471
+ acceleration: {
472
+ x: null,
473
+ y: null,
474
+ z: null,
475
+ },
476
+ accelerationIncludingGravity: {
477
+ x: null,
478
+ y: null,
479
+ z: null,
480
+ },
481
+ rotationRate: {
482
+ alpha: null,
483
+ beta: null,
484
+ gamma: null,
485
+ },
486
+ interval: 16,
487
+ };
488
+ export var useMotion = function (initialState) {
489
+ if (initialState === void 0) { initialState = defaultState; }
490
+ var _a = useState(initialState), state = _a[0], setState = _a[1];
491
+ useEffect(function () {
492
+ var handler = function (event) {
493
+ var acceleration = event.acceleration, accelerationIncludingGravity = event.accelerationIncludingGravity, rotationRate = event.rotationRate, interval = event.interval;
494
+ setState({
495
+ acceleration: {
496
+ x: acceleration.x,
497
+ y: acceleration.y,
498
+ z: acceleration.z,
499
+ },
500
+ accelerationIncludingGravity: {
501
+ x: accelerationIncludingGravity.x,
502
+ y: accelerationIncludingGravity.y,
503
+ z: accelerationIncludingGravity.z,
504
+ },
505
+ rotationRate: {
506
+ alpha: rotationRate.alpha,
507
+ beta: rotationRate.beta,
508
+ gamma: rotationRate.gamma,
509
+ },
510
+ interval: interval,
511
+ });
512
+ };
513
+ on(window, 'devicemotion', handler);
514
+ return function () {
515
+ off(window, 'devicemotion', handler);
516
+ };
517
+ }, []);
518
+ return state;
519
+ };
520
+ export var usePageLeave = function (onPageLeave, args) {
521
+ if (args === void 0) { args = []; }
522
+ useEffect(function () {
523
+ if (!onPageLeave) {
524
+ return;
525
+ }
526
+ var handler = function (event) {
527
+ event = event ? event : window.event;
528
+ var from = event.relatedTarget || event.toElement;
529
+ if (!from || from.nodeName === 'HTML') {
530
+ onPageLeave();
531
+ }
532
+ };
533
+ on(document, 'mouseout', handler);
534
+ return function () {
535
+ off(document, 'mouseout', handler);
536
+ };
537
+ }, args);
538
+ };
539
+ export var usePermission = function (permissionDesc) {
540
+ var _a = useState(''), state = _a[0], setState = _a[1];
541
+ useEffect(function () {
542
+ var mounted = true;
543
+ var permissionStatus = null;
544
+ var onChange = function () {
545
+ if (!mounted)
546
+ return;
547
+ setState(function () { var _a; return (_a = permissionStatus === null || permissionStatus === void 0 ? void 0 : permissionStatus.state) !== null && _a !== void 0 ? _a : ''; });
548
+ };
549
+ navigator.permissions
550
+ .query(permissionDesc) // 👈 cast to fix TS error
551
+ .then(function (status) {
552
+ permissionStatus = status;
553
+ on(permissionStatus, 'change', onChange);
554
+ onChange();
555
+ })
556
+ .catch(noop);
557
+ return function () {
558
+ permissionStatus && off(permissionStatus, 'change', onChange);
559
+ mounted = false;
560
+ permissionStatus = null;
561
+ };
562
+ }, [permissionDesc]);
563
+ return state;
564
+ };
565
+ export var useSpeech = function (text, options) {
566
+ var mounted = useRef(false);
567
+ var _a = useState(function () {
568
+ var _a = options.voice || {}, _b = _a.lang, lang = _b === void 0 ? 'default' : _b, _c = _a.name, name = _c === void 0 ? '' : _c;
569
+ return {
570
+ isPlaying: false,
571
+ status: VoiceStatus[VoiceStatus.init],
572
+ lang: options.lang || 'default',
573
+ voiceInfo: { lang: lang, name: name },
574
+ rate: options.rate || 1,
575
+ pitch: options.pitch || 1,
576
+ volume: options.volume || 1,
577
+ };
578
+ }), state = _a[0], setState = _a[1];
579
+ var handlePlay = useCallback(function () {
580
+ if (!mounted.current) {
581
+ return;
582
+ }
583
+ setState(function (preState) {
584
+ return __assign(__assign({}, preState), { isPlaying: true, status: VoiceStatus[VoiceStatus.play] });
585
+ });
586
+ }, []);
587
+ var handlePause = useCallback(function () {
588
+ if (!mounted.current) {
589
+ return;
590
+ }
591
+ setState(function (preState) {
592
+ return __assign(__assign({}, preState), { isPlaying: false, status: VoiceStatus[VoiceStatus.pause] });
593
+ });
594
+ }, []);
595
+ var handleEnd = useCallback(function () {
596
+ if (!mounted.current) {
597
+ return;
598
+ }
599
+ setState(function (preState) {
600
+ return __assign(__assign({}, preState), { isPlaying: false, status: VoiceStatus[VoiceStatus.end] });
601
+ });
602
+ }, []);
603
+ useEffect(function () {
604
+ mounted.current = true;
605
+ var utterance = new SpeechSynthesisUtterance(text);
606
+ options.lang && (utterance.lang = options.lang);
607
+ options.voice && (utterance.voice = options.voice);
608
+ utterance.rate = options.rate || 1;
609
+ utterance.pitch = options.pitch || 1;
610
+ utterance.volume = options.volume || 1;
611
+ utterance.onstart = handlePlay;
612
+ utterance.onpause = handlePause;
613
+ utterance.onresume = handlePlay;
614
+ utterance.onend = handleEnd;
615
+ window.speechSynthesis.speak(utterance);
616
+ return function () {
617
+ mounted.current = false;
618
+ };
619
+ }, []);
620
+ return state;
621
+ };
@@ -1,29 +1,12 @@
1
1
  import { RefObject } from 'react';
2
- import { AxiosRequestConfig } from 'axios';
3
- interface UseAxiosResponse<T> {
4
- data: T | null;
5
- loading: boolean;
6
- error: string | null;
7
- makeRequest: (url: string, method?: string, requestData?: any) => void;
8
- cancelRequest: () => void;
9
- }
10
- interface UseAxiosConfig extends AxiosRequestConfig {
11
- baseURL?: string;
12
- headers?: {
13
- [key: string]: string;
14
- };
15
- }
2
+ import { AsyncFunction, FetchState, MousePosition, ScrollPosition, UseAsyncReturn, UseAxiosConfig, UseAxiosResponse, WindowSize } from '../type';
3
+ export declare const isReady: () => boolean;
16
4
  export declare const useAxios: <T>(config?: UseAxiosConfig) => UseAxiosResponse<T>;
17
- export declare const useDrawer: () => import("../chunk1213/chunk158261").DrawerContextValue;
18
- export declare const useAdvReducer: <State, Action extends {
5
+ export declare const useDrawer: () => import("../type").DrawerContextValue;
6
+ export declare const useGenericReducer: <State, Action extends {
19
7
  type: string;
20
8
  }>(initialState: State, actions: Record<string, (state: State, action: Action) => State>) => (state: State | undefined, action: Action) => State;
21
- interface FetchState<T> {
22
- data: T | null;
23
- loading: boolean;
24
- error: string | null;
25
- }
26
- export declare function useFetch<T>(url: string): FetchState<T>;
9
+ export declare function useRequest<T>(url: string): FetchState<T>;
27
10
  export declare function useLocalStorage<T>(key: string, initialValue: T): [T, (value: T) => void];
28
11
  export declare function useToggle(initialValue?: boolean): [boolean, () => void];
29
12
  export declare function useDebounce<T>(value: T, delay: number): T;
@@ -32,17 +15,9 @@ export declare function usePrevious<T>(value: T): T | undefined;
32
15
  export declare function useMediaQuery(query: string): boolean;
33
16
  export declare function useClipboard(): [boolean, (text: string) => Promise<void>];
34
17
  export declare function useInterval(callback: () => void, delay: number | null): void;
35
- interface WindowSize {
36
- width: number;
37
- height: number;
38
- }
39
18
  export declare function useWindowSize(): WindowSize;
40
19
  export declare function useKeyPress(targetKey: string): boolean;
41
20
  export declare function useOnlineStatus(): boolean;
42
- interface ScrollPosition {
43
- x: number;
44
- y: number;
45
- }
46
21
  export declare function useScrollPosition(): ScrollPosition;
47
22
  export declare function useTimeout(callback: () => void, delay: number | null): void;
48
23
  export declare function useDarkMode(): [boolean, () => void];
@@ -90,10 +65,6 @@ export declare function useTimeoutFn(callback: () => void, delay: number | null)
90
65
  export declare function useDebouncedCallback(callback: () => void, delay: number): () => void;
91
66
  export declare function useScrollLock(lock: boolean): void;
92
67
  export declare function useResizeObserver<T extends HTMLElement>(ref: RefObject<T>): WindowSize | null;
93
- interface MousePosition {
94
- x: number;
95
- y: number;
96
- }
97
68
  export declare function useMousePosition(): MousePosition;
98
69
  type ScrollDirection = 'up' | 'down';
99
70
  export declare function useScrollDirection(): ScrollDirection;
@@ -104,7 +75,7 @@ export declare function useImageLoader(src: string): {
104
75
  export declare function usePersistedState<T>(key: string, initialValue: T): [T, React.Dispatch<React.SetStateAction<T>>];
105
76
  export declare function useReducedMotion(): boolean;
106
77
  export declare function useCookie(key: string): [string | null, (value: string, options?: any) => void, () => void];
107
- export declare function useFetchRetry<T>(url: string, options: RequestInit, retries?: number): {
78
+ export declare function useRequestRetry<T>(url: string, options: RequestInit, retries?: number): {
108
79
  data: T | null;
109
80
  error: string | null;
110
81
  loading: boolean;
@@ -112,14 +83,6 @@ export declare function useFetchRetry<T>(url: string, options: RequestInit, retr
112
83
  export declare function useDelay<T>(value: T, delay: number): T;
113
84
  export declare function useVisibilityChange(): boolean;
114
85
  export declare function useDebouncedValue<T>(value: T, delay: number): T;
115
- export type Status = 'idle' | 'pending' | 'success' | 'error';
116
- export type AsyncFunction<T> = () => Promise<T>;
117
- export interface UseAsyncReturn<T> {
118
- execute: () => void;
119
- status: Status;
120
- value: T | null;
121
- error: Error | null;
122
- }
123
86
  export declare function useAsync<T>(asyncFunction: AsyncFunction<T>, immediate?: boolean): UseAsyncReturn<T>;
124
87
  export type ScriptStatus = 'loading' | 'ready' | 'error' | 'unknown';
125
88
  export declare function useScript(src: string, removeOnUnmount?: boolean): ScriptStatus;
@@ -127,152 +90,4 @@ export declare function useIndexedDB<T>(dbName: string, storeName: string): {
127
90
  data: T | null;
128
91
  error: Error | null;
129
92
  };
130
- export declare function useGeoLocation(): {
131
- position: GeolocationPosition | null;
132
- error: Error | null;
133
- };
134
- export declare function useTimer(initialTime: number): {
135
- time: number;
136
- error: Error | null;
137
- };
138
- export declare function useIsMounted(): boolean;
139
- export declare function useCss(css: string): {
140
- error: Error | null;
141
- };
142
- export declare function useSpeak(text: string): {
143
- speak: () => void;
144
- error: Error | null;
145
- };
146
- export declare function useCountUp(target: number, duration: number): {
147
- count: number;
148
- error: Error | null;
149
- };
150
- export declare function useCountDown(start: number): {
151
- count: number;
152
- error: Error | null;
153
- };
154
- interface BatteryState {
155
- supported: boolean;
156
- loading: boolean;
157
- level: number | null;
158
- charging: boolean | null;
159
- chargingTime: number | null;
160
- dischargingTime: number | null;
161
- }
162
- export declare const useBattery: () => BatteryState;
163
- export declare const useEventListener: (eventName: string, handler: (event: Event) => void, elementRef?: React.RefObject<HTMLElement>, options?: boolean | AddEventListenerOptions) => void;
164
- interface HistoryState {
165
- [key: string]: any;
166
- }
167
- interface UseHistory {
168
- history: History;
169
- state: HistoryState | null;
170
- push: (path: string, state?: HistoryState) => void;
171
- replace: (path: string, state?: HistoryState) => void;
172
- goBack: () => void;
173
- goForward: () => void;
174
- }
175
- export declare const useHistory: () => UseHistory;
176
- interface UsePreferredLanguage {
177
- language: string;
178
- languages: Array<string>;
179
- isSupported: boolean;
180
- }
181
- export declare const usePreferredLanguage: () => UsePreferredLanguage;
182
- interface UseSessionStorage<T> {
183
- (key: string, initialValue: T): [T, (value: T) => void];
184
- }
185
- export declare const useSessionStorage: UseSessionStorage<any>;
186
- interface UseSound {
187
- play: () => void;
188
- pause: () => void;
189
- stop: () => void;
190
- setVolume: (volume: number) => void;
191
- isPlaying: boolean;
192
- error: Error | null;
193
- }
194
- export declare const useSound: (url: string) => UseSound;
195
- interface TouchPosition {
196
- x: number | null;
197
- y: number | null;
198
- }
199
- interface UseTouch {
200
- (elementRef: React.RefObject<HTMLElement>): {
201
- touchStart: TouchPosition;
202
- touchMove: TouchPosition;
203
- touchEnd: TouchPosition;
204
- };
205
- }
206
- export declare const useTouch: UseTouch;
207
- export declare const useUpdateEffect: (effect: React.EffectCallback, deps: React.DependencyList) => void;
208
- export declare const usePersistedForm: <T>(key: string, initialValue: T) => [T, (value: T) => void];
209
- export declare const useCrossFieldValidation: <T extends Record<string, any>>(validate: (values: T) => Record<keyof T, string | null>) => {
210
- errors: Record<keyof T, string | null>;
211
- validateFields: (values: T) => boolean;
212
- };
213
- export declare const useFieldArray: <T>(initialValue: T[]) => {
214
- fields: T[];
215
- append: (item: T) => void;
216
- remove: (index: number) => void;
217
- update: (index: number, item: T) => void;
218
- };
219
- type SubmitHandler<T> = (data: T) => Promise<void>;
220
- export declare const useFormSubmit: <T>(handler: SubmitHandler<T>) => {
221
- handleSubmit: (data: T) => Promise<void>;
222
- isSubmitting: boolean;
223
- submitError: string | null;
224
- };
225
- export declare const useSmartForm: <T extends Record<string, any>>(initialValues: T, storageKey?: string) => {
226
- values: T;
227
- handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
228
- setValues: import("react").Dispatch<import("react").SetStateAction<T>>;
229
- dirty: boolean;
230
- };
231
- export declare const useUndo: <T>(initialState: T) => {
232
- state: T;
233
- setState: (newState: T) => void;
234
- undo: () => false | void;
235
- redo: () => false | void;
236
- canUndo: boolean;
237
- canRedo: boolean;
238
- };
239
- export declare const useFormWizard: <T extends Record<string, any>>(steps: {
240
- validate?: (values: T) => Record<string, string>;
241
- component: React.FC<{
242
- values: T;
243
- setValues: (v: T) => void;
244
- }>;
245
- }[], initialValues: T) => {
246
- currentStep: number;
247
- CurrentStep: import("react").FC<{
248
- values: T;
249
- setValues: (v: T) => void;
250
- }>;
251
- values: T;
252
- setValues: import("react").Dispatch<import("react").SetStateAction<T>>;
253
- next: () => void;
254
- prev: () => void;
255
- errors: Record<string, string>;
256
- isFirstStep: boolean;
257
- isLastStep: boolean;
258
- };
259
- export declare const createOptimizedContext: <T>() => readonly [import("react").Provider<T | undefined>, <U>(selector: (value: T) => U) => U];
260
- export declare const useWebSocket: <T>(url: string, onMessage?: (data: T) => void) => {
261
- data: T | null;
262
- send: (message: any) => void;
263
- isConnected: boolean;
264
- };
265
- export declare const useDragReorder: <T>(initialItems: T[]) => {
266
- items: T[];
267
- handleDragStart: (index: number) => void;
268
- handleDragEnter: (index: number) => void;
269
- handleDrop: () => void;
270
- };
271
- export declare const useInfiniteScroll: <T>(fetchData: (page: number) => Promise<T[]>, initialData?: T[]) => {
272
- data: T[];
273
- loading: boolean;
274
- hasMore: boolean;
275
- lastElementRef: (node: HTMLElement | null) => void;
276
- };
277
- export declare const useEventListeners: (eventType: string, handler: (event: Event) => void, element?: HTMLElement | Window, options?: AddEventListenerOptions) => void;
278
93
  export {};