@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
@@ -0,0 +1,106 @@
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { scheduleAfterCommit } from "../scheduler.js";
4
+ import { NotebookPageTabNode } from "./notebook-page-tab.js";
5
+ import { SlotNode } from "./slot.js";
6
+ import { WidgetNode } from "./widget.js";
7
+ export class NotebookPageNode extends SlotNode {
8
+ static priority = 1;
9
+ position;
10
+ tabNode;
11
+ static matches(type) {
12
+ return type === "Notebook.Page";
13
+ }
14
+ setNotebook(notebook) {
15
+ this.setParent(notebook);
16
+ this.updateTabNode();
17
+ }
18
+ setPosition(position) {
19
+ this.position = position;
20
+ }
21
+ getNotebook() {
22
+ if (!this.parent) {
23
+ throw new Error("Expected Notebook reference to be set on NotebookPageNode");
24
+ }
25
+ return this.parent;
26
+ }
27
+ updateTabNode() {
28
+ if (this.tabNode) {
29
+ this.tabNode.setPage(this.parent, this.child);
30
+ }
31
+ }
32
+ appendChild(child) {
33
+ if (child instanceof NotebookPageTabNode) {
34
+ this.tabNode = child;
35
+ scheduleAfterCommit(() => {
36
+ this.updateTabNode();
37
+ });
38
+ return;
39
+ }
40
+ if (!(child instanceof WidgetNode)) {
41
+ throw new Error(`Cannot append '${child.typeName}' to 'Notebook.Page': expected Widget or Notebook.PageTab`);
42
+ }
43
+ const oldChild = this.child;
44
+ this.child = child.container;
45
+ scheduleAfterCommit(() => {
46
+ if (this.parent) {
47
+ this.onChildChange(oldChild);
48
+ }
49
+ this.updateTabNode();
50
+ });
51
+ }
52
+ removeChild(child) {
53
+ if (child instanceof NotebookPageTabNode) {
54
+ this.tabNode = undefined;
55
+ return;
56
+ }
57
+ // For content widget, use SlotNode's removeChild logic
58
+ super.removeChild();
59
+ }
60
+ unmount() {
61
+ this.tabNode = undefined;
62
+ super.unmount();
63
+ }
64
+ updateProps(oldProps, newProps) {
65
+ if (!oldProps || oldProps.label !== newProps.label) {
66
+ // Only update if using text label (no custom tab node)
67
+ if (this.child && this.parent && !this.tabNode?.child) {
68
+ const tabLabel = this.getNotebook().getTabLabel(this.child);
69
+ tabLabel.setLabel(newProps.label ?? "");
70
+ }
71
+ }
72
+ }
73
+ attachPage() {
74
+ const child = this.getChild();
75
+ const notebook = this.getNotebook();
76
+ // Use custom tab widget if provided, otherwise create a Label
77
+ let tabLabel;
78
+ if (this.tabNode?.child) {
79
+ tabLabel = this.tabNode.child;
80
+ }
81
+ else {
82
+ const label = new Gtk.Label();
83
+ label.setLabel(this.props.label ?? "");
84
+ tabLabel = label;
85
+ }
86
+ if (this.position !== undefined) {
87
+ notebook.insertPage(child, this.position, tabLabel);
88
+ return;
89
+ }
90
+ notebook.appendPage(child, tabLabel);
91
+ }
92
+ detachPage(childToDetach) {
93
+ const notebook = this.getNotebook();
94
+ const pageNum = notebook.pageNum(childToDetach);
95
+ notebook.removePage(pageNum);
96
+ }
97
+ onChildChange(oldChild) {
98
+ if (oldChild) {
99
+ this.detachPage(oldChild);
100
+ }
101
+ if (this.child) {
102
+ this.attachPage();
103
+ }
104
+ }
105
+ }
106
+ registerNodeClass(NotebookPageNode);
@@ -1,33 +1 @@
1
- import * as Gtk from "@gtkx/ffi/gtk";
2
- import type { ChildContainer, PageContainer } from "../containers.js";
3
- import type { Props } from "../factory.js";
4
- import { Node } from "../node.js";
5
- import { VirtualSlotNode } from "./virtual-slot.js";
6
- export declare class NotebookNode extends Node<Gtk.Notebook> implements PageContainer, ChildContainer {
7
- static matches(type: string): boolean;
8
- addPage(child: Gtk.Widget, label: string): void;
9
- insertPageBefore(child: Gtk.Widget, label: string, beforeChild: Gtk.Widget): void;
10
- removePage(child: Gtk.Widget): void;
11
- updatePageLabel(child: Gtk.Widget, label: string): void;
12
- attachChild(child: Gtk.Widget): void;
13
- insertChildBefore(child: Gtk.Widget, before: Gtk.Widget): void;
14
- detachChild(child: Gtk.Widget): void;
15
- appendChild(child: Node): void;
16
- insertBefore(child: Node, before: Node): void;
17
- removeChild(child: Node): void;
18
- }
19
- type NotebookPageProps = {
20
- label: string;
21
- };
22
- export declare class NotebookPageNode extends VirtualSlotNode<PageContainer, NotebookPageProps> {
23
- static consumedPropNames: string[];
24
- static matches(type: string): boolean;
25
- protected isValidContainer(parent: Node): parent is Node & PageContainer;
26
- protected extractSlotProps(props: Props): NotebookPageProps;
27
- protected addToContainer(container: PageContainer, child: Gtk.Widget, props: NotebookPageProps): void;
28
- protected insertBeforeInContainer(container: PageContainer, child: Gtk.Widget, props: NotebookPageProps, before: Gtk.Widget): void;
29
- protected removeFromContainer(container: PageContainer, child: Gtk.Widget): void;
30
- protected updateInContainer(container: PageContainer, child: Gtk.Widget, props: NotebookPageProps): void;
31
- updateProps(oldProps: Props, newProps: Props): void;
32
- }
33
1
  export {};
