@gtkx/react 0.14.0 → 0.16.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 +28 -27
  2. package/dist/errors.js +3 -0
  3. package/dist/factory.d.ts +3 -2
  4. package/dist/factory.js +1 -1
  5. package/dist/generated/internal.d.ts +28 -1
  6. package/dist/generated/internal.js +93 -18
  7. package/dist/generated/jsx.d.ts +1712 -1516
  8. package/dist/generated/jsx.js +475 -0
  9. package/dist/host-config.d.ts +3 -1
  10. package/dist/host-config.js +31 -11
  11. package/dist/jsx.d.ts +147 -97
  12. package/dist/jsx.js +89 -21
  13. package/dist/node.d.ts +3 -1
  14. package/dist/node.js +5 -3
  15. package/dist/nodes/abstract/positional-child.d.ts +9 -0
  16. package/dist/nodes/abstract/positional-child.js +29 -0
  17. package/dist/nodes/abstract/positional-parent.d.ts +18 -0
  18. package/dist/nodes/abstract/positional-parent.js +48 -0
  19. package/dist/nodes/abstract/virtual-container.d.ts +17 -0
  20. package/dist/nodes/abstract/virtual-container.js +59 -0
  21. package/dist/nodes/abstract/virtual-single-child.d.ts +18 -0
  22. package/dist/nodes/abstract/virtual-single-child.js +54 -0
  23. package/dist/nodes/action-row-child.d.ts +0 -13
  24. package/dist/nodes/action-row-child.js +14 -12
  25. package/dist/nodes/action-row.d.ts +6 -1
  26. package/dist/nodes/action-row.js +4 -37
  27. package/dist/nodes/adjustable.d.ts +23 -0
  28. package/dist/nodes/adjustable.js +62 -0
  29. package/dist/nodes/alert-dialog-response.d.ts +1 -0
  30. package/dist/nodes/alert-dialog-response.js +86 -0
  31. package/dist/nodes/animation/animation-controller.d.ts +17 -0
  32. package/dist/nodes/animation/animation-controller.js +107 -0
  33. package/dist/nodes/animation/animation-factory.d.ts +15 -0
  34. package/dist/nodes/animation/animation-factory.js +25 -0
  35. package/dist/nodes/animation/animation-node.d.ts +9 -0
  36. package/dist/nodes/animation/animation-node.js +126 -0
  37. package/dist/nodes/animation/animation-style-sheet.d.ts +16 -0
  38. package/dist/nodes/animation/animation-style-sheet.js +74 -0
  39. package/dist/nodes/animation/index.d.ts +4 -0
  40. package/dist/nodes/animation/index.js +1 -0
  41. package/dist/nodes/animation/property-mapper.d.ts +11 -0
  42. package/dist/nodes/animation/property-mapper.js +36 -0
  43. package/dist/nodes/animation/transform-state.d.ts +11 -0
  44. package/dist/nodes/animation/transform-state.js +57 -0
  45. package/dist/nodes/animation/widget-registry.d.ts +5 -0
  46. package/dist/nodes/animation/widget-registry.js +42 -0
  47. package/dist/nodes/application.js +17 -7
  48. package/dist/nodes/autowrapped.js +37 -43
  49. package/dist/nodes/calendar.js +16 -55
  50. package/dist/nodes/color-dialog-button.d.ts +1 -0
  51. package/dist/nodes/color-dialog-button.js +70 -0
  52. package/dist/nodes/column-view-column.d.ts +4 -3
  53. package/dist/nodes/column-view-column.js +5 -1
  54. package/dist/nodes/column-view.js +40 -43
  55. package/dist/nodes/dialog.d.ts +11 -0
  56. package/dist/nodes/dialog.js +20 -0
  57. package/dist/nodes/drawing-area.d.ts +1 -0
  58. package/dist/nodes/drawing-area.js +36 -0
  59. package/dist/nodes/event-controller.d.ts +1 -0
  60. package/dist/nodes/event-controller.js +96 -0
  61. package/dist/nodes/expander-row-child.d.ts +0 -14
  62. package/dist/nodes/expander-row-child.js +14 -12
  63. package/dist/nodes/expander-row.d.ts +6 -1
  64. package/dist/nodes/expander-row.js +11 -47
  65. package/dist/nodes/fixed-child.js +48 -36
  66. package/dist/nodes/font-dialog-button.d.ts +1 -0
  67. package/dist/nodes/font-dialog-button.js +90 -0
  68. package/dist/nodes/grid-child.js +39 -45
  69. package/dist/nodes/grid.d.ts +1 -0
  70. package/dist/nodes/grid.js +41 -0
  71. package/dist/nodes/index.d.ts +22 -6
  72. package/dist/nodes/index.js +22 -6
  73. package/dist/nodes/internal/base-item-renderer.d.ts +29 -0
  74. package/dist/nodes/internal/base-item-renderer.js +88 -0
  75. package/dist/nodes/internal/base-store.d.ts +9 -0
  76. package/dist/nodes/internal/base-store.js +20 -0
  77. package/dist/nodes/internal/child-attachment.d.ts +26 -0
  78. package/dist/nodes/internal/child-attachment.js +48 -0
  79. package/dist/nodes/internal/deferred-action.d.ts +8 -0
  80. package/dist/nodes/internal/deferred-action.js +19 -0
  81. package/dist/nodes/internal/list-item-renderer.d.ts +14 -14
  82. package/dist/nodes/internal/list-item-renderer.js +49 -70
  83. package/dist/nodes/internal/list-store.d.ts +7 -6
  84. package/dist/nodes/internal/list-store.js +20 -24
  85. package/dist/nodes/internal/predicates.d.ts +28 -1
  86. package/dist/nodes/internal/predicates.js +53 -38
  87. package/dist/nodes/internal/selection-model.d.ts +30 -0
  88. package/dist/nodes/internal/selection-model.js +91 -0
  89. package/dist/nodes/internal/signal-store.d.ts +5 -3
  90. package/dist/nodes/internal/signal-store.js +30 -21
  91. package/dist/nodes/internal/simple-list-store.js +6 -9
  92. package/dist/nodes/internal/text-buffer-controller.d.ts +43 -0
  93. package/dist/nodes/internal/text-buffer-controller.js +287 -0
  94. package/dist/nodes/internal/text-tag-styles.d.ts +43 -0
  95. package/dist/nodes/internal/text-tag-styles.js +52 -0
  96. package/dist/nodes/internal/tree-list-item-renderer.d.ts +16 -14
  97. package/dist/nodes/internal/tree-list-item-renderer.js +88 -91
  98. package/dist/nodes/internal/tree-store.d.ts +10 -9
  99. package/dist/nodes/internal/tree-store.js +31 -35
  100. package/dist/nodes/internal/utils.d.ts +7 -4
  101. package/dist/nodes/internal/utils.js +50 -5
  102. package/dist/nodes/level-bar.js +18 -66
  103. package/dist/nodes/list-item.d.ts +6 -3
  104. package/dist/nodes/list-item.js +7 -4
  105. package/dist/nodes/list-view.js +19 -11
  106. package/dist/nodes/menu.d.ts +3 -3
  107. package/dist/nodes/menu.js +3 -3
  108. package/dist/nodes/models/list.d.ts +11 -13
  109. package/dist/nodes/models/list.js +16 -73
  110. package/dist/nodes/models/menu.d.ts +8 -7
  111. package/dist/nodes/models/menu.js +43 -50
  112. package/dist/nodes/models/tree-list.d.ts +6 -12
  113. package/dist/nodes/models/tree-list.js +30 -93
  114. package/dist/nodes/navigation-page.d.ts +1 -0
  115. package/dist/nodes/navigation-page.js +7 -3
  116. package/dist/nodes/navigation-view.js +17 -28
  117. package/dist/nodes/notebook-page-tab.d.ts +4 -3
  118. package/dist/nodes/notebook-page-tab.js +5 -2
  119. package/dist/nodes/notebook-page.d.ts +7 -5
  120. package/dist/nodes/notebook-page.js +39 -16
  121. package/dist/nodes/notebook.js +2 -2
  122. package/dist/nodes/overlay-child.js +90 -30
  123. package/dist/nodes/pack-child.d.ts +0 -13
  124. package/dist/nodes/pack-child.js +14 -12
  125. package/dist/nodes/pack.d.ts +6 -1
  126. package/dist/nodes/pack.js +4 -37
  127. package/dist/nodes/popover-menu.js +2 -2
  128. package/dist/nodes/scale.js +15 -58
  129. package/dist/nodes/scrolled-window.js +7 -5
  130. package/dist/nodes/search-bar.d.ts +1 -0
  131. package/dist/nodes/search-bar.js +40 -0
  132. package/dist/nodes/shortcut-controller.d.ts +1 -0
  133. package/dist/nodes/shortcut-controller.js +90 -0
  134. package/dist/nodes/shortcut.d.ts +39 -0
  135. package/dist/nodes/shortcut.js +52 -0
  136. package/dist/nodes/simple-list-view.js +2 -3
  137. package/dist/nodes/slot.d.ts +6 -9
  138. package/dist/nodes/slot.js +27 -42
  139. package/dist/nodes/source-view.d.ts +1 -0
  140. package/dist/nodes/source-view.js +93 -0
  141. package/dist/nodes/stack-page.js +17 -13
  142. package/dist/nodes/stack.js +19 -5
  143. package/dist/nodes/text-anchor.d.ts +41 -0
  144. package/dist/nodes/text-anchor.js +59 -0
  145. package/dist/nodes/text-content.d.ts +10 -0
  146. package/dist/nodes/text-content.js +1 -0
  147. package/dist/nodes/text-paintable.d.ts +17 -0
  148. package/dist/nodes/text-paintable.js +34 -0
  149. package/dist/nodes/text-segment.d.ts +15 -0
  150. package/dist/nodes/text-segment.js +29 -0
  151. package/dist/nodes/text-tag.d.ts +136 -0
  152. package/dist/nodes/text-tag.js +202 -0
  153. package/dist/nodes/text-view.d.ts +31 -0
  154. package/dist/nodes/text-view.js +73 -0
  155. package/dist/nodes/toggle-group.js +24 -32
  156. package/dist/nodes/toggle.d.ts +1 -15
  157. package/dist/nodes/toggle.js +40 -32
  158. package/dist/nodes/toolbar-child.js +14 -16
  159. package/dist/nodes/tree-list-item.d.ts +7 -5
  160. package/dist/nodes/tree-list-item.js +24 -36
  161. package/dist/nodes/tree-list-view.js +9 -4
  162. package/dist/nodes/virtual.d.ts +1 -1
  163. package/dist/nodes/widget.d.ts +3 -13
  164. package/dist/nodes/widget.js +117 -231
  165. package/dist/nodes/window.d.ts +9 -3
  166. package/dist/nodes/window.js +35 -19
  167. package/dist/registry.d.ts +1 -1
  168. package/dist/render.js +8 -6
  169. package/dist/scheduler.d.ts +11 -1
  170. package/dist/scheduler.js +16 -4
  171. package/dist/types.d.ts +2 -110
  172. package/package.json +3 -3
  173. package/dist/nodes/calendar-mark.d.ts +0 -15
  174. package/dist/nodes/calendar-mark.js +0 -29
  175. package/dist/nodes/internal/constants.d.ts +0 -1
  176. package/dist/nodes/internal/constants.js +0 -21
  177. package/dist/nodes/level-bar-offset.d.ts +0 -13
  178. package/dist/nodes/level-bar-offset.js +0 -35
  179. package/dist/nodes/scale-mark.d.ts +0 -17
  180. package/dist/nodes/scale-mark.js +0 -38
  181. package/dist/nodes/virtual-child.d.ts +0 -18
  182. package/dist/nodes/virtual-child.js +0 -62
