feat(commands): add transparent artboard creation
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { documentCommands } from "@commands/document";
|
||||||
import { createCommandRegistry } from "@commands/registry";
|
import { createCommandRegistry } from "@commands/registry";
|
||||||
import { selectionCommands } from "@commands/selection";
|
import { selectionCommands } from "@commands/selection";
|
||||||
import { viewportCommands } from "@commands/viewport";
|
import { viewportCommands } from "@commands/viewport";
|
||||||
@@ -7,7 +8,7 @@ import { createAppStore } from "@editor/store";
|
|||||||
export type ImageStudioApp = ReturnType<typeof createImageStudioApp>;
|
export type ImageStudioApp = ReturnType<typeof createImageStudioApp>;
|
||||||
|
|
||||||
export function createImageStudioApp(options?: { documentName?: string }) {
|
export function createImageStudioApp(options?: { documentName?: string }) {
|
||||||
const registry = createCommandRegistry([...viewportCommands, ...selectionCommands]);
|
const registry = createCommandRegistry([...viewportCommands, ...selectionCommands, ...documentCommands]);
|
||||||
const store = createAppStore(createInitialAppState(options?.documentName), registry);
|
const store = createAppStore(createInitialAppState(options?.documentName), registry);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
22
commands/document.test.ts
Normal file
22
commands/document.test.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { describe, expect, test } from "bun:test";
|
||||||
|
import { createInitialAppState } from "@editor/initial-state";
|
||||||
|
import { documentAddArtboardCommand } from "./document";
|
||||||
|
|
||||||
|
describe("document commands", () => {
|
||||||
|
test("adds transparent artboard", () => {
|
||||||
|
const next = documentAddArtboardCommand.execute(
|
||||||
|
{ state: createInitialAppState("Test") },
|
||||||
|
{ id: "a1", name: "Artboard 1", bounds: { x: 0, y: 0, w: 320, h: 240 } },
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(next.document.artboards).toEqual([
|
||||||
|
{
|
||||||
|
id: "a1",
|
||||||
|
name: "Artboard 1",
|
||||||
|
bounds: { x: 0, y: 0, w: 320, h: 240 },
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
layers: [],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
34
commands/document.ts
Normal file
34
commands/document.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import type { Rect } from "@core/geometry";
|
||||||
|
import type { ArtboardId } from "@core/id";
|
||||||
|
import type { Command } from "./command";
|
||||||
|
|
||||||
|
export type DocumentAddArtboardPayload = {
|
||||||
|
id: ArtboardId;
|
||||||
|
name: string;
|
||||||
|
bounds: Rect;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const documentAddArtboardCommand: Command<DocumentAddArtboardPayload> = {
|
||||||
|
id: "document.addArtboard",
|
||||||
|
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 documentCommands = [documentAddArtboardCommand] satisfies Command<unknown>[];
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
export type { Command, CommandContext } from "./command";
|
export type { Command, CommandContext } from "./command";
|
||||||
|
export { documentAddArtboardCommand, documentCommands } from "./document";
|
||||||
|
export type { DocumentAddArtboardPayload } from "./document";
|
||||||
export type { CommandDispatcher, Dispatch } from "./dispatcher";
|
export type { CommandDispatcher, Dispatch } from "./dispatcher";
|
||||||
export type { CommandId, CommandPayloads } from "./payloads";
|
export type { CommandId, CommandPayloads } from "./payloads";
|
||||||
export { createCommandDispatcher } from "./dispatcher";
|
export { createCommandDispatcher } from "./dispatcher";
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { DocumentAddArtboardPayload } from "./document";
|
||||||
import type { SelectionAddLayerPayload, SelectionSetPayload } from "./selection";
|
import type { SelectionAddLayerPayload, SelectionSetPayload } from "./selection";
|
||||||
import type {
|
import type {
|
||||||
ViewportPanPayload,
|
ViewportPanPayload,
|
||||||
@@ -7,6 +8,7 @@ import type {
|
|||||||
} from "./viewport";
|
} from "./viewport";
|
||||||
|
|
||||||
export type CommandPayloads = {
|
export type CommandPayloads = {
|
||||||
|
"document.addArtboard": DocumentAddArtboardPayload;
|
||||||
"selection.set": SelectionSetPayload;
|
"selection.set": SelectionSetPayload;
|
||||||
"selection.clear": void;
|
"selection.clear": void;
|
||||||
"selection.addLayer": SelectionAddLayerPayload;
|
"selection.addLayer": SelectionAddLayerPayload;
|
||||||
|
|||||||
Reference in New Issue
Block a user