Skip to content

Commit 3181f60

Browse files
committed
feat: 处理selector可用性
1 parent 14b0302 commit 3181f60

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

packages/core/src/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export class App extends BaseService<EventArgs> {
5353
});
5454
}
5555

56+
public triggerSelector(): void {}
57+
5658
public setTool(curTool: Tool): void {
5759
const oldTool = this.currentTool;
5860
if (oldTool) {

packages/core/src/services/mouse.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Konva from 'konva';
2-
31
import { App } from '../app';
42
import { KonvaMouseEvent, Service } from '../types';
53

@@ -48,12 +46,6 @@ export class Mouse extends Service {
4846

4947
private onMouseMove(event: KonvaMouseEvent): void {
5048
this.app.emit('mouse:move', { event });
51-
if (event.target instanceof Konva.Stage) {
52-
document.body.style.cursor = 'default';
53-
} else {
54-
document.body.style.cursor = 'move';
55-
}
56-
5749
if (!this.app.currentTool || !this.app.currentTool.onMouseMove) {
5850
return;
5951
}

packages/core/src/services/selector.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ export class Selector extends Service {
7171
}
7272

7373
public select(...children: ChildType[]): void {
74+
if (!this.enable) {
75+
return;
76+
}
7477
this.selected.forEach((child) => child.draggable(false));
7578
this.selected = [];
7679
this.selector.nodes([]);
@@ -83,11 +86,22 @@ export class Selector extends Service {
8386
}
8487

8588
private onMouseDown(): void {
89+
if (!this.enable) {
90+
return;
91+
}
8692
this.rubberStartPoint.clone(this.app.pointer);
8793
this.rubberRect.setPosition(this.rubberStartPoint);
8894
}
8995

90-
private onMouseMove(): void {
96+
private onMouseMove({ event }: EventArgs['mouse:move']): void {
97+
if (!this.enable) {
98+
return;
99+
}
100+
if (event.target instanceof Konva.Stage) {
101+
document.body.style.cursor = 'default';
102+
} else {
103+
document.body.style.cursor = 'move';
104+
}
91105
const position = new Point(
92106
Math.min(this.app.pointer.x, this.rubberStartPoint.x),
93107
Math.min(this.app.pointer.y, this.rubberStartPoint.y)
@@ -101,10 +115,16 @@ export class Selector extends Service {
101115
}
102116

103117
private onMouseUp(): void {
118+
if (!this.enable) {
119+
return;
120+
}
104121
this.rubberRect.visible(false);
105122
}
106123

107124
private onMouseClick({ event }: EventArgs['mouse:click']): void {
125+
if (!this.enable) {
126+
return;
127+
}
108128
if (event.target instanceof Konva.Stage) {
109129
this.select();
110130
} else {
@@ -118,6 +138,7 @@ export class Selector extends Service {
118138
this.app.off('mouse:up', this.onMouseUp);
119139
this.app.off('mouse:click', this.onMouseClick);
120140
this.selected = [];
141+
this.enable = false;
121142
this.selector.destroy();
122143
this.optionLayer.destroy();
123144
}

0 commit comments

Comments
 (0)