WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.49k stars 4.19k forks source link

Allow extending editor preview in more ways #65005

Open simison opened 2 months ago

simison commented 2 months ago

What problem does this address?

In https://github.com/WordPress/gutenberg/pull/64644 we allowed extending the "preview dropdown" in a simple, fairly restrictive manner:

359590714-1330a6e3-f879-4a7b-8416-4d5abf436ba6

This is great for gathering feedback from real usage.

Extending the preview menu and canvas allow variety of publishing flows and tools, some examples:

An example of more complex preview capabilities from Substack done directly in the canvas:

https://github.com/WordPress/gutenberg/assets/87168/f5004855-fb42-4fe9-8fd0-e143a07e0191

Another simpler example from Jetpack Social, opening a modal for previewing:

Screenshot 2024-09-03 at 16 13 20

What is your proposed solution?

Allow extending pre-defined device sizes list

Extending existing devices list is simplest step, as the API could be purely declarative (size, icon, label) and hook into existing functionality:

Screenshot 2024-09-03 at 16 16 37

Examples might be slideshow presentations, TV screens, watches and other more exotic devices. WP is used to build not just websites.

Allow extending preview dropdown menu with multi-selection items

Selections would work in conjunction with existing device-size selectors, and work well with allowing extending editor canvas:

In above scenario you can preview post as a "free" or "paid" subscriber in various device sizes.

Some concerns come from having multiple plugins extend the menu in their own way, and how the menu should then look like. Do we force each plugin onto their own sub-menu or section? Should selections from one plugin clear selections from others? What are the defaults? How do we allow branding show up?

Allow adding multiple sections to preview dropdown menu

Expanding on above example, one could also introduce multiple devices/platforms that are separate from device sizes, such as "email" and "website":

2256164379-57da36ab-9fc7-41a5-9f0f-f5b2f079752d

Allow extending the editor canvas

Screenshot 2024-09-03 at 16 08 19

Extending canvas could be done in multiple ways. We could allow:

Allowing replacing the canvas brings up questions like do users expect to always be able edit what they see in the canvas, or can canvas work purely for "previewing" too?

fabiankaegy commented 2 months ago

Thank you for summarizing the needs here so well :) This would really go a long way!

mtias commented 2 months ago

Another example from core itself could be the Style Book—rendering on the canvas as a target. The cases where we render a pattern or a template part in isolation also seem relevant since elements like resize handlers could be part of the API.

gziolo commented 1 month ago

Another example from core itself could be the Style Book—rendering on the canvas as a target. The cases where we render a pattern or a template part in isolation also seem relevant since elements like resize handlers could be part of the API.

Interesting use cases. It makes me wonder whether we need to replicate the same SlotFill behavior we have for the sidebar. It feels like it would make perfect sense and could become an interesting option for extenders. I'm surprised we don't change the URL or store the visit to the Style Book in the browser history. Going back in the history 7-8 years, that was most likely the primary concern for opening the canvas for extenders.

skorasaurus commented 1 month ago

Some additional contexts to extend the preview window:

https://github.com/WordPress/gutenberg/issues/33578 https://github.com/WordPress/gutenberg/issues/27837 https://github.com/WordPress/gutenberg/issues/34655

A request to be able to remove the filter window if you wish - https://github.com/WordPress/gutenberg/issues/23126

bacoords commented 1 month ago

This is great! I'm a huge fan of "Allow extending the editor canvas"- some additional use cases: