moving grouop
This commit is contained in:
@@ -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 = () => {
|
||||
|
||||
@@ -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