@gtkx/react 0.14.0 → 0.16.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 +28 -27
- package/dist/errors.js +3 -0
- package/dist/factory.d.ts +3 -2
- package/dist/factory.js +1 -1
- package/dist/generated/internal.d.ts +28 -1
- package/dist/generated/internal.js +93 -18
- package/dist/generated/jsx.d.ts +1712 -1516
- package/dist/generated/jsx.js +475 -0
- package/dist/host-config.d.ts +3 -1
- package/dist/host-config.js +31 -11
- package/dist/jsx.d.ts +147 -97
- package/dist/jsx.js +89 -21
- package/dist/node.d.ts +3 -1
- package/dist/node.js +5 -3
- package/dist/nodes/abstract/positional-child.d.ts +9 -0
- package/dist/nodes/abstract/positional-child.js +29 -0
- package/dist/nodes/abstract/positional-parent.d.ts +18 -0
- package/dist/nodes/abstract/positional-parent.js +48 -0
- package/dist/nodes/abstract/virtual-container.d.ts +17 -0
- package/dist/nodes/abstract/virtual-container.js +59 -0
- package/dist/nodes/abstract/virtual-single-child.d.ts +18 -0
- package/dist/nodes/abstract/virtual-single-child.js +54 -0
- package/dist/nodes/action-row-child.d.ts +0 -13
- package/dist/nodes/action-row-child.js +14 -12
- package/dist/nodes/action-row.d.ts +6 -1
- package/dist/nodes/action-row.js +4 -37
- package/dist/nodes/adjustable.d.ts +23 -0
- package/dist/nodes/adjustable.js +62 -0
- package/dist/nodes/alert-dialog-response.d.ts +1 -0
- package/dist/nodes/alert-dialog-response.js +86 -0
- package/dist/nodes/animation/animation-controller.d.ts +17 -0
- package/dist/nodes/animation/animation-controller.js +107 -0
- package/dist/nodes/animation/animation-factory.d.ts +15 -0
- package/dist/nodes/animation/animation-factory.js +25 -0
- package/dist/nodes/animation/animation-node.d.ts +9 -0
- package/dist/nodes/animation/animation-node.js +126 -0
- package/dist/nodes/animation/animation-style-sheet.d.ts +16 -0
- package/dist/nodes/animation/animation-style-sheet.js +74 -0
- package/dist/nodes/animation/index.d.ts +4 -0
- package/dist/nodes/animation/index.js +1 -0
- package/dist/nodes/animation/property-mapper.d.ts +11 -0
- package/dist/nodes/animation/property-mapper.js +36 -0
- package/dist/nodes/animation/transform-state.d.ts +11 -0
- package/dist/nodes/animation/transform-state.js +57 -0
- package/dist/nodes/animation/widget-registry.d.ts +5 -0
- package/dist/nodes/animation/widget-registry.js +42 -0
- package/dist/nodes/application.js +17 -7
- package/dist/nodes/autowrapped.js +37 -43
- package/dist/nodes/calendar.js +16 -55
- package/dist/nodes/color-dialog-button.d.ts +1 -0
- package/dist/nodes/color-dialog-button.js +70 -0
- package/dist/nodes/column-view-column.d.ts +4 -3
- package/dist/nodes/column-view-column.js +5 -1
- package/dist/nodes/column-view.js +40 -43
- package/dist/nodes/dialog.d.ts +11 -0
- package/dist/nodes/dialog.js +20 -0
- package/dist/nodes/drawing-area.d.ts +1 -0
- package/dist/nodes/drawing-area.js +36 -0
- package/dist/nodes/event-controller.d.ts +1 -0
- package/dist/nodes/event-controller.js +96 -0
- package/dist/nodes/expander-row-child.d.ts +0 -14
- package/dist/nodes/expander-row-child.js +14 -12
- package/dist/nodes/expander-row.d.ts +6 -1
- package/dist/nodes/expander-row.js +11 -47
- package/dist/nodes/fixed-child.js +48 -36
- package/dist/nodes/font-dialog-button.d.ts +1 -0
- package/dist/nodes/font-dialog-button.js +90 -0
- package/dist/nodes/grid-child.js +39 -45
- package/dist/nodes/grid.d.ts +1 -0
- package/dist/nodes/grid.js +41 -0
- package/dist/nodes/index.d.ts +22 -6
- package/dist/nodes/index.js +22 -6
- package/dist/nodes/internal/base-item-renderer.d.ts +29 -0
- package/dist/nodes/internal/base-item-renderer.js +88 -0
- package/dist/nodes/internal/base-store.d.ts +9 -0
- package/dist/nodes/internal/base-store.js +20 -0
- package/dist/nodes/internal/child-attachment.d.ts +26 -0
- package/dist/nodes/internal/child-attachment.js +48 -0
- package/dist/nodes/internal/deferred-action.d.ts +8 -0
- package/dist/nodes/internal/deferred-action.js +19 -0
- package/dist/nodes/internal/list-item-renderer.d.ts +14 -14
- package/dist/nodes/internal/list-item-renderer.js +49 -70
- package/dist/nodes/internal/list-store.d.ts +7 -6
- package/dist/nodes/internal/list-store.js +20 -24
- package/dist/nodes/internal/predicates.d.ts +28 -1
- package/dist/nodes/internal/predicates.js +53 -38
- package/dist/nodes/internal/selection-model.d.ts +30 -0
- package/dist/nodes/internal/selection-model.js +91 -0
- package/dist/nodes/internal/signal-store.d.ts +5 -3
- package/dist/nodes/internal/signal-store.js +30 -21
- package/dist/nodes/internal/simple-list-store.js +6 -9
- package/dist/nodes/internal/text-buffer-controller.d.ts +43 -0
- package/dist/nodes/internal/text-buffer-controller.js +287 -0
- package/dist/nodes/internal/text-tag-styles.d.ts +43 -0
- package/dist/nodes/internal/text-tag-styles.js +52 -0
- package/dist/nodes/internal/tree-list-item-renderer.d.ts +16 -14
- package/dist/nodes/internal/tree-list-item-renderer.js +88 -91
- package/dist/nodes/internal/tree-store.d.ts +10 -9
- package/dist/nodes/internal/tree-store.js +31 -35
- package/dist/nodes/internal/utils.d.ts +7 -4
- package/dist/nodes/internal/utils.js +50 -5
- package/dist/nodes/level-bar.js +18 -66
- package/dist/nodes/list-item.d.ts +6 -3
- package/dist/nodes/list-item.js +7 -4
- package/dist/nodes/list-view.js +19 -11
- package/dist/nodes/menu.d.ts +3 -3
- package/dist/nodes/menu.js +3 -3
- package/dist/nodes/models/list.d.ts +11 -13
- package/dist/nodes/models/list.js +16 -73
- package/dist/nodes/models/menu.d.ts +8 -7
- package/dist/nodes/models/menu.js +43 -50
- package/dist/nodes/models/tree-list.d.ts +6 -12
- package/dist/nodes/models/tree-list.js +30 -93
- package/dist/nodes/navigation-page.d.ts +1 -0
- package/dist/nodes/navigation-page.js +7 -3
- package/dist/nodes/navigation-view.js +17 -28
- package/dist/nodes/notebook-page-tab.d.ts +4 -3
- package/dist/nodes/notebook-page-tab.js +5 -2
- package/dist/nodes/notebook-page.d.ts +7 -5
- package/dist/nodes/notebook-page.js +39 -16
- package/dist/nodes/notebook.js +2 -2
- package/dist/nodes/overlay-child.js +90 -30
- package/dist/nodes/pack-child.d.ts +0 -13
- package/dist/nodes/pack-child.js +14 -12
- package/dist/nodes/pack.d.ts +6 -1
- package/dist/nodes/pack.js +4 -37
- package/dist/nodes/popover-menu.js +2 -2
- package/dist/nodes/scale.js +15 -58
- package/dist/nodes/scrolled-window.js +7 -5
- package/dist/nodes/search-bar.d.ts +1 -0
- package/dist/nodes/search-bar.js +40 -0
- package/dist/nodes/shortcut-controller.d.ts +1 -0
- package/dist/nodes/shortcut-controller.js +90 -0
- package/dist/nodes/shortcut.d.ts +39 -0
- package/dist/nodes/shortcut.js +52 -0
- package/dist/nodes/simple-list-view.js +2 -3
- package/dist/nodes/slot.d.ts +6 -9
- package/dist/nodes/slot.js +27 -42
- package/dist/nodes/source-view.d.ts +1 -0
- package/dist/nodes/source-view.js +93 -0
- package/dist/nodes/stack-page.js +17 -13
- package/dist/nodes/stack.js +19 -5
- package/dist/nodes/text-anchor.d.ts +41 -0
- package/dist/nodes/text-anchor.js +59 -0
- package/dist/nodes/text-content.d.ts +10 -0
- package/dist/nodes/text-content.js +1 -0
- package/dist/nodes/text-paintable.d.ts +17 -0
- package/dist/nodes/text-paintable.js +34 -0
- package/dist/nodes/text-segment.d.ts +15 -0
- package/dist/nodes/text-segment.js +29 -0
- package/dist/nodes/text-tag.d.ts +136 -0
- package/dist/nodes/text-tag.js +202 -0
- package/dist/nodes/text-view.d.ts +31 -0
- package/dist/nodes/text-view.js +73 -0
- package/dist/nodes/toggle-group.js +24 -32
- package/dist/nodes/toggle.d.ts +1 -15
- package/dist/nodes/toggle.js +40 -32
- package/dist/nodes/toolbar-child.js +14 -16
- package/dist/nodes/tree-list-item.d.ts +7 -5
- package/dist/nodes/tree-list-item.js +24 -36
- package/dist/nodes/tree-list-view.js +9 -4
- package/dist/nodes/virtual.d.ts +1 -1
- package/dist/nodes/widget.d.ts +3 -13
- package/dist/nodes/widget.js +117 -231
- package/dist/nodes/window.d.ts +9 -3
- package/dist/nodes/window.js +35 -19
- package/dist/registry.d.ts +1 -1
- package/dist/render.js +8 -6
- package/dist/scheduler.d.ts +11 -1
- package/dist/scheduler.js +16 -4
- package/dist/types.d.ts +2 -110
- package/package.json +3 -3
- package/dist/nodes/calendar-mark.d.ts +0 -15
- package/dist/nodes/calendar-mark.js +0 -29
- package/dist/nodes/internal/constants.d.ts +0 -1
- package/dist/nodes/internal/constants.js +0 -21
- package/dist/nodes/level-bar-offset.d.ts +0 -13
- package/dist/nodes/level-bar-offset.js +0 -35
- package/dist/nodes/scale-mark.d.ts +0 -17
- package/dist/nodes/scale-mark.js +0 -38
- package/dist/nodes/virtual-child.d.ts +0 -18
- package/dist/nodes/virtual-child.js +0 -62
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Gio from "@gtkx/ffi/gio";
|
|
2
2
|
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
3
3
|
import type { Node } from "../../node.js";
|
|
4
|
+
import type { Container } from "../../types.js";
|
|
4
5
|
import { VirtualNode } from "../virtual.js";
|
|
5
6
|
export type MenuType = "root" | "item" | "section" | "submenu";
|
|
6
7
|
export type MenuProps = {
|
|
@@ -9,16 +10,16 @@ export type MenuProps = {
|
|
|
9
10
|
accels?: string | string[];
|
|
10
11
|
onActivate?: () => void;
|
|
11
12
|
};
|
|
12
|
-
export declare class
|
|
13
|
-
private actionMap
|
|
13
|
+
export declare class MenuModel extends VirtualNode<MenuProps> {
|
|
14
|
+
private actionMap;
|
|
14
15
|
private actionPrefix;
|
|
15
|
-
private parent
|
|
16
|
+
private parent;
|
|
16
17
|
private menu;
|
|
17
18
|
private type;
|
|
18
|
-
private application
|
|
19
|
-
private action
|
|
19
|
+
private application;
|
|
20
|
+
private action;
|
|
20
21
|
private children;
|
|
21
|
-
constructor(type: MenuType, props: MenuProps, actionMap?: Gio.ActionMap, application?: Gtk.Application);
|
|
22
|
+
constructor(type: MenuType, props: MenuProps, rootContainer: Container, actionMap?: Gio.ActionMap, application?: Gtk.Application);
|
|
22
23
|
setActionMap(actionMap: Gio.ActionMap, prefix: string): void;
|
|
23
24
|
private getAccels;
|
|
24
25
|
private getActionName;
|
|
@@ -34,7 +35,7 @@ export declare class Menu extends VirtualNode<MenuProps> {
|
|
|
34
35
|
getMenu(): Gio.Menu;
|
|
35
36
|
private getAction;
|
|
36
37
|
removeFromParent(): void;
|
|
37
|
-
insertInParentBefore(before:
|
|
38
|
+
insertInParentBefore(before: MenuModel): void;
|
|
38
39
|
appendToParent(): void;
|
|
39
40
|
appendChild(child: Node): void;
|
|
40
41
|
insertBefore(child: Node, before: Node): void;
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isObjectEqual } from "@gtkx/ffi";
|
|
2
2
|
import * as Gio from "@gtkx/ffi/gio";
|
|
3
3
|
import { CommitPriority, scheduleAfterCommit } from "../../scheduler.js";
|
|
4
|
-
import { signalStore } from "../internal/signal-store.js";
|
|
5
4
|
import { VirtualNode } from "../virtual.js";
|
|
6
|
-
export class
|
|
7
|
-
actionMap;
|
|
5
|
+
export class MenuModel extends VirtualNode {
|
|
6
|
+
actionMap = null;
|
|
8
7
|
actionPrefix;
|
|
9
|
-
parent;
|
|
8
|
+
parent = null;
|
|
10
9
|
menu;
|
|
11
10
|
type;
|
|
12
|
-
application;
|
|
13
|
-
action;
|
|
11
|
+
application = null;
|
|
12
|
+
action = null;
|
|
14
13
|
children = [];
|
|
15
|
-
constructor(type, props, actionMap, application) {
|
|
16
|
-
super("", props, undefined);
|
|
14
|
+
constructor(type, props, rootContainer, actionMap, application) {
|
|
15
|
+
super("", props, undefined, rootContainer);
|
|
17
16
|
this.type = type;
|
|
18
|
-
this.actionMap = actionMap;
|
|
17
|
+
this.actionMap = actionMap ?? null;
|
|
19
18
|
this.actionPrefix = application ? "app" : "menu";
|
|
20
|
-
this.application = application;
|
|
19
|
+
this.application = application ?? null;
|
|
21
20
|
this.menu = new Gio.Menu();
|
|
22
21
|
}
|
|
23
22
|
setActionMap(actionMap, prefix) {
|
|
@@ -65,29 +64,25 @@ export class Menu extends VirtualNode {
|
|
|
65
64
|
return this.actionMap;
|
|
66
65
|
}
|
|
67
66
|
createAction() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
});
|
|
67
|
+
if (this.action) {
|
|
68
|
+
this.signalStore.set(this, this.action, "activate", null);
|
|
69
|
+
}
|
|
70
|
+
this.action = new Gio.SimpleAction(this.getId());
|
|
71
|
+
this.signalStore.set(this, this.action, "activate", this.getOnActivate());
|
|
72
|
+
this.getActionMap().addAction(this.action);
|
|
73
|
+
if (this.application && this.props.accels) {
|
|
74
|
+
this.application.setAccelsForAction(this.getActionName(), this.getAccels());
|
|
75
|
+
}
|
|
79
76
|
}
|
|
80
77
|
removeAction() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
});
|
|
78
|
+
if (this.application && this.props.accels) {
|
|
79
|
+
this.application.setAccelsForAction(this.getActionName(), []);
|
|
80
|
+
}
|
|
81
|
+
if (this.action) {
|
|
82
|
+
this.getActionMap().removeAction(this.getId());
|
|
83
|
+
this.signalStore.set(this, this.action, "activate", null);
|
|
84
|
+
this.action = null;
|
|
85
|
+
}
|
|
91
86
|
}
|
|
92
87
|
getPosition() {
|
|
93
88
|
return this.findPositionIn(this.getParent());
|
|
@@ -125,7 +120,7 @@ export class Menu extends VirtualNode {
|
|
|
125
120
|
if (!this.parent)
|
|
126
121
|
return;
|
|
127
122
|
const parent = this.parent;
|
|
128
|
-
this.parent =
|
|
123
|
+
this.parent = null;
|
|
129
124
|
scheduleAfterCommit(() => {
|
|
130
125
|
const position = this.findPositionIn(parent);
|
|
131
126
|
if (position >= 0) {
|
|
@@ -152,7 +147,7 @@ export class Menu extends VirtualNode {
|
|
|
152
147
|
parent.insertSubmenu(beforePosition, this.menu, this.props.label);
|
|
153
148
|
break;
|
|
154
149
|
}
|
|
155
|
-
});
|
|
150
|
+
}, CommitPriority.NORMAL);
|
|
156
151
|
}
|
|
157
152
|
appendToParent() {
|
|
158
153
|
if (this.type === "item" && this.actionMap) {
|
|
@@ -171,10 +166,10 @@ export class Menu extends VirtualNode {
|
|
|
171
166
|
parent.appendSubmenu(this.menu, this.props.label);
|
|
172
167
|
break;
|
|
173
168
|
}
|
|
174
|
-
});
|
|
169
|
+
}, CommitPriority.NORMAL);
|
|
175
170
|
}
|
|
176
171
|
appendChild(child) {
|
|
177
|
-
if (!(child instanceof
|
|
172
|
+
if (!(child instanceof MenuModel)) {
|
|
178
173
|
return;
|
|
179
174
|
}
|
|
180
175
|
this.children.push(child);
|
|
@@ -185,7 +180,7 @@ export class Menu extends VirtualNode {
|
|
|
185
180
|
child.appendToParent();
|
|
186
181
|
}
|
|
187
182
|
insertBefore(child, before) {
|
|
188
|
-
if (!(child instanceof
|
|
183
|
+
if (!(child instanceof MenuModel) || !(before instanceof MenuModel)) {
|
|
189
184
|
return;
|
|
190
185
|
}
|
|
191
186
|
const beforeIndex = this.children.indexOf(before);
|
|
@@ -202,7 +197,7 @@ export class Menu extends VirtualNode {
|
|
|
202
197
|
child.insertInParentBefore(before);
|
|
203
198
|
}
|
|
204
199
|
removeChild(child) {
|
|
205
|
-
if (!(child instanceof
|
|
200
|
+
if (!(child instanceof MenuModel)) {
|
|
206
201
|
return;
|
|
207
202
|
}
|
|
208
203
|
const index = this.children.indexOf(child);
|
|
@@ -237,7 +232,7 @@ export class Menu extends VirtualNode {
|
|
|
237
232
|
return;
|
|
238
233
|
}
|
|
239
234
|
if (oldProps.onActivate !== newProps.onActivate) {
|
|
240
|
-
signalStore.set(this, this.getAction(), "activate", newProps.onActivate);
|
|
235
|
+
this.signalStore.set(this, this.getAction(), "activate", newProps.onActivate);
|
|
241
236
|
}
|
|
242
237
|
if (oldProps.accels !== newProps.accels) {
|
|
243
238
|
if (this.application) {
|
|
@@ -251,18 +246,16 @@ export class Menu extends VirtualNode {
|
|
|
251
246
|
}
|
|
252
247
|
if (!oldProps || oldProps.label !== newProps.label) {
|
|
253
248
|
const parent = this.parent;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
parent.insertSubmenu(position, this.menu, this.props.label);
|
|
263
|
-
}
|
|
249
|
+
const position = this.findPositionIn(parent);
|
|
250
|
+
if (position >= 0) {
|
|
251
|
+
parent.remove(position);
|
|
252
|
+
if (this.type === "section") {
|
|
253
|
+
parent.insertSection(position, this.menu, this.props.label);
|
|
254
|
+
}
|
|
255
|
+
else if (this.type === "submenu") {
|
|
256
|
+
parent.insertSubmenu(position, this.menu, this.props.label);
|
|
264
257
|
}
|
|
265
|
-
}
|
|
258
|
+
}
|
|
266
259
|
}
|
|
267
260
|
}
|
|
268
261
|
unmount() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
2
|
import type { Node } from "../../node.js";
|
|
3
|
+
import type { Container } from "../../types.js";
|
|
3
4
|
import { TreeStore } from "../internal/tree-store.js";
|
|
4
5
|
import { VirtualNode } from "../virtual.js";
|
|
5
6
|
export type TreeListProps = {
|
|
@@ -8,27 +9,20 @@ export type TreeListProps = {
|
|
|
8
9
|
selected?: string[];
|
|
9
10
|
onSelectionChanged?: (ids: string[]) => void;
|
|
10
11
|
};
|
|
11
|
-
type SelectionModel = Gtk.NoSelection | Gtk.SingleSelection | Gtk.MultiSelection;
|
|
12
12
|
export declare class TreeList extends VirtualNode<TreeListProps> {
|
|
13
13
|
private store;
|
|
14
14
|
private treeListModel;
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
private pendingSelection?;
|
|
18
|
-
private selectionScheduled;
|
|
19
|
-
constructor(props?: TreeListProps);
|
|
20
|
-
private initSelectionHandler;
|
|
15
|
+
private selectionManager;
|
|
16
|
+
constructor(props: TreeListProps | undefined, rootContainer: Container);
|
|
21
17
|
private createChildModel;
|
|
22
18
|
getStore(): TreeStore;
|
|
23
19
|
getTreeListModel(): Gtk.TreeListModel;
|
|
24
|
-
getSelectionModel():
|
|
20
|
+
getSelectionModel(): Gtk.NoSelection | Gtk.SingleSelection | Gtk.MultiSelection;
|
|
25
21
|
appendChild(child: Node): void;
|
|
22
|
+
private addItemWithChildren;
|
|
26
23
|
insertBefore(child: Node, before: Node): void;
|
|
27
24
|
removeChild(child: Node): void;
|
|
28
25
|
updateProps(oldProps: TreeListProps | null, newProps: TreeListProps): void;
|
|
29
|
-
private createSelectionModel;
|
|
30
26
|
private getSelection;
|
|
31
|
-
private
|
|
32
|
-
private applySelection;
|
|
27
|
+
private resolveSelectionIndices;
|
|
33
28
|
}
|
|
34
|
-
export {};
|
|
@@ -1,33 +1,17 @@
|
|
|
1
1
|
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
-
import {
|
|
3
|
-
import { signalStore } from "../internal/signal-store.js";
|
|
2
|
+
import { SelectionModelManager } from "../internal/selection-model.js";
|
|
4
3
|
import { TreeStore } from "../internal/tree-store.js";
|
|
5
|
-
import { TreeListItemNode } from "../tree-list-item.js";
|
|
4
|
+
import { createTreeItemData, TreeListItemNode } from "../tree-list-item.js";
|
|
6
5
|
import { VirtualNode } from "../virtual.js";
|
|
7
6
|
export class TreeList extends VirtualNode {
|
|
8
7
|
store;
|
|
9
8
|
treeListModel;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
selectionScheduled = false;
|
|
14
|
-
constructor(props = {}) {
|
|
15
|
-
super("", {}, undefined);
|
|
9
|
+
selectionManager;
|
|
10
|
+
constructor(props = {}, rootContainer) {
|
|
11
|
+
super("", {}, undefined, rootContainer);
|
|
16
12
|
this.store = new TreeStore();
|
|
17
13
|
this.treeListModel = new Gtk.TreeListModel(this.store.getRootModel(), false, props.autoexpand ?? false, (item) => this.createChildModel(item));
|
|
18
|
-
this.
|
|
19
|
-
this.selectionModel.setModel(this.treeListModel);
|
|
20
|
-
this.initSelectionHandler(props.onSelectionChanged);
|
|
21
|
-
}
|
|
22
|
-
initSelectionHandler(onSelectionChanged) {
|
|
23
|
-
if (!onSelectionChanged) {
|
|
24
|
-
signalStore.set(this, this.selectionModel, "selection-changed", null);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
this.handleSelectionChange = () => {
|
|
28
|
-
onSelectionChanged(this.getSelection());
|
|
29
|
-
};
|
|
30
|
-
signalStore.set(this, this.selectionModel, "selection-changed", this.handleSelectionChange);
|
|
14
|
+
this.selectionManager = new SelectionModelManager({ owner: this, signalStore: this.signalStore, ...props }, this.treeListModel, () => this.getSelection(), (ids) => this.resolveSelectionIndices(ids), () => this.treeListModel.getNItems());
|
|
31
15
|
}
|
|
32
16
|
createChildModel(item) {
|
|
33
17
|
if (!(item instanceof Gtk.StringObject))
|
|
@@ -42,7 +26,7 @@ export class TreeList extends VirtualNode {
|
|
|
42
26
|
return this.treeListModel;
|
|
43
27
|
}
|
|
44
28
|
getSelectionModel() {
|
|
45
|
-
return this.
|
|
29
|
+
return this.selectionManager.getSelectionModel();
|
|
46
30
|
}
|
|
47
31
|
appendChild(child) {
|
|
48
32
|
if (!(child instanceof TreeListItemNode)) {
|
|
@@ -51,16 +35,17 @@ export class TreeList extends VirtualNode {
|
|
|
51
35
|
if (!child.props.id) {
|
|
52
36
|
throw new Error("Cannot append 'TreeListItem' to 'TreeList': missing required 'id' prop");
|
|
53
37
|
}
|
|
54
|
-
const id = child.props.id;
|
|
55
38
|
child.setStore(this.store);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
39
|
+
this.addItemWithChildren(child);
|
|
40
|
+
}
|
|
41
|
+
addItemWithChildren(node, parentId) {
|
|
42
|
+
const id = node.props.id;
|
|
43
|
+
if (id === undefined)
|
|
44
|
+
return;
|
|
45
|
+
this.store.addItem(id, createTreeItemData(node.props), parentId);
|
|
46
|
+
for (const child of node.getChildNodes()) {
|
|
47
|
+
this.addItemWithChildren(child, id);
|
|
48
|
+
}
|
|
64
49
|
}
|
|
65
50
|
insertBefore(child, before) {
|
|
66
51
|
if (!(child instanceof TreeListItemNode) || !(before instanceof TreeListItemNode)) {
|
|
@@ -75,14 +60,7 @@ export class TreeList extends VirtualNode {
|
|
|
75
60
|
const id = child.props.id;
|
|
76
61
|
const beforeId = before.props.id;
|
|
77
62
|
child.setStore(this.store);
|
|
78
|
-
|
|
79
|
-
this.store.insertItemBefore(id, beforeId, {
|
|
80
|
-
value: child.props.value,
|
|
81
|
-
indentForDepth: child.props.indentForDepth,
|
|
82
|
-
indentForIcon: child.props.indentForIcon,
|
|
83
|
-
hideExpander: child.props.hideExpander,
|
|
84
|
-
});
|
|
85
|
-
});
|
|
63
|
+
this.store.insertItemBefore(id, beforeId, createTreeItemData(child.props));
|
|
86
64
|
}
|
|
87
65
|
removeChild(child) {
|
|
88
66
|
if (!(child instanceof TreeListItemNode)) {
|
|
@@ -92,9 +70,7 @@ export class TreeList extends VirtualNode {
|
|
|
92
70
|
throw new Error("Cannot remove 'TreeListItem' from 'TreeList': missing required 'id' prop");
|
|
93
71
|
}
|
|
94
72
|
const id = child.props.id;
|
|
95
|
-
|
|
96
|
-
this.store.removeItem(id);
|
|
97
|
-
});
|
|
73
|
+
this.store.removeItem(id);
|
|
98
74
|
child.setStore(null);
|
|
99
75
|
}
|
|
100
76
|
updateProps(oldProps, newProps) {
|
|
@@ -102,36 +78,10 @@ export class TreeList extends VirtualNode {
|
|
|
102
78
|
if (!oldProps || oldProps.autoexpand !== newProps.autoexpand) {
|
|
103
79
|
this.treeListModel.setAutoexpand(newProps.autoexpand ?? false);
|
|
104
80
|
}
|
|
105
|
-
|
|
106
|
-
signalStore.set(this, this.selectionModel, "selection-changed", null);
|
|
107
|
-
this.selectionModel = this.createSelectionModel(newProps.selectionMode);
|
|
108
|
-
this.selectionModel.setModel(this.treeListModel);
|
|
109
|
-
this.initSelectionHandler(newProps.onSelectionChanged);
|
|
110
|
-
this.setSelection(newProps.selected);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (!oldProps || oldProps.onSelectionChanged !== newProps.onSelectionChanged) {
|
|
114
|
-
this.initSelectionHandler(newProps.onSelectionChanged);
|
|
115
|
-
}
|
|
116
|
-
if (!oldProps || oldProps.selected !== newProps.selected) {
|
|
117
|
-
this.setSelection(newProps.selected);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
createSelectionModel(mode) {
|
|
121
|
-
const selectionMode = mode ?? Gtk.SelectionMode.SINGLE;
|
|
122
|
-
if (selectionMode === Gtk.SelectionMode.NONE) {
|
|
123
|
-
return new Gtk.NoSelection(this.treeListModel);
|
|
124
|
-
}
|
|
125
|
-
if (selectionMode === Gtk.SelectionMode.MULTIPLE) {
|
|
126
|
-
return new Gtk.MultiSelection(this.treeListModel);
|
|
127
|
-
}
|
|
128
|
-
const selectionModel = new Gtk.SingleSelection(this.treeListModel);
|
|
129
|
-
selectionModel.setAutoselect(selectionMode === Gtk.SelectionMode.BROWSE);
|
|
130
|
-
selectionModel.setCanUnselect(selectionMode !== Gtk.SelectionMode.BROWSE);
|
|
131
|
-
return selectionModel;
|
|
81
|
+
this.selectionManager.update(oldProps ? { owner: this, signalStore: this.signalStore, ...oldProps } : null, { owner: this, signalStore: this.signalStore, ...newProps }, this.treeListModel);
|
|
132
82
|
}
|
|
133
83
|
getSelection() {
|
|
134
|
-
const selection = this.
|
|
84
|
+
const selection = this.selectionManager.getSelectionModel().getSelection();
|
|
135
85
|
const size = selection.getSize();
|
|
136
86
|
const ids = [];
|
|
137
87
|
for (let i = 0; i < size; i++) {
|
|
@@ -146,31 +96,18 @@ export class TreeList extends VirtualNode {
|
|
|
146
96
|
}
|
|
147
97
|
return ids;
|
|
148
98
|
}
|
|
149
|
-
|
|
150
|
-
this.pendingSelection = ids;
|
|
151
|
-
if (!this.selectionScheduled) {
|
|
152
|
-
this.selectionScheduled = true;
|
|
153
|
-
scheduleAfterCommit(() => this.applySelection(), CommitPriority.LOW);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
applySelection() {
|
|
157
|
-
this.selectionScheduled = false;
|
|
158
|
-
const ids = this.pendingSelection;
|
|
159
|
-
this.pendingSelection = undefined;
|
|
99
|
+
resolveSelectionIndices(ids) {
|
|
160
100
|
const nItems = this.treeListModel.getNItems();
|
|
161
101
|
const selected = new Gtk.Bitset();
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (item instanceof Gtk.StringObject && ids.includes(item.getString())) {
|
|
170
|
-
selected.add(i);
|
|
171
|
-
}
|
|
102
|
+
for (let i = 0; i < nItems; i++) {
|
|
103
|
+
const row = this.treeListModel.getRow(i);
|
|
104
|
+
if (!row)
|
|
105
|
+
continue;
|
|
106
|
+
const item = row.getItem();
|
|
107
|
+
if (item instanceof Gtk.StringObject && ids.includes(item.getString())) {
|
|
108
|
+
selected.add(i);
|
|
172
109
|
}
|
|
173
110
|
}
|
|
174
|
-
|
|
111
|
+
return selected;
|
|
175
112
|
}
|
|
176
113
|
}
|
|
@@ -6,6 +6,7 @@ export declare class NavigationPageNode extends SlotNode<Props> {
|
|
|
6
6
|
static priority: number;
|
|
7
7
|
static matches(type: string): boolean;
|
|
8
8
|
updateProps(oldProps: Props | null, newProps: Props): void;
|
|
9
|
+
protected applyOwnProps(oldProps: Props | null, newProps: Props): void;
|
|
9
10
|
protected onChildChange(oldChild: Adw.NavigationPage | null): void;
|
|
10
11
|
}
|
|
11
12
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Adw from "@gtkx/ffi/adw";
|
|
2
2
|
import { registerNodeClass } from "../registry.js";
|
|
3
|
+
import { hasChanged } from "./internal/utils.js";
|
|
3
4
|
import { SlotNode } from "./slot.js";
|
|
4
5
|
export class NavigationPageNode extends SlotNode {
|
|
5
6
|
static priority = 1;
|
|
@@ -8,17 +9,20 @@ export class NavigationPageNode extends SlotNode {
|
|
|
8
9
|
}
|
|
9
10
|
updateProps(oldProps, newProps) {
|
|
10
11
|
super.updateProps(oldProps, newProps);
|
|
12
|
+
this.applyOwnProps(oldProps, newProps);
|
|
13
|
+
}
|
|
14
|
+
applyOwnProps(oldProps, newProps) {
|
|
11
15
|
const child = this.child;
|
|
12
16
|
if (!(child instanceof Adw.NavigationPage)) {
|
|
13
17
|
return;
|
|
14
18
|
}
|
|
15
|
-
if (newProps
|
|
19
|
+
if (hasChanged(oldProps, newProps, "id") && newProps.id !== undefined) {
|
|
16
20
|
child.setTag(newProps.id);
|
|
17
21
|
}
|
|
18
|
-
if (newProps
|
|
22
|
+
if (hasChanged(oldProps, newProps, "title") && newProps.title !== undefined) {
|
|
19
23
|
child.setTitle(newProps.title);
|
|
20
24
|
}
|
|
21
|
-
if (newProps
|
|
25
|
+
if (hasChanged(oldProps, newProps, "canPop") && newProps.canPop !== undefined) {
|
|
22
26
|
child.setCanPop(newProps.canPop);
|
|
23
27
|
}
|
|
24
28
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import * as Adw from "@gtkx/ffi/adw";
|
|
2
2
|
import { registerNodeClass } from "../registry.js";
|
|
3
|
-
import { scheduleAfterCommit } from "../scheduler.js";
|
|
4
|
-
import {
|
|
5
|
-
import { filterProps, isContainerType } from "./internal/utils.js";
|
|
3
|
+
import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
|
|
4
|
+
import { filterProps, hasChanged, matchesAnyClass, primitiveArrayEqual } from "./internal/utils.js";
|
|
6
5
|
import { NavigationPageNode } from "./navigation-page.js";
|
|
7
6
|
import { SlotNode } from "./slot.js";
|
|
8
7
|
import { WidgetNode } from "./widget.js";
|
|
9
|
-
const
|
|
8
|
+
const OWN_PROPS = ["history", "onHistoryChanged"];
|
|
10
9
|
class NavigationViewNode extends WidgetNode {
|
|
11
10
|
static priority = 1;
|
|
12
11
|
static matches(_type, containerOrClass) {
|
|
13
|
-
return
|
|
12
|
+
return matchesAnyClass([Adw.NavigationView], containerOrClass);
|
|
14
13
|
}
|
|
15
14
|
appendChild(child) {
|
|
16
15
|
if (child instanceof NavigationPageNode) {
|
|
@@ -45,35 +44,38 @@ class NavigationViewNode extends WidgetNode {
|
|
|
45
44
|
throw new Error(`Cannot remove '${child.typeName}' from 'NavigationView': expected x.NavigationPage or Widget`);
|
|
46
45
|
}
|
|
47
46
|
updateProps(oldProps, newProps) {
|
|
47
|
+
super.updateProps(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
|
|
48
|
+
this.applyOwnProps(oldProps, newProps);
|
|
49
|
+
}
|
|
50
|
+
applyOwnProps(oldProps, newProps) {
|
|
48
51
|
const oldHistory = oldProps?.history;
|
|
49
52
|
const newHistory = newProps.history;
|
|
50
|
-
if (newHistory && !
|
|
53
|
+
if (newHistory && !primitiveArrayEqual(oldHistory, newHistory)) {
|
|
51
54
|
this.syncHistory(newHistory);
|
|
52
55
|
}
|
|
53
|
-
if (
|
|
56
|
+
if (hasChanged(oldProps, newProps, "onHistoryChanged")) {
|
|
54
57
|
const onHistoryChanged = newProps.onHistoryChanged;
|
|
55
58
|
if (onHistoryChanged) {
|
|
56
59
|
const handleHistoryChanged = () => {
|
|
57
60
|
const history = this.getCurrentHistory();
|
|
58
61
|
onHistoryChanged(history);
|
|
59
62
|
};
|
|
60
|
-
signalStore.set(this, this.container, "popped", handleHistoryChanged);
|
|
61
|
-
signalStore.set(this, this.container, "pushed", handleHistoryChanged);
|
|
62
|
-
signalStore.set(this, this.container, "replaced", handleHistoryChanged);
|
|
63
|
+
this.signalStore.set(this, this.container, "popped", handleHistoryChanged);
|
|
64
|
+
this.signalStore.set(this, this.container, "pushed", handleHistoryChanged);
|
|
65
|
+
this.signalStore.set(this, this.container, "replaced", handleHistoryChanged);
|
|
63
66
|
}
|
|
64
67
|
else {
|
|
65
|
-
signalStore.set(this, this.container, "popped", null);
|
|
66
|
-
signalStore.set(this, this.container, "pushed", null);
|
|
67
|
-
signalStore.set(this, this.container, "replaced", null);
|
|
68
|
+
this.signalStore.set(this, this.container, "popped", null);
|
|
69
|
+
this.signalStore.set(this, this.container, "pushed", null);
|
|
70
|
+
this.signalStore.set(this, this.container, "replaced", null);
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
|
-
super.updateProps(filterProps(oldProps ?? {}, PROPS), filterProps(newProps, PROPS));
|
|
71
73
|
}
|
|
72
74
|
syncHistory(history) {
|
|
73
75
|
const container = this.container;
|
|
74
76
|
scheduleAfterCommit(() => {
|
|
75
77
|
container.replaceWithTags(history, history.length);
|
|
76
|
-
});
|
|
78
|
+
}, CommitPriority.NORMAL);
|
|
77
79
|
}
|
|
78
80
|
getCurrentHistory() {
|
|
79
81
|
const stack = this.container.getNavigationStack();
|
|
@@ -88,18 +90,5 @@ class NavigationViewNode extends WidgetNode {
|
|
|
88
90
|
}
|
|
89
91
|
return history;
|
|
90
92
|
}
|
|
91
|
-
arraysEqual(a, b) {
|
|
92
|
-
if (a === b)
|
|
93
|
-
return true;
|
|
94
|
-
if (!a || !b)
|
|
95
|
-
return false;
|
|
96
|
-
if (a.length !== b.length)
|
|
97
|
-
return false;
|
|
98
|
-
for (let i = 0; i < a.length; i++) {
|
|
99
|
-
if (a[i] !== b[i])
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
93
|
}
|
|
105
94
|
registerNodeClass(NavigationViewNode);
|
|
@@ -4,10 +4,11 @@ import { SlotNode } from "./slot.js";
|
|
|
4
4
|
type Props = Partial<SlotProps>;
|
|
5
5
|
export declare class NotebookPageTabNode extends SlotNode<Props> {
|
|
6
6
|
static priority: number;
|
|
7
|
-
private notebook
|
|
8
|
-
private page
|
|
7
|
+
private notebook;
|
|
8
|
+
private page;
|
|
9
9
|
static matches(type: string): boolean;
|
|
10
|
-
setPage(notebook
|
|
10
|
+
setPage(notebook: Gtk.Notebook | null, page: Gtk.Widget | null): void;
|
|
11
|
+
updateProps(oldProps: Props | null, newProps: Props): void;
|
|
11
12
|
private getNotebook;
|
|
12
13
|
private getPage;
|
|
13
14
|
protected onChildChange(_oldChild: Gtk.Widget | null): void;
|
|
@@ -2,8 +2,8 @@ import { registerNodeClass } from "../registry.js";
|
|
|
2
2
|
import { SlotNode } from "./slot.js";
|
|
3
3
|
export class NotebookPageTabNode extends SlotNode {
|
|
4
4
|
static priority = 1;
|
|
5
|
-
notebook;
|
|
6
|
-
page;
|
|
5
|
+
notebook = null;
|
|
6
|
+
page = null;
|
|
7
7
|
static matches(type) {
|
|
8
8
|
return type === "NotebookPageTab";
|
|
9
9
|
}
|
|
@@ -12,6 +12,9 @@ export class NotebookPageTabNode extends SlotNode {
|
|
|
12
12
|
this.page = page;
|
|
13
13
|
this.setParent(notebook);
|
|
14
14
|
}
|
|
15
|
+
updateProps(oldProps, newProps) {
|
|
16
|
+
super.updateProps(oldProps, newProps);
|
|
17
|
+
}
|
|
15
18
|
getNotebook() {
|
|
16
19
|
if (!this.notebook) {
|
|
17
20
|
throw new Error("Expected Notebook reference to be set on NotebookPageTabNode");
|
|
@@ -5,18 +5,20 @@ import { SlotNode } from "./slot.js";
|
|
|
5
5
|
type Props = Partial<NotebookPageProps>;
|
|
6
6
|
export declare class NotebookPageNode extends SlotNode<Props> {
|
|
7
7
|
static priority: number;
|
|
8
|
-
position
|
|
9
|
-
private tabNode
|
|
8
|
+
position: number | null;
|
|
9
|
+
private tabNode;
|
|
10
10
|
static matches(type: string): boolean;
|
|
11
|
-
|
|
12
|
-
setPosition(position
|
|
11
|
+
setParent(parent: Gtk.Widget | null): void;
|
|
12
|
+
setPosition(position: number | null): void;
|
|
13
13
|
private getNotebook;
|
|
14
14
|
private updateTabNode;
|
|
15
15
|
appendChild(child: Node): void;
|
|
16
|
-
removeChild(child
|
|
16
|
+
removeChild(child: Node): void;
|
|
17
17
|
unmount(): void;
|
|
18
18
|
updateProps(oldProps: Props | null, newProps: Props): void;
|
|
19
|
+
protected applyOwnProps(oldProps: Props | null, newProps: Props): void;
|
|
19
20
|
private attachPage;
|
|
21
|
+
private applyPageProps;
|
|
20
22
|
private detachPage;
|
|
21
23
|
protected onChildChange(oldChild: Gtk.Widget | null): void;
|
|
22
24
|
}
|