@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.
Files changed (182) hide show
  1. package/README.md +55 -67
  2. package/dist/errors.d.ts +3 -3
  3. package/dist/errors.js +8 -8
  4. package/dist/factory.d.ts +3 -5
  5. package/dist/factory.js +18 -71
  6. package/dist/fiber-root.d.ts +1 -1
  7. package/dist/fiber-root.js +1 -2
  8. package/dist/generated/internal.d.ts +3 -6
  9. package/dist/generated/internal.js +10386 -13577
  10. package/dist/generated/jsx.d.ts +914 -808
  11. package/dist/generated/jsx.js +123 -358
  12. package/dist/generated/registry.d.ts +4 -0
  13. package/dist/generated/registry.js +13 -0
  14. package/dist/host-config.d.ts +7 -4
  15. package/dist/host-config.js +53 -18
  16. package/dist/index.d.ts +2 -22
  17. package/dist/index.js +2 -40
  18. package/dist/jsx.d.ts +719 -0
  19. package/dist/jsx.js +392 -0
  20. package/dist/node.d.ts +15 -32
  21. package/dist/node.js +20 -240
  22. package/dist/nodes/action-row-child.d.ts +21 -0
  23. package/dist/nodes/action-row-child.js +69 -0
  24. package/dist/nodes/action-row.js +33 -0
  25. package/dist/nodes/application.d.ts +1 -0
  26. package/dist/nodes/application.js +38 -0
  27. package/dist/nodes/autowrapped.d.ts +1 -0
  28. package/dist/nodes/autowrapped.js +109 -0
  29. package/dist/nodes/column-view-column.d.ts +16 -0
  30. package/dist/nodes/column-view-column.js +54 -0
  31. package/dist/nodes/column-view.d.ts +0 -59
  32. package/dist/nodes/column-view.js +107 -226
  33. package/dist/nodes/fixed-child.d.ts +1 -0
  34. package/dist/nodes/fixed-child.js +45 -0
  35. package/dist/nodes/grid-child.d.ts +1 -0
  36. package/dist/nodes/grid-child.js +54 -0
  37. package/dist/nodes/index.d.ts +34 -0
  38. package/dist/nodes/index.js +34 -0
  39. package/dist/nodes/internal/list-item-renderer.d.ts +18 -0
  40. package/dist/nodes/internal/list-item-renderer.js +67 -0
  41. package/dist/nodes/internal/list-store.d.ts +16 -0
  42. package/dist/nodes/internal/list-store.js +69 -0
  43. package/dist/nodes/internal/predicates.d.ts +26 -0
  44. package/dist/nodes/internal/predicates.js +36 -0
  45. package/dist/nodes/internal/signal-store.d.ts +9 -0
  46. package/dist/nodes/internal/signal-store.js +54 -0
  47. package/dist/nodes/internal/simple-list-store.d.ts +14 -0
  48. package/dist/nodes/internal/simple-list-store.js +60 -0
  49. package/dist/nodes/internal/tree-list-item-renderer.d.ts +18 -0
  50. package/dist/nodes/internal/tree-list-item-renderer.js +90 -0
  51. package/dist/nodes/internal/tree-store.d.ts +28 -0
  52. package/dist/nodes/internal/tree-store.js +153 -0
  53. package/dist/nodes/internal/utils.d.ts +3 -0
  54. package/dist/nodes/internal/utils.js +20 -0
  55. package/dist/nodes/list-item.d.ts +12 -0
  56. package/dist/nodes/list-item.js +24 -0
  57. package/dist/nodes/list-view.d.ts +0 -22
  58. package/dist/nodes/list-view.js +45 -38
  59. package/dist/nodes/menu.d.ts +6 -106
  60. package/dist/nodes/menu.js +16 -268
  61. package/dist/nodes/models/list.d.ts +24 -0
  62. package/dist/nodes/models/list.js +102 -0
  63. package/dist/nodes/models/menu.d.ts +45 -0
  64. package/dist/nodes/models/menu.js +265 -0
  65. package/dist/nodes/models/tree-list.d.ts +28 -0
  66. package/dist/nodes/models/tree-list.js +141 -0
  67. package/dist/nodes/navigation-page.d.ts +21 -0
  68. package/dist/nodes/navigation-page.js +95 -0
  69. package/dist/nodes/navigation-view.d.ts +1 -0
  70. package/dist/nodes/navigation-view.js +29 -0
  71. package/dist/nodes/notebook-page-tab.d.ts +15 -0
  72. package/dist/nodes/notebook-page-tab.js +42 -0
  73. package/dist/nodes/notebook-page.d.ts +23 -0
  74. package/dist/nodes/notebook-page.js +106 -0
  75. package/dist/nodes/notebook.d.ts +0 -32
  76. package/dist/nodes/notebook.js +20 -113
  77. package/dist/nodes/overlay-child.d.ts +1 -0
  78. package/dist/nodes/overlay-child.js +30 -0
  79. package/dist/nodes/pack-child.d.ts +21 -0
  80. package/dist/nodes/pack-child.js +68 -0
  81. package/dist/nodes/pack.d.ts +1 -0
  82. package/dist/nodes/pack.js +33 -0
  83. package/dist/nodes/popover-menu.d.ts +1 -0
  84. package/dist/nodes/popover-menu.js +58 -0
  85. package/dist/nodes/simple-list-item.d.ts +9 -0
  86. package/dist/nodes/simple-list-item.js +9 -0
  87. package/dist/nodes/simple-list-view.d.ts +1 -0
  88. package/dist/nodes/simple-list-view.js +75 -0
  89. package/dist/nodes/slot.d.ts +18 -10
  90. package/dist/nodes/slot.js +83 -51
  91. package/dist/nodes/stack-page.d.ts +1 -0
  92. package/dist/nodes/stack-page.js +80 -0
  93. package/dist/nodes/stack.d.ts +1 -22
  94. package/dist/nodes/stack.js +21 -60
  95. package/dist/nodes/toast-overlay.d.ts +1 -0
  96. package/dist/nodes/toast-overlay.js +35 -0
  97. package/dist/nodes/toast.d.ts +17 -0
  98. package/dist/nodes/toast.js +77 -0
  99. package/dist/nodes/toolbar-child.d.ts +9 -0
  100. package/dist/nodes/toolbar-child.js +33 -0
  101. package/dist/nodes/toolbar.d.ts +1 -0
  102. package/dist/nodes/toolbar.js +42 -0
  103. package/dist/nodes/tree-list-item.d.ts +20 -0
  104. package/dist/nodes/tree-list-item.js +102 -0
  105. package/dist/nodes/tree-list-view.d.ts +1 -0
  106. package/dist/nodes/tree-list-view.js +57 -0
  107. package/dist/nodes/virtual.d.ts +13 -0
  108. package/dist/nodes/virtual.js +21 -0
  109. package/dist/nodes/widget.d.ts +17 -3
  110. package/dist/nodes/widget.js +258 -2
  111. package/dist/nodes/window.d.ts +1 -12
  112. package/dist/nodes/window.js +66 -27
  113. package/dist/portal.d.ts +18 -13
  114. package/dist/portal.js +17 -14
  115. package/dist/reconciler.d.ts +0 -4
  116. package/dist/reconciler.js +1 -9
  117. package/dist/registry.d.ts +8 -0
  118. package/dist/registry.js +5 -0
  119. package/dist/render.d.ts +108 -12
  120. package/dist/render.js +140 -16
  121. package/dist/scheduler.d.ts +4 -0
  122. package/dist/scheduler.js +10 -0
  123. package/dist/types.d.ts +3 -136
  124. package/package.json +6 -6
  125. package/dist/batch.d.ts +0 -5
  126. package/dist/batch.js +0 -31
  127. package/dist/codegen/jsx-generator.d.ts +0 -56
  128. package/dist/codegen/jsx-generator.js +0 -959
  129. package/dist/containers.d.ts +0 -58
  130. package/dist/nodes/about-dialog.d.ts +0 -8
  131. package/dist/nodes/about-dialog.js +0 -16
  132. package/dist/nodes/action-bar.d.ts +0 -5
  133. package/dist/nodes/action-bar.js +0 -6
  134. package/dist/nodes/combo-row.d.ts +0 -5
  135. package/dist/nodes/combo-row.js +0 -6
  136. package/dist/nodes/drop-down.d.ts +0 -9
  137. package/dist/nodes/drop-down.js +0 -12
  138. package/dist/nodes/flow-box.d.ts +0 -10
  139. package/dist/nodes/flow-box.js +0 -41
  140. package/dist/nodes/grid.d.ts +0 -30
  141. package/dist/nodes/grid.js +0 -84
  142. package/dist/nodes/header-bar.d.ts +0 -43
  143. package/dist/nodes/header-bar.js +0 -116
  144. package/dist/nodes/indexed-child-container.d.ts +0 -16
  145. package/dist/nodes/indexed-child-container.js +0 -22
  146. package/dist/nodes/list-box.d.ts +0 -10
  147. package/dist/nodes/list-box.js +0 -48
  148. package/dist/nodes/list-item-factory.d.ts +0 -19
  149. package/dist/nodes/list-item-factory.js +0 -58
  150. package/dist/nodes/overlay.d.ts +0 -11
  151. package/dist/nodes/overlay.js +0 -50
  152. package/dist/nodes/paged-stack.d.ts +0 -31
  153. package/dist/nodes/paged-stack.js +0 -95
  154. package/dist/nodes/root.d.ts +0 -8
  155. package/dist/nodes/root.js +0 -13
  156. package/dist/nodes/selectable-list.d.ts +0 -45
  157. package/dist/nodes/selectable-list.js +0 -260
  158. package/dist/nodes/stack-page-props.d.ts +0 -11
  159. package/dist/nodes/stack-page-props.js +0 -23
  160. package/dist/nodes/string-list-container.d.ts +0 -34
  161. package/dist/nodes/string-list-container.js +0 -118
  162. package/dist/nodes/string-list-item.d.ts +0 -19
  163. package/dist/nodes/string-list-item.js +0 -50
  164. package/dist/nodes/string-list-store.d.ts +0 -13
  165. package/dist/nodes/string-list-store.js +0 -44
  166. package/dist/nodes/text-view.d.ts +0 -8
  167. package/dist/nodes/text-view.js +0 -16
  168. package/dist/nodes/toggle-button.d.ts +0 -14
  169. package/dist/nodes/toggle-button.js +0 -39
  170. package/dist/nodes/toolbar-view.d.ts +0 -14
  171. package/dist/nodes/toolbar-view.js +0 -78
  172. package/dist/nodes/view-stack.d.ts +0 -9
  173. package/dist/nodes/view-stack.js +0 -28
  174. package/dist/nodes/virtual-item.d.ts +0 -19
  175. package/dist/nodes/virtual-item.js +0 -48
  176. package/dist/nodes/virtual-slot.d.ts +0 -25
  177. package/dist/nodes/virtual-slot.js +0 -57
  178. package/dist/predicates.d.ts +0 -29
  179. package/dist/predicates.js +0 -37
  180. package/dist/props.d.ts +0 -7
  181. package/dist/props.js +0 -12
  182. /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 { StringSorter } from "@gtkx/ffi/gtk";
