@peachy/react 0.0.8 → 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.d.mts +3 -8
- package/dist/extra.mjs +57 -0
- package/dist/global.d.mts +5 -4
- package/dist/hostconfig.d.mts +7 -0
- package/dist/hostconfig.mjs +111 -0
- package/dist/index.mjs +3 -109
- package/dist/jsx-runtime.d.mts +2 -2
- package/dist/types.d.mts +10 -1
- package/dist/utilities/children.mjs +7 -38
- package/dist/utilities/diff.mjs +28 -29
- package/dist/utilities/extra.mjs +16 -0
- package/package.json +8 -7
- package/tsconfig.json +2 -0
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,51 @@ 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
|
+
}
|
|
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
|
+
}
|
|
41
98
|
}]
|
|
42
99
|
]);
|
|
43
100
|
|
package/dist/global.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import GObject from "gi://GObject?version=2.0";
|
|
1
2
|
import { Key, Ref } from "react";
|
|
2
3
|
|
|
3
4
|
//#region src/global.d.ts
|
|
@@ -20,8 +21,8 @@ declare module "gi://Gtk?version=4.0" {
|
|
|
20
21
|
namespace Widget {
|
|
21
22
|
interface ConstructorProps {
|
|
22
23
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
* React children
|
|
25
|
+
*/
|
|
25
26
|
children: any;
|
|
26
27
|
}
|
|
27
28
|
}
|
|
@@ -32,8 +33,8 @@ declare module "gi://Gtk?version=3.0" {
|
|
|
32
33
|
namespace Widget {
|
|
33
34
|
interface ConstructorProps {
|
|
34
35
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
* React children
|
|
37
|
+
*/
|
|
37
38
|
children: any;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -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,118 +1,12 @@
|
|
|
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
|
-
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, () => {});
|
|
116
10
|
reconciler.updateContainer(jsx, container, null, callback);
|
|
117
11
|
};
|
|
118
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,8 +1,17 @@
|
|
|
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;
|
|
4
6
|
interface ReactionMetadata {
|
|
5
7
|
childType?: string;
|
|
6
8
|
}
|
|
9
|
+
interface PeachyExtraMethods<T extends Gtk.Widget, State = {}> {
|
|
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;
|
|
13
|
+
saveState?(instance: T): State;
|
|
14
|
+
restoreState?(instance: T, state: State): void;
|
|
15
|
+
}
|
|
7
16
|
//#endregion
|
|
8
|
-
export { Listener, Props, ReactionMetadata };
|
|
17
|
+
export { Listener, PeachyExtraMethods, Props, ReactionMetadata };
|
|
@@ -1,52 +1,21 @@
|
|
|
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
|
-
|
|
8
|
-
for (const [type, props] of extraMap) if (GObject.type_is_a(gtype, type)) {
|
|
9
|
-
if (props.appendChild) {
|
|
10
|
-
props.appendChild(parentInstance, child);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
if ("child" in parentInstance) {
|
|
15
|
-
parentInstance.child = child;
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if ("content" in parentInstance) {
|
|
19
|
-
parentInstance.content = child;
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
child.set_parent(parentInstance);
|
|
5
|
+
getExtraMethod(parentInstance, "appendChild")?.(parentInstance, child);
|
|
23
6
|
}
|
|
24
7
|
function insertBefore(parentInstance, child, sibling) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
if (props.insertBefore) return props.insertBefore(parentInstance, child, sibling);
|
|
28
|
-
}
|
|
8
|
+
const insertBefore = getExtraMethod(parentInstance, "insertBefore");
|
|
9
|
+
if (insertBefore) return insertBefore(parentInstance, child, sibling);
|
|
29
10
|
const children = getAllChildren(parentInstance);
|
|
30
|
-
children.forEach((child
|
|
11
|
+
children.forEach((child) => removeChild(parentInstance, child));
|
|
31
12
|
const childIndex = children.findIndex((c) => c === sibling);
|
|
32
13
|
if (childIndex !== -1) children.splice(childIndex, 0, child);
|
|
33
14
|
else children.push(child);
|
|
34
|
-
children.forEach((child
|
|
15
|
+
children.forEach((child) => appendChild(parentInstance, child));
|
|
35
16
|
}
|
|
36
17
|
function removeChild(parentInstance, child) {
|
|
37
|
-
|
|
38
|
-
for (const [type, props] of extraMap) if (GObject.type_is_a(gtype, type)) {
|
|
39
|
-
if (props.removeChild) return props.removeChild(parentInstance, child);
|
|
40
|
-
}
|
|
41
|
-
if ("child" in parentInstance) {
|
|
42
|
-
parentInstance.child = null;
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if ("content" in parentInstance) {
|
|
46
|
-
parentInstance.content = null;
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
child.unparent();
|
|
18
|
+
getExtraMethod(parentInstance, "removeChild")?.(parentInstance, child);
|
|
50
19
|
}
|
|
51
20
|
function getAllChildren(parentInstance) {
|
|
52
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 };
|
|
@@ -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.10",
|
|
4
4
|
"description": "Run GJS applications with react",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -16,16 +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/
|
|
27
|
-
"@types/react
|
|
28
|
-
"
|
|
26
|
+
"@types/node": "^25.2.1",
|
|
27
|
+
"@types/react": "^19.2.13",
|
|
28
|
+
"@types/react-reconciler": "^0.33.0",
|
|
29
|
+
"tsdown": "0.20.3",
|
|
29
30
|
"typescript": "^5.9.3"
|
|
30
31
|
},
|
|
31
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
|
}
|