@rpg-engine/long-bow 0.7.70 → 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.
Files changed (25) hide show
  1. package/dist/components/Item/Inventory/ItemSlot.d.ts +5 -18
  2. package/dist/components/Item/Inventory/ItemSlotTooltips.d.ts +12 -1
  3. package/dist/components/Item/Inventory/context/DraggingContext.d.ts +11 -0
  4. package/dist/hooks/useCursorPosition.d.ts +1 -1
  5. package/dist/long-bow.cjs.development.js +572 -660
  6. package/dist/long-bow.cjs.development.js.map +1 -1
  7. package/dist/long-bow.cjs.production.min.js +1 -1
  8. package/dist/long-bow.cjs.production.min.js.map +1 -1
  9. package/dist/long-bow.esm.js +574 -662
  10. package/dist/long-bow.esm.js.map +1 -1
  11. package/package.json +2 -3
  12. package/src/components/Equipment/EquipmentSet.tsx +29 -61
  13. package/src/components/Item/Inventory/DraggedItem.tsx +2 -2
  14. package/src/components/Item/Inventory/ItemContainer.tsx +44 -68
  15. package/src/components/Item/Inventory/ItemSlot.tsx +447 -239
  16. package/src/components/Item/Inventory/ItemSlotTooltips.tsx +46 -48
  17. package/src/components/Item/Inventory/context/DraggingContext.tsx +26 -0
  18. package/src/hooks/useCursorPosition.ts +20 -29
  19. package/src/stories/UI/containers/ItemContainer.stories.tsx +3 -30
  20. package/dist/components/Item/Inventory/context/ItemSlotDraggingContext.d.ts +0 -26
  21. package/dist/components/Item/Inventory/context/ItemSlotTooltipContext.d.ts +0 -28
  22. package/dist/components/Item/Inventory/hooks/useItemSlotDragAndDrop.d.ts +0 -39
  23. package/src/components/Item/Inventory/context/ItemSlotDraggingContext.tsx +0 -52
  24. package/src/components/Item/Inventory/context/ItemSlotTooltipContext.tsx +0 -95
  25. package/src/components/Item/Inventory/hooks/useItemSlotDragAndDrop.ts +0 -248
