diff --git a/apps/web/src/components/editor/properties-panel.tsx b/apps/web/src/components/editor/properties-panel.tsx index b0f9c62..4aea58c 100644 --- a/apps/web/src/components/editor/properties-panel.tsx +++ b/apps/web/src/components/editor/properties-panel.tsx @@ -4,25 +4,74 @@ import { useProjectStore } from "@/stores/project-store"; import { useAspectRatio } from "@/hooks/use-aspect-ratio"; import { Label } from "../ui/label"; import { ScrollArea } from "../ui/scroll-area"; +import { useTimelineStore } from "@/stores/timeline-store"; +import { Input } from "../ui/input"; +import { MediaElement, TextElement } from "@/types/timeline"; +import { useMediaStore } from "@/stores/media-store"; export function PropertiesPanel() { const { activeProject } = useProjectStore(); const { getDisplayName, canvasSize } = useAspectRatio(); + const { selectedElements, tracks, updateTextElement } = useTimelineStore(); + const { mediaItems } = useMediaStore(); + + const emptyView = ( +
+ {/* Media Properties */} +
+ + + + +
+
+ ); + + const TextProperties = (element: TextElement, trackId: string) => ( +
+ + updateTextElement(trackId, element.id, { content: e.target.value }) + } + /> +
+ ); + + const MediaProperties = (element: MediaElement) => { + const mediaItem = mediaItems.find((item) => item.id === element.mediaId); + + if (mediaItem?.type === "audio") { + return
Audio properties
; + } + + // video or image + return
Video/Image properties
; + }; + + const ElementProperties = ( + <> + {selectedElements.map(({ trackId, elementId }) => { + const track = tracks.find((t) => t.id === trackId); + const element = track?.elements.find((e) => e.id === elementId); + + if (element?.type === "text") { + return
{TextProperties(element, trackId)}
; + } + if (element?.type === "media") { + return
{MediaProperties(element)}
; + } + })} + + ); return ( -
- {/* Media Properties */} -
- - - - -
-
+ {selectedElements.length > 0 ? ElementProperties : emptyView}
); } diff --git a/apps/web/src/stores/timeline-store.ts b/apps/web/src/stores/timeline-store.ts index 7431e08..8c93439 100644 --- a/apps/web/src/stores/timeline-store.ts +++ b/apps/web/src/stores/timeline-store.ts @@ -4,6 +4,7 @@ import { TimelineElement, CreateTimelineElement, TimelineTrack, + TextElement, sortTracksByOrder, ensureMainTrack, validateElementTrackCompatibility, @@ -136,6 +137,28 @@ interface TimelineStore { loadProjectTimeline: (projectId: string) => Promise; saveProjectTimeline: (projectId: string) => Promise; clearTimeline: () => void; + updateTextElement: ( + trackId: string, + elementId: string, + updates: Partial< + Pick< + TextElement, + | "content" + | "fontSize" + | "fontFamily" + | "color" + | "backgroundColor" + | "textAlign" + | "fontWeight" + | "fontStyle" + | "textDecoration" + | "x" + | "y" + | "rotation" + | "opacity" + > + > + ) => void; } export const useTimelineStore = create((set, get) => { @@ -494,6 +517,24 @@ export const useTimelineStore = create((set, get) => { ); }, + updateTextElement: (trackId, elementId, updates) => { + get().pushHistory(); + updateTracksAndSave( + get()._tracks.map((track) => + track.id === trackId + ? { + ...track, + elements: track.elements.map((element) => + element.id === elementId && element.type === "text" + ? { ...element, ...updates } + : element + ), + } + : track + ) + ); + }, + splitElement: (trackId, elementId, splitTime) => { const { _tracks } = get(); const track = _tracks.find((t) => t.id === trackId);