Files
web-cad/frontend/src/tools/drawing/PolylineTool.ts
T
Agent Zero 05ccebad8d Replace frontend with deployed TS version from a08dd73
- Restore TS frontend source (canvas, tools, CRDT, components, services)
- Keep 5 JSX components that TS code depends on (CADCanvas, LayerPanel, BlockLibrary, PluginRegistry, Toolbar)
- Keep JS services (api.js, blockService.js) that components depend on
- Fix vite/plugin-react version mismatch (downgrade to v4 for vite 6)
- Add axios dependency
- Skip tsc in build script (vite/esbuild handles transpilation)
- Fix index.html lang=de, favicon path
- Add vite proxy config for /api and /ws
- Backend unchanged (already from deployed containers)
2026-06-28 02:16:58 +02:00

51 lines
1.2 KiB
TypeScript

import { Tool } from '../Tool';
import { YjsDocument } from '../../crdt/YjsDocument';
class PolylineTool extends Tool {
private points: Array<{ x: number; y: number }> = [];
private isDrawing: boolean = false;
constructor(yjsDoc: YjsDocument) {
super(yjsDoc);
this.name = 'PolylineTool';
}
onMouseDown(event: MouseEvent): void {
if (!this.isDrawing) {
// Start drawing
this.isDrawing = true;
this.points = [{ x: event.clientX, y: event.clientY }];
} else {
// Add point to polyline
this.points.push({ x: event.clientX, y: event.clientY });
// If shift key is not pressed, finish the polyline
if (!event.shiftKey) {
this.yjsDoc.createPolyline([...this.points]);
this.reset();
}
}
}
onMouseMove(event: MouseEvent): void {
// Preview polyline while drawing
}
onMouseUp(event: MouseEvent): void {
// Handle mouse up if needed
}
onKeyUp(event: KeyboardEvent): void {
// Handle key up events
if (event.key === 'Escape') {
this.reset();
}
}
reset(): void {
this.points = [];
this.isDrawing = false;
}
}
export { PolylineTool };