@yogiswara/honcho-editor-ui 2.11.4 → 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,2 +1,2 @@
1
1
  import React from "react";
2
- export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): React.RefObject<HTMLSpanElement>;
2
+ export default function useSliderEvents(onDragStart: () => void, onDragEnd: () => void, isBatchMode: boolean): React.RefObject<HTMLDivElement>;
@@ -2,32 +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
- // A single handler for starting the drag
9
- const handleStart = () => {
8
+ const handleMouseDown = () => {
10
9
  if (!isBatchMode) {
11
10
  onDragStart();
12
11
  }
12
+ // Add document listeners when dragging starts
13
+ document.addEventListener("mouseup", handleMouseUp);
14
+ document.addEventListener("touchend", handleTouchEnd);
13
15
  };
14
- // A single handler for ending the drag
15
- const handleEnd = () => {
16
+ const handleTouchStart = () => {
17
+ if (!isBatchMode) {
18
+ onDragStart();
19
+ }
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 = () => {
16
31
  onDragEnd();
32
+ // Remove document listeners when dragging ends
33
+ document.removeEventListener("mouseup", handleMouseUp);
34
+ document.removeEventListener("touchend", handleTouchEnd);
17
35
  };
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
36
+ sliderElement.addEventListener("mousedown", handleMouseDown);
37
+ sliderElement.addEventListener("touchstart", handleTouchStart);
25
38
  return () => {
26
- slider.removeEventListener('mousedown', handleStart);
27
- slider.removeEventListener('touchstart', handleStart);
28
- slider.removeEventListener('mouseup', handleEnd);
29
- slider.removeEventListener('touchend', handleEnd);
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);
30
44
  };
31
45
  }, [onDragStart, onDragEnd, isBatchMode]);
32
- return sliderRef;
46
+ return sliderRef; // Return the ref to be attached to the slider
33
47
  }
@@ -0,0 +1,12 @@
1
+ type SliderChangeHandler = (event: Event, value: number | number[]) => void;
2
+ /**
3
+ * A hook to reliably track the start and end of a slider drag interaction.
4
+ * @param onDragStart - Callback for when dragging begins.
5
+ * @param onDragEnd - Callback for when dragging ends.
6
+ * @returns { handleChange, handleChangeCommitted } - Handlers to be passed to the MUI Slider.
7
+ */
8
+ export declare function useSliderInteraction(onDragStart: () => void, onDragEnd: () => void): {
9
+ handleChange: SliderChangeHandler;
10
+ handleChangeCommitted: SliderChangeHandler;
11
+ };
12
+ export {};
@@ -0,0 +1,29 @@
1
+ import { useRef } from 'react';
2
+ /**
3
+ * A hook to reliably track the start and end of a slider drag interaction.
4
+ * @param onDragStart - Callback for when dragging begins.
5
+ * @param onDragEnd - Callback for when dragging ends.
6
+ * @returns { handleChange, handleChangeCommitted } - Handlers to be passed to the MUI Slider.
7
+ */
8
+ export function useSliderInteraction(onDragStart, onDragEnd) {
9
+ const isDraggingRef = useRef(false);
10
+ // This handler wraps the original `onChange`.
11
+ const handleChange = (event, value) => {
12
+ if (!isDraggingRef.current) {
13
+ // If not already dragging, this is the start.
14
+ isDraggingRef.current = true;
15
+ onDragStart();
16
+ }
17
+ // You would call your original `onChange` logic here if needed.
18
+ // For example: props.setTempScore("tempScore", value as number);
19
+ };
20
+ // This handler wraps the original `onChangeCommitted`.
21
+ const handleChangeCommitted = (event, value) => {
22
+ if (isDraggingRef.current) {
23
+ // If a drag was in progress, this is the end.
24
+ isDraggingRef.current = false;
25
+ onDragEnd();
26
+ }
27
+ };
28
+ return { handleChange, handleChangeCommitted };
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yogiswara/honcho-editor-ui",
3
- "version": "2.11.4",
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",