@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,22 +1,13 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
2
  import { Node } from "../node.js";
3
- import type { Container, Props } from "../types.js";
4
- import type { Attachable } from "./internal/predicates.js";
5
- export declare class EventControllerNode<T extends Gtk.EventController = Gtk.EventController> extends Node<T, Props> implements Attachable {
6
- static priority: number;
7
- static matches(type: string): boolean;
3
+ import type { Props } from "../types.js";
4
+ import { WidgetNode } from "./widget.js";
5
+ export declare class EventControllerNode<T extends Gtk.EventController = Gtk.EventController, TChild extends Node = any> extends Node<T, Props, WidgetNode, TChild> {
8
6
  static createContainer(props: Props, containerClass: typeof Gtk.EventController): Gtk.EventController;
9
- props: Props;
10
- protected parentWidget: Gtk.Widget | null;
11
- constructor(typeName: string, props: Props, container: T, rootContainer: Container);
12
- canBeChildOf(parent: Node): boolean;
13
- appendChild(_child: Node): void;
14
- removeChild(_child: Node): void;
15
- insertBefore(_child: Node, _before: Node): void;
16
- attachTo(parent: Node): void;
17
- detachFrom(_parent: Node): void;
18
- updateProps(oldProps: Props | null, newProps: Props): void;
19
- unmount(): void;
20
- private applyProps;
7
+ isValidParent(parent: Node): boolean;
8
+ setParent(parent: WidgetNode | null): void;
9
+ commitUpdate(oldProps: Props | null, newProps: Props): void;
10
+ detachDeletedInstance(): void;
11
+ private applyOwnProps;
21
12
  private setProperty;
22
13
  }
@@ -1,64 +1,43 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
- import { CONTROLLER_CLASSES, CONTROLLER_CONSTRUCTOR_PROPS } from "../generated/internal.js";
2
+ import { CONSTRUCTOR_PROPS } from "../generated/internal.js";
3
+ import { resolvePropMeta, resolveSignal } from "../metadata.js";
3
4
  import { Node } from "../node.js";
4
- import { registerNodeClass } from "../registry.js";
5
- import { propNameToSignalName, resolvePropMeta, resolveSignal } from "./internal/utils.js";
6
5
  import { WidgetNode } from "./widget.js";
7
6
  const G_TYPE_INVALID = 0;
8
7
  export class EventControllerNode extends Node {
9
- static priority = 1;
10
- static matches(type) {
11
- return type in CONTROLLER_CLASSES;
12
- }
13
8
  static createContainer(props, containerClass) {
14
9
  const typeName = containerClass.glibTypeName;
15
10
  if (typeName === "GtkDropTarget") {
16
11
  const actions = props.actions ?? 0;
17
12
  return new Gtk.DropTarget(G_TYPE_INVALID, actions);
18
13
  }
19
- const args = (CONTROLLER_CONSTRUCTOR_PROPS[typeName] ?? []).map((name) => props[name]);
14
+ const args = (CONSTRUCTOR_PROPS[typeName] ?? []).map((name) => props[name]);
20
15
  // biome-ignore lint/suspicious/noExplicitAny: Dynamic constructor invocation
21
16
  return new containerClass(...args);
22
17
  }
23
- props;
24
- parentWidget = null;
25
- constructor(typeName, props, container, rootContainer) {
26
- super(typeName, props, container, rootContainer);
27
- this.props = props;
28
- }
29
- canBeChildOf(parent) {
18
+ isValidParent(parent) {
30
19
  return parent instanceof WidgetNode;
31
20
  }
32
- appendChild(_child) { }
33
- removeChild(_child) { }
34
- insertBefore(_child, _before) { }
35
- attachTo(parent) {
36
- if (parent instanceof WidgetNode) {
37
- this.parentWidget = parent.container;
38
- parent.container.addController(this.container);
21
+ setParent(parent) {
22
+ if (!parent && this.parent) {
23
+ this.parent.container.removeController(this.container);
39
24
  }
40
- }
41
- detachFrom(_parent) {
42
- if (this.parentWidget) {
43
- this.parentWidget.removeController(this.container);
25
+ super.setParent(parent);
26
+ if (parent) {
27
+ parent.container.addController(this.container);
44
28
  }
45
- this.parentWidget = null;
46
29
  }
47
- updateProps(oldProps, newProps) {
48
- this.props = newProps;
49
- this.applyProps(oldProps, newProps);
30
+ commitUpdate(oldProps, newProps) {
31
+ super.commitUpdate(oldProps, newProps);
32
+ this.applyOwnProps(oldProps, newProps);
50
33
  }
51
- unmount() {
52
- if (this.parentWidget) {
53
- this.parentWidget.removeController(this.container);
34
+ detachDeletedInstance() {
35
+ if (this.parent && this.container.getWidget() === this.parent.container) {
36
+ this.parent.container.removeController(this.container);
54
37
  }
55
- this.parentWidget = null;
56
- super.unmount();
38
+ super.detachDeletedInstance();
57
39
  }
58
- applyProps(oldProps, newProps) {
59
- if (!this.container) {
60
- throw new Error(`EventControllerNode.applyProps: container is undefined for ${this.typeName}`);
61
- }
40
+ applyOwnProps(oldProps, newProps) {
62
41
  const propNames = new Set([...Object.keys(oldProps ?? {}), ...Object.keys(newProps ?? {})]);
63
42
  for (const name of propNames) {
64
43
  if (name === "children")
@@ -67,8 +46,8 @@ export class EventControllerNode extends Node {
67
46
  const newValue = newProps[name];
68
47
  if (oldValue === newValue)
69
48
  continue;
70
- const signalName = propNameToSignalName(name);
71
- if (resolveSignal(this.container, signalName)) {
49
+ const signalName = resolveSignal(this.container, name);
50
+ if (signalName) {
72
51
  const handler = typeof newValue === "function" ? newValue : undefined;
73
52
  this.signalStore.set(this, this.container, signalName, handler, { blockable: false });
74
53
  }
@@ -93,4 +72,3 @@ export class EventControllerNode extends Node {
93
72
  }
94
73
  }
95
74
  }
96
- registerNodeClass(EventControllerNode);
@@ -1 +1,18 @@
1
- export {};
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { FixedChildProps } 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 FixedChildNode extends VirtualNode<FixedChildProps, WidgetNode<Gtk.Fixed>, WidgetNode> {
7
+ isValidChild(child: Node): boolean;
8
+ isValidParent(parent: Node): boolean;
9
+ setParent(parent: WidgetNode<Gtk.Fixed> | null): void;
10
+ appendChild(child: WidgetNode): void;
11
+ removeChild(child: WidgetNode): void;
12
+ commitUpdate(oldProps: FixedChildProps | null, newProps: FixedChildProps): void;
13
+ detachDeletedInstance(): void;
14
+ private attachToParent;
15
+ private detachFromParent;
16
+ private repositionChild;
17
+ private applyTransform;
18
+ }
@@ -1,36 +1,40 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
- import { registerNodeClass } from "../registry.js";
3
- import { PositionalChildNode } from "./abstract/positional-child.js";
4
- import { hasChanged } from "./internal/utils.js";
5
- class FixedChildNode extends PositionalChildNode {
6
- static priority = 1;
7
- static matches(type) {
8
- return type === "FixedChild";
2
+ import { hasChanged } from "./internal/props.js";
3
+ import { VirtualNode } from "./virtual.js";
4
+ import { WidgetNode } from "./widget.js";
5
+ export class FixedChildNode extends VirtualNode {
6
+ isValidChild(child) {
7
+ return child instanceof WidgetNode;
9
8
  }
10
- canBeChildOf(parent) {
11
- return parent.container instanceof Gtk.Fixed;
9
+ isValidParent(parent) {
10
+ return parent instanceof WidgetNode && parent.container instanceof Gtk.Fixed;
12
11
  }
13
- onChildChange(oldChild) {
14
- super.onChildChange(oldChild);
15
- if (this.child) {
12
+ setParent(parent) {
13
+ if (!parent && this.parent && this.children[0]) {
14
+ this.detachFromParent(this.parent.container, this.children[0].container);
15
+ }
16
+ super.setParent(parent);
17
+ if (parent && this.children[0]) {
18
+ this.attachToParent(parent.container, this.children[0].container);
16
19
  this.applyTransform();
17
20
  }
18
21
  }
19
- attachToParent(parent, child) {
20
- const fixed = parent;
21
- const x = this.props.x ?? 0;
22
- const y = this.props.y ?? 0;
23
- fixed.put(child, x, y);
24
- }
25
- detachFromParent(parent, child) {
26
- parent.remove(child);
22
+ appendChild(child) {
23
+ super.appendChild(child);
24
+ if (this.parent) {
25
+ this.attachToParent(this.parent.container, child.container);
26
+ this.applyTransform();
27
+ }
27
28
  }
28
- updateProps(oldProps, newProps) {
29
- super.updateProps(oldProps, newProps);
30
- this.applyOwnProps(oldProps, newProps);
29
+ removeChild(child) {
30
+ if (this.parent) {
31
+ this.detachFromParent(this.parent.container, child.container);
32
+ }
33
+ super.removeChild(child);
31
34
  }
32
- applyOwnProps(oldProps, newProps) {
33
- if (!this.parent || !this.child) {
35
+ commitUpdate(oldProps, newProps) {
36
+ super.commitUpdate(oldProps, newProps);
37
+ if (!this.parent || !this.children[0]) {
34
38
  return;
35
39
  }
36
40
  const positionChanged = hasChanged(oldProps, newProps, "x") || hasChanged(oldProps, newProps, "y");
@@ -41,29 +45,41 @@ class FixedChildNode extends PositionalChildNode {
41
45
  this.applyTransform();
42
46
  }
43
47
  }
48
+ detachDeletedInstance() {
49
+ if (this.parent && this.children[0]) {
50
+ this.detachFromParent(this.parent.container, this.children[0].container);
51
+ }
52
+ super.detachDeletedInstance();
53
+ }
54
+ attachToParent(parent, child) {
55
+ const x = this.props.x ?? 0;
56
+ const y = this.props.y ?? 0;
57
+ parent.put(child, x, y);
58
+ }
59
+ detachFromParent(parent, child) {
60
+ const childParent = child.getParent();
61
+ if (childParent && childParent === parent) {
62
+ parent.remove(child);
63
+ }
64
+ }
44
65
  repositionChild() {
45
- const fixed = this.getTypedParent();
46
- const child = this.child;
47
- if (!child) {
66
+ if (!this.parent || !this.children[0])
48
67
  return;
49
- }
50
68
  const x = this.props.x ?? 0;
51
69
  const y = this.props.y ?? 0;
52
- fixed.remove(child);
53
- fixed.put(child, x, y);
70
+ this.parent.container.remove(this.children[0].container);
71
+ this.parent.container.put(this.children[0].container, x, y);
54
72
  this.applyTransform();
55
73
  }
56
74
  applyTransform() {
57
- if (!this.child || !this.props.transform) {
75
+ if (!this.parent || !this.children[0] || !this.props.transform) {
58
76
  return;
59
77
  }
60
- const fixed = this.getTypedParent();
61
- const layoutManager = fixed.getLayoutManager();
78
+ const layoutManager = this.parent.container.getLayoutManager();
62
79
  if (!layoutManager) {
63
80
  return;
64
81
  }
65
- const layoutChild = layoutManager.getLayoutChild(this.child);
82
+ const layoutChild = layoutManager.getLayoutChild(this.children[0].container);
66
83
  layoutChild.setTransform(this.props.transform);
67
84
  }
68
85
  }
69
- registerNodeClass(FixedChildNode);
@@ -1 +1,14 @@
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { GtkFontDialogButtonProps } from "../jsx.js";
3
+ import type { Container } from "../types.js";
4
+ import { WidgetNode } from "./widget.js";
5
+ declare const OWN_PROPS: readonly ["fontDesc", "onFontDescChanged", "title", "modal", "language", "useFont", "useSize", "level"];
6
+ type FontDialogButtonProps = Pick<GtkFontDialogButtonProps, (typeof OWN_PROPS)[number]>;
7
+ export declare class FontDialogButtonNode extends WidgetNode<Gtk.FontDialogButton, FontDialogButtonProps> {
8
+ private dialog;
9
+ static createContainer(_props: FontDialogButtonProps, containerClass: typeof Gtk.Widget): Container | null;
10
+ constructor(typeName: string, props: FontDialogButtonProps, container: Gtk.FontDialogButton, rootContainer: Container);
11
+ commitUpdate(oldProps: FontDialogButtonProps | null, newProps: FontDialogButtonProps): void;
12
+ private applyOwnProps;
13
+ }
1
14
  export {};
@@ -1,6 +1,5 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
- import { registerNodeClass } from "../registry.js";
3
- import { filterProps, hasChanged, matchesAnyClass } from "./internal/utils.js";
2
+ import { filterProps, hasChanged } from "./internal/props.js";
4
3
  import { WidgetNode } from "./widget.js";
5
4
  const OWN_PROPS = [
6
5
  "fontDesc",
@@ -12,33 +11,28 @@ const OWN_PROPS = [
12
11
  "useSize",
13
12
  "level",
14
13
  ];
15
- class FontDialogButtonNode extends WidgetNode {
16
- static priority = 1;
14
+ export class FontDialogButtonNode extends WidgetNode {
17
15
  dialog;
18
- notifyHandler = null;
19
- static matches(_type, containerOrClass) {
20
- return matchesAnyClass([Gtk.FontDialogButton], containerOrClass);
21
- }
22
16
  static createContainer(_props, containerClass) {
23
17
  const dialog = new Gtk.FontDialog();
24
18
  const button = new containerClass(dialog);
25
19
  return button;
26
20
  }
27
- constructor(type, props, container, rootContainer) {
28
- super(type, props, container, rootContainer);
21
+ constructor(typeName, props, container, rootContainer) {
22
+ super(typeName, props, container, rootContainer);
29
23
  const dialog = container.getDialog();
30
24
  if (!dialog) {
31
25
  throw new Error("FontDialogButton must have a dialog");
32
26
  }
33
27
  this.dialog = dialog;
34
28
  }
35
- updateProps(oldProps, newProps) {
36
- super.updateProps(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
29
+ commitUpdate(oldProps, newProps) {
30
+ super.commitUpdate(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
37
31
  this.applyOwnProps(oldProps, newProps);
38
32
  }
39
33
  applyOwnProps(oldProps, newProps) {
40
- if (hasChanged(oldProps, newProps, "title") && newProps.title !== undefined) {
41
- this.dialog.setTitle(newProps.title);
34
+ if (hasChanged(oldProps, newProps, "title")) {
35
+ this.dialog.setTitle(newProps.title ?? "");
42
36
  }
43
37
  if (hasChanged(oldProps, newProps, "modal")) {
44
38
  this.dialog.setModal(newProps.modal ?? true);
@@ -59,32 +53,15 @@ class FontDialogButtonNode extends WidgetNode {
59
53
  this.container.setFontDesc(newProps.fontDesc);
60
54
  }
61
55
  if (hasChanged(oldProps, newProps, "onFontDescChanged")) {
62
- this.setupNotifyHandler(newProps.onFontDescChanged);
63
- }
64
- }
65
- setupNotifyHandler(callback) {
66
- if (this.notifyHandler) {
67
- this.signalStore.set(this, this.container, "notify", undefined);
68
- this.notifyHandler = null;
69
- }
70
- if (callback) {
71
- this.notifyHandler = (_button, pspec) => {
72
- if (pspec.getName() === "font-desc") {
56
+ const callback = newProps.onFontDescChanged;
57
+ this.signalStore.set(this, this.container, "notify::font-desc", callback
58
+ ? () => {
73
59
  const fontDesc = this.container.getFontDesc();
74
60
  if (fontDesc) {
75
61
  callback(fontDesc);
76
62
  }
77
63
  }
78
- };
79
- this.signalStore.set(this, this.container, "notify", this.notifyHandler);
80
- }
81
- }
82
- unmount() {
83
- if (this.notifyHandler) {
84
- this.signalStore.set(this, this.container, "notify", undefined);
85
- this.notifyHandler = null;
64
+ : undefined);
86
65
  }
87
- super.unmount();
88
66
  }
89
67
  }
90
- registerNodeClass(FontDialogButtonNode);
@@ -1 +1,17 @@
1
- export {};
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { GridChildProps } 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 GridChildNode extends VirtualNode<GridChildProps, WidgetNode<Gtk.Grid>, WidgetNode> {
7
+ isValidChild(child: Node): boolean;
8
+ isValidParent(parent: Node): boolean;
9
+ setParent(parent: WidgetNode<Gtk.Grid> | null): void;
10
+ appendChild(child: WidgetNode): void;
11
+ removeChild(child: WidgetNode): void;
12
+ commitUpdate(oldProps: GridChildProps | null, newProps: GridChildProps): void;
13
+ detachDeletedInstance(): void;
14
+ private attachToParent;
15
+ private detachFromParent;
16
+ private reattachChild;
17
+ }
@@ -1,60 +1,80 @@
1
- import { isObjectEqual } from "@gtkx/ffi";
2
1
  import * as Gtk from "@gtkx/ffi/gtk";
3
- import { registerNodeClass } from "../registry.js";
4
- import { PositionalChildNode } from "./abstract/positional-child.js";
5
- import { hasChanged } from "./internal/utils.js";
6
- class GridChildNode extends PositionalChildNode {
7
- static priority = 1;
8
- static matches(type) {
9
- return type === "GridChild";
2
+ import { hasChanged } from "./internal/props.js";
3
+ import { VirtualNode } from "./virtual.js";
4
+ import { WidgetNode } from "./widget.js";
5
+ export class GridChildNode extends VirtualNode {
6
+ isValidChild(child) {
7
+ return child instanceof WidgetNode;
10
8
  }
11
- canBeChildOf(parent) {
12
- return parent.container instanceof Gtk.Grid;
9
+ isValidParent(parent) {
10
+ return parent instanceof WidgetNode && parent.container instanceof Gtk.Grid;
13
11
  }
14
- attachToParent(parent, child) {
15
- const grid = parent;
16
- const column = this.props.column ?? 0;
17
- const row = this.props.row ?? 0;
18
- const columnSpan = this.props.columnSpan ?? 1;
19
- const rowSpan = this.props.rowSpan ?? 1;
20
- const existingChild = grid.getChildAt(column, row);
21
- if (existingChild && !isObjectEqual(existingChild, child)) {
22
- grid.remove(existingChild);
12
+ setParent(parent) {
13
+ if (!parent && this.parent && this.children[0]) {
14
+ this.detachFromParent(this.parent.container, this.children[0].container);
15
+ }
16
+ super.setParent(parent);
17
+ if (parent && this.children[0]) {
18
+ this.attachToParent(parent.container, this.children[0].container);
23
19
  }
24
- grid.attach(child, column, row, columnSpan, rowSpan);
25
20
  }
26
- detachFromParent(parent, child) {
27
- parent.remove(child);
21
+ appendChild(child) {
22
+ super.appendChild(child);
23
+ if (this.parent) {
24
+ this.attachToParent(this.parent.container, child.container);
25
+ }
28
26
  }
29
- updateProps(oldProps, newProps) {
30
- super.updateProps(oldProps, newProps);
31
- this.applyOwnProps(oldProps, newProps);
27
+ removeChild(child) {
28
+ if (this.parent) {
29
+ this.detachFromParent(this.parent.container, child.container);
30
+ }
31
+ super.removeChild(child);
32
32
  }
33
- applyOwnProps(oldProps, newProps) {
33
+ commitUpdate(oldProps, newProps) {
34
+ super.commitUpdate(oldProps, newProps);
34
35
  const positionChanged = hasChanged(oldProps, newProps, "column") ||
35
36
  hasChanged(oldProps, newProps, "row") ||
36
37
  hasChanged(oldProps, newProps, "columnSpan") ||
37
38
  hasChanged(oldProps, newProps, "rowSpan");
38
- if (positionChanged && this.parent && this.child) {
39
+ if (positionChanged && this.parent && this.children[0]) {
39
40
  this.reattachChild();
40
41
  }
41
42
  }
43
+ detachDeletedInstance() {
44
+ if (this.parent && this.children[0]) {
45
+ this.detachFromParent(this.parent.container, this.children[0].container);
46
+ }
47
+ super.detachDeletedInstance();
48
+ }
49
+ attachToParent(parent, child) {
50
+ const column = this.props.column ?? 0;
51
+ const row = this.props.row ?? 0;
52
+ const columnSpan = this.props.columnSpan ?? 1;
53
+ const rowSpan = this.props.rowSpan ?? 1;
54
+ const existingChild = parent.getChildAt(column, row);
55
+ if (existingChild && existingChild !== child) {
56
+ parent.remove(existingChild);
57
+ }
58
+ parent.attach(child, column, row, columnSpan, rowSpan);
59
+ }
60
+ detachFromParent(parent, child) {
61
+ const childParent = child.getParent();
62
+ if (childParent && childParent === parent) {
63
+ parent.remove(child);
64
+ }
65
+ }
42
66
  reattachChild() {
43
- const grid = this.getTypedParent();
44
- const child = this.child;
45
- if (!child) {
67
+ if (!this.parent || !this.children[0])
46
68
  return;
47
- }
48
69
  const column = this.props.column ?? 0;
49
70
  const row = this.props.row ?? 0;
50
71
  const columnSpan = this.props.columnSpan ?? 1;
51
72
  const rowSpan = this.props.rowSpan ?? 1;
52
- const existingChild = grid.getChildAt(column, row);
53
- if (existingChild && !isObjectEqual(existingChild, child)) {
54
- grid.remove(existingChild);
73
+ const existingChild = this.parent.container.getChildAt(column, row);
74
+ if (existingChild && existingChild !== this.children[0].container) {
75
+ this.parent.container.remove(existingChild);
55
76
  }
56
- grid.remove(child);
57
- grid.attach(child, column, row, columnSpan, rowSpan);
77
+ this.parent.container.remove(this.children[0].container);
78
+ this.parent.container.attach(this.children[0].container, column, row, columnSpan, rowSpan);
58
79
  }
59
80
  }
60
- registerNodeClass(GridChildNode);
@@ -0,0 +1,24 @@
1
+ import type * as Gtk from "@gtkx/ffi/gtk";
2
+ import type { GtkGridViewProps } from "../jsx.js";
3
+ import type { Node } from "../node.js";
4
+ import type { Container } from "../types.js";
5
+ import { ListItemNode } from "./list-item.js";
6
+ import { type GridModelProps } from "./models/grid.js";
7
+ import { WidgetNode } from "./widget.js";
8
+ declare const OWN_PROPS: readonly ["renderItem", "estimatedItemHeight"];
9
+ type GridViewProps = Pick<GtkGridViewProps, (typeof OWN_PROPS)[number]> & GridModelProps;
10
+ export declare class GridViewNode extends WidgetNode<Gtk.GridView, GridViewProps, ListItemNode> {
11
+ private itemRenderer;
12
+ private grid;
13
+ constructor(typeName: string, props: GridViewProps, container: Gtk.GridView, rootContainer: Container);
14
+ isValidChild(child: Node): boolean;
15
+ appendChild(child: ListItemNode): void;
16
+ insertBefore(child: ListItemNode, before: ListItemNode): void;
17
+ removeChild(child: ListItemNode): void;
18
+ finalizeInitialChildren(props: GridViewProps): boolean;
19
+ commitUpdate(oldProps: GridViewProps | null, newProps: GridViewProps): void;
20
+ commitMount(): void;
21
+ detachDeletedInstance(): void;
22
+ private applyOwnProps;
23
+ }
24
+ export {};
@@ -0,0 +1,73 @@
1
+ import { GridItemRenderer } from "./internal/grid-item-renderer.js";
2
+ import { filterProps, hasChanged } from "./internal/props.js";
3
+ import { ListItemNode } from "./list-item.js";
4
+ import { GridModel } from "./models/grid.js";
5
+ import { WidgetNode } from "./widget.js";
6
+ const OWN_PROPS = ["renderItem", "estimatedItemHeight"];
7
+ export class GridViewNode extends WidgetNode {
8
+ itemRenderer;
9
+ grid;
10
+ constructor(typeName, props, container, rootContainer) {
11
+ super(typeName, props, container, rootContainer);
12
+ this.grid = new GridModel({ owner: this, signalStore: this.signalStore }, {
13
+ selectionMode: props.selectionMode,
14
+ selected: props.selected,
15
+ onSelectionChanged: props.onSelectionChanged,
16
+ });
17
+ this.itemRenderer = new GridItemRenderer(this.signalStore);
18
+ this.itemRenderer.setStore(this.grid.getStore());
19
+ this.grid.getStore().setOnItemUpdated((id) => this.itemRenderer.rebindItem(id));
20
+ this.container.setFactory(this.itemRenderer.getFactory());
21
+ }
22
+ isValidChild(child) {
23
+ if (!(child instanceof ListItemNode))
24
+ return false;
25
+ if (child.getChildNodes().length > 0) {
26
+ throw new Error("GtkGridView does not support nested ListItems. Use GtkListView for tree lists.");
27
+ }
28
+ return true;
29
+ }
30
+ appendChild(child) {
31
+ super.appendChild(child);
32
+ this.grid.appendChild(child);
33
+ }
34
+ insertBefore(child, before) {
35
+ super.insertBefore(child, before);
36
+ this.grid.insertBefore(child, before);
37
+ }
38
+ removeChild(child) {
39
+ this.grid.removeChild(child);
40
+ super.removeChild(child);
41
+ }
42
+ finalizeInitialChildren(props) {
43
+ super.finalizeInitialChildren(props);
44
+ return true;
45
+ }
46
+ commitUpdate(oldProps, newProps) {
47
+ super.commitUpdate(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
48
+ this.applyOwnProps(oldProps, newProps);
49
+ }
50
+ commitMount() {
51
+ super.commitMount();
52
+ this.grid.flushBatch();
53
+ this.container.setModel(this.grid.getSelectionModel());
54
+ }
55
+ detachDeletedInstance() {
56
+ this.itemRenderer.dispose();
57
+ super.detachDeletedInstance();
58
+ }
59
+ applyOwnProps(oldProps, newProps) {
60
+ if (hasChanged(oldProps, newProps, "renderItem")) {
61
+ this.itemRenderer.setRenderFn(newProps.renderItem ?? null);
62
+ }
63
+ if (hasChanged(oldProps, newProps, "estimatedItemHeight")) {
64
+ this.itemRenderer.setEstimatedItemHeight(newProps.estimatedItemHeight ?? null);
65
+ }
66
+ const previousModel = this.grid.getSelectionModel();
67
+ this.grid.updateProps(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
68
+ const currentModel = this.grid.getSelectionModel();
69
+ if (previousModel !== currentModel) {
70
+ this.container.setModel(currentModel);
71
+ }
72
+ }
73
+ }
@@ -4,25 +4,23 @@ import type Reconciler from "react-reconciler";
4
4
  import type { SignalStore } from "./signal-store.js";
5
5
  export declare abstract class BaseItemRenderer<TStore = unknown> {
6
6
  protected factory: Gtk.SignalListItemFactory;
7
- protected fiberRoots: Map<number, any>;
8
- protected tornDown: Set<number>;
7
+ protected fiberRoots: Map<Gtk.ListItem, any>;
8
+ protected tornDown: Set<Gtk.ListItem>;
9
9
  protected estimatedItemHeight: number | null;
10
10
  private store;
11
11
  protected signalStore: SignalStore;
12
- protected abstract getStoreTypeName(): string;
13
12
  constructor(signalStore: SignalStore);
14
13
  getFactory(): Gtk.SignalListItemFactory;
15
14
  setEstimatedItemHeight(height: number | null): void;
16
15
  setStore(store: TStore | null): void;
17
16
  protected getStore(): TStore;
18
17
  dispose(): void;
19
- protected abstract renderItem(ptr: number): ReactNode;
20
- protected abstract getItemFromListItem(listItem: Gtk.ListItem): unknown;
21
- protected abstract onSetup(listItem: Gtk.ListItem, ptr: number): Gtk.Widget;
22
- protected abstract onBind(listItem: Gtk.ListItem, ptr: number, fiberRoot: Reconciler.FiberRoot): void;
18
+ protected abstract renderItem(listItem: Gtk.ListItem): ReactNode;
19
+ protected abstract onSetup(listItem: Gtk.ListItem): Gtk.Widget;
20
+ protected abstract onBind(listItem: Gtk.ListItem, fiberRoot: Reconciler.FiberRoot): void;
23
21
  protected abstract onUnbind(listItem: Gtk.ListItem): void;
24
- protected abstract onTeardown(listItem: Gtk.ListItem, ptr: number): void;
25
- protected onSetupComplete(_ptr: number): void;
22
+ protected onSetupComplete(_listItem: Gtk.ListItem): void;
23
+ protected onTeardown(_listItem: Gtk.ListItem): void;
26
24
  protected createBox(): Gtk.Box;
27
25
  protected clearBoxSizeRequest(box: Gtk.Widget): void;
28
26
  private initializeFactory;