@yogiswara/honcho-editor-ui 3.1.5 → 3.1.6
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,33 +1,25 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
2
|
export default function useSliderEvents(onDragStart, onDragEnd, isBatchMode) {
|
|
3
|
-
// Use a generic HTMLElement to work for both <div> and <span>
|
|
4
3
|
const elementRef = useRef(null);
|
|
5
4
|
useEffect(() => {
|
|
6
5
|
const element = elementRef.current;
|
|
7
6
|
if (!element)
|
|
8
7
|
return;
|
|
9
|
-
// This handler is attached to the WINDOW for the 'pointerup' event.
|
|
10
8
|
const handleDragEnd = () => {
|
|
11
9
|
onDragEnd();
|
|
12
|
-
// Clean up the global listener immediately after the drag ends.
|
|
13
10
|
window.removeEventListener('pointerup', handleDragEnd);
|
|
14
11
|
};
|
|
15
|
-
// This handler is attached to the slider THUMB for the 'pointerdown' event.
|
|
16
12
|
const handleDragStart = (event) => {
|
|
17
|
-
//
|
|
18
|
-
|
|
13
|
+
// DO NOT call event.preventDefault() here.
|
|
14
|
+
// This allows the MUI Slider to handle its own drag logic.
|
|
19
15
|
if (!isBatchMode) {
|
|
20
16
|
onDragStart();
|
|
21
17
|
}
|
|
22
|
-
// When dragging starts, listen on the entire window for the end.
|
|
23
18
|
window.addEventListener('pointerup', handleDragEnd);
|
|
24
19
|
};
|
|
25
|
-
// Attach a single "start" listener to the specific element (the thumb).
|
|
26
20
|
element.addEventListener('pointerdown', handleDragStart);
|
|
27
|
-
// Cleanup function when the component unmounts
|
|
28
21
|
return () => {
|
|
29
22
|
element.removeEventListener('pointerdown', handleDragStart);
|
|
30
|
-
// Ensure any lingering window listeners are also removed.
|
|
31
23
|
window.removeEventListener('pointerup', handleDragEnd);
|
|
32
24
|
};
|
|
33
25
|
}, [onDragStart, onDragEnd, isBatchMode]);
|