@reactuses/core 5.0.5 → 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 +5 -1
- package/dist/index.cjs +17 -13
- package/dist/index.d.cts +84 -77
- package/dist/index.d.mts +84 -77
- package/dist/index.d.ts +84 -77
- package/dist/index.mjs +17 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ Refer to [documentations](https://reactuse.com/) for more details.
|
|
|
58
58
|
|
|
59
59
|
## Feedback
|
|
60
60
|
|
|
61
|
-
You can submit an [issue](https://github.com/childrentime/reactuse/issues) or provide feedback on [Discord](https://discord.gg/
|
|
61
|
+
You can submit an [issue](https://github.com/childrentime/reactuse/issues) or provide feedback on [Discord](https://discord.gg/HMsq6cFkKp).
|
|
62
62
|
|
|
63
63
|
<hr/>
|
|
64
64
|
|
|
@@ -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;
|
|
@@ -885,7 +888,8 @@ const useDraggable = (target, options = {})=>{
|
|
|
885
888
|
return [
|
|
886
889
|
position.x,
|
|
887
890
|
position.y,
|
|
888
|
-
!!pressedDelta
|
|
891
|
+
!!pressedDelta,
|
|
892
|
+
setPositon
|
|
889
893
|
];
|
|
890
894
|
};
|
|
891
895
|
|
|
@@ -928,7 +932,7 @@ const useResizeObserver = (target, callback, options = defaultOptions$1)=>{
|
|
|
928
932
|
}
|
|
929
933
|
}, []);
|
|
930
934
|
useDeepCompareEffect(()=>{
|
|
931
|
-
const element = target
|
|
935
|
+
const element = getTargetElement(target);
|
|
932
936
|
if (!element) {
|
|
933
937
|
return;
|
|
934
938
|
}
|
|
@@ -955,7 +959,7 @@ const useElementBounding = (target, options = defaultOptions$1)=>{
|
|
|
955
959
|
const [x, setX] = React.useState(0);
|
|
956
960
|
const [y, setY] = React.useState(0);
|
|
957
961
|
const update = useEvent(()=>{
|
|
958
|
-
const element = target
|
|
962
|
+
const element = getTargetElement(target);
|
|
959
963
|
if (!element) {
|
|
960
964
|
if (reset) {
|
|
961
965
|
setHeight(0);
|
|
@@ -1055,7 +1059,7 @@ const useIntersectionObserver = (target, callback, options = defaultOptions$1)=>
|
|
|
1055
1059
|
}
|
|
1056
1060
|
}, []);
|
|
1057
1061
|
useDeepCompareEffect(()=>{
|
|
1058
|
-
const element = target
|
|
1062
|
+
const element = getTargetElement(target);
|
|
1059
1063
|
if (!element) {
|
|
1060
1064
|
return;
|
|
1061
1065
|
}
|
|
@@ -2076,7 +2080,7 @@ const useMousePressed = (target, options = defaultOptions$1)=>{
|
|
|
2076
2080
|
const { touch = true, drag = true, initialValue = false } = options;
|
|
2077
2081
|
const [pressed, setPressed] = React.useState(initialValue);
|
|
2078
2082
|
const [sourceType, setSourceType] = React.useState(null);
|
|
2079
|
-
const element = target
|
|
2083
|
+
const element = getTargetElement(target);
|
|
2080
2084
|
const onPressed = React.useCallback((srcType)=>()=>{
|
|
2081
2085
|
setPressed(true);
|
|
2082
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)
|
|
@@ -448,22 +453,24 @@ interface Position {
|
|
|
448
453
|
* - x
|
|
449
454
|
* - y
|
|
450
455
|
* - 元素是否在拖动中
|
|
456
|
+
* - 设置元素的位置
|
|
451
457
|
* @returns_en A tuple with the following elements:
|
|
452
458
|
* - x
|
|
453
459
|
* - y
|
|
454
460
|
* - Whether the element is being dragged
|
|
461
|
+
* set the element position
|
|
455
462
|
*/
|
|
456
463
|
type UseDraggable = (
|
|
457
464
|
/**
|
|
458
465
|
* @zh dom对象
|
|
459
466
|
* @en dom element
|
|
460
467
|
*/
|
|
461
|
-
target:
|
|
468
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
462
469
|
/**
|
|
463
470
|
* @zh 可选参数
|
|
464
471
|
* @en optional params
|
|
465
472
|
*/
|
|
466
|
-
options?: UseDraggableOptions) => readonly [number, number, boolean];
|
|
473
|
+
options?: UseDraggableOptions) => readonly [number, number, boolean, Dispatch<SetStateAction<Position>>];
|
|
467
474
|
/**
|
|
468
475
|
* @title UseDraggableOptions
|
|
469
476
|
*/
|
|
@@ -497,7 +504,7 @@ interface UseDraggableOptions {
|
|
|
497
504
|
* @zh 设置拖拽容器边界
|
|
498
505
|
* @defaultValue undefined
|
|
499
506
|
*/
|
|
500
|
-
containerElement?:
|
|
507
|
+
containerElement?: BasicTarget<HTMLElement | SVGAElement>;
|
|
501
508
|
/**
|
|
502
509
|
* @en Handle that triggers the drag event
|
|
503
510
|
* @zh 触发拖动事件的dom元素
|
|
@@ -545,7 +552,7 @@ type UseDropZone = (
|
|
|
545
552
|
* @zh 目标元素
|
|
546
553
|
* @en target element
|
|
547
554
|
*/
|
|
548
|
-
target:
|
|
555
|
+
target: BasicTarget<EventTarget>,
|
|
549
556
|
/**
|
|
550
557
|
* @zh 拖拽释放时候的回调
|
|
551
558
|
* @en drop callback
|
|
@@ -562,7 +569,7 @@ type UseElementBounding = (
|
|
|
562
569
|
* @zh 目标元素
|
|
563
570
|
* @en target element
|
|
564
571
|
*/
|
|
565
|
-
target:
|
|
572
|
+
target: BasicTarget<Element>,
|
|
566
573
|
/**
|
|
567
574
|
* @zh 可选参数
|
|
568
575
|
* @en optional params
|
|
@@ -664,7 +671,7 @@ type UseElementSize = (
|
|
|
664
671
|
* @zh dom对象
|
|
665
672
|
* @en dom element
|
|
666
673
|
*/
|
|
667
|
-
target:
|
|
674
|
+
target: BasicTarget<Element>,
|
|
668
675
|
/**
|
|
669
676
|
* @zh `resizeObserver` 参数
|
|
670
677
|
* @en options passed to `resizeObserver`
|
|
@@ -687,7 +694,7 @@ type UseElementVisibility = (
|
|
|
687
694
|
* @zh dom对象
|
|
688
695
|
* @en dom element
|
|
689
696
|
*/
|
|
690
|
-
target:
|
|
697
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
691
698
|
/**
|
|
692
699
|
* @zh 传递给 `intersectionObserver` 的选项
|
|
693
700
|
* @en options passed to `intersectionObserver`
|
|
@@ -868,7 +875,7 @@ type UseFocus = (
|
|
|
868
875
|
* @zh dom对象
|
|
869
876
|
* @en dom element
|
|
870
877
|
*/
|
|
871
|
-
target:
|
|
878
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
872
879
|
/**
|
|
873
880
|
* @zh 默认值
|
|
874
881
|
* @en defaultValue
|
|
@@ -920,7 +927,7 @@ type UseFullscreen = (
|
|
|
920
927
|
* @zh dom元素
|
|
921
928
|
* @en dom element
|
|
922
929
|
*/
|
|
923
|
-
target:
|
|
930
|
+
target: BasicTarget<Element>,
|
|
924
931
|
/**
|
|
925
932
|
* @zh 可选参数
|
|
926
933
|
* @en optional params
|
|
@@ -996,7 +1003,17 @@ options?: Partial<PositionOptions>) => {
|
|
|
996
1003
|
|
|
997
1004
|
declare const useGeolocation: UseGeolocation;
|
|
998
1005
|
|
|
999
|
-
|
|
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;
|
|
1000
1017
|
|
|
1001
1018
|
/**
|
|
1002
1019
|
* @title UseIdle
|
|
@@ -1045,7 +1062,7 @@ type UseScroll = (
|
|
|
1045
1062
|
* @zh dom元素
|
|
1046
1063
|
* @en dom elment
|
|
1047
1064
|
*/
|
|
1048
|
-
target:
|
|
1065
|
+
target: BasicTarget<Element> | Window | Document,
|
|
1049
1066
|
/**
|
|
1050
1067
|
* @zh 可选参数
|
|
1051
1068
|
* @en optional params
|
|
@@ -1162,7 +1179,7 @@ type UseInfiniteScroll = (
|
|
|
1162
1179
|
* @zh dom元素
|
|
1163
1180
|
* @en dom element
|
|
1164
1181
|
*/
|
|
1165
|
-
target:
|
|
1182
|
+
target: BasicTarget<Element>,
|
|
1166
1183
|
/**
|
|
1167
1184
|
* @zh 加载更多函数
|
|
1168
1185
|
* @en load more function
|
|
@@ -1264,7 +1281,29 @@ interface UseInfiniteScrollDirection {
|
|
|
1264
1281
|
|
|
1265
1282
|
declare const useInfiniteScroll: UseInfiniteScroll;
|
|
1266
1283
|
|
|
1267
|
-
|
|
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;
|
|
1268
1307
|
|
|
1269
1308
|
/**
|
|
1270
1309
|
* @title useInterval
|
|
@@ -1457,7 +1496,7 @@ type UseMeasure = (
|
|
|
1457
1496
|
* @zh dom对象
|
|
1458
1497
|
* @en dom element
|
|
1459
1498
|
*/
|
|
1460
|
-
target:
|
|
1499
|
+
target: BasicTarget<Element>,
|
|
1461
1500
|
/**
|
|
1462
1501
|
* @zh 可选参数
|
|
1463
1502
|
* @en optional params
|
|
@@ -1594,7 +1633,7 @@ type UseMousePressed = (
|
|
|
1594
1633
|
* @zh dom对象
|
|
1595
1634
|
* @en dom element
|
|
1596
1635
|
*/
|
|
1597
|
-
target?:
|
|
1636
|
+
target?: BasicTarget<Element>,
|
|
1598
1637
|
/**
|
|
1599
1638
|
* @zh 可选参数
|
|
1600
1639
|
* @en optional params
|
|
@@ -1628,7 +1667,7 @@ interface UseMousePressedOptions {
|
|
|
1628
1667
|
*/
|
|
1629
1668
|
type UseMousePressedSourceType = "mouse" | "touch" | null;
|
|
1630
1669
|
|
|
1631
|
-
declare const useMousePressed:
|
|
1670
|
+
declare const useMousePressed: UseMousePressed;
|
|
1632
1671
|
|
|
1633
1672
|
/**
|
|
1634
1673
|
* @title UseMutationObserver
|
|
@@ -1921,7 +1960,27 @@ declare const useRafState: <S>(initialState: S | (() => S)) => readonly [S, Disp
|
|
|
1921
1960
|
|
|
1922
1961
|
declare const useReducedMotion: (defaultState?: boolean) => boolean;
|
|
1923
1962
|
|
|
1924
|
-
|
|
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;
|
|
1925
1984
|
|
|
1926
1985
|
declare const useScreenSafeArea: () => readonly [string, string, string, string, lodash.DebouncedFunc<() => void>];
|
|
1927
1986
|
|
|
@@ -2567,38 +2626,6 @@ baseUrl?: string,
|
|
|
2567
2626
|
*/
|
|
2568
2627
|
rel?: string) => void;
|
|
2569
2628
|
|
|
2570
|
-
/**
|
|
2571
|
-
* @title useHover
|
|
2572
|
-
*/
|
|
2573
|
-
type UseHover = <T extends Element = HTMLDivElement>(
|
|
2574
|
-
/**
|
|
2575
|
-
* @zh dom对象
|
|
2576
|
-
* @en dom element
|
|
2577
|
-
*/
|
|
2578
|
-
target: RefObject<T>) => boolean;
|
|
2579
|
-
|
|
2580
|
-
/**
|
|
2581
|
-
* @title useIntersectionObserver
|
|
2582
|
-
* @returns 停止监听函数
|
|
2583
|
-
* @returns_en stop listening function
|
|
2584
|
-
*/
|
|
2585
|
-
type UseIntersectionObserver = (
|
|
2586
|
-
/**
|
|
2587
|
-
* @zh dom元素
|
|
2588
|
-
* @en dom element
|
|
2589
|
-
*/
|
|
2590
|
-
target: RefObject<Element>,
|
|
2591
|
-
/**
|
|
2592
|
-
* @zh 回调
|
|
2593
|
-
* @en callback
|
|
2594
|
-
*/
|
|
2595
|
-
callback: IntersectionObserverCallback,
|
|
2596
|
-
/**
|
|
2597
|
-
* @zh 传递给 `IntersectionObserver` 的参数
|
|
2598
|
-
* @en options passed to `IntersectionObserver`
|
|
2599
|
-
*/
|
|
2600
|
-
options?: IntersectionObserverInit) => () => void;
|
|
2601
|
-
|
|
2602
2629
|
/**
|
|
2603
2630
|
* @title useLocalStorage
|
|
2604
2631
|
* @returns 包含以下元素的元组:
|
|
@@ -2727,26 +2754,6 @@ type UseReducedMotion = (
|
|
|
2727
2754
|
*/
|
|
2728
2755
|
defaultState?: boolean) => boolean;
|
|
2729
2756
|
|
|
2730
|
-
/**
|
|
2731
|
-
* @title useResizeObserver
|
|
2732
|
-
*/
|
|
2733
|
-
type UseResizeObserver = (
|
|
2734
|
-
/**
|
|
2735
|
-
* @zh dom元素
|
|
2736
|
-
* @en dom element
|
|
2737
|
-
*/
|
|
2738
|
-
target: RefObject<Element>,
|
|
2739
|
-
/**
|
|
2740
|
-
* @zh 回调
|
|
2741
|
-
* @en callback
|
|
2742
|
-
*/
|
|
2743
|
-
callback: ResizeObserverCallback,
|
|
2744
|
-
/**
|
|
2745
|
-
* @zh `resizeObserver` 参数
|
|
2746
|
-
* @en options passed to `resizeObserver`
|
|
2747
|
-
*/
|
|
2748
|
-
options?: ResizeObserverOptions) => () => void;
|
|
2749
|
-
|
|
2750
2757
|
/**
|
|
2751
2758
|
* @title useScreenSafeArea
|
|
2752
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)
|
|
@@ -448,22 +453,24 @@ interface Position {
|
|
|
448
453
|
* - x
|
|
449
454
|
* - y
|
|
450
455
|
* - 元素是否在拖动中
|
|
456
|
+
* - 设置元素的位置
|
|
451
457
|
* @returns_en A tuple with the following elements:
|
|
452
458
|
* - x
|
|
453
459
|
* - y
|
|
454
460
|
* - Whether the element is being dragged
|
|
461
|
+
* set the element position
|
|
455
462
|
*/
|
|
456
463
|
type UseDraggable = (
|
|
457
464
|
/**
|
|
458
465
|
* @zh dom对象
|
|
459
466
|
* @en dom element
|
|
460
467
|
*/
|
|
461
|
-
target:
|
|
468
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
462
469
|
/**
|
|
463
470
|
* @zh 可选参数
|
|
464
471
|
* @en optional params
|
|
465
472
|
*/
|
|
466
|
-
options?: UseDraggableOptions) => readonly [number, number, boolean];
|
|
473
|
+
options?: UseDraggableOptions) => readonly [number, number, boolean, Dispatch<SetStateAction<Position>>];
|
|
467
474
|
/**
|
|
468
475
|
* @title UseDraggableOptions
|
|
469
476
|
*/
|
|
@@ -497,7 +504,7 @@ interface UseDraggableOptions {
|
|
|
497
504
|
* @zh 设置拖拽容器边界
|
|
498
505
|
* @defaultValue undefined
|
|
499
506
|
*/
|
|
500
|
-
containerElement?:
|
|
507
|
+
containerElement?: BasicTarget<HTMLElement | SVGAElement>;
|
|
501
508
|
/**
|
|
502
509
|
* @en Handle that triggers the drag event
|
|
503
510
|
* @zh 触发拖动事件的dom元素
|
|
@@ -545,7 +552,7 @@ type UseDropZone = (
|
|
|
545
552
|
* @zh 目标元素
|
|
546
553
|
* @en target element
|
|
547
554
|
*/
|
|
548
|
-
target:
|
|
555
|
+
target: BasicTarget<EventTarget>,
|
|
549
556
|
/**
|
|
550
557
|
* @zh 拖拽释放时候的回调
|
|
551
558
|
* @en drop callback
|
|
@@ -562,7 +569,7 @@ type UseElementBounding = (
|
|
|
562
569
|
* @zh 目标元素
|
|
563
570
|
* @en target element
|
|
564
571
|
*/
|
|
565
|
-
target:
|
|
572
|
+
target: BasicTarget<Element>,
|
|
566
573
|
/**
|
|
567
574
|
* @zh 可选参数
|
|
568
575
|
* @en optional params
|
|
@@ -664,7 +671,7 @@ type UseElementSize = (
|
|
|
664
671
|
* @zh dom对象
|
|
665
672
|
* @en dom element
|
|
666
673
|
*/
|
|
667
|
-
target:
|
|
674
|
+
target: BasicTarget<Element>,
|
|
668
675
|
/**
|
|
669
676
|
* @zh `resizeObserver` 参数
|
|
670
677
|
* @en options passed to `resizeObserver`
|
|
@@ -687,7 +694,7 @@ type UseElementVisibility = (
|
|
|
687
694
|
* @zh dom对象
|
|
688
695
|
* @en dom element
|
|
689
696
|
*/
|
|
690
|
-
target:
|
|
697
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
691
698
|
/**
|
|
692
699
|
* @zh 传递给 `intersectionObserver` 的选项
|
|
693
700
|
* @en options passed to `intersectionObserver`
|
|
@@ -868,7 +875,7 @@ type UseFocus = (
|
|
|
868
875
|
* @zh dom对象
|
|
869
876
|
* @en dom element
|
|
870
877
|
*/
|
|
871
|
-
target:
|
|
878
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
872
879
|
/**
|
|
873
880
|
* @zh 默认值
|
|
874
881
|
* @en defaultValue
|
|
@@ -920,7 +927,7 @@ type UseFullscreen = (
|
|
|
920
927
|
* @zh dom元素
|
|
921
928
|
* @en dom element
|
|
922
929
|
*/
|
|
923
|
-
target:
|
|
930
|
+
target: BasicTarget<Element>,
|
|
924
931
|
/**
|
|
925
932
|
* @zh 可选参数
|
|
926
933
|
* @en optional params
|
|
@@ -996,7 +1003,17 @@ options?: Partial<PositionOptions>) => {
|
|
|
996
1003
|
|
|
997
1004
|
declare const useGeolocation: UseGeolocation;
|
|
998
1005
|
|
|
999
|
-
|
|
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;
|
|
1000
1017
|
|
|
1001
1018
|
/**
|
|
1002
1019
|
* @title UseIdle
|
|
@@ -1045,7 +1062,7 @@ type UseScroll = (
|
|
|
1045
1062
|
* @zh dom元素
|
|
1046
1063
|
* @en dom elment
|
|
1047
1064
|
*/
|
|
1048
|
-
target:
|
|
1065
|
+
target: BasicTarget<Element> | Window | Document,
|
|
1049
1066
|
/**
|
|
1050
1067
|
* @zh 可选参数
|
|
1051
1068
|
* @en optional params
|
|
@@ -1162,7 +1179,7 @@ type UseInfiniteScroll = (
|
|
|
1162
1179
|
* @zh dom元素
|
|
1163
1180
|
* @en dom element
|
|
1164
1181
|
*/
|
|
1165
|
-
target:
|
|
1182
|
+
target: BasicTarget<Element>,
|
|
1166
1183
|
/**
|
|
1167
1184
|
* @zh 加载更多函数
|
|
1168
1185
|
* @en load more function
|
|
@@ -1264,7 +1281,29 @@ interface UseInfiniteScrollDirection {
|
|
|
1264
1281
|
|
|
1265
1282
|
declare const useInfiniteScroll: UseInfiniteScroll;
|
|
1266
1283
|
|
|
1267
|
-
|
|
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;
|
|
1268
1307
|
|
|
1269
1308
|
/**
|
|
1270
1309
|
* @title useInterval
|
|
@@ -1457,7 +1496,7 @@ type UseMeasure = (
|
|
|
1457
1496
|
* @zh dom对象
|
|
1458
1497
|
* @en dom element
|
|
1459
1498
|
*/
|
|
1460
|
-
target:
|
|
1499
|
+
target: BasicTarget<Element>,
|
|
1461
1500
|
/**
|
|
1462
1501
|
* @zh 可选参数
|
|
1463
1502
|
* @en optional params
|
|
@@ -1594,7 +1633,7 @@ type UseMousePressed = (
|
|
|
1594
1633
|
* @zh dom对象
|
|
1595
1634
|
* @en dom element
|
|
1596
1635
|
*/
|
|
1597
|
-
target?:
|
|
1636
|
+
target?: BasicTarget<Element>,
|
|
1598
1637
|
/**
|
|
1599
1638
|
* @zh 可选参数
|
|
1600
1639
|
* @en optional params
|
|
@@ -1628,7 +1667,7 @@ interface UseMousePressedOptions {
|
|
|
1628
1667
|
*/
|
|
1629
1668
|
type UseMousePressedSourceType = "mouse" | "touch" | null;
|
|
1630
1669
|
|
|
1631
|
-
declare const useMousePressed:
|
|
1670
|
+
declare const useMousePressed: UseMousePressed;
|
|
1632
1671
|
|
|
1633
1672
|
/**
|
|
1634
1673
|
* @title UseMutationObserver
|
|
@@ -1921,7 +1960,27 @@ declare const useRafState: <S>(initialState: S | (() => S)) => readonly [S, Disp
|
|
|
1921
1960
|
|
|
1922
1961
|
declare const useReducedMotion: (defaultState?: boolean) => boolean;
|
|
1923
1962
|
|
|
1924
|
-
|
|
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;
|
|
1925
1984
|
|
|
1926
1985
|
declare const useScreenSafeArea: () => readonly [string, string, string, string, lodash.DebouncedFunc<() => void>];
|
|
1927
1986
|
|
|
@@ -2567,38 +2626,6 @@ baseUrl?: string,
|
|
|
2567
2626
|
*/
|
|
2568
2627
|
rel?: string) => void;
|
|
2569
2628
|
|
|
2570
|
-
/**
|
|
2571
|
-
* @title useHover
|
|
2572
|
-
*/
|
|
2573
|
-
type UseHover = <T extends Element = HTMLDivElement>(
|
|
2574
|
-
/**
|
|
2575
|
-
* @zh dom对象
|
|
2576
|
-
* @en dom element
|
|
2577
|
-
*/
|
|
2578
|
-
target: RefObject<T>) => boolean;
|
|
2579
|
-
|
|
2580
|
-
/**
|
|
2581
|
-
* @title useIntersectionObserver
|
|
2582
|
-
* @returns 停止监听函数
|
|
2583
|
-
* @returns_en stop listening function
|
|
2584
|
-
*/
|
|
2585
|
-
type UseIntersectionObserver = (
|
|
2586
|
-
/**
|
|
2587
|
-
* @zh dom元素
|
|
2588
|
-
* @en dom element
|
|
2589
|
-
*/
|
|
2590
|
-
target: RefObject<Element>,
|
|
2591
|
-
/**
|
|
2592
|
-
* @zh 回调
|
|
2593
|
-
* @en callback
|
|
2594
|
-
*/
|
|
2595
|
-
callback: IntersectionObserverCallback,
|
|
2596
|
-
/**
|
|
2597
|
-
* @zh 传递给 `IntersectionObserver` 的参数
|
|
2598
|
-
* @en options passed to `IntersectionObserver`
|
|
2599
|
-
*/
|
|
2600
|
-
options?: IntersectionObserverInit) => () => void;
|
|
2601
|
-
|
|
2602
2629
|
/**
|
|
2603
2630
|
* @title useLocalStorage
|
|
2604
2631
|
* @returns 包含以下元素的元组:
|
|
@@ -2727,26 +2754,6 @@ type UseReducedMotion = (
|
|
|
2727
2754
|
*/
|
|
2728
2755
|
defaultState?: boolean) => boolean;
|
|
2729
2756
|
|
|
2730
|
-
/**
|
|
2731
|
-
* @title useResizeObserver
|
|
2732
|
-
*/
|
|
2733
|
-
type UseResizeObserver = (
|
|
2734
|
-
/**
|
|
2735
|
-
* @zh dom元素
|
|
2736
|
-
* @en dom element
|
|
2737
|
-
*/
|
|
2738
|
-
target: RefObject<Element>,
|
|
2739
|
-
/**
|
|
2740
|
-
* @zh 回调
|
|
2741
|
-
* @en callback
|
|
2742
|
-
*/
|
|
2743
|
-
callback: ResizeObserverCallback,
|
|
2744
|
-
/**
|
|
2745
|
-
* @zh `resizeObserver` 参数
|
|
2746
|
-
* @en options passed to `resizeObserver`
|
|
2747
|
-
*/
|
|
2748
|
-
options?: ResizeObserverOptions) => () => void;
|
|
2749
|
-
|
|
2750
2757
|
/**
|
|
2751
2758
|
* @title useScreenSafeArea
|
|
2752
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)
|
|
@@ -448,22 +453,24 @@ interface Position {
|
|
|
448
453
|
* - x
|
|
449
454
|
* - y
|
|
450
455
|
* - 元素是否在拖动中
|
|
456
|
+
* - 设置元素的位置
|
|
451
457
|
* @returns_en A tuple with the following elements:
|
|
452
458
|
* - x
|
|
453
459
|
* - y
|
|
454
460
|
* - Whether the element is being dragged
|
|
461
|
+
* set the element position
|
|
455
462
|
*/
|
|
456
463
|
type UseDraggable = (
|
|
457
464
|
/**
|
|
458
465
|
* @zh dom对象
|
|
459
466
|
* @en dom element
|
|
460
467
|
*/
|
|
461
|
-
target:
|
|
468
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
462
469
|
/**
|
|
463
470
|
* @zh 可选参数
|
|
464
471
|
* @en optional params
|
|
465
472
|
*/
|
|
466
|
-
options?: UseDraggableOptions) => readonly [number, number, boolean];
|
|
473
|
+
options?: UseDraggableOptions) => readonly [number, number, boolean, Dispatch<SetStateAction<Position>>];
|
|
467
474
|
/**
|
|
468
475
|
* @title UseDraggableOptions
|
|
469
476
|
*/
|
|
@@ -497,7 +504,7 @@ interface UseDraggableOptions {
|
|
|
497
504
|
* @zh 设置拖拽容器边界
|
|
498
505
|
* @defaultValue undefined
|
|
499
506
|
*/
|
|
500
|
-
containerElement?:
|
|
507
|
+
containerElement?: BasicTarget<HTMLElement | SVGAElement>;
|
|
501
508
|
/**
|
|
502
509
|
* @en Handle that triggers the drag event
|
|
503
510
|
* @zh 触发拖动事件的dom元素
|
|
@@ -545,7 +552,7 @@ type UseDropZone = (
|
|
|
545
552
|
* @zh 目标元素
|
|
546
553
|
* @en target element
|
|
547
554
|
*/
|
|
548
|
-
target:
|
|
555
|
+
target: BasicTarget<EventTarget>,
|
|
549
556
|
/**
|
|
550
557
|
* @zh 拖拽释放时候的回调
|
|
551
558
|
* @en drop callback
|
|
@@ -562,7 +569,7 @@ type UseElementBounding = (
|
|
|
562
569
|
* @zh 目标元素
|
|
563
570
|
* @en target element
|
|
564
571
|
*/
|
|
565
|
-
target:
|
|
572
|
+
target: BasicTarget<Element>,
|
|
566
573
|
/**
|
|
567
574
|
* @zh 可选参数
|
|
568
575
|
* @en optional params
|
|
@@ -664,7 +671,7 @@ type UseElementSize = (
|
|
|
664
671
|
* @zh dom对象
|
|
665
672
|
* @en dom element
|
|
666
673
|
*/
|
|
667
|
-
target:
|
|
674
|
+
target: BasicTarget<Element>,
|
|
668
675
|
/**
|
|
669
676
|
* @zh `resizeObserver` 参数
|
|
670
677
|
* @en options passed to `resizeObserver`
|
|
@@ -687,7 +694,7 @@ type UseElementVisibility = (
|
|
|
687
694
|
* @zh dom对象
|
|
688
695
|
* @en dom element
|
|
689
696
|
*/
|
|
690
|
-
target:
|
|
697
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
691
698
|
/**
|
|
692
699
|
* @zh 传递给 `intersectionObserver` 的选项
|
|
693
700
|
* @en options passed to `intersectionObserver`
|
|
@@ -868,7 +875,7 @@ type UseFocus = (
|
|
|
868
875
|
* @zh dom对象
|
|
869
876
|
* @en dom element
|
|
870
877
|
*/
|
|
871
|
-
target:
|
|
878
|
+
target: BasicTarget<HTMLElement | SVGElement>,
|
|
872
879
|
/**
|
|
873
880
|
* @zh 默认值
|
|
874
881
|
* @en defaultValue
|
|
@@ -920,7 +927,7 @@ type UseFullscreen = (
|
|
|
920
927
|
* @zh dom元素
|
|
921
928
|
* @en dom element
|
|
922
929
|
*/
|
|
923
|
-
target:
|
|
930
|
+
target: BasicTarget<Element>,
|
|
924
931
|
/**
|
|
925
932
|
* @zh 可选参数
|
|
926
933
|
* @en optional params
|
|
@@ -996,7 +1003,17 @@ options?: Partial<PositionOptions>) => {
|
|
|
996
1003
|
|
|
997
1004
|
declare const useGeolocation: UseGeolocation;
|
|
998
1005
|
|
|
999
|
-
|
|
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;
|
|
1000
1017
|
|
|
1001
1018
|
/**
|
|
1002
1019
|
* @title UseIdle
|
|
@@ -1045,7 +1062,7 @@ type UseScroll = (
|
|
|
1045
1062
|
* @zh dom元素
|
|
1046
1063
|
* @en dom elment
|
|
1047
1064
|
*/
|
|
1048
|
-
target:
|
|
1065
|
+
target: BasicTarget<Element> | Window | Document,
|
|
1049
1066
|
/**
|
|
1050
1067
|
* @zh 可选参数
|
|
1051
1068
|
* @en optional params
|
|
@@ -1162,7 +1179,7 @@ type UseInfiniteScroll = (
|
|
|
1162
1179
|
* @zh dom元素
|
|
1163
1180
|
* @en dom element
|
|
1164
1181
|
*/
|
|
1165
|
-
target:
|
|
1182
|
+
target: BasicTarget<Element>,
|
|
1166
1183
|
/**
|
|
1167
1184
|
* @zh 加载更多函数
|
|
1168
1185
|
* @en load more function
|
|
@@ -1264,7 +1281,29 @@ interface UseInfiniteScrollDirection {
|
|
|
1264
1281
|
|
|
1265
1282
|
declare const useInfiniteScroll: UseInfiniteScroll;
|
|
1266
1283
|
|
|
1267
|
-
|
|
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;
|
|
1268
1307
|
|
|
1269
1308
|
/**
|
|
1270
1309
|
* @title useInterval
|
|
@@ -1457,7 +1496,7 @@ type UseMeasure = (
|
|
|
1457
1496
|
* @zh dom对象
|
|
1458
1497
|
* @en dom element
|
|
1459
1498
|
*/
|
|
1460
|
-
target:
|
|
1499
|
+
target: BasicTarget<Element>,
|
|
1461
1500
|
/**
|
|
1462
1501
|
* @zh 可选参数
|
|
1463
1502
|
* @en optional params
|
|
@@ -1594,7 +1633,7 @@ type UseMousePressed = (
|
|
|
1594
1633
|
* @zh dom对象
|
|
1595
1634
|
* @en dom element
|
|
1596
1635
|
*/
|
|
1597
|
-
target?:
|
|
1636
|
+
target?: BasicTarget<Element>,
|
|
1598
1637
|
/**
|
|
1599
1638
|
* @zh 可选参数
|
|
1600
1639
|
* @en optional params
|
|
@@ -1628,7 +1667,7 @@ interface UseMousePressedOptions {
|
|
|
1628
1667
|
*/
|
|
1629
1668
|
type UseMousePressedSourceType = "mouse" | "touch" | null;
|
|
1630
1669
|
|
|
1631
|
-
declare const useMousePressed:
|
|
1670
|
+
declare const useMousePressed: UseMousePressed;
|
|
1632
1671
|
|
|
1633
1672
|
/**
|
|
1634
1673
|
* @title UseMutationObserver
|
|
@@ -1921,7 +1960,27 @@ declare const useRafState: <S>(initialState: S | (() => S)) => readonly [S, Disp
|
|
|
1921
1960
|
|
|
1922
1961
|
declare const useReducedMotion: (defaultState?: boolean) => boolean;
|
|
1923
1962
|
|
|
1924
|
-
|
|
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;
|
|
1925
1984
|
|
|
1926
1985
|
declare const useScreenSafeArea: () => readonly [string, string, string, string, lodash.DebouncedFunc<() => void>];
|
|
1927
1986
|
|
|
@@ -2567,38 +2626,6 @@ baseUrl?: string,
|
|
|
2567
2626
|
*/
|
|
2568
2627
|
rel?: string) => void;
|
|
2569
2628
|
|
|
2570
|
-
/**
|
|
2571
|
-
* @title useHover
|
|
2572
|
-
*/
|
|
2573
|
-
type UseHover = <T extends Element = HTMLDivElement>(
|
|
2574
|
-
/**
|
|
2575
|
-
* @zh dom对象
|
|
2576
|
-
* @en dom element
|
|
2577
|
-
*/
|
|
2578
|
-
target: RefObject<T>) => boolean;
|
|
2579
|
-
|
|
2580
|
-
/**
|
|
2581
|
-
* @title useIntersectionObserver
|
|
2582
|
-
* @returns 停止监听函数
|
|
2583
|
-
* @returns_en stop listening function
|
|
2584
|
-
*/
|
|
2585
|
-
type UseIntersectionObserver = (
|
|
2586
|
-
/**
|
|
2587
|
-
* @zh dom元素
|
|
2588
|
-
* @en dom element
|
|
2589
|
-
*/
|
|
2590
|
-
target: RefObject<Element>,
|
|
2591
|
-
/**
|
|
2592
|
-
* @zh 回调
|
|
2593
|
-
* @en callback
|
|
2594
|
-
*/
|
|
2595
|
-
callback: IntersectionObserverCallback,
|
|
2596
|
-
/**
|
|
2597
|
-
* @zh 传递给 `IntersectionObserver` 的参数
|
|
2598
|
-
* @en options passed to `IntersectionObserver`
|
|
2599
|
-
*/
|
|
2600
|
-
options?: IntersectionObserverInit) => () => void;
|
|
2601
|
-
|
|
2602
2629
|
/**
|
|
2603
2630
|
* @title useLocalStorage
|
|
2604
2631
|
* @returns 包含以下元素的元组:
|
|
@@ -2727,26 +2754,6 @@ type UseReducedMotion = (
|
|
|
2727
2754
|
*/
|
|
2728
2755
|
defaultState?: boolean) => boolean;
|
|
2729
2756
|
|
|
2730
|
-
/**
|
|
2731
|
-
* @title useResizeObserver
|
|
2732
|
-
*/
|
|
2733
|
-
type UseResizeObserver = (
|
|
2734
|
-
/**
|
|
2735
|
-
* @zh dom元素
|
|
2736
|
-
* @en dom element
|
|
2737
|
-
*/
|
|
2738
|
-
target: RefObject<Element>,
|
|
2739
|
-
/**
|
|
2740
|
-
* @zh 回调
|
|
2741
|
-
* @en callback
|
|
2742
|
-
*/
|
|
2743
|
-
callback: ResizeObserverCallback,
|
|
2744
|
-
/**
|
|
2745
|
-
* @zh `resizeObserver` 参数
|
|
2746
|
-
* @en options passed to `resizeObserver`
|
|
2747
|
-
*/
|
|
2748
|
-
options?: ResizeObserverOptions) => () => void;
|
|
2749
|
-
|
|
2750
2757
|
/**
|
|
2751
2758
|
* @title useScreenSafeArea
|
|
2752
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;
|
|
@@ -878,7 +881,8 @@ const useDraggable = (target, options = {})=>{
|
|
|
878
881
|
return [
|
|
879
882
|
position.x,
|
|
880
883
|
position.y,
|
|
881
|
-
!!pressedDelta
|
|
884
|
+
!!pressedDelta,
|
|
885
|
+
setPositon
|
|
882
886
|
];
|
|
883
887
|
};
|
|
884
888
|
|
|
@@ -921,7 +925,7 @@ const useResizeObserver = (target, callback, options = defaultOptions$1)=>{
|
|
|
921
925
|
}
|
|
922
926
|
}, []);
|
|
923
927
|
useDeepCompareEffect(()=>{
|
|
924
|
-
const element = target
|
|
928
|
+
const element = getTargetElement(target);
|
|
925
929
|
if (!element) {
|
|
926
930
|
return;
|
|
927
931
|
}
|
|
@@ -948,7 +952,7 @@ const useElementBounding = (target, options = defaultOptions$1)=>{
|
|
|
948
952
|
const [x, setX] = useState(0);
|
|
949
953
|
const [y, setY] = useState(0);
|
|
950
954
|
const update = useEvent(()=>{
|
|
951
|
-
const element = target
|
|
955
|
+
const element = getTargetElement(target);
|
|
952
956
|
if (!element) {
|
|
953
957
|
if (reset) {
|
|
954
958
|
setHeight(0);
|
|
@@ -1048,7 +1052,7 @@ const useIntersectionObserver = (target, callback, options = defaultOptions$1)=>
|
|
|
1048
1052
|
}
|
|
1049
1053
|
}, []);
|
|
1050
1054
|
useDeepCompareEffect(()=>{
|
|
1051
|
-
const element = target
|
|
1055
|
+
const element = getTargetElement(target);
|
|
1052
1056
|
if (!element) {
|
|
1053
1057
|
return;
|
|
1054
1058
|
}
|
|
@@ -2069,7 +2073,7 @@ const useMousePressed = (target, options = defaultOptions$1)=>{
|
|
|
2069
2073
|
const { touch = true, drag = true, initialValue = false } = options;
|
|
2070
2074
|
const [pressed, setPressed] = useState(initialValue);
|
|
2071
2075
|
const [sourceType, setSourceType] = useState(null);
|
|
2072
|
-
const element = target
|
|
2076
|
+
const element = getTargetElement(target);
|
|
2073
2077
|
const onPressed = useCallback((srcType)=>()=>{
|
|
2074
2078
|
setPressed(true);
|
|
2075
2079
|
setSourceType(srcType);
|