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 = { 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 = { 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[];