fix grid add text
This commit is contained in:
+13
-10
@@ -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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user