@rpg-engine/long-bow 0.7.66 → 0.7.67

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.67",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -9,7 +9,7 @@ import {
9
9
  } from '@rpg-engine/shared';
10
10
 
11
11
  import { observer } from 'mobx-react-lite';
12
- import React, { useCallback, useEffect, useState } from 'react';
12
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
13
13
  import Draggable from 'react-draggable';
14
14
  import styled from 'styled-components';
15
15
  import { IPosition } from '../../../types/eventTypes';
@@ -134,6 +134,18 @@ export const ItemSlot = React.memo(
134
134
  []
135
135
  );
136
136
 
137
+ const isDraggingDisabled = useMemo(() => {
138
+ return (
139
+ contextMenuState.visible ||
140
+ onDragStart === undefined ||
141
+ onDragEnd === undefined
142
+ );
143
+ }, [contextMenuState.visible, onDragStart, onDragEnd]);
144
+
145
+ useEffect(() => {
146
+ console.log('isDraggingDisabled', isDraggingDisabled);
147
+ }, [isDraggingDisabled]);
148
+
137
149
  const {
138
150
  dragContainer,
139
151
  dragState,
@@ -229,6 +241,18 @@ export const ItemSlot = React.memo(
229
241
  [onMouseOut]
230
242
  );
231
243
 
244
+ const [showTooltipDelayed, setShowTooltipDelayed] = useState(false);
245
+
246
+ //@ts-ignore
247
+ useEffect(() => {
248
+ if (tooltipState.visible && !isDraggingDisabled) {
249
+ const timer = setTimeout(() => setShowTooltipDelayed(true), 50);
250
+ return () => clearTimeout(timer);
251
+ } else {
252
+ setShowTooltipDelayed(false);
253
+ }
254
+ }, [tooltipState.visible, isDraggingDisabled]);
255
+
232
256
  return (
233
257
  <Container
234
258
  isDraggingItem={!!draggingItem}
@@ -275,7 +299,7 @@ export const ItemSlot = React.memo(
275
299
  axis={isSelectingShortcut ? 'none' : 'both'}
276
300
  defaultClassName={item ? 'draggable' : 'empty-slot'}
277
301
  scale={dragScale}
278
- disabled={onDragStart === undefined || onDragEnd === undefined}
302
+ disabled={isDraggingDisabled}
279
303
  onStop={onDraggableStop}
280
304
  onStart={onDraggableStart}
281
305
  onDrag={onDraggableProgress}
@@ -299,8 +323,13 @@ export const ItemSlot = React.memo(
299
323
  onMouseEnter={() => {
300
324
  setTooltipState(prev => ({ ...prev, visible: true }));
301
325
  }}
302
- onMouseLeave={() => {
303
- setTooltipState(prev => ({ ...prev, visible: false }));
326
+ onMouseLeave={e => {
327
+ if (
328
+ !e.relatedTarget ||
329
+ !dragContainer.current?.contains(e.relatedTarget as Node)
330
+ ) {
331
+ setTooltipState(prev => ({ ...prev, visible: false }));
332
+ }
304
333
  }}
305
334
  >
306
335
  <ItemSlotRenderer
@@ -330,6 +359,9 @@ export const ItemSlot = React.memo(
330
359
  atlasIMG={atlasIMG}
331
360
  atlasJSON={atlasJSON}
332
361
  equipmentSet={equipmentSet}
362
+ isDragging={!!draggingItem}
363
+ isSelectingShortcut={!!isSelectingShortcut}
364
+ showTooltipDelayed={showTooltipDelayed}
333
365
  />
334
366
  </Container>
335
367
  );
@@ -345,11 +377,6 @@ interface ContainerTypes {
345
377
  }
346
378
 
347
379
  const Container = styled.div<ContainerTypes>`
348
-
349
- * {
350
- border: 1px solid red;
351
- }
352
-
353
380
  margin: 0.1rem;
354
381
 
355
382
  .react-draggable-dragging {
@@ -20,6 +20,9 @@ interface IProps {
20
20
  atlasIMG: any;
21
21
  atlasJSON: any;
22
22
  equipmentSet?: IEquipmentSet | null;
23
+ isDragging: boolean;
24
+ isSelectingShortcut: boolean;
25
+ showTooltipDelayed: boolean;
23
26
  }
24
27
 
25
28
  export const ItemSlotToolTips = ({
@@ -36,10 +39,15 @@ export const ItemSlotToolTips = ({
36
39
  atlasIMG,
37
40
  atlasJSON,
38
41
  equipmentSet,
42
+ isDragging,
43
+ isSelectingShortcut,
44
+ showTooltipDelayed,
39
45
  }: IProps): JSX.Element => {
46
+ const canShow = !isDragging || !isSelectingShortcut || showTooltipDelayed;
47
+
40
48
  return (
41
49
  <>
42
- {tooltipState.visible && item && !isFocused && (
50
+ {tooltipState.visible && item && !isFocused && canShow && (
43
51
  <ItemTooltip
44
52
  item={item}
45
53
  atlasIMG={atlasIMG}
@@ -48,7 +56,7 @@ export const ItemSlotToolTips = ({
48
56
  />
49
57
  )}
50
58
 
51
- {tooltipState.mobileVisible && item && (
59
+ {tooltipState.mobileVisible && item && canShow && (
52
60
  <MobileItemTooltip
53
61
  item={item}
54
62
  atlasIMG={atlasIMG}
@@ -68,7 +76,7 @@ export const ItemSlotToolTips = ({
68
76
  />
69
77
  )}
70
78
 
71
- {!isContextMenuDisabled && contextMenuState.visible && contextActions && (
79
+ {!isContextMenuDisabled && contextMenuState.visible && contextActions && canShow && (
72
80
  <RelativeListMenu
73
81
  options={contextActions}
74
82
  onSelected={(optionId: string) => {
@@ -98,7 +98,6 @@ export const useItemSlotDragAndDrop = ({
98
98
  isFocused: false,
99
99
  position: { x: 0, y: 0 },
100
100
  }));
101
- setDraggingItem(null);
102
101
  }, [setTooltipState]);
103
102
 
104
103
  const handleSuccessfulDrag = useCallback(
@@ -121,10 +120,8 @@ export const useItemSlotDragAndDrop = ({
121
120
  const onDraggableProgress: DraggableEventHandler = useCallback(
122
121
  (_e, data) => {
123
122
  const { x, y } = dragState.position;
124
- if (Math.abs(data.x - x) > 20 || Math.abs(data.y - y) > 20) {
123
+ if (Math.abs(data.x - x) > 5 || Math.abs(data.y - y) > 5) {
125
124
  setDragState(prev => ({ ...prev, wasDragged: true, isFocused: true }));
126
- } else {
127
- resetDragState();
128
125
  }
129
126
  if (!draggingItem) {
130
127
  setDraggingItem(item);
@@ -135,6 +132,9 @@ export const useItemSlotDragAndDrop = ({
135
132
 
136
133
  const onDraggableStop: DraggableEventHandler = useCallback(
137
134
  (e, data) => {
135
+ setTimeout(() => {
136
+ setDraggingItem(null);
137
+ }, 50);
138
138
  const target = e.target as HTMLElement;
139
139
  if (!target) return;
140
140
 
@@ -178,31 +178,14 @@ export const useItemSlotDragAndDrop = ({
178
178
  }, 50);
179
179
  } else if (item) {
180
180
  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
181
  if (
191
182
  !isContextMenuDisabled &&
192
183
  isTouch &&
193
184
  !isSelectingShortcut &&
194
- !draggingItem &&
195
- !dragState.wasDragged &&
196
- !dragState.isFocused
185
+ !draggingItem
197
186
  ) {
198
187
  setTooltipState(prev => ({ ...prev, mobileVisible: true }));
199
- } else if (
200
- !isContextMenuDisabled &&
201
- !isSelectingShortcut &&
202
- !isTouch &&
203
- !dragState.wasDragged &&
204
- !dragState.isFocused
205
- ) {
188
+ } else if (!isContextMenuDisabled && !isSelectingShortcut && !isTouch) {
206
189
  const event = e as MouseEvent;
207
190
  setContextMenuState(prev => ({
208
191
  visible: !prev.visible,