@rpg-engine/long-bow 0.7.52 → 0.7.53

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.52",
3
+ "version": "0.7.53",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -147,6 +147,7 @@ export const ItemSlot = React.memo(
147
147
  touchStartPosition,
148
148
  setTouchStartPosition,
149
149
  ] = useState<IPosition | null>(null);
150
+ const [isDragging, setIsDragging] = useState<boolean>(false); // New state to track dragging
150
151
 
151
152
  useEffect(() => {
152
153
  setDragState(prev => ({
@@ -185,8 +186,13 @@ export const ItemSlot = React.memo(
185
186
  }, [dragContainer]);
186
187
 
187
188
  const resetItem = () => {
188
- setTooltipState(prev => ({ ...prev, visible: false }));
189
+ setTooltipState(prev => ({
190
+ ...prev,
191
+ visible: false,
192
+ mobileVisible: false,
193
+ }));
189
194
  setDragState(prev => ({ ...prev, wasDragged: false }));
195
+ setIsDragging(false); // Reset dragging flag
190
196
  };
191
197
 
192
198
  const onSuccessfulDrag = (quantity?: number) => {
@@ -216,7 +222,7 @@ export const ItemSlot = React.memo(
216
222
  }
217
223
  }
218
224
 
219
- // remove the class react-draggable-dragging from the element
225
+ // Remove the class react-draggable-dragging from the element
220
226
  // to prevent the item from being dragged again
221
227
  target.classList.remove('react-draggable-dragging');
222
228
 
@@ -307,16 +313,22 @@ export const ItemSlot = React.memo(
307
313
  }
308
314
  }, 50);
309
315
  } else if (item) {
310
- if (isTouch && !isDrag) {
316
+ if (isTouch && isDragging) {
317
+ // If it's a touch and we were dragging, do not show context menu
318
+ return;
319
+ } else if (isTouch && !isDrag) {
320
+ // Handle as a tap/click
311
321
  setTooltipState(prev => ({
312
322
  ...prev,
313
323
  mobileVisible: true,
314
324
  }));
325
+ onPointerDown(item.type, containerType ?? null, item);
315
326
  } else if (
316
327
  !isTouch &&
317
328
  !isContextMenuDisabled &&
318
329
  !isSelectingShortcut
319
330
  ) {
331
+ // Handle as context menu for mouse devices
320
332
  setContextMenuState(prev => ({
321
333
  ...prev,
322
334
  visible: !contextMenuState.visible,
@@ -335,7 +347,7 @@ export const ItemSlot = React.memo(
335
347
  }
336
348
  }
337
349
 
338
- if (!isDrag || !isTouch) {
350
+ if (!isDrag && !isTouch) {
339
351
  console.log('Calling onPointerDown');
340
352
  onPointerDown(item.type, containerType ?? null, item);
341
353
  }
@@ -353,6 +365,8 @@ export const ItemSlot = React.memo(
353
365
  if (onDragStart && containerType) {
354
366
  onDragStart(item, slotIndex, containerType);
355
367
  }
368
+
369
+ setIsDragging(true); // Set dragging flag on start
356
370
  };
357
371
 
358
372
  const onDraggableProgress: DraggableEventHandler = (_e, data) => {
@@ -372,7 +386,7 @@ export const ItemSlot = React.memo(
372
386
  }
373
387
  };
374
388
 
375
- const onTouchStart = (e: React.TouchEvent) => {
389
+ const onTouchStartHandler = (e: React.TouchEvent) => {
376
390
  setTouchStartTime(new Date().getTime());
377
391
  setTouchStartPosition({
378
392
  x: e.touches[0].clientX,
@@ -380,9 +394,11 @@ export const ItemSlot = React.memo(
380
394
  });
381
395
  };
382
396
 
383
- const onTouchEnd = (e: React.TouchEvent) => {
384
- // Prevent default to stop potential unwanted behaviors
385
- e.preventDefault();
397
+ const onTouchEndHandler = (e: React.TouchEvent) => {
398
+ // Only prevent default if not dragging
399
+ if (!isDragging) {
400
+ e.preventDefault();
401
+ }
386
402
 
387
403
  const touch = e.changedTouches[0];
388
404
  const touchEndTime = new Date().getTime();
@@ -418,6 +434,8 @@ export const ItemSlot = React.memo(
418
434
  .elementFromPoint(touch.clientX, touch.clientY)
419
435
  ?.dispatchEvent(simulatedEvent);
420
436
  }
437
+
438
+ setIsDragging(false); // Reset dragging flag on touch end
421
439
  };
422
440
 
423
441
  const bounds = getContainerBounds();
@@ -446,8 +464,8 @@ export const ItemSlot = React.memo(
446
464
  item?.type === ItemType.Tool ||
447
465
  item?.subType === ItemSubType.Seed)
448
466
  }
449
- onTouchStart={onTouchStart}
450
- onTouchEnd={onTouchEnd}
467
+ onTouchStart={onTouchStartHandler}
468
+ onTouchEnd={onTouchEndHandler}
451
469
  >
452
470
  <Draggable
453
471
  axis={isSelectingShortcut ? 'none' : 'both'}
@@ -577,5 +595,6 @@ const ItemContainer = styled.div<{ isFocused?: boolean }>`
577
595
  height: 64px;
578
596
 
579
597
  position: relative;
580
- ${props => props.isFocused && 'z-index: 100; pointer-events: none;'};
598
+ ${({ isFocused }) =>
599
+ isFocused ? 'z-index: 100; pointer-events: none;' : ''};
581
600
  `;