32 lines
738 B
TypeScript
32 lines
738 B
TypeScript
|
|
import { Tool } from '../Tool';
|
||
|
|
import { YjsDocument } from '../../crdt/YjsDocument';
|
||
|
|
|
||
|
|
class TextTool extends Tool {
|
||
|
|
constructor(yjsDoc: YjsDocument) {
|
||
|
|
super(yjsDoc);
|
||
|
|
this.name = 'TextTool';
|
||
|
|
}
|
||
|
|
|
||
|
|
onMouseDown(event: MouseEvent): void {
|
||
|
|
// Get text input from user
|
||
|
|
const text = prompt('Enter text:');
|
||
|
|
if (text !== null && text !== '') {
|
||
|
|
// Create text element in Yjs document
|
||
|
|
this.yjsDoc.createText(event.clientX, event.clientY, text);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
onMouseMove(event: MouseEvent): void {
|
||
|
|
// No preview needed for text tool
|
||
|
|
}
|
||
|
|
|
||
|
|
onMouseUp(event: MouseEvent): void {
|
||
|
|
// Handle mouse up if needed
|
||
|
|
}
|
||
|
|
|
||
|
|
onKeyUp(event: KeyboardEvent): void {
|
||
|
|
// Handle key up events
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export { TextTool };
|