@@ -1,248 +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 { useItemSlotDragging } from '../context/ItemSlotDraggingContext';
5
- import { useItemSlotTooltip } from '../context/ItemSlotTooltipContext';
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
- }
34
-
35
- export const useItemSlotDragAndDrop = ({
36
- isDepotSystem,
37
- item,
38
- onDrop,
39
- onDragEnd,
40
- checkIfItemCanBeMoved,
41
- checkIfItemShouldDragEnd,
42
- setItemShortcut,
43
- isSelectingShortcut,
44
- onDragStart,
45
- onPointerDown,
46
- containerType,
47
- slotIndex,
48
- openQuantitySelector,
49
- isContextMenuDisabled,
50
- }: IUseItemSlotDragAndDrop) => {
51
- const dragContainer = useRef<HTMLDivElement>(null);
52
- const {
53
- item: draggingItem,
54
- setDraggingItem,
55
- dragState,
56
- setDragState,
57
- } = useItemSlotDragging();
58
-
59
- const { updateItemDetails, itemDetails } = useItemSlotTooltip();
60
-
61
- useEffect(() => {
62
- setDragState(prev => ({
63
- ...prev,
64
- position: { x: 0, y: 0 },
65
- isFocused: false,
66
- }));
67
- }, [item, isDepotSystem, setDragState]);
68
-
69
- useEffect(() => {
70
- if (onDrop && item && dragState.dropPosition) {
71
- onDrop(item, dragState.dropPosition);
72
- setDragState(prev => ({ ...prev, dropPosition: null }));
73
- }
74
- }, [dragState.dropPosition, item, onDrop]);
75
-
76
- const getContainerBounds = useCallback(() => {
77
- const container = dragContainer.current;
78
- if (!container) return { left: 0, top: 0, right: 0, bottom: 0 };
79
- const rect = container.getBoundingClientRect();
80
- return {
81
- left: rect.left,
82
- top: rect.top,
83
- right: window.innerWidth - rect.right,
84
- bottom: window.innerHeight - rect.bottom,
85
- };
86
- }, []);
87
-
88
- const resetDragState = useCallback(() => {
89
- console.log('RESET_DRAG_STATE!');
90
- setDragState(prev => ({
91
- ...prev,
92
- wasDragged: false,
93
- isFocused: false,
94
- position: { x: 0, y: 0 },
95
- }));
96
- setDraggingItem(null);
97
-
98
- // Reset tooltip visibility
99
- updateItemDetails({
100
- tooltip: { visible: false, mobileVisible: false },
101
- });
102
- }, [updateItemDetails, setDragState]);
103
-
104
- const handleSuccessfulDrag = useCallback(
105
- (quantity?: number) => {
106
- console.log('HANDLE_SUCCESSFUL_DRAG!');
107
- resetDragState();
108
- if (quantity !== -1 && item) {
109
- onDragEnd?.(quantity);
110
- }
111
- },
112
- [item, onDragEnd, resetDragState]
113
- );
114
-
115
- const onDraggableStart: DraggableEventHandler = useCallback(() => {
116
- console.log('ON_DRAGGABLE_START!');
117
- if (!item || isSelectingShortcut) return;
118
- if (onDragStart && containerType) {
119
- onDragStart(item, slotIndex, containerType);
120
- }
121
-
122
- if (!draggingItem && item) {
123
- console.log('!!! SETTING DRAGGING ITEM ', item._id);
124
- setDraggingItem(item);
125
- }
126
- }, [item, isSelectingShortcut, onDragStart, containerType, slotIndex]);
127
-
128
- const onDraggableProgress: DraggableEventHandler = useCallback(
129
- (_e, data) => {
130
- console.log('ON_DRAGGABLE_PROGRESS!');
131
- const { x, y } = dragState.position;
132
- if (Math.abs(data.x - x) > 5 || Math.abs(data.y - y) > 5) {
133
- setDragState(prev => ({ ...prev, wasDragged: true, isFocused: true }));
134
- }
135
- },
136
- [dragState.position, draggingItem, item, setDraggingItem, setDragState]
137
- );
138
-
139
- const onDraggableStop: DraggableEventHandler = useCallback(
140
- (e, data) => {
141
- console.log('ON_DRAGGABLE_STOP!');
142
-
143
- const target = e.target as HTMLElement;
144
-
145
- if (!target) return;
146
-
147
- target.classList.remove('react-draggable-dragging');
148
-
149
- if (target?.id.includes('shortcutSetter') && setItemShortcut && item) {
150
- const index = parseInt(target.id.split('_')[1]);
151
- if (!isNaN(index)) {
152
- setItemShortcut(item, index);
153
- }
154
- }
155
-
156
- if (dragState.wasDragged && item && !isSelectingShortcut) {
157
- const classes: string[] = Array.from(target.classList);
158
- const isOutsideDrop =
159
- classes.some(elm => elm.includes('rpgui-content')) ||
160
- classes.length === 0;
161
-
162
- if (isOutsideDrop) {
163
- setDragState(prev => ({
164
- ...prev,
165
- dropPosition: { x: data.x, y: data.y },
166
- }));
167
- }
168
-
169
- setDragState(prev => ({ ...prev, wasDragged: false }));
170
-
171
- setTimeout(() => {
172
- if (
173
- checkIfItemCanBeMoved?.() &&
174
- (!checkIfItemShouldDragEnd || checkIfItemShouldDragEnd())
175
- ) {
176
- if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) {
177
- openQuantitySelector(item.stackQty, handleSuccessfulDrag);
178
- } else {
179
- handleSuccessfulDrag(item.stackQty);
180
- }
181
- } else {
182
- resetDragState();
183
- }
184
- }, 50);
185
- } else if (item) {
186
- const isTouch = e.type === 'touchend';
187
-
188
- console.log(`Debug:
189
- isTouch: ${isTouch},
190
- isSelectingShortcut: ${isSelectingShortcut},
191
- draggingItem: ${draggingItem},
192
- dragginState: ${JSON.stringify(dragState)}
193
- `);
194
-
195
- if (!isContextMenuDisabled && isTouch && !isSelectingShortcut) {
196
- updateItemDetails({
197
- item,
198
- tooltip: { mobileVisible: true },
199
- });
200
- } else if (!isContextMenuDisabled && !isSelectingShortcut && !isTouch) {
201
- const event = e as MouseEvent;
202
-
203
- updateItemDetails({
204
- item,
205
- contextMenu: {
206
- visible: !itemDetails?.contextMenu?.visible,
207
- position: {
208
- x: event.clientX - 10,
209
- y: event.clientY - 5,
210
- },
211
- },
212
- });
213
- }
214
-
215
- onPointerDown?.(item.type, containerType ?? null, item);
216
- }
217
-
218
- console.log('setting draggingItem to null');
219
- setDraggingItem(null);
220
- },
221
- [
222
- dragState.wasDragged,
223
- item,
224
- isSelectingShortcut,
225
- checkIfItemCanBeMoved,
226
- checkIfItemShouldDragEnd,
227
- openQuantitySelector,
228
- handleSuccessfulDrag,
229
- resetDragState,
230
- isContextMenuDisabled,
231
- onPointerDown,
232
- containerType,
233
- setItemShortcut,
234
- ]
235
- );
236
-
237
- return {
238
- dragContainer,
239
- dragState,
240
- draggingItem,
241
- setDraggingItem,
242
- getContainerBounds,
243
- onDraggableStart,
244
- onDraggableProgress,
245
- onDraggableStop,
246
- resetItem: resetDragState,
247
- };
248
- };