🎥 Make videos programmatically with React
fix(studio): unify timeline tree row indentation
Jonny Burger4b57d76c9d54
diff --git a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsxindex 4f5bedb8af..e836e5edba 100644--- a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx+++ b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx@@ -7,13 +7,13 @@ import {StudioServerConnectionCtx} from '../../helpers/client-id';import type {EffectSchemaFieldInfo} from '../../helpers/timeline-layout';import {EXPANDED_SECTION_PADDING_RIGHT} from '../../helpers/timeline-layout';import {callApi} from '../call-api';-import {Padder} from './Padder';import {enqueueSavePropChange} from './save-prop-queue';+import {TimelineExpandArrowSpacer} from './TimelineExpandArrowButton';+import {TimelineLayerEyeSpacer} from './TimelineLayerEye';+import {TimelineRowChrome} from './TimelineRowChrome';import {TimelineFieldValue, UnsupportedStatus} from './TimelineSchemaField';const fieldRowBase: React.CSSProperties = {- display: 'flex',- alignItems: 'center',gap: 8,paddingRight: EXPANDED_SECTION_PADDING_RIGHT,};@@ -217,21 +217,23 @@ const Value: React.FC<{export const TimelineEffectFieldRow: React.FC<{readonly field: EffectSchemaFieldInfo;readonly validatedLocation: CodePosition;- readonly paddingLeft: number;- readonly nestedDepth: number;+ readonly rowDepth: number;readonly nodePath: SequencePropsSubscriptionKey;-}> = ({field, validatedLocation, paddingLeft, nestedDepth, nodePath}) => {+}> = ({field, validatedLocation, rowDepth, nodePath}) => {const style = useMemo(() => {return {...fieldRowBase,height: field.rowHeight,- paddingLeft,};- }, [field.rowHeight, paddingLeft]);+ }, [field.rowHeight]);return (- <div style={style}>- <Padder depth={nestedDepth + 1} />+ <TimelineRowChrome+ depth={rowDepth}+ eye={<TimelineLayerEyeSpacer />}+ arrow={<TimelineExpandArrowSpacer />}+ style={style}+ ><div style={fieldLabelRow}><span style={fieldName}>{field.description ?? field.key}</span></div>@@ -240,6 +242,6 @@ export const TimelineEffectFieldRow: React.FC<{nodePath={nodePath}validatedLocation={validatedLocation}/>- </div>+ </TimelineRowChrome>);};diff --git a/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsx b/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsxindex 67b6a62d9c..9341d055b0 100644--- a/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsx+++ b/packages/studio/src/components/Timeline/TimelineEffectGroupRow.tsx@@ -4,16 +4,15 @@ 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 {+ EXPANDED_SECTION_PADDING_RIGHT,+ TREE_GROUP_ROW_HEIGHT,+} from '../../helpers/timeline-layout';import type {GetIsExpanded} from '../ExpandedTracksProvider';-import {Padder} from './Padder';import {saveEffectProp} from './save-effect-prop';import {TimelineExpandArrowButton} from './TimelineExpandArrowButton';import {TimelineLayerEye, TimelineLayerEyeSpacer} from './TimelineLayerEye';--const groupRowBase: React.CSSProperties = {- display: 'flex',- alignItems: 'center',-};+import {TimelineRowChrome} from './TimelineRowChrome';const rowLabel: React.CSSProperties = {fontSize: 12,@@ -28,9 +27,7 @@ export const TimelineEffectGroupRow: React.FC<{readonly effectSchema: SequenceSchema;readonly nodePath: SequencePropsSubscriptionKey;readonly validatedLocation: CodePosition;- readonly nestedDepth: number;- readonly depth: number;- readonly style: React.CSSProperties;+ readonly rowDepth: number;readonly getIsExpanded: GetIsExpanded;readonly toggleTrack: (nodePathInfo: SequenceNodePathInfo) => void;}> = ({@@ -40,9 +37,7 @@ export const TimelineEffectGroupRow: React.FC<{effectSchema,nodePath,validatedLocation,- nestedDepth,- depth,- style,+ rowDepth,getIsExpanded,toggleTrack,}) => {@@ -114,30 +109,40 @@ export const TimelineEffectGroupRow: React.FC<{);const isExpanded = getIsExpanded(nodePathInfo);- const mergedStyle = useMemo(- (): React.CSSProperties => ({...groupRowBase, ...style}),- [style],++ const rowStyle = useMemo(+ (): React.CSSProperties => ({+ height: TREE_GROUP_ROW_HEIGHT,+ paddingRight: EXPANDED_SECTION_PADDING_RIGHT,+ }),+ [],);return (- <div style={mergedStyle}>- {canToggle ? (- <TimelineLayerEye- type="effect"- hidden={isDisabled}- onInvoked={onToggle}+ <TimelineRowChrome+ depth={rowDepth}+ eye={+ canToggle ? (+ <TimelineLayerEye+ type="effect"+ hidden={isDisabled}+ onInvoked={onToggle}+ />+ ) : (+ <TimelineLayerEyeSpacer />+ )+ }+ arrow={+ <TimelineExpandArrowButton+ isExpanded={isExpanded}+ onClick={() => toggleTrack(nodePathInfo)}+ label={`${label} section`}+ disabled={false}/>- ) : (- <TimelineLayerEyeSpacer />- )}- <Padder depth={nestedDepth + 1 + depth} />- <TimelineExpandArrowButton- isExpanded={isExpanded}- onClick={() => toggleTrack(nodePathInfo)}- label={`${label} section`}- disabled={false}- />+ }+ style={rowStyle}+ ><span style={rowLabel}>{label}</span>- </div>+ </TimelineRowChrome>);};diff --git a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsxindex f1792210d8..735fa13b69 100644--- a/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx+++ b/packages/studio/src/components/Timeline/TimelineExpandedRow.tsx@@ -1,28 +1,24 @@-import React, {useMemo} from 'react';+import React from 'react';import type {SequenceSchema, SequencePropsSubscriptionKey} from 'remotion';import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-source-map';import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';import type {TimelineTreeNode} from '../../helpers/timeline-layout';import {- EXPANDED_SECTION_PADDING_LEFT,EXPANDED_SECTION_PADDING_RIGHT,getTreeRowHeight,TREE_GROUP_ROW_HEIGHT,} from '../../helpers/timeline-layout';import type {GetIsExpanded} from '../ExpandedTracksProvider';-import {Padder} from './Padder';-import {TIMELINE_INDENT} from './timeline-indent';+import {getExpandedRowDepth} from './timeline-row-layout';import {TimelineEffectFieldRow} from './TimelineEffectFieldRow';import {TimelineEffectGroupRow} from './TimelineEffectGroupRow';-import {TimelineExpandArrowButton} from './TimelineExpandArrowButton';+import {+ TimelineExpandArrowButton,+ TimelineExpandArrowSpacer,+} from './TimelineExpandArrowButton';import {TimelineFieldRow} from './TimelineFieldRow';--const groupRowBase: React.CSSProperties = {- height: TREE_GROUP_ROW_HEIGHT,- display: 'flex',- alignItems: 'center',- paddingRight: EXPANDED_SECTION_PADDING_RIGHT,-};+import {TimelineLayerEyeSpacer} from './TimelineLayerEye';+import {TimelineRowChrome} from './TimelineRowChrome';const rowLabel: React.CSSProperties = {fontSize: 12,@@ -30,12 +26,6 @@ const rowLabel: React.CSSProperties = {userSelect: 'none',};-const labelOnlyRowBase: React.CSSProperties = {- display: 'flex',- alignItems: 'center',- paddingRight: EXPANDED_SECTION_PADDING_RIGHT,-};-export const TimelineExpandedRow: React.FC<{readonly node: TimelineTreeNode;readonly depth: number;@@ -55,26 +45,7 @@ export const TimelineExpandedRow: React.FC<{nodePath,schema,}) => {- const paddingLeft = EXPANDED_SECTION_PADDING_LEFT + depth * TIMELINE_INDENT;-- const groupStyle = useMemo(- (): React.CSSProperties => ({...groupRowBase, paddingLeft}),- [paddingLeft],- );-- const effectGroupStyle = useMemo(- (): React.CSSProperties => ({...groupRowBase, paddingLeft: 5}),- [],- );-- const labelOnlyStyle = useMemo(- (): React.CSSProperties => ({- ...labelOnlyRowBase,- height: getTreeRowHeight(node),- paddingLeft,- }),- [node, paddingLeft],- );+ const rowDepth = getExpandedRowDepth({nestedDepth, treeDepth: depth});if (node.kind === 'group') {if (node.effectInfo) {@@ -86,9 +57,7 @@ export const TimelineExpandedRow: React.FC<{effectSchema={node.effectInfo.effectSchema}nodePath={nodePath}validatedLocation={validatedLocation}- nestedDepth={nestedDepth}- depth={depth}- style={effectGroupStyle}+ rowDepth={rowDepth}getIsExpanded={getIsExpanded}toggleTrack={toggleTrack}/>@@ -97,16 +66,24 @@ export const TimelineExpandedRow: React.FC<{const isExpanded = getIsExpanded(node.nodePathInfo);return (- <div style={groupStyle}>- <Padder depth={nestedDepth + 1} />- <TimelineExpandArrowButton- isExpanded={isExpanded}- onClick={() => toggleTrack(node.nodePathInfo)}- label={`${node.label} section`}- disabled={false}- />+ <TimelineRowChrome+ depth={rowDepth}+ eye={<TimelineLayerEyeSpacer />}+ arrow={+ <TimelineExpandArrowButton+ isExpanded={isExpanded}+ onClick={() => toggleTrack(node.nodePathInfo)}+ label={`${node.label} section`}+ disabled={false}+ />+ }+ style={{+ height: TREE_GROUP_ROW_HEIGHT,+ paddingRight: EXPANDED_SECTION_PADDING_RIGHT,+ }}+ ><span style={rowLabel}>{node.label}</span>- </div>+ </TimelineRowChrome>);}@@ -116,8 +93,7 @@ export const TimelineExpandedRow: React.FC<{<TimelineEffectFieldRowfield={node.field}validatedLocation={validatedLocation}- paddingLeft={paddingLeft}- nestedDepth={nestedDepth}+ rowDepth={rowDepth}nodePath={nodePath}/>);@@ -128,8 +104,7 @@ export const TimelineExpandedRow: React.FC<{<TimelineFieldRowfield={node.field}validatedLocation={validatedLocation}- paddingLeft={paddingLeft}- nestedDepth={nestedDepth}+ rowDepth={rowDepth}nodePath={nodePath}schema={schema}/>@@ -142,9 +117,16 @@ export const TimelineExpandedRow: React.FC<{}return (- <div style={labelOnlyStyle}>- <Padder depth={nestedDepth + 1} />+ <TimelineRowChrome+ depth={rowDepth}+ eye={<TimelineLayerEyeSpacer />}+ arrow={<TimelineExpandArrowSpacer />}+ style={{+ height: getTreeRowHeight(node),+ paddingRight: EXPANDED_SECTION_PADDING_RIGHT,+ }}+ ><span style={rowLabel}>{node.label}</span>- </div>+ </TimelineRowChrome>);};diff --git a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineFieldRow.tsxindex b018ee0876..b751ffe73c 100644--- a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx+++ b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx@@ -13,16 +13,16 @@ import type {TimelineFieldOnSave,} from '../../helpers/timeline-layout';import {EXPANDED_SECTION_PADDING_RIGHT} from '../../helpers/timeline-layout';-import {Padder} from './Padder';import {saveSequenceProp} from './save-sequence-prop';+import {TimelineExpandArrowSpacer} from './TimelineExpandArrowButton';+import {TimelineLayerEyeSpacer} from './TimelineLayerEye';+import {TimelineRowChrome} from './TimelineRowChrome';import {TimelineFieldValue,TimelineNonEditableStatus,} from './TimelineSchemaField';const fieldRowBase: React.CSSProperties = {- display: 'flex',- alignItems: 'center',gap: 8,paddingRight: EXPANDED_SECTION_PADDING_RIGHT,};@@ -159,18 +159,10 @@ const Value: React.FC<{export const TimelineFieldRow: React.FC<{readonly field: SchemaFieldInfo;readonly validatedLocation: CodePosition;- readonly paddingLeft: number;- readonly nestedDepth: number;+ readonly rowDepth: number;readonly nodePath: SequencePropsSubscriptionKey;readonly schema: SequenceSchema;-}> = ({- field,- validatedLocation,- paddingLeft,- nestedDepth,- nodePath,- schema,-}) => {+}> = ({field, validatedLocation, rowDepth, nodePath, schema}) => {const {codeValues: visualModeCodeValues} = useContext(Internals.VisualModeCodeValuesContext,);@@ -185,17 +177,20 @@ export const TimelineFieldRow: React.FC<{return {...fieldRowBase,height: field.rowHeight,- paddingLeft,};- }, [field.rowHeight, paddingLeft]);+ }, [field.rowHeight]);if (codeValue === null) {return null;}return (- <div style={style}>- <Padder depth={nestedDepth + 1} />+ <TimelineRowChrome+ depth={rowDepth}+ eye={<TimelineLayerEyeSpacer />}+ arrow={<TimelineExpandArrowSpacer />}+ style={style}+ ><div style={fieldLabelRow}><span style={fieldName}>{field.description ?? field.key}</span></div>@@ -210,6 +205,6 @@ export const TimelineFieldRow: React.FC<{) : (<TimelineNonEditableStatus propStatus={codeValue} />)}- </div>+ </TimelineRowChrome>);};diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsxindex bad5a55c24..da524fd7ee 100644--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx@@ -17,7 +17,6 @@ import {} from '../ExpandedTracksProvider';import type {ComboboxValue} from '../NewComposition/ComboBox';import {showNotification} from '../Notifications/NotificationCenter';-import {Padder} from './Padder';import {saveSequenceProp} from './save-sequence-prop';import {TimelineExpandArrowButton,@@ -25,6 +24,7 @@ import {} from './TimelineExpandArrowButton';import {TimelineExpandedSection} from './TimelineExpandedSection';import {TimelineLayerEye, TimelineLayerEyeSpacer} from './TimelineLayerEye';+import {TimelineRowChrome} from './TimelineRowChrome';import {TimelineStack} from './TimelineStack';import {useResolveStackAndReactToChange} from './use-resolved-stack-react-to-change';@@ -271,12 +271,8 @@ export const TimelineListItem: React.FC<{height: TIMELINE_LAYER_HEIGHT_AUDIO,color: 'white',fontFamily: 'Arial, Helvetica, sans-serif',- display: 'flex',- flexDirection: 'row',- alignItems: 'center',wordBreak: 'break-all',textAlign: 'left',- paddingLeft: 5,};}, []);@@ -294,35 +290,39 @@ export const TimelineListItem: React.FC<{const trackRow = (<div style={outer}>- <div style={inner}>- {canToggleVisibility ? (- <TimelineLayerEye- type={sequence.type === 'audio' ? 'speaker' : 'eye'}- hidden={isItemHidden}- onInvoked={onToggleVisibility}- />- ) : (- <TimelineLayerEyeSpacer />- )}- <Padder depth={nestedDepth} />- {previewConnected ? (+ <TimelineRowChrome+ depth={nestedDepth}+ eye={+ canToggleVisibility ? (+ <TimelineLayerEye+ type={sequence.type === 'audio' ? 'speaker' : 'eye'}+ hidden={isItemHidden}+ onInvoked={onToggleVisibility}+ />+ ) : (+ <TimelineLayerEyeSpacer />+ )+ }+ arrow={hasExpandableContent ? (<TimelineExpandArrowButtonisExpanded={isExpanded}onClick={onToggleExpand}label="track properties"- disabled={nodePathInfo === null}+ disabled={!previewConnected || nodePathInfo === null}/>) : (<TimelineExpandArrowSpacer />)- ) : null}+ }+ style={inner}+ ><TimelineStacksequence={sequence}isCompact={isCompact}originalLocation={originalLocation}/>- </div>+ </TimelineRowChrome></div>);diff --git a/packages/studio/src/components/Timeline/TimelineRowChrome.tsx b/packages/studio/src/components/Timeline/TimelineRowChrome.tsxnew file mode 100644index 0000000000..1997b555fc--- /dev/null+++ b/packages/studio/src/components/Timeline/TimelineRowChrome.tsx@@ -0,0 +1,32 @@+import React, {useMemo} from 'react';+import {getTimelineRowPaddingLeft} from './timeline-row-layout';++const rowBase: React.CSSProperties = {+ display: 'flex',+ alignItems: 'center',+};++export const TimelineRowChrome: React.FC<{+ readonly depth: number;+ readonly eye: React.ReactNode;+ readonly arrow: React.ReactNode;+ readonly children: React.ReactNode;+ readonly style?: React.CSSProperties;+}> = ({depth, eye, arrow, children, style}) => {+ const rowStyle = useMemo(+ (): React.CSSProperties => ({+ ...rowBase,+ paddingLeft: getTimelineRowPaddingLeft(depth),+ ...style,+ }),+ [depth, style],+ );++ return (+ <div style={rowStyle}>+ {eye}+ {arrow}+ {children}+ </div>+ );+};diff --git a/packages/studio/src/components/Timeline/timeline-row-layout.ts b/packages/studio/src/components/Timeline/timeline-row-layout.tsnew file mode 100644index 0000000000..da7b8b235c--- /dev/null+++ b/packages/studio/src/components/Timeline/timeline-row-layout.ts@@ -0,0 +1,17 @@+import {TIMELINE_INDENT} from './timeline-indent';++export const TIMELINE_ROW_BASE_PADDING = 5;++export const getTimelineRowPaddingLeft = (depth: number): number => {+ return TIMELINE_ROW_BASE_PADDING + depth * TIMELINE_INDENT;+};++export const getExpandedRowDepth = ({+ nestedDepth,+ treeDepth,+}: {+ nestedDepth: number;+ treeDepth: number;+}): number => {+ return nestedDepth + 1 + treeDepth;+};diff --git a/packages/studio/src/helpers/timeline-layout.ts b/packages/studio/src/helpers/timeline-layout.tsindex abd4945458..bf8f969a45 100644--- a/packages/studio/src/helpers/timeline-layout.ts+++ b/packages/studio/src/helpers/timeline-layout.ts@@ -39,7 +39,6 @@ export const TIMELINE_ITEM_BORDER_BOTTOM = 1;export const TIMELINE_TRACK_EXPANDED_HEIGHT = 100;export const TREE_GROUP_ROW_HEIGHT = 22;-export const EXPANDED_SECTION_PADDING_LEFT = 28;export const EXPANDED_SECTION_PADDING_RIGHT = 10;export type TimelineFieldOnSave = (value: unknown) => Promise<void>;@@ -110,7 +109,12 @@ export const buildTimelineTree = ({kind: 'field',nodePathInfo: {sequenceSubscriptionKey,- auxiliaryKeys: [...auxiliaryKeys, f.key],+ auxiliaryKeys: [+ ...auxiliaryKeys,+ 'effects',+ i.toString(),+ f.key,+ ],index,numberOfSequencesWithThisNodePath: 0,},diff --git a/packages/studio/src/test/timeline-tree-layout.test.ts b/packages/studio/src/test/timeline-tree-layout.test.tsnew file mode 100644index 0000000000..9a9f9acfe7--- /dev/null+++ b/packages/studio/src/test/timeline-tree-layout.test.ts@@ -0,0 +1,123 @@+import {expect, test} from 'bun:test';+import type {TSequence} from 'remotion';+import {+ getExpandedRowDepth,+ getTimelineRowPaddingLeft,+} from '../components/Timeline/timeline-row-layout';+import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';+import {+ buildTimelineTree,+ flattenVisibleTreeNodes,+} from '../helpers/timeline-layout';++const nodePathInfo: SequenceNodePathInfo = {+ sequenceSubscriptionKey: {+ nodePath: ['Composition', 'Sequence'],+ overrideId: 'test',+ },+ auxiliaryKeys: [],+ index: 0,+ numberOfSequencesWithThisNodePath: 1,+};++const makeSequence = (): TSequence => ({+ from: 0,+ duration: 100,+ id: 'seq-1',+ displayName: 'HtmlInCanvas',+ parent: null,+ rootId: 'seq-1',+ showInTimeline: true,+ type: 'sequence',+ nonce: [[0, 0]],+ getStack: () => null,+ premountDisplay: null,+ postmountDisplay: null,+ controls: {+ overrideId: 'test',+ schema: {+ translate: {+ type: 'translate',+ description: 'Translate',+ },+ },+ currentRuntimeValueDotNotation: {},+ },+ effects: [+ {+ label: 'Halftone',+ schema: {+ color: {+ type: 'color',+ description: 'Color',+ },+ },+ },+ ],+});++test('effect field auxiliaryKeys include effect path', () => {+ const tree = buildTimelineTree({+ sequence: makeSequence(),+ nodePathInfo,+ getDragOverrides: () => ({}),+ codeValues: {},+ });++ const effectsGroup = tree.find(+ (n) => n.kind === 'group' && n.label === 'Effects',+ );+ expect(effectsGroup?.kind).toBe('group');+ if (effectsGroup?.kind !== 'group') {+ throw new Error('expected Effects group');+ }++ const halftone = effectsGroup.children[0];+ expect(halftone.kind).toBe('group');+ if (halftone.kind !== 'group') {+ throw new Error('expected Halftone group');+ }++ const colorField = halftone.children[0];+ expect(colorField.kind).toBe('field');+ if (colorField.kind !== 'field') {+ throw new Error('expected Color field');+ }++ expect(colorField.nodePathInfo.auxiliaryKeys).toEqual([+ 'effects',+ '0',+ 'color',+ ]);+});++test('flattenVisibleTreeNodes assigns increasing tree depth', () => {+ const tree = buildTimelineTree({+ sequence: makeSequence(),+ nodePathInfo,+ getDragOverrides: () => ({}),+ codeValues: {},+ });++ const flat = flattenVisibleTreeNodes({+ nodes: tree,+ getIsExpanded: () => true,+ });++ expect(flat.map(({node, depth}) => ({label: node.label, depth}))).toEqual([+ {label: 'Effects', depth: 0},+ {label: 'Halftone', depth: 1},+ {label: 'Color', depth: 2},+ {label: 'Translate', depth: 0},+ ]);+});++test('getExpandedRowDepth combines composition and tree depth', () => {+ expect(+ getExpandedRowDepth({+ nestedDepth: 1,+ treeDepth: 2,+ }),+ ).toBe(4);+ expect(getTimelineRowPaddingLeft(4)).toBe(45);+});