@ringozz/react-godot 4.7.2-614 → 4.7.2-616
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 +327 -327
- package/package.json +5 -5
- package/src/index.ts +58 -58
- package/src/react-fiber.ts +331 -320
- package/src/react-hooks.ts +164 -164
- package/src/react-jsx.ts +45 -45
package/src/react-hooks.ts
CHANGED
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
/**********************************************************************
|
|
2
|
-
Copyright (c) Vladimir Davidovich. All rights reserved.
|
|
3
|
-
***********************************************************************/
|
|
4
|
-
|
|
5
|
-
import type { Signal } from '@ringozz/godot';
|
|
6
|
-
import type { Node } from '@ringozz/godot/Node';
|
|
7
|
-
import type { Object as Instance } from '@ringozz/godot/Object';
|
|
8
|
-
import { PropertyTweener } from '@ringozz/godot/PropertyTweener';
|
|
9
|
-
import { Tween, type EaseType, type TransitionType } from '@ringozz/godot/Tween';
|
|
10
|
-
import type React from 'react';
|
|
11
|
-
import { useEffect, useMemo, useRef } from 'react';
|
|
12
|
-
import { toValueType } from '@ringozz/godot/runtime';
|
|
13
|
-
|
|
14
|
-
// Tween/PropertyTweener are only type-used here; value-reference them so their
|
|
15
|
-
// `_R` class registration isn't tree-shaken (otherwise createTween's wrapper
|
|
16
|
-
// falls back to an ancestor class and loses pause/play/tweenProperty).
|
|
17
|
-
void Tween;
|
|
18
|
-
void PropertyTweener;
|
|
19
|
-
|
|
20
|
-
export function useMutableCallback<T>(fn: T): React.RefObject<T> {
|
|
21
|
-
const ref = useRef<T>(fn);
|
|
22
|
-
useEffect(() => void (ref.current = fn), [fn]);
|
|
23
|
-
return ref;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function useSignal<T extends (...args: any[]) => any>(signal: Signal<T>, handler: T): void {
|
|
27
|
-
const ref = useMutableCallback(handler);
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
const fn = ((...args: any[]) => ref.current(...args)) as T;
|
|
30
|
-
signal.connect(fn);
|
|
31
|
-
return () => signal.disconnect(fn);
|
|
32
|
-
// do not specify 'signal' dependency, because it changes often.
|
|
33
|
-
// specify invariant contents instead.
|
|
34
|
-
/* oxlint-disable-next-line react-hooks/exhaustive-deps */
|
|
35
|
-
}, [signal.getObjectId(), signal.getName()]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ---- useTween: tween-as-prop-value ----
|
|
39
|
-
//
|
|
40
|
-
// useTween(create, deps) returns [spring, tweenRef]. `spring` holds one
|
|
41
|
-
// value-assigner per `to` key — a plain function spread onto the node
|
|
42
|
-
// (`<Node3D {...spring} />`). Instance.assign (C++) treats any function on a
|
|
43
|
-
// non-signal prop as a value-assigner and invokes it with (node, nativeName);
|
|
44
|
-
// each contributes its own prop's tweener to one shared native Tween created on
|
|
45
|
-
// the first invocation. `tweenRef.current` is that Tween (null until mounted).
|
|
46
|
-
// Re-rendering with the same deps keeps the same assigners (the reconciler's
|
|
47
|
-
// identity diff drops them, so nothing restarts); changing deps creates a new
|
|
48
|
-
// tween (the previous one is killed).
|
|
49
|
-
|
|
50
|
-
// Tweenable goal values: scalars and value-type tuples. `GodotVar` (the base of
|
|
51
|
-
// *every* Godot object) is deliberately NOT a member — `useTween` always wraps
|
|
52
|
-
// goals through `toValueType`, so callers pass plain numbers/tuples, and
|
|
53
|
-
// including `GodotVar` would wrongly admit signals/`Node` refs/object props.
|
|
54
|
-
//
|
|
55
|
-
// When the caller passes a node instance type (e.g. `useTween<Node3D>`), `to`
|
|
56
|
-
// /`from` are contextually typed against that node's settable props, so each
|
|
57
|
-
// array goal infers as the property's value-type tuple (Vector3, Basis, …). A
|
|
58
|
-
// bare `useTween(...)` call keeps the loose behavior below (`number[]` goals).
|
|
59
|
-
type TweenValue = number | number[] | number[][];
|
|
60
|
-
|
|
61
|
-
// Settable props whose value is a tweenable goal (`number`/value-type tuple).
|
|
62
|
-
// Signals, `Node` refs and other Godot objects are not `TweenValue`s, so they
|
|
63
|
-
// never leak into `spring` (`{...spring}` stays JSX-spreadable). Mapping over
|
|
64
|
-
// `keyof T` lets `to` be contextually typed with the node's value-type tuples.
|
|
65
|
-
type TweenableProps<T> = {
|
|
66
|
-
[K in keyof T as T[K] extends TweenValue ? K : never]: T[K];
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export interface TweenConfig {
|
|
70
|
-
/** Seconds (default 1). */
|
|
71
|
-
duration?: number;
|
|
72
|
-
/** Tween.setTrans — the default for the tween's tweeners. */
|
|
73
|
-
transition?: TransitionType;
|
|
74
|
-
/** Tween.setEase — the default for the tween's tweeners. */
|
|
75
|
-
ease?: EaseType;
|
|
76
|
-
/** PropertyTweener.setCustomInterpolator — a [0,1]→[0,1] easing function. */
|
|
77
|
-
easing?: (t: number) => number;
|
|
78
|
-
/** Tween.setSpeedScale. */
|
|
79
|
-
speedScale?: number;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface TweenProps<P extends Record<string, unknown> = Record<string, TweenValue>> {
|
|
83
|
-
/** Start values, applied on the first build (mount) before animating to `to`. */
|
|
84
|
-
from?: Partial<P>;
|
|
85
|
-
/** Target values — one assigner is returned per key. */
|
|
86
|
-
to: P;
|
|
87
|
-
config?: TweenConfig;
|
|
88
|
-
/** Seconds; per-tweener PropertyTweener.setDelay. */
|
|
89
|
-
delay?: number;
|
|
90
|
-
/** Tween.setLoops (0 = infinite). */
|
|
91
|
-
loops?: number;
|
|
92
|
-
/** Snap to `to` instead of animating. */
|
|
93
|
-
immediate?: boolean;
|
|
94
|
-
onStart?: () => void;
|
|
95
|
-
/** Fires on natural completion only (Godot's `finished`); kills/unmount don't fire it. */
|
|
96
|
-
onFinished?: () => void;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export type Spring<P extends Record<string, unknown>> = { [K in keyof P]: P[K] };
|
|
100
|
-
|
|
101
|
-
// tweenProperty/set reject generic JS arrays, so array goals are reconstructed
|
|
102
|
-
// as the property's value type by `toValueType` (resolves the node's
|
|
103
|
-
// property type and returns a GodotVar carrier the `_C` tween path unwraps;
|
|
104
|
-
// non-array goals pass through unchanged).
|
|
105
|
-
|
|
106
|
-
function makeSpring<P extends Record<string, unknown>>(
|
|
107
|
-
tweenRef: { current: Tween | null },
|
|
108
|
-
props: TweenProps<P>,
|
|
109
|
-
): Spring<P> {
|
|
110
|
-
const config = props.config ?? {};
|
|
111
|
-
const spring = {} as Spring<P>;
|
|
112
|
-
let started = false;
|
|
113
|
-
let applyFrom = false;
|
|
114
|
-
|
|
115
|
-
for (const [key, value] of Object.entries(props.to)) {
|
|
116
|
-
const fromValue = props.from?.[key];
|
|
117
|
-
const assigner = (node: Instance, native: string) => {
|
|
118
|
-
if (props.immediate) {
|
|
119
|
-
tweenRef.current?.kill();
|
|
120
|
-
tweenRef.current = null;
|
|
121
|
-
node.set(native, toValueType(node, native, value));
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (!started) {
|
|
125
|
-
started = true;
|
|
126
|
-
applyFrom = tweenRef.current === null; // first build (mount) ⇒ apply `from`
|
|
127
|
-
tweenRef.current?.kill();
|
|
128
|
-
const t = (node as unknown as Node).createTween();
|
|
129
|
-
tweenRef.current = t;
|
|
130
|
-
if (config.transition !== undefined) t.setTrans(config.transition);
|
|
131
|
-
if (config.ease !== undefined) t.setEase(config.ease);
|
|
132
|
-
if (config.speedScale !== undefined) t.setSpeedScale(config.speedScale);
|
|
133
|
-
if (props.loops !== undefined) t.setLoops(props.loops);
|
|
134
|
-
if (props.onFinished) t.finished.connect(props.onFinished);
|
|
135
|
-
t.bindNode(node as unknown as Node);
|
|
136
|
-
t.setParallel(true);
|
|
137
|
-
props.onStart?.();
|
|
138
|
-
}
|
|
139
|
-
const tw = tweenRef.current!.tweenProperty(node, native, toValueType(node, native, value), config.duration ?? 1);
|
|
140
|
-
if (applyFrom && fromValue !== undefined) tw.from(toValueType(node, native, fromValue));
|
|
141
|
-
if (props.delay !== undefined) tw.setDelay(props.delay);
|
|
142
|
-
if (config.easing) tw.setCustomInterpolator(config.easing);
|
|
143
|
-
};
|
|
144
|
-
spring[key as keyof P] = assigner as unknown as P[keyof P];
|
|
145
|
-
}
|
|
146
|
-
return spring;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function useTween<
|
|
150
|
-
T extends Instance = any,
|
|
151
|
-
P extends Partial<TweenableProps<T>> = Partial<TweenableProps<T>>,
|
|
152
|
-
>(
|
|
153
|
-
create: () => TweenProps<P>,
|
|
154
|
-
deps: unknown[] = [],
|
|
155
|
-
): [Spring<P>, React.RefObject<Tween | null>] {
|
|
156
|
-
const tweenRef = useRef<Tween | null>(null);
|
|
157
|
-
// 'create' is intentionally re-evaluated via `deps`, not listed here.
|
|
158
|
-
/* oxlint-disable-next-line react-hooks/exhaustive-deps */
|
|
159
|
-
const spring = useMemo(() => makeSpring(tweenRef, create()), deps);
|
|
160
|
-
// No unmount kill: the tween is `createTween()`-bound to the node, so Godot
|
|
161
|
-
// kills it when the node exits the tree. A `useEffect` cleanup would also run
|
|
162
|
-
// on StrictMode's synthetic mount teardown and kill the just-created tween.
|
|
163
|
-
return [spring, tweenRef];
|
|
164
|
-
}
|
|
1
|
+
/**********************************************************************
|
|
2
|
+
Copyright (c) Vladimir Davidovich. All rights reserved.
|
|
3
|
+
***********************************************************************/
|
|
4
|
+
|
|
5
|
+
import type { Signal } from '@ringozz/godot';
|
|
6
|
+
import type { Node } from '@ringozz/godot/Node';
|
|
7
|
+
import type { Object as Instance } from '@ringozz/godot/Object';
|
|
8
|
+
import { PropertyTweener } from '@ringozz/godot/PropertyTweener';
|
|
9
|
+
import { Tween, type EaseType, type TransitionType } from '@ringozz/godot/Tween';
|
|
10
|
+
import type React from 'react';
|
|
11
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
12
|
+
import { toValueType } from '@ringozz/godot/runtime';
|
|
13
|
+
|
|
14
|
+
// Tween/PropertyTweener are only type-used here; value-reference them so their
|
|
15
|
+
// `_R` class registration isn't tree-shaken (otherwise createTween's wrapper
|
|
16
|
+
// falls back to an ancestor class and loses pause/play/tweenProperty).
|
|
17
|
+
void Tween;
|
|
18
|
+
void PropertyTweener;
|
|
19
|
+
|
|
20
|
+
export function useMutableCallback<T>(fn: T): React.RefObject<T> {
|
|
21
|
+
const ref = useRef<T>(fn);
|
|
22
|
+
useEffect(() => void (ref.current = fn), [fn]);
|
|
23
|
+
return ref;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useSignal<T extends (...args: any[]) => any>(signal: Signal<T>, handler: T): void {
|
|
27
|
+
const ref = useMutableCallback(handler);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const fn = ((...args: any[]) => ref.current(...args)) as T;
|
|
30
|
+
signal.connect(fn);
|
|
31
|
+
return () => signal.disconnect(fn);
|
|
32
|
+
// do not specify 'signal' dependency, because it changes often.
|
|
33
|
+
// specify invariant contents instead.
|
|
34
|
+
/* oxlint-disable-next-line react-hooks/exhaustive-deps */
|
|
35
|
+
}, [signal.getObjectId(), signal.getName()]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ---- useTween: tween-as-prop-value ----
|
|
39
|
+
//
|
|
40
|
+
// useTween(create, deps) returns [spring, tweenRef]. `spring` holds one
|
|
41
|
+
// value-assigner per `to` key — a plain function spread onto the node
|
|
42
|
+
// (`<Node3D {...spring} />`). Instance.assign (C++) treats any function on a
|
|
43
|
+
// non-signal prop as a value-assigner and invokes it with (node, nativeName);
|
|
44
|
+
// each contributes its own prop's tweener to one shared native Tween created on
|
|
45
|
+
// the first invocation. `tweenRef.current` is that Tween (null until mounted).
|
|
46
|
+
// Re-rendering with the same deps keeps the same assigners (the reconciler's
|
|
47
|
+
// identity diff drops them, so nothing restarts); changing deps creates a new
|
|
48
|
+
// tween (the previous one is killed).
|
|
49
|
+
|
|
50
|
+
// Tweenable goal values: scalars and value-type tuples. `GodotVar` (the base of
|
|
51
|
+
// *every* Godot object) is deliberately NOT a member — `useTween` always wraps
|
|
52
|
+
// goals through `toValueType`, so callers pass plain numbers/tuples, and
|
|
53
|
+
// including `GodotVar` would wrongly admit signals/`Node` refs/object props.
|
|
54
|
+
//
|
|
55
|
+
// When the caller passes a node instance type (e.g. `useTween<Node3D>`), `to`
|
|
56
|
+
// /`from` are contextually typed against that node's settable props, so each
|
|
57
|
+
// array goal infers as the property's value-type tuple (Vector3, Basis, …). A
|
|
58
|
+
// bare `useTween(...)` call keeps the loose behavior below (`number[]` goals).
|
|
59
|
+
type TweenValue = number | number[] | number[][];
|
|
60
|
+
|
|
61
|
+
// Settable props whose value is a tweenable goal (`number`/value-type tuple).
|
|
62
|
+
// Signals, `Node` refs and other Godot objects are not `TweenValue`s, so they
|
|
63
|
+
// never leak into `spring` (`{...spring}` stays JSX-spreadable). Mapping over
|
|
64
|
+
// `keyof T` lets `to` be contextually typed with the node's value-type tuples.
|
|
65
|
+
type TweenableProps<T> = {
|
|
66
|
+
[K in keyof T as T[K] extends TweenValue ? K : never]: T[K];
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export interface TweenConfig {
|
|
70
|
+
/** Seconds (default 1). */
|
|
71
|
+
duration?: number;
|
|
72
|
+
/** Tween.setTrans — the default for the tween's tweeners. */
|
|
73
|
+
transition?: TransitionType;
|
|
74
|
+
/** Tween.setEase — the default for the tween's tweeners. */
|
|
75
|
+
ease?: EaseType;
|
|
76
|
+
/** PropertyTweener.setCustomInterpolator — a [0,1]→[0,1] easing function. */
|
|
77
|
+
easing?: (t: number) => number;
|
|
78
|
+
/** Tween.setSpeedScale. */
|
|
79
|
+
speedScale?: number;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface TweenProps<P extends Record<string, unknown> = Record<string, TweenValue>> {
|
|
83
|
+
/** Start values, applied on the first build (mount) before animating to `to`. */
|
|
84
|
+
from?: Partial<P>;
|
|
85
|
+
/** Target values — one assigner is returned per key. */
|
|
86
|
+
to: P;
|
|
87
|
+
config?: TweenConfig;
|
|
88
|
+
/** Seconds; per-tweener PropertyTweener.setDelay. */
|
|
89
|
+
delay?: number;
|
|
90
|
+
/** Tween.setLoops (0 = infinite). */
|
|
91
|
+
loops?: number;
|
|
92
|
+
/** Snap to `to` instead of animating. */
|
|
93
|
+
immediate?: boolean;
|
|
94
|
+
onStart?: () => void;
|
|
95
|
+
/** Fires on natural completion only (Godot's `finished`); kills/unmount don't fire it. */
|
|
96
|
+
onFinished?: () => void;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type Spring<P extends Record<string, unknown>> = { [K in keyof P]: P[K] };
|
|
100
|
+
|
|
101
|
+
// tweenProperty/set reject generic JS arrays, so array goals are reconstructed
|
|
102
|
+
// as the property's value type by `toValueType` (resolves the node's
|
|
103
|
+
// property type and returns a GodotVar carrier the `_C` tween path unwraps;
|
|
104
|
+
// non-array goals pass through unchanged).
|
|
105
|
+
|
|
106
|
+
function makeSpring<P extends Record<string, unknown>>(
|
|
107
|
+
tweenRef: { current: Tween | null },
|
|
108
|
+
props: TweenProps<P>,
|
|
109
|
+
): Spring<P> {
|
|
110
|
+
const config = props.config ?? {};
|
|
111
|
+
const spring = {} as Spring<P>;
|
|
112
|
+
let started = false;
|
|
113
|
+
let applyFrom = false;
|
|
114
|
+
|
|
115
|
+
for (const [key, value] of Object.entries(props.to)) {
|
|
116
|
+
const fromValue = props.from?.[key];
|
|
117
|
+
const assigner = (node: Instance, native: string) => {
|
|
118
|
+
if (props.immediate) {
|
|
119
|
+
tweenRef.current?.kill();
|
|
120
|
+
tweenRef.current = null;
|
|
121
|
+
node.set(native, toValueType(node, native, value));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (!started) {
|
|
125
|
+
started = true;
|
|
126
|
+
applyFrom = tweenRef.current === null; // first build (mount) ⇒ apply `from`
|
|
127
|
+
tweenRef.current?.kill();
|
|
128
|
+
const t = (node as unknown as Node).createTween();
|
|
129
|
+
tweenRef.current = t;
|
|
130
|
+
if (config.transition !== undefined) t.setTrans(config.transition);
|
|
131
|
+
if (config.ease !== undefined) t.setEase(config.ease);
|
|
132
|
+
if (config.speedScale !== undefined) t.setSpeedScale(config.speedScale);
|
|
133
|
+
if (props.loops !== undefined) t.setLoops(props.loops);
|
|
134
|
+
if (props.onFinished) t.finished.connect(props.onFinished);
|
|
135
|
+
t.bindNode(node as unknown as Node);
|
|
136
|
+
t.setParallel(true);
|
|
137
|
+
props.onStart?.();
|
|
138
|
+
}
|
|
139
|
+
const tw = tweenRef.current!.tweenProperty(node, native, toValueType(node, native, value), config.duration ?? 1);
|
|
140
|
+
if (applyFrom && fromValue !== undefined) tw.from(toValueType(node, native, fromValue));
|
|
141
|
+
if (props.delay !== undefined) tw.setDelay(props.delay);
|
|
142
|
+
if (config.easing) tw.setCustomInterpolator(config.easing);
|
|
143
|
+
};
|
|
144
|
+
spring[key as keyof P] = assigner as unknown as P[keyof P];
|
|
145
|
+
}
|
|
146
|
+
return spring;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function useTween<
|
|
150
|
+
T extends Instance = any,
|
|
151
|
+
P extends Partial<TweenableProps<T>> = Partial<TweenableProps<T>>,
|
|
152
|
+
>(
|
|
153
|
+
create: () => TweenProps<P>,
|
|
154
|
+
deps: unknown[] = [],
|
|
155
|
+
): [Spring<P>, React.RefObject<Tween | null>] {
|
|
156
|
+
const tweenRef = useRef<Tween | null>(null);
|
|
157
|
+
// 'create' is intentionally re-evaluated via `deps`, not listed here.
|
|
158
|
+
/* oxlint-disable-next-line react-hooks/exhaustive-deps */
|
|
159
|
+
const spring = useMemo(() => makeSpring(tweenRef, create()), deps);
|
|
160
|
+
// No unmount kill: the tween is `createTween()`-bound to the node, so Godot
|
|
161
|
+
// kills it when the node exits the tree. A `useEffect` cleanup would also run
|
|
162
|
+
// on StrictMode's synthetic mount teardown and kill the just-created tween.
|
|
163
|
+
return [spring, tweenRef];
|
|
164
|
+
}
|
package/src/react-jsx.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/**********************************************************************
|
|
2
|
-
Copyright (c) Vladimir Davidovich. All rights reserved.
|
|
3
|
-
***********************************************************************/
|
|
4
|
-
|
|
5
|
-
import { jsxDEV as reactJsxDEV } from 'react/jsx-dev-runtime';
|
|
6
|
-
import type * as ReactJSX from 'react/jsx-runtime';
|
|
7
|
-
import { Fragment, jsx as reactJsx, jsxs as reactJsxs } from 'react/jsx-runtime';
|
|
8
|
-
import type { ComponentProps, GodotConstructor } from './react-types.ts';
|
|
9
|
-
import { GodotVar } from '@ringozz/godot/runtime';
|
|
10
|
-
|
|
11
|
-
export function jsx(type: any, props?: any, key?: any) {
|
|
12
|
-
return reactJsx(GodotVar.isPrototypeOf(type) ? type.name : type, props, key);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function jsxs(type: any, props?: any, key?: any) {
|
|
16
|
-
return reactJsxs(GodotVar.isPrototypeOf(type) ? type.name : type, props, key);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function jsxDEV(type: any, props?: any, key?: any, isStatic?: any, source?: any, self?: any) {
|
|
20
|
-
return reactJsxDEV(GodotVar.isPrototypeOf(type) ? type.name : type, props, key, isStatic, source, self);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { Fragment };
|
|
24
|
-
|
|
25
|
-
// JSX namespace augmentation: these types are the public JSX contract for the
|
|
26
|
-
// `@ringozz/react-godot/jsx-runtime` import source, consumed by TypeScript in
|
|
27
|
-
// consumer files. They are intentionally not referenced within this module.
|
|
28
|
-
/* oxlint-disable no-unused-vars */
|
|
29
|
-
declare module '@ringozz/react-godot/jsx-runtime' {
|
|
30
|
-
export namespace JSX {
|
|
31
|
-
interface IntrinsicAttributes extends ReactJSX.JSX.IntrinsicAttributes { }
|
|
32
|
-
interface IntrinsicElements extends ReactJSX.JSX.IntrinsicElements { }
|
|
33
|
-
interface Element extends ReactJSX.JSX.Element { }
|
|
34
|
-
|
|
35
|
-
type ElementType =
|
|
36
|
-
| ReactJSX.JSX.ElementType
|
|
37
|
-
| GodotConstructor;
|
|
38
|
-
|
|
39
|
-
type LibraryManagedAttributes<C, P> =
|
|
40
|
-
C extends GodotConstructor
|
|
41
|
-
? ComponentProps<C>
|
|
42
|
-
: ReactJSX.JSX.LibraryManagedAttributes<C, P>;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/* oxlint-enable no-unused-vars */
|
|
1
|
+
/**********************************************************************
|
|
2
|
+
Copyright (c) Vladimir Davidovich. All rights reserved.
|
|
3
|
+
***********************************************************************/
|
|
4
|
+
|
|
5
|
+
import { jsxDEV as reactJsxDEV } from 'react/jsx-dev-runtime';
|
|
6
|
+
import type * as ReactJSX from 'react/jsx-runtime';
|
|
7
|
+
import { Fragment, jsx as reactJsx, jsxs as reactJsxs } from 'react/jsx-runtime';
|
|
8
|
+
import type { ComponentProps, GodotConstructor } from './react-types.ts';
|
|
9
|
+
import { GodotVar } from '@ringozz/godot/runtime';
|
|
10
|
+
|
|
11
|
+
export function jsx(type: any, props?: any, key?: any) {
|
|
12
|
+
return reactJsx(GodotVar.isPrototypeOf(type) ? type.name : type, props, key);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function jsxs(type: any, props?: any, key?: any) {
|
|
16
|
+
return reactJsxs(GodotVar.isPrototypeOf(type) ? type.name : type, props, key);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function jsxDEV(type: any, props?: any, key?: any, isStatic?: any, source?: any, self?: any) {
|
|
20
|
+
return reactJsxDEV(GodotVar.isPrototypeOf(type) ? type.name : type, props, key, isStatic, source, self);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { Fragment };
|
|
24
|
+
|
|
25
|
+
// JSX namespace augmentation: these types are the public JSX contract for the
|
|
26
|
+
// `@ringozz/react-godot/jsx-runtime` import source, consumed by TypeScript in
|
|
27
|
+
// consumer files. They are intentionally not referenced within this module.
|
|
28
|
+
/* oxlint-disable no-unused-vars */
|
|
29
|
+
declare module '@ringozz/react-godot/jsx-runtime' {
|
|
30
|
+
export namespace JSX {
|
|
31
|
+
interface IntrinsicAttributes extends ReactJSX.JSX.IntrinsicAttributes { }
|
|
32
|
+
interface IntrinsicElements extends ReactJSX.JSX.IntrinsicElements { }
|
|
33
|
+
interface Element extends ReactJSX.JSX.Element { }
|
|
34
|
+
|
|
35
|
+
type ElementType =
|
|
36
|
+
| ReactJSX.JSX.ElementType
|
|
37
|
+
| GodotConstructor;
|
|
38
|
+
|
|
39
|
+
type LibraryManagedAttributes<C, P> =
|
|
40
|
+
C extends GodotConstructor
|
|
41
|
+
? ComponentProps<C>
|
|
42
|
+
: ReactJSX.JSX.LibraryManagedAttributes<C, P>;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/* oxlint-enable no-unused-vars */
|