@rpg-engine/long-bow 0.7.68 → 0.7.71
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/ItemSlot.d.ts +2 -17
- package/dist/components/Item/Inventory/ItemSlotTooltips.d.ts +10 -7
- package/dist/components/Item/Inventory/context/DraggingContext.d.ts +2 -17
- package/dist/long-bow.cjs.development.js +334 -354
- 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 +335 -355
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Item/Inventory/ItemContainer.tsx +2 -2
- package/src/components/Item/Inventory/ItemSlot.tsx +441 -252
- package/src/components/Item/Inventory/ItemSlotTooltips.tsx +22 -18
- package/src/components/Item/Inventory/context/DraggingContext.tsx +5 -31
- package/src/mocks/skills.mocks.ts +0 -4
- package/src/stories/UI/containers/ItemContainer.stories.tsx +3 -30
- package/dist/components/Item/Inventory/hooks/useItemSlotDragAndDrop.d.ts +0 -43
- package/src/components/Item/Inventory/hooks/useItemSlotDragAndDrop.ts +0 -228
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { IEquipmentSet, IItem } from '@rpg-engine/shared';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { IPosition } from '../../../types/eventTypes';
|
|
3
4
|
import { RelativeListMenu } from '../../RelativeListMenu';
|
|
4
5
|
import { ItemTooltip } from '../Cards/ItemTooltip';
|
|
5
6
|
import { MobileItemTooltip } from '../Cards/MobileItemTooltip';
|
|
6
7
|
import { IContextMenuItem } from './itemContainerHelper';
|
|
7
|
-
import type { ContextMenuState, TooltipState } from './ItemSlot';
|
|
8
8
|
|
|
9
9
|
interface IProps {
|
|
10
|
-
|
|
11
|
-
setTooltipState: React.Dispatch<React.SetStateAction<TooltipState>>;
|
|
12
|
-
contextMenuState: ContextMenuState;
|
|
13
|
-
setContextMenuState: React.Dispatch<React.SetStateAction<ContextMenuState>>;
|
|
10
|
+
isTooltipVisible: boolean;
|
|
14
11
|
isFocused: boolean;
|
|
12
|
+
isContextMenuVisible: boolean;
|
|
15
13
|
isContextMenuDisabled: boolean;
|
|
16
14
|
item: IItem | null;
|
|
15
|
+
isTooltipMobileVisible: boolean;
|
|
17
16
|
contextActions: IContextMenuItem[];
|
|
17
|
+
contextMenuPosition: IPosition;
|
|
18
18
|
dragScale: number | undefined;
|
|
19
|
+
setIsContextMenuVisible: (visible: boolean) => void;
|
|
20
|
+
setIsTooltipMobileVisible: (visible: boolean) => void;
|
|
21
|
+
setIsTooltipVisible: (visible: boolean) => void;
|
|
19
22
|
onSelected?: (optionId: string, item: IItem) => void;
|
|
20
23
|
atlasIMG: any;
|
|
21
24
|
atlasJSON: any;
|
|
@@ -23,15 +26,17 @@ interface IProps {
|
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
export const ItemSlotToolTips = ({
|
|
26
|
-
|
|
27
|
-
setTooltipState,
|
|
28
|
-
contextMenuState,
|
|
29
|
-
setContextMenuState,
|
|
29
|
+
isTooltipVisible,
|
|
30
30
|
isFocused,
|
|
31
|
+
isContextMenuVisible,
|
|
31
32
|
isContextMenuDisabled,
|
|
32
33
|
item,
|
|
33
34
|
contextActions,
|
|
35
|
+
contextMenuPosition,
|
|
34
36
|
dragScale,
|
|
37
|
+
setIsContextMenuVisible,
|
|
38
|
+
setIsTooltipMobileVisible,
|
|
39
|
+
isTooltipMobileVisible,
|
|
35
40
|
onSelected,
|
|
36
41
|
atlasIMG,
|
|
37
42
|
atlasJSON,
|
|
@@ -39,7 +44,7 @@ export const ItemSlotToolTips = ({
|
|
|
39
44
|
}: IProps): JSX.Element => {
|
|
40
45
|
return (
|
|
41
46
|
<>
|
|
42
|
-
{
|
|
47
|
+
{isTooltipVisible && item && !isFocused && (
|
|
43
48
|
<ItemTooltip
|
|
44
49
|
item={item}
|
|
45
50
|
atlasIMG={atlasIMG}
|
|
@@ -48,19 +53,19 @@ export const ItemSlotToolTips = ({
|
|
|
48
53
|
/>
|
|
49
54
|
)}
|
|
50
55
|
|
|
51
|
-
{
|
|
56
|
+
{isTooltipMobileVisible && item && (
|
|
52
57
|
<MobileItemTooltip
|
|
53
58
|
item={item}
|
|
54
59
|
atlasIMG={atlasIMG}
|
|
55
60
|
atlasJSON={atlasJSON}
|
|
56
61
|
equipmentSet={equipmentSet}
|
|
57
62
|
closeTooltip={() => {
|
|
58
|
-
|
|
63
|
+
setIsTooltipMobileVisible(false);
|
|
59
64
|
}}
|
|
60
65
|
scale={dragScale}
|
|
61
66
|
options={contextActions}
|
|
62
67
|
onSelected={(optionId: string) => {
|
|
63
|
-
|
|
68
|
+
setIsContextMenuVisible(false);
|
|
64
69
|
if (item) {
|
|
65
70
|
onSelected?.(optionId, item);
|
|
66
71
|
}
|
|
@@ -68,20 +73,19 @@ export const ItemSlotToolTips = ({
|
|
|
68
73
|
/>
|
|
69
74
|
)}
|
|
70
75
|
|
|
71
|
-
{!isContextMenuDisabled &&
|
|
76
|
+
{!isContextMenuDisabled && isContextMenuVisible && contextActions && (
|
|
72
77
|
<RelativeListMenu
|
|
73
78
|
options={contextActions}
|
|
74
79
|
onSelected={(optionId: string) => {
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
setIsContextMenuVisible(false);
|
|
77
81
|
if (item) {
|
|
78
82
|
onSelected?.(optionId, item);
|
|
79
83
|
}
|
|
80
84
|
}}
|
|
81
85
|
onOutsideClick={() => {
|
|
82
|
-
|
|
86
|
+
setIsContextMenuVisible(false);
|
|
83
87
|
}}
|
|
84
|
-
pos={
|
|
88
|
+
pos={contextMenuPosition}
|
|
85
89
|
/>
|
|
86
90
|
)}
|
|
87
91
|
</>
|
|
@@ -1,52 +1,26 @@
|
|
|
1
1
|
import { IItem } from '@rpg-engine/shared';
|
|
2
2
|
import React, { createContext, useContext, useState } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
isFocused: boolean;
|
|
6
|
-
wasDragged: boolean;
|
|
7
|
-
position: { x: number; y: number };
|
|
8
|
-
dropPosition: { x: number; y: number } | null;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface DraggingContextType {
|
|
4
|
+
const DraggingContext = createContext<{
|
|
12
5
|
item: IItem | null;
|
|
13
6
|
setDraggingItem: React.Dispatch<React.SetStateAction<IItem | null>>;
|
|
14
|
-
|
|
15
|
-
setDragState: React.Dispatch<React.SetStateAction<DragState>>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const DraggingContext = createContext<DraggingContextType>({
|
|
7
|
+
}>({
|
|
19
8
|
item: null,
|
|
20
9
|
setDraggingItem: () => {},
|
|
21
|
-
dragState: {
|
|
22
|
-
isFocused: false,
|
|
23
|
-
wasDragged: false,
|
|
24
|
-
position: { x: 0, y: 0 },
|
|
25
|
-
dropPosition: null,
|
|
26
|
-
},
|
|
27
|
-
setDragState: () => {},
|
|
28
10
|
});
|
|
29
11
|
|
|
12
|
+
export const useDragging = () => useContext(DraggingContext);
|
|
13
|
+
|
|
30
14
|
interface IProps {
|
|
31
15
|
children: React.ReactNode;
|
|
32
16
|
}
|
|
33
17
|
|
|
34
18
|
export const DraggingProvider = ({ children }: IProps) => {
|
|
35
19
|
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
|
-
});
|
|
42
20
|
|
|
43
21
|
return (
|
|
44
|
-
<DraggingContext.Provider
|
|
45
|
-
value={{ item, setDraggingItem, dragState, setDragState }}
|
|
46
|
-
>
|
|
22
|
+
<DraggingContext.Provider value={{ item, setDraggingItem }}>
|
|
47
23
|
{children}
|
|
48
24
|
</DraggingContext.Provider>
|
|
49
25
|
);
|
|
50
26
|
};
|
|
51
|
-
|
|
52
|
-
export const useDragging = () => useContext(DraggingContext);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IItem, ItemContainerType
|
|
1
|
+
import { IItem, ItemContainerType } from '@rpg-engine/shared';
|
|
2
2
|
import { Meta, Story } from '@storybook/react';
|
|
3
3
|
import React, { useState } from 'react';
|
|
4
4
|
import {
|
|
@@ -21,26 +21,10 @@ const meta: Meta = {
|
|
|
21
21
|
|
|
22
22
|
export default meta;
|
|
23
23
|
|
|
24
|
-
const onMouseOver = (_event: any, slotIndex: number, item: IItem | null) => {
|
|
25
|
-
if (!item) {
|
|
26
|
-
console.log(`Free at ${slotIndex}`);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
console.log(`${item.name} at ${slotIndex}`);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
24
|
const onSelected = (payload: string, item: IItem) => {
|
|
33
25
|
console.log('onSelected', payload, item);
|
|
34
26
|
};
|
|
35
27
|
|
|
36
|
-
const onItemClick = (
|
|
37
|
-
item: IItem,
|
|
38
|
-
ItemType: ItemType,
|
|
39
|
-
itemContainerType: ItemContainerType | null
|
|
40
|
-
) => {
|
|
41
|
-
console.log(item, ItemType, itemContainerType, 'was clicked!');
|
|
42
|
-
};
|
|
43
|
-
|
|
44
28
|
// THIS IS ONLY LONG-BOW EXAMPLE FOR DRAG AND DROP
|
|
45
29
|
let dragItem: IItem | null = null;
|
|
46
30
|
let dropItem: IItem | null = null;
|
|
@@ -69,9 +53,9 @@ const Template: Story<IItemContainerProps & ITemplateProps> = ({
|
|
|
69
53
|
<ItemContainer
|
|
70
54
|
itemContainer={itemContainer}
|
|
71
55
|
onClose={() => console.log('closing item container')}
|
|
72
|
-
onMouseOver={
|
|
56
|
+
onMouseOver={() => {}}
|
|
73
57
|
onSelected={onSelected}
|
|
74
|
-
onItemClick={
|
|
58
|
+
onItemClick={() => {}}
|
|
75
59
|
checkIfItemCanBeMoved={() => allowedToDrop}
|
|
76
60
|
onItemDragEnd={quantity => {
|
|
77
61
|
// THIS IS ONLY LONG-BOW EXAMPLE FOR DRAG AND DROP
|
|
@@ -115,22 +99,11 @@ const Template: Story<IItemContainerProps & ITemplateProps> = ({
|
|
|
115
99
|
onItemPlaceDrop={(item, slotIndex) => {
|
|
116
100
|
// THIS IS ONLY LONG-BOW EXAMPLE FOR DRAG AND DROP
|
|
117
101
|
|
|
118
|
-
console.log({
|
|
119
|
-
item: item?.name,
|
|
120
|
-
sI: slotIndex,
|
|
121
|
-
dragK: dragItem?.key,
|
|
122
|
-
itemK: item?.key,
|
|
123
|
-
dragSlot,
|
|
124
|
-
slotIndex,
|
|
125
|
-
});
|
|
126
|
-
|
|
127
102
|
if (!item || (dragItem?.key === item?.key && dragSlot !== slotIndex)) {
|
|
128
|
-
console.log('allow');
|
|
129
103
|
allowedToDrop = true;
|
|
130
104
|
dropSlot = slotIndex;
|
|
131
105
|
dropItem = item ? item : null;
|
|
132
106
|
} else {
|
|
133
|
-
console.log('not allowing drop');
|
|
134
107
|
allowedToDrop = false;
|
|
135
108
|
dropSlot = -1;
|
|
136
109
|
dropItem = null;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { IItem, ItemContainerType, ItemType } from '@rpg-engine/shared';
|
|
3
|
-
import { DraggableEventHandler } from 'react-draggable';
|
|
4
|
-
import { ContextMenuState, TooltipState } from '../ItemSlot';
|
|
5
|
-
interface IUseItemSlotDragAndDrop {
|
|
6
|
-
isDepotSystem: boolean;
|
|
7
|
-
item: IItem;
|
|
8
|
-
onDrop: (item: IItem, dropPosition: {
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
}) => void;
|
|
12
|
-
onDragEnd?: (quantity?: number) => void;
|
|
13
|
-
checkIfItemCanBeMoved?: () => boolean;
|
|
14
|
-
checkIfItemShouldDragEnd?: () => boolean;
|
|
15
|
-
setItemShortcut?: (item: IItem, index: number) => void;
|
|
16
|
-
isSelectingShortcut?: boolean;
|
|
17
|
-
onDragStart?: (item: IItem, slotIndex: number, containerType: ItemContainerType) => void;
|
|
18
|
-
onPointerDown: (ItemType: ItemType, itemContainerType: ItemContainerType | null, item: IItem) => void;
|
|
19
|
-
containerType: ItemContainerType;
|
|
20
|
-
slotIndex: number;
|
|
21
|
-
openQuantitySelector: (quantity: number, onSuccess: (quantity?: number) => void) => void;
|
|
22
|
-
isContextMenuDisabled: boolean;
|
|
23
|
-
setTooltipState: React.Dispatch<React.SetStateAction<TooltipState>>;
|
|
24
|
-
setContextMenuState: React.Dispatch<React.SetStateAction<ContextMenuState>>;
|
|
25
|
-
contextMenuState: ContextMenuState;
|
|
26
|
-
}
|
|
27
|
-
export declare const useItemSlotDragAndDrop: ({ isDepotSystem, item, onDrop, onDragEnd, checkIfItemCanBeMoved, checkIfItemShouldDragEnd, setItemShortcut, isSelectingShortcut, onDragStart, onPointerDown, containerType, slotIndex, openQuantitySelector, isContextMenuDisabled, setTooltipState, setContextMenuState, }: IUseItemSlotDragAndDrop) => {
|
|
28
|
-
dragContainer: import("react").RefObject<HTMLDivElement>;
|
|
29
|
-
dragState: import("../context/DraggingContext").DragState;
|
|
30
|
-
draggingItem: IItem | null;
|
|
31
|
-
setDraggingItem: import("react").Dispatch<import("react").SetStateAction<IItem | null>>;
|
|
32
|
-
getContainerBounds: () => {
|
|
33
|
-
left: number;
|
|
34
|
-
top: number;
|
|
35
|
-
right: number;
|
|
36
|
-
bottom: number;
|
|
37
|
-
};
|
|
38
|
-
onDraggableStart: DraggableEventHandler;
|
|
39
|
-
onDraggableProgress: DraggableEventHandler;
|
|
40
|
-
onDraggableStop: DraggableEventHandler;
|
|
41
|
-
resetItem: () => void;
|
|
42
|
-
};
|
|
43
|
-
export {};
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import { IItem, ItemContainerType, ItemType } from '@rpg-engine/shared';
|
|
2
|
-
import { useCallback, useEffect, useRef } from 'react';
|
|
3
|
-
import { DraggableEventHandler } from 'react-draggable';
|
|
4
|
-
import { useDragging } from '../context/DraggingContext';
|
|
5
|
-
import { ContextMenuState, TooltipState } from '../ItemSlot';
|
|
6
|
-
|
|
7
|
-
interface IUseItemSlotDragAndDrop {
|
|
8
|
-
isDepotSystem: boolean;
|
|
9
|
-
item: IItem;
|
|
10
|
-
onDrop: (item: IItem, dropPosition: { x: number; y: number }) => void;
|
|
11
|
-
onDragEnd?: (quantity?: number) => void;
|
|
12
|
-
checkIfItemCanBeMoved?: () => boolean;
|
|
13
|
-
checkIfItemShouldDragEnd?: () => boolean;
|
|
14
|
-
setItemShortcut?: (item: IItem, index: number) => void;
|
|
15
|
-
isSelectingShortcut?: boolean;
|
|
16
|
-
onDragStart?: (
|
|
17
|
-
item: IItem,
|
|
18
|
-
slotIndex: number,
|
|
19
|
-
containerType: ItemContainerType
|
|
20
|
-
) => void;
|
|
21
|
-
onPointerDown: (
|
|
22
|
-
ItemType: ItemType,
|
|
23
|
-
itemContainerType: ItemContainerType | null,
|
|
24
|
-
item: IItem
|
|
25
|
-
) => void;
|
|
26
|
-
containerType: ItemContainerType;
|
|
27
|
-
slotIndex: number;
|
|
28
|
-
openQuantitySelector: (
|
|
29
|
-
quantity: number,
|
|
30
|
-
onSuccess: (quantity?: number) => void
|
|
31
|
-
) => void;
|
|
32
|
-
isContextMenuDisabled: boolean;
|
|
33
|
-
setTooltipState: React.Dispatch<React.SetStateAction<TooltipState>>;
|
|
34
|
-
setContextMenuState: React.Dispatch<React.SetStateAction<ContextMenuState>>;
|
|
35
|
-
contextMenuState: ContextMenuState;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const useItemSlotDragAndDrop = ({
|
|
39
|
-
isDepotSystem,
|
|
40
|
-
item,
|
|
41
|
-
onDrop,
|
|
42
|
-
onDragEnd,
|
|
43
|
-
checkIfItemCanBeMoved,
|
|
44
|
-
checkIfItemShouldDragEnd,
|
|
45
|
-
setItemShortcut,
|
|
46
|
-
isSelectingShortcut,
|
|
47
|
-
onDragStart,
|
|
48
|
-
onPointerDown,
|
|
49
|
-
containerType,
|
|
50
|
-
slotIndex,
|
|
51
|
-
openQuantitySelector,
|
|
52
|
-
isContextMenuDisabled,
|
|
53
|
-
setTooltipState,
|
|
54
|
-
setContextMenuState,
|
|
55
|
-
}: IUseItemSlotDragAndDrop) => {
|
|
56
|
-
const dragContainer = useRef<HTMLDivElement>(null);
|
|
57
|
-
const {
|
|
58
|
-
item: draggingItem,
|
|
59
|
-
setDraggingItem,
|
|
60
|
-
dragState,
|
|
61
|
-
setDragState,
|
|
62
|
-
} = useDragging();
|
|
63
|
-
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
setDragState(prev => ({
|
|
66
|
-
...prev,
|
|
67
|
-
position: { x: 0, y: 0 },
|
|
68
|
-
isFocused: false,
|
|
69
|
-
}));
|
|
70
|
-
}, [item, isDepotSystem, setDragState]);
|
|
71
|
-
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (onDrop && item && dragState.dropPosition) {
|
|
74
|
-
onDrop(item, dragState.dropPosition);
|
|
75
|
-
setDragState(prev => ({ ...prev, dropPosition: null }));
|
|
76
|
-
}
|
|
77
|
-
}, [dragState.dropPosition, item, onDrop]);
|
|
78
|
-
|
|
79
|
-
const getContainerBounds = useCallback(() => {
|
|
80
|
-
const container = dragContainer.current;
|
|
81
|
-
if (!container) return { left: 0, top: 0, right: 0, bottom: 0 };
|
|
82
|
-
const rect = container.getBoundingClientRect();
|
|
83
|
-
return {
|
|
84
|
-
left: rect.left,
|
|
85
|
-
top: rect.top,
|
|
86
|
-
right: window.innerWidth - rect.right,
|
|
87
|
-
bottom: window.innerHeight - rect.bottom,
|
|
88
|
-
};
|
|
89
|
-
}, []);
|
|
90
|
-
|
|
91
|
-
const resetDragState = useCallback(() => {
|
|
92
|
-
setDragState(prev => ({
|
|
93
|
-
...prev,
|
|
94
|
-
wasDragged: false,
|
|
95
|
-
isFocused: false,
|
|
96
|
-
position: { x: 0, y: 0 },
|
|
97
|
-
}));
|
|
98
|
-
}, [setTooltipState, setDragState]);
|
|
99
|
-
|
|
100
|
-
const handleSuccessfulDrag = useCallback(
|
|
101
|
-
(quantity?: number) => {
|
|
102
|
-
resetDragState();
|
|
103
|
-
if (quantity !== -1 && item) {
|
|
104
|
-
onDragEnd?.(quantity);
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
[item, onDragEnd, resetDragState]
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const onDraggableStart: DraggableEventHandler = useCallback(() => {
|
|
111
|
-
if (!item || isSelectingShortcut) return;
|
|
112
|
-
if (onDragStart && containerType) {
|
|
113
|
-
onDragStart(item, slotIndex, containerType);
|
|
114
|
-
}
|
|
115
|
-
}, [item, isSelectingShortcut, onDragStart, containerType, slotIndex]);
|
|
116
|
-
|
|
117
|
-
const onDraggableProgress: DraggableEventHandler = useCallback(
|
|
118
|
-
(_e, data) => {
|
|
119
|
-
const { x, y } = dragState.position;
|
|
120
|
-
if (Math.abs(data.x - x) > 5 || Math.abs(data.y - y) > 5) {
|
|
121
|
-
setDragState(prev => ({ ...prev, wasDragged: true, isFocused: true }));
|
|
122
|
-
}
|
|
123
|
-
if (!draggingItem) {
|
|
124
|
-
setDraggingItem(item);
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
[dragState.position, draggingItem, item, setDraggingItem, setDragState]
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
const onDraggableStop: DraggableEventHandler = useCallback(
|
|
131
|
-
(e, data) => {
|
|
132
|
-
setTimeout(() => {
|
|
133
|
-
setDraggingItem(null);
|
|
134
|
-
}, 50);
|
|
135
|
-
const target = e.target as HTMLElement;
|
|
136
|
-
if (!target) return;
|
|
137
|
-
|
|
138
|
-
target.classList.remove('react-draggable-dragging');
|
|
139
|
-
|
|
140
|
-
if (target?.id.includes('shortcutSetter') && setItemShortcut && item) {
|
|
141
|
-
const index = parseInt(target.id.split('_')[1]);
|
|
142
|
-
if (!isNaN(index)) {
|
|
143
|
-
setItemShortcut(item, index);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (dragState.wasDragged && item && !isSelectingShortcut) {
|
|
148
|
-
const classes: string[] = Array.from(target.classList);
|
|
149
|
-
const isOutsideDrop =
|
|
150
|
-
classes.some(elm => elm.includes('rpgui-content')) ||
|
|
151
|
-
classes.length === 0;
|
|
152
|
-
|
|
153
|
-
if (isOutsideDrop) {
|
|
154
|
-
setDragState(prev => ({
|
|
155
|
-
...prev,
|
|
156
|
-
dropPosition: { x: data.x, y: data.y },
|
|
157
|
-
}));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
setDragState(prev => ({ ...prev, wasDragged: false }));
|
|
161
|
-
|
|
162
|
-
setTimeout(() => {
|
|
163
|
-
if (
|
|
164
|
-
checkIfItemCanBeMoved?.() &&
|
|
165
|
-
(!checkIfItemShouldDragEnd || checkIfItemShouldDragEnd())
|
|
166
|
-
) {
|
|
167
|
-
if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) {
|
|
168
|
-
openQuantitySelector(item.stackQty, handleSuccessfulDrag);
|
|
169
|
-
} else {
|
|
170
|
-
handleSuccessfulDrag(item.stackQty);
|
|
171
|
-
}
|
|
172
|
-
} else {
|
|
173
|
-
resetDragState();
|
|
174
|
-
}
|
|
175
|
-
}, 50);
|
|
176
|
-
} else if (item) {
|
|
177
|
-
const isTouch = e.type === 'touchend';
|
|
178
|
-
if (
|
|
179
|
-
!isContextMenuDisabled &&
|
|
180
|
-
isTouch &&
|
|
181
|
-
!isSelectingShortcut &&
|
|
182
|
-
!draggingItem
|
|
183
|
-
) {
|
|
184
|
-
setTooltipState(prev => ({ ...prev, mobileVisible: true }));
|
|
185
|
-
} else if (!isContextMenuDisabled && !isSelectingShortcut && !isTouch) {
|
|
186
|
-
const event = e as MouseEvent;
|
|
187
|
-
setContextMenuState(prev => ({
|
|
188
|
-
visible: !prev.visible,
|
|
189
|
-
position: {
|
|
190
|
-
x: event.clientX - 10,
|
|
191
|
-
y: event.clientY - 5,
|
|
192
|
-
},
|
|
193
|
-
}));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
onPointerDown?.(item.type, containerType ?? null, item);
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
[
|
|
200
|
-
dragState.wasDragged,
|
|
201
|
-
item,
|
|
202
|
-
isSelectingShortcut,
|
|
203
|
-
checkIfItemCanBeMoved,
|
|
204
|
-
checkIfItemShouldDragEnd,
|
|
205
|
-
openQuantitySelector,
|
|
206
|
-
handleSuccessfulDrag,
|
|
207
|
-
resetDragState,
|
|
208
|
-
isContextMenuDisabled,
|
|
209
|
-
setTooltipState,
|
|
210
|
-
setContextMenuState,
|
|
211
|
-
onPointerDown,
|
|
212
|
-
containerType,
|
|
213
|
-
setItemShortcut,
|
|
214
|
-
]
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
return {
|
|
218
|
-
dragContainer,
|
|
219
|
-
dragState,
|
|
220
|
-
draggingItem,
|
|
221
|
-
setDraggingItem,
|
|
222
|
-
getContainerBounds,
|
|
223
|
-
onDraggableStart,
|
|
224
|
-
onDraggableProgress,
|
|
225
|
-
onDraggableStop,
|
|
226
|
-
resetItem: resetDragState,
|
|
227
|
-
};
|
|
228
|
-
};
|