diff options
Diffstat (limited to 'gjs/src/jsx/jsx-runtime.ts')
-rw-r--r-- | gjs/src/jsx/jsx-runtime.ts | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/gjs/src/jsx/jsx-runtime.ts b/gjs/src/jsx/jsx-runtime.ts index 9495da9..3d9cc49 100644 --- a/gjs/src/jsx/jsx-runtime.ts +++ b/gjs/src/jsx/jsx-runtime.ts @@ -1,5 +1,13 @@ import { Gtk } from "../imports.js" import * as Widget from "../widgets.js" +import Binding from "../binding.js" + +function w(e: any) { + if (e instanceof Gtk.Widget || e instanceof Binding) + return e + + return Widget.Label({ label: String(e) }) +} export function jsx( ctor: keyof typeof ctors | typeof Gtk.Widget, @@ -10,30 +18,27 @@ export function jsx( if (!Array.isArray(children)) children = [children] - if (children.length === 1) { - props.child = children[0] - delete props.children - } - - children = children.map((v: any) => { - if (v instanceof Gtk.Widget) - return v - - return Widget.Label({ label: String(v) }) - }) - - if (ctor === Widget.CenterBox) { + if (ctor === "centerbox") { if (children[0]) - props.startWidget = children[0] + props.startWidget = w(children[0]) if (children[1]) - props.centerWidget = children[1] + props.centerWidget = w(children[1]) if (children[2]) - props.endWidget = children[2] + props.endWidget = w(children[2]) } - if (ctor === Widget.Label) { - if (children[0]) - props.label = children[0] + else if (ctor === "label" && children[0]) { + props.label = children[0] + delete props.children + } + + else if (children.length === 1) { + props.child = w(children[0]) + delete props.children + } + + else { + props.children = children.map(w) } return typeof ctor === "string" |