@rpg-engine/long-bow 0.7.80 → 0.7.81

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.80",
3
+ "version": "0.7.81",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -153,7 +153,7 @@ export const ItemSlot: React.FC<IProps> = observer(
153
153
 
154
154
  const {
155
155
  isContextMenuVisible,
156
-
156
+ clearDetailsState,
157
157
  clearContextActions,
158
158
  } = detailsState;
159
159
 
@@ -181,12 +181,26 @@ export const ItemSlot: React.FC<IProps> = observer(
181
181
  isContextMenuDisabled, // Added missing dependency
182
182
  ]);
183
183
 
184
+ useEffect(() => {
185
+ // Reset drag position and focus when item changes
186
+ clearDraggingState();
187
+
188
+ // Clear context actions when component unmounts or dependencies change
189
+ return () => {
190
+ clearContextActions();
191
+ };
192
+ }, [
193
+ containerType,
194
+ isDepotSystem,
195
+ setContextActions,
196
+ clearContextActions,
197
+ isContextMenuDisabled,
198
+ updateDraggingState, // Add this dependency
199
+ ]);
200
+
184
201
  const resetItem = () => {
185
202
  clearDraggingState();
186
- updateDetailsState({
187
- item,
188
- isTooltipVisible: false,
189
- });
203
+ clearDetailsState();
190
204
  };
191
205
 
192
206
  const onSuccessfulDrag = (quantity?: number) => {
@@ -312,27 +326,31 @@ export const ItemSlot: React.FC<IProps> = observer(
312
326
  return { x: matrix.m41, y: matrix.m42 };
313
327
  };
314
328
 
315
- /**
316
- * Processes the end of a drag event, handling quantity selection or resetting state.
317
- */
318
- const processDragEnd = (item: IItem) => {
319
- if (checkIfItemCanBeMoved?.()) {
320
- if (checkIfItemShouldDragEnd && !checkIfItemShouldDragEnd()) return;
321
-
322
- if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) {
323
- openQuantitySelector(item.stackQty, onSuccessfulDrag);
329
+ const processDragEnd = useCallback(
330
+ (item: IItem) => {
331
+ if (checkIfItemCanBeMoved?.()) {
332
+ if (checkIfItemShouldDragEnd && !checkIfItemShouldDragEnd()) {
333
+ resetItem();
334
+ return;
335
+ }
336
+
337
+ if (item.stackQty && item.stackQty !== 1 && openQuantitySelector) {
338
+ openQuantitySelector(item.stackQty, onSuccessfulDrag);
339
+ } else {
340
+ onSuccessfulDrag(item.stackQty);
341
+ }
324
342
  } else {
325
- onSuccessfulDrag(item.stackQty);
343
+ resetItem();
326
344
  }
327
- } else {
328
- resetItem();
329
-
330
- updateDraggingState({
331
- isFocused: false,
332
- position: { x: 0, y: 0 },
333
- });
334
- }
335
- };
345
+ },
346
+ [
347
+ checkIfItemCanBeMoved,
348
+ checkIfItemShouldDragEnd,
349
+ openQuantitySelector,
350
+ onSuccessfulDrag,
351
+ resetItem,
352
+ ]
353
+ );
336
354
 
337
355
  /**
338
356
  * Handles the context menu or tooltip display after dragging stops without a drop.