@gtkx/react 0.1.12 → 0.1.15

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.
@@ -1,46 +1,33 @@
1
+ import { wrapPtr } from "@gtkx/ffi";
1
2
  import * as Gtk from "@gtkx/ffi/gtk";
2
- import { appendChild, disconnectSignalHandlers, isConnectable, removeChild } from "../widget-capabilities.js";
3
- const isListViewWidget = (widget) => "setModel" in widget &&
4
- typeof widget.setModel === "function" &&
5
- "setFactory" in widget &&
6
- typeof widget.setFactory === "function";
7
- const LIST_VIEW_TYPES = ["ListView", "ListView.Root"];
8
- export class ListViewNode {
9
- static needsWidget = true;
10
- static matches(type, widget) {
11
- if (!LIST_VIEW_TYPES.includes(type) && !type.startsWith("ListView"))
12
- return false;
13
- return widget !== null && isListViewWidget(widget);
3
+ import { Node } from "../node.js";
4
+ const LIST_WIDGETS = ["ListView", "ColumnView", "GridView"];
5
+ export class ListViewNode extends Node {
6
+ static matches(type) {
7
+ return LIST_WIDGETS.map((w) => `${w}.Root`).includes(type);
14
8
  }
15
- widget;
16
9
  stringList;
17
10
  selectionModel;
18
11
  factory;
19
12
  items = [];
20
13
  renderItem = null;
21
- signalHandlers = new Map();
22
14
  factorySignalHandlers = new Map();
23
- constructor(_type, widget, props) {
24
- if (!isListViewWidget(widget)) {
25
- throw new Error("ListViewNode requires a ListView widget");
26
- }
27
- this.widget = widget;
15
+ constructor(type, props, currentApp) {
16
+ super(type, props, currentApp);
28
17
  this.stringList = new Gtk.StringList([]);
29
18
  this.selectionModel = new Gtk.SingleSelection(this.stringList);
30
19
  this.factory = new Gtk.SignalListItemFactory();
31
20
  this.renderItem = props.renderItem;
32
- const setupHandlerId = this.factory.connect("setup", (listItemPtr) => {
33
- const listItem = Object.create(Gtk.ListItem.prototype);
34
- listItem.ptr = listItemPtr;
21
+ const setupHandlerId = this.factory.connect("setup", (_self, listItemObj) => {
22
+ const listItem = wrapPtr(listItemObj, Gtk.ListItem);
35
23
  if (this.renderItem) {
36
24
  const widget = this.renderItem(null);
37
25
  listItem.setChild(widget);
38
26
  }
39
27
  });
40
28
  this.factorySignalHandlers.set("setup", setupHandlerId);
41
- const bindHandlerId = this.factory.connect("bind", (listItemPtr) => {
42
- const listItem = Object.create(Gtk.ListItem.prototype);
43
- listItem.ptr = listItemPtr;
29
+ const bindHandlerId = this.factory.connect("bind", (_self, listItemObj) => {
30
+ const listItem = wrapPtr(listItemObj, Gtk.ListItem);
44
31
  const position = listItem.getPosition();
45
32
  const item = this.items[position];
46
33
  if (this.renderItem && item !== undefined) {
@@ -49,32 +36,8 @@ export class ListViewNode {
49
36
  }
50
37
  });
51
38
  this.factorySignalHandlers.set("bind", bindHandlerId);
52
- this.widget.setModel(this.selectionModel.ptr);
53
- this.widget.setFactory(this.factory.ptr);
54
- }
55
- getWidget() {
56
- return this.widget;
57
- }
58
- appendChild(child) {
59
- child.attachToParent(this);
60
- }
61
- removeChild(child) {
62
- child.detachFromParent(this);
63
- }
64
- insertBefore(child, _before) {
65
- this.appendChild(child);
66
- }
67
- attachToParent(parent) {
68
- const parentWidget = parent.getWidget?.();
69
- if (parentWidget) {
70
- appendChild(parentWidget, this.widget);
71
- }
72
- }
73
- detachFromParent(parent) {
74
- const parentWidget = parent.getWidget?.();
75
- if (parentWidget) {
76
- removeChild(parentWidget, this.widget);
77
- }
39
+ this.widget.setModel(this.selectionModel);
40
+ this.widget.setFactory(this.factory);
78
41
  }
79
42
  addItem(item) {
80
43
  this.items.push(item);
@@ -87,52 +50,25 @@ export class ListViewNode {
87
50
  this.stringList.remove(index);
88
51
  }
89
52
  }
53
+ consumedProps() {
54
+ const consumed = super.consumedProps();
55
+ consumed.add("renderItem");
56
+ return consumed;
57
+ }
90
58
  updateProps(oldProps, newProps) {
91
59
  if (oldProps.renderItem !== newProps.renderItem) {
92
60
  this.renderItem = newProps.renderItem;
93
61
  }
94
- const consumedProps = new Set(["children", "renderItem"]);
95
- const allKeys = new Set([...Object.keys(oldProps), ...Object.keys(newProps)]);
96
- for (const key of allKeys) {
97
- if (consumedProps.has(key))
98
- continue;
99
- const oldValue = oldProps[key];
100
- const newValue = newProps[key];
101
- if (oldValue === newValue)
102
- continue;
103
- if (key.startsWith("on")) {
104
- const eventName = key
105
- .slice(2)
106
- .replace(/([A-Z])/g, "-$1")
107
- .toLowerCase()
108
- .replace(/^-/, "");
109
- const oldHandlerId = this.signalHandlers.get(eventName);
110
- if (oldHandlerId !== undefined && isConnectable(this.widget)) {
111
- this.signalHandlers.delete(eventName);
112
- }
113
- if (typeof newValue === "function" && isConnectable(this.widget)) {
114
- const handlerId = this.widget.connect(eventName, newValue);
115
- this.signalHandlers.set(eventName, handlerId);
116
- }
117
- continue;
118
- }
119
- const setterName = `set${key.charAt(0).toUpperCase()}${key.slice(1)}`;
120
- const setter = this.widget[setterName];
121
- if (typeof setter === "function") {
122
- setter.call(this.widget, newValue);
123
- }
124
- }
62
+ super.updateProps(oldProps, newProps);
125
63
  }
126
- mount() { }
127
64
  dispose() {
128
- disconnectSignalHandlers(this.widget, this.signalHandlers);
129
- disconnectSignalHandlers(this.factory, this.factorySignalHandlers);
65
+ super.dispose();
66
+ this.widget.setModel(undefined);
67
+ this.widget.setFactory(undefined);
130
68
  }
131
69
  }
132
- const LIST_WIDGETS = ["ListView", "ColumnView", "GridView"];
133
- export class ListItemNode {
134
- static needsWidget = false;
135
- static matches(type, _widget) {
70
+ export class ListItemNode extends Node {
71
+ static matches(type) {
136
72
  const dotIndex = type.indexOf(".");
137
73
  if (dotIndex === -1)
138
74
  return false;
@@ -140,16 +76,17 @@ export class ListItemNode {
140
76
  const suffix = type.slice(dotIndex + 1);
141
77
  return suffix === "Item" && LIST_WIDGETS.includes(widgetType);
142
78
  }
79
+ isVirtual() {
80
+ return true;
81
+ }
143
82
  item;
144
- constructor(_type, _widget, props) {
83
+ constructor(type, props, _currentApp) {
84
+ super(type, props);
145
85
  this.item = props.item;
146
86
  }
147
87
  getItem() {
148
88
  return this.item;
149
89
  }
150
- appendChild(_child) { }
151
- removeChild(_child) { }
152
- insertBefore(_child, _before) { }
153
90
  attachToParent(parent) {
154
91
  if (parent instanceof ListViewNode) {
155
92
  parent.addItem(this.item);
@@ -160,6 +97,4 @@ export class ListItemNode {
160
97
  parent.removeItem(this.item);
161
98
  }
162
99
  }
163
- updateProps(_oldProps, _newProps) { }
164
- mount() { }
165
100
  }
@@ -1,29 +1,9 @@
1
1
  import type * as Gtk from "@gtkx/ffi/gtk";
2
- import type { Props } from "../factory.js";
3
- import type { Node } from "../node.js";
4
- interface OverlayWidget extends Gtk.Widget {
5
- setChild(child: unknown): void;
6
- addOverlay(widget: unknown): void;
7
- removeOverlay(widget: unknown): void;
8
- }
9
- export declare class OverlayNode implements Node<OverlayWidget> {
10
- static needsWidget: boolean;
11
- static matches(type: string, widget: Gtk.Widget | null): widget is OverlayWidget;
12
- private widget;
2
+ import { Node } from "../node.js";
3
+ export declare class OverlayNode extends Node<Gtk.Overlay> {
4
+ static matches(type: string): boolean;
13
5
  private mainChild;
14
6
  private overlayChildren;
15
- private signalHandlers;
16
- constructor(_type: string, widget: Gtk.Widget, _props: Props);
17
- getWidget(): OverlayWidget;
18
- appendChild(child: Node): void;
19
- removeChild(child: Node): void;
20
- insertBefore(child: Node, _before: Node): void;
21
- attachToParent(parent: Node): void;
22
- detachFromParent(parent: Node): void;
23
7
  attachChild(childWidget: Gtk.Widget): void;
24
8
  detachChild(childWidget: Gtk.Widget): void;
25
- updateProps(oldProps: Props, newProps: Props): void;
26
- mount(): void;
27
- dispose(): void;
28
9
  }
29
- export {};
@@ -1,59 +1,18 @@
1
- import { appendChild, disconnectSignalHandlers, isConnectable, removeChild } from "../widget-capabilities.js";
2
- const isOverlayWidget = (widget) => "setChild" in widget &&
3
- typeof widget.setChild === "function" &&
4
- "addOverlay" in widget &&
5
- typeof widget.addOverlay === "function" &&
6
- "removeOverlay" in widget &&
7
- typeof widget.removeOverlay === "function";
8
- export class OverlayNode {
9
- static needsWidget = true;
10
- static matches(type, widget) {
11
- if (type !== "Overlay" && type !== "Overlay.Root")
12
- return false;
13
- return widget !== null && isOverlayWidget(widget);
1
+ import { Node } from "../node.js";
2
+ export class OverlayNode extends Node {
3
+ static matches(type) {
4
+ return type === "Overlay" || type === "Overlay.Root";
14
5
  }
15
- widget;
16
6
  mainChild = null;
17
7
  overlayChildren = [];
18
- signalHandlers = new Map();
19
- constructor(_type, widget, _props) {
20
- if (!isOverlayWidget(widget)) {
21
- throw new Error("OverlayNode requires an Overlay widget");
22
- }
23
- this.widget = widget;
24
- }
25
- getWidget() {
26
- return this.widget;
27
- }
28
- appendChild(child) {
29
- child.attachToParent(this);
30
- }
31
- removeChild(child) {
32
- child.detachFromParent(this);
33
- }
34
- insertBefore(child, _before) {
35
- this.appendChild(child);
36
- }
37
- attachToParent(parent) {
38
- const parentWidget = parent.getWidget?.();
39
- if (parentWidget) {
40
- appendChild(parentWidget, this.widget);
41
- }
42
- }
43
- detachFromParent(parent) {
44
- const parentWidget = parent.getWidget?.();
45
- if (parentWidget) {
46
- removeChild(parentWidget, this.widget);
47
- }
48
- }
49
8
  attachChild(childWidget) {
50
9
  if (this.mainChild === null) {
51
10
  this.mainChild = childWidget;
52
- this.widget.setChild(childWidget.ptr);
11
+ this.widget.setChild(childWidget);
53
12
  }
54
13
  else {
55
14
  this.overlayChildren.push(childWidget);
56
- this.widget.addOverlay(childWidget.ptr);
15
+ this.widget.addOverlay(childWidget);
57
16
  }
58
17
  }
59
18
  detachChild(childWidget) {
@@ -65,45 +24,8 @@ export class OverlayNode {
65
24
  const index = this.overlayChildren.indexOf(childWidget);
66
25
  if (index !== -1) {
67
26
  this.overlayChildren.splice(index, 1);
68
- this.widget.removeOverlay(childWidget.ptr);
27
+ this.widget.removeOverlay(childWidget);
69
28
  }
70
29
  }
71
30
  }
72
- updateProps(oldProps, newProps) {
73
- const consumedProps = new Set(["children"]);
74
- const allKeys = new Set([...Object.keys(oldProps), ...Object.keys(newProps)]);
75
- for (const key of allKeys) {
76
- if (consumedProps.has(key))
77
- continue;
78
- const oldValue = oldProps[key];
79
- const newValue = newProps[key];
80
- if (oldValue === newValue)
81
- continue;
82
- if (key.startsWith("on")) {
83
- const eventName = key
84
- .slice(2)
85
- .replace(/([A-Z])/g, "-$1")
86
- .toLowerCase()
87
- .replace(/^-/, "");
88
- const oldHandlerId = this.signalHandlers.get(eventName);
89
- if (oldHandlerId !== undefined && isConnectable(this.widget)) {
90
- this.signalHandlers.delete(eventName);
91
- }
92
- if (typeof newValue === "function" && isConnectable(this.widget)) {
93
- const handlerId = this.widget.connect(eventName, newValue);
94
- this.signalHandlers.set(eventName, handlerId);
95
- }
96
- continue;
97
- }
98
- const setterName = `set${key.charAt(0).toUpperCase()}${key.slice(1)}`;
99
- const setter = this.widget[setterName];
100
- if (typeof setter === "function") {
101
- setter.call(this.widget, newValue);
102
- }
103
- }
104
- }
105
- mount() { }
106
- dispose() {
107
- disconnectSignalHandlers(this.widget, this.signalHandlers);
108
- }
109
31
  }
@@ -1,17 +1,13 @@
1
- import type * as Gtk from "@gtkx/ffi/gtk";
2
1
  import type { Props } from "../factory.js";
3
- import type { Node } from "../node.js";
4
- export declare class SlotNode implements Node {
5
- static needsWidget: boolean;
6
- static matches(type: string, _widget: Gtk.Widget | null): _widget is Gtk.Widget;
2
+ import { Node } from "../node.js";
3
+ export declare class SlotNode extends Node<never> {
4
+ static matches(type: string): boolean;
5
+ protected isVirtual(): boolean;
7
6
  private child;
8
7
  private slotName;
9
- constructor(type: string, _widget: Gtk.Widget, _props: Props);
8
+ constructor(type: string, props: Props, _currentApp?: unknown);
10
9
  appendChild(child: Node): void;
11
10
  removeChild(_child: Node): void;
12
- insertBefore(child: Node, _before: Node): void;
13
- updateProps(_oldProps: Props, _newProps: Props): void;
14
- mount(): void;
15
11
  attachToParent(parent: Node): void;
16
12
  detachFromParent(parent: Node): void;
17
13
  }
@@ -1,17 +1,21 @@
1
- export class SlotNode {
2
- static needsWidget = false;
3
- static matches(type, _widget) {
1
+ import { Node } from "../node.js";
2
+ export class SlotNode extends Node {
3
+ static matches(type) {
4
4
  if (!type.includes("."))
5
5
  return false;
6
6
  const parts = type.split(".");
7
7
  if (parts.length !== 2)
8
8
  return false;
9
9
  const suffix = parts[1];
10
- return suffix !== "Item" && suffix !== "Root";
10
+ return suffix !== "Root";
11
+ }
12
+ isVirtual() {
13
+ return true;
11
14
  }
12
15
  child = null;
13
16
  slotName;
14
- constructor(type, _widget, _props) {
17
+ constructor(type, props, _currentApp) {
18
+ super(type, props);
15
19
  const dotIndex = type.indexOf(".");
16
20
  if (dotIndex === -1) {
17
21
  throw new Error(`Invalid slot type: ${type}`);
@@ -19,21 +23,16 @@ export class SlotNode {
19
23
  this.slotName = type.substring(dotIndex + 1);
20
24
  }
21
25
  appendChild(child) {
22
- if (child.getWidget) {
26
+ if (child.getWidget()) {
23
27
  this.child = child;
24
28
  }
25
29
  }
26
30
  removeChild(_child) {
27
31
  this.child = null;
28
32
  }
29
- insertBefore(child, _before) {
30
- this.appendChild(child);
31
- }
32
- updateProps(_oldProps, _newProps) { }
33
- mount() { }
34
33
  attachToParent(parent) {
35
- const parentWidget = parent.getWidget?.();
36
- const childWidget = this.child?.getWidget?.();
34
+ const parentWidget = parent.getWidget();
35
+ const childWidget = this.child?.getWidget();
37
36
  if (!parentWidget || !childWidget)
38
37
  return;
39
38
  const setterName = `set${this.slotName}`;
@@ -43,7 +42,7 @@ export class SlotNode {
43
42
  }
44
43
  }
45
44
  detachFromParent(parent) {
46
- const parentWidget = parent.getWidget?.();
45
+ const parentWidget = parent.getWidget();
47
46
  if (!parentWidget)
48
47
  return;
49
48
  const setterName = `set${this.slotName}`;
@@ -1,18 +1,15 @@
1
- import type * as Gtk from "@gtkx/ffi/gtk";
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
2
  import type { Props } from "../factory.js";
3
- import type { Node } from "../node.js";
4
- export declare class WidgetNode implements Node {
5
- static needsWidget: boolean;
6
- static matches(_type: string, widget: Gtk.Widget | null): widget is Gtk.Widget;
7
- private widget;
8
- private signalHandlers;
9
- constructor(_type: string, widget: Gtk.Widget, _props: Props);
10
- getWidget(): Gtk.Widget;
11
- appendChild(child: Node): void;
12
- removeChild(child: Node): void;
13
- insertBefore(child: Node, _before: Node): void;
3
+ import { Node } from "../node.js";
4
+ export declare class WidgetWrapper extends Node<Gtk.Widget> {
5
+ constructor(widget: Gtk.Widget);
6
+ protected isVirtual(): boolean;
7
+ }
8
+ export declare class WidgetNode extends Node<Gtk.Widget> {
9
+ static matches(_type: string): boolean;
14
10
  attachToParent(parent: Node): void;
15
11
  detachFromParent(parent: Node): void;
12
+ protected consumedProps(): Set<string>;
16
13
  updateProps(oldProps: Props, newProps: Props): void;
17
14
  mount(): void;
18
15
  dispose(): void;
@@ -1,13 +1,12 @@
1
- import * as GObject from "@gtkx/ffi/gobject";
2
- import { appendChild, disconnectSignalHandlers, isConnectable, isDefaultSizable, isPresentable, removeChild, } from "../widget-capabilities.js";
3
- import { ActionBarNode } from "./action-bar.js";
4
- import { NotebookNode } from "./notebook.js";
1
+ import * as Gtk from "@gtkx/ffi/gtk";
2
+ import { Node } from "../node.js";
3
+ import { getCurrentApp } from "../reconciler.js";
5
4
  import { OverlayNode } from "./overlay.js";
6
5
  const COMBINED_PROPS = [
7
6
  {
8
7
  props: ["defaultWidth", "defaultHeight"],
9
8
  apply: (widget) => (values) => {
10
- if (isDefaultSizable(widget)) {
9
+ if (widget instanceof Gtk.Window) {
11
10
  const width = values.defaultWidth ?? -1;
12
11
  const height = values.defaultHeight ?? -1;
13
12
  widget.setDefaultSize(width, height);
@@ -15,122 +14,103 @@ const COMBINED_PROPS = [
15
14
  },
16
15
  },
17
16
  ];
18
- export class WidgetNode {
19
- static needsWidget = true;
20
- static matches(_type, widget) {
21
- return widget !== null;
22
- }
23
- widget;
24
- signalHandlers = new Map();
25
- constructor(_type, widget, _props) {
17
+ export class WidgetWrapper extends Node {
18
+ constructor(widget) {
19
+ super("", {});
26
20
  this.widget = widget;
27
21
  }
28
- getWidget() {
29
- return this.widget;
30
- }
31
- appendChild(child) {
32
- child.attachToParent(this);
22
+ isVirtual() {
23
+ return true;
33
24
  }
34
- removeChild(child) {
35
- child.detachFromParent(this);
36
- }
37
- insertBefore(child, _before) {
38
- this.appendChild(child);
25
+ }
26
+ export class WidgetNode extends Node {
27
+ static matches(_type) {
28
+ return true;
39
29
  }
40
30
  attachToParent(parent) {
41
- if (parent instanceof NotebookNode) {
42
- parent.attachChild(this.widget);
31
+ if (this.widget instanceof Gtk.AboutDialog) {
43
32
  return;
44
33
  }
45
34
  if (parent instanceof OverlayNode) {
46
35
  parent.attachChild(this.widget);
47
36
  return;
48
37
  }
49
- if (parent instanceof ActionBarNode) {
50
- parent.attachChild(this.widget);
38
+ const parentWidget = parent.getWidget();
39
+ if (!parentWidget)
40
+ return;
41
+ if (parentWidget instanceof Gtk.ActionBar) {
42
+ parentWidget.packStart(this.widget);
51
43
  return;
52
44
  }
53
- const parentWidget = parent.getWidget?.();
54
- if (parentWidget) {
55
- appendChild(parentWidget, this.widget);
45
+ if (parentWidget instanceof Gtk.Notebook) {
46
+ parentWidget.appendPage(this.widget);
47
+ return;
56
48
  }
49
+ super.attachToParent(parent);
57
50
  }
58
51
  detachFromParent(parent) {
59
- if (parent instanceof NotebookNode) {
60
- parent.detachChild(this.widget);
52
+ if (this.widget instanceof Gtk.AboutDialog) {
61
53
  return;
62
54
  }
63
55
  if (parent instanceof OverlayNode) {
64
56
  parent.detachChild(this.widget);
65
57
  return;
66
58
  }
67
- if (parent instanceof ActionBarNode) {
68
- parent.detachChild(this.widget);
59
+ const parentWidget = parent.getWidget();
60
+ if (!parentWidget)
61
+ return;
62
+ if (parentWidget instanceof Gtk.ActionBar) {
63
+ parentWidget.remove(this.widget);
64
+ return;
65
+ }
66
+ if (parentWidget instanceof Gtk.Notebook) {
67
+ const pageNum = parentWidget.pageNum(this.widget);
68
+ if (pageNum >= 0) {
69
+ parentWidget.removePage(pageNum);
70
+ }
69
71
  return;
70
72
  }
71
- const parentWidget = parent.getWidget?.();
72
- if (parentWidget) {
73
- removeChild(parentWidget, this.widget);
73
+ super.detachFromParent(parent);
74
+ }
75
+ consumedProps() {
76
+ const consumed = super.consumedProps();
77
+ consumed.add("application");
78
+ for (const handler of COMBINED_PROPS) {
79
+ for (const prop of handler.props) {
80
+ consumed.add(prop);
81
+ }
74
82
  }
83
+ return consumed;
75
84
  }
76
85
  updateProps(oldProps, newProps) {
77
- const consumedProps = new Set(["children", "application"]);
78
86
  for (const handler of COMBINED_PROPS) {
79
87
  const hasAnyChanged = handler.props.some((prop) => oldProps[prop] !== newProps[prop]);
80
88
  if (hasAnyChanged) {
81
89
  const values = {};
82
90
  for (const prop of handler.props) {
83
91
  values[prop] = newProps[prop];
84
- consumedProps.add(prop);
85
92
  }
86
93
  handler.apply(this.widget)(values);
87
94
  }
88
- else {
89
- for (const prop of handler.props) {
90
- consumedProps.add(prop);
91
- }
92
- }
93
- }
94
- const allKeys = new Set([...Object.keys(oldProps), ...Object.keys(newProps)]);
95
- for (const key of allKeys) {
96
- if (consumedProps.has(key))
97
- continue;
98
- const oldValue = oldProps[key];
99
- const newValue = newProps[key];
100
- if (oldValue === newValue)
101
- continue;
102
- if (key.startsWith("on")) {
103
- const eventName = key
104
- .slice(2)
105
- .replace(/([A-Z])/g, "-$1")
106
- .toLowerCase()
107
- .replace(/^-/, "");
108
- const oldHandlerId = this.signalHandlers.get(eventName);
109
- if (oldHandlerId !== undefined) {
110
- GObject.signalHandlerDisconnect(this.widget, oldHandlerId);
111
- this.signalHandlers.delete(eventName);
112
- }
113
- if (typeof newValue === "function" && isConnectable(this.widget)) {
114
- const handlerId = this.widget.connect(eventName, newValue);
115
- this.signalHandlers.set(eventName, handlerId);
116
- }
117
- continue;
118
- }
119
- if (newValue === undefined)
120
- continue;
121
- const setterName = `set${key.charAt(0).toUpperCase()}${key.slice(1)}`;
122
- const setter = this.widget[setterName];
123
- if (typeof setter === "function") {
124
- setter.call(this.widget, newValue);
125
- }
126
95
  }
96
+ super.updateProps(oldProps, newProps);
127
97
  }
128
98
  mount() {
129
- if (isPresentable(this.widget)) {
99
+ if (this.widget instanceof Gtk.AboutDialog) {
100
+ const app = getCurrentApp();
101
+ const activeWindow = app?.getActiveWindow();
102
+ if (activeWindow) {
103
+ this.widget.setTransientFor(activeWindow);
104
+ }
105
+ }
106
+ if (this.widget instanceof Gtk.Window) {
130
107
  this.widget.present();
131
108
  }
132
109
  }
133
110
  dispose() {
134
- disconnectSignalHandlers(this.widget, this.signalHandlers);
111
+ super.dispose();
112
+ if (this.widget instanceof Gtk.Window) {
113
+ this.widget.close();
114
+ }
135
115
  }
136
116
  }
package/dist/portal.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { ReactNode, ReactPortal } from "react";
2
- export declare const isRootPortalContainer: (container: unknown) => boolean;
2
+ export declare const ROOT_CONTAINER: unique symbol;
3
3
  export declare const createPortal: (children: ReactNode, container?: unknown, key?: string | null) => ReactPortal;
package/dist/portal.js CHANGED
@@ -1,11 +1,10 @@
1
- const ROOT_PORTAL_CONTAINER = Symbol("ROOT_PORTAL_CONTAINER");
2
- export const isRootPortalContainer = (container) => container === ROOT_PORTAL_CONTAINER;
1
+ export const ROOT_CONTAINER = Symbol("ROOT_CONTAINER");
3
2
  export const createPortal = (children, container, key) => {
4
3
  return {
5
4
  $$typeof: Symbol.for("react.portal"),
6
5
  key: key ?? null,
7
6
  children,
8
- containerInfo: container ?? ROOT_PORTAL_CONTAINER,
7
+ containerInfo: container ?? ROOT_CONTAINER,
9
8
  implementation: null,
10
9
  };
11
10
  };
@@ -0,0 +1,13 @@
1
+ import type * as Gtk from "@gtkx/ffi/gtk";
2
+ export interface Appendable extends Gtk.Widget {
3
+ append(child: unknown): void;
4
+ }
5
+ export interface SingleChild extends Gtk.Widget {
6
+ setChild(child: unknown): void;
7
+ }
8
+ export interface Removable extends Gtk.Widget {
9
+ remove(child: unknown): void;
10
+ }
11
+ export declare const isAppendable: (widget: Gtk.Widget) => widget is Appendable;
12
+ export declare const isSingleChild: (widget: Gtk.Widget) => widget is SingleChild;
13
+ export declare const isRemovable: (widget: Gtk.Widget) => widget is Removable;