1- import { getPanelTools } from "../dom.mjs" ;
1+ import { getPanelTools , getToolButtons , getToolButtonById } from "../dom.mjs" ;
22import { setTool } from "../state/actions/tool.mjs" ;
33import { TOOL_LIST } from "../state/constants.mjs" ;
4- import { updateActivatedButton } from "./utils.mjs" ;
54import { buildToolActions } from "./actions.mjs" ;
65import { buildToolVariants } from "./variants.mjs" ;
76import { ToolButton } from "./tool.mjs" ;
@@ -27,7 +26,19 @@ export function createToolPanel({ state }) {
2726 variantsController = new AbortController ( ) ;
2827 actionsController = new AbortController ( ) ;
2928
30- updateActivatedButton ( tools , updatedState . tool . id . description ) ;
29+ const prevActiveButton = Array . from ( getToolButtons ( ) ) . find (
30+ ( b ) => b . isActive ,
31+ ) ;
32+ prevActiveButton . isActive = false ;
33+
34+ const toolId = updatedState . tool . id ;
35+ const nextActiveButton = getToolButtonById ( toolId ) ;
36+
37+ if ( ! nextActiveButton ) {
38+ throw new Error ( `Tool button not found for tool: ${ toolId } ` ) ;
39+ }
40+
41+ nextActiveButton . isActive = true ;
3142
3243 if ( updatedState . tool . variants ) {
3344 buildToolVariants ( updatedState . tool , {
@@ -44,20 +55,19 @@ export function createToolPanel({ state }) {
4455 }
4556 } ) ;
4657
58+ const selectedTool = state . get ( ( prevState ) => prevState . tool ) ;
59+
4760 TOOL_LIST . forEach ( ( tool ) => {
4861 const button = new ToolButton ( {
4962 ...tool ,
5063 onClick : ( ) => setTool ( tool , { state } ) ,
64+ isActive : selectedTool . id === tool . id ,
5165 } ) ;
5266
5367 tools . appendChild ( button ) ;
5468 } ) ;
5569
56- const selectedTool = state . get ( ( prevState ) => prevState . tool ) ;
57-
5870 if ( selectedTool ) {
59- updateActivatedButton ( tools , selectedTool . id . description ) ;
60-
6171 if ( selectedTool . variants ) {
6272 buildToolVariants ( selectedTool , {
6373 state,
0 commit comments