This commit is contained in:
hamid zarghami
2026-01-04 11:27:53 +03:30
parent aa6153d289
commit 0c6bf2b52b
12 changed files with 758 additions and 291 deletions
+52
View File
@@ -62,6 +62,9 @@ export type EditorObject = {
visible?: boolean;
isMask?: boolean;
showMaskGuide?: boolean;
maskId?: string; // Reference to mask shape (DATA only, NO rendering logic)
maskInvert?: boolean; // اگر true: overlap مخفی می‌شود، اگر false: overlap نمایش داده می‌شود
groupId?: string;
};
export type Page = {
@@ -136,6 +139,8 @@ type EditorStoreType = {
setCurrentPage: (pageId: string) => void;
updatePageName: (pageId: string, name: string) => void;
toggleObjectVisibility: (id: string) => void;
groupObjects: (objectIds: string[]) => void;
ungroupObjects: (groupId: string) => void;
};
const createTableCellId = (row: number, col: number) => `cell-${row}-${col}`;
@@ -640,5 +645,52 @@ export const useEditorStore = create<EditorStoreType>((set, get) => {
selectedTableId: shouldDeselect ? null : state.selectedTableId,
}));
},
groupObjects: (objectIds) => {
const state = get();
if (objectIds.length < 2) return;
const groupId = `group-${crypto.randomUUID()}`;
const updateObjects = (objects: EditorObject[]) =>
objects.map((obj) =>
objectIds.includes(obj.id) ? { ...obj, groupId } : obj
);
if (state.currentPageId) {
set((state) => ({
objects: updateObjects(state.objects),
pages: state.pages.map((p) =>
p.id === state.currentPageId
? { ...p, objects: updateObjects(p.objects) }
: p
),
}));
return;
}
set((state) => ({
objects: updateObjects(state.objects),
}));
},
ungroupObjects: (groupId) => {
const state = get();
const updateObjects = (objects: EditorObject[]) =>
objects.map((obj) =>
obj.groupId === groupId ? { ...obj, groupId: undefined } : obj
);
if (state.currentPageId) {
set((state) => ({
objects: updateObjects(state.objects),
pages: state.pages.map((p) =>
p.id === state.currentPageId
? { ...p, objects: updateObjects(p.objects) }
: p
),
}));
return;
}
set((state) => ({
objects: updateObjects(state.objects),
}));
},
};
});