@rpg-engine/long-bow 0.7.77 → 0.7.80

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.77",
3
+ "version": "0.7.80",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -10,7 +10,7 @@ import {
10
10
  } from '@rpg-engine/shared';
11
11
 
12
12
  import { observer } from 'mobx-react-lite';
13
- import React, { useEffect, useRef } from 'react';
13
+ import React, { useCallback, useEffect, useRef } from 'react';
14
14
  import Draggable, { DraggableEventHandler } from 'react-draggable';
15
15
  import styled from 'styled-components';
16
16
  import { IPosition } from '../../../types/eventTypes';
@@ -151,7 +151,11 @@ export const ItemSlot: React.FC<IProps> = observer(
151
151
  setContextActions,
152
152
  } = useItemSlotDetails();
153
153
 
154
- const { isContextMenuVisible, clearContextActions } = detailsState;
154
+ const {
155
+ isContextMenuVisible,
156
+
157
+ clearContextActions,
158
+ } = detailsState;
155
159
 
156
160
  const dragContainer = useRef<HTMLDivElement>(null);
157
161
 
@@ -161,12 +165,7 @@ export const ItemSlot: React.FC<IProps> = observer(
161
165
  clearDraggingState,
162
166
  } = useItemSlotDragging();
163
167
 
164
- const {
165
- isFocused,
166
- dropPosition,
167
- isDragging,
168
- draggingDistance,
169
- } = draggingState;
168
+ const { isFocused, isDragging, draggingDistance } = draggingState;
170
169
 
171
170
  useEffect(() => {
172
171
  // Reset drag position and focus when item changes
@@ -182,16 +181,6 @@ export const ItemSlot: React.FC<IProps> = observer(
182
181
  isContextMenuDisabled, // Added missing dependency
183
182
  ]);
184
183
 
185
- useEffect(() => {
186
- // Handle outside drop
187
- if (onDrop && draggingState.item && dropPosition) {
188
- console.log('ITEM SLOT: Outside drop', draggingState.item.key);
189
- onDrop(draggingState.item, dropPosition);
190
-
191
- clearDraggingState();
192
- }
193
- }, [dropPosition, onDrop, draggingState.item]);
194
-
195
184
  const resetItem = () => {
196
185
  clearDraggingState();
197
186
  updateDetailsState({
@@ -271,38 +260,46 @@ export const ItemSlot: React.FC<IProps> = observer(
271
260
  /**
272
261
  * Handles the logic when an item has been dragged.
273
262
  */
274
- const handleDraggedItem = (e: any, data: any) => {
275
- requestAnimationFrame(() => {
263
+ const handleDraggedItem = useCallback(
264
+ (e: any, data: any) => {
276
265
  const targetClasses = Array.from((e.target as HTMLElement).classList);
277
266
  const isOutsideDrop =
278
267
  targetClasses.some(elm => elm.includes('rpgui-content')) ||
279
268
  targetClasses.length === 0;
280
269
 
281
- if (isOutsideDrop) {
270
+ if (isOutsideDrop && draggingState.isDragging && draggingState.item) {
271
+ console.log('ITEM SLOT: Outside drop', draggingState.item.key);
272
+ onDrop?.(draggingState.item, { x: data.x, y: data.y });
273
+ clearDraggingState();
274
+ } else {
282
275
  updateDraggingState({
283
276
  dropPosition: {
284
277
  x: data.x,
285
278
  y: data.y,
286
279
  },
280
+ isDragging: false,
287
281
  });
288
- }
289
282
 
290
- updateDraggingState({
291
- isDragging: false,
292
- });
293
-
294
- const targetElement = dragContainer.current;
295
- if (!targetElement) return;
283
+ const targetElement = dragContainer.current;
284
+ if (!targetElement) return;
296
285
 
297
- const { x, y } = getElementTransform(targetElement);
286
+ const { x, y } = getElementTransform(targetElement);
298
287
 
299
- updateDraggingState({
300
- position: { x, y },
301
- });
288
+ updateDraggingState({
289
+ position: { x, y },
290
+ });
302
291
 
303
- processDragEnd(item!);
304
- });
305
- };
292
+ processDragEnd(item!);
293
+ }
294
+ },
295
+ [
296
+ draggingState.isDragging,
297
+ draggingState.item,
298
+ onDrop,
299
+ clearDraggingState,
300
+ updateDraggingState,
301
+ ]
302
+ );
306
303
 
307
304
  /**
308
305
  * Retrieves the current transform position of the dragged element.
@@ -89,14 +89,12 @@ export const ItemSlotDetailsProvider: React.FC<IProps> = ({ children }) => {
89
89
  isDepotSystem: boolean,
90
90
  isContextMenuDisabled: boolean
91
91
  ): void => {
92
- console.log('ITEM SLOT: Set context actions for', item?.key);
93
92
  if (item && containerType && !isContextMenuDisabled) {
94
93
  const newContextActions = generateContextMenu(
95
94
  item,
96
95
  containerType as ItemContainerType,
97
96
  isDepotSystem
98
97
  );
99
- console.log('ITEM SLOT: New context actions:', newContextActions);
100
98
  updateDetailsState({ contextActions: newContextActions });
101
99
  } else {
102
100
  updateDetailsState({ contextActions: [] });