diff --git a/src/pages/editor/components/EditorCanvas.tsx b/src/pages/editor/components/EditorCanvas.tsx index 91331d5..28d7ffc 100644 --- a/src/pages/editor/components/EditorCanvas.tsx +++ b/src/pages/editor/components/EditorCanvas.tsx @@ -295,6 +295,14 @@ const EditorCanvas = ({ catalogSize }: EditorCanvasProps) => { } updateActiveGuides(snapped.activeGuideIds); + + // گروه فقط باکس انتخاب را درگ می‌کند؛ اعضا با مختصات مطلق جدا رسم می‌شوند — در حین drag باید استور هم‌گام شود + if (node.name() === "group-container") { + handleObjectUpdate(node.id(), { + x: snapped.position.x, + y: snapped.position.y, + }); + } }; const handleDragEnd = () => { diff --git a/src/pages/editor/components/canvas/useObjectHandlers.ts b/src/pages/editor/components/canvas/useObjectHandlers.ts index 90b42ea..4a0ed11 100644 --- a/src/pages/editor/components/canvas/useObjectHandlers.ts +++ b/src/pages/editor/components/canvas/useObjectHandlers.ts @@ -1,16 +1,18 @@ import { useEditorStore, type EditorObject } from "../../store/editorStore"; export const useObjectHandlers = () => { - const { objects, updateObject, groupObjects, ungroupObjects, updateCellValue, setEditingCell, editingCell } = + const { updateObject, groupObjects, ungroupObjects, updateCellValue, setEditingCell, editingCell } = useEditorStore(); const handleObjectUpdate = (id: string, updates: Partial) => { - const obj = objects.find((o) => o.id === id); + // همیشه آخرین state را بخوان تا چند dragmove پشت‌سرهم قبل از رِندر React، دلتا درست بماند + const liveObjects = useEditorStore.getState().objects; + const obj = liveObjects.find((o) => o.id === id); if (!obj) return; // اگر group object است و position تغییر کرد، همه objectهای داخل group را جابجا کن if (obj.type === "group" && (updates.x !== undefined || updates.y !== undefined)) { - const groupMembers = objects.filter((o) => o.groupId === id); + const groupMembers = liveObjects.filter((o) => o.groupId === id); const deltaX = updates.x !== undefined ? updates.x - (obj.x || 0) : 0; const deltaY = updates.y !== undefined ? updates.y - (obj.y || 0) : 0;