diff --git a/demo/muon-monitor/build.gradle.kts b/demo/muon-monitor/build.gradle.kts index a7bf2709..0ef8f166 100644 --- a/demo/muon-monitor/build.gradle.kts +++ b/demo/muon-monitor/build.gradle.kts @@ -5,7 +5,7 @@ plugins { group = "ru.mipt.npm" -val ktorVersion: String = ru.mipt.npm.gradle.KScienceVersions.ktorVersion +val ktorVersion: String = npmlibs.versions.ktor.get() kscience { useCoroutines() @@ -45,17 +45,17 @@ kotlin { jvmMain { dependencies { implementation("org.apache.commons:commons-math3:3.6.1") - implementation("io.ktor:ktor-server-cio:$ktorVersion") - implementation("io.ktor:ktor-serialization:$ktorVersion") + implementation(npmlibs.ktor.server.cio) + implementation(npmlibs.ktor.serialization) } } jsMain { dependencies { implementation(project(":ui:ring")) - implementation("io.ktor:ktor-client-js:$ktorVersion") - implementation("io.ktor:ktor-client-serialization:$ktorVersion") + implementation(npmlibs.ktor.client.js) + implementation(npmlibs.ktor.client.serialization) implementation(project(":visionforge-threejs")) - implementation(devNpm("webpack-bundle-analyzer", "4.4.0")) + //implementation(devNpm("webpack-bundle-analyzer", "4.4.0")) } } } diff --git a/gradle.properties b/gradle.properties index 41982482..fbaacb05 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,4 +7,6 @@ org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G org.gradle.parallel=true publishing.github=false -publishing.sonatype=false \ No newline at end of file +publishing.sonatype=false + +toolsVersion=0.10.9-kotlin-1.6.10 \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 088b448f..fb02e336 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ pluginManagement { - val toolsVersion = "0.10.7" + val toolsVersion: String by extra repositories { //mavenLocal() @@ -23,6 +23,9 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") enableFeaturePreview("VERSION_CATALOGS") dependencyResolutionManagement { + + val toolsVersion: String by extra + repositories { maven("https://repo.kotlin.link") mavenCentral() @@ -30,7 +33,7 @@ dependencyResolutionManagement { versionCatalogs { create("npmlibs") { - from("ru.mipt.npm:version-catalog:0.10.7") + from("ru.mipt.npm:version-catalog:$toolsVersion") } } } diff --git a/ui/react/src/main/kotlin/space/kscience/visionforge/react/MultiSelectChooser.kt b/ui/react/src/main/kotlin/space/kscience/visionforge/react/MultiSelectChooser.kt index 45a98abd..f3c81a57 100644 --- a/ui/react/src/main/kotlin/space/kscience/visionforge/react/MultiSelectChooser.kt +++ b/ui/react/src/main/kotlin/space/kscience/visionforge/react/MultiSelectChooser.kt @@ -5,35 +5,34 @@ import org.w3c.dom.HTMLOptionElement import org.w3c.dom.HTMLSelectElement import org.w3c.dom.asList import org.w3c.dom.events.Event -import react.FunctionComponent +import react.FC import react.dom.attrs import react.dom.option import react.dom.select -import react.functionComponent +import react.fc import space.kscience.dataforge.meta.descriptors.allowedValues import space.kscience.dataforge.values.asValue import space.kscience.dataforge.values.string @JsExport -public val MultiSelectChooser: FunctionComponent = - functionComponent("MultiSelectChooser") { props -> - val onChange: (Event) -> Unit = { event: Event -> - val newSelected = (event.target as HTMLSelectElement).selectedOptions.asList() - .map { (it as HTMLOptionElement).value.asValue() } - props.meta.value = newSelected.asValue() +public val MultiSelectChooser: FC = fc("MultiSelectChooser") { props -> + val onChange: (Event) -> Unit = { event: Event -> + val newSelected = (event.target as HTMLSelectElement).selectedOptions.asList() + .map { (it as HTMLOptionElement).value.asValue() } + props.meta.value = newSelected.asValue() + } + + select { + attrs { + multiple = true + values = (props.actual.value?.list ?: emptyList()).mapTo(HashSet()) { it.string } + onChangeFunction = onChange + } + props.descriptor?.allowedValues?.forEach { optionValue -> + option { + +optionValue.string + } } - select { - attrs { - multiple = true - values = (props.actual.value?.list ?: emptyList()).mapTo(HashSet()) { it.string } - onChangeFunction = onChange - } - props.descriptor?.allowedValues?.forEach { optionValue -> - option { - +optionValue.string - } - } - - } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/ui/react/src/main/kotlin/space/kscience/visionforge/react/PropertyEditor.kt b/ui/react/src/main/kotlin/space/kscience/visionforge/react/PropertyEditor.kt index 4264b77f..6c677e2e 100644 --- a/ui/react/src/main/kotlin/space/kscience/visionforge/react/PropertyEditor.kt +++ b/ui/react/src/main/kotlin/space/kscience/visionforge/react/PropertyEditor.kt @@ -47,10 +47,9 @@ public external interface PropertyEditorProps : Props { public var expanded: Boolean? } -private val PropertyEditorItem: FunctionComponent = - functionComponent("PropertyEditorItem") { props -> - propertyEditorItem(props) - } +private val PropertyEditorItem: FC = fc("PropertyEditorItem") { props -> + propertyEditorItem(props) +} private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { var expanded: Boolean by useState { props.expanded ?: true } @@ -129,7 +128,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { width = 160.px margin(1.px, 5.px) } - ValueChooser{ + ValueChooser { attrs { this.descriptor = descriptor this.meta = ownProperty @@ -193,7 +192,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { } @JsExport -public val PropertyEditor: FunctionComponent = functionComponent("PropertyEditor") { props -> +public val PropertyEditor: FC = fc("PropertyEditor") { props -> child(PropertyEditorItem) { attrs { this.key = "" @@ -211,7 +210,7 @@ public fun RBuilder.propertyEditor( allProperties: MetaProvider = ownProperties, descriptor: MetaDescriptor? = null, key: Any? = null, - expanded: Boolean? = null + expanded: Boolean? = null, ) { child(PropertyEditor) { attrs { diff --git a/ui/react/src/main/kotlin/space/kscience/visionforge/react/RangeValueChooser.kt b/ui/react/src/main/kotlin/space/kscience/visionforge/react/RangeValueChooser.kt index bda76147..8ccedc01 100644 --- a/ui/react/src/main/kotlin/space/kscience/visionforge/react/RangeValueChooser.kt +++ b/ui/react/src/main/kotlin/space/kscience/visionforge/react/RangeValueChooser.kt @@ -6,9 +6,9 @@ import kotlinx.html.InputType import kotlinx.html.js.onChangeFunction import org.w3c.dom.HTMLInputElement import org.w3c.dom.events.Event -import react.FunctionComponent +import react.FC import react.dom.attrs -import react.functionComponent +import react.fc import react.useState import space.kscience.dataforge.meta.descriptors.ValueRequirement import space.kscience.dataforge.meta.double @@ -19,58 +19,57 @@ import styled.css import styled.styledInput @JsExport -public val RangeValueChooser: FunctionComponent = - functionComponent("RangeValueChooser") { props -> - var innerValue by useState(props.actual.double) - var rangeDisabled: Boolean by useState(props.meta.value == null) +public val RangeValueChooser: FC = fc("RangeValueChooser") { props -> + var innerValue by useState(props.actual.double) + var rangeDisabled: Boolean by useState(props.meta.value == null) - val handleDisable: (Event) -> Unit = { - val checkBoxValue = (it.target as HTMLInputElement).checked - rangeDisabled = !checkBoxValue - props.meta.value = if(!checkBoxValue) { - null - } else { - innerValue?.asValue() - } + val handleDisable: (Event) -> Unit = { + val checkBoxValue = (it.target as HTMLInputElement).checked + rangeDisabled = !checkBoxValue + props.meta.value = if (!checkBoxValue) { + null + } else { + innerValue?.asValue() } + } - val handleChange: (Event) -> Unit = { - val newValue = (it.target as HTMLInputElement).value - props.meta.value = newValue.toDoubleOrNull()?.asValue() - innerValue = newValue.toDoubleOrNull() - } + val handleChange: (Event) -> Unit = { + val newValue = (it.target as HTMLInputElement).value + props.meta.value = newValue.toDoubleOrNull()?.asValue() + innerValue = newValue.toDoubleOrNull() + } - flexRow { - if(props.descriptor?.valueRequirement != ValueRequirement.REQUIRED) { - styledInput(type = InputType.checkBox) { - attrs { - defaultChecked = rangeDisabled.not() - onChangeFunction = handleDisable - } - } - } - - styledInput(type = InputType.range) { - css{ - width = 100.pct - } + flexRow { + if (props.descriptor?.valueRequirement != ValueRequirement.REQUIRED) { + styledInput(type = InputType.checkBox) { attrs { - disabled = rangeDisabled - value = innerValue?.toString() ?: "" - onChangeFunction = handleChange - consumer.onTagEvent(this, "input", handleChange) - val minValue = props.descriptor?.attributes?.get("min").string - minValue?.let { - min = it - } - val maxValue = props.descriptor?.attributes?.get("max").string - maxValue?.let { - max = it - } - props.descriptor?.attributes?.get("step").string?.let { - step = it - } + defaultChecked = rangeDisabled.not() + onChangeFunction = handleDisable } } } - } \ No newline at end of file + + styledInput(type = InputType.range) { + css { + width = 100.pct + } + attrs { + disabled = rangeDisabled + value = innerValue?.toString() ?: "" + onChangeFunction = handleChange + consumer.onTagEvent(this, "input", handleChange) + val minValue = props.descriptor?.attributes?.get("min").string + minValue?.let { + min = it + } + val maxValue = props.descriptor?.attributes?.get("max").string + maxValue?.let { + max = it + } + props.descriptor?.attributes?.get("step").string?.let { + step = it + } + } + } + } +} \ No newline at end of file diff --git a/ui/react/src/main/kotlin/space/kscience/visionforge/react/ThreeCanvasComponent.kt b/ui/react/src/main/kotlin/space/kscience/visionforge/react/ThreeCanvasComponent.kt index 319a867c..4683f579 100644 --- a/ui/react/src/main/kotlin/space/kscience/visionforge/react/ThreeCanvasComponent.kt +++ b/ui/react/src/main/kotlin/space/kscience/visionforge/react/ThreeCanvasComponent.kt @@ -21,13 +21,11 @@ public external interface ThreeCanvasProps : Props { public var selected: Name? } -public val ThreeCanvasComponent: FunctionComponent = functionComponent( - "ThreeCanvasComponent" -) { props -> +public val ThreeCanvasComponent: FC = fc("ThreeCanvasComponent") { props -> val elementRef = useRef(null) var canvas by useState(null) - val three: ThreePlugin = useMemo(props.context){ props.context.fetch(ThreePlugin) } + val three: ThreePlugin = useMemo(props.context) { props.context.fetch(ThreePlugin) } useEffect(props.solid, props.options, elementRef) { if (canvas == null) { diff --git a/ui/react/src/main/kotlin/space/kscience/visionforge/react/VisionTree.kt b/ui/react/src/main/kotlin/space/kscience/visionforge/react/VisionTree.kt index 539fa2ee..54fc8ec4 100644 --- a/ui/react/src/main/kotlin/space/kscience/visionforge/react/VisionTree.kt +++ b/ui/react/src/main/kotlin/space/kscience/visionforge/react/VisionTree.kt @@ -28,7 +28,7 @@ public external interface ObjectTreeProps : Props { public var clickCallback: (Name) -> Unit } -private val TreeLabel = functionComponent { props -> +private val TreeLabel = fc { props -> val token = useMemo(props.name) { props.name.lastOrNull()?.toString() ?: "World" } styledSpan { css { @@ -107,14 +107,14 @@ private fun RBuilder.visionTree(props: ObjectTreeProps): Unit { } @JsExport -public val ObjectTree: FunctionComponent = functionComponent("ObjectTree") { props -> +public val ObjectTree: FC = fc("ObjectTree") { props -> visionTree(props) } public fun RBuilder.visionTree( vision: Vision, selected: Name? = null, - clickCallback: (Name) -> Unit = {} + clickCallback: (Name) -> Unit = {}, ) { child(ObjectTree) { attrs { diff --git a/ui/react/src/main/kotlin/space/kscience/visionforge/react/valueChooser.kt b/ui/react/src/main/kotlin/space/kscience/visionforge/react/valueChooser.kt index 1296d777..03996c04 100644 --- a/ui/react/src/main/kotlin/space/kscience/visionforge/react/valueChooser.kt +++ b/ui/react/src/main/kotlin/space/kscience/visionforge/react/valueChooser.kt @@ -10,11 +10,11 @@ import kotlinx.html.js.onKeyDownFunction import org.w3c.dom.HTMLInputElement import org.w3c.dom.HTMLSelectElement import org.w3c.dom.events.Event -import react.FunctionComponent +import react.FC import react.Props import react.dom.attrs import react.dom.option -import react.functionComponent +import react.fc import react.useState import space.kscience.dataforge.meta.* import space.kscience.dataforge.meta.descriptors.MetaDescriptor @@ -36,136 +36,131 @@ public external interface ValueChooserProps : Props { } @JsExport -public val StringValueChooser: FunctionComponent = - functionComponent("StringValueChooser") { props -> - var value by useState(props.actual.string ?: "") - val keyDown: (Event) -> Unit = { event -> - if (event.type == "keydown" && event.asDynamic().key == "Enter") { - value = (event.target as HTMLInputElement).value - props.meta.value = value.asValue() - } +public val StringValueChooser: FC = fc("StringValueChooser") { props -> + var value by useState(props.actual.string ?: "") + val keyDown: (Event) -> Unit = { event -> + if (event.type == "keydown" && event.asDynamic().key == "Enter") { + value = (event.target as HTMLInputElement).value + props.meta.value = value.asValue() } - val handleChange: (Event) -> Unit = { - value = (it.target as HTMLInputElement).value + } + val handleChange: (Event) -> Unit = { + value = (it.target as HTMLInputElement).value + } + styledInput(type = InputType.text) { + css { + width = 100.pct } - styledInput(type = InputType.text) { - css { - width = 100.pct - } - attrs { - this.value = value - onKeyDownFunction = keyDown - onChangeFunction = handleChange + attrs { + this.value = value + onKeyDownFunction = keyDown + onChangeFunction = handleChange + } + } +} + +@JsExport +public val BooleanValueChooser: FC = fc("BooleanValueChooser") { props -> + val handleChange: (Event) -> Unit = { + val newValue = (it.target as HTMLInputElement).checked + props.meta.value = newValue.asValue() + } + styledInput(type = InputType.checkBox) { + css { + width = 100.pct + } + attrs { + //this.attributes["indeterminate"] = (props.item == null).toString() + checked = props.actual.boolean ?: false + onChangeFunction = handleChange + } + } +} + +@JsExport +public val NumberValueChooser: FC = fc("NumberValueChooser") { props -> + var innerValue by useState(props.actual.string ?: "") + val keyDown: (Event) -> Unit = { event -> + if (event.type == "keydown" && event.asDynamic().key == "Enter") { + innerValue = (event.target as HTMLInputElement).value + val number = innerValue.toDoubleOrNull() + if (number == null) { + console.error("The input value $innerValue is not a number") + } else { + props.meta.value = number.asValue() } } } - -@JsExport -public val BooleanValueChooser: FunctionComponent = - functionComponent("BooleanValueChooser") { props -> - val handleChange: (Event) -> Unit = { - val newValue = (it.target as HTMLInputElement).checked - props.meta.value = newValue.asValue() + val handleChange: (Event) -> Unit = { + innerValue = (it.target as HTMLInputElement).value + } + styledInput(type = InputType.number) { + css { + width = 100.pct } - styledInput(type = InputType.checkBox) { - css { - width = 100.pct + attrs { + value = innerValue + onKeyDownFunction = keyDown + onChangeFunction = handleChange + props.descriptor?.attributes?.get("step").string?.let { + step = it } - attrs { - //this.attributes["indeterminate"] = (props.item == null).toString() - checked = props.actual.boolean ?: false - onChangeFunction = handleChange + props.descriptor?.attributes?.get("min").string?.let { + min = it + } + props.descriptor?.attributes?.get("max").string?.let { + max = it } } } +} @JsExport -public val NumberValueChooser: FunctionComponent = - functionComponent("NumberValueChooser") { props -> - var innerValue by useState(props.actual.string ?: "") - val keyDown: (Event) -> Unit = { event -> - if (event.type == "keydown" && event.asDynamic().key == "Enter") { - innerValue = (event.target as HTMLInputElement).value - val number = innerValue.toDoubleOrNull() - if (number == null) { - console.error("The input value $innerValue is not a number") - } else { - props.meta.value = number.asValue() - } +public val ComboValueChooser: FC = fc("ComboValueChooser") { props -> + var selected by useState(props.actual.string ?: "") + val handleChange: (Event) -> Unit = { + selected = (it.target as HTMLSelectElement).value + props.meta.value = selected.asValue() + } + styledSelect { + css { + width = 100.pct + } + props.descriptor?.allowedValues?.forEach { + option { + +it.string } } - val handleChange: (Event) -> Unit = { - innerValue = (it.target as HTMLInputElement).value - } - styledInput(type = InputType.number) { - css { - width = 100.pct - } - attrs { - value = innerValue - onKeyDownFunction = keyDown - onChangeFunction = handleChange - props.descriptor?.attributes?.get("step").string?.let { - step = it - } - props.descriptor?.attributes?.get("min").string?.let { - min = it - } - props.descriptor?.attributes?.get("max").string?.let { - max = it - } - } + attrs { + this.value = props.actual.string ?: "" + multiple = false + onChangeFunction = handleChange } } +} @JsExport -public val ComboValueChooser: FunctionComponent = - functionComponent("ComboValueChooser") { props -> - var selected by useState(props.actual.string ?: "") - val handleChange: (Event) -> Unit = { - selected = (it.target as HTMLSelectElement).value - props.meta.value = selected.asValue() +public val ColorValueChooser: FC = fc("ColorValueChooser") { props -> + val handleChange: (Event) -> Unit = { + props.meta.value = (it.target as HTMLInputElement).value.asValue() + } + styledInput(type = InputType.color) { + css { + width = 100.pct + margin(0.px) } - styledSelect { - css { - width = 100.pct - } - props.descriptor?.allowedValues?.forEach { - option { - +it.string - } - } - attrs { - this.value = props.actual.string ?: "" - multiple = false - onChangeFunction = handleChange - } + attrs { + this.value = props.actual.value?.let { value -> + if (value.type == ValueType.NUMBER) Colors.rgbToString(value.int) + else value.string + } ?: "#000000" + onChangeFunction = handleChange } } +} @JsExport -public val ColorValueChooser: FunctionComponent = - functionComponent("ColorValueChooser") { props -> - val handleChange: (Event) -> Unit = { - props.meta.value = (it.target as HTMLInputElement).value.asValue() - } - styledInput(type = InputType.color) { - css { - width = 100.pct - margin(0.px) - } - attrs { - this.value = props.actual.value?.let { value -> - if (value.type == ValueType.NUMBER) Colors.rgbToString(value.int) - else value.string - } ?: "#000000" - onChangeFunction = handleChange - } - } - } - -@JsExport -public val ValueChooser: FunctionComponent = functionComponent("ValueChooser") { props -> +public val ValueChooser: FC = fc("ValueChooser") { props -> val rawInput by useState(false) val descriptor = props.descriptor diff --git a/visionforge-core/build.gradle.kts b/visionforge-core/build.gradle.kts index 3af5c602..b411dee9 100644 --- a/visionforge-core/build.gradle.kts +++ b/visionforge-core/build.gradle.kts @@ -5,7 +5,9 @@ plugins { val dataforgeVersion: String by rootProject.extra kscience{ - useSerialization() + useSerialization{ + json() + } } kotlin { diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooser.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooser.kt index d4ce7bb5..f62513b0 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooser.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooser.kt @@ -71,35 +71,31 @@ public interface ValueChooser { public companion object { - private fun findWidgetByType(context: Context, type: String): Factory? { - return when (Name.parse(type)) { - TextValueChooser.name -> TextValueChooser - ColorValueChooser.name -> ColorValueChooser - ComboBoxValueChooser.name -> ComboBoxValueChooser - else -> null//context.provideByType(type)//Search for additional factories in the plugin - } + private fun findWidgetByType(context: Context, type: String): Factory? = when (Name.parse(type)) { + TextValueChooser.name -> TextValueChooser + ColorValueChooser.name -> ColorValueChooser + ComboBoxValueChooser.name -> ComboBoxValueChooser + else -> null//context.provideByType(type)//Search for additional factories in the plugin } - private fun build(context: Context, descriptor: MetaDescriptor?): ValueChooser { - return if (descriptor == null) { - TextValueChooser(); - } else { - val widgetType = descriptor.widgetType - val chooser: ValueChooser = when { - widgetType != null -> { - findWidgetByType( - context, - widgetType - )?.invoke( - descriptor.widget - ) ?: TextValueChooser() - } - !descriptor.allowedValues.isNullOrEmpty() -> ComboBoxValueChooser() - else -> TextValueChooser() + private fun build(context: Context, descriptor: MetaDescriptor?): ValueChooser = if (descriptor == null) { + TextValueChooser(); + } else { + val widgetType = descriptor.widgetType + val chooser: ValueChooser = when { + widgetType != null -> { + findWidgetByType( + context, + widgetType + )?.invoke( + descriptor.widget + ) ?: TextValueChooser() } - chooser.descriptor = descriptor - chooser + !descriptor.allowedValues.isNullOrEmpty() -> ComboBoxValueChooser() + else -> TextValueChooser() } + chooser.descriptor = descriptor + chooser } public fun build( diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/geometry.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/geometry.kt index ccff7dcd..f815a262 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/geometry.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/geometry.kt @@ -42,6 +42,7 @@ public interface Point3D { } } +@Suppress("SERIALIZER_TYPE_INCOMPATIBLE") @Serializable(Point3DSerializer::class) public interface MutablePoint3D : Point3D { override var x: Float @@ -56,7 +57,6 @@ internal object Point3DSerializer : KSerializer { override val descriptor: SerialDescriptor = Point3DImpl.serializer().descriptor - override fun deserialize(decoder: Decoder): MutablePoint3D = decoder.decodeSerializableValue(Point3DImpl.serializer()) override fun serialize(encoder: Encoder, value: Point3D) {