Skip to content

🎥 Make videos programmatically with React

Studio: Keep Wrap action visible with agent fallback

JonnyBurgerf0a4a4c23090
diff --git a/packages/skills/skills/remotion-markup/SKILL.md b/packages/skills/skills/remotion-markup/SKILL.md
index 26e93f61d0..f2caa7443e 100644
--- a/packages/skills/skills/remotion-markup/SKILL.md
+++ b/packages/skills/skills/remotion-markup/SKILL.md
@@ -78,6 +78,18 @@ style={{
}}
```
+## Wrapping an item
+
+For a Studio request such as `Wrap Title (src/MyComp.tsx:42) in <Sequence>`, locate the JSX element at the given source location and make that exact element the wrapper's only direct child. Preserve the selected element, its props, its children, sibling order, and surrounding conditions or iteration. Do not move timing or styling props from the selected element to the wrapper.
+
+Import the requested wrapper and use this shape:
+
+- `AbsoluteFill` and `Sequence` come from `remotion` and need no props merely to wrap the item.
+- `HtmlInCanvas` comes from `remotion`; pass the current composition's `width` and `height` as explicit props.
+- `HtmlInCanvasMotionBlur` comes from `@remotion/motion-blur`; install that package if necessary and pass the current composition's `width` and `height` as explicit props.
+
+Do not wrap an ancestor or every matching component when the source location identifies one JSX expression. If that expression is inside a loop or conditional, wrap the expression in place so its existing runtime behavior is preserved.
+
## Assets
Place assets in the `public/` folder at your project root.
diff --git a/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx b/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx
index d92418130a..e2f79838f3 100644
--- a/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx
+++ b/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx
@@ -120,8 +120,11 @@ const SplitSequenceQuickAction: React.FC<{
const SequenceSourceQuickActions: React.FC<{
readonly selection: Extract<TimelineSelection, {type: 'sequence'}>;
readonly track: TimelineTrackData;
- readonly validatedSource: string;
-}> = ({selection, track, validatedSource}) => {
+ readonly validatedLocation: {
+ readonly source: string;
+ readonly line: number;
+ };
+}> = ({selection, track, validatedLocation}) => {
const timelinePosition = Internals.Timeline.useTimelinePosition();
const {previewServerState} = useContext(StudioServerConnectionCtx);
const {setSelectedModal} = useContext(SetSelectedModalContext);
@@ -148,7 +151,7 @@ const SequenceSourceQuickActions: React.FC<{
sequenceFrameOffset: track.sequenceFrameOffset,
setPropStatuses,
timelinePosition,
- validatedSource,
+ validatedSource: validatedLocation.source,
});
const sourceActionsDisabled =
previewServerState.type !== 'connected' || !isStudioInteractivityEnabled();
@@ -354,6 +357,7 @@ const SequenceSourceQuickActions: React.FC<{
nodePathInfo={selection.nodePathInfo}
sequence={track.sequence}
sourceActionsDisabled={sourceActionsDisabled}
+ sourceLocation={validatedLocation}
/>
<InspectorQuickAction
disabled={sourceActionsDisabled}
@@ -478,7 +482,7 @@ const SequenceExpandedInspector: React.FC<{
<SequenceSourceQuickActions
selection={sequenceSelection}
track={track}
- validatedSource={validatedLocation.source}
+ validatedLocation={validatedLocation}
/>
</InspectorQuickActionsSection>
</CollapsibleInspectorSection>
diff --git a/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx b/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx
index c919562cfc..d87e98364c 100644
--- a/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx
+++ b/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx
@@ -1,12 +1,15 @@
import type {NodeWrapper} from '@remotion/studio-shared';
-import React, {useCallback, useEffect, useMemo, useState} from 'react';
+import React, {useCallback, useContext, useMemo, useState} from 'react';
import {isHtmlInCanvasSupported, useVideoConfig} from 'remotion';
import {LIGHT_TEXT} from '../../helpers/colors';
-import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
-import type {TimelineTrackData} from '../../helpers/get-timeline-sequence-sort-key';
+import type {
+ SequenceNodePathInfo,
+ TimelineTrackData,
+} from '../../helpers/get-timeline-sequence-sort-key';
import {installRequiredPackages} from '../../helpers/install-required-package';
import {CaretDown} from '../../icons/caret';
import {WrapIcon} from '../../icons/wrap';
+import {SetSelectedModalContext} from '../../state/modals';
import {INSPECTOR_PANEL_HORIZONTAL_PADDING} from '../InspectorPanelLayout';
import type {ComboboxValue} from '../NewComposition/ComboBox';
import {showNotification} from '../Notifications/NotificationCenter';
@@ -64,49 +67,19 @@ export const SequenceWrapAction: React.FC<{
readonly nodePathInfo: SequenceNodePathInfo;
readonly sequence: TimelineTrackData['sequence'];
readonly sourceActionsDisabled: boolean;
-}> = ({nodePathInfo, sequence, sourceActionsDisabled}) => {
+ readonly sourceLocation: {
+ readonly source: string;
+ readonly line: number;
+ };
+}> = ({nodePathInfo, sequence, sourceActionsDisabled, sourceLocation}) => {
const {width, height} = useVideoConfig();
+ const {setSelectedModal} = useContext(SetSelectedModalContext);
const nodePathKey = JSON.stringify(nodePathInfo.sequenceSubscriptionKey);
- const [eligibility, setEligibility] = useState<{
- canWrap: boolean;
- canWrapHtmlInCanvas: boolean;
- } | null>(null);
const [busy, setBusy] = useState(false);
- useEffect(() => {
- setEligibility(null);
- if (sourceActionsDisabled) {
- return;
- }
-
- let cancelled = false;
- const nodePath = JSON.parse(
- nodePathKey,
- ) as SequenceNodePathInfo['sequenceSubscriptionKey'];
- wrapNode({
- fileName: nodePath.absolutePath,
- nodePath: nodePath.nodePath,
- wrapper: null,
- width: null,
- height: null,
- })
- .then((result) => {
- if (!cancelled && result.success) {
- setEligibility({
- canWrap: result.canWrap,
- canWrapHtmlInCanvas: result.canWrapHtmlInCanvas,
- });
- }
- })
- .catch(() => undefined);
- return () => {
- cancelled = true;
- };
- }, [nodePathKey, sequence, sourceActionsDisabled]);
-
const onWrap = useCallback(
async (wrapper: NodeWrapper) => {
- if (busy || sourceActionsDisabled || !eligibility?.canWrap) {
+ if (busy || sourceActionsDisabled) {
return;
}
@@ -115,6 +88,34 @@ export const SequenceWrapAction: React.FC<{
nodePathKey,
) as SequenceNodePathInfo['sequenceSubscriptionKey'];
try {
+ const eligibility = await wrapNode({
+ fileName: nodePath.absolutePath,
+ nodePath: nodePath.nodePath,
+ wrapper: null,
+ width: null,
+ height: null,
+ });
+ if (!eligibility.success) {
+ showNotification(eligibility.reason, 4000);
+ return;
+ }
+
+ if (
+ !eligibility.canWrap ||
+ ((wrapper === 'HtmlInCanvas' ||
+ wrapper === 'HtmlInCanvasMotionBlur') &&
+ !eligibility.canWrapHtmlInCanvas)
+ ) {
+ setSelectedModal({
+ type: 'wrap-refactor',
+ displayName:
+ sequence.displayName || sequence.controls?.componentName || null,
+ location: sourceLocation,
+ wrapper,
+ });
+ return;
+ }
+
if (wrapper === 'HtmlInCanvasMotionBlur') {
await installRequiredPackages([
{name: '@remotion/motion-blur', version: null},
@@ -137,7 +138,17 @@ export const SequenceWrapAction: React.FC<{
setBusy(false);
}
},
- [busy, eligibility, height, nodePathKey, sourceActionsDisabled, width],
+ [
+ busy,
+ height,
+ nodePathKey,
+ sequence.controls?.componentName,
+ sequence.displayName,
+ setSelectedModal,
+ sourceActionsDisabled,
+ sourceLocation,
+ width,
+ ],
);
const values = useMemo<ComboboxValue[]>(
@@ -156,9 +167,9 @@ export const SequenceWrapAction: React.FC<{
busy ||
((wrapper === 'HtmlInCanvas' ||
wrapper === 'HtmlInCanvasMotionBlur') &&
- (!eligibility?.canWrapHtmlInCanvas || !isHtmlInCanvasSupported())),
+ !isHtmlInCanvasSupported()),
})),
- [busy, eligibility, onWrap],
+ [busy, onWrap],
);
const segments = useMemo<SegmentedButtonSegment[]>(
@@ -169,7 +180,7 @@ export const SequenceWrapAction: React.FC<{
? `Wrap all ${nodePathInfo.numberOfSequencesWithThisNodePath} instances of this JSX element`
: 'Wrap this JSX element',
buttonId: null,
- disabled: busy,
+ disabled: busy || sourceActionsDisabled,
idleColor: LIGHT_TEXT,
leaveLeftSpace: false,
onOpenChange: null,
@@ -192,12 +203,13 @@ export const SequenceWrapAction: React.FC<{
values,
},
],
- [busy, nodePathInfo.numberOfSequencesWithThisNodePath, values],
+ [
+ busy,
+ nodePathInfo.numberOfSequencesWithThisNodePath,
+ sourceActionsDisabled,
+ values,
+ ],
);
- if (!eligibility?.canWrap || sourceActionsDisabled) {
- return null;
- }
-
return <SegmentedButton segments={segments} style={buttonStyle} />;
};
diff --git a/packages/studio/src/components/Modals.tsx b/packages/studio/src/components/Modals.tsx
index 58eb04cb95..56b3c9fe48 100644
--- a/packages/studio/src/components/Modals.tsx
+++ b/packages/studio/src/components/Modals.tsx
@@ -34,6 +34,7 @@ import {SettingsModal} from './SettingsModal';
import {SvgImportDialog} from './SvgImportDialog';
import {TranscriptionModalWithOptionalWhisper} from './Transcription/TranscriptionModalWithOptionalWhisper';
import {VideoMattingModalWithOptionalPackage} from './VideoMatting/VideoMattingModalWithOptionalPackage';
+import {WrapRefactorModal} from './WrapRefactorModal';
export const Modals: React.FC<{
readonly readOnlyStudio: boolean;
@@ -285,6 +286,9 @@ export const Modals: React.FC<{
{modalContextType && modalContextType.type === 'generate-with-agent' ? (
<GenerateWithAgentModal state={modalContextType} />
) : null}
+ {modalContextType && modalContextType.type === 'wrap-refactor' ? (
+ <WrapRefactorModal state={modalContextType} />
+ ) : null}
{modalContextType && modalContextType.type === 'quick-switcher' && (
<QuickSwitcher
readOnlyStudio={readOnlyStudio}
diff --git a/packages/studio/src/components/WrapRefactorModal.tsx b/packages/studio/src/components/WrapRefactorModal.tsx
new file mode 100644
index 0000000000..80020d3aab
--- /dev/null
+++ b/packages/studio/src/components/WrapRefactorModal.tsx
@@ -0,0 +1,85 @@
+import React, {useContext} from 'react';
+import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';
+import {StudioServerConnectionCtx} from '../helpers/client-id';
+import {LIGHT_TEXT} from '../helpers/colors';
+import {formatFileLocation} from '../helpers/format-file-location';
+import type {ModalState} from '../state/modals';
+import {AgentPrompt} from './AgentPrompt';
+import {getMaxModalHeight, getMaxModalWidth} from './ModalContainer';
+import {ModalHeader} from './ModalHeader';
+import {DismissableModal} from './NewComposition/DismissableModal';
+import {useSettings} from './SettingsContext';
+
+const panelStyle: React.CSSProperties = {
+ borderRadius: 6,
+ display: 'flex',
+ flexDirection: 'column',
+ maxHeight: getMaxModalHeight(800),
+ minWidth: 0,
+ overflow: 'hidden',
+ width: getMaxModalWidth(560),
+};
+
+const container: React.CSSProperties = {
+ minHeight: 0,
+ overflowY: 'auto',
+ padding: 16,
+};
+
+const text: React.CSSProperties = {
+ color: LIGHT_TEXT,
+ fontFamily: 'sans-serif',
+ fontSize: 14,
+ lineHeight: 1.5,
+ marginBottom: 16,
+};
+
+type State = Extract<ModalState, {type: 'wrap-refactor'}>;
+
+export const WrapRefactorModal: React.FC<{readonly state: State}> = ({
+ state,
+}) => {
+ const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const {error, remotionSkillsInfo} = useSettings();
+ const isBrowserStudio = getBrowserStudioOperations() !== null;
+ const canSuggestAgent =
+ !isBrowserStudio &&
+ !window.remotion_isReadOnlyStudio &&
+ previewServerState.type === 'connected' &&
+ remotionSkillsInfo?.skills.some(({name}) => name === 'remotion-markup');
+ const location =
+ formatFileLocation({
+ location: state.location,
+ root: window.remotion_cwd,
+ }) ?? state.location.source;
+ const target = state.displayName
+ ? `${state.displayName} (${location})`
+ : location;
+
+ return (
+ <DismissableModal panelStyle={panelStyle}>
+ <ModalHeader title="Wrap item" />
+ <div style={container}>
+ <div style={text}>
+ Studio could not safely wrap this item in
+ {` <${state.wrapper}>`} with an automated code change.
+ </div>
+ {canSuggestAgent ? (
+ <AgentPrompt
+ availableText="You can wrap it using an agent:"
+ promptDetails={` Wrap ${target} in <${state.wrapper}>`}
+ skillId="remotion-markup"
+ />
+ ) : (
+ <div style={text}>
+ {isBrowserStudio
+ ? 'Agent-assisted refactoring is unavailable in Browser Studio.'
+ : remotionSkillsInfo === null && error === null
+ ? 'Checking whether /remotion-markup is available...'
+ : 'The /remotion-markup Agent Skill is unavailable in this Studio.'}
+ </div>
+ )}
+ </div>
+ </DismissableModal>
+ );
+};
diff --git a/packages/studio/src/state/modals.ts b/packages/studio/src/state/modals.ts
index a697a0d505..2fe18e5703 100644
--- a/packages/studio/src/state/modals.ts
+++ b/packages/studio/src/state/modals.ts
@@ -15,6 +15,7 @@ import type {
CanvasCaptureData,
ElementInstallExpectedFileState,
ElementInstallRequest,
+ NodeWrapper,
RenderDefaults,
} from '@remotion/studio-shared';
import type {
@@ -293,6 +294,15 @@ export type ModalState =
line: number;
} | null;
}
+ | {
+ type: 'wrap-refactor';
+ displayName: string | null;
+ location: {
+ source: string;
+ line: number;
+ };
+ wrapper: NodeWrapper;
+ }
| {
type: 'quick-switcher';
mode: QuickSwitcherMode;