@@ -17,6 +17,7 @@ import { useScrollDirectionContext } from "@/hooks/scrollDirection";
1717import { ScrollDirection } from "@/types/scrollDirection" ;
1818import eventEmitter from "@/events-emitter" ;
1919import { tableCoordsStore } from "@/stores/tableCoords" ;
20+ import { useTablesInfo } from "@/hooks/table" ;
2021
2122interface DiagramWrapperProps {
2223 children : ReactNode ;
@@ -31,6 +32,7 @@ const DiagramWrapper = ({ children }: DiagramWrapperProps) => {
3132 useCursorChanger ( "grabbing" ) ;
3233 const themeColors = useThemeColors ( ) ;
3334 const stageRef = useRef < null | CoreStage > ( null ) ;
35+ const { hoveredTableName, setHoveredTableName } = useTablesInfo ( ) ;
3436
3537 // repositioning the stage only once
3638 const { scale : defaultStageScale , position : defaultStagePosition } =
@@ -83,6 +85,31 @@ const DiagramWrapper = ({ children }: DiagramWrapperProps) => {
8385 stageStateStore . set ( { scale : newScale , position : newPos } ) ;
8486 } ;
8587
88+ const nodeBelongsToTable = ( node : any ) : boolean => {
89+ let currentNode = node ;
90+ while ( currentNode != null ) {
91+ if (
92+ typeof currentNode . name === "function" &&
93+ typeof currentNode . name ( ) === "string"
94+ ) {
95+ const names = ( currentNode . name ( ) as string ) . split ( / \s + / ) ;
96+ if ( names . some ( ( n ) => n . startsWith ( "table-" ) ) ) {
97+ return true ;
98+ }
99+ }
100+ currentNode = currentNode . getParent ?.( ) ?? null ;
101+ }
102+ return false ;
103+ } ;
104+
105+ const handleStagePointerDown = (
106+ e : KonvaEventObject < MouseEvent | TouchEvent > ,
107+ ) => {
108+ if ( hoveredTableName == null ) return ;
109+ if ( nodeBelongsToTable ( e . target ) ) return ;
110+ setHoveredTableName ( null ) ;
111+ } ;
112+
86113 const fitToView = ( ) => {
87114 if ( stageRef . current != null ) {
88115 const stage = stageRef . current ;
@@ -183,6 +210,8 @@ const DiagramWrapper = ({ children }: DiagramWrapperProps) => {
183210 onDragStart = { onGrabbing }
184211 onDragEnd = { onGrabRelease }
185212 onWheel = { handleZooming }
213+ onMouseDown = { handleStagePointerDown }
214+ onTouchStart = { handleStagePointerDown }
186215 width = { windowWidth }
187216 height = { windowHeight }
188217 style = { { width : "fit-content" , backgroundColor : themeColors . bg } }
0 commit comments