@reactuses/core 5.0.4 → 5.0.6
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 +1 -1
- package/dist/index.cjs +18 -3
- package/dist/index.d.cts +4 -2
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +18 -3
- 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
|
|
package/dist/index.cjs
CHANGED
|
@@ -775,6 +775,18 @@ const useDoubleClick = ({ target, latency = 300, onSingleClick = ()=>{}, onDoubl
|
|
|
775
775
|
});
|
|
776
776
|
};
|
|
777
777
|
|
|
778
|
+
const isScrollX = (node)=>{
|
|
779
|
+
if (!node) {
|
|
780
|
+
return false;
|
|
781
|
+
}
|
|
782
|
+
return getComputedStyle(node).overflowX === "auto" || getComputedStyle(node).overflowX === "scroll";
|
|
783
|
+
};
|
|
784
|
+
const isScrollY = (node)=>{
|
|
785
|
+
if (!node) {
|
|
786
|
+
return false;
|
|
787
|
+
}
|
|
788
|
+
return getComputedStyle(node).overflowY === "auto" || getComputedStyle(node).overflowY === "scroll";
|
|
789
|
+
};
|
|
778
790
|
const useDraggable = (target, options = {})=>{
|
|
779
791
|
const { draggingElement, containerElement } = options;
|
|
780
792
|
var _options_handle;
|
|
@@ -844,8 +856,10 @@ const useDraggable = (target, options = {})=>{
|
|
|
844
856
|
x = e.clientX - pressedDelta.x;
|
|
845
857
|
y = e.clientY - pressedDelta.y;
|
|
846
858
|
if (container) {
|
|
847
|
-
|
|
848
|
-
|
|
859
|
+
const containerWidth = isScrollX(container) ? container.scrollWidth : container.clientWidth;
|
|
860
|
+
const containerHeight = isScrollY(container) ? container.scrollHeight : container.clientHeight;
|
|
861
|
+
x = Math.min(Math.max(0, x), containerWidth - targetRect.width);
|
|
862
|
+
y = Math.min(Math.max(0, y), containerHeight - targetRect.height);
|
|
849
863
|
}
|
|
850
864
|
setPositon({
|
|
851
865
|
x,
|
|
@@ -871,7 +885,8 @@ const useDraggable = (target, options = {})=>{
|
|
|
871
885
|
return [
|
|
872
886
|
position.x,
|
|
873
887
|
position.y,
|
|
874
|
-
!!pressedDelta
|
|
888
|
+
!!pressedDelta,
|
|
889
|
+
setPositon
|
|
875
890
|
];
|
|
876
891
|
};
|
|
877
892
|
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import react__default, { DependencyList, RefObject, MutableRefObject, EffectCallback,
|
|
2
|
+
import react__default, { DependencyList, RefObject, MutableRefObject, EffectCallback, Dispatch, SetStateAction, 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';
|
|
@@ -448,10 +448,12 @@ interface Position {
|
|
|
448
448
|
* - x
|
|
449
449
|
* - y
|
|
450
450
|
* - 元素是否在拖动中
|
|
451
|
+
* - 设置元素的位置
|
|
451
452
|
* @returns_en A tuple with the following elements:
|
|
452
453
|
* - x
|
|
453
454
|
* - y
|
|
454
455
|
* - Whether the element is being dragged
|
|
456
|
+
* set the element position
|
|
455
457
|
*/
|
|
456
458
|
type UseDraggable = (
|
|
457
459
|
/**
|
|
@@ -463,7 +465,7 @@ target: RefObject<HTMLElement | SVGElement>,
|
|
|
463
465
|
* @zh 可选参数
|
|
464
466
|
* @en optional params
|
|
465
467
|
*/
|
|
466
|
-
options?: UseDraggableOptions) => readonly [number, number, boolean];
|
|
468
|
+
options?: UseDraggableOptions) => readonly [number, number, boolean, Dispatch<SetStateAction<Position>>];
|
|
467
469
|
/**
|
|
468
470
|
* @title UseDraggableOptions
|
|
469
471
|
*/
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import react__default, { DependencyList, RefObject, MutableRefObject, EffectCallback,
|
|
2
|
+
import react__default, { DependencyList, RefObject, MutableRefObject, EffectCallback, Dispatch, SetStateAction, 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';
|
|
@@ -448,10 +448,12 @@ interface Position {
|
|
|
448
448
|
* - x
|
|
449
449
|
* - y
|
|
450
450
|
* - 元素是否在拖动中
|
|
451
|
+
* - 设置元素的位置
|
|
451
452
|
* @returns_en A tuple with the following elements:
|
|
452
453
|
* - x
|
|
453
454
|
* - y
|
|
454
455
|
* - Whether the element is being dragged
|
|
456
|
+
* set the element position
|
|
455
457
|
*/
|
|
456
458
|
type UseDraggable = (
|
|
457
459
|
/**
|
|
@@ -463,7 +465,7 @@ target: RefObject<HTMLElement | SVGElement>,
|
|
|
463
465
|
* @zh 可选参数
|
|
464
466
|
* @en optional params
|
|
465
467
|
*/
|
|
466
|
-
options?: UseDraggableOptions) => readonly [number, number, boolean];
|
|
468
|
+
options?: UseDraggableOptions) => readonly [number, number, boolean, Dispatch<SetStateAction<Position>>];
|
|
467
469
|
/**
|
|
468
470
|
* @title UseDraggableOptions
|
|
469
471
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import react__default, { DependencyList, RefObject, MutableRefObject, EffectCallback,
|
|
2
|
+
import react__default, { DependencyList, RefObject, MutableRefObject, EffectCallback, Dispatch, SetStateAction, 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';
|
|
@@ -448,10 +448,12 @@ interface Position {
|
|
|
448
448
|
* - x
|
|
449
449
|
* - y
|
|
450
450
|
* - 元素是否在拖动中
|
|
451
|
+
* - 设置元素的位置
|
|
451
452
|
* @returns_en A tuple with the following elements:
|
|
452
453
|
* - x
|
|
453
454
|
* - y
|
|
454
455
|
* - Whether the element is being dragged
|
|
456
|
+
* set the element position
|
|
455
457
|
*/
|
|
456
458
|
type UseDraggable = (
|
|
457
459
|
/**
|
|
@@ -463,7 +465,7 @@ target: RefObject<HTMLElement | SVGElement>,
|
|
|
463
465
|
* @zh 可选参数
|
|
464
466
|
* @en optional params
|
|
465
467
|
*/
|
|
466
|
-
options?: UseDraggableOptions) => readonly [number, number, boolean];
|
|
468
|
+
options?: UseDraggableOptions) => readonly [number, number, boolean, Dispatch<SetStateAction<Position>>];
|
|
467
469
|
/**
|
|
468
470
|
* @title UseDraggableOptions
|
|
469
471
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -768,6 +768,18 @@ const useDoubleClick = ({ target, latency = 300, onSingleClick = ()=>{}, onDoubl
|
|
|
768
768
|
});
|
|
769
769
|
};
|
|
770
770
|
|
|
771
|
+
const isScrollX = (node)=>{
|
|
772
|
+
if (!node) {
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
return getComputedStyle(node).overflowX === "auto" || getComputedStyle(node).overflowX === "scroll";
|
|
776
|
+
};
|
|
777
|
+
const isScrollY = (node)=>{
|
|
778
|
+
if (!node) {
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
return getComputedStyle(node).overflowY === "auto" || getComputedStyle(node).overflowY === "scroll";
|
|
782
|
+
};
|
|
771
783
|
const useDraggable = (target, options = {})=>{
|
|
772
784
|
const { draggingElement, containerElement } = options;
|
|
773
785
|
var _options_handle;
|
|
@@ -837,8 +849,10 @@ const useDraggable = (target, options = {})=>{
|
|
|
837
849
|
x = e.clientX - pressedDelta.x;
|
|
838
850
|
y = e.clientY - pressedDelta.y;
|
|
839
851
|
if (container) {
|
|
840
|
-
|
|
841
|
-
|
|
852
|
+
const containerWidth = isScrollX(container) ? container.scrollWidth : container.clientWidth;
|
|
853
|
+
const containerHeight = isScrollY(container) ? container.scrollHeight : container.clientHeight;
|
|
854
|
+
x = Math.min(Math.max(0, x), containerWidth - targetRect.width);
|
|
855
|
+
y = Math.min(Math.max(0, y), containerHeight - targetRect.height);
|
|
842
856
|
}
|
|
843
857
|
setPositon({
|
|
844
858
|
x,
|
|
@@ -864,7 +878,8 @@ const useDraggable = (target, options = {})=>{
|
|
|
864
878
|
return [
|
|
865
879
|
position.x,
|
|
866
880
|
position.y,
|
|
867
|
-
!!pressedDelta
|
|
881
|
+
!!pressedDelta,
|
|
882
|
+
setPositon
|
|
868
883
|
];
|
|
869
884
|
};
|
|
870
885
|
|