summaryrefslogtreecommitdiff
path: root/apps/web/src/components/editor/panels/timeline
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/components/editor/panels/timeline')
-rw-r--r--apps/web/src/components/editor/panels/timeline/drag-line.tsx2
-rw-r--r--apps/web/src/components/editor/panels/timeline/index.tsx115
-rw-r--r--apps/web/src/components/editor/panels/timeline/timeline-element.tsx424
-rw-r--r--apps/web/src/components/editor/panels/timeline/timeline-toolbar.tsx20
-rw-r--r--apps/web/src/components/editor/panels/timeline/timeline-track.tsx3
5 files changed, 323 insertions, 241 deletions
diff --git a/apps/web/src/components/editor/panels/timeline/drag-line.tsx b/apps/web/src/components/editor/panels/timeline/drag-line.tsx
index f31c6e28..291a4633 100644
--- a/apps/web/src/components/editor/panels/timeline/drag-line.tsx
+++ b/apps/web/src/components/editor/panels/timeline/drag-line.tsx
@@ -21,7 +21,7 @@ export function DragLine({
return (
<div
- className="bg-primary pointer-events-none absolute right-0 left-0 z-50 h-0.5"
+ className="bg-primary pointer-events-none absolute right-0 left-0 h-0.5"
style={{ top: `${lineTop}px` }}
/>
);
diff --git a/apps/web/src/components/editor/panels/timeline/index.tsx b/apps/web/src/components/editor/panels/timeline/index.tsx
index d89d270d..593976a8 100644
--- a/apps/web/src/components/editor/panels/timeline/index.tsx
+++ b/apps/web/src/components/editor/panels/timeline/index.tsx
@@ -55,16 +55,18 @@ import { useTimelinePlayhead } from "@/hooks/timeline/use-timeline-playhead";
import { DragLine } from "./drag-line";
import { invokeAction } from "@/lib/actions";
+const TRACKS_CONTAINER_MAX_HEIGHT = 800;
+const FALLBACK_CONTAINER_WIDTH = 1000;
+
export function Timeline() {
- const tracksContainerHeight = { min: 0, max: 800 };
- const { snappingEnabled } = useTimelineStore();
+ const tracksContainerHeight = { min: 0, max: TRACKS_CONTAINER_MAX_HEIGHT };
+ const snappingEnabled = useTimelineStore((s) => s.snappingEnabled);
const { clearElementSelection, setElementSelection } = useElementSelection();
const editor = useEditor();
const timeline = editor.timeline;
const tracks = timeline.getTracks();
const seek = (time: number) => editor.playback.seek({ time });
- // refs
const timelineRef = useRef<HTMLDivElement>(null);
const timelineHeaderRef = useRef<HTMLDivElement>(null);
const rulerRef = useRef<HTMLDivElement>(null);
@@ -74,7 +76,6 @@ export function Timeline() {
const playheadRef = useRef<HTMLDivElement>(null);
const trackLabelsScrollRef = useRef<HTMLDivElement>(null);
- // state
const [isResizing, setIsResizing] = useState(false);
const [currentSnapPoint, setCurrentSnapPoint] = useState<SnapPoint | null>(
null,
@@ -151,6 +152,7 @@ export function Timeline() {
const { isDragOver, dropTarget, dragProps } = useTimelineDragDrop({
containerRef: tracksContainerRef,
headerRef: timelineHeaderRef,
+ tracksScrollRef,
zoomLevel,
});
@@ -169,7 +171,7 @@ export function Timeline() {
zoomLevel,
});
- const containerWidth = tracksContainerRef.current?.clientWidth || 1000;
+ const containerWidth = tracksContainerRef.current?.clientWidth || FALLBACK_CONTAINER_WIDTH;
const contentWidth =
timelineDuration * TIMELINE_CONSTANTS.PIXELS_PER_SECOND * zoomLevel;
const paddingPx = getTimelinePaddingPx({
@@ -422,7 +424,20 @@ export function Timeline() {
{tracks.length === 0 ? (
<div />
) : (
- tracks.map((track, index) => (
+ [...tracks]
+ .map((track, index) => ({ track, index }))
+ .sort((a, b) => {
+ const aHasDragged = a.track.elements.some(
+ (element) => element.id === dragState.elementId,
+ );
+ const bHasDragged = b.track.elements.some(
+ (element) => element.id === dragState.elementId,
+ );
+ if (aHasDragged) return 1;
+ if (bHasDragged) return -1;
+ return 0;
+ })
+ .map(({ track, index }) => (
<ContextMenu key={track.id}>
<ContextMenuTrigger asChild>
<div
@@ -465,50 +480,50 @@ export function Timeline() {
<ContextMenuContent className="w-40">
<ContextMenuItem
icon={<HugeiconsIcon icon={TaskAdd02Icon} />}
- onClick={(e) => {
- e.stopPropagation();
- invokeAction("paste-copied");
- }}
- >
- Paste elements
- </ContextMenuItem>
- <ContextMenuItem
- onClick={(e) => {
- e.stopPropagation();
- timeline.toggleTrackMute({
- trackId: track.id,
- });
- }}
- >
- <HugeiconsIcon icon={VolumeHighIcon} />
- <span>
- {canTracktHaveAudio(track) && track.muted
- ? "Unmute track"
- : "Mute track"}
- </span>
- </ContextMenuItem>
- <ContextMenuItem
- onClick={(e) => {
- e.stopPropagation();
- timeline.toggleTrackVisibility({
- trackId: track.id,
- });
- }}
- >
- <HugeiconsIcon icon={ViewIcon} />
- <span>
- {canTrackBeHidden(track) && track.hidden
- ? "Show track"
- : "Hide track"}
- </span>
- </ContextMenuItem>
- <ContextMenuItem
- onClick={(e) => {
- e.stopPropagation();
- timeline.removeTrack({
- trackId: track.id,
- });
- }}
+ onClick={(event) => {
+ event.stopPropagation();
+ invokeAction("paste-copied");
+ }}
+ >
+ Paste elements
+ </ContextMenuItem>
+ <ContextMenuItem
+ onClick={(event) => {
+ event.stopPropagation();
+ timeline.toggleTrackMute({
+ trackId: track.id,
+ });
+ }}
+ >
+ <HugeiconsIcon icon={VolumeHighIcon} />
+ <span>
+ {canTracktHaveAudio(track) && track.muted
+ ? "Unmute track"
+ : "Mute track"}
+ </span>
+ </ContextMenuItem>
+ <ContextMenuItem
+ onClick={(event) => {
+ event.stopPropagation();
+ timeline.toggleTrackVisibility({
+ trackId: track.id,
+ });
+ }}
+ >
+ <HugeiconsIcon icon={ViewIcon} />
+ <span>
+ {canTrackBeHidden(track) && track.hidden
+ ? "Show track"
+ : "Hide track"}
+ </span>
+ </ContextMenuItem>
+ <ContextMenuItem
+ onClick={(event) => {
+ event.stopPropagation();
+ timeline.removeTrack({
+ trackId: track.id,
+ });
+ }}
variant="destructive"
>
<HugeiconsIcon icon={Delete02Icon} />
diff --git a/apps/web/src/components/editor/panels/timeline/timeline-element.tsx b/apps/web/src/components/editor/panels/timeline/timeline-element.tsx
index 38cf953b..f96979d4 100644
--- a/apps/web/src/components/editor/panels/timeline/timeline-element.tsx
+++ b/apps/web/src/components/editor/panels/timeline/timeline-element.tsx
@@ -4,6 +4,10 @@ import { useEditor } from "@/hooks/use-editor";
import { useAssetsPanelStore } from "@/stores/assets-panel-store";
import AudioWaveform from "./audio-waveform";
import { useTimelineElementResize } from "@/hooks/timeline/element/use-element-resize";
+import {
+ useKeyframeDrag,
+ type KeyframeDragState,
+} from "@/hooks/timeline/element/use-keyframe-drag";
import { useKeyframeSelection } from "@/hooks/timeline/element/use-keyframe-selection";
import type { SnapPoint } from "@/lib/timeline/snap-utils";
import { getElementKeyframes } from "@/lib/animation";
@@ -26,6 +30,7 @@ import {
import type {
TimelineElement as TimelineElementType,
TimelineTrack,
+ VisualElement,
ElementDragState,
} from "@/types/timeline";
import type { MediaAsset } from "@/types/assets";
@@ -53,8 +58,11 @@ import { uppercase } from "@/utils/string";
import type { ComponentProps, ReactNode } from "react";
import type { SelectedKeyframeRef, ElementKeyframe } from "@/types/animation";
import { cn } from "@/utils/ui";
+import { Button } from "@/components/ui/button";
+import { usePropertiesStore } from "@/stores/properties-store";
const KEYFRAME_INDICATOR_MIN_WIDTH_PX = 40;
+const ELEMENT_RING_WIDTH_PX = 1.5;
interface KeyframeIndicator {
time: number;
@@ -62,7 +70,7 @@ interface KeyframeIndicator {
keyframes: SelectedKeyframeRef[];
}
-function buildKeyframeIndicator({
+export function buildKeyframeIndicator({
keyframe,
trackId,
elementId,
@@ -98,7 +106,7 @@ function buildKeyframeIndicator({
};
}
-function getKeyframeIndicators({
+export function getKeyframeIndicators({
keyframes,
trackId,
elementId,
@@ -145,8 +153,8 @@ function getKeyframeIndicators({
return [...keyframesByTime.values()].sort((a, b) => a.time - b.time);
}
-function getDisplayShortcut(action: TAction) {
- const { defaultShortcuts } = getActionDefinition(action);
+export function getDisplayShortcut({ action }: { action: TAction }) {
+ const { defaultShortcuts } = getActionDefinition({ action });
if (!defaultShortcuts?.length) {
return "";
}
@@ -164,10 +172,13 @@ interface TimelineElementProps {
onSnapPointChange?: (snapPoint: SnapPoint | null) => void;
onResizeStateChange?: (params: { isResizing: boolean }) => void;
onElementMouseDown: (
- e: React.MouseEvent,
+ event: React.MouseEvent,
+ element: TimelineElementType,
+ ) => void;
+ onElementClick: (
+ event: React.MouseEvent,
element: TimelineElementType,
) => void;
- onElementClick: (e: React.MouseEvent, element: TimelineElementType) => void;
dragState: ElementDragState;
isDropTarget?: boolean;
}
@@ -188,12 +199,12 @@ export function TimelineElement({
const { selectedElements } = useElementSelection();
const { requestRevealMedia } = useAssetsPanelStore();
- const mediaAssets = editor.media.getAssets();
let mediaAsset: MediaAsset | null = null;
if (hasMediaId(element)) {
mediaAsset =
- mediaAssets.find((asset) => asset.id === element.mediaId) ?? null;
+ editor.media.getAssets().find((asset) => asset.id === element.mediaId) ??
+ null;
}
const hasAudio = mediaSupportsAudio({ media: mediaAsset });
@@ -242,6 +253,13 @@ export function TimelineElement({
elementWidth,
})
: [];
+
+ const {
+ keyframeDragState,
+ handleKeyframeMouseDown,
+ handleKeyframeClick,
+ getVisualOffsetPx,
+ } = useKeyframeDrag({ zoomLevel, element });
const handleRevealInMedia = ({ event }: { event: React.MouseEvent }) => {
event.stopPropagation();
if (hasMediaId(element)) {
@@ -255,7 +273,7 @@ export function TimelineElement({
<ContextMenu>
<ContextMenuTrigger asChild>
<div
- className={`absolute top-0 h-full select-none`}
+ className="absolute top-0 h-full select-none"
style={{
left: `${elementLeft}px`,
width: `${elementWidth}px`,
@@ -269,15 +287,24 @@ export function TimelineElement({
element={element}
track={track}
isSelected={isSelected}
- hasAudio={hasAudio}
- isMuted={isMuted}
- mediaAssets={mediaAssets}
onElementClick={onElementClick}
onElementMouseDown={onElementMouseDown}
handleResizeStart={handleResizeStart}
isDropTarget={isDropTarget}
/>
- {isSelected && <KeyframeIndicators indicators={keyframeIndicators} />}
+ {isSelected && (
+ <div className="pointer-events-none absolute inset-0 overflow-hidden">
+ <KeyframeIndicators
+ indicators={keyframeIndicators}
+ dragState={keyframeDragState}
+ displayedStartTime={displayedStartTime}
+ elementLeft={elementLeft}
+ onKeyframeMouseDown={handleKeyframeMouseDown}
+ onKeyframeClick={handleKeyframeClick}
+ getVisualOffsetPx={getVisualOffsetPx}
+ />
+ </div>
+ )}
</div>
</ContextMenuTrigger>
<ContextMenuContent className="w-64">
@@ -344,9 +371,6 @@ function ElementInner({
element,
track,
isSelected,
- hasAudio,
- isMuted,
- mediaAssets,
onElementClick,
onElementMouseDown,
handleResizeStart,
@@ -355,12 +379,12 @@ function ElementInner({
element: TimelineElementType;
track: TimelineTrack;
isSelected: boolean;
- hasAudio: boolean;
- isMuted: boolean;
- mediaAssets: MediaAsset[];
- onElementClick: (e: React.MouseEvent, element: TimelineElementType) => void;
+ onElementClick: (
+ event: React.MouseEvent,
+ element: TimelineElementType,
+ ) => void;
onElementMouseDown: (
- e: React.MouseEvent,
+ event: React.MouseEvent,
element: TimelineElementType,
) => void;
handleResizeStart: (params: {
@@ -374,47 +398,56 @@ function ElementInner({
(canElementBeHidden(element) && element.hidden) || isDropTarget
? "opacity-50"
: "";
+ const closeClipEffects = usePropertiesStore(
+ (state) => state.closeClipEffects,
+ );
return (
<div
- className={`relative h-full cursor-pointer overflow-hidden rounded-[0.5rem] ${getTrackClasses(
- {
- type: track.type,
- },
- )} ${opacityClass}`}
+ className="relative h-full cursor-pointer"
+ style={{ marginInline: ELEMENT_RING_WIDTH_PX }}
>
- <button
- type="button"
- className="absolute inset-0 size-full cursor-pointer"
- onClick={(e) => onElementClick(e, element)}
- onMouseDown={(e) => onElementMouseDown(e, element)}
+ <div
+ className={cn(
+ "absolute inset-0 overflow-hidden rounded-sm",
+ getTrackClasses({ type: track.type }),
+ opacityClass,
+ )}
+ style={
+ isSelected
+ ? {
+ boxShadow: `0 0 0 ${ELEMENT_RING_WIDTH_PX}px var(--foreground)`,
+ }
+ : undefined
+ }
>
- <div className="absolute inset-0 flex h-full items-center">
- <ElementContent
- element={element}
- track={track}
- isSelected={isSelected}
- mediaAssets={mediaAssets}
+ <button
+ type="button"
+ className="absolute inset-0 size-full cursor-pointer flex flex-col"
+ onClick={(event) => {
+ closeClipEffects();
+ onElementClick(event, element);
+ }}
+ onMouseDown={(event) => onElementMouseDown(event, element)}
+ >
+ <div className="flex flex-1 min-h-0 items-center overflow-hidden">
+ <ElementContent
+ element={element}
+ track={track}
+ isSelected={isSelected}
+ />
+ </div>
+ </button>
+ </div>
+
+ {element.type !== "audio" && element.type !== "effect" && (
+ <div className="sticky left-1 z-10 mt-1 ml-1 w-fit">
+ <EffectsButton
+ element={element as VisualElement}
+ trackId={track.id}
/>
</div>
- {(hasAudio
- ? isMuted
- : canElementBeHidden(element) && element.hidden) && (
- <div className="bg-opacity-50 pointer-events-none absolute inset-0 flex items-center justify-center bg-black">
- {hasAudio ? (
- <HugeiconsIcon
- icon={VolumeHighIcon}
- className="size-6 text-white"
- />
- ) : (
- <HugeiconsIcon
- icon={VolumeOffIcon}
- className="size-6 text-white"
- />
- )}
- </div>
- )}
- </button>
+ )}
{isSelected && (
<>
@@ -451,68 +484,82 @@ function ResizeHandle({
return (
<button
type="button"
- className={`bg-primary absolute top-0 bottom-0 flex w-[0.6rem] items-center justify-center ${isLeft ? "left-0 cursor-w-resize" : "right-0 cursor-e-resize"}`}
+ className={cn(
+ "absolute top-0 bottom-0 w-2",
+ isLeft ? "-left-1 cursor-w-resize" : "-right-1 cursor-e-resize",
+ )}
onMouseDown={(event) => handleResizeStart({ event, elementId, side })}
+ onClick={(event) => event.stopPropagation()}
aria-label={`${isLeft ? "Left" : "Right"} resize handle`}
- >
- <div className="bg-foreground h-[1.5rem] w-[0.2rem] rounded-full" />
- </button>
+ ></button>
);
}
function KeyframeIndicators({
indicators,
+ dragState,
+ displayedStartTime,
+ elementLeft,
+ onKeyframeMouseDown,
+ onKeyframeClick,
+ getVisualOffsetPx,
}: {
indicators: KeyframeIndicator[];
+ dragState: KeyframeDragState;
+ displayedStartTime: number;
+ elementLeft: number;
+ onKeyframeMouseDown: (params: {
+ event: React.MouseEvent;
+ keyframes: SelectedKeyframeRef[];
+ }) => void;
+ onKeyframeClick: (params: {
+ event: React.MouseEvent;
+ keyframes: SelectedKeyframeRef[];
+ orderedKeyframes: SelectedKeyframeRef[];
+ }) => void;
+ getVisualOffsetPx: (params: {
+ indicatorTime: number;
+ indicatorOffsetPx: number;
+ isBeingDragged: boolean;
+ displayedStartTime: number;
+ elementLeft: number;
+ }) => number;
}) {
- const { isKeyframeSelected, toggleKeyframeSelection, selectKeyframeRange } =
- useKeyframeSelection();
+ const { isKeyframeSelected } = useKeyframeSelection();
const orderedKeyframes = indicators.flatMap(
(indicator) => indicator.keyframes,
);
- const handleKeyframeMouseDown = ({ event }: { event: React.MouseEvent }) => {
- event.preventDefault();
- event.stopPropagation();
- };
-
- const handleKeyframeClick = ({
- event,
- keyframes,
- }: {
- event: React.MouseEvent;
- keyframes: SelectedKeyframeRef[];
- }) => {
- event.stopPropagation();
- if (event.shiftKey) {
- selectKeyframeRange({
- orderedKeyframes,
- targetKeyframes: keyframes,
- isAdditive: event.metaKey || event.ctrlKey,
- });
- return;
- }
-
- toggleKeyframeSelection({
- keyframes,
- isMultiKey: event.metaKey || event.ctrlKey,
- });
- };
-
return indicators.map((indicator) => {
const isIndicatorSelected = indicator.keyframes.some((keyframe) =>
isKeyframeSelected({ keyframe }),
);
+ const isBeingDragged = indicator.keyframes.some((kf) =>
+ dragState.draggingKeyframeIds.has(kf.keyframeId),
+ );
+ const visualOffsetPx = getVisualOffsetPx({
+ indicatorTime: indicator.time,
+ indicatorOffsetPx: indicator.offsetPx,
+ isBeingDragged,
+ displayedStartTime,
+ elementLeft,
+ });
return (
<button
key={indicator.time}
type="button"
- className="absolute top-1/2 -translate-x-1/2 -translate-y-1/2 cursor-pointer"
- style={{ left: indicator.offsetPx }}
- onMouseDown={(event) => handleKeyframeMouseDown({ event })}
+ className="pointer-events-auto absolute top-1/2 -translate-x-1/2 -translate-y-1/2 cursor-grab"
+ style={{ left: visualOffsetPx }}
+ onMouseDown={(event) =>
+ onKeyframeMouseDown({ event, keyframes: indicator.keyframes })
+ }
onClick={(event) =>
- handleKeyframeClick({ event, keyframes: indicator.keyframes })
+ onKeyframeClick({
+ event,
+ keyframes: indicator.keyframes,
+ orderedKeyframes,
+ })
}
aria-label="Select keyframe"
>
@@ -533,10 +580,82 @@ interface ElementContentProps {
element: TimelineElementType;
track: TimelineTrack;
isSelected: boolean;
+}
+
+interface ElementContentRendererProps extends ElementContentProps {
mediaAssets: MediaAsset[];
}
-type ElementContentRenderer = (props: ElementContentProps) => ReactNode;
+type ElementContentRenderer = (props: ElementContentRendererProps) => ReactNode;
+
+export function renderTiledMedia({
+ element,
+ imageUrl,
+ track,
+}: {
+ element: VisualElement;
+ imageUrl: string | undefined;
+ track: ElementContentProps["track"];
+}): ReactNode {
+ if (!imageUrl) {
+ return (
+ <span className="text-foreground/80 truncate text-xs">
+ {element.name}
+ </span>
+ );
+ }
+
+ const trackHeight = getTrackHeight({ type: track.type });
+ const tileWidth = trackHeight * (16 / 9);
+
+ return (
+ <div
+ className="absolute inset-0"
+ style={{
+ backgroundImage: `url(${imageUrl})`,
+ backgroundRepeat: "repeat-x",
+ backgroundSize: `${tileWidth}px ${trackHeight}px`,
+ backgroundPosition: "left center",
+ pointerEvents: "none",
+ }}
+ />
+ );
+}
+
+function EffectsButton({
+ element,
+ trackId,
+ className,
+}: {
+ element: VisualElement;
+ trackId: string;
+ className?: string;
+}) {
+ const openClipEffects = usePropertiesStore((state) => state.openClipEffects);
+ const { selectElement } = useElementSelection();
+
+ if (!element.effects?.length) {
+ return null;
+ }
+
+ const handleClick = (event: React.MouseEvent) => {
+ event.stopPropagation();
+ selectElement({ elementId: element.id, trackId });
+ openClipEffects({ elementId: element.id, trackId });
+ };
+
+ return (
+ <Button
+ variant="text"
+ size="icon"
+ className={cn("rounded-sm !size-5 bg-background/50", className)}
+ onClick={handleClick}
+ onMouseDown={(event) => event.stopPropagation()}
+ >
+ <HugeiconsIcon icon={MagicWand05Icon} />
+ </Button>
+ );
+}
const ELEMENT_CONTENT_RENDERERS: Record<
TimelineElementType["type"],
@@ -548,7 +667,7 @@ const ELEMENT_CONTENT_RENDERERS: Record<
{ type: "text" }
>;
return (
- <div className="flex size-full items-center justify-start pl-3">
+ <div className="flex size-full items-center justify-start pl-2">
<span className="truncate text-xs text-white">
{textElement.content}
</span>
@@ -557,8 +676,11 @@ const ELEMENT_CONTENT_RENDERERS: Record<
},
effect: ({ element }) => (
<div className="flex size-full items-center justify-start gap-1 pl-2">
- <HugeiconsIcon icon={MagicWand05Icon} className="size-4 shrink-0 text-white" />
- <span className="truncate text-xs text-white">{element.name}</span>
+ <HugeiconsIcon
+ icon={MagicWand05Icon}
+ className="size-4 shrink-0 text-white"
+ />
+ <span className="truncate text-xs text-white ml-1">{element.name}</span>
</div>
),
sticker: ({ element }) => {
@@ -618,7 +740,7 @@ const ELEMENT_CONTENT_RENDERERS: Record<
</span>
);
},
- video: ({ element, track, isSelected, mediaAssets }) => {
+ video: ({ element, track, mediaAssets }) => {
const videoElement = element as Extract<
TimelineElementType,
{ type: "video" }
@@ -626,48 +748,13 @@ const ELEMENT_CONTENT_RENDERERS: Record<
const mediaAsset = mediaAssets.find(
(asset) => asset.id === videoElement.mediaId,
);
-
- if (!mediaAsset) {
- return (
- <span className="text-foreground/80 truncate text-xs">
- {videoElement.name}
- </span>
- );
- }
-
- if (mediaAsset.thumbnailUrl) {
- const trackHeight = getTrackHeight({ type: track.type });
- const tileWidth = trackHeight * (16 / 9);
-
- return (
- <div className="flex size-full items-center justify-center">
- <div
- className={`relative size-full ${isSelected ? "bg-primary" : "bg-transparent"}`}
- >
- <div
- className="absolute right-0 left-0"
- style={{
- backgroundImage: `url(${mediaAsset.thumbnailUrl})`,
- backgroundRepeat: "repeat-x",
- backgroundSize: `${tileWidth}px ${trackHeight}px`,
- backgroundPosition: "left center",
- pointerEvents: "none",
- top: isSelected ? "0.25rem" : "0rem",
- bottom: isSelected ? "0.25rem" : "0rem",
- }}
- />
- </div>
- </div>
- );
- }
-
- return (
- <span className="text-foreground/80 truncate text-xs">
- {videoElement.name}
- </span>
- );
+ return renderTiledMedia({
+ element: videoElement,
+ imageUrl: mediaAsset?.thumbnailUrl,
+ track,
+ });
},
- image: ({ element, track, isSelected, mediaAssets }) => {
+ image: ({ element, track, mediaAssets }) => {
const imageElement = element as Extract<
TimelineElementType,
{ type: "image" }
@@ -675,44 +762,27 @@ const ELEMENT_CONTENT_RENDERERS: Record<
const mediaAsset = mediaAssets.find(
(asset) => asset.id === imageElement.mediaId,
);
-
- if (!mediaAsset?.url) {
- return (
- <span className="text-foreground/80 truncate text-xs">
- {imageElement.name}
- </span>
- );
- }
-
- const trackHeight = getTrackHeight({ type: track.type });
- const tileWidth = trackHeight * (16 / 9);
-
- return (
- <div className="flex size-full items-center justify-center">
- <div
- className={`relative size-full ${isSelected ? "bg-primary" : "bg-transparent"}`}
- >
- <div
- className="absolute right-0 left-0"
- style={{
- backgroundImage: `url(${mediaAsset.url})`,
- backgroundRepeat: "repeat-x",
- backgroundSize: `${tileWidth}px ${trackHeight}px`,
- backgroundPosition: "left center",
- pointerEvents: "none",
- top: isSelected ? "0.25rem" : "0rem",
- bottom: isSelected ? "0.25rem" : "0rem",
- }}
- />
- </div>
- </div>
- );
+ return renderTiledMedia({
+ element: imageElement,
+ imageUrl: mediaAsset?.url,
+ track,
+ });
},
};
-function ElementContent(props: ElementContentProps) {
- const renderer = ELEMENT_CONTENT_RENDERERS[props.element.type];
- return <>{renderer(props)}</>;
+function ElementContent({ element, track, isSelected }: ElementContentProps) {
+ const editor = useEditor();
+ const renderer = ELEMENT_CONTENT_RENDERERS[element.type];
+ return (
+ <>
+ {renderer({
+ element,
+ track,
+ isSelected,
+ mediaAssets: editor.media.getAssets(),
+ })}
+ </>
+ );
}
function CopyMenuItem() {
@@ -740,9 +810,9 @@ function MuteMenuItem({
return <HugeiconsIcon icon={VolumeMute02Icon} />;
}
return isMuted ? (
- <HugeiconsIcon icon={VolumeHighIcon} />
- ) : (
<HugeiconsIcon icon={VolumeOffIcon} />
+ ) : (
+ <HugeiconsIcon icon={VolumeHighIcon} />
);
};
@@ -823,7 +893,7 @@ function ActionMenuItem({
event.stopPropagation();
invokeAction(action);
}}
- textRight={getDisplayShortcut(action)}
+ textRight={getDisplayShortcut({ action })}
{...props}
>
{children}
diff --git a/apps/web/src/components/editor/panels/timeline/timeline-toolbar.tsx b/apps/web/src/components/editor/panels/timeline/timeline-toolbar.tsx
index 03ce88eb..533ea63d 100644
--- a/apps/web/src/components/editor/panels/timeline/timeline-toolbar.tsx
+++ b/apps/web/src/components/editor/panels/timeline/timeline-toolbar.tsx
@@ -78,7 +78,7 @@ export function TimelineToolbar({
function ToolbarLeftSection() {
const editor = useEditor();
const currentTime = editor.playback.getCurrentTime();
- const currentBookmarked = editor.scenes.isBookmarked({ time: currentTime });
+ const isCurrentlyBookmarked = editor.scenes.isBookmarked({ time: currentTime });
const handleAction = ({
action,
@@ -116,7 +116,7 @@ function ToolbarLeftSection() {
<ToolbarButton
icon={<SplitSquareHorizontal />}
- tooltip="Coming soon" /* separate audio */
+ tooltip="Separate audio (coming soon)"
disabled={true}
onClick={({ event: _event }) => {}}
/>
@@ -131,7 +131,7 @@ function ToolbarLeftSection() {
<ToolbarButton
icon={<HugeiconsIcon icon={SnowIcon} />}
- tooltip="Coming soon" /* freeze frame */
+ tooltip="Freeze frame (coming soon)"
disabled={true}
onClick={({ event: _event }) => {}}
/>
@@ -149,8 +149,8 @@ function ToolbarLeftSection() {
<Tooltip>
<ToolbarButton
icon={<HugeiconsIcon icon={Bookmark02Icon} />}
- isActive={currentBookmarked}
- tooltip={currentBookmarked ? "Remove bookmark" : "Add bookmark"}
+ isActive={isCurrentlyBookmarked}
+ tooltip={isCurrentlyBookmarked ? "Remove bookmark" : "Add bookmark"}
onClick={({ event }) =>
handleAction({ action: "toggle-bookmark", event })
}
@@ -191,12 +191,10 @@ function ToolbarRightSection({
onZoomChange: (zoom: number) => void;
onZoom: (options: { direction: "in" | "out" }) => void;
}) {
- const {
- snappingEnabled,
- rippleEditingEnabled,
- toggleSnapping,
- toggleRippleEditing,
- } = useTimelineStore();
+ const snappingEnabled = useTimelineStore((s) => s.snappingEnabled);
+ const rippleEditingEnabled = useTimelineStore((s) => s.rippleEditingEnabled);
+ const toggleSnapping = useTimelineStore((s) => s.toggleSnapping);
+ const toggleRippleEditing = useTimelineStore((s) => s.toggleRippleEditing);
return (
<div className="flex items-center gap-1">
diff --git a/apps/web/src/components/editor/panels/timeline/timeline-track.tsx b/apps/web/src/components/editor/panels/timeline/timeline-track.tsx
index fbc7cb3f..81cda7a6 100644
--- a/apps/web/src/components/editor/panels/timeline/timeline-track.tsx
+++ b/apps/web/src/components/editor/panels/timeline/timeline-track.tsx
@@ -52,7 +52,7 @@ export function TimelineTrackContent({
targetElementId = null,
}: TimelineTrackContentProps) {
const editor = useEditor();
- const { isElementSelected, clearElementSelection } = useElementSelection();
+ const { isElementSelected } = useElementSelection();
const duration = editor.timeline.getTotalDuration();
@@ -69,7 +69,6 @@ export function TimelineTrackContent({
className="size-full"
onClick={(event) => {
if (shouldIgnoreClick?.()) return;
- clearElementSelection();
onTrackClick?.(event);
}}
onMouseDown={(event) => {