gnim 1.2.4 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dbus.d.ts CHANGED
@@ -7,8 +7,9 @@
7
7
  import Gio from "gi://Gio";
8
8
  import GLib from "gi://GLib";
9
9
  import GObject from "gi://GObject";
10
- import { type InferVariant } from "./variant.js";
11
10
  import { register } from "./gobject.js";
11
+ export declare const Variant: typeof GLib.Variant;
12
+ export type Variant<T extends string> = GLib.Variant<T>;
12
13
  declare const info: unique symbol;
13
14
  declare const internals: unique symbol;
14
15
  declare const remoteMethod: unique symbol;
@@ -62,10 +63,11 @@ type DBusType = string | {
62
63
  type: string;
63
64
  name: string;
64
65
  };
66
+ type DeepInfer<T extends string> = ReturnType<GLib.Variant<T>["deepUnpack"]>;
65
67
  type InferVariantTypes<T extends Array<DBusType>> = {
66
- [K in keyof T]: T[K] extends string ? InferVariant<T[K]> : T[K] extends {
68
+ [K in keyof T]: T[K] extends string ? DeepInfer<T[K]> : T[K] extends {
67
69
  type: infer S;
68
- } ? S extends string ? InferVariant<S> : never : unknown;
70
+ } ? S extends string ? DeepInfer<S> : never : unknown;
69
71
  };
70
72
  /**
71
73
  * Registers a method.
@@ -103,21 +105,21 @@ export declare function methodAsync<const InArgs extends Array<DBusType>>(...inA
103
105
  * not emit the notify signal.
104
106
  * ```
105
107
  */
106
- export declare function property<T extends string>(type: T): (_: void, ctx: ClassFieldDecoratorContext<Service, InferVariant<T>>) => (this: Service, init: InferVariant<T>) => InferVariant<T>;
108
+ export declare function property<T extends string>(type: T): (_: void, ctx: ClassFieldDecoratorContext<Service, DeepInfer<T>>) => (this: Service, init: DeepInfer<T>) => DeepInfer<T>;
107
109
  /**
108
110
  * Registers a read-only property. Can be used in conjuction with {@link setter} to define
109
111
  * read-write properties as accessors.
110
112
  *
111
113
  * Note that you will need to explicitly emit the notify signal.
112
114
  */
113
- export declare function getter<T extends string>(type: T): (getter: (this: Service) => InferVariant<T>, ctx: ClassGetterDecoratorContext<Service, InferVariant<T>>) => (this: Service) => InferVariant<T>;
115
+ export declare function getter<T extends string>(type: T): (getter: (this: Service) => DeepInfer<T>, ctx: ClassGetterDecoratorContext<Service, DeepInfer<T>>) => (this: Service) => DeepInfer<T>;
114
116
  /**
115
117
  * Registers a write-only property. Can be used in conjuction with {@link getter} to define
116
118
  * read-write properties as accessors.
117
119
  *
118
120
  * Note that you will need to explicitly emit the notify signal.
119
121
  */
120
- export declare function setter<T extends string>(type: T): (setter: (this: Service, value: InferVariant<T>) => void, ctx: ClassSetterDecoratorContext<Service, InferVariant<T>>) => (this: Service, value: InferVariant<T>) => void;
122
+ export declare function setter<T extends string>(type: T): (setter: (this: Service, value: DeepInfer<T>) => void, ctx: ClassSetterDecoratorContext<Service, DeepInfer<T>>) => (this: Service, value: DeepInfer<T>) => void;
121
123
  /**
122
124
  * Registers a signal which when invoked will emit the signal
123
125
  * on the local object and the exported object.
@@ -125,15 +127,4 @@ export declare function setter<T extends string>(type: T): (setter: (this: Servi
125
127
  * **Note**: its not possible to emit signals on remote objects through proxies.
126
128
  */
127
129
  export declare function signal<const Params extends Array<DBusType>>(...params: Params): (method: (this: Service, ...params: InferVariantTypes<Params>) => void, ctx: ClassMethodDecoratorContext<Service, typeof method>) => typeof method;
