🎥 Make videos programmatically with React
makes sense
Jonny Burgera636288ab145
diff --git a/packages/bundler/src/error-overlay/remotion-overlay/AskOnDiscord.tsx b/packages/bundler/src/error-overlay/remotion-overlay/AskOnDiscord.tsxnew file mode 100644index 0000000000..61289473b0--- /dev/null+++ b/packages/bundler/src/error-overlay/remotion-overlay/AskOnDiscord.tsx@@ -0,0 +1,11 @@+const DISCORD_LINK = 'https://discord.gg/6VzzNDwUwV';++import React, {useCallback} from 'react';+import {Button} from './Button';++export const AskOnDiscord: React.FC = () => {+ const openInBrowser = useCallback(() => {+ window.open(DISCORD_LINK, '_blank');+ }, []);+ return <Button onClick={openInBrowser}>Ask on Discord</Button>;+};diff --git a/packages/bundler/src/error-overlay/remotion-overlay/Button.tsx b/packages/bundler/src/error-overlay/remotion-overlay/Button.tsxnew file mode 100644index 0000000000..b7e89cb048--- /dev/null+++ b/packages/bundler/src/error-overlay/remotion-overlay/Button.tsx@@ -0,0 +1,30 @@+import React from 'react';++const INPUT_BORDER_COLOR_UNHOVERED = 'rgba(0, 0, 0, 0.6)';+const INPUT_BACKGROUND = '#2f363d';++const button: React.CSSProperties = {+ border: `1px solid ${INPUT_BORDER_COLOR_UNHOVERED}`,+ borderRadius: 4,+ backgroundColor: INPUT_BACKGROUND,+ appearance: 'none',+ fontFamily: 'inherit',+ fontSize: 14,+ color: 'white',+};++const buttonContainer: React.CSSProperties = {+ padding: 10,+ cursor: 'pointer',+ fontSize: 14,+};++export const Button: React.FC<{+ onClick: () => void;+}> = ({children, onClick}) => {+ return (+ <button style={button} type="button" onClick={onClick}>+ <div style={buttonContainer}>{children}</div>+ </button>+ );+};diff --git a/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsx b/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsxindex 8ee49021fc..02668e3111 100644--- a/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsx+++ b/packages/bundler/src/error-overlay/remotion-overlay/ErrorDisplay.tsx@@ -1,10 +1,15 @@import React from 'react';import {ErrorRecord} from '../react-overlay/listen-to-runtime-errors';+import {AskOnDiscord} from './AskOnDiscord';+import {OpenInEditor} from './OpenInEditor';+import {SearchGithubIssues} from './SearchGitHubIssues';import {StackElement} from './StackFrame';const container: React.CSSProperties = {width: '100%',maxWidth: 1000,+ paddingLeft: 14,+ paddingRight: 14,marginLeft: 'auto',marginRight: 'auto',fontFamily: 'SF Pro Text, sans-serif',@@ -15,6 +20,7 @@ const title: React.CSSProperties = {fontSize: '1.5em',fontWeight: 'bold',lineHeight: 1.5,+ marginBottom: 8,};const errName: React.CSSProperties = {@@ -31,6 +37,11 @@ const stack: React.CSSProperties = {marginBottom: '10vh',};+const spacer: React.CSSProperties = {+ width: 5,+ display: 'inline-block',+};+export const ErrorDisplay: React.FC<{display: ErrorRecord;}> = ({display}) => {@@ -49,6 +60,15 @@ export const ErrorDisplay: React.FC<{<br />{display.error.message}</div>+ {display.stackFrames.length > 0 ? (+ <>+ <OpenInEditor stack={display.stackFrames[0]} />+ <div style={spacer} />+ </>+ ) : null}+ <SearchGithubIssues message={display.error.message} />+ <div style={spacer} />+ <AskOnDiscord /><div style={stack}>{display.stackFrames.map((s, i) => {return (diff --git a/packages/bundler/src/error-overlay/remotion-overlay/OpenInEditor.tsx b/packages/bundler/src/error-overlay/remotion-overlay/OpenInEditor.tsxnew file mode 100644index 0000000000..521f71ebcb--- /dev/null+++ b/packages/bundler/src/error-overlay/remotion-overlay/OpenInEditor.tsx@@ -0,0 +1,26 @@+import React, {useCallback} from 'react';+import {StackFrame} from '../react-overlay/utils/stack-frame';+import {Button} from './Button';++export const OpenInEditor: React.FC<{+ stack: StackFrame;+}> = ({stack}) => {+ const openInBrowser = useCallback(() => {+ fetch(`/api/open-in-editor`, {+ method: 'post',+ headers: {+ 'content-type': 'application/json',+ },+ body: JSON.stringify({+ stack,+ }),+ })+ .then(() => {+ console.log('opened');+ })+ .catch((err) => {+ console.log('could not open', err);+ });+ }, [stack]);+ return <Button onClick={openInBrowser}>Open in editor</Button>;+};diff --git a/packages/bundler/src/error-overlay/remotion-overlay/SearchGitHubIssues.tsx b/packages/bundler/src/error-overlay/remotion-overlay/SearchGitHubIssues.tsxnew file mode 100644index 0000000000..523198edce--- /dev/null+++ b/packages/bundler/src/error-overlay/remotion-overlay/SearchGitHubIssues.tsx@@ -0,0 +1,16 @@+import React, {useCallback} from 'react';+import {Button} from './Button';++export const SearchGithubIssues: React.FC<{+ message: string;+}> = ({message}) => {+ const openInBrowser = useCallback(() => {+ window.open(+ `https://github.com/remotion-dev/remotion/issues?q=${encodeURIComponent(+ message+ )}`,+ '_blank'+ );+ }, [message]);+ return <Button onClick={openInBrowser}>Search GitHub Issues</Button>;+};diff --git a/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsx b/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsxindex 627c8fcedd..6cc6baa49f 100644--- a/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsx+++ b/packages/bundler/src/error-overlay/remotion-overlay/StackFrame.tsx@@ -1,5 +1,6 @@import React, {useCallback, useState} from 'react';import {StackFrame} from '../react-overlay/utils/stack-frame';+import {Button} from './Button';import {CaretDown, CaretRight} from './carets';import {CodeFrame} from './CodeFrame';import {formatLocation} from './format-location';@@ -30,25 +31,6 @@ const fnName: React.CSSProperties = {fontSize: 14,};-const INPUT_BORDER_COLOR_UNHOVERED = 'rgba(0, 0, 0, 0.6)';-const INPUT_BACKGROUND = '#2f363d';--const button: React.CSSProperties = {- border: `1px solid ${INPUT_BORDER_COLOR_UNHOVERED}`,- borderRadius: 4,- backgroundColor: INPUT_BACKGROUND,- appearance: 'none',- fontFamily: 'inherit',- fontSize: 14,- color: 'white',-};--const buttonContainer: React.CSSProperties = {- padding: 10,- cursor: 'pointer',- fontSize: 14,-};-export const StackElement: React.FC<{s: StackFrame;lineNumberWidth: number;@@ -70,11 +52,9 @@ export const StackElement: React.FC<{</div></div>{s._originalScriptCode ? (- <button style={button} type="button" onClick={toggleCodeFrame}>- <div style={buttonContainer}>- {showCodeFrame ? <CaretDown /> : <CaretRight />}- </div>- </button>+ <Button onClick={toggleCodeFrame}>+ {showCodeFrame ? <CaretDown /> : <CaretRight />}+ </Button>) : null}</div><div>diff --git a/packages/bundler/src/start-server.ts b/packages/bundler/src/start-server.tsindex 1ef6b242f8..03725b5de1 100644--- a/packages/bundler/src/start-server.ts+++ b/packages/bundler/src/start-server.ts@@ -84,12 +84,19 @@ export const startServer = async (});});+ app.use(express.json());app.post('/api/open-in-editor', (req, res) => {- const body = req.body as StackFrame;+ const body = req.body as {stack: StackFrame};+ if (!('stack' in body)) {+ throw new TypeError('Need to pass stack');+ }++ const stack = body.stack as StackFrame;+launchEditor(- body._originalFileName as string,- body._originalLineNumber as number,- body._originalColumnNumber as number+ path.resolve(process.cwd(), stack._originalFileName as string),+ stack._originalLineNumber as number,+ stack._originalColumnNumber as number);res.json({success: true,diff --git a/packages/bundler/src/webpack-config.ts b/packages/bundler/src/webpack-config.tsindex 5e19ce6f4b..e55d60f0e4 100644--- a/packages/bundler/src/webpack-config.ts+++ b/packages/bundler/src/webpack-config.ts@@ -99,6 +99,7 @@ export const webpackConfig = ({globalObject: 'this',filename: 'bundle.js',path: outDir,+ devtoolModuleFilenameTemplate: '[resource-path]',},devServer: {contentBase: path.resolve(__dirname, '..', 'web'),