New properties #34

Merged
altavir merged 19 commits from new-properties into dev 2020-12-29 13:35:01 +03:00
3 changed files with 16 additions and 10 deletions
Showing only changes of commit 1e183107cf - Show all commits

View File

@ -4,6 +4,7 @@ import hep.dataforge.meta.descriptors.NodeDescriptor
import hep.dataforge.vision.* import hep.dataforge.vision.*
import hep.dataforge.vision.react.metaViewer import hep.dataforge.vision.react.metaViewer
import hep.dataforge.vision.react.propertyEditor import hep.dataforge.vision.react.propertyEditor
import hep.dataforge.vision.solid.SolidReference
import org.w3c.dom.Element import org.w3c.dom.Element
import react.RBuilder import react.RBuilder
import react.dom.render import react.dom.render
@ -22,7 +23,11 @@ public fun RBuilder.visionPropertyEditor(
descriptor = descriptor, descriptor = descriptor,
key = key) key = key)
} }
val styles = vision.styles val styles = if (vision is SolidReference) {
(vision.styles + vision.prototype.styles).distinct()
} else {
vision.styles
}
if (styles.isNotEmpty()) { if (styles.isNotEmpty()) {
card("Styles") { card("Styles") {
accordion("styles") { accordion("styles") {

View File

@ -65,11 +65,12 @@ private val PropertyEditorItem: FunctionalComponent<PropertyEditorProps> =
private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) { private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
var expanded: Boolean by useState { true } 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) } 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 { var actualItem: MetaItem? by useState {
item ?: props.defaultProvider?.getItem(itemName) ?: descriptorItem?.defaultItem() item ?: props.defaultProvider?.getItem(itemName) ?: descriptorItem?.defaultItem()
@ -79,7 +80,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
fun update() { fun update() {
item = props.provider.getItem(itemName) item = props.provider.getItem(itemName)
actualItem = item ?: descriptorItem?.defaultItem() actualItem = item ?: props.defaultProvider?.getItem(itemName) ?: descriptorItem?.defaultItem()
} }
if (props.updateFlow != null) { if (props.updateFlow != null) {

View File

@ -20,17 +20,17 @@ import styled.styledInput
import styled.styledSelect import styled.styledSelect
public external interface ValueChooserProps : RProps { public external interface ValueChooserProps : RProps {
var item: MetaItem? public var item: MetaItem?
var descriptor: ValueDescriptor? public var descriptor: ValueDescriptor?
var valueChanged: ((Value?) -> Unit)? public var valueChanged: ((Value?) -> Unit)?
} }
public external interface ValueChooserState : RState { public external interface ValueChooserState : RState {
var rawInput: Boolean? public var rawInput: Boolean?
} }
@JsExport @JsExport
class ValueChooserComponent(props: ValueChooserProps) : RComponent<ValueChooserProps, ValueChooserState>(props) { public class ValueChooserComponent(props: ValueChooserProps) : RComponent<ValueChooserProps, ValueChooserState>(props) {
private val element = createRef<HTMLElement>() private val element = createRef<HTMLElement>()
private fun getValue(): Value? { private fun getValue(): Value? {