4
- import { Node } from "../node.js";
5
- import { connectListItemFactorySignals } from "./list-item-factory.js";
6
- import { SelectableListNode } from "./selectable-list.js";
7
- import { VirtualItemNode } from "./virtual-item.js";
8
- export class ColumnViewNode extends SelectableListNode {
9
- static consumedPropNames = [
10
- "sortColumn",
11
- "sortOrder",
12
- "onSortChange",
13
- "selected",
14
- "onSelectionChanged",
15
- "selectionMode",
16
- ];
17
- static matches(type) {
18
- return type === "ColumnView.Root";
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
- initialize(props) {
21
- const selectionState = this.initializeSelectionState(props);
22
- this.state = {
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
- this.state.sorterChangedHandlerId = null;
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.state.lastNotifiedColumn = columnId;
66
- this.state.lastNotifiedOrder = order;
67
- this.state.onSortChange(columnId, order);
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
- super.appendChild(child);
36
+ this.container.appendColumn(child.column);
37
+ child.setStore(this.list.getStore());
81
38
  }
82
39
  insertBefore(child, before) {
83
- if (child instanceof ColumnViewColumnNode && before instanceof ColumnViewColumnNode) {
84
- child.parent = this;
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
- super.removeChild(child);
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
- if (oldProps.sortColumn !== newProps.sortColumn || oldProps.sortOrder !== newProps.sortOrder) {
116
- this.state.sortColumn = newSortColumn;
117
- this.state.sortOrder = newSortOrder;
118
- this.applySortIndicator();
47
+ const existingColumn = this.findColumnInView(child.column);
48
+ if (existingColumn) {
49
+ this.container.removeColumn(existingColumn);
119
50
  }
120
- this.updateSelectionProps(oldProps, newProps);
121
- }
122
- applySortIndicator() {
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
- addColumn(columnNode) {
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
- insertColumnBefore(column, before) {
141
- const beforeIndex = this.state.columns.indexOf(before);
142
- if (beforeIndex === -1) {
143
- this.addColumn(column);
60
+ removeChild(child) {
61
+ if (child instanceof ListItemNode) {
62
+ this.list.removeChild(child);
144
63
  return;
145
64
  }
146
- this.state.columns.splice(beforeIndex, 0, column);
147
- this.widget.insertColumn(beforeIndex, column.getColumn());
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
- export class ColumnViewColumnNode extends Node {
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
- if (props.fixedWidth !== undefined) {
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.renderCell !== newProps.renderCell) {
221
- this.state.renderCell = newProps.renderCell;
222
- }
223
- if (oldProps.title !== newProps.title) {
224
- this.state.column.setTitle(newProps.title);
225
- }
226
- if (oldProps.expand !== newProps.expand) {
227
- this.state.column.setExpand(newProps.expand);
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.resizable !== newProps.resizable) {
230
- this.state.column.setResizable(newProps.resizable);
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
- if (oldProps.fixedWidth !== newProps.fixedWidth) {
233
- this.state.column.setFixedWidth(newProps.fixedWidth);
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
- if (oldProps.id !== newProps.id) {
236
- this.state.columnId = newProps.id ?? undefined;
237
- this.state.column.setId(this.state.columnId);
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
- if (oldProps.sortable !== newProps.sortable) {
240
- const sortable = newProps.sortable;
241
- if (sortable && !this.state.sorter) {
242
- this.state.sorter = new StringSorter();
243
- this.state.column.setSorter(this.state.sorter);
244
- }
245
- else if (!sortable && this.state.sorter) {
246
- this.state.column.setSorter(undefined);
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
- export class ColumnViewItemNode extends VirtualItemNode {
253
- static matches(type) {
254
- return type === "ColumnView.Item";
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
+ }