summaryrefslogtreecommitdiff
path: root/apps/web/src/components/editor/preview-panel.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/components/editor/preview-panel.tsx')
-rw-r--r--apps/web/src/components/editor/preview-panel.tsx104
1 files changed, 75 insertions, 29 deletions
diff --git a/apps/web/src/components/editor/preview-panel.tsx b/apps/web/src/components/editor/preview-panel.tsx
index 14b086fe..8842b482 100644
--- a/apps/web/src/components/editor/preview-panel.tsx
+++ b/apps/web/src/components/editor/preview-panel.tsx
@@ -14,8 +14,18 @@ import { cn } from "@/lib/utils";
import { formatTimeCode } from "@/lib/time";
import { EditableTimecode } from "@/components/ui/editable-timecode";
import { FONT_CLASS_MAP } from "@/lib/font-config";
-import { useProjectStore } from "@/stores/project-store";
+import { DEFAULT_CANVAS_SIZE, useProjectStore } from "@/stores/project-store";
import { TextElementDragState } from "@/types/editor";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
+import { Checkbox } from "@/components/ui/checkbox";
+import { LayoutGuideOverlay } from "./layout-guide-overlay";
+import { Label } from "../ui/label";
+import { SocialsIcon } from "../icons";
+import { PLATFORM_LAYOUTS, type PlatformLayout } from "@/stores/editor-store";
interface ActiveElement {
element: TimelineElement;
@@ -26,8 +36,8 @@ interface ActiveElement {
export function PreviewPanel() {
const { tracks, getTotalDuration, updateTextElement } = useTimelineStore();
const { mediaItems } = useMediaStore();
- const { currentTime, toggle, setCurrentTime, isPlaying } = usePlaybackStore();
- const { canvasSize } = useEditorStore();
+ const { currentTime, toggle, setCurrentTime } = usePlaybackStore();
+ const { activeProject } = useProjectStore();
const previewRef = useRef<HTMLDivElement>(null);
const containerRef = useRef<HTMLDivElement>(null);
const [previewDimensions, setPreviewDimensions] = useState({
@@ -35,7 +45,8 @@ export function PreviewPanel() {
height: 0,
});
const [isExpanded, setIsExpanded] = useState(false);
- const { activeProject } = useProjectStore();
+
+ const canvasSize = activeProject?.canvasSize || DEFAULT_CANVAS_SIZE;
const [dragState, setDragState] = useState<TextElementDragState>({
isDragging: false,
elementId: null,
@@ -350,20 +361,18 @@ export function PreviewPanel() {
style={{
left: `${
50 +
- (
- (dragState.isDragging && dragState.elementId === element.id
- ? dragState.currentX
- : element.x) / canvasSize.width
- ) *
+ ((dragState.isDragging && dragState.elementId === element.id
+ ? dragState.currentX
+ : element.x) /
+ canvasSize.width) *
100
}%`,
top: `${
50 +
- (
- (dragState.isDragging && dragState.elementId === element.id
- ? dragState.currentY
- : element.y) / canvasSize.height
- ) *
+ ((dragState.isDragging && dragState.elementId === element.id
+ ? dragState.currentY
+ : element.y) /
+ canvasSize.height) *
100
}%`,
transform: `translate(-50%, -50%) rotate(${element.rotation}deg) scale(${scaleRatio})`,
@@ -498,13 +507,7 @@ export function PreviewPanel() {
renderElement(elementData, index)
)
)}
- {activeProject?.backgroundType === "blur" &&
- blurBackgroundElements.length === 0 &&
- activeElements.length > 0 && (
- <div className="absolute bottom-2 left-2 right-2 bg-black/70 text-white text-xs p-2 rounded">
- Add a video or image to use blur background
- </div>
- )}
+ <LayoutGuideOverlay />
</div>
) : null}
@@ -760,13 +763,7 @@ function FullscreenPreview({
renderElement(elementData, index)
)
)}
- {activeProject?.backgroundType === "blur" &&
- blurBackgroundElements.length === 0 &&
- activeElements.length > 0 && (
- <div className="absolute bottom-2 left-2 right-2 bg-black/70 text-white text-xs p-2 rounded">
- Add a video or image to use blur background
- </div>
- )}
+ <LayoutGuideOverlay />
</div>
</div>
<div className="p-4 bg-background">
@@ -801,6 +798,7 @@ function PreviewToolbar({
getTotalDuration: () => number;
}) {
const { isPlaying } = usePlaybackStore();
+ const { layoutGuide, toggleLayoutGuide } = useEditorStore();
if (isExpanded) {
return (
@@ -820,7 +818,7 @@ function PreviewToolbar({
return (
<div
data-toolbar
- className="flex justify-between gap-2 px-1.5 pr-4 py-1.5 border border-border/50 w-auto absolute bottom-4 right-4 bg-black/20 rounded-full backdrop-blur-l text-white"
+ className="flex justify-end gap-2 h-auto pb-5 pr-5 pt-4 w-full"
>
<div className="flex items-center gap-2">
<Button
@@ -836,6 +834,54 @@ function PreviewToolbar({
<Play className="h-3 w-3" />
)}
</Button>
+ <Popover>
+ <PopoverTrigger asChild>
+ <Button
+ variant="text"
+ size="icon"
+ className="h-auto p-0 mr-1"
+ title="Toggle layout guide"
+ >
+ <SocialsIcon className="!size-6" />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent className="w-80">
+ <div className="grid gap-4">
+ <div className="space-y-2">
+ <h4 className="font-medium leading-none">Layout guide</h4>
+ <p className="text-sm text-muted-foreground">
+ Show platform-specific layout guides to help align your
+ content with interface elements like profile pictures,
+ usernames, and interaction buttons.
+ </p>
+ </div>
+ <div className="grid gap-2">
+ <div className="flex items-center space-x-2">
+ <Checkbox
+ id="none"
+ checked={layoutGuide.platform === null}
+ onCheckedChange={() =>
+ toggleLayoutGuide(layoutGuide.platform || "tiktok")
+ }
+ />
+ <Label htmlFor="none">None</Label>
+ </div>
+ {Object.entries(PLATFORM_LAYOUTS).map(([platform, label]) => (
+ <div key={platform} className="flex items-center space-x-2">
+ <Checkbox
+ id={platform}
+ checked={layoutGuide.platform === platform}
+ onCheckedChange={() =>
+ toggleLayoutGuide(platform as PlatformLayout)
+ }
+ />
+ <Label htmlFor={platform}>{label}</Label>
+ </div>
+ ))}
+ </div>
+ </div>
+ </PopoverContent>
+ </Popover>
<Button
variant="text"
size="icon"