@peachy/react 0.0.9 → 0.0.10
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/extra.mjs +37 -0
- package/dist/global.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/jsx-runtime.d.mts +2 -2
- package/dist/types.d.mts +5 -3
- package/dist/utilities/children.mjs +4 -24
- package/dist/utilities/diff.mjs +28 -29
- package/package.json +8 -8
- package/tsconfig.json +2 -0
package/dist/extra.mjs
CHANGED
|
@@ -58,6 +58,43 @@ const extraMap = new Map([
|
|
|
58
58
|
restoreState(instance, state) {
|
|
59
59
|
instance.set_position(state.cursorPosition);
|
|
60
60
|
}
|
|
61
|
+
}],
|
|
62
|
+
[Gtk.Widget.$gtype, {
|
|
63
|
+
appendChild(parentInstance, child) {
|
|
64
|
+
if (child instanceof Gtk.EventController) {
|
|
65
|
+
parentInstance.add_controller(child);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if ("child" in parentInstance) {
|
|
69
|
+
parentInstance.child = child;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if ("content" in parentInstance) {
|
|
73
|
+
parentInstance.content = child;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (child instanceof Gtk.Widget) child.set_parent(parentInstance);
|
|
77
|
+
console.warn(`Don't know how to append child to ${parentInstance.constructor.name}, please provide an implementation for it in the extraMap`);
|
|
78
|
+
},
|
|
79
|
+
removeChild(parentInstance, child) {
|
|
80
|
+
if (child instanceof Gtk.EventController) {
|
|
81
|
+
parentInstance.remove_controller(child);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if ("child" in parentInstance) {
|
|
85
|
+
parentInstance.child = null;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if ("content" in parentInstance) {
|
|
89
|
+
parentInstance.content = null;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (child instanceof Gtk.Widget) {
|
|
93
|
+
child.unparent();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
console.warn(`Don't know how to remove child from ${parentInstance.constructor.name}, please provide an implementation for it in the extraMap`);
|
|
97
|
+
}
|
|
61
98
|
}]
|
|
62
99
|
]);
|
|
63
100
|
|
package/dist/global.d.mts
CHANGED
|
@@ -21,8 +21,8 @@ declare module "gi://Gtk?version=4.0" {
|
|
|
21
21
|
namespace Widget {
|
|
22
22
|
interface ConstructorProps {
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
* React children
|
|
25
|
+
*/
|
|
26
26
|
children: any;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -33,8 +33,8 @@ declare module "gi://Gtk?version=3.0" {
|
|
|
33
33
|
namespace Widget {
|
|
34
34
|
interface ConstructorProps {
|
|
35
35
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
* React children
|
|
37
|
+
*/
|
|
38
38
|
children: any;
|
|
39
39
|
}
|
|
40
40
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import Reconciler from "react-reconciler";
|
|
|
6
6
|
//#region src/index.ts
|
|
7
7
|
const reconciler = Reconciler(hostConfig);
|
|
8
8
|
const render = (jsx, root, callback) => {
|
|
9
|
-
const container = reconciler.createContainer(root, 0, null, false, null, "peachy", console.error, console.error, console.error, () => {}
|
|
9
|
+
const container = reconciler.createContainer(root, 0, null, false, null, "peachy", console.error, console.error, console.error, () => {});
|
|
10
10
|
reconciler.updateContainer(jsx, container, null, callback);
|
|
11
11
|
};
|
|
12
12
|
reconciler.injectIntoDevTools({
|
package/dist/jsx-runtime.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from "react";
|
|
2
2
|
import * as React from "react/jsx-runtime";
|
|
3
3
|
|
|
4
4
|
//#region src/jsx-runtime.d.ts
|
|
5
5
|
declare const jsx: typeof React.jsx;
|
|
6
6
|
declare const jsxs: typeof React.jsxs;
|
|
7
|
-
declare const Fragment:
|
|
7
|
+
declare const Fragment: react.ExoticComponent<react.FragmentProps>;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { Fragment, jsx, jsxs };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import GObject from "gi://GObject?version=2.0";
|
|
2
|
+
|
|
1
3
|
//#region src/types.d.ts
|
|
2
4
|
type Props = Record<string, unknown>;
|
|
3
5
|
type Listener = (...args: any[]) => any;
|
|
@@ -5,9 +7,9 @@ interface ReactionMetadata {
|
|
|
5
7
|
childType?: string;
|
|
6
8
|
}
|
|
7
9
|
interface PeachyExtraMethods<T extends Gtk.Widget, State = {}> {
|
|
8
|
-
appendChild?(parentInstance: T, child:
|
|
9
|
-
insertBefore?(parentInstance: T, child:
|
|
10
|
-
removeChild?(parentInstance: T, child:
|
|
10
|
+
appendChild?(parentInstance: T, child: GObject.Object): void;
|
|
11
|
+
insertBefore?(parentInstance: T, child: GObject.Object, before: GObject.Object | null): void;
|
|
12
|
+
removeChild?(parentInstance: T, child: GObject.Object): void;
|
|
11
13
|
saveState?(instance: T): State;
|
|
12
14
|
restoreState?(instance: T, state: State): void;
|
|
13
15
|
}
|
|
@@ -2,40 +2,20 @@ import { getExtraMethod } from "./extra.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/utilities/children.ts
|
|
4
4
|
function appendChild(parentInstance, child) {
|
|
5
|
-
|
|
6
|
-
if (appendChild) return appendChild(parentInstance, child);
|
|
7
|
-
if ("child" in parentInstance) {
|
|
8
|
-
parentInstance.child = child;
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if ("content" in parentInstance) {
|
|
12
|
-
parentInstance.content = child;
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
child.set_parent(parentInstance);
|
|
5
|
+
getExtraMethod(parentInstance, "appendChild")?.(parentInstance, child);
|
|
16
6
|
}
|
|
17
7
|
function insertBefore(parentInstance, child, sibling) {
|
|
18
8
|
const insertBefore = getExtraMethod(parentInstance, "insertBefore");
|
|
19
9
|
if (insertBefore) return insertBefore(parentInstance, child, sibling);
|
|
20
10
|
const children = getAllChildren(parentInstance);
|
|
21
|
-
children.forEach((child
|
|
11
|
+
children.forEach((child) => removeChild(parentInstance, child));
|
|
22
12
|
const childIndex = children.findIndex((c) => c === sibling);
|
|
23
13
|
if (childIndex !== -1) children.splice(childIndex, 0, child);
|
|
24
14
|
else children.push(child);
|
|
25
|
-
children.forEach((child
|
|
15
|
+
children.forEach((child) => appendChild(parentInstance, child));
|
|
26
16
|
}
|
|
27
17
|
function removeChild(parentInstance, child) {
|
|
28
|
-
|
|
29
|
-
if (removeChild) return removeChild(parentInstance, child);
|
|
30
|
-
if ("child" in parentInstance) {
|
|
31
|
-
parentInstance.child = null;
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if ("content" in parentInstance) {
|
|
35
|
-
parentInstance.content = null;
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
child.unparent();
|
|
18
|
+
getExtraMethod(parentInstance, "removeChild")?.(parentInstance, child);
|
|
39
19
|
}
|
|
40
20
|
function getAllChildren(parentInstance) {
|
|
41
21
|
const children = [];
|
package/dist/utilities/diff.mjs
CHANGED
|
@@ -2,44 +2,43 @@ import { setMetadataFromProps } from "./metadata.mjs";
|
|
|
2
2
|
import GObject from "gi://GObject?version=2.0";
|
|
3
3
|
|
|
4
4
|
//#region src/utilities/diff.ts
|
|
5
|
-
const INTERNAL_PROP_NAMES = [
|
|
5
|
+
const INTERNAL_PROP_NAMES = new Set([
|
|
6
6
|
"childType",
|
|
7
7
|
"ref",
|
|
8
|
-
"key"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const isEvent = (key) => key.startsWith("on");
|
|
12
|
-
const isProperty = (key) => key !== "children" && !isEvent(key) && !INTERNAL_PROP_NAMES.includes(key);
|
|
13
|
-
const isNew = (prev, next) => (key) => prev[key] !== next[key];
|
|
14
|
-
const isGone = (prev, next) => (key) => !(key in next);
|
|
8
|
+
"key",
|
|
9
|
+
"children"
|
|
10
|
+
]);
|
|
15
11
|
function updateWidget(widget, prev, next) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
widget.freeze_notify();
|
|
13
|
+
try {
|
|
14
|
+
for (const key of Object.keys(prev)) {
|
|
15
|
+
if (INTERNAL_PROP_NAMES.has(key)) continue;
|
|
16
|
+
const isChanged = prev[key] !== next[key];
|
|
17
|
+
const isRemoved = !(key in next);
|
|
18
|
+
if (isEvent(key) && (isRemoved || isChanged)) {
|
|
19
|
+
if (GObject.signal_handlers_disconnect_by_func(widget, prev[key]) === 0) console.warn(`No signal handler found for ${key}`);
|
|
20
|
+
} else if (!isEvent(key) && isRemoved) widget[key] = void 0;
|
|
21
|
+
}
|
|
22
|
+
for (const key of Object.keys(next)) {
|
|
23
|
+
if (INTERNAL_PROP_NAMES.has(key)) continue;
|
|
24
|
+
if (prev[key] === next[key]) continue;
|
|
25
|
+
if (isEvent(key)) widget.connect(getEventName(key), next[key]);
|
|
26
|
+
else widget[key] = next[key];
|
|
27
|
+
}
|
|
28
|
+
} finally {
|
|
29
|
+
widget.thaw_notify();
|
|
30
|
+
}
|
|
29
31
|
setMetadataFromProps(widget, next);
|
|
30
32
|
}
|
|
31
33
|
function getProperties(props) {
|
|
32
|
-
return Object.
|
|
33
|
-
acc[key] = props[key];
|
|
34
|
-
return acc;
|
|
35
|
-
}, {});
|
|
34
|
+
return Object.fromEntries(Object.entries(props).filter(([key]) => isProperty(key)));
|
|
36
35
|
}
|
|
37
36
|
function getEventListeners(props) {
|
|
38
|
-
return Object.
|
|
39
|
-
acc[key] = props[key];
|
|
40
|
-
return acc;
|
|
41
|
-
}, {});
|
|
37
|
+
return Object.fromEntries(Object.entries(props).filter(([key]) => isEvent(key)));
|
|
42
38
|
}
|
|
39
|
+
const getEventName = (event) => event.substring(2).replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "").replace(/:-?/, "::");
|
|
40
|
+
const isEvent = (key) => key.startsWith("on");
|
|
41
|
+
const isProperty = (key) => !isEvent(key) && !INTERNAL_PROP_NAMES.has(key);
|
|
43
42
|
|
|
44
43
|
//#endregion
|
|
45
44
|
export { getEventListeners, getEventName, getProperties, updateWidget };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peachy/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Run GJS applications with react",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -16,17 +16,17 @@
|
|
|
16
16
|
},
|
|
17
17
|
"author": "Angelo Verlain <hey@vixalien.com>",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@peachy/types": "^2025.
|
|
20
|
-
"react": "^19.2.
|
|
19
|
+
"@peachy/types": "^2025.2.4",
|
|
20
|
+
"react": "^19.2.4",
|
|
21
21
|
"react-reconciler": "^0.33.0",
|
|
22
22
|
"reflect-metadata": "^0.2.2",
|
|
23
|
-
"@peachy/core": "0.0.
|
|
23
|
+
"@peachy/core": "0.0.10"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/node": "^25.
|
|
27
|
-
"@types/react": "^19.2.
|
|
28
|
-
"@types/react-reconciler": "^0.
|
|
29
|
-
"tsdown": "0.20.
|
|
26
|
+
"@types/node": "^25.2.1",
|
|
27
|
+
"@types/react": "^19.2.13",
|
|
28
|
+
"@types/react-reconciler": "^0.33.0",
|
|
29
|
+
"tsdown": "0.20.3",
|
|
30
30
|
"typescript": "^5.9.3"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
package/tsconfig.json
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
"include": [
|
|
8
8
|
// when installed locally
|
|
9
9
|
"./node_modules/@peachy/types/types/index.d.ts",
|
|
10
|
+
"./node_modules/@peachy/core/node_modules/@peachy/plugin-resources/src/types/global.d.ts",
|
|
10
11
|
// when installed via npm/pnpm
|
|
11
12
|
"../types/types/index.d.ts",
|
|
13
|
+
"../plugin-resources/src/types/global.d.ts",
|
|
12
14
|
"${configDir}/src/**/*",
|
|
13
15
|
],
|
|
14
16
|
}
|