gbs-add-block 0.0.76 → 0.0.77
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/README.md +3 -2
- package/package.json +1 -1
- package/source/components/contextmenu/index.tsx +39 -15
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# GBS Building Blocks 2.0 (v0.0.
|
|
1
|
+
# GBS Building Blocks 2.0 (v0.0.77)
|
|
2
2
|
|
|
3
3
|
Latest and upgraded version of GBS building blocks with headless UI and removed dependencies.
|
|
4
4
|
|
|
@@ -6,9 +6,10 @@ Latest and upgraded version of GBS building blocks with headless UI and removed
|
|
|
6
6
|
|
|
7
7
|
For detailed documentation on usage and props, Please visit: [Building Block Documentation v2.0](https://blackmax-designs.gitbook.io/building-block-v2.0)
|
|
8
8
|
|
|
9
|
-
## What's New 🎉 (Ver 0.0.
|
|
9
|
+
## What's New 🎉 (Ver 0.0.77)
|
|
10
10
|
|
|
11
11
|
- Updated for bug fixes.
|
|
12
|
+
- New Component Card Added
|
|
12
13
|
|
|
13
14
|
## Authors
|
|
14
15
|
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import { ContextMenuProps, Position } from "./types";
|
|
|
4
4
|
export const ContextMenu: React.FC<ContextMenuProps> = ({ children }) => {
|
|
5
5
|
const [isVisible, setIsVisible] = useState<boolean>(false);
|
|
6
6
|
const [position, setPosition] = useState<Position>({ x: 0, y: 0 });
|
|
7
|
+
const [viewportSize, setViewportSize] = useState<Position>({ x: 0, y: 0 });
|
|
7
8
|
|
|
8
9
|
const handleContextMenu = useCallback(
|
|
9
10
|
(event: MouseEvent | globalThis.MouseEvent) => {
|
|
@@ -22,25 +23,48 @@ export const ContextMenu: React.FC<ContextMenuProps> = ({ children }) => {
|
|
|
22
23
|
}, [isVisible]);
|
|
23
24
|
|
|
24
25
|
useEffect(() => {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
if (typeof window !== "undefined") {
|
|
27
|
+
setViewportSize({
|
|
28
|
+
x: window.innerWidth,
|
|
29
|
+
y: window.innerHeight,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const handleResize = () => {
|
|
33
|
+
setViewportSize({
|
|
34
|
+
x: window.innerWidth,
|
|
35
|
+
y: window.innerHeight,
|
|
36
|
+
});
|
|
37
|
+
};
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
window.addEventListener("resize", handleResize);
|
|
40
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
41
|
+
}
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (typeof document !== "undefined") {
|
|
46
|
+
document.addEventListener("click", handleClick);
|
|
47
|
+
document.addEventListener("contextmenu", handleContextMenu);
|
|
48
|
+
|
|
49
|
+
return () => {
|
|
50
|
+
document.removeEventListener("click", handleClick);
|
|
51
|
+
document.removeEventListener("contextmenu", handleContextMenu);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
32
54
|
}, [handleClick, handleContextMenu]);
|
|
33
55
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
56
|
+
const adjustedPosition = useCallback(
|
|
57
|
+
(pos: Position): Position => {
|
|
58
|
+
const menuWidth = 160; // min-width from CSS
|
|
59
|
+
const menuHeight = 200; // approximate max height
|
|
38
60
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
return {
|
|
62
|
+
x: Math.min(pos.x, Math.max(viewportSize.x - menuWidth, 0)),
|
|
63
|
+
y: Math.min(pos.y, Math.max(viewportSize.y - menuHeight, 0)),
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
[viewportSize]
|
|
67
|
+
);
|
|
44
68
|
|
|
45
69
|
const finalPosition = adjustedPosition(position);
|
|
46
70
|
|