65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
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<SelectionSetPayload> = {
|
|
id: commandIds.selectionSet,
|
|
name: "Set selection",
|
|
execute({ state }, payload) {
|
|
return {
|
|
...state,
|
|
editor: {
|
|
...state.editor,
|
|
selection: {
|
|
artboardId: payload.artboardId,
|
|
layerIds: [...payload.layerIds],
|
|
},
|
|
},
|
|
};
|
|
},
|
|
};
|
|
|
|
export const selectionClearCommand: Command = {
|
|
id: commandIds.selectionClear,
|
|
name: "Clear selection",
|
|
execute({ state }) {
|
|
return {
|
|
...state,
|
|
editor: {
|
|
...state.editor,
|
|
selection: { layerIds: [] },
|
|
},
|
|
};
|
|
},
|
|
};
|
|
|
|
export const selectionAddLayerCommand: Command<SelectionAddLayerPayload> = {
|
|
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],
|
|
},
|
|
},
|
|
};
|
|
},
|
|
};
|
|
|
|
export const selectionCommands = [selectionSetCommand, selectionClearCommand, selectionAddLayerCommand] satisfies Command<unknown>[];
|