feat: add project management features including open/save functionality and recovery support

This commit is contained in:
syntaxbullet
2026-07-10 23:46:01 +02:00
parent 6d652c3264
commit 9697075d29
15 changed files with 613 additions and 2 deletions

37
commands/project.ts Normal file
View File

@@ -0,0 +1,37 @@
import type { ImageDocument } from "@core/document";
import { initialEditorState } from "@editor/initial-state";
import type { Command } from "./command";
import { commandIds } from "./ids";
export type ProjectOpenPayload = { document: ImageDocument };
export const projectOpenCommand: Command<ProjectOpenPayload> = {
id: commandIds.projectOpen,
name: "Open project",
history: { mode: "ignore" },
execute({ state }, payload) {
const firstArtboard = payload.document.artboards[0];
const viewport = state.editor.viewport;
const padding = 48;
const availableWidth = Math.max(0, viewport.size.w - padding * 2);
const availableHeight = Math.max(0, viewport.size.h - padding * 2);
const canFit = Boolean(firstArtboard && availableWidth > 0 && availableHeight > 0 && firstArtboard.bounds.w > 0 && firstArtboard.bounds.h > 0);
return {
document: payload.document,
editor: {
...initialEditorState,
viewport: {
...viewport,
center: firstArtboard
? { x: firstArtboard.bounds.x + firstArtboard.bounds.w / 2, y: firstArtboard.bounds.y + firstArtboard.bounds.h / 2 }
: viewport.center,
zoom: canFit && firstArtboard ? Math.max(0.01, Math.min(availableWidth / firstArtboard.bounds.w, availableHeight / firstArtboard.bounds.h)) : viewport.zoom,
},
selection: { artboardId: firstArtboard?.id, layerIds: [] },
},
history: { past: [], future: [] },
};
},
};
export const projectCommands = [projectOpenCommand] satisfies Command<unknown>[];