diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
index 6d0ee1c..2e4da65 100644
--- a/.idea/kotlinc.xml
+++ b/.idea/kotlinc.xml
@@ -1,6 +1,7 @@
-
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/JsApp.xml b/.idea/runConfigurations/JsApp.xml
index 5e4d9f0..d9479b8 100644
--- a/.idea/runConfigurations/JsApp.xml
+++ b/.idea/runConfigurations/JsApp.xml
@@ -2,7 +2,7 @@
-
+
true
true
+ false
false
false
+ false
+ false
\ No newline at end of file
diff --git a/.idea/runConfigurations/desktopApp.xml b/.idea/runConfigurations/desktopApp.xml
index 05feec7..e0e41df 100644
--- a/.idea/runConfigurations/desktopApp.xml
+++ b/.idea/runConfigurations/desktopApp.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/.idea/runConfigurations/desktopAppHotReload.xml b/.idea/runConfigurations/desktopAppHotReload.xml
index 6746435..d11837a 100644
--- a/.idea/runConfigurations/desktopAppHotReload.xml
+++ b/.idea/runConfigurations/desktopAppHotReload.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/.idea/runConfigurations/wasmJsApp.xml b/.idea/runConfigurations/wasmJsApp.xml
index 06af0f0..52804ba 100644
--- a/.idea/runConfigurations/wasmJsApp.xml
+++ b/.idea/runConfigurations/wasmJsApp.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/README.md b/README.md
index 2837472..374a26a 100644
--- a/README.md
+++ b/README.md
@@ -95,7 +95,7 @@ JsonTree(
## Search
-JsonTree can be searched for keys and values by using the `searchState` parameter. The SearchState provides the following data about the current results. For an example on how to implement a search UI see the sample [here](sample/src/commonMain/kotlin/App.kt).
+JsonTree can be searched for keys and values by using the `searchState` parameter. The SearchState provides the following data about the current results. For an example on how to implement a search UI see the sample [here](shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/App.kt).
- `query` - The string which should be searched in the JsonTree
- `totalResults` - The total count of results for the query
diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts
index 2275972..8709079 100644
--- a/androidApp/build.gradle.kts
+++ b/androidApp/build.gradle.kts
@@ -22,7 +22,7 @@ android {
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
- "proguard-rules.pro"
+ "proguard-rules.pro",
)
// for testing only, don't do this in your app
signingConfig = signingConfigs.getByName("debug")
@@ -39,7 +39,7 @@ android {
}
dependencies {
- implementation(project(":sample"))
+ implementation(project(":shared"))
implementation(libs.androidx.activity.compose)
implementation(libs.jb.compose.components.resources)
-}
\ No newline at end of file
+}
diff --git a/build.gradle.kts b/build.gradle.kts
index e5ce7f0..5999fa4 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -9,6 +9,7 @@ buildscript {
plugins {
alias(libs.plugins.android.application).apply(false)
alias(libs.plugins.kotlinMultiplatform).apply(false)
+ alias(libs.plugins.kotlinJvm).apply(false)
alias(libs.plugins.compose).apply(false)
alias(libs.plugins.compose.compiler).apply(false)
alias(libs.plugins.publish).apply(false)
@@ -18,14 +19,16 @@ plugins {
}
apiValidation {
- ignoredProjects.add("sample")
+ ignoredProjects.addAll(listOf("shared", "desktopApp", "webApp"))
}
val projectSource = file(projectDir)
val configFiles = files("$rootDir/detekt/config.yml")
val baselineFile = File("$rootDir/detekt/baseline.xml")
val kotlinFiles = "**/*.kt"
-val sampleModuleFiles = "**/sample/**"
+val sharedModuleFiles = "**/shared/**"
+val desktopAppModuleFiles = "**/desktopApp/**"
+val webAppModuleFiles = "**/webApp/**"
val resourceFiles = "**/resources/**"
val buildFiles = "**/build/**"
val testFiles = "**/commonTest/**"
@@ -57,15 +60,14 @@ tasks.register("detektGene
baseline.set(baselineFile)
config.setFrom(configFiles)
include(kotlinFiles)
- exclude(sampleModuleFiles, resourceFiles, buildFiles, testFiles)
+ exclude(sharedModuleFiles, desktopAppModuleFiles, webAppModuleFiles, resourceFiles, buildFiles, testFiles)
}
-
tasks.withType().configureEach {
include(kotlinFiles)
- exclude(sampleModuleFiles, resourceFiles, buildFiles, testFiles)
+ exclude(sharedModuleFiles, desktopAppModuleFiles, webAppModuleFiles, resourceFiles, buildFiles, testFiles)
}
dependencies {
detektPlugins(libs.detekt.formatting)
-}
\ No newline at end of file
+}
diff --git a/desktopApp/build.gradle.kts b/desktopApp/build.gradle.kts
new file mode 100644
index 0000000..f6c260f
--- /dev/null
+++ b/desktopApp/build.gradle.kts
@@ -0,0 +1,35 @@
+import org.jetbrains.compose.desktop.application.dsl.TargetFormat
+
+plugins {
+ alias(libs.plugins.kotlinJvm)
+ alias(libs.plugins.compose)
+ alias(libs.plugins.compose.compiler)
+}
+
+group = "com.sebastianneubauer.jsontreesample"
+version = "1.0"
+
+dependencies {
+ implementation(project(":shared"))
+ implementation(compose.desktop.currentOs)
+}
+
+kotlin {
+ jvmToolchain(17)
+}
+
+compose.desktop {
+ application {
+ mainClass = "com.sebastianneubauer.jsontreesample.MainKt"
+ buildTypes.release {
+ proguard {
+ configurationFiles.from("compose-desktop.pro")
+ }
+ }
+ nativeDistributions {
+ targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
+ packageName = "com.sebastianneubauer.jsontreesample"
+ packageVersion = "1.0.0"
+ }
+ }
+}
diff --git a/sample/compose-desktop.pro b/desktopApp/compose-desktop.pro
similarity index 100%
rename from sample/compose-desktop.pro
rename to desktopApp/compose-desktop.pro
diff --git a/sample/src/jvmMain/kotlin/com/sebastianneubauer/jsontreesample/main.kt b/desktopApp/src/main/kotlin/com/sebastianneubauer/jsontreesample/main.kt
similarity index 100%
rename from sample/src/jvmMain/kotlin/com/sebastianneubauer/jsontreesample/main.kt
rename to desktopApp/src/main/kotlin/com/sebastianneubauer/jsontreesample/main.kt
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 4efa713..afefbe7 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -42,6 +42,7 @@ detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting",
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
+kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
androidKotlinMultiplatformLibrary = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" }
compose = { id = "org.jetbrains.compose", version.ref = "compose" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
diff --git a/iosApp/iosApp.xcodeproj/project.pbxproj b/iosApp/iosApp.xcodeproj/project.pbxproj
index 42f290d..030c094 100644
--- a/iosApp/iosApp.xcodeproj/project.pbxproj
+++ b/iosApp/iosApp.xcodeproj/project.pbxproj
@@ -175,7 +175,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "if [ \"YES\" = \"$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED\" ]; then\n echo \"Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \\\"YES\\\"\"\n exit 0\nfi\ncd \"$SRCROOT/..\"\n./gradlew :sample:embedAndSignAppleFrameworkForXcode\n";
+ shellScript = "if [ \"YES\" = \"$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED\" ]; then\n echo \"Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \\\"YES\\\"\"\n exit 0\nfi\ncd \"$SRCROOT/..\"\n./gradlew :shared:embedAndSignAppleFrameworkForXcode\n";
};
/* End PBXShellScriptBuildPhase section */
@@ -323,7 +323,7 @@
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
- "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)\n$(SRCROOT)/../sample/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
+ "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
);
INFOPLIST_FILE = iosApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.3;
@@ -350,7 +350,7 @@
ENABLE_PREVIEWS = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
- "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)\n$(SRCROOT)/../sample/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
+ "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
);
INFOPLIST_FILE = iosApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.3;
diff --git a/iosApp/iosApp/ContentView.swift b/iosApp/iosApp/ContentView.swift
index ab75edd..110d219 100644
--- a/iosApp/iosApp/ContentView.swift
+++ b/iosApp/iosApp/ContentView.swift
@@ -1,6 +1,6 @@
import UIKit
import SwiftUI
-import Sample
+import Shared
struct ComposeView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
diff --git a/jsontree/build.gradle.kts b/jsontree/build.gradle.kts
index 65fa97a..c1dcac9 100644
--- a/jsontree/build.gradle.kts
+++ b/jsontree/build.gradle.kts
@@ -1,6 +1,5 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
-import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree
plugins {
alias(libs.plugins.kotlinMultiplatform)
@@ -81,4 +80,4 @@ kotlin {
implementation(compose.desktop.currentOs)
}
}
-}
\ No newline at end of file
+}
diff --git a/sample/src/wasmJsMain/kotlin/com/sebastianneubauer/jsontreesample/main.wasm.kt b/sample/src/wasmJsMain/kotlin/com/sebastianneubauer/jsontreesample/main.wasm.kt
deleted file mode 100644
index 98ce44d..0000000
--- a/sample/src/wasmJsMain/kotlin/com/sebastianneubauer/jsontreesample/main.wasm.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.sebastianneubauer.jsontreesample
-
-import androidx.compose.ui.ExperimentalComposeUiApi
-import androidx.compose.ui.window.ComposeViewport
-import kotlinx.browser.document
-import org.jetbrains.compose.resources.ExperimentalResourceApi
-import org.jetbrains.compose.resources.configureWebResources
-
-@OptIn(ExperimentalComposeUiApi::class, ExperimentalResourceApi::class)
-fun main() {
- configureWebResources {
- resourcePathMapping { path -> "./$path" }
- }
- ComposeViewport(document.body!!) {
- App()
- }
-}
\ No newline at end of file
diff --git a/sample/src/wasmJsMain/resources/index.html b/sample/src/wasmJsMain/resources/index.html
deleted file mode 100644
index 7207c3a..0000000
--- a/sample/src/wasmJsMain/resources/index.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
- JsonTree
-
-
-
-
-
-
\ No newline at end of file
diff --git a/sample/src/wasmJsMain/resources/styles.css b/sample/src/wasmJsMain/resources/styles.css
deleted file mode 100644
index 0549b10..0000000
--- a/sample/src/wasmJsMain/resources/styles.css
+++ /dev/null
@@ -1,7 +0,0 @@
-html, body {
- width: 100%;
- height: 100%;
- margin: 0;
- padding: 0;
- overflow: hidden;
-}
\ No newline at end of file
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 8212c51..508f56a 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -13,5 +13,7 @@ dependencyResolutionManagement {
}
rootProject.name = "JsonTree"
include(":jsontree")
-include(":sample")
+include(":shared")
include(":androidApp")
+include(":desktopApp")
+include(":webApp")
diff --git a/sample/build.gradle.kts b/shared/build.gradle.kts
similarity index 60%
rename from sample/build.gradle.kts
rename to shared/build.gradle.kts
index df4735c..faa832a 100644
--- a/sample/build.gradle.kts
+++ b/shared/build.gradle.kts
@@ -1,4 +1,3 @@
-import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
plugins {
@@ -25,26 +24,22 @@ kotlin {
listOf(
iosX64(),
iosArm64(),
- iosSimulatorArm64()
+ iosSimulatorArm64(),
).forEach {
it.binaries.framework {
- baseName = "Sample"
+ baseName = "Shared"
isStatic = true
}
}
js {
- outputModuleName = "jsontree"
browser()
- binaries.executable()
useEsModules()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
- outputModuleName = "jsontree"
browser()
- binaries.executable()
}
sourceSets {
@@ -66,32 +61,18 @@ kotlin {
commonTest.dependencies {
implementation(kotlin("test"))
}
-
- jvmMain.dependencies {
- implementation(compose.desktop.currentOs)
- }
}
- //https://kotlinlang.org/docs/native-objc-interop.html#export-of-kdoc-comments-to-generated-objective-c-headers
+ // https://kotlinlang.org/docs/native-objc-interop.html#export-of-kdoc-comments-to-generated-objective-c-headers
targets.withType {
- compilations["main"].compilerOptions.options.freeCompilerArgs.add("-Xexport-kdoc")
+ compilations["main"]
+ .compilerOptions.options.freeCompilerArgs
+ .add("-Xexport-kdoc")
}
jvmToolchain(17)
}
-compose.desktop {
- application {
- mainClass = "com.sebastianneubauer.jsontreesample.MainKt"
- buildTypes.release {
- proguard {
- configurationFiles.from("compose-desktop.pro")
- }
- }
- nativeDistributions {
- targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
- packageName = "com.sebastianneubauer.jsontreesample"
- packageVersion = "1.0.0"
- }
- }
+compose.resources {
+ packageOfResClass = "com.sebastianneubauer.jsontreesample.shared.generated.resources"
}
diff --git a/sample/src/commonMain/composeResources/drawable/arrow_down.xml b/shared/src/commonMain/composeResources/drawable/arrow_down.xml
similarity index 100%
rename from sample/src/commonMain/composeResources/drawable/arrow_down.xml
rename to shared/src/commonMain/composeResources/drawable/arrow_down.xml
diff --git a/sample/src/commonMain/composeResources/drawable/arrow_up.xml b/shared/src/commonMain/composeResources/drawable/arrow_up.xml
similarity index 100%
rename from sample/src/commonMain/composeResources/drawable/arrow_up.xml
rename to shared/src/commonMain/composeResources/drawable/arrow_up.xml
diff --git a/sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/App.kt b/shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/App.kt
similarity index 73%
rename from sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/App.kt
rename to shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/App.kt
index 34f2c03..6a1f45b 100644
--- a/sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/App.kt
+++ b/shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/App.kt
@@ -54,22 +54,23 @@ import com.sebastianneubauer.jsontree.diff.JsonTreeDiffInfo
import com.sebastianneubauer.jsontree.diff.defaultDarkDiffColors
import com.sebastianneubauer.jsontree.diff.defaultLightDiffColors
import com.sebastianneubauer.jsontree.search.rememberSearchState
-import com.sebastianneubauer.jsontreesample.sample.generated.resources.Res
-import com.sebastianneubauer.jsontreesample.sample.generated.resources.arrow_down
-import com.sebastianneubauer.jsontreesample.sample.generated.resources.arrow_up
+import com.sebastianneubauer.jsontreesample.shared.generated.resources.Res
+import com.sebastianneubauer.jsontreesample.shared.generated.resources.arrow_down
+import com.sebastianneubauer.jsontreesample.shared.generated.resources.arrow_up
import com.sebastianneubauer.jsontreesample.ui.theme.JsonTreeTheme
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.painterResource
@Composable
-fun App() = JsonTreeTheme(darkTheme = false) {
- MainScreen()
-}
+fun App() =
+ JsonTreeTheme(darkTheme = false) {
+ MainScreen()
+ }
@OptIn(
ExperimentalMaterial3Api::class,
ExperimentalFoundationApi::class,
- ExperimentalLayoutApi::class
+ ExperimentalLayoutApi::class,
)
@Composable
private fun MainScreen() {
@@ -88,12 +89,13 @@ private fun MainScreen() {
)
},
contentWindowInsets = WindowInsets(top = 60.dp),
- containerColor = Color.White
+ containerColor = Color.White,
) { padding ->
Column(
- modifier = Modifier
- .fillMaxSize()
- .padding(padding)
+ modifier =
+ Modifier
+ .fillMaxSize()
+ .padding(padding),
) {
var errorMessage: String? by remember { mutableStateOf(null) }
var json: String by remember { mutableStateOf(simpleJson) }
@@ -117,50 +119,53 @@ private fun MainScreen() {
modifier = Modifier.padding(horizontal = 8.dp),
onClick = {
errorMessage = null
- json = when (json) {
- emptyJson -> simpleJson
- simpleJson -> complexJson
- complexJson -> invalidJson
- invalidJson -> emptyJson
- else -> throw IllegalStateException("No JSON selected!")
- }
- }
+ json =
+ when (json) {
+ emptyJson -> simpleJson
+ simpleJson -> complexJson
+ complexJson -> invalidJson
+ invalidJson -> emptyJson
+ else -> throw IllegalStateException("No JSON selected!")
+ }
+ },
) {
Text(
- text = when (json) {
- simpleJson -> "Simple Json"
- emptyJson -> "Empty Json"
- complexJson -> "Complex Json"
- invalidJson -> "Invalid Json"
- else -> throw IllegalStateException("No JSON selected!")
- }
+ text =
+ when (json) {
+ simpleJson -> "Simple Json"
+ emptyJson -> "Empty Json"
+ complexJson -> "Complex Json"
+ invalidJson -> "Invalid Json"
+ else -> throw IllegalStateException("No JSON selected!")
+ },
)
}
Button(
modifier = Modifier.padding(horizontal = 8.dp),
onClick = {
- val newState = when (initialState) {
- TreeState.EXPANDED -> TreeState.COLLAPSED
- TreeState.COLLAPSED -> TreeState.FIRST_ITEM_EXPANDED
- TreeState.FIRST_ITEM_EXPANDED -> TreeState.EXPANDED
- }
+ val newState =
+ when (initialState) {
+ TreeState.EXPANDED -> TreeState.COLLAPSED
+ TreeState.COLLAPSED -> TreeState.FIRST_ITEM_EXPANDED
+ TreeState.FIRST_ITEM_EXPANDED -> TreeState.EXPANDED
+ }
initialState = newState
- }
+ },
) {
Text(text = initialState.name)
}
Button(
modifier = Modifier.padding(horizontal = 8.dp),
- onClick = { showIndices = !showIndices }
+ onClick = { showIndices = !showIndices },
) {
Text(text = if (showIndices) "Hide indices" else "Show indices")
}
Button(
modifier = Modifier.padding(horizontal = 8.dp),
- onClick = { showItemCount = !showItemCount }
+ onClick = { showItemCount = !showItemCount },
) {
Text(text = if (showItemCount) "Hide item count" else "Show item count")
}
@@ -169,28 +174,28 @@ private fun MainScreen() {
modifier = Modifier.padding(horizontal = 8.dp),
onClick = {
colors = if (colors == defaultLightColors) defaultDarkColors else defaultLightColors
- }
+ },
) {
Text(text = if (colors == defaultLightColors) "Light" else "Dark")
}
Button(
modifier = Modifier.padding(horizontal = 8.dp),
- onClick = { expandSingleChildren = !expandSingleChildren }
+ onClick = { expandSingleChildren = !expandSingleChildren },
) {
Text(text = if (expandSingleChildren) "Expand children" else "Don't expand children")
}
Button(
modifier = Modifier.padding(horizontal = 8.dp),
- onClick = { showDiff = !showDiff }
+ onClick = { showDiff = !showDiff },
) {
Text(text = if (showDiff) "Hide diff" else "Show diff")
}
Button(
modifier = Modifier.padding(horizontal = 8.dp),
- onClick = { showInlineDiffs = !showInlineDiffs }
+ onClick = { showInlineDiffs = !showInlineDiffs },
) {
Text(text = if (showInlineDiffs) "Hide inline diffs" else "Show inline diffs")
}
@@ -205,7 +210,7 @@ private fun MainScreen() {
coroutineScope.launch {
listState.animateScrollToItem(0)
}
- }
+ },
) {
Text(text = "To Top")
}
@@ -217,7 +222,7 @@ private fun MainScreen() {
val lastIndex = listState.layoutInfo.totalItemsCount - 1
listState.animateScrollToItem(lastIndex.coerceAtLeast(0))
}
- }
+ },
) {
Text(text = "To Bottom")
}
@@ -225,7 +230,7 @@ private fun MainScreen() {
Spacer(Modifier.height(8.dp))
- if(showDiff) {
+ if (showDiff) {
JsonDiff(
originalJson = json,
showInlineDiffs = showInlineDiffs,
@@ -240,32 +245,32 @@ private fun MainScreen() {
value = searchQuery,
onValueChange = { searchState.query = it },
singleLine = true,
- label = { Text("Search Key/Value") }
+ label = { Text("Search Key/Value") },
)
Row(
modifier = Modifier.padding(8.dp),
- verticalAlignment = Alignment.CenterVertically
+ verticalAlignment = Alignment.CenterVertically,
) {
IconButton(
onClick = {
coroutineScope.launch { searchState.selectNext() }
- }
+ },
) {
Icon(
painter = painterResource(Res.drawable.arrow_down),
- contentDescription = "next"
+ contentDescription = "next",
)
}
IconButton(
onClick = {
coroutineScope.launch { searchState.selectPrevious() }
- }
+ },
) {
Icon(
painter = painterResource(Res.drawable.arrow_up),
- contentDescription = "prev"
+ contentDescription = "prev",
)
}
@@ -277,48 +282,51 @@ private fun MainScreen() {
val pagerState = rememberPagerState(initialPage = 0, pageCount = { 3 })
- //Pager to test leaving composition
+ // Pager to test leaving composition
HorizontalPager(
modifier = Modifier.fillMaxWidth().weight(1F),
state = pagerState,
- verticalAlignment = Alignment.Top
+ verticalAlignment = Alignment.Top,
) { pageIndex ->
when (pageIndex) {
0 -> {
val error = errorMessage
if (error != null) {
Text(
- modifier = Modifier
- .fillMaxSize()
- .background(
- color = if (colors == defaultLightColors) Color.Unspecified else Color.Black
- ),
+ modifier =
+ Modifier
+ .fillMaxSize()
+ .background(
+ color = if (colors == defaultLightColors) Color.Unspecified else Color.Black,
+ ),
text = error,
color = if (colors == defaultLightColors) Color.Black else Color.White,
)
} else {
SelectionContainer {
JsonTree(
- modifier = Modifier
- .fillMaxSize()
- .horizontalScroll(rememberScrollState())
- .background(
- if (colors == defaultLightColors) Color.Unspecified else Color.Black
- ),
+ modifier =
+ Modifier
+ .fillMaxSize()
+ .horizontalScroll(rememberScrollState())
+ .background(
+ if (colors == defaultLightColors) Color.Unspecified else Color.Black,
+ ),
contentPadding = PaddingValues(vertical = jsonTreePadding),
json = json,
onLoading = {
Box(
- modifier = Modifier
- .fillMaxSize()
- .background(
- if (colors == defaultLightColors) Color.Unspecified else Color.Black
- ),
- contentAlignment = Alignment.Center
+ modifier =
+ Modifier
+ .fillMaxSize()
+ .background(
+ if (colors == defaultLightColors) Color.Unspecified else Color.Black,
+ ),
+ contentAlignment = Alignment.Center,
) {
Text(
text = "Loading...",
- color = if (colors == defaultLightColors) Color.Black else Color.White
+ color = if (colors == defaultLightColors) Color.Black else Color.White,
)
}
},
@@ -339,7 +347,7 @@ private fun MainScreen() {
val resultIndex = searchState.selectedResultListIndex
LaunchedEffect(resultIndex) {
- if(resultIndex != null && !listState.isScrollInProgress) {
+ if (resultIndex != null && !listState.isScrollInProgress) {
listState.animateScrollToItem(resultIndex, jsonTreePaddingPx)
}
}
@@ -364,80 +372,86 @@ private fun MainScreen() {
private fun JsonDiff(
originalJson: String,
showInlineDiffs: Boolean,
- colors: TreeColors
+ colors: TreeColors,
) {
var diffInfo by remember(originalJson, showInlineDiffs) { mutableStateOf(null) }
val currentDiffInfo = diffInfo
Column {
- val lineChanges = if(currentDiffInfo != null) {
- val changeInfo = currentDiffInfo.changeInfo
- if(changeInfo.insertions == 0 && changeInfo.deletions == 0) {
- "Identical"
+ val lineChanges =
+ if (currentDiffInfo != null) {
+ val changeInfo = currentDiffInfo.changeInfo
+ if (changeInfo.insertions == 0 && changeInfo.deletions == 0) {
+ "Identical"
+ } else {
+ "+${changeInfo.insertions} -${changeInfo.deletions}"
+ }
} else {
- "+${changeInfo.insertions} -${changeInfo.deletions}"
+ null
}
- } else null
Row {
Text(
modifier = Modifier.weight(1F),
text = "Original:",
- color = Color.Black
+ color = Color.Black,
)
Row(modifier = Modifier.weight(1F)) {
Text(
modifier = Modifier.weight(1F),
text = "Revised:",
- color = Color.Black
+ color = Color.Black,
)
- if(lineChanges != null) {
+ if (lineChanges != null) {
Text(
text = lineChanges,
- color = Color.Black
+ color = Color.Black,
)
}
}
}
JsonTreeDiff(
- modifier = Modifier
- .fillMaxWidth()
- .height(400.dp),
+ modifier =
+ Modifier
+ .fillMaxWidth()
+ .height(400.dp),
originalJson = originalJson,
revisedJson = complexJsonRevised,
showInlineDiffs = showInlineDiffs,
- colors = if(colors == defaultLightColors) defaultLightDiffColors else defaultDarkDiffColors,
+ colors = if (colors == defaultLightColors) defaultLightDiffColors else defaultDarkDiffColors,
contentPadding = PaddingValues(8.dp),
onSuccess = { diffInfo = it.info },
onLoading = {
Box(
- modifier = Modifier
- .fillMaxSize()
- .background(
- if (colors == defaultLightColors) Color.White else Color.Black
- ),
- contentAlignment = Alignment.Center
+ modifier =
+ Modifier
+ .fillMaxSize()
+ .background(
+ if (colors == defaultLightColors) Color.White else Color.Black,
+ ),
+ contentAlignment = Alignment.Center,
) {
Text(
text = "Loading...",
- color = if (colors == defaultLightColors) Color.Black else Color.White
+ color = if (colors == defaultLightColors) Color.Black else Color.White,
)
}
},
onError = { errorState ->
Text(
- modifier = Modifier
- .fillMaxSize()
- .background(
- color = if (colors == defaultLightColors) Color.White else Color.Black
- ),
+ modifier =
+ Modifier
+ .fillMaxSize()
+ .background(
+ color = if (colors == defaultLightColors) Color.White else Color.Black,
+ ),
text = errorState.error.throwable.message ?: "Unknown error",
color = if (colors == defaultLightColors) Color.Black else Color.White,
)
- }
+ },
)
}
}
@@ -447,4 +461,4 @@ private fun JsonDiff(
private fun PreviewMainScreen() =
JsonTreeTheme {
MainScreen()
- }
\ No newline at end of file
+ }
diff --git a/sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/JsonStrings.kt b/shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/JsonStrings.kt
similarity index 100%
rename from sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/JsonStrings.kt
rename to shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/JsonStrings.kt
diff --git a/sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/JsonTreeDiffStrings.kt b/shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/JsonTreeDiffStrings.kt
similarity index 100%
rename from sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/JsonTreeDiffStrings.kt
rename to shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/JsonTreeDiffStrings.kt
diff --git a/sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Color.kt b/shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Color.kt
similarity index 100%
rename from sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Color.kt
rename to shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Color.kt
diff --git a/sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Shape.kt b/shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Shape.kt
similarity index 100%
rename from sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Shape.kt
rename to shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Shape.kt
diff --git a/sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Theme.kt b/shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Theme.kt
similarity index 100%
rename from sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Theme.kt
rename to shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Theme.kt
diff --git a/sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Type.kt b/shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Type.kt
similarity index 100%
rename from sample/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Type.kt
rename to shared/src/commonMain/kotlin/com/sebastianneubauer/jsontreesample/ui/theme/Type.kt
diff --git a/sample/src/iosMain/kotlin/com/sebastianneubauer/jsontreesample/main.kt b/shared/src/iosMain/kotlin/com/sebastianneubauer/jsontreesample/MainViewController.kt
similarity index 82%
rename from sample/src/iosMain/kotlin/com/sebastianneubauer/jsontreesample/main.kt
rename to shared/src/iosMain/kotlin/com/sebastianneubauer/jsontreesample/MainViewController.kt
index 628d527..e7d9bc4 100644
--- a/sample/src/iosMain/kotlin/com/sebastianneubauer/jsontreesample/main.kt
+++ b/shared/src/iosMain/kotlin/com/sebastianneubauer/jsontreesample/MainViewController.kt
@@ -1,7 +1,6 @@
package com.sebastianneubauer.jsontreesample
import androidx.compose.ui.window.ComposeUIViewController
-import com.sebastianneubauer.jsontreesample.App
import platform.UIKit.UIViewController
fun MainViewController(): UIViewController = ComposeUIViewController { App() }
diff --git a/webApp/build.gradle.kts b/webApp/build.gradle.kts
new file mode 100644
index 0000000..67f0dae
--- /dev/null
+++ b/webApp/build.gradle.kts
@@ -0,0 +1,31 @@
+import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
+
+plugins {
+ alias(libs.plugins.kotlinMultiplatform)
+ alias(libs.plugins.compose)
+ alias(libs.plugins.compose.compiler)
+}
+
+group = "com.sebastianneubauer.jsontreesample"
+version = "1.0"
+
+kotlin {
+ js {
+ browser()
+ binaries.executable()
+ }
+
+ @OptIn(ExperimentalWasmDsl::class)
+ wasmJs {
+ browser()
+ binaries.executable()
+ }
+
+ sourceSets {
+ commonMain.dependencies {
+ implementation(project(":shared"))
+ implementation(libs.jb.compose.runtime)
+ implementation(libs.jb.compose.foundation)
+ }
+ }
+}
diff --git a/sample/src/jsMain/kotlin/com/sebastianneubauer/jsontreesample/main.js.kt b/webApp/src/webMain/kotlin/com/sebastianneubauer/jsontreesample/main.kt
similarity index 55%
rename from sample/src/jsMain/kotlin/com/sebastianneubauer/jsontreesample/main.js.kt
rename to webApp/src/webMain/kotlin/com/sebastianneubauer/jsontreesample/main.kt
index 5e70eae..a670f73 100644
--- a/sample/src/jsMain/kotlin/com/sebastianneubauer/jsontreesample/main.js.kt
+++ b/webApp/src/webMain/kotlin/com/sebastianneubauer/jsontreesample/main.kt
@@ -2,14 +2,10 @@ package com.sebastianneubauer.jsontreesample
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.ComposeViewport
-import kotlinx.browser.document
-import org.jetbrains.skiko.wasm.onWasmReady
@OptIn(ExperimentalComposeUiApi::class)
fun main() {
- onWasmReady {
- ComposeViewport(document.body!!) {
- App()
- }
+ ComposeViewport {
+ App()
}
-}
\ No newline at end of file
+}
diff --git a/sample/src/jsMain/resources/index.html b/webApp/src/webMain/resources/index.html
similarity index 80%
rename from sample/src/jsMain/resources/index.html
rename to webApp/src/webMain/resources/index.html
index 7207c3a..130f57c 100644
--- a/sample/src/jsMain/resources/index.html
+++ b/webApp/src/webMain/resources/index.html
@@ -7,6 +7,6 @@
-
+