@rpg-engine/long-bow 0.7.80 → 0.7.82
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/dist/hooks/useTouchTarget.d.ts +5 -0
- package/dist/long-bow.cjs.development.js +37 -17
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +38 -18
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Item/Inventory/ItemSlot.tsx +51 -25
- package/src/hooks/useTouchTarget.ts +38 -0
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ import { observer } from 'mobx-react-lite';
|
|
|
13
13
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
14
14
|
import Draggable, { DraggableEventHandler } from 'react-draggable';
|
|
15
15
|
import styled from 'styled-components';
|
|
16
|
+
import useTouchTarget from '../../../hooks/useTouchTarget';
|
|
16
17
|
import { IPosition } from '../../../types/eventTypes';
|
|
17
18
|
import { rarityColor } from './ItemSlotRarity';
|
|
18
19
|
import { ItemSlotRenderer } from './ItemSlotRenderer';
|
|
@@ -151,9 +152,11 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
151
152
|
setContextActions,
|
|
152
153
|
} = useItemSlotDetails();
|
|
153
154
|
|
|
155
|
+
const getTouchTarget = useTouchTarget();
|
|
156
|
+
|
|
154
157
|
const {
|
|
155
158
|
isContextMenuVisible,
|
|
156
|
-
|
|
159
|
+
clearDetailsState,
|
|
157
160
|
clearContextActions,
|
|
158
161
|
} = detailsState;
|
|
159
162
|
|
|
@@ -181,12 +184,26 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
181
184
|
isContextMenuDisabled, // Added missing dependency
|
|
182
185
|
]);
|
|
183
186
|
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
// Reset drag position and focus when item changes
|
|
189
|
+
clearDraggingState();
|
|
190
|
+
|
|
191
|
+
// Clear context actions when component unmounts or dependencies change
|
|
192
|
+
return () => {
|
|
193
|
+
clearContextActions();
|
|
194
|
+
};
|
|
195
|
+
}, [
|
|
196
|
+
containerType,
|
|
197
|
+
isDepotSystem,
|
|
198
|
+
setContextActions,
|
|
199
|
+
clearContextActions,
|
|
200
|
+
isContextMenuDisabled,
|
|
201
|
+
updateDraggingState, // Add this dependency
|
|
202
|
+
]);
|
|
203
|
+
|
|
184
204
|
const resetItem = () => {
|
|
185
205
|
clearDraggingState();
|
|
186
|
-
|
|
187
|
-
item,
|
|
188
|
-
isTooltipVisible: false,
|
|
189
|
-
});
|
|
206
|
+
clearDetailsState();
|
|
190
207
|
};
|
|
191
208
|
|
|
192
209
|
const onSuccessfulDrag = (quantity?: number) => {
|
|
@@ -217,7 +234,12 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
217
234
|
item: null,
|
|
218
235
|
});
|
|
219
236
|
|
|
220
|
-
|
|
237
|
+
let target = e.target as HTMLElement;
|
|
238
|
+
|
|
239
|
+
if (isMobile()) {
|
|
240
|
+
target = getTouchTarget(e as MouseEvent);
|
|
241
|
+
}
|
|
242
|
+
|
|
221
243
|
handleShortcutSetter(target);
|
|
222
244
|
removeDraggingClass(target);
|
|
223
245
|
|
|
@@ -312,27 +334,31 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
312
334
|
return { x: matrix.m41, y: matrix.m42 };
|
|
313
335
|
};
|
|
314
336
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
337
|
+
const processDragEnd = useCallback(
|
|
338
|
+
(item: IItem) => {
|
|
339
|
+
if (checkIfItemCanBeMoved?.()) {
|
|
340
|
+
if (checkIfItemShouldDragEnd && !checkIfItemShouldDragEnd()) {
|
|
341
|
+
resetItem();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) {
|
|
346
|
+
openQuantitySelector(item.stackQty, onSuccessfulDrag);
|
|
347
|
+
} else {
|
|
348
|
+
onSuccessfulDrag(item.stackQty);
|
|
349
|
+
}
|
|
324
350
|
} else {
|
|
325
|
-
|
|
351
|
+
resetItem();
|
|
326
352
|
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
353
|
+
},
|
|
354
|
+
[
|
|
355
|
+
checkIfItemCanBeMoved,
|
|
356
|
+
checkIfItemShouldDragEnd,
|
|
357
|
+
openQuantitySelector,
|
|
358
|
+
onSuccessfulDrag,
|
|
359
|
+
resetItem,
|
|
360
|
+
]
|
|
361
|
+
);
|
|
336
362
|
|
|
337
363
|
/**
|
|
338
364
|
* Handles the context menu or tooltip display after dragging stops without a drop.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
interface IEventWithTarget {
|
|
4
|
+
target: EventTarget | null;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface ITouchEvent extends IEventWithTarget {
|
|
8
|
+
changedTouches?: TouchList;
|
|
9
|
+
|
|
10
|
+
touches?: TouchList;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useTouchTarget() {
|
|
14
|
+
const getTouchTarget = useCallback(
|
|
15
|
+
(e: MouseEvent | TouchEvent | IEventWithTarget): HTMLElement => {
|
|
16
|
+
// Check if it's a touch event
|
|
17
|
+
if ('changedTouches' in e || 'touches' in e) {
|
|
18
|
+
const touchEvent = e as ITouchEvent;
|
|
19
|
+
const touch = touchEvent.changedTouches?.[0] || touchEvent.touches?.[0];
|
|
20
|
+
|
|
21
|
+
if (touch) {
|
|
22
|
+
return document.elementFromPoint(
|
|
23
|
+
touch.clientX,
|
|
24
|
+
touch.clientY
|
|
25
|
+
) as HTMLElement;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// If it's not a touch event or touch is not available, fallback to target
|
|
30
|
+
return (e.target as HTMLElement) || document.body;
|
|
31
|
+
},
|
|
32
|
+
[]
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return getTouchTarget;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default useTouchTarget;
|