Files
image-studio/commands/selection.ts
2026-07-03 09:51:26 +02:00

64 lines
1.5 KiB
TypeScript

import type { ArtboardId, LayerId } from "@core/id";
import type { Command } from "./command";
export type SelectionSetPayload = {
artboardId?: ArtboardId;
layerIds: LayerId[];
};
export type SelectionAddLayerPayload = {
layerId: LayerId;
};
export const selectionSetCommand: Command<SelectionSetPayload> = {
id: "selection.set",
name: "Set selection",
execute({ state }, payload) {
return {
...state,
editor: {
...state.editor,
selection: {
artboardId: payload.artboardId,
layerIds: [...payload.layerIds],
},
},
};
},
};
export const selectionClearCommand: Command = {
id: "selection.clear",
name: "Clear selection",
execute({ state }) {
return {
...state,
editor: {
...state.editor,
selection: { layerIds: [] },
},
};
},
};
export const selectionAddLayerCommand: Command<SelectionAddLayerPayload> = {
id: "selection.addLayer",
name: "Add layer to selection",
execute({ state }, payload) {
if (state.editor.selection.layerIds.includes(payload.layerId)) return state;
return {
...state,
editor: {
...state.editor,
selection: {
...state.editor.selection,
layerIds: [...state.editor.selection.layerIds, payload.layerId],
},
},
};
},
};
export const selectionCommands = [selectionSetCommand, selectionClearCommand, selectionAddLayerCommand] satisfies Command<unknown>[];