Session 19.3 - Widget/Component Editing Plan

Planning document for enabling modification of generated embeddables and widgets

Session 19.3: Widget/Component Editing Plan

🎯 Goal

Enable users to modify generated embeddables (UI components) from the AI Platform Generator.


🏗️ Current State

What's Generated

When AI generates a module, it creates:

Module: "Member Management"
├── Entity: Member
├── Actions: CreateMember, UpdateMember, DeleteMember, GetMember, ListMembers
└── Embeddables:
     ├── MemberList (table view)
     ├── MemberCard (card view)
     ├── MemberForm (create/edit form)
     └── MemberDetail (detail view)

Current Limitations


🎨 Proposed Solution

Option A: Visual Embeddable Editor (Recommended)

Concept: Create a visual editor specifically for module embeddables.

Flow:

User clicks "Edit Component" on MemberList
         ↓
Open Visual Embeddable Editor
         ↓
User modifies:
  - Layout (grid/flex)
  - Fields to display
  - Styling (colors, spacing)
  - Actions (buttons, events)
         ↓
Save changes to ModuleContext
         ↓
Regenerate component code
         ↓
Update module files

Implementation:

  1. Create EmbeddableEditorComponent in modularity-lib
  2. Visual canvas for component layout
  3. Property panels for configuration
  4. Live preview
  5. Code generation on save

Pros:

Cons:


Option B: Widget Builder Integration

Concept: Convert generated embeddables to widgets that can be edited in widget-builder.

Flow:

User clicks "Edit Component" on MemberList
         ↓
Convert embeddable to widget definition
         ↓
Open in Widget Builder
         ↓
User modifies widget
         ↓
Save as custom widget
         ↓
Update module to use custom widget

Implementation:

  1. Create EmbeddableToWidgetConverter service
  2. Map embeddable properties to widget properties
  3. Open widget-builder with converted widget
  4. On save, update module's embeddable reference

Pros:

Cons:


Option C: Code Editor with Templates

Concept: Provide a code editor with templates and snippets.

Flow:

User clicks "Edit Component" on MemberList
         ↓
Open Code Editor with component files
         ↓
User modifies .ts, .html, .scss
         ↓
Validate changes
         ↓
Save and rebuild module

Implementation:

  1. Embed Monaco Editor
  2. Load component files
  3. Syntax highlighting + IntelliSense
  4. Validation on save
  5. Hot reload

Pros:

Cons:


🎯 Recommended Approach: Hybrid (A + B)

Phase 1: Visual Editor for Simple Changes (Option A)

For common modifications:

UI:

┌────────────────────────────────────────┐
│ Editing: Member List Component         │
├────────────────────────────────────────┤
│ Fields to Display:                     │
│ ☑ Name                                 │
│ ☑ Email                                │
│ ☑ Phone                                │
│ ☐ Address                              │
│                                        │
│ Layout:                                │
│ ○ Table  ● Grid  ○ List               │
│                                        │
│ Actions:                               │
│ ☑ View Details                         │
│ ☑ Edit                                 │
│ ☑ Delete                               │
│                                        │
│ [Preview] [Save Changes] [Cancel]      │
└────────────────────────────────────────┘

Phase 2: Advanced Editor for Complex Changes (Option C)

For advanced modifications:

Access: "Advanced Mode" button in visual editor


🔧 Technical Architecture

Embeddable Metadata Storage

interface EmbeddableCustomization {
  embeddableId: string;
  moduleId: string;
  customizations: {
    layout?: 'table' | 'grid' | 'list';
    visibleFields?: string[];
    fieldOrder?: string[];
    styling?: {
      colors?: Record<string, string>;
      spacing?: Record<string, string>;
    };
    actions?: {
      id: string;
      label: string;
      icon: string;
      actionId: string; // Links to module action
    }[];
  };
  version: number;
  lastModified: string;
}

Storage Location

Code Generation

class EmbeddableCodeGenerator {
  generate(embeddable: EmbeddableDefinitionV2, customizations: EmbeddableCustomization): {
    typescript: string;
    html: string;
    scss: string;
  } {
    // Generate .ts, .html, .scss based on customizations
    // Use templates + variable substitution
  }
}

📋 Implementation Checklist

Phase 1: Visual Editor (4-6 hours)

Phase 2: Code Generation (3-4 hours)

Phase 3: Integration (2-3 hours)


🎨 UI Mockup

Module Card with Edit Buttons

┌──────────────────────────────────────┐
│ 👥 Member Management                 │
│                                      │
│ Manage gym members with profiles     │
│                                      │
│ 📊 1 entity  ⚡ 5 actions  🎨 4 UI   │
│                                      │
│ Components:                          │
│ • Member List      [Edit] [Preview]  │
│ • Member Card      [Edit] [Preview]  │
│ • Member Form      [Edit] [Preview]  │
│ • Member Detail    [Edit] [Preview]  │
│                                      │
│ [Edit Module] [Deploy]               │
└──────────────────────────────────────┘

🔗 Integration Points

With modularity-lib

With widget-builder

With editor-web-lib


🎓 Key Decisions

Decision Choice Reasoning Confidence
Editing approach Hybrid (Visual + Code) Beginner-friendly with advanced option 92%
Storage location ModuleContext + Flash Consistent with existing architecture 95%
Code generation Template-based Maintainable and extensible 93%
Integration modularity-lib first Core module system 96%

📁 Files to Create

File Purpose
embeddable-editor.component.ts Visual editor UI
embeddable-code-generator.service.ts Code generation
embeddable-customization.model.ts Type definitions
embeddable-templates/ Component templates

🚀 Success Criteria


Status: Planning Complete
Next: Implement Phase 1 (Visual Editor)
Estimated Effort: 10-15 hours total