Skip to content
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

Add support to custom previews #186

Merged

Conversation

jcheringer
Copy link
Contributor

@jcheringer jcheringer commented Sep 21, 2022

Summary

On Crowdsignal, we have been using the Isolated Block Editor as the core of our New Editor Experience (NEX), where the users can build their Surveys (Projects) using blocks.

We offer a few distribution channels to the users to share their Projects with their audience.
Some of these distribution channels should appear on the user's page using specific designs like Popups or Cards.

Currently, the Isolated Block Editor only supports the standard devices: Desktop, Tablet, and Mobile.
We'd like to provide the users a way to preview these distribution channels from inside the Editor.

image

image

The suggested changes will allow:

  • Define whether to show the current preview inside an iframe
  • Customize the iframe wrapper styles
  • Disable the editor canvas animations

Testing Instructions

TBD

Comment on lines +39 to +45
const { assets } = useSelect( ( select ) => {
const settings = select( 'core/block-editor' ).getSettings();
return {
assets: settings.__unstableResolvedAssets,
};
}, [] );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is necessary to allow the injection of the styles into the iframe preview.
It was based on: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/block-preview/auto.js#L31-L38

@@ -89,6 +93,7 @@ const DEFAULT_STATE = {
patterns: [],
defaultPreferences: {},
allowApi: false,
disableCanvasAnimations: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For our Popup preview use case, we need to use a position: absolute on the preview.
We faced a weird behavior that seemed to be related to the animation library.
Some of the styling properties were kept when switching between previews, causing an issue when switching from an absolute positioned preview to one of the other.
Disabling the animations solved this issue.

Copy link
Contributor

@msurdi-a8c msurdi-a8c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. It also seems it does not break any existing behaviour, so 💯

I'll mention @johngodley here just so that he can give this a look whenever he's back, but I think this is safe to merge and release if you need it before he has a chance to check this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants