fix ccolor one page

This commit is contained in:
hamid zarghami
2026-05-06 14:53:55 +03:30
parent b1068eec26
commit 8717afbced
7 changed files with 77 additions and 30 deletions
@@ -53,6 +53,9 @@ export const createInitialPage = (name: string): Page => ({
name,
objects: [],
guides: [],
backgroundType: "color",
backgroundColor: "#ffffff",
backgroundImageUrl: "",
});
export const reorderByIds = (
+28
View File
@@ -44,6 +44,11 @@ export type {
BackgroundType,
} from "./editorStore.types";
type PageBackgroundSettings = Pick<
Page,
"backgroundType" | "backgroundColor" | "backgroundImageUrl"
>;
type EditorStoreType = {
tool: ToolType;
setTool: (tool: ToolType) => void;
@@ -134,6 +139,7 @@ type EditorStoreType = {
sendObjectBackward: (id: string) => void;
documentSettings: DocumentSettings;
updateDocumentSettings: (updates: Partial<DocumentSettings>) => void;
updateCurrentPageBackground: (updates: Partial<PageBackgroundSettings>) => void;
};
export const useEditorStore = create<EditorStoreType>((set, get) => {
@@ -191,6 +197,18 @@ export const useEditorStore = create<EditorStoreType>((set, get) => {
set((state) => ({
documentSettings: { ...state.documentSettings, ...updates },
})),
updateCurrentPageBackground: (updates) =>
set((state) => {
if (!state.currentPageId) return {};
const currentPage = state.pages.find((p) => p.id === state.currentPageId);
if (!currentPage) return {};
const nextPage = { ...currentPage, ...updates };
return {
pages: state.pages.map((p) =>
p.id === state.currentPageId ? nextPage : p,
),
};
}),
tool: "select",
setTool: (tool) =>
set((state) => ({
@@ -816,6 +834,9 @@ export const useEditorStore = create<EditorStoreType>((set, get) => {
name: `${pageToDuplicate.name} (کپی)`,
objects: duplicatedObjects,
guides: [...pageToDuplicate.guides],
backgroundType: pageToDuplicate.backgroundType,
backgroundColor: pageToDuplicate.backgroundColor,
backgroundImageUrl: pageToDuplicate.backgroundImageUrl,
};
set((state) => ({
@@ -978,11 +999,18 @@ export const useEditorStore = create<EditorStoreType>((set, get) => {
},
loadPages: (pages, documentSettings) => {
if (pages.length === 0) return;
const fallbackSettings = documentSettings ?? {};
const normalizedPages = pages.map((page) => ({
...page,
id: isInvalidPageId(page.id) ? createScopedId("page") : page.id,
guides: page.guides || [],
objects: ensureMissingGroupObjects(page.objects || []),
backgroundType:
page.backgroundType ?? fallbackSettings.backgroundType ?? "color",
backgroundColor:
page.backgroundColor ?? fallbackSettings.backgroundColor ?? "#ffffff",
backgroundImageUrl:
page.backgroundImageUrl ?? fallbackSettings.backgroundImageUrl ?? "",
}));
const firstPage = normalizedPages[0];
const currentSettings = get().documentSettings;
@@ -80,6 +80,9 @@ export type Page = {
name: string;
objects: EditorObject[];
guides: PageGuide[];
backgroundType: BackgroundType;
backgroundColor: string;
backgroundImageUrl: string;
};
export type DisplayStyle = 'single' | 'double';