@reactuses/core 5.0.4 → 5.0.5

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 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
- x = Math.min(Math.max(0, x), container.scrollWidth - targetRect.width);
848
- y = Math.min(Math.max(0, y), container.scrollHeight - targetRect.height);
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,
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
- x = Math.min(Math.max(0, x), container.scrollWidth - targetRect.width);
841
- y = Math.min(Math.max(0, y), container.scrollHeight - targetRect.height);
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactuses/core",
3
- "version": "5.0.4",
3
+ "version": "5.0.5",
4
4
  "license": "Unlicense",
5
5
  "homepage": "https://www.reactuse.com/",
6
6
  "repository": {