Files
OpenCut/apps/web/src/stores/editor-store.ts
T

71 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-07-24 14:41:34 -07:00
import { create } from "zustand";
import { persist } from "zustand/middleware";
2026-01-31 00:20:04 +01:00
import type { TPlatformLayout } from "@/types/editor";
import { DEFAULT_CANVAS_PRESETS } from "@/constants/project-constants";
import type { TCanvasSize } from "@/types/project";
2025-08-04 17:17:48 +02:00
interface LayoutGuideSettings {
2026-01-31 00:20:04 +01:00
platform: TPlatformLayout | null;
2025-08-04 17:17:48 +02:00
}
2025-07-24 14:41:34 -07:00
interface EditorState {
2026-01-31 00:20:04 +01:00
isInitializing: boolean;
isPanelsReady: boolean;
canvasPresets: TCanvasSize[];
layoutGuide: LayoutGuideSettings;
setInitializing: (loading: boolean) => void;
setPanelsReady: (ready: boolean) => void;
initializeApp: () => Promise<void>;
setLayoutGuide: (settings: Partial<LayoutGuideSettings>) => void;
toggleLayoutGuide: (platform: TPlatformLayout) => void;
2025-07-24 14:41:34 -07:00
}
export const useEditorStore = create<EditorState>()(
2026-01-31 00:20:04 +01:00
persist(
(set) => ({
isInitializing: true,
isPanelsReady: false,
canvasPresets: DEFAULT_CANVAS_PRESETS,
layoutGuide: {
platform: null,
},
setInitializing: (loading) => {
set({ isInitializing: loading });
},
2025-08-04 17:17:48 +02:00
2026-01-31 00:20:04 +01:00
setPanelsReady: (ready) => {
set({ isPanelsReady: ready });
},
2026-01-31 00:20:04 +01:00
initializeApp: async () => {
set({ isInitializing: true, isPanelsReady: false });
2026-01-31 00:20:04 +01:00
set({ isPanelsReady: true, isInitializing: false });
},
2026-01-31 00:20:04 +01:00
setLayoutGuide: (settings) => {
set((state) => ({
layoutGuide: {
...state.layoutGuide,
...settings,
},
}));
},
2026-01-31 00:20:04 +01:00
toggleLayoutGuide: (platform) => {
set((state) => ({
layoutGuide: {
platform: state.layoutGuide.platform === platform ? null : platform,
},
}));
},
}),
{
name: "editor-settings",
partialize: (state) => ({
layoutGuide: state.layoutGuide,
}),
},
),
);