@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.7.66",
3
+ "version": "0.7.68",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -250,7 +250,6 @@ export const ItemSlot = React.memo(
250
250
  }
251
251
  }}
252
252
  onTouchEnd={e => {
253
- handleInteractionEnd(e);
254
253
  const { clientX, clientY } = e.changedTouches[0];
255
254
  const simulatedEvent = new MouseEvent('mouseup', {
256
255
  clientX,
@@ -345,11 +344,6 @@ interface ContainerTypes {
345
344
  }
346
345
 
347
346
  const Container = styled.div<ContainerTypes>`
348
-
349
- * {
350
- border: 1px solid red;
351
- }
352
-
353
347
  margin: 0.1rem;
354
348
 
355
349
  .react-draggable-dragging {
@@ -1,26 +1,52 @@
1
1
  import { IItem } from '@rpg-engine/shared';
2
2
  import React, { createContext, useContext, useState } from 'react';
3
3
 
4
- const DraggingContext = createContext<{
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 value={{ item, setDraggingItem }}>
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, useState } from 'react';
2
+ import { useCallback, useEffect, useRef } from 'react';
3
3
  import { DraggableEventHandler } from 'react-draggable';
4
4
  import { useDragging } from '../context/DraggingContext';
5
- import { ContextMenuState, DragState, TooltipState } from '../ItemSlot';
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 { item: draggingItem, setDraggingItem } = useDragging();
58
-
59
- const [dragState, setDragState] = useState<DragState>({
60
- isFocused: false,
61
- wasDragged: false,
62
- position: { x: 0, y: 0 },
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,15 +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
- setDraggingItem(null);
102
- }, [setTooltipState]);
98
+ }, [setTooltipState, setDragState]);
103
99
 
104
100
  const handleSuccessfulDrag = useCallback(
105
101
  (quantity?: number) => {
@@ -121,20 +117,21 @@ export const useItemSlotDragAndDrop = ({
121
117
  const onDraggableProgress: DraggableEventHandler = useCallback(
122
118
  (_e, data) => {
123
119
  const { x, y } = dragState.position;
124
- if (Math.abs(data.x - x) > 20 || Math.abs(data.y - y) > 20) {
120
+ if (Math.abs(data.x - x) > 5 || Math.abs(data.y - y) > 5) {
125
121
  setDragState(prev => ({ ...prev, wasDragged: true, isFocused: true }));
126
- } else {
127
- resetDragState();
128
122
  }
129
123
  if (!draggingItem) {
130
124
  setDraggingItem(item);
131
125
  }
132
126
  },
133
- [dragState.position, draggingItem, item, setDraggingItem]
127
+ [dragState.position, draggingItem, item, setDraggingItem, setDragState]
134
128
  );
135
129
 
136
130
  const onDraggableStop: DraggableEventHandler = useCallback(
137
131
  (e, data) => {
132
+ setTimeout(() => {
133
+ setDraggingItem(null);
134
+ }, 50);
138
135
  const target = e.target as HTMLElement;
139
136
  if (!target) return;
140
137
 
@@ -178,31 +175,14 @@ export const useItemSlotDragAndDrop = ({
178
175
  }, 50);
179
176
  } else if (item) {
180
177
  const isTouch = e.type === 'touchend';
181
-
182
- console.log(`Debug:
183
- isTouch: ${isTouch},
184
- isSelectingShortcut: ${isSelectingShortcut},
185
- draggingItem: ${draggingItem},
186
- dragState.wasDragged: ${dragState.wasDragged},
187
- dragState.isFocused: ${dragState.isFocused}
188
- `);
189
-
190
178
  if (
191
179
  !isContextMenuDisabled &&
192
180
  isTouch &&
193
181
  !isSelectingShortcut &&
194
- !draggingItem &&
195
- !dragState.wasDragged &&
196
- !dragState.isFocused
182
+ !draggingItem
197
183
  ) {
198
184
  setTooltipState(prev => ({ ...prev, mobileVisible: true }));
199
- } else if (
200
- !isContextMenuDisabled &&
201
- !isSelectingShortcut &&
202
- !isTouch &&
203
- !dragState.wasDragged &&
204
- !dragState.isFocused
205
- ) {
185
+ } else if (!isContextMenuDisabled && !isSelectingShortcut && !isTouch) {
206
186
  const event = e as MouseEvent;
207
187
  setContextMenuState(prev => ({
208
188
  visible: !prev.visible,