@gtkx/react 0.1.38 → 0.1.40

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.
@@ -6,9 +6,11 @@ export declare class SlotNode extends Node<never> {
6
6
  protected isVirtual(): boolean;
7
7
  private child;
8
8
  private slotName;
9
+ private parentNode;
9
10
  constructor(type: string, props: Props, app: Gtk.Application);
11
+ private updateParentSlot;
10
12
  appendChild(child: Node): void;
11
13
  removeChild(_child: Node): void;
12
14
  attachToParent(parent: Node): void;
13
- detachFromParent(parent: Node): void;
15
+ detachFromParent(_parent: Node): void;
14
16
  }
@@ -14,6 +14,7 @@ export class SlotNode extends Node {
14
14
  }
15
15
  child = null;
16
16
  slotName;
17
+ parentNode = null;
17
18
  constructor(type, props, app) {
18
19
  super(type, props, app);
19
20
  const dotIndex = type.indexOf(".");
@@ -22,33 +23,44 @@ export class SlotNode extends Node {
22
23
  }
23
24
  this.slotName = type.substring(dotIndex + 1);
24
25
  }
26
+ updateParentSlot() {
27
+ if (!this.parentNode)
28
+ return;
29
+ const parentWidget = this.parentNode.getWidget();
30
+ const childWidget = this.child?.getWidget();
31
+ if (!parentWidget)
32
+ return;
33
+ const setterName = `set${this.slotName}`;
34
+ const setter = parentWidget[setterName];
35
+ if (typeof setter === "function") {
36
+ setter.call(parentWidget, childWidget?.ptr ?? null);
37
+ }
38
+ }
25
39
  appendChild(child) {
26
40
  if (child.getWidget()) {
27
41
  this.child = child;
42
+ this.updateParentSlot();
28
43
  }
29
44
  }
30
45
  removeChild(_child) {
31
46
  this.child = null;
47
+ this.updateParentSlot();
32
48
  }
33
49
  attachToParent(parent) {
34
- const parentWidget = parent.getWidget();
35
- const childWidget = this.child?.getWidget();
36
- if (!parentWidget || !childWidget)
37
- return;
38
- const setterName = `set${this.slotName}`;
39
- const setter = parentWidget[setterName];
40
- if (typeof setter === "function") {
41
- setter.call(parentWidget, childWidget.ptr);
42
- }
50
+ this.parentNode = parent;
51
+ this.updateParentSlot();
43
52
  }
44
- detachFromParent(parent) {
45
- const parentWidget = parent.getWidget();
46
- if (!parentWidget)
47
- return;
48
- const setterName = `set${this.slotName}`;
49
- const setter = parentWidget[setterName];
50
- if (typeof setter === "function") {
51
- setter.call(parentWidget, null);
53
+ detachFromParent(_parent) {
54
+ if (this.parentNode) {
55
+ const parentWidget = this.parentNode.getWidget();
56
+ if (parentWidget) {
57
+ const setterName = `set${this.slotName}`;
58
+ const setter = parentWidget[setterName];
59
+ if (typeof setter === "function") {
60
+ setter.call(parentWidget, null);
61
+ }
62
+ }
52
63
  }
64
+ this.parentNode = null;
53
65
  }
54
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/react",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "Build GTK4 desktop applications with React and TypeScript",
5
5
  "keywords": [
6
6
  "gtk",
@@ -36,10 +36,10 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "react-reconciler": "0.33.0",
39
- "@gtkx/ffi": "0.1.38"
39
+ "@gtkx/ffi": "0.1.40"
40
40
  },
41
41
  "devDependencies": {
42
- "@gtkx/gir": "0.1.38"
42
+ "@gtkx/gir": "0.1.40"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "react": "^19"