@gtkx/react 0.8.0 → 0.9.1

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 (62) hide show
  1. package/dist/{container-interfaces.d.ts → containers.d.ts} +10 -37
  2. package/dist/containers.js +1 -0
  3. package/dist/factory.d.ts +1 -1
  4. package/dist/factory.js +3 -3
  5. package/dist/{reconciler/host-config.d.ts → host-config.d.ts} +2 -2
  6. package/dist/{reconciler/host-config.js → host-config.js} +2 -2
  7. package/dist/node.d.ts +5 -6
  8. package/dist/node.js +54 -72
  9. package/dist/nodes/about-dialog.d.ts +2 -3
  10. package/dist/nodes/about-dialog.js +6 -4
  11. package/dist/nodes/column-view.d.ts +10 -9
  12. package/dist/nodes/column-view.js +53 -40
  13. package/dist/nodes/flow-box.js +1 -1
  14. package/dist/nodes/grid.d.ts +4 -1
  15. package/dist/nodes/grid.js +39 -1
  16. package/dist/nodes/header-bar.d.ts +15 -14
  17. package/dist/nodes/header-bar.js +79 -39
  18. package/dist/nodes/indexed-child-container.d.ts +1 -1
  19. package/dist/nodes/list-box.js +2 -2
  20. package/dist/nodes/list-item-factory.js +3 -3
  21. package/dist/nodes/list-view.d.ts +1 -2
  22. package/dist/nodes/list-view.js +2 -2
  23. package/dist/nodes/menu.d.ts +28 -12
  24. package/dist/nodes/menu.js +64 -37
  25. package/dist/nodes/notebook.d.ts +4 -1
  26. package/dist/nodes/notebook.js +48 -4
  27. package/dist/nodes/overlay.d.ts +1 -1
  28. package/dist/nodes/overlay.js +1 -1
  29. package/dist/nodes/paged-stack.d.ts +7 -3
  30. package/dist/nodes/paged-stack.js +47 -2
  31. package/dist/nodes/root.d.ts +1 -1
  32. package/dist/nodes/root.js +2 -2
  33. package/dist/nodes/selectable-list.d.ts +7 -3
  34. package/dist/nodes/selectable-list.js +37 -5
  35. package/dist/nodes/slot.d.ts +3 -4
  36. package/dist/nodes/slot.js +11 -10
  37. package/dist/nodes/stack-page-props.d.ts +1 -1
  38. package/dist/nodes/stack.d.ts +1 -1
  39. package/dist/nodes/stack.js +2 -2
  40. package/dist/nodes/string-list-container.d.ts +5 -12
  41. package/dist/nodes/string-list-container.js +34 -6
  42. package/dist/nodes/string-list-item.d.ts +10 -6
  43. package/dist/nodes/string-list-item.js +19 -17
  44. package/dist/nodes/toggle-button.d.ts +0 -3
  45. package/dist/nodes/toggle-button.js +0 -28
  46. package/dist/nodes/toolbar-view.d.ts +2 -3
  47. package/dist/nodes/toolbar-view.js +10 -9
  48. package/dist/nodes/view-stack.d.ts +1 -1
  49. package/dist/nodes/view-stack.js +2 -2
  50. package/dist/nodes/virtual-item.d.ts +9 -5
  51. package/dist/nodes/virtual-item.js +16 -20
  52. package/dist/nodes/virtual-slot.d.ts +4 -4
  53. package/dist/nodes/virtual-slot.js +12 -26
  54. package/dist/nodes/window.d.ts +2 -1
  55. package/dist/nodes/window.js +7 -3
  56. package/dist/predicates.d.ts +9 -18
  57. package/dist/predicates.js +31 -18
  58. package/dist/reconciler.d.ts +1 -1
  59. package/dist/reconciler.js +1 -1
  60. package/dist/types.d.ts +2 -0
  61. package/package.json +5 -5
  62. package/dist/container-interfaces.js +0 -26
