Skip to content

🎥 Make videos programmatically with React

Merge remote-tracking branch 'origin/main' into pr-6674

pullfrog[bot]3264c66ded7e
diff --cc packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
index 3315af545d,3c54dacafe..5a968dc92c
--- a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
@@@ -34,41 -31,7 +35,41 @@@ const fieldName: React.CSSProperties =
fontSize: 12,
};
+const fieldLabelRow: React.CSSProperties = {
+ flex: 1,
+ display: 'flex',
+ flexDirection: 'row',
+ alignItems: 'center',
+ gap: 6,
+};
+
+const TimelineFieldRow: React.FC<{
+ readonly field: SchemaFieldInfo;
- readonly canUpdate: boolean | null;
- readonly onSave: (key: string, value: unknown) => void;
- }> = ({field, canUpdate, onSave}) => {
++ readonly propStatus: CanUpdateSequencePropStatus | null;
++ readonly onSave: (key: string, value: unknown) => Promise<void>;
++}> = ({field, propStatus, onSave}) => {
+ const [saving, setSaving] = useState(false);
+
+ const onSavingChange = useCallback((s: boolean) => {
+ setSaving(s);
+ }, []);
+
+ return (
+ <div style={{...fieldRow, height: field.rowHeight}}>
+ <div style={fieldLabelRow}>
+ <span style={fieldName}>{field.key}</span>
+ <TimelineFieldSavingSpinner saving={saving} />
+ </div>
+ <TimelineFieldValue
+ field={field}
- canUpdate={canUpdate}
++ propStatus={propStatus}
+ onSave={onSave}
+ onSavingChange={onSavingChange}
+ />
+ </div>
+ );
+};
+
export const TimelineExpandedSection: React.FC<{
readonly sequence: TSequence;
readonly originalLocation: OriginalPosition | null;
@@@ -121,36 -92,43 +130,38 @@@
);
const onSave = useCallback(
-- (key: string, value: unknown) => {
- if (!canUpdate || !validatedLocation) {
- return;
++ (key: string, value: unknown): Promise<void> => {
+ if (!propStatuses || !validatedLocation) {
- return;
++ return Promise.resolve();
}
- callApi('/api/save-sequence-props', {
+ const status = propStatuses[key];
+ if (!status || !status.canUpdate) {
- return;
++ return Promise.resolve();
+ }
+
- callApi('/api/save-sequence-props', {
++ return callApi('/api/save-sequence-props', {
fileName: validatedLocation.source,
line: validatedLocation.line,
column: validatedLocation.column,
key,
value: JSON.stringify(value),
enumPaths: [],
-- }).catch((err) => {
-- // eslint-disable-next-line no-console
-- console.error('Failed to save sequence prop:', err);
-- });
++ }).then(() => undefined);
},
- [canUpdate, validatedLocation],
+ [propStatuses, validatedLocation],
);
return (
<div style={{...expandedSectionBase, height: expandedHeight}}>
{schemaFields
? schemaFields.map((field) => (
- <div key={field.key} style={{...fieldRow, height: field.rowHeight}}>
- <span style={fieldName}>{field.key}</span>
- <TimelineFieldValue
- field={field}
- propStatus={propStatuses?.[field.key] ?? null}
- onSave={onSave}
- />
- </div>
+ <TimelineFieldRow
+ key={field.key}
+ field={field}
- canUpdate={canUpdate}
++ propStatus={propStatuses?.[field.key] ?? null}
+ onSave={onSave}
+ />
))
: 'No schema'}
</div>
diff --cc packages/studio/src/components/Timeline/TimelineSchemaField.tsx
index 4df97c0c8a,86fbf5b46c..ede14e1952
--- a/packages/studio/src/components/Timeline/TimelineSchemaField.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSchemaField.tsx
@@@ -1,4 -1,5 +1,5 @@@
- import React, {useCallback, useEffect, useRef, useState} from 'react';
+ import type {CanUpdateSequencePropStatus} from '@remotion/studio-shared';
-import React, {useCallback} from 'react';
++import React, {useCallback, useEffect, useState} from 'react';
import type {SchemaFieldInfo} from '../../helpers/timeline-layout';
import {InputDragger} from '../NewComposition/InputDragger';
import {
@@@ -28,44 -28,28 +29,47 @@@ const notEditableBackground: React.CSSP
const TimelineNumberField: React.FC<{
readonly field: SchemaFieldInfo;
- readonly canUpdate: boolean | null;
- readonly onSave: (key: string, value: unknown) => void;
+ readonly canUpdate: boolean;
- readonly onSave: (key: string, value: unknown) => void;
-}> = ({field, canUpdate, onSave}) => {
- const onValueChange = useCallback((_newVal: number) => {
- // No-op during drag; save happens on drag end
++ readonly onSave: (key: string, value: unknown) => Promise<void>;
+ readonly onSavingChange: (saving: boolean) => void;
+}> = ({field, canUpdate, onSave, onSavingChange}) => {
+ const [dragValue, setDragValue] = useState<number | null>(null);
- const dragging = useRef(false);
+
+ const onValueChange = useCallback((newVal: number) => {
- dragging.current = true;
+ setDragValue(newVal);
}, []);
+ useEffect(() => {
+ setDragValue(null);
+ onSavingChange(false);
+ }, [field.currentValue, onSavingChange]);
+
const onValueChangeEnd = useCallback(
(newVal: number) => {
- dragging.current = false;
- if (canUpdate) {
- onSave(field.key, newVal);
+ if (canUpdate && newVal !== field.currentValue) {
+ onSavingChange(true);
- onSave(field.key, newVal);
++ onSave(field.key, newVal).catch(() => {
++ onSavingChange(false);
++ setDragValue(null);
++ });
+ } else {
+ setDragValue(null);
}
},
- [canUpdate, onSave, field.key],
+ [canUpdate, onSave, onSavingChange, field.key, field.currentValue],
);
const onTextChange = useCallback(
(newVal: string) => {
if (canUpdate) {
const parsed = Number(newVal);
- if (!Number.isNaN(parsed)) {
- onSave(field.key, parsed);
+ if (!Number.isNaN(parsed) && parsed !== field.currentValue) {
+ setDragValue(parsed);
+ onSavingChange(true);
- onSave(field.key, parsed);
++ onSave(field.key, parsed).catch(() => {
++ onSavingChange(false);
++ setDragValue(null);
++ });
}
}
},
@@@ -91,14 -75,10 +95,11 @@@
export const TimelineFieldValue: React.FC<{
readonly field: SchemaFieldInfo;
- readonly canUpdate: boolean | null;
- readonly onSave: (key: string, value: unknown) => void;
+ readonly propStatus: CanUpdateSequencePropStatus | null;
- readonly onSave: (key: string, value: unknown) => void;
-}> = ({field, propStatus, onSave}) => {
++ readonly onSave: (key: string, value: unknown) => Promise<void>;
+ readonly onSavingChange: (saving: boolean) => void;
- }> = ({field, canUpdate, onSave, onSavingChange}) => {
- const wrapperStyle: React.CSSProperties | undefined =
- canUpdate === null || canUpdate === false
- ? notEditableBackground
- : undefined;
++}> = ({field, propStatus, onSave, onSavingChange}) => {
+ const canUpdate = propStatus !== null && propStatus.canUpdate;
if (!field.supported) {
return (
@@@ -119,8 -100,18 +121,19 @@@
);
}
+ if (field.typeName === 'number') {
+ return (
+ <TimelineNumberField
+ field={field}
+ canUpdate={canUpdate}
+ onSave={onSave}
++ onSavingChange={onSavingChange}
+ />
+ );
+ }
+
return (
- <span style={{...unsupportedLabel, fontStyle: 'normal', ...wrapperStyle}}>
+ <span style={{...unsupportedLabel, fontStyle: 'normal'}}>
{String(field.currentValue)}
</span>
);