In Panopoly 1.x, we have FPP previews in a number of places...

Nr 1: When picking a new widget to add

When adding a new widget, there is a preview of what it could look like, rather than just the name.

There's actually a system where a CTools plugin or FPP can provide default data or an image for the preview too.

See the implementation issue: #3073658: Implement preview when choosing a block to add in layout_builder

Nr 2: Preview of the widget in the layout

After adding the widget, it'll be shown in the IPE as a preview of it's content.

Nr 3: Live preview of settings changes while editing widget

While editing a block, in a frame next to the controls, you can see a live preview of the block as you change it's settings.

See the implementation issue: #3072796: Implement live preview while editing block

How to achieve in Drupal 8

Of these, we get #2 in Layout Builder already - so that's done.

However, we don't get #1 or #3. How can we get those? Are there any core issues about them?

One of the problems with #3 is that the settings tray is so small, so there isn't anywhere we can put the preview. Perhaps the preview could be rendered right into the layout, same as #2, but updated in real time? The other idea I had, was that perhaps the settings tray could expand the whole width of the screen, and then we would have space to put the preview in there.

For #1, we'll probably want to implement a system where the block can say what it's contentless preview should look like. See #2484843: Allow widgets to control how their "example" is rendered on the "Add content" dialog (including using a static image rather than rendering) for details about how that works in Panopoly 1.x.

Let's start with some research, brainstorming and experimentation!

We can break this out into a couple issues, if necessary, once we have a concrete plan.

Comments

dsnopek created an issue. See original summary.

dsnopek’s picture

Issue summary: View changes
dsnopek’s picture

Issue summary: View changes
tim.plunkett’s picture

shadcn’s picture

Status: Active » Needs review
StatusFileSize
new5 MB
new10.56 KB

I've been looking into this for a while now. I've tested a few core patches and tried some other contrib solutions. I like the direction that @tim.plunkett implemented in #2999580: Make blocks appear in the layout builder without saving formatter settings.

Attached is a proof-of-concept patch (for #1 and #3) for the panopoly_magic module.

This patch contains suggestions from @tedbow in #6.

Here's how it works:

  1. We take over the layout_builder.add_block form and replace with a custom controller.
  2. When you click on a block to add to the layout builder, instead of showing the configure form, we programmatically insert the block into the layout builder first, then opens the configuration form.
  3. For live preview, the layout_builder_update_block form is enhanced with a preview button and a live preview library.
  4. On preview, the configuration for the block is updated, but not the layout temp storage. This allows previewing without updating the actual layout until the user clicks update.
  5. This allows block to be added, configured and previewed without affecting the layout like we had in Panopoly 1.x
  6. Config validation on previewing still works

Here's a quick gif:

Preview

Let's test 👍(Note: this does not work with content fields for now)

dsnopek’s picture

Issue summary: View changes
StatusFileSize
new88.87 KB
new144.75 KB
new144.68 KB

Updating issue summary with some screenshots from Panopoly 1.x to clarify the different previews

dsnopek’s picture

I tested @arshadcn's patch in #6 - it's awesome!

The only issue I noticed is that edits in the WYSIWYG don't seem to trigger the preview to update. We had support for that in Panopoly 1.x, but it was specific to TinyMCE - we'll need to implement something similar to for CKEditor.

However, the main reason for my comment is to clarify that the patch in #6 is only addressing preview nr 3 from the issue summary. We still don't have a plan for how to address nr 1, which is showing a visual of the widget when selecting what to add, rather than simply showing a list of widget names.

I think that suffers from the same "the tray is really small" problem. If it were even twice as wide, it could probably display the previews for everything (like Panopoly 1.x's "Automatic" mode). However, I don't see how it could do something like Panopoly 1.x's "Single" mode, which is what we switched to for better usability and performance - we'd need the full screen width to make that work.

dsnopek’s picture

Category: Task » Plan

I made a new issue #3072796: Implement live preview while editing block to continue developing @arshadcn's patch from #6. This can be a meta-issue to brainstorm what to do, and then we can make child issues for implementation. That way we aren't mixing ideas for solving preview nr 1, with review of the patch for preview nr 3.

dsnopek’s picture

Title: Implement (live) block preview in Layout Builder? » How to do (live) block preview in Layout Builder?

Make the title sound more plan-y and less implement-y

dsnopek’s picture

Issue summary: View changes

Added links to the implementation issues in the issue summary

dsnopek’s picture

Hiding patch now that this is a meta. Mostly for me, so I don't think this is the implementation issue and grab the patch from here again. :-)

dsnopek’s picture

Status: Needs review » Fixed

All types of the previews are now addressed in Panopoly!

There's still a little bit for nr 3 (handling reusable blocks), which I've made a new issue for:

#3116002: Live preview while editing REUSABLE blocks

But since that's all that remains, I'm going to close this issue :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

thestevelavigne’s picture

It appears that this does not handle FieldBlocks. When a FieldBlock is added via Layout Builder, it throws an Ajax error due to missing context. Any ideas on how to resolve this?

dsnopek’s picture

@Nugg: Please open a new issue about that! There's still a few bugs in the live previews provided by panopoly_magic