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.
| Comment | File | Size | Author |
|---|
Comments
Comment #2
dsnopekComment #3
dsnopekComment #4
dsnopekHere's some related core issues:
Comment #5
tim.plunkett#3 might be accomplished via #2999580: Make blocks appear in the layout builder without saving formatter settings
Comment #6
shadcn commentedI'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:
layout_builder.add_blockform and replace with a custom controller.layout_builder_update_blockform is enhanced with a preview button and a live preview library.Here's a quick gif:
Let's test 👍(Note: this does not work with content fields for now)
Comment #7
dsnopekUpdating issue summary with some screenshots from Panopoly 1.x to clarify the different previews
Comment #8
dsnopekI 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.
Comment #9
dsnopekI 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.
Comment #10
dsnopekMake the title sound more plan-y and less implement-y
Comment #11
dsnopekAdded links to the implementation issues in the issue summary
Comment #12
dsnopekHiding 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. :-)
Comment #13
dsnopekAll 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 :-)
Comment #15
thestevelavigne commentedIt 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?
Comment #16
dsnopek@Nugg: Please open a new issue about that! There's still a few bugs in the live previews provided by panopoly_magic