@@ -2,21 +2,37 @@ import type * as Godot from "godot"
|
||||
import * as React from "react"
|
||||
|
||||
|
||||
export type Component<T extends Godot.Node<Godot.NodePathMap>> = React.FunctionComponent<Props<T>>
|
||||
export interface Component<T extends Godot.Node<Godot.NodePathMap>>
|
||||
extends React.FunctionComponent<Props<T>>, Prototype<T> {}
|
||||
|
||||
export type Props<T extends Godot.Node<Godot.NodePathMap>> = {
|
||||
readonly ref?: React.RefObject<T | null>
|
||||
} & {
|
||||
// biome-ignore lint/complexity/noBannedTypes: using Function here is completely fine
|
||||
[K in keyof T as T[K] extends Function ? never : K]?: T[K]
|
||||
}
|
||||
|
||||
export interface InstrinsicAttributes {
|
||||
export interface Prototype<T extends Godot.Node<Godot.NodePathMap>> {
|
||||
useRef(): React.RefObject<T | null>
|
||||
useUnsafeRef(): React.RefObject<T>
|
||||
}
|
||||
|
||||
export interface InstrinsicAttributes extends React.Attributes {
|
||||
readonly children?: React.ReactNode
|
||||
readonly name?: string
|
||||
}
|
||||
|
||||
export const Prototype: Prototype<any> = {
|
||||
useRef() { return React.useRef(null) },
|
||||
useUnsafeRef() { return React.useRef(null) },
|
||||
}
|
||||
|
||||
export const make = <T extends Godot.Node<Godot.NodePathMap>>(
|
||||
class_: new (...args: any[]) => T
|
||||
): Component<T> => {
|
||||
const f = (props: Props<T>) => React.createElement("element", { ...props, class: class_ })
|
||||
f.displayName = class_.name
|
||||
return f
|
||||
}
|
||||
): Component<T> => Object.setPrototypeOf(
|
||||
Object.assign(
|
||||
(props: Props<T>) => React.createElement("element", { ...props, class: class_ }),
|
||||
{ displayName: class_.name },
|
||||
),
|
||||
Prototype,
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ export const renderComponent: {
|
||||
} = (
|
||||
container: Node<NodePathMap>,
|
||||
component: React.FC<{}>,
|
||||
props?: React.Attributes,
|
||||
props?: Record<string, unknown>,
|
||||
): void => {
|
||||
const reconciler = Reconciler.make()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user