@rpg-engine/long-bow 0.7.50 → 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.
@@ -27931,8 +27931,11 @@ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
27931
27931
  contextActions = _useState4[0],
27932
27932
  setContextActions = _useState4[1];
27933
27933
  var _useState5 = useState(null),
27934
- dragStartTime = _useState5[0],
27935
- setDragStartTime = _useState5[1];
27934
+ touchStartTime = _useState5[0],
27935
+ setTouchStartTime = _useState5[1];
27936
+ var _useState6 = useState(null),
27937
+ touchStartPosition = _useState6[0],
27938
+ setTouchStartPosition = _useState6[1];
27936
27939
  useEffect(function () {
27937
27940
  setDragState(function (prev) {
27938
27941
  return _extends({}, prev, {
@@ -28014,8 +28017,31 @@ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
28014
28017
  // remove the class react-draggable-dragging from the element
28015
28018
  // to prevent the item from being dragged again
28016
28019
  target.classList.remove('react-draggable-dragging');
28017
- var dragEndTime = Date.now();
28018
- var dragDuration = dragStartTime ? dragEndTime - dragStartTime : 0;
28020
+ var isTouch = e.type.startsWith('touch');
28021
+ if (isTouch) {
28022
+ var touchEvent = e;
28023
+ var touch = touchEvent.changedTouches[0];
28024
+ var touchEndTime = new Date().getTime();
28025
+ var touchDuration = touchStartTime ? touchEndTime - touchStartTime : 0;
28026
+ // Check if it's a short tap (less than 200ms) and hasn't moved much
28027
+ var isShortTap = touchDuration < 200;
28028
+ var hasMovedSignificantly = touchStartPosition && (Math.abs(touch.clientX - touchStartPosition.x) > 10 || Math.abs(touch.clientY - touchStartPosition.y) > 10);
28029
+ if (isShortTap && !hasMovedSignificantly) {
28030
+ // Handle as a tap/click
28031
+ if (item) {
28032
+ setTooltipState(function (prev) {
28033
+ return _extends({}, prev, {
28034
+ mobileVisible: true
28035
+ });
28036
+ });
28037
+ onPointerDown(item.type, containerType != null ? containerType : null, item);
28038
+ }
28039
+ return;
28040
+ }
28041
+ }
28042
+ // Threshold for considering a tap/click as a drag
28043
+ var dragThreshold = 5; // pixels
28044
+ var isDrag = Math.abs(data.x) > dragThreshold || Math.abs(data.y) > dragThreshold;
28019
28045
  if (dragState.wasDragged && item && !isSelectingShortcut) {
28020
28046
  var _e$target;
28021
28047
  //@ts-ignore
@@ -28071,18 +28097,14 @@ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
28071
28097
  });
28072
28098
  }
28073
28099
  }, 50);
28074
- } else if (item && dragDuration < 200) {
28075
- // Consider it a click if drag duration is less than 200ms
28076
- var isTouch = false;
28077
- if (!isContextMenuDisabled && e.type === 'touchend' && !isSelectingShortcut) {
28078
- isTouch = true;
28100
+ } else if (item) {
28101
+ if (isTouch && !isDrag) {
28079
28102
  setTooltipState(function (prev) {
28080
28103
  return _extends({}, prev, {
28081
28104
  mobileVisible: true
28082
28105
  });
28083
28106
  });
28084
- }
28085
- if (!isContextMenuDisabled && !isSelectingShortcut && !isTouch && !dragState.wasDragged) {
28107
+ } else if (!isTouch && !isContextMenuDisabled && !isSelectingShortcut) {
28086
28108
  setContextMenuState(function (prev) {
28087
28109
  return _extends({}, prev, {
28088
28110
  visible: !contextMenuState.visible
@@ -28100,14 +28122,22 @@ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
28100
28122
  });
28101
28123
  }
28102
28124
  }
28103
- onPointerDown(item.type, containerType != null ? containerType : null, item);
28125
+ if (!isDrag || !isTouch) {
28126
+ console.log('Calling onPointerDown');
28127
+ onPointerDown(item.type, containerType != null ? containerType : null, item);
28128
+ }
28104
28129
  }
28130
+ setDragState(function (prev) {
28131
+ return _extends({}, prev, {
28132
+ wasDragged: false
28133
+ });
28134
+ });
28135
+ console.log('Final dragState:', dragState);
28105
28136
  };
28106
28137
  var onDraggableStart = function onDraggableStart() {
28107
28138
  if (!item || isSelectingShortcut) {
28108
28139
  return;
28109
28140
  }
28110
- setDragStartTime(Date.now());
28111
28141
  if (onDragStart && containerType) {
28112
28142
  onDragStart(item, slotIndex, containerType);
28113
28143
  }
@@ -28125,6 +28155,43 @@ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
28125
28155
  setDraggingItem(item);
28126
28156
  }
28127
28157
  };
28158
+ var onTouchStart = function onTouchStart(e) {
28159
+ setTouchStartTime(new Date().getTime());
28160
+ setTouchStartPosition({
28161
+ x: e.touches[0].clientX,
28162
+ y: e.touches[0].clientY
28163
+ });
28164
+ };
28165
+ var onTouchEnd = function onTouchEnd(e) {
28166
+ // Prevent default to stop potential unwanted behaviors
28167
+ e.preventDefault();
28168
+ var touch = e.changedTouches[0];
28169
+ var touchEndTime = new Date().getTime();
28170
+ var touchDuration = touchStartTime ? touchEndTime - touchStartTime : 0;
28171
+ // Check if it's a short tap (less than 200ms) and hasn't moved much
28172
+ var isShortTap = touchDuration < 200;
28173
+ var hasMovedSignificantly = touchStartPosition && (Math.abs(touch.clientX - touchStartPosition.x) > 10 || Math.abs(touch.clientY - touchStartPosition.y) > 10);
28174
+ if (isShortTap && !hasMovedSignificantly) {
28175
+ // Handle as a tap/click
28176
+ if (item) {
28177
+ setTooltipState(function (prev) {
28178
+ return _extends({}, prev, {
28179
+ mobileVisible: true
28180
+ });
28181
+ });
28182
+ onPointerDown(item.type, containerType != null ? containerType : null, item);
28183
+ }
28184
+ } else {
28185
+ var _document$elementFrom;
28186
+ // Handle as a drag end
28187
+ var simulatedEvent = new MouseEvent('mouseup', {
28188
+ clientX: touch.clientX,
28189
+ clientY: touch.clientY,
28190
+ bubbles: true
28191
+ });
28192
+ (_document$elementFrom = document.elementFromPoint(touch.clientX, touch.clientY)) == null ? void 0 : _document$elementFrom.dispatchEvent(simulatedEvent);
28193
+ }
28194
+ };
28128
28195
  var bounds = getContainerBounds();
28129
28196
  return React.createElement(Container$b, {
28130
28197
  isDraggingItem: !!draggingItem,
@@ -28136,22 +28203,12 @@ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
28136
28203
  onPlaceDrop(data, slotIndex, containerType);
28137
28204
  }
28138
28205
  },
28139
- onTouchEnd: function onTouchEnd(e) {
28140
- var _document$elementFrom;
28141
- var _e$changedTouches$ = e.changedTouches[0],
28142
- clientX = _e$changedTouches$.clientX,
28143
- clientY = _e$changedTouches$.clientY;
28144
- var simulatedEvent = new MouseEvent('mouseup', {
28145
- clientX: clientX,
28146
- clientY: clientY,
28147
- bubbles: true
28148
- });
28149
- (_document$elementFrom = document.elementFromPoint(clientX, clientY)) == null ? void 0 : _document$elementFrom.dispatchEvent(simulatedEvent);
28150
- },
28151
28206
  onPointerDown: onDragStart !== undefined && onDragEnd !== undefined ? undefined : function () {
28152
28207
  if (item) onPointerDown(item.type, containerType != null ? containerType : null, item);
28153
28208
  },
28154
- isSelectingShortcut: isSelectingShortcut && ((item == null ? void 0 : item.type) === ItemType.Consumable || (item == null ? void 0 : item.type) === ItemType.Tool || (item == null ? void 0 : item.subType) === ItemSubType.Seed)
28209
+ isSelectingShortcut: isSelectingShortcut && ((item == null ? void 0 : item.type) === ItemType.Consumable || (item == null ? void 0 : item.type) === ItemType.Tool || (item == null ? void 0 : item.subType) === ItemSubType.Seed),
28210
+ onTouchStart: onTouchStart,
28211
+ onTouchEnd: onTouchEnd
28155
28212
  }, React.createElement(Draggable, {
28156
28213
  axis: isSelectingShortcut ? 'none' : 'both',
28157
28214
  defaultClassName: item ? 'draggable' : 'empty-slot',