feat(commands): add artboard bounds command
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { createInitialAppState } from "@editor/initial-state";
|
import { createInitialAppState } from "@editor/initial-state";
|
||||||
import { documentAddArtboardCommand } from "./document";
|
import { documentAddArtboardCommand, documentSetArtboardBoundsCommand } from "./document";
|
||||||
|
|
||||||
describe("document commands", () => {
|
describe("document commands", () => {
|
||||||
test("adds transparent artboard", () => {
|
test("adds transparent artboard", () => {
|
||||||
@@ -19,4 +19,15 @@ describe("document commands", () => {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("sets artboard bounds", () => {
|
||||||
|
const state = documentAddArtboardCommand.execute(
|
||||||
|
{ state: createInitialAppState("Test") },
|
||||||
|
{ id: "a1", name: "Artboard 1", bounds: { x: 0, y: 0, w: 320, h: 240 } },
|
||||||
|
);
|
||||||
|
|
||||||
|
const next = documentSetArtboardBoundsCommand.execute({ state }, { id: "a1", bounds: { x: 10, y: 20, w: 640, h: 480 } });
|
||||||
|
|
||||||
|
expect(next.document.artboards[0]?.bounds).toEqual({ x: 10, y: 20, w: 640, h: 480 });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ export type DocumentAddArtboardPayload = {
|
|||||||
bounds: Rect;
|
bounds: Rect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type DocumentSetArtboardBoundsPayload = {
|
||||||
|
id: ArtboardId;
|
||||||
|
bounds: Rect;
|
||||||
|
};
|
||||||
|
|
||||||
export const documentAddArtboardCommand: Command<DocumentAddArtboardPayload> = {
|
export const documentAddArtboardCommand: Command<DocumentAddArtboardPayload> = {
|
||||||
id: commandIds.documentAddArtboard,
|
id: commandIds.documentAddArtboard,
|
||||||
name: "Add artboard",
|
name: "Add artboard",
|
||||||
@@ -32,4 +37,20 @@ export const documentAddArtboardCommand: Command<DocumentAddArtboardPayload> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const documentCommands = [documentAddArtboardCommand] satisfies Command<unknown>[];
|
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>[];
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export const commandIds = {
|
export const commandIds = {
|
||||||
documentAddArtboard: "document.addArtboard",
|
documentAddArtboard: "document.addArtboard",
|
||||||
|
documentSetArtboardBounds: "document.setArtboardBounds",
|
||||||
selectionSet: "selection.set",
|
selectionSet: "selection.set",
|
||||||
selectionClear: "selection.clear",
|
selectionClear: "selection.clear",
|
||||||
selectionAddLayer: "selection.addLayer",
|
selectionAddLayer: "selection.addLayer",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { commandIds } from "./ids";
|
import { commandIds } from "./ids";
|
||||||
import type { DocumentAddArtboardPayload } from "./document";
|
import type { DocumentAddArtboardPayload, DocumentSetArtboardBoundsPayload } from "./document";
|
||||||
import type { SelectionAddLayerPayload, SelectionSetPayload } from "./selection";
|
import type { SelectionAddLayerPayload, SelectionSetPayload } from "./selection";
|
||||||
import type { ToolSetActivePayload } from "./tool";
|
import type { ToolSetActivePayload } from "./tool";
|
||||||
import type {
|
import type {
|
||||||
@@ -12,6 +12,7 @@ import type {
|
|||||||
|
|
||||||
export type CommandPayloads = {
|
export type CommandPayloads = {
|
||||||
[commandIds.documentAddArtboard]: DocumentAddArtboardPayload;
|
[commandIds.documentAddArtboard]: DocumentAddArtboardPayload;
|
||||||
|
[commandIds.documentSetArtboardBounds]: DocumentSetArtboardBoundsPayload;
|
||||||
[commandIds.selectionSet]: SelectionSetPayload;
|
[commandIds.selectionSet]: SelectionSetPayload;
|
||||||
[commandIds.selectionClear]: void;
|
[commandIds.selectionClear]: void;
|
||||||
[commandIds.selectionAddLayer]: SelectionAddLayerPayload;
|
[commandIds.selectionAddLayer]: SelectionAddLayerPayload;
|
||||||
|
|||||||
Reference in New Issue
Block a user