@yogiswara/honcho-editor-ui 2.10.13 → 2.10.14

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 @@
1
- import React from "react";
2
- export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): React.RefObject<HTMLSpanElement>;
1
+ export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): import("react").RefObject<HTMLSpanElement>;
@@ -2,31 +2,34 @@ 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 slider = sliderRef.current;
6
- if (!slider)
5
+ const sliderElement = sliderRef.current;
6
+ if (!sliderElement)
7
7
  return;
8
- // A single handler for starting the drag
9
8
  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);
13
16
  };
14
- // A single handler for ending the drag
15
17
  const handleEnd = () => {
18
+ // 3. When the drag ends (anywhere on the page), we call onDragEnd...
16
19
  onDragEnd();
20
+ // 4. ...and IMPORTANTLY, we clean up the document listeners.
21
+ document.removeEventListener("mouseup", handleEnd);
22
+ document.removeEventListener("touchend", handleEnd);
17
23
  };
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
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
25
28
  return () => {
26
- slider.removeEventListener('mousedown', handleStart);
27
- slider.removeEventListener('touchstart', handleStart);
28
- slider.removeEventListener('mouseup', handleEnd);
29
- slider.removeEventListener('touchend', handleEnd);
29
+ sliderElement.removeEventListener("mousedown", handleStart);
30
+ sliderElement.removeEventListener("touchstart", handleStart);
31
+ document.removeEventListener("mouseup", handleEnd);
32
+ document.removeEventListener("touchend", handleEnd);
30
33
  };
31
34
  }, [onDragStart, onDragEnd, isBatchMode]);
32
35
  return sliderRef;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yogiswara/honcho-editor-ui",
3
- "version": "2.10.13",
3
+ "version": "2.10.14",
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",