🎥 Make videos programmatically with React
fix(studio): select timeline layers from resize edges
YUHAO-cornc57642b15bd7
diff --git a/packages/example/e2e/timeline-right-edge.test.mts b/packages/example/e2e/timeline-right-edge.test.mtsindex f67e62e09e..263da6d76e 100644--- a/packages/example/e2e/timeline-right-edge.test.mts+++ b/packages/example/e2e/timeline-right-edge.test.mts@@ -55,7 +55,7 @@ const Layers = () => <>export const E2eTestRoot = () => <Composition id="timeline-edges" component={Layers} durationInFrames={180} fps={30} width={640} height={360} />;`,);- await page.setViewportSize({width: 1440, height: 1600});+ await page.setViewportSize({width: 1440, height: 2000});await page.goto(`${STUDIO_URL}/timeline-edges`);for (const [name, radius] of [['Fill available time', '2px'],@@ -109,6 +109,130 @@ export const E2eTestRoot = () => <Composition id="timeline-edges" component={Layawait expect(layer).toHaveCSS('border-top-left-radius', radius);await expect(layer).toHaveCSS('border-bottom-left-radius', radius);}++ const rightEdgeLayer = page.locator(+ '[data-timeline-marquee-item][title="Explicit fill cutoff"]',+ );+ await expect(rightEdgeLayer).toHaveCSS('opacity', '0.75');+ await rightEdgeLayer.locator('[title="Drag to change duration"]').click();+ await expect(rightEdgeLayer).toHaveCSS('opacity', '1');++ const leftEdgeLayer = page.locator(+ '[data-timeline-marquee-item][title="Solid cutoff"]',+ );+ await expect(leftEdgeLayer).toHaveCSS('opacity', '0.75');+ await leftEdgeLayer.locator('[title="Drag to trim start"]').click();+ await expect(leftEdgeLayer).toHaveCSS('opacity', '1');+ await expect(rightEdgeLayer).toHaveCSS('opacity', '0.75');++ const dragWithMeta = async ({+ handle,+ deltaX,+ }: {+ readonly handle: ReturnType<typeof page.locator>;+ readonly deltaX: number;+ }) => {+ const box = await handle.boundingBox();+ if (box === null) {+ throw new Error(+ 'Expected timeline resize handle to have a bounding box',+ );+ }++ await page.keyboard.down('Meta');+ await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);+ await page.mouse.down();+ await page.mouse.move(+ box.x + box.width / 2 + deltaX,+ box.y + box.height / 2,+ {+ steps: 5,+ },+ );+ await page.mouse.up();+ await page.keyboard.up('Meta');+ };++ const getSequenceNumberProp = (+ source: string,+ name: string,+ prop: 'durationInFrames' | 'from',+ ) => {+ const match = source.match(+ new RegExp(+ `<[A-Za-z]+\\b(?=[^>]*name="${name}")(?=[^>]*${prop}=\\{(\\d+)\\})[^>]*>`,+ ),+ );+ return match ? Number(match[1]) : null;+ };++ const rightResizeA = page.locator(+ '[data-timeline-marquee-item][title="Explicit fill cutoff"]',+ );+ const rightResizeB = page.locator(+ '[data-timeline-marquee-item][title="Duration cutoff"]',+ );+ await rightResizeA.scrollIntoViewIfNeeded();+ await rightResizeA.click();+ await dragWithMeta({+ handle: rightResizeB.locator('[title="Drag to change duration"]'),+ deltaX: -40,+ });+ await expect+ .poll(() => {+ const source = fs.readFileSync(rootFile, 'utf-8');+ return [+ getSequenceNumberProp(+ source,+ 'Explicit fill cutoff',+ 'durationInFrames',+ ),+ getSequenceNumberProp(source, 'Duration cutoff', 'durationInFrames'),+ ];+ })+ .toEqual([24, 9]);++ const leftResizeA = page.locator(+ '[data-timeline-marquee-item][title="Explicit composition match"]',+ );+ const leftResizeB = page.locator(+ '[data-timeline-marquee-item][title="Fill clipped before own cutoff"]',+ );+ await leftResizeA.scrollIntoViewIfNeeded();+ await leftResizeA.click();+ await dragWithMeta({+ handle: leftResizeB.locator('[title="Drag to trim start"]'),+ deltaX: 40,+ });+ await expect+ .poll(() => {+ const source = fs.readFileSync(rootFile, 'utf-8');+ const fromA = getSequenceNumberProp(+ source,+ 'Explicit composition match',+ 'from',+ );+ const fromB = getSequenceNumberProp(+ source,+ 'Fill clipped before own cutoff',+ 'from',+ );+ return [+ fromA,+ fromB,+ getSequenceNumberProp(+ source,+ 'Explicit composition match',+ 'durationInFrames',+ ),+ getSequenceNumberProp(+ source,+ 'Fill clipped before own cutoff',+ 'durationInFrames',+ ),+ ];+ })+ .toEqual([6, 6, 174, 174]);} finally {await stopStudio();}diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsxindex 3ffb9f93a2..47adb6c099 100644--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx@@ -969,6 +969,8 @@ const TimelineSequenceInner: React.FC<{windowWidth={windowWidth}timelineDurationInFrames={video.durationInFrames ?? 1}onDragEnd={dragAwareDoubleClick.endPointerGesture}+ onSelect={onSelect}+ selected={selected}/>) : null}{showRightEdgeDragHandle &&@@ -980,6 +982,8 @@ const TimelineSequenceInner: React.FC<{windowWidth={windowWidth}timelineDurationInFrames={video.durationInFrames ?? 1}onDragEnd={dragAwareDoubleClick.endPointerGesture}+ onSelect={onSelect}+ selected={selected}/>) : null}</>diff --git a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsxindex 4a0db2ba82..b9e5055cad 100644--- a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx@@ -10,6 +10,7 @@ import React, {useRef,useState,} from 'react';+import {flushSync} from 'react-dom';import type {CanUpdateSequencePropStatus,CanUpdateSequencePropStatusKeyframed,@@ -42,7 +43,9 @@ import {} from './save-sequence-prop';import {getTimelineSequenceSelectionKey,+ shouldSelectTimelineRowOnPointerDown,useCurrentTimelineSelectionStateAsRef,+ type TimelineSelectionInteraction,type TimelineSelection,} from './TimelineSelection';@@ -50,6 +53,34 @@ const HANDLE_INSET = 6;const HANDLE_OUTSET = 8;export const timelineSequenceFromDragSnapThresholdPx = 10;+const getTimelineSequenceEdgeSelectionInteraction = ({+ button,+ selected,+ shiftKey,+ metaKey,+ ctrlKey,+}: {+ readonly button: number;+ readonly selected: boolean;+ readonly shiftKey: boolean;+ readonly metaKey: boolean;+ readonly ctrlKey: boolean;+}): TimelineSelectionInteraction | null => {+ if (+ button !== 0 ||+ !shouldSelectTimelineRowOnPointerDown({+ selected,+ shiftKey,+ metaKey,+ ctrlKey,+ })+ ) {+ return null;+ }++ return {shiftKey, toggleKey: metaKey || ctrlKey};+};+const baseStyle: React.CSSProperties = {position: 'absolute',top: 0,@@ -1099,7 +1130,16 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{readonly windowWidth: number;readonly timelineDurationInFrames: number;readonly onDragEnd: (wasDragged: boolean) => void;-}> = ({nodePathInfo, windowWidth, timelineDurationInFrames, onDragEnd}) => {+ readonly onSelect: (interaction?: TimelineSelectionInteraction) => void;+ readonly selected: boolean;+}> = ({+ nodePathInfo,+ windowWidth,+ timelineDurationInFrames,+ onDragEnd,+ onSelect,+ selected,+}) => {const {setPropStatuses, setDragOverrides, clearDragOverrides} = useContext(Internals.VisualModeSettersContext,);@@ -1218,6 +1258,17 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{return;}+ const selectionInteraction = getTimelineSequenceEdgeSelectionInteraction({+ button: e.button,+ selected,+ shiftKey: e.shiftKey,+ metaKey: e.metaKey,+ ctrlKey: e.ctrlKey,+ });+ if (selectionInteraction) {+ flushSync(() => onSelect(selectionInteraction));+ }+const pxPerFrame =timelineDurationInFrames > 0? (windowWidth - TIMELINE_PADDING * 2) / timelineDurationInFrames@@ -1262,7 +1313,9 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{},[currentSelection,+ onSelect,propStatusesRef,+ selected,sequencesRef,timelineDurationInFrames,windowWidth,@@ -1675,7 +1728,16 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{readonly windowWidth: number;readonly timelineDurationInFrames: number;readonly onDragEnd: (wasDragged: boolean) => void;-}> = ({nodePathInfo, windowWidth, timelineDurationInFrames, onDragEnd}) => {+ readonly onSelect: (interaction?: TimelineSelectionInteraction) => void;+ readonly selected: boolean;+}> = ({+ nodePathInfo,+ windowWidth,+ timelineDurationInFrames,+ onDragEnd,+ onSelect,+ selected,+}) => {const {setPropStatuses, setDragOverrides, clearDragOverrides} = useContext(Internals.VisualModeSettersContext,);@@ -1793,6 +1855,17 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{return;}+ const selectionInteraction = getTimelineSequenceEdgeSelectionInteraction({+ button: e.button,+ selected,+ shiftKey: e.shiftKey,+ metaKey: e.metaKey,+ ctrlKey: e.ctrlKey,+ });+ if (selectionInteraction) {+ flushSync(() => onSelect(selectionInteraction));+ }+const pxPerFrame =timelineDurationInFrames > 0? (windowWidth - TIMELINE_PADDING * 2) / timelineDurationInFrames@@ -1837,7 +1910,9 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{},[currentSelection,+ onSelect,propStatusesRef,+ selected,sequencesRef,timelineDurationInFrames,windowWidth,