From ac43a5a73fa905cdac905bc956763b6093d6738e Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Wed, 15 Apr 2026 05:43:29 +0200 Subject: feat: move/resize multiple elements --- .../components/editor/panels/timeline/index.tsx | 57 ++++++++++------------ 1 file changed, 27 insertions(+), 30 deletions(-) (limited to 'apps/web/src/components/editor/panels/timeline/index.tsx') diff --git a/apps/web/src/components/editor/panels/timeline/index.tsx b/apps/web/src/components/editor/panels/timeline/index.tsx index ae9e19c9..20e9faf1 100644 --- a/apps/web/src/components/editor/panels/timeline/index.tsx +++ b/apps/web/src/components/editor/panels/timeline/index.tsx @@ -61,7 +61,6 @@ import { SELECTED_TRACK_ROW_CLASS } from "./theme"; import { computeTrackExpansionHeight, getTrackExpandedRows, - getExpansionHeight, getPropertyLabel, type ExpandedRow, } from "./expanded-layout"; @@ -75,6 +74,7 @@ import { TimelineBookmarksRow } from "./bookmarks"; import { useBookmarkDrag } from "@/hooks/timeline/use-bookmark-drag"; import { useEdgeAutoScroll } from "@/hooks/timeline/use-edge-auto-scroll"; import { useInitialScrollBottom } from "@/hooks/timeline/use-initial-scroll-bottom"; +import { useTimelineResize } from "@/hooks/timeline/use-timeline-resize"; import { useTimelineStore } from "@/stores/timeline-store"; import { useEditor } from "@/hooks/use-editor"; import { useTimelinePlayhead } from "@/hooks/timeline/use-timeline-playhead"; @@ -119,7 +119,9 @@ export function Timeline() { } = useElementSelection(); const editor = useEditor(); const timeline = editor.timeline; - const scene = useEditor((currentEditor) => currentEditor.scenes.getActiveSceneOrNull()); + const scene = useEditor((currentEditor) => + currentEditor.scenes.getActiveSceneOrNull(), + ); const tracks = useMemo( () => scene @@ -140,7 +142,6 @@ export function Timeline() { const playheadRef = useRef(null); const trackLabelsScrollRef = useRef(null); - const [isResizing, setIsResizing] = useState(false); const [currentSnapPoint, setCurrentSnapPoint] = useState( null, ); @@ -148,15 +149,6 @@ export function Timeline() { const handleSnapPointChange = useCallback((snapPoint: SnapPoint | null) => { setCurrentSnapPoint(snapPoint); }, []); - const handleResizeStateChange = useCallback( - ({ isResizing: nextIsResizing }: { isResizing: boolean }) => { - setIsResizing(nextIsResizing); - if (!nextIsResizing) { - setCurrentSnapPoint(null); - } - }, - [], - ); const timelineDuration = timeline.getTotalDuration() || 0; const minZoomLevel = getTimelineZoomMin({ @@ -176,6 +168,10 @@ export function Timeline() { tracksScrollRef, rulerScrollRef, }); + const { isResizing, handleResizeStart } = useTimelineResize({ + zoomLevel, + onSnapPointChange: handleSnapPointChange, + }); const expandedElementIds = useTimelineStore((s) => s.expandedElementIds); @@ -366,7 +362,10 @@ export function Timeline() { const containerWidth = tracksContainerRef.current?.clientWidth || FALLBACK_CONTAINER_WIDTH; - const contentWidth = timelineTimeToPixels({ time: timelineDuration, zoomLevel }); + const contentWidth = timelineTimeToPixels({ + time: timelineDuration, + zoomLevel, + }); const paddingPx = getTimelinePaddingPx({ containerWidth, zoomLevel, @@ -513,7 +512,10 @@ export function Timeline() { TRACKS_CONTAINER_HEIGHT.min, Math.min( TRACKS_CONTAINER_HEIGHT.max, - getTotalTracksHeight({ tracks, getExtraHeight: getTrackExpansionHeight }), + getTotalTracksHeight({ + tracks, + getExtraHeight: getTrackExpansionHeight, + }), ), ) + TIMELINE_CONTENT_TOP_PADDING_PX }px`, @@ -533,14 +535,13 @@ export function Timeline() { }} > {tracks.length > 0 && ( - { @@ -718,8 +719,7 @@ function TimelineTrackRows({ dragState, tracksScrollRef, lastMouseXRef, - onSnapPointChange, - onResizeStateChange, + onResizeStart, onElementMouseDown, onElementClick, onTrackMouseDown, @@ -733,8 +733,9 @@ function TimelineTrackRows({ dragState: ElementDragState; tracksScrollRef: React.RefObject; lastMouseXRef: React.RefObject; - onSnapPointChange: (snapPoint: SnapPoint | null) => void; - onResizeStateChange: (params: { isResizing: boolean }) => void; + onResizeStart: React.ComponentProps< + typeof TimelineTrackContent + >["onResizeStart"]; onElementMouseDown: React.ComponentProps< typeof TimelineTrackContent >["onElementMouseDown"]; @@ -798,8 +799,7 @@ function TimelineTrackRows({
- {rows.map((row, index) => ( + {rows.map((row) => (
-- cgit v1.3.1