Skip to content

Commit 2bcb7d9

Browse files
authored
feat: Introduce CursorLayer (#149)
1 parent 0559302 commit 2bcb7d9

File tree

9 files changed

+458
-12
lines changed

9 files changed

+458
-12
lines changed

src/components/canvas/GraphComponent/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export class GraphComponent<
133133
return;
134134
}
135135
this.context.graph.getGraphLayer().captureEvents(this);
136+
this.context.graph.lockCursor("grabbing");
136137
const xy = getXY(this.context.canvas, event);
137138
startDragCoords = this.context.camera.applyToPoint(xy[0], xy[1]);
138139
})
@@ -150,6 +151,7 @@ export class GraphComponent<
150151
})
151152
.on(EVENTS.DRAG_END, (_event: MouseEvent) => {
152153
this.context.graph.getGraphLayer().releaseCapture();
154+
this.context.graph.unlockCursor();
153155
startDragCoords = undefined;
154156
onDrop?.(_event);
155157
});

src/components/canvas/blocks/Block.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export class Block<T extends TBlock = TBlock, Props extends TBlockProps = TBlock
9393
> {
9494
public static IS = IS_BLOCK_TYPE;
9595

96+
public cursor?: string = "pointer";
97+
9698
// from controller mixin
9799
public readonly isBlock = true;
98100

src/components/canvas/blocks/controllers/BlockController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ export class BlockController {
6161
dragListener(block.context.ownerDocument)
6262
.on(EVENTS.DRAG_START, (_event: MouseEvent) => {
6363
block.context.graph.getGraphLayer().captureEvents(block);
64+
block.context.graph.lockCursor("grabbing");
6465
dispatchEvents(draggingElements, createCustomDragEvent(EVENTS.DRAG_START, _event));
6566
})
6667
.on(EVENTS.DRAG_UPDATE, (_event: MouseEvent) => {
6768
dispatchEvents(draggingElements, createCustomDragEvent(EVENTS.DRAG_UPDATE, _event));
6869
})
6970
.on(EVENTS.DRAG_END, (_event: MouseEvent) => {
7071
block.context.graph.getGraphLayer().releaseCapture();
72+
block.context.graph.unlockCursor();
7173
dispatchEvents(draggingElements, createCustomDragEvent(EVENTS.DRAG_END, _event));
7274
});
7375
});

src/components/canvas/layers/connectionLayer/ConnectionLayer.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,16 @@ export class ConnectionLayer extends Layer<
200200
nativeEvent.stopPropagation();
201201
dragListener(this.root.ownerDocument)
202202
.on(EVENTS.DRAG_START, (dStartEvent: MouseEvent) => {
203+
this.context.graph.lockCursor("crosshair");
203204
this.onStartConnection(dStartEvent, this.context.graph.getPointInCameraSpace(dStartEvent));
204205
})
205206
.on(EVENTS.DRAG_UPDATE, (dUpdateEvent: MouseEvent) =>
206207
this.onMoveNewConnection(dUpdateEvent, this.context.graph.getPointInCameraSpace(dUpdateEvent))
207208
)
208-
.on(EVENTS.DRAG_END, (dEndEvent: MouseEvent) =>
209-
this.onEndNewConnection(this.context.graph.getPointInCameraSpace(dEndEvent))
210-
);
209+
.on(EVENTS.DRAG_END, (dEndEvent: MouseEvent) => {
210+
this.context.graph.unlockCursor();
211+
this.onEndNewConnection(this.context.graph.getPointInCameraSpace(dEndEvent));
212+
});
211213
}
212214
};
213215

0 commit comments

Comments
 (0)