From 54ceb7b631c22bbc835176b14f951afbd7290a9a Mon Sep 17 00:00:00 2001
From: ngqile
Date: Thu, 3 Dec 2026 15:15:32 +0800
Subject: [PATCH] feat(pages): page canvas and in-place editing of landing page
text
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
---
local/seed/04-zh-cn-messages.sql | 2 +
.../changes/add-page-visual-editor/tasks.md | 4 +-
.../components/pages/CmsBlocks.edit.test.tsx | 104 ++++++++++++
.../app/components/pages/CmsBlocks.tsx | 111 +++++++-----
.../app/components/pages/CmsEdit.tsx | 160 ++++++++++++++++++
.../app/components/pages/PageCanvas.test.tsx | 17 ++
.../app/components/pages/PageCanvas.tsx | 36 ++++
.../app/lib/i18n/defaultMessages.ts | 1 +
.../app/lib/i18n/zh_CN.seed.json | 1 +
9 files changed, 387 insertions(+), 49 deletions(-)
create mode 100644 solvway-admin-portal/app/components/pages/CmsBlocks.edit.test.tsx
create mode 100644 solvway-admin-portal/app/components/pages/CmsEdit.tsx
create mode 100644 solvway-admin-portal/app/components/pages/PageCanvas.test.tsx
create mode 100644 solvway-admin-portal/app/components/pages/PageCanvas.tsx
diff --git a/local/seed/04-zh-cn-messages.sql b/local/seed/04-zh-cn-messages.sql
index b182294..234fc90 100644
--- a/local/seed/04-zh-cn-messages.sql
+++ b/local/seed/04-zh-cn-messages.sql
@@ -1497,6 +1497,8 @@ INSERT INTO message (code, content, area) SELECT 'PagesLeaveMessage', JSON_OBJEC
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '此页面的修改尚未保存。离开将丢失这些修改,确定离开吗?') WHERE LOWER(code) = LOWER('PagesLeaveMessage') AND area = 'A';
INSERT INTO message (code, content, area) SELECT 'PagesLeave', JSON_OBJECT('en_US', 'Leave', 'zh_CN', '离开'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLeave') AND area = 'A');
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '离开') WHERE LOWER(code) = LOWER('PagesLeave') AND area = 'A';
+INSERT INTO message (code, content, area) SELECT 'PagesSaveToUpdate', JSON_OBJECT('en_US', 'Save to update', 'zh_CN', '保存后更新'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesSaveToUpdate') AND area = 'A');
+UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '保存后更新') WHERE LOWER(code) = LOWER('PagesSaveToUpdate') AND area = 'A';
INSERT INTO message (code, content, area) SELECT 'PagesChangesPublished', JSON_OBJECT('en_US', 'Changes published.', 'zh_CN', '修改已发布。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesChangesPublished') AND area = 'A');
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '修改已发布。') WHERE LOWER(code) = LOWER('PagesChangesPublished') AND area = 'A';
INSERT INTO message (code, content, area) SELECT 'PagesChangesDiscarded', JSON_OBJECT('en_US', 'Changes discarded.', 'zh_CN', '修改已放弃。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesChangesDiscarded') AND area = 'A');
diff --git a/openspec/changes/add-page-visual-editor/tasks.md b/openspec/changes/add-page-visual-editor/tasks.md
index ede4ec6..e2f8900 100644
--- a/openspec/changes/add-page-visual-editor/tasks.md
+++ b/openspec/changes/add-page-visual-editor/tasks.md
@@ -22,8 +22,8 @@ Design: `design.md`. Every task is TDD. Work is serial in the main session, with
## 2. Canvas
-- [ ] 2.1 `PageCanvas`: the frame, the Desktop view (1280 px scaled) and the Phone view (390 px), live updates from the draft, and links and buttons inert.
-- [ ] 2.2 Edit-mode hooks in `CmsBlocks`: `EditContext`, `EditableText` for every plain text field with its server limit, image spots, `Section` outline and `data-index`. Public rendering stays unchanged: the existing `CmsBlocks*.test.tsx` stay green.
+- [x] 2.1 `PageCanvas`: the frame, the Desktop view (1280 px scaled) and the Phone view (390 px), live updates from the draft, and links and buttons inert.
+- [x] 2.2 Edit-mode hooks in `CmsBlocks`: `EditContext`, `EditableText` for every plain text field with its server limit, image spots, `Section` outline and `data-index`. Public rendering stays unchanged: the existing `CmsBlocks*.test.tsx` stay green.
- [ ] 2.3 Rich text in place: `RichTextEditor` bare mode with a floating toolbar (test: an unsafe link is refused with a message).
- [ ] 2.4 Custom HTML on the canvas: the saved-draft frame, the "Save to update" mark, and a reload after save.
diff --git a/solvway-admin-portal/app/components/pages/CmsBlocks.edit.test.tsx b/solvway-admin-portal/app/components/pages/CmsBlocks.edit.test.tsx
new file mode 100644
index 0000000..8d01f8f
--- /dev/null
+++ b/solvway-admin-portal/app/components/pages/CmsBlocks.edit.test.tsx
@@ -0,0 +1,104 @@
+import { fireEvent, render, screen, within } from "@testing-library/react";
+import { describe, it, expect, vi } from "vitest";
+import { LandingPage, type PublicBlock } from "./CmsBlocks";
+import { setField, type PageEdit } from "./CmsEdit";
+
+// add-page-visual-editor: the page in edit mode. Text edits in place, sections select, images open the picker, and
+// nothing navigates. Without `edit` the page renders exactly as before (CmsBlocks*.test.tsx).
+const company = { code: "INS", name: "INS Sdn Bhd" };
+const page = (blocks: PublicBlock[]) => ({ slug: "hotel", title: "Hotel day", blocks });
+
+function editor(overrides: Partial = {}): PageEdit {
+ return {
+ selected: null, select: vi.fn(), text: vi.fn(), html: vi.fn(), image: vi.fn(),
+ preview: () => undefined, stale: () => false, frameVersion: 0, chrome: () => null, ...overrides,
+ };
+}
+
+const typeInto = (el: HTMLElement, value: string) => { el.textContent = value; fireEvent.input(el); };
+
+describe("LandingPage in edit mode", () => {
+ it("edits a heading, a card title and a FAQ answer in place as plain text", () => {
+ const edit = editor();
+ render( );
+ const heading = screen.getAllByRole("textbox", { name: "Heading" })[0];
+ expect(heading).toHaveAttribute("contenteditable", "plaintext-only");
+ expect(heading).toHaveTextContent("Hotel week");
+ typeInto(heading, "Hotel month");
+ expect(edit.text).toHaveBeenLastCalledWith(0, "heading", "Hotel month");
+
+ typeInto(screen.getAllByRole("textbox", { name: "Title" })[1], "Second");
+ expect(edit.text).toHaveBeenLastCalledWith(1, "cards.1.title", "Second");
+ typeInto(screen.getByRole("textbox", { name: "Answer 1" }), "Yes\nno");
+ expect(edit.text).toHaveBeenLastCalledWith(2, "items.0.answer", "Yes\nno");
+ });
+
+ it("offers an empty heading as a spot to type, and shows the limit once close to it", () => {
+ render( );
+ expect(screen.getByText("100/120")).toBeInTheDocument();
+ expect(screen.getAllByRole("textbox", { name: "Heading" })[1]).toHaveTextContent("");
+ });
+
+ it("selects a section on click, outlines the selected one, and draws the editor's tools in it", () => {
+ const edit = editor({ selected: 1, chrome: (i) => tools {i} });
+ render( );
+ const sections = document.querySelectorAll("[data-index]");
+ expect([...sections].map((s) => s.getAttribute("data-index"))).toEqual(["0", "1"]);
+ expect(sections[1]).toHaveAttribute("data-selected", "true");
+ expect(sections[0]).not.toHaveAttribute("data-selected");
+ expect(within(sections[1] as HTMLElement).getByText("tools 1")).toBeInTheDocument();
+ fireEvent.click(sections[0]);
+ expect(edit.select).toHaveBeenCalledWith(0);
+ });
+
+ it("keeps links and buttons from navigating, and edits a button's label", () => {
+ const edit = editor();
+ render( );
+ const label = screen.getByRole("textbox", { name: "Button label" });
+ const link = label.closest("a")!;
+ expect(fireEvent.click(link)).toBe(false); // default prevented
+ typeInto(label, "Join now");
+ expect(edit.text).toHaveBeenLastCalledWith(0, "buttonLabel", "Join now");
+ });
+
+ it("opens the picker from an image spot and shows a chosen image before it is saved", () => {
+ const edit = editor({ preview: (i) => (i === 0 ? "data:image/png;base64,AAAA" : undefined) });
+ render( );
+ const spots = screen.getAllByRole("button", { name: "Image" });
+ expect(spots).toHaveLength(2);
+ expect(spots[0].querySelector("img")).toHaveAttribute("src", "data:image/png;base64,AAAA");
+ fireEvent.click(spots[1]);
+ expect(edit.image).toHaveBeenCalledWith(1);
+ });
+
+ it("shows a Custom HTML block's saved version, selectable, marked while its HTML has unsaved edits", () => {
+ const edit = editor({ stale: (i) => i === 0, frameVersion: 3 });
+ render(x
" }])} edit={edit} preview frameBase="/pages/5/preview/frame" />);
+ expect(document.querySelector("iframe")).toHaveAttribute("src", "/pages/5/preview/frame/0?v=3");
+ expect(screen.getByText("Save to update")).toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: "Custom HTML" }));
+ expect(edit.select).toHaveBeenCalledWith(0);
+ });
+
+ it("renders no editing without edit mode", () => {
+ render( );
+ expect(document.querySelector("[contenteditable]")).toBeNull();
+ expect(document.querySelector("[data-index]")).toBeNull();
+ expect(screen.queryByRole("button")).toBeNull();
+ expect(screen.getByRole("heading", { level: 2, name: "Hotel week" })).toBeInTheDocument();
+ });
+});
+
+describe("setField", () => {
+ it("sets a top-level field or one inside a card or question, leaving the rest", () => {
+ const block = { type: "FEATURES" as const, heading: "H", cards: [{ title: "A", text: "a" }, { title: "B" }] };
+ expect(setField(block, "heading", "New")).toEqual({ ...block, heading: "New" });
+ expect(setField(block, "cards.1.title", "C").cards).toEqual([{ title: "A", text: "a" }, { title: "C" }]);
+ expect(block.cards[1].title).toBe("B");
+ expect(setField({ type: "FAQ", items: [{ question: "Q", answer: "A" }] }, "items.0.answer", "Z").items).toEqual([{ question: "Q", answer: "Z" }]);
+ });
+});
diff --git a/solvway-admin-portal/app/components/pages/CmsBlocks.tsx b/solvway-admin-portal/app/components/pages/CmsBlocks.tsx
index 95ab27e..7b381cb 100644
--- a/solvway-admin-portal/app/components/pages/CmsBlocks.tsx
+++ b/solvway-admin-portal/app/components/pages/CmsBlocks.tsx
@@ -4,6 +4,7 @@ import type { RegistrationInfo } from "@/app/lib/services/publicRegistration";
import { SafeHtml } from "./SafeHtml";
import { LandingForm } from "./LandingForm";
import { HtmlFrame } from "./HtmlFrame";
+import { EditContext, EditSection, HeroShade, HtmlSpot, ImageSpot, Text, stopNavigation, type PageEdit } from "./CmsEdit";
// 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. A Custom HTML block is
@@ -28,34 +29,34 @@ const BANDS: Record, string> = {
};
const bandOf = (look: unknown) => (LOOKS.includes(look as Look) && look !== "DEFAULT" ? (look as Exclude) : null);
-function ButtonLink({ block }: { block: CmsBlock }) {
- if (!block.buttonLabel || !isSafeLink(block.buttonUrl)) return null;
+function ButtonLink({ block, index, edit }: { block: CmsBlock; index: number; edit?: boolean }) {
+ // In edit mode a button with a label shows whatever its link, so its label can be typed in place.
+ if (!block.buttonLabel || (!edit && !isSafeLink(block.buttonUrl))) return null;
const external = /^https:/i.test(block.buttonUrl!);
const colours = bandOf(block.look) === "ACCENT" ? "bg-background text-foreground" : "bg-primary text-primary-foreground";
return (
- {block.buttonLabel}
+
);
}
-function BlockImage({ id, className }: { id?: number | null; className: string }) {
- // eslint-disable-next-line @next/next/no-img-element -- an uploaded image of unknown size
- return id ? : null;
-}
-
-function Block({ block, index, company, slug, preview }: { block: PublicBlock; index: number; company: string; slug: string; preview?: boolean }) {
+function Block({ block, index, company, slug, preview, edit }: { block: PublicBlock; index: number; company: string; slug: string; preview?: boolean; edit?: boolean }) {
+ const image = block.imageId ? imageSrc(block.imageId) : undefined;
+ const button = ;
switch (block.type) {
case "HERO":
return (
-
-
- {block.heading ?
{block.heading} : null}
- {block.text ?
{block.text}
: null}
-
-
+
+
+
+
+ {button}
+
);
case "RICH_TEXT":
@@ -63,32 +64,43 @@ function Block({ block, index, company, slug, preview }: { block: PublicBlock; i
case "IMAGE_TEXT":
return (
-
+ {image || edit ? (
+
+
+
+ ) : null}
- {block.heading ?
{block.heading} : null}
+
{block.html ? : null}
-
+ {button}
);
case "FAQ":
return block.items?.length ? (
- {block.heading ? {block.heading} : null}
+
- {block.items.map((item, i) => (
-
- {item.question}
- {item.answer}
-
- ))}
+ {block.items.map((item, i) => {
+ const question =
;
+ const answer =
;
+ // In edit mode every answer shows: a
would toggle on a click or a typed space.
+ return edit ? (
+
+ ) : (
+
+ {item.question}
+ {answer}
+
+ );
+ })}
) : null;
case "FORM":
return (
- {block.heading ? {block.heading} : null}
+
);
@@ -96,8 +108,8 @@ function Block({ block, index, company, slug, preview }: { block: PublicBlock; i
return (
- {block.heading ?
{block.heading} : null}
- {block.text ?
{block.text}
: null}
+
+
{(block.cards ?? []).map((card, i) => {
@@ -105,8 +117,8 @@ function Block({ block, index, company, slug, preview }: { block: PublicBlock; i
return (
{Icon ? : null}
- {card.title}
- {card.text}
+
+
);
})}
@@ -116,14 +128,14 @@ function Block({ block, index, company, slug, preview }: { block: PublicBlock; i
case "STEPS":
return (
- {block.heading ? {block.heading} : null}
+
{(block.cards ?? []).map((card, i) => (
{i + 1}
-
{card.title}
-
{card.text}
+
+
))}
@@ -134,16 +146,16 @@ function Block({ block, index, company, slug, preview }: { block: PublicBlock; i
return (
- {(block.cards ?? []).map((card, i) => {card.title} )}
+ {(block.cards ?? []).map((card, i) => )}
);
case "CTA":
return (
- {block.heading}
- {block.text ? {block.text}
: null}
-
+
+
+ {button}
);
default:
@@ -154,13 +166,15 @@ function Block({ block, index, company, slug, preview }: { block: PublicBlock; i
const WIDTH = "mx-auto w-full max-w-5xl px-4";
/** A block in the page width; with a non-default look, inside a full-width band of that colour. */
-function Section({ block, children }: { block: PublicBlock; children: ReactNode }) {
+function Section({ block, index, children }: { block: PublicBlock; index: number; children: ReactNode }) {
const band = bandOf(block.look);
- if (!band) return {children}
;
+ if (!band) return {children}
;
return (
-
+
+
+
);
}
@@ -168,7 +182,7 @@ function Section({ block, children }: { block: PublicBlock; children: ReactNode
* 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 }: {
+export function LandingPage({ company, page, banner, preview, frameBase, edit }: {
company: Branding;
page: { slug: string; title: string; hideHeader?: boolean; blocks: PublicBlock[] };
banner?: ReactNode;
@@ -176,12 +190,14 @@ export function LandingPage({ company, page, banner, preview, frameBase }: {
preview?: boolean;
/** Where block frames load from; the public page's frame address by default. */
frameBase?: string;
+ /** The on-page editor's canvas (add-page-visual-editor): text edits in place and nothing navigates. */
+ edit?: PageEdit;
}) {
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 (
-
+ const body = (
+
{banner}
{page.hideHeader ? null :
@@ -197,10 +213,11 @@ export function LandingPage({ company, page, banner, preview, frameBase }: {
{page.title}
{page.blocks.map((block, i) => block.type === "HTML"
- ?
- : )}
+ ?
+ : )}
);
+ return edit ? {body} : body;
}
diff --git a/solvway-admin-portal/app/components/pages/CmsEdit.tsx b/solvway-admin-portal/app/components/pages/CmsEdit.tsx
new file mode 100644
index 0000000..40b1884
--- /dev/null
+++ b/solvway-admin-portal/app/components/pages/CmsEdit.tsx
@@ -0,0 +1,160 @@
+"use client";
+
+import { createContext, useContext, useLayoutEffect, useRef, type ElementType, type FormEvent, type KeyboardEvent, type MouseEvent, type ReactNode } from "react";
+import { ImagePlus } from "lucide-react";
+import { BLOCK_LABELS, type CmsBlock } from "@/app/lib/cmsPages";
+import { useT } from "@/app/lib/i18n/MessagesProvider";
+
+// add-page-visual-editor: the landing page in edit mode, on the on-page editor's canvas. The public page and the
+// preview never provide an edit context, so every part here renders exactly the public markup without one.
+
+export interface PageEdit {
+ /** The selected block's index, or null. */
+ selected: number | null;
+ select(index: number): void;
+ /** A plain text field changed: `path` is "heading", "text", "buttonLabel", "cards..title|text" or "items..question|answer". */
+ text(index: number, path: string, value: string): void;
+ /** A rich text block's HTML changed. */
+ html(index: number, html: string): void;
+ /** An image spot was clicked: the editor opens its file picker. */
+ image(index: number): void;
+ /** A chosen image not yet uploaded, as a data URL. */
+ preview(index: number): string | undefined;
+ /** A Custom HTML block whose HTML has unsaved edits: its frame still shows the saved version. */
+ stale(index: number): boolean;
+ /** Bumped after each save, so Custom HTML frames reload the saved version. */
+ frameVersion: number;
+ /** The editor's own tools for a selected section (toolbar, add section). */
+ chrome(index: number): ReactNode;
+}
+
+export const EditContext = createContext(null);
+export const useEdit = () => useContext(EditContext);
+
+/** The block with one plain text field set, by its path (see PageEdit.text). */
+export function setField(block: CmsBlock, path: string, value: string): CmsBlock {
+ const [list, at, key] = path.split(".");
+ if (key === undefined) return { ...block, [list]: value };
+ const items = [...((block[list as "cards" | "items"] ?? []) as object[])];
+ items[Number(at)] = { ...items[Number(at)], [key]: value };
+ return { ...block, [list]: items };
+}
+
+/**
+ * A plain text field: the text as-is on the public page; in edit mode the same element, typed into in place. It is
+ * never re-rendered from its value while focused, so the caret stays where it is.
+ */
+export function Text({ as: Tag, index, path, value, max, code, n, className, multiline }: {
+ as: ElementType;
+ index: number;
+ path: string;
+ value: string | undefined;
+ max: number;
+ /** The field's label code, the editable's name; `n` fills its {number}. */
+ code: string;
+ n?: number;
+ className?: string;
+ multiline?: boolean;
+}) {
+ const edit = useEdit();
+ if (!edit) return value ? {value} : null;
+ return ;
+}
+
+function EditableText({ as: Tag, edit, index, path, value, max, code, n, className, multiline }: {
+ as: ElementType; edit: PageEdit; index: number; path: string; value: string; max: number; code: string; n?: number; className?: string; multiline?: boolean;
+}) {
+ const t = useT();
+ const ref = useRef(null);
+ useLayoutEffect(() => {
+ const el = ref.current;
+ if (el && el.ownerDocument.activeElement !== el && el.textContent !== value) el.textContent = value;
+ }, [value]);
+ const near = value.length > max * 0.8;
+ const name = t(code, n === undefined ? undefined : { number: n });
+ return (
+ <>
+ ) => edit.text(index, path, e.currentTarget.textContent ?? "")}
+ onKeyDown={(e: KeyboardEvent) => { if (e.key === "Enter" && !multiline) e.preventDefault(); }} />
+ {near ? max ? "text-destructive" : "opacity-60"}`}>{`${value.length}/${max}`} : null}
+ >
+ );
+}
+
+/**
+ * An image of a block: in edit mode a button that opens the editor's file picker, showing a chosen image at once.
+ * A background image (`corner`) stays as it is, with a small button in the corner instead.
+ */
+export function ImageSpot({ index, src, className, corner }: { index: number; src: string | undefined; className: string; corner?: boolean }) {
+ const t = useT();
+ const edit = useEdit();
+ const shown = edit?.preview(index) ?? src;
+ // eslint-disable-next-line @next/next/no-img-element -- an uploaded image of unknown size
+ const img = shown ? : null;
+ if (!edit) return img;
+ const open = (e: MouseEvent) => { e.stopPropagation(); edit.select(index); edit.image(index); };
+ if (corner) {
+ return (
+ <>
+ {img}
+
+
+
+ >
+ );
+ }
+ return (
+
+ {img ?? }
+
+
+ );
+}
+
+/** In edit mode, the whole page: clicks never follow a link or submit. */
+export function stopNavigation(e: MouseEvent) {
+ if ((e.target as Element).closest("a[href], button[type=submit], form")) e.preventDefault();
+}
+
+/** A section's frame in edit mode: selected on click, outlined when hovered or selected, with the editor's tools. */
+export function EditSection({ index, children }: { index: number; children: ReactNode }) {
+ const edit = useEdit();
+ if (!edit) return <>{children}>;
+ const selected = edit.selected === index;
+ return (
+ edit.select(index)}
+ className={`relative outline-offset-2 hover:outline-dashed hover:outline-1 hover:outline-primary/60 ${selected ? "outline-2 outline-primary hover:outline-solid hover:outline-2" : ""}`}>
+ {children}
+ {edit.chrome(index)}
+
+ );
+}
+
+/** A Custom HTML block in edit mode: its saved version, covered so a click selects it, marked while unsaved. */
+export function HtmlSpot({ index, children }: { index: number; children: ReactNode }) {
+ const t = useT();
+ const edit = useEdit();
+ if (!edit) return <>{children}>;
+ return (
+
+
+ {children}
+ edit.select(index)} />
+ {edit.stale(index) ? (
+ {t("PagesSaveToUpdate")}
+ ) : null}
+
+
+ );
+}
+
+/** The hero's text area: shaded over an image, including one chosen in the editor and not saved yet. */
+export function HeroShade({ index, image, shaded, plain, children }: { index: number; image: boolean; shaded: string; plain: string; children: ReactNode }) {
+ const edit = useEdit();
+ return {children}
;
+}
diff --git a/solvway-admin-portal/app/components/pages/PageCanvas.test.tsx b/solvway-admin-portal/app/components/pages/PageCanvas.test.tsx
new file mode 100644
index 0000000..c643aa5
--- /dev/null
+++ b/solvway-admin-portal/app/components/pages/PageCanvas.test.tsx
@@ -0,0 +1,17 @@
+import { render, waitFor, within } from "@testing-library/react";
+import { describe, it, expect } from "vitest";
+import { PageCanvas } from "./PageCanvas";
+
+// add-page-visual-editor: the canvas is a device screen, Desktop 1280 px (scaled to fit) or Phone 390 px.
+const frame = () => document.querySelector("iframe") as HTMLIFrameElement;
+
+describe("PageCanvas", () => {
+ it("shows the page on a 1280 px desktop screen or a 390 px phone screen", async () => {
+ const { rerender } = render(Hello
);
+ expect(frame()).toHaveStyle({ width: "1280px" });
+ await waitFor(() => expect(within(frame().contentDocument!.body).getByText("Hello")).toBeInTheDocument());
+ rerender(Hello
);
+ expect(frame()).toHaveStyle({ width: "390px" });
+ expect(within(frame().contentDocument!.body).getByText("Hello")).toBeInTheDocument();
+ });
+});
diff --git a/solvway-admin-portal/app/components/pages/PageCanvas.tsx b/solvway-admin-portal/app/components/pages/PageCanvas.tsx
new file mode 100644
index 0000000..9234e6c
--- /dev/null
+++ b/solvway-admin-portal/app/components/pages/PageCanvas.tsx
@@ -0,0 +1,36 @@
+"use client";
+
+import { useEffect, useRef, useState, type ReactNode } from "react";
+import { CanvasFrame } from "./CanvasFrame";
+
+export type Device = "DESKTOP" | "PHONE";
+
+/**
+ * The on-page editor's canvas (add-page-visual-editor, design Decision 2): the page on a device screen. Desktop is a
+ * 1280 px screen scaled down to the space it has, so a laptop shows the desktop layout; Phone is 390 px at full size.
+ */
+export function PageCanvas({ device, title, children }: { device: Device; title: string; children: ReactNode }) {
+ const box = useRef(null);
+ const [space, setSpace] = useState({ width: 0, height: 0 });
+ useEffect(() => {
+ const el = box.current;
+ if (!el) return;
+ const measure = () => setSpace({ width: el.clientWidth, height: el.clientHeight });
+ const observer = new ResizeObserver(measure);
+ observer.observe(el);
+ measure();
+ return () => observer.disconnect();
+ }, []);
+ const width = device === "PHONE" ? 390 : 1280;
+ const scale = device === "PHONE" || !space.width ? 1 : Math.min(1, space.width / width);
+ const height = (space.height || 800) / scale;
+ return (
+
+ );
+}
diff --git a/solvway-admin-portal/app/lib/i18n/defaultMessages.ts b/solvway-admin-portal/app/lib/i18n/defaultMessages.ts
index 61ff546..1a3a02b 100644
--- a/solvway-admin-portal/app/lib/i18n/defaultMessages.ts
+++ b/solvway-admin-portal/app/lib/i18n/defaultMessages.ts
@@ -760,6 +760,7 @@ export const DEFAULT_MESSAGES: Record = {
PagesLeaveTitle: "Leave without saving?",
PagesLeaveMessage: "Your changes to this page are not saved. Leave and lose them?",
PagesLeave: "Leave",
+ PagesSaveToUpdate: "Save to update",
PagesChangesPublished: "Changes published.",
PagesChangesDiscarded: "Changes discarded.",
PagesPreviewDraftBanner: "Preview of unpublished changes. Visitors still see the published version.",
diff --git a/solvway-admin-portal/app/lib/i18n/zh_CN.seed.json b/solvway-admin-portal/app/lib/i18n/zh_CN.seed.json
index b23dd82..8bac871 100644
--- a/solvway-admin-portal/app/lib/i18n/zh_CN.seed.json
+++ b/solvway-admin-portal/app/lib/i18n/zh_CN.seed.json
@@ -744,6 +744,7 @@
"PagesLeaveTitle": "不保存就离开?",
"PagesLeaveMessage": "此页面的修改尚未保存。离开将丢失这些修改,确定离开吗?",
"PagesLeave": "离开",
+ "PagesSaveToUpdate": "保存后更新",
"PagesChangesPublished": "修改已发布。",
"PagesChangesDiscarded": "修改已放弃。",
"PagesPreviewDraftBanner": "未发布修改的预览。访客看到的仍是已发布的版本。",