Overview

Parent issue #3499919: [Meta] Plan for in-browser code components
Blocked by

Compile and present a preview for code components, so users can see the result of their work before their code component is put into action.

Proposed resolution

Using the JavaScript code, CSS code, and global CSS code being edited for the component in #3499988: Editing code components:

  1. Compile and bundle JavaScript code authored as Preact components using the WebAssembly build of SWC (Speedy Web Compiler):
  2. Use the bundled JavaScript code with import maps to provide a live preview;
  3. Compile component CSS (CSS tab) using the global CSS (global CSS tab) as Tailwind CSS v4 config in the browser with tailwindcss-in-browser;
  4. Include resulted CSS in the live preview;
  5. Pass example/default prop values from #3500017: Defining props for code components in the preview

Use #3483267: [exploratory] PoC of Preact+Tailwind components editable via CodeMirror as a reference, all of this was implemented there.

User interface changes

Preview for code components

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

balintbrews created an issue. See original summary.

balintbrews’s picture

Issue summary: View changes
balintbrews’s picture

Issue summary: View changes
balintbrews’s picture

Issue summary: View changes
effulgentsia’s picture

Issue tags: +sprint
hooroomoo’s picture

Assigned: Unassigned » hooroomoo

hooroomoo’s picture

Copied over the codeEditorSlice code to this from #3500761: Allow code components to import from npm packages so adding credit now before i forget

hooroomoo’s picture

Assigned: hooroomoo » balintbrews
Status: Active » Needs review
balintbrews’s picture

Assigned: balintbrews » hooroomoo
Status: Needs review » Needs work

balintbrews’s picture

Crediting @effulgentsia, who came up with the idea to use @swc/wasm-web, and @xinran, who did the original implementation in #3483267: [exploratory] PoC of Preact+Tailwind components editable via CodeMirror.

hooroomoo’s picture

Assigned: hooroomoo » balintbrews
Status: Needs work » Needs review

balintbrews’s picture

Assigned: balintbrews » hooroomoo
Status: Needs review » Fixed
Issue tags: +Needs screenshots

Amazing work, @hooroomoo!

I'll leave this assigned to you, so you can record a screencast. We can also do that when we land #3500017: Defining props for code components, hopefully soon. 😊

hooroomoo’s picture

Assigned: hooroomoo » Unassigned
Issue summary: View changes
Issue tags: -Needs screenshots
StatusFileSize
new2.39 MB

Gif that shows changing JSX, changing global style of primary color to pink, showing the error messages we added here for compile errors and if the code is missing a default export.

effulgentsia’s picture

Issue tags: -sprint
wim leers’s picture

@hooroomoo 🤩🤩

lauriii’s picture

This looks 🔥🔥🔥! Great work @hooroomoo! 👏

A tiny suggestion I have is that could we add a loading animation for the state where the preview is being loaded when opening the code editor?

lauriii’s picture

Crediting the designers who worked on this.

Status: Fixed » Closed (fixed)

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