summaryrefslogtreecommitdiff
path: root/lang/gjs/src/gtk3/jsx-runtime.ts
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-11-24 00:04:07 +0000
committerAylur <[email protected]>2024-12-02 22:34:01 +0100
commit2f09ed83386b334f0dfb7f376b99739b15e49fc9 (patch)
tree4be7848780c4145310a5fa69c60661a61c69ca47 /lang/gjs/src/gtk3/jsx-runtime.ts
parent990f031507b21f8a18c0710016fb76b1f260afe8 (diff)
gjs gtk4 support
export jsx-runtime
Diffstat (limited to 'lang/gjs/src/gtk3/jsx-runtime.ts')
-rw-r--r--lang/gjs/src/gtk3/jsx-runtime.ts31
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 9da4bb6..f37c695 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 = {