feat(commands): add tool mode commands
This commit is contained in:
64
commands/tool.ts
Normal file
64
commands/tool.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import type { ToolId } from "@editor/tools";
|
||||
import type { Command } from "./command";
|
||||
|
||||
export type ToolSetActivePayload = {
|
||||
tool: ToolId;
|
||||
};
|
||||
|
||||
export const toolSetActiveCommand: Command<ToolSetActivePayload> = {
|
||||
id: "tool.setActive",
|
||||
name: "Set active tool",
|
||||
execute({ state }, payload) {
|
||||
return {
|
||||
...state,
|
||||
editor: {
|
||||
...state.editor,
|
||||
tools: {
|
||||
activeTool: payload.tool,
|
||||
interactionMode: { type: "tool", tool: payload.tool },
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const toolEnterTemporaryPanCommand: Command = {
|
||||
id: "tool.enterTemporaryPan",
|
||||
name: "Enter temporary pan",
|
||||
execute({ state }) {
|
||||
if (state.editor.tools.interactionMode.type === "temporary-pan") return state;
|
||||
|
||||
return {
|
||||
...state,
|
||||
editor: {
|
||||
...state.editor,
|
||||
tools: {
|
||||
...state.editor.tools,
|
||||
interactionMode: { type: "temporary-pan", previousTool: state.editor.tools.activeTool },
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const toolExitTemporaryPanCommand: Command = {
|
||||
id: "tool.exitTemporaryPan",
|
||||
name: "Exit temporary pan",
|
||||
execute({ state }) {
|
||||
const mode = state.editor.tools.interactionMode;
|
||||
if (mode.type !== "temporary-pan") return state;
|
||||
|
||||
return {
|
||||
...state,
|
||||
editor: {
|
||||
...state.editor,
|
||||
tools: {
|
||||
activeTool: mode.previousTool,
|
||||
interactionMode: { type: "tool", tool: mode.previousTool },
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const toolCommands = [toolSetActiveCommand, toolEnterTemporaryPanCommand, toolExitTemporaryPanCommand] satisfies Command<unknown>[];
|
||||
Reference in New Issue
Block a user