11import type React from "react"
2- import { useCallback , useEffect , useMemo , useState } from "react"
2+ import { useCallback , useEffect , useMemo , useRef , useState } from "react"
33import type MirabufSceneObject from "@/mirabuf/MirabufSceneObject"
44import InputSchemeManager from "@/systems/input/InputSchemeManager"
55import World from "@/systems/World"
@@ -29,7 +29,7 @@ import ConfigureCameraPointsInterface from "./interfaces/ConfigureCameraPointsIn
2929import ConfigureProtectedZonesInterface from "./interfaces/scoring/ConfigureProtectedZonesInterface"
3030import ConfigureScoringZonesInterface from "./interfaces/scoring/ConfigureScoringZonesInterface"
3131import EventSystem from "@/systems/EventSystem.ts"
32- import { Tab , Tabs } from "@mui/material"
32+ import { Tab , Tabs , type TabsActions } from "@mui/material"
3333import { SoundPlayer } from "@/systems/sound/SoundPlayer"
3434import CommandRegistry , { type CommandDefinition , type CommandProvider } from "@/ui/components/CommandRegistry"
3535import { globalAddToast , globalOpenPanel } from "@/ui/components/GlobalUIControls"
@@ -188,6 +188,19 @@ const ConfigurePanel: React.FC<PanelImplProps<void, ConfigurePanelCustomProps>>
188188 }
189189 } , [ ] )
190190
191+ // Resize tab indicator when content changes size
192+ const tabsActionsRef = useRef < TabsActions > ( null )
193+ const contentRef = useRef < HTMLDivElement > ( null )
194+
195+ useEffect ( ( ) => {
196+ const content = contentRef . current
197+ if ( ! content ) return
198+
199+ const observer = new ResizeObserver ( ( ) => tabsActionsRef . current ?. updateIndicator ( ) )
200+ observer . observe ( content )
201+ return ( ) => observer . disconnect ( )
202+ } , [ ] )
203+
191204 useEffect ( ( ) => {
192205 if ( selectedAssembly != null ) {
193206 setAccessedAssemblies ( v => [ ...v , selectedAssembly ] )
@@ -280,6 +293,7 @@ const ConfigurePanel: React.FC<PanelImplProps<void, ConfigurePanelCustomProps>>
280293 return (
281294 < >
282295 < Tabs
296+ action = { tabsActionsRef }
283297 value = { configurationType }
284298 onChange = { ( _ , newValue ) => setConfigurationType ( newValue ) }
285299 textColor = "inherit"
@@ -291,70 +305,72 @@ const ConfigurePanel: React.FC<PanelImplProps<void, ConfigurePanelCustomProps>>
291305 < Tab key = "fields" value = "FIELDS" label = "FIELDS" />
292306 < Tab key = "inputs" value = "INPUTS" label = "INPUTS" />
293307 </ Tabs >
294- { configurationType === "INPUTS" && (
295- < ConfigureInputsInterface panel = { panel ! } registerCleanupFunction = { registerCleanupFunctions } />
296- ) }
297- { configurationType !== "INPUTS" && (
298- < >
299- < AssemblySelection
300- panel = { panel ! }
301- configurationType = { configurationType }
302- onAssemblySelected = { a => {
303- if ( configMode !== undefined ) EventSystem . dispatch ( "ConfigurationSavedEvent" )
304- setConfigMode ( undefined )
305- setSelectedAssembly ( a as MirabufSceneObject )
306- } }
307- selectedAssembly = { selectedAssembly }
308- onStageDelete = { opt => {
309- const id = ( opt as AssemblySelectionOption ) . assemblyObject . id
310- setPendingDeletes ( prev => [ ...prev , id ] )
311- } }
312- pendingDeletes = { pendingDeletes }
313- />
314- { selectedAssembly !== undefined && (
315- < ConfigModeSelection
316- modes = { modes }
317- configMode = { configMode }
318- onModeSelected = { mode => {
308+ < div ref = { contentRef } >
309+ { configurationType === "INPUTS" && (
310+ < ConfigureInputsInterface panel = { panel ! } registerCleanupFunction = { registerCleanupFunctions } />
311+ ) }
312+ { configurationType !== "INPUTS" && (
313+ < >
314+ < AssemblySelection
315+ panel = { panel ! }
316+ configurationType = { configurationType }
317+ onAssemblySelected = { a => {
319318 if ( configMode !== undefined ) EventSystem . dispatch ( "ConfigurationSavedEvent" )
320- setConfigMode ( mode )
319+ setConfigMode ( undefined )
320+ setSelectedAssembly ( a as MirabufSceneObject )
321321 } }
322+ selectedAssembly = { selectedAssembly }
323+ onStageDelete = { opt => {
324+ const id = ( opt as AssemblySelectionOption ) . assemblyObject . id
325+ setPendingDeletes ( prev => [ ...prev , id ] )
326+ } }
327+ pendingDeletes = { pendingDeletes }
322328 />
323- ) }
324- { ConfigSubPanel != null && (
325- < ConfigSubPanel
326- panel = { panel ! }
327- selectedAssembly = { selectedAssembly ! }
328- hasMadeChanges = { hasMadeChanges }
329- setDisableAccept = { setDisableAccept }
330- registerCleanupFunction = { registerCleanupFunctions }
331- />
332- ) }
333- { configMode === undefined && selectedAssembly !== undefined && (
334- < >
335- < Spacer height = { 16 } />
336- < AssemblyExportButton selectedAssembly = { selectedAssembly } />
337- < Spacer height = { 16 } />
338- < Button
339- className = { "w-full" }
340- color = { "warning" }
341- onClick = { ( ) => {
342- closePanel ( panel ! . id , CloseType . ACCEPT )
343- selectedAssembly . resetPreferences ( )
344- globalAddToast (
345- "info" ,
346- "Preferences for " + selectedAssembly . descriptiveName + " reset"
347- )
329+ { selectedAssembly !== undefined && (
330+ < ConfigModeSelection
331+ modes = { modes }
332+ configMode = { configMode }
333+ onModeSelected = { mode => {
334+ if ( configMode !== undefined ) EventSystem . dispatch ( "ConfigurationSavedEvent" )
335+ setConfigMode ( mode )
348336 } }
349- >
350- Reset
351- < Spacer width = { 5 } />
352- < FaArrowsRotate />
353- </ Button >
354- </ >
355- ) }
356- </ >
357- ) }
337+ />
338+ ) }
339+ { ConfigSubPanel != null && (
340+ < ConfigSubPanel
341+ panel = { panel ! }
342+ selectedAssembly = { selectedAssembly ! }
343+ hasMadeChanges = { hasMadeChanges }
344+ setDisableAccept = { setDisableAccept }
345+ registerCleanupFunction = { registerCleanupFunctions }
346+ />
347+ ) }
348+ { configMode === undefined && selectedAssembly !== undefined && (
349+ < >
350+ < Spacer height = { 16 } />
351+ < AssemblyExportButton selectedAssembly = { selectedAssembly } />
352+ < Spacer height = { 16 } />
353+ < Button
354+ className = { "w-full" }
355+ color = { "warning" }
356+ onClick = { ( ) => {
357+ closePanel ( panel ! . id , CloseType . ACCEPT )
358+ selectedAssembly . resetPreferences ( )
359+ globalAddToast (
360+ "info" ,
361+ "Preferences for " + selectedAssembly . descriptiveName + " reset"
362+ )
363+ } }
364+ >
365+ Reset
366+ < Spacer width = { 5 } />
367+ < FaArrowsRotate />
368+ </ Button >
369+ </ >
370+ ) }
371+ </ >
372+ ) }
373+ </ div >
358374 </ >
359375 )
360376}
0 commit comments