@gtkx/react 0.9.4 → 0.10.0
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 +55 -67
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +8 -8
- package/dist/factory.d.ts +3 -5
- package/dist/factory.js +18 -71
- package/dist/fiber-root.d.ts +1 -1
- package/dist/fiber-root.js +1 -2
- package/dist/generated/internal.d.ts +3 -6
- package/dist/generated/internal.js +10386 -13577
- package/dist/generated/jsx.d.ts +914 -808
- package/dist/generated/jsx.js +123 -358
- package/dist/generated/registry.d.ts +4 -0
- package/dist/generated/registry.js +13 -0
- package/dist/host-config.d.ts +7 -4
- package/dist/host-config.js +53 -18
- package/dist/index.d.ts +2 -22
- package/dist/index.js +2 -40
- package/dist/jsx.d.ts +719 -0
- package/dist/jsx.js +392 -0
- package/dist/node.d.ts +15 -32
- package/dist/node.js +20 -240
- package/dist/nodes/action-row-child.d.ts +21 -0
- package/dist/nodes/action-row-child.js +69 -0
- package/dist/nodes/action-row.js +33 -0
- package/dist/nodes/application.d.ts +1 -0
- package/dist/nodes/application.js +38 -0
- package/dist/nodes/autowrapped.d.ts +1 -0
- package/dist/nodes/autowrapped.js +109 -0
- package/dist/nodes/column-view-column.d.ts +16 -0
- package/dist/nodes/column-view-column.js +54 -0
- package/dist/nodes/column-view.d.ts +0 -59
- package/dist/nodes/column-view.js +107 -226
- package/dist/nodes/fixed-child.d.ts +1 -0
- package/dist/nodes/fixed-child.js +45 -0
- package/dist/nodes/grid-child.d.ts +1 -0
- package/dist/nodes/grid-child.js +54 -0
- package/dist/nodes/index.d.ts +34 -0
- package/dist/nodes/index.js +34 -0
- package/dist/nodes/internal/list-item-renderer.d.ts +18 -0
- package/dist/nodes/internal/list-item-renderer.js +67 -0
- package/dist/nodes/internal/list-store.d.ts +16 -0
- package/dist/nodes/internal/list-store.js +69 -0
- package/dist/nodes/internal/predicates.d.ts +26 -0
- package/dist/nodes/internal/predicates.js +36 -0
- package/dist/nodes/internal/signal-store.d.ts +9 -0
- package/dist/nodes/internal/signal-store.js +54 -0
- package/dist/nodes/internal/simple-list-store.d.ts +14 -0
- package/dist/nodes/internal/simple-list-store.js +60 -0
- package/dist/nodes/internal/tree-list-item-renderer.d.ts +18 -0
- package/dist/nodes/internal/tree-list-item-renderer.js +90 -0
- package/dist/nodes/internal/tree-store.d.ts +28 -0
- package/dist/nodes/internal/tree-store.js +153 -0
- package/dist/nodes/internal/utils.d.ts +3 -0
- package/dist/nodes/internal/utils.js +20 -0
- package/dist/nodes/list-item.d.ts +12 -0
- package/dist/nodes/list-item.js +24 -0
- package/dist/nodes/list-view.d.ts +0 -22
- package/dist/nodes/list-view.js +45 -38
- package/dist/nodes/menu.d.ts +6 -106
- package/dist/nodes/menu.js +16 -268
- package/dist/nodes/models/list.d.ts +24 -0
- package/dist/nodes/models/list.js +102 -0
- package/dist/nodes/models/menu.d.ts +45 -0
- package/dist/nodes/models/menu.js +265 -0
- package/dist/nodes/models/tree-list.d.ts +28 -0
- package/dist/nodes/models/tree-list.js +141 -0
- package/dist/nodes/navigation-page.d.ts +21 -0
- package/dist/nodes/navigation-page.js +95 -0
- package/dist/nodes/navigation-view.d.ts +1 -0
- package/dist/nodes/navigation-view.js +29 -0
- package/dist/nodes/notebook-page-tab.d.ts +15 -0
- package/dist/nodes/notebook-page-tab.js +42 -0
- package/dist/nodes/notebook-page.d.ts +23 -0
- package/dist/nodes/notebook-page.js +106 -0
- package/dist/nodes/notebook.d.ts +0 -32
- package/dist/nodes/notebook.js +20 -113
- package/dist/nodes/overlay-child.d.ts +1 -0
- package/dist/nodes/overlay-child.js +30 -0
- package/dist/nodes/pack-child.d.ts +21 -0
- package/dist/nodes/pack-child.js +68 -0
- package/dist/nodes/pack.d.ts +1 -0
- package/dist/nodes/pack.js +33 -0
- package/dist/nodes/popover-menu.d.ts +1 -0
- package/dist/nodes/popover-menu.js +58 -0
- package/dist/nodes/simple-list-item.d.ts +9 -0
- package/dist/nodes/simple-list-item.js +9 -0
- package/dist/nodes/simple-list-view.d.ts +1 -0
- package/dist/nodes/simple-list-view.js +75 -0
- package/dist/nodes/slot.d.ts +18 -10
- package/dist/nodes/slot.js +83 -51
- package/dist/nodes/stack-page.d.ts +1 -0
- package/dist/nodes/stack-page.js +80 -0
- package/dist/nodes/stack.d.ts +1 -22
- package/dist/nodes/stack.js +21 -60
- package/dist/nodes/toast-overlay.d.ts +1 -0
- package/dist/nodes/toast-overlay.js +35 -0
- package/dist/nodes/toast.d.ts +17 -0
- package/dist/nodes/toast.js +77 -0
- package/dist/nodes/toolbar-child.d.ts +9 -0
- package/dist/nodes/toolbar-child.js +33 -0
- package/dist/nodes/toolbar.d.ts +1 -0
- package/dist/nodes/toolbar.js +42 -0
- package/dist/nodes/tree-list-item.d.ts +20 -0
- package/dist/nodes/tree-list-item.js +102 -0
- package/dist/nodes/tree-list-view.d.ts +1 -0
- package/dist/nodes/tree-list-view.js +57 -0
- package/dist/nodes/virtual.d.ts +13 -0
- package/dist/nodes/virtual.js +21 -0
- package/dist/nodes/widget.d.ts +17 -3
- package/dist/nodes/widget.js +258 -2
- package/dist/nodes/window.d.ts +1 -12
- package/dist/nodes/window.js +66 -27
- package/dist/portal.d.ts +18 -13
- package/dist/portal.js +17 -14
- package/dist/reconciler.d.ts +0 -4
- package/dist/reconciler.js +1 -9
- package/dist/registry.d.ts +8 -0
- package/dist/registry.js +5 -0
- package/dist/render.d.ts +108 -12
- package/dist/render.js +140 -16
- package/dist/scheduler.d.ts +4 -0
- package/dist/scheduler.js +10 -0
- package/dist/types.d.ts +3 -136
- package/package.json +6 -6
- package/dist/batch.d.ts +0 -5
- package/dist/batch.js +0 -31
- package/dist/codegen/jsx-generator.d.ts +0 -56
- package/dist/codegen/jsx-generator.js +0 -959
- package/dist/containers.d.ts +0 -58
- package/dist/nodes/about-dialog.d.ts +0 -8
- package/dist/nodes/about-dialog.js +0 -16
- package/dist/nodes/action-bar.d.ts +0 -5
- package/dist/nodes/action-bar.js +0 -6
- package/dist/nodes/combo-row.d.ts +0 -5
- package/dist/nodes/combo-row.js +0 -6
- package/dist/nodes/drop-down.d.ts +0 -9
- package/dist/nodes/drop-down.js +0 -12
- package/dist/nodes/flow-box.d.ts +0 -10
- package/dist/nodes/flow-box.js +0 -41
- package/dist/nodes/grid.d.ts +0 -30
- package/dist/nodes/grid.js +0 -84
- package/dist/nodes/header-bar.d.ts +0 -43
- package/dist/nodes/header-bar.js +0 -116
- package/dist/nodes/indexed-child-container.d.ts +0 -16
- package/dist/nodes/indexed-child-container.js +0 -22
- package/dist/nodes/list-box.d.ts +0 -10
- package/dist/nodes/list-box.js +0 -48
- package/dist/nodes/list-item-factory.d.ts +0 -19
- package/dist/nodes/list-item-factory.js +0 -58
- package/dist/nodes/overlay.d.ts +0 -11
- package/dist/nodes/overlay.js +0 -50
- package/dist/nodes/paged-stack.d.ts +0 -31
- package/dist/nodes/paged-stack.js +0 -95
- package/dist/nodes/root.d.ts +0 -8
- package/dist/nodes/root.js +0 -13
- package/dist/nodes/selectable-list.d.ts +0 -45
- package/dist/nodes/selectable-list.js +0 -260
- package/dist/nodes/stack-page-props.d.ts +0 -11
- package/dist/nodes/stack-page-props.js +0 -23
- package/dist/nodes/string-list-container.d.ts +0 -34
- package/dist/nodes/string-list-container.js +0 -118
- package/dist/nodes/string-list-item.d.ts +0 -19
- package/dist/nodes/string-list-item.js +0 -50
- package/dist/nodes/string-list-store.d.ts +0 -13
- package/dist/nodes/string-list-store.js +0 -44
- package/dist/nodes/text-view.d.ts +0 -8
- package/dist/nodes/text-view.js +0 -16
- package/dist/nodes/toggle-button.d.ts +0 -14
- package/dist/nodes/toggle-button.js +0 -39
- package/dist/nodes/toolbar-view.d.ts +0 -14
- package/dist/nodes/toolbar-view.js +0 -78
- package/dist/nodes/view-stack.d.ts +0 -9
- package/dist/nodes/view-stack.js +0 -28
- package/dist/nodes/virtual-item.d.ts +0 -19
- package/dist/nodes/virtual-item.js +0 -48
- package/dist/nodes/virtual-slot.d.ts +0 -25
- package/dist/nodes/virtual-slot.js +0 -57
- package/dist/predicates.d.ts +0 -29
- package/dist/predicates.js +0 -37
- package/dist/props.d.ts +0 -7
- package/dist/props.js +0 -12
- /package/dist/{containers.js → nodes/action-row.d.ts} +0 -0
package/dist/node.js
CHANGED
|
@@ -1,246 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as GObject from "@gtkx/ffi/gobject";
|
|
3
|
-
import * as Gtk from "@gtkx/ffi/gtk";
|
|
4
|
-
import * as GtkSource from "@gtkx/ffi/gtksource";
|
|
5
|
-
import * as Vte from "@gtkx/ffi/vte";
|
|
6
|
-
import * as WebKit from "@gtkx/ffi/webkit";
|
|
7
|
-
import { CONSTRUCTOR_PARAMS, PROP_SETTERS, SETTER_GETTERS } from "./generated/internal.js";
|
|
8
|
-
import { isAddable, isAppendable, isChildContainer, isRemovable, isSingleChild } from "./predicates.js";
|
|
9
|
-
export const normalizeWidgetType = (type) => type.split(".")[0] || type;
|
|
10
|
-
const NAMESPACE_REGISTRY = [
|
|
11
|
-
["GtkSource", GtkSource],
|
|
12
|
-
["WebKit", WebKit],
|
|
13
|
-
["Adw", Adw],
|
|
14
|
-
["Vte", Vte],
|
|
15
|
-
];
|
|
16
|
-
const resolveWidgetClass = (type) => {
|
|
17
|
-
for (const [prefix, namespace] of NAMESPACE_REGISTRY) {
|
|
18
|
-
if (type.startsWith(prefix)) {
|
|
19
|
-
const className = type.slice(prefix.length);
|
|
20
|
-
return namespace[className];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
// biome-ignore lint/performance/noDynamicNamespaceImportAccess: dynamic widget resolution by name
|
|
24
|
-
return Gtk[type];
|
|
25
|
-
};
|
|
26
|
-
const extractConstructorArgs = (type, props) => {
|
|
27
|
-
const params = CONSTRUCTOR_PARAMS[type];
|
|
28
|
-
if (!params)
|
|
29
|
-
return [];
|
|
30
|
-
return params.map((p) => props[p.name]);
|
|
31
|
-
};
|
|
1
|
+
import { SignalStore } from "./nodes/internal/signal-store.js";
|
|
32
2
|
export class Node {
|
|
33
|
-
static
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
static consumedPropNames = [];
|
|
37
|
-
signalHandlers = new Map();
|
|
38
|
-
widget = undefined;
|
|
39
|
-
widgetType;
|
|
40
|
-
nodeType;
|
|
41
|
-
parent = null;
|
|
42
|
-
_state = null;
|
|
43
|
-
get state() {
|
|
44
|
-
if (this._state === null) {
|
|
45
|
-
throw new Error(`${this.constructor.name} not initialized`);
|
|
46
|
-
}
|
|
47
|
-
return this._state;
|
|
48
|
-
}
|
|
49
|
-
set state(value) {
|
|
50
|
-
this._state = value;
|
|
51
|
-
}
|
|
52
|
-
isVirtual() {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
isStandalone() {
|
|
3
|
+
static priority = 0;
|
|
4
|
+
static matches(_type, _containerOrClass) {
|
|
56
5
|
return false;
|
|
57
6
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (!WidgetClass) {
|
|
75
|
-
throw new Error(`Unknown GTK widget type: ${widgetType}`);
|
|
76
|
-
}
|
|
77
|
-
return new WidgetClass(...extractConstructorArgs(widgetType, props));
|
|
78
|
-
}
|
|
79
|
-
getWidget() {
|
|
80
|
-
return this.widget;
|
|
81
|
-
}
|
|
82
|
-
appendChild(child) {
|
|
83
|
-
child.parent = this;
|
|
84
|
-
const childWidget = child.getWidget();
|
|
85
|
-
if (!childWidget || child.isStandalone())
|
|
86
|
-
return;
|
|
87
|
-
if (isChildContainer(this)) {
|
|
88
|
-
this.attachChild(childWidget);
|
|
89
|
-
}
|
|
90
|
-
else if (this.widget && isAppendable(this.widget)) {
|
|
91
|
-
childWidget.insertBefore(this.widget);
|
|
92
|
-
}
|
|
93
|
-
else if (this.widget && isAddable(this.widget)) {
|
|
94
|
-
this.widget.add(childWidget);
|
|
95
|
-
}
|
|
96
|
-
else if (this.widget && isSingleChild(this.widget)) {
|
|
97
|
-
this.widget.setChild(childWidget);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
removeChild(child) {
|
|
101
|
-
child.unmount();
|
|
102
|
-
const childWidget = child.getWidget();
|
|
103
|
-
if (childWidget) {
|
|
104
|
-
if (isChildContainer(this)) {
|
|
105
|
-
this.detachChild(childWidget);
|
|
106
|
-
}
|
|
107
|
-
else if (this.widget && isRemovable(this.widget)) {
|
|
108
|
-
this.widget.remove(childWidget);
|
|
109
|
-
}
|
|
110
|
-
else if (this.widget && isSingleChild(this.widget)) {
|
|
111
|
-
this.widget.setChild(null);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
child.parent = null;
|
|
115
|
-
}
|
|
116
|
-
insertBefore(child, before) {
|
|
117
|
-
child.parent = this;
|
|
118
|
-
const childWidget = child.getWidget();
|
|
119
|
-
const beforeWidget = before.getWidget();
|
|
120
|
-
if (!childWidget || child.isStandalone())
|
|
121
|
-
return;
|
|
122
|
-
if (isChildContainer(this)) {
|
|
123
|
-
if (beforeWidget) {
|
|
124
|
-
this.insertChildBefore(childWidget, beforeWidget);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
this.attachChild(childWidget);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else if (this.widget && isAppendable(this.widget) && beforeWidget) {
|
|
131
|
-
childWidget.insertBefore(this.widget, beforeWidget);
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
this.appendChild(child);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
7
|
+
static createContainer(_props, _containerClass, _rootContainer) {
|
|
8
|
+
throw new Error("Cannot create container: unsupported node type");
|
|
9
|
+
}
|
|
10
|
+
container;
|
|
11
|
+
typeName;
|
|
12
|
+
signalStore;
|
|
13
|
+
constructor(typeName, _props = {}, container, _rootContainer) {
|
|
14
|
+
this.typeName = typeName;
|
|
15
|
+
this.container = container;
|
|
16
|
+
this.signalStore = new SignalStore();
|
|
17
|
+
}
|
|
18
|
+
appendChild(_child) { }
|
|
19
|
+
removeChild(_child) { }
|
|
20
|
+
insertBefore(_child, _before) { }
|
|
21
|
+
updateProps(_oldProps, _newProps) { }
|
|
22
|
+
mount() { }
|
|
137
23
|
unmount() {
|
|
138
|
-
this.
|
|
139
|
-
}
|
|
140
|
-
disconnectAllSignals() {
|
|
141
|
-
const widget = this.getWidget();
|
|
142
|
-
if (!widget)
|
|
143
|
-
return;
|
|
144
|
-
for (const [_eventName, handlerId] of this.signalHandlers) {
|
|
145
|
-
GObject.signalHandlerDisconnect(widget, handlerId);
|
|
146
|
-
}
|
|
147
|
-
this.signalHandlers.clear();
|
|
148
|
-
}
|
|
149
|
-
hasParent() {
|
|
150
|
-
return this.parent !== null;
|
|
151
|
-
}
|
|
152
|
-
consumedProps() {
|
|
153
|
-
const consumed = new Set(["children"]);
|
|
154
|
-
let proto = Object.getPrototypeOf(this);
|
|
155
|
-
while (proto && proto.constructor !== Object) {
|
|
156
|
-
const propNames = proto.constructor.consumedPropNames;
|
|
157
|
-
if (propNames) {
|
|
158
|
-
for (const name of propNames) {
|
|
159
|
-
consumed.add(name);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
proto = Object.getPrototypeOf(proto);
|
|
163
|
-
}
|
|
164
|
-
return consumed;
|
|
24
|
+
this.signalStore.clear();
|
|
165
25
|
}
|
|
166
|
-
updateProps(oldProps, newProps) {
|
|
167
|
-
const widget = this.getWidget();
|
|
168
|
-
if (!widget)
|
|
169
|
-
return;
|
|
170
|
-
const consumed = this.consumedProps();
|
|
171
|
-
const allKeys = new Set([...Object.keys(oldProps), ...Object.keys(newProps)]);
|
|
172
|
-
const signalUpdates = [];
|
|
173
|
-
const propertyUpdates = [];
|
|
174
|
-
for (const key of allKeys) {
|
|
175
|
-
if (consumed.has(key))
|
|
176
|
-
continue;
|
|
177
|
-
const oldValue = oldProps[key];
|
|
178
|
-
const newValue = newProps[key];
|
|
179
|
-
if (oldValue === newValue)
|
|
180
|
-
continue;
|
|
181
|
-
if (key.startsWith("on")) {
|
|
182
|
-
signalUpdates.push({ key, newValue });
|
|
183
|
-
}
|
|
184
|
-
else if (newValue !== undefined) {
|
|
185
|
-
propertyUpdates.push({ key, newValue });
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
for (const { key } of signalUpdates) {
|
|
189
|
-
this.disconnectSignal(this.propKeyToEventName(key));
|
|
190
|
-
}
|
|
191
|
-
if (propertyUpdates.length > 0) {
|
|
192
|
-
widget.freezeNotify();
|
|
193
|
-
}
|
|
194
|
-
for (const { key, newValue } of propertyUpdates) {
|
|
195
|
-
this.setProperty(widget, key, newValue);
|
|
196
|
-
}
|
|
197
|
-
if (propertyUpdates.length > 0) {
|
|
198
|
-
widget.thawNotify();
|
|
199
|
-
}
|
|
200
|
-
for (const { key, newValue } of signalUpdates) {
|
|
201
|
-
if (typeof newValue === "function") {
|
|
202
|
-
this.connectSignal(widget, this.propKeyToEventName(key), newValue);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
propKeyToEventName(key) {
|
|
207
|
-
return key
|
|
208
|
-
.slice(2)
|
|
209
|
-
.replace(/([A-Z])/g, "-$1")
|
|
210
|
-
.toLowerCase()
|
|
211
|
-
.replace(/^-/, "");
|
|
212
|
-
}
|
|
213
|
-
disconnectSignal(eventName) {
|
|
214
|
-
const handlerId = this.signalHandlers.get(eventName);
|
|
215
|
-
if (handlerId !== undefined) {
|
|
216
|
-
const widget = this.getWidget();
|
|
217
|
-
if (widget) {
|
|
218
|
-
GObject.signalHandlerDisconnect(widget, handlerId);
|
|
219
|
-
}
|
|
220
|
-
this.signalHandlers.delete(eventName);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
connectSignal(widget, eventName, handler) {
|
|
224
|
-
const handlerId = widget.connect(eventName, handler);
|
|
225
|
-
this.signalHandlers.set(eventName, handlerId);
|
|
226
|
-
}
|
|
227
|
-
setProperty(widget, key, value) {
|
|
228
|
-
const setterName = PROP_SETTERS[this.widgetType]?.[key];
|
|
229
|
-
if (!setterName)
|
|
230
|
-
return;
|
|
231
|
-
const setter = widget[setterName];
|
|
232
|
-
if (typeof setter !== "function")
|
|
233
|
-
return;
|
|
234
|
-
const getterName = SETTER_GETTERS[this.widgetType]?.[setterName];
|
|
235
|
-
if (getterName) {
|
|
236
|
-
const getter = widget[getterName];
|
|
237
|
-
if (typeof getter === "function") {
|
|
238
|
-
const currentValue = getter.call(widget);
|
|
239
|
-
if (currentValue === value)
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
setter.call(widget, value);
|
|
244
|
-
}
|
|
245
|
-
mount() { }
|
|
246
26
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import type { Node } from "../node.js";
|
|
3
|
+
import { VirtualNode } from "./virtual.js";
|
|
4
|
+
type PrefixSuffixWidget = Gtk.Widget & {
|
|
5
|
+
addPrefix(child: Gtk.Widget): void;
|
|
6
|
+
addSuffix(child: Gtk.Widget): void;
|
|
7
|
+
remove(child: Gtk.Widget): void;
|
|
8
|
+
};
|
|
9
|
+
export declare class ActionRowChild extends VirtualNode {
|
|
10
|
+
static priority: number;
|
|
11
|
+
static matches(type: string): boolean;
|
|
12
|
+
private parent?;
|
|
13
|
+
private children;
|
|
14
|
+
private getPosition;
|
|
15
|
+
setParent(newParent?: PrefixSuffixWidget): void;
|
|
16
|
+
appendChild(child: Node): void;
|
|
17
|
+
insertBefore(child: Node): void;
|
|
18
|
+
removeChild(child: Node): void;
|
|
19
|
+
unmount(): void;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { registerNodeClass } from "../registry.js";
|
|
2
|
+
import { scheduleAfterCommit } from "../scheduler.js";
|
|
3
|
+
import { VirtualNode } from "./virtual.js";
|
|
4
|
+
import { WidgetNode } from "./widget.js";
|
|
5
|
+
export class ActionRowChild extends VirtualNode {
|
|
6
|
+
static priority = 1;
|
|
7
|
+
static matches(type) {
|
|
8
|
+
return type === "ActionRow.Prefix" || type === "ActionRow.Suffix";
|
|
9
|
+
}
|
|
10
|
+
parent;
|
|
11
|
+
children = [];
|
|
12
|
+
getPosition() {
|
|
13
|
+
return this.typeName === "ActionRow.Prefix" ? "prefix" : "suffix";
|
|
14
|
+
}
|
|
15
|
+
setParent(newParent) {
|
|
16
|
+
this.parent = newParent;
|
|
17
|
+
}
|
|
18
|
+
appendChild(child) {
|
|
19
|
+
if (!(child instanceof WidgetNode)) {
|
|
20
|
+
throw new Error(`Cannot append '${child.typeName}' to '${this.typeName}': expected Widget`);
|
|
21
|
+
}
|
|
22
|
+
const widget = child.container;
|
|
23
|
+
this.children.push(widget);
|
|
24
|
+
scheduleAfterCommit(() => {
|
|
25
|
+
if (this.parent) {
|
|
26
|
+
if (this.getPosition() === "prefix") {
|
|
27
|
+
this.parent.addPrefix(widget);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.parent.addSuffix(widget);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
insertBefore(child) {
|
|
36
|
+
this.appendChild(child);
|
|
37
|
+
}
|
|
38
|
+
removeChild(child) {
|
|
39
|
+
if (!(child instanceof WidgetNode)) {
|
|
40
|
+
throw new Error(`Cannot remove '${child.typeName}' from '${this.typeName}': expected Widget`);
|
|
41
|
+
}
|
|
42
|
+
const widget = child.container;
|
|
43
|
+
const parent = this.parent;
|
|
44
|
+
const index = this.children.indexOf(widget);
|
|
45
|
+
if (index !== -1) {
|
|
46
|
+
this.children.splice(index, 1);
|
|
47
|
+
}
|
|
48
|
+
scheduleAfterCommit(() => {
|
|
49
|
+
if (parent) {
|
|
50
|
+
parent.remove(widget);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
unmount() {
|
|
55
|
+
const parent = this.parent;
|
|
56
|
+
const childrenToRemove = [...this.children];
|
|
57
|
+
if (parent && childrenToRemove.length > 0) {
|
|
58
|
+
scheduleAfterCommit(() => {
|
|
59
|
+
for (const widget of childrenToRemove) {
|
|
60
|
+
parent.remove(widget);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
this.children = [];
|
|
65
|
+
this.parent = undefined;
|
|
66
|
+
super.unmount();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
registerNodeClass(ActionRowChild);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import { registerNodeClass } from "../registry.js";
|
|
3
|
+
import { ActionRowChild } from "./action-row-child.js";
|
|
4
|
+
import { WidgetNode } from "./widget.js";
|
|
5
|
+
class ActionRowNode extends WidgetNode {
|
|
6
|
+
static priority = 0;
|
|
7
|
+
static matches(_type, containerOrClass) {
|
|
8
|
+
if (!containerOrClass ||
|
|
9
|
+
(typeof containerOrClass !== "function" && !(containerOrClass instanceof Gtk.Widget))) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const protoOrInstance = typeof containerOrClass === "function" ? containerOrClass.prototype : containerOrClass;
|
|
13
|
+
return "addPrefix" in protoOrInstance && "addSuffix" in protoOrInstance && "remove" in protoOrInstance;
|
|
14
|
+
}
|
|
15
|
+
appendChild(child) {
|
|
16
|
+
if (child instanceof ActionRowChild) {
|
|
17
|
+
child.setParent(this.container);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
super.appendChild(child);
|
|
21
|
+
}
|
|
22
|
+
insertBefore(child) {
|
|
23
|
+
this.appendChild(child);
|
|
24
|
+
}
|
|
25
|
+
removeChild(child) {
|
|
26
|
+
if (child instanceof ActionRowChild) {
|
|
27
|
+
child.unmount();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
super.removeChild(child);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
registerNodeClass(ActionRowNode);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import { Node } from "../node.js";
|
|
3
|
+
import { registerNodeClass } from "../registry.js";
|
|
4
|
+
import { isContainerType } from "./internal/utils.js";
|
|
5
|
+
import { MenuNode } from "./menu.js";
|
|
6
|
+
import { Menu } from "./models/menu.js";
|
|
7
|
+
class ApplicationNode extends Node {
|
|
8
|
+
static priority = 0;
|
|
9
|
+
menu;
|
|
10
|
+
static matches(_type, containerOrClass) {
|
|
11
|
+
return isContainerType(Gtk.Application, containerOrClass);
|
|
12
|
+
}
|
|
13
|
+
constructor(typeName, props, container, rootContainer) {
|
|
14
|
+
super(typeName, props, container, rootContainer);
|
|
15
|
+
const application = rootContainer instanceof Gtk.Application ? rootContainer : undefined;
|
|
16
|
+
this.menu = new Menu("root", {}, container, application);
|
|
17
|
+
}
|
|
18
|
+
appendChild(child) {
|
|
19
|
+
if (child instanceof MenuNode) {
|
|
20
|
+
this.menu.appendChild(child);
|
|
21
|
+
this.container.setMenubar(this.menu.getMenu());
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
insertBefore(child, before) {
|
|
25
|
+
if (child instanceof MenuNode) {
|
|
26
|
+
this.menu.insertBefore(child, before);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
removeChild(child) {
|
|
30
|
+
if (child instanceof MenuNode) {
|
|
31
|
+
this.menu.removeChild(child);
|
|
32
|
+
if (this.menu.getMenu().getNItems() === 0) {
|
|
33
|
+
this.container.setMenubar(undefined);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
registerNodeClass(ApplicationNode);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { batch } from "@gtkx/ffi";
|
|
2
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
3
|
+
import { registerNodeClass } from "../registry.js";
|
|
4
|
+
import { isRemovable, isSingleChild } from "./internal/predicates.js";
|
|
5
|
+
import { isContainerType } from "./internal/utils.js";
|
|
6
|
+
import { WidgetNode } from "./widget.js";
|
|
7
|
+
const isAutowrappedChild = (obj) => {
|
|
8
|
+
return obj instanceof Gtk.ListBoxRow || obj instanceof Gtk.FlowBoxChild;
|
|
9
|
+
};
|
|
10
|
+
class AutowrappedNode extends WidgetNode {
|
|
11
|
+
static priority = 2;
|
|
12
|
+
static matches(_type, containerOrClass) {
|
|
13
|
+
return isContainerType(Gtk.ListBox, containerOrClass) || isContainerType(Gtk.FlowBox, containerOrClass);
|
|
14
|
+
}
|
|
15
|
+
appendChild(child) {
|
|
16
|
+
if (!(child instanceof WidgetNode)) {
|
|
17
|
+
super.appendChild(child);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
batch(() => {
|
|
21
|
+
if (isAutowrappedChild(child.container)) {
|
|
22
|
+
const currentParent = child.container.getParent();
|
|
23
|
+
if (currentParent !== null && isRemovable(currentParent)) {
|
|
24
|
+
currentParent.remove(child.container);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.removeExistingWrapper(child.container);
|
|
29
|
+
}
|
|
30
|
+
this.container.append(child.container);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
removeChild(child) {
|
|
34
|
+
if (!(child instanceof WidgetNode)) {
|
|
35
|
+
super.removeChild(child);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
batch(() => {
|
|
39
|
+
if (!isAutowrappedChild(child.container)) {
|
|
40
|
+
const wrapper = child.container.getParent();
|
|
41
|
+
if (wrapper && isSingleChild(wrapper)) {
|
|
42
|
+
wrapper.setChild(null);
|
|
43
|
+
this.container.remove(wrapper);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
this.container.remove(child.container);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
insertBefore(child, before) {
|
|
51
|
+
if (!(child instanceof WidgetNode) || !(before instanceof WidgetNode)) {
|
|
52
|
+
super.insertBefore(child, before);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
batch(() => {
|
|
56
|
+
const currentParent = child.container.getParent();
|
|
57
|
+
if (currentParent !== null) {
|
|
58
|
+
if (isAutowrappedChild(child.container)) {
|
|
59
|
+
if (isRemovable(currentParent)) {
|
|
60
|
+
currentParent.remove(child.container);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.removeExistingWrapper(child.container);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (!isAutowrappedChild(child.container)) {
|
|
68
|
+
this.removeExistingWrapper(child.container);
|
|
69
|
+
}
|
|
70
|
+
const position = this.findChildPosition(before);
|
|
71
|
+
if (position !== undefined) {
|
|
72
|
+
this.container.insert(child.container, position);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.container.append(child.container);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
removeExistingWrapper(childWidget) {
|
|
80
|
+
const existingWrapper = childWidget.getParent();
|
|
81
|
+
if (existingWrapper && isSingleChild(existingWrapper)) {
|
|
82
|
+
existingWrapper.setChild(null);
|
|
83
|
+
const wrapperParent = existingWrapper.getParent();
|
|
84
|
+
if (wrapperParent !== null && isRemovable(wrapperParent)) {
|
|
85
|
+
wrapperParent.remove(existingWrapper);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
findChildPosition(before) {
|
|
90
|
+
let position = 0;
|
|
91
|
+
let currentChild = this.container.getFirstChild();
|
|
92
|
+
const beforeIsWrapper = isAutowrappedChild(before.container);
|
|
93
|
+
while (currentChild) {
|
|
94
|
+
const widgetToCompare = beforeIsWrapper ? currentChild : this.unwrapChild(currentChild);
|
|
95
|
+
if (widgetToCompare?.equals(before.container)) {
|
|
96
|
+
return position;
|
|
97
|
+
}
|
|
98
|
+
position++;
|
|
99
|
+
currentChild = currentChild.getNextSibling();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
unwrapChild(child) {
|
|
103
|
+
if ("getChild" in child && typeof child.getChild === "function") {
|
|
104
|
+
return child.getChild();
|
|
105
|
+
}
|
|
106
|
+
return child;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
registerNodeClass(AutowrappedNode);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import type { ColumnViewColumnProps } from "../jsx.js";
|
|
3
|
+
import type { Container } from "../types.js";
|
|
4
|
+
import type { ListStore } from "./internal/list-store.js";
|
|
5
|
+
import { VirtualNode } from "./virtual.js";
|
|
6
|
+
type Props = Partial<ColumnViewColumnProps>;
|
|
7
|
+
export declare class ColumnViewColumnNode extends VirtualNode<Props> {
|
|
8
|
+
static priority: number;
|
|
9
|
+
static matches(type: string): boolean;
|
|
10
|
+
column: Gtk.ColumnViewColumn;
|
|
11
|
+
private itemRenderer;
|
|
12
|
+
constructor(typeName: string, props: Props, container: undefined, rootContainer?: Container);
|
|
13
|
+
setStore(model?: ListStore): void;
|
|
14
|
+
updateProps(oldProps: Props | null, newProps: Props): void;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import { registerNodeClass } from "../registry.js";
|
|
3
|
+
import { ListItemRenderer } from "./internal/list-item-renderer.js";
|
|
4
|
+
import { VirtualNode } from "./virtual.js";
|
|
5
|
+
export class ColumnViewColumnNode extends VirtualNode {
|
|
6
|
+
static priority = 1;
|
|
7
|
+
static matches(type) {
|
|
8
|
+
return type === "ColumnViewColumn";
|
|
9
|
+
}
|
|
10
|
+
column;
|
|
11
|
+
itemRenderer;
|
|
12
|
+
constructor(typeName, props, container, rootContainer) {
|
|
13
|
+
super(typeName, props, container, rootContainer);
|
|
14
|
+
this.itemRenderer = new ListItemRenderer(this.signalStore);
|
|
15
|
+
this.column = new Gtk.ColumnViewColumn();
|
|
16
|
+
this.column.setFactory(this.itemRenderer.getFactory());
|
|
17
|
+
}
|
|
18
|
+
setStore(model) {
|
|
19
|
+
this.itemRenderer.setStore(model);
|
|
20
|
+
}
|
|
21
|
+
updateProps(oldProps, newProps) {
|
|
22
|
+
if (!oldProps || oldProps.renderCell !== newProps.renderCell) {
|
|
23
|
+
if (newProps.renderCell) {
|
|
24
|
+
this.itemRenderer.setRenderFn(newProps.renderCell);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!oldProps || oldProps.title !== newProps.title) {
|
|
28
|
+
this.column.setTitle(newProps.title ?? "");
|
|
29
|
+
}
|
|
30
|
+
if (!oldProps || oldProps.expand !== newProps.expand) {
|
|
31
|
+
this.column.setExpand(newProps.expand ?? false);
|
|
32
|
+
}
|
|
33
|
+
if (!oldProps || oldProps.resizable !== newProps.resizable) {
|
|
34
|
+
this.column.setResizable(newProps.resizable ?? false);
|
|
35
|
+
}
|
|
36
|
+
if (!oldProps || oldProps.fixedWidth !== newProps.fixedWidth) {
|
|
37
|
+
this.column.setFixedWidth(newProps.fixedWidth ?? -1);
|
|
38
|
+
}
|
|
39
|
+
if (!oldProps || oldProps.id !== newProps.id) {
|
|
40
|
+
if (newProps.id) {
|
|
41
|
+
this.column.setId(newProps.id);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!oldProps || oldProps.sortable !== newProps.sortable) {
|
|
45
|
+
if (newProps.sortable) {
|
|
46
|
+
this.column.setSorter(new Gtk.StringSorter());
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.column.setSorter(undefined);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
registerNodeClass(ColumnViewColumnNode);
|
|
@@ -1,60 +1 @@
|
|
|
1
|
-
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
-
import { StringSorter } from "@gtkx/ffi/gtk";
|
|
3
|
-
import type { ColumnContainer } from "../containers.js";
|
|
4
|
-
import type { Props } from "../factory.js";
|
|
5
|
-
import { Node } from "../node.js";
|
|
6
|
-
import type { RenderItemFn } from "../types.js";
|
|
7
|
-
import { type ListItemFactoryHandlers, type ListItemInfo } from "./list-item-factory.js";
|
|
8
|
-
import { SelectableListNode, type SelectableListState } from "./selectable-list.js";
|
|
9
|
-
import { VirtualItemNode } from "./virtual-item.js";
|
|
10
|
-
type ColumnViewState = SelectableListState & {
|
|
11
|
-
columns: ColumnViewColumnNode[];
|
|
12
|
-
sortColumn: string | null;
|
|
13
|
-
sortOrder: Gtk.SortType;
|
|
14
|
-
onSortChange: ((column: string | null, order: Gtk.SortType) => void) | null;
|
|
15
|
-
sorterChangedHandlerId: number | null;
|
|
16
|
-
lastNotifiedColumn: string | null;
|
|
17
|
-
lastNotifiedOrder: Gtk.SortType;
|
|
18
|
-
};
|
|
19
|
-
export declare class ColumnViewNode extends SelectableListNode<Gtk.ColumnView, ColumnViewState> implements ColumnContainer {
|
|
20
|
-
static consumedPropNames: string[];
|
|
21
|
-
static matches(type: string): boolean;
|
|
22
|
-
initialize(props: Props): void;
|
|
23
|
-
private connectSorterChangedSignal;
|
|
24
|
-
private disconnectSorterChangedSignal;
|
|
25
|
-
private notifySortChange;
|
|
26
|
-
unmount(): void;
|
|
27
|
-
appendChild(child: Node): void;
|
|
28
|
-
insertBefore(child: Node, before: Node): void;
|
|
29
|
-
removeChild(child: Node): void;
|
|
30
|
-
updateProps(oldProps: Props, newProps: Props): void;
|
|
31
|
-
private applySortIndicator;
|
|
32
|
-
addColumn(columnNode: ColumnViewColumnNode): void;
|
|
33
|
-
insertColumnBefore(column: ColumnViewColumnNode, before: ColumnViewColumnNode): void;
|
|
34
|
-
removeColumn(column: ColumnViewColumnNode): void;
|
|
35
|
-
}
|
|
36
|
-
type ColumnViewColumnState = {
|
|
37
|
-
column: Gtk.ColumnViewColumn;
|
|
38
|
-
factory: Gtk.SignalListItemFactory;
|
|
39
|
-
factoryHandlers: ListItemFactoryHandlers | null;
|
|
40
|
-
renderCell: RenderItemFn<unknown>;
|
|
41
|
-
columnId?: string;
|
|
42
|
-
listItemCache: Map<number, ListItemInfo>;
|
|
43
|
-
sorter?: StringSorter;
|
|
44
|
-
};
|
|
45
|
-
export declare class ColumnViewColumnNode extends Node<never, ColumnViewColumnState> {
|
|
46
|
-
static consumedPropNames: string[];
|
|
47
|
-
static matches(type: string): boolean;
|
|
48
|
-
protected isVirtual(): boolean;
|
|
49
|
-
private columnView;
|
|
50
|
-
initialize(props: Props): void;
|
|
51
|
-
getColumn(): Gtk.ColumnViewColumn;
|
|
52
|
-
getId(): string | undefined;
|
|
53
|
-
setColumnView(columnView: ColumnViewNode | null): void;
|
|
54
|
-
unmount(): void;
|
|
55
|
-
updateProps(oldProps: Props, newProps: Props): void;
|
|
56
|
-
}
|
|
57
|
-
export declare class ColumnViewItemNode extends VirtualItemNode {
|
|
58
|
-
static matches(type: string): boolean;
|
|
59
|
-
}
|
|
60
1
|
export {};
|