@gtkx/react 1.0.0-rc.3 → 1.0.0-rc.4
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/README.md +4 -5
- package/dist/adw/config.d.ts +1 -0
- package/dist/adw/config.d.ts.map +1 -1
- package/dist/adw/config.js +1 -0
- package/dist/adw/config.js.map +1 -1
- package/dist/adw/dialog.d.ts +1 -0
- package/dist/adw/dialog.d.ts.map +1 -1
- package/dist/adw/dialog.js +1 -0
- package/dist/adw/dialog.js.map +1 -1
- package/dist/adw/element-behaviors.js +2 -3
- package/dist/adw/element-behaviors.js.map +1 -1
- package/dist/adw/element-config.d.ts +4 -3
- package/dist/adw/element-config.d.ts.map +1 -1
- package/dist/adw/element-config.js +14 -13
- package/dist/adw/element-config.js.map +1 -1
- package/dist/adw/index.d.ts +1 -0
- package/dist/adw/index.d.ts.map +1 -1
- package/dist/adw/index.js +1 -0
- package/dist/adw/index.js.map +1 -1
- package/dist/adw/prop-types.d.ts +1 -1
- package/dist/adw/prop-types.d.ts.map +1 -1
- package/dist/adw/prop-types.js.map +1 -1
- package/dist/bootstrap.js +1 -1
- package/dist/bootstrap.js.map +1 -1
- package/dist/components/application.d.ts +1 -0
- package/dist/components/application.d.ts.map +1 -1
- package/dist/components/application.js +1 -0
- package/dist/components/application.js.map +1 -1
- package/dist/components/element.d.ts +0 -1
- package/dist/components/element.d.ts.map +1 -1
- package/dist/components/element.js +0 -1
- package/dist/components/element.js.map +1 -1
- package/dist/components/window.d.ts +1 -0
- package/dist/components/window.d.ts.map +1 -1
- package/dist/components/window.js +1 -0
- package/dist/components/window.js.map +1 -1
- package/dist/config.d.ts +5 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/element-behaviors.js +0 -1
- package/dist/element-behaviors.js.map +1 -1
- package/dist/element-config.d.ts +4 -3
- package/dist/element-config.d.ts.map +1 -1
- package/dist/element-config.js +12 -11
- package/dist/element-config.js.map +1 -1
- package/dist/hooks/use-bind-setting.d.ts +8 -7
- package/dist/hooks/use-bind-setting.d.ts.map +1 -1
- package/dist/hooks/use-bind-setting.js +2 -7
- package/dist/hooks/use-bind-setting.js.map +1 -1
- package/dist/hooks/use-parent-window.d.ts +3 -1
- package/dist/hooks/use-parent-window.d.ts.map +1 -1
- package/dist/hooks/use-parent-window.js +3 -1
- package/dist/hooks/use-parent-window.js.map +1 -1
- package/dist/hooks/use-property.d.ts +2 -2
- package/dist/hooks/use-property.d.ts.map +1 -1
- package/dist/hooks/use-property.js +1 -2
- package/dist/hooks/use-property.js.map +1 -1
- package/dist/hooks/use-setting.d.ts +2 -3
- package/dist/hooks/use-setting.d.ts.map +1 -1
- package/dist/hooks/use-setting.js +2 -3
- package/dist/hooks/use-setting.js.map +1 -1
- package/dist/hooks/use-signal.d.ts +13 -7
- package/dist/hooks/use-signal.d.ts.map +1 -1
- package/dist/hooks/use-signal.js +6 -8
- package/dist/hooks/use-signal.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -3
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +2 -3
- package/dist/internal.js.map +1 -1
- package/dist/prop-types.d.ts +60 -0
- package/dist/prop-types.d.ts.map +1 -1
- package/dist/prop-types.js.map +1 -1
- package/dist/reconciler/behaviors.d.ts +0 -15
- package/dist/reconciler/behaviors.d.ts.map +1 -1
- package/dist/reconciler/behaviors.js +5 -20
- package/dist/reconciler/behaviors.js.map +1 -1
- package/dist/reconciler/host-config.d.ts +1 -1
- package/dist/reconciler/host-config.d.ts.map +1 -1
- package/dist/reconciler/host-config.js.map +1 -1
- package/dist/reconciler/instance.js +1 -1
- package/dist/reconciler/instance.js.map +1 -1
- package/dist/reconciler/metadata.d.ts +1 -1
- package/dist/reconciler/metadata.d.ts.map +1 -1
- package/dist/reconciler/metadata.js +7 -7
- package/dist/reconciler/metadata.js.map +1 -1
- package/dist/reconciler/node.d.ts +2 -2
- package/dist/reconciler/node.d.ts.map +1 -1
- package/dist/reconciler/node.js +1 -1
- package/dist/reconciler/node.js.map +1 -1
- package/dist/reconciler/placement.js +6 -6
- package/dist/reconciler/placement.js.map +1 -1
- package/dist/reconciler/registry.d.ts +42 -30
- package/dist/reconciler/registry.d.ts.map +1 -1
- package/dist/reconciler/registry.js +10 -19
- package/dist/reconciler/registry.js.map +1 -1
- package/dist/reconciler/root-element.d.ts +0 -1
- package/dist/reconciler/root-element.d.ts.map +1 -1
- package/dist/reconciler/root-element.js +0 -1
- package/dist/reconciler/root-element.js.map +1 -1
- package/dist/reconciler/root.d.ts +6 -20
- package/dist/reconciler/root.d.ts.map +1 -1
- package/dist/reconciler/root.js +4 -19
- package/dist/reconciler/root.js.map +1 -1
- package/dist/reconciler/signals.js +2 -2
- package/dist/reconciler/signals.js.map +1 -1
- package/dist/reconciler/text.js +5 -5
- package/dist/reconciler/text.js.map +1 -1
- package/dist/utils/accessible-metadata.d.ts +0 -7
- package/dist/utils/accessible-metadata.d.ts.map +1 -1
- package/dist/utils/accessible-metadata.js +0 -7
- package/dist/utils/accessible-metadata.js.map +1 -1
- package/dist/utils/accessible-props.d.ts +49 -1
- package/dist/utils/accessible-props.d.ts.map +1 -1
- package/dist/utils/accessible-props.js.map +1 -1
- package/dist/utils/ref-prop.d.ts +0 -6
- package/dist/utils/ref-prop.d.ts.map +1 -1
- package/dist/utils/ref-prop.js +0 -6
- package/dist/utils/ref-prop.js.map +1 -1
- package/dist/utils/settings.d.ts +6 -0
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/settings.js.map +1 -1
- package/env.d.ts +11 -4
- package/package.json +5 -5
- package/src/adw/config.ts +1 -0
- package/src/adw/dialog.tsx +1 -0
- package/src/adw/element-behaviors.ts +2 -3
- package/src/adw/element-config.ts +14 -13
- package/src/adw/index.ts +1 -0
- package/src/adw/prop-types.ts +1 -1
- package/src/bootstrap.ts +1 -1
- package/src/components/application.tsx +1 -0
- package/src/components/element.tsx +0 -1
- package/src/components/window.tsx +1 -0
- package/src/config.ts +5 -9
- package/src/element-behaviors.ts +0 -1
- package/src/element-config.ts +12 -11
- package/src/hooks/use-bind-setting.ts +8 -7
- package/src/hooks/use-parent-window.ts +3 -1
- package/src/hooks/use-property.ts +2 -2
- package/src/hooks/use-setting.ts +2 -3
- package/src/hooks/use-signal.ts +16 -10
- package/src/index.ts +10 -2
- package/src/internal.ts +4 -3
- package/src/prop-types.ts +86 -5
- package/src/reconciler/behaviors.ts +6 -21
- package/src/reconciler/host-config.ts +1 -1
- package/src/reconciler/instance.ts +1 -1
- package/src/reconciler/metadata.ts +8 -8
- package/src/reconciler/node.ts +3 -3
- package/src/reconciler/placement.ts +6 -6
- package/src/reconciler/registry.ts +52 -37
- package/src/reconciler/root-element.ts +0 -1
- package/src/reconciler/root.ts +6 -20
- package/src/reconciler/signals.ts +2 -2
- package/src/reconciler/text.ts +6 -6
- package/src/utils/accessible-metadata.ts +0 -7
- package/src/utils/accessible-props.ts +49 -1
- package/src/utils/ref-prop.ts +0 -6
- package/src/utils/settings.ts +6 -0
|
@@ -6,22 +6,23 @@ import type { SettingsSchema, SettingsSchemaKeys } from "../utils/settings.js";
|
|
|
6
6
|
import { type RefProp, resolveRefProp } from "../utils/ref-prop.js";
|
|
7
7
|
import { useSettings } from "./use-setting.js";
|
|
8
8
|
|
|
9
|
+
/** Options for {@link useBindSetting}. */
|
|
9
10
|
type UseBindSettingOptions<K extends SettingsSchemaKeys> = {
|
|
11
|
+
/** Schema the settings object is opened from. */
|
|
10
12
|
schema: SettingsSchema<K>;
|
|
13
|
+
/** Key of that schema to bind. */
|
|
11
14
|
key: keyof K & string;
|
|
15
|
+
/** Object holding the property, given directly or as a ref; nothing is bound while it is absent. */
|
|
12
16
|
object: RefProp<GObject.Object>;
|
|
17
|
+
/** camelCase name of the property to keep in sync with the key. */
|
|
13
18
|
property: string;
|
|
19
|
+
/** Direction and conversion behavior of the bind; defaults to `Gio.SettingsBindFlags.DEFAULT`. */
|
|
14
20
|
flags?: Gio.SettingsBindFlags;
|
|
15
21
|
};
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
|
-
* Binds a GSettings key to a property of a GObject, keeping the two in sync
|
|
19
|
-
*
|
|
20
|
-
* @param options.schema The schema reference identifying the settings backend.
|
|
21
|
-
* @param options.key The key within the schema to bind.
|
|
22
|
-
* @param options.object The GObject whose property is bound to the setting.
|
|
23
|
-
* @param options.property The name of the object property to bind.
|
|
24
|
-
* @param options.flags Flags controlling the binding's direction and behaviour.
|
|
24
|
+
* Binds a GSettings key to a property of a GObject, keeping the two in sync until the component unmounts.
|
|
25
|
+
* `property` is given in camelCase, and `flags` defaults to `Gio.SettingsBindFlags.DEFAULT`, a two-way bind.
|
|
25
26
|
*/
|
|
26
27
|
function useBindSetting<K extends SettingsSchemaKeys>({
|
|
27
28
|
schema,
|
|
@@ -4,7 +4,9 @@ import { type Context, createContext, use } from "react";
|
|
|
4
4
|
const ParentWindowContext: Context<Gtk.Window | null> = createContext<Gtk.Window | null>(null);
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Returns the `Gtk.Window`
|
|
7
|
+
* Returns the `Gtk.Window` of the nearest window ancestor. This is `null` on the first render even inside a
|
|
8
|
+
* window, because a window provides itself only once its GObject exists, and stays `null` outside one. The
|
|
9
|
+
* component re-renders when it resolves, so derive from the value rather than reading it once.
|
|
8
10
|
*/
|
|
9
11
|
const useParentWindow = (): Gtk.Window | null => use(ParentWindowContext);
|
|
10
12
|
|
|
@@ -4,14 +4,14 @@ import type { RefProp } from "../utils/ref-prop.js";
|
|
|
4
4
|
import { useObjectValue } from "./use-object-value.js";
|
|
5
5
|
|
|
6
6
|
type Properties<T extends GObject.Object> = NonNullable<T["__properties__"]>;
|
|
7
|
+
/** Every property `T` declares that is also readable off the instance, in camelCase. */
|
|
7
8
|
type PropertyName<T extends GObject.Object> = keyof Properties<T> & keyof T;
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Subscribes to a GObject property and returns its current value, re-rendering when the property changes.
|
|
11
12
|
*
|
|
12
|
-
* @param object The GObject (or ref to one) whose property to observe.
|
|
13
13
|
* @param propertyName The camelCase name of a readable property on the object.
|
|
14
|
-
* @returns The current
|
|
14
|
+
* @returns The current value, or `undefined` while the object is null or an unresolved ref.
|
|
15
15
|
*/
|
|
16
16
|
function useProperty<T extends GObject.Object, P extends PropertyName<T>>(
|
|
17
17
|
object: RefProp<T>,
|
package/src/hooks/use-setting.ts
CHANGED
|
@@ -16,9 +16,8 @@ const useSettings = <K extends SettingsSchemaKeys>({ id, path }: UseSettingsProp
|
|
|
16
16
|
/**
|
|
17
17
|
* Reads and writes a single key of a GSettings schema, re-rendering when the stored value changes.
|
|
18
18
|
*
|
|
19
|
-
* @
|
|
20
|
-
* @
|
|
21
|
-
* @returns A tuple of the current value and a setter that persists a new value.
|
|
19
|
+
* @returns The current value, and a setter that writes a new one back to GSettings.
|
|
20
|
+
* @throws When the key is not declared in the schema.
|
|
22
21
|
*/
|
|
23
22
|
function useSetting<K extends SettingsSchemaKeys, P extends keyof K>(
|
|
24
23
|
schema: SettingsSchema<K>,
|
package/src/hooks/use-signal.ts
CHANGED
|
@@ -4,8 +4,13 @@ import { useEffectEvent, useLayoutEffect } from "react";
|
|
|
4
4
|
import { type RefProp, resolveRefProp } from "../utils/ref-prop.js";
|
|
5
5
|
|
|
6
6
|
type Signals<T extends GObject.Object> = NonNullable<T["__signals__"]>;
|
|
7
|
+
/** Every signal name `T` declares, on its own or narrowed by a `::detail` suffix. */
|
|
7
8
|
type SignalName<T extends GObject.Object> = keyof Signals<T> | `${keyof Signals<T> & string}::${string}`;
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* The handler signature `T` declares for signal `S`, looked up through any `::detail` suffix and
|
|
12
|
+
* falling back to an untyped `SignalHandler` when the object declares no such signal.
|
|
13
|
+
*/
|
|
9
14
|
type TypedSignalHandler<T extends GObject.Object, S extends string> = S extends keyof Signals<T>
|
|
10
15
|
? Signals<T>[S]
|
|
11
16
|
: S extends `${infer TBase}::${string}`
|
|
@@ -14,9 +19,12 @@ type TypedSignalHandler<T extends GObject.Object, S extends string> = S extends
|
|
|
14
19
|
: SignalHandler
|
|
15
20
|
: SignalHandler;
|
|
16
21
|
|
|
22
|
+
/** Options for {@link useSignal}. */
|
|
17
23
|
type UseSignalOptions = {
|
|
18
|
-
after
|
|
19
|
-
|
|
24
|
+
/** Runs the handler after the object's own default handler rather than before it. */
|
|
25
|
+
isAfter?: boolean;
|
|
26
|
+
/** Invokes the handler once, with no arguments, as soon as the signal is connected. */
|
|
27
|
+
isImmediate?: boolean;
|
|
20
28
|
};
|
|
21
29
|
|
|
22
30
|
/**
|
|
@@ -29,16 +37,14 @@ type UseSignalOptions = {
|
|
|
29
37
|
* runs the handler captured on the first render. Keep the calling component unwrapped, or read the values the
|
|
30
38
|
* handler needs off the GObject itself. React fixes this on the 19.3 line.
|
|
31
39
|
*
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param handler The callback invoked when the signal is emitted.
|
|
35
|
-
* @param options Connection options such as running after the default handler or invoking immediately.
|
|
40
|
+
* @param signal The signal name, optionally with a `::detail` suffix.
|
|
41
|
+
* @param options `isAfter` runs the handler after the default handler; `isImmediate` also invokes it on connect.
|
|
36
42
|
*/
|
|
37
43
|
function useSignal<T extends GObject.Object, S extends SignalName<T> & string>(
|
|
38
44
|
object: RefProp<T>,
|
|
39
45
|
signal: S,
|
|
40
46
|
handler: TypedSignalHandler<T, S>,
|
|
41
|
-
{
|
|
47
|
+
{ isAfter = false, isImmediate = false }: UseSignalOptions = {},
|
|
42
48
|
): void {
|
|
43
49
|
const emit = useEffectEvent(handler as SignalHandler);
|
|
44
50
|
|
|
@@ -49,16 +55,16 @@ function useSignal<T extends GObject.Object, S extends SignalName<T> & string>(
|
|
|
49
55
|
return;
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
resolved.on(signal, emit,
|
|
58
|
+
resolved.on(signal, emit, isAfter);
|
|
53
59
|
|
|
54
|
-
if (
|
|
60
|
+
if (isImmediate) {
|
|
55
61
|
emit();
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
return () => {
|
|
59
65
|
resolved.off(signal, emit);
|
|
60
66
|
};
|
|
61
|
-
}, [object, signal,
|
|
67
|
+
}, [object, signal, isAfter, isImmediate]);
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
export { useSignal, type SignalName, type TypedSignalHandler };
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import "./bootstrap.js";
|
|
2
2
|
|
|
3
|
+
/** @public */
|
|
3
4
|
export { useApplication } from "./hooks/use-application.js";
|
|
5
|
+
/** @public */
|
|
4
6
|
export { useBindSetting } from "./hooks/use-bind-setting.js";
|
|
7
|
+
/** @public */
|
|
5
8
|
export { useParentWindow } from "./hooks/use-parent-window.js";
|
|
9
|
+
/** @public */
|
|
6
10
|
export { useProperty } from "./hooks/use-property.js";
|
|
11
|
+
/** @public */
|
|
7
12
|
export { useSetting } from "./hooks/use-setting.js";
|
|
13
|
+
/** @public */
|
|
8
14
|
export { useSignal } from "./hooks/use-signal.js";
|
|
9
|
-
|
|
15
|
+
/** @public */
|
|
10
16
|
export { type RootElement, rootElement } from "./reconciler/root-element.js";
|
|
17
|
+
/** @public */
|
|
11
18
|
export { createPortal, createRoot, quit, type Root } from "./reconciler/root.js";
|
|
19
|
+
/** @public */
|
|
12
20
|
export type { AccessibleProps } from "./utils/accessible-props.js";
|
|
21
|
+
/** @public */
|
|
13
22
|
export type { RefProp } from "./utils/ref-prop.js";
|
|
14
|
-
export type { SettingsSchema, SettingsSchemaKeys, SettingValue } from "./utils/settings.js";
|
package/src/internal.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import "./bootstrap.js";
|
|
2
2
|
|
|
3
|
+
/** @internal */
|
|
3
4
|
export { createApplicationComponent } from "./components/application.js";
|
|
4
5
|
export { createElementComponent } from "./components/element.js";
|
|
6
|
+
/** @internal */
|
|
5
7
|
export { createWindowComponent } from "./components/window.js";
|
|
6
|
-
export { ApplicationContext } from "./hooks/use-application.js";
|
|
7
8
|
export { useMergedRef } from "./hooks/use-merged-refs.js";
|
|
8
|
-
export { useObjectValue } from "./hooks/use-object-value.js";
|
|
9
9
|
export type * from "./prop-types.js";
|
|
10
|
+
export type { ModuleExport } from "./reconciler/registry.js";
|
|
10
11
|
export { isRootElement } from "./reconciler/root-element.js";
|
|
11
12
|
export { createReconcilerRoot, type ReconcilerRoot, setReconcilerErrorHandler } from "./reconciler/root.js";
|
|
12
13
|
export { applyWrite } from "./reconciler/signals.js";
|
|
13
14
|
export { getAccessibleMetadata } from "./utils/accessible-metadata.js";
|
|
14
|
-
export {
|
|
15
|
+
export type { SettingsSchema, SettingsSchemaKeys, SettingValue } from "./utils/settings.js";
|
package/src/prop-types.ts
CHANGED
|
@@ -5,110 +5,191 @@ import type { ReactNode } from "react";
|
|
|
5
5
|
|
|
6
6
|
/** One entry of a `GMenu`'s `items` prop; `submenu` and `section` nest further menus. */
|
|
7
7
|
type MenuItem = {
|
|
8
|
+
/** Text shown for the entry, or the heading of the submenu or section it introduces. */
|
|
8
9
|
label?: string | null;
|
|
10
|
+
/** Detailed action name the entry activates, ignored when `submenu` or `section` is given. */
|
|
9
11
|
action?: string | null;
|
|
12
|
+
/** Entries of a separate menu the labelled entry opens. */
|
|
10
13
|
submenu?: MenuItem[];
|
|
14
|
+
/** Entries appended below the label as an inline section, used only when `submenu` is absent. */
|
|
11
15
|
section?: MenuItem[];
|
|
12
16
|
};
|
|
13
17
|
|
|
14
18
|
/** One Visual Format Language block applied to a `Gtk.ConstraintLayout`. */
|
|
15
19
|
type VflConstraints = {
|
|
20
|
+
/** Format lines, each describing every constraint on one row or column. */
|
|
16
21
|
lines: string[];
|
|
22
|
+
/** Default horizontal spacing the `-` operator stands for; defaults to 0. */
|
|
17
23
|
hspacing?: number;
|
|
24
|
+
/** Default vertical spacing the `-` operator stands for; defaults to 0. */
|
|
18
25
|
vspacing?: number;
|
|
26
|
+
/** Targets the view names in `lines` refer to; defaults to none. */
|
|
19
27
|
views?: Map<string, Gtk.ConstraintTarget>;
|
|
20
28
|
};
|
|
21
29
|
|
|
22
30
|
/** One mark on a `Gtk.Scale`. */
|
|
23
|
-
type ScaleMark = {
|
|
31
|
+
type ScaleMark = {
|
|
32
|
+
/** Point on the scale the mark is drawn at; defaults to 0. */
|
|
33
|
+
value?: number;
|
|
34
|
+
/** Side of the scale the mark and its label sit on. */
|
|
35
|
+
position: Gtk.PositionType;
|
|
36
|
+
/** Pango markup drawn beside the mark, or `null` for an unlabelled one. */
|
|
37
|
+
markup?: string | null;
|
|
38
|
+
};
|
|
39
|
+
|
|
24
40
|
/** One labelled offset on a `Gtk.LevelBar`. */
|
|
25
|
-
type LevelBarOffset = {
|
|
41
|
+
type LevelBarOffset = {
|
|
42
|
+
/** Style class applied to the bar's blocks while the value falls in this offset's interval. */
|
|
43
|
+
name: string;
|
|
44
|
+
/** Upper bound of that interval; defaults to 0. */
|
|
45
|
+
value?: number;
|
|
46
|
+
};
|
|
47
|
+
|
|
26
48
|
/** One credit section on a `Gtk.AboutDialog`. */
|
|
27
|
-
type CreditSection = {
|
|
49
|
+
type CreditSection = {
|
|
50
|
+
/** Heading the names are listed under. */
|
|
51
|
+
sectionName: string;
|
|
52
|
+
/** Names listed in the section. */
|
|
53
|
+
people: string[];
|
|
54
|
+
};
|
|
55
|
+
|
|
28
56
|
/** One accelerator binding on a `Gtk.Application`. */
|
|
29
|
-
type ActionAccel = {
|
|
57
|
+
type ActionAccel = {
|
|
58
|
+
/** Action the accelerators activate, such as `app.quit` or `win.open('file')`. */
|
|
59
|
+
detailedActionName: string;
|
|
60
|
+
/** Accelerators in `Gtk.acceleratorParse` syntax, cleared when the entry goes away. */
|
|
61
|
+
accels: string[];
|
|
62
|
+
};
|
|
63
|
+
|
|
30
64
|
/** The drag icon of a `Gtk.DragSource`, with its hotspot. */
|
|
31
|
-
type DragSourceIcon = {
|
|
65
|
+
type DragSourceIcon = {
|
|
66
|
+
/** Image shown under the pointer during the drag; defaults to none. */
|
|
67
|
+
paintable?: Gdk.Paintable | null;
|
|
68
|
+
/** Horizontal offset of the pointer within the image; defaults to 0. */
|
|
69
|
+
hotX?: number;
|
|
70
|
+
/** Vertical offset of the pointer within the image; defaults to 0. */
|
|
71
|
+
hotY?: number;
|
|
72
|
+
};
|
|
32
73
|
|
|
33
74
|
/** Props of an element that accepts children. */
|
|
34
75
|
type ChildrenProps = {
|
|
76
|
+
/** Elements attached to the element's default child slot, or its text for elements that hold text. */
|
|
35
77
|
children?: ReactNode;
|
|
36
78
|
};
|
|
37
79
|
|
|
80
|
+
/** Objects a widget takes through a method call rather than a property. */
|
|
38
81
|
type GtkWidgetProps = {
|
|
82
|
+
/** `Gtk.EventController` elements added to the widget. */
|
|
39
83
|
controllers?: ReactNode | null | undefined;
|
|
84
|
+
/** `Gio.ActionGroup` elements inserted into the widget, each under its own `prefix`. */
|
|
40
85
|
actionGroups?: ReactNode | null | undefined;
|
|
41
86
|
} & ChildrenProps;
|
|
42
87
|
|
|
88
|
+
/** Props of an action group placed in a widget's `actionGroups` slot. */
|
|
43
89
|
type GActionGroupProps = {
|
|
90
|
+
/** Prefix the group's actions are addressed by, such as `win`; defaults to the empty string. */
|
|
44
91
|
prefix?: string | null | undefined;
|
|
45
92
|
};
|
|
46
93
|
|
|
94
|
+
/** Props of an element implementing `Gio.ActionMap`. */
|
|
47
95
|
type GActionMapProps = {
|
|
96
|
+
/** `Gio.Action` elements added to the map, removed again by their `name`. */
|
|
48
97
|
actions?: ReactNode | null | undefined;
|
|
49
98
|
};
|
|
50
99
|
|
|
100
|
+
/** Props of a `Gio.Menu` element. */
|
|
51
101
|
type GMenuProps = {
|
|
102
|
+
/** Entries the menu is rebuilt from whenever they change. */
|
|
52
103
|
items?: MenuItem[] | null | undefined;
|
|
53
104
|
};
|
|
54
105
|
|
|
106
|
+
/** Props of a `Gtk.ShortcutController` element. */
|
|
55
107
|
type GtkShortcutControllerProps = {
|
|
108
|
+
/** `Gtk.Shortcut` elements the controller watches for. */
|
|
56
109
|
shortcuts?: ReactNode | null | undefined;
|
|
57
110
|
};
|
|
58
111
|
|
|
112
|
+
/** Props of a `Gtk.Overlay` element, whose `children` is the widget the overlays sit above. */
|
|
59
113
|
type GtkOverlayProps = {
|
|
114
|
+
/** Widgets stacked over the main child. */
|
|
60
115
|
overlays?: ReactNode | null | undefined;
|
|
61
116
|
} & ChildrenProps;
|
|
62
117
|
|
|
118
|
+
/** Props of a `Gtk.ConstraintLayout` element. */
|
|
63
119
|
type GtkConstraintLayoutProps = {
|
|
120
|
+
/** `Gtk.Constraint` elements added to the layout. */
|
|
64
121
|
constraints?: ReactNode | null | undefined;
|
|
122
|
+
/** `Gtk.ConstraintGuide` elements added to the layout as invisible spacers. */
|
|
65
123
|
guides?: ReactNode | null | undefined;
|
|
124
|
+
/** Visual Format Language blocks whose constraints are added alongside `constraints`. */
|
|
66
125
|
vfl?: VflConstraints[] | null | undefined;
|
|
67
126
|
};
|
|
68
127
|
|
|
69
128
|
/** Props of `GtkTextChildAnchor`, which embeds either a child widget or a paintable in a text buffer. */
|
|
70
129
|
type GtkTextChildAnchorProps = {
|
|
130
|
+
/** Image inserted into the buffer instead of an anchored widget; giving both is an error. */
|
|
71
131
|
paintable?: Gdk.Paintable | null | undefined;
|
|
72
132
|
} & ChildrenProps;
|
|
73
133
|
|
|
134
|
+
/** Props of a `Gtk.HeaderBar` or `Gtk.ActionBar` element. */
|
|
74
135
|
type GtkHeaderBarProps = {
|
|
136
|
+
/** Widgets packed at the start of the bar. */
|
|
75
137
|
start?: ReactNode | null | undefined;
|
|
138
|
+
/** Widgets packed at the end of the bar. */
|
|
76
139
|
end?: ReactNode | null | undefined;
|
|
77
140
|
};
|
|
78
141
|
|
|
142
|
+
/** Props of a `Gtk.Scale` element. */
|
|
79
143
|
type GtkScaleProps = {
|
|
144
|
+
/** Marks drawn along the scale, cleared and re-added whenever the list changes. */
|
|
80
145
|
marks?: ScaleMark[] | null | undefined;
|
|
81
146
|
};
|
|
82
147
|
|
|
148
|
+
/** Props of a `Gtk.Calendar` element. */
|
|
83
149
|
type GtkCalendarProps = {
|
|
150
|
+
/** Days of the shown month drawn as marked, cleared and re-marked whenever the list changes. */
|
|
84
151
|
markedDays?: number[] | null | undefined;
|
|
85
152
|
};
|
|
86
153
|
|
|
154
|
+
/** Props of a `Gtk.LevelBar` element. */
|
|
87
155
|
type GtkLevelBarProps = {
|
|
156
|
+
/** Offsets that split the bar's range into differently styled intervals. */
|
|
88
157
|
offsets?: LevelBarOffset[] | null | undefined;
|
|
89
158
|
};
|
|
90
159
|
|
|
160
|
+
/** Props of a `Gtk.SizeGroup` element. */
|
|
91
161
|
type GtkSizeGroupProps = {
|
|
162
|
+
/** Widgets the group keeps at a common size. */
|
|
92
163
|
widgets?: Gtk.Widget[] | null | undefined;
|
|
93
164
|
};
|
|
94
165
|
|
|
166
|
+
/** Props of a `Gtk.AboutDialog` element. */
|
|
95
167
|
type GtkAboutDialogProps = {
|
|
168
|
+
/** Extra sections appended to the dialog's credits, which GTK offers no way to remove. */
|
|
96
169
|
creditSections?: CreditSection[] | null | undefined;
|
|
97
170
|
};
|
|
98
171
|
|
|
172
|
+
/** Props of a `Gtk.Application` element, whose `children` are the windows it owns. */
|
|
99
173
|
type GtkApplicationProps = {
|
|
174
|
+
/** Accelerators bound to the application's actions. */
|
|
100
175
|
actionAccels?: ActionAccel[] | null | undefined;
|
|
101
176
|
} & ChildrenProps;
|
|
102
177
|
|
|
178
|
+
/** Props of a `Gtk.DropTarget` element. */
|
|
103
179
|
type GtkDropTargetProps = {
|
|
180
|
+
/** GTypes the target accepts a drop of. */
|
|
104
181
|
types?: GObject.Type[] | null | undefined;
|
|
105
182
|
};
|
|
106
183
|
|
|
184
|
+
/** Props of a `Gtk.DrawingArea` element. */
|
|
107
185
|
type GtkDrawingAreaProps = {
|
|
186
|
+
/** Callback that draws the area's contents; setting it queues a redraw. */
|
|
108
187
|
drawFunc?: Gtk.DrawingAreaDrawFunc | null | undefined;
|
|
109
188
|
};
|
|
110
189
|
|
|
190
|
+
/** Props of a `Gtk.DragSource` element. */
|
|
111
191
|
type GtkDragSourceProps = {
|
|
192
|
+
/** Icon shown under the pointer while a drag started from this source is in flight. */
|
|
112
193
|
icon?: DragSourceIcon | null | undefined;
|
|
113
194
|
};
|
|
114
195
|
|
|
@@ -23,7 +23,7 @@ type ListHooks<P extends GObject.Object, I, H> = {
|
|
|
23
23
|
|
|
24
24
|
type ListEntry = { item: unknown; handle: unknown };
|
|
25
25
|
type ListState = { snapshot: unknown[]; entries: ListEntry[] };
|
|
26
|
-
type DeferredState = { desired: unknown;
|
|
26
|
+
type DeferredState = { desired: unknown; isPresent: boolean; applied: unknown };
|
|
27
27
|
type CanApply<P extends GObject.Object, V> = (object: P, value: V) => boolean;
|
|
28
28
|
type ChildSetter = GObject.Object & { setChild: (child: Gtk.Widget | null) => void };
|
|
29
29
|
type ContentSetter<C extends Gtk.Widget> = GObject.Object & { setContent: (content: C | null) => void };
|
|
@@ -67,7 +67,6 @@ const slotAttach =
|
|
|
67
67
|
return attach(object as P, child as C, info) ?? true;
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
/** Builds a behavior for a named child slot holding children of `childType`, claiming matches only. */
|
|
71
70
|
const slot = <P extends GObject.Object, C extends GObject.Object>(
|
|
72
71
|
slotName: string,
|
|
73
72
|
childType: string,
|
|
@@ -94,7 +93,6 @@ const slot = <P extends GObject.Object, C extends GObject.Object>(
|
|
|
94
93
|
return behavior;
|
|
95
94
|
};
|
|
96
95
|
|
|
97
|
-
/** Builds a scalar-prop behavior that invokes `apply` whenever the value changes, and claims the prop. */
|
|
98
96
|
const value = <P extends GObject.Object, V>(
|
|
99
97
|
prop: string,
|
|
100
98
|
apply: ValueApply<P, V>,
|
|
@@ -130,11 +128,6 @@ const teardownList = <P extends GObject.Object, I, H>(
|
|
|
130
128
|
}
|
|
131
129
|
};
|
|
132
130
|
|
|
133
|
-
/**
|
|
134
|
-
* Builds an array-prop behavior that adds, removes, and clears its items, reapplying on structural
|
|
135
|
-
* change. `add` may return a handle that the same item's later `remove` receives, for items whose
|
|
136
|
-
* teardown needs what `add` produced (as VFL constraints need the objects the layout created).
|
|
137
|
-
*/
|
|
138
131
|
const list = <P extends GObject.Object, I, H = void>(
|
|
139
132
|
prop: string,
|
|
140
133
|
hooks: ListHooks<P, I, H>,
|
|
@@ -142,7 +135,7 @@ const list = <P extends GObject.Object, I, H = void>(
|
|
|
142
135
|
const { add } = hooks;
|
|
143
136
|
|
|
144
137
|
return {
|
|
145
|
-
|
|
138
|
+
initialize: (): ListState => ({ snapshot: [], entries: [] }),
|
|
146
139
|
update: (object, _prev, next, context) => {
|
|
147
140
|
const state = context as ListState;
|
|
148
141
|
const raw = next[prop];
|
|
@@ -169,7 +162,7 @@ const flushDeferred = <P extends GObject.Object, V>(
|
|
|
169
162
|
): void => {
|
|
170
163
|
const state = context as DeferredState;
|
|
171
164
|
|
|
172
|
-
if (!state.
|
|
165
|
+
if (!state.isPresent || Object.is(state.applied, state.desired)) {
|
|
173
166
|
return;
|
|
174
167
|
}
|
|
175
168
|
|
|
@@ -184,17 +177,16 @@ const flushDeferred = <P extends GObject.Object, V>(
|
|
|
184
177
|
state.applied = state.desired;
|
|
185
178
|
};
|
|
186
179
|
|
|
187
|
-
/** Builds a behavior for a prop applied after the surrounding commit, deferred until `canApply` returns true. */
|
|
188
180
|
const deferred = <P extends GObject.Object, V>(
|
|
189
181
|
prop: string,
|
|
190
182
|
canApply?: CanApply<P, V>,
|
|
191
183
|
): ElementBehavior<P> => ({
|
|
192
184
|
deferred: [prop],
|
|
193
|
-
|
|
185
|
+
initialize: (): DeferredState => ({ desired: undefined, isPresent: false, applied: undefined }),
|
|
194
186
|
update: (_object, _prev, next, context) => {
|
|
195
187
|
const state = context as DeferredState;
|
|
196
188
|
state.desired = next[prop];
|
|
197
|
-
state.
|
|
189
|
+
state.isPresent = next[prop] !== undefined;
|
|
198
190
|
|
|
199
191
|
return [prop];
|
|
200
192
|
},
|
|
@@ -203,7 +195,6 @@ const deferred = <P extends GObject.Object, V>(
|
|
|
203
195
|
},
|
|
204
196
|
});
|
|
205
197
|
|
|
206
|
-
/** Builds a behavior for a text prop kept in controlled-input sync: set when provided, never reset. */
|
|
207
198
|
const controlledText = (prop: string): ElementBehavior =>
|
|
208
199
|
value(prop, (object, next) => {
|
|
209
200
|
if (!hasSameText(object, prop, next)) {
|
|
@@ -213,7 +204,6 @@ const controlledText = (prop: string): ElementBehavior =>
|
|
|
213
204
|
}
|
|
214
205
|
});
|
|
215
206
|
|
|
216
|
-
/** Behavior for a container that installs its single child with `setChild`. */
|
|
217
207
|
const childSetterSlot = <P extends ChildSetter>(): ElementBehavior<P> =>
|
|
218
208
|
slot<P, Gtk.Widget>("children", "GtkWidget", {
|
|
219
209
|
attach: (parent, child) => {
|
|
@@ -224,7 +214,6 @@ const childSetterSlot = <P extends ChildSetter>(): ElementBehavior<P> =>
|
|
|
224
214
|
},
|
|
225
215
|
});
|
|
226
216
|
|
|
227
|
-
/** Behavior for a container that installs its single child with `setContent`. */
|
|
228
217
|
const contentSetterSlot = <P extends ContentSetter<C>, C extends Gtk.Widget = Gtk.Widget>(
|
|
229
218
|
childType = "GtkWidget",
|
|
230
219
|
): ElementBehavior<P> =>
|
|
@@ -237,7 +226,6 @@ const contentSetterSlot = <P extends ContentSetter<C>, C extends Gtk.Widget = Gt
|
|
|
237
226
|
},
|
|
238
227
|
});
|
|
239
228
|
|
|
240
|
-
/** Behavior for a `GtkBox`-style container that orders children by sibling. */
|
|
241
229
|
const boxSlot = <P extends BoxLike>(): ElementBehavior<P> =>
|
|
242
230
|
slot<P, Gtk.Widget>("children", "GtkWidget", {
|
|
243
231
|
attach: (box, child, info) => box.insertChildAfter(child, info.sibling as Gtk.Widget | null),
|
|
@@ -249,7 +237,6 @@ const boxSlot = <P extends BoxLike>(): ElementBehavior<P> =>
|
|
|
249
237
|
},
|
|
250
238
|
});
|
|
251
239
|
|
|
252
|
-
/** Behavior for a container whose children are added and removed by a pair of methods. */
|
|
253
240
|
const addRemoveSlot = <C extends GObject.Object, P extends GObject.Object>(
|
|
254
241
|
slotName: string,
|
|
255
242
|
childType: string,
|
|
@@ -257,7 +244,6 @@ const addRemoveSlot = <C extends GObject.Object, P extends GObject.Object>(
|
|
|
257
244
|
remove: (parent: P, child: C) => void,
|
|
258
245
|
): ElementBehavior => slot<P, C>(slotName, childType, { attach: add, detach: remove });
|
|
259
246
|
|
|
260
|
-
/** Behavior for a `children` slot whose attach call returns the page object the container adopts. */
|
|
261
247
|
const adoptedChildrenSlot = <P extends GObject.Object, C extends GObject.Object>(
|
|
262
248
|
childType: string,
|
|
263
249
|
add: (parent: P, item: C) => unknown,
|
|
@@ -300,7 +286,6 @@ const removeWrappedRow = (
|
|
|
300
286
|
}
|
|
301
287
|
};
|
|
302
288
|
|
|
303
|
-
/** Behavior for an index-placed container that wraps each child in `Wrapper` before adding it. */
|
|
304
289
|
const wrappingIndexedSlot = <W extends Gtk.Widget, P extends IndexedInserter>(
|
|
305
290
|
Wrapper: new (props: Props) => W,
|
|
306
291
|
setChild: (wrapper: W, inner: Gtk.Widget) => void,
|
|
@@ -312,7 +297,7 @@ const wrappingIndexedSlot = <W extends Gtk.Widget, P extends IndexedInserter>(
|
|
|
312
297
|
removeWrappedRow(Wrapper, parent, child, info.context as RowCache);
|
|
313
298
|
},
|
|
314
299
|
}),
|
|
315
|
-
|
|
300
|
+
initialize: (): RowCache => new WeakMap(),
|
|
316
301
|
});
|
|
317
302
|
|
|
318
303
|
export {
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
validateContentMix,
|
|
42
42
|
} from "./text.js";
|
|
43
43
|
|
|
44
|
-
/**
|
|
44
|
+
/** What a tree is rendered into: any GObject, or the {@link RootElement} marker to render at the top level. */
|
|
45
45
|
type Container = RootElement | GObject.Object;
|
|
46
46
|
|
|
47
47
|
type PriorityTracker = {
|
|
@@ -69,7 +69,7 @@ const createObject = (typeName: string, type: bigint, input: Props): GObject.Obj
|
|
|
69
69
|
const resolveElementNode = (typeName: string, props: Props, dispatch: Dispatch): ElementNode | LazyNode => {
|
|
70
70
|
const info = typeInfoFor(typeName);
|
|
71
71
|
|
|
72
|
-
if (info.
|
|
72
|
+
if (info.isLazy) {
|
|
73
73
|
return createLazyNode(typeName, props, dispatch);
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TYPE_INVALID, typeFromName, typeInterfaces, typeName, typeParent } from "@gtkx/runtime";
|
|
2
2
|
import { getOrInsert } from "@gtkx/utils";
|
|
3
|
-
import {
|
|
3
|
+
import { constructOnlyProps, constructProps, defaultProps, signals, userEventSignals } from "virtual:gtkx-config";
|
|
4
4
|
import { deferredProps, type ElementBehavior, ELEMENTS } from "./registry.js";
|
|
5
5
|
|
|
6
6
|
type TypeInfo = {
|
|
@@ -9,7 +9,7 @@ type TypeInfo = {
|
|
|
9
9
|
userEventSignals: Set<string>;
|
|
10
10
|
behaviors: ElementBehavior[];
|
|
11
11
|
deferred: Set<string>;
|
|
12
|
-
|
|
12
|
+
isLazy: boolean;
|
|
13
13
|
hasFlush: boolean;
|
|
14
14
|
hasMount: boolean;
|
|
15
15
|
constructOnly: Set<string>;
|
|
@@ -58,10 +58,10 @@ const addAll = <T>(target: Set<T>, source: Iterable<T> | undefined): void => {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
const accumulateAncestor = (info: TypeInfo, ancestor: string): void => {
|
|
61
|
-
Object.assign(info.signals,
|
|
61
|
+
Object.assign(info.signals, signals[ancestor] ?? {});
|
|
62
62
|
addAll(info.userEventSignals, userEventSignals[ancestor]);
|
|
63
|
-
addAll(info.constructOnly,
|
|
64
|
-
addAll(info.construct,
|
|
63
|
+
addAll(info.constructOnly, constructOnlyProps[ancestor]);
|
|
64
|
+
addAll(info.construct, constructProps[ancestor]);
|
|
65
65
|
info.behaviors.push(...(ELEMENTS[ancestor]?.behaviors ?? []));
|
|
66
66
|
};
|
|
67
67
|
|
|
@@ -92,7 +92,7 @@ const buildTypeInfo = (name: string): TypeInfo => {
|
|
|
92
92
|
userEventSignals: new Set(),
|
|
93
93
|
behaviors: [],
|
|
94
94
|
deferred: new Set(),
|
|
95
|
-
|
|
95
|
+
isLazy: false,
|
|
96
96
|
hasFlush: false,
|
|
97
97
|
hasMount: false,
|
|
98
98
|
constructOnly: new Set(),
|
|
@@ -105,10 +105,10 @@ const buildTypeInfo = (name: string): TypeInfo => {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
resolveBehaviorFlags(info);
|
|
108
|
-
info.
|
|
108
|
+
info.isLazy = chain.some((ancestor) => ELEMENTS[ancestor]?.isLazy === true);
|
|
109
109
|
|
|
110
110
|
for (const ancestor of chain.toReversed()) {
|
|
111
|
-
Object.assign(info.defaults,
|
|
111
|
+
Object.assign(info.defaults, defaultProps[ancestor] ?? {});
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
return info;
|
package/src/reconciler/node.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { getOrInsert } from "@gtkx/utils";
|
|
|
5
5
|
import type { ElementBehavior, Props } from "./registry.js";
|
|
6
6
|
|
|
7
7
|
type ContentKind = "label" | "buffer" | "tag" | "anchor";
|
|
8
|
-
type HandlerRecord = { signal: string; handler: SignalHandler; wrapped: SignalHandler;
|
|
8
|
+
type HandlerRecord = { signal: string; handler: SignalHandler; wrapped: SignalHandler; isBlockable: boolean };
|
|
9
9
|
type Dispatch = (fn: () => unknown) => unknown;
|
|
10
10
|
|
|
11
11
|
type SignalTarget = {
|
|
@@ -21,7 +21,7 @@ type PlacedChild = {
|
|
|
21
21
|
adopted: GObject.Object | null;
|
|
22
22
|
slot: string;
|
|
23
23
|
behavior: ElementBehavior | null;
|
|
24
|
-
|
|
24
|
+
isAttached: boolean;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
type ElementNode = SignalTarget & {
|
|
@@ -129,7 +129,7 @@ const lazyTarget = (node: LazyNode, adopted: GObject.Object): SignalTarget => ({
|
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
const getOrCreateContext = (node: ElementNode, behavior: ElementBehavior): unknown =>
|
|
132
|
-
getOrInsert(node.contexts, behavior, () => behavior.
|
|
132
|
+
getOrInsert(node.contexts, behavior, () => behavior.initialize?.(node.object));
|
|
133
133
|
|
|
134
134
|
export {
|
|
135
135
|
ELEMENT_KIND,
|