Skip to content

Open source CapCut alternative.

TypeScript

refactor(site): share the Cut editor mock outside the landing page

David Ledaf7eb26988c
diff --git a/site/src/app/cut/_components/landing/CutHero.tsx b/site/src/app/cut/_components/landing/CutHero.tsx
index fa28a822..a0b35e4d 100644
--- a/site/src/app/cut/_components/landing/CutHero.tsx
+++ b/site/src/app/cut/_components/landing/CutHero.tsx
@@ -2,7 +2,7 @@
import { PillButton } from "@/app/_components/landing/LandingPrimitives";
import { useAppEntryHref } from "@/app/_components/landing/useAppEntryHref";
-import { EditorMock } from "@/app/cut/_components/landing/editor-mock/EditorMock";
+import { EditorMock } from "@/cut/components/editor-mock/EditorMock";
export function CutHero({ root }: { root: string }) {
const appHref = useAppEntryHref();
diff --git a/site/src/app/cut/_components/landing/editor-mock/EditorMock.tsx b/site/src/app/cut/_components/landing/editor-mock/EditorMock.tsx
deleted file mode 100644
index da4d98ef..00000000
--- a/site/src/app/cut/_components/landing/editor-mock/EditorMock.tsx
+++ /dev/null
@@ -1,101 +0,0 @@
-"use client";
-
-import { useEffect, useRef, useState } from "react";
-
-import "./editor-mock.css";
-
-import { MockAiPanel } from "@/app/cut/_components/landing/editor-mock/MockAiPanel";
-import { MockPreview } from "@/app/cut/_components/landing/editor-mock/MockPreview";
-import { MockSidePanel } from "@/app/cut/_components/landing/editor-mock/MockSidePanel";
-import { MockTimeline } from "@/app/cut/_components/landing/editor-mock/MockTimeline";
-import { MockTopBar } from "@/app/cut/_components/landing/editor-mock/MockTopBar";
-import { MOCK_PROJECTS } from "@/app/cut/_components/landing/editor-mock/mockData";
-import { cn } from "@/lib/utils";
-
-// The mock is authored at a fixed design size and scaled to the hero's width,
-// so its internals never reflow — it behaves like a live screenshot.
-const DESIGN_W = 1200;
-const DESIGN_H = 726;
-
-// A hand-built, display-only replica of the Cut editor showing two finished
-// projects. The panels copy the real components' chrome (see the Mock*
-// siblings) over hardcoded data — no stores, no engine. The dots below switch
-// projects; nothing auto-advances.
-export function EditorMock() {
- const [active, setActive] = useState(0);
- const frameRef = useRef<HTMLDivElement>(null);
- const [scale, setScale] = useState(1);
-
- useEffect(() => {
- const el = frameRef.current;
- if (!el) return;
- const ro = new ResizeObserver(([entry]) => {
- setScale(entry.contentRect.width / DESIGN_W);
- });
- ro.observe(el);
- return () => ro.disconnect();
- }, []);
-
- return (
- <figure className="m-0">
- <div ref={frameRef} className="w-full">
- <div style={{ height: Math.round(DESIGN_H * scale) }}>
- <div
- aria-hidden
- className="pointer-events-none relative origin-top-left overflow-hidden rounded-2xl bg-card font-system text-foreground antialiased shadow-[0_0_0_1px_rgba(0,0,0,0.08),0_24px_64px_rgba(15,14,13,0.25)] select-none"
- style={{ width: DESIGN_W, height: DESIGN_H, transform: `scale(${scale})` }}
- >
- {MOCK_PROJECTS.map((project, i) => (
- <div
- key={project.id}
- className={cn(
- // Same frame as the real editor: the chat panel is a
- // full-height column beside the top-bar/preview/timeline grid.
- "absolute inset-0 flex bg-card transition-opacity duration-300",
- i === active ? "opacity-100" : "opacity-0",
- )}
- >
- <div className="grid min-w-0 flex-1 grid-rows-[46px_minmax(0,1fr)_auto]">
- <MockTopBar project={project} />
- <div className="grid min-h-0 grid-cols-[auto_minmax(0,1fr)]">
- <MockSidePanel project={project} />
- <MockPreview project={project} active={i === active} />
- </div>
- <MockTimeline project={project} />
- </div>
- <MockAiPanel project={project} />
- </div>
- ))}
- </div>
- </div>
- </div>
- <figcaption className="sr-only">
- The Donkey Cut editor with a finished project open: generated media in
- the side panel, clips and music on the timeline, and the AI chat that
- assembled them.
- </figcaption>
- <div className="mt-6 flex flex-wrap justify-center gap-1.5">
- {MOCK_PROJECTS.map((project, i) => (
- <button
- key={project.id}
- type="button"
- onClick={() => setActive(i)}
- aria-pressed={i === active}
- className={cn(
- "flex items-center gap-1.5 rounded-full border border-ink px-2.5 py-3 text-xs font-medium transition-colors",
- i === active ? "bg-ink text-white" : "bg-white text-ink hover:bg-ink/5",
- )}
- >
- <span
- className={cn(
- "size-1.5 rounded-full",
- i === active ? "bg-coral" : "bg-ink/25",
- )}
- />
- {project.switcherLabel}
- </button>
- ))}
- </div>
- </figure>
- );
-}
diff --git a/site/src/cut/components/editor-mock/EditorMock.tsx b/site/src/cut/components/editor-mock/EditorMock.tsx
new file mode 100644
index 00000000..c229eceb
--- /dev/null
+++ b/site/src/cut/components/editor-mock/EditorMock.tsx
@@ -0,0 +1,152 @@
+"use client";
+
+import { useEffect, useRef, useState } from "react";
+
+import "./editor-mock.css";
+
+import { MockAiPanel } from "@/cut/components/editor-mock/MockAiPanel";
+import { MockPreview } from "@/cut/components/editor-mock/MockPreview";
+import { MockSidePanel } from "@/cut/components/editor-mock/MockSidePanel";
+import { MockTimeline } from "@/cut/components/editor-mock/MockTimeline";
+import { MockTopBar } from "@/cut/components/editor-mock/MockTopBar";
+import { MOCK_PROJECTS } from "@/cut/components/editor-mock/mockData";
+import { cn } from "@/lib/utils";
+
+// The mock is authored at a fixed design size and scaled to its container's
+// width, so its internals never reflow — it behaves like a live screenshot.
+const DESIGN_W = 1200;
+const DESIGN_H = 726;
+
+// Which slice of that design is on screen. "full" is the whole editor; "ai"
+// crops to the chat column and the timeline edge beside it, which is how the
+// same mock reads as a different picture when the subject is the assistant.
+const VIEWS = {
+ full: { x: 0, w: DESIGN_W },
+ ai: { x: 655, w: DESIGN_W - 655 },
+} as const;
+
+export type EditorMockView = keyof typeof VIEWS;
+
+type Props = {
+ view?: EditorMockView;
+ /** Which dimension the mock is sized by. "width" fills the container and
+ * takes whatever height that implies; "height" fills a container of bounded
+ * height and takes whatever width that implies, which is what a cropped view
+ * needs so it can't grow taller than the space it was given. */
+ fit?: "width" | "height";
+ /** The dots that switch projects. Off where the mock is one slide of a
+ * larger sequence and the only navigation should be that sequence's. */
+ showSwitcher?: boolean;
+};
+
+// A hand-built, display-only replica of the Cut editor showing two finished
+// projects. The panels copy the real components' chrome (see the Mock*
+// siblings) over hardcoded data — no stores, no engine. The dots below switch
+// projects; nothing auto-advances.
+export function EditorMock({
+ view = "full",
+ fit = "width",
+ showSwitcher = true,
+}: Props) {
+ const [active, setActive] = useState(0);
+ const frameRef = useRef<HTMLDivElement>(null);
+ const [box, setBox] = useState({ width: 0, height: 0 });
+
+ useEffect(() => {
+ const el = frameRef.current;
+ if (!el) return;
+ const ro = new ResizeObserver(([entry]) => {
+ const { width, height } = entry.contentRect;
+ setBox({ width, height });
+ });
+ ro.observe(el);
+ return () => ro.disconnect();
+ }, []);
+
+ const { x, w } = VIEWS[view];
+ const scale = fit === "height" ? box.height / DESIGN_H : box.width / w;
+
+ return (
+ <figure
+ className={cn("m-0 flex min-h-0 flex-col", fit === "height" && "h-full")}
+ >
+ <div
+ ref={frameRef}
+ className={cn("w-full", fit === "height" && "min-h-0 flex-1")}
+ >
+ {/* Sized by width, the box holds its shape from the aspect ratio alone,
+ so the space it will occupy is right before the first measurement
+ and the page never jumps under it. */}
+ <div
+ className="mx-auto overflow-hidden rounded-2xl bg-card shadow-[0_0_0_1px_rgba(0,0,0,0.08),0_24px_64px_rgba(15,14,13,0.25)]"
+ style={
+ fit === "height"
+ ? { width: Math.round(w * scale), height: Math.round(DESIGN_H * scale) }
+ : { width: "100%", aspectRatio: `${w} / ${DESIGN_H}` }
+ }
+ >
+ <div
+ aria-hidden
+ className="pointer-events-none relative origin-top-left overflow-hidden bg-card font-system text-foreground antialiased select-none"
+ style={{
+ width: DESIGN_W,
+ height: DESIGN_H,
+ transform: `scale(${scale}) translateX(${-x}px)`,
+ }}
+ >
+ {MOCK_PROJECTS.map((project, i) => (
+ <div
+ key={project.id}
+ className={cn(
+ // Same frame as the real editor: the chat panel is a
+ // full-height column beside the top-bar/preview/timeline grid.
+ "absolute inset-0 flex bg-card transition-opacity duration-300",
+ i === active ? "opacity-100" : "opacity-0",
+ )}
+ >
+ <div className="grid min-w-0 flex-1 grid-rows-[46px_minmax(0,1fr)_auto]">
+ <MockTopBar project={project} />
+ <div className="grid min-h-0 grid-cols-[auto_minmax(0,1fr)]">
+ <MockSidePanel project={project} />
+ <MockPreview project={project} active={i === active} />
+ </div>
+ <MockTimeline project={project} />
+ </div>
+ <MockAiPanel project={project} />
+ </div>
+ ))}
+ </div>
+ </div>
+ </div>
+ <figcaption className="sr-only">
+ The Donkey Cut editor with a finished project open: generated media in
+ the side panel, clips and music on the timeline, and the AI chat that
+ assembled them.
+ </figcaption>
+ {showSwitcher && (
+ <div className="mt-6 flex flex-wrap justify-center gap-1.5">
+ {MOCK_PROJECTS.map((project, i) => (
+ <button
+ key={project.id}
+ type="button"
+ onClick={() => setActive(i)}
+ aria-pressed={i === active}
+ className={cn(
+ "flex items-center gap-1.5 rounded-full border border-ink px-2.5 py-3 text-xs font-medium transition-colors",
+ i === active ? "bg-ink text-white" : "bg-white text-ink hover:bg-ink/5",
+ )}
+ >
+ <span
+ className={cn(
+ "size-1.5 rounded-full",
+ i === active ? "bg-coral" : "bg-ink/25",
+ )}
+ />
+ {project.switcherLabel}
+ </button>
+ ))}
+ </div>
+ )}
+ </figure>
+ );
+}
diff --git a/site/src/app/cut/_components/landing/editor-mock/MockAiPanel.tsx b/site/src/cut/components/editor-mock/MockAiPanel.tsx
similarity index 98%
rename from site/src/app/cut/_components/landing/editor-mock/MockAiPanel.tsx
rename to site/src/cut/components/editor-mock/MockAiPanel.tsx
index 3e8e2afe..1ecae5ca 100644
--- a/site/src/app/cut/_components/landing/editor-mock/MockAiPanel.tsx
+++ b/site/src/cut/components/editor-mock/MockAiPanel.tsx
@@ -14,7 +14,7 @@ import { cn } from "@/lib/utils";
import type {
MockChatMessage,
MockProject,
-} from "@/app/cut/_components/landing/editor-mock/mockData";
+} from "@/cut/components/editor-mock/mockData";
/** Static replica of the Cut editor's AI chat panel for the landing mock.
* Mirrors AiPanel's structure and Tailwind styling with hardcoded content. */
diff --git a/site/src/app/cut/_components/landing/editor-mock/MockPreview.tsx b/site/src/cut/components/editor-mock/MockPreview.tsx
similarity index 95%
rename from site/src/app/cut/_components/landing/editor-mock/MockPreview.tsx
rename to site/src/cut/components/editor-mock/MockPreview.tsx
index 823d3b65..82db99ae 100644
--- a/site/src/app/cut/_components/landing/editor-mock/MockPreview.tsx
+++ b/site/src/cut/components/editor-mock/MockPreview.tsx
@@ -2,7 +2,7 @@
import { useEffect, useRef } from "react";
-import type { MockProject } from "@/app/cut/_components/landing/editor-mock/mockData";
+import type { MockProject } from "@/cut/components/editor-mock/mockData";
// Static replica of the editor's preview stage (src/cut/components/Preview.tsx):
// the black rounded canvas on the muted backdrop, here playing a looping muted
diff --git a/site/src/app/cut/_components/landing/editor-mock/MockSidePanel.tsx b/site/src/cut/components/editor-mock/MockSidePanel.tsx
similarity index 99%
rename from site/src/app/cut/_components/landing/editor-mock/MockSidePanel.tsx
rename to site/src/cut/components/editor-mock/MockSidePanel.tsx
index 2c7a609a..dfd65de1 100644
--- a/site/src/app/cut/_components/landing/editor-mock/MockSidePanel.tsx
+++ b/site/src/cut/components/editor-mock/MockSidePanel.tsx
@@ -15,7 +15,7 @@ import { cn } from "@/lib/utils";
import type {
MockPanelTab,
MockProject,
-} from "@/app/cut/_components/landing/editor-mock/mockData";
+} from "@/cut/components/editor-mock/mockData";
// Static replica of the editor's left side panel for the landing mock: the
// icon rail plus the open generation panel, populated from hardcoded slide
diff --git a/site/src/app/cut/_components/landing/editor-mock/MockTimeline.tsx b/site/src/cut/components/editor-mock/MockTimeline.tsx
similarity index 98%
rename from site/src/app/cut/_components/landing/editor-mock/MockTimeline.tsx
rename to site/src/cut/components/editor-mock/MockTimeline.tsx
index e09c333f..43a09080 100644
--- a/site/src/app/cut/_components/landing/editor-mock/MockTimeline.tsx
+++ b/site/src/cut/components/editor-mock/MockTimeline.tsx
@@ -5,7 +5,7 @@
import type { CSSProperties } from "react";
import { cn } from "@/lib/utils";
-import type { MockProject } from "@/app/cut/_components/landing/editor-mock/mockData";
+import type { MockProject } from "@/cut/components/editor-mock/mockData";
// The timeline column sits left of the full-height chat panel (340px), so its
// usable track width is the frame minus that column and some gutter.
diff --git a/site/src/app/cut/_components/landing/editor-mock/MockTopBar.tsx b/site/src/cut/components/editor-mock/MockTopBar.tsx
similarity index 96%
rename from site/src/app/cut/_components/landing/editor-mock/MockTopBar.tsx
rename to site/src/cut/components/editor-mock/MockTopBar.tsx
index ccc0dba0..76977682 100644
--- a/site/src/app/cut/_components/landing/editor-mock/MockTopBar.tsx
+++ b/site/src/cut/components/editor-mock/MockTopBar.tsx
@@ -10,7 +10,7 @@ import {
Upload,
} from "lucide-react";
-import type { MockProject } from "@/app/cut/_components/landing/editor-mock/mockData";
+import type { MockProject } from "@/cut/components/editor-mock/mockData";
// Static replica of src/cut/components/TopBar.tsx — same chrome, no store.
export function MockTopBar({ project }: { project: MockProject }) {
diff --git a/site/src/app/cut/_components/landing/editor-mock/editor-mock.css b/site/src/cut/components/editor-mock/editor-mock.css
similarity index 100%
rename from site/src/app/cut/_components/landing/editor-mock/editor-mock.css
rename to site/src/cut/components/editor-mock/editor-mock.css
diff --git a/site/src/app/cut/_components/landing/editor-mock/mockData.ts b/site/src/cut/components/editor-mock/mockData.ts
similarity index 100%
rename from site/src/app/cut/_components/landing/editor-mock/mockData.ts
rename to site/src/cut/components/editor-mock/mockData.ts