feat: add conditional rendering to properties panel with text change functionality

This commit is contained in:
Maze Winther
2025-07-09 23:59:39 +02:00
parent b6aa8e10d6
commit 8dd6f9a9b3
2 changed files with 102 additions and 12 deletions

View File

@ -4,6 +4,7 @@ import {
TimelineElement,
CreateTimelineElement,
TimelineTrack,
TextElement,
sortTracksByOrder,
ensureMainTrack,
validateElementTrackCompatibility,
@ -136,6 +137,28 @@ interface TimelineStore {
loadProjectTimeline: (projectId: string) => Promise<void>;
saveProjectTimeline: (projectId: string) => Promise<void>;
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<TimelineStore>((set, get) => {
@ -494,6 +517,24 @@ export const useTimelineStore = create<TimelineStore>((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);