128
- declare class GLibVariant<T extends string = any> extends GLib.Variant<T> {
129
- static new<T extends string>(signature: T, value: InferVariant<T>): GLib.Variant<T>;
130
- constructor(signature: T, value: InferVariant<T>);
131
- deepUnpack<V = InferVariant<T>>(): V;
132
- deep_unpack<V = InferVariant<T>>(): V;
133
- }
134
- export declare namespace Variant {
135
- type Infer<S extends string> = InferVariant<S>;
136
- }
137
- export declare const Variant: typeof GLibVariant;
138
- export type Variant<T extends string = any> = GLibVariant<T>;
139
130
  export {};
package/dist/dbus.js CHANGED
@@ -22,6 +22,7 @@ import GObject from "gi://GObject";
22
22
  import { definePropertyGetter, kebabify, xml } from "./util.js";
23
23
  import { register, property as gproperty, signal as gsignal, getter as ggetter, setter as gsetter, } from "./gobject.js";
24
24
  const DEFAULT_TIMEOUT = 10000;
25
+ export const Variant = GLib.Variant;
25
26
  const info = Symbol("dbus interface info");
26
27
  const internals = Symbol("dbus interface internals");
27
28
  const remoteMethod = Symbol("proxy remoteMethod");
@@ -549,28 +550,3 @@ export function signal(...params) {
549
550
  };
550
551
  };
551
552
  }
552
- // HACK: how do I augment it globally?
553
- class GLibVariant extends GLib.Variant {
554
- static new(signature, value) {
555
- return GLib.Variant.new(signature, value);
556
- }
557
- constructor(signature, value) {
558
- super(signature, value);
559
- }
560
- deepUnpack() {
561
- return super.deepUnpack();
562
- }
563
- deep_unpack() {
564
- return super.deepUnpack();
565
- }
566
- }
567
- export const Variant = GLib.Variant;
568
- // FIXME: should be augmented globally
569
- // declare module "gi://GLib?version=2.0" {
570
- // export namespace GLib {
571
- // export interface Variant<T extends string = string> {
572
- // deepUnpack<V = InferVariantType<T>>(): V
573
- // deep_unpack<V = InferVariantType<T>>(): V
574
- // }
575
- // }
576
- // }
Binary file
package/dist/gobject.d.ts CHANGED
@@ -22,6 +22,20 @@ export type ParamFlags = GObject.ParamFlags;
22
22
  export declare const ParamFlags: typeof GObject.ParamFlags;
23
23
  export type GType<T = unknown> = GObject.GType<T>;
24
24
  type GObj = GObject.Object;
25
+ type Context = {
26
+ private: false;
27
+ static: false;
28
+ name: string;
29
+ };
30
+ type PropertyContext<T> = ClassFieldDecoratorContext<GObj, T> & Context;
31
+ type GetterContext<T> = ClassGetterDecoratorContext<GObj, T> & Context;
32
+ type SetterContext<T> = ClassSetterDecoratorContext<GObj, T> & Context;
33
+ type SignalContext<T extends () => any> = ClassMethodDecoratorContext<GObj, T> & Context;
34
+ type SignalOptions = {
35
+ default?: boolean;
36
+ flags?: SignalFlags;
37
+ accumulator?: AccumulatorType;
38
+ };
25
39
  type PropertyTypeDeclaration<T> = ((name: string, flags: ParamFlags) => ParamSpec<T>) | ParamSpec<T> | {
26
40
  $gtype: GType<T>;
27
41
  };
@@ -35,7 +49,7 @@ type PropertyTypeDeclaration<T> = ((name: string, flags: ParamFlags) => ParamSpe
35
49
  * }
36
50
  * ```
37
51
  */
38
- export declare function property<T>(typeDeclaration: PropertyTypeDeclaration<T>): (_: void, ctx: ClassFieldDecoratorContext<GObj, T>, options?: {
52
+ export declare function property<T>(typeDeclaration: PropertyTypeDeclaration<T>): (_: void, ctx: PropertyContext<T>, options?: {
39
53
  metaOnly: true;
40
54
  }) => (this: GObj, init: T) => T;
41
55
  /**
@@ -57,7 +71,7 @@ export declare function property<T>(typeDeclaration: PropertyTypeDeclaration<T>)
57
71
  * }
58
72
  * ```
59
73
  */
