diff options
author | Aylur <[email protected]> | 2024-12-25 02:38:27 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-12-25 02:38:27 +0100 |
commit | 37f0d24178a1516eb45eb639640e07c5dc3b8e81 (patch) | |
tree | 28ff8d1030be1919c00152e99b4ab9c229b0f01b /lang/gjs/src/gtk3/jsx-runtime.ts | |
parent | 553b2186db47fb34602d4e949c1e40a018238d7a (diff) | |
parent | 0f2fefd2053203e1bfe4d66eb4e37dea07369890 (diff) |
Merge pull request #196 from Aylur/feat/jsx-gtk4
Add jsx support for gtk4
Diffstat (limited to 'lang/gjs/src/gtk3/jsx-runtime.ts')
-rw-r--r-- | lang/gjs/src/gtk3/jsx-runtime.ts | 31 |
1 files changed, 4 insertions, 27 deletions
diff --git a/lang/gjs/src/gtk3/jsx-runtime.ts b/lang/gjs/src/gtk3/jsx-runtime.ts index f2fe9a4..ee720af 100644 --- a/lang/gjs/src/gtk3/jsx-runtime.ts +++ b/lang/gjs/src/gtk3/jsx-runtime.ts @@ -1,11 +1,8 @@ import Gtk from "gi://Gtk?version=3.0" -import { mergeBindings, type BindableChild } from "./astalify.js" +import { type BindableChild } from "./astalify.js" +import { mergeBindings, jsx as _jsx } from "../_astal.js" import * as Widget from "./widget.js" -function isArrowFunction(func: any): func is (args: any) => any { - return !Object.hasOwn(func, "prototype") -} - export function Fragment({ children = [], child }: { child?: BindableChild children?: Array<BindableChild> @@ -16,29 +13,9 @@ export function Fragment({ children = [], child }: { export function jsx( ctor: keyof typeof ctors | typeof Gtk.Widget, - { children, ...props }: any, + props: any, ) { - children ??= [] - - if (!Array.isArray(children)) - children = [children] - - children = children.filter(Boolean) - - if (children.length === 1) - props.child = children[0] - else if (children.length > 1) - props.children = children - - if (typeof ctor === "string") { - return new ctors[ctor](props) - } - - if (isArrowFunction(ctor)) - return ctor(props) - - // @ts-expect-error can be class or function - return new ctor(props) + return _jsx(ctors, ctor as any, props) } const ctors = { |