/** * Canvas Component * * Main visual editor canvas that renders an iframe with editable HTML content. * Features: * - Iframe for isolated HTML editing environment * - Overlay canvas for selection/hover visualization * - Integration with selector and overlay utilities * - Communication bridge with StylePanel * * Architecture: * ┌─────────────────────────────────────────────────────────┐ * │ Canvas Container │ * │ ┌──────────────────────────────────────────────────────┐│ * │ │ Overlay Canvas (absolute, pointer-events: none) ││ * │ │ - Draws selection boxes ││ * │ │ - Draws hover highlights ││ * │ │ - Draws resize handles ││ * │ └──────────────────────────────────────────────────────┘│ * │ ┌──────────────────────────────────────────────────────┐│ * │ │ Iframe (editable HTML document) ││ * │ │ - Receives click events via selector.ts ││ * │ │ - Contains the page being edited ││ * │ └──────────────────────────────────────────────────────┘│ * └─────────────────────────────────────────────────────────┘ */ import React, { useRef, useEffect, useState, useCallback } from 'react'; import { SelectedElement } from '../types/editor'; import { setupIframeClickListener, updateElementRect, createSelectedElement } from '../utils/selector'; import { renderOverlay, clearOverlay } from '../utils/overlay'; interface CanvasProps { initialContent?: string; selectedElement: SelectedElement | null; onElementSelect: (element: SelectedElement | null) => void; showSpacing?: boolean; showDimensions?: boolean; deviceMode?: 'desktop' | 'tablet' | 'mobile'; } // Default HTML content for the iframe - blank canvas ready for sections const DEFAULT_CONTENT = `