@gtkx/react 0.7.0 → 0.8.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.
@@ -3,5 +3,8 @@ import { IndexedChildContainerNode } from "./indexed-child-container.js";
3
3
  export declare class FlowBoxNode extends IndexedChildContainerNode<Gtk.FlowBox> {
4
4
  static matches(type: string): boolean;
5
5
  protected getInsertionIndex(before: Gtk.Widget): number;
6
- protected getWidgetToRemove(child: Gtk.Widget): Gtk.Widget;
6
+ private unparentFromChild;
7
+ attachChild(child: Gtk.Widget): void;
8
+ insertChildBefore(child: Gtk.Widget, before: Gtk.Widget): void;
9
+ detachChild(child: Gtk.Widget): void;
7
10
  }
@@ -1,3 +1,4 @@
1
+ import { beginBatch, endBatch } from "@gtkx/ffi";
1
2
  import { isFlowBoxChild } from "../predicates.js";
2
3
  import { IndexedChildContainerNode } from "./indexed-child-container.js";
3
4
  export class FlowBoxNode extends IndexedChildContainerNode {
@@ -11,7 +12,30 @@ export class FlowBoxNode extends IndexedChildContainerNode {
11
12
  }
12
13
  return -1;
13
14
  }
14
- getWidgetToRemove(child) {
15
- return child.getParent() ?? child;
15
+ unparentFromChild(child) {
16
+ const parent = child.getParent();
17
+ if (parent && isFlowBoxChild(parent)) {
18
+ beginBatch();
19
+ parent.setChild(null);
20
+ this.widget.remove(parent);
21
+ endBatch();
22
+ }
23
+ }
24
+ attachChild(child) {
25
+ this.unparentFromChild(child);
26
+ this.widget.append(child);
27
+ }
28
+ insertChildBefore(child, before) {
29
+ this.unparentFromChild(child);
30
+ const index = this.getInsertionIndex(before);
31
+ if (index >= 0) {
32
+ this.widget.insert(child, index);
33
+ }
34
+ else {
35
+ this.widget.append(child);
36
+ }
37
+ }
38
+ detachChild(child) {
39
+ this.unparentFromChild(child);
16
40
  }
17
41
  }
@@ -24,6 +24,9 @@ export class PackContainerNode extends Node {
24
24
  if (childWidget) {
25
25
  this.removeFromPack(childWidget);
26
26
  }
27
+ else {
28
+ child.detachFromParent(this);
29
+ }
27
30
  }
28
31
  }
