🎥 Make videos programmatically with React
`@remotion/studio`: Add slide transitions between inspector views
Jonny Burger5f24cad00063
diff --git a/packages/studio/src/components/InspectorPanel.tsx b/packages/studio/src/components/InspectorPanel.tsxindex c30a1ba81a..c70be8aaf6 100644--- a/packages/studio/src/components/InspectorPanel.tsx+++ b/packages/studio/src/components/InspectorPanel.tsx@@ -46,12 +46,10 @@ export const InspectorPanel: React.FC<{if (selectedItems.length > 1) {if (sameSequenceInspectorSelection) {return (- <div style={container}>- <SelectedInspector- selection={sameSequenceInspectorSelection}- readOnlyStudio={readOnlyStudio}- />- </div>+ <SelectedInspector+ selection={sameSequenceInspectorSelection}+ readOnlyStudio={readOnlyStudio}+ />);}@@ -74,11 +72,9 @@ export const InspectorPanel: React.FC<{}return (- <div style={container}>- <SelectedInspector- selection={selectedItems[0]}- readOnlyStudio={readOnlyStudio}- />- </div>+ <SelectedInspector+ selection={selectedItems[0]}+ readOnlyStudio={readOnlyStudio}+ />);};diff --git a/packages/studio/src/components/InspectorPanel/EasingInspector.tsx b/packages/studio/src/components/InspectorPanel/EasingInspector.tsxindex 300fd4846b..5c21925783 100644--- a/packages/studio/src/components/InspectorPanel/EasingInspector.tsx+++ b/packages/studio/src/components/InspectorPanel/EasingInspector.tsx@@ -37,7 +37,6 @@ import {import {getEasingSelectionFromCurrentKeyframes} from './easing-inspector-selection';import {KeyframeEasingNavigator} from './KeyframeEasingNavigator';import {KeyframeSettings} from './KeyframeSettings';-import {SequenceInspectorSections} from './SequenceInspectorHeader';import {selectedContainer} from './styles';import {useTrackForSelection} from './use-track-for-selection';@@ -349,7 +348,6 @@ export const EasingInspector: React.FC<{return (<div style={selectedContainer} className={VERTICAL_SCROLLBAR_CLASSNAME}>- <SequenceInspectorSections track={track} /><EasingEditorkey={getTimelineSelectionKey(currentEasingSelection)}state={state}diff --git a/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx b/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsxindex 9a380a6539..12df182d8d 100644--- a/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx+++ b/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx@@ -55,7 +55,6 @@ import {} from './common';import {clampInspectorKeyframeDisplayFrame} from './keyframe-inspector-frame';import {KeyframeEasingNavigator} from './KeyframeEasingNavigator';-import {SequenceInspectorSections} from './SequenceInspectorHeader';import {detailsBeforeInlineAction,detailsWithInlineAction,@@ -533,7 +532,6 @@ export const KeyframeInspector: React.FC<{return (<div style={selectedContainer} className={VERTICAL_SCROLLBAR_CLASSNAME}>- <SequenceInspectorSections track={track} /><InspectorBackActiondisabled={parentSelection === null}onClick={onSelectParent}diff --git a/packages/studio/src/components/InspectorPanel/SelectedInspector.tsx b/packages/studio/src/components/InspectorPanel/SelectedInspector.tsxindex dc01c2e49d..b9190ac432 100644--- a/packages/studio/src/components/InspectorPanel/SelectedInspector.tsx+++ b/packages/studio/src/components/InspectorPanel/SelectedInspector.tsx@@ -1,13 +1,32 @@-import React from 'react';-import type {TimelineSelection} from '../Timeline/TimelineSelection';+import React, {useLayoutEffect, useRef, useState} from 'react';+import {flushSync} from 'react-dom';+import {+ getTimelineSequenceSelectionKey,+ type TimelineSelection,+} from '../Timeline/TimelineSelection';import {InspectorMessage} from './common';import {EasingInspector} from './EasingInspector';import {GuideInspector} from './GuideInspector';import {isSequenceSectionSelection} from './inspector-selection';import {KeyframeInspector} from './KeyframeInspector';+import {SequenceInspectorSections} from './SequenceInspectorHeader';import {SequenceSelectionInspector} from './SequenceSelectionInspector';+import {container} from './styles';+import {useTrackForSelection} from './use-track-for-selection';-export const SelectedInspector: React.FC<{+const headerStyle: React.CSSProperties = {+ flexShrink: 0,+};++const contentStyle: React.CSSProperties = {+ display: 'flex',+ flex: 1,+ flexDirection: 'column',+ minHeight: 0,+ overflow: 'hidden',+};++const SelectedInspectorContent: React.FC<{readonly selection: TimelineSelection;readonly readOnlyStudio: boolean;}> = ({selection, readOnlyStudio}) => {@@ -34,3 +53,109 @@ export const SelectedInspector: React.FC<{return <InspectorMessage>Inspector unavailable</InspectorMessage>;};++export const SelectedInspector: React.FC<{+ readonly selection: TimelineSelection;+ readonly readOnlyStudio: boolean;+}> = ({selection, readOnlyStudio}) => {+ const [displayedSelection, setDisplayedSelection] = useState(selection);+ const displayedSelectionRef = useRef(selection);+ const panelRef = useRef<HTMLDivElement>(null);+ const track = useTrackForSelection(displayedSelection);++ useLayoutEffect(() => {+ const previous = displayedSelectionRef.current;+ if (previous === selection) {+ return;+ }++ const forward =+ isSequenceSectionSelection(previous) &&+ (selection.type === 'keyframe' || selection.type === 'easing');+ const backward =+ (previous.type === 'keyframe' || previous.type === 'easing') &&+ isSequenceSectionSelection(selection);+ const panel = panelRef.current;+ if (+ (!forward && !backward) ||+ getTimelineSequenceSelectionKey(previous.nodePathInfo) !==+ getTimelineSequenceSelectionKey(selection.nodePathInfo) ||+ panel === null ||+ typeof document.startViewTransition !== 'function' ||+ typeof flushSync !== 'function' ||+ window.matchMedia('(prefers-reduced-motion: reduce)').matches+ ) {+ displayedSelectionRef.current = selection;+ setDisplayedSelection(selection);+ return;+ }++ // Defer only the inspector DOM swap; timeline selection stays synchronous.+ const root = document.documentElement;+ const transitionClass = forward+ ? '__remotion-inspector-forward'+ : '__remotion-inspector-backward';+ root.classList.add(transitionClass);+ panel.style.setProperty('view-transition-name', 'remotion-inspector');+ let cancelled = false;++ const cleanup = () => {+ root.classList.remove(transitionClass);+ panel.style.removeProperty('view-transition-name');+ };++ const transition = document.startViewTransition(() => {+ if (cancelled) {+ return;+ }++ flushSync(() => {+ displayedSelectionRef.current = selection;+ setDisplayedSelection(selection);+ });+ });+ // A skipped transition still applies its update, but rejects `ready`.+ transition.ready.catch(() => undefined);+ transition.finished.then(+ () => {+ if (!cancelled) {+ cleanup();+ }+ },+ () => {+ if (!cancelled) {+ cleanup();+ }+ },+ );++ return () => {+ cancelled = true;+ transition.skipTransition();+ cleanup();+ };+ }, [selection]);++ return (+ <div style={container}>+ {track === null ? null : (+ <div style={headerStyle}>+ <SequenceInspectorSections+ key={+ track.nodePathInfo+ ? getTimelineSequenceSelectionKey(track.nodePathInfo)+ : track.sequence.id+ }+ track={track}+ />+ </div>+ )}+ <div ref={panelRef} style={contentStyle}>+ <SelectedInspectorContent+ selection={displayedSelection}+ readOnlyStudio={readOnlyStudio}+ />+ </div>+ </div>+ );+};diff --git a/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx b/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsxindex 723c0266e1..41eacd112b 100644--- a/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx+++ b/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx@@ -43,16 +43,8 @@ import {largeInspectorActionIconContainerStyle,largeInspectorActionIconStyle,} from './common';-import {- ConnectedCompositionsSection,- useConnectedCompositions,-} from './ConnectedCompositionsSection';import type {SequenceSectionSelection} from './inspector-selection';-import {- SequenceInspectorDuplicationSection,- SequenceInspectorHeader,- useSequenceInspectorSourceLocation,-} from './SequenceInspectorHeader';+import {useSequenceInspectorSourceLocation} from './SequenceInspectorHeader';import {SequencePrecomposeAction} from './SequencePrecomposeAction';import {SequenceWrapAction} from './SequenceWrapAction';import {selectedContainer} from './styles';@@ -405,9 +397,7 @@ const SequenceExpandedInspector: React.FC<{const {previewServerState} = useContext(StudioServerConnectionCtx);const {selectedItems, selectItems} = useTimelineSelection();const sourceLocation = useSequenceInspectorSourceLocation(track.sequence);- const connectedCompositions = useConnectedCompositions({track});const {validatedLocation} = sourceLocation;- const stackKey = track.sequence.getStack();const sequenceSelection = useMemo((): Extract<TimelineSelection,{type: 'sequence'}@@ -468,17 +458,6 @@ const SequenceExpandedInspector: React.FC<{className={VERTICAL_SCROLLBAR_CLASSNAME}onPointerDown={selectSequenceOnInspectorPointerDown}>- <SequenceInspectorHeader- key={stackKey ?? track.sequence.id}- sourceLocation={sourceLocation}- track={track}- />- <SequenceInspectorDuplicationSection track={track} />- {connectedCompositions.length > 0 ? (- <ConnectedCompositionsSection- connectedCompositions={connectedCompositions}- />- ) : null}{validatedLocation ? (<><InspectorSequenceSectiondiff --git a/packages/studio/src/helpers/inject-css.ts b/packages/studio/src/helpers/inject-css.tsindex 83166a5f6b..b119497c60 100644--- a/packages/studio/src/helpers/inject-css.ts+++ b/packages/studio/src/helpers/inject-css.ts@@ -27,6 +27,57 @@ const makeDefaultGlobalCSS = () => {position: static !important;}+ html.__remotion-inspector-forward,+ html.__remotion-inspector-backward {+ view-transition-name: none;+ --remotion-inspector-slide-distance: 100%;+ }++ html.__remotion-inspector-backward {+ --remotion-inspector-slide-distance: -100%;+ }++ html.__remotion-inspector-forward::view-transition,+ html.__remotion-inspector-backward::view-transition {+ pointer-events: none;+ }++ ::view-transition-group(remotion-inspector) {+ animation: none;+ overflow: clip;+ }++ ::view-transition-old(remotion-inspector),+ ::view-transition-new(remotion-inspector) {+ animation-duration: 75ms;+ animation-timing-function: ease-out;+ animation-fill-mode: both;+ mix-blend-mode: normal;+ }++ ::view-transition-old(remotion-inspector) {+ animation-name: remotion-inspector-slide-out;+ }++ ::view-transition-new(remotion-inspector) {+ animation-name: remotion-inspector-slide-in;+ }++ @keyframes remotion-inspector-slide-out {+ to { transform: translateX(calc(-1 * var(--remotion-inspector-slide-distance))); }+ }++ @keyframes remotion-inspector-slide-in {+ from { transform: translateX(var(--remotion-inspector-slide-distance)); }+ }++ @media (prefers-reduced-motion: reduce) {+ ::view-transition-old(remotion-inspector),+ ::view-transition-new(remotion-inspector) {+ animation: none;+ }+ }+.remotion-splitter {user-select: none;-webkit-user-select: none;