Skip to content

🎥 Make videos programmatically with React

remove code editor

Jonny Burgerfe680ef3a240
diff --git a/packages/convert/app/components/timing-editor/CodeFrame.tsx b/packages/convert/app/components/timing-editor/CodeFrame.tsx
deleted file mode 100644
index 20d5cad993..0000000000
--- a/packages/convert/app/components/timing-editor/CodeFrame.tsx
+++ /dev/null
@@ -1,135 +0,0 @@
-import React, {useCallback, useEffect, useMemo, useState} from 'react';
-import {codeToHtml} from 'shikiji';
-import {DEFAULT_DAMPING, DEFAULT_MASS, DEFAULT_STIFFNESS} from './defaults';
-import {Tabs, TabsContent, TabsList, TabsTrigger} from '~/components/ui/tabs';
-import {Button} from '~/components/ui/button';
-import {Spacing} from './Spacing';
-import {copyText} from './copy-text';
-import toast, {Toaster} from 'react-hot-toast';
-
-type Props = {
- readonly damping: number;
- readonly mass: number;
- readonly stiffness: number;
- readonly overshotClamping: boolean;
- readonly reverse: boolean;
- readonly durationInFrames: number | null;
- readonly delay: number;
-};
-
-const CodeFrame: React.FC<
- Props & {
- readonly platform: 'remotion' | 'reanimated';
- }
-> = ({
- damping,
- mass,
- stiffness,
- overshotClamping,
- reverse,
- platform,
- durationInFrames,
- delay,
-}) => {
- const [h, setH] = useState<string | null>(null);
-
- const code = useMemo(() => {
- const isDefaultDamping = DEFAULT_DAMPING === damping;
- const isDefaultMass = DEFAULT_MASS === mass;
- const isDefaultStiffness = DEFAULT_STIFFNESS === stiffness;
-
- const isAllDefault =
- isDefaultDamping && isDefaultMass && isDefaultStiffness;
-
- const lines = [
- 'const spr = spring({',
- platform === 'remotion' ? ' frame,' : null,
- platform === 'remotion' ? ' fps,' : null,
- platform === 'reanimated' ? ' toValue: 1,' : null,
- isAllDefault ? null : ' config: {',
- isDefaultDamping ? null : ` damping: ${damping},`,
- isDefaultMass ? null : ` mass: ${mass},`,
- isDefaultStiffness ? null : ` stiffness: ${stiffness},`,
- isAllDefault ? null : ' },',
- durationInFrames === null || platform === 'reanimated'
- ? null
- : ` durationInFrames: ${durationInFrames},`,
- delay === 0 || platform === 'reanimated' ? null : ` delay: ${delay},`,
- overshotClamping ? ' overshootClamping: true,' : null,
- reverse ? ' reverse: true,' : null,
- '});',
- ]
- .filter(Boolean)
- .join('\n');
- return lines;
- }, [
- damping,
- mass,
- stiffness,
- platform,
- durationInFrames,
- delay,
- overshotClamping,
- reverse,
- ]);
-
- useEffect(() => {
- codeToHtml(code, {
- lang: 'javascript',
- theme: 'github-dark',
- }).then((html) => {
- setH(html);
- });
- }, [code]);
-
- const onClick = useCallback(async () => {
- try {
- await copyText(code);
- toast.success('Copied to clipboard!');
- } catch (err) {
- toast.error((err as Error).message);
- }
- }, [code]);
-
- return (
- <div>
- <div
- style={{
- backgroundColor: '#24292E',
- paddingTop: 14,
- paddingLeft: 20,
- height: 300,
- borderRadius: 8,
- }}
- >
- {h ? (
- <div
- dangerouslySetInnerHTML={{__html: h}}
- />
- ) : null}
- </div>
- <Spacing block y={1} />
- <Button style={{width: '100%'}} onClick={onClick}>
- Copy
- </Button>
- <Toaster />
- </div>
- );
-};
-
-export function CodeFrameTabs(props: Props) {
- return (
- <Tabs defaultValue="remotion">
- <TabsList className="grid w-full grid-cols-2">
- <TabsTrigger value="remotion">Remotion</TabsTrigger>
- <TabsTrigger value="reanimated">Reanimated</TabsTrigger>
- </TabsList>
- <TabsContent value="remotion">
- <CodeFrame platform="remotion" {...props} />
- </TabsContent>
- <TabsContent value="reanimated">
- <CodeFrame platform="reanimated" {...props} />
- </TabsContent>
- </Tabs>
- );
-}
diff --git a/packages/convert/app/components/timing-editor/Sidebar.tsx b/packages/convert/app/components/timing-editor/Sidebar.tsx
index aab8a4cd04..77df5d6a80 100644
--- a/packages/convert/app/components/timing-editor/Sidebar.tsx
+++ b/packages/convert/app/components/timing-editor/Sidebar.tsx
@@ -3,8 +3,6 @@ import {Slider} from '~/components/ui/slider';
import {SliderLabel} from './SliderLabel';
import {CheckboxWithLabel} from './CheckboxWithLabel';
import {Spacing} from './Spacing';
-import {CodeFrameTabs} from './CodeFrame';
-import {Tabs, TabsContent, TabsList, TabsTrigger} from '~/components/ui/tabs';
import {PADDING_LEFT} from './draw-trajectory';
export const Sidebar: React.FC<{
@@ -52,100 +50,79 @@ export const Sidebar: React.FC<{
borderLeft: '1px solid #242424',
}}
>
- <Tabs defaultValue="configuration">
- <TabsList className="grid w-full grid-cols-2">
- <TabsTrigger value="configuration">Configuration</TabsTrigger>
- <TabsTrigger value="code">Code</TabsTrigger>
- </TabsList>
- <TabsContent value="configuration">
- <Spacing y={3} />
- <Slider
- value={[mass]}
- min={0.3}
- step={0.1}
- max={10}
- onValueChange={onMassChange}
- onPointerUp={onRelease}
- />
- <SliderLabel label="mass" value={mass} toggleable={null} />
- <br />
- <Slider
- min={1}
- max={200}
- value={[damping]}
- onValueChange={onDampingChange}
- onPointerUp={onRelease}
- />
- <SliderLabel label="damping" value={damping} toggleable={null} />
- <br />
- <Slider
- min={1}
- max={200}
- value={[stiffness]}
- onValueChange={onStiffnessChange}
- onPointerUp={onRelease}
- />
- <SliderLabel toggleable={null} label="stiffness" value={stiffness} />
- <br />
- <Slider
- min={0}
- max={400}
- value={[delay]}
- onValueChange={(val) => {
- onDelayChange(val[0]);
- }}
- onPointerUp={onRelease}
- />
- <SliderLabel label="delay" toggleable={null} value={delay} />
- <br />
- <>
- <Slider
- min={1}
- max={200}
- value={[fixedDurationInFrames ?? calculatedDurationInFrames]}
- style={{opacity: fixedDurationInFrames === null ? 0.5 : 1}}
- onValueChange={(val) => {
- onDurationInFramesChange(val[0]);
- }}
- onPointerUp={onRelease}
- />
- <SliderLabel
- label="durationInFrames"
- toggleable={(enabled) => {
- if (enabled) {
- onDurationInFramesChange(calculatedDurationInFrames);
- } else {
- onDurationInFramesChange(null);
- }
- }}
- value={fixedDurationInFrames ?? null}
- />
- </>
- <br />
- <CheckboxWithLabel
- checked={overshootClamping}
- id="overshootClamping"
- onCheckedChange={onOvershootClampingChange}
- />
- <CheckboxWithLabel
- checked={reverse}
- id="reverse"
- onCheckedChange={onReverseChange}
- />
- <Spacing y={2} />
- </TabsContent>
- <TabsContent value="code">
- <CodeFrameTabs
- delay={delay}
- damping={damping}
- mass={mass}
- stiffness={stiffness}
- overshotClamping={overshootClamping}
- reverse={reverse}
- durationInFrames={fixedDurationInFrames}
- />
- </TabsContent>
- </Tabs>
+ <Spacing y={3} />
+ <Slider
+ value={[mass]}
+ min={0.3}
+ step={0.1}
+ max={10}
+ onValueChange={onMassChange}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel label="mass" value={mass} toggleable={null} />
+ <br />
+ <Slider
+ min={1}
+ max={200}
+ value={[damping]}
+ onValueChange={onDampingChange}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel label="damping" value={damping} toggleable={null} />
+ <br />
+ <Slider
+ min={1}
+ max={200}
+ value={[stiffness]}
+ onValueChange={onStiffnessChange}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel toggleable={null} label="stiffness" value={stiffness} />
+ <br />
+ <Slider
+ min={0}
+ max={400}
+ value={[delay]}
+ onValueChange={(val) => {
+ onDelayChange(val[0]);
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel label="delay" toggleable={null} value={delay} />
+ <br />
+ <Slider
+ min={1}
+ max={200}
+ value={[fixedDurationInFrames ?? calculatedDurationInFrames]}
+ style={{opacity: fixedDurationInFrames === null ? 0.5 : 1}}
+ onValueChange={(val) => {
+ onDurationInFramesChange(val[0]);
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="durationInFrames"
+ toggleable={(enabled) => {
+ if (enabled) {
+ onDurationInFramesChange(calculatedDurationInFrames);
+ } else {
+ onDurationInFramesChange(null);
+ }
+ }}
+ value={fixedDurationInFrames ?? null}
+ />
+ <br />
+ <CheckboxWithLabel
+ checked={overshootClamping}
+ id="overshootClamping"
+ onCheckedChange={onOvershootClampingChange}
+ />
+ <CheckboxWithLabel
+ checked={reverse}
+ id="reverse"
+ onCheckedChange={onReverseChange}
+ />
+ <Spacing y={2} />
</div>
);
};