@rpg-engine/long-bow 0.7.67 → 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/ItemSlotTooltips.d.ts +1 -4
- 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 +45 -69
- 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 +45 -69
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Item/Inventory/ItemSlot.tsx +4 -37
- package/src/components/Item/Inventory/ItemSlotTooltips.tsx +3 -11
- package/src/components/Item/Inventory/context/DraggingContext.tsx +31 -5
- package/src/components/Item/Inventory/hooks/useItemSlotDragAndDrop.ts +11 -14
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from '@rpg-engine/shared';
|
|
10
10
|
|
|
11
11
|
import { observer } from 'mobx-react-lite';
|
|
12
|
-
import React, { useCallback, useEffect,
|
|
12
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
13
13
|
import Draggable from 'react-draggable';
|
|
14
14
|
import styled from 'styled-components';
|
|
15
15
|
import { IPosition } from '../../../types/eventTypes';
|
|
@@ -134,18 +134,6 @@ export const ItemSlot = React.memo(
|
|
|
134
134
|
[]
|
|
135
135
|
);
|
|
136
136
|
|
|
137
|
-
const isDraggingDisabled = useMemo(() => {
|
|
138
|
-
return (
|
|
139
|
-
contextMenuState.visible ||
|
|
140
|
-
onDragStart === undefined ||
|
|
141
|
-
onDragEnd === undefined
|
|
142
|
-
);
|
|
143
|
-
}, [contextMenuState.visible, onDragStart, onDragEnd]);
|
|
144
|
-
|
|
145
|
-
useEffect(() => {
|
|
146
|
-
console.log('isDraggingDisabled', isDraggingDisabled);
|
|
147
|
-
}, [isDraggingDisabled]);
|
|
148
|
-
|
|
149
137
|
const {
|
|
150
138
|
dragContainer,
|
|
151
139
|
dragState,
|
|
@@ -241,18 +229,6 @@ export const ItemSlot = React.memo(
|
|
|
241
229
|
[onMouseOut]
|
|
242
230
|
);
|
|
243
231
|
|
|
244
|
-
const [showTooltipDelayed, setShowTooltipDelayed] = useState(false);
|
|
245
|
-
|
|
246
|
-
//@ts-ignore
|
|
247
|
-
useEffect(() => {
|
|
248
|
-
if (tooltipState.visible && !isDraggingDisabled) {
|
|
249
|
-
const timer = setTimeout(() => setShowTooltipDelayed(true), 50);
|
|
250
|
-
return () => clearTimeout(timer);
|
|
251
|
-
} else {
|
|
252
|
-
setShowTooltipDelayed(false);
|
|
253
|
-
}
|
|
254
|
-
}, [tooltipState.visible, isDraggingDisabled]);
|
|
255
|
-
|
|
256
232
|
return (
|
|
257
233
|
<Container
|
|
258
234
|
isDraggingItem={!!draggingItem}
|
|
@@ -274,7 +250,6 @@ export const ItemSlot = React.memo(
|
|
|
274
250
|
}
|
|
275
251
|
}}
|
|
276
252
|
onTouchEnd={e => {
|
|
277
|
-
handleInteractionEnd(e);
|
|
278
253
|
const { clientX, clientY } = e.changedTouches[0];
|
|
279
254
|
const simulatedEvent = new MouseEvent('mouseup', {
|
|
280
255
|
clientX,
|
|
@@ -299,7 +274,7 @@ export const ItemSlot = React.memo(
|
|
|
299
274
|
axis={isSelectingShortcut ? 'none' : 'both'}
|
|
300
275
|
defaultClassName={item ? 'draggable' : 'empty-slot'}
|
|
301
276
|
scale={dragScale}
|
|
302
|
-
disabled={
|
|
277
|
+
disabled={onDragStart === undefined || onDragEnd === undefined}
|
|
303
278
|
onStop={onDraggableStop}
|
|
304
279
|
onStart={onDraggableStart}
|
|
305
280
|
onDrag={onDraggableProgress}
|
|
@@ -323,13 +298,8 @@ export const ItemSlot = React.memo(
|
|
|
323
298
|
onMouseEnter={() => {
|
|
324
299
|
setTooltipState(prev => ({ ...prev, visible: true }));
|
|
325
300
|
}}
|
|
326
|
-
onMouseLeave={
|
|
327
|
-
|
|
328
|
-
!e.relatedTarget ||
|
|
329
|
-
!dragContainer.current?.contains(e.relatedTarget as Node)
|
|
330
|
-
) {
|
|
331
|
-
setTooltipState(prev => ({ ...prev, visible: false }));
|
|
332
|
-
}
|
|
301
|
+
onMouseLeave={() => {
|
|
302
|
+
setTooltipState(prev => ({ ...prev, visible: false }));
|
|
333
303
|
}}
|
|
334
304
|
>
|
|
335
305
|
<ItemSlotRenderer
|
|
@@ -359,9 +329,6 @@ export const ItemSlot = React.memo(
|
|
|
359
329
|
atlasIMG={atlasIMG}
|
|
360
330
|
atlasJSON={atlasJSON}
|
|
361
331
|
equipmentSet={equipmentSet}
|
|
362
|
-
isDragging={!!draggingItem}
|
|
363
|
-
isSelectingShortcut={!!isSelectingShortcut}
|
|
364
|
-
showTooltipDelayed={showTooltipDelayed}
|
|
365
332
|
/>
|
|
366
333
|
</Container>
|
|
367
334
|
);
|
|
@@ -20,9 +20,6 @@ interface IProps {
|
|
|
20
20
|
atlasIMG: any;
|
|
21
21
|
atlasJSON: any;
|
|
22
22
|
equipmentSet?: IEquipmentSet | null;
|
|
23
|
-
isDragging: boolean;
|
|
24
|
-
isSelectingShortcut: boolean;
|
|
25
|
-
showTooltipDelayed: boolean;
|
|
26
23
|
}
|
|
27
24
|
|
|
28
25
|
export const ItemSlotToolTips = ({
|
|
@@ -39,15 +36,10 @@ export const ItemSlotToolTips = ({
|
|
|
39
36
|
atlasIMG,
|
|
40
37
|
atlasJSON,
|
|
41
38
|
equipmentSet,
|
|
42
|
-
isDragging,
|
|
43
|
-
isSelectingShortcut,
|
|
44
|
-
showTooltipDelayed,
|
|
45
39
|
}: IProps): JSX.Element => {
|
|
46
|
-
const canShow = !isDragging || !isSelectingShortcut || showTooltipDelayed;
|
|
47
|
-
|
|
48
40
|
return (
|
|
49
41
|
<>
|
|
50
|
-
{tooltipState.visible && item && !isFocused &&
|
|
42
|
+
{tooltipState.visible && item && !isFocused && (
|
|
51
43
|
<ItemTooltip
|
|
52
44
|
item={item}
|
|
53
45
|
atlasIMG={atlasIMG}
|
|
@@ -56,7 +48,7 @@ export const ItemSlotToolTips = ({
|
|
|
56
48
|
/>
|
|
57
49
|
)}
|
|
58
50
|
|
|
59
|
-
{tooltipState.mobileVisible && item &&
|
|
51
|
+
{tooltipState.mobileVisible && item && (
|
|
60
52
|
<MobileItemTooltip
|
|
61
53
|
item={item}
|
|
62
54
|
atlasIMG={atlasIMG}
|
|
@@ -76,7 +68,7 @@ export const ItemSlotToolTips = ({
|
|
|
76
68
|
/>
|
|
77
69
|
)}
|
|
78
70
|
|
|
79
|
-
{!isContextMenuDisabled && contextMenuState.visible && contextActions &&
|
|
71
|
+
{!isContextMenuDisabled && contextMenuState.visible && contextActions && (
|
|
80
72
|
<RelativeListMenu
|
|
81
73
|
options={contextActions}
|
|
82
74
|
onSelected={(optionId: string) => {
|
|
@@ -1,26 +1,52 @@
|
|
|
1
1
|
import { IItem } from '@rpg-engine/shared';
|
|
2
2
|
import React, { createContext, useContext, useState } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export interface DragState {
|
|
5
|
+
isFocused: boolean;
|
|
6
|
+
wasDragged: boolean;
|
|
7
|
+
position: { x: number; y: number };
|
|
8
|
+
dropPosition: { x: number; y: number } | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface DraggingContextType {
|
|
5
12
|
item: IItem | null;
|
|
6
13
|
setDraggingItem: React.Dispatch<React.SetStateAction<IItem | null>>;
|
|
7
|
-
|
|
14
|
+
dragState: DragState;
|
|
15
|
+
setDragState: React.Dispatch<React.SetStateAction<DragState>>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const DraggingContext = createContext<DraggingContextType>({
|
|
8
19
|
item: null,
|
|
9
20
|
setDraggingItem: () => {},
|
|
21
|
+
dragState: {
|
|
22
|
+
isFocused: false,
|
|
23
|
+
wasDragged: false,
|
|
24
|
+
position: { x: 0, y: 0 },
|
|
25
|
+
dropPosition: null,
|
|
26
|
+
},
|
|
27
|
+
setDragState: () => {},
|
|
10
28
|
});
|
|
11
29
|
|
|
12
|
-
export const useDragging = () => useContext(DraggingContext);
|
|
13
|
-
|
|
14
30
|
interface IProps {
|
|
15
31
|
children: React.ReactNode;
|
|
16
32
|
}
|
|
17
33
|
|
|
18
34
|
export const DraggingProvider = ({ children }: IProps) => {
|
|
19
35
|
const [item, setDraggingItem] = useState<IItem | null>(null);
|
|
36
|
+
const [dragState, setDragState] = useState<DragState>({
|
|
37
|
+
isFocused: false,
|
|
38
|
+
wasDragged: false,
|
|
39
|
+
position: { x: 0, y: 0 },
|
|
40
|
+
dropPosition: null,
|
|
41
|
+
});
|
|
20
42
|
|
|
21
43
|
return (
|
|
22
|
-
<DraggingContext.Provider
|
|
44
|
+
<DraggingContext.Provider
|
|
45
|
+
value={{ item, setDraggingItem, dragState, setDragState }}
|
|
46
|
+
>
|
|
23
47
|
{children}
|
|
24
48
|
</DraggingContext.Provider>
|
|
25
49
|
);
|
|
26
50
|
};
|
|
51
|
+
|
|
52
|
+
export const useDragging = () => useContext(DraggingContext);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IItem, ItemContainerType, ItemType } from '@rpg-engine/shared';
|
|
2
|
-
import { useCallback, useEffect, useRef
|
|
2
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
3
3
|
import { DraggableEventHandler } from 'react-draggable';
|
|
4
4
|
import { useDragging } from '../context/DraggingContext';
|
|
5
|
-
import { ContextMenuState,
|
|
5
|
+
import { ContextMenuState, TooltipState } from '../ItemSlot';
|
|
6
6
|
|
|
7
7
|
interface IUseItemSlotDragAndDrop {
|
|
8
8
|
isDepotSystem: boolean;
|
|
@@ -54,14 +54,12 @@ export const useItemSlotDragAndDrop = ({
|
|
|
54
54
|
setContextMenuState,
|
|
55
55
|
}: IUseItemSlotDragAndDrop) => {
|
|
56
56
|
const dragContainer = useRef<HTMLDivElement>(null);
|
|
57
|
-
const {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
dropPosition: null,
|
|
64
|
-
});
|
|
57
|
+
const {
|
|
58
|
+
item: draggingItem,
|
|
59
|
+
setDraggingItem,
|
|
60
|
+
dragState,
|
|
61
|
+
setDragState,
|
|
62
|
+
} = useDragging();
|
|
65
63
|
|
|
66
64
|
useEffect(() => {
|
|
67
65
|
setDragState(prev => ({
|
|
@@ -69,7 +67,7 @@ export const useItemSlotDragAndDrop = ({
|
|
|
69
67
|
position: { x: 0, y: 0 },
|
|
70
68
|
isFocused: false,
|
|
71
69
|
}));
|
|
72
|
-
}, [item, isDepotSystem]);
|
|
70
|
+
}, [item, isDepotSystem, setDragState]);
|
|
73
71
|
|
|
74
72
|
useEffect(() => {
|
|
75
73
|
if (onDrop && item && dragState.dropPosition) {
|
|
@@ -91,14 +89,13 @@ export const useItemSlotDragAndDrop = ({
|
|
|
91
89
|
}, []);
|
|
92
90
|
|
|
93
91
|
const resetDragState = useCallback(() => {
|
|
94
|
-
setTooltipState(prev => ({ ...prev, visible: false }));
|
|
95
92
|
setDragState(prev => ({
|
|
96
93
|
...prev,
|
|
97
94
|
wasDragged: false,
|
|
98
95
|
isFocused: false,
|
|
99
96
|
position: { x: 0, y: 0 },
|
|
100
97
|
}));
|
|
101
|
-
}, [setTooltipState]);
|
|
98
|
+
}, [setTooltipState, setDragState]);
|
|
102
99
|
|
|
103
100
|
const handleSuccessfulDrag = useCallback(
|
|
104
101
|
(quantity?: number) => {
|
|
@@ -127,7 +124,7 @@ export const useItemSlotDragAndDrop = ({
|
|
|
127
124
|
setDraggingItem(item);
|
|
128
125
|
}
|
|
129
126
|
},
|
|
130
|
-
[dragState.position, draggingItem, item, setDraggingItem]
|
|
127
|
+
[dragState.position, draggingItem, item, setDraggingItem, setDragState]
|
|
131
128
|
);
|
|
132
129
|
|
|
133
130
|
const onDraggableStop: DraggableEventHandler = useCallback(
|