@peachy/react 0.0.10 → 0.0.12
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 +5 -22
- package/dist/extra.d.mts +3 -1
- package/dist/extra.mjs +1 -3
- package/dist/global.d.mts +10 -30
- package/dist/hostconfig.mjs +46 -19
- package/dist/index.d.mts +17 -5
- package/dist/index.mjs +24 -4
- package/dist/jsx-dev-runtime.mjs +1 -3
- package/dist/jsx-runtime.d.mts +1 -2
- package/dist/jsx-runtime.mjs +1 -3
- package/dist/jsx-utils.mjs +1 -3
- package/dist/type-map.d.mts +3 -1
- package/dist/type-map.mjs +1 -2
- package/dist/types.d.mts +5 -0
- package/dist/utilities/children.mjs +1 -3
- package/dist/utilities/diff.mjs +2 -3
- package/dist/utilities/extra.mjs +1 -3
- package/dist/utilities/metadata.mjs +6 -4
- package/dist/utilities/suspend.mjs +31 -0
- package/dist/utilities/type.mjs +1 -2
- package/package.json +13 -12
- package/tsconfig.json +7 -5
package/README.md
CHANGED
|
@@ -36,10 +36,7 @@ Here is a basic example that creates a GTK application window with a label:
|
|
|
36
36
|
import Gtk from "gi://Gtk?version=4.0";
|
|
37
37
|
import { render } from "@peachy/react";
|
|
38
38
|
|
|
39
|
-
const app = Gtk.Application.new(
|
|
40
|
-
"com.hello.world",
|
|
41
|
-
Gio.ApplicationFlags.DEFAULT_FLAGS,
|
|
42
|
-
);
|
|
39
|
+
const app = Gtk.Application.new("com.hello.world", Gio.ApplicationFlags.DEFAULT_FLAGS);
|
|
43
40
|
|
|
44
41
|
app.connect("activate", () => {
|
|
45
42
|
const app_window = Gtk.ApplicationWindow.new(app);
|
|
@@ -58,22 +55,14 @@ You can also create reusable components using React's component system. For exam
|
|
|
58
55
|
import Gtk from "gi://Gtk?version=4.0";
|
|
59
56
|
import { render } from "@peachy/react";
|
|
60
57
|
|
|
61
|
-
const Button = ({ label, onClick }) =>
|
|
62
|
-
<Gtk.Button label={label} onClick={onClick} />
|
|
63
|
-
);
|
|
58
|
+
const Button = ({ label, onClick }) => <Gtk.Button label={label} onClick={onClick} />;
|
|
64
59
|
|
|
65
|
-
const app = Gtk.Application.new(
|
|
66
|
-
"com.hello.world",
|
|
67
|
-
Gio.ApplicationFlags.DEFAULT_FLAGS,
|
|
68
|
-
);
|
|
60
|
+
const app = Gtk.Application.new("com.hello.world", Gio.ApplicationFlags.DEFAULT_FLAGS);
|
|
69
61
|
|
|
70
62
|
app.connect("activate", () => {
|
|
71
63
|
const app_window = Gtk.ApplicationWindow.new(app);
|
|
72
64
|
|
|
73
|
-
render(
|
|
74
|
-
<Button label="Click me!" onClick={() => console.log("Button clicked")} />,
|
|
75
|
-
app_window,
|
|
76
|
-
);
|
|
65
|
+
render(<Button label="Click me!" onClick={() => console.log("Button clicked")} />, app_window);
|
|
77
66
|
|
|
78
67
|
app_window.present();
|
|
79
68
|
});
|
|
@@ -95,13 +84,7 @@ const Button = () => {
|
|
|
95
84
|
const onClicked = () => console.log("Button clicked");
|
|
96
85
|
const onFocused = () => console.log("Button focused/unfocused");
|
|
97
86
|
|
|
98
|
-
return
|
|
99
|
-
<Gtk.Button
|
|
100
|
-
label="Hello World"
|
|
101
|
-
onClicked={onClicked}
|
|
102
|
-
onNotify:hasFocus={onFocused}
|
|
103
|
-
/>
|
|
104
|
-
);
|
|
87
|
+
return <Gtk.Button label="Hello World" onClicked={onClicked} onNotify:hasFocus={onFocused} />;
|
|
105
88
|
};
|
|
106
89
|
|
|
107
90
|
app.run([]);
|
package/dist/extra.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PeachyExtraMethods } from "./types.mjs";
|
|
2
|
+
import Gtk from "gi://Gtk?version=4.0";
|
|
3
|
+
import GObject from "gi://GObject?version=2.0";
|
|
2
4
|
|
|
3
5
|
//#region src/extra.d.ts
|
|
4
|
-
declare const extraMap: Map<GObject.GType
|
|
6
|
+
declare const extraMap: Map<GObject.GType<unknown>, PeachyExtraMethods<Gtk.Widget, {}>>;
|
|
5
7
|
//#endregion
|
|
6
8
|
export { extraMap };
|
package/dist/extra.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getMetadata } from "./utilities/metadata.mjs";
|
|
2
2
|
import Gtk from "gi://Gtk?version=4.0";
|
|
3
|
-
|
|
4
3
|
//#region src/extra.ts
|
|
5
4
|
/**
|
|
6
5
|
* GTK has some limitations, so here we try to solve some of them
|
|
@@ -97,6 +96,5 @@ const extraMap = new Map([
|
|
|
97
96
|
}
|
|
98
97
|
}]
|
|
99
98
|
]);
|
|
100
|
-
|
|
101
99
|
//#endregion
|
|
102
|
-
export { extraMap };
|
|
100
|
+
export { extraMap };
|
package/dist/global.d.mts
CHANGED
|
@@ -3,42 +3,22 @@ import { Key, Ref } from "react";
|
|
|
3
3
|
|
|
4
4
|
//#region src/global.d.ts
|
|
5
5
|
type PascalCase<S> = S extends `${infer Head}${"-" | "_"}${infer Tail}` ? `${Capitalize<Head>}${PascalCase<Tail>}` : S extends string ? Capitalize<S> : never;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`on${PascalCase<`${E}:${D}`>}` : S extends string ? `on${PascalCase<S>}` : never]?: GObject.SignalCallback<Self, Self["$signals"][S]> };
|
|
6
|
+
// [TODO] maybe optimize this later by getting all the static signals
|
|
7
|
+
type SignalProps<Self extends GObject.Object> = { [S in keyof Self["$signals"] as S extends `${infer E}::${infer D}` ? `on${PascalCase<E>}:${E extends "notify" ? PascalCase<keyof Self["$readableProperties"]> : string}` : S extends string ? `on${PascalCase<S>}` : never]?: GObject.SignalCallback<Self, Self["$signals"][S]> };
|
|
9
8
|
declare global {
|
|
10
9
|
namespace JSX {
|
|
11
10
|
interface IntrinsicAttributes {
|
|
12
|
-
|
|
11
|
+
// react props
|
|
13
12
|
ref?: Ref<any>;
|
|
14
13
|
key?: Key | null | undefined;
|
|
14
|
+
children?: OrArray<any>; // peachy props
|
|
15
|
+
/** @deprecated use `$type` instead */
|
|
16
|
+
childType?: string;
|
|
17
|
+
$type?: string;
|
|
15
18
|
}
|
|
16
|
-
type LibraryManagedAttributes<C, Props> = C extends
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
declare module "gi://Gtk?version=4.0" {
|
|
20
|
-
namespace Gtk {
|
|
21
|
-
namespace Widget {
|
|
22
|
-
interface ConstructorProps {
|
|
23
|
-
/**
|
|
24
|
-
* React children
|
|
25
|
-
*/
|
|
26
|
-
children: any;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
declare module "gi://Gtk?version=3.0" {
|
|
32
|
-
namespace Gtk {
|
|
33
|
-
namespace Widget {
|
|
34
|
-
interface ConstructorProps {
|
|
35
|
-
/**
|
|
36
|
-
* React children
|
|
37
|
-
*/
|
|
38
|
-
children: any;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
19
|
+
type LibraryManagedAttributes<C, Props> = C["prototype"] extends GObject.Object ? Props & SignalProps<C["prototype"]> : Props;
|
|
41
20
|
}
|
|
42
21
|
}
|
|
22
|
+
type OrArray<T> = T | T[];
|
|
43
23
|
//#endregion
|
|
44
|
-
export { PascalCase
|
|
24
|
+
export { PascalCase };
|
package/dist/hostconfig.mjs
CHANGED
|
@@ -2,10 +2,11 @@ import { setMetadataFromProps } from "./utilities/metadata.mjs";
|
|
|
2
2
|
import { typeMap } from "./type-map.mjs";
|
|
3
3
|
import { appendChild, insertBefore, removeChild } from "./utilities/children.mjs";
|
|
4
4
|
import { getEventListeners, getEventName, getProperties, updateWidget } from "./utilities/diff.mjs";
|
|
5
|
+
import { hideInstance, unhideInstance } from "./utilities/suspend.mjs";
|
|
5
6
|
import Gtk from "gi://Gtk?version=4.0";
|
|
7
|
+
import { createContext } from "react";
|
|
6
8
|
import GLib from "gi://GLib?version=2.0";
|
|
7
9
|
import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constants";
|
|
8
|
-
|
|
9
10
|
//#region src/hostconfig.ts
|
|
10
11
|
const emptyObject = {};
|
|
11
12
|
let updatePriority = NoEventPriority;
|
|
@@ -13,15 +14,15 @@ const hostConfig = {
|
|
|
13
14
|
appendInitialChild(parentInstance, child) {
|
|
14
15
|
appendChild(parentInstance, child);
|
|
15
16
|
},
|
|
16
|
-
createInstance(type, props
|
|
17
|
+
createInstance(type, props) {
|
|
17
18
|
const klass = typeMap.get(type);
|
|
18
19
|
if (!klass) throw new Error(`Unknown type: ${type}`);
|
|
19
20
|
return new klass(getProperties(props));
|
|
20
21
|
},
|
|
21
|
-
createTextInstance(
|
|
22
|
-
return Gtk.Label
|
|
22
|
+
createTextInstance(label) {
|
|
23
|
+
return new Gtk.Label({ label });
|
|
23
24
|
},
|
|
24
|
-
finalizeInitialChildren(widget,
|
|
25
|
+
finalizeInitialChildren(widget, _type, props) {
|
|
25
26
|
const events = getEventListeners(props);
|
|
26
27
|
Object.keys(events).forEach((name) => {
|
|
27
28
|
const eventType = getEventName(name);
|
|
@@ -33,34 +34,32 @@ const hostConfig = {
|
|
|
33
34
|
getPublicInstance(inst) {
|
|
34
35
|
return inst;
|
|
35
36
|
},
|
|
36
|
-
prepareForCommit(
|
|
37
|
+
prepareForCommit() {
|
|
37
38
|
return null;
|
|
38
39
|
},
|
|
39
40
|
resetAfterCommit() {},
|
|
40
|
-
getRootHostContext(
|
|
41
|
+
getRootHostContext() {
|
|
41
42
|
return emptyObject;
|
|
42
43
|
},
|
|
43
|
-
getChildHostContext(
|
|
44
|
+
getChildHostContext() {
|
|
44
45
|
return emptyObject;
|
|
45
46
|
},
|
|
46
|
-
shouldSetTextContent(
|
|
47
|
+
shouldSetTextContent() {
|
|
47
48
|
return false;
|
|
48
49
|
},
|
|
50
|
+
isPrimaryRenderer: true,
|
|
49
51
|
supportsMutation: true,
|
|
50
52
|
supportsHydration: false,
|
|
51
53
|
supportsPersistence: false,
|
|
52
54
|
supportsMicrotasks: true,
|
|
53
|
-
scheduleTimeout: (fn, delay) => {
|
|
55
|
+
scheduleTimeout: (fn, delay = 10) => {
|
|
54
56
|
GLib.timeout_add(GLib.PRIORITY_DEFAULT, delay, () => {
|
|
55
57
|
fn();
|
|
56
58
|
return GLib.SOURCE_REMOVE;
|
|
57
59
|
});
|
|
58
60
|
},
|
|
59
61
|
scheduleMicrotask: (fn) => {
|
|
60
|
-
|
|
61
|
-
fn();
|
|
62
|
-
return GLib.SOURCE_REMOVE;
|
|
63
|
-
});
|
|
62
|
+
Promise.resolve().then(fn);
|
|
64
63
|
},
|
|
65
64
|
removeChild(parentInstance, child) {
|
|
66
65
|
removeChild(parentInstance, child);
|
|
@@ -81,8 +80,10 @@ const hostConfig = {
|
|
|
81
80
|
appendChildToContainer(container, child) {
|
|
82
81
|
appendChild(container, child);
|
|
83
82
|
},
|
|
84
|
-
detachDeletedInstance(node) {
|
|
85
|
-
|
|
83
|
+
detachDeletedInstance(node) {
|
|
84
|
+
node.unparent();
|
|
85
|
+
},
|
|
86
|
+
commitUpdate(widget, type, oldProps, newProps) {
|
|
86
87
|
updateWidget(widget, oldProps, newProps);
|
|
87
88
|
},
|
|
88
89
|
commitTextUpdate(textInstance, oldText, newText) {
|
|
@@ -104,8 +105,34 @@ const hostConfig = {
|
|
|
104
105
|
resolveEventType() {
|
|
105
106
|
return null;
|
|
106
107
|
},
|
|
107
|
-
trackSchedulerEvent() {}
|
|
108
|
+
trackSchedulerEvent() {},
|
|
109
|
+
hideInstance(instance) {
|
|
110
|
+
hideInstance(instance);
|
|
111
|
+
},
|
|
112
|
+
hideTextInstance(textInstance) {
|
|
113
|
+
hideInstance(textInstance);
|
|
114
|
+
},
|
|
115
|
+
unhideInstance(instance) {
|
|
116
|
+
unhideInstance(instance);
|
|
117
|
+
},
|
|
118
|
+
unhideTextInstance(textInstance) {
|
|
119
|
+
unhideInstance(textInstance);
|
|
120
|
+
},
|
|
121
|
+
maySuspendCommit: () => false,
|
|
122
|
+
preloadInstance: () => true,
|
|
123
|
+
startSuspendingCommit: () => {},
|
|
124
|
+
suspendInstance: () => {},
|
|
125
|
+
waitForCommitToBeReady: () => null,
|
|
126
|
+
NotPendingTransition: null,
|
|
127
|
+
HostTransitionContext: createContext(null),
|
|
128
|
+
getInstanceFromNode() {
|
|
129
|
+
return null;
|
|
130
|
+
},
|
|
131
|
+
getParentSuspenseInstance() {
|
|
132
|
+
return null;
|
|
133
|
+
},
|
|
134
|
+
preparePortalMount() {},
|
|
135
|
+
noTimeout: -1
|
|
108
136
|
};
|
|
109
|
-
|
|
110
137
|
//#endregion
|
|
111
|
-
export { hostConfig };
|
|
138
|
+
export { hostConfig };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import "./global.mjs";
|
|
2
1
|
import Gtk from "gi://Gtk?version=4.0";
|
|
3
|
-
import "
|
|
4
|
-
|
|
2
|
+
import { ReactNode, ReactPortal } from "react";
|
|
5
3
|
//#region src/index.d.ts
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated please use `createRoot` instead
|
|
6
|
+
*/
|
|
7
|
+
declare const render: (jsx: ReactNode, root: Gtk.Widget, callback?: () => void) => void;
|
|
8
|
+
interface Root {
|
|
9
|
+
render(element: ReactNode): void;
|
|
10
|
+
unmount(): void;
|
|
11
|
+
}
|
|
12
|
+
declare function createRoot(container: Gtk.Widget, options?: {
|
|
13
|
+
identifierPrefix?: string;
|
|
14
|
+
onUncaughtError?: (e: Error) => void;
|
|
15
|
+
onCaughtError?: (e: Error) => void;
|
|
16
|
+
onRecoverableError?: (e: Error) => void;
|
|
17
|
+
}): Root;
|
|
18
|
+
declare function createPortal(children: ReactNode, container: Gtk.Widget, key?: string): ReactPortal;
|
|
7
19
|
//#endregion
|
|
8
|
-
export { render };
|
|
20
|
+
export { Root, createPortal, createRoot, render };
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
1
1
|
import "./global.d.mts";
|
|
2
2
|
import { hostConfig } from "./hostconfig.mjs";
|
|
3
|
+
import Gtk from "gi://Gtk?version=4.0";
|
|
4
|
+
import { ConcurrentRoot, LegacyRoot } from "react-reconciler/constants";
|
|
3
5
|
import "reflect-metadata";
|
|
6
|
+
import "@peachy/polyfills/performance";
|
|
4
7
|
import Reconciler from "react-reconciler";
|
|
5
|
-
|
|
6
8
|
//#region src/index.ts
|
|
7
9
|
const reconciler = Reconciler(hostConfig);
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated please use `createRoot` instead
|
|
12
|
+
*/
|
|
8
13
|
const render = (jsx, root, callback) => {
|
|
9
|
-
const container = reconciler.createContainer(root,
|
|
14
|
+
const container = reconciler.createContainer(root, LegacyRoot, null, false, null, "peachy", console.error, console.error, console.error, () => {});
|
|
10
15
|
reconciler.updateContainer(jsx, container, null, callback);
|
|
11
16
|
};
|
|
17
|
+
function createRoot(container, options) {
|
|
18
|
+
if (container instanceof Gtk.Widget === false) throw new Error("container must be a Gtk.Widget");
|
|
19
|
+
const fiberRoot = reconciler.createContainer(container, ConcurrentRoot, null, false, null, options?.identifierPrefix ?? "", options?.onUncaughtError ?? console.error, options?.onCaughtError ?? console.error, options?.onRecoverableError ?? console.error, console.error);
|
|
20
|
+
return {
|
|
21
|
+
render(element) {
|
|
22
|
+
reconciler.updateContainer(element, fiberRoot, null, null);
|
|
23
|
+
},
|
|
24
|
+
unmount() {
|
|
25
|
+
reconciler.updateContainer(null, fiberRoot, null, null);
|
|
26
|
+
reconciler.flushSyncWork();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function createPortal(children, container, key) {
|
|
31
|
+
return reconciler.createPortal(children, container, null, key);
|
|
32
|
+
}
|
|
12
33
|
reconciler.injectIntoDevTools({
|
|
13
34
|
bundleType: process.env.NODE_ENV === "development" ? 1 : 0,
|
|
14
35
|
version: "0.0.1",
|
|
15
36
|
rendererPackageName: "peachy"
|
|
16
37
|
});
|
|
17
|
-
|
|
18
38
|
//#endregion
|
|
19
|
-
export { render };
|
|
39
|
+
export { createPortal, createRoot, render };
|
package/dist/jsx-dev-runtime.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { transformType } from "./jsx-utils.mjs";
|
|
2
2
|
import * as React from "react/jsx-dev-runtime";
|
|
3
|
-
|
|
4
3
|
//#region src/jsx-dev-runtime.ts
|
|
5
4
|
const jsxDEV = (type, ...args) => {
|
|
6
5
|
const transformedType = transformType(type);
|
|
7
6
|
return React.jsxDEV(transformedType, ...args);
|
|
8
7
|
};
|
|
9
|
-
|
|
10
8
|
//#endregion
|
|
11
|
-
export { jsxDEV };
|
|
9
|
+
export { jsxDEV };
|
package/dist/jsx-runtime.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import * as react from "react";
|
|
2
1
|
import * as React from "react/jsx-runtime";
|
|
3
2
|
|
|
4
3
|
//#region src/jsx-runtime.d.ts
|
|
5
4
|
declare const jsx: typeof React.jsx;
|
|
6
5
|
declare const jsxs: typeof React.jsxs;
|
|
7
|
-
declare const Fragment:
|
|
6
|
+
declare const Fragment: typeof React.Fragment;
|
|
8
7
|
//#endregion
|
|
9
8
|
export { Fragment, jsx, jsxs };
|
package/dist/jsx-runtime.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { transformType } from "./jsx-utils.mjs";
|
|
2
2
|
import * as React from "react/jsx-runtime";
|
|
3
|
-
|
|
4
3
|
//#region src/jsx-runtime.ts
|
|
5
4
|
const jsx = (type, ...args) => {
|
|
6
5
|
const transformedType = transformType(type);
|
|
@@ -11,6 +10,5 @@ const jsxs = (type, ...args) => {
|
|
|
11
10
|
return React.jsxs(transformedType, ...args);
|
|
12
11
|
};
|
|
13
12
|
const Fragment = React.Fragment;
|
|
14
|
-
|
|
15
13
|
//#endregion
|
|
16
|
-
export { Fragment, jsx, jsxs };
|
|
14
|
+
export { Fragment, jsx, jsxs };
|
package/dist/jsx-utils.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { typeMap } from "./type-map.mjs";
|
|
2
2
|
import GObject from "gi://GObject?version=2.0";
|
|
3
|
-
|
|
4
3
|
//#region src/jsx-utils.ts
|
|
5
4
|
function isGtkWidgetClass(type) {
|
|
6
5
|
return typeof type === "function" && type.prototype instanceof GObject.Object;
|
|
@@ -13,6 +12,5 @@ const transformType = (type) => {
|
|
|
13
12
|
}
|
|
14
13
|
return type;
|
|
15
14
|
};
|
|
16
|
-
|
|
17
15
|
//#endregion
|
|
18
|
-
export { transformType };
|
|
16
|
+
export { transformType };
|
package/dist/type-map.d.mts
CHANGED
package/dist/type-map.mjs
CHANGED
package/dist/types.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Gtk from "gi://Gtk?version=4.0";
|
|
1
2
|
import GObject from "gi://GObject?version=2.0";
|
|
2
3
|
|
|
3
4
|
//#region src/types.d.ts
|
|
@@ -5,6 +6,10 @@ type Props = Record<string, unknown>;
|
|
|
5
6
|
type Listener = (...args: any[]) => any;
|
|
6
7
|
interface ReactionMetadata {
|
|
7
8
|
childType?: string;
|
|
9
|
+
suspenseState?: {
|
|
10
|
+
parent: Gtk.Widget;
|
|
11
|
+
nextSibling: Gtk.Widget | null;
|
|
12
|
+
};
|
|
8
13
|
}
|
|
9
14
|
interface PeachyExtraMethods<T extends Gtk.Widget, State = {}> {
|
|
10
15
|
appendChild?(parentInstance: T, child: GObject.Object): void;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getExtraMethod } from "./extra.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/utilities/children.ts
|
|
4
3
|
function appendChild(parentInstance, child) {
|
|
5
4
|
getExtraMethod(parentInstance, "appendChild")?.(parentInstance, child);
|
|
@@ -26,6 +25,5 @@ function getAllChildren(parentInstance) {
|
|
|
26
25
|
}
|
|
27
26
|
return children;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
28
|
//#endregion
|
|
31
|
-
export { appendChild, insertBefore, removeChild };
|
|
29
|
+
export { appendChild, insertBefore, removeChild };
|
package/dist/utilities/diff.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { setMetadataFromProps } from "./metadata.mjs";
|
|
2
2
|
import GObject from "gi://GObject?version=2.0";
|
|
3
|
-
|
|
4
3
|
//#region src/utilities/diff.ts
|
|
5
4
|
const INTERNAL_PROP_NAMES = new Set([
|
|
6
5
|
"childType",
|
|
6
|
+
"$type",
|
|
7
7
|
"ref",
|
|
8
8
|
"key",
|
|
9
9
|
"children"
|
|
@@ -39,6 +39,5 @@ function getEventListeners(props) {
|
|
|
39
39
|
const getEventName = (event) => event.substring(2).replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "").replace(/:-?/, "::");
|
|
40
40
|
const isEvent = (key) => key.startsWith("on");
|
|
41
41
|
const isProperty = (key) => !isEvent(key) && !INTERNAL_PROP_NAMES.has(key);
|
|
42
|
-
|
|
43
42
|
//#endregion
|
|
44
|
-
export { getEventListeners, getEventName, getProperties, updateWidget };
|
|
43
|
+
export { getEventListeners, getEventName, getProperties, updateWidget };
|
package/dist/utilities/extra.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { extraMap } from "../extra.mjs";
|
|
2
2
|
import { getGtype } from "./type.mjs";
|
|
3
3
|
import GObject from "gi://GObject?version=2.0";
|
|
4
|
-
|
|
5
4
|
//#region src/utilities/extra.ts
|
|
6
5
|
function getExtraMethod(object, method) {
|
|
7
6
|
const gtype = getGtype(object);
|
|
@@ -11,6 +10,5 @@ function getExtraMethod(object, method) {
|
|
|
11
10
|
}
|
|
12
11
|
return null;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
//#endregion
|
|
16
|
-
export { getExtraMethod };
|
|
14
|
+
export { getExtraMethod };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/utilities/metadata.ts
|
|
2
2
|
const METADATA_KEY = "rx:metadata";
|
|
3
3
|
function parseMetadataFromProps(props) {
|
|
4
|
-
return { childType: props.childType };
|
|
4
|
+
return { childType: props.$type ?? props.childType };
|
|
5
5
|
}
|
|
6
6
|
function getMetadata(object) {
|
|
7
7
|
return Reflect.getMetadata(METADATA_KEY, object) ?? null;
|
|
@@ -10,8 +10,10 @@ function setMetadata(object, value) {
|
|
|
10
10
|
Reflect.defineMetadata(METADATA_KEY, value, object);
|
|
11
11
|
}
|
|
12
12
|
function setMetadataFromProps(object, props) {
|
|
13
|
-
setMetadata(object,
|
|
13
|
+
setMetadata(object, {
|
|
14
|
+
...getMetadata(object),
|
|
15
|
+
...parseMetadataFromProps(props)
|
|
16
|
+
});
|
|
14
17
|
}
|
|
15
|
-
|
|
16
18
|
//#endregion
|
|
17
|
-
export { getMetadata, setMetadataFromProps };
|
|
19
|
+
export { getMetadata, setMetadata, setMetadataFromProps };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getMetadata, setMetadata } from "./metadata.mjs";
|
|
2
|
+
import { insertBefore, removeChild } from "./children.mjs";
|
|
3
|
+
//#region src/utilities/suspend.ts
|
|
4
|
+
/**
|
|
5
|
+
* Hide an instance by removing it from its parent and storing its parent and next sibling in metadata.
|
|
6
|
+
*/
|
|
7
|
+
function hideInstance(instance) {
|
|
8
|
+
const parent = instance.get_parent();
|
|
9
|
+
if (!parent) return;
|
|
10
|
+
let meta = getMetadata(instance);
|
|
11
|
+
meta ??= {};
|
|
12
|
+
meta.suspenseState = {
|
|
13
|
+
parent,
|
|
14
|
+
nextSibling: instance.get_next_sibling()
|
|
15
|
+
};
|
|
16
|
+
setMetadata(instance, meta);
|
|
17
|
+
removeChild(parent, instance);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Restore an instance by inserting it after its stored next sibling in its stored parent.
|
|
21
|
+
*/
|
|
22
|
+
function unhideInstance(instance) {
|
|
23
|
+
let meta = getMetadata(instance);
|
|
24
|
+
if (!meta?.suspenseState) return;
|
|
25
|
+
const { parent, nextSibling } = meta.suspenseState;
|
|
26
|
+
insertBefore(parent, instance, nextSibling);
|
|
27
|
+
if (meta) delete meta.suspenseState;
|
|
28
|
+
setMetadata(instance, meta);
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { hideInstance, unhideInstance };
|
package/dist/utilities/type.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peachy/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Run GJS applications with react",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Angelo Verlain <hey@vixalien.com>",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"tsconfig.json"
|
|
10
|
+
],
|
|
5
11
|
"main": "./dist/index.mjs",
|
|
6
12
|
"exports": {
|
|
7
13
|
".": {
|
|
@@ -14,26 +20,21 @@
|
|
|
14
20
|
},
|
|
15
21
|
"./tsconfig": "./tsconfig.json"
|
|
16
22
|
},
|
|
17
|
-
"author": "Angelo Verlain <hey@vixalien.com>",
|
|
18
23
|
"dependencies": {
|
|
19
|
-
"@peachy/types": "^
|
|
24
|
+
"@peachy/types": "^2026.3.10",
|
|
20
25
|
"react": "^19.2.4",
|
|
21
26
|
"react-reconciler": "^0.33.0",
|
|
22
27
|
"reflect-metadata": "^0.2.2",
|
|
23
|
-
"@peachy/core": "0.0.
|
|
28
|
+
"@peachy/core": "0.0.12",
|
|
29
|
+
"@peachy/polyfills": "0.0.12"
|
|
24
30
|
},
|
|
25
31
|
"devDependencies": {
|
|
26
|
-
"@types/node": "^25.
|
|
27
|
-
"@types/react": "^19.2.
|
|
32
|
+
"@types/node": "^25.3.5",
|
|
33
|
+
"@types/react": "^19.2.14",
|
|
28
34
|
"@types/react-reconciler": "^0.33.0",
|
|
29
|
-
"tsdown": "0.
|
|
35
|
+
"tsdown": "0.21.0",
|
|
30
36
|
"typescript": "^5.9.3"
|
|
31
37
|
},
|
|
32
|
-
"files": [
|
|
33
|
-
"dist",
|
|
34
|
-
"tsconfig.json"
|
|
35
|
-
],
|
|
36
|
-
"license": "MIT",
|
|
37
38
|
"scripts": {
|
|
38
39
|
"build": "tsdown"
|
|
39
40
|
},
|
package/tsconfig.json
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
"extends": "@peachy/core/tsconfig",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"jsx": "react-jsx",
|
|
5
|
-
"jsxImportSource": "@peachy/react"
|
|
5
|
+
"jsxImportSource": "@peachy/react"
|
|
6
6
|
},
|
|
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/
|
|
10
|
+
"./node_modules/@peachy/core/node_modules/@peachy/plugin-resources/src/modules.d.ts",
|
|
11
|
+
"./node_modules/@peachy/core/node_modules/@peachy/plugin-css/src/modules.d.ts",
|
|
11
12
|
// when installed via npm/pnpm
|
|
12
13
|
"../types/types/index.d.ts",
|
|
13
|
-
"../plugin-resources/src/
|
|
14
|
-
"
|
|
15
|
-
|
|
14
|
+
"../plugin-resources/src/modules.d.ts",
|
|
15
|
+
"../plugin-css/src/modules.d.ts",
|
|
16
|
+
"${configDir}/src/**/*"
|
|
17
|
+
]
|
|
16
18
|
}
|