Skip to content

🎥 Make videos programmatically with React

allow right click on in / out marker

Jonny Burger953d3645994a
diff --git a/packages/cli/src/editor/components/Menu/MenuSubItem.tsx b/packages/cli/src/editor/components/Menu/MenuSubItem.tsx
index 7a89f4a6a0..ec009f0f00 100644
--- a/packages/cli/src/editor/components/Menu/MenuSubItem.tsx
+++ b/packages/cli/src/editor/components/Menu/MenuSubItem.tsx
@@ -1,4 +1,5 @@
import {PlayerInternals} from '@remotion/player';
+import type {PointerEvent} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import ReactDOM from 'react-dom';
import {CLEAR_HOVER, LIGHT_TEXT} from '../../helpers/colors';
@@ -51,7 +52,7 @@ export type SubMenuActivated = false | 'with-mouse' | 'without-mouse';
export const MenuSubItem: React.FC<{
label: React.ReactNode;
id: string;
- onActionChosen: (id: string) => void;
+ onActionChosen: (id: string, e: PointerEvent<HTMLDivElement>) => void;
selected: boolean;
onItemSelected: (id: string) => void;
keyHint: string | null;
@@ -91,9 +92,12 @@ export const MenuSubItem: React.FC<{
};
}, [selected]);
- const onItemTriggered = useCallback(() => {
- onActionChosen(id);
- }, [id, onActionChosen]);
+ const onItemTriggered = useCallback(
+ (e: PointerEvent<HTMLDivElement>) => {
+ onActionChosen(id, e);
+ },
+ [id, onActionChosen],
+ );
const onPointerEnter = useCallback(() => {
onItemSelected(id);
diff --git a/packages/cli/src/editor/components/NewComposition/ComboBox.tsx b/packages/cli/src/editor/components/NewComposition/ComboBox.tsx
index 2b150a5a73..400a7fae66 100644
--- a/packages/cli/src/editor/components/NewComposition/ComboBox.tsx
+++ b/packages/cli/src/editor/components/NewComposition/ComboBox.tsx
@@ -55,7 +55,7 @@ export type SelectionItem = {
id: string;
label: React.ReactNode;
value: string | number;
- onClick: (id: string) => void;
+ onClick: (id: string, e: React.PointerEvent | null) => void;
keyHint: string | null;
leftItem: React.ReactNode;
subMenu: SubMenu | null;
diff --git a/packages/cli/src/editor/components/NewComposition/MenuContent.tsx b/packages/cli/src/editor/components/NewComposition/MenuContent.tsx
index ec27931429..8d24ef4091 100644
--- a/packages/cli/src/editor/components/NewComposition/MenuContent.tsx
+++ b/packages/cli/src/editor/components/NewComposition/MenuContent.tsx
@@ -1,4 +1,4 @@
-import type {SetStateAction} from 'react';
+import type {PointerEvent, SetStateAction} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {INPUT_BORDER_COLOR_UNHOVERED} from '../../helpers/colors';
import {useKeybinding} from '../../helpers/use-keybinding';
@@ -133,7 +133,7 @@ export const MenuContent: React.FC<{
}
onHide();
- item.onClick(item.id);
+ item.onClick(item.id, null);
}, [onHide, selectedItem, values]);
const onArrowRight = useCallback(() => {
@@ -299,9 +299,9 @@ export const MenuContent: React.FC<{
return <MenuDivider key={item.id} />;
}
- const onClick = () => {
+ const onClick = (id: string, e: PointerEvent<HTMLDivElement>) => {
onHide();
- item.onClick(item.id);
+ item.onClick(id, e);
};
return (
diff --git a/packages/cli/src/editor/components/Timeline/TimelineDragHandler.tsx b/packages/cli/src/editor/components/Timeline/TimelineDragHandler.tsx
index 1dcaa3bf23..94044f74ec 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineDragHandler.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineDragHandler.tsx
@@ -15,7 +15,10 @@ import {
useTimelineSetInOutFramePosition,
} from '../../state/in-out';
import {TimelineZoomCtx} from '../../state/timeline-zoom';
+import {useZIndex} from '../../state/z-index';
+import {ContextMenu} from '../ContextMenu';
import {VERTICAL_SCROLLBAR_CLASSNAME} from '../Menu/is-menu-item';
+import type {ComboboxValue} from '../NewComposition/ComboBox';
import {defaultInOutValue} from '../TimelineInOutToggle';
import {scrollableRef, sliderAreaRef} from './timeline-refs';
import {
@@ -48,6 +51,11 @@ const container: React.CSSProperties = {
top: 0,
};
+const style: React.CSSProperties = {
+ width: '100%',
+ height: '100%',
+};
+
const getClientXWithScroll = (x: number) => {
return x + (scrollableRef.current?.scrollLeft as number);
};
@@ -77,6 +85,7 @@ const Inner: React.FC = () => {
triggerOnWindowResize: true,
shouldApplyCssTransforms: true,
});
+ const {isHighestContext} = useZIndex();
const setFrame = Internals.useTimelineSetFrame();
const [inOutDragging, setInOutDragging] = useState<
@@ -144,6 +153,10 @@ const Inner: React.FC = () => {
return;
}
+ if (!isHighestContext) {
+ return;
+ }
+
stopInterval();
if (!videoConfig) {
return;
@@ -193,7 +206,18 @@ const Inner: React.FC = () => {
});
pause();
},
- [videoConfig, left, width, seek, playing, pause, outFrame, get, inFrame],
+ [
+ isHighestContext,
+ videoConfig,
+ left,
+ width,
+ seek,
+ playing,
+ pause,
+ inFrame,
+ get,
+ outFrame,
+ ],
);
const onPointerMoveScrubbing = useCallback(
@@ -485,28 +509,78 @@ const Inner: React.FC = () => {
};
}, [inOutDragging.dragging, onPointerMoveInOut, onPointerUpInOut]);
+ const inContextMenu = useMemo((): ComboboxValue[] => {
+ return [
+ {
+ id: 'hide-in',
+ keyHint: null,
+ label: 'Clear In marker',
+ leftItem: null,
+ onClick: (_, e) => {
+ e?.stopPropagation();
+ e?.preventDefault();
+ setInAndOutFrames((prev) => ({
+ ...prev,
+ [videoConfig.id]: {
+ ...(prev[videoConfig.id] ?? defaultInOutValue),
+ inFrame: null,
+ },
+ }));
+ },
+ quickSwitcherLabel: null,
+ subMenu: null,
+ type: 'item',
+ value: 'hide-in',
+ },
+ ];
+ }, [setInAndOutFrames, videoConfig.id]);
+
+ const outContextMenu = useMemo((): ComboboxValue[] => {
+ return [
+ {
+ id: 'hide-out',
+ keyHint: null,
+ label: 'Clear Out marker',
+ leftItem: null,
+ onClick: (_, e) => {
+ e?.stopPropagation();
+ e?.preventDefault();
+ setInAndOutFrames((prev) => ({
+ ...prev,
+ [videoConfig.id]: {
+ ...(prev[videoConfig.id] ?? defaultInOutValue),
+ outFrame: null,
+ },
+ }));
+ },
+ quickSwitcherLabel: null,
+ subMenu: null,
+ type: 'item',
+ value: 'hide-out',
+ },
+ ];
+ }, [setInAndOutFrames, videoConfig.id]);
+
return (
- <div
- style={{
- width: '100%',
- height: '100%',
- }}
- onPointerDown={onPointerDown}
- >
+ <div style={style} onPointerDown={onPointerDown}>
<div style={inner} className={VERTICAL_SCROLLBAR_CLASSNAME} />
{inFrame !== null && (
- <TimelineInOutPointerHandle
- type="in"
- atFrame={inFrame}
- dragging={inOutDragging.dragging === 'in'}
- />
+ <ContextMenu values={inContextMenu}>
+ <TimelineInOutPointerHandle
+ type="in"
+ atFrame={inFrame}
+ dragging={inOutDragging.dragging === 'in'}
+ />
+ </ContextMenu>
)}
{outFrame !== null && (
- <TimelineInOutPointerHandle
- type="out"
- dragging={inOutDragging.dragging === 'out'}
- atFrame={outFrame}
- />
+ <ContextMenu values={outContextMenu}>
+ <TimelineInOutPointerHandle
+ type="out"
+ dragging={inOutDragging.dragging === 'out'}
+ atFrame={outFrame}
+ />
+ </ContextMenu>
)}
</div>
);
diff --git a/packages/cli/src/editor/helpers/use-menu-structure.tsx b/packages/cli/src/editor/helpers/use-menu-structure.tsx
index 518f0fdd64..c87b3c9cbf 100644
--- a/packages/cli/src/editor/helpers/use-menu-structure.tsx
+++ b/packages/cli/src/editor/helpers/use-menu-structure.tsx
@@ -820,7 +820,7 @@ const itemToSearchResult = (
id: item.id,
onSelected: () => {
setSelectedModal(null);
- item.onClick(item.id);
+ item.onClick(item.id, null);
},
title: [...prefixes, getItemLabel(item)].join(': '),
},