@gtkx/react 0.17.2 → 0.18.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 (194) hide show
  1. package/README.md +7 -7
  2. package/dist/factory.d.ts +0 -1
  3. package/dist/factory.js +21 -8
  4. package/dist/generated/internal.d.ts +4 -51
  5. package/dist/generated/internal.js +626 -412
  6. package/dist/generated/jsx.d.ts +453 -958
  7. package/dist/host-config.d.ts +1 -1
  8. package/dist/host-config.js +18 -23
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/jsx.d.ts +579 -302
  12. package/dist/jsx.js +37 -179
  13. package/dist/metadata.d.ts +3 -0
  14. package/dist/metadata.js +26 -0
  15. package/dist/node.d.ts +20 -12
  16. package/dist/node.js +72 -17
  17. package/dist/nodes/adjustable.d.ts +3 -16
  18. package/dist/nodes/adjustable.js +5 -22
  19. package/dist/nodes/alert-dialog-response.d.ts +14 -1
  20. package/dist/nodes/alert-dialog-response.js +36 -62
  21. package/dist/nodes/animation.d.ts +37 -1
  22. package/dist/nodes/animation.js +162 -105
  23. package/dist/nodes/application.d.ts +11 -1
  24. package/dist/nodes/application.js +17 -38
  25. package/dist/nodes/calendar.d.ts +13 -0
  26. package/dist/nodes/calendar.js +10 -16
  27. package/dist/nodes/color-dialog-button.d.ts +13 -0
  28. package/dist/nodes/color-dialog-button.js +10 -38
  29. package/dist/nodes/column-view-column.d.ts +13 -11
  30. package/dist/nodes/column-view-column.js +27 -23
  31. package/dist/nodes/column-view.d.ts +31 -0
  32. package/dist/nodes/column-view.js +44 -44
  33. package/dist/nodes/container-slot.d.ts +15 -0
  34. package/dist/nodes/container-slot.js +68 -0
  35. package/dist/nodes/dialog.d.ts +6 -8
  36. package/dist/nodes/dialog.js +12 -13
  37. package/dist/nodes/drawing-area.d.ts +12 -0
  38. package/dist/nodes/drawing-area.js +24 -24
  39. package/dist/nodes/drop-down.d.ts +22 -0
  40. package/dist/nodes/drop-down.js +72 -0
  41. package/dist/nodes/event-controller.d.ts +8 -17
  42. package/dist/nodes/event-controller.js +20 -42
  43. package/dist/nodes/fixed-child.d.ts +18 -1
  44. package/dist/nodes/fixed-child.js +52 -36
  45. package/dist/nodes/font-dialog-button.d.ts +13 -0
  46. package/dist/nodes/font-dialog-button.js +12 -35
  47. package/dist/nodes/grid-child.d.ts +17 -1
  48. package/dist/nodes/grid-child.js +57 -37
  49. package/dist/nodes/grid-view.d.ts +24 -0
  50. package/dist/nodes/grid-view.js +73 -0
  51. package/dist/nodes/internal/base-item-renderer.d.ts +7 -9
  52. package/dist/nodes/internal/base-item-renderer.js +15 -18
  53. package/dist/nodes/internal/grid-item-renderer.d.ts +17 -0
  54. package/dist/nodes/internal/grid-item-renderer.js +59 -0
  55. package/dist/nodes/internal/list-item-renderer.d.ts +14 -9
  56. package/dist/nodes/internal/list-item-renderer.js +96 -35
  57. package/dist/nodes/internal/list-store.d.ts +5 -0
  58. package/dist/nodes/internal/list-store.js +39 -9
  59. package/dist/nodes/internal/predicates.d.ts +4 -19
  60. package/dist/nodes/internal/predicates.js +1 -20
  61. package/dist/nodes/internal/props.d.ts +5 -0
  62. package/dist/nodes/internal/props.js +42 -0
  63. package/dist/nodes/internal/{selection-model.d.ts → selection-model-controller.d.ts} +4 -9
  64. package/dist/nodes/internal/{selection-model.js → selection-model-controller.js} +6 -15
  65. package/dist/nodes/internal/signal-store.js +12 -5
  66. package/dist/nodes/internal/simple-list-store.d.ts +5 -0
  67. package/dist/nodes/internal/simple-list-store.js +42 -13
  68. package/dist/nodes/internal/text-buffer-controller.d.ts +4 -12
  69. package/dist/nodes/internal/text-buffer-controller.js +32 -33
  70. package/dist/nodes/internal/tree-store.d.ts +7 -0
  71. package/dist/nodes/internal/tree-store.js +75 -18
  72. package/dist/nodes/internal/widget.d.ts +7 -0
  73. package/dist/nodes/internal/widget.js +68 -0
  74. package/dist/nodes/level-bar.d.ts +10 -0
  75. package/dist/nodes/level-bar.js +11 -22
  76. package/dist/nodes/list-item.d.ts +17 -9
  77. package/dist/nodes/list-item.js +67 -12
  78. package/dist/nodes/list-view.d.ts +23 -0
  79. package/dist/nodes/list-view.js +27 -31
  80. package/dist/nodes/menu.d.ts +2 -4
  81. package/dist/nodes/menu.js +0 -6
  82. package/dist/nodes/models/grid.d.ts +27 -0
  83. package/dist/nodes/models/grid.js +68 -0
  84. package/dist/nodes/models/list.d.ts +15 -13
  85. package/dist/nodes/models/list.js +48 -26
  86. package/dist/nodes/models/menu.d.ts +15 -16
  87. package/dist/nodes/models/menu.js +63 -93
  88. package/dist/nodes/navigation-page.d.ts +16 -10
  89. package/dist/nodes/navigation-page.js +108 -31
  90. package/dist/nodes/navigation-view.d.ts +15 -0
  91. package/dist/nodes/navigation-view.js +15 -65
  92. package/dist/nodes/notebook-page-tab.d.ts +10 -12
  93. package/dist/nodes/notebook-page-tab.js +24 -27
  94. package/dist/nodes/notebook-page.d.ts +19 -16
  95. package/dist/nodes/notebook-page.js +75 -56
  96. package/dist/nodes/notebook.d.ts +10 -1
  97. package/dist/nodes/notebook.js +10 -22
  98. package/dist/nodes/overlay-child.d.ts +17 -1
  99. package/dist/nodes/overlay-child.js +53 -75
  100. package/dist/nodes/popover-menu.d.ts +15 -0
  101. package/dist/nodes/popover-menu.js +13 -26
  102. package/dist/nodes/scale.d.ts +8 -0
  103. package/dist/nodes/scale.js +2 -11
  104. package/dist/nodes/scrolled-window.d.ts +9 -0
  105. package/dist/nodes/scrolled-window.js +5 -11
  106. package/dist/nodes/search-bar.d.ts +9 -0
  107. package/dist/nodes/search-bar.js +8 -33
  108. package/dist/nodes/shortcut-controller.d.ts +9 -1
  109. package/dist/nodes/shortcut-controller.js +12 -25
  110. package/dist/nodes/shortcut.d.ts +11 -33
  111. package/dist/nodes/shortcut.js +19 -15
  112. package/dist/nodes/slot.d.ts +16 -15
  113. package/dist/nodes/slot.js +63 -57
  114. package/dist/nodes/source-view.d.ts +16 -0
  115. package/dist/nodes/source-view.js +44 -44
  116. package/dist/nodes/stack-page.d.ts +21 -1
  117. package/dist/nodes/stack-page.js +68 -17
  118. package/dist/nodes/stack.d.ts +11 -0
  119. package/dist/nodes/stack.js +8 -26
  120. package/dist/nodes/text-anchor.d.ts +11 -30
  121. package/dist/nodes/text-anchor.js +20 -22
  122. package/dist/nodes/text-content.d.ts +1 -0
  123. package/dist/nodes/text-content.js +1 -1
  124. package/dist/nodes/text-paintable.d.ts +10 -15
  125. package/dist/nodes/text-paintable.js +16 -9
  126. package/dist/nodes/text-segment.d.ts +12 -10
  127. package/dist/nodes/text-segment.js +19 -11
  128. package/dist/nodes/text-tag.d.ts +20 -119
  129. package/dist/nodes/text-tag.js +153 -119
  130. package/dist/nodes/text-view.d.ts +13 -18
  131. package/dist/nodes/text-view.js +17 -17
  132. package/dist/nodes/toggle-group.d.ts +9 -0
  133. package/dist/nodes/toggle-group.js +8 -33
  134. package/dist/nodes/toggle.d.ts +15 -1
  135. package/dist/nodes/toggle.js +34 -52
  136. package/dist/nodes/virtual.d.ts +3 -10
  137. package/dist/nodes/virtual.js +1 -14
  138. package/dist/nodes/web-view.d.ts +9 -0
  139. package/dist/nodes/web-view.js +10 -24
  140. package/dist/nodes/widget.d.ts +17 -13
  141. package/dist/nodes/widget.js +185 -112
  142. package/dist/nodes/window.d.ts +20 -21
  143. package/dist/nodes/window.js +54 -35
  144. package/dist/registry.d.ts +17 -6
  145. package/dist/registry.js +104 -5
  146. package/dist/render.d.ts +1 -10
  147. package/dist/render.js +1 -13
  148. package/package.json +6 -6
  149. package/dist/animation/css-builder.d.ts +0 -3
  150. package/dist/animation/css-builder.js +0 -53
  151. package/dist/animation/types.d.ts +0 -120
  152. package/dist/animation/types.js +0 -1
  153. package/dist/nodes/abstract/positional-child.d.ts +0 -9
  154. package/dist/nodes/abstract/positional-child.js +0 -29
  155. package/dist/nodes/abstract/virtual-container.d.ts +0 -21
  156. package/dist/nodes/abstract/virtual-container.js +0 -68
  157. package/dist/nodes/abstract/virtual-single-child.d.ts +0 -18
  158. package/dist/nodes/abstract/virtual-single-child.js +0 -55
  159. package/dist/nodes/action-row-child.d.ts +0 -1
  160. package/dist/nodes/action-row-child.js +0 -30
  161. package/dist/nodes/autowrapped.d.ts +0 -1
  162. package/dist/nodes/autowrapped.js +0 -115
  163. package/dist/nodes/expander-row-child.d.ts +0 -1
  164. package/dist/nodes/expander-row-child.js +0 -30
  165. package/dist/nodes/grid.d.ts +0 -1
  166. package/dist/nodes/grid.js +0 -41
  167. package/dist/nodes/index.d.ts +0 -56
  168. package/dist/nodes/index.js +0 -56
  169. package/dist/nodes/internal/child-attachment.d.ts +0 -26
  170. package/dist/nodes/internal/child-attachment.js +0 -48
  171. package/dist/nodes/internal/deferred-action.d.ts +0 -9
  172. package/dist/nodes/internal/deferred-action.js +0 -22
  173. package/dist/nodes/internal/text-tag-styles.d.ts +0 -43
  174. package/dist/nodes/internal/text-tag-styles.js +0 -52
  175. package/dist/nodes/internal/tree-list-item-renderer.d.ts +0 -26
  176. package/dist/nodes/internal/tree-list-item-renderer.js +0 -134
  177. package/dist/nodes/internal/utils.d.ts +0 -12
  178. package/dist/nodes/internal/utils.js +0 -92
  179. package/dist/nodes/models/tree-list.d.ts +0 -28
  180. package/dist/nodes/models/tree-list.js +0 -113
  181. package/dist/nodes/pack-child.d.ts +0 -1
  182. package/dist/nodes/pack-child.js +0 -30
  183. package/dist/nodes/simple-list-item.d.ts +0 -9
  184. package/dist/nodes/simple-list-item.js +0 -9
  185. package/dist/nodes/simple-list-view.d.ts +0 -1
  186. package/dist/nodes/simple-list-view.js +0 -74
  187. package/dist/nodes/toolbar-child.d.ts +0 -1
  188. package/dist/nodes/toolbar-child.js +0 -30
  189. package/dist/nodes/tree-list-item.d.ts +0 -22
  190. package/dist/nodes/tree-list-item.js +0 -90
  191. package/dist/nodes/tree-list-view.d.ts +0 -1
  192. package/dist/nodes/tree-list-view.js +0 -77
  193. package/dist/scheduler.d.ts +0 -26
  194. package/dist/scheduler.js +0 -42
