@rpg-engine/long-bow 0.5.36 → 0.5.38

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,11 @@
1
+ /// <reference types="react" />
2
+ interface IUseScrollOnDragProps {
3
+ containerRef: React.RefObject<HTMLDivElement>;
4
+ threshold: number;
5
+ scrollStep: number;
6
+ }
7
+ export declare const useScrollOnDrag: ({ containerRef, threshold, scrollStep, }: IUseScrollOnDragProps) => {
8
+ startScrolling: (clientY: number) => void;
9
+ stopScrolling: () => void;
10
+ };
11
+ export {};
@@ -14020,7 +14020,8 @@ var ItemSlot = /*#__PURE__*/mobxReactLite.observer(function (_ref) {
14020
14020
  onStart: onDraggableStart,
14021
14021
  onDrag: onDraggableProgress,
14022
14022
  position: dragPosition,
14023
- cancel: ".empty-slot"
14023
+ cancel: ".empty-slot",
14024
+ bounds: ".item-container-body"
14024
14025
  }, React__default.createElement(ItemContainer, {
14025
14026
  ref: dragContainer,
14026
14027
  isFocused: isFocused,
@@ -15669,6 +15670,54 @@ var SlotsContainer = function SlotsContainer(_ref) {
15669
15670
  }, children);
15670
15671
  };
15671
15672
 
15673
+ var useScrollOnDrag = function useScrollOnDrag(_ref) {
15674
+ var containerRef = _ref.containerRef,
15675
+ threshold = _ref.threshold,
15676
+ scrollStep = _ref.scrollStep;
15677
+ var animationFrameId = React.useRef(null);
15678
+ var startScrolling = React.useCallback(function (clientY) {
15679
+ var scroll = function scroll() {
15680
+ if (containerRef.current) {
15681
+ var _containerRef$current = containerRef.current.getBoundingClientRect(),
15682
+ top = _containerRef$current.top,
15683
+ bottom = _containerRef$current.bottom;
15684
+ var maxScrollTop = containerRef.current.scrollHeight - containerRef.current.clientHeight;
15685
+ var distanceFromTop = clientY - top;
15686
+ var distanceFromBottom = bottom - clientY;
15687
+ if (distanceFromTop < threshold && containerRef.current.scrollTop > 0) {
15688
+ containerRef.current.scrollTop -= scrollStep;
15689
+ animationFrameId.current = requestAnimationFrame(scroll);
15690
+ } else if (distanceFromBottom < threshold && containerRef.current.scrollTop < maxScrollTop) {
15691
+ containerRef.current.scrollTop += scrollStep;
15692
+ animationFrameId.current = requestAnimationFrame(scroll);
15693
+ } else {
15694
+ // Stop scrolling if neither condition is met
15695
+ stopScrolling();
15696
+ }
15697
+ }
15698
+ };
15699
+ var stopScrolling = function stopScrolling() {
15700
+ if (animationFrameId.current !== null) {
15701
+ cancelAnimationFrame(animationFrameId.current);
15702
+ animationFrameId.current = null;
15703
+ }
15704
+ };
15705
+ //@ts-ignore
15706
+ cancelAnimationFrame(animationFrameId.current); // Cancel any existing animation frame
15707
+ animationFrameId.current = requestAnimationFrame(scroll);
15708
+ }, [containerRef, threshold, scrollStep]);
15709
+ var stopScrolling = React.useCallback(function () {
15710
+ if (animationFrameId.current !== null) {
15711
+ cancelAnimationFrame(animationFrameId.current);
15712
+ animationFrameId.current = null;
15713
+ }
15714
+ }, []);
15715
+ return {
15716
+ startScrolling: startScrolling,
15717
+ stopScrolling: stopScrolling
15718
+ };
15719
+ };
15720
+
15672
15721
  var ShortcutsSetter = function ShortcutsSetter(_ref) {
15673
15722
  var setSettingShortcutIndex = _ref.setSettingShortcutIndex,
15674
15723
  settingShortcutIndex = _ref.settingShortcutIndex,
@@ -15970,11 +16019,47 @@ var ItemContainer$1 = function ItemContainer(_ref) {
15970
16019
  var _useState2 = React.useState(-1),
15971
16020
  settingShortcutIndex = _useState2[0],
15972
16021
  setSettingShortcutIndex = _useState2[1];
16022
+ var containerRef = React.useRef(null);
16023
+ var _useScrollOnDrag = useScrollOnDrag({
16024
+ containerRef: containerRef,
16025
+ threshold: 50,
16026
+ scrollStep: 4
16027
+ }),
16028
+ startScrolling = _useScrollOnDrag.startScrolling,
16029
+ stopScrolling = _useScrollOnDrag.stopScrolling;
15973
16030
  var handleSetShortcut = function handleSetShortcut(item, index) {
15974
16031
  if (item.type === shared.ItemType.Consumable || item.type === shared.ItemType.Tool) {
15975
16032
  setItemShortcut == null ? void 0 : setItemShortcut(item.key, index);
15976
16033
  }
15977
16034
  };
16035
+ var handleMouseMove = React.useCallback(function (e) {
16036
+ startScrolling(e.clientY);
16037
+ }, [startScrolling]);
16038
+ var onDragStartScrollingEvents = React.useCallback(function () {
16039
+ document.addEventListener('pointermove', handleMouseMove);
16040
+ document.addEventListener('pointerup', function () {
16041
+ stopScrolling();
16042
+ document.removeEventListener('pointermove', handleMouseMove);
16043
+ });
16044
+ }, [handleMouseMove, onItemDragStart, stopScrolling]);
16045
+ var onDragEndScrollingEvents = React.useCallback(function () {
16046
+ stopScrolling();
16047
+ document.removeEventListener('pointermove', handleMouseMove);
16048
+ }, [handleMouseMove, onItemDragStart, stopScrolling]);
16049
+ var onDragStart = function onDragStart(item, slotIndex, itemContainerType) {
16050
+ console.log('DRAG START');
16051
+ if (onItemDragStart) {
16052
+ onItemDragStart(item, slotIndex, itemContainerType);
16053
+ }
16054
+ onDragStartScrollingEvents();
16055
+ };
16056
+ var onDragEnd = function onDragEnd(quantity) {
16057
+ console.log('DRAG END');
16058
+ if (onItemDragEnd) {
16059
+ onItemDragEnd(quantity);
16060
+ }
16061
+ onDragEndScrollingEvents();
16062
+ };
15978
16063
  var onRenderSlots = function onRenderSlots() {
15979
16064
  var slots = [];
15980
16065
  for (var i = 0; i < itemContainer.slotQty; i++) {
@@ -15997,12 +16082,8 @@ var ItemContainer$1 = function ItemContainer(_ref) {
15997
16082
  onSelected: function onSelected(optionId, item) {
15998
16083
  if (_onSelected) _onSelected(optionId, item);
15999
16084
  },
16000
- onDragStart: function onDragStart(item, slotIndex, itemContainerType) {
16001
- if (onItemDragStart) onItemDragStart(item, slotIndex, itemContainerType);
16002
- },
16003
- onDragEnd: function onDragEnd(quantity) {
16004
- if (onItemDragEnd) onItemDragEnd(quantity);
16005
- },
16085
+ onDragStart: onDragStart,
16086
+ onDragEnd: onDragEnd,
16006
16087
  dragScale: scale,
16007
16088
  checkIfItemCanBeMoved: checkIfItemCanBeMoved,
16008
16089
  checkIfItemShouldDragEnd: checkIfItemShouldDragEnd,
@@ -16014,10 +16095,18 @@ var ItemContainer$1 = function ItemContainer(_ref) {
16014
16095
  });
16015
16096
  },
16016
16097
  onPlaceDrop: function onPlaceDrop(item, slotIndex, itemContainerType) {
16017
- if (onItemPlaceDrop) onItemPlaceDrop(item, slotIndex, itemContainerType);
16098
+ if (onItemPlaceDrop) {
16099
+ onItemPlaceDrop(item, slotIndex, itemContainerType);
16100
+ }
16101
+ console.log('PLACE DROP');
16102
+ onDragEndScrollingEvents();
16018
16103
  },
16019
16104
  onOutsideDrop: function onOutsideDrop(item, position) {
16020
- if (_onOutsideDrop) _onOutsideDrop(item, position);
16105
+ if (_onOutsideDrop) {
16106
+ _onOutsideDrop(item, position);
16107
+ }
16108
+ console.log('OUTSIDE DROP');
16109
+ onDragEndScrollingEvents();
16021
16110
  },
16022
16111
  atlasIMG: atlasIMG,
16023
16112
  atlasJSON: atlasJSON,
@@ -16048,7 +16137,8 @@ var ItemContainer$1 = function ItemContainer(_ref) {
16048
16137
  atlasIMG: atlasIMG,
16049
16138
  atlasJSON: atlasJSON
16050
16139
  }), React__default.createElement(ItemsContainer, {
16051
- className: "item-container-body"
16140
+ className: "item-container-body",
16141
+ ref: containerRef
16052
16142
  }, onRenderSlots())), quantitySelect.isOpen && React__default.createElement(ItemQuantitySelectorModal, {
16053
16143
  quantitySelect: quantitySelect,
16054
16144
  setQuantitySelect: setQuantitySelect