@peachy/react 0.0.8 → 0.0.9
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.d.mts +3 -8
- package/dist/extra.mjs +20 -0
- package/dist/global.d.mts +1 -0
- package/dist/hostconfig.d.mts +7 -0
- package/dist/hostconfig.mjs +111 -0
- package/dist/index.mjs +2 -108
- package/dist/types.d.mts +8 -1
- package/dist/utilities/children.mjs +7 -18
- package/dist/utilities/extra.mjs +16 -0
- package/package.json +3 -2
package/dist/extra.d.mts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PeachyExtraMethods } from "./types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/extra.d.ts
|
|
4
|
-
|
|
5
|
-
appendChild?(parentInstance: T, child: Gtk.Widget): void;
|
|
6
|
-
insertBefore?(parentInstance: T, child: Gtk.Widget, before: Gtk.Widget | null): void;
|
|
7
|
-
removeChild?(parentInstance: T, child: Gtk.Widget): void;
|
|
8
|
-
}
|
|
9
|
-
declare const extraMap: Map<GObject.GType, ReactionExtraProps<Gtk.Widget>>;
|
|
4
|
+
declare const extraMap: Map<GObject.GType, PeachyExtraMethods<Gtk.Widget, {}>>;
|
|
10
5
|
//#endregion
|
|
11
|
-
export {
|
|
6
|
+
export { extraMap };
|
package/dist/extra.mjs
CHANGED
|
@@ -2,6 +2,18 @@ import { getMetadata } from "./utilities/metadata.mjs";
|
|
|
2
2
|
import Gtk from "gi://Gtk?version=4.0";
|
|
3
3
|
|
|
4
4
|
//#region src/extra.ts
|
|
5
|
+
/**
|
|
6
|
+
* GTK has some limitations, so here we try to solve some of them
|
|
7
|
+
*
|
|
8
|
+
* For example, it's not that clear how to add children to an element, every Widget
|
|
9
|
+
* has it's own API, here we map each Object (or an Interface) on how to something
|
|
10
|
+
* for example:
|
|
11
|
+
*
|
|
12
|
+
* - how to append a child to this object
|
|
13
|
+
* - how to remove a child from this object
|
|
14
|
+
* - how to insert a child before another child
|
|
15
|
+
* - how to save/restore state for this object (between updates, not currently saved)
|
|
16
|
+
*/
|
|
5
17
|
let builder;
|
|
6
18
|
const extraMap = new Map([
|
|
7
19
|
[Gtk.Buildable.$gtype, { appendChild: (parentInstance, child) => {
|
|
@@ -38,6 +50,14 @@ const extraMap = new Map([
|
|
|
38
50
|
const siblingRow = sibling instanceof Gtk.ListBoxRow ? sibling : sibling.get_ancestor(Gtk.ListBoxRow.$gtype);
|
|
39
51
|
parentInstance.insert(child, siblingRow?.get_index() ?? 0);
|
|
40
52
|
}
|
|
53
|
+
}],
|
|
54
|
+
[Gtk.Editable.$gtype, {
|
|
55
|
+
saveState(instance) {
|
|
56
|
+
return { cursorPosition: instance.get_position() };
|
|
57
|
+
},
|
|
58
|
+
restoreState(instance, state) {
|
|
59
|
+
instance.set_position(state.cursorPosition);
|
|
60
|
+
}
|
|
41
61
|
}]
|
|
42
62
|
]);
|
|
43
63
|
|
package/dist/global.d.mts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Gtk from "gi://Gtk?version=4.0";
|
|
2
|
+
import { HostConfig } from "react-reconciler";
|
|
3
|
+
|
|
4
|
+
//#region src/hostconfig.d.ts
|
|
5
|
+
declare const hostConfig: HostConfig<string, Record<string, unknown>, Gtk.Widget, Gtk.Widget, Gtk.Label, Gtk.Widget, null, any, any, any, any, any, any, any>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { hostConfig };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { setMetadataFromProps } from "./utilities/metadata.mjs";
|
|
2
|
+
import { typeMap } from "./type-map.mjs";
|
|
3
|
+
import { appendChild, insertBefore, removeChild } from "./utilities/children.mjs";
|
|
4
|
+
import { getEventListeners, getEventName, getProperties, updateWidget } from "./utilities/diff.mjs";
|
|
5
|
+
import Gtk from "gi://Gtk?version=4.0";
|
|
6
|
+
import GLib from "gi://GLib?version=2.0";
|
|
7
|
+
import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constants";
|
|
8
|
+
|
|
9
|
+
//#region src/hostconfig.ts
|
|
10
|
+
const emptyObject = {};
|
|
11
|
+
let updatePriority = NoEventPriority;
|
|
12
|
+
const hostConfig = {
|
|
13
|
+
appendInitialChild(parentInstance, child) {
|
|
14
|
+
appendChild(parentInstance, child);
|
|
15
|
+
},
|
|
16
|
+
createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
|
|
17
|
+
const klass = typeMap.get(type);
|
|
18
|
+
if (!klass) throw new Error(`Unknown type: ${type}`);
|
|
19
|
+
return new klass(getProperties(props));
|
|
20
|
+
},
|
|
21
|
+
createTextInstance(text, rootContainerInstance, internalInstanceHandle) {
|
|
22
|
+
return Gtk.Label.new(text);
|
|
23
|
+
},
|
|
24
|
+
finalizeInitialChildren(widget, type, props) {
|
|
25
|
+
const events = getEventListeners(props);
|
|
26
|
+
Object.keys(events).forEach((name) => {
|
|
27
|
+
const eventType = getEventName(name);
|
|
28
|
+
widget.connect(eventType, events[name]);
|
|
29
|
+
});
|
|
30
|
+
setMetadataFromProps(widget, props);
|
|
31
|
+
return false;
|
|
32
|
+
},
|
|
33
|
+
getPublicInstance(inst) {
|
|
34
|
+
return inst;
|
|
35
|
+
},
|
|
36
|
+
prepareForCommit(container) {
|
|
37
|
+
return null;
|
|
38
|
+
},
|
|
39
|
+
resetAfterCommit() {},
|
|
40
|
+
getRootHostContext(rootInstance) {
|
|
41
|
+
return emptyObject;
|
|
42
|
+
},
|
|
43
|
+
getChildHostContext(parentHostContext, type) {
|
|
44
|
+
return emptyObject;
|
|
45
|
+
},
|
|
46
|
+
shouldSetTextContent(type, props) {
|
|
47
|
+
return false;
|
|
48
|
+
},
|
|
49
|
+
supportsMutation: true,
|
|
50
|
+
supportsHydration: false,
|
|
51
|
+
supportsPersistence: false,
|
|
52
|
+
supportsMicrotasks: true,
|
|
53
|
+
scheduleTimeout: (fn, delay) => {
|
|
54
|
+
GLib.timeout_add(GLib.PRIORITY_DEFAULT, delay, () => {
|
|
55
|
+
fn();
|
|
56
|
+
return GLib.SOURCE_REMOVE;
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
scheduleMicrotask: (fn) => {
|
|
60
|
+
GLib.idle_add(GLib.PRIORITY_HIGH_IDLE, () => {
|
|
61
|
+
fn();
|
|
62
|
+
return GLib.SOURCE_REMOVE;
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
removeChild(parentInstance, child) {
|
|
66
|
+
removeChild(parentInstance, child);
|
|
67
|
+
},
|
|
68
|
+
removeChildFromContainer(parentInstance, child) {
|
|
69
|
+
removeChild(parentInstance, child);
|
|
70
|
+
},
|
|
71
|
+
insertBefore(parentInstance, child, beforeChild) {
|
|
72
|
+
insertBefore(parentInstance, child, beforeChild);
|
|
73
|
+
},
|
|
74
|
+
insertInContainerBefore(parentInstance, child, beforeChild) {
|
|
75
|
+
insertBefore(parentInstance, child, beforeChild);
|
|
76
|
+
},
|
|
77
|
+
clearContainer(container) {},
|
|
78
|
+
appendChild(parentInstance, child) {
|
|
79
|
+
appendChild(parentInstance, child);
|
|
80
|
+
},
|
|
81
|
+
appendChildToContainer(container, child) {
|
|
82
|
+
appendChild(container, child);
|
|
83
|
+
},
|
|
84
|
+
detachDeletedInstance(node) {},
|
|
85
|
+
commitUpdate(widget, type, oldProps, newProps, internalInstanceHandle) {
|
|
86
|
+
updateWidget(widget, oldProps, newProps);
|
|
87
|
+
},
|
|
88
|
+
commitTextUpdate(textInstance, oldText, newText) {
|
|
89
|
+
textInstance.label = newText;
|
|
90
|
+
},
|
|
91
|
+
resolveUpdatePriority: function() {
|
|
92
|
+
if (updatePriority !== NoEventPriority) return updatePriority;
|
|
93
|
+
return DefaultEventPriority;
|
|
94
|
+
},
|
|
95
|
+
setCurrentUpdatePriority: function(newPriority) {
|
|
96
|
+
updatePriority = newPriority;
|
|
97
|
+
},
|
|
98
|
+
getCurrentUpdatePriority: function() {
|
|
99
|
+
return updatePriority;
|
|
100
|
+
},
|
|
101
|
+
resolveEventTimeStamp() {
|
|
102
|
+
return -1.1;
|
|
103
|
+
},
|
|
104
|
+
resolveEventType() {
|
|
105
|
+
return null;
|
|
106
|
+
},
|
|
107
|
+
trackSchedulerEvent() {}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
export { hostConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1,116 +1,10 @@
|
|
|
1
|
-
import { setMetadataFromProps } from "./utilities/metadata.mjs";
|
|
2
1
|
import "./global.d.mts";
|
|
3
|
-
import {
|
|
4
|
-
import { appendChild, insertBefore, removeChild } from "./utilities/children.mjs";
|
|
5
|
-
import { getEventListeners, getEventName, getProperties, updateWidget } from "./utilities/diff.mjs";
|
|
6
|
-
import Gtk from "gi://Gtk?version=4.0";
|
|
2
|
+
import { hostConfig } from "./hostconfig.mjs";
|
|
7
3
|
import "reflect-metadata";
|
|
8
|
-
import GLib from "gi://GLib?version=2.0";
|
|
9
4
|
import Reconciler from "react-reconciler";
|
|
10
|
-
import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constants";
|
|
11
5
|
|
|
12
6
|
//#region src/index.ts
|
|
13
|
-
const
|
|
14
|
-
let updatePriority = NoEventPriority;
|
|
15
|
-
const reconciler = Reconciler({
|
|
16
|
-
appendInitialChild(parentInstance, child) {
|
|
17
|
-
appendChild(parentInstance, child);
|
|
18
|
-
},
|
|
19
|
-
createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
|
|
20
|
-
const klass = typeMap.get(type);
|
|
21
|
-
if (!klass) throw new Error(`Unknown type: ${type}`);
|
|
22
|
-
return new klass(getProperties(props));
|
|
23
|
-
},
|
|
24
|
-
createTextInstance(text, rootContainerInstance, internalInstanceHandle) {
|
|
25
|
-
return Gtk.Label.new(text);
|
|
26
|
-
},
|
|
27
|
-
finalizeInitialChildren(widget, type, props) {
|
|
28
|
-
const events = getEventListeners(props);
|
|
29
|
-
Object.keys(events).forEach((name) => {
|
|
30
|
-
const eventType = getEventName(name);
|
|
31
|
-
widget.connect(eventType, events[name]);
|
|
32
|
-
});
|
|
33
|
-
setMetadataFromProps(widget, props);
|
|
34
|
-
return false;
|
|
35
|
-
},
|
|
36
|
-
getPublicInstance(inst) {
|
|
37
|
-
return inst;
|
|
38
|
-
},
|
|
39
|
-
prepareForCommit() {
|
|
40
|
-
return null;
|
|
41
|
-
},
|
|
42
|
-
resetAfterCommit() {},
|
|
43
|
-
getRootHostContext(rootInstance) {
|
|
44
|
-
return emptyObject;
|
|
45
|
-
},
|
|
46
|
-
getChildHostContext(parentHostContext, type) {
|
|
47
|
-
return emptyObject;
|
|
48
|
-
},
|
|
49
|
-
shouldSetTextContent(type, props) {
|
|
50
|
-
return false;
|
|
51
|
-
},
|
|
52
|
-
supportsMutation: true,
|
|
53
|
-
supportsHydration: false,
|
|
54
|
-
supportsPersistence: false,
|
|
55
|
-
supportsMicrotasks: true,
|
|
56
|
-
scheduleTimeout: (fn, delay) => {
|
|
57
|
-
GLib.timeout_add(GLib.PRIORITY_DEFAULT, delay, () => {
|
|
58
|
-
fn();
|
|
59
|
-
return GLib.SOURCE_REMOVE;
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
scheduleMicrotask: (fn) => {
|
|
63
|
-
GLib.idle_add(GLib.PRIORITY_HIGH_IDLE, () => {
|
|
64
|
-
fn();
|
|
65
|
-
return GLib.SOURCE_REMOVE;
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
removeChild(parentInstance, child) {
|
|
69
|
-
removeChild(parentInstance, child);
|
|
70
|
-
},
|
|
71
|
-
removeChildFromContainer(parentInstance, child) {
|
|
72
|
-
removeChild(parentInstance, child);
|
|
73
|
-
},
|
|
74
|
-
insertBefore(parentInstance, child, beforeChild) {
|
|
75
|
-
insertBefore(parentInstance, child, beforeChild);
|
|
76
|
-
},
|
|
77
|
-
insertInContainerBefore(parentInstance, child, beforeChild) {
|
|
78
|
-
insertBefore(parentInstance, child, beforeChild);
|
|
79
|
-
},
|
|
80
|
-
clearContainer(container) {},
|
|
81
|
-
appendChild(parentInstance, child) {
|
|
82
|
-
appendChild(parentInstance, child);
|
|
83
|
-
},
|
|
84
|
-
appendChildToContainer(container, child) {
|
|
85
|
-
appendChild(container, child);
|
|
86
|
-
},
|
|
87
|
-
detachDeletedInstance(node) {
|
|
88
|
-
node.unparent();
|
|
89
|
-
},
|
|
90
|
-
commitUpdate(widget, type, oldProps, newProps, internalInstanceHandle) {
|
|
91
|
-
updateWidget(widget, oldProps, newProps);
|
|
92
|
-
},
|
|
93
|
-
commitTextUpdate(textInstance, oldText, newText) {
|
|
94
|
-
textInstance.label = newText;
|
|
95
|
-
},
|
|
96
|
-
resolveUpdatePriority: function() {
|
|
97
|
-
if (updatePriority !== NoEventPriority) return updatePriority;
|
|
98
|
-
return DefaultEventPriority;
|
|
99
|
-
},
|
|
100
|
-
setCurrentUpdatePriority: function(newPriority) {
|
|
101
|
-
updatePriority = newPriority;
|
|
102
|
-
},
|
|
103
|
-
getCurrentUpdatePriority: function() {
|
|
104
|
-
return updatePriority;
|
|
105
|
-
},
|
|
106
|
-
resolveEventTimeStamp() {
|
|
107
|
-
return -1.1;
|
|
108
|
-
},
|
|
109
|
-
resolveEventType() {
|
|
110
|
-
return null;
|
|
111
|
-
},
|
|
112
|
-
trackSchedulerEvent() {}
|
|
113
|
-
});
|
|
7
|
+
const reconciler = Reconciler(hostConfig);
|
|
114
8
|
const render = (jsx, root, callback) => {
|
|
115
9
|
const container = reconciler.createContainer(root, 0, null, false, null, "peachy", console.error, console.error, console.error, () => {}, null);
|
|
116
10
|
reconciler.updateContainer(jsx, container, null, callback);
|
package/dist/types.d.mts
CHANGED
|
@@ -4,5 +4,12 @@ type Listener = (...args: any[]) => any;
|
|
|
4
4
|
interface ReactionMetadata {
|
|
5
5
|
childType?: string;
|
|
6
6
|
}
|
|
7
|
+
interface PeachyExtraMethods<T extends Gtk.Widget, State = {}> {
|
|
8
|
+
appendChild?(parentInstance: T, child: Gtk.Widget): void;
|
|
9
|
+
insertBefore?(parentInstance: T, child: Gtk.Widget, before: Gtk.Widget | null): void;
|
|
10
|
+
removeChild?(parentInstance: T, child: Gtk.Widget): void;
|
|
11
|
+
saveState?(instance: T): State;
|
|
12
|
+
restoreState?(instance: T, state: State): void;
|
|
13
|
+
}
|
|
7
14
|
//#endregion
|
|
8
|
-
export { Listener, Props, ReactionMetadata };
|
|
15
|
+
export { Listener, PeachyExtraMethods, Props, ReactionMetadata };
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getGtype } from "./type.mjs";
|
|
3
|
-
import GObject from "gi://GObject?version=2.0";
|
|
1
|
+
import { getExtraMethod } from "./extra.mjs";
|
|
4
2
|
|
|
5
3
|
//#region src/utilities/children.ts
|
|
6
4
|
function appendChild(parentInstance, child) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
if (props.appendChild) {
|
|
10
|
-
props.appendChild(parentInstance, child);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
5
|
+
const appendChild = getExtraMethod(parentInstance, "appendChild");
|
|
6
|
+
if (appendChild) return appendChild(parentInstance, child);
|
|
14
7
|
if ("child" in parentInstance) {
|
|
15
8
|
parentInstance.child = child;
|
|
16
9
|
return;
|
|
@@ -22,10 +15,8 @@ function appendChild(parentInstance, child) {
|
|
|
22
15
|
child.set_parent(parentInstance);
|
|
23
16
|
}
|
|
24
17
|
function insertBefore(parentInstance, child, sibling) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
if (props.insertBefore) return props.insertBefore(parentInstance, child, sibling);
|
|
28
|
-
}
|
|
18
|
+
const insertBefore = getExtraMethod(parentInstance, "insertBefore");
|
|
19
|
+
if (insertBefore) return insertBefore(parentInstance, child, sibling);
|
|
29
20
|
const children = getAllChildren(parentInstance);
|
|
30
21
|
children.forEach((child$1) => removeChild(parentInstance, child$1));
|
|
31
22
|
const childIndex = children.findIndex((c) => c === sibling);
|
|
@@ -34,10 +25,8 @@ function insertBefore(parentInstance, child, sibling) {
|
|
|
34
25
|
children.forEach((child$1) => appendChild(parentInstance, child$1));
|
|
35
26
|
}
|
|
36
27
|
function removeChild(parentInstance, child) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
if (props.removeChild) return props.removeChild(parentInstance, child);
|
|
40
|
-
}
|
|
28
|
+
const removeChild = getExtraMethod(parentInstance, "removeChild");
|
|
29
|
+
if (removeChild) return removeChild(parentInstance, child);
|
|
41
30
|
if ("child" in parentInstance) {
|
|
42
31
|
parentInstance.child = null;
|
|
43
32
|
return;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { extraMap } from "../extra.mjs";
|
|
2
|
+
import { getGtype } from "./type.mjs";
|
|
3
|
+
import GObject from "gi://GObject?version=2.0";
|
|
4
|
+
|
|
5
|
+
//#region src/utilities/extra.ts
|
|
6
|
+
function getExtraMethod(object, method) {
|
|
7
|
+
const gtype = getGtype(object);
|
|
8
|
+
for (const [type, props] of extraMap) if (GObject.type_is_a(gtype, type)) {
|
|
9
|
+
const methodImplementation = props[method];
|
|
10
|
+
if (methodImplementation) return methodImplementation;
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { getExtraMethod };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peachy/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Run GJS applications with react",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -20,9 +20,10 @@
|
|
|
20
20
|
"react": "^19.2.3",
|
|
21
21
|
"react-reconciler": "^0.33.0",
|
|
22
22
|
"reflect-metadata": "^0.2.2",
|
|
23
|
-
"@peachy/core": "0.0.
|
|
23
|
+
"@peachy/core": "0.0.9"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@types/node": "^25.0.9",
|
|
26
27
|
"@types/react": "^19.2.8",
|
|
27
28
|
"@types/react-reconciler": "^0.32.3",
|
|
28
29
|
"tsdown": "0.20.0-beta.4",
|