@msobiecki/react-marauders-path 1.17.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 +63 -12
- package/package.json +4 -4
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
|
|
|
@@ -85,8 +86,8 @@ useKey(
|
|
|
85
86
|
import { useWheel } from '@msobiecki/react-marauders-path';
|
|
86
87
|
|
|
87
88
|
function MyComponent() {
|
|
88
|
-
useWheel((event,
|
|
89
|
-
console.log(`Scrolled - X: ${
|
|
89
|
+
useWheel((event, data) => {
|
|
90
|
+
console.log(`Scrolled - X: ${data.deltaX}, Y: ${data.deltaY}`);
|
|
90
91
|
});
|
|
91
92
|
|
|
92
93
|
return <div>Scroll to interact</div>;
|
|
@@ -99,14 +100,28 @@ function MyComponent() {
|
|
|
99
100
|
import { useSwipe } from '@msobiecki/react-marauders-path';
|
|
100
101
|
|
|
101
102
|
function MyComponent() {
|
|
102
|
-
useSwipe('left' (event,
|
|
103
|
-
console.log(`Swiped ${
|
|
103
|
+
useSwipe('left' (event, direction, data) => {
|
|
104
|
+
console.log(`Swiped ${direction} with velocity ${data.velocity}`);
|
|
104
105
|
});
|
|
105
106
|
|
|
106
107
|
return <div>Swipe left</div>;
|
|
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?)`
|
|
@@ -140,7 +155,7 @@ Hook for handling mouse wheel events with support for different delta modes and
|
|
|
140
155
|
|
|
141
156
|
**Parameters:**
|
|
142
157
|
|
|
143
|
-
- `callback: (event: WheelEvent,
|
|
158
|
+
- `callback: (event: WheelEvent, data: WheelData) => void | boolean` - Called when wheel event occurs
|
|
144
159
|
- `options?: UseWheelOptions` - Optional configuration
|
|
145
160
|
|
|
146
161
|
**Options:**
|
|
@@ -160,9 +175,9 @@ interface UseWheelOptions {
|
|
|
160
175
|
|
|
161
176
|
```typescript
|
|
162
177
|
interface WheelData {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
178
|
+
deltaX: number; // Delta X value
|
|
179
|
+
deltaY: number; // Delta Y value
|
|
180
|
+
deltaZ: number; // Delta Z value
|
|
166
181
|
deltaMode: number; // Delta mode value
|
|
167
182
|
}
|
|
168
183
|
```
|
|
@@ -174,7 +189,7 @@ Hook for handling touch swipe gestures with configurable distance and velocity t
|
|
|
174
189
|
**Parameters:**
|
|
175
190
|
|
|
176
191
|
- `swipe: left | right | up | down | horizontal | vertical | both` - Allowed directions to listen
|
|
177
|
-
- `callback: (event:
|
|
192
|
+
- `callback: (event: PointerEvent, direction: SwipeDirection, data: SwipeData) => void | boolean` - Called when a swipe event occurs
|
|
178
193
|
- `options?: UseSwipeOptions` - Optional configuration
|
|
179
194
|
|
|
180
195
|
**Options:**
|
|
@@ -194,7 +209,6 @@ interface UseSwipeOptions {
|
|
|
194
209
|
|
|
195
210
|
```typescript
|
|
196
211
|
interface SwipeData {
|
|
197
|
-
direction: SwipeDirection; // Resolved direction
|
|
198
212
|
deltaX: number; // Horizontal travel
|
|
199
213
|
deltaY: number; // Vertical travel
|
|
200
214
|
velocity: number; // Average speed (distance / duration)
|
|
@@ -202,6 +216,44 @@ interface SwipeData {
|
|
|
202
216
|
}
|
|
203
217
|
```
|
|
204
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
|
+
|
|
205
257
|
## Advanced Examples
|
|
206
258
|
|
|
207
259
|
### Using Options for Event Type and Propagation Control
|
|
@@ -316,7 +368,6 @@ npm lint
|
|
|
316
368
|
- 🚧 **`useTap`** – single tap / click
|
|
317
369
|
- 🚧 **`useDoubleTap`** – quick double tap
|
|
318
370
|
- 🚧 **`usePress`** – press and hold (longPress)
|
|
319
|
-
- 🚧 **`useDrag`** – dragging elements (MouseEvent / PointerEvent / TouchEvent)
|
|
320
371
|
- 🚧 **`usePinch`** – two-finger pinch / zoom
|
|
321
372
|
|
|
322
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,13 +23,13 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@anolilab/multi-semantic-release": "^4.1.1",
|
|
26
|
-
"@commitlint/cli": "^20.4.
|
|
27
|
-
"@commitlint/config-conventional": "^20.4.
|
|
26
|
+
"@commitlint/cli": "^20.4.2",
|
|
27
|
+
"@commitlint/config-conventional": "^20.4.2",
|
|
28
28
|
"@msobiecki/eslint-config": "^9.12.0",
|
|
29
29
|
"@semantic-release/changelog": "^6.0.3",
|
|
30
30
|
"@semantic-release/git": "^10.0.1",
|
|
31
31
|
"@testing-library/react": "^16.3.2",
|
|
32
|
-
"@types/node": "^25.
|
|
32
|
+
"@types/node": "^25.3.0",
|
|
33
33
|
"@types/react": "^19.2.14",
|
|
34
34
|
"@types/react-dom": "^19.2.3",
|
|
35
35
|
"@vitejs/plugin-react-swc": "^4.2.3",
|