@yogiswara/honcho-editor-ui 2.10.13 → 2.10.14
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.
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): React.RefObject<HTMLSpanElement>;
|
|
1
|
+
export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): import("react").RefObject<HTMLSpanElement>;
|
|
@@ -2,31 +2,34 @@ import { useEffect, useRef } from "react";
|
|
|
2
2
|
export default function useSliderEvents(onDragStart, onDragEnd, isBatchMode) {
|
|
3
3
|
const sliderRef = useRef(null);
|
|
4
4
|
useEffect(() => {
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
5
|
+
const sliderElement = sliderRef.current;
|
|
6
|
+
if (!sliderElement)
|
|
7
7
|
return;
|
|
8
|
-
// A single handler for starting the drag
|
|
9
8
|
const handleStart = () => {
|
|
9
|
+
// 1. When a drag STARTS on the slider...
|
|
10
10
|
if (!isBatchMode) {
|
|
11
11
|
onDragStart();
|
|
12
12
|
}
|
|
13
|
+
// 2. ...we add listeners to the whole DOCUMENT to catch the END of the drag.
|
|
14
|
+
document.addEventListener("mouseup", handleEnd);
|
|
15
|
+
document.addEventListener("touchend", handleEnd);
|
|
13
16
|
};
|
|
14
|
-
// A single handler for ending the drag
|
|
15
17
|
const handleEnd = () => {
|
|
18
|
+
// 3. When the drag ends (anywhere on the page), we call onDragEnd...
|
|
16
19
|
onDragEnd();
|
|
20
|
+
// 4. ...and IMPORTANTLY, we clean up the document listeners.
|
|
21
|
+
document.removeEventListener("mouseup", handleEnd);
|
|
22
|
+
document.removeEventListener("touchend", handleEnd);
|
|
17
23
|
};
|
|
18
|
-
// Listen for
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
slider.addEventListener('mouseup', handleEnd);
|
|
23
|
-
slider.addEventListener('touchend', handleEnd, { passive: true });
|
|
24
|
-
// Cleanup function to remove all listeners
|
|
24
|
+
// Listen for the "start" events on the slider element itself
|
|
25
|
+
sliderElement.addEventListener("mousedown", handleStart);
|
|
26
|
+
sliderElement.addEventListener("touchstart", handleStart, { passive: true });
|
|
27
|
+
// Cleanup function to remove all listeners when the component unmounts
|
|
25
28
|
return () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
sliderElement.removeEventListener("mousedown", handleStart);
|
|
30
|
+
sliderElement.removeEventListener("touchstart", handleStart);
|
|
31
|
+
document.removeEventListener("mouseup", handleEnd);
|
|
32
|
+
document.removeEventListener("touchend", handleEnd);
|
|
30
33
|
};
|
|
31
34
|
}, [onDragStart, onDragEnd, isBatchMode]);
|
|
32
35
|
return sliderRef;
|