@msobiecki/react-marauders-path 1.18.0 → 1.20.0

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.
Files changed (2) hide show
  1. package/README.md +56 -3
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![License](https://img.shields.io/badge/license-%20%20GNU%20GPLv3%20-green.svg)](https://github.com/msobiecki/react-marauders-path/blob/master/LICENSE)
4
4
 
5
- A lightweight, type-safe React library for handling keyboard, wheel, and swipe events. Perfect for games, interactive applications, and input-driven interfaces.
5
+ A lightweight, type-safe React library for handling keyboard, wheel, swipe, and drag events. Perfect for games, interactive applications, and input-driven interfaces.
6
6
 
7
7
  ![react-marauders-path](./docs/images/logotype.png)
8
8
 
@@ -11,6 +11,7 @@ A lightweight, type-safe React library for handling keyboard, wheel, and swipe e
11
11
  - 🎮 **Keyboard Event Handling** - Simple API for detecting single keys, key combinations, and sequences
12
12
  - 🎡 **Wheel Event Handling** - Mouse wheel scrolling with delta tracking and batching support
13
13
  - 🖐️ **Swipe Gesture Handling** - Touch swipe detection with distance and velocity thresholds
14
+ - 🖱️ **Drag Event Handling** - Pointer drag tracking with movement and delta data
14
15
 
15
16
  ## Installation
16
17
 
@@ -107,6 +108,20 @@ function MyComponent() {
107
108
  }
108
109
  ```
109
110
 
111
+ ### Drag Event Hook
112
+
113
+ ```typescript
114
+ import { useDrag } from '@msobiecki/react-marauders-path';
115
+
116
+ function MyComponent() {
117
+ useDrag((event, data) => {
118
+ console.log(`Dragged by X: ${data.deltaX}, Y: ${data.deltaY}`);
119
+ });
120
+
121
+ return <div>Drag to interact</div>;
122
+ }
123
+ ```
124
+
110
125
  ## API
111
126
 
112
127
  ### `useKey(keyEvent, callback, options?)`
@@ -156,7 +171,7 @@ interface UseWheelOptions {
156
171
  }
157
172
  ```
158
173
 
159
- **Delta Data:**
174
+ **Wheel Data:**
160
175
 
161
176
  ```typescript
162
177
  interface WheelData {
@@ -201,6 +216,45 @@ interface SwipeData {
201
216
  }
202
217
  ```
203
218
 
219
+ ### `useDrag(callback, options?)`
220
+
221
+ Hook for handling pointer drag gestures with configurable threshold and pointer types.
222
+
223
+ **Parameters:**
224
+
225
+ - `callback: (event: PointerEvent, data: DragData) => void | boolean` - Called when drag event occurs
226
+ - `options?: UseDragOptions` - Optional configuration
227
+
228
+ **Options:**
229
+
230
+ ```typescript
231
+ interface UseDragOptions {
232
+ eventPointerTypes?: Array<"touch" | "mouse" | "pen">; // Default: ["touch", "mouse", "pen"]
233
+ eventCapture?: boolean; // Default: false
234
+ eventOnce?: boolean; // Default: false
235
+ eventStopImmediatePropagation?: boolean; // Default: false
236
+ threshold?: number; // Default: 0 (px) - Minimum drag distance
237
+ container?: RefObject<HTMLElement>; // Default: window
238
+ raf?: boolean; // Default: false - Use requestAnimationFrame for batching
239
+ }
240
+ ```
241
+
242
+ **Drag Data:**
243
+
244
+ ```typescript
245
+ interface DragData {
246
+ deltaX: number; // Horizontal movement from drag start
247
+ deltaY: number; // Vertical movement from drag start
248
+ movementX: number; // Horizontal movement from previous drag event
249
+ movementY: number; // Vertical movement from previous drag event
250
+ duration: number; // Drag duration in ms
251
+ startX: number; // Drag start X
252
+ startY: number; // Drag start Y
253
+ endX: number; // Drag end X
254
+ endY: number; // Drag end Y
255
+ }
256
+ ```
257
+
204
258
  ## Advanced Examples
205
259
 
206
260
  ### Using Options for Event Type and Propagation Control
@@ -315,7 +369,6 @@ npm lint
315
369
  - 🚧 **`useTap`** – single tap / click
316
370
  - 🚧 **`useDoubleTap`** – quick double tap
317
371
  - 🚧 **`usePress`** – press and hold (longPress)
318
- - 🚧 **`useDrag`** – dragging elements (MouseEvent / PointerEvent / TouchEvent)
319
372
  - 🚧 **`usePinch`** – two-finger pinch / zoom
320
373
 
321
374
  ### Pointer / Mouse Hooks (Unified)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msobiecki/react-marauders-path",
3
- "version": "1.18.0",
3
+ "version": "1.20.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22.17.1"
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@anolilab/multi-semantic-release": "^4.1.1",
26
- "@commitlint/cli": "^20.4.1",
26
+ "@commitlint/cli": "^20.4.2",
27
27
  "@commitlint/config-conventional": "^20.4.2",
28
28
  "@msobiecki/eslint-config": "^9.12.0",
29
29
  "@semantic-release/changelog": "^6.0.3",