@@ -1,16 +1,12 @@
1
- import { isObjectEqual } from "@gtkx/ffi";
2
1
  import * as Gio from "@gtkx/ffi/gio";
3
- import { CommitPriority, scheduleAfterCommit } from "../../scheduler.js";
4
2
  import { VirtualNode } from "../virtual.js";
5
3
  export class MenuModel extends VirtualNode {
6
4
  actionMap = null;
7
5
  actionPrefix;
8
- parent = null;
9
6
  menu;
10
7
  type;
11
8
  application = null;
12
9
  action = null;
13
- children = [];
14
10
  constructor(type, props, rootContainer, actionMap, application) {
15
11
  super("", props, undefined, rootContainer);
16
12
  this.type = type;
@@ -19,6 +15,12 @@ export class MenuModel extends VirtualNode {
19
15
  this.application = application ?? null;
20
16
  this.menu = new Gio.Menu();
21
17
  }
18
+ isValidChild(child) {
19
+ return child instanceof MenuModel;
20
+ }
21
+ isValidParent(parent) {
22
+ return parent instanceof MenuModel;
23
+ }
22
24
  setActionMap(actionMap, prefix) {
23
25
  this.actionMap = actionMap;
24
26
  this.actionPrefix = prefix;
@@ -51,11 +53,11 @@ export class MenuModel extends VirtualNode {
51
53
  }
52
54
  return this.props.id;
53
55
  }
54
- getParent() {
56
+ getParentMenu() {
55
57
  if (!this.parent) {
56
58
  throw new Error("Expected parent menu to be set on MenuNode");
57
59
  }
58
- return this.parent;
60
+ return this.parent.getMenu();
59
61
  }
60
62
  getActionMap() {
61
63
  if (!this.actionMap) {
@@ -85,28 +87,25 @@ export class MenuModel extends VirtualNode {
85
87
  }
86
88
  }
87
89
  getPosition() {
88
- return this.findPositionIn(this.getParent());
90
+ return this.findPositionIn(this.getParentMenu());
89
91
  }
90
- findPositionIn(parent) {
91
- for (let i = 0; i < parent.getNItems(); i++) {
92
+ findPositionIn(parentMenu) {
93
+ for (let i = 0; i < parentMenu.getNItems(); i++) {
92
94
  if (this.type === "item") {
93
- const actionName = parent.getItemAttributeValue(i, "action")?.getString();
95
+ const actionName = parentMenu.getItemAttributeValue(i, "action")?.getString();
94
96
  if (actionName === this.getActionName()) {
95
97
  return i;
96
98
  }
97
99
  }
98
100
  else {
99
- const link = parent.getItemLink(i, this.type);
100
- if (link && isObjectEqual(link, this.menu)) {
101
+ const link = parentMenu.getItemLink(i, this.type);
102
+ if (link && link === this.menu) {
101
103
  return i;
102
104
  }
103
105
  }
104
106
  }
105
107
  return -1;
106
108
  }
107
- setParent(parent) {
108
- this.parent = parent;
109
- }
110
109
  getMenu() {
111
110
  return this.menu;
112
111
  }
@@ -116,98 +115,71 @@ export class MenuModel extends VirtualNode {
116
115
  }
117
116
  return this.action;
118
117
  }
119
- removeFromParent() {
118
+ removeFromParentMenu() {
120
119
  if (!this.parent)
121
120
  return;
122
- const parent = this.parent;
123
- this.parent = null;
124
- scheduleAfterCommit(() => {
125
- const position = this.findPositionIn(parent);
126
- if (position >= 0) {
127
- parent.remove(position);
128
- }
129
- }, CommitPriority.HIGH);
121
+ const parentMenu = this.parent.getMenu();
122
+ const position = this.findPositionIn(parentMenu);
123
+ if (position >= 0) {
124
+ parentMenu.remove(position);
125
+ }
130
126
  }
131
127
  insertInParentBefore(before) {
132
128
  if (this.type === "item" && this.actionMap) {
133
129
  this.createAction();
134
130
  }
135
- scheduleAfterCommit(() => {
136
- const parent = this.getParent();
137
- const beforePosition = before.getPosition();
138
- switch (this.type) {
139
- case "item": {
140
- parent.insert(beforePosition, this.props.label, this.getActionName());
141
- break;
142
- }
143
- case "section":
144
- parent.insertSection(beforePosition, this.menu, this.props.label);
145
- break;
146
- case "submenu":
147
- parent.insertSubmenu(beforePosition, this.menu, this.props.label);
148
- break;
131
+ const parentMenu = this.getParentMenu();
132
+ const beforePosition = before.getPosition();
133
+ switch (this.type) {
134
+ case "item": {
135
+ parentMenu.insert(beforePosition, this.props.label, this.getActionName());
136
+ break;
149
137
  }
150
- }, CommitPriority.NORMAL);
138
+ case "section":
139
+ parentMenu.insertSection(beforePosition, this.menu, this.props.label);
140
+ break;
141
+ case "submenu":
142
+ parentMenu.insertSubmenu(beforePosition, this.menu, this.props.label);
143
+ break;
144
+ }
151
145
  }
152
- appendToParent() {
146
+ appendToParentMenu() {
153
147
  if (this.type === "item" && this.actionMap) {
154
148
  this.createAction();
155
149
  }
156
- scheduleAfterCommit(() => {
157
- const parent = this.getParent();
158
- switch (this.type) {
159
- case "item":
160
- parent.append(this.props.label, this.getActionName());
161
- break;
162
- case "section":
163
- parent.appendSection(this.menu, this.props.label);
164
- break;
165
- case "submenu":
166
- parent.appendSubmenu(this.menu, this.props.label);
167
- break;
168
- }
169
- }, CommitPriority.NORMAL);
150
+ const parentMenu = this.getParentMenu();
151
+ switch (this.type) {
152
+ case "item":
153
+ parentMenu.append(this.props.label, this.getActionName());
154
+ break;
155
+ case "section":
156
+ parentMenu.appendSection(this.menu, this.props.label);
157
+ break;
158
+ case "submenu":
159
+ parentMenu.appendSubmenu(this.menu, this.props.label);
160
+ break;
161
+ }
170
162
  }
171
163
  appendChild(child) {
172
- if (!(child instanceof MenuModel)) {
173
- return;
174
- }
175
- this.children.push(child);
164
+ super.appendChild(child);
176
165
  if (this.actionMap) {
177
166
  child.setActionMap(this.actionMap, this.actionPrefix);
178
167
  }
179
- child.setParent(this.menu);
180
- child.appendToParent();
168
+ child.appendToParentMenu();
181
169
  }
182
170
  insertBefore(child, before) {
183
- if (!(child instanceof MenuModel) || !(before instanceof MenuModel)) {
184
- return;
185
- }
186
- const beforeIndex = this.children.indexOf(before);
187
- if (beforeIndex >= 0) {
188
- this.children.splice(beforeIndex, 0, child);
189
- }
190
- else {
191
- this.children.push(child);
192
- }
171
+ super.insertBefore(child, before);
193
172
  if (this.actionMap) {
194
173
  child.setActionMap(this.actionMap, this.actionPrefix);
195
174
  }
196
- child.setParent(this.menu);
197
175
  child.insertInParentBefore(before);
198
176
  }
199
177
  removeChild(child) {
200
- if (!(child instanceof MenuModel)) {
201
- return;
202
- }
203
- const index = this.children.indexOf(child);
204
- if (index >= 0) {
205
- this.children.splice(index, 1);
206
- }
207
- child.removeFromParent();
178
+ child.removeFromParentMenu();
179
+ super.removeChild(child);
208
180
  }
209
- updateProps(oldProps, newProps) {
210
- super.updateProps(oldProps, newProps);
181
+ commitUpdate(oldProps, newProps) {
182
+ super.commitUpdate(oldProps, newProps);
211
183
  if (this.type === "item") {
212
184
  this.updateItemProps(oldProps, newProps);
213
185
  }
@@ -223,12 +195,10 @@ export class MenuModel extends VirtualNode {
223
195
  return;
224
196
  }
225
197
  if (oldProps.id !== newProps.id || oldProps.label !== newProps.label) {
226
- const parent = this.parent;
227
198
  this.removeAction();
228
- this.removeFromParent();
229
- this.parent = parent;
199
+ this.removeFromParentMenu();
230
200
  this.createAction();
231
- this.appendToParent();
201
+ this.appendToParentMenu();
232
202
  return;
233
203
  }
234
204
  if (oldProps.onActivate !== newProps.onActivate) {
@@ -245,22 +215,22 @@ export class MenuModel extends VirtualNode {
245
215
  return;
246
216
  }
247
217
  if (!oldProps || oldProps.label !== newProps.label) {
248
- const parent = this.parent;
249
- const position = this.findPositionIn(parent);
218
+ const parentMenu = this.parent.getMenu();
219
+ const position = this.findPositionIn(parentMenu);
250
220
  if (position >= 0) {
251
- parent.remove(position);
221
+ parentMenu.remove(position);
252
222
  if (this.type === "section") {
253
- parent.insertSection(position, this.menu, this.props.label);
223
+ parentMenu.insertSection(position, this.menu, this.props.label);
254
224
  }
255
225
  else if (this.type === "submenu") {
256
- parent.insertSubmenu(position, this.menu, this.props.label);
226
+ parentMenu.insertSubmenu(position, this.menu, this.props.label);
257
227
  }
258
228
  }
259
229
  }
260
230
  }
261
- unmount() {
231
+ detachDeletedInstance() {
262
232
  this.removeAction();
263
- this.removeFromParent();
264
- super.unmount();
233
+ this.removeFromParentMenu();
234
+ super.detachDeletedInstance();
265
235
  }
266
236
  }
@@ -1,12 +1,18 @@
1
- import * as Adw from "@gtkx/ffi/adw";
2
1
  import type { NavigationPageProps } from "../jsx.js";
3
- import { SlotNode } from "./slot.js";
4
- type Props = Partial<NavigationPageProps>;
5
- export declare class NavigationPageNode extends SlotNode<Props> {
6
- static priority: number;
7
- static matches(type: string): boolean;
8
- updateProps(oldProps: Props | null, newProps: Props): void;
9
- protected applyOwnProps(oldProps: Props | null, newProps: Props): void;
10
- protected onChildChange(oldChild: Adw.NavigationPage | null): void;
2
+ import type { Node } from "../node.js";
3
+ import { VirtualNode } from "./virtual.js";
4
+ import { WidgetNode } from "./widget.js";
5
+ export declare class NavigationPageNode extends VirtualNode<NavigationPageProps, WidgetNode, WidgetNode> {
6
+ private wrappedPage;
7
+ isValidChild(child: Node): boolean;
8
+ isValidParent(parent: Node): boolean;
9
+ setParent(parent: WidgetNode | null): void;
10
+ appendChild(child: WidgetNode): void;
11
+ removeChild(child: WidgetNode): void;
12
+ commitUpdate(oldProps: NavigationPageProps | null, newProps: NavigationPageProps): void;
13
+ detachDeletedInstance(): void;
14
+ private applyOwnProps;
15
+ private onChildChange;
16
+ private applySlotChild;
17
+ private getParentWidget;
11
18
  }
12
- export {};
@@ -1,51 +1,128 @@
1
1
  import * as Adw from "@gtkx/ffi/adw";
2
- import { registerNodeClass } from "../registry.js";
3
- import { hasChanged } from "./internal/utils.js";
4
- import { SlotNode } from "./slot.js";
5
- export class NavigationPageNode extends SlotNode {
6
- static priority = 1;
7
- static matches(type) {
8
- return type === "NavigationPage";
9
- }
10
- updateProps(oldProps, newProps) {
11
- super.updateProps(oldProps, newProps);
2
+ import { toCamelCase } from "@gtkx/gir";
3
+ import { hasChanged } from "./internal/props.js";
4
+ import { getFocusWidget, isDescendantOf, resolvePropertySetter } from "./internal/widget.js";
5
+ import { VirtualNode } from "./virtual.js";
6
+ import { WidgetNode } from "./widget.js";
7
+ export class NavigationPageNode extends VirtualNode {
8
+ wrappedPage = null;
9
+ isValidChild(child) {
10
+ return child instanceof WidgetNode;
11
+ }
12
+ isValidParent(parent) {
13
+ return parent instanceof WidgetNode;
14
+ }
15
+ setParent(parent) {
16
+ if (!parent && this.parent && this.wrappedPage) {
17
+ const parentWidget = this.getParentWidget();
18
+ if (parentWidget instanceof Adw.NavigationView) {
19
+ parentWidget.remove(this.wrappedPage);
20
+ }
21
+ else {
22
+ this.applySlotChild(parentWidget, this.wrappedPage);
23
+ }
24
+ this.wrappedPage = null;
25
+ }
26
+ super.setParent(parent);
27
+ if (parent && this.children[0]) {
28
+ this.onChildChange(null);
29
+ }
30
+ }
31
+ appendChild(child) {
32
+ const oldChildWidget = this.children[0]?.container ?? null;
33
+ super.appendChild(child);
34
+ if (this.parent) {
35
+ this.onChildChange(oldChildWidget);
36
+ }
37
+ }
38
+ removeChild(child) {
39
+ const oldChildWidget = child.container;
40
+ super.removeChild(child);
41
+ if (this.parent && oldChildWidget) {
42
+ this.onChildChange(oldChildWidget);
43
+ }
44
+ }
45
+ commitUpdate(oldProps, newProps) {
46
+ super.commitUpdate(oldProps, newProps);
12
47
  this.applyOwnProps(oldProps, newProps);
13
48
  }
49
+ detachDeletedInstance() {
50
+ if (this.parent && this.wrappedPage) {
51
+ const parentWidget = this.getParentWidget();
52
+ if (parentWidget instanceof Adw.NavigationView) {
53
+ parentWidget.remove(this.wrappedPage);
54
+ }
55
+ else {
56
+ this.applySlotChild(parentWidget, this.wrappedPage);
57
+ }
58
+ }
59
+ this.wrappedPage = null;
60
+ super.detachDeletedInstance();
61
+ }
14
62
  applyOwnProps(oldProps, newProps) {
15
- const child = this.child;
16
- if (!(child instanceof Adw.NavigationPage)) {
63
+ if (!this.wrappedPage) {
17
64
  return;
18
65
  }
19
- if (hasChanged(oldProps, newProps, "id") && newProps.id !== undefined) {
20
- child.setTag(newProps.id);
66
+ if (hasChanged(oldProps, newProps, "id")) {
67
+ this.wrappedPage.setTag(newProps.id);
21
68
  }
22
- if (hasChanged(oldProps, newProps, "title") && newProps.title !== undefined) {
23
- child.setTitle(newProps.title);
69
+ if (hasChanged(oldProps, newProps, "title")) {
70
+ this.wrappedPage.setTitle(newProps.title ?? "");
24
71
  }
25
- if (hasChanged(oldProps, newProps, "canPop") && newProps.canPop !== undefined) {
26
- child.setCanPop(newProps.canPop);
72
+ if (hasChanged(oldProps, newProps, "canPop")) {
73
+ this.wrappedPage.setCanPop(newProps.canPop ?? true);
27
74
  }
28
75
  }
29
76
  onChildChange(oldChild) {
30
- const navigationView = this.getParent();
77
+ const parentWidget = this.getParentWidget();
31
78
  const title = this.props.title ?? "";
32
- if (this.child) {
33
- this.child = this.props.id
34
- ? Adw.NavigationPage.newWithTag(this.child, title, this.props.id)
35
- : new Adw.NavigationPage(this.child, title);
36
- this.updateProps(null, this.props);
79
+ const childWidget = this.children[0]?.container ?? null;
80
+ if (childWidget) {
81
+ const wrappedChild = this.props.id
82
+ ? Adw.NavigationPage.newWithTag(childWidget, title, this.props.id)
83
+ : new Adw.NavigationPage(childWidget, title);
84
+ this.wrappedPage = wrappedChild;
85
+ this.applyOwnProps(null, this.props);
86
+ if (parentWidget instanceof Adw.NavigationView) {
87
+ if (oldChild instanceof Adw.NavigationPage) {
88
+ parentWidget.remove(oldChild);
89
+ }
90
+ parentWidget.add(wrappedChild);
91
+ }
92
+ else {
93
+ this.applySlotChild(parentWidget, oldChild);
94
+ }
37
95
  }
38
- if (navigationView instanceof Adw.NavigationView) {
96
+ else if (parentWidget instanceof Adw.NavigationView) {
39
97
  if (oldChild instanceof Adw.NavigationPage) {
40
- navigationView.remove(oldChild);
41
- }
42
- if (this.child) {
43
- navigationView.add(this.child);
98
+ parentWidget.remove(oldChild);
44
99
  }
100
+ this.wrappedPage = null;
45
101
  }
46
102
  else {
47
- super.onChildChange(oldChild);
103
+ this.wrappedPage = null;
104
+ this.applySlotChild(parentWidget, oldChild);
105
+ }
106
+ }
107
+ applySlotChild(parentWidget, oldChild) {
108
+ const propId = toCamelCase(this.props.id ?? "");
109
+ const setter = resolvePropertySetter(parentWidget, propId);
110
+ if (!setter) {
111
+ const parentType = parentWidget.constructor.glibTypeName;
112
+ throw new Error(`Unable to find property for slot '${propId}' on type '${parentType}'`);
113
+ }
114
+ if (oldChild && !this.wrappedPage) {
115
+ const focus = getFocusWidget(oldChild);
116
+ if (focus && isDescendantOf(focus, oldChild)) {
117
+ parentWidget.grabFocus();
118
+ }
119
+ }
120
+ setter(this.wrappedPage);
121
+ }
122
+ getParentWidget() {
123
+ if (!this.parent) {
124
+ throw new Error("Expected parent widget to be set on NavigationPageNode");
48
125
  }
126
+ return this.parent.container;
49
127
  }
50
128
  }
51
- registerNodeClass(NavigationPageNode);
@@ -1 +1,16 @@
1
+ import * as Adw from "@gtkx/ffi/adw";
2
+ import type { AdwNavigationViewProps } from "../jsx.js";
3
+ import type { Node } from "../node.js";
4
+ import { NavigationPageNode } from "./navigation-page.js";
5
+ import { SlotNode } from "./slot.js";
6
+ import { WidgetNode } from "./widget.js";
7
+ declare const OWN_PROPS: readonly ["history", "onHistoryChanged"];
8
+ type NavigationViewProps = Pick<AdwNavigationViewProps, (typeof OWN_PROPS)[number]>;
9
+ type NavigationViewChild = NavigationPageNode | SlotNode | WidgetNode;
10
+ export declare class NavigationViewNode extends WidgetNode<Adw.NavigationView, NavigationViewProps, NavigationViewChild> {
11
+ isValidChild(child: Node): boolean;
12
+ commitUpdate(oldProps: NavigationViewProps | null, newProps: NavigationViewProps): void;
13
+ private applyOwnProps;
14
+ private getCurrentHistory;
15
+ }
1
16
  export {};
@@ -1,89 +1,40 @@
1
1
  import * as Adw from "@gtkx/ffi/adw";
2
- import { registerNodeClass } from "../registry.js";
3
- import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
4
- import { filterProps, hasChanged, matchesAnyClass, primitiveArrayEqual } from "./internal/utils.js";
2
+ import { filterProps, hasChanged, primitiveArrayEqual } from "./internal/props.js";
5
3
  import { NavigationPageNode } from "./navigation-page.js";
6
4
  import { SlotNode } from "./slot.js";
7
5
  import { WidgetNode } from "./widget.js";
8
6
  const OWN_PROPS = ["history", "onHistoryChanged"];
9
- class NavigationViewNode extends WidgetNode {
10
- static priority = 1;
11
- static matches(_type, containerOrClass) {
12
- return matchesAnyClass([Adw.NavigationView], containerOrClass);
7
+ export class NavigationViewNode extends WidgetNode {
8
+ isValidChild(child) {
9
+ return child instanceof NavigationPageNode || child instanceof SlotNode || child instanceof WidgetNode;
13
10
  }
14
- appendChild(child) {
15
- if (child instanceof NavigationPageNode) {
16
- child.setParent(this.container);
17
- return;
18
- }
19
- if (child instanceof SlotNode || child instanceof WidgetNode) {
20
- super.appendChild(child);
21
- return;
22
- }
23
- throw new Error(`Cannot append '${child.typeName}' to 'NavigationView': expected x.NavigationPage or Widget`);
24
- }
25
- insertBefore(child, before) {
26
- if (child instanceof NavigationPageNode) {
27
- child.setParent(this.container);
28
- return;
29
- }
30
- if (child instanceof SlotNode || child instanceof WidgetNode) {
31
- super.insertBefore(child, before);
32
- return;
33
- }
34
- throw new Error(`Cannot insert '${child.typeName}' into 'NavigationView': expected x.NavigationPage or Widget`);
35
- }
36
- removeChild(child) {
37
- if (child instanceof NavigationPageNode) {
38
- return;
39
- }
40
- if (child instanceof SlotNode || child instanceof WidgetNode) {
41
- super.removeChild(child);
42
- return;
43
- }
44
- throw new Error(`Cannot remove '${child.typeName}' from 'NavigationView': expected x.NavigationPage or Widget`);
45
- }
46
- updateProps(oldProps, newProps) {
47
- super.updateProps(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
11
+ commitUpdate(oldProps, newProps) {
12
+ super.commitUpdate(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
48
13
  this.applyOwnProps(oldProps, newProps);
49
14
  }
50
15
  applyOwnProps(oldProps, newProps) {
51
16
  const oldHistory = oldProps?.history;
52
17
  const newHistory = newProps.history;
53
18
  if (newHistory && !primitiveArrayEqual(oldHistory, newHistory)) {
54
- this.syncHistory(newHistory);
19
+ this.container.replaceWithTags(newHistory, newHistory.length);
55
20
  }
56
21
  if (hasChanged(oldProps, newProps, "onHistoryChanged")) {
57
- const onHistoryChanged = newProps.onHistoryChanged;
58
- if (onHistoryChanged) {
59
- const handleHistoryChanged = () => {
60
- const history = this.getCurrentHistory();
61
- onHistoryChanged(history);
62
- };
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);
66
- }
67
- else {
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);
71
- }
22
+ const { onHistoryChanged } = newProps;
23
+ const handler = onHistoryChanged ? () => onHistoryChanged(this.getCurrentHistory()) : undefined;
24
+ this.signalStore.set(this, this.container, "popped", handler);
25
+ this.signalStore.set(this, this.container, "pushed", handler);
26
+ this.signalStore.set(this, this.container, "replaced", handler);
72
27
  }
73
28
  }
74
- syncHistory(history) {
75
- const container = this.container;
76
- scheduleAfterCommit(() => {
77
- container.replaceWithTags(history, history.length);
78
- }, CommitPriority.NORMAL);
79
- }
80
29
  getCurrentHistory() {
81
30
  const stack = this.container.getNavigationStack();
82
31
  const history = [];
83
32
  const nItems = stack.getNItems();
84
33
  for (let i = 0; i < nItems; i++) {
85
34
  const page = stack.getObject(i);
86
- const tag = page?.getTag();
35
+ if (!(page instanceof Adw.NavigationPage))
36
+ continue;
37
+ const tag = page.getTag();
87
38
  if (tag) {
88
39
  history.push(tag);
89
40
  }
@@ -91,4 +42,3 @@ class NavigationViewNode extends WidgetNode {
91
42
  return history;
92
43
  }
93
44
  }
94
- registerNodeClass(NavigationViewNode);
@@ -1,16 +1,14 @@
1
- import type * as Gtk from "@gtkx/ffi/gtk";
2
1
  import type { SlotProps } from "../jsx.js";
3
- import { SlotNode } from "./slot.js";
4
- type Props = Partial<SlotProps>;
5
- export declare class NotebookPageTabNode extends SlotNode<Props> {
6
- static priority: number;
7
- private notebook;
8
- private page;
9
- static matches(type: string): boolean;
10
- setPage(notebook: Gtk.Notebook | null, page: Gtk.Widget | null): void;
11
- updateProps(oldProps: Props | null, newProps: Props): void;
2
+ import type { Node } from "../node.js";
3
+ import type { NotebookPageNode } from "./notebook-page.js";
4
+ import { VirtualNode } from "./virtual.js";
5
+ import { WidgetNode } from "./widget.js";
6
+ export declare class NotebookPageTabNode extends VirtualNode<SlotProps, NotebookPageNode, WidgetNode> {
7
+ isValidChild(child: Node): boolean;
8
+ isValidParent(parent: Node): boolean;
12
9
  private getNotebook;
13
10
  private getPage;
14
- protected onChildChange(_oldChild: Gtk.Widget | null): void;
11
+ appendChild(child: WidgetNode): void;
12
+ removeChild(child: WidgetNode): void;
13
+ private onChildChange;
15
14
  }
16
- export {};