@@ -1,18 +1,19 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
2
  import { registerNodeClass } from "../registry.js";
3
- import { scheduleAfterCommit } from "../scheduler.js";
3
+ import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
4
+ import { hasChanged } from "./internal/utils.js";
4
5
  import { NotebookPageTabNode } from "./notebook-page-tab.js";
5
6
  import { SlotNode } from "./slot.js";
6
7
  import { WidgetNode } from "./widget.js";
7
8
  export class NotebookPageNode extends SlotNode {
8
9
  static priority = 1;
9
- position;
10
- tabNode;
10
+ position = null;
11
+ tabNode = null;
11
12
  static matches(type) {
12
13
  return type === "NotebookPage";
13
14
  }
14
- setNotebook(notebook) {
15
- this.setParent(notebook);
15
+ setParent(parent) {
16
+ super.setParent(parent);
16
17
  this.updateTabNode();
17
18
  }
18
19
  setPosition(position) {
@@ -34,7 +35,7 @@ export class NotebookPageNode extends SlotNode {
34
35
  this.tabNode = child;
35
36
  scheduleAfterCommit(() => {
36
37
  this.updateTabNode();
37
- });
38
+ }, CommitPriority.NORMAL);
38
39
  return;
39
40
  }
40
41
  if (!(child instanceof WidgetNode)) {
@@ -47,26 +48,31 @@ export class NotebookPageNode extends SlotNode {
47
48
  this.onChildChange(oldChild ?? null);
48
49
  }
49
50
  this.updateTabNode();
50
- });
51
+ }, CommitPriority.NORMAL);
51
52
  }
