@msobiecki/react-marauders-path 1.18.0 → 1.19.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.
- package/README.md +54 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/msobiecki/react-marauders-path/blob/master/LICENSE)
|
|
4
4
|
|
|
5
|
-
A lightweight, type-safe React library for handling keyboard, wheel, and
|
|
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
|

|
|
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?)`
|
|
@@ -201,6 +216,44 @@ 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
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Drag Data:**
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
interface DragData {
|
|
245
|
+
deltaX: number; // Horizontal movement from drag start
|
|
246
|
+
deltaY: number; // Vertical movement from drag start
|
|
247
|
+
movementX: number; // Horizontal movement from previous drag event
|
|
248
|
+
movementY: number; // Vertical movement from previous drag event
|
|
249
|
+
duration: number; // Drag duration in ms
|
|
250
|
+
startX: number; // Drag start X
|
|
251
|
+
startY: number; // Drag start Y
|
|
252
|
+
endX: number; // Drag end X
|
|
253
|
+
endY: number; // Drag end Y
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
204
257
|
## Advanced Examples
|
|
205
258
|
|
|
206
259
|
### Using Options for Event Type and Propagation Control
|
|
@@ -315,7 +368,6 @@ npm lint
|
|
|
315
368
|
- 🚧 **`useTap`** – single tap / click
|
|
316
369
|
- 🚧 **`useDoubleTap`** – quick double tap
|
|
317
370
|
- 🚧 **`usePress`** – press and hold (longPress)
|
|
318
|
-
- 🚧 **`useDrag`** – dragging elements (MouseEvent / PointerEvent / TouchEvent)
|
|
319
371
|
- 🚧 **`usePinch`** – two-finger pinch / zoom
|
|
320
372
|
|
|
321
373
|
### Pointer / Mouse Hooks (Unified)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@msobiecki/react-marauders-path",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.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.
|
|
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",
|