diff --git a/ballast-debugger-ui/build.gradle.kts b/ballast-debugger-ui/build.gradle.kts new file mode 100644 index 00000000..8687e4d8 --- /dev/null +++ b/ballast-debugger-ui/build.gradle.kts @@ -0,0 +1,41 @@ +plugins { + id("copper-leaf-base") + id("copper-leaf-targets") + id("copper-leaf-kotest") + id("copper-leaf-serialization") + id("copper-leaf-compose") + id("copper-leaf-lint") + id("copper-leaf-publish") +} + +kotlin { + sourceSets { + all { + languageSettings.apply { + optIn("androidx.compose.material.ExperimentalMaterialApi") + optIn("androidx.compose.foundation.ExperimentalFoundationApi") + optIn("com.copperleaf.ballast.ExperimentalBallastApi") + } + } + + val commonMain by getting { + dependencies { + // Ktor websocket server + implementation(libs.kotlinx.datetime) + implementation(libs.bundles.ktorEmbeddedServer) + + implementation(libs.kotlinx.coroutines.swing) + implementation(libs.multiplatformSettings.core) + implementation(libs.multiplatformSettings.test) + + // Ballast, to manage its own UI state (with debugger artifact to share serialization models between the client and server) + implementation(project(":ballast-core")) + implementation(project(":ballast-repository")) + implementation(project(":ballast-saved-state")) + implementation(project(":ballast-navigation")) + implementation(project(":ballast-debugger-models")) + implementation(project(":ballast-debugger-server")) + } + } + } +} diff --git a/ballast-debugger-ui/gradle.properties b/ballast-debugger-ui/gradle.properties new file mode 100644 index 00000000..6d1149b9 --- /dev/null +++ b/ballast-debugger-ui/gradle.properties @@ -0,0 +1,7 @@ +copperleaf.description=Compose UI for Ballast Debugger +copperleaf.targets.android=false +copperleaf.targets.jvm=true +copperleaf.targets.ios=false +copperleaf.targets.js=false + +copperleaf.compose.splitPane=true diff --git a/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/injector/DebuggerToolWindowInjector.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/injector/DebuggerToolWindowInjector.kt new file mode 100644 index 00000000..0fc3a5ab --- /dev/null +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/injector/DebuggerToolWindowInjector.kt @@ -0,0 +1,14 @@ +package com.copperleaf.ballast.debugger.idea.features.debugger.injector + +import com.copperleaf.ballast.debugger.idea.features.debugger.router.DebuggerRouter +import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiViewModel +import com.copperleaf.ballast.debugger.server.vm.DebuggerServerViewModel + +public interface DebuggerToolWindowInjector { + + public val debuggerRouter: DebuggerRouter + public val debuggerServerViewModel: DebuggerServerViewModel + public val debuggerUiViewModel: DebuggerUiViewModel + + public companion object +} diff --git a/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/repository/DebuggerUseCase.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/repository/DebuggerUseCase.kt new file mode 100644 index 00000000..6c0b51f8 --- /dev/null +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/repository/DebuggerUseCase.kt @@ -0,0 +1,13 @@ +package com.copperleaf.ballast.debugger.idea.features.debugger.repository + +import com.copperleaf.ballast.debugger.idea.settings.DebuggerUiSettings +import com.copperleaf.ballast.debugger.idea.settings.GeneralSettings +import com.copperleaf.ballast.debugger.server.BallastDebuggerServerSettings +import com.copperleaf.ballast.repository.cache.Cached +import kotlinx.coroutines.flow.Flow + +public interface DebuggerUseCase { + public fun observeGeneralSettings(): Flow> + public fun observeBallastDebuggerServerSettings(): Flow> + public fun observeDebuggerUiSettings(): Flow> +} diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRoute.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRoute.kt similarity index 97% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRoute.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRoute.kt index 2bf61941..be294f8d 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRoute.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRoute.kt @@ -4,7 +4,7 @@ import com.copperleaf.ballast.navigation.routing.Route import com.copperleaf.ballast.navigation.routing.RouteAnnotation import com.copperleaf.ballast.navigation.routing.RouteMatcher -enum class DebuggerRoute( +public enum class DebuggerRoute( routeFormat: String, override val annotations: Set = emptySet(), ) : Route { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRouter.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRouter.kt similarity index 67% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRouter.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRouter.kt index 6f1a1b01..c1ead570 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRouter.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/DebuggerRouter.kt @@ -2,4 +2,4 @@ package com.copperleaf.ballast.debugger.idea.features.debugger.router import com.copperleaf.ballast.navigation.vm.BasicRouter -typealias DebuggerRouter = BasicRouter +public typealias DebuggerRouter = BasicRouter diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/RouterEventHandler.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/RouterEventHandler.kt similarity index 91% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/RouterEventHandler.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/RouterEventHandler.kt index 19bf21ec..7c6c5ac5 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/RouterEventHandler.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/router/RouterEventHandler.kt @@ -4,7 +4,7 @@ import com.copperleaf.ballast.EventHandler import com.copperleaf.ballast.EventHandlerScope import com.copperleaf.ballast.navigation.routing.RouterContract -class RouterEventHandler : EventHandler< +public class RouterEventHandler : EventHandler< RouterContract.Inputs, RouterContract.Events, RouterContract.State> { @@ -13,7 +13,7 @@ class RouterEventHandler : EventHandler< RouterContract.Events, RouterContract.State>.handleEvent( event: RouterContract.Events - ) = when (event) { + ): Unit = when (event) { is RouterContract.Events.BackstackChanged -> {} is RouterContract.Events.BackstackEmptied -> {} is RouterContract.Events.NoChange -> {} diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/server/DebuggerServerEventHandler.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/server/DebuggerServerEventHandler.kt similarity index 87% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/server/DebuggerServerEventHandler.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/server/DebuggerServerEventHandler.kt index f7148b9d..e88ac8fa 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/server/DebuggerServerEventHandler.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/server/DebuggerServerEventHandler.kt @@ -6,8 +6,8 @@ import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiContr import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiViewModel import com.copperleaf.ballast.debugger.server.vm.DebuggerServerContract -class DebuggerServerEventHandler( - private val getDebuggerUiViewModelLazy: ()->DebuggerUiViewModel +public class DebuggerServerEventHandler( + private val getDebuggerUiViewModelLazy: () -> DebuggerUiViewModel ) : EventHandler< DebuggerServerContract.Inputs, DebuggerServerContract.Events, @@ -17,7 +17,7 @@ class DebuggerServerEventHandler( DebuggerServerContract.Events, DebuggerServerContract.State>.handleEvent( event: DebuggerServerContract.Events - ) = when (event) { + ): Unit = when (event) { is DebuggerServerContract.Events.ConnectionEstablished -> { getDebuggerUiViewModelLazy() .send(DebuggerUiContract.Inputs.OnConnectionEstablished(event.connectionId)) diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/DebuggerUi.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/DebuggerUi.kt similarity index 90% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/DebuggerUi.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/DebuggerUi.kt index 7eaf6e0f..ec949310 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/DebuggerUi.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/DebuggerUi.kt @@ -54,29 +54,26 @@ import com.copperleaf.ballast.debugger.idea.features.debugger.ui.widgets.remembe import com.copperleaf.ballast.debugger.idea.features.debugger.ui.widgets.rememberViewModelSideJobsList import com.copperleaf.ballast.debugger.idea.features.debugger.ui.widgets.rememberViewModelStatesList import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiContract -import com.copperleaf.ballast.debugger.idea.theme.IdeaPluginTheme import com.copperleaf.ballast.navigation.routing.Destination import com.copperleaf.ballast.navigation.routing.renderCurrentDestination -object DebuggerUi { +public object DebuggerUi { @Composable - fun Content(injector: DebuggerToolWindowInjector) { + public fun Content(injector: DebuggerToolWindowInjector) { val debuggerUiViewModel = remember(injector) { injector.debuggerUiViewModel } val debuggerUiState by debuggerUiViewModel.observeStates().collectAsState() - IdeaPluginTheme(injector.project, debuggerUiState.cachedSettings) { - ProvideTime { - Content( - debuggerUiState, - debuggerUiViewModel::trySend, - ) - } + ProvideTime { + Content( + debuggerUiState, + debuggerUiViewModel::trySend, + ) } } @Composable - fun Content( + public fun Content( uiState: DebuggerUiContract.State, postInput: (DebuggerUiContract.Inputs) -> Unit, ) { @@ -89,7 +86,7 @@ object DebuggerUi { } @Composable - fun Destination.Match.RouteContent( + public fun Destination.Match.RouteContent( currentRoute: DebuggerRoute, uiState: DebuggerUiContract.State, postInput: (DebuggerUiContract.Inputs) -> Unit, @@ -117,7 +114,7 @@ object DebuggerUi { val connectionsList by rememberConnectionsList(uiState.serverState) val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) DebuggerScaffold( primaryToolbar = { @@ -131,7 +128,7 @@ object DebuggerUi { postInput, ) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, ) } @@ -140,7 +137,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val statesList by rememberViewModelStatesList(viewModel, uiState.searchText) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -159,8 +156,8 @@ object DebuggerUi { tabs = { ViewModelTabStrip(connection, viewModel, postInput) }, mainContentLeft = { StatesList(connection, viewModel, statesList, null, postInput) }, contentLeftToolbar = { StatesListToolbar(connection, viewModel, statesList, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -169,7 +166,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val statesList by rememberViewModelStatesList(viewModel, uiState.searchText) val selectedState by rememberSelectedViewModelStateSnapshot(viewModel) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -195,8 +192,8 @@ object DebuggerUi { StateDetails(selectedState, postInput) }, contentRightToolbar = { StateDetailsToolbar(connection, viewModel, selectedState, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -205,7 +202,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val inputsList by rememberViewModelInputsList(viewModel, uiState.searchText) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -224,8 +221,8 @@ object DebuggerUi { tabs = { ViewModelTabStrip(connection, viewModel, postInput) }, mainContentLeft = { InputsList(connection, viewModel, inputsList, null, postInput) }, contentLeftToolbar = { InputsListToolbar(connection, viewModel, inputsList, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -234,7 +231,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val inputsList by rememberViewModelInputsList(viewModel, uiState.searchText) val selectedInput by rememberSelectedViewModelInput(viewModel) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -260,8 +257,8 @@ object DebuggerUi { InputDetails(selectedInput, postInput) }, contentRightToolbar = { InputDetailsToolbar(connection, viewModel, selectedInput, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -270,7 +267,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val eventsList by rememberViewModelEventsList(viewModel, uiState.searchText) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -289,8 +286,8 @@ object DebuggerUi { tabs = { ViewModelTabStrip(connection, viewModel, postInput) }, mainContentLeft = { EventsList(connection, viewModel, eventsList, null, postInput) }, contentLeftToolbar = { EventsListToolbar(connection, viewModel, eventsList, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -299,7 +296,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val eventsList by rememberViewModelEventsList(viewModel, uiState.searchText) val selectedEvent by rememberSelectedViewModelEvent(viewModel) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -325,8 +322,8 @@ object DebuggerUi { EventDetails(selectedEvent, postInput) }, contentRightToolbar = { EventDetailsToolbar(connection, viewModel, selectedEvent, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -335,7 +332,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val sideJobsList by rememberViewModelSideJobsList(viewModel, uiState.searchText) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -354,8 +351,8 @@ object DebuggerUi { tabs = { ViewModelTabStrip(connection, viewModel, postInput) }, mainContentLeft = { SideJobsList(connection, viewModel, sideJobsList, null, postInput) }, contentLeftToolbar = { SideJobsListToolbar(connection, viewModel, sideJobsList, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -364,7 +361,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val sideJobsList by rememberViewModelSideJobsList(viewModel, uiState.searchText) val selectedSideJob by rememberSelectedViewModelSideJob(viewModel) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -390,8 +387,8 @@ object DebuggerUi { SideJobDetails(selectedSideJob, postInput) }, contentRightToolbar = { SideJobDetailsToolbar(connection, viewModel, selectedSideJob, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -400,7 +397,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val interceptorList by rememberViewModelInterceptorList(viewModel, uiState.searchText) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -419,8 +416,8 @@ object DebuggerUi { tabs = { ViewModelTabStrip(connection, viewModel, postInput) }, mainContentLeft = { InterceptorsList(connection, viewModel, interceptorList, null, postInput) }, contentLeftToolbar = { InterceptorsListToolbar(connection, viewModel, interceptorList, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -429,7 +426,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val interceptorList by rememberViewModelInterceptorList(viewModel, uiState.searchText) val selectedInterceptor by rememberSelectedViewModelInterceptor(viewModel) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -455,8 +452,8 @@ object DebuggerUi { InterceptorDetails(selectedInterceptor, postInput) }, contentRightToolbar = { InterceptorDetailsToolbar(connection, viewModel, selectedInterceptor, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -465,7 +462,7 @@ object DebuggerUi { val connection by rememberSelectedConnection(connectionsList) val viewModelList by rememberViewModelList(connection) val viewModel by rememberSelectedViewModel(connection) - val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) + val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) val fullHistory by rememberViewModelLogsList(viewModel, uiState.searchText) val latestState by rememberLatestViewModelStateSnapshot(viewModel) @@ -484,8 +481,8 @@ object DebuggerUi { tabs = { ViewModelTabStrip(connection, viewModel, postInput) }, mainContentLeft = { LogsList(connection, viewModel, fullHistory, postInput) }, contentLeftToolbar = { LogsListToolbar(connection, viewModel, fullHistory, postInput) }, - secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, - stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } + secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, + stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } ) } @@ -494,7 +491,7 @@ object DebuggerUi { // val connection by rememberSelectedConnection(connectionsList) // val viewModelList by rememberViewModelList(connection) // val viewModel by rememberSelectedViewModel(connection) -// val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedSettings) +// val currentAppDestination by rememberConnectionCurrentDestination(connection, uiState.cachedDebuggerUiSettings) // val latestState by rememberLatestViewModelStateSnapshot(viewModel) // // DebuggerScaffold( @@ -510,8 +507,8 @@ object DebuggerUi { // ) // }, // tabs = { ViewModelTabStrip(connection, viewModel, postInput) }, -// secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedSettings, postInput) }, -// stickyContent = { SpecialViewModelState(latestState, uiState.cachedSettings, postInput) } +// secondaryContent = { SpecialRouterToolbar(currentAppDestination, uiState.cachedDebuggerUiSettings, postInput) }, +// stickyContent = { SpecialViewModelState(latestState, uiState.cachedDebuggerUiSettings, postInput) } // ) // } } diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerPrimaryToolbar.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerPrimaryToolbar.kt similarity index 90% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerPrimaryToolbar.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerPrimaryToolbar.kt index b7fac0ec..90629657 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerPrimaryToolbar.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerPrimaryToolbar.kt @@ -1,4 +1,5 @@ @file:Suppress("UNUSED_PARAMETER") + package com.copperleaf.ballast.debugger.idea.features.debugger.ui.widgets import androidx.compose.foundation.layout.RowScope @@ -16,6 +17,7 @@ import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiContr import com.copperleaf.ballast.debugger.models.BallastApplicationState import com.copperleaf.ballast.debugger.models.BallastConnectionState import com.copperleaf.ballast.debugger.models.BallastViewModelState +import com.copperleaf.ballast.debugger.server.vm.DebuggerServerContract import com.copperleaf.ballast.navigation.routing.Destination import com.copperleaf.ballast.navigation.routing.build import com.copperleaf.ballast.navigation.routing.directions @@ -24,7 +26,7 @@ import com.copperleaf.ballast.navigation.routing.pathParameter import com.copperleaf.ballast.navigation.routing.stringPath @Composable -fun RowScope.DebuggerPrimaryToolbar( +internal fun RowScope.DebuggerPrimaryToolbar( currentRoute: DebuggerRoute, connections: List, selectedConnection: BallastConnectionState?, @@ -36,7 +38,13 @@ fun RowScope.DebuggerPrimaryToolbar( ToolBarActionIconButton( imageVector = Icons.Default.ClearAll, contentDescription = "Clear All Connections", - onClick = { postInput(DebuggerUiContract.Inputs.ClearAllConnections) }, + onClick = { + postInput( + DebuggerUiContract.Inputs.SendToDebuggerServer( + DebuggerServerContract.Inputs.ClearAllConnections + ) + ) + }, ) DebuggerConnectionsComboBox( @@ -71,7 +79,7 @@ fun RowScope.DebuggerPrimaryToolbar( } @Composable -fun DebuggerConnectionsComboBox( +internal fun DebuggerConnectionsComboBox( connections: List, selectedConnection: BallastConnectionState?, postInput: (DebuggerUiContract.Inputs) -> Unit, @@ -115,7 +123,7 @@ fun DebuggerConnectionsComboBox( } @Composable -fun DebuggerConnectionViewModelsComboBox( +internal fun DebuggerConnectionViewModelsComboBox( currentRoute: DebuggerRoute, connection: BallastConnectionState, viewModels: List, @@ -150,7 +158,7 @@ fun DebuggerConnectionViewModelsComboBox( // --------------------------------------------------------------------------------------------------------------------- @Composable -fun rememberConnectionsList( +internal fun rememberConnectionsList( serverState: BallastApplicationState, ): State> { return viewModelValue { @@ -159,7 +167,7 @@ fun rememberConnectionsList( } @Composable -fun Destination.ParametersProvider.rememberSelectedConnection( +internal fun Destination.ParametersProvider.rememberSelectedConnection( connectionsList: List, ): State { return viewModelValue { @@ -169,7 +177,7 @@ fun Destination.ParametersProvider.rememberSelectedConnection( } @Composable -fun rememberViewModelList( +internal fun rememberViewModelList( connection: BallastConnectionState?, ): State> { return viewModelValue { @@ -182,7 +190,7 @@ fun rememberViewModelList( } @Composable -fun Destination.ParametersProvider.rememberSelectedViewModel( +internal fun Destination.ParametersProvider.rememberSelectedViewModel( connection: BallastConnectionState?, ): State { return viewModelValue { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerScaffold.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerScaffold.kt similarity index 99% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerScaffold.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerScaffold.kt index 2a251dad..7704bbf2 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerScaffold.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/DebuggerScaffold.kt @@ -17,7 +17,7 @@ import org.jetbrains.compose.splitpane.HorizontalSplitPane import org.jetbrains.compose.splitpane.rememberSplitPaneState @Composable -fun DebuggerScaffold( +internal fun DebuggerScaffold( primaryToolbar: (@Composable RowScope.() -> Unit)? = null, tabs: (@Composable RowScope.() -> Unit)? = null, mainContentLeft: (@Composable ColumnScope.() -> Unit)? = null, diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Events.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Events.kt similarity index 91% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Events.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Events.kt index 28a8967d..b878a548 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Events.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Events.kt @@ -29,6 +29,7 @@ import com.copperleaf.ballast.debugger.idea.utils.maybeFilter import com.copperleaf.ballast.debugger.models.BallastConnectionState import com.copperleaf.ballast.debugger.models.BallastEventState import com.copperleaf.ballast.debugger.models.BallastViewModelState +import com.copperleaf.ballast.debugger.server.vm.DebuggerServerContract import com.copperleaf.ballast.debugger.utils.minus import com.copperleaf.ballast.debugger.utils.removeFraction import com.copperleaf.ballast.navigation.routing.Destination @@ -42,7 +43,7 @@ import kotlin.time.Duration import kotlin.time.DurationUnit @Composable -fun ColumnScope.EventsListToolbar( +internal fun ColumnScope.EventsListToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, events: List, @@ -56,9 +57,11 @@ fun ColumnScope.EventsListToolbar( contentDescription = "Clear Events", onClick = { postInput( - DebuggerUiContract.Inputs.ClearAllEvents( - connection.connectionId, - viewModel.viewModelName + DebuggerUiContract.Inputs.SendToDebuggerServer( + DebuggerServerContract.Inputs.ClearAllEvents( + connection.connectionId, + viewModel.viewModelName + ) ) ) }, @@ -66,7 +69,7 @@ fun ColumnScope.EventsListToolbar( } @Composable -fun ColumnScope.EventsList( +internal fun ColumnScope.EventsList( connection: BallastConnectionState?, viewModel: BallastViewModelState?, events: List, @@ -93,7 +96,7 @@ fun ColumnScope.EventsList( } @Composable -fun ColumnScope.EventDetailsToolbar( +internal fun ColumnScope.EventDetailsToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, event: BallastEventState?, @@ -102,7 +105,7 @@ fun ColumnScope.EventDetailsToolbar( } @Composable -fun ColumnScope.EventDetails( +internal fun ColumnScope.EventDetails( event: BallastEventState?, postInput: (DebuggerUiContract.Inputs) -> Unit, ) { @@ -144,7 +147,7 @@ fun ColumnScope.EventDetails( @Suppress("UNUSED_PARAMETER") @Composable -fun EventSummary( +internal fun EventSummary( eventState: BallastEventState, focusedEvent: BallastEventState?, postInput: (DebuggerUiContract.Inputs) -> Unit, @@ -190,7 +193,7 @@ fun EventSummary( // --------------------------------------------------------------------------------------------------------------------- @Composable -fun rememberViewModelEventsList( +internal fun rememberViewModelEventsList( viewModel: BallastViewModelState?, searchText: String, ): State> { @@ -202,7 +205,7 @@ fun rememberViewModelEventsList( } @Composable -fun Destination.ParametersProvider.rememberSelectedViewModelEvent( +internal fun Destination.ParametersProvider.rememberSelectedViewModelEvent( viewModel: BallastViewModelState?, ): State { return viewModelValue { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Inputs.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Inputs.kt similarity index 85% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Inputs.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Inputs.kt index 3a6f7e17..bfcc7024 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Inputs.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Inputs.kt @@ -41,6 +41,7 @@ import com.copperleaf.ballast.debugger.idea.utils.maybeFilter import com.copperleaf.ballast.debugger.models.BallastConnectionState import com.copperleaf.ballast.debugger.models.BallastInputState import com.copperleaf.ballast.debugger.models.BallastViewModelState +import com.copperleaf.ballast.debugger.server.vm.DebuggerServerContract import com.copperleaf.ballast.debugger.utils.minus import com.copperleaf.ballast.debugger.utils.removeFraction import com.copperleaf.ballast.debugger.versions.ClientVersion @@ -56,7 +57,7 @@ import kotlin.time.Duration import kotlin.time.DurationUnit @Composable -fun ColumnScope.InputsListToolbar( +internal fun ColumnScope.InputsListToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, inputs: List, @@ -70,9 +71,11 @@ fun ColumnScope.InputsListToolbar( contentDescription = "Clear Inputs", onClick = { postInput( - DebuggerUiContract.Inputs.ClearAllInputs( - connection.connectionId, - viewModel.viewModelName + DebuggerUiContract.Inputs.SendToDebuggerServer( + DebuggerServerContract.Inputs.ClearAllInputs( + connection.connectionId, + viewModel.viewModelName + ) ) ) }, @@ -97,12 +100,14 @@ fun ColumnScope.InputsListToolbar( confirmButton = { Button({ postInput( - DebuggerUiContract.Inputs.SendDebuggerAction( - BallastDebuggerActionV4.RequestSendInput( - connection.connectionId, - viewModel.viewModelName, - serializedInput = serializedState, - inputContentType = stateContentType, + DebuggerUiContract.Inputs.SendToDebuggerServer( + DebuggerServerContract.Inputs.SendDebuggerAction( + BallastDebuggerActionV4.RequestSendInput( + connection.connectionId, + viewModel.viewModelName, + serializedInput = serializedState, + inputContentType = stateContentType, + ) ) ) ) @@ -132,7 +137,7 @@ fun ColumnScope.InputsListToolbar( } @Composable -fun ColumnScope.InputsList( +internal fun ColumnScope.InputsList( connection: BallastConnectionState?, viewModel: BallastViewModelState?, inputs: List, @@ -159,7 +164,7 @@ fun ColumnScope.InputsList( } @Composable -fun ColumnScope.InputDetailsToolbar( +internal fun ColumnScope.InputDetailsToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, input: BallastInputState?, @@ -168,7 +173,7 @@ fun ColumnScope.InputDetailsToolbar( } @Composable -fun ColumnScope.InputDetails( +internal fun ColumnScope.InputDetails( input: BallastInputState?, postInput: (DebuggerUiContract.Inputs) -> Unit, ) { @@ -209,7 +214,7 @@ fun ColumnScope.InputDetails( @Suppress("UNUSED_PARAMETER") @Composable -fun InputSummary( +internal fun InputSummary( inputState: BallastInputState, focusedInput: BallastInputState?, postInput: (DebuggerUiContract.Inputs) -> Unit, @@ -220,11 +225,13 @@ fun InputSummary( buildList { this += ContextMenuItem("Resend Input") { postInput( - DebuggerUiContract.Inputs.SendDebuggerAction( - BallastDebuggerActionV4.RequestResendInput( - connectionId = inputState.connectionId, - viewModelName = inputState.viewModelName, - inputUuid = inputState.uuid, + DebuggerUiContract.Inputs.SendToDebuggerServer( + DebuggerServerContract.Inputs.SendDebuggerAction( + BallastDebuggerActionV4.RequestResendInput( + connectionId = inputState.connectionId, + viewModelName = inputState.viewModelName, + inputUuid = inputState.uuid, + ) ) ) ) @@ -272,7 +279,7 @@ fun InputSummary( // --------------------------------------------------------------------------------------------------------------------- @Composable -fun rememberViewModelInputsList( +internal fun rememberViewModelInputsList( viewModel: BallastViewModelState?, searchText: String, ): State> { @@ -284,7 +291,7 @@ fun rememberViewModelInputsList( } @Composable -fun Destination.ParametersProvider.rememberSelectedViewModelInput( +internal fun Destination.ParametersProvider.rememberSelectedViewModelInput( viewModel: BallastViewModelState?, ): State { return viewModelValue { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Interceptors.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Interceptors.kt similarity index 93% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Interceptors.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Interceptors.kt index 8cb27aec..efe94ebc 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Interceptors.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Interceptors.kt @@ -32,7 +32,7 @@ import com.copperleaf.ballast.navigation.routing.pathParameter import com.copperleaf.ballast.navigation.routing.stringPath @Composable -fun ColumnScope.InterceptorsListToolbar( +internal fun ColumnScope.InterceptorsListToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, interceptors: List, @@ -41,7 +41,7 @@ fun ColumnScope.InterceptorsListToolbar( } @Composable -fun ColumnScope.InterceptorsList( +internal fun ColumnScope.InterceptorsList( connection: BallastConnectionState?, viewModel: BallastViewModelState?, interceptors: List, @@ -68,7 +68,7 @@ fun ColumnScope.InterceptorsList( } @Composable -fun ColumnScope.InterceptorDetailsToolbar( +internal fun ColumnScope.InterceptorDetailsToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, interceptor: BallastInterceptorState?, @@ -77,7 +77,7 @@ fun ColumnScope.InterceptorDetailsToolbar( } @Composable -fun ColumnScope.InterceptorDetails( +internal fun ColumnScope.InterceptorDetails( interceptor: BallastInterceptorState?, postInput: (DebuggerUiContract.Inputs) -> Unit, ) { @@ -85,7 +85,7 @@ fun ColumnScope.InterceptorDetails( @Suppress("UNUSED_PARAMETER") @Composable -fun InterceptorSummary( +internal fun InterceptorSummary( interceptorState: BallastInterceptorState, focusedInterceptor: BallastInterceptorState?, postInput: (DebuggerUiContract.Inputs) -> Unit, @@ -121,7 +121,7 @@ fun InterceptorSummary( // --------------------------------------------------------------------------------------------------------------------- @Composable -fun rememberViewModelInterceptorList( +internal fun rememberViewModelInterceptorList( viewModel: BallastViewModelState?, searchText: String, ): State> { @@ -133,7 +133,7 @@ fun rememberViewModelInterceptorList( } @Composable -fun Destination.ParametersProvider.rememberSelectedViewModelInterceptor( +internal fun Destination.ParametersProvider.rememberSelectedViewModelInterceptor( viewModel: BallastViewModelState?, ): State { return viewModelValue { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Logs.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Logs.kt similarity index 90% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Logs.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Logs.kt index 42068f5f..df2f1222 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Logs.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/Logs.kt @@ -26,10 +26,12 @@ import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiContr import com.copperleaf.ballast.debugger.idea.utils.maybeFilter import com.copperleaf.ballast.debugger.models.BallastConnectionState import com.copperleaf.ballast.debugger.models.BallastViewModelState +import com.copperleaf.ballast.debugger.server.vm.DebuggerServerContract +import com.copperleaf.ballast.debugger.versions.v4.BallastDebuggerActionV4 import com.copperleaf.ballast.debugger.versions.v4.BallastDebuggerEventV4 @Composable -fun ColumnScope.LogsListToolbar( +internal fun ColumnScope.LogsListToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, fullHistory: List, @@ -41,12 +43,21 @@ fun ColumnScope.LogsListToolbar( ToolBarActionIconButton( imageVector = Icons.Default.ClearAll, contentDescription = "Clear Logs", - onClick = { postInput(DebuggerUiContract.Inputs.ClearAllLogs(connection.connectionId, viewModel.viewModelName)) }, + onClick = { + postInput( + DebuggerUiContract.Inputs.SendToDebuggerServer( + DebuggerServerContract.Inputs.ClearAllLogs( + connection.connectionId, + viewModel.viewModelName, + ) + ) + ) + }, ) } @Composable -fun ColumnScope.LogsList( +internal fun ColumnScope.LogsList( connection: BallastConnectionState?, viewModel: BallastViewModelState?, fullHistory: List, @@ -76,7 +87,7 @@ fun ColumnScope.LogsList( @Suppress("UNUSED_PARAMETER") @Composable -fun LogSummary( +internal fun LogSummary( logEntry: BallastDebuggerEventV4, postInput: (DebuggerUiContract.Inputs) -> Unit, ) { @@ -131,7 +142,7 @@ fun LogSummary( // --------------------------------------------------------------------------------------------------------------------- @Composable -fun rememberViewModelLogsList( +internal fun rememberViewModelLogsList( viewModel: BallastViewModelState?, searchText: String, ): State> { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SideJobs.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SideJobs.kt similarity index 91% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SideJobs.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SideJobs.kt index bdf387f1..7f69b271 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SideJobs.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SideJobs.kt @@ -29,6 +29,7 @@ import com.copperleaf.ballast.debugger.idea.utils.maybeFilter import com.copperleaf.ballast.debugger.models.BallastConnectionState import com.copperleaf.ballast.debugger.models.BallastSideJobState import com.copperleaf.ballast.debugger.models.BallastViewModelState +import com.copperleaf.ballast.debugger.server.vm.DebuggerServerContract import com.copperleaf.ballast.debugger.utils.minus import com.copperleaf.ballast.debugger.utils.removeFraction import com.copperleaf.ballast.navigation.routing.Destination @@ -42,7 +43,7 @@ import kotlin.time.Duration import kotlin.time.DurationUnit @Composable -fun ColumnScope.SideJobsListToolbar( +internal fun ColumnScope.SideJobsListToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, sideJobs: List, @@ -56,9 +57,11 @@ fun ColumnScope.SideJobsListToolbar( contentDescription = "Clear Side Jobs", onClick = { postInput( - DebuggerUiContract.Inputs.ClearAllSideJobs( - connection.connectionId, - viewModel.viewModelName + DebuggerUiContract.Inputs.SendToDebuggerServer( + DebuggerServerContract.Inputs.ClearAllSideJobs( + connection.connectionId, + viewModel.viewModelName, + ) ) ) }, @@ -66,7 +69,7 @@ fun ColumnScope.SideJobsListToolbar( } @Composable -fun ColumnScope.SideJobsList( +internal fun ColumnScope.SideJobsList( connection: BallastConnectionState?, viewModel: BallastViewModelState?, sideJobs: List, @@ -93,7 +96,7 @@ fun ColumnScope.SideJobsList( } @Composable -fun ColumnScope.SideJobDetailsToolbar( +internal fun ColumnScope.SideJobDetailsToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, sideJob: BallastSideJobState?, @@ -102,7 +105,7 @@ fun ColumnScope.SideJobDetailsToolbar( } @Composable -fun ColumnScope.SideJobDetails( +internal fun ColumnScope.SideJobDetails( sideJob: BallastSideJobState?, postInput: (DebuggerUiContract.Inputs) -> Unit, ) { @@ -144,7 +147,7 @@ fun ColumnScope.SideJobDetails( @Suppress("UNUSED_PARAMETER") @Composable -fun SideJobSummary( +internal fun SideJobSummary( sideJobState: BallastSideJobState, focusedSideJob: BallastSideJobState?, postInput: (DebuggerUiContract.Inputs) -> Unit, @@ -191,7 +194,7 @@ fun SideJobSummary( // --------------------------------------------------------------------------------------------------------------------- @Composable -fun rememberViewModelSideJobsList( +internal fun rememberViewModelSideJobsList( viewModel: BallastViewModelState?, searchText: String, ): State> { @@ -203,7 +206,7 @@ fun rememberViewModelSideJobsList( } @Composable -fun Destination.ParametersProvider.rememberSelectedViewModelSideJob( +internal fun Destination.ParametersProvider.rememberSelectedViewModelSideJob( viewModel: BallastViewModelState?, ): State { return viewModelValue { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialRouterToolbar.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialRouterToolbar.kt similarity index 86% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialRouterToolbar.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialRouterToolbar.kt index 786cbb86..8f0db033 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialRouterToolbar.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialRouterToolbar.kt @@ -9,14 +9,14 @@ import androidx.compose.material.TextField import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiContract -import com.copperleaf.ballast.debugger.idea.settings.IntellijPluginSettingsSnapshot +import com.copperleaf.ballast.debugger.idea.settings.DebuggerUiSettings import com.copperleaf.ballast.repository.cache.Cached import com.copperleaf.ballast.repository.cache.getCachedOrNull @Composable -fun ColumnScope.SpecialRouterToolbar( +internal fun ColumnScope.SpecialRouterToolbar( url: String?, - settings: Cached, + settings: Cached, postInput: (DebuggerUiContract.Inputs) -> Unit, ) { if (settings.getCachedOrNull()?.showCurrentRoute == true) { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialViewModelState.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialViewModelState.kt similarity index 83% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialViewModelState.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialViewModelState.kt index edc5f4ef..7560ad9a 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialViewModelState.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/SpecialViewModelState.kt @@ -6,15 +6,15 @@ import androidx.compose.material.Divider import androidx.compose.material.Text import androidx.compose.runtime.Composable import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiContract -import com.copperleaf.ballast.debugger.idea.settings.IntellijPluginSettingsSnapshot +import com.copperleaf.ballast.debugger.idea.settings.DebuggerUiSettings import com.copperleaf.ballast.debugger.models.BallastStateSnapshot import com.copperleaf.ballast.repository.cache.Cached import com.copperleaf.ballast.repository.cache.getCachedOrNull @Composable -fun ColumnScope.SpecialViewModelState( +internal fun ColumnScope.SpecialViewModelState( currentState: BallastStateSnapshot?, - settings: Cached, + settings: Cached, postInput: (DebuggerUiContract.Inputs) -> Unit, ) { if (settings.getCachedOrNull()?.alwaysShowCurrentState == true) { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/States.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/States.kt similarity index 82% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/States.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/States.kt index 06c9166c..7fc48cdf 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/States.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/States.kt @@ -40,6 +40,7 @@ import com.copperleaf.ballast.debugger.idea.utils.maybeFilter import com.copperleaf.ballast.debugger.models.BallastConnectionState import com.copperleaf.ballast.debugger.models.BallastStateSnapshot import com.copperleaf.ballast.debugger.models.BallastViewModelState +import com.copperleaf.ballast.debugger.server.vm.DebuggerServerContract import com.copperleaf.ballast.debugger.versions.ClientVersion import com.copperleaf.ballast.debugger.versions.v4.BallastDebuggerActionV4 import com.copperleaf.ballast.navigation.routing.Destination @@ -49,7 +50,7 @@ import com.copperleaf.ballast.navigation.routing.pathParameter import com.copperleaf.ballast.navigation.routing.stringPath @Composable -fun ColumnScope.StatesListToolbar( +internal fun ColumnScope.StatesListToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, states: List, @@ -61,7 +62,16 @@ fun ColumnScope.StatesListToolbar( ToolBarActionIconButton( imageVector = Icons.Default.ClearAll, contentDescription = "Clear States", - onClick = { postInput(DebuggerUiContract.Inputs.ClearAllStates(connection.connectionId, viewModel.viewModelName)) }, + onClick = { + postInput( + DebuggerUiContract.Inputs.SendToDebuggerServer( + DebuggerServerContract.Inputs.ClearAllStates( + connection.connectionId, + viewModel.viewModelName, + ) + ) + ) + }, ) // Replace states from JSON @@ -83,12 +93,14 @@ fun ColumnScope.StatesListToolbar( confirmButton = { Button({ postInput( - DebuggerUiContract.Inputs.SendDebuggerAction( - BallastDebuggerActionV4.RequestReplaceState( - connection.connectionId, - viewModel.viewModelName, - serializedState = serializedState, - stateContentType = stateContentType, + DebuggerUiContract.Inputs.SendToDebuggerServer( + DebuggerServerContract.Inputs.SendDebuggerAction( + BallastDebuggerActionV4.RequestReplaceState( + connection.connectionId, + viewModel.viewModelName, + serializedState = serializedState, + stateContentType = stateContentType, + ) ) ) ) @@ -118,7 +130,7 @@ fun ColumnScope.StatesListToolbar( } @Composable -fun ColumnScope.StatesList( +internal fun ColumnScope.StatesList( connection: BallastConnectionState?, viewModel: BallastViewModelState?, states: List, @@ -145,7 +157,7 @@ fun ColumnScope.StatesList( } @Composable -fun ColumnScope.StateDetailsToolbar( +internal fun ColumnScope.StateDetailsToolbar( connection: BallastConnectionState?, viewModel: BallastViewModelState?, stateSnapshot: BallastStateSnapshot?, @@ -154,7 +166,7 @@ fun ColumnScope.StateDetailsToolbar( } @Composable -fun ColumnScope.StateDetails( +internal fun ColumnScope.StateDetails( stateSnapshot: BallastStateSnapshot?, postInput: (DebuggerUiContract.Inputs) -> Unit, ) { @@ -171,7 +183,7 @@ fun ColumnScope.StateDetails( @Suppress("UNUSED_PARAMETER") @Composable -fun StateSnapshotSummary( +internal fun StateSnapshotSummary( stateSnapshot: BallastStateSnapshot, focusedState: BallastStateSnapshot?, postInput: (DebuggerUiContract.Inputs) -> Unit, @@ -181,11 +193,13 @@ fun StateSnapshotSummary( buildList { this += ContextMenuItem("Rollback to this State") { postInput( - DebuggerUiContract.Inputs.SendDebuggerAction( - BallastDebuggerActionV4.RequestRestoreState( - connectionId = stateSnapshot.connectionId, - viewModelName = stateSnapshot.viewModelName, - stateUuid = stateSnapshot.uuid, + DebuggerUiContract.Inputs.SendToDebuggerServer( + DebuggerServerContract.Inputs.SendDebuggerAction( + BallastDebuggerActionV4.RequestRestoreState( + connectionId = stateSnapshot.connectionId, + viewModelName = stateSnapshot.viewModelName, + stateUuid = stateSnapshot.uuid, + ) ) ) ) @@ -224,9 +238,8 @@ fun StateSnapshotSummary( // Data for States // --------------------------------------------------------------------------------------------------------------------- - @Composable -fun rememberViewModelStatesList( +internal fun rememberViewModelStatesList( viewModel: BallastViewModelState?, searchText: String, ): State> { @@ -238,7 +251,7 @@ fun rememberViewModelStatesList( } @Composable -fun Destination.ParametersProvider.rememberSelectedViewModelStateSnapshot( +internal fun Destination.ParametersProvider.rememberSelectedViewModelStateSnapshot( viewModel: BallastViewModelState?, ): State { return viewModelValue { @@ -248,7 +261,7 @@ fun Destination.ParametersProvider.rememberSelectedViewModelStateSnapshot( } @Composable -fun rememberLatestViewModelStateSnapshot( +internal fun rememberLatestViewModelStateSnapshot( viewModel: BallastViewModelState?, ): State { return viewModelValue { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelContentTab.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelContentTab.kt similarity index 97% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelContentTab.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelContentTab.kt index e0570158..e45b36c9 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelContentTab.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelContentTab.kt @@ -17,9 +17,9 @@ import com.copperleaf.ballast.navigation.routing.build import com.copperleaf.ballast.navigation.routing.directions import com.copperleaf.ballast.navigation.routing.pathParameter -enum class ViewModelContentTab( - val icon: ImageVector, - val text: String, +internal enum class ViewModelContentTab( + internal val icon: ImageVector, + internal val text: String, ) { States(Icons.Default.List, "States"), Inputs(Icons.Default.Refresh, "Inputs"), diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelTabStrip.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelTabStrip.kt similarity index 96% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelTabStrip.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelTabStrip.kt index 491c3166..c7f22eaf 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelTabStrip.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/ViewModelTabStrip.kt @@ -9,14 +9,14 @@ import androidx.compose.material.ScrollableTabRow import androidx.compose.material.Tab import androidx.compose.material.Text import androidx.compose.runtime.Composable -import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiContract import com.copperleaf.ballast.debugger.idea.features.debugger.router.DebuggerRoute +import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiContract import com.copperleaf.ballast.debugger.models.BallastConnectionState import com.copperleaf.ballast.debugger.models.BallastViewModelState import com.copperleaf.ballast.navigation.routing.Destination @Composable -fun Destination.Match.ViewModelTabStrip( +internal fun Destination.Match.ViewModelTabStrip( connection: BallastConnectionState?, viewModel: BallastViewModelState?, postInput: (DebuggerUiContract.Inputs) -> Unit, diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/utils.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/utils.kt similarity index 93% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/utils.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/utils.kt index bce22743..5040cf3d 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/utils.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/widgets/utils.kt @@ -55,6 +55,7 @@ import androidx.compose.material.icons.filled.ArrowDropDown import androidx.compose.material.icons.filled.CopyAll import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.ProvidableCompositionLocal import androidx.compose.runtime.State import androidx.compose.runtime.compositionLocalOf import androidx.compose.runtime.derivedStateOf @@ -77,10 +78,11 @@ import androidx.compose.ui.input.pointer.PointerIcon import androidx.compose.ui.input.pointer.pointerHoverIcon import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex import com.copperleaf.ballast.debugger.idea.features.debugger.router.DebuggerRoute -import com.copperleaf.ballast.debugger.idea.settings.IntellijPluginSettingsSnapshot +import com.copperleaf.ballast.debugger.idea.settings.DebuggerUiSettings import com.copperleaf.ballast.debugger.idea.utils.datatypes.DataType import com.copperleaf.ballast.debugger.models.BallastConnectionState import com.copperleaf.ballast.debugger.utils.minus @@ -90,8 +92,6 @@ import com.copperleaf.ballast.navigation.routing.directions import com.copperleaf.ballast.navigation.routing.pathParameter import com.copperleaf.ballast.repository.cache.Cached import com.copperleaf.ballast.repository.cache.getCachedOrNull -import com.intellij.openapi.ide.CopyPasteManager -import com.intellij.openapi.project.Project import io.ktor.http.ContentType import kotlinx.coroutines.delay import kotlinx.datetime.LocalDateTime @@ -101,27 +101,25 @@ import org.jetbrains.compose.splitpane.SplitPaneState import org.jetbrains.compose.splitpane.SplitterScope import org.jetbrains.compose.splitpane.VerticalSplitPane import java.awt.Cursor -import java.awt.datatransfer.StringSelection import java.time.format.DateTimeFormatter import kotlin.time.Duration -val minSplitPaneSize = 48.dp +public val minSplitPaneSize: Dp = 48.dp -fun LocalDateTime.format(pattern: String = "hh:mm:ss a"): String { +public fun LocalDateTime.format(pattern: String = "hh:mm:ss a"): String { return this.toJavaLocalDateTime().format( DateTimeFormatter.ofPattern(pattern) ) } -fun LocalDateTime.ago(now: LocalDateTime = LocalDateTime.now()): Duration { +public fun LocalDateTime.ago(now: LocalDateTime = LocalDateTime.now()): Duration { return now - this } -val LocalProject = compositionLocalOf { error("LocalProject not provided") } -val LocalTimer = compositionLocalOf { error("LocalDateTime not provided") } +public val LocalTimer: ProvidableCompositionLocal = compositionLocalOf { error("LocalDateTime not provided") } @Composable -fun currentTimeAsState(): State { +public fun currentTimeAsState(): State { return produceState(LocalDateTime.now()) { while (true) { delay(1000) @@ -131,7 +129,7 @@ fun currentTimeAsState(): State { } @Composable -fun ProvideTime(content: @Composable () -> Unit) { +public fun ProvideTime(content: @Composable () -> Unit) { val time by currentTimeAsState() CompositionLocalProvider(LocalTimer provides time) { @@ -140,7 +138,7 @@ fun ProvideTime(content: @Composable () -> Unit) { } @Composable -fun StatusIcon( +public fun StatusIcon( isActive: Boolean, activeText: String, inactiveText: String, @@ -187,7 +185,7 @@ fun StatusIcon( } @Composable -fun SplitPane( +public fun SplitPane( splitPaneState: SplitPaneState, modifier: Modifier = Modifier, navigation: LazyListScope.() -> Unit, @@ -226,7 +224,7 @@ fun SplitPane( } @Composable -fun VSplitPane( +public fun VSplitPane( splitPaneState: SplitPaneState, modifier: Modifier = Modifier, topContent: @Composable () -> Unit, @@ -252,7 +250,7 @@ fun VSplitPane( } } -fun Modifier.cursorForResize( +public fun Modifier.cursorForResize( isHorizontal: Boolean, ): Modifier = composed { val icon = if (isHorizontal) { @@ -264,7 +262,7 @@ fun Modifier.cursorForResize( } @Composable -fun Modifier.onHoverState( +public fun Modifier.onHoverState( notHovering: @Composable () -> Modifier = { Modifier }, hovering: @Composable () -> Modifier = { Modifier } ): Modifier { @@ -276,7 +274,7 @@ fun Modifier.onHoverState( .then(if (isHovered) hovering() else notHovering()) } -fun SplitterScope.ColoredSplitter(isHorizontal: Boolean) { +public fun SplitterScope.ColoredSplitter(isHorizontal: Boolean) { visiblePart { Box( Modifier @@ -299,14 +297,14 @@ fun SplitterScope.ColoredSplitter(isHorizontal: Boolean) { } @Composable -fun Modifier.highlight(enabled: Boolean = true): Modifier { +public fun Modifier.highlight(enabled: Boolean = true): Modifier { val next = if (enabled) Modifier.background(MaterialTheme.colors.onSurface.copy(alpha = 0.12f)) else Modifier return this.then(next) } @Suppress("UNUSED_PARAMETER") @Composable -fun IntellijEditor( +public fun IntellijEditor( text: String, contentType: ContentType, modifier: Modifier = Modifier, @@ -357,9 +355,9 @@ fun IntellijEditor( } @Composable -fun rememberConnectionCurrentDestination( +public fun rememberConnectionCurrentDestination( connection: BallastConnectionState?, - settings: Cached, + settings: Cached, ): State { return viewModelValue { val uiSettings = settings.getCachedOrNull() @@ -388,7 +386,7 @@ fun rememberConnectionCurrentDestination( } } -fun getRouteForSelectedViewModel( +public fun getRouteForSelectedViewModel( currentRoute: DebuggerRoute, connectionId: String, viewModelName: String?, @@ -426,7 +424,7 @@ fun getRouteForSelectedViewModel( } @Composable -fun Section( +public fun Section( title: @Composable () -> Unit, modifier: Modifier = Modifier, content: @Composable ColumnScope.() -> Unit, @@ -448,7 +446,7 @@ fun Section( } @Composable -fun CheckboxArea( +public fun CheckboxArea( checked: Boolean, onCheckedChange: (Boolean) -> Unit, modifier: Modifier = Modifier, @@ -474,7 +472,7 @@ fun CheckboxArea( } @Composable -fun RadioButtonArea( +public fun RadioButtonArea( selected: Boolean, onClick: (() -> Unit)?, modifier: Modifier = Modifier, @@ -503,7 +501,7 @@ fun RadioButtonArea( } @Composable -fun ToolBarActionIconButton( +public fun ToolBarActionIconButton( imageVector: ImageVector, contentDescription: String, modifier: Modifier = Modifier, @@ -533,7 +531,7 @@ fun ToolBarActionIconButton( } @Composable -fun DropdownSelector( +public fun DropdownSelector( items: List, value: T, onValueChange: (T) -> Unit, @@ -579,7 +577,7 @@ fun DropdownSelector( } @Composable -fun RadioGroup( +public fun RadioGroup( items: List, value: T, onValueChange: (T) -> Unit, @@ -601,15 +599,15 @@ fun RadioGroup( } @Composable -internal fun viewModelValue(calculation: () -> T): State { +public fun viewModelValue(calculation: () -> T): State { return derivedStateOf { calculation() } // return remember { derivedStateOf { calculation() } } } -internal fun String.asContentType(): ContentType { +public fun String.asContentType(): ContentType { return ContentType.parse(this) } -internal fun ContentType.asContentTypeString(): String { +public fun ContentType.asContentTypeString(): String { return "$contentType/$contentSubtype" } diff --git a/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiContract.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiContract.kt new file mode 100644 index 00000000..ae156474 --- /dev/null +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiContract.kt @@ -0,0 +1,61 @@ +package com.copperleaf.ballast.debugger.idea.features.debugger.vm + +import com.copperleaf.ballast.debugger.idea.features.debugger.router.DebuggerRoute +import com.copperleaf.ballast.debugger.idea.settings.DebuggerUiSettings +import com.copperleaf.ballast.debugger.idea.settings.GeneralSettings +import com.copperleaf.ballast.debugger.models.BallastApplicationState +import com.copperleaf.ballast.debugger.server.BallastDebuggerServerSettings +import com.copperleaf.ballast.debugger.server.vm.DebuggerServerContract +import com.copperleaf.ballast.navigation.routing.Backstack +import com.copperleaf.ballast.repository.cache.Cached +import com.copperleaf.ballast.repository.cache.getCachedOrThrow +import com.copperleaf.ballast.repository.cache.isReady + +public object DebuggerUiContract { + public data class State( + val cachedGeneralSettings: Cached = Cached.NotLoaded(), + val cachedBallastDebuggerServerSettings: Cached = Cached.NotLoaded(), + val cachedDebuggerUiSettings: Cached = Cached.NotLoaded(), + + val serverState: BallastApplicationState = BallastApplicationState(), + val backstack: Backstack = emptyList(), + val searchText: String = "", + +// val connectionsPanePercentage: SplitPaneState = SplitPaneState(0.35f, true), +// val viewModelsPanePercentage: SplitPaneState = SplitPaneState(0.35f, true), +// val eventsPanePercentage: SplitPaneState = SplitPaneState(0.35f, true), + ) { + public val isReady: Boolean = isReady( + cachedGeneralSettings, + cachedBallastDebuggerServerSettings, + cachedDebuggerUiSettings, + ) + public val generalSettings: GeneralSettings by lazy { cachedGeneralSettings.getCachedOrThrow() } + public val ballastDebuggerServerSettings: BallastDebuggerServerSettings by lazy { cachedBallastDebuggerServerSettings.getCachedOrThrow() } + public val debuggerUiSettings: DebuggerUiSettings by lazy { cachedDebuggerUiSettings.getCachedOrThrow() } + } + + public sealed class Inputs { + public data object Initialize : Inputs() + + public data class OnConnectionEstablished(val connectionId: String) : Inputs() + + public data class ServerStateChanged(val serverState: BallastApplicationState) : Inputs() + public data class BackstackChanged(val backstack: Backstack) : Inputs() + public data class GeneralSettingsChanged(val settings: Cached) : Inputs() + public data class BallastDebuggerServerSettingsChanged(val settings: Cached) : Inputs() + public data class DebuggerUiSettingsChanged(val settings: Cached) : Inputs() + + // forwarded to other VMs + public data class SendToDebuggerServer(val debuggerServerInput: DebuggerServerContract.Inputs) : Inputs() + public data class Navigate(val destinationUrl: String) : Inputs() + + // manage own interactions + public data class UpdateSearchText(val value: String) : Inputs() + public data class CopyToClipboard(val text: String) : Inputs() + } + + public sealed class Events { + public data class CopyToClipboard(val text: String) : Events() + } +} diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiInputHandler.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiInputHandler.kt similarity index 60% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiInputHandler.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiInputHandler.kt index fb602eaa..9e1daad1 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiInputHandler.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiInputHandler.kt @@ -2,22 +2,20 @@ package com.copperleaf.ballast.debugger.idea.features.debugger.vm import com.copperleaf.ballast.InputHandler import com.copperleaf.ballast.InputHandlerScope +import com.copperleaf.ballast.debugger.idea.features.debugger.repository.DebuggerUseCase import com.copperleaf.ballast.debugger.idea.features.debugger.router.DebuggerRouter import com.copperleaf.ballast.debugger.idea.features.debugger.ui.widgets.getRouteForSelectedViewModel -import com.copperleaf.ballast.debugger.idea.repository.RepositoryViewModel import com.copperleaf.ballast.debugger.server.vm.DebuggerServerContract import com.copperleaf.ballast.debugger.server.vm.DebuggerServerViewModel import com.copperleaf.ballast.navigation.routing.RouterContract import com.copperleaf.ballast.observeFlows import com.copperleaf.ballast.postInput -import com.intellij.openapi.ide.CopyPasteManager import kotlinx.coroutines.flow.map -import java.awt.datatransfer.StringSelection -class DebuggerUiInputHandler( +public class DebuggerUiInputHandler( private val debuggerRouter: DebuggerRouter, private val debuggerServerViewModel: DebuggerServerViewModel, - private val repository: RepositoryViewModel, + private val useCase: DebuggerUseCase, ) : InputHandler< DebuggerUiContract.Inputs, DebuggerUiContract.Events, @@ -37,9 +35,15 @@ class DebuggerUiInputHandler( debuggerServerViewModel .observeStates() .map { DebuggerUiContract.Inputs.ServerStateChanged(it.applicationState) }, - repository - .observeStates() - .map { DebuggerUiContract.Inputs.SettingsChanged(it.settings) }, + useCase + .observeGeneralSettings() + .map { DebuggerUiContract.Inputs.GeneralSettingsChanged(it) }, + useCase + .observeBallastDebuggerServerSettings() + .map { DebuggerUiContract.Inputs.BallastDebuggerServerSettingsChanged(it) }, + useCase + .observeDebuggerUiSettings() + .map { DebuggerUiContract.Inputs.DebuggerUiSettingsChanged(it) }, ) } @@ -49,11 +53,11 @@ class DebuggerUiInputHandler( if (!currentState.isReady) { noOp() } else { - if (!currentState.settings.autoselectDebuggerConnections) { + if (!currentState.debuggerUiSettings.autoselectDebuggerConnections) { noOp() } else { - val latestRoute = currentState.settings.lastRoute - val latestViewModelName = currentState.settings.lastViewModelName + val latestRoute = currentState.debuggerUiSettings.lastRoute + val latestViewModelName = currentState.debuggerUiSettings.lastViewModelName val route = if (latestViewModelName.isNotBlank()) { getRouteForSelectedViewModel( @@ -84,9 +88,19 @@ class DebuggerUiInputHandler( updateState { it.copy(backstack = input.backstack) } } - is DebuggerUiContract.Inputs.SettingsChanged -> { + is DebuggerUiContract.Inputs.GeneralSettingsChanged -> { + val previousState = getCurrentState() + val currentState = updateStateAndGet { it.copy(cachedGeneralSettings = input.settings) } + startServerIfNeeded(previousState, currentState) + } + is DebuggerUiContract.Inputs.BallastDebuggerServerSettingsChanged -> { + val previousState = getCurrentState() + val currentState = updateStateAndGet { it.copy(cachedBallastDebuggerServerSettings = input.settings) } + startServerIfNeeded(previousState, currentState) + } + is DebuggerUiContract.Inputs.DebuggerUiSettingsChanged -> { val previousState = getCurrentState() - val currentState = updateStateAndGet { it.copy(cachedSettings = input.settings) } + val currentState = updateStateAndGet { it.copy(cachedDebuggerUiSettings = input.settings) } startServerIfNeeded(previousState, currentState) } @@ -102,57 +116,14 @@ class DebuggerUiInputHandler( updateState { it.copy(searchText = input.value) } } - is DebuggerUiContract.Inputs.SendDebuggerAction -> { - sideJob("SendDebuggerAction") { - debuggerServerViewModel.send(DebuggerServerContract.Inputs.SendDebuggerAction(input.action)) - } - } - - is DebuggerUiContract.Inputs.ClearAllConnections -> { - sideJob("ClearAllConnections") { - debuggerServerViewModel.send( - DebuggerServerContract.Inputs.ClearAll - ) - } - } - is DebuggerUiContract.Inputs.ClearAllStates -> { - sideJob("ClearAllStates") { - debuggerServerViewModel.send( - DebuggerServerContract.Inputs.ClearAllStates(input.connectionId, input.viewModelName) - ) + is DebuggerUiContract.Inputs.SendToDebuggerServer -> { + sideJob("SendToDebuggerServer") { + debuggerServerViewModel.send(input.debuggerServerInput) } } - is DebuggerUiContract.Inputs.ClearAllInputs -> { - sideJob("ClearAllInputs") { - debuggerServerViewModel.send( - DebuggerServerContract.Inputs.ClearAllInputs(input.connectionId, input.viewModelName) - ) - } - } - is DebuggerUiContract.Inputs.ClearAllEvents -> { - sideJob("ClearAllEvents") { - debuggerServerViewModel.send( - DebuggerServerContract.Inputs.ClearAllEvents(input.connectionId, input.viewModelName) - ) - } - } - is DebuggerUiContract.Inputs.ClearAllSideJobs -> { - sideJob("ClearAllSideJobs") { - debuggerServerViewModel.send( - DebuggerServerContract.Inputs.ClearAllSideJobs(input.connectionId, input.viewModelName) - ) - } - } - is DebuggerUiContract.Inputs.ClearAllLogs -> { - sideJob("ClearAllLogs") { - debuggerServerViewModel.send( - DebuggerServerContract.Inputs.ClearAllLogs(input.connectionId, input.viewModelName) - ) - } - } is DebuggerUiContract.Inputs.CopyToClipboard -> { - CopyPasteManager.getInstance().setContents(StringSelection(input.text)) + postEvent(DebuggerUiContract.Events.CopyToClipboard(input.text)) } } @@ -169,8 +140,8 @@ class DebuggerUiInputHandler( true } else { // server is already active, restart if the port settings have changed - val previousSettingsPort = previousState.settings.debuggerServerPort - val currentSettingsPort = currentState.settings.debuggerServerPort + val previousSettingsPort = previousState.ballastDebuggerServerSettings.debuggerServerPort + val currentSettingsPort = currentState.ballastDebuggerServerSettings.debuggerServerPort previousSettingsPort != currentSettingsPort } } else { @@ -179,7 +150,7 @@ class DebuggerUiInputHandler( if (requestServerStart) { sideJob("start server") { - debuggerServerViewModel.send(DebuggerServerContract.Inputs.StartServer(currentState.settings)) + debuggerServerViewModel.send(DebuggerServerContract.Inputs.StartServer(currentState.ballastDebuggerServerSettings)) } } } diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiViewModel.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiViewModel.kt similarity index 79% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiViewModel.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiViewModel.kt index e44dc618..fb2572b3 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiViewModel.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiViewModel.kt @@ -2,7 +2,7 @@ package com.copperleaf.ballast.debugger.idea.features.debugger.vm import com.copperleaf.ballast.core.BasicViewModel -typealias DebuggerUiViewModel = BasicViewModel< +public typealias DebuggerUiViewModel = BasicViewModel< DebuggerUiContract.Inputs, DebuggerUiContract.Events, DebuggerUiContract.State> diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/settings/DebuggerUiSettings.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/settings/DebuggerUiSettings.kt similarity index 51% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/settings/DebuggerUiSettings.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/settings/DebuggerUiSettings.kt index 9ad24098..8d5c31d9 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/settings/DebuggerUiSettings.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/settings/DebuggerUiSettings.kt @@ -9,13 +9,13 @@ import com.copperleaf.ballast.debugger.idea.features.debugger.router.DebuggerRou * * See https://plugins.jetbrains.com/docs/intellij/persisting-state-of-components.html#implementing-the-persistentstatecomponent-interface */ -interface DebuggerUiSettings { - val lastRoute: DebuggerRoute - val lastViewModelName: String - val autoselectDebuggerConnections: Boolean - val alwaysShowCurrentState: Boolean - val showCurrentRoute: Boolean - val routerViewModelName: String - val detailsPanePercentage: Float +public interface DebuggerUiSettings { + public val lastRoute: DebuggerRoute + public val lastViewModelName: String + public val autoselectDebuggerConnections: Boolean + public val alwaysShowCurrentState: Boolean + public val showCurrentRoute: Boolean + public val routerViewModelName: String + public val detailsPanePercentage: Float } diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/settings/GeneralSettings.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/settings/GeneralSettings.kt similarity index 69% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/settings/GeneralSettings.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/settings/GeneralSettings.kt index 316ec745..8a8e632b 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/settings/GeneralSettings.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/settings/GeneralSettings.kt @@ -5,8 +5,8 @@ package com.copperleaf.ballast.debugger.idea.settings * * See https://plugins.jetbrains.com/docs/intellij/persisting-state-of-components.html#implementing-the-persistentstatecomponent-interface */ -interface GeneralSettings { - val ballastVersion: String - val darkTheme: Boolean +public interface GeneralSettings { + public val ballastVersion: String + public val darkTheme: Boolean } diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/DataType.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/DataType.kt similarity index 58% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/DataType.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/DataType.kt index 5d413100..9bd521e7 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/DataType.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/DataType.kt @@ -3,13 +3,13 @@ package com.copperleaf.ballast.debugger.idea.utils.datatypes import io.ktor.http.ContentType import kotlinx.serialization.json.JsonElement -interface DataType { - fun reformat(input: String): String +public interface DataType { + public fun reformat(input: String): String - fun parseToJson(input: String): JsonElement + public fun parseToJson(input: String): JsonElement - companion object { - fun getForMimeType(mimeType: ContentType): DataType { + public companion object { + public fun getForMimeType(mimeType: ContentType): DataType { return when(mimeType) { ContentType.Application.Json -> JsonDataType() else -> ToStringDataType() diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/JsonDataType.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/JsonDataType.kt similarity index 93% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/JsonDataType.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/JsonDataType.kt index 8b76d54e..36772c0a 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/JsonDataType.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/JsonDataType.kt @@ -3,7 +3,7 @@ package com.copperleaf.ballast.debugger.idea.utils.datatypes import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement -class JsonDataType : DataType { +public class JsonDataType : DataType { private val prettyJson = Json { this.prettyPrint = true } override fun reformat(input: String): String { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/ToStringDataType.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/ToStringDataType.kt similarity index 87% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/ToStringDataType.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/ToStringDataType.kt index c2f69b97..5fcae846 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/ToStringDataType.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/datatypes/ToStringDataType.kt @@ -2,7 +2,7 @@ package com.copperleaf.ballast.debugger.idea.utils.datatypes import kotlinx.serialization.json.JsonElement -class ToStringDataType : DataType { +public class ToStringDataType : DataType { override fun reformat(input: String): String { return input } diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/searchFilter.kt b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/searchFilter.kt similarity index 68% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/searchFilter.kt rename to ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/searchFilter.kt index 5563018a..b4caaf23 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/utils/searchFilter.kt +++ b/ballast-debugger-ui/src/commonMain/kotlin/com/copperleaf/ballast/debugger/idea/utils/searchFilter.kt @@ -1,6 +1,6 @@ package com.copperleaf.ballast.debugger.idea.utils -fun List?.maybeFilter(searchQuery: String, getFields: (T) -> List): List { +internal fun List?.maybeFilter(searchQuery: String, getFields: (T) -> List): List { if (this == null) return emptyList() if (searchQuery.isBlank()) return this diff --git a/ballast-idea-plugin/build.gradle.kts b/ballast-idea-plugin/build.gradle.kts index ac6bb4c0..ca9c1933 100644 --- a/ballast-idea-plugin/build.gradle.kts +++ b/ballast-idea-plugin/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { implementation(project(":ballast-navigation")) implementation(project(":ballast-debugger-models")) implementation(project(":ballast-debugger-server")) + implementation(project(":ballast-debugger-ui")) } buildConfig { diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/BallastIntellijPluginInjector.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/BallastIntellijPluginInjector.kt index e9c76990..0f2b8f44 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/BallastIntellijPluginInjector.kt +++ b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/BallastIntellijPluginInjector.kt @@ -1,6 +1,7 @@ package com.copperleaf.ballast.debugger.idea import com.copperleaf.ballast.BallastViewModelConfiguration +import com.copperleaf.ballast.debugger.idea.features.debugger.repository.DebuggerUseCase import com.copperleaf.ballast.debugger.idea.repository.RepositoryViewModel import com.intellij.openapi.project.Project import kotlinx.coroutines.CoroutineDispatcher @@ -21,6 +22,7 @@ interface BallastIntellijPluginInjector { fun newMainCoroutineScope(): CoroutineScope val repository: RepositoryViewModel + val debuggerUseCase: DebuggerUseCase companion object { private val projectMap = mutableMapOf() diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/BallastIntellijPluginInjectorImpl.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/BallastIntellijPluginInjectorImpl.kt index bedbf967..be6f6d79 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/BallastIntellijPluginInjectorImpl.kt +++ b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/BallastIntellijPluginInjectorImpl.kt @@ -7,6 +7,8 @@ import com.copperleaf.ballast.core.BootstrapInterceptor import com.copperleaf.ballast.core.FifoInputStrategy import com.copperleaf.ballast.core.LoggingInterceptor import com.copperleaf.ballast.debugger.idea.base.IntellijPluginBallastLogger +import com.copperleaf.ballast.debugger.idea.features.debugger.DebuggerUseCaseImpl +import com.copperleaf.ballast.debugger.idea.features.debugger.repository.DebuggerUseCase import com.copperleaf.ballast.debugger.idea.repository.RepositoryContract import com.copperleaf.ballast.debugger.idea.repository.RepositoryEventHandler import com.copperleaf.ballast.debugger.idea.repository.RepositoryInputHandler @@ -73,4 +75,7 @@ class BallastIntellijPluginInjectorImpl( .build(), eventHandler = RepositoryEventHandler(), ) + + override val debuggerUseCase: DebuggerUseCase + get() = DebuggerUseCaseImpl(repository) } diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerToolWindow.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerToolWindow.kt new file mode 100644 index 00000000..8d89a6e3 --- /dev/null +++ b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerToolWindow.kt @@ -0,0 +1,31 @@ +package com.copperleaf.ballast.debugger.idea.features.debugger + +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import com.copperleaf.ballast.debugger.idea.BallastIntellijPluginInjector +import com.copperleaf.ballast.debugger.idea.base.setContent +import com.copperleaf.ballast.debugger.idea.features.debugger.ui.DebuggerUi +import com.copperleaf.ballast.debugger.idea.theme.IdeaPluginTheme +import com.intellij.openapi.project.DumbAware +import com.intellij.openapi.project.Project +import com.intellij.openapi.wm.ToolWindow +import com.intellij.openapi.wm.ToolWindowFactory + +class DebuggerToolWindow { + class Factory : ToolWindowFactory, DumbAware { + override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { + toolWindow.setContent(null) { + val toolWindowCoroutineScope = rememberCoroutineScope() + val injector = remember { + DebuggerToolWindowInjectorImpl( + pluginInjector = BallastIntellijPluginInjector.getInstance(project), + toolWindowCoroutineScope = toolWindowCoroutineScope, + ) + } + IdeaPluginTheme(project) { + DebuggerUi.Content(injector) + } + } + } + } +} diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/injector/DebuggerToolWindowInjectorImpl.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerToolWindowInjectorImpl.kt similarity index 92% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/injector/DebuggerToolWindowInjectorImpl.kt rename to ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerToolWindowInjectorImpl.kt index 01a116fe..79d9da3d 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/injector/DebuggerToolWindowInjectorImpl.kt +++ b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerToolWindowInjectorImpl.kt @@ -1,14 +1,14 @@ -package com.copperleaf.ballast.debugger.idea.features.debugger.injector +package com.copperleaf.ballast.debugger.idea.features.debugger import com.copperleaf.ballast.build import com.copperleaf.ballast.core.BasicViewModel import com.copperleaf.ballast.debugger.idea.BallastIntellijPluginInjector +import com.copperleaf.ballast.debugger.idea.features.debugger.injector.DebuggerToolWindowInjector import com.copperleaf.ballast.debugger.idea.features.debugger.router.DebuggerRoute import com.copperleaf.ballast.debugger.idea.features.debugger.router.DebuggerRouter import com.copperleaf.ballast.debugger.idea.features.debugger.router.RouterEventHandler import com.copperleaf.ballast.debugger.idea.features.debugger.server.DebuggerServerEventHandler import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiContract -import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiEventHandler import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiInputHandler import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiViewModel import com.copperleaf.ballast.debugger.server.vm.DebuggerServerContract @@ -25,7 +25,7 @@ class DebuggerToolWindowInjectorImpl( private val pluginInjector: BallastIntellijPluginInjector, private val toolWindowCoroutineScope: CoroutineScope, ) : DebuggerToolWindowInjector { - override val project = pluginInjector.project + private val project = pluginInjector.project override val debuggerRouter: DebuggerRouter = BasicRouter( coroutineScope = toolWindowCoroutineScope, @@ -65,7 +65,7 @@ class DebuggerToolWindowInjectorImpl( inputHandler = DebuggerUiInputHandler( debuggerRouter, debuggerServerViewModel, - pluginInjector.repository, + pluginInjector.debuggerUseCase, ), name = "Debugger Ui", ) diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiEventHandler.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerUiEventHandler.kt similarity index 57% rename from ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiEventHandler.kt rename to ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerUiEventHandler.kt index 0d94e689..7b596a0a 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiEventHandler.kt +++ b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerUiEventHandler.kt @@ -1,7 +1,10 @@ -package com.copperleaf.ballast.debugger.idea.features.debugger.vm +package com.copperleaf.ballast.debugger.idea.features.debugger import com.copperleaf.ballast.EventHandler import com.copperleaf.ballast.EventHandlerScope +import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiContract +import com.intellij.openapi.ide.CopyPasteManager +import java.awt.datatransfer.StringSelection @Suppress("UNUSED_EXPRESSION") class DebuggerUiEventHandler() : EventHandler< @@ -14,6 +17,8 @@ class DebuggerUiEventHandler() : EventHandler< DebuggerUiContract.State>.handleEvent( event: DebuggerUiContract.Events ) = when (event) { - else -> {} + is DebuggerUiContract.Events.CopyToClipboard -> { + CopyPasteManager.getInstance().setContents(StringSelection(event.text)) + } } } diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerUseCaseImpl.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerUseCaseImpl.kt new file mode 100644 index 00000000..c07ebce1 --- /dev/null +++ b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/DebuggerUseCaseImpl.kt @@ -0,0 +1,40 @@ +package com.copperleaf.ballast.debugger.idea.features.debugger + +import com.copperleaf.ballast.debugger.idea.features.debugger.repository.DebuggerUseCase +import com.copperleaf.ballast.debugger.idea.repository.RepositoryViewModel +import com.copperleaf.ballast.debugger.idea.settings.DebuggerUiSettings +import com.copperleaf.ballast.debugger.idea.settings.GeneralSettings +import com.copperleaf.ballast.debugger.server.BallastDebuggerServerSettings +import com.copperleaf.ballast.repository.cache.Cached +import com.copperleaf.ballast.repository.cache.map +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +public class DebuggerUseCaseImpl( + private val viewModel: RepositoryViewModel +) : DebuggerUseCase { + + override fun observeGeneralSettings(): Flow> { + return viewModel.observeStates().map { state -> + state.settings.map { settings -> + settings + } + } + } + + override fun observeBallastDebuggerServerSettings(): Flow> { + return viewModel.observeStates().map { state -> + state.settings.map { settings -> + settings + } + } + } + + override fun observeDebuggerUiSettings(): Flow> { + return viewModel.observeStates().map { state -> + state.settings.map { settings -> + settings + } + } + } +} diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/injector/DebuggerToolWindowInjector.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/injector/DebuggerToolWindowInjector.kt deleted file mode 100644 index 63992239..00000000 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/injector/DebuggerToolWindowInjector.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.copperleaf.ballast.debugger.idea.features.debugger.injector - -import com.copperleaf.ballast.debugger.idea.BallastIntellijPluginInjector -import com.copperleaf.ballast.debugger.idea.features.debugger.router.DebuggerRouter -import com.copperleaf.ballast.debugger.idea.features.debugger.vm.DebuggerUiViewModel -import com.copperleaf.ballast.debugger.server.vm.DebuggerServerViewModel -import com.intellij.openapi.project.Project -import kotlinx.coroutines.CoroutineScope - -interface DebuggerToolWindowInjector { - - val project: Project - val debuggerRouter: DebuggerRouter - val debuggerServerViewModel: DebuggerServerViewModel - val debuggerUiViewModel: DebuggerUiViewModel - - companion object { - fun getInstance( - project: Project, - toolWindowCoroutineScope: CoroutineScope - ): DebuggerToolWindowInjector { - return DebuggerToolWindowInjectorImpl( - pluginInjector = BallastIntellijPluginInjector.getInstance(project), - toolWindowCoroutineScope = toolWindowCoroutineScope, - ) - } - } -} diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/DebuggerToolWindow.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/DebuggerToolWindow.kt deleted file mode 100644 index 62965d31..00000000 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/ui/DebuggerToolWindow.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.copperleaf.ballast.debugger.idea.features.debugger.ui - -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import com.copperleaf.ballast.debugger.idea.base.setContent -import com.copperleaf.ballast.debugger.idea.features.debugger.injector.DebuggerToolWindowInjector -import com.intellij.openapi.project.DumbAware -import com.intellij.openapi.project.Project -import com.intellij.openapi.wm.ToolWindow -import com.intellij.openapi.wm.ToolWindowFactory - -class DebuggerToolWindow { - class Factory : ToolWindowFactory, DumbAware { - override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { - toolWindow.setContent(null) { - val toolWindowCoroutineScope = rememberCoroutineScope() - val injector = remember { DebuggerToolWindowInjector.getInstance(project, toolWindowCoroutineScope) } - DebuggerUi.Content(injector) - } - } - } -} diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiContract.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiContract.kt deleted file mode 100644 index a2b3202f..00000000 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/debugger/vm/DebuggerUiContract.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.copperleaf.ballast.debugger.idea.features.debugger.vm - -import com.copperleaf.ballast.debugger.idea.features.debugger.router.DebuggerRoute -import com.copperleaf.ballast.debugger.idea.settings.IntellijPluginSettingsSnapshot -import com.copperleaf.ballast.debugger.models.BallastApplicationState -import com.copperleaf.ballast.debugger.versions.v4.BallastDebuggerActionV4 -import com.copperleaf.ballast.navigation.routing.Backstack -import com.copperleaf.ballast.repository.cache.Cached -import com.copperleaf.ballast.repository.cache.getCachedOrThrow -import com.copperleaf.ballast.repository.cache.isLoading -import org.jetbrains.compose.splitpane.SplitPaneState - -object DebuggerUiContract { - data class State( - val cachedSettings: Cached = Cached.NotLoaded(), - val serverState: BallastApplicationState = BallastApplicationState(), - val backstack: Backstack = emptyList(), - val searchText: String = "", - - val connectionsPanePercentage: SplitPaneState = SplitPaneState(0.35f, true), - val viewModelsPanePercentage: SplitPaneState = SplitPaneState(0.35f, true), - val eventsPanePercentage: SplitPaneState = SplitPaneState(0.35f, true), - ) { - val isReady = !cachedSettings.isLoading() - val settings by lazy { - cachedSettings.getCachedOrThrow() - } - } - - sealed class Inputs { - data object Initialize : Inputs() - - data class OnConnectionEstablished(val connectionId: String) : Inputs() - - data class ServerStateChanged(val serverState: BallastApplicationState) : Inputs() - data class BackstackChanged(val backstack: Backstack) : Inputs() - data class SettingsChanged(val settings: Cached) : Inputs() - - // forwarded to Server VM - data object ClearAllConnections : Inputs() - data class ClearAllStates(val connectionId: String, val viewModelName: String) : Inputs() - data class ClearAllInputs(val connectionId: String, val viewModelName: String) : Inputs() - data class ClearAllEvents(val connectionId: String, val viewModelName: String) : Inputs() - data class ClearAllSideJobs(val connectionId: String, val viewModelName: String) : Inputs() - data class ClearAllLogs(val connectionId: String, val viewModelName: String) : Inputs() - - data class Navigate(val destinationUrl: String) : Inputs() - - data class SendDebuggerAction(val action: BallastDebuggerActionV4) : Inputs() - data class UpdateSearchText(val value: String) : Inputs() - - data class CopyToClipboard(val text: String) : Inputs() - } - - sealed class Events -} diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/settings/ui/SettingsUi.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/settings/ui/SettingsUi.kt index 7f848319..a9deaf54 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/settings/ui/SettingsUi.kt +++ b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/features/settings/ui/SettingsUi.kt @@ -39,7 +39,7 @@ object SettingsUi { val debuggerUiViewModel = remember(injector) { injector.settingsPanelViewModel } val debuggerUiState by debuggerUiViewModel.observeStates().collectAsState() - IdeaPluginTheme(injector.project, debuggerUiState.cachedSettings) { + IdeaPluginTheme(injector.project) { ProvideTime { Content( debuggerUiState, diff --git a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/theme/IdeaPluginTheme.kt b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/theme/IdeaPluginTheme.kt index 81d32c7e..e873adcb 100644 --- a/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/theme/IdeaPluginTheme.kt +++ b/ballast-idea-plugin/src/main/kotlin/com/copperleaf/ballast/debugger/idea/theme/IdeaPluginTheme.kt @@ -10,36 +10,30 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import com.copperleaf.ballast.debugger.idea.settings.IntellijPluginSettingsSnapshot -import com.copperleaf.ballast.debugger.idea.features.debugger.ui.widgets.LocalProject -import com.copperleaf.ballast.repository.cache.Cached -import com.copperleaf.ballast.repository.cache.getCachedOrNull import com.intellij.openapi.project.Project @Composable fun IdeaPluginTheme( project: Project, - settings: Cached, +// settings: Cached, content: @Composable () -> Unit, ) { - settings.getCachedOrNull()?.let { - IdeaPluginTheme(project, it, content) - } +// settings.getCachedOrNull()?.let { + IdeaPluginTheme(project, true, content) +// } } @Composable private fun IdeaPluginTheme( project: Project, - settings: IntellijPluginSettingsSnapshot, + darkTheme: Boolean, content: @Composable () -> Unit, ) { - - val primaryColor = Color(0xff_ffab00) val secondaryColor = Color(0xff_ffab00) val swingColors = SwingColor() - val materialColors = if (settings.darkTheme) { + val materialColors = if (darkTheme) { darkColors( primary = primaryColor, secondary = secondaryColor, @@ -74,7 +68,6 @@ private fun IdeaPluginTheme( content = { // DesktopTheme { CompositionLocalProvider( - LocalProject provides project, LocalContentColor provides materialColors.onBackground, ) { Column( diff --git a/ballast-idea-plugin/src/main/resources/META-INF/plugin.xml b/ballast-idea-plugin/src/main/resources/META-INF/plugin.xml index eae24f4b..b230647d 100644 --- a/ballast-idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/ballast-idea-plugin/src/main/resources/META-INF/plugin.xml @@ -49,7 +49,7 @@ This IDEA plugin is built upon the best features of Kotlin: secondary="true" icon="AllIcons.Toolwindows.Documentation" anchor="bottom" - factoryClass="com.copperleaf.ballast.debugger.idea.features.debugger.ui.DebuggerToolWindow$Factory"/> + factoryClass="com.copperleaf.ballast.debugger.idea.features.debugger.DebuggerToolWindow$Factory"/> Cached.isLoading(): Boolean { } } +/** + * Returns true if all Cached properties are not in the "Loading" state + */ +public fun isReady(vararg cached: Cached<*>): Boolean { + return cached + .map { !it.isLoading() } + .all { it } +} + /** * Returns true if the Repository has not started fetching from the remote source yet, or if it has started fetching and * did not have a prior value (thus, is the first time attempting to load this value). diff --git a/settings.gradle.kts b/settings.gradle.kts index d2944fb7..eaf8ba6d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -40,6 +40,7 @@ include(":ballast-firebase-analytics") include(":ballast-debugger-models") include(":ballast-debugger-client") include(":ballast-debugger-server") +include(":ballast-debugger-ui") include(":ballast-idea-plugin") include(":ballast-test")