feat(commands): add image asset layer commands
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import type { Asset } from "@core/asset";
|
||||
import type { ImageLayer } from "@core/image-layer";
|
||||
import type { Rect } from "@core/geometry";
|
||||
import type { ArtboardId } from "@core/id";
|
||||
import type { Command } from "./command";
|
||||
@@ -14,6 +16,15 @@ export type DocumentSetArtboardBoundsPayload = {
|
||||
bounds: Rect;
|
||||
};
|
||||
|
||||
export type DocumentAddAssetPayload = {
|
||||
asset: Asset;
|
||||
};
|
||||
|
||||
export type DocumentAddImageLayerPayload = {
|
||||
artboardId: ArtboardId;
|
||||
layer: ImageLayer;
|
||||
};
|
||||
|
||||
export const documentAddArtboardCommand: Command<DocumentAddArtboardPayload> = {
|
||||
id: commandIds.documentAddArtboard,
|
||||
name: "Add artboard",
|
||||
@@ -53,4 +64,41 @@ export const documentSetArtboardBoundsCommand: Command<DocumentSetArtboardBounds
|
||||
},
|
||||
};
|
||||
|
||||
export const documentCommands = [documentAddArtboardCommand, documentSetArtboardBoundsCommand] satisfies Command<unknown>[];
|
||||
export const documentAddAssetCommand: Command<DocumentAddAssetPayload> = {
|
||||
id: commandIds.documentAddAsset,
|
||||
name: "Add asset",
|
||||
execute({ state }, payload) {
|
||||
if (state.document.assets.some((asset) => asset.id === payload.asset.id)) return state;
|
||||
|
||||
return {
|
||||
...state,
|
||||
document: {
|
||||
...state.document,
|
||||
assets: [...state.document.assets, payload.asset],
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const documentAddImageLayerCommand: Command<DocumentAddImageLayerPayload> = {
|
||||
id: commandIds.documentAddImageLayer,
|
||||
name: "Add image layer",
|
||||
execute({ state }, payload) {
|
||||
return {
|
||||
...state,
|
||||
document: {
|
||||
...state.document,
|
||||
artboards: state.document.artboards.map((artboard) =>
|
||||
artboard.id === payload.artboardId ? { ...artboard, layers: [...artboard.layers, payload.layer] } : artboard,
|
||||
),
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const documentCommands = [
|
||||
documentAddArtboardCommand,
|
||||
documentSetArtboardBoundsCommand,
|
||||
documentAddAssetCommand,
|
||||
documentAddImageLayerCommand,
|
||||
] satisfies Command<unknown>[];
|
||||
|
||||
Reference in New Issue
Block a user