29
32
  export class AdwHeaderBarNode extends PackContainerNode {
@@ -3,4 +3,8 @@ import { IndexedChildContainerNode } from "./indexed-child-container.js";
3
3
  export declare class ListBoxNode extends IndexedChildContainerNode<Gtk.ListBox> {
4
4
  static matches(type: string): boolean;
5
5
  protected getInsertionIndex(before: Gtk.Widget): number;
6
+ private unparentFromRow;
7
+ attachChild(child: Gtk.Widget): void;
8
+ insertChildBefore(child: Gtk.Widget, before: Gtk.Widget): void;
9
+ detachChild(child: Gtk.Widget): void;
6
10
  }
@@ -1,3 +1,4 @@
1
+ import { beginBatch, endBatch } from "@gtkx/ffi";
1
2
  import { isListBoxRow } from "../predicates.js";
2
3
  import { IndexedChildContainerNode } from "./indexed-child-container.js";
3
4
  export class ListBoxNode extends IndexedChildContainerNode {
@@ -5,9 +6,43 @@ export class ListBoxNode extends IndexedChildContainerNode {
5
6
  return type === "ListBox";
6
7
  }
7
8
  getInsertionIndex(before) {
8
- if (isListBoxRow(before)) {
9
- return before.getIndex();
9
+ const beforeParent = before.getParent();
10
+ if (beforeParent && isListBoxRow(beforeParent)) {
11
+ return beforeParent.getIndex();
10
12
  }
11
13
  return -1;
12
14
  }
15
+ unparentFromRow(child) {
16
+ const parent = child.getParent();
17
+ if (parent && isListBoxRow(parent)) {
18
+ beginBatch();
19
+ parent.setChild(null);
20
+ this.widget.remove(parent);
21
+ endBatch();
22
+ }
23
+ }
24
+ attachChild(child) {
25
+ this.unparentFromRow(child);
26
+ this.widget.append(child);
27
+ }
28
+ insertChildBefore(child, before) {
29
+ this.unparentFromRow(child);
30
+ const index = this.getInsertionIndex(before);
31
+ if (index >= 0) {
32
+ this.widget.insert(child, index);
33
+ }
34
+ else {
35
+ this.widget.append(child);
36
+ }
37
+ }
38
+ detachChild(child) {
39
+ if (isListBoxRow(child)) {
40
+ beginBatch();
41
+ child.setChild(null);
42
+ this.widget.remove(child);
43
+ endBatch();
44
+ return;
45
+ }
46
+ this.unparentFromRow(child);
47
+ }
13
48
  }
package/dist/render.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ApplicationFlags } from "@gtkx/ffi/gio";
1
+ import type * as Gio from "@gtkx/ffi/gio";
2
2
  import type { ReactNode } from "react";
3
3
  export declare const getContainer: () => unknown;
4
4
  /**
@@ -19,4 +19,4 @@ export declare const getContainer: () => unknown;
19
19
  * @param appId - The application ID (e.g., "com.example.myapp")
20
20
  * @param flags - Optional GIO application flags
21
21
  */
22
- export declare const render: (element: ReactNode, appId: string, flags?: ApplicationFlags) => void;
22
+ export declare const render: (element: ReactNode, appId: string, flags?: Gio.ApplicationFlags) => void;
package/dist/render.js CHANGED
@@ -4,15 +4,6 @@ import { ROOT_NODE_CONTAINER } from "./factory.js";
4
4
  import { reconciler } from "./reconciler.js";
5
5
  let container = null;
6
6
  export const getContainer = () => container;
7
- const APP_ID_PATTERN = /^[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)+$/;
8
- function validateAppId(appId) {
9
- if (!appId || typeof appId !== "string") {
10
- throw new Error("appId must be a non-empty string");
11
- }
12
- if (!APP_ID_PATTERN.test(appId)) {
13
- throw new Error(`Invalid appId "${appId}". App ID must be in reverse-DNS format (e.g., "com.example.myapp")`);
14
- }
15
- }
16
7
  /**
17
8
  * Renders a React element tree as a GTK application.
18
9
  * This is the main entry point for GTKX applications.
@@ -32,7 +23,6 @@ function validateAppId(appId) {
32
23
  * @param flags - Optional GIO application flags
33
24
  */
34
25
  export const render = (element, appId, flags) => {
35
- validateAppId(appId);
36
26
  start(appId, flags);
37
27
  const instance = reconciler.getInstance();
38
28
  container = instance.createContainer(ROOT_NODE_CONTAINER, 0, null, false, null, "", (error) => {
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SortType } from "@gtkx/ffi/gtk";
1
+ import type * as Gtk from "@gtkx/ffi/gtk";
2
2
  import type { ReactElement, ReactNode } from "react";
3
3
  /**
4
4
  * Props for slot components that accept children.
@@ -78,9 +78,9 @@ export type ColumnViewRootProps<C extends string = string> = {
78
78
  /** The ID of the currently sorted column, or null if unsorted. Controls the sort indicator UI. */
79
79
  sortColumn?: C | null;
80
80
  /** The current sort direction. Controls the sort indicator UI. */
81
- sortOrder?: SortType;
81
+ sortOrder?: Gtk.SortType;
82
82
  /** Callback fired when the user clicks a column header to change sort. */
83
- onSortChange?: (column: C | null, order: SortType) => void;
83
+ onSortChange?: (column: C | null, order: Gtk.SortType) => void;
84
84
  };
85
85
  export type NotebookPageProps = SlotProps & {
86
86
  label: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/react",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Build GTK4 desktop applications with React and TypeScript",
5
5
  "keywords": [
6
6
  "gtk",
@@ -35,11 +35,12 @@
35
35
  "dist"
36
36
  ],
37
37
  "dependencies": {
38
- "react-reconciler": "0.33.0",
39
- "@gtkx/ffi": "0.7.0"
38
+ "react-reconciler": "^0.33.0",
39
+ "@gtkx/ffi": "0.8.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@gtkx/gir": "0.7.0"
42
+ "@gtkx/gir": "0.8.0",
43
+ "@gtkx/native": "0.8.0"
43
44
  },
44
45
  "peerDependencies": {
45
46
  "react": "^19"