-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow the Preview Menu to be extendible by plugins #25430
Conversation
Issue: #25309 cc @westonruter |
|
||
Each of these takes 2 props, `deviceName`, and `children`. | ||
|
||
- `deviceName` - A string that serves as an internal identifier for your |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd keep this more generic and not assume it's a device.
Think e.g. AMP previews, social media previews, etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the external interface to use previewId
as a way to match the menu item with the content.
6690ad1
to
ff0d1e2
Compare
I'm not completely happy with:
|
37df129
to
f82031b
Compare
High level, this seems cool with me, and brings value to the preview dropdown. I'd love to see anything from AMP previews, to search result previews, to "behind paywall" previews in that dropdown, or whatever else developers might throw at it. With regards to the technical implementation, I'll defer to Riad and Mikael. |
Is this something we'd want in the full site editor as well, how does it map to the "complementary areas" abstraction. Do you have any thoughts on that @jorgefilipecosta |
My first try at this used Complementary Areas. (@youknowriad @jorgefilipecosta ) Here are the problems I found with it:
|
f82031b
to
fcc3670
Compare
I'm a developer working on the AMP plugin and this PR would be very helpful for us by getting rid of some of the hacks we have in place for rendering the AMP button in the editor post header settings. In our case however all we would want is to extend the preview menu by rendering our component within the |
const { deviceType } = useSelect( | ||
( select ) => ( { | ||
deviceType: select( | ||
'core/edit-post' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The block editor is a generic package that may be used outside WordPress, while the core/edit-post is a package to edit regular WordPress posts. I think we should avoid having the block-editor depending or querying data from core/edit-post.
I guess things will also not work as expected for edit-site scree where we don't have a core/edit-post module?
The device type is passed to the PreviewOptions as a prop. Could we rely on that prop instead?
Not directly related to this PR, but I think it makes sense to move the preview functionality under the WordPress/interface package. It is common to edit-post and edit-site. It has functionality like the singleEnableItems that can be used to store which preview is active. I guess the slot / fill here could also be abstracted as action item packages/interface/src/components/action-item/README.md.
Regarding the API, we are exposing PluginPreview, PluginPreviewMenuItem on the @wordpress/block-editor' package. As far as I know, the bock-editor does not expose slot & fills besides the ones used by blocks. All the plugin related API's are exposed under edit-post/edit-site. I guess for this case it may make sense too to make PluginPreview, PluginPreviewMenuItem under @wordpress/edit-site/edit-post. I guess we could implement the slot fills under WordPress/interface, and then on edit-site and edit-post, we would simply have wrappers that pass a specific scope. Similar to what we do for the sidebar and menu item slots.
The PreviewOptions component would have a prop for additional preview options that edit-site and edit-post use.
cc: @gziolo and @youknowriad In case you have a different option.
One thing that is a bit confusing in the whole Preview Menu is that: It's something that would need to be clarified first with designers to remove some confusion. Regarding the proposal, the whole idea makes sense to me. There some open questions like whether editor modes should be also extensible. What is the main factor that decides where to put new menu items? Should there be only one slot that renders the visual editor or code editor or something else registered by a plugin? It might be the most efficient to optimize usage by introducing a single component |
Two things:
We should gray those responsive preview menu items in that case. |
Any specific action items to push this PR forward? |
@pierlon hi! Would you have interest in helping this PR forward? |
@jorgefilipecosta To move forward, the file |
BTW, I don't have much time available to work on this; if you see it and want to run with it, feel free. |
The feedback left on this PR has been addressed in a new PR: #31984. |
Does it mean that this PR should get closed in favor of #31984? |
@mreishus, thank you for all the work done so far. Let's continue in the fresh PR that received some updates. |
Description
<PluginPreviewMenuItem>
creates new menu entries<PluginPreview>
registers what will render in the main area when that entry is selectedScreenshots
Concerns
<PluginPreview>
be able to access data stores withuseSelect
to get the info it needs? Or will that info need to be passed down by props?How has this been tested?
Creating this test plugin and using wp-env to run it:
Test plugin repository with webpack build included here.
Types of changes
Checklist: