🎥 Make videos programmatically with React
Merge origin/main into codex/sequence-freeze-prop
Jonny Burgerc80400c78848
diff --cc packages/core/src/Img.tsxindex 0ea7a3939a,4ce33e1d70..f6b9bb1845--- a/packages/core/src/Img.tsx+++ b/packages/core/src/Img.tsx@@@ -340,11 -337,8 +340,9 @@@ const NativeImgInner: React.FC<NativeImlayout="none"from={from ?? 0}durationInFrames={durationInFrames ?? Infinity}+ freeze={freeze}_remotionInternalStack={stack}- _remotionInternalDocumentationLink={- name === undefined ? 'https://www.remotion.dev/docs/img' : undefined- }+ _remotionInternalDocumentationLink="https://www.remotion.dev/docs/img"_remotionInternalIsMedia={{type: 'image', src}}name={name ?? '<Img>'}_experimentalControls={controls}diff --cc packages/core/src/loop/index.tsxindex 166dc4f100,e54fe2e460..9db94aeb0c--- a/packages/core/src/loop/index.tsx+++ b/packages/core/src/loop/index.tsx@@@ -14,7 -14,7 +14,7 @@@ export type LoopProps =readonly name?: string;readonly children: React.ReactNode;} & LayoutAndStyle &-- Pick<SequenceProps, 'showInTimeline'>;++ Pick<SequenceProps, 'freeze' | 'showInTimeline'>;type LoopContextType = {iteration: number;@@@ -37,6 -37,6 +37,7 @@@ export const Loop: React.FC<LoopProps>durationInFrames,times = Infinity,children,++ freeze,name,showInTimeline,...props@@@ -96,11 -96,9 +97,10 @@@durationInFrames={durationInFrames}from={from}name={name ?? '<Loop>'}- _remotionInternalDocumentationLink={- name === undefined ? 'https://www.remotion.dev/docs/loop' : undefined- }+ _remotionInternalDocumentationLink="https://www.remotion.dev/docs/loop"_remotionInternalLoopDisplay={loopDisplay}layout={props.layout}++ freeze={freeze}style={style}showInTimeline={showInTimeline}>diff --cc packages/core/src/sequence-field-schema.tsindex d0ba8f0bc8,45a75fb54f..6443ee9075--- a/packages/core/src/sequence-field-schema.ts+++ b/packages/core/src/sequence-field-schema.ts@@@ -265,14 -278,7 +278,14 @@@ export const fromField =hiddenFromList: true,} as const satisfies SequenceFieldSchema;+export const freezeField = {+ type: 'number',+ default: undefined,+ step: 1,+ hiddenFromList: true,+} as const satisfies SequenceFieldSchema;+- export const sequenceSchema = {+ export const sequenceSchema = extendSchemaWithSequenceName({hidden: hiddenField,showInTimeline: showInTimelineField,from: fromField,@@@ -287,15 -292,14 +300,15 @@@none: {},},},- } as const satisfies SequenceSchema;+ } as const satisfies SequenceSchema);- export const sequenceSchemaWithoutFrom = {+ export const sequenceSchemaWithoutFrom = extendSchemaWithSequenceName({hidden: hiddenField,showInTimeline: showInTimelineField,+ freeze: freezeField,durationInFrames: durationInFramesField,layout: sequenceSchema.layout,- } as const satisfies SequenceSchema;+ } as const satisfies SequenceSchema);export const sequenceSchemaDefaultLayoutNone: SequenceSchema = {...sequenceSchema,diff --cc packages/studio-server/src/test/get-all-schema-keys.test.tsindex 5c5dc88be6,da64b6bc17..4b2ea839e0--- a/packages/studio-server/src/test/get-all-schema-keys.test.ts+++ b/packages/studio-server/src/test/get-all-schema-keys.test.ts@@@ -24,6 -25,6 +25,7 @@@ test('getAllSchemaKeys returns every ke'styleWhilePostmounted','durationInFrames','from',++ 'freeze',].sort(),);});diff --cc packages/studio/src/components/Timeline/TimelineSequenceItem.tsxindex 9f72898998,9a5ee2cd16..8c88978b60--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx@@@ -553,70 -583,234 +586,298 @@@ export const TimelineSequenceItem: Reac: undefined;}, [propStatuses, nodePath]);+ const codeHiddenStatus = propStatusesForOverride?.hidden;+ const codeNameStatus = propStatusesForOverride?.name;++ const isItemHidden = useMemo(() => {+ const propStatus =+ codeHiddenStatus && codeHiddenStatus.status === 'static'+ ? codeHiddenStatus.codeValue+ : undefined;+ const runtimeValue =+ sequence.controls?.currentRuntimeValueDotNotation.hidden;+ const effective = (propStatus ?? runtimeValue) as boolean | undefined;+ return effective ?? false;+ }, [codeHiddenStatus, sequence.controls?.currentRuntimeValueDotNotation]);++ const displayName = useMemo(() => {+ if (+ codeNameStatus &&+ codeNameStatus.status === 'static' &&+ typeof codeNameStatus.codeValue === 'string'+ ) {+ return codeNameStatus.codeValue;+ }++ return sequence.displayName;+ }, [codeNameStatus, sequence.displayName]);++ const onToggleVisibility = useCallback(+ (type: 'enable' | 'disable') => {+ if (+ !sequence.controls ||+ !nodePath ||+ !validatedLocation ||+ !propStatusesForOverride ||+ !codeHiddenStatus ||+ codeHiddenStatus.status !== 'static' ||+ previewServerState.type !== 'connected'+ ) {+ return;+ }++ const newValue = type !== 'enable';+ const {schema} = sequence.controls;++ const fieldSchema = schema.hidden;+ const defaultValue =+ fieldSchema && fieldSchema.type === 'boolean'+ ? JSON.stringify(fieldSchema.default)+ : null;++ saveSequenceProps({+ changes: [+ {+ fileName: validatedLocation.source,+ nodePath,+ fieldKey: 'hidden',+ value: newValue,+ defaultValue,+ schema,+ },+ ],+ setPropStatuses,+ clientId: previewServerState.clientId,+ undoLabel: newValue ? 'Hide sequence' : 'Show sequence',+ redoLabel: newValue ? 'Hide sequence again' : 'Show sequence again',+ });+ },+ [+ codeHiddenStatus,+ propStatusesForOverride,+ nodePath,+ previewServerState,+ sequence.controls,+ setPropStatuses,+ validatedLocation,+ ],+ );++ const outerHeight = useMemo(+ () => getTimelineLayerHeight(sequence.type) + TIMELINE_ITEM_BORDER_BOTTOM,+ [sequence.type],+ );++ const inner: React.CSSProperties = useMemo(() => {+ return {+ height: TIMELINE_LIST_ITEM_ROW_HEIGHT,+ color: 'white',+ fontFamily: 'Arial, Helvetica, sans-serif',+ wordBreak: 'break-all',+ textAlign: 'left',+ flexShrink: 0,+ };+ }, []);++ const rowStyle = useMemo((): React.CSSProperties => {+ return effectDropHovered+ ? {+ ...inner,+ ...effectDropHighlight,+ }+ : inner;+ }, [effectDropHovered, inner]);++ const hasExpandableContent =+ Boolean(sequence.controls) || sequence.effects.length > 0;++ const canToggleVisibility =+ previewConnected &&+ Boolean(sequence.controls) &&+ nodePath !== null &&+ validatedLocation !== null &&+ codeHiddenStatus !== undefined &&+ codeHiddenStatus !== null &&+ codeHiddenStatus.status === 'static';++ const canRenameThisSequence =+ previewServerState.type === 'connected' &&+ !window.remotion_isReadOnlyStudio &&+ Boolean(sequence.controls) &&+ nodePath !== null &&+ validatedLocation !== null &&+ codeNameStatus !== undefined &&+ codeNameStatus !== null &&+ codeNameStatus.status === 'static';++ const canRenameSelectedSequence =+ canRenameThisSequence &&+ selected &&+ selectedItems.length === 1 &&+ selectedItems[0]?.type === 'sequence';++ const onCancelRenaming = useCallback(() => {+ setIsRenaming(false);+ }, []);++ const onSaveName = useCallback(+ async (name: string) => {+ if (+ !canRenameThisSequence ||+ previewServerState.type !== 'connected' ||+ !sequence.controls ||+ !nodePath ||+ !validatedLocation+ ) {+ setIsRenaming(false);+ return;+ }++ if (name === displayName) {+ setIsRenaming(false);+ return;+ }++ const savePromise = saveSequenceProps({+ changes: [+ {+ fileName: validatedLocation.source,+ nodePath,+ fieldKey: 'name',+ value: name,+ defaultValue: null,+ schema: sequence.controls.schema,+ },+ ],+ setPropStatuses,+ clientId: previewServerState.clientId,+ undoLabel: 'Rename sequence',+ redoLabel: 'Rename sequence again',+ });+ setIsRenaming(false);+ await savePromise;+ },+ [+ canRenameThisSequence,+ displayName,+ nodePath,+ previewServerState,+ sequence.controls,+ setPropStatuses,+ validatedLocation,+ ],+ );++ React.useEffect(() => {+ if (!canRenameSelectedSequence || !process.env.KEYBOARD_SHORTCUTS_ENABLED) {+ setIsRenaming(false);+ return;+ }++ const onKeyDown = (e: KeyboardEvent) => {+ if (!isHighestContext) {+ return;+ }++ const commandKey = window.navigator.platform.startsWith('Mac')+ ? e.metaKey+ : e.ctrlKey;++ if (commandKey || e.key.toLowerCase() !== 'enter') {+ return;+ }++ if (+ document.activeElement instanceof HTMLInputElement ||+ document.activeElement instanceof HTMLTextAreaElement+ ) {+ return;+ }++ e.preventDefault();+ e.stopImmediatePropagation();+ setIsRenaming(true);+ };++ window.addEventListener('keydown', onKeyDown, true);++ return () => {+ window.removeEventListener('keydown', onKeyDown, true);+ };+ }, [canRenameSelectedSequence, isHighestContext]);++ const onRenameSequence = useCallback(() => {+ if (!canRenameThisSequence) {+ return;+ }++ setIsRenaming(true);+ }, [canRenameThisSequence]);++ const freezeStatus = propStatusesForOverride?.freeze;+ const isFrozen =+ freezeStatus?.status === 'static' && freezeStatus.codeValue !== undefined;++ const canToggleFreeze =+ previewConnected &&+ Boolean(sequence.controls) &&+ nodePath !== null &&+ validatedLocation !== null &&+ freezeStatus !== undefined &&+ freezeStatus !== null &&+ freezeStatus.status === 'static';++ const onToggleFreezeFrame = useCallback(() => {+ if (+ !canToggleFreeze ||+ !sequence.controls ||+ !nodePath ||+ !validatedLocation ||+ previewServerState.type !== 'connected'+ ) {+ return;+ }++ const rawFreezeFrame = Math.round(+ timelinePosition - sequence.from + sequenceFrameOffset,+ );+ const maxFrame = Number.isFinite(sequence.duration)+ ? Math.max(0, sequence.duration - 1)+ : rawFreezeFrame;+ const freezeFrame = Math.min(Math.max(0, rawFreezeFrame), maxFrame);+ const remove = isFrozen;++ saveSequenceProps({+ changes: [+ {+ fileName: validatedLocation.source,+ nodePath,+ fieldKey: 'freeze',+ value: remove ? undefined : freezeFrame,+ defaultValue: null,+ schema: sequence.controls.schema,+ remove,+ },+ ],+ setPropStatuses,+ clientId: previewServerState.clientId,+ undoLabel: remove ? 'Unfreeze sequence' : 'Freeze sequence',+ redoLabel: remove ? 'Freeze sequence again' : 'Unfreeze sequence again',+ });+ }, [+ canToggleFreeze,+ isFrozen,+ nodePath,+ previewServerState,+ sequence.controls,+ sequence.duration,+ sequence.from,+ sequenceFrameOffset,+ setPropStatuses,+ timelinePosition,+ validatedLocation,+ ]);+const contextMenuValues = useMemo((): ComboboxValue[] => {if (!previewConnected) {return [];@@@ -702,26 -896,26 +963,38 @@@value: 'show-asset',}: null,- documentationLink- ? {- type: 'divider' as const,- id: 'open-component-docs-divider',- }- : null,++ {++ type: 'divider' as const,++ id: 'sequence-source-actions-divider',++ },+ {+ type: 'item' as const,+ id: 'rename-sequence',+ keyHint: 'Enter',+ label: 'Rename...',+ leftItem: null,+ disabled: !canRenameThisSequence,+ onClick: () => {+ onRenameSequence();+ },+ quickSwitcherLabel: null,+ subMenu: null,+ value: 'rename-sequence',+ },+ {+ type: 'item' as const,+ id: 'toggle-freeze-frame',+ keyHint: null,+ label: isFrozen ? 'Unfreeze frame' : 'Freeze frame',+ leftItem: null,+ disabled: !canToggleFreeze,+ onClick: () => {+ onToggleFreezeFrame();+ },+ quickSwitcherLabel: null,+ subMenu: null,+ value: 'toggle-freeze-frame',+ },- documentationLink- ? {- type: 'divider' as const,- id: 'open-component-docs-divider',- }- : null,{type: 'item' as const,id: 'disable-interactivity',@@@ -736,6 -930,6 +1009,10 @@@subMenu: null,value: 'disable-interactivity',},++ {++ type: 'divider' as const,++ id: 'sequence-duplicate-delete-divider',++ },{type: 'item' as const,id: 'duplicate-sequence',@@@ -775,7 -969,8 +1052,9 @@@].filter(NoReactInternals.truthy);}, [assetLinkInfo,+ canOpenInEditor,+ canRenameThisSequence,+ canToggleFreeze,deleteDisabled,disableInteractivityDisabled,duplicateDisabled,@@@ -784,143 -978,13 +1063,13 @@@onDeleteSequenceFromSource,onDisableSequenceInteractivity,onDuplicateSequenceFromSource,+ onRenameSequence,+ onToggleFreezeFrame,- canOpenInEditor,openInEditor,previewConnected,selectAsset,sequence,]);-- const isExpanded =- previewConnected && nodePathInfo !== null && getIsExpanded(nodePathInfo);-- const onToggleExpand = useCallback(() => {- if (nodePathInfo === null) {- return;- }-- toggleTrack(nodePathInfo);- }, [nodePathInfo, toggleTrack]);-- const onShowInEditorDoubleClick = useCallback(- (e: React.MouseEvent<HTMLDivElement>) => {- if (!canOpenInEditor) {- return;- }-- if (isTimelineSelectionModifierEvent(e)) {- e.stopPropagation();- return;- }-- e.stopPropagation();- openInEditor();- },- [canOpenInEditor, openInEditor],- );-- const codeHiddenStatus = propStatusesForOverride?.hidden;-- const isItemHidden = useMemo(() => {- const propStatus =- codeHiddenStatus && codeHiddenStatus.status === 'static'- ? codeHiddenStatus.codeValue- : undefined;- const runtimeValue =- sequence.controls?.currentRuntimeValueDotNotation.hidden;- const effective = (propStatus ?? runtimeValue) as boolean | undefined;- return effective ?? false;- }, [codeHiddenStatus, sequence.controls?.currentRuntimeValueDotNotation]);-- const onToggleVisibility = useCallback(- (type: 'enable' | 'disable') => {- if (- !sequence.controls ||- !nodePath ||- !validatedLocation ||- !propStatusesForOverride ||- !codeHiddenStatus ||- codeHiddenStatus.status !== 'static' ||- previewServerState.type !== 'connected'- ) {- return;- }-- const newValue = type !== 'enable';- const {schema} = sequence.controls;-- const fieldSchema = schema.hidden;- const defaultValue =- fieldSchema && fieldSchema.type === 'boolean'- ? JSON.stringify(fieldSchema.default)- : null;-- saveSequenceProps({- changes: [- {- fileName: validatedLocation.source,- nodePath,- fieldKey: 'hidden',- value: newValue,- defaultValue,- schema,- },- ],- setPropStatuses,- clientId: previewServerState.clientId,- undoLabel: newValue ? 'Hide sequence' : 'Show sequence',- redoLabel: newValue ? 'Hide sequence again' : 'Show sequence again',- });- },- [- codeHiddenStatus,- propStatusesForOverride,- nodePath,- previewServerState,- sequence.controls,- setPropStatuses,- validatedLocation,- ],- );-- const outerHeight = useMemo(- () => getTimelineLayerHeight(sequence.type) + TIMELINE_ITEM_BORDER_BOTTOM,- [sequence.type],- );-- const inner: React.CSSProperties = useMemo(() => {- return {- height: TIMELINE_LIST_ITEM_ROW_HEIGHT,- color: 'white',- fontFamily: 'Arial, Helvetica, sans-serif',- wordBreak: 'break-all',- textAlign: 'left',- flexShrink: 0,- };- }, []);-- const rowStyle = useMemo((): React.CSSProperties => {- return effectDropHovered- ? {- ...inner,- ...effectDropHighlight,- }- : inner;- }, [effectDropHovered, inner]);-- const hasExpandableContent =- Boolean(sequence.controls) || sequence.effects.length > 0;-- const canToggleVisibility =- previewConnected &&- Boolean(sequence.controls) &&- nodePath !== null &&- validatedLocation !== null &&- codeHiddenStatus !== undefined &&- codeHiddenStatus !== null &&- codeHiddenStatus.status === 'static';--const canDropEffect =previewServerState.type === 'connected' &&nodePath !== null &&