@yogiswara/honcho-editor-ui 3.0.0 → 3.0.2
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 @@
|
|
|
1
|
-
export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): import("react").RefObject<
|
|
1
|
+
export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): import("react").RefObject<HTMLElement>;
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
2
|
export default function useSliderEvents(onDragStart, onDragEnd, isBatchMode) {
|
|
3
|
-
|
|
3
|
+
// Use a generic HTMLElement to work for both <div> and <span>
|
|
4
|
+
const elementRef = useRef(null);
|
|
4
5
|
useEffect(() => {
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
6
|
+
const element = elementRef.current;
|
|
7
|
+
if (!element)
|
|
7
8
|
return;
|
|
8
|
-
// This
|
|
9
|
+
// This handler is attached to the WINDOW to reliably catch the end of the drag.
|
|
9
10
|
const handleDragEnd = () => {
|
|
10
11
|
onDragEnd();
|
|
11
|
-
//
|
|
12
|
+
// Clean up the global listeners immediately after they fire.
|
|
12
13
|
window.removeEventListener('mouseup', handleDragEnd);
|
|
13
14
|
window.removeEventListener('touchend', handleDragEnd);
|
|
14
15
|
};
|
|
15
|
-
// This
|
|
16
|
+
// This handler is attached to the slider THUMB to start the drag.
|
|
16
17
|
const handleDragStart = () => {
|
|
17
18
|
if (!isBatchMode) {
|
|
18
19
|
onDragStart();
|
|
19
20
|
}
|
|
20
|
-
// When
|
|
21
|
+
// When dragging starts, listen on the entire window for the end.
|
|
21
22
|
window.addEventListener('mouseup', handleDragEnd);
|
|
22
23
|
window.addEventListener('touchend', handleDragEnd);
|
|
23
24
|
};
|
|
24
|
-
// Attach
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//
|
|
25
|
+
// Attach "start" listeners to the specific element (the thumb).
|
|
26
|
+
element.addEventListener('mousedown', handleDragStart);
|
|
27
|
+
element.addEventListener('touchstart', handleDragStart, { passive: true });
|
|
28
|
+
// Cleanup function when the component unmounts.
|
|
28
29
|
return () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//
|
|
30
|
+
element.removeEventListener('mousedown', handleDragStart);
|
|
31
|
+
element.removeEventListener('touchstart', handleDragStart);
|
|
32
|
+
// Ensure any lingering window listeners are also removed.
|
|
32
33
|
window.removeEventListener('mouseup', handleDragEnd);
|
|
33
34
|
window.removeEventListener('touchend', handleDragEnd);
|
|
34
35
|
};
|
|
35
36
|
}, [onDragStart, onDragEnd, isBatchMode]);
|
|
36
|
-
return
|
|
37
|
+
return elementRef;
|
|
37
38
|
}
|