v0.2.0-dev-22 #47
@ -17,11 +17,12 @@ public fun RBuilder.visionPropertyEditor(
|
|||||||
|
|
||||||
card("Properties") {
|
card("Properties") {
|
||||||
propertyEditor(
|
propertyEditor(
|
||||||
provider = vision.ownProperties,
|
ownProperties = vision.ownProperties,
|
||||||
defaultProvider = vision.allProperties(),
|
allProperties = vision.allProperties(),
|
||||||
updateFlow = vision.propertyChanges,
|
updateFlow = vision.propertyChanges,
|
||||||
descriptor = descriptor,
|
descriptor = descriptor,
|
||||||
key = key)
|
key = key
|
||||||
|
)
|
||||||
}
|
}
|
||||||
val styles = if (vision is SolidReference) {
|
val styles = if (vision is SolidReference) {
|
||||||
(vision.styles + vision.prototype.styles).distinct()
|
(vision.styles + vision.prototype.styles).distinct()
|
||||||
|
@ -29,17 +29,17 @@ public external interface PropertyEditorProps : RProps {
|
|||||||
/**
|
/**
|
||||||
* Root config object - always non null
|
* Root config object - always non null
|
||||||
*/
|
*/
|
||||||
public var provider: MutableItemProvider
|
public var ownProperties: MutableItemProvider
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide default item (greyed out if used)
|
* Provide default item (greyed out if used)
|
||||||
*/
|
*/
|
||||||
public var defaultProvider: ItemProvider?
|
public var allProperties: ItemProvider?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full path to the displayed node in [provider]. Could be empty
|
* Full path to the displayed node in [ownProperties]. Could be empty
|
||||||
*/
|
*/
|
||||||
public var name: Name?
|
public var name: Name
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Root descriptor
|
* Root descriptor
|
||||||
@ -65,27 +65,21 @@ 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 = props.name ?: Name.EMPTY
|
val descriptorItem: ItemDescriptor? = props.descriptor?.get(props.name)
|
||||||
val descriptorItem: ItemDescriptor? =
|
|
||||||
useMemo({ props.descriptor?.get(itemName) }, arrayOf(props.descriptor, itemName))
|
|
||||||
|
|
||||||
var item: MetaItem? by useState { props.provider.getItem(itemName) }
|
|
||||||
|
|
||||||
if (descriptorItem?.hidden == true) return //fail fast for hidden property
|
if (descriptorItem?.hidden == true) return //fail fast for hidden property
|
||||||
|
var ownProperty: MetaItem? by useState { props.ownProperties.getItem(props.name) }
|
||||||
|
val actualItem: MetaItem? = props.allProperties?.getItem(props.name)
|
||||||
|
|
||||||
var actualItem: MetaItem? by useState {
|
println("Actual item for ${props.name?.toString()} is ${actualItem.toString()}")
|
||||||
item ?: props.defaultProvider?.getItem(itemName) ?: descriptorItem?.defaultItem()
|
|
||||||
}
|
|
||||||
|
|
||||||
val token = itemName.lastOrNull()?.toString() ?: "Properties"
|
val token = props.name.lastOrNull()?.toString() ?: "Properties"
|
||||||
|
|
||||||
fun update() {
|
fun update() {
|
||||||
item = props.provider.getItem(itemName)
|
ownProperty = props.ownProperties.getItem(props.name)
|
||||||
actualItem = item ?: props.defaultProvider?.getItem(itemName) ?: descriptorItem?.defaultItem()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.updateFlow != null) {
|
if (props.updateFlow != null) {
|
||||||
useEffectWithCleanup(listOf(props.provider, props.updateFlow)) {
|
useEffectWithCleanup(listOf(props.ownProperties, props.updateFlow)) {
|
||||||
val updateJob = props.updateFlow!!.onEach { updatedName ->
|
val updateJob = props.updateFlow!!.onEach { updatedName ->
|
||||||
if (updatedName == props.name) {
|
if (updatedName == props.name) {
|
||||||
update()
|
update()
|
||||||
@ -101,15 +95,15 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
|
|||||||
|
|
||||||
val valueChanged: (Value?) -> Unit = {
|
val valueChanged: (Value?) -> Unit = {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
props.provider.remove(itemName)
|
props.ownProperties.remove(props.name)
|
||||||
} else {
|
} else {
|
||||||
props.provider[itemName] = it
|
props.ownProperties[props.name] = it
|
||||||
}
|
}
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
val removeClick: (Event) -> Unit = {
|
val removeClick: (Event) -> Unit = {
|
||||||
props.provider.remove(itemName)
|
props.ownProperties.remove(props.name)
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +126,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
|
|||||||
styledSpan {
|
styledSpan {
|
||||||
css {
|
css {
|
||||||
+TreeStyles.treeLabel
|
+TreeStyles.treeLabel
|
||||||
if (item == null) {
|
if (ownProperty == null) {
|
||||||
+TreeStyles.treeLabelInactive
|
+TreeStyles.treeLabelInactive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +142,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
|
|||||||
(descriptorItem as? NodeDescriptor)?.items?.keys?.forEach {
|
(descriptorItem as? NodeDescriptor)?.items?.keys?.forEach {
|
||||||
add(NameToken(it))
|
add(NameToken(it))
|
||||||
}
|
}
|
||||||
item?.node?.items?.keys?.let { addAll(it) }
|
ownProperty?.node?.items?.keys?.let { addAll(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
keys.filter { !it.body.startsWith("@") }.forEach { token ->
|
keys.filter { !it.body.startsWith("@") }.forEach { token ->
|
||||||
@ -159,8 +153,9 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
|
|||||||
child(PropertyEditorItem) {
|
child(PropertyEditorItem) {
|
||||||
attrs {
|
attrs {
|
||||||
this.key = props.name.toString()
|
this.key = props.name.toString()
|
||||||
this.provider = props.provider
|
this.ownProperties = props.ownProperties
|
||||||
this.name = itemName + token
|
this.allProperties = props.allProperties
|
||||||
|
this.name = props.name + token
|
||||||
this.descriptor = props.descriptor
|
this.descriptor = props.descriptor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,7 +175,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
|
|||||||
}
|
}
|
||||||
styledSpan {
|
styledSpan {
|
||||||
css {
|
css {
|
||||||
if (item == null) {
|
if (ownProperty == null) {
|
||||||
+TreeStyles.treeLabelInactive
|
+TreeStyles.treeLabelInactive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,7 +187,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
|
|||||||
+TreeStyles.resizeableInput
|
+TreeStyles.resizeableInput
|
||||||
}
|
}
|
||||||
valueChooser(
|
valueChooser(
|
||||||
itemName,
|
props.name,
|
||||||
actualItem,
|
actualItem,
|
||||||
descriptorItem as? ValueDescriptor,
|
descriptorItem as? ValueDescriptor,
|
||||||
valueChanged
|
valueChanged
|
||||||
@ -204,7 +199,7 @@ private fun RBuilder.propertyEditorItem(props: PropertyEditorProps) {
|
|||||||
}
|
}
|
||||||
+"\u00D7"
|
+"\u00D7"
|
||||||
attrs {
|
attrs {
|
||||||
if (item == null) {
|
if (ownProperty == null) {
|
||||||
disabled = true
|
disabled = true
|
||||||
} else {
|
} else {
|
||||||
onClickFunction = removeClick
|
onClickFunction = removeClick
|
||||||
@ -222,8 +217,8 @@ public val PropertyEditor: FunctionalComponent<PropertyEditorProps> = functional
|
|||||||
child(PropertyEditorItem) {
|
child(PropertyEditorItem) {
|
||||||
attrs {
|
attrs {
|
||||||
this.key = ""
|
this.key = ""
|
||||||
this.provider = props.provider
|
this.ownProperties = props.ownProperties
|
||||||
this.defaultProvider = props.defaultProvider
|
this.allProperties = props.allProperties
|
||||||
this.name = Name.EMPTY
|
this.name = Name.EMPTY
|
||||||
this.descriptor = props.descriptor
|
this.descriptor = props.descriptor
|
||||||
this.scope = props.scope
|
this.scope = props.scope
|
||||||
@ -232,8 +227,8 @@ public val PropertyEditor: FunctionalComponent<PropertyEditorProps> = functional
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun RBuilder.propertyEditor(
|
public fun RBuilder.propertyEditor(
|
||||||
provider: MutableItemProvider,
|
ownProperties: MutableItemProvider,
|
||||||
defaultProvider: ItemProvider?,
|
allProperties: ItemProvider?,
|
||||||
updateFlow: Flow<Name>? = null,
|
updateFlow: Flow<Name>? = null,
|
||||||
descriptor: NodeDescriptor? = null,
|
descriptor: NodeDescriptor? = null,
|
||||||
scope: CoroutineScope? = null,
|
scope: CoroutineScope? = null,
|
||||||
@ -241,8 +236,8 @@ public fun RBuilder.propertyEditor(
|
|||||||
) {
|
) {
|
||||||
child(PropertyEditor) {
|
child(PropertyEditor) {
|
||||||
attrs {
|
attrs {
|
||||||
this.provider = provider
|
this.ownProperties = ownProperties
|
||||||
this.defaultProvider = defaultProvider
|
this.allProperties = allProperties
|
||||||
this.updateFlow = updateFlow
|
this.updateFlow = updateFlow
|
||||||
this.descriptor = descriptor
|
this.descriptor = descriptor
|
||||||
this.key = key?.toString() ?: ""
|
this.key = key?.toString() ?: ""
|
||||||
|
@ -134,8 +134,8 @@ public fun Vision.allProperties(
|
|||||||
): MutableItemProvider = object : MutableItemProvider {
|
): MutableItemProvider = object : MutableItemProvider {
|
||||||
override fun getItem(name: Name): MetaItem? = getProperty(
|
override fun getItem(name: Name): MetaItem? = getProperty(
|
||||||
name,
|
name,
|
||||||
inherit = inherit ?: (descriptor?.get(name)?.inherited != false),
|
inherit = inherit ?: (descriptor?.get(name)?.inherited == true),
|
||||||
includeStyles = includeStyles ?: (descriptor?.get(name)?.usesStyles == true),
|
includeStyles = includeStyles ?: (descriptor?.get(name)?.usesStyles != false),
|
||||||
includeDefaults = includeDefaults
|
includeDefaults = includeDefaults
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user