import type { ArtboardId, LayerId } from "@core/id"; import type { Command } from "./command"; import { commandIds } from "./ids"; export type SelectionSetPayload = { artboardId?: ArtboardId; layerIds: LayerId[]; }; export type SelectionAddLayerPayload = { layerId: LayerId; }; export const selectionSetCommand: Command = { id: commandIds.selectionSet, name: "Set selection", execute({ state }, payload) { const selection = { artboardId: payload.artboardId, layerIds: [...payload.layerIds], }; return { ...state, editor: { ...state.editor, selection, maskEdit: selection.layerIds.length === 1 && selection.layerIds[0] === state.editor.maskEdit?.targetLayerId ? state.editor.maskEdit : undefined, brushPreview: undefined, brushStrokePreview: undefined, }, }; }, }; export const selectionClearCommand: Command = { id: commandIds.selectionClear, name: "Clear selection", execute({ state }) { return { ...state, editor: { ...state.editor, selection: { layerIds: [] }, maskEdit: undefined, brushPreview: undefined, brushStrokePreview: undefined, }, }; }, }; export const selectionAddLayerCommand: Command = { id: commandIds.selectionAddLayer, 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], }, maskEdit: undefined, brushPreview: undefined, brushStrokePreview: undefined, }, }; }, }; export const selectionCommands = [selectionSetCommand, selectionClearCommand, selectionAddLayerCommand] satisfies Command[];