60
- export declare function getter<T>(typeDeclaration: PropertyTypeDeclaration<T>): (getter: (this: GObj) => T, ctx: ClassGetterDecoratorContext<GObj, T>) => (this: GObj) => T;
74
+ export declare function getter<T>(typeDeclaration: PropertyTypeDeclaration<T>): (getter: (this: GObj) => T, ctx: GetterContext<T>) => (this: GObj) => T;
61
75
  /**
62
76
  * Defines a write-only property to be registered when using the {@link register} decorator.
63
77
  * If the setter has a getter pair decorated with the {@link getter} decorator the property will be writeable *and* readable.
@@ -77,7 +91,7 @@ export declare function getter<T>(typeDeclaration: PropertyTypeDeclaration<T>):
77
91
  * }
78
92
  * ```
79
93
  */
80
- export declare function setter<T>(typeDeclaration: PropertyTypeDeclaration<T>): (setter: (this: GObj, value: T) => void, ctx: ClassSetterDecoratorContext<GObj, T>) => (this: GObj, value: T) => void;
94
+ export declare function setter<T>(typeDeclaration: PropertyTypeDeclaration<T>): (setter: (this: GObj, value: T) => void, ctx: SetterContext<T>) => (this: GObj, value: T) => void;
81
95
  type ParamType<P> = P extends {
82
96
  $gtype: GType<infer T>;
83
97
  } ? T : P extends GType<infer T> ? T : never;
@@ -104,10 +118,7 @@ export declare function signal<const Params extends Array<{
104
118
  $gtype: GType;
105
119
  } | GType>, Return extends {
106
120
  $gtype: GType;
107
- } | GType>(params: Params, returnType?: Return, options?: {
108
- flags?: SignalFlags;
109
- accumulator?: AccumulatorType;
110
- }): (method: (this: GObj, ...args: ParamTypes<Params>) => ParamType<Return>, ctx: ClassMethodDecoratorContext<GObj, typeof method>) => typeof method;
121
+ } | GType>(params: Params, returnType?: Return, options?: SignalOptions): (method: (this: GObj, ...args: ParamTypes<Params>) => ParamType<Return>, ctx: SignalContext<typeof method>) => typeof method;
111
122
  /**
112
123
  * Defines a signal to be registered when using the {@link register} decorator.
113
124
  *
@@ -123,7 +134,7 @@ export declare function signal<const Params extends Array<{
123
134
  */
124
135
  export declare function signal<Params extends Array<{
125
136
  $gtype: GType;
126
- } | GType>>(...params: Params): (method: (this: GObject.Object, ...args: ParamTypes<Params>) => void, ctx: ClassMethodDecoratorContext<GObj, typeof method>) => typeof method;
137
+ } | GType>>(...params: Params): (method: (this: GObject.Object, ...args: ParamTypes<Params>) => void, ctx: SignalContext<typeof method>) => typeof method;
127
138
  type MetaInfo = GObject.MetaInfo<never, Array<{
128
139
  $gtype: GType<unknown>;
129
140
  }>, never>;
