import type { WorkspacePanel } from "@editor/state"; import type { Command } from "./command"; import { commandIds } from "./ids"; export type WorkspaceSetPanelPayload = { panel: WorkspacePanel }; export const workspaceSetPanelCommand: Command = { id: commandIds.workspaceSetPanel, name: "Set workspace panel", history: { mode: "ignore" }, execute({ state }, payload) { if (!workspacePanels.has(payload.panel)) return state; const currentTool = state.editor.tools.activeTool; const previousNonGenerateTool = currentTool === "generate" ? state.editor.workspace.previousNonGenerateTool : currentTool; const nextTool = payload.panel === "generate" ? "generate" : currentTool === "generate" ? previousNonGenerateTool : currentTool; if (state.editor.workspace.panel === payload.panel && currentTool === nextTool) return state; return { ...state, editor: { ...state.editor, workspace: { panel: payload.panel, previousNonGenerateTool }, tools: nextTool === currentTool ? state.editor.tools : { ...state.editor.tools, activeTool: nextTool, interactionMode: { type: "tool", tool: nextTool } }, brushPreview: nextTool === currentTool ? state.editor.brushPreview : undefined, brushStrokePreview: nextTool === currentTool ? state.editor.brushStrokePreview : undefined, }, }; }, }; const workspacePanels = new Set(["none", "generate", "layers"]); export const workspaceCommands = [workspaceSetPanelCommand] satisfies Command[];