@rpg-engine/long-bow 0.7.81 → 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 +21 -0
- 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 +22 -1
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Item/Inventory/ItemSlot.tsx +9 -1
- 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,6 +152,8 @@ 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,
|
|
@@ -231,7 +234,12 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
231
234
|
item: null,
|
|
232
235
|
});
|
|
233
236
|
|
|
234
|
-
|
|
237
|
+
let target = e.target as HTMLElement;
|
|
238
|
+
|
|
239
|
+
if (isMobile()) {
|
|
240
|
+
target = getTouchTarget(e as MouseEvent);
|
|
241
|
+
}
|
|
242
|
+
|
|
235
243
|
handleShortcutSetter(target);
|
|
236
244
|
removeDraggingClass(target);
|
|
237
245
|
|
|
@@ -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;
|