🎥 Make videos programmatically with React
`@remotion/studio`: Move project download to composition inspector (#10652)
Jonny Burger2000ae8b3f81
diff --git a/packages/studio/src/components/InspectorPanel/CompositionInspector.tsx b/packages/studio/src/components/InspectorPanel/CompositionInspector.tsxindex ee65601db3..8e642b7f1f 100644--- a/packages/studio/src/components/InspectorPanel/CompositionInspector.tsx+++ b/packages/studio/src/components/InspectorPanel/CompositionInspector.tsx@@ -6,10 +6,13 @@ import React, {useState,} from 'react';import type {_InternalTypes} from 'remotion';+import {getBrowserStudioOperations} from '../../helpers/browser-studio-operations';import {StudioServerConnectionCtx} from '../../helpers/client-id';import {CURRENT_COLOR} from '../../helpers/colors';+import {downloadBlob} from '../../helpers/download-blob';import {isStudioInteractivityEnabled} from '../../helpers/interactivity-enabled';import {BrowseElementsIcon} from '../../icons/browse-elements';+import {CloudDownloadIcon} from '../../icons/cloud-download';import {PicIcon} from '../../icons/frame';import {SolidIcon} from '../../icons/solid';import {FilmIcon} from '../../icons/video';@@ -17,6 +20,7 @@ import {VisualControlsContext} from '../../visual-controls/VisualControls';import {DefaultPropsEditor} from '../DefaultPropsEditor';import {useZodIfPossible} from '../get-zod-if-possible';import {VERTICAL_SCROLLBAR_CLASSNAME} from '../Menu/is-menu-item';+import {showNotification} from '../Notifications/NotificationCenter';import {ObserveDefaultPropsContext} from '../ObserveDefaultPropsContext';import {type DataEditorMode,@@ -77,9 +81,7 @@ const browseElementsArrowStyle: React.CSSProperties = {width: 12,};-const CompositionActions: React.FC<{- readonly readOnlyStudio: boolean;-}> = ({readOnlyStudio}) => {+const CompositionActions: React.FC = () => {const {canInsertAsset,canInsertComposition,@@ -91,6 +93,32 @@ const CompositionActions: React.FC<{insertComposition,insertSolid,} = useCompositionActions();+ const downloadProject = getBrowserStudioOperations()?.downloadProject ?? null;++ const onDownloadProject = useCallback(async () => {+ if (downloadProject === null) {+ return;+ }++ try {+ const {data, fileName} = await downloadProject();+ const arrayBuffer = data.buffer.slice(+ data.byteOffset,+ data.byteOffset + data.byteLength,+ ) as ArrayBuffer;+ downloadBlob(+ new Blob([arrayBuffer], {type: 'application/zip'}),+ fileName,+ );+ } catch (error) {+ showNotification(+ `Could not download project: ${+ error instanceof Error ? error.message : String(error)+ }`,+ 2000,+ );+ }+ }, [downloadProject]);const openElementsLibrary = useCallback(() => {window.open(@@ -101,8 +129,10 @@ const CompositionActions: React.FC<{}, []);if (- (readOnlyStudio && !canShowInsertSolid) ||- (!canShowInsertAsset && !canShowInsertComposition && !canShowInsertSolid)+ !canShowInsertAsset &&+ !canShowInsertComposition &&+ !canShowInsertSolid &&+ downloadProject === null) {return null;}@@ -169,6 +199,17 @@ const CompositionActions: React.FC<{</svg></InspectorQuickAction>) : null}+ {downloadProject ? (+ <InspectorQuickAction+ disabled={false}+ onClick={onDownloadProject}+ renderIcon={(color) => (+ <CloudDownloadIcon color={color} style={actionIconStyle} />+ )}+ >+ Download project+ </InspectorQuickAction>+ ) : null}</InspectorQuickActionsSection>);};@@ -341,7 +382,7 @@ export const CompositionInspector: React.FC<{setDefaultProps={setDefaultProps}/><CompositionVisualControlsSection readOnlyStudio={readOnlyStudio} />- <CompositionActions readOnlyStudio={readOnlyStudio} />+ <CompositionActions /></div>);};diff --git a/packages/studio/src/helpers/use-menu-structure.tsx b/packages/studio/src/helpers/use-menu-structure.tsxindex 875ef24bae..ce9643d153 100644--- a/packages/studio/src/helpers/use-menu-structure.tsx+++ b/packages/studio/src/helpers/use-menu-structure.tsx@@ -34,7 +34,6 @@ import {getBrowserStudioOperations} from './browser-studio-operations';import {checkFullscreenSupport} from './check-fullscreen-support';import {StudioServerConnectionCtx} from './client-id';import {CURRENT_COLOR} from './colors';-import {downloadBlob} from './download-blob';import {getFileManagerName} from './get-file-manager-name';import {getGitMenuItem} from './get-git-menu-item';import {useMobileLayout} from './mobile-layout';@@ -73,7 +72,6 @@ const getFileMenu = ({window.remotion_fileSystemPlatform,);const browserStudioOperations = getBrowserStudioOperations();- const downloadProject = browserStudioOperations?.downloadProject;const items: ComboboxValue[] = [readOnlyStudio? null@@ -143,46 +141,6 @@ const getFileMenu = ({quickSwitcherLabel: 'Override input props',}: null,- downloadProject- ? {- id: 'download-project',- value: 'download-project',- label: 'Download project',- onClick: async () => {- closeMenu();-- try {- const {data, fileName} = await downloadProject();- const arrayBuffer = data.buffer.slice(- data.byteOffset,- data.byteOffset + data.byteLength,- ) as ArrayBuffer;- downloadBlob(- new Blob([arrayBuffer], {type: 'application/zip'}),- fileName,- );- } catch (error) {- showNotification(- `Could not download project: ${- error instanceof Error ? error.message : String(error)- }`,- 2000,- );- }- },- type: 'item' as const,- keyHint: null,- leftItem: null,- subMenu: null,- quickSwitcherLabel: 'Download project',- }- : null,- !readOnlyStudio && downloadProject && browserStudioOperations === null- ? {- type: 'divider' as const,- id: 'open-project-divider',- }- : null,editorName && editorId && !readOnlyStudio? {id: 'open-in-editor',diff --git a/packages/studio/src/icons/cloud-download.tsx b/packages/studio/src/icons/cloud-download.tsxnew file mode 100644index 0000000000..ed6c42c179--- /dev/null+++ b/packages/studio/src/icons/cloud-download.tsx@@ -0,0 +1,14 @@+import type {SVGProps} from 'react';++export const CloudDownloadIcon: React.FC<+ SVGProps<SVGSVGElement> & {readonly color: string}+> = ({color, ...props}) => {+ return (+ <svg {...props} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">+ <path+ fill={color}+ d="M128 176c0-61.9 50.1-112 112-112 39.3 0 73.8 20.2 93.8 50.8 4.4 6.7 13.1 9.1 20.3 5.7 11.4-5.5 24.3-8.5 37.9-8.5 48.6 0 88 39.4 88 88 0 14.1-3.3 27.4-9.2 39.2-2 4.1-2.2 8.9-.5 13.1s5.2 7.6 9.5 9.1c37.4 13.1 64.2 48.8 64.2 90.6 0 53-43 96-96 96l-304 0c-61.9 0-112-50.1-112-112 0-53.7 37.8-98.6 88.2-109.5 4.3-.9 8.1-3.6 10.3-7.4s2.9-8.3 1.7-12.6c-2.7-9.7-4.2-19.9-4.2-30.5zM240 32c-79.5 0-144 64.5-144 144 0 8 .7 15.9 1.9 23.5-56.9 19.2-97.9 73-97.9 136.5 0 79.5 64.5 144 144 144l304 0c70.7 0 128-57.3 128-128 0-49.9-28.5-93-70.1-114.2 3.9-11.9 6.1-24.6 6.1-37.8 0-66.3-53.7-120-120-120-13.7 0-26.9 2.3-39.2 6.5-26.4-33.2-67.1-54.5-112.8-54.5zM371.3 307.3c6.2-6.2 6.2-16.4 0-22.6s-16.4-6.2-22.6 0L304 329.4 304 208c0-8.8-7.2-16-16-16s-16 7.2-16 16l0 121.4-44.7-44.7c-6.2-6.2-16.4-6.2-22.6 0s-6.2 16.4 0 22.6l72 72c6.2 6.2 16.4 6.2 22.6 0l72-72z"+ />+ </svg>+ );+};