fix grid add text

This commit is contained in:
hamid zarghami
2025-12-31 14:31:37 +03:30
parent 1ba62b0cee
commit 828ba0c7c1
4 changed files with 33 additions and 32 deletions
+13 -10
View File
@@ -7,7 +7,7 @@ type TableProps = {
obj: EditorObject;
selectedCellId: string | null;
onCellClick: (tableId: string, cellId: string, node: Konva.Node) => void;
onCellDblClick: (tableId: string, cellId: string, x: number, y: number, text: string) => void;
onCellDblClick: (tableId: string, cellId: string, x: number, y: number, width: number, height: number, text: string) => void;
onDragEnd: (tableId: string, x: number, y: number) => void;
draggable: boolean;
};
@@ -48,17 +48,20 @@ const Table = ({
const cell = cells[cellId];
if (!cell) return;
const row = parseInt(cellId.split("-")[1]);
const col = parseInt(cellId.split("-")[2]);
const cellX = col * cellWidth;
const cellY = row * cellHeight;
const groupPos = groupRef.current.getAbsolutePosition();
// Get the target node (Rect or Text)
const targetNode = e.target;
// Get the client rect which includes all transformations (scale, position, etc.)
const box = targetNode.getClientRect();
const stageBox = stage.container().getBoundingClientRect();
const x = stageBox.left + groupPos.x + cellX;
const y = stageBox.top + groupPos.y + cellY;
// Calculate position relative to viewport
const x = stageBox.left + box.x;
const y = stageBox.top + box.y;
const width = box.width;
const height = box.height;
onCellDblClick(obj.id, cellId, x, y, cell.text);
onCellDblClick(obj.id, cellId, x, y, width, height, cell.text);
};
const handleDragEnd = () => {