@rpg-engine/long-bow 0.7.72 → 0.7.73
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 +0 -1
- package/dist/components/Item/Inventory/ItemSlotTooltips.d.ts +2 -14
- package/dist/components/Item/Inventory/context/ItemSlotDetailsContext.d.ts +30 -0
- package/dist/components/Item/Inventory/context/ItemSlotDraggingContext.d.ts +22 -0
- package/dist/long-bow.cjs.development.js +459 -438
- 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 +461 -440
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Equipment/EquipmentSet.tsx +43 -26
- package/src/components/Item/Inventory/DraggedItem.tsx +4 -2
- package/src/components/Item/Inventory/ItemContainer.tsx +248 -181
- package/src/components/Item/Inventory/ItemSlot.tsx +138 -212
- package/src/components/Item/Inventory/ItemSlotTooltips.tsx +41 -40
- package/src/components/Item/Inventory/context/ItemSlotDetailsContext.tsx +130 -0
- package/src/components/Item/Inventory/context/ItemSlotDraggingContext.tsx +81 -0
- package/dist/components/Item/Inventory/context/DraggingContext.d.ts +0 -11
- package/src/components/Item/Inventory/context/DraggingContext.tsx +0 -26
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { IItem, ItemContainerType } from '@rpg-engine/shared';
|
|
2
|
+
import React, {
|
|
3
|
+
createContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useMemo,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { generateContextMenu, IContextMenuItem } from '../itemContainerHelper';
|
|
10
|
+
|
|
11
|
+
interface IPosition {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface IItemSlotDetailsState {
|
|
17
|
+
item: IItem | null;
|
|
18
|
+
isTooltipVisible: boolean;
|
|
19
|
+
isTooltipMobileVisible: boolean;
|
|
20
|
+
isContextMenuVisible: boolean;
|
|
21
|
+
contextMenuPosition: IPosition;
|
|
22
|
+
contextActions: IContextMenuItem[];
|
|
23
|
+
clearContextActions: () => void;
|
|
24
|
+
clearDetailsState: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface IItemSlotDetailsContext {
|
|
28
|
+
detailsState: IItemSlotDetailsState;
|
|
29
|
+
updateDetailsState: (newState: Partial<IItemSlotDetailsState>) => void;
|
|
30
|
+
clearDetailsState: () => void;
|
|
31
|
+
setContextActions: (
|
|
32
|
+
item: IItem | null,
|
|
33
|
+
containerType: string | null,
|
|
34
|
+
isDepotSystem: boolean
|
|
35
|
+
) => void;
|
|
36
|
+
clearContextActions: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const initialDetailsState: IItemSlotDetailsState = {
|
|
40
|
+
item: null,
|
|
41
|
+
isTooltipVisible: false,
|
|
42
|
+
isTooltipMobileVisible: false,
|
|
43
|
+
isContextMenuVisible: false,
|
|
44
|
+
contextMenuPosition: { x: 0, y: 0 },
|
|
45
|
+
contextActions: [],
|
|
46
|
+
clearContextActions: () => {},
|
|
47
|
+
clearDetailsState: () => {},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const ItemSlotDetailsContext = createContext<IItemSlotDetailsContext>({
|
|
51
|
+
detailsState: initialDetailsState,
|
|
52
|
+
updateDetailsState: () => {},
|
|
53
|
+
clearDetailsState: () => {},
|
|
54
|
+
setContextActions: () => {},
|
|
55
|
+
clearContextActions: () => {},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const useItemSlotDetails = (): IItemSlotDetailsContext =>
|
|
59
|
+
useContext(ItemSlotDetailsContext);
|
|
60
|
+
|
|
61
|
+
interface IProps {
|
|
62
|
+
children: React.ReactNode;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const ItemSlotDetailsProvider: React.FC<IProps> = ({ children }) => {
|
|
66
|
+
const [detailsState, setDetailsState] = useState<IItemSlotDetailsState>(
|
|
67
|
+
initialDetailsState
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const updateDetailsState = useCallback(
|
|
71
|
+
(newState: Partial<IItemSlotDetailsState>): void => {
|
|
72
|
+
setDetailsState(prevState => ({
|
|
73
|
+
...prevState,
|
|
74
|
+
...newState,
|
|
75
|
+
}));
|
|
76
|
+
},
|
|
77
|
+
[]
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const clearDetailsState = useCallback(() => {
|
|
81
|
+
setDetailsState(initialDetailsState);
|
|
82
|
+
}, [setDetailsState]);
|
|
83
|
+
|
|
84
|
+
const setContextActions = useCallback(
|
|
85
|
+
(
|
|
86
|
+
item: IItem | null,
|
|
87
|
+
containerType: string | null,
|
|
88
|
+
isDepotSystem: boolean
|
|
89
|
+
): void => {
|
|
90
|
+
if (item && containerType) {
|
|
91
|
+
const newContextActions = generateContextMenu(
|
|
92
|
+
item,
|
|
93
|
+
containerType as ItemContainerType,
|
|
94
|
+
isDepotSystem
|
|
95
|
+
);
|
|
96
|
+
updateDetailsState({ contextActions: newContextActions });
|
|
97
|
+
} else {
|
|
98
|
+
updateDetailsState({ contextActions: [] });
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
[]
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const clearContextActions = useCallback(() => {
|
|
105
|
+
updateDetailsState({ contextActions: [] });
|
|
106
|
+
}, [updateDetailsState]);
|
|
107
|
+
|
|
108
|
+
const contextValue = useMemo(
|
|
109
|
+
() => ({
|
|
110
|
+
detailsState,
|
|
111
|
+
updateDetailsState,
|
|
112
|
+
clearDetailsState,
|
|
113
|
+
setContextActions,
|
|
114
|
+
clearContextActions,
|
|
115
|
+
}),
|
|
116
|
+
[
|
|
117
|
+
detailsState,
|
|
118
|
+
updateDetailsState,
|
|
119
|
+
clearDetailsState,
|
|
120
|
+
setContextActions,
|
|
121
|
+
clearContextActions,
|
|
122
|
+
]
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<ItemSlotDetailsContext.Provider value={contextValue}>
|
|
127
|
+
{children}
|
|
128
|
+
</ItemSlotDetailsContext.Provider>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { IItem } from '@rpg-engine/shared';
|
|
2
|
+
import React, {
|
|
3
|
+
createContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useMemo,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { IPosition } from '../../../../types/eventTypes';
|
|
10
|
+
|
|
11
|
+
interface IDraggingState {
|
|
12
|
+
item: IItem | null;
|
|
13
|
+
isDragging: boolean;
|
|
14
|
+
position: IPosition;
|
|
15
|
+
dropPosition: IPosition | null;
|
|
16
|
+
isFocused: boolean;
|
|
17
|
+
draggingDistance: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface IDraggingContext {
|
|
21
|
+
draggingState: IDraggingState;
|
|
22
|
+
updateDraggingState: (newState: Partial<IDraggingState>) => void;
|
|
23
|
+
clearDraggingState: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const initialDraggingState: IDraggingState = {
|
|
27
|
+
item: null,
|
|
28
|
+
isDragging: false,
|
|
29
|
+
position: { x: 0, y: 0 },
|
|
30
|
+
dropPosition: null,
|
|
31
|
+
isFocused: false,
|
|
32
|
+
draggingDistance: 0,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const ItemSlotDraggingContext = createContext<IDraggingContext>({
|
|
36
|
+
draggingState: initialDraggingState,
|
|
37
|
+
updateDraggingState: () => {},
|
|
38
|
+
clearDraggingState: () => {},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const useItemSlotDragging = (): IDraggingContext =>
|
|
42
|
+
useContext(ItemSlotDraggingContext);
|
|
43
|
+
|
|
44
|
+
interface IProps {
|
|
45
|
+
children: React.ReactNode;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const ItemSlotDraggingProvider: React.FC<IProps> = ({ children }) => {
|
|
49
|
+
const [draggingState, setDraggingState] = useState<IDraggingState>(
|
|
50
|
+
initialDraggingState
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const updateDraggingState = useCallback(
|
|
54
|
+
(newState: Partial<IDraggingState>): void => {
|
|
55
|
+
setDraggingState(prevState => ({
|
|
56
|
+
...prevState,
|
|
57
|
+
...newState,
|
|
58
|
+
}));
|
|
59
|
+
},
|
|
60
|
+
[]
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const clearDraggingState = useCallback(() => {
|
|
64
|
+
setDraggingState(initialDraggingState);
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
const contextValue = useMemo(
|
|
68
|
+
() => ({
|
|
69
|
+
draggingState,
|
|
70
|
+
updateDraggingState,
|
|
71
|
+
clearDraggingState,
|
|
72
|
+
}),
|
|
73
|
+
[draggingState, updateDraggingState, clearDraggingState]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<ItemSlotDraggingContext.Provider value={contextValue}>
|
|
78
|
+
{children}
|
|
79
|
+
</ItemSlotDraggingContext.Provider>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IItem } from '@rpg-engine/shared';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
export declare const useDragging: () => {
|
|
4
|
-
item: IItem | null;
|
|
5
|
-
setDraggingItem: React.Dispatch<React.SetStateAction<IItem | null>>;
|
|
6
|
-
};
|
|
7
|
-
interface IProps {
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
}
|
|
10
|
-
export declare const DraggingProvider: ({ children }: IProps) => JSX.Element;
|
|
11
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { IItem } from '@rpg-engine/shared';
|
|
2
|
-
import React, { createContext, useContext, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
const DraggingContext = createContext<{
|
|
5
|
-
item: IItem | null;
|
|
6
|
-
setDraggingItem: React.Dispatch<React.SetStateAction<IItem | null>>;
|
|
7
|
-
}>({
|
|
8
|
-
item: null,
|
|
9
|
-
setDraggingItem: () => {},
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export const useDragging = () => useContext(DraggingContext);
|
|
13
|
-
|
|
14
|
-
interface IProps {
|
|
15
|
-
children: React.ReactNode;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const DraggingProvider = ({ children }: IProps) => {
|
|
19
|
-
const [item, setDraggingItem] = useState<IItem | null>(null);
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<DraggingContext.Provider value={{ item, setDraggingItem }}>
|
|
23
|
-
{children}
|
|
24
|
-
</DraggingContext.Provider>
|
|
25
|
-
);
|
|
26
|
-
};
|