🎥 Make videos programmatically with React
right click to disable out marks
Jonny Burgerbc2ef1737087
diff --git a/packages/cli/src/editor/components/TimelineInOutToggle.tsx b/packages/cli/src/editor/components/TimelineInOutToggle.tsxindex 94d9a1746e..32c6c43cc8 100644--- a/packages/cli/src/editor/components/TimelineInOutToggle.tsx+++ b/packages/cli/src/editor/components/TimelineInOutToggle.tsx@@ -24,7 +24,11 @@ import {persistMarks} from '../state/marks';import {ControlButton} from './ControlButton';const getTooltipText = (pointType: string, key: string) =>- [`Mark ${pointType}`, areKeyboardShortcutsDisabled() ? null : `(${key})`]+ [+ `Mark ${pointType}`,+ areKeyboardShortcutsDisabled() ? null : `(${key})`,+ '- right click to clear',+ ].filter(truthy).join(' ');@@ -34,8 +38,8 @@ const style: React.CSSProperties = {};export const inOutHandles = createRef<{- inMarkClick: () => void;- outMarkClick: () => void;+ inMarkClick: (e: KeyboardEvent) => void;+ outMarkClick: (e: KeyboardEvent) => void;clearMarks: () => void;setMarks: (marks: [number | null, number | null]) => void;}>();@@ -49,96 +53,158 @@ export const TimelineInOutPointToggle: React.FC = () => {const videoConfig = Internals.useUnsafeVideoConfig();const keybindings = useKeybinding();- const onInMark = useCallback(() => {- if (!videoConfig) {- return null;- }+ const onInOutClear = useCallback(() => {+ setInAndOutFrames(() => {+ return {+ inFrame: null,+ outFrame: null,+ };+ });+ }, [setInAndOutFrames]);- setInAndOutFrames((prev) => {- const biggestPossible =- prev.outFrame === null ? Infinity : prev.outFrame - 1;- const selected = Math.min(timelinePosition, biggestPossible);+ const onInMark = useCallback(+ (e: KeyboardEvent | React.MouseEvent) => {+ if (!videoConfig) {+ return null;+ }- if (selected === 0) {- return {- ...prev,- inFrame: null,- };+ if (e.shiftKey) {+ setInAndOutFrames((f) => {+ return {+ ...f,+ inFrame: null,+ };+ });+ return null;}- if (prev.inFrame !== null) {- // Disable if already at this position- if (prev.inFrame === selected) {+ setInAndOutFrames((prev) => {+ const biggestPossible =+ prev.outFrame === null ? Infinity : prev.outFrame - 1;+ const selected = Math.min(timelinePosition, biggestPossible);++ if (selected === 0) {return {...prev,inFrame: null,};}++ if (prev.inFrame !== null) {+ // Disable if already at this position+ if (prev.inFrame === selected) {+ return {+ ...prev,+ inFrame: null,+ };+ }+ }++ return {+ ...prev,+ inFrame: selected,+ };+ });+ },+ [setInAndOutFrames, timelinePosition, videoConfig]+ );++ const clearInMark = useCallback(+ (e: React.MouseEvent) => {+ if (!videoConfig) {+ return null;}- return {- ...prev,- inFrame: selected,- };- });- }, [setInAndOutFrames, timelinePosition, videoConfig]);+ e.preventDefault();- const onOutMark = useCallback(() => {- if (!videoConfig) {- return null;- }+ setInAndOutFrames((f) => {+ return {+ ...f,+ inFrame: null,+ };+ });+ },+ [setInAndOutFrames, videoConfig]+ );++ const clearOutMark = useCallback(+ (e: React.MouseEvent) => {+ if (!videoConfig) {+ return null;+ }- setInAndOutFrames((prev) => {- const smallestPossible =- prev.inFrame === null ? -Infinity : prev.inFrame + 1;- const selected = Math.max(timelinePosition, smallestPossible);+ e.preventDefault();- if (selected === videoConfig.durationInFrames - 1) {+ setInAndOutFrames((f) => {return {- ...prev,+ ...f,outFrame: null,};+ });+ },+ [setInAndOutFrames, videoConfig]+ );++ const onOutMark = useCallback(+ (e: KeyboardEvent | React.MouseEvent) => {+ if (!videoConfig) {+ return null;}- if (prev.outFrame !== null) {- if (prev.outFrame === selected) {+ if (e.shiftKey) {+ setInAndOutFrames((f) => {+ return {+ ...f,+ outFrame: null,+ };+ });+ return;+ }++ setInAndOutFrames((prev) => {+ const smallestPossible =+ prev.inFrame === null ? -Infinity : prev.inFrame + 1;+ const selected = Math.max(timelinePosition, smallestPossible);++ if (selected === videoConfig.durationInFrames - 1) {return {...prev,outFrame: null,};}- }- return {- ...prev,- outFrame: selected,- };- });- }, [setInAndOutFrames, timelinePosition, videoConfig]);+ if (prev.outFrame !== null) {+ if (prev.outFrame === selected) {+ return {+ ...prev,+ outFrame: null,+ };+ }+ }- const onInOutClear = useCallback(() => {- setInAndOutFrames(() => {- return {- inFrame: null,- outFrame: null,- };- });- }, [setInAndOutFrames]);+ return {+ ...prev,+ outFrame: selected,+ };+ });+ },+ [setInAndOutFrames, timelinePosition, videoConfig]+ );useEffect(() => {const iKey = keybindings.registerKeybinding({event: 'keypress',key: 'i',- callback: () => {- onInMark();+ callback: (e) => {+ onInMark(e);},commandCtrlKey: false,});const oKey = keybindings.registerKeybinding({event: 'keypress',key: 'o',- callback: () => {- onOutMark();+ callback: (e) => {+ onOutMark(e);},commandCtrlKey: false,});@@ -224,7 +290,8 @@ export const TimelineInOutPointToggle: React.FC = () => {<ControlButtontitle={getTooltipText('In', 'I')}aria-label={getTooltipText('In', 'I')}- onClick={onInMark}+ onClick={(e) => onInMark(e)}+ onContextMenu={clearInMark}disabled={timelinePosition === 0}><TimelineInPointer@@ -233,9 +300,10 @@ export const TimelineInOutPointToggle: React.FC = () => {/></ControlButton><ControlButton- title={getTooltipText('Out', '(O)')}- aria-label={getTooltipText('Out', '(O)')}+ title={getTooltipText('Out', 'O')}+ aria-label={getTooltipText('Out', 'O')}onClick={onOutMark}+ onContextMenu={clearOutMark}disabled={timelinePosition === videoConfig.durationInFrames - 1}><TimelineOutPointer