@rpg-engine/long-bow 0.7.38 → 0.7.40

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, useMemo, useCallback, Fragment } from 'react';
1
+ import React, { useState, useEffect, Component, useRef, useContext, createContext, useCallback, useMemo, 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';
@@ -27651,54 +27651,68 @@ var Option = /*#__PURE__*/styled.button.withConfig({
27651
27651
  })(["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;}"]);
27652
27652
 
27653
27653
  var ItemSlotToolTips = function ItemSlotToolTips(_ref) {
27654
- var isTooltipVisible = _ref.isTooltipVisible,
27654
+ var tooltipState = _ref.tooltipState,
27655
+ setTooltipState = _ref.setTooltipState,
27656
+ contextMenuState = _ref.contextMenuState,
27657
+ setContextMenuState = _ref.setContextMenuState,
27655
27658
  isFocused = _ref.isFocused,
27656
- isContextMenuVisible = _ref.isContextMenuVisible,
27657
27659
  isContextMenuDisabled = _ref.isContextMenuDisabled,
27658
27660
  item = _ref.item,
27659
27661
  contextActions = _ref.contextActions,
27660
- contextMenuPosition = _ref.contextMenuPosition,
27661
27662
  dragScale = _ref.dragScale,
27662
- setIsContextMenuVisible = _ref.setIsContextMenuVisible,
27663
- setIsTooltipMobileVisible = _ref.setIsTooltipMobileVisible,
27664
- isTooltipMobileVisible = _ref.isTooltipMobileVisible,
27665
27663
  _onSelected = _ref.onSelected,
27666
27664
  atlasIMG = _ref.atlasIMG,
27667
27665
  atlasJSON = _ref.atlasJSON,
27668
27666
  equipmentSet = _ref.equipmentSet;
27669
- return React.createElement(React.Fragment, null, isTooltipVisible && item && !isFocused && React.createElement(ItemTooltip, {
27667
+ return React.createElement(React.Fragment, null, tooltipState.visible && item && !isFocused && React.createElement(ItemTooltip, {
27670
27668
  item: item,
27671
27669
  atlasIMG: atlasIMG,
27672
27670
  atlasJSON: atlasJSON,
27673
27671
  equipmentSet: equipmentSet
27674
- }), isTooltipMobileVisible && item && React.createElement(MobileItemTooltip, {
27672
+ }), tooltipState.mobileVisible && item && React.createElement(MobileItemTooltip, {
27675
27673
  item: item,
27676
27674
  atlasIMG: atlasIMG,
27677
27675
  atlasJSON: atlasJSON,
27678
27676
  equipmentSet: equipmentSet,
27679
27677
  closeTooltip: function closeTooltip() {
27680
- setIsTooltipMobileVisible(false);
27678
+ setTooltipState(function (prev) {
27679
+ return _extends({}, prev, {
27680
+ mobileVisible: false
27681
+ });
27682
+ });
27681
27683
  },
27682
27684
  scale: dragScale,
27683
27685
  options: contextActions,
27684
27686
  onSelected: function onSelected(optionId) {
27685
- setIsContextMenuVisible(false);
27687
+ setContextMenuState(function (prev) {
27688
+ return _extends({}, prev, {
27689
+ visible: false
27690
+ });
27691
+ });
27686
27692
  if (item) {
27687
27693
  _onSelected == null ? void 0 : _onSelected(optionId, item);
27688
27694
  }
27689
27695
  }
27690
- }), !isContextMenuDisabled && isContextMenuVisible && contextActions && React.createElement(RelativeListMenu, {
27696
+ }), !isContextMenuDisabled && contextMenuState.visible && contextActions && React.createElement(RelativeListMenu, {
27691
27697
  options: contextActions,
27692
27698
  onSelected: function onSelected(optionId) {
27693
- setIsContextMenuVisible(false);
27699
+ setContextMenuState(function (prev) {
27700
+ return _extends({}, prev, {
27701
+ visible: false
27702
+ });
27703
+ });
27694
27704
  if (item) {
27695
27705
  _onSelected == null ? void 0 : _onSelected(optionId, item);
27696
27706
  }
27697
27707
  },
27698
27708
  onOutsideClick: function onOutsideClick() {
27699
- setIsContextMenuVisible(false);
27709
+ setContextMenuState(function (prev) {
27710
+ return _extends({}, prev, {
27711
+ visible: false
27712
+ });
27713
+ });
27700
27714
  },
27701
- pos: contextMenuPosition
27715
+ pos: contextMenuState.position
27702
27716
  }));
27703
27717
  };
27704
27718
 
@@ -27859,7 +27873,7 @@ var EquipmentSlotSpriteByType = {
27859
27873
  RightHand: 'shields/plate-shield.png',
27860
27874
  Accessory: 'ranged-weapons/arrow.png'
27861
27875
  };
27862
- var ItemSlot = /*#__PURE__*/observer(function (_ref) {
27876
+ var ItemSlot = /*#__PURE__*/React.memo( /*#__PURE__*/observer(function (_ref) {
27863
27877
  var slotIndex = _ref.slotIndex,
27864
27878
  item = _ref.item,
27865
27879
  containerType = _ref.itemContainerType,
@@ -27884,70 +27898,103 @@ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
27884
27898
  equipmentSet = _ref.equipmentSet,
27885
27899
  setItemShortcut = _ref.setItemShortcut,
27886
27900
  isDepotSystem = _ref.isDepotSystem;
27887
- var _useState = useState(false),
27888
- isTooltipVisible = _useState[0],
27889
- setTooltipVisible = _useState[1];
27890
- var _useState2 = useState(false),
27891
- isTooltipMobileVisible = _useState2[0],
27892
- setIsTooltipMobileVisible = _useState2[1];
27893
- var _useState3 = useState(false),
27894
- isContextMenuVisible = _useState3[0],
27895
- setIsContextMenuVisible = _useState3[1];
27896
- var _useState4 = useState({
27897
- x: 0,
27898
- y: 0
27901
+ var _useState = useState({
27902
+ visible: false,
27903
+ mobileVisible: false
27899
27904
  }),
27900
- contextMenuPosition = _useState4[0],
27901
- setContextMenuPosition = _useState4[1];
27902
- var _useState5 = useState(false),
27903
- isFocused = _useState5[0],
27904
- setIsFocused = _useState5[1];
27905
- var _useState6 = useState(false),
27906
- wasDragged = _useState6[0],
27907
- setWasDragged = _useState6[1];
27908
- var _useState7 = useState({
27909
- x: 0,
27910
- y: 0
27905
+ tooltipState = _useState[0],
27906
+ setTooltipState = _useState[1];
27907
+ var _useState2 = useState({
27908
+ visible: false,
27909
+ position: {
27910
+ x: 0,
27911
+ y: 0
27912
+ }
27913
+ }),
27914
+ contextMenuState = _useState2[0],
27915
+ setContextMenuState = _useState2[1];
27916
+ var _useState3 = useState({
27917
+ isFocused: false,
27918
+ wasDragged: false,
27919
+ position: {
27920
+ x: 0,
27921
+ y: 0
27922
+ },
27923
+ dropPosition: null
27911
27924
  }),
27912
- dragPosition = _useState7[0],
27913
- setDragPosition = _useState7[1];
27914
- var _useState8 = useState(null),
27915
- dropPosition = _useState8[0],
27916
- setDropPosition = _useState8[1];
27925
+ dragState = _useState3[0],
27926
+ setDragState = _useState3[1];
27917
27927
  var dragContainer = useRef(null);
27918
27928
  var _useDragging = useDragging(),
27919
27929
  draggingItem = _useDragging.item,
27920
27930
  setDraggingItem = _useDragging.setDraggingItem;
27921
- var _useState9 = useState([]),
27922
- contextActions = _useState9[0],
27923
- setContextActions = _useState9[1];
27931
+ var _useState4 = useState([]),
27932
+ contextActions = _useState4[0],
27933
+ setContextActions = _useState4[1];
27924
27934
  useEffect(function () {
27925
- setDragPosition({
27926
- x: 0,
27927
- y: 0
27935
+ setDragState(function (prev) {
27936
+ return _extends({}, prev, {
27937
+ position: {
27938
+ x: 0,
27939
+ y: 0
27940
+ },
27941
+ isFocused: false
27942
+ });
27928
27943
  });
27929
- setIsFocused(false);
27930
27944
  if (item && containerType) {
27931
27945
  setContextActions(generateContextMenu(item, containerType, isDepotSystem));
27932
27946
  }
27933
27947
  }, [item, isDepotSystem]);
27934
27948
  useEffect(function () {
27935
- if (onDrop && item && dropPosition) {
27936
- onDrop(item, dropPosition);
27949
+ if (onDrop && item && dragState.dropPosition) {
27950
+ onDrop(item, dragState.dropPosition);
27951
+ setDragState(function (prev) {
27952
+ return _extends({}, prev, {
27953
+ dropPosition: null
27954
+ });
27955
+ });
27937
27956
  }
27938
- }, [dropPosition]);
27957
+ }, [dragState.dropPosition]);
27958
+ var getContainerBounds = useCallback(function () {
27959
+ var container = dragContainer.current;
27960
+ if (!container) return {
27961
+ left: 0,
27962
+ top: 0,
27963
+ right: 0,
27964
+ bottom: 0
27965
+ };
27966
+ var rect = container.getBoundingClientRect();
27967
+ return {
27968
+ left: rect.left,
27969
+ top: rect.top,
27970
+ right: window.innerWidth - rect.right,
27971
+ bottom: window.innerHeight - rect.bottom
27972
+ };
27973
+ }, [dragContainer]);
27939
27974
  var resetItem = function resetItem() {
27940
- setTooltipVisible(false);
27941
- setWasDragged(false);
27975
+ setTooltipState(function (prev) {
27976
+ return _extends({}, prev, {
27977
+ visible: false
27978
+ });
27979
+ });
27980
+ setDragState(function (prev) {
27981
+ return _extends({}, prev, {
27982
+ wasDragged: false
27983
+ });
27984
+ });
27942
27985
  };
27943
27986
  var onSuccessfulDrag = function onSuccessfulDrag(quantity) {
27944
27987
  resetItem();
27945
27988
  if (quantity === -1) {
27946
- setDragPosition({
27947
- x: 0,
27948
- y: 0
27989
+ setDragState(function (prev) {
27990
+ return _extends({}, prev, {
27991
+ position: {
27992
+ x: 0,
27993
+ y: 0
27994
+ },
27995
+ isFocused: false
27996
+ });
27949
27997
  });
27950
- setIsFocused(false);
27951
27998
  } else if (item) {
27952
27999
  onDragEnd == null ? void 0 : onDragEnd(quantity);
27953
28000
  }
@@ -27955,6 +28002,7 @@ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
27955
28002
  var onDraggableStop = function onDraggableStop(e, data) {
27956
28003
  setDraggingItem(null);
27957
28004
  var target = e.target;
28005
+ if (!target) return;
27958
28006
  if (target != null && target.id.includes('shortcutSetter') && setItemShortcut && item) {
27959
28007
  var index = parseInt(target.id.split('_')[1]);
27960
28008
  if (!isNaN(index)) {
@@ -27964,7 +28012,7 @@ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
27964
28012
  // remove the class react-draggable-dragging from the element
27965
28013
  // to prevent the item from being dragged again
27966
28014
  target.classList.remove('react-draggable-dragging');
27967
- if (wasDragged && item && !isSelectingShortcut) {
28015
+ if (dragState.wasDragged && item && !isSelectingShortcut) {
27968
28016
  var _e$target;
27969
28017
  //@ts-ignore
27970
28018
  var classes = Array.from((_e$target = e.target) == null ? void 0 : _e$target.classList);
@@ -27972,32 +28020,50 @@ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
27972
28020
  return elm.includes('rpgui-content');
27973
28021
  }) || classes.length === 0;
27974
28022
  if (isOutsideDrop) {
27975
- setDropPosition({
27976
- x: data.x,
27977
- y: data.y
28023
+ setDragState(function (prev) {
28024
+ return _extends({}, prev, {
28025
+ dropPosition: {
28026
+ x: data.x,
28027
+ y: data.y
28028
+ }
28029
+ });
27978
28030
  });
27979
28031
  }
27980
- setWasDragged(false);
28032
+ setDragState(function (prev) {
28033
+ return _extends({}, prev, {
28034
+ wasDragged: false
28035
+ });
28036
+ });
27981
28037
  var _target = dragContainer.current;
27982
- if (!_target || !wasDragged) return;
28038
+ if (!_target || !dragState.wasDragged) return;
27983
28039
  var style = window.getComputedStyle(_target);
27984
28040
  var matrix = new DOMMatrixReadOnly(style.transform);
27985
28041
  var x = matrix.m41;
27986
28042
  var y = matrix.m42;
27987
- setDragPosition({
27988
- x: x,
27989
- y: y
28043
+ setDragState(function (prev) {
28044
+ return _extends({}, prev, {
28045
+ position: {
28046
+ x: x,
28047
+ y: y
28048
+ }
28049
+ });
27990
28050
  });
27991
28051
  setTimeout(function () {
27992
- if (checkIfItemCanBeMoved != null && checkIfItemCanBeMoved()) {
28052
+ if (checkIfItemCanBeMoved && checkIfItemCanBeMoved()) {
27993
28053
  if (checkIfItemShouldDragEnd && !checkIfItemShouldDragEnd()) return;
27994
- if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) openQuantitySelector(item.stackQty, onSuccessfulDrag);else onSuccessfulDrag(item.stackQty);
28054
+ if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) {
28055
+ openQuantitySelector(item.stackQty, onSuccessfulDrag);
28056
+ } else onSuccessfulDrag(item.stackQty);
27995
28057
  } else {
27996
28058
  resetItem();
27997
- setIsFocused(false);
27998
- setDragPosition({
27999
- x: 0,
28000
- y: 0
28059
+ setDragState(function (prev) {
28060
+ return _extends({}, prev, {
28061
+ isFocused: false,
28062
+ position: {
28063
+ x: 0,
28064
+ y: 0
28065
+ }
28066
+ });
28001
28067
  });
28002
28068
  }
28003
28069
  }, 50);
@@ -28005,15 +28071,27 @@ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
28005
28071
  var isTouch = false;
28006
28072
  if (!isContextMenuDisabled && e.type === 'touchend' && !isSelectingShortcut) {
28007
28073
  isTouch = true;
28008
- setIsTooltipMobileVisible(true);
28074
+ setTooltipState(function (prev) {
28075
+ return _extends({}, prev, {
28076
+ mobileVisible: true
28077
+ });
28078
+ });
28009
28079
  }
28010
28080
  if (!isContextMenuDisabled && !isSelectingShortcut && !isTouch) {
28011
- setIsContextMenuVisible(!isContextMenuVisible);
28081
+ setContextMenuState(function (prev) {
28082
+ return _extends({}, prev, {
28083
+ visible: !contextMenuState.visible
28084
+ });
28085
+ });
28012
28086
  var event = e;
28013
28087
  if (event.clientX && event.clientY) {
28014
- setContextMenuPosition({
28015
- x: event.clientX - 10,
28016
- y: event.clientY - 5
28088
+ setContextMenuState(function (prev) {
28089
+ return _extends({}, prev, {
28090
+ position: {
28091
+ x: event.clientX - 10,
28092
+ y: event.clientY - 5
28093
+ }
28094
+ });
28017
28095
  });
28018
28096
  }
28019
28097
  }
@@ -28029,21 +28107,28 @@ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
28029
28107
  }
28030
28108
  };
28031
28109
  var onDraggableProgress = function onDraggableProgress(_e, data) {
28032
- if (Math.abs(data.x - dragPosition.x) > 5 || Math.abs(data.y - dragPosition.y) > 5) {
28033
- setWasDragged(true);
28034
- setIsFocused(true);
28110
+ if (Math.abs(data.x - dragState.position.x) > 5 || Math.abs(data.y - dragState.position.y) > 5) {
28111
+ setDragState(function (prev) {
28112
+ return _extends({}, prev, {
28113
+ wasDragged: true,
28114
+ isFocused: true
28115
+ });
28116
+ });
28035
28117
  }
28036
28118
  if (!draggingItem) {
28037
28119
  setDraggingItem(item);
28038
28120
  }
28039
28121
  };
28122
+ var bounds = getContainerBounds();
28040
28123
  return React.createElement(Container$b, {
28041
28124
  isDraggingItem: !!draggingItem,
28042
28125
  item: item,
28043
28126
  className: "rpgui-icon empty-slot",
28044
28127
  onMouseUp: function onMouseUp() {
28045
28128
  var data = item ? item : null;
28046
- if (onPlaceDrop && containerType) onPlaceDrop(data, slotIndex, containerType);
28129
+ if (onPlaceDrop && containerType) {
28130
+ onPlaceDrop(data, slotIndex, containerType);
28131
+ }
28047
28132
  },
28048
28133
  onTouchEnd: function onTouchEnd(e) {
28049
28134
  var _document$elementFrom;
@@ -28069,12 +28154,12 @@ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
28069
28154
  onStop: onDraggableStop,
28070
28155
  onStart: onDraggableStart,
28071
28156
  onDrag: onDraggableProgress,
28072
- position: dragPosition,
28157
+ position: dragState.position,
28073
28158
  cancel: ".empty-slot",
28074
- bounds: ".item-container-body, .equipment-container-body"
28159
+ bounds: bounds
28075
28160
  }, React.createElement(ItemContainer, {
28076
28161
  ref: dragContainer,
28077
- isFocused: isFocused,
28162
+ isFocused: dragState.isFocused,
28078
28163
  onMouseOver: function onMouseOver(event) {
28079
28164
  _onMouseOver == null ? void 0 : _onMouseOver(event, slotIndex, item, event.clientX, event.clientY);
28080
28165
  },
@@ -28082,10 +28167,18 @@ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
28082
28167
  if (_onMouseOut) _onMouseOut();
28083
28168
  },
28084
28169
  onMouseEnter: function onMouseEnter() {
28085
- setTooltipVisible(true);
28170
+ setTooltipState(function (prev) {
28171
+ return _extends({}, prev, {
28172
+ visible: true
28173
+ });
28174
+ });
28086
28175
  },
28087
28176
  onMouseLeave: function onMouseLeave() {
28088
- setTooltipVisible(false);
28177
+ setTooltipState(function (prev) {
28178
+ return _extends({}, prev, {
28179
+ visible: false
28180
+ });
28181
+ });
28089
28182
  }
28090
28183
  }, React.createElement(ItemSlotRenderer, {
28091
28184
  item: item,
@@ -28094,27 +28187,28 @@ var ItemSlot = /*#__PURE__*/observer(function (_ref) {
28094
28187
  atlasJSON: atlasJSON,
28095
28188
  containerType: containerType
28096
28189
  }))), React.createElement(ItemSlotToolTips, {
28097
- isTooltipVisible: isTooltipVisible,
28098
- isTooltipMobileVisible: isTooltipMobileVisible,
28099
- setIsTooltipMobileVisible: setIsTooltipMobileVisible,
28100
- isFocused: isFocused,
28101
- isContextMenuVisible: isContextMenuVisible,
28190
+ tooltipState: tooltipState,
28191
+ setTooltipState: setTooltipState,
28192
+ contextMenuState: contextMenuState,
28193
+ setContextMenuState: setContextMenuState,
28194
+ isFocused: dragState.isFocused,
28102
28195
  isContextMenuDisabled: isContextMenuDisabled,
28103
28196
  item: item,
28104
28197
  contextActions: contextActions,
28105
- contextMenuPosition: contextMenuPosition,
28106
28198
  dragScale: dragScale,
28107
- setIsContextMenuVisible: setIsContextMenuVisible,
28108
28199
  onSelected: function onSelected(optionId, item) {
28109
- setIsContextMenuVisible(false);
28200
+ setContextMenuState(function (prev) {
28201
+ return _extends({}, prev, {
28202
+ visible: false
28203
+ });
28204
+ });
28110
28205
  if (_onSelected) _onSelected(optionId, item);
28111
28206
  },
28112
28207
  atlasIMG: atlasIMG,
28113
28208
  atlasJSON: atlasJSON,
28114
- equipmentSet: equipmentSet,
28115
- setIsTooltipVisible: setTooltipVisible
28209
+ equipmentSet: equipmentSet
28116
28210
  }));
28117
- });
28211
+ }));
28118
28212
  var Container$b = /*#__PURE__*/styled.div.withConfig({
28119
28213
  displayName: "ItemSlot__Container",
28120
28214
  componentId: "sc-l2j5ef-0"
@@ -30543,7 +30637,9 @@ var ItemContainer$1 = function ItemContainer(_ref) {
30543
30637
  if (settingShortcutIndex !== -1) {
30544
30638
  setSettingShortcutIndex(-1);
30545
30639
  handleSetShortcut(item, settingShortcutIndex);
30546
- } else if (onItemClick) onItemClick(item, itemType, containerType);
30640
+ } else if (onItemClick) {
30641
+ onItemClick(item, itemType, containerType);
30642
+ }
30547
30643
  },
30548
30644
  onSelected: function onSelected(optionId, item) {
30549
30645
  if (_onSelected) _onSelected(optionId, item);