Gutenberg block: WordPress Playground Demo#126
Merged
Conversation
Collaborator
|
Something tells me @jonathanbossenger, @westnz, and @juanmaguitar will love this. Thank you so much for making the web better @dawidurbanski! |
Contributor
|
This is indeed exciting. I will add it to my list of things to test out! |
|
This is amazing! 🥳 |
Collaborator
|
Thank you @dawidurbanski! I got it to work with |
johnhooks
pushed a commit
to johnhooks/playground-tools
that referenced
this pull request
Oct 11, 2024
## Description Adds support for previewing Gutenberg Pull Requests via the a `gutenberg-pr` query parameter: https://playground.wordpress.net/wordpress.html?gutenberg-pr=47739&url=/wp-admin/plugins.php?test=test My test PR: WordPress/gutenberg#47739 <img width="1149" alt="CleanShot 2023-02-03 at 19 33 17@2x" src="https://user-images.githubusercontent.com/205419/216681315-2af555c1-6249-4758-afe0-aa54b66c68a3.png"> ## Implementation The plugin bundle is downloaded from GitHub CI and installed by applying the following Blueprint: ```js function applyGutenbergPRSteps(prNumber: number): StepDefinition[] { return [ { step: 'mkdir', path: '/wordpress/pr', }, { step: 'writeFile', path: '/wordpress/pr/pr.zip', data: { resource: 'url', url: `/plugin-proxy?org=WordPress&repo=gutenberg&workflow=Build%20Gutenberg%20Plugin%20Zip&artifact=gutenberg-plugin&pr=${prNumber}`, caption: `Downloading Gutenberg PR ${prNumber}`, }, progress: { weight: 2, caption: `Applying Gutenberg PR ${prNumber}`, }, }, { step: 'unzip', zipPath: '/wordpress/pr/pr.zip', extractToPath: '/wordpress/pr', }, { step: 'installPlugin', pluginZipFile: { resource: 'vfs', path: '/wordpress/pr/gutenberg.zip', }, }, ]; } ``` Gutenberg PR preview from playground.wordpress.net can be embedded in other apps via an iframe. To implement your own PR previewer that pulls data from another repo, you'll need to expose an API endpoint to download the ZIP bundle and then plug it in the `writeFile` step above. Once you have that, here's how you'd apply a custom blueprint: ```ts import { startPlaygroundWeb } from "https://unpkg.com/@wp-playground/client@0.1.32/index.js"; startPlaygroundWeb({ iframe, remoteUrl: `https://playground.wordpress.net/remote.html`, blueprint: { steps: applyPR( 47339 ) } }) function applyPR( prNumber ) { return [ { step: 'mkdir', path: '/wordpress/pr', }, // ... ]; } ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
This pull request aims to demonstrate a possible usage of WordPress Playground inside a Gutenberg block.
Why?
We should make adding WordPress Playground to any WordPress site as easy as possible.
With this highly customizable block, users can embed WordPress Playground within their posts or pages content.
Possibility of adding files to the Playground instance from the code editor make this the easiest way of integrating Playground with your WordPress website.
The code editor can be editable for users on the front-end so it may serve a role of interactive tutorial/guide.
All features
wp_add_inline_scriptCaveats
"apiVersion": 2to prevent wrapping in iframe - it won't work inside another iframe for now - again Playground limitationNotes
Editcomponent),PlaygroundDemo.tsxdefinitely requires some work (to split it into multiple components),InspectorControlsinput fields fromonChangetoonBlurto prevent so many Playground inits,I developed this using the standard@wordpress/scriptspackage. I was unable to add this to the project custom build and nx sharedpackage.jsonso this PR is as is. Any contributions to make it work with this repo are welcomed,Testing Instructions
Two options
From zip
git clone git@github.com:dawidurbanski/playground-tools.gitcd playground-tools/packages/playground-demo-blocknpm install && npm run plugin-zipFrom source
wp-content/pluginsof your WordPress instalationgit clone git@github.com:dawidurbanski/playground-tools.gitnpm install && npm run buildComplete block example in plugin mode
Expand to grab block code