diff --git a/craft/src/editor/Canvas.tsx b/craft/src/editor/Canvas.tsx index bb67cbc..69d11ce 100644 --- a/craft/src/editor/Canvas.tsx +++ b/craft/src/editor/Canvas.tsx @@ -5,6 +5,7 @@ import { usePages } from '../state/PageContext'; import { useDevice } from '../state/DeviceContext'; import { DEVICE_WIDTHS } from '../constants/presets'; import { exportBodyHtml } from '../utils/html-export'; +import { applyResponsiveCssForDevice } from '../utils/responsive-style'; import { useIsMobile } from '../hooks/useIsMobile'; import { useMobileChrome } from '../state/MobileChromeContext'; import { useSitesmithModal } from '../state/SitesmithContext'; @@ -21,21 +22,24 @@ interface CanvasProps { * Renders the actual header/footer content from the Craft.js state as a * non-interactive preview. This is the user's own authored content. */ -const ZonePreview: React.FC<{ craftState: string | null; zone: 'header' | 'footer' }> = ({ +export const ZonePreview: React.FC<{ craftState: string | null; zone: 'header' | 'footer' }> = ({ craftState, zone, }) => { const containerRef = useRef(null); + const { device } = useDevice(); + // Per-device overrides follow the editor's device mode, not the browser + // viewport the exported @media rules would evaluate against. const renderedHtml = useMemo(() => { if (!craftState) return null; try { const result = exportBodyHtml(craftState, zone); - return result.html || null; + return result.html ? applyResponsiveCssForDevice(result.html, device) : null; } catch { return null; } - }, [craftState, zone]); + }, [craftState, zone, device]); // Set the rendered HTML into the container via ref (user-authored content) useEffect(() => { diff --git a/craft/src/editor/ZonePreview.device.test.tsx b/craft/src/editor/ZonePreview.device.test.tsx new file mode 100644 index 0000000..13dc58c --- /dev/null +++ b/craft/src/editor/ZonePreview.device.test.tsx @@ -0,0 +1,62 @@ +import React from 'react'; +import { describe, test, expect, afterEach } from 'vitest'; +import { createRoot, Root } from 'react-dom/client'; +import { act } from 'react-dom/test-utils'; +import { DeviceProvider } from '../state/DeviceContext'; +import { ZonePreview } from './Canvas'; +import type { DeviceMode } from '../types'; + +/** + * Minor finding: tablet/mobile editor modes did not show per-device overrides in + * the header/footer zone previews -- the exported `