@@ -147,6 +158,16 @@ export declare function register<Cls extends {
147
158
  /**
148
159
  * @experimental
149
160
  * Asserts a gtype in cases where the type is too loose/strict.
161
+ *
162
+ * Example:
163
+ * ```ts
164
+ * type Tuple = [number, number]
165
+ * const Tuple = gtype<Tuple>(Array)
166
+ *
167
+ * class {
168
+ * \@property(Tuple) value = [1, 2] as Tuple
169
+ * }
170
+ * ```
150
171
  */
151
172
  export declare function gtype<Assert>(type: GType<any> | {
152
173
  $gtype: GType<any>;
package/dist/gobject.js CHANGED
@@ -157,6 +157,7 @@ export function signal(...args) {
157
157
  const [params, returnType, options] = args;
158
158
  signals[signalName] = {
159
159
  method,
160
+ default: options?.default ?? true,
160
161
  param_types: params.map((i) => ("$gtype" in i ? i.$gtype : i)),
161
162
  ...(returnType && {
162
163
  return_type: "$gtype" in returnType ? returnType.$gtype : returnType,
@@ -202,7 +203,7 @@ function pspecFromGType(type, name, flags) {
202
203
  return ParamSpec.int64(name, "", "", flags, MININT64, MAXINT64, 0);
203
204
  case GObject.TYPE_UINT64:
204
205
  return ParamSpec.uint64(name, "", "", flags, 0, Number.MAX_SAFE_INTEGER, 0);
205
- case GObject.type_from_name("gfloat"):
206
+ case GObject.TYPE_FLOAT:
206
207
  return ParamSpec.float(name, "", "", flags, MINFLOAT, MAXFLOAT, 0);
207
208
  case GObject.TYPE_DOUBLE:
208
209
  return ParamSpec.double(name, "", "", flags, Number.MIN_VALUE, Number.MIN_VALUE, 0);
@@ -271,20 +272,34 @@ export function register(options = {}) {
271
272
  const spec = pspec(key, flags, type);
272
273
  return [key, spec];
273
274
  }));
274
- const signals = fromEntries(entries(meta.signals ?? {}).map(([signalName, { method, ...signal }]) => {
275
- defineProperty(cls.prototype, `on_${signalName.replaceAll("-", "_")}`, {
276
- enumerable: false,
277
- configurable: false,
278
- value: method,
279
- });
275
+ const signals = fromEntries(entries(meta.signals ?? {}).map(([signalName, { default: def, method, ...signal }]) => {
276
+ if (def) {
277
+ defineProperty(cls.prototype, `on_${signalName.replaceAll("-", "_")}`, {
278
+ enumerable: false,
279
+ configurable: false,
280
+ value: method,
281
+ });
282
+ }
280
283
  return [signalName, signal];
281
284
  }));
285
+ delete meta.properties;
286
+ delete meta.signals;
282
287
  registerClass({ ...options, Properties: props, Signals: signals }, cls);
283
288
  };
284
289
  }
285
290
  /**
286
291
  * @experimental
287
292
  * Asserts a gtype in cases where the type is too loose/strict.
293
+ *
294
+ * Example:
295
+ * ```ts
296
+ * type Tuple = [number, number]
297
+ * const Tuple = gtype<Tuple>(Array)
298
+ *
299
+ * class {
300
+ * \@property(Tuple) value = [1, 2] as Tuple
301
+ * }
302
+ * ```
288
303
  */
289
304
  export function gtype(type) {
290
305
  return "$gtype" in type ? type : { $gtype: type };
package/dist/jsx/For.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Fragment } from "./Fragment.js";
2
2
  import { createState } from "./state.js";
3
3
  import { env } from "./env.js";
4
- import { onCleanup, Scope } from "./scope.js";
4
+ import { getScope, onCleanup, Scope } from "./scope.js";
5
5
  // TODO: support Gio.ListModel
6
6
  export function For({ each, children: mkChild, cleanup, id = (item) => item, }) {
7
+ const currentScope = getScope();
7
8
  const map = new Map();
8
9
  const fragment = new Fragment();
9
10
  function remove({ item, child, index: [index], scope }) {
@@ -44,17 +45,17 @@ export function For({ each, children: mkChild, cleanup, id = (item) => item, })
44
45
  }
45
46
  else {
46
47
  const [index, setIndex] = createState(i);
47
- const scope = new Scope(Scope.current);
48
+ const scope = new Scope(currentScope);
48
49
  const child = scope.run(() => mkChild(item, index));
49
50
  map.set(key, { item, child, index: [index, setIndex], scope });
50
51
  fragment.addChild(child);
51
52
  }
52
53
  });
53
54
  }
54
- callback(each.get());
55
55
  const dispose = each.subscribe(() => {
56
56
  callback(each.get());
57
57
  });
58
+ callback(each.get());
58
59
  onCleanup(() => {
59
60
  dispose();
60
61
  for (const value of map.values()) {
package/dist/jsx/With.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Fragment } from "./Fragment.js";
2
2
  import { env } from "./env.js";
3
- import { onCleanup, Scope } from "./scope.js";
3
+ import { getScope, onCleanup, Scope } from "./scope.js";
4
4
  export function With({ value, children: mkChild, cleanup, }) {
5
+ const currentScope = getScope();
5
6
  const fragment = new Fragment();
6
7
  let scope;
7
8
  function callback(v) {
@@ -16,7 +17,7 @@ export function With({ value, children: mkChild, cleanup, }) {
16
17
  if (scope)
17
18
  scope.dispose();
18
19
  }
19
- scope = new Scope(Scope.current);
20
+ scope = new Scope(currentScope);
20
21
  const ch = scope.run(() => mkChild(v));
21
22
  if (ch !== "" && ch !== false && ch !== null && ch !== undefined) {
22
23
  fragment.addChild(ch);
package/dist/jsx/jsx.d.ts CHANGED
@@ -3,7 +3,10 @@ import { Fragment } from "./Fragment.js";
3
3
  import { Accessor } from "./state.js";
4
4
  import { CC, FC } from "./env.js";
5
5
  import { Pascalify } from "../util.js";
6
- type Node = Array<GObject.Object> | GObject.Object | number | string | boolean | null | undefined;
6
+ /**
7
+ * Represents all of the things that can be passed as a child to class components.
8
+ */
9
+ export type Node = Array<GObject.Object> | GObject.Object | number | string | boolean | null | undefined;
7
10
  export declare const gtkType: unique symbol;
8
11
  /**
9
12
  * Get the type of the object specified through the `$type` property
@@ -1,7 +1,7 @@
1
1
  import GObject from "gi://GObject";
2
2
  import Gio from "gi://Gio";
3
+ import GLib from "gi://GLib";
3
4
  import { type Pascalify } from "../util.js";
4
- import { type InferVariantRec, type InferVariant } from "../variant.js";
5
5
  type SubscribeCallback = () => void;
6
6
  type DisposeFunction = () => void;
7
7
  type SubscribeFunction = (callback: SubscribeCallback) => DisposeFunction;
@@ -82,7 +82,7 @@ export declare function createBinding<T extends GObject.Object, P extends keyof
82
82
  * @param key The settings key
83
83
  */
84
84
  export declare function createBinding<T>(settings: Gio.Settings, key: string): Accessor<T>;
85
- type ConnectionHandler<O extends GObject.Object, S extends keyof O["$signals"], Return> = O["$signals"][S] extends (...args: any[]) => infer R ? void extends R ? (...args: Parameters<O["$signals"][S]>) => Return : never : never;
85
+ type ConnectionHandler<O extends GObject.Object, S extends keyof O["$signals"], T> = O["$signals"][S] extends (...args: any[]) => infer R ? void extends R ? (...args: [...Parameters<O["$signals"][S]>, currentValue: T]) => T : never : never;
86
86
  /**
87
87
  * Create an `Accessor` which sets up a list of `GObject.Object` signal connections.
88
88
  *
@@ -116,11 +116,13 @@ export declare function createConnection<T, O1 extends GObject.Object, S1 extend
116
116
  * @param producer The producer function which should return a cleanup function
117
117
  */
118
118
  export declare function createExternal<T>(init: T, producer: (set: Setter<T>) => DisposeFunction): Accessor<T>;
119
+ type DeepInfer<T extends string> = ReturnType<GLib.Variant<T>["deepUnpack"]>;
120
+ type RecursiveInfer<T extends string> = ReturnType<GLib.Variant<T>["recursiveUnpack"]>;
119
121
  /** @experimental */
120
122
  type Settings<T extends Record<string, string>> = {
121
- [K in keyof T as Uncapitalize<Pascalify<K>>]: Accessor<InferVariantRec<T[K]>>;
123
+ [K in keyof T as Uncapitalize<Pascalify<K>>]: Accessor<RecursiveInfer<T[K]>>;
122
124
  } & {
123
- [K in keyof T as `set${Pascalify<K>}`]: Setter<InferVariant<T[K]>>;
125
+ [K in keyof T as `set${Pascalify<K>}`]: Setter<DeepInfer<T[K]>>;
124
126
  };
125
127
  /**
126
128
  * @experimental
package/dist/jsx/state.js CHANGED
@@ -29,6 +29,7 @@ export class Accessor extends Function {
29
29
  * @returns Unsubscribe function.
30
30
  */
31
31
  subscribe(callback) {
32
+ // TODO: auto unsub when a scope is available?
32
33
  return __classPrivateFieldGet(this, _Accessor_subscribe, "f").call(this, callback);
33
34
  }
34
35
  /**
@@ -176,7 +177,7 @@ export function createConnection(init, h1, h2, h3, h4, h5, h6, h7, h8, h9) {
176
177
  if (subscribers.size === 0) {
177
178
  dispose = signals.map(([object, signal, callback]) => {
178
179
  const id = GObject.Object.prototype.connect.call(object, signal, (_, ...args) => {
179
- const newValue = callback(...args);
180
+ const newValue = callback(...args, value);
180
181
  if (value !== newValue) {
181
182
  value = newValue;
182
183
  subscribers.forEach((cb) => cb());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gnim",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "type": "module",
5
5
  "author": "Aylur",
6
6
  "license": "MIT",