🎥 Make videos programmatically with React
Select added effects in Studio
JonnyBurger7a9ca81975cb
diff --git a/packages/browser-studio/src/browser-studio-operations.ts b/packages/browser-studio/src/browser-studio-operations.tsindex 8e1d8b75d3..869304212f 100644--- a/packages/browser-studio/src/browser-studio-operations.ts+++ b/packages/browser-studio/src/browser-studio-operations.ts@@ -1120,7 +1120,17 @@ export const createBrowserStudioOperations = ({result.changes,),});- return {success: true};+ return {+ success: true,+ ...(request.includeInsertedEffect+ ? {+ insertedEffect: {+ effectIndex: result.insertedEffect.effectIndex,+ nodePath: result.insertedEffect.nodePath,+ },+ }+ : {}),+ };} catch (error) {return getStructuredError(error);}diff --git a/packages/studio-server/src/preview-server/routes/add-effect.ts b/packages/studio-server/src/preview-server/routes/add-effect.tsindex 8a49f6ce99..c977412b65 100644--- a/packages/studio-server/src/preview-server/routes/add-effect.ts+++ b/packages/studio-server/src/preview-server/routes/add-effect.ts@@ -32,6 +32,7 @@ export const addEffectHandler: ApiHandler<effectImportPath,effectConfig,clientId,+ includeInsertedEffect,},remotionRoot,logLevel,@@ -106,6 +107,14 @@ export const addEffectHandler: ApiHandler<return {success: true,+ ...(includeInsertedEffect+ ? {+ insertedEffect: {+ effectIndex: result.insertedEffect.effectIndex,+ nodePath: result.insertedEffect.nodePath,+ },+ }+ : {}),};} catch (err) {return {diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.tsindex 5caf89f89b..fae2351e0a 100644--- a/packages/studio-shared/src/api-requests.ts+++ b/packages/studio-shared/src/api-requests.ts@@ -576,11 +576,16 @@ export type AddEffectRequest = {effectImportPath: string;effectConfig: EffectConfig;clientId: string;+ includeInsertedEffect?: boolean;};export type AddEffectResponse =| {success: true;+ insertedEffect?: {+ effectIndex: number;+ nodePath: SequencePropsSubscriptionKey['nodePath'];+ };}| {success: false;diff --git a/packages/studio/src/components/EffectPickerModal.tsx b/packages/studio/src/components/EffectPickerModal.tsxindex 3890ca09b8..77bd6d1d80 100644--- a/packages/studio/src/components/EffectPickerModal.tsx+++ b/packages/studio/src/components/EffectPickerModal.tsx@@ -246,10 +246,17 @@ const EffectPickerContent: React.FC<{clientId: state.clientId,effect: item.effect,fileName: state.fileName,- nodePath: state.nodePath,+ nodePathInfo: state.nodePathInfo,+ selectItems: state.selectItems,});},- [setSelectedModal, state.clientId, state.fileName, state.nodePath],+ [+ setSelectedModal,+ state.clientId,+ state.fileName,+ state.nodePathInfo,+ state.selectItems,+ ],);const onArrowDown = useCallback(() => {diff --git a/packages/studio/src/components/InspectorSequenceSection.tsx b/packages/studio/src/components/InspectorSequenceSection.tsxindex 428c2d756f..4250bd1c54 100644--- a/packages/studio/src/components/InspectorSequenceSection.tsx+++ b/packages/studio/src/components/InspectorSequenceSection.tsx@@ -327,7 +327,8 @@ export const InspectorSequenceSection: React.FC<{includeTextContent: true,includeSourceControls: true,});- const {inspectorRevealRequest, selectedItems} = useTimelineSelection();+ const {inspectorRevealRequest, selectedItems, selectItems} =+ useTimelineSelection();const selectedEffect =selectedItems.length === 1 &&(selectedItems[0].type === 'sequence-effect' ||@@ -757,14 +758,16 @@ export const InspectorSequenceSection: React.FC<{type: 'add-effect',clientId: previewServerState.clientId,fileName: validatedLocation.source,- nodePath: nodePathInfo.sequenceSubscriptionKey,+ nodePathInfo,+ selectItems,});}, [canAddEffect,- nodePathInfo.sequenceSubscriptionKey,+ nodePathInfo,previewServerState,setAdditionalSectionExpanded,setSelectedModal,+ selectItems,validatedLocation.source,]);diff --git a/packages/studio/src/components/SelectedOutlineElement.tsx b/packages/studio/src/components/SelectedOutlineElement.tsxindex 9f3d9c9d34..e6e8a9efe4 100644--- a/packages/studio/src/components/SelectedOutlineElement.tsx+++ b/packages/studio/src/components/SelectedOutlineElement.tsx@@ -41,6 +41,7 @@ import {getTimelineSequenceSelectionKey,type TimelineSelection,type TimelineSelectionInteraction,+ useTimelineSelection,} from './Timeline/TimelineSelection';import {getOriginalLocationFromStack} from './Timeline/TimelineStack/get-stack';import {useDeleteTimelineItems} from './Timeline/use-delete-timeline-items';@@ -114,6 +115,7 @@ const SelectedOutlineElementUnmemoized: React.FC<const selectComposition = useSelectComposition();const {compositions} = useContext(Internals.CompositionManager);const {setSelectedModal} = useContext(SetSelectedModalContext);+ const {selectItems} = useTimelineSelection();const {setManuallyEnabled} = useContext(Transform3DModeStateContext);const {controlTarget, getLayoutTarget, getTarget, hovered, onHoverChange} =useSelectedOutlineControlTarget({@@ -353,7 +355,8 @@ const SelectedOutlineElementUnmemoized: React.FC<type: 'add-effect',clientId: previewServerState.clientId,fileName: nodePath.absolutePath,- nodePath,+ nodePathInfo: contextMenuTarget.nodePathInfo,+ selectItems,});},quickSwitcherLabel: null,@@ -445,6 +448,7 @@ const SelectedOutlineElementUnmemoized: React.FC<resolveOriginalLocation,setManuallyEnabled,selectAsset,+ selectItems,setSelectedModal,setPropStatuses,outline.path,diff --git a/packages/studio/src/components/SelectedOutlinePolygon.tsx b/packages/studio/src/components/SelectedOutlinePolygon.tsxindex 6deb81e076..4b493c3b5e 100644--- a/packages/studio/src/components/SelectedOutlinePolygon.tsx+++ b/packages/studio/src/components/SelectedOutlinePolygon.tsx@@ -59,6 +59,7 @@ import type {TimelineSelection,TimelineSelectionInteraction,} from './Timeline/TimelineSelection';+import {useTimelineSelection} from './Timeline/TimelineSelection';const {CanvasOutlinePolygon, handleCanvasOutlinePointerDown} = CanvasInternals;@@ -132,6 +133,7 @@ const SelectedOutlinePolygonUnmemoized: React.FC<{const {editorSnapping} = useContext(EditorSnappingContext);const {editorShowGuides, guidesList} = useContext(EditorShowGuidesContext);const polygonRef = useRef<SVGPolygonElement>(null);+ const {selectItems} = useTimelineSelection();const [effectDropHovered, setEffectDropHovered] = useState(false);const visible = showSelectedOutline || hovered;const getEffectDropTarget = React.useCallback(() => {@@ -151,7 +153,7 @@ const SelectedOutlinePolygonUnmemoized: React.FC<{return {clientId: previewServerState.clientId,fileName: nodePath.absolutePath,- nodePath,+ nodePathInfo: target.nodePathInfo,};}, [getLayoutTarget, previewServerState]);@@ -558,11 +560,12 @@ const SelectedOutlinePolygonUnmemoized: React.FC<{await addEffectFromDragData({dragData,fileName: effectDrop.fileName,- nodePath: effectDrop.nodePath,+ nodePathInfo: effectDrop.nodePathInfo,clientId: effectDrop.clientId,+ selectItems,});},- [getEffectDropTarget],+ [getEffectDropTarget, selectItems],);return (diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsxindex fda85b4e61..f5617eaf60 100644--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx@@ -29,7 +29,10 @@ import {type GetEffectDragOverrides,type PropStatuses,} from 'remotion';-import {canUseKeyframeOperations} from '../../helpers/browser-studio-operations';+import {+ canUseEffectOperations,+ canUseKeyframeOperations,+} from '../../helpers/browser-studio-operations';import {StudioServerConnectionCtx} from '../../helpers/client-id';import {BACKGROUND,@@ -984,6 +987,7 @@ export const TimelineSelectionProvider: React.FC<{(previewServerState.type === 'connected' ||window.remotion_isReadOnlyStudio);const keyframeOperationsAvailable = canUseKeyframeOperations();+ const effectOperationsAvailable = canUseEffectOperations();const selectionController = useCanvasSelectionController();const selectionState = useCanvasSelection(selectionController);const selectionScope = useRef<string | null>(null);@@ -1018,8 +1022,9 @@ export const TimelineSelectionProvider: React.FC<{canSelect &&(!window.remotion_isReadOnlyStudio ||keyframeOperationsAvailable ||+ (effectOperationsAvailable && item.type === 'sequence-effect') ||item.type === 'sequence'),- [canSelect, keyframeOperationsAvailable],+ [canSelect, effectOperationsAvailable, keyframeOperationsAvailable],);const availableSelectionState =diff --git a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsxindex 9050e5555c..b699e0ee76 100644--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx@@ -107,6 +107,7 @@ import {type TimelineSelection,useTimelineRowContainsSelection,useTimelineRowSelection,+ useTimelineSelection,} from './TimelineSelection';import {TimelineSequenceName} from './TimelineSequenceName';import {TIMELINE_TIME_INDICATOR_HEIGHT} from './TimelineTimeIndicators';@@ -343,6 +344,7 @@ const TimelineSequenceItemInner: React.FC<{const deleteTimelineItems = useDeleteTimelineItems();const {onSelect, selectable, selected, selectedItems, selectItem} =useTimelineRowSelection(nodePathInfo);+ const {selectItems} = useTimelineSelection();const selectedSequenceNodePathInfos = useMemo(() => {if (!selected ||@@ -1109,7 +1111,7 @@ const TimelineSequenceItemInner: React.FC<{if (!canAddEffect ||previewServerState.type !== 'connected' ||- !nodePath ||+ nodePathInfo === null ||!validatedLocation?.source) {return;@@ -1119,13 +1121,15 @@ const TimelineSequenceItemInner: React.FC<{type: 'add-effect',clientId: previewServerState.clientId,fileName: validatedLocation.source,- nodePath,+ nodePathInfo,+ selectItems,});}, [canAddEffect,- nodePath,+ nodePathInfo,previewServerState,setSelectedModal,+ selectItems,validatedLocation?.source,]);@@ -1412,7 +1416,7 @@ const TimelineSequenceItemInner: React.FC<{if (!canDropEffect ||previewServerState.type !== 'connected' ||- nodePath === null ||+ nodePathInfo === null ||validatedLocation === null ||!hasEffectDragType(e.dataTransfer)) {@@ -1438,11 +1442,18 @@ const TimelineSequenceItemInner: React.FC<{await addEffectFromDragData({dragData,fileName: validatedLocation.source,- nodePath,+ nodePathInfo,clientId: previewServerState.clientId,+ selectItems,});},- [canDropEffect, nodePath, previewServerState, validatedLocation],+ [+ canDropEffect,+ nodePathInfo,+ previewServerState,+ selectItems,+ validatedLocation,+ ],);const trackRow = (diff --git a/packages/studio/src/components/effect-drag-and-drop.ts b/packages/studio/src/components/effect-drag-and-drop.tsindex 50f8d12c57..ffc59b9257 100644--- a/packages/studio/src/components/effect-drag-and-drop.ts+++ b/packages/studio/src/components/effect-drag-and-drop.ts@@ -6,11 +6,12 @@ import {type EffectDefinition,getRequiredPackageForEffectImportPath,} from '@remotion/studio-shared';-import type {SequencePropsSubscriptionKey} from 'remotion';import {getBrowserStudioEffectOperations} from '../helpers/browser-studio-operations';+import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';import {installRequiredPackages} from '../helpers/install-required-package';import {addEffect} from './effect-operations-api';import {showNotification} from './Notifications/NotificationCenter';+import type {useTimelineSelection} from './Timeline/TimelineSelection';export const hasEffectDragType = (dataTransfer: DataTransfer) => {return (@@ -34,18 +35,21 @@ export const addEffectFromDragData = ({clientId,dragData,fileName,- nodePath,+ nodePathInfo,+ selectItems,}: {readonly clientId: string;readonly dragData: EffectDragData;readonly fileName: string;- readonly nodePath: SequencePropsSubscriptionKey;+ readonly nodePathInfo: SequenceNodePathInfo;+ readonly selectItems: ReturnType<typeof useTimelineSelection>['selectItems'];}) => {return addEffectToSequence({clientId,effect: dragData.effect,fileName,- nodePath,+ nodePathInfo,+ selectItems,});};@@ -53,12 +57,14 @@ export const addEffectToSequence = async ({clientId,effect,fileName,- nodePath,+ nodePathInfo,+ selectItems,}: {readonly clientId: string;readonly effect: EffectDefinition;readonly fileName: string;- readonly nodePath: SequencePropsSubscriptionKey;+ readonly nodePathInfo: SequenceNodePathInfo;+ readonly selectItems: ReturnType<typeof useTimelineSelection>['selectItems'];}) => {try {const requiredPackage = getRequiredPackageForEffectImportPath(@@ -72,16 +78,39 @@ export const addEffectToSequence = async ({const result = await addEffect({fileName,- sequenceNodePath: nodePath,+ sequenceNodePath: nodePathInfo.sequenceSubscriptionKey,effectName: effect.name,effectImportPath: effect.importPath,effectConfig: effect.config,clientId,+ includeInsertedEffect: true,});if (!result.success) {showNotification(result.reason, 4000);+ return;}++ selectItems(+ [+ {+ type: 'sequence-effect',+ nodePathInfo: {+ ...nodePathInfo,+ sequenceSubscriptionKey: {+ ...nodePathInfo.sequenceSubscriptionKey,+ nodePath:+ result.insertedEffect?.nodePath ??+ nodePathInfo.sequenceSubscriptionKey.nodePath,+ },+ },+ i:+ result.insertedEffect?.effectIndex ??+ nodePathInfo.sequenceSubscriptionKey.effectKeys.length,+ },+ ],+ {revealInInspector: true},+ );} catch (err) {showNotification((err as Error).message, 4000);}diff --git a/packages/studio/src/state/modals.ts b/packages/studio/src/state/modals.tsindex 9d4c970cee..a697a0d505 100644--- a/packages/studio/src/state/modals.ts+++ b/packages/studio/src/state/modals.ts@@ -33,6 +33,8 @@ import type {StaticFile} from '../api/get-static-files';import type {CompType} from '../components/NewComposition/DuplicateComposition';import type {QuickSwitcherMode} from '../components/QuickSwitcher/NoResults';import type {RenderType} from '../components/RenderModal/RenderModalAdvanced';+import type {useTimelineSelection} from '../components/Timeline/TimelineSelection';+import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';export type WebRenderModalState = {type: 'web-render';@@ -136,8 +138,9 @@ export type SvgImportDialogState = {export type AddEffectModalState = {type: 'add-effect';fileName: string;- nodePath: SequencePropsSubscriptionKey;+ nodePathInfo: SequenceNodePathInfo;clientId: string;+ selectItems: ReturnType<typeof useTimelineSelection>['selectItems'];};export type AssetSelectionModalState = {