🎥 Make videos programmatically with React
awesome
Jonny Burger158a6ec53f0e
diff --git a/packages/studio-server/src/codemods/duplicate-composition.ts b/packages/studio-server/src/codemods/duplicate-composition.tsindex ab4e0e3e9e..1919d1658a 100644--- a/packages/studio-server/src/codemods/duplicate-composition.ts+++ b/packages/studio-server/src/codemods/duplicate-composition.ts@@ -30,7 +30,7 @@ export const parseAndApplyCodemod = async ({});if (changesMade.length === 0) {- throw new Error('No changes were made to the file');+ throw new Error('Could not find changes to made to the file');}const output = recast.print(newAst, {diff --git a/packages/studio-server/src/codemods/recast-mods.ts b/packages/studio-server/src/codemods/recast-mods.tsindex 60e6ad5422..dc463f055d 100644--- a/packages/studio-server/src/codemods/recast-mods.ts+++ b/packages/studio-server/src/codemods/recast-mods.ts@@ -3,6 +3,7 @@ import type {Declaration,Expression,File,+ JSXAttribute,JSXFragment,Statement,VariableDeclarator,@@ -178,13 +179,14 @@ const mapJsxChild = () {return [c,- changeCompositionIdInJSXElement({+ changeComposition({jsxElement: c,newCompositionId: transformation.newId,newCompositionFps: transformation.newFps,newCompositionDurationInFrames: transformation.newDurationInFrames,newCompositionHeight: transformation.newHeight,newCompositionWidth: transformation.newWidth,+ newTagToUse: transformation.tag,changesMade,}),];@@ -195,7 +197,7 @@ const mapJsxChild = (compId === transformation.idToRename) {return [- changeCompositionIdInJSXElement({+ changeComposition({jsxElement: c,newCompositionId: transformation.newId,newCompositionFps: null,@@ -203,6 +205,7 @@ const mapJsxChild = (newCompositionHeight: null,newCompositionWidth: null,changesMade,+ newTagToUse: null,}),];}@@ -282,7 +285,7 @@ const getCompositionIdFromJSXElement = (return id[0];};-const changeCompositionIdInJSXElement = ({+const changeComposition = ({jsxElement,newCompositionId,newCompositionFps,@@ -290,6 +293,7 @@ const changeCompositionIdInJSXElement = ({newCompositionHeight,newCompositionWidth,changesMade,+ newTagToUse,}: {jsxElement: JSXFragment['children'][number];newCompositionId: string;@@ -297,6 +301,7 @@ const changeCompositionIdInJSXElement = ({newCompositionDurationInFrames: number | null;newCompositionHeight: number | null;newCompositionWidth: number | null;+ newTagToUse: 'Composition' | 'Still' | null;changesMade: Change[];}): JSXFragment['children'][number] => {if (jsxElement.type !== 'JSXElement') {@@ -311,131 +316,160 @@ const changeCompositionIdInJSXElement = ({return jsxElement;}- if (name.name !== 'Composition') {+ if (name.name !== 'Composition' && name.name !== 'Still') {return jsxElement;}- const attributes = openingElement.attributes.map((attribute) => {- if (attribute.type === 'JSXSpreadAttribute') {- return attribute;- }+ const attributes = openingElement.attributes+ .map((attribute) => {+ if (attribute.type === 'JSXSpreadAttribute') {+ return attribute;+ }- if (attribute.name.type === 'JSXNamespacedName') {- return attribute;- }-- // TODO: Support JSX- if (- attribute.name.name === 'id' &&- attribute.value &&- attribute.value.type === 'StringLiteral'- ) {- changesMade.push({- description: 'Replaced composition id',- });-- return {- ...attribute,- value: {...attribute.value, value: newCompositionId},- };- }-- if (- attribute.name.name === 'fps' &&- attribute.value &&- attribute.value.type === 'JSXExpressionContainer' &&- attribute.value.expression.type === 'NumericLiteral' &&- newCompositionFps !== null- ) {- changesMade.push({- description: 'Replaced FPS',- });-- return {- ...attribute,- value: {- ...attribute.value,- expression: {...attribute.value.expression, value: newCompositionFps},- },- };- }-- if (- attribute.name.name === 'durationInFrames' &&- attribute.value &&- attribute.value.type === 'JSXExpressionContainer' &&- attribute.value.expression.type === 'NumericLiteral' &&- newCompositionDurationInFrames !== null- ) {- changesMade.push({- description: 'Replaced durationInFrames',- });-- return {- ...attribute,- value: {- ...attribute.value,- expression: {- ...attribute.value.expression,- value: newCompositionDurationInFrames,+ if (attribute.name.type === 'JSXNamespacedName') {+ return attribute;+ }++ if (attribute.name.name === 'fps' && newTagToUse === 'Still') {+ changesMade.push({description: 'Removed fps attribute'});+ return null;+ }++ if (+ attribute.name.name === 'durationInFrames' &&+ newTagToUse === 'Still'+ ) {+ changesMade.push({description: 'Removed durationInFrames'});+ return null;+ }++ // TODO: Support JSX+ if (+ attribute.name.name === 'id' &&+ attribute.value &&+ attribute.value.type === 'StringLiteral'+ ) {+ changesMade.push({+ description: 'Replaced composition id',+ });++ return {+ ...attribute,+ value: {...attribute.value, value: newCompositionId},+ };+ }++ if (+ attribute.name.name === 'fps' &&+ attribute.value &&+ attribute.value.type === 'JSXExpressionContainer' &&+ attribute.value.expression.type === 'NumericLiteral' &&+ newCompositionFps !== null+ ) {+ changesMade.push({+ description: 'Replaced FPS',+ });++ return {+ ...attribute,+ value: {+ ...attribute.value,+ expression: {+ ...attribute.value.expression,+ value: newCompositionFps,+ },},- },- };- }-- if (- attribute.name.name === 'width' &&- attribute.value &&- attribute.value.type === 'JSXExpressionContainer' &&- attribute.value.expression.type === 'NumericLiteral' &&- newCompositionWidth !== null- ) {- changesMade.push({- description: 'Replaced width',- });-- return {- ...attribute,- value: {- ...attribute.value,- expression: {- ...attribute.value.expression,- value: newCompositionWidth,+ };+ }++ if (+ attribute.name.name === 'durationInFrames' &&+ attribute.value &&+ attribute.value.type === 'JSXExpressionContainer' &&+ attribute.value.expression.type === 'NumericLiteral' &&+ newCompositionDurationInFrames !== null+ ) {+ changesMade.push({+ description: 'Replaced durationInFrames',+ });++ return {+ ...attribute,+ value: {+ ...attribute.value,+ expression: {+ ...attribute.value.expression,+ value: newCompositionDurationInFrames,+ },},- },- };- }-- if (- attribute.name.name === 'height' &&- attribute.value &&- attribute.value.type === 'JSXExpressionContainer' &&- attribute.value.expression.type === 'NumericLiteral' &&- newCompositionHeight !== null- ) {- changesMade.push({- description: 'Replaced height',- });-- return {- ...attribute,- value: {- ...attribute.value,- expression: {- ...attribute.value.expression,- value: newCompositionHeight,+ };+ }++ if (+ attribute.name.name === 'width' &&+ attribute.value &&+ attribute.value.type === 'JSXExpressionContainer' &&+ attribute.value.expression.type === 'NumericLiteral' &&+ newCompositionWidth !== null+ ) {+ changesMade.push({+ description: 'Replaced width',+ });++ return {+ ...attribute,+ value: {+ ...attribute.value,+ expression: {+ ...attribute.value.expression,+ value: newCompositionWidth,+ },},- },- };- }+ };+ }- return attribute;- });+ if (+ attribute.name.name === 'height' &&+ attribute.value &&+ attribute.value.type === 'JSXExpressionContainer' &&+ attribute.value.expression.type === 'NumericLiteral' &&+ newCompositionHeight !== null+ ) {+ changesMade.push({+ description: 'Replaced height',+ });++ return {+ ...attribute,+ value: {+ ...attribute.value,+ expression: {+ ...attribute.value.expression,+ value: newCompositionHeight,+ },+ },+ };+ }++ return attribute;+ })+ .filter(Boolean) as JSXAttribute[];++ const newName = newTagToUse ?? name.name;+ if (newName !== name.name) {+ changesMade.push({+ description: `Changed tag`,+ });+ }return {...jsxElement,openingElement: {...jsxElement.openingElement,+ name: {+ ...name,+ name: newName,+ },attributes,},};diff --git a/packages/studio-shared/src/codemods.ts b/packages/studio-shared/src/codemods.tsindex 4fc9f27abd..97780e3891 100644--- a/packages/studio-shared/src/codemods.ts+++ b/packages/studio-shared/src/codemods.ts@@ -7,6 +7,7 @@ export type RecastCodemod =newWidth: number | null;newFps: number | null;newDurationInFrames: number | null;+ tag: 'Still' | 'Composition';}| {type: 'rename-composition';diff --git a/packages/studio/src/components/CompositionSelectorItem.tsx b/packages/studio/src/components/CompositionSelectorItem.tsxindex 7b931d5db6..00e0c1ea40 100644--- a/packages/studio/src/components/CompositionSelectorItem.tsx+++ b/packages/studio/src/components/CompositionSelectorItem.tsx@@ -181,7 +181,7 @@ export const CompositionSelectorItem: React.FC<{.catch((err) => {showNotification(`Could not delete composition: ${err.message}`,- 1000,+ 2000,);});},diff --git a/packages/studio/src/components/NewComposition/DuplicateComposition.tsx b/packages/studio/src/components/NewComposition/DuplicateComposition.tsxindex 42fae73282..8fa20ee883 100644--- a/packages/studio/src/components/NewComposition/DuplicateComposition.tsx+++ b/packages/studio/src/components/NewComposition/DuplicateComposition.tsx@@ -242,6 +242,7 @@ const DuplicateCompositionLoaded: React.FC<{newHeight: null,newId,newWidth: null,+ tag: type === 'still' ? 'Still' : 'Composition',},dryRun: true,});@@ -251,7 +252,7 @@ const DuplicateCompositionLoaded: React.FC<{}setCanApplyCodemod(res.success);- }, [newId, resolved.result.id]);+ }, [newId, resolved.result.id, type]);useEffect(() => {getCanApplyCodemod()@@ -278,6 +279,7 @@ const DuplicateCompositionLoaded: React.FC<{newHeight: hadDimensionsDefined ? Number(size.height) : null,newWidth: hadDimensionsDefined ? Number(size.width) : null,newId,+ tag: type === 'still' ? 'Still' : 'Composition',},dryRun: false,})@@ -299,7 +301,9 @@ const DuplicateCompositionLoaded: React.FC<{resolved.result.id,selectedFrameRate,setSelectedModal,- size,+ size.height,+ size.width,+ type,]);useEffect(() => {@@ -328,17 +332,22 @@ const DuplicateCompositionLoaded: React.FC<{<NewCompHeader title={'Duplicate ' + resolved.result.id} /><form><div style={content}>- <div style={optionRow}>- <div style={label}>Type</div>- <div style={rightRow}>- <Combobox- title="Type of composition"- style={comboBoxStyle}- values={typeValues}- selectedId={type}- />+ {initialCompType === 'composition' ? (+ // We allow converting from a composition to a still, but+ // not the other way around+ <div style={optionRow}>+ <div style={label}>Type</div>+ <div style={rightRow}>+ <Combobox+ title="Type of composition"+ style={comboBoxStyle}+ values={typeValues}+ selectedId={type}+ />+ </div></div>- </div>+ ) : null}+<div style={optionRow}><div style={label}>ID</div><div style={rightRow}>