Skip to content

Commit 6b03a6d

Browse files
authored
fix: cursorLayer blocking propagation events (#153)
1 parent a40d43b commit 6b03a6d

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/components/canvas/layers/cursorLayer/CursorLayer.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,15 @@ export type TCursorLayerProps = LayerProps & {
6161
* Context provided to CursorLayer during rendering.
6262
*/
6363
export type TCursorLayerContext = LayerContext & {
64-
html: HTMLDivElement;
6564
graph: Graph;
6665
};
6766

6867
/**
6968
* CursorLayer provides cursor management for graph components.
7069
*
71-
* This layer solves performance issues with cursor changes by using a dedicated
72-
* HTML overlay instead of modifying the root element's cursor style, which can
73-
* cause expensive style recalculations.
70+
* This layer manages cursor changes by applying cursor styles directly to the
71+
* graph root element, avoiding event blocking issues while maintaining
72+
* performance.
7473
*
7574
* ## Features:
7675
* - **Automatic mode**: Dynamically sets cursor based on component under mouse
@@ -82,8 +81,8 @@ export type TCursorLayerContext = LayerContext & {
8281
* graph.getCursorLayer().isAuto(); // true
8382
*
8483
* // Manual mode
85-
* graph.setCursor("grabbing");
86-
* graph.unsetCursor(); // returns to auto mode
84+
* graph.lockCursor("grabbing");
85+
* graph.unlockCursor(); // returns to auto mode
8786
* ```
8887
*
8988
* @example
@@ -95,10 +94,10 @@ export type TCursorLayerContext = LayerContext & {
9594
* console.log(cursorLayer.getMode()); // "auto" | "manual"
9695
*
9796
* // Set manual cursor
98-
* cursorLayer.setCursor("wait");
97+
* cursorLayer.lockCursor("wait");
9998
*
10099
* // Return to automatic behavior
101-
* cursorLayer.unsetCursor();
100+
* cursorLayer.unlockCursor();
102101
* ```
103102
*/
104103
export class CursorLayer extends Layer<TCursorLayerProps, TCursorLayerContext> {
@@ -118,10 +117,7 @@ export class CursorLayer extends Layer<TCursorLayerProps, TCursorLayerContext> {
118117
*/
119118
constructor(props: TCursorLayerProps) {
120119
super({
121-
html: {
122-
zIndex: 1000, // Above all other layers
123-
classNames: ["cursor-layer"],
124-
},
120+
// No HTML element needed - we'll apply cursor to the root element
125121
...props,
126122
});
127123
}
@@ -186,15 +182,23 @@ export class CursorLayer extends Layer<TCursorLayerProps, TCursorLayerContext> {
186182
}
187183

188184
/**
189-
* Applies the specified cursor to the HTML layer element.
185+
* Applies the specified cursor to the graph root element.
190186
*
191187
* @param cursor - The cursor type to apply
192188
* @private
193189
*/
194190
private applyCursor(cursor: CursorLayerCursorTypes): void {
195-
const htmlElement = this.getHTML();
196-
if (htmlElement) {
197-
htmlElement.style.cursor = cursor;
191+
const rootElement = this.props.graph.layers.$root;
192+
if (rootElement) {
193+
rootElement.style.cursor = cursor;
194+
}
195+
}
196+
197+
protected unmountLayer(): void {
198+
super.unmountLayer();
199+
const rootElement = this.props.graph.layers.$root;
200+
if (rootElement) {
201+
rootElement.style.cursor = "auto";
198202
}
199203
}
200204

0 commit comments

Comments
 (0)