@gtkx/native 0.1.27 → 0.1.29

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/README.md ADDED
@@ -0,0 +1,209 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/eugeniodepalo/gtkx/HEAD/logo.svg" alt="GTKX Logo" width="128" height="128">
3
+ </p>
4
+
5
+ <h1 align="center">GTKX</h1>
6
+
7
+ <p align="center">
8
+ <strong>Build native GTK4 desktop applications with React and TypeScript</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://eugeniodepalo.github.io/gtkx">Documentation</a> ·
13
+ <a href="#quick-start">Quick Start</a> ·
14
+ <a href="#examples">Examples</a>
15
+ </p>
16
+
17
+ ---
18
+
19
+ GTKX bridges React's component model with GTK4's native widget system. Write familiar React code and render it as native Linux desktop applications with full access to GTK4 widgets, signals, and styling.
20
+
21
+ ## Features
22
+
23
+ - **React Components** — Use React hooks, state, and component patterns you already know
24
+ - **Type-Safe** — Full TypeScript support with auto-generated types from GTK4 introspection data
25
+ - **Native Performance** — Direct FFI bindings to GTK4 via Rust and libffi
26
+ - **CSS-in-JS Styling** — Emotion-style `css` template literals for GTK widgets
27
+ - **Testing Library** — Familiar `screen`, `userEvent`, and query APIs for testing components
28
+
29
+ ## Quick Start
30
+
31
+ ```bash
32
+ # Install dependencies
33
+ pnpm add @gtkx/react @gtkx/ffi react
34
+
35
+ # For TypeScript (recommended)
36
+ pnpm add -D @types/react tsx typescript
37
+
38
+ # For styling (optional)
39
+ pnpm add @gtkx/css
40
+
41
+ # For testing (optional)
42
+ pnpm add -D @gtkx/testing
43
+ ```
44
+
45
+ Create your first app:
46
+
47
+ ```tsx
48
+ // index.tsx
49
+ import { render } from "@gtkx/react";
50
+ import { App } from "./app.js";
51
+
52
+ render(<App />, "org.example.MyApp");
53
+ ```
54
+
55
+ ```tsx
56
+ // app.tsx
57
+ import { ApplicationWindow, Box, Button, Label, quit } from "@gtkx/react";
58
+ import { Orientation } from "@gtkx/ffi/gtk";
59
+ import { useState } from "react";
60
+
61
+ export const App = () => {
62
+ const [count, setCount] = useState(0);
63
+
64
+ return (
65
+ <ApplicationWindow
66
+ title="My App"
67
+ defaultWidth={400}
68
+ defaultHeight={300}
69
+ onCloseRequest={quit}
70
+ >
71
+ <Box orientation={Orientation.VERTICAL} spacing={12} margin={20}>
72
+ <Label.Root label={`Count: ${count}`} />
73
+ <Button
74
+ label="Increment"
75
+ onClicked={() => setCount((c) => c + 1)}
76
+ />
77
+ </Box>
78
+ </ApplicationWindow>
79
+ );
80
+ };
81
+ ```
82
+
83
+ Run with:
84
+
85
+ ```bash
86
+ pnpm tsx index.tsx
87
+ ```
88
+
89
+ ## Styling
90
+
91
+ Use `@gtkx/css` for CSS-in-JS styling:
92
+
93
+ ```tsx
94
+ import { css } from "@gtkx/css";
95
+ import { Button } from "@gtkx/react";
96
+
97
+ const primaryButton = css`
98
+ padding: 16px 32px;
99
+ border-radius: 24px;
100
+ background: linear-gradient(135deg, #3584e4, #9141ac);
101
+ color: white;
102
+ font-weight: bold;
103
+ `;
104
+
105
+ const MyButton = () => (
106
+ <Button label="Click me" cssClasses={[primaryButton]} />
107
+ );
108
+ ```
109
+
110
+ GTK also provides built-in CSS classes like `suggested-action`, `destructive-action`, `card`, and `heading`.
111
+
112
+ ## Testing
113
+
114
+ Use `@gtkx/testing` for Testing Library-style component tests:
115
+
116
+ ```tsx
117
+ import { cleanup, render, screen, userEvent, fireEvent } from "@gtkx/testing";
118
+ import { AccessibleRole } from "@gtkx/ffi/gtk";
119
+ import { App } from "./app.js";
120
+
121
+ // Clean up after each test
122
+ afterEach(() => cleanup());
123
+
124
+ test("increments count when clicking button", async () => {
125
+ render(<App />);
126
+
127
+ const button = await screen.findByRole(AccessibleRole.BUTTON, {
128
+ name: "Increment",
129
+ });
130
+ await userEvent.click(button);
131
+
132
+ await screen.findByText("Count: 1");
133
+ });
134
+
135
+ test("can also use fireEvent for synchronous events", async () => {
136
+ render(<App />);
137
+
138
+ const button = await screen.findByRole(AccessibleRole.BUTTON, {
139
+ name: "Increment",
140
+ });
141
+ fireEvent.click(button);
142
+
143
+ await screen.findByText("Count: 1");
144
+ });
145
+ ```
146
+
147
+ ### Available APIs
148
+
149
+ **Queries** - Find elements in the rendered tree:
150
+ - `getBy*` / `getAllBy*` - Throws if not found
151
+ - `queryBy*` / `queryAllBy*` - Returns null/empty array if not found
152
+ - `findBy*` / `findAllBy*` - Async, waits for element
153
+
154
+ Query types: `ByRole`, `ByText`, `ByLabelText`, `ByTestId`
155
+
156
+ **User Interactions**:
157
+ - `userEvent.click(element)` - Simulate click
158
+ - `userEvent.dblClick(element)` - Simulate double click
159
+ - `userEvent.type(element, text)` - Type text into input
160
+ - `userEvent.clear(element)` - Clear input text
161
+ - `userEvent.setup()` - Create reusable instance
162
+
163
+ **Low-level Events**:
164
+ - `fireEvent(element, signalName)` - Emit any GTK signal
165
+ - `fireEvent.click(element)` - Emit clicked signal
166
+ - `fireEvent.activate(element)` - Emit activate signal
167
+
168
+ **Utilities**:
169
+ - `waitFor(callback)` - Wait for condition
170
+ - `waitForElementToBeRemoved(element)` - Wait for element removal
171
+
172
+ ## Examples
173
+
174
+ ### Counter
175
+
176
+ A minimal counter app demonstrating state management:
177
+
178
+ ```bash
179
+ turbo start --filter=counter-example
180
+ ```
181
+
182
+ ### GTK4 Demo
183
+
184
+ A comprehensive showcase of GTK4 widgets and features:
185
+
186
+ ```bash
187
+ turbo start --filter=gtk4-demo
188
+ ```
189
+
190
+ ## Packages
191
+
192
+ | Package | Description |
193
+ |---------|-------------|
194
+ | [@gtkx/react](packages/react) | React reconciler and JSX components |
195
+ | [@gtkx/ffi](packages/ffi) | TypeScript FFI bindings for GTK4 |
196
+ | [@gtkx/native](packages/native) | Rust native module for FFI bridge |
197
+ | [@gtkx/css](packages/css) | CSS-in-JS styling for GTK widgets |
198
+ | [@gtkx/testing](packages/testing) | Testing utilities for GTKX components |
199
+ | [@gtkx/gir](packages/gir) | GObject Introspection parser for codegen |
200
+
201
+ ## Requirements
202
+
203
+ - Node.js 20+
204
+ - GTK4 development libraries
205
+ - Linux (GTK4 is Linux-native)
206
+
207
+ ## License
208
+
209
+ [MPL-2.0](LICENSE)
package/dist/index.node CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/native",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "Rust-based native module providing FFI bindings for GTKX",
5
5
  "keywords": [
6
6
  "gtk",