@reactuses/core 5.0.3 → 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 +19 -11
- package/dist/index.mjs +19 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -577,15 +577,10 @@ function useStorage(key, defaultValue, getStorage = ()=>isBrowser ? sessionStora
|
|
|
577
577
|
onError(err);
|
|
578
578
|
}
|
|
579
579
|
const type = guessSerializerType(defaultValue);
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
return (_options_serializer = options.serializer) != null ? _options_serializer : StorageSerializers[type];
|
|
583
|
-
}, [
|
|
584
|
-
options.serializer,
|
|
585
|
-
type
|
|
586
|
-
]);
|
|
580
|
+
var _options_serializer;
|
|
581
|
+
const serializer = (_options_serializer = options.serializer) != null ? _options_serializer : StorageSerializers[type];
|
|
587
582
|
const [state, setState] = React.useState(getInitialState$2(key, defaultValue, storage, serializer, onError));
|
|
588
|
-
|
|
583
|
+
useDeepCompareEffect(()=>{
|
|
589
584
|
const data = effectStorageValue ? isFunction(effectStorageValue) ? effectStorageValue() : effectStorageValue : defaultValue;
|
|
590
585
|
const getStoredValue = ()=>{
|
|
591
586
|
try {
|
|
@@ -601,7 +596,6 @@ function useStorage(key, defaultValue, getStorage = ()=>isBrowser ? sessionStora
|
|
|
601
596
|
}
|
|
602
597
|
};
|
|
603
598
|
setState(getStoredValue());
|
|
604
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
605
599
|
}, [
|
|
606
600
|
key,
|
|
607
601
|
serializer,
|
|
@@ -781,6 +775,18 @@ const useDoubleClick = ({ target, latency = 300, onSingleClick = ()=>{}, onDoubl
|
|
|
781
775
|
});
|
|
782
776
|
};
|
|
783
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
|
+
};
|
|
784
790
|
const useDraggable = (target, options = {})=>{
|
|
785
791
|
const { draggingElement, containerElement } = options;
|
|
786
792
|
var _options_handle;
|
|
@@ -850,8 +856,10 @@ const useDraggable = (target, options = {})=>{
|
|
|
850
856
|
x = e.clientX - pressedDelta.x;
|
|
851
857
|
y = e.clientY - pressedDelta.y;
|
|
852
858
|
if (container) {
|
|
853
|
-
|
|
854
|
-
|
|
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);
|
|
855
863
|
}
|
|
856
864
|
setPositon({
|
|
857
865
|
x,
|
package/dist/index.mjs
CHANGED
|
@@ -570,15 +570,10 @@ function useStorage(key, defaultValue, getStorage = ()=>isBrowser ? sessionStora
|
|
|
570
570
|
onError(err);
|
|
571
571
|
}
|
|
572
572
|
const type = guessSerializerType(defaultValue);
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return (_options_serializer = options.serializer) != null ? _options_serializer : StorageSerializers[type];
|
|
576
|
-
}, [
|
|
577
|
-
options.serializer,
|
|
578
|
-
type
|
|
579
|
-
]);
|
|
573
|
+
var _options_serializer;
|
|
574
|
+
const serializer = (_options_serializer = options.serializer) != null ? _options_serializer : StorageSerializers[type];
|
|
580
575
|
const [state, setState] = useState(getInitialState$2(key, defaultValue, storage, serializer, onError));
|
|
581
|
-
|
|
576
|
+
useDeepCompareEffect(()=>{
|
|
582
577
|
const data = effectStorageValue ? isFunction(effectStorageValue) ? effectStorageValue() : effectStorageValue : defaultValue;
|
|
583
578
|
const getStoredValue = ()=>{
|
|
584
579
|
try {
|
|
@@ -594,7 +589,6 @@ function useStorage(key, defaultValue, getStorage = ()=>isBrowser ? sessionStora
|
|
|
594
589
|
}
|
|
595
590
|
};
|
|
596
591
|
setState(getStoredValue());
|
|
597
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
598
592
|
}, [
|
|
599
593
|
key,
|
|
600
594
|
serializer,
|
|
@@ -774,6 +768,18 @@ const useDoubleClick = ({ target, latency = 300, onSingleClick = ()=>{}, onDoubl
|
|
|
774
768
|
});
|
|
775
769
|
};
|
|
776
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
|
+
};
|
|
777
783
|
const useDraggable = (target, options = {})=>{
|
|
778
784
|
const { draggingElement, containerElement } = options;
|
|
779
785
|
var _options_handle;
|
|
@@ -843,8 +849,10 @@ const useDraggable = (target, options = {})=>{
|
|
|
843
849
|
x = e.clientX - pressedDelta.x;
|
|
844
850
|
y = e.clientY - pressedDelta.y;
|
|
845
851
|
if (container) {
|
|
846
|
-
|
|
847
|
-
|
|
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);
|
|
848
856
|
}
|
|
849
857
|
setPositon({
|
|
850
858
|
x,
|