-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: create new PB element plugins (#4342)
- Loading branch information
Showing
10 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
packages/app-page-builder/src/plugins/PbEditorPageElementAdvancedSettingsPlugin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { PbEditorPageElementAdvancedSettingsPlugin as BasePbEditorPageElementAdvancedSettingsPlugin } from "~/types"; | ||
import { useRegisterLegacyPlugin } from "@webiny/app/hooks/useRegisterLegacyPlugin"; | ||
|
||
export interface PbEditorPageElementAdvancedSettingsPluginParams | ||
extends Pick<BasePbEditorPageElementAdvancedSettingsPlugin, "elementType" | "onSave"> { | ||
element: JSX.Element; | ||
} | ||
|
||
export const PbEditorPageElementAdvancedSettingsPlugin = ( | ||
props: PbEditorPageElementAdvancedSettingsPluginParams | ||
) => { | ||
useRegisterLegacyPlugin<BasePbEditorPageElementAdvancedSettingsPlugin>({ | ||
...props, | ||
render: () => props.element, | ||
type: "pb-editor-page-element-advanced-settings" | ||
}); | ||
|
||
return null; | ||
}; |
24 changes: 24 additions & 0 deletions
24
packages/app-page-builder/src/plugins/PbEditorPageElementPlugin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { PbEditorPageElementPlugin as BasePbEditorPageElementPlugin } from "~/types"; | ||
import { legacyPluginToReactComponent } from "@webiny/app/utils"; | ||
|
||
export const PbEditorPageElementPlugin = legacyPluginToReactComponent< | ||
Pick< | ||
BasePbEditorPageElementPlugin, | ||
| "elementType" | ||
| "toolbar" | ||
| "help" | ||
| "target" | ||
| "settings" | ||
| "create" | ||
| "render" | ||
| "canDelete" | ||
| "canReceiveChildren" | ||
| "onReceived" | ||
| "onChildDeleted" | ||
| "onCreate" | ||
| "renderElementPreview" | ||
> | ||
>({ | ||
pluginType: "pb-editor-page-element", | ||
componentDisplayName: "PbEditorPageElementPlugin" | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/app-page-builder/src/plugins/PbRenderElementPlugin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { PbRenderElementPlugin as BasePbRenderElementPlugin } from "~/types"; | ||
import { legacyPluginToReactComponent } from "@webiny/app/utils"; | ||
|
||
export const PbRenderElementPlugin = legacyPluginToReactComponent< | ||
Pick<BasePbRenderElementPlugin, "elementType" | "render"> | ||
>({ | ||
pluginType: "pb-render-page-element", | ||
componentDisplayName: "PbRenderElementPlugin" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
export * from "./PbPageLayoutPlugin"; | ||
export * from "./PbEditorPageElementAdvancedSettingsPlugin"; | ||
export * from "./PbRenderElementPlugin"; | ||
export * from "./PbEditorPageElementPlugin"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { PbRenderElementPlugin as BasePbRenderElementPlugin } from "@webiny/app-page-builder/types"; | ||
import { legacyPluginToReactComponent } from "@webiny/app/utils"; | ||
|
||
export const PbRenderElementPlugin = legacyPluginToReactComponent< | ||
Pick<BasePbRenderElementPlugin, "elementType" | "render"> | ||
>({ | ||
pluginType: "pb-render-page-element", | ||
componentDisplayName: "PbRenderElementPlugin" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./PbRenderElementPlugin"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useRef } from "react"; | ||
import { plugins } from "@webiny/plugins"; | ||
import { type Plugin } from "@webiny/plugins/types"; | ||
|
||
export function useRegisterLegacyPlugin<TPlugin extends Plugin>(plugin: TPlugin) { | ||
const pluginRegistered = useRef<boolean>(false); | ||
if (!pluginRegistered.current) { | ||
pluginRegistered.current = true; | ||
plugins.register(plugin); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from "react"; | ||
import { useRegisterLegacyPlugin } from "~/hooks/useRegisterLegacyPlugin"; | ||
|
||
export interface LegacyPluginToReactComponentParams { | ||
pluginType: string; | ||
componentDisplayName: string; | ||
} | ||
|
||
export const legacyPluginToReactComponent = function <TProps extends Record<string, any>>( | ||
params: LegacyPluginToReactComponentParams | ||
) { | ||
const Component: React.ComponentType<TProps> = props => { | ||
useRegisterLegacyPlugin({ ...props, type: params.pluginType }); | ||
return null; | ||
}; | ||
|
||
Component.displayName = params.componentDisplayName; | ||
|
||
return Component; | ||
}; |