@rpg-engine/long-bow 0.5.36 → 0.5.37

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