From e7accbd7bda1f470e2bfccfb3383813f443f63e2 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Wed, 15 Jan 2025 18:17:27 -0500 Subject: [PATCH] feat(ags4): write own ConstructProps to exclude props --- modules/ags/gtk4/widget/astalify/astalify.ts | 1 + modules/ags/gtk4/widget/astalify/generics.ts | 26 +++++++++++++++++++ modules/ags/gtk4/widget/astalify/index.ts | 7 ++++- modules/ags/gtk4/widget/subclasses/box.ts | 4 +-- modules/ags/gtk4/widget/subclasses/button.ts | 4 +-- .../ags/gtk4/widget/subclasses/calendar.ts | 4 +-- .../ags/gtk4/widget/subclasses/centerbox.ts | 4 +-- modules/ags/gtk4/widget/subclasses/entry.ts | 4 +-- modules/ags/gtk4/widget/subclasses/image.ts | 4 +-- modules/ags/gtk4/widget/subclasses/label.ts | 4 +-- .../ags/gtk4/widget/subclasses/levelbar.ts | 4 +-- .../ags/gtk4/widget/subclasses/menubutton.ts | 4 +-- modules/ags/gtk4/widget/subclasses/overlay.ts | 4 +-- modules/ags/gtk4/widget/subclasses/popover.ts | 4 +-- .../ags/gtk4/widget/subclasses/revealer.ts | 4 +-- modules/ags/gtk4/widget/subclasses/slider.ts | 4 +-- modules/ags/gtk4/widget/subclasses/stack.ts | 4 +-- modules/ags/gtk4/widget/subclasses/switch.ts | 4 +-- modules/ags/gtk4/widget/subclasses/window.ts | 4 +-- 19 files changed, 65 insertions(+), 33 deletions(-) diff --git a/modules/ags/gtk4/widget/astalify/astalify.ts b/modules/ags/gtk4/widget/astalify/astalify.ts index 2f6b54d2..5375c286 100644 --- a/modules/ags/gtk4/widget/astalify/astalify.ts +++ b/modules/ags/gtk4/widget/astalify/astalify.ts @@ -108,6 +108,7 @@ export default < this.setChildren(this, children); } + private _cursorName: Cursor = 'default'; @property(String) diff --git a/modules/ags/gtk4/widget/astalify/generics.ts b/modules/ags/gtk4/widget/astalify/generics.ts index ad27a871..272c7fc4 100644 --- a/modules/ags/gtk4/widget/astalify/generics.ts +++ b/modules/ags/gtk4/widget/astalify/generics.ts @@ -1,6 +1,8 @@ import { Gtk } from 'astal/gtk4'; import { Binding } from 'astal/binding'; +import { EventController } from './controller'; + // A mixin class must have a constructor with a single rest parameter of type 'any[]' // eslint-disable-next-line "@typescript-eslint/no-explicit-any" export type MixinParams = any[]; @@ -28,6 +30,30 @@ export interface AstalifyProps { cursorName: Cursor } +type SigHandler< + W extends InstanceType, + Args extends unknown[], +> = ((self: W, ...args: Args) => unknown) | string | string[]; + +export type ConstructProps< + Self extends InstanceType, + Props extends Gtk.Widget.ConstructorProps, + Signals extends Record<`on${string}`, unknown[]> = Record<`on${string}`, unknown[]>, +> = Partial<{ + // @ts-expect-error can't assign to unknown, but it works as expected though + [S in keyof Signals]: SigHandler +}> & Partial>> & Partial>> & { + noImplicitDestroy?: true + type?: string + cssName?: string +} & EventController & { + onDestroy?: (self: Self) => unknown + setup?: (self: Self) => void +}; + export type Cursor = | 'default' | 'help' diff --git a/modules/ags/gtk4/widget/astalify/index.ts b/modules/ags/gtk4/widget/astalify/index.ts index 80986ad2..ad46465d 100644 --- a/modules/ags/gtk4/widget/astalify/index.ts +++ b/modules/ags/gtk4/widget/astalify/index.ts @@ -2,4 +2,9 @@ import astalify from './astalify'; export default astalify; -export { type AstalifyProps, type BindableProps, childType } from './generics'; +export { + type AstalifyProps, + type BindableProps, + type ConstructProps, + childType, +} from './generics'; diff --git a/modules/ags/gtk4/widget/subclasses/box.ts b/modules/ags/gtk4/widget/subclasses/box.ts index 2ba6eae8..4f3f41d1 100644 --- a/modules/ags/gtk4/widget/subclasses/box.ts +++ b/modules/ags/gtk4/widget/subclasses/box.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Astal, type ConstructProps, Gtk } from 'astal/gtk4'; +import { Astal, Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type BoxProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/button.ts b/modules/ags/gtk4/widget/subclasses/button.ts index d932596b..a9c1203c 100644 --- a/modules/ags/gtk4/widget/subclasses/button.ts +++ b/modules/ags/gtk4/widget/subclasses/button.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; type ButtonSignals = Record<`on${string}`, unknown[]> & { diff --git a/modules/ags/gtk4/widget/subclasses/calendar.ts b/modules/ags/gtk4/widget/subclasses/calendar.ts index c7a86e93..8888d9fd 100644 --- a/modules/ags/gtk4/widget/subclasses/calendar.ts +++ b/modules/ags/gtk4/widget/subclasses/calendar.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; type CalendarSignals = Record<`on${string}`, unknown[]> & { diff --git a/modules/ags/gtk4/widget/subclasses/centerbox.ts b/modules/ags/gtk4/widget/subclasses/centerbox.ts index b7de42f5..78fa55ef 100644 --- a/modules/ags/gtk4/widget/subclasses/centerbox.ts +++ b/modules/ags/gtk4/widget/subclasses/centerbox.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type CenterBoxProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/entry.ts b/modules/ags/gtk4/widget/subclasses/entry.ts index 14362955..ed02c663 100644 --- a/modules/ags/gtk4/widget/subclasses/entry.ts +++ b/modules/ags/gtk4/widget/subclasses/entry.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; type EntrySignals = Record<`on${string}`, unknown[]> & { diff --git a/modules/ags/gtk4/widget/subclasses/image.ts b/modules/ags/gtk4/widget/subclasses/image.ts index c58a9322..c614ffc3 100644 --- a/modules/ags/gtk4/widget/subclasses/image.ts +++ b/modules/ags/gtk4/widget/subclasses/image.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type ImageProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/label.ts b/modules/ags/gtk4/widget/subclasses/label.ts index e5691fee..4dd1cd76 100644 --- a/modules/ags/gtk4/widget/subclasses/label.ts +++ b/modules/ags/gtk4/widget/subclasses/label.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type LabelProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/levelbar.ts b/modules/ags/gtk4/widget/subclasses/levelbar.ts index 39dca036..e51894a9 100644 --- a/modules/ags/gtk4/widget/subclasses/levelbar.ts +++ b/modules/ags/gtk4/widget/subclasses/levelbar.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type LevelBarProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/menubutton.ts b/modules/ags/gtk4/widget/subclasses/menubutton.ts index bfb0283a..3e2c0900 100644 --- a/modules/ags/gtk4/widget/subclasses/menubutton.ts +++ b/modules/ags/gtk4/widget/subclasses/menubutton.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type MenuButtonProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/overlay.ts b/modules/ags/gtk4/widget/subclasses/overlay.ts index a53e9ad2..f4541c0d 100644 --- a/modules/ags/gtk4/widget/subclasses/overlay.ts +++ b/modules/ags/gtk4/widget/subclasses/overlay.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { childType, type AstalifyProps } from '../astalify'; +import astalify, { childType, type AstalifyProps, type ConstructProps } from '../astalify'; export type OverlayProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/popover.ts b/modules/ags/gtk4/widget/subclasses/popover.ts index 67fc7748..a47c5d37 100644 --- a/modules/ags/gtk4/widget/subclasses/popover.ts +++ b/modules/ags/gtk4/widget/subclasses/popover.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type PopoverProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/revealer.ts b/modules/ags/gtk4/widget/subclasses/revealer.ts index b1f5a54d..77b241fd 100644 --- a/modules/ags/gtk4/widget/subclasses/revealer.ts +++ b/modules/ags/gtk4/widget/subclasses/revealer.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type RevealerProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/slider.ts b/modules/ags/gtk4/widget/subclasses/slider.ts index e99bb084..4f327f72 100644 --- a/modules/ags/gtk4/widget/subclasses/slider.ts +++ b/modules/ags/gtk4/widget/subclasses/slider.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Astal, type ConstructProps } from 'astal/gtk4'; +import { Astal } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; type SliderSignals = Record<`on${string}`, unknown[]> & { diff --git a/modules/ags/gtk4/widget/subclasses/stack.ts b/modules/ags/gtk4/widget/subclasses/stack.ts index 9638f7f8..c10ff3e5 100644 --- a/modules/ags/gtk4/widget/subclasses/stack.ts +++ b/modules/ags/gtk4/widget/subclasses/stack.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type StackProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/switch.ts b/modules/ags/gtk4/widget/subclasses/switch.ts index a9b96707..9c075a18 100644 --- a/modules/ags/gtk4/widget/subclasses/switch.ts +++ b/modules/ags/gtk4/widget/subclasses/switch.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Gtk, type ConstructProps } from 'astal/gtk4'; +import { Gtk } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type SwitchProps = ConstructProps< diff --git a/modules/ags/gtk4/widget/subclasses/window.ts b/modules/ags/gtk4/widget/subclasses/window.ts index 4df0da6d..e5e7e5a6 100644 --- a/modules/ags/gtk4/widget/subclasses/window.ts +++ b/modules/ags/gtk4/widget/subclasses/window.ts @@ -1,7 +1,7 @@ import { register } from 'astal'; -import { Astal, type ConstructProps } from 'astal/gtk4'; +import { Astal } from 'astal/gtk4'; -import astalify, { type AstalifyProps } from '../astalify'; +import astalify, { type AstalifyProps, type ConstructProps } from '../astalify'; export type WindowProps = ConstructProps<