@reactuses/core 5.0.1 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +21 -16
- package/dist/index.d.cts +7 -1
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.mjs +21 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -61,15 +61,11 @@ function getTargetElement(target, defaultElement) {
|
|
|
61
61
|
return targetElement;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const isPrimitive$1 = (val)=>val !== Object(val);
|
|
65
64
|
const useCustomCompareEffect = (effect, deps, depsEqual)=>{
|
|
66
65
|
if (process.env.NODE_ENV !== "production") {
|
|
67
66
|
if (!Array.isArray(deps) || !deps.length) {
|
|
68
67
|
console.warn("`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead.");
|
|
69
68
|
}
|
|
70
|
-
if (deps.every(isPrimitive$1)) {
|
|
71
|
-
console.warn("`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.");
|
|
72
|
-
}
|
|
73
69
|
if (typeof depsEqual !== "function") {
|
|
74
70
|
console.warn("`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list");
|
|
75
71
|
}
|
|
@@ -82,15 +78,11 @@ const useCustomCompareEffect = (effect, deps, depsEqual)=>{
|
|
|
82
78
|
React.useEffect(effect, ref.current);
|
|
83
79
|
};
|
|
84
80
|
|
|
85
|
-
const isPrimitive = (val)=>val !== Object(val);
|
|
86
81
|
const useDeepCompareEffect = (effect, deps)=>{
|
|
87
82
|
if (process.env.NODE_ENV !== "production") {
|
|
88
83
|
if (!Array.isArray(deps) || !deps.length) {
|
|
89
84
|
console.warn("`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead.");
|
|
90
85
|
}
|
|
91
|
-
if (deps.every(isPrimitive)) {
|
|
92
|
-
console.warn("`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.");
|
|
93
|
-
}
|
|
94
86
|
}
|
|
95
87
|
useCustomCompareEffect(effect, deps, lodashEs.isEqual);
|
|
96
88
|
};
|
|
@@ -790,7 +782,7 @@ const useDoubleClick = ({ target, latency = 300, onSingleClick = ()=>{}, onDoubl
|
|
|
790
782
|
};
|
|
791
783
|
|
|
792
784
|
const useDraggable = (target, options = {})=>{
|
|
793
|
-
const draggingElement = options
|
|
785
|
+
const { draggingElement, containerElement } = options;
|
|
794
786
|
var _options_handle;
|
|
795
787
|
const draggingHandle = (_options_handle = options.handle) != null ? _options_handle : target;
|
|
796
788
|
var _options_initialValue;
|
|
@@ -798,7 +790,7 @@ const useDraggable = (target, options = {})=>{
|
|
|
798
790
|
x: 0,
|
|
799
791
|
y: 0
|
|
800
792
|
});
|
|
801
|
-
|
|
793
|
+
useDeepCompareEffect(()=>{
|
|
802
794
|
var _options_initialValue;
|
|
803
795
|
setPositon((_options_initialValue = options.initialValue) != null ? _options_initialValue : {
|
|
804
796
|
x: 0,
|
|
@@ -823,6 +815,7 @@ const useDraggable = (target, options = {})=>{
|
|
|
823
815
|
}
|
|
824
816
|
};
|
|
825
817
|
const start = (e)=>{
|
|
818
|
+
var _container_getBoundingClientRect;
|
|
826
819
|
const element = target.current;
|
|
827
820
|
if (!filterEvent(e) || !element) {
|
|
828
821
|
return;
|
|
@@ -830,10 +823,12 @@ const useDraggable = (target, options = {})=>{
|
|
|
830
823
|
if (options.exact && e.target !== element) {
|
|
831
824
|
return;
|
|
832
825
|
}
|
|
833
|
-
const
|
|
826
|
+
const container = containerElement == null ? void 0 : containerElement.current;
|
|
827
|
+
const containerRect = container == null ? void 0 : (_container_getBoundingClientRect = container.getBoundingClientRect) == null ? void 0 : _container_getBoundingClientRect.call(container);
|
|
828
|
+
const targetRect = element.getBoundingClientRect();
|
|
834
829
|
const pos = {
|
|
835
|
-
x: e.
|
|
836
|
-
y: e.
|
|
830
|
+
x: e.clientX - (container ? targetRect.left - containerRect.left + container.scrollLeft : targetRect.left),
|
|
831
|
+
y: e.clientY - (container ? targetRect.top - containerRect.top + container.scrollTop : targetRect.top)
|
|
837
832
|
};
|
|
838
833
|
if ((options.onStart == null ? void 0 : options.onStart.call(options, pos, e)) === false) {
|
|
839
834
|
return;
|
|
@@ -842,15 +837,25 @@ const useDraggable = (target, options = {})=>{
|
|
|
842
837
|
handleEvent(e);
|
|
843
838
|
};
|
|
844
839
|
const move = (e)=>{
|
|
845
|
-
|
|
840
|
+
const element = target.current;
|
|
841
|
+
if (!filterEvent(e) || !element) {
|
|
846
842
|
return;
|
|
847
843
|
}
|
|
848
844
|
if (!pressedDelta) {
|
|
849
845
|
return;
|
|
850
846
|
}
|
|
847
|
+
const container = containerElement == null ? void 0 : containerElement.current;
|
|
848
|
+
const targetRect = element.getBoundingClientRect();
|
|
849
|
+
let { x, y } = position;
|
|
850
|
+
x = e.clientX - pressedDelta.x;
|
|
851
|
+
y = e.clientY - pressedDelta.y;
|
|
852
|
+
if (container) {
|
|
853
|
+
x = Math.min(Math.max(0, x), container.scrollWidth - targetRect.width);
|
|
854
|
+
y = Math.min(Math.max(0, y), container.scrollHeight - targetRect.height);
|
|
855
|
+
}
|
|
851
856
|
setPositon({
|
|
852
|
-
x
|
|
853
|
-
y
|
|
857
|
+
x,
|
|
858
|
+
y
|
|
854
859
|
});
|
|
855
860
|
options.onMove == null ? void 0 : options.onMove.call(options, position, e);
|
|
856
861
|
handleEvent(e);
|
package/dist/index.d.cts
CHANGED
|
@@ -491,7 +491,13 @@ interface UseDraggableOptions {
|
|
|
491
491
|
* @zh 将“pointermove”和“pointerup”事件附加到的dom元素
|
|
492
492
|
* @defaultValue window
|
|
493
493
|
*/
|
|
494
|
-
draggingElement?:
|
|
494
|
+
draggingElement?: BasicTarget<HTMLElement | SVGElement>;
|
|
495
|
+
/**
|
|
496
|
+
* @en Element for calculating bounds (If not set, it will use the event's target).
|
|
497
|
+
* @zh 设置拖拽容器边界
|
|
498
|
+
* @defaultValue undefined
|
|
499
|
+
*/
|
|
500
|
+
containerElement?: RefObject<HTMLElement | SVGAElement>;
|
|
495
501
|
/**
|
|
496
502
|
* @en Handle that triggers the drag event
|
|
497
503
|
* @zh 触发拖动事件的dom元素
|
package/dist/index.d.mts
CHANGED
|
@@ -491,7 +491,13 @@ interface UseDraggableOptions {
|
|
|
491
491
|
* @zh 将“pointermove”和“pointerup”事件附加到的dom元素
|
|
492
492
|
* @defaultValue window
|
|
493
493
|
*/
|
|
494
|
-
draggingElement?:
|
|
494
|
+
draggingElement?: BasicTarget<HTMLElement | SVGElement>;
|
|
495
|
+
/**
|
|
496
|
+
* @en Element for calculating bounds (If not set, it will use the event's target).
|
|
497
|
+
* @zh 设置拖拽容器边界
|
|
498
|
+
* @defaultValue undefined
|
|
499
|
+
*/
|
|
500
|
+
containerElement?: RefObject<HTMLElement | SVGAElement>;
|
|
495
501
|
/**
|
|
496
502
|
* @en Handle that triggers the drag event
|
|
497
503
|
* @zh 触发拖动事件的dom元素
|
package/dist/index.d.ts
CHANGED
|
@@ -491,7 +491,13 @@ interface UseDraggableOptions {
|
|
|
491
491
|
* @zh 将“pointermove”和“pointerup”事件附加到的dom元素
|
|
492
492
|
* @defaultValue window
|
|
493
493
|
*/
|
|
494
|
-
draggingElement?:
|
|
494
|
+
draggingElement?: BasicTarget<HTMLElement | SVGElement>;
|
|
495
|
+
/**
|
|
496
|
+
* @en Element for calculating bounds (If not set, it will use the event's target).
|
|
497
|
+
* @zh 设置拖拽容器边界
|
|
498
|
+
* @defaultValue undefined
|
|
499
|
+
*/
|
|
500
|
+
containerElement?: RefObject<HTMLElement | SVGAElement>;
|
|
495
501
|
/**
|
|
496
502
|
* @en Handle that triggers the drag event
|
|
497
503
|
* @zh 触发拖动事件的dom元素
|
package/dist/index.mjs
CHANGED
|
@@ -54,15 +54,11 @@ function getTargetElement(target, defaultElement) {
|
|
|
54
54
|
return targetElement;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
const isPrimitive$1 = (val)=>val !== Object(val);
|
|
58
57
|
const useCustomCompareEffect = (effect, deps, depsEqual)=>{
|
|
59
58
|
if (process.env.NODE_ENV !== "production") {
|
|
60
59
|
if (!Array.isArray(deps) || !deps.length) {
|
|
61
60
|
console.warn("`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead.");
|
|
62
61
|
}
|
|
63
|
-
if (deps.every(isPrimitive$1)) {
|
|
64
|
-
console.warn("`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.");
|
|
65
|
-
}
|
|
66
62
|
if (typeof depsEqual !== "function") {
|
|
67
63
|
console.warn("`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list");
|
|
68
64
|
}
|
|
@@ -75,15 +71,11 @@ const useCustomCompareEffect = (effect, deps, depsEqual)=>{
|
|
|
75
71
|
useEffect(effect, ref.current);
|
|
76
72
|
};
|
|
77
73
|
|
|
78
|
-
const isPrimitive = (val)=>val !== Object(val);
|
|
79
74
|
const useDeepCompareEffect = (effect, deps)=>{
|
|
80
75
|
if (process.env.NODE_ENV !== "production") {
|
|
81
76
|
if (!Array.isArray(deps) || !deps.length) {
|
|
82
77
|
console.warn("`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead.");
|
|
83
78
|
}
|
|
84
|
-
if (deps.every(isPrimitive)) {
|
|
85
|
-
console.warn("`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.");
|
|
86
|
-
}
|
|
87
79
|
}
|
|
88
80
|
useCustomCompareEffect(effect, deps, isEqual);
|
|
89
81
|
};
|
|
@@ -783,7 +775,7 @@ const useDoubleClick = ({ target, latency = 300, onSingleClick = ()=>{}, onDoubl
|
|
|
783
775
|
};
|
|
784
776
|
|
|
785
777
|
const useDraggable = (target, options = {})=>{
|
|
786
|
-
const draggingElement = options
|
|
778
|
+
const { draggingElement, containerElement } = options;
|
|
787
779
|
var _options_handle;
|
|
788
780
|
const draggingHandle = (_options_handle = options.handle) != null ? _options_handle : target;
|
|
789
781
|
var _options_initialValue;
|
|
@@ -791,7 +783,7 @@ const useDraggable = (target, options = {})=>{
|
|
|
791
783
|
x: 0,
|
|
792
784
|
y: 0
|
|
793
785
|
});
|
|
794
|
-
|
|
786
|
+
useDeepCompareEffect(()=>{
|
|
795
787
|
var _options_initialValue;
|
|
796
788
|
setPositon((_options_initialValue = options.initialValue) != null ? _options_initialValue : {
|
|
797
789
|
x: 0,
|
|
@@ -816,6 +808,7 @@ const useDraggable = (target, options = {})=>{
|
|
|
816
808
|
}
|
|
817
809
|
};
|
|
818
810
|
const start = (e)=>{
|
|
811
|
+
var _container_getBoundingClientRect;
|
|
819
812
|
const element = target.current;
|
|
820
813
|
if (!filterEvent(e) || !element) {
|
|
821
814
|
return;
|
|
@@ -823,10 +816,12 @@ const useDraggable = (target, options = {})=>{
|
|
|
823
816
|
if (options.exact && e.target !== element) {
|
|
824
817
|
return;
|
|
825
818
|
}
|
|
826
|
-
const
|
|
819
|
+
const container = containerElement == null ? void 0 : containerElement.current;
|
|
820
|
+
const containerRect = container == null ? void 0 : (_container_getBoundingClientRect = container.getBoundingClientRect) == null ? void 0 : _container_getBoundingClientRect.call(container);
|
|
821
|
+
const targetRect = element.getBoundingClientRect();
|
|
827
822
|
const pos = {
|
|
828
|
-
x: e.
|
|
829
|
-
y: e.
|
|
823
|
+
x: e.clientX - (container ? targetRect.left - containerRect.left + container.scrollLeft : targetRect.left),
|
|
824
|
+
y: e.clientY - (container ? targetRect.top - containerRect.top + container.scrollTop : targetRect.top)
|
|
830
825
|
};
|
|
831
826
|
if ((options.onStart == null ? void 0 : options.onStart.call(options, pos, e)) === false) {
|
|
832
827
|
return;
|
|
@@ -835,15 +830,25 @@ const useDraggable = (target, options = {})=>{
|
|
|
835
830
|
handleEvent(e);
|
|
836
831
|
};
|
|
837
832
|
const move = (e)=>{
|
|
838
|
-
|
|
833
|
+
const element = target.current;
|
|
834
|
+
if (!filterEvent(e) || !element) {
|
|
839
835
|
return;
|
|
840
836
|
}
|
|
841
837
|
if (!pressedDelta) {
|
|
842
838
|
return;
|
|
843
839
|
}
|
|
840
|
+
const container = containerElement == null ? void 0 : containerElement.current;
|
|
841
|
+
const targetRect = element.getBoundingClientRect();
|
|
842
|
+
let { x, y } = position;
|
|
843
|
+
x = e.clientX - pressedDelta.x;
|
|
844
|
+
y = e.clientY - pressedDelta.y;
|
|
845
|
+
if (container) {
|
|
846
|
+
x = Math.min(Math.max(0, x), container.scrollWidth - targetRect.width);
|
|
847
|
+
y = Math.min(Math.max(0, y), container.scrollHeight - targetRect.height);
|
|
848
|
+
}
|
|
844
849
|
setPositon({
|
|
845
|
-
x
|
|
846
|
-
y
|
|
850
|
+
x,
|
|
851
|
+
y
|
|
847
852
|
});
|
|
848
853
|
options.onMove == null ? void 0 : options.onMove.call(options, position, e);
|
|
849
854
|
handleEvent(e);
|