@reactuses/core 5.0.6 → 5.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/index.cjs +15 -12
- package/dist/index.d.cts +81 -76
- package/dist/index.d.mts +81 -76
- package/dist/index.d.ts +81 -76
- package/dist/index.mjs +15 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,6 +66,10 @@ You can submit an [issue](https://github.com/childrentime/reactuse/issues) or pr
|
|
|
66
66
|
|
|
67
67
|
See the [**Contributing Guide**](https://github.com/childrentime/reactuse/blob/main/CONTRIBUTING.md)
|
|
68
68
|
|
|
69
|
+
## ChangeLog
|
|
70
|
+
|
|
71
|
+
See the [**ChangeLog**](https://github.com/childrentime/reactuse/blob/main/packages/core/changelog.md)
|
|
72
|
+
|
|
69
73
|
<hr/>
|
|
70
74
|
|
|
71
75
|
## Thanks
|
package/dist/index.cjs
CHANGED
|
@@ -181,10 +181,13 @@ const useAsyncEffect = (effect, cleanup = noop, deps)=>{
|
|
|
181
181
|
const listerOptions = {
|
|
182
182
|
passive: true
|
|
183
183
|
};
|
|
184
|
-
const useClickOutside = (target, handler)=>{
|
|
184
|
+
const useClickOutside = (target, handler, enabled = true)=>{
|
|
185
185
|
const savedHandler = useLatest(handler);
|
|
186
186
|
const listener = (event)=>{
|
|
187
|
-
|
|
187
|
+
if (!enabled) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const element = getTargetElement(target);
|
|
188
191
|
if (!element) {
|
|
189
192
|
return;
|
|
190
193
|
}
|
|
@@ -822,19 +825,19 @@ const useDraggable = (target, options = {})=>{
|
|
|
822
825
|
};
|
|
823
826
|
const start = (e)=>{
|
|
824
827
|
var _container_getBoundingClientRect;
|
|
825
|
-
const element = target
|
|
828
|
+
const element = getTargetElement(target);
|
|
826
829
|
if (!filterEvent(e) || !element) {
|
|
827
830
|
return;
|
|
828
831
|
}
|
|
829
832
|
if (options.exact && e.target !== element) {
|
|
830
833
|
return;
|
|
831
834
|
}
|
|
832
|
-
const container = containerElement
|
|
835
|
+
const container = getTargetElement(containerElement);
|
|
833
836
|
const containerRect = container == null ? void 0 : (_container_getBoundingClientRect = container.getBoundingClientRect) == null ? void 0 : _container_getBoundingClientRect.call(container);
|
|
834
837
|
const targetRect = element.getBoundingClientRect();
|
|
835
838
|
const pos = {
|
|
836
|
-
x: e.clientX - (container ? targetRect.left - containerRect.left + container.scrollLeft : targetRect.left),
|
|
837
|
-
y: e.clientY - (container ? targetRect.top - containerRect.top + container.scrollTop : targetRect.top)
|
|
839
|
+
x: e.clientX - (container && containerRect ? targetRect.left - (containerRect == null ? void 0 : containerRect.left) + container.scrollLeft : targetRect.left),
|
|
840
|
+
y: e.clientY - (container && containerRect ? targetRect.top - containerRect.top + container.scrollTop : targetRect.top)
|
|
838
841
|
};
|
|
839
842
|
if ((options.onStart == null ? void 0 : options.onStart.call(options, pos, e)) === false) {
|
|
840
843
|
return;
|
|
@@ -843,14 +846,14 @@ const useDraggable = (target, options = {})=>{
|
|
|
843
846
|
handleEvent(e);
|
|
844
847
|
};
|
|
845
848
|
const move = (e)=>{
|
|
846
|
-
const element = target
|
|
849
|
+
const element = getTargetElement(target);
|
|
847
850
|
if (!filterEvent(e) || !element) {
|
|
848
851
|
return;
|
|
849
852
|
}
|
|
850
853
|
if (!pressedDelta) {
|
|
851
854
|
return;
|
|
852
855
|
}
|
|
853
|
-
const container = containerElement
|
|
856
|
+
const container = getTargetElement(containerElement);
|
|
854
857
|
const targetRect = element.getBoundingClientRect();
|
|
855
858
|
let { x, y } = position;
|
|
856
859
|
x = e.clientX - pressedDelta.x;
|
|
@@ -929,7 +932,7 @@ const useResizeObserver = (target, callback, options = defaultOptions$1)=>{
|
|
|
929
932
|
}
|
|
930
933
|
}, []);
|
|
931
934
|
useDeepCompareEffect(()=>{
|
|
932
|
-
const element = target
|
|
935
|
+
const element = getTargetElement(target);
|
|
933
936
|
if (!element) {
|
|
934
937
|
return;
|
|
935
938
|
}
|
|
@@ -956,7 +959,7 @@ const useElementBounding = (target, options = defaultOptions$1)=>{
|
|
|
956
959
|
const [x, setX] = React.useState(0);
|
|
957
960
|
const [y, setY] = React.useState(0);
|
|
958
961
|
const update = useEvent(()=>{
|
|
959
|
-
const element = target
|
|
962
|
+
const element = getTargetElement(target);
|
|
960
963
|
if (!element) {
|
|
961
964
|
if (reset) {
|
|
962
965
|
setHeight(0);
|
|
@@ -1056,7 +1059,7 @@ const useIntersectionObserver = (target, callback, options = defaultOptions$1)=>
|
|
|
1056
1059
|
}
|
|
1057
1060
|
}, []);
|
|
1058
1061
|
useDeepCompareEffect(()=>{
|
|
1059
|
-
const element = target
|
|
1062
|
+
const element = getTargetElement(target);
|
|
1060
1063
|
if (!element) {
|
|
1061
1064
|
return;
|
|
1062
1065
|
}
|
|
@@ -2077,7 +2080,7 @@ const useMousePressed = (target, options = defaultOptions$1)=>{
|
|
|
2077
2080
|
const { touch = true, drag = true, initialValue = false } = options;
|
|
2078
2081
|
const [pressed, setPressed] = React.useState(initialValue);
|
|
2079
2082
|
const [sourceType, setSourceType] = React.useState(null);
|
|
2080
|
-
const element = target
|
|
2083
|
+
const element = getTargetElement(target);
|
|
2081
2084
|
const onPressed = React.useCallback((srcType)=>()=>{
|
|
2082
2085
|
setPressed(true);
|
|
2083
2086
|
setSourceType(srcType);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import react__default, { DependencyList,
|
|
2
|
+
import react__default, { DependencyList, MutableRefObject, EffectCallback, Dispatch, SetStateAction, RefObject, useEffect, useLayoutEffect } from 'react';
|
|
3
3
|
import Cookies from 'js-cookie';
|
|
4
4
|
import { DebounceSettings, ThrottleSettings, DebouncedFunc as DebouncedFunc$1 } from 'lodash-es';
|
|
5
5
|
import * as lodash from 'lodash';
|
|
@@ -38,6 +38,10 @@ deps?: DependencyList) => void;
|
|
|
38
38
|
|
|
39
39
|
declare const useAsyncEffect: UseAsyncEffect;
|
|
40
40
|
|
|
41
|
+
type TargetValue<T> = T | undefined | null;
|
|
42
|
+
type TargetType = HTMLElement | Element | Window | Document | EventTarget;
|
|
43
|
+
type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
|
|
44
|
+
|
|
41
45
|
/**
|
|
42
46
|
* @title useClickOutside
|
|
43
47
|
*/
|
|
@@ -46,12 +50,17 @@ type UseClickOutside = (
|
|
|
46
50
|
* @zh dom对象
|
|
47
51
|
* @en dom element
|
|
48
52
|
*/
|
|
49
|
-
target:
|
|
53
|
+
target: BasicTarget<Element>,
|
|
50
54
|
/**
|
|
51
55
|
* @zh 监听函数
|
|
52
56
|
* @en listener fucntion
|
|
53
57
|
*/
|
|
54
|
-
handler: (evt: EventType) => void
|
|
58
|
+
handler: (evt: EventType) => void,
|
|
59
|
+
/**
|
|
60
|
+
* @zh 监听函数是否生效
|
|
61
|
+
* @en whether the listener fucntion is enabled
|
|
62
|
+
*/
|
|
63
|
+
enabled?: boolean) => void;
|
|
55
64
|
type EventType = MouseEvent | TouchEvent;
|
|
56
65
|
|
|
57
66
|
declare const useClickOutside: UseClickOutside;
|
|
@@ -166,10 +175,6 @@ min?: number | null) => readonly [
|
|
|
166
175
|
|
|
167
176
|
declare const useCounter: UseCounter;
|
|
168
177
|
|
|
169
|
-
type TargetValue<T> = T | undefined | null;
|
|
170
|
-
type TargetType = HTMLElement | Element | Window | Document | EventTarget;
|
|
171
|
-
type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
|
|
172
|
-
|
|
173
178
|
declare const defaultOptions: UseCssVarOptions;
|
|
174
179
|
/**
|
|
175
180
|
* @title useCssVar
|
|
@@ -414,7 +419,7 @@ interface UseDoubleClickProps {
|
|
|
414
419
|
* @zh dom对象
|
|
415
420
|
* @en dom element
|
|
416
421
|
*/
|
|
417
|
-
target:
|
|
422
|
+
target: BasicTarget<Element>;
|
|
418
423
|
/**
|
|
419
424
|
* @zh 延迟时间(毫秒)
|
|
420
425
|
* @en latency time (milliseconds)
|
|
@@ -460,7 +465,7 @@ type UseDraggable = (
|
|
|
460
465
|
* @zh dom对象
|
|
461
466
|
* @en dom element
|
|
462
467
|
*/
|
|
463
|
-
target:
|
|
468
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
464
469
|
/**
|
|
465
470
|
* @zh 可选参数
|
|
466
471
|
* @en optional params
|
|
@@ -499,7 +504,7 @@ interface UseDraggableOptions {
|
|
|
499
504
|
* @zh 设置拖拽容器边界
|
|
500
505
|
* @defaultValue undefined
|
|
501
506
|
*/
|
|
502
|
-
containerElement?:
|
|
507
|
+
containerElement?: BasicTarget<HTMLElement | SVGAElement>;
|
|
503
508
|
/**
|
|
504
509
|
* @en Handle that triggers the drag event
|
|
505
510
|
* @zh 触发拖动事件的dom元素
|
|
@@ -547,7 +552,7 @@ type UseDropZone = (
|
|
|
547
552
|
* @zh 目标元素
|
|
548
553
|
* @en target element
|
|
549
554
|
*/
|
|
550
|
-
target:
|
|
555
|
+
target: BasicTarget<EventTarget>,
|
|
551
556
|
/**
|
|
552
557
|
* @zh 拖拽释放时候的回调
|
|
553
558
|
* @en drop callback
|
|
@@ -564,7 +569,7 @@ type UseElementBounding = (
|
|
|
564
569
|
* @zh 目标元素
|
|
565
570
|
* @en target element
|
|
566
571
|
*/
|
|
567
|
-
target:
|
|
572
|
+
target: BasicTarget<Element>,
|
|
568
573
|
/**
|
|
569
574
|
* @zh 可选参数
|
|
570
575
|
* @en optional params
|
|
@@ -666,7 +671,7 @@ type UseElementSize = (
|
|
|
666
671
|
* @zh dom对象
|
|
667
672
|
* @en dom element
|
|
668
673
|
*/
|
|
669
|
-
target:
|
|
674
|
+
target: BasicTarget<Element>,
|
|
670
675
|
/**
|
|
671
676
|
* @zh `resizeObserver` 参数
|
|
672
677
|
* @en options passed to `resizeObserver`
|
|
@@ -689,7 +694,7 @@ type UseElementVisibility = (
|
|
|
689
694
|
* @zh dom对象
|
|
690
695
|
* @en dom element
|
|
691
696
|
*/
|
|
692
|
-
target:
|
|
697
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
693
698
|
/**
|
|
694
699
|
* @zh 传递给 `intersectionObserver` 的选项
|
|
695
700
|
* @en options passed to `intersectionObserver`
|
|
@@ -870,7 +875,7 @@ type UseFocus = (
|
|
|
870
875
|
* @zh dom对象
|
|
871
876
|
* @en dom element
|
|
872
877
|
*/
|
|
873
|
-
target:
|
|
878
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
874
879
|
/**
|
|
875
880
|
* @zh 默认值
|
|
876
881
|
* @en defaultValue
|
|
@@ -922,7 +927,7 @@ type UseFullscreen = (
|
|
|
922
927
|
* @zh dom元素
|
|
923
928
|
* @en dom element
|
|
924
929
|
*/
|
|
925
|
-
target:
|
|
930
|
+
target: BasicTarget<Element>,
|
|
926
931
|
/**
|
|
927
932
|
* @zh 可选参数
|
|
928
933
|
* @en optional params
|
|
@@ -998,7 +1003,17 @@ options?: Partial<PositionOptions>) => {
|
|
|
998
1003
|
|
|
999
1004
|
declare const useGeolocation: UseGeolocation;
|
|
1000
1005
|
|
|
1001
|
-
|
|
1006
|
+
/**
|
|
1007
|
+
* @title useHover
|
|
1008
|
+
*/
|
|
1009
|
+
type UseHover = <T extends Element = HTMLDivElement>(
|
|
1010
|
+
/**
|
|
1011
|
+
* @zh dom对象
|
|
1012
|
+
* @en dom element
|
|
1013
|
+
*/
|
|
1014
|
+
target: BasicTarget<T>) => boolean;
|
|
1015
|
+
|
|
1016
|
+
declare const useHover: UseHover;
|
|
1002
1017
|
|
|
1003
1018
|
/**
|
|
1004
1019
|
* @title UseIdle
|
|
@@ -1047,7 +1062,7 @@ type UseScroll = (
|
|
|
1047
1062
|
* @zh dom元素
|
|
1048
1063
|
* @en dom elment
|
|
1049
1064
|
*/
|
|
1050
|
-
target:
|
|
1065
|
+
target: BasicTarget<Element> | Window | Document,
|
|
1051
1066
|
/**
|
|
1052
1067
|
* @zh 可选参数
|
|
1053
1068
|
* @en optional params
|
|
@@ -1164,7 +1179,7 @@ type UseInfiniteScroll = (
|
|
|
1164
1179
|
* @zh dom元素
|
|
1165
1180
|
* @en dom element
|
|
1166
1181
|
*/
|
|
1167
|
-
target:
|
|
1182
|
+
target: BasicTarget<Element>,
|
|
1168
1183
|
/**
|
|
1169
1184
|
* @zh 加载更多函数
|
|
1170
1185
|
* @en load more function
|
|
@@ -1266,7 +1281,29 @@ interface UseInfiniteScrollDirection {
|
|
|
1266
1281
|
|
|
1267
1282
|
declare const useInfiniteScroll: UseInfiniteScroll;
|
|
1268
1283
|
|
|
1269
|
-
|
|
1284
|
+
/**
|
|
1285
|
+
* @title useIntersectionObserver
|
|
1286
|
+
* @returns 停止监听函数
|
|
1287
|
+
* @returns_en stop listening function
|
|
1288
|
+
*/
|
|
1289
|
+
type UseIntersectionObserver = (
|
|
1290
|
+
/**
|
|
1291
|
+
* @zh dom元素
|
|
1292
|
+
* @en dom element
|
|
1293
|
+
*/
|
|
1294
|
+
target: BasicTarget<Element>,
|
|
1295
|
+
/**
|
|
1296
|
+
* @zh 回调
|
|
1297
|
+
* @en callback
|
|
1298
|
+
*/
|
|
1299
|
+
callback: IntersectionObserverCallback,
|
|
1300
|
+
/**
|
|
1301
|
+
* @zh 传递给 `IntersectionObserver` 的参数
|
|
1302
|
+
* @en options passed to `IntersectionObserver`
|
|
1303
|
+
*/
|
|
1304
|
+
options?: IntersectionObserverInit) => () => void;
|
|
1305
|
+
|
|
1306
|
+
declare const useIntersectionObserver: UseIntersectionObserver;
|
|
1270
1307
|
|
|
1271
1308
|
/**
|
|
1272
1309
|
* @title useInterval
|
|
@@ -1459,7 +1496,7 @@ type UseMeasure = (
|
|
|
1459
1496
|
* @zh dom对象
|
|
1460
1497
|
* @en dom element
|
|
1461
1498
|
*/
|
|
1462
|
-
target:
|
|
1499
|
+
target: BasicTarget<Element>,
|
|
1463
1500
|
/**
|
|
1464
1501
|
* @zh 可选参数
|
|
1465
1502
|
* @en optional params
|
|
@@ -1596,7 +1633,7 @@ type UseMousePressed = (
|
|
|
1596
1633
|
* @zh dom对象
|
|
1597
1634
|
* @en dom element
|
|
1598
1635
|
*/
|
|
1599
|
-
target?:
|
|
1636
|
+
target?: BasicTarget<Element>,
|
|
1600
1637
|
/**
|
|
1601
1638
|
* @zh 可选参数
|
|
1602
1639
|
* @en optional params
|
|
@@ -1630,7 +1667,7 @@ interface UseMousePressedOptions {
|
|
|
1630
1667
|
*/
|
|
1631
1668
|
type UseMousePressedSourceType = "mouse" | "touch" | null;
|
|
1632
1669
|
|
|
1633
|
-
declare const useMousePressed:
|
|
1670
|
+
declare const useMousePressed: UseMousePressed;
|
|
1634
1671
|
|
|
1635
1672
|
/**
|
|
1636
1673
|
* @title UseMutationObserver
|
|
@@ -1923,7 +1960,27 @@ declare const useRafState: <S>(initialState: S | (() => S)) => readonly [S, Disp
|
|
|
1923
1960
|
|
|
1924
1961
|
declare const useReducedMotion: (defaultState?: boolean) => boolean;
|
|
1925
1962
|
|
|
1926
|
-
|
|
1963
|
+
/**
|
|
1964
|
+
* @title useResizeObserver
|
|
1965
|
+
*/
|
|
1966
|
+
type UseResizeObserver = (
|
|
1967
|
+
/**
|
|
1968
|
+
* @zh dom元素
|
|
1969
|
+
* @en dom element
|
|
1970
|
+
*/
|
|
1971
|
+
target: BasicTarget<Element>,
|
|
1972
|
+
/**
|
|
1973
|
+
* @zh 回调
|
|
1974
|
+
* @en callback
|
|
1975
|
+
*/
|
|
1976
|
+
callback: ResizeObserverCallback,
|
|
1977
|
+
/**
|
|
1978
|
+
* @zh `resizeObserver` 参数
|
|
1979
|
+
* @en options passed to `resizeObserver`
|
|
1980
|
+
*/
|
|
1981
|
+
options?: ResizeObserverOptions) => () => void;
|
|
1982
|
+
|
|
1983
|
+
declare const useResizeObserver: UseResizeObserver;
|
|
1927
1984
|
|
|
1928
1985
|
declare const useScreenSafeArea: () => readonly [string, string, string, string, lodash.DebouncedFunc<() => void>];
|
|
1929
1986
|
|
|
@@ -2569,38 +2626,6 @@ baseUrl?: string,
|
|
|
2569
2626
|
*/
|
|
2570
2627
|
rel?: string) => void;
|
|
2571
2628
|
|
|
2572
|
-
/**
|
|
2573
|
-
* @title useHover
|
|
2574
|
-
*/
|
|
2575
|
-
type UseHover = <T extends Element = HTMLDivElement>(
|
|
2576
|
-
/**
|
|
2577
|
-
* @zh dom对象
|
|
2578
|
-
* @en dom element
|
|
2579
|
-
*/
|
|
2580
|
-
target: RefObject<T>) => boolean;
|
|
2581
|
-
|
|
2582
|
-
/**
|
|
2583
|
-
* @title useIntersectionObserver
|
|
2584
|
-
* @returns 停止监听函数
|
|
2585
|
-
* @returns_en stop listening function
|
|
2586
|
-
*/
|
|
2587
|
-
type UseIntersectionObserver = (
|
|
2588
|
-
/**
|
|
2589
|
-
* @zh dom元素
|
|
2590
|
-
* @en dom element
|
|
2591
|
-
*/
|
|
2592
|
-
target: RefObject<Element>,
|
|
2593
|
-
/**
|
|
2594
|
-
* @zh 回调
|
|
2595
|
-
* @en callback
|
|
2596
|
-
*/
|
|
2597
|
-
callback: IntersectionObserverCallback,
|
|
2598
|
-
/**
|
|
2599
|
-
* @zh 传递给 `IntersectionObserver` 的参数
|
|
2600
|
-
* @en options passed to `IntersectionObserver`
|
|
2601
|
-
*/
|
|
2602
|
-
options?: IntersectionObserverInit) => () => void;
|
|
2603
|
-
|
|
2604
2629
|
/**
|
|
2605
2630
|
* @title useLocalStorage
|
|
2606
2631
|
* @returns 包含以下元素的元组:
|
|
@@ -2729,26 +2754,6 @@ type UseReducedMotion = (
|
|
|
2729
2754
|
*/
|
|
2730
2755
|
defaultState?: boolean) => boolean;
|
|
2731
2756
|
|
|
2732
|
-
/**
|
|
2733
|
-
* @title useResizeObserver
|
|
2734
|
-
*/
|
|
2735
|
-
type UseResizeObserver = (
|
|
2736
|
-
/**
|
|
2737
|
-
* @zh dom元素
|
|
2738
|
-
* @en dom element
|
|
2739
|
-
*/
|
|
2740
|
-
target: RefObject<Element>,
|
|
2741
|
-
/**
|
|
2742
|
-
* @zh 回调
|
|
2743
|
-
* @en callback
|
|
2744
|
-
*/
|
|
2745
|
-
callback: ResizeObserverCallback,
|
|
2746
|
-
/**
|
|
2747
|
-
* @zh `resizeObserver` 参数
|
|
2748
|
-
* @en options passed to `resizeObserver`
|
|
2749
|
-
*/
|
|
2750
|
-
options?: ResizeObserverOptions) => () => void;
|
|
2751
|
-
|
|
2752
2757
|
/**
|
|
2753
2758
|
* @title useScreenSafeArea
|
|
2754
2759
|
* @returns 包含以下元素的元组:
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import react__default, { DependencyList,
|
|
2
|
+
import react__default, { DependencyList, MutableRefObject, EffectCallback, Dispatch, SetStateAction, RefObject, useEffect, useLayoutEffect } from 'react';
|
|
3
3
|
import Cookies from 'js-cookie';
|
|
4
4
|
import { DebounceSettings, ThrottleSettings, DebouncedFunc as DebouncedFunc$1 } from 'lodash-es';
|
|
5
5
|
import * as lodash from 'lodash';
|
|
@@ -38,6 +38,10 @@ deps?: DependencyList) => void;
|
|
|
38
38
|
|
|
39
39
|
declare const useAsyncEffect: UseAsyncEffect;
|
|
40
40
|
|
|
41
|
+
type TargetValue<T> = T | undefined | null;
|
|
42
|
+
type TargetType = HTMLElement | Element | Window | Document | EventTarget;
|
|
43
|
+
type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
|
|
44
|
+
|
|
41
45
|
/**
|
|
42
46
|
* @title useClickOutside
|
|
43
47
|
*/
|
|
@@ -46,12 +50,17 @@ type UseClickOutside = (
|
|
|
46
50
|
* @zh dom对象
|
|
47
51
|
* @en dom element
|
|
48
52
|
*/
|
|
49
|
-
target:
|
|
53
|
+
target: BasicTarget<Element>,
|
|
50
54
|
/**
|
|
51
55
|
* @zh 监听函数
|
|
52
56
|
* @en listener fucntion
|
|
53
57
|
*/
|
|
54
|
-
handler: (evt: EventType) => void
|
|
58
|
+
handler: (evt: EventType) => void,
|
|
59
|
+
/**
|
|
60
|
+
* @zh 监听函数是否生效
|
|
61
|
+
* @en whether the listener fucntion is enabled
|
|
62
|
+
*/
|
|
63
|
+
enabled?: boolean) => void;
|
|
55
64
|
type EventType = MouseEvent | TouchEvent;
|
|
56
65
|
|
|
57
66
|
declare const useClickOutside: UseClickOutside;
|
|
@@ -166,10 +175,6 @@ min?: number | null) => readonly [
|
|
|
166
175
|
|
|
167
176
|
declare const useCounter: UseCounter;
|
|
168
177
|
|
|
169
|
-
type TargetValue<T> = T | undefined | null;
|
|
170
|
-
type TargetType = HTMLElement | Element | Window | Document | EventTarget;
|
|
171
|
-
type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
|
|
172
|
-
|
|
173
178
|
declare const defaultOptions: UseCssVarOptions;
|
|
174
179
|
/**
|
|
175
180
|
* @title useCssVar
|
|
@@ -414,7 +419,7 @@ interface UseDoubleClickProps {
|
|
|
414
419
|
* @zh dom对象
|
|
415
420
|
* @en dom element
|
|
416
421
|
*/
|
|
417
|
-
target:
|
|
422
|
+
target: BasicTarget<Element>;
|
|
418
423
|
/**
|
|
419
424
|
* @zh 延迟时间(毫秒)
|
|
420
425
|
* @en latency time (milliseconds)
|
|
@@ -460,7 +465,7 @@ type UseDraggable = (
|
|
|
460
465
|
* @zh dom对象
|
|
461
466
|
* @en dom element
|
|
462
467
|
*/
|
|
463
|
-
target:
|
|
468
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
464
469
|
/**
|
|
465
470
|
* @zh 可选参数
|
|
466
471
|
* @en optional params
|
|
@@ -499,7 +504,7 @@ interface UseDraggableOptions {
|
|
|
499
504
|
* @zh 设置拖拽容器边界
|
|
500
505
|
* @defaultValue undefined
|
|
501
506
|
*/
|
|
502
|
-
containerElement?:
|
|
507
|
+
containerElement?: BasicTarget<HTMLElement | SVGAElement>;
|
|
503
508
|
/**
|
|
504
509
|
* @en Handle that triggers the drag event
|
|
505
510
|
* @zh 触发拖动事件的dom元素
|
|
@@ -547,7 +552,7 @@ type UseDropZone = (
|
|
|
547
552
|
* @zh 目标元素
|
|
548
553
|
* @en target element
|
|
549
554
|
*/
|
|
550
|
-
target:
|
|
555
|
+
target: BasicTarget<EventTarget>,
|
|
551
556
|
/**
|
|
552
557
|
* @zh 拖拽释放时候的回调
|
|
553
558
|
* @en drop callback
|
|
@@ -564,7 +569,7 @@ type UseElementBounding = (
|
|
|
564
569
|
* @zh 目标元素
|
|
565
570
|
* @en target element
|
|
566
571
|
*/
|
|
567
|
-
target:
|
|
572
|
+
target: BasicTarget<Element>,
|
|
568
573
|
/**
|
|
569
574
|
* @zh 可选参数
|
|
570
575
|
* @en optional params
|
|
@@ -666,7 +671,7 @@ type UseElementSize = (
|
|
|
666
671
|
* @zh dom对象
|
|
667
672
|
* @en dom element
|
|
668
673
|
*/
|
|
669
|
-
target:
|
|
674
|
+
target: BasicTarget<Element>,
|
|
670
675
|
/**
|
|
671
676
|
* @zh `resizeObserver` 参数
|
|
672
677
|
* @en options passed to `resizeObserver`
|
|
@@ -689,7 +694,7 @@ type UseElementVisibility = (
|
|
|
689
694
|
* @zh dom对象
|
|
690
695
|
* @en dom element
|
|
691
696
|
*/
|
|
692
|
-
target:
|
|
697
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
693
698
|
/**
|
|
694
699
|
* @zh 传递给 `intersectionObserver` 的选项
|
|
695
700
|
* @en options passed to `intersectionObserver`
|
|
@@ -870,7 +875,7 @@ type UseFocus = (
|
|
|
870
875
|
* @zh dom对象
|
|
871
876
|
* @en dom element
|
|
872
877
|
*/
|
|
873
|
-
target:
|
|
878
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
874
879
|
/**
|
|
875
880
|
* @zh 默认值
|
|
876
881
|
* @en defaultValue
|
|
@@ -922,7 +927,7 @@ type UseFullscreen = (
|
|
|
922
927
|
* @zh dom元素
|
|
923
928
|
* @en dom element
|
|
924
929
|
*/
|
|
925
|
-
target:
|
|
930
|
+
target: BasicTarget<Element>,
|
|
926
931
|
/**
|
|
927
932
|
* @zh 可选参数
|
|
928
933
|
* @en optional params
|
|
@@ -998,7 +1003,17 @@ options?: Partial<PositionOptions>) => {
|
|
|
998
1003
|
|
|
999
1004
|
declare const useGeolocation: UseGeolocation;
|
|
1000
1005
|
|
|
1001
|
-
|
|
1006
|
+
/**
|
|
1007
|
+
* @title useHover
|
|
1008
|
+
*/
|
|
1009
|
+
type UseHover = <T extends Element = HTMLDivElement>(
|
|
1010
|
+
/**
|
|
1011
|
+
* @zh dom对象
|
|
1012
|
+
* @en dom element
|
|
1013
|
+
*/
|
|
1014
|
+
target: BasicTarget<T>) => boolean;
|
|
1015
|
+
|
|
1016
|
+
declare const useHover: UseHover;
|
|
1002
1017
|
|
|
1003
1018
|
/**
|
|
1004
1019
|
* @title UseIdle
|
|
@@ -1047,7 +1062,7 @@ type UseScroll = (
|
|
|
1047
1062
|
* @zh dom元素
|
|
1048
1063
|
* @en dom elment
|
|
1049
1064
|
*/
|
|
1050
|
-
target:
|
|
1065
|
+
target: BasicTarget<Element> | Window | Document,
|
|
1051
1066
|
/**
|
|
1052
1067
|
* @zh 可选参数
|
|
1053
1068
|
* @en optional params
|
|
@@ -1164,7 +1179,7 @@ type UseInfiniteScroll = (
|
|
|
1164
1179
|
* @zh dom元素
|
|
1165
1180
|
* @en dom element
|
|
1166
1181
|
*/
|
|
1167
|
-
target:
|
|
1182
|
+
target: BasicTarget<Element>,
|
|
1168
1183
|
/**
|
|
1169
1184
|
* @zh 加载更多函数
|
|
1170
1185
|
* @en load more function
|
|
@@ -1266,7 +1281,29 @@ interface UseInfiniteScrollDirection {
|
|
|
1266
1281
|
|
|
1267
1282
|
declare const useInfiniteScroll: UseInfiniteScroll;
|
|
1268
1283
|
|
|
1269
|
-
|
|
1284
|
+
/**
|
|
1285
|
+
* @title useIntersectionObserver
|
|
1286
|
+
* @returns 停止监听函数
|
|
1287
|
+
* @returns_en stop listening function
|
|
1288
|
+
*/
|
|
1289
|
+
type UseIntersectionObserver = (
|
|
1290
|
+
/**
|
|
1291
|
+
* @zh dom元素
|
|
1292
|
+
* @en dom element
|
|
1293
|
+
*/
|
|
1294
|
+
target: BasicTarget<Element>,
|
|
1295
|
+
/**
|
|
1296
|
+
* @zh 回调
|
|
1297
|
+
* @en callback
|
|
1298
|
+
*/
|
|
1299
|
+
callback: IntersectionObserverCallback,
|
|
1300
|
+
/**
|
|
1301
|
+
* @zh 传递给 `IntersectionObserver` 的参数
|
|
1302
|
+
* @en options passed to `IntersectionObserver`
|
|
1303
|
+
*/
|
|
1304
|
+
options?: IntersectionObserverInit) => () => void;
|
|
1305
|
+
|
|
1306
|
+
declare const useIntersectionObserver: UseIntersectionObserver;
|
|
1270
1307
|
|
|
1271
1308
|
/**
|
|
1272
1309
|
* @title useInterval
|
|
@@ -1459,7 +1496,7 @@ type UseMeasure = (
|
|
|
1459
1496
|
* @zh dom对象
|
|
1460
1497
|
* @en dom element
|
|
1461
1498
|
*/
|
|
1462
|
-
target:
|
|
1499
|
+
target: BasicTarget<Element>,
|
|
1463
1500
|
/**
|
|
1464
1501
|
* @zh 可选参数
|
|
1465
1502
|
* @en optional params
|
|
@@ -1596,7 +1633,7 @@ type UseMousePressed = (
|
|
|
1596
1633
|
* @zh dom对象
|
|
1597
1634
|
* @en dom element
|
|
1598
1635
|
*/
|
|
1599
|
-
target?:
|
|
1636
|
+
target?: BasicTarget<Element>,
|
|
1600
1637
|
/**
|
|
1601
1638
|
* @zh 可选参数
|
|
1602
1639
|
* @en optional params
|
|
@@ -1630,7 +1667,7 @@ interface UseMousePressedOptions {
|
|
|
1630
1667
|
*/
|
|
1631
1668
|
type UseMousePressedSourceType = "mouse" | "touch" | null;
|
|
1632
1669
|
|
|
1633
|
-
declare const useMousePressed:
|
|
1670
|
+
declare const useMousePressed: UseMousePressed;
|
|
1634
1671
|
|
|
1635
1672
|
/**
|
|
1636
1673
|
* @title UseMutationObserver
|
|
@@ -1923,7 +1960,27 @@ declare const useRafState: <S>(initialState: S | (() => S)) => readonly [S, Disp
|
|
|
1923
1960
|
|
|
1924
1961
|
declare const useReducedMotion: (defaultState?: boolean) => boolean;
|
|
1925
1962
|
|
|
1926
|
-
|
|
1963
|
+
/**
|
|
1964
|
+
* @title useResizeObserver
|
|
1965
|
+
*/
|
|
1966
|
+
type UseResizeObserver = (
|
|
1967
|
+
/**
|
|
1968
|
+
* @zh dom元素
|
|
1969
|
+
* @en dom element
|
|
1970
|
+
*/
|
|
1971
|
+
target: BasicTarget<Element>,
|
|
1972
|
+
/**
|
|
1973
|
+
* @zh 回调
|
|
1974
|
+
* @en callback
|
|
1975
|
+
*/
|
|
1976
|
+
callback: ResizeObserverCallback,
|
|
1977
|
+
/**
|
|
1978
|
+
* @zh `resizeObserver` 参数
|
|
1979
|
+
* @en options passed to `resizeObserver`
|
|
1980
|
+
*/
|
|
1981
|
+
options?: ResizeObserverOptions) => () => void;
|
|
1982
|
+
|
|
1983
|
+
declare const useResizeObserver: UseResizeObserver;
|
|
1927
1984
|
|
|
1928
1985
|
declare const useScreenSafeArea: () => readonly [string, string, string, string, lodash.DebouncedFunc<() => void>];
|
|
1929
1986
|
|
|
@@ -2569,38 +2626,6 @@ baseUrl?: string,
|
|
|
2569
2626
|
*/
|
|
2570
2627
|
rel?: string) => void;
|
|
2571
2628
|
|
|
2572
|
-
/**
|
|
2573
|
-
* @title useHover
|
|
2574
|
-
*/
|
|
2575
|
-
type UseHover = <T extends Element = HTMLDivElement>(
|
|
2576
|
-
/**
|
|
2577
|
-
* @zh dom对象
|
|
2578
|
-
* @en dom element
|
|
2579
|
-
*/
|
|
2580
|
-
target: RefObject<T>) => boolean;
|
|
2581
|
-
|
|
2582
|
-
/**
|
|
2583
|
-
* @title useIntersectionObserver
|
|
2584
|
-
* @returns 停止监听函数
|
|
2585
|
-
* @returns_en stop listening function
|
|
2586
|
-
*/
|
|
2587
|
-
type UseIntersectionObserver = (
|
|
2588
|
-
/**
|
|
2589
|
-
* @zh dom元素
|
|
2590
|
-
* @en dom element
|
|
2591
|
-
*/
|
|
2592
|
-
target: RefObject<Element>,
|
|
2593
|
-
/**
|
|
2594
|
-
* @zh 回调
|
|
2595
|
-
* @en callback
|
|
2596
|
-
*/
|
|
2597
|
-
callback: IntersectionObserverCallback,
|
|
2598
|
-
/**
|
|
2599
|
-
* @zh 传递给 `IntersectionObserver` 的参数
|
|
2600
|
-
* @en options passed to `IntersectionObserver`
|
|
2601
|
-
*/
|
|
2602
|
-
options?: IntersectionObserverInit) => () => void;
|
|
2603
|
-
|
|
2604
2629
|
/**
|
|
2605
2630
|
* @title useLocalStorage
|
|
2606
2631
|
* @returns 包含以下元素的元组:
|
|
@@ -2729,26 +2754,6 @@ type UseReducedMotion = (
|
|
|
2729
2754
|
*/
|
|
2730
2755
|
defaultState?: boolean) => boolean;
|
|
2731
2756
|
|
|
2732
|
-
/**
|
|
2733
|
-
* @title useResizeObserver
|
|
2734
|
-
*/
|
|
2735
|
-
type UseResizeObserver = (
|
|
2736
|
-
/**
|
|
2737
|
-
* @zh dom元素
|
|
2738
|
-
* @en dom element
|
|
2739
|
-
*/
|
|
2740
|
-
target: RefObject<Element>,
|
|
2741
|
-
/**
|
|
2742
|
-
* @zh 回调
|
|
2743
|
-
* @en callback
|
|
2744
|
-
*/
|
|
2745
|
-
callback: ResizeObserverCallback,
|
|
2746
|
-
/**
|
|
2747
|
-
* @zh `resizeObserver` 参数
|
|
2748
|
-
* @en options passed to `resizeObserver`
|
|
2749
|
-
*/
|
|
2750
|
-
options?: ResizeObserverOptions) => () => void;
|
|
2751
|
-
|
|
2752
2757
|
/**
|
|
2753
2758
|
* @title useScreenSafeArea
|
|
2754
2759
|
* @returns 包含以下元素的元组:
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import react__default, { DependencyList,
|
|
2
|
+
import react__default, { DependencyList, MutableRefObject, EffectCallback, Dispatch, SetStateAction, RefObject, useEffect, useLayoutEffect } from 'react';
|
|
3
3
|
import Cookies from 'js-cookie';
|
|
4
4
|
import { DebounceSettings, ThrottleSettings, DebouncedFunc as DebouncedFunc$1 } from 'lodash-es';
|
|
5
5
|
import * as lodash from 'lodash';
|
|
@@ -38,6 +38,10 @@ deps?: DependencyList) => void;
|
|
|
38
38
|
|
|
39
39
|
declare const useAsyncEffect: UseAsyncEffect;
|
|
40
40
|
|
|
41
|
+
type TargetValue<T> = T | undefined | null;
|
|
42
|
+
type TargetType = HTMLElement | Element | Window | Document | EventTarget;
|
|
43
|
+
type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
|
|
44
|
+
|
|
41
45
|
/**
|
|
42
46
|
* @title useClickOutside
|
|
43
47
|
*/
|
|
@@ -46,12 +50,17 @@ type UseClickOutside = (
|
|
|
46
50
|
* @zh dom对象
|
|
47
51
|
* @en dom element
|
|
48
52
|
*/
|
|
49
|
-
target:
|
|
53
|
+
target: BasicTarget<Element>,
|
|
50
54
|
/**
|
|
51
55
|
* @zh 监听函数
|
|
52
56
|
* @en listener fucntion
|
|
53
57
|
*/
|
|
54
|
-
handler: (evt: EventType) => void
|
|
58
|
+
handler: (evt: EventType) => void,
|
|
59
|
+
/**
|
|
60
|
+
* @zh 监听函数是否生效
|
|
61
|
+
* @en whether the listener fucntion is enabled
|
|
62
|
+
*/
|
|
63
|
+
enabled?: boolean) => void;
|
|
55
64
|
type EventType = MouseEvent | TouchEvent;
|
|
56
65
|
|
|
57
66
|
declare const useClickOutside: UseClickOutside;
|
|
@@ -166,10 +175,6 @@ min?: number | null) => readonly [
|
|
|
166
175
|
|
|
167
176
|
declare const useCounter: UseCounter;
|
|
168
177
|
|
|
169
|
-
type TargetValue<T> = T | undefined | null;
|
|
170
|
-
type TargetType = HTMLElement | Element | Window | Document | EventTarget;
|
|
171
|
-
type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;
|
|
172
|
-
|
|
173
178
|
declare const defaultOptions: UseCssVarOptions;
|
|
174
179
|
/**
|
|
175
180
|
* @title useCssVar
|
|
@@ -414,7 +419,7 @@ interface UseDoubleClickProps {
|
|
|
414
419
|
* @zh dom对象
|
|
415
420
|
* @en dom element
|
|
416
421
|
*/
|
|
417
|
-
target:
|
|
422
|
+
target: BasicTarget<Element>;
|
|
418
423
|
/**
|
|
419
424
|
* @zh 延迟时间(毫秒)
|
|
420
425
|
* @en latency time (milliseconds)
|
|
@@ -460,7 +465,7 @@ type UseDraggable = (
|
|
|
460
465
|
* @zh dom对象
|
|
461
466
|
* @en dom element
|
|
462
467
|
*/
|
|
463
|
-
target:
|
|
468
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
464
469
|
/**
|
|
465
470
|
* @zh 可选参数
|
|
466
471
|
* @en optional params
|
|
@@ -499,7 +504,7 @@ interface UseDraggableOptions {
|
|
|
499
504
|
* @zh 设置拖拽容器边界
|
|
500
505
|
* @defaultValue undefined
|
|
501
506
|
*/
|
|
502
|
-
containerElement?:
|
|
507
|
+
containerElement?: BasicTarget<HTMLElement | SVGAElement>;
|
|
503
508
|
/**
|
|
504
509
|
* @en Handle that triggers the drag event
|
|
505
510
|
* @zh 触发拖动事件的dom元素
|
|
@@ -547,7 +552,7 @@ type UseDropZone = (
|
|
|
547
552
|
* @zh 目标元素
|
|
548
553
|
* @en target element
|
|
549
554
|
*/
|
|
550
|
-
target:
|
|
555
|
+
target: BasicTarget<EventTarget>,
|
|
551
556
|
/**
|
|
552
557
|
* @zh 拖拽释放时候的回调
|
|
553
558
|
* @en drop callback
|
|
@@ -564,7 +569,7 @@ type UseElementBounding = (
|
|
|
564
569
|
* @zh 目标元素
|
|
565
570
|
* @en target element
|
|
566
571
|
*/
|
|
567
|
-
target:
|
|
572
|
+
target: BasicTarget<Element>,
|
|
568
573
|
/**
|
|
569
574
|
* @zh 可选参数
|
|
570
575
|
* @en optional params
|
|
@@ -666,7 +671,7 @@ type UseElementSize = (
|
|
|
666
671
|
* @zh dom对象
|
|
667
672
|
* @en dom element
|
|
668
673
|
*/
|
|
669
|
-
target:
|
|
674
|
+
target: BasicTarget<Element>,
|
|
670
675
|
/**
|
|
671
676
|
* @zh `resizeObserver` 参数
|
|
672
677
|
* @en options passed to `resizeObserver`
|
|
@@ -689,7 +694,7 @@ type UseElementVisibility = (
|
|
|
689
694
|
* @zh dom对象
|
|
690
695
|
* @en dom element
|
|
691
696
|
*/
|
|
692
|
-
target:
|
|
697
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
693
698
|
/**
|
|
694
699
|
* @zh 传递给 `intersectionObserver` 的选项
|
|
695
700
|
* @en options passed to `intersectionObserver`
|
|
@@ -870,7 +875,7 @@ type UseFocus = (
|
|
|
870
875
|
* @zh dom对象
|
|
871
876
|
* @en dom element
|
|
872
877
|
*/
|
|
873
|
-
target:
|
|
878
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
874
879
|
/**
|
|
875
880
|
* @zh 默认值
|
|
876
881
|
* @en defaultValue
|
|
@@ -922,7 +927,7 @@ type UseFullscreen = (
|
|
|
922
927
|
* @zh dom元素
|
|
923
928
|
* @en dom element
|
|
924
929
|
*/
|
|
925
|
-
target:
|
|
930
|
+
target: BasicTarget<Element>,
|
|
926
931
|
/**
|
|
927
932
|
* @zh 可选参数
|
|
928
933
|
* @en optional params
|
|
@@ -998,7 +1003,17 @@ options?: Partial<PositionOptions>) => {
|
|
|
998
1003
|
|
|
999
1004
|
declare const useGeolocation: UseGeolocation;
|
|
1000
1005
|
|
|
1001
|
-
|
|
1006
|
+
/**
|
|
1007
|
+
* @title useHover
|
|
1008
|
+
*/
|
|
1009
|
+
type UseHover = <T extends Element = HTMLDivElement>(
|
|
1010
|
+
/**
|
|
1011
|
+
* @zh dom对象
|
|
1012
|
+
* @en dom element
|
|
1013
|
+
*/
|
|
1014
|
+
target: BasicTarget<T>) => boolean;
|
|
1015
|
+
|
|
1016
|
+
declare const useHover: UseHover;
|
|
1002
1017
|
|
|
1003
1018
|
/**
|
|
1004
1019
|
* @title UseIdle
|
|
@@ -1047,7 +1062,7 @@ type UseScroll = (
|
|
|
1047
1062
|
* @zh dom元素
|
|
1048
1063
|
* @en dom elment
|
|
1049
1064
|
*/
|
|
1050
|
-
target:
|
|
1065
|
+
target: BasicTarget<Element> | Window | Document,
|
|
1051
1066
|
/**
|
|
1052
1067
|
* @zh 可选参数
|
|
1053
1068
|
* @en optional params
|
|
@@ -1164,7 +1179,7 @@ type UseInfiniteScroll = (
|
|
|
1164
1179
|
* @zh dom元素
|
|
1165
1180
|
* @en dom element
|
|
1166
1181
|
*/
|
|
1167
|
-
target:
|
|
1182
|
+
target: BasicTarget<Element>,
|
|
1168
1183
|
/**
|
|
1169
1184
|
* @zh 加载更多函数
|
|
1170
1185
|
* @en load more function
|
|
@@ -1266,7 +1281,29 @@ interface UseInfiniteScrollDirection {
|
|
|
1266
1281
|
|
|
1267
1282
|
declare const useInfiniteScroll: UseInfiniteScroll;
|
|
1268
1283
|
|
|
1269
|
-
|
|
1284
|
+
/**
|
|
1285
|
+
* @title useIntersectionObserver
|
|
1286
|
+
* @returns 停止监听函数
|
|
1287
|
+
* @returns_en stop listening function
|
|
1288
|
+
*/
|
|
1289
|
+
type UseIntersectionObserver = (
|
|
1290
|
+
/**
|
|
1291
|
+
* @zh dom元素
|
|
1292
|
+
* @en dom element
|
|
1293
|
+
*/
|
|
1294
|
+
target: BasicTarget<Element>,
|
|
1295
|
+
/**
|
|
1296
|
+
* @zh 回调
|
|
1297
|
+
* @en callback
|
|
1298
|
+
*/
|
|
1299
|
+
callback: IntersectionObserverCallback,
|
|
1300
|
+
/**
|
|
1301
|
+
* @zh 传递给 `IntersectionObserver` 的参数
|
|
1302
|
+
* @en options passed to `IntersectionObserver`
|
|
1303
|
+
*/
|
|
1304
|
+
options?: IntersectionObserverInit) => () => void;
|
|
1305
|
+
|
|
1306
|
+
declare const useIntersectionObserver: UseIntersectionObserver;
|
|
1270
1307
|
|
|
1271
1308
|
/**
|
|
1272
1309
|
* @title useInterval
|
|
@@ -1459,7 +1496,7 @@ type UseMeasure = (
|
|
|
1459
1496
|
* @zh dom对象
|
|
1460
1497
|
* @en dom element
|
|
1461
1498
|
*/
|
|
1462
|
-
target:
|
|
1499
|
+
target: BasicTarget<Element>,
|
|
1463
1500
|
/**
|
|
1464
1501
|
* @zh 可选参数
|
|
1465
1502
|
* @en optional params
|
|
@@ -1596,7 +1633,7 @@ type UseMousePressed = (
|
|
|
1596
1633
|
* @zh dom对象
|
|
1597
1634
|
* @en dom element
|
|
1598
1635
|
*/
|
|
1599
|
-
target?:
|
|
1636
|
+
target?: BasicTarget<Element>,
|
|
1600
1637
|
/**
|
|
1601
1638
|
* @zh 可选参数
|
|
1602
1639
|
* @en optional params
|
|
@@ -1630,7 +1667,7 @@ interface UseMousePressedOptions {
|
|
|
1630
1667
|
*/
|
|
1631
1668
|
type UseMousePressedSourceType = "mouse" | "touch" | null;
|
|
1632
1669
|
|
|
1633
|
-
declare const useMousePressed:
|
|
1670
|
+
declare const useMousePressed: UseMousePressed;
|
|
1634
1671
|
|
|
1635
1672
|
/**
|
|
1636
1673
|
* @title UseMutationObserver
|
|
@@ -1923,7 +1960,27 @@ declare const useRafState: <S>(initialState: S | (() => S)) => readonly [S, Disp
|
|
|
1923
1960
|
|
|
1924
1961
|
declare const useReducedMotion: (defaultState?: boolean) => boolean;
|
|
1925
1962
|
|
|
1926
|
-
|
|
1963
|
+
/**
|
|
1964
|
+
* @title useResizeObserver
|
|
1965
|
+
*/
|
|
1966
|
+
type UseResizeObserver = (
|
|
1967
|
+
/**
|
|
1968
|
+
* @zh dom元素
|
|
1969
|
+
* @en dom element
|
|
1970
|
+
*/
|
|
1971
|
+
target: BasicTarget<Element>,
|
|
1972
|
+
/**
|
|
1973
|
+
* @zh 回调
|
|
1974
|
+
* @en callback
|
|
1975
|
+
*/
|
|
1976
|
+
callback: ResizeObserverCallback,
|
|
1977
|
+
/**
|
|
1978
|
+
* @zh `resizeObserver` 参数
|
|
1979
|
+
* @en options passed to `resizeObserver`
|
|
1980
|
+
*/
|
|
1981
|
+
options?: ResizeObserverOptions) => () => void;
|
|
1982
|
+
|
|
1983
|
+
declare const useResizeObserver: UseResizeObserver;
|
|
1927
1984
|
|
|
1928
1985
|
declare const useScreenSafeArea: () => readonly [string, string, string, string, lodash.DebouncedFunc<() => void>];
|
|
1929
1986
|
|
|
@@ -2569,38 +2626,6 @@ baseUrl?: string,
|
|
|
2569
2626
|
*/
|
|
2570
2627
|
rel?: string) => void;
|
|
2571
2628
|
|
|
2572
|
-
/**
|
|
2573
|
-
* @title useHover
|
|
2574
|
-
*/
|
|
2575
|
-
type UseHover = <T extends Element = HTMLDivElement>(
|
|
2576
|
-
/**
|
|
2577
|
-
* @zh dom对象
|
|
2578
|
-
* @en dom element
|
|
2579
|
-
*/
|
|
2580
|
-
target: RefObject<T>) => boolean;
|
|
2581
|
-
|
|
2582
|
-
/**
|
|
2583
|
-
* @title useIntersectionObserver
|
|
2584
|
-
* @returns 停止监听函数
|
|
2585
|
-
* @returns_en stop listening function
|
|
2586
|
-
*/
|
|
2587
|
-
type UseIntersectionObserver = (
|
|
2588
|
-
/**
|
|
2589
|
-
* @zh dom元素
|
|
2590
|
-
* @en dom element
|
|
2591
|
-
*/
|
|
2592
|
-
target: RefObject<Element>,
|
|
2593
|
-
/**
|
|
2594
|
-
* @zh 回调
|
|
2595
|
-
* @en callback
|
|
2596
|
-
*/
|
|
2597
|
-
callback: IntersectionObserverCallback,
|
|
2598
|
-
/**
|
|
2599
|
-
* @zh 传递给 `IntersectionObserver` 的参数
|
|
2600
|
-
* @en options passed to `IntersectionObserver`
|
|
2601
|
-
*/
|
|
2602
|
-
options?: IntersectionObserverInit) => () => void;
|
|
2603
|
-
|
|
2604
2629
|
/**
|
|
2605
2630
|
* @title useLocalStorage
|
|
2606
2631
|
* @returns 包含以下元素的元组:
|
|
@@ -2729,26 +2754,6 @@ type UseReducedMotion = (
|
|
|
2729
2754
|
*/
|
|
2730
2755
|
defaultState?: boolean) => boolean;
|
|
2731
2756
|
|
|
2732
|
-
/**
|
|
2733
|
-
* @title useResizeObserver
|
|
2734
|
-
*/
|
|
2735
|
-
type UseResizeObserver = (
|
|
2736
|
-
/**
|
|
2737
|
-
* @zh dom元素
|
|
2738
|
-
* @en dom element
|
|
2739
|
-
*/
|
|
2740
|
-
target: RefObject<Element>,
|
|
2741
|
-
/**
|
|
2742
|
-
* @zh 回调
|
|
2743
|
-
* @en callback
|
|
2744
|
-
*/
|
|
2745
|
-
callback: ResizeObserverCallback,
|
|
2746
|
-
/**
|
|
2747
|
-
* @zh `resizeObserver` 参数
|
|
2748
|
-
* @en options passed to `resizeObserver`
|
|
2749
|
-
*/
|
|
2750
|
-
options?: ResizeObserverOptions) => () => void;
|
|
2751
|
-
|
|
2752
2757
|
/**
|
|
2753
2758
|
* @title useScreenSafeArea
|
|
2754
2759
|
* @returns 包含以下元素的元组:
|
package/dist/index.mjs
CHANGED
|
@@ -174,10 +174,13 @@ const useAsyncEffect = (effect, cleanup = noop, deps)=>{
|
|
|
174
174
|
const listerOptions = {
|
|
175
175
|
passive: true
|
|
176
176
|
};
|
|
177
|
-
const useClickOutside = (target, handler)=>{
|
|
177
|
+
const useClickOutside = (target, handler, enabled = true)=>{
|
|
178
178
|
const savedHandler = useLatest(handler);
|
|
179
179
|
const listener = (event)=>{
|
|
180
|
-
|
|
180
|
+
if (!enabled) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const element = getTargetElement(target);
|
|
181
184
|
if (!element) {
|
|
182
185
|
return;
|
|
183
186
|
}
|
|
@@ -815,19 +818,19 @@ const useDraggable = (target, options = {})=>{
|
|
|
815
818
|
};
|
|
816
819
|
const start = (e)=>{
|
|
817
820
|
var _container_getBoundingClientRect;
|
|
818
|
-
const element = target
|
|
821
|
+
const element = getTargetElement(target);
|
|
819
822
|
if (!filterEvent(e) || !element) {
|
|
820
823
|
return;
|
|
821
824
|
}
|
|
822
825
|
if (options.exact && e.target !== element) {
|
|
823
826
|
return;
|
|
824
827
|
}
|
|
825
|
-
const container = containerElement
|
|
828
|
+
const container = getTargetElement(containerElement);
|
|
826
829
|
const containerRect = container == null ? void 0 : (_container_getBoundingClientRect = container.getBoundingClientRect) == null ? void 0 : _container_getBoundingClientRect.call(container);
|
|
827
830
|
const targetRect = element.getBoundingClientRect();
|
|
828
831
|
const pos = {
|
|
829
|
-
x: e.clientX - (container ? targetRect.left - containerRect.left + container.scrollLeft : targetRect.left),
|
|
830
|
-
y: e.clientY - (container ? targetRect.top - containerRect.top + container.scrollTop : targetRect.top)
|
|
832
|
+
x: e.clientX - (container && containerRect ? targetRect.left - (containerRect == null ? void 0 : containerRect.left) + container.scrollLeft : targetRect.left),
|
|
833
|
+
y: e.clientY - (container && containerRect ? targetRect.top - containerRect.top + container.scrollTop : targetRect.top)
|
|
831
834
|
};
|
|
832
835
|
if ((options.onStart == null ? void 0 : options.onStart.call(options, pos, e)) === false) {
|
|
833
836
|
return;
|
|
@@ -836,14 +839,14 @@ const useDraggable = (target, options = {})=>{
|
|
|
836
839
|
handleEvent(e);
|
|
837
840
|
};
|
|
838
841
|
const move = (e)=>{
|
|
839
|
-
const element = target
|
|
842
|
+
const element = getTargetElement(target);
|
|
840
843
|
if (!filterEvent(e) || !element) {
|
|
841
844
|
return;
|
|
842
845
|
}
|
|
843
846
|
if (!pressedDelta) {
|
|
844
847
|
return;
|
|
845
848
|
}
|
|
846
|
-
const container = containerElement
|
|
849
|
+
const container = getTargetElement(containerElement);
|
|
847
850
|
const targetRect = element.getBoundingClientRect();
|
|
848
851
|
let { x, y } = position;
|
|
849
852
|
x = e.clientX - pressedDelta.x;
|
|
@@ -922,7 +925,7 @@ const useResizeObserver = (target, callback, options = defaultOptions$1)=>{
|
|
|
922
925
|
}
|
|
923
926
|
}, []);
|
|
924
927
|
useDeepCompareEffect(()=>{
|
|
925
|
-
const element = target
|
|
928
|
+
const element = getTargetElement(target);
|
|
926
929
|
if (!element) {
|
|
927
930
|
return;
|
|
928
931
|
}
|
|
@@ -949,7 +952,7 @@ const useElementBounding = (target, options = defaultOptions$1)=>{
|
|
|
949
952
|
const [x, setX] = useState(0);
|
|
950
953
|
const [y, setY] = useState(0);
|
|
951
954
|
const update = useEvent(()=>{
|
|
952
|
-
const element = target
|
|
955
|
+
const element = getTargetElement(target);
|
|
953
956
|
if (!element) {
|
|
954
957
|
if (reset) {
|
|
955
958
|
setHeight(0);
|
|
@@ -1049,7 +1052,7 @@ const useIntersectionObserver = (target, callback, options = defaultOptions$1)=>
|
|
|
1049
1052
|
}
|
|
1050
1053
|
}, []);
|
|
1051
1054
|
useDeepCompareEffect(()=>{
|
|
1052
|
-
const element = target
|
|
1055
|
+
const element = getTargetElement(target);
|
|
1053
1056
|
if (!element) {
|
|
1054
1057
|
return;
|
|
1055
1058
|
}
|
|
@@ -2070,7 +2073,7 @@ const useMousePressed = (target, options = defaultOptions$1)=>{
|
|
|
2070
2073
|
const { touch = true, drag = true, initialValue = false } = options;
|
|
2071
2074
|
const [pressed, setPressed] = useState(initialValue);
|
|
2072
2075
|
const [sourceType, setSourceType] = useState(null);
|
|
2073
|
-
const element = target
|
|
2076
|
+
const element = getTargetElement(target);
|
|
2074
2077
|
const onPressed = useCallback((srcType)=>()=>{
|
|
2075
2078
|
setPressed(true);
|
|
2076
2079
|
setSourceType(srcType);
|