@gtkx/react 0.2.6 → 0.3.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/README.md +18 -16
- package/dist/nodes/column-view.js +10 -10
- package/dist/nodes/list.js +7 -7
- package/dist/nodes/slot.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -64,20 +64,12 @@ npm install -D @types/react typescript
|
|
|
64
64
|
Create your first app:
|
|
65
65
|
|
|
66
66
|
```tsx
|
|
67
|
-
//
|
|
68
|
-
import { render } from "@gtkx/react";
|
|
69
|
-
import { App } from "./app.js";
|
|
70
|
-
|
|
71
|
-
render(<App />, "org.example.MyApp");
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
```tsx
|
|
75
|
-
// app.tsx
|
|
76
|
-
import { ApplicationWindow, Box, Button, Label, quit } from "@gtkx/react";
|
|
77
|
-
import { Orientation } from "@gtkx/ffi/gtk";
|
|
67
|
+
// src/app.tsx
|
|
78
68
|
import { useState } from "react";
|
|
69
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
70
|
+
import { ApplicationWindow, Box, Button, Label, quit } from "@gtkx/react";
|
|
79
71
|
|
|
80
|
-
export
|
|
72
|
+
export default function App() {
|
|
81
73
|
const [count, setCount] = useState(0);
|
|
82
74
|
|
|
83
75
|
return (
|
|
@@ -88,7 +80,7 @@ export const App = () => {
|
|
|
88
80
|
onCloseRequest={quit}
|
|
89
81
|
>
|
|
90
82
|
<Box
|
|
91
|
-
orientation={Orientation.VERTICAL}
|
|
83
|
+
orientation={Gtk.Orientation.VERTICAL}
|
|
92
84
|
spacing={12}
|
|
93
85
|
marginStart={20}
|
|
94
86
|
marginEnd={20}
|
|
@@ -100,7 +92,17 @@ export const App = () => {
|
|
|
100
92
|
</Box>
|
|
101
93
|
</ApplicationWindow>
|
|
102
94
|
);
|
|
103
|
-
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const appId = "org.example.MyApp";
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
// src/index.tsx
|
|
102
|
+
import { render } from "@gtkx/react";
|
|
103
|
+
import App, { appId } from "./app.js";
|
|
104
|
+
|
|
105
|
+
render(<App />, appId);
|
|
104
106
|
```
|
|
105
107
|
|
|
106
108
|
Run with HMR:
|
|
@@ -109,10 +111,10 @@ Run with HMR:
|
|
|
109
111
|
npx gtkx dev src/app.tsx
|
|
110
112
|
```
|
|
111
113
|
|
|
112
|
-
Or without HMR:
|
|
114
|
+
Or without HMR (production):
|
|
113
115
|
|
|
114
116
|
```bash
|
|
115
|
-
npx
|
|
117
|
+
npx tsc -b && node dist/index.js
|
|
116
118
|
```
|
|
117
119
|
|
|
118
120
|
## Styling
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getObject,
|
|
1
|
+
import { getObject, getObjectAddr } from "@gtkx/ffi";
|
|
2
2
|
import * as GObject from "@gtkx/ffi/gobject";
|
|
3
3
|
import * as Gtk from "@gtkx/ffi/gtk";
|
|
4
4
|
import { scheduleFlush } from "../batch.js";
|
|
@@ -71,7 +71,7 @@ export class ColumnViewNode extends Node {
|
|
|
71
71
|
const baseSorter = this.widget.getSorter();
|
|
72
72
|
if (!baseSorter)
|
|
73
73
|
return;
|
|
74
|
-
const sorter = getObject(baseSorter.
|
|
74
|
+
const sorter = getObject(baseSorter.id);
|
|
75
75
|
const column = sorter.getPrimarySortColumn();
|
|
76
76
|
const order = sorter.getPrimarySortOrder();
|
|
77
77
|
const columnId = column?.getId() ?? null;
|
|
@@ -244,8 +244,8 @@ export class ColumnViewColumnNode extends Node {
|
|
|
244
244
|
column.setFixedWidth(props.fixedWidth);
|
|
245
245
|
}
|
|
246
246
|
factory.connect("setup", (_self, listItemObj) => {
|
|
247
|
-
const listItem = getObject(listItemObj.
|
|
248
|
-
const id =
|
|
247
|
+
const listItem = getObject(listItemObj.id);
|
|
248
|
+
const id = getObjectAddr(listItemObj.id);
|
|
249
249
|
const box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
|
|
250
250
|
listItem.setChild(box);
|
|
251
251
|
const fiberRoot = createFiberRoot(box);
|
|
@@ -254,8 +254,8 @@ export class ColumnViewColumnNode extends Node {
|
|
|
254
254
|
reconciler.getInstance().updateContainer(element, fiberRoot, null, () => { });
|
|
255
255
|
});
|
|
256
256
|
factory.connect("bind", (_self, listItemObj) => {
|
|
257
|
-
const listItem = getObject(listItemObj.
|
|
258
|
-
const id =
|
|
257
|
+
const listItem = getObject(listItemObj.id);
|
|
258
|
+
const id = getObjectAddr(listItemObj.id);
|
|
259
259
|
const info = this.state.listItemCache.get(id);
|
|
260
260
|
if (!info)
|
|
261
261
|
return;
|
|
@@ -268,14 +268,14 @@ export class ColumnViewColumnNode extends Node {
|
|
|
268
268
|
}
|
|
269
269
|
});
|
|
270
270
|
factory.connect("unbind", (_self, listItemObj) => {
|
|
271
|
-
const id =
|
|
271
|
+
const id = getObjectAddr(listItemObj.id);
|
|
272
272
|
const info = this.state.listItemCache.get(id);
|
|
273
273
|
if (!info)
|
|
274
274
|
return;
|
|
275
275
|
reconciler.getInstance().updateContainer(null, info.fiberRoot, null, () => { });
|
|
276
276
|
});
|
|
277
277
|
factory.connect("teardown", (_self, listItemObj) => {
|
|
278
|
-
const id =
|
|
278
|
+
const id = getObjectAddr(listItemObj.id);
|
|
279
279
|
const info = this.state.listItemCache.get(id);
|
|
280
280
|
if (info) {
|
|
281
281
|
reconciler.getInstance().updateContainer(null, info.fiberRoot, null, () => { });
|
|
@@ -309,8 +309,8 @@ export class ColumnViewColumnNode extends Node {
|
|
|
309
309
|
const columnView = this.columnView;
|
|
310
310
|
const wrappedSortFn = (stringObjPtrA, stringObjPtrB) => {
|
|
311
311
|
const items = columnView.getItems();
|
|
312
|
-
const stringObjA = getObject(stringObjPtrA
|
|
313
|
-
const stringObjB = getObject(stringObjPtrB
|
|
312
|
+
const stringObjA = getObject(stringObjPtrA);
|
|
313
|
+
const stringObjB = getObject(stringObjPtrB);
|
|
314
314
|
const indexA = Number.parseInt(stringObjA.getString(), 10);
|
|
315
315
|
const indexB = Number.parseInt(stringObjB.getString(), 10);
|
|
316
316
|
if (Number.isNaN(indexA) || Number.isNaN(indexB))
|
package/dist/nodes/list.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getObject,
|
|
1
|
+
import { getObject, getObjectAddr } from "@gtkx/ffi";
|
|
2
2
|
import * as Gtk from "@gtkx/ffi/gtk";
|
|
3
3
|
import { scheduleFlush } from "../batch.js";
|
|
4
4
|
import { isItemContainer } from "../container-interfaces.js";
|
|
@@ -28,8 +28,8 @@ export class ListViewNode extends Node {
|
|
|
28
28
|
this.state.selectionModel = selectionModel;
|
|
29
29
|
this.state.factory = factory;
|
|
30
30
|
factory.connect("setup", (_self, listItemObj) => {
|
|
31
|
-
const listItem = getObject(listItemObj.
|
|
32
|
-
const id =
|
|
31
|
+
const listItem = getObject(listItemObj.id);
|
|
32
|
+
const id = getObjectAddr(listItemObj.id);
|
|
33
33
|
const box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
|
|
34
34
|
listItem.setChild(box);
|
|
35
35
|
const fiberRoot = createFiberRoot(box);
|
|
@@ -38,8 +38,8 @@ export class ListViewNode extends Node {
|
|
|
38
38
|
reconciler.getInstance().updateContainer(element, fiberRoot, null, () => { });
|
|
39
39
|
});
|
|
40
40
|
factory.connect("bind", (_self, listItemObj) => {
|
|
41
|
-
const listItem = getObject(listItemObj.
|
|
42
|
-
const id =
|
|
41
|
+
const listItem = getObject(listItemObj.id);
|
|
42
|
+
const id = getObjectAddr(listItemObj.id);
|
|
43
43
|
const info = this.state.listItemCache.get(id);
|
|
44
44
|
if (!info)
|
|
45
45
|
return;
|
|
@@ -49,14 +49,14 @@ export class ListViewNode extends Node {
|
|
|
49
49
|
reconciler.getInstance().updateContainer(element, info.fiberRoot, null, () => { });
|
|
50
50
|
});
|
|
51
51
|
factory.connect("unbind", (_self, listItemObj) => {
|
|
52
|
-
const id =
|
|
52
|
+
const id = getObjectAddr(listItemObj.id);
|
|
53
53
|
const info = this.state.listItemCache.get(id);
|
|
54
54
|
if (!info)
|
|
55
55
|
return;
|
|
56
56
|
reconciler.getInstance().updateContainer(null, info.fiberRoot, null, () => { });
|
|
57
57
|
});
|
|
58
58
|
factory.connect("teardown", (_self, listItemObj) => {
|
|
59
|
-
const id =
|
|
59
|
+
const id = getObjectAddr(listItemObj.id);
|
|
60
60
|
const info = this.state.listItemCache.get(id);
|
|
61
61
|
if (info) {
|
|
62
62
|
reconciler.getInstance().updateContainer(null, info.fiberRoot, null, () => { });
|
package/dist/nodes/slot.js
CHANGED
|
@@ -33,7 +33,7 @@ export class SlotNode extends Node {
|
|
|
33
33
|
const setterName = `set${this.slotName}`;
|
|
34
34
|
const setter = parentWidget[setterName];
|
|
35
35
|
if (typeof setter === "function") {
|
|
36
|
-
setter.call(parentWidget, childWidget?.
|
|
36
|
+
setter.call(parentWidget, childWidget?.id ?? null);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
appendChild(child) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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.
|
|
39
|
+
"@gtkx/ffi": "0.3.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@gtkx/gir": "0.
|
|
42
|
+
"@gtkx/gir": "0.3.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": "^19"
|