🎥 Make videos programmatically with React
`@remotion/studio`: Allow selecting timeline items (behind flag) (#7741)
Jonny Burgerad19b115c5af
diff --git a/packages/studio/src/components/CompositionSelectorItem.tsx b/packages/studio/src/components/CompositionSelectorItem.tsxindex 9515b9a325..7d1085957c 100644--- a/packages/studio/src/components/CompositionSelectorItem.tsx+++ b/packages/studio/src/components/CompositionSelectorItem.tsx@@ -241,7 +241,7 @@ export const CompositionSelectorItem: React.FC<{}return (- <ContextMenu values={contextMenu}>+ <ContextMenu values={contextMenu} onOpen={null}><Row align="center"><aref={compositionRowRef}diff --git a/packages/studio/src/components/ContextMenu.tsx b/packages/studio/src/components/ContextMenu.tsxindex 3bc38402dc..8fa035fcc9 100644--- a/packages/studio/src/components/ContextMenu.tsx+++ b/packages/studio/src/components/ContextMenu.tsx@@ -28,7 +28,8 @@ type OpenState =export const ContextMenu: React.FC<{readonly children: React.ReactNode;readonly values: ComboboxValue[];-}> = ({children, values}) => {+ readonly onOpen: (() => void) | null;+}> = ({children, values, onOpen}) => {const ref = useRef<HTMLDivElement>(null);const [opened, setOpened] = useState<OpenState>({type: 'not-open'});const {currentZIndex} = useZIndex();@@ -52,6 +53,7 @@ export const ContextMenu: React.FC<{const onClick = (e: MouseEvent) => {e.preventDefault();e.stopPropagation();+ onOpen?.();setOpened({type: 'open', left: e.clientX, top: e.clientY});return false;@@ -62,7 +64,7 @@ export const ContextMenu: React.FC<{return () => {current.removeEventListener('contextmenu', onClick);};- }, [size]);+ }, [onOpen, size]);const spaceToBottom = useMemo(() => {if (size && opened.type === 'open') {diff --git a/packages/studio/src/components/EditorGuides/Guide.tsx b/packages/studio/src/components/EditorGuides/Guide.tsxindex 6d49bc0b40..13fd8fc9df 100644--- a/packages/studio/src/components/EditorGuides/Guide.tsx+++ b/packages/studio/src/components/EditorGuides/Guide.tsx@@ -114,7 +114,7 @@ const GuideComp: React.FC<{}, [guide.id, setGuidesList]);return (- <ContextMenu values={values}>+ <ContextMenu values={values} onOpen={null}><divstyle={guideStyle}onMouseDown={onMouseDown}diff --git a/packages/studio/src/components/ExpandedTracksProvider.tsx b/packages/studio/src/components/ExpandedTracksProvider.tsxindex 2374b20bb4..874135cc05 100644--- a/packages/studio/src/components/ExpandedTracksProvider.tsx+++ b/packages/studio/src/components/ExpandedTracksProvider.tsx@@ -1,4 +1,3 @@-import {stringifySequenceExpandedRowKey} from '@remotion/studio-shared';import React, {createContext, useCallback, useMemo, useState} from 'react';import type {SequencePropsSubscriptionKey} from 'remotion';import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';@@ -8,13 +7,7 @@ import {persistBooleanMap,toggleBooleanMapKey,} from '../helpers/persist-boolean-map';--const nodePathInfoToExpandedKey = (info: SequenceNodePathInfo): string =>- [- stringifySequenceExpandedRowKey(info.sequenceSubscriptionKey),- info.auxiliaryKeys.join('.'),- info.index,- ].join('.');+import {timelineNodePathInfoToKey} from '../helpers/timeline-node-path-key';const SESSION_STORAGE_KEY = 'remotion.editor.expandedTracks';@@ -61,7 +54,7 @@ export const ExpandedTracksProvider: React.FC<{const toggleTrack = useCallback((nodePathInfo: SequenceNodePathInfo) => {setExpandedTracks((prev) => {- const key = nodePathInfoToExpandedKey(nodePathInfo);+ const key = timelineNodePathInfoToKey(nodePathInfo);const next = toggleBooleanMapKey(prev, key);persistBooleanMap(SESSION_STORAGE_KEY, next);return next;@@ -93,7 +86,7 @@ export const ExpandedTracksProvider: React.FC<{const getterValue = useMemo((): ExpandedTracksGetterContextValue => ({getIsExpanded: (nodePathInfo) =>- expandedTracks[nodePathInfoToExpandedKey(nodePathInfo)] ?? false,+ expandedTracks[timelineNodePathInfoToKey(nodePathInfo)] ?? false,}),[expandedTracks],);diff --git a/packages/studio/src/components/Timeline/Timeline.tsx b/packages/studio/src/components/Timeline/Timeline.tsxindex 6cb633f638..f3d4ea38b7 100644--- a/packages/studio/src/components/Timeline/Timeline.tsx+++ b/packages/studio/src/components/Timeline/Timeline.tsx@@ -21,6 +21,7 @@ import {TimelineList} from './TimelineList';import {TimelinePinchZoom} from './TimelinePinchZoom';import {TimelinePlayCursorSyncer} from './TimelinePlayCursorSyncer';import {TimelineScrollable} from './TimelineScrollable';+import {TimelineSelectionProvider} from './TimelineSelection';import {TimelineSlider} from './TimelineSlider';import {TimelineTimeIndicators,@@ -87,56 +88,58 @@ const TimelineInner: React.FC = () => {style={container}className={'css-reset ' + VERTICAL_SCROLLBAR_CLASSNAME}>- {sequences.map((sequence) => {- if (!sequence.controls || !previewConnected || !sequence.getStack()) {- return null;- }+ <TimelineSelectionProvider>+ {sequences.map((sequence) => {+ if (!sequence.controls || !previewConnected || !sequence.getStack()) {+ return null;+ }- return (- <SubscribeToNodePaths- key={sequence.id}- overrideId={sequence.controls.overrideId}- schema={sequence.controls.schema}- getStack={sequence.getStack}- effects={sequence.effects}- />- );- })}- <SequencePropsObserver />- <TimelineHeightContainer shown={shown} hasBeenCut={hasBeenCut}>- {isStill ? (- <TimelineList timeline={shown} />- ) : (- <TimelineWidthProvider>- <TimelinePinchZoom />- <SplitterContainer- orientation="vertical"- defaultFlex={0.2}- id="names-to-timeline"- maxFlex={0.5}- minFlex={0.15}- >- <SplitterElement- type="flexer"- sticky={<TimelineTimePlaceholders />}+ return (+ <SubscribeToNodePaths+ key={sequence.id}+ overrideId={sequence.controls.overrideId}+ schema={sequence.controls.schema}+ getStack={sequence.getStack}+ effects={sequence.effects}+ />+ );+ })}+ <SequencePropsObserver />+ <TimelineHeightContainer shown={shown} hasBeenCut={hasBeenCut}>+ {isStill ? (+ <TimelineList timeline={shown} />+ ) : (+ <TimelineWidthProvider>+ <TimelinePinchZoom />+ <SplitterContainer+ orientation="vertical"+ defaultFlex={0.2}+ id="names-to-timeline"+ maxFlex={0.5}+ minFlex={0.15}>- <TimelineList timeline={shown} />- </SplitterElement>- <SplitterHandle onCollapse={noop} allowToCollapse="none" />- <SplitterElement type="anti-flexer" sticky={null}>- <TimelineScrollable>- <TimelineTracks timeline={shown} hasBeenCut={hasBeenCut} />- <TimelineInOutPointer />- <TimelinePlayCursorSyncer />- <TimelineDragHandler />- <TimelineTimeIndicators />- <TimelineSlider />- </TimelineScrollable>- </SplitterElement>- </SplitterContainer>- </TimelineWidthProvider>- )}- </TimelineHeightContainer>+ <SplitterElement+ type="flexer"+ sticky={<TimelineTimePlaceholders />}+ >+ <TimelineList timeline={shown} />+ </SplitterElement>+ <SplitterHandle onCollapse={noop} allowToCollapse="none" />+ <SplitterElement type="anti-flexer" sticky={null}>+ <TimelineScrollable>+ <TimelineTracks timeline={shown} hasBeenCut={hasBeenCut} />+ <TimelineInOutPointer />+ <TimelinePlayCursorSyncer />+ <TimelineDragHandler />+ <TimelineTimeIndicators />+ <TimelineSlider />+ </TimelineScrollable>+ </SplitterElement>+ </SplitterContainer>+ </TimelineWidthProvider>+ )}+ </TimelineHeightContainer>+ </TimelineSelectionProvider></div>);};diff --git a/packages/studio/src/components/Timeline/TimelineDragHandler.tsx b/packages/studio/src/components/Timeline/TimelineDragHandler.tsxindex 2f04a02b52..40443d57c7 100644--- a/packages/studio/src/components/Timeline/TimelineDragHandler.tsx+++ b/packages/studio/src/components/Timeline/TimelineDragHandler.tsx@@ -600,7 +600,7 @@ const TimelineDragHandlerInner: React.FC = () => {<div style={style} onPointerDown={onPointerDown}><div style={inner} className={VERTICAL_SCROLLBAR_CLASSNAME} />{inFrame !== null && (- <ContextMenu values={inContextMenu}>+ <ContextMenu values={inContextMenu} onOpen={null}><TimelineInOutPointerHandletype="in"atFrame={inFrame}@@ -609,7 +609,7 @@ const TimelineDragHandlerInner: React.FC = () => {</ContextMenu>)}{outFrame !== null && (- <ContextMenu values={outContextMenu}>+ <ContextMenu values={outContextMenu} onOpen={null}><TimelineInOutPointerHandletype="out"dragging={inOutDragging.dragging === 'out'}diff --git a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsxindex 95bd9ec422..a0a61ffc1c 100644--- a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx+++ b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx@@ -4,6 +4,7 @@ import type {SequencePropsSubscriptionKey} from 'remotion';import {Internals} from 'remotion';import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-source-map';import {StudioServerConnectionCtx} from '../../helpers/client-id';+import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';import type {EffectSchemaFieldInfo} from '../../helpers/timeline-layout';import {EXPANDED_SECTION_PADDING_RIGHT} from '../../helpers/timeline-layout';import {callApi} from '../call-api';@@ -14,8 +15,20 @@ import {TimelineExpandArrowSpacer} from './TimelineExpandArrowButton';import {TimelineLayerEyeSpacer} from './TimelineLayerEye';import {TimelineRowChrome} from './TimelineRowChrome';import {TimelineFieldValue, UnsupportedStatus} from './TimelineSchemaField';--const fieldRowBase: React.CSSProperties = {+import {+ getTimelineSelectedLabelStyle,+ TIMELINE_SELECTED_LABEL_TEXT,+ useTimelineRowSelection,+} from './TimelineSelection';++const fieldRowBase: React.CSSProperties = {};++const valueColumnStyle: React.CSSProperties = {+ alignItems: 'center',+ alignSelf: 'stretch',+ display: 'flex',+ flex: 1,+ minWidth: 0,paddingRight: EXPANDED_SECTION_PADDING_RIGHT,};@@ -215,7 +228,9 @@ export const TimelineEffectFieldRow: React.FC<{readonly validatedLocation: CodePosition;readonly rowDepth: number;readonly nodePath: SequencePropsSubscriptionKey;-}> = ({field, validatedLocation, rowDepth, nodePath}) => {+ readonly nodePathInfo: SequenceNodePathInfo;+}> = ({field, validatedLocation, rowDepth, nodePath, nodePathInfo}) => {+ const selection = useTimelineRowSelection(nodePathInfo);const style = useMemo(() => {return {...fieldRowBase,@@ -224,8 +239,22 @@ export const TimelineEffectFieldRow: React.FC<{}, [field.rowHeight]);const labelRowStyle = useMemo(- () => getTimelineFieldLabelRowStyle(rowDepth),- [rowDepth],+ (): React.CSSProperties => ({+ ...getTimelineFieldLabelRowStyle(rowDepth),+ ...getTimelineSelectedLabelStyle(selection.selected),+ alignSelf: 'stretch',+ }),+ [rowDepth, selection.selected],+ );++ const fieldNameStyle = useMemo(+ (): React.CSSProperties => ({+ ...fieldName,+ color: selection.selected+ ? TIMELINE_SELECTED_LABEL_TEXT+ : fieldName.color,+ }),+ [selection.selected],);return (@@ -234,15 +263,21 @@ export const TimelineEffectFieldRow: React.FC<{eye={<TimelineLayerEyeSpacer />}arrow={<TimelineExpandArrowSpacer />}style={style}+ selected={selection.selected}+ selectable={selection.selectable}+ onSelect={selection.onSelect}+ showSelectedBackground><div style={labelRowStyle}>- <span style={fieldName}>{field.description ?? field.key}</span>+ <span style={fieldNameStyle}>{field.description ?? field.key}</span>+ </div>+ <div style={valueColumnStyle}>+ <Value+ field={field}+ nodePath={nodePath}+ validatedLocation={validatedLocation}+ /></div>- <Value- field={field}- nodePath={nodePath}- validatedLocation={validatedLocation}- /></TimelineRowChrome>);};diff --git a/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsx b/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsxindex 985c325e1c..5f44d8ab5c 100644--- a/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsx+++ b/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsx@@ -17,6 +17,11 @@ import {saveEffectProp} from './save-effect-prop';import {TimelineExpandArrowButton} from './TimelineExpandArrowButton';import {TimelineLayerEye, TimelineLayerEyeSpacer} from './TimelineLayerEye';import {TimelineRowChrome} from './TimelineRowChrome';+import {+ getTimelineSelectedLabelStyle,+ TIMELINE_SELECTED_LABEL_TEXT,+ useTimelineRowSelection,+} from './TimelineSelection';const rowLabel: React.CSSProperties = {fontSize: 12,@@ -52,6 +57,7 @@ export const TimelineEffectGroupRow: React.FC<{const previewConnected = previewServerState.type === 'connected';const {codeValues} = useContext(Internals.VisualModeCodeValuesContext);const {setCodeValues} = useContext(Internals.VisualModeSettersContext);+ const selection = useTimelineRowSelection(nodePathInfo);const effectStatus = useMemo(() =>@@ -173,7 +179,6 @@ export const TimelineEffectGroupRow: React.FC<{const rowStyle = useMemo((): React.CSSProperties => ({height: TREE_GROUP_ROW_HEIGHT,- paddingRight: EXPANDED_SECTION_PADDING_RIGHT,}),[],);@@ -182,11 +187,19 @@ export const TimelineEffectGroupRow: React.FC<{const hoverEffect = labelHovered && documentationLink !== null;return {...rowLabel,+ ...getTimelineSelectedLabelStyle(selection.selected),+ alignSelf: 'stretch',+ alignItems: 'center',+ color: selection.selected ? TIMELINE_SELECTED_LABEL_TEXT : rowLabel.color,+ display: 'flex',+ flex: 1,+ minWidth: 0,+ paddingRight: EXPANDED_SECTION_PADDING_RIGHT,textDecoration: hoverEffect ? 'underline' : 'none',textUnderlineOffset: 2,cursor: hoverEffect ? 'pointer' : undefined,};- }, [documentationLink, labelHovered]);+ }, [documentationLink, labelHovered, selection.selected]);const onClickLabel = useCallback(() => {if (documentationLink === null) {@@ -219,6 +232,10 @@ export const TimelineEffectGroupRow: React.FC<{/>}style={rowStyle}+ selected={selection.selected}+ selectable={selection.selectable}+ onSelect={selection.onSelect}+ showSelectedBackground><spanonPointerEnter={() => setLabelHovered(true)}@@ -235,7 +252,12 @@ export const TimelineEffectGroupRow: React.FC<{);return previewConnected ? (- <ContextMenu values={contextMenuValues}>{row}</ContextMenu>+ <ContextMenu+ values={contextMenuValues}+ onOpen={selection.selectable ? selection.onSelect : null}+ >+ {row}+ </ContextMenu>) : (row);diff --git a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsxindex 48093f2049..0ba1bb2f9f 100644--- a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx+++ b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx@@ -19,6 +19,11 @@ import {import {TimelineFieldRow} from './TimelineFieldRow';import {TimelineLayerEyeSpacer} from './TimelineLayerEye';import {TimelineRowChrome} from './TimelineRowChrome';+import {+ getTimelineSelectedLabelStyle,+ TIMELINE_SELECTED_LABEL_TEXT,+ useTimelineRowSelection,+} from './TimelineSelection';const rowLabel: React.CSSProperties = {fontSize: 12,@@ -46,6 +51,21 @@ export const TimelineExpandedRow: React.FC<{schema,}) => {const rowDepth = getExpandedRowDepth({nestedDepth, treeDepth: depth});+ const selection = useTimelineRowSelection(node.nodePathInfo);+ const labelStyle = React.useMemo(+ (): React.CSSProperties => ({+ ...rowLabel,+ ...getTimelineSelectedLabelStyle(selection.selected),+ alignSelf: 'stretch',+ alignItems: 'center',+ color: selection.selected ? TIMELINE_SELECTED_LABEL_TEXT : rowLabel.color,+ display: 'flex',+ flex: 1,+ minWidth: 0,+ paddingRight: EXPANDED_SECTION_PADDING_RIGHT,+ }),+ [selection.selected],+ );if (node.kind === 'group') {if (node.effectInfo) {@@ -80,10 +100,13 @@ export const TimelineExpandedRow: React.FC<{}style={{height: TREE_GROUP_ROW_HEIGHT,- paddingRight: EXPANDED_SECTION_PADDING_RIGHT,}}+ selected={selection.selected}+ selectable={selection.selectable}+ onSelect={selection.onSelect}+ showSelectedBackground>- <span style={rowLabel}>{node.label}</span>+ <span style={labelStyle}>{node.label}</span></TimelineRowChrome>);}@@ -96,6 +119,7 @@ export const TimelineExpandedRow: React.FC<{validatedLocation={validatedLocation}rowDepth={rowDepth}nodePath={nodePath}+ nodePathInfo={node.nodePathInfo}/>);}@@ -107,6 +131,7 @@ export const TimelineExpandedRow: React.FC<{validatedLocation={validatedLocation}rowDepth={rowDepth}nodePath={nodePath}+ nodePathInfo={node.nodePathInfo}schema={schema}/>);@@ -124,10 +149,13 @@ export const TimelineExpandedRow: React.FC<{arrow={<TimelineExpandArrowSpacer />}style={{height: getTreeRowHeight(node),- paddingRight: EXPANDED_SECTION_PADDING_RIGHT,}}+ selected={selection.selected}+ selectable={selection.selectable}+ onSelect={selection.onSelect}+ showSelectedBackground>- <span style={rowLabel}>{node.label}</span>+ <span style={labelStyle}>{node.label}</span></TimelineRowChrome>);};diff --git a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsxindex e2bc6260f2..a1dcd1f4d2 100644--- a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx+++ b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx@@ -24,8 +24,8 @@ const expandedSectionBase: React.CSSProperties = {};const separator: React.CSSProperties = {- height: 1,- backgroundColor: TIMELINE_TRACK_SEPARATOR,+ height: 0,+ borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`,};export const TimelineExpandedSection: React.FC<{diff --git a/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx b/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsxindex 7927105379..dc56781bec 100644--- a/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx+++ b/packages/studio/src/components/Timeline/TimelineExpandedTrackKeyframes.tsx@@ -1,6 +1,6 @@import React, {useContext, useMemo} from 'react';-import {Internals, type TSequence, useVideoConfig} from 'remotion';-import {LIGHT_TEXT, TIMELINE_TRACK_SEPARATOR} from '../../helpers/colors';+import {Internals, useVideoConfig, type TSequence} from 'remotion';+import {LIGHT_TEXT} from '../../helpers/colors';import {getXPositionOfItemInTimelineImperatively} from '../../helpers/get-left-of-timeline-slider';import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';import {@@ -13,19 +13,20 @@ import {} from '../../helpers/timeline-layout';import {ExpandedTracksGetterContext} from '../ExpandedTracksProvider';import {getTimelineKeyframes} from './get-timeline-keyframes';+import {+ getTimelineSelectedTrackHighlightStyle,+ TIMELINE_SELECTED_LABEL_BACKGROUND,+ useTimelineSelection,+ type TimelineSelection,+} from './TimelineSelection';import {TimelineWidthContext} from './TimelineWidthProvider';const row: React.CSSProperties = {position: 'relative',};-const separator: React.CSSProperties = {- height: 1,- backgroundColor: TIMELINE_TRACK_SEPARATOR,-};--const section: React.CSSProperties = {- borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`,+const rowSeparator: React.CSSProperties = {+ height: TIMELINE_ITEM_BORDER_BOTTOM,};const diamondBase: React.CSSProperties = {@@ -85,6 +86,7 @@ const TimelineExpandedTrackKeyframesInner: React.FC<{const timelineWidth = useContext(TimelineWidthContext);const {getIsExpanded} = useContext(ExpandedTracksGetterContext);const {codeValues} = useContext(Internals.VisualModeCodeValuesContext);+ const {isSelected, selectItem} = useTimelineSelection();const tree = useMemo(() =>@@ -125,6 +127,7 @@ const TimelineExpandedTrackKeyframesInner: React.FC<{keyframeDisplayOffset,}),key: JSON.stringify(node.nodePathInfo),+ rowNodePathInfo: node.nodePathInfo,})),[codeValues,@@ -140,31 +143,62 @@ const TimelineExpandedTrackKeyframesInner: React.FC<{height: expandedHeight + TIMELINE_ITEM_BORDER_BOTTOM,}}>- <div style={{...section, height: expandedHeight}}>- {rows.map(({height, keyframes, key}, i) => {+ <div style={{height: expandedHeight}}>+ {rows.map(({height, keyframes, key, rowNodePathInfo}, i) => {+ const rowSelected = isSelected({+ type: 'row',+ nodePathInfo: rowNodePathInfo,+ });+return (<React.Fragment key={key}>- {i > 0 ? <div style={separator} /> : null}+ {i > 0 ? <div style={rowSeparator} /> : null}<div style={{...row, height}}>+ {rowSelected ? (+ <div style={getTimelineSelectedTrackHighlightStyle()} />+ ) : null}{timelineWidth === null? null- : keyframes.map((keyframe) => (- <div- key={String(keyframe.frame)}- style={{- ...diamondBase,- left:- getXPositionOfItemInTimelineImperatively(- keyframe.frame,- videoConfig.durationInFrames,- timelineWidth,- ) - TIMELINE_PADDING,- top: height / 2,- transform: 'translate(-50%, -50%) rotate(45deg)',- }}- title={`Keyframe at frame ${keyframe.frame}`}- />- ))}+ : keyframes.map((keyframe) => {+ const selectionItem: TimelineSelection = {+ type: 'keyframe',+ nodePathInfo: rowNodePathInfo,+ frame: keyframe.frame,+ };+ const selected = isSelected(selectionItem);++ return (+ <button+ key={String(keyframe.frame)}+ type="button"+ style={{+ ...diamondBase,+ backgroundColor: selected+ ? TIMELINE_SELECTED_LABEL_BACKGROUND+ : LIGHT_TEXT,+ border: 'none',+ cursor: 'default',+ left:+ getXPositionOfItemInTimelineImperatively(+ keyframe.frame,+ videoConfig.durationInFrames,+ timelineWidth,+ ) - TIMELINE_PADDING,+ padding: 0,+ pointerEvents: 'auto',+ top: height / 2,+ transform: 'translate(-50%, -50%) rotate(45deg)',+ }}+ title={`Keyframe at frame ${keyframe.frame}`}+ aria-label={`Select keyframe at frame ${keyframe.frame}`}+ onPointerDown={(e) => {+ if (e.button === 0) {+ selectItem(selectionItem);+ }+ }}+ />+ );+ })}</div></React.Fragment>);diff --git a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineFieldRow.tsxindex 198bcf37cc..a52e05e70d 100644--- a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx+++ b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx@@ -2,11 +2,12 @@ import React, {useCallback, useContext, useMemo} from 'react';import type {CanUpdateSequencePropStatusTrue,SequencePropsSubscriptionKey,+ SequenceSchema,} from 'remotion';-import type {SequenceSchema} from 'remotion';import {Internals} from 'remotion';import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-source-map';import {StudioServerConnectionCtx} from '../../helpers/client-id';+import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';import type {SchemaFieldInfo,TimelineFieldOnDragValueChange,@@ -22,8 +23,20 @@ import {TimelineFieldValue,TimelineNonEditableStatus,} from './TimelineSchemaField';--const fieldRowBase: React.CSSProperties = {+import {+ getTimelineSelectedLabelStyle,+ TIMELINE_SELECTED_LABEL_TEXT,+ useTimelineRowSelection,+} from './TimelineSelection';++const fieldRowBase: React.CSSProperties = {};++const valueColumnStyle: React.CSSProperties = {+ alignItems: 'center',+ alignSelf: 'stretch',+ display: 'flex',+ flex: 1,+ minWidth: 0,paddingRight: EXPANDED_SECTION_PADDING_RIGHT,};@@ -153,11 +166,13 @@ export const TimelineFieldRow: React.FC<{readonly validatedLocation: CodePosition;readonly rowDepth: number;readonly nodePath: SequencePropsSubscriptionKey;+ readonly nodePathInfo: SequenceNodePathInfo;readonly schema: SequenceSchema;-}> = ({field, validatedLocation, rowDepth, nodePath, schema}) => {+}> = ({field, validatedLocation, rowDepth, nodePath, nodePathInfo, schema}) => {const {codeValues: visualModeCodeValues} = useContext(Internals.VisualModeCodeValuesContext,);+ const selection = useTimelineRowSelection(nodePathInfo);const codeValuesForOverride = Internals.getCodeValuesCtx(visualModeCodeValues,@@ -173,8 +188,22 @@ export const TimelineFieldRow: React.FC<{}, [field.rowHeight]);const labelRowStyle = useMemo(- () => getTimelineFieldLabelRowStyle(rowDepth),- [rowDepth],+ (): React.CSSProperties => ({+ ...getTimelineFieldLabelRowStyle(rowDepth),+ ...getTimelineSelectedLabelStyle(selection.selected),+ alignSelf: 'stretch',+ }),+ [rowDepth, selection.selected],+ );++ const fieldNameStyle = useMemo(+ (): React.CSSProperties => ({+ ...fieldName,+ color: selection.selected+ ? TIMELINE_SELECTED_LABEL_TEXT+ : fieldName.color,+ }),+ [selection.selected],);if (codeValue === null) {@@ -187,20 +216,28 @@ export const TimelineFieldRow: React.FC<{eye={<TimelineLayerEyeSpacer />}arrow={<TimelineExpandArrowSpacer />}style={style}+ selected={selection.selected}+ selectable={selection.selectable}+ onSelect={selection.onSelect}+ showSelectedBackground><div style={labelRowStyle}>- <span style={fieldName}>{field.description ?? field.key}</span>+ <span style={fieldNameStyle}>{field.description ?? field.key}</span></div>{codeValue.canUpdate ? (- <Value- field={field}- nodePath={nodePath}- validatedLocation={validatedLocation}- schema={schema}- codeValue={codeValue}- />+ <div style={valueColumnStyle}>+ <Value+ field={field}+ nodePath={nodePath}+ validatedLocation={validatedLocation}+ schema={schema}+ codeValue={codeValue}+ />+ </div>) : (- <TimelineNonEditableStatus propStatus={codeValue} />+ <div style={valueColumnStyle}>+ <TimelineNonEditableStatus propStatus={codeValue} />+ </div>)}</TimelineRowChrome>);diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsxindex f0e5f2e484..005cedc604 100644--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx@@ -27,6 +27,10 @@ import {TimelineExpandedSection} from './TimelineExpandedSection';import {TimelineLayerEye, TimelineLayerEyeSpacer} from './TimelineLayerEye';import {TimelineMediaInfo} from './TimelineMediaInfo';import {TimelineRowChrome} from './TimelineRowChrome';+import {+ TIMELINE_SELECTED_BACKGROUND,+ useTimelineRowSelection,+} from './TimelineSelection';import {TimelineStack} from './TimelineStack';import {useResolveStackAndReactToChange} from './use-resolved-stack-react-to-change';@@ -43,6 +47,8 @@ export const TimelineListItem: React.FC<{const {toggleTrack} = useContext(ExpandedTracksSetterContext);const {codeValues} = useContext(Internals.VisualModeCodeValuesContext);const {setCodeValues} = useContext(Internals.VisualModeSettersContext);+ const {onSelect, selectable, selected} =+ useTimelineRowSelection(nodePathInfo);const originalLocation = useResolveStackAndReactToChange(sequence.getStack);@@ -261,13 +267,23 @@ export const TimelineListItem: React.FC<{const outer: React.CSSProperties = useMemo(() => {return {+ backgroundColor: selected ? TIMELINE_SELECTED_BACKGROUND : undefined,height:getTimelineLayerHeight(sequence.type) + TIMELINE_ITEM_BORDER_BOTTOM,borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`,display: 'flex',flexDirection: 'column',};- }, [sequence.type]);+ }, [selected, sequence.type]);++ const onSelectPointerDown = useCallback(+ (e: React.PointerEvent<HTMLDivElement>) => {+ if (e.button === 0) {+ onSelect();+ }+ },+ [onSelect],+ );const inner: React.CSSProperties = useMemo(() => {return {@@ -310,7 +326,11 @@ export const TimelineListItem: React.FC<{codeHiddenStatus.canUpdate;const trackRow = (- <div style={outer}>+ <div+ style={outer}+ onPointerDown={selectable ? onSelectPointerDown : undefined}+ onContextMenu={selectable ? onSelect : undefined}+ ><TimelineRowChromedepth={nestedDepth}eye={@@ -337,11 +357,16 @@ export const TimelineListItem: React.FC<{)}style={inner}+ selected={selected}+ selectable={false}+ onSelect={onSelect}+ showSelectedBackground={false}><TimelineStacksequence={sequence}isCompact={isCompact}originalLocation={originalLocation}+ selected={selected}/></TimelineRowChrome>{mediaSrc ? (@@ -358,7 +383,12 @@ export const TimelineListItem: React.FC<{return (<>{previewConnected ? (- <ContextMenu values={contextMenuValues}>{trackRow}</ContextMenu>+ <ContextMenu+ values={contextMenuValues}+ onOpen={selectable ? onSelect : null}+ >+ {trackRow}+ </ContextMenu>) : (trackRow)}diff --git a/packages/studio/src/components/Timeline/TimelineRowChrome.tsx b/packages/studio/src/components/Timeline/TimelineRowChrome.tsxindex 819bd07bfd..6e3d3004a1 100644--- a/packages/studio/src/components/Timeline/TimelineRowChrome.tsx+++ b/packages/studio/src/components/Timeline/TimelineRowChrome.tsx@@ -1,13 +1,22 @@-import React, {useMemo} from 'react';+import React, {useCallback, useMemo} from 'react';import {Padder} from './Padder';import {TIMELINE_ROW_BASE_PADDING,getTimelineRowIndentWidth,} from './timeline-row-layout';+import {TIMELINE_SELECTED_BACKGROUND} from './TimelineSelection';const rowBase: React.CSSProperties = {+ alignItems: 'stretch',display: 'flex',+};++const chromeColumnStyle: React.CSSProperties = {alignItems: 'center',+ alignSelf: 'stretch',+ display: 'flex',+ flexShrink: 0,+ paddingLeft: TIMELINE_ROW_BASE_PADDING,};export const TimelineRowChrome: React.FC<{@@ -15,24 +24,56 @@ export const TimelineRowChrome: React.FC<{readonly eye: React.ReactNode;readonly arrow: React.ReactNode;readonly children: React.ReactNode;- readonly style?: React.CSSProperties;-}> = ({depth, eye, arrow, children, style}) => {+ readonly style: React.CSSProperties;+ readonly selected: boolean;+ readonly selectable: boolean;+ readonly onSelect: () => void;+ readonly showSelectedBackground: boolean;+}> = ({+ depth,+ eye,+ arrow,+ children,+ style,+ selected,+ selectable,+ onSelect,+ showSelectedBackground,+}) => {const rowStyle = useMemo((): React.CSSProperties => ({...rowBase,- paddingLeft: TIMELINE_ROW_BASE_PADDING,...style,+ backgroundColor:+ selected && showSelectedBackground+ ? TIMELINE_SELECTED_BACKGROUND+ : undefined,}),- [style],+ [selected, showSelectedBackground, style],);const indentWidth = getTimelineRowIndentWidth(depth);+ const onPointerDown = useCallback(+ (e: React.PointerEvent<HTMLDivElement>) => {+ if (e.button === 0) {+ onSelect();+ }+ },+ [onSelect],+ );+return (- <div style={rowStyle}>- {eye}- {indentWidth > 0 ? <Padder depth={depth} /> : null}- {arrow}+ <div+ style={rowStyle}+ onPointerDown={selectable ? onPointerDown : undefined}+ onContextMenu={selectable ? onSelect : undefined}+ >+ <div style={chromeColumnStyle}>+ {eye}+ {indentWidth > 0 ? <Padder depth={depth} /> : null}+ {arrow}+ </div>{children}</div>);diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsxnew file mode 100644index 0000000000..0618254c16--- /dev/null+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx@@ -0,0 +1,165 @@+import React, {+ createContext,+ useCallback,+ useContext,+ useEffect,+ useMemo,+ useState,+ type CSSProperties,+} from 'react';+import {StudioServerConnectionCtx} from '../../helpers/client-id';+import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';+import {TIMELINE_PADDING} from '../../helpers/timeline-layout';+import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';++export const TIMELINE_SELECTED_BACKGROUND = 'rgba(255, 255, 255, 0.1)';+export const TIMELINE_SELECTED_LABEL_BACKGROUND = '#B0B0B0';+export const TIMELINE_SELECTED_LABEL_TEXT = 'black';+export const TIMELINE_SELECTED_LABEL_HORIZONTAL_PADDING = 2;++export const getTimelineSelectedLabelStyle = (+ selected: boolean,+): CSSProperties => {+ if (!selected) {+ return {};+ }++ const padding = TIMELINE_SELECTED_LABEL_HORIZONTAL_PADDING;+ return {+ backgroundColor: TIMELINE_SELECTED_LABEL_BACKGROUND,+ marginLeft: -padding,+ marginRight: -padding,+ paddingLeft: padding,+ paddingRight: padding,+ };+};++export const getTimelineSelectedTrackHighlightStyle = (): CSSProperties => ({+ backgroundColor: TIMELINE_SELECTED_BACKGROUND,+ bottom: 0,+ left: -TIMELINE_PADDING,+ pointerEvents: 'none',+ position: 'absolute',+ right: -TIMELINE_PADDING,+ top: 0,+});++export const SELECTION_ENABLED = false;++export type TimelineSelection =+ | {+ readonly type: 'row';+ readonly nodePathInfo: SequenceNodePathInfo;+ }+ | {+ readonly type: 'keyframe';+ readonly nodePathInfo: SequenceNodePathInfo;+ readonly frame: number;+ };++type TimelineSelectionContextValue = {+ readonly canSelect: boolean;+ readonly isSelected: (item: TimelineSelection) => boolean;+ readonly selectItem: (item: TimelineSelection) => void;+};++const TimelineSelectionContext = createContext<TimelineSelectionContextValue>({+ canSelect: false,+ isSelected: () => false,+ selectItem: () => undefined,+});++const getTimelineSelectionKey = (item: TimelineSelection): string => {+ const rowKey = timelineNodePathInfoToKey(item.nodePathInfo);+ if (item.type === 'row') {+ return rowKey;+ }++ return `${rowKey}.keyframe.${item.frame}`;+};++export const TimelineSelectionProvider: React.FC<{+ readonly children: React.ReactNode;+}> = ({children}) => {+ const {previewServerState} = useContext(StudioServerConnectionCtx);+ const canSelect =+ SELECTION_ENABLED &&+ previewServerState.type === 'connected' &&+ !window.remotion_isReadOnlyStudio;+ const [selectedItem, setSelectedItem] = useState<TimelineSelection | null>(+ null,+ );++ useEffect(() => {+ if (!canSelect) {+ setSelectedItem(null);+ }+ }, [canSelect]);++ const isSelected = useCallback(+ (item: TimelineSelection) => {+ return selectedItem === null+ ? false+ : getTimelineSelectionKey(selectedItem) ===+ getTimelineSelectionKey(item);+ },+ [selectedItem],+ );++ const selectItem = useCallback(+ (item: TimelineSelection) => {+ if (!canSelect) {+ return;+ }++ setSelectedItem(item);+ },+ [canSelect],+ );++ const value = useMemo(+ (): TimelineSelectionContextValue => ({+ canSelect,+ isSelected,+ selectItem,+ }),+ [canSelect, isSelected, selectItem],+ );++ return (+ <TimelineSelectionContext.Provider value={value}>+ {children}+ </TimelineSelectionContext.Provider>+ );+};++export const useTimelineSelection = () => {+ return useContext(TimelineSelectionContext);+};++export const useTimelineRowSelection = (+ nodePathInfo: SequenceNodePathInfo | null,+) => {+ const {canSelect, isSelected, selectItem} = useTimelineSelection();+ const selectionItem = useMemo(+ (): TimelineSelection | null =>+ nodePathInfo === null ? null : {type: 'row', nodePathInfo},+ [nodePathInfo],+ );++ const selected = selectionItem === null ? false : isSelected(selectionItem);++ const onSelect = useCallback(() => {+ if (selectionItem === null) {+ return;+ }++ selectItem(selectionItem);+ }, [selectItem, selectionItem]);++ return {+ onSelect,+ selectable: canSelect && selectionItem !== null,+ selected,+ };+};diff --git a/packages/studio/src/components/Timeline/TimelineStack/index.tsx b/packages/studio/src/components/Timeline/TimelineStack/index.tsxindex 8d5b7bf7d0..9fa4a3a066 100644--- a/packages/studio/src/components/Timeline/TimelineStack/index.tsx+++ b/packages/studio/src/components/Timeline/TimelineStack/index.tsx@@ -13,13 +13,18 @@ import {openOriginalPositionInEditor} from '../../../helpers/open-in-editor';import {Spacing} from '../../layout';import {showNotification} from '../../Notifications/NotificationCenter';import {Spinner} from '../../Spinner';+import {+ getTimelineSelectedLabelStyle,+ TIMELINE_SELECTED_LABEL_TEXT,+} from '../TimelineSelection';import {getOriginalSourceAttribution} from './source-attribution';export const TimelineStack: React.FC<{readonly isCompact: boolean;readonly sequence: TSequence;readonly originalLocation: OriginalPosition | null;-}> = ({isCompact, sequence, originalLocation}) => {+ readonly selected: boolean;+}> = ({isCompact, sequence, originalLocation, selected}) => {const [stackHovered, setStackHovered] = useState(false);const [titleHovered, setTitleHovered] = useState(false);const [opening, setOpening] = useState(false);@@ -117,22 +122,41 @@ export const TimelineStack: React.FC<{};}, [opening, stackHovered, stackHoverable]);+ const labelContainerStyle: React.CSSProperties = useMemo(() => {+ return {+ alignItems: 'center',+ alignSelf: 'stretch',+ display: 'flex',+ flex: 1,+ flexDirection: 'row',+ minWidth: 0,+ };+ }, []);+const titleStyle: React.CSSProperties = useMemo(() => {const hoverEffect = titleHovered && titleHoverable;return {+ alignItems: 'center',+ alignSelf: 'stretch',+ ...getTimelineSelectedLabelStyle(selected),+ display: 'flex',fontSize: 12,whiteSpace: 'nowrap',textOverflow: 'ellipsis',overflow: 'hidden',lineHeight: 1.2,- color: opening && isCompact ? VERY_LIGHT_TEXT : LIGHT_COLOR,+ color: selected+ ? TIMELINE_SELECTED_LABEL_TEXT+ : opening && isCompact+ ? VERY_LIGHT_TEXT+ : LIGHT_COLOR,userSelect: 'none',WebkitUserSelect: 'none',textDecoration: hoverEffect ? 'underline' : 'none',textUnderlineOffset: 2,cursor: hoverEffect ? 'pointer' : undefined,};- }, [titleHoverable, isCompact, opening, titleHovered]);+ }, [titleHoverable, isCompact, opening, selected, titleHovered]);const text =sequence.displayName.length > 1000@@ -140,7 +164,7 @@ export const TimelineStack: React.FC<{: sequence.displayName;return (- <>+ <div style={labelContainerStyle}><divonPointerEnter={onTitlePointerEnter}onPointerLeave={onTitlePointerLeave}@@ -170,6 +194,6 @@ export const TimelineStack: React.FC<{<Spinner duration={0.5} size={12} /></>) : null}- </>+ </div>);};diff --git a/packages/studio/src/components/Timeline/TimelineTracks.tsx b/packages/studio/src/components/Timeline/TimelineTracks.tsxindex 91f16e8e32..4ff61d459b 100644--- a/packages/studio/src/components/Timeline/TimelineTracks.tsx+++ b/packages/studio/src/components/Timeline/TimelineTracks.tsx@@ -9,13 +9,16 @@ import {import {ExpandedTracksGetterContext} from '../ExpandedTracksProvider';import {MaxTimelineTracksReached} from './MaxTimelineTracks';import {TimelineExpandedTrackKeyframes} from './TimelineExpandedTrackKeyframes';+import {+ getTimelineSelectedTrackHighlightStyle,+ useTimelineSelection,+} from './TimelineSelection';import {TimelineSequence} from './TimelineSequence';import {TimelineTimePadding} from './TimelineTimeIndicators';const content: React.CSSProperties = {paddingLeft: TIMELINE_PADDING,paddingRight: TIMELINE_PADDING,- paddingTop: 1,};const timelineContent: React.CSSProperties = {@@ -29,6 +32,7 @@ const TimelineTracksInner: React.FC<{const {getIsExpanded} = useContext(ExpandedTracksGetterContext);const {previewServerState} = useContext(StudioServerConnectionCtx);const previewServerConnected = previewServerState.type === 'connected';+ const {isSelected} = useTimelineSelection();const timelineStyle: React.CSSProperties = useMemo(() => {return {@@ -44,6 +48,9 @@ const TimelineTracksInner: React.FC<{{timeline.map((track) => {const isExpanded =track.nodePathInfo !== null && getIsExpanded(track.nodePathInfo);+ const rowSelected =+ track.nodePathInfo !== null &&+ isSelected({type: 'row', nodePathInfo: track.nodePathInfo});return (<div key={track.sequence.id}>@@ -51,8 +58,12 @@ const TimelineTracksInner: React.FC<{style={{height: getTimelineLayerHeight(track.sequence.type),marginBottom: TIMELINE_ITEM_BORDER_BOTTOM,+ position: 'relative',}}>+ {rowSelected ? (+ <div style={getTimelineSelectedTrackHighlightStyle()} />+ ) : null}<TimelineSequence s={track.sequence} /></div>{isExpanded && track.nodePathInfo && previewServerConnected ? (diff --git a/packages/studio/src/helpers/timeline-node-path-key.ts b/packages/studio/src/helpers/timeline-node-path-key.tsnew file mode 100644index 0000000000..82691ec36f--- /dev/null+++ b/packages/studio/src/helpers/timeline-node-path-key.ts@@ -0,0 +1,9 @@+import {stringifySequenceExpandedRowKey} from '@remotion/studio-shared';+import type {SequenceNodePathInfo} from './get-timeline-sequence-sort-key';++export const timelineNodePathInfoToKey = (info: SequenceNodePathInfo): string =>+ [+ stringifySequenceExpandedRowKey(info.sequenceSubscriptionKey),+ info.auxiliaryKeys.join('.'),+ info.index,+ ].join('.');diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.tsnew file mode 100644index 0000000000..e92b2e3ebf--- /dev/null+++ b/packages/studio/src/test/timeline-selection.test.ts@@ -0,0 +1,6 @@+import {expect, test} from 'bun:test';+import {SELECTION_ENABLED} from '../components/Timeline/TimelineSelection';++test('Timeline selection should stay disabled until released publicly', () => {+ expect(SELECTION_ENABLED).toBe(false);+});