@rpg-engine/long-bow 0.7.76 → 0.7.79

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.76",
3
+ "version": "0.7.79",
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';
@@ -272,38 +272,46 @@ export const ItemSlot: React.FC<IProps> = observer(
272
272
  /**
273
273
  * Handles the logic when an item has been dragged.
274
274
  */
275
- const handleDraggedItem = (e: any, data: any) => {
276
- requestAnimationFrame(() => {
275
+ const handleDraggedItem = useCallback(
276
+ (e: any, data: any) => {
277
277
  const targetClasses = Array.from((e.target as HTMLElement).classList);
278
278
  const isOutsideDrop =
279
279
  targetClasses.some(elm => elm.includes('rpgui-content')) ||
280
280
  targetClasses.length === 0;
281
281
 
282
- if (isOutsideDrop) {
282
+ if (isOutsideDrop && draggingState.isDragging && draggingState.item) {
283
+ console.log('ITEM SLOT: Outside drop', draggingState.item.key);
284
+ onDrop?.(draggingState.item, { x: data.x, y: data.y });
285
+ clearDraggingState();
286
+ } else {
283
287
  updateDraggingState({
284
288
  dropPosition: {
285
289
  x: data.x,
286
290
  y: data.y,
287
291
  },
292
+ isDragging: false,
288
293
  });
289
- }
290
294
 
291
- updateDraggingState({
292
- isDragging: false,
293
- });
294
-
295
- const targetElement = dragContainer.current;
296
- if (!targetElement) return;
295
+ const targetElement = dragContainer.current;
296
+ if (!targetElement) return;
297
297
 
298
- const { x, y } = getElementTransform(targetElement);
298
+ const { x, y } = getElementTransform(targetElement);
299
299
 
300
- updateDraggingState({
301
- position: { x, y },
302
- });
300
+ updateDraggingState({
301
+ position: { x, y },
302
+ });
303
303
 
304
- processDragEnd(item!);
305
- });
306
- };
304
+ processDragEnd(item!);
305
+ }
306
+ },
307
+ [
308
+ draggingState.isDragging,
309
+ draggingState.item,
310
+ onDrop,
311
+ clearDraggingState,
312
+ updateDraggingState,
313
+ ]
314
+ );
307
315
 
308
316
  /**
309
317
  * 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: [] });