Home / archive / 2025-work-artifacts / playground / README-UNIFIED

LARC Playground - Unified System

Overview

The new unified playground combines three powerful modes into one cohesive experience:

  • ๐Ÿ“š Gallery Mode - Browse and explore pre-built component examples
  • ๐Ÿ”จ Builder Mode - Visual drag-and-drop component builder
  • ๐Ÿ’ป Editor Mode - CodePen-style live code editor
  • What's New?

    โœ… Issues Fixed

  • Property Changes Now Apply Correctly
  • - Fixed event listeners for attribute updates - Properties update on change (checkboxes/selects) or blur (textareas) - Visual feedback when properties are updated
  • CSS Styling Works Properly
  • - Click "Apply Styles" button to apply CSS to components - CSS presets for quick styling (Card, Gradient, Shadow, Bordered) - Clear visual feedback when styles are applied - Styles persist across mode switches
  • Actions/Events System Functional
  • - Add custom event handlers to components - Support for click, hover, focus, and other DOM events - Publish to PAN bus directly from UI - Console logging and alerts for debugging
  • Clear Mode Separation
  • - Top-level tabs clearly show which mode you're in - Each mode has its own dedicated UI - Easy switching between modes with example preservation

    ๐Ÿ†• New Features

    #### Gallery Mode

    • Visual Example Browser - See all 20+ examples in a beautiful grid
    • Search & Filter - Find examples quickly
    • Quick Actions - Open any example in Builder or Editor with one click
    • Preview - Open examples in a new window for fullscreen testing
    #### Builder Mode
    • Component Palette - Drag components from sidebar
    • Visual Canvas - See components render live
    • 3-Tab Properties Panel:
    - Properties - Edit component attributes with type-aware inputs - CSS - Style containers with live preview - Actions - Bind events and PAN bus messages
    • Code Export - Export your creation as standalone HTML
    #### Editor Mode
    • 3-Pane Code Editor - HTML, CSS, JavaScript tabs
    • Live Preview - See changes as you type (1s debounce)
    • Auto-run - Changes apply automatically
    • Export - Download as standalone HTML file
    • Format - Basic code formatting
    • Fullscreen Preview - Test in fullscreen mode

    File Structure

    playground/
    โ”œโ”€โ”€ index-new.html              # New unified playground entry point
    โ”œโ”€โ”€ playground-unified.mjs      # Main controller for all three modes
    โ”œโ”€โ”€ styles/
    โ”‚   โ”œโ”€โ”€ playground-unified.css  # Unified styles for all modes
    โ”‚   โ””โ”€โ”€ playground.css          # Original styles (still used by components)
    โ”œโ”€โ”€ components/                 # Existing components (reused)
    โ”‚   โ”œโ”€โ”€ pg-palette.mjs
    โ”‚   โ”œโ”€โ”€ pg-canvas.mjs
    โ”‚   โ”œโ”€โ”€ pg-properties.mjs
    โ”‚   โ”œโ”€โ”€ pg-exporter.mjs
    โ”‚   โ””โ”€โ”€ pg-bus-monitor.mjs
    โ””โ”€โ”€ examples.mjs                # 20+ pre-built examples

    How to Use

    Accessing the Playground

    Option 1: Direct Access
    https://larcjs.com/playground/index-new.html
    Option 2: Replace Current Playground
    cd /home/cdr/domains/larcjs.com/www/larc/playground
    cp index.html index-old.html  # Backup
    cp index-new.html index.html  # Replace

    Gallery Mode

  • Browse the example cards
  • Use search box to find specific examples
  • Click action buttons:
  • - ๐Ÿ”จ Open in Builder - Load in visual builder - ๐Ÿ’ป Open in Editor - Load code in editor - ๐Ÿ‘ Preview - Open in new window

    Builder Mode

  • Add Components:
  • - Click component from left sidebar palette - Component appears on canvas - Select component to edit properties
  • Edit Properties (Right Panel):
  • - Properties Tab - Edit attributes - Text inputs for strings - Checkboxes for booleans - Textareas for JSON/objects - Changes apply on blur/change - CSS Tab - Style the component - Write custom CSS in textarea - Use presets for quick styles - Click "Apply Styles" to see changes - Actions Tab - Add event handlers - Choose event (click, hover, etc.) - Choose action (PAN publish, console, alert) - Add value/message - Click "Add Action" to attach
  • Export Code:
  • - View generated HTML in bottom panel - Copy code for your own project

    Editor Mode

  • Edit Code:
  • - Switch between HTML/CSS/JS tabs - Write your code in each editor - Changes auto-run after 1 second
  • Preview:
  • - Right pane shows live preview - Click refresh button to force update - Click fullscreen for expanded view
  • Controls:
  • - โ–ถ Run - Force immediate preview update - Clear - Reset all editors (with confirmation) - Format - Basic code formatting - Export - Download as standalone HTML

    PAN Bus Monitor

    Click "PAN Monitor" button in header to see real-time PAN bus messages:

    • Message topic and payload
    • Timestamp
    • Source component
    • Helps debug communication between components

    Architecture

    Mode Management

    The PlaygroundUnified class manages all three modes:

    class PlaygroundUnified {
      constructor() {
        this.currentMode = 'gallery';  // gallery | builder | editor
        this.examples = getAllExamples();
        this.currentExample = null;
      }
    
      switchMode(mode) {
        // Update tabs, panels, and load appropriate content
      }
    }

    Mode Switching Flow

    Gallery Example Card
        โ†“ "Open in Builder"
    Builder Mode (loads example components)
        โ†“ Edit properties, add styling
    Builder Export
        โ†“ Copy HTML
    Editor Mode (paste and customize)
        โ†“ Add JavaScript, refine CSS
    Export Standalone HTML

    Component Communication

    All modes use the existing PAN bus system:

    // Properties panel publishes changes
    document.dispatchEvent(new CustomEvent('canvas-changed', {
      bubbles: true
    }));
    
    // Canvas listens for component selection
    document.addEventListener('component-selected', (e) => {
      this.addComponent(e.detail);
    });

    Key Improvements

    1. Property Updates

    Old Behavior:
    • Properties sometimes didn't update
    • No visual feedback
    • Unclear when changes applied
    New Behavior:
    attachPropertyListeners() {
      this.querySelectorAll('[data-attr]').forEach(input => {
        let eventType = input.type === 'checkbox' ? 'change' :
                       input.tagName === 'TEXTAREA' ? 'blur' : 'input';
    
        input.addEventListener(eventType, (e) => {
          const attrName = e.target.dataset.attr;
          const value = e.target.type === 'checkbox' ?
                       e.target.checked : e.target.value;
    
          // Update element immediately
          if (this.selectedElement) {
            if (value === '') {
              this.selectedElement.removeAttribute(attrName);
            } else {
              this.selectedElement.setAttribute(attrName, value);
            }
          }
    
          // Notify canvas
          document.dispatchEvent(new CustomEvent('canvas-changed'));
        });
      });
    }

    2. CSS Application

    Old Behavior:
    • CSS changes didn't visually apply
    • Unclear if styles were saved
    New Behavior:
    attachCSSListeners() {
      applyBtn.addEventListener('click', () => {
        const css = cssEditor.value;
        const componentId = this.selectedElement.dataset.componentId;
    
        // Store CSS
        this.customCSS.set(componentId, css);
    
        // Apply immediately via style attribute
        this.selectedElement.style.cssText = css;
    
        // Show success feedback
        this.showFeedback('Styles applied!', 'success');
      });
    }
    Visual Feedback: Toast notifications appear when styles are applied/cleared.

    3. Actions System

    Old Behavior:
    • Actions system partially implemented
    • No clear indication of active actions
    New Behavior:
    applyAction(action) {
      this.selectedElement.addEventListener(action.event, (e) => {
        switch (action.type) {
          case 'publish':
            // Publish to PAN bus
            document.dispatchEvent(new CustomEvent('pan:publish', {
              detail: {
                topic: action.topic,
                data: { source: this.componentMeta?.name }
              }
            }));
            break;
    
          case 'console':
            console.log(`[${this.componentMeta?.displayName}]`, action.message);
            break;
    
          case 'alert':
            alert(action.message);
            break;
        }
      });
    }

    Actions are immediately attached and work on next event trigger.

    Example: Using All Three Modes

    Scenario: Creating a Dashboard

  • Start in Gallery:
  • - Find "Dashboard Layout" example - Click "Open in Builder"
  • Customize in Builder:
  • - Example loads with pan-card, pan-table, pan-chart - Select pan-card - Properties Tab: Change header to "My Dashboard" - CSS Tab: Apply gradient preset - Actions Tab: Add click event that publishes to "card.clicked"
  • Refine in Editor:
  • - Switch to Editor mode - Current state loads into HTML editor - Add JavaScript to handle "card.clicked" event:
    document.addEventListener('pan:message', (e) => {
           if (e.detail.topic === 'card.clicked') {
             console.log('Card clicked!', e.detail);
           }
         });
    - Add custom CSS animations - Export as standalone HTML
  • Test & Share:
  • - Open PAN Monitor to see messages - Test all interactions - Export final HTML - Deploy or share

    Best Practices

    Gallery Mode

    • โœ… Use search to find examples quickly
    • โœ… Preview examples before opening in Builder
    • โœ… Check component list to understand what's included

    Builder Mode

    • โœ… Always check the Properties tab to see available attributes
    • โœ… Use CSS presets as starting points
    • โœ… Test actions with PAN Monitor open
    • โœ… Export code frequently to save progress

    Editor Mode

    • โœ… Use HTML tab for structure
    • โœ… Use CSS tab for styling
    • โœ… Use JS tab for interactivity
    • โœ… Wait 1 second after typing for auto-run
    • โœ… Use "Format" button to clean up code
    • โœ… Export when satisfied with result

    Troubleshooting

    Properties Not Updating

    Problem: Changes in Properties tab don't reflect in component Solutions:
  • For textareas (JSON/object fields): Click outside the textarea (blur event)
  • For text inputs: Type and wait for auto-update
  • For checkboxes/selects: Change fires immediately
  • Check browser console for errors
  • CSS Not Applying

    Problem: CSS in CSS tab doesn't show visual changes Solutions:
  • Make sure to click "Apply Styles" button
  • Check CSS syntax (use presets as reference)
  • Verify component is still selected (blue outline)
  • Try clearing styles and reapplying
  • Actions Not Firing

    Problem: Event handlers don't trigger Solutions:
  • Verify action was added (should appear in actions list)
  • Open PAN Monitor to see if messages are published
  • Check event type matches user interaction
  • Refresh page and re-add action if needed
  • Editor Preview Not Updating

    Problem: Code changes don't show in preview Solutions:
  • Wait 1 second for debounced auto-run
  • Click "โ–ถ Run" button to force update
  • Check for JavaScript errors in preview frame
  • Verify LARC components are loading (check network tab)
  • Migration from Old Playground

    If you want to keep both versions:

    # Rename old playground
    mv index.html index-classic.html
    
    # Use new playground as default
    cp index-new.html index.html
    
    # Update links
    # index-classic.html = old drag-and-drop only
    # index.html = new unified system

    Technical Details

    Dependencies

    • @larcjs/core@3.0.1 - Core PAN bus system
    • @larcjs/ui@3.0.1 - UI components
    • Existing pg-* components (palette, canvas, properties, etc.)

    Browser Support

    • Chrome 90+
    • Firefox 88+
    • Safari 14+
    • Edge 90+
    Requirements:
    • ES Modules
    • Custom Elements v1
    • Shadow DOM
    • CSS Grid
    • Flexbox

    Performance

    • Gallery mode: Renders 20+ cards efficiently
    • Builder mode: Handles 50+ components on canvas
    • Editor mode: 1-second debounce for auto-run
    • All modes: Minimal memory footprint

    Future Enhancements

    Potential improvements for future versions:

    • [ ] Syntax highlighting in editor (CodeMirror/Monaco)
    • [ ] Component search in Builder palette
    • [ ] Undo/redo in Builder
    • [ ] Save examples to localStorage
    • [ ] Share examples via URL
    • [ ] Import/export Builder projects
    • [ ] Template library expansion
    • [ ] Mobile-optimized layout
    • [ ] Collaborative editing
    • [ ] Video tutorials integration

    Support

    For issues or questions:

    • GitHub: https://github.com/larcjs/larc/issues
    • Discord: https://discord.gg/zjUPsWTu
    • Documentation: https://larcjs.com/docs/

    Contributing

    The playground is open source! Contributions welcome:

  • Fork the repository
  • Make improvements
  • Test all three modes
  • Submit pull request
  • See CONTRIBUTING.md for guidelines.


    Built with LARC - Lightweight Asynchronous Relay Core