Skip to content

🎥 Make videos programmatically with React

@remotion/studio: Add outline visibility toggle

Jonny Burger088dd3a1a46b
diff --git a/packages/studio/src/components/EditorContexts.tsx b/packages/studio/src/components/EditorContexts.tsx
index 850d15f4ff..e42603b64e 100644
--- a/packages/studio/src/components/EditorContexts.tsx
+++ b/packages/studio/src/components/EditorContexts.tsx
@@ -16,6 +16,7 @@ import {ClientRenderQueueProcessor} from './RenderQueue/ClientRenderQueueProcess
import {RenderQueueContextProvider} from './RenderQueue/context';
import {SetTimelineInOutProvider} from './SetTimelineInOutProvider';
import {ShowGuidesProvider} from './ShowGuidesProvider';
+import {ShowOutlinesProvider} from './ShowOutlinesProvider';
import {ShowRulersProvider} from './ShowRulersProvider';
import {VisualControlsUndoSync} from './VisualControls/VisualControlsUndoSync';
import {ZoomGesturesProvider} from './ZoomGesturesProvider';
@@ -36,27 +37,29 @@ export const EditorContexts: React.FC<{
<ZoomGesturesProvider>
<ShowRulersProvider>
<ShowGuidesProvider>
- <PreviewSizeProvider>
- <ModalsProvider>
- <MediaVolumeProvider>
- <PlayerInternals.PlayerEmitterProvider
- currentPlaybackRate={null}
- >
- <SidebarContextProvider>
- <FolderContextProvider>
- <HighestZIndexProvider>
- <SetTimelineInOutProvider>
- <ExpandedTracksProvider>
- {children}
- </ExpandedTracksProvider>
- </SetTimelineInOutProvider>
- </HighestZIndexProvider>
- </FolderContextProvider>
- </SidebarContextProvider>
- </PlayerInternals.PlayerEmitterProvider>
- </MediaVolumeProvider>
- </ModalsProvider>
- </PreviewSizeProvider>
+ <ShowOutlinesProvider>
+ <PreviewSizeProvider>
+ <ModalsProvider>
+ <MediaVolumeProvider>
+ <PlayerInternals.PlayerEmitterProvider
+ currentPlaybackRate={null}
+ >
+ <SidebarContextProvider>
+ <FolderContextProvider>
+ <HighestZIndexProvider>
+ <SetTimelineInOutProvider>
+ <ExpandedTracksProvider>
+ {children}
+ </ExpandedTracksProvider>
+ </SetTimelineInOutProvider>
+ </HighestZIndexProvider>
+ </FolderContextProvider>
+ </SidebarContextProvider>
+ </PlayerInternals.PlayerEmitterProvider>
+ </MediaVolumeProvider>
+ </ModalsProvider>
+ </PreviewSizeProvider>
+ </ShowOutlinesProvider>
</ShowGuidesProvider>
</ShowRulersProvider>
</ZoomGesturesProvider>
diff --git a/packages/studio/src/components/OutlineToggle.tsx b/packages/studio/src/components/OutlineToggle.tsx
new file mode 100644
index 0000000000..324fd10109
--- /dev/null
+++ b/packages/studio/src/components/OutlineToggle.tsx
@@ -0,0 +1,42 @@
+import React, {useCallback, useContext} from 'react';
+import {BLUE} from '../helpers/colors';
+import {EditorShowOutlinesContext} from '../state/editor-outlines';
+import {ControlButton} from './ControlButton';
+
+const size = 3;
+
+export const OutlineToggle: React.FC = () => {
+ const {editorShowOutlines, setEditorShowOutlines} = useContext(
+ EditorShowOutlinesContext,
+ );
+
+ const onClick = useCallback(() => {
+ setEditorShowOutlines((current) => !current);
+ }, [setEditorShowOutlines]);
+
+ const color = editorShowOutlines ? BLUE : 'white';
+ const accessibilityLabel = editorShowOutlines
+ ? 'Hide outlines'
+ : 'Show outlines';
+
+ return (
+ <ControlButton
+ title={accessibilityLabel}
+ aria-label={accessibilityLabel}
+ onClick={onClick}
+ >
+ <svg
+ viewBox="0 0 20 20"
+ style={{width: 18, height: 18}}
+ aria-hidden="true"
+ focusable="false"
+ >
+ <path d="M5 5H15V15H5Z" fill="none" stroke={color} strokeWidth={1.8} />
+ <rect x={3.5} y={3.5} width={size} height={size} fill={color} />
+ <rect x={13.5} y={3.5} width={size} height={size} fill={color} />
+ <rect x={13.5} y={13.5} width={size} height={size} fill={color} />
+ <rect x={3.5} y={13.5} width={size} height={size} fill={color} />
+ </svg>
+ </ControlButton>
+ );
+};
diff --git a/packages/studio/src/components/PreviewToolbar.tsx b/packages/studio/src/components/PreviewToolbar.tsx
index fd0fe2340b..8f95963e8e 100644
--- a/packages/studio/src/components/PreviewToolbar.tsx
+++ b/packages/studio/src/components/PreviewToolbar.tsx
@@ -8,6 +8,7 @@ import {
} from '../helpers/is-current-selected-still';
import {useMobileLayout} from '../helpers/mobile-layout';
import {TIMELINE_PADDING} from '../helpers/timeline-layout';
+import {ENABLE_OUTLINES} from '../state/editor-outlines';
import {loadLoopOption} from '../state/loop';
import {CheckboardToggle} from './CheckboardToggle';
import {FpsCounter} from './FpsCounter';
@@ -15,6 +16,7 @@ import {FullScreenToggle} from './FullscreenToggle';
import {Flex, Spacing} from './layout';
import {LoopToggle} from './LoopToggle';
import {MuteToggle} from './MuteToggle';
+import {OutlineToggle} from './OutlineToggle';
import {PlaybackKeyboardShortcutsManager} from './PlaybackKeyboardShortcutsManager';
import {PlaybackRatePersistor} from './PlaybackRatePersistor';
import {PlaybackRateSelector} from './PlaybackRateSelector';
@@ -194,6 +196,9 @@ export const PreviewToolbar: React.FC<{
</>
) : null}
{canvasContent?.type === 'composition' ? <CheckboardToggle /> : null}
+ {ENABLE_OUTLINES && canvasContent?.type === 'composition' ? (
+ <OutlineToggle />
+ ) : null}
<Spacing x={1} />
{canvasContent && isFullscreenSupported ? <FullScreenToggle /> : null}
<Flex />
diff --git a/packages/studio/src/components/SelectedOutlineOverlay.tsx b/packages/studio/src/components/SelectedOutlineOverlay.tsx
index 82b82f2a0f..66a6284913 100644
--- a/packages/studio/src/components/SelectedOutlineOverlay.tsx
+++ b/packages/studio/src/components/SelectedOutlineOverlay.tsx
@@ -18,6 +18,10 @@ import {StudioServerConnectionCtx} from '../helpers/client-id';
import {BLUE} from '../helpers/colors';
import {getBoxQuadsPonyfill} from '../helpers/get-box-quads-ponyfill';
import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';
+import {
+ EditorShowOutlinesContext,
+ ENABLE_OUTLINES,
+} from '../state/editor-outlines';
import {ScaleLockContext} from '../state/scale-lock';
import {showNotification} from './Notifications/NotificationCenter';
import {callAddSequenceKeyframe} from './Timeline/call-add-keyframe';
@@ -33,7 +37,6 @@ import {
} from './Timeline/timeline-translate-utils';
import {getLinkedScale} from './Timeline/TimelineScaleField';
import {
- ENABLE_OUTLINES,
getTimelineSequenceSelectionKey,
type TimelineSelection,
type TimelineSelectionInteraction,
@@ -1500,6 +1503,7 @@ export const SelectedOutlineOverlay: React.FC<{
Internals.VisualModeDragOverridesContext,
);
const {getScaleLockState} = useContext(ScaleLockContext);
+ const {editorShowOutlines} = useContext(EditorShowOutlinesContext);
const [outlines, setOutlines] = useState<readonly SelectedOutline[]>([]);
const [hoveredOutlineKey, setHoveredOutlineKey] = useState<string | null>(
null,
@@ -1507,7 +1511,7 @@ export const SelectedOutlineOverlay: React.FC<{
const overlayRef = useRef<SVGSVGElement>(null);
const outlineTargets = useMemo((): SelectedOutlineTarget[] => {
- if (!ENABLE_OUTLINES) {
+ if (!ENABLE_OUTLINES || !editorShowOutlines) {
return [];
}
@@ -1614,6 +1618,7 @@ export const SelectedOutlineOverlay: React.FC<{
getDragOverrides,
getEffectDragOverrides,
getScaleLockState,
+ editorShowOutlines,
overrideIdToNodePathMappings,
previewServerState,
selectedItems,
diff --git a/packages/studio/src/components/ShowOutlinesProvider.tsx b/packages/studio/src/components/ShowOutlinesProvider.tsx
new file mode 100644
index 0000000000..dd108254f3
--- /dev/null
+++ b/packages/studio/src/components/ShowOutlinesProvider.tsx
@@ -0,0 +1,38 @@
+import React, {useCallback, useMemo, useState} from 'react';
+import {
+ EditorShowOutlinesContext,
+ loadEditorShowOutlinesOption,
+ persistEditorShowOutlinesOption,
+} from '../state/editor-outlines';
+
+export const ShowOutlinesProvider: React.FC<{
+ readonly children: React.ReactNode;
+}> = ({children}) => {
+ const [editorShowOutlines, setEditorShowOutlinesState] = useState(() =>
+ loadEditorShowOutlinesOption(),
+ );
+
+ const setEditorShowOutlines = useCallback(
+ (newValue: (prevState: boolean) => boolean) => {
+ setEditorShowOutlinesState((prevState) => {
+ const newVal = newValue(prevState);
+ persistEditorShowOutlinesOption(newVal);
+ return newVal;
+ });
+ },
+ [],
+ );
+
+ const editorShowOutlinesCtx = useMemo(() => {
+ return {
+ editorShowOutlines,
+ setEditorShowOutlines,
+ };
+ }, [editorShowOutlines, setEditorShowOutlines]);
+
+ return (
+ <EditorShowOutlinesContext.Provider value={editorShowOutlinesCtx}>
+ {children}
+ </EditorShowOutlinesContext.Provider>
+ );
+};
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsx
index 6a68c57fc5..43f0275227 100644
--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx
@@ -17,6 +17,10 @@ import type {
import {TIMELINE_PADDING} from '../../helpers/timeline-layout';
import {timelineNodePathInfoToKey} from '../../helpers/timeline-node-path-key';
import {useKeybinding} from '../../helpers/use-keybinding';
+import {
+ EditorShowOutlinesContext,
+ ENABLE_OUTLINES as ENABLE_OUTLINES_FLAG,
+} from '../../state/editor-outlines';
import {TimelineClipboardKeybindings} from './TimelineClipboardKeybindings';
import {TimelineDeleteKeybindings} from './TimelineDeleteKeybindings';
@@ -62,7 +66,7 @@ export const getTimelineSelectedTrackHighlightStyle = (
export const SELECTION_ENABLED = false;
export const TIMELINE_TOP_DRAG = false;
-export const ENABLE_OUTLINES = false;
+export {ENABLE_OUTLINES} from '../../state/editor-outlines';
type TimelineSelectionBase = {
readonly nodePathInfo: SequenceNodePathInfo;
@@ -443,8 +447,9 @@ export const TimelineSelectionProvider: React.FC<{
readonly children: React.ReactNode;
}> = ({children}) => {
const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const {editorShowOutlines} = useContext(EditorShowOutlinesContext);
const canSelect =
- (SELECTION_ENABLED || ENABLE_OUTLINES) &&
+ (SELECTION_ENABLED || (ENABLE_OUTLINES_FLAG && editorShowOutlines)) &&
previewServerState.type === 'connected' &&
!window.remotion_isReadOnlyStudio;
const [selectedItems, setSelectedItems] = useState<
diff --git a/packages/studio/src/state/editor-outlines.ts b/packages/studio/src/state/editor-outlines.ts
new file mode 100644
index 0000000000..7435446469
--- /dev/null
+++ b/packages/studio/src/state/editor-outlines.ts
@@ -0,0 +1,24 @@
+import {createContext} from 'react';
+
+type State = {
+ editorShowOutlines: boolean;
+ setEditorShowOutlines: (cb: (prevState: boolean) => boolean) => void;
+};
+
+const key = 'remotion.editorShowOutlines';
+
+export const ENABLE_OUTLINES = true;
+
+export const persistEditorShowOutlinesOption = (option: boolean) => {
+ localStorage.setItem(key, String(option));
+};
+
+export const loadEditorShowOutlinesOption = (): boolean => {
+ const item = localStorage.getItem(key);
+ return item !== 'false';
+};
+
+export const EditorShowOutlinesContext = createContext<State>({
+ editorShowOutlines: true,
+ setEditorShowOutlines: () => undefined,
+});
diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.ts
index cfa07a9d65..f91a77127b 100644
--- a/packages/studio/src/test/timeline-selection.test.ts
+++ b/packages/studio/src/test/timeline-selection.test.ts
@@ -32,7 +32,6 @@ import {
type PasteEffectsTarget,
} from '../components/Timeline/TimelineClipboardKeybindings';
import {
- ENABLE_OUTLINES,
getSelectableTimelineSequenceSelections,
getTimelineSelectionAfterInteraction,
getTimelineSelectionFromNodePathInfo,
@@ -50,6 +49,11 @@ import {
getTimelineSequenceFromDragValue,
} from '../components/Timeline/TimelineSequenceRightEdgeDragHandle';
import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';
+import {
+ ENABLE_OUTLINES,
+ loadEditorShowOutlinesOption,
+ persistEditorShowOutlinesOption,
+} from '../state/editor-outlines';
const makeKey = (
nodePath: SequenceNodePath,
@@ -61,6 +65,39 @@ const makeKey = (
effectKeys,
});
+const withMockLocalStorage = (callback: () => void) => {
+ const previousDescriptor = Object.getOwnPropertyDescriptor(
+ globalThis,
+ 'localStorage',
+ );
+ const values = new Map<string, string>();
+ const localStorageMock: Storage = {
+ clear: () => values.clear(),
+ getItem: (key: string) => values.get(key) ?? null,
+ key: (index: number) => [...values.keys()][index] ?? null,
+ removeItem: (key: string) => values.delete(key),
+ setItem: (key: string, value: string) => values.set(key, value),
+ get length() {
+ return values.size;
+ },
+ };
+
+ Object.defineProperty(globalThis, 'localStorage', {
+ configurable: true,
+ value: localStorageMock,
+ });
+
+ try {
+ callback();
+ } finally {
+ if (previousDescriptor) {
+ Object.defineProperty(globalThis, 'localStorage', previousDescriptor);
+ } else {
+ Reflect.deleteProperty(globalThis, 'localStorage');
+ }
+ }
+};
+
const makeNodePathInfo = (
nodePath: SequenceNodePath,
auxiliaryKeys: string[],
@@ -693,8 +730,20 @@ test('Timeline from drag removes the prop at the default value', () => {
});
});
-test('Timeline outlines should not be enabled', () => {
- expect(ENABLE_OUTLINES).toBe(false);
+test('Timeline outlines should be enabled', () => {
+ expect(ENABLE_OUTLINES).toBe(true);
+});
+
+test('Timeline outlines visibility is enabled by default and persisted', () => {
+ withMockLocalStorage(() => {
+ expect(loadEditorShowOutlinesOption()).toBe(true);
+
+ persistEditorShowOutlinesOption(false);
+ expect(loadEditorShowOutlinesOption()).toBe(false);
+
+ persistEditorShowOutlinesOption(true);
+ expect(loadEditorShowOutlinesOption()).toBe(true);
+ });
});
test('Canvas outline selection uses conventional modifier keys', () => {