import { createWidget } from "@engine/api"; import { clone, SetOptionalPropertyFrom } from "@granity/helpers"; import { forwardRef, ForwardRefRenderFunction } from "react"; import { DefaultGameWidgetProps, GameWidgetComponent, GameWidgetModule, WidgetOptions, } from "../gameTypes"; import gameWidgetMapper from "../mappers/gameWidgetMapper"; /** * A function helping you creating a Game widget. * */ export default ( widget: SetOptionalPropertyFrom, "type"> ) => { const clonedWidget = clone(widget); const widgetModule = gameWidgetMapper(clonedWidget); if ("hasRef" in widgetModule && widgetModule.hasRef) { (widgetModule.component as GameWidgetComponent) = forwardRef( widget.component as ForwardRefRenderFunction ) as GameWidgetComponent; } return createWidget>(widgetModule); };