@reactuses/core 6.1.9 → 6.1.10
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/dist/index.cjs +17 -15
- package/dist/index.d.cts +7 -6
- package/dist/index.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.mjs +17 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ function isString(val) {
|
|
|
23
23
|
const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
|
|
24
24
|
const isBrowser = typeof window !== 'undefined';
|
|
25
25
|
const isNavigator = typeof navigator !== 'undefined';
|
|
26
|
-
function noop() {}
|
|
26
|
+
function noop$1() {}
|
|
27
27
|
const isIOS = isBrowser && ((_window = window) == null ? void 0 : (_window_navigator = _window.navigator) == null ? void 0 : _window_navigator.userAgent) && /iP(?:ad|hone|od)/.test(window.navigator.userAgent);
|
|
28
28
|
|
|
29
29
|
const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useEffect;
|
|
@@ -113,10 +113,10 @@ const useDeepCompareEffect = (effect, deps)=>{
|
|
|
113
113
|
useCustomCompareEffect(effect, deps, lodashEs.isEqual);
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
-
function
|
|
116
|
+
function useEventListenerImpl(eventName, handler, element, options = defaultOptions$1) {
|
|
117
117
|
const savedHandler = useLatest(handler);
|
|
118
|
+
const targetElement = getTargetElement(element, defaultWindow);
|
|
118
119
|
useDeepCompareEffect(()=>{
|
|
119
|
-
const targetElement = getTargetElement(element, defaultWindow);
|
|
120
120
|
if (!(targetElement && targetElement.addEventListener)) {
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
@@ -130,10 +130,12 @@ function useEventListener(eventName, handler, element, options = defaultOptions$
|
|
|
130
130
|
};
|
|
131
131
|
}, [
|
|
132
132
|
eventName,
|
|
133
|
-
|
|
133
|
+
targetElement,
|
|
134
134
|
options
|
|
135
135
|
]);
|
|
136
136
|
}
|
|
137
|
+
function noop() {}
|
|
138
|
+
const useEventListener = isBrowser ? useEventListenerImpl : noop;
|
|
137
139
|
|
|
138
140
|
const useMount = (fn)=>{
|
|
139
141
|
if (isDev) {
|
|
@@ -203,7 +205,7 @@ function _async_to_generator$7(fn) {
|
|
|
203
205
|
});
|
|
204
206
|
};
|
|
205
207
|
}
|
|
206
|
-
const useAsyncEffect = (effect, cleanup = noop, deps)=>{
|
|
208
|
+
const useAsyncEffect = (effect, cleanup = noop$1, deps)=>{
|
|
207
209
|
const mounted = useMountedState();
|
|
208
210
|
React.useEffect(()=>{
|
|
209
211
|
const execute = ()=>_async_to_generator$7(function*() {
|
|
@@ -1774,7 +1776,7 @@ const defaultListerOptions = {
|
|
|
1774
1776
|
passive: true
|
|
1775
1777
|
};
|
|
1776
1778
|
const useScroll = (target, options = defaultOptions$1)=>{
|
|
1777
|
-
const { throttle = 0, idle = 200, onStop = noop, onScroll = noop, offset = {
|
|
1779
|
+
const { throttle = 0, idle = 200, onStop = noop$1, onScroll = noop$1, offset = {
|
|
1778
1780
|
left: 0,
|
|
1779
1781
|
right: 0,
|
|
1780
1782
|
top: 0,
|
|
@@ -2112,7 +2114,7 @@ const useMediaDevices = (options = {})=>{
|
|
|
2112
2114
|
label
|
|
2113
2115
|
}))
|
|
2114
2116
|
});
|
|
2115
|
-
}).catch(noop);
|
|
2117
|
+
}).catch(noop$1);
|
|
2116
2118
|
}, []);
|
|
2117
2119
|
const ensurePermissions = React.useCallback(()=>_async_to_generator$3(function*() {
|
|
2118
2120
|
if (!isSupported) {
|
|
@@ -2515,13 +2517,13 @@ function usePageLeave() {
|
|
|
2515
2517
|
const from = event.relatedTarget || event.toElement;
|
|
2516
2518
|
setIsLeft(!from);
|
|
2517
2519
|
};
|
|
2518
|
-
useEventListener('mouseout', handler,
|
|
2520
|
+
useEventListener('mouseout', handler, defaultWindow, {
|
|
2519
2521
|
passive: true
|
|
2520
2522
|
});
|
|
2521
|
-
useEventListener('mouseleave', handler,
|
|
2523
|
+
useEventListener('mouseleave', handler, defaultDocument, {
|
|
2522
2524
|
passive: true
|
|
2523
2525
|
});
|
|
2524
|
-
useEventListener('mouseenter', handler,
|
|
2526
|
+
useEventListener('mouseenter', handler, defaultDocument, {
|
|
2525
2527
|
passive: true
|
|
2526
2528
|
});
|
|
2527
2529
|
return isLeft;
|
|
@@ -2549,7 +2551,7 @@ const usePermission = (permissionDesc)=>{
|
|
|
2549
2551
|
permissionStatus = status;
|
|
2550
2552
|
on(permissionStatus, 'change', onChange);
|
|
2551
2553
|
onChange();
|
|
2552
|
-
}).catch(noop);
|
|
2554
|
+
}).catch(noop$1);
|
|
2553
2555
|
return ()=>{
|
|
2554
2556
|
permissionStatus && off(permissionStatus, 'change', onChange);
|
|
2555
2557
|
mounted = false;
|
|
@@ -2687,7 +2689,7 @@ const useScratch = (target, options = {})=>{
|
|
|
2687
2689
|
isScratching: true
|
|
2688
2690
|
});
|
|
2689
2691
|
refState.current = newState;
|
|
2690
|
-
(optionsRef.current.onScratch || noop)(newState);
|
|
2692
|
+
(optionsRef.current.onScratch || noop$1)(newState);
|
|
2691
2693
|
return newState;
|
|
2692
2694
|
});
|
|
2693
2695
|
});
|
|
@@ -2701,7 +2703,7 @@ const useScratch = (target, options = {})=>{
|
|
|
2701
2703
|
isScratching: false
|
|
2702
2704
|
});
|
|
2703
2705
|
refState.current = endState;
|
|
2704
|
-
(optionsRef.current.onScratchEnd || noop)(endState);
|
|
2706
|
+
(optionsRef.current.onScratchEnd || noop$1)(endState);
|
|
2705
2707
|
setState(endState);
|
|
2706
2708
|
};
|
|
2707
2709
|
const startScratching = (docX, docY)=>{
|
|
@@ -2734,7 +2736,7 @@ const useScratch = (target, options = {})=>{
|
|
|
2734
2736
|
posY: elY
|
|
2735
2737
|
};
|
|
2736
2738
|
refState.current = newState;
|
|
2737
|
-
(optionsRef.current.onScratchStart || noop)(newState);
|
|
2739
|
+
(optionsRef.current.onScratchStart || noop$1)(newState);
|
|
2738
2740
|
setState(newState);
|
|
2739
2741
|
};
|
|
2740
2742
|
useEventListener('mousedown', (event)=>{
|
|
@@ -2761,7 +2763,7 @@ const useScratch = (target, options = {})=>{
|
|
|
2761
2763
|
return state;
|
|
2762
2764
|
};
|
|
2763
2765
|
|
|
2764
|
-
const useScriptTag = (src, onLoaded = noop, options = defaultOptions$1)=>{
|
|
2766
|
+
const useScriptTag = (src, onLoaded = noop$1, options = defaultOptions$1)=>{
|
|
2765
2767
|
const { immediate = true, manual = false, type = 'text/javascript', async = true, crossOrigin, referrerPolicy, noModule, defer, attrs = {} } = options;
|
|
2766
2768
|
const scriptTag = React.useRef(null);
|
|
2767
2769
|
const _promise = React.useRef(null);
|
package/dist/index.d.cts
CHANGED
|
@@ -888,12 +888,13 @@ interface UseEventEmitterReturn<T, U = void> {
|
|
|
888
888
|
declare function useEventEmitter<T, U = void>(): readonly [UseEventEmitterEvent<T, U>, (arg1: T, arg2: U) => void, () => void];
|
|
889
889
|
|
|
890
890
|
type Target = BasicTarget<HTMLElement | Element | Window | Document | EventTarget>;
|
|
891
|
-
declare function
|
|
892
|
-
declare function
|
|
893
|
-
declare function
|
|
894
|
-
declare function
|
|
895
|
-
declare function
|
|
896
|
-
declare function
|
|
891
|
+
declare function useEventListenerImpl<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, element?: Window, options?: boolean | AddEventListenerOptions): void;
|
|
892
|
+
declare function useEventListenerImpl<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, element: Document, options?: boolean | AddEventListenerOptions): void;
|
|
893
|
+
declare function useEventListenerImpl<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLDivElement>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void, element: T, options?: boolean | AddEventListenerOptions): void;
|
|
894
|
+
declare function useEventListenerImpl<K extends keyof ElementEventMap>(eventName: K, handler: (event: ElementEventMap[K]) => void, element: Element, options?: boolean | AddEventListenerOptions): void;
|
|
895
|
+
declare function useEventListenerImpl<K = Event>(eventName: string, handler: (event: K) => void, element: EventTarget | null | undefined, options?: boolean | AddEventListenerOptions): void;
|
|
896
|
+
declare function useEventListenerImpl(eventName: string, handler: (...p: any) => void, element?: Target, options?: boolean | AddEventListenerOptions): void;
|
|
897
|
+
declare const useEventListener: typeof useEventListenerImpl;
|
|
897
898
|
|
|
898
899
|
/**
|
|
899
900
|
* @title useEyeDropper
|
package/dist/index.d.mts
CHANGED
|
@@ -888,12 +888,13 @@ interface UseEventEmitterReturn<T, U = void> {
|
|
|
888
888
|
declare function useEventEmitter<T, U = void>(): readonly [UseEventEmitterEvent<T, U>, (arg1: T, arg2: U) => void, () => void];
|
|
889
889
|
|
|
890
890
|
type Target = BasicTarget<HTMLElement | Element | Window | Document | EventTarget>;
|
|
891
|
-
declare function
|
|
892
|
-
declare function
|
|
893
|
-
declare function
|
|
894
|
-
declare function
|
|
895
|
-
declare function
|
|
896
|
-
declare function
|
|
891
|
+
declare function useEventListenerImpl<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, element?: Window, options?: boolean | AddEventListenerOptions): void;
|
|
892
|
+
declare function useEventListenerImpl<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, element: Document, options?: boolean | AddEventListenerOptions): void;
|
|
893
|
+
declare function useEventListenerImpl<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLDivElement>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void, element: T, options?: boolean | AddEventListenerOptions): void;
|
|
894
|
+
declare function useEventListenerImpl<K extends keyof ElementEventMap>(eventName: K, handler: (event: ElementEventMap[K]) => void, element: Element, options?: boolean | AddEventListenerOptions): void;
|
|
895
|
+
declare function useEventListenerImpl<K = Event>(eventName: string, handler: (event: K) => void, element: EventTarget | null | undefined, options?: boolean | AddEventListenerOptions): void;
|
|
896
|
+
declare function useEventListenerImpl(eventName: string, handler: (...p: any) => void, element?: Target, options?: boolean | AddEventListenerOptions): void;
|
|
897
|
+
declare const useEventListener: typeof useEventListenerImpl;
|
|
897
898
|
|
|
898
899
|
/**
|
|
899
900
|
* @title useEyeDropper
|
package/dist/index.d.ts
CHANGED
|
@@ -888,12 +888,13 @@ interface UseEventEmitterReturn<T, U = void> {
|
|
|
888
888
|
declare function useEventEmitter<T, U = void>(): readonly [UseEventEmitterEvent<T, U>, (arg1: T, arg2: U) => void, () => void];
|
|
889
889
|
|
|
890
890
|
type Target = BasicTarget<HTMLElement | Element | Window | Document | EventTarget>;
|
|
891
|
-
declare function
|
|
892
|
-
declare function
|
|
893
|
-
declare function
|
|
894
|
-
declare function
|
|
895
|
-
declare function
|
|
896
|
-
declare function
|
|
891
|
+
declare function useEventListenerImpl<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, element?: Window, options?: boolean | AddEventListenerOptions): void;
|
|
892
|
+
declare function useEventListenerImpl<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, element: Document, options?: boolean | AddEventListenerOptions): void;
|
|
893
|
+
declare function useEventListenerImpl<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLDivElement>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void, element: T, options?: boolean | AddEventListenerOptions): void;
|
|
894
|
+
declare function useEventListenerImpl<K extends keyof ElementEventMap>(eventName: K, handler: (event: ElementEventMap[K]) => void, element: Element, options?: boolean | AddEventListenerOptions): void;
|
|
895
|
+
declare function useEventListenerImpl<K = Event>(eventName: string, handler: (event: K) => void, element: EventTarget | null | undefined, options?: boolean | AddEventListenerOptions): void;
|
|
896
|
+
declare function useEventListenerImpl(eventName: string, handler: (...p: any) => void, element?: Target, options?: boolean | AddEventListenerOptions): void;
|
|
897
|
+
declare const useEventListener: typeof useEventListenerImpl;
|
|
897
898
|
|
|
898
899
|
/**
|
|
899
900
|
* @title useEyeDropper
|
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ function isString(val) {
|
|
|
15
15
|
const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
|
|
16
16
|
const isBrowser = typeof window !== 'undefined';
|
|
17
17
|
const isNavigator = typeof navigator !== 'undefined';
|
|
18
|
-
function noop() {}
|
|
18
|
+
function noop$1() {}
|
|
19
19
|
const isIOS = isBrowser && ((_window = window) == null ? void 0 : (_window_navigator = _window.navigator) == null ? void 0 : _window_navigator.userAgent) && /iP(?:ad|hone|od)/.test(window.navigator.userAgent);
|
|
20
20
|
|
|
21
21
|
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect;
|
|
@@ -105,10 +105,10 @@ const useDeepCompareEffect = (effect, deps)=>{
|
|
|
105
105
|
useCustomCompareEffect(effect, deps, isEqual);
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
-
function
|
|
108
|
+
function useEventListenerImpl(eventName, handler, element, options = defaultOptions$1) {
|
|
109
109
|
const savedHandler = useLatest(handler);
|
|
110
|
+
const targetElement = getTargetElement(element, defaultWindow);
|
|
110
111
|
useDeepCompareEffect(()=>{
|
|
111
|
-
const targetElement = getTargetElement(element, defaultWindow);
|
|
112
112
|
if (!(targetElement && targetElement.addEventListener)) {
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
@@ -122,10 +122,12 @@ function useEventListener(eventName, handler, element, options = defaultOptions$
|
|
|
122
122
|
};
|
|
123
123
|
}, [
|
|
124
124
|
eventName,
|
|
125
|
-
|
|
125
|
+
targetElement,
|
|
126
126
|
options
|
|
127
127
|
]);
|
|
128
128
|
}
|
|
129
|
+
function noop() {}
|
|
130
|
+
const useEventListener = isBrowser ? useEventListenerImpl : noop;
|
|
129
131
|
|
|
130
132
|
const useMount = (fn)=>{
|
|
131
133
|
if (isDev) {
|
|
@@ -195,7 +197,7 @@ function _async_to_generator$7(fn) {
|
|
|
195
197
|
});
|
|
196
198
|
};
|
|
197
199
|
}
|
|
198
|
-
const useAsyncEffect = (effect, cleanup = noop, deps)=>{
|
|
200
|
+
const useAsyncEffect = (effect, cleanup = noop$1, deps)=>{
|
|
199
201
|
const mounted = useMountedState();
|
|
200
202
|
useEffect(()=>{
|
|
201
203
|
const execute = ()=>_async_to_generator$7(function*() {
|
|
@@ -1766,7 +1768,7 @@ const defaultListerOptions = {
|
|
|
1766
1768
|
passive: true
|
|
1767
1769
|
};
|
|
1768
1770
|
const useScroll = (target, options = defaultOptions$1)=>{
|
|
1769
|
-
const { throttle = 0, idle = 200, onStop = noop, onScroll = noop, offset = {
|
|
1771
|
+
const { throttle = 0, idle = 200, onStop = noop$1, onScroll = noop$1, offset = {
|
|
1770
1772
|
left: 0,
|
|
1771
1773
|
right: 0,
|
|
1772
1774
|
top: 0,
|
|
@@ -2104,7 +2106,7 @@ const useMediaDevices = (options = {})=>{
|
|
|
2104
2106
|
label
|
|
2105
2107
|
}))
|
|
2106
2108
|
});
|
|
2107
|
-
}).catch(noop);
|
|
2109
|
+
}).catch(noop$1);
|
|
2108
2110
|
}, []);
|
|
2109
2111
|
const ensurePermissions = useCallback(()=>_async_to_generator$3(function*() {
|
|
2110
2112
|
if (!isSupported) {
|
|
@@ -2507,13 +2509,13 @@ function usePageLeave() {
|
|
|
2507
2509
|
const from = event.relatedTarget || event.toElement;
|
|
2508
2510
|
setIsLeft(!from);
|
|
2509
2511
|
};
|
|
2510
|
-
useEventListener('mouseout', handler,
|
|
2512
|
+
useEventListener('mouseout', handler, defaultWindow, {
|
|
2511
2513
|
passive: true
|
|
2512
2514
|
});
|
|
2513
|
-
useEventListener('mouseleave', handler,
|
|
2515
|
+
useEventListener('mouseleave', handler, defaultDocument, {
|
|
2514
2516
|
passive: true
|
|
2515
2517
|
});
|
|
2516
|
-
useEventListener('mouseenter', handler,
|
|
2518
|
+
useEventListener('mouseenter', handler, defaultDocument, {
|
|
2517
2519
|
passive: true
|
|
2518
2520
|
});
|
|
2519
2521
|
return isLeft;
|
|
@@ -2541,7 +2543,7 @@ const usePermission = (permissionDesc)=>{
|
|
|
2541
2543
|
permissionStatus = status;
|
|
2542
2544
|
on(permissionStatus, 'change', onChange);
|
|
2543
2545
|
onChange();
|
|
2544
|
-
}).catch(noop);
|
|
2546
|
+
}).catch(noop$1);
|
|
2545
2547
|
return ()=>{
|
|
2546
2548
|
permissionStatus && off(permissionStatus, 'change', onChange);
|
|
2547
2549
|
mounted = false;
|
|
@@ -2679,7 +2681,7 @@ const useScratch = (target, options = {})=>{
|
|
|
2679
2681
|
isScratching: true
|
|
2680
2682
|
});
|
|
2681
2683
|
refState.current = newState;
|
|
2682
|
-
(optionsRef.current.onScratch || noop)(newState);
|
|
2684
|
+
(optionsRef.current.onScratch || noop$1)(newState);
|
|
2683
2685
|
return newState;
|
|
2684
2686
|
});
|
|
2685
2687
|
});
|
|
@@ -2693,7 +2695,7 @@ const useScratch = (target, options = {})=>{
|
|
|
2693
2695
|
isScratching: false
|
|
2694
2696
|
});
|
|
2695
2697
|
refState.current = endState;
|
|
2696
|
-
(optionsRef.current.onScratchEnd || noop)(endState);
|
|
2698
|
+
(optionsRef.current.onScratchEnd || noop$1)(endState);
|
|
2697
2699
|
setState(endState);
|
|
2698
2700
|
};
|
|
2699
2701
|
const startScratching = (docX, docY)=>{
|
|
@@ -2726,7 +2728,7 @@ const useScratch = (target, options = {})=>{
|
|
|
2726
2728
|
posY: elY
|
|
2727
2729
|
};
|
|
2728
2730
|
refState.current = newState;
|
|
2729
|
-
(optionsRef.current.onScratchStart || noop)(newState);
|
|
2731
|
+
(optionsRef.current.onScratchStart || noop$1)(newState);
|
|
2730
2732
|
setState(newState);
|
|
2731
2733
|
};
|
|
2732
2734
|
useEventListener('mousedown', (event)=>{
|
|
@@ -2753,7 +2755,7 @@ const useScratch = (target, options = {})=>{
|
|
|
2753
2755
|
return state;
|
|
2754
2756
|
};
|
|
2755
2757
|
|
|
2756
|
-
const useScriptTag = (src, onLoaded = noop, options = defaultOptions$1)=>{
|
|
2758
|
+
const useScriptTag = (src, onLoaded = noop$1, options = defaultOptions$1)=>{
|
|
2757
2759
|
const { immediate = true, manual = false, type = 'text/javascript', async = true, crossOrigin, referrerPolicy, noModule, defer, attrs = {} } = options;
|
|
2758
2760
|
const scriptTag = useRef(null);
|
|
2759
2761
|
const _promise = useRef(null);
|