From 1e183107cf9b8bc63a6ef7b02a1919a2d3ed8450 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 26 Dec 2020 17:48:18 +0300 Subject: [PATCH] Properly treat prototype styles in editor --- .../dataforge/vision/bootstrap/visionPropertyEditor.kt | 7 ++++++- .../hep/dataforge/vision/react/PropertyEditor.kt | 9 +++++---- .../kotlin/hep/dataforge/vision/react/valueChooser.kt | 10 +++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt index b9a30bc8..2d8b96f0 100644 --- a/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt +++ b/ui/bootstrap/src/main/kotlin/hep/dataforge/vision/bootstrap/visionPropertyEditor.kt @@ -4,6 +4,7 @@ import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.vision.* import hep.dataforge.vision.react.metaViewer import hep.dataforge.vision.react.propertyEditor + import hep.dataforge.vision.solid.SolidReference import org.w3c.dom.Element import react.RBuilder import react.dom.render @@ -22,7 +23,11 @@ public fun RBuilder.visionPropertyEditor( descriptor = descriptor, key = key) } - val styles = vision.styles + val styles = if (vision is SolidReference) { + (vision.styles + vision.prototype.styles).distinct() + } else { + vision.styles + } if (styles.isNotEmpty()) { card("Styles") { accordion("styles") { diff --git a/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt b/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt index c4eb03a0..3eb1eb97 100644 --- a/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt +++ b/ui/react/src/main/kotlin/hep/dataforge/vision/react/PropertyEditor.kt @@ -65,11 +65,12 @@ private val PropertyEditorItem: FunctionalComponent = private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { var expanded: Boolean by useState { true } - val itemName by useState { props.name ?: Name.EMPTY } + val itemName = useMemo( { props.name ?: Name.EMPTY }, arrayOf(props.name)) var item: MetaItem? by useState { props.provider.getItem(itemName) } - val descriptorItem: ItemDescriptor? = props.descriptor?.get(itemName) + val descriptorItem: ItemDescriptor? = + useMemo({ props.descriptor?.get(itemName) }, arrayOf(props.descriptor, itemName)) - if(descriptorItem?.hidden == true) return //fail fast for hidden property + if (descriptorItem?.hidden == true) return //fail fast for hidden property var actualItem: MetaItem? by useState { item ?: props.defaultProvider?.getItem(itemName) ?: descriptorItem?.defaultItem() @@ -79,7 +80,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { fun update() { item = props.provider.getItem(itemName) - actualItem = item ?: descriptorItem?.defaultItem() + actualItem = item ?: props.defaultProvider?.getItem(itemName) ?: descriptorItem?.defaultItem() } if (props.updateFlow != null) { diff --git a/ui/react/src/main/kotlin/hep/dataforge/vision/react/valueChooser.kt b/ui/react/src/main/kotlin/hep/dataforge/vision/react/valueChooser.kt index 884791b5..68638e25 100644 --- a/ui/react/src/main/kotlin/hep/dataforge/vision/react/valueChooser.kt +++ b/ui/react/src/main/kotlin/hep/dataforge/vision/react/valueChooser.kt @@ -20,17 +20,17 @@ import styled.styledInput import styled.styledSelect public external interface ValueChooserProps : RProps { - var item: MetaItem? - var descriptor: ValueDescriptor? - var valueChanged: ((Value?) -> Unit)? + public var item: MetaItem? + public var descriptor: ValueDescriptor? + public var valueChanged: ((Value?) -> Unit)? } public external interface ValueChooserState : RState { - var rawInput: Boolean? + public var rawInput: Boolean? } @JsExport -class ValueChooserComponent(props: ValueChooserProps) : RComponent(props) { +public class ValueChooserComponent(props: ValueChooserProps) : RComponent(props) { private val element = createRef() private fun getValue(): Value? {