@yogiswara/honcho-editor-ui 2.10.6 → 2.10.8
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,2 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): React.RefObject<
|
|
2
|
+
export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): React.RefObject<HTMLSpanElement>;
|
|
@@ -1,50 +1,39 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
2
|
export default function useSliderEvents(onDragStart, onDragEnd, isBatchMode) {
|
|
3
3
|
const sliderRef = useRef(null);
|
|
4
|
-
console.log("BATCH MODE CALLED?", isBatchMode);
|
|
5
|
-
console.log("SLIDEREVENT CALLED START!", onDragStart);
|
|
6
|
-
console.log("SLIDEREVENT CALLED END!", onDragEnd);
|
|
7
4
|
useEffect(() => {
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
5
|
+
const slider = sliderRef.current;
|
|
6
|
+
if (!slider)
|
|
10
7
|
return;
|
|
11
|
-
|
|
8
|
+
// A single handler for starting the drag
|
|
9
|
+
const handleStart = () => {
|
|
12
10
|
if (!isBatchMode) {
|
|
13
11
|
onDragStart();
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
document.addEventListener("
|
|
17
|
-
document.addEventListener("touchend", handleTouchEnd);
|
|
13
|
+
document.addEventListener("mouseup", handleEnd);
|
|
14
|
+
document.addEventListener("touchend", handleEnd);
|
|
18
15
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
onDragStart();
|
|
22
|
-
}
|
|
23
|
-
// Add document listeners when dragging starts
|
|
24
|
-
document.addEventListener("mouseup", handleMouseUp);
|
|
25
|
-
document.addEventListener("touchend", handleTouchEnd);
|
|
26
|
-
};
|
|
27
|
-
const handleMouseUp = () => {
|
|
28
|
-
onDragEnd();
|
|
29
|
-
// Remove document listeners when dragging ends
|
|
30
|
-
document.removeEventListener("mouseup", handleMouseUp);
|
|
31
|
-
document.removeEventListener("touchend", handleTouchEnd);
|
|
32
|
-
};
|
|
33
|
-
const handleTouchEnd = () => {
|
|
16
|
+
// A single handler for ending the drag
|
|
17
|
+
const handleEnd = () => {
|
|
34
18
|
onDragEnd();
|
|
35
|
-
|
|
36
|
-
document.removeEventListener("
|
|
37
|
-
document.removeEventListener("touchend", handleTouchEnd);
|
|
19
|
+
document.removeEventListener("mouseup", handleEnd);
|
|
20
|
+
document.removeEventListener("touchend", handleEnd);
|
|
38
21
|
};
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
// Listen for BOTH mouse and touch start events
|
|
23
|
+
slider.addEventListener('mousedown', handleStart);
|
|
24
|
+
slider.addEventListener('touchstart', handleStart, { passive: true });
|
|
25
|
+
// Listen for BOTH mouse and touch end events
|
|
26
|
+
slider.addEventListener('mouseup', handleEnd);
|
|
27
|
+
slider.addEventListener('touchend', handleEnd, { passive: true });
|
|
28
|
+
// Cleanup function to remove all listeners
|
|
41
29
|
return () => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
document.removeEventListener("
|
|
30
|
+
slider.removeEventListener('mousedown', handleStart);
|
|
31
|
+
slider.removeEventListener('touchstart', handleStart);
|
|
32
|
+
slider.removeEventListener('mouseup', handleEnd);
|
|
33
|
+
slider.removeEventListener('touchend', handleEnd);
|
|
34
|
+
document.removeEventListener("mouseup", handleEnd);
|
|
35
|
+
document.removeEventListener("touchend", handleEnd);
|
|
47
36
|
};
|
|
48
37
|
}, [onDragStart, onDragEnd, isBatchMode]);
|
|
49
|
-
return sliderRef;
|
|
38
|
+
return sliderRef;
|
|
50
39
|
}
|