Skip to content

🎥 Make videos programmatically with React

Read Studio editing state when actions begin

Jonny Burger865dcac57b9b
diff --git a/packages/studio/src/components/GlobalKeybindings.tsx b/packages/studio/src/components/GlobalKeybindings.tsx
index 9cc8548705..55814fd48e 100644
--- a/packages/studio/src/components/GlobalKeybindings.tsx
+++ b/packages/studio/src/components/GlobalKeybindings.tsx
@@ -21,6 +21,7 @@ import {askAiModalRef} from './AskAiModal';
import {useCompositionNavigation} from './CompositionSelector';
import {explorerSidebarTabs} from './ExplorerPanelRef';
import {showNotification} from './Notifications/NotificationCenter';
+import {OverrideIdToNodePathMappingsRefContext} from './SequencePropsSubscriptionProvider';
import {
getTimelineSequenceSelectionKey,
useCurrentTimelineSelectionStateAsRef,
@@ -118,8 +119,8 @@ export const GlobalKeybindings: React.FC = () => {
const currentSelection = useCurrentTimelineSelectionStateAsRef();
const sequencesRef = useContext(Internals.SequenceManagerRefContext);
const videoConfig = Internals.useUnsafeVideoConfig();
- const {overrideIdToNodePathMappings} = useContext(
- Internals.OverrideIdsToNodePathsGettersContext,
+ const overrideIdToNodePathMappingsRef = useContext(
+ OverrideIdToNodePathMappingsRefContext,
);
const {navigateToNextComposition, navigateToPreviousComposition} =
useCompositionNavigation();
@@ -141,7 +142,7 @@ export const GlobalKeybindings: React.FC = () => {
);
const timeline = calculateTimeline({
sequences: sequencesRef.current,
- overrideIdsToNodePaths: overrideIdToNodePathMappings,
+ overrideIdsToNodePaths: overrideIdToNodePathMappingsRef.current,
});
const track = timeline.find(
(candidate) =>
@@ -178,7 +179,12 @@ export const GlobalKeybindings: React.FC = () => {
);
return true;
},
- [currentSelection, overrideIdToNodePathMappings, sequencesRef, videoConfig],
+ [
+ currentSelection,
+ overrideIdToNodePathMappingsRef,
+ sequencesRef,
+ videoConfig,
+ ],
);
const openRenderModal = useCallback(() => {
diff --git a/packages/studio/src/components/InspectorPanel/AlignmentControls.tsx b/packages/studio/src/components/InspectorPanel/AlignmentControls.tsx
index b486bd6841..6be94c206a 100644
--- a/packages/studio/src/components/InspectorPanel/AlignmentControls.tsx
+++ b/packages/studio/src/components/InspectorPanel/AlignmentControls.tsx
@@ -1,9 +1,13 @@
import React, {useCallback, useContext, useMemo} from 'react';
-import {Internals, type CanUpdateSequencePropStatus} from 'remotion';
+import {
+ Internals,
+ type CanUpdateSequencePropStatus,
+ type SequenceRegistrationControls,
+} from 'remotion';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
import type {TimelineTrackData} from '../../helpers/get-timeline-sequence-sort-key';
import {isStudioInteractivityEnabled} from '../../helpers/interactivity-enabled';
-import {useRuntimeValues} from '../../helpers/use-runtime-values';
+import {useRuntimeValueSelector} from '../../helpers/use-runtime-values';
import {AlignBottomIcon} from '../../icons/align-bottom';
import {AlignCenterHorizontalIcon} from '../../icons/align-center-horizontal';
import {AlignCenterVerticalIcon} from '../../icons/align-center-vertical';
@@ -20,6 +24,10 @@ import {
getKeyframeDisplayOffset,
getKeyframeSourceFrame,
} from '../Timeline/get-timeline-keyframes';
+import {
+ getCurrentDimensions,
+ getCurrentFrame,
+} from '../Timeline/imperative-state';
import {saveSequenceProps} from '../Timeline/save-sequence-prop';
import {
parseTranslate,
@@ -76,12 +84,98 @@ const AlignmentButton: React.FC<{
);
};
-export const AlignmentControls: React.FC<{
+type AlignmentDirection =
+ | 'left'
+ | 'center-h'
+ | 'right'
+ | 'top'
+ | 'center-v'
+ | 'bottom';
+type AlignmentEligibility = 'hidden' | 'enabled' | 'disabled';
+
+const AlignmentButtons = React.memo(
+ ({
+ eligibility,
+ onAlign,
+ }: {
+ readonly eligibility: AlignmentEligibility;
+ readonly onAlign: (direction: AlignmentDirection) => void;
+ }) => {
+ if (eligibility === 'hidden') {
+ return null;
+ }
+
+ const alignmentDisabled = eligibility === 'disabled';
+
+ return (
+ <div style={container}>
+ <AlignmentButton
+ aria-label="Align left"
+ onClick={() => onAlign('left')}
+ Icon={AlignLeftIcon}
+ disabled={alignmentDisabled}
+ />
+ <AlignmentButton
+ aria-label="Align center horizontally"
+ onClick={() => onAlign('center-h')}
+ Icon={AlignCenterHorizontalIcon}
+ disabled={alignmentDisabled}
+ />
+ <AlignmentButton
+ aria-label="Align right"
+ onClick={() => onAlign('right')}
+ Icon={AlignRightIcon}
+ disabled={alignmentDisabled}
+ />
+ <div style={verticalSpacer} />
+ <AlignmentButton
+ aria-label="Align top"
+ onClick={() => onAlign('top')}
+ Icon={AlignTopIcon}
+ disabled={alignmentDisabled}
+ />
+ <AlignmentButton
+ aria-label="Align center vertically"
+ onClick={() => onAlign('center-v')}
+ Icon={AlignCenterVerticalIcon}
+ disabled={alignmentDisabled}
+ />
+ <AlignmentButton
+ aria-label="Align bottom"
+ onClick={() => onAlign('bottom')}
+ Icon={AlignBottomIcon}
+ disabled={alignmentDisabled}
+ />
+ </div>
+ );
+ },
+);
+
+const AlignmentControlsWithAnimatedSchema: React.FC<{
+ readonly controls: SequenceRegistrationControls;
+ readonly getEligibility: (
+ values: Readonly<Record<string, unknown>>,
+ frame: number,
+ ) => AlignmentEligibility;
+ readonly onAlign: (direction: AlignmentDirection) => void;
+}> = ({controls, getEligibility, onAlign}) => {
+ const frame = Internals.Timeline.useTimelinePosition();
+ return (
+ <AlignmentButtons
+ eligibility={getEligibility(controls.runtimeValues.getSnapshot(), frame)}
+ onAlign={onAlign}
+ />
+ );
+};
+
+const AlignmentControlsUnmemoized: React.FC<{
readonly track: TimelineTrackData;
}> = ({track}) => {
- const runtimeValues = useRuntimeValues(track.sequence.controls);
const {previewServerState} = useContext(StudioServerConnectionCtx);
const {propStatuses} = useContext(Internals.VisualModePropStatusesContext);
+ const propStatusesRef = useContext(
+ Internals.VisualModePropStatusesRefContext,
+ );
const {getDragOverrides} = useContext(
Internals.VisualModeDragOverridesContext,
);
@@ -96,12 +190,95 @@ export const AlignmentControls: React.FC<{
);
}, [canvasContent, compositions]);
- const timelinePosition = Internals.Timeline.useTimelinePosition();
+ const renderNodePath = track.nodePathInfo?.sequenceSubscriptionKey ?? null;
+ const renderNodePropStatuses =
+ renderNodePath === null
+ ? undefined
+ : Internals.getPropStatusesCtx(propStatuses, renderNodePath);
+ const schema = track.sequence.controls?.schema ?? null;
+ const getAlignmentEligibility = useCallback(
+ (
+ runtimeValues: Readonly<Record<string, unknown>>,
+ frame: number,
+ ): AlignmentEligibility => {
+ if (schema === null) {
+ return 'hidden';
+ }
+
+ // Only enum values decide which translate field is visible. Animated
+ // numeric values are read when aligning, without rendering the buttons.
+ const renderDragOverrides =
+ renderNodePath === null ? {} : (getDragOverrides(renderNodePath) ?? {});
+ const activeSchema = Internals.flattenActiveSchema(schema, (key) => {
+ const {merged} = Internals.computeEffectiveSchemaValuesDotNotation({
+ schema,
+ currentValue: Object.prototype.hasOwnProperty.call(runtimeValues, key)
+ ? {[key]: runtimeValues[key]}
+ : {},
+ overrideValues: renderDragOverrides,
+ propStatus: renderNodePropStatuses,
+ frame:
+ (frame - track.keyframeDisplayOffset) * track.keyframePlaybackRate,
+ });
+ return merged[key];
+ });
+ if (activeSchema[translateFieldKey]?.type !== 'translate') {
+ return 'hidden';
+ }
+
+ return isPropStatusDraggable(renderNodePropStatuses?.[translateFieldKey])
+ ? 'enabled'
+ : 'disabled';
+ },
+ [
+ getDragOverrides,
+ renderNodePath,
+ renderNodePropStatuses,
+ schema,
+ track.keyframeDisplayOffset,
+ track.keyframePlaybackRate,
+ ],
+ );
+ const selectAlignmentEligibility = useCallback(
+ (values: Readonly<Record<string, unknown>>) =>
+ getAlignmentEligibility(values, getCurrentFrame()),
+ [getAlignmentEligibility],
+ );
+ const hasAnimatedSchema = useMemo(() => {
+ if (schema === null) {
+ return false;
+ }
+
+ const dragOverrides =
+ renderNodePath === null ? {} : (getDragOverrides(renderNodePath) ?? {});
+ const schemas = [schema];
+ while (schemas.length > 0) {
+ const currentSchema = schemas.pop()!;
+ for (const [key, field] of Object.entries(currentSchema)) {
+ if (field.type !== 'enum') {
+ continue;
+ }
+
+ if (
+ renderNodePropStatuses?.[key]?.status === 'keyframed' ||
+ dragOverrides[key]?.type === 'keyframed'
+ ) {
+ return true;
+ }
+
+ schemas.push(...Object.values(field.variants));
+ }
+ }
+
+ return false;
+ }, [getDragOverrides, renderNodePath, renderNodePropStatuses, schema]);
+ const alignmentEligibility = useRuntimeValueSelector({
+ controls: track.sequence.controls,
+ selector: selectAlignmentEligibility,
+ });
const handleAlign = useCallback(
- (
- direction: 'left' | 'center-h' | 'right' | 'top' | 'center-v' | 'bottom',
- ) => {
+ (direction: AlignmentDirection) => {
if (
!isStudioInteractivityEnabled() ||
previewServerState.type !== 'connected' ||
@@ -116,9 +293,11 @@ export const AlignmentControls: React.FC<{
return;
}
+ const timelinePosition = getCurrentFrame();
+ const runtimeValues = track.sequence.controls.runtimeValues.getSnapshot();
const nodePath = track.nodePathInfo.sequenceSubscriptionKey;
const nodePropStatuses = Internals.getPropStatusesCtx(
- propStatuses,
+ propStatusesRef.current,
nodePath,
);
const dragOverrides = getDragOverrides(nodePath) ?? {};
@@ -151,7 +330,8 @@ export const AlignmentControls: React.FC<{
return;
}
- if (!currentCompositionMetadata?.width) {
+ const {width} = getCurrentDimensions();
+ if (!width) {
return;
}
@@ -160,7 +340,7 @@ export const AlignmentControls: React.FC<{
return;
}
- const scale = compositionRect.width / currentCompositionMetadata.width;
+ const scale = compositionRect.width / width;
const currentTranslate = propStatus
? String(
@@ -250,10 +430,7 @@ export const AlignmentControls: React.FC<{
[
previewServerState,
track,
- currentCompositionMetadata,
- timelinePosition,
- propStatuses,
- runtimeValues,
+ propStatusesRef,
getDragOverrides,
setPropStatuses,
],
@@ -269,71 +446,18 @@ export const AlignmentControls: React.FC<{
return null;
}
- const renderNodePath = track.nodePathInfo.sequenceSubscriptionKey;
- const renderNodePropStatuses = Internals.getPropStatusesCtx(
- propStatuses,
- renderNodePath,
- );
- const renderDragOverrides = getDragOverrides(renderNodePath) ?? {};
-
- const renderActiveSchema = getSelectedOutlineActiveSchema({
- schema: track.sequence.controls.schema,
- currentRuntimeValueDotNotation: runtimeValues,
- dragOverrides: renderDragOverrides,
- propStatus: renderNodePropStatuses,
- frame:
- (timelinePosition - track.keyframeDisplayOffset) *
- track.keyframePlaybackRate,
- });
-
- const renderFieldSchema = renderActiveSchema?.[translateFieldKey];
- const renderPropStatus = renderNodePropStatuses?.[translateFieldKey];
-
- if (renderFieldSchema?.type !== 'translate') {
- return null;
- }
-
- const alignmentDisabled = !isPropStatusDraggable(renderPropStatus);
-
- return (
- <div style={container}>
- <AlignmentButton
- aria-label="Align left"
- onClick={() => handleAlign('left')}
- Icon={AlignLeftIcon}
- disabled={alignmentDisabled}
- />
- <AlignmentButton
- aria-label="Align center horizontally"
- onClick={() => handleAlign('center-h')}
- Icon={AlignCenterHorizontalIcon}
- disabled={alignmentDisabled}
- />
- <AlignmentButton
- aria-label="Align right"
- onClick={() => handleAlign('right')}
- Icon={AlignRightIcon}
- disabled={alignmentDisabled}
- />
- <div style={verticalSpacer} />
- <AlignmentButton
- aria-label="Align top"
- onClick={() => handleAlign('top')}
- Icon={AlignTopIcon}
- disabled={alignmentDisabled}
- />
- <AlignmentButton
- aria-label="Align center vertically"
- onClick={() => handleAlign('center-v')}
- Icon={AlignCenterVerticalIcon}
- disabled={alignmentDisabled}
- />
- <AlignmentButton
- aria-label="Align bottom"
- onClick={() => handleAlign('bottom')}
- Icon={AlignBottomIcon}
- disabled={alignmentDisabled}
- />
- </div>
+ return hasAnimatedSchema ? (
+ <AlignmentControlsWithAnimatedSchema
+ controls={track.sequence.controls}
+ getEligibility={getAlignmentEligibility}
+ onAlign={handleAlign}
+ />
+ ) : (
+ <AlignmentButtons
+ eligibility={alignmentEligibility}
+ onAlign={handleAlign}
+ />
);
};
+
+export const AlignmentControls = React.memo(AlignmentControlsUnmemoized);
diff --git a/packages/studio/src/components/InspectorPanel/SequencePrecomposeAction.tsx b/packages/studio/src/components/InspectorPanel/SequencePrecomposeAction.tsx
index 632a1e24fb..58309d312c 100644
--- a/packages/studio/src/components/InspectorPanel/SequencePrecomposeAction.tsx
+++ b/packages/studio/src/components/InspectorPanel/SequencePrecomposeAction.tsx
@@ -1,5 +1,5 @@
import React, {useCallback, useContext, useState} from 'react';
-import {Internals, useVideoConfig} from 'remotion';
+import {Internals} from 'remotion';
import {getBrowserStudioOperations} from '../../helpers/browser-studio-operations';
import {getConnectedCompositions} from '../../helpers/get-connected-compositions';
import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
@@ -8,6 +8,11 @@ import {SetSelectedModalContext} from '../../state/modals';
import {selectCompositionWhenReady} from '../InitialCompositionLoader';
import {showNotification} from '../Notifications/NotificationCenter';
import {precomposeJsxNodes} from '../precompose-jsx-nodes-api';
+import {
+ getCurrentDimensions,
+ getCurrentDuration,
+ getCurrentFps,
+} from '../Timeline/imperative-state';
import {useResolvedStack} from '../Timeline/use-resolved-stack';
import {InspectorQuickAction} from './common';
@@ -30,7 +35,6 @@ export const SequencePrecomposeAction: React.FC<{
const {compositions, canvasContent} = useContext(
Internals.CompositionManager,
);
- const {width, height, fps, durationInFrames} = useVideoConfig();
const [busy, setBusy] = useState(false);
const browserStudioOperations = getBrowserStudioOperations();
const compositionId =
@@ -88,7 +92,11 @@ export const SequencePrecomposeAction: React.FC<{
compositionFile,
compositionId,
existingCompositionIds: compositions.map(({id}) => id),
- metadata: {width, height, fps, durationInFrames},
+ metadata: {
+ ...getCurrentDimensions(),
+ fps: getCurrentFps(),
+ durationInFrames: getCurrentDuration(),
+ },
};
const uniqueSourceNodes =
@@ -135,13 +143,9 @@ export const SequencePrecomposeAction: React.FC<{
compositionFile,
compositionId,
compositions,
- durationInFrames,
- fps,
hasConnectedComposition,
- height,
setSelectedModal,
targets,
- width,
]);
if (!canChangeSource || hasConnectedComposition || targets.length === 0) {
diff --git a/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx b/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx
index 62b6932df0..f4e25b249c 100644
--- a/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx
+++ b/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx
@@ -1,6 +1,6 @@
import type {NodeWrapper} from '@remotion/studio-shared';
import React, {useCallback, useContext, useState} from 'react';
-import {Internals, isHtmlInCanvasSupported, useVideoConfig} from 'remotion';
+import {Internals, isHtmlInCanvasSupported} from 'remotion';
import {calculateTimeline} from '../../helpers/calculate-timeline';
import type {
SequenceNodePathInfo,
@@ -11,6 +11,8 @@ import {HtmlInCanvasIcon} from '../../icons/html-in-canvas';
import {MotionBlurIcon} from '../../icons/motion-blur';
import {SetSelectedModalContext} from '../../state/modals';
import {showNotification} from '../Notifications/NotificationCenter';
+import {OverrideIdToNodePathMappingsRefContext} from '../SequencePropsSubscriptionProvider';
+import {getCurrentDimensions} from '../Timeline/imperative-state';
import {wrapNode} from '../wrap-node-api';
import {
InspectorQuickAction,
@@ -38,11 +40,10 @@ export const SequenceWrapAction: React.FC<{
readonly line: number;
};
}> = ({nodePathInfo, track, sourceActionsDisabled, sourceLocation}) => {
- const {width, height} = useVideoConfig();
const {setSelectedModal} = useContext(SetSelectedModalContext);
const sequencesRef = useContext(Internals.SequenceManagerRefContext);
- const {overrideIdToNodePathMappings} = useContext(
- Internals.OverrideIdsToNodePathsGettersContext,
+ const overrideIdToNodePathMappingsRef = useContext(
+ OverrideIdToNodePathMappingsRefContext,
);
const {sequence} = track;
const [busy, setBusy] = useState(false);
@@ -63,6 +64,9 @@ export const SequenceWrapAction: React.FC<{
}
const sequences = sequencesRef.current;
+ const overrideIdToNodePathMappings =
+ overrideIdToNodePathMappingsRef.current;
+ const {width, height} = getCurrentDimensions();
const sequencesById = new Map(
sequences.map((registeredSequence) => [
registeredSequence.id,
@@ -178,9 +182,8 @@ export const SequenceWrapAction: React.FC<{
},
[
busy,
- height,
nodePathInfo.sequenceSubscriptionKey,
- overrideIdToNodePathMappings,
+ overrideIdToNodePathMappingsRef,
sequence.controls?.componentName,
sequence.displayName,
sequence.id,
@@ -188,7 +191,6 @@ export const SequenceWrapAction: React.FC<{
setSelectedModal,
sourceActionsDisabled,
sourceLocation,
- width,
],
);
diff --git a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
index 66e136d79d..dc48e10b15 100644
--- a/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
+++ b/packages/studio/src/components/Timeline/TimelineClipboardKeybindings.tsx
@@ -38,6 +38,7 @@ import {
import {useConfirmationDialog} from '../ConfirmationDialog';
import {pasteEffects} from '../effect-operations-api';
import {showNotification} from '../Notifications/NotificationCenter';
+import {OverrideIdToNodePathMappingsRefContext} from '../SequencePropsSubscriptionProvider';
import {callAddKeyframes} from './call-add-keyframe';
import {callDeleteKeyframes} from './call-delete-keyframe';
import {
@@ -68,7 +69,7 @@ import {
} from './sequence-prop-clipboard';
import {
useCurrentTimelineSelectionStateAsRef,
- useTimelineSelection,
+ useTimelineSelectionCanSelect,
type TimelineSelection,
} from './TimelineSelection';
import {
@@ -651,15 +652,15 @@ export const getPasteEffectPropTarget = ({
export const TimelineClipboardKeybindings: React.FC = () => {
const keybindings = useKeybinding();
const {previewServerState} = useContext(StudioServerConnectionCtx);
- const {canSelect} = useTimelineSelection();
+ const canSelect = useTimelineSelectionCanSelect();
const currentSelection = useCurrentTimelineSelectionStateAsRef();
const propStatusesRef = useContext(
Internals.VisualModePropStatusesRefContext,
);
const {setPropStatuses} = useContext(Internals.VisualModeSettersContext);
const sequencesRef = useContext(Internals.SequenceManagerRefContext);
- const {overrideIdToNodePathMappings} = useContext(
- Internals.OverrideIdsToNodePathsGettersContext,
+ const overrideIdToNodePathMappingsRef = useContext(
+ OverrideIdToNodePathMappingsRefContext,
);
const confirm = useConfirmationDialog();
@@ -677,6 +678,8 @@ export const TimelineClipboardKeybindings: React.FC = () => {
const {selectedItems} = currentSelection.current;
const propStatuses = propStatusesRef.current;
const sequences = sequencesRef.current;
+ const overrideIdToNodePathMappings =
+ overrideIdToNodePathMappingsRef.current;
if (selectedItems.length === 0) {
return;
}
@@ -893,6 +896,8 @@ export const TimelineClipboardKeybindings: React.FC = () => {
return;
}
+ const overrideIdToNodePathMappings =
+ overrideIdToNodePathMappingsRef.current;
const effectClipboardData = getEffectClipboardDataFromSelections({
selectedItems,
propStatuses: propStatusesRef.current,
@@ -986,10 +991,13 @@ export const TimelineClipboardKeybindings: React.FC = () => {
const {text, envelope} = readClipboardTextAndEffectsEnvelope(
e.clipboardData,
);
+ const propStatuses = propStatusesRef.current;
+ const sequences = sequencesRef.current;
+ const overrideIdToNodePathMappings =
+ overrideIdToNodePathMappingsRef.current;
+ const timelinePosition = getCurrentFrame();
Promise.resolve()
.then(() => {
- const propStatuses = propStatusesRef.current;
- const sequences = sequencesRef.current;
const keyframeResult = parseKeyframeClipboardDataResult(text);
if (keyframeResult.status !== 'invalid') {
if (keyframeResult.status === 'unsupported-version') {
@@ -1003,7 +1011,7 @@ export const TimelineClipboardKeybindings: React.FC = () => {
const keyframeTarget = getPasteKeyframeTarget({
selectedItems,
payload: keyframeResult.data,
- timelinePosition: getCurrentFrame(),
+ timelinePosition,
sequences,
overrideIdsToNodePaths: overrideIdToNodePathMappings,
propStatuses,
@@ -1434,7 +1442,7 @@ export const TimelineClipboardKeybindings: React.FC = () => {
confirm,
currentSelection,
keybindings,
- overrideIdToNodePathMappings,
+ overrideIdToNodePathMappingsRef,
propStatusesRef,
previewServerState,
sequencesRef,
diff --git a/packages/studio/src/components/Timeline/TimelineDeleteKeybindings.tsx b/packages/studio/src/components/Timeline/TimelineDeleteKeybindings.tsx
index ca738c31f4..dae487eae3 100644
--- a/packages/studio/src/components/Timeline/TimelineDeleteKeybindings.tsx
+++ b/packages/studio/src/components/Timeline/TimelineDeleteKeybindings.tsx
@@ -10,7 +10,7 @@ import {getCurrentFrame} from './imperative-state';
import {splitSelectedTimelineItems} from './split-selected-timeline-item';
import {
useCurrentTimelineSelectionStateAsRef,
- useTimelineSelection,
+ useTimelineSelectionCanSelect,
} from './TimelineSelection';
import {useDeleteTimelineItems} from './use-delete-timeline-items';
@@ -24,7 +24,7 @@ export const TimelineDeleteKeybindings: React.FC = () => {
const propStatusesRef = useContext(
Internals.VisualModePropStatusesRefContext,
);
- const {canSelect} = useTimelineSelection();
+ const canSelect = useTimelineSelectionCanSelect();
const currentSelection = useCurrentTimelineSelectionStateAsRef();
const confirm = useConfirmationDialog();
const deleteTimelineItems = useDeleteTimelineItems();
diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsx
index effda08b32..3d3d5ed871 100644
--- a/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsx
+++ b/packages/studio/src/components/Timeline/TimelineKeyframeEasingLine.tsx
@@ -8,6 +8,7 @@ import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sor
import {TIMELINE_PADDING} from '../../helpers/timeline-layout';
import {ContextMenuForTarget} from '../ContextMenu';
import type {ComboboxValue} from '../NewComposition/ComboBox';
+import {OverrideIdToNodePathMappingsRefContext} from '../SequencePropsSubscriptionProvider';
import {EasingPresetPreview} from './EasingEditorModal';
import {
TIMELINE_MARQUEE_ITEM_ATTR,
@@ -103,8 +104,8 @@ const TimelineKeyframeEasingLineInteraction: React.FC<
Internals.VisualModePropStatusesRefContext,
);
const {setPropStatuses} = useContext(Internals.VisualModeSettersContext);
- const {overrideIdToNodePathMappings} = useContext(
- Internals.OverrideIdsToNodePathsGettersContext,
+ const overrideIdToNodePathMappingsRef = useContext(
+ OverrideIdToNodePathMappingsRefContext,
);
const currentSelection = useCurrentTimelineSelectionStateAsRef();
@@ -124,7 +125,7 @@ const TimelineKeyframeEasingLineInteraction: React.FC<
const promise = updateSelectedTimelineEasings({
selections: getTargetSelections(),
sequences: sequencesRef.current,
- overrideIdsToNodePaths: overrideIdToNodePathMappings,
+ overrideIdsToNodePaths: overrideIdToNodePathMappingsRef.current,
propStatuses: propStatusesRef.current,
setPropStatuses,
clientId: previewServerState.clientId,
@@ -134,7 +135,7 @@ const TimelineKeyframeEasingLineInteraction: React.FC<
},
[
getTargetSelections,
- overrideIdToNodePathMappings,
+ overrideIdToNodePathMappingsRef,
previewServerState,
propStatusesRef,
sequencesRef,
diff --git a/packages/studio/src/components/Timeline/TimelinePlayCursorSyncer.tsx b/packages/studio/src/components/Timeline/TimelinePlayCursorSyncer.tsx
index b1737eb963..2cd5e0eb84 100644
--- a/packages/studio/src/components/Timeline/TimelinePlayCursorSyncer.tsx
+++ b/packages/studio/src/components/Timeline/TimelinePlayCursorSyncer.tsx
@@ -7,6 +7,7 @@ import {
getCurrentDuration,
getCurrentFrame,
getCurrentZoom,
+ setCurrentDimensions,
setCurrentDuration,
setCurrentFps,
setCurrentFrame,
@@ -47,6 +48,7 @@ export const TimelinePlayCursorSyncer: React.FC = () => {
setCurrentZoom(zoom);
setCurrentDuration(video.durationInFrames);
setCurrentFps(video.fps);
+ setCurrentDimensions(video.width, video.height);
}
/**
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsx
index 2960b1e401..e3a94fc637 100644
--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx
@@ -503,6 +503,8 @@ const defaultTimelineSelectionContextValue: TimelineSelectionContextValue = {
clearSelection: () => undefined,
};
+const TimelineSelectionCanSelectContext = createContext(false);
+
const TimelineSelectionContext = createContext<TimelineSelectionContextValue>(
defaultTimelineSelectionContextValue,
);
@@ -804,7 +806,7 @@ export const TimelineSelectAllKeybindings: React.FC<{
readonly timeline: readonly TimelineTrackData[];
}> = ({timeline}) => {
const keybindings = useKeybinding();
- const {canSelect} = useTimelineSelection();
+ const canSelect = useTimelineSelectionCanSelect();
const currentSelection = useCurrentTimelineSelectionStateAsRef();
const selectableSequenceSelections = useMemo(
@@ -1505,23 +1507,29 @@ export const TimelineSelectionProvider: React.FC<{
);
return (
- <CurrentTimelineSelectionContext.Provider value={currentSelection}>
- <TimelineRowSelectionContext.Provider value={rowSelectionContextValue}>
- <TimelineSelectionContext.Provider value={value}>
- {children}
- <TimelineEscapeKeybindings />
- {isStudioInteractivityEnabled() ? (
- <>
- <TimelineClipboardKeybindings />
- <TimelineDeleteKeybindings />
- </>
- ) : null}
- </TimelineSelectionContext.Provider>
- </TimelineRowSelectionContext.Provider>
- </CurrentTimelineSelectionContext.Provider>
+ <TimelineSelectionCanSelectContext.Provider value={canSelect}>
+ <CurrentTimelineSelectionContext.Provider value={currentSelection}>
+ <TimelineRowSelectionContext.Provider value={rowSelectionContextValue}>
+ <TimelineSelectionContext.Provider value={value}>
+ {children}
+ <TimelineEscapeKeybindings />
+ {isStudioInteractivityEnabled() ? (
+ <>
+ <TimelineClipboardKeybindings />
+ <TimelineDeleteKeybindings />
+ </>
+ ) : null}
+ </TimelineSelectionContext.Provider>
+ </TimelineRowSelectionContext.Provider>
+ </CurrentTimelineSelectionContext.Provider>
+ </TimelineSelectionCanSelectContext.Provider>
);
};
+export const useTimelineSelectionCanSelect = () => {
+ return useContext(TimelineSelectionCanSelectContext);
+};
+
export const useTimelineSelection = () => {
return useContext(TimelineSelectionContext);
};
diff --git a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
index 3cf9de02ae..d6c46d7778 100644
--- a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
@@ -26,6 +26,7 @@ import type {
import {ContextMenu} from '../ContextMenu';
import {INSPECTOR_PANEL_HORIZONTAL_PADDING} from '../InspectorPanelLayout';
import type {ComboboxValue} from '../NewComposition/ComboBox';
+import {OverrideIdToNodePathMappingsRefContext} from '../SequencePropsSubscriptionProvider';
import {useEditorOpening} from '../use-default-editor-info';
import {callAddSequenceKeyframe} from './call-add-keyframe';
import {getCopyContextForAgentsMenuItem} from './get-copy-context-for-agents-menu-item';
@@ -115,8 +116,8 @@ const Value: React.FC<{
Internals.VisualModePropStatusesRefContext,
);
const sequencesRef = useContext(Internals.SequenceManagerRefContext);
- const {overrideIdToNodePathMappings} = useContext(
- Internals.OverrideIdsToNodePathsGettersContext,
+ const overrideIdToNodePathMappingsRef = useContext(
+ OverrideIdToNodePathMappingsRefContext,
);
const getPlaybackRateChanges = useCallback(
(value: unknown) => {
@@ -144,7 +145,7 @@ const Value: React.FC<{
return getPlaybackRateKeyframeChanges({
nodePath,
sequences: sequencesRef.current,
- overrideIdsToNodePaths: overrideIdToNodePathMappings,
+ overrideIdsToNodePaths: overrideIdToNodePathMappingsRef.current,
propStatuses: propStatusesRef.current,
previousPlaybackRate,
playbackRate: value,
@@ -154,7 +155,7 @@ const Value: React.FC<{
field.fieldSchema.default,
field.key,
nodePath,
- overrideIdToNodePathMappings,
+ overrideIdToNodePathMappingsRef,
propStatusesRef,
sequencesRef,
],
@@ -179,6 +180,8 @@ const Value: React.FC<{
}
const key = stringifySequenceSubscriptionKey(nodePath);
+ const overrideIdToNodePathMappings =
+ overrideIdToNodePathMappingsRef.current;
const sequence = sequencesRef.current.find((candidate) => {
const overrideId = candidate.controls?.overrideId;
const path = overrideId
@@ -201,7 +204,7 @@ const Value: React.FC<{
[
field.key,
nodePath,
- overrideIdToNodePathMappings,
+ overrideIdToNodePathMappingsRef,
propStatusesRef,
schema,
sequencesRef,
diff --git a/packages/studio/src/components/Timeline/imperative-state.ts b/packages/studio/src/components/Timeline/imperative-state.ts
index fbfb195105..a1739c7f09 100644
--- a/packages/studio/src/components/Timeline/imperative-state.ts
+++ b/packages/studio/src/components/Timeline/imperative-state.ts
@@ -2,6 +2,7 @@ let currentFrame = 0;
let currentZoom = 1;
let currentDuration = 1;
let currentFps = 1;
+let currentDimensions = {width: 1, height: 1};
export const getCurrentZoom = () => {
return currentZoom;
@@ -34,3 +35,18 @@ export const getCurrentFps = () => {
export const setCurrentFps = (d: number) => {
currentFps = d;
};
+
+export const getCurrentDimensions = () => {
+ return currentDimensions;
+};
+
+export const setCurrentDimensions = (width: number, height: number) => {
+ if (
+ currentDimensions.width === width &&
+ currentDimensions.height === height
+ ) {
+ return;
+ }
+
+ currentDimensions = {width, height};
+};
diff --git a/packages/studio/src/components/Timeline/use-delete-timeline-items.ts b/packages/studio/src/components/Timeline/use-delete-timeline-items.ts
index c7002e3eb2..423416ef47 100644
--- a/packages/studio/src/components/Timeline/use-delete-timeline-items.ts
+++ b/packages/studio/src/components/Timeline/use-delete-timeline-items.ts
@@ -7,6 +7,7 @@ import {
persistGuidesList,
} from '../../state/editor-guides';
import {useConfirmationDialog} from '../ConfirmationDialog';
+import {OverrideIdToNodePathMappingsRefContext} from '../SequencePropsSubscriptionProvider';
import {
deleteSelectedTimelineItems,
getTimelineSelectionAfterDeletingItems,
@@ -25,8 +26,8 @@ import {
export const useDeleteTimelineItems = () => {
const {previewServerState} = useContext(StudioServerConnectionCtx);
const sequencesRef = useContext(Internals.SequenceManagerRefContext);
- const {overrideIdToNodePathMappings} = useContext(
- Internals.OverrideIdsToNodePathsGettersContext,
+ const overrideIdToNodePathMappingsRef = useContext(
+ OverrideIdToNodePathMappingsRefContext,
);
const propStatusesRef = useContext(
Internals.VisualModePropStatusesRefContext,
@@ -50,6 +51,8 @@ export const useDeleteTimelineItems = () => {
} = currentSelection.current;
const selectedItems = selectedItemsOverride ?? currentSelectedItems;
const sequences = sequencesRef.current;
+ const overrideIdToNodePathMappings =
+ overrideIdToNodePathMappingsRef.current;
const propStatuses = propStatusesRef.current;
const timelinePosition = getCurrentFrame();
if (selectedItems.length === 0) {
@@ -144,7 +147,7 @@ export const useDeleteTimelineItems = () => {
[
confirm,
currentSelection,
- overrideIdToNodePathMappings,
+ overrideIdToNodePathMappingsRef,
previewServerState,
propStatusesRef,
sequencesRef,
diff --git a/packages/studio/src/components/Timeline/use-timeline-keyframe-drag.ts b/packages/studio/src/components/Timeline/use-timeline-keyframe-drag.ts
index e477876556..8bcf83e873 100644
--- a/packages/studio/src/components/Timeline/use-timeline-keyframe-drag.ts
+++ b/packages/studio/src/components/Timeline/use-timeline-keyframe-drag.ts
@@ -17,6 +17,7 @@ import {
startCapturedPointerSession,
} from '../../helpers/pointer-session';
import {TIMELINE_PADDING} from '../../helpers/timeline-layout';
+import {OverrideIdToNodePathMappingsRefContext} from '../SequencePropsSubscriptionProvider';
import {callMoveKeyframes} from './call-move-keyframe';
import {findTrackForNodePathInfo} from './find-track-for-node-path-info';
import {
@@ -477,8 +478,8 @@ export const useTimelineKeyframeDrag = ({
const timelineWidth = useContext(TimelineWidthContext);
const {previewServerState} = useContext(StudioServerConnectionCtx);
const sequencesRef = useContext(Internals.SequenceManagerRefContext);
- const {overrideIdToNodePathMappings} = useContext(
- Internals.OverrideIdsToNodePathsGettersContext,
+ const overrideIdToNodePathMappingsRef = useContext(
+ OverrideIdToNodePathMappingsRefContext,
);
const propStatusesRef = useContext(
Internals.VisualModePropStatusesRefContext,
@@ -539,6 +540,8 @@ export const useTimelineKeyframeDrag = ({
let lastDelta = 0;
const propStatuses = propStatusesRef.current;
const sequences = sequencesRef.current;
+ const overrideIdToNodePathMappings =
+ overrideIdToNodePathMappingsRef.current;
const resolveDragTargets = () => {
if (dragTargets !== null) {
@@ -731,7 +734,7 @@ export const useTimelineKeyframeDrag = ({
frame,
nodePathInfo,
onSelect,
- overrideIdToNodePathMappings,
+ overrideIdToNodePathMappingsRef,
propStatusesRef,
previewServerState,
selectable,
@@ -762,8 +765,8 @@ export const useTimelineEasingKeyframeDrag = ({
const timelineWidth = useContext(TimelineWidthContext);
const {previewServerState} = useContext(StudioServerConnectionCtx);
const sequencesRef = useContext(Internals.SequenceManagerRefContext);
- const {overrideIdToNodePathMappings} = useContext(
- Internals.OverrideIdsToNodePathsGettersContext,
+ const overrideIdToNodePathMappingsRef = useContext(
+ OverrideIdToNodePathMappingsRefContext,
);
const propStatusesRef = useContext(
Internals.VisualModePropStatusesRefContext,
@@ -816,6 +819,8 @@ export const useTimelineEasingKeyframeDrag = ({
let lastDelta = 0;
const propStatuses = propStatusesRef.current;
const sequences = sequencesRef.current;
+ const overrideIdToNodePathMappings =
+ overrideIdToNodePathMappingsRef.current;
const resolveDragTargets = () => {
if (dragTargets !== null) {
@@ -1005,7 +1010,7 @@ export const useTimelineEasingKeyframeDrag = ({
clearDraggedKeyframes,
currentSelection,
onSelect,
- overrideIdToNodePathMappings,
+ overrideIdToNodePathMappingsRef,
propStatusesRef,
previewServerState,
selectable,