@@ -1,10 +1,11 @@
1
- import { Node } from "../node.js";
1
+ import { Node as NodeClass } from "../node.js";
2
+ import { StackPageNode } from "./stack.js";
2
3
  import { applyStackPageProps } from "./stack-page-props.js";
3
4
  /**
4
5
  * Abstract node for paged stack widgets (Gtk.Stack, Adw.ViewStack).
5
6
  * Handles visible child deferral and common page operations.
6
7
  */
7
- export class PagedStackNode extends Node {
8
+ export class PagedStackNode extends NodeClass {
8
9
  static consumedPropNames = ["visibleChildName"];
9
10
  pendingVisibleChildName = null;
10
11
  applyPendingVisibleChild() {
@@ -45,6 +46,50 @@ export class PagedStackNode extends Node {
45
46
  this.pendingVisibleChildName = name;
46
47
  }
47
48
  }
49
+ appendChild(child) {
50
+ if (child instanceof StackPageNode) {
51
+ child.parent = this;
52
+ const childWidget = child.getChildWidget();
53
+ const props = child.getSlotProps();
54
+ if (childWidget) {
55
+ this.addStackPage(childWidget, props);
56
+ child.setParentContainer(this);
57
+ }
58
+ return;
59
+ }
60
+ super.appendChild(child);
61
+ }
62
+ insertBefore(child, before) {
63
+ if (child instanceof StackPageNode) {
64
+ child.parent = this;
65
+ const childWidget = child.getChildWidget();
66
+ const props = child.getSlotProps();
67
+ if (childWidget) {
68
+ const beforeWidget = child.getBeforeWidget(before);
69
+ if (beforeWidget) {
70
+ this.insertStackPageBefore(childWidget, props, beforeWidget);
71
+ }
72
+ else {
73
+ this.addStackPage(childWidget, props);
74
+ }
75
+ child.setParentContainer(this);
76
+ }
77
+ return;
78
+ }
79
+ super.insertBefore(child, before);
80
+ }
81
+ removeChild(child) {
82
+ if (child instanceof StackPageNode) {
83
+ const childWidget = child.getChildWidget();
84
+ if (childWidget) {
85
+ this.removeStackPage(childWidget);
86
+ }
87
+ child.unmount();
88
+ child.parent = null;
89
+ return;
90
+ }
91
+ super.removeChild(child);
92
+ }
48
93
  updateProps(oldProps, newProps) {
49
94
  if (newProps.visibleChildName !== undefined) {
50
95
  this.setVisibleChildOrDefer(newProps.visibleChildName);
@@ -2,7 +2,7 @@ import type * as Gtk from "@gtkx/ffi/gtk";
2
2
  import { Node } from "../node.js";
3
3
  export declare const ROOT_NODE_CONTAINER: unique symbol;
4
4
  export declare class RootNode extends Node<never> {
5
- static matches(_type: string, existingWidget?: Gtk.Widget | typeof ROOT_NODE_CONTAINER): boolean;
5
+ static matches(_type: string, widget?: Gtk.Widget | typeof ROOT_NODE_CONTAINER): boolean;
6
6
  protected isVirtual(): boolean;
7
7
  constructor();
8
8
  }
@@ -1,8 +1,8 @@
1
1
  import { Node } from "../node.js";
2
2
  export const ROOT_NODE_CONTAINER = Symbol.for("ROOT_NODE_CONTAINER");
3
3
  export class RootNode extends Node {
4
- static matches(_type, existingWidget) {
5
- return existingWidget === ROOT_NODE_CONTAINER;
4
+ static matches(_type, widget) {
5
+ return widget === ROOT_NODE_CONTAINER;
6
6
  }
7
7
  isVirtual() {
8
8
  return true;
@@ -1,7 +1,8 @@
1
1
  import * as Gtk from "@gtkx/ffi/gtk";
2
- import type { ItemContainer } from "../container-interfaces.js";
2
+ import type { ItemContainer } from "../containers.js";
3
3
  import type { Props } from "../factory.js";
4
- import { Node } from "../node.js";
4
+ import type { Node } from "../node.js";
5
+ import { Node as NodeClass } from "../node.js";
5
6
  export type SelectableListState = {
6
7
  itemsById: Map<string, unknown>;
7
8
  itemOrder: string[];
@@ -18,7 +19,10 @@ export type SelectableListState = {
18
19
  type SelectableListWidget = Gtk.Widget & {
19
20
  setModel(model: Gtk.SelectionModel): void;
20
21
  };
21
- export declare abstract class SelectableListNode<T extends SelectableListWidget, S extends SelectableListState> extends Node<T, S> implements ItemContainer<unknown> {
22
+ export declare abstract class SelectableListNode<T extends SelectableListWidget, S extends SelectableListState> extends NodeClass<T, S> implements ItemContainer<unknown> {
23
+ appendChild(child: Node): void;
24
+ insertBefore(child: Node, before: Node): void;
25
+ removeChild(child: Node): void;
22
26
  protected initializeSelectionState(props: Props): SelectableListState;
23
27
  protected applySelectionModel(): void;
24
28
  protected cleanupSelection(): void;
@@ -1,15 +1,47 @@
1
- import { getInterface } from "@gtkx/ffi";
1
+ import { getObject } from "@gtkx/ffi";
2
2
  import * as Gio from "@gtkx/ffi/gio";
3
3
  import * as GObject from "@gtkx/ffi/gobject";
4
4
  import * as Gtk from "@gtkx/ffi/gtk";
5
5
  import { scheduleFlush } from "../batch.js";
6
- import { Node } from "../node.js";
6
+ import { Node as NodeClass } from "../node.js";
7
7
  import { getCallbackChange } from "../props.js";
8
- export class SelectableListNode extends Node {
8
+ import { VirtualItemNode } from "./virtual-item.js";
9
+ export class SelectableListNode extends NodeClass {
10
+ appendChild(child) {
11
+ if (child instanceof VirtualItemNode) {
12
+ child.parent = this;
13
+ child.addToContainer(this);
14
+ child.setParentContainer(this);
15
+ return;
16
+ }
17
+ super.appendChild(child);
18
+ }
19
+ insertBefore(child, before) {
20
+ if (child instanceof VirtualItemNode) {
21
+ child.parent = this;
22
+ if (before instanceof VirtualItemNode) {
23
+ child.insertBeforeInContainer(this, before.getId());
24
+ }
25
+ else {
26
+ child.addToContainer(this);
27
+ }
28
+ child.setParentContainer(this);
29
+ return;
30
+ }
31
+ super.insertBefore(child, before);
32
+ }
33
+ removeChild(child) {
34
+ if (child instanceof VirtualItemNode) {
35
+ child.unmount();
36
+ child.parent = null;
37
+ return;
38
+ }
39
+ super.removeChild(child);
40
+ }
9
41
  initializeSelectionState(props) {
10
42
  const selectionMode = props.selectionMode ?? Gtk.SelectionMode.SINGLE;
11
43
  const stringList = new Gtk.StringList([]);
12
- const listModel = getInterface(stringList.id, Gio.ListModel);
44
+ const listModel = getObject(stringList.id, Gio.ListModel) ?? undefined;
13
45
  const selectionModel = selectionMode === Gtk.SelectionMode.MULTIPLE
14
46
  ? new Gtk.MultiSelection(listModel)
15
47
  : new Gtk.SingleSelection(listModel);
@@ -68,7 +100,7 @@ export class SelectableListNode extends Node {
68
100
  const currentSelection = this.getSelectedIds();
69
101
  const hadHandler = this.state.selectionHandlerId !== null;
70
102
  this.disconnectSelectionHandler();
71
- const listModel = getInterface(this.state.stringList.id, Gio.ListModel);
103
+ const listModel = getObject(this.state.stringList.id, Gio.ListModel) ?? undefined;
72
104
  const newSelectionModel = newSelectionMode === Gtk.SelectionMode.MULTIPLE
73
105
  ? new Gtk.MultiSelection(listModel)
74
106
  : new Gtk.SingleSelection(listModel);
@@ -4,11 +4,10 @@ export declare class SlotNode extends Node<never> {
4
4
  protected isVirtual(): boolean;
5
5
  private child;
6
6
  private slotName;
7
- private parentNode;
8
7
  constructor(type: string);
9
8
  private updateParentSlot;
10
9
  appendChild(child: Node): void;
11
- removeChild(_child: Node): void;
12
- attachToParent(parent: Node): void;
13
- detachFromParent(_parent: Node): void;
10
+ removeChild(child: Node): void;
11
+ mount(): void;
12
+ unmount(): void;
14
13
  }
@@ -14,7 +14,6 @@ export class SlotNode extends Node {
14
14
  }
15
15
  child = null;
16
16
  slotName;
17
- parentNode = null;
18
17
  constructor(type) {
19
18
  super(type);
20
19
  const dotIndex = type.indexOf(".");
@@ -24,9 +23,9 @@ export class SlotNode extends Node {
24
23
  this.slotName = type.substring(dotIndex + 1);
25
24
  }
26
25
  updateParentSlot() {
27
- if (!this.parentNode)
26
+ if (!this.parent)
28
27
  return;
29
- const parentWidget = this.parentNode.getWidget();
28
+ const parentWidget = this.parent.getWidget();
30
29
  const childWidget = this.child?.getWidget();
31
30
  if (!parentWidget)
32
31
  return;
@@ -37,22 +36,24 @@ export class SlotNode extends Node {
37
36
  }
38
37
  }
39
38
  appendChild(child) {
39
+ child.parent = this;
40
40
  if (child.getWidget()) {
41
41
  this.child = child;
42
42
  this.updateParentSlot();
43
43
  }
44
44
  }
45
- removeChild(_child) {
45
+ removeChild(child) {
46
+ child.unmount();
46
47
  this.child = null;
47
48
  this.updateParentSlot();
49
+ child.parent = null;
48
50
  }
49
- attachToParent(parent) {
50
- this.parentNode = parent;
51
+ mount() {
51
52
  this.updateParentSlot();
52
53
  }
53
- detachFromParent(_parent) {
54
- if (this.parentNode) {
55
- const parentWidget = this.parentNode.getWidget();
54
+ unmount() {
55
+ if (this.parent) {
56
+ const parentWidget = this.parent.getWidget();
56
57
  if (parentWidget) {
57
58
  const setterName = `set${this.slotName}`;
58
59
  const setter = parentWidget[setterName];
@@ -61,6 +62,6 @@ export class SlotNode extends Node {
61
62
  }
62
63
  }
63
64
  }
64
- this.parentNode = null;
65
+ super.unmount();
65
66
  }
66
67
  }
@@ -1,4 +1,4 @@
1
- import type { StackPageProps } from "../container-interfaces.js";
1
+ import type { StackPageProps } from "../containers.js";
2
2
  export type StackPageLike = {
3
3
  setName(name: string): void;
4
4
  setTitle(title: string): void;
@@ -1,5 +1,5 @@
1
1
  import type * as Gtk from "@gtkx/ffi/gtk";
2
- import { type StackPageContainer, type StackPageProps } from "../container-interfaces.js";
2
+ import type { StackPageContainer, StackPageProps } from "../containers.js";
3
3
  import type { Props } from "../factory.js";
4
4
  import type { Node } from "../node.js";
5
5
  import { PagedStackNode } from "./paged-stack.js";
@@ -1,4 +1,4 @@
1
- import { isStackPageContainer } from "../container-interfaces.js";
1
+ import { isStackPageContainer } from "../predicates.js";
2
2
  import { PagedStackNode } from "./paged-stack.js";
3
3
  import { applyStackPageProps } from "./stack-page-props.js";
4
4
  import { VirtualSlotNode } from "./virtual-slot.js";
@@ -11,7 +11,7 @@ export class StackNode extends PagedStackNode {
11
11
  const { name, title } = props;
12
12
  let stackPage;
13
13
  if (title !== undefined) {
14
- stackPage = this.widget.addTitled(child, title, name ?? null);
14
+ stackPage = this.widget.addTitled(child, title, name);
15
15
  }
16
16
  else if (name !== undefined) {
17
17
  stackPage = this.widget.addNamed(child, name);
@@ -1,20 +1,10 @@
1
1
  import * as Gio from "@gtkx/ffi/gio";
2
2
  import type * as Gtk from "@gtkx/ffi/gtk";
3
+ import type { StringListContainer } from "../containers.js";
3
4
  import type { Props } from "../factory.js";
4
5
  import type { Node } from "../node.js";
5
6
  import { Node as NodeClass } from "../node.js";
6
7
  import { StringListStore } from "./string-list-store.js";
7
- export type StringListItem = {
8
- id: string;
9
- label: string;
10
- };
11
- type StringListContainer = {
12
- addStringListItem(id: string, label: string): void;
13
- insertStringListItemBefore(id: string, label: string, beforeId: string): void;
14
- removeStringListItem(id: string): void;
15
- updateStringListItem(oldId: string, newId: string, newLabel: string): void;
16
- };
17
- export declare const isStringListContainer: (node: Node) => node is Node & StringListContainer;
18
8
  type StringListContainerState = {
19
9
  store: StringListStore;
20
10
  onSelectionChanged?: (id: string) => void;
@@ -22,12 +12,15 @@ type StringListContainerState = {
22
12
  hasAppliedInitialSelection: boolean;
23
13
  };
24
14
  type StringListWidget = Gtk.Widget & {
25
- setModel(model: Gio.ListModel | null): void;
15
+ setModel(model?: Gio.ListModel): void;
26
16
  getSelected(): number;
27
17
  setSelected(position: number): void;
28
18
  };
29
19
  export declare abstract class StringListContainerNode<T extends StringListWidget> extends NodeClass<T, StringListContainerState> implements StringListContainer {
30
20
  static consumedPropNames: string[];
21
+ appendChild(child: Node): void;
22
+ insertBefore(child: Node, before: Node): void;
23
+ removeChild(child: Node): void;
31
24
  initialize(props: Props): void;
32
25
  private connectSelectionHandler;
33
26
  addStringListItem(id: string, label: string): void;
@@ -1,22 +1,50 @@
1
- import { getInterface } from "@gtkx/ffi";
1
+ import { getObject } from "@gtkx/ffi";
2
2
  import * as Gio from "@gtkx/ffi/gio";
3
3
  import { Node as NodeClass } from "../node.js";
4
4
  import { getCallbackChange } from "../props.js";
5
+ import { StringListItemNode } from "./string-list-item.js";
5
6
  import { StringListStore } from "./string-list-store.js";
6
- export const isStringListContainer = (node) => "addStringListItem" in node &&
7
- "insertStringListItemBefore" in node &&
8
- "removeStringListItem" in node &&
9
- "updateStringListItem" in node;
10
7
  const SELECTION_SIGNAL = "notify::selected";
11
8
  export class StringListContainerNode extends NodeClass {
12
9
  static consumedPropNames = ["onSelectionChanged", "selectedId"];
10
+ appendChild(child) {
11
+ if (child instanceof StringListItemNode) {
12
+ child.parent = this;
13
+ child.addToContainer(this);
14
+ child.setParentContainer(this);
15
+ return;
16
+ }
17
+ super.appendChild(child);
18
+ }
19
+ insertBefore(child, before) {
20
+ if (child instanceof StringListItemNode) {
21
+ child.parent = this;
22
+ if (before instanceof StringListItemNode) {
23
+ child.insertBeforeInContainer(this, before.getId());
24
+ }
25
+ else {
26
+ child.addToContainer(this);
27
+ }
28
+ child.setParentContainer(this);
29
+ return;
30
+ }
31
+ super.insertBefore(child, before);
32
+ }
33
+ removeChild(child) {
34
+ if (child instanceof StringListItemNode) {
35
+ child.unmount();
36
+ child.parent = null;
37
+ return;
38
+ }
39
+ super.removeChild(child);
40
+ }
13
41
  initialize(props) {
14
42
  const store = new StringListStore();
15
43
  const onSelectionChanged = props.onSelectionChanged;
16
44
  const initialSelection = props.selectedId;
17
45
  this.state = { store, onSelectionChanged, initialSelection, hasAppliedInitialSelection: false };
18
46
  super.initialize(props);
19
- this.widget.setModel(getInterface(store.getModel().id, Gio.ListModel));
47
+ this.widget.setModel(getObject(store.getModel().id, Gio.ListModel) ?? undefined);
20
48
  }
21
49
  connectSelectionHandler() {
22
50
  const handler = () => {
@@ -1,15 +1,19 @@
1
+ import type { StringListContainer, StringListItem } from "../containers.js";
1
2
  import type { Props } from "../factory.js";
2
- import { Node } from "../node.js";
3
- import { type StringListItem } from "./string-list-container.js";
4
- export declare abstract class StringListItemNode extends Node<never> {
3
+ import type { Node } from "../node.js";
4
+ import { Node as NodeClass } from "../node.js";
5
+ export declare abstract class StringListItemNode extends NodeClass<never> {
5
6
  static consumedPropNames: string[];
6
7
  protected isVirtual(): boolean;
7
8
  private id;
8
9
  private label;
10
+ private parentContainer;
9
11
  initialize(props: Props): void;
12
+ getId(): string;
10
13
  getStringListItem(): StringListItem;
11
- attachToParent(parent: Node): void;
12
- attachToParentBefore(parent: Node, before: Node): void;
13
- detachFromParent(parent: Node): void;
14
+ setParentContainer(container: Node & StringListContainer): void;
15
+ addToContainer(container: StringListContainer): void;
16
+ insertBeforeInContainer(container: StringListContainer, beforeId: string): void;
17
+ unmount(): void;
14
18
  updateProps(oldProps: Props, newProps: Props): void;
15
19
  }
@@ -1,37 +1,39 @@
1
- import { Node } from "../node.js";
2
- import { isStringListContainer } from "./string-list-container.js";
3
- export class StringListItemNode extends Node {
1
+ import { Node as NodeClass } from "../node.js";
2
+ import { isStringListContainer } from "../predicates.js";
3
+ export class StringListItemNode extends NodeClass {
4
4
  static consumedPropNames = ["id", "label"];
5
5
  isVirtual() {
6
6
  return true;
7
7
  }
8
8
  id = "";
9
9
  label = "";
10
+ parentContainer = null;
10
11
  initialize(props) {
11
12
  this.id = props.id;
12
13
  this.label = props.label;
13
14
  super.initialize(props);
14
15
  }
16
+ getId() {
17
+ return this.id;
18
+ }
15
19
  getStringListItem() {
16
20
  return { id: this.id, label: this.label };
17
21
  }
18
- attachToParent(parent) {
19
- if (isStringListContainer(parent)) {
20
- parent.addStringListItem(this.id, this.label);
21
- }
22
+ setParentContainer(container) {
23
+ this.parentContainer = container;
22
24
  }
23
- attachToParentBefore(parent, before) {
24
- if (isStringListContainer(parent) && before instanceof StringListItemNode) {
25
- parent.insertStringListItemBefore(this.id, this.label, before.id);
26
- }
27
- else {
28
- this.attachToParent(parent);
29
- }
25
+ addToContainer(container) {
26
+ container.addStringListItem(this.id, this.label);
27
+ }
28
+ insertBeforeInContainer(container, beforeId) {
29
+ container.insertStringListItemBefore(this.id, this.label, beforeId);
30
30
  }
31
- detachFromParent(parent) {
32
- if (isStringListContainer(parent)) {
33
- parent.removeStringListItem(this.id);
31
+ unmount() {
32
+ if (this.parentContainer) {
33
+ this.parentContainer.removeStringListItem(this.id);
34
34
  }
35
+ this.parentContainer = null;
36
+ super.unmount();
35
37
  }
36
38
  updateProps(oldProps, newProps) {
37
39
  const oldId = oldProps.id;
@@ -16,9 +16,6 @@ export declare class ToggleButtonNode extends Node<Gtk.ToggleButton, ToggleButto
16
16
  static consumedPropNames: string[];
17
17
  static matches(type: string): boolean;
18
18
  initialize(props: Props): void;
19
- attachToParent(parent: Node): void;
20
- attachToParentBefore(parent: Node, before: Node): void;
21
- detachFromParent(parent: Node): void;
22
19
  updateProps(_oldProps: Props, newProps: Props): void;
23
20
  protected connectSignal(widget: Gtk.Widget, eventName: string, handler: (...args: unknown[]) => unknown): void;
24
21
  }
@@ -1,4 +1,3 @@
1
- import { isChildContainer } from "../container-interfaces.js";
2
1
  import { Node } from "../node.js";
3
2
  /**
4
3
  * Specialized node for GtkToggleButton that prevents signal feedback loops.
@@ -17,33 +16,6 @@ export class ToggleButtonNode extends Node {
17
16
  this.state = { lastPropsActive: undefined };
18
17
  super.initialize(props);
19
18
  }
20
- attachToParent(parent) {
21
- if (isChildContainer(parent)) {
22
- parent.attachChild(this.widget);
23
- return;
24
- }
25
- super.attachToParent(parent);
26
- }
27
- attachToParentBefore(parent, before) {
28
- if (isChildContainer(parent)) {
29
- const beforeWidget = before.getWidget();
30
- if (beforeWidget) {
31
- parent.insertChildBefore(this.widget, beforeWidget);
32
- }
33
- else {
34
- parent.attachChild(this.widget);
35
- }
36
- return;
37
- }
38
- super.attachToParentBefore(parent, before);
39
- }
40
- detachFromParent(parent) {
41
- if (isChildContainer(parent)) {
42
- parent.detachChild(this.widget);
43
- return;
44
- }
45
- super.detachFromParent(parent);
46
- }
47
19
  updateProps(_oldProps, newProps) {
48
20
  const widget = this.getWidget();
49
21
  if (!widget) {
@@ -7,13 +7,12 @@ export declare class ToolbarViewSlotNode extends Node<never> {
7
7
  static matches(type: string): boolean;
8
8
  protected isVirtual(): boolean;
9
9
  private slotType;
10
- private parentNode;
11
10
  private children;
12
11
  constructor(type: string);
13
12
  appendChild(child: Node): void;
14
13
  removeChild(child: Node): void;
15
- attachToParent(parent: Node): void;
16
- detachFromParent(_parent: Node): void;
14
+ mount(): void;
15
+ unmount(): void;
17
16
  private addBarToParent;
18
17
  private removeBarFromParent;
19
18
  }
@@ -14,7 +14,6 @@ export class ToolbarViewSlotNode extends Node {
14
14
  return true;
15
15
  }
16
16
  slotType;
17
- parentNode = null;
18
17
  children = [];
19
18
  constructor(type) {
20
19
  super(type);
@@ -25,26 +24,28 @@ export class ToolbarViewSlotNode extends Node {
25
24
  this.slotType = slot;
26
25
  }
27
26
  appendChild(child) {
27
+ child.parent = this;
28
28
  const childWidget = child.getWidget();
29
29
  if (!childWidget)
30
30
  return;
31
31
  this.children.push(child);
32
- if (this.parentNode) {
32
+ if (this.parent) {
33
33
  this.addBarToParent(childWidget);
34
34
  }
35
35
  }
36
36
  removeChild(child) {
37
+ child.unmount();
37
38
  const index = this.children.indexOf(child);
38
39
  if (index !== -1) {
39
40
  this.children.splice(index, 1);
40
41
  }
41
42
  const childWidget = child.getWidget();
42
- if (this.parentNode && childWidget) {
43
+ if (this.parent && childWidget) {
43
44
  this.removeBarFromParent(childWidget);
44
45
  }
46
+ child.parent = null;
45
47
  }
46
- attachToParent(parent) {
47
- this.parentNode = parent;
48
+ mount() {
48
49
  for (const child of this.children) {
49
50
  const childWidget = child.getWidget();
50
51
  if (childWidget) {
@@ -52,17 +53,17 @@ export class ToolbarViewSlotNode extends Node {
52
53
  }
53
54
  }
54
55
  }
55
- detachFromParent(_parent) {
56
+ unmount() {
56
57
  for (const child of this.children) {
57
58
  const childWidget = child.getWidget();
58
59
  if (childWidget) {
59
60
  this.removeBarFromParent(childWidget);
60
61
  }
61
62
  }
62
- this.parentNode = null;
63
+ super.unmount();
63
64
  }
64
65
  addBarToParent(childWidget) {
65
- const parentWidget = this.parentNode?.getWidget();
66
+ const parentWidget = this.parent?.getWidget();
66
67
  if (!parentWidget)
67
68
  return;
68
69
  if (this.slotType === "Top") {
@@ -73,7 +74,7 @@ export class ToolbarViewSlotNode extends Node {
73
74
  }
74
75
  }
75
76
  removeBarFromParent(childWidget) {
76
- const parentWidget = this.parentNode?.getWidget();
77
+ const parentWidget = this.parent?.getWidget();
77
78
  if (!parentWidget)
78
79
  return;
79
80
  parentWidget.remove(childWidget);
@@ -1,6 +1,6 @@
1
1
  import type * as Adw from "@gtkx/ffi/adw";
2
2
  import type * as Gtk from "@gtkx/ffi/gtk";
3
- import type { StackPageProps } from "../container-interfaces.js";
3
+ import type { StackPageProps } from "../containers.js";
4
4
  import { PagedStackNode } from "./paged-stack.js";
5
5
  export declare class ViewStackNode extends PagedStackNode<Adw.ViewStack> {
6
6
  static matches(type: string): boolean;
@@ -8,10 +8,10 @@ export class ViewStackNode extends PagedStackNode {
8
8
  const { name, title, iconName } = props;
9
9
  let page;
10
10
  if (title !== undefined && iconName !== undefined) {
11
- page = this.widget.addTitledWithIcon(child, title, iconName, name ?? null);
11
+ page = this.widget.addTitledWithIcon(child, title, iconName, name);
12
12
  }
13
13
  else if (title !== undefined) {
14
- page = this.widget.addTitled(child, title, name ?? null);
14
+ page = this.widget.addTitled(child, title, name);
15
15
  }
16
16
  else if (name !== undefined) {
17
17
  page = this.widget.addNamed(child, name);
@@ -1,20 +1,24 @@
1
+ import type { ItemContainer } from "../containers.js";
1
2
  import type { Props } from "../factory.js";
2
- import { Node } from "../node.js";
3
+ import type { Node } from "../node.js";
4
+ import { Node as NodeClass } from "../node.js";
3
5
  /**
4
6
  * Base class for virtual item nodes used in list-based containers.
5
7
  * Virtual nodes don't create GTK widgets directly but represent items
6
8
  * in list models (ListView, GridView, ColumnView).
7
9
  */
8
- export declare abstract class VirtualItemNode extends Node<never> {
10
+ export declare abstract class VirtualItemNode extends NodeClass<never> {
9
11
  static consumedPropNames: string[];
10
12
  protected isVirtual(): boolean;
11
13
  private id;
12
14
  private item;
15
+ private parentContainer;
13
16
  initialize(props: Props): void;
14
17
  getId(): string;
15
18
  getItem(): unknown;
16
- attachToParent(parent: Node): void;
17
- attachToParentBefore(parent: Node, before: Node): void;
18
- detachFromParent(parent: Node): void;
19
+ setParentContainer(container: Node & ItemContainer<unknown>): void;
20
+ addToContainer(container: ItemContainer<unknown>): void;
21
+ insertBeforeInContainer(container: ItemContainer<unknown>, beforeId: string): void;
22
+ unmount(): void;
19
23
  updateProps(oldProps: Props, newProps: Props): void;
20
24
  }