🎥 Make videos programmatically with React
keybindings + copy code
Jonny Burgerb527c070729d
diff --git a/packages/cli/src/editor/components/Editor.tsx b/packages/cli/src/editor/components/Editor.tsxindex 0d2903b432..3c6f55e245 100644--- a/packages/cli/src/editor/components/Editor.tsx+++ b/packages/cli/src/editor/components/Editor.tsx@@ -30,6 +30,7 @@ import {HigherZIndex} from '../state/z-index';import {EditorContent} from './EditorContent';import {FramePersistor} from './FramePersistor';import {GlobalKeybindings} from './GlobalKeybindings';+import {KeyboardShortcuts} from './KeyboardShortcutsModal';import {NewComposition} from './NewComposition/NewComposition';import {UpdateModal} from './UpdateModal/UpdateModal';@@ -166,6 +167,10 @@ export const Editor: React.FC = () => {modalContextType.type === 'update' && (<UpdateModal info={modalContextType.info} />)}+ {modalContextType &&+ modalContextType.type === 'shortcuts' && (+ <KeyboardShortcuts />+ )}</HigherZIndex></HighestZIndexProvider></PlayerInternals.PlayerEventEmitterContext.Provider>diff --git a/packages/cli/src/editor/components/GlobalKeybindings.tsx b/packages/cli/src/editor/components/GlobalKeybindings.tsxindex 634cf4635d..58bb1ada14 100644--- a/packages/cli/src/editor/components/GlobalKeybindings.tsx+++ b/packages/cli/src/editor/components/GlobalKeybindings.tsx@@ -15,13 +15,20 @@ export const GlobalKeybindings: React.FC = () => {compType: 'composition',});});- const cKey = keybindings.registerKeybinding('keypress', 'c', () => {++ const cKey = keybindings.registerKeybinding('keypress', 't', () => {setCheckerboard((c) => !c);});+ const questionMark = keybindings.registerKeybinding('keypress', '?', () => {+ setSelectedModal({+ type: 'shortcuts',+ });+ });return () => {nKey.unregister();cKey.unregister();+ questionMark.unregister();};}, [keybindings, setCheckerboard, setSelectedModal]);diff --git a/packages/cli/src/editor/components/KeyboardShortcutsModal.tsx b/packages/cli/src/editor/components/KeyboardShortcutsModal.tsxnew file mode 100644index 0000000000..ad99bdec55--- /dev/null+++ b/packages/cli/src/editor/components/KeyboardShortcutsModal.tsx@@ -0,0 +1,114 @@+import React, {useCallback, useContext} from 'react';+import {ArrowLeft, ArrowRight, ShiftIcon} from '../icons/keys';+import {ModalsContext} from '../state/modals';+import {Row, Spacing} from './layout';+import {ModalContainer} from './ModalContainer';+import {NewCompHeader} from './ModalHeader';++const left: React.CSSProperties = {+ width: 100,+ paddingTop: 8,+ paddingBottom: 8,+};++const key: React.CSSProperties = {+ background: '#333',+ padding: '3px 6px',+ color: 'white',+ borderRadius: 3,+ border: '1px solid black',+ borderBottomWidth: 3,+ fontSize: 13,+ fontFamily: 'inherit',+};++const right: React.CSSProperties = {+ fontSize: 15,+};++const container: React.CSSProperties = {+ paddingLeft: 20,+ paddingRight: 40,+ paddingTop: 10,+ paddingBottom: 10,+};++export const KeyboardShortcuts: React.FC = () => {+ const {setSelectedModal} = useContext(ModalsContext);++ const onQuit = useCallback(() => {+ setSelectedModal(null);+ }, [setSelectedModal]);++ return (+ <ModalContainer onEscape={onQuit} onOutsideClick={onQuit}>+ <NewCompHeader title="Keyboard shortcuts" />+ <div style={container}>+ <Row align="center">+ <div style={left}>+ <kbd style={key}>+ <ShiftIcon />+ </kbd>+ <Spacing x={0.3} />+ <kbd style={key}>+ <ArrowLeft />+ </kbd>+ </div>+ <div style={right}>1 second back</div>+ </Row>+ <Row align="center">+ <div style={left}>+ <kbd style={key}>+ <ArrowLeft />+ </kbd>{' '}+ </div>+ <div style={right}>Previous frame</div>+ </Row>+ <Row align="center">+ <div style={left}>+ <kbd style={key}>Space</kbd>+ </div>+ <div style={right}>Play / Pause</div>+ </Row>+ <Row align="center">+ <div style={left}>+ <kbd style={key}>+ <ArrowRight />+ </kbd>+ </div>+ <div style={right}>Next frame</div>+ </Row>+ <Row align="center">+ <div style={left}>+ <kbd style={key}>+ <ShiftIcon />+ </kbd>+ <Spacing x={0.3} />+ <kbd style={key}>+ <ArrowRight />+ </kbd>{' '}+ </div>+ <div style={right}>1 second forward</div>+ </Row>+ <Row align="center">+ <div style={left}>+ <kbd style={key}>N</kbd>+ </div>+ <div style={right}>New composition</div>+ </Row>+ <Row align="center">+ <div style={left}>+ <kbd style={key}>T</kbd>+ </div>+ <div style={right}>Toggle checkerboard transparency</div>+ </Row>+ <Row align="center">+ <div style={left}>+ <kbd style={key}>?</kbd>+ </div>+ <div style={right}>Show keyboard shortcuts</div>+ </Row>+ </div>+ </ModalContainer>+ );+};diff --git a/packages/cli/src/editor/components/MenuToolbar.tsx b/packages/cli/src/editor/components/MenuToolbar.tsxindex c2878e1b37..bb7d856819 100644--- a/packages/cli/src/editor/components/MenuToolbar.tsx+++ b/packages/cli/src/editor/components/MenuToolbar.tsx@@ -196,7 +196,7 @@ export const MenuToolbar: React.FC = () => {},{id: 'checkerboard',- keyHint: 'C',+ keyHint: 'T',label: 'Transparency as checkerboard',onClick: () => {close();diff --git a/packages/cli/src/editor/components/NewComposition/NewCompCode.tsx b/packages/cli/src/editor/components/NewComposition/NewCompCode.tsxindex 41289f60b9..c69f99c7db 100644--- a/packages/cli/src/editor/components/NewComposition/NewCompCode.tsx+++ b/packages/cli/src/editor/components/NewComposition/NewCompCode.tsx@@ -6,8 +6,13 @@ const keywordColor = '#F97583';const makeProperty = (key: string,val: number | string,- type: 'const' | 'string'+ type: 'const' | 'string',+ raw: boolean) => {+ if (raw) {+ return makePropertyRaw(key, val, type);+ }+return [` `,<span key={key + 'key'} style={{color: propColor}}>@@ -38,6 +43,20 @@ const makeProperty = (];};+const makePropertyRaw = (+ key: string,+ val: number | string,+ type: 'const' | 'string'+) => {+ return [+ ` `,+ key,+ '=',+ type === 'string' ? ['"' + val + '"'].join('') : ['{', val, '}'].join(''),+ '\n',+ ].join('');+};+export const getNewCompositionCode = ({type,height,@@ -45,6 +64,7 @@ export const getNewCompositionCode = ({fps,durationInFrames,name,+ raw,}: {type: 'still' | 'composition';height: number;@@ -52,21 +72,32 @@ export const getNewCompositionCode = ({fps: number;durationInFrames: number;name: string;+ raw: boolean;}) => {+ const compName = type === 'still' ? 'Still' : 'Composition';++ const props = [+ ...makeProperty('id', name, 'string', raw),+ ...makeProperty('component', name, 'const', raw),+ ...(type === 'composition'+ ? makeProperty('durationInFrames', durationInFrames, 'const', raw)+ : []),+ ...makeProperty('height', height, 'const', raw),+ ...makeProperty('width', width, 'const', raw),+ ...(type === 'composition' ? makeProperty('fps', fps, 'const', raw) : []),+ ];++ if (raw) {+ return ['<', compName, '\n', ...props, '/>'].join('');+ }+return [`<`,<span key="compname" style={{color: '#79B8FF'}}>- {type === 'still' ? 'Still' : 'Composition'}+ {compName}</span>,<br key="linebr1" />,- ...makeProperty('id', name, 'string'),- ...makeProperty('component', name, 'const'),- ...(type === 'composition'- ? makeProperty('durationInFrames', durationInFrames, 'const')- : []),- ...makeProperty('height', height, 'const'),- ...makeProperty('width', width, 'const'),- ...(type === 'composition' ? makeProperty('fps', fps, 'const') : []),+ ...props,'/>',];};diff --git a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx b/packages/cli/src/editor/components/NewComposition/NewComposition.tsxindex f55162e8e8..2a279e1a0c 100644--- a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx+++ b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx@@ -7,6 +7,7 @@ import React, {} from 'react';import {Checkmark} from '../../icons/Checkmark';import {ModalsContext} from '../../state/modals';+import {CopyButton} from '../CopyButton';import {Spacing} from '../layout';import {ModalContainer} from '../ModalContainer';import {NewCompHeader} from '../ModalHeader';@@ -35,6 +36,7 @@ const panelRight: React.CSSProperties = {display: 'flex',justifyContent: 'center',alignItems: 'center',+ position: 'relative',};const pre: React.CSSProperties = {@@ -192,8 +194,32 @@ export const NewComposition: React.FC<{initialCompType: CompType}> = ({height: Number(height),width: Number(width),name,+ raw: false,})}</pre>+ <div+ style={{+ position: 'absolute',+ bottom: 10,+ right: 10,+ }}+ >+ <CopyButton+ label="Copy code"+ labelWhenCopied="Copied"+ textToCopy={+ getNewCompositionCode({+ type,+ durationInFrames: Number(durationInFrames),+ fps: Number(selectedFrameRate),+ height: Number(height),+ width: Number(width),+ name,+ raw: true,+ }) as string+ }+ />+ </div></div></div></ModalContainer>diff --git a/packages/cli/src/editor/components/UpdateCheck.tsx b/packages/cli/src/editor/components/UpdateCheck.tsxindex aeac0f71c0..1539d057ed 100644--- a/packages/cli/src/editor/components/UpdateCheck.tsx+++ b/packages/cli/src/editor/components/UpdateCheck.tsx@@ -1,5 +1,6 @@import React, {useCallback, useContext, useEffect, useState} from 'react';import {ModalsContext} from '../state/modals';+import {useZIndex} from '../state/z-index';type PackageManager = 'npm' | 'yarn' | 'unknown';@@ -23,6 +24,7 @@ const buttonStyle: React.CSSProperties = {export const UpdateCheck = () => {const [info, setInfo] = useState<UpdateInfo | null>(null);const {setSelectedModal} = useContext(ModalsContext);+ const {tabIndex} = useZIndex();const checkForUpdates = useCallback(() => {fetch('/update')@@ -53,7 +55,12 @@ export const UpdateCheck = () => {}return (- <button style={buttonStyle} onClick={openModal} type="button">+ <button+ tabIndex={tabIndex}+ style={buttonStyle}+ onClick={openModal}+ type="button"+ >Update available!</button>);diff --git a/packages/cli/src/editor/components/layout.tsx b/packages/cli/src/editor/components/layout.tsxindex 686f56ad99..d0b6b2cec7 100644--- a/packages/cli/src/editor/components/layout.tsx+++ b/packages/cli/src/editor/components/layout.tsx@@ -8,7 +8,7 @@ export const Spacing: React.FC<{}> = ({x = 0, y = 0}) => {const style = useMemo((): React.CSSProperties => {return {- display: 'block',+ display: 'inline-block',width: x * SPACING_UNIT,height: y * SPACING_UNIT,};diff --git a/packages/cli/src/editor/icons/keys.tsx b/packages/cli/src/editor/icons/keys.tsxnew file mode 100644index 0000000000..c9165a5c57--- /dev/null+++ b/packages/cli/src/editor/icons/keys.tsx@@ -0,0 +1,34 @@+import React from 'react';++export const ShiftIcon: React.FC = () => {+ return (+ <svg style={{width: 10}} viewBox="0 0 448 512">+ <path+ fill="currentColor"+ d="M48.048 304h73.798v128c0 26.51 21.49 48 48 48h108.308c26.51 0 48-21.49 48-48V304h73.789c42.638 0 64.151-51.731 33.941-81.941l-175.943-176c-18.745-18.745-49.137-18.746-67.882 0l-175.952 176C-16.042 252.208 5.325 304 48.048 304zM224 80l176 176H278.154v176H169.846V256H48L224 80z"+ />+ </svg>+ );+};++export const ArrowLeft: React.FC = () => {+ return (+ <svg style={{width: 10}} viewBox="0 0 448 512">+ <path+ fill="currentColor"+ d="M257.5 445.1l-22.2 22.2c-9.4 9.4-24.6 9.4-33.9 0L7 273c-9.4-9.4-9.4-24.6 0-33.9L201.4 44.7c9.4-9.4 24.6-9.4 33.9 0l22.2 22.2c9.5 9.5 9.3 25-.4 34.3L136.6 216H424c13.3 0 24 10.7 24 24v32c0 13.3-10.7 24-24 24H136.6l120.5 114.8c9.8 9.3 10 24.8.4 34.3z"+ />+ </svg>+ );+};++export const ArrowRight: React.FC = () => {+ return (+ <svg style={{width: 10}} viewBox="0 0 448 512">+ <path+ fill="currentColor"+ d="M190.5 66.9l22.2-22.2c9.4-9.4 24.6-9.4 33.9 0L441 239c9.4 9.4 9.4 24.6 0 33.9L246.6 467.3c-9.4 9.4-24.6 9.4-33.9 0l-22.2-22.2c-9.5-9.5-9.3-25 .4-34.3L311.4 296H24c-13.3 0-24-10.7-24-24v-32c0-13.3 10.7-24 24-24h287.4L190.9 101.2c-9.8-9.3-10-24.8-.4-34.3z"+ />+ </svg>+ );+};diff --git a/packages/cli/src/editor/state/modals.ts b/packages/cli/src/editor/state/modals.tsindex f9b9bce22a..874e1f18a8 100644--- a/packages/cli/src/editor/state/modals.ts+++ b/packages/cli/src/editor/state/modals.ts@@ -10,6 +10,9 @@ export type ModalState =| {type: 'update';info: UpdateInfo;+ }+ | {+ type: 'shortcuts';};export type ModalContextType = {