Editor Web
Ecosistema completo para organización y gestión de contenido con interfaces espaciales
Editor Web - Widget Positioning & Persistence
Widget Drag & Drop System
The editor web system uses a sophisticated drag-and-drop mechanism with Flash Persistence for state management and real-time reactive canvas expansion.
Key Components
- ResponsiveDraggableDirective: Handles drag interactions, visual feedback, and real-time canvas expansion
- WidgetHostComponent: Manages widget positioning and CSS application
- EditorService: Coordinates state updates and persistence
- Flash Persistence: Handles automatic state persistence
- CanvasOperationsService: Manages canvas height and layout operations
🎯 Real-Time Canvas Features
Intelligent Canvas Expansion
- During Drag: Canvas expands in real-time as widgets approach boundaries
- Buffer Zone: 150px buffer triggers automatic expansion before widgets reach edge
- No Reversion: Widgets never snap back or appear outside canvas
- Grid Updates: Cuadrícula (grid background) updates dynamically with canvas height
- Unlimited Height: Canvas can expand infinitely - no artificial limits ✨
- Minimum Height: 500px base height ensures usable canvas even without widgets
Reactive Grid System
- Grid pattern adjusts automatically when canvas expands
- Maintains consistent grid spacing across all canvas heights
- Updates triggered by custom events during drag operations
Boundary Prevention
- Widgets are prevented from appearing outside canvas bounds
- Automatic canvas expansion ensures sufficient space
- Visual feedback during drag shows available drop zones
Critical Issues & Solutions
Issue: Widgets Not Persisting Position Changes
Symptoms:
- Widgets move visually during drag but revert to original position
- No persistence logs in console
Root Causes & Solutions:
Unreasonable Coordinate Values
- Problem: Widgets loaded with coordinates like
x: 7244, y: 13187(off-screen) - Solution: Position validation in
ResponsiveDraggableDirective.updateWidgetPositionModel()
- Problem: Widgets loaded with coordinates like
Type Safety Issues
- Problem:
Operator '<' cannot be applied to types 'string | number' and 'number' - Solution: Convert coordinates to numbers before comparison in validation logic
- Problem:
CSS Positioning Override
- Problem:
position: relative; left: auto; top: auto;overriding absolute positioning - Solution: Set
[autoApplyPositionAndSize]="true"in editor canvas template
- Problem:
Drag Directive Disabled
- Problem:
dragEnabled: falsebecause widgets not selected - Solution: Ensure widgets are selected (
isSelected: true) for drag to work
- Problem:
Transform Reset Timing
- Problem: Transform reset too early, causing visual snap-back
- Solution: Delay transform reset by 50ms to allow CSS positioning to apply
Canvas Auto-Sizing
- Problem: Canvas doesn't expand vertically when widgets are positioned outside visible area
- Solution: Real-time canvas expansion during drag operations
Conflicting Position Validations
- Problem: Two position validation systems fighting each other
- Solution: Removed WidgetHostComponent validation, let ResponsiveDraggableDirective handle all
Canvas Height Constraint
- Problem: Canvas has fixed height preventing vertical expansion
- Solution: Use
height: autowith dynamicmin-heightbased on widget positions
Main Layout Constraints
- Problem: Parent layout containers with
overflow: hiddenpreventing canvas expansion - Solution: Changed main layout to
overflow: visibleand content container to allow vertical expansion
- Problem: Parent layout containers with
Real-Time Expansion During Drag ✨
- Problem: Canvas only expanded after drag ended, causing widgets to appear outside temporarily
- Solution: Added
checkAndExpandCanvas()method that runs during drag move events - Implementation:
- Monitors widget position in real-time during drag
- Expands canvas immediately when widget approaches boundary (150px buffer)
- Dispatches
canvas-realtime-expansioncustom event - Updates grid background dynamically
Artificial Height Limits Removed ✨ NEW
- Problem: Canvas was limited to ~2800px height due to hardcoded constraints
- Solution: Removed all artificial limits - canvas can now expand infinitely
- Changes:
- Position validation: Changed from
< 2000to< 50000(only catches obvious errors) - Drag constraints: Removed
maxYlimit, set toNumber.POSITIVE_INFINITY - Allow widgets to be positioned at any Y coordinate (5000px, 10000px, etc.)
- Position validation: Changed from
- Result: Professional canvas that grows with your content, no arbitrary restrictions
Debugging Checklist
When widgets don't persist position changes:
- Check Position Values: Look for unreasonable coordinates (>2000px)
- Verify Drag Enablement: Ensure
dragEnabled: truein logs - Check CSS Positioning: Verify
position: absoluteandleft/topvalues - Monitor Persistence: Look for
💾 Flash Persistence: Persistedlogs - Check State Updates: Verify
EditorService.setWidgetsis called - Check Real-Time Expansion: Look for
🚨 REAL-TIME CANVAS EXPANSIONlogs - Verify Grid Updates: Check for
🎯 REAL-TIME EXPANSIONlogs
Success Indicators
✅ Working correctly when you see:
🎯 Position validation check: {isPositionReasonable: true}🎯 WidgetHostComponent.isDraggable: {finalDraggable: true}🎯 Updating widget position model: {newX: 68, newY: 164}💾 Flash Persistence: Persisted flash:editor-state✅ WRITE VERIFICATION: flash:editor-state successfully persisted🚨 REAL-TIME CANVAS EXPANSION: {widgetBottom: 450, newMinHeight: 600}✨ NEW🎯 REAL-TIME EXPANSION: {newHeight: 600, triggerReason: 'drag-move'}✨ NEW
Performance Notes
- Flash Persistence uses micro-cache for instant reads
- Position validation prevents off-screen widget issues
- Transform reset timing ensures smooth visual feedback
- State updates trigger automatic persistence via signals
- Real-time canvas expansion runs only when needed (widget approaches boundary)
- Grid updates are throttled to prevent performance issues
- Canvas never shrinks during editing to maintain stability
API Reference
Custom Events
canvas-height-recalculation-needed: Triggered after drag end for full height recalculationcanvas-realtime-expansion: Triggered during drag when canvas needs immediate expansion- Detail:
{ newHeight: number, widgetId: string, widgetBottom: number, triggerReason: string }
- Detail:
Key Methods
ResponsiveDraggableDirective.checkAndExpandCanvas(): Real-time canvas expansion during dragCanvasOperationsService.recalculateCanvasHeight(): Full canvas height recalculationEditorCanvasComponent.updateGridBackground(): Dynamic grid background update