Skip to content

πŸŽ₯ Make videos programmatically with React

`@remotion/studio`: Make Interactive text editable in visual mode (#8669)

Igor Samokhovetsc026c91f8f5f
diff --git a/packages/core/src/Interactive.tsx b/packages/core/src/Interactive.tsx
index a9f9030d09..319f3ea427 100644
--- a/packages/core/src/Interactive.tsx
+++ b/packages/core/src/Interactive.tsx
@@ -5,6 +5,7 @@ import {
baseSchema,
premountSchema,
sequenceSchema,
+ textContentSchema,
textSchema,
transformSchema,
type InteractivitySchema,
@@ -104,6 +105,7 @@ const interactiveElementSchema = {
...baseSchema,
...transformSchema,
...textSchema,
+ ...textContentSchema,
} as const satisfies InteractivitySchema;
const setRef = <ElementType,>(
diff --git a/packages/core/src/interactivity-schema.ts b/packages/core/src/interactivity-schema.ts
index 04ef4da232..93c9cdd46c 100644
--- a/packages/core/src/interactivity-schema.ts
+++ b/packages/core/src/interactivity-schema.ts
@@ -94,6 +94,13 @@ export type ColorFieldSchema = {
keyframable?: boolean;
};
+export type TextContentFieldSchema = {
+ type: 'text-content';
+ default: string;
+ description?: string;
+ keyframable?: false;
+};
+
export type EnumFieldSchema = {
type: 'enum';
default: string;
@@ -173,6 +180,7 @@ export type VisibleFieldSchema =
| ScaleFieldSchema
| UvCoordinateFieldSchema
| ColorFieldSchema
+ | TextContentFieldSchema
| ArrayFieldSchema
| EnumFieldSchema;
@@ -294,6 +302,15 @@ export const textSchema = {
},
} as const satisfies InteractivitySchema;
+export const textContentSchema = {
+ children: {
+ type: 'text-content',
+ default: '',
+ description: 'Text',
+ keyframable: false,
+ },
+} as const satisfies InteractivitySchema;
+
export const premountSchema = {
premountFor: {
type: 'number',
diff --git a/packages/core/src/test/drag-override-value.test.ts b/packages/core/src/test/drag-override-value.test.ts
index 4dd7a0989b..54ab206604 100644
--- a/packages/core/src/test/drag-override-value.test.ts
+++ b/packages/core/src/test/drag-override-value.test.ts
@@ -6,6 +6,7 @@ import {
import {
computeEffectiveSchemaValuesDotNotation,
makeKeyframedDragOverride,
+ makeStaticDragOverride,
type CanUpdateSequencePropStatusKeyframed,
} from '../use-schema';
@@ -159,6 +160,34 @@ test('computeEffectiveSchemaValuesDotNotation resolves keyframed drag overrides
expect(merged.opacity).toBe(3);
});
+test('getEffectiveVisualModeValue resolves static string drag overrides', () => {
+ expect(
+ getEffectiveVisualModeValue({
+ propStatus: {
+ status: 'static',
+ codeValue: 'Old',
+ },
+ dragOverrideValue: makeStaticDragOverride('New'),
+ defaultValue: undefined,
+ frame: null,
+ shouldResortToDefaultValueIfUndefined: false,
+ }),
+ ).toBe('New');
+
+ expect(
+ getEffectiveVisualModeValue({
+ propStatus: {
+ status: 'static',
+ codeValue: 'Old',
+ },
+ dragOverrideValue: makeStaticDragOverride(''),
+ defaultValue: undefined,
+ frame: null,
+ shouldResortToDefaultValueIfUndefined: false,
+ }),
+ ).toBe('');
+});
+
test('getEffectiveVisualModeValue resolves keyframed drag overrides at the source frame', () => {
const status = makeKeyframedStatus();
diff --git a/packages/core/src/test/with-interactivity-schema-helpers.test.ts b/packages/core/src/test/with-interactivity-schema-helpers.test.ts
index e8333ff822..cde0bb0bd2 100644
--- a/packages/core/src/test/with-interactivity-schema-helpers.test.ts
+++ b/packages/core/src/test/with-interactivity-schema-helpers.test.ts
@@ -10,6 +10,7 @@ import {
sequenceSchema,
sequenceSchemaWithoutFrom,
sequenceStyleSchema,
+ textContentSchema,
textSchema,
transformSchema,
} from '../interactivity-schema.js';
@@ -185,6 +186,22 @@ test('readValuesFromProps reads dot-notation keys via getNestedValue', () => {
expect(values['style.rotate']).toBeUndefined();
});
+test('readValuesFromProps ignores non-string text content runtime values', () => {
+ const props = {
+ children: {type: 'span'},
+ };
+ const flatSchema = getFlatSchemaWithAllKeys(textContentSchema);
+ const values = readValuesFromProps(props, ['children'], flatSchema);
+ expect(values.children).toBeUndefined();
+
+ const stringValues = readValuesFromProps(
+ {children: 'Hello'},
+ ['children'],
+ flatSchema,
+ );
+ expect(stringValues.children).toBe('Hello');
+});
+
test('selectActiveKeys returns only the hidden + layout keys when layout=none', () => {
const values = {
layout: 'none',
@@ -245,6 +262,7 @@ test('mergeValues writes nested values back into props with dot keys', () => {
const props = {layout: 'absolute-fill', style: {scale: 1}};
const values = {layout: 'absolute-fill', 'style.scale': 2};
const merged = mergeValues({
+ flatSchema: getFlatSchemaWithAllKeys(sequenceSchema),
props,
valuesDotNotation: values,
schemaKeys: ['layout', 'style.scale'],
@@ -254,12 +272,26 @@ test('mergeValues writes nested values back into props with dot keys', () => {
expect((merged.style as {scale: number}).scale).toBe(2);
});
+test('mergeValues preserves non-string text content props', () => {
+ const children = {type: 'span'};
+ const merged = mergeValues({
+ flatSchema: getFlatSchemaWithAllKeys(textContentSchema),
+ props: {children},
+ valuesDotNotation: {children: undefined},
+ schemaKeys: ['children'],
+ propsToDelete: new Set(),
+ });
+ expect(merged.children).toBe(children);
+});
+
test('end-to-end: layout=none drops style.scale from active props', () => {
const props = {layout: 'none', style: {scale: 2}};
const flatKeys = Object.keys(getFlatSchemaWithAllKeys(sequenceSchema));
const values = readValuesFromProps(props, flatKeys);
const activeKeys = selectActiveKeys(sequenceSchema, values);
+ const flatSchema = getFlatSchemaWithAllKeys(sequenceSchema);
const merged = mergeValues({
+ flatSchema,
props,
valuesDotNotation: values,
schemaKeys: activeKeys,
diff --git a/packages/core/src/with-interactivity-schema.ts b/packages/core/src/with-interactivity-schema.ts
index 336df78667..1def36ad91 100644
--- a/packages/core/src/with-interactivity-schema.ts
+++ b/packages/core/src/with-interactivity-schema.ts
@@ -41,13 +41,34 @@ export const getNestedValue = (
return current;
};
+export const getRuntimeValueForSchemaKey = ({
+ flatSchema,
+ key,
+ props,
+}: {
+ flatSchema: InteractivitySchema;
+ key: string;
+ props: Record<string, unknown>;
+}): unknown => {
+ const value = getNestedValue(props, key);
+
+ if (flatSchema[key]?.type === 'text-content' && typeof value !== 'string') {
+ return undefined;
+ }
+
+ return value;
+};
+
export const readValuesFromProps = (
props: Record<string, unknown>,
keys: string[],
+ flatSchema?: InteractivitySchema,
): Record<string, unknown> => {
const out: Record<string, unknown> = {};
for (const key of keys) {
- out[key] = getNestedValue(props, key);
+ out[key] = flatSchema
+ ? getRuntimeValueForSchemaKey({flatSchema, key, props})
+ : getNestedValue(props, key);
}
return out;
@@ -61,11 +82,13 @@ export const selectActiveKeys = (
};
export const mergeValues = ({
+ flatSchema,
props,
valuesDotNotation,
schemaKeys,
propsToDelete,
}: {
+ flatSchema: InteractivitySchema;
props: Record<string, unknown>;
valuesDotNotation: Record<string, unknown>;
schemaKeys: string[];
@@ -75,6 +98,10 @@ export const mergeValues = ({
for (const key of schemaKeys) {
const value = valuesDotNotation[key];
+ if (flatSchema[key]?.type === 'text-content' && value === undefined) {
+ continue;
+ }
+
const parts = key.split('.');
if (parts.length === 1) {
@@ -100,7 +127,16 @@ export const mergeValues = ({
current[parts[parts.length - 1]] = value;
}
- deleteNestedKey(merged, propsToDelete);
+ const propsToDeleteWithoutTextContent = new Set(
+ [...propsToDelete].filter(
+ (key) =>
+ !(
+ flatSchema[key]?.type === 'text-content' &&
+ valuesDotNotation[key] === undefined
+ ),
+ ),
+ );
+ deleteNestedKey(merged, propsToDeleteWithoutTextContent);
return merged;
};
@@ -188,12 +224,21 @@ export const withInteractivitySchema = <
// memoized on the leaf values so the object reference is stable
// when nothing changed β€” otherwise downstream `useMemo`s churn and
// effects (e.g. Sequence registration) re-fire every render.
- const runtimeValues = flatKeys.map((k) =>
- getNestedValue(props as Record<string, unknown>, k),
+ const runtimeValues = flatKeys.map((key) =>
+ getRuntimeValueForSchemaKey({
+ flatSchema,
+ key,
+ props: props as Record<string, unknown>,
+ }),
);
// eslint-disable-next-line react-hooks/rules-of-hooks
const currentRuntimeValueDotNotation = useMemo(
- () => readValuesFromProps(props as Record<string, unknown>, flatKeys),
+ () =>
+ readValuesFromProps(
+ props as Record<string, unknown>,
+ flatKeys,
+ flatSchema,
+ ),
// eslint-disable-next-line react-hooks/exhaustive-deps
runtimeValues,
);
@@ -239,6 +284,7 @@ export const withInteractivitySchema = <
// 5. Apply the active values back onto the props.
const mergedProps = mergeValues({
+ flatSchema,
props: props as Record<string, unknown>,
valuesDotNotation,
schemaKeys: activeKeys,
diff --git a/packages/studio-server/src/codemods/update-sequence-props/update-sequence-props.ts b/packages/studio-server/src/codemods/update-sequence-props/update-sequence-props.ts
index 4ba5c38f59..45838835ae 100644
--- a/packages/studio-server/src/codemods/update-sequence-props/update-sequence-props.ts
+++ b/packages/studio-server/src/codemods/update-sequence-props/update-sequence-props.ts
@@ -7,9 +7,14 @@ import type {
StringLiteral,
} from '@babel/types';
import * as recast from 'recast';
-import type {SequenceNodePath, InteractivitySchema} from 'remotion';
+import type {InteractivitySchema, SequenceNodePath} from 'remotion';
import {NoReactInternals} from 'remotion/no-react';
-import {findJsxElementAtNodePath} from '../../preview-server/routes/can-update-sequence-props';
+import {
+ findJsxElementNodeAtNodePath,
+ getStaticJsxChildrenAttribute,
+ getStaticJsxTextContent,
+ hasJsxChildrenAttribute,
+} from '../../preview-server/routes/can-update-sequence-props';
import {formatFileContent} from '../format-file-content';
import {parseAst, serializeAst} from '../parse-ast';
import {parseValueExpression, updateNestedProp} from '../update-nested-prop';
@@ -115,16 +120,89 @@ const snapshotTopLevelAttrs = (
return result;
};
-type JSXOpeningElementLike = NonNullable<
- ReturnType<typeof findJsxElementAtNodePath>
+type JSXElementLike = NonNullable<
+ ReturnType<typeof findJsxElementNodeAtNodePath>
>;
+type JSXOpeningElementLike = JSXElementLike['openingElement'];
+
+const escapeJsxText = (value: string): string => {
+ return value
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
+ .replace(/{/g, '&#123;')
+ .replace(/}/g, '&#125;');
+};
+
+const findChildrenAttribute = (
+ node: JSXOpeningElementLike,
+): JSXAttribute | undefined => {
+ return node.attributes?.find((attr) => {
+ return (
+ attr.type === 'JSXAttribute' &&
+ attr.name.type === 'JSXIdentifier' &&
+ attr.name.name === 'children'
+ );
+ }) as JSXAttribute | undefined;
+};
+
+const updateJsxTextContent = ({
+ jsxElement,
+ value,
+}: {
+ jsxElement: JSXElementLike;
+ value: unknown;
+}): string => {
+ const nextValue = String(value ?? '');
+ const staticChildrenAttribute = getStaticJsxChildrenAttribute(
+ jsxElement.openingElement,
+ );
+ if (staticChildrenAttribute) {
+ const childrenAttribute = findChildrenAttribute(jsxElement.openingElement);
+ if (!childrenAttribute) {
+ throw new Error('Expected static children attribute to exist');
+ }
+
+ childrenAttribute.value = b.stringLiteral(nextValue) as StringLiteral;
+ return staticChildrenAttribute.value;
+ }
+
+ if (hasJsxChildrenAttribute(jsxElement.openingElement)) {
+ throw new Error(
+ 'Cannot update text content because the children attribute is not static text',
+ );
+ }
+
+ const staticTextContent = getStaticJsxTextContent(jsxElement);
+ if (!staticTextContent) {
+ throw new Error(
+ 'Cannot update text content because JSX children are not static text',
+ );
+ }
+
+ const canRepresentAsJsxText =
+ staticTextContent.kind === 'jsx-text' &&
+ !nextValue.includes('\n') &&
+ nextValue.trim() === nextValue;
+ if (canRepresentAsJsxText) {
+ jsxElement.children = [
+ b.jsxText(escapeJsxText(nextValue)),
+ ] as unknown as JSXElementLike['children'];
+ } else {
+ jsxElement.children = [
+ b.jsxExpressionContainer(b.stringLiteral(nextValue)),
+ ] as unknown as JSXElementLike['children'];
+ }
+
+ return staticTextContent.value;
+};
const updateSequencePropsNode = ({
- node,
+ jsxElement,
updates,
schema,
}: {
- node: JSXOpeningElementLike;
+ jsxElement: JSXElementLike;
updates: SequencePropUpdate[];
schema: InteractivitySchema;
}): {
@@ -132,6 +210,7 @@ const updateSequencePropsNode = ({
logLine: number;
removedProps: RemovedProp[];
} => {
+ const node = jsxElement.openingElement;
const logLine = node.loc?.start.line ?? 1;
const oldValueStrings: string[] = [];
@@ -146,6 +225,12 @@ const updateSequencePropsNode = ({
for (const {key, value, defaultValue} of updates) {
let oldValueString = '';
+ if (key === 'children') {
+ oldValueString = updateJsxTextContent({jsxElement, value});
+ oldValueStrings.push(oldValueString);
+ continue;
+ }
+
const isDefault =
defaultValue !== null &&
JSON.stringify(value) === JSON.stringify(defaultValue);
@@ -284,15 +369,15 @@ export const updateSequencePropsAst = ({
} => {
const ast = parseAst(input);
- const node = findJsxElementAtNodePath(ast, nodePath);
- if (!node) {
+ const jsxElement = findJsxElementNodeAtNodePath(ast, nodePath);
+ if (!jsxElement) {
throw new Error(
'Could not find a JSX element at the specified line to update',
);
}
const {oldValueStrings, logLine, removedProps} = updateSequencePropsNode({
- node,
+ jsxElement,
updates,
schema,
});
@@ -316,14 +401,14 @@ export const updateMultipleSequenceProps = async ({
}): Promise<UpdateMultipleSequencePropsResult> => {
const ast = parseAst(input);
const results = changes.map(({nodePath, updates, schema}) => {
- const node = findJsxElementAtNodePath(ast, nodePath);
- if (!node) {
+ const jsxElement = findJsxElementNodeAtNodePath(ast, nodePath);
+ if (!jsxElement) {
throw new Error(
'Could not find a JSX element at the specified line to update',
);
}
- return updateSequencePropsNode({node, updates, schema});
+ return updateSequencePropsNode({jsxElement, updates, schema});
});
const {output, formatted} = await formatFileContent({
diff --git a/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts b/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts
index 095d8d84ae..eda512deb0 100644
--- a/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts
+++ b/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts
@@ -4,6 +4,7 @@ import type {
Expression,
File,
JSXAttribute,
+ JSXElement,
JSXOpeningElement,
NewExpression,
ObjectExpression,
@@ -34,8 +35,8 @@ import {toImportAgnosticNodePath} from '../../helpers/import-agnostic-node-path'
import {resolveFileInsideProject} from '../../helpers/resolve-file-inside-project';
import {
getJsxComponentIdentity,
- JsxElementIdentityMismatchError,
jsxComponentIdentitiesMatch,
+ JsxElementIdentityMismatchError,
} from '../jsx-component-identity';
import {JsxElementNotFoundAtLocationError} from '../jsx-element-not-found-at-location-error';
import {computeEffectPropStatus} from './can-update-effect-props';
@@ -749,17 +750,123 @@ const getNodePathForRecastPath = (
return toImportAgnosticNodePath({ast, nodePath: segments});
};
-export const findJsxElementAtNodePath = (
+export const findJsxElementPathAtNodePath = (
ast: File,
nodePath: SequenceNodePath,
-): JSXOpeningElement | null => {
+) => {
const current = getAstNodePath(ast, nodePath);
if (!current) {
return null;
}
if (recast.types.namedTypes.JSXOpeningElement.check(current.value)) {
- return current.value as unknown as JSXOpeningElement;
+ return current;
+ }
+
+ return null;
+};
+
+export const findJsxElementAtNodePath = (
+ ast: File,
+ nodePath: SequenceNodePath,
+): JSXOpeningElement | null => {
+ const current = findJsxElementPathAtNodePath(ast, nodePath);
+ return current ? (current.value as unknown as JSXOpeningElement) : null;
+};
+
+export const findJsxElementNodeAtNodePath = (
+ ast: File,
+ nodePath: SequenceNodePath,
+): JSXElement | null => {
+ const current = findJsxElementPathAtNodePath(ast, nodePath);
+ if (!current) {
+ return null;
+ }
+
+ if (recast.types.namedTypes.JSXElement.check(current.parentPath?.value)) {
+ return current.parentPath.value as unknown as JSXElement;
+ }
+
+ return null;
+};
+
+export type StaticJsxTextContent =
+ | {kind: 'jsx-text'; value: string}
+ | {kind: 'string-expression'; value: string};
+
+const findJsxChildrenAttribute = (
+ jsxElement: JSXOpeningElement,
+): JSXAttribute | null => {
+ const childrenAttr = jsxElement.attributes.find((attr) => {
+ return (
+ attr.type === 'JSXAttribute' &&
+ attr.name.type === 'JSXIdentifier' &&
+ attr.name.name === 'children'
+ );
+ });
+
+ return childrenAttr && childrenAttr.type === 'JSXAttribute'
+ ? childrenAttr
+ : null;
+};
+
+export const getStaticJsxChildrenAttribute = (
+ jsxElement: JSXOpeningElement,
+): StaticJsxTextContent | null => {
+ const childrenAttr = findJsxChildrenAttribute(jsxElement);
+ if (!childrenAttr?.value) {
+ return null;
+ }
+
+ if (childrenAttr.value.type === 'StringLiteral') {
+ return {kind: 'jsx-text', value: childrenAttr.value.value};
+ }
+
+ if (
+ childrenAttr.value.type === 'JSXExpressionContainer' &&
+ childrenAttr.value.expression.type === 'StringLiteral'
+ ) {
+ return {
+ kind: 'string-expression',
+ value: childrenAttr.value.expression.value,
+ };
+ }
+
+ return null;
+};
+
+export const hasJsxChildrenAttribute = (
+ jsxElement: JSXOpeningElement,
+): boolean => findJsxChildrenAttribute(jsxElement) !== null;
+
+export const getStaticJsxTextContent = (
+ jsxElement: JSXElement,
+): StaticJsxTextContent | null => {
+ const meaningfulChildren = jsxElement.children.filter((candidate) => {
+ return !(candidate.type === 'JSXText' && candidate.value.trim() === '');
+ });
+
+ if (meaningfulChildren.length === 0) {
+ return {kind: 'jsx-text', value: ''};
+ }
+
+ if (meaningfulChildren.length !== 1) {
+ return null;
+ }
+
+ const child = meaningfulChildren[0];
+ if (child.type === 'JSXText') {
+ return {
+ kind: 'jsx-text',
+ value: child.value.includes('\n') ? child.value.trim() : child.value,
+ };
+ }
+
+ if (
+ child.type === 'JSXExpressionContainer' &&
+ child.expression.type === 'StringLiteral'
+ ) {
+ return {kind: 'string-expression', value: child.expression.value};
}
return null;
@@ -903,16 +1010,37 @@ const computeEffectsForJsx = ({
const computeSequenceOnlyPropsRecord = ({
jsxElement,
+ jsxElementNode,
ast,
keys,
}: {
jsxElement: JSXOpeningElement;
+ jsxElementNode: JSXElement;
ast: File;
keys: string[];
}): Record<string, CanUpdatePropStatus> => {
const allProps = getPropsStatus(jsxElement, ast);
const filteredProps: Record<string, CanUpdatePropStatus> = {};
for (const key of keys) {
+ if (key === 'children') {
+ const staticChildrenAttribute = getStaticJsxChildrenAttribute(jsxElement);
+ if (staticChildrenAttribute) {
+ filteredProps[key] = staticStatus(staticChildrenAttribute.value);
+ continue;
+ }
+
+ if (hasJsxChildrenAttribute(jsxElement)) {
+ filteredProps[key] = computedStatus();
+ continue;
+ }
+
+ const staticTextContent = getStaticJsxTextContent(jsxElementNode);
+ filteredProps[key] = staticTextContent
+ ? staticStatus(staticTextContent.value)
+ : computedStatus();
+ continue;
+ }
+
const dotIndex = key.indexOf('.');
if (dotIndex !== -1) {
filteredProps[key] = getNestedPropStatus(
@@ -946,9 +1074,10 @@ export const computeSequencePropsStatusFromContent = ({
}): CanUpdateSequencePropsResponseTrue => {
const ast = parseAst(fileContents);
- const jsxElement = findJsxElementAtNodePath(ast, nodePath);
+ const jsxElementNode = findJsxElementNodeAtNodePath(ast, nodePath);
+ const jsxElement = jsxElementNode?.openingElement ?? null;
- if (!jsxElement) {
+ if (!jsxElement || !jsxElementNode) {
throw new JsxElementNotFoundAtLocationError();
}
@@ -961,7 +1090,12 @@ export const computeSequencePropsStatusFromContent = ({
throw new JsxElementIdentityMismatchError();
}
- const filteredProps = computeSequenceOnlyPropsRecord({jsxElement, ast, keys});
+ const filteredProps = computeSequenceOnlyPropsRecord({
+ jsxElement,
+ jsxElementNode,
+ ast,
+ keys,
+ });
const effectsStatuses = computeEffectsForJsx({ast, jsxElement, effects});
return {
diff --git a/packages/studio-server/src/test/compute-sequence-props-status.test.ts b/packages/studio-server/src/test/compute-sequence-props-status.test.ts
index 363e19bfaa..539a6551cb 100644
--- a/packages/studio-server/src/test/compute-sequence-props-status.test.ts
+++ b/packages/studio-server/src/test/compute-sequence-props-status.test.ts
@@ -759,3 +759,98 @@ export const Example: React.FC = () => {
status: 'computed',
});
});
+
+test('computeSequencePropsStatus should detect static JSX text children', () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC = () => {
+ return <Interactive.P>Hello</Interactive.P>;
+};
+`;
+ const result = computeSequencePropsStatusFromContent({
+ fileContents: input,
+ nodePath: getNodePathFromContent(input, 5),
+ componentIdentity: null,
+ keys: ['children'],
+ effects: [],
+ });
+
+ expect(result.props.children).toEqual({status: 'static', codeValue: 'Hello'});
+});
+
+test('computeSequencePropsStatus should detect static children attribute', () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC = () => {
+ return <Interactive.P children="Hello" />;
+};
+`;
+ const result = computeSequencePropsStatusFromContent({
+ fileContents: input,
+ nodePath: getNodePathFromContent(input, 5),
+ componentIdentity: null,
+ keys: ['children'],
+ effects: [],
+ });
+
+ expect(result.props.children).toEqual({status: 'static', codeValue: 'Hello'});
+});
+
+test('computeSequencePropsStatus should prefer static children attribute over JSX children', () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC = () => {
+ return <Interactive.P children="Hello">Stale</Interactive.P>;
+};
+`;
+ const result = computeSequencePropsStatusFromContent({
+ fileContents: input,
+ nodePath: getNodePathFromContent(input, 5),
+ componentIdentity: null,
+ keys: ['children'],
+ effects: [],
+ });
+
+ expect(result.props.children).toEqual({status: 'static', codeValue: 'Hello'});
+});
+
+test('computeSequencePropsStatus should detect empty JSX text children', () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC = () => {
+ return <Interactive.P></Interactive.P>;
+};
+`;
+ const result = computeSequencePropsStatusFromContent({
+ fileContents: input,
+ nodePath: getNodePathFromContent(input, 5),
+ componentIdentity: null,
+ keys: ['children'],
+ effects: [],
+ });
+
+ expect(result.props.children).toEqual({status: 'static', codeValue: ''});
+});
+
+test('computeSequencePropsStatus should reject non-static text children', () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC<{text: string}> = ({text}) => {
+ return <Interactive.P>{text}</Interactive.P>;
+};
+`;
+ const result = computeSequencePropsStatusFromContent({
+ fileContents: input,
+ nodePath: getNodePathFromContent(input, 5),
+ componentIdentity: null,
+ keys: ['children'],
+ effects: [],
+ });
+
+ expect(result.props.children).toEqual({status: 'computed'});
+});
diff --git a/packages/studio-server/src/test/update-sequence-props.test.ts b/packages/studio-server/src/test/update-sequence-props.test.ts
index 6b9a4f812e..7fb49abc53 100644
--- a/packages/studio-server/src/test/update-sequence-props.test.ts
+++ b/packages/studio-server/src/test/update-sequence-props.test.ts
@@ -220,3 +220,137 @@ test('updateMultipleSequenceProps should update multiple nodes in one format pas
expect(output.split('\n')[7]).toContain('hueShift={90}');
expect(output.split('\n')[8]).toContain('durationInFrames={120}');
});
+
+test('updateSequenceProps should update JSX text children', async () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC = () => {
+ return <Interactive.P>Hello</Interactive.P>;
+};
+`;
+
+ const {output, oldValueStrings} = await updateSequenceProps({
+ input,
+ nodePath: lineColumnToNodePath(input, 5),
+ updates: [{key: 'children', value: 'Goodbye', defaultValue: ''}],
+ schema: NoReactInternals.sequenceSchema,
+ prettierConfigOverride: null,
+ });
+
+ expect(oldValueStrings[0]).toBe('Hello');
+ expect(output).toContain('<Interactive.P>Goodbye</Interactive.P>');
+});
+
+test('updateSequenceProps should preserve trailing spaces in JSX text children', async () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC = () => {
+ return <Interactive.P>Hello</Interactive.P>;
+};
+`;
+
+ const {output, oldValueStrings} = await updateSequenceProps({
+ input,
+ nodePath: lineColumnToNodePath(input, 5),
+ updates: [{key: 'children', value: 'Cool! I ', defaultValue: ''}],
+ schema: NoReactInternals.sequenceSchema,
+ prettierConfigOverride: null,
+ });
+
+ expect(oldValueStrings[0]).toBe('Hello');
+ expect(output).toContain("<Interactive.P>{'Cool! I '}</Interactive.P>");
+});
+
+test('updateSequenceProps should update children attribute', async () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC = () => {
+ return <Interactive.P children="Hello" />;
+};
+`;
+
+ const {output, oldValueStrings} = await updateSequenceProps({
+ input,
+ nodePath: lineColumnToNodePath(input, 5),
+ updates: [{key: 'children', value: 'Goodbye', defaultValue: ''}],
+ schema: NoReactInternals.sequenceSchema,
+ prettierConfigOverride: null,
+ });
+
+ expect(oldValueStrings[0]).toBe('Hello');
+ expect(output).toContain('<Interactive.P children="Goodbye" />');
+ expect(output).not.toContain('>Goodbye</Interactive.P>');
+});
+
+test('updateSequenceProps should update children attribute instead of JSX children', async () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC = () => {
+ return <Interactive.P children="Hello">Stale</Interactive.P>;
+};
+`;
+
+ const {output, oldValueStrings} = await updateSequenceProps({
+ input,
+ nodePath: lineColumnToNodePath(input, 5),
+ updates: [{key: 'children', value: 'Goodbye', defaultValue: ''}],
+ schema: NoReactInternals.sequenceSchema,
+ prettierConfigOverride: null,
+ });
+
+ expect(oldValueStrings[0]).toBe('Hello');
+ expect(output).toContain(
+ '<Interactive.P children="Goodbye">Stale</Interactive.P>',
+ );
+});
+
+test('updateSequenceProps should update empty JSX text children', async () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC = () => {
+ return <Interactive.P></Interactive.P>;
+};
+`;
+
+ const {output, oldValueStrings} = await updateSequenceProps({
+ input,
+ nodePath: lineColumnToNodePath(input, 5),
+ updates: [{key: 'children', value: 'Hello again', defaultValue: ''}],
+ schema: NoReactInternals.sequenceSchema,
+ prettierConfigOverride: null,
+ });
+
+ expect(oldValueStrings[0]).toBe('');
+ expect(output).toContain('<Interactive.P>Hello again</Interactive.P>');
+});
+
+test('updateSequenceProps should refuse complex children', async () => {
+ const input = `import React from 'react';
+import {Interactive} from 'remotion';
+
+export const Example: React.FC = () => {
+ return (
+ <Interactive.P>
+ Hello <Interactive.Strong>world</Interactive.Strong>
+ </Interactive.P>
+ );
+};
+`;
+
+ await expect(
+ updateSequenceProps({
+ input,
+ nodePath: lineColumnToNodePath(input, 6),
+ updates: [{key: 'children', value: 'Goodbye', defaultValue: ''}],
+ schema: NoReactInternals.sequenceSchema,
+ prettierConfigOverride: null,
+ }),
+ ).rejects.toThrow(
+ 'Cannot update text content because JSX children are not static text',
+ );
+});
diff --git a/packages/studio-shared/src/schema-field-info.ts b/packages/studio-shared/src/schema-field-info.ts
index 37c7a3aa71..d151d8b4d9 100644
--- a/packages/studio-shared/src/schema-field-info.ts
+++ b/packages/studio-shared/src/schema-field-info.ts
@@ -4,10 +4,10 @@ import type {
EffectDefinition,
GetDragOverrides,
GetEffectDragOverrides,
+ InteractivitySchema,
PropStatuses,
SequenceControls,
SequencePropsSubscriptionKey,
- InteractivitySchema,
VisibleFieldSchema,
} from 'remotion';
import {Internals} from 'remotion';
@@ -70,6 +70,7 @@ const TRANSFORM_FIELD_KEYS = new Set([
]);
const TEXT_FIELD_KEYS = new Set([
+ 'children',
'style.color',
'style.fontSize',
'style.lineHeight',
@@ -113,6 +114,7 @@ const SUPPORTED_SCHEMA_TYPES = [
'scale',
'uv-coordinate',
'color',
+ 'text-content',
'array',
'enum',
'hidden',
@@ -153,6 +155,10 @@ const getSchemaFieldRowHeight = ({
);
}
+ if (fieldSchema.type === 'text-content') {
+ return SCHEMA_FIELD_ROW_HEIGHT * 2;
+ }
+
return SCHEMA_FIELD_ROW_HEIGHT;
};
@@ -188,12 +194,14 @@ export const getFieldsToShow = ({
nodePath,
schema,
currentRuntimeValueDotNotation,
+ includeTextContent,
}: {
schema: InteractivitySchema;
currentRuntimeValueDotNotation: Record<string, unknown>;
getDragOverrides: GetDragOverrides;
propStatuses: PropStatuses;
nodePath: SequencePropsSubscriptionKey;
+ includeTextContent?: boolean;
}): InteractivitySchemaFieldInfo[] | null => {
const {merged: valuesDotNotation} =
Internals.computeEffectiveSchemaValuesDotNotation({
@@ -203,7 +211,6 @@ export const getFieldsToShow = ({
propStatus: Internals.getPropStatusesCtx(propStatuses, nodePath),
frame: null,
});
-
const activeSchema = Internals.flattenActiveSchema(
schema,
(key) => valuesDotNotation[key],
@@ -224,6 +231,10 @@ export const getFieldsToShow = ({
return null;
}
+ if (fieldSchema.type === 'text-content' && !includeTextContent) {
+ return null;
+ }
+
// `hidden` is represented as the eye/speaker icon on the timeline track,
// so we don't render it as a regular field in the expanded section.
if (key === 'hidden') {
diff --git a/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx b/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx
index faf36feffc..c96ae4eec1 100644
--- a/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx
+++ b/packages/studio/src/components/InspectorPanel/KeyframeInspector.tsx
@@ -12,8 +12,8 @@ import React, {
import type {
CanUpdateSequencePropStatusKeyframed,
DragOverrideValue,
- SequencePropsSubscriptionKey,
InteractivitySchema,
+ SequencePropsSubscriptionKey,
} from 'remotion';
import {Internals, useVideoConfig} from 'remotion';
import type {CodePosition} from '../../error-overlay/react-overlay/utils/get-source-map';
@@ -191,6 +191,7 @@ export const KeyframeInspector: React.FC<{
getDragOverrides,
propStatuses,
nodePath,
+ includeTextContent: false,
});
const sequenceField =
sequenceFields?.find(
diff --git a/packages/studio/src/components/InspectorSequenceSection.tsx b/packages/studio/src/components/InspectorSequenceSection.tsx
index 52bedb5c71..cf2b1e35c1 100644
--- a/packages/studio/src/components/InspectorSequenceSection.tsx
+++ b/packages/studio/src/components/InspectorSequenceSection.tsx
@@ -165,6 +165,7 @@ export const InspectorSequenceSection: React.FC<{
const {tree} = useTimelineExpandedTree({
sequence,
nodePathInfo,
+ includeTextContent: true,
});
const [collapsedKeys, setCollapsedKeys] = useState<ReadonlySet<string>>(
loadInspectorCollapsedKeys,
diff --git a/packages/studio/src/components/OptionsPanel.tsx b/packages/studio/src/components/OptionsPanel.tsx
index b933fdb759..ce153843e9 100644
--- a/packages/studio/src/components/OptionsPanel.tsx
+++ b/packages/studio/src/components/OptionsPanel.tsx
@@ -1,5 +1,4 @@
import React, {
- createRef,
useCallback,
useContext,
useImperativeHandle,
@@ -14,6 +13,7 @@ import {SHOW_BROWSER_RENDERING} from '../helpers/show-browser-rendering';
import {useZodIfPossible, useZodTypesIfPossible} from './get-zod-if-possible';
import {InspectorPanel} from './InspectorPanel';
import {showNotification} from './Notifications/NotificationCenter';
+import {optionsSidebarTabs} from './options-sidebar-tabs';
import {deepEqual} from './RenderModal/SchemaEditor/deep-equal';
import {extractEnumJsonPaths} from './RenderModal/SchemaEditor/extract-enum-json-paths';
import {SchemaResetButton} from './RenderModal/SchemaEditor/SchemaResetButton';
@@ -51,10 +51,6 @@ export const persistSelectedOptionsSidebarPanel = (
localStorage.setItem(localStorageKey, panel);
};
-export const optionsSidebarTabs = createRef<{
- selectRendersPanel: () => void;
-}>();
-
export const OptionsPanel: React.FC<{
readonly readOnlyStudio: boolean;
}> = ({readOnlyStudio}) => {
@@ -91,6 +87,10 @@ export const OptionsPanel: React.FC<{
useImperativeHandle(optionsSidebarTabs, () => {
return {
+ selectInspectorPanel: () => {
+ setPanel('inspector');
+ persistSelectedOptionsSidebarPanel('inspector');
+ },
selectRendersPanel: () => {
setPanel('renders');
persistSelectedOptionsSidebarPanel('renders');
diff --git a/packages/studio/src/components/RenderModal/ServerRenderModal.tsx b/packages/studio/src/components/RenderModal/ServerRenderModal.tsx
index 8822c63eb6..2ec540b784 100644
--- a/packages/studio/src/components/RenderModal/ServerRenderModal.tsx
+++ b/packages/studio/src/components/RenderModal/ServerRenderModal.tsx
@@ -54,10 +54,8 @@ import {ModalHeader} from '../ModalHeader';
import type {ComboboxValue} from '../NewComposition/ComboBox';
import {DismissableModal} from '../NewComposition/DismissableModal';
import {showNotification} from '../Notifications/NotificationCenter';
-import {
- optionsSidebarTabs,
- persistSelectedOptionsSidebarPanel,
-} from '../OptionsPanel';
+import {optionsSidebarTabs} from '../options-sidebar-tabs';
+import {persistSelectedOptionsSidebarPanel} from '../OptionsPanel';
import {
addSequenceRenderJob,
addStillRenderJob,
diff --git a/packages/studio/src/components/RenderModal/WebRenderModal.tsx b/packages/studio/src/components/RenderModal/WebRenderModal.tsx
index 7016e68bfd..0cfff48364 100644
--- a/packages/studio/src/components/RenderModal/WebRenderModal.tsx
+++ b/packages/studio/src/components/RenderModal/WebRenderModal.tsx
@@ -29,10 +29,8 @@ import {Button} from '../Button';
import {VERTICAL_SCROLLBAR_CLASSNAME} from '../Menu/is-menu-item';
import {ModalHeader} from '../ModalHeader';
import {DismissableModal} from '../NewComposition/DismissableModal';
-import {
- optionsSidebarTabs,
- persistSelectedOptionsSidebarPanel,
-} from '../OptionsPanel';
+import {optionsSidebarTabs} from '../options-sidebar-tabs';
+import {persistSelectedOptionsSidebarPanel} from '../OptionsPanel';
import {RenderQueueContext} from '../RenderQueue/context';
import type {SegmentedControlItem} from '../SegmentedControl';
import {SegmentedControl} from '../SegmentedControl';
diff --git a/packages/studio/src/components/SelectedOutlineElement.tsx b/packages/studio/src/components/SelectedOutlineElement.tsx
index 9fc8f723e4..4e9210b960 100644
--- a/packages/studio/src/components/SelectedOutlineElement.tsx
+++ b/packages/studio/src/components/SelectedOutlineElement.tsx
@@ -1,4 +1,5 @@
import React, {useContext, useMemo, useRef, useState} from 'react';
+import {flushSync} from 'react-dom';
import type {ResolvedStackLocation} from 'remotion';
import {Internals} from 'remotion';
import {NoReactInternals} from 'remotion/no-react';
@@ -22,6 +23,7 @@ import {
} from './ForceSpecificCursor';
import type {ComboboxValue} from './NewComposition/ComboBox';
import {showNotification} from './Notifications/NotificationCenter';
+import {optionsSidebarTabs} from './options-sidebar-tabs';
import {
applySelectedOutlineDragAxisLock,
applySelectedOutlineTransformOriginAxisLock,
@@ -83,6 +85,10 @@ import {
} from './Timeline/call-add-keyframe';
import {disableSequenceInteractivity} from './Timeline/disable-sequence-interactivity';
import {duplicateSequencesFromSource} from './Timeline/duplicate-selected-timeline-item';
+import {
+ commitPendingInspectorFields,
+ requestFocusInspectorField,
+} from './Timeline/focus-inspector-field';
import {getSequenceContextMenuItems} from './Timeline/get-sequence-context-menu-items';
import {saveSequenceProps} from './Timeline/save-sequence-prop';
import {getTimelineAssetLinkInfo} from './Timeline/timeline-asset-link';
@@ -472,6 +478,7 @@ const SelectedOutlinePolygon: React.FC<{
item: TimelineSelection,
interaction: TimelineSelectionInteraction,
) => void;
+ readonly onTextEditStart: (target: SelectedOutlineTarget) => void;
readonly scale: number;
readonly target: SelectedOutlineTarget | undefined;
}> = ({
@@ -484,6 +491,7 @@ const SelectedOutlinePolygon: React.FC<{
onDraggingChange,
onHoverChange,
onSelect,
+ onTextEditStart,
scale,
target,
}) => {
@@ -528,6 +536,10 @@ const SelectedOutlinePolygon: React.FC<{
return;
}
+ if (commitPendingInspectorFields()) {
+ return;
+ }
+
const startPointerX = event.clientX;
const startPointerY = event.clientY;
const dragStates = getSelectedOutlineDragStates({
@@ -709,6 +721,19 @@ const SelectedOutlinePolygon: React.FC<{
],
);
+ const onDoubleClick = React.useCallback(
+ (event: React.MouseEvent<SVGPolygonElement>) => {
+ if (target === undefined) {
+ return;
+ }
+
+ event.preventDefault();
+ event.stopPropagation();
+ onTextEditStart(target);
+ },
+ [onTextEditStart, target],
+ );
+
const onEffectDragOver = React.useCallback(
(event: React.DragEvent<SVGPolygonElement>) => {
if (effectDrop === null || !hasEffectDragType(event.dataTransfer)) {
@@ -788,6 +813,7 @@ const SelectedOutlinePolygon: React.FC<{
}
}}
onPointerDown={onPointerDown}
+ onDoubleClick={onDoubleClick}
onDragOver={effectDrop === null ? undefined : onEffectDragOver}
onDragLeave={effectDrop === null ? undefined : onEffectDragLeave}
onDrop={effectDrop === null ? undefined : onEffectDrop}
@@ -864,6 +890,10 @@ const SelectedOutlineScaleEdgeLine: React.FC<{
return;
}
+ if (commitPendingInspectorFields()) {
+ return;
+ }
+
const startPointer = {x: event.clientX, y: event.clientY};
const dragStates = getSelectedOutlineScaleDragStates({
dragTargets: selected ? allScaleDragTargets : [scaleDrag],
@@ -1146,6 +1176,10 @@ const SelectedOutlineRotationCornerHandle: React.FC<{
return;
}
+ if (commitPendingInspectorFields()) {
+ return;
+ }
+
const startPointer = {x: event.clientX, y: event.clientY};
const svgRect = svg.getBoundingClientRect();
const center = svgPointToClientPoint(
@@ -1433,6 +1467,40 @@ export const SelectedOutlineElement: React.FC<{
const selectAsset = useSelectAsset();
const {setSelectedModal} = useContext(ModalsContext);
+ const onTextEditStart = React.useCallback(
+ (editTarget: SelectedOutlineTarget) => {
+ const {textEdit} = editTarget;
+ if (textEdit === null) {
+ return;
+ }
+
+ if (
+ textEdit.propStatus.status !== 'static' ||
+ typeof textEdit.propStatus.codeValue !== 'string'
+ ) {
+ showNotification(
+ 'This text is computed and cannot be edited visually',
+ 3000,
+ );
+ return;
+ }
+
+ flushSync(() => {
+ if (!editTarget.selected) {
+ onSelect(editTarget.selection, {shiftKey: false, toggleKey: false});
+ }
+
+ optionsSidebarTabs.current?.selectInspectorPanel();
+ });
+
+ requestFocusInspectorField({
+ fieldKey: 'children',
+ nodePath: textEdit.nodePath,
+ });
+ },
+ [onSelect],
+ );
+
const onContextMenuOpen = React.useCallback(async () => {
if (target === undefined || previewServerState.type !== 'connected') {
return false;
@@ -1623,6 +1691,7 @@ export const SelectedOutlineElement: React.FC<{
onDraggingChange={onDraggingChange}
onHoverChange={onHoverChange}
onSelect={onSelect}
+ onTextEditStart={onTextEditStart}
scale={scale}
target={target}
/>
diff --git a/packages/studio/src/components/SelectedOutlineOverlay.tsx b/packages/studio/src/components/SelectedOutlineOverlay.tsx
index 2ad76fb46d..f971bbacb2 100644
--- a/packages/studio/src/components/SelectedOutlineOverlay.tsx
+++ b/packages/studio/src/components/SelectedOutlineOverlay.tsx
@@ -23,8 +23,8 @@ import {
getSelectedOutlineDragValues,
getSelectedOutlineKeyboardNudgeDeltas,
getSelectedOutlineKeyboardNudgeDirection,
- type SelectedOutlineKeyframedDragChange,
type SelectedOutlineKeyboardNudgeDirection,
+ type SelectedOutlineKeyframedDragChange,
type SelectedOutlineStaticDragChange,
} from './selected-outline-drag';
import {type SelectedOutline} from './selected-outline-geometry';
@@ -56,9 +56,9 @@ import {getCurrentDuration, getCurrentFps} from './Timeline/imperative-state';
import {saveSequenceProps} from './Timeline/save-sequence-prop';
import {ensureFrameIsInViewport} from './Timeline/timeline-scroll-logic';
import {
+ useTimelineSelection,
type TimelineSelection,
type TimelineSelectionInteraction,
- useTimelineSelection,
} from './Timeline/TimelineSelection';
export {
@@ -79,11 +79,11 @@ export {
getSelectedOutlineScaleEdgeInfo,
getSelectedOutlineTransformOriginLockedAxis,
isSelectedOutlineDragPastThreshold,
- selectedOutlineUvSnapThresholdPx,
selectedOutlineTransformOriginSnapThresholdPx,
+ selectedOutlineUvSnapThresholdPx,
snapSelectedOutlineRotationDeltaDegrees,
- snapSelectedOutlineUv,
snapSelectedOutlineTransformOriginUv,
+ snapSelectedOutlineUv,
} from './selected-outline-drag';
export {
getOutlineSelectionInteraction,
@@ -226,6 +226,8 @@ export const SelectedOutlineOverlay: React.FC<{
activeSchema?.[transformOriginFieldKey];
const transformOriginPropStatus =
nodePropStatuses?.[transformOriginFieldKey];
+ const textContentFieldSchema = activeSchema?.children;
+ const textContentPropStatus = nodePropStatuses?.children;
const transformOriginValueForRotation =
transformOriginFieldSchema?.type === 'transform-origin' &&
(transformOriginPropStatus?.status === 'static' ||
@@ -293,6 +295,11 @@ export const SelectedOutlineOverlay: React.FC<{
const canDropEffect =
previewServerState.type === 'connected' &&
controls?.supportsEffects === true;
+ const canTextEdit =
+ previewServerState.type === 'connected' &&
+ controls !== null &&
+ textContentFieldSchema?.type === 'text-content' &&
+ textContentPropStatus !== undefined;
return {
key,
@@ -420,6 +427,12 @@ export const SelectedOutlineOverlay: React.FC<{
),
}
: null,
+ textEdit: canTextEdit
+ ? {
+ nodePath,
+ propStatus: textContentPropStatus,
+ }
+ : null,
uvHandles: containsSelection
? getSelectedUvHandles({
propStatuses,
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
index 3553561190..c0f537647d 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
@@ -40,6 +40,7 @@ export const TimelineExpandedSection: React.FC<{
const {filteredTree, getIsExpanded, toggleTrack} = useTimelineExpandedTree({
sequence,
nodePathInfo,
+ includeTextContent: false,
});
const flat = useMemo(
diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx
index 36f238695f..98ada9fd8f 100644
--- a/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx
+++ b/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx
@@ -6,9 +6,9 @@ import type {
DragOverrideValue,
GetDragOverrides,
GetEffectDragOverrides,
+ InteractivitySchema,
PropStatuses,
SequencePropsSubscriptionKey,
- InteractivitySchema,
} from 'remotion';
import {Internals, useVideoConfig} from 'remotion';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
@@ -220,6 +220,7 @@ const resolveKeyframeControlTarget = ({
getDragOverrides,
getEffectDragOverrides,
propStatuses,
+ includeTextContent: false,
});
const fieldNode = findFieldNode(
tree,
diff --git a/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsx b/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsx
index 193f92b230..08c4d43ca3 100644
--- a/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsx
+++ b/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsx
@@ -16,6 +16,7 @@ import {TimelineEnumField} from './TimelineEnumField';
import {TimelineNumberField} from './TimelineNumberField';
import {TimelineRotationField} from './TimelineRotationField';
import {TimelineScaleField} from './TimelineScaleField';
+import {TimelineTextContentField} from './TimelineTextContentField';
import {TimelineTransformOriginField} from './TimelineTransformOriginField';
import {TimelineTranslateField} from './TimelineTranslateField';
import {TimelineUvCoordinateField} from './TimelineUvCoordinateField';
@@ -200,5 +201,21 @@ export const TimelinePrimitiveFieldValue: React.FC<{
);
}
+ if (field.typeName === 'text-content') {
+ return (
+ <span style={inlineWrapper}>
+ <TimelineTextContentField
+ effectiveValue={effectiveValue}
+ field={field}
+ nodePath={scaleLockNodePath}
+ onDragEnd={onDragEnd}
+ onDragValueChange={onDragValueChange}
+ onSave={onSave}
+ propStatus={propStatus}
+ />
+ </span>
+ );
+ }
+
throw new Error(`Unsupported field type: ${field.typeName satisfies never}`);
};
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsx
index bcae96f74b..811c4b4beb 100644
--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx
@@ -833,6 +833,7 @@ export const getSelectableTimelineItems = ({
getDragOverrides,
getEffectDragOverrides,
propStatuses,
+ includeTextContent: false,
});
const filteredTree = filterTimelineExpandedTree({
nodes: tree,
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
index f39ec8f97e..b73f142f97 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
@@ -125,6 +125,7 @@ const TimelineSequenceExpandArrow: React.FC<{
const {filteredTree} = useTimelineExpandedTree({
sequence,
nodePathInfo,
+ includeTextContent: false,
});
if (filteredTree.length === 0) {
diff --git a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
index ca90b4094e..444dbd9262 100644
--- a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
@@ -114,9 +114,11 @@ const Value: React.FC<{
}
const defaultValue =
- field.fieldSchema.default !== undefined
- ? JSON.stringify(field.fieldSchema.default)
- : null;
+ field.fieldSchema.type === 'text-content'
+ ? null
+ : field.fieldSchema.default !== undefined
+ ? JSON.stringify(field.fieldSchema.default)
+ : null;
const stringifiedValue = JSON.stringify(value);
const fieldLabel = field.description ?? field.key;
@@ -154,6 +156,7 @@ const Value: React.FC<{
clientId,
field.description,
field.fieldSchema.default,
+ field.fieldSchema.type,
field.key,
nodePath,
schema,
diff --git a/packages/studio/src/components/Timeline/TimelineTextContentField.tsx b/packages/studio/src/components/Timeline/TimelineTextContentField.tsx
new file mode 100644
index 0000000000..e1c4fa043a
--- /dev/null
+++ b/packages/studio/src/components/Timeline/TimelineTextContentField.tsx
@@ -0,0 +1,153 @@
+import React, {useCallback, useRef} from 'react';
+import type {
+ CanUpdateSequencePropStatusStatic,
+ SequencePropsSubscriptionKey,
+} from 'remotion';
+import type {
+ SchemaFieldInfo,
+ TimelineFieldOnDragValueChange,
+ TimelineFieldOnSave,
+} from '../../helpers/timeline-layout';
+import {RemTextarea} from '../NewComposition/RemTextarea';
+import {
+ registerCommitPendingInspectorField,
+ registerFocusInspectorFieldElement,
+} from './focus-inspector-field';
+
+export const TimelineTextContentField: React.FC<{
+ readonly field: SchemaFieldInfo;
+ readonly effectiveValue: unknown;
+ readonly propStatus: CanUpdateSequencePropStatusStatic;
+ readonly nodePath: SequencePropsSubscriptionKey | null;
+ readonly onDragEnd: () => void;
+ readonly onDragValueChange: TimelineFieldOnDragValueChange;
+ readonly onSave: TimelineFieldOnSave;
+}> = ({
+ effectiveValue,
+ field,
+ nodePath,
+ onDragEnd,
+ onDragValueChange,
+ onSave,
+ propStatus,
+}) => {
+ const inputRef = useRef<HTMLTextAreaElement>(null);
+ const currentValue = String(effectiveValue ?? '');
+ const draftRef = useRef({
+ dirty: false,
+ value: currentValue,
+ });
+ const latestRef = useRef({
+ codeValue: propStatus.codeValue,
+ onDragEnd,
+ onDragValueChange,
+ onSave,
+ });
+
+ latestRef.current = {
+ codeValue: propStatus.codeValue,
+ onDragEnd,
+ onDragValueChange,
+ onSave,
+ };
+
+ if (!draftRef.current.dirty) {
+ draftRef.current.value = currentValue;
+ }
+
+ const commitPending = useCallback(() => {
+ if (!draftRef.current.dirty) {
+ return false;
+ }
+
+ const value = inputRef.current?.value ?? draftRef.current.value;
+ const savedValue = String(latestRef.current.codeValue ?? '');
+ draftRef.current = {
+ dirty: false,
+ value,
+ };
+
+ if (value === savedValue) {
+ latestRef.current.onDragEnd();
+ return false;
+ }
+
+ latestRef.current
+ .onSave(value)
+ .finally(() => {
+ if (!draftRef.current.dirty && draftRef.current.value === value) {
+ latestRef.current.onDragEnd();
+ }
+ })
+ .catch(() => undefined);
+
+ return true;
+ }, []);
+
+ const setInputRef = useCallback(
+ (element: HTMLTextAreaElement | null) => {
+ if (element === null && inputRef.current !== null) {
+ commitPending();
+ }
+
+ inputRef.current = element;
+ registerFocusInspectorFieldElement({
+ element,
+ fieldKey: field.key,
+ nodePath,
+ });
+ registerCommitPendingInspectorField({
+ commitPending: element === null ? null : commitPending,
+ fieldKey: field.key,
+ nodePath,
+ });
+ },
+ [commitPending, field.key, nodePath],
+ );
+
+ const onChange = useCallback(
+ (event: React.ChangeEvent<HTMLTextAreaElement>) => {
+ const {value} = event.currentTarget;
+ draftRef.current = {
+ dirty: true,
+ value,
+ };
+ latestRef.current.onDragValueChange(value);
+ },
+ [],
+ );
+
+ const onKeyDownCapture = useCallback(
+ (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
+ if (event.key === 'Escape') {
+ const savedValue = String(latestRef.current.codeValue ?? '');
+ draftRef.current = {
+ dirty: false,
+ value: savedValue,
+ };
+ event.currentTarget.value = savedValue;
+ latestRef.current.onDragEnd();
+ event.currentTarget.blur();
+ }
+ },
+ [],
+ );
+
+ return (
+ <RemTextarea
+ key={String(propStatus.codeValue ?? '')}
+ ref={setInputRef}
+ status="ok"
+ small
+ defaultValue={currentValue}
+ onBlur={commitPending}
+ onChange={onChange}
+ onKeyDownCapture={onKeyDownCapture}
+ style={{
+ boxSizing: 'border-box',
+ height: 40,
+ width: 160,
+ }}
+ />
+ );
+};
diff --git a/packages/studio/src/components/Timeline/focus-inspector-field.ts b/packages/studio/src/components/Timeline/focus-inspector-field.ts
new file mode 100644
index 0000000000..201d91f216
--- /dev/null
+++ b/packages/studio/src/components/Timeline/focus-inspector-field.ts
@@ -0,0 +1,86 @@
+import type {SequencePropsSubscriptionKey} from 'remotion';
+
+const serializeRegistryKey = ({
+ fieldKey,
+ nodePath,
+}: {
+ readonly fieldKey: string;
+ readonly nodePath: SequencePropsSubscriptionKey;
+}) => {
+ return JSON.stringify({fieldKey, nodePath});
+};
+
+const registeredFields = new Map<string, HTMLTextAreaElement>();
+const registeredCommitPendingCallbacks = new Map<string, () => boolean>();
+
+export const registerFocusInspectorFieldElement = ({
+ element,
+ fieldKey,
+ nodePath,
+}: {
+ readonly element: HTMLTextAreaElement | null;
+ readonly fieldKey: string;
+ readonly nodePath: SequencePropsSubscriptionKey | null;
+}) => {
+ if (nodePath === null) {
+ return;
+ }
+
+ const key = serializeRegistryKey({fieldKey, nodePath});
+
+ if (element === null) {
+ registeredFields.delete(key);
+ return;
+ }
+
+ registeredFields.set(key, element);
+};
+
+export const requestFocusInspectorField = ({
+ fieldKey,
+ nodePath,
+}: {
+ readonly fieldKey: string;
+ readonly nodePath: SequencePropsSubscriptionKey;
+}) => {
+ const element = registeredFields.get(
+ serializeRegistryKey({fieldKey, nodePath}),
+ );
+
+ requestAnimationFrame(() => {
+ element?.scrollIntoView({block: 'center'});
+ element?.focus();
+ element?.select();
+ });
+};
+
+export const registerCommitPendingInspectorField = ({
+ commitPending,
+ fieldKey,
+ nodePath,
+}: {
+ readonly commitPending: (() => boolean) | null;
+ readonly fieldKey: string;
+ readonly nodePath: SequencePropsSubscriptionKey | null;
+}) => {
+ if (nodePath === null) {
+ return;
+ }
+
+ const key = serializeRegistryKey({fieldKey, nodePath});
+ if (commitPending === null) {
+ registeredCommitPendingCallbacks.delete(key);
+ return;
+ }
+
+ registeredCommitPendingCallbacks.set(key, commitPending);
+};
+
+export const commitPendingInspectorFields = () => {
+ let committed = false;
+ for (const commitPending of registeredCommitPendingCallbacks.values()) {
+ committed = commitPending() || committed;
+ }
+
+ return committed;
+};
diff --git a/packages/studio/src/components/Timeline/timeline-field-display-utils.ts b/packages/studio/src/components/Timeline/timeline-field-display-utils.ts
index c774944509..ca475b393c 100644
--- a/packages/studio/src/components/Timeline/timeline-field-display-utils.ts
+++ b/packages/studio/src/components/Timeline/timeline-field-display-utils.ts
@@ -387,6 +387,9 @@ export const formatTimelineFieldValueForDisplay = ({
formatUnknownTimelineValueForDisplay(value)
);
+ case 'text-content':
+ return String(value);
+
case 'array':
case 'boolean':
case 'color':
diff --git a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
index 4ecf61fc91..f14a636495 100644
--- a/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
+++ b/packages/studio/src/components/Timeline/use-expanded-track-keyframe-rows.ts
@@ -102,6 +102,7 @@ export const useExpandedTrackKeyframeRows = ({
getDragOverrides,
getEffectDragOverrides,
propStatuses,
+ includeTextContent: false,
}),
[
propStatuses,
diff --git a/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts b/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts
index 09092a1037..1faf1cfa0d 100644
--- a/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts
+++ b/packages/studio/src/components/Timeline/use-timeline-expanded-tree.ts
@@ -17,9 +17,11 @@ import {useTimelineSelection} from './TimelineSelection';
export const useTimelineExpandedTree = ({
sequence,
nodePathInfo,
+ includeTextContent,
}: {
readonly sequence: TSequence;
readonly nodePathInfo: SequenceNodePathInfo;
+ readonly includeTextContent: boolean;
}) => {
const {getIsExpanded} = useContext(ExpandedTracksGetterContext);
const {toggleTrack} = useContext(ExpandedTracksSetterContext);
@@ -39,6 +41,7 @@ export const useTimelineExpandedTree = ({
getDragOverrides,
getEffectDragOverrides,
propStatuses: visualModePropStatuses,
+ includeTextContent,
}),
[
sequence,
@@ -46,6 +49,7 @@ export const useTimelineExpandedTree = ({
getDragOverrides,
getEffectDragOverrides,
visualModePropStatuses,
+ includeTextContent,
],
);
const selectedRowKeys = useMemo(
diff --git a/packages/studio/src/components/Timeline/use-timeline-height.ts b/packages/studio/src/components/Timeline/use-timeline-height.ts
index bfc1b36a5f..59b1eeb475 100644
--- a/packages/studio/src/components/Timeline/use-timeline-height.ts
+++ b/packages/studio/src/components/Timeline/use-timeline-height.ts
@@ -5,8 +5,8 @@ import type {TrackWithHash} from '../../helpers/get-timeline-sequence-sort-key';
import {
buildTimelineTree,
flattenVisibleTreeNodes,
- getTreeRowHeight,
getTimelineLayerHeight,
+ getTreeRowHeight,
TIMELINE_ITEM_BORDER_BOTTOM,
} from '../../helpers/timeline-layout';
import {ExpandedTracksGetterContext} from '../ExpandedTracksProvider';
@@ -62,6 +62,7 @@ export const useTimelineHeight = ({
getDragOverrides,
getEffectDragOverrides,
propStatuses,
+ includeTextContent: false,
});
const filteredTree = filterTimelineExpandedTree({
nodes: tree,
diff --git a/packages/studio/src/components/options-sidebar-tabs.ts b/packages/studio/src/components/options-sidebar-tabs.ts
new file mode 100644
index 0000000000..89a5e0d2c1
--- /dev/null
+++ b/packages/studio/src/components/options-sidebar-tabs.ts
@@ -0,0 +1,6 @@
+import {createRef} from 'react';
+
+export const optionsSidebarTabs = createRef<{
+ selectInspectorPanel: () => void;
+ selectRendersPanel: () => void;
+}>();
diff --git a/packages/studio/src/components/selected-outline-types.ts b/packages/studio/src/components/selected-outline-types.ts
index 82e97db35f..ad773401ff 100644
--- a/packages/studio/src/components/selected-outline-types.ts
+++ b/packages/studio/src/components/selected-outline-types.ts
@@ -1,9 +1,10 @@
import type {
+ CanUpdateSequencePropStatus,
CanUpdateSequencePropStatusKeyframed,
CanUpdateSequencePropStatusStatic,
+ InteractivitySchema,
InteractivitySchemaField,
SequencePropsSubscriptionKey,
- InteractivitySchema,
TSequence,
} from 'remotion';
import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';
@@ -33,6 +34,7 @@ export type SelectedOutlineTarget = {
readonly scaleDrag: SelectedOutlineScaleDragTarget | null;
readonly rotationDrag: SelectedOutlineRotationDragTarget | null;
readonly transformOriginDrag: SelectedOutlineTransformOriginDragTarget | null;
+ readonly textEdit: SelectedOutlineTextEditTarget | null;
readonly uvHandles: readonly SelectedOutlineUvHandle[];
};
@@ -42,6 +44,11 @@ export type SelectedOutlineEffectDropTarget = {
readonly nodePath: SequencePropsSubscriptionKey;
};
+export type SelectedOutlineTextEditTarget = {
+ readonly nodePath: SequencePropsSubscriptionKey;
+ readonly propStatus: CanUpdateSequencePropStatus;
+};
+
export type SelectedOutlineDragTarget = {
readonly propStatus:
| CanUpdateSequencePropStatusStatic
diff --git a/packages/studio/src/helpers/timeline-layout.ts b/packages/studio/src/helpers/timeline-layout.ts
index 168e2bdc9f..e1961e694d 100644
--- a/packages/studio/src/helpers/timeline-layout.ts
+++ b/packages/studio/src/helpers/timeline-layout.ts
@@ -4,12 +4,12 @@ import {
type AnySchemaFieldInfo,
type DragOverrides,
type EffectSchemaFieldInfo,
+ type InteractivitySchemaFieldInfo,
type SchemaFieldGroup,
type SchemaFieldGroupInfo,
type PropStatuses,
type SchemaFieldInfo,
type SequenceControls,
- type InteractivitySchemaFieldInfo,
} from '@remotion/studio-shared';
import type {
GetDragOverrides,
@@ -31,12 +31,12 @@ export type {
AnySchemaFieldInfo,
DragOverrides,
EffectSchemaFieldInfo,
+ InteractivitySchemaFieldInfo,
PropStatuses,
SchemaFieldGroup,
SchemaFieldGroupInfo,
SchemaFieldInfo,
SequenceControls,
- InteractivitySchemaFieldInfo,
};
export const TIMELINE_PADDING = 16;
@@ -81,12 +81,14 @@ export const buildTimelineTree = ({
getDragOverrides,
getEffectDragOverrides,
propStatuses,
+ includeTextContent,
}: {
sequence: TSequence;
nodePathInfo: SequenceNodePathInfo;
getDragOverrides: GetDragOverrides;
getEffectDragOverrides: GetEffectDragOverrides;
propStatuses: PropStatuses;
+ includeTextContent: boolean;
}): TimelineTreeNode[] => {
const roots: TimelineTreeNode[] = [];
const {sequenceSubscriptionKey, index, auxiliaryKeys, supportsEffects} =
@@ -99,6 +101,7 @@ export const buildTimelineTree = ({
getDragOverrides,
propStatuses,
nodePath: sequenceSubscriptionKey,
+ includeTextContent,
});
if (controlFields && controlFields.length > 0) {
@@ -237,6 +240,7 @@ export const getExpandedTrackHeight = ({
getDragOverrides: () => ({}),
getEffectDragOverrides: () => ({}),
propStatuses,
+ includeTextContent: false,
});
const flat = flattenVisibleTreeNodes({nodes: tree, getIsExpanded});