-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Make the Preview Menu extensible #31984
Conversation
e25140c
to
0a205de
Compare
Thanks for working on this! It's non-trivial to test, I got this far: ... but have to move on to some other tasks, so can't explore the intricacies too deeply. For that reason, thank you for including great screenshots as well. High level, I still think it makes a lot of sense for us to allow this menu to be extensible, so that plugins can add custom preview interfaces exactly like what is outlined for AMP. Looking at the current API, though, it seems like this would plugins to add anything there — not just menu items, which I fear is likely to be abused to show all sorts of irrelevant things. Is there any way we can rein in the API to only allow menu items in a very specific format? Ideally plugin developers should not have to know about which components to use to make a menu item look correctly like a menu item. Considering we can always expand this in the future, what is the least we can start with? Label & onclick action? Label & external link action? Do we need to allow custom icons & subgroups? The less we can start with, the better we'll know where to improve and expand upon it in future iterations. What do you think? |
@jasmussen, should we follow the same path as with the By the way, isn't the name "preview" too generic? |
I like the sound of that. While as noted I think there's a place for this feature, I like for APIs to be mostly agnostic in their implementation, so if we were to theoretically move the preview dropdown somewhere else in the interface, the API would still work and make sense.
Good point, especially as I've seen recent conversations about renaming it to just "View". |
9189a38
to
f4e401b
Compare
As per the review feedback, there seems to be no need to expose the Preview menu item fill at all. It should be sufficient to expose the title, icon, and click handler. This way we "protect" the Preview menu drop-down from injecting arbitrary, irrelevant elements into it. Thanks to that, the entire custom previews implementation could be simplified. It's now mostly contained within the `PluginPreview` component itself.
@gziolo @jasmussen Thanks for your feedback!
I like this approach, too. I think having a similar API as the
I haven't done anything about this, yet. Do you think |
Note that the PR description has been updated to reflect the changes introduced in f949647 (i.e. that there is now just one new component, the |
2236783
to
0301e1d
Compare
Is it planned to add more devices? |
Noting here that we are discussing a general strategy for making the editor interface extensible in #37448. |
First pass at continuing work on extending preview menu in editors. The work is entirely copied from #36119, which includes work from #31984 Tony Arcangelini <[email protected]> Piotr Delawski <[email protected]>
Implemented with #64644. Thank you for your contribution. |
Description
This PR introduces a new
<PluginPreview>
component to the@wordpress/block-editor
package. It allows for defining a custom "Preview" menu item along with optional content that is rendered instead of theVisualEditor
.Thanks to that, plugin authors can extend the "Preview" menu and provide optional custom content previews.
This PR is based on #25430 proposed by @mreishus. It addresses @jorgefilipecosta's feedback pointing out that the new component added to
@wordpress/block-editor
should not depend on the@wordpress/edit-post
package.In the original implementation we were using a
deviceType
and asetDeviceType
action from thecore/edit-post
store. Right now, they are passed to the slot fill by theVisualEditorOrPluginPreview
component (that lives in the@wordpress/edit-post
package).There's one additional difference between this PR and the original one. The custom preview (
PluginPreview
component children) is optional now. If there is no custom preview provided, selecting a custom "Preview" menu item will not affect theVisualEditor
. Instead, plugin authors may rely on theonClick
event handler for providing custom functionality. This may be very helpful in the case of plugins that provide external previews (e.g. paywalled content, search results, or AMP preview as proposed in ampproject/amp-wp#5943).How has this been tested?
Screenshots
Types of changes
New feature (non-breaking change which adds functionality)
Fixes #25309
Relates to Automattic/wp-calypso#42896
Relates to ampproject/amp-wp#5943
Checklist:
*.native.js
files for terms that need renaming or removal).