@rpg-engine/long-bow 0.7.66 → 0.7.68
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.
- package/dist/components/Item/Inventory/context/DraggingContext.d.ts +17 -2
- package/dist/components/Item/Inventory/hooks/useItemSlotDragAndDrop.d.ts +2 -2
- package/dist/long-bow.cjs.development.js +41 -34
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +41 -34
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Item/Inventory/ItemSlot.tsx +0 -6
- package/src/components/Item/Inventory/context/DraggingContext.tsx +31 -5
- package/src/components/Item/Inventory/hooks/useItemSlotDragAndDrop.ts +17 -37
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { IItem } from '@rpg-engine/shared';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
export
|
|
3
|
+
export interface DragState {
|
|
4
|
+
isFocused: boolean;
|
|
5
|
+
wasDragged: boolean;
|
|
6
|
+
position: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
};
|
|
10
|
+
dropPosition: {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
} | null;
|
|
14
|
+
}
|
|
15
|
+
interface DraggingContextType {
|
|
4
16
|
item: IItem | null;
|
|
5
17
|
setDraggingItem: React.Dispatch<React.SetStateAction<IItem | null>>;
|
|
6
|
-
|
|
18
|
+
dragState: DragState;
|
|
19
|
+
setDragState: React.Dispatch<React.SetStateAction<DragState>>;
|
|
20
|
+
}
|
|
7
21
|
interface IProps {
|
|
8
22
|
children: React.ReactNode;
|
|
9
23
|
}
|
|
10
24
|
export declare const DraggingProvider: ({ children }: IProps) => JSX.Element;
|
|
25
|
+
export declare const useDragging: () => DraggingContextType;
|
|
11
26
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { IItem, ItemContainerType, ItemType } from '@rpg-engine/shared';
|
|
3
3
|
import { DraggableEventHandler } from 'react-draggable';
|
|
4
|
-
import { ContextMenuState,
|
|
4
|
+
import { ContextMenuState, TooltipState } from '../ItemSlot';
|
|
5
5
|
interface IUseItemSlotDragAndDrop {
|
|
6
6
|
isDepotSystem: boolean;
|
|
7
7
|
item: IItem;
|
|
@@ -26,7 +26,7 @@ interface IUseItemSlotDragAndDrop {
|
|
|
26
26
|
}
|
|
27
27
|
export declare const useItemSlotDragAndDrop: ({ isDepotSystem, item, onDrop, onDragEnd, checkIfItemCanBeMoved, checkIfItemShouldDragEnd, setItemShortcut, isSelectingShortcut, onDragStart, onPointerDown, containerType, slotIndex, openQuantitySelector, isContextMenuDisabled, setTooltipState, setContextMenuState, }: IUseItemSlotDragAndDrop) => {
|
|
28
28
|
dragContainer: import("react").RefObject<HTMLDivElement>;
|
|
29
|
-
dragState: DragState;
|
|
29
|
+
dragState: import("../context/DraggingContext").DragState;
|
|
30
30
|
draggingItem: IItem | null;
|
|
31
31
|
setDraggingItem: import("react").Dispatch<import("react").SetStateAction<IItem | null>>;
|
|
32
32
|
getContainerBounds: () => {
|
|
@@ -27723,23 +27723,46 @@ var ItemSlotToolTips = function ItemSlotToolTips(_ref) {
|
|
|
27723
27723
|
|
|
27724
27724
|
var DraggingContext = /*#__PURE__*/React.createContext({
|
|
27725
27725
|
item: null,
|
|
27726
|
-
setDraggingItem: function setDraggingItem() {}
|
|
27726
|
+
setDraggingItem: function setDraggingItem() {},
|
|
27727
|
+
dragState: {
|
|
27728
|
+
isFocused: false,
|
|
27729
|
+
wasDragged: false,
|
|
27730
|
+
position: {
|
|
27731
|
+
x: 0,
|
|
27732
|
+
y: 0
|
|
27733
|
+
},
|
|
27734
|
+
dropPosition: null
|
|
27735
|
+
},
|
|
27736
|
+
setDragState: function setDragState() {}
|
|
27727
27737
|
});
|
|
27728
|
-
var useDragging = function useDragging() {
|
|
27729
|
-
return React.useContext(DraggingContext);
|
|
27730
|
-
};
|
|
27731
27738
|
var DraggingProvider = function DraggingProvider(_ref) {
|
|
27732
27739
|
var children = _ref.children;
|
|
27733
27740
|
var _useState = React.useState(null),
|
|
27734
27741
|
item = _useState[0],
|
|
27735
27742
|
setDraggingItem = _useState[1];
|
|
27743
|
+
var _useState2 = React.useState({
|
|
27744
|
+
isFocused: false,
|
|
27745
|
+
wasDragged: false,
|
|
27746
|
+
position: {
|
|
27747
|
+
x: 0,
|
|
27748
|
+
y: 0
|
|
27749
|
+
},
|
|
27750
|
+
dropPosition: null
|
|
27751
|
+
}),
|
|
27752
|
+
dragState = _useState2[0],
|
|
27753
|
+
setDragState = _useState2[1];
|
|
27736
27754
|
return React__default.createElement(DraggingContext.Provider, {
|
|
27737
27755
|
value: {
|
|
27738
27756
|
item: item,
|
|
27739
|
-
setDraggingItem: setDraggingItem
|
|
27757
|
+
setDraggingItem: setDraggingItem,
|
|
27758
|
+
dragState: dragState,
|
|
27759
|
+
setDragState: setDragState
|
|
27740
27760
|
}
|
|
27741
27761
|
}, children);
|
|
27742
27762
|
};
|
|
27763
|
+
var useDragging = function useDragging() {
|
|
27764
|
+
return React.useContext(DraggingContext);
|
|
27765
|
+
};
|
|
27743
27766
|
|
|
27744
27767
|
var useItemSlotDragAndDrop = function useItemSlotDragAndDrop(_ref) {
|
|
27745
27768
|
var isDepotSystem = _ref.isDepotSystem,
|
|
@@ -27761,18 +27784,9 @@ var useItemSlotDragAndDrop = function useItemSlotDragAndDrop(_ref) {
|
|
|
27761
27784
|
var dragContainer = React.useRef(null);
|
|
27762
27785
|
var _useDragging = useDragging(),
|
|
27763
27786
|
draggingItem = _useDragging.item,
|
|
27764
|
-
setDraggingItem = _useDragging.setDraggingItem
|
|
27765
|
-
|
|
27766
|
-
|
|
27767
|
-
wasDragged: false,
|
|
27768
|
-
position: {
|
|
27769
|
-
x: 0,
|
|
27770
|
-
y: 0
|
|
27771
|
-
},
|
|
27772
|
-
dropPosition: null
|
|
27773
|
-
}),
|
|
27774
|
-
dragState = _useState[0],
|
|
27775
|
-
setDragState = _useState[1];
|
|
27787
|
+
setDraggingItem = _useDragging.setDraggingItem,
|
|
27788
|
+
dragState = _useDragging.dragState,
|
|
27789
|
+
setDragState = _useDragging.setDragState;
|
|
27776
27790
|
React.useEffect(function () {
|
|
27777
27791
|
setDragState(function (prev) {
|
|
27778
27792
|
return _extends({}, prev, {
|
|
@@ -27783,7 +27797,7 @@ var useItemSlotDragAndDrop = function useItemSlotDragAndDrop(_ref) {
|
|
|
27783
27797
|
isFocused: false
|
|
27784
27798
|
});
|
|
27785
27799
|
});
|
|
27786
|
-
}, [item, isDepotSystem]);
|
|
27800
|
+
}, [item, isDepotSystem, setDragState]);
|
|
27787
27801
|
React.useEffect(function () {
|
|
27788
27802
|
if (onDrop && item && dragState.dropPosition) {
|
|
27789
27803
|
onDrop(item, dragState.dropPosition);
|
|
@@ -27811,11 +27825,6 @@ var useItemSlotDragAndDrop = function useItemSlotDragAndDrop(_ref) {
|
|
|
27811
27825
|
};
|
|
27812
27826
|
}, []);
|
|
27813
27827
|
var resetDragState = React.useCallback(function () {
|
|
27814
|
-
setTooltipState(function (prev) {
|
|
27815
|
-
return _extends({}, prev, {
|
|
27816
|
-
visible: false
|
|
27817
|
-
});
|
|
27818
|
-
});
|
|
27819
27828
|
setDragState(function (prev) {
|
|
27820
27829
|
return _extends({}, prev, {
|
|
27821
27830
|
wasDragged: false,
|
|
@@ -27826,8 +27835,7 @@ var useItemSlotDragAndDrop = function useItemSlotDragAndDrop(_ref) {
|
|
|
27826
27835
|
}
|
|
27827
27836
|
});
|
|
27828
27837
|
});
|
|
27829
|
-
|
|
27830
|
-
}, [setTooltipState]);
|
|
27838
|
+
}, [setTooltipState, setDragState]);
|
|
27831
27839
|
var handleSuccessfulDrag = React.useCallback(function (quantity) {
|
|
27832
27840
|
resetDragState();
|
|
27833
27841
|
if (quantity !== -1 && item) {
|
|
@@ -27844,21 +27852,22 @@ var useItemSlotDragAndDrop = function useItemSlotDragAndDrop(_ref) {
|
|
|
27844
27852
|
var _dragState$position = dragState.position,
|
|
27845
27853
|
x = _dragState$position.x,
|
|
27846
27854
|
y = _dragState$position.y;
|
|
27847
|
-
if (Math.abs(data.x - x) >
|
|
27855
|
+
if (Math.abs(data.x - x) > 5 || Math.abs(data.y - y) > 5) {
|
|
27848
27856
|
setDragState(function (prev) {
|
|
27849
27857
|
return _extends({}, prev, {
|
|
27850
27858
|
wasDragged: true,
|
|
27851
27859
|
isFocused: true
|
|
27852
27860
|
});
|
|
27853
27861
|
});
|
|
27854
|
-
} else {
|
|
27855
|
-
resetDragState();
|
|
27856
27862
|
}
|
|
27857
27863
|
if (!draggingItem) {
|
|
27858
27864
|
setDraggingItem(item);
|
|
27859
27865
|
}
|
|
27860
|
-
}, [dragState.position, draggingItem, item, setDraggingItem]);
|
|
27866
|
+
}, [dragState.position, draggingItem, item, setDraggingItem, setDragState]);
|
|
27861
27867
|
var onDraggableStop = React.useCallback(function (e, data) {
|
|
27868
|
+
setTimeout(function () {
|
|
27869
|
+
setDraggingItem(null);
|
|
27870
|
+
}, 50);
|
|
27862
27871
|
var target = e.target;
|
|
27863
27872
|
if (!target) return;
|
|
27864
27873
|
target.classList.remove('react-draggable-dragging');
|
|
@@ -27901,14 +27910,13 @@ var useItemSlotDragAndDrop = function useItemSlotDragAndDrop(_ref) {
|
|
|
27901
27910
|
}, 50);
|
|
27902
27911
|
} else if (item) {
|
|
27903
27912
|
var isTouch = e.type === 'touchend';
|
|
27904
|
-
|
|
27905
|
-
if (!isContextMenuDisabled && isTouch && !isSelectingShortcut && !draggingItem && !dragState.wasDragged && !dragState.isFocused) {
|
|
27913
|
+
if (!isContextMenuDisabled && isTouch && !isSelectingShortcut && !draggingItem) {
|
|
27906
27914
|
setTooltipState(function (prev) {
|
|
27907
27915
|
return _extends({}, prev, {
|
|
27908
27916
|
mobileVisible: true
|
|
27909
27917
|
});
|
|
27910
27918
|
});
|
|
27911
|
-
} else if (!isContextMenuDisabled && !isSelectingShortcut && !isTouch
|
|
27919
|
+
} else if (!isContextMenuDisabled && !isSelectingShortcut && !isTouch) {
|
|
27912
27920
|
var event = e;
|
|
27913
27921
|
setContextMenuState(function (prev) {
|
|
27914
27922
|
return {
|
|
@@ -28204,7 +28212,6 @@ var ItemSlot = /*#__PURE__*/React__default.memo( /*#__PURE__*/mobxReactLite.obse
|
|
|
28204
28212
|
},
|
|
28205
28213
|
onTouchEnd: function onTouchEnd(e) {
|
|
28206
28214
|
var _document$elementFrom2;
|
|
28207
|
-
handleInteractionEnd(e);
|
|
28208
28215
|
var _e$changedTouches$ = e.changedTouches[0],
|
|
28209
28216
|
clientX = _e$changedTouches$.clientX,
|
|
28210
28217
|
clientY = _e$changedTouches$.clientY;
|
|
@@ -28283,7 +28290,7 @@ var ItemSlot = /*#__PURE__*/React__default.memo( /*#__PURE__*/mobxReactLite.obse
|
|
|
28283
28290
|
var Container$b = /*#__PURE__*/styled__default.div.withConfig({
|
|
28284
28291
|
displayName: "ItemSlot__Container",
|
|
28285
28292
|
componentId: "sc-l2j5ef-0"
|
|
28286
|
-
})(["
|
|
28293
|
+
})(["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) {
|
|
28287
28294
|
var isDraggingItem = _ref3.isDraggingItem;
|
|
28288
28295
|
return isDraggingItem ? 0 : 1;
|
|
28289
28296
|
}, function (_ref4) {
|