Skip to content

[Website] Add standalone playground block demo page - #3071

Merged
adamziel merged 12 commits into
trunkfrom
add-playground-block-demo
Dec 22, 2025
Merged

adamziel merged 12 commits into
trunkfrom
add-playground-block-demo

Conversation

@adamziel

@adamziel adamziel commented Dec 22, 2025 •

Copy link
Copy Markdown
Collaborator

Summary

This PR extracts the playground_demo_maybe_render_full_page_block functionality from the WordPress Playground Block plugin into a standalone HTML page that can be shipped on playground.wordpress.net.

The page provides an interactive code editor with live WordPress Playground preview, supporting:

  • Multi-file editing with syntax highlighting (PHP, JS, CSS, HTML, JSON)
  • JSX transpilation with esbuild-wasm
  • File tabs for switching between files
  • Download code as ZIP
  • Live WordPress Playground preview
  • URL parameter support for sharing configurations
  • Full-page and embedded view modes

URL Parameters

The page reads configuration from URL query parameters:

  • ?playground-full-page&playground-attributes=<base64> for full page mode
  • ?playground-attributes=<base64> for embedded mode
  • No parameters shows a default demo

Testing instructions

First, CI should be green – this PR ships the relevant E2E tests.

Then, follow these steps:

  • Visit /playground-block-demo.html and verify the default demo loads
  • Click "Run" and verify WordPress Playground loads
  • Edit the code and click "Run" to verify changes are applied
  • Test with each test link above
  • Verify JSX transpilation works (Test link Make the bundle smaller than 20M #2)
  • Verify Playground-only mode shows no editor (Test link Expose PHP fatal errors from the WASM interpreter #3)
  • Switch between file tabs and verify correct content displays
  • Download as ZIP and verify the archive contains all files

Test these on the deployed preview or local dev server (http://localhost:5400/website-extras/playground-block-demo.html):

1. Simple Code Editor (PHP Plugin)

Shows a basic PHP plugin with code editor and live preview side-by-side.

?playground-full-page=&playground-attributes=eyJjb2RlRWRpdG9yIjp0cnVlLCJjb2RlRWRpdG9yVHJhbnNwaWxlSnN4IjpmYWxzZSwiZmlsZXMiOlsiVzNzaWJtRnRaU0k2SW5Cc2RXZHBiaTV3YUhBaUxDSmpiMjUwWlc1MGN5STZJandcL2NHaHdYRzR2S2lwY2JpQXFJRkJzZFdkcGJpQk9ZVzFsT2lCWGIzSmtVSEpsYzNNZ1JHVnRieUJRYkhWbmFXNWNiaUFxTDF4dVhHNWhaR1JmWVdOMGFXOXVLQ2QzY0Y5b1pXRmtKeXdnWm5WdVkzUnBiMjRvS1NCN1hHNGdJQ0FnWldOb2J5QW5QR2d4UGtobGJHeHZJR1p5YjIwZ2RHaGxJSEJzZFdkcGJqd3ZhREUrUEdKeVBqeGljajQ4WW5JK1BHSnlQaWM3WEc1OUtUdGNiaUo5WFE9PSJdLCJjb2RlRWRpdG9yU2lkZUJ5U2lkZSI6dHJ1ZSwiY29kZUVkaXRvck11bHRpcGxlRmlsZXMiOmZhbHNlLCJjb2RlRWRpdG9yTW9kZSI6InBsdWdpbiIsImxvZ0luVXNlciI6dHJ1ZSwiY29uZmlndXJhdGlvblNvdXJjZSI6ImJsb2NrLWF0dHJpYnV0ZXMiLCJyZXF1aXJlTGl2ZVByZXZpZXdBY3RpdmF0aW9uIjpmYWxzZSwiY29uc3RhbnRzIjp7ImEiOiJiIn19

2. JSX Transpilation (Interactive React Counter)

Demonstrates JSX transpilation with a multi-file plugin containing a React component.

?playground-full-page=&playground-attributes=eyJjb2RlRWRpdG9yIjp0cnVlLCJjb2RlRWRpdG9yVHJhbnNwaWxlSnN4Ijp0cnVlLCJmaWxlcyI6WyJXM3NpYm1GdFpTSTZJbkJzZFdkcGJpNXdhSEFpTENKamIyNTBaVzUwY3lJNklqdy9jR2h3WEc0dktpcGNiaUFxSUZCc2RXZHBiaUJPWVcxbE9pQktVMWdnUkdWdGJ5QlFiSFZuYVc1Y2JpQXFJRVJsYzJOeWFYQjBhVzl1T2lCRVpXMXZibk4wY21GMFpYTWdTbE5ZSUhSeVlXNXpjR2xzWVhScGIyNGdhVzRnVjI5eVpGQnlaWE56SUZCc1lYbG5jbTkxYm1SY2JpQXFMMXh1WEc1aFpHUmZZV04wYVc5dUtDZDNjRjlsYm5GMVpYVmxYM05qY21sd2RITW5MQ0JtZFc1amRHbHZiaWdwSUh0Y2JpQWdJQ0IzY0Y5bGJuRjFaWFZsWDNOamNtb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playground-full-page&playground-attributes=eyJjb2RlRWRpdG9yIjpmYWxzZSwiY29kZUVkaXRvclJlYWRPbmx5IjpmYWxzZSwiY29kZUVkaXRvclNpZGVCeVNpZGUiOmZhbHNlLCJjb2RlRWRpdG9yVHJhbnNwaWxlSnN4IjpmYWxzZSwiY29kZUVkaXRvck11bHRpcGxlRmlsZXMiOmZhbHNlLCJjb2RlRWRpdG9yTW9kZSI6InBsdWdpbiIsImxvZ0luVXNlciI6dHJ1ZSwibGFuZGluZ1BhZ2VVcmwiOiIvd3AtYWRtaW4vIiwiY3JlYXRlTmV3UG9zdCI6ZmFsc2UsImNyZWF0ZU5ld1Bvc3RUeXBlIjoicG9zdCIsImNyZWF0ZU5ld1Bvc3RUaXRsZSI6IiIsImNyZWF0ZU5ld1Bvc3RDb250ZW50IjoiIiwicmVkaXJlY3RUb1Bvc3QiOmZhbHNlLCJyZWRpcmVjdFRvUG9zdFR5cGUiOiJmcm9udCIsImJsdWVwcmludCI6IiIsImJsdWVwcmludFVybCI6IiIsImNvbmZpZ3VyYXRpb25Tb3VyY2UiOiJibG9jay1hdHRyaWJ1dGVzIiwicmVxdWlyZUxpdmVQcmV2aWV3QWN0aXZhdGlvbiI6ZmFsc2UsImNvZGVFZGl0b3JFcnJvckxvZyI6ZmFsc2UsImNvbnN0YW50cyI6ImUzMD0iLCJmaWxlcyI6W119

This extracts the playground_demo_maybe_render_full_page_block functionality
from the WordPress Playground Block plugin into a standalone HTML page that
can be shipped on playground.wordpress.net.

The page provides an interactive code editor with live WordPress Playground
preview, supporting multi-file editing with syntax highlighting, JSX
transpilation, and real-time preview updates.

Key features:
- Multi-file code editor with syntax highlighting (PHP, JS, CSS, HTML, JSON)
- File tabs for switching between files
- Download code as ZIP
- Live WordPress Playground preview
- URL parameter support for sharing configurations
- Full-page and embedded view modes

The page reads configuration from URL query parameters:
- ?playground-full-page&playground-attributes=<base64> for full page mode
- ?playground-attributes=<base64> for embedded mode
- No parameters shows a default demo

New dependencies: @uiw/react-codemirror, esbuild-wasm, sass
Add Playwright E2E tests covering the three main use-cases:

1. Simple Code Editor (PHP Plugin) - tests code editor visibility,
   plugin output rendering, and side-by-side layout
2. JSX Transpilation - tests multi-file tabs, JSX rendering in
   WordPress, and JSX syntax in the editor
3. Full Page Playground Only - tests no-editor mode with full-width
   WordPress Playground display

The tests verify that the standalone playground block frame page
works correctly with URL-based configurations for code editing
and WordPress Playground preview.
@adamziel adamziel changed the title Add standalone playground block demo page [Website] Add standalone playground block demo page Dec 22, 2025
@adamziel
adamziel merged commit b728ee3 into trunk Dec 22, 2025
33 checks passed
@adamziel
adamziel deleted the add-playground-block-demo branch December 22, 2025 15:33
adamziel added a commit to WordPress/playground-tools that referenced this pull request Dec 22, 2025
Rewires the "Open in a new tab" link in the Playground block to go
directly to playground.wordpress.net/, see the [related Playground
handler logic](WordPress/wordpress-playground#3071).

This commit simplifies the plugin and shifts work from the local site
to the Playground.

 ## Testing instructions

1. Start a local dev server via `nx dev wordpress-playground-block`
2. Create a new post
3. Add the Playground block
4. Create a few files in that block
5. Publish the page
6. View the published page
7. Click the "Open in a new tab" link
8. Confirm it opens at playground.wordpress.net
adamziel added a commit to WordPress/playground-tools that referenced this pull request Dec 22, 2025
…#397)

Rewires the "Open in a new tab" link in the Playground block to go
directly to playground.wordpress.net/, see the [related Playground
handler
logic](WordPress/wordpress-playground#3071).

This commit simplifies the plugin and shifts work from the local site to
the Playground.

 ## Testing instructions

1. Start a local dev server via `nx dev wordpress-playground-block`
2. Create a new post
3. Add the Playground block
4. Create a few files in that block
5. Publish the page
6. View the published page
7. Click the "Open in a new tab" link
8. Confirm it opens at playground.wordpress.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant