@gtkx/react 0.1.12 → 0.1.14
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 +6 -5
- package/dist/codegen/jsx-generator.js +13 -11
- package/dist/factory.js +2 -36
- package/dist/generated/jsx.d.ts +239 -239
- package/dist/index.js +2 -3
- package/dist/node.d.ts +17 -7
- package/dist/node.js +126 -1
- package/dist/nodes/dropdown.d.ts +23 -30
- package/dist/nodes/dropdown.js +31 -99
- package/dist/nodes/grid.d.ts +7 -24
- package/dist/nodes/grid.js +19 -72
- package/dist/nodes/list.d.ts +12 -31
- package/dist/nodes/list.js +30 -95
- package/dist/nodes/overlay.d.ts +3 -23
- package/dist/nodes/overlay.js +7 -85
- package/dist/nodes/slot.d.ts +5 -9
- package/dist/nodes/slot.js +13 -14
- package/dist/nodes/widget.d.ts +5 -12
- package/dist/nodes/widget.js +53 -82
- package/dist/portal.d.ts +0 -1
- package/dist/portal.js +0 -1
- package/dist/predicates.d.ts +13 -0
- package/dist/predicates.js +3 -0
- package/dist/reconciler.d.ts +5 -6
- package/dist/reconciler.js +14 -31
- package/dist/types.d.ts +2 -2
- package/package.json +5 -4
- package/dist/nodes/action-bar.d.ts +0 -27
- package/dist/nodes/action-bar.js +0 -88
- package/dist/nodes/dialog.d.ts +0 -19
- package/dist/nodes/dialog.js +0 -87
- package/dist/nodes/notebook.d.ts +0 -25
- package/dist/nodes/notebook.js +0 -88
- package/dist/nodes/text.d.ts +0 -16
- package/dist/nodes/text.js +0 -31
- package/dist/signal-utils.d.ts +0 -4
- package/dist/signal-utils.js +0 -7
- package/dist/widget-capabilities.d.ts +0 -46
- package/dist/widget-capabilities.js +0 -32
package/dist/nodes/list.js
CHANGED
|
@@ -1,46 +1,33 @@
|
|
|
1
|
+
import { wrapPtr } from "@gtkx/ffi";
|
|
1
2
|
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const LIST_VIEW_TYPES = ["ListView", "ListView.Root"];
|
|
8
|
-
export class ListViewNode {
|
|
9
|
-
static needsWidget = true;
|
|
10
|
-
static matches(type, widget) {
|
|
11
|
-
if (!LIST_VIEW_TYPES.includes(type) && !type.startsWith("ListView"))
|
|
12
|
-
return false;
|
|
13
|
-
return widget !== null && isListViewWidget(widget);
|
|
3
|
+
import { Node } from "../node.js";
|
|
4
|
+
const LIST_WIDGETS = ["ListView", "ColumnView", "GridView"];
|
|
5
|
+
export class ListViewNode extends Node {
|
|
6
|
+
static matches(type) {
|
|
7
|
+
return LIST_WIDGETS.map((w) => `${w}.Root`).includes(type);
|
|
14
8
|
}
|
|
15
|
-
widget;
|
|
16
9
|
stringList;
|
|
17
10
|
selectionModel;
|
|
18
11
|
factory;
|
|
19
12
|
items = [];
|
|
20
13
|
renderItem = null;
|
|
21
|
-
signalHandlers = new Map();
|
|
22
14
|
factorySignalHandlers = new Map();
|
|
23
|
-
constructor(
|
|
24
|
-
|
|
25
|
-
throw new Error("ListViewNode requires a ListView widget");
|
|
26
|
-
}
|
|
27
|
-
this.widget = widget;
|
|
15
|
+
constructor(type, props, currentApp) {
|
|
16
|
+
super(type, props, currentApp);
|
|
28
17
|
this.stringList = new Gtk.StringList([]);
|
|
29
18
|
this.selectionModel = new Gtk.SingleSelection(this.stringList);
|
|
30
19
|
this.factory = new Gtk.SignalListItemFactory();
|
|
31
20
|
this.renderItem = props.renderItem;
|
|
32
|
-
const setupHandlerId = this.factory.connect("setup", (
|
|
33
|
-
const listItem =
|
|
34
|
-
listItem.ptr = listItemPtr;
|
|
21
|
+
const setupHandlerId = this.factory.connect("setup", (_self, listItemObj) => {
|
|
22
|
+
const listItem = wrapPtr(listItemObj, Gtk.ListItem);
|
|
35
23
|
if (this.renderItem) {
|
|
36
24
|
const widget = this.renderItem(null);
|
|
37
25
|
listItem.setChild(widget);
|
|
38
26
|
}
|
|
39
27
|
});
|
|
40
28
|
this.factorySignalHandlers.set("setup", setupHandlerId);
|
|
41
|
-
const bindHandlerId = this.factory.connect("bind", (
|
|
42
|
-
const listItem =
|
|
43
|
-
listItem.ptr = listItemPtr;
|
|
29
|
+
const bindHandlerId = this.factory.connect("bind", (_self, listItemObj) => {
|
|
30
|
+
const listItem = wrapPtr(listItemObj, Gtk.ListItem);
|
|
44
31
|
const position = listItem.getPosition();
|
|
45
32
|
const item = this.items[position];
|
|
46
33
|
if (this.renderItem && item !== undefined) {
|
|
@@ -49,32 +36,8 @@ export class ListViewNode {
|
|
|
49
36
|
}
|
|
50
37
|
});
|
|
51
38
|
this.factorySignalHandlers.set("bind", bindHandlerId);
|
|
52
|
-
this.widget.setModel(this.selectionModel
|
|
53
|
-
this.widget.setFactory(this.factory
|
|
54
|
-
}
|
|
55
|
-
getWidget() {
|
|
56
|
-
return this.widget;
|
|
57
|
-
}
|
|
58
|
-
appendChild(child) {
|
|
59
|
-
child.attachToParent(this);
|
|
60
|
-
}
|
|
61
|
-
removeChild(child) {
|
|
62
|
-
child.detachFromParent(this);
|
|
63
|
-
}
|
|
64
|
-
insertBefore(child, _before) {
|
|
65
|
-
this.appendChild(child);
|
|
66
|
-
}
|
|
67
|
-
attachToParent(parent) {
|
|
68
|
-
const parentWidget = parent.getWidget?.();
|
|
69
|
-
if (parentWidget) {
|
|
70
|
-
appendChild(parentWidget, this.widget);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
detachFromParent(parent) {
|
|
74
|
-
const parentWidget = parent.getWidget?.();
|
|
75
|
-
if (parentWidget) {
|
|
76
|
-
removeChild(parentWidget, this.widget);
|
|
77
|
-
}
|
|
39
|
+
this.widget.setModel(this.selectionModel);
|
|
40
|
+
this.widget.setFactory(this.factory);
|
|
78
41
|
}
|
|
79
42
|
addItem(item) {
|
|
80
43
|
this.items.push(item);
|
|
@@ -87,52 +50,25 @@ export class ListViewNode {
|
|
|
87
50
|
this.stringList.remove(index);
|
|
88
51
|
}
|
|
89
52
|
}
|
|
53
|
+
consumedProps() {
|
|
54
|
+
const consumed = super.consumedProps();
|
|
55
|
+
consumed.add("renderItem");
|
|
56
|
+
return consumed;
|
|
57
|
+
}
|
|
90
58
|
updateProps(oldProps, newProps) {
|
|
91
59
|
if (oldProps.renderItem !== newProps.renderItem) {
|
|
92
60
|
this.renderItem = newProps.renderItem;
|
|
93
61
|
}
|
|
94
|
-
|
|
95
|
-
const allKeys = new Set([...Object.keys(oldProps), ...Object.keys(newProps)]);
|
|
96
|
-
for (const key of allKeys) {
|
|
97
|
-
if (consumedProps.has(key))
|
|
98
|
-
continue;
|
|
99
|
-
const oldValue = oldProps[key];
|
|
100
|
-
const newValue = newProps[key];
|
|
101
|
-
if (oldValue === newValue)
|
|
102
|
-
continue;
|
|
103
|
-
if (key.startsWith("on")) {
|
|
104
|
-
const eventName = key
|
|
105
|
-
.slice(2)
|
|
106
|
-
.replace(/([A-Z])/g, "-$1")
|
|
107
|
-
.toLowerCase()
|
|
108
|
-
.replace(/^-/, "");
|
|
109
|
-
const oldHandlerId = this.signalHandlers.get(eventName);
|
|
110
|
-
if (oldHandlerId !== undefined && isConnectable(this.widget)) {
|
|
111
|
-
this.signalHandlers.delete(eventName);
|
|
112
|
-
}
|
|
113
|
-
if (typeof newValue === "function" && isConnectable(this.widget)) {
|
|
114
|
-
const handlerId = this.widget.connect(eventName, newValue);
|
|
115
|
-
this.signalHandlers.set(eventName, handlerId);
|
|
116
|
-
}
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
const setterName = `set${key.charAt(0).toUpperCase()}${key.slice(1)}`;
|
|
120
|
-
const setter = this.widget[setterName];
|
|
121
|
-
if (typeof setter === "function") {
|
|
122
|
-
setter.call(this.widget, newValue);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
62
|
+
super.updateProps(oldProps, newProps);
|
|
125
63
|
}
|
|
126
|
-
mount() { }
|
|
127
64
|
dispose() {
|
|
128
|
-
|
|
129
|
-
|
|
65
|
+
super.dispose();
|
|
66
|
+
this.widget.setModel(undefined);
|
|
67
|
+
this.widget.setFactory(undefined);
|
|
130
68
|
}
|
|
131
69
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
static needsWidget = false;
|
|
135
|
-
static matches(type, _widget) {
|
|
70
|
+
export class ListItemNode extends Node {
|
|
71
|
+
static matches(type) {
|
|
136
72
|
const dotIndex = type.indexOf(".");
|
|
137
73
|
if (dotIndex === -1)
|
|
138
74
|
return false;
|
|
@@ -140,16 +76,17 @@ export class ListItemNode {
|
|
|
140
76
|
const suffix = type.slice(dotIndex + 1);
|
|
141
77
|
return suffix === "Item" && LIST_WIDGETS.includes(widgetType);
|
|
142
78
|
}
|
|
79
|
+
isVirtual() {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
143
82
|
item;
|
|
144
|
-
constructor(
|
|
83
|
+
constructor(type, props, _currentApp) {
|
|
84
|
+
super(type, props);
|
|
145
85
|
this.item = props.item;
|
|
146
86
|
}
|
|
147
87
|
getItem() {
|
|
148
88
|
return this.item;
|
|
149
89
|
}
|
|
150
|
-
appendChild(_child) { }
|
|
151
|
-
removeChild(_child) { }
|
|
152
|
-
insertBefore(_child, _before) { }
|
|
153
90
|
attachToParent(parent) {
|
|
154
91
|
if (parent instanceof ListViewNode) {
|
|
155
92
|
parent.addItem(this.item);
|
|
@@ -160,6 +97,4 @@ export class ListItemNode {
|
|
|
160
97
|
parent.removeItem(this.item);
|
|
161
98
|
}
|
|
162
99
|
}
|
|
163
|
-
updateProps(_oldProps, _newProps) { }
|
|
164
|
-
mount() { }
|
|
165
100
|
}
|
package/dist/nodes/overlay.d.ts
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
setChild(child: unknown): void;
|
|
6
|
-
addOverlay(widget: unknown): void;
|
|
7
|
-
removeOverlay(widget: unknown): void;
|
|
8
|
-
}
|
|
9
|
-
export declare class OverlayNode implements Node<OverlayWidget> {
|
|
10
|
-
static needsWidget: boolean;
|
|
11
|
-
static matches(type: string, widget: Gtk.Widget | null): widget is OverlayWidget;
|
|
12
|
-
private widget;
|
|
2
|
+
import { Node } from "../node.js";
|
|
3
|
+
export declare class OverlayNode extends Node<Gtk.Overlay> {
|
|
4
|
+
static matches(type: string): boolean;
|
|
13
5
|
private mainChild;
|
|
14
6
|
private overlayChildren;
|
|
15
|
-
private signalHandlers;
|
|
16
|
-
constructor(_type: string, widget: Gtk.Widget, _props: Props);
|
|
17
|
-
getWidget(): OverlayWidget;
|
|
18
|
-
appendChild(child: Node): void;
|
|
19
|
-
removeChild(child: Node): void;
|
|
20
|
-
insertBefore(child: Node, _before: Node): void;
|
|
21
|
-
attachToParent(parent: Node): void;
|
|
22
|
-
detachFromParent(parent: Node): void;
|
|
23
7
|
attachChild(childWidget: Gtk.Widget): void;
|
|
24
8
|
detachChild(childWidget: Gtk.Widget): void;
|
|
25
|
-
updateProps(oldProps: Props, newProps: Props): void;
|
|
26
|
-
mount(): void;
|
|
27
|
-
dispose(): void;
|
|
28
9
|
}
|
|
29
|
-
export {};
|
package/dist/nodes/overlay.js
CHANGED
|
@@ -1,59 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
typeof widget.addOverlay === "function" &&
|
|
6
|
-
"removeOverlay" in widget &&
|
|
7
|
-
typeof widget.removeOverlay === "function";
|
|
8
|
-
export class OverlayNode {
|
|
9
|
-
static needsWidget = true;
|
|
10
|
-
static matches(type, widget) {
|
|
11
|
-
if (type !== "Overlay" && type !== "Overlay.Root")
|
|
12
|
-
return false;
|
|
13
|
-
return widget !== null && isOverlayWidget(widget);
|
|
1
|
+
import { Node } from "../node.js";
|
|
2
|
+
export class OverlayNode extends Node {
|
|
3
|
+
static matches(type) {
|
|
4
|
+
return type === "Overlay" || type === "Overlay.Root";
|
|
14
5
|
}
|
|
15
|
-
widget;
|
|
16
6
|
mainChild = null;
|
|
17
7
|
overlayChildren = [];
|
|
18
|
-
signalHandlers = new Map();
|
|
19
|
-
constructor(_type, widget, _props) {
|
|
20
|
-
if (!isOverlayWidget(widget)) {
|
|
21
|
-
throw new Error("OverlayNode requires an Overlay widget");
|
|
22
|
-
}
|
|
23
|
-
this.widget = widget;
|
|
24
|
-
}
|
|
25
|
-
getWidget() {
|
|
26
|
-
return this.widget;
|
|
27
|
-
}
|
|
28
|
-
appendChild(child) {
|
|
29
|
-
child.attachToParent(this);
|
|
30
|
-
}
|
|
31
|
-
removeChild(child) {
|
|
32
|
-
child.detachFromParent(this);
|
|
33
|
-
}
|
|
34
|
-
insertBefore(child, _before) {
|
|
35
|
-
this.appendChild(child);
|
|
36
|
-
}
|
|
37
|
-
attachToParent(parent) {
|
|
38
|
-
const parentWidget = parent.getWidget?.();
|
|
39
|
-
if (parentWidget) {
|
|
40
|
-
appendChild(parentWidget, this.widget);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
detachFromParent(parent) {
|
|
44
|
-
const parentWidget = parent.getWidget?.();
|
|
45
|
-
if (parentWidget) {
|
|
46
|
-
removeChild(parentWidget, this.widget);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
8
|
attachChild(childWidget) {
|
|
50
9
|
if (this.mainChild === null) {
|
|
51
10
|
this.mainChild = childWidget;
|
|
52
|
-
this.widget.setChild(childWidget
|
|
11
|
+
this.widget.setChild(childWidget);
|
|
53
12
|
}
|
|
54
13
|
else {
|
|
55
14
|
this.overlayChildren.push(childWidget);
|
|
56
|
-
this.widget.addOverlay(childWidget
|
|
15
|
+
this.widget.addOverlay(childWidget);
|
|
57
16
|
}
|
|
58
17
|
}
|
|
59
18
|
detachChild(childWidget) {
|
|
@@ -65,45 +24,8 @@ export class OverlayNode {
|
|
|
65
24
|
const index = this.overlayChildren.indexOf(childWidget);
|
|
66
25
|
if (index !== -1) {
|
|
67
26
|
this.overlayChildren.splice(index, 1);
|
|
68
|
-
this.widget.removeOverlay(childWidget
|
|
27
|
+
this.widget.removeOverlay(childWidget);
|
|
69
28
|
}
|
|
70
29
|
}
|
|
71
30
|
}
|
|
72
|
-
updateProps(oldProps, newProps) {
|
|
73
|
-
const consumedProps = new Set(["children"]);
|
|
74
|
-
const allKeys = new Set([...Object.keys(oldProps), ...Object.keys(newProps)]);
|
|
75
|
-
for (const key of allKeys) {
|
|
76
|
-
if (consumedProps.has(key))
|
|
77
|
-
continue;
|
|
78
|
-
const oldValue = oldProps[key];
|
|
79
|
-
const newValue = newProps[key];
|
|
80
|
-
if (oldValue === newValue)
|
|
81
|
-
continue;
|
|
82
|
-
if (key.startsWith("on")) {
|
|
83
|
-
const eventName = key
|
|
84
|
-
.slice(2)
|
|
85
|
-
.replace(/([A-Z])/g, "-$1")
|
|
86
|
-
.toLowerCase()
|
|
87
|
-
.replace(/^-/, "");
|
|
88
|
-
const oldHandlerId = this.signalHandlers.get(eventName);
|
|
89
|
-
if (oldHandlerId !== undefined && isConnectable(this.widget)) {
|
|
90
|
-
this.signalHandlers.delete(eventName);
|
|
91
|
-
}
|
|
92
|
-
if (typeof newValue === "function" && isConnectable(this.widget)) {
|
|
93
|
-
const handlerId = this.widget.connect(eventName, newValue);
|
|
94
|
-
this.signalHandlers.set(eventName, handlerId);
|
|
95
|
-
}
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const setterName = `set${key.charAt(0).toUpperCase()}${key.slice(1)}`;
|
|
99
|
-
const setter = this.widget[setterName];
|
|
100
|
-
if (typeof setter === "function") {
|
|
101
|
-
setter.call(this.widget, newValue);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
mount() { }
|
|
106
|
-
dispose() {
|
|
107
|
-
disconnectSignalHandlers(this.widget, this.signalHandlers);
|
|
108
|
-
}
|
|
109
31
|
}
|
package/dist/nodes/slot.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
2
1
|
import type { Props } from "../factory.js";
|
|
3
|
-
import
|
|
4
|
-
export declare class SlotNode
|
|
5
|
-
static
|
|
6
|
-
|
|
2
|
+
import { Node } from "../node.js";
|
|
3
|
+
export declare class SlotNode extends Node<never> {
|
|
4
|
+
static matches(type: string): boolean;
|
|
5
|
+
protected isVirtual(): boolean;
|
|
7
6
|
private child;
|
|
8
7
|
private slotName;
|
|
9
|
-
constructor(type: string,
|
|
8
|
+
constructor(type: string, props: Props, _currentApp?: unknown);
|
|
10
9
|
appendChild(child: Node): void;
|
|
11
10
|
removeChild(_child: Node): void;
|
|
12
|
-
insertBefore(child: Node, _before: Node): void;
|
|
13
|
-
updateProps(_oldProps: Props, _newProps: Props): void;
|
|
14
|
-
mount(): void;
|
|
15
11
|
attachToParent(parent: Node): void;
|
|
16
12
|
detachFromParent(parent: Node): void;
|
|
17
13
|
}
|
package/dist/nodes/slot.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
static matches(type
|
|
1
|
+
import { Node } from "../node.js";
|
|
2
|
+
export class SlotNode extends Node {
|
|
3
|
+
static matches(type) {
|
|
4
4
|
if (!type.includes("."))
|
|
5
5
|
return false;
|
|
6
6
|
const parts = type.split(".");
|
|
7
7
|
if (parts.length !== 2)
|
|
8
8
|
return false;
|
|
9
9
|
const suffix = parts[1];
|
|
10
|
-
return suffix !== "
|
|
10
|
+
return suffix !== "Root";
|
|
11
|
+
}
|
|
12
|
+
isVirtual() {
|
|
13
|
+
return true;
|
|
11
14
|
}
|
|
12
15
|
child = null;
|
|
13
16
|
slotName;
|
|
14
|
-
constructor(type,
|
|
17
|
+
constructor(type, props, _currentApp) {
|
|
18
|
+
super(type, props);
|
|
15
19
|
const dotIndex = type.indexOf(".");
|
|
16
20
|
if (dotIndex === -1) {
|
|
17
21
|
throw new Error(`Invalid slot type: ${type}`);
|
|
@@ -19,21 +23,16 @@ export class SlotNode {
|
|
|
19
23
|
this.slotName = type.substring(dotIndex + 1);
|
|
20
24
|
}
|
|
21
25
|
appendChild(child) {
|
|
22
|
-
if (child.getWidget) {
|
|
26
|
+
if (child.getWidget()) {
|
|
23
27
|
this.child = child;
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
removeChild(_child) {
|
|
27
31
|
this.child = null;
|
|
28
32
|
}
|
|
29
|
-
insertBefore(child, _before) {
|
|
30
|
-
this.appendChild(child);
|
|
31
|
-
}
|
|
32
|
-
updateProps(_oldProps, _newProps) { }
|
|
33
|
-
mount() { }
|
|
34
33
|
attachToParent(parent) {
|
|
35
|
-
const parentWidget = parent.getWidget
|
|
36
|
-
const childWidget = this.child?.getWidget
|
|
34
|
+
const parentWidget = parent.getWidget();
|
|
35
|
+
const childWidget = this.child?.getWidget();
|
|
37
36
|
if (!parentWidget || !childWidget)
|
|
38
37
|
return;
|
|
39
38
|
const setterName = `set${this.slotName}`;
|
|
@@ -43,7 +42,7 @@ export class SlotNode {
|
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
detachFromParent(parent) {
|
|
46
|
-
const parentWidget = parent.getWidget
|
|
45
|
+
const parentWidget = parent.getWidget();
|
|
47
46
|
if (!parentWidget)
|
|
48
47
|
return;
|
|
49
48
|
const setterName = `set${this.slotName}`;
|
package/dist/nodes/widget.d.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
2
|
import type { Props } from "../factory.js";
|
|
3
|
-
import
|
|
4
|
-
export declare class WidgetNode
|
|
5
|
-
static
|
|
6
|
-
static matches(_type: string, widget: Gtk.Widget | null): widget is Gtk.Widget;
|
|
7
|
-
private widget;
|
|
8
|
-
private signalHandlers;
|
|
9
|
-
constructor(_type: string, widget: Gtk.Widget, _props: Props);
|
|
10
|
-
getWidget(): Gtk.Widget;
|
|
11
|
-
appendChild(child: Node): void;
|
|
12
|
-
removeChild(child: Node): void;
|
|
13
|
-
insertBefore(child: Node, _before: Node): void;
|
|
3
|
+
import { Node } from "../node.js";
|
|
4
|
+
export declare class WidgetNode extends Node<Gtk.Widget> {
|
|
5
|
+
static matches(_type: string): boolean;
|
|
14
6
|
attachToParent(parent: Node): void;
|
|
15
7
|
detachFromParent(parent: Node): void;
|
|
8
|
+
protected consumedProps(): Set<string>;
|
|
16
9
|
updateProps(oldProps: Props, newProps: Props): void;
|
|
17
10
|
mount(): void;
|
|
18
11
|
dispose(): void;
|
package/dist/nodes/widget.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { NotebookNode } from "./notebook.js";
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import { Node } from "../node.js";
|
|
3
|
+
import { getCurrentApp } from "../reconciler.js";
|
|
5
4
|
import { OverlayNode } from "./overlay.js";
|
|
6
5
|
const COMBINED_PROPS = [
|
|
7
6
|
{
|
|
8
7
|
props: ["defaultWidth", "defaultHeight"],
|
|
9
8
|
apply: (widget) => (values) => {
|
|
10
|
-
if (
|
|
9
|
+
if (widget instanceof Gtk.Window) {
|
|
11
10
|
const width = values.defaultWidth ?? -1;
|
|
12
11
|
const height = values.defaultHeight ?? -1;
|
|
13
12
|
widget.setDefaultSize(width, height);
|
|
@@ -15,122 +14,94 @@ const COMBINED_PROPS = [
|
|
|
15
14
|
},
|
|
16
15
|
},
|
|
17
16
|
];
|
|
18
|
-
export class WidgetNode {
|
|
19
|
-
static
|
|
20
|
-
|
|
21
|
-
return widget !== null;
|
|
22
|
-
}
|
|
23
|
-
widget;
|
|
24
|
-
signalHandlers = new Map();
|
|
25
|
-
constructor(_type, widget, _props) {
|
|
26
|
-
this.widget = widget;
|
|
27
|
-
}
|
|
28
|
-
getWidget() {
|
|
29
|
-
return this.widget;
|
|
30
|
-
}
|
|
31
|
-
appendChild(child) {
|
|
32
|
-
child.attachToParent(this);
|
|
33
|
-
}
|
|
34
|
-
removeChild(child) {
|
|
35
|
-
child.detachFromParent(this);
|
|
36
|
-
}
|
|
37
|
-
insertBefore(child, _before) {
|
|
38
|
-
this.appendChild(child);
|
|
17
|
+
export class WidgetNode extends Node {
|
|
18
|
+
static matches(_type) {
|
|
19
|
+
return true;
|
|
39
20
|
}
|
|
40
21
|
attachToParent(parent) {
|
|
41
|
-
if (
|
|
42
|
-
parent.attachChild(this.widget);
|
|
22
|
+
if (this.widget instanceof Gtk.AboutDialog) {
|
|
43
23
|
return;
|
|
44
24
|
}
|
|
45
25
|
if (parent instanceof OverlayNode) {
|
|
46
26
|
parent.attachChild(this.widget);
|
|
47
27
|
return;
|
|
48
28
|
}
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
const parentWidget = parent.getWidget();
|
|
30
|
+
if (!parentWidget)
|
|
31
|
+
return;
|
|
32
|
+
if (parentWidget instanceof Gtk.ActionBar) {
|
|
33
|
+
parentWidget.packStart(this.widget);
|
|
51
34
|
return;
|
|
52
35
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
if (parentWidget instanceof Gtk.Notebook) {
|
|
37
|
+
parentWidget.appendPage(this.widget);
|
|
38
|
+
return;
|
|
56
39
|
}
|
|
40
|
+
super.attachToParent(parent);
|
|
57
41
|
}
|
|
58
42
|
detachFromParent(parent) {
|
|
59
|
-
if (
|
|
60
|
-
parent.detachChild(this.widget);
|
|
43
|
+
if (this.widget instanceof Gtk.AboutDialog) {
|
|
61
44
|
return;
|
|
62
45
|
}
|
|
63
46
|
if (parent instanceof OverlayNode) {
|
|
64
47
|
parent.detachChild(this.widget);
|
|
65
48
|
return;
|
|
66
49
|
}
|
|
67
|
-
|
|
68
|
-
|
|
50
|
+
const parentWidget = parent.getWidget();
|
|
51
|
+
if (!parentWidget)
|
|
52
|
+
return;
|
|
53
|
+
if (parentWidget instanceof Gtk.ActionBar) {
|
|
54
|
+
parentWidget.remove(this.widget);
|
|
69
55
|
return;
|
|
70
56
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
57
|
+
if (parentWidget instanceof Gtk.Notebook) {
|
|
58
|
+
const pageNum = parentWidget.pageNum(this.widget);
|
|
59
|
+
if (pageNum >= 0) {
|
|
60
|
+
parentWidget.removePage(pageNum);
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
74
63
|
}
|
|
64
|
+
super.detachFromParent(parent);
|
|
65
|
+
}
|
|
66
|
+
consumedProps() {
|
|
67
|
+
const consumed = super.consumedProps();
|
|
68
|
+
consumed.add("application");
|
|
69
|
+
for (const handler of COMBINED_PROPS) {
|
|
70
|
+
for (const prop of handler.props) {
|
|
71
|
+
consumed.add(prop);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return consumed;
|
|
75
75
|
}
|
|
76
76
|
updateProps(oldProps, newProps) {
|
|
77
|
-
const consumedProps = new Set(["children", "application"]);
|
|
78
77
|
for (const handler of COMBINED_PROPS) {
|
|
79
78
|
const hasAnyChanged = handler.props.some((prop) => oldProps[prop] !== newProps[prop]);
|
|
80
79
|
if (hasAnyChanged) {
|
|
81
80
|
const values = {};
|
|
82
81
|
for (const prop of handler.props) {
|
|
83
82
|
values[prop] = newProps[prop];
|
|
84
|
-
consumedProps.add(prop);
|
|
85
83
|
}
|
|
86
84
|
handler.apply(this.widget)(values);
|
|
87
85
|
}
|
|
88
|
-
else {
|
|
89
|
-
for (const prop of handler.props) {
|
|
90
|
-
consumedProps.add(prop);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
const allKeys = new Set([...Object.keys(oldProps), ...Object.keys(newProps)]);
|
|
95
|
-
for (const key of allKeys) {
|
|
96
|
-
if (consumedProps.has(key))
|
|
97
|
-
continue;
|
|
98
|
-
const oldValue = oldProps[key];
|
|
99
|
-
const newValue = newProps[key];
|
|
100
|
-
if (oldValue === newValue)
|
|
101
|
-
continue;
|
|
102
|
-
if (key.startsWith("on")) {
|
|
103
|
-
const eventName = key
|
|
104
|
-
.slice(2)
|
|
105
|
-
.replace(/([A-Z])/g, "-$1")
|
|
106
|
-
.toLowerCase()
|
|
107
|
-
.replace(/^-/, "");
|
|
108
|
-
const oldHandlerId = this.signalHandlers.get(eventName);
|
|
109
|
-
if (oldHandlerId !== undefined) {
|
|
110
|
-
GObject.signalHandlerDisconnect(this.widget, oldHandlerId);
|
|
111
|
-
this.signalHandlers.delete(eventName);
|
|
112
|
-
}
|
|
113
|
-
if (typeof newValue === "function" && isConnectable(this.widget)) {
|
|
114
|
-
const handlerId = this.widget.connect(eventName, newValue);
|
|
115
|
-
this.signalHandlers.set(eventName, handlerId);
|
|
116
|
-
}
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
if (newValue === undefined)
|
|
120
|
-
continue;
|
|
121
|
-
const setterName = `set${key.charAt(0).toUpperCase()}${key.slice(1)}`;
|
|
122
|
-
const setter = this.widget[setterName];
|
|
123
|
-
if (typeof setter === "function") {
|
|
124
|
-
setter.call(this.widget, newValue);
|
|
125
|
-
}
|
|
126
86
|
}
|
|
87
|
+
super.updateProps(oldProps, newProps);
|
|
127
88
|
}
|
|
128
89
|
mount() {
|
|
129
|
-
if (
|
|
90
|
+
if (this.widget instanceof Gtk.AboutDialog) {
|
|
91
|
+
const app = getCurrentApp();
|
|
92
|
+
const activeWindow = app?.getActiveWindow();
|
|
93
|
+
if (activeWindow) {
|
|
94
|
+
this.widget.setTransientFor(activeWindow);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (this.widget instanceof Gtk.Window) {
|
|
130
98
|
this.widget.present();
|
|
131
99
|
}
|
|
132
100
|
}
|
|
133
101
|
dispose() {
|
|
134
|
-
|
|
102
|
+
super.dispose();
|
|
103
|
+
if (this.widget instanceof Gtk.Window) {
|
|
104
|
+
this.widget.close();
|
|
105
|
+
}
|
|
135
106
|
}
|
|
136
107
|
}
|
package/dist/portal.d.ts
CHANGED
package/dist/portal.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
export interface Appendable extends Gtk.Widget {
|
|
3
|
+
append(child: unknown): void;
|
|
4
|
+
}
|
|
5
|
+
export interface SingleChild extends Gtk.Widget {
|
|
6
|
+
setChild(child: unknown): void;
|
|
7
|
+
}
|
|
8
|
+
export interface Removable extends Gtk.Widget {
|
|
9
|
+
remove(child: unknown): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const isAppendable: (widget: Gtk.Widget) => widget is Appendable;
|
|
12
|
+
export declare const isSingleChild: (widget: Gtk.Widget) => widget is SingleChild;
|
|
13
|
+
export declare const isRemovable: (widget: Gtk.Widget) => widget is Removable;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export const isAppendable = (widget) => "append" in widget && typeof widget.append === "function";
|
|
2
|
+
export const isSingleChild = (widget) => "setChild" in widget && typeof widget.setChild === "function";
|
|
3
|
+
export const isRemovable = (widget) => "remove" in widget && typeof widget.remove === "function";
|