@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(handleDragStartWithLog, handleDragEndWithLog, props.isBatchMode);
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
- 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<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 slider = sliderRef.current;
6
- if (!slider)
5
+ const sliderElement = sliderRef.current;
6
+ if (!sliderElement)
7
7
  return;
8
- // This function will be attached to the WINDOW to listen for the end of a drag.
9
- const handleDragEnd = () => {
10
- onDragEnd();
11
- // IMPORTANT: Clean up the global listeners immediately after the drag ends.
12
- window.removeEventListener('mouseup', handleDragEnd);
13
- window.removeEventListener('touchend', handleDragEnd);
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
- // This function is attached ONLY to the slider thumb to start a drag.
16
- const handleDragStart = () => {
16
+ const handleTouchStart = () => {
17
17
  if (!isBatchMode) {
18
18
  onDragStart();
19
19
  }
20
- // When a drag starts, attach the listeners to the window to catch the end.
21
- window.addEventListener('mouseup', handleDragEnd);
22
- window.addEventListener('touchend', handleDragEnd);
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
- // Attach the "start" listeners to the slider thumb.
25
- slider.addEventListener('mousedown', handleDragStart);
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
- slider.removeEventListener('mousedown', handleDragStart);
30
- slider.removeEventListener('touchstart', handleDragStart);
31
- // Also remove any lingering window listeners, just in case.
32
- window.removeEventListener('mouseup', handleDragEnd);
33
- window.removeEventListener('touchend', handleDragEnd);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yogiswara/honcho-editor-ui",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
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",