diff --git a/openspec/changes/add-custom-html-block/tasks.md b/openspec/changes/add-custom-html-block/tasks.md
index a43fdf8..271fc3e 100644
--- a/openspec/changes/add-custom-html-block/tasks.md
+++ b/openspec/changes/add-custom-html-block/tasks.md
@@ -17,7 +17,7 @@ Design: `design.md` and `docs/superpowers/specs/2026-12-02-custom-html-block-des
- [x] 2.1 Frame routes (public and preview) with the sandbox headers, the 404 rules and the height script.
- The middleware skips them; `routeGuard` admits the public frame path.
- Security code: read the whole diff.
-- [ ] 2.2 `CmsBlocks`:
+- [x] 2.2 `CmsBlocks`:
- the sandboxed iframe with height messages from its own frame only;
- `hideHeader` hides the header and the title.
- [ ] 2.3 Editor:
diff --git a/solvway-admin-portal/app/components/pages/CmsBlocks.html.test.tsx b/solvway-admin-portal/app/components/pages/CmsBlocks.html.test.tsx
new file mode 100644
index 0000000..6711a1e
--- /dev/null
+++ b/solvway-admin-portal/app/components/pages/CmsBlocks.html.test.tsx
@@ -0,0 +1,43 @@
+import { act, render, screen } from "@testing-library/react";
+import { describe, it, expect } from "vitest";
+import { LandingPage, type PublicBlock } from "./CmsBlocks";
+import { FRAME_SANDBOX } from "@/app/lib/frameHtml";
+
+// add-custom-html-block: an HTML block is a sealed frame sized by its own reports; "hide header" drops the header.
+const company = { code: "INS", name: "INS Sdn Bhd", logoImageId: 4, accentColor: null };
+const page = (blocks: PublicBlock[], hideHeader = false) => ({ slug: "hotel", title: "Hotel day", hideHeader, blocks });
+const HTML: PublicBlock = { type: "HTML", html: "
Designed
" };
+
+const frame = () => document.querySelector("iframe") as HTMLIFrameElement;
+
+describe("LandingPage: Custom HTML", () => {
+ it("shows an HTML block as a sealed frame from its own address, never inline", () => {
+ render();
+ expect(frame()).toHaveAttribute("src", "/p/INS/hotel/frame/1");
+ expect(frame()).toHaveAttribute("sandbox", FRAME_SANDBOX);
+ expect(frame()).toHaveAttribute("title", "Hotel day");
+ expect(frame().style.height).toBe("600px");
+ expect(screen.queryByText("Designed")).not.toBeInTheDocument();
+ expect(document.querySelector("script")).toBeNull();
+ });
+
+ it("uses the preview's frame address when given", () => {
+ render();
+ expect(frame()).toHaveAttribute("src", "/pages/5/preview/frame/0");
+ });
+
+ it("grows to its frame's reported height and ignores other windows", () => {
+ render();
+ act(() => { window.dispatchEvent(new MessageEvent("message", { data: { type: "colite-frame-height", height: 2400 }, source: window })); });
+ expect(frame().style.height).toBe("600px");
+ act(() => { window.dispatchEvent(new MessageEvent("message", { data: { type: "colite-frame-height", height: 2400 }, source: frame().contentWindow })); });
+ expect(frame().style.height).toBe("2400px");
+ });
+
+ it("hides the company header and shows the title to screen readers only when the page says so", () => {
+ render();
+ expect(screen.queryByRole("img", { name: "INS Sdn Bhd" })).not.toBeInTheDocument();
+ expect(document.querySelector("header")).toBeNull();
+ expect(screen.getByRole("heading", { level: 1, name: "Hotel day" })).toHaveClass("sr-only");
+ });
+});
diff --git a/solvway-admin-portal/app/components/pages/CmsBlocks.tsx b/solvway-admin-portal/app/components/pages/CmsBlocks.tsx
index 66e4cf1..42de083 100644
--- a/solvway-admin-portal/app/components/pages/CmsBlocks.tsx
+++ b/solvway-admin-portal/app/components/pages/CmsBlocks.tsx
@@ -3,9 +3,11 @@ import { contrastText, imageSrc, isSafeLink, type CmsBlock } from "@/app/lib/cms
import type { RegistrationInfo } from "@/app/lib/services/publicRegistration";
import { SafeHtml } from "./SafeHtml";
import { LandingForm } from "./LandingForm";
+import { HtmlFrame } from "./HtmlFrame";
// Landing-page blocks, ported from babyboo's CmsBlocks minus the product blocks. HTML only goes through SafeHtml;
-// images are this company's uploads; buttons render only for a safe link, checked again here.
+// images are this company's uploads; buttons render only for a safe link, checked again here. A Custom HTML block is
+// never rendered here: it is a sealed frame loaded from its own address (add-custom-html-block).
export type PublicBlock = CmsBlock & { form?: RegistrationInfo; closed?: boolean };
@@ -86,20 +88,28 @@ function Block({ block, index, company, slug, preview }: { block: PublicBlock; i
}
}
-/** A whole landing page: the company header (logo, accent), the title as the only h1, then the blocks. */
-export function LandingPage({ company, page, banner, preview }: {
+const WIDTH = "mx-auto w-full max-w-5xl px-4";
+
+/**
+ * A whole landing page: the company header (logo, accent), the title as the only h1, then the blocks. Custom HTML
+ * blocks run full width; with hideHeader the header goes and the title is for screen readers only.
+ */
+export function LandingPage({ company, page, banner, preview, frameBase }: {
company: Branding;
- page: { slug: string; title: string; blocks: PublicBlock[] };
+ page: { slug: string; title: string; hideHeader?: boolean; blocks: PublicBlock[] };
banner?: ReactNode;
/** The editor's draft preview: forms show a note instead of taking sign-ups. */
preview?: boolean;
+ /** Where block frames load from; the public page's frame address by default. */
+ frameBase?: string;
}) {
+ const frames = frameBase ?? `/p/${encodeURIComponent(company.code)}/${encodeURIComponent(page.slug)}/frame`;
const accent = company.accentColor && /^#[0-9A-Fa-f]{6}$/.test(company.accentColor) ? company.accentColor : null;
const style = accent ? ({ "--primary": accent, "--primary-foreground": contrastText(accent), "--ring": accent } as CSSProperties) : undefined;
return (
{banner}
-
}
+
+ {page.title}
+ {page.blocks.map((block, i) => block.type === "HTML"
+ ?
+ :
)}
);
diff --git a/solvway-admin-portal/app/components/pages/HtmlFrame.tsx b/solvway-admin-portal/app/components/pages/HtmlFrame.tsx
new file mode 100644
index 0000000..e64922a
--- /dev/null
+++ b/solvway-admin-portal/app/components/pages/HtmlFrame.tsx
@@ -0,0 +1,19 @@
+"use client";
+
+import { useEffect, useRef, useState } from "react";
+import { FRAME_SANDBOX, nextFrameHeight, START_HEIGHT, type FrameHeight } from "@/app/lib/frameHtml";
+
+/** A Custom HTML block: the sealed frame, sized by height reports from that frame's own window only. */
+export function HtmlFrame({ src, title }: { src: string; title: string }) {
+ const ref = useRef(null);
+ const [size, setSize] = useState({ height: START_HEIGHT, steps: [] });
+ useEffect(() => {
+ const onMessage = (e: MessageEvent) => {
+ if (!ref.current || e.source !== ref.current.contentWindow) return;
+ setSize((s) => nextFrameHeight(s, e.data));
+ };
+ window.addEventListener("message", onMessage);
+ return () => window.removeEventListener("message", onMessage);
+ }, []);
+ return ;
+}
diff --git a/solvway-admin-portal/app/lib/cmsPages.ts b/solvway-admin-portal/app/lib/cmsPages.ts
index ca1e542..5d8d218 100644
--- a/solvway-admin-portal/app/lib/cmsPages.ts
+++ b/solvway-admin-portal/app/lib/cmsPages.ts
@@ -1,7 +1,7 @@
// Landing-page blocks and the editor's pure helpers (add-landing-pages), ported from babyboo's cmsPages.ts
// minus the product blocks. Images are page_image ids, served at /api/public/page-images/.
-export type BlockType = "HERO" | "RICH_TEXT" | "IMAGE_TEXT" | "FAQ" | "FORM";
+export type BlockType = "HERO" | "RICH_TEXT" | "IMAGE_TEXT" | "FAQ" | "FORM" | "HTML";
export const BLOCK_TYPES: BlockType[] = ["HERO", "RICH_TEXT", "IMAGE_TEXT", "FAQ", "FORM"];
@@ -11,6 +11,7 @@ export const BLOCK_LABELS: Record = {
IMAGE_TEXT: "PagesBlockImageText",
FAQ: "PagesBlockFaq",
FORM: "PagesBlockForm",
+ HTML: "PagesBlockHtml",
};
export interface CmsFaqItem {
diff --git a/solvway-admin-portal/app/p/[company]/[slug]/page.tsx b/solvway-admin-portal/app/p/[company]/[slug]/page.tsx
index 892d420..7695318 100644
--- a/solvway-admin-portal/app/p/[company]/[slug]/page.tsx
+++ b/solvway-admin-portal/app/p/[company]/[slug]/page.tsx
@@ -10,7 +10,7 @@ type Props = { params: Promise<{ company: string; slug: string }> };
interface PublicPage {
company: Branding;
- page: { slug: string; title: string; metaDescription?: string | null; blocks: PublicBlock[] };
+ page: { slug: string; title: string; metaDescription?: string | null; hideHeader?: boolean; blocks: PublicBlock[] };
}
const load = cache(async (company: string, slug: string): Promise => {
diff --git a/solvway-admin-portal/app/pages/[id]/preview/page.tsx b/solvway-admin-portal/app/pages/[id]/preview/page.tsx
index 220e657..067d4d4 100644
--- a/solvway-admin-portal/app/pages/[id]/preview/page.tsx
+++ b/solvway-admin-portal/app/pages/[id]/preview/page.tsx
@@ -12,6 +12,7 @@ type Props = { params: Promise<{ id: string }> };
interface AdminPage {
slug: string;
title: string;
+ hideHeader?: boolean;
blocks: PublicBlock[];
company?: Branding;
}
@@ -27,7 +28,7 @@ export default async function PagePreview({ params }: Props) {
const banner = {t("PagesPreviewBanner")}
;
return (
-
+
);
}