moving grouop
This commit is contained in:
@@ -295,6 +295,14 @@ const EditorCanvas = ({ catalogSize }: EditorCanvasProps) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateActiveGuides(snapped.activeGuideIds);
|
updateActiveGuides(snapped.activeGuideIds);
|
||||||
|
|
||||||
|
// گروه فقط باکس انتخاب را درگ میکند؛ اعضا با مختصات مطلق جدا رسم میشوند — در حین drag باید استور همگام شود
|
||||||
|
if (node.name() === "group-container") {
|
||||||
|
handleObjectUpdate(node.id(), {
|
||||||
|
x: snapped.position.x,
|
||||||
|
y: snapped.position.y,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDragEnd = () => {
|
const handleDragEnd = () => {
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
import { useEditorStore, type EditorObject } from "../../store/editorStore";
|
import { useEditorStore, type EditorObject } from "../../store/editorStore";
|
||||||
|
|
||||||
export const useObjectHandlers = () => {
|
export const useObjectHandlers = () => {
|
||||||
const { objects, updateObject, groupObjects, ungroupObjects, updateCellValue, setEditingCell, editingCell } =
|
const { updateObject, groupObjects, ungroupObjects, updateCellValue, setEditingCell, editingCell } =
|
||||||
useEditorStore();
|
useEditorStore();
|
||||||
|
|
||||||
const handleObjectUpdate = (id: string, updates: Partial<EditorObject>) => {
|
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;
|
if (!obj) return;
|
||||||
|
|
||||||
// اگر group object است و position تغییر کرد، همه objectهای داخل group را جابجا کن
|
// اگر group object است و position تغییر کرد، همه objectهای داخل group را جابجا کن
|
||||||
if (obj.type === "group" && (updates.x !== undefined || updates.y !== undefined)) {
|
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 deltaX = updates.x !== undefined ? updates.x - (obj.x || 0) : 0;
|
||||||
const deltaY = updates.y !== undefined ? updates.y - (obj.y || 0) : 0;
|
const deltaY = updates.y !== undefined ? updates.y - (obj.y || 0) : 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user