@@ -19,6 +19,7 @@ import type {
|
||||
TableData,
|
||||
ToolType,
|
||||
DocumentSettings,
|
||||
GalleryItem,
|
||||
} from "./editorStore.types";
|
||||
|
||||
const MAX_OBJECT_HISTORY = 50;
|
||||
@@ -56,6 +57,7 @@ export type {
|
||||
TableData,
|
||||
ToolType,
|
||||
DocumentSettings,
|
||||
GalleryItem,
|
||||
DisplayStyle,
|
||||
BackgroundType,
|
||||
EntranceAnimationType,
|
||||
@@ -149,6 +151,7 @@ type EditorStoreType = {
|
||||
loadPages: (
|
||||
pages: Page[],
|
||||
documentSettings?: Partial<DocumentSettings>,
|
||||
gallery?: GalleryItem[],
|
||||
) => void;
|
||||
resetEditor: () => void;
|
||||
clipboardObjects: EditorObject[];
|
||||
@@ -166,6 +169,10 @@ type EditorStoreType = {
|
||||
updateCurrentPageBackground: (
|
||||
updates: Partial<PageBackgroundSettings>,
|
||||
) => void;
|
||||
gallery: GalleryItem[];
|
||||
addGalleryItem: (item: GalleryItem) => void;
|
||||
removeGalleryItem: (id: string) => void;
|
||||
setGallery: (items: GalleryItem[]) => void;
|
||||
};
|
||||
|
||||
const DEFAULT_DOCUMENT_SETTINGS: DocumentSettings = {
|
||||
@@ -245,6 +252,14 @@ export const useEditorStore = create<EditorStoreType>((set, get) => {
|
||||
),
|
||||
};
|
||||
}),
|
||||
gallery: [],
|
||||
addGalleryItem: (item) =>
|
||||
set((state) => ({ gallery: [...state.gallery, item] })),
|
||||
removeGalleryItem: (id) =>
|
||||
set((state) => ({
|
||||
gallery: state.gallery.filter((item) => item.id !== id),
|
||||
})),
|
||||
setGallery: (items) => set({ gallery: items }),
|
||||
tool: "select",
|
||||
setTool: (tool) =>
|
||||
set((state) => ({
|
||||
@@ -999,9 +1014,10 @@ export const useEditorStore = create<EditorStoreType>((set, get) => {
|
||||
objectHistoryPast: [],
|
||||
objectHistoryFuture: [],
|
||||
documentSettings: { ...DEFAULT_DOCUMENT_SETTINGS },
|
||||
gallery: [],
|
||||
});
|
||||
},
|
||||
loadPages: (pages, documentSettings) => {
|
||||
loadPages: (pages, documentSettings, gallery) => {
|
||||
if (pages.length === 0) return;
|
||||
const fallbackSettings = documentSettings ?? {};
|
||||
const normalizedPages = pages.map((page) => ({
|
||||
@@ -1036,6 +1052,7 @@ export const useEditorStore = create<EditorStoreType>((set, get) => {
|
||||
...(documentSettings && {
|
||||
documentSettings: { ...currentSettings, ...documentSettings },
|
||||
}),
|
||||
...(gallery !== undefined && { gallery }),
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -120,3 +120,11 @@ export type DocumentSettings = {
|
||||
backgroundGradient?: LinearGradient;
|
||||
backgroundImageUrl: string;
|
||||
};
|
||||
|
||||
/** تصویر آپلودشده در گالری کاتالوگ (مشترک بین همهٔ صفحات) */
|
||||
export type GalleryItem = {
|
||||
id: string;
|
||||
url: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user