@yogiswara/honcho-editor-ui 2.10.14 → 2.10.15

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
- export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): import("react").RefObject<HTMLSpanElement>;
1
+ import React from "react";
2
+ export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): React.RefObject<HTMLSpanElement>;
@@ -2,34 +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 sliderElement = sliderRef.current;
6
- if (!sliderElement)
5
+ const slider = sliderRef.current;
6
+ if (!slider)
7
7
  return;
8
+ // A single handler for starting the drag
8
9
  const handleStart = () => {
9
- // 1. When a drag STARTS on the slider...
10
10
  if (!isBatchMode) {
11
11
  onDragStart();
12
12
  }
13
- // 2. ...we add listeners to the whole DOCUMENT to catch the END of the drag.
14
- document.addEventListener("mouseup", handleEnd);
15
- document.addEventListener("touchend", handleEnd);
16
13
  };
14
+ // A single handler for ending the drag
17
15
  const handleEnd = () => {
18
- // 3. When the drag ends (anywhere on the page), we call onDragEnd...
19
16
  onDragEnd();
20
- // 4. ...and IMPORTANTLY, we clean up the document listeners.
21
- document.removeEventListener("mouseup", handleEnd);
22
- document.removeEventListener("touchend", handleEnd);
23
17
  };
24
- // Listen for the "start" events on the slider element itself
25
- sliderElement.addEventListener("mousedown", handleStart);
26
- sliderElement.addEventListener("touchstart", handleStart, { passive: true });
27
- // Cleanup function to remove all listeners when the component unmounts
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
28
25
  return () => {
29
- sliderElement.removeEventListener("mousedown", handleStart);
30
- sliderElement.removeEventListener("touchstart", handleStart);
31
- document.removeEventListener("mouseup", handleEnd);
32
- document.removeEventListener("touchend", handleEnd);
26
+ slider.removeEventListener('mousedown', handleStart);
27
+ slider.removeEventListener('touchstart', handleStart);
28
+ slider.removeEventListener('mouseup', handleEnd);
29
+ slider.removeEventListener('touchend', handleEnd);
33
30
  };
34
31
  }, [onDragStart, onDragEnd, isBatchMode]);
35
32
  return sliderRef;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yogiswara/honcho-editor-ui",
3
- "version": "2.10.14",
3
+ "version": "2.10.15",
4
4
  "description": "A complete UI component library for the Honcho photo editor.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",