@gtkx/react 0.9.3 → 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 +2325 -2219
- package/dist/generated/jsx.js +1339 -1574
- 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
|
@@ -1,256 +1,137 @@
|
|
|
1
|
-
import * as GObject from "@gtkx/ffi/gobject";
|
|
2
1
|
import * as Gtk from "@gtkx/ffi/gtk";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
import { registerNodeClass } from "../registry.js";
|
|
3
|
+
import { ColumnViewColumnNode } from "./column-view-column.js";
|
|
4
|
+
import { filterProps, isContainerType } from "./internal/utils.js";
|
|
5
|
+
import { ListItemNode } from "./list-item.js";
|
|
6
|
+
import { List } from "./models/list.js";
|
|
7
|
+
import { WidgetNode } from "./widget.js";
|
|
8
|
+
const PROP_NAMES = ["sortColumn", "sortOrder", "onSortChange"];
|
|
9
|
+
class ColumnViewNode extends WidgetNode {
|
|
10
|
+
static priority = 1;
|
|
11
|
+
handleSortChange;
|
|
12
|
+
list;
|
|
13
|
+
static matches(_type, containerOrClass) {
|
|
14
|
+
return isContainerType(Gtk.ColumnView, containerOrClass);
|
|
15
|
+
}
|
|
16
|
+
constructor(typeName, props, container, rootContainer) {
|
|
17
|
+
super(typeName, props, container, rootContainer);
|
|
18
|
+
this.list = new List(props.selectionMode);
|
|
19
|
+
}
|
|
20
|
+
mount() {
|
|
21
|
+
super.mount();
|
|
22
|
+
this.container.setModel(this.list.getSelectionModel());
|
|
19
23
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
...selectionState,
|
|
24
|
-
columns: [],
|
|
25
|
-
sortColumn: props.sortColumn ?? null,
|
|
26
|
-
sortOrder: props.sortOrder ?? Gtk.SortType.ASCENDING,
|
|
27
|
-
onSortChange: props.onSortChange ?? null,
|
|
28
|
-
sorterChangedHandlerId: null,
|
|
29
|
-
lastNotifiedColumn: null,
|
|
30
|
-
lastNotifiedOrder: Gtk.SortType.ASCENDING,
|
|
31
|
-
};
|
|
32
|
-
super.initialize(props);
|
|
33
|
-
this.applySelectionModel();
|
|
34
|
-
this.connectSorterChangedSignal();
|
|
35
|
-
}
|
|
36
|
-
connectSorterChangedSignal() {
|
|
37
|
-
const sorter = this.widget.getSorter();
|
|
38
|
-
if (!sorter || !this.state.onSortChange)
|
|
39
|
-
return;
|
|
40
|
-
this.state.sorterChangedHandlerId = sorter.connect("changed", () => {
|
|
41
|
-
this.notifySortChange();
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
disconnectSorterChangedSignal() {
|
|
45
|
-
if (this.state.sorterChangedHandlerId === null)
|
|
24
|
+
appendChild(child) {
|
|
25
|
+
if (child instanceof ListItemNode) {
|
|
26
|
+
this.list.appendChild(child);
|
|
46
27
|
return;
|
|
47
|
-
const sorter = this.widget.getSorter();
|
|
48
|
-
if (sorter) {
|
|
49
|
-
GObject.signalHandlerDisconnect(sorter, this.state.sorterChangedHandlerId);
|
|
50
28
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
notifySortChange() {
|
|
54
|
-
if (!this.state.onSortChange)
|
|
55
|
-
return;
|
|
56
|
-
const sorter = this.widget.getSorter();
|
|
57
|
-
if (!sorter)
|
|
58
|
-
return;
|
|
59
|
-
const column = sorter.getPrimarySortColumn();
|
|
60
|
-
const order = sorter.getPrimarySortOrder();
|
|
61
|
-
const columnId = column?.getId() ?? null;
|
|
62
|
-
if (columnId === this.state.lastNotifiedColumn && order === this.state.lastNotifiedOrder) {
|
|
63
|
-
return;
|
|
29
|
+
if (!(child instanceof ColumnViewColumnNode)) {
|
|
30
|
+
throw new Error(`Cannot append '${child.typeName}' to 'ColumnView': expected ColumnViewColumn`);
|
|
64
31
|
}
|
|
65
|
-
this.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
unmount() {
|
|
70
|
-
this.disconnectSorterChangedSignal();
|
|
71
|
-
this.cleanupSelection();
|
|
72
|
-
super.unmount();
|
|
73
|
-
}
|
|
74
|
-
appendChild(child) {
|
|
75
|
-
if (child instanceof ColumnViewColumnNode) {
|
|
76
|
-
child.parent = this;
|
|
77
|
-
this.addColumn(child);
|
|
78
|
-
return;
|
|
32
|
+
const existingColumn = this.findColumnInView(child.column);
|
|
33
|
+
if (existingColumn) {
|
|
34
|
+
this.container.removeColumn(existingColumn);
|
|
79
35
|
}
|
|
80
|
-
|
|
36
|
+
this.container.appendColumn(child.column);
|
|
37
|
+
child.setStore(this.list.getStore());
|
|
81
38
|
}
|
|
82
39
|
insertBefore(child, before) {
|
|
83
|
-
if (child instanceof
|
|
84
|
-
child
|
|
85
|
-
this.insertColumnBefore(child, before);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
super.insertBefore(child, before);
|
|
89
|
-
}
|
|
90
|
-
removeChild(child) {
|
|
91
|
-
if (child instanceof ColumnViewColumnNode) {
|
|
92
|
-
this.removeColumn(child);
|
|
93
|
-
child.unmount();
|
|
94
|
-
child.parent = null;
|
|
40
|
+
if (child instanceof ListItemNode) {
|
|
41
|
+
this.list.insertBefore(child, before);
|
|
95
42
|
return;
|
|
96
43
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
updateProps(oldProps, newProps) {
|
|
100
|
-
super.updateProps(oldProps, newProps);
|
|
101
|
-
const newSortColumn = newProps.sortColumn ?? null;
|
|
102
|
-
const newSortOrder = newProps.sortOrder ?? Gtk.SortType.ASCENDING;
|
|
103
|
-
const newOnSortChange = newProps.onSortChange ?? null;
|
|
104
|
-
if (oldProps.onSortChange !== newProps.onSortChange) {
|
|
105
|
-
const hadCallback = this.state.onSortChange !== null;
|
|
106
|
-
this.state.onSortChange = newOnSortChange;
|
|
107
|
-
const hasCallback = this.state.onSortChange !== null;
|
|
108
|
-
if (!hadCallback && hasCallback) {
|
|
109
|
-
this.connectSorterChangedSignal();
|
|
110
|
-
}
|
|
111
|
-
else if (hadCallback && !hasCallback) {
|
|
112
|
-
this.disconnectSorterChangedSignal();
|
|
113
|
-
}
|
|
44
|
+
if (!(child instanceof ColumnViewColumnNode)) {
|
|
45
|
+
throw new Error(`Cannot insert '${child.typeName}' to 'ColumnView': expected ColumnViewColumn`);
|
|
114
46
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
this.
|
|
118
|
-
this.applySortIndicator();
|
|
47
|
+
const existingColumn = this.findColumnInView(child.column);
|
|
48
|
+
if (existingColumn) {
|
|
49
|
+
this.container.removeColumn(existingColumn);
|
|
119
50
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (this.state.sortColumn === null) {
|
|
124
|
-
this.widget.sortByColumn(this.state.sortOrder);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const column = this.state.columns.find((c) => c.getId() === this.state.sortColumn);
|
|
128
|
-
if (column) {
|
|
129
|
-
this.widget.sortByColumn(this.state.sortOrder, column.getColumn());
|
|
51
|
+
if (before instanceof ColumnViewColumnNode) {
|
|
52
|
+
const beforeIndex = this.getColumnIndex(before.column);
|
|
53
|
+
this.container.insertColumn(beforeIndex, child.column);
|
|
130
54
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.state.columns.push(columnNode);
|
|
134
|
-
this.widget.appendColumn(columnNode.getColumn());
|
|
135
|
-
columnNode.setColumnView(this);
|
|
136
|
-
if (columnNode.getId() === this.state.sortColumn) {
|
|
137
|
-
this.applySortIndicator();
|
|
55
|
+
else {
|
|
56
|
+
this.container.appendColumn(child.column);
|
|
138
57
|
}
|
|
58
|
+
child.setStore(this.list.getStore());
|
|
139
59
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.addColumn(column);
|
|
60
|
+
removeChild(child) {
|
|
61
|
+
if (child instanceof ListItemNode) {
|
|
62
|
+
this.list.removeChild(child);
|
|
144
63
|
return;
|
|
145
64
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
column.setColumnView(this);
|
|
149
|
-
}
|
|
150
|
-
removeColumn(column) {
|
|
151
|
-
const index = this.state.columns.indexOf(column);
|
|
152
|
-
if (index !== -1) {
|
|
153
|
-
this.state.columns.splice(index, 1);
|
|
154
|
-
this.widget.removeColumn(column.getColumn());
|
|
155
|
-
column.setColumnView(null);
|
|
65
|
+
if (!(child instanceof ColumnViewColumnNode)) {
|
|
66
|
+
throw new Error(`Cannot remove '${child.typeName}' from 'ColumnView': expected ColumnViewColumn`);
|
|
156
67
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
static consumedPropNames = ["renderCell", "title", "expand", "resizable", "fixedWidth", "id", "sortable"];
|
|
161
|
-
static matches(type) {
|
|
162
|
-
return type === "ColumnView.Column";
|
|
163
|
-
}
|
|
164
|
-
isVirtual() {
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
columnView = null;
|
|
168
|
-
initialize(props) {
|
|
169
|
-
const factory = new Gtk.SignalListItemFactory();
|
|
170
|
-
const column = new Gtk.ColumnViewColumn(props.title, factory);
|
|
171
|
-
const columnId = props.id ?? undefined;
|
|
172
|
-
const sortable = props.sortable;
|
|
173
|
-
const sorter = sortable ? new StringSorter() : undefined;
|
|
174
|
-
this.state = {
|
|
175
|
-
column,
|
|
176
|
-
factory,
|
|
177
|
-
factoryHandlers: null,
|
|
178
|
-
renderCell: props.renderCell,
|
|
179
|
-
columnId,
|
|
180
|
-
listItemCache: new Map(),
|
|
181
|
-
sorter,
|
|
182
|
-
};
|
|
183
|
-
if (sorter) {
|
|
184
|
-
column.setSorter(sorter);
|
|
185
|
-
}
|
|
186
|
-
super.initialize(props);
|
|
187
|
-
if (columnId !== null) {
|
|
188
|
-
column.setId(columnId);
|
|
189
|
-
}
|
|
190
|
-
if (props.expand !== undefined) {
|
|
191
|
-
column.setExpand(props.expand);
|
|
192
|
-
}
|
|
193
|
-
if (props.resizable !== undefined) {
|
|
194
|
-
column.setResizable(props.resizable);
|
|
68
|
+
const existingColumn = this.findColumnInView(child.column);
|
|
69
|
+
if (existingColumn) {
|
|
70
|
+
this.container.removeColumn(existingColumn);
|
|
195
71
|
}
|
|
196
|
-
|
|
197
|
-
column.setFixedWidth(props.fixedWidth);
|
|
198
|
-
}
|
|
199
|
-
this.state.factoryHandlers = connectListItemFactorySignals({
|
|
200
|
-
factory,
|
|
201
|
-
listItemCache: this.state.listItemCache,
|
|
202
|
-
getRenderFn: () => this.state.renderCell,
|
|
203
|
-
getItemAtPosition: (position) => this.columnView?.getItems()[position] ?? null,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
getColumn() {
|
|
207
|
-
return this.state.column;
|
|
208
|
-
}
|
|
209
|
-
getId() {
|
|
210
|
-
return this.state.columnId;
|
|
211
|
-
}
|
|
212
|
-
setColumnView(columnView) {
|
|
213
|
-
this.columnView = columnView;
|
|
214
|
-
}
|
|
215
|
-
unmount() {
|
|
216
|
-
this.state.factoryHandlers?.disconnect();
|
|
217
|
-
super.unmount();
|
|
72
|
+
child.setStore(undefined);
|
|
218
73
|
}
|
|
219
74
|
updateProps(oldProps, newProps) {
|
|
220
|
-
if (oldProps.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
75
|
+
if (!oldProps || oldProps.onSortChange !== newProps.onSortChange) {
|
|
76
|
+
const sorter = this.container.getSorter();
|
|
77
|
+
const onSortChange = newProps.onSortChange;
|
|
78
|
+
if (sorter) {
|
|
79
|
+
this.handleSortChange = () => {
|
|
80
|
+
onSortChange?.(sorter.getPrimarySortColumn()?.getId() ?? null, sorter.getPrimarySortOrder());
|
|
81
|
+
};
|
|
82
|
+
this.signalStore.set(sorter, "changed", this.handleSortChange);
|
|
83
|
+
}
|
|
228
84
|
}
|
|
229
|
-
if (oldProps.
|
|
230
|
-
|
|
85
|
+
if (!oldProps || oldProps.sortColumn !== newProps.sortColumn || oldProps.sortOrder !== newProps.sortOrder) {
|
|
86
|
+
const sortColumn = newProps.sortColumn;
|
|
87
|
+
const sortOrder = newProps.sortOrder ?? Gtk.SortType.ASCENDING;
|
|
88
|
+
if (!sortColumn) {
|
|
89
|
+
this.container.sortByColumn(sortOrder);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.container.sortByColumn(sortOrder, this.getColumn(sortColumn));
|
|
93
|
+
}
|
|
231
94
|
}
|
|
232
|
-
|
|
233
|
-
|
|
95
|
+
this.list.updateProps(filterProps(oldProps ?? {}, PROP_NAMES), filterProps(newProps, PROP_NAMES));
|
|
96
|
+
super.updateProps(filterProps(oldProps ?? {}, PROP_NAMES), filterProps(newProps, PROP_NAMES));
|
|
97
|
+
}
|
|
98
|
+
getColumn(columnId) {
|
|
99
|
+
const columns = this.container.getColumns();
|
|
100
|
+
for (let i = 0; i < columns.getNItems(); i++) {
|
|
101
|
+
const column = columns.getObject(i);
|
|
102
|
+
if (column.getId() === columnId) {
|
|
103
|
+
return column;
|
|
104
|
+
}
|
|
234
105
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
106
|
+
throw new Error(`Unable to find column '${columnId}' in ColumnView`);
|
|
107
|
+
}
|
|
108
|
+
getColumnIndex(column) {
|
|
109
|
+
const index = this.findColumnIndex(column);
|
|
110
|
+
if (index === -1) {
|
|
111
|
+
throw new Error(`Unable to find column '${column.getId()}' in ColumnView`);
|
|
238
112
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
this.state.sorter = undefined;
|
|
113
|
+
return index;
|
|
114
|
+
}
|
|
115
|
+
findColumnIndex(column) {
|
|
116
|
+
const columns = this.container.getColumns();
|
|
117
|
+
for (let i = 0; i < columns.getNItems(); i++) {
|
|
118
|
+
const col = columns.getObject(i);
|
|
119
|
+
if (col.getId() === column.getId()) {
|
|
120
|
+
return i;
|
|
248
121
|
}
|
|
249
122
|
}
|
|
123
|
+
return -1;
|
|
250
124
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
125
|
+
findColumnInView(column) {
|
|
126
|
+
const columns = this.container.getColumns();
|
|
127
|
+
const targetId = column.getId();
|
|
128
|
+
for (let i = 0; i < columns.getNItems(); i++) {
|
|
129
|
+
const col = columns.getObject(i);
|
|
130
|
+
if (col.getId() === targetId) {
|
|
131
|
+
return col;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
255
135
|
}
|
|
256
136
|
}
|
|
137
|
+
registerNodeClass(ColumnViewNode);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { registerNodeClass } from "../registry.js";
|
|
2
|
+
import { SlotNode } from "./slot.js";
|
|
3
|
+
class FixedChildNode extends SlotNode {
|
|
4
|
+
static priority = 1;
|
|
5
|
+
static matches(type) {
|
|
6
|
+
return type === "FixedChild";
|
|
7
|
+
}
|
|
8
|
+
getFixed() {
|
|
9
|
+
if (!this.parent) {
|
|
10
|
+
throw new Error("Expected Fixed reference to be set on FixedChildNode");
|
|
11
|
+
}
|
|
12
|
+
return this.parent;
|
|
13
|
+
}
|
|
14
|
+
updateProps(oldProps, newProps) {
|
|
15
|
+
super.updateProps(oldProps, newProps);
|
|
16
|
+
if (!oldProps || oldProps.x !== newProps.x || oldProps.y !== newProps.y) {
|
|
17
|
+
if (this.parent && this.child) {
|
|
18
|
+
this.positionChild();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
positionChild() {
|
|
23
|
+
const fixed = this.getFixed();
|
|
24
|
+
const x = this.props.x ?? 0;
|
|
25
|
+
const y = this.props.y ?? 0;
|
|
26
|
+
if (this.child) {
|
|
27
|
+
const child = this.child;
|
|
28
|
+
const currentParent = child.getParent();
|
|
29
|
+
if (currentParent?.equals(fixed)) {
|
|
30
|
+
fixed.remove(child);
|
|
31
|
+
}
|
|
32
|
+
fixed.put(child, x, y);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
onChildChange(oldChild) {
|
|
36
|
+
const fixed = this.getFixed();
|
|
37
|
+
if (oldChild) {
|
|
38
|
+
fixed.remove(oldChild);
|
|
39
|
+
}
|
|
40
|
+
if (this.child) {
|
|
41
|
+
this.positionChild();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
registerNodeClass(FixedChildNode);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { registerNodeClass } from "../registry.js";
|
|
2
|
+
import { SlotNode } from "./slot.js";
|
|
3
|
+
class GridChildNode extends SlotNode {
|
|
4
|
+
static priority = 1;
|
|
5
|
+
static matches(type) {
|
|
6
|
+
return type === "GridChild";
|
|
7
|
+
}
|
|
8
|
+
updateProps(oldProps, newProps) {
|
|
9
|
+
super.updateProps(oldProps, newProps);
|
|
10
|
+
if (!oldProps ||
|
|
11
|
+
oldProps.column !== newProps.column ||
|
|
12
|
+
oldProps.row !== newProps.row ||
|
|
13
|
+
oldProps.columnSpan !== newProps.columnSpan ||
|
|
14
|
+
oldProps.rowSpan !== newProps.rowSpan) {
|
|
15
|
+
if (this.parent && this.child) {
|
|
16
|
+
this.attachChild();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
getGrid() {
|
|
21
|
+
if (!this.parent) {
|
|
22
|
+
throw new Error("Expected Grid reference to be set on GridChildNode");
|
|
23
|
+
}
|
|
24
|
+
return this.parent;
|
|
25
|
+
}
|
|
26
|
+
attachChild() {
|
|
27
|
+
const grid = this.getGrid();
|
|
28
|
+
const column = this.props.column ?? 0;
|
|
29
|
+
const row = this.props.row ?? 0;
|
|
30
|
+
const columnSpan = this.props.columnSpan ?? 1;
|
|
31
|
+
const rowSpan = this.props.rowSpan ?? 1;
|
|
32
|
+
const existingChild = grid.getChildAt(column, row);
|
|
33
|
+
if (existingChild && !existingChild.equals(this.child)) {
|
|
34
|
+
grid.remove(existingChild);
|
|
35
|
+
}
|
|
36
|
+
if (this.child) {
|
|
37
|
+
const currentParent = this.child.getParent();
|
|
38
|
+
if (currentParent?.equals(grid)) {
|
|
39
|
+
grid.remove(this.child);
|
|
40
|
+
}
|
|
41
|
+
grid.attach(this.child, column, row, columnSpan, rowSpan);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
onChildChange(oldChild) {
|
|
45
|
+
const grid = this.getGrid();
|
|
46
|
+
if (oldChild) {
|
|
47
|
+
grid.remove(oldChild);
|
|
48
|
+
}
|
|
49
|
+
if (this.child) {
|
|
50
|
+
this.attachChild();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
registerNodeClass(GridChildNode);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "./action-row-child.js";
|
|
2
|
+
import "./action-row.js";
|
|
3
|
+
import "./application.js";
|
|
4
|
+
import "./autowrapped.js";
|
|
5
|
+
import "./column-view-column.js";
|
|
6
|
+
import "./column-view.js";
|
|
7
|
+
import "./fixed-child.js";
|
|
8
|
+
import "./grid-child.js";
|
|
9
|
+
import "./list-item.js";
|
|
10
|
+
import "./list-view.js";
|
|
11
|
+
import "./menu.js";
|
|
12
|
+
import "./navigation-page.js";
|
|
13
|
+
import "./navigation-view.js";
|
|
14
|
+
import "./notebook-page-tab.js";
|
|
15
|
+
import "./notebook-page.js";
|
|
16
|
+
import "./notebook.js";
|
|
17
|
+
import "./overlay-child.js";
|
|
18
|
+
import "./pack-child.js";
|
|
19
|
+
import "./pack.js";
|
|
20
|
+
import "./popover-menu.js";
|
|
21
|
+
import "./simple-list-item.js";
|
|
22
|
+
import "./simple-list-view.js";
|
|
23
|
+
import "./slot.js";
|
|
24
|
+
import "./stack-page.js";
|
|
25
|
+
import "./stack.js";
|
|
26
|
+
import "./toast-overlay.js";
|
|
27
|
+
import "./toast.js";
|
|
28
|
+
import "./toolbar-child.js";
|
|
29
|
+
import "./toolbar.js";
|
|
30
|
+
import "./tree-list-item.js";
|
|
31
|
+
import "./tree-list-view.js";
|
|
32
|
+
import "./virtual.js";
|
|
33
|
+
import "./widget.js";
|
|
34
|
+
import "./window.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "./action-row-child.js";
|
|
2
|
+
import "./action-row.js";
|
|
3
|
+
import "./application.js";
|
|
4
|
+
import "./autowrapped.js";
|
|
5
|
+
import "./column-view-column.js";
|
|
6
|
+
import "./column-view.js";
|
|
7
|
+
import "./fixed-child.js";
|
|
8
|
+
import "./grid-child.js";
|
|
9
|
+
import "./list-item.js";
|
|
10
|
+
import "./list-view.js";
|
|
11
|
+
import "./menu.js";
|
|
12
|
+
import "./navigation-page.js";
|
|
13
|
+
import "./navigation-view.js";
|
|
14
|
+
import "./notebook-page-tab.js";
|
|
15
|
+
import "./notebook-page.js";
|
|
16
|
+
import "./notebook.js";
|
|
17
|
+
import "./overlay-child.js";
|
|
18
|
+
import "./pack-child.js";
|
|
19
|
+
import "./pack.js";
|
|
20
|
+
import "./popover-menu.js";
|
|
21
|
+
import "./simple-list-item.js";
|
|
22
|
+
import "./simple-list-view.js";
|
|
23
|
+
import "./slot.js";
|
|
24
|
+
import "./stack-page.js";
|
|
25
|
+
import "./stack.js";
|
|
26
|
+
import "./toast-overlay.js";
|
|
27
|
+
import "./toast.js";
|
|
28
|
+
import "./toolbar-child.js";
|
|
29
|
+
import "./toolbar.js";
|
|
30
|
+
import "./tree-list-item.js";
|
|
31
|
+
import "./tree-list-view.js";
|
|
32
|
+
import "./virtual.js";
|
|
33
|
+
import "./widget.js";
|
|
34
|
+
import "./window.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { ListStore } from "./list-store.js";
|
|
4
|
+
import type { SignalStore } from "./signal-store.js";
|
|
5
|
+
export type RenderItemFn<T> = (item: T | null) => ReactNode;
|
|
6
|
+
export declare class ListItemRenderer {
|
|
7
|
+
private factory;
|
|
8
|
+
private store?;
|
|
9
|
+
private fiberRoots;
|
|
10
|
+
private renderFn?;
|
|
11
|
+
private signalStore;
|
|
12
|
+
constructor(signalStore: SignalStore);
|
|
13
|
+
getFactory(): Gtk.SignalListItemFactory;
|
|
14
|
+
setRenderFn(renderFn?: RenderItemFn<unknown>): void;
|
|
15
|
+
setStore(store?: ListStore): void;
|
|
16
|
+
private getStore;
|
|
17
|
+
private initialize;
|
|
18
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getObjectId } from "@gtkx/ffi";
|
|
2
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
3
|
+
import { createFiberRoot } from "../../fiber-root.js";
|
|
4
|
+
import { reconciler } from "../../reconciler.js";
|
|
5
|
+
export class ListItemRenderer {
|
|
6
|
+
factory;
|
|
7
|
+
store;
|
|
8
|
+
fiberRoots = new Map();
|
|
9
|
+
renderFn = () => null;
|
|
10
|
+
signalStore;
|
|
11
|
+
constructor(signalStore) {
|
|
12
|
+
this.signalStore = signalStore;
|
|
13
|
+
this.factory = new Gtk.SignalListItemFactory();
|
|
14
|
+
this.initialize();
|
|
15
|
+
}
|
|
16
|
+
getFactory() {
|
|
17
|
+
return this.factory;
|
|
18
|
+
}
|
|
19
|
+
setRenderFn(renderFn) {
|
|
20
|
+
this.renderFn = renderFn;
|
|
21
|
+
}
|
|
22
|
+
setStore(store) {
|
|
23
|
+
this.store = store;
|
|
24
|
+
}
|
|
25
|
+
getStore() {
|
|
26
|
+
if (!this.store) {
|
|
27
|
+
throw new Error("Expected list store to be set on ListItemRenderer");
|
|
28
|
+
}
|
|
29
|
+
return this.store;
|
|
30
|
+
}
|
|
31
|
+
initialize() {
|
|
32
|
+
this.signalStore.set(this.factory, "setup", (_self, listItem) => {
|
|
33
|
+
const ptr = getObjectId(listItem.id);
|
|
34
|
+
const box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
|
|
35
|
+
listItem.setChild(box);
|
|
36
|
+
const fiberRoot = createFiberRoot(box);
|
|
37
|
+
this.fiberRoots.set(ptr, fiberRoot);
|
|
38
|
+
const element = this.renderFn?.(null);
|
|
39
|
+
reconciler.getInstance().updateContainer(element, fiberRoot, null, () => { });
|
|
40
|
+
});
|
|
41
|
+
this.signalStore.set(this.factory, "bind", (_self, listItem) => {
|
|
42
|
+
const ptr = getObjectId(listItem.id);
|
|
43
|
+
const fiberRoot = this.fiberRoots.get(ptr);
|
|
44
|
+
if (!fiberRoot)
|
|
45
|
+
return;
|
|
46
|
+
const id = listItem.getItem();
|
|
47
|
+
const item = this.getStore().getItem(id.getString());
|
|
48
|
+
const element = this.renderFn?.(item);
|
|
49
|
+
reconciler.getInstance().updateContainer(element, fiberRoot, null, () => { });
|
|
50
|
+
});
|
|
51
|
+
this.signalStore.set(this.factory, "unbind", (_self, listItem) => {
|
|
52
|
+
const ptr = getObjectId(listItem.id);
|
|
53
|
+
const fiberRoot = this.fiberRoots.get(ptr);
|
|
54
|
+
if (!fiberRoot)
|
|
55
|
+
return;
|
|
56
|
+
reconciler.getInstance().updateContainer(null, fiberRoot, null, () => { });
|
|
57
|
+
});
|
|
58
|
+
this.signalStore.set(this.factory, "teardown", (_self, listItem) => {
|
|
59
|
+
const ptr = getObjectId(listItem.id);
|
|
60
|
+
const fiberRoot = this.fiberRoots.get(ptr);
|
|
61
|
+
if (fiberRoot) {
|
|
62
|
+
reconciler.getInstance().updateContainer(null, fiberRoot, null, () => { });
|
|
63
|
+
queueMicrotask(() => this.fiberRoots.delete(ptr));
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
export declare class ListStore {
|
|
3
|
+
private items;
|
|
4
|
+
private model;
|
|
5
|
+
private newSortedIds;
|
|
6
|
+
private sortedIds;
|
|
7
|
+
private shouldSync;
|
|
8
|
+
addItem(id: string, item: unknown): void;
|
|
9
|
+
removeItem(id: string): void;
|
|
10
|
+
insertItemBefore(id: string, beforeId: string, item: unknown): void;
|
|
11
|
+
updateItem(id: string, item: unknown): void;
|
|
12
|
+
getItem(id: string): unknown;
|
|
13
|
+
getModel(): Gtk.StringList;
|
|
14
|
+
private scheduleSync;
|
|
15
|
+
private sync;
|
|
16
|
+
}
|