52
53
  removeChild(child) {
53
54
  if (child instanceof NotebookPageTabNode) {
54
- this.tabNode = undefined;
55
+ this.tabNode = null;
55
56
  return;
56
57
  }
57
- super.removeChild();
58
+ super.removeChild(child);
58
59
  }
59
60
  unmount() {
60
- this.tabNode = undefined;
61
+ this.tabNode = null;
61
62
  super.unmount();
62
63
  }
63
64
  updateProps(oldProps, newProps) {
64
65
  super.updateProps(oldProps, newProps);
65
- if (!oldProps || oldProps.label !== newProps.label) {
66
- if (this.child && this.parent && !this.tabNode?.child) {
67
- const tabLabel = this.getNotebook().getTabLabel(this.child);
68
- tabLabel.setLabel(newProps.label ?? "");
69
- }
66
+ this.applyOwnProps(oldProps, newProps);
67
+ }
68
+ applyOwnProps(oldProps, newProps) {
69
+ if (hasChanged(oldProps, newProps, "label") && this.child && this.parent && !this.tabNode?.child) {
70
+ const tabLabel = this.getNotebook().getTabLabel(this.child);
71
+ tabLabel.setLabel(newProps.label ?? "");
72
+ }
73
+ const pagePropsChanged = hasChanged(oldProps, newProps, "tabExpand") || hasChanged(oldProps, newProps, "tabFill");
74
+ if (this.child && this.parent && pagePropsChanged) {
75
+ this.applyPageProps();
70
76
  }
71
77
  }
72
78
  attachPage() {
@@ -83,9 +89,26 @@ export class NotebookPageNode extends SlotNode {
83
89
  }
84
90
  if (this.position != null) {
85
91
  notebook.insertPage(child, this.position, tabLabel);
92
+ }
93
+ else {
94
+ notebook.appendPage(child, tabLabel);
95
+ }
96
+ this.applyPageProps();
97
+ }
98
+ applyPageProps() {
99
+ const child = this.child;
100
+ if (!child || !this.parent)
86
101
  return;
102
+ const notebook = this.getNotebook();
103
+ const page = notebook.getPage(child);
104
+ if (!page)
105
+ return;
106
+ if (this.props.tabExpand !== undefined) {
107
+ page.setTabExpand(this.props.tabExpand);
108
+ }
109
+ if (this.props.tabFill !== undefined) {
110
+ page.setTabFill(this.props.tabFill);
87
111
  }
88
- notebook.appendPage(child, tabLabel);
89
112
  }
90
113
  detachPage(childToDetach) {
91
114
  const notebook = this.getNotebook();
@@ -12,7 +12,7 @@ class NotebookNode extends WidgetNode {
12
12
  if (!(child instanceof NotebookPageNode)) {
13
13
  throw new Error(`Cannot append '${child.typeName}' to 'Notebook': expected x.NotebookPage`);
14
14
  }
15
- child.setNotebook(this.container);
15
+ child.setParent(this.container);
16
16
  }
17
17
  insertBefore(child, before) {
18
18
  if (!(child instanceof NotebookPageNode) || !(before instanceof NotebookPageNode)) {
@@ -20,7 +20,7 @@ class NotebookNode extends WidgetNode {
20
20
  }
21
21
  const beforePosition = this.container.pageNum(before.getChild());
22
22
  child.setPosition(beforePosition);
23
- child.setNotebook(this.container);
23
+ child.setParent(this.container);
24
24
  }
25
25
  removeChild(child) {
26
26
  if (!(child instanceof NotebookPageNode)) {
@@ -1,49 +1,109 @@
1
- import { batch, isObjectEqual } from "@gtkx/ffi";
1
+ import { isObjectEqual } from "@gtkx/ffi";
2
2
  import { registerNodeClass } from "../registry.js";
3
- import { SlotNode } from "./slot.js";
4
- class OverlayChildNode extends SlotNode {
3
+ import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
4
+ import { VirtualNode } from "./virtual.js";
5
+ import { WidgetNode } from "./widget.js";
6
+ class OverlayChildNode extends VirtualNode {
5
7
  static priority = 1;
6
8
  static matches(type) {
7
9
  return type === "OverlayChild";
8
10
  }
9
- getOverlay() {
10
- if (!this.parent) {
11
- throw new Error("Expected parent widget to be set on OverlayChildNode");
11
+ parent = null;
12
+ children = new Set();
13
+ canBeChildOf(parent) {
14
+ return parent instanceof WidgetNode;
15
+ }
16
+ attachTo(parent) {
17
+ if (parent instanceof WidgetNode) {
18
+ this.parent = parent.container;
12
19
  }
13
- return this.parent;
14
20
  }
15
- updateProps(oldProps, newProps) {
16
- super.updateProps(oldProps, newProps);
17
- if (!this.parent || !this.child) {
18
- return;
21
+ detachFrom(_parent) { }
22
+ unmount() {
23
+ if (this.parent && this.children.size > 0) {
24
+ const parent = this.parent;
25
+ const children = [...this.children];
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
+ }
32
+ }
19
33
  }
20
- const overlay = this.getOverlay();
21
- if (!oldProps || oldProps.measure !== newProps.measure) {
22
- overlay.setMeasureOverlay(this.child, newProps.measure ?? false);
34
+ this.parent = null;
35
+ super.unmount();
36
+ }
37
+ appendChild(child) {
38
+ if (!(child instanceof WidgetNode)) {
39
+ throw new Error(`Cannot append '${child.typeName}' to '${this.typeName}': expected Widget`);
23
40
  }
24
- if (!oldProps || oldProps.clipOverlay !== newProps.clipOverlay) {
25
- overlay.setClipOverlay(this.child, newProps.clipOverlay ?? false);
41
+ const widget = child.container;
42
+ this.children.add(widget);
43
+ scheduleAfterCommit(() => {
44
+ if (this.parent) {
45
+ this.attachChild(widget);
46
+ }
47
+ }, CommitPriority.NORMAL);
48
+ }
49
+ insertBefore(child, _before) {
50
+ if (!(child instanceof WidgetNode)) {
51
+ throw new Error(`Cannot insert '${child.typeName}' into '${this.typeName}': expected Widget`);
26
52
  }
53
+ const widget = child.container;
54
+ this.children.add(widget);
55
+ scheduleAfterCommit(() => {
56
+ if (this.parent) {
57
+ this.attachChild(widget);
58
+ }
59
+ }, CommitPriority.NORMAL);
27
60
  }
28
- onChildChange(oldChild) {
29
- const overlay = this.getOverlay();
30
- batch(() => {
31
- if (oldChild) {
32
- const parent = oldChild.getParent();
33
- if (parent && isObjectEqual(parent, overlay)) {
34
- overlay.removeOverlay(oldChild);
61
+ 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(widget);
68
+ scheduleAfterCommit(() => {
69
+ if (parent) {
70
+ const currentParent = widget.getParent();
71
+ if (currentParent && isObjectEqual(currentParent, parent)) {
72
+ parent.removeOverlay(widget);
35
73
  }
36
74
  }
37
- if (this.child) {
38
- overlay.addOverlay(this.child);
39
- if (this.props.measure !== undefined) {
40
- overlay.setMeasureOverlay(this.child, this.props.measure);
75
+ }, CommitPriority.HIGH);
76
+ }
77
+ updateProps(oldProps, newProps) {
78
+ super.updateProps(oldProps, newProps);
79
+ if (!this.parent) {
80
+ return;
81
+ }
82
+ const measureChanged = oldProps?.measure !== newProps.measure;
83
+ const clipOverlayChanged = oldProps?.clipOverlay !== newProps.clipOverlay;
84
+ if (measureChanged || clipOverlayChanged) {
85
+ const parent = this.parent;
86
+ for (const child of this.children) {
87
+ if (measureChanged) {
88
+ parent.setMeasureOverlay(child, newProps.measure ?? false);
41
89
  }
42
- if (this.props.clipOverlay !== undefined) {
43
- overlay.setClipOverlay(this.child, this.props.clipOverlay);
90
+ if (clipOverlayChanged) {
91
+ parent.setClipOverlay(child, newProps.clipOverlay ?? false);
44
92
  }
45
93
  }
46
- });
94
+ }
95
+ }
96
+ attachChild(widget) {
97
+ if (!this.parent) {
98
+ return;
99
+ }
100
+ this.parent.addOverlay(widget);
101
+ if (this.props.measure !== undefined) {
102
+ this.parent.setMeasureOverlay(widget, this.props.measure);
103
+ }
104
+ if (this.props.clipOverlay !== undefined) {
105
+ this.parent.setClipOverlay(widget, this.props.clipOverlay);
106
+ }
47
107
  }
48
108
  }
49
109
  registerNodeClass(OverlayChildNode);
@@ -1,14 +1 @@
1
- import type * as Gtk from "@gtkx/ffi/gtk";
2
- import { VirtualChildNode } from "./virtual-child.js";
3
- type PackableWidget = Gtk.Widget & {
4
- packStart(child: Gtk.Widget): void;
5
- packEnd(child: Gtk.Widget): void;
6
- remove(child: Gtk.Widget): void;
7
- };
8
- export declare class PackChild extends VirtualChildNode<PackableWidget> {
9
- static priority: number;
10
- static matches(type: string): boolean;
11
- protected getPositionLabel(): string;
12
- protected attachChild(parent: PackableWidget, widget: Gtk.Widget): void;
13
- }
14
1
  export {};
@@ -1,20 +1,22 @@
1
1
  import { registerNodeClass } from "../registry.js";
2
- import { VirtualChildNode } from "./virtual-child.js";
3
- export class PackChild extends VirtualChildNode {
2
+ import { VirtualContainerNode } from "./abstract/virtual-container.js";
3
+ class PackStartNode extends VirtualContainerNode {
4
4
  static priority = 1;
5
5
  static matches(type) {
6
- return type === "PackStart" || type === "PackEnd";
6
+ return type === "PackStart";
7
7
  }
8
- getPositionLabel() {
9
- return this.typeName === "PackStart" ? "start" : "end";
8
+ attachChild(parent, widget) {
9
+ parent.packStart(widget);
10
+ }
11
+ }
12
+ class PackEndNode extends VirtualContainerNode {
13
+ static priority = 1;
14
+ static matches(type) {
15
+ return type === "PackEnd";
10
16
  }
11
17
  attachChild(parent, widget) {
12
- if (this.getPositionLabel() === "start") {
13
- parent.packStart(widget);
14
- }
15
- else {
16
- parent.packEnd(widget);
17
- }
18
+ parent.packEnd(widget);
18
19
  }
19
20
  }
20
- registerNodeClass(PackChild);
21
+ registerNodeClass(PackStartNode);
22
+ registerNodeClass(PackEndNode);
@@ -1 +1,6 @@
1
- export {};
1
+ import type * as Gtk from "@gtkx/ffi/gtk";
2
+ export type PackableWidget = Gtk.Widget & {
3
+ packStart(child: Gtk.Widget): void;
4
+ packEnd(child: Gtk.Widget): void;
5
+ remove(child: Gtk.Widget): void;
6
+ };
@@ -1,46 +1,13 @@
1
1
  import { PACK_INTERFACE_METHODS } from "../generated/internal.js";
2
2
  import { registerNodeClass } from "../registry.js";
3
+ import { PositionalParentNode } from "./abstract/positional-parent.js";
3
4
  import { matchesInterface } from "./internal/utils.js";
4
- import { PackChild } from "./pack-child.js";
5
- import { SlotNode } from "./slot.js";
6
- import { WidgetNode } from "./widget.js";
7
- class PackNode extends WidgetNode {
5
+ class PackNode extends PositionalParentNode {
8
6
  static priority = 0;
7
+ acceptedPositionalChildTypes = new Set(["PackStart", "PackEnd"]);
8
+ containerTypeName = "Pack";
9
9
  static matches(_type, containerOrClass) {
10
10
  return matchesInterface(PACK_INTERFACE_METHODS, containerOrClass);
11
11
  }
12
- appendChild(child) {
13
- if (child instanceof PackChild) {
14
- child.setParent(this.container);
15
- return;
16
- }
17
- if (child instanceof SlotNode || child instanceof WidgetNode) {
18
- super.appendChild(child);
19
- return;
20
- }
21
- throw new Error(`Cannot append '${child.typeName}' to 'Pack': expected x.PackStart, x.PackEnd, or Widget`);
22
- }
23
- insertBefore(child, before) {
24
- if (child instanceof PackChild) {
25
- child.setParent(this.container);
26
- return;
27
- }
28
- if (child instanceof SlotNode || child instanceof WidgetNode) {
29
- super.insertBefore(child, before);
30
- return;
31
- }
32
- throw new Error(`Cannot insert '${child.typeName}' into 'Pack': expected x.PackStart, x.PackEnd, or Widget`);
33
- }
34
- removeChild(child) {
35
- if (child instanceof PackChild) {
36
- child.unmount();
37
- return;
38
- }
39
- if (child instanceof SlotNode || child instanceof WidgetNode) {
40
- super.removeChild(child);
41
- return;
42
- }
43
- throw new Error(`Cannot remove '${child.typeName}' from 'Pack': expected x.PackStart, x.PackEnd, or Widget`);
44
- }
45
12
  }
46
13
  registerNodeClass(PackNode);
@@ -4,7 +4,7 @@ import { POPOVER_MENU_CLASSES } from "../generated/internal.js";
4
4
  import { registerNodeClass } from "../registry.js";
5
5
  import { matchesAnyClass } from "./internal/utils.js";
6
6
  import { MenuNode } from "./menu.js";
7
- import { Menu } from "./models/menu.js";
7
+ import { MenuModel } from "./models/menu.js";
8
8
  import { SlotNode } from "./slot.js";
9
9
  import { WidgetNode } from "./widget.js";
10
10
  const ACTION_PREFIX = "menu";
@@ -20,7 +20,7 @@ class PopoverMenuNode extends WidgetNode {
20
20
  const actionGroup = new Gio.SimpleActionGroup();
21
21
  const prefix = application ? "app" : ACTION_PREFIX;
22
22
  this.container.insertActionGroup(prefix, actionGroup);
23
- this.menu = new Menu("root", {}, actionGroup, application);
23
+ this.menu = new MenuModel("root", {}, rootContainer, actionGroup, application);
24
24
  this.container.setMenuModel(this.menu.getMenu());
25
25
  }
26
26
  appendChild(child) {
@@ -1,70 +1,27 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
2
  import { registerNodeClass } from "../registry.js";
3
- import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
4
- import { isContainerType } from "./internal/utils.js";
5
- import { ScaleMarkNode } from "./scale-mark.js";
6
- import { SlotNode } from "./slot.js";
7
- import { WidgetNode } from "./widget.js";
8
- class ScaleNode extends WidgetNode {
3
+ import { AdjustableNode } from "./adjustable.js";
4
+ import { matchesAnyClass, shallowArrayEqual } from "./internal/utils.js";
5
+ class ScaleNode extends AdjustableNode {
9
6
  static priority = 1;
10
- markChildren = [];
7
+ appliedMarks = [];
11
8
  static matches(_type, containerOrClass) {
12
- return isContainerType(Gtk.Scale, containerOrClass);
9
+ return matchesAnyClass([Gtk.Scale], containerOrClass);
13
10
  }
14
- appendChild(child) {
15
- if (child instanceof ScaleMarkNode) {
16
- child.setScale(this.container, () => this.scheduleRebuildAllMarks());
17
- this.markChildren.push(child);
18
- scheduleAfterCommit(() => child.addMark());
19
- return;
20
- }
21
- if (child instanceof SlotNode || child instanceof WidgetNode) {
22
- super.appendChild(child);
23
- return;
24
- }
25
- throw new Error(`Cannot append '${child.typeName}' to 'Scale': expected x.ScaleMark or Widget`);
11
+ applyOwnProps(oldProps, newProps) {
12
+ super.applyOwnProps(oldProps, newProps);
13
+ this.applyMarks(newProps);
26
14
  }
27
- insertBefore(child, before) {
28
- if (child instanceof ScaleMarkNode) {
29
- child.setScale(this.container, () => this.scheduleRebuildAllMarks());
30
- const beforeIndex = this.markChildren.indexOf(before);
31
- if (beforeIndex >= 0) {
32
- this.markChildren.splice(beforeIndex, 0, child);
33
- }
34
- else {
35
- this.markChildren.push(child);
36
- }
37
- this.scheduleRebuildAllMarks();
15
+ applyMarks(newProps) {
16
+ const newMarks = newProps.marks ?? [];
17
+ if (shallowArrayEqual(this.appliedMarks, newMarks)) {
38
18
  return;
39
19
  }
40
- if (child instanceof SlotNode || child instanceof WidgetNode) {
41
- super.insertBefore(child, before);
42
- return;
20
+ this.container.clearMarks();
21
+ for (const mark of newMarks) {
22
+ this.container.addMark(mark.value, mark.position ?? Gtk.PositionType.BOTTOM, mark.label);
43
23
  }
44
- throw new Error(`Cannot insert '${child.typeName}' into 'Scale': expected x.ScaleMark or Widget`);
45
- }
46
- removeChild(child) {
47
- if (child instanceof ScaleMarkNode) {
48
- const index = this.markChildren.indexOf(child);
49
- if (index >= 0) {
50
- this.markChildren.splice(index, 1);
51
- }
52
- this.scheduleRebuildAllMarks(CommitPriority.HIGH);
53
- return;
54
- }
55
- if (child instanceof SlotNode || child instanceof WidgetNode) {
56
- super.removeChild(child);
57
- return;
58
- }
59
- throw new Error(`Cannot remove '${child.typeName}' from 'Scale': expected x.ScaleMark or Widget`);
60
- }
61
- scheduleRebuildAllMarks(priority = CommitPriority.NORMAL) {
62
- scheduleAfterCommit(() => {
63
- this.container.clearMarks();
64
- for (const mark of this.markChildren) {
65
- mark.addMark();
66
- }
67
- }, priority);
24
+ this.appliedMarks = [...newMarks];
68
25
  }
69
26
  }
70
27
  registerNodeClass(ScaleNode);
@@ -1,21 +1,23 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
2
  import { registerNodeClass } from "../registry.js";
3
- import { filterProps, isContainerType } from "./internal/utils.js";
3
+ import { filterProps, hasChanged, matchesAnyClass } from "./internal/utils.js";
4
4
  import { WidgetNode } from "./widget.js";
5
5
  const PROPS = ["hscrollbarPolicy", "vscrollbarPolicy"];
6
6
  class ScrolledWindowNode extends WidgetNode {
7
7
  static priority = 2;
8
8
  static matches(_type, containerOrClass) {
9
- return isContainerType(Gtk.ScrolledWindow, containerOrClass);
9
+ return matchesAnyClass([Gtk.ScrolledWindow], containerOrClass);
10
10
  }
11
11
  updateProps(oldProps, newProps) {
12
- if (oldProps?.hscrollbarPolicy !== newProps.hscrollbarPolicy ||
13
- oldProps?.vscrollbarPolicy !== newProps.vscrollbarPolicy) {
12
+ super.updateProps(oldProps ? filterProps(oldProps, PROPS) : null, filterProps(newProps, PROPS));
13
+ this.applyOwnProps(oldProps, newProps);
14
+ }
15
+ applyOwnProps(oldProps, newProps) {
16
+ if (hasChanged(oldProps, newProps, "hscrollbarPolicy") || hasChanged(oldProps, newProps, "vscrollbarPolicy")) {
14
17
  const hPolicy = newProps.hscrollbarPolicy ?? Gtk.PolicyType.AUTOMATIC;
15
18
  const vPolicy = newProps.vscrollbarPolicy ?? Gtk.PolicyType.AUTOMATIC;
16
19
  this.container.setPolicy(hPolicy, vPolicy);
17
20
  }
18
- super.updateProps(filterProps(oldProps ?? {}, PROPS), filterProps(newProps, PROPS));
19
21
  }
20
22
  }
21
23
  registerNodeClass(ScrolledWindowNode);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { filterProps, hasChanged, matchesAnyClass } from "./internal/utils.js";
4
+ import { WidgetNode } from "./widget.js";
5
+ const OWN_PROPS = ["onSearchModeChanged"];
6
+ class SearchBarNode extends WidgetNode {
7
+ static priority = 1;
8
+ notifyHandler = null;
9
+ static matches(_type, containerOrClass) {
10
+ return matchesAnyClass([Gtk.SearchBar], containerOrClass);
11
+ }
12
+ updateProps(oldProps, newProps) {
13
+ super.updateProps(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
14
+ if (hasChanged(oldProps, newProps, "onSearchModeChanged")) {
15
+ this.setupNotifyHandler(newProps.onSearchModeChanged);
16
+ }
17
+ }
18
+ setupNotifyHandler(callback) {
19
+ if (this.notifyHandler) {
20
+ this.signalStore.set(this, this.container, "notify", undefined);
21
+ this.notifyHandler = null;
22
+ }
23
+ if (callback) {
24
+ this.notifyHandler = (_searchBar, pspec) => {
25
+ if (pspec.getName() === "search-mode-enabled") {
26
+ callback(this.container.getSearchMode());
27
+ }
28
+ };
29
+ this.signalStore.set(this, this.container, "notify", this.notifyHandler);
30
+ }
31
+ }
32
+ unmount() {
33
+ if (this.notifyHandler) {
34
+ this.signalStore.set(this, this.container, "notify", undefined);
35
+ this.notifyHandler = null;
36
+ }
37
+ super.unmount();
38
+ }
39
+ }
40
+ registerNodeClass(SearchBarNode);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,90 @@
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { hasChanged } from "./internal/utils.js";
4
+ import { ShortcutNode } from "./shortcut.js";
5
+ import { VirtualNode } from "./virtual.js";
6
+ import { WidgetNode } from "./widget.js";
7
+ class ShortcutControllerNode extends VirtualNode {
8
+ static priority = 0;
9
+ static matches(type) {
10
+ return type === "GtkShortcutController";
11
+ }
12
+ controller = null;
13
+ parentWidget = null;
14
+ shortcuts = [];
15
+ setParent(widget) {
16
+ if (this.parentWidget && this.controller) {
17
+ this.parentWidget.removeController(this.controller);
18
+ }
19
+ this.parentWidget = widget;
20
+ if (widget) {
21
+ this.controller = new Gtk.ShortcutController();
22
+ this.applyScope();
23
+ widget.addController(this.controller);
24
+ for (const shortcut of this.shortcuts) {
25
+ this.addShortcutToController(shortcut);
26
+ }
27
+ }
28
+ else {
29
+ this.controller = null;
30
+ }
31
+ }
32
+ appendChild(child) {
33
+ if (!(child instanceof ShortcutNode)) {
34
+ throw new Error(`ShortcutController only accepts Shortcut children, got '${child.typeName}'`);
35
+ }
36
+ this.shortcuts.push(child);
37
+ if (this.controller) {
38
+ this.addShortcutToController(child);
39
+ }
40
+ }
41
+ removeChild(child) {
42
+ if (!(child instanceof ShortcutNode))
43
+ return;
44
+ const index = this.shortcuts.indexOf(child);
45
+ if (index !== -1) {
46
+ this.shortcuts.splice(index, 1);
47
+ if (this.controller && child.shortcut) {
48
+ this.controller.removeShortcut(child.shortcut);
49
+ }
50
+ }
51
+ }
52
+ updateProps(oldProps, newProps) {
53
+ super.updateProps(oldProps, newProps);
54
+ this.applyOwnProps(oldProps, newProps);
55
+ }
56
+ applyOwnProps(oldProps, newProps) {
57
+ if (hasChanged(oldProps, newProps, "scope")) {
58
+ this.applyScope();
59
+ }
60
+ }
61
+ unmount() {
62
+ this.setParent(null);
63
+ super.unmount();
64
+ }
65
+ canBeChildOf(parent) {
66
+ return parent instanceof WidgetNode;
67
+ }
68
+ attachTo(parent) {
69
+ if (parent instanceof WidgetNode) {
70
+ this.setParent(parent.container);
71
+ }
72
+ }
73
+ detachFrom(_parent) {
74
+ this.setParent(null);
75
+ }
76
+ applyScope() {
77
+ if (!this.controller)
78
+ return;
79
+ this.controller.setScope(this.props.scope ?? Gtk.ShortcutScope.LOCAL);
80
+ }
81
+ addShortcutToController(node) {
82
+ if (!this.controller)
83
+ return;
84
+ node.createShortcut();
85
+ if (node.shortcut) {
86
+ this.controller.addShortcut(node.shortcut);
87
+ }
88
+ }
89
+ }
90
+ registerNodeClass(ShortcutControllerNode);