feat(commands): add selection commands
This commit is contained in:
63
commands/selection.ts
Normal file
63
commands/selection.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
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>[];
|
||||
Reference in New Issue
Block a user