mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 02:56:23 +08:00
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import {
|
|
Utils,
|
|
TLPointerEventHandler,
|
|
TLBoundsCorner,
|
|
TLBoundsHandleEventHandler,
|
|
} from '@tldraw/core';
|
|
import Vec from '@tldraw/vec';
|
|
import { Frame } from '@toeverything/components/board-shapes';
|
|
import { SessionType, TDShapeType } from '@toeverything/components/board-types';
|
|
import { BaseTool, BaseToolStatus } from '@toeverything/components/board-state';
|
|
|
|
export class FrameTool extends BaseTool {
|
|
override type = TDShapeType.Frame as const;
|
|
/* ----------------- Event Handlers ----------------- */
|
|
|
|
override onPointerDown: TLPointerEventHandler = () => {
|
|
if (this.status !== BaseToolStatus.Idle) return;
|
|
const {
|
|
currentPoint,
|
|
currentGrid,
|
|
settings: { showGrid },
|
|
appState: { currentPageId, currentStyle },
|
|
document: { id: workspace },
|
|
} = this.app;
|
|
|
|
const childIndex = 0;
|
|
|
|
const id = Utils.uniqueId();
|
|
|
|
const newShape = Frame.create({
|
|
id,
|
|
parentId: currentPageId,
|
|
childIndex,
|
|
point: showGrid
|
|
? Vec.snap(currentPoint, currentGrid)
|
|
: currentPoint,
|
|
style: { ...currentStyle },
|
|
workspace,
|
|
});
|
|
|
|
this.app.patchCreate([newShape]);
|
|
|
|
this.app.startSession(
|
|
SessionType.TransformSingle,
|
|
newShape.id,
|
|
TLBoundsCorner.BottomRight,
|
|
true
|
|
);
|
|
|
|
this.set_status(BaseToolStatus.Creating);
|
|
};
|
|
}
|