WIDGET CONTEXT CLASSIFICATION
Comprehensive guidelines for AI-assisted development within the Editor platform
Widget Context Classification - Implementation Summary
Date: December 9, 2025
Session: Widget System Architecture Fix
Status: ✅ COMPLETE
Overview
This implementation fixes the widget/embeddable system disconnect by:
- Fixing widget creation - Using existing
ModuleWidgetBridgeServiceas fallback - Adding context classification - Distinguishing page widgets from structural components
- Implementing contextual filtering - Showing appropriate widgets based on context
Problem Statement
Issue 1: Factory Disconnect
UI components (Panel, Card, Tabs, etc.) were registered in WidgetsEmbeddableRegistryService but had no corresponding widget factories, causing "No factory found" errors when trying to add them to the canvas.
Issue 2: No Context Separation
All widgets appeared in the page editor palette, including structural components (Panel, Menu, Dialog) that should only be available in modular-universe for building platform structure.
Solution Architecture
1. Widget Creation Fix
File: libs/libs-structural/editor-web-lib/src/lib/components/widget-library/widget-library.component.ts
Change: Updated addWidgetToCanvas() to use existing ModuleWidgetBridgeService as fallback:
addWidgetToCanvas(widget: WidgetCard): void {
try {
// Try factory first (for basic widgets)
const newWidget = this.widgetFactory.createWidget(widgetType);
this.editorService.addWidget(newWidget);
} catch (error) {
// IMPROVED: Use existing ModuleWidgetBridgeService for embeddables
const bridgedWidget = this.moduleBridge.createWidgetFromEmbeddable(
widget.id,
{ position: { x: 100, y: 100 } }
);
if (bridgedWidget) {
this.editorService.addWidget(bridgedWidget);
}
}
}
2. Context Classification System
File: libs/libs-widgets/widgets/src/lib/services/widgets-embeddable-registry.service.ts
Added:
export type EmbeddableContext = 'page' | 'structural' | 'universal';
export interface EmbeddableDefinition {
// ... existing fields ...
context?: EmbeddableContext;
}
3. Widget Classification
| Context | Components | Where Used |
|---|---|---|
| page | text, button, image, video, hero, gallery, testimonial, feature, pricing, card-widget, form inputs, feedback (toast, spinner, skeleton, progress), icon, link, shape, divider, spacer | editor-web-lib (page content) |
| structural | panel, menu, dialog, expansion-panel | modular-universe (platform structure) |
| universal | tabs, container, ux-card | Both contexts |
4. Contextual Filtering
File: libs/libs-structural/editor-web-lib/src/lib/components/widget-library/widget-library.component.ts
Added:
readonly contextFilter = signal<WidgetContextFilter>('page');
readonly contextFilters = [
{ id: 'page', label: 'Page Widgets', icon: 'web', description: 'Content for pages' },
{ id: 'structural', label: 'Structural', icon: 'account_tree', description: 'Platform structure' },
{ id: 'universal', label: 'Universal', icon: 'all_inclusive', description: 'Works in both' },
{ id: 'all', label: 'All Contexts', icon: 'apps', description: 'Show all' }
];
// Filter logic in currentCategoryWidgets computed
if (context !== 'all') {
widgets = widgets.filter(widget => {
const widgetContext = widget.context || 'page';
return widgetContext === context || widgetContext === 'universal';
});
}
Files Modified
Core Type Definitions
libs/libs-widgets/widgets/src/lib/services/widgets-embeddable-registry.service.ts- Added
EmbeddableContexttype - Added
contextfield toEmbeddableDefinition
- Added
libs/libs-ui-core/ui-core/src/lib/components/services/ui-embeddable-registrar.service.ts- Added
contexttoUiComponentConfiginterface - Updated
register()to pass context through
- Added
UI Component Embeddables (libs-ui)
libs/libs-ui/ux-panel/src/lib/embeddables/panel.embeddable.ts-context: 'structural'libs/libs-ui/ux-menu/src/lib/embeddables/menu.embeddable.ts-context: 'structural'libs/libs-ui-core/ui-core/src/lib/components/ux-tabs/embeddables/tabs.embeddable.ts-context: 'universal'libs/libs-ui-core/ui-core/src/lib/components/card/components/card.embeddable.ts-context: 'universal'libs/libs-ui-core/ui-core/src/lib/components/input/input.embeddable.ts-context: 'page'libs/libs-ui-core/ui-forms/src/lib/embeddables/select.embeddable.ts-context: 'page'libs/libs-ui-core/ui-forms/src/lib/embeddables/checkbox.embeddable.ts-context: 'page'libs/libs-ui-core/ui-forms/src/lib/embeddables/toggle.embeddable.ts-context: 'page'libs/libs-ui-core/ui-feedback/src/lib/embeddables/dialog.embeddable.ts-context: 'structural'libs/libs-ui-core/ui-feedback/src/lib/embeddables/toast.embeddable.ts-context: 'page'libs/libs-ui/ux-loading/src/lib/embeddables/spinner.embeddable.ts-context: 'page'libs/libs-ui/ux-loading/src/lib/embeddables/skeleton.embeddable.ts-context: 'page'libs/libs-ui/ux-loading/src/lib/embeddables/progress.embeddable.ts-context: 'page'libs/libs-ui/ux-icons/src/lib/embeddables/icon.embeddable.ts-context: 'page'libs/libs-ux/ux-utils-lib/src/lib/embeddables/expansion-panel.embeddable.ts-context: 'structural'libs/libs-ux/ux-utils-lib/src/lib/embeddables/progress-circle.embeddable.ts-context: 'page'
Built-in Widget Definitions
libs/libs-widgets/widgets/src/lib/registry/widget-registry-init.ts- Added
contexttoBuiltinWidgetDefinterface - Updated
widgetToEmbeddable()to pass context through - Added
context: 'page'to all built-in widgets (text, button, image, video, etc.) - Added
context: 'universal'to container widget
- Added
Widget Library Component
libs/libs-structural/editor-web-lib/src/lib/components/widget-library/widget-library.component.ts- Injected
ModuleWidgetBridgeService - Updated
addWidgetToCanvas()with bridge fallback - Added
contextFiltersignal (defaults to 'page') - Added
contextFiltersarray with filter options - Added
setContextFilter()method - Updated
currentCategoryWidgetscomputed to apply context filtering - Updated
loadWidgetsFromRegistry()to capture context from widgets
- Injected
Smart Component Handling
Tabs Component (Universal Context)
The UxTabsComponent already supports both page content and structural navigation via the routeIntegration input:
routeIntegration=false(default) → Content tabs for page widgetsrouteIntegration=true→ Route-based navigation tabs for structural use
By marking it as context: 'universal', it appears in both:
- Page editor palette (for content tabs)
- Modular universe palette (for navigation tabs)
Card Component (Universal Context)
Both card-widget (built-in) and ux-card (UI component) are marked as universal because:
- Cards are common page content elements
- Cards can also be structural containers in layouts
Container Widget (Universal Context)
The container widget is universal because it's used for:
- Grouping page content widgets
- Organizing structural layout sections
Usage
In Page Editor (editor-web-lib)
By default, the widget palette shows only context: 'page' and context: 'universal' widgets:
- ✅ Text, Button, Image, Video, Forms
- ✅ Tabs (content mode), Card, Container
- ❌ Panel, Menu, Dialog (filtered out)
In Modular Universe
The structural component palette should show only context: 'structural' and context: 'universal' widgets:
- ✅ Panel, Menu, Dialog, Expansion Panel
- ✅ Tabs (navigation mode), Card, Container
- ❌ Text, Button, Image (filtered out)
Switching Contexts
Users can toggle the context filter to see all widgets if needed:
// In widget library component
setContextFilter('all'); // Show all widgets regardless of context
Testing Checklist
- UI components (Panel, Card, Tabs) can be added to page editor canvas without errors
- Structural components (Panel, Menu, Dialog) do NOT appear in page editor by default
- Page widgets (text, button, image) do NOT appear in modular-universe by default
- Universal widgets (Tabs, Card, Container) appear in both contexts
- Widget variants are selectable and work correctly
- No "No factory found" errors in console
- Context filter UI works and switches between page/structural/universal/all
Architecture Diagram
┌─────────────────────────────────────────────────────────────────────────────┐
│ WIDGET CREATION FLOW (✅ FIXED) │
├─────────────────────────────────────────────────────────────────────────────┤
│ User clicks "Add Widget" in WidgetLibrary │
│ ↓ │
│ WidgetFactoryService.createWidget(type) │
│ ↓ │
│ Try: WidgetRegistryService.getFactory(type) │
│ ↓ │
│ ✅ SUCCESS for basic widgets (text, button, etc.) │
│ ❌ FAIL for UI components (panel, card, etc.) │
│ ↓ │
│ Fallback: ModuleWidgetBridgeService.createWidgetFromEmbeddable() │
│ ↓ │
│ ✅ SUCCESS - Widget created from EmbeddableDefinition │
│ ↓ │
│ EditorService.addWidget(widget) │
│ ↓ │
│ ✅ Widget appears on canvas │
└─────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ CONTEXT FILTERING FLOW (✅ NEW) │
├─────────────────────────────────────────────────────────────────────────────┤
│ WidgetLibraryComponent loads widgets │
│ ↓ │
│ contextFilter = 'page' (default in editor-web-lib) │
│ ↓ │
│ Filter widgets where: │
│ widget.context === 'page' OR widget.context === 'universal' │
│ ↓ │
│ ✅ Show: text, button, image, tabs, card, container │
│ ❌ Hide: panel, menu, dialog, expansion-panel │
└─────────────────────────────────────────────────────────────────────────────┘
Key Insights
Reuse Over Recreation
Instead of creating new factories or services, we improved existing systems:
ModuleWidgetBridgeService.createWidgetFromEmbeddable()already existedWidgetsEmbeddableRegistryServicealready unified all embeddables- We just connected them properly in
WidgetLibraryComponent
Context as Metadata
The context field is optional metadata that doesn't break existing functionality:
- Defaults to
'page'if not specified - Backwards compatible with widgets that don't have context
- Enables smart filtering without requiring code changes
Smart Components
Components like Tabs are truly universal - they work in both contexts:
- Page editor: Content tabs (
routeIntegration=false) - Modular universe: Navigation tabs (
routeIntegration=true)
Next Steps
For Future Development
Modular Universe Integration
- Create structural component palette in
modular-universe - Default
contextFilterto'structural'in that context - Show Panel, Menu, Dialog for building platform structure
- Create structural component palette in
Enhanced Context Awareness
- Add context hints/tooltips in widget palette
- Show different default properties based on context
- Provide context-specific examples in documentation
AI Training
- Train AI to understand context classification
- Generate appropriate widgets based on context
- Suggest context switches when needed
Success Metrics
✅ All 5 tasks completed:
- Fixed widget creation using existing bridge service
- Added
EmbeddableContexttype and field - Classified all UI embeddables (18 components)
- Classified all built-in widgets (20+ widgets)
- Implemented contextual filtering in widget library
✅ No linter errors in any modified files
✅ Backwards compatible - existing widgets without context still work
✅ Reusability achieved - leveraged existing systems instead of creating new ones