@yogiswara/honcho-editor-ui 3.0.0 → 3.0.1
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.
|
@@ -88,7 +88,7 @@ export default function HSliderColorMobile(props) {
|
|
|
88
88
|
console.log('[HSliderColorMobile TEMPERATURE] SLIDER onDragEnd triggered.');
|
|
89
89
|
props.onDragEnd();
|
|
90
90
|
};
|
|
91
|
-
const tempSliderRef = useSliderEvents(
|
|
91
|
+
const tempSliderRef = useSliderEvents(props.onDragStart, props.onDragEnd, props.isBatchMode);
|
|
92
92
|
const tintSliderRef = useSliderEvents(props.onDragStart, props.onDragEnd, props.isBatchMode);
|
|
93
93
|
const vibranceSliderRef = useSliderEvents(props.onDragStart, props.onDragEnd, props.isBatchMode);
|
|
94
94
|
const saturationSliderRef = useSliderEvents(props.onDragStart, props.onDragEnd, props.isBatchMode);
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import React from "react";
|
|
2
|
+
export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): React.RefObject<HTMLDivElement>;
|
|
@@ -2,36 +2,46 @@ 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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const handleMouseDown = () => {
|
|
9
|
+
if (!isBatchMode) {
|
|
10
|
+
onDragStart();
|
|
11
|
+
}
|
|
12
|
+
// Add document listeners when dragging starts
|
|
13
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
14
|
+
document.addEventListener("touchend", handleTouchEnd);
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
-
const handleDragStart = () => {
|
|
16
|
+
const handleTouchStart = () => {
|
|
17
17
|
if (!isBatchMode) {
|
|
18
18
|
onDragStart();
|
|
19
19
|
}
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// Add document listeners when dragging starts
|
|
21
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
22
|
+
document.addEventListener("touchend", handleTouchEnd);
|
|
23
|
+
};
|
|
24
|
+
const handleMouseUp = () => {
|
|
25
|
+
onDragEnd();
|
|
26
|
+
// Remove document listeners when dragging ends
|
|
27
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
28
|
+
document.removeEventListener("touchend", handleTouchEnd);
|
|
29
|
+
};
|
|
30
|
+
const handleTouchEnd = () => {
|
|
31
|
+
onDragEnd();
|
|
32
|
+
// Remove document listeners when dragging ends
|
|
33
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
34
|
+
document.removeEventListener("touchend", handleTouchEnd);
|
|
23
35
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
slider.addEventListener('touchstart', handleDragStart, { passive: true });
|
|
27
|
-
// The main cleanup function for when the component unmounts.
|
|
36
|
+
sliderElement.addEventListener("mousedown", handleMouseDown);
|
|
37
|
+
sliderElement.addEventListener("touchstart", handleTouchStart);
|
|
28
38
|
return () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
sliderElement.removeEventListener("mousedown", handleMouseDown);
|
|
40
|
+
sliderElement.removeEventListener("touchstart", handleTouchStart);
|
|
41
|
+
// Clean up any remaining document listeners
|
|
42
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
43
|
+
document.removeEventListener("touchend", handleTouchEnd);
|
|
34
44
|
};
|
|
35
45
|
}, [onDragStart, onDragEnd, isBatchMode]);
|
|
36
|
-
return sliderRef;
|
|
46
|
+
return sliderRef; // Return the ref to be attached to the slider
|
|
37
47
|
}
|