mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
fix: timeline element resizing
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
} from "@/hooks/timeline/element/use-keyframe-drag";
|
} from "@/hooks/timeline/element/use-keyframe-drag";
|
||||||
import { useKeyframeSelection } from "@/hooks/timeline/element/use-keyframe-selection";
|
import { useKeyframeSelection } from "@/hooks/timeline/element/use-keyframe-selection";
|
||||||
import { useKeyframeBoxSelect } from "@/hooks/timeline/element/use-keyframe-box-select";
|
import { useKeyframeBoxSelect } from "@/hooks/timeline/element/use-keyframe-box-select";
|
||||||
|
import { useTimelineElementResize } from "@/hooks/timeline/element/use-element-resize";
|
||||||
import { SelectionBox } from "@/lib/selection/selection-box";
|
import { SelectionBox } from "@/lib/selection/selection-box";
|
||||||
import { getElementKeyframes } from "@/lib/animation";
|
import { getElementKeyframes } from "@/lib/animation";
|
||||||
import {
|
import {
|
||||||
@@ -85,6 +86,7 @@ import {
|
|||||||
getExpansionHeight,
|
getExpansionHeight,
|
||||||
type ExpandedRow,
|
type ExpandedRow,
|
||||||
} from "./expanded-layout";
|
} from "./expanded-layout";
|
||||||
|
import type { SnapPoint } from "@/lib/timeline/snap-utils";
|
||||||
|
|
||||||
const KEYFRAME_INDICATOR_MIN_WIDTH_PX = 40;
|
const KEYFRAME_INDICATOR_MIN_WIDTH_PX = 40;
|
||||||
const ELEMENT_RING_WIDTH_PX = 1.5;
|
const ELEMENT_RING_WIDTH_PX = 1.5;
|
||||||
@@ -195,12 +197,8 @@ interface TimelineElementProps {
|
|||||||
track: TimelineTrack;
|
track: TimelineTrack;
|
||||||
zoomLevel: number;
|
zoomLevel: number;
|
||||||
isSelected: boolean;
|
isSelected: boolean;
|
||||||
onResizeStart: (params: {
|
onSnapPointChange?: (snapPoint: SnapPoint | null) => void;
|
||||||
event: React.MouseEvent;
|
onResizeStateChange?: (params: { isResizing: boolean }) => void;
|
||||||
element: TimelineElementType;
|
|
||||||
track: TimelineTrack;
|
|
||||||
side: "left" | "right";
|
|
||||||
}) => void;
|
|
||||||
onElementMouseDown: (
|
onElementMouseDown: (
|
||||||
event: React.MouseEvent,
|
event: React.MouseEvent,
|
||||||
element: TimelineElementType,
|
element: TimelineElementType,
|
||||||
@@ -218,7 +216,8 @@ export function TimelineElement({
|
|||||||
track,
|
track,
|
||||||
zoomLevel,
|
zoomLevel,
|
||||||
isSelected,
|
isSelected,
|
||||||
onResizeStart,
|
onSnapPointChange,
|
||||||
|
onResizeStateChange,
|
||||||
onElementMouseDown,
|
onElementMouseDown,
|
||||||
onElementClick,
|
onElementClick,
|
||||||
dragState,
|
dragState,
|
||||||
@@ -232,6 +231,18 @@ export function TimelineElement({
|
|||||||
elementId: element.id,
|
elementId: element.id,
|
||||||
fallback: element,
|
fallback: element,
|
||||||
});
|
});
|
||||||
|
const {
|
||||||
|
currentDuration,
|
||||||
|
currentStartTime,
|
||||||
|
handleResizeStart,
|
||||||
|
isResizing,
|
||||||
|
} = useTimelineElementResize({
|
||||||
|
element,
|
||||||
|
track,
|
||||||
|
zoomLevel,
|
||||||
|
onSnapPointChange,
|
||||||
|
onResizeStateChange,
|
||||||
|
});
|
||||||
|
|
||||||
let mediaAsset: MediaAsset | null = null;
|
let mediaAsset: MediaAsset | null = null;
|
||||||
|
|
||||||
@@ -256,9 +267,13 @@ export function TimelineElement({
|
|||||||
const elementStartTime =
|
const elementStartTime =
|
||||||
isBeingDragged && dragState.isDragging
|
isBeingDragged && dragState.isDragging
|
||||||
? dragState.currentTime + dragTimeOffset
|
? dragState.currentTime + dragTimeOffset
|
||||||
: renderElement.startTime;
|
: isResizing
|
||||||
|
? currentStartTime
|
||||||
|
: renderElement.startTime;
|
||||||
const displayedStartTime = elementStartTime;
|
const displayedStartTime = elementStartTime;
|
||||||
const displayedDuration = renderElement.duration;
|
const displayedDuration = isResizing
|
||||||
|
? currentDuration
|
||||||
|
: renderElement.duration;
|
||||||
const elementWidth = timelineTimeToPixels({
|
const elementWidth = timelineTimeToPixels({
|
||||||
time: displayedDuration,
|
time: displayedDuration,
|
||||||
zoomLevel,
|
zoomLevel,
|
||||||
@@ -267,6 +282,22 @@ export function TimelineElement({
|
|||||||
time: displayedStartTime,
|
time: displayedStartTime,
|
||||||
zoomLevel,
|
zoomLevel,
|
||||||
});
|
});
|
||||||
|
const handleElementResizeStart = ({
|
||||||
|
event,
|
||||||
|
element,
|
||||||
|
side,
|
||||||
|
}: {
|
||||||
|
event: React.MouseEvent;
|
||||||
|
element: TimelineElementType;
|
||||||
|
track: TimelineTrack;
|
||||||
|
side: "left" | "right";
|
||||||
|
}) => {
|
||||||
|
handleResizeStart({
|
||||||
|
event,
|
||||||
|
elementId: element.id,
|
||||||
|
side,
|
||||||
|
});
|
||||||
|
};
|
||||||
const keyframeIndicators = isSelected
|
const keyframeIndicators = isSelected
|
||||||
? getKeyframeIndicators({
|
? getKeyframeIndicators({
|
||||||
keyframes: getElementKeyframes({ animations: element.animations }),
|
keyframes: getElementKeyframes({ animations: element.animations }),
|
||||||
@@ -391,7 +422,7 @@ export function TimelineElement({
|
|||||||
expandedContent={expandedContent}
|
expandedContent={expandedContent}
|
||||||
onElementClick={onElementClick}
|
onElementClick={onElementClick}
|
||||||
onElementMouseDown={onElementMouseDown}
|
onElementMouseDown={onElementMouseDown}
|
||||||
onResizeStart={onResizeStart}
|
onResizeStart={handleElementResizeStart}
|
||||||
isDropTarget={isDropTarget}
|
isDropTarget={isDropTarget}
|
||||||
/>
|
/>
|
||||||
{isSelected && (
|
{isSelected && (
|
||||||
|
|||||||
Reference in New Issue
Block a user