@rpg-engine/long-bow 0.8.230 → 0.8.231
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/dist/long-bow.cjs.development.js +38 -18
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +38 -18
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Item/Cards/ItemTooltip.tsx +27 -16
- package/src/components/shared/SimpleTooltip.tsx +32 -19
package/package.json
CHANGED
|
@@ -20,38 +20,49 @@ export const ItemTooltip: React.FC<IItemTooltipProps> = ({
|
|
|
20
20
|
equipmentSet,
|
|
21
21
|
}) => {
|
|
22
22
|
const ref = useRef<HTMLDivElement>(null);
|
|
23
|
+
const rafId = useRef<number | null>(null);
|
|
23
24
|
|
|
24
25
|
useEffect(() => {
|
|
25
26
|
const { current } = ref;
|
|
26
27
|
|
|
27
28
|
if (current) {
|
|
28
29
|
const handleMouseMove = (event: MouseEvent) => {
|
|
30
|
+
if (rafId.current !== null) return;
|
|
31
|
+
|
|
29
32
|
const { clientX, clientY } = event;
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
rafId.current = requestAnimationFrame(() => {
|
|
35
|
+
rafId.current = null;
|
|
36
|
+
|
|
37
|
+
// Adjust the position of the tooltip based on the mouse position
|
|
38
|
+
const rect = current.getBoundingClientRect();
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
const tooltipWidth = rect.width;
|
|
41
|
+
const tooltipHeight = rect.height;
|
|
42
|
+
const isOffScreenRight =
|
|
43
|
+
clientX + tooltipWidth + offset > window.innerWidth;
|
|
44
|
+
const isOffScreenBottom =
|
|
45
|
+
clientY + tooltipHeight + offset > window.innerHeight;
|
|
46
|
+
const x = isOffScreenRight
|
|
47
|
+
? clientX - tooltipWidth - offset
|
|
48
|
+
: clientX + offset;
|
|
49
|
+
const y = isOffScreenBottom
|
|
50
|
+
? clientY - tooltipHeight - offset
|
|
51
|
+
: clientY + offset;
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
current.style.transform = `translate(${x}px, ${y}px)`;
|
|
54
|
+
current.style.opacity = '1';
|
|
55
|
+
});
|
|
49
56
|
};
|
|
50
57
|
|
|
51
58
|
window.addEventListener('mousemove', handleMouseMove);
|
|
52
59
|
|
|
53
60
|
return () => {
|
|
54
61
|
window.removeEventListener('mousemove', handleMouseMove);
|
|
62
|
+
if (rafId.current !== null) {
|
|
63
|
+
cancelAnimationFrame(rafId.current);
|
|
64
|
+
rafId.current = null;
|
|
65
|
+
}
|
|
55
66
|
};
|
|
56
67
|
}
|
|
57
68
|
|
|
@@ -28,6 +28,7 @@ export const SimpleTooltip: React.FC<TooltipProps> = ({
|
|
|
28
28
|
const tooltipRef = useRef<HTMLDivElement>(null);
|
|
29
29
|
const triggerRef = useRef<HTMLDivElement>(null);
|
|
30
30
|
const timeoutRef = useRef<NodeJS.Timeout>();
|
|
31
|
+
const rafId = useRef<number | null>(null);
|
|
31
32
|
|
|
32
33
|
const calculatePosition = () => {
|
|
33
34
|
if (!triggerRef.current || !tooltipRef.current) return;
|
|
@@ -87,26 +88,34 @@ export const SimpleTooltip: React.FC<TooltipProps> = ({
|
|
|
87
88
|
|
|
88
89
|
useEffect(() => {
|
|
89
90
|
const handleMouseMove = (event: MouseEvent) => {
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
91
|
+
if (rafId.current !== null) return;
|
|
92
|
+
|
|
93
|
+
const { clientX, clientY } = event;
|
|
94
|
+
|
|
95
|
+
rafId.current = requestAnimationFrame(() => {
|
|
96
|
+
rafId.current = null;
|
|
97
|
+
|
|
98
|
+
if (visible && tooltipRef.current && triggerRef.current) {
|
|
99
|
+
const tooltipRect = tooltipRef.current.getBoundingClientRect();
|
|
100
|
+
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
101
|
+
|
|
102
|
+
const isOutsideTooltip =
|
|
103
|
+
clientX < tooltipRect.left ||
|
|
104
|
+
clientX > tooltipRect.right ||
|
|
105
|
+
clientY < tooltipRect.top ||
|
|
106
|
+
clientY > tooltipRect.bottom;
|
|
107
|
+
|
|
108
|
+
const isOutsideTrigger =
|
|
109
|
+
clientX < triggerRect.left ||
|
|
110
|
+
clientX > triggerRect.right ||
|
|
111
|
+
clientY < triggerRect.top ||
|
|
112
|
+
clientY > triggerRect.bottom;
|
|
113
|
+
|
|
114
|
+
if (isOutsideTooltip && isOutsideTrigger) {
|
|
115
|
+
hideTooltip();
|
|
116
|
+
}
|
|
108
117
|
}
|
|
109
|
-
}
|
|
118
|
+
});
|
|
110
119
|
};
|
|
111
120
|
|
|
112
121
|
const handleScroll = () => {
|
|
@@ -129,6 +138,10 @@ export const SimpleTooltip: React.FC<TooltipProps> = ({
|
|
|
129
138
|
document.removeEventListener('mousemove', handleMouseMove);
|
|
130
139
|
window.removeEventListener('scroll', handleScroll);
|
|
131
140
|
window.removeEventListener('resize', handleResize);
|
|
141
|
+
if (rafId.current !== null) {
|
|
142
|
+
cancelAnimationFrame(rafId.current);
|
|
143
|
+
rafId.current = null;
|
|
144
|
+
}
|
|
132
145
|
clearTimeout(timeoutRef.current);
|
|
133
146
|
};
|
|
134
147
|
}, [visible]);
|