Skip to content

🎥 Make videos programmatically with React

Elements: Support component-owned sequences (#10101)

Igor Samokhovets26f195af8988
diff --git a/.agents/skills/publish-element/SKILL.md b/.agents/skills/publish-element/SKILL.md
index a7ae6ca779..f7e1c77957 100644
--- a/.agents/skills/publish-element/SKILL.md
+++ b/.agents/skills/publish-element/SKILL.md
@@ -26,9 +26,9 @@ bun run remotion
## 2. Perform the publication review
-Review the finished source, MDX page, and central definition against the Element Guidelines. Resolve placeholder content and finalize the description, display name, contributors, dimensions, duration, declared dependencies, preview padding, poster frame, and `preview` object. Confirm that `durationInFrames` is appropriate for both the preview and the `<Sequence>` installed into Studio, and that every external source import except `react`, `react-dom`, and `remotion` appears in `dependencies`. Remotion packages must use `version: null`; every non-Remotion package must use an exact semantic version, not a range or tag. Confirm that `posterUrl` and `videoUrl` use flat `https://remotion.media/elements/<category>-<slug>-preview.png` and `.mp4` paths. Preview assets are composited onto the standard background and use MP4 for broad browser, social-card, and embed compatibility, even when the Element itself supports transparency. These explicit URLs are the publishing source of truth.
+Review the finished source, MDX page, and central definition against the Element Guidelines. Resolve placeholder content and finalize the description, display name, contributors, dimensions, duration, `installationMode`, declared dependencies, preview padding, poster frame, and `preview` object. Confirm that `durationInFrames` is appropriate for both the preview and either the generated `<Sequence>` or component-owned Sequence installed into Studio. Use `installationMode: 'wrapped'` by default. Before approving `'component-owned-sequence'`, verify that the component owns the intended interactive Sequence, forwards `from`, `durationInFrames`, `name`, and `style`, defines its rendered dimensions, and remains movable and trimmable without an outer Sequence. Confirm that every external source import except `react`, `react-dom`, and `remotion` appears in `dependencies`. Remotion packages must use `version: null`; every non-Remotion package must use an exact semantic version, not a range or tag. Confirm that `posterUrl` and `videoUrl` use flat `https://remotion.media/elements/<category>-<slug>-preview.png` and `.mp4` paths. Preview assets are composited onto the standard background and use MP4 for broad browser, social-card, and embed compatibility, even when the Element itself supports transparency. These explicit URLs are the publishing source of truth.
-Re-check the technical implementation requirements from the [`scaffold-element` skill](../scaffold-element/SKILL.md): The reusable implementation must remain in one self-contained TSX file, fill its configured bounds without a wrapper `<Sequence>` or preview-only source padding, and leave outer placement to the surrounding project. Animated entrances must have exits with inline, hardcoded frame ranges on useful named `Interactive.*` elements. Inner control names must not repeat the Element display name.
+Re-check the technical implementation requirements from the [`scaffold-element` skill](../scaffold-element/SKILL.md): The reusable implementation must remain in one self-contained TSX file, fill its configured bounds without a preview-only wrapper `<Sequence>` or source padding, and leave outer placement to either the generated wrapper or its component-owned Sequence. Animated entrances must have exits with inline, hardcoded frame ranges on useful named `Interactive.*` elements. Inner control names must not repeat the Element display name.
When the Element has Studio-editable controls, also review it using the [interactivity best practices skill](../interactivity-best-practices/SKILL.md).
diff --git a/.agents/skills/scaffold-element/SKILL.md b/.agents/skills/scaffold-element/SKILL.md
index 9e712d71dc..e40bda5826 100644
--- a/.agents/skills/scaffold-element/SKILL.md
+++ b/.agents/skills/scaffold-element/SKILL.md
@@ -16,6 +16,7 @@ Choose an existing category and a kebab-case slug. Before creating files, determ
- Composition width, height, fps, and preview duration
- Installed Element duration, or `null` when it should adapt to the composition
- Fixed Element width and height, or `null` for both so it inherits the composition dimensions
+- Whether installation uses the default generated `<Sequence>` (`installationMode: 'wrapped'`) or the component already owns the one interactive Sequence users should edit (`installationMode: 'component-owned-sequence'`)
- Every external source dependency as `{name, version}`; use `null` for Remotion packages and an exact semantic version for every non-Remotion package
- Preview padding, which affects only the docs preview and not the Element bounds
- A provisional poster frame
@@ -42,11 +43,13 @@ Adapt the copied `index.mdx` to the production pattern: import `elementDefinitio
Implement only enough of the component to provide a visible starting point in the intended bounds. Keep the reusable implementation in one self-contained TSX source file. Make the component fill its bounds without adding a wrapper `<Sequence>` or source padding for the preview. Do not use `left`, `right`, `top`, or `bottom` to place the Element itself; the surrounding project owns placement.
+Use `installationMode: 'wrapped'` by default. Use `'component-owned-sequence'` only when the component already owns the one interactive Sequence that users should edit and forwards `from`, `durationInFrames`, `name`, and `style` to that Sequence and its rendered outline. A component-owned-sequence Element must also define its own rendered dimensions.
+
Follow the Element Guidelines for the component itself. When using Studio-editable controls, also follow the [interactivity best practices skill](../interactivity-best-practices/SKILL.md). Keep entrance and exit keyframes inline with hardcoded frame ranges on the useful named `Interactive.*` element so they can be adjusted in Studio. Do not repeat the Element display name in inner control names.
## 3. Register the development composition
-Import and register the component in `packages/docs/src/components/Elements/element-definitions.ts` using the planned preview metadata. Set `durationInFrames` to the duration used by both the preview and the `<Sequence>` installed into Studio. Declare every external source import in `dependencies` except `react`, `react-dom`, and `remotion`, which are provided by every Remotion project. Use `version: null` for Remotion packages and an exact semantic version for every non-Remotion package; version ranges and tags are not accepted. Add the explicit `preview` object next to the render metadata, including `posterUrl` and `videoUrl`. The URLs in this object are the source of truth for publishing; do not add a helper that derives production URLs from the Element slug.
+Import and register the component in `packages/docs/src/components/Elements/element-definitions.ts` using the planned preview metadata. Set `installationMode` explicitly. Set `durationInFrames` to the duration used by both the preview and either the generated `<Sequence>` or the component-owned Sequence installed into Studio. Declare every external source import in `dependencies` except `react`, `react-dom`, and `remotion`, which are provided by every Remotion project. Use `version: null` for Remotion packages and an exact semantic version for every non-Remotion package; version ranges and tags are not accepted. Add the explicit `preview` object next to the render metadata, including `posterUrl` and `videoUrl`. The URLs in this object are the source of truth for publishing; do not add a helper that derives production URLs from the Element slug.
Do not edit `packages/docs/src/remotion/Root.tsx`. It automatically creates a composition for every central definition using the same sizing and wrapper used by published Elements.
diff --git a/packages/docs/docs/studio-protocol/create-element-payload.mdx b/packages/docs/docs/studio-protocol/create-element-payload.mdx
index b405b15eed..8ac31047a6 100644
--- a/packages/docs/docs/studio-protocol/create-element-payload.mdx
+++ b/packages/docs/docs/studio-protocol/create-element-payload.mdx
@@ -52,10 +52,20 @@ Do not declare `react`, `react-dom`, or `remotion`; every Remotion project alrea
The preferred width and height, or `null` for an Element without fixed dimensions. Both values must be positive finite numbers.
+Studio uses these dimensions for the drag preview, drop position, and the generated `<Sequence>` when `installationMode` is `'wrapped'`. They are not passed to the component as `width` and `height` props when `installationMode` is `'component-owned-sequence'`.
+
### durationInFrames
The preferred duration shown while dragging. It must be a positive integer.
+### installationMode?<AvailableFrom v="4.0.506" />
+
+Controls how Studio installs the Element. The default is `'wrapped'`.
+
+Use `'wrapped'` for a regular visual component. Studio generates a [`<Sequence>`](/docs/sequence) around the component to provide its timing, name, dimensions, and position.
+
+Use `'component-owned-sequence'` only if the component already owns the one Sequence that should appear in the timeline and be editable in Studio. The component must accept and forward `from`, `durationInFrames`, `name`, and `style` to that Sequence and its rendered outline. It must also define its own rendered dimensions. Studio places timing and absolute positioning props directly on the component call instead of generating an outer Sequence.
+
## Return value
A `StudioElementPayload` with payload version `1`. Pass the returned object unchanged to a transport API instead of serializing it manually.
diff --git a/packages/docs/elements-template/index.mdx b/packages/docs/elements-template/index.mdx
index 81480971d1..fccf466ddb 100644
--- a/packages/docs/elements-template/index.mdx
+++ b/packages/docs/elements-template/index.mdx
@@ -25,6 +25,7 @@ export const elementDefinition = {
},
previewPadding: 0,
slug: 'category/element-title',
+ installationMode: 'wrapped',
width: 1920,
};
diff --git a/packages/docs/elements/guidelines.mdx b/packages/docs/elements/guidelines.mdx
index 01c7d4f4b1..0abdc11849 100644
--- a/packages/docs/elements/guidelines.mdx
+++ b/packages/docs/elements/guidelines.mdx
@@ -31,13 +31,15 @@ The caption Elements show the distinction: moving a pill between words, popping
## Design it for composition
-Size the Element to its smallest useful bounding box. Let the surrounding [`<Sequence>`](/docs/sequence) control its placement and duration. Set both dimensions to `null` if it adapts to the composition.
+Size the Element to its smallest useful bounding box. By default, let the [`<Sequence>`](/docs/sequence) generated during installation control its placement and duration. Set both dimensions to `null` if it adapts to the composition.
-Do not add internal padding only to improve the gallery preview.
+An Element that already owns the one interactive Sequence users should edit may set `installationMode: 'component-owned-sequence'` in its central definition. In this mode, the public component must accept and forward `from`, `durationInFrames`, `name`, and `style` to its Sequence and rendered outline. It must also define its own rendered dimensions because Element metadata dimensions are not passed as component props.
+
+Do not use the component-owned mode merely to remove markup: The Element needs to remain movable and trimmable through its component-owned Sequence. Do not add internal padding only to improve the gallery preview.
## Make animations complete
-Include an exit animation whenever there is an entrance animation. Animate properties within the Element, such as translation, scale, and opacity; leave placement to the surrounding `<Sequence>`.
+Include an exit animation whenever there is an entrance animation. Animate properties within the Element, such as translation, scale, and opacity; leave placement to the generated wrapper or the component-owned Sequence.
## Expose useful Studio controls
diff --git a/packages/docs/src/components/Elements/ElementPage.tsx b/packages/docs/src/components/Elements/ElementPage.tsx
index 700182a725..38839c974a 100644
--- a/packages/docs/src/components/Elements/ElementPage.tsx
+++ b/packages/docs/src/components/Elements/ElementPage.tsx
@@ -49,6 +49,7 @@ export const ElementPage: React.FC<ElementPageProps> = ({
elementWidth,
fps,
slug,
+ installationMode,
} = definition;
const [installStatus, setInstallStatus] = useState<InstallStatus>({
type: 'idle',
@@ -78,6 +79,7 @@ export const ElementPage: React.FC<ElementPageProps> = ({
durationInFrames,
slug,
sourceCode,
+ installationMode,
});
}, [
definition.dependencies,
@@ -87,6 +89,7 @@ export const ElementPage: React.FC<ElementPageProps> = ({
elementWidth,
slug,
sourceCode,
+ installationMode,
]);
const installElement = useCallback(async () => {
diff --git a/packages/docs/src/components/Elements/element-definitions.ts b/packages/docs/src/components/Elements/element-definitions.ts
index a011af10e4..19ca75b198 100644
--- a/packages/docs/src/components/Elements/element-definitions.ts
+++ b/packages/docs/src/components/Elements/element-definitions.ts
@@ -1,4 +1,7 @@
-import type {ElementDependency} from '@remotion/studio-protocol';
+import type {
+ ElementDependency,
+ ElementInstallationMode,
+} from '@remotion/studio-protocol';
import type {ComponentType} from 'react';
import {LiquidContours} from '../../../elements/backgrounds/liquid-contours/liquid-contours';
import {NotebookPaper} from '../../../elements/backgrounds/notebook-paper/notebook-paper';
@@ -40,6 +43,7 @@ export type ElementDefinition = {
readonly preview: ElementPreviewMetadata;
readonly previewPadding: number;
readonly slug: string;
+ readonly installationMode: ElementInstallationMode;
readonly width: number;
};
@@ -66,6 +70,7 @@ export const elementDefinitions = {
},
previewPadding: 0,
slug: 'backgrounds/liquid-contours',
+ installationMode: 'wrapped',
width: 1920,
},
'backgrounds/notebook-paper': {
@@ -89,6 +94,7 @@ export const elementDefinitions = {
},
previewPadding: 0,
slug: 'backgrounds/notebook-paper',
+ installationMode: 'wrapped',
width: 1920,
},
'backgrounds/paper-texture': {
@@ -113,6 +119,7 @@ export const elementDefinitions = {
},
previewPadding: 0,
slug: 'backgrounds/paper-texture',
+ installationMode: 'wrapped',
width: 1920,
},
'backgrounds/rotating-starburst': {
@@ -136,6 +143,7 @@ export const elementDefinitions = {
},
previewPadding: 0,
slug: 'backgrounds/rotating-starburst',
+ installationMode: 'wrapped',
width: 1920,
},
'overlays/location-lower-third': {
@@ -159,6 +167,7 @@ export const elementDefinitions = {
},
previewPadding: 300,
slug: 'overlays/location-lower-third',
+ installationMode: 'wrapped',
width: 1920,
},
'overlays/lower-third': {
@@ -183,6 +192,7 @@ export const elementDefinitions = {
},
previewPadding: 300,
slug: 'overlays/lower-third',
+ installationMode: 'wrapped',
width: 1920,
},
'data/horizontal-bar-chart': {
@@ -207,6 +217,7 @@ export const elementDefinitions = {
},
previewPadding: 56,
slug: 'data/horizontal-bar-chart',
+ installationMode: 'wrapped',
width: 1920,
},
'data/number-counter': {
@@ -236,6 +247,7 @@ export const elementDefinitions = {
},
previewPadding: 120,
slug: 'data/number-counter',
+ installationMode: 'wrapped',
width: 1920,
},
'data/product-offer': {
@@ -260,6 +272,7 @@ export const elementDefinitions = {
},
previewPadding: 90,
slug: 'data/product-offer',
+ installationMode: 'wrapped',
width: 1080,
},
'text/circle-marker': {
@@ -287,6 +300,7 @@ export const elementDefinitions = {
},
previewPadding: 120,
slug: 'text/circle-marker',
+ installationMode: 'wrapped',
width: 1920,
},
'text/crossed-off': {
@@ -312,6 +326,7 @@ export const elementDefinitions = {
},
previewPadding: 120,
slug: 'text/crossed-off',
+ installationMode: 'wrapped',
width: 1920,
},
'text/news-article-headline-highlight': {
@@ -336,6 +351,7 @@ export const elementDefinitions = {
},
previewPadding: 0,
slug: 'text/news-article-headline-highlight',
+ installationMode: 'wrapped',
width: 1920,
},
'text/strike-through': {
@@ -363,6 +379,7 @@ export const elementDefinitions = {
},
previewPadding: 120,
slug: 'text/strike-through',
+ installationMode: 'wrapped',
width: 1920,
},
'text/text-marker': {
@@ -388,6 +405,7 @@ export const elementDefinitions = {
},
previewPadding: 120,
slug: 'text/text-marker',
+ installationMode: 'wrapped',
width: 1920,
},
'captions/moving-pill-captions': {
@@ -416,6 +434,7 @@ export const elementDefinitions = {
},
previewPadding: 120,
slug: 'captions/moving-pill-captions',
+ installationMode: 'component-owned-sequence',
width: 1920,
},
'captions/popping-word-captions': {
@@ -443,6 +462,7 @@ export const elementDefinitions = {
},
previewPadding: 120,
slug: 'captions/popping-word-captions',
+ installationMode: 'component-owned-sequence',
width: 1920,
},
'captions/word-highlight-captions': {
@@ -470,6 +490,7 @@ export const elementDefinitions = {
},
previewPadding: 120,
slug: 'captions/word-highlight-captions',
+ installationMode: 'component-owned-sequence',
width: 1920,
},
} satisfies Record<string, ElementDefinition>;
diff --git a/packages/docs/src/test/elements.test.ts b/packages/docs/src/test/elements.test.ts
index 26e3398f2a..762f88b4d5 100644
--- a/packages/docs/src/test/elements.test.ts
+++ b/packages/docs/src/test/elements.test.ts
@@ -336,6 +336,22 @@ describe('Element preview definitions', () => {
}
});
+ test('only caption Elements use a component-owned Sequence', () => {
+ const componentOwnedSequenceSlugs = new Set([
+ 'captions/moving-pill-captions',
+ 'captions/popping-word-captions',
+ 'captions/word-highlight-captions',
+ ]);
+
+ for (const definition of elementDefinitionList) {
+ expect(definition.installationMode).toBe(
+ componentOwnedSequenceSlugs.has(definition.slug)
+ ? 'component-owned-sequence'
+ : 'wrapped',
+ );
+ }
+ });
+
test('declares every external source dependency centrally with a valid version', () => {
for (const element of productionElements) {
const definition = elementDefinitionList.find(
@@ -454,8 +470,9 @@ describe('Element preview definitions', () => {
}
});
- test('the Element template includes explicit flat preview URLs', () => {
+ test('the Element template includes explicit defaults and preview URLs', () => {
const template = readFileSync(path.join(templateRoot, 'index.mdx'), 'utf8');
+ expect(template).toContain("installationMode: 'wrapped'");
expect(template).toContain(
"posterUrl: 'https://remotion.media/elements/category-element-title-preview.png'",
);
diff --git a/packages/studio-protocol/src/drag-data.ts b/packages/studio-protocol/src/drag-data.ts
index 1d418c8b6d..feab714086 100644
--- a/packages/studio-protocol/src/drag-data.ts
+++ b/packages/studio-protocol/src/drag-data.ts
@@ -274,6 +274,7 @@ export const makeDragData = ((
durationInFrames: input.durationInFrames,
slug: input.slug,
sourceCode: input.sourceCode,
+ installationMode: input.installationMode,
}),
{
type: input.type,
diff --git a/packages/studio-protocol/src/element-drag-data.ts b/packages/studio-protocol/src/element-drag-data.ts
index 437c102909..51efda6ba3 100644
--- a/packages/studio-protocol/src/element-drag-data.ts
+++ b/packages/studio-protocol/src/element-drag-data.ts
@@ -4,6 +4,8 @@ import {
} from './component-drag-data';
import {isRecord, isValidPackageName} from './validation';
+export type ElementInstallationMode = 'wrapped' | 'component-owned-sequence';
+
export type ElementDependency =
| {
readonly name: `@remotion/${string}`;
@@ -20,6 +22,7 @@ export type ElementDragData = {
element: {
dependencies: ElementDependency[];
durationInFrames?: number;
+ installationMode?: ElementInstallationMode;
slug: string;
displayName: string;
sourceCode: string;
@@ -130,6 +133,7 @@ export const makeElementDragData = ({
durationInFrames,
slug,
sourceCode,
+ installationMode,
}: Omit<ElementDragData['element'], 'dependencies'> & {
dependencies: ElementDependency[];
}): ElementDragData => {
@@ -151,6 +155,7 @@ export const makeElementDragData = ({
dimensions,
displayName,
...(durationInFrames === undefined ? {} : {durationInFrames}),
+ ...(installationMode === undefined ? {} : {installationMode}),
slug,
sourceCode,
},
@@ -166,6 +171,11 @@ const isDimensions = (value: unknown): value is ComponentDimensions =>
Number.isFinite(value.height) &&
value.height > 0;
+const isElementInstallationMode = (
+ value: unknown,
+): value is ElementInstallationMode =>
+ value === 'wrapped' || value === 'component-owned-sequence';
+
const isDuration = (value: unknown): value is number =>
typeof value === 'number' &&
Number.isInteger(value) &&
@@ -189,6 +199,7 @@ export const parseElementDragData = (value: string): ElementDragData | null => {
durationInFrames,
slug,
sourceCode,
+ installationMode,
} = parsed.element;
const validDependencies =
Array.isArray(dependencies) && dependencies.length <= 100
@@ -207,6 +218,8 @@ export const parseElementDragData = (value: string): ElementDragData | null => {
validDependencies === null ||
!validDependencies.every(isElementDependency) ||
(durationInFrames !== undefined && !isDuration(durationInFrames)) ||
+ (installationMode !== undefined &&
+ !isElementInstallationMode(installationMode)) ||
(dimensions !== undefined &&
dimensions !== null &&
!isDimensions(dimensions))
@@ -219,6 +232,7 @@ export const parseElementDragData = (value: string): ElementDragData | null => {
durationInFrames,
slug,
sourceCode,
+ installationMode,
});
} catch {
return null;
diff --git a/packages/studio-protocol/src/element-payload.ts b/packages/studio-protocol/src/element-payload.ts
index cfd3665447..2c6c4561d7 100644
--- a/packages/studio-protocol/src/element-payload.ts
+++ b/packages/studio-protocol/src/element-payload.ts
@@ -7,6 +7,7 @@ import {
parseElementDragData,
type ElementDependency,
type ElementDragData,
+ type ElementInstallationMode,
} from './element-drag-data';
import {isRecord} from './validation';
@@ -21,6 +22,7 @@ export type CreateElementPayloadInput = {
readonly dependencies: readonly ElementDependency[];
readonly dimensions: ComponentDimensions | null;
readonly durationInFrames: number;
+ readonly installationMode?: ElementInstallationMode;
};
export type StudioElementPayload = ElementDragData & {
@@ -71,6 +73,15 @@ const assertCreateElementPayloadInput = (
throw new TypeError(
'durationInFrames must be an integer between 1 and 100000000',
);
+ if (
+ input.installationMode !== undefined &&
+ input.installationMode !== 'wrapped' &&
+ input.installationMode !== 'component-owned-sequence'
+ ) {
+ throw new TypeError(
+ 'installationMode must be "wrapped" or "component-owned-sequence"',
+ );
+ }
};
export const createElementPayload = (
@@ -85,6 +96,7 @@ export const createElementPayload = (
durationInFrames: input.durationInFrames,
slug: input.slug,
sourceCode: input.sourceCode,
+ installationMode: input.installationMode ?? 'wrapped',
});
const payload: StudioElementPayload = {
...constructed.data,
diff --git a/packages/studio-protocol/src/index.ts b/packages/studio-protocol/src/index.ts
index 265e339544..019e028fe5 100644
--- a/packages/studio-protocol/src/index.ts
+++ b/packages/studio-protocol/src/index.ts
@@ -47,7 +47,11 @@ export type {
} from './drag-preview-metadata';
export {setStudioDragData} from './drag-transport';
export type {EffectDragData} from './effect-drag-data';
-export type {ElementDependency, ElementDragData} from './element-drag-data';
+export type {
+ ElementDependency,
+ ElementDragData,
+ ElementInstallationMode,
+} from './element-drag-data';
export {
createElementPayload,
type CreateElementPayloadInput,
diff --git a/packages/studio-protocol/src/test/element-payload.test.ts b/packages/studio-protocol/src/test/element-payload.test.ts
index 4dddb33f63..b6fd84190a 100644
--- a/packages/studio-protocol/src/test/element-payload.test.ts
+++ b/packages/studio-protocol/src/test/element-payload.test.ts
@@ -3,6 +3,7 @@ import {parseDragData} from '../drag-data';
import {setStudioDragData} from '../drag-transport';
import {
createElementPayload,
+ parseStudioElementPayload,
type CreateElementPayloadInput,
} from '../element-payload';
@@ -17,6 +18,7 @@ const validInput = {
durationInFrames: 90,
slug: 'lower-third',
sourceCode: 'export const LowerThird = () => null;',
+ installationMode: 'component-owned-sequence',
} satisfies CreateElementPayloadInput;
const createInvalidPayload = (input: unknown) =>
@@ -36,10 +38,12 @@ test('creates one canonical Element payload for HTTP and drag transports', () =>
dimensions: {width: 800, height: 200},
displayName: 'Lower Third',
durationInFrames: 90,
+ installationMode: 'component-owned-sequence',
slug: 'lower-third',
sourceCode: 'export const LowerThird = () => null;',
},
});
+ expect(parseStudioElementPayload(payload)).toEqual(payload);
const data = new Map<string, string>();
const dataTransfer = {
@@ -57,11 +61,32 @@ test('creates one canonical Element payload for HTTP and drag transports', () =>
parseDragData({mimeType: mimeType!, payload: data.get(mimeType!)!}),
).toMatchObject({
type: 'element',
- data: {element: {displayName: 'Lower Third'}},
+ data: {
+ element: {
+ displayName: 'Lower Third',
+ installationMode: 'component-owned-sequence',
+ },
+ },
preview: {width: 800, height: 200, durationInFrames: 90},
});
});
+test('defaults new Element payloads to wrapped installation', () => {
+ const {installationMode: _installationMode, ...input} = validInput;
+ const payload = createElementPayload(input);
+ expect(payload.element.installationMode).toBe('wrapped');
+});
+
+test('rejects an invalid installation mode from Studio payloads', () => {
+ const payload = createElementPayload(validInput);
+ expect(
+ parseStudioElementPayload({
+ ...payload,
+ element: {...payload.element, installationMode: 'no'},
+ }),
+ ).toBe(null);
+});
+
test('rejects invalid Element authoring input with actionable errors', () => {
const cases: Array<{input: unknown; message: string}> = [
{
@@ -129,6 +154,11 @@ test('rejects invalid Element authoring input with actionable errors', () => {
input: {...validInput, durationInFrames: 0},
message: 'durationInFrames must be an integer between 1 and 100000000',
},
+ {
+ input: {...validInput, installationMode: 'no'},
+ message:
+ 'installationMode must be "wrapped" or "component-owned-sequence"',
+ },
];
for (const {input, message} of cases) {
diff --git a/packages/studio-server/src/preview-server/routes/insert-element.ts b/packages/studio-server/src/preview-server/routes/insert-element.ts
index 268c0932c3..410a2c61b0 100644
--- a/packages/studio-server/src/preview-server/routes/insert-element.ts
+++ b/packages/studio-server/src/preview-server/routes/insert-element.ts
@@ -69,6 +69,10 @@ export const insertElementHandler: ApiHandler<
throw new Error('from must be a non-negative integer');
}
+ const installationMode = element.installationMode ?? 'wrapped';
+ const componentOwnsSequence =
+ installationMode === 'component-owned-sequence';
+
RenderInternals.Log.trace(
{indent: false, logLevel},
`[insert-element] Received request for compositionFile="${compositionFile}" compositionId="${compositionId}" element="${element.slug}"`,
@@ -135,18 +139,32 @@ export const insertElementHandler: ApiHandler<
componentName: plan.componentName,
importName: plan.componentName,
importPath: plan.importPath,
- props: [],
- position: null,
+ props: componentOwnsSequence
+ ? [
+ ...(element.durationInFrames === undefined
+ ? []
+ : [
+ {
+ name: 'durationInFrames',
+ value: element.durationInFrames,
+ },
+ ]),
+ {name: 'name', value: element.displayName},
+ ]
+ : [],
+ position: componentOwnsSequence ? position : null,
},
- from: null,
+ from: componentOwnsSequence ? from : null,
prettierConfigOverride: null,
- wrapInSequence: {
- dimensions: element.dimensions,
- durationInFrames: element.durationInFrames ?? null,
- from,
- name: element.displayName,
- position,
- },
+ wrapInSequence: componentOwnsSequence
+ ? null
+ : {
+ dimensions: element.dimensions,
+ durationInFrames: element.durationInFrames ?? null,
+ from,
+ name: element.displayName,
+ position,
+ },
});
const finalPlan = await getElementInstallPlan({
diff --git a/packages/studio-server/src/test/insert-element.test.ts b/packages/studio-server/src/test/insert-element.test.ts
index 348e88cc5c..58e3c63ffc 100644
--- a/packages/studio-server/src/test/insert-element.test.ts
+++ b/packages/studio-server/src/test/insert-element.test.ts
@@ -48,7 +48,7 @@ const incomingElementSource =
const existingElementSource =
'export const LowerThird = () => <div>Locally changed</div>;\n';
-const element = {
+const element: InsertElementRequest['element'] = {
dependencies: [],
dimensions: {width: 900, height: 260},
durationInFrames: 72,
@@ -78,20 +78,7 @@ const makeFixture = () => {
addNewClientListener: () => () => undefined,
});
- const callHandler = (
- overwriteExisting: boolean,
- expectedFileState: InsertElementRequest['expectedFileState'] = null,
- ) => {
- const input: InsertElementRequest = {
- compositionFile: 'Root.tsx',
- compositionId: 'target',
- element,
- expectedFileState,
- from: null,
- overwriteExisting,
- position: null,
- };
-
+ const callHandlerWithInput = (input: InsertElementRequest) => {
return insertElementHandler({
binariesDirectory: null,
configFile: null,
@@ -111,6 +98,21 @@ const makeFixture = () => {
});
};
+ const callHandler = (
+ overwriteExisting: boolean,
+ expectedFileState: InsertElementRequest['expectedFileState'] = null,
+ ) => {
+ return callHandlerWithInput({
+ compositionFile: 'Root.tsx',
+ compositionId: 'target',
+ element,
+ expectedFileState,
+ from: null,
+ overwriteExisting,
+ position: null,
+ });
+ };
+
const prepareInstall = () => {
const input: PrepareElementInstallRequest = {
compositionFile: 'Root.tsx',
@@ -147,6 +149,7 @@ const makeFixture = () => {
return {
callHandler,
+ callHandlerWithInput,
cleanup,
prepareInstall,
compositionFile,
@@ -194,6 +197,36 @@ test('creates a new Element file without an overwrite conflict', async () => {
}
});
+test('installs an Element with a component-owned Sequence', async () => {
+ const fixture = makeFixture();
+ try {
+ const response = await fixture.callHandlerWithInput({
+ compositionFile: 'Root.tsx',
+ compositionId: 'target',
+ element: {...element, installationMode: 'component-owned-sequence'},
+ expectedFileState: null,
+ from: 30,
+ overwriteExisting: false,
+ position: {x: 120, y: 80},
+ });
+
+ expect(response).toEqual({success: true});
+ expect(readFileSync(fixture.elementFile, 'utf-8')).toBe(
+ incomingElementSource,
+ );
+ const composition = readFileSync(fixture.compositionFile, 'utf-8');
+ expect(composition).not.toContain('<Sequence');
+ expect(composition).toContain('<LowerThird');
+ expect(composition).toContain('durationInFrames={72}');
+ expect(composition).toContain('from={30}');
+ expect(composition).toContain('name="Lower Third"');
+ expect(composition).toContain("position: 'absolute'");
+ expect(composition).toContain("translate: '120px 80px'");
+ } finally {
+ fixture.cleanup();
+ }
+});
+
test('reuses an identical Element file without an overwrite conflict', async () => {
const fixture = makeFixture();
try {
diff --git a/packages/studio-shared/src/test/element-drag-data.test.ts b/packages/studio-shared/src/test/element-drag-data.test.ts
index 12cda2d697..5f4a0c8508 100644
--- a/packages/studio-shared/src/test/element-drag-data.test.ts
+++ b/packages/studio-shared/src/test/element-drag-data.test.ts
@@ -69,6 +69,22 @@ test('rejects element drag data without dependencies', () => {
).toBe(null);
});
+test('preserves component-owned-sequence Element drag data', () => {
+ const componentOwnedSequenceElement = {
+ ...validElement,
+ installationMode: 'component-owned-sequence' as const,
+ };
+ expect(
+ parseElementDragData(
+ JSON.stringify(makeElementDragData(componentOwnedSequenceElement)),
+ ),
+ ).toEqual({
+ type: 'remotion-element',
+ version: 1,
+ element: {...componentOwnedSequenceElement, durationInFrames: 120},
+ });
+});
+
test('accepts element drag data with null dimensions', () => {
const elementWithoutDimensions = {...validElement, dimensions: null};
expect(
@@ -165,6 +181,15 @@ test('rejects invalid element drag data', () => {
}),
),
).toBe(null);
+ expect(
+ parseElementDragData(
+ JSON.stringify({
+ type: 'remotion-element',
+ version: 1,
+ element: {...validElement, installationMode: 'no'},
+ }),
+ ),
+ ).toBe(null);
for (const dependencies of [
['@remotion/google-fonts'],
['--ignore-scripts'],