Skip to content

🎥 Make videos programmatically with React

commands

Jonny Burger1a1d88a5f107
diff --git a/packages/cli/src/editor/components/MenuToolbar.tsx b/packages/cli/src/editor/components/MenuToolbar.tsx
index 1e1f865914..db318c1792 100644
--- a/packages/cli/src/editor/components/MenuToolbar.tsx
+++ b/packages/cli/src/editor/components/MenuToolbar.tsx
@@ -1,22 +1,10 @@
-import React, {useCallback, useContext, useMemo, useState} from 'react';
-import {Internals} from 'remotion';
+import React, {useCallback, useMemo, useState} from 'react';
import {BACKGROUND} from '../helpers/colors';
-import {pickColor} from '../helpers/pick-color';
-import {areKeyboardShortcutsDisabled} from '../helpers/use-keybinding';
-import {Checkmark} from '../icons/Checkmark';
-import {CheckerboardContext} from '../state/checkerboard';
-import {ModalsContext} from '../state/modals';
-import {PreviewSizeContext} from '../state/preview-size';
-import {RichTimelineContext} from '../state/rich-timeline';
-import type {SidebarCollapsedState} from '../state/sidebar';
-import {SidebarContext} from '../state/sidebar';
-import {timelineRef} from '../state/timeline-ref';
+import {useMenuStructure} from '../helpers/use-menu-structure';
import {Row} from './layout';
-import type {Menu, MenuId} from './Menu/MenuItem';
+import type {MenuId} from './Menu/MenuItem';
import {MenuItem} from './Menu/MenuItem';
import {MenuBuildIndicator} from './MenuBuildIndicator';
-import {getPreviewSizeLabel, getUniqueSizes} from './SizeSelector';
-import {inOutHandles} from './TimelineInOutToggle';
import {UpdateCheck} from './UpdateCheck';
const row: React.CSSProperties = {
@@ -35,25 +23,8 @@ const flex: React.CSSProperties = {
flex: 1,
};
-type Structure = Menu[];
-
-const openExternal = (link: string) => {
- window.open(link, '_blank');
-};
-
-const rotate: React.CSSProperties = {
- transform: `rotate(90deg)`,
-};
-const ICON_SIZE = 16;
-
export const MenuToolbar: React.FC = () => {
const [selected, setSelected] = useState<MenuId | null>(null);
- const {setSelectedModal} = useContext(ModalsContext);
- const {checkerboard, setCheckerboard} = useContext(CheckerboardContext);
- const {richTimeline, setRichTimeline} = useContext(RichTimelineContext);
- const {size, setSize} = useContext(PreviewSizeContext);
- const {setSidebarCollapsedState, sidebarCollapsedState} =
- useContext(SidebarContext);
const itemClicked = useCallback(
(itemId: MenuId) => {
@@ -71,465 +42,11 @@ export const MenuToolbar: React.FC = () => {
[selected, setSelected]
);
- const close = useCallback(() => {
+ const closeMenu = useCallback(() => {
setSelected(null);
}, []);
- const sizes = getUniqueSizes(size);
-
- const structure = useMemo((): Structure => {
- const struct: Structure = [
- {
- id: 'remotion' as const,
- label: (
- <Row align="center" justify="center">
- <svg
- width={ICON_SIZE}
- height={ICON_SIZE}
- viewBox="-100 -100 400 400"
- style={rotate}
- >
- <path
- fill="#fff"
- stroke="#fff"
- strokeWidth="100"
- strokeLinejoin="round"
- d="M 2 172 a 196 100 0 0 0 195 5 A 196 240 0 0 0 100 2.259 A 196 240 0 0 0 2 172 z"
- />
- </svg>
- </Row>
- ),
- leaveLeftPadding: false,
- items: [
- {
- id: 'about',
- value: 'about',
- label: 'About Remotion',
- onClick: () => {
- close();
- openExternal('https://remotion.dev');
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- },
- {
- id: 'changelog',
- value: 'changelog',
- label: 'Changelog',
- onClick: () => {
- close();
- openExternal('https://github.com/remotion-dev/remotion/releases');
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- },
- {
- id: 'license',
- value: 'license',
- label: 'License',
- onClick: () => {
- close();
- openExternal(
- 'https://github.com/remotion-dev/remotion/blob/main/LICENSE.md'
- );
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- },
- ],
- },
- {
- id: 'file' as const,
- label: 'File',
- leaveLeftPadding: false,
- items: [
- {
- id: 'new-sequence',
- value: 'new-sequence',
- label: 'New composition...',
- onClick: () => {
- close();
- setSelectedModal({
- compType: 'composition',
- type: 'new-comp',
- });
- },
- type: 'item' as const,
- keyHint: 'N',
- leftItem: null,
- subMenu: null,
- },
- {
- id: 'new-still',
- value: 'new-still',
- label: 'New still...',
- onClick: () => {
- close();
- setSelectedModal({
- compType: 'still',
- type: 'new-comp',
- });
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- },
- ],
- },
- {
- id: 'view' as const,
- label: 'View',
- leaveLeftPadding: true,
- items: [
- {
- id: 'preview-size',
- keyHint: null,
- label: 'Preview size',
- onClick: () => undefined,
- type: 'item' as const,
- value: 'preview-size',
- leftItem: null,
- subMenu: {
- leaveLeftSpace: true,
- preselectIndex: sizes.findIndex(
- (s) => String(size.size) === String(s.size)
- ),
- items: sizes.map((newSize) => ({
- id: String(newSize.size),
- keyHint: newSize.size === 1 ? '0' : null,
- label: getPreviewSizeLabel(newSize),
- leftItem:
- String(newSize.size) === String(size.size) ? (
- <Checkmark />
- ) : null,
- onClick: () => {
- close();
- setSize(() => newSize);
- },
- subMenu: null,
- type: 'item' as const,
- value: newSize.size,
- })),
- },
- },
- {
- id: 'timeline-divider',
- type: 'divider' as const,
- },
- {
- id: 'left-sidebar',
- label: 'Sidebar',
- keyHint: null,
- type: 'item' as const,
- value: 'preview-size',
- leftItem: null,
- subMenu: {
- leaveLeftSpace: true,
- preselectIndex: 0,
- items: [
- {
- id: 'sidebar-responsive',
- keyHint: null,
- label: 'Responsive',
- leftItem:
- sidebarCollapsedState === 'responsive' ? (
- <Checkmark />
- ) : null,
- onClick: () => {
- setSidebarCollapsedState('responsive');
- },
- subMenu: null,
- type: 'item' as const,
- value: 'responsive' as SidebarCollapsedState,
- },
- {
- id: 'sidebar-expanded',
- keyHint: null,
- label: 'Expanded',
- leftItem:
- sidebarCollapsedState === 'expanded' ? <Checkmark /> : null,
- onClick: () => {
- setSidebarCollapsedState('expanded');
- },
- subMenu: null,
- type: 'item' as const,
- value: 'expanded' as SidebarCollapsedState,
- },
- {
- id: 'sidebar-collapsed',
- keyHint: null,
- label: 'Collapsed',
- leftItem:
- sidebarCollapsedState === 'collapsed' ? (
- <Checkmark />
- ) : null,
- onClick: () => {
- setSidebarCollapsedState('collapsed');
- },
- subMenu: null,
- type: 'item' as const,
- value: 'collapsed' as SidebarCollapsedState,
- },
- ],
- },
- onClick: () => undefined,
- },
- {
- id: 'timeline-divider',
- type: 'divider' as const,
- },
- {
- id: 'checkerboard',
- keyHint: 'T',
- label: 'Transparency as checkerboard',
- onClick: () => {
- close();
- setCheckerboard((c) => !c);
- },
- type: 'item' as const,
- value: 'checkerboard',
- leftItem: checkerboard ? <Checkmark /> : null,
- subMenu: null,
- },
- {
- id: 'timeline-divider',
- type: 'divider' as const,
- },
- {
- id: 'rich-timeline',
- keyHint: null,
- label: 'Rich timeline',
- onClick: () => {
- close();
- setRichTimeline((r) => !r);
- },
- type: 'item' as const,
- value: 'rich-timeline',
- leftItem: richTimeline ? <Checkmark /> : null,
- subMenu: null,
- },
- {
- id: 'expand-all',
- keyHint: null,
- label: 'Expand all',
- onClick: () => {
- close();
- timelineRef.current?.expandAll();
- },
- type: 'item' as const,
- value: 'expand-all',
- leftItem: null,
- subMenu: null,
- },
- {
- id: 'collapse-all',
- keyHint: null,
- label: 'Collapse all',
- onClick: () => {
- close();
- timelineRef.current?.collapseAll();
- },
- type: 'item' as const,
- value: 'collapse-all',
- leftItem: null,
- subMenu: null,
- },
- {
- id: 'in-out-divider',
- type: 'divider' as const,
- },
- {
- id: 'in-mark',
- keyHint: 'I',
- label: 'In Mark',
- leftItem: null,
- onClick: () => {
- close();
- inOutHandles.current?.inMarkClick(null);
- },
- subMenu: null,
- type: 'item' as const,
- value: 'in-mark',
- },
- {
- id: 'out-mark',
- keyHint: 'O',
- label: 'Out Mark',
- leftItem: null,
- onClick: () => {
- close();
- inOutHandles.current?.outMarkClick(null);
- },
- subMenu: null,
- type: 'item' as const,
- value: 'out-mark',
- },
- {
- id: 'x-mark',
- keyHint: 'X',
- label: 'Clear In/Out Marks',
- leftItem: null,
- onClick: () => {
- close();
- inOutHandles.current?.clearMarks();
- },
- subMenu: null,
- type: 'item' as const,
- value: 'clear-marks',
- },
- ],
- },
- 'EyeDropper' in window
- ? {
- id: 'tools' as const,
- label: 'Tools',
- leaveLeftPadding: false,
- items: [
- {
- id: 'color-picker',
- value: 'color-picker',
- label: 'Color Picker',
- onClick: () => pickColor(),
- leftItem: null,
- keyHint: null,
- subMenu: null,
- type: 'item' as const,
- },
- ],
- }
- : null,
- {
- id: 'help' as const,
- label: 'Help',
- leaveLeftPadding: false,
- items: [
- {
- id: 'shortcuts',
- value: 'shortcuts',
- label: areKeyboardShortcutsDisabled()
- ? 'Shortcuts (disabled)'
- : 'Shortcuts',
- onClick: () => {
- close();
-
- setSelectedModal({
- type: 'shortcuts',
- });
- },
- keyHint: '?',
- leftItem: null,
- subMenu: null,
- type: 'item' as const,
- },
- {
- id: 'docs',
- value: 'docs',
- label: 'Docs',
- onClick: () => {
- close();
- openExternal('https://remotion.dev/docs');
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- },
- {
- id: 'file-issue',
- value: 'file-issue',
- label: 'File an issue',
- onClick: () => {
- close();
- openExternal(
- 'https://github.com/remotion-dev/remotion/issues/new/choose'
- );
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- },
- {
- id: 'discord',
- value: 'discord',
- label: 'Join Discord community',
- onClick: () => {
- close();
- openExternal('https://discord.com/invite/6VzzNDwUwV');
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- },
- {
- id: 'help-divider',
- type: 'divider' as const,
- },
- {
- id: 'insta',
- value: 'insta',
- label: 'Instagram',
- onClick: () => {
- close();
- openExternal('https://instagram.com/remotion.dev');
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- },
- {
- id: 'twitter',
- value: 'twitter',
- label: 'Twitter',
- onClick: () => {
- close();
- openExternal('https://twitter.com/remotion_dev');
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- },
- {
- id: 'tiktok',
- value: 'tiktok',
- label: 'TikTok',
- onClick: () => {
- close();
- openExternal('https://www.tiktok.com/@remotion.dev');
- },
- type: 'item' as const,
- keyHint: null,
- leftItem: null,
- subMenu: null,
- },
- ],
- },
- ].filter(Internals.truthy);
-
- return struct;
- }, [
- checkerboard,
- close,
- richTimeline,
- setCheckerboard,
- setRichTimeline,
- setSelectedModal,
- setSidebarCollapsedState,
- setSize,
- sidebarCollapsedState,
- size.size,
- sizes,
- ]);
+ const structure = useMenuStructure(closeMenu);
const menus = useMemo(() => {
return structure.map((s) => s.id);
diff --git a/packages/cli/src/editor/components/NewComposition/ComboBox.tsx b/packages/cli/src/editor/components/NewComposition/ComboBox.tsx
index ac32d0238f..7908509c45 100644
--- a/packages/cli/src/editor/components/NewComposition/ComboBox.tsx
+++ b/packages/cli/src/editor/components/NewComposition/ComboBox.tsx
@@ -39,7 +39,7 @@ export type SubMenu = {
items: ComboboxValue[];
};
-type SelectionItem = {
+export type SelectionItem = {
type: 'item';
id: string;
label: React.ReactNode;
@@ -48,6 +48,7 @@ type SelectionItem = {
keyHint: string | null;
leftItem: React.ReactNode;
subMenu: SubMenu | null;
+ quickSwitcherLabel: string | null;
};
export type ComboboxValue = DividerItem | SelectionItem;
diff --git a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
index 2a5eb01dea..45b878eb5a 100644
--- a/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
+++ b/packages/cli/src/editor/components/NewComposition/NewComposition.tsx
@@ -202,6 +202,7 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {
leftItem:
String(frameRate) === selectedFrameRate ? <Checkmark /> : null,
subMenu: null,
+ quickSwitcherLabel: null,
};
});
}, [onFpsChange, selectedFrameRate]);
@@ -224,6 +225,7 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {
subMenu: null,
type: 'item',
value: 'composition' as CompType,
+ quickSwitcherLabel: null,
},
{
id: 'still',
@@ -234,6 +236,7 @@ const NewComposition: React.FC<{initialCompType: CompType}> = (props) => {
subMenu: null,
type: 'item',
value: 'still' as CompType,
+ quickSwitcherLabel: null,
},
];
}, [onTypeChanged]);
diff --git a/packages/cli/src/editor/components/PlaybackRateSelector.tsx b/packages/cli/src/editor/components/PlaybackRateSelector.tsx
index 4a3a0f7bdd..82c7419b10 100644
--- a/packages/cli/src/editor/components/PlaybackRateSelector.tsx
+++ b/packages/cli/src/editor/components/PlaybackRateSelector.tsx
@@ -52,6 +52,7 @@ export const PlaybackRateSelector: React.FC<{
<Checkmark />
) : null,
subMenu: null,
+ quickSwitcherLabel: null,
};
});
const middle = Math.floor(commonPlaybackRates.length / 2);
diff --git a/packages/cli/src/editor/components/QuickSwitcher/NoResults.tsx b/packages/cli/src/editor/components/QuickSwitcher/NoResults.tsx
index 86b28de18a..3599ba210b 100644
--- a/packages/cli/src/editor/components/QuickSwitcher/NoResults.tsx
+++ b/packages/cli/src/editor/components/QuickSwitcher/NoResults.tsx
@@ -8,12 +8,15 @@ const container: React.CSSProperties = {
fontSize: 14,
};
+export type Mode = 'commands' | 'compositions';
+
export const QuickSwitcherNoResults: React.FC<{
query: string;
-}> = ({query}) => {
+ mode: Mode;
+}> = ({query, mode}) => {
return (
<div style={container}>
- No compositions matching {'"'}
+ No {mode === 'commands' ? 'commands' : 'compositions'} matching {'"'}
{query}
{'"'}
</div>
diff --git a/packages/cli/src/editor/components/QuickSwitcher/QuickSwitcherContent.tsx b/packages/cli/src/editor/components/QuickSwitcher/QuickSwitcherContent.tsx
index bf236e84b4..aea10ed7af 100644
--- a/packages/cli/src/editor/components/QuickSwitcher/QuickSwitcherContent.tsx
+++ b/packages/cli/src/editor/components/QuickSwitcher/QuickSwitcherContent.tsx
@@ -9,9 +9,14 @@ import {Internals} from 'remotion';
import {INPUT_BORDER_COLOR_UNHOVERED} from '../../helpers/colors';
import {isCompositionStill} from '../../helpers/is-composition-still';
import {useKeybinding} from '../../helpers/use-keybinding';
+import {
+ makeSearchResults,
+ useMenuStructure,
+} from '../../helpers/use-menu-structure';
import {ModalsContext} from '../../state/modals';
import {useSelectComposition} from '../InitialCompositionLoader';
import {fuzzySearch} from './fuzzy-search';
+import type {Mode} from './NoResults';
import {QuickSwitcherNoResults} from './NoResults';
import type {TQuickSwitcherResult} from './QuickSwitcherResult';
import {QuickSwitcherResult} from './QuickSwitcherResult';
@@ -51,13 +56,38 @@ export const QuickSwitcherContent: React.FC = () => {
selectedIndex: 0,
});
const selectComposition = useSelectComposition();
+ const closeMenu = useCallback(() => undefined, []);
+ const actions = useMenuStructure(closeMenu);
const {setSelectedModal} = useContext(ModalsContext);
const keybindings = useKeybinding();
+
+ const mode: Mode = state.query.startsWith('>') ? 'commands' : 'compositions';
+
+ const actualQuery = useMemo(() => {
+ if (mode === 'commands') {
+ return state.query.substring(1).trim();
+ }
+
+ return state.query.trim();
+ }, [mode, state.query]);
+
+ const menuActions = useMemo((): TQuickSwitcherResult[] => {
+ if (mode !== 'commands') {
+ return [];
+ }
+
+ return makeSearchResults(actions, setSelectedModal);
+ }, [actions, mode, setSelectedModal]);
+
const resultsArray = useMemo((): TQuickSwitcherResult[] => {
+ if (mode === 'commands') {
+ return fuzzySearch(actualQuery, menuActions);
+ }
+
return fuzzySearch(
- state.query,
+ actualQuery,
compositions.map((c) => {
return {
id: 'composition-' + c.id,
@@ -71,7 +101,14 @@ export const QuickSwitcherContent: React.FC = () => {
};
})
);
- }, [compositions, state.query, selectComposition, setSelectedModal]);
+ }, [
+ mode,
+ compositions,
+ actualQuery,
+ menuActions,
+ selectComposition,
+ setSelectedModal,
+ ]);
const onArrowDown = useCallback(() => {
setState((s) => {
@@ -154,7 +191,7 @@ export const QuickSwitcherContent: React.FC = () => {
);
})}
{resultsArray.length === 0 ? (
- <QuickSwitcherNoResults query={state.query} />
+ <QuickSwitcherNoResults mode={mode} query={actualQuery} />
) : null}
</div>
</div>
diff --git a/packages/cli/src/editor/components/QuickSwitcher/QuickSwitcherResult.tsx b/packages/cli/src/editor/components/QuickSwitcher/QuickSwitcherResult.tsx
index 216fe84312..74f35514b4 100644
--- a/packages/cli/src/editor/components/QuickSwitcher/QuickSwitcherResult.tsx
+++ b/packages/cli/src/editor/components/QuickSwitcher/QuickSwitcherResult.tsx
@@ -5,10 +5,14 @@ import {FilmIcon} from '../../icons/film';
import {StillIcon} from '../../icons/still';
import {Spacing} from '../layout';
-type QuickSwitcherResultDetail = {
- type: 'composition';
- compositionType: 'composition' | 'still';
-};
+type QuickSwitcherResultDetail =
+ | {
+ type: 'composition';
+ compositionType: 'composition' | 'still';
+ }
+ | {
+ type: 'menu-item';
+ };
export type TQuickSwitcherResult = {
title: string;
@@ -81,6 +85,7 @@ export const QuickSwitcherResult: React.FC<{
binding.unregister();
};
}, [keybindings, result.onSelected, selected]);
+
useEffect(() => {
if (selected) {
ref.current?.scrollIntoView({
@@ -110,11 +115,13 @@ export const QuickSwitcherResult: React.FC<{
return (
<div ref={ref} key={result.id} style={style} onClick={result.onSelected}>
- {result.compositionType === 'still' ? (
- <StillIcon style={iconStyle} />
- ) : (
- <FilmIcon style={iconStyle} />
- )}
+ {result.type === 'composition' ? (
+ result.compositionType === 'still' ? (
+ <StillIcon style={iconStyle} />
+ ) : (
+ <FilmIcon style={iconStyle} />
+ )
+ ) : null}
<Spacing x={1} />
<div style={labelStyle}>{result.title}</div>
</div>
diff --git a/packages/cli/src/editor/components/SizeSelector.tsx b/packages/cli/src/editor/components/SizeSelector.tsx
index 82b6757f82..92cd833a8d 100644
--- a/packages/cli/src/editor/components/SizeSelector.tsx
+++ b/packages/cli/src/editor/components/SizeSelector.tsx
@@ -97,6 +97,7 @@ export const SizeSelector: React.FC = () => {
leftItem:
String(size.size) === String(newSize.size) ? <Checkmark /> : null,
subMenu: null,
+ quickSwitcherLabel: null,
};
});
}, [setSize, size]);
diff --git a/packages/cli/src/editor/helpers/use-menu-structure.tsx b/packages/cli/src/editor/helpers/use-menu-structure.tsx
new file mode 100644
index 0000000000..ff4e939e4e
--- /dev/null
+++ b/packages/cli/src/editor/helpers/use-menu-structure.tsx
@@ -0,0 +1,600 @@
+import {useContext, useMemo} from 'react';
+import {Internals} from 'remotion';
+import {truthy} from '../../truthy';
+import {Row} from '../components/layout';
+import type {Menu} from '../components/Menu/MenuItem';
+import type {SelectionItem} from '../components/NewComposition/ComboBox';
+import type {TQuickSwitcherResult} from '../components/QuickSwitcher/QuickSwitcherResult';
+import {getPreviewSizeLabel, getUniqueSizes} from '../components/SizeSelector';
+import {inOutHandles} from '../components/TimelineInOutToggle';
+import {Checkmark} from '../icons/Checkmark';
+import {CheckerboardContext} from '../state/checkerboard';
+import type {ModalState} from '../state/modals';
+import {ModalsContext} from '../state/modals';
+import {PreviewSizeContext} from '../state/preview-size';
+import {RichTimelineContext} from '../state/rich-timeline';
+import type {SidebarCollapsedState} from '../state/sidebar';
+import {SidebarContext} from '../state/sidebar';
+import {timelineRef} from '../state/timeline-ref';
+import {pickColor} from './pick-color';
+import {areKeyboardShortcutsDisabled} from './use-keybinding';
+
+type Structure = Menu[];
+
+const openExternal = (link: string) => {
+ window.open(link, '_blank');
+};
+
+const rotate: React.CSSProperties = {
+ transform: `rotate(90deg)`,
+};
+const ICON_SIZE = 16;
+
+export const useMenuStructure = (closeMenu: () => void) => {
+ const {setSelectedModal} = useContext(ModalsContext);
+ const {checkerboard, setCheckerboard} = useContext(CheckerboardContext);
+ const {richTimeline, setRichTimeline} = useContext(RichTimelineContext);
+ const {size, setSize} = useContext(PreviewSizeContext);
+ const {setSidebarCollapsedState, sidebarCollapsedState} =
+ useContext(SidebarContext);
+
+ const sizes = getUniqueSizes(size);
+
+ const structure = useMemo((): Structure => {
+ const struct: Structure = [
+ {
+ id: 'remotion' as const,
+ label: (
+ <Row align="center" justify="center">
+ <svg
+ width={ICON_SIZE}
+ height={ICON_SIZE}
+ viewBox="-100 -100 400 400"
+ style={rotate}
+ >
+ <path
+ fill="#fff"
+ stroke="#fff"
+ strokeWidth="100"
+ strokeLinejoin="round"
+ d="M 2 172 a 196 100 0 0 0 195 5 A 196 240 0 0 0 100 2.259 A 196 240 0 0 0 2 172 z"
+ />
+ </svg>
+ </Row>
+ ),
+ leaveLeftPadding: false,
+ items: [
+ {
+ id: 'about',
+ value: 'about',
+ label: 'About Remotion',
+ onClick: () => {
+ closeMenu();
+ openExternal('https://remotion.dev');
+ },
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'Help: About Remotion',
+ },
+ {
+ id: 'changelog',
+ value: 'changelog',
+ label: 'Changelog',
+ onClick: () => {
+ closeMenu();
+ openExternal('https://github.com/remotion-dev/remotion/releases');
+ },
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'Help: Changelog',
+ },
+ {
+ id: 'license',
+ value: 'license',
+ label: 'License',
+ onClick: () => {
+ closeMenu();
+ openExternal(
+ 'https://github.com/remotion-dev/remotion/blob/main/LICENSE.md'
+ );
+ },
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'Help: License',
+ },
+ ],
+ quickSwitcherLabel: null,
+ },
+ {
+ id: 'file' as const,
+ label: 'File',
+ leaveLeftPadding: false,
+ items: [
+ {
+ id: 'new-sequence',
+ value: 'new-sequence',
+ label: 'New composition...',
+ onClick: () => {
+ closeMenu();
+ setSelectedModal({
+ compType: 'composition',
+ type: 'new-comp',
+ });
+ },
+ type: 'item' as const,
+ keyHint: 'N',
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'New composition...',
+ },
+ {
+ id: 'new-still',
+ value: 'new-still',
+ label: 'New still...',
+ onClick: () => {
+ closeMenu();
+ setSelectedModal({
+ compType: 'still',
+ type: 'new-comp',
+ });
+ },
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'New still...',
+ },
+ ],
+ quickSwitcherLabel: null,
+ },
+ {
+ id: 'view' as const,
+ label: 'View',
+ leaveLeftPadding: true,
+ items: [
+ {
+ id: 'preview-size',
+ keyHint: null,
+ label: 'Preview size',
+ onClick: () => undefined,
+ type: 'item' as const,
+ value: 'preview-size',
+ leftItem: null,
+ subMenu: {
+ leaveLeftSpace: true,
+ preselectIndex: sizes.findIndex(
+ (s) => String(size.size) === String(s.size)
+ ),
+ items: sizes.map((newSize) => ({
+ id: String(newSize.size),
+ keyHint: newSize.size === 1 ? '0' : null,
+ label: getPreviewSizeLabel(newSize),
+ leftItem:
+ String(newSize.size) === String(size.size) ? (
+ <Checkmark />
+ ) : null,
+ onClick: () => {
+ closeMenu();
+ setSize(() => newSize);
+ },
+ subMenu: null,
+ type: 'item' as const,
+ value: newSize.size,
+ quickSwitcherLabel: null,
+ })),
+ quickSwitcherLabel: null,
+ },
+ quickSwitcherLabel: null,
+ },
+ {
+ id: 'timeline-divider',
+ type: 'divider' as const,
+ },
+ {
+ id: 'left-sidebar',
+ label: 'Sidebar',
+ keyHint: null,
+ type: 'item' as const,
+ value: 'preview-size',
+ leftItem: null,
+ quickSwitcherLabel: null,
+ subMenu: {
+ leaveLeftSpace: true,
+ preselectIndex: 0,
+ items: [
+ {
+ id: 'sidebar-responsive',
+ keyHint: null,
+ label: 'Responsive',
+ leftItem:
+ sidebarCollapsedState === 'responsive' ? (
+ <Checkmark />
+ ) : null,
+ onClick: () => {
+ setSidebarCollapsedState('responsive');
+ },
+ subMenu: null,
+ type: 'item' as const,
+ value: 'responsive' as SidebarCollapsedState,
+ quickSwitcherLabel: null,
+ },
+ {
+ id: 'sidebar-expanded',
+ keyHint: null,
+ label: 'Expanded',
+ leftItem:
+ sidebarCollapsedState === 'expanded' ? <Checkmark /> : null,
+ onClick: () => {
+ setSidebarCollapsedState('expanded');
+ },
+ subMenu: null,
+ type: 'item' as const,
+ value: 'expanded' as SidebarCollapsedState,
+ quickSwitcherLabel: null,
+ },
+ {
+ id: 'sidebar-collapsed',
+ keyHint: null,
+ label: 'Collapsed',
+ leftItem:
+ sidebarCollapsedState === 'collapsed' ? (
+ <Checkmark />
+ ) : null,
+ onClick: () => {
+ setSidebarCollapsedState('collapsed');
+ },
+ subMenu: null,
+ type: 'item' as const,
+ value: 'collapsed' as SidebarCollapsedState,
+ quickSwitcherLabel: null,
+ },
+ ],
+ },
+ onClick: () => undefined,
+ },
+ {
+ id: 'timeline-divider',
+ type: 'divider' as const,
+ },
+ {
+ id: 'checkerboard',
+ keyHint: 'T',
+ label: 'Transparency as checkerboard',
+ onClick: () => {
+ closeMenu();
+ setCheckerboard((c) => !c);
+ },
+ type: 'item' as const,
+ value: 'checkerboard',
+ leftItem: checkerboard ? <Checkmark /> : null,
+ subMenu: null,
+ quickSwitcherLabel: checkerboard
+ ? 'Disable Checkerboard Transparency'
+ : 'Enable Checkerboard Transparency',
+ },
+ {
+ id: 'timeline-divider',
+ type: 'divider' as const,
+ },
+ {
+ id: 'rich-timeline',
+ keyHint: null,
+ label: 'Rich timeline',
+ onClick: () => {
+ closeMenu();
+ setRichTimeline((r) => !r);
+ },
+ type: 'item' as const,
+ value: 'rich-timeline',
+ leftItem: richTimeline ? <Checkmark /> : null,
+ subMenu: null,
+ quickSwitcherLabel: richTimeline
+ ? 'Timeline: Disable Rich Timeline'
+ : 'Timeline: Enable Rich Timeline',
+ },
+ {
+ id: 'expand-all',
+ keyHint: null,
+ label: 'Expand all',
+ onClick: () => {
+ closeMenu();
+ timelineRef.current?.expandAll();
+ },
+ type: 'item' as const,
+ value: 'expand-all',
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'Timeline: Expand all Timeline layers',
+ },
+ {
+ id: 'collapse-all',
+ keyHint: null,
+ label: 'Collapse all',
+ onClick: () => {
+ closeMenu();
+ timelineRef.current?.collapseAll();
+ },
+ type: 'item' as const,
+ value: 'collapse-all',
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'Timeline: Collapse all layers',
+ },
+ {
+ id: 'in-out-divider',
+ type: 'divider' as const,
+ },
+ {
+ id: 'in-mark',
+ keyHint: 'I',
+ label: 'In Mark',
+ leftItem: null,
+ onClick: () => {
+ closeMenu();
+ inOutHandles.current?.inMarkClick(null);
+ },
+ subMenu: null,
+ type: 'item' as const,
+ value: 'in-mark',
+ quickSwitcherLabel: 'Timeline: Set In Mark',
+ },
+ {
+ id: 'out-mark',
+ keyHint: 'O',
+ label: 'Out Mark',
+ leftItem: null,
+ onClick: () => {
+ closeMenu();
+ inOutHandles.current?.outMarkClick(null);
+ },
+ subMenu: null,
+ type: 'item' as const,
+ value: 'out-mark',
+ quickSwitcherLabel: 'Timeline: Set Out Mark',
+ },
+ {
+ id: 'x-mark',
+ keyHint: 'X',
+ label: 'Clear In/Out Marks',
+ leftItem: null,
+ onClick: () => {
+ closeMenu();
+ inOutHandles.current?.clearMarks();
+ },
+ subMenu: null,
+ type: 'item' as const,
+ value: 'clear-marks',
+ quickSwitcherLabel: 'Timeline: Clear In and Out Mark',
+ },
+ ],
+ },
+ 'EyeDropper' in window
+ ? {
+ id: 'tools' as const,
+ label: 'Tools',
+ leaveLeftPadding: false,
+ items: [
+ {
+ id: 'color-picker',
+ value: 'color-picker',
+ label: 'Color Picker',
+ onClick: () => pickColor(),
+ leftItem: null,
+ keyHint: null,
+ subMenu: null,
+ type: 'item' as const,
+ quickSwitcherLabel: 'Show Color Picker',
+ },
+ ],
+ quickSwitcherLabel: null,
+ }
+ : null,
+ {
+ id: 'help' as const,
+ label: 'Help',
+ leaveLeftPadding: false,
+ items: [
+ {
+ id: 'shortcuts',
+ value: 'shortcuts',
+ label: areKeyboardShortcutsDisabled()
+ ? 'Shortcuts (disabled)'
+ : 'Shortcuts',
+ onClick: () => {
+ closeMenu();
+
+ setSelectedModal({
+ type: 'shortcuts',
+ });
+ },
+ keyHint: '?',
+ leftItem: null,
+ subMenu: null,
+ type: 'item' as const,
+ quickSwitcherLabel: areKeyboardShortcutsDisabled()
+ ? 'Show all Keyboard Shortcuts (disabled)'
+ : 'Show all Keyboard Shortcuts',
+ },
+ {
+ id: 'docs',
+ value: 'docs',
+ label: 'Docs',
+ onClick: () => {
+ closeMenu();
+ openExternal('https://remotion.dev/docs');
+ },
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'Visit Documentation',
+ },
+ {
+ id: 'file-issue',
+ value: 'file-issue',
+ label: 'File an issue',
+ onClick: () => {
+ closeMenu();
+ openExternal(
+ 'https://github.com/remotion-dev/remotion/issues/new/choose'
+ );
+ },
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'File GitHub issue',
+ },
+ {
+ id: 'discord',
+ value: 'discord',
+ label: 'Join Discord community',
+ onClick: () => {
+ closeMenu();
+ openExternal('https://discord.com/invite/6VzzNDwUwV');
+ },
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: null,
+ },
+ {
+ id: 'help-divider',
+ type: 'divider' as const,
+ },
+ {
+ id: 'insta',
+ value: 'insta',
+ label: 'Instagram',
+ onClick: () => {
+ closeMenu();
+ openExternal('https://instagram.com/remotion.dev');
+ },
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'Follow Remotion on Instagram',
+ },
+ {
+ id: 'twitter',
+ value: 'twitter',
+ label: 'Twitter',
+ onClick: () => {
+ closeMenu();
+ openExternal('https://twitter.com/remotion_dev');
+ },
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'Follow Remotion on Twitter',
+ },
+ {
+ id: 'tiktok',
+ value: 'tiktok',
+ label: 'TikTok',
+ onClick: () => {
+ closeMenu();
+ openExternal('https://www.tiktok.com/@remotion.dev');
+ },
+ type: 'item' as const,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: 'Follow Remotion on TikTok',
+ },
+ ],
+ },
+ ].filter(Internals.truthy);
+
+ return struct;
+ }, [
+ checkerboard,
+ closeMenu,
+ richTimeline,
+ setCheckerboard,
+ setRichTimeline,
+ setSelectedModal,
+ setSidebarCollapsedState,
+ setSize,
+ sidebarCollapsedState,
+ size.size,
+ sizes,
+ ]);
+
+ return structure;
+};
+
+const getItemLabel = (item: SelectionItem) => {
+ if (item.quickSwitcherLabel !== null) {
+ return item.quickSwitcherLabel;
+ }
+
+ if (typeof item.label === 'string') {
+ return item.label;
+ }
+
+ return item.label?.toString() as string;
+};
+
+const itemToSearchResult = (
+ item: SelectionItem,
+ setSelectedModal: (value: React.SetStateAction<ModalState | null>) => void,
+ prefixes: string[]
+): TQuickSwitcherResult[] => {
+ if (item.subMenu) {
+ return item.subMenu.items
+ .map((subItem) => {
+ if (subItem.type === 'divider') {
+ return null;
+ }
+
+ return itemToSearchResult(subItem, setSelectedModal, [
+ ...prefixes,
+ getItemLabel(item),
+ ]);
+ })
+ .flat(1)
+ .filter(truthy);
+ }
+
+ return [
+ {
+ type: 'menu-item',
+ id: item.id,
+ onSelected: () => {
+ setSelectedModal(null);
+ item.onClick(item.id);
+ },
+ title: [...prefixes, getItemLabel(item)].join(': '),
+ },
+ ];
+};
+
+export const makeSearchResults = (
+ actions: Structure,
+ setSelectedModal: (value: React.SetStateAction<ModalState | null>) => void
+) => {
+ const items: TQuickSwitcherResult[] = actions
+ .map((menu) => {
+ return menu.items.map((item): TQuickSwitcherResult[] | null => {
+ if (item.type === 'divider') {
+ return null;
+ }
+
+ return itemToSearchResult(item, setSelectedModal, []);
+ });
+ })
+ .flat(Infinity)
+ .filter(truthy) as TQuickSwitcherResult[];
+
+ return items;
+};