hide object and show

This commit is contained in:
hamid zarghami
2025-12-31 16:08:55 +03:30
parent d17b7c3dc5
commit 1906e404f0
3 changed files with 50 additions and 3 deletions
+38
View File
@@ -59,6 +59,7 @@ export type EditorObject = {
scaleY?: number;
shapeType?: ShapeType;
tableData?: TableData;
visible?: boolean;
};
export type Page = {
@@ -132,6 +133,7 @@ type EditorStoreType = {
deletePage: (pageId: string) => void;
setCurrentPage: (pageId: string) => void;
updatePageName: (pageId: string, name: string) => void;
toggleObjectVisibility: (id: string) => void;
};
const createTableCellId = (row: number, col: number) => `cell-${row}-${col}`;
@@ -600,5 +602,41 @@ export const useEditorStore = create<EditorStoreType>((set, get) => {
pages: state.pages.map((p) => (p.id === pageId ? { ...p, name } : p)),
}));
},
toggleObjectVisibility: (id) => {
const state = get();
const obj = state.objects.find((o) => o.id === id);
if (!obj) return;
const newVisible = !(obj.visible ?? true);
const shouldDeselect = !newVisible && (state.selectedObjectId === id || state.selectedTableId === id);
if (state.currentPageId) {
set((state) => ({
objects: state.objects.map((obj) =>
obj.id === id ? { ...obj, visible: newVisible } : obj
),
pages: state.pages.map((p) =>
p.id === state.currentPageId
? {
...p,
objects: p.objects.map((obj) =>
obj.id === id ? { ...obj, visible: newVisible } : obj
),
}
: p
),
selectedObjectId: shouldDeselect ? null : state.selectedObjectId,
selectedTableId: shouldDeselect ? null : state.selectedTableId,
}));
return;
}
set((state) => ({
objects: state.objects.map((obj) =>
obj.id === id ? { ...obj, visible: newVisible } : obj
),
selectedObjectId: shouldDeselect ? null : state.selectedObjectId,
selectedTableId: shouldDeselect ? null : state.selectedTableId,
}));
},
};
});