@rpg-engine/long-bow 0.7.41 → 0.7.42

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.41",
3
+ "version": "0.7.42",
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 [isClicking, setIsClicking] = useState(false);
146
+ const clickTimeoutRef = useRef<NodeJS.Timeout | null>(null);
147
+
148
+ // Add a ref to track touch events
149
+ const isTouchEventRef = useRef(false);
145
150
 
146
151
  useEffect(() => {
147
152
  setDragState(prev => ({
@@ -327,20 +332,59 @@ export const ItemSlot = React.memo(
327
332
  }
328
333
  };
329
334
 
335
+ const handleMouseDown = (_e: React.MouseEvent) => {
336
+ setIsClicking(true);
337
+ clickTimeoutRef.current = setTimeout(() => {
338
+ setIsClicking(false);
339
+ // Allow dragging by setting wasDragged to true
340
+ setDragState(prev => ({
341
+ ...prev,
342
+ wasDragged: true,
343
+ isFocused: true,
344
+ }));
345
+ }, 200); // 200ms threshold for distinguishing click vs. hold
346
+ };
347
+
348
+ const handleMouseUp = (_e: React.MouseEvent) => {
349
+ if (clickTimeoutRef.current) {
350
+ clearTimeout(clickTimeoutRef.current);
351
+ clickTimeoutRef.current = null;
352
+ }
353
+
354
+ if (isClicking && item) {
355
+ // Always open the mobile menu when clicking an item
356
+ setTooltipState(prev => ({ ...prev, mobileVisible: true }));
357
+ setContextMenuState(prev => ({ ...prev, visible: false })); // Ensure desktop menu is closed
358
+ onPointerDown(item.type, containerType ?? null, item);
359
+ setIsClicking(false);
360
+ } else if (onPlaceDrop && containerType) {
361
+ // Handle item placement if not clicking (i.e., after dragging)
362
+ const data = item ? item : null;
363
+ onPlaceDrop(data, slotIndex, containerType);
364
+ }
365
+
366
+ // Reset drag state
367
+ setDragState(prev => ({ ...prev, wasDragged: false }));
368
+ };
369
+
370
+ const handleMouseLeave = () => {
371
+ if (clickTimeoutRef.current) {
372
+ clearTimeout(clickTimeoutRef.current);
373
+ clickTimeoutRef.current = null;
374
+ }
375
+ setIsClicking(false);
376
+ };
377
+
330
378
  const bounds = getContainerBounds();
331
379
  return (
332
380
  <Container
333
381
  isDraggingItem={!!draggingItem}
334
382
  item={item}
335
383
  className="rpgui-icon empty-slot"
336
- onMouseUp={() => {
337
- const data = item ? item : null;
338
- if (onPlaceDrop && containerType) {
339
- onPlaceDrop(data, slotIndex, containerType);
340
- }
341
- }}
342
384
  onTouchEnd={e => {
343
385
  const { clientX, clientY } = e.changedTouches[0];
386
+ // Set the flag to indicate a touch event
387
+ isTouchEventRef.current = true;
344
388
  const simulatedEvent = new MouseEvent('mouseup', {
345
389
  clientX,
346
390
  clientY,
@@ -365,12 +409,17 @@ export const ItemSlot = React.memo(
365
409
  item?.type === ItemType.Tool ||
366
410
  item?.subType === ItemSubType.Seed)
367
411
  }
412
+ onMouseDown={handleMouseDown}
413
+ onMouseUp={handleMouseUp}
414
+ onMouseLeave={handleMouseLeave}
368
415
  >
369
416
  <Draggable
370
417
  axis={isSelectingShortcut ? 'none' : 'both'}
371
418
  defaultClassName={item ? 'draggable' : 'empty-slot'}
372
419
  scale={dragScale}
373
- disabled={onDragStart === undefined || onDragEnd === undefined}
420
+ disabled={
421
+ isClicking || onDragStart === undefined || onDragEnd === undefined
422
+ }
374
423
  onStop={onDraggableStop}
375
424
  onStart={onDraggableStart}
376
425
  onDrag={onDraggableProgress}