@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,42 +1,39 @@
1
- import { registerNodeClass } from "../registry.js";
2
- import { SlotNode } from "./slot.js";
3
- export class NotebookPageTabNode extends SlotNode {
4
- static priority = 1;
5
- notebook = null;
6
- page = null;
7
- static matches(type) {
8
- return type === "NotebookPageTab";
1
+ import { VirtualNode } from "./virtual.js";
2
+ import { WidgetNode } from "./widget.js";
3
+ export class NotebookPageTabNode extends VirtualNode {
4
+ isValidChild(child) {
5
+ return child instanceof WidgetNode;
9
6
  }
10
- setPage(notebook, page) {
11
- this.notebook = notebook;
12
- this.page = page;
13
- this.setParent(notebook);
14
- }
15
- updateProps(oldProps, newProps) {
16
- super.updateProps(oldProps, newProps);
7
+ isValidParent(parent) {
8
+ return parent instanceof VirtualNode && parent.typeName === "NotebookPage";
17
9
  }
18
10
  getNotebook() {
19
- if (!this.notebook) {
20
- throw new Error("Expected Notebook reference to be set on NotebookPageTabNode");
21
- }
22
- return this.notebook;
11
+ return this.parent?.parent?.container ?? null;
23
12
  }
24
13
  getPage() {
25
- if (!this.page) {
26
- throw new Error("Expected page reference to be set on NotebookPageTabNode");
14
+ return this.parent?.findContentChild()?.container ?? null;
15
+ }
16
+ appendChild(child) {
17
+ super.appendChild(child);
18
+ if (this.parent) {
19
+ this.onChildChange();
27
20
  }
28
- return this.page;
29
21
  }
30
- onChildChange(_oldChild) {
31
- if (!this.notebook || !this.page) {
32
- return;
22
+ removeChild(child) {
23
+ super.removeChild(child);
24
+ if (this.parent) {
25
+ this.onChildChange();
33
26
  }
27
+ }
28
+ onChildChange() {
34
29
  const notebook = this.getNotebook();
35
30
  const page = this.getPage();
31
+ if (!notebook || !page) {
32
+ return;
33
+ }
36
34
  if (notebook.pageNum(page) === -1) {
37
35
  return;
38
36
  }
39
- notebook.setTabLabel(page, this.child);
37
+ notebook.setTabLabel(page, this.children[0]?.container ?? null);
40
38
  }
41
39
  }
42
- registerNodeClass(NotebookPageTabNode);
@@ -1,25 +1,28 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
2
  import type { NotebookPageProps } from "../jsx.js";
3
3
  import type { Node } from "../node.js";
4
- import { SlotNode } from "./slot.js";
5
- type Props = Partial<NotebookPageProps>;
6
- export declare class NotebookPageNode extends SlotNode<Props> {
7
- static priority: number;
8
- position: number | null;
9
- private tabNode;
10
- static matches(type: string): boolean;
11
- setParent(parent: Gtk.Widget | null): void;
4
+ import { NotebookPageTabNode } from "./notebook-page-tab.js";
5
+ import { VirtualNode } from "./virtual.js";
6
+ import { WidgetNode } from "./widget.js";
7
+ type NotebookPageChild = WidgetNode | NotebookPageTabNode;
8
+ export declare class NotebookPageNode extends VirtualNode<NotebookPageProps, WidgetNode<Gtk.Notebook>, NotebookPageChild> {
9
+ private position;
10
+ isValidChild(child: Node): boolean;
11
+ isValidParent(parent: Node): boolean;
12
+ findTabNode(): NotebookPageTabNode | undefined;
13
+ findContentChild(): WidgetNode | undefined;
14
+ setParent(parent: WidgetNode<Gtk.Notebook> | null): void;
15
+ appendChild(child: NotebookPageChild): void;
16
+ removeChild(child: NotebookPageChild): void;
17
+ commitUpdate(oldProps: NotebookPageProps | null, newProps: NotebookPageProps): void;
18
+ detachDeletedInstance(): void;
12
19
  setPosition(position: number | null): void;
13
- private getNotebook;
14
- private updateTabNode;
15
- appendChild(child: Node): void;
16
- removeChild(child: Node): void;
17
- unmount(): void;
18
- updateProps(oldProps: Props | null, newProps: Props): void;
19
- protected applyOwnProps(oldProps: Props | null, newProps: Props): void;
20
+ getChildWidget(): Gtk.Widget;
21
+ private getParentWidget;
22
+ private applyOwnProps;
20
23
  private attachPage;
21
24
  private applyPageProps;
22
25
  private detachPage;
23
- protected onChildChange(oldChild: Gtk.Widget | null): void;
26
+ private onChildChange;
24
27
  }
25
28
  export {};
@@ -1,86 +1,104 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
- import { registerNodeClass } from "../registry.js";
3
- import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
4
- import { hasChanged } from "./internal/utils.js";
2
+ import { hasChanged } from "./internal/props.js";
5
3
  import { NotebookPageTabNode } from "./notebook-page-tab.js";
6
- import { SlotNode } from "./slot.js";
4
+ import { VirtualNode } from "./virtual.js";
7
5
  import { WidgetNode } from "./widget.js";
8
- export class NotebookPageNode extends SlotNode {
9
- static priority = 1;
6
+ export class NotebookPageNode extends VirtualNode {
10
7
  position = null;
11
- tabNode = null;
12
- static matches(type) {
13
- return type === "NotebookPage";
8
+ isValidChild(child) {
9
+ return child instanceof WidgetNode || child instanceof NotebookPageTabNode;
14
10
  }
15
- setParent(parent) {
16
- super.setParent(parent);
17
- this.updateTabNode();
11
+ isValidParent(parent) {
12
+ return parent instanceof WidgetNode && parent.container instanceof Gtk.Notebook;
18
13
  }
19
- setPosition(position) {
20
- this.position = position;
14
+ findTabNode() {
15
+ return this.children.find((c) => c instanceof NotebookPageTabNode);
21
16
  }
22
- getNotebook() {
23
- if (!this.parent) {
24
- throw new Error("Expected Notebook reference to be set on NotebookPageNode");
25
- }
26
- return this.parent;
17
+ findContentChild() {
18
+ return this.children.find((c) => c instanceof WidgetNode && !(c instanceof NotebookPageTabNode));
27
19
  }
28
- updateTabNode() {
29
- if (this.tabNode) {
30
- this.tabNode.setPage(this.parent, this.child);
20
+ setParent(parent) {
21
+ if (!parent && this.parent) {
22
+ const childWidget = this.findContentChild()?.container ?? null;
23
+ if (childWidget) {
24
+ this.detachPage(childWidget);
25
+ }
26
+ }
27
+ super.setParent(parent);
28
+ if (parent && this.findContentChild()) {
29
+ this.onChildChange(null);
31
30
  }
32
31
  }
33
32
  appendChild(child) {
34
33
  if (child instanceof NotebookPageTabNode) {
35
- this.tabNode = child;
36
- scheduleAfterCommit(() => {
37
- this.updateTabNode();
38
- }, CommitPriority.NORMAL);
34
+ super.appendChild(child);
39
35
  return;
40
36
  }
41
- if (!(child instanceof WidgetNode)) {
42
- throw new Error(`Cannot append '${child.typeName}' to 'x.NotebookPage': expected Widget or x.NotebookPageTab`);
37
+ const oldContent = this.findContentChild()?.container ?? null;
38
+ super.appendChild(child);
39
+ if (this.parent) {
40
+ this.onChildChange(oldContent);
43
41
  }
44
- const oldChild = this.child;
45
- this.child = child.container;
46
- scheduleAfterCommit(() => {
47
- if (this.parent) {
48
- this.onChildChange(oldChild ?? null);
49
- }
50
- this.updateTabNode();
51
- }, CommitPriority.NORMAL);
52
42
  }
53
43
  removeChild(child) {
54
44
  if (child instanceof NotebookPageTabNode) {
55
- this.tabNode = null;
45
+ super.removeChild(child);
56
46
  return;
57
47
  }
48
+ const isContent = child === this.findContentChild();
49
+ const oldContent = isContent ? child.container : null;
58
50
  super.removeChild(child);
51
+ if (isContent && this.parent && oldContent) {
52
+ this.onChildChange(oldContent);
53
+ }
59
54
  }
60
- unmount() {
61
- this.tabNode = null;
62
- super.unmount();
63
- }
64
- updateProps(oldProps, newProps) {
65
- super.updateProps(oldProps, newProps);
55
+ commitUpdate(oldProps, newProps) {
56
+ super.commitUpdate(oldProps, newProps);
66
57
  this.applyOwnProps(oldProps, newProps);
67
58
  }
59
+ detachDeletedInstance() {
60
+ const childWidget = this.findContentChild()?.container ?? null;
61
+ if (childWidget && this.parent) {
62
+ this.detachPage(childWidget);
63
+ }
64
+ super.detachDeletedInstance();
65
+ }
66
+ setPosition(position) {
67
+ this.position = position;
68
+ }
69
+ getChildWidget() {
70
+ const contentChild = this.findContentChild();
71
+ if (!contentChild) {
72
+ throw new Error("Expected content child widget to be set on NotebookPageNode");
73
+ }
74
+ return contentChild.container;
75
+ }
76
+ getParentWidget() {
77
+ if (!this.parent) {
78
+ throw new Error("Expected parent widget to be set on NotebookPageNode");
79
+ }
80
+ return this.parent.container;
81
+ }
68
82
  applyOwnProps(oldProps, newProps) {
69
- if (hasChanged(oldProps, newProps, "label") && this.child && this.parent && !this.tabNode?.child) {
70
- const tabLabel = this.getNotebook().getTabLabel(this.child);
83
+ const contentChild = this.findContentChild();
84
+ const childWidget = contentChild?.container ?? null;
85
+ const tabNode = this.findTabNode();
86
+ if (hasChanged(oldProps, newProps, "label") && childWidget && this.parent && !tabNode?.children[0]) {
87
+ const tabLabel = this.getParentWidget().getTabLabel(childWidget);
71
88
  tabLabel.setLabel(newProps.label ?? "");
72
89
  }
73
90
  const pagePropsChanged = hasChanged(oldProps, newProps, "tabExpand") || hasChanged(oldProps, newProps, "tabFill");
74
- if (this.child && this.parent && pagePropsChanged) {
91
+ if (childWidget && this.parent && pagePropsChanged) {
75
92
  this.applyPageProps();
76
93
  }
77
94
  }
78
95
  attachPage() {
79
- const child = this.getChild();
80
- const notebook = this.getNotebook();
96
+ const child = this.getChildWidget();
97
+ const notebook = this.getParentWidget();
98
+ const tabNode = this.findTabNode();
81
99
  let tabLabel;
82
- if (this.tabNode?.child) {
83
- tabLabel = this.tabNode.child;
100
+ if (tabNode?.children[0]) {
101
+ tabLabel = tabNode.children[0].container;
84
102
  }
85
103
  else {
86
104
  const label = new Gtk.Label();
@@ -96,10 +114,10 @@ export class NotebookPageNode extends SlotNode {
96
114
  this.applyPageProps();
97
115
  }
98
116
  applyPageProps() {
99
- const child = this.child;
117
+ const child = this.findContentChild()?.container ?? null;
100
118
  if (!child || !this.parent)
101
119
  return;
102
- const notebook = this.getNotebook();
120
+ const notebook = this.getParentWidget();
103
121
  const page = notebook.getPage(child);
104
122
  if (!page)
105
123
  return;
@@ -111,17 +129,18 @@ export class NotebookPageNode extends SlotNode {
111
129
  }
112
130
  }
113
131
  detachPage(childToDetach) {
114
- const notebook = this.getNotebook();
132
+ const notebook = this.getParentWidget();
115
133
  const pageNum = notebook.pageNum(childToDetach);
116
- notebook.removePage(pageNum);
134
+ if (pageNum !== -1) {
135
+ notebook.removePage(pageNum);
136
+ }
117
137
  }
118
138
  onChildChange(oldChild) {
119
139
  if (oldChild) {
120
140
  this.detachPage(oldChild);
121
141
  }
122
- if (this.child) {
142
+ if (this.findContentChild()) {
123
143
  this.attachPage();
124
144
  }
125
145
  }
126
146
  }
127
- registerNodeClass(NotebookPageNode);
@@ -1 +1,10 @@
1
- export {};
1
+ import type * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { Node } from "../node.js";
3
+ import type { Props } from "../types.js";
4
+ import { NotebookPageNode } from "./notebook-page.js";
5
+ import { WidgetNode } from "./widget.js";
6
+ export declare class NotebookNode extends WidgetNode<Gtk.Notebook, Props, NotebookPageNode> {
7
+ isValidChild(child: Node): boolean;
8
+ insertBefore(child: NotebookPageNode, before: NotebookPageNode): void;
9
+ removeChild(child: NotebookPageNode): void;
10
+ }
@@ -1,32 +1,20 @@
1
- import { NOTEBOOK_CLASSES } from "../generated/internal.js";
2
- import { registerNodeClass } from "../registry.js";
3
- import { matchesAnyClass } from "./internal/utils.js";
4
1
  import { NotebookPageNode } from "./notebook-page.js";
5
2
  import { WidgetNode } from "./widget.js";
6
- class NotebookNode extends WidgetNode {
7
- static priority = 1;
8
- static matches(_type, containerOrClass) {
9
- return matchesAnyClass(NOTEBOOK_CLASSES, containerOrClass);
10
- }
11
- appendChild(child) {
12
- if (!(child instanceof NotebookPageNode)) {
13
- throw new Error(`Cannot append '${child.typeName}' to 'Notebook': expected x.NotebookPage`);
14
- }
15
- child.setParent(this.container);
3
+ export class NotebookNode extends WidgetNode {
4
+ isValidChild(child) {
5
+ return child instanceof NotebookPageNode;
16
6
  }
17
7
  insertBefore(child, before) {
18
- if (!(child instanceof NotebookPageNode) || !(before instanceof NotebookPageNode)) {
19
- throw new Error(`Cannot insert '${child.typeName}' into 'Notebook': expected x.NotebookPage`);
20
- }
21
- const beforePosition = this.container.pageNum(before.getChild());
8
+ const isMove = this.children.includes(child);
9
+ const beforePosition = this.container.pageNum(before.getChildWidget());
22
10
  child.setPosition(beforePosition);
23
- child.setParent(this.container);
11
+ if (isMove) {
12
+ this.container.reorderChild(child.getChildWidget(), beforePosition);
13
+ }
14
+ super.insertBefore(child, before);
24
15
  }
25
16
  removeChild(child) {
26
- if (!(child instanceof NotebookPageNode)) {
27
- throw new Error(`Cannot remove '${child.typeName}' from 'Notebook': expected x.NotebookPage`);
28
- }
29
17
  child.setPosition(null);
18
+ super.removeChild(child);
30
19
  }
31
20
  }
32
- registerNodeClass(NotebookNode);
@@ -1 +1,17 @@
1
- export {};
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { OverlayChildProps } from "../jsx.js";
3
+ import type { Node } from "../node.js";
4
+ import { VirtualNode } from "./virtual.js";
5
+ import { WidgetNode } from "./widget.js";
6
+ export declare class OverlayChildNode extends VirtualNode<OverlayChildProps, WidgetNode<Gtk.Overlay>, WidgetNode> {
7
+ isValidChild(child: Node): boolean;
8
+ isValidParent(parent: Node): boolean;
9
+ setParent(parent: WidgetNode<Gtk.Overlay> | null): void;
10
+ appendChild(child: WidgetNode): void;
11
+ insertBefore(child: WidgetNode, before: WidgetNode): void;
12
+ removeChild(child: WidgetNode): void;
13
+ commitUpdate(oldProps: OverlayChildProps | null, newProps: OverlayChildProps): void;
14
+ detachDeletedInstance(): void;
15
+ private attachToParent;
16
+ private detachAllChildren;
17
+ }
@@ -1,109 +1,87 @@
1
- import { getNativeId, isObjectEqual } from "@gtkx/ffi";
2
- import { registerNodeClass } from "../registry.js";
3
- import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import { hasChanged } from "./internal/props.js";
4
3
  import { VirtualNode } from "./virtual.js";
5
4
  import { WidgetNode } from "./widget.js";
6
- class OverlayChildNode extends VirtualNode {
7
- static priority = 1;
8
- static matches(type) {
9
- return type === "OverlayChild";
5
+ export class OverlayChildNode extends VirtualNode {
6
+ isValidChild(child) {
7
+ return child instanceof WidgetNode;
10
8
  }
11
- parent = null;
12
- children = new Map();
13
- canBeChildOf(parent) {
14
- return parent instanceof WidgetNode;
9
+ isValidParent(parent) {
10
+ return parent instanceof WidgetNode && parent.container instanceof Gtk.Overlay;
15
11
  }
16
- attachTo(parent) {
17
- if (parent instanceof WidgetNode) {
18
- this.parent = parent.container;
12
+ setParent(parent) {
13
+ if (!parent && this.parent) {
14
+ this.detachAllChildren(this.parent.container);
19
15
  }
20
- }
21
- detachFrom(_parent) { }
22
- unmount() {
23
- if (this.parent && this.children.size > 0) {
24
- const parent = this.parent;
25
- const children = [...this.children.values()];
26
- this.children.clear();
27
- for (const child of children) {
28
- const currentParent = child.getParent();
29
- if (currentParent && isObjectEqual(currentParent, parent)) {
30
- parent.removeOverlay(child);
31
- }
16
+ super.setParent(parent);
17
+ if (parent) {
18
+ for (const child of this.children) {
19
+ this.attachToParent(parent.container, child.container);
32
20
  }
33
21
  }
34
- this.parent = null;
35
- super.unmount();
36
22
  }
37
23
  appendChild(child) {
38
- if (!(child instanceof WidgetNode)) {
39
- throw new Error(`Cannot append '${child.typeName}' to '${this.typeName}': expected Widget`);
24
+ super.appendChild(child);
25
+ if (this.parent) {
26
+ this.attachToParent(this.parent.container, child.container);
40
27
  }
41
- const widget = child.container;
42
- this.children.set(getNativeId(widget.handle), widget);
43
- scheduleAfterCommit(() => {
44
- if (this.parent) {
45
- this.attachChild(widget);
46
- }
47
- }, CommitPriority.NORMAL);
48
28
  }
49
- insertBefore(child, _before) {
50
- if (!(child instanceof WidgetNode)) {
51
- throw new Error(`Cannot insert '${child.typeName}' into '${this.typeName}': expected Widget`);
29
+ insertBefore(child, before) {
30
+ super.insertBefore(child, before);
31
+ if (this.parent) {
32
+ this.attachToParent(this.parent.container, child.container);
52
33
  }
53
- const widget = child.container;
54
- this.children.set(getNativeId(widget.handle), widget);
55
- scheduleAfterCommit(() => {
56
- if (this.parent) {
57
- this.attachChild(widget);
58
- }
59
- }, CommitPriority.NORMAL);
60
34
  }
61
35
  removeChild(child) {
62
- if (!(child instanceof WidgetNode)) {
63
- throw new Error(`Cannot remove '${child.typeName}' from '${this.typeName}': expected Widget`);
64
- }
65
- const widget = child.container;
66
- const parent = this.parent;
67
- this.children.delete(getNativeId(widget.handle));
68
- scheduleAfterCommit(() => {
69
- if (parent) {
70
- const currentParent = widget.getParent();
71
- if (currentParent && isObjectEqual(currentParent, parent)) {
72
- parent.removeOverlay(widget);
73
- }
36
+ if (this.parent) {
37
+ const widget = child.container;
38
+ const currentParent = widget.getParent();
39
+ if (currentParent && currentParent === this.parent.container) {
40
+ this.parent.container.removeOverlay(widget);
74
41
  }
75
- }, CommitPriority.HIGH);
42
+ }
43
+ super.removeChild(child);
76
44
  }
77
- updateProps(oldProps, newProps) {
78
- super.updateProps(oldProps, newProps);
45
+ commitUpdate(oldProps, newProps) {
46
+ super.commitUpdate(oldProps, newProps);
79
47
  if (!this.parent) {
80
48
  return;
81
49
  }
82
- const measureChanged = oldProps?.measure !== newProps.measure;
83
- const clipOverlayChanged = oldProps?.clipOverlay !== newProps.clipOverlay;
50
+ const measureChanged = hasChanged(oldProps, newProps, "measure");
51
+ const clipOverlayChanged = hasChanged(oldProps, newProps, "clipOverlay");
84
52
  if (measureChanged || clipOverlayChanged) {
85
- const parent = this.parent;
86
- for (const child of this.children.values()) {
53
+ const parent = this.parent.container;
54
+ for (const child of this.children) {
87
55
  if (measureChanged) {
88
- parent.setMeasureOverlay(child, newProps.measure ?? false);
56
+ parent.setMeasureOverlay(child.container, newProps.measure ?? false);
89
57
  }
90
58
  if (clipOverlayChanged) {
91
- parent.setClipOverlay(child, newProps.clipOverlay ?? false);
59
+ parent.setClipOverlay(child.container, newProps.clipOverlay ?? false);
92
60
  }
93
61
  }
94
62
  }
95
63
  }
96
- attachChild(widget) {
97
- if (!this.parent) {
98
- return;
64
+ detachDeletedInstance() {
65
+ if (this.parent) {
66
+ this.detachAllChildren(this.parent.container);
99
67
  }
100
- this.parent.addOverlay(widget);
68
+ super.detachDeletedInstance();
69
+ }
70
+ attachToParent(parent, child) {
71
+ parent.addOverlay(child);
101
72
  if (this.props.measure !== undefined) {
102
- this.parent.setMeasureOverlay(widget, this.props.measure);
73
+ parent.setMeasureOverlay(child, this.props.measure);
103
74
  }
104
75
  if (this.props.clipOverlay !== undefined) {
105
- this.parent.setClipOverlay(widget, this.props.clipOverlay);
76
+ parent.setClipOverlay(child, this.props.clipOverlay);
77
+ }
78
+ }
79
+ detachAllChildren(parent) {
80
+ for (const child of this.children) {
81
+ const currentParent = child.container.getParent();
82
+ if (currentParent && currentParent === parent) {
83
+ parent.removeOverlay(child.container);
84
+ }
106
85
  }
107
86
  }
108
87
  }
109
- registerNodeClass(OverlayChildNode);
@@ -1 +1,16 @@
1
+ import type { Node } from "../node.js";
2
+ import type { PopoverMenuWidget } from "../registry.js";
3
+ import type { Container, Props } from "../types.js";
4
+ import { MenuNode } from "./menu.js";
5
+ import { SlotNode } from "./slot.js";
6
+ import { WidgetNode } from "./widget.js";
7
+ type PopoverMenuChild = MenuNode | SlotNode | WidgetNode;
8
+ export declare class PopoverMenuNode extends WidgetNode<PopoverMenuWidget, Props, PopoverMenuChild> {
9
+ private menu;
10
+ isValidChild(child: Node): boolean;
11
+ constructor(typeName: string, props: Props, container: PopoverMenuWidget, rootContainer: Container);
12
+ appendChild(child: PopoverMenuChild): void;
13
+ insertBefore(child: PopoverMenuChild, before: PopoverMenuChild): void;
14
+ removeChild(child: PopoverMenuChild): void;
15
+ }
1
16
  export {};
@@ -1,24 +1,19 @@
1
1
  import * as Gio from "@gtkx/ffi/gio";
2
2
  import * as Gtk from "@gtkx/ffi/gtk";
3
- import { POPOVER_MENU_CLASSES } from "../generated/internal.js";
4
- import { registerNodeClass } from "../registry.js";
5
- import { matchesAnyClass } from "./internal/utils.js";
6
3
  import { MenuNode } from "./menu.js";
7
4
  import { MenuModel } from "./models/menu.js";
8
5
  import { SlotNode } from "./slot.js";
9
6
  import { WidgetNode } from "./widget.js";
10
- const ACTION_PREFIX = "menu";
11
- class PopoverMenuNode extends WidgetNode {
12
- static priority = 1;
7
+ export class PopoverMenuNode extends WidgetNode {
13
8
  menu;
14
- static matches(_type, containerOrClass) {
15
- return matchesAnyClass(POPOVER_MENU_CLASSES, containerOrClass);
9
+ isValidChild(child) {
10
+ return child instanceof MenuNode || child instanceof SlotNode || child instanceof WidgetNode;
16
11
  }
17
12
  constructor(typeName, props, container, rootContainer) {
18
13
  super(typeName, props, container, rootContainer);
19
14
  const application = rootContainer instanceof Gtk.Application ? rootContainer : undefined;
20
15
  const actionGroup = new Gio.SimpleActionGroup();
21
- const prefix = application ? "app" : ACTION_PREFIX;
16
+ const prefix = application ? "app" : "menu";
22
17
  this.container.insertActionGroup(prefix, actionGroup);
23
18
  this.menu = new MenuModel("root", {}, rootContainer, actionGroup, application);
24
19
  this.container.setMenuModel(this.menu.getMenu());
@@ -28,33 +23,25 @@ class PopoverMenuNode extends WidgetNode {
28
23
  this.menu.appendChild(child);
29
24
  return;
30
25
  }
31
- if (child instanceof SlotNode || child instanceof WidgetNode) {
32
- super.appendChild(child);
33
- return;
34
- }
35
- throw new Error(`Cannot append '${child.typeName}' to 'PopoverMenu': expected MenuItem or Widget`);
26
+ super.appendChild(child);
36
27
  }
37
28
  insertBefore(child, before) {
38
29
  if (child instanceof MenuNode) {
39
- this.menu.insertBefore(child, before);
40
- return;
41
- }
42
- if (child instanceof SlotNode || child instanceof WidgetNode) {
43
- super.insertBefore(child, before);
30
+ if (before instanceof MenuNode) {
31
+ this.menu.insertBefore(child, before);
32
+ }
33
+ else {
34
+ this.menu.appendChild(child);
35
+ }
44
36
  return;
45
37
  }
46
- throw new Error(`Cannot insert '${child.typeName}' into 'PopoverMenu': expected MenuItem or Widget`);
38
+ super.insertBefore(child, before);
47
39
  }
48
40
  removeChild(child) {
49
41
  if (child instanceof MenuNode) {
50
42
  this.menu.removeChild(child);
51
43
  return;
52
44
  }
53
- if (child instanceof SlotNode || child instanceof WidgetNode) {
54
- super.removeChild(child);
55
- return;
56
- }
57
- throw new Error(`Cannot remove '${child.typeName}' from 'PopoverMenu': expected MenuItem or Widget`);
45
+ super.removeChild(child);
58
46
  }
59
47
  }
60
- registerNodeClass(PopoverMenuNode);
@@ -1 +1,9 @@
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { AdjustableProps, GtkScaleProps } from "../jsx.js";
3
+ import { AdjustableNode } from "./adjustable.js";
4
+ type ScaleProps = AdjustableProps & Pick<GtkScaleProps, "marks">;
5
+ export declare class ScaleNode extends AdjustableNode<Gtk.Scale> {
6
+ private appliedMarks;
7
+ protected applyOwnProps(oldProps: ScaleProps | null, newProps: ScaleProps): void;
8
+ }
1
9
  export {};