feat: implement document actions for managing artboards, zoom, and history; update UI components to utilize new actions
This commit is contained in:
58
app/document-actions.ts
Normal file
58
app/document-actions.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { commandIds } from "@commands/ids";
|
||||
import type { ArtboardId } from "@core/id";
|
||||
import type { AppStore } from "@editor/store";
|
||||
import { downloadArtboardPng } from "@operations/export/downloadArtboard";
|
||||
import type { GenerationWorkflow } from "@operations/generation/workflow";
|
||||
|
||||
export type DocumentActions = ReturnType<typeof createDocumentActions>;
|
||||
|
||||
export function createDocumentActions(store: AppStore, generation: GenerationWorkflow) {
|
||||
return {
|
||||
openGenerate() {
|
||||
store.dispatch(commandIds.workspaceSetPanel, { panel: "generate" });
|
||||
},
|
||||
|
||||
generate() {
|
||||
return generation.generate();
|
||||
},
|
||||
|
||||
exportArtboard(artboardId?: ArtboardId) {
|
||||
const state = store.getState();
|
||||
const resolvedId = artboardId ?? state.editor.selection.artboardId;
|
||||
const artboard = resolvedId
|
||||
? state.document.artboards.find((candidate) => candidate.id === resolvedId)
|
||||
: state.document.artboards[0];
|
||||
if (!artboard) return Promise.resolve();
|
||||
return downloadArtboardPng(artboard, state.document.assets);
|
||||
},
|
||||
|
||||
fitArtboard(artboardId?: ArtboardId) {
|
||||
store.dispatch(commandIds.viewportFitArtboard, artboardId ? { artboardId } : undefined);
|
||||
},
|
||||
|
||||
zoomBy(factor: number) {
|
||||
const zoom = store.getState().editor.viewport.zoom;
|
||||
store.dispatch(commandIds.viewportSetZoom, { zoom: zoom * factor });
|
||||
},
|
||||
|
||||
zoomTo(zoom: number) {
|
||||
store.dispatch(commandIds.viewportSetZoom, { zoom });
|
||||
},
|
||||
|
||||
undo() {
|
||||
store.dispatch(commandIds.historyUndo, undefined);
|
||||
},
|
||||
|
||||
canUndo() {
|
||||
return store.getState().history.past.length > 0;
|
||||
},
|
||||
|
||||
redo() {
|
||||
store.dispatch(commandIds.historyRedo, undefined);
|
||||
},
|
||||
|
||||
canRedo() {
|
||||
return store.getState().history.future.length > 0;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user