@@ -1,125 +1,32 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
- import { Node } from "../node.js";
3
- import { isPageContainer } from "../predicates.js";
4
- import { VirtualSlotNode } from "./virtual-slot.js";
5
- export class NotebookNode extends Node {
6
- static matches(type) {
7
- return type === "Notebook" || type === "Notebook.Root";
8
- }
9
- addPage(child, label) {
10
- const tabLabel = new Gtk.Label();
11
- tabLabel.setLabel(label);
12
- this.widget.appendPage(child, tabLabel);
13
- }
14
- insertPageBefore(child, label, beforeChild) {
15
- const beforePageNum = this.widget.pageNum(beforeChild);
16
- const tabLabel = new Gtk.Label();
17
- tabLabel.setLabel(label);
18
- if (beforePageNum >= 0) {
19
- this.widget.insertPage(child, beforePageNum, tabLabel);
20
- }
21
- else {
22
- this.widget.appendPage(child, tabLabel);
23
- }
24
- }
25
- removePage(child) {
26
- const pageNum = this.widget.pageNum(child);
27
- if (pageNum >= 0) {
28
- this.widget.removePage(pageNum);
29
- }
30
- }
31
- updatePageLabel(child, label) {
32
- const tabLabel = new Gtk.Label();
33
- tabLabel.setLabel(label);
34
- this.widget.setTabLabel(child, tabLabel);
35
- }
36
- attachChild(child) {
37
- this.widget.appendPage(child);
38
- }
39
- insertChildBefore(child, before) {
40
- const beforePageNum = this.widget.pageNum(before);
41
- if (beforePageNum >= 0) {
42
- this.widget.insertPage(child, beforePageNum);
43
- }
44
- else {
45
- this.widget.appendPage(child);
46
- }
47
- }
48
- detachChild(child) {
49
- this.removePage(child);
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { isContainerType } from "./internal/utils.js";
4
+ import { NotebookPageNode } from "./notebook-page.js";
5
+ import { WidgetNode } from "./widget.js";
6
+ class NotebookNode extends WidgetNode {
7
+ static priority = 1;
8
+ static matches(_type, containerOrClass) {
9
+ return isContainerType(Gtk.Notebook, containerOrClass);
50
10
  }
51
11
  appendChild(child) {
52
- if (child instanceof NotebookPageNode) {
53
- child.parent = this;
54
- const childWidget = child.getChildWidget();
55
- const props = child.getSlotProps();
56
- if (childWidget) {
57
- this.addPage(childWidget, props.label);
58
- child.setParentContainer(this);
59
- }
60
- return;
12
+ if (!(child instanceof NotebookPageNode)) {
13
+ throw new Error(`Cannot append '${child.typeName}' to 'Notebook': expected Notebook.Page`);
61
14
  }
62
- super.appendChild(child);
15
+ child.setNotebook(this.container);
63
16
  }
64
17
  insertBefore(child, before) {
65
- if (child instanceof NotebookPageNode) {
66
- child.parent = this;
67
- const childWidget = child.getChildWidget();
68
- const props = child.getSlotProps();
69
- if (childWidget) {
70
- const beforeWidget = child.getBeforeWidget(before);
71
- if (beforeWidget) {
72
- this.insertPageBefore(childWidget, props.label, beforeWidget);
73
- }
74
- else {
75
- this.addPage(childWidget, props.label);
76
- }
77
- child.setParentContainer(this);
78
- }
79
- return;
18
+ if (!(child instanceof NotebookPageNode) || !(before instanceof NotebookPageNode)) {
19
+ throw new Error(`Cannot insert '${child.typeName}' to 'Notebook': expected Notebook.Page`);
80
20
  }
81
- super.insertBefore(child, before);
21
+ const beforePosition = this.container.pageNum(before.getChild());
22
+ child.setPosition(beforePosition);
23
+ child.setNotebook(this.container);
82
24
  }
83
25
  removeChild(child) {
84
- if (child instanceof NotebookPageNode) {
85
- const childWidget = child.getChildWidget();
86
- if (childWidget) {
87
- this.removePage(childWidget);
88
- }
89
- child.unmount();
90
- child.parent = null;
91
- return;
26
+ if (!(child instanceof NotebookPageNode)) {
27
+ throw new Error(`Cannot remove '${child.typeName}' from 'Notebook': expected Notebook.Page`);
92
28
  }
93
- super.removeChild(child);
94
- }
95
- }
96
- export class NotebookPageNode extends VirtualSlotNode {
97
- static consumedPropNames = ["label"];
98
- static matches(type) {
99
- return type === "Notebook.Page";
100
- }
101
- isValidContainer(parent) {
102
- return isPageContainer(parent);
103
- }
104
- extractSlotProps(props) {
105
- return {
106
- label: props.label ?? "",
107
- };
108
- }
109
- addToContainer(container, child, props) {
110
- container.addPage(child, props.label);
111
- }
112
- insertBeforeInContainer(container, child, props, before) {
113
- container.insertPageBefore(child, props.label, before);
114
- }
115
- removeFromContainer(container, child) {
116
- container.removePage(child);
117
- }
118
- updateInContainer(container, child, props) {
119
- container.updatePageLabel(child, props.label);
120
- }
121
- updateProps(oldProps, newProps) {
122
- this.updateSlotPropsIfChanged(oldProps, newProps, ["label"]);
123
- super.updateProps(oldProps, newProps);
29
+ child.setPosition(undefined);
124
30
  }
125
31
  }
32
+ registerNodeClass(NotebookNode);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ import { registerNodeClass } from "../registry.js";
2
+ import { SlotNode } from "./slot.js";
3
+ class OverlayChildNode extends SlotNode {
4
+ static priority = 1;
5
+ static matches(type) {
6
+ return type === "OverlayChild";
7
+ }
8
+ getOverlay() {
9
+ if (!this.parent) {
10
+ throw new Error("Expected parent widget to be set on OverlayChildNode");
11
+ }
12
+ return this.parent;
13
+ }
14
+ onChildChange(oldChild) {
15
+ const overlay = this.getOverlay();
16
+ if (oldChild) {
17
+ overlay.removeOverlay(oldChild);
18
+ }
19
+ if (this.child) {
20
+ overlay.addOverlay(this.child);
21
+ if (this.props.measure !== undefined) {
22
+ overlay.setMeasureOverlay(this.child, this.props.measure);
23
+ }
24
+ if (this.props.clipOverlay !== undefined) {
25
+ overlay.setClipOverlay(this.child, this.props.clipOverlay);
26
+ }
27
+ }
28
+ }
29
+ }
30
+ registerNodeClass(OverlayChildNode);
@@ -0,0 +1,21 @@
1
+ import type * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { Node } from "../node.js";
3
+ import { VirtualNode } from "./virtual.js";
4
+ type PackableWidget = Gtk.Widget & {
5
+ packStart(child: Gtk.Widget): void;
6
+ packEnd(child: Gtk.Widget): void;
7
+ remove(child: Gtk.Widget): void;
8
+ };
9
+ export declare class PackChild extends VirtualNode {
10
+ static priority: number;
11
+ static matches(type: string): boolean;
12
+ private parent?;
13
+ private children;
14
+ private getPosition;
15
+ setParent(newParent?: PackableWidget): void;
16
+ unmount(): void;
17
+ appendChild(child: Node): void;
18
+ insertBefore(child: Node): void;
19
+ removeChild(child: Node): void;
20
+ }
21
+ export {};
@@ -0,0 +1,68 @@
1
+ import { registerNodeClass } from "../registry.js";
2
+ import { scheduleAfterCommit } from "../scheduler.js";
3
+ import { VirtualNode } from "./virtual.js";
4
+ import { WidgetNode } from "./widget.js";
5
+ export class PackChild extends VirtualNode {
6
+ static priority = 1;
7
+ static matches(type) {
8
+ return type === "Pack.Start" || type === "Pack.End";
9
+ }
10
+ parent;
11
+ children = [];
12
+ getPosition() {
13
+ return this.typeName === "Pack.Start" ? "start" : "end";
14
+ }
15
+ setParent(newParent) {
16
+ this.parent = newParent;
17
+ }
18
+ unmount() {
19
+ const parent = this.parent;
20
+ const childrenToRemove = [...this.children];
21
+ if (parent && childrenToRemove.length > 0) {
22
+ scheduleAfterCommit(() => {
23
+ for (const widget of childrenToRemove) {
24
+ parent.remove(widget);
25
+ }
26
+ });
27
+ }
28
+ this.children = [];
29
+ this.parent = undefined;
30
+ super.unmount();
31
+ }
32
+ appendChild(child) {
33
+ if (!(child instanceof WidgetNode)) {
34
+ throw new Error(`Cannot append '${child.typeName}' to '${this.typeName}': expected Widget`);
35
+ }
36
+ const widget = child.container;
37
+ this.children.push(widget);
38
+ scheduleAfterCommit(() => {
39
+ if (this.parent) {
40
+ if (this.getPosition() === "start") {
41
+ this.parent.packStart(widget);
42
+ }
43
+ else {
44
+ this.parent.packEnd(widget);
45
+ }
46
+ }
47
+ });
48
+ }
49
+ insertBefore(child) {
50
+ this.appendChild(child);
51
+ }
52
+ removeChild(child) {
53
+ if (!(child instanceof WidgetNode)) {
54
+ throw new Error(`Cannot remove '${child.typeName}' from '${this.typeName}': expected Widget`);
55
+ }
56
+ const widget = child.container;
57
+ const index = this.children.indexOf(widget);
58
+ if (index !== -1) {
59
+ this.children.splice(index, 1);
60
+ }
61
+ scheduleAfterCommit(() => {
62
+ if (this.parent) {
63
+ this.parent.remove(widget);
64
+ }
65
+ });
66
+ }
67
+ }
68
+ registerNodeClass(PackChild);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { PackChild } from "./pack-child.js";
4
+ import { WidgetNode } from "./widget.js";
5
+ class PackNode extends WidgetNode {
6
+ static priority = 0;
7
+ static matches(_type, containerOrClass) {
8
+ if (!containerOrClass ||
9
+ (typeof containerOrClass !== "function" && !(containerOrClass instanceof Gtk.Widget))) {
10
+ return false;
11
+ }
12
+ const protoOrInstance = typeof containerOrClass === "function" ? containerOrClass.prototype : containerOrClass;
13
+ return "packStart" in protoOrInstance && "packEnd" in protoOrInstance && "remove" in protoOrInstance;
14
+ }
15
+ appendChild(child) {
16
+ if (child instanceof PackChild) {
17
+ child.setParent(this.container);
18
+ return;
19
+ }
20
+ super.appendChild(child);
21
+ }
22
+ insertBefore(child) {
23
+ this.appendChild(child);
24
+ }
25
+ removeChild(child) {
26
+ if (child instanceof PackChild) {
27
+ child.unmount();
28
+ return;
29
+ }
30
+ super.removeChild(child);
31
+ }
32
+ }
33
+ registerNodeClass(PackNode);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ import * as Gio from "@gtkx/ffi/gio";
2
+ import * as Gtk from "@gtkx/ffi/gtk";
3
+ import { registerNodeClass } from "../registry.js";
4
+ import { isContainerType } from "./internal/utils.js";
5
+ import { MenuNode } from "./menu.js";
6
+ import { Menu } from "./models/menu.js";
7
+ import { SlotNode } from "./slot.js";
8
+ import { WidgetNode } from "./widget.js";
9
+ const ACTION_PREFIX = "menu";
10
+ class PopoverMenuNode extends WidgetNode {
11
+ static priority = 1;
12
+ menu;
13
+ static matches(_type, containerOrClass) {
14
+ return (isContainerType(Gtk.PopoverMenu, containerOrClass) ||
15
+ isContainerType(Gtk.PopoverMenuBar, containerOrClass) ||
16
+ isContainerType(Gtk.MenuButton, containerOrClass));
17
+ }
18
+ constructor(typeName, props, container, rootContainer) {
19
+ super(typeName, props, container, rootContainer);
20
+ const application = rootContainer instanceof Gtk.Application ? rootContainer : undefined;
21
+ const actionGroup = new Gio.SimpleActionGroup();
22
+ const prefix = application ? "app" : ACTION_PREFIX;
23
+ this.container.insertActionGroup(prefix, actionGroup);
24
+ this.menu = new Menu("root", {}, actionGroup, application);
25
+ this.container.setMenuModel(this.menu.getMenu());
26
+ }
27
+ appendChild(child) {
28
+ if (child instanceof SlotNode || child instanceof WidgetNode) {
29
+ super.appendChild(child);
30
+ return;
31
+ }
32
+ if (!(child instanceof MenuNode)) {
33
+ throw new Error(`Cannot append '${child.typeName}' to 'PopoverMenu': expected MenuItem`);
34
+ }
35
+ this.menu.appendChild(child);
36
+ }
37
+ insertBefore(child, before) {
38
+ if (child instanceof SlotNode || child instanceof WidgetNode) {
39
+ super.insertBefore(child, before);
40
+ return;
41
+ }
42
+ if (!(child instanceof MenuNode)) {
43
+ throw new Error(`Cannot insert '${child.typeName}' to 'PopoverMenu': expected MenuItem`);
44
+ }
45
+ this.menu.insertBefore(child, before);
46
+ }
47
+ removeChild(child) {
48
+ if (child instanceof SlotNode || child instanceof WidgetNode) {
49
+ super.removeChild(child);
50
+ return;
51
+ }
52
+ if (!(child instanceof MenuNode)) {
53
+ throw new Error(`Cannot remove '${child.typeName}' from 'PopoverMenu': expected MenuItem`);
54
+ }
55
+ this.menu.removeChild(child);
56
+ }
57
+ }
58
+ registerNodeClass(PopoverMenuNode);
@@ -0,0 +1,9 @@
1
+ import type { StringListItemProps } from "../jsx.js";
2
+ import type { SimpleListStore } from "./internal/simple-list-store.js";
3
+ import { ListItemNode } from "./list-item.js";
4
+ type Props = Partial<StringListItemProps>;
5
+ export declare class SimpleListItemNode extends ListItemNode<SimpleListStore, Props> {
6
+ static priority: number;
7
+ static matches(type: string): boolean;
8
+ }
9
+ export {};
@@ -0,0 +1,9 @@
1
+ import { registerNodeClass } from "../registry.js";
2
+ import { ListItemNode } from "./list-item.js";
3
+ export class SimpleListItemNode extends ListItemNode {
4
+ static priority = -1;
5
+ static matches(type) {
6
+ return type === "SimpleListItem";
7
+ }
8
+ }
9
+ registerNodeClass(SimpleListItemNode);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
1
+ import * as Adw from "@gtkx/ffi/adw";
2
+ import * as Gtk from "@gtkx/ffi/gtk";
3
+ import { registerNodeClass } from "../registry.js";
4
+ import { SimpleListStore } from "./internal/simple-list-store.js";
5
+ import { filterProps, isContainerType } from "./internal/utils.js";
6
+ import { SimpleListItemNode } from "./simple-list-item.js";
7
+ import { WidgetNode } from "./widget.js";
8
+ const PROP_NAMES = ["selectedId", "onSelectionChanged"];
9
+ class SimpleListViewNode extends WidgetNode {
10
+ static priority = -1;
11
+ static matches(_type, containerOrClass) {
12
+ return isContainerType(Gtk.DropDown, containerOrClass) || isContainerType(Adw.ComboRow, containerOrClass);
13
+ }
14
+ store = new SimpleListStore();
15
+ constructor(typeName, props, container, rootContainer) {
16
+ super(typeName, props, container, rootContainer);
17
+ this.container.setModel(this.store.getModel());
18
+ }
19
+ updateProps(oldProps, newProps) {
20
+ if (!oldProps || oldProps.onSelectionChanged !== newProps.onSelectionChanged) {
21
+ const onSelectionChanged = newProps.onSelectionChanged;
22
+ const handleSelectionChange = onSelectionChanged
23
+ ? () => {
24
+ const selectedIndex = this.container.getSelected();
25
+ const id = this.store.getIdAtIndex(selectedIndex);
26
+ if (id !== undefined) {
27
+ onSelectionChanged(id);
28
+ }
29
+ }
30
+ : undefined;
31
+ this.signalStore.set(this.container, "notify::selected", handleSelectionChange);
32
+ }
33
+ if (!oldProps || oldProps.selectedId !== newProps.selectedId) {
34
+ const index = newProps.selectedId !== undefined ? this.store.getIndexById(newProps.selectedId) : undefined;
35
+ if (index !== undefined) {
36
+ this.container.setSelected(index);
37
+ }
38
+ }
39
+ super.updateProps(filterProps(oldProps ?? {}, PROP_NAMES), filterProps(newProps, PROP_NAMES));
40
+ }
41
+ appendChild(child) {
42
+ if (!(child instanceof SimpleListItemNode)) {
43
+ throw new Error(`Cannot append '${child.typeName}' to 'SimpleListView': expected SimpleListItem`);
44
+ }
45
+ const { id, value } = child.props;
46
+ if (!id || value === undefined) {
47
+ throw new Error("Expected 'id' and 'value' props to be present on SimpleListItem");
48
+ }
49
+ child.setStore(this.store);
50
+ this.store.addItem(id, value);
51
+ }
52
+ insertBefore(child, before) {
53
+ if (!(child instanceof SimpleListItemNode) || !(before instanceof SimpleListItemNode)) {
54
+ throw new Error(`Cannot insert '${child.typeName}' to 'SimpleListView': expected SimpleListItem`);
55
+ }
56
+ const { id, value } = child.props;
57
+ const beforeId = before.props.id;
58
+ if (!id || value === undefined || !beforeId) {
59
+ throw new Error("Expected 'id' and 'value' props to be present on SimpleListItem");
60
+ }
61
+ child.setStore(this.store);
62
+ this.store.insertItemBefore(id, beforeId, value);
63
+ }
64
+ removeChild(child) {
65
+ if (!(child instanceof SimpleListItemNode)) {
66
+ throw new Error(`Cannot remove '${child.typeName}' from 'SimpleListView': expected SimpleListItem`);
67
+ }
68
+ const { id } = child.props;
69
+ if (!id) {
70
+ throw new Error("Expected 'id' prop to be present on SimpleListItem");
71
+ }
72
+ this.store.removeItem(id);
73
+ }
74
+ }
75
+ registerNodeClass(SimpleListViewNode);
@@ -1,13 +1,21 @@
1
- import { Node } from "../node.js";
2
- export declare class SlotNode extends Node<never> {
1
+ import type * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { SlotProps } from "../jsx.js";
3
+ import type { Node } from "../node.js";
4
+ import { VirtualNode } from "./virtual.js";
5
+ type SlotNodeProps = Omit<SlotProps, "children">;
6
+ export declare class SlotNode<P extends SlotNodeProps = SlotNodeProps> extends VirtualNode<P> {
7
+ static priority: number;
3
8
  static matches(type: string): boolean;
4
- protected isVirtual(): boolean;
5
- private child;
6
- private slotName;
7
- constructor(type: string);
8
- private updateParentSlot;
9
- appendChild(child: Node): void;
10
- removeChild(child: Node): void;
11
- mount(): void;
9
+ parent?: Gtk.Widget;
10
+ child?: Gtk.Widget;
11
+ setParent(parent?: Gtk.Widget): void;
12
12
  unmount(): void;
13
+ protected getId(): string;
14
+ protected getParent(): Gtk.Widget;
15
+ getChild(): Gtk.Widget;
16
+ appendChild(child: Node): void;
17
+ removeChild(): void;
18
+ protected onChildChange(oldChild: Gtk.Widget | undefined): void;
19
+ private isDescendantOf;
13
20
  }
21
+ export {};