diff options
Diffstat (limited to 'gjs/src')
-rw-r--r-- | gjs/src/application.ts | 2 | ||||
-rw-r--r-- | gjs/src/astalify.ts | 27 | ||||
-rw-r--r-- | gjs/src/imports.ts | 1 | ||||
-rw-r--r-- | gjs/src/jsx/jsx-runtime.ts | 7 |
4 files changed, 24 insertions, 13 deletions
diff --git a/gjs/src/application.ts b/gjs/src/application.ts index 42bbb72..b42492f 100644 --- a/gjs/src/application.ts +++ b/gjs/src/application.ts @@ -1,7 +1,7 @@ import { Astal, GObject, Gio } from "./imports.js" type RequestHandler = { - (request: string, res: (response: string) => void): void + (request: string, res: (response: any) => void): void } type Config = Partial<{ diff --git a/gjs/src/astalify.ts b/gjs/src/astalify.ts index 3a613a5..4b4145c 100644 --- a/gjs/src/astalify.ts +++ b/gjs/src/astalify.ts @@ -1,5 +1,6 @@ import Binding, { kebabify, type Connectable, type Subscribable } from "./binding.js" import { Astal, Gtk } from "./imports.js" +import { execAsync } from "./process.js" export type Widget<C extends { new(...args: any): Gtk.Widget }> = InstanceType<C> & { className: string @@ -97,8 +98,15 @@ function ctor(self: any, config: any, ...children: Gtk.Widget[]) { self.add(child) } - for (const [signal, callback] of onHandlers) - self.connect(signal, callback) + for (const [signal, callback] of onHandlers) { + if (typeof callback === "function") { + self.connect(signal, callback) + } + else { + self.connect(signal, () => execAsync(callback) + .then(print).catch(console.error)) + } + } if (self instanceof Gtk.Container) { if (pchildren) { @@ -172,14 +180,19 @@ type BindableProps<T> = { [K in keyof T]: Binding<NonNullable<T[K]>> | T[K]; } +type SigHandler< + W extends { new(...args: any): Gtk.Widget }, + Args extends Array<unknown>, +> = ((self: Widget<W>, ...args: Args) => unknown) | string | string[] + export type ConstructProps< Self extends { new(...args: any[]): any }, Props = unknown, - Signals extends Record<string, Array<unknown>> = Record<string, []> -> = { - [Key in `on${string}`]: (self: Widget<Self>) => unknown -} & Partial<{ - [sig in keyof Signals]: (self: Widget<Self>, ...args: Signals[sig]) => unknown + Signals extends Record<`on${string}`, Array<unknown>> = Record<`on${string}`, any[]> +> = Partial<{ + [S in keyof Signals]: SigHandler<Self, Signals[S]> +}> & Partial<{ + [Key in `on${string}`]: SigHandler<Self, any[]> }> & BindableProps<Props & { className?: string css?: string diff --git a/gjs/src/imports.ts b/gjs/src/imports.ts index c6724c1..cbed004 100644 --- a/gjs/src/imports.ts +++ b/gjs/src/imports.ts @@ -6,4 +6,5 @@ export { default as Astal } from "gi://Astal?version=0.1" export { default as GObject } from "gi://GObject?version=2.0" export { default as Gio } from "gi://Gio?version=2.0" export { default as Gtk } from "gi://Gtk?version=3.0" +export { default as Gdk } from "gi://Gdk?version=3.0" export { default as GLib } from "gi://GLib?version=2.0" diff --git a/gjs/src/jsx/jsx-runtime.ts b/gjs/src/jsx/jsx-runtime.ts index 3d9cc49..7a90dc5 100644 --- a/gjs/src/jsx/jsx-runtime.ts +++ b/gjs/src/jsx/jsx-runtime.ts @@ -17,6 +17,8 @@ export function jsx( if (!Array.isArray(children)) children = [children] + else + children = children.flat() if (ctor === "centerbox") { if (children[0]) @@ -27,11 +29,6 @@ export function jsx( props.endWidget = w(children[2]) } - 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 |