@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
@@ -1,67 +1,99 @@
1
- import { Node } from "../node.js";
2
- export class SlotNode extends Node {
1
+ import { toCamelCase } from "@gtkx/gir";
2
+ import { PROPS } from "../generated/internal.js";
3
+ import { registerNodeClass } from "../registry.js";
4
+ import { scheduleAfterCommit } from "../scheduler.js";
5
+ import { VirtualNode } from "./virtual.js";
6
+ import { WidgetNode } from "./widget.js";
7
+ export class SlotNode extends VirtualNode {
8
+ static priority = 2;
3
9
  static matches(type) {
4
- if (!type.includes("."))
5
- return false;
6
- const parts = type.split(".");
7
- if (parts.length !== 2)
8
- return false;
9
- const suffix = parts[1];
10
- return suffix !== "Root";
10
+ return type === "Slot";
11
11
  }
12
- isVirtual() {
13
- return true;
12
+ parent;
13
+ child;
14
+ setParent(parent) {
15
+ this.parent = parent;
14
16
  }
15
- child = null;
16
- slotName;
17
- constructor(type) {
18
- super(type);
19
- const dotIndex = type.indexOf(".");
20
- if (dotIndex === -1) {
21
- throw new Error(`Invalid slot type: ${type}`);
17
+ unmount() {
18
+ if (this.parent && this.child) {
19
+ const oldChild = this.child;
20
+ this.child = undefined;
21
+ this.onChildChange(oldChild);
22
+ }
23
+ this.parent = undefined;
24
+ super.unmount();
25
+ }
26
+ getId() {
27
+ const id = this.props.id;
28
+ if (!id) {
29
+ throw new Error("Expected 'id' prop to be present on Slot");
22
30
  }
23
- this.slotName = type.substring(dotIndex + 1);
31
+ return toCamelCase(id);
24
32
  }
25
- updateParentSlot() {
26
- if (!this.parent)
27
- return;
28
- const parentWidget = this.parent.getWidget();
29
- const childWidget = this.child?.getWidget();
30
- if (!parentWidget)
31
- return;
32
- const setterName = `set${this.slotName}`;
33
- const setter = parentWidget[setterName];
34
- if (typeof setter === "function") {
35
- setter.call(parentWidget, childWidget?.id ?? null);
33
+ getParent() {
34
+ if (!this.parent) {
35
+ throw new Error(`Expected parent widget to be set on '${this.getId()}' SlotNode`);
36
36
  }
37
+ return this.parent;
38
+ }
39
+ getChild() {
40
+ if (!this.child) {
41
+ throw new Error(`Expected child widget to be set on '${this.getId()}' SlotNode`);
42
+ }
43
+ return this.child;
37
44
  }
38
45
  appendChild(child) {
39
- child.parent = this;
40
- if (child.getWidget()) {
41
- this.child = child;
42
- this.updateParentSlot();
46
+ if (!(child instanceof WidgetNode)) {
47
+ throw new Error(`Cannot append '${child.typeName}' to 'Slot': expected Widget`);
43
48
  }
49
+ const oldChild = this.child;
50
+ this.child = child.container;
51
+ scheduleAfterCommit(() => {
52
+ if (this.parent) {
53
+ this.onChildChange(oldChild);
54
+ }
55
+ });
44
56
  }
45
- removeChild(child) {
46
- child.unmount();
47
- this.child = null;
48
- this.updateParentSlot();
49
- child.parent = null;
57
+ removeChild() {
58
+ const oldChild = this.child;
59
+ scheduleAfterCommit(() => {
60
+ if (oldChild === this.child) {
61
+ this.child = undefined;
62
+ }
63
+ if (this.parent) {
64
+ this.onChildChange(oldChild);
65
+ }
66
+ });
50
67
  }
51
- mount() {
52
- this.updateParentSlot();
68
+ onChildChange(oldChild) {
69
+ const parent = this.getParent();
70
+ const parentType = parent.constructor.glibTypeName;
71
+ const [_, setterName] = PROPS[parentType]?.[this.getId()] ?? [];
72
+ if (!setterName) {
73
+ throw new Error(`Unable to find property for Slot '${this.getId()}' on type '${parentType}'`);
74
+ }
75
+ const setter = parent[setterName];
76
+ if (typeof setter !== "function") {
77
+ throw new Error(`Expected setter function for Slot '${this.getId()}' on type '${parentType}'`);
78
+ }
79
+ if (oldChild && !this.child) {
80
+ const root = oldChild.getRoot();
81
+ const focusWidget = root?.getFocus?.();
82
+ if (focusWidget && this.isDescendantOf(focusWidget, oldChild)) {
83
+ parent.grabFocus();
84
+ }
85
+ }
86
+ setter.call(parent, this.child);
53
87
  }
54
- unmount() {
55
- if (this.parent) {
56
- const parentWidget = this.parent.getWidget();
57
- if (parentWidget) {
58
- const setterName = `set${this.slotName}`;
59
- const setter = parentWidget[setterName];
60
- if (typeof setter === "function") {
61
- setter.call(parentWidget, null);
62
- }
88
+ isDescendantOf(widget, ancestor) {
89
+ let current = widget;
90
+ while (current) {
91
+ if (current.equals(ancestor)) {
92
+ return true;
63
93
  }
94
+ current = current.getParent();
64
95
  }
65
- super.unmount();
96
+ return false;
66
97
  }
67
98
  }
99
+ registerNodeClass(SlotNode);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,80 @@
1
+ import * as Adw from "@gtkx/ffi/adw";
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { SlotNode } from "./slot.js";
4
+ class StackPageNode extends SlotNode {
5
+ static priority = 1;
6
+ page;
7
+ static matches(type) {
8
+ return type === "StackPage";
9
+ }
10
+ updateProps(oldProps, newProps) {
11
+ super.updateProps(oldProps, newProps);
12
+ if (!this.page) {
13
+ return;
14
+ }
15
+ if (newProps.title && (!oldProps || oldProps.title !== newProps.title)) {
16
+ this.page.setTitle(newProps.title);
17
+ }
18
+ if (newProps.iconName && (!oldProps || oldProps.iconName !== newProps.iconName)) {
19
+ this.page.setIconName(newProps.iconName);
20
+ }
21
+ if (!oldProps || oldProps.needsAttention !== newProps.needsAttention) {
22
+ this.page.setNeedsAttention(newProps.needsAttention ?? false);
23
+ }
24
+ if (!oldProps || oldProps.visible !== newProps.visible) {
25
+ this.page.setVisible(newProps.visible ?? true);
26
+ }
27
+ if (!oldProps || oldProps.useUnderline !== newProps.useUnderline) {
28
+ this.page.setUseUnderline(newProps.useUnderline ?? false);
29
+ }
30
+ if ("setBadgeNumber" in this.page && (!oldProps || oldProps.badgeNumber !== newProps.badgeNumber)) {
31
+ this.page.setBadgeNumber?.(newProps.badgeNumber ?? 0);
32
+ }
33
+ }
34
+ addPage() {
35
+ const child = this.getChild();
36
+ const parent = this.getParent();
37
+ let page;
38
+ if (parent instanceof Adw.ViewStack) {
39
+ if (this.props.title && this.props.iconName) {
40
+ page = parent.addTitledWithIcon(child, this.props.title, this.props.iconName, this.props.name);
41
+ }
42
+ else if (this.props.title) {
43
+ page = parent.addTitled(child, this.props.title, this.props.name);
44
+ }
45
+ else if (this.props.name) {
46
+ page = parent.addNamed(child, this.props.name);
47
+ }
48
+ else {
49
+ page = parent.add(child);
50
+ }
51
+ }
52
+ else {
53
+ if (this.props.title) {
54
+ page = parent.addTitled(child, this.props.title, this.props.name);
55
+ }
56
+ else if (this.props.name) {
57
+ page = parent.addNamed(child, this.props.name);
58
+ }
59
+ else {
60
+ page = parent.addChild(child);
61
+ }
62
+ }
63
+ this.page = page;
64
+ this.updateProps(null, this.props);
65
+ }
66
+ removePage(oldChild) {
67
+ const parent = this.getParent();
68
+ if (!oldChild) {
69
+ return;
70
+ }
71
+ parent.remove(oldChild);
72
+ }
73
+ onChildChange(oldChild) {
74
+ this.removePage(oldChild);
75
+ if (this.child) {
76
+ this.addPage();
77
+ }
78
+ }
79
+ }
80
+ registerNodeClass(StackPageNode);
@@ -1,22 +1 @@
1
- import type * as Gtk from "@gtkx/ffi/gtk";
2
- import type { StackPageContainer, StackPageProps } from "../containers.js";
3
- import type { Props } from "../factory.js";
4
- import type { Node } from "../node.js";
5
- import { PagedStackNode } from "./paged-stack.js";
6
- import { VirtualSlotNode } from "./virtual-slot.js";
7
- export declare class StackNode extends PagedStackNode<Gtk.Stack> {
8
- static matches(type: string): boolean;
9
- addStackPage(child: Gtk.Widget, props: StackPageProps): void;
10
- protected addChildToWidget(child: Gtk.Widget): void;
11
- }
12
- export declare class StackPageNode extends VirtualSlotNode<StackPageContainer, StackPageProps> {
13
- static consumedPropNames: string[];
14
- static matches(type: string): boolean;
15
- protected isValidContainer(parent: Node): parent is Node & StackPageContainer;
16
- protected extractSlotProps(props: Props): StackPageProps;
17
- protected addToContainer(container: StackPageContainer, child: Gtk.Widget, props: StackPageProps): void;
18
- protected insertBeforeInContainer(container: StackPageContainer, child: Gtk.Widget, props: StackPageProps, before: Gtk.Widget): void;
19
- protected removeFromContainer(container: StackPageContainer, child: Gtk.Widget): void;
20
- protected updateInContainer(container: StackPageContainer, child: Gtk.Widget, props: StackPageProps): void;
21
- updateProps(oldProps: Props, newProps: Props): void;
22
- }
1
+ export {};
@@ -1,64 +1,25 @@
1
- import { isStackPageContainer } from "../predicates.js";
2
- import { PagedStackNode } from "./paged-stack.js";
3
- import { applyStackPageProps } from "./stack-page-props.js";
4
- import { VirtualSlotNode } from "./virtual-slot.js";
5
- const STACK_PAGE_PROP_KEYS = ["name", "title", "iconName", "needsAttention", "visible", "useUnderline", "badgeNumber"];
6
- export class StackNode extends PagedStackNode {
7
- static matches(type) {
8
- return type === "Stack" || type === "Stack.Root";
9
- }
10
- addStackPage(child, props) {
11
- const { name, title } = props;
12
- let stackPage;
13
- if (title !== undefined) {
14
- stackPage = this.widget.addTitled(child, title, name);
15
- }
16
- else if (name !== undefined) {
17
- stackPage = this.widget.addNamed(child, name);
18
- }
19
- else {
20
- stackPage = this.widget.addChild(child);
21
- }
22
- applyStackPageProps(stackPage, props);
23
- this.applyPendingVisibleChild();
24
- }
25
- addChildToWidget(child) {
26
- this.widget.addChild(child);
27
- }
28
- }
29
- export class StackPageNode extends VirtualSlotNode {
30
- static consumedPropNames = STACK_PAGE_PROP_KEYS;
31
- static matches(type) {
32
- return type === "Stack.Page" || type === "AdwViewStack.Page";
33
- }
34
- isValidContainer(parent) {
35
- return isStackPageContainer(parent);
36
- }
37
- extractSlotProps(props) {
38
- return {
39
- name: props.name,
40
- title: props.title,
41
- iconName: props.iconName,
42
- needsAttention: props.needsAttention,
43
- visible: props.visible,
44
- useUnderline: props.useUnderline,
45
- badgeNumber: props.badgeNumber,
46
- };
47
- }
48
- addToContainer(container, child, props) {
49
- container.addStackPage(child, props);
50
- }
51
- insertBeforeInContainer(container, child, props, before) {
52
- container.insertStackPageBefore(child, props, before);
53
- }
54
- removeFromContainer(container, child) {
55
- container.removeStackPage(child);
56
- }
57
- updateInContainer(container, child, props) {
58
- container.updateStackPageProps(child, props);
1
+ import * as Adw from "@gtkx/ffi/adw";
2
+ import * as Gtk from "@gtkx/ffi/gtk";
3
+ import { registerNodeClass } from "../registry.js";
4
+ import { scheduleAfterCommit } from "../scheduler.js";
5
+ import { filterProps, isContainerType } from "./internal/utils.js";
6
+ import { WidgetNode } from "./widget.js";
7
+ const PROPS = ["visibleChildName"];
8
+ class StackNode extends WidgetNode {
9
+ static priority = 1;
10
+ static matches(_type, containerOrClass) {
11
+ return isContainerType(Gtk.Stack, containerOrClass) || isContainerType(Adw.ViewStack, containerOrClass);
59
12
  }
60
13
  updateProps(oldProps, newProps) {
61
- this.updateSlotPropsIfChanged(oldProps, newProps, STACK_PAGE_PROP_KEYS);
62
- super.updateProps(oldProps, newProps);
14
+ if (newProps.visibleChildName && this.container.getVisibleChildName() !== newProps.visibleChildName) {
15
+ const visibleChildName = newProps.visibleChildName;
16
+ scheduleAfterCommit(() => {
17
+ if (this.container.getChildByName(visibleChildName)) {
18
+ this.container.setVisibleChildName(visibleChildName);
19
+ }
20
+ });
21
+ }
22
+ super.updateProps(filterProps(oldProps ?? {}, PROPS), filterProps(newProps, PROPS));
63
23
  }
64
24
  }
25
+ registerNodeClass(StackNode);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import * as Adw from "@gtkx/ffi/adw";
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { isContainerType } from "./internal/utils.js";
4
+ import { ToastNode } from "./toast.js";
5
+ import { WidgetNode } from "./widget.js";
6
+ class ToastOverlayNode extends WidgetNode {
7
+ static priority = 1;
8
+ static matches(_type, containerOrClass) {
9
+ return isContainerType(Adw.ToastOverlay, containerOrClass);
10
+ }
11
+ appendChild(child) {
12
+ if (child instanceof ToastNode) {
13
+ child.setParent(this.container);
14
+ return;
15
+ }
16
+ if (child instanceof WidgetNode) {
17
+ this.container.setChild(child.container);
18
+ return;
19
+ }
20
+ throw new Error(`Cannot append '${child.typeName}' to 'ToastOverlay': expected Widget or Toast`);
21
+ }
22
+ insertBefore(child, _before) {
23
+ this.appendChild(child);
24
+ }
25
+ removeChild(child) {
26
+ if (child instanceof ToastNode) {
27
+ child.unmount();
28
+ return;
29
+ }
30
+ if (child instanceof WidgetNode) {
31
+ this.container.setChild(undefined);
32
+ }
33
+ }
34
+ }
35
+ registerNodeClass(ToastOverlayNode);
@@ -0,0 +1,17 @@
1
+ import * as Adw from "@gtkx/ffi/adw";
2
+ import type { ToastProps } from "../jsx.js";
3
+ import { VirtualNode } from "./virtual.js";
4
+ type Props = ToastProps;
5
+ export declare class ToastNode extends VirtualNode<Props> {
6
+ static priority: number;
7
+ static matches(type: string): boolean;
8
+ private toast?;
9
+ private parent?;
10
+ setParent(parent?: Adw.ToastOverlay): void;
11
+ private createToast;
12
+ private showToast;
13
+ updateProps(oldProps: Props | null, newProps: Props): void;
14
+ mount(): void;
15
+ unmount(): void;
16
+ }
17
+ export {};
@@ -0,0 +1,77 @@
1
+ import * as Adw from "@gtkx/ffi/adw";
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { VirtualNode } from "./virtual.js";
4
+ export class ToastNode extends VirtualNode {
5
+ static priority = 1;
6
+ static matches(type) {
7
+ return type === "Toast";
8
+ }
9
+ toast;
10
+ parent;
11
+ setParent(parent) {
12
+ this.parent = parent;
13
+ }
14
+ createToast() {
15
+ const toast = new Adw.Toast(this.props.title);
16
+ if (this.props.timeout !== undefined) {
17
+ toast.setTimeout(this.props.timeout);
18
+ }
19
+ if (this.props.priority !== undefined) {
20
+ toast.setPriority(this.props.priority);
21
+ }
22
+ if (this.props.buttonLabel) {
23
+ toast.setButtonLabel(this.props.buttonLabel);
24
+ }
25
+ if (this.props.actionName) {
26
+ toast.setActionName(this.props.actionName);
27
+ }
28
+ if (this.props.useMarkup !== undefined) {
29
+ toast.setUseMarkup(this.props.useMarkup);
30
+ }
31
+ return toast;
32
+ }
33
+ showToast() {
34
+ if (!this.parent || this.toast)
35
+ return;
36
+ this.toast = this.createToast();
37
+ if (this.props.onButtonClicked) {
38
+ this.signalStore.set(this.toast, "button-clicked", () => {
39
+ this.props.onButtonClicked?.();
40
+ });
41
+ }
42
+ this.signalStore.set(this.toast, "dismissed", () => {
43
+ this.props.onDismissed?.();
44
+ });
45
+ this.parent.addToast(this.toast);
46
+ }
47
+ updateProps(oldProps, newProps) {
48
+ super.updateProps(oldProps, newProps);
49
+ if (!this.toast)
50
+ return;
51
+ if (!oldProps || oldProps.title !== newProps.title) {
52
+ this.toast.setTitle(newProps.title);
53
+ }
54
+ if (!oldProps || oldProps.buttonLabel !== newProps.buttonLabel) {
55
+ this.toast.setButtonLabel(newProps.buttonLabel);
56
+ }
57
+ if (!oldProps || oldProps.actionName !== newProps.actionName) {
58
+ this.toast.setActionName(newProps.actionName);
59
+ }
60
+ if (!oldProps || oldProps.useMarkup !== newProps.useMarkup) {
61
+ this.toast.setUseMarkup(newProps.useMarkup ?? false);
62
+ }
63
+ }
64
+ mount() {
65
+ super.mount();
66
+ this.showToast();
67
+ }
68
+ unmount() {
69
+ if (this.toast) {
70
+ this.toast.dismiss();
71
+ this.props.onDismissed?.();
72
+ }
73
+ this.parent = undefined;
74
+ super.unmount();
75
+ }
76
+ }
77
+ registerNodeClass(ToastNode);
@@ -0,0 +1,9 @@
1
+ import type * as Gtk from "@gtkx/ffi/gtk";
2
+ import { SlotNode } from "./slot.js";
3
+ export declare class ToolbarChildNode extends SlotNode {
4
+ static priority: number;
5
+ static matches(type: string): boolean;
6
+ private getToolbar;
7
+ private getPosition;
8
+ protected onChildChange(oldChild: Gtk.Widget | undefined): void;
9
+ }
@@ -0,0 +1,33 @@
1
+ import { registerNodeClass } from "../registry.js";
2
+ import { SlotNode } from "./slot.js";
3
+ export class ToolbarChildNode extends SlotNode {
4
+ static priority = 1;
5
+ static matches(type) {
6
+ return type === "Toolbar.Top" || type === "Toolbar.Bottom";
7
+ }
8
+ getToolbar() {
9
+ if (!this.parent) {
10
+ throw new Error("Expected ToolbarView reference to be set on ToolbarChildNode");
11
+ }
12
+ return this.parent;
13
+ }
14
+ getPosition() {
15
+ return this.typeName === "Toolbar.Top" ? "top" : "bottom";
16
+ }
17
+ onChildChange(oldChild) {
18
+ const toolbar = this.getToolbar();
19
+ if (oldChild) {
20
+ toolbar.remove(oldChild);
21
+ }
22
+ if (this.child) {
23
+ const position = this.getPosition();
24
+ if (position === "top") {
25
+ toolbar.addTopBar(this.child);
26
+ }
27
+ else {
28
+ toolbar.addBottomBar(this.child);
29
+ }
30
+ }
31
+ }
32
+ }
33
+ registerNodeClass(ToolbarChildNode);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ import * as Adw from "@gtkx/ffi/adw";
2
+ import { registerNodeClass } from "../registry.js";
3
+ import { isContainerType } from "./internal/utils.js";
4
+ import { ToolbarChildNode } from "./toolbar-child.js";
5
+ import { WidgetNode } from "./widget.js";
6
+ class ToolbarNode extends WidgetNode {
7
+ static priority = 0;
8
+ static matches(_type, containerOrClass) {
9
+ return isContainerType(Adw.ToolbarView, containerOrClass);
10
+ }
11
+ appendChild(child) {
12
+ if (child instanceof ToolbarChildNode) {
13
+ child.setParent(this.container);
14
+ return;
15
+ }
16
+ if (!(child instanceof WidgetNode)) {
17
+ throw new Error(`Cannot append '${child.typeName}' to 'ToolbarView': expected Widget`);
18
+ }
19
+ this.container.setContent(child.container);
20
+ }
21
+ insertBefore(child) {
22
+ if (child instanceof ToolbarChildNode) {
23
+ child.setParent(this.container);
24
+ return;
25
+ }
26
+ if (!(child instanceof WidgetNode)) {
27
+ throw new Error(`Cannot insert '${child.typeName}' to 'ToolbarView': expected Widget`);
28
+ }
29
+ this.container.setContent(child.container);
30
+ }
31
+ removeChild(child) {
32
+ if (child instanceof ToolbarChildNode) {
33
+ child.unmount();
34
+ return;
35
+ }
36
+ if (!(child instanceof WidgetNode)) {
37
+ throw new Error(`Cannot remove '${child.typeName}' from 'ToolbarView': expected Widget`);
38
+ }
39
+ this.container.setContent(undefined);
40
+ }
41
+ }
42
+ registerNodeClass(ToolbarNode);
@@ -0,0 +1,20 @@
1
+ import type { TreeListItemProps } from "../jsx.js";
2
+ import type { Node } from "../node.js";
3
+ import type { TreeStore } from "./internal/tree-store.js";
4
+ import { VirtualNode } from "./virtual.js";
5
+ type Props = Partial<TreeListItemProps>;
6
+ export declare class TreeListItemNode extends VirtualNode<Props> {
7
+ static priority: number;
8
+ private store?;
9
+ private parentItemId?;
10
+ private childNodes;
11
+ static matches(type: string): boolean;
12
+ setStore(store?: TreeStore): void;
13
+ setParentItemId(parentId?: string): void;
14
+ getParentItemId(): string | undefined;
15
+ appendChild(child: Node): void;
16
+ insertBefore(child: Node, before: Node): void;
17
+ removeChild(child: Node): void;
18
+ updateProps(oldProps: Props | null, newProps: Props): void;
19
+ }
20
+ export {};