diff --git a/.gitignore b/.gitignore index 7fab40d3..6d07da58 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ build/ data/ !gradle-wrapper.jar + +/kotlin-js-store/yarn.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index d2cf0882..a59c31d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,11 @@ ## [Unreleased] ### Added +- Context receivers flag ### Changed - Naming of Canvas3D options -- Lights are added to the scene instead of 3D options +- Lights are added to the scene instead of 3D options ### Deprecated diff --git a/build.gradle.kts b/build.gradle.kts index c3148a64..3d983923 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ val fxVersion by extra("11") allprojects{ group = "space.kscience" - version = "0.2.1-dev-1" + version = "0.3.0-dev-1" } subprojects { diff --git a/demo/muon-monitor/build.gradle.kts b/demo/muon-monitor/build.gradle.kts index 59d3495a..f3b1710c 100644 --- a/demo/muon-monitor/build.gradle.kts +++ b/demo/muon-monitor/build.gradle.kts @@ -45,8 +45,9 @@ kotlin { jvmMain { dependencies { implementation("org.apache.commons:commons-math3:3.6.1") - implementation("io.ktor-server-cio:${npmlibs.versions.ktor}") - implementation("io.ktor:ktor-serialization-kotlinx-json:${npmlibs.versions.ktor}") + implementation("io.ktor:ktor-server-cio:${ktorVersion}") + implementation("io.ktor:ktor-server-content-negotiation:${ktorVersion}") + implementation("io.ktor:ktor-serialization-kotlinx-json:${ktorVersion}") } } jsMain { diff --git a/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/MMServer.kt b/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/MMServer.kt index 29abd7ca..aa533431 100644 --- a/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/MMServer.kt +++ b/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/MMServer.kt @@ -1,24 +1,22 @@ package ru.mipt.npm.muon.monitor.server -import io.ktor.application.Application -import io.ktor.application.call -import io.ktor.application.install -import io.ktor.application.log -import io.ktor.features.CallLogging -import io.ktor.features.ContentNegotiation -import io.ktor.features.DefaultHeaders import io.ktor.http.ContentType import io.ktor.http.HttpStatusCode -import io.ktor.http.content.resources -import io.ktor.http.content.static -import io.ktor.response.respond -import io.ktor.response.respondText -import io.ktor.routing.Routing -import io.ktor.routing.get -import io.ktor.serialization.json +import io.ktor.serialization.kotlinx.json.json +import io.ktor.server.application.Application +import io.ktor.server.application.call +import io.ktor.server.application.install +import io.ktor.server.application.log import io.ktor.server.cio.CIO import io.ktor.server.engine.embeddedServer +import io.ktor.server.http.content.resources +import io.ktor.server.http.content.static +import io.ktor.server.plugins.contentnegotiation.ContentNegotiation +import io.ktor.server.response.respond +import io.ktor.server.response.respondText +import io.ktor.server.routing.Routing +import io.ktor.server.routing.get import org.apache.commons.math3.random.JDKRandomGenerator import ru.mipt.npm.muon.monitor.Model import ru.mipt.npm.muon.monitor.sim.Cos2TrackGenerator @@ -40,8 +38,6 @@ fun Application.module(context: Context = Global) { environment.log.info("Current directory: $currentDir") val solidManager = context.fetch(Solids) - install(DefaultHeaders) - install(CallLogging) install(ContentNegotiation) { json() } diff --git a/demo/playground/build.gradle.kts b/demo/playground/build.gradle.kts index 61f4e033..076f9d37 100644 --- a/demo/playground/build.gradle.kts +++ b/demo/playground/build.gradle.kts @@ -32,7 +32,7 @@ kotlin { kotlinOptions { jvmTarget = "11" freeCompilerArgs = - freeCompilerArgs + "-Xjvm-default=all" + "-Xopt-in=kotlin.RequiresOptIn" + "-Xlambdas=indy" + freeCompilerArgs + "-Xjvm-default=all" + "-Xopt-in=kotlin.RequiresOptIn" + "-Xlambdas=indy" + "-Xcontext-receivers" } } testRuns["test"].executionTask.configure { diff --git a/gradle.properties b/gradle.properties index 1d420172..f6fbbfc2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,5 +3,6 @@ kotlin.mpp.stability.nowarn=true kotlin.jupyter.add.scanner=false org.gradle.parallel=true +org.gradle.jvmargs=-Xmx4G toolsVersion=0.11.4-kotlin-1.6.20 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e5897..aa991fce 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/ui/bootstrap/src/main/kotlin/space/kscience/visionforge/bootstrap/tabComponent.kt b/ui/bootstrap/src/main/kotlin/space/kscience/visionforge/bootstrap/tabComponent.kt index 07bd9b55..23b5071b 100644 --- a/ui/bootstrap/src/main/kotlin/space/kscience/visionforge/bootstrap/tabComponent.kt +++ b/ui/bootstrap/src/main/kotlin/space/kscience/visionforge/bootstrap/tabComponent.kt @@ -30,7 +30,7 @@ public external interface TabPaneProps : PropsWithChildren { public val TabPane: FC = fc("TabPane") { props -> var activeTab: String? by useState(props.activeTab) - val children: Array = Children.map(props.children) { + val children: Array?> = Children.map(props.children) { it.asElementOrNull() } ?: emptyArray() diff --git a/visionforge-server/build.gradle.kts b/visionforge-server/build.gradle.kts index 86234c10..a89f2d07 100644 --- a/visionforge-server/build.gradle.kts +++ b/visionforge-server/build.gradle.kts @@ -2,9 +2,12 @@ plugins { id("ru.mipt.npm.gradle.jvm") } +val ktorVersion = npmlibs.versions.ktor.get() + dependencies { api(project(":visionforge-core")) - api("io.ktor-server-cio:${npmlibs.versions.ktor}") - api("io.ktor:ktor-server-html-builder:${npmlibs.versions.ktor}") - api("io.ktor:ktor-server-websockets:${npmlibs.versions.ktor}") + api("io.ktor:ktor-server-cio:${ktorVersion}") + api("io.ktor:ktor-server-html-builder:${ktorVersion}") + api("io.ktor:ktor-server-websockets:${ktorVersion}") + implementation("io.ktor:ktor-server-cors:${ktorVersion}") } \ No newline at end of file diff --git a/visionforge-server/src/main/kotlin/space/kscience/visionforge/server/VisionServer.kt b/visionforge-server/src/main/kotlin/space/kscience/visionforge/server/VisionServer.kt index 2abb6efb..7d55771c 100644 --- a/visionforge-server/src/main/kotlin/space/kscience/visionforge/server/VisionServer.kt +++ b/visionforge-server/src/main/kotlin/space/kscience/visionforge/server/VisionServer.kt @@ -1,24 +1,25 @@ package space.kscience.visionforge.server -import io.ktor.application.* -import io.ktor.features.CORS -import io.ktor.features.CallLogging -import io.ktor.html.respondHtml import io.ktor.http.* -import io.ktor.http.cio.websocket.Frame -import io.ktor.http.content.resources -import io.ktor.http.content.static -import io.ktor.response.respond -import io.ktor.response.respondText -import io.ktor.routing.* +import io.ktor.server.application.* import io.ktor.server.cio.CIO import io.ktor.server.engine.ApplicationEngine import io.ktor.server.engine.embeddedServer -import io.ktor.util.getOrFail -import io.ktor.websocket.WebSockets -import io.ktor.websocket.webSocket +import io.ktor.server.html.respondHtml +import io.ktor.server.http.content.resources +import io.ktor.server.http.content.static +import io.ktor.server.plugins.cors.CORS +import io.ktor.server.response.respond +import io.ktor.server.response.respondText +import io.ktor.server.routing.* +import io.ktor.server.util.getOrFail +import io.ktor.server.websocket.WebSockets +import io.ktor.server.websocket.webSocket +import io.ktor.websocket.Frame import kotlinx.coroutines.channels.consumeEach import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.html.* @@ -130,13 +131,13 @@ public class VisionServer internal constructor( try { withContext(visionManager.context.coroutineContext) { - vision.flowChanges(updateInterval.milliseconds).collect { update -> + vision.flowChanges(updateInterval.milliseconds).onEach { update -> val json = visionManager.jsonFormat.encodeToString( VisionChange.serializer(), update ) outgoing.send(Frame.Text(json)) - } + }.collect() } } catch (t: Throwable) { application.log.info("WebSocket update channel for $name is closed with exception: $t") @@ -241,21 +242,16 @@ public fun Application.visionServer( webServerUrl: Url, path: String = DEFAULT_PAGE, ): VisionServer { - if (featureOrNull(WebSockets) == null) { - install(WebSockets) + install(WebSockets) + install(CORS) { + anyHost() } - if (featureOrNull(CORS) == null) { - install(CORS) { - anyHost() - } - } +// if (pluginOrNull(CallLogging) == null) { +// install(CallLogging) +// } - if (featureOrNull(CallLogging) == null) { - install(CallLogging) - } - - val serverRoute = (featureOrNull(Routing) ?: install(Routing)).createRouteFromPath(path) + val serverRoute = install(Routing).createRouteFromPath(path) serverRoute { static { @@ -263,7 +259,7 @@ public fun Application.visionServer( } } - return VisionServer(visionManager, webServerUrl.copy(encodedPath = path), serverRoute) + return VisionServer(visionManager, URLBuilder(webServerUrl).apply { encodedPath = path }.build(), serverRoute) } /** diff --git a/visionforge-tables/src/jsMain/kotlin/space/kscience/visionforge/tables/TableVisionJsPlugin.kt b/visionforge-tables/src/jsMain/kotlin/space/kscience/visionforge/tables/TableVisionJsPlugin.kt index 42525847..bc1fb271 100644 --- a/visionforge-tables/src/jsMain/kotlin/space/kscience/visionforge/tables/TableVisionJsPlugin.kt +++ b/visionforge-tables/src/jsMain/kotlin/space/kscience/visionforge/tables/TableVisionJsPlugin.kt @@ -1,6 +1,6 @@ package space.kscience.visionforge.tables -import kotlinext.js.jso +import kotlinx.js.jso import org.w3c.dom.Element import org.w3c.dom.HTMLElement import space.kscience.dataforge.context.AbstractPlugin diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeLabelFactory.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeLabelFactory.kt index 02586120..38e3e6a6 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeLabelFactory.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeLabelFactory.kt @@ -4,7 +4,6 @@ package space.kscience.visionforge.solid.three import info.laht.threekt.core.Object3D import info.laht.threekt.geometries.TextBufferGeometry import info.laht.threekt.objects.Mesh -import kotlinext.js.jsObject import kotlinext.js.jso import space.kscience.dataforge.context.logger import space.kscience.dataforge.context.warn