-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
638 additions
and
101 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
build-logic/src/main/kotlin/js-browser-library-convention.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
id("publication-convention") | ||
} | ||
|
||
kotlin { | ||
explicitApi() | ||
|
||
js(IR) { | ||
browser() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
kotlinx-coroutines/src/commonMain/kotlin/ksm/coroutines/StateControllerBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ksm.coroutines | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import ksm.annotation.LibraryApi | ||
import ksm.coroutines.plugin.CoroutinesPlugin | ||
import ksm.plugin.PluginController | ||
import ksm.plugin.install | ||
|
||
@OptIn(LibraryApi::class) | ||
public fun PluginController.Builder.installCoroutines(scope: CoroutineScope) { | ||
install(CoroutinesPlugin(scope)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
navigation/navigation-compose/src/main/kotlin/ksm/navigation/compose/StateBuilderScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
package ksm.navigation.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import ksm.StateController | ||
import ksm.navigation.NavigationController | ||
import ksm.navigation.compose.plugin.ComposePlugin | ||
import ksm.navigation.state.route.StateBuilderScope | ||
import ksm.navigation.route.StateBuilderScope | ||
import ksm.plugin.plugin | ||
|
||
public fun StateBuilderScope.Content( | ||
block: @Composable NavigationController.() -> Unit | ||
block: @Composable ComposeController.() -> Unit | ||
) { | ||
context.plugin(ComposePlugin).setContent(context, block) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...on/navigation-compose/src/main/kotlin/ksm/navigation/compose/route/ComposeBuilderScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ksm.navigation.compose.route | ||
|
||
import androidx.compose.runtime.Composable | ||
import ksm.context.StateContext | ||
import ksm.navigation.compose.ComposeController | ||
import ksm.navigation.compose.plugin.ComposePlugin | ||
import ksm.navigation.route.StateBuilderScope | ||
import ksm.plugin.plugin | ||
|
||
public fun ComposeBuilderScope(context: StateContext): ComposeBuilderScope { | ||
return object : ComposeBuilderScope { | ||
override val context = context | ||
} | ||
} | ||
|
||
public interface ComposeBuilderScope : StateBuilderScope | ||
|
||
@Suppress("FunctionName") | ||
public fun ComposeBuilderScope.Content(content: @Composable ComposeController.() -> Unit) { | ||
context.plugin(ComposePlugin).setContent( | ||
context = context, | ||
content = content | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
...tion/navigation-compose/src/main/kotlin/ksm/navigation/compose/route/ComposeController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ksm.navigation.compose.route | ||
|
||
import ksm.navigation.compose.ComposeController | ||
import ksm.navigation.route.plugin.StateRoutePlugin | ||
import ksm.plugin.plugin | ||
|
||
public fun ComposeController.states(block: ComposeRouteScope.() -> Unit) { | ||
context.plugin(StateRoutePlugin).states(context) { context -> | ||
ComposeRouteScope(context).apply(block) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...tion/navigation-compose/src/main/kotlin/ksm/navigation/compose/route/ComposeRouteScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ksm.navigation.compose.route | ||
|
||
import ksm.context.StateContext | ||
import ksm.navigation.route.StateRouteScope | ||
import ksm.navigation.state.name.interceptNamedRoute | ||
|
||
public fun ComposeRouteScope(context: StateContext): ComposeRouteScope { | ||
return object : ComposeRouteScope { | ||
override val context = context | ||
} | ||
} | ||
|
||
public interface ComposeRouteScope : StateRouteScope | ||
|
||
public inline fun ComposeRouteScope.named(name: String, block: ComposeBuilderScope.() -> Unit) { | ||
context.interceptNamedRoute(name) { ComposeBuilderScope(context).block() } | ||
} |
2 changes: 1 addition & 1 deletion
2
navigation/navigation-mdi/src/commonMain/kotlin/ksm/navigation/mdi/StateBuilderScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
plugins { | ||
id("js-browser-library-convention") | ||
} | ||
|
||
version = libs.versions.ksm.get() | ||
|
||
dependencies { | ||
commonMainApi(projects.navigation) | ||
jsMainImplementation(libs.react) | ||
jsMainImplementation(libs.react.dom) | ||
} |
21 changes: 21 additions & 0 deletions
21
navigation/navigation-react/src/jsMain/kotlin/ksm/navigation/react/ReactController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ksm.navigation.react | ||
|
||
import ksm.context.StateContext | ||
import ksm.navigation.NavigationController | ||
import ksm.plugin.factory.StateControllerFactory | ||
import kotlin.reflect.KType | ||
import kotlin.reflect.typeOf | ||
|
||
public interface ReactController : NavigationController { | ||
public interface Builder : NavigationController.Builder | ||
|
||
public companion object : StateControllerFactory { | ||
override val type: KType = typeOf<ReactController>() | ||
|
||
override fun wrap(context: StateContext): ReactController { | ||
return object : ReactController { | ||
override val context = context | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
navigation/navigation-react/src/jsMain/kotlin/ksm/navigation/react/ReactControllerBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ksm.navigation.react | ||
|
||
import ksm.annotation.LibraryApi | ||
import ksm.context.StateContext | ||
import ksm.navigation.navigationRuntime | ||
import ksm.navigation.react.observable.ObservableState | ||
import ksm.navigation.react.plugin.ReactPlugin | ||
import ksm.plugin.install | ||
|
||
@LibraryApi | ||
public inline fun ReactController.Builder.reactRuntime( | ||
enableConfiguration: Boolean = true, | ||
enableLifecycle: Boolean = true, | ||
enableFinishOnce: Boolean = true, | ||
enableStateName: Boolean = true, | ||
enableStateParameters: Boolean = true, | ||
enableStack: Boolean = true, | ||
enableStateRoutePlugin: Boolean = true, | ||
block: () -> Unit | ||
) { | ||
navigationRuntime( | ||
controllerFactory = ReactController, | ||
enableConfiguration = enableConfiguration, | ||
enableLifecycle = enableLifecycle, | ||
enableFinishOnce = enableFinishOnce, | ||
enableStateName = enableStateName, | ||
enableStateParameters = enableStateParameters, | ||
enableStack = enableStack, | ||
enableStateRoutePlugin = enableStateRoutePlugin | ||
) { | ||
install(ReactPlugin) | ||
block() | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
navigation/navigation-react/src/jsMain/kotlin/ksm/navigation/react/UseReactController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ksm.navigation.react | ||
|
||
import ksm.annotation.LibraryApi | ||
import ksm.context.StateContext | ||
import react.useMemo | ||
|
||
/** | ||
* Only works inside fc | ||
*/ | ||
@OptIn(LibraryApi::class) | ||
public fun useReactController( | ||
enableConfiguration: Boolean = true, | ||
enableLifecycle: Boolean = true, | ||
enableFinishOnce: Boolean = true, | ||
enableStateName: Boolean = true, | ||
enableStateParameters: Boolean = true, | ||
enableStack: Boolean = true, | ||
enableStateRoutePlugin: Boolean = true, | ||
builder: ReactController.Builder.() -> Unit = {} | ||
): ReactController { | ||
return useMemo( | ||
enableConfiguration, | ||
enableLifecycle, | ||
enableFinishOnce, | ||
enableStateName, | ||
enableStateParameters, | ||
enableStack, | ||
enableStateRoutePlugin | ||
) { | ||
val scope = object : ReactController.Builder { | ||
override var context: StateContext = StateContext.Empty | ||
} | ||
scope.reactRuntime( | ||
enableConfiguration = enableConfiguration, | ||
enableLifecycle = enableLifecycle, | ||
enableFinishOnce = enableFinishOnce, | ||
enableStateName = enableStateName, | ||
enableStateParameters = enableStateParameters, | ||
enableStack = enableStack, | ||
enableStateRoutePlugin = enableStateRoutePlugin | ||
) { | ||
builder(scope) | ||
} | ||
ReactController.wrap(scope.context) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
navigation/navigation-react/src/jsMain/kotlin/ksm/navigation/react/example/ReactExample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ksm.navigation.react.example | ||
|
||
import ksm.navigation.react.host.ReactStateHost | ||
import ksm.navigation.react.host.ReactStateHostComponent | ||
import ksm.navigation.react.route.component | ||
import ksm.navigation.react.route.named | ||
import ksm.navigation.react.route.states | ||
import ksm.navigation.react.useReactController | ||
import react.FC | ||
|
||
private val exampleComponent = FC { | ||
val controller = useReactController() | ||
|
||
controller.states { | ||
named("FirstState") { | ||
component { | ||
|
||
} | ||
} | ||
named("SecondState") { | ||
component { | ||
|
||
} | ||
} | ||
} | ||
|
||
ReactStateHost( | ||
controller = controller, | ||
startStateName = "FirstState" | ||
) | ||
} |
Oops, something went wrong.