@rpg-engine/long-bow 0.7.51 → 0.7.52

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.7.51",
3
+ "version": "0.7.52",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -142,6 +142,11 @@ export const ItemSlot = React.memo(
142
142
  const [contextActions, setContextActions] = useState<IContextMenuItem[]>(
143
143
  []
144
144
  );
145
+ const [touchStartTime, setTouchStartTime] = useState<number | null>(null);
146
+ const [
147
+ touchStartPosition,
148
+ setTouchStartPosition,
149
+ ] = useState<IPosition | null>(null);
145
150
 
146
151
  useEffect(() => {
147
152
  setDragState(prev => ({
@@ -217,6 +222,34 @@ export const ItemSlot = React.memo(
217
222
 
218
223
  const isTouch = e.type.startsWith('touch');
219
224
 
225
+ if (isTouch) {
226
+ const touchEvent = e as TouchEvent;
227
+ const touch = touchEvent.changedTouches[0];
228
+ const touchEndTime = new Date().getTime();
229
+ const touchDuration = touchStartTime
230
+ ? touchEndTime - touchStartTime
231
+ : 0;
232
+
233
+ // Check if it's a short tap (less than 200ms) and hasn't moved much
234
+ const isShortTap = touchDuration < 200;
235
+ const hasMovedSignificantly =
236
+ touchStartPosition &&
237
+ (Math.abs(touch.clientX - touchStartPosition.x) > 10 ||
238
+ Math.abs(touch.clientY - touchStartPosition.y) > 10);
239
+
240
+ if (isShortTap && !hasMovedSignificantly) {
241
+ // Handle as a tap/click
242
+ if (item) {
243
+ setTooltipState(prev => ({
244
+ ...prev,
245
+ mobileVisible: true,
246
+ }));
247
+ onPointerDown(item.type, containerType ?? null, item);
248
+ }
249
+ return;
250
+ }
251
+ }
252
+
220
253
  // Threshold for considering a tap/click as a drag
221
254
  const dragThreshold = 5; // pixels
222
255
  const isDrag =
@@ -339,6 +372,54 @@ export const ItemSlot = React.memo(
339
372
  }
340
373
  };
341
374
 
375
+ const onTouchStart = (e: React.TouchEvent) => {
376
+ setTouchStartTime(new Date().getTime());
377
+ setTouchStartPosition({
378
+ x: e.touches[0].clientX,
379
+ y: e.touches[0].clientY,
380
+ });
381
+ };
382
+
383
+ const onTouchEnd = (e: React.TouchEvent) => {
384
+ // Prevent default to stop potential unwanted behaviors
385
+ e.preventDefault();
386
+
387
+ const touch = e.changedTouches[0];
388
+ const touchEndTime = new Date().getTime();
389
+ const touchDuration = touchStartTime
390
+ ? touchEndTime - touchStartTime
391
+ : 0;
392
+
393
+ // Check if it's a short tap (less than 200ms) and hasn't moved much
394
+ const isShortTap = touchDuration < 200;
395
+ const hasMovedSignificantly =
396
+ touchStartPosition &&
397
+ (Math.abs(touch.clientX - touchStartPosition.x) > 10 ||
398
+ Math.abs(touch.clientY - touchStartPosition.y) > 10);
399
+
400
+ if (isShortTap && !hasMovedSignificantly) {
401
+ // Handle as a tap/click
402
+ if (item) {
403
+ setTooltipState(prev => ({
404
+ ...prev,
405
+ mobileVisible: true,
406
+ }));
407
+ onPointerDown(item.type, containerType ?? null, item);
408
+ }
409
+ } else {
410
+ // Handle as a drag end
411
+ const simulatedEvent = new MouseEvent('mouseup', {
412
+ clientX: touch.clientX,
413
+ clientY: touch.clientY,
414
+ bubbles: true,
415
+ });
416
+
417
+ document
418
+ .elementFromPoint(touch.clientX, touch.clientY)
419
+ ?.dispatchEvent(simulatedEvent);
420
+ }
421
+ };
422
+
342
423
  const bounds = getContainerBounds();
343
424
  return (
344
425
  <Container
@@ -351,18 +432,6 @@ export const ItemSlot = React.memo(
351
432
  onPlaceDrop(data, slotIndex, containerType);
352
433
  }
353
434
  }}
354
- onTouchEnd={e => {
355
- const { clientX, clientY } = e.changedTouches[0];
356
- const simulatedEvent = new MouseEvent('mouseup', {
357
- clientX,
358
- clientY,
359
- bubbles: true,
360
- });
361
-
362
- document
363
- .elementFromPoint(clientX, clientY)
364
- ?.dispatchEvent(simulatedEvent);
365
- }}
366
435
  onPointerDown={
367
436
  onDragStart !== undefined && onDragEnd !== undefined
368
437
  ? undefined
@@ -377,6 +446,8 @@ export const ItemSlot = React.memo(
377
446
  item?.type === ItemType.Tool ||
378
447
  item?.subType === ItemSubType.Seed)
379
448
  }
449
+ onTouchStart={onTouchStart}
450
+ onTouchEnd={onTouchEnd}
380
451
  >
381
452
  <Draggable
382
453
  axis={isSelectingShortcut ? 'none' : 'both'}