@rpg-engine/long-bow 0.7.77 → 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.77",
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';
@@ -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
 
@@ -184,13 +188,10 @@ export const ItemSlot: React.FC<IProps> = observer(
184
188
 
185
189
  useEffect(() => {
186
190
  // 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();
191
+ if (onDrop && item && dropPosition) {
192
+ onDrop(item, dropPosition);
192
193
  }
193
- }, [dropPosition, onDrop, draggingState.item]);
194
+ }, [dropPosition, onDrop, item]);
194
195
 
195
196
  const resetItem = () => {
196
197
  clearDraggingState();
@@ -271,38 +272,46 @@ export const ItemSlot: React.FC<IProps> = observer(
271
272
  /**
272
273
  * Handles the logic when an item has been dragged.
273
274
  */
274
- const handleDraggedItem = (e: any, data: any) => {
275
- requestAnimationFrame(() => {
275
+ const handleDraggedItem = useCallback(
276
+ (e: any, data: any) => {
276
277
  const targetClasses = Array.from((e.target as HTMLElement).classList);
277
278
  const isOutsideDrop =
278
279
  targetClasses.some(elm => elm.includes('rpgui-content')) ||
279
280
  targetClasses.length === 0;
280
281
 
281
- 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 {
282
287
  updateDraggingState({
283
288
  dropPosition: {
284
289
  x: data.x,
285
290
  y: data.y,
286
291
  },
292
+ isDragging: false,
287
293
  });
288
- }
289
-
290
- updateDraggingState({
291
- isDragging: false,
292
- });
293
294
 
294
- const targetElement = dragContainer.current;
295
- if (!targetElement) return;
295
+ const targetElement = dragContainer.current;
296
+ if (!targetElement) return;
296
297
 
297
- const { x, y } = getElementTransform(targetElement);
298
+ const { x, y } = getElementTransform(targetElement);
298
299
 
299
- updateDraggingState({
300
- position: { x, y },
301
- });
300
+ updateDraggingState({
301
+ position: { x, y },
302
+ });
302
303
 
303
- processDragEnd(item!);
304
- });
305
- };
304
+ processDragEnd(item!);
305
+ }
306
+ },
307
+ [
308
+ draggingState.isDragging,
309
+ draggingState.item,
310
+ onDrop,
311
+ clearDraggingState,
312
+ updateDraggingState,
313
+ ]
314
+ );
306
315
 
307
316
  /**
308
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: [] });