mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 10:36:22 +08:00
init: the first public commit for AFFiNE
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user