diff --git a/packages/app-page-builder/src/plugins/PbEditorPageElementPlugin.tsx b/packages/app-page-builder/src/plugins/PbEditorPageElementPlugin.tsx index ba8f4247c5f..7c9e065edee 100644 --- a/packages/app-page-builder/src/plugins/PbEditorPageElementPlugin.tsx +++ b/packages/app-page-builder/src/plugins/PbEditorPageElementPlugin.tsx @@ -1,8 +1,10 @@ import type { PbEditorPageElementPlugin as BasePbEditorPageElementPlugin } from "~/types"; +import type { Renderer } from "@webiny/app-page-builder-elements/types"; + import { legacyPluginToReactComponent } from "@webiny/app/utils"; -export const PbEditorPageElementPlugin = legacyPluginToReactComponent< - Pick< +export interface PbEditorPageElementPluginProps + extends Pick< BasePbEditorPageElementPlugin, | "elementType" | "toolbar" @@ -10,15 +12,24 @@ export const PbEditorPageElementPlugin = legacyPluginToReactComponent< | "target" | "settings" | "create" - | "render" | "canDelete" | "canReceiveChildren" | "onReceived" | "onChildDeleted" | "onCreate" | "renderElementPreview" - > ->({ - pluginType: "pb-editor-page-element", - componentDisplayName: "PbEditorPageElementPlugin" -}); + > { + renderer: Renderer; +} + +export const PbEditorPageElementPlugin = + legacyPluginToReactComponent({ + pluginType: "pb-editor-page-element", + componentDisplayName: "PbEditorPageElementPlugin", + mapProps: props => { + return { + ...props, + render: props.renderer + }; + } + }); diff --git a/packages/app-page-builder/src/plugins/PbRenderElementPlugin.tsx b/packages/app-page-builder/src/plugins/PbRenderElementPlugin.tsx index cedbadab567..90e79829c9a 100644 --- a/packages/app-page-builder/src/plugins/PbRenderElementPlugin.tsx +++ b/packages/app-page-builder/src/plugins/PbRenderElementPlugin.tsx @@ -1,9 +1,17 @@ import type { PbRenderElementPlugin as BasePbRenderElementPlugin } from "~/types"; import { legacyPluginToReactComponent } from "@webiny/app/utils"; -export const PbRenderElementPlugin = legacyPluginToReactComponent< - Pick ->({ +interface PbRenderElementPluginProps extends Pick { + renderer: BasePbRenderElementPlugin["render"]; +} + +export const PbRenderElementPlugin = legacyPluginToReactComponent({ pluginType: "pb-render-page-element", - componentDisplayName: "PbRenderElementPlugin" + componentDisplayName: "PbRenderElementPlugin", + mapProps: props => { + return { + ...props, + render: props.renderer + }; + } }); diff --git a/packages/app-website/src/plugins/PbRenderElementPlugin.tsx b/packages/app-website/src/plugins/PbRenderElementPlugin.tsx index ffaa7fc5125..0c07c47c2ae 100644 --- a/packages/app-website/src/plugins/PbRenderElementPlugin.tsx +++ b/packages/app-website/src/plugins/PbRenderElementPlugin.tsx @@ -1,9 +1,17 @@ import type { PbRenderElementPlugin as BasePbRenderElementPlugin } from "@webiny/app-page-builder/types"; import { legacyPluginToReactComponent } from "@webiny/app/utils"; -export const PbRenderElementPlugin = legacyPluginToReactComponent< - Pick ->({ +interface PbRenderElementPluginProps extends Pick { + renderer: BasePbRenderElementPlugin["render"]; +} + +export const PbRenderElementPlugin = legacyPluginToReactComponent({ pluginType: "pb-render-page-element", - componentDisplayName: "PbRenderElementPlugin" + componentDisplayName: "PbRenderElementPlugin", + mapProps: props => { + return { + ...props, + render: props.renderer + }; + } }); diff --git a/packages/app/src/utils/legacyPluginToReactComponent.ts b/packages/app/src/utils/legacyPluginToReactComponent.ts index 3d93cc3915a..5da2e3f999c 100644 --- a/packages/app/src/utils/legacyPluginToReactComponent.ts +++ b/packages/app/src/utils/legacyPluginToReactComponent.ts @@ -1,16 +1,21 @@ import React from "react"; import { useRegisterLegacyPlugin } from "~/hooks/useRegisterLegacyPlugin"; -export interface LegacyPluginToReactComponentParams { +export interface LegacyPluginToReactComponentParams> { pluginType: string; componentDisplayName: string; + mapProps?: (props: TProps) => TProps; } export const legacyPluginToReactComponent = function >( - params: LegacyPluginToReactComponentParams + params: LegacyPluginToReactComponentParams ) { const Component: React.ComponentType = props => { - useRegisterLegacyPlugin({ ...props, type: params.pluginType }); + const plugin = Object.assign( + { type: params.pluginType }, + params.mapProps ? params.mapProps(props) : props + ); + useRegisterLegacyPlugin(plugin); return null; };