import React, {useMemo} from 'react'; import type {TSequence} from 'remotion'; import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-source-map'; import {TIMELINE_TRACK_SEPARATOR, WHITE} from '../../helpers/colors'; import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key'; import { flattenVisibleTreeNodes, getTreeRowHeight, TIMELINE_ITEM_BORDER_BOTTOM, } from '../../helpers/timeline-layout'; import {timelineNodePathInfoToStableKey} from '../../helpers/timeline-node-path-key'; import {EffectReorderTargetsProvider} from './TimelineEffectItem'; import {TimelineExpandedRow} from './TimelineExpandedRow'; import {TimelineRowSelectedBackgroundContext} from './TimelineRowChrome'; import { TIMELINE_BACKGROUND, TIMELINE_EXPANDED_SELECTED_BACKGROUND, } from './TimelineSelection'; import {useTimelineExpandedTree} from './use-timeline-expanded-tree'; const expandedSectionBase: React.CSSProperties = { backgroundColor: TIMELINE_BACKGROUND, color: WHITE, fontFamily: 'Arial, Helvetica, sans-serif', fontSize: 12, display: 'flex', flexDirection: 'column', borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`, }; const separator: React.CSSProperties = { height: 0, borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`, }; export const TimelineExpandedSection: React.FC<{ readonly sequence: TSequence; readonly validatedLocation: CodePosition; readonly nodePathInfo: SequenceNodePathInfo; readonly nestedDepth: number; readonly keyframeDisplayOffset: number; readonly keyframePlaybackRate: number; }> = ({ sequence, validatedLocation, nodePathInfo, nestedDepth, keyframeDisplayOffset, keyframePlaybackRate, }) => { const {filteredTree, getIsExpanded, toggleTrack} = useTimelineExpandedTree({ sequence, nodePathInfo, includeTextContent: false, includeSourceControls: false, includeInspectorOnlyFields: false, }); const flat = useMemo( () => flattenVisibleTreeNodes({nodes: filteredTree, getIsExpanded}), [filteredTree, getIsExpanded], ); const expandedHeight = useMemo(() => { const totalRowsHeight = flat.reduce( (sum, {node}) => sum + getTreeRowHeight(node), 0, ); const separators = Math.max(0, flat.length - 1); return totalRowsHeight + separators; }, [flat]); const style = useMemo(() => { return { ...expandedSectionBase, height: expandedHeight + TIMELINE_ITEM_BORDER_BOTTOM, }; }, [expandedHeight]); const {schema} = sequence.controls!; if (flat.length === 0) { return null; } return (
{flat.map(({node, depth}, i) => { return ( {i > 0 ?
: null} {null} ); })}
); };