Skip to content

🎥 Make videos programmatically with React

Defer ChatGPT annotation metadata until menu activation

Jonny Burgerb4dfc6d42680
diff --git a/packages/studio/src/components/InspectorOpenInEditor.tsx b/packages/studio/src/components/InspectorOpenInEditor.tsx
index 1a3b9f69e1..ca65436f61 100644
--- a/packages/studio/src/components/InspectorOpenInEditor.tsx
+++ b/packages/studio/src/components/InspectorOpenInEditor.tsx
@@ -225,7 +225,7 @@ export const InspectorOpenInEditor: React.FC<{
'[aria-label="Inspector source location"]',
) ?? null,
initialComment: null,
- metadata: {
+ getMetadata: () => ({
selection: annotationName,
...(location?.source
? {
@@ -236,7 +236,7 @@ export const InspectorOpenInEditor: React.FC<{
}) ?? location.source,
}
: {}),
- },
+ }),
})
: []),
];
diff --git a/packages/studio/src/components/SelectedOutlineElement.tsx b/packages/studio/src/components/SelectedOutlineElement.tsx
index f5de3d1df7..a61efbab59 100644
--- a/packages/studio/src/components/SelectedOutlineElement.tsx
+++ b/packages/studio/src/components/SelectedOutlineElement.tsx
@@ -13,7 +13,6 @@ import {
openInCodingAgent as launchCodingAgent,
openOriginalPositionInEditor,
} from '../helpers/open-in-editor';
-import {getSequenceAnnotationAttributes} from '../helpers/sequence-annotation';
import {SetSelectedModalContext} from '../state/modals';
import {Transform3DModeStateContext} from '../state/transform-3d-mode';
import {useConfirmationDialog} from './ConfirmationDialog';
@@ -46,7 +45,6 @@ import {
} from './Timeline/TimelineSelection';
import {getOriginalLocationFromStack} from './Timeline/TimelineStack/get-stack';
import {useDeleteTimelineItems} from './Timeline/use-delete-timeline-items';
-import {useResolvedStack} from './Timeline/use-resolved-stack';
import {
useDefaultCodingAgentInfo,
useEditorOpening,
@@ -124,9 +122,6 @@ const SelectedOutlineElementUnmemoized: React.FC<
getLatestTargetByKey,
layoutTarget,
});
- const annotationLocation = useResolvedStack(
- layoutTarget?.sequence.getStack() ?? null,
- );
const resolveOriginalLocation = React.useCallback(
async (resolveTarget: SelectedOutlineTarget) => {
@@ -469,15 +464,6 @@ const SelectedOutlineElementUnmemoized: React.FC<
return (
<>
<SelectedOutlinePolygon
- annotationAttributes={
- layoutTarget
- ? getSequenceAnnotationAttributes({
- sequence: layoutTarget.sequence,
- location: annotationLocation,
- surface: 'outline',
- })
- : null
- }
compositionHeight={compositionHeight}
compositionWidth={compositionWidth}
containsSelection={layoutTarget?.containsSelection === true}
diff --git a/packages/studio/src/components/SelectedOutlinePolygon.tsx b/packages/studio/src/components/SelectedOutlinePolygon.tsx
index ae1929cc3f..4decf78703 100644
--- a/packages/studio/src/components/SelectedOutlinePolygon.tsx
+++ b/packages/studio/src/components/SelectedOutlinePolygon.tsx
@@ -10,7 +10,6 @@ import {
import {createDragAwareDoubleClickTracker} from '../helpers/drag-aware-double-click';
import {isStudioInteractivityEnabled} from '../helpers/interactivity-enabled';
import {isMac} from '../helpers/is-mac';
-import type {getSequenceAnnotationAttributes} from '../helpers/sequence-annotation';
import {EditorShowGuidesContext} from '../state/editor-guides';
import {EditorSnappingContext} from '../state/editor-snapping';
import {
@@ -60,9 +59,6 @@ export const SELECTED_OUTLINE_KEY_ATTR =
'data-remotion-studio-selected-outline-key';
const SelectedOutlinePolygonUnmemoized: React.FC<{
- readonly annotationAttributes: ReturnType<
- typeof getSequenceAnnotationAttributes
- > | null;
readonly compositionHeight: number;
readonly compositionWidth: number;
readonly containsSelection: boolean;
@@ -93,7 +89,6 @@ const SelectedOutlinePolygonUnmemoized: React.FC<{
readonly showSelectedOutline: boolean;
readonly translateWithCommandKey: boolean;
}> = ({
- annotationAttributes,
compositionHeight,
compositionWidth,
containsSelection,
@@ -440,7 +435,6 @@ const SelectedOutlinePolygonUnmemoized: React.FC<{
return (
<CanvasOutlinePolygon
ref={polygonRef}
- {...annotationAttributes}
{...{
[PREVENT_CLEAR_SELECTION_ON_POINTER_DOWN_ATTR]: 'true',
[SELECTED_OUTLINE_KEY_ATTR]: outline.key,
diff --git a/packages/studio/src/components/SelectedOutlineRenderer.tsx b/packages/studio/src/components/SelectedOutlineRenderer.tsx
index ccf36bb548..8853900738 100644
--- a/packages/studio/src/components/SelectedOutlineRenderer.tsx
+++ b/packages/studio/src/components/SelectedOutlineRenderer.tsx
@@ -232,7 +232,6 @@ const SelectedOutlineRendererUnmemoized: React.FC<{
return (
<svg
ref={overlayRef}
- {...{'oai-annotation-container': ''}}
style={outlineContainer}
width="100%"
height="100%"
diff --git a/packages/studio/src/components/Timeline/TimelineEffectItem.tsx b/packages/studio/src/components/Timeline/TimelineEffectItem.tsx
index 7c24d0afe5..9a09818610 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectItem.tsx
@@ -250,7 +250,7 @@ export const TimelineEffectItem: React.FC<{
id: 'annotate-effect',
getTarget: () => annotationTarget.current,
initialComment: markupSkillAvailable ? '$remotion-markup' : null,
- metadata: {
+ getMetadata: () => ({
layer: nodePath.nodePath.join('.'),
layerKeys: JSON.stringify(nodePath.sequenceKeys),
effect: label,
@@ -260,7 +260,7 @@ export const TimelineEffectItem: React.FC<{
location: validatedLocation,
root: window.remotion_cwd,
}) ?? validatedLocation.source,
- },
+ }),
}),
];
diff --git a/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx b/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
index a8c4377ff5..ec55f24a7f 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
@@ -609,7 +609,7 @@ export const TimelineEffectPropItem: React.FC<{
id: 'annotate-effect-property',
getTarget: () => annotationTarget.current,
initialComment: markupSkillAvailable ? '$remotion-markup' : null,
- metadata: {
+ getMetadata: () => ({
layer: nodePath.nodePath.join('.'),
layerKeys: JSON.stringify(nodePath.sequenceKeys),
effectIndex: field.effectIndex,
@@ -622,7 +622,7 @@ export const TimelineEffectPropItem: React.FC<{
location: validatedLocation,
root: window.remotion_cwd,
}) ?? validatedLocation.source,
- },
+ }),
}),
{
type: 'divider',
diff --git a/packages/studio/src/components/Timeline/TimelineList.tsx b/packages/studio/src/components/Timeline/TimelineList.tsx
index 9d6ddaa0a5..356f6c87f5 100644
--- a/packages/studio/src/components/Timeline/TimelineList.tsx
+++ b/packages/studio/src/components/Timeline/TimelineList.tsx
@@ -232,10 +232,7 @@ export const TimelineList: React.FC = () => {
}, [rows, virtualItems]);
return (
- <div
- style={{...container, height: tracksEnd}}
- {...{'oai-annotation-container': ''}}
- >
+ <div style={{...container, height: tracksEnd}}>
<style>{`.remotion-timeline-sequence-name-measure::before {
content: attr(data-name);
display: block;
diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsx
index b4cf94513c..5308d411d5 100644
--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx
@@ -11,7 +11,6 @@ import React, {
} from 'react';
import type {
_InternalTypes,
- ResolvedStackLocation,
SequencePropsSubscriptionKey,
TSequence,
} from 'remotion';
@@ -40,7 +39,6 @@ import {getTimelineSequenceLayout} from '../../helpers/get-timeline-sequence-lay
import type {SequenceNodePathInfo} from '../../helpers/get-timeline-sequence-sort-key';
import {isStudioInteractivityEnabled} from '../../helpers/interactivity-enabled';
import {isVideoWithLastFrameHold} from '../../helpers/is-video-with-last-frame-hold';
-import {getSequenceAnnotationAttributes} from '../../helpers/sequence-annotation';
import {getStudioShowPremounting} from '../../helpers/studio-runtime-config';
import {
getTimelineLayerHeight,
@@ -328,7 +326,6 @@ const TimelineSequenceBar: React.FC<{
readonly labelOffset: number;
readonly hasCaptionsSchema: boolean;
readonly connectedComposition: _InternalTypes['AnyComposition'] | null;
- readonly annotationLocation: ResolvedStackLocation | null;
readonly activeTrimEdge: 'left' | 'right' | null;
readonly leftTrimHighlight: {
readonly left: number;
@@ -372,7 +369,6 @@ const TimelineSequenceBar: React.FC<{
connectedComposition,
activeTrimEdge,
leftTrimHighlight,
- annotationLocation,
displayDurationInFrames,
selectionBounds,
premount,
@@ -655,11 +651,6 @@ const TimelineSequenceBar: React.FC<{
<div
ref={ref}
role="group"
- {...getSequenceAnnotationAttributes({
- sequence: s,
- location: annotationLocation,
- surface: 'layer',
- })}
{...{[TIMELINE_MARQUEE_ITEM_ATTR]: true}}
style={actualStyle}
aria-label={s.displayName}
@@ -1477,7 +1468,6 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
naturalMediaDuration,
maxMediaDuration,
effectiveMaxMediaDuration,
- originalLocation,
validatedLocation,
nodePath,
fromCanUpdate,
@@ -1554,7 +1544,6 @@ const TimelineSequenceLayoutInner: React.FC<{
naturalMediaDuration,
maxMediaDuration,
effectiveMaxMediaDuration,
- originalLocation,
validatedLocation,
nodePath,
fromCanUpdate,
@@ -1881,7 +1870,6 @@ const TimelineSequenceLayoutInner: React.FC<{
)
}
connectedComposition={connectedCompositions[0] ?? null}
- annotationLocation={originalLocation}
activeTrimEdge={activeTrimEdge}
leftTrimHighlight={
visibleLayout.media?.offset === 0 ? visibleLayout.media : null
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
index 222154f7b6..856441b7ce 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
@@ -40,7 +40,6 @@ import {
isPointerSessionRelease,
startDeferredCapturedPointerSession,
} from '../../helpers/pointer-session';
-import {getSequenceAnnotationAttributes} from '../../helpers/sequence-annotation';
import {getStudioKeyboardShortcutsEnabled} from '../../helpers/studio-runtime-config';
import {
getTimelineLayerHeight,
@@ -1756,16 +1755,11 @@ const TimelineSequenceItemInner: React.FC<{
trackRow
);
- const annotatedTrackRow = (
+ const trackRowWithDropTarget = (
<div
{...{
[LUT_EFFECT_DROP_TARGET_ATTR]: canDropEffect ? 'true' : undefined,
}}
- {...getSequenceAnnotationAttributes({
- sequence,
- location: originalLocation,
- surface: 'track',
- })}
>
{reorderableTrackRow}
</div>
@@ -1775,10 +1769,10 @@ const TimelineSequenceItemInner: React.FC<{
<>
{previewConnected || window.remotion_isReadOnlyStudio ? (
<ContextMenu getItems={getContextMenuItems}>
- {annotatedTrackRow}
+ {trackRowWithDropTarget}
</ContextMenu>
) : (
- annotatedTrackRow
+ trackRowWithDropTarget
)}
{previewConnected &&
isStudioInteractivityEnabled() &&
diff --git a/packages/studio/src/components/Timeline/TimelineTrack.tsx b/packages/studio/src/components/Timeline/TimelineTrack.tsx
index e61222d97b..5f276db384 100644
--- a/packages/studio/src/components/Timeline/TimelineTrack.tsx
+++ b/packages/studio/src/components/Timeline/TimelineTrack.tsx
@@ -1,7 +1,6 @@
import React, {useContext, useMemo} from 'react';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
import type {TimelineTrackData} from '../../helpers/get-timeline-sequence-sort-key';
-import {getSequenceAnnotationAttributes} from '../../helpers/sequence-annotation';
import {
getTimelineLayerHeight,
TIMELINE_ITEM_BORDER_BOTTOM,
@@ -16,14 +15,12 @@ import {
} from './TimelineSelection';
import {TimelineSequence} from './TimelineSequence';
import {TimelineWidthContext} from './TimelineWidthProvider';
-import {useResolvedStack} from './use-resolved-stack';
const emptyConnectedCompositions = [] as const;
const TimelineTrackUnmemoized: React.FC<{
readonly track: TimelineTrackData;
}> = ({track}) => {
- const annotationLocation = useResolvedStack(track.sequence.getStack());
const {getIsExpanded} = useContext(ExpandedTracksGetterContext);
const {previewServerState} = useContext(StudioServerConnectionCtx);
const previewServerConnected = previewServerState.type === 'connected';
@@ -55,14 +52,7 @@ const TimelineTrackUnmemoized: React.FC<{
return (
<div onPointerEnter={onPointerEnter} onPointerLeave={onPointerLeave}>
- <div
- style={layerStyle}
- {...getSequenceAnnotationAttributes({
- sequence: track.sequence,
- location: annotationLocation,
- surface: 'track',
- })}
- >
+ <div style={layerStyle}>
{rowHighlightBackground && timelineWidth !== null ? (
<div
style={getTimelineSelectedTrackHighlightStyle(
diff --git a/packages/studio/src/components/Timeline/TimelineTracks.tsx b/packages/studio/src/components/Timeline/TimelineTracks.tsx
index 0450bd3231..2e0b0a6f2e 100644
--- a/packages/studio/src/components/Timeline/TimelineTracks.tsx
+++ b/packages/studio/src/components/Timeline/TimelineTracks.tsx
@@ -93,7 +93,7 @@ const TimelineTracksInner: React.FC<{
}, []);
return (
- <div style={timelineStyle} {...{'oai-annotation-container': ''}}>
+ <div style={timelineStyle}>
<div style={{...content, height: tracksEnd}}>
{virtualItems.map((virtualItem) => {
const {sceneRange, track, items, auxiliaryRows, auxiliaryRowOffsets} =
diff --git a/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts b/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts
index 7fe1d72b2d..d61d4fd285 100644
--- a/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts
+++ b/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts
@@ -356,10 +356,11 @@ export const getSequenceContextMenuItems = (
contextMenuTarget,
]),
initialComment: null,
- metadata: getSequenceAnnotationMetadata({
- sequence,
- location: originalLocation,
- }),
+ getMetadata: () =>
+ getSequenceAnnotationMetadata({
+ sequence,
+ location: originalLocation,
+ }),
}),
assetLinkInfo
? {
diff --git a/packages/studio/src/components/composition-menu-items.ts b/packages/studio/src/components/composition-menu-items.ts
index e707926801..041a42048d 100644
--- a/packages/studio/src/components/composition-menu-items.ts
+++ b/packages/studio/src/components/composition-menu-items.ts
@@ -450,10 +450,10 @@ export const getCompositionMenuItems = ({
),
),
initialComment: null,
- metadata: {
+ getMetadata: () => ({
composition: composition.id,
...(fileLocation ? {source: fileLocation} : {}),
- },
+ }),
})
: []),
{
diff --git a/packages/studio/src/components/get-annotate-with-chatgpt-menu-item.ts b/packages/studio/src/components/get-annotate-with-chatgpt-menu-item.ts
index c9b21a23ff..22f9015af7 100644
--- a/packages/studio/src/components/get-annotate-with-chatgpt-menu-item.ts
+++ b/packages/studio/src/components/get-annotate-with-chatgpt-menu-item.ts
@@ -6,12 +6,12 @@ export const getAnnotateWithChatGPTMenuItems = ({
id,
getTarget,
initialComment,
- metadata,
+ getMetadata,
}: {
readonly id: string;
readonly getTarget: () => Element | null;
readonly initialComment: string | null;
- readonly metadata: Record<string, string | number>;
+ readonly getMetadata: () => Record<string, string | number>;
}): ComboboxValue[] => {
if (window.remotion_isReadOnlyStudio || getCodexAnnotation() === null) {
return [];
@@ -26,7 +26,11 @@ export const getAnnotateWithChatGPTMenuItems = ({
leftItem: null,
disabled: false,
onClick: () => {
- requestCodexAnnotation({target: getTarget(), initialComment, metadata});
+ requestCodexAnnotation({
+ target: getTarget(),
+ initialComment,
+ metadata: getMetadata(),
+ });
},
quickSwitcherLabel: null,
subMenu: null,
diff --git a/packages/studio/src/helpers/sequence-annotation.ts b/packages/studio/src/helpers/sequence-annotation.ts
index 712af224ea..85cf8f1fbd 100644
--- a/packages/studio/src/helpers/sequence-annotation.ts
+++ b/packages/studio/src/helpers/sequence-annotation.ts
@@ -38,26 +38,3 @@ export const getSequenceAnnotationMetadata = ({
return metadata;
};
-
-export const getSequenceAnnotationAttributes = ({
- sequence,
- location,
- surface,
-}: {
- readonly sequence: TSequence;
- readonly location: ResolvedStackLocation | null;
- readonly surface: 'outline' | 'layer' | 'track';
-}) => {
- const metadata = getSequenceAnnotationMetadata({sequence, location});
- return {
- 'data-remotion-annotation-surface': surface,
- 'data-remotion-layer': metadata.layer,
- 'data-remotion-sequence-type': sequence.type,
- 'data-remotion-from': metadata.from,
- 'data-remotion-duration': metadata.duration,
- 'data-remotion-source': metadata.source,
- 'data-remotion-line': metadata.line,
- 'oai-annotatable': metadata.layer,
- 'oai-annotation-metadata': JSON.stringify(metadata),
- };
-};