🎥 Make videos programmatically with React
actually pretty good!
Jonny Burger561c10c2c655
diff --git a/packages/studio-server/src/preview-server/routes/install-dependency.ts b/packages/studio-server/src/preview-server/routes/install-dependency.tsindex 34d81d313b..83d9a5b7f0 100644--- a/packages/studio-server/src/preview-server/routes/install-dependency.ts+++ b/packages/studio-server/src/preview-server/routes/install-dependency.ts@@ -34,11 +34,13 @@ const getInstallCommand = ({export const handleInstallPackage: ApiHandler<InstallPackageRequest,InstallPackageResponse-> = async ({logLevel, remotionRoot, input: {packageName}}) => {- if (listOfInstallableRemotionPackages.includes(packageName) === false) {- return Promise.reject(- new Error(`Package ${packageName} is not allowed to be installed.`),- );+> = async ({logLevel, remotionRoot, input: {packageNames}}) => {+ for (const packageName of packageNames) {+ if (listOfInstallableRemotionPackages.includes(packageName) === false) {+ return Promise.reject(+ new Error(`Package ${packageName} is not allowed to be installed.`),+ );+ }}// TODO: Should set this to "undefined" if not in development@@ -53,7 +55,7 @@ export const handleInstallPackage: ApiHandler<const command = getInstallCommand({manager: manager.manager,- packages: [packageName],+ packages: packageNames,version: VERSION,});diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.tsindex 77b928b3e0..771912bc65 100644--- a/packages/studio-shared/src/api-requests.ts+++ b/packages/studio-shared/src/api-requests.ts@@ -192,7 +192,7 @@ export type RestartStudioRequest = {};export type RestartStudioResponse = {};export type InstallPackageRequest = {- packageName: InstallablePackage;+ packageNames: InstallablePackage[];};export type InstallPackageResponse = {};diff --git a/packages/studio/src/api/install-package.ts b/packages/studio/src/api/install-package.tsindex 3e532e190d..a7b0b9a9f5 100644--- a/packages/studio/src/api/install-package.ts+++ b/packages/studio/src/api/install-package.ts@@ -4,8 +4,8 @@ import type {} from '@remotion/studio-shared';import {callApi} from '../components/call-api';-export const installPackage = (- packageName: InstallablePackage,+export const installPackages = (+ packageNames: InstallablePackage[],): Promise<InstallPackageResponse> => {- return callApi('/api/install-package', {packageName});+ return callApi('/api/install-package', {packageNames});};diff --git a/packages/studio/src/components/InstallPackage.tsx b/packages/studio/src/components/InstallPackage.tsxindex 50f9329628..296ee4f604 100644--- a/packages/studio/src/components/InstallPackage.tsx+++ b/packages/studio/src/components/InstallPackage.tsx@@ -1,19 +1,27 @@-import type {InstallablePackage} from '@remotion/studio-shared';+import {+ listOfInstallableRemotionPackages,+ type InstallablePackage,+} from '@remotion/studio-shared';import React, {useCallback, useContext, useEffect} from 'react';import {VERSION} from 'remotion';-import {installPackage} from '../api/install-package';+import {installPackages} from '../api/install-package';import {restartStudio} from '../api/restart-studio';import {ShortcutHint} from '../error-overlay/remotion-overlay/ShortcutHint';import {StudioServerConnectionCtx} from '../helpers/client-id';+import {LIGHT_TEXT} from '../helpers/colors';import {useKeybinding} from '../helpers/use-keybinding';+import {Checkbox} from './Checkbox';+import {VERTICAL_SCROLLBAR_CLASSNAME} from './Menu/is-menu-item';import {ModalButton} from './ModalButton';import {ModalFooterContainer} from './ModalFooter';import {ModalHeader} from './ModalHeader';import {DismissableModal} from './NewComposition/DismissableModal';-import {Flex, Row} from './layout';+import {Flex, Row, Spacing} from './layout';const container: React.CSSProperties = {padding: 20,+ maxHeight: 400,+ overflowY: 'auto',};const text: React.CSSProperties = {@@ -38,12 +46,38 @@ type State =type: 'restarting';};-export const InstallPackageModal: React.FC<{- readonly packageName: InstallablePackage;-}> = ({packageName}) => {+export const InstallPackageModal: React.FC<{}> = () => {const [state, setState] = React.useState<State>({type: 'idle'});+ const [map, setMap] = React.useState<{[key in InstallablePackage]: boolean}>({+ '@remotion/animated-emoji': false,+ '@remotion/gif': false,+ '@remotion/lottie': false,+ '@remotion/media-utils': false,+ '@remotion/animation-utils': false,+ '@remotion/cloudrun': false,+ '@remotion/google-fonts': false,+ '@remotion/enable-scss': false,+ '@remotion/lambda': false,+ '@remotion/layout-utils': false,+ '@remotion/media-parser': false,+ '@remotion/motion-blur': false,+ '@remotion/noise': false,+ '@remotion/paths': false,+ '@remotion/rive': false,+ '@remotion/shapes': false,+ '@remotion/skia': false,+ '@remotion/studio': false,+ '@remotion/tailwind': false,+ '@remotion/three': false,+ '@remotion/transitions': false,+ '@remotion/zod-types': false,+ });const {previewServerState: ctx} = useContext(StudioServerConnectionCtx);+ const selectedPackages = (Object.keys(map) as InstallablePackage[]).filter(+ (pkg) => map[pkg],+ );+const onClick = useCallback(async () => {if (state.type === 'done') {setState({type: 'restarting'});@@ -53,16 +87,18 @@ export const InstallPackageModal: React.FC<{setState({type: 'installing'});try {- await installPackage(packageName);+ await installPackages(selectedPackages);setState({type: 'done'});} catch (err) {setState({type: 'error', error: err as Error});}- }, [packageName, state.type]);+ }, [selectedPackages, state.type]);++ const canSelectPackages = state.type === 'idle' && ctx.type === 'connected';const disabled =- (state.type !== 'idle' && state.type !== 'done') ||- ctx.type !== 'connected';+ !(canSelectPackages || state.type === 'done') ||+ selectedPackages.length === 0;const {registerKeybinding} = useKeybinding();useEffect(() => {@@ -89,26 +125,57 @@ export const InstallPackageModal: React.FC<{return (<DismissableModal>- <ModalHeader title="Install package" />- <div style={container}>+ <ModalHeader title="Install packages" />+ <div style={container} className={VERTICAL_SCROLLBAR_CLASSNAME}>{state.type === 'done' ? (<div style={text}>- The package was installed. It is recommended to restart the server.+ Installed package{selectedPackages.length === 1 ? '' : 's'}{' '}+ successfully. Restart the server to complete.</div>) : state.type === 'restarting' ? (<div style={text}>Restarting the Studio server...</div>) : state.type === 'installing' ? (<div style={text}>- The package is installing. Check your terminal for progress.+ Installing package{selectedPackages.length === 1 ? '' : 's'}. Check+ your terminal for progress.</div>) : (<div style={text}>- This will install the package {packageName}@{VERSION} from npm.+ {listOfInstallableRemotionPackages.map((pkg) => {+ return (+ <Row key={pkg} align="center">+ <Checkbox+ checked={map[pkg]}+ name={pkg}+ onChange={() => {+ setMap((prev) => ({...prev, [pkg]: !prev[pkg]}));+ }}+ disabled={!canSelectPackages}+ />+ <Spacing x={1.5} />+ <div+ style={{+ color: LIGHT_TEXT,+ fontSize: 15,+ lineHeight: 1.8,+ }}+ >+ {pkg}+ </div>+ </Row>+ );+ })}</div>)}</div><ModalFooterContainer><Row align="center">+ {state.type === 'idle' ? (+ <span style={{color: LIGHT_TEXT, fontSize: 13, lineHeight: 1.2}}>+ This will install {selectedPackages.length} package+ {selectedPackages.length === 1 ? '' : 's'} (v{VERSION})+ </span>+ ) : null}<Flex /><ModalButton onClick={onClick} disabled={disabled}>{state.type === 'restarting'diff --git a/packages/studio/src/components/Modals.tsx b/packages/studio/src/components/Modals.tsxindex d22c6dbade..83591779f5 100644--- a/packages/studio/src/components/Modals.tsx+++ b/packages/studio/src/components/Modals.tsx@@ -102,8 +102,8 @@ export const Modals: React.FC<{knownBugs={modalContextType.knownBugs}/>)}- {modalContextType && modalContextType.type === 'install-package' && (- <InstallPackageModal packageName={modalContextType.packageName} />+ {modalContextType && modalContextType.type === 'install-packages' && (+ <InstallPackageModal />)}{modalContextType && modalContextType.type === 'quick-switcher' && (diff --git a/packages/studio/src/error-overlay/remotion-overlay/ShortcutHint.tsx b/packages/studio/src/error-overlay/remotion-overlay/ShortcutHint.tsxindex 9e4f63a6c6..ec9da8d54f 100644--- a/packages/studio/src/error-overlay/remotion-overlay/ShortcutHint.tsx+++ b/packages/studio/src/error-overlay/remotion-overlay/ShortcutHint.tsx@@ -10,17 +10,19 @@ const container: React.CSSProperties = {marginLeft: 6,opacity: 0.6,verticalAlign: 'middle',+ fontSize: 14,};export const ShortcutHint: React.FC<{- keyToPress: string;- cmdOrCtrl: boolean;+ readonly keyToPress: string;+ readonly cmdOrCtrl: boolean;}> = ({keyToPress, cmdOrCtrl}) => {const style = useMemo((): React.CSSProperties => {if (keyToPress === '↵') {return {display: 'inline-block',transform: `translateY(2px)`,+ fontSize: 14,};}diff --git a/packages/studio/src/helpers/use-menu-structure.tsx b/packages/studio/src/helpers/use-menu-structure.tsxindex af8c9df906..332e69136e 100644--- a/packages/studio/src/helpers/use-menu-structure.tsx+++ b/packages/studio/src/helpers/use-menu-structure.tsx@@ -1,4 +1,3 @@-import {listOfInstallableRemotionPackages} from '@remotion/studio-shared';import {useContext, useMemo} from 'react';import {Internals} from 'remotion';import {NoReactInternals} from 'remotion/no-react';@@ -654,28 +653,31 @@ export const useMenuStructure = (].filter(Internals.truthy),quickSwitcherLabel: null,},- {- id: 'install' as const,- label: 'Install',- leaveLeftPadding: false,- items: listOfInstallableRemotionPackages.map((pkg) => ({- id: pkg,- value: pkg,- label: pkg,- onClick: () => {- closeMenu();- setSelectedModal({- type: 'install-package',- packageName: pkg,- });+ readOnlyStudio+ ? null+ : {+ id: 'install' as const,+ label: 'Packages',+ leaveLeftPadding: false,+ items: [+ {+ id: 'install-packages',+ value: 'install-packages',+ label: 'Install...',+ onClick: () => {+ closeMenu();+ setSelectedModal({+ type: 'install-packages',+ });+ },+ type: 'item' as const,+ keyHint: null,+ leftItem: null,+ subMenu: null,+ quickSwitcherLabel: `Install packages`,+ },+ ],},- type: 'item' as const,- keyHint: null,- leftItem: null,- subMenu: null,- quickSwitcherLabel: `Install ${pkg}`,- })),- },{id: 'help' as const,label: 'Help',diff --git a/packages/studio/src/state/modals.ts b/packages/studio/src/state/modals.tsindex f712f7a2a2..add91e149d 100644--- a/packages/studio/src/state/modals.ts+++ b/packages/studio/src/state/modals.ts@@ -10,7 +10,6 @@ import type {VideoImageFormat,X264Preset,} from '@remotion/renderer';-import type {InstallablePackage} from '@remotion/studio-shared';import type React from 'react';import {createContext} from 'react';import type {CompType} from '../components/NewComposition/DuplicateComposition';@@ -87,8 +86,7 @@ export type ModalState =knownBugs: Bug[];}| {- type: 'install-package';- packageName: InstallablePackage;+ type: 'install-packages';}| {type: 'quick-switcher';