@rpg-engine/long-bow 0.7.80 → 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.
@@ -0,0 +1,5 @@
1
+ interface IEventWithTarget {
2
+ target: EventTarget | null;
3
+ }
4
+ export declare function useTouchTarget(): (e: MouseEvent | TouchEvent | IEventWithTarget) => HTMLElement;
5
+ export default useTouchTarget;
@@ -27377,6 +27377,23 @@ var Container$8 = /*#__PURE__*/styled__default.div.withConfig({
27377
27377
  componentId: "sc-dgmp04-0"
27378
27378
  })(["position:static !important;"]);
27379
27379
 
27380
+ function useTouchTarget() {
27381
+ var getTouchTarget = React.useCallback(function (e) {
27382
+ // Check if it's a touch event
27383
+ if ('changedTouches' in e || 'touches' in e) {
27384
+ var _touchEvent$changedTo, _touchEvent$touches;
27385
+ var touchEvent = e;
27386
+ var touch = ((_touchEvent$changedTo = touchEvent.changedTouches) == null ? void 0 : _touchEvent$changedTo[0]) || ((_touchEvent$touches = touchEvent.touches) == null ? void 0 : _touchEvent$touches[0]);
27387
+ if (touch) {
27388
+ return document.elementFromPoint(touch.clientX, touch.clientY);
27389
+ }
27390
+ }
27391
+ // If it's not a touch event or touch is not available, fallback to target
27392
+ return e.target || document.body;
27393
+ }, []);
27394
+ return getTouchTarget;
27395
+ }
27396
+
27380
27397
  var rarityColor = function rarityColor(item) {
27381
27398
  switch (item == null ? void 0 : item.rarity) {
27382
27399
  case shared.ItemRarities.Uncommon:
@@ -27820,7 +27837,9 @@ var ItemSlot = /*#__PURE__*/mobxReactLite.observer(function (_ref) {
27820
27837
  detailsState = _useItemSlotDetails.detailsState,
27821
27838
  updateDetailsState = _useItemSlotDetails.updateDetailsState,
27822
27839
  setContextActions = _useItemSlotDetails.setContextActions;
27840
+ var getTouchTarget = useTouchTarget();
27823
27841
  var isContextMenuVisible = detailsState.isContextMenuVisible,
27842
+ clearDetailsState = detailsState.clearDetailsState,
27824
27843
  clearContextActions = detailsState.clearContextActions;
27825
27844
  var dragContainer = React.useRef(null);
27826
27845
  var _useItemSlotDragging = useItemSlotDragging(),
@@ -27840,12 +27859,17 @@ var ItemSlot = /*#__PURE__*/mobxReactLite.observer(function (_ref) {
27840
27859
  isFocused: false
27841
27860
  });
27842
27861
  }, [containerType, isDepotSystem, setContextActions, clearContextActions, isContextMenuDisabled]);
27862
+ React.useEffect(function () {
27863
+ // Reset drag position and focus when item changes
27864
+ clearDraggingState();
27865
+ // Clear context actions when component unmounts or dependencies change
27866
+ return function () {
27867
+ clearContextActions();
27868
+ };
27869
+ }, [containerType, isDepotSystem, setContextActions, clearContextActions, isContextMenuDisabled, updateDraggingState]);
27843
27870
  var resetItem = function resetItem() {
27844
27871
  clearDraggingState();
27845
- updateDetailsState({
27846
- item: item,
27847
- isTooltipVisible: false
27848
- });
27872
+ clearDetailsState();
27849
27873
  };
27850
27874
  var onSuccessfulDrag = function onSuccessfulDrag(quantity) {
27851
27875
  resetItem();
@@ -27870,6 +27894,9 @@ var ItemSlot = /*#__PURE__*/mobxReactLite.observer(function (_ref) {
27870
27894
  item: null
27871
27895
  });
27872
27896
  var target = e.target;
27897
+ if (shared.isMobile()) {
27898
+ target = getTouchTarget(e);
27899
+ }
27873
27900
  handleShortcutSetter(target);
27874
27901
  removeDraggingClass(target);
27875
27902
  var shouldHandleDraggedItemResult = shouldHandleDraggedItem();
@@ -27951,12 +27978,12 @@ var ItemSlot = /*#__PURE__*/mobxReactLite.observer(function (_ref) {
27951
27978
  y: matrix.m42
27952
27979
  };
27953
27980
  };
27954
- /**
27955
- * Processes the end of a drag event, handling quantity selection or resetting state.
27956
- */
27957
- var processDragEnd = function processDragEnd(item) {
27981
+ var processDragEnd = React.useCallback(function (item) {
27958
27982
  if (checkIfItemCanBeMoved != null && checkIfItemCanBeMoved()) {
27959
- if (checkIfItemShouldDragEnd && !checkIfItemShouldDragEnd()) return;
27983
+ if (checkIfItemShouldDragEnd && !checkIfItemShouldDragEnd()) {
27984
+ resetItem();
27985
+ return;
27986
+ }
27960
27987
  if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) {
27961
27988
  openQuantitySelector(item.stackQty, onSuccessfulDrag);
27962
27989
  } else {
@@ -27964,15 +27991,8 @@ var ItemSlot = /*#__PURE__*/mobxReactLite.observer(function (_ref) {
27964
27991
  }
27965
27992
  } else {
27966
27993
  resetItem();
27967
- updateDraggingState({
27968
- isFocused: false,
27969
- position: {
27970
- x: 0,
27971
- y: 0
27972
- }
27973
- });
27974
27994
  }
27975
- };
27995
+ }, [checkIfItemCanBeMoved, checkIfItemShouldDragEnd, openQuantitySelector, onSuccessfulDrag, resetItem]);
27976
27996
  /**
27977
27997
  * Handles the context menu or tooltip display after dragging stops without a drop.
27978
27998
  */