57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import type { Rect } from "@core/geometry";
|
|
import type { ArtboardId } from "@core/id";
|
|
import type { Command } from "./command";
|
|
import { commandIds } from "./ids";
|
|
|
|
export type DocumentAddArtboardPayload = {
|
|
id: ArtboardId;
|
|
name: string;
|
|
bounds: Rect;
|
|
};
|
|
|
|
export type DocumentSetArtboardBoundsPayload = {
|
|
id: ArtboardId;
|
|
bounds: Rect;
|
|
};
|
|
|
|
export const documentAddArtboardCommand: Command<DocumentAddArtboardPayload> = {
|
|
id: commandIds.documentAddArtboard,
|
|
name: "Add artboard",
|
|
execute({ state }, payload) {
|
|
return {
|
|
...state,
|
|
document: {
|
|
...state.document,
|
|
artboards: [
|
|
...state.document.artboards,
|
|
{
|
|
id: payload.id,
|
|
name: payload.name,
|
|
bounds: payload.bounds,
|
|
backgroundColor: "transparent",
|
|
layers: [],
|
|
},
|
|
],
|
|
},
|
|
};
|
|
},
|
|
};
|
|
|
|
export const documentSetArtboardBoundsCommand: Command<DocumentSetArtboardBoundsPayload> = {
|
|
id: commandIds.documentSetArtboardBounds,
|
|
name: "Set artboard bounds",
|
|
execute({ state }, payload) {
|
|
return {
|
|
...state,
|
|
document: {
|
|
...state.document,
|
|
artboards: state.document.artboards.map((artboard) =>
|
|
artboard.id === payload.id ? { ...artboard, bounds: { ...payload.bounds } } : artboard,
|
|
),
|
|
},
|
|
};
|
|
},
|
|
};
|
|
|
|
export const documentCommands = [documentAddArtboardCommand, documentSetArtboardBoundsCommand] satisfies Command<unknown>[];
|