Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-7919: feat(editor): preserve loaded HTML previews when enlarging (#9121)

Frezcb335d526e1df
diff --git a/e2e/html-preview-fullscreen.spec.ts b/e2e/html-preview-fullscreen.spec.ts
new file mode 100644
index 0000000000..184688999f
--- /dev/null
+++ b/e2e/html-preview-fullscreen.spec.ts
@@ -0,0 +1,285 @@
+import { expect, test, type Locator } from "@playwright/test";
+import { createTestApi, loginAsDefault } from "./helpers";
+import type { TestApiClient } from "./fixtures";
+
+const html = `<style>html,body{margin:0;padding:0}</style>
+<div style="height:480px"><input aria-label="Retained input" value="initial"></div>
+${"<!-- long source -->\n".repeat(100)}`;
+const content = `${"Paragraph before the preview.\n\n".repeat(60)}\`\`\`html\n${html}\n\`\`\``;
+
+function readScroll(element: HTMLElement) {
+ return { top: element.scrollTop, height: element.scrollHeight };
+}
+
+async function scrollContainer(block: Locator) {
+ return block.evaluateHandle((element) => {
+ for (let parent = element.parentElement; parent; parent = parent.parentElement) {
+ if (
+ /auto|scroll/.test(getComputedStyle(parent).overflowY) &&
+ parent.scrollHeight > parent.clientHeight
+ ) {
+ return parent;
+ }
+ }
+ throw new Error("Expected the issue's outer scroll container");
+ });
+}
+
+test.describe("HTML preview fullscreen", () => {
+ let api: TestApiClient;
+ let workspaceSlug: string;
+
+ test.beforeEach(async ({ page, baseURL }) => {
+ // These fixtures create isolated local workspaces, never shared-site data.
+ const local = (url: string) =>
+ ["localhost", "127.0.0.1", "[::1]"].includes(new URL(url).hostname);
+ test.skip(
+ !local(baseURL!) || !local(process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080"),
+ "Local fixtures only",
+ );
+ await page.setViewportSize({ width: 1440, height: 1080 });
+ api = await createTestApi();
+ workspaceSlug = await loginAsDefault(page);
+ });
+
+ test.afterEach(async () => {
+ await api?.cleanup();
+ });
+
+ for (const location of ["description", "reply"] as const) {
+ test(`${location} keeps its outer scroll position and loaded iframe`, async ({
+ page,
+ }, testInfo) => {
+ const issue = await api.createIssue(`HTML preview ${location}`, {
+ description: location === "description" ? content : "Reply preview regression",
+ });
+ const comment = location === "reply" ? await api.createComment(issue.id, content) : null;
+ await page.goto(`/${workspaceSlug}/issues/${issue.identifier}`, {
+ waitUntil: "domcontentloaded",
+ });
+ const outer = await scrollContainer(
+ page.getByText("Paragraph before the preview.", { exact: true }).first(),
+ );
+ await outer.evaluate((element) => {
+ element.scrollTop = element.scrollHeight - element.clientHeight;
+ });
+ const block = page.locator(
+ location === "description"
+ ? ".code-block-wrapper"
+ : `[data-comment-content="${comment!.id}"] [data-dynamic-block="html"]`,
+ );
+ await block.scrollIntoViewIfNeeded();
+ const iframe = block.locator("iframe");
+ await expect(iframe).toBeVisible();
+ await expect.poll(async () => (await iframe.boundingBox())?.height).toBe(480);
+ const input = iframe.contentFrame().getByRole("textbox", { name: "Retained input" });
+ await expect(input).toBeVisible();
+ const frameElement = await iframe.elementHandle();
+ const frame = (await frameElement!.contentFrame())!;
+ await input.fill("Keep this document");
+ const timeOrigin = await frame.evaluate(() => performance.timeOrigin);
+ const scroller = await scrollContainer(block);
+ await scroller.evaluate((element) => {
+ element.scrollTop = element.scrollHeight - element.clientHeight;
+ });
+ const before = await scroller.evaluate(readScroll);
+ expect(before.top).toBeGreaterThan(480);
+ const blockHeight = (await block.boundingBox())!.height;
+ const opener = block.getByRole("button", { name: "Fullscreen" });
+ await block.hover();
+ await testInfo.attach(`${location}-inline`, {
+ body: await page.screenshot(),
+ contentType: "image/png",
+ });
+ await expect(opener).toBeInViewport();
+
+ for (let round = 0; round < 3; round++) {
+ await opener.click();
+ const dialog = page.getByRole("dialog");
+ await expect(dialog).toBeVisible();
+ if (round === 0)
+ await testInfo.attach(`${location}-enlarged`, {
+ body: await page.screenshot(),
+ contentType: "image/png",
+ });
+ expect(
+ await dialog.locator("iframe").evaluate((element, original) => element === original, frameElement),
+ ).toBe(true);
+ expect((await dialog.boundingBox())!.height).toBe(972);
+ await expect.poll(async () => scroller.evaluate(readScroll)).toEqual(before);
+ expect((await block.boundingBox())!.height).toBe(blockHeight);
+ await expect(input).toHaveValue("Keep this document");
+ expect(await frame.evaluate(() => performance.timeOrigin)).toBe(timeOrigin);
+ if (round === 0) {
+ await page.getByRole("button", { name: "Close", exact: true }).click();
+ } else if (round === 1) {
+ await page.mouse.click(4, 4);
+ } else {
+ await page.keyboard.press("Escape");
+ }
+ await expect(page.getByRole("dialog")).toHaveCount(0);
+ await expect.poll(async () => scroller.evaluate(readScroll)).toEqual(before);
+ expect((await block.boundingBox())!.height).toBe(blockHeight);
+ expect(
+ await iframe.evaluate((element, original) => element === original, frameElement),
+ ).toBe(true);
+ expect(await frame.evaluate(() => performance.timeOrigin)).toBe(timeOrigin);
+ await expect(opener).toBeFocused();
+ }
+ await testInfo.attach(`${location}-restored`, {
+ body: await page.screenshot(),
+ contentType: "image/png",
+ });
+ await testInfo.attach(`${location}-geometry`, {
+ body: Buffer.from(
+ JSON.stringify({
+ before,
+ after: await scroller.evaluate(readScroll),
+ rounds: 3,
+ blockHeight,
+ iframeHeight: 480,
+ fullscreenHeight: 972,
+ documentRetained: true,
+ inputRetained: true,
+ }),
+ ),
+ contentType: "application/json",
+ });
+
+ if (location === "description") {
+ await block.getByRole("button", { name: "Show source" }).click();
+ await opener.scrollIntoViewIfNeeded();
+ const sourceHeight = (await block.boundingBox())!.height;
+ const sourceScroll = await scroller.evaluate(readScroll);
+ await opener.click();
+ await expect(page.getByRole("dialog").locator("iframe")).toBeVisible();
+ expect((await block.boundingBox())!.height).toBe(sourceHeight);
+ expect(await scroller.evaluate(readScroll)).toEqual(sourceScroll);
+ await page.keyboard.press("Escape");
+ await expect(page.getByRole("dialog")).toHaveCount(0);
+ expect((await block.boundingBox())!.height).toBe(sourceHeight);
+ expect(await scroller.evaluate(readScroll)).toEqual(sourceScroll);
+ expect(await frame.evaluate(() => performance.timeOrigin)).toBe(timeOrigin);
+ }
+ });
+ }
+
+ test("reply remeasures content changed while enlarged, including from source", async ({ page }) => {
+ const interactiveHtml = `<style>html,body{margin:0;padding:0}</style>
+<div id="content" style="height:200px">
+ <input aria-label="Retained input" value="initial">
+ <button onclick="document.getElementById('content').style.height='1200px'">Expand content</button>
+ <button onclick="document.getElementById('content').style.height='200px'">Collapse content</button>
+</div>`;
+ const issue = await api.createIssue("HTML preview content resize");
+ const comment = await api.createComment(issue.id, `\`\`\`html\n${interactiveHtml}\n\`\`\``);
+ await page.goto(`/${workspaceSlug}/issues/${issue.identifier}`, { waitUntil: "domcontentloaded" });
+ const block = page.locator(`[data-comment-content="${comment.id}"] [data-dynamic-block="html"]`);
+ const iframe = block.locator("iframe");
+ const frame = (await (await iframe.elementHandle())!.contentFrame())!;
+ const input = iframe.contentFrame().getByRole("textbox", { name: "Retained input" });
+ await input.fill("Keep this document");
+ const timeOrigin = await frame.evaluate(() => performance.timeOrigin);
+ const inlineHeight = () => iframe.evaluate((element) => element.parentElement!.style.height);
+ await expect.poll(inlineHeight).toBe("200px");
+ const resizeContent = async (action: string, height: number) => {
+ const reported = iframe.evaluate((element, expected) => new Promise<void>((resolve) => {
+ const onMessage = (event: MessageEvent) => {
+ if (event.source !== (element as HTMLIFrameElement).contentWindow || event.data?.type !== "height" || event.data.height !== expected) return;
+ window.removeEventListener("message", onMessage);
+ resolve();
+ };
+ window.addEventListener("message", onMessage);
+ }), height);
+ await iframe.contentFrame().getByRole("button", { name: action }).click();
+ // Reproduce the bridge deduplication before closing the enlarged preview.
+ await reported;
+ };
+
+ for (const [action, height] of [["Expand content", 1200], ["Collapse content", 200]] as const) {
+ await block.hover();
+ await block.getByRole("button", { name: "Fullscreen" }).click();
+ await resizeContent(action, height);
+ await page.getByRole("dialog").getByRole("button", { name: "Close", exact: true }).click();
+ await expect.poll(inlineHeight).toBe(`${height}px`);
+ await expect(block.getByRole("button", { name: "Show all", exact: true })).toHaveCount(height > 480 ? 1 : 0);
+ await expect(input).toHaveValue("Keep this document");
+ expect(await frame.evaluate(() => performance.timeOrigin)).toBe(timeOrigin);
+ }
+
+ await block.getByRole("tab", { name: "Source" }).click();
+ await block.getByRole("button", { name: "Fullscreen" }).click();
+ await resizeContent("Expand content", 1200);
+ await page.getByRole("dialog").getByRole("button", { name: "Close", exact: true }).click();
+ await expect(block.getByRole("tab", { name: "Source" })).toHaveAttribute("aria-selected", "true");
+ await block.getByRole("tab", { name: "Preview" }).click();
+ await expect.poll(inlineHeight).toBe("1200px");
+ await expect(block.getByRole("button", { name: "Show all", exact: true })).toBeVisible();
+ await expect(input).toHaveValue("Keep this document");
+ expect(await frame.evaluate(() => performance.timeOrigin)).toBe(timeOrigin);
+ });
+
+ test("enlarging from expanded reply source preserves its panel and outer layout", async ({
+ page,
+ }, testInfo) => {
+ const issue = await api.createIssue("Expanded HTML source regression");
+ const comment = await api.createComment(issue.id, content);
+ await page.goto(`/${workspaceSlug}/issues/${issue.identifier}`, {
+ waitUntil: "domcontentloaded",
+ });
+ const outer = await scrollContainer(
+ page.getByText("Paragraph before the preview.", { exact: true }).first(),
+ );
+ await outer.evaluate((element) => {
+ element.scrollTop = element.scrollHeight - element.clientHeight;
+ });
+ const block = page.locator(
+ `[data-comment-content="${comment.id}"] [data-dynamic-block="html"]`,
+ );
+ await block.scrollIntoViewIfNeeded();
+ await block.getByRole("tab", { name: "Source" }).click();
+ await block.getByRole("button", { name: "Show all" }).click();
+ const source = block.locator("pre");
+ const originalSource = await source.elementHandle();
+ const beforeHeight = (await block.boundingBox())!.height;
+ expect(beforeHeight).toBeGreaterThan(480);
+ const scroller = await scrollContainer(block);
+ const opener = block.getByRole("button", { name: "Fullscreen" });
+ await opener.scrollIntoViewIfNeeded();
+ const before = await scroller.evaluate(readScroll);
+ await opener.click();
+ await expect(page.getByRole("dialog").locator("iframe")).toBeVisible();
+ expect(await originalSource!.evaluate((element) => element.isConnected)).toBe(true);
+ expect((await block.boundingBox())!.height).toBe(beforeHeight);
+ expect(await scroller.evaluate(readScroll)).toEqual(before);
+ await page.keyboard.press("Escape");
+ await expect(page.getByRole("dialog")).toHaveCount(0);
+ expect(await source.evaluate((element, original) => element === original, originalSource)).toBe(
+ true,
+ );
+ await expect(block.getByRole("tab", { name: "Source" })).toHaveAttribute(
+ "aria-selected",
+ "true",
+ );
+ await expect(block.getByRole("button", { name: "Show all" })).toHaveCount(0);
+ expect((await block.boundingBox())!.height).toBe(beforeHeight);
+ expect(await scroller.evaluate(readScroll)).toEqual(before);
+ await expect(opener).toBeFocused();
+ await testInfo.attach("source-restored", {
+ body: await page.screenshot(),
+ contentType: "image/png",
+ });
+ await testInfo.attach("source-geometry", {
+ body: Buffer.from(
+ JSON.stringify({
+ before,
+ after: await scroller.evaluate(readScroll),
+ sourceHeight: beforeHeight,
+ expandedSourceRetained: true,
+ sourceElementRetained: true,
+ }),
+ ),
+ contentType: "application/json",
+ });
+ });
+});
diff --git a/packages/ui/docs/dialog.md b/packages/ui/docs/dialog.md
index 6e91bfe24d..bc740567a3 100644
--- a/packages/ui/docs/dialog.md
+++ b/packages/ui/docs/dialog.md
@@ -14,6 +14,8 @@ Provide a title and a concise description. Let the primitive manage focus trappi
Only close a submitting dialog after the operation succeeds. Preserve its input and show an error on failure. The UI Lab save interaction is a local demonstration; it makes no API request.
+HTML code previews use the focused `HtmlPreviewSurface` in `packages/views/editor/` instead of a portal. Its native dialog promotes the existing inline iframe to the browser's top layer without changing its DOM parent or reloading its document. Keep the preview mounted when switching to source, and defer source updates until it is visible. When returning to inline preview, request a fresh height report even if unchanged; fullscreen reports must not overwrite the inline height. Verify repeated open/close, focus restoration, backdrop dismissal and inline height restoration after content expands or shrinks in a browser; jsdom cannot verify iframe document retention. Escape works when focus is in the parent document; keyboard events inside a cross-origin iframe do not reach it.
+
## Correct
```tsx
diff --git a/packages/views/common/use-debounced-value.ts b/packages/views/common/use-debounced-value.ts
index 93656bf88f..69550479c6 100644
--- a/packages/views/common/use-debounced-value.ts
+++ b/packages/views/common/use-debounced-value.ts
@@ -2,12 +2,13 @@
import { useEffect, useState } from "react";
-/** The value as it stood once it stopped changing for `delayMs`. */
-export function useDebouncedValue<T>(value: T, delayMs: number): T {
+/** The last settled value; disabling cancels pending updates and retains it. */
+export function useDebouncedValue<T>(value: T, delayMs: number, enabled = true): T {
const [debounced, setDebounced] = useState(value);
useEffect(() => {
+ if (!enabled) return;
const id = setTimeout(() => setDebounced(value), delayMs);
return () => clearTimeout(id);
- }, [value, delayMs]);
+ }, [value, delayMs, enabled]);
return debounced;
}
diff --git a/packages/views/editor/dynamic-block.tsx b/packages/views/editor/dynamic-block.tsx
index cd983ee0f7..5cbdd7bddb 100644
--- a/packages/views/editor/dynamic-block.tsx
+++ b/packages/views/editor/dynamic-block.tsx
@@ -86,6 +86,8 @@ interface DynamicBlockProps {
error?: DynamicBlockError | null;
/** Shows the fullscreen button when set. */
onFullscreen?: () => void;
+ /** Reveals the mounted preview while its surface is enlarged. */
+ fullscreen?: boolean;
/** Focus returns here when the kind's fullscreen surface closes. */
fullscreenButtonRef?: Ref<HTMLButtonElement>;
/**
@@ -102,6 +104,7 @@ export function DynamicBlock({
source,
error,
onFullscreen,
+ fullscreen = false,
fullscreenButtonRef,
preview,
className,
@@ -203,15 +206,20 @@ export function DynamicBlock({
</Button>
</div>
</div>
- <TabsContent value="preview" keepMounted>
- {error && (
+ <TabsContent
+ value="preview"
+ keepMounted
+ hidden={!fullscreen && view !== "preview"}
+ inert={!fullscreen && view !== "preview"}
+ >
+ {error && view === "preview" && (
<DynamicBlockErrorPanel
kind={kind}
error={error}
onViewSource={() => setView("source")}
/>
)}
- <div hidden={!!error}>
+ <div hidden={!!error && !fullscreen}>
<CollapsibleBody>{preview({ active: view === "preview" && !error })}</CollapsibleBody>
</div>
</TabsContent>
diff --git a/packages/views/editor/extensions/code-block-view.test.tsx b/packages/views/editor/extensions/code-block-view.test.tsx
index 694e84b6f6..633595160d 100644
--- a/packages/views/editor/extensions/code-block-view.test.tsx
+++ b/packages/views/editor/extensions/code-block-view.test.tsx
@@ -1,5 +1,12 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-import { act, fireEvent, render, screen } from "@testing-library/react";
+import {
+ act,
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+} from "@testing-library/react";
+import { mockNativeDialog } from "../test-utils/native-dialog";
// Tiptap's NodeView primitives are hard to instantiate in jsdom without a
// full editor. Stub them so the test can render <CodeBlockView /> as a plain
@@ -33,6 +40,8 @@ vi.mock("../../i18n", () => ({
copy_code: "Copy code",
show_preview: "Show preview",
show_source: "Show source",
+ fullscreen: "Fullscreen",
+ close_preview: "Close",
},
}),
}),
@@ -50,13 +59,17 @@ function makeProps(language: string, text: string) {
}
describe("CodeBlockView — html language toggle", () => {
+ let restoreDialog: () => void;
// Inner async timers in useDebouncedValue make the iframe srcDoc lag by
// ~200ms; use fake timers so the test stays deterministic.
beforeEach(() => {
vi.useFakeTimers({ shouldAdvanceTime: true });
+ restoreDialog = mockNativeDialog();
});
afterEach(() => {
+ cleanup();
vi.useRealTimers();
+ restoreDialog();
});
it("defaults to preview view: renders an iframe with sandbox='allow-scripts' and keeps the <pre> mounted (hidden)", () => {
@@ -77,24 +90,98 @@ describe("CodeBlockView — html language toggle", () => {
expect(pre?.className).toContain("sr-only");
});
- it("toggles to source view: iframe is removed and the <pre> is no longer hidden", () => {
+ it("toggles to source view without unloading the preview or editor content", () => {
render(<CodeBlockView {...makeProps("html", "<p>hello</p>")} />);
act(() => {
vi.advanceTimersByTime(250);
});
- expect(document.querySelector("iframe")).toBeTruthy();
+ const frame = document.querySelector("iframe");
+ expect(frame).toBeTruthy();
const toggle = screen.getByTitle("Show source");
fireEvent.click(toggle);
- expect(document.querySelector("iframe")).toBeNull();
+ expect(document.querySelector("iframe")).toBe(frame);
+ expect(frame?.closest("[hidden]")).toBeTruthy();
const nvc = screen.getByTestId("nvc");
const pre = nvc.closest("pre")!;
expect(pre.className).not.toContain("sr-only");
});
+ it("opens the current HTML in a larger sandboxed preview without replacing editor content", () => {
+ const { rerender } = render(
+ <CodeBlockView {...makeProps("html", "<p>first</p>")} />,
+ );
+ act(() => {
+ vi.advanceTimersByTime(250);
+ });
+ const editorContent = screen.getByTestId("nvc");
+ rerender(<CodeBlockView {...makeProps("html", "<p>latest</p>")} />);
+ act(() => {
+ vi.advanceTimersByTime(250);
+ });
+ const original = document.querySelector("iframe");
+ const opener = screen.getByRole("button", { name: "Fullscreen" });
+ fireEvent.click(opener);
+ const dialog = screen.getByRole("dialog", {
+ name: "Localized HTML preview",
+ });
+ const frame = dialog.querySelector("iframe");
+ expect(frame).toBe(original);
+ expect(document.querySelectorAll("iframe")).toHaveLength(1);
+ expect(frame?.getAttribute("srcdoc")).toBe("<p>latest</p>");
+ expect(frame?.getAttribute("sandbox")).toBe("allow-scripts");
+ expect(screen.getByTestId("nvc")).toBe(editorContent);
+ expect(document.querySelector("iframe")).toBe(original);
+ fireEvent.click(screen.getByRole("button", { name: "Close" }));
+ act(() => {
+ vi.advanceTimersByTime(250);
+ });
+ expect(screen.queryByRole("dialog")).toBeNull();
+ expect(screen.getByTestId("nvc")).toBe(editorContent);
+ fireEvent.click(opener);
+ expect(screen.getByRole("dialog").querySelector("iframe")).toBe(original);
+ fireEvent.click(screen.getByRole("button", { name: "Close" }));
+ fireEvent.click(screen.getByTitle("Show source"));
+ expect(editorContent.closest("pre")?.className).not.toContain("sr-only");
+ fireEvent.click(opener);
+ expect(screen.getByRole("dialog").querySelector("iframe")).toBe(original);
+ expect(original?.closest("[hidden]")).toBeNull();
+ });
+
it("does not show the toggle or an iframe for a non-html language", () => {
render(<CodeBlockView {...makeProps("typescript", "const x = 1;")} />);
expect(screen.queryByTitle("Show source")).toBeNull();
expect(screen.queryByTitle("Show preview")).toBeNull();
expect(document.querySelector("iframe")).toBeNull();
});
+
+ it("defers source edits until the retained preview is visible", () => {
+ const { rerender } = render(
+ <CodeBlockView {...makeProps("html", "<p>initial</p>")} />,
+ );
+ const frame = document.querySelector("iframe")!;
+ const editorContent = screen.getByTestId("nvc");
+
+ rerender(<CodeBlockView {...makeProps("html", "<p>pending</p>")} />);
+ fireEvent.click(screen.getByTitle("Show source"));
+ act(() => vi.advanceTimersByTime(250));
+ expect(frame.getAttribute("srcdoc")).toBe("<p>initial</p>");
+ rerender(<CodeBlockView {...makeProps("html", "<p>edited</p>")} />);
+ act(() => vi.advanceTimersByTime(250));
+ expect(frame.getAttribute("srcdoc")).toBe("<p>initial</p>");
+
+ fireEvent.click(screen.getByRole("button", { name: "Fullscreen" }));
+ act(() => vi.advanceTimersByTime(250));
+ expect(frame.getAttribute("srcdoc")).toBe("<p>edited</p>");
+ expect(screen.getByRole("dialog").querySelector("iframe")).toBe(frame);
+ fireEvent.click(screen.getByRole("button", { name: "Close" }));
+
+ rerender(<CodeBlockView {...makeProps("html", "<p>latest</p>")} />);
+ act(() => vi.advanceTimersByTime(250));
+ expect(frame.getAttribute("srcdoc")).toBe("<p>edited</p>");
+ fireEvent.click(screen.getByTitle("Show preview"));
+ act(() => vi.advanceTimersByTime(250));
+ expect(frame.getAttribute("srcdoc")).toBe("<p>latest</p>");
+ expect(document.querySelector("iframe")).toBe(frame);
+ expect(screen.getByTestId("nvc")).toBe(editorContent);
+ });
});
diff --git a/packages/views/editor/extensions/code-block-view.tsx b/packages/views/editor/extensions/code-block-view.tsx
index 44bd823fb2..3ba882bf78 100644
--- a/packages/views/editor/extensions/code-block-view.tsx
+++ b/packages/views/editor/extensions/code-block-view.tsx
@@ -3,7 +3,9 @@
import { useState } from "react";
import { NodeViewWrapper, NodeViewContent } from "@tiptap/react";
import type { NodeViewProps } from "@tiptap/react";
-import { Code as CodeIcon, Copy, Check, Eye } from "lucide-react";
+import { Code as CodeIcon, Copy, Check, Eye, Maximize2 } from "lucide-react";
+import { Button } from "@multica/ui/components/ui/button";
+import { HtmlPreviewSurface } from "../html-preview-surface";
import { cn } from "@multica/ui/lib/utils";
import { copyText } from "@multica/ui/lib/clipboard";
import { useDebouncedValue } from "../../common/use-debounced-value";
@@ -20,11 +22,12 @@ import { CodeBlockIframe } from "../code-block-iframe";
// keystroke causes the iframe to re-load and flicker.
const PREVIEW_DEBOUNCE_MS = 200;
-const HTML_PREVIEW_HEIGHT = "h-[480px]";
+const HTML_PREVIEW_HEIGHT_PX = 480;
function CodeBlockView({ node }: NodeViewProps) {
const { t } = useT("editor");
const [copied, setCopied] = useState(false);
+ const [fullscreen, setFullscreen] = useState(false);
// HTML blocks default to "preview"; the user can flip to "source" to
// edit the markup directly. Note: the source `<pre>` MUST stay mounted
// (just hidden) so ProseMirror keeps its NodeView bindings — unmounting
@@ -33,6 +36,7 @@ function CodeBlockView({ node }: NodeViewProps) {
const language = node.attrs.language || "";
const isMermaid = language === "mermaid";
const isHtml = language === "html";
+ const showHtmlPreview = isHtml && view === "preview";
const chart = node.textContent;
const debouncedChart = useDebouncedValue(
isMermaid ? chart : "",
@@ -41,6 +45,7 @@ function CodeBlockView({ node }: NodeViewProps) {
const debouncedHtml = useDebouncedValue(
isHtml ? chart : "",
PREVIEW_DEBOUNCE_MS,
+ showHtmlPreview || fullscreen,
);
const handleCopy = async () => {
@@ -52,7 +57,6 @@ function CodeBlockView({ node }: NodeViewProps) {
}
};
- const showHtmlPreview = isHtml && view === "preview";
const toggleView = () =>
setView((v) => (v === "preview" ? "source" : "preview"));
@@ -66,16 +70,28 @@ function CodeBlockView({ node }: NodeViewProps) {
<MermaidDiagram chart={debouncedChart} />
</div>
)}
- {isHtml && showHtmlPreview && (
+ {isHtml && (
// CSS-hidden when toggled off so the `<pre>` below stays mounted —
// unmounting either side would either lose ProseMirror bindings
// (source) or thrash iframe.srcDoc (preview).
- <div contentEditable={false} className="mb-1">
- <CodeBlockIframe
- html={debouncedHtml}
+ <div
+ contentEditable={false}
+ className={showHtmlPreview ? "mb-1" : undefined}
+ hidden={!showHtmlPreview && !fullscreen}
+ >
+ <HtmlPreviewSurface
+ open={fullscreen}
+ inlineHeight={showHtmlPreview ? HTML_PREVIEW_HEIGHT_PX : 0}
+ onOpenChange={setFullscreen}
title={t(($) => $.code_block.html_preview)}
- heightClassName={HTML_PREVIEW_HEIGHT}
- />
+ >
+ <CodeBlockIframe
+ html={debouncedHtml}
+ title={t(($) => $.code_block.html_preview)}
+ heightClassName={fullscreen ? "h-full" : "h-[480px]"}
+ className={fullscreen ? "rounded-none border-0" : undefined}
+ />
+ </HtmlPreviewSurface>
</div>
)}
<div
@@ -110,6 +126,19 @@ function CodeBlockView({ node }: NodeViewProps) {
)}
</button>
)}
+ {isHtml && (
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon-xs"
+ className="text-muted-foreground"
+ title={t(($) => $.code_block.fullscreen)}
+ aria-label={t(($) => $.code_block.fullscreen)}
+ onClick={() => setFullscreen(true)}
+ >
+ <Maximize2 className="h-3.5 w-3.5" />
+ </Button>
+ )}
<button
type="button"
onClick={handleCopy}
diff --git a/packages/views/editor/html-block-preview.test.tsx b/packages/views/editor/html-block-preview.test.tsx
index e72b4b77e0..1895c71b0d 100644
--- a/packages/views/editor/html-block-preview.test.tsx
+++ b/packages/views/editor/html-block-preview.test.tsx
@@ -1,5 +1,12 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-import { act, fireEvent, render, screen } from "@testing-library/react";
+import {
+ act,
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+} from "@testing-library/react";
+import { mockNativeDialog } from "./test-utils/native-dialog";
vi.mock("../i18n", async () => {
const editor = (await import("../locales/en/editor.json")).default;
@@ -23,8 +30,16 @@ vi.mock("./code-block-static", () => ({
import { HtmlBlockPreview } from "./html-block-preview";
import { HTML_BLOCK_MESSAGE_KEY } from "./utils/html-block-document";
-beforeEach(() => window.sessionStorage.clear());
-afterEach(() => vi.restoreAllMocks());
+let restoreDialog: () => void;
+beforeEach(() => {
+ window.sessionStorage.clear();
+ restoreDialog = mockNativeDialog();
+});
+afterEach(() => {
+ cleanup();
+ restoreDialog();
+ vi.restoreAllMocks();
+});
function inlineFrame(): HTMLIFrameElement {
const frame = document.querySelector<HTMLIFrameElement>('[data-dynamic-block="html"] iframe');
@@ -148,15 +163,61 @@ describe("HtmlBlockPreview — errors", () => {
});
describe("HtmlBlockPreview — fullscreen", () => {
- it("opens the same document in a dialog", () => {
+ it("enlarges the loaded iframe without creating another document", () => {
render(<HtmlBlockPreview html="<p>hi</p>" />);
+ const original = inlineFrame();
expect(document.querySelectorAll("iframe")).toHaveLength(1);
fireEvent.click(screen.getByRole("button", { name: "Fullscreen" }));
const frames = document.querySelectorAll("iframe");
- expect(frames).toHaveLength(2);
- expect(frames[1]!.getAttribute("srcdoc")).toBe(frames[0]!.getAttribute("srcdoc"));
- expect(frames[1]!.getAttribute("sandbox")).toBe("allow-scripts");
+ expect(frames).toHaveLength(1);
+ expect(screen.getByRole("dialog").querySelector("iframe")).toBe(original);
+ expect(original.getAttribute("sandbox")).toBe("allow-scripts");
+ fireEvent.click(screen.getByRole("button", { name: "Close" }));
+ expect(screen.queryByRole("dialog")).toBeNull();
+ fireEvent.click(screen.getByRole("button", { name: "Fullscreen" }));
+ expect(screen.getByRole("dialog").querySelector("iframe")).toBe(original);
+ });
+
+ it("ignores enlarged viewport measurements and restores the inline height", () => {
+ render(<HtmlBlockPreview html="<p>hi</p>" />);
+ const frame = inlineFrame();
+ post(frame, { type: "height", height: 264 });
+ fireEvent.click(screen.getByRole("button", { name: "Fullscreen" }));
+ post(frame, { type: "height", height: 972 });
+ fireEvent.click(screen.getByRole("button", { name: "Close" }));
+ expect(frame.parentElement?.style.height).toBe("264px");
+ });
+
+ it("reveals the loaded preview from source and restores source on close", () => {
+ render(<HtmlBlockPreview html="<p>hi</p>" />);
+ const frame = inlineFrame();
+ fireEvent.click(screen.getByRole("tab", { name: "Source" }));
+ fireEvent.click(screen.getByRole("button", { name: "Fullscreen" }));
+ expect(screen.getByRole("dialog").querySelector("iframe")).toBe(frame);
+ expect(frame.closest("[hidden]")).toBeNull();
+ expect(frame.closest("[inert]")).toBeNull();
+ fireEvent.click(screen.getByRole("button", { name: "Close" }));
+ expect(
+ screen.getByRole("tab", { name: "Source" }).getAttribute("aria-selected"),
+ ).toBe("true");
+ });
+
+ it("keeps expanded source mounted and selected while enlarging the preview", () => {
+ vi.spyOn(HTMLElement.prototype, "offsetHeight", "get").mockReturnValue(900);
+ render(<HtmlBlockPreview html={"<p>long source</p>\n".repeat(100)} />);
+ fireEvent.click(screen.getByRole("tab", { name: "Source" }));
+ const source = screen.getByTestId("code-block-static");
+ fireEvent.click(screen.getByRole("button", { name: "Show all" }));
+
+ fireEvent.click(screen.getByRole("button", { name: "Fullscreen" }));
+ expect(source.isConnected).toBe(true);
+ expect(screen.getByRole("tab", { name: "Source" }).getAttribute("aria-selected")).toBe("true");
+ fireEvent.click(screen.getByRole("button", { name: "Close" }));
+
+ expect(screen.getByTestId("code-block-static")).toBe(source);
+ expect(source.closest("[data-collapsed]")).toBeNull();
+ expect(screen.queryByRole("button", { name: "Show all" })).toBeNull();
});
});
diff --git a/packages/views/editor/html-block-preview.tsx b/packages/views/editor/html-block-preview.tsx
index 05120f7ad7..2d80675726 100644
--- a/packages/views/editor/html-block-preview.tsx
+++ b/packages/views/editor/html-block-preview.tsx
@@ -14,9 +14,9 @@
* `<NodeViewContent as="code" />` so the user can continue typing.
*/
-import { useEffect, useReducer, useRef, useState } from "react";
+import { useEffect, useLayoutEffect, useReducer, useRef, useState } from "react";
import { cn } from "@multica/ui/lib/utils";
-import { Dialog, DialogContent } from "@multica/ui/components/ui/dialog";
+import { HtmlPreviewSurface } from "./html-preview-surface";
import { useT } from "../i18n";
import { CodeBlockIframe } from "./code-block-iframe";
import {
@@ -29,6 +29,7 @@ import {
} from "./dynamic-block";
import { useThemeVersion } from "./hooks/use-theme-version";
import {
+ HTML_BLOCK_MESSAGE_KEY,
INITIAL_HTML_BLOCK_HEIGHT,
buildHtmlBlockDocument,
nextHtmlBlockHeight,
@@ -123,6 +124,7 @@ export function HtmlBlockPreview({ html, title }: HtmlBlockPreviewProps) {
title={title}
source={html}
error={error}
+ fullscreen={fullscreen}
onFullscreen={() => setFullscreen(true)}
preview={({ active }) => (
<HtmlBlockBody
@@ -131,25 +133,12 @@ export function HtmlBlockPreview({ html, title }: HtmlBlockPreviewProps) {
srcDoc={srcDoc}
title={frameTitle}
active={active}
+ fullscreen={fullscreen}
+ onFullscreenChange={setFullscreen}
onError={setError}
/>
)}
/>
- <Dialog open={fullscreen} onOpenChange={setFullscreen}>
- <DialogContent
- className="!max-w-6xl !h-[min(90vh,calc(100vh-2rem))] w-full p-0 gap-0 overflow-hidden"
- aria-label={t(($) => $.code_block.fullscreen)}
- >
- {srcDoc != null && (
- <CodeBlockIframe
- html={srcDoc}
- title={frameTitle}
- heightClassName="h-full"
- className="rounded-none border-0"
- />
- )}
- </DialogContent>
- </Dialog>
</div>
);
}
@@ -159,12 +148,16 @@ function HtmlBlockBody({
srcDoc,
title,
active,
+ fullscreen,
+ onFullscreenChange,
onError,
}: {
html: string;
srcDoc: string | null;
title: string;
active: boolean;
+ fullscreen: boolean;
+ onFullscreenChange: (open: boolean) => void;
onError: (error: DynamicBlockError) => void;
}) {
const iframeRef = useRef<HTMLIFrameElement>(null);
@@ -176,8 +169,9 @@ function HtmlBlockBody({
// The listener is registered once; these refs give it the current values.
const activeRef = useRef(active);
const onErrorRef = useRef(onError);
- useEffect(() => {
- activeRef.current = active;
+ useLayoutEffect(() => {
+ // A full-size document's bridge must not overwrite its inline height.
+ activeRef.current = active && !fullscreen;
onErrorRef.current = onError;
});
@@ -185,6 +179,16 @@ function HtmlBlockBody({
setCachedHeight(readCachedHeight(html));
}, [html]);
+ useEffect(() => {
+ if (!active || fullscreen) return;
+ // Fullscreen reports were ignored, but the bridge deduplicated them.
+ // Ask again after inline layout is restored, even if its height is unchanged.
+ iframeRef.current?.contentWindow?.postMessage(
+ { [HTML_BLOCK_MESSAGE_KEY]: 1, type: "measure" },
+ "*",
+ );
+ }, [active, fullscreen]);
+
useEffect(() => {
const onMessage = (event: MessageEvent) => {
// Only this block's own frame; every block shares the window.
@@ -221,25 +225,38 @@ function HtmlBlockBody({
);
return (
- <div className="relative" style={{ height: bodyHeight }}>
- {srcDoc != null && (
- <CodeBlockIframe
- ref={iframeRef}
- html={srcDoc}
- title={title}
- heightClassName="h-full"
- // The frame is the block's body, so it draws no border of its own.
- // Transparent lets a document without a background sit on the
- // block's surface.
- className={cn("block rounded-none border-0 bg-transparent", !ready && "invisible")}
- onLoad={() => setLoaded(true)}
- />
- )}
- {!ready && (
- <div className="absolute inset-0">
- <DynamicBlockSkeleton />
- </div>
- )}
- </div>
+ <HtmlPreviewSurface
+ open={fullscreen}
+ inlineHeight={active ? bodyHeight : 0}
+ onOpenChange={onFullscreenChange}
+ title={title}
+ >
+ <div
+ className="relative"
+ style={{ height: fullscreen ? "100%" : bodyHeight }}
+ >
+ {srcDoc != null && (
+ <CodeBlockIframe
+ ref={iframeRef}
+ html={srcDoc}
+ title={title}
+ heightClassName="h-full"
+ // The frame is the block's body, so it draws no border of its own.
+ // Transparent lets a document without a background sit on the
+ // block's surface.
+ className={cn(
+ "block rounded-none border-0 bg-transparent",
+ !ready && !fullscreen && "invisible",
+ )}
+ onLoad={() => setLoaded(true)}
+ />
+ )}
+ {!ready && !fullscreen && (
+ <div className="absolute inset-0">
+ <DynamicBlockSkeleton />
+ </div>
+ )}
+ </div>
+ </HtmlPreviewSurface>
);
}
diff --git a/packages/views/editor/html-preview-surface.tsx b/packages/views/editor/html-preview-surface.tsx
new file mode 100644
index 0000000000..ee6b95f8d1
--- /dev/null
+++ b/packages/views/editor/html-preview-surface.tsx
@@ -0,0 +1,121 @@
+"use client";
+
+import {
+ useEffect,
+ useId,
+ useLayoutEffect,
+ useRef,
+ type MouseEvent,
+ type ReactNode,
+} from "react";
+import { X } from "lucide-react";
+import { Button } from "@multica/ui/components/ui/button";
+import { useT } from "../i18n";
+
+/**
+ * A native top-layer dialog keeps the preview in its original DOM parent.
+ * Moving an iframe into a portal would reload its browsing context, even if
+ * React kept the same element. The wrapper reserves the inline height while
+ * the dialog is open, so outer scroll containers keep their layout.
+ */
+export function HtmlPreviewSurface({
+ open,
+ inlineHeight,
+ onOpenChange,
+ title,
+ children,
+}: {
+ open: boolean;
+ /** The inline body's height, or zero when its preview is hidden. */
+ inlineHeight: number;
+ onOpenChange: (open: boolean) => void;
+ title: string;
+ children: ReactNode;
+}) {
+ const { t } = useT("editor");
+ const titleId = useId();
+ const dialogRef = useRef<HTMLDialogElement>(null);
+ const closeRef = useRef<HTMLButtonElement>(null);
+ const backdropPress = useRef(false);
+
+ useLayoutEffect(() => {
+ const dialog = dialogRef.current;
+ if (!dialog) return;
+ if (open && !dialog.open) {
+ dialog.showModal();
+ closeRef.current?.focus();
+ } else if (!open && dialog.open) {
+ dialog.close();
+ }
+ }, [open]);
+
+ useEffect(() => {
+ if (!open) return;
+ const body = document.body;
+ const previous = body.style.overflow;
+ body.style.overflow = "hidden";
+ return () => {
+ if (body.style.overflow === "hidden") body.style.overflow = previous;
+ };
+ }, [open]);
+
+ useEffect(() => {
+ const dialog = dialogRef.current;
+ return () => {
+ if (dialog?.open) dialog.close();
+ };
+ }, []);
+
+ const outside = (event: MouseEvent<HTMLDialogElement>) => {
+ if (event.target !== event.currentTarget) return false;
+ const rect = event.currentTarget.getBoundingClientRect();
+ return (
+ event.clientX < rect.left ||
+ event.clientX > rect.right ||
+ event.clientY < rect.top ||
+ event.clientY > rect.bottom
+ );
+ };
+
+ return (
+ <div style={open ? { height: inlineHeight } : undefined}>
+ <dialog
+ ref={dialogRef}
+ role={open ? "dialog" : "presentation"}
+ aria-labelledby={open ? titleId : undefined}
+ onClose={() => onOpenChange(false)}
+ onKeyDown={(event) => {
+ if (open && event.key === "Escape") event.stopPropagation();
+ }}
+ onPointerDown={(event) => {
+ backdropPress.current = outside(event);
+ }}
+ onClick={(event) => {
+ if (backdropPress.current && outside(event)) dialogRef.current?.close();
+ backdropPress.current = false;
+ }}
+ className="relative m-0 block max-h-none w-full max-w-none border-0 bg-transparent p-0 text-inherit open:fixed open:inset-0 open:m-auto open:h-[min(90dvh,calc(100dvh-2rem))] open:w-[min(72rem,calc(100vw-2rem))] open:overflow-hidden open:rounded-xl open:bg-surface-raised open:shadow-[var(--floating-shadow)] open:ring-1 open:ring-surface-border backdrop:bg-black/10 backdrop:backdrop-blur-xs"
+ >
+ {children}
+ {open && (
+ <>
+ <span id={titleId} className="sr-only">
+ {title}
+ </span>
+ <Button
+ ref={closeRef}
+ type="button"
+ variant="ghost"
+ size="icon-sm"
+ className="absolute top-2 right-2"
+ aria-label={t(($) => $.code_block.close_preview)}
+ onClick={() => dialogRef.current?.close()}
+ >
+ <X />
+ </Button>
+ </>
+ )}
+ </dialog>
+ </div>
+ );
+}
diff --git a/packages/views/editor/test-utils/native-dialog.ts b/packages/views/editor/test-utils/native-dialog.ts
new file mode 100644
index 0000000000..8cab8fef2a
--- /dev/null
+++ b/packages/views/editor/test-utils/native-dialog.ts
@@ -0,0 +1,32 @@
+/** jsdom has no top-layer dialog API; browser tests cover the real behavior. */
+export function mockNativeDialog() {
+ const prototype = HTMLDialogElement.prototype;
+ const show = Object.getOwnPropertyDescriptor(prototype, "showModal");
+ const close = Object.getOwnPropertyDescriptor(prototype, "close");
+ const focus = new WeakMap<HTMLDialogElement, Element | null>();
+ Object.defineProperties(prototype, {
+ showModal: {
+ configurable: true,
+ value(this: HTMLDialogElement) {
+ focus.set(this, document.activeElement);
+ this.open = true;
+ },
+ },
+ close: {
+ configurable: true,
+ value(this: HTMLDialogElement) {
+ if (!this.open) return;
+ this.open = false;
+ const previous = focus.get(this);
+ if (previous instanceof HTMLElement) previous.focus();
+ this.dispatchEvent(new Event("close"));
+ },
+ },
+ });
+ return () => {
+ if (show) Object.defineProperty(prototype, "showModal", show);
+ else delete (prototype as Partial<HTMLDialogElement>).showModal;
+ if (close) Object.defineProperty(prototype, "close", close);
+ else delete (prototype as Partial<HTMLDialogElement>).close;
+ };
+}
diff --git a/packages/views/editor/utils/html-block-document.test.ts b/packages/views/editor/utils/html-block-document.test.ts
index ec71e1125f..d47868617d 100644
--- a/packages/views/editor/utils/html-block-document.test.ts
+++ b/packages/views/editor/utils/html-block-document.test.ts
@@ -1,5 +1,6 @@
// @vitest-environment node
-import { describe, expect, it } from "vitest";
+import { runInNewContext } from "node:vm";
+import { describe, expect, it, vi } from "vitest";
import {
HTML_BLOCK_MAX_CONTENT_PX,
HTML_BLOCK_MESSAGE_KEY,
@@ -15,6 +16,42 @@ import { __FRAGMENT_NAV_SHIM__ } from "./iframe-fragment-nav";
const THEME = { declarations: "--foreground:black;--chart-1:blue", colorScheme: "dark" as const };
+describe("HTML block bridge", () => {
+ it("repeats an unchanged height only when its parent requests a measurement", () => {
+ const listeners = new Map<string, (event?: unknown) => void>();
+ const parent = { postMessage: vi.fn() };
+ runInNewContext(__HTML_BLOCK_BRIDGE__, {
+ parent,
+ window: { addEventListener: (type: string, listener: (event?: unknown) => void) => listeners.set(type, listener) },
+ document: {
+ readyState: "complete",
+ body: { children: [] },
+ createRange: () => ({
+ selectNodeContents: () => {},
+ getBoundingClientRect: () => ({ width: 100, height: 200, bottom: 200 }),
+ }),
+ },
+ getComputedStyle: () => ({}),
+ });
+ const height = { [HTML_BLOCK_MESSAGE_KEY]: 1, type: "height", height: 200 };
+ expect(parent.postMessage).toHaveBeenLastCalledWith(height, "*");
+ listeners.get("load")!();
+ expect(parent.postMessage).toHaveBeenCalledTimes(1);
+
+ const request = { [HTML_BLOCK_MESSAGE_KEY]: 1, type: "measure" };
+ listeners.get("message")!({ source: {}, data: request });
+ listeners.get("message")!({ source: parent, data: { type: "measure" } });
+ listeners.get("message")!({ source: parent, data: { ...request, type: "other" } });
+ expect(parent.postMessage).toHaveBeenCalledTimes(1);
+
+ listeners.get("message")!({ source: parent, data: request });
+ expect(parent.postMessage).toHaveBeenCalledTimes(2);
+ expect(parent.postMessage).toHaveBeenLastCalledWith(height, "*");
+ listeners.get("load")!();
+ expect(parent.postMessage).toHaveBeenCalledTimes(2);
+ });
+});
+
describe("buildHtmlBlockDocument", () => {
it("puts the theme and bridge in front of the markup and the fragment shim after it", () => {
const doc = buildHtmlBlockDocument("<p>hi</p>", THEME);
diff --git a/packages/views/editor/utils/html-block-document.ts b/packages/views/editor/utils/html-block-document.ts
index b15c5ae7a4..9bfac86b6e 100644
--- a/packages/views/editor/utils/html-block-document.ts
+++ b/packages/views/editor/utils/html-block-document.ts
@@ -76,6 +76,8 @@ const BRIDGE_SCRIPT = [
"if(r.width||r.height)bottom=Math.max(bottom,r.bottom+px(ks.marginBottom))}",
"var h=bottom?Math.ceil(bottom+(window.scrollY||0)+px(bs.paddingBottom)+px(bs.borderBottomWidth)+px(bs.marginBottom)):0;",
"if(h!==last){last=h;post({type:'height',height:h})}}",
+ "window.addEventListener('message',function(e){var m=e.data;",
+ "if(e.source!==parent||!m||m[K]!==1||m.type!=='measure')return;last=-1;measure()});",
"var failed=false;",
"window.addEventListener('error',function(e){if(failed)return;var t=e.target;",
"if(t&&t!==window&&t.tagName){if(t.tagName!=='SCRIPT')return;failed=true;",
diff --git a/packages/views/locales/en/editor.json b/packages/views/locales/en/editor.json
index 2fe807d2e4..b53e73efce 100644
--- a/packages/views/locales/en/editor.json
+++ b/packages/views/locales/en/editor.json
@@ -121,6 +121,7 @@
},
"code_block": {
"html_preview": "HTML preview",
+ "close_preview": "Close",
"copy_code": "Copy code",
"show_preview": "Show preview",
"show_source": "Show source",
diff --git a/packages/views/locales/fr/editor.json b/packages/views/locales/fr/editor.json
index 29e13b2feb..e1bfb82788 100644
--- a/packages/views/locales/fr/editor.json
+++ b/packages/views/locales/fr/editor.json
@@ -121,6 +121,7 @@
},
"code_block": {
"html_preview": "Aperçu HTML",
+ "close_preview": "Fermer",
"copy_code": "Copier le code",
"show_preview": "Afficher l'aperçu",
"show_source": "Afficher la source",
diff --git a/packages/views/locales/ja/editor.json b/packages/views/locales/ja/editor.json
index ac3f5aa7e2..12c3f1dd40 100644
--- a/packages/views/locales/ja/editor.json
+++ b/packages/views/locales/ja/editor.json
@@ -110,6 +110,7 @@
},
"code_block": {
"html_preview": "HTML プレビュー",
+ "close_preview": "閉じる",
"copy_code": "コードをコピー",
"show_preview": "プレビューを表示",
"show_source": "ソースを表示",
diff --git a/packages/views/locales/ko/editor.json b/packages/views/locales/ko/editor.json
index e836966973..ea12cf524c 100644
--- a/packages/views/locales/ko/editor.json
+++ b/packages/views/locales/ko/editor.json
@@ -110,6 +110,7 @@
},
"code_block": {
"html_preview": "HTML 미리보기",
+ "close_preview": "닫기",
"copy_code": "코드 복사",
"show_preview": "미리보기 표시",
"show_source": "소스 표시",
diff --git a/packages/views/locales/zh-Hans/editor.json b/packages/views/locales/zh-Hans/editor.json
index 19c91d6e7f..b45fbad958 100644
--- a/packages/views/locales/zh-Hans/editor.json
+++ b/packages/views/locales/zh-Hans/editor.json
@@ -117,6 +117,7 @@
},
"code_block": {
"html_preview": "HTML 预览",
+ "close_preview": "关闭",
"copy_code": "复制代码",
"show_preview": "显示预览",
"show_source": "显示源码",