mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
init: the first public commit for AFFiNE
This commit is contained in:
1
libs/components/board-tools/src/laser-tool/index.ts
Normal file
1
libs/components/board-tools/src/laser-tool/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './laser-tool';
|
||||
69
libs/components/board-tools/src/laser-tool/laser-tool.ts
Normal file
69
libs/components/board-tools/src/laser-tool/laser-tool.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { TLPointerEventHandler } from '@tldraw/core';
|
||||
// import { Draw } from '@toeverything/components/board-shapes';
|
||||
import { Vec } from '@tldraw/vec';
|
||||
|
||||
import { SessionType, TDShapeType } from '@toeverything/components/board-types';
|
||||
import { BaseTool } from '@toeverything/components/board-state';
|
||||
|
||||
enum Status {
|
||||
Idle = 'idle',
|
||||
Pointing = 'pointing',
|
||||
Laser = 'laser',
|
||||
}
|
||||
|
||||
export class LaserTool extends BaseTool {
|
||||
override type = TDShapeType.Laser as const;
|
||||
|
||||
override status: Status = Status.Idle;
|
||||
|
||||
/* ----------------- Event Handlers ----------------- */
|
||||
|
||||
override onPointerDown: TLPointerEventHandler = () => {
|
||||
if (this.app.readOnly) return;
|
||||
if (this.status !== Status.Idle) return;
|
||||
|
||||
this.set_status(Status.Pointing);
|
||||
};
|
||||
|
||||
override onPointerMove: TLPointerEventHandler = info => {
|
||||
if (this.app.readOnly) return;
|
||||
switch (this.status) {
|
||||
case Status.Pointing: {
|
||||
if (Vec.dist(info.origin, info.point) > 3) {
|
||||
this.app.startSession(SessionType.Laser);
|
||||
this.app.updateSession();
|
||||
this.set_status(Status.Laser);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Status.Laser: {
|
||||
this.app.updateSession();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
override onPointerUp: TLPointerEventHandler = () => {
|
||||
if (this.app.readOnly) return;
|
||||
switch (this.status) {
|
||||
case Status.Laser: {
|
||||
this.app.completeSession();
|
||||
}
|
||||
}
|
||||
|
||||
this.set_status(Status.Idle);
|
||||
};
|
||||
|
||||
override onCancel = () => {
|
||||
if (this.status === Status.Idle) {
|
||||
if (this.previous) {
|
||||
this.app.selectTool(this.previous);
|
||||
} else {
|
||||
this.app.selectTool('select');
|
||||
}
|
||||
} else {
|
||||
this.set_status(Status.Idle);
|
||||
}
|
||||
|
||||
this.app.cancelSession();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user