Fix JS config editor for properties without defaults

This commit is contained in:
Alexander Nozik 2020-11-19 15:22:42 +03:00
parent cae3ab00d9
commit e01a688664
5 changed files with 109 additions and 97 deletions

View File

@ -24,7 +24,7 @@ fun Page<Solid>.demo(name: String, title: String = name, block: SolidGroup.() ->
} }
val canvasOptions = Canvas3DOptions { val canvasOptions = Canvas3DOptions {
minSize = 500 minSize = 600
axes { axes {
size = 500.0 size = 500.0
visible = true visible = true

View File

@ -66,7 +66,7 @@ class ThreeDemoGrid(element: Element, idPrefix: String = "") : Page<Solid> {
id = name.toString() id = name.toString()
role = "tabpanel" role = "tabpanel"
attributes["aria-labelledby"] = "tab[$name]" attributes["aria-labelledby"] = "tab[$name]"
div("container w-100 h-100") { id = "output-$name" }.also {element-> div("w-100 h-100") { id = "output-$name" }.also {element->
output = three.createCanvas(element, canvasOptions) output = three.createCanvas(element, canvasOptions)
} }
hr() hr()

View File

@ -37,7 +37,8 @@ public external interface ConfigEditorItemProps : RProps {
public var descriptor: NodeDescriptor? public var descriptor: NodeDescriptor?
} }
private val ConfigEditorItem: FunctionalComponent<ConfigEditorItemProps> = functionalComponent("ConfigEditorItem") { props -> private val ConfigEditorItem: FunctionalComponent<ConfigEditorItemProps> =
functionalComponent("ConfigEditorItem") { props ->
configEditorItem(props) configEditorItem(props)
} }
@ -82,8 +83,9 @@ private fun RBuilder.configEditorItem(props: ConfigEditorItemProps) {
update() update()
} }
when (actualItem) {
is MetaItem.NodeItem -> {
if (actualItem is MetaItem.NodeItem) {
styledDiv { styledDiv {
css { css {
+TreeStyles.treeLeaf +TreeStyles.treeLeaf
@ -141,8 +143,7 @@ private fun RBuilder.configEditorItem(props: ConfigEditorItemProps) {
} }
} }
} }
} } else {
is MetaItem.ValueItem -> {
styledDiv { styledDiv {
css { css {
+TreeStyles.treeLeaf +TreeStyles.treeLeaf
@ -188,7 +189,6 @@ private fun RBuilder.configEditorItem(props: ConfigEditorItemProps) {
} }
} }
} }
}
public external interface ConfigEditorProps : RProps { public external interface ConfigEditorProps : RProps {
public var id: Name public var id: Name
@ -210,7 +210,12 @@ public val ConfigEditor: FunctionalComponent<ConfigEditorProps> = functionalComp
} }
} }
public fun Element.configEditor(config: Config, descriptor: NodeDescriptor? = null, default: Meta? = null, key: Any? = null) { public fun Element.configEditor(
config: Config,
descriptor: NodeDescriptor? = null,
default: Meta? = null,
key: Any? = null,
) {
render(this) { render(this) {
child(ConfigEditor) { child(ConfigEditor) {
attrs { attrs {
@ -223,7 +228,12 @@ public fun Element.configEditor(config: Config, descriptor: NodeDescriptor? = nu
} }
} }
public fun RBuilder.configEditor(config: Config, descriptor: NodeDescriptor? = null, default: Meta? = null, key: Any? = null) { public fun RBuilder.configEditor(
config: Config,
descriptor: NodeDescriptor? = null,
default: Meta? = null,
key: Any? = null,
) {
child(ConfigEditor) { child(ConfigEditor) {
attrs { attrs {
this.key = key?.toString() ?: "" this.key = key?.toString() ?: ""

View File

@ -61,6 +61,8 @@ public val ThreeCanvasComponent: FunctionalComponent<ThreeCanvasProps> = functio
minWidth = 500.px minWidth = 500.px
minHeight = 500.px minHeight = 500.px
display = Display.inherit display = Display.inherit
width = 100.pct
height = 100.pct
flex(1.0, 1.0, FlexBasis.auto) flex(1.0, 1.0, FlexBasis.auto)
} }
ref = elementRef ref = elementRef

View File

@ -117,14 +117,14 @@ public class ThreePlugin : AbstractPlugin(), HtmlVisionBinding<Solid> {
} }
public fun createCanvas( public fun createCanvas(
element: HTMLElement, element: Element,
options: Canvas3DOptions = Canvas3DOptions.empty(), options: Canvas3DOptions = Canvas3DOptions.empty(),
): ThreeCanvas = ThreeCanvas(this, options).apply { ): ThreeCanvas = ThreeCanvas(this, options).apply {
attach(element) attach(element)
} }
override fun bind(element: Element, vision: Solid) { override fun bind(element: Element, vision: Solid) {
TODO("Not yet implemented") createCanvas(element).render(vision)
} }
public companion object : PluginFactory<ThreePlugin> { public companion object : PluginFactory<ThreePlugin> {