@yogiswara/honcho-editor-ui 2.10.10 → 2.10.11
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 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import React from "react";
|
|
2
|
+
export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): React.RefObject<HTMLSpanElement>;
|
|
@@ -2,36 +2,31 @@ 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 slider = sliderRef.current;
|
|
6
|
+
if (!slider)
|
|
7
7
|
return;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
e.stopPropagation();
|
|
8
|
+
// A single handler for starting the drag
|
|
9
|
+
const handleStart = () => {
|
|
11
10
|
if (!isBatchMode) {
|
|
12
11
|
onDragStart();
|
|
13
12
|
}
|
|
14
|
-
// Add "end" listeners to the whole document when a drag starts
|
|
15
|
-
document.addEventListener("mouseup", handleEnd);
|
|
16
|
-
document.addEventListener("touchend", handleEnd);
|
|
17
13
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
e.stopPropagation();
|
|
14
|
+
// A single handler for ending the drag
|
|
15
|
+
const handleEnd = () => {
|
|
21
16
|
onDragEnd();
|
|
22
|
-
// IMPORTANT: Remove the "end" listeners from the document to clean up
|
|
23
|
-
document.removeEventListener("mouseup", handleEnd);
|
|
24
|
-
document.removeEventListener("touchend", handleEnd);
|
|
25
17
|
};
|
|
26
|
-
// Listen for
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
18
|
+
// Listen for BOTH mouse and touch start events
|
|
19
|
+
slider.addEventListener('mousedown', handleStart);
|
|
20
|
+
slider.addEventListener('touchstart', handleStart, { passive: true });
|
|
21
|
+
// Listen for BOTH mouse and touch end events
|
|
22
|
+
slider.addEventListener('mouseup', handleEnd);
|
|
23
|
+
slider.addEventListener('touchend', handleEnd, { passive: true });
|
|
24
|
+
// Cleanup function to remove all listeners
|
|
30
25
|
return () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
slider.removeEventListener('mousedown', handleStart);
|
|
27
|
+
slider.removeEventListener('touchstart', handleStart);
|
|
28
|
+
slider.removeEventListener('mouseup', handleEnd);
|
|
29
|
+
slider.removeEventListener('touchend', handleEnd);
|
|
35
30
|
};
|
|
36
31
|
}, [onDragStart, onDragEnd, isBatchMode]);
|
|
37
32
|
return sliderRef;
|