moving grouop
This commit is contained in:
@@ -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<EditorObject>) => {
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user