@gtkx/react 0.7.0 → 0.9.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.
- package/dist/{container-interfaces.d.ts → containers.d.ts} +10 -37
- package/dist/containers.js +1 -0
- package/dist/factory.d.ts +1 -1
- package/dist/factory.js +3 -3
- package/dist/{reconciler/host-config.d.ts → host-config.d.ts} +2 -2
- package/dist/{reconciler/host-config.js → host-config.js} +2 -2
- package/dist/node.d.ts +5 -6
- package/dist/node.js +54 -72
- package/dist/nodes/about-dialog.d.ts +2 -3
- package/dist/nodes/about-dialog.js +6 -4
- package/dist/nodes/column-view.d.ts +6 -7
- package/dist/nodes/column-view.js +29 -32
- package/dist/nodes/flow-box.d.ts +4 -1
- package/dist/nodes/flow-box.js +26 -2
- package/dist/nodes/grid.d.ts +4 -1
- package/dist/nodes/grid.js +39 -1
- package/dist/nodes/header-bar.d.ts +15 -14
- package/dist/nodes/header-bar.js +79 -36
- package/dist/nodes/indexed-child-container.d.ts +1 -1
- package/dist/nodes/list-box.d.ts +4 -0
- package/dist/nodes/list-box.js +37 -2
- package/dist/nodes/list-view.d.ts +1 -2
- package/dist/nodes/list-view.js +2 -2
- package/dist/nodes/menu.d.ts +27 -11
- package/dist/nodes/menu.js +59 -32
- package/dist/nodes/notebook.d.ts +4 -1
- package/dist/nodes/notebook.js +45 -1
- package/dist/nodes/overlay.d.ts +1 -1
- package/dist/nodes/paged-stack.d.ts +7 -3
- package/dist/nodes/paged-stack.js +47 -2
- package/dist/nodes/root.d.ts +1 -1
- package/dist/nodes/root.js +2 -2
- package/dist/nodes/selectable-list.d.ts +7 -3
- package/dist/nodes/selectable-list.js +34 -2
- package/dist/nodes/slot.d.ts +3 -4
- package/dist/nodes/slot.js +11 -10
- package/dist/nodes/stack-page-props.d.ts +1 -1
- package/dist/nodes/stack.d.ts +1 -1
- package/dist/nodes/stack.js +1 -1
- package/dist/nodes/string-list-container.d.ts +4 -11
- package/dist/nodes/string-list-container.js +32 -4
- package/dist/nodes/string-list-item.d.ts +10 -6
- package/dist/nodes/string-list-item.js +19 -17
- package/dist/nodes/toggle-button.d.ts +0 -3
- package/dist/nodes/toggle-button.js +0 -28
- package/dist/nodes/toolbar-view.d.ts +2 -3
- package/dist/nodes/toolbar-view.js +10 -9
- package/dist/nodes/view-stack.d.ts +1 -1
- package/dist/nodes/virtual-item.d.ts +9 -5
- package/dist/nodes/virtual-item.js +16 -20
- package/dist/nodes/virtual-slot.d.ts +4 -4
- package/dist/nodes/virtual-slot.js +12 -26
- package/dist/nodes/window.d.ts +2 -1
- package/dist/nodes/window.js +7 -3
- package/dist/predicates.d.ts +9 -18
- package/dist/predicates.js +31 -18
- package/dist/reconciler.d.ts +1 -1
- package/dist/reconciler.js +1 -1
- package/dist/render.d.ts +2 -2
- package/dist/render.js +0 -10
- package/dist/types.d.ts +3 -3
- package/package.json +5 -4
- package/dist/container-interfaces.js +0 -26
|
@@ -16,10 +16,10 @@ export declare abstract class VirtualSlotNode<TContainer, TProps> extends Node<n
|
|
|
16
16
|
protected abstract extractSlotProps(props: Props): TProps;
|
|
17
17
|
initialize(props: Props): void;
|
|
18
18
|
getChildWidget(): Gtk.Widget | null;
|
|
19
|
+
getSlotProps(): TProps;
|
|
20
|
+
setParentContainer(container: Node & TContainer): void;
|
|
21
|
+
getBeforeWidget(before: Node): Gtk.Widget | null;
|
|
19
22
|
appendChild(child: Node): void;
|
|
20
|
-
|
|
21
|
-
attachToParentBefore(parent: Node, before: Node): void;
|
|
22
|
-
protected getBeforeWidget(before: Node): Gtk.Widget | null;
|
|
23
|
-
detachFromParent(parent: Node): void;
|
|
23
|
+
unmount(): void;
|
|
24
24
|
protected updateSlotPropsIfChanged(oldProps: Props, newProps: Props, propKeys: string[]): boolean;
|
|
25
25
|
}
|
|
@@ -22,29 +22,11 @@ export class VirtualSlotNode extends Node {
|
|
|
22
22
|
getChildWidget() {
|
|
23
23
|
return this.childWidget;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (childWidget) {
|
|
28
|
-
this.childWidget = childWidget;
|
|
29
|
-
}
|
|
25
|
+
getSlotProps() {
|
|
26
|
+
return this.slotProps;
|
|
30
27
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.parentContainer = parent;
|
|
34
|
-
this.addToContainer(parent, this.childWidget, this.slotProps);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
attachToParentBefore(parent, before) {
|
|
38
|
-
if (this.isValidContainer(parent) && this.childWidget) {
|
|
39
|
-
this.parentContainer = parent;
|
|
40
|
-
const beforeWidget = this.getBeforeWidget(before);
|
|
41
|
-
if (beforeWidget) {
|
|
42
|
-
this.insertBeforeInContainer(parent, this.childWidget, this.slotProps, beforeWidget);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.addToContainer(parent, this.childWidget, this.slotProps);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
28
|
+
setParentContainer(container) {
|
|
29
|
+
this.parentContainer = container;
|
|
48
30
|
}
|
|
49
31
|
getBeforeWidget(before) {
|
|
50
32
|
if (before instanceof VirtualSlotNode) {
|
|
@@ -52,12 +34,16 @@ export class VirtualSlotNode extends Node {
|
|
|
52
34
|
}
|
|
53
35
|
return before.getWidget() ?? null;
|
|
54
36
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
37
|
+
appendChild(child) {
|
|
38
|
+
const childWidget = child.getWidget();
|
|
39
|
+
if (childWidget) {
|
|
40
|
+
this.childWidget = childWidget;
|
|
59
41
|
}
|
|
60
42
|
}
|
|
43
|
+
unmount() {
|
|
44
|
+
this.parentContainer = null;
|
|
45
|
+
super.unmount();
|
|
46
|
+
}
|
|
61
47
|
updateSlotPropsIfChanged(oldProps, newProps, propKeys) {
|
|
62
48
|
const changed = propKeys.some((key) => oldProps[key] !== newProps[key]);
|
|
63
49
|
if (changed) {
|
package/dist/nodes/window.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ import { Node } from "../node.js";
|
|
|
4
4
|
export declare class WindowNode extends Node<Gtk.Window> {
|
|
5
5
|
static consumedPropNames: string[];
|
|
6
6
|
static matches(type: string): boolean;
|
|
7
|
+
protected isStandalone(): boolean;
|
|
7
8
|
protected createWidget(type: string, _props: Props): Gtk.Window;
|
|
8
|
-
detachFromParent(_parent: Node): void;
|
|
9
9
|
mount(): void;
|
|
10
|
+
unmount(): void;
|
|
10
11
|
updateProps(oldProps: Props, newProps: Props): void;
|
|
11
12
|
}
|
package/dist/nodes/window.js
CHANGED
|
@@ -8,6 +8,9 @@ export class WindowNode extends Node {
|
|
|
8
8
|
static matches(type) {
|
|
9
9
|
return WINDOW_TYPES.has(normalizeWidgetType(type));
|
|
10
10
|
}
|
|
11
|
+
isStandalone() {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
11
14
|
createWidget(type, _props) {
|
|
12
15
|
const widgetType = normalizeWidgetType(type);
|
|
13
16
|
if (widgetType === "ApplicationWindow") {
|
|
@@ -21,12 +24,13 @@ export class WindowNode extends Node {
|
|
|
21
24
|
}
|
|
22
25
|
return new Gtk.Window();
|
|
23
26
|
}
|
|
24
|
-
detachFromParent(_parent) {
|
|
25
|
-
this.widget.destroy();
|
|
26
|
-
}
|
|
27
27
|
mount() {
|
|
28
28
|
this.widget.present();
|
|
29
29
|
}
|
|
30
|
+
unmount() {
|
|
31
|
+
this.widget.destroy();
|
|
32
|
+
super.unmount();
|
|
33
|
+
}
|
|
30
34
|
updateProps(oldProps, newProps) {
|
|
31
35
|
const widthChanged = oldProps.defaultWidth !== newProps.defaultWidth;
|
|
32
36
|
const heightChanged = oldProps.defaultHeight !== newProps.defaultHeight;
|
package/dist/predicates.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
+
import type { ChildContainer, GridContainer, ItemContainer, PackContainer, PageContainer, StackPageContainer, StringListContainer } from "./containers.js";
|
|
3
|
+
import type { Node } from "./node.js";
|
|
2
4
|
interface Appendable extends Gtk.Widget {
|
|
3
5
|
append(child: unknown): void;
|
|
4
6
|
}
|
|
@@ -11,28 +13,17 @@ interface SingleChild extends Gtk.Widget {
|
|
|
11
13
|
interface Removable extends Gtk.Widget {
|
|
12
14
|
remove(child: unknown): void;
|
|
13
15
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Type guard that checks if a GTK widget supports appending children via an append method.
|
|
16
|
-
*/
|
|
17
16
|
export declare const isAppendable: (widget: Gtk.Widget) => widget is Appendable;
|
|
18
|
-
/**
|
|
19
|
-
* Type guard that checks if a GTK widget supports adding children via an add method.
|
|
20
|
-
*/
|
|
21
17
|
export declare const isAddable: (widget: Gtk.Widget) => widget is Addable;
|
|
22
|
-
/**
|
|
23
|
-
* Type guard that checks if a GTK widget supports a single child via setChild method.
|
|
24
|
-
*/
|
|
25
18
|
export declare const isSingleChild: (widget: Gtk.Widget) => widget is SingleChild;
|
|
26
|
-
/**
|
|
27
|
-
* Type guard that checks if a GTK widget supports removing children via a remove method.
|
|
28
|
-
*/
|
|
29
19
|
export declare const isRemovable: (widget: Gtk.Widget) => widget is Removable;
|
|
30
|
-
/**
|
|
31
|
-
* Type guard that checks if a GTK widget is a FlowBoxChild.
|
|
32
|
-
*/
|
|
33
20
|
export declare const isFlowBoxChild: (widget: Gtk.Widget) => widget is Gtk.FlowBoxChild;
|
|
34
|
-
/**
|
|
35
|
-
* Type guard that checks if a GTK widget is a ListBoxRow.
|
|
36
|
-
*/
|
|
37
21
|
export declare const isListBoxRow: (widget: Gtk.Widget) => widget is Gtk.ListBoxRow;
|
|
22
|
+
export declare const isChildContainer: (node: Node) => node is Node & ChildContainer;
|
|
23
|
+
export declare const isPageContainer: (node: Node) => node is Node & PageContainer;
|
|
24
|
+
export declare const isStackPageContainer: (node: Node) => node is Node & StackPageContainer;
|
|
25
|
+
export declare const isGridContainer: (node: Node) => node is Node & GridContainer;
|
|
26
|
+
export declare const isItemContainer: (node: Node) => node is Node & ItemContainer<unknown>;
|
|
27
|
+
export declare const isPackContainer: (node: Node) => node is Node & PackContainer;
|
|
28
|
+
export declare const isStringListContainer: (node: Node) => node is Node & StringListContainer;
|
|
38
29
|
export {};
|
package/dist/predicates.js
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard that checks if a GTK widget supports appending children via an append method.
|
|
3
|
-
*/
|
|
4
1
|
export const isAppendable = (widget) => "append" in widget && typeof widget.append === "function";
|
|
5
|
-
/**
|
|
6
|
-
* Type guard that checks if a GTK widget supports adding children via an add method.
|
|
7
|
-
*/
|
|
8
2
|
export const isAddable = (widget) => "add" in widget && typeof widget.add === "function";
|
|
9
|
-
/**
|
|
10
|
-
* Type guard that checks if a GTK widget supports a single child via setChild method.
|
|
11
|
-
*/
|
|
12
3
|
export const isSingleChild = (widget) => "setChild" in widget && typeof widget.setChild === "function";
|
|
13
|
-
/**
|
|
14
|
-
* Type guard that checks if a GTK widget supports removing children via a remove method.
|
|
15
|
-
*/
|
|
16
4
|
export const isRemovable = (widget) => "remove" in widget && typeof widget.remove === "function";
|
|
17
|
-
/**
|
|
18
|
-
* Type guard that checks if a GTK widget is a FlowBoxChild.
|
|
19
|
-
*/
|
|
20
5
|
export const isFlowBoxChild = (widget) => "getIndex" in widget && "getChild" in widget && typeof widget.getIndex === "function";
|
|
21
|
-
/**
|
|
22
|
-
* Type guard that checks if a GTK widget is a ListBoxRow.
|
|
23
|
-
*/
|
|
24
6
|
export const isListBoxRow = (widget) => "getIndex" in widget && "isSelected" in widget && typeof widget.getIndex === "function";
|
|
7
|
+
const createContainerGuard = (requiredMethods) => (node) => requiredMethods.every((method) => method in node);
|
|
8
|
+
export const isChildContainer = createContainerGuard([
|
|
9
|
+
"attachChild",
|
|
10
|
+
"detachChild",
|
|
11
|
+
"insertChildBefore",
|
|
12
|
+
]);
|
|
13
|
+
export const isPageContainer = createContainerGuard([
|
|
14
|
+
"addPage",
|
|
15
|
+
"removePage",
|
|
16
|
+
"insertPageBefore",
|
|
17
|
+
"updatePageLabel",
|
|
18
|
+
]);
|
|
19
|
+
export const isStackPageContainer = createContainerGuard([
|
|
20
|
+
"addStackPage",
|
|
21
|
+
"removeStackPage",
|
|
22
|
+
"updateStackPageProps",
|
|
23
|
+
]);
|
|
24
|
+
export const isGridContainer = createContainerGuard(["attachToGrid", "removeFromGrid"]);
|
|
25
|
+
export const isItemContainer = createContainerGuard([
|
|
26
|
+
"addItem",
|
|
27
|
+
"insertItemBefore",
|
|
28
|
+
"removeItem",
|
|
29
|
+
"updateItem",
|
|
30
|
+
]);
|
|
31
|
+
export const isPackContainer = createContainerGuard(["packStart", "packEnd", "removeFromPack"]);
|
|
32
|
+
export const isStringListContainer = createContainerGuard([
|
|
33
|
+
"addStringListItem",
|
|
34
|
+
"insertStringListItemBefore",
|
|
35
|
+
"removeStringListItem",
|
|
36
|
+
"updateStringListItem",
|
|
37
|
+
]);
|
package/dist/reconciler.d.ts
CHANGED
package/dist/reconciler.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ReactReconciler from "react-reconciler";
|
|
2
2
|
import packageJson from "../package.json" with { type: "json" };
|
|
3
3
|
import { createNode } from "./factory.js";
|
|
4
|
-
import { createHostConfig } from "./
|
|
4
|
+
import { createHostConfig } from "./host-config.js";
|
|
5
5
|
class Reconciler {
|
|
6
6
|
instance;
|
|
7
7
|
constructor() {
|
package/dist/render.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.9.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.
|
|
38
|
+
"react-reconciler": "^0.33.0",
|
|
39
|
+
"@gtkx/ffi": "0.9.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@gtkx/
|
|
42
|
+
"@gtkx/native": "0.9.0",
|
|
43
|
+
"@gtkx/gir": "0.9.0"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
46
|
"react": "^19"
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const createContainerGuard = (requiredMethods) => (node) => requiredMethods.every((method) => method in node);
|
|
2
|
-
export const isChildContainer = createContainerGuard([
|
|
3
|
-
"attachChild",
|
|
4
|
-
"detachChild",
|
|
5
|
-
"insertChildBefore",
|
|
6
|
-
]);
|
|
7
|
-
export const isPageContainer = createContainerGuard([
|
|
8
|
-
"addPage",
|
|
9
|
-
"removePage",
|
|
10
|
-
"insertPageBefore",
|
|
11
|
-
"updatePageLabel",
|
|
12
|
-
]);
|
|
13
|
-
export const isStackPageContainer = createContainerGuard([
|
|
14
|
-
"addStackPage",
|
|
15
|
-
"removeStackPage",
|
|
16
|
-
"updateStackPageProps",
|
|
17
|
-
]);
|
|
18
|
-
export const isGridContainer = createContainerGuard(["attachToGrid", "removeFromGrid"]);
|
|
19
|
-
export const isItemContainer = createContainerGuard([
|
|
20
|
-
"addItem",
|
|
21
|
-
"insertItemBefore",
|
|
22
|
-
"removeItem",
|
|
23
|
-
"updateItem",
|
|
24
|
-
]);
|
|
25
|
-
export const isColumnContainer = createContainerGuard(["addColumn", "removeColumn", "getItems"]);
|
|
26
|
-
export const isPackContainer = createContainerGuard(["packStart", "packEnd", "removeFromPack"]);
|