@rpg-engine/long-bow 0.7.68 → 0.7.71

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.
@@ -1,4 +1,4 @@
1
- import React, { useState, useEffect, Component, useRef, useContext, createContext, useCallback, useMemo, Fragment } from 'react';
1
+ import React, { useState, useEffect, Component, useRef, useContext, createContext, useMemo, useCallback, Fragment } from 'react';
2
2
  import styled, { css, keyframes } from 'styled-components';
3
3
  import { BeatLoader } from 'react-spinners';
4
4
  import { v4 } from 'uuid';
@@ -27650,293 +27650,76 @@ var Option = /*#__PURE__*/styled.button.withConfig({
27650
27650
  })(["padding:1rem;background-color:#333;color:white;border:none;border-radius:3px;width:8rem;transition:background-color 0.1s;&:hover{background-color:#555;}@media (max-width:640px){padding:1rem 0.5rem;}"]);
27651
27651
 
27652
27652
  var ItemSlotToolTips = function ItemSlotToolTips(_ref) {
27653
- var tooltipState = _ref.tooltipState,
27654
- setTooltipState = _ref.setTooltipState,
27655
- contextMenuState = _ref.contextMenuState,
27656
- setContextMenuState = _ref.setContextMenuState,
27653
+ var isTooltipVisible = _ref.isTooltipVisible,
27657
27654
  isFocused = _ref.isFocused,
27655
+ isContextMenuVisible = _ref.isContextMenuVisible,
27658
27656
  isContextMenuDisabled = _ref.isContextMenuDisabled,
27659
27657
  item = _ref.item,
27660
27658
  contextActions = _ref.contextActions,
27659
+ contextMenuPosition = _ref.contextMenuPosition,
27661
27660
  dragScale = _ref.dragScale,
27661
+ setIsContextMenuVisible = _ref.setIsContextMenuVisible,
27662
+ setIsTooltipMobileVisible = _ref.setIsTooltipMobileVisible,
27663
+ isTooltipMobileVisible = _ref.isTooltipMobileVisible,
27662
27664
  _onSelected = _ref.onSelected,
27663
27665
  atlasIMG = _ref.atlasIMG,
27664
27666
  atlasJSON = _ref.atlasJSON,
27665
27667
  equipmentSet = _ref.equipmentSet;
27666
- return React.createElement(React.Fragment, null, tooltipState.visible && item && !isFocused && React.createElement(ItemTooltip, {
27668
+ return React.createElement(React.Fragment, null, isTooltipVisible && item && !isFocused && React.createElement(ItemTooltip, {
27667
27669
  item: item,
27668
27670
  atlasIMG: atlasIMG,
27669
27671
  atlasJSON: atlasJSON,
27670
27672
  equipmentSet: equipmentSet
27671
- }), tooltipState.mobileVisible && item && React.createElement(MobileItemTooltip, {
27673
+ }), isTooltipMobileVisible && item && React.createElement(MobileItemTooltip, {
27672
27674
  item: item,
27673
27675
  atlasIMG: atlasIMG,
27674
27676
  atlasJSON: atlasJSON,
27675
27677
  equipmentSet: equipmentSet,
27676
27678
  closeTooltip: function closeTooltip() {
27677
- setTooltipState(function (prev) {
27678
- return _extends({}, prev, {
27679
- mobileVisible: false
27680
- });
27681
- });
27679
+ setIsTooltipMobileVisible(false);
27682
27680
  },
27683
27681
  scale: dragScale,
27684
27682
  options: contextActions,
27685
27683
  onSelected: function onSelected(optionId) {
27686
- setContextMenuState(function (prev) {
27687
- return _extends({}, prev, {
27688
- visible: false
27689
- });
27690
- });
27684
+ setIsContextMenuVisible(false);
27691
27685
  if (item) {
27692
27686
  _onSelected == null ? void 0 : _onSelected(optionId, item);
27693
27687
  }
27694
27688
  }
27695
- }), !isContextMenuDisabled && contextMenuState.visible && contextActions && React.createElement(RelativeListMenu, {
27689
+ }), !isContextMenuDisabled && isContextMenuVisible && contextActions && React.createElement(RelativeListMenu, {
27696
27690
  options: contextActions,
27697
27691
  onSelected: function onSelected(optionId) {
27698
- setContextMenuState(function (prev) {
27699
- return _extends({}, prev, {
27700
- visible: false
27701
- });
27702
- });
27692
+ setIsContextMenuVisible(false);
27703
27693
  if (item) {
27704
27694
  _onSelected == null ? void 0 : _onSelected(optionId, item);
27705
27695
  }
27706
27696
  },
27707
27697
  onOutsideClick: function onOutsideClick() {
27708
- setContextMenuState(function (prev) {
27709
- return _extends({}, prev, {
27710
- visible: false
27711
- });
27712
- });
27698
+ setIsContextMenuVisible(false);
27713
27699
  },
27714
- pos: contextMenuState.position
27700
+ pos: contextMenuPosition
27715
27701
  }));
27716
27702
  };
27717
27703
 
27718
27704
  var DraggingContext = /*#__PURE__*/createContext({
27719
27705
  item: null,
27720
- setDraggingItem: function setDraggingItem() {},
27721
- dragState: {
27722
- isFocused: false,
27723
- wasDragged: false,
27724
- position: {
27725
- x: 0,
27726
- y: 0
27727
- },
27728
- dropPosition: null
27729
- },
27730
- setDragState: function setDragState() {}
27706
+ setDraggingItem: function setDraggingItem() {}
27731
27707
  });
27708
+ var useDragging = function useDragging() {
27709
+ return useContext(DraggingContext);
27710
+ };
27732
27711
  var DraggingProvider = function DraggingProvider(_ref) {
27733
27712
  var children = _ref.children;
27734
27713
  var _useState = useState(null),
27735
27714
  item = _useState[0],
27736
27715
  setDraggingItem = _useState[1];
27737
- var _useState2 = useState({
27738
- isFocused: false,
27739
- wasDragged: false,
27740
- position: {
27741
- x: 0,
27742
- y: 0
27743
- },
27744
- dropPosition: null
27745
- }),
27746
- dragState = _useState2[0],
27747
- setDragState = _useState2[1];
27748
27716
  return React.createElement(DraggingContext.Provider, {
27749
27717
  value: {
27750
27718
  item: item,
27751
- setDraggingItem: setDraggingItem,
27752
- dragState: dragState,
27753
- setDragState: setDragState
27719
+ setDraggingItem: setDraggingItem
27754
27720
  }
27755
27721
  }, children);
27756
27722
  };
27757
- var useDragging = function useDragging() {
27758
- return useContext(DraggingContext);
27759
- };
27760
-
27761
- var useItemSlotDragAndDrop = function useItemSlotDragAndDrop(_ref) {
27762
- var isDepotSystem = _ref.isDepotSystem,
27763
- item = _ref.item,
27764
- onDrop = _ref.onDrop,
27765
- onDragEnd = _ref.onDragEnd,
27766
- checkIfItemCanBeMoved = _ref.checkIfItemCanBeMoved,
27767
- checkIfItemShouldDragEnd = _ref.checkIfItemShouldDragEnd,
27768
- setItemShortcut = _ref.setItemShortcut,
27769
- isSelectingShortcut = _ref.isSelectingShortcut,
27770
- onDragStart = _ref.onDragStart,
27771
- onPointerDown = _ref.onPointerDown,
27772
- containerType = _ref.containerType,
27773
- slotIndex = _ref.slotIndex,
27774
- openQuantitySelector = _ref.openQuantitySelector,
27775
- isContextMenuDisabled = _ref.isContextMenuDisabled,
27776
- setTooltipState = _ref.setTooltipState,
27777
- setContextMenuState = _ref.setContextMenuState;
27778
- var dragContainer = useRef(null);
27779
- var _useDragging = useDragging(),
27780
- draggingItem = _useDragging.item,
27781
- setDraggingItem = _useDragging.setDraggingItem,
27782
- dragState = _useDragging.dragState,
27783
- setDragState = _useDragging.setDragState;
27784
- useEffect(function () {
27785
- setDragState(function (prev) {
27786
- return _extends({}, prev, {
27787
- position: {
27788
- x: 0,
27789
- y: 0
27790
- },
27791
- isFocused: false
27792
- });
27793
- });
27794
- }, [item, isDepotSystem, setDragState]);
27795
- useEffect(function () {
27796
- if (onDrop && item && dragState.dropPosition) {
27797
- onDrop(item, dragState.dropPosition);
27798
- setDragState(function (prev) {
27799
- return _extends({}, prev, {
27800
- dropPosition: null
27801
- });
27802
- });
27803
- }
27804
- }, [dragState.dropPosition, item, onDrop]);
27805
- var getContainerBounds = useCallback(function () {
27806
- var container = dragContainer.current;
27807
- if (!container) return {
27808
- left: 0,
27809
- top: 0,
27810
- right: 0,
27811
- bottom: 0
27812
- };
27813
- var rect = container.getBoundingClientRect();
27814
- return {
27815
- left: rect.left,
27816
- top: rect.top,
27817
- right: window.innerWidth - rect.right,
27818
- bottom: window.innerHeight - rect.bottom
27819
- };
27820
- }, []);
27821
- var resetDragState = useCallback(function () {
27822
- setDragState(function (prev) {
27823
- return _extends({}, prev, {
27824
- wasDragged: false,
27825
- isFocused: false,
27826
- position: {
27827
- x: 0,
27828
- y: 0
27829
- }
27830
- });
27831
- });
27832
- }, [setTooltipState, setDragState]);
27833
- var handleSuccessfulDrag = useCallback(function (quantity) {
27834
- resetDragState();
27835
- if (quantity !== -1 && item) {
27836
- onDragEnd == null ? void 0 : onDragEnd(quantity);
27837
- }
27838
- }, [item, onDragEnd, resetDragState]);
27839
- var onDraggableStart = useCallback(function () {
27840
- if (!item || isSelectingShortcut) return;
27841
- if (onDragStart && containerType) {
27842
- onDragStart(item, slotIndex, containerType);
27843
- }
27844
- }, [item, isSelectingShortcut, onDragStart, containerType, slotIndex]);
27845
- var onDraggableProgress = useCallback(function (_e, data) {
27846
- var _dragState$position = dragState.position,
27847
- x = _dragState$position.x,
27848
- y = _dragState$position.y;
27849
- if (Math.abs(data.x - x) > 5 || Math.abs(data.y - y) > 5) {
27850
- setDragState(function (prev) {
27851
- return _extends({}, prev, {
27852
- wasDragged: true,
27853
- isFocused: true
27854
- });
27855
- });
27856
- }
27857
- if (!draggingItem) {
27858
- setDraggingItem(item);
27859
- }
27860
- }, [dragState.position, draggingItem, item, setDraggingItem, setDragState]);
27861
- var onDraggableStop = useCallback(function (e, data) {
27862
- setTimeout(function () {
27863
- setDraggingItem(null);
27864
- }, 50);
27865
- var target = e.target;
27866
- if (!target) return;
27867
- target.classList.remove('react-draggable-dragging');
27868
- if (target != null && target.id.includes('shortcutSetter') && setItemShortcut && item) {
27869
- var index = parseInt(target.id.split('_')[1]);
27870
- if (!isNaN(index)) {
27871
- setItemShortcut(item, index);
27872
- }
27873
- }
27874
- if (dragState.wasDragged && item && !isSelectingShortcut) {
27875
- var classes = Array.from(target.classList);
27876
- var isOutsideDrop = classes.some(function (elm) {
27877
- return elm.includes('rpgui-content');
27878
- }) || classes.length === 0;
27879
- if (isOutsideDrop) {
27880
- setDragState(function (prev) {
27881
- return _extends({}, prev, {
27882
- dropPosition: {
27883
- x: data.x,
27884
- y: data.y
27885
- }
27886
- });
27887
- });
27888
- }
27889
- setDragState(function (prev) {
27890
- return _extends({}, prev, {
27891
- wasDragged: false
27892
- });
27893
- });
27894
- setTimeout(function () {
27895
- if (checkIfItemCanBeMoved != null && checkIfItemCanBeMoved() && (!checkIfItemShouldDragEnd || checkIfItemShouldDragEnd())) {
27896
- if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) {
27897
- openQuantitySelector(item.stackQty, handleSuccessfulDrag);
27898
- } else {
27899
- handleSuccessfulDrag(item.stackQty);
27900
- }
27901
- } else {
27902
- resetDragState();
27903
- }
27904
- }, 50);
27905
- } else if (item) {
27906
- var isTouch = e.type === 'touchend';
27907
- if (!isContextMenuDisabled && isTouch && !isSelectingShortcut && !draggingItem) {
27908
- setTooltipState(function (prev) {
27909
- return _extends({}, prev, {
27910
- mobileVisible: true
27911
- });
27912
- });
27913
- } else if (!isContextMenuDisabled && !isSelectingShortcut && !isTouch) {
27914
- var event = e;
27915
- setContextMenuState(function (prev) {
27916
- return {
27917
- visible: !prev.visible,
27918
- position: {
27919
- x: event.clientX - 10,
27920
- y: event.clientY - 5
27921
- }
27922
- };
27923
- });
27924
- }
27925
- onPointerDown == null ? void 0 : onPointerDown(item.type, containerType != null ? containerType : null, item);
27926
- }
27927
- }, [dragState.wasDragged, item, isSelectingShortcut, checkIfItemCanBeMoved, checkIfItemShouldDragEnd, openQuantitySelector, handleSuccessfulDrag, resetDragState, isContextMenuDisabled, setTooltipState, setContextMenuState, onPointerDown, containerType, setItemShortcut]);
27928
- return {
27929
- dragContainer: dragContainer,
27930
- dragState: dragState,
27931
- draggingItem: draggingItem,
27932
- setDraggingItem: setDraggingItem,
27933
- getContainerBounds: getContainerBounds,
27934
- onDraggableStart: onDraggableStart,
27935
- onDraggableProgress: onDraggableProgress,
27936
- onDraggableStop: onDraggableStop,
27937
- resetItem: resetDragState
27938
- };
27939
- };
27940
27723
 
27941
27724
  var generateContextMenuListOptions = function generateContextMenuListOptions(actionsByTypeList) {
27942
27725
  var contextMenu = actionsByTypeList.map(function (action) {
@@ -28075,13 +27858,13 @@ var EquipmentSlotSpriteByType = {
28075
27858
  RightHand: 'shields/plate-shield.png',
28076
27859
  Accessory: 'ranged-weapons/arrow.png'
28077
27860
  };
28078
- var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
27861
+ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
28079
27862
  var slotIndex = _ref.slotIndex,
28080
27863
  item = _ref.item,
28081
27864
  containerType = _ref.itemContainerType,
28082
27865
  slotSpriteMask = _ref.slotSpriteMask,
28083
27866
  _onMouseOver = _ref.onMouseOver,
28084
- onMouseOut = _ref.onMouseOut,
27867
+ _onMouseOut = _ref.onMouseOut,
28085
27868
  onPointerDown = _ref.onPointerDown,
28086
27869
  _onSelected = _ref.onSelected,
28087
27870
  atlasJSON = _ref.atlasJSON,
@@ -28094,118 +27877,292 @@ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
28094
27877
  onDrop = _ref.onOutsideDrop,
28095
27878
  checkIfItemCanBeMoved = _ref.checkIfItemCanBeMoved,
28096
27879
  openQuantitySelector = _ref.openQuantitySelector,
27880
+ checkIfItemShouldDragEnd = _ref.checkIfItemShouldDragEnd,
28097
27881
  dragScale = _ref.dragScale,
28098
27882
  isSelectingShortcut = _ref.isSelectingShortcut,
28099
27883
  equipmentSet = _ref.equipmentSet,
28100
27884
  setItemShortcut = _ref.setItemShortcut,
28101
27885
  isDepotSystem = _ref.isDepotSystem;
27886
+ // Centralized state using a single useState hook
28102
27887
  var _useState = useState({
28103
- visible: false,
28104
- mobileVisible: false
28105
- }),
28106
- tooltipState = _useState[0],
28107
- setTooltipState = _useState[1];
28108
- var _useState2 = useState({
28109
- visible: false,
28110
- position: {
27888
+ isTooltipVisible: false,
27889
+ isTooltipMobileVisible: false,
27890
+ isContextMenuVisible: false,
27891
+ contextMenuPosition: {
28111
27892
  x: 0,
28112
27893
  y: 0
28113
- }
28114
- }),
28115
- contextMenuState = _useState2[0],
28116
- setContextMenuState = _useState2[1];
28117
- var _useState3 = useState([]),
28118
- contextActions = _useState3[0],
28119
- setContextActions = _useState3[1];
28120
- var _useItemSlotDragAndDr = useItemSlotDragAndDrop({
28121
- isDepotSystem: !!isDepotSystem,
28122
- item: item,
28123
- onDrop: onDrop != null ? onDrop : function () {},
28124
- onDragEnd: onDragEnd,
28125
- checkIfItemCanBeMoved: checkIfItemCanBeMoved,
28126
- setItemShortcut: setItemShortcut,
28127
- isSelectingShortcut: isSelectingShortcut,
28128
- onDragStart: onDragStart,
28129
- onPointerDown: onPointerDown,
28130
- containerType: containerType,
28131
- slotIndex: slotIndex,
28132
- openQuantitySelector: openQuantitySelector != null ? openQuantitySelector : function () {},
28133
- isContextMenuDisabled: isContextMenuDisabled,
28134
- setTooltipState: setTooltipState,
28135
- contextMenuState: contextMenuState,
28136
- setContextMenuState: setContextMenuState
27894
+ },
27895
+ isFocused: false,
27896
+ wasDragged: false,
27897
+ dragPosition: {
27898
+ x: 0,
27899
+ y: 0
27900
+ },
27901
+ dropPosition: null,
27902
+ contextActions: [],
27903
+ draggingDistance: 0
28137
27904
  }),
28138
- dragContainer = _useItemSlotDragAndDr.dragContainer,
28139
- dragState = _useItemSlotDragAndDr.dragState,
28140
- draggingItem = _useItemSlotDragAndDr.draggingItem,
28141
- getContainerBounds = _useItemSlotDragAndDr.getContainerBounds,
28142
- onDraggableStart = _useItemSlotDragAndDr.onDraggableStart,
28143
- onDraggableProgress = _useItemSlotDragAndDr.onDraggableProgress,
28144
- onDraggableStop = _useItemSlotDragAndDr.onDraggableStop;
27905
+ state = _useState[0],
27906
+ setState = _useState[1];
27907
+ var isTooltipVisible = state.isTooltipVisible,
27908
+ isTooltipMobileVisible = state.isTooltipMobileVisible,
27909
+ isContextMenuVisible = state.isContextMenuVisible,
27910
+ contextMenuPosition = state.contextMenuPosition,
27911
+ isFocused = state.isFocused,
27912
+ wasDragged = state.wasDragged,
27913
+ dragPosition = state.dragPosition,
27914
+ dropPosition = state.dropPosition,
27915
+ contextActions = state.contextActions;
27916
+ var dragContainer = useRef(null);
27917
+ var _useDragging = useDragging(),
27918
+ draggingItem = _useDragging.item,
27919
+ setDraggingItem = _useDragging.setDraggingItem;
28145
27920
  useEffect(function () {
27921
+ // Reset drag position and focus when item changes
27922
+ setState(function (prevState) {
27923
+ return _extends({}, prevState, {
27924
+ dragPosition: {
27925
+ x: 0,
27926
+ y: 0
27927
+ },
27928
+ isFocused: false
27929
+ });
27930
+ });
27931
+ // Update context actions when item or depot system changes
28146
27932
  if (item && containerType) {
28147
- setContextActions(generateContextMenu(item, containerType, isDepotSystem));
27933
+ setState(function (prevState) {
27934
+ return _extends({}, prevState, {
27935
+ contextActions: generateContextMenu(item, containerType, isDepotSystem)
27936
+ });
27937
+ });
27938
+ } else {
27939
+ setState(function (prevState) {
27940
+ return _extends({}, prevState, {
27941
+ contextActions: []
27942
+ });
27943
+ });
28148
27944
  }
28149
27945
  }, [item, isDepotSystem]);
28150
- var bounds = getContainerBounds();
28151
- var handleInteraction = useCallback(function (event) {
28152
- event.stopPropagation();
28153
- var _ref2 = 'touches' in event ? event.touches[0] : event,
28154
- clientX = _ref2.clientX,
28155
- clientY = _ref2.clientY;
28156
- if (item && containerType) {
28157
- if (onPlaceDrop && draggingItem) {
28158
- onPlaceDrop(item, slotIndex, containerType);
28159
- }
28160
- if (onPointerDown && onDragStart === undefined && onDragEnd === undefined) {
28161
- onPointerDown(item.type, containerType, item);
27946
+ useEffect(function () {
27947
+ // Handle outside drop
27948
+ if (onDrop && item && dropPosition) {
27949
+ onDrop(item, dropPosition);
27950
+ }
27951
+ }, [dropPosition]);
27952
+ var resetItem = function resetItem() {
27953
+ setState(function (prevState) {
27954
+ return _extends({}, prevState, {
27955
+ isTooltipVisible: false,
27956
+ wasDragged: false
27957
+ });
27958
+ });
27959
+ };
27960
+ var onSuccessfulDrag = function onSuccessfulDrag(quantity) {
27961
+ resetItem();
27962
+ if (quantity === -1) {
27963
+ setState(function (prevState) {
27964
+ return _extends({}, prevState, {
27965
+ dragPosition: {
27966
+ x: 0,
27967
+ y: 0
27968
+ },
27969
+ isFocused: false
27970
+ });
27971
+ });
27972
+ } else if (item) {
27973
+ onDragEnd == null ? void 0 : onDragEnd(quantity);
27974
+ }
27975
+ };
27976
+ var onDraggableStop = function onDraggableStop(e, data) {
27977
+ console.log('>>> ON_DRAGGABLE_STOP');
27978
+ // Stop the dragging state
27979
+ console.log('setDraggingItem(null)');
27980
+ setDraggingItem(null);
27981
+ var target = e.target;
27982
+ console.log('handleShortcutSetter(target)');
27983
+ handleShortcutSetter(target);
27984
+ console.log('removeDraggingClass(target)');
27985
+ removeDraggingClass(target);
27986
+ console.log('shouldHandleDraggedItem()');
27987
+ if (shouldHandleDraggedItem()) {
27988
+ console.log('handleDraggedItem(e, data)');
27989
+ handleDraggedItem(e, data);
27990
+ } else if (item && !wasDragged) {
27991
+ console.log('handleContextMenuOrTooltip(e)');
27992
+ handleContextMenuOrTooltip(e);
27993
+ }
27994
+ };
27995
+ /**
27996
+ * Handles the shortcut setter logic if the target element is a shortcut setter.
27997
+ */
27998
+ var handleShortcutSetter = function handleShortcutSetter(target) {
27999
+ if (target != null && target.id.includes('shortcutSetter') && setItemShortcut && item) {
28000
+ var index = parseInt(target.id.split('_')[1], 10);
28001
+ if (!isNaN(index)) {
28002
+ setItemShortcut(item, index);
28162
28003
  }
28163
28004
  }
28164
- setTooltipState(function (prev) {
28165
- return _extends({}, prev, {
28166
- visible: true
28005
+ };
28006
+ /**
28007
+ * Removes the dragging CSS class from the target element.
28008
+ */
28009
+ var removeDraggingClass = function removeDraggingClass(target) {
28010
+ target.classList.remove('react-draggable-dragging');
28011
+ };
28012
+ /**
28013
+ * Determines whether the dragged item should be processed.
28014
+ */
28015
+ var shouldHandleDraggedItem = function shouldHandleDraggedItem() {
28016
+ console.log("Debug: shouldHandleDraggedItem()", "wasDragged: " + wasDragged, "item: " + item, "isSelectingShortcut: " + isSelectingShortcut);
28017
+ return !!(wasDragged && item && !isSelectingShortcut);
28018
+ };
28019
+ /**
28020
+ * Handles the logic when an item has been dragged.
28021
+ */
28022
+ var handleDraggedItem = function handleDraggedItem(e, data) {
28023
+ var targetClasses = Array.from(e.target.classList);
28024
+ var isOutsideDrop = targetClasses.some(function (elm) {
28025
+ return elm.includes('rpgui-content');
28026
+ }) || targetClasses.length === 0;
28027
+ if (isOutsideDrop) {
28028
+ setState(function (prevState) {
28029
+ return _extends({}, prevState, {
28030
+ dropPosition: {
28031
+ x: data.x,
28032
+ y: data.y
28033
+ }
28034
+ });
28035
+ });
28036
+ }
28037
+ setState(function (prevState) {
28038
+ return _extends({}, prevState, {
28039
+ wasDragged: false
28167
28040
  });
28168
28041
  });
28169
- _onMouseOver == null ? void 0 : _onMouseOver(event, slotIndex, item, clientX, clientY);
28170
- }, [item, containerType, slotIndex, onPlaceDrop, onPointerDown, _onMouseOver, onDragStart, onDragEnd]);
28171
- var handleInteractionEnd = useCallback(function (event) {
28172
- event.preventDefault();
28173
- event.stopPropagation();
28174
- setTooltipState(function (prev) {
28175
- return _extends({}, prev, {
28176
- visible: false
28042
+ var targetElement = dragContainer.current;
28043
+ if (!targetElement) return;
28044
+ var _getElementTransform = getElementTransform(targetElement),
28045
+ x = _getElementTransform.x,
28046
+ y = _getElementTransform.y;
28047
+ setState(function (prevState) {
28048
+ return _extends({}, prevState, {
28049
+ dragPosition: {
28050
+ x: x,
28051
+ y: y
28052
+ }
28177
28053
  });
28178
28054
  });
28179
- onMouseOut == null ? void 0 : onMouseOut();
28180
- if (event.type === 'touchend' && 'changedTouches' in event) {
28181
- var _document$elementFrom;
28182
- var _event$changedTouches = event.changedTouches[0],
28183
- clientX = _event$changedTouches.clientX,
28184
- clientY = _event$changedTouches.clientY;
28185
- var simulatedEvent = new MouseEvent('mouseup', {
28186
- clientX: clientX,
28187
- clientY: clientY,
28188
- bubbles: true
28055
+ // Delay to ensure state updates before proceeding
28056
+ setTimeout(function () {
28057
+ processDragEnd(item);
28058
+ }, 50);
28059
+ };
28060
+ /**
28061
+ * Retrieves the current transform position of the dragged element.
28062
+ */
28063
+ var getElementTransform = function getElementTransform(element) {
28064
+ var style = window.getComputedStyle(element);
28065
+ var matrix = new DOMMatrixReadOnly(style.transform);
28066
+ return {
28067
+ x: matrix.m41,
28068
+ y: matrix.m42
28069
+ };
28070
+ };
28071
+ /**
28072
+ * Processes the end of a drag event, handling quantity selection or resetting state.
28073
+ */
28074
+ var processDragEnd = function processDragEnd(item) {
28075
+ console.log("Debug: processDragEnd(item)", "item: " + item);
28076
+ if (checkIfItemCanBeMoved != null && checkIfItemCanBeMoved()) {
28077
+ console.log("Debug: checkIfItemCanBeMoved()", "result: " + checkIfItemCanBeMoved());
28078
+ if (checkIfItemShouldDragEnd && !checkIfItemShouldDragEnd()) return;
28079
+ console.log("Debug: checkIfItemShouldDragEnd()", "result: " + (checkIfItemShouldDragEnd == null ? void 0 : checkIfItemShouldDragEnd()));
28080
+ if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) {
28081
+ console.log("Debug: openQuantitySelector(item.stackQty, onSuccessfulDrag)");
28082
+ openQuantitySelector(item.stackQty, onSuccessfulDrag);
28083
+ } else {
28084
+ console.log("Debug: onSuccessfulDrag(item.stackQty)");
28085
+ onSuccessfulDrag(item.stackQty);
28086
+ }
28087
+ } else {
28088
+ console.log("Debug: resetItem()");
28089
+ resetItem();
28090
+ setState(function (prevState) {
28091
+ return _extends({}, prevState, {
28092
+ isFocused: false,
28093
+ dragPosition: {
28094
+ x: 0,
28095
+ y: 0
28096
+ }
28097
+ });
28189
28098
  });
28190
- (_document$elementFrom = document.elementFromPoint(clientX, clientY)) == null ? void 0 : _document$elementFrom.dispatchEvent(simulatedEvent);
28191
28099
  }
28192
- }, [onMouseOut]);
28100
+ };
28101
+ /**
28102
+ * Handles the context menu or tooltip display after dragging stops without a drop.
28103
+ */
28104
+ var handleContextMenuOrTooltip = function handleContextMenuOrTooltip(e) {
28105
+ var isTouchEvent = false;
28106
+ if (!isContextMenuDisabled && e.type === 'touchend' && !isSelectingShortcut) {
28107
+ isTouchEvent = true;
28108
+ setState(function (prevState) {
28109
+ return _extends({}, prevState, {
28110
+ isTooltipMobileVisible: true
28111
+ });
28112
+ });
28113
+ }
28114
+ if (!isContextMenuDisabled && !isSelectingShortcut && !isTouchEvent) {
28115
+ setState(function (prevState) {
28116
+ return _extends({}, prevState, {
28117
+ isContextMenuVisible: !prevState.isContextMenuVisible,
28118
+ contextMenuPosition: {
28119
+ x: e.clientX - 10,
28120
+ y: e.clientY - 5
28121
+ }
28122
+ });
28123
+ });
28124
+ }
28125
+ if (item) {
28126
+ onPointerDown(item.type, containerType != null ? containerType : null, item);
28127
+ }
28128
+ };
28129
+ var onDraggableStart = function onDraggableStart() {
28130
+ if (!item || isSelectingShortcut) {
28131
+ return;
28132
+ }
28133
+ if (onDragStart && containerType) {
28134
+ onDragStart(item, slotIndex, containerType);
28135
+ }
28136
+ };
28137
+ var onDraggableProgress = function onDraggableProgress(_e, _data) {
28138
+ // increment draggingDistance by 1
28139
+ setState(function (prevState) {
28140
+ return _extends({}, prevState, {
28141
+ draggingDistance: prevState.draggingDistance + 1
28142
+ });
28143
+ });
28144
+ if (state.draggingDistance > 10) {
28145
+ setState(function (prevState) {
28146
+ return _extends({}, prevState, {
28147
+ wasDragged: true,
28148
+ isFocused: true
28149
+ });
28150
+ });
28151
+ }
28152
+ if (!draggingItem) {
28153
+ setDraggingItem(item);
28154
+ }
28155
+ };
28193
28156
  return React.createElement(Container$b, {
28194
28157
  isDraggingItem: !!draggingItem,
28195
28158
  item: item,
28196
28159
  className: "rpgui-icon empty-slot",
28197
- 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),
28198
- onMouseDown: handleInteraction,
28199
- onTouchStart: handleInteraction,
28200
- onMouseUp: function onMouseUp(e) {
28201
- handleInteractionEnd(e);
28160
+ onMouseUp: function onMouseUp() {
28202
28161
  var data = item ? item : null;
28203
- if (onPlaceDrop && containerType && draggingItem) {
28204
- onPlaceDrop(data, slotIndex, containerType);
28205
- }
28162
+ if (onPlaceDrop && containerType) onPlaceDrop(data, slotIndex, containerType);
28206
28163
  },
28207
28164
  onTouchEnd: function onTouchEnd(e) {
28208
- var _document$elementFrom2;
28165
+ var _document$elementFrom;
28209
28166
  var _e$changedTouches$ = e.changedTouches[0],
28210
28167
  clientX = _e$changedTouches$.clientX,
28211
28168
  clientY = _e$changedTouches$.clientY;
@@ -28214,12 +28171,12 @@ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
28214
28171
  clientY: clientY,
28215
28172
  bubbles: true
28216
28173
  });
28217
- (_document$elementFrom2 = document.elementFromPoint(clientX, clientY)) == null ? void 0 : _document$elementFrom2.dispatchEvent(simulatedEvent);
28174
+ (_document$elementFrom = document.elementFromPoint(clientX, clientY)) == null ? void 0 : _document$elementFrom.dispatchEvent(simulatedEvent);
28218
28175
  },
28219
28176
  onPointerDown: onDragStart !== undefined && onDragEnd !== undefined ? undefined : function () {
28220
28177
  if (item) onPointerDown(item.type, containerType != null ? containerType : null, item);
28221
28178
  },
28222
- onMouseLeave: handleInteractionEnd
28179
+ 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)
28223
28180
  }, React.createElement(Draggable, {
28224
28181
  axis: isSelectingShortcut ? 'none' : 'both',
28225
28182
  defaultClassName: item ? 'draggable' : 'empty-slot',
@@ -28228,27 +28185,29 @@ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
28228
28185
  onStop: onDraggableStop,
28229
28186
  onStart: onDraggableStart,
28230
28187
  onDrag: onDraggableProgress,
28231
- position: dragState.position,
28188
+ position: dragPosition,
28232
28189
  cancel: ".empty-slot",
28233
- bounds: bounds
28190
+ bounds: ".item-container-body, .equipment-container-body"
28234
28191
  }, React.createElement(ItemContainer, {
28235
28192
  ref: dragContainer,
28236
- isFocused: dragState.isFocused,
28193
+ isFocused: isFocused,
28237
28194
  onMouseOver: function onMouseOver(event) {
28238
28195
  _onMouseOver == null ? void 0 : _onMouseOver(event, slotIndex, item, event.clientX, event.clientY);
28239
28196
  },
28240
- onMouseOut: onMouseOut,
28197
+ onMouseOut: function onMouseOut() {
28198
+ if (_onMouseOut) _onMouseOut();
28199
+ },
28241
28200
  onMouseEnter: function onMouseEnter() {
28242
- setTooltipState(function (prev) {
28243
- return _extends({}, prev, {
28244
- visible: true
28201
+ setState(function (prevState) {
28202
+ return _extends({}, prevState, {
28203
+ isTooltipVisible: true
28245
28204
  });
28246
28205
  });
28247
28206
  },
28248
28207
  onMouseLeave: function onMouseLeave() {
28249
- setTooltipState(function (prev) {
28250
- return _extends({}, prev, {
28251
- visible: false
28208
+ setState(function (prevState) {
28209
+ return _extends({}, prevState, {
28210
+ isTooltipVisible: false
28252
28211
  });
28253
28212
  });
28254
28213
  }
@@ -28259,45 +28218,66 @@ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
28259
28218
  atlasJSON: atlasJSON,
28260
28219
  containerType: containerType
28261
28220
  }))), React.createElement(ItemSlotToolTips, {
28262
- tooltipState: tooltipState,
28263
- setTooltipState: setTooltipState,
28264
- contextMenuState: contextMenuState,
28265
- setContextMenuState: setContextMenuState,
28266
- isFocused: dragState.isFocused,
28221
+ isTooltipVisible: isTooltipVisible,
28222
+ isTooltipMobileVisible: isTooltipMobileVisible,
28223
+ setIsTooltipMobileVisible: function setIsTooltipMobileVisible(value) {
28224
+ return setState(function (prevState) {
28225
+ return _extends({}, prevState, {
28226
+ isTooltipMobileVisible: value
28227
+ });
28228
+ });
28229
+ },
28230
+ isFocused: isFocused,
28231
+ isContextMenuVisible: isContextMenuVisible,
28267
28232
  isContextMenuDisabled: isContextMenuDisabled,
28268
28233
  item: item,
28269
28234
  contextActions: contextActions,
28235
+ contextMenuPosition: contextMenuPosition,
28270
28236
  dragScale: dragScale,
28237
+ setIsContextMenuVisible: function setIsContextMenuVisible(value) {
28238
+ return setState(function (prevState) {
28239
+ return _extends({}, prevState, {
28240
+ isContextMenuVisible: value
28241
+ });
28242
+ });
28243
+ },
28271
28244
  onSelected: function onSelected(optionId, item) {
28272
- setContextMenuState(function (prev) {
28273
- return _extends({}, prev, {
28274
- visible: false
28245
+ setState(function (prevState) {
28246
+ return _extends({}, prevState, {
28247
+ isContextMenuVisible: false
28275
28248
  });
28276
28249
  });
28277
28250
  if (_onSelected) _onSelected(optionId, item);
28278
28251
  },
28279
28252
  atlasIMG: atlasIMG,
28280
28253
  atlasJSON: atlasJSON,
28281
- equipmentSet: equipmentSet
28254
+ equipmentSet: equipmentSet,
28255
+ setIsTooltipVisible: function setIsTooltipVisible(value) {
28256
+ return setState(function (prevState) {
28257
+ return _extends({}, prevState, {
28258
+ isTooltipVisible: value
28259
+ });
28260
+ });
28261
+ }
28282
28262
  }));
28283
- }));
28263
+ });
28284
28264
  var Container$b = /*#__PURE__*/styled.div.withConfig({
28285
28265
  displayName: "ItemSlot__Container",
28286
28266
  componentId: "sc-l2j5ef-0"
28287
- })(["margin:0.1rem;.react-draggable-dragging{opacity:", ";}position:relative;.sprite-from-atlas-img--item{position:relative;top:1.5rem;left:1.5rem;border-color:", ";box-shadow:", " inset,", ";}&::before{content:'';position:absolute;top:0;left:0;width:100%;height:100%;z-index:1;border-radius:12px;pointer-events:none;animation:", ";@keyframes bg-color-change{0%{background-color:rgba(255 255 255 / 0.5);}50%{background-color:transparent;}100%{background-color:rgba(255 255 255 / 0.5);}}}"], function (_ref3) {
28288
- var isDraggingItem = _ref3.isDraggingItem;
28267
+ })(["margin:0.1rem;.react-draggable-dragging{opacity:", ";}position:relative;.sprite-from-atlas-img--item{position:relative;top:1.5rem;left:1.5rem;border-color:", ";box-shadow:", " inset,", ";}&::before{content:'';position:absolute;top:0;left:0;width:100%;height:100%;z-index:1;border-radius:12px;pointer-events:none;animation:", ";@keyframes bg-color-change{0%{background-color:rgba(255 255 255 / 0.5);}50%{background-color:transparent;}100%{background-color:rgba(255 255 255 / 0.5);}}}"], function (_ref2) {
28268
+ var isDraggingItem = _ref2.isDraggingItem;
28289
28269
  return isDraggingItem ? 0 : 1;
28270
+ }, function (_ref3) {
28271
+ var item = _ref3.item;
28272
+ return rarityColor(item);
28290
28273
  }, function (_ref4) {
28291
28274
  var item = _ref4.item;
28292
- return rarityColor(item);
28275
+ return "0 0 5px 2px " + rarityColor(item);
28293
28276
  }, function (_ref5) {
28294
28277
  var item = _ref5.item;
28295
- return "0 0 5px 2px " + rarityColor(item);
28296
- }, function (_ref6) {
28297
- var item = _ref6.item;
28298
28278
  return "0 0 4px 3px " + rarityColor(item);
28299
- }, function (_ref7) {
28300
- var isSelectingShortcut = _ref7.isSelectingShortcut;
28279
+ }, function (_ref6) {
28280
+ var isSelectingShortcut = _ref6.isSelectingShortcut;
28301
28281
  return isSelectingShortcut ? 'bg-color-change 1s infinite' : 'none';
28302
28282
  });
28303
28283
  var ItemContainer = /*#__PURE__*/styled.div.withConfig({
@@ -30630,6 +30610,7 @@ var ItemContainer$1 = function ItemContainer(_ref) {
30630
30610
  _onOutsideDrop = _ref.onOutsideDrop,
30631
30611
  checkIfItemCanBeMoved = _ref.checkIfItemCanBeMoved,
30632
30612
  initialPosition = _ref.initialPosition,
30613
+ checkIfItemShouldDragEnd = _ref.checkIfItemShouldDragEnd,
30633
30614
  scale = _ref.scale,
30634
30615
  shortcuts = _ref.shortcuts,
30635
30616
  setItemShortcut = _ref.setItemShortcut,
@@ -30678,14 +30659,12 @@ var ItemContainer$1 = function ItemContainer(_ref) {
30678
30659
  document.removeEventListener('pointermove', handleMouseMove);
30679
30660
  }, [handleMouseMove, onItemDragStart, stopScrolling]);
30680
30661
  var onDragStart = function onDragStart(item, slotIndex, itemContainerType) {
30681
- console.log('DRAG START');
30682
30662
  if (onItemDragStart) {
30683
30663
  onItemDragStart(item, slotIndex, itemContainerType);
30684
30664
  }
30685
30665
  onDragStartScrollingEvents();
30686
30666
  };
30687
30667
  var onDragEnd = function onDragEnd(quantity) {
30688
- console.log('DRAG END');
30689
30668
  if (onItemDragEnd) {
30690
30669
  onItemDragEnd(quantity);
30691
30670
  }
@@ -30719,6 +30698,7 @@ var ItemContainer$1 = function ItemContainer(_ref) {
30719
30698
  onDragEnd: onDragEnd,
30720
30699
  dragScale: scale,
30721
30700
  checkIfItemCanBeMoved: checkIfItemCanBeMoved,
30701
+ checkIfItemShouldDragEnd: checkIfItemShouldDragEnd,
30722
30702
  openQuantitySelector: function openQuantitySelector(maxQuantity, callback) {
30723
30703
  setQuantitySelect({
30724
30704
  isOpen: true,