Skip to content

πŸŽ₯ Make videos programmatically with React

`@remotion/studio`: Refine Element installation confirmation (#9930)

Igor Samokhovets125296bb7ec3
diff --git a/packages/studio/src/components/Canvas.tsx b/packages/studio/src/components/Canvas.tsx
index 5bd855f0bb..1334c5ae32 100644
--- a/packages/studio/src/components/Canvas.tsx
+++ b/packages/studio/src/components/Canvas.tsx
@@ -59,6 +59,7 @@ import {EditorRulers} from './EditorRuler';
import {useIsRulerVisible} from './EditorRuler/use-is-ruler-visible';
import {getEffectDragData} from './effect-drag-and-drop';
import {subscribeToElementInstallRequests} from './element-install-request';
+import {ElementInstallConfirmation} from './ElementInstallConfirmation';
import {handleDrop} from './handle-drop';
import {
hasSvgFile,
@@ -76,60 +77,8 @@ import {useSvgImportDialog} from './SvgImportDialog';
import {getCurrentFrame} from './Timeline/imperative-state';
import {useResolvedStack} from './Timeline/use-resolved-stack';
-const elementInstallCompositionIdStyle: React.CSSProperties = {
- fontFamily: 'monospace',
- fontSize: 13,
-};
-
const elementInstallDependencyIgnoreList = ['react', 'react-dom', 'remotion'];
-const elementInstallDependencyListStyle: React.CSSProperties = {
- marginTop: 8,
- marginBottom: 0,
- paddingLeft: 24,
- listStyleType: 'disc',
-};
-
-const elementInstallDependencyStyle: React.CSSProperties = {
- color: 'inherit',
- fontFamily: 'monospace',
- fontSize: 13,
- lineHeight: 1.5,
-};
-
-const elementInstallCodeDetailsStyle: React.CSSProperties = {
- marginTop: 12,
- fontSize: 13,
-};
-
-const elementInstallCodeSummaryStyle: React.CSSProperties = {
- cursor: 'pointer',
- fontSize: 13,
- fontWeight: 500,
-};
-
-const elementInstallCodeBlockStyle: React.CSSProperties = {
- marginTop: 8,
- marginBottom: 0,
- maxHeight: 240,
- overflow: 'auto',
- padding: 12,
- borderRadius: 6,
- backgroundColor: 'rgba(255, 255, 255, 0.06)',
- fontSize: 12,
- lineHeight: 1.5,
- whiteSpace: 'pre',
-};
-
-const makeSourceControlsVisible = (sourceCode: string) => {
- return sourceCode.replace(
- /[\u200b-\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g,
- (character) => {
- return `\\u${character.codePointAt(0)?.toString(16).padStart(4, '0')}`;
- },
- );
-};
-
const getContainerStyle = (
editorZoomGestures: boolean,
): React.CSSProperties => ({
@@ -936,76 +885,24 @@ export const Canvas: React.FC<{
);
const sourceLabel =
activeElementInstallRequest.source.type === 'studio-protocol'
- ? `Requested by ${activeElementInstallRequest.source.origin}`
+ ? activeElementInstallRequest.source.origin
: 'Unverified drag-and-drop payload';
const accepted = await confirm({
title: 'Install Element',
message: (
- <>
- <strong>{sourceLabel}</strong>
- <br />
- <br />
- Install β€œ{activeElementInstallRequest.element.displayName}” into{' '}
- <code style={elementInstallCompositionIdStyle}>
- {activeElementInstallRequest.compositionId}
- </code>{' '}
- as <code>{preflight.plan.filePath}</code>?
- {preflight.plan.expectedFileState.exists ? (
- <>
- <br />
- <br />
- This replaces the existing Element source file.
- </>
- ) : null}
- <br />
- <br />
- Accepted source code and package lifecycle scripts run with this
- project&apos;s access to files and the network.
- {dependenciesToReview.length > 0 ? (
- <>
- <br />
- <br />
- Declared dependencies:
- <ul style={elementInstallDependencyListStyle}>
- {dependenciesToReview.map((packageName) => (
- <li key={packageName} style={elementInstallDependencyStyle}>
- {packageName}{' '}
- {missingPackages.includes(packageName)
- ? '(will install)'
- : '(already installed)'}
- </li>
- ))}
- </ul>
- </>
- ) : null}
- {ignoredDependencies.length > 0 ? (
- <details style={elementInstallCodeDetailsStyle}>
- <summary style={elementInstallCodeSummaryStyle}>
- Already available in this project (
- {ignoredDependencies.length})
- </summary>
- <ul style={elementInstallDependencyListStyle}>
- {ignoredDependencies.map((packageName) => (
- <li key={packageName} style={elementInstallDependencyStyle}>
- {packageName}
- </li>
- ))}
- </ul>
- </details>
- ) : null}
- <details style={elementInstallCodeDetailsStyle}>
- <summary style={elementInstallCodeSummaryStyle}>
- Review Element source
- </summary>
- <pre style={elementInstallCodeBlockStyle}>
- <code>
- {makeSourceControlsVisible(
- activeElementInstallRequest.element.sourceCode,
- )}
- </code>
- </pre>
- </details>
- </>
+ <ElementInstallConfirmation
+ displayName={activeElementInstallRequest.element.displayName}
+ sourceLabel={sourceLabel}
+ sourceIsUnverified={
+ activeElementInstallRequest.source.type === 'drag-and-drop'
+ }
+ compositionId={activeElementInstallRequest.compositionId}
+ filePath={preflight.plan.filePath}
+ overwritesExistingFile={preflight.plan.expectedFileState.exists}
+ dependenciesToReview={dependenciesToReview}
+ missingPackages={missingPackages}
+ sourceCode={activeElementInstallRequest.element.sourceCode}
+ />
),
confirmLabel: 'Install',
cancelLabel: 'Cancel',
diff --git a/packages/studio/src/components/ConfirmationDialog.tsx b/packages/studio/src/components/ConfirmationDialog.tsx
index df803c67bd..a714412ef0 100644
--- a/packages/studio/src/components/ConfirmationDialog.tsx
+++ b/packages/studio/src/components/ConfirmationDialog.tsx
@@ -20,11 +20,15 @@ const content: React.CSSProperties = {
padding: 16,
fontSize: 14,
flex: 1,
- minWidth: 420,
- maxWidth: 560,
+ width: 'min(600px, calc(100vw - 40px))',
+ minWidth: 0,
lineHeight: 1.4,
};
+const footerStyle: React.CSSProperties = {
+ minWidth: 0,
+};
+
export const useConfirmationDialog = (): ConfirmationDialogFunction => {
const {setSelectedModal} = useContext(ModalsContext);
@@ -126,7 +130,7 @@ export const ConfirmationDialog: React.FC<{
<ModalHeader title={state.title} onClose={onCancel} />
<form onSubmit={onSubmit}>
<div style={content}>{state.message}</div>
- <ModalFooterContainer>
+ <ModalFooterContainer style={footerStyle}>
<Row align="center">
<Flex />
<Button onClick={onCancel} style={cancelStyle}>
diff --git a/packages/studio/src/components/ElementInstallConfirmation.tsx b/packages/studio/src/components/ElementInstallConfirmation.tsx
new file mode 100644
index 0000000000..04daf9068c
--- /dev/null
+++ b/packages/studio/src/components/ElementInstallConfirmation.tsx
@@ -0,0 +1,312 @@
+import React from 'react';
+import {
+ INPUT_BACKGROUND,
+ LIGHT_TEXT,
+ WARNING_COLOR,
+ WHITE,
+ WHITE_ALPHA_12,
+} from '../helpers/colors';
+import {WarningTriangle} from './NewComposition/ValidationMessage';
+
+const container: React.CSSProperties = {
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 20,
+ color: WHITE,
+ fontFamily: 'sans-serif',
+ fontSize: 13,
+ lineHeight: 1.5,
+};
+
+const sectionStyle: React.CSSProperties = {
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 10,
+};
+
+const sectionTitleStyle: React.CSSProperties = {
+ margin: 0,
+ color: WHITE,
+ fontFamily: 'sans-serif',
+ fontSize: 13,
+ fontWeight: 600,
+ lineHeight: 1.5,
+};
+
+const metadataStyle: React.CSSProperties = {
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 8,
+ margin: 0,
+};
+
+const metadataRowStyle: React.CSSProperties = {
+ display: 'grid',
+ gridTemplateColumns: '100px minmax(0, 1fr)',
+ alignItems: 'baseline',
+ gap: 12,
+};
+
+const metadataTermStyle: React.CSSProperties = {
+ color: LIGHT_TEXT,
+ fontFamily: 'sans-serif',
+ fontSize: 13,
+ fontWeight: 500,
+ lineHeight: 1.5,
+};
+
+const metadataDescriptionStyle: React.CSSProperties = {
+ margin: 0,
+ minWidth: 0,
+ color: WHITE,
+ fontFamily: 'sans-serif',
+ fontSize: 13,
+ fontWeight: 400,
+ lineHeight: 1.5,
+ overflowWrap: 'anywhere',
+};
+
+const unverifiedSourceStyle: React.CSSProperties = {
+ ...metadataDescriptionStyle,
+ color: WARNING_COLOR,
+};
+
+const codeStyle: React.CSSProperties = {
+ color: 'inherit',
+ fontFamily: 'monospace',
+ fontSize: 13,
+ lineHeight: 1.5,
+};
+
+const overwriteStyle: React.CSSProperties = {
+ margin: 0,
+ color: WARNING_COLOR,
+ fontFamily: 'sans-serif',
+ fontSize: 13,
+ fontWeight: 500,
+ lineHeight: 1.5,
+};
+
+const dependencyListStyle: React.CSSProperties = {
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 8,
+ margin: 0,
+ padding: 0,
+ listStyleType: 'none',
+};
+
+const dependencyRowStyle: React.CSSProperties = {
+ display: 'flex',
+ alignItems: 'baseline',
+ justifyContent: 'space-between',
+ gap: 16,
+ minWidth: 0,
+};
+
+const dependencyNameStyle: React.CSSProperties = {
+ minWidth: 0,
+ color: WHITE,
+ fontFamily: 'monospace',
+ fontSize: 13,
+ lineHeight: 1.5,
+ overflowWrap: 'anywhere',
+};
+
+const dependencyInstallStatusStyle: React.CSSProperties = {
+ flexShrink: 0,
+ color: WARNING_COLOR,
+ fontFamily: 'sans-serif',
+ fontSize: 13,
+ fontWeight: 500,
+ lineHeight: 1.5,
+};
+
+const dependencyInstalledStatusStyle: React.CSSProperties = {
+ ...dependencyInstallStatusStyle,
+ color: LIGHT_TEXT,
+};
+
+const warningStyle: React.CSSProperties = {
+ display: 'flex',
+ alignItems: 'flex-start',
+ gap: 10,
+ minWidth: 0,
+};
+
+const warningIconStyle: React.CSSProperties = {
+ width: 16,
+ height: 16,
+ marginTop: 1,
+ flexShrink: 0,
+ fill: WARNING_COLOR,
+};
+
+const warningDescriptionStyle: React.CSSProperties = {
+ margin: 0,
+ minWidth: 0,
+ color: LIGHT_TEXT,
+ fontFamily: 'sans-serif',
+ fontSize: 13,
+ fontWeight: 400,
+ lineHeight: 1.5,
+};
+
+const sourceDetailsStyle: React.CSSProperties = {
+ paddingTop: 2,
+ fontFamily: 'sans-serif',
+ fontSize: 13,
+ lineHeight: 1.5,
+};
+
+const sourceSummaryStyle: React.CSSProperties = {
+ cursor: 'pointer',
+ color: WHITE,
+ fontFamily: 'sans-serif',
+ fontSize: 13,
+ fontWeight: 500,
+ lineHeight: 1.5,
+};
+
+const sourceCodeBlockStyle: React.CSSProperties = {
+ marginTop: 10,
+ marginBottom: 0,
+ maxHeight: 240,
+ overflow: 'auto',
+ padding: 12,
+ border: `1px solid ${WHITE_ALPHA_12}`,
+ borderRadius: 6,
+ backgroundColor: INPUT_BACKGROUND,
+ color: WHITE,
+ fontFamily: 'monospace',
+ fontSize: 12,
+ lineHeight: 1.5,
+ whiteSpace: 'pre',
+};
+
+const sourceCodeStyle: React.CSSProperties = {
+ color: 'inherit',
+ fontFamily: 'inherit',
+ fontSize: 'inherit',
+ lineHeight: 'inherit',
+};
+
+const makeSourceControlsVisible = (sourceCode: string) => {
+ return sourceCode.replace(
+ /[\u200b-\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g,
+ (character) => {
+ return `\\u${character.codePointAt(0)?.toString(16).padStart(4, '0')}`;
+ },
+ );
+};
+
+export const ElementInstallConfirmation: React.FC<{
+ readonly displayName: string;
+ readonly sourceLabel: string;
+ readonly sourceIsUnverified: boolean;
+ readonly compositionId: string;
+ readonly filePath: string;
+ readonly overwritesExistingFile: boolean;
+ readonly dependenciesToReview: string[];
+ readonly missingPackages: string[];
+ readonly sourceCode: string;
+}> = ({
+ displayName,
+ sourceLabel,
+ sourceIsUnverified,
+ compositionId,
+ filePath,
+ overwritesExistingFile,
+ dependenciesToReview,
+ missingPackages,
+ sourceCode,
+}) => {
+ return (
+ <div style={container}>
+ <dl style={metadataStyle} aria-label="Installation details">
+ <div style={metadataRowStyle}>
+ <dt style={metadataTermStyle}>Element</dt>
+ <dd style={metadataDescriptionStyle}>{displayName}</dd>
+ </div>
+ <div style={metadataRowStyle}>
+ <dt style={metadataTermStyle}>Request source</dt>
+ <dd
+ style={
+ sourceIsUnverified
+ ? unverifiedSourceStyle
+ : metadataDescriptionStyle
+ }
+ >
+ {sourceLabel}
+ </dd>
+ </div>
+ <div style={metadataRowStyle}>
+ <dt style={metadataTermStyle}>Composition</dt>
+ <dd style={metadataDescriptionStyle}>
+ <code style={codeStyle}>{compositionId}</code>
+ </dd>
+ </div>
+ <div style={metadataRowStyle}>
+ <dt style={metadataTermStyle}>Destination</dt>
+ <dd style={metadataDescriptionStyle}>
+ <code style={codeStyle}>{filePath}</code>
+ </dd>
+ </div>
+ {overwritesExistingFile ? (
+ <div style={metadataRowStyle}>
+ <dt style={metadataTermStyle}>File change</dt>
+ <dd style={overwriteStyle}>Replace existing source file</dd>
+ </div>
+ ) : null}
+ </dl>
+
+ {dependenciesToReview.length > 0 ? (
+ <section
+ style={sectionStyle}
+ aria-labelledby="element-install-dependencies"
+ >
+ <h3 id="element-install-dependencies" style={sectionTitleStyle}>
+ Dependencies
+ </h3>
+ <ul style={dependencyListStyle} role="list">
+ {dependenciesToReview.map((packageName) => {
+ const willInstall = missingPackages.includes(packageName);
+ return (
+ <li key={packageName} style={dependencyRowStyle}>
+ <div style={dependencyNameStyle}>{packageName}</div>
+ <div
+ style={
+ willInstall
+ ? dependencyInstallStatusStyle
+ : dependencyInstalledStatusStyle
+ }
+ >
+ {willInstall ? 'Will be installed' : 'Installed'}
+ </div>
+ </li>
+ );
+ })}
+ </ul>
+ </section>
+ ) : null}
+
+ <div style={warningStyle}>
+ <WarningTriangle style={warningIconStyle} />
+ <p style={warningDescriptionStyle}>
+ This adds executable source code to your project. Package lifecycle
+ scripts may also run during installation, with access to your files
+ and the network.
+ </p>
+ </div>
+
+ <details style={sourceDetailsStyle}>
+ <summary style={sourceSummaryStyle}>Source code</summary>
+ <pre style={sourceCodeBlockStyle}>
+ <code style={sourceCodeStyle}>
+ {makeSourceControlsVisible(sourceCode)}
+ </code>
+ </pre>
+ </details>
+ </div>
+ );
+};
diff --git a/packages/studio/src/components/ModalFooter.tsx b/packages/studio/src/components/ModalFooter.tsx
index 28245f59f4..efcd448505 100644
--- a/packages/studio/src/components/ModalFooter.tsx
+++ b/packages/studio/src/components/ModalFooter.tsx
@@ -11,6 +11,11 @@ const content: React.CSSProperties = {
export const ModalFooterContainer: React.FC<{
readonly children: React.ReactNode;
-}> = ({children}) => {
- return <div style={{...content, borderTop: BORDER_BLACK}}>{children}</div>;
+ readonly style?: React.CSSProperties;
+}> = ({children, style}) => {
+ return (
+ <div style={{...content, ...style, borderTop: BORDER_BLACK}}>
+ {children}
+ </div>
+ );
};